<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/106367>106367</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Miscompile related to licm-promotion
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vfdff
</td>
</tr>
</table>
<pre>
* test: https://gcc.godbolt.org/z/GYa8MhcW1
```
unsigned long Run_Index;
void report() {
fprintf(stderr,"COUNT|%ld|1|lps\n", Run_Index);
exit(0);
}
/* main program, corresponds to procedures */
/* Main and Proc_0 in the Ada version */
int main (int argc, char *argv[])
{
...
int duration = atoi(argv[1]);
Run_Index = 0;
wake_me(duration, report);
for (Run_Index = 1; ; ++Run_Index) {
} /* loop "for Run_Index" */
}
```
* the Run_Index is a global variable, it should not be promoted out the loop body ?
> now, the **Run_Index** is promoted out the loop body, so it is always return **1** .
```
~/test/issue5187 » clang -O0 test-code.c && ./a.out 10
COUNT|3708645939|1|lps
------------------------------------------------------------
~/test/issue5187 » clang -O2 test-code.c && ./a.out 10
COUNT|1|1|lps
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyklM-P6zQQx_-a6WW0kTNpmuSQQ38QxGF5CIEQp5UTO6nBtSvb6b7Hgb8d2Zv2ZVcIgbD6I61nPvOdGY-592oyUrZQHqA8bfgczta1t1GM46a34ksLtMcgfYBij3gO4eqh2AN1QN00DNlkRW91yKybgLo_gLpvf-X183n4JQd2AraHHVte6edsUkCB2poJf5zNy3dGyM9QHBbz9HmzSqCTV-sCUA3UIFQPg2a8OmXCCFT7IKRzQEcgOn76-fufoDoClVpAdcyhOuqrh_JogAjouIpGzSpgIz-rGIa9-7s6rQWlhPd44crg1dnJ8UskDtY56a_WCI_Bxp1BitlJj8sCSq5rxnNkcCPwB2eHF4bKYDhL3AuON-m8sgbXa01QJrxJAKrjM3fTkGScuQPWA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