Skip to content

Commit 7b9f988

Browse files
committed
[VPlan] Limit stride replacement to vector region and middle VPBB (NFC).
At the moment this in NFC, but ensures we only replace uses that are dominated by runtime checks as we model more of the skeleton in VPlan.
1 parent 0558fe3 commit 7b9f988

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9189,6 +9189,14 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
91899189

91909190
// Replace VPValues for known constant strides guaranteed by predicate scalar
91919191
// evolution.
9192+
auto CanUseVersionedStride = [&Plan](VPUser &U, unsigned) {
9193+
auto *R = dyn_cast<VPRecipeBase>(&U);
9194+
if (!R)
9195+
return false;
9196+
return R->getParent()->getParent() ||
9197+
R->getParent() ==
9198+
Plan->getVectorLoopRegion()->getSinglePredecessor();
9199+
};
91929200
for (auto [_, Stride] : Legal->getLAI()->getSymbolicStrides()) {
91939201
auto *StrideV = cast<SCEVUnknown>(Stride)->getValue();
91949202
auto *ScevStride = dyn_cast<SCEVConstant>(PSE.getSCEV(StrideV));
@@ -9199,7 +9207,7 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
91999207
auto *CI = Plan->getOrAddLiveIn(
92009208
ConstantInt::get(Stride->getType(), ScevStride->getAPInt()));
92019209
if (VPValue *StrideVPV = Plan->getLiveIn(StrideV))
9202-
StrideVPV->replaceAllUsesWith(CI);
9210+
StrideVPV->replaceUsesWithIf(CI, CanUseVersionedStride);
92039211

92049212
// The versioned value may not be used in the loop directly but through a
92059213
// sext/zext. Add new live-ins in those cases.
@@ -9213,7 +9221,7 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
92139221
APInt C = isa<SExtInst>(U) ? ScevStride->getAPInt().sext(BW)
92149222
: ScevStride->getAPInt().zext(BW);
92159223
VPValue *CI = Plan->getOrAddLiveIn(ConstantInt::get(U->getType(), C));
9216-
StrideVPV->replaceAllUsesWith(CI);
9224+
StrideVPV->replaceUsesWithIf(CI, CanUseVersionedStride);
92179225
}
92189226
}
92199227

0 commit comments

Comments
 (0)