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

    <tr>
        <th>Summary</th>
        <td>
            RISCV64 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 a;
int b[8][6];
int c;
int main() {
  signed char f = 0;
  for (signed char g = 0; g <= 5; g++) {
    f = b[g + 2][0] % 8;
    b[0][g] = f + (long)1;
  }
  for (int d = 0; d < 6; d++)
    a = b[c][d];
  if (a == 1)
    return 0;
  else
    return 1;
}
```
Commands:
```bash
> /scratch/tc-testing/llvm-feb-5/build/bin/clang -O2 -march=rv64gcv red.c -o user-config.out
> QEMU_CPU=rv64,vlen=128,v=true,vext_spec=v1.0,Zve32f=true,Zve64f=true /scratch/tc-testing/llvm-feb-5/build/bin/qemu-riscv64 user-config.out
> echo $?
1
> /scratch/tc-testing/llvm-feb-5/build/bin/clang -O1 -march=rv64gcv red.c -o user-config.out
> QEMU_CPU=rv64,vlen=128,v=true,vext_spec=v1.0,Zve32f=true,Zve64f=true /scratch/tc-testing/llvm-feb-5/build/bin/qemu-riscv64 user-config.out
> echo $?
0
```
Bugpoint/asm:
[bugpoint-and-asm.zip](https://github.com/llvm/llvm-project/files/14174211/bugpoint-and-asm.zip)

opt-bisect-limit points to `InferAlignmentPass`

Discovered/tested using a7bc9cb6ffa91ff0ebabc45c0c7263c7c2c3a4de (not bisected)
Found using fuzzer.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkVU2PpDYQ_TXFxaJljPk6cJhuFmkPUTYfm8NeVsYU4ATsjm1IMr8-MvR0z2Q3h0S5RULgsl-9en5lQDinRo1YQ3aGrInE6idj66vwVslfYqs246LO9H_UP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