[llvm-branch-commits] [llvm] f51e696 - [VPlan] Don't look through FOR splices in isUsedByLoadStoreAddress. (#233141)
Douglas Yung via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Nov 19 21:01:28 PST 2026
Author: Florian Hahn
Date: 2026-11-20T05:01:13Z
New Revision: f51e6963e4edfefbc23dad9b81e5c762f01de4b8
URL: https://github.com/llvm/llvm-project/commit/f51e6963e4edfefbc23dad9b81e5c762f01de4b8
DIFF: https://github.com/llvm/llvm-project/commit/f51e6963e4edfefbc23dad9b81e5c762f01de4b8.diff
LOG: [VPlan] Don't look through FOR splices in isUsedByLoadStoreAddress. (#233141)
isUsedByLoadStoreAddress incorrectly looked through recurrence splices.
This lead to makeVPlanMemOpDecision incorrectly replicating loads
(instead of widening), while the address is converted to a single-scalar
by legacy decision.
This fixes a miscompile in the added test.
(cherry picked from commit 22a203c0a2120105eaa78f45305f8f04a363cf14)
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
llvm/test/Transforms/LoopVectorize/AArch64/gather-do-not-vectorize-addressing.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
index 693c557c76f18b..0bb9fabb24930c 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
@@ -745,8 +745,10 @@ bool vputils::isUsedByLoadStoreAddress(const VPValue *V) {
// The legacy cost model only supports scalarization loads/stores with phi
// addresses, if the phi is directly used as load/store address. Don't
- // traverse further for Blends.
- if (Blend)
+ // traverse further for Blends and first-order recurrence splices.
+ if (Blend ||
+ match(Cur,
+ m_VPInstruction<VPInstruction::FirstOrderRecurrenceSplice>()))
continue;
// Only traverse further through users that also define a value (and can
diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/gather-do-not-vectorize-addressing.ll b/llvm/test/Transforms/LoopVectorize/AArch64/gather-do-not-vectorize-addressing.ll
index a1daa771eded1d..5e4548cbe72d19 100644
--- a/llvm/test/Transforms/LoopVectorize/AArch64/gather-do-not-vectorize-addressing.ll
+++ b/llvm/test/Transforms/LoopVectorize/AArch64/gather-do-not-vectorize-addressing.ll
@@ -165,10 +165,7 @@ define void @load_used_as_address_via_recurrence(ptr noalias %A, ptr noalias %sr
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
; CHECK-NEXT: [[VECTOR_RECUR:%.*]] = phi <2 x i64> [ <i64 poison, i64 0>, %[[VECTOR_PH]] ], [ [[TMP5:%.*]], %[[VECTOR_BODY]] ]
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i64, ptr [[SRC]], i64 [[INDEX]]
-; CHECK-NEXT: [[TMP2:%.*]] = load i64, ptr [[TMP1]], align 8
-; CHECK-NEXT: [[TMP3:%.*]] = load i64, ptr [[TMP1]], align 8
-; CHECK-NEXT: [[TMP4:%.*]] = insertelement <2 x i64> poison, i64 [[TMP2]], i32 0
-; CHECK-NEXT: [[TMP5]] = insertelement <2 x i64> [[TMP4]], i64 [[TMP3]], i32 1
+; CHECK-NEXT: [[TMP5]] = load <2 x i64>, ptr [[TMP1]], align 8
; CHECK-NEXT: [[TMP6:%.*]] = shufflevector <2 x i64> [[VECTOR_RECUR]], <2 x i64> [[TMP5]], <2 x i32> <i32 1, i32 2>
; CHECK-NEXT: [[TMP7:%.*]] = extractelement <2 x i64> [[TMP6]], i64 0
; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[TMP7]]
@@ -184,11 +181,12 @@ define void @load_used_as_address_via_recurrence(ptr noalias %A, ptr noalias %sr
; CHECK-NEXT: [[TMP16:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
; CHECK-NEXT: br i1 [[TMP16]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
; CHECK: [[MIDDLE_BLOCK]]:
+; CHECK-NEXT: [[VECTOR_RECUR_EXTRACT:%.*]] = extractelement <2 x i64> [[TMP5]], i64 1
; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]]
; CHECK-NEXT: br i1 [[CMP_N]], label %[[EXIT:.*]], label %[[SCALAR_PH]]
; CHECK: [[SCALAR_PH]]:
; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
-; CHECK-NEXT: [[SCALAR_RECUR_INIT:%.*]] = phi i64 [ [[TMP3]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
+; CHECK-NEXT: [[SCALAR_RECUR_INIT:%.*]] = phi i64 [ [[VECTOR_RECUR_EXTRACT]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
; CHECK-NEXT: br label %[[LOOP:.*]]
; CHECK: [[LOOP]]:
; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
More information about the llvm-branch-commits
mailing list