[llvm-branch-commits] [llvm] CodeGen: Find PHI sources while rewriting PHIs in SplitCriticalEdge (PR #230500)

Nikita Popov via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Oct 9 08:58:16 PDT 2026


================
@@ -1303,29 +1315,14 @@ MachineBasicBlock::SplitCriticalEdge(MachineBasicBlock *Succ,
     SlotIndex PrevIndex = StartIndex.getPrevSlot();
     SlotIndex EndIndex = Indexes->getMBBEndIdx(NMBB);
 
-    // Find the registers used from NMBB in PHIs in Succ.
-    SmallSet<Register, 8> PHISrcRegs;
-    for (MachineBasicBlock::instr_iterator
-         I = Succ->instr_begin(), E = Succ->instr_end();
-         I != E && I->isPHI(); ++I) {
-      for (unsigned ni = 1, ne = I->getNumOperands(); ni != ne; ni += 2) {
-        if (I->getOperand(ni+1).getMBB() == NMBB) {
-          MachineOperand &MO = I->getOperand(ni);
-          Register Reg = MO.getReg();
-          if (MO.isUndef())
-            continue;
-          PHISrcRegs.insert(Reg);
-
-          LiveInterval &LI = LIS->getInterval(Reg);
-          VNInfo *VNI = LI.getVNInfoAt(PrevIndex);
-          assert(VNI &&
-                 "PHI sources should be live out of their predecessors.");
-          LI.addSegment(LiveInterval::Segment(StartIndex, EndIndex, VNI));
-          for (auto &SR : LI.subranges()) {
-            if (VNInfo *SRVNI = SR.getVNInfoAt(PrevIndex))
-              SR.addSegment(LiveInterval::Segment(StartIndex, EndIndex, SRVNI));
-          }
-        }
+    for (Register Reg : PHISrcRegs) {
----------------
nikic wrote:

Does the order the registers are processed here matter, or will addSegment() produce the same result regardless of order?

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


More information about the llvm-branch-commits mailing list