From 649794ff576fb9a033358799eb43a43addff1aa9 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 18 Jan 2019 13:13:21 +0000 Subject: [PATCH] re PR tree-optimization/88903 (wrong-code with SLP vectorized shift) 2019-01-18 Richard Biener PR tree-optimization/88903 * tree-vect-stmts.c (vectorizable_shift): Verify we see all scalar stmts a SLP shift amount is composed of when detecting shifts by scalars. * gcc.dg/vect/pr88903-1.c: New testcase. * gcc.dg/vect/pr88903-2.c: Likewise. From-SVN: r268076 --- gcc/ChangeLog | 7 +++++++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gcc.dg/vect/pr88903-1.c | 26 +++++++++++++++++++++++++ gcc/testsuite/gcc.dg/vect/pr88903-2.c | 28 +++++++++++++++++++++++++++ gcc/tree-vect-stmts.c | 10 ++++++++++ 5 files changed, 77 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/vect/pr88903-1.c create mode 100644 gcc/testsuite/gcc.dg/vect/pr88903-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ff87cbe5807..13890776cc0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2019-01-18 Richard Biener + + PR tree-optimization/88903 + * tree-vect-stmts.c (vectorizable_shift): Verify we see all + scalar stmts a SLP shift amount is composed of when detecting + shifts by scalars. + 2019-01-18 Richard Earnshaw PR target/88799 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 88a590ee9fa..77b89f46084 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-01-18 Richard Biener + + PR tree-optimization/88903 + * gcc.dg/vect/pr88903-1.c: New testcase. + * gcc.dg/vect/pr88903-2.c: Likewise. + 2019-01-18 H.J. Lu PR c/51628 diff --git a/gcc/testsuite/gcc.dg/vect/pr88903-1.c b/gcc/testsuite/gcc.dg/vect/pr88903-1.c new file mode 100644 index 00000000000..dead2b5e723 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr88903-1.c @@ -0,0 +1,26 @@ +#include "tree-vect.h" + +int x[1024]; + +void __attribute__((noinline)) +foo() +{ + for (int i = 0; i < 512; ++i) + { + x[2*i] = x[2*i] << (i+1); + x[2*i+1] = x[2*i+1] << (i+1); + } +} + +int +main() +{ + check_vect (); + for (int i = 0; i < 1024; ++i) + x[i] = i; + foo (); + for (int i = 0; i < 1024; ++i) + if (x[i] != i << (i/2+1)) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/vect/pr88903-2.c b/gcc/testsuite/gcc.dg/vect/pr88903-2.c new file mode 100644 index 00000000000..cd88a99c604 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr88903-2.c @@ -0,0 +1,28 @@ +#include "tree-vect.h" + +int x[1024]; +int y[1024]; +int z[1024]; + +void __attribute__((noinline)) foo() +{ + for (int i = 0; i < 512; ++i) + { + x[2*i] = x[2*i] << y[2*i]; + x[2*i+1] = x[2*i+1] << y[2*i]; + z[2*i] = y[2*i]; + z[2*i+1] = y[2*i+1]; + } +} + +int main() +{ + check_vect (); + for (int i = 0; i < 1024; ++i) + x[i] = i, y[i] = i % 8; + foo (); + for (int i = 0; i < 1024; ++i) + if (x[i] != i << ((i & ~1) % 8)) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c index c0e19dd178c..2220fce3165 100644 --- a/gcc/tree-vect-stmts.c +++ b/gcc/tree-vect-stmts.c @@ -5540,6 +5540,16 @@ vectorizable_shift (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, if (!operand_equal_p (gimple_assign_rhs2 (slpstmt), op1, 0)) scalar_shift_arg = false; } + + /* For internal SLP defs we have to make sure we see scalar stmts + for all vector elements. + ??? For different vectors we could resort to a different + scalar shift operand but code-generation below simply always + takes the first. */ + if (dt[1] == vect_internal_def + && maybe_ne (nunits_out * SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node), + stmts.length ())) + scalar_shift_arg = false; } /* If the shift amount is computed by a pattern stmt we cannot -- 2.30.2