<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/115446>115446</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[RISC-V] Possible Miscompilation by Indexed Segment Load-Store Intrinsics
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Yibo-He
</td>
</tr>
</table>
<pre>
In the following code with rvv intrinsics, I load data from a to b.
The index of `__riscv_vsoxseg5ei8_v_f64m1x5` is obtained from the result of `__riscv_vid_v_u8mf8`(*=8), and i think the result should be the same with `__riscv_vsseg5e64_v_f64m1x5` (if this is a misunderstanding, please tell me).
However, values of vector a are not equal to values in vector b after the for loop.
```
#include <riscv_vector.h>
#define dataLen 20
uint8_t idx[dataLen];
double a[dataLen]; double b[dataLen];
int main(){
for (int i = 0; i < dataLen; ++i) { a[i] = i * 10.0; }
for (int i = 0; i < dataLen; ++i) { b[i] = 0; }
int placeholder0 = dataLen;
double* ptr_a = a;
double* ptr_b = b;
for (size_t vl; placeholder0 > 0; placeholder0 -= vl * 5){
vl = __riscv_vsetvl_e64m1(placeholder0);
vfloat64m1x5_t va = __riscv_vlseg5e64_v_f64m1x5(ptr_a, vl);
vuint8mf8_t vidx = __riscv_vsll_vx_u8mf8(__riscv_vid_v_u8mf8(vl), 3, vl);
__riscv_vsoxseg5ei8_v_f64m1x5(ptr_b, vidx, va, vl);
ptr_a += vl * 5;
ptr_b += vl * 5;
}
for(int i=0; i<dataLen; ++i){ if(a[i]!=b[i]){ __builtin_printf("a[%d]=%lf, b[%d]=%lf\n", i, a[i], i, b[i]); } }
return 0;
}
```
Result:
```
a[1]=10.000000, b[1]=50.000000
a[2]=20.000000, b[2]=60.000000
a[3]=30.000000, b[3]=70.000000
a[4]=40.000000, b[4]=80.000000
a[5]=50.000000, b[5]=90.000000
a[6]=60.000000, b[6]=0.000000
a[7]=70.000000, b[7]=0.000000
a[8]=80.000000, b[8]=0.000000
a[9]=90.000000, b[9]=0.000000
a[11]=110.000000, b[11]=150.000000
a[12]=120.000000, b[12]=160.000000
a[13]=130.000000, b[13]=170.000000
a[14]=140.000000, b[14]=180.000000
a[15]=150.000000, b[15]=190.000000
a[16]=160.000000, b[16]=0.000000
a[17]=170.000000, b[17]=0.000000
a[18]=180.000000, b[18]=0.000000
a[19]=190.000000, b[19]=0.000000
```
The above results appear in LLVM 18.1.8 and 19.1.0 (with qemu 9.1.0).
```
$ clang --version
clang version 19.1.0
Target: riscv64-unknown-linux-gnu
Thread model: posix
InstalledDir: ...
$ qemu-riscv64 --version
qemu-riscv64 version 9.1.0
Copyright (c) 2003-2024 Fabrice Bellard and the QEMU Project developers
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykV8Fu27oS_Rp6M7AhUpYlLbyI7QYNkAJ97XsF3kqgJMrmLUW6JKW49-svSFGOLTnd3CBI4pk5w8M5Q2ZIjeFHydgWJTuUHBa0syelt__npVp-ZotS1b-3LxLsiUGjhFBvXB6hUjWDN25PoPseuLSaS8Mrg8geXkAoWkNNLYVGqxYoWAXlCkUHFD3998SAy5pdQDWANlFRaG6qvuiNuhh2TBjPir5oNusWXxK0iYAbUKWlXLJ6SOeYaGY6YacpeF30RZe1TYY2ESIZIk8oPmSI5I4XlTVwsCcuf97mMCfViRpK5o2GtmFjd9w8s836nhkiGW9cQuNIUmi56WTNtLFU1lwe3aJnwahhYJkQ0DJE8lCGz-qN9Uy7kJ6Kjhm3l55VVmmgQDUDqSywXx0VrnohhssxpgTaWKaDLBqEUueQ2u19-B4-kpjLSnQ1AxTvw4Z8ktUJxZ-uQTVruGRetlcmgQR4x6XNCgu8vqBkF7woOaB4NwTUqisFAzr1QnCUj2FcWmgpl16mHKXBDH43rrLSAgcUHyByydyf-5GcMyCyQ2THEckBpTu_PEfJwSM4IPIEOFp5KEoP_y53eZt7mtLlOgtasZMSNdORD3rPNYYNxXC0zl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