Skip to content

Commit de3a9dc

Browse files
committed
Reuse traversal loop
1 parent aeb4e7d commit de3a9dc

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
@@ -2819,32 +2819,6 @@ static VPRecipeBase *optimizeMaskToEVL(VPValue *HeaderMask,
28192819
return nullptr;
28202820
}
28212821

2822-
static void convertToEVLReverse(VPlan &Plan, VPTypeAnalysis &TypeInfo,
2823-
VPValue &EVL) {
2824-
SmallVector<VPRecipeBase *> ToRemove;
2825-
2826-
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
2827-
vp_depth_first_shallow(Plan.getVectorLoopRegion()->getEntry()))) {
2828-
for (VPRecipeBase &R : make_early_inc_range(reverse(*VPBB))) {
2829-
auto *VPI = dyn_cast<VPInstruction>(&R);
2830-
if (!VPI || VPI->getOpcode() != VPInstruction::Reverse)
2831-
continue;
2832-
2833-
SmallVector<VPValue *> Ops(VPI->operands());
2834-
Ops.append({Plan.getTrue(), &EVL});
2835-
auto *NewReverse = new VPWidenIntrinsicRecipe(
2836-
Intrinsic::experimental_vp_reverse, Ops,
2837-
TypeInfo.inferScalarType(VPI), {}, {}, VPI->getDebugLoc());
2838-
NewReverse->insertBefore(VPI);
2839-
VPI->replaceAllUsesWith(NewReverse);
2840-
ToRemove.push_back(VPI);
2841-
}
2842-
}
2843-
2844-
for (VPRecipeBase *R : ToRemove)
2845-
R->eraseFromParent();
2846-
}
2847-
28482822
/// Replace recipes with their EVL variants.
28492823
static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
28502824
VPTypeAnalysis TypeInfo(Plan);
@@ -2882,6 +2856,7 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
28822856
// contained.
28832857
bool ContainsFORs =
28842858
any_of(Header->phis(), IsaPred<VPFirstOrderRecurrencePHIRecipe>);
2859+
VPValue *PrevEVL = nullptr;
28852860
if (ContainsFORs) {
28862861
// TODO: Use VPInstruction::ExplicitVectorLength to get maximum EVL.
28872862
VPValue *MaxEVL = &Plan.getVF();
@@ -2892,28 +2867,42 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
28922867
TypeInfo.inferScalarType(MaxEVL), DebugLoc::getUnknown());
28932868

28942869
Builder.setInsertPoint(Header, Header->getFirstNonPhi());
2895-
VPValue *PrevEVL = Builder.createScalarPhi(
2896-
{MaxEVL, &EVL}, DebugLoc::getUnknown(), "prev.evl");
2897-
2898-
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
2899-
vp_depth_first_deep(Plan.getVectorLoopRegion()->getEntry()))) {
2900-
for (VPRecipeBase &R : *VPBB) {
2901-
VPValue *V1, *V2;
2902-
if (!match(&R,
2903-
m_VPInstruction<VPInstruction::FirstOrderRecurrenceSplice>(
2904-
m_VPValue(V1), m_VPValue(V2))))
2905-
continue;
2870+
PrevEVL = Builder.createScalarPhi({MaxEVL, &EVL}, DebugLoc::getUnknown(),
2871+
"prev.evl");
2872+
}
2873+
2874+
// Transform the recipes must be converted to vector predication intrinsics
2875+
// even if they do not use header mask.
2876+
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
2877+
vp_depth_first_deep(Plan.getVectorLoopRegion()->getEntry()))) {
2878+
for (VPRecipeBase &R : *VPBB) {
2879+
VPWidenIntrinsicRecipe *NewRecipe = nullptr;
2880+
VPValue *V1, *V2;
2881+
if (match(&R, m_VPInstruction<VPInstruction::FirstOrderRecurrenceSplice>(
2882+
m_VPValue(V1), m_VPValue(V2)))) {
29062883
VPValue *Imm = Plan.getOrAddLiveIn(
29072884
ConstantInt::getSigned(Type::getInt32Ty(Plan.getContext()), -1));
2908-
VPWidenIntrinsicRecipe *VPSplice = new VPWidenIntrinsicRecipe(
2885+
NewRecipe = new VPWidenIntrinsicRecipe(
29092886
Intrinsic::experimental_vp_splice,
29102887
{V1, V2, Imm, Plan.getTrue(), PrevEVL, &EVL},
29112888
TypeInfo.inferScalarType(R.getVPSingleValue()), {}, {},
29122889
R.getDebugLoc());
2913-
VPSplice->insertBefore(&R);
2914-
R.getVPSingleValue()->replaceAllUsesWith(VPSplice);
2915-
ToErase.push_back(&R);
29162890
}
2891+
2892+
// TODO: Only convert reverse to vp.reverse if it uses the result of
2893+
// vp.load, or defines the stored value of vp.store.
2894+
if (match(&R, m_VPInstruction<VPInstruction::Reverse>(m_VPValue(V1)))) {
2895+
NewRecipe = new VPWidenIntrinsicRecipe(
2896+
Intrinsic::experimental_vp_reverse, {V1, Plan.getTrue(), &EVL},
2897+
TypeInfo.inferScalarType(R.getVPSingleValue()), {}, {},
2898+
R.getDebugLoc());
2899+
}
2900+
2901+
if (!NewRecipe)
2902+
continue;
2903+
NewRecipe->insertBefore(&R);
2904+
R.getVPSingleValue()->replaceAllUsesWith(NewRecipe);
2905+
ToErase.push_back(&R);
29172906
}
29182907
}
29192908

@@ -2960,7 +2949,6 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
29602949
}
29612950
ToErase.push_back(CurRecipe);
29622951
}
2963-
convertToEVLReverse(Plan, TypeInfo, EVL);
29642952
// Remove dead EVL mask.
29652953
if (EVLMask->getNumUsers() == 0)
29662954
ToErase.push_back(EVLMask->getDefiningRecipe());

0 commit comments

Comments
 (0)