Skip to content

Commit e07dc01

Browse files
committed
Reuse traversal loop
1 parent ebef594 commit e07dc01

File tree

1 file changed

+30
-42
lines changed

1 file changed

+30
-42
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2910,32 +2910,6 @@ static VPRecipeBase *optimizeMaskToEVL(VPValue *HeaderMask,
29102910
return nullptr;
29112911
}
29122912

2913-
static void convertToEVLReverse(VPlan &Plan, VPTypeAnalysis &TypeInfo,
2914-
VPValue &EVL) {
2915-
SmallVector<VPRecipeBase *> ToRemove;
2916-
2917-
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
2918-
vp_depth_first_shallow(Plan.getVectorLoopRegion()->getEntry()))) {
2919-
for (VPRecipeBase &R : make_early_inc_range(reverse(*VPBB))) {
2920-
auto *VPI = dyn_cast<VPInstruction>(&R);
2921-
if (!VPI || VPI->getOpcode() != VPInstruction::Reverse)
2922-
continue;
2923-
2924-
SmallVector<VPValue *> Ops(VPI->operands());
2925-
Ops.append({Plan.getTrue(), &EVL});
2926-
auto *NewReverse = new VPWidenIntrinsicRecipe(
2927-
Intrinsic::experimental_vp_reverse, Ops,
2928-
TypeInfo.inferScalarType(VPI), {}, {}, VPI->getDebugLoc());
2929-
NewReverse->insertBefore(VPI);
2930-
VPI->replaceAllUsesWith(NewReverse);
2931-
ToRemove.push_back(VPI);
2932-
}
2933-
}
2934-
2935-
for (VPRecipeBase *R : ToRemove)
2936-
R->eraseFromParent();
2937-
}
2938-
29392913
/// Replace recipes with their EVL variants.
29402914
static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
29412915
VPTypeAnalysis TypeInfo(Plan);
@@ -2973,6 +2947,7 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
29732947
// contained.
29742948
bool ContainsFORs =
29752949
any_of(Header->phis(), IsaPred<VPFirstOrderRecurrencePHIRecipe>);
2950+
VPValue *PrevEVL = nullptr;
29762951
if (ContainsFORs) {
29772952
// TODO: Use VPInstruction::ExplicitVectorLength to get maximum EVL.
29782953
VPValue *MaxEVL = &Plan.getVF();
@@ -2983,28 +2958,42 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
29832958
TypeInfo.inferScalarType(MaxEVL), DebugLoc::getUnknown());
29842959

29852960
Builder.setInsertPoint(Header, Header->getFirstNonPhi());
2986-
VPValue *PrevEVL = Builder.createScalarPhi(
2987-
{MaxEVL, &EVL}, DebugLoc::getUnknown(), "prev.evl");
2988-
2989-
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
2990-
vp_depth_first_deep(Plan.getVectorLoopRegion()->getEntry()))) {
2991-
for (VPRecipeBase &R : *VPBB) {
2992-
VPValue *V1, *V2;
2993-
if (!match(&R,
2994-
m_VPInstruction<VPInstruction::FirstOrderRecurrenceSplice>(
2995-
m_VPValue(V1), m_VPValue(V2))))
2996-
continue;
2961+
PrevEVL = Builder.createScalarPhi({MaxEVL, &EVL}, DebugLoc::getUnknown(),
2962+
"prev.evl");
2963+
}
2964+
2965+
// Transform the recipes must be converted to vector predication intrinsics
2966+
// even if they do not use header mask.
2967+
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
2968+
vp_depth_first_deep(Plan.getVectorLoopRegion()->getEntry()))) {
2969+
for (VPRecipeBase &R : *VPBB) {
2970+
VPWidenIntrinsicRecipe *NewRecipe = nullptr;
2971+
VPValue *V1, *V2;
2972+
if (match(&R, m_VPInstruction<VPInstruction::FirstOrderRecurrenceSplice>(
2973+
m_VPValue(V1), m_VPValue(V2)))) {
29972974
VPValue *Imm = Plan.getOrAddLiveIn(
29982975
ConstantInt::getSigned(Type::getInt32Ty(Plan.getContext()), -1));
2999-
VPWidenIntrinsicRecipe *VPSplice = new VPWidenIntrinsicRecipe(
2976+
NewRecipe = new VPWidenIntrinsicRecipe(
30002977
Intrinsic::experimental_vp_splice,
30012978
{V1, V2, Imm, Plan.getTrue(), PrevEVL, &EVL},
30022979
TypeInfo.inferScalarType(R.getVPSingleValue()), {}, {},
30032980
R.getDebugLoc());
3004-
VPSplice->insertBefore(&R);
3005-
R.getVPSingleValue()->replaceAllUsesWith(VPSplice);
3006-
ToErase.push_back(&R);
30072981
}
2982+
2983+
// TODO: Only convert reverse to vp.reverse if it uses the result of
2984+
// vp.load, or defines the stored value of vp.store.
2985+
if (match(&R, m_VPInstruction<VPInstruction::Reverse>(m_VPValue(V1)))) {
2986+
NewRecipe = new VPWidenIntrinsicRecipe(
2987+
Intrinsic::experimental_vp_reverse, {V1, Plan.getTrue(), &EVL},
2988+
TypeInfo.inferScalarType(R.getVPSingleValue()), {}, {},
2989+
R.getDebugLoc());
2990+
}
2991+
2992+
if (!NewRecipe)
2993+
continue;
2994+
NewRecipe->insertBefore(&R);
2995+
R.getVPSingleValue()->replaceAllUsesWith(NewRecipe);
2996+
ToErase.push_back(&R);
30082997
}
30092998
}
30102999

@@ -3051,7 +3040,6 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
30513040
}
30523041
ToErase.push_back(CurRecipe);
30533042
}
3054-
convertToEVLReverse(Plan, TypeInfo, EVL);
30553043
// Remove dead EVL mask.
30563044
if (EVLMask->getNumUsers() == 0)
30573045
ToErase.push_back(EVLMask->getDefiningRecipe());

0 commit comments

Comments
 (0)