After MachineSink, there will be peephole opportunity for:
%0:g8rc_and_g8rc_nox0 = ADDI8 %5:g8rc_and_g8rc_nox0, 144 STD killed %7:g8rc, 16, %0:g8rc_and_g8rc_nox0 :: (store 8 into %ir.8)
------>
STD killed %7:g8rc, 160, %5:g8rc_and_g8rc_nox0 :: (store 8 into %ir.8)
This folding opportunity may become unfoldable after RA because we may redefine addi's register operand in RA. So we add this peephole before RA in convertToImmediateForm.
First try was implemented in https://reviews.llvm.org/D46377 and the author @nemanjai found out that patch can use some existing logic in later committed patch https://reviews.llvm.org/D49007.
This patch tries to do this.
What about the IdxOfADDI and IdxOfLI ?