public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-9262] tree-optimization/108950 - widen-sum reduction ICE
@ 2023-03-15 9:48 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-03-15 9:48 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:f4e4108dd005084fc1c88bba14fda6b200e70daa
commit r12-9262-gf4e4108dd005084fc1c88bba14fda6b200e70daa
Author: Richard Biener <rguenther@suse.de>
Date: Tue Feb 28 15:34:27 2023 +0100
tree-optimization/108950 - widen-sum reduction ICE
When we end up with a widen-sum with an invariant smaller operand
the reduction code uses a wrong vector type for it, causing
IL checking ICEs. The following fixes that and the inefficiency
of using a widen-sum with a widenend invariant operand as well
by actually performing the check the following comment wants.
PR tree-optimization/108950
* tree-vect-patterns.cc (vect_recog_widen_sum_pattern):
Check oprnd0 is defined in the loop.
* tree-vect-loop.cc (vectorizable_reduction): Record all
operands vector types, compute that of invariants and
properly update their SLP nodes.
* gcc.dg/vect/pr108950.c: New testcase.
(cherry picked from commit e3837b6f6c28a1d2cea3a69efbda795ea3fb8816)
Diff:
---
gcc/testsuite/gcc.dg/vect/pr108950.c | 13 +++++++++++++
gcc/tree-vect-loop.cc | 17 +++++++++++------
gcc/tree-vect-patterns.cc | 4 +++-
3 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/vect/pr108950.c b/gcc/testsuite/gcc.dg/vect/pr108950.c
new file mode 100644
index 00000000000..2163866dfa7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr108950.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+
+int m;
+short int n;
+
+__attribute__ ((simd)) int
+foo (void)
+{
+ m += n;
+ m += n;
+}
+
+/* { dg-final { scan-tree-dump-not "widen_sum" "vect" } } */
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 001f7dd8ab3..9dccbaa1b06 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -6569,6 +6569,7 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
stmt_vector_for_cost *cost_vec)
{
tree vectype_in = NULL_TREE;
+ tree vectype_op[3] = { NULL_TREE, NULL_TREE, NULL_TREE };
class loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
enum vect_def_type cond_reduc_dt = vect_unknown_def_type;
stmt_vec_info cond_stmt_vinfo = NULL;
@@ -6578,7 +6579,6 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
bool nested_cycle = false;
bool double_reduc = false;
int vec_num;
- tree tem;
tree cr_index_scalar_type = NULL_TREE, cr_index_vector_type = NULL_TREE;
tree cond_reduc_val = NULL_TREE;
@@ -6826,7 +6826,7 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
enum vect_def_type dt;
if (!vect_is_simple_use (loop_vinfo, stmt_info, slp_for_stmt_info,
i + opno_adjust, &op.ops[i], &slp_op[i], &dt,
- &tem, &def_stmt_info))
+ &vectype_op[i], &def_stmt_info))
{
if (dump_enabled_p ())
dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
@@ -6841,15 +6841,20 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
if (VECTORIZABLE_CYCLE_DEF (dt))
return false;
+ if (!vectype_op[i])
+ vectype_op[i]
+ = get_vectype_for_scalar_type (loop_vinfo,
+ TREE_TYPE (op.ops[i]), slp_op[i]);
+
/* To properly compute ncopies we are interested in the widest
non-reduction input type in case we're looking at a widening
accumulation that we later handle in vect_transform_reduction. */
if (lane_reduc_code_p
- && tem
+ && vectype_op[i]
&& (!vectype_in
|| (GET_MODE_SIZE (SCALAR_TYPE_MODE (TREE_TYPE (vectype_in)))
- < GET_MODE_SIZE (SCALAR_TYPE_MODE (TREE_TYPE (tem))))))
- vectype_in = tem;
+ < GET_MODE_SIZE (SCALAR_TYPE_MODE (TREE_TYPE (vectype_op[i]))))))
+ vectype_in = vectype_op[i];
if (op.code == COND_EXPR)
{
@@ -7362,7 +7367,7 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
&& !lane_reduc_code_p
&& reduction_type != FOLD_LEFT_REDUCTION))
for (i = 0; i < (int) op.num_ops; i++)
- if (!vect_maybe_update_slp_op_vectype (slp_op[i], vectype_in))
+ if (!vect_maybe_update_slp_op_vectype (slp_op[i], vectype_op[i]))
{
if (dump_enabled_p ())
dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index a4572454478..e1bcab0f7f6 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -1790,7 +1790,9 @@ vect_recog_widen_sum_pattern (vec_info *vinfo,
of the above pattern. */
if (!vect_reassociating_reduction_p (vinfo, stmt_vinfo, PLUS_EXPR,
- &oprnd0, &oprnd1))
+ &oprnd0, &oprnd1)
+ || TREE_CODE (oprnd0) != SSA_NAME
+ || !vinfo->lookup_def (oprnd0))
return NULL;
type = TREE_TYPE (gimple_get_lhs (last_stmt));
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-03-15 9:48 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-15 9:48 [gcc r12-9262] tree-optimization/108950 - widen-sum reduction ICE Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).