<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/98462>98462</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] performance inconsistency at optimization level -O2
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
bi6c
</td>
</tr>
</table>
<pre>
```c
#include<stdio.h>
#include<stdint.h>
int32_t a = 1L;
uint64_t b = 18446744073709551615UL;;
uint64_t c() {
uint8_t d[8];
int32_t *e = &a;
int f;
for (f = 0; f < 8; f++)
d[f] = 79;
g:
*e = 1 ^ d[6];
b--;
if (b)
goto g;
}
void main() {
c();
printf("%d\n", a);
printf("%d\n", b);
}
```
Hello, we are using clang to compile the above code in Ubuntu 22.04.3 LTS.
We found that there is a performance hog when we compile it with llvmorg-18.1.8 and llvmorg-19-init at optimization level 2.
When we compiled with llvmorg-17.0.6, the execution time was less than 1 second.
```console
$ ../compiler-builds/llvmorg-17.0.6_build/bin/clang -fsanitize=undefined -fsanitize=address -g -lgcc_s --rtlib=compiler-rt -O2 testcase.c -o exec
$ time timeout 5s ./exec
78
0
real 0m0.008s
user 0m0.008s
sys 0m0.000s
$ ../compiler-builds/llvmorg-18.1.8_build/bin/clang -fsanitize=undefined -fsanitize=address -g -lgcc_s --rtlib=compiler-rt -O2 testcase.c -o exec
$ time timeout 5s ./exec
real 0m5.002s
user 0m5.002s
sys 0m0.000s
$ ../compiler-builds/llvmorg-19-init_build/bin/clang -fsanitize=undefined -fsanitize=address -g -lgcc_s --rtlib=compiler-rt -O2 testcase.c -o exec
$ time timeout 5s ./exec
real 0m5.002s
user 0m4.994s
sys 0m0.008s
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVU2P5CYQ_TX0pWSEsWnbBx9mpreVw0p7SFY5jjCUbSIaWgbPZPbXR9j9OZOJkltWsmyoelX1eC5Ah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