re PR tree-optimization/87977 (ICE: verify_ssa failed (error: definition in block...
authorJakub Jelinek <jakub@redhat.com>
Wed, 14 Nov 2018 09:01:47 +0000 (10:01 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 14 Nov 2018 09:01:47 +0000 (10:01 +0100)
PR tree-optimization/87977
* tree-ssa-math-opts.c (optimize_recip_sqrt): Don't reuse division
stmt, build a new one and replace the old one with it.  Formatting fix.
Call release_ssa_name (x) if !has_other_use and !delete_div.
(pass_cse_reciprocals::execute): Before calling optimize_recip_sqrt
verify lhs of stmt is still def.

* gcc.dg/recip_sqrt_mult_1.c: Add -fcompare-debug to dg-options.
* gcc.dg/recip_sqrt_mult_2.c: Likewise.
* gcc.dg/recip_sqrt_mult_3.c: Likewise.
* gcc.dg/recip_sqrt_mult_4.c: Likewise.
* gcc.dg/recip_sqrt_mult_5.c: Likewise.

From-SVN: r266098

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/recip_sqrt_mult_1.c
gcc/testsuite/gcc.dg/recip_sqrt_mult_2.c
gcc/testsuite/gcc.dg/recip_sqrt_mult_3.c
gcc/testsuite/gcc.dg/recip_sqrt_mult_4.c
gcc/testsuite/gcc.dg/recip_sqrt_mult_5.c
gcc/tree-ssa-math-opts.c

index 62f6383195a4b8e75aac682c0a7c89d5ea056a75..cbd89695b1d887a6b20f221839a4dbb51a9df37c 100644 (file)
@@ -1,3 +1,12 @@
+2018-11-14  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/87977
+       * tree-ssa-math-opts.c (optimize_recip_sqrt): Don't reuse division
+       stmt, build a new one and replace the old one with it.  Formatting fix.
+       Call release_ssa_name (x) if !has_other_use and !delete_div.
+       (pass_cse_reciprocals::execute): Before calling optimize_recip_sqrt
+       verify lhs of stmt is still def.
+
 2018-11-13  Peter Bergner  <bergner@linux.ibm.com>
 
        PR rtl-optimization/87507
index c1c92b1cbc8fa0695d82737e86f6b66f28093e62..eb871d03d7c4cf60b4b1fe40f84e500ab5c5c8e2 100644 (file)
@@ -1,3 +1,12 @@
+2018-11-14  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/87977
+       * gcc.dg/recip_sqrt_mult_1.c: Add -fcompare-debug to dg-options.
+       * gcc.dg/recip_sqrt_mult_2.c: Likewise.
+       * gcc.dg/recip_sqrt_mult_3.c: Likewise.
+       * gcc.dg/recip_sqrt_mult_4.c: Likewise.
+       * gcc.dg/recip_sqrt_mult_5.c: Likewise.
+
 2018-11-13  Peter Bergner  <bergner@linux.ibm.com>
 
        PR rtl-optimization/87507
index 188390a4ecffca1b21f05c4f19abecfb7ebd188f..e057306a4ee89514f7a0b1651e024ad4339b3d3f 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-Ofast -fdump-tree-recip" } */
+/* { dg-options "-Ofast -fdump-tree-recip -fcompare-debug" } */
 
 double res, res2, tmp;
 void
index c5fc3de7b657b1769e76254b4bc874e0595e43ef..6ff284b60d3a14bf4764f191ea697acedbfed94c 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-Ofast -fdump-tree-optimized" } */
+/* { dg-options "-Ofast -fdump-tree-optimized -fcompare-debug" } */
 
 float
 foo (float a)
index e7d185ba7e22cfc7cca72296d5ccc544f24fdb14..7a8305de72745df20f4840538c4f999426eee551 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-Ofast -fdump-tree-optimized" } */
+/* { dg-options "-Ofast -fdump-tree-optimized -fcompare-debug" } */
 
 double
 foo (double a)
index e3005f2feb6f4bacbb6eafc0155e196cb866fcdf..3b8c1ec600f2b1c7478c777822aadff3706cf000 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-Ofast -fdump-tree-recip" } */
+/* { dg-options "-Ofast -fdump-tree-recip -fcompare-debug" } */
 
 /* The main path doesn't have any multiplications.
    Avoid introducing them in the recip pass.  */
index e871f0fcd4feb1687f9815e4babf4d0667a15ea8..27c6cd2e5128336b0812cce52ea70245c66a726d 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-Ofast -fdump-tree-recip" } */
+/* { dg-options "-Ofast -fdump-tree-recip -fcompare-debug" } */
 
 /* We want to do the recip_sqrt transformations here there is already
    a multiplication on the main path.  */
index ccff56f4297fb24a47bd68842c59ef9186301de2..d21077734e6040d7b0f298bab35ada863f0e916e 100644 (file)
@@ -652,8 +652,12 @@ optimize_recip_sqrt (gimple_stmt_iterator *def_gsi, tree def)
          print_gimple_stmt (dump_file, stmt, 0, TDF_NONE);
          fprintf (dump_file, "with new division\n");
        }
-      gimple_assign_set_lhs (stmt, sqr_ssa_name);
-      gimple_assign_set_rhs2 (stmt, a);
+      stmt
+       = gimple_build_assign (sqr_ssa_name, gimple_assign_rhs_code (stmt),
+                              gimple_assign_rhs1 (stmt), a);
+      gsi_insert_before (def_gsi, stmt, GSI_SAME_STMT);
+      gsi_remove (def_gsi, true);
+      *def_gsi = gsi_for_stmt (stmt);
       fold_stmt_inplace (def_gsi);
       update_stmt (stmt);
 
@@ -704,7 +708,7 @@ optimize_recip_sqrt (gimple_stmt_iterator *def_gsi, tree def)
 
       gimple *new_stmt
        = gimple_build_assign (x, MULT_EXPR,
-                               orig_sqrt_ssa_name, sqr_ssa_name);
+                              orig_sqrt_ssa_name, sqr_ssa_name);
       gsi_insert_after (def_gsi, new_stmt, GSI_NEW_STMT);
       update_stmt (stmt);
     }
@@ -715,6 +719,8 @@ optimize_recip_sqrt (gimple_stmt_iterator *def_gsi, tree def)
       gsi_remove (&gsi2, true);
       release_defs (stmt);
     }
+  else
+    release_ssa_name (x);
 }
 
 /* Look for floating-point divisions among DEF's uses, and try to
@@ -951,6 +957,7 @@ pass_cse_reciprocals::execute (function *fun)
              stmt = gsi_stmt (gsi);
              if (flag_unsafe_math_optimizations
                  && is_gimple_assign (stmt)
+                 && gimple_assign_lhs (stmt) == def
                  && !stmt_can_throw_internal (cfun, stmt)
                  && gimple_assign_rhs_code (stmt) == RDIV_EXPR)
                optimize_recip_sqrt (&gsi, def);