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

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 13:46:57 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-amdgpu

Author: Kewen Meng (Kewen12)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/227852.diff


2 Files Affected:

- (modified) llvm/lib/CodeGen/MachineBasicBlock.cpp (+4-2) 
- (added) llvm/test/CodeGen/AMDGPU/phi-elimination-split-critical-edge-nonoverlapping-subrange.mir (+43) 


``````````diff
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp
index fa708fee5f769..b1f8143e4b473 100644
--- a/llvm/lib/CodeGen/MachineBasicBlock.cpp
+++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp
@@ -1383,8 +1383,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
+...

``````````

</details>


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


More information about the llvm-commits mailing list