Skip to content

Commit 39db575

Browse files
committed
[LV][ARM] Inloop reduction cost modelling
This adds cost modelling for the inloop vectorization added in 745bf6c. Up until now they have been modelled as the original underlying instruction, usually an add. This happens to works OK for MVE with instructions that are reducing into the same type as they are working on. But MVE's instructions can perform the equivalent of an extended MLA as a single instruction: %sa = sext <16 x i8> A to <16 x i32> %sb = sext <16 x i8> B to <16 x i32> %m = mul <16 x i32> %sa, %sb %r = vecreduce.add(%m) -> R = VMLADAV A, B There are other instructions for performing add reductions of v4i32/v8i16/v16i8 into i32 (VADDV), for doing the same with v4i32->i64 (VADDLV) and for performing a v4i32/v8i16 MLA into an i64 (VMLALDAV). The i64 are particularly interesting as there are no native i64 add/mul instructions, leading to the i64 add and mul naturally getting very high costs. Also worth mentioning, under NEON there is the concept of a sdot/udot instruction which performs a partial reduction from a v16i8 to a v4i32. They extend and mul/sum the first four elements from the inputs into the first element of the output, repeating for each of the four output lanes. They could possibly be represented in the same way as above in llvm, so long as a vecreduce.add could perform a partial reduction. The vectorizer would then produce a combination of in and outer loop reductions to efficiently use the sdot and udot instructions. Although this patch does not do that yet, it does suggest that separating the input reduction type from the produced result type is a useful concept to model. It also shows that a MLA reduction as a single instruction is fairly common. This patch attempt to improve the costmodelling of in-loop reductions by: - Adding some pattern matching in the loop vectorizer cost model to match extended reduction patterns that are optionally extended and/or MLA patterns. This marks the cost of the reduction instruction correctly and the sext/zext/mul leading up to it as free, which is otherwise difficult to tell and may get a very high cost. (In the long run this can hopefully be replaced by vplan producing a single node and costing it correctly, but that is not yet something that vplan can do). - getExtendedAddReductionCost is added to query the cost of these extended reduction patterns. - Expanded the ARM costs to account for these expanded sizes, which is a fairly simple change in itself. - Some minor alterations to allow inloop reduction larger than the highest vector width and i64 MVE reductions. - An extra InLoopReductionImmediateChains map was added to the vectorizer for it to efficiently detect which instructions are reductions in the cost model. - The tests have some updates to show what I believe is optimal vectorization and where we are now. Put together this can greatly improve performance for reduction loop under MVE. Differential Revision: https://reviews.llvm.org/D93476
1 parent 2f03528 commit 39db575

9 files changed

Lines changed: 568 additions & 160 deletions

File tree

‎llvm/include/llvm/Analysis/TargetTransformInfo.h‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,16 @@ class TargetTransformInfo {
11821182
VectorType *Ty, VectorType *CondTy, bool IsPairwiseForm, bool IsUnsigned,
11831183
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput) const;
11841184

