[llvm] 5f1eb74 - [VPlan] Place VPExpandSCEVRecipe in pre-header.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 10 01:28:23 PDT 2022
Author: Florian Hahn
Date: 2022-04-10T10:26:20+02:00
New Revision: 5f1eb7485077eb295fc17568c0abcf7799b0ade8
URL: https://github.com/llvm/llvm-project/commit/5f1eb7485077eb295fc17568c0abcf7799b0ade8
DIFF: https://github.com/llvm/llvm-project/commit/5f1eb7485077eb295fc17568c0abcf7799b0ade8.diff
LOG: [VPlan] Place VPExpandSCEVRecipe in pre-header.
After D121624 models the pre-header in VPlan, VPExpandSCEVRecipes can be
placed there. This ensures SCEV expansion happens before modifying the
CFG during VPlan execution, when CFG is incomplete.
Depends on D121624.
Reviewed By: Ayal
Differential Revision: https://reviews.llvm.org/D122095
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlan.cpp
llvm/lib/Transforms/Vectorize/VPlan.h
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
llvm/test/Transforms/LoopVectorize/vplan-printing.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index d531c7a6a761b..48877850184c3 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -1474,9 +1474,8 @@ void VPExpandSCEVRecipe::execute(VPTransformState &State) {
const DataLayout &DL = State.CFG.PrevBB->getModule()->getDataLayout();
SCEVExpander Exp(SE, DL, "induction");
- BasicBlock *VectorPH = State.CFG.getPreheaderBBFor(this);
- Value *Res =
- Exp.expandCodeFor(Expr, Expr->getType(), VectorPH->getTerminator());
+ Value *Res = Exp.expandCodeFor(Expr, Expr->getType(),
+ &*State.Builder.GetInsertPoint());
for (unsigned Part = 0, UF = State.UF; Part < UF; ++Part)
State.set(this, Res, Part);
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 683613097ef4f..0430264de54ac 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1805,9 +1805,6 @@ class VPWidenMemoryInstructionRecipe : public VPRecipeBase, public VPValue {
};
/// Recipe to expand a SCEV expression.
-/// TODO: Currently the recipe always expands the expression in the loop
-/// pre-header, but the recipe is currently placed in the header; place it in
-/// the pre-header once the latter is modeled in VPlan as a VPBasicBlock.
class VPExpandSCEVRecipe : public VPRecipeBase, public VPValue {
const SCEV *Expr;
ScalarEvolution &SE;
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index cbef53540bfb2..8f0c7cafc7c21 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -437,12 +437,9 @@ void VPlanTransforms::optimizeInductions(VPlan &Plan, ScalarEvolution &SE) {
IV->getStartValue(), Step, TruncI ? TruncI->getType() : nullptr);
HeaderVPBB->insert(Steps, HeaderVPBB->getFirstNonPhi());
- if (Step->getDef()) {
- // TODO: Place the step in the preheader, once it is explicitly modeled in
- // VPlan.
- HeaderVPBB->insert(cast<VPRecipeBase>(Step->getDef()),
- HeaderVPBB->getFirstNonPhi());
- }
+ if (Step->getDef())
+ Plan.getEntry()->getEntryBasicBlock()->appendRecipe(
+ cast<VPRecipeBase>(Step->getDef()));
// If there are no vector users of IV, simply update all users to use Step
// instead.
diff --git a/llvm/test/Transforms/LoopVectorize/vplan-printing.ll b/llvm/test/Transforms/LoopVectorize/vplan-printing.ll
index ab61a0e4437a8..5ba13c1777ea7 100644
--- a/llvm/test/Transforms/LoopVectorize/vplan-printing.ll
+++ b/llvm/test/Transforms/LoopVectorize/vplan-printing.ll
@@ -418,6 +418,7 @@ define void @print_expand_scev(i64 %y, i8* %ptr) {
; CHECK-NEXT: Live-in vp<%0> = vector-trip-count
; CHECK-EMPTY:
; CHECK-NEXT: vector.ph:
+; CHECK-NEXT: EMIT vp<[[EXP_SCEV:%.+]]> = EXPAND SCEV (1 + (%y /u 492802768830814060))<nuw><nsw>
; CHECK-NEXT: Successor(s): vector loop
; CHECK-EMPTY:
; CHECK-NEXT: <x1> vector loop: {
@@ -426,7 +427,6 @@ define void @print_expand_scev(i64 %y, i8* %ptr) {
; CHECK-NEXT: WIDEN-INDUCTION\l" +
; CHECK-NEXT: " %iv = phi %iv.next, 0\l" +
; CHECK-NEXT: " ir<%v2>
-; CHECK-NEXT: EMIT vp<[[EXP_SCEV:%.+]]> = EXPAND SCEV (1 + (%y /u 492802768830814060))<nuw><nsw>
; CHECK-NEXT: vp<[[STEPS:%.+]]> = SCALAR-STEPS vp<[[CAN_IV]]>, ir<0>, vp<[[EXP_SCEV]]>
; CHECK-NEXT: WIDEN ir<%v3> = add ir<%v2>, ir<1>
; CHECK-NEXT: REPLICATE ir<%gep> = getelementptr ir<%ptr>, vp<[[STEPS]]>
More information about the llvm-commits
mailing list