<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/56317>56317</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed oppurtunity to narrow vluxei64.v (gatther load)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:RISC-V,
performance
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
preames
</td>
</tr>
</table>
<pre>
This is a performance opportunity noted when analyzing sqlite3. Filing this with reproduction instructions for the original observation and some analysis below, plan to follow up with reduced test cases when I have some time.
`$clang -isystem $GNU_TOOLCHAIN_DIR/sysroot/usr/include/ --target=riscv64 -mllvm -riscv-v-vector-bits-min=256 -mllvm -scalable-vectorization=on -Xclang -target-feature -Xclang +v,+f,+m,+c,+d,+zba sqlite-autoconf-3380500/sqlite3.c -c -O2 -g`
The amalgamation file is taken from the sqlite3 website.
Non optimal assembly observed:
```
li a1, 98
... and a bit later ...
vsetvli zero, zero, e16, mf2, ta, mu
vluxei64.v v8, (zero), v12
vluxei64.v v12, (zero), v16
vand.vx v8, v8, a1
vand.vx v12, v12, a1
```
We're using a wider data type for the indexed load then is required.
This assembly should look something like:
```
li a1, 98
... and a bit later ...
vsetvli zero, zero, e8, mf2, ta, mu
vluxei64.v v8, (zero), v12
vluxei64.v v12, (zero), v16
vand.vx v8, v8, a1
vand.vx v12, v12, a1
```
In this particular case, using a narrow datatype doesn't gain us much, but it's still an interesting missed opportunity. As a guess, I would say this is probably a missing IR level optimization before this loop got vectorized.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzdVU1v4zgM_TXORbDhyI0bH3zotOhugN0W6HY_bgNaYhxtZckjyU7TX7-U7aQtMHOdwyaGKMkkRfGRz42Vp_r5oDyjB1iPbm9dB0Ygs31vXRiMCidmbEDJjgc0DAzo05syLfPftApYZOxe6bgO0c1RhQNz2DsrBxGUNUwZH9w894y8kx45d6pV5InZxqMbY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