[PATCH] D122095: [VPlan] Place VPExpandSCEVRecipe in pre-header.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 20 03:16:41 PDT 2022
fhahn created this revision.
fhahn added reviewers: gilr, Ayal, rengolin.
Herald added subscribers: tschuett, psnobl, rogfer01, javed.absar, bollu, hiraditya.
Herald added a project: All.
fhahn requested review of this revision.
Herald added a subscriber: vkmr.
Herald added a project: LLVM.
After D121624 <https://reviews.llvm.org/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 <https://reviews.llvm.org/D121624>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D122095
Files:
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
Index: llvm/test/Transforms/LoopVectorize/vplan-printing.ll
===================================================================
--- llvm/test/Transforms/LoopVectorize/vplan-printing.ll
+++ llvm/test/Transforms/LoopVectorize/vplan-printing.ll
@@ -418,6 +418,7 @@
; 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 @@
; 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]]>
Index: llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -436,12 +436,9 @@
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.
Index: llvm/lib/Transforms/Vectorize/VPlan.h
===================================================================
--- llvm/lib/Transforms/Vectorize/VPlan.h
+++ llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1806,9 +1806,6 @@
};
/// 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;
Index: llvm/lib/Transforms/Vectorize/VPlan.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -1463,7 +1463,7 @@
State.CFG.VectorPreHeader->getModule()->getDataLayout();
SCEVExpander Exp(SE, DL, "induction");
Value *Res = Exp.expandCodeFor(Expr, Expr->getType(),
- State.CFG.VectorPreHeader->getTerminator());
+ &*State.Builder.GetInsertPoint());
for (unsigned Part = 0, UF = State.UF; Part < UF; ++Part)
State.set(this, Res, Part);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122095.416767.patch
Type: text/x-patch
Size: 3125 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220320/10510de0/attachment.bin>
More information about the llvm-commits
mailing list