Index: include/llvm/IR/IntrinsicsAArch64.td =================================================================== --- include/llvm/IR/IntrinsicsAArch64.td +++ include/llvm/IR/IntrinsicsAArch64.td @@ -149,6 +149,11 @@ class AdvSIMD_1Arg_Intrinsic : Intrinsic<[llvm_any_ty], [LLVMMatchType<0>], [IntrNoMem]>; + + class AdvSIMD_Dot_Intrinsic + : Intrinsic<[llvm_anyvector_ty], + [LLVMMatchType<0>, llvm_anyvector_ty, LLVMMatchType<1>], + [IntrNoMem]>; } // Arithmetic ops @@ -415,6 +420,10 @@ // Scalar FP Inexact Narrowing def int_aarch64_sisd_fcvtxn : Intrinsic<[llvm_float_ty], [llvm_double_ty], [IntrNoMem]>; + + // v8.2-A Dot Product + def int_aarch64_neon_udot : AdvSIMD_Dot_Intrinsic; + def int_aarch64_neon_sdot : AdvSIMD_Dot_Intrinsic; } let TargetPrefix = "aarch64" in { // All intrinsics start with "llvm.aarch64.". Index: lib/Target/AArch64/AArch64InstrFormats.td =================================================================== --- lib/Target/AArch64/AArch64InstrFormats.td +++ lib/Target/AArch64/AArch64InstrFormats.td @@ -4595,11 +4595,24 @@ } class BaseSIMDThreeSameVectorDot : - BaseSIMDThreeSameVector { + string kind2, RegisterOperand RegType, + ValueType AccumType, ValueType InputType, + SDPatternOperator OpNode> : + BaseSIMDThreeSameVectorTied { let AsmString = !strconcat(asm, "{\t$Rd" # kind1 # ", $Rn" # kind2 # ", $Rm" # kind2 # "}"); } +multiclass SIMDThreeSameVectorDot { + def v8i8 : BaseSIMDThreeSameVectorDot<0, U, asm, ".2s", ".8b", V64, + v2i32, v8i8, OpNode>; + def v16i8 : BaseSIMDThreeSameVectorDot<1, U, asm, ".4s", ".16b", V128, + v4i32, v16i8, OpNode>; +} + // All operand sizes distinguished in the encoding. multiclass SIMDThreeSameVector opc, string asm, SDPatternOperator OpNode> { @@ -7029,14 +7042,31 @@ // ARMv8.2 Index Dot product instructions class BaseSIMDThreeSameVectorDotIndex : - BaseSIMDIndexedTied { + string lhs_kind, string rhs_kind, + RegisterOperand RegType, + ValueType AccumType, ValueType InputType, + SDPatternOperator OpNode> : + BaseSIMDIndexedTied { bits<2> idx; let Inst{21} = idx{0}; // L let Inst{11} = idx{1}; // H } +multiclass SIMDThreeSameVectorDotIndex { + def v8i8 : BaseSIMDThreeSameVectorDotIndex<0, U, asm, ".2s", ".8b", ".4b", V64, + v2i32, v8i8, OpNode>; + def v16i8 : BaseSIMDThreeSameVectorDotIndex<1, U, asm, ".4s", ".16b", ".4b", V128, + v4i32, v16i8, OpNode>; +} + multiclass SIMDFPIndexed opc, string asm, SDPatternOperator OpNode> { let Predicates = [HasNEON, HasFullFP16] in { Index: lib/Target/AArch64/AArch64InstrInfo.td =================================================================== --- lib/Target/AArch64/AArch64InstrInfo.td +++ lib/Target/AArch64/AArch64InstrInfo.td @@ -453,14 +453,10 @@ // ARMv8.2 Dot Product let Predicates = [HasDotProd] in { -def UDOT2S : BaseSIMDThreeSameVectorDot<0, 1, "udot", ".2s", ".8b">; -def SDOT2S : BaseSIMDThreeSameVectorDot<0, 0, "sdot", ".2s", ".8b">; -def UDOT4S : BaseSIMDThreeSameVectorDot<1, 1, "udot", ".4s", ".16b">; -def SDOT4S : BaseSIMDThreeSameVectorDot<1, 0, "sdot", ".4s", ".16b">; -def UDOTIDX2S : BaseSIMDThreeSameVectorDotIndex<0, 1, "udot", ".2s", ".8b", ".4b">; -def SDOTIDX2S : BaseSIMDThreeSameVectorDotIndex<0, 0, "sdot", ".2s", ".8b", ".4b">; -def UDOTIDX4S : BaseSIMDThreeSameVectorDotIndex<1, 1, "udot", ".4s", ".16b", ".4b">; -def SDOTIDX4S : BaseSIMDThreeSameVectorDotIndex<1, 0, "sdot", ".4s", ".16b", ".4b">; +defm SDOT : SIMDThreeSameVectorDot<0, "sdot", int_aarch64_neon_sdot>; +defm UDOT : SIMDThreeSameVectorDot<1, "udot", int_aarch64_neon_udot>; +defm SDOTlane : SIMDThreeSameVectorDotIndex<0, "sdot", int_aarch64_neon_sdot>; +defm UDOTlane : SIMDThreeSameVectorDotIndex<1, "udot", int_aarch64_neon_udot>; } let Predicates = [HasRCPC] in { Index: test/CodeGen/AArch64/neon-dot-product.ll =================================================================== --- /dev/null +++ test/CodeGen/AArch64/neon-dot-product.ll @@ -0,0 +1,129 @@ +; RUN: llc -mattr=+dotprod < %s | FileCheck %s + +target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" +target triple = "arm64-none-linux-gnu" + +declare <2 x i32> @llvm.aarch64.neon.udot.v2i32.v8i8(<2 x i32>, <8 x i8>, <8 x i8>) +declare <4 x i32> @llvm.aarch64.neon.udot.v4i32.v16i8(<4 x i32>, <16 x i8>, <16 x i8>) +declare <2 x i32> @llvm.aarch64.neon.sdot.v2i32.v8i8(<2 x i32>, <8 x i8>, <8 x i8>) +declare <4 x i32> @llvm.aarch64.neon.sdot.v4i32.v16i8(<4 x i32>, <16 x i8>, <16 x i8>) + +define <2 x i32> @test_vdot_u32(<2 x i32> %a, <8 x i8> %b, <8 x i8> %c) #0 { +entry: +; CHECK-LABEL: test_vdot_u32: +; CHECK: udot v0.2s, v1.8b, v2.8b + %vdot1.i = call <2 x i32> @llvm.aarch64.neon.udot.v2i32.v8i8(<2 x i32> %a, <8 x i8> %b, <8 x i8> %c) #2 + ret <2 x i32> %vdot1.i +} + +define <4 x i32> @test_vdotq_u32(<4 x i32> %a, <16 x i8> %b, <16 x i8> %c) #0 { +entry: +; CHECK-LABEL: test_vdotq_u32: +; CHECK: udot v0.4s, v1.16b, v2.16b + %vdot1.i = call <4 x i32> @llvm.aarch64.neon.udot.v4i32.v16i8(<4 x i32> %a, <16 x i8> %b, <16 x i8> %c) #2 + ret <4 x i32> %vdot1.i +} + +define <2 x i32> @test_vdot_s32(<2 x i32> %a, <8 x i8> %b, <8 x i8> %c) #0 { +entry: +; CHECK-LABEL: test_vdot_s32: +; CHECK: sdot v0.2s, v1.8b, v2.8b + %vdot1.i = call <2 x i32> @llvm.aarch64.neon.sdot.v2i32.v8i8(<2 x i32> %a, <8 x i8> %b, <8 x i8> %c) #2 + ret <2 x i32> %vdot1.i +} + +define <4 x i32> @test_vdotq_s32(<4 x i32> %a, <16 x i8> %b, <16 x i8> %c) #0 { +entry: +; CHECK-LABEL: test_vdotq_s32: +; CHECK: sdot v0.4s, v1.16b, v2.16b + %vdot1.i = call <4 x i32> @llvm.aarch64.neon.sdot.v4i32.v16i8(<4 x i32> %a, <16 x i8> %b, <16 x i8> %c) #2 + ret <4 x i32> %vdot1.i +} + +define <2 x i32> @test_vdot_lane_u32(<2 x i32> %a, <8 x i8> %b, <8 x i8> %c) { +entry: +; CHECK-LABEL: test_vdot_lane_u32: +; CHECK: udot v0.2s, v1.8b, v2.4b[1] + %.cast = bitcast <8 x i8> %c to <2 x i32> + %shuffle = shufflevector <2 x i32> %.cast, <2 x i32> undef, <2 x i32> + %.cast5 = bitcast <2 x i32> %shuffle to <8 x i8> + %vdot1.i = call <2 x i32> @llvm.aarch64.neon.udot.v2i32.v8i8(<2 x i32> %a, <8 x i8> %b, <8 x i8> %.cast5) #2 + ret <2 x i32> %vdot1.i +} + +define <4 x i32> @test_vdotq_lane_u32(<4 x i32> %a, <16 x i8> %b, <8 x i8> %c) { +entry: +; CHECK-LABEL: test_vdotq_lane_u32: +; CHECK: udot v0.4s, v1.16b, v2.4b[1] + %.cast = bitcast <8 x i8> %c to <2 x i32> + %shuffle = shufflevector <2 x i32> %.cast, <2 x i32> undef, <4 x i32> + %.cast3 = bitcast <4 x i32> %shuffle to <16 x i8> + %vdot1.i = call <4 x i32> @llvm.aarch64.neon.udot.v4i32.v16i8(<4 x i32> %a, <16 x i8> %b, <16 x i8> %.cast3) #2 + ret <4 x i32> %vdot1.i +} + +define <2 x i32> @test_vdot_laneq_u32(<2 x i32> %a, <8 x i8> %b, <16 x i8> %c) { +entry: +; CHECK-LABEL: test_vdot_laneq_u32: +; CHECK: udot v0.2s, v1.8b, v2.4b[1] + %.cast = bitcast <16 x i8> %c to <4 x i32> + %shuffle = shufflevector <4 x i32> %.cast, <4 x i32> undef, <2 x i32> + %.cast5 = bitcast <2 x i32> %shuffle to <8 x i8> + %vdot1.i = call <2 x i32> @llvm.aarch64.neon.udot.v2i32.v8i8(<2 x i32> %a, <8 x i8> %b, <8 x i8> %.cast5) #2 + ret <2 x i32> %vdot1.i +} + +define <4 x i32> @test_vdotq_laneq_u32(<4 x i32> %a, <16 x i8> %b, <16 x i8> %c) { +entry: +; CHECK-LABEL: test_vdotq_laneq_u32: +; CHECK: udot v0.4s, v1.16b, v2.4b[1] + %.cast = bitcast <16 x i8> %c to <4 x i32> + %shuffle = shufflevector <4 x i32> %.cast, <4 x i32> undef, <4 x i32> + %.cast3 = bitcast <4 x i32> %shuffle to <16 x i8> + %vdot1.i = call <4 x i32> @llvm.aarch64.neon.udot.v4i32.v16i8(<4 x i32> %a, <16 x i8> %b, <16 x i8> %.cast3) #2 + ret <4 x i32> %vdot1.i +} + +define <2 x i32> @test_vdot_lane_s32(<2 x i32> %a, <8 x i8> %b, <8 x i8> %c) { +entry: +; CHECK-LABEL: test_vdot_lane_s32: +; CHECK: sdot v0.2s, v1.8b, v2.4b[1] + %.cast = bitcast <8 x i8> %c to <2 x i32> + %shuffle = shufflevector <2 x i32> %.cast, <2 x i32> undef, <2 x i32> + %.cast5 = bitcast <2 x i32> %shuffle to <8 x i8> + %vdot1.i = call <2 x i32> @llvm.aarch64.neon.sdot.v2i32.v8i8(<2 x i32> %a, <8 x i8> %b, <8 x i8> %.cast5) #2 + ret <2 x i32> %vdot1.i +} + +define <4 x i32> @test_vdotq_lane_s32(<4 x i32> %a, <16 x i8> %b, <8 x i8> %c) { +entry: +; CHECK-LABEL: test_vdotq_lane_s32: +; CHECK: sdot v0.4s, v1.16b, v2.4b[1] + %.cast = bitcast <8 x i8> %c to <2 x i32> + %shuffle = shufflevector <2 x i32> %.cast, <2 x i32> undef, <4 x i32> + %.cast3 = bitcast <4 x i32> %shuffle to <16 x i8> + %vdot1.i = call <4 x i32> @llvm.aarch64.neon.sdot.v4i32.v16i8(<4 x i32> %a, <16 x i8> %b, <16 x i8> %.cast3) #2 + ret <4 x i32> %vdot1.i +} + +define <2 x i32> @test_vdot_laneq_s32(<2 x i32> %a, <8 x i8> %b, <16 x i8> %c) { +entry: +; CHECK-LABEL: test_vdot_laneq_s32: +; CHECK: sdot v0.2s, v1.8b, v2.4b[1] + %.cast = bitcast <16 x i8> %c to <4 x i32> + %shuffle = shufflevector <4 x i32> %.cast, <4 x i32> undef, <2 x i32> + %.cast5 = bitcast <2 x i32> %shuffle to <8 x i8> + %vdot1.i = call <2 x i32> @llvm.aarch64.neon.sdot.v2i32.v8i8(<2 x i32> %a, <8 x i8> %b, <8 x i8> %.cast5) #2 + ret <2 x i32> %vdot1.i +} + +define <4 x i32> @test_vdotq_laneq_s32(<4 x i32> %a, <16 x i8> %b, <16 x i8> %c) { +entry: +; CHECK-LABEL: test_vdotq_laneq_s32: +; CHECK: sdot v0.4s, v1.16b, v2.4b[1] + %.cast = bitcast <16 x i8> %c to <4 x i32> + %shuffle = shufflevector <4 x i32> %.cast, <4 x i32> undef, <4 x i32> + %.cast3 = bitcast <4 x i32> %shuffle to <16 x i8> + %vdot1.i = call <4 x i32> @llvm.aarch64.neon.sdot.v4i32.v16i8(<4 x i32> %a, <16 x i8> %b, <16 x i8> %.cast3) #2 + ret <4 x i32> %vdot1.i +}