<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64598>64598</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Wrong code at -O2 on x86_64 (recent regression in GVN pass)
</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>
Clang at -O2 emits the wrong code.
Bisected to 84bcfa0e1b34938d1d11a44e9e17c6e222dd2f42, which was committed by @weiguozhi
Compiler explorer: https://godbolt.org/z/rW9chv3hj
```console
% cat a.c
int printf(const char *, ...);
int a, d, e, f, h, j, t, q;
char c, s;
signed char g;
signed char *i = &g;
int *k = &h;
int **l = &k;
signed char **m = &i;
signed char ***r = &m;
static signed char ****n = &r;
long o, u;
int p[7];
void v() {
t = 0;
for (; t < 9; t++) {
q = 0;
for (; c + q; q++)
p[q] = 3;
}
}
void w(long x, char y) {
for (; o;) {
v();
s = x;
u = y;
}
}
int main() {
for (; d <= 3; d++) {
e = 0;
for (; e <= 3; e++) {
int *b;
f = 3;
for (; f; f--) {
w(****n, **l);
b = &j;
*b = **l + ***r;
}
}
}
for (; **l;)
;
printf("%X\n", a);
}
%
% clang -O0 a.c && ./a.out
0
% clang -O2 a.c && ./a.out
Segmentation fault
%
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VU1zozgQ_TXtS5cpaD4MBw7YLu9t57BVO3vbEkKAMoAcJOJkfv2UFGODnZkU1ZFbT6-7n6QW01o2gxA5xHuIjxs2mVaNuW6Z2rYT23ZyU6rqIz90bGiQGdx-IxS9NBpNK_AyqqFBrirhgX8Ev_i0e6kFN6JCozCNSl4zXwRlGGVhWgVVELAoEpkIdjwRRFRVVEcEdMBLK3mLF6aRq76XxlKUHwiRfxGymdTPVuIyzkH1Z9mJEcX7uVOjGCEssDXmrCEsgE5Ap0Z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