[llvm] [MachineCSE] Enhance MachineCSE simple PRE to find common subexpressi… (PR #129860)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 5 04:49:25 PST 2025


================
@@ -887,6 +887,23 @@ bool MachineCSEImpl::ProcessBlockPRE(MachineDominatorTree *DT,
         NewMI.setDebugLoc(EmptyDL);
 
         NewMI.getOperand(0).setReg(NewReg);
+        for (MachineOperand &MO :
+             llvm::make_early_inc_range(MRI->use_nodbg_operands(VReg))) {
+          if (MO.isUse()) {
+            MO.setReg(NewReg);
+          }
+        }
+        auto *SiblingBBMI = PREMap.try_emplace(&MI).first->getFirst();
+        for (MachineOperand &MO :
+             llvm::make_early_inc_range(MRI->use_nodbg_operands(
+                 SiblingBBMI->getOperand(0).getReg()))) {
+          if (MO.isUse()) {
+            MachineInstr *UseMI = MO.getParent();
+            PREMap.erase(UseMI);
+            MO.setReg(NewReg);
+            PREMap[UseMI] = UseMI->getParent();
----------------
arsenm wrote:

Double map lookup? 

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


More information about the llvm-commits mailing list