-
Notifications
You must be signed in to change notification settings - Fork 11.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
[execute]binary compile with -O0 run diff to gcc -O0 on aarch64 #50847
Comments
Thanks for the report, I can reproduce with latest clang. Here's a godbolt showing both: https://godbolt.org/z/nosMbnrbP The key seems to be that GCC takes the thing that clang warns about, ~a > -1L always being true. clang generates code for that check at O0, gcc does not.
.LBB0_1: I need a bit more time to understand the warning. Certainly it seems like clang is proving itself wrong! (or just emitting incorrect code) |
Missed the "L" first time reading the example. So of course this warning makes sense, sizeof(-1L) is 8, sizeof(a) is 4. 4 bytes is never going to be > 8. |
I think I don't fully understand the logic behind the warning, if it were just down to byte size then it would always be false. Anyway if we take what gcc does as correct, x86 and riscv seem to get it right with clang. The AArch64 code has half of it right. It will always follow the branch ("is always true") but it's got the labels flipped.
.LBB0_1: // But this is the label the tbz should branch to https://developer.arm.com/documentation/dui0802/a/A64-General-Instructions/TBZ I confirmed manually by changing the asm:
|
TLDR: We make a mistake when inverting a bit test because we sign extend a value instead of zero extending it. It only effects Global Isel, I think I have a fix. I've found where this goes wrong, and a potential fix. I need to consider if it's just fixing this one case and how to test more generally. I'm using a smaller example in these tests: The first thing to mention is that fastisel does not make this mistake: https://developer.arm.com/documentation/dui0802/a/A64-General-Instructions/TBNZ The commit that changed the assembly output was:
However this in itself is not the problem. G_ICMP is lowered to instructions after post legalizer lowering. First note that an earlier pass flips the labels and so the greater than/less comparison that we use. < # *** IR Dump Before AArch64PreLegalizerCombiner ***:
20,22c20,22
|
Fixed by https://reviews.llvm.org/D108755. |
Tom, can we get this fix into the release? https://reviews.llvm.org/rG5f48c144c58f6d23e850a1978a6fe05887103b17 |
Re-opening to track inclusion into the release branch. |
Merged: 80f974e |
mentioned in issue #51489 |
Extended Description
yansendao@jvmtest-129:boole-issue2603$ gcc test-creduce.c -Wall && ./a.out
3
yansendao@jvmtest-129:boole-issue2603$ ~/software/llvm12/bin/clang test-creduce.c -Wall && ./a.out
test-creduce.c:7:10: warning: result of comparison of constant -1 with expression of type 'unsigned int' is always true [-Wtautological-constant-out-of-range-compare]
if (~a > -1L)
~~ ^ ~~~
1 warning generated.
0
yansendao@jvmtest-129:boole-issue2603$ ~/software/llvm12/bin/clang -v
clang version 12.0.1
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/yansendao/software/llvm12/bin
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7.5.0
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/8
Found candidate GCC installation: /usr/lib64/gcc/aarch64-linux-gnu/7
Found candidate GCC installation: /usr/lib64/gcc/aarch64-linux-gnu/7.5.0
Found candidate GCC installation: /usr/lib64/gcc/aarch64-linux-gnu/8
Selected GCC installation: /usr/lib64/gcc/aarch64-linux-gnu/7.5.0
Candidate multilib: .;@m64
Selected multilib: .;@m64
yansendao@jvmtest-129:boole-issue2603$ cat test-creduce.c
int printf(const char *, ...);
unsigned a;
long b;
short c, d;
long *e = &b;
short f() {
if (~a > -1L)
return 3;
return d;
}
int main() {
c = f();
*e = c;
printf("%d\n", (int)b);
return 0;
}
The text was updated successfully, but these errors were encountered: