Hi Kito, Thanks for the suggestion. I'll send v2 with these changes.
Thanks, Jiawei On 2026/11/16 21:42, Kito Cheng wrote:
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; } ... }
