diff --git a/llvm/include/llvm/IR/IntrinsicsAArch64.td b/llvm/include/llvm/IR/IntrinsicsAArch64.td --- a/llvm/include/llvm/IR/IntrinsicsAArch64.td +++ b/llvm/include/llvm/IR/IntrinsicsAArch64.td @@ -998,6 +998,17 @@ [LLVMSubdivide2VectorType<0>, llvm_anyvector_ty], [IntrNoMem]>; + class SVE2_2VectorArg_Narrowing_Intrinsic + : Intrinsic< + [LLVMSubdivide2VectorType<0>], + [llvm_anyvector_ty, LLVMMatchType<0>], + [IntrNoMem]>; + + class SVE2_Merged2VectorArg_Narrowing_Intrinsic + : Intrinsic< + [LLVMSubdivide2VectorType<0>], + [LLVMSubdivide2VectorType<0>, llvm_anyvector_ty, LLVMMatchType<0>], + [IntrNoMem]>; // NOTE: There is no relationship between these intrinsics beyond an attempt // to reuse currently identical class definitions. @@ -1504,4 +1515,19 @@ def int_aarch64_sve_sqxtunt : SVE2_Merged1VectorArg_Narrowing_Intrinsic; def int_aarch64_sve_uqxtnb : SVE2_1VectorArg_Narrowing_Intrinsic; def int_aarch64_sve_uqxtnt : SVE2_Merged1VectorArg_Narrowing_Intrinsic; + +// +// SVE2 - Binary narrowing DSP operations +// +def int_aarch64_sve_addhnb : SVE2_2VectorArg_Narrowing_Intrinsic; +def int_aarch64_sve_addhnt : SVE2_Merged2VectorArg_Narrowing_Intrinsic; + +def int_aarch64_sve_raddhnb : SVE2_2VectorArg_Narrowing_Intrinsic; +def int_aarch64_sve_raddhnt : SVE2_Merged2VectorArg_Narrowing_Intrinsic; + +def int_aarch64_sve_subhnb : SVE2_2VectorArg_Narrowing_Intrinsic; +def int_aarch64_sve_subhnt : SVE2_Merged2VectorArg_Narrowing_Intrinsic; + +def int_aarch64_sve_rsubhnb : SVE2_2VectorArg_Narrowing_Intrinsic; +def int_aarch64_sve_rsubhnt : SVE2_Merged2VectorArg_Narrowing_Intrinsic; } diff --git a/llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td b/llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td --- a/llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td +++ b/llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td @@ -1446,16 +1446,16 @@ defm UQRSHRNT_ZZI : sve2_int_bin_shift_imm_right_narrow_top<0b111, "uqrshrnt">; // SVE2 integer add/subtract narrow high part (bottom) - defm ADDHNB_ZZZ : sve2_int_addsub_narrow_high_bottom<0b00, "addhnb">; - defm RADDHNB_ZZZ : sve2_int_addsub_narrow_high_bottom<0b01, "raddhnb">; - defm SUBHNB_ZZZ : sve2_int_addsub_narrow_high_bottom<0b10, "subhnb">; - defm RSUBHNB_ZZZ : sve2_int_addsub_narrow_high_bottom<0b11, "rsubhnb">; + defm ADDHNB_ZZZ : sve2_int_addsub_narrow_high_bottom<0b00, "addhnb", int_aarch64_sve_addhnb>; + defm RADDHNB_ZZZ : sve2_int_addsub_narrow_high_bottom<0b01, "raddhnb", int_aarch64_sve_raddhnb>; + defm SUBHNB_ZZZ : sve2_int_addsub_narrow_high_bottom<0b10, "subhnb", int_aarch64_sve_subhnb>; + defm RSUBHNB_ZZZ : sve2_int_addsub_narrow_high_bottom<0b11, "rsubhnb", int_aarch64_sve_rsubhnb>; // SVE2 integer add/subtract narrow high part (top) - defm ADDHNT_ZZZ : sve2_int_addsub_narrow_high_top<0b00, "addhnt">; - defm RADDHNT_ZZZ : sve2_int_addsub_narrow_high_top<0b01, "raddhnt">; - defm SUBHNT_ZZZ : sve2_int_addsub_narrow_high_top<0b10, "subhnt">; - defm RSUBHNT_ZZZ : sve2_int_addsub_narrow_high_top<0b11, "rsubhnt">; + defm ADDHNT_ZZZ : sve2_int_addsub_narrow_high_top<0b00, "addhnt", int_aarch64_sve_addhnt>; + defm RADDHNT_ZZZ : sve2_int_addsub_narrow_high_top<0b01, "raddhnt", int_aarch64_sve_raddhnt>; + defm SUBHNT_ZZZ : sve2_int_addsub_narrow_high_top<0b10, "subhnt", int_aarch64_sve_subhnt>; + defm RSUBHNT_ZZZ : sve2_int_addsub_narrow_high_top<0b11, "rsubhnt", int_aarch64_sve_rsubhnt>; // SVE2 saturating extract narrow (bottom) defm SQXTNB_ZZ : sve2_int_sat_extract_narrow_bottom<0b00, "sqxtnb", int_aarch64_sve_sqxtnb>; diff --git a/llvm/lib/Target/AArch64/SVEInstrFormats.td b/llvm/lib/Target/AArch64/SVEInstrFormats.td --- a/llvm/lib/Target/AArch64/SVEInstrFormats.td +++ b/llvm/lib/Target/AArch64/SVEInstrFormats.td @@ -3005,10 +3005,15 @@ let Inst{4-0} = Zd; } -multiclass sve2_int_addsub_narrow_high_bottom opc, string asm> { +multiclass sve2_int_addsub_narrow_high_bottom opc, string asm, + SDPatternOperator op> { def _B : sve2_int_addsub_narrow_high_bottom<0b01, opc, asm, ZPR8, ZPR16>; def _H : sve2_int_addsub_narrow_high_bottom<0b10, opc, asm, ZPR16, ZPR32>; def _S : sve2_int_addsub_narrow_high_bottom<0b11, opc, asm, ZPR32, ZPR64>; + + def : SVE_2_Op_Pat(NAME # _B)>; + def : SVE_2_Op_Pat(NAME # _H)>; + def : SVE_2_Op_Pat(NAME # _S)>; } class sve2_int_addsub_narrow_high_top sz, bits<2> opc, string asm, @@ -3031,10 +3036,15 @@ let Constraints = "$Zd = $_Zd"; } -multiclass sve2_int_addsub_narrow_high_top opc, string asm> { +multiclass sve2_int_addsub_narrow_high_top opc, string asm, + SDPatternOperator op> { def _B : sve2_int_addsub_narrow_high_top<0b01, opc, asm, ZPR8, ZPR16>; def _H : sve2_int_addsub_narrow_high_top<0b10, opc, asm, ZPR16, ZPR32>; def _S : sve2_int_addsub_narrow_high_top<0b11, opc, asm, ZPR32, ZPR64>; + + def : SVE_3_Op_Pat(NAME # _B)>; + def : SVE_3_Op_Pat(NAME # _H)>; + def : SVE_3_Op_Pat(NAME # _S)>; } class sve2_int_sat_extract_narrow_bottom tsz8_64, bits<2> opc, string asm, diff --git a/llvm/test/CodeGen/AArch64/sve2-intrinsics-binary-narrowing-add-sub.ll b/llvm/test/CodeGen/AArch64/sve2-intrinsics-binary-narrowing-add-sub.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/AArch64/sve2-intrinsics-binary-narrowing-add-sub.ll @@ -0,0 +1,278 @@ +; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve2 < %s | FileCheck %s + +; ADDHNB + +define @addhnb_h( %a, %b) { +; CHECK-LABEL: addhnb_h: +; CHECK: addhnb z0.b, z0.h, z1.h +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.addhnb.nxv8i16( %a, + %b) + ret %out +} + +define @addhnb_s( %a, %b) { +; CHECK-LABEL: addhnb_s: +; CHECK: addhnb z0.h, z0.s, z1.s +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.addhnb.nxv4i32( %a, + %b) + ret %out +} + +define @addhnb_d( %a, %b) { +; CHECK-LABEL: addhnb_d: +; CHECK: addhnb z0.s, z0.d, z1.d +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.addhnb.nxv2i64( %a, + %b) + ret %out +} + +; ADDHNT + +define @addhnt_h( %a, %b, %c) { +; CHECK-LABEL: addhnt_h: +; CHECK: addhnt z0.b, z1.h, z2.h +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.addhnt.nxv8i16( %a, + %b, + %c) + ret %out +} + +define @addhnt_s( %a, %b, %c) { +; CHECK-LABEL: addhnt_s: +; CHECK: addhnt z0.h, z1.s, z2.s +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.addhnt.nxv4i32( %a, + %b, + %c) + ret %out +} + +define @addhnt_d( %a, %b, %c) { +; CHECK-LABEL: addhnt_d: +; CHECK: addhnt z0.s, z1.d, z2.d +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.addhnt.nxv2i64( %a, + %b, + %c) + ret %out +} + +; RADDHNB + +define @raddhnb_h( %a, %b) { +; CHECK-LABEL: raddhnb_h: +; CHECK: raddhnb z0.b, z0.h, z1.h +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.raddhnb.nxv8i16( %a, + %b) + ret %out +} + +define @raddhnb_s( %a, %b) { +; CHECK-LABEL: raddhnb_s: +; CHECK: raddhnb z0.h, z0.s, z1.s +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.raddhnb.nxv4i32( %a, + %b) + ret %out +} + +define @raddhnb_d( %a, %b) { +; CHECK-LABEL: raddhnb_d: +; CHECK: raddhnb z0.s, z0.d, z1.d +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.raddhnb.nxv2i64( %a, + %b) + ret %out +} + +; RADDHNT + +define @raddhnt_h( %a, %b, %c) { +; CHECK-LABEL: raddhnt_h: +; CHECK: raddhnt z0.b, z1.h, z2.h +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.raddhnt.nxv8i16( %a, + %b, + %c) + ret %out +} + +define @raddhnt_s( %a, %b, %c) { +; CHECK-LABEL: raddhnt_s: +; CHECK: raddhnt z0.h, z1.s, z2.s +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.raddhnt.nxv4i32( %a, + %b, + %c) + ret %out +} + +define @raddhnt_d( %a, %b, %c) { +; CHECK-LABEL: raddhnt_d: +; CHECK: raddhnt z0.s, z1.d, z2.d +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.raddhnt.nxv2i64( %a, + %b, + %c) + ret %out +} + +; RSUBHNB + +define @rsubhnb_h( %a, %b) { +; CHECK-LABEL: rsubhnb_h: +; CHECK: rsubhnb z0.b, z0.h, z1.h +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.rsubhnb.nxv8i16( %a, + %b) + ret %out +} + +define @rsubhnb_s( %a, %b) { +; CHECK-LABEL: rsubhnb_s: +; CHECK: rsubhnb z0.h, z0.s, z1.s +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.rsubhnb.nxv4i32( %a, + %b) + ret %out +} + +define @rsubhnb_d( %a, %b) { +; CHECK-LABEL: rsubhnb_d: +; CHECK: rsubhnb z0.s, z0.d, z1.d +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.rsubhnb.nxv2i64( %a, + %b) + ret %out +} + +; RSUBHNT + +define @rsubhnt_h( %a, %b, %c) { +; CHECK-LABEL: rsubhnt_h: +; CHECK: rsubhnt z0.b, z1.h, z2.h +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.rsubhnt.nxv8i16( %a, + %b, + %c) + ret %out +} + +define @rsubhnt_s( %a, %b, %c) { +; CHECK-LABEL: rsubhnt_s: +; CHECK: rsubhnt z0.h, z1.s, z2.s +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.rsubhnt.nxv4i32( %a, + %b, + %c) + ret %out +} + +define @rsubhnt_d( %a, %b, %c) { +; CHECK-LABEL: rsubhnt_d: +; CHECK: rsubhnt z0.s, z1.d, z2.d +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.rsubhnt.nxv2i64( %a, + %b, + %c) + ret %out +} + +; SUBHNB + +define @subhnb_h( %a, %b) { +; CHECK-LABEL: subhnb_h: +; CHECK: subhnb z0.b, z0.h, z1.h +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.subhnb.nxv8i16( %a, + %b) + ret %out +} + +define @subhnb_s( %a, %b) { +; CHECK-LABEL: subhnb_s: +; CHECK: subhnb z0.h, z0.s, z1.s +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.subhnb.nxv4i32( %a, + %b) + ret %out +} + +define @subhnb_d( %a, %b) { +; CHECK-LABEL: subhnb_d: +; CHECK: subhnb z0.s, z0.d, z1.d +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.subhnb.nxv2i64( %a, + %b) + ret %out +} + +; SUBHNT + +define @subhnt_h( %a, %b, %c) { +; CHECK-LABEL: subhnt_h: +; CHECK: subhnt z0.b, z1.h, z2.h +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.subhnt.nxv8i16( %a, + %b, + %c) + ret %out +} + +define @subhnt_s( %a, %b, %c) { +; CHECK-LABEL: subhnt_s: +; CHECK: subhnt z0.h, z1.s, z2.s +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.subhnt.nxv4i32( %a, + %b, + %c) + ret %out +} + +define @subhnt_d( %a, %b, %c) { +; CHECK-LABEL: subhnt_d: +; CHECK: subhnt z0.s, z1.d, z2.d +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.subhnt.nxv2i64( %a, + %b, + %c) + ret %out +} + + +declare @llvm.aarch64.sve.addhnb.nxv8i16(, ) +declare @llvm.aarch64.sve.addhnb.nxv4i32(, ) +declare @llvm.aarch64.sve.addhnb.nxv2i64(, ) + +declare @llvm.aarch64.sve.addhnt.nxv8i16(, , ) +declare @llvm.aarch64.sve.addhnt.nxv4i32(, , ) +declare @llvm.aarch64.sve.addhnt.nxv2i64(, , ) + +declare @llvm.aarch64.sve.raddhnb.nxv8i16(, ) +declare @llvm.aarch64.sve.raddhnb.nxv4i32(, ) +declare @llvm.aarch64.sve.raddhnb.nxv2i64(, ) + +declare @llvm.aarch64.sve.raddhnt.nxv8i16(, , ) +declare @llvm.aarch64.sve.raddhnt.nxv4i32(, , ) +declare @llvm.aarch64.sve.raddhnt.nxv2i64(, , ) + +declare @llvm.aarch64.sve.subhnb.nxv8i16(, ) +declare @llvm.aarch64.sve.subhnb.nxv4i32(, ) +declare @llvm.aarch64.sve.subhnb.nxv2i64(, ) + +declare @llvm.aarch64.sve.subhnt.nxv8i16(, , ) +declare @llvm.aarch64.sve.subhnt.nxv4i32(, , ) +declare @llvm.aarch64.sve.subhnt.nxv2i64(, , ) + +declare @llvm.aarch64.sve.rsubhnb.nxv8i16(, ) +declare @llvm.aarch64.sve.rsubhnb.nxv4i32(, ) +declare @llvm.aarch64.sve.rsubhnb.nxv2i64(, ) + +declare @llvm.aarch64.sve.rsubhnt.nxv8i16(, , ) +declare @llvm.aarch64.sve.rsubhnt.nxv4i32(, , ) +declare @llvm.aarch64.sve.rsubhnt.nxv2i64(, , )