@@ -2849,32 +2849,6 @@ static VPRecipeBase *optimizeMaskToEVL(VPValue *HeaderMask,
28492849 return nullptr ;
28502850}
28512851
2852- static void convertToEVLReverse (VPlan &Plan, VPTypeAnalysis &TypeInfo,
2853- VPValue &EVL) {
2854- SmallVector<VPRecipeBase *> ToRemove;
2855-
2856- for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
2857- vp_depth_first_shallow (Plan.getVectorLoopRegion ()->getEntry ()))) {
2858- for (VPRecipeBase &R : make_early_inc_range (reverse (*VPBB))) {
2859- auto *VPI = dyn_cast<VPInstruction>(&R);
2860- if (!VPI || VPI->getOpcode () != VPInstruction::Reverse)
2861- continue ;
2862-
2863- SmallVector<VPValue *> Ops (VPI->operands ());
2864- Ops.append ({Plan.getTrue (), &EVL});
2865- auto *NewReverse = new VPWidenIntrinsicRecipe (
2866- Intrinsic::experimental_vp_reverse, Ops,
2867- TypeInfo.inferScalarType (VPI), {}, {}, VPI->getDebugLoc ());
2868- NewReverse->insertBefore (VPI);
2869- VPI->replaceAllUsesWith (NewReverse);
2870- ToRemove.push_back (VPI);
2871- }
2872- }
2873-
2874- for (VPRecipeBase *R : ToRemove)
2875- R->eraseFromParent ();
2876- }
2877-
28782852// / Replace recipes with their EVL variants.
28792853static void transformRecipestoEVLRecipes (VPlan &Plan, VPValue &EVL) {
28802854 VPTypeAnalysis TypeInfo (Plan);
@@ -2912,6 +2886,7 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
29122886 // contained.
29132887 bool ContainsFORs =
29142888 any_of (Header->phis (), IsaPred<VPFirstOrderRecurrencePHIRecipe>);
2889+ VPValue *PrevEVL = nullptr ;
29152890 if (ContainsFORs) {
29162891 // TODO: Use VPInstruction::ExplicitVectorLength to get maximum EVL.
29172892 VPValue *MaxEVL = &Plan.getVF ();
@@ -2922,28 +2897,42 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
29222897 TypeInfo.inferScalarType (MaxEVL), DebugLoc::getUnknown ());
29232898
29242899 Builder.setInsertPoint (Header, Header->getFirstNonPhi ());
2925- VPValue *PrevEVL = Builder.createScalarPhi (
2926- {MaxEVL, &EVL}, DebugLoc::getUnknown (), " prev.evl" );
2927-
2928- for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
2929- vp_depth_first_deep (Plan.getVectorLoopRegion ()->getEntry ()))) {
2930- for (VPRecipeBase &R : *VPBB) {
2931- VPValue *V1, *V2;
2932- if (!match (&R,
2933- m_VPInstruction<VPInstruction::FirstOrderRecurrenceSplice>(
2934- m_VPValue (V1), m_VPValue (V2))))
2935- continue ;
2900+ PrevEVL = Builder.createScalarPhi ({MaxEVL, &EVL}, DebugLoc::getUnknown (),
2901+ " prev.evl" );
2902+ }
2903+
2904+ // Transform the recipes must be converted to vector predication intrinsics
2905+ // even if they do not use header mask.
2906+ for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
2907+ vp_depth_first_deep (Plan.getVectorLoopRegion ()->getEntry ()))) {
2908+ for (VPRecipeBase &R : *VPBB) {
2909+ VPWidenIntrinsicRecipe *NewRecipe = nullptr ;
2910+ VPValue *V1, *V2;
2911+ if (match (&R, m_VPInstruction<VPInstruction::FirstOrderRecurrenceSplice>(
2912+ m_VPValue (V1), m_VPValue (V2)))) {
29362913 VPValue *Imm = Plan.getOrAddLiveIn (
29372914 ConstantInt::getSigned (Type::getInt32Ty (Plan.getContext ()), -1 ));
2938- VPWidenIntrinsicRecipe *VPSplice = new VPWidenIntrinsicRecipe (
2915+ NewRecipe = new VPWidenIntrinsicRecipe (
29392916 Intrinsic::experimental_vp_splice,
29402917 {V1, V2, Imm, Plan.getTrue (), PrevEVL, &EVL},
29412918 TypeInfo.inferScalarType (R.getVPSingleValue ()), {}, {},
29422919 R.getDebugLoc ());
2943- VPSplice->insertBefore (&R);
2944- R.getVPSingleValue ()->replaceAllUsesWith (VPSplice);
2945- ToErase.push_back (&R);
29462920 }
2921+
2922+ // TODO: Only convert reverse to vp.reverse if it uses the result of
2923+ // vp.load, or defines the stored value of vp.store.
2924+ if (match (&R, m_VPInstruction<VPInstruction::Reverse>(m_VPValue (V1)))) {
2925+ NewRecipe = new VPWidenIntrinsicRecipe (
2926+ Intrinsic::experimental_vp_reverse, {V1, Plan.getTrue (), &EVL},
2927+ TypeInfo.inferScalarType (R.getVPSingleValue ()), {}, {},
2928+ R.getDebugLoc ());
2929+ }
2930+
2931+ if (!NewRecipe)
2932+ continue ;
2933+ NewRecipe->insertBefore (&R);
2934+ R.getVPSingleValue ()->replaceAllUsesWith (NewRecipe);
2935+ ToErase.push_back (&R);
29472936 }
29482937 }
29492938
@@ -2990,7 +2979,6 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
29902979 }
29912980 ToErase.push_back (CurRecipe);
29922981 }
2993- convertToEVLReverse (Plan, TypeInfo, EVL);
29942982 // Remove dead EVL mask.
29952983 if (EVLMask->getNumUsers () == 0 )
29962984 ToErase.push_back (EVLMask->getDefiningRecipe ());
0 commit comments