[llvm] [LV] Avoid adding stray predicates in isConsecutivePtr (PR #213662)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 6 01:24:02 PDT 2026


================
@@ -14,43 +14,32 @@ define void @stride_exceeds_i32_max(ptr noalias readonly %src, ptr noalias %dst,
 ; CHECK-NEXT:    [[TMP4:%.*]] = add nuw nsw i32 [[TMP3]], 1
 ; CHECK-NEXT:    br label %[[VECTOR_SCEVCHECK:.*]]
 ; CHECK:       [[VECTOR_SCEVCHECK]]:
-; CHECK-NEXT:    [[TMP5:%.*]] = icmp slt i16 -1, [[START]]
-; CHECK-NEXT:    br i1 [[TMP5]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
-; CHECK:       [[VECTOR_PH]]:
-; CHECK-NEXT:    [[TMP12:%.*]] = sext i16 [[START]] to i64
-; CHECK-NEXT:    [[TMP13:%.*]] = mul nsw i64 [[TMP12]], 3000000000
-; CHECK-NEXT:    [[SCEVGEP:%.*]] = getelementptr i8, ptr [[SRC]], i64 [[TMP13]]
 ; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 16 x ptr> poison, ptr [[DST]], i64 0
 ; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 16 x ptr> [[BROADCAST_SPLATINSERT]], <vscale x 16 x ptr> poison, <vscale x 16 x i32> zeroinitializer
+; CHECK-NEXT:    [[TMP8:%.*]] = call <vscale x 16 x i16> @llvm.stepvector.nxv16i16()
----------------
artagnon wrote:

It is due to fragile matching, as I suspected, and this matches the stride:

```cpp
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 541a3da85599..13338bb60e78 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -5782,6 +5782,10 @@ void VPlanTransforms::convertToStridedAccesses(VPlan &Plan,
       const SCEV *PtrSCEV = vputils::getSCEVExprForVPValue(Ptr, PSE, &L);
       const SCEV *Start;
       const SCEVConstant *Step;
+      // Srip any scaling factor and casts.
+      match(PtrSCEV, m_scev_Add(m_SCEV(PtrSCEV), m_SCEVUnknown()));
+      match(PtrSCEV, m_scev_Mul(m_SCEVConstant(), m_SCEV(PtrSCEV)));
+      match(PtrSCEV, m_scev_IntegralCast(m_SCEV(PtrSCEV)));
       // TODO: Support non-constant loop invariant stride.
       if (!match(PtrSCEV,
                  m_scev_AffineAddRec(m_SCEV(Start), m_SCEVConstant(Step),
```

... but this is a broader change, and what we really want to find is the pointer's stride, as in https://github.com/llvm/llvm-project/pull/212816. Not sure what we can do about this for now?

https://github.com/llvm/llvm-project/pull/213662


More information about the llvm-commits mailing list