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

    <tr>
        <th>Summary</th>
        <td>
            [RISCV] Fold doLocalPrepass back into main algorithm and thus extend to cross block cases
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:RISC-V,
            llvm:codegen,
            performance
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            preames
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          preames
      </td>
    </tr>
</table>

<pre>
    If we land https://reviews.llvm.org/D125270, I think this opens up an interesting opportunity.  Filing this so I don't forget.  I'm going to deliberately not doing anything on this until the strict asserts have been enabled for a week or so.  I want to snag any latent correctness issues first.  

First, as a nfc, I think we can extract a transfer function for the state transitions which is shared by all three phases.  The mutation was the last thing causing them to diverge.  The key detail is that phase 3 uses the output state from the transfer for inserting vsetvli *before* the SEW operand instructions.  

Second, if we do that, I think we can fold most of the prepass back into the main algorithm by phrasing the canonicalizations as changes to the output state.  This should be okay since (a) we're not actually modifying any instruction until phase 3, and b) all phases agree.  

This would have the nice side effect of letting the prepass rules benefit from cross block information.  We do need to make sure the dataflow still convergences in a reasonable period, but I doubt that will be a major problem.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxtlE9v4zYQxT-NfBmsYctWbB98SDcNEKCHoil2zxQ1srimSIF_7Lqfvm8op0mzDQJLGooz7_1mxNZ3t-NLT1cmq1xHQ0pTrDaPVf2M_8AXw9e4tPYyLn04IfS0rpt6t6rqr_RCaTDuLL-R_MQuUp5IOTIuceCYjDshPvmQsjPptiR6NlaCZUf0yNB5V9W7RD2yc8IbL3gc6eTLa546tqbloBLbGzmfsEFWlLtJbaR3c7LskrG4ZYopGJ1IxcghRRrUhalldsROtZY7KUUKhvlMuIteitJVuST1olMlO2gkRkj7EFgnxzGSiTFzpN6EKEqr1VO1epx_nyUmTFREbtfrj3zAVoMK_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