[llvm] [VPlan] Allow tail folding with uncountable early exits (PR #174974)
Shih-Po Hung via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 10 06:58:04 PST 2026
================
@@ -3952,6 +3946,18 @@ void VPlanTransforms::handleUncountableEarlyExit(VPBasicBlock *EarlyExitingVPBB,
? CondOfEarlyExitingVPBB
: Builder.createNot(CondOfEarlyExitingVPBB);
+ // Create a mask and predicate any "exited" lanes in successor blocks.
+ VPValue *FirstActiveLane =
+ Builder.createNaryOp(VPInstruction::FirstActiveLane, {CondToEarlyExit},
+ DebugLoc::getUnknown(), "first.active.lane");
----------------
arcbbb wrote:
To avoid poison when the trip count isn't a multiple of VF (tail-foled loops), I am thinking about an EarlyExit recipe like this:
```
%EarlyExitMask = EarlyExit %CondToEarlyExit
%FirstActiveLane = first.active.lane %EarlyExitMask
...
%EarlyExit = AnyOf %EarlyExitMask
```
Later, `(EarlyExit %cond)` need to be lowered into:
`(logical-and %cond, (active-lane-mask 0, (extractvalue %ffload, 1)))`
if the user is a masked load/store or branch.
https://github.com/llvm/llvm-project/pull/174974
More information about the llvm-commits
mailing list