[llvm] [AMDGPU] SIFixSgprCopies should not process twice VGPR to SGPR copies inserted by PHI preprocessing. (PR #134153)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 8 09:23:47 PDT 2025


================
@@ -971,16 +971,29 @@ void SIFixSGPRCopies::analyzeVGPRToSGPRCopy(MachineInstr* MI) {
       }
     } else if (Inst->getNumExplicitDefs() != 0) {
       Register Reg = Inst->getOperand(0).getReg();
-      if (TRI->isSGPRReg(*MRI, Reg) && !TII->isVALU(*Inst))
-        for (auto &U : MRI->use_instructions(Reg))
-          Users.push_back(&U);
+      if (TRI->isSGPRReg(*MRI, Reg) && !TII->isVALU(*Inst)) {
+        if (Reg.isVirtual()) {
+          for (auto &U : MRI->use_instructions(Reg))
+            Users.push_back(&U);
+        } else {
+          auto I = Inst->getIterator();
+          auto E = Inst->getParent()->end();
+          while (++I != E) {
+            if (I->readsRegister(Reg, TRI))
+              Users.push_back(&*I);
+            if (I->modifiesRegister(Reg, TRI))
+              break;
+          }
----------------
arsenm wrote:

Because it's hard and overcomplicated. You don't know the semantic context for why the physical register is here. and this certainly isn't testing all the edge cases for physical register tracking. This wasn't in the last revision, and this patch should be the bare minimum to fix the issue 

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


More information about the llvm-commits mailing list