[llvm] [AMDGPU] Simplify waitcnt insertion on function entry. NFC. (PR #172461)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 16 03:25:52 PST 2025


https://github.com/jayfoad created https://github.com/llvm/llvm-project/pull/172461

This pass runs way too late for PHI instructions.


>From 2da46a3fab4d475e01b8c49ac2270cda30ace1d8 Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Tue, 16 Dec 2025 11:08:45 +0000
Subject: [PATCH] [AMDGPU] Simplify waitcnt insertion on function entry. NFC.

This pass runs way too late for PHI instructions.
---
 llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
index 0a743dbc2e258..ab7f559004599 100644
--- a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
@@ -2829,7 +2829,6 @@ bool SIInsertWaitcnts::run(MachineFunction &MF) {
   bool Modified = false;
 
   MachineBasicBlock &EntryBB = MF.front();
-  MachineBasicBlock::iterator I = EntryBB.begin();
 
   if (!MFI->isEntryFunction()) {
     // Wait for any outstanding memory operations that the input registers may
@@ -2838,9 +2837,9 @@ bool SIInsertWaitcnts::run(MachineFunction &MF) {
 
     // TODO: Could insert earlier and schedule more liberally with operations
     // that only use caller preserved registers.
-    for (MachineBasicBlock::iterator E = EntryBB.end();
-         I != E && (I->isPHI() || I->isMetaInstruction()); ++I)
-      ;
+    MachineBasicBlock::iterator I = EntryBB.begin();
+    while (I != EntryBB.end() && I->isMetaInstruction())
+      ++I;
 
     if (ST->hasExtendedWaitCounts()) {
       BuildMI(EntryBB, I, DebugLoc(), TII->get(AMDGPU::S_WAIT_LOADCNT_DSCNT))



More information about the llvm-commits mailing list