[llvm] [VPlan] Remove MaskedCond and preserve SSA in early exits (PR #201784)
Andrei Elovikov via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 2 09:46:11 PDT 2026
================
@@ -3235,20 +3224,19 @@ bool VPlanTransforms::handleUncountableEarlyExits(
m_BranchOnCond(m_VPValue(CondOfEarlyExitingVPBB)));
assert(Matched && "Terminator must be BranchOnCond");
- // Insert the MaskedCond in the EarlyExitingVPBB so the predicator adds
- // the correct block mask.
VPBuilder EarlyExitingBuilder(EarlyExitingVPBB->getTerminator());
- auto *CondToEarlyExit = EarlyExitingBuilder.createNaryOp(
- VPInstruction::MaskedCond,
+ auto *CondToEarlyExit =
TrueSucc == ExitBlock
? CondOfEarlyExitingVPBB
- : EarlyExitingBuilder.createNot(CondOfEarlyExitingVPBB));
- assert((isa<VPIRValue>(CondOfEarlyExitingVPBB) ||
- !VPDT.properlyDominates(EarlyExitingVPBB, LatchVPBB) ||
- VPDT.properlyDominates(
- CondOfEarlyExitingVPBB->getDefiningRecipe()->getParent(),
- LatchVPBB)) &&
- "exit condition must dominate the latch");
+ : EarlyExitingBuilder.createNot(CondOfEarlyExitingVPBB);
+
+ // Add phis so there's a def of CondToEarlyExit on every path leading to the
+ // latch. The condition is false on paths that didn't go through
+ // EarlyExitingVPBB.
+ DenseMap<VPBasicBlock *, VPValue *> Defs = {{HeaderVPBB, Plan.getFalse()}};
+ Defs[EarlyExitingVPBB] = CondToEarlyExit;
+ CondToEarlyExit = vputils::reconstructSSA(LatchVPBB, Defs);
----------------
eas wrote:
Nit:
```suggestion
CondToEarlyExit = vputils::reconstructSSA(LatchVPBB,
{{HeaderVPBB, Plan.getFalse()},
{EarlyExitingVPBB, CondToEarlyExit});
```
likewise below.
https://github.com/llvm/llvm-project/pull/201784
More information about the llvm-commits
mailing list