Index: llvm/include/llvm/IR/IntrinsicsAArch64.td =================================================================== --- llvm/include/llvm/IR/IntrinsicsAArch64.td +++ llvm/include/llvm/IR/IntrinsicsAArch64.td @@ -768,6 +768,13 @@ LLVMMatchType<0>], [IntrNoMem]>; + class AdvSIMD_SVE_CNT_Intrinsic + : Intrinsic<[LLVMVectorOfBitcastsToInt<0>], + [LLVMVectorOfBitcastsToInt<0>, + LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>, + llvm_anyvector_ty], + [IntrNoMem]>; + // This class of intrinsics are not intended to be useful within LLVM IR but // are instead here to support some of the more regid parts of the ACLE. class Builtin_SVCVT @@ -788,6 +795,12 @@ def int_aarch64_sve_neg : AdvSIMD_Merged1VectorArg_Intrinsic; // +// Counting bits +// + +def int_aarch64_sve_cnt : AdvSIMD_SVE_CNT_Intrinsic; + +// // Floating-point comparisons // Index: llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td =================================================================== --- llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td +++ llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td @@ -97,11 +97,11 @@ defm ABS_ZPmZ : sve_int_un_pred_arit_0< 0b110, "abs", int_aarch64_sve_abs>; defm NEG_ZPmZ : sve_int_un_pred_arit_0< 0b111, "neg", int_aarch64_sve_neg>; - defm CLS_ZPmZ : sve_int_un_pred_arit_1< 0b000, "cls">; - defm CLZ_ZPmZ : sve_int_un_pred_arit_1< 0b001, "clz">; - defm CNT_ZPmZ : sve_int_un_pred_arit_1< 0b010, "cnt">; - defm CNOT_ZPmZ : sve_int_un_pred_arit_1< 0b011, "cnot">; - defm NOT_ZPmZ : sve_int_un_pred_arit_1< 0b110, "not">; + defm CLS_ZPmZ : sve_int_un_pred_arit_1< 0b000, "cls", null_frag>; + defm CLZ_ZPmZ : sve_int_un_pred_arit_1< 0b001, "clz", null_frag>; + defm CNT_ZPmZ : sve_int_un_pred_arit_1< 0b010, "cnt", int_aarch64_sve_cnt>; + defm CNOT_ZPmZ : sve_int_un_pred_arit_1< 0b011, "cnot", null_frag>; + defm NOT_ZPmZ : sve_int_un_pred_arit_1< 0b110, "not", null_frag>; defm FABS_ZPmZ : sve_int_un_pred_arit_1_fp<0b100, "fabs">; defm FNEG_ZPmZ : sve_int_un_pred_arit_1_fp<0b101, "fneg">; Index: llvm/lib/Target/AArch64/SVEInstrFormats.td =================================================================== --- llvm/lib/Target/AArch64/SVEInstrFormats.td +++ llvm/lib/Target/AArch64/SVEInstrFormats.td @@ -2871,11 +2871,21 @@ def _D : sve_int_un_pred_arit<0b11, { opc, 0b0 }, asm, ZPR64>; } -multiclass sve_int_un_pred_arit_1 opc, string asm> { +multiclass sve_int_un_pred_arit_1 opc, string asm, + SDPatternOperator op> { def _B : sve_int_un_pred_arit<0b00, { opc, 0b1 }, asm, ZPR8>; def _H : sve_int_un_pred_arit<0b01, { opc, 0b1 }, asm, ZPR16>; def _S : sve_int_un_pred_arit<0b10, { opc, 0b1 }, asm, ZPR32>; def _D : sve_int_un_pred_arit<0b11, { opc, 0b1 }, asm, ZPR64>; + + def : SVE_3_Op_Pat(NAME # _B)>; + def : SVE_3_Op_Pat(NAME # _H)>; + def : SVE_3_Op_Pat(NAME # _S)>; + def : SVE_3_Op_Pat(NAME # _D)>; + + def : SVE_3_Op_Pat(NAME # _H)>; + def : SVE_3_Op_Pat(NAME # _S)>; + def : SVE_3_Op_Pat(NAME # _D)>; } multiclass sve_int_un_pred_arit_1_fp opc, string asm> { Index: llvm/test/CodeGen/AArch64/sve-intrinsics-counting-bits.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/AArch64/sve-intrinsics-counting-bits.ll @@ -0,0 +1,83 @@ +; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s + +; +; CNT +; + +define @cnt_i8( %a, %pg, %b) { +; CHECK-LABEL: cnt_i8: +; CHECK: cnt z0.b, p0/m, z1.b +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.cnt.nxv16i8( %a, + %pg, + %b) + ret %out +} + +define @cnt_i16( %a, %pg, %b) { +; CHECK-LABEL: cnt_i16: +; CHECK: cnt z0.h, p0/m, z1.h +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.cnt.nxv8i16( %a, + %pg, + %b) + ret %out +} + +define @cnt_i32( %a, %pg, %b) { +; CHECK-LABEL: cnt_i32: +; CHECK: cnt z0.s, p0/m, z1.s +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.cnt.nxv4i32( %a, + %pg, + %b) + ret %out +} + +define @cnt_i64( %a, %pg, %b) { +; CHECK-LABEL: cnt_i64: +; CHECK: cnt z0.d, p0/m, z1.d +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.cnt.nxv2i64( %a, + %pg, + %b) + ret %out +} + +define @cnt_f16( %a, %pg, %b) { +; CHECK-LABEL: cnt_f16: +; CHECK: cnt z0.h, p0/m, z1.h +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.cnt.nxv8f16( %a, + %pg, + %b) + ret %out +} + +define @cnt_f32( %a, %pg, %b) { +; CHECK-LABEL: cnt_f32: +; CHECK: cnt z0.s, p0/m, z1.s +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.cnt.nxv4f32( %a, + %pg, + %b) + ret %out +} + +define @cnt_f64( %a, %pg, %b) { +; CHECK-LABEL: cnt_f64: +; CHECK: cnt z0.d, p0/m, z1.d +; CHECK-NEXT: ret + %out = call @llvm.aarch64.sve.cnt.nxv2f64( %a, + %pg, + %b) + ret %out +} + +declare @llvm.aarch64.sve.cnt.nxv16i8(, , ) +declare @llvm.aarch64.sve.cnt.nxv8i16(, , ) +declare @llvm.aarch64.sve.cnt.nxv4i32(, , ) +declare @llvm.aarch64.sve.cnt.nxv2i64(, , ) +declare @llvm.aarch64.sve.cnt.nxv8f16(, , ) +declare @llvm.aarch64.sve.cnt.nxv4f32(, , ) +declare @llvm.aarch64.sve.cnt.nxv2f64(, , )