<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/117909>117909</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[RISC-V] Illegal instruction by Clang for FP rounding mode intrinsics
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rvismith-project
</td>
</tr>
</table>
<pre>
Clang 19 and 20 generate illegal instruction when an implicit FP rounding mode intrinsic used after an Explicit FP rounding mode intrinsic. A test case example:
```
$ cat 0.c
#include <riscv_vector.h>
#define dataLen 1
float a[dataLen]; float b[dataLen];
int main(){
for (int i = 0; i < dataLen; ++i) { a[i] = 1.0; }
for (int i = 0; i < dataLen; ++i) { b[i] = 0; }
int avl = dataLen;
float* ptr_a = a; float* ptr_b = b;
for (size_t vl; avl > 0; avl -= vl){
vl = __riscv_vsetvl_e32m1(avl);
vfloat32m1_t va = __riscv_vlse32_v_f32m1(ptr_a, 4, vl);
va = __riscv_vfsqrt_v_f32m1_rm( va, __RISCV_FRM_RNE, vl);
va = __riscv_vfredosum_vs_f32m1_f32m1(va, va, vl);
__riscv_vse32_v_f32m1(ptr_b, va, vl);
ptr_a += vl;
ptr_b += vl;
}
return 0;
}
$ /home/compiler/llvm/19.1.4/bin/clang -march=rv64gcv_zvfh -mabi=lp64d -Wno-psabi -static -O1 -save-temps 0.c
$ cat 0.s
...
.LBB0_1: # =>This Inner Loop Header: Depth=1
vsetvli a4, a2, e32, m1, ta, ma
vlse32.v v8, (a0), a3
fsrmi a5, 0
vfsqrt.v v8, v8
fsrmi 7
vfredosum.vs v8, v8, v8
fsrm a5
vse32.v v8, (a1)
slli a5, a4, 2
add a0, a0, a5
subw a2, a2, a4
add a1, a1, a5
bgtz a2, .LBB0_1
...
$ /home/compiler/llvm/19.1.4/bin/clang --version
clang version 19.1.4 (https://github.com/llvm/llvm-project.git aadaa00de76ed0c4987b97450dd638f63a385bed)
Target: riscv64-unknown-unknown-elf
Thread model: posix
InstalledDir: /home/compiler/llvm/19.1.4/bin
```
The instruction ` fsrmi 7` is illegal.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVt2Oo7gSfhrnphRkbBLgIhdJp6PT0pxzVrOj2UtUQCXxrjFZ2zA_T7-yge50z6x2dleKTKiq73P9mTI6py6GaMc2B7Y5rnDw197u7Khcp_x1fbP9r9T4Vd23X3YPGs0F0hLQtCA4XMiQRU-gtKYLalDGeTs0XvUGPl3JABpQ3U2rRnk4_QS2H0yrzAW6viVQxltlnGpgcNQCnj3ZgHj8_JeIBPbgyXlo0BHQZ-xumpjcM75nWz7_-J6JDBr0wJMmvkllGj20BEw-WOWasRqp8b1Nrkw-ThYtnZUhaNHjOzKQMr4_6x49INscZinbHJk8wCSv38oZ3yvjoUNlmCiYKFkeZADn3gITRVAqYPIIPLCEvw_LfkHAxIGJg2KiBJYf4r6KbY4RkSYRw_Ljv2Cs7xnv-QIPjjrKX-DTTiFWJvZw87bCaIHPOVjkdZTXz5jJO6e-UuVh1MF-on-ctg0v6wAZ9V2aAGYXqmqukSM_6oqk6FImCpys5bN19CEowy74GqodSVGN1XkGR_eZeIAsLG-Z3oDP7nfrF3BlOyYKGCO6qt4__fzwsTq9_2_1_n-PP8Jlqe3d0FWjm_kWlybGeb0juQv_mxDq70MAlvqIw5zXV4r6G8XSSZb8YE0sSzgHURpODxOna98RE6em725Kk2XipPXYMXFKyyRNMiZOdej0UxO_DusObXNl8mjHbXZpxurreL4Gaa2YPOrbNmth_Yvp1zeHtYK18-hVA-v_p7B2ONLaU3dzzyd2Ob-O8X2SJGF9dzjwKmVyD0zIkGQmHz9clYMnY8jCu76_wX8IW7LB5kg3H9wJB5nxcuolxXiJsQNQhJVkfIT0PoCPae1wBsQOSsbwtwiK0IE8pDyg5WR0draLnJsg5TMyts8dcixeW-eL3dwayejubd8gJvoliG9cSoNLUeu0fvFlilJMGmzbsP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