[llvm] [VPlan] Preserve SSA in early exits (PR #201784)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 21 05:49:30 PDT 2026
================
@@ -3326,20 +3320,20 @@ 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. EarlyExitingVPBB may be the same as HeaderVPBB, so
+ // assign in order.
+ DenseMap<VPBasicBlock *, VPValue *> Defs = {{HeaderVPBB, Plan.getFalse()}};
+ Defs[EarlyExitingVPBB] = CondToEarlyExit;
----------------
lukel97 wrote:
Done in fbb4b0ec1a0102f7c201821657ea5f1bacc5f329 (apologies for the force push, had to rebase since the precommitted test changed on main)
https://github.com/llvm/llvm-project/pull/201784
More information about the llvm-commits
mailing list