<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63893>63893</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Wrong code at -O2 on x86_64-linux_gnu (a recent regression in Two-Address instruction pass)
</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>
This looks like a recent regression. Clang at -O2 produces the wrong code. `opt-bisect-limit` suggests that the issue might be in ` Two-Address instruction pass`.
Compiler explorer: https://godbolt.org/z/G6vxTTzPr
```console
% cat a.c
int printf(const char *, ...);
short c;
int f, q = 3, r, t, z, ae_y;
char g, b, h, m, o, s;
static long i_0_0 = 23772937180;
static char *j = &b;
static char **k[5] = {&j};
static char ***l = &k[4];
long n;
static long *p = &i_0_0, *e = &i_0_0;
int *ae(int *ad) {
long u;
int *v = &f;
af:
for (;;) {
*j = 8;
int w;
for (; o; o--)
if (*j + *p + g)
goto af;
if (*ad)
;
else{
for (; t <= 1; t++) {
int *x = &r;
for (;; s++) {
*v = 9;
if (q + *ad)
break;
}
if (g)
goto af;
for (; s + m; m++)
;
u = *e;
*e = (unsigned)u;
*x ^= (int)n + m;
*v = c;
if (*v)
;
else {
ad = &ae_y;
return x;
}
}
}
for (; h;)
;
}
}
void ag() { char ****a[] = {&l, &l}; }
int main() {
ae(&z);
printf("%ld\n", i_0_0);
}
%
% clang-tk -O0 a.c && ./a.out
2298100700
%
% clang-tk -O2 a.c && ./a.out
23772937180
%
% clang-tk -v
clang version 17.0.0 (https://github.com/llvm/llvm-project.git 46333f71f8e0d6444a9b2c9e063aedb83ebb9735)
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/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Candidate multilib: .;@m64
Selected multilib: .;@m64
%
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vs2O4ygQfhpyKdnC-P-QQ5LejPY0K21Le2xhm9hME8gATmf66VfgvyTdm9mVZlsRjeGrj6qiqCpqDG8lY2uUblH6tKK97ZRem46qoOtpIPiqUs2P9XPHDQilXg0I_sqAgmY1kxY0azUzhisZwk5Q2QK1EHwlcNKq6WtmwHYM3rSSLdSqYSGgDKuTDSpuWG0DwY_cogyD6duWGevw1HohbkzP4MjbzkLFgEsnCs9vKtg0jTsUuDRW97XlSsKJGoMyHALCTwhvhnGnjicumAZ2OQmlmUbxBjprTwbFG0T2iOxb1VRK2FDpFpH9OyL7L9n58vz8_oe-ZkIZHn61kkYJNq6SFGpqgYb1sMClhZPm0h4QKRzUQt1RDYhsENlBGIaIlCjeDmjTKW2hnr-d9MHhvgOKnyB2U-0G64Z3N1D28mPGe-rWLVdu6NxwdINyg1nOsdTyGoS7BP6CX7CnJ3GekzLOowLfIyedv3kgIll1j7gya_OK0m2K0qcBnG8Ryb6h_OmRCCIbMXE78QSlC97rKT_VHpHNaZLzljhDEdmw28VrhyKyoQyRYpo3iJReS4-AgbefRQBG4HmiPMx79ODCZoQdlDOmcJvx9o4TFucVV8wD99vNykIDyg9B4EJk3gfgBw_whGQ7uoBs3cVPuFZZBfRwe9Qk5i2-JryBMWHYjeY3KllA8c6ZEfkvRLb-d2fsZBkim8vkNX1zyi2t4zIPuGDx__JYRoO-T074YNbwV2lGXz-c7cLxVl1P9hMX3jnD-KOPbnqctf-g-T1BP3pkwz5qtQRu0UufiZ1R_WfAC6D0txHLpUWklLM6H8CD7-oPW3NMnP-N5i40Prsc2kyXfJONFoBmttcSLj-7hpvPm48rr3fD8_qHAJ6l5slZ8QZo6-30sXWfeFzsDOXuKmGJIZFkYkh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