Index: llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp =================================================================== --- llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp +++ llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp @@ -780,7 +780,7 @@ I->eraseFromParent(); if (A->use_empty()) cast(A)->eraseFromParent(); - if (B->use_empty()) + if (A != B && B->use_empty()) cast(B)->eraseFromParent(); } } Index: llvm/test/Transforms/LowerMatrixIntrinsics/transpose-opts.ll =================================================================== --- llvm/test/Transforms/LowerMatrixIntrinsics/transpose-opts.ll +++ llvm/test/Transforms/LowerMatrixIntrinsics/transpose-opts.ll @@ -936,10 +936,164 @@ ret void } +define <9 x float> @mult_tt_same_op(<9 x float> %a) { +; CHECK-LABEL: @mult_tt_same_op( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[SPLIT:%.*]] = shufflevector <9 x float> [[A:%.*]], <9 x float> poison, <3 x i32> +; CHECK-NEXT: [[SPLIT1:%.*]] = shufflevector <9 x float> [[A]], <9 x float> poison, <3 x i32> +; CHECK-NEXT: [[SPLIT2:%.*]] = shufflevector <9 x float> [[A]], <9 x float> poison, <3 x i32> +; CHECK-NEXT: [[SPLIT3:%.*]] = shufflevector <9 x float> [[A]], <9 x float> poison, <3 x i32> +; CHECK-NEXT: [[SPLIT4:%.*]] = shufflevector <9 x float> [[A]], <9 x float> poison, <3 x i32> +; CHECK-NEXT: [[SPLIT5:%.*]] = shufflevector <9 x float> [[A]], <9 x float> poison, <3 x i32> +; CHECK-NEXT: [[BLOCK:%.*]] = shufflevector <3 x float> [[SPLIT]], <3 x float> poison, <2 x i32> +; CHECK-NEXT: [[TMP0:%.*]] = extractelement <3 x float> [[SPLIT3]], i64 0 +; CHECK-NEXT: [[SPLAT_SPLATINSERT:%.*]] = insertelement <2 x float> poison, float [[TMP0]], i32 0 +; CHECK-NEXT: [[SPLAT_SPLAT:%.*]] = shufflevector <2 x float> [[SPLAT_SPLATINSERT]], <2 x float> poison, <2 x i32> zeroinitializer +; CHECK-NEXT: [[TMP1:%.*]] = fmul <2 x float> [[BLOCK]], [[SPLAT_SPLAT]] +; CHECK-NEXT: [[BLOCK6:%.*]] = shufflevector <3 x float> [[SPLIT1]], <3 x float> poison, <2 x i32> +; CHECK-NEXT: [[TMP2:%.*]] = extractelement <3 x float> [[SPLIT3]], i64 1 +; CHECK-NEXT: [[SPLAT_SPLATINSERT7:%.*]] = insertelement <2 x float> poison, float [[TMP2]], i32 0 +; CHECK-NEXT: [[SPLAT_SPLAT8:%.*]] = shufflevector <2 x float> [[SPLAT_SPLATINSERT7]], <2 x float> poison, <2 x i32> zeroinitializer +; CHECK-NEXT: [[TMP3:%.*]] = fmul <2 x float> [[BLOCK6]], [[SPLAT_SPLAT8]] +; CHECK-NEXT: [[TMP4:%.*]] = fadd <2 x float> [[TMP1]], [[TMP3]] +; CHECK-NEXT: [[BLOCK9:%.*]] = shufflevector <3 x float> [[SPLIT2]], <3 x float> poison, <2 x i32> +; CHECK-NEXT: [[TMP5:%.*]] = extractelement <3 x float> [[SPLIT3]], i64 2 +; CHECK-NEXT: [[SPLAT_SPLATINSERT10:%.*]] = insertelement <2 x float> poison, float [[TMP5]], i32 0 +; CHECK-NEXT: [[SPLAT_SPLAT11:%.*]] = shufflevector <2 x float> [[SPLAT_SPLATINSERT10]], <2 x float> poison, <2 x i32> zeroinitializer +; CHECK-NEXT: [[TMP6:%.*]] = fmul <2 x float> [[BLOCK9]], [[SPLAT_SPLAT11]] +; CHECK-NEXT: [[TMP7:%.*]] = fadd <2 x float> [[TMP4]], [[TMP6]] +; CHECK-NEXT: [[TMP8:%.*]] = shufflevector <2 x float> [[TMP7]], <2 x float> poison, <3 x i32> +; CHECK-NEXT: [[TMP9:%.*]] = shufflevector <3 x float> undef, <3 x float> [[TMP8]], <3 x i32> +; CHECK-NEXT: [[BLOCK12:%.*]] = shufflevector <3 x float> [[SPLIT]], <3 x float> poison, <1 x i32> +; CHECK-NEXT: [[TMP10:%.*]] = extractelement <3 x float> [[SPLIT3]], i64 0 +; CHECK-NEXT: [[SPLAT_SPLATINSERT13:%.*]] = insertelement <1 x float> poison, float [[TMP10]], i32 0 +; CHECK-NEXT: [[SPLAT_SPLAT14:%.*]] = shufflevector <1 x float> [[SPLAT_SPLATINSERT13]], <1 x float> poison, <1 x i32> zeroinitializer +; CHECK-NEXT: [[TMP11:%.*]] = fmul <1 x float> [[BLOCK12]], [[SPLAT_SPLAT14]] +; CHECK-NEXT: [[BLOCK15:%.*]] = shufflevector <3 x float> [[SPLIT1]], <3 x float> poison, <1 x i32> +; CHECK-NEXT: [[TMP12:%.*]] = extractelement <3 x float> [[SPLIT3]], i64 1 +; CHECK-NEXT: [[SPLAT_SPLATINSERT16:%.*]] = insertelement <1 x float> poison, float [[TMP12]], i32 0 +; CHECK-NEXT: [[SPLAT_SPLAT17:%.*]] = shufflevector <1 x float> [[SPLAT_SPLATINSERT16]], <1 x float> poison, <1 x i32> zeroinitializer +; CHECK-NEXT: [[TMP13:%.*]] = fmul <1 x float> [[BLOCK15]], [[SPLAT_SPLAT17]] +; CHECK-NEXT: [[TMP14:%.*]] = fadd <1 x float> [[TMP11]], [[TMP13]] +; CHECK-NEXT: [[BLOCK18:%.*]] = shufflevector <3 x float> [[SPLIT2]], <3 x float> poison, <1 x i32> +; CHECK-NEXT: [[TMP15:%.*]] = extractelement <3 x float> [[SPLIT3]], i64 2 +; CHECK-NEXT: [[SPLAT_SPLATINSERT19:%.*]] = insertelement <1 x float> poison, float [[TMP15]], i32 0 +; CHECK-NEXT: [[SPLAT_SPLAT20:%.*]] = shufflevector <1 x float> [[SPLAT_SPLATINSERT19]], <1 x float> poison, <1 x i32> zeroinitializer +; CHECK-NEXT: [[TMP16:%.*]] = fmul <1 x float> [[BLOCK18]], [[SPLAT_SPLAT20]] +; CHECK-NEXT: [[TMP17:%.*]] = fadd <1 x float> [[TMP14]], [[TMP16]] +; CHECK-NEXT: [[TMP18:%.*]] = shufflevector <1 x float> [[TMP17]], <1 x float> poison, <3 x i32> +; CHECK-NEXT: [[TMP19:%.*]] = shufflevector <3 x float> [[TMP9]], <3 x float> [[TMP18]], <3 x i32> +; CHECK-NEXT: [[BLOCK21:%.*]] = shufflevector <3 x float> [[SPLIT]], <3 x float> poison, <2 x i32> +; CHECK-NEXT: [[TMP20:%.*]] = extractelement <3 x float> [[SPLIT4]], i64 0 +; CHECK-NEXT: [[SPLAT_SPLATINSERT22:%.*]] = insertelement <2 x float> poison, float [[TMP20]], i32 0 +; CHECK-NEXT: [[SPLAT_SPLAT23:%.*]] = shufflevector <2 x float> [[SPLAT_SPLATINSERT22]], <2 x float> poison, <2 x i32> zeroinitializer +; CHECK-NEXT: [[TMP21:%.*]] = fmul <2 x float> [[BLOCK21]], [[SPLAT_SPLAT23]] +; CHECK-NEXT: [[BLOCK24:%.*]] = shufflevector <3 x float> [[SPLIT1]], <3 x float> poison, <2 x i32> +; CHECK-NEXT: [[TMP22:%.*]] = extractelement <3 x float> [[SPLIT4]], i64 1 +; CHECK-NEXT: [[SPLAT_SPLATINSERT25:%.*]] = insertelement <2 x float> poison, float [[TMP22]], i32 0 +; CHECK-NEXT: [[SPLAT_SPLAT26:%.*]] = shufflevector <2 x float> [[SPLAT_SPLATINSERT25]], <2 x float> poison, <2 x i32> zeroinitializer +; CHECK-NEXT: [[TMP23:%.*]] = fmul <2 x float> [[BLOCK24]], [[SPLAT_SPLAT26]] +; CHECK-NEXT: [[TMP24:%.*]] = fadd <2 x float> [[TMP21]], [[TMP23]] +; CHECK-NEXT: [[BLOCK27:%.*]] = shufflevector <3 x float> [[SPLIT2]], <3 x float> poison, <2 x i32> +; CHECK-NEXT: [[TMP25:%.*]] = extractelement <3 x float> [[SPLIT4]], i64 2 +; CHECK-NEXT: [[SPLAT_SPLATINSERT28:%.*]] = insertelement <2 x float> poison, float [[TMP25]], i32 0 +; CHECK-NEXT: [[SPLAT_SPLAT29:%.*]] = shufflevector <2 x float> [[SPLAT_SPLATINSERT28]], <2 x float> poison, <2 x i32> zeroinitializer +; CHECK-NEXT: [[TMP26:%.*]] = fmul <2 x float> [[BLOCK27]], [[SPLAT_SPLAT29]] +; CHECK-NEXT: [[TMP27:%.*]] = fadd <2 x float> [[TMP24]], [[TMP26]] +; CHECK-NEXT: [[TMP28:%.*]] = shufflevector <2 x float> [[TMP27]], <2 x float> poison, <3 x i32> +; CHECK-NEXT: [[TMP29:%.*]] = shufflevector <3 x float> undef, <3 x float> [[TMP28]], <3 x i32> +; CHECK-NEXT: [[BLOCK30:%.*]] = shufflevector <3 x float> [[SPLIT]], <3 x float> poison, <1 x i32> +; CHECK-NEXT: [[TMP30:%.*]] = extractelement <3 x float> [[SPLIT4]], i64 0 +; CHECK-NEXT: [[SPLAT_SPLATINSERT31:%.*]] = insertelement <1 x float> poison, float [[TMP30]], i32 0 +; CHECK-NEXT: [[SPLAT_SPLAT32:%.*]] = shufflevector <1 x float> [[SPLAT_SPLATINSERT31]], <1 x float> poison, <1 x i32> zeroinitializer +; CHECK-NEXT: [[TMP31:%.*]] = fmul <1 x float> [[BLOCK30]], [[SPLAT_SPLAT32]] +; CHECK-NEXT: [[BLOCK33:%.*]] = shufflevector <3 x float> [[SPLIT1]], <3 x float> poison, <1 x i32> +; CHECK-NEXT: [[TMP32:%.*]] = extractelement <3 x float> [[SPLIT4]], i64 1 +; CHECK-NEXT: [[SPLAT_SPLATINSERT34:%.*]] = insertelement <1 x float> poison, float [[TMP32]], i32 0 +; CHECK-NEXT: [[SPLAT_SPLAT35:%.*]] = shufflevector <1 x float> [[SPLAT_SPLATINSERT34]], <1 x float> poison, <1 x i32> zeroinitializer +; CHECK-NEXT: [[TMP33:%.*]] = fmul <1 x float> [[BLOCK33]], [[SPLAT_SPLAT35]] +; CHECK-NEXT: [[TMP34:%.*]] = fadd <1 x float> [[TMP31]], [[TMP33]] +; CHECK-NEXT: [[BLOCK36:%.*]] = shufflevector <3 x float> [[SPLIT2]], <3 x float> poison, <1 x i32> +; CHECK-NEXT: [[TMP35:%.*]] = extractelement <3 x float> [[SPLIT4]], i64 2 +; CHECK-NEXT: [[SPLAT_SPLATINSERT37:%.*]] = insertelement <1 x float> poison, float [[TMP35]], i32 0 +; CHECK-NEXT: [[SPLAT_SPLAT38:%.*]] = shufflevector <1 x float> [[SPLAT_SPLATINSERT37]], <1 x float> poison, <1 x i32> zeroinitializer +; CHECK-NEXT: [[TMP36:%.*]] = fmul <1 x float> [[BLOCK36]], [[SPLAT_SPLAT38]] +; CHECK-NEXT: [[TMP37:%.*]] = fadd <1 x float> [[TMP34]], [[TMP36]] +; CHECK-NEXT: [[TMP38:%.*]] = shufflevector <1 x float> [[TMP37]], <1 x float> poison, <3 x i32> +; CHECK-NEXT: [[TMP39:%.*]] = shufflevector <3 x float> [[TMP29]], <3 x float> [[TMP38]], <3 x i32> +; CHECK-NEXT: [[BLOCK39:%.*]] = shufflevector <3 x float> [[SPLIT]], <3 x float> poison, <2 x i32> +; CHECK-NEXT: [[TMP40:%.*]] = extractelement <3 x float> [[SPLIT5]], i64 0 +; CHECK-NEXT: [[SPLAT_SPLATINSERT40:%.*]] = insertelement <2 x float> poison, float [[TMP40]], i32 0 +; CHECK-NEXT: [[SPLAT_SPLAT41:%.*]] = shufflevector <2 x float> [[SPLAT_SPLATINSERT40]], <2 x float> poison, <2 x i32> zeroinitializer +; CHECK-NEXT: [[TMP41:%.*]] = fmul <2 x float> [[BLOCK39]], [[SPLAT_SPLAT41]] +; CHECK-NEXT: [[BLOCK42:%.*]] = shufflevector <3 x float> [[SPLIT1]], <3 x float> poison, <2 x i32> +; CHECK-NEXT: [[TMP42:%.*]] = extractelement <3 x float> [[SPLIT5]], i64 1 +; CHECK-NEXT: [[SPLAT_SPLATINSERT43:%.*]] = insertelement <2 x float> poison, float [[TMP42]], i32 0 +; CHECK-NEXT: [[SPLAT_SPLAT44:%.*]] = shufflevector <2 x float> [[SPLAT_SPLATINSERT43]], <2 x float> poison, <2 x i32> zeroinitializer +; CHECK-NEXT: [[TMP43:%.*]] = fmul <2 x float> [[BLOCK42]], [[SPLAT_SPLAT44]] +; CHECK-NEXT: [[TMP44:%.*]] = fadd <2 x float> [[TMP41]], [[TMP43]] +; CHECK-NEXT: [[BLOCK45:%.*]] = shufflevector <3 x float> [[SPLIT2]], <3 x float> poison, <2 x i32> +; CHECK-NEXT: [[TMP45:%.*]] = extractelement <3 x float> [[SPLIT5]], i64 2 +; CHECK-NEXT: [[SPLAT_SPLATINSERT46:%.*]] = insertelement <2 x float> poison, float [[TMP45]], i32 0 +; CHECK-NEXT: [[SPLAT_SPLAT47:%.*]] = shufflevector <2 x float> [[SPLAT_SPLATINSERT46]], <2 x float> poison, <2 x i32> zeroinitializer +; CHECK-NEXT: [[TMP46:%.*]] = fmul <2 x float> [[BLOCK45]], [[SPLAT_SPLAT47]] +; CHECK-NEXT: [[TMP47:%.*]] = fadd <2 x float> [[TMP44]], [[TMP46]] +; CHECK-NEXT: [[TMP48:%.*]] = shufflevector <2 x float> [[TMP47]], <2 x float> poison, <3 x i32> +; CHECK-NEXT: [[TMP49:%.*]] = shufflevector <3 x float> undef, <3 x float> [[TMP48]], <3 x i32> +; CHECK-NEXT: [[BLOCK48:%.*]] = shufflevector <3 x float> [[SPLIT]], <3 x float> poison, <1 x i32> +; CHECK-NEXT: [[TMP50:%.*]] = extractelement <3 x float> [[SPLIT5]], i64 0 +; CHECK-NEXT: [[SPLAT_SPLATINSERT49:%.*]] = insertelement <1 x float> poison, float [[TMP50]], i32 0 +; CHECK-NEXT: [[SPLAT_SPLAT50:%.*]] = shufflevector <1 x float> [[SPLAT_SPLATINSERT49]], <1 x float> poison, <1 x i32> zeroinitializer +; CHECK-NEXT: [[TMP51:%.*]] = fmul <1 x float> [[BLOCK48]], [[SPLAT_SPLAT50]] +; CHECK-NEXT: [[BLOCK51:%.*]] = shufflevector <3 x float> [[SPLIT1]], <3 x float> poison, <1 x i32> +; CHECK-NEXT: [[TMP52:%.*]] = extractelement <3 x float> [[SPLIT5]], i64 1 +; CHECK-NEXT: [[SPLAT_SPLATINSERT52:%.*]] = insertelement <1 x float> poison, float [[TMP52]], i32 0 +; CHECK-NEXT: [[SPLAT_SPLAT53:%.*]] = shufflevector <1 x float> [[SPLAT_SPLATINSERT52]], <1 x float> poison, <1 x i32> zeroinitializer +; CHECK-NEXT: [[TMP53:%.*]] = fmul <1 x float> [[BLOCK51]], [[SPLAT_SPLAT53]] +; CHECK-NEXT: [[TMP54:%.*]] = fadd <1 x float> [[TMP51]], [[TMP53]] +; CHECK-NEXT: [[BLOCK54:%.*]] = shufflevector <3 x float> [[SPLIT2]], <3 x float> poison, <1 x i32> +; CHECK-NEXT: [[TMP55:%.*]] = extractelement <3 x float> [[SPLIT5]], i64 2 +; CHECK-NEXT: [[SPLAT_SPLATINSERT55:%.*]] = insertelement <1 x float> poison, float [[TMP55]], i32 0 +; CHECK-NEXT: [[SPLAT_SPLAT56:%.*]] = shufflevector <1 x float> [[SPLAT_SPLATINSERT55]], <1 x float> poison, <1 x i32> zeroinitializer +; CHECK-NEXT: [[TMP56:%.*]] = fmul <1 x float> [[BLOCK54]], [[SPLAT_SPLAT56]] +; CHECK-NEXT: [[TMP57:%.*]] = fadd <1 x float> [[TMP54]], [[TMP56]] +; CHECK-NEXT: [[TMP58:%.*]] = shufflevector <1 x float> [[TMP57]], <1 x float> poison, <3 x i32> +; CHECK-NEXT: [[TMP59:%.*]] = shufflevector <3 x float> [[TMP49]], <3 x float> [[TMP58]], <3 x i32> +; CHECK-NEXT: [[TMP60:%.*]] = extractelement <3 x float> [[TMP19]], i64 0 +; CHECK-NEXT: [[TMP61:%.*]] = insertelement <3 x float> undef, float [[TMP60]], i64 0 +; CHECK-NEXT: [[TMP62:%.*]] = extractelement <3 x float> [[TMP39]], i64 0 +; CHECK-NEXT: [[TMP63:%.*]] = insertelement <3 x float> [[TMP61]], float [[TMP62]], i64 1 +; CHECK-NEXT: [[TMP64:%.*]] = extractelement <3 x float> [[TMP59]], i64 0 +; CHECK-NEXT: [[TMP65:%.*]] = insertelement <3 x float> [[TMP63]], float [[TMP64]], i64 2 +; CHECK-NEXT: [[TMP66:%.*]] = extractelement <3 x float> [[TMP19]], i64 1 +; CHECK-NEXT: [[TMP67:%.*]] = insertelement <3 x float> undef, float [[TMP66]], i64 0 +; CHECK-NEXT: [[TMP68:%.*]] = extractelement <3 x float> [[TMP39]], i64 1 +; CHECK-NEXT: [[TMP69:%.*]] = insertelement <3 x float> [[TMP67]], float [[TMP68]], i64 1 +; CHECK-NEXT: [[TMP70:%.*]] = extractelement <3 x float> [[TMP59]], i64 1 +; CHECK-NEXT: [[TMP71:%.*]] = insertelement <3 x float> [[TMP69]], float [[TMP70]], i64 2 +; CHECK-NEXT: [[TMP72:%.*]] = extractelement <3 x float> [[TMP19]], i64 2 +; CHECK-NEXT: [[TMP73:%.*]] = insertelement <3 x float> undef, float [[TMP72]], i64 0 +; CHECK-NEXT: [[TMP74:%.*]] = extractelement <3 x float> [[TMP39]], i64 2 +; CHECK-NEXT: [[TMP75:%.*]] = insertelement <3 x float> [[TMP73]], float [[TMP74]], i64 1 +; CHECK-NEXT: [[TMP76:%.*]] = extractelement <3 x float> [[TMP59]], i64 2 +; CHECK-NEXT: [[TMP77:%.*]] = insertelement <3 x float> [[TMP75]], float [[TMP76]], i64 2 +; CHECK-NEXT: [[TMP78:%.*]] = shufflevector <3 x float> [[TMP65]], <3 x float> [[TMP71]], <6 x i32> +; CHECK-NEXT: [[TMP79:%.*]] = shufflevector <3 x float> [[TMP77]], <3 x float> poison, <6 x i32> +; CHECK-NEXT: [[TMP80:%.*]] = shufflevector <6 x float> [[TMP78]], <6 x float> [[TMP79]], <9 x i32> +; CHECK-NEXT: ret <9 x float> [[TMP80]] +; +entry: + %t = call <9 x float> @llvm.matrix.transpose.v9f32(<9 x float> %a, i32 3, i32 3) + %m = call <9 x float> @llvm.matrix.multiply.v9f32.v9f32.v9f32(<9 x float> %t, <9 x float> %t, i32 3, i32 3, i32 3) + ret <9 x float> %m +} + declare <9 x double> @llvm.matrix.multiply.v9f64.v9f64.v9f64(<9 x double>, <9 x double>, i32, i32, i32) declare <12 x double> @llvm.matrix.multiply.v12f64.v6f64.v8f64(<6 x double>, <8 x double>, i32, i32, i32) declare <8 x double> @llvm.matrix.multiply.v8f64.v6f64.v12f64(<6 x double> %a, <12 x double>, i32, i32, i32) +declare <9 x float> @llvm.matrix.multiply.v9f32.v9f32.v9f32(<9 x float>, <9 x float>, i32 immarg, i32 immarg, i32 immarg) #1 declare <9 x double> @llvm.matrix.transpose.v9f64.v9f64(<9 x double>, i32, i32) declare <6 x double> @llvm.matrix.transpose.v6f64.v6f64(<6 x double>, i32, i32) declare <8 x double> @llvm.matrix.transpose.v8f64.v8f64(<8 x double>, i32, i32) declare <12 x double> @llvm.matrix.transpose.v12f64.v12f64(<12 x double>, i32, i32) +declare <9 x float> @llvm.matrix.transpose.v9f32(<9 x float>, i32 immarg, i32 immarg) #1