[llvm] [PeepholeOptimizer] Recognize new move-immediate instructions (PR #72128)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 15 02:39:29 PST 2023


jayfoad wrote:

> I think SIFoldOperands works backwards from how it should

I know - you have mentioned it once or twice :) I think https://reviews.llvm.org/D114643 might have removed a (the?) barrier to doing this, since the pass no longer cares how many uses each constant has.

As for the implementation, I'm not sure it needs to "collect seen foldable instructions". We're in SSA form so can't it just do:
```
for (MBB : MF)
  for (MI : MBB)
    for (Op : MI.use_operands())
      DefMI = MRI.getOneDef(Op.getReg())
      if (DefMI.isMoveImmediate())
        try to fold it
```
Then the only complexity is if multiple operands of the same MI are foldable, you might want to carefully choose _which_ ones to fold.

https://github.com/llvm/llvm-project/pull/72128


More information about the llvm-commits mailing list