<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64060>64060</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Wrong code at -O3 on x86_64-linux_gnu (recent regression on `Early Machine Loop Invariant Code Motion`)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
shao-hua-li
</td>
</tr>
</table>
<pre>
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
```console
% 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
%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