Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tommythorn/rustc-codegen-issue
Small example of suboptimal code generation from Rust 1.70 on RISC-V (and others?)
https://github.com/tommythorn/rustc-codegen-issue
Last synced: 13 days ago
JSON representation
Small example of suboptimal code generation from Rust 1.70 on RISC-V (and others?)
- Host: GitHub
- URL: https://github.com/tommythorn/rustc-codegen-issue
- Owner: tommythorn
- Created: 2023-07-01T03:53:29.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-07-01T03:53:46.000Z (over 1 year ago)
- Last Synced: 2025-01-11T16:16:18.621Z (18 days ago)
- Language: Rust
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.txt
Awesome Lists containing this project
README
A small example of suboptimal Rust Code Generation
--------------------------------------------------Predictably my rant about non-perfect rustc 1.70 codegen was countered
with a request for code. Here is the code. If I recall correctly, it
wasn't RISC-V specific, but I find RISC-V easier to read so here it is
generated withrustc -O --crate-type lib -C target-feature=+zba -C target-feature=+zbb src/lib.rs
objdump -d liblib.rlibshows
1a: 60171693 ctz a3,a4
1e: fff70793 add a5,a4,-1
22: 8f7d and a4,a4,a5
24: 00d897b3 sll a5,a7,a3
28: 40f30333 sub t1,t1,a5
2c: 20653023 sd t1,512(a0) <<<< should be hoisted
30: 02d2e463 bltu t0,a3,58
34: 20a6e6b3 sh3add a3,a3,a0
38: 6294 ld a3,0(a3)
3a: 0107e833 or a6,a5,a6
3e: 9636 add a2,a2,a3
40: 15fd add a1,a1,-1
42: 20c53823 sd a2,528(a0) <<<< should be hoisted
46: f9f1 bnez a1,1ahow two stores should have been hoisted out of the loop. You can get
the expected code by doing this manuallyNote, I otherwise very happy with the code generated by rustc in general, though the
auipi ra, K1
jalr ra,ra(K2)pattern instead of just
jal L
was shocking.
Tommy, 20230630