From: Richard Sandiford Date: Mon, 26 Feb 2018 16:17:00 +0000 (+0000) Subject: Make fix for PR 83965 handle SLP reduction chains X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d99dcb77bbbfdaf30c5993ea917001da259f47ba;p=gcc.git Make fix for PR 83965 handle SLP reduction chains This patch prevents pattern-matching of fold-left SLP reduction chains, which the previous patch for 83965 didn't handle properly. It only stops the last statement in the group from being matched, but that's enough to cause the group to be dissolved later. A better fix would be to put all the information about the reduction on the the first statement in the reduction chain, so that every statement in the group can tell what the group is doing. That doesn't seem like stage 4 material though. 2018-02-26 Richard Sandiford gcc/ PR tree-optimization/83965 * tree-vect-patterns.c (vect_reassociating_reduction_p): Assume that grouped statements are part of a reduction chain. Return true if the statement is not marked as a reduction itself but is part of a group. (vect_recog_dot_prod_pattern): Don't check whether the statement is part of a group here. (vect_recog_sad_pattern): Likewise. (vect_recog_widen_sum_pattern): Likewise. gcc/testsuite/ PR tree-optimization/83965 * gcc.dg/vect/pr83965-2.c: New test. From-SVN: r257995 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3e1eae15bb5..6ba082ac7ed 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2018-02-26 Richard Sandiford + + PR tree-optimization/83965 + * tree-vect-patterns.c (vect_reassociating_reduction_p): Assume + that grouped statements are part of a reduction chain. Return + true if the statement is not marked as a reduction itself but + is part of a group. + (vect_recog_dot_prod_pattern): Don't check whether the statement + is part of a group here. + (vect_recog_sad_pattern): Likewise. + (vect_recog_widen_sum_pattern): Likewise. + 2018-02-26 Eric Botcazou PR debug/84545 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a32934ba686..a927f22cdf2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-02-26 Richard Sandiford + + PR tree-optimization/83965 + * gcc.dg/vect/pr83965-2.c: New test. + 2018-02-26 Tom de Vries * gcc.c-torture/compile/regs-arg-size.c (swprintf): Declare. diff --git a/gcc/testsuite/gcc.dg/vect/pr83965-2.c b/gcc/testsuite/gcc.dg/vect/pr83965-2.c new file mode 100644 index 00000000000..b9e3260dbe9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr83965-2.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-Ofast -ftrapv" } */ + +int c; +unsigned char d; +int e (unsigned char *f) +{ + int g; + for (int a; a; a++) + { + for (int b = 0; b < 6; b++) + g += __builtin_abs (f[b] - d); + f += c; + } + return g; +} diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c index 34f69e9843d..621ed07758f 100644 --- a/gcc/tree-vect-patterns.c +++ b/gcc/tree-vect-patterns.c @@ -222,13 +222,16 @@ vect_recog_temp_ssa_var (tree type, gimple *stmt) } /* Return true if STMT_VINFO describes a reduction for which reassociation - is allowed. */ + is allowed. If STMT_INFO is part of a group, assume that it's part of + a reduction chain and optimistically assume that all statements + except the last allow reassociation. */ static bool vect_reassociating_reduction_p (stmt_vec_info stmt_vinfo) { return (STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_reduction_def - && STMT_VINFO_REDUC_TYPE (stmt_vinfo) != FOLD_LEFT_REDUCTION); + ? STMT_VINFO_REDUC_TYPE (stmt_vinfo) != FOLD_LEFT_REDUCTION + : GROUP_FIRST_ELEMENT (stmt_vinfo) != NULL); } /* Function vect_recog_dot_prod_pattern @@ -350,8 +353,7 @@ vect_recog_dot_prod_pattern (vec *stmts, tree *type_in, { gimple *def_stmt; - if (!vect_reassociating_reduction_p (stmt_vinfo) - && ! STMT_VINFO_GROUP_FIRST_ELEMENT (stmt_vinfo)) + if (!vect_reassociating_reduction_p (stmt_vinfo)) return NULL; oprnd0 = gimple_assign_rhs1 (last_stmt); oprnd1 = gimple_assign_rhs2 (last_stmt); @@ -571,8 +573,7 @@ vect_recog_sad_pattern (vec *stmts, tree *type_in, { gimple *def_stmt; - if (!vect_reassociating_reduction_p (stmt_vinfo) - && ! STMT_VINFO_GROUP_FIRST_ELEMENT (stmt_vinfo)) + if (!vect_reassociating_reduction_p (stmt_vinfo)) return NULL; plus_oprnd0 = gimple_assign_rhs1 (last_stmt); plus_oprnd1 = gimple_assign_rhs2 (last_stmt); @@ -1256,8 +1257,7 @@ vect_recog_widen_sum_pattern (vec *stmts, tree *type_in, if (gimple_assign_rhs_code (last_stmt) != PLUS_EXPR) return NULL; - if (!vect_reassociating_reduction_p (stmt_vinfo) - && ! STMT_VINFO_GROUP_FIRST_ELEMENT (stmt_vinfo)) + if (!vect_reassociating_reduction_p (stmt_vinfo)) return NULL; oprnd0 = gimple_assign_rhs1 (last_stmt);