[llvm] [CodeGen] Debug insns must not affect liveness analysis (PR #193104)
via llvm-commits
llvm-commits at lists.llvm.org
Fri May 8 14:06:41 PDT 2026
https://github.com/LU-JOHN updated https://github.com/llvm/llvm-project/pull/193104
>From 346f58207fc3dbbb63a23025fc44ec42b066f5b5 Mon Sep 17 00:00:00 2001
From: John Lu <John.Lu at amd.com>
Date: Mon, 20 Apr 2026 17:51:44 -0500
Subject: [PATCH 1/5] Debug insns must not affect DCE
Signed-off-by: John Lu <John.Lu at amd.com>
---
.../CodeGen/DeadMachineInstructionElim.cpp | 3 +++
...debug-independence-dead-mi-elimination.mir | 25 +++++++++++++++++++
2 files changed, 28 insertions(+)
create mode 100644 llvm/test/CodeGen/AMDGPU/debug-independence-dead-mi-elimination.mir
diff --git a/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp b/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp
index 8783afadbf097..b8dec965884b1 100644
--- a/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp
+++ b/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp
@@ -101,6 +101,9 @@ bool DeadMachineInstructionElimImpl::eliminateDeadMI(MachineFunction &MF) {
// Now scan the instructions and delete dead ones, tracking physreg
// liveness as we go.
for (MachineInstr &MI : make_early_inc_range(reverse(*MBB))) {
+ // Do not let debug instructions affect liveness calculations.
+ if (MI.isDebugInstr())
+ continue;
// If the instruction is dead, delete it!
if (MI.isDead(*MRI, &LivePhysRegs)) {
LLVM_DEBUG(dbgs() << "DeadMachineInstructionElim: DELETING: " << MI);
diff --git a/llvm/test/CodeGen/AMDGPU/debug-independence-dead-mi-elimination.mir b/llvm/test/CodeGen/AMDGPU/debug-independence-dead-mi-elimination.mir
new file mode 100644
index 0000000000000..b47a39e646252
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/debug-independence-dead-mi-elimination.mir
@@ -0,0 +1,25 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+# RUN: llc -mtriple=amdgcn -mcpu=gfx900 -run-pass dead-mi-elimination -o - %s | FileCheck %s
+# RUN: llc -mtriple=amdgcn -mcpu=gfx900 -run-pass dead-mi-elimination -o - %s -debugify-and-strip-all-safe | FileCheck %s
+
+# Ensure that references in debug instructions to register results in dead
+# instructions does not prevent DCE.
+
+---
+name: func
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $vgpr0
+ ; GCN-LABEL: name: func
+ ; GCN: liveins: $vgpr0
+ ; GCN-NEXT: {{ $}}
+ ; GCN-NEXT: SI_RETURN implicit $vgpr0
+ ; CHECK-LABEL: name: func
+ ; CHECK: liveins: $vgpr0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: SI_RETURN implicit $vgpr0
+ $sgpr0 = S_MOV_B32 0
+ SI_RETURN implicit $vgpr0
+...
+
>From 491cb0f435fcea693de6cbbb3a3420e472a5943b Mon Sep 17 00:00:00 2001
From: John Lu <John.Lu at amd.com>
Date: Tue, 21 Apr 2026 15:42:16 -0500
Subject: [PATCH 2/5] Skip debug insns in stepBackward
Signed-off-by: John Lu <John.Lu at amd.com>
---
llvm/lib/CodeGen/DeadMachineInstructionElim.cpp | 3 ---
llvm/lib/CodeGen/LiveRegUnits.cpp | 4 ++++
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp b/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp
index b8dec965884b1..8783afadbf097 100644
--- a/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp
+++ b/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp
@@ -101,9 +101,6 @@ bool DeadMachineInstructionElimImpl::eliminateDeadMI(MachineFunction &MF) {
// Now scan the instructions and delete dead ones, tracking physreg
// liveness as we go.
for (MachineInstr &MI : make_early_inc_range(reverse(*MBB))) {
- // Do not let debug instructions affect liveness calculations.
- if (MI.isDebugInstr())
- continue;
// If the instruction is dead, delete it!
if (MI.isDead(*MRI, &LivePhysRegs)) {
LLVM_DEBUG(dbgs() << "DeadMachineInstructionElim: DELETING: " << MI);
diff --git a/llvm/lib/CodeGen/LiveRegUnits.cpp b/llvm/lib/CodeGen/LiveRegUnits.cpp
index 348ccd85f4c45..c04c1404c29a5 100644
--- a/llvm/lib/CodeGen/LiveRegUnits.cpp
+++ b/llvm/lib/CodeGen/LiveRegUnits.cpp
@@ -42,6 +42,10 @@ void LiveRegUnits::addRegsInMask(const uint32_t *RegMask) {
}
void LiveRegUnits::stepBackward(const MachineInstr &MI) {
+ // Do not let debug instructions affect liveness calculations.
+ if (MI.isDebugInstr())
+ return;
+
// Remove defined registers and regmask kills from the set.
for (const MachineOperand &MOP : MI.operands()) {
if (MOP.isReg()) {
>From 83b7217a5974907f478484ec4d3a64f4c0d70cd9 Mon Sep 17 00:00:00 2001
From: John Lu <John.Lu at amd.com>
Date: Tue, 21 Apr 2026 15:45:28 -0500
Subject: [PATCH 3/5] Fix grammar
Signed-off-by: John Lu <John.Lu at amd.com>
---
.../CodeGen/AMDGPU/debug-independence-dead-mi-elimination.mir | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/test/CodeGen/AMDGPU/debug-independence-dead-mi-elimination.mir b/llvm/test/CodeGen/AMDGPU/debug-independence-dead-mi-elimination.mir
index b47a39e646252..c1844406a8917 100644
--- a/llvm/test/CodeGen/AMDGPU/debug-independence-dead-mi-elimination.mir
+++ b/llvm/test/CodeGen/AMDGPU/debug-independence-dead-mi-elimination.mir
@@ -3,7 +3,7 @@
# RUN: llc -mtriple=amdgcn -mcpu=gfx900 -run-pass dead-mi-elimination -o - %s -debugify-and-strip-all-safe | FileCheck %s
# Ensure that references in debug instructions to register results in dead
-# instructions does not prevent DCE.
+# instructions do not prevent DCE.
---
name: func
>From ca216bf451308959d5b3bb3bca34e800b46a4485 Mon Sep 17 00:00:00 2001
From: John Lu <John.Lu at amd.com>
Date: Wed, 22 Apr 2026 08:40:35 -0500
Subject: [PATCH 4/5] Address feedback
Signed-off-by: John Lu <John.Lu at amd.com>
---
.../CodeGen/AMDGPU/debug-independence-dead-mi-elimination.mir | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/test/CodeGen/AMDGPU/debug-independence-dead-mi-elimination.mir b/llvm/test/CodeGen/AMDGPU/debug-independence-dead-mi-elimination.mir
index c1844406a8917..a35eb170ea937 100644
--- a/llvm/test/CodeGen/AMDGPU/debug-independence-dead-mi-elimination.mir
+++ b/llvm/test/CodeGen/AMDGPU/debug-independence-dead-mi-elimination.mir
@@ -1,6 +1,6 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
-# RUN: llc -mtriple=amdgcn -mcpu=gfx900 -run-pass dead-mi-elimination -o - %s | FileCheck %s
-# RUN: llc -mtriple=amdgcn -mcpu=gfx900 -run-pass dead-mi-elimination -o - %s -debugify-and-strip-all-safe | FileCheck %s
+# RUN: llc -mtriple=amdgcn -mcpu=gfx900 -run-pass=dead-mi-elimination -o - %s | FileCheck %s
+# RUN: llc -mtriple=amdgcn -mcpu=gfx900 -run-pass=dead-mi-elimination -o - %s -debugify-and-strip-all-safe | FileCheck %s
# Ensure that references in debug instructions to register results in dead
# instructions do not prevent DCE.
>From 3949f7c416410862e2ea5c528d9287b01f9e9066 Mon Sep 17 00:00:00 2001
From: John Lu <John.Lu at amd.com>
Date: Fri, 8 May 2026 16:06:24 -0500
Subject: [PATCH 5/5] More testing of debug-independence in LiveRegUnits
Signed-off-by: John Lu <John.Lu at amd.com>
---
llvm/test/CodeGen/AArch64/machine-outliner-calls.mir | 1 +
llvm/test/CodeGen/AMDGPU/eliminate-frame-index-v-add-co-u32.mir | 1 +
llvm/test/CodeGen/ARM/flag-crash.ll | 1 +
llvm/test/CodeGen/Thumb2/ldr-str-imm12.ll | 1 +
llvm/test/CodeGen/WebAssembly/simd-arith.ll | 1 +
5 files changed, 5 insertions(+)
diff --git a/llvm/test/CodeGen/AArch64/machine-outliner-calls.mir b/llvm/test/CodeGen/AArch64/machine-outliner-calls.mir
index 700a5b228122f..ea995b002e976 100644
--- a/llvm/test/CodeGen/AArch64/machine-outliner-calls.mir
+++ b/llvm/test/CodeGen/AArch64/machine-outliner-calls.mir
@@ -1,4 +1,5 @@
# RUN: llc -mtriple=aarch64--- -run-pass=prologepilog -run-pass=machine-outliner -verify-machineinstrs %s -o - | FileCheck %s
+# RUN: llc -mtriple=aarch64--- -run-pass=prologepilog -run-pass=machine-outliner -verify-machineinstrs %s -o - -debugify-and-strip-all-safe | FileCheck %s
# RUN: llc -mtriple=aarch64-pc-windows-msvc -run-pass=prologepilog -run-pass=machine-outliner -verify-machineinstrs %s -o - | FileCheck %s -check-prefix=WINDOWS
--- |
define void @baz() #0 {
diff --git a/llvm/test/CodeGen/AMDGPU/eliminate-frame-index-v-add-co-u32.mir b/llvm/test/CodeGen/AMDGPU/eliminate-frame-index-v-add-co-u32.mir
index 79486d56c55ca..c7dcfe1e5754a 100644
--- a/llvm/test/CodeGen/AMDGPU/eliminate-frame-index-v-add-co-u32.mir
+++ b/llvm/test/CodeGen/AMDGPU/eliminate-frame-index-v-add-co-u32.mir
@@ -1,5 +1,6 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx700 -verify-machineinstrs -run-pass=prologepilog %s -o - | FileCheck -check-prefixes=MUBUFW64,GFX7 %s
+# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx700 -verify-machineinstrs -run-pass=prologepilog -debugify-and-strip-all-safe %s -o - | FileCheck -check-prefixes=MUBUFW64,GFX7 %s
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx803 -verify-machineinstrs -run-pass=prologepilog %s -o - | FileCheck -check-prefixes=MUBUFW64,GFX8 %s
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -verify-machineinstrs -run-pass=prologepilog %s -o - | FileCheck -check-prefixes=MUBUFW64,GFX900 %s
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -verify-machineinstrs -run-pass=prologepilog %s -o - | FileCheck -check-prefixes=MUBUFW64,GFX90A %s
diff --git a/llvm/test/CodeGen/ARM/flag-crash.ll b/llvm/test/CodeGen/ARM/flag-crash.ll
index 83a6b2470c51a..056f097fd17f8 100644
--- a/llvm/test/CodeGen/ARM/flag-crash.ll
+++ b/llvm/test/CodeGen/ARM/flag-crash.ll
@@ -1,4 +1,5 @@
; RUN: llc < %s -O3 -mtriple=thumbv7-apple-darwin10 -mcpu=cortex-a8 -relocation-model=pic
+; RUN: llc < %s -O3 -mtriple=thumbv7-apple-darwin10 -mcpu=cortex-a8 -relocation-model=pic -debugify-and-strip-all-safe
; PR7484
%struct.gs_matrix = type { float, i32, float, i32, float, i32, float, i32, float, i32, float, i32 }
diff --git a/llvm/test/CodeGen/Thumb2/ldr-str-imm12.ll b/llvm/test/CodeGen/Thumb2/ldr-str-imm12.ll
index 1d177b0a4ebbf..ce039cb1d5452 100644
--- a/llvm/test/CodeGen/Thumb2/ldr-str-imm12.ll
+++ b/llvm/test/CodeGen/Thumb2/ldr-str-imm12.ll
@@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=thumbv7-apple-darwin -arm-atomic-cfg-tidy=0 -mcpu=cortex-a8 -relocation-model=pic -frame-pointer=all | FileCheck %s
+; RUN: llc < %s -mtriple=thumbv7-apple-darwin -arm-atomic-cfg-tidy=0 -mcpu=cortex-a8 -relocation-model=pic -frame-pointer=all -debugify-and-strip-all-safe | FileCheck %s
; rdar://7352504
%0 = type { i16, i8, i8 }
diff --git a/llvm/test/CodeGen/WebAssembly/simd-arith.ll b/llvm/test/CodeGen/WebAssembly/simd-arith.ll
index cb06ee84ec99c..5fcbd2bee5861 100644
--- a/llvm/test/CodeGen/WebAssembly/simd-arith.ll
+++ b/llvm/test/CodeGen/WebAssembly/simd-arith.ll
@@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+simd128 | FileCheck %s --check-prefix=SIMD128
+; RUN: llc < %s -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+simd128 -debugify-and-strip-all-safe | FileCheck %s --check-prefix=SIMD128
; RUN: llc < %s -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+simd128 -fast-isel | FileCheck %s --check-prefix=SIMD128-FAST
; RUN: llc < %s -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s --check-prefix=NO-SIMD128
; RUN: llc < %s -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -fast-isel | FileCheck %s --check-prefix=NO-SIMD128-FAST
More information about the llvm-commits
mailing list