[llvm] [VPlan] Only fold ExtractLastLane if op is generates single-scalar. (PR #222448)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 9 14:08:00 PDT 2026
https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/222448
Replace the recursive isSingleScalar check with doesGenerateSingleScalar
from https://github.com/llvm/llvm-project/pull/222447.
The recursive check can lead to cases where we recursively determine
that the VPValue could be single-scalar, but for some reason it does not
get narrowed and produces a wide result in the end, leading to a crash
in the newly added test case.
Depends on https://github.com/llvm/llvm-project/pull/222447 (included in PR)
>From 3b52797a2064a5fd88d63719e1d119b003938247 Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Mon, 8 Jun 2026 18:01:36 +0100
Subject: [PATCH 1/2] [VPlan] Add doesGenerateSingleScalalar and use where
applicable. (NFCI)
Similar to #199047, factor out the non-recursive logic from isSingleScalar
to doesGenerateSingleScalar to determine single-scalar-ness encoded by the
recipe, without recursion.
Use the cheaper, non-recursive variant at sites where the recursive
result cannot differ or is not needed:
- VPCSEDenseMapInfo hash/equality: operands are compared separately, so
the recursive classification is fully determined including operands
in the hash
- materializePacksAndUnpacks, VPWidenGEPRecipe::usesFirstLaneOnly:
narrowToSingleScalar already scalarizes all relevant cases
explicitly.
---
.../Transforms/Vectorize/VPlanLowering.cpp | 2 +-
.../lib/Transforms/Vectorize/VPlanRecipes.cpp | 2 +-
.../Transforms/Vectorize/VPlanTransforms.cpp | 12 ++++---
llvm/lib/Transforms/Vectorize/VPlanUtils.cpp | 35 ++++++++++++-------
llvm/lib/Transforms/Vectorize/VPlanUtils.h | 4 +++
5 files changed, 36 insertions(+), 19 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanLowering.cpp b/llvm/lib/Transforms/Vectorize/VPlanLowering.cpp
index ddde0cd83a704..ce8f06c561b1b 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanLowering.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanLowering.cpp
@@ -851,7 +851,7 @@ void VPlanTransforms::materializePacksAndUnpacks(VPlan &Plan) {
// TODO: The Defs skipped here may or may not be vector values.
// Introduce Unpacks, and remove them later, if they are guaranteed to
// produce scalar values.
- if (vputils::isSingleScalar(Def))
+ if (vputils::doesGenerateSingleScalar(Def))
continue;
// Only introduce an Unpack if some, but not all, users use the first
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index c0beb2e825e52..7de75811944c4 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -3250,7 +3250,7 @@ void VPScalarIVStepsRecipe::printRecipe(raw_ostream &O, const Twine &Indent,
bool VPWidenGEPRecipe::usesFirstLaneOnly(const VPValue *Op) const {
assert(is_contained(operands(), Op) && "Op must be an operand of the recipe");
- return vputils::isSingleScalar(Op);
+ return vputils::doesGenerateSingleScalar(Op);
}
void VPWidenGEPRecipe::execute(VPTransformState &State) {
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index d12aec83f2856..8fe06568e2ac8 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -2264,10 +2264,11 @@ struct VPCSEDenseMapInfo : public DenseMapInfo<VPSingleDefRecipe *> {
/// Hash the underlying data of \p Def.
static unsigned getHashValue(const VPSingleDefRecipe *Def) {
- hash_code Result = hash_combine(
- Def->getVPRecipeID(), vputils::getOpcodeOrIntrinsicID(Def),
- getGEPSourceElementType(Def), Def->getScalarType(),
- vputils::isSingleScalar(Def), hash_combine_range(Def->operands()));
+ hash_code Result =
+ hash_combine(Def->getVPRecipeID(), vputils::getOpcodeOrIntrinsicID(Def),
+ getGEPSourceElementType(Def), Def->getScalarType(),
+ vputils::doesGenerateSingleScalar(Def),
+ hash_combine_range(Def->operands()));
if (auto *RFlags = dyn_cast<VPRecipeWithIRFlags>(Def))
if (RFlags->hasPredicate())
return hash_combine(Result, RFlags->getPredicate());
@@ -2286,7 +2287,8 @@ struct VPCSEDenseMapInfo : public DenseMapInfo<VPSingleDefRecipe *> {
vputils::getOpcodeOrIntrinsicID(L) !=
vputils::getOpcodeOrIntrinsicID(R) ||
getGEPSourceElementType(L) != getGEPSourceElementType(R) ||
- vputils::isSingleScalar(L) != vputils::isSingleScalar(R) ||
+ vputils::doesGenerateSingleScalar(L) !=
+ vputils::doesGenerateSingleScalar(R) ||
!equal(L->operands(), R->operands()))
return false;
assert(vputils::getOpcodeOrIntrinsicID(L) &&
diff --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
index 8327b30c7583e..43c1eb41778ac 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
@@ -431,7 +431,7 @@ bool vputils::isElementwise(const VPValue *V) {
return Instruction::isUnaryOp(Opcode) || Instruction::isBinaryOp(Opcode);
}
-bool vputils::isSingleScalar(const VPValue *VPV) {
+bool vputils::doesGenerateSingleScalar(const VPValue *VPV) {
// Live-in, symbolic and canonical-IV region values are single-scalar.
if (auto *RV = dyn_cast<VPRegionValue>(VPV))
return RV == RV->getDefiningRegion()->getCanonicalIV();
@@ -445,19 +445,10 @@ bool vputils::isSingleScalar(const VPValue *VPV) {
// lanes.
if (RegionOfR && RegionOfR->isReplicator())
return false;
- return Rep->isSingleScalar() || (preservesUniformity(Rep->getOpcode()) &&
- all_of(Rep->operands(), isSingleScalar));
- }
- if (isa<VPWidenGEPRecipe, VPBlendRecipe>(VPV))
- return all_of(VPV->getDefiningRecipe()->operands(), isSingleScalar);
- if (auto *WidenR = dyn_cast<VPWidenRecipe>(VPV)) {
- return preservesUniformity(WidenR->getOpcode()) &&
- all_of(WidenR->operands(), isSingleScalar);
+ return Rep->isSingleScalar();
}
if (auto *VPI = dyn_cast<VPInstruction>(VPV))
- return VPI->isSingleScalar() || VPI->isVectorToScalar() ||
- (preservesUniformity(VPI->getOpcode()) &&
- all_of(VPI->operands(), isSingleScalar));
+ return VPI->isSingleScalar() || VPI->isVectorToScalar();
if (auto *RR = dyn_cast<VPReductionRecipe>(VPV))
return !RR->isPartialReduction();
if (isa<VPVectorPointerRecipe, VPVectorEndPointerRecipe, VPDerivedIVRecipe>(
@@ -470,6 +461,26 @@ bool vputils::isSingleScalar(const VPValue *VPV) {
return isa<VPExpandSCEVRecipe>(VPV);
}
+bool vputils::isSingleScalar(const VPValue *VPV) {
+ if (doesGenerateSingleScalar(VPV))
+ return true;
+
+ // A uniformity-preserving operation is single-scalar if all its operands are.
+ if (auto *Rep = dyn_cast<VPReplicateRecipe>(VPV)) {
+ const VPRegionBlock *RegionOfR = Rep->getRegion();
+ if (RegionOfR && RegionOfR->isReplicator())
+ return false;
+ return preservesUniformity(Rep->getOpcode()) &&
+ all_of(Rep->operands(), isSingleScalar);
+ }
+ if (isa<VPWidenGEPRecipe, VPBlendRecipe>(VPV))
+ return all_of(VPV->getDefiningRecipe()->operands(), isSingleScalar);
+
+ return isa<VPWidenRecipe, VPInstruction>(VPV) &&
+ preservesUniformity(vputils::getOpcode(VPV)) &&
+ all_of(VPV->getDefiningRecipe()->operands(), isSingleScalar);
+}
+
bool vputils::isUniformAcrossVFsAndUFs(const VPValue *V) {
// Live-ins, symbolic and canonical-IV region values are uniform.
if (auto *RV = dyn_cast<VPRegionValue>(V))
diff --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.h b/llvm/lib/Transforms/Vectorize/VPlanUtils.h
index 738a5bc8b8066..8f1cbb9006209 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanUtils.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanUtils.h
@@ -70,6 +70,10 @@ bool isElementwise(const VPValue *V);
/// Returns true if \p R produces scalar values for all VF lanes.
bool doesGeneratePerAllLanes(const VPRecipeBase *R);
+/// Returns true if \p VPV is defined by a recipe producing a single-scalar
+/// value or a live-in/symbolic value/single-scalar region value.
+bool doesGenerateSingleScalar(const VPValue *VPV);
+
/// Returns the header block of the first, top-level loop, or null if none
/// exist.
VPBasicBlock *getFirstLoopHeader(VPlan &Plan, VPDominatorTree &VPDT);
>From 32e58f74e6a2f766c0cd4a3ae641bf7f7feecc27 Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Wed, 9 Sep 2026 15:47:44 +0100
Subject: [PATCH 2/2] [VPlan] Only fold ExtractLastLane if op is generates
single-scalar.
Replace the recursive isSingleScalar check with doesGenerateSingleScalar
from https://github.com/llvm/llvm-project/pull/222447.
The recursive check can lead to cases where we recursively determine
that the VPValue could be single-scalar, but for some reason it does not
get narrowed and produces a wide result in the end, leading to a crash
in the newly added test case.
---
.../Transforms/Vectorize/VPlanTransforms.cpp | 3 +-
...scalable-chained-first-order-recurrence.ll | 210 ++++++++++++++++++
2 files changed, 212 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/Transforms/LoopVectorize/AArch64/scalable-chained-first-order-recurrence.ll
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 8fe06568e2ac8..a484d700e92f0 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -1291,7 +1291,8 @@ static VPValue *simplifyRecipe(VPlan &Plan, VPSingleDefRecipe *Def) {
if (match(A, m_Broadcast(m_VPValue(B))))
return B;
- if (isa<VPInstruction, VPReplicateRecipe>(A) && vputils::isSingleScalar(A))
+ if (isa<VPInstruction, VPReplicateRecipe>(A) &&
+ vputils::doesGenerateSingleScalar(A))
return A;
if (Plan.hasScalarVFOnly())
diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/scalable-chained-first-order-recurrence.ll b/llvm/test/Transforms/LoopVectorize/AArch64/scalable-chained-first-order-recurrence.ll
new file mode 100644
index 0000000000000..6d66119f4d7c5
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/AArch64/scalable-chained-first-order-recurrence.ll
@@ -0,0 +1,210 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals none --version 6
+; RUN: opt -S -passes=loop-vectorize -mtriple aarch64 -mattr=+sve -scalable-vectorization=on -force-vector-width=4 < %s | FileCheck %s
+
+target triple = "aarch64-unknown-linux-gnu"
+
+; A chain of two first-order recurrences: %for.y reads the previous-iteration
+; value of trunc(%for.x), and %for.x's backedge value is loop-invariant.
+define i32 @test_chained_first_order_recurrences_2(ptr %base, i64 %x) #0 {
+; CHECK-LABEL: define i32 @test_chained_first_order_recurrences_2(
+; CHECK-SAME: ptr [[BASE:%.*]], i64 [[X:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT: [[ENTRY:.*]]:
+; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT: [[TMP1:%.*]] = shl nuw i64 [[TMP0]], 3
+; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 4098, [[TMP1]]
+; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
+; CHECK: [[VECTOR_PH]]:
+; CHECK-NEXT: [[TMP2:%.*]] = shl nuw i64 [[TMP0]], 2
+; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 4098, [[TMP1]]
+; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 4098, [[N_MOD_VF]]
+; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 4 x i64> poison, i64 [[X]], i64 0
+; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 4 x i64> [[BROADCAST_SPLATINSERT]], <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer
+; CHECK-NEXT: [[TMP4:%.*]] = shl <vscale x 4 x i64> [[BROADCAST_SPLAT]], splat (i64 1)
+; CHECK-NEXT: [[TMP5:%.*]] = call i32 @llvm.vscale.i32()
+; CHECK-NEXT: [[TMP6:%.*]] = mul nuw i32 [[TMP5]], 4
+; CHECK-NEXT: [[TMP7:%.*]] = sub i32 [[TMP6]], 1
+; CHECK-NEXT: [[VECTOR_RECUR_INIT:%.*]] = insertelement <vscale x 4 x i64> poison, i64 0, i32 [[TMP7]]
+; CHECK-NEXT: [[TMP8:%.*]] = call i32 @llvm.vscale.i32()
+; CHECK-NEXT: [[TMP9:%.*]] = mul nuw i32 [[TMP8]], 4
+; CHECK-NEXT: [[TMP10:%.*]] = sub i32 [[TMP9]], 1
+; CHECK-NEXT: [[VECTOR_RECUR_INIT1:%.*]] = insertelement <vscale x 4 x i32> poison, i32 0, i32 [[TMP10]]
+; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
+; CHECK: [[VECTOR_BODY]]:
+; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; CHECK-NEXT: [[VECTOR_RECUR:%.*]] = phi <vscale x 4 x i64> [ [[VECTOR_RECUR_INIT]], %[[VECTOR_PH]] ], [ [[TMP4]], %[[VECTOR_BODY]] ]
+; CHECK-NEXT: [[VECTOR_RECUR2:%.*]] = phi <vscale x 4 x i32> [ [[VECTOR_RECUR_INIT1]], %[[VECTOR_PH]] ], [ [[TMP15:%.*]], %[[VECTOR_BODY]] ]
+; CHECK-NEXT: [[TMP11:%.*]] = getelementptr i64, ptr [[BASE]], i64 [[INDEX]]
+; CHECK-NEXT: [[TMP12:%.*]] = call <vscale x 4 x i64> @llvm.vector.splice.right.nxv4i64(<vscale x 4 x i64> [[VECTOR_RECUR]], <vscale x 4 x i64> [[TMP4]], i32 1)
+; CHECK-NEXT: [[TMP13:%.*]] = call <vscale x 4 x i64> @llvm.vector.splice.right.nxv4i64(<vscale x 4 x i64> [[TMP4]], <vscale x 4 x i64> [[TMP4]], i32 1)
+; CHECK-NEXT: [[TMP14:%.*]] = trunc <vscale x 4 x i64> [[TMP12]] to <vscale x 4 x i32>
+; CHECK-NEXT: [[TMP15]] = trunc <vscale x 4 x i64> [[TMP13]] to <vscale x 4 x i32>
+; CHECK-NEXT: [[TMP16:%.*]] = call <vscale x 4 x i32> @llvm.vector.splice.right.nxv4i32(<vscale x 4 x i32> [[VECTOR_RECUR2]], <vscale x 4 x i32> [[TMP14]], i32 1)
+; CHECK-NEXT: [[TMP17:%.*]] = call <vscale x 4 x i32> @llvm.vector.splice.right.nxv4i32(<vscale x 4 x i32> [[TMP14]], <vscale x 4 x i32> [[TMP15]], i32 1)
+; CHECK-NEXT: [[TMP18:%.*]] = sext <vscale x 4 x i32> [[TMP16]] to <vscale x 4 x i64>
+; CHECK-NEXT: [[TMP19:%.*]] = sext <vscale x 4 x i32> [[TMP17]] to <vscale x 4 x i64>
+; CHECK-NEXT: [[TMP20:%.*]] = getelementptr i64, ptr [[TMP11]], i64 [[TMP2]]
+; CHECK-NEXT: store <vscale x 4 x i64> [[TMP18]], ptr [[TMP11]], align 8
+; CHECK-NEXT: store <vscale x 4 x i64> [[TMP19]], ptr [[TMP20]], align 8
+; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP1]]
+; CHECK-NEXT: [[TMP21:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
+; CHECK-NEXT: br i1 [[TMP21]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
+; CHECK: [[MIDDLE_BLOCK]]:
+; CHECK-NEXT: [[TMP22:%.*]] = call i32 @llvm.vscale.i32()
+; CHECK-NEXT: [[TMP23:%.*]] = mul nuw i32 [[TMP22]], 4
+; CHECK-NEXT: [[TMP24:%.*]] = sub i32 [[TMP23]], 1
+; CHECK-NEXT: [[VECTOR_RECUR_EXTRACT:%.*]] = extractelement <vscale x 4 x i64> [[TMP4]], i32 [[TMP24]]
+; CHECK-NEXT: [[TMP25:%.*]] = call i32 @llvm.vscale.i32()
+; CHECK-NEXT: [[TMP26:%.*]] = mul nuw i32 [[TMP25]], 4
+; CHECK-NEXT: [[TMP27:%.*]] = sub i32 [[TMP26]], 1
+; CHECK-NEXT: [[VECTOR_RECUR_EXTRACT3:%.*]] = extractelement <vscale x 4 x i32> [[TMP15]], i32 [[TMP27]]
+; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 4098, [[N_VEC]]
+; CHECK-NEXT: br i1 [[CMP_N]], label %[[RET:.*]], 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 [ [[VECTOR_RECUR_EXTRACT]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
+; CHECK-NEXT: [[SCALAR_RECUR_INIT4:%.*]] = phi i32 [ [[VECTOR_RECUR_EXTRACT3]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
+; CHECK-NEXT: br label %[[LOOP:.*]]
+; CHECK: [[LOOP]]:
+; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[IV_NEXT:%.*]], %[[LOOP]] ], [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ]
+; CHECK-NEXT: [[FOR_X:%.*]] = phi i64 [ [[FOR_X_NEXT:%.*]], %[[LOOP]] ], [ [[SCALAR_RECUR_INIT]], %[[SCALAR_PH]] ]
+; CHECK-NEXT: [[FOR_Y:%.*]] = phi i32 [ [[FOR_X_PREV:%.*]], %[[LOOP]] ], [ [[SCALAR_RECUR_INIT4]], %[[SCALAR_PH]] ]
+; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV]], 1
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr i64, ptr [[BASE]], i64 [[IV]]
+; CHECK-NEXT: [[FOR_X_PREV]] = trunc i64 [[FOR_X]] to i32
+; CHECK-NEXT: [[FOR_Y_I64:%.*]] = sext i32 [[FOR_Y]] to i64
+; CHECK-NEXT: store i64 [[FOR_Y_I64]], ptr [[GEP]], align 8
+; CHECK-NEXT: [[FOR_X_NEXT]] = mul i64 [[X]], 2
+; CHECK-NEXT: [[ICMP:%.*]] = icmp ugt i64 [[IV]], 4096
+; CHECK-NEXT: br i1 [[ICMP]], label %[[RET]], label %[[LOOP]], !llvm.loop [[LOOP3:![0-9]+]]
+; CHECK: [[RET]]:
+; CHECK-NEXT: ret i32 0
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i64 [ %iv.next, %loop ], [ 0, %entry ]
+ %for.x = phi i64 [ %for.x.next, %loop ], [ 0, %entry ]
+ %for.y = phi i32 [ %for.x.prev, %loop ], [ 0, %entry ]
+ %iv.next = add i64 %iv, 1
+ %gep = getelementptr i64, ptr %base, i64 %iv
+ %for.x.prev = trunc i64 %for.x to i32
+ %for.y.i64 = sext i32 %for.y to i64
+ store i64 %for.y.i64, ptr %gep
+ %for.x.next = mul i64 %x, 2
+ %icmp = icmp ugt i64 %iv, 4096
+ br i1 %icmp, label %ret, label %loop
+
+ret:
+ ret i32 0
+}
+
+define i32 @test_chained_first_order_recurrences_3(ptr %base, i64 %x) #0 {
+; CHECK-LABEL: define i32 @test_chained_first_order_recurrences_3(
+; CHECK-SAME: ptr [[BASE:%.*]], i64 [[X:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT: [[ENTRY:.*]]:
+; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT: [[TMP1:%.*]] = shl nuw i64 [[TMP0]], 3
+; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 4098, [[TMP1]]
+; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
+; CHECK: [[VECTOR_PH]]:
+; CHECK-NEXT: [[TMP2:%.*]] = shl nuw i64 [[TMP0]], 2
+; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 4098, [[TMP1]]
+; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 4098, [[N_MOD_VF]]
+; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 4 x i64> poison, i64 [[X]], i64 0
+; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 4 x i64> [[BROADCAST_SPLATINSERT]], <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer
+; CHECK-NEXT: [[TMP4:%.*]] = shl <vscale x 4 x i64> [[BROADCAST_SPLAT]], splat (i64 1)
+; CHECK-NEXT: [[TMP5:%.*]] = call i32 @llvm.vscale.i32()
+; CHECK-NEXT: [[TMP6:%.*]] = mul nuw i32 [[TMP5]], 4
+; CHECK-NEXT: [[TMP7:%.*]] = sub i32 [[TMP6]], 1
+; CHECK-NEXT: [[VECTOR_RECUR_INIT:%.*]] = insertelement <vscale x 4 x i64> poison, i64 0, i32 [[TMP7]]
+; CHECK-NEXT: [[TMP8:%.*]] = call i32 @llvm.vscale.i32()
+; CHECK-NEXT: [[TMP9:%.*]] = mul nuw i32 [[TMP8]], 4
+; CHECK-NEXT: [[TMP10:%.*]] = sub i32 [[TMP9]], 1
+; CHECK-NEXT: [[VECTOR_RECUR_INIT1:%.*]] = insertelement <vscale x 4 x i32> poison, i32 0, i32 [[TMP10]]
+; CHECK-NEXT: [[TMP11:%.*]] = call i32 @llvm.vscale.i32()
+; CHECK-NEXT: [[TMP12:%.*]] = mul nuw i32 [[TMP11]], 4
+; CHECK-NEXT: [[TMP13:%.*]] = sub i32 [[TMP12]], 1
+; CHECK-NEXT: [[VECTOR_RECUR_INIT2:%.*]] = insertelement <vscale x 4 x i32> poison, i32 0, i32 [[TMP13]]
+; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
+; CHECK: [[VECTOR_BODY]]:
+; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; CHECK-NEXT: [[VECTOR_RECUR:%.*]] = phi <vscale x 4 x i64> [ [[VECTOR_RECUR_INIT]], %[[VECTOR_PH]] ], [ [[TMP4]], %[[VECTOR_BODY]] ]
+; CHECK-NEXT: [[VECTOR_RECUR3:%.*]] = phi <vscale x 4 x i32> [ [[VECTOR_RECUR_INIT1]], %[[VECTOR_PH]] ], [ [[TMP18:%.*]], %[[VECTOR_BODY]] ]
+; CHECK-NEXT: [[VECTOR_RECUR4:%.*]] = phi <vscale x 4 x i32> [ [[VECTOR_RECUR_INIT2]], %[[VECTOR_PH]] ], [ [[TMP20:%.*]], %[[VECTOR_BODY]] ]
+; CHECK-NEXT: [[TMP14:%.*]] = getelementptr i64, ptr [[BASE]], i64 [[INDEX]]
+; CHECK-NEXT: [[TMP15:%.*]] = call <vscale x 4 x i64> @llvm.vector.splice.right.nxv4i64(<vscale x 4 x i64> [[VECTOR_RECUR]], <vscale x 4 x i64> [[TMP4]], i32 1)
+; CHECK-NEXT: [[TMP16:%.*]] = call <vscale x 4 x i64> @llvm.vector.splice.right.nxv4i64(<vscale x 4 x i64> [[TMP4]], <vscale x 4 x i64> [[TMP4]], i32 1)
+; CHECK-NEXT: [[TMP17:%.*]] = trunc <vscale x 4 x i64> [[TMP15]] to <vscale x 4 x i32>
+; CHECK-NEXT: [[TMP18]] = trunc <vscale x 4 x i64> [[TMP16]] to <vscale x 4 x i32>
+; CHECK-NEXT: [[TMP19:%.*]] = call <vscale x 4 x i32> @llvm.vector.splice.right.nxv4i32(<vscale x 4 x i32> [[VECTOR_RECUR3]], <vscale x 4 x i32> [[TMP17]], i32 1)
+; CHECK-NEXT: [[TMP20]] = call <vscale x 4 x i32> @llvm.vector.splice.right.nxv4i32(<vscale x 4 x i32> [[TMP17]], <vscale x 4 x i32> [[TMP18]], i32 1)
+; CHECK-NEXT: [[TMP21:%.*]] = call <vscale x 4 x i32> @llvm.vector.splice.right.nxv4i32(<vscale x 4 x i32> [[VECTOR_RECUR4]], <vscale x 4 x i32> [[TMP19]], i32 1)
+; CHECK-NEXT: [[TMP22:%.*]] = call <vscale x 4 x i32> @llvm.vector.splice.right.nxv4i32(<vscale x 4 x i32> [[TMP19]], <vscale x 4 x i32> [[TMP20]], i32 1)
+; CHECK-NEXT: [[TMP23:%.*]] = sext <vscale x 4 x i32> [[TMP21]] to <vscale x 4 x i64>
+; CHECK-NEXT: [[TMP24:%.*]] = sext <vscale x 4 x i32> [[TMP22]] to <vscale x 4 x i64>
+; CHECK-NEXT: [[TMP25:%.*]] = getelementptr i64, ptr [[TMP14]], i64 [[TMP2]]
+; CHECK-NEXT: store <vscale x 4 x i64> [[TMP23]], ptr [[TMP14]], align 8
+; CHECK-NEXT: store <vscale x 4 x i64> [[TMP24]], ptr [[TMP25]], align 8
+; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP1]]
+; CHECK-NEXT: [[TMP26:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
+; CHECK-NEXT: br i1 [[TMP26]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
+; CHECK: [[MIDDLE_BLOCK]]:
+; CHECK-NEXT: [[TMP27:%.*]] = call i32 @llvm.vscale.i32()
+; CHECK-NEXT: [[TMP28:%.*]] = mul nuw i32 [[TMP27]], 4
+; CHECK-NEXT: [[TMP29:%.*]] = sub i32 [[TMP28]], 1
+; CHECK-NEXT: [[VECTOR_RECUR_EXTRACT:%.*]] = extractelement <vscale x 4 x i64> [[TMP4]], i32 [[TMP29]]
+; CHECK-NEXT: [[TMP30:%.*]] = call i32 @llvm.vscale.i32()
+; CHECK-NEXT: [[TMP31:%.*]] = mul nuw i32 [[TMP30]], 4
+; CHECK-NEXT: [[TMP32:%.*]] = sub i32 [[TMP31]], 1
+; CHECK-NEXT: [[VECTOR_RECUR_EXTRACT5:%.*]] = extractelement <vscale x 4 x i32> [[TMP18]], i32 [[TMP32]]
+; CHECK-NEXT: [[TMP33:%.*]] = call i32 @llvm.vscale.i32()
+; CHECK-NEXT: [[TMP34:%.*]] = mul nuw i32 [[TMP33]], 4
+; CHECK-NEXT: [[TMP35:%.*]] = sub i32 [[TMP34]], 1
+; CHECK-NEXT: [[VECTOR_RECUR_EXTRACT6:%.*]] = extractelement <vscale x 4 x i32> [[TMP20]], i32 [[TMP35]]
+; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 4098, [[N_VEC]]
+; CHECK-NEXT: br i1 [[CMP_N]], label %[[RET:.*]], 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 [ [[VECTOR_RECUR_EXTRACT]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
+; CHECK-NEXT: [[SCALAR_RECUR_INIT7:%.*]] = phi i32 [ [[VECTOR_RECUR_EXTRACT5]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
+; CHECK-NEXT: [[SCALAR_RECUR_INIT8:%.*]] = phi i32 [ [[VECTOR_RECUR_EXTRACT6]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
+; CHECK-NEXT: br label %[[LOOP:.*]]
+; CHECK: [[LOOP]]:
+; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[IV_NEXT:%.*]], %[[LOOP]] ], [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ]
+; CHECK-NEXT: [[FOR_X:%.*]] = phi i64 [ [[FOR_X_NEXT:%.*]], %[[LOOP]] ], [ [[SCALAR_RECUR_INIT]], %[[SCALAR_PH]] ]
+; CHECK-NEXT: [[FOR_Y:%.*]] = phi i32 [ [[FOR_X_PREV:%.*]], %[[LOOP]] ], [ [[SCALAR_RECUR_INIT7]], %[[SCALAR_PH]] ]
+; CHECK-NEXT: [[FOR_Z:%.*]] = phi i32 [ [[FOR_Y]], %[[LOOP]] ], [ [[SCALAR_RECUR_INIT8]], %[[SCALAR_PH]] ]
+; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV]], 1
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr i64, ptr [[BASE]], i64 [[IV]]
+; CHECK-NEXT: [[FOR_X_PREV]] = trunc i64 [[FOR_X]] to i32
+; CHECK-NEXT: [[FOR_Z_I64:%.*]] = sext i32 [[FOR_Z]] to i64
+; CHECK-NEXT: store i64 [[FOR_Z_I64]], ptr [[GEP]], align 8
+; CHECK-NEXT: [[FOR_X_NEXT]] = mul i64 [[X]], 2
+; CHECK-NEXT: [[ICMP:%.*]] = icmp ugt i64 [[IV]], 4096
+; CHECK-NEXT: br i1 [[ICMP]], label %[[RET]], label %[[LOOP]], !llvm.loop [[LOOP5:![0-9]+]]
+; CHECK: [[RET]]:
+; CHECK-NEXT: ret i32 0
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i64 [ %iv.next, %loop ], [ 0, %entry ]
+ %for.x = phi i64 [ %for.x.next, %loop ], [ 0, %entry ]
+ %for.y = phi i32 [ %for.x.prev, %loop ], [ 0, %entry ]
+ %for.z = phi i32 [ %for.y, %loop ], [ 0, %entry ]
+ %iv.next = add i64 %iv, 1
+ %gep = getelementptr i64, ptr %base, i64 %iv
+ %for.x.prev = trunc i64 %for.x to i32
+ %for.z.i64 = sext i32 %for.z to i64
+ store i64 %for.z.i64, ptr %gep
+ %for.x.next = mul i64 %x, 2
+ %icmp = icmp ugt i64 %iv, 4096
+ br i1 %icmp, label %ret, label %loop
+
+ret:
+ ret i32 0
+}
+
+attributes #0 = { "target-features"="+sve" }
More information about the llvm-commits
mailing list