[llvm] [AMDGPU] Generate waterfall for calls with SGPR(inreg) argument (PR #146997)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 20 17:36:21 PDT 2025


================
@@ -1128,6 +1166,45 @@ void SIFixSGPRCopies::lowerVGPR2SGPRCopies(MachineFunction &MF) {
   }
 }
 
+void SIFixSGPRCopies::lowerPysicalSGPRInsts(MachineFunction &MF) {
+  for (auto &Entry : WaterFalls) {
+    MachineInstr *MI = Entry.first;
+    struct V2PysSCopyInfo Info = Entry.second;
+    if (Info.MOs.size() == 0 || Info.SGPRs.size() != Info.MOs.size())
+      continue;
+
+    if (MI->getOpcode() == AMDGPU::SI_CALL_ISEL) {
+      // Move everything between ADJCALLSTACKUP and ADJCALLSTACKDOWN and
+      // following copies, we also need to move copies from and to physical
+      // registers into the loop block.
+      unsigned FrameSetupOpcode = TII->getCallFrameSetupOpcode();
+      unsigned FrameDestroyOpcode = TII->getCallFrameDestroyOpcode();
+
+      // Also move the copies to physical registers into the loop block
+      MachineBasicBlock &MBB = *MI->getParent();
+      MachineBasicBlock::iterator Start(MI);
+      while (Start->getOpcode() != FrameSetupOpcode)
+        --Start;
+      MachineBasicBlock::iterator End(MI);
+      while (End->getOpcode() != FrameDestroyOpcode)
+        ++End;
+
+      // Also include following copies of the return value
+      ++End;
+      while (End != MBB.end() && End->isCopy() && End->getOperand(1).isReg() &&
+             MI->definesRegister(End->getOperand(1).getReg(), TRI))
+        ++End;
+
+      llvm::loadMBUFScalarOperandsFromVGPR(*TII, *MI, Info.MOs, MDT, Start, End,
+                                           Info.SGPRs);
+    }
+  }
+  // Avoid some O0 tests where no use of COPY to SGPR
+  if (!WaterFalls.empty())
+    for (auto &Entry : V2PhySCopies)
+      Entry->eraseFromParent();
----------------
Shoreshen wrote:

Hi @jmmartinez , it looks like the copy was a transfer of stack:
<img width="1172" height="873" alt="image" src="https://github.com/user-attachments/assets/6d343ea2-dae8-4962-bf26-21bedb821699" />
If that's the case, there would be no use of it.....

Maybe I should exclude COPYs to stack pointer register...

https://github.com/llvm/llvm-project/pull/146997


More information about the llvm-commits mailing list