tree-if-conv.c (predicate_scalar_phi): Update new_stmt if fold_stmt returned true.
authorAndrew Pinski <apinski@cavium.com>
Fri, 30 Jun 2017 20:40:38 +0000 (20:40 +0000)
committerAndrew Pinski <pinskia@gcc.gnu.org>
Fri, 30 Jun 2017 20:40:38 +0000 (13:40 -0700)
2017-06-30  Andrew Pinski  <apinski@cavium.com>

        * tree-if-conv.c (predicate_scalar_phi): Update new_stmt if
        fold_stmt returned true.
2017-06-30  Andrew Pinski  <apinski@cavium.com>

        * gcc.dg/torture/pr81245.c: New testcase.

From-SVN: r249854

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr81245.c [new file with mode: 0644]
gcc/tree-if-conv.c

index 8fd5ef6288243565719072438bf0c89387fcec76..73a0555d432717055a5d192be4b18f4ef5ae975d 100644 (file)
@@ -1,3 +1,8 @@
+2017-06-30  Andrew Pinski  <apinski@cavium.com>
+
+       * tree-if-conv.c (predicate_scalar_phi): Update new_stmt if
+       fold_stmt returned true.
+
 2017-06-30  Nathan Sidwell  <nathan@acm.org>
 
        * ggc.h (empty_string): Delete.
index 92d5f63ae2f765a47d3bbaa5c2e27be1bd22d1c5..0331735cae05bd50aa9b32325716ef85f5007c61 100644 (file)
@@ -1,3 +1,7 @@
+2017-06-30  Andrew Pinski  <apinski@cavium.com>
+
+       * gcc.dg/torture/pr81245.c: New testcase.
+
 2017-06-30  Aldy Hernandez  <aldyh@redhat.com>
 
        * 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 (file)
index 0000000..b2ee7bb
--- /dev/null
@@ -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;
+  }
+}
index b1f06a83fb2044fde5f920b98dde7b641120020e..dbacc6e195025e9f5e0107dd6ccb1d9157fe8b5d 100644 (file)
@@ -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))
        {