Open ChaiTRex opened 3 months ago
Note that I can't reproduce this on my own machine, but I get another bug there (https://github.com/rust-lang/rust/issues/127641).
rustc -O
sets opt-level=2
, but cargo build --release
sets opt-level=3
by default (https://godbolt.org/z/x7WTa9MWc), which is likely the difference here.
My experiments with trying to cram x86 assembly via asm!
and Godbolt into LLVM-MCA can't replicate the "clearly faster" result, so I don't feel confident closing this like I did #127641, but there's some distortion since that isn't very direct.
I would expect -Copt-level=s
or -Copt-level=z
to remove this forward jump.
I tried this code in Godbolt:
I expected to see this happen: Generated assembly doesn't include jumps to the next instruction.
Instead, this happened: Generated assembly does include a jump to the next instruction.
On
x86_64-unknown-linux-gnu
(with command line flag-O
), notice that thejmp .LBB0_3
line is just above the.LBB0_3
label, and so that instruction can be removed, reducing code size:On
aarch64-apple-darwin
(with command line flags-O --target=aarch64-apple-darwin
), the same thing occurs with theb LBB0_3
instruction:Meta
``` rustc 1.79.0 (129f3b996 2024-06-10) binary: rustc commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081 commit-date: 2024-06-10 host: x86_64-unknown-linux-gnu release: 1.79.0 LLVM version: 18.1.7 ``` ``` rustc 1.80.0-beta.4 (64a1fe671 2024-06-21) binary: rustc commit-hash: 64a1fe67112931359c7c9a222f08fd206255c2b5 commit-date: 2024-06-21 host: x86_64-unknown-linux-gnu release: 1.80.0-beta.4 LLVM version: 18.1.7 ``` ``` rustc 1.81.0-nightly (0c81f94b9 2024-07-10) binary: rustc commit-hash: 0c81f94b9a6207fb1fc080caa83584dea2d71fc6 commit-date: 2024-07-10 host: x86_64-unknown-linux-gnu release: 1.81.0-nightly LLVM version: 18.1.7 ```rustc --version --verbose
Note that I can't reproduce this on my own machine, but I get another bug there (#127641).