@@ -7540,22 +7540,27 @@ VPRecipeBuilder::tryToWidenMemory(Instruction *I, ArrayRef<VPValue *> Operands,
75407540static VPWidenIntOrFpInductionRecipe *
75417541createWidenInductionRecipes (PHINode *Phi, Instruction *PhiOrTrunc,
75427542 VPValue *Start, const InductionDescriptor &IndDesc,
7543- VPlan &Plan, ScalarEvolution &SE, Loop &OrigLoop) {
7543+ VPlan &Plan, ScalarEvolution &SE, Loop &OrigLoop,
7544+ bool FoldTailByMasking) {
75447545 assert (IndDesc.getStartValue () ==
75457546 Phi->getIncomingValueForBlock (OrigLoop.getLoopPreheader ()));
75467547 assert (SE.isLoopInvariant (IndDesc.getStep (), &OrigLoop) &&
75477548 " step must be loop invariant" );
75487549
7550+ // When folding tail by masking, we may execute more lanes than the original
7551+ // scalar loop, and should hence not set NoWrap flags.
7552+ VPIRFlags Flags =
7553+ vputils::getNoWrapFlagsFromIndDesc (IndDesc, FoldTailByMasking);
75497554 VPValue *Step =
75507555 vputils::getOrCreateVPValueForSCEVExpr (Plan, IndDesc.getStep ());
75517556 if (auto *TruncI = dyn_cast<TruncInst>(PhiOrTrunc)) {
75527557 return new VPWidenIntOrFpInductionRecipe (Phi, Start, Step, &Plan.getVF (),
7553- IndDesc, TruncI,
7558+ IndDesc, TruncI, Flags,
75547559 TruncI->getDebugLoc ());
75557560 }
75567561 assert (isa<PHINode>(PhiOrTrunc) && " must be a phi node here" );
75577562 return new VPWidenIntOrFpInductionRecipe (Phi, Start, Step, &Plan.getVF (),
7558- IndDesc, Phi->getDebugLoc ());
7563+ IndDesc, Flags, Phi->getDebugLoc ());
75597564}
75607565
75617566VPHeaderPHIRecipe *VPRecipeBuilder::tryToOptimizeInductionPHI (
@@ -7565,7 +7570,8 @@ VPHeaderPHIRecipe *VPRecipeBuilder::tryToOptimizeInductionPHI(
75657570 // produces its scalar and vector values.
75667571 if (auto *II = Legal->getIntOrFpInductionDescriptor (Phi))
75677572 return createWidenInductionRecipes (Phi, Phi, Operands[0 ], *II, Plan,
7568- *PSE.getSE (), *OrigLoop);
7573+ *PSE.getSE (), *OrigLoop,
7574+ CM.foldTailByMasking ());
75697575
75707576 // Check if this is pointer induction. If so, build the recipe for it.
75717577 if (auto *II = Legal->getPointerInductionDescriptor (Phi)) {
@@ -7605,7 +7611,7 @@ VPWidenIntOrFpInductionRecipe *VPRecipeBuilder::tryToOptimizeInductionTruncate(
76057611 const InductionDescriptor &II = *Legal->getIntOrFpInductionDescriptor (Phi);
76067612 VPValue *Start = Plan.getOrAddLiveIn (II.getStartValue ());
76077613 return createWidenInductionRecipes (Phi, I, Start, II, Plan, *PSE.getSE (),
7608- *OrigLoop);
7614+ *OrigLoop, CM. foldTailByMasking () );
76097615 }
76107616 return nullptr ;
76117617}
@@ -8500,7 +8506,7 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlan(VFRange &Range) {
85008506 [this ](PHINode *P) {
85018507 return Legal->getIntOrFpInductionDescriptor (P);
85028508 },
8503- *TLI))
8509+ *TLI, CM. foldTailByMasking () ))
85048510 return nullptr ;
85058511
85068512 // Collect mapping of IR header phis to header phi recipes, to be used in
0 commit comments