-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rust generates suboptimal code for x.div_euclid(2) #118392
Comments
A simple playground example with fn main() {
assert_eq!(
(-7i32) / 2, // -3
(-7i32).div_euclid(2) // -4
);
} However if you use @rustbot labels -C-bug -needs-triage +C-discussion |
@Urgau I believe
div2:
mov eax, edi
shr eax, 31
add eax, edi
sar eax
ret Note how the generated code adds sign bit, which is correct. |
@rustbot labels +C-bug +needs-triage -C-discussion I-heavy I-slow A-LLVM A-codegen T-compiler |
LLVM issue: llvm/llvm-project#73622 Worth noting that the problem only occurs with 2, not other power of two constants. |
My bad, I wrongly deduced that you meant |
Confirmed fixed by #120055, needs codegen test. |
Add codegen tests for E-needs-test close rust-lang#36010 close rust-lang#68667 close rust-lang#74938 close rust-lang#83585 close rust-lang#93036 close rust-lang#109328 close rust-lang#110797 close rust-lang#111508 close rust-lang#112509 close rust-lang#113757 close rust-lang#120440 close rust-lang#118392 close rust-lang#71096 r? nikic
Add codegen tests for E-needs-test close rust-lang#36010 close rust-lang#68667 close rust-lang#74938 close rust-lang#83585 close rust-lang#93036 close rust-lang#109328 close rust-lang#110797 close rust-lang#111508 close rust-lang#112509 close rust-lang#113757 close rust-lang#120440 close rust-lang#118392 close rust-lang#71096 r? nikic
Add codegen tests for E-needs-test close rust-lang#36010 close rust-lang#68667 close rust-lang#74938 close rust-lang#83585 close rust-lang#93036 close rust-lang#109328 close rust-lang#110797 close rust-lang#111508 close rust-lang#112509 close rust-lang#113757 close rust-lang#120440 close rust-lang#118392 close rust-lang#71096 r? nikic
Add codegen tests for E-needs-test close rust-lang#36010 close rust-lang#68667 close rust-lang#74938 close rust-lang#83585 close rust-lang#93036 close rust-lang#109328 close rust-lang#110797 close rust-lang#111508 close rust-lang#112509 close rust-lang#113757 close rust-lang#120440 close rust-lang#118392 close rust-lang#71096 r? nikic
I tried this code:
I expected to see this happen:
After compiling to assembly with
-C opt-level=3
to generate the following x86 assembly code.Instead, this happened:
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: