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

    <tr>
        <th>Summary</th>
        <td>
            [RISC-V] Miscompile at -O2
        </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
int printf(const char *, ...);
int a, c = 1;
int b[2];
int main() {
d:
  for (; a < 8; a += 1) {
    int *e = &c;
    if (&b[1] == e)
      *e = 0;
 }
f:
  if (0) {
    goto f;
    goto d;
  }
 printf("%d\n", c);
}
```
The condition `if (&b[1] == e)` should never be true.

Commands:
```bash
> /scratch/tc-testing/tc-mar-4-llvm/build/bin/clang -march=rv64gcv -O2 red.c -o red.out -fno-strict-aliasing
> /scratch/tc-testing/tc-mar-4-llvm/build/bin/qemu-riscv64 red.out
0
> /scratch/tc-testing/tc-mar-4-llvm/build/bin/clang red.c -o red.out -fno-strict-aliasing
> /scratch/tc-testing/tc-mar-4-llvm/build/bin/qemu-riscv64 red.out
1
```

Godbolt: https://godbolt.org/z/eEfqjf5rr

`-opt-bisect-limit` points at `InstCombinePass`

Discovered/tested using version 57592e9ae78e16ffe4f2a2cd3190c422bcdba5a0 (not bisected)

Found using fuzzer
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVE2P2zYQ_TWjy0AGPdTnQQd_REUORYo26J2iKIupRDok5aL76wtKu7Y3KXppgQCGTA45772ZeZLwXl-MUg3kR8jPiVjCaF1zFcFp-Ufq9M36pLP9X81n5YMUXgE_ADsDO0DBtp_c9toEvDptwgBUSWt8QDkKh0AHoBPudjugGvjxcVvEuETgZ9y_O-ggPxLk53fBWWgDVAHVCOVrvL-rQRxs5KqAH1Eg8BO-Lem4MTwnIiJGUKCDWgUAFfJOt54OKxoVUcwe8nO8Fm-qWMb9Gj4g2CMfyvO2Gp4EbojsOx0XGywO78jXUP8UugM-WgxEQHkP-cmsyxPK5wbfM-5z2rafR4XSml4HbQ1Cwf690IKhH-0y9WjUTTnsFAa3qN0r9vo82XkWpvffW6MTfnwN8Q8I1HrpRJAjUBtkGpQP2ly2zSxcmqXTdJuB2m7RUx__48hbOQlzwXhDjsDP7lZkF3nD9BOhU_1OYmrXhV0CpoOxqY_uDamYtPCR4D8r-KrmJXXay1uRvVFtqOz_Ku-HV7L_R7tsz59s39kpAD_gGMJ1nTS1QO1lO9hZF6lfgFr1Yfj6Zcide86HgqX2GtJOeyVDOulZh2itq9UmeBQhGvGj8eFk504b9Yvw_hsJZ-2lvSmnYi2xWtXjEnuCN-V89HJe5jWpWqiyUvtiGFQ2kCDZ833NZEbUyb4TuWDR7sYG3MREvPqZqLWLeYMelpcX5ZK-4X3Na5GoZl-yumAF2xfJ2NS9qkTZ9aLiIi-LciiqSuZs3_VDVXBVJrohRhnjLGfEOS92NaOqzkRRDFTlVckhY2oWetrFYcUuJtr7RTUVr7MymUSnJr9-m4mM-hPXw_i25-fENTEn7ZaLh4xN2gf_QAk6TOtH_dePv53S3-Nb_XNs4HzVk4r9Tj9Rsrip-WacOoxLt5M2GufVPyvL1dkvSgagdpXggdpV4t8BAAD__16vywg">