Hi Bohan, First, please have a look at the Satoshi review:
https://gcc.sashiko.dev/#/patchset/20261023120117.59808-1-garthlei%40linux.alibaba.com Both issues seem valid to me but the second might not be directly relevant (see below). All in all the patch looks pretty good already and beside the few nits and the coalesce discussion it's IMHO close. I still haven't looked at the builtin plumbing in detail but high-level it looks reasonable. > +TargetVariable > +int riscv_zvabd_subext > + > TargetVariable > int riscv_zvb_subext > > @@ -103,9 +109,6 @@ int riscv_zvk_subext > TargetVariable > int riscv_zvl_subext > > -TargetVariable > -int riscv_zvabd_subext > - Why is this moving? :) > +/* Initialize COALESCED for a permutation using FACTOR times wider > elements, > + preserving D's query or emission mode. Keep D unchanged and return false > + if the permutation or mode cannot be coalesced. */ > + > +static bool > +prepare_coalesced_vec_perm (expand_vec_perm_d *coalesced, > + const expand_vec_perm_d *d, unsigned int factor) > +{ > + machine_mode mode; > + > + if (!coalesced->perm.new_shrunk_vector (d->perm, factor) > + || !get_coalesced_mode (d->vmode, factor).exists (&mode)) > + return false; > + > + gcc_assert (known_eq (coalesced->perm.length (), GET_MODE_NUNITS (mode))); > + coalesced->vmode = mode; > + coalesced->op_mode = mode; > + coalesced->one_vector_p = d->one_vector_p; > + coalesced->testing_p = d->testing_p; > + coalesced->target = d->target ? gen_lowpart (mode, d->target) : NULL_RTX; > + coalesced->op0 = d->op0 ? gen_lowpart (mode, d->op0) : NULL_RTX; > + coalesced->op1 = d->op1 ? gen_lowpart (mode, d->op1) : NULL_RTX; > + return true; > +} I just realized that this already exists for aarch64 as well as x86. Long term surely something common code should do but for now we need to handle it ourselves. The function itself seems ok to me but its usage seems a bit peculiar :) IMHO the order should be roughly: (1) Coalesce/reencode the perm (2) Try patterns with the reencoded perm (except the generic fallback) (3) Try wit the original perm (except fallback) (4) Try reencoded fallback (5) Try fallback. But I suppose that would create a bit of churn and might change a few test expectations. Thus, how about we leave the coalescing out of this patch, also out of the new even/odd patterns and do it as a follow up? > +(define_insn "@xt_pred_<xxtvarith_ins_name><mode>" > + [(set (match_operand:V_VLS 0 "register_operand" "=vr, vr") > + (if_then_else:V_VLS > + (unspec:<VM> > + [(match_operand 4 "vector_length_operand" " rK, rK") > + (match_operand 5 "const_int_operand" " i, i") > + (match_operand 6 "const_int_operand" " i, i") > + (reg:SI VL_REGNUM) > + (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) > + (unspec:V_VLS > + [(match_operand:V_VLS 2 "register_operand" "vr,vr") > + (match_operand:V_VLS 3 "register_operand" "vr,vr")] UNSPEC_XT_VIL_IT) > + (match_operand:V_VLS 1 "vector_merge_operand" "vu,0")))] > + "TARGET_VECTOR && TARGET_XXTVARITH" > + "xt.<xxtvarith_ins_name>.vv\t%0,%2,%3" > + [(set_attr "type" "xt_<xxtvarith_ins_name>") > + (set_attr "mode" "<MODE>") > + (set_attr "merge_op_idx" "1") > + (set_attr "vl_op_idx" "4") > + (set (attr "ta") (symbol_ref "riscv_vector::get_ta(operands[5])")) > + (set (attr "avl_type_idx") (const_int 6))]) Are all these attributes necessary? Didn't you already add them to the attribute list? > diff --git a/gcc/testsuite/lib/target-supports.exp > b/gcc/testsuite/lib/target-supports.exp > index 3c5dfd59f6f..6c93c7375b6 100644 > --- a/gcc/testsuite/lib/target-supports.exp > +++ b/gcc/testsuite/lib/target-supports.exp > @@ -2349,6 +2349,17 @@ proc check_effective_target_riscv_zbkc { } { > }] > } > > +# Return 1 if the target arch supports the XXTVarith extension, 0 otherwise. > +# Cache the result. > + > +proc check_effective_target_riscv_xxtvarith { } { > + return [check_no_compiler_messages riscv_ext_xxtvarith assembly { > + #ifndef __riscv_xxtvarith > + #error "Not __riscv_xxtvarith" > + #endif > + }] > +} Wouldn't you rather want a runtime check here? In the end I don't mind too much as I trust you have done the testing but from a consistency perspective I'd prefer a real check. Not a blocker, your call. -- Regards Robin
