[llvm-branch-commits] [llvm] CodeGen: Check subrange liveness directly when trimming split edges (PR #228055)

Matt Arsenault via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Oct 1 05:13:07 PDT 2026


https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/228055

SplitCriticalEdge trims the stale extension of a live range into the newly
created block. The subrange guard used overlaps(StartIndex, EndIndex), which
happens to work only because insertMBBInMaps creates exactly one fresh index for
the new block, so no pre-existing segment endpoint can fall strictly inside the
range. That only happens to make makes overlap equivalent to containment.

Check liveAt(PrevIndex) instead, mirroring the same condition on the main range.

Co-authored-by: Claude Opus 5 <noreply at anthropic.com>

>From f039a4b2a3172eb4259fec98460dde9b577718ea Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Thu, 1 Oct 2026 13:37:10 +0200
Subject: [PATCH] CodeGen: Check subrange liveness directly when trimming split
 edges

SplitCriticalEdge trims the stale extension of a live range into the newly
created block. The subrange guard used overlaps(StartIndex, EndIndex), which
happens to work only because insertMBBInMaps creates exactly one fresh index for
the new block, so no pre-existing segment endpoint can fall strictly inside the
range. That only happens to make makes overlap equivalent to containment.

Check liveAt(PrevIndex) instead, mirroring the same condition on the main range.

Co-authored-by: Claude Opus 5 <noreply at anthropic.com>
---
 llvm/lib/CodeGen/MachineBasicBlock.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp
index 006a9fcb02bf4..4cd6afed26405 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);
+        // The main range is live across NMBB, but an individual lane need not
+        // be.
         for (auto &SR : LI.subranges()) {
-          if (SR.overlaps(StartIndex, EndIndex))
+          if (SR.liveAt(PrevIndex))
             SR.removeSegment(StartIndex, EndIndex);
         }
       }



More information about the llvm-branch-commits mailing list