[llvm] [AMDGPU][SIInsertWaitcnts] don't crash when printing messages at end of block (PR #145694)
Sameer Sahasrabuddhe via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 25 05:52:58 PDT 2025
https://github.com/ssahasra created https://github.com/llvm/llvm-project/pull/145694
None
>From 760b8ee98c0e166f892c0edb9b7f4fc6ea29b9c8 Mon Sep 17 00:00:00 2001
From: Sameer Sahasrabuddhe <sameer.sahasrabuddhe at amd.com>
Date: Wed, 25 Jun 2025 18:19:39 +0530
Subject: [PATCH] [AMDGPU][SIInsertWaitcnts] don't crash when printing messages
at end of block
---
llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
index f43831016952a..98e1696056f11 100644
--- a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
@@ -1353,7 +1353,14 @@ bool WaitcntGeneratorPreGFX12::applyPreexistingWaitcnt(
MachineInstr *WaitcntInstr = nullptr;
MachineInstr *WaitcntVsCntInstr = nullptr;
- LLVM_DEBUG(dbgs() << "PreGFX12::applyPreexistingWaitcnt at: " << *It);
+ // clang-format off
+ LLVM_DEBUG(dbgs() << "PreGFX12::applyPreexistingWaitcnt at: ";
+ if (It == OldWaitcntInstr.getParent()->instr_end())
+ dbgs() << "end of block\n";
+ else
+ dbgs() << *It;
+ );
+ // clang-format on
for (auto &II :
make_early_inc_range(make_range(OldWaitcntInstr.getIterator(), It))) {
@@ -1377,6 +1384,7 @@ bool WaitcntGeneratorPreGFX12::applyPreexistingWaitcnt(
// Merge consecutive waitcnt of the same type by erasing multiples.
if (WaitcntInstr || (!Wait.hasWaitExceptStoreCnt() && TrySimplify)) {
+ LLVM_DEBUG(dbgs() << "erased waitcnt: " << II);
II.eraseFromParent();
Modified = true;
} else
@@ -1507,7 +1515,10 @@ bool WaitcntGeneratorGFX12Plus::applyPreexistingWaitcnt(
MachineInstr *CombinedStoreDsCntInstr = nullptr;
MachineInstr *WaitInstrs[NUM_EXTENDED_INST_CNTS] = {};
- LLVM_DEBUG(dbgs() << "GFX12Plus::applyPreexistingWaitcnt at: " << *It);
+ LLVM_DEBUG(dbgs() << "GFX12Plus::applyPreexistingWaitcnt at: ";
+ if (It == OldWaitcntInstr.getParent()->instr_end()) dbgs()
+ << "end of block\n";
+ else dbgs() << *It);
for (auto &II :
make_early_inc_range(make_range(OldWaitcntInstr.getIterator(), It))) {
More information about the llvm-commits
mailing list