[llvm] [LAA][LV]Allow recognition of strided pointers with constant stride (PR #171151)

Nashe Mncube via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 23 06:30:12 PST 2026


https://github.com/nasherm updated https://github.com/llvm/llvm-project/pull/171151

>From c4cb0dffe28d3e10c9983a5e82ab5daf1c11792e Mon Sep 17 00:00:00 2001
From: nasmnc01 <nashe.mncube at arm.com>
Date: Fri, 5 Dec 2025 13:51:10 +0000
Subject: [PATCH 1/7] [IndVarSimplify] Add rewriting ptr-add phis with offset
 addressing

This patch adds support to IndVarSimplify to rewrite IVs used in loops for
strided loads or stores. These IVs are rewritten to make use of offset
addressing thereby elimnating PHI nodes and simplifying the IR.
The motivation for this is that with these PHI nodes eliminated vectorization
becomes more feasible.

Change-Id: Ib3385ee5de03c46b4de035b550fbf56403e9e376
---
 llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | 111 ++++++++++++++++++
 .../rewrite-ptr-addr-with-offset-addr.ll      |  64 ++++++++++
 2 files changed, 175 insertions(+)
 create mode 100644 llvm/test/Transforms/IndVarSimplify/rewrite-ptr-addr-with-offset-addr.ll

diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
index f377c192371ea..435931ce5ea26 100644
--- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -164,6 +164,9 @@ class IndVarSimplify {
 
   bool sinkUnusedInvariants(Loop *L);
 
+  bool rewritePtrIncrementWithOffsettAddressing(
+      Loop *L, SmallVectorImpl<WeakTrackingVH> &DeadInsts);
+
 public:
   IndVarSimplify(LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT,
                  const DataLayout &DL, TargetLibraryInfo *TLI,
@@ -2039,6 +2042,111 @@ bool IndVarSimplify::predicateLoopExits(Loop *L, SCEVExpander &Rewriter) {
   return Changed;
 }
 
+bool IndVarSimplify::rewritePtrIncrementWithOffsettAddressing(
+    Loop *L, SmallVectorImpl<WeakTrackingVH> &DeadInsts) {
+  SmallVector<PHINode *, 8> LoopPhis(
+      llvm::make_pointer_range(L->getHeader()->phis()));
+  bool Changed = false;
+
+  auto IsPtrToOffsetAddressingCandidate = [&](PHINode *PHI) -> bool {
+    if (PHI->user_empty())
+      return false;
+
+    if (PHI->hasConstantValue())
+      return false;
+
+    // TODO: is this necessary.
+    if (L->getCanonicalInductionVariable() == PHI)
+      return false;
+
+    // We are only concerned with simple PHI nodes
+    // with two incoming values.
+    if (PHI->getNumIncomingValues() != 2)
+      return false;
+
+    return true;
+  };
+
+  auto NonInvariantPHIOp = [&](Value *Op0, Value *Op1) -> Value * {
+    // One of the two incoming values must be loop invariant
+    // but not both
+    if (!(L->isLoopInvariant(Op0) != L->isLoopInvariant(Op1)))
+      return nullptr;
+
+    return (L->isLoopInvariant(Op0)) ? Op1 : Op0;
+  };
+
+  auto IsConstantIncrement = [&](GetElementPtrInst *GEP) -> bool {
+    if (GEP->getNumIndices() != 1)
+      return false;
+
+    if (GEP->hasAllConstantIndices())
+      return true;
+
+    for (Value *V : GEP->indices())
+      if (!L->isLoopInvariant(V))
+        return false;
+
+    return true;
+  };
+
+  auto AdjustWidth = [&](Value *V, IRBuilder<> &IR,
+                         unsigned TargetWidth, bool IsSigned) -> Value * {
+    if (V->getType()->getIntegerBitWidth() == TargetWidth)
+      return V;
+    if (IsSigned)
+      return IR.CreateSExt(V, IntegerType::get(V->getContext(), TargetWidth));
+    return IR.CreateZExt(V, IntegerType::get(V->getContext(), TargetWidth));
+  };
+
+  IRBuilder<> Builder(L->getHeader()->getFirstNonPHI());
+  for (auto *PHI : LoopPhis) {
+    if (!IsPtrToOffsetAddressingCandidate(PHI))
+      continue;
+
+    Value *CanonicalIV = L->getCanonicalInductionVariable();
+    if (!CanonicalIV)
+      continue;
+    if (!L->getLatchCmpInst())
+      return false;
+
+    Value *Op0 = PHI->getIncomingValue(0);
+    Value *Op1 = PHI->getIncomingValue(1);
+    Value *LoopDependentIncomingVal = NonInvariantPHIOp(Op0, Op1);
+    if (!LoopDependentIncomingVal)
+      continue;
+
+    if (auto *LoopStrideGEPInst =
+            dyn_cast<GetElementPtrInst>(LoopDependentIncomingVal)) {
+      Value *InvariantIncomingVal =
+          (Op0 == LoopDependentIncomingVal) ? Op1 : Op0;
+      if (!dyn_cast<GetElementPtrInst>(InvariantIncomingVal))
+        continue;
+
+      if (!IsConstantIncrement(LoopStrideGEPInst))
+        continue;
+
+      // Replace PHI with offset addressing GEP
+      Value *Stride = LoopStrideGEPInst->getOperand(1);
+      bool IsSigned = L->getLatchCmpInst()->isSigned();
+      unsigned MaxWidth = std::max(CanonicalIV->getType()->getIntegerBitWidth(),
+                                   Stride->getType()->getIntegerBitWidth());
+
+      CanonicalIV = AdjustWidth(CanonicalIV, Builder, MaxWidth, IsSigned);
+      Stride = AdjustWidth(Stride, Builder, MaxWidth, IsSigned);
+
+      Value *Mul = Builder.CreateMul(CanonicalIV, Stride);
+      Value *NewGEP =
+          Builder.CreateInBoundsGEP(LoopStrideGEPInst->getResultElementType(),
+                                    InvariantIncomingVal, ArrayRef(Mul));
+      PHI->replaceAllUsesWith(NewGEP);
+      DeadInsts.emplace_back(PHI);
+      Changed |= true;
+    }
+  }
+  return Changed;
+}
+
 //===----------------------------------------------------------------------===//
 //  IndVarSimplify driver. Manage several subpasses of IV simplification.
 //===----------------------------------------------------------------------===//
@@ -2116,6 +2224,9 @@ bool IndVarSimplify::run(Loop *L) {
     SE->forgetLoop(L);
   }
 
+  // Try to rewrite ptr increments with ptr offset addressing
+  Changed |= rewritePtrIncrementWithOffsettAddressing(L, DeadInsts);
+
   // If we have a trip count expression, rewrite the loop's exit condition
   // using it.
   if (!DisableLFTR) {
diff --git a/llvm/test/Transforms/IndVarSimplify/rewrite-ptr-addr-with-offset-addr.ll b/llvm/test/Transforms/IndVarSimplify/rewrite-ptr-addr-with-offset-addr.ll
new file mode 100644
index 0000000000000..c08696f51b076
--- /dev/null
+++ b/llvm/test/Transforms/IndVarSimplify/rewrite-ptr-addr-with-offset-addr.ll
@@ -0,0 +1,64 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt < %s -passes=indvars -S -o - | FileCheck %s
+
+
+define void @mat_transpose(float* %pIn, float* %pOut, i32 %nRows, i32 %nCols) {
+; CHECK-LABEL: define void @mat_transpose(
+; CHECK-SAME: ptr [[PIN:%.*]], ptr [[POUT:%.*]], i32 [[NROWS:%.*]], i32 [[NCOLS:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*]]:
+; CHECK-NEXT:    br label %[[LOOP_ROW:.*]]
+; CHECK:       [[LOOP_ROW]]:
+; CHECK-NEXT:    [[ROW_IV:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[ROW_INC:%.*]], %[[LOOP_ROW_END:.*]] ]
+; CHECK-NEXT:    [[CMP_ROW:%.*]] = icmp ult i32 [[ROW_IV]], [[NROWS]]
+; CHECK-NEXT:    br i1 [[CMP_ROW]], label %[[LOOP_COL_PRE:.*]], label %[[EXIT:.*]]
+; CHECK:       [[LOOP_COL_PRE]]:
+; CHECK-NEXT:    [[PX_BASE:%.*]] = getelementptr inbounds float, ptr [[POUT]], i32 [[ROW_IV]]
+; CHECK-NEXT:    br label %[[LOOP_COL:.*]]
+; CHECK:       [[LOOP_COL]]:
+; CHECK-NEXT:    [[COL_IV:%.*]] = phi i32 [ 0, %[[LOOP_COL_PRE]] ], [ [[COL_INC:%.*]], %[[LOOP_COL]] ]
+; CHECK-NEXT:    [[PIN_PTR:%.*]] = phi ptr [ [[PIN]], %[[LOOP_COL_PRE]] ], [ [[PIN_NEXT:%.*]], %[[LOOP_COL]] ]
+; CHECK-NEXT:    [[TMP0:%.*]] = mul i32 [[COL_IV]], [[NROWS]]
+; CHECK-NEXT:    [[PX_PTR:%.*]] = getelementptr inbounds float, ptr [[PX_BASE]], i32 [[TMP0]]
+; CHECK-NEXT:    [[PIN_LOAD:%.*]] = load float, ptr [[PIN_PTR]], align 4
+; CHECK-NEXT:    [[PIN_NEXT]] = getelementptr float, ptr [[PIN_PTR]], i32 1
+; CHECK-NEXT:    store float [[PIN_LOAD]], ptr [[PX_PTR]], align 4
+; CHECK-NEXT:    [[COL_INC]] = add nuw i32 [[COL_IV]], 1
+; CHECK-NEXT:    [[CMP_COL:%.*]] = icmp ult i32 [[COL_INC]], [[NCOLS]]
+; CHECK-NEXT:    br i1 [[CMP_COL]], label %[[LOOP_COL]], label %[[LOOP_ROW_END]]
+; CHECK:       [[LOOP_ROW_END]]:
+; CHECK-NEXT:    [[ROW_INC]] = add nuw i32 [[ROW_IV]], 1
+; CHECK-NEXT:    br label %[[LOOP_ROW]]
+; CHECK:       [[EXIT]]:
+; CHECK-NEXT:    ret void
+;
+entry:
+  br label %loop_row
+
+loop_row:
+  %row.iv = phi i32 [ 0, %entry ], [ %row.inc, %loop_row_end ]
+  %cmp.row = icmp ult i32 %row.iv, %nRows
+  br i1 %cmp.row, label %loop_col_pre, label %exit
+
+loop_col_pre:
+  %px.base = getelementptr inbounds float, float* %pOut, i32 %row.iv
+  br label %loop_col
+
+loop_col:
+  %col.iv = phi i32 [ 0, %loop_col_pre ], [ %col.inc,  %loop_col  ]
+  %pIn.ptr = phi float* [ %pIn, %loop_col_pre ], [ %pIn.next, %loop_col   ]
+  %px.ptr = phi float* [ %px.base, %loop_col_pre ], [ %px.next,  %loop_col   ]
+  %pIn.load = load float, float* %pIn.ptr
+  %pIn.next = getelementptr float, float* %pIn.ptr, i32 1
+  store float %pIn.load, float* %px.ptr
+  %px.next = getelementptr float, float* %px.ptr, i32 %nRows
+  %col.inc = add nuw i32 %col.iv, 1
+  %cmp.col = icmp ult i32 %col.inc, %nCols
+  br i1 %cmp.col, label %loop_col, label %loop_row_end
+
+loop_row_end:
+  %row.inc = add nuw i32 %row.iv, 1
+  br label %loop_row
+
+exit:
+  ret void
+}

>From f9598f06b022e604dac262a3c519aa25a2b8e409 Mon Sep 17 00:00:00 2001
From: nasmnc01 <nashe.mncube at arm.com>
Date: Tue, 9 Dec 2025 10:34:25 +0000
Subject: [PATCH 2/7] Compiler warning due to use of deprecated function

Change-Id: Id8287887c3c77c24619ebf07b5f76a532217aff6
---
 llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
index 435931ce5ea26..b76c784aba879 100644
--- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -2099,7 +2099,7 @@ bool IndVarSimplify::rewritePtrIncrementWithOffsettAddressing(
     return IR.CreateZExt(V, IntegerType::get(V->getContext(), TargetWidth));
   };
 
-  IRBuilder<> Builder(L->getHeader()->getFirstNonPHI());
+  IRBuilder<> Builder(&*L->getHeader()->getFirstInsertionPt());
   for (auto *PHI : LoopPhis) {
     if (!IsPtrToOffsetAddressingCandidate(PHI))
       continue;

>From b2bb9b262f95858f958da81c7c2c68a51f2ad53d Mon Sep 17 00:00:00 2001
From: nasmnc01 <nashe.mncube at arm.com>
Date: Tue, 9 Dec 2025 10:39:06 +0000
Subject: [PATCH 3/7] Formatting

Change-Id: I4d161c236398dca05be84d43e33ada913309b992
---
 llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
index b76c784aba879..fb891b786c8fe 100644
--- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -2090,8 +2090,8 @@ bool IndVarSimplify::rewritePtrIncrementWithOffsettAddressing(
     return true;
   };
 
-  auto AdjustWidth = [&](Value *V, IRBuilder<> &IR,
-                         unsigned TargetWidth, bool IsSigned) -> Value * {
+  auto AdjustWidth = [&](Value *V, IRBuilder<> &IR, unsigned TargetWidth,
+                         bool IsSigned) -> Value * {
     if (V->getType()->getIntegerBitWidth() == TargetWidth)
       return V;
     if (IsSigned)

>From 1d12202927051aa765d86d2b36c091c446becc69 Mon Sep 17 00:00:00 2001
From: nasmnc01 <nashe.mncube at arm.com>
Date: Tue, 9 Dec 2025 11:15:01 +0000
Subject: [PATCH 4/7] Copilot review

Change-Id: Ida6175d40f7bc0f95b28e37a30538aa3cbd64a1e
---
 llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
index fb891b786c8fe..a1fa76f39814c 100644
--- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -164,7 +164,7 @@ class IndVarSimplify {
 
   bool sinkUnusedInvariants(Loop *L);
 
-  bool rewritePtrIncrementWithOffsettAddressing(
+  bool rewritePtrIncrementWithOffsetAddressing(
       Loop *L, SmallVectorImpl<WeakTrackingVH> &DeadInsts);
 
 public:
@@ -2042,12 +2042,15 @@ bool IndVarSimplify::predicateLoopExits(Loop *L, SCEVExpander &Rewriter) {
   return Changed;
 }
 
-bool IndVarSimplify::rewritePtrIncrementWithOffsettAddressing(
+bool IndVarSimplify::rewritePtrIncrementWithOffsetAddressing(
     Loop *L, SmallVectorImpl<WeakTrackingVH> &DeadInsts) {
   SmallVector<PHINode *, 8> LoopPhis(
       llvm::make_pointer_range(L->getHeader()->phis()));
   bool Changed = false;
 
+  if (!L->getLatchCmpInst())
+    return false;
+
   auto IsPtrToOffsetAddressingCandidate = [&](PHINode *PHI) -> bool {
     if (PHI->user_empty())
       return false;
@@ -2055,7 +2058,6 @@ bool IndVarSimplify::rewritePtrIncrementWithOffsettAddressing(
     if (PHI->hasConstantValue())
       return false;
 
-    // TODO: is this necessary.
     if (L->getCanonicalInductionVariable() == PHI)
       return false;
 
@@ -2107,8 +2109,6 @@ bool IndVarSimplify::rewritePtrIncrementWithOffsettAddressing(
     Value *CanonicalIV = L->getCanonicalInductionVariable();
     if (!CanonicalIV)
       continue;
-    if (!L->getLatchCmpInst())
-      return false;
 
     Value *Op0 = PHI->getIncomingValue(0);
     Value *Op1 = PHI->getIncomingValue(1);
@@ -2141,7 +2141,7 @@ bool IndVarSimplify::rewritePtrIncrementWithOffsettAddressing(
                                     InvariantIncomingVal, ArrayRef(Mul));
       PHI->replaceAllUsesWith(NewGEP);
       DeadInsts.emplace_back(PHI);
-      Changed |= true;
+      Changed = true;
     }
   }
   return Changed;
@@ -2225,7 +2225,7 @@ bool IndVarSimplify::run(Loop *L) {
   }
 
   // Try to rewrite ptr increments with ptr offset addressing
-  Changed |= rewritePtrIncrementWithOffsettAddressing(L, DeadInsts);
+  Changed |= rewritePtrIncrementWithOffsetAddressing(L, DeadInsts);
 
   // If we have a trip count expression, rewrite the loop's exit condition
   // using it.

>From 18a9ecc33987a8c0bd12782ff1906c2a8cfbc51d Mon Sep 17 00:00:00 2001
From: nasmnc01 <nashe.mncube at arm.com>
Date: Mon, 12 Jan 2026 13:17:05 +0000
Subject: [PATCH 5/7] [LAA][LV]Allow recognition of strided pointers with
 constant stride

This patch fixes an issue found during LoopAccessAnalysis with respect
to recognising strided pointers that make use of runtime constants.
It was found that for a loop of the following form

```
for (unsigned row = 0; row < nRows; row++) {
  float *px = pOut + row;
  for (unsigned col = 0; col < nCols; col++) {
    *px = *pIn++;
    px += nRows;
}
```

Vectorization would expectedly fail due to the use of a runtime strided IV px.
When passing the `lv-strided-pointer-ivs=true` option, vectorization would be
attempted but would be seen as non-profitable. However, when transforming the loop
to the following form

```
for (unsigned row = 0; row < nRows; row++) {
  for (unsigned col = 0; col < nCols; col++) {
    pOut[row + col * nRows] = *pIn++;
}
```

With `lv-strided-pointer-ivs=true` this vectorizes successfully. As these
loops are equivalent, investigation sought to find out why vectorization was failing.
The cause was found to be that when obtaining the stride for the IVs LAA doesn't
recognise strides that may make use of loop-invariant runtime constants
unless they are in a specific SCEV add-rec form such as in loop two. This patch
allows for the first type of add-rec to also be recognised when the option
`lv-strided-pointer-ivs=true` is passed to the compiler.

Change-Id: Ib01a6b802f516516ac0215569a8d283af915c297
---
 .../llvm/Analysis/LoopAccessAnalysis.h        |   3 +-
 llvm/lib/Analysis/LoopAccessAnalysis.cpp      |  46 ++++++-
 llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | 111 ---------------
 .../Vectorize/LoopVectorizationLegality.cpp   |   7 +-
 .../rewrite-ptr-addr-with-offset-addr.ll      |  64 ---------
 .../LoopVectorize/RISCV/strided-accesses.ll   |  48 +++----
 .../LoopVectorize/pointer-induction.ll        | 130 +++++++++++++++---
 .../LoopVectorize/scev-predicate-reasoning.ll |  21 +--
 8 files changed, 176 insertions(+), 254 deletions(-)
 delete mode 100644 llvm/test/Transforms/IndVarSimplify/rewrite-ptr-addr-with-offset-addr.ll

diff --git a/llvm/include/llvm/Analysis/LoopAccessAnalysis.h b/llvm/include/llvm/Analysis/LoopAccessAnalysis.h
index c85ef3e131068..902f76496eede 100644
--- a/llvm/include/llvm/Analysis/LoopAccessAnalysis.h
+++ b/llvm/include/llvm/Analysis/LoopAccessAnalysis.h
@@ -896,7 +896,8 @@ getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr,
              const Loop *Lp, const DominatorTree &DT,
              const DenseMap<Value *, const SCEV *> &StridesMap =
                  DenseMap<Value *, const SCEV *>(),
-             bool Assume = false, bool ShouldCheckWrap = true);
+             bool Assume = false, bool ShouldCheckWrap = true,
+             bool AllowStridedPtrs = false);
 
 /// Returns the distance between the pointers \p PtrA and \p PtrB iff they are
 /// compatible and it is possible to calculate the distance between them. This
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index 2fc724970747c..a8e2ee647269a 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -968,7 +968,8 @@ class AccessAnalysis {
 /// isNoWrap.
 static std::optional<int64_t>
 getStrideFromAddRec(const SCEVAddRecExpr *AR, const Loop *Lp, Type *AccessTy,
-                    Value *Ptr, PredicatedScalarEvolution &PSE) {
+                    Value *Ptr, PredicatedScalarEvolution &PSE,
+                    bool AllowStridedPtrs = false) {
   if (isa<ScalableVectorType>(AccessTy)) {
     LLVM_DEBUG(dbgs() << "LAA: Bad stride - Scalable object: " << *AccessTy
                       << "\n");
@@ -987,12 +988,43 @@ getStrideFromAddRec(const SCEVAddRecExpr *AR, const Loop *Lp, Type *AccessTy,
     return std::nullopt;
   }
 
-  // Check the step is constant.
-  const SCEV *Step = AR->getStepRecurrence(*PSE.getSE());
-
   // Calculate the pointer stride and check if it is constant.
+  // If we allow strided pointers we also check the add recurrence
+  // expression is making use of loop-invariant
+  // runtime constant for example
+  //
+  // Step = { stride * runtime_constant }
+  //
+  // we should treat this as a constant add recurrence.
+  // To achieve this we check the arguments of
+  // the step are loop invariant and compute the step
+  // as equivalent to just stride.
+  //
+  // We only check this for mul expressions as these
+  // are most common and expected for strided
+  // pointer recurrence expressions.
+  const SCEV *Step = AR->getStepRecurrence(*PSE.getSE());
   const APInt *APStepVal;
-  if (!match(Step, m_scev_APInt(APStepVal))) {
+  auto IsInvariantConstAddRecStep = [&](const SCEV *Step) -> bool {
+    const SCEV *Multiplier;
+
+    // Check the step is constant.
+    if (match(Step, m_scev_APInt(APStepVal)))
+      return true;
+
+    if (AllowStridedPtrs) {
+      for (const auto *Op : Step->operands()) {
+        if (!PSE.getSE()->isLoopInvariant(Op, Lp))
+          return false;
+      }
+      return match(Step,
+                   m_scev_c_Mul(m_scev_APInt(APStepVal), m_SCEV(Multiplier)));
+    }
+
+    return false;
+  };
+
+  if (!IsInvariantConstAddRecStep(Step)) {
     LLVM_DEBUG({
       dbgs() << "LAA: Bad stride - Not a constant strided ";
       if (Ptr)
@@ -1625,7 +1657,7 @@ std::optional<int64_t>
 llvm::getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr,
                    const Loop *Lp, const DominatorTree &DT,
                    const DenseMap<Value *, const SCEV *> &StridesMap,
-                   bool Assume, bool ShouldCheckWrap) {
+                   bool Assume, bool ShouldCheckWrap, bool AllowStridedPtrs) {
   const SCEV *PtrScev = replaceSymbolicStrideSCEV(PSE, StridesMap, Ptr);
   if (PSE.getSE()->isLoopInvariant(PtrScev, Lp))
     return 0;
@@ -1643,7 +1675,7 @@ llvm::getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr,
   }
 
   std::optional<int64_t> Stride =
-      getStrideFromAddRec(AR, Lp, AccessTy, Ptr, PSE);
+      getStrideFromAddRec(AR, Lp, AccessTy, Ptr, PSE, AllowStridedPtrs);
   if (!ShouldCheckWrap || !Stride)
     return Stride;
 
diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
index a1fa76f39814c..f377c192371ea 100644
--- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -164,9 +164,6 @@ class IndVarSimplify {
 
   bool sinkUnusedInvariants(Loop *L);
 
-  bool rewritePtrIncrementWithOffsetAddressing(
-      Loop *L, SmallVectorImpl<WeakTrackingVH> &DeadInsts);
-
 public:
   IndVarSimplify(LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT,
                  const DataLayout &DL, TargetLibraryInfo *TLI,
@@ -2042,111 +2039,6 @@ bool IndVarSimplify::predicateLoopExits(Loop *L, SCEVExpander &Rewriter) {
   return Changed;
 }
 
-bool IndVarSimplify::rewritePtrIncrementWithOffsetAddressing(
-    Loop *L, SmallVectorImpl<WeakTrackingVH> &DeadInsts) {
-  SmallVector<PHINode *, 8> LoopPhis(
-      llvm::make_pointer_range(L->getHeader()->phis()));
-  bool Changed = false;
-
-  if (!L->getLatchCmpInst())
-    return false;
-
-  auto IsPtrToOffsetAddressingCandidate = [&](PHINode *PHI) -> bool {
-    if (PHI->user_empty())
-      return false;
-
-    if (PHI->hasConstantValue())
-      return false;
-
-    if (L->getCanonicalInductionVariable() == PHI)
-      return false;
-
-    // We are only concerned with simple PHI nodes
-    // with two incoming values.
-    if (PHI->getNumIncomingValues() != 2)
-      return false;
-
-    return true;
-  };
-
-  auto NonInvariantPHIOp = [&](Value *Op0, Value *Op1) -> Value * {
-    // One of the two incoming values must be loop invariant
-    // but not both
-    if (!(L->isLoopInvariant(Op0) != L->isLoopInvariant(Op1)))
-      return nullptr;
-
-    return (L->isLoopInvariant(Op0)) ? Op1 : Op0;
-  };
-
-  auto IsConstantIncrement = [&](GetElementPtrInst *GEP) -> bool {
-    if (GEP->getNumIndices() != 1)
-      return false;
-
-    if (GEP->hasAllConstantIndices())
-      return true;
-
-    for (Value *V : GEP->indices())
-      if (!L->isLoopInvariant(V))
-        return false;
-
-    return true;
-  };
-
-  auto AdjustWidth = [&](Value *V, IRBuilder<> &IR, unsigned TargetWidth,
-                         bool IsSigned) -> Value * {
-    if (V->getType()->getIntegerBitWidth() == TargetWidth)
-      return V;
-    if (IsSigned)
-      return IR.CreateSExt(V, IntegerType::get(V->getContext(), TargetWidth));
-    return IR.CreateZExt(V, IntegerType::get(V->getContext(), TargetWidth));
-  };
-
-  IRBuilder<> Builder(&*L->getHeader()->getFirstInsertionPt());
-  for (auto *PHI : LoopPhis) {
-    if (!IsPtrToOffsetAddressingCandidate(PHI))
-      continue;
-
-    Value *CanonicalIV = L->getCanonicalInductionVariable();
-    if (!CanonicalIV)
-      continue;
-
-    Value *Op0 = PHI->getIncomingValue(0);
-    Value *Op1 = PHI->getIncomingValue(1);
-    Value *LoopDependentIncomingVal = NonInvariantPHIOp(Op0, Op1);
-    if (!LoopDependentIncomingVal)
-      continue;
-
-    if (auto *LoopStrideGEPInst =
-            dyn_cast<GetElementPtrInst>(LoopDependentIncomingVal)) {
-      Value *InvariantIncomingVal =
-          (Op0 == LoopDependentIncomingVal) ? Op1 : Op0;
-      if (!dyn_cast<GetElementPtrInst>(InvariantIncomingVal))
-        continue;
-
-      if (!IsConstantIncrement(LoopStrideGEPInst))
-        continue;
-
-      // Replace PHI with offset addressing GEP
-      Value *Stride = LoopStrideGEPInst->getOperand(1);
-      bool IsSigned = L->getLatchCmpInst()->isSigned();
-      unsigned MaxWidth = std::max(CanonicalIV->getType()->getIntegerBitWidth(),
-                                   Stride->getType()->getIntegerBitWidth());
-
-      CanonicalIV = AdjustWidth(CanonicalIV, Builder, MaxWidth, IsSigned);
-      Stride = AdjustWidth(Stride, Builder, MaxWidth, IsSigned);
-
-      Value *Mul = Builder.CreateMul(CanonicalIV, Stride);
-      Value *NewGEP =
-          Builder.CreateInBoundsGEP(LoopStrideGEPInst->getResultElementType(),
-                                    InvariantIncomingVal, ArrayRef(Mul));
-      PHI->replaceAllUsesWith(NewGEP);
-      DeadInsts.emplace_back(PHI);
-      Changed = true;
-    }
-  }
-  return Changed;
-}
-
 //===----------------------------------------------------------------------===//
 //  IndVarSimplify driver. Manage several subpasses of IV simplification.
 //===----------------------------------------------------------------------===//
@@ -2224,9 +2116,6 @@ bool IndVarSimplify::run(Loop *L) {
     SE->forgetLoop(L);
   }
 
-  // Try to rewrite ptr increments with ptr offset addressing
-  Changed |= rewritePtrIncrementWithOffsetAddressing(L, DeadInsts);
-
   // If we have a trip count expression, rewrite the loop's exit condition
   // using it.
   if (!DisableLFTR) {
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
index ea431b4fa5df8..effb2a6f7ccf5 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
@@ -481,9 +481,10 @@ int LoopVectorizationLegality::isConsecutivePtr(Type *AccessTy,
   const auto &Strides =
     LAI ? LAI->getSymbolicStrides() : DenseMap<Value *, const SCEV *>();
 
-  int Stride = getPtrStride(PSE, AccessTy, Ptr, TheLoop, *DT, Strides,
-                            AllowRuntimeSCEVChecks, false)
-                   .value_or(0);
+  int Stride =
+      getPtrStride(PSE, AccessTy, Ptr, TheLoop, *DT, Strides,
+                   AllowRuntimeSCEVChecks, false, AllowStridedPointerIVs)
+          .value_or(0);
   if (Stride == 1 || Stride == -1)
     return Stride;
   return 0;
diff --git a/llvm/test/Transforms/IndVarSimplify/rewrite-ptr-addr-with-offset-addr.ll b/llvm/test/Transforms/IndVarSimplify/rewrite-ptr-addr-with-offset-addr.ll
deleted file mode 100644
index c08696f51b076..0000000000000
--- a/llvm/test/Transforms/IndVarSimplify/rewrite-ptr-addr-with-offset-addr.ll
+++ /dev/null
@@ -1,64 +0,0 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
-; RUN: opt < %s -passes=indvars -S -o - | FileCheck %s
-
-
-define void @mat_transpose(float* %pIn, float* %pOut, i32 %nRows, i32 %nCols) {
-; CHECK-LABEL: define void @mat_transpose(
-; CHECK-SAME: ptr [[PIN:%.*]], ptr [[POUT:%.*]], i32 [[NROWS:%.*]], i32 [[NCOLS:%.*]]) {
-; CHECK-NEXT:  [[ENTRY:.*]]:
-; CHECK-NEXT:    br label %[[LOOP_ROW:.*]]
-; CHECK:       [[LOOP_ROW]]:
-; CHECK-NEXT:    [[ROW_IV:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[ROW_INC:%.*]], %[[LOOP_ROW_END:.*]] ]
-; CHECK-NEXT:    [[CMP_ROW:%.*]] = icmp ult i32 [[ROW_IV]], [[NROWS]]
-; CHECK-NEXT:    br i1 [[CMP_ROW]], label %[[LOOP_COL_PRE:.*]], label %[[EXIT:.*]]
-; CHECK:       [[LOOP_COL_PRE]]:
-; CHECK-NEXT:    [[PX_BASE:%.*]] = getelementptr inbounds float, ptr [[POUT]], i32 [[ROW_IV]]
-; CHECK-NEXT:    br label %[[LOOP_COL:.*]]
-; CHECK:       [[LOOP_COL]]:
-; CHECK-NEXT:    [[COL_IV:%.*]] = phi i32 [ 0, %[[LOOP_COL_PRE]] ], [ [[COL_INC:%.*]], %[[LOOP_COL]] ]
-; CHECK-NEXT:    [[PIN_PTR:%.*]] = phi ptr [ [[PIN]], %[[LOOP_COL_PRE]] ], [ [[PIN_NEXT:%.*]], %[[LOOP_COL]] ]
-; CHECK-NEXT:    [[TMP0:%.*]] = mul i32 [[COL_IV]], [[NROWS]]
-; CHECK-NEXT:    [[PX_PTR:%.*]] = getelementptr inbounds float, ptr [[PX_BASE]], i32 [[TMP0]]
-; CHECK-NEXT:    [[PIN_LOAD:%.*]] = load float, ptr [[PIN_PTR]], align 4
-; CHECK-NEXT:    [[PIN_NEXT]] = getelementptr float, ptr [[PIN_PTR]], i32 1
-; CHECK-NEXT:    store float [[PIN_LOAD]], ptr [[PX_PTR]], align 4
-; CHECK-NEXT:    [[COL_INC]] = add nuw i32 [[COL_IV]], 1
-; CHECK-NEXT:    [[CMP_COL:%.*]] = icmp ult i32 [[COL_INC]], [[NCOLS]]
-; CHECK-NEXT:    br i1 [[CMP_COL]], label %[[LOOP_COL]], label %[[LOOP_ROW_END]]
-; CHECK:       [[LOOP_ROW_END]]:
-; CHECK-NEXT:    [[ROW_INC]] = add nuw i32 [[ROW_IV]], 1
-; CHECK-NEXT:    br label %[[LOOP_ROW]]
-; CHECK:       [[EXIT]]:
-; CHECK-NEXT:    ret void
-;
-entry:
-  br label %loop_row
-
-loop_row:
-  %row.iv = phi i32 [ 0, %entry ], [ %row.inc, %loop_row_end ]
-  %cmp.row = icmp ult i32 %row.iv, %nRows
-  br i1 %cmp.row, label %loop_col_pre, label %exit
-
-loop_col_pre:
-  %px.base = getelementptr inbounds float, float* %pOut, i32 %row.iv
-  br label %loop_col
-
-loop_col:
-  %col.iv = phi i32 [ 0, %loop_col_pre ], [ %col.inc,  %loop_col  ]
-  %pIn.ptr = phi float* [ %pIn, %loop_col_pre ], [ %pIn.next, %loop_col   ]
-  %px.ptr = phi float* [ %px.base, %loop_col_pre ], [ %px.next,  %loop_col   ]
-  %pIn.load = load float, float* %pIn.ptr
-  %pIn.next = getelementptr float, float* %pIn.ptr, i32 1
-  store float %pIn.load, float* %px.ptr
-  %px.next = getelementptr float, float* %px.ptr, i32 %nRows
-  %col.inc = add nuw i32 %col.iv, 1
-  %cmp.col = icmp ult i32 %col.inc, %nCols
-  br i1 %cmp.col, label %loop_col, label %loop_row_end
-
-loop_row_end:
-  %row.inc = add nuw i32 %row.iv, 1
-  br label %loop_row
-
-exit:
-  ret void
-}
diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/strided-accesses.ll b/llvm/test/Transforms/LoopVectorize/RISCV/strided-accesses.ll
index 0da00bf0dbd0f..2bef1e50317de 100644
--- a/llvm/test/Transforms/LoopVectorize/RISCV/strided-accesses.ll
+++ b/llvm/test/Transforms/LoopVectorize/RISCV/strided-accesses.ll
@@ -764,25 +764,20 @@ define void @double_stride_int_scaled(ptr %p, ptr %p2, i64 %stride) {
 ; STRIDED-NEXT:    [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
 ; STRIDED-NEXT:    br i1 [[FOUND_CONFLICT]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
 ; STRIDED:       vector.ph:
-; STRIDED-NEXT:    [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <vscale x 4 x i64> poison, i64 [[STRIDE]], i64 0
-; STRIDED-NEXT:    [[BROADCAST_SPLAT1:%.*]] = shufflevector <vscale x 4 x i64> [[BROADCAST_SPLATINSERT1]], <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer
-; STRIDED-NEXT:    [[TMP12:%.*]] = call <vscale x 4 x i64> @llvm.stepvector.nxv4i64()
 ; STRIDED-NEXT:    br label [[VECTOR_BODY:%.*]]
 ; STRIDED:       vector.body:
-; STRIDED-NEXT:    [[VEC_IND:%.*]] = phi <vscale x 4 x i64> [ [[TMP12]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
+; STRIDED-NEXT:    [[EVL_BASED_IV:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_EVL_NEXT:%.*]], [[VECTOR_BODY]] ]
 ; STRIDED-NEXT:    [[AVL:%.*]] = phi i64 [ 1024, [[VECTOR_PH]] ], [ [[AVL_NEXT:%.*]], [[VECTOR_BODY]] ]
 ; STRIDED-NEXT:    [[TMP43:%.*]] = call i32 @llvm.experimental.get.vector.length.i64(i64 [[AVL]], i32 4, i1 true)
-; STRIDED-NEXT:    [[TMP44:%.*]] = zext i32 [[TMP43]] to i64
-; STRIDED-NEXT:    [[BROADCAST_SPLATINSERT9:%.*]] = insertelement <vscale x 4 x i64> poison, i64 [[TMP44]], i64 0
-; STRIDED-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 4 x i64> [[BROADCAST_SPLATINSERT9]], <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer
-; STRIDED-NEXT:    [[TMP18:%.*]] = mul nuw nsw <vscale x 4 x i64> [[VEC_IND]], [[BROADCAST_SPLAT1]]
-; STRIDED-NEXT:    [[TMP19:%.*]] = getelementptr i32, ptr [[P]], <vscale x 4 x i64> [[TMP18]]
-; STRIDED-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 4 x i32> @llvm.vp.gather.nxv4i32.nxv4p0(<vscale x 4 x ptr> align 4 [[TMP19]], <vscale x 4 x i1> splat (i1 true), i32 [[TMP43]]), !alias.scope [[META5:![0-9]+]]
+; STRIDED-NEXT:    [[TMP42:%.*]] = mul nuw nsw i64 [[EVL_BASED_IV]], [[STRIDE]]
+; STRIDED-NEXT:    [[TMP45:%.*]] = getelementptr i32, ptr [[P]], i64 [[TMP42]]
+; STRIDED-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 4 x i32> @llvm.vp.load.nxv4i32.p0(ptr align 4 [[TMP45]], <vscale x 4 x i1> splat (i1 true), i32 [[TMP43]]), !alias.scope [[META5:![0-9]+]]
 ; STRIDED-NEXT:    [[TMP20:%.*]] = add <vscale x 4 x i32> [[WIDE_MASKED_GATHER]], splat (i32 1)
-; STRIDED-NEXT:    [[TMP21:%.*]] = getelementptr i32, ptr [[P2]], <vscale x 4 x i64> [[TMP18]]
-; STRIDED-NEXT:    call void @llvm.vp.scatter.nxv4i32.nxv4p0(<vscale x 4 x i32> [[TMP20]], <vscale x 4 x ptr> align 4 [[TMP21]], <vscale x 4 x i1> splat (i1 true), i32 [[TMP43]]), !alias.scope [[META8:![0-9]+]], !noalias [[META5]]
+; STRIDED-NEXT:    [[TMP46:%.*]] = getelementptr i32, ptr [[P2]], i64 [[TMP42]]
+; STRIDED-NEXT:    call void @llvm.vp.store.nxv4i32.p0(<vscale x 4 x i32> [[TMP20]], ptr align 4 [[TMP46]], <vscale x 4 x i1> splat (i1 true), i32 [[TMP43]]), !alias.scope [[META8:![0-9]+]], !noalias [[META5]]
+; STRIDED-NEXT:    [[TMP44:%.*]] = zext i32 [[TMP43]] to i64
+; STRIDED-NEXT:    [[INDEX_EVL_NEXT]] = add nuw i64 [[TMP44]], [[EVL_BASED_IV]]
 ; STRIDED-NEXT:    [[AVL_NEXT]] = sub nuw i64 [[AVL]], [[TMP44]]
-; STRIDED-NEXT:    [[VEC_IND_NEXT]] = add <vscale x 4 x i64> [[VEC_IND]], [[BROADCAST_SPLAT]]
 ; STRIDED-NEXT:    [[TMP41:%.*]] = icmp eq i64 [[AVL_NEXT]], 0
 ; STRIDED-NEXT:    br i1 [[TMP41]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP10:![0-9]+]]
 ; STRIDED:       middle.block:
@@ -861,33 +856,24 @@ define void @double_stride_int_scaled(ptr %p, ptr %p2, i64 %stride) {
 ; STRIDED-UF2:       vector.ph:
 ; STRIDED-UF2-NEXT:    [[TMP28:%.*]] = call i64 @llvm.vscale.i64()
 ; STRIDED-UF2-NEXT:    [[TMP29:%.*]] = shl nuw i64 [[TMP28]], 2
-; STRIDED-UF2-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 4 x i64> poison, i64 [[TMP29]], i64 0
-; STRIDED-UF2-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 4 x i64> [[BROADCAST_SPLATINSERT]], <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer
 ; STRIDED-UF2-NEXT:    [[TMP30:%.*]] = shl nuw i64 [[TMP29]], 1
 ; STRIDED-UF2-NEXT:    [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP30]]
 ; STRIDED-UF2-NEXT:    [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
-; STRIDED-UF2-NEXT:    [[BROADCAST_SPLATINSERT10:%.*]] = insertelement <vscale x 4 x i64> poison, i64 [[STRIDE]], i64 0
-; STRIDED-UF2-NEXT:    [[BROADCAST_SPLAT11:%.*]] = shufflevector <vscale x 4 x i64> [[BROADCAST_SPLATINSERT10]], <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer
-; STRIDED-UF2-NEXT:    [[TMP31:%.*]] = call <vscale x 4 x i64> @llvm.stepvector.nxv4i64()
 ; STRIDED-UF2-NEXT:    br label [[VECTOR_BODY:%.*]]
 ; STRIDED-UF2:       vector.body:
 ; STRIDED-UF2-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
-; STRIDED-UF2-NEXT:    [[VEC_IND:%.*]] = phi <vscale x 4 x i64> [ [[TMP31]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
-; STRIDED-UF2-NEXT:    [[STEP_ADD:%.*]] = add <vscale x 4 x i64> [[VEC_IND]], [[BROADCAST_SPLAT]]
-; STRIDED-UF2-NEXT:    [[TMP33:%.*]] = mul nuw nsw <vscale x 4 x i64> [[VEC_IND]], [[BROADCAST_SPLAT11]]
-; STRIDED-UF2-NEXT:    [[TMP34:%.*]] = mul nuw nsw <vscale x 4 x i64> [[STEP_ADD]], [[BROADCAST_SPLAT11]]
-; STRIDED-UF2-NEXT:    [[TMP35:%.*]] = getelementptr i32, ptr [[P]], <vscale x 4 x i64> [[TMP33]]
-; STRIDED-UF2-NEXT:    [[TMP36:%.*]] = getelementptr i32, ptr [[P]], <vscale x 4 x i64> [[TMP34]]
-; STRIDED-UF2-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 4 x i32> @llvm.masked.gather.nxv4i32.nxv4p0(<vscale x 4 x ptr> align 4 [[TMP35]], <vscale x 4 x i1> splat (i1 true), <vscale x 4 x i32> poison), !alias.scope [[META8:![0-9]+]]
-; STRIDED-UF2-NEXT:    [[WIDE_MASKED_GATHER12:%.*]] = call <vscale x 4 x i32> @llvm.masked.gather.nxv4i32.nxv4p0(<vscale x 4 x ptr> align 4 [[TMP36]], <vscale x 4 x i1> splat (i1 true), <vscale x 4 x i32> poison), !alias.scope [[META8]]
+; STRIDED-UF2-NEXT:    [[TMP31:%.*]] = mul nuw nsw i64 [[INDEX]], [[STRIDE]]
+; STRIDED-UF2-NEXT:    [[TMP32:%.*]] = getelementptr i32, ptr [[P]], i64 [[TMP31]]
+; STRIDED-UF2-NEXT:    [[TMP33:%.*]] = getelementptr i32, ptr [[TMP32]], i64 [[TMP29]]
+; STRIDED-UF2-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = load <vscale x 4 x i32>, ptr [[TMP32]], align 4, !alias.scope [[META8:![0-9]+]]
+; STRIDED-UF2-NEXT:    [[WIDE_MASKED_GATHER12:%.*]] = load <vscale x 4 x i32>, ptr [[TMP33]], align 4, !alias.scope [[META8]]
 ; STRIDED-UF2-NEXT:    [[TMP37:%.*]] = add <vscale x 4 x i32> [[WIDE_MASKED_GATHER]], splat (i32 1)
 ; STRIDED-UF2-NEXT:    [[TMP38:%.*]] = add <vscale x 4 x i32> [[WIDE_MASKED_GATHER12]], splat (i32 1)
-; STRIDED-UF2-NEXT:    [[TMP39:%.*]] = getelementptr i32, ptr [[P2]], <vscale x 4 x i64> [[TMP33]]
-; STRIDED-UF2-NEXT:    [[TMP40:%.*]] = getelementptr i32, ptr [[P2]], <vscale x 4 x i64> [[TMP34]]
-; STRIDED-UF2-NEXT:    call void @llvm.masked.scatter.nxv4i32.nxv4p0(<vscale x 4 x i32> [[TMP37]], <vscale x 4 x ptr> align 4 [[TMP39]], <vscale x 4 x i1> splat (i1 true)), !alias.scope [[META11:![0-9]+]], !noalias [[META8]]
-; STRIDED-UF2-NEXT:    call void @llvm.masked.scatter.nxv4i32.nxv4p0(<vscale x 4 x i32> [[TMP38]], <vscale x 4 x ptr> align 4 [[TMP40]], <vscale x 4 x i1> splat (i1 true)), !alias.scope [[META11]], !noalias [[META8]]
+; STRIDED-UF2-NEXT:    [[TMP36:%.*]] = getelementptr i32, ptr [[P2]], i64 [[TMP31]]
+; STRIDED-UF2-NEXT:    [[TMP39:%.*]] = getelementptr i32, ptr [[TMP36]], i64 [[TMP29]]
+; STRIDED-UF2-NEXT:    store <vscale x 4 x i32> [[TMP37]], ptr [[TMP36]], align 4, !alias.scope [[META11:![0-9]+]], !noalias [[META8]]
+; STRIDED-UF2-NEXT:    store <vscale x 4 x i32> [[TMP38]], ptr [[TMP39]], align 4, !alias.scope [[META11]], !noalias [[META8]]
 ; STRIDED-UF2-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP30]]
-; STRIDED-UF2-NEXT:    [[VEC_IND_NEXT]] = add <vscale x 4 x i64> [[STEP_ADD]], [[BROADCAST_SPLAT]]
 ; STRIDED-UF2-NEXT:    [[TMP41:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
 ; STRIDED-UF2-NEXT:    br i1 [[TMP41]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP13:![0-9]+]]
 ; STRIDED-UF2:       middle.block:
diff --git a/llvm/test/Transforms/LoopVectorize/pointer-induction.ll b/llvm/test/Transforms/LoopVectorize/pointer-induction.ll
index 995c2016339a4..44514cf758450 100644
--- a/llvm/test/Transforms/LoopVectorize/pointer-induction.ll
+++ b/llvm/test/Transforms/LoopVectorize/pointer-induction.ll
@@ -536,28 +536,10 @@ define i64 @ivopt_widen_ptr_indvar_2(ptr noalias %a, i64 %stride, i64 %n) {
 ; STRIDED:       vector.body:
 ; STRIDED-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
 ; STRIDED-NEXT:    [[OFFSET_IDX:%.*]] = mul i64 [[INDEX]], [[TMP1]]
-; STRIDED-NEXT:    [[TMP8:%.*]] = mul i64 0, [[TMP1]]
-; STRIDED-NEXT:    [[TMP9:%.*]] = add i64 [[OFFSET_IDX]], [[TMP8]]
-; STRIDED-NEXT:    [[TMP10:%.*]] = mul i64 1, [[TMP1]]
-; STRIDED-NEXT:    [[TMP11:%.*]] = add i64 [[OFFSET_IDX]], [[TMP10]]
-; STRIDED-NEXT:    [[TMP12:%.*]] = mul i64 2, [[TMP1]]
-; STRIDED-NEXT:    [[TMP13:%.*]] = add i64 [[OFFSET_IDX]], [[TMP12]]
-; STRIDED-NEXT:    [[TMP14:%.*]] = mul i64 3, [[TMP1]]
-; STRIDED-NEXT:    [[TMP15:%.*]] = add i64 [[OFFSET_IDX]], [[TMP14]]
-; STRIDED-NEXT:    [[NEXT_GEP:%.*]] = getelementptr i8, ptr null, i64 [[TMP9]]
-; STRIDED-NEXT:    [[NEXT_GEP1:%.*]] = getelementptr i8, ptr null, i64 [[TMP11]]
-; STRIDED-NEXT:    [[NEXT_GEP2:%.*]] = getelementptr i8, ptr null, i64 [[TMP13]]
-; STRIDED-NEXT:    [[NEXT_GEP3:%.*]] = getelementptr i8, ptr null, i64 [[TMP15]]
+; STRIDED-NEXT:    [[NEXT_GEP:%.*]] = getelementptr i8, ptr null, i64 [[OFFSET_IDX]]
 ; STRIDED-NEXT:    [[TMP21:%.*]] = getelementptr i64, ptr [[A:%.*]], i64 [[INDEX]]
 ; STRIDED-NEXT:    [[WIDE_LOAD:%.*]] = load <4 x i64>, ptr [[TMP21]], align 8
-; STRIDED-NEXT:    [[TMP23:%.*]] = extractelement <4 x i64> [[WIDE_LOAD]], i32 0
-; STRIDED-NEXT:    [[TMP24:%.*]] = extractelement <4 x i64> [[WIDE_LOAD]], i32 1
-; STRIDED-NEXT:    [[TMP16:%.*]] = extractelement <4 x i64> [[WIDE_LOAD]], i32 2
-; STRIDED-NEXT:    [[TMP25:%.*]] = extractelement <4 x i64> [[WIDE_LOAD]], i32 3
-; STRIDED-NEXT:    store i64 [[TMP23]], ptr [[NEXT_GEP]], align 8
-; STRIDED-NEXT:    store i64 [[TMP24]], ptr [[NEXT_GEP1]], align 8
-; STRIDED-NEXT:    store i64 [[TMP16]], ptr [[NEXT_GEP2]], align 8
-; STRIDED-NEXT:    store i64 [[TMP25]], ptr [[NEXT_GEP3]], align 8
+; STRIDED-NEXT:    store <4 x i64> [[WIDE_LOAD]], ptr [[NEXT_GEP]], align 8
 ; STRIDED-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
 ; STRIDED-NEXT:    [[TMP18:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
 ; STRIDED-NEXT:    br i1 [[TMP18]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP12:![0-9]+]]
@@ -700,3 +682,111 @@ exit:
   %result = add i64 %cast.ptr, %0
   ret i64 %result
 }
+
+; Test a pointer induction with a loop-invariant runtime stride.
+define void @strided_ptr_iv_runtime_stride(ptr %pIn, ptr %pOut, i32 %nCols, i32 %stride) {
+; DEFAULT-LABEL: @strided_ptr_iv_runtime_stride(
+; DEFAULT-NEXT:  entry:
+; DEFAULT-NEXT:    br label [[LOOP:%.*]]
+; DEFAULT:       loop:
+; DEFAULT-NEXT:    [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
+; DEFAULT-NEXT:    [[IN_PTR:%.*]] = phi ptr [ [[PIN:%.*]], [[ENTRY]] ], [ [[IN_NEXT:%.*]], [[LOOP]] ]
+; DEFAULT-NEXT:    [[OUT_PTR:%.*]] = phi ptr [ [[POUT:%.*]], [[ENTRY]] ], [ [[OUT_NEXT:%.*]], [[LOOP]] ]
+; DEFAULT-NEXT:    [[VAL:%.*]] = load float, ptr [[IN_PTR]], align 4
+; DEFAULT-NEXT:    store float [[VAL]], ptr [[OUT_PTR]], align 4
+; DEFAULT-NEXT:    [[IN_NEXT]] = getelementptr inbounds float, ptr [[IN_PTR]], i32 1
+; DEFAULT-NEXT:    [[OUT_NEXT]] = getelementptr inbounds float, ptr [[OUT_PTR]], i32 [[STRIDE:%.*]]
+; DEFAULT-NEXT:    [[IV_NEXT]] = add nuw i32 [[IV]], 1
+; DEFAULT-NEXT:    [[CMP:%.*]] = icmp ult i32 [[IV_NEXT]], [[NCOLS:%.*]]
+; DEFAULT-NEXT:    br i1 [[CMP]], label [[LOOP]], label [[EXIT:%.*]]
+; DEFAULT:       exit:
+; DEFAULT-NEXT:    ret void
+;
+; STRIDED-LABEL: @strided_ptr_iv_runtime_stride(
+; STRIDED-NEXT:  entry:
+; STRIDED-NEXT:    [[TMP0:%.*]] = zext i32 [[NCOLS:%.*]] to i64
+; STRIDED-NEXT:    [[UMAX4:%.*]] = call i64 @llvm.umax.i64(i64 [[TMP0]], i64 1)
+; STRIDED-NEXT:    [[TMP1:%.*]] = sext i32 [[STRIDE:%.*]] to i64
+; STRIDED-NEXT:    [[TMP2:%.*]] = shl nsw i64 [[TMP1]], 2
+; STRIDED-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[UMAX4]], 4
+; STRIDED-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
+; STRIDED:       vector.memcheck:
+; STRIDED-NEXT:    [[TMP3:%.*]] = sext i32 [[STRIDE]] to i64
+; STRIDED-NEXT:    [[UMAX:%.*]] = call i32 @llvm.umax.i32(i32 [[NCOLS]], i32 1)
+; STRIDED-NEXT:    [[TMP4:%.*]] = add i32 [[UMAX]], -1
+; STRIDED-NEXT:    [[TMP5:%.*]] = zext i32 [[TMP4]] to i64
+; STRIDED-NEXT:    [[TMP6:%.*]] = mul i64 [[TMP3]], [[TMP5]]
+; STRIDED-NEXT:    [[TMP7:%.*]] = shl i64 [[TMP6]], 2
+; STRIDED-NEXT:    [[SCEVGEP:%.*]] = getelementptr i8, ptr [[POUT:%.*]], i64 [[TMP7]]
+; STRIDED-NEXT:    [[TMP8:%.*]] = icmp ult ptr [[POUT]], [[SCEVGEP]]
+; STRIDED-NEXT:    [[UMIN:%.*]] = select i1 [[TMP8]], ptr [[POUT]], ptr [[SCEVGEP]]
+; STRIDED-NEXT:    [[TMP9:%.*]] = icmp ugt ptr [[POUT]], [[SCEVGEP]]
+; STRIDED-NEXT:    [[UMAX1:%.*]] = select i1 [[TMP9]], ptr [[POUT]], ptr [[SCEVGEP]]
+; STRIDED-NEXT:    [[SCEVGEP2:%.*]] = getelementptr i8, ptr [[UMAX1]], i64 4
+; STRIDED-NEXT:    [[TMP10:%.*]] = shl nuw nsw i64 [[TMP5]], 2
+; STRIDED-NEXT:    [[TMP11:%.*]] = add nuw nsw i64 [[TMP10]], 4
+; STRIDED-NEXT:    [[SCEVGEP3:%.*]] = getelementptr i8, ptr [[PIN:%.*]], i64 [[TMP11]]
+; STRIDED-NEXT:    [[BOUND0:%.*]] = icmp ult ptr [[UMIN]], [[SCEVGEP3]]
+; STRIDED-NEXT:    [[BOUND1:%.*]] = icmp ult ptr [[PIN]], [[SCEVGEP2]]
+; STRIDED-NEXT:    [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
+; STRIDED-NEXT:    br i1 [[FOUND_CONFLICT]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
+; STRIDED:       vector.ph:
+; STRIDED-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[UMAX4]], 4
+; STRIDED-NEXT:    [[N_VEC:%.*]] = sub i64 [[UMAX4]], [[N_MOD_VF]]
+; STRIDED-NEXT:    [[TMP12:%.*]] = trunc i64 [[N_VEC]] to i32
+; STRIDED-NEXT:    [[TMP13:%.*]] = mul i64 [[N_VEC]], 4
+; STRIDED-NEXT:    [[TMP14:%.*]] = getelementptr i8, ptr [[PIN]], i64 [[TMP13]]
+; STRIDED-NEXT:    [[TMP15:%.*]] = mul i64 [[N_VEC]], [[TMP2]]
+; STRIDED-NEXT:    [[TMP16:%.*]] = getelementptr i8, ptr [[POUT]], i64 [[TMP15]]
+; STRIDED-NEXT:    br label [[VECTOR_BODY:%.*]]
+; STRIDED:       vector.body:
+; STRIDED-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
+; STRIDED-NEXT:    [[OFFSET_IDX:%.*]] = mul i64 [[INDEX]], 4
+; STRIDED-NEXT:    [[NEXT_GEP:%.*]] = getelementptr i8, ptr [[PIN]], i64 [[OFFSET_IDX]]
+; STRIDED-NEXT:    [[OFFSET_IDX5:%.*]] = mul i64 [[INDEX]], [[TMP2]]
+; STRIDED-NEXT:    [[NEXT_GEP6:%.*]] = getelementptr i8, ptr [[POUT]], i64 [[OFFSET_IDX5]]
+; STRIDED-NEXT:    [[WIDE_LOAD:%.*]] = load <4 x float>, ptr [[NEXT_GEP]], align 4, !alias.scope [[META16:![0-9]+]]
+; STRIDED-NEXT:    store <4 x float> [[WIDE_LOAD]], ptr [[NEXT_GEP6]], align 4, !alias.scope [[META19:![0-9]+]], !noalias [[META16]]
+; STRIDED-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
+; STRIDED-NEXT:    [[TMP17:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
+; STRIDED-NEXT:    br i1 [[TMP17]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP21:![0-9]+]]
+; STRIDED:       middle.block:
+; STRIDED-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[UMAX4]], [[N_VEC]]
+; STRIDED-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
+; STRIDED:       scalar.ph:
+; STRIDED-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ [[TMP12]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_MEMCHECK]] ]
+; STRIDED-NEXT:    [[BC_RESUME_VAL7:%.*]] = phi ptr [ [[TMP14]], [[MIDDLE_BLOCK]] ], [ [[PIN]], [[ENTRY]] ], [ [[PIN]], [[VECTOR_MEMCHECK]] ]
+; STRIDED-NEXT:    [[BC_RESUME_VAL8:%.*]] = phi ptr [ [[TMP16]], [[MIDDLE_BLOCK]] ], [ [[POUT]], [[ENTRY]] ], [ [[POUT]], [[VECTOR_MEMCHECK]] ]
+; STRIDED-NEXT:    br label [[LOOP:%.*]]
+; STRIDED:       loop:
+; STRIDED-NEXT:    [[IV:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
+; STRIDED-NEXT:    [[IN_PTR:%.*]] = phi ptr [ [[BC_RESUME_VAL7]], [[SCALAR_PH]] ], [ [[IN_NEXT:%.*]], [[LOOP]] ]
+; STRIDED-NEXT:    [[OUT_PTR:%.*]] = phi ptr [ [[BC_RESUME_VAL8]], [[SCALAR_PH]] ], [ [[OUT_NEXT:%.*]], [[LOOP]] ]
+; STRIDED-NEXT:    [[VAL:%.*]] = load float, ptr [[IN_PTR]], align 4
+; STRIDED-NEXT:    store float [[VAL]], ptr [[OUT_PTR]], align 4
+; STRIDED-NEXT:    [[IN_NEXT]] = getelementptr inbounds float, ptr [[IN_PTR]], i32 1
+; STRIDED-NEXT:    [[OUT_NEXT]] = getelementptr inbounds float, ptr [[OUT_PTR]], i32 [[STRIDE]]
+; STRIDED-NEXT:    [[IV_NEXT]] = add nuw i32 [[IV]], 1
+; STRIDED-NEXT:    [[CMP:%.*]] = icmp ult i32 [[IV_NEXT]], [[NCOLS]]
+; STRIDED-NEXT:    br i1 [[CMP]], label [[LOOP]], label [[EXIT]], !llvm.loop [[LOOP22:![0-9]+]]
+; STRIDED:       exit:
+; STRIDED-NEXT:    ret void
+;
+entry:
+  br label %loop
+
+loop:
+  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
+  %in.ptr = phi ptr [ %pIn, %entry ], [ %in.next, %loop ]
+  %out.ptr = phi ptr [ %pOut, %entry ], [ %out.next, %loop ]
+  %val = load float, ptr %in.ptr, align 4
+  store float %val, ptr %out.ptr, align 4
+  %in.next = getelementptr inbounds float, ptr %in.ptr, i32 1
+  %out.next = getelementptr inbounds float, ptr %out.ptr, i32 %stride
+  %iv.next = add nuw i32 %iv, 1
+  %cmp = icmp ult i32 %iv.next, %nCols
+  br i1 %cmp, label %loop, label %exit
+
+exit:
+  ret void
+}
diff --git a/llvm/test/Transforms/LoopVectorize/scev-predicate-reasoning.ll b/llvm/test/Transforms/LoopVectorize/scev-predicate-reasoning.ll
index e40e8bb10a3f8..2749a819614c7 100644
--- a/llvm/test/Transforms/LoopVectorize/scev-predicate-reasoning.ll
+++ b/llvm/test/Transforms/LoopVectorize/scev-predicate-reasoning.ll
@@ -20,28 +20,15 @@ define void @step_direction_unknown(i32 %arg, ptr %dst) {
 ; CHECK-NEXT:    [[TMP6:%.*]] = or i1 [[TMP5]], [[MUL_OVERFLOW]]
 ; CHECK-NEXT:    br i1 [[TMP6]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
 ; CHECK:       [[VECTOR_PH]]:
-; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i32> poison, i32 [[ADD]], i64 0
-; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT]], <4 x i32> poison, <4 x i32> zeroinitializer
 ; CHECK-NEXT:    br label %[[VECTOR_BODY:.*]]
 ; CHECK:       [[VECTOR_BODY]]:
 ; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
-; CHECK-NEXT:    [[VEC_IND:%.*]] = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %[[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], %[[VECTOR_BODY]] ]
-; CHECK-NEXT:    [[TMP8:%.*]] = mul <4 x i32> [[BROADCAST_SPLAT]], [[VEC_IND]]
-; CHECK-NEXT:    [[TMP9:%.*]] = zext <4 x i32> [[TMP8]] to <4 x i64>
-; CHECK-NEXT:    [[TMP10:%.*]] = extractelement <4 x i64> [[TMP9]], i32 0
-; CHECK-NEXT:    [[TMP11:%.*]] = extractelement <4 x i64> [[TMP9]], i32 1
-; CHECK-NEXT:    [[TMP12:%.*]] = extractelement <4 x i64> [[TMP9]], i32 2
-; CHECK-NEXT:    [[TMP13:%.*]] = extractelement <4 x i64> [[TMP9]], i32 3
-; CHECK-NEXT:    [[TMP14:%.*]] = getelementptr double, ptr [[DST]], i64 [[TMP10]]
-; CHECK-NEXT:    [[TMP15:%.*]] = getelementptr double, ptr [[DST]], i64 [[TMP11]]
-; CHECK-NEXT:    [[TMP16:%.*]] = getelementptr double, ptr [[DST]], i64 [[TMP12]]
+; CHECK-NEXT:    [[TMP7:%.*]] = trunc i64 [[INDEX]] to i32
+; CHECK-NEXT:    [[TMP8:%.*]] = mul i32 [[ADD]], [[TMP7]]
+; CHECK-NEXT:    [[TMP13:%.*]] = zext i32 [[TMP8]] to i64
 ; CHECK-NEXT:    [[TMP17:%.*]] = getelementptr double, ptr [[DST]], i64 [[TMP13]]
-; CHECK-NEXT:    store double 0.000000e+00, ptr [[TMP14]], align 8
-; CHECK-NEXT:    store double 0.000000e+00, ptr [[TMP15]], align 8
-; CHECK-NEXT:    store double 0.000000e+00, ptr [[TMP16]], align 8
-; CHECK-NEXT:    store double 0.000000e+00, ptr [[TMP17]], align 8
+; CHECK-NEXT:    store <4 x double> zeroinitializer, ptr [[TMP17]], align 8
 ; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
-; CHECK-NEXT:    [[VEC_IND_NEXT]] = add <4 x i32> [[VEC_IND]], splat (i32 4)
 ; CHECK-NEXT:    [[TMP18:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
 ; CHECK-NEXT:    br i1 [[TMP18]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
 ; CHECK:       [[MIDDLE_BLOCK]]:

>From 4652ec52546ff33389d849bd1d9ad067855cc837 Mon Sep 17 00:00:00 2001
From: nasmnc01 <nashe.mncube at arm.com>
Date: Wed, 21 Jan 2026 15:39:51 +0000
Subject: [PATCH 6/7] Add const runtime strided pointer helpers

Change-Id: I554dba37cb16436851427d47298733784d08ff6c
---
 .../llvm/Analysis/LoopAccessAnalysis.h        | 14 +++-
 .../Vectorize/LoopVectorizationLegality.h     | 10 +++
 llvm/lib/Analysis/LoopAccessAnalysis.cpp      | 65 ++++++++++++++-----
 .../Vectorize/LoopVectorizationLegality.cpp   | 23 +++++--
 4 files changed, 90 insertions(+), 22 deletions(-)

diff --git a/llvm/include/llvm/Analysis/LoopAccessAnalysis.h b/llvm/include/llvm/Analysis/LoopAccessAnalysis.h
index 902f76496eede..d76790b72e2f8 100644
--- a/llvm/include/llvm/Analysis/LoopAccessAnalysis.h
+++ b/llvm/include/llvm/Analysis/LoopAccessAnalysis.h
@@ -896,8 +896,18 @@ getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr,
              const Loop *Lp, const DominatorTree &DT,
              const DenseMap<Value *, const SCEV *> &StridesMap =
                  DenseMap<Value *, const SCEV *>(),
-             bool Assume = false, bool ShouldCheckWrap = true,
-             bool AllowStridedPtrs = false);
+             bool Assume = false, bool ShouldCheckWrap = true);
+
+/// This method will check if the ptr is making use of a runtime constant to
+/// calculate the stride i.e. A[stride * multiplier] with multiplier defined at
+/// runtime. In the case that the stride is of the form stride * multiplier,
+/// this method will return a pair of the base stride and the multiplier SCEV.
+LLVM_ABI std::optional<int64_t>
+getPtrConstRuntimeStride(PredicatedScalarEvolution &PSE, Type *AccessTy,
+             Value *Ptr, const Loop *Lp, const DominatorTree &DT,
+             const DenseMap<Value *, const SCEV *> &StridesMap =
+                 DenseMap<Value *, const SCEV *>(),
+             bool Assume = false);
 
 /// Returns the distance between the pointers \p PtrA and \p PtrB iff they are
 /// compatible and it is possible to calculate the distance between them. This
diff --git a/llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h b/llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
index f82fc588639dd..9136782d97acb 100644
--- a/llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
+++ b/llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
@@ -378,6 +378,16 @@ class LoopVectorizationLegality {
   /// loop. Do not use after invoking 'createVectorizedLoopSkeleton' (PR34965).
   int isConsecutivePtr(Type *AccessTy, Value *Ptr) const;
 
+
+  // Check is this pointer is const runtime strided when vectorizing.
+  // This occurs for pointers that have an access pattern such as
+  //
+  // A[offset + stride * runtime_constant]
+  //
+  // This check allows us to vectorize these into a wide load/store when
+  // `lv-strided-pointer-ivs=true` is true.
+  bool isConstRuntimeStridedPtr(Type *AccessTy, Value *Ptr) const;
+
   /// Returns true if \p V is invariant across all loop iterations according to
   /// SCEV.
   bool isInvariant(Value *V) const;
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index a8e2ee647269a..1be961bd928ed 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -964,8 +964,8 @@ class AccessAnalysis {
 
 } // end anonymous namespace
 
-/// Try to compute a constant stride for \p AR. Used by getPtrStride and
-/// isNoWrap.
+/// Try to compute a constant stride for \p AR. Used by getPtrStride,
+/// getPtrConstRuntimeStride and isNoWrap.
 static std::optional<int64_t>
 getStrideFromAddRec(const SCEVAddRecExpr *AR, const Loop *Lp, Type *AccessTy,
                     Value *Ptr, PredicatedScalarEvolution &PSE,
@@ -988,21 +988,18 @@ getStrideFromAddRec(const SCEVAddRecExpr *AR, const Loop *Lp, Type *AccessTy,
     return std::nullopt;
   }
 
-  // Calculate the pointer stride and check if it is constant.
-  // If we allow strided pointers we also check the add recurrence
-  // expression is making use of loop-invariant
-  // runtime constant for example
+  // Calculate the pointer stride and check if it is constant. If we allow
+  // strided pointers we also check the add recurrence expression is making use
+  // of loop-invariant runtime constant for example
   //
   // Step = { stride * runtime_constant }
   //
-  // we should treat this as a constant add recurrence.
-  // To achieve this we check the arguments of
-  // the step are loop invariant and compute the step
-  // as equivalent to just stride.
+  // we should treat this as a constant add recurrence. To achieve this we check
+  // the arguments of the step are loop invariant and compute the step as
+  // equivalent to just stride.
   //
-  // We only check this for mul expressions as these
-  // are most common and expected for strided
-  // pointer recurrence expressions.
+  // We only check this for mul expressions as these are most common and
+  // expected for strided pointer recurrence expressions.
   const SCEV *Step = AR->getStepRecurrence(*PSE.getSE());
   const APInt *APStepVal;
   auto IsInvariantConstAddRecStep = [&](const SCEV *Step) -> bool {
@@ -1013,10 +1010,14 @@ getStrideFromAddRec(const SCEVAddRecExpr *AR, const Loop *Lp, Type *AccessTy,
       return true;
 
     if (AllowStridedPtrs) {
+      if (PSE.getSE()->isKnownNegative(Step))
+        return false;
+
       for (const auto *Op : Step->operands()) {
         if (!PSE.getSE()->isLoopInvariant(Op, Lp))
           return false;
       }
+
       return match(Step,
                    m_scev_c_Mul(m_scev_APInt(APStepVal), m_SCEV(Multiplier)));
     }
@@ -1657,7 +1658,7 @@ std::optional<int64_t>
 llvm::getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr,
                    const Loop *Lp, const DominatorTree &DT,
                    const DenseMap<Value *, const SCEV *> &StridesMap,
-                   bool Assume, bool ShouldCheckWrap, bool AllowStridedPtrs) {
+                   bool Assume, bool ShouldCheckWrap) {
   const SCEV *PtrScev = replaceSymbolicStrideSCEV(PSE, StridesMap, Ptr);
   if (PSE.getSE()->isLoopInvariant(PtrScev, Lp))
     return 0;
@@ -1675,7 +1676,7 @@ llvm::getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr,
   }
 
   std::optional<int64_t> Stride =
-      getStrideFromAddRec(AR, Lp, AccessTy, Ptr, PSE, AllowStridedPtrs);
+      getStrideFromAddRec(AR, Lp, AccessTy, Ptr, PSE);
   if (!ShouldCheckWrap || !Stride)
     return Stride;
 
@@ -1688,6 +1689,40 @@ llvm::getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr,
   return std::nullopt;
 }
 
+/// Check whether the access through \p Ptr has a constant runtime stride
+std::optional<int64_t> llvm::getPtrConstRuntimeStride(
+    PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr, const Loop *Lp,
+    const DominatorTree &DT, const DenseMap<Value *, const SCEV *> &StridesMap,
+    bool Assume) {
+  const SCEV *PtrScev = replaceSymbolicStrideSCEV(PSE, StridesMap, Ptr);
+  if (PSE.getSE()->isLoopInvariant(PtrScev, Lp))
+    return 0;
+
+  assert(Ptr->getType()->isPointerTy() && "Unexpected non-ptr");
+
+  const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(PtrScev);
+  if (Assume && !AR)
+    AR = PSE.getAsAddRec(Ptr);
+
+  if (!AR) {
+    LLVM_DEBUG(dbgs() << "LAA: Bad stride - Not an AddRecExpr pointer " << *Ptr
+                      << " SCEV: " << *PtrScev << "\n");
+    return std::nullopt;
+  }
+
+  std::optional<int64_t> Stride = getStrideFromAddRec(
+      AR, Lp, AccessTy, Ptr, PSE, /* AllowStridedPtrs =*/true);
+
+  if (!Stride) {
+    LLVM_DEBUG(
+        dbgs() << "LAA: Bad stride - Pointer isn't runtime const strided "
+               << *Ptr << " SCEV: " << *AR << "\n");
+    return std::nullopt;
+  }
+
+  return Stride;
+}
+
 std::optional<int64_t> llvm::getPointersDiff(Type *ElemTyA, Value *PtrA,
                                              Type *ElemTyB, Value *PtrB,
                                              const DataLayout &DL,
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
index effb2a6f7ccf5..14204792c22b9 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
@@ -481,15 +481,29 @@ int LoopVectorizationLegality::isConsecutivePtr(Type *AccessTy,
   const auto &Strides =
     LAI ? LAI->getSymbolicStrides() : DenseMap<Value *, const SCEV *>();
 
-  int Stride =
-      getPtrStride(PSE, AccessTy, Ptr, TheLoop, *DT, Strides,
-                   AllowRuntimeSCEVChecks, false, AllowStridedPointerIVs)
-          .value_or(0);
+  int Stride = getPtrStride(PSE, AccessTy, Ptr, TheLoop, *DT, Strides,
+                            AllowRuntimeSCEVChecks, false)
+                   .value_or(0);
   if (Stride == 1 || Stride == -1)
     return Stride;
   return 0;
 }
 
+bool LoopVectorizationLegality::isConstRuntimeStridedPtr(Type *AccessTy,
+                                                         Value *Ptr) const {
+  if (!AllowStridedPointerIVs)
+    return false;
+
+  const auto &Strides =
+      LAI ? LAI->getSymbolicStrides() : DenseMap<Value *, const SCEV *>();
+
+  int Stride = getPtrConstRuntimeStride(PSE, AccessTy, Ptr, TheLoop, *DT,
+                                        Strides, AllowRuntimeSCEVChecks)
+                   .value_or(0);
+
+  return Stride;
+}
+
 bool LoopVectorizationLegality::isInvariant(Value *V) const {
   return LAI->isInvariant(V);
 }
@@ -1712,7 +1726,6 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
         "RecurrencesInEarlyExitLoop", ORE, TheLoop);
     return false;
   }
-
   SmallVector<BasicBlock *, 8> ExitingBlocks;
   TheLoop->getExitingBlocks(ExitingBlocks);
 

>From 1fd3f1191bb930e8d06140fd7cef1de7381cce12 Mon Sep 17 00:00:00 2001
From: nasmnc01 <nashe.mncube at arm.com>
Date: Thu, 22 Jan 2026 15:12:11 +0000
Subject: [PATCH 7/7] Plugging use of runtime const stride helpers into
 vectorizer

- makes use of new LAA methods
- adds changes to LV cost model decision code to allow for widening
  or gather/scatter.

Change-Id: I108ad4a995d54f7f40b84ba8abdc362cc6681125
---
 .../Vectorize/LoopVectorizationLegality.h     |   6 +-
 llvm/lib/Analysis/LoopAccessAnalysis.cpp      |  18 +-
 .../Vectorize/LoopVectorizationLegality.cpp   |   6 +-
 .../Transforms/Vectorize/LoopVectorize.cpp    |  59 ++++-
 .../LoopVectorize/RISCV/strided-accesses.ll   | 221 +++++++++++-------
 .../LoopVectorize/pointer-induction.ll        |  19 +-
 .../LoopVectorize/scev-predicate-reasoning.ll |  11 +-
 7 files changed, 238 insertions(+), 102 deletions(-)

diff --git a/llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h b/llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
index 9136782d97acb..7116ad017c72a 100644
--- a/llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
+++ b/llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
@@ -379,14 +379,14 @@ class LoopVectorizationLegality {
   int isConsecutivePtr(Type *AccessTy, Value *Ptr) const;
 
 
-  // Check is this pointer is const runtime strided when vectorizing.
+  // Check if this pointer is const runtime strided when vectorizing.
   // This occurs for pointers that have an access pattern such as
   //
   // A[offset + stride * runtime_constant]
   //
   // This check allows us to vectorize these into a wide load/store when
-  // `lv-strided-pointer-ivs=true` is true.
-  bool isConstRuntimeStridedPtr(Type *AccessTy, Value *Ptr) const;
+  // `lv-strided-pointer-ivs=true`
+  int isConstRuntimeStridedPtr(Type *AccessTy, Value *Ptr) const;
 
   /// Returns true if \p V is invariant across all loop iterations according to
   /// SCEV.
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index 1be961bd928ed..afabb8b68d93f 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -1693,7 +1693,11 @@ llvm::getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr,
 std::optional<int64_t> llvm::getPtrConstRuntimeStride(
     PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr, const Loop *Lp,
     const DominatorTree &DT, const DenseMap<Value *, const SCEV *> &StridesMap,
-    bool Assume) {
+    bool AllowRuntimeSCEVChecks) {
+  // Require runtime checks to ensure correctness of runtime stride
+  if (!AllowRuntimeSCEVChecks)
+    return std::nullopt;
+
   const SCEV *PtrScev = replaceSymbolicStrideSCEV(PSE, StridesMap, Ptr);
   if (PSE.getSE()->isLoopInvariant(PtrScev, Lp))
     return 0;
@@ -1701,7 +1705,7 @@ std::optional<int64_t> llvm::getPtrConstRuntimeStride(
   assert(Ptr->getType()->isPointerTy() && "Unexpected non-ptr");
 
   const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(PtrScev);
-  if (Assume && !AR)
+  if (AllowRuntimeSCEVChecks && !AR)
     AR = PSE.getAsAddRec(Ptr);
 
   if (!AR) {
@@ -1720,6 +1724,16 @@ std::optional<int64_t> llvm::getPtrConstRuntimeStride(
     return std::nullopt;
   }
 
+  // Add runtime SCEV check for multiplier
+  const SCEV *Step = AR->getStepRecurrence(*PSE.getSE());
+  const APInt *APStepVal;
+  const SCEV *Multiplier;
+  if (match(Step, m_scev_c_Mul(m_scev_APInt(APStepVal), m_SCEV(Multiplier)))) {
+    const SCEV *One = PSE.getSE()->getOne(Multiplier->getType());
+    PSE.addPredicate(
+        *PSE.getSE()->getComparePredicate(CmpInst::ICMP_EQ, Multiplier, One));
+  }
+
   return Stride;
 }
 
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
index 14204792c22b9..c7471a8928b66 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
@@ -489,10 +489,10 @@ int LoopVectorizationLegality::isConsecutivePtr(Type *AccessTy,
   return 0;
 }
 
-bool LoopVectorizationLegality::isConstRuntimeStridedPtr(Type *AccessTy,
-                                                         Value *Ptr) const {
+int LoopVectorizationLegality::isConstRuntimeStridedPtr(Type *AccessTy,
+                                                        Value *Ptr) const {
   if (!AllowStridedPointerIVs)
-    return false;
+    return 0;
 
   const auto &Strides =
       LAI ? LAI->getSymbolicStrides() : DenseMap<Value *, const SCEV *>();
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 0811628fd56b3..d7e939e0f5f2a 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -1255,6 +1255,10 @@ class LoopVectorizationCostModel {
   /// access that can be widened.
   bool memoryInstructionCanBeWidened(Instruction *I, ElementCount VF);
 
+  // Returns true if \p is a memory instruction with strided memory access that
+  // can be widened.
+  bool stridedMemoryAccessCanBeWidened(Instruction *I, ElementCount VF);
+
   /// Returns true if \p I is a memory instruction in an interleaved-group
   /// of memory accesses that can be vectorized with wide vector loads/stores
   /// and shuffles.
@@ -1543,7 +1547,8 @@ class LoopVectorizationCostModel {
 
   /// The cost computation for widening instruction \p I with consecutive
   /// memory access.
-  InstructionCost getConsecutiveMemOpCost(Instruction *I, ElementCount VF);
+  InstructionCost getConsecutiveMemOpCost(Instruction *I, ElementCount VF,
+                                          bool IsRuntimeConstStrided = false);
 
   /// The cost calculation for Load/Store instruction \p I with uniform pointer -
   /// Load: scalar load + broadcast.
@@ -3091,6 +3096,32 @@ bool LoopVectorizationCostModel::memoryInstructionCanBeWidened(
   return true;
 }
 
+bool LoopVectorizationCostModel::stridedMemoryAccessCanBeWidened(
+    Instruction *I, ElementCount VF) {
+  // Get and ensure we have a valid memory instruction.
+  assert((isa<LoadInst, StoreInst>(I)) && "Invalid memory instruction");
+
+  auto *Ptr = getLoadStorePointerOperand(I);
+  auto *ScalarTy = getLoadStoreType(I);
+
+  // In order to be widened, the pointer should be consecutive, first of all.
+  if (!Legal->isConstRuntimeStridedPtr(ScalarTy, Ptr))
+    return false;
+
+  // If the instruction is a store located in a predicated block, it will be
+  // scalarized.
+  if (isScalarWithPredication(I, VF))
+    return false;
+
+  // If the instruction's allocated size doesn't equal it's type size, it
+  // requires padding and will be scalarized.
+  auto &DL = I->getDataLayout();
+  if (hasIrregularType(ScalarTy, DL))
+    return false;
+
+  return true;
+}
+
 void LoopVectorizationCostModel::collectLoopUniforms(ElementCount VF) {
   // We should not collect Uniforms more than once per VF. Right now,
   // this function is called from collectUniformsAndScalars(), which
@@ -5302,15 +5333,18 @@ LoopVectorizationCostModel::getMemInstScalarizationCost(Instruction *I,
   return Cost;
 }
 
-InstructionCost
-LoopVectorizationCostModel::getConsecutiveMemOpCost(Instruction *I,
-                                                    ElementCount VF) {
+InstructionCost LoopVectorizationCostModel::getConsecutiveMemOpCost(
+    Instruction *I, ElementCount VF, bool IsRuntimeConstStrided) {
   Type *ValTy = getLoadStoreType(I);
   auto *VectorTy = cast<VectorType>(toVectorTy(ValTy, VF));
   Value *Ptr = getLoadStorePointerOperand(I);
   unsigned AS = getLoadStoreAddressSpace(I);
   int ConsecutiveStride = Legal->isConsecutivePtr(ValTy, Ptr);
 
+  ConsecutiveStride = (!ConsecutiveStride && IsRuntimeConstStrided)
+                          ? Legal->isConstRuntimeStridedPtr(ValTy, Ptr)
+                          : ConsecutiveStride;
+
   assert((ConsecutiveStride == 1 || ConsecutiveStride == -1) &&
          "Stride should be 1 or -1 for consecutive memory access");
   const Align Alignment = getLoadStoreAlignment(I);
@@ -5753,6 +5787,23 @@ void LoopVectorizationCostModel::setCostBasedWideningDecision(ElementCount VF) {
             ConsecutiveStride == 1 ? CM_Widen : CM_Widen_Reverse;
         setWideningDecision(&I, VF, Decision, Cost);
         continue;
+      } else if (stridedMemoryAccessCanBeWidened(&I, VF)) {
+        int BaseStride = Legal->isConstRuntimeStridedPtr(
+            getLoadStoreType(&I), getLoadStorePointerOperand(&I));
+        assert((BaseStride >= 1) && "Expected base stride to be >= 1");
+
+        // For base strides greater than 1 we should default to
+        // gather/scatters
+        InstructionCost Cost;
+        if (BaseStride == 1) {
+          Cost = getConsecutiveMemOpCost(&I, VF, true);
+          setWideningDecision(&I, VF, CM_Widen, Cost);
+        } else {
+          Cost = isLegalGatherOrScatter(&I, VF) ? getGatherScatterCost(&I, VF)
+                                                : InstructionCost::getInvalid();
+          setWideningDecision(&I, VF, CM_GatherScatter, Cost);
+        }
+        continue;
       }
 
       // Choose between Interleaving, Gather/Scatter or Scalarization.
diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/strided-accesses.ll b/llvm/test/Transforms/LoopVectorize/RISCV/strided-accesses.ll
index 2bef1e50317de..9d641cc08a18c 100644
--- a/llvm/test/Transforms/LoopVectorize/RISCV/strided-accesses.ll
+++ b/llvm/test/Transforms/LoopVectorize/RISCV/strided-accesses.ll
@@ -237,68 +237,125 @@ define void @single_constant_stride_ptr_iv(ptr %p) {
 ; CHECK:       exit:
 ; CHECK-NEXT:    ret void
 ;
-; CHECK-UF2-LABEL: @single_constant_stride_ptr_iv(
-; CHECK-UF2-NEXT:  entry:
-; CHECK-UF2-NEXT:    [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
-; CHECK-UF2-NEXT:    [[TMP1:%.*]] = shl nuw i64 [[TMP0]], 3
-; CHECK-UF2-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ule i64 1024, [[TMP1]]
-; CHECK-UF2-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
-; CHECK-UF2:       vector.ph:
-; CHECK-UF2-NEXT:    [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
-; CHECK-UF2-NEXT:    [[TMP3:%.*]] = shl nuw i64 [[TMP2]], 2
-; CHECK-UF2-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 4 x i64> poison, i64 [[TMP3]], i64 0
-; CHECK-UF2-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 4 x i64> [[BROADCAST_SPLATINSERT]], <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer
-; CHECK-UF2-NEXT:    [[TMP4:%.*]] = shl nuw i64 [[TMP3]], 1
-; CHECK-UF2-NEXT:    [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP4]]
-; CHECK-UF2-NEXT:    [[TMP5:%.*]] = icmp eq i64 [[N_MOD_VF]], 0
-; CHECK-UF2-NEXT:    [[TMP6:%.*]] = select i1 [[TMP5]], i64 [[TMP4]], i64 [[N_MOD_VF]]
-; CHECK-UF2-NEXT:    [[N_VEC:%.*]] = sub i64 1024, [[TMP6]]
-; CHECK-UF2-NEXT:    [[TMP7:%.*]] = mul i64 [[N_VEC]], 8
-; CHECK-UF2-NEXT:    [[TMP8:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 [[TMP7]]
-; CHECK-UF2-NEXT:    [[TMP9:%.*]] = shl <vscale x 4 x i64> [[BROADCAST_SPLAT]], splat (i64 3)
-; CHECK-UF2-NEXT:    br label [[VECTOR_BODY:%.*]]
-; CHECK-UF2:       vector.body:
-; CHECK-UF2-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
-; CHECK-UF2-NEXT:    [[POINTER_PHI:%.*]] = phi ptr [ [[P]], [[VECTOR_PH]] ], [ [[PTR_IND:%.*]], [[VECTOR_BODY]] ]
-; CHECK-UF2-NEXT:    [[TMP10:%.*]] = call <vscale x 4 x i64> @llvm.stepvector.nxv4i64()
-; CHECK-UF2-NEXT:    [[TMP11:%.*]] = shl <vscale x 4 x i64> [[TMP10]], splat (i64 3)
-; CHECK-UF2-NEXT:    [[VECTOR_GEP:%.*]] = getelementptr i8, ptr [[POINTER_PHI]], <vscale x 4 x i64> [[TMP11]]
-; CHECK-UF2-NEXT:    [[TMP12:%.*]] = extractelement <vscale x 4 x ptr> [[VECTOR_GEP]], i32 0
-; CHECK-UF2-NEXT:    [[STEP_ADD:%.*]] = getelementptr i8, <vscale x 4 x ptr> [[VECTOR_GEP]], <vscale x 4 x i64> [[TMP9]]
-; CHECK-UF2-NEXT:    [[WIDE_VEC:%.*]] = load <vscale x 8 x i32>, ptr [[TMP12]], align 4
-; CHECK-UF2-NEXT:    [[STRIDED_VEC:%.*]] = call { <vscale x 4 x i32>, <vscale x 4 x i32> } @llvm.vector.deinterleave2.nxv8i32(<vscale x 8 x i32> [[WIDE_VEC]])
-; CHECK-UF2-NEXT:    [[TMP13:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[STRIDED_VEC]], 0
-; CHECK-UF2-NEXT:    [[TMP14:%.*]] = extractelement <vscale x 4 x ptr> [[STEP_ADD]], i32 0
-; CHECK-UF2-NEXT:    [[WIDE_VEC1:%.*]] = load <vscale x 8 x i32>, ptr [[TMP14]], align 4
-; CHECK-UF2-NEXT:    [[STRIDED_VEC2:%.*]] = call { <vscale x 4 x i32>, <vscale x 4 x i32> } @llvm.vector.deinterleave2.nxv8i32(<vscale x 8 x i32> [[WIDE_VEC1]])
-; CHECK-UF2-NEXT:    [[TMP15:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[STRIDED_VEC2]], 0
-; CHECK-UF2-NEXT:    [[TMP16:%.*]] = add <vscale x 4 x i32> [[TMP13]], splat (i32 1)
-; CHECK-UF2-NEXT:    [[TMP17:%.*]] = add <vscale x 4 x i32> [[TMP15]], splat (i32 1)
-; CHECK-UF2-NEXT:    call void @llvm.masked.scatter.nxv4i32.nxv4p0(<vscale x 4 x i32> [[TMP16]], <vscale x 4 x ptr> align 4 [[VECTOR_GEP]], <vscale x 4 x i1> splat (i1 true))
-; CHECK-UF2-NEXT:    call void @llvm.masked.scatter.nxv4i32.nxv4p0(<vscale x 4 x i32> [[TMP17]], <vscale x 4 x ptr> align 4 [[STEP_ADD]], <vscale x 4 x i1> splat (i1 true))
-; CHECK-UF2-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP4]]
-; CHECK-UF2-NEXT:    [[TMP18:%.*]] = shl i64 [[TMP4]], 3
-; CHECK-UF2-NEXT:    [[PTR_IND]] = getelementptr i8, ptr [[POINTER_PHI]], i64 [[TMP18]]
-; CHECK-UF2-NEXT:    [[TMP19:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
-; CHECK-UF2-NEXT:    br i1 [[TMP19]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP6:![0-9]+]]
-; CHECK-UF2:       middle.block:
-; CHECK-UF2-NEXT:    br label [[SCALAR_PH]]
-; CHECK-UF2:       scalar.ph:
-; CHECK-UF2-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
-; CHECK-UF2-NEXT:    [[BC_RESUME_VAL3:%.*]] = phi ptr [ [[TMP8]], [[MIDDLE_BLOCK]] ], [ [[P]], [[ENTRY]] ]
-; CHECK-UF2-NEXT:    br label [[LOOP:%.*]]
-; CHECK-UF2:       loop:
-; CHECK-UF2-NEXT:    [[I:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[NEXTI:%.*]], [[LOOP]] ]
-; CHECK-UF2-NEXT:    [[PTR:%.*]] = phi ptr [ [[BC_RESUME_VAL3]], [[SCALAR_PH]] ], [ [[PTR_NEXT:%.*]], [[LOOP]] ]
-; CHECK-UF2-NEXT:    [[X0:%.*]] = load i32, ptr [[PTR]], align 4
-; CHECK-UF2-NEXT:    [[Y0:%.*]] = add i32 [[X0]], 1
-; CHECK-UF2-NEXT:    store i32 [[Y0]], ptr [[PTR]], align 4
-; CHECK-UF2-NEXT:    [[PTR_NEXT]] = getelementptr inbounds i8, ptr [[PTR]], i64 8
-; CHECK-UF2-NEXT:    [[NEXTI]] = add i64 [[I]], 1
-; CHECK-UF2-NEXT:    [[DONE:%.*]] = icmp eq i64 [[NEXTI]], 1024
-; CHECK-UF2-NEXT:    br i1 [[DONE]], label [[EXIT:%.*]], label [[LOOP]], !llvm.loop [[LOOP7:![0-9]+]]
-; CHECK-UF2:       exit:
-; CHECK-UF2-NEXT:    ret void
+; NOSTRIDED-UF2-LABEL: @single_constant_stride_ptr_iv(
+; NOSTRIDED-UF2-NEXT:  entry:
+; NOSTRIDED-UF2-NEXT:    [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
+; NOSTRIDED-UF2-NEXT:    [[TMP1:%.*]] = shl nuw i64 [[TMP0]], 3
+; NOSTRIDED-UF2-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ule i64 1024, [[TMP1]]
+; NOSTRIDED-UF2-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
+; NOSTRIDED-UF2:       vector.ph:
+; NOSTRIDED-UF2-NEXT:    [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
+; NOSTRIDED-UF2-NEXT:    [[TMP3:%.*]] = shl nuw i64 [[TMP2]], 2
+; NOSTRIDED-UF2-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 4 x i64> poison, i64 [[TMP3]], i64 0
+; NOSTRIDED-UF2-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 4 x i64> [[BROADCAST_SPLATINSERT]], <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer
+; NOSTRIDED-UF2-NEXT:    [[TMP4:%.*]] = shl nuw i64 [[TMP3]], 1
+; NOSTRIDED-UF2-NEXT:    [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP4]]
+; NOSTRIDED-UF2-NEXT:    [[TMP5:%.*]] = icmp eq i64 [[N_MOD_VF]], 0
+; NOSTRIDED-UF2-NEXT:    [[TMP6:%.*]] = select i1 [[TMP5]], i64 [[TMP4]], i64 [[N_MOD_VF]]
+; NOSTRIDED-UF2-NEXT:    [[N_VEC:%.*]] = sub i64 1024, [[TMP6]]
+; NOSTRIDED-UF2-NEXT:    [[TMP7:%.*]] = mul i64 [[N_VEC]], 8
+; NOSTRIDED-UF2-NEXT:    [[TMP8:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 [[TMP7]]
+; NOSTRIDED-UF2-NEXT:    [[TMP9:%.*]] = shl <vscale x 4 x i64> [[BROADCAST_SPLAT]], splat (i64 3)
+; NOSTRIDED-UF2-NEXT:    br label [[VECTOR_BODY:%.*]]
+; NOSTRIDED-UF2:       vector.body:
+; NOSTRIDED-UF2-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
+; NOSTRIDED-UF2-NEXT:    [[POINTER_PHI:%.*]] = phi ptr [ [[P]], [[VECTOR_PH]] ], [ [[PTR_IND:%.*]], [[VECTOR_BODY]] ]
+; NOSTRIDED-UF2-NEXT:    [[TMP10:%.*]] = call <vscale x 4 x i64> @llvm.stepvector.nxv4i64()
+; NOSTRIDED-UF2-NEXT:    [[TMP11:%.*]] = shl <vscale x 4 x i64> [[TMP10]], splat (i64 3)
+; NOSTRIDED-UF2-NEXT:    [[VECTOR_GEP:%.*]] = getelementptr i8, ptr [[POINTER_PHI]], <vscale x 4 x i64> [[TMP11]]
+; NOSTRIDED-UF2-NEXT:    [[TMP12:%.*]] = extractelement <vscale x 4 x ptr> [[VECTOR_GEP]], i32 0
+; NOSTRIDED-UF2-NEXT:    [[STEP_ADD:%.*]] = getelementptr i8, <vscale x 4 x ptr> [[VECTOR_GEP]], <vscale x 4 x i64> [[TMP9]]
+; NOSTRIDED-UF2-NEXT:    [[WIDE_VEC:%.*]] = load <vscale x 8 x i32>, ptr [[TMP12]], align 4
+; NOSTRIDED-UF2-NEXT:    [[STRIDED_VEC:%.*]] = call { <vscale x 4 x i32>, <vscale x 4 x i32> } @llvm.vector.deinterleave2.nxv8i32(<vscale x 8 x i32> [[WIDE_VEC]])
+; NOSTRIDED-UF2-NEXT:    [[TMP13:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[STRIDED_VEC]], 0
+; NOSTRIDED-UF2-NEXT:    [[TMP14:%.*]] = extractelement <vscale x 4 x ptr> [[STEP_ADD]], i32 0
+; NOSTRIDED-UF2-NEXT:    [[WIDE_VEC1:%.*]] = load <vscale x 8 x i32>, ptr [[TMP14]], align 4
+; NOSTRIDED-UF2-NEXT:    [[STRIDED_VEC2:%.*]] = call { <vscale x 4 x i32>, <vscale x 4 x i32> } @llvm.vector.deinterleave2.nxv8i32(<vscale x 8 x i32> [[WIDE_VEC1]])
+; NOSTRIDED-UF2-NEXT:    [[TMP15:%.*]] = extractvalue { <vscale x 4 x i32>, <vscale x 4 x i32> } [[STRIDED_VEC2]], 0
+; NOSTRIDED-UF2-NEXT:    [[TMP16:%.*]] = add <vscale x 4 x i32> [[TMP13]], splat (i32 1)
+; NOSTRIDED-UF2-NEXT:    [[TMP17:%.*]] = add <vscale x 4 x i32> [[TMP15]], splat (i32 1)
+; NOSTRIDED-UF2-NEXT:    call void @llvm.masked.scatter.nxv4i32.nxv4p0(<vscale x 4 x i32> [[TMP16]], <vscale x 4 x ptr> align 4 [[VECTOR_GEP]], <vscale x 4 x i1> splat (i1 true))
+; NOSTRIDED-UF2-NEXT:    call void @llvm.masked.scatter.nxv4i32.nxv4p0(<vscale x 4 x i32> [[TMP17]], <vscale x 4 x ptr> align 4 [[STEP_ADD]], <vscale x 4 x i1> splat (i1 true))
+; NOSTRIDED-UF2-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP4]]
+; NOSTRIDED-UF2-NEXT:    [[TMP18:%.*]] = shl i64 [[TMP4]], 3
+; NOSTRIDED-UF2-NEXT:    [[PTR_IND]] = getelementptr i8, ptr [[POINTER_PHI]], i64 [[TMP18]]
+; NOSTRIDED-UF2-NEXT:    [[TMP19:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
+; NOSTRIDED-UF2-NEXT:    br i1 [[TMP19]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP6:![0-9]+]]
+; NOSTRIDED-UF2:       middle.block:
+; NOSTRIDED-UF2-NEXT:    br label [[SCALAR_PH]]
+; NOSTRIDED-UF2:       scalar.ph:
+; NOSTRIDED-UF2-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
+; NOSTRIDED-UF2-NEXT:    [[BC_RESUME_VAL3:%.*]] = phi ptr [ [[TMP8]], [[MIDDLE_BLOCK]] ], [ [[P]], [[ENTRY]] ]
+; NOSTRIDED-UF2-NEXT:    br label [[LOOP:%.*]]
+; NOSTRIDED-UF2:       loop:
+; NOSTRIDED-UF2-NEXT:    [[I:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[NEXTI:%.*]], [[LOOP]] ]
+; NOSTRIDED-UF2-NEXT:    [[PTR:%.*]] = phi ptr [ [[BC_RESUME_VAL3]], [[SCALAR_PH]] ], [ [[PTR_NEXT:%.*]], [[LOOP]] ]
+; NOSTRIDED-UF2-NEXT:    [[X0:%.*]] = load i32, ptr [[PTR]], align 4
+; NOSTRIDED-UF2-NEXT:    [[Y0:%.*]] = add i32 [[X0]], 1
+; NOSTRIDED-UF2-NEXT:    store i32 [[Y0]], ptr [[PTR]], align 4
+; NOSTRIDED-UF2-NEXT:    [[PTR_NEXT]] = getelementptr inbounds i8, ptr [[PTR]], i64 8
+; NOSTRIDED-UF2-NEXT:    [[NEXTI]] = add i64 [[I]], 1
+; NOSTRIDED-UF2-NEXT:    [[DONE:%.*]] = icmp eq i64 [[NEXTI]], 1024
+; NOSTRIDED-UF2-NEXT:    br i1 [[DONE]], label [[EXIT:%.*]], label [[LOOP]], !llvm.loop [[LOOP7:![0-9]+]]
+; NOSTRIDED-UF2:       exit:
+; NOSTRIDED-UF2-NEXT:    ret void
+;
+; STRIDED-UF2-LABEL: @single_constant_stride_ptr_iv(
+; STRIDED-UF2-NEXT:  entry:
+; STRIDED-UF2-NEXT:    [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
+; STRIDED-UF2-NEXT:    [[TMP1:%.*]] = shl nuw i64 [[TMP0]], 3
+; STRIDED-UF2-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ule i64 1024, [[TMP1]]
+; STRIDED-UF2-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
+; STRIDED-UF2:       vector.ph:
+; STRIDED-UF2-NEXT:    [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
+; STRIDED-UF2-NEXT:    [[TMP3:%.*]] = shl nuw i64 [[TMP2]], 2
+; STRIDED-UF2-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 4 x i64> poison, i64 [[TMP3]], i64 0
+; STRIDED-UF2-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 4 x i64> [[BROADCAST_SPLATINSERT]], <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer
+; STRIDED-UF2-NEXT:    [[TMP4:%.*]] = shl nuw i64 [[TMP3]], 1
+; STRIDED-UF2-NEXT:    [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP4]]
+; STRIDED-UF2-NEXT:    [[TMP5:%.*]] = icmp eq i64 [[N_MOD_VF]], 0
+; STRIDED-UF2-NEXT:    [[TMP6:%.*]] = select i1 [[TMP5]], i64 [[TMP4]], i64 [[N_MOD_VF]]
+; STRIDED-UF2-NEXT:    [[N_VEC:%.*]] = sub i64 1024, [[TMP6]]
+; STRIDED-UF2-NEXT:    [[TMP7:%.*]] = mul i64 [[N_VEC]], 8
+; STRIDED-UF2-NEXT:    [[TMP8:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 [[TMP7]]
+; STRIDED-UF2-NEXT:    [[TMP9:%.*]] = shl <vscale x 4 x i64> [[BROADCAST_SPLAT]], splat (i64 3)
+; STRIDED-UF2-NEXT:    br label [[VECTOR_BODY:%.*]]
+; STRIDED-UF2:       vector.body:
+; STRIDED-UF2-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
+; STRIDED-UF2-NEXT:    [[POINTER_PHI:%.*]] = phi ptr [ [[P]], [[VECTOR_PH]] ], [ [[PTR_IND:%.*]], [[VECTOR_BODY]] ]
+; STRIDED-UF2-NEXT:    [[TMP10:%.*]] = call <vscale x 4 x i64> @llvm.stepvector.nxv4i64()
+; STRIDED-UF2-NEXT:    [[TMP11:%.*]] = shl <vscale x 4 x i64> [[TMP10]], splat (i64 3)
+; STRIDED-UF2-NEXT:    [[VECTOR_GEP:%.*]] = getelementptr i8, ptr [[POINTER_PHI]], <vscale x 4 x i64> [[TMP11]]
+; STRIDED-UF2-NEXT:    [[STEP_ADD:%.*]] = getelementptr i8, <vscale x 4 x ptr> [[VECTOR_GEP]], <vscale x 4 x i64> [[TMP9]]
+; STRIDED-UF2-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 4 x i32> @llvm.masked.gather.nxv4i32.nxv4p0(<vscale x 4 x ptr> align 4 [[VECTOR_GEP]], <vscale x 4 x i1> splat (i1 true), <vscale x 4 x i32> poison)
+; STRIDED-UF2-NEXT:    [[WIDE_MASKED_GATHER1:%.*]] = call <vscale x 4 x i32> @llvm.masked.gather.nxv4i32.nxv4p0(<vscale x 4 x ptr> align 4 [[STEP_ADD]], <vscale x 4 x i1> splat (i1 true), <vscale x 4 x i32> poison)
+; STRIDED-UF2-NEXT:    [[TMP12:%.*]] = add <vscale x 4 x i32> [[WIDE_MASKED_GATHER]], splat (i32 1)
+; STRIDED-UF2-NEXT:    [[TMP13:%.*]] = add <vscale x 4 x i32> [[WIDE_MASKED_GATHER1]], splat (i32 1)
+; STRIDED-UF2-NEXT:    call void @llvm.masked.scatter.nxv4i32.nxv4p0(<vscale x 4 x i32> [[TMP12]], <vscale x 4 x ptr> align 4 [[VECTOR_GEP]], <vscale x 4 x i1> splat (i1 true))
+; STRIDED-UF2-NEXT:    call void @llvm.masked.scatter.nxv4i32.nxv4p0(<vscale x 4 x i32> [[TMP13]], <vscale x 4 x ptr> align 4 [[STEP_ADD]], <vscale x 4 x i1> splat (i1 true))
+; STRIDED-UF2-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP4]]
+; STRIDED-UF2-NEXT:    [[TMP14:%.*]] = shl i64 [[TMP4]], 3
+; STRIDED-UF2-NEXT:    [[PTR_IND]] = getelementptr i8, ptr [[POINTER_PHI]], i64 [[TMP14]]
+; STRIDED-UF2-NEXT:    [[TMP15:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
+; STRIDED-UF2-NEXT:    br i1 [[TMP15]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP6:![0-9]+]]
+; STRIDED-UF2:       middle.block:
+; STRIDED-UF2-NEXT:    br label [[SCALAR_PH]]
+; STRIDED-UF2:       scalar.ph:
+; STRIDED-UF2-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
+; STRIDED-UF2-NEXT:    [[BC_RESUME_VAL2:%.*]] = phi ptr [ [[TMP8]], [[MIDDLE_BLOCK]] ], [ [[P]], [[ENTRY]] ]
+; STRIDED-UF2-NEXT:    br label [[LOOP:%.*]]
+; STRIDED-UF2:       loop:
+; STRIDED-UF2-NEXT:    [[I:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[NEXTI:%.*]], [[LOOP]] ]
+; STRIDED-UF2-NEXT:    [[PTR:%.*]] = phi ptr [ [[BC_RESUME_VAL2]], [[SCALAR_PH]] ], [ [[PTR_NEXT:%.*]], [[LOOP]] ]
+; STRIDED-UF2-NEXT:    [[X0:%.*]] = load i32, ptr [[PTR]], align 4
+; STRIDED-UF2-NEXT:    [[Y0:%.*]] = add i32 [[X0]], 1
+; STRIDED-UF2-NEXT:    store i32 [[Y0]], ptr [[PTR]], align 4
+; STRIDED-UF2-NEXT:    [[PTR_NEXT]] = getelementptr inbounds i8, ptr [[PTR]], i64 8
+; STRIDED-UF2-NEXT:    [[NEXTI]] = add i64 [[I]], 1
+; STRIDED-UF2-NEXT:    [[DONE:%.*]] = icmp eq i64 [[NEXTI]], 1024
+; STRIDED-UF2-NEXT:    br i1 [[DONE]], label [[EXIT:%.*]], label [[LOOP]], !llvm.loop [[LOOP7:![0-9]+]]
+; STRIDED-UF2:       exit:
+; STRIDED-UF2-NEXT:    ret void
 ;
 entry:
   br label %loop
@@ -743,8 +800,10 @@ define void @double_stride_int_scaled(ptr %p, ptr %p2, i64 %stride) {
 ; STRIDED-NEXT:    [[TMP38:%.*]] = icmp ugt ptr [[TMP36]], [[P]]
 ; STRIDED-NEXT:    [[TMP39:%.*]] = select i1 [[TMP34]], i1 [[TMP38]], i1 [[TMP37]]
 ; STRIDED-NEXT:    [[TMP40:%.*]] = or i1 [[TMP39]], [[MUL_OVERFLOW3]]
+; STRIDED-NEXT:    [[IDENT_CHECK:%.*]] = icmp ne i64 [[STRIDE]], 1
 ; STRIDED-NEXT:    [[TMP23:%.*]] = or i1 [[TMP13]], [[TMP40]]
-; STRIDED-NEXT:    br i1 [[TMP23]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK1:%.*]]
+; STRIDED-NEXT:    [[TMP21:%.*]] = or i1 [[TMP23]], [[IDENT_CHECK]]
+; STRIDED-NEXT:    br i1 [[TMP21]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK1:%.*]]
 ; STRIDED:       vector.memcheck:
 ; STRIDED-NEXT:    [[TMP3:%.*]] = mul i64 [[STRIDE]], 4092
 ; STRIDED-NEXT:    [[SCEVGEP:%.*]] = getelementptr i8, ptr [[P2]], i64 [[TMP3]]
@@ -772,9 +831,9 @@ define void @double_stride_int_scaled(ptr %p, ptr %p2, i64 %stride) {
 ; STRIDED-NEXT:    [[TMP42:%.*]] = mul nuw nsw i64 [[EVL_BASED_IV]], [[STRIDE]]
 ; STRIDED-NEXT:    [[TMP45:%.*]] = getelementptr i32, ptr [[P]], i64 [[TMP42]]
 ; STRIDED-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 4 x i32> @llvm.vp.load.nxv4i32.p0(ptr align 4 [[TMP45]], <vscale x 4 x i1> splat (i1 true), i32 [[TMP43]]), !alias.scope [[META5:![0-9]+]]
-; STRIDED-NEXT:    [[TMP20:%.*]] = add <vscale x 4 x i32> [[WIDE_MASKED_GATHER]], splat (i32 1)
+; STRIDED-NEXT:    [[TMP47:%.*]] = add <vscale x 4 x i32> [[WIDE_MASKED_GATHER]], splat (i32 1)
 ; STRIDED-NEXT:    [[TMP46:%.*]] = getelementptr i32, ptr [[P2]], i64 [[TMP42]]
-; STRIDED-NEXT:    call void @llvm.vp.store.nxv4i32.p0(<vscale x 4 x i32> [[TMP20]], ptr align 4 [[TMP46]], <vscale x 4 x i1> splat (i1 true), i32 [[TMP43]]), !alias.scope [[META8:![0-9]+]], !noalias [[META5]]
+; STRIDED-NEXT:    call void @llvm.vp.store.nxv4i32.p0(<vscale x 4 x i32> [[TMP47]], ptr align 4 [[TMP46]], <vscale x 4 x i1> splat (i1 true), i32 [[TMP43]]), !alias.scope [[META8:![0-9]+]], !noalias [[META5]]
 ; STRIDED-NEXT:    [[TMP44:%.*]] = zext i32 [[TMP43]] to i64
 ; STRIDED-NEXT:    [[INDEX_EVL_NEXT]] = add nuw i64 [[TMP44]], [[EVL_BASED_IV]]
 ; STRIDED-NEXT:    [[AVL_NEXT]] = sub nuw i64 [[AVL]], [[TMP44]]
@@ -803,7 +862,7 @@ define void @double_stride_int_scaled(ptr %p, ptr %p2, i64 %stride) {
 ; STRIDED-UF2-NEXT:  entry:
 ; STRIDED-UF2-NEXT:    [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
 ; STRIDED-UF2-NEXT:    [[TMP1:%.*]] = shl nuw i64 [[TMP0]], 3
-; STRIDED-UF2-NEXT:    [[UMAX9:%.*]] = call i64 @llvm.umax.i64(i64 [[TMP1]], i64 79)
+; STRIDED-UF2-NEXT:    [[UMAX9:%.*]] = call i64 @llvm.umax.i64(i64 [[TMP1]], i64 98)
 ; STRIDED-UF2-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[UMAX9]]
 ; STRIDED-UF2-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
 ; STRIDED-UF2:       vector.scevcheck:
@@ -833,8 +892,10 @@ define void @double_stride_int_scaled(ptr %p, ptr %p2, i64 %stride) {
 ; STRIDED-UF2-NEXT:    [[TMP19:%.*]] = icmp ugt ptr [[TMP17]], [[P]]
 ; STRIDED-UF2-NEXT:    [[TMP20:%.*]] = select i1 [[TMP13]], i1 [[TMP19]], i1 [[TMP18]]
 ; STRIDED-UF2-NEXT:    [[TMP21:%.*]] = or i1 [[TMP20]], [[MUL_OVERFLOW3]]
+; STRIDED-UF2-NEXT:    [[IDENT_CHECK:%.*]] = icmp ne i64 [[STRIDE]], 1
 ; STRIDED-UF2-NEXT:    [[TMP22:%.*]] = or i1 [[TMP12]], [[TMP21]]
-; STRIDED-UF2-NEXT:    br i1 [[TMP22]], label [[SCALAR_PH]], label [[VECTOR_MEMCHECK:%.*]]
+; STRIDED-UF2-NEXT:    [[TMP32:%.*]] = or i1 [[TMP22]], [[IDENT_CHECK]]
+; STRIDED-UF2-NEXT:    br i1 [[TMP32]], label [[SCALAR_PH]], label [[VECTOR_MEMCHECK:%.*]]
 ; STRIDED-UF2:       vector.memcheck:
 ; STRIDED-UF2-NEXT:    [[TMP23:%.*]] = mul i64 [[STRIDE]], 4092
 ; STRIDED-UF2-NEXT:    [[SCEVGEP:%.*]] = getelementptr i8, ptr [[P2]], i64 [[TMP23]]
@@ -862,20 +923,20 @@ define void @double_stride_int_scaled(ptr %p, ptr %p2, i64 %stride) {
 ; STRIDED-UF2-NEXT:    br label [[VECTOR_BODY:%.*]]
 ; STRIDED-UF2:       vector.body:
 ; STRIDED-UF2-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
-; STRIDED-UF2-NEXT:    [[TMP31:%.*]] = mul nuw nsw i64 [[INDEX]], [[STRIDE]]
-; STRIDED-UF2-NEXT:    [[TMP32:%.*]] = getelementptr i32, ptr [[P]], i64 [[TMP31]]
-; STRIDED-UF2-NEXT:    [[TMP33:%.*]] = getelementptr i32, ptr [[TMP32]], i64 [[TMP29]]
-; STRIDED-UF2-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = load <vscale x 4 x i32>, ptr [[TMP32]], align 4, !alias.scope [[META8:![0-9]+]]
-; STRIDED-UF2-NEXT:    [[WIDE_MASKED_GATHER12:%.*]] = load <vscale x 4 x i32>, ptr [[TMP33]], align 4, !alias.scope [[META8]]
-; STRIDED-UF2-NEXT:    [[TMP37:%.*]] = add <vscale x 4 x i32> [[WIDE_MASKED_GATHER]], splat (i32 1)
-; STRIDED-UF2-NEXT:    [[TMP38:%.*]] = add <vscale x 4 x i32> [[WIDE_MASKED_GATHER12]], splat (i32 1)
-; STRIDED-UF2-NEXT:    [[TMP36:%.*]] = getelementptr i32, ptr [[P2]], i64 [[TMP31]]
-; STRIDED-UF2-NEXT:    [[TMP39:%.*]] = getelementptr i32, ptr [[TMP36]], i64 [[TMP29]]
-; STRIDED-UF2-NEXT:    store <vscale x 4 x i32> [[TMP37]], ptr [[TMP36]], align 4, !alias.scope [[META11:![0-9]+]], !noalias [[META8]]
-; STRIDED-UF2-NEXT:    store <vscale x 4 x i32> [[TMP38]], ptr [[TMP39]], align 4, !alias.scope [[META11]], !noalias [[META8]]
+; STRIDED-UF2-NEXT:    [[TMP34:%.*]] = mul nuw nsw i64 [[INDEX]], [[STRIDE]]
+; STRIDED-UF2-NEXT:    [[TMP35:%.*]] = getelementptr i32, ptr [[P]], i64 [[TMP34]]
+; STRIDED-UF2-NEXT:    [[TMP33:%.*]] = getelementptr i32, ptr [[TMP35]], i64 [[TMP29]]
+; STRIDED-UF2-NEXT:    [[WIDE_LOAD:%.*]] = load <vscale x 4 x i32>, ptr [[TMP35]], align 4, !alias.scope [[META8:![0-9]+]]
+; STRIDED-UF2-NEXT:    [[WIDE_LOAD10:%.*]] = load <vscale x 4 x i32>, ptr [[TMP33]], align 4, !alias.scope [[META8]]
+; STRIDED-UF2-NEXT:    [[TMP36:%.*]] = add <vscale x 4 x i32> [[WIDE_LOAD]], splat (i32 1)
+; STRIDED-UF2-NEXT:    [[TMP39:%.*]] = add <vscale x 4 x i32> [[WIDE_LOAD10]], splat (i32 1)
+; STRIDED-UF2-NEXT:    [[TMP31:%.*]] = getelementptr i32, ptr [[P2]], i64 [[TMP34]]
+; STRIDED-UF2-NEXT:    [[TMP37:%.*]] = getelementptr i32, ptr [[TMP31]], i64 [[TMP29]]
+; STRIDED-UF2-NEXT:    store <vscale x 4 x i32> [[TMP36]], ptr [[TMP31]], align 4, !alias.scope [[META11:![0-9]+]], !noalias [[META8]]
+; STRIDED-UF2-NEXT:    store <vscale x 4 x i32> [[TMP39]], ptr [[TMP37]], align 4, !alias.scope [[META11]], !noalias [[META8]]
 ; STRIDED-UF2-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP30]]
-; STRIDED-UF2-NEXT:    [[TMP41:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
-; STRIDED-UF2-NEXT:    br i1 [[TMP41]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP13:![0-9]+]]
+; STRIDED-UF2-NEXT:    [[TMP38:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
+; STRIDED-UF2-NEXT:    br i1 [[TMP38]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP13:![0-9]+]]
 ; STRIDED-UF2:       middle.block:
 ; STRIDED-UF2-NEXT:    [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
 ; STRIDED-UF2-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
diff --git a/llvm/test/Transforms/LoopVectorize/pointer-induction.ll b/llvm/test/Transforms/LoopVectorize/pointer-induction.ll
index 44514cf758450..ddcb5ab622b7c 100644
--- a/llvm/test/Transforms/LoopVectorize/pointer-induction.ll
+++ b/llvm/test/Transforms/LoopVectorize/pointer-induction.ll
@@ -527,6 +527,9 @@ define i64 @ivopt_widen_ptr_indvar_2(ptr noalias %a, i64 %stride, i64 %n) {
 ; STRIDED-NEXT:    [[TMP1:%.*]] = shl i64 [[STRIDE:%.*]], 3
 ; STRIDED-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TMP0]], 4
 ; STRIDED-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
+; STRIDED:       vector.scevcheck:
+; STRIDED-NEXT:    [[IDENT_CHECK:%.*]] = icmp ne i64 [[STRIDE]], 1
+; STRIDED-NEXT:    br i1 [[IDENT_CHECK]], label [[SCALAR_PH]], label [[VECTOR_PH1:%.*]]
 ; STRIDED:       vector.ph:
 ; STRIDED-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[TMP0]], 4
 ; STRIDED-NEXT:    [[N_VEC:%.*]] = sub i64 [[TMP0]], [[N_MOD_VF]]
@@ -534,7 +537,7 @@ define i64 @ivopt_widen_ptr_indvar_2(ptr noalias %a, i64 %stride, i64 %n) {
 ; STRIDED-NEXT:    [[TMP3:%.*]] = getelementptr i8, ptr null, i64 [[TMP2]]
 ; STRIDED-NEXT:    br label [[VECTOR_BODY:%.*]]
 ; STRIDED:       vector.body:
-; STRIDED-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
+; STRIDED-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH1]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
 ; STRIDED-NEXT:    [[OFFSET_IDX:%.*]] = mul i64 [[INDEX]], [[TMP1]]
 ; STRIDED-NEXT:    [[NEXT_GEP:%.*]] = getelementptr i8, ptr null, i64 [[OFFSET_IDX]]
 ; STRIDED-NEXT:    [[TMP21:%.*]] = getelementptr i64, ptr [[A:%.*]], i64 [[INDEX]]
@@ -550,8 +553,8 @@ define i64 @ivopt_widen_ptr_indvar_2(ptr noalias %a, i64 %stride, i64 %n) {
 ; STRIDED-NEXT:    [[IND_ESCAPE:%.*]] = getelementptr i8, ptr [[TMP3]], i64 [[TMP19]]
 ; STRIDED-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
 ; STRIDED:       scalar.ph:
-; STRIDED-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
-; STRIDED-NEXT:    [[BC_RESUME_VAL4:%.*]] = phi ptr [ [[TMP3]], [[MIDDLE_BLOCK]] ], [ null, [[ENTRY]] ]
+; STRIDED-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_PH]] ]
+; STRIDED-NEXT:    [[BC_RESUME_VAL4:%.*]] = phi ptr [ [[TMP3]], [[MIDDLE_BLOCK]] ], [ null, [[ENTRY]] ], [ null, [[VECTOR_PH]] ]
 ; STRIDED-NEXT:    br label [[FOR_BODY:%.*]]
 ; STRIDED:       for.body:
 ; STRIDED-NEXT:    [[INDVAR:%.*]] = phi i64 [ [[INDVAR_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
@@ -710,6 +713,10 @@ define void @strided_ptr_iv_runtime_stride(ptr %pIn, ptr %pOut, i32 %nCols, i32
 ; STRIDED-NEXT:    [[TMP2:%.*]] = shl nsw i64 [[TMP1]], 2
 ; STRIDED-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[UMAX4]], 4
 ; STRIDED-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
+; STRIDED:       vector.scevcheck:
+; STRIDED-NEXT:    [[TMP18:%.*]] = sext i32 [[STRIDE]] to i64
+; STRIDED-NEXT:    [[IDENT_CHECK:%.*]] = icmp ne i64 [[TMP18]], 1
+; STRIDED-NEXT:    br i1 [[IDENT_CHECK]], label [[SCALAR_PH]], label [[VECTOR_MEMCHECK1:%.*]]
 ; STRIDED:       vector.memcheck:
 ; STRIDED-NEXT:    [[TMP3:%.*]] = sext i32 [[STRIDE]] to i64
 ; STRIDED-NEXT:    [[UMAX:%.*]] = call i32 @llvm.umax.i32(i32 [[NCOLS]], i32 1)
@@ -754,9 +761,9 @@ define void @strided_ptr_iv_runtime_stride(ptr %pIn, ptr %pOut, i32 %nCols, i32
 ; STRIDED-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[UMAX4]], [[N_VEC]]
 ; STRIDED-NEXT:    br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
 ; STRIDED:       scalar.ph:
-; STRIDED-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ [[TMP12]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_MEMCHECK]] ]
-; STRIDED-NEXT:    [[BC_RESUME_VAL7:%.*]] = phi ptr [ [[TMP14]], [[MIDDLE_BLOCK]] ], [ [[PIN]], [[ENTRY]] ], [ [[PIN]], [[VECTOR_MEMCHECK]] ]
-; STRIDED-NEXT:    [[BC_RESUME_VAL8:%.*]] = phi ptr [ [[TMP16]], [[MIDDLE_BLOCK]] ], [ [[POUT]], [[ENTRY]] ], [ [[POUT]], [[VECTOR_MEMCHECK]] ]
+; STRIDED-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ [[TMP12]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_MEMCHECK]] ], [ 0, [[VECTOR_MEMCHECK1]] ]
+; STRIDED-NEXT:    [[BC_RESUME_VAL7:%.*]] = phi ptr [ [[TMP14]], [[MIDDLE_BLOCK]] ], [ [[PIN]], [[ENTRY]] ], [ [[PIN]], [[VECTOR_MEMCHECK]] ], [ [[PIN]], [[VECTOR_MEMCHECK1]] ]
+; STRIDED-NEXT:    [[BC_RESUME_VAL8:%.*]] = phi ptr [ [[TMP16]], [[MIDDLE_BLOCK]] ], [ [[POUT]], [[ENTRY]] ], [ [[POUT]], [[VECTOR_MEMCHECK]] ], [ [[POUT]], [[VECTOR_MEMCHECK1]] ]
 ; STRIDED-NEXT:    br label [[LOOP:%.*]]
 ; STRIDED:       loop:
 ; STRIDED-NEXT:    [[IV:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
diff --git a/llvm/test/Transforms/LoopVectorize/scev-predicate-reasoning.ll b/llvm/test/Transforms/LoopVectorize/scev-predicate-reasoning.ll
index 2749a819614c7..a3648fceb7d2c 100644
--- a/llvm/test/Transforms/LoopVectorize/scev-predicate-reasoning.ll
+++ b/llvm/test/Transforms/LoopVectorize/scev-predicate-reasoning.ll
@@ -18,16 +18,19 @@ define void @step_direction_unknown(i32 %arg, ptr %dst) {
 ; CHECK-NEXT:    [[TMP4:%.*]] = icmp ugt i32 [[TMP3]], 0
 ; CHECK-NEXT:    [[TMP5:%.*]] = select i1 [[TMP1]], i1 [[TMP4]], i1 false
 ; CHECK-NEXT:    [[TMP6:%.*]] = or i1 [[TMP5]], [[MUL_OVERFLOW]]
-; CHECK-NEXT:    br i1 [[TMP6]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
+; CHECK-NEXT:    [[TMP9:%.*]] = sext i32 [[ADD]] to i64
+; CHECK-NEXT:    [[IDENT_CHECK:%.*]] = icmp ne i64 [[TMP9]], 1
+; CHECK-NEXT:    [[TMP10:%.*]] = or i1 [[TMP6]], [[IDENT_CHECK]]
+; CHECK-NEXT:    br i1 [[TMP10]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
 ; CHECK:       [[VECTOR_PH]]:
 ; CHECK-NEXT:    br label %[[VECTOR_BODY:.*]]
 ; CHECK:       [[VECTOR_BODY]]:
 ; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
 ; CHECK-NEXT:    [[TMP7:%.*]] = trunc i64 [[INDEX]] to i32
 ; CHECK-NEXT:    [[TMP8:%.*]] = mul i32 [[ADD]], [[TMP7]]
-; CHECK-NEXT:    [[TMP13:%.*]] = zext i32 [[TMP8]] to i64
-; CHECK-NEXT:    [[TMP17:%.*]] = getelementptr double, ptr [[DST]], i64 [[TMP13]]
-; CHECK-NEXT:    store <4 x double> zeroinitializer, ptr [[TMP17]], align 8
+; CHECK-NEXT:    [[TMP12:%.*]] = zext i32 [[TMP8]] to i64
+; CHECK-NEXT:    [[TMP16:%.*]] = getelementptr double, ptr [[DST]], i64 [[TMP12]]
+; CHECK-NEXT:    store <4 x double> zeroinitializer, ptr [[TMP16]], align 8
 ; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
 ; CHECK-NEXT:    [[TMP18:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
 ; CHECK-NEXT:    br i1 [[TMP18]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]



More information about the llvm-commits mailing list