<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58340>58340</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Wrong code at -O3 on x86_64-linux_gnu (IndVarSimplifyPass)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
shao-hua-li
</td>
</tr>
</table>
<pre>
```console
% clang-tk -v
clang version 16.0.0 (https://github.com/llvm/llvm-project.git 0c1a3da8ea1f0e024ebfd85c7532926f26c6bde5)
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/11
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
%
% clang-tk -w -O0 a.c && ./a.out
2
% clang-tk -w -O3 a.c && ./a.out
9
% cat a.c
void printf();
long a;
int b, d, e;
int *c;
void f(int *g) { *g = b; }
char h() {
long *i = &a;
for (;;) {
int j = 0;
for (;; a++) {
b = 2;
for (; b <= 8; b++) {
c = &j;
if (j)
break;
}
if (j)
break;
j = 1;
}
e = 3;
for (; e <= 8; e++) {
int k;
d = 3;
for (; d <= 8; d++) {
*i = k;
f(&k);
}
if (a)
return 0;
}
}
}
int main() {
h();
printf("%d\n", a);
}
%
```
Compiler explorer: https://godbolt.org/z/WTce7z7Md
`opt-bisect-limit` indicates the issue maybe in `IndVarSimplifyPass`
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVVtv2zoM_jX2C2HDli-JH_ywJujBHg42YMPZ46BbYrWKFchy1-7XH0pOncRtAwxYoNgSxe8jRZMUM-KljepsGtz0g9EyyrZR9ikiFXBN-33iHiF5moRBAE_SDsr0kNdplmYQkXX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