<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/107891>107891</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[RISC-V] Miscompile with RISC-V Vector Peephole Optimization
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
patrick-rivos
</td>
</tr>
</table>
<pre>
Testcase:
```c
long b;
long c[5];
int d[25];
int main() {
for (long g = 3; g < b + 23; g += 4)
d[g] = g * g ?: c[g];
__builtin_printf("%u\n", d[3]);
}
```
Commands:
```
> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/clang -march=rv64gcv -O3 red.c -o user-config.out -fsigned-char -fno-strict-aliasing -fwrapv
> QEMU_CPU=rv64,vlen=128,rvv_ta_all_1s=true,rvv_ma_all_1s=true,v=true,vext_spec=v1.0,zve32f=true,zve32x=true,zve64d=true,zve64f=true,zve64x=true timeout --verbose -k 0.1 4 /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/bin/qemu-riscv64 user-config.out
4294967295
> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/clang -march=rv64gcv -O3 red.c -o user-config.out -fsigned-char -fno-strict-aliasing -fwrapv -mllvm -opt-bisect-limit=131
...
BISECT: running pass (131) RISC-V DAG->DAG Pattern Instruction Selection on function (main)
BISECT: NOT running pass (132) RISC-V Vector Peephole Optimization on function (main)
...
> QEMU_CPU=rv64,vlen=128,rvv_ta_all_1s=true,rvv_ma_all_1s=true,v=true,vext_spec=v1.0,zve32f=true,zve32x=true,zve64d=true,zve64f=true,zve64x=true timeout --verbose -k 0.1 4 /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/bin/qemu-riscv64 user-config.out
9
```
-opt-bisect-limit points to `RISC-V Vector Peephole Optimization`
Found via fuzzer. First detected on a build from the 6th of September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