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

    <tr>
        <th>Summary</th>
        <td>
            RISCV `-mno-strict-align` generates problem instructions for some targets
        </td>
    </tr>

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

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

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

<pre>
    When passed ` --target=riscv64-linux-gnu -march=rv64gcv -mno-strict-align`, clang-18 and up generate `vle64` and `vse64` instructions for the following code despite receiving byte pointers:

```C
__attribute__((noinline))
void vector_memcpy(uint8_t* d, uint8_t const* p) {
  __builtin_memcpy(d, p, 16);
}
```
https://godbolt.org/z/x9ddoehTY

If the pointer is unaligned then my Kendryte K230 board (C908) will raise a bus error trying to execute this.

However, `-mno-strict-align` offers big performance gains for some scalar code, where unaligned access is supported just fine. There seems to be no way to specify that vector code should respect alignments while scalar code can do unaligned access.

Scalar code "seems to work" when you cast a byte pointer to a wider type when it's unaligned, but there are other issues with that and most portable code prefers `memcpy()` with the expectation that the compiler will optimise it correctly.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VFGPmzgQ_jXOy4gIHJaQBx7aXUVX9e1a3emeImMP4J6xkT0ky_3600C2Tbt3EgLGHnvm--abUSnZ3iM24umjeHrZqZmGEJs0FG0ItGuDWZo_B_QwqZTQgKhyyDJSsUcSh5dok75WZeasn1-z3s-QjSrqgbeuVdnrK2SjD1miaDVlytneiyoX8hm0U77PihqUNzBP0KPHqAg5xNVhVXIo3mM73W3rE8VZkw0-QRci0IDQBefCzfoedDAIBtNkCSGiRnvl5XYhhClYTxiTOHwQ-YvI395Vvj3Pm325KKJo25nwchGyFrL2wXpnPQp54md1uwZr4IqaQryMOOppEbKeraf6QkJ-AMMQ7zbo4NO6Ogl5AnH8uN0BcLm0s3Vk_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