<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63019>63019</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Invalid optimization around loops
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Nilstrieb
</td>
</tr>
</table>
<pre>
come from https://github.com/rust-lang/rust/issues/112061
alive2 complains about an optimization in the LLVM IR: https://alive2.llvm.org/ce/z/fyzhJ3
The code is quite big and I have made attempts to minimize it, but I didn't quite figure out the tooling, so I'm not sure whether my not very good minimizations would be useful. Everything can be found on https://github.com/Nilstrieb/rlo-issue-112061 if desired.
The program prints `11` on O0/O1 and `22` on O2.
This small helper must be linked in to run the program:
```c
#include <stdio.h>
#include <stdint.h>
void print_var(uint8_t x) {
printf("%d", x);
}
void fn12_rs();
int main() {
fn12_rs();
}
```
I can't say for sure that the IR emitted by rustc is free of UB, but I suspect that this is the case. The code is really sensitive to small changes and rustc's constant propagation pass actually masks the miscompilation and has to be disabled.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VN2OozgTfRpzU0oEpgPJBRf9M5Hyab4dabS7ty2DC6gdY7Muk970069s0j2ZXs1IkQn41Kmyz6lSzDRYxEbsHsTuKVNLGJ1vfiPDwRO2Wev0penchNB7N8EYwsyivBfyKORxoDAu7bZzk5BHv3DYGGWH638hj8S8IAt5LAqZV4XIn0R-v67K0BkldG6ajSLLoFq3BFAW3BxoolcVyFkgC2FE-Pz5z__D6aso7z9UsNJsjTlPW-dj6g6FPL4Keewvr-P_ytucv48IndMIxPD3QgGhpQGU1XCCUZ0RJqURVAg4zYEhOJjIxloQKAj5CO0S4ASatBWyDleOnobFI8TqY6nBOUPxEh6BHZyErCewLgBH0MuIYUQP0yV9O6O_wOCcfkuUDs3w4hajoUVYGPvFbOFTRIaR7ACdsnGnd4vV4OyvFH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