Skip to content

Commit a55afd4

Browse files
committed
[VPlan Based] Try to remove CM_Strided from uniform analysis
Also cherry-pick the branch Mel-Chen:legalizeAndOptimizeInductions However, still not work well as collectLoopUniforms if the use-chain is too compilicated. :(
1 parent a1b3c74 commit a55afd4

File tree

3 files changed

+62
-76
lines changed

3 files changed

+62
-76
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3412,9 +3412,9 @@ void LoopVectorizationCostModel::collectLoopUniforms(ElementCount VF) {
34123412
if (IsUniformMemOpUse(I))
34133413
return true;
34143414

3415-
return (
3416-
WideningDecision == CM_Widen || WideningDecision == CM_Widen_Reverse ||
3417-
WideningDecision == CM_Strided || WideningDecision == CM_Interleave);
3415+
return (WideningDecision == CM_Widen ||
3416+
WideningDecision == CM_Widen_Reverse ||
3417+
WideningDecision == CM_Interleave);
34183418
};
34193419

34203420
// Returns true if Ptr is the pointer operand of a memory access instruction

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -625,13 +625,14 @@ static SmallVector<VPUser *> collectUsersRecursively(VPValue *V) {
625625
static void legalizeAndOptimizeInductions(VPlan &Plan) {
626626
using namespace llvm::VPlanPatternMatch;
627627
VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
628-
bool HasOnlyVectorVFs = !Plan.hasScalarVFOnly();
629-
VPBuilder Builder(HeaderVPBB, HeaderVPBB->getFirstNonPhi());
630-
for (VPRecipeBase &Phi : HeaderVPBB->phis()) {
631-
auto *PhiR = dyn_cast<VPWidenInductionRecipe>(&Phi);
632-
if (!PhiR)
633-
continue;
628+
SmallVector<VPWidenInductionRecipe *, 4> InductionPhis;
629+
for (VPRecipeBase &R : HeaderVPBB->phis())
630+
if (auto *IV = dyn_cast<VPWidenInductionRecipe>(&R))
631+
InductionPhis.push_back(IV);
634632

633+
bool HasOnlyVectorVFs = !Plan.hasScalarVFOnly();
634+
VPBuilder Builder;
635+
for (VPWidenInductionRecipe *PhiR : reverse(InductionPhis)) {
635636
// Try to narrow wide and replicating recipes to uniform recipes, based on
636637
// VPlan analysis.
637638
// TODO: Apply to all recipes in the future, to replace legacy uniformity
@@ -641,7 +642,8 @@ static void legalizeAndOptimizeInductions(VPlan &Plan) {
641642
auto *Def = dyn_cast<VPSingleDefRecipe>(U);
642643
auto *RepR = dyn_cast<VPReplicateRecipe>(U);
643644
// Skip recipes that shouldn't be narrowed.
644-
if (!Def || !isa<VPReplicateRecipe, VPWidenRecipe>(Def) ||
645+
if (!Def ||
646+
!isa<VPReplicateRecipe, VPWidenRecipe, VPWidenGEPRecipe>(Def) ||
645647
Def->getNumUsers() == 0 || !Def->getUnderlyingValue() ||
646648
(RepR && (RepR->isUniform() || RepR->isPredicated())))
647649
continue;
@@ -655,11 +657,13 @@ static void legalizeAndOptimizeInductions(VPlan &Plan) {
655657
Def->operands(), /*IsUniform*/ true);
656658
Clone->insertAfter(Def);
657659
Def->replaceAllUsesWith(Clone);
660+
Def->eraseFromParent();
658661
}
659662

663+
Builder.setInsertPoint(HeaderVPBB, HeaderVPBB->getFirstNonPhi());
660664
// Replace wide pointer inductions which have only their scalars used by
661665
// PtrAdd(IndStart, ScalarIVSteps (0, Step)).
662-
if (auto *PtrIV = dyn_cast<VPWidenPointerInductionRecipe>(&Phi)) {
666+
if (auto *PtrIV = dyn_cast<VPWidenPointerInductionRecipe>(PhiR)) {
663667
if (!PtrIV->onlyScalarsGenerated(Plan.hasScalableVF()))
664668
continue;
665669

@@ -680,7 +684,7 @@ static void legalizeAndOptimizeInductions(VPlan &Plan) {
680684

681685
// Replace widened induction with scalar steps for users that only use
682686
// scalars.
683-
auto *WideIV = cast<VPWidenIntOrFpInductionRecipe>(&Phi);
687+
auto *WideIV = cast<VPWidenIntOrFpInductionRecipe>(PhiR);
684688
if (HasOnlyVectorVFs && none_of(WideIV->users(), [WideIV](VPUser *U) {
685689
return U->usesScalars(WideIV);
686690
}))

0 commit comments

Comments
 (0)