-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
f32::powi(_,0) broken on raspberry pi (beta and nightly) #37559
Comments
I tried to find the nightlies between which this was introduced, however the best I can do is some time between I can get |
In case it helps anyone, assembly and ir of the following demo are here: https://gist.github.com/anonymous/a2a13985180e9960579f5f4a5372596a #[inline(never)]
fn foo() -> f32 {
12345.0f32.powi(0)
}
fn main() {
println!("{}", foo());
} |
Forgot to mention that as far as I can tell, it only impacts the debug builds. -O builds look fine. |
@kali: At least for my example, when compiling with Edit: Indeed, when preventing llvm from const folding the #[inline(never)]
fn foo(i: i32) -> f32 {
12345.0f32.powi(i)
}
fn main() {
let s = String::new();
println!("{}", foo(s.len() as i32));
} |
For what it's worth, I can not reproduce it with armv7-apple-ios on current nightly. |
cc @japaric -- maybe related to the builtins stuff? |
@japaric if you know the fix, can it be backported to beta in the next day or two? |
Oh, it's related to optimization, so maybe not intrinsics. |
|
Isn't this a Raspberry Pi? Why is everyone using the armv7 triple? That Pi has an ARMv6 processor in it. (Pi 2+ is ARMv7). @kali Can you post the output of running |
@japaric: At least I have |
It's a Pi 2. Envoyé de mon iPhone
|
I don't have access to it right now to check the abi. It's a fresh raspbian install, and rustup. Envoyé de mon iPhone
|
Alright, I can reproduce this now via cross-compile + qemu, even inside the range that previously failed due to SIGILL, I'll try to track down the nightlies between which this was introduced. |
triage: P-high Given that ARM/RasbPi are not tier 1, it's not entirely clear how to prioritize this, but it seems like something we should fix sooner rather than later. We haven't assigned anyone from compiler team yet though since it's not clear who would be best to tackle it. @japaric, do you think you can investigate whether it is indeed related to #35021? |
Alright, so the generated llvm-ir and asm are exactly the same (at least when using the |
I have disassembled the generated executables and actually found a difference now: In the "good" case, the calculation is deferred to the external In the "bad" case, __powisf2:
0002af00 vmov.f32 s14, #0x1
0002af04 mov r3, r1
0002af06 vmov s15, r0
0002af0a b 0x2af10
0002af0c vmul.f32 s15, s15, s15
0002af10 add.w r2, r3, r3, lsr #31
0002af14 lsls r3, r3, #0x1f
0002af16 it mi
0002af18 vmulmi.f32 s14, s14, s15
0002af1c asrs r3, r2, #0x1
0002af1e bne 0x2af0c
0002af20 cmp r1, #0x0
0002af22 itt lt
0002af24 vmovlt.f32 s15, #0x1
0002af28 vdivlt.f32 s14, s15, s14
0002af2c vmov r0, s14
0002af30 bx lr
Both executables require the same shared libraries:
My current hypothesis (from what I picked up over time, I'm not really an expert here) is that the |
(The following is 70% guesswork) I've been trying to debug this a bit and think that problem is a calling convention mismatch. The
1 Edit: was previously |
That seems likely. It wouldn't be the first time either. We had a compiler-rt implementation that triggered UB and we had to fix its C implementation. And you are right that before the "compiler-rt crate-ification" PR this symbol came from Ideas to fix this:
|
Holy cow, nice investigation @TimNN! That's only mildly disturbing that making our linking to compiler-rt "more correct" ended up introducing a bug...
The implementation is pretty small and seems like for the arguments in the program above it should trivially return the right value, unfortunately. Compiling with the wrong flags though seems quite possible! If that is indeed the problem then in theory this can wreak havoc with jemalloc and/or any other C code in the world as well, so I'd prefer to dig into if that's the problem before we stop compiling |
Wow. That was impressive. Thanks a lot @TimNN and the gang. |
[beta] fix #37559: update compiler-rt
fix rust-lang#37559: update compiler-rt Fixes rust-lang#37559 r? @alexcrichton
fix rust-lang#37559: update compiler-rt Fixes rust-lang#37559 r? @alexcrichton
fix rust-lang#37559: update compiler-rt Fixes rust-lang#37559 r? @alexcrichton
This should be fixed on beta and in 1.13. |
Can anybody test on the latest beta? |
Seems to be working in |
@TimNN Woo! Thank you for testing! |
ho, boy.
|
float litterals got impacted somehow...
|
Should we re-open this ? or is it better to create a new one ? |
ok. |
This update of compiler-rt includes rust-lang/compiler-rt#26 which provides a targeted fix to the powisf2 intrinsics to keep rust-lang#37559 fixed but also address the new issue of rust-lang#37630. I've also [written up my thoughts][1] on why it appears that this is the correct fix for now (hoepfully at least). Closes rust-lang#37630 [1]: rust-lang/compiler-rt#26 (comment)
std: Update compiler-rt for more ABI fixes This update of compiler-rt includes rust-lang/compiler-rt#26 which provides a targeted fix to the powisf2 intrinsics to keep #37559 fixed but also address the new issue of #37630. I've also [written up my thoughts][1] on why it appears that this is the correct fix for now (hoepfully at least). Closes #37630 [1]: rust-lang/compiler-rt#26 (comment)
to pick up the fixes for rust-lang/rust#37559 and rust-lang/rust#37630
update the compiler-rt submodule to pick up the fixes for rust-lang/rust#37559 and rust-lang/rust#37630 r? @alexcrichton cc @TimNN
This update of compiler-rt includes rust-lang/compiler-rt#26 which provides a targeted fix to the powisf2 intrinsics to keep rust-lang#37559 fixed but also address the new issue of rust-lang#37630. I've also [written up my thoughts][1] on why it appears that this is the correct fix for now (hoepfully at least). Closes rust-lang#37630 [1]: rust-lang/compiler-rt#26 (comment)
On a rapsberry pi, rust installed through with rustup:
Stable is correct, but beta and nightly are terribly wrong, so with have a regression. It specifically breaks num-bigint tests on raspberry pi.
The text was updated successfully, but these errors were encountered: