[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 01:24:07 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:
I also wonder if something more is needed to make debug-info as good as possible in case this optimization triggers.
I tried changing to use_nodbg_empty locally, and then I noticed that
```test/DebugInfo/ARM/partial-subreg.ll``` failed.
After PHI elimination we then got
```
%18:dpair = COPY killed %11:qpr
DBG_VALUE %5:dpair, $noreg, !"self", !DIExpression(DW_OP_LLVM_fragment, 0, 96), debug-location !9; simd.swift:5897:5 line no:5897
```
instead of the previous
```
%5:dpair = COPY killed %11:qpr
DBG_VALUE %5:dpair, $noreg, !"self", !DIExpression(DW_OP_LLVM_fragment, 0, 96), debug-location !9; simd.swift:5897:5 line no:5897
```
i.e. tthe DBG_VALUE was leftt witth a reference to %5 which gott no definition.
https://github.com/llvm/llvm-project/pull/131837
More information about the llvm-commits
mailing list