]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end: refactor WIDEN_SUM_EXPR into convert optab [PR122069]
authorTamar Christina <tamar.christina@arm.com>
Sat, 18 Oct 2025 07:18:14 +0000 (08:18 +0100)
committerTamar Christina <tamar.christina@arm.com>
Sat, 18 Oct 2025 07:24:16 +0000 (08:24 +0100)
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.

gcc/doc/md.texi
gcc/optabs.cc
gcc/optabs.def
gcc/tree-vect-patterns.cc

index 44e1149bea89b18903061713e8319d834b76adbf..97d21b90a650e5e5fad5cd72b01f30983ca4ab43 100644 (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
index 5c9450f61450fa4425d08339a1c2b5f7f5e654ec..0865fc2e19aeb2b3056c8634334d6c1644a3cc96 100644 (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);
index 790e43f08f476c8025dc2797f9ecaffe5b66acc5..6cfcef9697189f5fd646fe7cb8f7372b6e4a0dde 100644 (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")
index a5c721e615358d826ea201c68f661862093f5f77..c92fbcd143dc731c87ca6103f13f7d9f71600c9d 100644 (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);