[llvm] [CodeGen] DetectDeadLanes: do not rewrite operand flags on bundles (PR #222124)

Kevin McAfee via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 12:54:24 PDT 2026


https://github.com/kalxr updated https://github.com/llvm/llvm-project/pull/222124

>From c33fc3464ce792b734b33499ed09c6da0e98315b Mon Sep 17 00:00:00 2001
From: Kevin McAfee <kmcafee at nvidia.com>
Date: Fri, 4 Sep 2026 21:03:37 +0000
Subject: [PATCH 1/3] precommit

---
 .../AMDGPU/detect-dead-lanes-bundle.mir       | 57 +++++++++++++++++++
 1 file changed, 57 insertions(+)
 create mode 100644 llvm/test/CodeGen/AMDGPU/detect-dead-lanes-bundle.mir

diff --git a/llvm/test/CodeGen/AMDGPU/detect-dead-lanes-bundle.mir b/llvm/test/CodeGen/AMDGPU/detect-dead-lanes-bundle.mir
new file mode 100644
index 0000000000000..79d4365187ffb
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/detect-dead-lanes-bundle.mir
@@ -0,0 +1,57 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
+# RUN: llc -mtriple=amdgcn -mcpu=gfx600 -run-pass detect-dead-lanes -verify-machineinstrs -o - %s | FileCheck %s
+# RUN: llc -mtriple=amdgcn -mcpu=gfx600 -passes detect-dead-lanes -verify-machineinstrs -o - %s | FileCheck %s
+---
+name: bundle_header_use_not_marked_undef
+tracksRegLiveness: true
+registers:
+  - { id: 0, class: sreg_64 }
+body: |
+  bb.0:
+    ; CHECK-LABEL: name: bundle_header_use_not_marked_undef
+    ; CHECK: [[DEF:%[0-9]+]]:sreg_64 = IMPLICIT_DEF
+    ; CHECK-NEXT: BUNDLE implicit undef [[DEF]] {
+    ; CHECK-NEXT:   S_NOP 0, implicit [[DEF]]
+    ; CHECK-NEXT: }
+    ; CHECK-NEXT: S_NOP 0, implicit undef [[DEF]]
+    %0 = IMPLICIT_DEF
+    BUNDLE implicit %0 {
+      S_NOP 0, implicit %0
+    }
+    S_NOP 0, implicit %0
+...
+---
+name: bundle_header_use_not_marked_undef_via_reg_sequence
+tracksRegLiveness: true
+registers:
+  - { id: 0, class: sgpr_128 }
+  - { id: 1, class: sreg_64 }
+body: |
+  bb.0:
+    ; CHECK-LABEL: name: bundle_header_use_not_marked_undef_via_reg_sequence
+    ; CHECK: [[DEF:%[0-9]+]]:sgpr_128 = IMPLICIT_DEF
+    ; CHECK-NEXT: [[REG_SEQUENCE:%[0-9]+]]:sreg_64 = REG_SEQUENCE undef [[DEF]].sub0, %subreg.sub0, undef [[DEF]].sub1, %subreg.sub1
+    ; CHECK-NEXT: BUNDLE implicit undef [[REG_SEQUENCE]] {
+    ; CHECK-NEXT:   S_NOP 0, implicit [[REG_SEQUENCE]]
+    ; CHECK-NEXT: }
+    %0 = IMPLICIT_DEF
+    %1 = REG_SEQUENCE %0.sub0, %subreg.sub0, %0.sub1, %subreg.sub1
+    BUNDLE implicit %1 {
+      S_NOP 0, implicit %1
+    }
+...
+---
+name: headerless_bundle_def_not_marked_dead
+tracksRegLiveness: true
+registers:
+  - { id: 0, class: sreg_64 }
+body: |
+  bb.0:
+    ; CHECK-LABEL: name: headerless_bundle_def_not_marked_dead
+    ; CHECK: dead [[S_MOV_B64_:%[0-9]+]]:sreg_64 = S_MOV_B64 0 {
+    ; CHECK-NEXT:   S_NOP 0, implicit internal [[S_MOV_B64_]]
+    ; CHECK-NEXT: }
+    %0 = S_MOV_B64 0 {
+      S_NOP 0, implicit internal %0
+    }
+...

>From a3b599368f4be8b049bda1fdf8937afc793dea01 Mon Sep 17 00:00:00 2001
From: Kevin McAfee <kmcafee at nvidia.com>
Date: Fri, 4 Sep 2026 22:24:01 +0000
Subject: [PATCH 2/3] [CodeGen] DetectDeadLanes: do not rewrite operand flags
 on bundles

modifySubRegisterOperandStatus() only visits top level instructions, so
for a bundle it only sees the header. Marking bundle header operands
dead or undef could make the header disagree with the bundled
instructions, which are what LiveIntervals looks at. Rewriting the
bundled instructions would not be correct either: bundle internal reads
are ignored by MachineOperand::readsReg(), so an internal def only used
inside the bundle would be marked dead.
---
 llvm/lib/CodeGen/DetectDeadLanes.cpp                  | 7 +++++++
 llvm/test/CodeGen/AMDGPU/detect-dead-lanes-bundle.mir | 6 +++---
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/CodeGen/DetectDeadLanes.cpp b/llvm/lib/CodeGen/DetectDeadLanes.cpp
index 125c129f5edc4..77010b5d6da0f 100644
--- a/llvm/lib/CodeGen/DetectDeadLanes.cpp
+++ b/llvm/lib/CodeGen/DetectDeadLanes.cpp
@@ -497,6 +497,13 @@ DetectDeadLanes::modifySubRegisterOperandStatus(const DeadLaneDetector &DLD,
   // Mark operands as dead/unused.
   for (MachineBasicBlock &MBB : MF) {
     for (MachineInstr &MI : MBB) {
+      // Marking bundle header operands dead or undef could make the header
+      // disagree with the bundled instructions. Rewriting the bundled
+      // instructions would not be correct either: bundle internal reads are
+      // ignored by MachineOperand::readsReg(), so an internal def only used
+      // inside the bundle would be marked dead.
+      if (MI.isBundled())
+        continue;
       for (MachineOperand &MO : MI.operands()) {
         if (!MO.isReg())
           continue;
diff --git a/llvm/test/CodeGen/AMDGPU/detect-dead-lanes-bundle.mir b/llvm/test/CodeGen/AMDGPU/detect-dead-lanes-bundle.mir
index 79d4365187ffb..7a5178a7ce1b5 100644
--- a/llvm/test/CodeGen/AMDGPU/detect-dead-lanes-bundle.mir
+++ b/llvm/test/CodeGen/AMDGPU/detect-dead-lanes-bundle.mir
@@ -10,7 +10,7 @@ body: |
   bb.0:
     ; CHECK-LABEL: name: bundle_header_use_not_marked_undef
     ; CHECK: [[DEF:%[0-9]+]]:sreg_64 = IMPLICIT_DEF
-    ; CHECK-NEXT: BUNDLE implicit undef [[DEF]] {
+    ; CHECK-NEXT: BUNDLE implicit [[DEF]] {
     ; CHECK-NEXT:   S_NOP 0, implicit [[DEF]]
     ; CHECK-NEXT: }
     ; CHECK-NEXT: S_NOP 0, implicit undef [[DEF]]
@@ -31,7 +31,7 @@ body: |
     ; CHECK-LABEL: name: bundle_header_use_not_marked_undef_via_reg_sequence
     ; CHECK: [[DEF:%[0-9]+]]:sgpr_128 = IMPLICIT_DEF
     ; CHECK-NEXT: [[REG_SEQUENCE:%[0-9]+]]:sreg_64 = REG_SEQUENCE undef [[DEF]].sub0, %subreg.sub0, undef [[DEF]].sub1, %subreg.sub1
-    ; CHECK-NEXT: BUNDLE implicit undef [[REG_SEQUENCE]] {
+    ; CHECK-NEXT: BUNDLE implicit [[REG_SEQUENCE]] {
     ; CHECK-NEXT:   S_NOP 0, implicit [[REG_SEQUENCE]]
     ; CHECK-NEXT: }
     %0 = IMPLICIT_DEF
@@ -48,7 +48,7 @@ registers:
 body: |
   bb.0:
     ; CHECK-LABEL: name: headerless_bundle_def_not_marked_dead
-    ; CHECK: dead [[S_MOV_B64_:%[0-9]+]]:sreg_64 = S_MOV_B64 0 {
+    ; CHECK: [[S_MOV_B64_:%[0-9]+]]:sreg_64 = S_MOV_B64 0 {
     ; CHECK-NEXT:   S_NOP 0, implicit internal [[S_MOV_B64_]]
     ; CHECK-NEXT: }
     %0 = S_MOV_B64 0 {

>From c0329958df2ca5b669379cd0e9eee5217bffe60e Mon Sep 17 00:00:00 2001
From: Kevin McAfee <kevin.a.mcafee at gmail.com>
Date: Thu, 10 Sep 2026 12:54:14 -0700
Subject: [PATCH 3/3] Update
 llvm/test/CodeGen/AMDGPU/detect-dead-lanes-bundle.mir

Co-authored-by: Matt Arsenault <arsenm2 at gmail.com>
---
 llvm/test/CodeGen/AMDGPU/detect-dead-lanes-bundle.mir | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/test/CodeGen/AMDGPU/detect-dead-lanes-bundle.mir b/llvm/test/CodeGen/AMDGPU/detect-dead-lanes-bundle.mir
index 7a5178a7ce1b5..b6bff43f3bab4 100644
--- a/llvm/test/CodeGen/AMDGPU/detect-dead-lanes-bundle.mir
+++ b/llvm/test/CodeGen/AMDGPU/detect-dead-lanes-bundle.mir
@@ -1,6 +1,6 @@
 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
-# RUN: llc -mtriple=amdgcn -mcpu=gfx600 -run-pass detect-dead-lanes -verify-machineinstrs -o - %s | FileCheck %s
-# RUN: llc -mtriple=amdgcn -mcpu=gfx600 -passes detect-dead-lanes -verify-machineinstrs -o - %s | FileCheck %s
+# RUN: llc -mtriple=amdgpu9.00 -run-pass=detect-dead-lanes -o - %s | FileCheck %s
+# RUN: llc -mtriple=amdgpu6.00 -passes=detect-dead-lanes -o - %s | FileCheck %s
 ---
 name: bundle_header_use_not_marked_undef
 tracksRegLiveness: true



More information about the llvm-commits mailing list