@@ -9189,6 +9189,14 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
9189
9189
9190
9190
// Replace VPValues for known constant strides guaranteed by predicate scalar
9191
9191
// 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
+ };
9192
9200
for (auto [_, Stride] : Legal->getLAI ()->getSymbolicStrides ()) {
9193
9201
auto *StrideV = cast<SCEVUnknown>(Stride)->getValue ();
9194
9202
auto *ScevStride = dyn_cast<SCEVConstant>(PSE.getSCEV (StrideV));
@@ -9199,7 +9207,7 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
9199
9207
auto *CI = Plan->getOrAddLiveIn (
9200
9208
ConstantInt::get (Stride->getType (), ScevStride->getAPInt ()));
9201
9209
if (VPValue *StrideVPV = Plan->getLiveIn (StrideV))
9202
- StrideVPV->replaceAllUsesWith (CI);
9210
+ StrideVPV->replaceUsesWithIf (CI, CanUseVersionedStride );
9203
9211
9204
9212
// The versioned value may not be used in the loop directly but through a
9205
9213
// sext/zext. Add new live-ins in those cases.
@@ -9213,7 +9221,7 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
9213
9221
APInt C = isa<SExtInst>(U) ? ScevStride->getAPInt ().sext (BW)
9214
9222
: ScevStride->getAPInt ().zext (BW);
9215
9223
VPValue *CI = Plan->getOrAddLiveIn (ConstantInt::get (U->getType (), C));
9216
- StrideVPV->replaceAllUsesWith (CI);
9224
+ StrideVPV->replaceUsesWithIf (CI, CanUseVersionedStride );
9217
9225
}
9218
9226
}
9219
9227
0 commit comments