<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/56321>56321</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Missed oppurtunity to narrow sext byte load pattern
        </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:
```
        ld      a1, 152(sp)
        slli    a2, a1, 56
        srai    a1, a2, 56
```
This is extracting the low byte, and then sign extending it.

This assembly should look something like:
```
        lb      a1, 152(sp)
```
There's a second issue here as well.  Even if compiled with zbb, the sign extend shift sequence is not replaced with sext.b.  Not sure if this is specific to stack fills, or if this is a more general problem.  
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx9VE1v3DYQ_TXaC6GFRK3246BDYtepgdYGUqfoLaCokZYxRSokte761_dR0q7tHgIRJEXOvPl4M6xtc66ejsozDMEGcq11vTCSmB0G68JoVDgzYwM17OVIhgkj9PlVmY75n1oFKtbsTun4HyLMiwpH5mhwthllUNYwZXxw894zoEMO4E51CkjM1p7cSUySwjTM255mGx5oNWn7kvAbNmhhWLDQ1zhh43AxBCvwLJAPTApPfnbynh3FiWawoHpaJ9ltkn1a5m2W8I0EYsdS5c8-UM9w8uXh2_enx8c_bn7_dP_w_fb-a8LvcOusDdiN3mFWRuqxI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