Closed
Description
This looks like a recent regression. Clang at -O3 produced the wrong code. opt-bisect-limit
suggests that the issue might be in Early Machine Loop Invariant Code Motion
.
Compiler explorer: https://godbolt.org/z/edvh1f84c
% cat a.c
int printf(const char *, ...);
int a, e, f, g, i, h;
long b = 0xFE0BD880D91824DA;
long *c = &b;
char d;
int j[5];
int m() {
for (; *c < 9;) {
h = 0;
long *l = &b;
a && (*l &= -(unsigned)(0 <= 9));
return 0;
}
return 0;
}
int main() {
short k;
f = 0;
for (; f <= 1; f++) {
k = g + b;
for (;;) {
for (; e <= 1; e++)
for (; a <= 1; a++)
;
g = 0;
if (j[i])
break;
j[0] = 4;
if (k)
for (; d; d++)
;
}
}
m();
*c = 0 < b;
printf("%d\n", (int)b);
}
%
% clang-tk -O0 a.c && ./a.out
1
% clang-tk -O3 a.c && ./a.out
0
% clang-tk -v
clang version 17.0.0 (https://github.com/llvm/llvm-project.git 20245ed4dea067d281e5d091badf7bcffbb1445b)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /zdata/shaoli/compilers/ccbuilder-compilers
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Candidate multilib: .;@m64
Selected multilib: .;@m64
%