> diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> index d83e26351c9..ae4fa0efb56 100644
> --- a/gcc/config/riscv/riscv.cc
> +++ b/gcc/config/riscv/riscv.cc
> @@ -4598,6 +4598,27 @@ riscv_rtx_costs (rtx x, machine_mode mode, int
> outer_code, int opno ATTRIBUTE_UN
> return true;
> }
>
> + /* Match the exposed RTL of riscv_xpack_<code>_<X:mode>_<HX:mode>_2.
> + All three operations combine disjoint halves into one pack. */
> + if (TARGET_ZBKB
> + && mode == word_mode
> + && GET_MODE (x) == mode
> + && (GET_CODE (x) == IOR || GET_CODE (x) == XOR
> + || GET_CODE (x) == PLUS)
> + && GET_CODE (XEXP (x, 0)) == ASHIFT
> + && GET_MODE (XEXP (x, 0)) == mode
> + && register_operand (XEXP (XEXP (x, 0), 0), mode)
> + && CONST_INT_P (XEXP (XEXP (x, 0), 1))
> + && INTVAL (XEXP (XEXP (x, 0), 1)) == BITS_PER_WORD / 2
> + && GET_CODE (XEXP (x, 1)) == ZERO_EXTEND
> + && GET_MODE (XEXP (x, 1)) == mode
> + && register_operand (XEXP (XEXP (x, 1), 0),
> + TARGET_64BIT ? SImode : HImode))
> + {
> + *total = COSTS_N_INSNS (1);
> + return true;
> + }
> +
Could you try to use riscv_insn_cost for that? the check is
right...but it's not easy to read and maintain,
so we probably should check that on riscv_insn_cost, and that function
has full rtx_insn
which means we can use insn attr to check that instead of checking the RTL.
And I guess we may need define new subtype to easier identity the
instruction otherwise all insn type in crypto.md is all "crypto"
e.g.
static int
riscv_insn_cost (rtx_insn *insn, bool speed)
{
if (recog_memoized (insn) >= 0)
switch (get_attr_type (insn))
{
case TYPE_CRYPTO:
switch (get_attr_subtype (insn))
{
case SUBTYPE_PACK:
return COSTS_N_INSNS (1);
default:
break;
}
break;
}
...
}
> bool float_mode_p = FLOAT_MODE_P (mode);
> int cost;
>
> diff --git a/gcc/testsuite/gcc.target/riscv/pack64-zba.c
> b/gcc/testsuite/gcc.target/riscv/pack64-zba.c
> new file mode 100644
> index 00000000000..ef92a43ffee
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/pack64-zba.c
> @@ -0,0 +1,9 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -march=rv64gc_zba_zbkb -mabi=lp64" } */
> +/* { dg-skip-if "" { *-*-* } { "-g" "-flto" "-O0" } } */
> +
> +#include "pack64.c"
> +
> +/* { dg-final { scan-assembler-times "\\spack\\s" 2 } } */
> +/* { dg-final { scan-assembler-not "\\sslli\\s" } } */
> +/* { dg-final { scan-assembler-not "\\sadd\\.uw\\s" } } */
>