public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Richard Biener <rguenther@suse.de>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] internal-fn, tree-cfg, v2: Fix .TRAP handling and another __builtin_trap vops issue [PR106099]
Date: Thu, 25 Aug 2022 09:48:13 +0200	[thread overview]
Message-ID: <YwcpPfC0w24dsaR1@tucnak> (raw)
In-Reply-To: <nycvar.YFH.7.77.849.2208241014090.13569@jbgna.fhfr.qr>

On Wed, Aug 24, 2022 at 10:20:45AM +0000, Richard Biener wrote:
> So
> 
>    combined_fn cfn = builtin_cfn_unreachable ();
>    gimple_build (&gsi, false, GSI_NEW_STMT, cfn, void_type_node);
> 
> ?

So what about just using existing call that creates the GIMPLE call,
whether it is builtin call or internal call?
I didn't use that initially because the code then wants to add a cgraph
edge for the fndecl, but in fact it is quite easy to gimple_call_fndecl
afterwards:

2022-08-25  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.

--- gcc/internal-fn.def.jj	2022-07-28 12:43:12.876295553 +0200
+++ gcc/internal-fn.def	2022-08-23 14:21:49.559364691 +0200
@@ -458,7 +458,8 @@ DEF_INTERNAL_FN (SPACESHIP, ECF_CONST |
 
 /* __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
--- gcc/tree-cfg.cc.jj	2022-07-26 10:32:23.998267698 +0200
+++ gcc/tree-cfg.cc	2022-08-25 09:42:19.013039869 +0200
@@ -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);
+		  }
 	    }
 	}
     }
--- gcc/testsuite/gcc.dg/pr106099.c.jj	2022-08-23 14:30:51.992057144 +0200
+++ gcc/testsuite/gcc.dg/pr106099.c	2022-08-23 14:29:04.271508337 +0200
@@ -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);
+}

	Jakub


  reply	other threads:[~2022-08-25  7:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-24  8:24 [PATCH] internal-fn, tree-cfg: " Jakub Jelinek
2022-08-24 10:20 ` Richard Biener
2022-08-25  7:48   ` Jakub Jelinek [this message]
2022-08-25  8:29     ` [PATCH] internal-fn, tree-cfg, v2: " Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YwcpPfC0w24dsaR1@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rguenther@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).