[llvm] [PHIElimination] Account for PHI operands that appear more than once (PR #146806)

Mikael Holmén via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 2 22:05:32 PDT 2025


================
@@ -744,6 +732,32 @@ void PHIEliminationImpl::LowerPHINode(MachineBasicBlock &MBB,
     }
   }
 
+  // Remove redundant COPY instruction chains, which were potentially added by
+  // the code above. This can simplify the CFG which later on to prevent a
+  // suboptimal block layout.
+  for (MachineInstr *NewCopy : InsertedCopies) {
+    if (NewCopy->isImplicitDef())
+      continue;
+    Register IncomingReg = NewCopy->getOperand(0).getReg();
+    if (!IncomingReg.isVirtual())
+      continue;
+    Register SrcReg = NewCopy->getOperand(1).getReg();
+    if (!MRI->hasOneUse(SrcReg))
----------------
mikaelholmen wrote:

hasOneNonDBGUse ?

Also see a previous comment at https://github.com/llvm/llvm-project/pull/131837#discussion_r2174969801

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


More information about the llvm-commits mailing list