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

    <tr>
        <th>Summary</th>
        <td>
            Missed oppurtunity to remat constant address
        </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:
```
        sd      a1, 104(sp)
        lui     a2, %hi(.L.str.669)
        addi    a1, a2, %lo(.L.str.669)
        sd      a1, 56(sp)
        lui     a2, %hi(.L.str.1213)
        addi    a1, a2, %lo(.L.str.1213)
        sd      a1, 32(sp)
```
Here we are materializing a constant address into a register just to spill it onto the stack.  In this case, at least 32(sp) has exactly one use and we could have moved the address materialization there at no cost.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVE2P2zYQ_TXyhZAgU7bXOuiQ7GIbA-kukG6K3gKKGslMKFIlKbveX99HSfE6KXoIRJAU55Pz5rG2zaV6OSrPMAQbyLXW9cJIYnYYrAujUeHCjA3UsPORDBNG6MurMh3zf2sVqMjYo9LxP0Q3ZxWOzNHgbDPKoKxhyvjg5r1n8A49OHeqU_DEbO3JncSkKUzDvO1pjuHhrSZtzwm_Z4MWhgULe40TNg7fAyEKMgvkA5PCk5-TPLCjONHsLKiesiR_SPJ3y7zLE76R8NixVPmLD9QznPz29P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