1185+
/// Calculate the cost of an extended reduction pattern, similar to
1186+
/// getArithmeticReductionCost of an Add reduction with an extension and
1187+
/// optional multiply. This is the cost of as:
1188+
/// ResTy vecreduce.add(ext(Ty A)), or if IsMLA flag is set then:
1189+
/// ResTy vecreduce.add(mul(ext(Ty A), ext(Ty B)). The reduction happens
1190+
/// on a VectorType with ResTy elements and Ty lanes.
1191+
InstructionCost getExtendedAddReductionCost(
1192+
bool IsMLA, bool IsUnsigned, Type *ResTy, VectorType *Ty,
1193+
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput) const;
1194+
11851195
/// \returns The cost of Intrinsic instructions. Analyses the real arguments.
11861196
/// Three cases are handled: 1. scalar instruction 2. vector instruction
11871197
/// 3. scalar instruction which is to be vectorized.
@@ -1588,6 +1598,9 @@ class TargetTransformInfo::Concept {
15881598
virtual int getMinMaxReductionCost(VectorType *Ty, VectorType *CondTy,
15891599
bool IsPairwiseForm, bool IsUnsigned,
15901600
TTI::TargetCostKind CostKind) = 0;
1601+
virtual InstructionCost getExtendedAddReductionCost(
1602+
bool IsMLA, bool IsUnsigned, Type *ResTy, VectorType *Ty,
1603+
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput) = 0;
15911604
virtual int getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
15921605
TTI::TargetCostKind CostKind) = 0;
15931606
virtual int getCallInstrCost(Function *F, Type *RetTy,
@@ -2065,6 +2078,12 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
20652078
return Impl.getMinMaxReductionCost(Ty, CondTy, IsPairwiseForm, IsUnsigned,
20662079
CostKind);
20672080
}
2081+
InstructionCost getExtendedAddReductionCost(
2082+
bool IsMLA, bool IsUnsigned, Type *ResTy, VectorType *Ty,
2083+
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput) override {
2084+
return Impl.getExtendedAddReductionCost(IsMLA, IsUnsigned, ResTy, Ty,
2085+
CostKind);
2086+
}
20682087
int getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
20692088
TTI::TargetCostKind CostKind) override {
20702089
return Impl.getIntrinsicInstrCost(ICA, CostKind);

‎llvm/include/llvm/Analysis/TargetTransformInfoImpl.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,12 @@ class TargetTransformInfoImplBase {
600600
return 1;
601601
}
602602

603+
InstructionCost getExtendedAddReductionCost(
604+
bool IsMLA, bool IsUnsigned, Type *ResTy, VectorType *Ty,
605+
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput) const {
606+
return 1;
607+
}
608+
603609
unsigned getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const {
604610
return 0;
605611
}

‎llvm/include/llvm/CodeGen/BasicTTIImpl.h‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,27 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
20142014
thisT()->getVectorInstrCost(Instruction::ExtractElement, Ty, 0);
20152015
}
20162016

2017+
InstructionCost getExtendedAddReductionCost(bool IsMLA, bool IsUnsigned,
2018+
Type *ResTy, VectorType *Ty,
2019+
TTI::TargetCostKind CostKind) {
2020+
// Without any native support, this is equivalent to the cost of
2021+
// vecreduce.add(ext) or if IsMLA vecreduce.add(mul(ext, ext))
2022+
VectorType *ExtTy = VectorType::get(ResTy, Ty);
2023+
unsigned RedCost = thisT()->getArithmeticReductionCost(
2024+
Instruction::Add, ExtTy, false, CostKind);
2025+
unsigned MulCost = 0;
2026+
unsigned ExtCost = thisT()->getCastInstrCost(
2027+
IsUnsigned ? Instruction::ZExt : Instruction::SExt, ExtTy, Ty,
2028+
TTI::CastContextHint::None, CostKind);
2029+
if (IsMLA) {
2030+
MulCost =
2031+
thisT()->getArithmeticInstrCost(Instruction::Mul, ExtTy, CostKind);
2032+
ExtCost *= 2;
2033+
}
2034+
2035+
return RedCost + MulCost + ExtCost;
2036+
}
2037+
20172038
unsigned getVectorSplitCost() { return 1; }
20182039

20192040
/// @}

‎llvm/lib/Analysis/TargetTransformInfo.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,13 @@ int TargetTransformInfo::getMinMaxReductionCost(
943943
return Cost;
944944
}
945945

946+
InstructionCost TargetTransformInfo::getExtendedAddReductionCost(
947+
bool IsMLA, bool IsUnsigned, Type *ResTy, VectorType *Ty,
948+
TTI::TargetCostKind CostKind) const {
949+
return TTIImpl->getExtendedAddReductionCost(IsMLA, IsUnsigned, ResTy, Ty,
950+
CostKind);
951+
}
952+
946953
unsigned
947954
TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const {
948955
return TTIImpl->getCostOfKeepingLiveOverCall(Tys);

‎llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,25 @@ int ARMTTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *ValTy,
15111511
CostKind);
15121512
}
15131513

