[llvm] [AMDGPU] Skip debug instructions in SIShrinkInstructions::matchSwap (PR #160123)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 22 08:48:47 PDT 2025
https://github.com/jayfoad updated https://github.com/llvm/llvm-project/pull/160123
>From f95713483e91435d60b1bc325b10a4994f9e6fbb Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Mon, 22 Sep 2025 15:00:43 +0100
Subject: [PATCH 1/2] [AMDGPU] Skip debug instructions in
SIShrinkInstructions::matchSwap
---
llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp | 2 ++
llvm/test/CodeGen/AMDGPU/v_swap_b32.mir | 1 +
2 files changed, 3 insertions(+)
diff --git a/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp b/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp
index 7a519117f2482..4f0e6d07208e6 100644
--- a/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp
+++ b/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp
@@ -733,6 +733,8 @@ MachineInstr *SIShrinkInstructions::matchSwap(MachineInstr &MovT) const {
MachineInstr *MovX = nullptr;
for (auto IY = MovY->getIterator(), I = std::next(MovT.getIterator());
I != IY; ++I) {
+ if (I->isMetaInstruction())
+ continue;
if (instReadsReg(&*I, X, Xsub) || instModifiesReg(&*I, Y, Ysub) ||
instModifiesReg(&*I, T, Tsub) ||
(MovX && instModifiesReg(&*I, X, Xsub))) {
diff --git a/llvm/test/CodeGen/AMDGPU/v_swap_b32.mir b/llvm/test/CodeGen/AMDGPU/v_swap_b32.mir
index 95aaea6ea8091..27229cd518028 100644
--- a/llvm/test/CodeGen/AMDGPU/v_swap_b32.mir
+++ b/llvm/test/CodeGen/AMDGPU/v_swap_b32.mir
@@ -1,4 +1,5 @@
# RUN: llc -simplify-mir -mtriple=amdgcn -mcpu=gfx900 -run-pass=si-shrink-instructions -verify-machineinstrs %s -o - | FileCheck -check-prefix=GCN %s
+# RUN: llc -simplify-mir -mtriple=amdgcn -mcpu=gfx900 -run-pass=si-shrink-instructions -verify-machineinstrs %s -o - -debugify-and-strip-all-safe | FileCheck -check-prefix=GCN %s
# RUN: llc -simplify-mir -mtriple=amdgcn -mcpu=gfx900 -passes=si-shrink-instructions -verify-machineinstrs %s -o - | FileCheck -check-prefix=GCN %s
# GCN-LABEL: name: swap_phys_condensed
>From f5b599e271a64d11a203fc2f52e4216140efaf9d Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Mon, 22 Sep 2025 16:48:23 +0100
Subject: [PATCH 2/2] Fix
---
llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp b/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp
index 4f0e6d07208e6..179ecbad5239f 100644
--- a/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp
+++ b/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp
@@ -712,10 +712,13 @@ MachineInstr *SIShrinkInstructions::matchSwap(MachineInstr &MovT) const {
bool KilledT = false;
for (auto Iter = std::next(MovT.getIterator()),
E = MovT.getParent()->instr_end();
- Iter != E && Count < SearchLimit && !KilledT; ++Iter, ++Count) {
+ Iter != E && Count < SearchLimit && !KilledT; ++Iter) {
MachineInstr *MovY = &*Iter;
KilledT = MovY->killsRegister(T, TRI);
+ if (MovY->isDebugInstr())
+ continue;
+ ++Count;
if ((MovY->getOpcode() != AMDGPU::V_MOV_B32_e32 &&
MovY->getOpcode() != AMDGPU::V_MOV_B16_t16_e32 &&
@@ -733,7 +736,7 @@ MachineInstr *SIShrinkInstructions::matchSwap(MachineInstr &MovT) const {
MachineInstr *MovX = nullptr;
for (auto IY = MovY->getIterator(), I = std::next(MovT.getIterator());
I != IY; ++I) {
- if (I->isMetaInstruction())
+ if (I->isDebugInstr())
continue;
if (instReadsReg(&*I, X, Xsub) || instModifiesReg(&*I, Y, Ysub) ||
instModifiesReg(&*I, T, Tsub) ||
More information about the llvm-commits
mailing list