[llvm] [AMDGPU] Fold copies of constant physical registers into their uses (PR #154410)

Stanislav Mekhanoshin via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 17 01:16:12 PDT 2025


================
@@ -727,8 +728,12 @@ bool SIFoldOperandsImpl::updateOperand(FoldCandidate &Fold) const {
   // 16-bit SGPRs instead of 32-bit ones.
   if (Old.getSubReg() == AMDGPU::lo16 && TRI->isSGPRReg(*MRI, New->getReg()))
     Old.setSubReg(AMDGPU::NoSubRegister);
-  Old.substVirtReg(New->getReg(), New->getSubReg(), *TRI);
-  Old.setIsUndef(New->isUndef());
+  if (New->getReg().isPhysical()) {
+    Old.substPhysReg(New->getReg(), *TRI);
+  } else {
+    Old.substVirtReg(New->getReg(), New->getSubReg(), *TRI);
+    Old.setIsUndef(New->isUndef());
----------------
rampitec wrote:

Well, it does not really change anything. But if you think how it looks in assembly... There is already branching. Yes, it is not necessary. It just hides code which will be dead into a branch which is already there.

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


More information about the llvm-commits mailing list