diff --git a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp --- a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp +++ b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp @@ -982,9 +982,16 @@ SmallPtrSet FusedInsts; for (CallInst *CI : MaybeFusableInsts) LowerMatrixMultiplyFused(CI, FusedInsts); + + // Third, try to lower any dot products + for (CallInst *CI : MaybeFusableInsts) { + if (FusedInsts.find(CI) != FusedInsts.end()) // skip if already fused + continue; + lowerDotProduct(CI, FusedInsts, getFastMathFlags(CI)); + } Changed = !FusedInsts.empty(); - // Third, lower remaining instructions with shape information. + // Fourth, lower remaining instructions with shape information. for (Instruction *Inst : MatrixInsts) { if (FusedInsts.count(Inst)) continue; @@ -1311,6 +1318,101 @@ } } + /// Special case for MatMul lowering. Prevents scalar loads of row-major + /// vectors Lowers to vector reduction add instead of sequential add if + /// reassocation is enabled. + void lowerDotProduct(CallInst *MatMul, + SmallPtrSet &FusedInsts, + FastMathFlags FMF) { + ShapeInfo LShape(MatMul->getArgOperand(2), MatMul->getArgOperand(3)); + ShapeInfo RShape(MatMul->getArgOperand(3), MatMul->getArgOperand(4)); + + if (LShape.NumRows != 1 || RShape.NumColumns != 1) // not a dot product + return; + + Value *LHS = MatMul->getArgOperand(0); + Value *RHS = MatMul->getArgOperand(1); + + Type *ElementType = cast(LHS->getType())->getElementType(); + bool IsIntVec = ElementType->isIntegerTy(); + + // Floating point reductions require reassocation. + if (!IsIntVec && !FMF.allowReassoc()) + return; + + auto IsSupportedArg = [](Value *Op, unsigned N) { + if (!isa(Op)) + return true; + return match(Op, m_OneUse(m_CombineOr( + m_Load(m_Value()), + m_Intrinsic( + m_Value(), m_SpecificInt(N))))); + }; + if (!IsSupportedArg(RHS, RShape.NumColumns) || + !IsSupportedArg(LHS, LShape.NumColumns)) + return; + + // We compare the costs of a vector.reduce.add to sequential add. + int AddOpCode = IsIntVec ? Instruction::Add : Instruction::FAdd; + FastMathFlags FMFReassoc; + FMFReassoc.setAllowReassoc(); + InstructionCost ReductionCost = TTI.getArithmeticReductionCost( + AddOpCode, cast(LHS->getType()), FMFReassoc); + InstructionCost SequentialAddCost = + TTI.getArithmeticInstrCost(AddOpCode, ElementType) * + (LShape.NumColumns - 1); + if (ReductionCost >= SequentialAddCost) + return; + + FusedInsts.insert(MatMul); + IRBuilder<> Builder(MatMul); + auto FlattenArg = [&Builder, &FusedInsts](Value *Op) -> Value * { + // Matmul must be the only user of loads because we don't use LowerLoad + // for row vectors (LowerLoad results in scalar loads and shufflevectors + // instead of single vector load). + if (!match(Op, m_CombineOr( + m_Load(m_Value()), + m_Intrinsic()))) { + return Op; + } + FusedInsts.insert(cast(Op)); + + // If vector uses the builtin load, lower to a LoadInst + Value *Ptr; + if (match(Op, m_Intrinsic( + m_Value(Ptr)))) { + auto *NewLoad = Builder.CreateLoad(Op->getType(), Ptr); + Op->replaceAllUsesWith(NewLoad); + cast(Op)->eraseFromParent(); + return NewLoad; + } + return Op; + }; + LHS = FlattenArg(LHS); + RHS = FlattenArg(RHS); + + // Insert mul/fmul and llvm.vector.reduce.fadd + Value *Mul = + IsIntVec ? Builder.CreateMul(LHS, RHS) : Builder.CreateFMul(LHS, RHS); + + Value *Result; + if (IsIntVec) + Result = Builder.CreateAddReduce(Mul); + else { + Result = Builder.CreateFAddReduce( + ConstantFP::get(cast(LHS->getType())->getElementType(), + 0.0), + Mul); + cast(Result)->setFastMathFlags(FMF); + } + + // pack scalar back into a matrix and then replace matmul inst + Result = Builder.CreateInsertElement(PoisonValue::get(MatMul->getType()), + Result, uint64_t(0)); + MatMul->replaceAllUsesWith(Result); + MatMul->eraseFromParent(); + } + /// Compute \p Result += \p A * \p B for input matrices with left-associating /// addition. /// diff --git a/llvm/test/Transforms/LowerMatrixIntrinsics/dot-product-int.ll b/llvm/test/Transforms/LowerMatrixIntrinsics/dot-product-int.ll --- a/llvm/test/Transforms/LowerMatrixIntrinsics/dot-product-int.ll +++ b/llvm/test/Transforms/LowerMatrixIntrinsics/dot-product-int.ll @@ -5,65 +5,10 @@ define <1 x i32> @dotproduct_i32_v8(<8 x i32> %a, <8 x i32> %b) { ; CHECK-LABEL: @dotproduct_i32_v8( ; CHECK-NEXT: entry: -; CHECK-NEXT: [[SPLIT:%.*]] = shufflevector <8 x i32> [[A:%.*]], <8 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[SPLIT1:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT2:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT3:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT4:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT5:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT6:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT7:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT8:%.*]] = shufflevector <8 x i32> [[B:%.*]], <8 x i32> poison, <8 x i32> -; CHECK-NEXT: [[BLOCK:%.*]] = shufflevector <1 x i32> [[SPLIT]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP0:%.*]] = extractelement <8 x i32> [[SPLIT8]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLATINSERT:%.*]] = insertelement <1 x i32> poison, i32 [[TMP0]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP1:%.*]] = mul <1 x i32> [[BLOCK]], [[SPLAT_SPLAT]] -; CHECK-NEXT: [[BLOCK9:%.*]] = shufflevector <1 x i32> [[SPLIT1]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP2:%.*]] = extractelement <8 x i32> [[SPLIT8]], i64 1 -; CHECK-NEXT: [[SPLAT_SPLATINSERT10:%.*]] = insertelement <1 x i32> poison, i32 [[TMP2]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT11:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT10]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP3:%.*]] = mul <1 x i32> [[BLOCK9]], [[SPLAT_SPLAT11]] -; CHECK-NEXT: [[TMP4:%.*]] = add <1 x i32> [[TMP1]], [[TMP3]] -; CHECK-NEXT: [[BLOCK12:%.*]] = shufflevector <1 x i32> [[SPLIT2]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP5:%.*]] = extractelement <8 x i32> [[SPLIT8]], i64 2 -; CHECK-NEXT: [[SPLAT_SPLATINSERT13:%.*]] = insertelement <1 x i32> poison, i32 [[TMP5]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT14:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT13]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP6:%.*]] = mul <1 x i32> [[BLOCK12]], [[SPLAT_SPLAT14]] -; CHECK-NEXT: [[TMP7:%.*]] = add <1 x i32> [[TMP4]], [[TMP6]] -; CHECK-NEXT: [[BLOCK15:%.*]] = shufflevector <1 x i32> [[SPLIT3]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP8:%.*]] = extractelement <8 x i32> [[SPLIT8]], i64 3 -; CHECK-NEXT: [[SPLAT_SPLATINSERT16:%.*]] = insertelement <1 x i32> poison, i32 [[TMP8]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT17:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT16]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP9:%.*]] = mul <1 x i32> [[BLOCK15]], [[SPLAT_SPLAT17]] -; CHECK-NEXT: [[TMP10:%.*]] = add <1 x i32> [[TMP7]], [[TMP9]] -; CHECK-NEXT: [[BLOCK18:%.*]] = shufflevector <1 x i32> [[SPLIT4]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP11:%.*]] = extractelement <8 x i32> [[SPLIT8]], i64 4 -; CHECK-NEXT: [[SPLAT_SPLATINSERT19:%.*]] = insertelement <1 x i32> poison, i32 [[TMP11]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT20:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT19]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP12:%.*]] = mul <1 x i32> [[BLOCK18]], [[SPLAT_SPLAT20]] -; CHECK-NEXT: [[TMP13:%.*]] = add <1 x i32> [[TMP10]], [[TMP12]] -; CHECK-NEXT: [[BLOCK21:%.*]] = shufflevector <1 x i32> [[SPLIT5]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP14:%.*]] = extractelement <8 x i32> [[SPLIT8]], i64 5 -; CHECK-NEXT: [[SPLAT_SPLATINSERT22:%.*]] = insertelement <1 x i32> poison, i32 [[TMP14]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT23:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT22]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP15:%.*]] = mul <1 x i32> [[BLOCK21]], [[SPLAT_SPLAT23]] -; CHECK-NEXT: [[TMP16:%.*]] = add <1 x i32> [[TMP13]], [[TMP15]] -; CHECK-NEXT: [[BLOCK24:%.*]] = shufflevector <1 x i32> [[SPLIT6]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP17:%.*]] = extractelement <8 x i32> [[SPLIT8]], i64 6 -; CHECK-NEXT: [[SPLAT_SPLATINSERT25:%.*]] = insertelement <1 x i32> poison, i32 [[TMP17]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT26:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT25]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP18:%.*]] = mul <1 x i32> [[BLOCK24]], [[SPLAT_SPLAT26]] -; CHECK-NEXT: [[TMP19:%.*]] = add <1 x i32> [[TMP16]], [[TMP18]] -; CHECK-NEXT: [[BLOCK27:%.*]] = shufflevector <1 x i32> [[SPLIT7]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP20:%.*]] = extractelement <8 x i32> [[SPLIT8]], i64 7 -; CHECK-NEXT: [[SPLAT_SPLATINSERT28:%.*]] = insertelement <1 x i32> poison, i32 [[TMP20]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT29:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT28]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP21:%.*]] = mul <1 x i32> [[BLOCK27]], [[SPLAT_SPLAT29]] -; CHECK-NEXT: [[TMP22:%.*]] = add <1 x i32> [[TMP19]], [[TMP21]] -; CHECK-NEXT: [[TMP23:%.*]] = shufflevector <1 x i32> [[TMP22]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP24:%.*]] = shufflevector <1 x i32> undef, <1 x i32> [[TMP23]], <1 x i32> -; CHECK-NEXT: ret <1 x i32> [[TMP24]] +; CHECK-NEXT: [[TMP0:%.*]] = mul <8 x i32> [[A:%.*]], [[B:%.*]] +; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> [[TMP0]]) +; CHECK-NEXT: [[TMP2:%.*]] = insertelement <1 x i32> poison, i32 [[TMP1]], i64 0 +; CHECK-NEXT: ret <1 x i32> [[TMP2]] ; entry: %c = tail call <1 x i32> @llvm.matrix.multiply.v1i32.v8i32.v8i32(<8 x i32> %a, <8 x i32> %b, i32 1, i32 8, i32 1) @@ -77,66 +22,11 @@ define <1 x i32> @dotproduct_i32_v8_result_used_by_inst(<8 x i32> %a, <8 x i32> %b) { ; CHECK-LABEL: @dotproduct_i32_v8_result_used_by_inst( ; CHECK-NEXT: entry: -; CHECK-NEXT: [[SPLIT:%.*]] = shufflevector <8 x i32> [[A:%.*]], <8 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[SPLIT1:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT2:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT3:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT4:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT5:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT6:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT7:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT8:%.*]] = shufflevector <8 x i32> [[B:%.*]], <8 x i32> poison, <8 x i32> -; CHECK-NEXT: [[BLOCK:%.*]] = shufflevector <1 x i32> [[SPLIT]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP0:%.*]] = extractelement <8 x i32> [[SPLIT8]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLATINSERT:%.*]] = insertelement <1 x i32> poison, i32 [[TMP0]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP1:%.*]] = mul <1 x i32> [[BLOCK]], [[SPLAT_SPLAT]] -; CHECK-NEXT: [[BLOCK9:%.*]] = shufflevector <1 x i32> [[SPLIT1]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP2:%.*]] = extractelement <8 x i32> [[SPLIT8]], i64 1 -; CHECK-NEXT: [[SPLAT_SPLATINSERT10:%.*]] = insertelement <1 x i32> poison, i32 [[TMP2]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT11:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT10]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP3:%.*]] = mul <1 x i32> [[BLOCK9]], [[SPLAT_SPLAT11]] -; CHECK-NEXT: [[TMP4:%.*]] = add <1 x i32> [[TMP1]], [[TMP3]] -; CHECK-NEXT: [[BLOCK12:%.*]] = shufflevector <1 x i32> [[SPLIT2]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP5:%.*]] = extractelement <8 x i32> [[SPLIT8]], i64 2 -; CHECK-NEXT: [[SPLAT_SPLATINSERT13:%.*]] = insertelement <1 x i32> poison, i32 [[TMP5]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT14:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT13]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP6:%.*]] = mul <1 x i32> [[BLOCK12]], [[SPLAT_SPLAT14]] -; CHECK-NEXT: [[TMP7:%.*]] = add <1 x i32> [[TMP4]], [[TMP6]] -; CHECK-NEXT: [[BLOCK15:%.*]] = shufflevector <1 x i32> [[SPLIT3]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP8:%.*]] = extractelement <8 x i32> [[SPLIT8]], i64 3 -; CHECK-NEXT: [[SPLAT_SPLATINSERT16:%.*]] = insertelement <1 x i32> poison, i32 [[TMP8]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT17:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT16]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP9:%.*]] = mul <1 x i32> [[BLOCK15]], [[SPLAT_SPLAT17]] -; CHECK-NEXT: [[TMP10:%.*]] = add <1 x i32> [[TMP7]], [[TMP9]] -; CHECK-NEXT: [[BLOCK18:%.*]] = shufflevector <1 x i32> [[SPLIT4]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP11:%.*]] = extractelement <8 x i32> [[SPLIT8]], i64 4 -; CHECK-NEXT: [[SPLAT_SPLATINSERT19:%.*]] = insertelement <1 x i32> poison, i32 [[TMP11]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT20:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT19]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP12:%.*]] = mul <1 x i32> [[BLOCK18]], [[SPLAT_SPLAT20]] -; CHECK-NEXT: [[TMP13:%.*]] = add <1 x i32> [[TMP10]], [[TMP12]] -; CHECK-NEXT: [[BLOCK21:%.*]] = shufflevector <1 x i32> [[SPLIT5]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP14:%.*]] = extractelement <8 x i32> [[SPLIT8]], i64 5 -; CHECK-NEXT: [[SPLAT_SPLATINSERT22:%.*]] = insertelement <1 x i32> poison, i32 [[TMP14]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT23:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT22]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP15:%.*]] = mul <1 x i32> [[BLOCK21]], [[SPLAT_SPLAT23]] -; CHECK-NEXT: [[TMP16:%.*]] = add <1 x i32> [[TMP13]], [[TMP15]] -; CHECK-NEXT: [[BLOCK24:%.*]] = shufflevector <1 x i32> [[SPLIT6]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP17:%.*]] = extractelement <8 x i32> [[SPLIT8]], i64 6 -; CHECK-NEXT: [[SPLAT_SPLATINSERT25:%.*]] = insertelement <1 x i32> poison, i32 [[TMP17]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT26:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT25]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP18:%.*]] = mul <1 x i32> [[BLOCK24]], [[SPLAT_SPLAT26]] -; CHECK-NEXT: [[TMP19:%.*]] = add <1 x i32> [[TMP16]], [[TMP18]] -; CHECK-NEXT: [[BLOCK27:%.*]] = shufflevector <1 x i32> [[SPLIT7]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP20:%.*]] = extractelement <8 x i32> [[SPLIT8]], i64 7 -; CHECK-NEXT: [[SPLAT_SPLATINSERT28:%.*]] = insertelement <1 x i32> poison, i32 [[TMP20]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT29:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT28]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP21:%.*]] = mul <1 x i32> [[BLOCK27]], [[SPLAT_SPLAT29]] -; CHECK-NEXT: [[TMP22:%.*]] = add <1 x i32> [[TMP19]], [[TMP21]] -; CHECK-NEXT: [[TMP23:%.*]] = shufflevector <1 x i32> [[TMP22]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP24:%.*]] = shufflevector <1 x i32> undef, <1 x i32> [[TMP23]], <1 x i32> -; CHECK-NEXT: call void @use(<1 x i32> [[TMP24]]) -; CHECK-NEXT: ret <1 x i32> [[TMP24]] +; CHECK-NEXT: [[TMP0:%.*]] = mul <8 x i32> [[A:%.*]], [[B:%.*]] +; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> [[TMP0]]) +; CHECK-NEXT: [[TMP2:%.*]] = insertelement <1 x i32> poison, i32 [[TMP1]], i64 0 +; CHECK-NEXT: call void @use(<1 x i32> [[TMP2]]) +; CHECK-NEXT: ret <1 x i32> [[TMP2]] ; entry: %c = tail call <1 x i32> @llvm.matrix.multiply.v1i32.v8i32.v8i32(<8 x i32> %a, <8 x i32> %b, i32 1, i32 8, i32 1) @@ -148,40 +38,10 @@ define <1 x i32> @dotproduct_i32_v8_constvector(<8 x i32> %a) { ; CHECK-LABEL: @dotproduct_i32_v8_constvector( ; CHECK-NEXT: entry: -; CHECK-NEXT: [[SPLIT:%.*]] = shufflevector <8 x i32> [[A:%.*]], <8 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[SPLIT1:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT2:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT3:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT4:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT5:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT6:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT7:%.*]] = shufflevector <8 x i32> [[A]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[BLOCK:%.*]] = shufflevector <1 x i32> [[SPLIT]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP0:%.*]] = mul <1 x i32> [[BLOCK]], -; CHECK-NEXT: [[BLOCK8:%.*]] = shufflevector <1 x i32> [[SPLIT1]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP1:%.*]] = mul <1 x i32> [[BLOCK8]], -; CHECK-NEXT: [[TMP2:%.*]] = add <1 x i32> [[TMP0]], [[TMP1]] -; CHECK-NEXT: [[BLOCK9:%.*]] = shufflevector <1 x i32> [[SPLIT2]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP3:%.*]] = mul <1 x i32> [[BLOCK9]], -; CHECK-NEXT: [[TMP4:%.*]] = add <1 x i32> [[TMP2]], [[TMP3]] -; CHECK-NEXT: [[BLOCK10:%.*]] = shufflevector <1 x i32> [[SPLIT3]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP5:%.*]] = mul <1 x i32> [[BLOCK10]], -; CHECK-NEXT: [[TMP6:%.*]] = add <1 x i32> [[TMP4]], [[TMP5]] -; CHECK-NEXT: [[BLOCK11:%.*]] = shufflevector <1 x i32> [[SPLIT4]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP7:%.*]] = mul <1 x i32> [[BLOCK11]], -; CHECK-NEXT: [[TMP8:%.*]] = add <1 x i32> [[TMP6]], [[TMP7]] -; CHECK-NEXT: [[BLOCK12:%.*]] = shufflevector <1 x i32> [[SPLIT5]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP9:%.*]] = mul <1 x i32> [[BLOCK12]], -; CHECK-NEXT: [[TMP10:%.*]] = add <1 x i32> [[TMP8]], [[TMP9]] -; CHECK-NEXT: [[BLOCK13:%.*]] = shufflevector <1 x i32> [[SPLIT6]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP11:%.*]] = mul <1 x i32> [[BLOCK13]], -; CHECK-NEXT: [[TMP12:%.*]] = add <1 x i32> [[TMP10]], [[TMP11]] -; CHECK-NEXT: [[BLOCK14:%.*]] = shufflevector <1 x i32> [[SPLIT7]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP13:%.*]] = mul <1 x i32> [[BLOCK14]], -; CHECK-NEXT: [[TMP14:%.*]] = add <1 x i32> [[TMP12]], [[TMP13]] -; CHECK-NEXT: [[TMP15:%.*]] = shufflevector <1 x i32> [[TMP14]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP16:%.*]] = shufflevector <1 x i32> undef, <1 x i32> [[TMP15]], <1 x i32> -; CHECK-NEXT: ret <1 x i32> [[TMP16]] +; CHECK-NEXT: [[TMP0:%.*]] = mul <8 x i32> [[A:%.*]], +; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> [[TMP0]]) +; CHECK-NEXT: [[TMP2:%.*]] = insertelement <1 x i32> poison, i32 [[TMP1]], i64 0 +; CHECK-NEXT: ret <1 x i32> [[TMP2]] ; entry: %c = tail call <1 x i32> @llvm.matrix.multiply.v1i32.v8i32.v8i32(<8 x i32> %a, <8 x i32> , i32 1, i32 8, i32 1) @@ -463,65 +323,10 @@ define <1 x i64> @dotproduct_i64_v8(<8 x i64> %a, <8 x i64> %b) { ; CHECK-LABEL: @dotproduct_i64_v8( ; CHECK-NEXT: entry: -; CHECK-NEXT: [[SPLIT:%.*]] = shufflevector <8 x i64> [[A:%.*]], <8 x i64> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[SPLIT1:%.*]] = shufflevector <8 x i64> [[A]], <8 x i64> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT2:%.*]] = shufflevector <8 x i64> [[A]], <8 x i64> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT3:%.*]] = shufflevector <8 x i64> [[A]], <8 x i64> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT4:%.*]] = shufflevector <8 x i64> [[A]], <8 x i64> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT5:%.*]] = shufflevector <8 x i64> [[A]], <8 x i64> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT6:%.*]] = shufflevector <8 x i64> [[A]], <8 x i64> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT7:%.*]] = shufflevector <8 x i64> [[A]], <8 x i64> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT8:%.*]] = shufflevector <8 x i64> [[B:%.*]], <8 x i64> poison, <8 x i32> -; CHECK-NEXT: [[BLOCK:%.*]] = shufflevector <1 x i64> [[SPLIT]], <1 x i64> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP0:%.*]] = extractelement <8 x i64> [[SPLIT8]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLATINSERT:%.*]] = insertelement <1 x i64> poison, i64 [[TMP0]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT:%.*]] = shufflevector <1 x i64> [[SPLAT_SPLATINSERT]], <1 x i64> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP1:%.*]] = mul <1 x i64> [[BLOCK]], [[SPLAT_SPLAT]] -; CHECK-NEXT: [[BLOCK9:%.*]] = shufflevector <1 x i64> [[SPLIT1]], <1 x i64> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP2:%.*]] = extractelement <8 x i64> [[SPLIT8]], i64 1 -; CHECK-NEXT: [[SPLAT_SPLATINSERT10:%.*]] = insertelement <1 x i64> poison, i64 [[TMP2]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT11:%.*]] = shufflevector <1 x i64> [[SPLAT_SPLATINSERT10]], <1 x i64> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP3:%.*]] = mul <1 x i64> [[BLOCK9]], [[SPLAT_SPLAT11]] -; CHECK-NEXT: [[TMP4:%.*]] = add <1 x i64> [[TMP1]], [[TMP3]] -; CHECK-NEXT: [[BLOCK12:%.*]] = shufflevector <1 x i64> [[SPLIT2]], <1 x i64> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP5:%.*]] = extractelement <8 x i64> [[SPLIT8]], i64 2 -; CHECK-NEXT: [[SPLAT_SPLATINSERT13:%.*]] = insertelement <1 x i64> poison, i64 [[TMP5]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT14:%.*]] = shufflevector <1 x i64> [[SPLAT_SPLATINSERT13]], <1 x i64> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP6:%.*]] = mul <1 x i64> [[BLOCK12]], [[SPLAT_SPLAT14]] -; CHECK-NEXT: [[TMP7:%.*]] = add <1 x i64> [[TMP4]], [[TMP6]] -; CHECK-NEXT: [[BLOCK15:%.*]] = shufflevector <1 x i64> [[SPLIT3]], <1 x i64> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP8:%.*]] = extractelement <8 x i64> [[SPLIT8]], i64 3 -; CHECK-NEXT: [[SPLAT_SPLATINSERT16:%.*]] = insertelement <1 x i64> poison, i64 [[TMP8]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT17:%.*]] = shufflevector <1 x i64> [[SPLAT_SPLATINSERT16]], <1 x i64> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP9:%.*]] = mul <1 x i64> [[BLOCK15]], [[SPLAT_SPLAT17]] -; CHECK-NEXT: [[TMP10:%.*]] = add <1 x i64> [[TMP7]], [[TMP9]] -; CHECK-NEXT: [[BLOCK18:%.*]] = shufflevector <1 x i64> [[SPLIT4]], <1 x i64> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP11:%.*]] = extractelement <8 x i64> [[SPLIT8]], i64 4 -; CHECK-NEXT: [[SPLAT_SPLATINSERT19:%.*]] = insertelement <1 x i64> poison, i64 [[TMP11]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT20:%.*]] = shufflevector <1 x i64> [[SPLAT_SPLATINSERT19]], <1 x i64> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP12:%.*]] = mul <1 x i64> [[BLOCK18]], [[SPLAT_SPLAT20]] -; CHECK-NEXT: [[TMP13:%.*]] = add <1 x i64> [[TMP10]], [[TMP12]] -; CHECK-NEXT: [[BLOCK21:%.*]] = shufflevector <1 x i64> [[SPLIT5]], <1 x i64> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP14:%.*]] = extractelement <8 x i64> [[SPLIT8]], i64 5 -; CHECK-NEXT: [[SPLAT_SPLATINSERT22:%.*]] = insertelement <1 x i64> poison, i64 [[TMP14]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT23:%.*]] = shufflevector <1 x i64> [[SPLAT_SPLATINSERT22]], <1 x i64> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP15:%.*]] = mul <1 x i64> [[BLOCK21]], [[SPLAT_SPLAT23]] -; CHECK-NEXT: [[TMP16:%.*]] = add <1 x i64> [[TMP13]], [[TMP15]] -; CHECK-NEXT: [[BLOCK24:%.*]] = shufflevector <1 x i64> [[SPLIT6]], <1 x i64> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP17:%.*]] = extractelement <8 x i64> [[SPLIT8]], i64 6 -; CHECK-NEXT: [[SPLAT_SPLATINSERT25:%.*]] = insertelement <1 x i64> poison, i64 [[TMP17]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT26:%.*]] = shufflevector <1 x i64> [[SPLAT_SPLATINSERT25]], <1 x i64> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP18:%.*]] = mul <1 x i64> [[BLOCK24]], [[SPLAT_SPLAT26]] -; CHECK-NEXT: [[TMP19:%.*]] = add <1 x i64> [[TMP16]], [[TMP18]] -; CHECK-NEXT: [[BLOCK27:%.*]] = shufflevector <1 x i64> [[SPLIT7]], <1 x i64> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP20:%.*]] = extractelement <8 x i64> [[SPLIT8]], i64 7 -; CHECK-NEXT: [[SPLAT_SPLATINSERT28:%.*]] = insertelement <1 x i64> poison, i64 [[TMP20]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT29:%.*]] = shufflevector <1 x i64> [[SPLAT_SPLATINSERT28]], <1 x i64> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP21:%.*]] = mul <1 x i64> [[BLOCK27]], [[SPLAT_SPLAT29]] -; CHECK-NEXT: [[TMP22:%.*]] = add <1 x i64> [[TMP19]], [[TMP21]] -; CHECK-NEXT: [[TMP23:%.*]] = shufflevector <1 x i64> [[TMP22]], <1 x i64> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP24:%.*]] = shufflevector <1 x i64> undef, <1 x i64> [[TMP23]], <1 x i32> -; CHECK-NEXT: ret <1 x i64> [[TMP24]] +; CHECK-NEXT: [[TMP0:%.*]] = mul <8 x i64> [[A:%.*]], [[B:%.*]] +; CHECK-NEXT: [[TMP1:%.*]] = call i64 @llvm.vector.reduce.add.v8i64(<8 x i64> [[TMP0]]) +; CHECK-NEXT: [[TMP2:%.*]] = insertelement <1 x i64> poison, i64 [[TMP1]], i64 0 +; CHECK-NEXT: ret <1 x i64> [[TMP2]] ; entry: %c = tail call <1 x i64> @llvm.matrix.multiply.v1i64.v8i64.v8i64(<8 x i64> %a, <8 x i64> %b, i32 1, i32 8, i32 1) @@ -533,88 +338,12 @@ define <1 x i32> @intrinsic_column_major_load_dot_product_i32_v8(ptr %lhs_address, ptr %rhs_address) { ; CHECK-LABEL: @intrinsic_column_major_load_dot_product_i32_v8( ; CHECK-NEXT: entry: -; CHECK-NEXT: [[COL_LOAD:%.*]] = load <8 x i32>, ptr [[LHS_ADDRESS:%.*]], align 4 -; CHECK-NEXT: [[COL_LOAD1:%.*]] = load <1 x i32>, ptr [[RHS_ADDRESS:%.*]], align 4 -; CHECK-NEXT: [[VEC_GEP:%.*]] = getelementptr i32, ptr [[RHS_ADDRESS]], i64 1 -; CHECK-NEXT: [[COL_LOAD2:%.*]] = load <1 x i32>, ptr [[VEC_GEP]], align 4 -; CHECK-NEXT: [[VEC_GEP3:%.*]] = getelementptr i32, ptr [[RHS_ADDRESS]], i64 2 -; CHECK-NEXT: [[COL_LOAD4:%.*]] = load <1 x i32>, ptr [[VEC_GEP3]], align 4 -; CHECK-NEXT: [[VEC_GEP5:%.*]] = getelementptr i32, ptr [[RHS_ADDRESS]], i64 3 -; CHECK-NEXT: [[COL_LOAD6:%.*]] = load <1 x i32>, ptr [[VEC_GEP5]], align 4 -; CHECK-NEXT: [[VEC_GEP7:%.*]] = getelementptr i32, ptr [[RHS_ADDRESS]], i64 4 -; CHECK-NEXT: [[COL_LOAD8:%.*]] = load <1 x i32>, ptr [[VEC_GEP7]], align 4 -; CHECK-NEXT: [[VEC_GEP9:%.*]] = getelementptr i32, ptr [[RHS_ADDRESS]], i64 5 -; CHECK-NEXT: [[COL_LOAD10:%.*]] = load <1 x i32>, ptr [[VEC_GEP9]], align 4 -; CHECK-NEXT: [[VEC_GEP11:%.*]] = getelementptr i32, ptr [[RHS_ADDRESS]], i64 6 -; CHECK-NEXT: [[COL_LOAD12:%.*]] = load <1 x i32>, ptr [[VEC_GEP11]], align 4 -; CHECK-NEXT: [[VEC_GEP13:%.*]] = getelementptr i32, ptr [[RHS_ADDRESS]], i64 7 -; CHECK-NEXT: [[COL_LOAD14:%.*]] = load <1 x i32>, ptr [[VEC_GEP13]], align 4 -; CHECK-NEXT: [[SPLIT:%.*]] = shufflevector <8 x i32> [[COL_LOAD]], <8 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[SPLIT15:%.*]] = shufflevector <8 x i32> [[COL_LOAD]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT16:%.*]] = shufflevector <8 x i32> [[COL_LOAD]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT17:%.*]] = shufflevector <8 x i32> [[COL_LOAD]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT18:%.*]] = shufflevector <8 x i32> [[COL_LOAD]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT19:%.*]] = shufflevector <8 x i32> [[COL_LOAD]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT20:%.*]] = shufflevector <8 x i32> [[COL_LOAD]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[SPLIT21:%.*]] = shufflevector <8 x i32> [[COL_LOAD]], <8 x i32> poison, <1 x i32> -; CHECK-NEXT: [[TMP0:%.*]] = shufflevector <1 x i32> [[COL_LOAD1]], <1 x i32> [[COL_LOAD2]], <2 x i32> -; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <1 x i32> [[COL_LOAD4]], <1 x i32> [[COL_LOAD6]], <2 x i32> -; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <1 x i32> [[COL_LOAD8]], <1 x i32> [[COL_LOAD10]], <2 x i32> -; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <1 x i32> [[COL_LOAD12]], <1 x i32> [[COL_LOAD14]], <2 x i32> -; CHECK-NEXT: [[TMP4:%.*]] = shufflevector <2 x i32> [[TMP0]], <2 x i32> [[TMP1]], <4 x i32> -; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <2 x i32> [[TMP2]], <2 x i32> [[TMP3]], <4 x i32> -; CHECK-NEXT: [[TMP6:%.*]] = shufflevector <4 x i32> [[TMP4]], <4 x i32> [[TMP5]], <8 x i32> -; CHECK-NEXT: [[SPLIT22:%.*]] = shufflevector <8 x i32> [[TMP6]], <8 x i32> poison, <8 x i32> -; CHECK-NEXT: [[BLOCK:%.*]] = shufflevector <1 x i32> [[SPLIT]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP7:%.*]] = extractelement <8 x i32> [[SPLIT22]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLATINSERT:%.*]] = insertelement <1 x i32> poison, i32 [[TMP7]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP8:%.*]] = mul <1 x i32> [[BLOCK]], [[SPLAT_SPLAT]] -; CHECK-NEXT: [[BLOCK23:%.*]] = shufflevector <1 x i32> [[SPLIT15]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP9:%.*]] = extractelement <8 x i32> [[SPLIT22]], i64 1 -; CHECK-NEXT: [[SPLAT_SPLATINSERT24:%.*]] = insertelement <1 x i32> poison, i32 [[TMP9]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT25:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT24]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP10:%.*]] = mul <1 x i32> [[BLOCK23]], [[SPLAT_SPLAT25]] -; CHECK-NEXT: [[TMP11:%.*]] = add <1 x i32> [[TMP8]], [[TMP10]] -; CHECK-NEXT: [[BLOCK26:%.*]] = shufflevector <1 x i32> [[SPLIT16]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP12:%.*]] = extractelement <8 x i32> [[SPLIT22]], i64 2 -; CHECK-NEXT: [[SPLAT_SPLATINSERT27:%.*]] = insertelement <1 x i32> poison, i32 [[TMP12]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT28:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT27]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP13:%.*]] = mul <1 x i32> [[BLOCK26]], [[SPLAT_SPLAT28]] -; CHECK-NEXT: [[TMP14:%.*]] = add <1 x i32> [[TMP11]], [[TMP13]] -; CHECK-NEXT: [[BLOCK29:%.*]] = shufflevector <1 x i32> [[SPLIT17]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP15:%.*]] = extractelement <8 x i32> [[SPLIT22]], i64 3 -; CHECK-NEXT: [[SPLAT_SPLATINSERT30:%.*]] = insertelement <1 x i32> poison, i32 [[TMP15]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT31:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT30]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP16:%.*]] = mul <1 x i32> [[BLOCK29]], [[SPLAT_SPLAT31]] -; CHECK-NEXT: [[TMP17:%.*]] = add <1 x i32> [[TMP14]], [[TMP16]] -; CHECK-NEXT: [[BLOCK32:%.*]] = shufflevector <1 x i32> [[SPLIT18]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP18:%.*]] = extractelement <8 x i32> [[SPLIT22]], i64 4 -; CHECK-NEXT: [[SPLAT_SPLATINSERT33:%.*]] = insertelement <1 x i32> poison, i32 [[TMP18]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT34:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT33]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP19:%.*]] = mul <1 x i32> [[BLOCK32]], [[SPLAT_SPLAT34]] -; CHECK-NEXT: [[TMP20:%.*]] = add <1 x i32> [[TMP17]], [[TMP19]] -; CHECK-NEXT: [[BLOCK35:%.*]] = shufflevector <1 x i32> [[SPLIT19]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP21:%.*]] = extractelement <8 x i32> [[SPLIT22]], i64 5 -; CHECK-NEXT: [[SPLAT_SPLATINSERT36:%.*]] = insertelement <1 x i32> poison, i32 [[TMP21]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT37:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT36]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP22:%.*]] = mul <1 x i32> [[BLOCK35]], [[SPLAT_SPLAT37]] -; CHECK-NEXT: [[TMP23:%.*]] = add <1 x i32> [[TMP20]], [[TMP22]] -; CHECK-NEXT: [[BLOCK38:%.*]] = shufflevector <1 x i32> [[SPLIT20]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP24:%.*]] = extractelement <8 x i32> [[SPLIT22]], i64 6 -; CHECK-NEXT: [[SPLAT_SPLATINSERT39:%.*]] = insertelement <1 x i32> poison, i32 [[TMP24]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT40:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT39]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP25:%.*]] = mul <1 x i32> [[BLOCK38]], [[SPLAT_SPLAT40]] -; CHECK-NEXT: [[TMP26:%.*]] = add <1 x i32> [[TMP23]], [[TMP25]] -; CHECK-NEXT: [[BLOCK41:%.*]] = shufflevector <1 x i32> [[SPLIT21]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP27:%.*]] = extractelement <8 x i32> [[SPLIT22]], i64 7 -; CHECK-NEXT: [[SPLAT_SPLATINSERT42:%.*]] = insertelement <1 x i32> poison, i32 [[TMP27]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT43:%.*]] = shufflevector <1 x i32> [[SPLAT_SPLATINSERT42]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP28:%.*]] = mul <1 x i32> [[BLOCK41]], [[SPLAT_SPLAT43]] -; CHECK-NEXT: [[TMP29:%.*]] = add <1 x i32> [[TMP26]], [[TMP28]] -; CHECK-NEXT: [[TMP30:%.*]] = shufflevector <1 x i32> [[TMP29]], <1 x i32> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP31:%.*]] = shufflevector <1 x i32> undef, <1 x i32> [[TMP30]], <1 x i32> -; CHECK-NEXT: ret <1 x i32> [[TMP31]] +; CHECK-NEXT: [[TMP0:%.*]] = load <8 x i32>, ptr [[LHS_ADDRESS:%.*]], align 32 +; CHECK-NEXT: [[TMP1:%.*]] = load <8 x i32>, ptr [[RHS_ADDRESS:%.*]], align 32 +; CHECK-NEXT: [[TMP2:%.*]] = mul <8 x i32> [[TMP0]], [[TMP1]] +; CHECK-NEXT: [[TMP3:%.*]] = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> [[TMP2]]) +; CHECK-NEXT: [[TMP4:%.*]] = insertelement <1 x i32> poison, i32 [[TMP3]], i64 0 +; CHECK-NEXT: ret <1 x i32> [[TMP4]] ; entry: %lhs = tail call <8 x i32> @llvm.matrix.column.major.load.v8i32.i64(ptr nonnull align 4 %lhs_address, i64 8, i1 false, i32 8, i32 1) @@ -740,56 +469,12 @@ define <1 x i16> @LoadInst_dot_product_i16_v6(ptr %lhs_address, ptr %rhs_address) { ; CHECK-LABEL: @LoadInst_dot_product_i16_v6( ; CHECK-NEXT: entry: -; CHECK-NEXT: [[COL_LOAD:%.*]] = load <1 x i16>, ptr [[LHS_ADDRESS:%.*]], align 16 -; CHECK-NEXT: [[VEC_GEP:%.*]] = getelementptr i16, ptr [[LHS_ADDRESS]], i64 1 -; CHECK-NEXT: [[COL_LOAD1:%.*]] = load <1 x i16>, ptr [[VEC_GEP]], align 2 -; CHECK-NEXT: [[VEC_GEP2:%.*]] = getelementptr i16, ptr [[LHS_ADDRESS]], i64 2 -; CHECK-NEXT: [[COL_LOAD3:%.*]] = load <1 x i16>, ptr [[VEC_GEP2]], align 4 -; CHECK-NEXT: [[VEC_GEP4:%.*]] = getelementptr i16, ptr [[LHS_ADDRESS]], i64 3 -; CHECK-NEXT: [[COL_LOAD5:%.*]] = load <1 x i16>, ptr [[VEC_GEP4]], align 2 -; CHECK-NEXT: [[VEC_GEP6:%.*]] = getelementptr i16, ptr [[LHS_ADDRESS]], i64 4 -; CHECK-NEXT: [[COL_LOAD7:%.*]] = load <1 x i16>, ptr [[VEC_GEP6]], align 8 -; CHECK-NEXT: [[VEC_GEP8:%.*]] = getelementptr i16, ptr [[LHS_ADDRESS]], i64 5 -; CHECK-NEXT: [[COL_LOAD9:%.*]] = load <1 x i16>, ptr [[VEC_GEP8]], align 2 -; CHECK-NEXT: [[COL_LOAD10:%.*]] = load <6 x i16>, ptr [[RHS_ADDRESS:%.*]], align 16 -; CHECK-NEXT: [[BLOCK:%.*]] = shufflevector <1 x i16> [[COL_LOAD]], <1 x i16> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP0:%.*]] = extractelement <6 x i16> [[COL_LOAD10]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLATINSERT:%.*]] = insertelement <1 x i16> poison, i16 [[TMP0]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT:%.*]] = shufflevector <1 x i16> [[SPLAT_SPLATINSERT]], <1 x i16> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP1:%.*]] = mul <1 x i16> [[BLOCK]], [[SPLAT_SPLAT]] -; CHECK-NEXT: [[BLOCK11:%.*]] = shufflevector <1 x i16> [[COL_LOAD1]], <1 x i16> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP2:%.*]] = extractelement <6 x i16> [[COL_LOAD10]], i64 1 -; CHECK-NEXT: [[SPLAT_SPLATINSERT12:%.*]] = insertelement <1 x i16> poison, i16 [[TMP2]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT13:%.*]] = shufflevector <1 x i16> [[SPLAT_SPLATINSERT12]], <1 x i16> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP3:%.*]] = mul <1 x i16> [[BLOCK11]], [[SPLAT_SPLAT13]] -; CHECK-NEXT: [[TMP4:%.*]] = add <1 x i16> [[TMP1]], [[TMP3]] -; CHECK-NEXT: [[BLOCK14:%.*]] = shufflevector <1 x i16> [[COL_LOAD3]], <1 x i16> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP5:%.*]] = extractelement <6 x i16> [[COL_LOAD10]], i64 2 -; CHECK-NEXT: [[SPLAT_SPLATINSERT15:%.*]] = insertelement <1 x i16> poison, i16 [[TMP5]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT16:%.*]] = shufflevector <1 x i16> [[SPLAT_SPLATINSERT15]], <1 x i16> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP6:%.*]] = mul <1 x i16> [[BLOCK14]], [[SPLAT_SPLAT16]] -; CHECK-NEXT: [[TMP7:%.*]] = add <1 x i16> [[TMP4]], [[TMP6]] -; CHECK-NEXT: [[BLOCK17:%.*]] = shufflevector <1 x i16> [[COL_LOAD5]], <1 x i16> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP8:%.*]] = extractelement <6 x i16> [[COL_LOAD10]], i64 3 -; CHECK-NEXT: [[SPLAT_SPLATINSERT18:%.*]] = insertelement <1 x i16> poison, i16 [[TMP8]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT19:%.*]] = shufflevector <1 x i16> [[SPLAT_SPLATINSERT18]], <1 x i16> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP9:%.*]] = mul <1 x i16> [[BLOCK17]], [[SPLAT_SPLAT19]] -; CHECK-NEXT: [[TMP10:%.*]] = add <1 x i16> [[TMP7]], [[TMP9]] -; CHECK-NEXT: [[BLOCK20:%.*]] = shufflevector <1 x i16> [[COL_LOAD7]], <1 x i16> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP11:%.*]] = extractelement <6 x i16> [[COL_LOAD10]], i64 4 -; CHECK-NEXT: [[SPLAT_SPLATINSERT21:%.*]] = insertelement <1 x i16> poison, i16 [[TMP11]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT22:%.*]] = shufflevector <1 x i16> [[SPLAT_SPLATINSERT21]], <1 x i16> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP12:%.*]] = mul <1 x i16> [[BLOCK20]], [[SPLAT_SPLAT22]] -; CHECK-NEXT: [[TMP13:%.*]] = add <1 x i16> [[TMP10]], [[TMP12]] -; CHECK-NEXT: [[BLOCK23:%.*]] = shufflevector <1 x i16> [[COL_LOAD9]], <1 x i16> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP14:%.*]] = extractelement <6 x i16> [[COL_LOAD10]], i64 5 -; CHECK-NEXT: [[SPLAT_SPLATINSERT24:%.*]] = insertelement <1 x i16> poison, i16 [[TMP14]], i64 0 -; CHECK-NEXT: [[SPLAT_SPLAT25:%.*]] = shufflevector <1 x i16> [[SPLAT_SPLATINSERT24]], <1 x i16> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP15:%.*]] = mul <1 x i16> [[BLOCK23]], [[SPLAT_SPLAT25]] -; CHECK-NEXT: [[TMP16:%.*]] = add <1 x i16> [[TMP13]], [[TMP15]] -; CHECK-NEXT: [[TMP17:%.*]] = shufflevector <1 x i16> [[TMP16]], <1 x i16> poison, <1 x i32> zeroinitializer -; CHECK-NEXT: [[TMP18:%.*]] = shufflevector <1 x i16> undef, <1 x i16> [[TMP17]], <1 x i32> -; CHECK-NEXT: ret <1 x i16> [[TMP18]] +; CHECK-NEXT: [[LHS:%.*]] = load <6 x i16>, ptr [[LHS_ADDRESS:%.*]], align 16 +; CHECK-NEXT: [[RHS:%.*]] = load <6 x i16>, ptr [[RHS_ADDRESS:%.*]], align 16 +; CHECK-NEXT: [[TMP0:%.*]] = mul <6 x i16> [[LHS]], [[RHS]] +; CHECK-NEXT: [[TMP1:%.*]] = call i16 @llvm.vector.reduce.add.v6i16(<6 x i16> [[TMP0]]) +; CHECK-NEXT: [[TMP2:%.*]] = insertelement <1 x i16> poison, i16 [[TMP1]], i64 0 +; CHECK-NEXT: ret <1 x i16> [[TMP2]] ; entry: %lhs = load <6 x i16>, ptr %lhs_address