diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp index fd69759be0f4..07b8aaa6c883 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -4393,6 +4393,12 @@ tryToMatchAndCreateExtendedReduction(VPReductionRecipe *Red, VPCostContext &Ctx, Type *RedTy = Ctx.Types.inferScalarType(Red); VPValue *VecOp = Red->getVecOp(); + // For partial reductions, the decision has already been made at the point of + // transforming reductions -> partial reductions for a given plan, based on + // the cost-model. + if (Red->isPartialReduction()) + return new VPExpressionRecipe(cast(VecOp), Red); + // Clamp the range if using extended-reduction is profitable. auto IsExtendedRedValidAndClampRange = [&](unsigned Opcode, Instruction::CastOps ExtOpc, Type *SrcTy) -> bool { @@ -4406,23 +4412,13 @@ tryToMatchAndCreateExtendedReduction(VPReductionRecipe *Red, VPCostContext &Ctx, cast(VecOp)->computeCost(VF, Ctx); InstructionCost RedCost = Red->computeCost(VF, Ctx); - if (Red->isPartialReduction()) { - TargetTransformInfo::PartialReductionExtendKind ExtKind = - TargetTransformInfo::getPartialReductionExtendKind(ExtOpc); - // FIXME: Move partial reduction creation, costing and clamping - // here from LoopVectorize.cpp. - ExtRedCost = Ctx.TTI.getPartialReductionCost( - Opcode, SrcTy, nullptr, RedTy, VF, ExtKind, - llvm::TargetTransformInfo::PR_None, std::nullopt, Ctx.CostKind, - RedTy->isFloatingPointTy() - ? std::optional{Red->getFastMathFlags()} - : std::nullopt); - } else if (!RedTy->isFloatingPointTy()) { - // TTI::getExtendedReductionCost only supports integer types. - ExtRedCost = Ctx.TTI.getExtendedReductionCost( - Opcode, ExtOpc == Instruction::CastOps::ZExt, RedTy, SrcVecTy, - Red->getFastMathFlags(), CostKind); - } + // TTI::getExtendedReductionCost for in-loop reductions + // only supports integer types. + if (RedTy->isFloatingPointTy()) + return false; + ExtRedCost = Ctx.TTI.getExtendedReductionCost( + Opcode, ExtOpc == Instruction::CastOps::ZExt, RedTy, SrcVecTy, + Red->getFastMathFlags(), CostKind); return ExtRedCost.isValid() && ExtRedCost < ExtCost + RedCost; }, Range); @@ -4466,42 +4462,29 @@ tryToMatchAndCreateMulAccumulateReduction(VPReductionRecipe *Red, VPWidenCastRecipe *OuterExt) -> bool { return LoopVectorizationPlanner::getDecisionAndClampRange( [&](ElementCount VF) { + // For partial reductions, the decision has already been made at the + // point of transforming reductions -> partial reductions for a given + // plan, based on the cost-model. + if (Red->isPartialReduction()) + return true; + TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput; Type *SrcTy = Ext0 ? Ctx.Types.inferScalarType(Ext0->getOperand(0)) : RedTy; InstructionCost MulAccCost; - if (Red->isPartialReduction()) { - Type *SrcTy2 = - Ext1 ? Ctx.Types.inferScalarType(Ext1->getOperand(0)) : nullptr; - // FIXME: Move partial reduction creation, costing and clamping - // here from LoopVectorize.cpp. - MulAccCost = Ctx.TTI.getPartialReductionCost( - Opcode, SrcTy, SrcTy2, RedTy, VF, - Ext0 ? TargetTransformInfo::getPartialReductionExtendKind( - Ext0->getOpcode()) - : TargetTransformInfo::PR_None, - Ext1 ? TargetTransformInfo::getPartialReductionExtendKind( - Ext1->getOpcode()) - : TargetTransformInfo::PR_None, - Mul->getOpcode(), CostKind, - RedTy->isFloatingPointTy() - ? std::optional{Red->getFastMathFlags()} - : std::nullopt); - } else { - // Only partial reductions support mixed or floating-point extends - // at the moment. - if (Ext0 && Ext1 && - (Ext0->getOpcode() != Ext1->getOpcode() || - Ext0->getOpcode() == Instruction::CastOps::FPExt)) - return false; + // Only partial reductions support mixed or floating-point extends at + // the moment. + if (Ext0 && Ext1 && + (Ext0->getOpcode() != Ext1->getOpcode() || + Ext0->getOpcode() == Instruction::CastOps::FPExt)) + return false; - bool IsZExt = - !Ext0 || Ext0->getOpcode() == Instruction::CastOps::ZExt; - auto *SrcVecTy = cast(toVectorTy(SrcTy, VF)); - MulAccCost = Ctx.TTI.getMulAccReductionCost(IsZExt, Opcode, RedTy, - SrcVecTy, CostKind); - } + bool IsZExt = + !Ext0 || Ext0->getOpcode() == Instruction::CastOps::ZExt; + auto *SrcVecTy = cast(toVectorTy(SrcTy, VF)); + MulAccCost = Ctx.TTI.getMulAccReductionCost(IsZExt, Opcode, RedTy, + SrcVecTy, CostKind); InstructionCost MulCost = Mul->computeCost(VF, Ctx); InstructionCost RedCost = Red->computeCost(VF, Ctx); @@ -6067,12 +6050,11 @@ static void transformToPartialReduction(const VPPartialReductionChain &Chain, [&NewResult](VPUser &U, unsigned Idx) { return &U != NewResult; }); } -/// Check if a partial reduction chain is is supported by the target (i.e. does -/// not have an invalid cost) for the given VF range. Clamps the range and -/// returns true if profitable for any VF. -static bool isValidPartialReduction(const VPPartialReductionChain &Chain, - Type *PhiType, VPCostContext &CostCtx, - VFRange &Range) { +/// Returns the cost of a link in a partial-reduction chain for a given VF. +static InstructionCost +getPartialReductionLinkCost(VPCostContext &CostCtx, + const VPPartialReductionChain &Link, + ElementCount VF) { auto GetExtInfo = [&CostCtx](VPWidenCastRecipe *Ext) -> std::pair { if (!Ext) @@ -6082,7 +6064,8 @@ static bool isValidPartialReduction(const VPPartialReductionChain &Chain, static_cast(Ext->getOpcode())); return {ExtOpType, ExtKind}; }; - ExtendedReductionOperand ExtendedOp = Chain.ExtendedOp; + + const ExtendedReductionOperand &ExtendedOp = Link.ExtendedOp; VPWidenCastRecipe *ExtendA = ExtendedOp.CastRecipes[0]; VPWidenCastRecipe *ExtendB = ExtendedOp.CastRecipes[1]; @@ -6091,38 +6074,35 @@ static bool isValidPartialReduction(const VPPartialReductionChain &Chain, std::tie(ExtOpTypeA, ExtKindA) = GetExtInfo(ExtendA); std::tie(ExtOpTypeB, ExtKindB) = GetExtInfo(ExtendB); + std::optional BinOpc; + if (ExtendedOp.BinOp && ExtendedOp.BinOp != Link.ReductionBinOp) + BinOpc = ExtendedOp.BinOp->getOpcode(); + // If ExtendB is nullptr but there's a separate BinOp, the second operand // was a constant that can use the same extend kind as the first. - if (!ExtendB && ExtendedOp.BinOp && - ExtendedOp.BinOp != Chain.ReductionBinOp) { + if (!ExtendB && BinOpc) { const APInt *Const = nullptr; for (VPValue *Op : ExtendedOp.BinOp->operands()) { if (match(Op, m_APInt(Const))) break; } if (!Const || !canConstantBeExtended(Const, ExtOpTypeA, ExtKindA)) - return false; + return InstructionCost::getInvalid(); ExtOpTypeB = ExtOpTypeA; ExtKindB = ExtKindA; } - std::optional BinOpc; - if (ExtendedOp.BinOp && ExtendedOp.BinOp != Chain.ReductionBinOp) - BinOpc = ExtendedOp.BinOp->getOpcode(); + Type *RdxType = CostCtx.Types.inferScalarType(Link.ReductionBinOp); + std::optional Flags; + if (RdxType->isFloatingPointTy()) + Flags = Link.ReductionBinOp->getFastMathFlags(); - VPWidenRecipe *WidenRecipe = Chain.ReductionBinOp; - return LoopVectorizationPlanner::getDecisionAndClampRange( - [&](ElementCount VF) { - return CostCtx.TTI - .getPartialReductionCost( - WidenRecipe->getOpcode(), ExtOpTypeA, ExtOpTypeB, PhiType, VF, - ExtKindA, ExtKindB, BinOpc, CostCtx.CostKind, - PhiType->isFloatingPointTy() - ? std::optional{WidenRecipe->getFastMathFlags()} - : std::nullopt) - .isValid(); - }, - Range); + unsigned Opcode = Link.RK == RecurKind::Sub + ? (unsigned)Instruction::Add + : Link.ReductionBinOp->getOpcode(); + return CostCtx.TTI.getPartialReductionCost(Opcode, ExtOpTypeA, ExtOpTypeB, + RdxType, VF, ExtKindA, ExtKindB, + BinOpc, CostCtx.CostKind, Flags); } static TTI::PartialReductionExtendKind @@ -6228,7 +6208,7 @@ getScaledReductions(VPReductionPHIRecipe *RedPhiR, VPCostContext &CostCtx, VPValue *ExitValue = RdxResult->getOperand(0); match(ExitValue, m_Select(m_VPValue(), m_VPValue(ExitValue), m_VPValue())); - SmallVector Chains; + SmallVector Chain; RecurKind RK = RedPhiR->getRecurrenceKind(); Type *PhiType = CostCtx.Types.inferScalarType(RedPhiR); TypeSize PHISize = PhiType->getPrimitiveSizeInBits(); @@ -6260,20 +6240,20 @@ getScaledReductions(VPReductionPHIRecipe *RedPhiR, VPCostContext &CostCtx, if (!PHISize.hasKnownScalarFactor(ExtSrcSize)) return std::nullopt; - VPPartialReductionChain Chain( + // Check if a partial reduction chain is supported by the target (i.e. does + // not have an invalid cost) for the given VF range. Clamps the range and + // returns true if feasible for any VF. + VPPartialReductionChain Link( {UpdateR, *ExtendedOp, static_cast(PHISize.getKnownScalarFactor(ExtSrcSize)), RK}); - if (!isValidPartialReduction(Chain, PhiType, CostCtx, Range)) - return std::nullopt; - - Chains.push_back(Chain); + Chain.push_back(Link); CurrentValue = PrevValue; } - // The chains were collected by traversing backwards from the exit value. + // The chain links were collected by traversing backwards from the exit value. // Reverse the chains so they are in program order. - std::reverse(Chains.begin(), Chains.end()); - return Chains; + std::reverse(Chain.begin(), Chain.end()); + return Chain; } } // namespace @@ -6317,6 +6297,30 @@ void VPlanTransforms::createPartialReductions(VPlan &Plan, }); }; + auto IsProfitablePartialReductionChainForVF = + [&](ArrayRef Chain, ElementCount VF) -> bool { + InstructionCost PartialCost = 0, RegularCost = 0; + + // The chain is a profitable partial reduction chain if the cost of handling + // the entire chain is cheaper when using partial reductions than when + // handling the entire chain using regular reductions. + for (const VPPartialReductionChain &Link : Chain) { + const ExtendedReductionOperand &ExtendedOp = Link.ExtendedOp; + InstructionCost LinkCost = getPartialReductionLinkCost(CostCtx, Link, VF); + if (!LinkCost.isValid()) + return false; + + PartialCost += LinkCost; + RegularCost += Link.ReductionBinOp->computeCost(VF, CostCtx); + if (ExtendedOp.BinOp && ExtendedOp.BinOp != Link.ReductionBinOp) + RegularCost += ExtendedOp.BinOp->computeCost(VF, CostCtx); + for (VPWidenCastRecipe *Extend : ExtendedOp.CastRecipes) + if (Extend) + RegularCost += Extend->computeCost(VF, CostCtx); + } + return PartialCost.isValid() && PartialCost <= RegularCost; + }; + // Validate chains: check that extends are only used by partial reductions, // and that reduction bin ops are only used by other partial reductions with // matching scale factors, are outside the loop region or the select @@ -6355,6 +6359,14 @@ void VPlanTransforms::createPartialReductions(VPlan &Plan, } } } + + // Clear the chain if it is not profitable. + if (!LoopVectorizationPlanner::getDecisionAndClampRange( + [&, &Chains = Chains](ElementCount VF) { + return IsProfitablePartialReductionChainForVF(Chains, VF); + }, + Range)) + Chains.clear(); } for (auto &[Phi, Chains] : ChainsByPhi) diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-chained.ll b/llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-chained.ll index 15e0220b71d6..98d3ee86cf27 100644 --- a/llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-chained.ll +++ b/llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-chained.ll @@ -893,7 +893,7 @@ define i32 @chained_partial_reduce_sub_add_sub(ptr %a, ptr %b, ptr %c, i32 %N) # ; CHECK-SVE-MAXBW-NEXT: br label [[VECTOR_BODY:%.*]] ; CHECK-SVE-MAXBW: vector.body: ; CHECK-SVE-MAXBW-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ] -; CHECK-SVE-MAXBW-NEXT: [[VEC_PHI:%.*]] = phi [ zeroinitializer, [[VECTOR_PH]] ], [ [[PARTIAL_REDUCE4:%.*]], [[VECTOR_BODY]] ] +; CHECK-SVE-MAXBW-NEXT: [[VEC_PHI:%.*]] = phi [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP15:%.*]], [[VECTOR_BODY]] ] ; CHECK-SVE-MAXBW-NEXT: [[TMP7:%.*]] = getelementptr inbounds nuw i8, ptr [[A]], i64 [[INDEX]] ; CHECK-SVE-MAXBW-NEXT: [[TMP8:%.*]] = getelementptr inbounds nuw i8, ptr [[B]], i64 [[INDEX]] ; CHECK-SVE-MAXBW-NEXT: [[TMP9:%.*]] = getelementptr inbounds nuw i8, ptr [[C]], i64 [[INDEX]] @@ -902,20 +902,18 @@ define i32 @chained_partial_reduce_sub_add_sub(ptr %a, ptr %b, ptr %c, i32 %N) # ; CHECK-SVE-MAXBW-NEXT: [[WIDE_LOAD2:%.*]] = load , ptr [[TMP9]], align 1 ; CHECK-SVE-MAXBW-NEXT: [[TMP13:%.*]] = sext [[WIDE_LOAD]] to ; CHECK-SVE-MAXBW-NEXT: [[TMP14:%.*]] = sext [[WIDE_LOAD1]] to -; CHECK-SVE-MAXBW-NEXT: [[TMP16:%.*]] = mul nsw [[TMP13]], [[TMP14]] -; CHECK-SVE-MAXBW-NEXT: [[TMP17:%.*]] = sub nsw zeroinitializer, [[TMP16]] -; CHECK-SVE-MAXBW-NEXT: [[PARTIAL_REDUCE:%.*]] = call @llvm.vector.partial.reduce.add.nxv2i32.nxv8i32( [[VEC_PHI]], [[TMP17]]) ; CHECK-SVE-MAXBW-NEXT: [[TMP12:%.*]] = sext [[WIDE_LOAD2]] to +; CHECK-SVE-MAXBW-NEXT: [[TMP10:%.*]] = mul nsw [[TMP13]], [[TMP14]] +; CHECK-SVE-MAXBW-NEXT: [[TMP11:%.*]] = sub [[VEC_PHI]], [[TMP10]] ; CHECK-SVE-MAXBW-NEXT: [[TMP18:%.*]] = mul nsw [[TMP13]], [[TMP12]] -; CHECK-SVE-MAXBW-NEXT: [[PARTIAL_REDUCE3:%.*]] = call @llvm.vector.partial.reduce.add.nxv2i32.nxv8i32( [[PARTIAL_REDUCE]], [[TMP18]]) +; CHECK-SVE-MAXBW-NEXT: [[TMP16:%.*]] = add [[TMP11]], [[TMP18]] ; CHECK-SVE-MAXBW-NEXT: [[TMP19:%.*]] = mul nsw [[TMP14]], [[TMP12]] -; CHECK-SVE-MAXBW-NEXT: [[TMP20:%.*]] = sub zeroinitializer, [[TMP19]] -; CHECK-SVE-MAXBW-NEXT: [[PARTIAL_REDUCE4]] = call @llvm.vector.partial.reduce.add.nxv2i32.nxv8i32( [[PARTIAL_REDUCE3]], [[TMP20]]) +; CHECK-SVE-MAXBW-NEXT: [[TMP15]] = sub [[TMP16]], [[TMP19]] ; CHECK-SVE-MAXBW-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP3]] ; CHECK-SVE-MAXBW-NEXT: [[TMP22:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]] ; CHECK-SVE-MAXBW-NEXT: br i1 [[TMP22]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP12:![0-9]+]] ; CHECK-SVE-MAXBW: middle.block: -; CHECK-SVE-MAXBW-NEXT: [[TMP23:%.*]] = call i32 @llvm.vector.reduce.add.nxv2i32( [[PARTIAL_REDUCE4]]) +; CHECK-SVE-MAXBW-NEXT: [[TMP17:%.*]] = call i32 @llvm.vector.reduce.add.nxv8i32( [[TMP15]]) ; CHECK-SVE-MAXBW-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[WIDE_TRIP_COUNT]], [[N_VEC]] ; CHECK-SVE-MAXBW-NEXT: br i1 [[CMP_N]], label [[FOR_COND_CLEANUP:%.*]], label [[SCALAR_PH]] ; CHECK-SVE-MAXBW: scalar.ph: diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-fdot-product.ll b/llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-fdot-product.ll index c0667bc26e82..4769dccb996e 100644 --- a/llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-fdot-product.ll +++ b/llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-fdot-product.ll @@ -956,8 +956,8 @@ define double @ext_fmul_half_to_double(i64 %n, ptr %a, i8 %b) #2 { ; CHECK-NEXT: br label %[[VECTOR_BODY:.*]] ; CHECK: [[VECTOR_BODY]]: ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ] -; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <2 x double> [ , %[[VECTOR_PH]] ], [ [[PARTIAL_REDUCE:%.*]], %[[VECTOR_BODY]] ] -; CHECK-NEXT: [[VEC_PHI1:%.*]] = phi <2 x double> [ splat (double -0.000000e+00), %[[VECTOR_PH]] ], [ [[PARTIAL_REDUCE3:%.*]], %[[VECTOR_BODY]] ] +; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <8 x double> [ , %[[VECTOR_PH]] ], [ [[TMP9:%.*]], %[[VECTOR_BODY]] ] +; CHECK-NEXT: [[VEC_PHI1:%.*]] = phi <8 x double> [ splat (double -0.000000e+00), %[[VECTOR_PH]] ], [ [[TMP10:%.*]], %[[VECTOR_BODY]] ] ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr half, ptr [[A]], i64 [[INDEX]] ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr half, ptr [[TMP1]], i64 8 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <8 x half>, ptr [[TMP1]], align 2 @@ -967,15 +967,15 @@ define double @ext_fmul_half_to_double(i64 %n, ptr %a, i8 %b) #2 { ; CHECK-NEXT: [[TMP5:%.*]] = fmul reassoc contract <8 x float> [[TMP3]], [[TMP3]] ; CHECK-NEXT: [[TMP6:%.*]] = fmul reassoc contract <8 x float> [[TMP4]], [[TMP4]] ; CHECK-NEXT: [[TMP7:%.*]] = fpext <8 x float> [[TMP5]] to <8 x double> -; CHECK-NEXT: [[PARTIAL_REDUCE]] = call reassoc contract <2 x double> @llvm.vector.partial.reduce.fadd.v2f64.v8f64(<2 x double> [[VEC_PHI]], <8 x double> [[TMP7]]) ; CHECK-NEXT: [[TMP8:%.*]] = fpext <8 x float> [[TMP6]] to <8 x double> -; CHECK-NEXT: [[PARTIAL_REDUCE3]] = call reassoc contract <2 x double> @llvm.vector.partial.reduce.fadd.v2f64.v8f64(<2 x double> [[VEC_PHI1]], <8 x double> [[TMP8]]) +; CHECK-NEXT: [[TMP9]] = fadd reassoc contract <8 x double> [[VEC_PHI]], [[TMP7]] +; CHECK-NEXT: [[TMP10]] = fadd reassoc contract <8 x double> [[VEC_PHI1]], [[TMP8]] ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 16 ; CHECK-NEXT: [[TMP11:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]] ; CHECK-NEXT: br i1 [[TMP11]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP30:![0-9]+]] ; CHECK: [[MIDDLE_BLOCK]]: -; CHECK-NEXT: [[BIN_RDX:%.*]] = fadd reassoc contract <2 x double> [[PARTIAL_REDUCE3]], [[PARTIAL_REDUCE]] -; CHECK-NEXT: [[TMP10:%.*]] = call reassoc contract double @llvm.vector.reduce.fadd.v2f64(double -0.000000e+00, <2 x double> [[BIN_RDX]]) +; CHECK-NEXT: [[BIN_RDX:%.*]] = fadd reassoc contract <8 x double> [[TMP10]], [[TMP9]] +; CHECK-NEXT: [[TMP12:%.*]] = call reassoc contract double @llvm.vector.reduce.fadd.v8f64(double -0.000000e+00, <8 x double> [[BIN_RDX]]) ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[TMP0]], [[N_VEC]] ; CHECK-NEXT: br i1 [[CMP_N]], [[EXIT:label %.*]], label %[[SCALAR_PH]] ; CHECK: [[SCALAR_PH]]: diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-no-dotprod.ll b/llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-no-dotprod.ll index 87076baff329..de1f76c3ceb0 100644 --- a/llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-no-dotprod.ll +++ b/llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-no-dotprod.ll @@ -13,30 +13,30 @@ define i32 @not_dotp(ptr %a, ptr %b) { ; CHECK-NEXT: br label %[[VECTOR_BODY:.*]] ; CHECK: [[VECTOR_BODY]]: ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ] -; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x i32> [ zeroinitializer, %[[VECTOR_PH]] ], [ [[PARTIAL_REDUCE:%.*]], %[[VECTOR_BODY]] ] -; CHECK-NEXT: [[VEC_PHI1:%.*]] = phi <4 x i32> [ zeroinitializer, %[[VECTOR_PH]] ], [ [[PARTIAL_REDUCE5:%.*]], %[[VECTOR_BODY]] ] +; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <16 x i32> [ zeroinitializer, %[[VECTOR_PH]] ], [ [[TMP14:%.*]], %[[VECTOR_BODY]] ] +; CHECK-NEXT: [[VEC_PHI1:%.*]] = phi <16 x i32> [ zeroinitializer, %[[VECTOR_PH]] ], [ [[TMP16:%.*]], %[[VECTOR_BODY]] ] ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr i8, ptr [[A]], i64 [[INDEX]] ; CHECK-NEXT: [[TMP3:%.*]] = getelementptr i8, ptr [[TMP1]], i64 16 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <16 x i8>, ptr [[TMP1]], align 1 ; CHECK-NEXT: [[WIDE_LOAD2:%.*]] = load <16 x i8>, ptr [[TMP3]], align 1 +; CHECK-NEXT: [[TMP4:%.*]] = zext <16 x i8> [[WIDE_LOAD]] to <16 x i32> +; CHECK-NEXT: [[TMP5:%.*]] = zext <16 x i8> [[WIDE_LOAD2]] to <16 x i32> ; CHECK-NEXT: [[TMP6:%.*]] = getelementptr i8, ptr [[B]], i64 [[INDEX]] ; CHECK-NEXT: [[TMP8:%.*]] = getelementptr i8, ptr [[TMP6]], i64 16 ; CHECK-NEXT: [[WIDE_LOAD3:%.*]] = load <16 x i8>, ptr [[TMP6]], align 1 ; CHECK-NEXT: [[WIDE_LOAD4:%.*]] = load <16 x i8>, ptr [[TMP8]], align 1 ; CHECK-NEXT: [[TMP9:%.*]] = zext <16 x i8> [[WIDE_LOAD3]] to <16 x i32> -; CHECK-NEXT: [[TMP4:%.*]] = zext <16 x i8> [[WIDE_LOAD]] to <16 x i32> -; CHECK-NEXT: [[TMP11:%.*]] = mul <16 x i32> [[TMP9]], [[TMP4]] -; CHECK-NEXT: [[PARTIAL_REDUCE]] = call <4 x i32> @llvm.vector.partial.reduce.add.v4i32.v16i32(<4 x i32> [[VEC_PHI]], <16 x i32> [[TMP11]]) ; CHECK-NEXT: [[TMP10:%.*]] = zext <16 x i8> [[WIDE_LOAD4]] to <16 x i32> -; CHECK-NEXT: [[TMP5:%.*]] = zext <16 x i8> [[WIDE_LOAD2]] to <16 x i32> +; CHECK-NEXT: [[TMP11:%.*]] = mul <16 x i32> [[TMP9]], [[TMP4]] ; CHECK-NEXT: [[TMP12:%.*]] = mul <16 x i32> [[TMP10]], [[TMP5]] -; CHECK-NEXT: [[PARTIAL_REDUCE5]] = call <4 x i32> @llvm.vector.partial.reduce.add.v4i32.v16i32(<4 x i32> [[VEC_PHI1]], <16 x i32> [[TMP12]]) +; CHECK-NEXT: [[TMP14]] = add <16 x i32> [[TMP11]], [[VEC_PHI]] +; CHECK-NEXT: [[TMP16]] = add <16 x i32> [[TMP12]], [[VEC_PHI1]] ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 32 ; CHECK-NEXT: [[TMP15:%.*]] = icmp eq i64 [[INDEX_NEXT]], 992 ; CHECK-NEXT: br i1 [[TMP15]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]] ; CHECK: [[MIDDLE_BLOCK]]: -; CHECK-NEXT: [[BIN_RDX:%.*]] = add <4 x i32> [[PARTIAL_REDUCE5]], [[PARTIAL_REDUCE]] -; CHECK-NEXT: [[TMP13:%.*]] = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[BIN_RDX]]) +; CHECK-NEXT: [[BIN_RDX:%.*]] = add <16 x i32> [[TMP16]], [[TMP14]] +; CHECK-NEXT: [[TMP13:%.*]] = call i32 @llvm.vector.reduce.add.v16i32(<16 x i32> [[BIN_RDX]]) ; CHECK-NEXT: br label %[[SCALAR_PH:.*]] ; CHECK: [[SCALAR_PH]]: ; diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/vector-reverse.ll b/llvm/test/Transforms/LoopVectorize/AArch64/vector-reverse.ll index 518a502a0850..0f95dc5645c4 100644 --- a/llvm/test/Transforms/LoopVectorize/AArch64/vector-reverse.ll +++ b/llvm/test/Transforms/LoopVectorize/AArch64/vector-reverse.ll @@ -203,17 +203,17 @@ define i32 @reverse_store_with_partial_reduction(ptr noalias %dst, ptr noalias % ; CHECK-NEXT: [[N_MOD_VF10:%.*]] = urem i64 [[TMP0]], 4 ; CHECK-NEXT: [[N_VEC11:%.*]] = sub i64 [[TMP0]], [[N_MOD_VF10]] ; CHECK-NEXT: [[TMP32:%.*]] = sub i64 [[N]], [[N_VEC11]] -; CHECK-NEXT: [[TMP33:%.*]] = insertelement <2 x i32> zeroinitializer, i32 [[BC_MERGE_RDX]], i32 0 +; CHECK-NEXT: [[TMP26:%.*]] = insertelement <4 x i32> zeroinitializer, i32 [[BC_MERGE_RDX]], i32 0 ; CHECK-NEXT: br label %[[VEC_EPILOG_VECTOR_BODY:.*]] ; CHECK: [[VEC_EPILOG_VECTOR_BODY]]: ; CHECK-NEXT: [[INDEX12:%.*]] = phi i64 [ [[VEC_EPILOG_RESUME_VAL]], %[[VEC_EPILOG_PH]] ], [ [[INDEX_NEXT18:%.*]], %[[VEC_EPILOG_VECTOR_BODY]] ] -; CHECK-NEXT: [[VEC_PHI13:%.*]] = phi <2 x i32> [ [[TMP33]], %[[VEC_EPILOG_PH]] ], [ [[PARTIAL_REDUCE16:%.*]], %[[VEC_EPILOG_VECTOR_BODY]] ] +; CHECK-NEXT: [[VEC_PHI13:%.*]] = phi <4 x i32> [ [[TMP26]], %[[VEC_EPILOG_PH]] ], [ [[TMP33:%.*]], %[[VEC_EPILOG_VECTOR_BODY]] ] ; CHECK-NEXT: [[OFFSET_IDX:%.*]] = sub i64 [[N]], [[INDEX12]] ; CHECK-NEXT: [[TMP34:%.*]] = load i16, ptr [[SRC]], align 2 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT14:%.*]] = insertelement <4 x i16> poison, i16 [[TMP34]], i64 0 ; CHECK-NEXT: [[BROADCAST_SPLAT15:%.*]] = shufflevector <4 x i16> [[BROADCAST_SPLATINSERT14]], <4 x i16> poison, <4 x i32> zeroinitializer ; CHECK-NEXT: [[TMP35:%.*]] = sext <4 x i16> [[BROADCAST_SPLAT15]] to <4 x i32> -; CHECK-NEXT: [[PARTIAL_REDUCE16]] = call <2 x i32> @llvm.vector.partial.reduce.add.v2i32.v4i32(<2 x i32> [[VEC_PHI13]], <4 x i32> [[TMP35]]) +; CHECK-NEXT: [[TMP33]] = add <4 x i32> [[VEC_PHI13]], [[TMP35]] ; CHECK-NEXT: [[TMP36:%.*]] = getelementptr i16, ptr [[DST]], i64 [[OFFSET_IDX]] ; CHECK-NEXT: [[TMP38:%.*]] = getelementptr i16, ptr [[TMP36]], i64 -3 ; CHECK-NEXT: [[REVERSE17:%.*]] = shufflevector <4 x i16> [[BROADCAST_SPLAT15]], <4 x i16> poison, <4 x i32> @@ -222,7 +222,7 @@ define i32 @reverse_store_with_partial_reduction(ptr noalias %dst, ptr noalias % ; CHECK-NEXT: [[TMP39:%.*]] = icmp eq i64 [[INDEX_NEXT18]], [[N_VEC11]] ; CHECK-NEXT: br i1 [[TMP39]], label %[[VEC_EPILOG_MIDDLE_BLOCK:.*]], label %[[VEC_EPILOG_VECTOR_BODY]], !llvm.loop [[LOOP9:![0-9]+]] ; CHECK: [[VEC_EPILOG_MIDDLE_BLOCK]]: -; CHECK-NEXT: [[TMP40:%.*]] = call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> [[PARTIAL_REDUCE16]]) +; CHECK-NEXT: [[TMP37:%.*]] = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[TMP33]]) ; CHECK-NEXT: [[CMP_N19:%.*]] = icmp eq i64 [[TMP0]], [[N_VEC11]] ; CHECK-NEXT: br i1 [[CMP_N19]], [[EXIT]], label %[[VEC_EPILOG_SCALAR_PH]] ; CHECK: [[VEC_EPILOG_SCALAR_PH]]: