[llvm] 8995a35 - [LLVM] Skip non-overlapping subranges (#227852)

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 01:56:02 PDT 2026


Author: Kewen Meng
Date: 2026-10-01T10:55:53+02:00
New Revision: 8995a358fa77a669679594aa9857ba0e0b224ab1

URL: https://github.com/llvm/llvm-project/commit/8995a358fa77a669679594aa9857ba0e0b224ab1
DIFF: https://github.com/llvm/llvm-project/commit/8995a358fa77a669679594aa9857ba0e0b224ab1.diff

LOG: [LLVM] Skip non-overlapping subranges (#227852)

Add guard to skip subranges that not live in the interval.

fix to: https://github.com/llvm/llvm-project/pull/227252

Passed local libc tests:
```
Total Discovered Tests: 814
  Passed: 814 (100.00%)
```

assisted by: cursor

Added: 
    llvm/test/CodeGen/AMDGPU/phi-elimination-split-critical-edge-nonoverlapping-subrange.mir

Modified: 
    llvm/lib/CodeGen/MachineBasicBlock.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp
index e920e825dda2c..006a9fcb02bf4 100644
--- a/llvm/lib/CodeGen/MachineBasicBlock.cpp
+++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp
@@ -1385,8 +1385,10 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(
         }
       } else if (!isLiveOut && !isLastMBB) {
         LI.removeSegment(StartIndex, EndIndex);
-        for (auto &SR : LI.subranges())
-          SR.removeSegment(StartIndex, EndIndex);
+        for (auto &SR : LI.subranges()) {
+          if (SR.overlaps(StartIndex, EndIndex))
+            SR.removeSegment(StartIndex, EndIndex);
+        }
       }
     }
 

diff  --git a/llvm/test/CodeGen/AMDGPU/phi-elimination-split-critical-edge-nonoverlapping-subrange.mir b/llvm/test/CodeGen/AMDGPU/phi-elimination-split-critical-edge-nonoverlapping-subrange.mir
new file mode 100644
index 0000000000000..0d94737654a62
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/phi-elimination-split-critical-edge-nonoverlapping-subrange.mir
@@ -0,0 +1,43 @@
+# RUN: llc -mtriple=amdgpu9.00 -verify-machineinstrs -run-pass=liveintervals,phi-node-elimination -o - %s | FileCheck %s
+# RUN: llc -mtriple=amdgpu9.00 -verify-each -passes='require<live-intervals>,phi-node-elimination' -o - %s | FileCheck %s
+
+# Splitting the critical edge from %bb.1 to %bb.2 removes the new block's
+# interval from %wide. Only %wide.sub0 is live out of %bb.1; %wide.sub1 has a
+# later, non-overlapping segment in %bb.4. Do not try to remove the new block's
+# interval from that non-overlapping subrange.
+
+# CHECK-LABEL: name: split_critical_edge_nonoverlapping_subrange
+# CHECK: bb.1:
+# CHECK: bb.5:
+# CHECK: bb.2:
+
+---
+name: split_critical_edge_nonoverlapping_subrange
+tracksRegLiveness: true
+body: |
+  bb.0:
+    %lo:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
+    %hi:vgpr_32 = V_MOV_B32_e32 1, implicit $exec
+    %wide:vreg_64 = REG_SEQUENCE %lo, %subreg.sub0, %hi, %subreg.sub1
+    %phisrc:vgpr_32 = V_MOV_B32_e32 2, 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:
+    %phi:vgpr_32 = PHI %phisrc, %bb.1, %other:vgpr_32, %bb.4
+    S_ENDPGM 0, implicit %phi
+
+  bb.3:
+    S_ENDPGM 0, implicit %wide.sub0, implicit %phisrc
+
+  bb.4:
+    %other:vgpr_32 = V_MOV_B32_e32 3, implicit $exec
+    S_NOP 0, implicit %wide.sub1
+    S_BRANCH %bb.2
+...


        


More information about the llvm-commits mailing list