[llvm] [AMDGPU][True16][CodeGen] stop emitting spgr_lo16 from isel (PR #144819)

Brox Chen via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 23 14:51:36 PDT 2025


================
@@ -7804,15 +7805,22 @@ void SIInstrInfo::moveToVALUImpl(SIInstrWorklist &Worklist,
       // that copies will end up as machine instructions and not be
       // eliminated.
       addUsersToMoveToVALUWorklist(DstReg, MRI, Worklist);
-      MRI.replaceRegWith(DstReg, Inst.getOperand(1).getReg());
-      MRI.clearKillFlags(Inst.getOperand(1).getReg());
+      Register NewDstReg = Inst.getOperand(1).getReg();
+      MRI.replaceRegWith(DstReg, NewDstReg);
+      MRI.clearKillFlags(NewDstReg);
       Inst.getOperand(0).setReg(DstReg);
       // Make sure we don't leave around a dead VGPR->SGPR copy. Normally
       // these are deleted later, but at -O0 it would leave a suspicious
       // looking illegal copy of an undef register.
       for (unsigned I = Inst.getNumOperands() - 1; I != 0; --I)
         Inst.removeOperand(I);
       Inst.setDesc(get(AMDGPU::IMPLICIT_DEF));
+      // Legalize t16 operand since replaceReg is called after addUsersToVALU
----------------
broxigarchen wrote:

I cannot. This case is special as it use the source reg from the copy instead of creating a new reg to replace the dest reg.

If I called replace reg with the source reg first, and then call addUserstoVALU, it includes additional users from the source reg which is incorrect. i.e
```
a = copy b
c = func(a)
d = func(b)
```
This includes addtional inst d.

Another option is to create a new reg and replace the dest reg like what we normally do. But seems it hit some regressions in some other passes, like what the comment explains on the top of this code so I would rather keep it.

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


More information about the llvm-commits mailing list