From 9fd29cce52f589aafbe5935710e3f02e4c91aa43 Mon Sep 17 00:00:00 2001 From: Oliver Stannard Date: Fri, 27 Apr 2018 13:45:32 +0000 Subject: [PATCH] [AArch64] Codegen for v8.2A dot product intrinsics This adds IR intrinsics for the AArch64 dot-product instructions introduced in v8.2-A. Differential revisioon: https://reviews.llvm.org/D46107 llvm-svn: 331036 --- include/llvm/IR/IntrinsicsAArch64.td | 9 ++ lib/Target/AArch64/AArch64InstrFormats.td | 40 ++++++- lib/Target/AArch64/AArch64InstrInfo.td | 12 +-- test/CodeGen/AArch64/neon-dot-product.ll | 126 ++++++++++++++++++++++ 4 files changed, 174 insertions(+), 13 deletions(-) create mode 100644 test/CodeGen/AArch64/neon-dot-product.ll diff --git a/include/llvm/IR/IntrinsicsAArch64.td b/include/llvm/IR/IntrinsicsAArch64.td index 50341338c39..994671419cd 100644 --- a/include/llvm/IR/IntrinsicsAArch64.td +++ b/include/llvm/IR/IntrinsicsAArch64.td @@ -149,6 +149,11 @@ let TargetPrefix = "aarch64" in { // All intrinsics start with "llvm.aarch64.". 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 @@ let TargetPrefix = "aarch64", IntrProperties = [IntrNoMem] in { // 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.". diff --git a/lib/Target/AArch64/AArch64InstrFormats.td b/lib/Target/AArch64/AArch64InstrFormats.td index a1b34379b5b..f1fd6c958e9 100644 --- a/lib/Target/AArch64/AArch64InstrFormats.td +++ b/lib/Target/AArch64/AArch64InstrFormats.td @@ -4595,11 +4595,24 @@ class BaseSIMDThreeSameVectorTied size, bits<5> opcode, } 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 @@ class BaseSIMDIndexedTied size, bits<4> opc, // 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 { diff --git a/lib/Target/AArch64/AArch64InstrInfo.td b/lib/Target/AArch64/AArch64InstrInfo.td index 8eba86aa1b9..d7b9a804247 100644 --- a/lib/Target/AArch64/AArch64InstrInfo.td +++ b/lib/Target/AArch64/AArch64InstrInfo.td @@ -453,14 +453,10 @@ def ISB : CRmSystemI; -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 { diff --git a/test/CodeGen/AArch64/neon-dot-product.ll b/test/CodeGen/AArch64/neon-dot-product.ll new file mode 100644 index 00000000000..5ad75a7d24c --- /dev/null +++ b/test/CodeGen/AArch64/neon-dot-product.ll @@ -0,0 +1,126 @@ +; RUN: llc -mtriple aarch64-none-linux-gnu -mattr=+dotprod < %s | FileCheck %s + +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 +}