<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/78647>78647</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
RISC-V vector intrinsics construct unshared constant-zero temporaries
</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>
If you need two vectors of zeroes with different types, you might write something like:
```C
int f(vuint8m1_t v8, vuint16m1_t v16) {
const vuint8m1_t z8 = __riscv_vmv_v_x_u8m1(0, __riscv_vsetvlmax_e8m1());
const vuint16m1_t z16 = __riscv_vmv_v_x_u16m1(0, __riscv_vsetvlmax_e16m1());
return __riscv_vmv_x(__riscv_vredsum(v8, z8, __riscv_vsetvlmax_e8m1()))
+ __riscv_vmv_x(__riscv_vredsum(v16, z16, __riscv_vsetvlmax_e16m1()));
}
```
Or you might write the equivalent expressions inline in other code. Either way this results in separate temporaries -- a wasted register and an unnecessary `vsetvli`/`vmv.vx` pair.
You can work around it with this:
```C
int f(vuint8m1_t v8, vuint16m1_t v16) {
const vuint8m1_t z8 = __riscv_vmv_v_x_u8m1(0, __riscv_vsetvlmax_e8m1());
const vuint16m1_t z16 = __riscv_vreinterpret_u16m1(z8);
return __riscv_vmv_x(__riscv_vredsum(v8, z8, __riscv_vsetvlmax_e8m1()))
+ __riscv_vmv_x(__riscv_vredsum(v16, z16, __riscv_vsetvlmax_e16m1()));
}
```
It'd be helpful to fold these together if possible. I'm not sure what all the constraints are.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkVU2P4zYM_TXKhUhgyx5_HHzYmWmAORVogQI9BbJNx-rKkitSzsevL2QHs9PtophzCwgJKJqPfNQjqIj02SI24ulZPL3uVODR-YbGtHWOd63rb83bADcXwCL2wBcHC3bsPIEb4I7eIcFF8wi9Hgb0aBn4NiMJ-bKGTfo8Mly8ZgRyE_Ko7RmM_ooi-yKSV5F8EUWynZfN1pZhELJagrZcTemJYaki3nqRFttNWghZgyiftyAAgM5ZYvgQdq9AZK9wOnlN3XJapuW0nK6nUE2pkFUSMd99hLyYSV1PuHmFrOPJfoz_qOKeFj_OEP3_kuLh_i7Ht0weOXj7N9irkNW77bGnMMUerY25V5-hIutHAiGfPwMdO_wSKX6KxEce5et3L7uZP_t_SIJHBPwz6EWZKB28zh6JtLME2hptEbQFxyN66FyPB4Cf9Gpd1A141AQeKRiOnwPhrLyKqDjNziuvkWC_BwUXRYw9eDxrYvSgbA_KQrAWOyRS_gaiSDZuOtYrj9GelsNyFUUCs9L-8PGRfncBOmXh4vxXUN4F24PmbRJiWf9JcXvUltHPHvld4ffq_6Tg7feNhSx7aBFGNPMQDLCDwZk-ypkQ2J1xFakeYHZEujVRuW9ClhNYx0DBI1xGxaCMWWdg7b5X2jKB8njY9U3W11mtdtikZfJUyPSpqHZjM5R5mie9UlWWVDIvh65D2fVt0mOd1G21041MZJ6kaSWzvEiqQ1ll3VNd911R5nXWdSJPcFLaHIxZpoPz550mCtiUVZGXO6NaNLTuAyktXmB1CinjevBNjNm34UwiT4wmpm8orNlg88vbry_73x5LArRlry3pjh4MQ8cQLI3KY79dKcv7uEc-Du0ueNOMzPM6R_Io5PGseQztoXOTkMeY8_G3n737AzsW8rhWSkIeVyZ_BQAA__-skS_Y">