From ef6e6914c8245ca24dae952bc054ae2328e751ab Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Mon, 26 Nov 2018 15:37:35 +0000 Subject: [PATCH] re PR tree-optimization/88182 (ICE in vectorizable_reduction, at tree-vect-loop.c:6465) 2018-11-26 Richard Biener PR tree-optimization/88182 * tree-vect-loop.c (vectorizable_reduction): Pick up single correct reduc_def_info. * tree-vect-slp.c (vect_analyze_slp_instance): Set STMT_VINFO_REDUC_DEF of the first stmt. libgomp/ * testsuite/libgomp.c++/pr88182.C: New testcase. From-SVN: r266467 --- gcc/ChangeLog | 8 +++++++ gcc/tree-vect-loop.c | 29 ++++++++++------------- gcc/tree-vect-slp.c | 2 ++ libgomp/ChangeLog | 5 ++++ libgomp/testsuite/libgomp.c++/pr88182.C | 42 +++++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 17 deletions(-) create mode 100644 libgomp/testsuite/libgomp.c++/pr88182.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6be4605..b68fdad 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2018-11-26 Richard Biener + + PR tree-optimization/88182 + * tree-vect-loop.c (vectorizable_reduction): Pick up single + correct reduc_def_info. + * tree-vect-slp.c (vect_analyze_slp_instance): Set + STMT_VINFO_REDUC_DEF of the first stmt. + 2018-11-26 Andreas Krebbel * doc/invoke.texi: Document z14/arch12 -march option. diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index 07a22d7..9589a8e 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -6223,7 +6223,14 @@ vectorizable_reduction (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, The last use is the reduction variable. In case of nested cycle this assumption is not true: we use reduc_index to record the index of the reduction variable. */ - stmt_vec_info reduc_def_info = NULL; + stmt_vec_info reduc_def_info; + if (orig_stmt_info) + reduc_def_info = STMT_VINFO_REDUC_DEF (orig_stmt_info); + else + reduc_def_info = STMT_VINFO_REDUC_DEF (stmt_info); + gcc_assert (reduc_def_info); + gphi *reduc_def_phi = as_a (reduc_def_info->stmt); + tree reduc_def = PHI_RESULT (reduc_def_phi); int reduc_index = -1; for (i = 0; i < op_type; i++) { @@ -6236,9 +6243,9 @@ vectorizable_reduction (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, &def_stmt_info); dt = dts[i]; gcc_assert (is_simple_use); - if (dt == vect_reduction_def) + if (dt == vect_reduction_def + && ops[i] == reduc_def) { - reduc_def_info = def_stmt_info; reduc_index = i; continue; } @@ -6259,10 +6266,10 @@ vectorizable_reduction (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, && !(dt == vect_nested_cycle && nested_cycle)) return false; - if (dt == vect_nested_cycle) + if (dt == vect_nested_cycle + && ops[i] == reduc_def) { found_nested_cycle_def = true; - reduc_def_info = def_stmt_info; reduc_index = i; } @@ -6298,20 +6305,8 @@ vectorizable_reduction (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, "in-order reduction chain without SLP.\n"); return false; } - - if (orig_stmt_info) - reduc_def_info = STMT_VINFO_REDUC_DEF (orig_stmt_info); - else - reduc_def_info = STMT_VINFO_REDUC_DEF (stmt_info); } - if (! reduc_def_info) - return false; - - gphi *reduc_def_phi = dyn_cast (reduc_def_info->stmt); - if (!reduc_def_phi) - return false; - if (!(reduc_index == -1 || dts[reduc_index] == vect_reduction_def || dts[reduc_index] == vect_nested_cycle diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c index 9e805d0..4267cc9 100644 --- a/gcc/tree-vect-slp.c +++ b/gcc/tree-vect-slp.c @@ -1952,6 +1952,8 @@ vect_analyze_slp_instance (vec_info *vinfo, transform the node. In the reduction analysis phase only the last element of the chain is marked as reduction. */ STMT_VINFO_DEF_TYPE (stmt_info) = vect_reduction_def; + STMT_VINFO_REDUC_DEF (vect_orig_stmt (stmt_info)) + = STMT_VINFO_REDUC_DEF (vect_orig_stmt (scalar_stmts.last ())); } else { diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index 4037356..7068355 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,3 +1,8 @@ +2018-11-26 Richard Biener + + PR tree-optimization/88182 + * testsuite/libgomp.c++/pr88182.C: New testcase. + 2018-11-20 Jakub Jelinek PR bootstrap/88106 diff --git a/libgomp/testsuite/libgomp.c++/pr88182.C b/libgomp/testsuite/libgomp.c++/pr88182.C new file mode 100644 index 0000000..2e3ac69 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/pr88182.C @@ -0,0 +1,42 @@ +// { dg-do run } +// { dg-options "-O -fopenmp -ftree-loop-if-convert -fno-ssa-phiopt" } + +#pragma omp declare simd simdlen(4) notinbranch +__attribute__((noinline)) int +foo (double c1, double c2) +{ + double z1 = c1, z2 = c2; + int res = 100, i; + + for (i = 0; i < 5; i++) + { + res = (z1 * z1 + z2 * z2 > 4.0) ? (i < res ? i : res) : res; + z1 = c1 + z1 * z1 - z2 * z2; + z2 = c2 + 2.0 * z1 * z2; + c1 += 0.5; + c2 += 0.5; + } + return res; +} + +__attribute__((noinline, noclone)) void +bar (double *x, double *y) +{ + asm volatile ("" : : "rm" (x), "rm" (y) : "memory"); +} + +int +main () +{ + int i; + double c[4] = { 0.0, 1.0, 0.0, 1.0 }; + double d[4] = { 0.0, 1.0, 2.0, 0.0 }; + int e[4]; + bar (c, d); +#pragma omp simd safelen(4) + for (i = 0; i < 4; i++) + e[i] = foo (c[i], d[i]); + if (e[0] != 3 || e[1] != 1 || e[2] != 1 || e[3] != 2) + __builtin_abort (); + return 0; +} -- 2.7.4