<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/106700>106700</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[RISCV][SiFive] How to prevent reordering of VCIX instructions when using intrinsics and inline-asm?
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
michalt
</td>
</tr>
</table>
<pre>
We've run into an interesting problem when writing some high-performance kernels that use the VCIX instructions.
In a few places we wanted to use both intrinsics and a small amount of inline assembly (it's performance critical and writing it manually was a noticeable win). This turns out to be tricky because the compiler reorders the intrinsics and the inline-asm block. VCIX instructions should not be reordered across each other, and this is accomplished through `VCIX_STATE` ([code](https://github.com/llvm/llvm-project/blob/1b32c3e2985f89900030289eaa44e3d92cab85af/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp#L147-L148), #77049). This works fine when using intrinsics, however, we couldn't find a way to indicate that `VCIX_STATE` gets clobbered by inline-asm.
Is this something that's possible and we just missed it? If not, what would be the best approach here?
@4vtomat @topperc @michaelmaitland Any suggestions would be very welcome! 🙂
Simplified repro: https://godbolt.org/z/KcT3asrKa
![image](https://github.com/user-attachments/assets/c474a902-bc97-4a8b-a9bb-7e6e8b6020b5)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUlE9v4zgPxj-NciESKLKd2Icc2ulrvMXMaVrM7m1ByYytqSwZohwj--kXcqbTzh9gsZfIUCDyIZ8ficy290QnUd2L6mGDcxpCPI3WDOjSRofuevqDhDpeCOLswfoUANeTInGyvocpBu1ohGUgD0u06yWHkWCw_bCdKJ5DHNEbgheKnhxDGjDBzARpIPjy4fFPsJ5TnE2ywfNOyAch726_jx4QzrTA5NAQw0KwoE_UQQprCB3SkPVE69kaBvQdIPCIzgGOYfYJwhmsd9YTIDON2l1BqNomoY4M7_WZrN6gW4O8lmITjOhndO4KCzIg-JCsI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