re PR rtl-optimization/90082 (ICE in delete_unmarked_insns, at dce.c:653)
authorJakub Jelinek <jakub@redhat.com>
Tue, 16 Apr 2019 08:26:26 +0000 (10:26 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 16 Apr 2019 08:26:26 +0000 (10:26 +0200)
PR rtl-optimization/90082
* dce.c (can_delete_call): New function.
(deletable_insn_p, mark_insn): Use it.

* gcc.dg/pr90082.c: New test.

From-SVN: r270380

gcc/ChangeLog
gcc/dce.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr90082.c [new file with mode: 0644]

index 7e1e60ca86e31dda37789bc088bfce7d1acd59be..368f36affc26c61ffbd858cdfcad20468c147402 100644 (file)
@@ -1,5 +1,9 @@
 2019-04-16  Jakub Jelinek  <jakub@redhat.com>
 
+       PR rtl-optimization/90082
+       * dce.c (can_delete_call): New function.
+       (deletable_insn_p, mark_insn): Use it.
+
        PR tree-optimization/90090
        * tree-ssa-math-opts.c (is_division_by): Ignore divisions that can
        throw internally.
index e6822fed7911f4938282db32d2ec2cf1b3495014..68d3713b0918c9a1b3eb6f9090d6484e906d16e4 100644 (file)
--- a/gcc/dce.c
+++ b/gcc/dce.c
@@ -87,6 +87,32 @@ deletable_insn_p_1 (rtx body)
     }
 }
 
+/* Don't delete calls that may throw if we cannot do so.  */
+
+static bool
+can_delete_call (rtx_insn *insn)
+{
+  if (cfun->can_delete_dead_exceptions && can_alter_cfg)
+    return true;
+  if (!insn_nothrow_p (insn))
+    return false;
+  if (can_alter_cfg)
+    return true;
+  /* If we can't alter cfg, even when the call can't throw exceptions, it
+     might have EDGE_ABNORMAL_CALL edges and so we shouldn't delete such
+     calls.  */
+  gcc_assert (CALL_P (insn));
+  if (BLOCK_FOR_INSN (insn) && BB_END (BLOCK_FOR_INSN (insn)) == insn)
+    {
+      edge e;
+      edge_iterator ei;
+
+      FOR_EACH_EDGE (e, ei, BLOCK_FOR_INSN (insn)->succs)
+       if ((e->flags & EDGE_ABNORMAL_CALL) != 0)
+         return false;
+    }
+  return true;
+}
 
 /* Return true if INSN is a normal instruction that can be deleted by
    the DCE pass.  */
@@ -111,8 +137,7 @@ deletable_insn_p (rtx_insn *insn, bool fast, bitmap arg_stores)
       && (RTL_CONST_OR_PURE_CALL_P (insn)
          && !RTL_LOOPING_CONST_OR_PURE_CALL_P (insn))
       /* Don't delete calls that may throw if we cannot do so.  */
-      && ((cfun->can_delete_dead_exceptions && can_alter_cfg)
-         || insn_nothrow_p (insn)))
+      && can_delete_call (insn))
     return find_call_stack_args (as_a <rtx_call_insn *> (insn), false,
                                 fast, arg_stores);
 
@@ -206,8 +231,7 @@ mark_insn (rtx_insn *insn, bool fast)
          && !SIBLING_CALL_P (insn)
          && (RTL_CONST_OR_PURE_CALL_P (insn)
              && !RTL_LOOPING_CONST_OR_PURE_CALL_P (insn))
-         && ((cfun->can_delete_dead_exceptions && can_alter_cfg)
-             || insn_nothrow_p (insn)))
+         && can_delete_call (insn))
        find_call_stack_args (as_a <rtx_call_insn *> (insn), true, fast, NULL);
     }
 }
index d2e07721f6eb15af2a3e74310ebbdef67379e6d3..92f9bb5911b4f376cb62a8323218f22c8d1b0ce0 100644 (file)
@@ -1,5 +1,8 @@
 2019-04-16  Jakub Jelinek  <jakub@redhat.com>
 
+       PR rtl-optimization/90082
+       * gcc.dg/pr90082.c: New test.
+
        PR tree-optimization/90090
        * g++.dg/opt/pr90090.C: New test.
 
diff --git a/gcc/testsuite/gcc.dg/pr90082.c b/gcc/testsuite/gcc.dg/pr90082.c
new file mode 100644 (file)
index 0000000..bb8293f
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR rtl-optimization/90082 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fnon-call-exceptions -ftrapv" } */
+
+void *buf[5];
+
+void
+foo (int a)
+{
+  if (__builtin_setjmp (buf) == 0)
+    __asm__ ("" : : "n" (a * 2));      /* { dg-error "impossible constraint in 'asm'" } */
+                                       /* { dg-warning "asm operand 0 probably doesn't match constraints" "" { target *-*-* } .-1 } */
+}