middle-end: refactor WIDEN_SUM_EXPR into convert optab [PR122069]

This patch changes the widen_[us]sum optabs into a convert optabs such that
targets and specify more than one conversion.

Following this patch are patches rewriting all targets using this change.

While working on this I noticed that the pattern does miss some cases it
could handle if it tried multiple attempts. e.g. if the promotion is from
qi to si, and the target doesn't have this, it should try hi -> si.

But I'm leaving that for now.

gcc/ChangeLog:

	PR middle-end/122069
	* doc/md.texi (widen_ssum@var{n}@var{m}3, widen_usum@var{n}@var{m}3):
	Update docs.
	* optabs.cc (expand_widen_pattern_expr): Add WIDEN_SUM_EXPR as widening.
	* optabs.def (ssum_widen_optab, usum_widen_optab): Convert from direct
	to a conversion optab.
	* tree-vect-patterns.cc (vect_recog_widen_sum_pattern): Change
	vect_supportable_direct_optab_p into vect_supportable_conv_optab_p.
This commit is contained in:
Tamar Christina 2025-10-18 08:18:14 +01:00
parent 2c1949bf15
commit 2bb6a8c4f9
4 changed files with 13 additions and 9 deletions

View File

@ -5847,15 +5847,15 @@ equal or wider than the mode of the absolute difference. The result is placed
in operand 0, which is of the same mode as operand 3.
@var{m} is the mode of operand 1 and operand 2.
@cindex @code{widen_ssum@var{m}3} instruction pattern
@cindex @code{widen_usum@var{m}3} instruction pattern
@item @samp{widen_ssum@var{m}3}
@itemx @samp{widen_usum@var{m}3}
@cindex @code{widen_ssum@var{n}@var{m}3} instruction pattern
@cindex @code{widen_usum@var{n}@var{m}3} instruction pattern
@item @samp{widen_ssum@var{n}@var{m}3}
@itemx @samp{widen_usum@var{n}@var{m}3}
Operands 0 and 2 are of the same mode, which is wider than the mode of
operand 1. Add operand 1 to operand 2 and place the widened result in
operand 0. (This is used express accumulation of elements into an accumulator
of a wider mode.)
@var{m} is the mode of operand 1.
@var{m} is the mode of operand 1 and @var{n} is the mode of operand 0.
@cindex @code{smulhs@var{m}3} instruction pattern
@cindex @code{umulhs@var{m}3} instruction pattern

View File

@ -322,6 +322,10 @@ expand_widen_pattern_expr (const_sepops ops, rtx op0, rtx op1, rtx wide_op,
icode = find_widening_optab_handler (widen_pattern_optab,
TYPE_MODE (TREE_TYPE (ops->op2)),
tmode0);
else if (ops->code == WIDEN_SUM_EXPR)
icode = find_widening_optab_handler (widen_pattern_optab,
TYPE_MODE (TREE_TYPE (ops->op1)),
tmode0);
else
icode = optab_handler (widen_pattern_optab, tmode0);
gcc_assert (icode != CODE_FOR_nothing);

View File

@ -85,6 +85,8 @@ OPTAB_CD(smsub_widen_optab, "msub$b$a4")
OPTAB_CD(umsub_widen_optab, "umsub$b$a4")
OPTAB_CD(ssmsub_widen_optab, "ssmsub$b$a4")
OPTAB_CD(usmsub_widen_optab, "usmsub$a$b4")
OPTAB_CD(ssum_widen_optab, "widen_ssum$a$b3")
OPTAB_CD(usum_widen_optab, "widen_usum$a$b3")
OPTAB_CD(crc_optab, "crc$a$b4")
OPTAB_CD(crc_rev_optab, "crc_rev$a$b4")
OPTAB_CD(vec_load_lanes_optab, "vec_load_lanes$a$b")
@ -415,8 +417,6 @@ OPTAB_D (savg_floor_optab, "avg$a3_floor")
OPTAB_D (uavg_floor_optab, "uavg$a3_floor")
OPTAB_D (savg_ceil_optab, "avg$a3_ceil")
OPTAB_D (uavg_ceil_optab, "uavg$a3_ceil")
OPTAB_D (ssum_widen_optab, "widen_ssum$I$a3")
OPTAB_D (usum_widen_optab, "widen_usum$I$a3")
OPTAB_D (usad_optab, "usad$I$a")
OPTAB_D (ssad_optab, "ssad$I$a")
OPTAB_D (smulhs_optab, "smulhs$a3")

View File

@ -2542,8 +2542,8 @@ vect_recog_widen_sum_pattern (vec_info *vinfo,
vect_pattern_detected ("vect_recog_widen_sum_pattern", last_stmt);
if (!vect_supportable_direct_optab_p (vinfo, type, WIDEN_SUM_EXPR,
unprom0.type, type_out))
if (!vect_supportable_conv_optab_p (vinfo, type, WIDEN_SUM_EXPR,
unprom0.type, type_out))
return NULL;
var = vect_recog_temp_ssa_var (type, NULL);