[llvm] [LLVM] Skip non-overlapping subranges (PR #227852)
Kewen Meng via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 30 13:46:16 PDT 2026
https://github.com/Kewen12 updated https://github.com/llvm/llvm-project/pull/227852
>From 4135a5adb3b9e0ea581a815bf3ed61c482fe504e Mon Sep 17 00:00:00 2001
From: Kewen Meng <kewen.meng at amd.com>
Date: Wed, 30 Sep 2026 15:06:30 -0500
Subject: [PATCH 1/2] [libc] Skip non-overlapping subranges
---
llvm/lib/CodeGen/MachineBasicBlock.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
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);
+ }
}
}
>From f02ea9c0d83b02353b628c9478ea3488557f59f7 Mon Sep 17 00:00:00 2001
From: Kewen Meng <kewen.meng at amd.com>
Date: Wed, 30 Sep 2026 15:45:28 -0500
Subject: [PATCH 2/2] added test
---
...-critical-edge-nonoverlapping-subrange.mir | 43 +++++++++++++++++++
1 file changed, 43 insertions(+)
create mode 100644 llvm/test/CodeGen/AMDGPU/phi-elimination-split-critical-edge-nonoverlapping-subrange.mir
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