[llvm] [LV] Fix incorrect address for interleave loads with dead members (PR #203555)

Mel Chen via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 8 03:17:46 PDT 2026


https://github.com/Mel-Chen updated https://github.com/llvm/llvm-project/pull/203555

>From 4710dd80a33b7e47937ae41826c647a2953d1343 Mon Sep 17 00:00:00 2001
From: Mel Chen <mel.chen at sifive.com>
Date: Wed, 8 Jul 2026 02:44:05 -0700
Subject: [PATCH 1/7] pre-commit test

---
 .../LoopVectorize/versioning-dead-load.ll     | 217 ++++++++++++++++++
 1 file changed, 217 insertions(+)
 create mode 100644 llvm/test/Transforms/LoopVectorize/versioning-dead-load.ll

diff --git a/llvm/test/Transforms/LoopVectorize/versioning-dead-load.ll b/llvm/test/Transforms/LoopVectorize/versioning-dead-load.ll
new file mode 100644
index 0000000000000..d5a971cb6e6cd
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/versioning-dead-load.ll
@@ -0,0 +1,217 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals none --version 6
+; RUN: opt -S -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -enable-interleaved-mem-accesses=true -enable-mem-access-versioning=true < %s | FileCheck %s --check-prefix=VF4UF1
+; RUN: opt -S -passes=loop-vectorize -force-vector-width=1 -force-vector-interleave=2 -enable-interleaved-mem-accesses=true -enable-mem-access-versioning=true < %s | FileCheck %s --check-prefix=VF1UF2
+; RUN: opt -S -passes=loop-vectorize -force-vector-width=2 -force-vector-interleave=2 -enable-interleaved-mem-accesses=true -enable-mem-access-versioning=true < %s | FileCheck %s --check-prefix=VF2UF2
+
+define void @f(ptr noalias %p, ptr noalias %q, ptr noalias %dst, i64 %stride) {
+; VF4UF1-LABEL: define void @f(
+; VF4UF1-SAME: ptr noalias [[P:%.*]], ptr noalias [[Q:%.*]], ptr noalias [[DST:%.*]], i64 [[STRIDE:%.*]]) {
+; VF4UF1-NEXT:  [[ENTRY:.*:]]
+; VF4UF1-NEXT:    br label %[[VECTOR_SCEVCHECK:.*]]
+; VF4UF1:       [[VECTOR_SCEVCHECK]]:
+; VF4UF1-NEXT:    [[IDENT_CHECK:%.*]] = icmp ne i64 [[STRIDE]], 1
+; VF4UF1-NEXT:    br i1 [[IDENT_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
+; VF4UF1:       [[VECTOR_PH]]:
+; VF4UF1-NEXT:    br label %[[VECTOR_BODY:.*]]
+; VF4UF1:       [[VECTOR_BODY]]:
+; VF4UF1-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; VF4UF1-NEXT:    [[TMP0:%.*]] = shl nuw nsw i64 [[INDEX]], 3
+; VF4UF1-NEXT:    [[TMP1:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i64 [[TMP0]]
+; VF4UF1-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x ptr> poison, ptr [[TMP1]], i64 0
+; VF4UF1-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x ptr> [[BROADCAST_SPLATINSERT]], <4 x ptr> poison, <4 x i32> zeroinitializer
+; VF4UF1-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <4 x i32> @llvm.masked.gather.v4i32.v4p0(<4 x ptr> align 4 [[BROADCAST_SPLAT]], <4 x i1> splat (i1 true), <4 x i32> poison)
+; VF4UF1-NEXT:    [[TMP2:%.*]] = getelementptr inbounds [4 x i8], ptr [[Q]], i64 [[INDEX]]
+; VF4UF1-NEXT:    store <4 x i32> [[WIDE_MASKED_GATHER]], ptr [[TMP2]], align 4
+; VF4UF1-NEXT:    [[TMP3:%.*]] = getelementptr inbounds nuw [4 x i8], ptr [[DST]], i64 [[INDEX]]
+; VF4UF1-NEXT:    store <4 x i32> zeroinitializer, ptr [[TMP3]], align 4
+; VF4UF1-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
+; VF4UF1-NEXT:    [[TMP4:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
+; VF4UF1-NEXT:    br i1 [[TMP4]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
+; VF4UF1:       [[MIDDLE_BLOCK]]:
+; VF4UF1-NEXT:    br label %[[EXIT:.*]]
+; VF4UF1:       [[SCALAR_PH]]:
+; VF4UF1-NEXT:    br label %[[FOR_BODY:.*]]
+; VF4UF1:       [[FOR_BODY]]:
+; VF4UF1-NEXT:    [[I_021:%.*]] = phi i64 [ [[INC:%.*]], %[[IF_END:.*]] ], [ 0, %[[SCALAR_PH]] ]
+; VF4UF1-NEXT:    [[ARRAYIDX_IDX:%.*]] = shl nuw nsw i64 [[I_021]], 3
+; VF4UF1-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i64 [[ARRAYIDX_IDX]]
+; VF4UF1-NEXT:    [[TMP5:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
+; VF4UF1-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds nuw i8, ptr [[ARRAYIDX]], i64 4
+; VF4UF1-NEXT:    [[TMP6:%.*]] = load i32, ptr [[ARRAYIDX2]], align 4
+; VF4UF1-NEXT:    [[MUL3:%.*]] = mul nsw i64 [[I_021]], [[STRIDE]]
+; VF4UF1-NEXT:    [[ARRAYIDX4:%.*]] = getelementptr inbounds [4 x i8], ptr [[Q]], i64 [[MUL3]]
+; VF4UF1-NEXT:    store i32 [[TMP5]], ptr [[ARRAYIDX4]], align 4
+; VF4UF1-NEXT:    [[CMP5:%.*]] = icmp sgt i32 [[TMP5]], 0
+; VF4UF1-NEXT:    br i1 [[CMP5]], label %[[IF_THEN:.*]], label %[[IF_END]]
+; VF4UF1:       [[IF_THEN]]:
+; VF4UF1-NEXT:    [[REM:%.*]] = srem i64 3, [[STRIDE]]
+; VF4UF1-NEXT:    [[TMP7:%.*]] = trunc nuw nsw i64 [[REM]] to i32
+; VF4UF1-NEXT:    [[TMP8:%.*]] = mul i32 [[TMP6]], [[TMP7]]
+; VF4UF1-NEXT:    br label %[[IF_END]]
+; VF4UF1:       [[IF_END]]:
+; VF4UF1-NEXT:    [[CONV9:%.*]] = phi i32 [ [[TMP8]], %[[IF_THEN]] ], [ 0, %[[FOR_BODY]] ]
+; VF4UF1-NEXT:    [[ARRAYIDX10:%.*]] = getelementptr inbounds nuw [4 x i8], ptr [[DST]], i64 [[I_021]]
+; VF4UF1-NEXT:    store i32 [[CONV9]], ptr [[ARRAYIDX10]], align 4
+; VF4UF1-NEXT:    [[INC]] = add nuw nsw i64 [[I_021]], 1
+; VF4UF1-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INC]], 1024
+; VF4UF1-NEXT:    br i1 [[EXITCOND_NOT]], label %[[EXIT]], label %[[FOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
+; VF4UF1:       [[EXIT]]:
+; VF4UF1-NEXT:    ret void
+;
+; VF1UF2-LABEL: define void @f(
+; VF1UF2-SAME: ptr noalias [[P:%.*]], ptr noalias [[Q:%.*]], ptr noalias [[DST:%.*]], i64 [[STRIDE:%.*]]) {
+; VF1UF2-NEXT:  [[ENTRY:.*:]]
+; VF1UF2-NEXT:    br label %[[VECTOR_SCEVCHECK:.*]]
+; VF1UF2:       [[VECTOR_SCEVCHECK]]:
+; VF1UF2-NEXT:    [[IDENT_CHECK:%.*]] = icmp ne i64 [[STRIDE]], 1
+; VF1UF2-NEXT:    br i1 [[IDENT_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
+; VF1UF2:       [[VECTOR_PH]]:
+; VF1UF2-NEXT:    br label %[[VECTOR_BODY:.*]]
+; VF1UF2:       [[VECTOR_BODY]]:
+; VF1UF2-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; VF1UF2-NEXT:    [[TMP0:%.*]] = add i64 [[INDEX]], 1
+; VF1UF2-NEXT:    [[TMP1:%.*]] = shl nuw nsw i64 [[INDEX]], 3
+; VF1UF2-NEXT:    [[TMP2:%.*]] = shl nuw nsw i64 [[TMP0]], 3
+; VF1UF2-NEXT:    [[TMP3:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i64 [[TMP1]]
+; VF1UF2-NEXT:    [[TMP4:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i64 [[TMP2]]
+; VF1UF2-NEXT:    [[TMP5:%.*]] = load i32, ptr [[TMP3]], align 4
+; VF1UF2-NEXT:    [[TMP6:%.*]] = load i32, ptr [[TMP4]], align 4
+; VF1UF2-NEXT:    [[TMP7:%.*]] = getelementptr inbounds [4 x i8], ptr [[Q]], i64 [[INDEX]]
+; VF1UF2-NEXT:    [[TMP8:%.*]] = getelementptr inbounds [4 x i8], ptr [[Q]], i64 [[TMP0]]
+; VF1UF2-NEXT:    store i32 [[TMP5]], ptr [[TMP7]], align 4
+; VF1UF2-NEXT:    store i32 [[TMP6]], ptr [[TMP8]], align 4
+; VF1UF2-NEXT:    [[TMP9:%.*]] = getelementptr inbounds nuw [4 x i8], ptr [[DST]], i64 [[INDEX]]
+; VF1UF2-NEXT:    [[TMP10:%.*]] = getelementptr inbounds nuw [4 x i8], ptr [[DST]], i64 [[TMP0]]
+; VF1UF2-NEXT:    store i32 0, ptr [[TMP9]], align 4
+; VF1UF2-NEXT:    store i32 0, ptr [[TMP10]], align 4
+; VF1UF2-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
+; VF1UF2-NEXT:    [[TMP11:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
+; VF1UF2-NEXT:    br i1 [[TMP11]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
+; VF1UF2:       [[MIDDLE_BLOCK]]:
+; VF1UF2-NEXT:    br label %[[EXIT:.*]]
+; VF1UF2:       [[SCALAR_PH]]:
+; VF1UF2-NEXT:    br label %[[FOR_BODY:.*]]
+; VF1UF2:       [[FOR_BODY]]:
+; VF1UF2-NEXT:    [[I_021:%.*]] = phi i64 [ [[INC:%.*]], %[[IF_END:.*]] ], [ 0, %[[SCALAR_PH]] ]
+; VF1UF2-NEXT:    [[ARRAYIDX_IDX:%.*]] = shl nuw nsw i64 [[I_021]], 3
+; VF1UF2-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i64 [[ARRAYIDX_IDX]]
+; VF1UF2-NEXT:    [[TMP12:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
+; VF1UF2-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds nuw i8, ptr [[ARRAYIDX]], i64 4
+; VF1UF2-NEXT:    [[TMP13:%.*]] = load i32, ptr [[ARRAYIDX2]], align 4
+; VF1UF2-NEXT:    [[MUL3:%.*]] = mul nsw i64 [[I_021]], [[STRIDE]]
+; VF1UF2-NEXT:    [[ARRAYIDX4:%.*]] = getelementptr inbounds [4 x i8], ptr [[Q]], i64 [[MUL3]]
+; VF1UF2-NEXT:    store i32 [[TMP12]], ptr [[ARRAYIDX4]], align 4
+; VF1UF2-NEXT:    [[CMP5:%.*]] = icmp sgt i32 [[TMP12]], 0
+; VF1UF2-NEXT:    br i1 [[CMP5]], label %[[IF_THEN:.*]], label %[[IF_END]]
+; VF1UF2:       [[IF_THEN]]:
+; VF1UF2-NEXT:    [[REM:%.*]] = srem i64 3, [[STRIDE]]
+; VF1UF2-NEXT:    [[TMP14:%.*]] = trunc nuw nsw i64 [[REM]] to i32
+; VF1UF2-NEXT:    [[TMP15:%.*]] = mul i32 [[TMP13]], [[TMP14]]
+; VF1UF2-NEXT:    br label %[[IF_END]]
+; VF1UF2:       [[IF_END]]:
+; VF1UF2-NEXT:    [[CONV9:%.*]] = phi i32 [ [[TMP15]], %[[IF_THEN]] ], [ 0, %[[FOR_BODY]] ]
+; VF1UF2-NEXT:    [[ARRAYIDX10:%.*]] = getelementptr inbounds nuw [4 x i8], ptr [[DST]], i64 [[I_021]]
+; VF1UF2-NEXT:    store i32 [[CONV9]], ptr [[ARRAYIDX10]], align 4
+; VF1UF2-NEXT:    [[INC]] = add nuw nsw i64 [[I_021]], 1
+; VF1UF2-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INC]], 1024
+; VF1UF2-NEXT:    br i1 [[EXITCOND_NOT]], label %[[EXIT]], label %[[FOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
+; VF1UF2:       [[EXIT]]:
+; VF1UF2-NEXT:    ret void
+;
+; VF2UF2-LABEL: define void @f(
+; VF2UF2-SAME: ptr noalias [[P:%.*]], ptr noalias [[Q:%.*]], ptr noalias [[DST:%.*]], i64 [[STRIDE:%.*]]) {
+; VF2UF2-NEXT:  [[ENTRY:.*:]]
+; VF2UF2-NEXT:    br label %[[VECTOR_SCEVCHECK:.*]]
+; VF2UF2:       [[VECTOR_SCEVCHECK]]:
+; VF2UF2-NEXT:    [[IDENT_CHECK:%.*]] = icmp ne i64 [[STRIDE]], 1
+; VF2UF2-NEXT:    br i1 [[IDENT_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
+; VF2UF2:       [[VECTOR_PH]]:
+; VF2UF2-NEXT:    br label %[[VECTOR_BODY:.*]]
+; VF2UF2:       [[VECTOR_BODY]]:
+; VF2UF2-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; VF2UF2-NEXT:    [[TMP0:%.*]] = add i64 [[INDEX]], 2
+; VF2UF2-NEXT:    [[TMP1:%.*]] = shl nuw nsw i64 [[INDEX]], 3
+; VF2UF2-NEXT:    [[TMP2:%.*]] = shl nuw nsw i64 [[TMP0]], 3
+; VF2UF2-NEXT:    [[TMP3:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i64 [[TMP1]]
+; VF2UF2-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x ptr> poison, ptr [[TMP3]], i64 0
+; VF2UF2-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x ptr> [[BROADCAST_SPLATINSERT]], <2 x ptr> poison, <2 x i32> zeroinitializer
+; VF2UF2-NEXT:    [[TMP4:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i64 [[TMP2]]
+; VF2UF2-NEXT:    [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <2 x ptr> poison, ptr [[TMP4]], i64 0
+; VF2UF2-NEXT:    [[BROADCAST_SPLAT2:%.*]] = shufflevector <2 x ptr> [[BROADCAST_SPLATINSERT1]], <2 x ptr> poison, <2 x i32> zeroinitializer
+; VF2UF2-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <2 x i32> @llvm.masked.gather.v2i32.v2p0(<2 x ptr> align 4 [[BROADCAST_SPLAT]], <2 x i1> splat (i1 true), <2 x i32> poison)
+; VF2UF2-NEXT:    [[WIDE_MASKED_GATHER3:%.*]] = call <2 x i32> @llvm.masked.gather.v2i32.v2p0(<2 x ptr> align 4 [[BROADCAST_SPLAT2]], <2 x i1> splat (i1 true), <2 x i32> poison)
+; VF2UF2-NEXT:    [[TMP5:%.*]] = getelementptr inbounds [4 x i8], ptr [[Q]], i64 [[INDEX]]
+; VF2UF2-NEXT:    [[TMP6:%.*]] = getelementptr inbounds i32, ptr [[TMP5]], i64 2
+; VF2UF2-NEXT:    store <2 x i32> [[WIDE_MASKED_GATHER]], ptr [[TMP5]], align 4
+; VF2UF2-NEXT:    store <2 x i32> [[WIDE_MASKED_GATHER3]], ptr [[TMP6]], align 4
+; VF2UF2-NEXT:    [[TMP7:%.*]] = getelementptr inbounds nuw [4 x i8], ptr [[DST]], i64 [[INDEX]]
+; VF2UF2-NEXT:    [[TMP8:%.*]] = getelementptr inbounds nuw i32, ptr [[TMP7]], i64 2
+; VF2UF2-NEXT:    store <2 x i32> zeroinitializer, ptr [[TMP7]], align 4
+; VF2UF2-NEXT:    store <2 x i32> zeroinitializer, ptr [[TMP8]], align 4
+; VF2UF2-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
+; VF2UF2-NEXT:    [[TMP9:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
+; VF2UF2-NEXT:    br i1 [[TMP9]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
+; VF2UF2:       [[MIDDLE_BLOCK]]:
+; VF2UF2-NEXT:    br label %[[EXIT:.*]]
+; VF2UF2:       [[SCALAR_PH]]:
+; VF2UF2-NEXT:    br label %[[FOR_BODY:.*]]
+; VF2UF2:       [[FOR_BODY]]:
+; VF2UF2-NEXT:    [[I_021:%.*]] = phi i64 [ [[INC:%.*]], %[[IF_END:.*]] ], [ 0, %[[SCALAR_PH]] ]
+; VF2UF2-NEXT:    [[ARRAYIDX_IDX:%.*]] = shl nuw nsw i64 [[I_021]], 3
+; VF2UF2-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i64 [[ARRAYIDX_IDX]]
+; VF2UF2-NEXT:    [[TMP10:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
+; VF2UF2-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds nuw i8, ptr [[ARRAYIDX]], i64 4
+; VF2UF2-NEXT:    [[TMP11:%.*]] = load i32, ptr [[ARRAYIDX2]], align 4
+; VF2UF2-NEXT:    [[MUL3:%.*]] = mul nsw i64 [[I_021]], [[STRIDE]]
+; VF2UF2-NEXT:    [[ARRAYIDX4:%.*]] = getelementptr inbounds [4 x i8], ptr [[Q]], i64 [[MUL3]]
+; VF2UF2-NEXT:    store i32 [[TMP10]], ptr [[ARRAYIDX4]], align 4
+; VF2UF2-NEXT:    [[CMP5:%.*]] = icmp sgt i32 [[TMP10]], 0
+; VF2UF2-NEXT:    br i1 [[CMP5]], label %[[IF_THEN:.*]], label %[[IF_END]]
+; VF2UF2:       [[IF_THEN]]:
+; VF2UF2-NEXT:    [[REM:%.*]] = srem i64 3, [[STRIDE]]
+; VF2UF2-NEXT:    [[TMP12:%.*]] = trunc nuw nsw i64 [[REM]] to i32
+; VF2UF2-NEXT:    [[TMP13:%.*]] = mul i32 [[TMP11]], [[TMP12]]
+; VF2UF2-NEXT:    br label %[[IF_END]]
+; VF2UF2:       [[IF_END]]:
+; VF2UF2-NEXT:    [[CONV9:%.*]] = phi i32 [ [[TMP13]], %[[IF_THEN]] ], [ 0, %[[FOR_BODY]] ]
+; VF2UF2-NEXT:    [[ARRAYIDX10:%.*]] = getelementptr inbounds nuw [4 x i8], ptr [[DST]], i64 [[I_021]]
+; VF2UF2-NEXT:    store i32 [[CONV9]], ptr [[ARRAYIDX10]], align 4
+; VF2UF2-NEXT:    [[INC]] = add nuw nsw i64 [[I_021]], 1
+; VF2UF2-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INC]], 1024
+; VF2UF2-NEXT:    br i1 [[EXITCOND_NOT]], label %[[EXIT]], label %[[FOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
+; VF2UF2:       [[EXIT]]:
+; VF2UF2-NEXT:    ret void
+;
+entry:
+  br label %for.body
+
+for.body:
+  %i.021 = phi i64 [ %inc, %if.end ], [ 0, %entry ]
+  %arrayidx.idx = shl nuw nsw i64 %i.021, 3
+  %arrayidx = getelementptr inbounds nuw i8, ptr %p, i64 %arrayidx.idx
+  %0 = load i32, ptr %arrayidx, align 4
+  %arrayidx2 = getelementptr inbounds nuw i8, ptr %arrayidx, i64 4
+  %1 = load i32, ptr %arrayidx2, align 4
+  %mul3 = mul nsw i64 %i.021, %stride
+  %arrayidx4 = getelementptr inbounds [4 x i8], ptr %q, i64 %mul3
+  store i32 %0, ptr %arrayidx4, align 4
+  %cmp5 = icmp sgt i32 %0, 0
+  br i1 %cmp5, label %if.then, label %if.end
+
+if.then:
+  %rem = srem i64 3, %stride
+  %2 = trunc nuw nsw i64 %rem to i32
+  %3 = mul i32 %1, %2
+  br label %if.end
+
+if.end:
+  %t.0 = phi i32 [ %3, %if.then ], [ 0, %for.body ]
+  %arrayidx10 = getelementptr inbounds nuw [4 x i8], ptr %dst, i64 %i.021
+  store i32 %t.0, ptr %arrayidx10, align 4
+  %inc = add nuw nsw i64 %i.021, 1
+  %exitcond.not = icmp eq i64 %inc, 1024
+  br i1 %exitcond.not, label %exit, label %for.body
+
+exit:
+  ret void
+}

>From 0e0df25ea797f1b9024fb51b7e00216438ce1347 Mon Sep 17 00:00:00 2001
From: Mel Chen <mel.chen at sifive.com>
Date: Fri, 12 Jun 2026 07:28:06 -0700
Subject: [PATCH 2/7] test

---
 .../LoopVectorize/RISCV/pointer-induction.ll  | 142 ++++++++++++++++++
 1 file changed, 142 insertions(+)

diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/pointer-induction.ll b/llvm/test/Transforms/LoopVectorize/RISCV/pointer-induction.ll
index 3a3833a1ed2c8..792fac2a5e206 100644
--- a/llvm/test/Transforms/LoopVectorize/RISCV/pointer-induction.ll
+++ b/llvm/test/Transforms/LoopVectorize/RISCV/pointer-induction.ll
@@ -1,5 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals none --version 6
 ; RUN: opt -p loop-vectorize -S %s | FileCheck %s
+; RUN: opt -p loop-vectorize -S -tail-folding-policy=dont-fold-tail %s | FileCheck %s --check-prefix=NO-FOLDING
 
 target triple = "riscv64-unknown-linux-gnu"
 
@@ -41,6 +42,69 @@ define void @ptr_induction(ptr %p, ptr noalias %q, ptr noalias %p.end) #0 {
 ; CHECK:       [[EXIT]]:
 ; CHECK-NEXT:    ret void
 ;
+; NO-FOLDING-LABEL: define void @ptr_induction(
+; NO-FOLDING-SAME: ptr [[P:%.*]], ptr noalias [[Q:%.*]], ptr noalias [[P_END:%.*]]) #[[ATTR0:[0-9]+]] {
+; NO-FOLDING-NEXT:  [[ENTRY:.*]]:
+; NO-FOLDING-NEXT:    [[P2:%.*]] = ptrtoint ptr [[P]] to i64
+; NO-FOLDING-NEXT:    [[P_END1:%.*]] = ptrtoint ptr [[P_END]] to i64
+; NO-FOLDING-NEXT:    [[TMP0:%.*]] = add i64 [[P_END1]], 1
+; NO-FOLDING-NEXT:    [[TMP1:%.*]] = sub i64 [[TMP0]], [[P2]]
+; NO-FOLDING-NEXT:    [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
+; NO-FOLDING-NEXT:    [[TMP3:%.*]] = shl nuw i64 [[TMP2]], 1
+; NO-FOLDING-NEXT:    [[UMAX:%.*]] = call i64 @llvm.umax.i64(i64 [[TMP3]], i64 4)
+; NO-FOLDING-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TMP1]], [[UMAX]]
+; NO-FOLDING-NEXT:    br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
+; NO-FOLDING:       [[VECTOR_PH]]:
+; NO-FOLDING-NEXT:    [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
+; NO-FOLDING-NEXT:    [[TMP5:%.*]] = shl nuw i64 [[TMP4]], 1
+; NO-FOLDING-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[TMP1]], [[TMP5]]
+; NO-FOLDING-NEXT:    [[N_VEC:%.*]] = sub i64 [[TMP1]], [[N_MOD_VF]]
+; NO-FOLDING-NEXT:    [[TMP6:%.*]] = getelementptr i8, ptr [[P]], i64 [[N_VEC]]
+; NO-FOLDING-NEXT:    [[TMP7:%.*]] = call <vscale x 2 x i64> @llvm.stepvector.nxv2i64()
+; NO-FOLDING-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 2 x i64> poison, i64 [[TMP5]], i64 0
+; NO-FOLDING-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 2 x i64> [[BROADCAST_SPLATINSERT]], <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer
+; NO-FOLDING-NEXT:    br label %[[VECTOR_BODY:.*]]
+; NO-FOLDING:       [[VECTOR_BODY]]:
+; NO-FOLDING-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; NO-FOLDING-NEXT:    [[VEC_IND:%.*]] = phi <vscale x 2 x i64> [ [[TMP7]], %[[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; NO-FOLDING-NEXT:    [[POINTER_PHI:%.*]] = phi ptr [ [[P]], %[[VECTOR_PH]] ], [ [[PTR_IND3:%.*]], %[[VECTOR_BODY]] ]
+; NO-FOLDING-NEXT:    [[VECTOR_GEP:%.*]] = getelementptr i8, ptr [[POINTER_PHI]], <vscale x 2 x i64> [[TMP7]]
+; NO-FOLDING-NEXT:    [[TMP8:%.*]] = ptrtoint <vscale x 2 x ptr> [[VECTOR_GEP]] to <vscale x 2 x i64>
+; NO-FOLDING-NEXT:    [[TMP9:%.*]] = call i32 @llvm.vscale.i32()
+; NO-FOLDING-NEXT:    [[TMP10:%.*]] = mul nuw i32 [[TMP9]], 2
+; NO-FOLDING-NEXT:    [[TMP11:%.*]] = sub i32 [[TMP10]], 1
+; NO-FOLDING-NEXT:    [[TMP12:%.*]] = extractelement <vscale x 2 x i64> [[TMP8]], i32 [[TMP11]]
+; NO-FOLDING-NEXT:    store i64 [[TMP12]], ptr [[Q]], align 8
+; NO-FOLDING-NEXT:    [[TMP13:%.*]] = call i32 @llvm.vscale.i32()
+; NO-FOLDING-NEXT:    [[TMP14:%.*]] = mul nuw i32 [[TMP13]], 2
+; NO-FOLDING-NEXT:    [[TMP15:%.*]] = sub i32 [[TMP14]], 1
+; NO-FOLDING-NEXT:    [[TMP16:%.*]] = extractelement <vscale x 2 x i64> [[VEC_IND]], i32 [[TMP15]]
+; NO-FOLDING-NEXT:    store i64 [[TMP16]], ptr [[P]], align 8
+; NO-FOLDING-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
+; NO-FOLDING-NEXT:    [[VEC_IND_NEXT]] = add <vscale x 2 x i64> [[VEC_IND]], [[BROADCAST_SPLAT]]
+; NO-FOLDING-NEXT:    [[PTR_IND3]] = getelementptr i8, ptr [[POINTER_PHI]], i64 [[TMP5]]
+; NO-FOLDING-NEXT:    [[TMP17:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
+; NO-FOLDING-NEXT:    br i1 [[TMP17]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
+; NO-FOLDING:       [[MIDDLE_BLOCK]]:
+; NO-FOLDING-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[TMP1]], [[N_VEC]]
+; NO-FOLDING-NEXT:    br i1 [[CMP_N]], label %[[EXIT:.*]], label %[[SCALAR_PH]]
+; NO-FOLDING:       [[SCALAR_PH]]:
+; NO-FOLDING-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
+; NO-FOLDING-NEXT:    [[BC_RESUME_VAL4:%.*]] = phi ptr [ [[TMP6]], %[[MIDDLE_BLOCK]] ], [ [[P]], %[[ENTRY]] ]
+; NO-FOLDING-NEXT:    br label %[[LOOP:.*]]
+; NO-FOLDING:       [[LOOP]]:
+; NO-FOLDING-NEXT:    [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
+; NO-FOLDING-NEXT:    [[PTR_IND:%.*]] = phi ptr [ [[BC_RESUME_VAL4]], %[[SCALAR_PH]] ], [ [[PTR_IND_NEXT:%.*]], %[[LOOP]] ]
+; NO-FOLDING-NEXT:    [[PTRI64:%.*]] = ptrtoint ptr [[PTR_IND]] to i64
+; NO-FOLDING-NEXT:    store i64 [[PTRI64]], ptr [[Q]], align 8
+; NO-FOLDING-NEXT:    store i64 [[IV]], ptr [[P]], align 8
+; NO-FOLDING-NEXT:    [[IV_NEXT]] = add i64 [[IV]], 1
+; NO-FOLDING-NEXT:    [[PTR_IND_NEXT]] = getelementptr i8, ptr [[PTR_IND]], i64 1
+; NO-FOLDING-NEXT:    [[EC:%.*]] = icmp eq ptr [[PTR_IND]], [[P_END]]
+; NO-FOLDING-NEXT:    br i1 [[EC]], label %[[EXIT]], label %[[LOOP]], !llvm.loop [[LOOP3:![0-9]+]]
+; NO-FOLDING:       [[EXIT]]:
+; NO-FOLDING-NEXT:    ret void
+;
 entry:
   br label %loop
 
@@ -108,6 +172,84 @@ define i1 @scalarize_ptr_induction(ptr %start, ptr %end, ptr noalias %dst, i1 %c
 ; CHECK:       [[LOOP]]:
 ; CHECK-NEXT:    ret i1 [[TMP25]]
 ;
+; NO-FOLDING-LABEL: define i1 @scalarize_ptr_induction(
+; NO-FOLDING-SAME: ptr [[START:%.*]], ptr [[END:%.*]], ptr noalias [[DST:%.*]], i1 [[C:%.*]]) #[[ATTR1:[0-9]+]] {
+; NO-FOLDING-NEXT:  [[ENTRY:.*]]:
+; NO-FOLDING-NEXT:    [[START5:%.*]] = ptrtoint ptr [[START]] to i64
+; NO-FOLDING-NEXT:    [[END4:%.*]] = ptrtoint ptr [[END]] to i64
+; NO-FOLDING-NEXT:    [[START2:%.*]] = ptrtoint ptr [[START]] to i64
+; NO-FOLDING-NEXT:    [[END1:%.*]] = ptrtoint ptr [[END]] to i64
+; NO-FOLDING-NEXT:    [[TMP0:%.*]] = add i64 [[END4]], -12
+; NO-FOLDING-NEXT:    [[TMP1:%.*]] = sub i64 [[TMP0]], [[START5]]
+; NO-FOLDING-NEXT:    [[TMP2:%.*]] = udiv i64 [[TMP1]], 12
+; NO-FOLDING-NEXT:    [[TMP3:%.*]] = add nuw nsw i64 [[TMP2]], 1
+; NO-FOLDING-NEXT:    [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
+; NO-FOLDING-NEXT:    [[TMP5:%.*]] = shl nuw i64 [[TMP4]], 1
+; NO-FOLDING-NEXT:    [[UMAX:%.*]] = call i64 @llvm.umax.i64(i64 [[TMP5]], i64 24)
+; NO-FOLDING-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ule i64 [[TMP3]], [[UMAX]]
+; NO-FOLDING-NEXT:    br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_MEMCHECK:.*]]
+; NO-FOLDING:       [[VECTOR_MEMCHECK]]:
+; NO-FOLDING-NEXT:    [[SCEVGEP:%.*]] = getelementptr i8, ptr [[DST]], i64 8
+; NO-FOLDING-NEXT:    [[TMP6:%.*]] = add i64 [[END1]], -12
+; NO-FOLDING-NEXT:    [[TMP7:%.*]] = sub i64 [[TMP6]], [[START2]]
+; NO-FOLDING-NEXT:    [[TMP8:%.*]] = udiv i64 [[TMP7]], 12
+; NO-FOLDING-NEXT:    [[TMP9:%.*]] = mul nuw i64 [[TMP8]], 12
+; NO-FOLDING-NEXT:    [[TMP10:%.*]] = add i64 [[TMP9]], 8
+; NO-FOLDING-NEXT:    [[SCEVGEP3:%.*]] = getelementptr i8, ptr [[START]], i64 [[TMP10]]
+; NO-FOLDING-NEXT:    [[BOUND0:%.*]] = icmp ult ptr [[DST]], [[SCEVGEP3]]
+; NO-FOLDING-NEXT:    [[BOUND1:%.*]] = icmp ult ptr [[START]], [[SCEVGEP]]
+; NO-FOLDING-NEXT:    [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
+; NO-FOLDING-NEXT:    br i1 [[FOUND_CONFLICT]], label %[[SCALAR_PH]], label %[[VECTOR_PH:.*]]
+; NO-FOLDING:       [[VECTOR_PH]]:
+; NO-FOLDING-NEXT:    [[TMP11:%.*]] = call i64 @llvm.vscale.i64()
+; NO-FOLDING-NEXT:    [[TMP12:%.*]] = shl nuw i64 [[TMP11]], 1
+; NO-FOLDING-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[TMP3]], [[TMP12]]
+; NO-FOLDING-NEXT:    [[TMP13:%.*]] = icmp eq i64 [[N_MOD_VF]], 0
+; NO-FOLDING-NEXT:    [[TMP14:%.*]] = select i1 [[TMP13]], i64 [[TMP12]], i64 [[N_MOD_VF]]
+; NO-FOLDING-NEXT:    [[N_VEC:%.*]] = sub i64 [[TMP3]], [[TMP14]]
+; NO-FOLDING-NEXT:    [[TMP15:%.*]] = mul i64 [[N_VEC]], 12
+; NO-FOLDING-NEXT:    [[TMP16:%.*]] = getelementptr i8, ptr [[START]], i64 [[TMP15]]
+; NO-FOLDING-NEXT:    br label %[[VECTOR_BODY:.*]]
+; NO-FOLDING:       [[VECTOR_BODY]]:
+; NO-FOLDING-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; NO-FOLDING-NEXT:    [[TMP17:%.*]] = mul i64 [[INDEX]], 12
+; NO-FOLDING-NEXT:    [[NEXT_GEP:%.*]] = getelementptr i8, ptr [[START]], i64 [[TMP17]]
+; NO-FOLDING-NEXT:    [[TMP18:%.*]] = getelementptr i8, ptr [[NEXT_GEP]], i64 4
+; NO-FOLDING-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 2 x ptr> poison, ptr [[TMP18]], i64 0
+; NO-FOLDING-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 2 x ptr> [[BROADCAST_SPLATINSERT]], <vscale x 2 x ptr> poison, <vscale x 2 x i32> zeroinitializer
+; NO-FOLDING-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 2 x i32> @llvm.masked.gather.nxv2i32.nxv2p0(<vscale x 2 x ptr> align 4 [[BROADCAST_SPLAT]], <vscale x 2 x i1> splat (i1 true), <vscale x 2 x i32> poison), !alias.scope [[META4:![0-9]+]]
+; NO-FOLDING-NEXT:    [[TMP19:%.*]] = zext <vscale x 2 x i32> [[WIDE_MASKED_GATHER]] to <vscale x 2 x i64>
+; NO-FOLDING-NEXT:    [[TMP20:%.*]] = mul <vscale x 2 x i64> [[TMP19]], splat (i64 -7070675565921424023)
+; NO-FOLDING-NEXT:    [[TMP21:%.*]] = add <vscale x 2 x i64> [[TMP20]], splat (i64 -4)
+; NO-FOLDING-NEXT:    [[TMP22:%.*]] = call i32 @llvm.vscale.i32()
+; NO-FOLDING-NEXT:    [[TMP23:%.*]] = mul nuw i32 [[TMP22]], 2
+; NO-FOLDING-NEXT:    [[TMP24:%.*]] = sub i32 [[TMP23]], 1
+; NO-FOLDING-NEXT:    [[TMP25:%.*]] = extractelement <vscale x 2 x i64> [[TMP21]], i32 [[TMP24]]
+; NO-FOLDING-NEXT:    store i64 [[TMP25]], ptr [[DST]], align 1, !alias.scope [[META7:![0-9]+]], !noalias [[META4]]
+; NO-FOLDING-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP12]]
+; NO-FOLDING-NEXT:    [[TMP26:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
+; NO-FOLDING-NEXT:    br i1 [[TMP26]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP9:![0-9]+]]
+; NO-FOLDING:       [[MIDDLE_BLOCK]]:
+; NO-FOLDING-NEXT:    br label %[[SCALAR_PH]]
+; NO-FOLDING:       [[SCALAR_PH]]:
+; NO-FOLDING-NEXT:    [[BC_RESUME_VAL:%.*]] = phi ptr [ [[TMP16]], %[[MIDDLE_BLOCK]] ], [ [[START]], %[[ENTRY]] ], [ [[START]], %[[VECTOR_MEMCHECK]] ]
+; NO-FOLDING-NEXT:    br label %[[LOOP:.*]]
+; NO-FOLDING:       [[LOOP]]:
+; NO-FOLDING-NEXT:    [[PTR_IV:%.*]] = phi ptr [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[PTR_IV_NEXT:%.*]], %[[LOOP]] ]
+; NO-FOLDING-NEXT:    [[GEP:%.*]] = getelementptr i8, ptr [[PTR_IV]], i64 4
+; NO-FOLDING-NEXT:    [[L:%.*]] = load i32, ptr [[GEP]], align 4
+; NO-FOLDING-NEXT:    [[EXT:%.*]] = zext i32 [[L]] to i64
+; NO-FOLDING-NEXT:    [[UNUSED:%.*]] = load i32, ptr [[PTR_IV]], align 4
+; NO-FOLDING-NEXT:    [[MUL1:%.*]] = mul i64 [[EXT]], -7070675565921424023
+; NO-FOLDING-NEXT:    [[MUL2:%.*]] = add i64 [[MUL1]], -4
+; NO-FOLDING-NEXT:    store i64 [[MUL2]], ptr [[DST]], align 1
+; NO-FOLDING-NEXT:    [[PTR_IV_NEXT]] = getelementptr nusw i8, ptr [[PTR_IV]], i64 12
+; NO-FOLDING-NEXT:    [[CMP:%.*]] = icmp eq ptr [[PTR_IV_NEXT]], [[END]]
+; NO-FOLDING-NEXT:    br i1 [[CMP]], label %[[EXIT:.*]], label %[[LOOP]], !llvm.loop [[LOOP10:![0-9]+]]
+; NO-FOLDING:       [[EXIT]]:
+; NO-FOLDING-NEXT:    [[CMP_LCSSA:%.*]] = phi i1 [ [[CMP]], %[[LOOP]] ]
+; NO-FOLDING-NEXT:    ret i1 [[CMP_LCSSA]]
+;
 entry:
   br label %loop
 

>From 0dda86d50942b253789fe9214852197367b56a30 Mon Sep 17 00:00:00 2001
From: Mel Chen <mel.chen at sifive.com>
Date: Fri, 12 Jun 2026 07:40:57 -0700
Subject: [PATCH 3/7] repair address

---
 .../Transforms/Vectorize/VPlanTransforms.cpp  | 28 ++++++++++++++++++-
 ...e-to-widen-memory-with-wide-ops-chained.ll |  6 ++--
 .../LoopVectorize/RISCV/dead-ops-cost.ll      |  4 +--
 .../LoopVectorize/RISCV/pointer-induction.ll  |  7 +++--
 .../LoopVectorize/consecutive-ptr-uniforms.ll |  3 +-
 5 files changed, 37 insertions(+), 11 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 0a879d7d92941..70adfcfb0c8ec 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -3750,8 +3750,34 @@ void VPlanTransforms::createInterleaveGroups(
     // but have no users.
     if (llvm::any_of(IG->members(), [&IRMemberToRecipe](Instruction *Member) {
           return !IRMemberToRecipe.contains(Member);
-        }))
+        })) {
+      auto &DL = Plan.getDataLayout();
+      for (unsigned I = 0; I < IG->getFactor(); ++I)
+        if (Instruction *Member = IG->getMember(I)) {
+          // Fix addresses of members that still have recipes.
+          if (auto *MemberR = IRMemberToRecipe.lookup(Member)) {
+            auto *LoadR = cast<VPWidenLoadRecipe>(MemberR->getAsRecipe());
+            VPBuilder Builder(LoadR);
+            VPValue *Base = MemberR->getAddr();
+            Type *IndexTy = DL.getIndexType(Base->getScalarType());
+            VPValue *StepVec =
+                Builder.createNaryOp(VPInstruction::StepVector, {}, IndexTy);
+            int64_t Stride = IG->getFactor();
+            if (IG->isReverse())
+              Stride = -Stride;
+            VPValue *StrideVPV = Plan.getConstantInt(IndexTy, (uint64_t)Stride,
+                                                     /*IsSigned=*/true);
+            VPValue *Idx = Builder.createOverflowingOp(Instruction::Mul,
+                                                       {StepVec, StrideVPV});
+            auto *WidenGEP =
+                new VPWidenGEPRecipe(getLoadStoreType(Member), {Base, Idx}, {},
+                                     LoadR->getDebugLoc());
+            Builder.insert(WidenGEP);
+            LoadR->setOperand(0, WidenGEP);
+          }
+        }
       continue;
+    }
 
     auto *Start = IRMemberToRecipe.lookup(IG->getMember(0));
     VPIRMetadata InterleaveMD(*Start);
diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/transform-narrow-interleave-to-widen-memory-with-wide-ops-chained.ll b/llvm/test/Transforms/LoopVectorize/AArch64/transform-narrow-interleave-to-widen-memory-with-wide-ops-chained.ll
index f0f638f0dbbdd..4c963a87f95c8 100644
--- a/llvm/test/Transforms/LoopVectorize/AArch64/transform-narrow-interleave-to-widen-memory-with-wide-ops-chained.ll
+++ b/llvm/test/Transforms/LoopVectorize/AArch64/transform-narrow-interleave-to-widen-memory-with-wide-ops-chained.ll
@@ -299,8 +299,7 @@ define void @test_2xi64_mul_sub_mismatched_ops2(ptr noalias %data, ptr noalias %
 ; VF2-NEXT:    [[TMP4:%.*]] = sub <2 x i64> [[TMP3]], splat (i64 2)
 ; VF2-NEXT:    [[TMP9:%.*]] = or disjoint i64 [[TMP1]], 1
 ; VF2-NEXT:    [[TMP10:%.*]] = getelementptr inbounds i64, ptr [[DATA]], i64 [[TMP9]]
-; VF2-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x ptr> poison, ptr [[TMP10]], i64 0
-; VF2-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x ptr> [[BROADCAST_SPLATINSERT]], <2 x ptr> poison, <2 x i32> zeroinitializer
+; VF2-NEXT:    [[BROADCAST_SPLAT:%.*]] = getelementptr i64, ptr [[TMP10]], <2 x i64> <i64 0, i64 2>
 ; VF2-NEXT:    [[STRIDED_VEC1:%.*]] = call <2 x i64> @llvm.masked.gather.v2i64.v2p0(<2 x ptr> align 8 [[BROADCAST_SPLAT]], <2 x i1> splat (i1 true), <2 x i64> poison)
 ; VF2-NEXT:    [[TMP5:%.*]] = mul <2 x i64> [[WIDE_LOAD]], [[STRIDED_VEC1]]
 ; VF2-NEXT:    [[TMP6:%.*]] = sub <2 x i64> [[TMP5]], splat (i64 2)
@@ -599,8 +598,7 @@ define void @test_2xi64_mul_add_xor_mismatched_ops(ptr noalias %data, ptr noalia
 ; VF2-NEXT:    [[TMP5:%.*]] = xor <2 x i64> splat (i64 4), [[TMP4]]
 ; VF2-NEXT:    [[TMP11:%.*]] = or disjoint i64 [[TMP1]], 1
 ; VF2-NEXT:    [[TMP12:%.*]] = getelementptr inbounds i64, ptr [[DATA]], i64 [[TMP11]]
-; VF2-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x ptr> poison, ptr [[TMP12]], i64 0
-; VF2-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x ptr> [[BROADCAST_SPLATINSERT]], <2 x ptr> poison, <2 x i32> zeroinitializer
+; VF2-NEXT:    [[BROADCAST_SPLAT:%.*]] = getelementptr i64, ptr [[TMP12]], <2 x i64> <i64 0, i64 2>
 ; VF2-NEXT:    [[STRIDED_VEC1:%.*]] = call <2 x i64> @llvm.masked.gather.v2i64.v2p0(<2 x ptr> align 8 [[BROADCAST_SPLAT]], <2 x i1> splat (i1 true), <2 x i64> poison)
 ; VF2-NEXT:    [[TMP6:%.*]] = mul <2 x i64> [[WIDE_LOAD]], [[STRIDED_VEC1]]
 ; VF2-NEXT:    [[TMP7:%.*]] = add <2 x i64> [[TMP6]], splat (i64 2)
diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/dead-ops-cost.ll b/llvm/test/Transforms/LoopVectorize/RISCV/dead-ops-cost.ll
index a9db4458a34ff..0c2291564eb80 100644
--- a/llvm/test/Transforms/LoopVectorize/RISCV/dead-ops-cost.ll
+++ b/llvm/test/Transforms/LoopVectorize/RISCV/dead-ops-cost.ll
@@ -349,6 +349,7 @@ define void @gather_interleave_group_with_dead_insert_pos(i64 %N, ptr noalias %s
 ; CHECK-NEXT:    br label %[[VECTOR_PH:.*]]
 ; CHECK:       [[VECTOR_PH]]:
 ; CHECK-NEXT:    [[TMP9:%.*]] = call <vscale x 4 x i64> @llvm.stepvector.nxv4i64()
+; CHECK-NEXT:    [[TMP5:%.*]] = shl <vscale x 4 x i64> [[TMP9]], splat (i64 1)
 ; CHECK-NEXT:    [[TMP4:%.*]] = mul nsw <vscale x 4 x i64> [[TMP9]], splat (i64 2)
 ; CHECK-NEXT:    br label %[[VECTOR_BODY:.*]]
 ; CHECK:       [[VECTOR_BODY]]:
@@ -363,8 +364,7 @@ define void @gather_interleave_group_with_dead_insert_pos(i64 %N, ptr noalias %s
 ; CHECK-NEXT:    [[OFFSET_IDX:%.*]] = shl i64 [[EVL_BASED_IV]], 1
 ; CHECK-NEXT:    [[TMP11:%.*]] = add i64 [[OFFSET_IDX]], 1
 ; CHECK-NEXT:    [[TMP22:%.*]] = getelementptr i8, ptr [[SRC]], i64 [[TMP11]]
-; CHECK-NEXT:    [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <vscale x 4 x ptr> poison, ptr [[TMP22]], i64 0
-; CHECK-NEXT:    [[BROADCAST_SPLAT2:%.*]] = shufflevector <vscale x 4 x ptr> [[BROADCAST_SPLATINSERT1]], <vscale x 4 x ptr> poison, <vscale x 4 x i32> zeroinitializer
+; CHECK-NEXT:    [[BROADCAST_SPLAT2:%.*]] = getelementptr i8, ptr [[TMP22]], <vscale x 4 x i64> [[TMP5]]
 ; CHECK-NEXT:    [[TMP17:%.*]] = call <vscale x 4 x i8> @llvm.vp.gather.nxv4i8.nxv4p0(<vscale x 4 x ptr> align 1 [[BROADCAST_SPLAT2]], <vscale x 4 x i1> splat (i1 true), i32 [[TMP10]])
 ; CHECK-NEXT:    [[TMP18:%.*]] = zext <vscale x 4 x i8> [[TMP17]] to <vscale x 4 x i32>
 ; CHECK-NEXT:    [[TMP19:%.*]] = getelementptr i32, ptr [[DST]], <vscale x 4 x i64> [[VEC_IND]]
diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/pointer-induction.ll b/llvm/test/Transforms/LoopVectorize/RISCV/pointer-induction.ll
index 792fac2a5e206..ceaf34511dbbc 100644
--- a/llvm/test/Transforms/LoopVectorize/RISCV/pointer-induction.ll
+++ b/llvm/test/Transforms/LoopVectorize/RISCV/pointer-induction.ll
@@ -209,15 +209,16 @@ define i1 @scalarize_ptr_induction(ptr %start, ptr %end, ptr noalias %dst, i1 %c
 ; NO-FOLDING-NEXT:    [[N_VEC:%.*]] = sub i64 [[TMP3]], [[TMP14]]
 ; NO-FOLDING-NEXT:    [[TMP15:%.*]] = mul i64 [[N_VEC]], 12
 ; NO-FOLDING-NEXT:    [[TMP16:%.*]] = getelementptr i8, ptr [[START]], i64 [[TMP15]]
+; NO-FOLDING-NEXT:    [[TMP27:%.*]] = call <vscale x 2 x i64> @llvm.stepvector.nxv2i64()
+; NO-FOLDING-NEXT:    [[TMP28:%.*]] = mul <vscale x 2 x i64> [[TMP27]], splat (i64 3)
 ; NO-FOLDING-NEXT:    br label %[[VECTOR_BODY:.*]]
 ; NO-FOLDING:       [[VECTOR_BODY]]:
 ; NO-FOLDING-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
 ; NO-FOLDING-NEXT:    [[TMP17:%.*]] = mul i64 [[INDEX]], 12
 ; NO-FOLDING-NEXT:    [[NEXT_GEP:%.*]] = getelementptr i8, ptr [[START]], i64 [[TMP17]]
 ; NO-FOLDING-NEXT:    [[TMP18:%.*]] = getelementptr i8, ptr [[NEXT_GEP]], i64 4
-; NO-FOLDING-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 2 x ptr> poison, ptr [[TMP18]], i64 0
-; NO-FOLDING-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 2 x ptr> [[BROADCAST_SPLATINSERT]], <vscale x 2 x ptr> poison, <vscale x 2 x i32> zeroinitializer
-; NO-FOLDING-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 2 x i32> @llvm.masked.gather.nxv2i32.nxv2p0(<vscale x 2 x ptr> align 4 [[BROADCAST_SPLAT]], <vscale x 2 x i1> splat (i1 true), <vscale x 2 x i32> poison), !alias.scope [[META4:![0-9]+]]
+; NO-FOLDING-NEXT:    [[WIDE_GEP:%.*]] = getelementptr i32, ptr [[TMP18]], <vscale x 2 x i64> [[TMP28]]
+; NO-FOLDING-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 2 x i32> @llvm.masked.gather.nxv2i32.nxv2p0(<vscale x 2 x ptr> align 4 [[WIDE_GEP]], <vscale x 2 x i1> splat (i1 true), <vscale x 2 x i32> poison), !alias.scope [[META4:![0-9]+]]
 ; NO-FOLDING-NEXT:    [[TMP19:%.*]] = zext <vscale x 2 x i32> [[WIDE_MASKED_GATHER]] to <vscale x 2 x i64>
 ; NO-FOLDING-NEXT:    [[TMP20:%.*]] = mul <vscale x 2 x i64> [[TMP19]], splat (i64 -7070675565921424023)
 ; NO-FOLDING-NEXT:    [[TMP21:%.*]] = add <vscale x 2 x i64> [[TMP20]], splat (i64 -4)
diff --git a/llvm/test/Transforms/LoopVectorize/consecutive-ptr-uniforms.ll b/llvm/test/Transforms/LoopVectorize/consecutive-ptr-uniforms.ll
index 50f5d417be7ad..5bd1d613417f4 100644
--- a/llvm/test/Transforms/LoopVectorize/consecutive-ptr-uniforms.ll
+++ b/llvm/test/Transforms/LoopVectorize/consecutive-ptr-uniforms.ll
@@ -1065,7 +1065,8 @@ define void @pointer_iv_non_uniform_0(ptr %a, i64 %n) {
 ; INTER-NEXT:    [[TMP32:%.*]] = insertelement <4 x ptr> [[TMP31]], ptr [[TMP28]], i32 1
 ; INTER-NEXT:    [[TMP33:%.*]] = insertelement <4 x ptr> [[TMP32]], ptr [[TMP29]], i32 2
 ; INTER-NEXT:    [[TMP34:%.*]] = insertelement <4 x ptr> [[TMP33]], ptr [[TMP30]], i32 3
-; INTER-NEXT:    [[STRIDED_VEC6:%.*]] = call <4 x i32> @llvm.masked.gather.v4i32.v4p0(<4 x ptr> align 8 [[TMP34]], <4 x i1> splat (i1 true), <4 x i32> poison)
+; INTER-NEXT:    [[WIDE_GEP:%.*]] = getelementptr i32, <4 x ptr> [[TMP34]], <4 x i64> <i64 0, i64 4, i64 8, i64 12>
+; INTER-NEXT:    [[STRIDED_VEC6:%.*]] = call <4 x i32> @llvm.masked.gather.v4i32.v4p0(<4 x ptr> align 8 [[WIDE_GEP]], <4 x i1> splat (i1 true), <4 x i32> poison)
 ; INTER-NEXT:    [[TMP17:%.*]] = sub <4 x i32> [[STRIDED_VEC6]], [[STRIDED_VEC]]
 ; INTER-NEXT:    [[TMP18:%.*]] = sub <4 x i32> [[STRIDED_VEC]], [[STRIDED_VEC4]]
 ; INTER-NEXT:    [[TMP9:%.*]] = getelementptr inbounds i32, ptr [[NEXT_GEP]], i32 2

>From fd2a80a6ca96b954662cac6da4b313f0ef401e3c Mon Sep 17 00:00:00 2001
From: Mel Chen <mel.chen at sifive.com>
Date: Tue, 23 Jun 2026 02:37:46 -0700
Subject: [PATCH 4/7] rebase and update

---
 .../LoopVectorize/RISCV/pointer-induction.ll           | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/pointer-induction.ll b/llvm/test/Transforms/LoopVectorize/RISCV/pointer-induction.ll
index ceaf34511dbbc..f52710895fd94 100644
--- a/llvm/test/Transforms/LoopVectorize/RISCV/pointer-induction.ll
+++ b/llvm/test/Transforms/LoopVectorize/RISCV/pointer-induction.ll
@@ -219,6 +219,10 @@ define i1 @scalarize_ptr_induction(ptr %start, ptr %end, ptr noalias %dst, i1 %c
 ; NO-FOLDING-NEXT:    [[TMP18:%.*]] = getelementptr i8, ptr [[NEXT_GEP]], i64 4
 ; NO-FOLDING-NEXT:    [[WIDE_GEP:%.*]] = getelementptr i32, ptr [[TMP18]], <vscale x 2 x i64> [[TMP28]]
 ; NO-FOLDING-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 2 x i32> @llvm.masked.gather.nxv2i32.nxv2p0(<vscale x 2 x ptr> align 4 [[WIDE_GEP]], <vscale x 2 x i1> splat (i1 true), <vscale x 2 x i32> poison), !alias.scope [[META4:![0-9]+]]
+; NO-FOLDING-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP12]]
+; NO-FOLDING-NEXT:    [[TMP26:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
+; NO-FOLDING-NEXT:    br i1 [[TMP26]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP7:![0-9]+]]
+; NO-FOLDING:       [[MIDDLE_BLOCK]]:
 ; NO-FOLDING-NEXT:    [[TMP19:%.*]] = zext <vscale x 2 x i32> [[WIDE_MASKED_GATHER]] to <vscale x 2 x i64>
 ; NO-FOLDING-NEXT:    [[TMP20:%.*]] = mul <vscale x 2 x i64> [[TMP19]], splat (i64 -7070675565921424023)
 ; NO-FOLDING-NEXT:    [[TMP21:%.*]] = add <vscale x 2 x i64> [[TMP20]], splat (i64 -4)
@@ -226,11 +230,7 @@ define i1 @scalarize_ptr_induction(ptr %start, ptr %end, ptr noalias %dst, i1 %c
 ; NO-FOLDING-NEXT:    [[TMP23:%.*]] = mul nuw i32 [[TMP22]], 2
 ; NO-FOLDING-NEXT:    [[TMP24:%.*]] = sub i32 [[TMP23]], 1
 ; NO-FOLDING-NEXT:    [[TMP25:%.*]] = extractelement <vscale x 2 x i64> [[TMP21]], i32 [[TMP24]]
-; NO-FOLDING-NEXT:    store i64 [[TMP25]], ptr [[DST]], align 1, !alias.scope [[META7:![0-9]+]], !noalias [[META4]]
-; NO-FOLDING-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP12]]
-; NO-FOLDING-NEXT:    [[TMP26:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
-; NO-FOLDING-NEXT:    br i1 [[TMP26]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP9:![0-9]+]]
-; NO-FOLDING:       [[MIDDLE_BLOCK]]:
+; NO-FOLDING-NEXT:    store i64 [[TMP25]], ptr [[DST]], align 1, !alias.scope [[META8:![0-9]+]], !noalias [[META4]]
 ; NO-FOLDING-NEXT:    br label %[[SCALAR_PH]]
 ; NO-FOLDING:       [[SCALAR_PH]]:
 ; NO-FOLDING-NEXT:    [[BC_RESUME_VAL:%.*]] = phi ptr [ [[TMP16]], %[[MIDDLE_BLOCK]] ], [ [[START]], %[[ENTRY]] ], [ [[START]], %[[VECTOR_MEMCHECK]] ]

>From b378a682fbbe83880ebc1d5ae80a5bb5bca2f627 Mon Sep 17 00:00:00 2001
From: Mel Chen <mel.chen at sifive.com>
Date: Tue, 23 Jun 2026 02:58:15 -0700
Subject: [PATCH 5/7] reduce nested if

---
 .../Transforms/Vectorize/VPlanTransforms.cpp  | 50 ++++++++++---------
 1 file changed, 26 insertions(+), 24 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 70adfcfb0c8ec..9d7097dd1e340 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -3752,30 +3752,32 @@ void VPlanTransforms::createInterleaveGroups(
           return !IRMemberToRecipe.contains(Member);
         })) {
       auto &DL = Plan.getDataLayout();
-      for (unsigned I = 0; I < IG->getFactor(); ++I)
-        if (Instruction *Member = IG->getMember(I)) {
-          // Fix addresses of members that still have recipes.
-          if (auto *MemberR = IRMemberToRecipe.lookup(Member)) {
-            auto *LoadR = cast<VPWidenLoadRecipe>(MemberR->getAsRecipe());
-            VPBuilder Builder(LoadR);
-            VPValue *Base = MemberR->getAddr();
-            Type *IndexTy = DL.getIndexType(Base->getScalarType());
-            VPValue *StepVec =
-                Builder.createNaryOp(VPInstruction::StepVector, {}, IndexTy);
-            int64_t Stride = IG->getFactor();
-            if (IG->isReverse())
-              Stride = -Stride;
-            VPValue *StrideVPV = Plan.getConstantInt(IndexTy, (uint64_t)Stride,
-                                                     /*IsSigned=*/true);
-            VPValue *Idx = Builder.createOverflowingOp(Instruction::Mul,
-                                                       {StepVec, StrideVPV});
-            auto *WidenGEP =
-                new VPWidenGEPRecipe(getLoadStoreType(Member), {Base, Idx}, {},
-                                     LoadR->getDebugLoc());
-            Builder.insert(WidenGEP);
-            LoadR->setOperand(0, WidenGEP);
-          }
-        }
+      for (unsigned I = 0; I < IG->getFactor(); ++I) {
+        Instruction *Member = IG->getMember(I);
+        if (!Member)
+          continue;
+        auto *MemberR = IRMemberToRecipe.lookup(Member);
+        if (!MemberR)
+          continue;
+        // Fix addresses of members that still have recipes.
+        auto *LoadR = cast<VPWidenLoadRecipe>(MemberR->getAsRecipe());
+        VPBuilder Builder(LoadR);
+        VPValue *Base = MemberR->getAddr();
+        Type *IndexTy = DL.getIndexType(Base->getScalarType());
+        VPValue *StepVec =
+            Builder.createNaryOp(VPInstruction::StepVector, {}, IndexTy);
+        int64_t Stride = IG->getFactor();
+        if (IG->isReverse())
+          Stride = -Stride;
+        VPValue *StrideVPV = Plan.getConstantInt(IndexTy, (uint64_t)Stride,
+                                                 /*IsSigned=*/true);
+        VPValue *Idx =
+            Builder.createOverflowingOp(Instruction::Mul, {StepVec, StrideVPV});
+        auto *WidenGEP = new VPWidenGEPRecipe(
+            getLoadStoreType(Member), {Base, Idx}, {}, LoadR->getDebugLoc());
+        Builder.insert(WidenGEP);
+        LoadR->setOperand(0, WidenGEP);
+      }
       continue;
     }
 

>From ee554b6c3c477344fb3cd7efc1b9b0eee90bdadc Mon Sep 17 00:00:00 2001
From: Mel Chen <mel.chen at sifive.com>
Date: Wed, 8 Jul 2026 01:49:17 -0700
Subject: [PATCH 6/7] only fix address if it is uniform

---
 .../Transforms/Vectorize/VPlanTransforms.cpp  |  2 +
 .../LoopVectorize/RISCV/pointer-induction.ll  | 42 ++++++-------------
 .../LoopVectorize/consecutive-ptr-uniforms.ll |  3 +-
 3 files changed, 16 insertions(+), 31 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 9d7097dd1e340..cd5eddb5dcc94 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -3763,6 +3763,8 @@ void VPlanTransforms::createInterleaveGroups(
         auto *LoadR = cast<VPWidenLoadRecipe>(MemberR->getAsRecipe());
         VPBuilder Builder(LoadR);
         VPValue *Base = MemberR->getAddr();
+        if (!vputils::isSingleScalar(Base))
+          continue;
         Type *IndexTy = DL.getIndexType(Base->getScalarType());
         VPValue *StepVec =
             Builder.createNaryOp(VPInstruction::StepVector, {}, IndexTy);
diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/pointer-induction.ll b/llvm/test/Transforms/LoopVectorize/RISCV/pointer-induction.ll
index f52710895fd94..761d1de23d9c4 100644
--- a/llvm/test/Transforms/LoopVectorize/RISCV/pointer-induction.ll
+++ b/llvm/test/Transforms/LoopVectorize/RISCV/pointer-induction.ll
@@ -175,34 +175,18 @@ define i1 @scalarize_ptr_induction(ptr %start, ptr %end, ptr noalias %dst, i1 %c
 ; NO-FOLDING-LABEL: define i1 @scalarize_ptr_induction(
 ; NO-FOLDING-SAME: ptr [[START:%.*]], ptr [[END:%.*]], ptr noalias [[DST:%.*]], i1 [[C:%.*]]) #[[ATTR1:[0-9]+]] {
 ; NO-FOLDING-NEXT:  [[ENTRY:.*]]:
-; NO-FOLDING-NEXT:    [[START5:%.*]] = ptrtoint ptr [[START]] to i64
-; NO-FOLDING-NEXT:    [[END4:%.*]] = ptrtoint ptr [[END]] to i64
 ; NO-FOLDING-NEXT:    [[START2:%.*]] = ptrtoint ptr [[START]] to i64
 ; NO-FOLDING-NEXT:    [[END1:%.*]] = ptrtoint ptr [[END]] to i64
-; NO-FOLDING-NEXT:    [[TMP0:%.*]] = add i64 [[END4]], -12
-; NO-FOLDING-NEXT:    [[TMP1:%.*]] = sub i64 [[TMP0]], [[START5]]
+; NO-FOLDING-NEXT:    [[TMP0:%.*]] = add i64 [[END1]], -12
+; NO-FOLDING-NEXT:    [[TMP1:%.*]] = sub i64 [[TMP0]], [[START2]]
 ; NO-FOLDING-NEXT:    [[TMP2:%.*]] = udiv i64 [[TMP1]], 12
 ; NO-FOLDING-NEXT:    [[TMP3:%.*]] = add nuw nsw i64 [[TMP2]], 1
 ; NO-FOLDING-NEXT:    [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
 ; NO-FOLDING-NEXT:    [[TMP5:%.*]] = shl nuw i64 [[TMP4]], 1
-; NO-FOLDING-NEXT:    [[UMAX:%.*]] = call i64 @llvm.umax.i64(i64 [[TMP5]], i64 24)
-; NO-FOLDING-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ule i64 [[TMP3]], [[UMAX]]
-; NO-FOLDING-NEXT:    br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_MEMCHECK:.*]]
-; NO-FOLDING:       [[VECTOR_MEMCHECK]]:
-; NO-FOLDING-NEXT:    [[SCEVGEP:%.*]] = getelementptr i8, ptr [[DST]], i64 8
-; NO-FOLDING-NEXT:    [[TMP6:%.*]] = add i64 [[END1]], -12
-; NO-FOLDING-NEXT:    [[TMP7:%.*]] = sub i64 [[TMP6]], [[START2]]
-; NO-FOLDING-NEXT:    [[TMP8:%.*]] = udiv i64 [[TMP7]], 12
-; NO-FOLDING-NEXT:    [[TMP9:%.*]] = mul nuw i64 [[TMP8]], 12
-; NO-FOLDING-NEXT:    [[TMP10:%.*]] = add i64 [[TMP9]], 8
-; NO-FOLDING-NEXT:    [[SCEVGEP3:%.*]] = getelementptr i8, ptr [[START]], i64 [[TMP10]]
-; NO-FOLDING-NEXT:    [[BOUND0:%.*]] = icmp ult ptr [[DST]], [[SCEVGEP3]]
-; NO-FOLDING-NEXT:    [[BOUND1:%.*]] = icmp ult ptr [[START]], [[SCEVGEP]]
-; NO-FOLDING-NEXT:    [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
-; NO-FOLDING-NEXT:    br i1 [[FOUND_CONFLICT]], label %[[SCALAR_PH]], label %[[VECTOR_PH:.*]]
+; NO-FOLDING-NEXT:    [[FOUND_CONFLICT:%.*]] = icmp ule i64 [[TMP3]], [[TMP5]]
+; NO-FOLDING-NEXT:    br i1 [[FOUND_CONFLICT]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
 ; NO-FOLDING:       [[VECTOR_PH]]:
-; NO-FOLDING-NEXT:    [[TMP11:%.*]] = call i64 @llvm.vscale.i64()
-; NO-FOLDING-NEXT:    [[TMP12:%.*]] = shl nuw i64 [[TMP11]], 1
+; NO-FOLDING-NEXT:    [[TMP12:%.*]] = shl nuw i64 [[TMP4]], 1
 ; NO-FOLDING-NEXT:    [[N_MOD_VF:%.*]] = urem i64 [[TMP3]], [[TMP12]]
 ; NO-FOLDING-NEXT:    [[TMP13:%.*]] = icmp eq i64 [[N_MOD_VF]], 0
 ; NO-FOLDING-NEXT:    [[TMP14:%.*]] = select i1 [[TMP13]], i64 [[TMP12]], i64 [[N_MOD_VF]]
@@ -218,11 +202,7 @@ define i1 @scalarize_ptr_induction(ptr %start, ptr %end, ptr noalias %dst, i1 %c
 ; NO-FOLDING-NEXT:    [[NEXT_GEP:%.*]] = getelementptr i8, ptr [[START]], i64 [[TMP17]]
 ; NO-FOLDING-NEXT:    [[TMP18:%.*]] = getelementptr i8, ptr [[NEXT_GEP]], i64 4
 ; NO-FOLDING-NEXT:    [[WIDE_GEP:%.*]] = getelementptr i32, ptr [[TMP18]], <vscale x 2 x i64> [[TMP28]]
-; NO-FOLDING-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 2 x i32> @llvm.masked.gather.nxv2i32.nxv2p0(<vscale x 2 x ptr> align 4 [[WIDE_GEP]], <vscale x 2 x i1> splat (i1 true), <vscale x 2 x i32> poison), !alias.scope [[META4:![0-9]+]]
-; NO-FOLDING-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP12]]
-; NO-FOLDING-NEXT:    [[TMP26:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
-; NO-FOLDING-NEXT:    br i1 [[TMP26]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP7:![0-9]+]]
-; NO-FOLDING:       [[MIDDLE_BLOCK]]:
+; NO-FOLDING-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 2 x i32> @llvm.masked.gather.nxv2i32.nxv2p0(<vscale x 2 x ptr> align 4 [[WIDE_GEP]], <vscale x 2 x i1> splat (i1 true), <vscale x 2 x i32> poison)
 ; NO-FOLDING-NEXT:    [[TMP19:%.*]] = zext <vscale x 2 x i32> [[WIDE_MASKED_GATHER]] to <vscale x 2 x i64>
 ; NO-FOLDING-NEXT:    [[TMP20:%.*]] = mul <vscale x 2 x i64> [[TMP19]], splat (i64 -7070675565921424023)
 ; NO-FOLDING-NEXT:    [[TMP21:%.*]] = add <vscale x 2 x i64> [[TMP20]], splat (i64 -4)
@@ -230,10 +210,14 @@ define i1 @scalarize_ptr_induction(ptr %start, ptr %end, ptr noalias %dst, i1 %c
 ; NO-FOLDING-NEXT:    [[TMP23:%.*]] = mul nuw i32 [[TMP22]], 2
 ; NO-FOLDING-NEXT:    [[TMP24:%.*]] = sub i32 [[TMP23]], 1
 ; NO-FOLDING-NEXT:    [[TMP25:%.*]] = extractelement <vscale x 2 x i64> [[TMP21]], i32 [[TMP24]]
-; NO-FOLDING-NEXT:    store i64 [[TMP25]], ptr [[DST]], align 1, !alias.scope [[META8:![0-9]+]], !noalias [[META4]]
+; NO-FOLDING-NEXT:    store i64 [[TMP25]], ptr [[DST]], align 1
+; NO-FOLDING-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP12]]
+; NO-FOLDING-NEXT:    [[TMP26:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
+; NO-FOLDING-NEXT:    br i1 [[TMP26]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
+; NO-FOLDING:       [[MIDDLE_BLOCK]]:
 ; NO-FOLDING-NEXT:    br label %[[SCALAR_PH]]
 ; NO-FOLDING:       [[SCALAR_PH]]:
-; NO-FOLDING-NEXT:    [[BC_RESUME_VAL:%.*]] = phi ptr [ [[TMP16]], %[[MIDDLE_BLOCK]] ], [ [[START]], %[[ENTRY]] ], [ [[START]], %[[VECTOR_MEMCHECK]] ]
+; NO-FOLDING-NEXT:    [[BC_RESUME_VAL:%.*]] = phi ptr [ [[TMP16]], %[[MIDDLE_BLOCK]] ], [ [[START]], %[[ENTRY]] ]
 ; NO-FOLDING-NEXT:    br label %[[LOOP:.*]]
 ; NO-FOLDING:       [[LOOP]]:
 ; NO-FOLDING-NEXT:    [[PTR_IV:%.*]] = phi ptr [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[PTR_IV_NEXT:%.*]], %[[LOOP]] ]
@@ -246,7 +230,7 @@ define i1 @scalarize_ptr_induction(ptr %start, ptr %end, ptr noalias %dst, i1 %c
 ; NO-FOLDING-NEXT:    store i64 [[MUL2]], ptr [[DST]], align 1
 ; NO-FOLDING-NEXT:    [[PTR_IV_NEXT]] = getelementptr nusw i8, ptr [[PTR_IV]], i64 12
 ; NO-FOLDING-NEXT:    [[CMP:%.*]] = icmp eq ptr [[PTR_IV_NEXT]], [[END]]
-; NO-FOLDING-NEXT:    br i1 [[CMP]], label %[[EXIT:.*]], label %[[LOOP]], !llvm.loop [[LOOP10:![0-9]+]]
+; NO-FOLDING-NEXT:    br i1 [[CMP]], label %[[EXIT:.*]], label %[[LOOP]], !llvm.loop [[LOOP5:![0-9]+]]
 ; NO-FOLDING:       [[EXIT]]:
 ; NO-FOLDING-NEXT:    [[CMP_LCSSA:%.*]] = phi i1 [ [[CMP]], %[[LOOP]] ]
 ; NO-FOLDING-NEXT:    ret i1 [[CMP_LCSSA]]
diff --git a/llvm/test/Transforms/LoopVectorize/consecutive-ptr-uniforms.ll b/llvm/test/Transforms/LoopVectorize/consecutive-ptr-uniforms.ll
index 5bd1d613417f4..50f5d417be7ad 100644
--- a/llvm/test/Transforms/LoopVectorize/consecutive-ptr-uniforms.ll
+++ b/llvm/test/Transforms/LoopVectorize/consecutive-ptr-uniforms.ll
@@ -1065,8 +1065,7 @@ define void @pointer_iv_non_uniform_0(ptr %a, i64 %n) {
 ; INTER-NEXT:    [[TMP32:%.*]] = insertelement <4 x ptr> [[TMP31]], ptr [[TMP28]], i32 1
 ; INTER-NEXT:    [[TMP33:%.*]] = insertelement <4 x ptr> [[TMP32]], ptr [[TMP29]], i32 2
 ; INTER-NEXT:    [[TMP34:%.*]] = insertelement <4 x ptr> [[TMP33]], ptr [[TMP30]], i32 3
-; INTER-NEXT:    [[WIDE_GEP:%.*]] = getelementptr i32, <4 x ptr> [[TMP34]], <4 x i64> <i64 0, i64 4, i64 8, i64 12>
-; INTER-NEXT:    [[STRIDED_VEC6:%.*]] = call <4 x i32> @llvm.masked.gather.v4i32.v4p0(<4 x ptr> align 8 [[WIDE_GEP]], <4 x i1> splat (i1 true), <4 x i32> poison)
+; INTER-NEXT:    [[STRIDED_VEC6:%.*]] = call <4 x i32> @llvm.masked.gather.v4i32.v4p0(<4 x ptr> align 8 [[TMP34]], <4 x i1> splat (i1 true), <4 x i32> poison)
 ; INTER-NEXT:    [[TMP17:%.*]] = sub <4 x i32> [[STRIDED_VEC6]], [[STRIDED_VEC]]
 ; INTER-NEXT:    [[TMP18:%.*]] = sub <4 x i32> [[STRIDED_VEC]], [[STRIDED_VEC4]]
 ; INTER-NEXT:    [[TMP9:%.*]] = getelementptr inbounds i32, ptr [[NEXT_GEP]], i32 2

>From 8a95f455df7018f717a4080f568125fc9e22c4d7 Mon Sep 17 00:00:00 2001
From: Mel Chen <mel.chen at sifive.com>
Date: Wed, 8 Jul 2026 03:17:09 -0700
Subject: [PATCH 7/7] test versioning case

---
 .../Transforms/LoopVectorize/versioning-dead-load.ll     | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/llvm/test/Transforms/LoopVectorize/versioning-dead-load.ll b/llvm/test/Transforms/LoopVectorize/versioning-dead-load.ll
index d5a971cb6e6cd..65a9859a43a2f 100644
--- a/llvm/test/Transforms/LoopVectorize/versioning-dead-load.ll
+++ b/llvm/test/Transforms/LoopVectorize/versioning-dead-load.ll
@@ -17,8 +17,7 @@ define void @f(ptr noalias %p, ptr noalias %q, ptr noalias %dst, i64 %stride) {
 ; VF4UF1-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
 ; VF4UF1-NEXT:    [[TMP0:%.*]] = shl nuw nsw i64 [[INDEX]], 3
 ; VF4UF1-NEXT:    [[TMP1:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i64 [[TMP0]]
-; VF4UF1-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x ptr> poison, ptr [[TMP1]], i64 0
-; VF4UF1-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x ptr> [[BROADCAST_SPLATINSERT]], <4 x ptr> poison, <4 x i32> zeroinitializer
+; VF4UF1-NEXT:    [[BROADCAST_SPLAT:%.*]] = getelementptr i32, ptr [[TMP1]], <4 x i64> <i64 0, i64 2, i64 4, i64 6>
 ; VF4UF1-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <4 x i32> @llvm.masked.gather.v4i32.v4p0(<4 x ptr> align 4 [[BROADCAST_SPLAT]], <4 x i1> splat (i1 true), <4 x i32> poison)
 ; VF4UF1-NEXT:    [[TMP2:%.*]] = getelementptr inbounds [4 x i8], ptr [[Q]], i64 [[INDEX]]
 ; VF4UF1-NEXT:    store <4 x i32> [[WIDE_MASKED_GATHER]], ptr [[TMP2]], align 4
@@ -133,11 +132,9 @@ define void @f(ptr noalias %p, ptr noalias %q, ptr noalias %dst, i64 %stride) {
 ; VF2UF2-NEXT:    [[TMP1:%.*]] = shl nuw nsw i64 [[INDEX]], 3
 ; VF2UF2-NEXT:    [[TMP2:%.*]] = shl nuw nsw i64 [[TMP0]], 3
 ; VF2UF2-NEXT:    [[TMP3:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i64 [[TMP1]]
-; VF2UF2-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x ptr> poison, ptr [[TMP3]], i64 0
-; VF2UF2-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x ptr> [[BROADCAST_SPLATINSERT]], <2 x ptr> poison, <2 x i32> zeroinitializer
 ; VF2UF2-NEXT:    [[TMP4:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i64 [[TMP2]]
-; VF2UF2-NEXT:    [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <2 x ptr> poison, ptr [[TMP4]], i64 0
-; VF2UF2-NEXT:    [[BROADCAST_SPLAT2:%.*]] = shufflevector <2 x ptr> [[BROADCAST_SPLATINSERT1]], <2 x ptr> poison, <2 x i32> zeroinitializer
+; VF2UF2-NEXT:    [[BROADCAST_SPLAT:%.*]] = getelementptr i32, ptr [[TMP3]], <2 x i64> <i64 0, i64 2>
+; VF2UF2-NEXT:    [[BROADCAST_SPLAT2:%.*]] = getelementptr i32, ptr [[TMP4]], <2 x i64> <i64 0, i64 2>
 ; VF2UF2-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = call <2 x i32> @llvm.masked.gather.v2i32.v2p0(<2 x ptr> align 4 [[BROADCAST_SPLAT]], <2 x i1> splat (i1 true), <2 x i32> poison)
 ; VF2UF2-NEXT:    [[WIDE_MASKED_GATHER3:%.*]] = call <2 x i32> @llvm.masked.gather.v2i32.v2p0(<2 x ptr> align 4 [[BROADCAST_SPLAT2]], <2 x i1> splat (i1 true), <2 x i32> poison)
 ; VF2UF2-NEXT:    [[TMP5:%.*]] = getelementptr inbounds [4 x i8], ptr [[Q]], i64 [[INDEX]]



More information about the llvm-commits mailing list