From fb6a764dfdb74bbd0acfb7dc8d95a98286637d8a Mon Sep 17 00:00:00 2001 From: Andrew Pinski Date: Fri, 30 Jun 2017 20:40:38 +0000 Subject: [PATCH] tree-if-conv.c (predicate_scalar_phi): Update new_stmt if fold_stmt returned true. 2017-06-30 Andrew Pinski * tree-if-conv.c (predicate_scalar_phi): Update new_stmt if fold_stmt returned true. 2017-06-30 Andrew Pinski * gcc.dg/torture/pr81245.c: New testcase. From-SVN: r249854 --- gcc/ChangeLog | 5 +++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/torture/pr81245.c | 16 ++++++++++++++++ gcc/tree-if-conv.c | 7 +++++-- 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr81245.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8fd5ef62882..73a0555d432 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2017-06-30 Andrew Pinski + + * tree-if-conv.c (predicate_scalar_phi): Update new_stmt if + fold_stmt returned true. + 2017-06-30 Nathan Sidwell * ggc.h (empty_string): Delete. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 92d5f63ae2f..0331735cae0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-06-30 Andrew Pinski + + * gcc.dg/torture/pr81245.c: New testcase. + 2017-06-30 Aldy Hernandez * gcc.dg/Walloca-14.c: Adapt test to recognize new complaint of diff --git a/gcc/testsuite/gcc.dg/torture/pr81245.c b/gcc/testsuite/gcc.dg/torture/pr81245.c new file mode 100644 index 00000000000..b2ee7bb3a9b --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr81245.c @@ -0,0 +1,16 @@ +/* { dg-options "-ffast-math" } */ +/* { dg-do compile } */ +/* This test used to crash the vectorizer as the ifconvert pass + used to convert the if to copysign but called update_stmt on + the old statement after calling fold_stmt. */ +double sg[18]; +void f(void) +{ + for (int i = 0 ;i < 18;i++) + { + if (sg[i] < 0.0) + sg[i] = -1.0; + else + sg[i] = 1.0; + } +} diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c index b1f06a83fb2..dbacc6e1950 100644 --- a/gcc/tree-if-conv.c +++ b/gcc/tree-if-conv.c @@ -1853,8 +1853,11 @@ predicate_scalar_phi (gphi *phi, gimple_stmt_iterator *gsi) new_stmt = gimple_build_assign (res, rhs); gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT); gimple_stmt_iterator new_gsi = gsi_for_stmt (new_stmt); - fold_stmt (&new_gsi, ifcvt_follow_ssa_use_edges); - update_stmt (new_stmt); + if (fold_stmt (&new_gsi, ifcvt_follow_ssa_use_edges)) + { + new_stmt = gsi_stmt (new_gsi); + update_stmt (new_stmt); + } if (dump_file && (dump_flags & TDF_DETAILS)) { -- 2.30.2