-
Notifications
You must be signed in to change notification settings - Fork 10.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
srem-related vector miscompile on AArch64 #77169
Comments
@llvm/issue-subscribers-backend-aarch64 Author: John Regehr (regehr)
here's a function `@f` that I believe is being miscompiled and also a glue function `@g` that'll let us test it from C:
```llvm
define <4 x i32> @f(<4 x i32> %0) {
%2 = srem <4 x i32> %0, <i32 1, i32 1, i32 2, i32 3>
%3 = icmp eq <4 x i32> %2, zeroinitializer
%4 = zext <4 x i1> %3 to <4 x i32>
ret <4 x i32> %4
}
define void @g(ptr %p) {
on my M1 Mac it gives:
but, by inspection, we can see that the second line should have been the codegen for this one is kind of lengthy, so I hope this explanation suffices, thanks |
I think this reproduces on X86 too? |
it does repro on x86-64. sorry, I should have checked that last night, was being lazy |
Looks like maybe an issue with the algorithm in TargetLowering::prepareSREMEqFold for N=INT_MIN and D is a power of 2. I think that comes from Hacker's Delight. |
I think the issue is that q=mod(n*multiplicative_inverse(d0), 2^W) is not in the range [-2147483647, 2147483647] when n is -2147483648. So the thoerem that gives the rotate right trick doesn't apply. CC: @RKSimon @LebedevRI |
a power of two. The expansion previously used, derived from Hacker's Delight, does not work correctly when the dividend is INT_MIN and the divisor is a power of two. We now use an alternate derivation of the A and Q constants specifically for the power-of-two divisor case to avoid this problem. Credit to Fabian Giesen for the new derivation. Fixes llvm#77169
a power of two. The expansion previously used, derived from Hacker's Delight, does not work correctly when the dividend is INT_MIN and the divisor is a power of two. We now use an alternate derivation of the A and Q constants specifically for the power-of-two divisor case to avoid this problem. Credit to Fabian Giesen for the new derivation. I have exhaustively tested the new derivation at W=32 for all values of N and all D=2^K. Fixes llvm#77169
…er of two. (#82706) The expansion previously used, derived from Hacker's Delight, does not work correctly when the dividend is INT_MIN and the divisor is a power of two. We now use an alternate derivation of the A and Q constants specifically for the power-of-two divisor case to avoid this problem. Credit to Fabian Giesen for the new derivation. Fixes #77169
here's a function
@f
that I believe is being miscompiled and also a glue function@g
that'll let us test it from C:here's a test driver:
on my M1 Mac it gives:
but, by inspection, we can see that the second line should have been
1 1 1 1
the codegen for this one is kind of lengthy, so I hope this explanation suffices, thanks
The text was updated successfully, but these errors were encountered: