re PR tree-optimization/90090 (ICE in mark_reachable_handlers, at tree-eh.c:3938...
authorJakub Jelinek <jakub@redhat.com>
Tue, 16 Apr 2019 08:24:47 +0000 (10:24 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 16 Apr 2019 08:24:47 +0000 (10:24 +0200)
PR tree-optimization/90090
* tree-ssa-math-opts.c (is_division_by): Ignore divisions that can
throw internally.
(is_division_by_square): Likewise.  Formatting fix.

* g++.dg/opt/pr90090.C: New test.

From-SVN: r270379

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/pr90090.C [new file with mode: 0644]
gcc/tree-ssa-math-opts.c

index 393e176175299f52483c4defb4ee88d54947e91e..7e1e60ca86e31dda37789bc088bfce7d1acd59be 100644 (file)
@@ -1,3 +1,10 @@
+2019-04-16  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/90090
+       * tree-ssa-math-opts.c (is_division_by): Ignore divisions that can
+       throw internally.
+       (is_division_by_square): Likewise.  Formatting fix.
+
 2019-04-16  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/56049
index 9f89fba152e61ea6ef799fd58a4caeb164f04eb5..d2e07721f6eb15af2a3e74310ebbdef67379e6d3 100644 (file)
@@ -1,3 +1,8 @@
+2019-04-16  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/90090
+       * g++.dg/opt/pr90090.C: New test.
+
 2019-04-16  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/56049
diff --git a/gcc/testsuite/g++.dg/opt/pr90090.C b/gcc/testsuite/g++.dg/opt/pr90090.C
new file mode 100644 (file)
index 0000000..f60a888
--- /dev/null
@@ -0,0 +1,19 @@
+// PR tree-optimization/90090
+// { dg-do compile }
+// { dg-options "-Ofast -fno-associative-math -fsignaling-nans -fno-tree-dce -fnon-call-exceptions" }
+
+double bar (double, double, double, double, double);
+double baz ();
+
+double
+foo (double a)
+{
+  try
+    {
+      return bar (1.0/a, 2.0/a, 4.0/a, 8.0/a, 16.0/a);
+    }
+  catch (...)
+    {
+      return baz ();
+    }
+}
index 1496520c9dc6b94807a1493be5976b40c2ab8f33..b7bbde4e40288c1a3f93e06273652454f7ed0899 100644 (file)
@@ -334,7 +334,8 @@ is_division_by (gimple *use_stmt, tree def)
         /* Do not recognize x / x as valid division, as we are getting
            confused later by replacing all immediate uses x in such
            a stmt.  */
-        && gimple_assign_rhs1 (use_stmt) != def;
+        && gimple_assign_rhs1 (use_stmt) != def
+        && !stmt_can_throw_internal (cfun, use_stmt);
 }
 
 /* Return TRUE if USE_STMT is a multiplication of DEF by A.  */
@@ -367,13 +368,12 @@ is_division_by_square (gimple *use_stmt, tree def)
 {
   if (gimple_code (use_stmt) == GIMPLE_ASSIGN
       && gimple_assign_rhs_code (use_stmt) == RDIV_EXPR
-      && gimple_assign_rhs1 (use_stmt) != gimple_assign_rhs2 (use_stmt))
+      && gimple_assign_rhs1 (use_stmt) != gimple_assign_rhs2 (use_stmt)
+      && !stmt_can_throw_internal (cfun, use_stmt))
     {
       tree denominator = gimple_assign_rhs2 (use_stmt);
       if (TREE_CODE (denominator) == SSA_NAME)
-       {
-         return is_square_of (SSA_NAME_DEF_STMT (denominator), def);
-       }
+       return is_square_of (SSA_NAME_DEF_STMT (denominator), def);
     }
   return 0;
 }