[llvm] [X86][APX] Reuse EFLAGS across multi-predecessor blocks via NF in optimizeCompareInstr (PR #208184)
Phoebe Wang via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 8 07:34:36 PDT 2026
================
@@ -5285,6 +5300,105 @@ static std::pair<X86::CondCode, unsigned> isUseDefConvertible(const MachineInstr
}
}
+MachineInstr *X86InstrInfo::findDominatingRedundantFlagInstr(
+ MachineInstr &CmpInstr, Register SrcReg, Register SrcReg2, int64_t CmpMask,
+ int64_t CmpValue, MachineBasicBlock *MultiPredMBB, bool &IsSwapped,
+ int64_t &ImmDelta,
+ SmallVectorImpl<std::pair<MachineInstr *, unsigned>> &InstsToUpdate) const {
+ assert(Subtarget.hasNF() && "NF feature required");
+ MachineBasicBlock &CmpMBB = *CmpInstr.getParent();
+ MachineFunction &MF = *CmpMBB.getParent();
+ const TargetRegisterInfo *TRI = &getRegisterInfo();
+
+ // The caller already scanned MultiPredMBB (and any single-predecessor blocks
+ // between it and CmpMBB) without finding the producer, so the producer must
+ // live in a block that strictly dominates MultiPredMBB. Walk up the
+ // immediate-dominator chain. In each dominating block scan backward: the
+ // redundant producer ends the search; an NF-convertible clobber is stepped
+ // over (it will be collected by the path walk below) so the producer can
+ // still be found earlier in the same block or further up; any other EFLAGS
+ // clobber shadows the producer, so its flags cannot reach CmpInstr.
+ MachineDominatorTree MDT(MF);
+ MachineDomTreeNode *Node = MDT.getNode(MultiPredMBB);
+ MachineInstr *Sub = nullptr;
+ for (Node = Node ? Node->getIDom() : nullptr; Node && !Sub;
----------------
phoebewang wrote:
```
if (!Node)
return nullptr;
```
https://github.com/llvm/llvm-project/pull/208184
More information about the llvm-commits
mailing list