<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57780>57780</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[LICM] wrongcode at -O2
</td>
</tr>
<tr>
<th>Labels</th>
<td>
loopoptim
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
fhahn
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
JonPsson
</td>
</tr>
</table>
<pre>
Bisected to 0776c48 "Recommit "[LICM] Only create load in ph when promoting load or store doesn't exec."
This program is supposed to print 0:
clang -O0 wrong0.i -o a.out ; ./a.out
0
clang -O2 wrong0.i -o a.out ; ./a.out
5
```
int printf(const char *, ...);
int a = 0, b = 1;
short c = 0;
long d = 0;
int *e = &b;
int f(int g) { return a / g; }
int main() {
int h = 10;
i:
if (h) {
int j = 0;
if (d) {
long k = 4;
l:
if (b)
goto i;
}
h = 0;
for (; h < 6; ++h) {
if (f(*e))
;
else
goto l;
c = 5;
for (; b; b--)
;
}
}
printf("%d\n", c);
}
```
[testcase.tar.gz](https://github.com/llvm/llvm-project/files/9583448/testcase.tar.gz)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVNuOmzAQ_Rp4GQUZc80DD7koUqtWW1X9AWMc8NbBCJtu26_v2CRZwq6qVrJ8Gc-ZOWPPTK2bX9VeGsGtaMBqIEWR87SEgNKvguvLRVq3D7L9pw-Hz0F2hKde_QI-CmYFKM0akD0MHbx0AtdRX7SVfTvf6BGM1aOARgvTB7SwIH4KHjmD5BiQ3Tx_66Rx0HZkF8CtmYZBm5nPMMreAgmS3RLBFUMfmycCL6PuWxJJ2GhgkZ6QbbIH9HDyp1mdPKLov6GypccgJ9fhj46Up3YOaMl1byzwjo34VLuAHiCK0NYWbS5NOAxDR0cMB3Vqv43vSqbTI1q5KtykColCsxI6S-hJeHFA8_odT46YW1skAkGxh1HYaewdA3pCKcYbFMc16sIk_lN5xcxyAHfTzXTJ2tX9Z1DtjLbLbgWe4c-rELzc6zdv9AF81N89JH2AqIW7VxO1e-yFFKDVmDvyAXqP1h26d-ictfu_0r2Muz5A7h-J7nG8Derm--yfaycchTWLB_MAQhnxDk21UptTIFtJF-xqP202f_e3iHf10fCauq4SadYE2aH32wPwh8S9Ax_T_zpneyuM5cyIyLIxan9jf3AZYO1g3EfRE45W2m6qI-wleFDqx23ZYMU_Y9_B41kqYXDdZmWSpkjqtLZ7i3SeQ1HFeZ4kNE8JDZsqabbJloVWWiWqRavyZc51I4BZV_fhNKrqv9lJYyZPLyuKkoRdxWlMsepJXeQ5p2WWsowWnDSCYefksQgVq_GvHRN8VKX1oAcrL76NHkNZUUIp2cZ5HJM8pRE9l3HKBOdJXiaU8CAlAutQRY5HpMc2HCtPqZ5ag5dKGmteL5kxsu2FuLo7d6zrr67YZLGpVB91_8UY3Yc-ksqH8Qch25Ra">