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

    <tr>
        <th>Summary</th>
        <td>
            [RISCV] Failure to use rev8 and 4 byte stores. Possibly due to alignment tracking
        </td>
    </tr>

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

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

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

<pre>
    With -march=rv32gc_zbb, gcc uses two rev8 instructions and two word sized stores. clang emits shifts and byte stores. https://godbolt.org/z/bWxrnM8rv

```
#include <stdint.h>
struct a {
 uint64_t b;
  uint8_t block[64];
};
void c(struct a *ctx) {
  uint64_t d = ctx->b;
  (ctx->block + 64 - 8)[0] = d >> 56;
  (ctx->block + 64 - 8)[1] = d >> 48;
  (ctx->block + 64 - 8)[2] = d >> 40;
  (ctx->block + 64 - 8)[3] = d >> 32;
  (ctx->block + 64 - 8)[4] = d >> 24;
  (ctx->block + 64 - 8)[5] = d >> 16;
  (ctx->block + 64 - 8)[6] = d >> 8;
  (ctx->block + 64 - 8)[7] = d;
}
```

I believe the issue has something to do with determining alignment of the bytes stores. RISC-V requires strict alignment of word stores. The store is aligned, but the compiler isn't able to see it.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMlM2O4zYMx5-GvhAJ9GE7zsGHZDIB9lCgaIvd48KSOLa6spVKcubj6Qs52Um7uQQQYIPij6Io_tnFaPuJqIVqD9Wh6OY0-NAmfzpR0IXy5r39ZtOAq7ELegB5CGcpev39QykQT9hrjXOkiOnVY6Bzg3aKKcw6WT9F7Caz7Lz6YDDaDzIYkw8U16hdN_VIo00R42Bf0sVbvSf69BlSOkWQOxBHEMfeG-VdWvvQgzh-gDiqb29h-q0JZ2C7vGp2XWwHQtpJu9kQgnyKydgprQeQz8B2lwSxQ9jsge1wtlOqy-8JFcjFsFiabHBe_4BqX5dQHS6bsLn-nL01qEE0t3Bip9MbiO3PwLfIBkEeUKe3Fcjnz2NAND9N-SAEsce6xBU2ILZQ7RlUhwXM-DPIZ6zqR1l-x5bNo6y4Z9mjrLxjpXiULe9YUT7KVncsf7hW9R37cKk2n-itPX7pRLb7goqcpTNhGghtjDPh0EWMfqQ02KnH5NF4fM1KM5QojHbK5s7ZfhppSuhfFjbLI37q448vfz6tvmKgf2YbFnuwuRP_S12kdwX-Gq7iQhsvbmSyjNWclvDajyfrKKCNE4hNwk45yslFIrRpXZhWmq3cdgW1fFOV5baWXBRDS8QlN7xpthUxznW3pZpzoesXVUnFWWFbwUTFGlbzmlVcrF-M5NJsNsQN65jaQslo7KxbO3ces8aLpU4tr4SUrHCdIheXMSXERK-XKoLIrVqENkMrNfcRSuZsTPEWJtnklvmWq_U1P9exs24Oy73mSJexlWdP-f_p87uP0Sr3jmZefG9lTaHTP-zUF3Nw7S9DyqZhVmvtRxDHnMP1szoF_zfpBOK4ZB5BHK9XO7fi3wAAAP__6LucZA">