Skip to content

Conversation

@ssahasra
Copy link
Collaborator

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Jun 25, 2025

@llvm/pr-subscribers-backend-amdgpu

Author: Sameer Sahasrabuddhe (ssahasra)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/145694.diff

1 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp (+13-2)
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))) {

@ssahasra ssahasra force-pushed the users/ssahasra/waitcnt-dont-crash branch from 760b8ee to 4e7db8f Compare June 25, 2025 12:54
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use LLVM_DEBUG({}) instead

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! That looks so much nicer!

@ssahasra ssahasra force-pushed the users/ssahasra/waitcnt-dont-crash branch from 4e7db8f to a8133be Compare June 25, 2025 14:28
@ssahasra ssahasra merged commit 81e0799 into main Jun 25, 2025
7 checks passed
@ssahasra ssahasra deleted the users/ssahasra/waitcnt-dont-crash branch June 25, 2025 15:29
anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants