From b085e51d818a39c7e2ea659ebbefd1943689c642 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Thu, 14 May 2020 16:07:59 -0500 Subject: [PATCH] [AArch64][SVE] Add some integer DestructiveBinaryComm* patterns Add DestructiveBinaryComm* patterns for ADD, SUB, and SUBR. Differential Revision: https://reviews.llvm.org/D76711 --- .../lib/Target/AArch64/AArch64SVEInstrInfo.td | 10 +- llvm/lib/Target/AArch64/SVEInstrFormats.td | 19 +- .../sve-intrinsics-int-arith-merging.ll | 172 ++++++++++++++++++ 3 files changed, 193 insertions(+), 8 deletions(-) create mode 100644 llvm/test/CodeGen/AArch64/sve-intrinsics-int-arith-merging.ll diff --git a/llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td b/llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td index 363d451b2c07..8c0c95bd124a 100644 --- a/llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td +++ b/llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td @@ -199,9 +199,13 @@ let Predicates = [HasSVE] in { defm EOR_ZZZ : sve_int_bin_cons_log<0b10, "eor", xor>; defm BIC_ZZZ : sve_int_bin_cons_log<0b11, "bic", null_frag>; - defm ADD_ZPmZ : sve_int_bin_pred_arit_0<0b000, "add", int_aarch64_sve_add>; - defm SUB_ZPmZ : sve_int_bin_pred_arit_0<0b001, "sub", int_aarch64_sve_sub>; - defm SUBR_ZPmZ : sve_int_bin_pred_arit_0<0b011, "subr", int_aarch64_sve_subr>; + defm ADD_ZPmZ : sve_int_bin_pred_arit_0<0b000, "add", "ADD_ZPZZ", int_aarch64_sve_add, DestructiveBinaryComm>; + defm SUB_ZPmZ : sve_int_bin_pred_arit_0<0b001, "sub", "SUB_ZPZZ", int_aarch64_sve_sub, DestructiveBinaryCommWithRev, "SUBR_ZPmZ", 1>; + defm SUBR_ZPmZ : sve_int_bin_pred_arit_0<0b011, "subr", "SUBR_ZPZZ", int_aarch64_sve_subr, DestructiveBinaryCommWithRev, "SUB_ZPmZ", 0>; + + defm ADD_ZPZZ : sve_int_bin_pred_zx; + defm SUB_ZPZZ : sve_int_bin_pred_zx; + defm SUBR_ZPZZ : sve_int_bin_pred_zx; defm ORR_ZPmZ : sve_int_bin_pred_log<0b000, "orr", int_aarch64_sve_orr>; defm EOR_ZPmZ : sve_int_bin_pred_log<0b001, "eor", int_aarch64_sve_eor>; diff --git a/llvm/lib/Target/AArch64/SVEInstrFormats.td b/llvm/lib/Target/AArch64/SVEInstrFormats.td index 5624e78b65ac..48b3d8a3199a 100644 --- a/llvm/lib/Target/AArch64/SVEInstrFormats.td +++ b/llvm/lib/Target/AArch64/SVEInstrFormats.td @@ -2341,11 +2341,20 @@ multiclass sve_int_bin_pred_log opc, string asm, SDPatternOperator op> { def : SVE_3_Op_Pat(NAME # _D)>; } -multiclass sve_int_bin_pred_arit_0 opc, string asm, SDPatternOperator op> { - def _B : sve_int_bin_pred_arit_log<0b00, 0b00, opc, asm, ZPR8>; - def _H : sve_int_bin_pred_arit_log<0b01, 0b00, opc, asm, ZPR16>; - def _S : sve_int_bin_pred_arit_log<0b10, 0b00, opc, asm, ZPR32>; - def _D : sve_int_bin_pred_arit_log<0b11, 0b00, opc, asm, ZPR64>; +multiclass sve_int_bin_pred_arit_0 opc, string asm, string Ps, + SDPatternOperator op, + DestructiveInstTypeEnum flags, + string revname="", bit isOrig=0> { + let DestructiveInstType = flags in { + def _B : sve_int_bin_pred_arit_log<0b00, 0b00, opc, asm, ZPR8>, + SVEPseudo2Instr, SVEInstr2Rev; + def _H : sve_int_bin_pred_arit_log<0b01, 0b00, opc, asm, ZPR16>, + SVEPseudo2Instr, SVEInstr2Rev; + def _S : sve_int_bin_pred_arit_log<0b10, 0b00, opc, asm, ZPR32>, + SVEPseudo2Instr, SVEInstr2Rev; + def _D : sve_int_bin_pred_arit_log<0b11, 0b00, opc, asm, ZPR64>, + SVEPseudo2Instr, SVEInstr2Rev; + } def : SVE_3_Op_Pat(NAME # _B)>; def : SVE_3_Op_Pat(NAME # _H)>; diff --git a/llvm/test/CodeGen/AArch64/sve-intrinsics-int-arith-merging.ll b/llvm/test/CodeGen/AArch64/sve-intrinsics-int-arith-merging.ll new file mode 100644 index 000000000000..984ebd17322f --- /dev/null +++ b/llvm/test/CodeGen/AArch64/sve-intrinsics-int-arith-merging.ll @@ -0,0 +1,172 @@ +; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s + +; +; ADD +; + +define @add_i8( %pg, %a, %b) { +; CHECK-LABEL: add_i8: +; CHECK: movprfx z0.b, p0/z, z0.b +; CHECK-NEXT: add z0.b, p0/m, z0.b, z1.b +; CHECK-NEXT: ret + %a_z = select %pg, %a, zeroinitializer + %out = call @llvm.aarch64.sve.add.nxv16i8( %pg, + %a_z, + %b) + ret %out +} + +define @add_i16( %pg, %a, %b) { +; CHECK-LABEL: add_i16: +; CHECK: movprfx z0.h, p0/z, z0.h +; CHECK-NEXT: add z0.h, p0/m, z0.h, z1.h +; CHECK-NEXT: ret + %a_z = select %pg, %a, zeroinitializer + %out = call @llvm.aarch64.sve.add.nxv8i16( %pg, + %a_z, + %b) + ret %out +} + +define @add_i32( %pg, %a, %b) { +; CHECK-LABEL: add_i32: +; CHECK: movprfx z0.s, p0/z, z0.s +; CHECK-NEXT: add z0.s, p0/m, z0.s, z1.s +; CHECK-NEXT: ret + %a_z = select %pg, %a, zeroinitializer + %out = call @llvm.aarch64.sve.add.nxv4i32( %pg, + %a_z, + %b) + ret %out +} + +define @add_i64( %pg, %a, %b) { +; CHECK-LABEL: add_i64: +; CHECK: movprfx z0.d, p0/z, z0.d +; CHECK-NEXT: add z0.d, p0/m, z0.d, z1.d +; CHECK-NEXT: ret + %a_z = select %pg, %a, zeroinitializer + %out = call @llvm.aarch64.sve.add.nxv2i64( %pg, + %a_z, + %b) + ret %out +} + +; +; SUB +; + +define @sub_i8( %pg, %a, %b) { +; CHECK-LABEL: sub_i8: +; CHECK: movprfx z0.b, p0/z, z0.b +; CHECK-NEXT: sub z0.b, p0/m, z0.b, z1.b +; CHECK-NEXT: ret + %a_z = select %pg, %a, zeroinitializer + %out = call @llvm.aarch64.sve.sub.nxv16i8( %pg, + %a_z, + %b) + ret %out +} + +define @sub_i16( %pg, %a, %b) { +; CHECK-LABEL: sub_i16: +; CHECK: movprfx z0.h, p0/z, z0.h +; CHECK-NEXT: sub z0.h, p0/m, z0.h, z1.h +; CHECK-NEXT: ret + %a_z = select %pg, %a, zeroinitializer + %out = call @llvm.aarch64.sve.sub.nxv8i16( %pg, + %a_z, + %b) + ret %out +} + +define @sub_i32( %pg, %a, %b) { +; CHECK-LABEL: sub_i32: +; CHECK: movprfx z0.s, p0/z, z0.s +; CHECK-NEXT: sub z0.s, p0/m, z0.s, z1.s +; CHECK-NEXT: ret + %a_z = select %pg, %a, zeroinitializer + %out = call @llvm.aarch64.sve.sub.nxv4i32( %pg, + %a_z, + %b) + ret %out +} + +define @sub_i64( %pg, %a, %b) { +; CHECK-LABEL: sub_i64: +; CHECK: movprfx z0.d, p0/z, z0.d +; CHECK-NEXT: sub z0.d, p0/m, z0.d, z1.d +; CHECK-NEXT: ret + %a_z = select %pg, %a, zeroinitializer + %out = call @llvm.aarch64.sve.sub.nxv2i64( %pg, + %a_z, + %b) + ret %out +} + +; +; SUBR +; + +define @subr_i8( %pg, %a, %b) { +; CHECK-LABEL: subr_i8: +; CHECK: movprfx z0.b, p0/z, z0.b +; CHECK-NEXT: subr z0.b, p0/m, z0.b, z1.b +; CHECK-NEXT: ret + %a_z = select %pg, %a, zeroinitializer + %out = call @llvm.aarch64.sve.subr.nxv16i8( %pg, + %a_z, + %b) + ret %out +} + +define @subr_i16( %pg, %a, %b) { +; CHECK-LABEL: subr_i16: +; CHECK: movprfx z0.h, p0/z, z0.h +; CHECK-NEXT: subr z0.h, p0/m, z0.h, z1.h +; CHECK-NEXT: ret + %a_z = select %pg, %a, zeroinitializer + %out = call @llvm.aarch64.sve.subr.nxv8i16( %pg, + %a_z, + %b) + ret %out +} + +define @subr_i32( %pg, %a, %b) { +; CHECK-LABEL: subr_i32: +; CHECK: movprfx z0.s, p0/z, z0.s +; CHECK-NEXT: subr z0.s, p0/m, z0.s, z1.s +; CHECK-NEXT: ret + %a_z = select %pg, %a, zeroinitializer + %out = call @llvm.aarch64.sve.subr.nxv4i32( %pg, + %a_z, + %b) + ret %out +} + +define @subr_i64( %pg, %a, %b) { +; CHECK-LABEL: subr_i64: +; CHECK: movprfx z0.d, p0/z, z0.d +; CHECK-NEXT: subr z0.d, p0/m, z0.d, z1.d +; CHECK-NEXT: ret + %a_z = select %pg, %a, zeroinitializer + %out = call @llvm.aarch64.sve.subr.nxv2i64( %pg, + %a_z, + %b) + ret %out +} + +declare @llvm.aarch64.sve.add.nxv16i8(, , ) +declare @llvm.aarch64.sve.add.nxv8i16(, , ) +declare @llvm.aarch64.sve.add.nxv4i32(, , ) +declare @llvm.aarch64.sve.add.nxv2i64(, , ) + +declare @llvm.aarch64.sve.sub.nxv16i8(, , ) +declare @llvm.aarch64.sve.sub.nxv8i16(, , ) +declare @llvm.aarch64.sve.sub.nxv4i32(, , ) +declare @llvm.aarch64.sve.sub.nxv2i64(, , ) + +declare @llvm.aarch64.sve.subr.nxv16i8(, , ) +declare @llvm.aarch64.sve.subr.nxv8i16(, , ) +declare @llvm.aarch64.sve.subr.nxv4i32(, , ) +declare @llvm.aarch64.sve.subr.nxv2i64(, , )