<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/162512>162512</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [RISC-V] Miscompile at -O3
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ewlu
      </td>
    </tr>
</table>

<pre>
    Testcase:
```c
int a;
long long ad;
int w[14];
_Bool x[14];
unsigned short b[14][14][14][14];
void c(int w[], _Bool x[]) {
  for (short y = 0; y < 014; y++)
    for (_Bool z = 0; z < 1; z = 1) {
      for (int aa = 1; aa < x[10] + 2; aa++)
        b[y][y][z][a] = 0;
      for (int ab = 1; ab < x[10] + 12; ab++)
        a -= w[ab];
 }
}
int main() {
  for (int y = 0; y < 4; ++y)
    for (int ag = 0; ag < 4; ++ag)
      for (int ah = 0; ah < 4; ++ah)
        for (int ai = 0; ai < 4; ++ai)
          b[y][ag][ah][ai] = 040;
  c(w, x);
  for (int y = 0; y < 4;)
    for (int ag = 0; ag < 4;)
      for (int ah = 0; ah < 4;)
 for (int ai; y < 4; ++y)
          for (ag = 0; ag < 4; ++ag)
 for (ah = 0; ah < 4; ++ah)
              for (ai = 0; ai < 4; ++ai)
 ad ^= b[y][ag][ah][ai];
  __builtin_printf("%llu\n", ad);
}


```

Commands:
```
# -O3
$ /scratch/ewlu/daily-upstream-build/build-gcv/bin/clang -march=rv64gcv_zvl256b -O3 red.c -o user-config.out -fsigned-char -fno-strict-aliasing -fwrapv 
$ QEMU_CPU=rv64,vlen=256,rvv_ta_all_1s=true,rvv_ma_all_1s=true,v=true,vext_spec=v1.0,zve32f=true,zve64f=true timeout --verbose -k 0.1 4 /scratch/ewlu/daily-upstream-build/build-gcv/bin/qemu-riscv64 user-config.out
32
# -O2
$ /scratch/ewlu/daily-upstream-build/build-gcv/bin/clang -march=rv64gcv_zvl256b -O2 red.c -o user-config.out -fsigned-char -fno-strict-aliasing -fwrapv 
$ QEMU_CPU=rv64,vlen=256,rvv_ta_all_1s=true,rvv_ma_all_1s=true,v=true,vext_spec=v1.0,zve32f=true,zve64f=true timeout --verbose -k 0.1 4 /scratch/ewlu/daily-upstream-build/build-gcv/bin/qemu-riscv64 user-config.out
0
```

Found via fuzzer
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsVluPqzYX_TU7LxaR2VySPPAwgYP0PRx9vZ2-RgYMuDWQ2oaZya-vbMhtMtWZUas-NUJ4-7K8NmuZHZjWouk5TyDaQ5St2GjaQSX8WY6rYqhek1-4NiXTHIInoE8Q0_kqgT6J3hAGwR7okxz6hrgbq-YRO_kM0d4PIcrmocN-GCR5uR8ce5dARXQ7KEOKy-xftQ41DaIiJeD2TGNnMCVXCjewI7CxywmpB0UAtzPJK4EgIxSCvQtTQv3QdQD37to5zAU173q6ok4O5Z_DjPi3XDdIJxFblgT7OU5nDShEGQHcE5xn3pLbn5XjdX76pTnNDXPgJZ93WYsb1uIdVn-mLd6jZcSzYCssKy6iE9hk9gy4u-XomOgBt-_obGcfVHYaz3SvDxq7nJsrxMV3GNbcJnkLa29g7QOsvX-2W6C4AYoHoLgH3rnBmqVtl1ZcDAkvltgD-myP5YvdKfiYQp9R5nOCLKvvBPieO3d7f9Cf8-pP2XJP9DFjWEUg-mJXfs-Zs_iHQzEKaUR_OCrRm9qdXgSMpBwhSnvXSW0ROxu2nHl6V_3mbjp0Hesr_aY02hgD4v0_cFFIAHNdKmbKFjC3lRUwr5iQr9541EZx1nk2qwowd63XlJON7cuVl5L1DfE6psoWgkxNcdiU0-E0SYziwrIQxat1SbyBjJorrxz6WjTrYTTEq-fa6pUtU8Sr-8HTRonSeEwKpoXduH5W7DiRJdUfv3z9dkh_-LYwAaaT5D0EGUYxYKqm6WDYgUl58DUEmVEjX4a7x-HpJuQv5qCPvIQgm_w1BUxPEw-wvi45TTwOz31iR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