public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-2213] internal-fn, tree-cfg: Fix .TRAP handling and another __builtin_trap vops issue [PR106099]
@ 2022-08-26  7:29 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2022-08-26  7:29 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:530dc5aaaeb67c223fd0e3986d635408dcea4343

commit r13-2213-g530dc5aaaeb67c223fd0e3986d635408dcea4343
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Aug 26 09:28:48 2022 +0200

    internal-fn, tree-cfg: Fix .TRAP handling and another __builtin_trap vops issue [PR106099]
    
    This patch fixes 2 __builtin_unreachable/__builtin_trap related issues.
    One (first hunk) is that CDDCE happily removes calls to .TRAP ()
    internal-fn as useless.  The problem is that the internal-fn is
    ECF_CONST | ECF_NORETURN, doesn't have lhs and so DCE thinks it doesn't
    have side-effects and removes it.  __builtin_unreachable which has
    the same ECF_* flags works fine, as since PR44485 we implicitly add
    ECF_LOOPING_CONST_OR_PURE to ECF_CONST | ECF_NORETURN builtins, but
    do it in flags_from_decl_or_type which isn't called for internal-fns.
    As IFN_TRAP is the only ifn with such flags, it seems easier to
    add it explicitly.
    
    The other issue (which on the testcase can be seen only with the
    first bug unfixed) is that execute_fixup_cfg can add a __builtin_trap
    which needs vops, but nothing adds it and it can appear in many passes
    which don't have corresponding TODO_update_ssa_only_virtuals etc.
    Fixed similarly as last time but emitting ifn there instead.
    
    2022-08-26  Jakub Jelinek  <jakub@redhat.com>
    
            PR tree-optimization/106099
            * internal-fn.def (TRAP): Add ECF_LOOPING_CONST_OR_PURE flag.
            * tree-cfg.cc (execute_fixup_cfg): Add IFN_TRAP instead of
            __builtin_trap to avoid the need of vops.
    
            * gcc.dg/pr106099.c: New test.

Diff:
---
 gcc/internal-fn.def             |  3 ++-
 gcc/testsuite/gcc.dg/pr106099.c | 10 ++++++++++
 gcc/tree-cfg.cc                 | 14 +++++++-------
 3 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/gcc/internal-fn.def b/gcc/internal-fn.def
index 7bf661ca376..5e672183f4d 100644
--- a/gcc/internal-fn.def
+++ b/gcc/internal-fn.def
@@ -458,7 +458,8 @@ DEF_INTERNAL_FN (SPACESHIP, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL)
 
 /* __builtin_trap created from/for __builtin_unreachable.  */
 DEF_INTERNAL_FN (TRAP, ECF_CONST | ECF_LEAF | ECF_NORETURN
-		       | ECF_NOTHROW | ECF_COLD, NULL)
+		       | ECF_NOTHROW | ECF_COLD | ECF_LOOPING_CONST_OR_PURE,
+		 NULL)
 
 #undef DEF_INTERNAL_INT_FN
 #undef DEF_INTERNAL_FLT_FN
diff --git a/gcc/testsuite/gcc.dg/pr106099.c b/gcc/testsuite/gcc.dg/pr106099.c
new file mode 100644
index 00000000000..01b11442b2f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr106099.c
@@ -0,0 +1,10 @@
+/* PR tree-optimization/106099 */
+/* { dg-do compile } */
+/* { dg-options "-O -fharden-compares -fno-tree-forwprop -fno-tree-ch -fno-tree-dominator-opts -fno-tree-ccp -funreachable-traps --param=scev-max-expr-size=1" } */
+
+void
+foo (void)
+{
+  for (unsigned i = 0; i == 0; i++)
+    __builtin_printf ("%d", i);
+}
diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index 5bcf78198e7..91ec33c80a4 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -9878,16 +9878,16 @@ execute_fixup_cfg (void)
 	    {
 	      if (stmt && is_gimple_call (stmt))
 		gimple_call_set_ctrl_altering (stmt, false);
-	      tree fndecl = builtin_decl_unreachable ();
-	      stmt = gimple_build_call (fndecl, 0);
+	      stmt = gimple_build_builtin_unreachable (UNKNOWN_LOCATION);
 	      gimple_stmt_iterator gsi = gsi_last_bb (bb);
 	      gsi_insert_after (&gsi, stmt, GSI_NEW_STMT);
 	      if (!cfun->after_inlining)
-		{
-		  gcall *call_stmt = dyn_cast <gcall *> (stmt);
-		  node->create_edge (cgraph_node::get_create (fndecl),
-				     call_stmt, bb->count);
-		}
+		if (tree fndecl = gimple_call_fndecl (stmt))
+		  {
+		    gcall *call_stmt = dyn_cast <gcall *> (stmt);
+		    node->create_edge (cgraph_node::get_create (fndecl),
+				       call_stmt, bb->count);
+		  }
 	    }
 	}
     }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-08-26  7:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-26  7:29 [gcc r13-2213] internal-fn, tree-cfg: Fix .TRAP handling and another __builtin_trap vops issue [PR106099] Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).