[llvm] [PHIElimination] Reuse existing COPY in predecessor basic block (PR #131837)

Mikael Holmén via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 3 00:08:56 PDT 2025


================
@@ -581,6 +581,15 @@ void PHIEliminationImpl::LowerPHINode(MachineBasicBlock &MBB,
       continue;
     }
 
+    // Reuse an existing copy in the block if possible.
+    if (MachineInstr *DefMI = MRI->getUniqueVRegDef(SrcReg)) {
+      if (DefMI->isCopy() && DefMI->getParent() == &opBlock &&
+          MRI->use_empty(SrcReg)) {
----------------
mikaelholmen wrote:

@guy-david :
E.g. with
```llc -verify-machineinstrs -O3 -mtriple=aarch64-linux-gnu bbi-108599_aarch64.mir -o - -run-pass phi-node-elimination```
you get different results depending on if you leave the DBG_VALUE in the input or not.
[bbi-108599_aarch64.mir.gz](https://github.com/user-attachments/files/21031362/bbi-108599_aarch64.mir.gz)


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


More information about the llvm-commits mailing list