<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/107414>107414</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[LoongArch] Miscompilation with O2
</td>
</tr>
<tr>
<th>Labels</th>
<td>
miscompilation,
backend:loongarch
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
dtcxzyw
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dtcxzyw
</td>
</tr>
</table>
<pre>
Reproducer:
```
#include "csmith.h"
int32_t g, f=2, b;
int main() {
g = (3202030857 / f);
b = safe_lshift_func_uint16_t_u_u(1, g);
printf("%d\n", b);
}
```
```
> clang -O0 test.c -w -I../csmith-install/include && ./a.out
1
> clang -O2 test.c -w -I../csmith-install/include && ./a.out
16
```
llvm version: 03d5b7ca3d83eee3514318ef8934ba26bc3d7fa9
```
(ssh)dtcxzyw@ibarakasen [ llvm-project@main ] $ lscpu
Architecture: loongarch64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 48 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Model name: Loongson-3A5000
CPU family: Loongson-64bit
Model: 0x10
Thread(s) per core: 1
Core(s) per socket: 4
Socket(s): 1
BogoMIPS: 5000.00
Flags: cpucfg lam ual fpu lsx lasx crc32 complex crypto lvz lbt_x86 lbt_arm lbt_mips
Caches (sum of all):
L1d: 256 KiB (4 instances)
L1i: 256 KiB (4 instances)
L2: 1 MiB (4 instances)
L3: 16 MiB (1 instance)
NUMA:
NUMA node(s): 1
NUMA node0 CPU(s): 0-3
(ssh)dtcxzyw@ibarakasen [ llvm-project@main ] $ uname -a
Linux ibarakasen 6.10.7-aosc-main #1 SMP PREEMPT_DYNAMIC Tue Sep 3 03:58:16 UTC 2024 loongarch64 GNU/Linux
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVstu2zgXfhp6cyCBF9288MKJ4x_FHzdGkyxmZVAUJXF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