middle-end/95171 - inlining of trapping compare into non-call EH fn
authorRichard Biener <rguenther@suse.de>
Mon, 18 May 2020 06:51:23 +0000 (08:51 +0200)
committerRichard Biener <rguenther@suse.de>
Mon, 18 May 2020 10:27:53 +0000 (12:27 +0200)
This fixes always-inlining across -fnon-call-exception boundaries
for conditions which we do not allow to throw.

2020-05-18  Richard Biener  <rguenther@suse.de>

PR middle-end/95171
* tree-inline.c (remap_gimple_stmt): Split out trapping compares
when inlining into a non-call EH function.

* gcc.dg/pr95171.c: New testcase.

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr95171.c [new file with mode: 0644]
gcc/tree-inline.c

index 491293d77df1f14ecbbfac94936c06c01207f666..98c035a5356970441cf9f58297eb3c2e0797089e 100644 (file)
@@ -1,3 +1,9 @@
+2020-05-18  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/95171
+       * tree-inline.c (remap_gimple_stmt): Split out trapping compares
+       when inlining into a non-call EH function.
+
 2020-05-18  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/95172
index 1123599b9a71f188594cfbd29cc1f7dac587c2ff..33425f259b47ebf9262d5796b348906074412b0e 100644 (file)
@@ -1,3 +1,8 @@
+2020-05-18  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/95171
+       * gcc.dg/pr95171.c: New testcase.
+
 2020-05-18  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/95172
diff --git a/gcc/testsuite/gcc.dg/pr95171.c b/gcc/testsuite/gcc.dg/pr95171.c
new file mode 100644 (file)
index 0000000..af9bde7
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-fexceptions -ffinite-math-only -fnon-call-exceptions" } */
+
+inline double __attribute__ ((always_inline))
+w9 (int q2)
+{
+  return __builtin_fabs (__builtin_nan ("")) > 0.0 ? 1.0 : q2 / 1.0;
+}
+
+double __attribute__ ((optimize ("-fipa-cp")))
+o7 (int iz)
+{
+  int rj[1];
+
+  (void) rj;
+
+  return w9 (iz);
+}
index ee96c9cfff08a12324a1e77fd411b0996d184950..943f3f9407be2453b0752eba1abbd15350478e63 100644 (file)
@@ -1956,6 +1956,37 @@ remap_gimple_stmt (gimple *stmt, copy_body_data *id)
       gimple_set_vuse (copy, NULL_TREE);
     }
 
+  if (cfun->can_throw_non_call_exceptions)
+    {
+      /* When inlining a function which does not have non-call exceptions
+        enabled into a function that has (which only happens with
+        always-inline) we have to fixup stmts that cannot throw.  */
+      if (gcond *cond = dyn_cast <gcond *> (copy))
+       if (gimple_could_trap_p (cond))
+         {
+           gassign *cmp
+             = gimple_build_assign (make_ssa_name (boolean_type_node),
+                                    gimple_cond_code (cond),
+                                    gimple_cond_lhs (cond),
+                                    gimple_cond_rhs (cond));
+           gimple_seq_add_stmt (&stmts, cmp);
+           gimple_cond_set_code (cond, NE_EXPR);
+           gimple_cond_set_lhs (cond, gimple_assign_lhs (cmp));
+           gimple_cond_set_rhs (cond, boolean_false_node);
+         }
+      if (gassign *ass = dyn_cast <gassign *> (copy))
+       if ((gimple_assign_rhs_code (ass) == COND_EXPR
+            || gimple_assign_rhs_code (ass) == VEC_COND_EXPR)
+           && gimple_could_trap_p (ass))
+         {
+           gassign *cmp
+             = gimple_build_assign (make_ssa_name (boolean_type_node),
+                                    gimple_assign_rhs1 (ass));
+           gimple_seq_add_stmt (&stmts, cmp);
+           gimple_assign_set_rhs1 (ass, gimple_assign_lhs (cmp));
+         }
+    }
+
   gimple_seq_add_stmt (&stmts, copy);
   return stmts;
 }