@@ -2738,32 +2738,6 @@ static VPRecipeBase *optimizeMaskToEVL(VPValue *HeaderMask,
27382738 return nullptr ;
27392739}
27402740
2741- static void convertToEVLReverse (VPlan &Plan, VPTypeAnalysis &TypeInfo,
2742- VPValue &EVL) {
2743- SmallVector<VPRecipeBase *> ToRemove;
2744-
2745- for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
2746- vp_depth_first_shallow (Plan.getVectorLoopRegion ()->getEntry ()))) {
2747- for (VPRecipeBase &R : make_early_inc_range (reverse (*VPBB))) {
2748- auto *VPI = dyn_cast<VPInstruction>(&R);
2749- if (!VPI || VPI->getOpcode () != VPInstruction::Reverse)
2750- continue ;
2751-
2752- SmallVector<VPValue *> Ops (VPI->operands ());
2753- Ops.append ({Plan.getTrue (), &EVL});
2754- auto *NewReverse = new VPWidenIntrinsicRecipe (
2755- Intrinsic::experimental_vp_reverse, Ops,
2756- TypeInfo.inferScalarType (VPI), {}, {}, VPI->getDebugLoc ());
2757- NewReverse->insertBefore (VPI);
2758- VPI->replaceAllUsesWith (NewReverse);
2759- ToRemove.push_back (VPI);
2760- }
2761- }
2762-
2763- for (VPRecipeBase *R : ToRemove)
2764- R->eraseFromParent ();
2765- }
2766-
27672741// / Replace recipes with their EVL variants.
27682742static void transformRecipestoEVLRecipes (VPlan &Plan, VPValue &EVL) {
27692743 VPTypeAnalysis TypeInfo (Plan);
@@ -2801,6 +2775,7 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
28012775 // contained.
28022776 bool ContainsFORs =
28032777 any_of (Header->phis (), IsaPred<VPFirstOrderRecurrencePHIRecipe>);
2778+ VPValue *PrevEVL = nullptr ;
28042779 if (ContainsFORs) {
28052780 // TODO: Use VPInstruction::ExplicitVectorLength to get maximum EVL.
28062781 VPValue *MaxEVL = &Plan.getVF ();
@@ -2811,28 +2786,42 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
28112786 TypeInfo.inferScalarType (MaxEVL), DebugLoc::getUnknown ());
28122787
28132788 Builder.setInsertPoint (Header, Header->getFirstNonPhi ());
2814- VPValue *PrevEVL = Builder.createScalarPhi (
2815- {MaxEVL, &EVL}, DebugLoc::getUnknown (), " prev.evl" );
2816-
2817- for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
2818- vp_depth_first_deep (Plan.getVectorLoopRegion ()->getEntry ()))) {
2819- for (VPRecipeBase &R : *VPBB) {
2820- VPValue *V1, *V2;
2821- if (!match (&R,
2822- m_VPInstruction<VPInstruction::FirstOrderRecurrenceSplice>(
2823- m_VPValue (V1), m_VPValue (V2))))
2824- continue ;
2789+ PrevEVL = Builder.createScalarPhi ({MaxEVL, &EVL}, DebugLoc::getUnknown (),
2790+ " prev.evl" );
2791+ }
2792+
2793+ // Transform the recipes must be converted to vector predication intrinsics
2794+ // even if they do not use header mask.
2795+ for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
2796+ vp_depth_first_deep (Plan.getVectorLoopRegion ()->getEntry ()))) {
2797+ for (VPRecipeBase &R : *VPBB) {
2798+ VPWidenIntrinsicRecipe *NewRecipe = nullptr ;
2799+ VPValue *V1, *V2;
2800+ if (match (&R, m_VPInstruction<VPInstruction::FirstOrderRecurrenceSplice>(
2801+ m_VPValue (V1), m_VPValue (V2)))) {
28252802 VPValue *Imm = Plan.getOrAddLiveIn (
28262803 ConstantInt::getSigned (Type::getInt32Ty (Plan.getContext ()), -1 ));
2827- VPWidenIntrinsicRecipe *VPSplice = new VPWidenIntrinsicRecipe (
2804+ NewRecipe = new VPWidenIntrinsicRecipe (
28282805 Intrinsic::experimental_vp_splice,
28292806 {V1, V2, Imm, Plan.getTrue (), PrevEVL, &EVL},
28302807 TypeInfo.inferScalarType (R.getVPSingleValue ()), {}, {},
28312808 R.getDebugLoc ());
2832- VPSplice->insertBefore (&R);
2833- R.getVPSingleValue ()->replaceAllUsesWith (VPSplice);
2834- ToErase.push_back (&R);
28352809 }
2810+
2811+ // TODO: Only convert reverse to vp.reverse if it uses the result of
2812+ // vp.load, or defines the stored value of vp.store.
2813+ if (match (&R, m_VPInstruction<VPInstruction::Reverse>(m_VPValue (V1)))) {
2814+ NewRecipe = new VPWidenIntrinsicRecipe (
2815+ Intrinsic::experimental_vp_reverse, {V1, Plan.getTrue (), &EVL},
2816+ TypeInfo.inferScalarType (R.getVPSingleValue ()), {}, {},
2817+ R.getDebugLoc ());
2818+ }
2819+
2820+ if (!NewRecipe)
2821+ continue ;
2822+ NewRecipe->insertBefore (&R);
2823+ R.getVPSingleValue ()->replaceAllUsesWith (NewRecipe);
2824+ ToErase.push_back (&R);
28362825 }
28372826 }
28382827
@@ -2879,7 +2868,6 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
28792868 }
28802869 ToErase.push_back (CurRecipe);
28812870 }
2882- convertToEVLReverse (Plan, TypeInfo, EVL);
28832871 // Remove dead EVL mask.
28842872 if (EVLMask->getNumUsers () == 0 )
28852873 ToErase.push_back (EVLMask->getDefiningRecipe ());
0 commit comments