On 11/16/26 6:42 AM, 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,
But that is how this is typically done.

Also note that in costing code you can be presented with RTL that does not match any valid insn in the target.

Jeff


Reply via email to