From f1485e5b24f83af957e3d528dc80cd88b67acdc5 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 10 Oct 2014 11:17:13 +0000 Subject: [PATCH] re PR tree-optimization/63379 (Incorrect vectorization when enabling SSE and O3, initialises loop with wrong value) 2014-10-10 Richard Biener PR tree-optimization/63379 * tree-vect-slp.c (vect_get_constant_vectors): Do not compute a neutral operand for min/max when it is not a reduction chain. * gcc.dg/vect/pr63379.c: New testcase. From-SVN: r216070 --- gcc/ChangeLog | 6 ++++ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.dg/vect/pr63379.c | 43 +++++++++++++++++++++++++++++ gcc/tree-vect-slp.c | 22 ++++++++++----- 4 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vect/pr63379.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index dbee77683b7..a42593f960e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2014-10-10 Richard Biener + + PR tree-optimization/63379 + * tree-vect-slp.c (vect_get_constant_vectors): Do not compute + a neutral operand for min/max when it is not a reduction chain. + 2014-10-10 Richard Biener PR tree-optimization/63476 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d9e93d352a9..632aa84af6a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-10-10 Richard Biener + + PR tree-optimization/63379 + * gcc.dg/vect/pr63379.c: New testcase. + 2014-10-10 Jakub Jelinek PR fortran/59488 diff --git a/gcc/testsuite/gcc.dg/vect/pr63379.c b/gcc/testsuite/gcc.dg/vect/pr63379.c new file mode 100644 index 00000000000..f6e8fc6a4ce --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr63379.c @@ -0,0 +1,43 @@ +/* PR tree-optimization/63379 */ +/* { dg-do run } */ + +#include "tree-vect.h" + +extern void abort (void); + +typedef struct { + int x; + int y; +} Point; + +Point pt_array[25]; + +void __attribute__((noinline,noclone)) +generate_array(void) +{ + unsigned int i; + for (i = 0; i<25; i++) + { + pt_array[i].x = i; + pt_array[i].y = 1000+i; + } +} + +int main() +{ + check_vect (); + generate_array (); + Point min_pt = pt_array[0]; + Point *ptr, *ptr_end; + for (ptr = pt_array+1, ptr_end = pt_array+25; ptr != ptr_end; ++ptr) + { + min_pt.x = (min_pt.x < ptr->x) ? min_pt.x : ptr->x; + min_pt.y = (min_pt.y < ptr->y) ? min_pt.y : ptr->y; + } + + if (min_pt.x != 0 || min_pt.y != 1000) + abort (); + return 0; +} + +/* { dg-final { cleanup-tree-dump "vect" } } */ diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c index d48d3f571e3..59842291a99 100644 --- a/gcc/tree-vect-slp.c +++ b/gcc/tree-vect-slp.c @@ -2395,13 +2395,21 @@ vect_get_constant_vectors (tree op, slp_tree slp_node, neutral_op = build_int_cst (TREE_TYPE (op), -1); break; - case MAX_EXPR: - case MIN_EXPR: - def_stmt = SSA_NAME_DEF_STMT (op); - loop = (gimple_bb (stmt))->loop_father; - neutral_op = PHI_ARG_DEF_FROM_EDGE (def_stmt, - loop_preheader_edge (loop)); - break; + /* For MIN/MAX we don't have an easy neutral operand but + the initial values can be used fine here. Only for + a reduction chain we have to force a neutral element. */ + case MAX_EXPR: + case MIN_EXPR: + if (!GROUP_FIRST_ELEMENT (stmt_vinfo)) + neutral_op = NULL; + else + { + def_stmt = SSA_NAME_DEF_STMT (op); + loop = (gimple_bb (stmt))->loop_father; + neutral_op = PHI_ARG_DEF_FROM_EDGE (def_stmt, + loop_preheader_edge (loop)); + } + break; default: neutral_op = NULL; -- 2.30.2