1514+
InstructionCost
1515+
ARMTTIImpl::getExtendedAddReductionCost(bool IsMLA, bool IsUnsigned,
1516+
Type *ResTy, VectorType *ValTy,
1517+
TTI::TargetCostKind CostKind) {
1518+
EVT ValVT = TLI->getValueType(DL, ValTy);
1519+
EVT ResVT = TLI->getValueType(DL, ResTy);
1520+
if (ST->hasMVEIntegerOps() && ValVT.isSimple() && ResVT.isSimple()) {
1521+
std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, ValTy);
1522+
if ((LT.second == MVT::v16i8 && ResVT.getSizeInBits() <= 32) ||
1523+
(LT.second == MVT::v8i16 &&
1524+
ResVT.getSizeInBits() <= (IsMLA ? 64 : 32)) ||
1525+
(LT.second == MVT::v4i32 && ResVT.getSizeInBits() <= 64))
1526+
return ST->getMVEVectorCostFactor() * LT.first;
1527+
}
1528+
1529+
return BaseT::getExtendedAddReductionCost(IsMLA, IsUnsigned, ResTy, ValTy,
1530+
CostKind);
1531+
}
1532+
15141533
int ARMTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
15151534
TTI::TargetCostKind CostKind) {
15161535
switch (ICA.getID()) {
@@ -2082,7 +2101,7 @@ bool ARMTTIImpl::preferInLoopReduction(unsigned Opcode, Type *Ty,
20822101
unsigned ScalarBits = Ty->getScalarSizeInBits();
20832102
switch (Opcode) {
20842103
case Instruction::Add:
2085-
return ScalarBits <= 32;
2104+
return ScalarBits <= 64;
20862105
default:
20872106
return false;
20882107
}

‎llvm/lib/Target/ARM/ARMTargetTransformInfo.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ class ARMTTIImpl : public BasicTTIImplBase<ARMTTIImpl> {
247247
int getArithmeticReductionCost(unsigned Opcode, VectorType *ValTy,
248248
bool IsPairwiseForm,
249249
TTI::TargetCostKind CostKind);
250+
InstructionCost getExtendedAddReductionCost(bool IsMLA, bool IsUnsigned,
251+
Type *ResTy, VectorType *ValTy,
252+
TTI::TargetCostKind CostKind);
250253

251254
int getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
252255
TTI::TargetCostKind CostKind);

‎llvm/lib/Transforms/Vectorize/LoopVectorize.cpp‎

Lines changed: 148 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,12 @@ class LoopVectorizationCostModel {
16551655
InstructionCost getInstructionCost(Instruction *I, ElementCount VF,
16561656
Type *&VectorTy);
16571657

1658+
/// Return the cost of instructions in an inloop reduction pattern, if I is
1659+
/// part of that pattern.
1660+
InstructionCost getReductionPatternCost(Instruction *I, ElementCount VF,
1661+
Type *VectorTy,
1662+
TTI::TargetCostKind CostKind);
1663+
16581664
/// Calculate vectorization cost of memory instruction \p I.
16591665
InstructionCost getMemoryInstructionCost(Instruction *I, ElementCount VF);
16601666

@@ -1738,6 +1744,12 @@ class LoopVectorizationCostModel {
17381744
/// (PHI) to bottom
17391745
ReductionChainMap InLoopReductionChains;
17401746

1747+
/// A Map of inloop reduction operations and their immediate chain operand.
1748+
/// FIXME: This can be removed once reductions can be costed correctly in
1749+
/// vplan. This was added to allow quick lookup to the inloop operations,
1750+
/// without having to loop through InLoopReductionChains.
1751+
DenseMap<Instruction *, Instruction *> InLoopReductionImmediateChains;
1752+
17411753
/// Returns the expected difference in cost from scalarizing the expression
17421754
/// feeding a predicated instruction \p PredInst. The instructions to
17431755
/// scalarize and their scalar costs are collected in \p ScalarCosts. A
@@ -5983,6 +5995,11 @@ LoopVectorizationCostModel::getSmallestAndWidestTypes() {
59835995
if (!Legal->isReductionVariable(PN))
59845996
continue;
59855997
RecurrenceDescriptor RdxDesc = Legal->getReductionVars()[PN];
5998+
if (PreferInLoopReductions ||
5999+
TTI.preferInLoopReduction(RdxDesc.getOpcode(),
6000+
RdxDesc.getRecurrenceType(),
6001+
TargetTransformInfo::ReductionFlags()))
6002+
continue;
59866003
T = RdxDesc.getRecurrenceType();
59876004
}
59886005

@@ -6815,6 +6832,116 @@ LoopVectorizationCostModel::getInterleaveGroupCost(Instruction *I,
68156832
return Cost;
68166833
}
68176834

6835+
InstructionCost LoopVectorizationCostModel::getReductionPatternCost(
6836+
Instruction *I, ElementCount VF, Type *Ty, TTI::TargetCostKind CostKind) {
6837+
// Early exit for no inloop reductions
6838+
if (InLoopReductionChains.empty() || VF.isScalar() || !isa<VectorType>(Ty))
6839+
return InstructionCost::getInvalid();
6840+
auto *VectorTy = cast<VectorType>(Ty);
6841+
6842+
// We are looking for a pattern of, and finding the minimal acceptable cost:
6843+
// reduce(mul(ext(A), ext(B))) or
6844+
// reduce(mul(A, B)) or
6845+
// reduce(ext(A)) or
6846+
// reduce(A).
6847+
// The basic idea is that we walk down the tree to do that, finding the root
6848+
// reduction instruction in InLoopReductionImmediateChains. From there we find
6849+
// the pattern of mul/ext and test the cost of the entire pattern vs the cost
6850+
// of the components. If the reduction cost is lower then we return it for the
6851+
// reduction instruction and 0 for the other instructions in the pattern. If
6852+
// it is not we return an invalid cost specifying the orignal cost method
6853+
// should be used.
6854+
Instruction *RetI = I;
6855+
if ((RetI->getOpcode() == Instruction::SExt ||
6856+
RetI->getOpcode() == Instruction::ZExt)) {
6857+
if (!RetI->hasOneUser())
6858+
return InstructionCost::getInvalid();
6859+
RetI = RetI->user_back();
6860+
}
6861+
if (RetI->getOpcode() == Instruction::Mul &&
6862+
RetI->user_back()->getOpcode() == Instruction::Add) {
6863+
if (!RetI->hasOneUser())
6864+
return InstructionCost::getInvalid();
6865+
RetI = RetI->user_back();
6866+
}
6867+
6868+
// Test if the found instruction is a reduction, and if not return an invalid
6869+
// cost specifying the parent to use the original cost modelling.
6870+
if (!InLoopReductionImmediateChains.count(RetI))
6871+
return InstructionCost::getInvalid();
6872+
6873+
// Find the reduction this chain is a part of and calculate the basic cost of
6874+
// the reduction on its own.
6875+
Instruction *LastChain = InLoopReductionImmediateChains[RetI];
6876+
Instruction *ReductionPhi = LastChain;
6877+
while (!isa<PHINode>(ReductionPhi))
6878+
ReductionPhi = InLoopReductionImmediateChains[ReductionPhi];
6879+
6880+
RecurrenceDescriptor RdxDesc =
6881+
Legal->getReductionVars()[cast<PHINode>(ReductionPhi)];
6882+
unsigned BaseCost = TTI.getArithmeticReductionCost(RdxDesc.getOpcode(),
6883+
VectorTy, false, CostKind);
6884+
6885+
// Get the operand that was not the reduction chain and match it to one of the
6886+
// patterns, returning the better cost if it is found.
6887+
Instruction *RedOp = RetI->getOperand(1) == LastChain
6888+
? dyn_cast<Instruction>(RetI->getOperand(0))
6889+
: dyn_cast<Instruction>(RetI->getOperand(1));
6890+
6891+
VectorTy = VectorType::get(I->getOperand(0)->getType(), VectorTy);
6892+
6893+
if (RedOp && (isa<SExtInst>(RedOp) || isa<ZExtInst>(RedOp)) &&
6894+
!TheLoop->isLoopInvariant(RedOp)) {
6895+
bool IsUnsigned = isa<ZExtInst>(RedOp);
6896+
auto *ExtType = VectorType::get(RedOp->getOperand(0)->getType(), VectorTy);
6897+
InstructionCost RedCost = TTI.getExtendedAddReductionCost(
6898+
/*IsMLA=*/false, IsUnsigned, RdxDesc.getRecurrenceType(), ExtType,
6899+
CostKind);
6900+
6901+
unsigned ExtCost =
6902+
TTI.getCastInstrCost(RedOp->getOpcode(), VectorTy, ExtType,
6903+
TTI::CastContextHint::None, CostKind, RedOp);
6904+
if (RedCost.isValid() && RedCost < BaseCost + ExtCost)
6905+
return I == RetI ? *RedCost.getValue() : 0;
6906+
} else if (RedOp && RedOp->getOpcode() == Instruction::Mul) {
6907+
Instruction *Mul = RedOp;
6908+
Instruction *Op0 = dyn_cast<Instruction>(Mul->getOperand(0));
6909+
Instruction *Op1 = dyn_cast<Instruction>(Mul->getOperand(1));
6910+
if (Op0 && Op1 && (isa<SExtInst>(Op0) || isa<ZExtInst>(Op0)) &&
6911+
Op0->getOpcode() == Op1->getOpcode() &&
6912+
Op0->getOperand(0)->getType() == Op1->getOperand(0)->getType() &&
6913+
!TheLoop->isLoopInvariant(Op0) && !TheLoop->isLoopInvariant(Op1)) {
6914+
bool IsUnsigned = isa<ZExtInst>(Op0);
6915+
auto *ExtType = VectorType::get(Op0->getOperand(0)->getType(), VectorTy);
6916+
// reduce(mul(ext, ext))
6917+
unsigned ExtCost =
6918+
TTI.getCastInstrCost(Op0->getOpcode(), VectorTy, ExtType,
6919+
TTI::CastContextHint::None, CostKind, Op0);
6920+
unsigned MulCost =
6921+
TTI.getArithmeticInstrCost(Mul->getOpcode(), VectorTy, CostKind);
6922+
6923+
InstructionCost RedCost = TTI.getExtendedAddReductionCost(
6924+
/*IsMLA=*/true, IsUnsigned, RdxDesc.getRecurrenceType(), ExtType,
6925+
CostKind);
6926+
6927+
if (RedCost.isValid() && RedCost < ExtCost * 2 + MulCost + BaseCost)
6928+
return I == RetI ? *RedCost.getValue() : 0;
6929+
} else {
6930+
unsigned MulCost =
6931+
TTI.getArithmeticInstrCost(Mul->getOpcode(), VectorTy, CostKind);
6932+
6933+
InstructionCost RedCost = TTI.getExtendedAddReductionCost(
6934+
/*IsMLA=*/true, true, RdxDesc.getRecurrenceType(), VectorTy,
6935+
CostKind);
6936+
6937+
if (RedCost.isValid() && RedCost < MulCost + BaseCost)
6938+
return I == RetI ? *RedCost.getValue() : 0;
6939+
}
6940+
}
6941+
6942+
return I == RetI ? BaseCost : InstructionCost::getInvalid();
6943+
}
6944+
68186945
InstructionCost
68196946
LoopVectorizationCostModel::getMemoryInstructionCost(Instruction *I,
68206947
ElementCount VF) {
@@ -7169,6 +7296,13 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, ElementCount VF,
71697296
// Since we will replace the stride by 1 the multiplication should go away.
71707297
if (I->getOpcode() == Instruction::Mul && isStrideMul(I, Legal))
71717298
return 0;
7299+
7300+
// Detect reduction patterns
7301+
InstructionCost RedCost;
7302+
if ((RedCost = getReductionPatternCost(I, VF, VectorTy, CostKind))
7303+
.isValid())
7304+
return RedCost;
7305+
71727306
// Certain instructions can be cheaper to vectorize if they have a constant
71737307
// second vector operand. One example of this are shifts on x86.
71747308
Value *Op2 = I->getOperand(1);
@@ -7292,6 +7426,12 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, ElementCount VF,
72927426
Trunc->getSrcTy(), CCH, CostKind, Trunc);
72937427
}
72947428

7429+
// Detect reduction patterns
7430+
InstructionCost RedCost;
7431+
if ((RedCost = getReductionPatternCost(I, VF, VectorTy, CostKind))
7432+
.isValid())
7433+
return RedCost;
7434+
72957435
Type *SrcScalarTy = I->getOperand(0)->getType();
72967436
Type *SrcVecTy =
72977437
VectorTy->isVectorTy() ? ToVectorTy(SrcScalarTy, VF) : SrcScalarTy;
@@ -7422,8 +7562,15 @@ void LoopVectorizationCostModel::collectInLoopReductions() {
74227562
SmallVector<Instruction *, 4> ReductionOperations =
74237563
RdxDesc.getReductionOpChain(Phi, TheLoop);
74247564
bool InLoop = !ReductionOperations.empty();
7425-
if (InLoop)
7565+
if (InLoop) {
74267566
InLoopReductionChains[Phi] = ReductionOperations;
7567+
// Add the elements to InLoopReductionImmediateChains for cost modelling.
7568+
Instruction *LastChain = Phi;
7569+
for (auto *I : ReductionOperations) {
7570+
InLoopReductionImmediateChains[I] = LastChain;
7571+
LastChain = I;
7572+
}
7573+
}
74277574
LLVM_DEBUG(dbgs() << "LV: Using " << (InLoop ? "inloop" : "out of loop")
74287575
<< " reduction for phi: " << *Phi << "\n");
74297576
}

‎llvm/test/Transforms/LoopVectorize/ARM/mve-reduction-types.ll‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,33 @@ define i32 @mla_i32(i8* noalias nocapture readonly %A, i8* noalias nocapture rea
1212
; CHECK: for.body.preheader:
1313
; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
1414
; CHECK: vector.ph:
15-
; CHECK-NEXT: [[N_RND_UP:%.*]] = add i32 [[N]], 3
16-
; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i32 [[N_RND_UP]], 4
15+
; CHECK-NEXT: [[N_RND_UP:%.*]] = add i32 [[N]], 15
16+
; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i32 [[N_RND_UP]], 16
1717
; CHECK-NEXT: [[N_VEC:%.*]] = sub i32 [[N_RND_UP]], [[N_MOD_VF]]
1818
; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
1919
; CHECK: vector.body:
2020
; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
2121
; CHECK-NEXT: [[VEC_PHI:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[TMP12:%.*]], [[VECTOR_BODY]] ]
22-
; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i32> poison, i32 [[INDEX]], i32 0
23-
; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT]], <4 x i32> poison, <4 x i32> zeroinitializer
24-
; CHECK-NEXT: [[INDUCTION:%.*]] = add <4 x i32> [[BROADCAST_SPLAT]], <i32 0, i32 1, i32 2, i32 3>
22+
; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <16 x i32> poison, i32 [[INDEX]], i32 0
23+
; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <16 x i32> [[BROADCAST_SPLATINSERT]], <16 x i32> poison, <16 x i32> zeroinitializer
24+
; CHECK-NEXT: [[INDUCTION:%.*]] = add <16 x i32> [[BROADCAST_SPLAT]], <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
2525
; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[INDEX]], 0
26-
; CHECK-NEXT: [[ACTIVE_LANE_MASK:%.*]] = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 [[TMP0]], i32 [[N]])
26+
; CHECK-NEXT: [[ACTIVE_LANE_MASK:%.*]] = call <16 x i1> @llvm.get.active.lane.mask.v16i1.i32(i32 [[TMP0]], i32 [[N]])
2727
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i8, i8* [[A:%.*]], i32 [[TMP0]]
2828
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds i8, i8* [[TMP1]], i32 0
29-
; CHECK-NEXT: [[TMP3:%.*]] = bitcast i8* [[TMP2]] to <4 x i8>*
30-
; CHECK-NEXT: [[WIDE_MASKED_LOAD:%.*]] = call <4 x i8> @llvm.masked.load.v4i8.p0v4i8(<4 x i8>* [[TMP3]], i32 1, <4 x i1> [[ACTIVE_LANE_MASK]], <4 x i8> poison)
31-
; CHECK-NEXT: [[TMP4:%.*]] = sext <4 x i8> [[WIDE_MASKED_LOAD]] to <4 x i32>
29+
; CHECK-NEXT: [[TMP3:%.*]] = bitcast i8* [[TMP2]] to <16 x i8>*
30+
; CHECK-NEXT: [[WIDE_MASKED_LOAD:%.*]] = call <16 x i8> @llvm.masked.load.v16i8.p0v16i8(<16 x i8>* [[TMP3]], i32 1, <16 x i1> [[ACTIVE_LANE_MASK]], <16 x i8> poison)
31+
; CHECK-NEXT: [[TMP4:%.*]] = sext <16 x i8> [[WIDE_MASKED_LOAD]] to <16 x i32>
3232
; CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds i8, i8* [[B:%.*]], i32 [[TMP0]]
3333
; CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds i8, i8* [[TMP5]], i32 0
34-
; CHECK-NEXT: [[TMP7:%.*]] = bitcast i8* [[TMP6]] to <4 x i8>*
35-
; CHECK-NEXT: [[WIDE_MASKED_LOAD1:%.*]] = call <4 x i8> @llvm.masked.load.v4i8.p0v4i8(<4 x i8>* [[TMP7]], i32 1, <4 x i1> [[ACTIVE_LANE_MASK]], <4 x i8> poison)
36-
; CHECK-NEXT: [[TMP8:%.*]] = sext <4 x i8> [[WIDE_MASKED_LOAD1]] to <4 x i32>
37-
; CHECK-NEXT: [[TMP9:%.*]] = mul nsw <4 x i32> [[TMP8]], [[TMP4]]
38-
; CHECK-NEXT: [[TMP10:%.*]] = select <4 x i1> [[ACTIVE_LANE_MASK]], <4 x i32> [[TMP9]], <4 x i32> zeroinitializer
39-
; CHECK-NEXT: [[TMP11:%.*]] = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[TMP10]])
34+
; CHECK-NEXT: [[TMP7:%.*]] = bitcast i8* [[TMP6]] to <16 x i8>*
35+
; CHECK-NEXT: [[WIDE_MASKED_LOAD1:%.*]] = call <16 x i8> @llvm.masked.load.v16i8.p0v16i8(<16 x i8>* [[TMP7]], i32 1, <16 x i1> [[ACTIVE_LANE_MASK]], <16 x i8> poison)
36+
; CHECK-NEXT: [[TMP8:%.*]] = sext <16 x i8> [[WIDE_MASKED_LOAD1]] to <16 x i32>
37+
; CHECK-NEXT: [[TMP9:%.*]] = mul nsw <16 x i32> [[TMP8]], [[TMP4]]
38+
; CHECK-NEXT: [[TMP10:%.*]] = select <16 x i1> [[ACTIVE_LANE_MASK]], <16 x i32> [[TMP9]], <16 x i32> zeroinitializer
39+
; CHECK-NEXT: [[TMP11:%.*]] = call i32 @llvm.vector.reduce.add.v16i32(<16 x i32> [[TMP10]])
4040
; CHECK-NEXT: [[TMP12]] = add i32 [[TMP11]], [[VEC_PHI]]
41-
; CHECK-NEXT: [[INDEX_NEXT]] = add i32 [[INDEX]], 4
41+
; CHECK-NEXT: [[INDEX_NEXT]] = add i32 [[INDEX]], 16
4242
; CHECK-NEXT: [[TMP13:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
4343
; CHECK-NEXT: br i1 [[TMP13]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], [[LOOP0:!llvm.loop !.*]]
4444
; CHECK: middle.block:

0 commit comments

Comments
 (0)