[llvm] [VPlan] Preserve SSA in early exits (PR #201784)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 14 07:04:00 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;
----------------
david-arm wrote:
Alternatively you could just save the lookup and make it clearer by doing:
```
if (HeaderVPBB != EarlyExitingVPBB)
Defs[EarlyExitingVPBB] = CondToEarlyExit;
```
https://github.com/llvm/llvm-project/pull/201784
More information about the llvm-commits
mailing list