[llvm] [VPlan] Introduce reduction selects for tail folding in foldTailByMasking. NFCI (PR #192987)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 28 08:46:47 PDT 2026
================
@@ -1165,18 +1165,24 @@ void VPlanTransforms::foldTailByMasking(VPlan &Plan) {
if (match(&R, m_ExtractLastPart(m_VPValue(V))))
NeedsPhi[V].push_back(&R);
- // Insert phis with a poison incoming value for past the end of the tail.
+ // Insert phis for values coming past the end of the tail.
Builder.setInsertPoint(Latch, Latch->begin());
VPTypeAnalysis TypeInfo(Plan);
for (const auto &[V, Users] : NeedsPhi) {
if (isa<VPIRValue>(V))
continue;
- // TODO: For reduction phis, use phi value instead of poison so we can
- // remove the special casing for tail folding in
- // LoopVectorizationPlanner::addReductionResultComputation
- VPValue *Poison =
+ VPValue *Backedge =
Plan.getOrAddLiveIn(PoisonValue::get(TypeInfo.inferScalarType(V)));
- VPInstruction *Phi = Builder.createScalarPhi({V, Poison});
+ VPIRFlags Flags;
+ auto *RedIt = find_if(V->users(), IsaPred<VPReductionPHIRecipe>);
+ auto *RdxPhi =
+ RedIt != V->user_end() ? cast<VPReductionPHIRecipe>(*RedIt) : nullptr;
+ if (RdxPhi && !RdxPhi->isInLoop()) {
----------------
lukel97 wrote:
Asserted in 64d477ebe8d200d22341ecddcb852a1fe9e278ad
https://github.com/llvm/llvm-project/pull/192987
More information about the llvm-commits
mailing list