<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/148837>148837</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[RISC-V] __attribute__((interrupt)) does not save vector registers
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
amitch1999
</td>
</tr>
</table>
<pre>
Hi,
I played around a little with a code snippet I found online of a vector function that uses intrinsics,
and I noticed that if I add the `__attribute__((interrupt))` attribute to the function, llvm does not save the vector registers used inside the function
Although all vector registers (v0-31) all caller-saved by the ABI.
GCC 14/15 does save the vector registers used in the function.
[Link to godbolt comparison](https://godbolt.org/z/5x36Kfshh)
The snippet:
```
#include <riscv_vector.h>
extern const float *in;
extern size_t n;
extern float ret;
__attribute__((interrupt)) void reduce_max()
{
size_t vlmax = __riscv_vsetvlmax_e32m1();
vfloat32m1_t max_array = __riscv_vfmv_s_f_f32m1(in[0], vlmax);
while (n > 0)
{
size_t vl = __riscv_vsetvl_e32m1(n);
vfloat32m1_t vs2 = __riscv_vle32_v_f32m1(in, vl);
max_array = __riscv_vfmax_vv_f32m1(max_array, vs2, vl);
in += vl;
n -= vl;
}
vfloat32m1_t reduce_max = __riscv_vfredmax_vs_f32m1_f32m1(max_array, max_array, vlmax);
ret = __riscv_vfmv_f_s_f32m1_f32(reduce_max);
}
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyElUGP6jYQxz_NcBmBHCdZkkMOgX20qD21Va-RiQfi1tjIdrK779NXTrLLhveqRZEQ9sz__xtPPAjv1cUQVZDvIH9eiT501lXiqkLbJWVZrk5WvlW_KuB7YDWw-og3Ld5IonC2NxIFahWCJnxRoUOBrZWE3qjbjQIe8TwGWaOVIbRnFDhQG6zDc2_aoKzB0ImAvSePygSnjFetn9yEkXhEY4NqSU5x6oxHFDL-IoQn1jQiBKdOfaCmAV4AL5QJ5Fx_C8DL-Dwx_IjBYMfMd3Pge9R6uKK05KMTejHQGDJjOrooH8j5iCgx4klaarC61qGz_aVDofWPicCLga3TBHg5BrRCa3Lr6CTx9DaK1bvjBlj9y36PSQb8kOQT0pc4C5TN1CLId78r828s9mLlyeqArb3ehFPeGsifgRddCDcPaQ38APwwR22suwA_fAd-yF_Tp9_OvuviCY6if3UfbY15rIYnNj-sBp4q0-peEkK6d8q3QzMRbzpIv00K9BrIGWyt8QHP2oqAwGtlIN3dd736Tk3A5eIU7KLzbi6R1V-3HgerJDqSfUvNVbyOQWM52yiDiO92g76KV4T0GZtmpvcUxtWGUn5N5tTRHoeRJy43AWOIcE68LdPP16Hxzbk5z9nKQL5j4-HvJ7sPvRnlpVOa4stiENJvyCbUuHPHXSD_hPcD1izUF8CD58tMTSlvhs-kI-K93vnzv5WK12a453-EjTKeP6h9ElQGge-i2KCXVgbXj8uwfb5nLwq6N_gBzJEc2fzE9nPCJe6iMdHJUfixsefmkyTw4vMr9l7mhPt-R1aySmWZlmJFVbLNeV5wxstVV0kmuDixbFtmSZuVp7yQUhRFkmVlkvA8XamKM56zbZInPOZsRJtmiSDalvRUilMGGaOrUHoTB1m8wivlfU9VkhVFul1pcSLtx_nOuaEXHHeB8zjuXRWT1qf-4iFjWvng7zJBBT3-Mfxx_HO__hvyeApf3rnlJH0cW6ve6eph-KjQ9adNa6_AD9F8_lrfnP2H2gD8MCL7OBanmoaK_xcAAP__BGsdVw">