[llvm] ccafeec - CodeGen: Fix stale live range for undef PHI sources on split edges (#228057)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 2 05:20:55 PDT 2026
Author: Matt Arsenault
Date: 2026-10-02T14:20:45+02:00
New Revision: ccafeec5625a44b90be71d9e4b9515d4d3ea6612
URL: https://github.com/llvm/llvm-project/commit/ccafeec5625a44b90be71d9e4b9515d4d3ea6612
DIFF: https://github.com/llvm/llvm-project/commit/ccafeec5625a44b90be71d9e4b9515d4d3ea6612.diff
LOG: CodeGen: Fix stale live range for undef PHI sources on split edges (#228057)
SplitCriticalEdge collects the PHI sources coming from the new block so
the trimming loop below does not undo the segment just added for them.
An undef operand gets no segment, but was still added to the set, so a
register that is only an undef PHI operand on the split edge kept the
stale extension of its live range through the new block.
Co-authored-by: Claude Opus 5 <noreply at anthropic.com>
Added:
llvm/test/CodeGen/AMDGPU/phi-elimination-split-critical-edge-undef-phi-source.mir
Modified:
llvm/lib/CodeGen/MachineBasicBlock.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp
index 4cd6afed26405..108d5fe842ca2 100644
--- a/llvm/lib/CodeGen/MachineBasicBlock.cpp
+++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp
@@ -1345,9 +1345,9 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(
if (I->getOperand(ni+1).getMBB() == NMBB) {
MachineOperand &MO = I->getOperand(ni);
Register Reg = MO.getReg();
- PHISrcRegs.insert(Reg);
if (MO.isUndef())
continue;
+ PHISrcRegs.insert(Reg);
LiveInterval &LI = LIS->getInterval(Reg);
VNInfo *VNI = LI.getVNInfoAt(PrevIndex);
diff --git a/llvm/test/CodeGen/AMDGPU/phi-elimination-split-critical-edge-undef-phi-source.mir b/llvm/test/CodeGen/AMDGPU/phi-elimination-split-critical-edge-undef-phi-source.mir
new file mode 100644
index 0000000000000..c9c29eb7b875c
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/phi-elimination-split-critical-edge-undef-phi-source.mir
@@ -0,0 +1,36 @@
+# RUN: llc -mtriple=amdgpu9.00 -passes='require<live-intervals>,phi-node-elimination,print<live-intervals>' -filetype=null %s 2>&1 | FileCheck %s
+
+# %0 is only an undef PHI operand on the critical edge from %bb.1 to
+# %bb.2, so splitting the edge must not leave %0 live through the new
+# block.
+
+# CHECK: ********** INTERVALS **********
+# CHECK-NEXT: %0 [16r,[[SPLIT:[0-9]+]]B:0)
+# CHECK: [[SPLIT]]B{{[[:space:]]+}}bb.5:
+
+---
+name: split_critical_edge_undef_phi_source
+tracksRegLiveness: true
+body: |
+ bb.0:
+ %0:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
+ %1:vgpr_32 = V_MOV_B32_e32 1, implicit $exec
+ $scc = IMPLICIT_DEF
+ S_CBRANCH_SCC1 %bb.1, implicit $scc
+ S_BRANCH %bb.4
+
+ bb.1:
+ $scc = IMPLICIT_DEF
+ S_CBRANCH_SCC1 %bb.3, implicit $scc
+ S_BRANCH %bb.2
+
+ bb.2:
+ %2:vgpr_32 = PHI undef %0, %bb.1, %1, %bb.4
+ S_ENDPGM 0, implicit %2
+
+ bb.3:
+ S_ENDPGM 0, implicit %0
+
+ bb.4:
+ S_BRANCH %bb.2
+...
More information about the llvm-commits
mailing list