@@ -7543,22 +7543,27 @@ VPRecipeBuilder::tryToWidenMemory(Instruction *I, ArrayRef<VPValue *> Operands,
75437543static VPWidenIntOrFpInductionRecipe *
75447544createWidenInductionRecipes (PHINode *Phi, Instruction *PhiOrTrunc,
75457545 VPValue *Start, const InductionDescriptor &IndDesc,
7546- VPlan &Plan, ScalarEvolution &SE, Loop &OrigLoop) {
7546+ VPlan &Plan, ScalarEvolution &SE, Loop &OrigLoop,
7547+ bool FoldTailByMasking) {
75477548 assert (IndDesc.getStartValue () ==
75487549 Phi->getIncomingValueForBlock (OrigLoop.getLoopPreheader ()));
75497550 assert (SE.isLoopInvariant (IndDesc.getStep (), &OrigLoop) &&
75507551 " step must be loop invariant" );
75517552
7553+ // When folding tail by masking, we may execute more lanes than the original
7554+ // scalar loop, and should hence not set NoWrap flags.
7555+ VPIRFlags Flags =
7556+ vputils::getNoWrapFlagsFromIndDesc (IndDesc, FoldTailByMasking);
75527557 VPValue *Step =
75537558 vputils::getOrCreateVPValueForSCEVExpr (Plan, IndDesc.getStep ());
75547559 if (auto *TruncI = dyn_cast<TruncInst>(PhiOrTrunc)) {
75557560 return new VPWidenIntOrFpInductionRecipe (Phi, Start, Step, &Plan.getVF (),
7556- IndDesc, TruncI,
7561+ IndDesc, TruncI, Flags,
75577562 TruncI->getDebugLoc ());
75587563 }
75597564 assert (isa<PHINode>(PhiOrTrunc) && " must be a phi node here" );
75607565 return new VPWidenIntOrFpInductionRecipe (Phi, Start, Step, &Plan.getVF (),
7561- IndDesc, Phi->getDebugLoc ());
7566+ IndDesc, Flags, Phi->getDebugLoc ());
75627567}
75637568
75647569VPHeaderPHIRecipe *VPRecipeBuilder::tryToOptimizeInductionPHI (
@@ -7568,7 +7573,8 @@ VPHeaderPHIRecipe *VPRecipeBuilder::tryToOptimizeInductionPHI(
75687573 // produces its scalar and vector values.
75697574 if (auto *II = Legal->getIntOrFpInductionDescriptor (Phi))
75707575 return createWidenInductionRecipes (Phi, Phi, Operands[0 ], *II, Plan,
7571- *PSE.getSE (), *OrigLoop);
7576+ *PSE.getSE (), *OrigLoop,
7577+ CM.foldTailByMasking ());
75727578
75737579 // Check if this is pointer induction. If so, build the recipe for it.
75747580 if (auto *II = Legal->getPointerInductionDescriptor (Phi)) {
@@ -7608,7 +7614,7 @@ VPWidenIntOrFpInductionRecipe *VPRecipeBuilder::tryToOptimizeInductionTruncate(
76087614 const InductionDescriptor &II = *Legal->getIntOrFpInductionDescriptor (Phi);
76097615 VPValue *Start = Plan.getOrAddLiveIn (II.getStartValue ());
76107616 return createWidenInductionRecipes (Phi, I, Start, II, Plan, *PSE.getSE (),
7611- *OrigLoop);
7617+ *OrigLoop, CM. foldTailByMasking () );
76127618 }
76137619 return nullptr ;
76147620}
@@ -8499,7 +8505,7 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlan(VFRange &Range) {
84998505 [this ](PHINode *P) {
85008506 return Legal->getIntOrFpInductionDescriptor (P);
85018507 },
8502- *TLI))
8508+ *TLI, CM. foldTailByMasking () ))
85038509 return nullptr ;
85048510
85058511 // Collect mapping of IR header phis to header phi recipes, to be used in
0 commit comments