public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] cgraph: Handle BUILT_IN_UNREACHABLE_TRAP like BUILT_IN_UNREACHABLE in more spots [PR106258]
@ 2023-02-22  9:12 Jakub Jelinek
  2023-02-22  9:52 ` Richard Biener
  0 siblings, 1 reply; 11+ messages in thread
From: Jakub Jelinek @ 2023-02-22  9:12 UTC (permalink / raw)
  To: Richard Biener, Jan Hubicka, Martin Jambor; +Cc: gcc-patches

Hi!

The following testcase ICEs because we still have some spots that
treat BUILT_IN_UNREACHABLE specially but not BUILT_IN_UNREACHABLE_TRAP
the same.

The following patch fixes that, bootstrapped/regtested on x86_64-linux and
i686-linux, ok for trunk?

2023-02-22  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/106258
	* cgraph.cc (cgraph_edge::redirect_call_stmt_to_callee,
	cgraph_update_edges_for_call_stmt_node, cgraph_node::verify_node):
	Handle BUILT_IN_UNREACHABLE_TRAP like BUILT_IN_UNREACHABLE.
	* cgraphclones.cc (cgraph_node::create_clone): Likewise.

	* g++.dg/ipa/pr106258.C: New test.

--- gcc/cgraph.cc.jj	2023-02-07 10:33:46.027107080 +0100
+++ gcc/cgraph.cc	2023-02-21 14:57:10.405454504 +0100
@@ -1548,7 +1548,8 @@ cgraph_edge::redirect_call_stmt_to_calle
   else
     {
       if (flag_checking
-	  && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE))
+	  && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
+	  && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE_TRAP))
 	ipa_verify_edge_has_no_modifications (e);
       new_stmt = e->call_stmt;
       gimple_call_set_fndecl (new_stmt, e->callee->decl);
@@ -1634,7 +1635,9 @@ cgraph_update_edges_for_call_stmt_node (
 	{
 	  /* Keep calls marked as dead dead.  */
 	  if (new_stmt && is_gimple_call (new_stmt) && e->callee
-	      && fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE))
+	      && (fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
+		  || fndecl_built_in_p (e->callee->decl,
+					BUILT_IN_UNREACHABLE_TRAP)))
 	    {
 	      cgraph_edge::set_call_stmt (node->get_edge (old_stmt),
 					  as_a <gcall *> (new_stmt));
@@ -3598,7 +3601,9 @@ cgraph_node::verify_node (void)
 	  /* Optimized out calls are redirected to __builtin_unreachable.  */
 	  && (e->count.nonzero_p ()
 	      || ! e->callee->decl
-	      || !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE))
+	      || !(fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
+		   || fndecl_built_in_p (e->callee->decl,
+					 BUILT_IN_UNREACHABLE_TRAP)))
 	  && count
 	      == ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (decl))->count
 	  && (!e->count.ipa_p ()
--- gcc/cgraphclones.cc.jj	2023-01-02 09:32:44.706962765 +0100
+++ gcc/cgraphclones.cc	2023-02-21 14:58:11.619568895 +0100
@@ -425,7 +425,9 @@ cgraph_node::create_clone (tree new_decl
 	 version.  The only exception is when the edge was proved to
 	 be unreachable during the cloning procedure.  */
       if (!e->callee
-	  || !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE))
+	  || !(fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
+	       || fndecl_built_in_p (e->callee->decl,
+				     BUILT_IN_UNREACHABLE_TRAP)))
         e->redirect_callee_duplicating_thunks (new_node);
     }
   new_node->expand_all_artificial_thunks ();
--- gcc/testsuite/g++.dg/ipa/pr106258.C.jj	2023-02-21 15:02:17.251015237 +0100
+++ gcc/testsuite/g++.dg/ipa/pr106258.C	2023-02-21 15:02:12.255087511 +0100
@@ -0,0 +1,5 @@
+// PR middle-end/106258
+// { dg-do compile { target c++11 } }
+// { dg-options "-O2 -funreachable-traps" }
+
+#include "ipa-sra-4.C"

	Jakub


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] cgraph: Handle BUILT_IN_UNREACHABLE_TRAP like BUILT_IN_UNREACHABLE in more spots [PR106258]
  2023-02-22  9:12 [PATCH] cgraph: Handle BUILT_IN_UNREACHABLE_TRAP like BUILT_IN_UNREACHABLE in more spots [PR106258] Jakub Jelinek
@ 2023-02-22  9:52 ` Richard Biener
  2023-02-22 11:04   ` [PATCH] tree: Add 3 argument fndecl_built_in_p Jakub Jelinek
  0 siblings, 1 reply; 11+ messages in thread
From: Richard Biener @ 2023-02-22  9:52 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Jan Hubicka, Martin Jambor, gcc-patches

On Wed, 22 Feb 2023, Jakub Jelinek wrote:

> Hi!
> 
> The following testcase ICEs because we still have some spots that
> treat BUILT_IN_UNREACHABLE specially but not BUILT_IN_UNREACHABLE_TRAP
> the same.
> 
> The following patch fixes that, bootstrapped/regtested on x86_64-linux and
> i686-linux, ok for trunk?

OK.

> 2023-02-22  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR middle-end/106258
> 	* cgraph.cc (cgraph_edge::redirect_call_stmt_to_callee,
> 	cgraph_update_edges_for_call_stmt_node, cgraph_node::verify_node):
> 	Handle BUILT_IN_UNREACHABLE_TRAP like BUILT_IN_UNREACHABLE.
> 	* cgraphclones.cc (cgraph_node::create_clone): Likewise.
> 
> 	* g++.dg/ipa/pr106258.C: New test.
> 
> --- gcc/cgraph.cc.jj	2023-02-07 10:33:46.027107080 +0100
> +++ gcc/cgraph.cc	2023-02-21 14:57:10.405454504 +0100
> @@ -1548,7 +1548,8 @@ cgraph_edge::redirect_call_stmt_to_calle
>    else
>      {
>        if (flag_checking
> -	  && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE))
> +	  && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
> +	  && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE_TRAP))
>  	ipa_verify_edge_has_no_modifications (e);
>        new_stmt = e->call_stmt;
>        gimple_call_set_fndecl (new_stmt, e->callee->decl);
> @@ -1634,7 +1635,9 @@ cgraph_update_edges_for_call_stmt_node (
>  	{
>  	  /* Keep calls marked as dead dead.  */
>  	  if (new_stmt && is_gimple_call (new_stmt) && e->callee
> -	      && fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE))
> +	      && (fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
> +		  || fndecl_built_in_p (e->callee->decl,
> +					BUILT_IN_UNREACHABLE_TRAP)))
>  	    {
>  	      cgraph_edge::set_call_stmt (node->get_edge (old_stmt),
>  					  as_a <gcall *> (new_stmt));
> @@ -3598,7 +3601,9 @@ cgraph_node::verify_node (void)
>  	  /* Optimized out calls are redirected to __builtin_unreachable.  */
>  	  && (e->count.nonzero_p ()
>  	      || ! e->callee->decl
> -	      || !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE))
> +	      || !(fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
> +		   || fndecl_built_in_p (e->callee->decl,
> +					 BUILT_IN_UNREACHABLE_TRAP)))
>  	  && count
>  	      == ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (decl))->count
>  	  && (!e->count.ipa_p ()
> --- gcc/cgraphclones.cc.jj	2023-01-02 09:32:44.706962765 +0100
> +++ gcc/cgraphclones.cc	2023-02-21 14:58:11.619568895 +0100
> @@ -425,7 +425,9 @@ cgraph_node::create_clone (tree new_decl
>  	 version.  The only exception is when the edge was proved to
>  	 be unreachable during the cloning procedure.  */
>        if (!e->callee
> -	  || !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE))
> +	  || !(fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
> +	       || fndecl_built_in_p (e->callee->decl,
> +				     BUILT_IN_UNREACHABLE_TRAP)))
>          e->redirect_callee_duplicating_thunks (new_node);
>      }
>    new_node->expand_all_artificial_thunks ();
> --- gcc/testsuite/g++.dg/ipa/pr106258.C.jj	2023-02-21 15:02:17.251015237 +0100
> +++ gcc/testsuite/g++.dg/ipa/pr106258.C	2023-02-21 15:02:12.255087511 +0100
> @@ -0,0 +1,5 @@
> +// PR middle-end/106258
> +// { dg-do compile { target c++11 } }
> +// { dg-options "-O2 -funreachable-traps" }
> +
> +#include "ipa-sra-4.C"
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
HRB 36809 (AG Nuernberg)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] tree: Add 3 argument fndecl_built_in_p
  2023-02-22  9:52 ` Richard Biener
@ 2023-02-22 11:04   ` Jakub Jelinek
  2023-02-22 11:43     ` Richard Biener
  0 siblings, 1 reply; 11+ messages in thread
From: Jakub Jelinek @ 2023-02-22 11:04 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

On Wed, Feb 22, 2023 at 09:52:06AM +0000, Richard Biener wrote:
> > The following testcase ICEs because we still have some spots that
> > treat BUILT_IN_UNREACHABLE specially but not BUILT_IN_UNREACHABLE_TRAP
> > the same.

This patch uses (fndecl_built_in_p (node, BUILT_IN_UNREACHABLE)
		 || fndecl_built_in_p (node, BUILT_IN_UNREACHABLE_TRAP))
a lot and from grepping around, we do something like that in lots of
other places, or in some spots instead as
(fndecl_built_in_p (node, BUILT_IN_NORMAL)
 && (DECL_FUNCTION_CODE (node) == BUILT_IN_WHATEVER1
     || DECL_FUNCTION_CODE (node) == BUILT_IN_WHATEVER2))
The following patch adds an overload for this case, so we can write
it in a shorter way.  It isn't worth for 3+, code in that case
typically uses the fndecl_built_in_p (node, BUILT_IN_NORMAL)
+ switch in DECL_FUNCTION_CODE.

If this isn't appropriate for GCC 13 (or not at all), I think we'll
need to change at least ipa-prop.cc because it suffers from the same
problem as the previous patch was fixing.

2023-02-22  Jakub Jelinek  <jakub@redhat.com>

	* tree.h (fndecl_built_in_p): New overload with 2 built_in_function
	arguments.
	* builtins.cc (fold_builtin_expect): Use it.
	* gimplify.cc (goa_stabilize_expr): Likewise.
	* cgraphclones.cc (cgraph_node::create_clone): Likewise.
	* ipa-fnsummary.cc (compute_fn_summary): Likewise.
	* omp-low.cc (setjmp_or_longjmp_p): Likewise.
	* cgraph.cc (cgraph_edge::redirect_call_stmt_to_callee,
	cgraph_update_edges_for_call_stmt_node,
	cgraph_edge::verify_corresponds_to_fndecl,
	cgraph_node::verify_node): Likewise.
	* tree-stdarg.cc (optimize_va_list_gpr_fpr_size): Likewise.
	* gimple-ssa-warn-access.cc (matching_alloc_calls_p): Likewise.
	* ipa-prop.cc (try_make_edge_direct_virtual_call): Handle
	BUILT_IN_UNREACHABLE_TRAP like BUILT_IN_UNREACHABLE.

--- gcc/tree.h.jj	2023-02-17 12:45:08.223636043 +0100
+++ gcc/tree.h	2023-02-22 11:25:31.608825229 +0100
@@ -6615,6 +6615,18 @@ fndecl_built_in_p (const_tree node, buil
 	  && DECL_FUNCTION_CODE (node) == name);
 }
 
+/* Faster variant of
+   fndecl_built_in_p (NODE, NAME1) || fndecl_built_in_p (NODE, NAME2).  */
+
+inline bool
+fndecl_built_in_p (const_tree node, built_in_function name1,
+		   built_in_function name2)
+{
+  return (fndecl_built_in_p (node, BUILT_IN_NORMAL)
+	  && (DECL_FUNCTION_CODE (node) == name1
+	      || DECL_FUNCTION_CODE (node) == name2));
+}
+
 /* A struct for encapsulating location information about an operator
    and the operation built from it.
 
--- gcc/builtins.cc.jj	2023-02-14 12:09:57.163647987 +0100
+++ gcc/builtins.cc	2023-02-22 11:29:43.800179949 +0100
@@ -8625,8 +8625,8 @@ fold_builtin_expect (location_t loc, tre
 
   if (TREE_CODE (inner) == CALL_EXPR
       && (fndecl = get_callee_fndecl (inner))
-      && (fndecl_built_in_p (fndecl, BUILT_IN_EXPECT)
-	  || fndecl_built_in_p (fndecl, BUILT_IN_EXPECT_WITH_PROBABILITY)))
+      && fndecl_built_in_p (fndecl, BUILT_IN_EXPECT,
+			    BUILT_IN_EXPECT_WITH_PROBABILITY))
     return arg0;
 
   inner = inner_arg0;
--- gcc/gimplify.cc.jj	2023-02-15 09:23:27.807390189 +0100
+++ gcc/gimplify.cc	2023-02-22 11:32:38.446655528 +0100
@@ -15815,8 +15815,8 @@ goa_stabilize_expr (tree *expr_p, gimple
       if (TREE_CODE (expr) == CALL_EXPR)
 	{
 	  if (tree fndecl = get_callee_fndecl (expr))
-	    if (fndecl_built_in_p (fndecl, BUILT_IN_CLEAR_PADDING)
-		|| fndecl_built_in_p (fndecl, BUILT_IN_MEMCMP))
+	    if (fndecl_built_in_p (fndecl, BUILT_IN_CLEAR_PADDING,
+					   BUILT_IN_MEMCMP))
 	      {
 		int nargs = call_expr_nargs (expr);
 		for (int i = 0; i < nargs; i++)
--- gcc/cgraphclones.cc.jj	2023-02-22 11:21:56.467934980 +0100
+++ gcc/cgraphclones.cc	2023-02-22 11:28:30.272242754 +0100
@@ -425,9 +425,8 @@ cgraph_node::create_clone (tree new_decl
 	 version.  The only exception is when the edge was proved to
 	 be unreachable during the cloning procedure.  */
       if (!e->callee
-	  || !(fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
-	       || fndecl_built_in_p (e->callee->decl,
-				     BUILT_IN_UNREACHABLE_TRAP)))
+	  || !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
+						  BUILT_IN_UNREACHABLE_TRAP))
         e->redirect_callee_duplicating_thunks (new_node);
     }
   new_node->expand_all_artificial_thunks ();
--- gcc/ipa-fnsummary.cc.jj	2023-01-02 09:32:45.510951148 +0100
+++ gcc/ipa-fnsummary.cc	2023-02-22 11:33:07.922229473 +0100
@@ -3180,8 +3180,8 @@ compute_fn_summary (struct cgraph_node *
 	       for (e = node->callees; e; e = e->next_callee)
 		 {
 		   tree cdecl = e->callee->decl;
-		   if (fndecl_built_in_p (cdecl, BUILT_IN_APPLY_ARGS)
-		       || fndecl_built_in_p (cdecl, BUILT_IN_VA_START))
+		   if (fndecl_built_in_p (cdecl, BUILT_IN_APPLY_ARGS,
+						 BUILT_IN_VA_START))
 		     break;
 		 }
 	       node->can_change_signature = !e;
--- gcc/omp-low.cc.jj	2023-01-02 09:32:25.281243440 +0100
+++ gcc/omp-low.cc	2023-02-22 11:35:06.418516664 +0100
@@ -3992,8 +3992,7 @@ scan_omp_1_op (tree *tp, int *walk_subtr
 static bool
 setjmp_or_longjmp_p (const_tree fndecl)
 {
-  if (fndecl_built_in_p (fndecl, BUILT_IN_SETJMP)
-      || fndecl_built_in_p (fndecl, BUILT_IN_LONGJMP))
+  if (fndecl_built_in_p (fndecl, BUILT_IN_SETJMP, BUILT_IN_LONGJMP))
     return true;
 
   tree declname = DECL_NAME (fndecl);
--- gcc/cgraph.cc.jj	2023-02-22 11:21:56.466934995 +0100
+++ gcc/cgraph.cc	2023-02-22 11:27:29.907115300 +0100
@@ -1548,8 +1548,8 @@ cgraph_edge::redirect_call_stmt_to_calle
   else
     {
       if (flag_checking
-	  && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
-	  && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE_TRAP))
+	  && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
+						  BUILT_IN_UNREACHABLE_TRAP))
 	ipa_verify_edge_has_no_modifications (e);
       new_stmt = e->call_stmt;
       gimple_call_set_fndecl (new_stmt, e->callee->decl);
@@ -1635,9 +1635,8 @@ cgraph_update_edges_for_call_stmt_node (
 	{
 	  /* Keep calls marked as dead dead.  */
 	  if (new_stmt && is_gimple_call (new_stmt) && e->callee
-	      && (fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
-		  || fndecl_built_in_p (e->callee->decl,
-					BUILT_IN_UNREACHABLE_TRAP)))
+	      && fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
+				    BUILT_IN_UNREACHABLE_TRAP))
 	    {
 	      cgraph_edge::set_call_stmt (node->get_edge (old_stmt),
 					  as_a <gcall *> (new_stmt));
@@ -3259,9 +3258,8 @@ cgraph_edge::verify_corresponds_to_fndec
   /* Optimizers can redirect unreachable calls or calls triggering undefined
      behavior to __builtin_unreachable or __builtin_unreachable trap.  */
 
-  if (fndecl_built_in_p (callee->decl, BUILT_IN_NORMAL)
-      && (DECL_FUNCTION_CODE (callee->decl) == BUILT_IN_UNREACHABLE
-	  || DECL_FUNCTION_CODE (callee->decl) == BUILT_IN_UNREACHABLE_TRAP))
+  if (fndecl_built_in_p (callee->decl, BUILT_IN_UNREACHABLE,
+				       BUILT_IN_UNREACHABLE_TRAP))
     return false;
 
   if (callee->former_clone_of != node->decl
@@ -3601,9 +3599,8 @@ cgraph_node::verify_node (void)
 	  /* Optimized out calls are redirected to __builtin_unreachable.  */
 	  && (e->count.nonzero_p ()
 	      || ! e->callee->decl
-	      || !(fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
-		   || fndecl_built_in_p (e->callee->decl,
-					 BUILT_IN_UNREACHABLE_TRAP)))
+	      || !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
+				     BUILT_IN_UNREACHABLE_TRAP))
 	  && count
 	      == ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (decl))->count
 	  && (!e->count.ipa_p ()
--- gcc/tree-stdarg.cc.jj	2023-01-02 09:32:24.970247934 +0100
+++ gcc/tree-stdarg.cc	2023-02-22 11:38:22.383684097 +0100
@@ -867,8 +867,8 @@ optimize_va_list_gpr_fpr_size (function
 	      tree callee = gimple_call_fndecl (stmt);
 
 	      if (callee
-		  && (fndecl_built_in_p (callee, BUILT_IN_VA_START)
-		      || fndecl_built_in_p (callee, BUILT_IN_VA_END)))
+		  && fndecl_built_in_p (callee, BUILT_IN_VA_START,
+						BUILT_IN_VA_END))
 		continue;
 	    }
 
--- gcc/gimple-ssa-warn-access.cc.jj	2023-02-16 10:13:23.822208868 +0100
+++ gcc/gimple-ssa-warn-access.cc	2023-02-22 11:31:36.168555726 +0100
@@ -1780,8 +1780,7 @@ matching_alloc_calls_p (tree alloc_decl,
 
       /* Return false for deallocation functions that are known not
 	 to match.  */
-      if (fndecl_built_in_p (dealloc_decl, BUILT_IN_FREE)
-	  || fndecl_built_in_p (dealloc_decl, BUILT_IN_REALLOC))
+      if (fndecl_built_in_p (dealloc_decl, BUILT_IN_FREE, BUILT_IN_REALLOC))
 	return false;
       /* Otherwise proceed below to check the deallocation function's
 	 "*dealloc" attributes to look for one that mentions this operator
@@ -1805,8 +1804,8 @@ matching_alloc_calls_p (tree alloc_decl,
 	  if (DECL_IS_OPERATOR_DELETE_P (dealloc_decl))
 	    return false;
 
-	  if (fndecl_built_in_p (dealloc_decl, BUILT_IN_FREE)
-	      || fndecl_built_in_p (dealloc_decl, BUILT_IN_REALLOC))
+	  if (fndecl_built_in_p (dealloc_decl, BUILT_IN_FREE,
+					       BUILT_IN_REALLOC))
 	    return true;
 
 	  alloc_dealloc_kind = alloc_kind_t::builtin;
--- gcc/ipa-prop.cc.jj	2023-01-02 09:32:46.077942956 +0100
+++ gcc/ipa-prop.cc	2023-02-22 11:34:15.572251634 +0100
@@ -3849,7 +3849,8 @@ try_make_edge_direct_virtual_call (struc
 	  if (can_refer)
 	    {
 	      if (!t
-		  || fndecl_built_in_p (t, BUILT_IN_UNREACHABLE)
+		  || fndecl_built_in_p (t, BUILT_IN_UNREACHABLE,
+					   BUILT_IN_UNREACHABLE_TRAP)
 		  || !possible_polymorphic_call_target_p
 		       (ie, cgraph_node::get (t)))
 		{

	Jakub


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] tree: Add 3 argument fndecl_built_in_p
  2023-02-22 11:04   ` [PATCH] tree: Add 3 argument fndecl_built_in_p Jakub Jelinek
@ 2023-02-22 11:43     ` Richard Biener
  2023-02-22 12:16       ` Jonathan Wakely
  0 siblings, 1 reply; 11+ messages in thread
From: Richard Biener @ 2023-02-22 11:43 UTC (permalink / raw)
  To: Jakub Jelinek, jwakely; +Cc: gcc-patches

On Wed, 22 Feb 2023, Jakub Jelinek wrote:

> On Wed, Feb 22, 2023 at 09:52:06AM +0000, Richard Biener wrote:
> > > The following testcase ICEs because we still have some spots that
> > > treat BUILT_IN_UNREACHABLE specially but not BUILT_IN_UNREACHABLE_TRAP
> > > the same.
> 
> This patch uses (fndecl_built_in_p (node, BUILT_IN_UNREACHABLE)
> 		 || fndecl_built_in_p (node, BUILT_IN_UNREACHABLE_TRAP))
> a lot and from grepping around, we do something like that in lots of
> other places, or in some spots instead as
> (fndecl_built_in_p (node, BUILT_IN_NORMAL)
>  && (DECL_FUNCTION_CODE (node) == BUILT_IN_WHATEVER1
>      || DECL_FUNCTION_CODE (node) == BUILT_IN_WHATEVER2))
> The following patch adds an overload for this case, so we can write
> it in a shorter way.  It isn't worth for 3+, code in that case
> typically uses the fndecl_built_in_p (node, BUILT_IN_NORMAL)
> + switch in DECL_FUNCTION_CODE.
> 
> If this isn't appropriate for GCC 13 (or not at all), I think we'll
> need to change at least ipa-prop.cc because it suffers from the same
> problem as the previous patch was fixing.

Is it possible to use C++ (template) magic to expand the > 1 argument
case to

  if (fndecl_built_in_p (BUILT_IN_NORMA)
      && (... || ... || ...

lispy we'd expand to the head check and then recursively on the
first and the remaining args.

Richard.

> 2023-02-22  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* tree.h (fndecl_built_in_p): New overload with 2 built_in_function
> 	arguments.
> 	* builtins.cc (fold_builtin_expect): Use it.
> 	* gimplify.cc (goa_stabilize_expr): Likewise.
> 	* cgraphclones.cc (cgraph_node::create_clone): Likewise.
> 	* ipa-fnsummary.cc (compute_fn_summary): Likewise.
> 	* omp-low.cc (setjmp_or_longjmp_p): Likewise.
> 	* cgraph.cc (cgraph_edge::redirect_call_stmt_to_callee,
> 	cgraph_update_edges_for_call_stmt_node,
> 	cgraph_edge::verify_corresponds_to_fndecl,
> 	cgraph_node::verify_node): Likewise.
> 	* tree-stdarg.cc (optimize_va_list_gpr_fpr_size): Likewise.
> 	* gimple-ssa-warn-access.cc (matching_alloc_calls_p): Likewise.
> 	* ipa-prop.cc (try_make_edge_direct_virtual_call): Handle
> 	BUILT_IN_UNREACHABLE_TRAP like BUILT_IN_UNREACHABLE.
> 
> --- gcc/tree.h.jj	2023-02-17 12:45:08.223636043 +0100
> +++ gcc/tree.h	2023-02-22 11:25:31.608825229 +0100
> @@ -6615,6 +6615,18 @@ fndecl_built_in_p (const_tree node, buil
>  	  && DECL_FUNCTION_CODE (node) == name);
>  }
>  
> +/* Faster variant of
> +   fndecl_built_in_p (NODE, NAME1) || fndecl_built_in_p (NODE, NAME2).  */
> +
> +inline bool
> +fndecl_built_in_p (const_tree node, built_in_function name1,
> +		   built_in_function name2)
> +{
> +  return (fndecl_built_in_p (node, BUILT_IN_NORMAL)
> +	  && (DECL_FUNCTION_CODE (node) == name1
> +	      || DECL_FUNCTION_CODE (node) == name2));
> +}
> +
>  /* A struct for encapsulating location information about an operator
>     and the operation built from it.
>  
> --- gcc/builtins.cc.jj	2023-02-14 12:09:57.163647987 +0100
> +++ gcc/builtins.cc	2023-02-22 11:29:43.800179949 +0100
> @@ -8625,8 +8625,8 @@ fold_builtin_expect (location_t loc, tre
>  
>    if (TREE_CODE (inner) == CALL_EXPR
>        && (fndecl = get_callee_fndecl (inner))
> -      && (fndecl_built_in_p (fndecl, BUILT_IN_EXPECT)
> -	  || fndecl_built_in_p (fndecl, BUILT_IN_EXPECT_WITH_PROBABILITY)))
> +      && fndecl_built_in_p (fndecl, BUILT_IN_EXPECT,
> +			    BUILT_IN_EXPECT_WITH_PROBABILITY))
>      return arg0;
>  
>    inner = inner_arg0;
> --- gcc/gimplify.cc.jj	2023-02-15 09:23:27.807390189 +0100
> +++ gcc/gimplify.cc	2023-02-22 11:32:38.446655528 +0100
> @@ -15815,8 +15815,8 @@ goa_stabilize_expr (tree *expr_p, gimple
>        if (TREE_CODE (expr) == CALL_EXPR)
>  	{
>  	  if (tree fndecl = get_callee_fndecl (expr))
> -	    if (fndecl_built_in_p (fndecl, BUILT_IN_CLEAR_PADDING)
> -		|| fndecl_built_in_p (fndecl, BUILT_IN_MEMCMP))
> +	    if (fndecl_built_in_p (fndecl, BUILT_IN_CLEAR_PADDING,
> +					   BUILT_IN_MEMCMP))
>  	      {
>  		int nargs = call_expr_nargs (expr);
>  		for (int i = 0; i < nargs; i++)
> --- gcc/cgraphclones.cc.jj	2023-02-22 11:21:56.467934980 +0100
> +++ gcc/cgraphclones.cc	2023-02-22 11:28:30.272242754 +0100
> @@ -425,9 +425,8 @@ cgraph_node::create_clone (tree new_decl
>  	 version.  The only exception is when the edge was proved to
>  	 be unreachable during the cloning procedure.  */
>        if (!e->callee
> -	  || !(fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
> -	       || fndecl_built_in_p (e->callee->decl,
> -				     BUILT_IN_UNREACHABLE_TRAP)))
> +	  || !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
> +						  BUILT_IN_UNREACHABLE_TRAP))
>          e->redirect_callee_duplicating_thunks (new_node);
>      }
>    new_node->expand_all_artificial_thunks ();
> --- gcc/ipa-fnsummary.cc.jj	2023-01-02 09:32:45.510951148 +0100
> +++ gcc/ipa-fnsummary.cc	2023-02-22 11:33:07.922229473 +0100
> @@ -3180,8 +3180,8 @@ compute_fn_summary (struct cgraph_node *
>  	       for (e = node->callees; e; e = e->next_callee)
>  		 {
>  		   tree cdecl = e->callee->decl;
> -		   if (fndecl_built_in_p (cdecl, BUILT_IN_APPLY_ARGS)
> -		       || fndecl_built_in_p (cdecl, BUILT_IN_VA_START))
> +		   if (fndecl_built_in_p (cdecl, BUILT_IN_APPLY_ARGS,
> +						 BUILT_IN_VA_START))
>  		     break;
>  		 }
>  	       node->can_change_signature = !e;
> --- gcc/omp-low.cc.jj	2023-01-02 09:32:25.281243440 +0100
> +++ gcc/omp-low.cc	2023-02-22 11:35:06.418516664 +0100
> @@ -3992,8 +3992,7 @@ scan_omp_1_op (tree *tp, int *walk_subtr
>  static bool
>  setjmp_or_longjmp_p (const_tree fndecl)
>  {
> -  if (fndecl_built_in_p (fndecl, BUILT_IN_SETJMP)
> -      || fndecl_built_in_p (fndecl, BUILT_IN_LONGJMP))
> +  if (fndecl_built_in_p (fndecl, BUILT_IN_SETJMP, BUILT_IN_LONGJMP))
>      return true;
>  
>    tree declname = DECL_NAME (fndecl);
> --- gcc/cgraph.cc.jj	2023-02-22 11:21:56.466934995 +0100
> +++ gcc/cgraph.cc	2023-02-22 11:27:29.907115300 +0100
> @@ -1548,8 +1548,8 @@ cgraph_edge::redirect_call_stmt_to_calle
>    else
>      {
>        if (flag_checking
> -	  && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
> -	  && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE_TRAP))
> +	  && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
> +						  BUILT_IN_UNREACHABLE_TRAP))
>  	ipa_verify_edge_has_no_modifications (e);
>        new_stmt = e->call_stmt;
>        gimple_call_set_fndecl (new_stmt, e->callee->decl);
> @@ -1635,9 +1635,8 @@ cgraph_update_edges_for_call_stmt_node (
>  	{
>  	  /* Keep calls marked as dead dead.  */
>  	  if (new_stmt && is_gimple_call (new_stmt) && e->callee
> -	      && (fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
> -		  || fndecl_built_in_p (e->callee->decl,
> -					BUILT_IN_UNREACHABLE_TRAP)))
> +	      && fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
> +				    BUILT_IN_UNREACHABLE_TRAP))
>  	    {
>  	      cgraph_edge::set_call_stmt (node->get_edge (old_stmt),
>  					  as_a <gcall *> (new_stmt));
> @@ -3259,9 +3258,8 @@ cgraph_edge::verify_corresponds_to_fndec
>    /* Optimizers can redirect unreachable calls or calls triggering undefined
>       behavior to __builtin_unreachable or __builtin_unreachable trap.  */
>  
> -  if (fndecl_built_in_p (callee->decl, BUILT_IN_NORMAL)
> -      && (DECL_FUNCTION_CODE (callee->decl) == BUILT_IN_UNREACHABLE
> -	  || DECL_FUNCTION_CODE (callee->decl) == BUILT_IN_UNREACHABLE_TRAP))
> +  if (fndecl_built_in_p (callee->decl, BUILT_IN_UNREACHABLE,
> +				       BUILT_IN_UNREACHABLE_TRAP))
>      return false;
>  
>    if (callee->former_clone_of != node->decl
> @@ -3601,9 +3599,8 @@ cgraph_node::verify_node (void)
>  	  /* Optimized out calls are redirected to __builtin_unreachable.  */
>  	  && (e->count.nonzero_p ()
>  	      || ! e->callee->decl
> -	      || !(fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
> -		   || fndecl_built_in_p (e->callee->decl,
> -					 BUILT_IN_UNREACHABLE_TRAP)))
> +	      || !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
> +				     BUILT_IN_UNREACHABLE_TRAP))
>  	  && count
>  	      == ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (decl))->count
>  	  && (!e->count.ipa_p ()
> --- gcc/tree-stdarg.cc.jj	2023-01-02 09:32:24.970247934 +0100
> +++ gcc/tree-stdarg.cc	2023-02-22 11:38:22.383684097 +0100
> @@ -867,8 +867,8 @@ optimize_va_list_gpr_fpr_size (function
>  	      tree callee = gimple_call_fndecl (stmt);
>  
>  	      if (callee
> -		  && (fndecl_built_in_p (callee, BUILT_IN_VA_START)
> -		      || fndecl_built_in_p (callee, BUILT_IN_VA_END)))
> +		  && fndecl_built_in_p (callee, BUILT_IN_VA_START,
> +						BUILT_IN_VA_END))
>  		continue;
>  	    }
>  
> --- gcc/gimple-ssa-warn-access.cc.jj	2023-02-16 10:13:23.822208868 +0100
> +++ gcc/gimple-ssa-warn-access.cc	2023-02-22 11:31:36.168555726 +0100
> @@ -1780,8 +1780,7 @@ matching_alloc_calls_p (tree alloc_decl,
>  
>        /* Return false for deallocation functions that are known not
>  	 to match.  */
> -      if (fndecl_built_in_p (dealloc_decl, BUILT_IN_FREE)
> -	  || fndecl_built_in_p (dealloc_decl, BUILT_IN_REALLOC))
> +      if (fndecl_built_in_p (dealloc_decl, BUILT_IN_FREE, BUILT_IN_REALLOC))
>  	return false;
>        /* Otherwise proceed below to check the deallocation function's
>  	 "*dealloc" attributes to look for one that mentions this operator
> @@ -1805,8 +1804,8 @@ matching_alloc_calls_p (tree alloc_decl,
>  	  if (DECL_IS_OPERATOR_DELETE_P (dealloc_decl))
>  	    return false;
>  
> -	  if (fndecl_built_in_p (dealloc_decl, BUILT_IN_FREE)
> -	      || fndecl_built_in_p (dealloc_decl, BUILT_IN_REALLOC))
> +	  if (fndecl_built_in_p (dealloc_decl, BUILT_IN_FREE,
> +					       BUILT_IN_REALLOC))
>  	    return true;
>  
>  	  alloc_dealloc_kind = alloc_kind_t::builtin;
> --- gcc/ipa-prop.cc.jj	2023-01-02 09:32:46.077942956 +0100
> +++ gcc/ipa-prop.cc	2023-02-22 11:34:15.572251634 +0100
> @@ -3849,7 +3849,8 @@ try_make_edge_direct_virtual_call (struc
>  	  if (can_refer)
>  	    {
>  	      if (!t
> -		  || fndecl_built_in_p (t, BUILT_IN_UNREACHABLE)
> +		  || fndecl_built_in_p (t, BUILT_IN_UNREACHABLE,
> +					   BUILT_IN_UNREACHABLE_TRAP)
>  		  || !possible_polymorphic_call_target_p
>  		       (ie, cgraph_node::get (t)))
>  		{
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
HRB 36809 (AG Nuernberg)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] tree: Add 3 argument fndecl_built_in_p
  2023-02-22 11:43     ` Richard Biener
@ 2023-02-22 12:16       ` Jonathan Wakely
  2023-02-22 12:35         ` Jonathan Wakely
  2023-02-22 12:49         ` [PATCH] tree: Add 3 argument fndecl_built_in_p Richard Biener
  0 siblings, 2 replies; 11+ messages in thread
From: Jonathan Wakely @ 2023-02-22 12:16 UTC (permalink / raw)
  To: Richard Biener; +Cc: Jakub Jelinek, gcc-patches

On Wed, 22 Feb 2023 at 11:49, Richard Biener <rguenther@suse.de> wrote:
>
> On Wed, 22 Feb 2023, Jakub Jelinek wrote:
>
> > On Wed, Feb 22, 2023 at 09:52:06AM +0000, Richard Biener wrote:
> > > > The following testcase ICEs because we still have some spots that
> > > > treat BUILT_IN_UNREACHABLE specially but not BUILT_IN_UNREACHABLE_TRAP
> > > > the same.
> >
> > This patch uses (fndecl_built_in_p (node, BUILT_IN_UNREACHABLE)
> >                || fndecl_built_in_p (node, BUILT_IN_UNREACHABLE_TRAP))
> > a lot and from grepping around, we do something like that in lots of
> > other places, or in some spots instead as
> > (fndecl_built_in_p (node, BUILT_IN_NORMAL)
> >  && (DECL_FUNCTION_CODE (node) == BUILT_IN_WHATEVER1
> >      || DECL_FUNCTION_CODE (node) == BUILT_IN_WHATEVER2))
> > The following patch adds an overload for this case, so we can write
> > it in a shorter way.  It isn't worth for 3+, code in that case
> > typically uses the fndecl_built_in_p (node, BUILT_IN_NORMAL)
> > + switch in DECL_FUNCTION_CODE.
> >
> > If this isn't appropriate for GCC 13 (or not at all), I think we'll
> > need to change at least ipa-prop.cc because it suffers from the same
> > problem as the previous patch was fixing.
>
> Is it possible to use C++ (template) magic to expand the > 1 argument
> case to
>
>   if (fndecl_built_in_p (BUILT_IN_NORMA)
>       && (... || ... || ...
>
> lispy we'd expand to the head check and then recursively on the
> first and the remaining args.

In C++17 yes, there are fold expressions, so you'd write it as literally:

if (fndecl_built_in_p (BUILT_IN_NORMA)
      && (DECL_FUNCTION_CODE (node) == name || ...)

Where "name" is a parameter pack, and the "..." is literally what the
code would contain, not an abbreviation for the example :-)

For C++11 you can write it recursively. Something like:


// Single argument case terminates recursion.
inline bool
fndecl_built_in_matches_name_p (const_tree node, built_in_function name1)
{
  return DECL_FUNCTION_CODE (node) == name1;
}

// Recursive case. If names... is an empty pack then the overload above
// is a better match.
template<typename... Functions>
inline bool
fndecl_built_in_matches_name_p (const_tree node, built_in_function name1,
                Functions... names)
{
  return DECL_FUNCTION_CODE (node) == name1
           || fndecl_built_in_matches_name_p (node, names...);
}

// Call with one or more names.
template<typename... Functions>
inline bool
fndecl_built_in_p (const_tree node, built_in_function name1,
                Functions names...)
{
  return (fndecl_built_in_p (node, BUILT_IN_NORMAL)
       && fndecl_built_in_matches_name_p (node, name1, names...);
}

I think the "is a better match" comment is the status of C++ after a
DR, so might not actually be true in C++11 with GCC 4.8, I can check
that (and if needed, rewrite the recursive case to avoid the problem).


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] tree: Add 3 argument fndecl_built_in_p
  2023-02-22 12:16       ` Jonathan Wakely
@ 2023-02-22 12:35         ` Jonathan Wakely
  2023-02-22 18:33           ` [PATCH] tree, v2: " Jakub Jelinek
  2023-02-22 12:49         ` [PATCH] tree: Add 3 argument fndecl_built_in_p Richard Biener
  1 sibling, 1 reply; 11+ messages in thread
From: Jonathan Wakely @ 2023-02-22 12:35 UTC (permalink / raw)
  To: Richard Biener; +Cc: Jakub Jelinek, gcc-patches

On Wed, 22 Feb 2023 at 12:16, Jonathan Wakely <jwakely@redhat.com> wrote:
>
> On Wed, 22 Feb 2023 at 11:49, Richard Biener <rguenther@suse.de> wrote:
> >
> > On Wed, 22 Feb 2023, Jakub Jelinek wrote:
> >
> > > On Wed, Feb 22, 2023 at 09:52:06AM +0000, Richard Biener wrote:
> > > > > The following testcase ICEs because we still have some spots that
> > > > > treat BUILT_IN_UNREACHABLE specially but not BUILT_IN_UNREACHABLE_TRAP
> > > > > the same.
> > >
> > > This patch uses (fndecl_built_in_p (node, BUILT_IN_UNREACHABLE)
> > >                || fndecl_built_in_p (node, BUILT_IN_UNREACHABLE_TRAP))
> > > a lot and from grepping around, we do something like that in lots of
> > > other places, or in some spots instead as
> > > (fndecl_built_in_p (node, BUILT_IN_NORMAL)
> > >  && (DECL_FUNCTION_CODE (node) == BUILT_IN_WHATEVER1
> > >      || DECL_FUNCTION_CODE (node) == BUILT_IN_WHATEVER2))
> > > The following patch adds an overload for this case, so we can write
> > > it in a shorter way.  It isn't worth for 3+, code in that case
> > > typically uses the fndecl_built_in_p (node, BUILT_IN_NORMAL)
> > > + switch in DECL_FUNCTION_CODE.
> > >
> > > If this isn't appropriate for GCC 13 (or not at all), I think we'll
> > > need to change at least ipa-prop.cc because it suffers from the same
> > > problem as the previous patch was fixing.
> >
> > Is it possible to use C++ (template) magic to expand the > 1 argument
> > case to
> >
> >   if (fndecl_built_in_p (BUILT_IN_NORMA)
> >       && (... || ... || ...
> >
> > lispy we'd expand to the head check and then recursively on the
> > first and the remaining args.
>
> In C++17 yes, there are fold expressions, so you'd write it as literally:
>
> if (fndecl_built_in_p (BUILT_IN_NORMA)
>       && (DECL_FUNCTION_CODE (node) == name || ...)
>
> Where "name" is a parameter pack, and the "..." is literally what the
> code would contain, not an abbreviation for the example :-)
>
> For C++11 you can write it recursively. Something like:
>
>
> // Single argument case terminates recursion.
> inline bool
> fndecl_built_in_matches_name_p (const_tree node, built_in_function name1)
> {
>   return DECL_FUNCTION_CODE (node) == name1;
> }
>
> // Recursive case. If names... is an empty pack then the overload above
> // is a better match.
> template<typename... Functions>
> inline bool
> fndecl_built_in_matches_name_p (const_tree node, built_in_function name1,
>                 Functions... names)
> {
>   return DECL_FUNCTION_CODE (node) == name1
>            || fndecl_built_in_matches_name_p (node, names...);
> }
>
> // Call with one or more names.
> template<typename... Functions>
> inline bool
> fndecl_built_in_p (const_tree node, built_in_function name1,
>                 Functions names...)
> {
>   return (fndecl_built_in_p (node, BUILT_IN_NORMAL)
>        && fndecl_built_in_matches_name_p (node, name1, names...);
> }
>
> I think the "is a better match" comment is the status of C++ after a
> DR, so might not actually be true in C++11 with GCC 4.8, I can check
> that (and if needed, rewrite the recursive case to avoid the problem).

Yes, I was right, it doesn't work in gcc 4.8. This does though (with
typos above fixed too, and actually tested on GCC 4.8.5):

// Single argument case terminates recursion.
inline bool
fndecl_built_in_matches_name_p (const_tree node, built_in_function name1)
{
 return DECL_FUNCTION_CODE (node) == name1;
}

// Recursive case for two or more names.
template<typename... Functions>
inline bool
fndecl_built_in_matches_name_p (const_tree node, built_in_function name1,
                               built_in_function name2,
                               Functions... names)
{
 return DECL_FUNCTION_CODE (node) == name1
          || fndecl_built_in_matches_name_p (node, name2, names...);
}

// Call with one or more names.
template<typename... Functions>
inline bool
fndecl_built_in_p (const_tree node, built_in_function name1,
                 Functions... names)
{
 return fndecl_built_in_p (node, BUILT_IN_NORMAL)
      && fndecl_built_in_matches_name_p (node, name1, names...);
}


The variadic template fndecl_builtin_p above can replace the existing
one in gcc/tree.h and will work for all the existing cases with a
single name argument, but also support multiple names.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] tree: Add 3 argument fndecl_built_in_p
  2023-02-22 12:16       ` Jonathan Wakely
  2023-02-22 12:35         ` Jonathan Wakely
@ 2023-02-22 12:49         ` Richard Biener
  1 sibling, 0 replies; 11+ messages in thread
From: Richard Biener @ 2023-02-22 12:49 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: Richard Biener, Jakub Jelinek, gcc-patches

On Wed, Feb 22, 2023 at 1:17 PM Jonathan Wakely via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> On Wed, 22 Feb 2023 at 11:49, Richard Biener <rguenther@suse.de> wrote:
> >
> > On Wed, 22 Feb 2023, Jakub Jelinek wrote:
> >
> > > On Wed, Feb 22, 2023 at 09:52:06AM +0000, Richard Biener wrote:
> > > > > The following testcase ICEs because we still have some spots that
> > > > > treat BUILT_IN_UNREACHABLE specially but not BUILT_IN_UNREACHABLE_TRAP
> > > > > the same.
> > >
> > > This patch uses (fndecl_built_in_p (node, BUILT_IN_UNREACHABLE)
> > >                || fndecl_built_in_p (node, BUILT_IN_UNREACHABLE_TRAP))
> > > a lot and from grepping around, we do something like that in lots of
> > > other places, or in some spots instead as
> > > (fndecl_built_in_p (node, BUILT_IN_NORMAL)
> > >  && (DECL_FUNCTION_CODE (node) == BUILT_IN_WHATEVER1
> > >      || DECL_FUNCTION_CODE (node) == BUILT_IN_WHATEVER2))
> > > The following patch adds an overload for this case, so we can write
> > > it in a shorter way.  It isn't worth for 3+, code in that case
> > > typically uses the fndecl_built_in_p (node, BUILT_IN_NORMAL)
> > > + switch in DECL_FUNCTION_CODE.
> > >
> > > If this isn't appropriate for GCC 13 (or not at all), I think we'll
> > > need to change at least ipa-prop.cc because it suffers from the same
> > > problem as the previous patch was fixing.
> >
> > Is it possible to use C++ (template) magic to expand the > 1 argument
> > case to
> >
> >   if (fndecl_built_in_p (BUILT_IN_NORMA)
> >       && (... || ... || ...
> >
> > lispy we'd expand to the head check and then recursively on the
> > first and the remaining args.
>
> In C++17 yes, there are fold expressions, so you'd write it as literally:
>
> if (fndecl_built_in_p (BUILT_IN_NORMA)
>       && (DECL_FUNCTION_CODE (node) == name || ...)
>
> Where "name" is a parameter pack, and the "..." is literally what the
> code would contain, not an abbreviation for the example :-)

Ah, that's nice.  But then I'd need to replace each arg with
DECL_FUNCTION_CODE (node) == arg, fold expressions seem to
only support literal replacement here?

> For C++11 you can write it recursively. Something like:

But sure, we're C++11 only ...

>
> // Single argument case terminates recursion.
> inline bool
> fndecl_built_in_matches_name_p (const_tree node, built_in_function name1)
> {
>   return DECL_FUNCTION_CODE (node) == name1;
> }
>
> // Recursive case. If names... is an empty pack then the overload above
> // is a better match.
> template<typename... Functions>
> inline bool
> fndecl_built_in_matches_name_p (const_tree node, built_in_function name1,
>                 Functions... names)
> {
>   return DECL_FUNCTION_CODE (node) == name1
>            || fndecl_built_in_matches_name_p (node, names...);
> }
>
> // Call with one or more names.
> template<typename... Functions>
> inline bool
> fndecl_built_in_p (const_tree node, built_in_function name1,
>                 Functions names...)
> {
>   return (fndecl_built_in_p (node, BUILT_IN_NORMAL)
>        && fndecl_built_in_matches_name_p (node, name1, names...);
> }
>
> I think the "is a better match" comment is the status of C++ after a
> DR, so might not actually be true in C++11 with GCC 4.8, I can check
> that (and if needed, rewrite the recursive case to avoid the problem).
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] tree, v2: Add 3 argument fndecl_built_in_p
  2023-02-22 12:35         ` Jonathan Wakely
@ 2023-02-22 18:33           ` Jakub Jelinek
  2023-02-22 18:46             ` Richard Biener
  0 siblings, 1 reply; 11+ messages in thread
From: Jakub Jelinek @ 2023-02-22 18:33 UTC (permalink / raw)
  To: Richard Biener, Jonathan Wakely; +Cc: gcc-patches

On Wed, Feb 22, 2023 at 12:35:24PM +0000, Jonathan Wakely wrote:
> Yes, I was right, it doesn't work in gcc 4.8. This does though (with
> typos above fixed too, and actually tested on GCC 4.8.5):

I think we don't need the DECL_FUNCTION_CODE (node) in every recursive call,
we can just pass DECL_FUNCTION_CODE (node) down instead.

The following patch does that, tested again also with gcc 4.8:

2023-02-22  Jakub Jelinek  <jakub@redhat.com>
	    Jonathan Wakely  <jwakely@redhat.com>

	* tree.h (built_in_function_equal_p): New helper function.
	(fndecl_built_in_p): Turn into variadic template to support
	1 or more built_in_function arguments.
	* builtins.cc (fold_builtin_expect): Use 3 argument fndecl_built_in_p.
	* gimplify.cc (goa_stabilize_expr): Likewise.
	* cgraphclones.cc (cgraph_node::create_clone): Likewise.
	* ipa-fnsummary.cc (compute_fn_summary): Likewise.
	* omp-low.cc (setjmp_or_longjmp_p): Likewise.
	* cgraph.cc (cgraph_edge::redirect_call_stmt_to_callee,
	cgraph_update_edges_for_call_stmt_node,
	cgraph_edge::verify_corresponds_to_fndecl,
	cgraph_node::verify_node): Likewise.
	* tree-stdarg.cc (optimize_va_list_gpr_fpr_size): Likewise.
	* gimple-ssa-warn-access.cc (matching_alloc_calls_p): Likewise.
	* ipa-prop.cc (try_make_edge_direct_virtual_call): Handle
	BUILT_IN_UNREACHABLE_TRAP like BUILT_IN_UNREACHABLE.

--- gcc/tree.h.jj	2023-02-17 12:45:08.223636043 +0100
+++ gcc/tree.h	2023-02-22 17:10:57.410410020 +0100
@@ -6575,6 +6575,24 @@ type_has_mode_precision_p (const_tree t)
   return known_eq (TYPE_PRECISION (t), GET_MODE_PRECISION (TYPE_MODE (t)));
 }
 
+/* Helper functions for fndecl_built_in_p.  */
+
+inline bool
+built_in_function_equal_p (built_in_function name0, built_in_function name1)
+{
+ return name0 == name1;
+}
+
+/* Recursive case for two or more names.  */
+
+template <typename... F>
+inline bool
+built_in_function_equal_p (built_in_function name0, built_in_function name1,
+			   built_in_function name2, F... names)
+{
+ return name0 == name1 || built_in_function_equal_p (name0, name2, names...);
+}
+
 /* Return true if a FUNCTION_DECL NODE is a GCC built-in function.
 
    Note that it is different from the DECL_IS_UNDECLARED_BUILTIN
@@ -6606,13 +6624,16 @@ fndecl_built_in_p (const_tree node, unsi
 }
 
 /* Return true if a FUNCTION_DECL NODE is a GCC built-in function
-   of BUILT_IN_NORMAL class with name equal to NAME.  */
+   of BUILT_IN_NORMAL class with name equal to NAME1 (or other mentioned
+   NAMES).  */
 
+template <typename... F>
 inline bool
-fndecl_built_in_p (const_tree node, built_in_function name)
+fndecl_built_in_p (const_tree node, built_in_function name1, F... names)
 {
   return (fndecl_built_in_p (node, BUILT_IN_NORMAL)
-	  && DECL_FUNCTION_CODE (node) == name);
+	  && built_in_function_equal_p (DECL_FUNCTION_CODE (node),
+					name1, names...));
 }
 
 /* A struct for encapsulating location information about an operator
--- gcc/builtins.cc.jj	2023-02-14 12:09:57.163647987 +0100
+++ gcc/builtins.cc	2023-02-22 11:29:43.800179949 +0100
@@ -8625,8 +8625,8 @@ fold_builtin_expect (location_t loc, tre
 
   if (TREE_CODE (inner) == CALL_EXPR
       && (fndecl = get_callee_fndecl (inner))
-      && (fndecl_built_in_p (fndecl, BUILT_IN_EXPECT)
-	  || fndecl_built_in_p (fndecl, BUILT_IN_EXPECT_WITH_PROBABILITY)))
+      && fndecl_built_in_p (fndecl, BUILT_IN_EXPECT,
+			    BUILT_IN_EXPECT_WITH_PROBABILITY))
     return arg0;
 
   inner = inner_arg0;
--- gcc/gimplify.cc.jj	2023-02-15 09:23:27.807390189 +0100
+++ gcc/gimplify.cc	2023-02-22 11:32:38.446655528 +0100
@@ -15815,8 +15815,8 @@ goa_stabilize_expr (tree *expr_p, gimple
       if (TREE_CODE (expr) == CALL_EXPR)
 	{
 	  if (tree fndecl = get_callee_fndecl (expr))
-	    if (fndecl_built_in_p (fndecl, BUILT_IN_CLEAR_PADDING)
-		|| fndecl_built_in_p (fndecl, BUILT_IN_MEMCMP))
+	    if (fndecl_built_in_p (fndecl, BUILT_IN_CLEAR_PADDING,
+					   BUILT_IN_MEMCMP))
 	      {
 		int nargs = call_expr_nargs (expr);
 		for (int i = 0; i < nargs; i++)
--- gcc/cgraphclones.cc.jj	2023-02-22 11:21:56.467934980 +0100
+++ gcc/cgraphclones.cc	2023-02-22 11:28:30.272242754 +0100
@@ -425,9 +425,8 @@ cgraph_node::create_clone (tree new_decl
 	 version.  The only exception is when the edge was proved to
 	 be unreachable during the cloning procedure.  */
       if (!e->callee
-	  || !(fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
-	       || fndecl_built_in_p (e->callee->decl,
-				     BUILT_IN_UNREACHABLE_TRAP)))
+	  || !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
+						  BUILT_IN_UNREACHABLE_TRAP))
         e->redirect_callee_duplicating_thunks (new_node);
     }
   new_node->expand_all_artificial_thunks ();
--- gcc/ipa-fnsummary.cc.jj	2023-01-02 09:32:45.510951148 +0100
+++ gcc/ipa-fnsummary.cc	2023-02-22 11:33:07.922229473 +0100
@@ -3180,8 +3180,8 @@ compute_fn_summary (struct cgraph_node *
 	       for (e = node->callees; e; e = e->next_callee)
 		 {
 		   tree cdecl = e->callee->decl;
-		   if (fndecl_built_in_p (cdecl, BUILT_IN_APPLY_ARGS)
-		       || fndecl_built_in_p (cdecl, BUILT_IN_VA_START))
+		   if (fndecl_built_in_p (cdecl, BUILT_IN_APPLY_ARGS,
+						 BUILT_IN_VA_START))
 		     break;
 		 }
 	       node->can_change_signature = !e;
--- gcc/omp-low.cc.jj	2023-01-02 09:32:25.281243440 +0100
+++ gcc/omp-low.cc	2023-02-22 11:35:06.418516664 +0100
@@ -3992,8 +3992,7 @@ scan_omp_1_op (tree *tp, int *walk_subtr
 static bool
 setjmp_or_longjmp_p (const_tree fndecl)
 {
-  if (fndecl_built_in_p (fndecl, BUILT_IN_SETJMP)
-      || fndecl_built_in_p (fndecl, BUILT_IN_LONGJMP))
+  if (fndecl_built_in_p (fndecl, BUILT_IN_SETJMP, BUILT_IN_LONGJMP))
     return true;
 
   tree declname = DECL_NAME (fndecl);
--- gcc/cgraph.cc.jj	2023-02-22 11:21:56.466934995 +0100
+++ gcc/cgraph.cc	2023-02-22 11:27:29.907115300 +0100
@@ -1548,8 +1548,8 @@ cgraph_edge::redirect_call_stmt_to_calle
   else
     {
       if (flag_checking
-	  && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
-	  && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE_TRAP))
+	  && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
+						  BUILT_IN_UNREACHABLE_TRAP))
 	ipa_verify_edge_has_no_modifications (e);
       new_stmt = e->call_stmt;
       gimple_call_set_fndecl (new_stmt, e->callee->decl);
@@ -1635,9 +1635,8 @@ cgraph_update_edges_for_call_stmt_node (
 	{
 	  /* Keep calls marked as dead dead.  */
 	  if (new_stmt && is_gimple_call (new_stmt) && e->callee
-	      && (fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
-		  || fndecl_built_in_p (e->callee->decl,
-					BUILT_IN_UNREACHABLE_TRAP)))
+	      && fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
+				    BUILT_IN_UNREACHABLE_TRAP))
 	    {
 	      cgraph_edge::set_call_stmt (node->get_edge (old_stmt),
 					  as_a <gcall *> (new_stmt));
@@ -3259,9 +3258,8 @@ cgraph_edge::verify_corresponds_to_fndec
   /* Optimizers can redirect unreachable calls or calls triggering undefined
      behavior to __builtin_unreachable or __builtin_unreachable trap.  */
 
-  if (fndecl_built_in_p (callee->decl, BUILT_IN_NORMAL)
-      && (DECL_FUNCTION_CODE (callee->decl) == BUILT_IN_UNREACHABLE
-	  || DECL_FUNCTION_CODE (callee->decl) == BUILT_IN_UNREACHABLE_TRAP))
+  if (fndecl_built_in_p (callee->decl, BUILT_IN_UNREACHABLE,
+				       BUILT_IN_UNREACHABLE_TRAP))
     return false;
 
   if (callee->former_clone_of != node->decl
@@ -3601,9 +3599,8 @@ cgraph_node::verify_node (void)
 	  /* Optimized out calls are redirected to __builtin_unreachable.  */
 	  && (e->count.nonzero_p ()
 	      || ! e->callee->decl
-	      || !(fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
-		   || fndecl_built_in_p (e->callee->decl,
-					 BUILT_IN_UNREACHABLE_TRAP)))
+	      || !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
+				     BUILT_IN_UNREACHABLE_TRAP))
 	  && count
 	      == ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (decl))->count
 	  && (!e->count.ipa_p ()
--- gcc/tree-stdarg.cc.jj	2023-01-02 09:32:24.970247934 +0100
+++ gcc/tree-stdarg.cc	2023-02-22 11:38:22.383684097 +0100
@@ -867,8 +867,8 @@ optimize_va_list_gpr_fpr_size (function
 	      tree callee = gimple_call_fndecl (stmt);
 
 	      if (callee
-		  && (fndecl_built_in_p (callee, BUILT_IN_VA_START)
-		      || fndecl_built_in_p (callee, BUILT_IN_VA_END)))
+		  && fndecl_built_in_p (callee, BUILT_IN_VA_START,
+						BUILT_IN_VA_END))
 		continue;
 	    }
 
--- gcc/gimple-ssa-warn-access.cc.jj	2023-02-16 10:13:23.822208868 +0100
+++ gcc/gimple-ssa-warn-access.cc	2023-02-22 11:31:36.168555726 +0100
@@ -1780,8 +1780,7 @@ matching_alloc_calls_p (tree alloc_decl,
 
       /* Return false for deallocation functions that are known not
 	 to match.  */
-      if (fndecl_built_in_p (dealloc_decl, BUILT_IN_FREE)
-	  || fndecl_built_in_p (dealloc_decl, BUILT_IN_REALLOC))
+      if (fndecl_built_in_p (dealloc_decl, BUILT_IN_FREE, BUILT_IN_REALLOC))
 	return false;
       /* Otherwise proceed below to check the deallocation function's
 	 "*dealloc" attributes to look for one that mentions this operator
@@ -1805,8 +1804,8 @@ matching_alloc_calls_p (tree alloc_decl,
 	  if (DECL_IS_OPERATOR_DELETE_P (dealloc_decl))
 	    return false;
 
-	  if (fndecl_built_in_p (dealloc_decl, BUILT_IN_FREE)
-	      || fndecl_built_in_p (dealloc_decl, BUILT_IN_REALLOC))
+	  if (fndecl_built_in_p (dealloc_decl, BUILT_IN_FREE,
+					       BUILT_IN_REALLOC))
 	    return true;
 
 	  alloc_dealloc_kind = alloc_kind_t::builtin;
--- gcc/ipa-prop.cc.jj	2023-01-02 09:32:46.077942956 +0100
+++ gcc/ipa-prop.cc	2023-02-22 11:34:15.572251634 +0100
@@ -3849,7 +3849,8 @@ try_make_edge_direct_virtual_call (struc
 	  if (can_refer)
 	    {
 	      if (!t
-		  || fndecl_built_in_p (t, BUILT_IN_UNREACHABLE)
+		  || fndecl_built_in_p (t, BUILT_IN_UNREACHABLE,
+					   BUILT_IN_UNREACHABLE_TRAP)
 		  || !possible_polymorphic_call_target_p
 		       (ie, cgraph_node::get (t)))
 		{


	Jakub


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] tree, v2: Add 3 argument fndecl_built_in_p
  2023-02-22 18:33           ` [PATCH] tree, v2: " Jakub Jelinek
@ 2023-02-22 18:46             ` Richard Biener
  2023-02-23  6:56               ` [PATCH] ipa-prop: Fix another case of missing BUILT_IN_UNREACHABLE_TRAP handling [PR106258] Jakub Jelinek
  0 siblings, 1 reply; 11+ messages in thread
From: Richard Biener @ 2023-02-22 18:46 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Richard Biener, Jonathan Wakely, gcc-patches



> Am 22.02.2023 um 19:34 schrieb Jakub Jelinek <jakub@redhat.com>:
> 
> On Wed, Feb 22, 2023 at 12:35:24PM +0000, Jonathan Wakely wrote:
>> Yes, I was right, it doesn't work in gcc 4.8. This does though (with
>> typos above fixed too, and actually tested on GCC 4.8.5):
> 
> I think we don't need the DECL_FUNCTION_CODE (node) in every recursive call,
> we can just pass DECL_FUNCTION_CODE (node) down instead.
> 
> The following patch does that, tested again also with gcc 4.8:

Ok for stage1

Thanks,
Richard 

> 2023-02-22  Jakub Jelinek  <jakub@redhat.com>
>        Jonathan Wakely  <jwakely@redhat.com>
> 
>    * tree.h (built_in_function_equal_p): New helper function.
>    (fndecl_built_in_p): Turn into variadic template to support
>    1 or more built_in_function arguments.
>    * builtins.cc (fold_builtin_expect): Use 3 argument fndecl_built_in_p.
>    * gimplify.cc (goa_stabilize_expr): Likewise.
>    * cgraphclones.cc (cgraph_node::create_clone): Likewise.
>    * ipa-fnsummary.cc (compute_fn_summary): Likewise.
>    * omp-low.cc (setjmp_or_longjmp_p): Likewise.
>    * cgraph.cc (cgraph_edge::redirect_call_stmt_to_callee,
>    cgraph_update_edges_for_call_stmt_node,
>    cgraph_edge::verify_corresponds_to_fndecl,
>    cgraph_node::verify_node): Likewise.
>    * tree-stdarg.cc (optimize_va_list_gpr_fpr_size): Likewise.
>    * gimple-ssa-warn-access.cc (matching_alloc_calls_p): Likewise.
>    * ipa-prop.cc (try_make_edge_direct_virtual_call): Handle
>    BUILT_IN_UNREACHABLE_TRAP like BUILT_IN_UNREACHABLE.
> 
> --- gcc/tree.h.jj    2023-02-17 12:45:08.223636043 +0100
> +++ gcc/tree.h    2023-02-22 17:10:57.410410020 +0100
> @@ -6575,6 +6575,24 @@ type_has_mode_precision_p (const_tree t)
>   return known_eq (TYPE_PRECISION (t), GET_MODE_PRECISION (TYPE_MODE (t)));
> }
> 
> +/* Helper functions for fndecl_built_in_p.  */
> +
> +inline bool
> +built_in_function_equal_p (built_in_function name0, built_in_function name1)
> +{
> + return name0 == name1;
> +}
> +
> +/* Recursive case for two or more names.  */
> +
> +template <typename... F>
> +inline bool
> +built_in_function_equal_p (built_in_function name0, built_in_function name1,
> +               built_in_function name2, F... names)
> +{
> + return name0 == name1 || built_in_function_equal_p (name0, name2, names...);
> +}
> +
> /* Return true if a FUNCTION_DECL NODE is a GCC built-in function.
> 
>    Note that it is different from the DECL_IS_UNDECLARED_BUILTIN
> @@ -6606,13 +6624,16 @@ fndecl_built_in_p (const_tree node, unsi
> }
> 
> /* Return true if a FUNCTION_DECL NODE is a GCC built-in function
> -   of BUILT_IN_NORMAL class with name equal to NAME.  */
> +   of BUILT_IN_NORMAL class with name equal to NAME1 (or other mentioned
> +   NAMES).  */
> 
> +template <typename... F>
> inline bool
> -fndecl_built_in_p (const_tree node, built_in_function name)
> +fndecl_built_in_p (const_tree node, built_in_function name1, F... names)
> {
>   return (fndecl_built_in_p (node, BUILT_IN_NORMAL)
> -      && DECL_FUNCTION_CODE (node) == name);
> +      && built_in_function_equal_p (DECL_FUNCTION_CODE (node),
> +                    name1, names...));
> }
> 
> /* A struct for encapsulating location information about an operator
> --- gcc/builtins.cc.jj    2023-02-14 12:09:57.163647987 +0100
> +++ gcc/builtins.cc    2023-02-22 11:29:43.800179949 +0100
> @@ -8625,8 +8625,8 @@ fold_builtin_expect (location_t loc, tre
> 
>   if (TREE_CODE (inner) == CALL_EXPR
>       && (fndecl = get_callee_fndecl (inner))
> -      && (fndecl_built_in_p (fndecl, BUILT_IN_EXPECT)
> -      || fndecl_built_in_p (fndecl, BUILT_IN_EXPECT_WITH_PROBABILITY)))
> +      && fndecl_built_in_p (fndecl, BUILT_IN_EXPECT,
> +                BUILT_IN_EXPECT_WITH_PROBABILITY))
>     return arg0;
> 
>   inner = inner_arg0;
> --- gcc/gimplify.cc.jj    2023-02-15 09:23:27.807390189 +0100
> +++ gcc/gimplify.cc    2023-02-22 11:32:38.446655528 +0100
> @@ -15815,8 +15815,8 @@ goa_stabilize_expr (tree *expr_p, gimple
>       if (TREE_CODE (expr) == CALL_EXPR)
>    {
>      if (tree fndecl = get_callee_fndecl (expr))
> -        if (fndecl_built_in_p (fndecl, BUILT_IN_CLEAR_PADDING)
> -        || fndecl_built_in_p (fndecl, BUILT_IN_MEMCMP))
> +        if (fndecl_built_in_p (fndecl, BUILT_IN_CLEAR_PADDING,
> +                       BUILT_IN_MEMCMP))
>          {
>        int nargs = call_expr_nargs (expr);
>        for (int i = 0; i < nargs; i++)
> --- gcc/cgraphclones.cc.jj    2023-02-22 11:21:56.467934980 +0100
> +++ gcc/cgraphclones.cc    2023-02-22 11:28:30.272242754 +0100
> @@ -425,9 +425,8 @@ cgraph_node::create_clone (tree new_decl
>     version.  The only exception is when the edge was proved to
>     be unreachable during the cloning procedure.  */
>       if (!e->callee
> -      || !(fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
> -           || fndecl_built_in_p (e->callee->decl,
> -                     BUILT_IN_UNREACHABLE_TRAP)))
> +      || !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
> +                          BUILT_IN_UNREACHABLE_TRAP))
>         e->redirect_callee_duplicating_thunks (new_node);
>     }
>   new_node->expand_all_artificial_thunks ();
> --- gcc/ipa-fnsummary.cc.jj    2023-01-02 09:32:45.510951148 +0100
> +++ gcc/ipa-fnsummary.cc    2023-02-22 11:33:07.922229473 +0100
> @@ -3180,8 +3180,8 @@ compute_fn_summary (struct cgraph_node *
>           for (e = node->callees; e; e = e->next_callee)
>         {
>           tree cdecl = e->callee->decl;
> -           if (fndecl_built_in_p (cdecl, BUILT_IN_APPLY_ARGS)
> -               || fndecl_built_in_p (cdecl, BUILT_IN_VA_START))
> +           if (fndecl_built_in_p (cdecl, BUILT_IN_APPLY_ARGS,
> +                         BUILT_IN_VA_START))
>             break;
>         }
>           node->can_change_signature = !e;
> --- gcc/omp-low.cc.jj    2023-01-02 09:32:25.281243440 +0100
> +++ gcc/omp-low.cc    2023-02-22 11:35:06.418516664 +0100
> @@ -3992,8 +3992,7 @@ scan_omp_1_op (tree *tp, int *walk_subtr
> static bool
> setjmp_or_longjmp_p (const_tree fndecl)
> {
> -  if (fndecl_built_in_p (fndecl, BUILT_IN_SETJMP)
> -      || fndecl_built_in_p (fndecl, BUILT_IN_LONGJMP))
> +  if (fndecl_built_in_p (fndecl, BUILT_IN_SETJMP, BUILT_IN_LONGJMP))
>     return true;
> 
>   tree declname = DECL_NAME (fndecl);
> --- gcc/cgraph.cc.jj    2023-02-22 11:21:56.466934995 +0100
> +++ gcc/cgraph.cc    2023-02-22 11:27:29.907115300 +0100
> @@ -1548,8 +1548,8 @@ cgraph_edge::redirect_call_stmt_to_calle
>   else
>     {
>       if (flag_checking
> -      && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
> -      && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE_TRAP))
> +      && !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
> +                          BUILT_IN_UNREACHABLE_TRAP))
>    ipa_verify_edge_has_no_modifications (e);
>       new_stmt = e->call_stmt;
>       gimple_call_set_fndecl (new_stmt, e->callee->decl);
> @@ -1635,9 +1635,8 @@ cgraph_update_edges_for_call_stmt_node (
>    {
>      /* Keep calls marked as dead dead.  */
>      if (new_stmt && is_gimple_call (new_stmt) && e->callee
> -          && (fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
> -          || fndecl_built_in_p (e->callee->decl,
> -                    BUILT_IN_UNREACHABLE_TRAP)))
> +          && fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
> +                    BUILT_IN_UNREACHABLE_TRAP))
>        {
>          cgraph_edge::set_call_stmt (node->get_edge (old_stmt),
>                      as_a <gcall *> (new_stmt));
> @@ -3259,9 +3258,8 @@ cgraph_edge::verify_corresponds_to_fndec
>   /* Optimizers can redirect unreachable calls or calls triggering undefined
>      behavior to __builtin_unreachable or __builtin_unreachable trap.  */
> 
> -  if (fndecl_built_in_p (callee->decl, BUILT_IN_NORMAL)
> -      && (DECL_FUNCTION_CODE (callee->decl) == BUILT_IN_UNREACHABLE
> -      || DECL_FUNCTION_CODE (callee->decl) == BUILT_IN_UNREACHABLE_TRAP))
> +  if (fndecl_built_in_p (callee->decl, BUILT_IN_UNREACHABLE,
> +                       BUILT_IN_UNREACHABLE_TRAP))
>     return false;
> 
>   if (callee->former_clone_of != node->decl
> @@ -3601,9 +3599,8 @@ cgraph_node::verify_node (void)
>      /* Optimized out calls are redirected to __builtin_unreachable.  */
>      && (e->count.nonzero_p ()
>          || ! e->callee->decl
> -          || !(fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE)
> -           || fndecl_built_in_p (e->callee->decl,
> -                     BUILT_IN_UNREACHABLE_TRAP)))
> +          || !fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE,
> +                     BUILT_IN_UNREACHABLE_TRAP))
>      && count
>          == ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (decl))->count
>      && (!e->count.ipa_p ()
> --- gcc/tree-stdarg.cc.jj    2023-01-02 09:32:24.970247934 +0100
> +++ gcc/tree-stdarg.cc    2023-02-22 11:38:22.383684097 +0100
> @@ -867,8 +867,8 @@ optimize_va_list_gpr_fpr_size (function
>          tree callee = gimple_call_fndecl (stmt);
> 
>          if (callee
> -          && (fndecl_built_in_p (callee, BUILT_IN_VA_START)
> -              || fndecl_built_in_p (callee, BUILT_IN_VA_END)))
> +          && fndecl_built_in_p (callee, BUILT_IN_VA_START,
> +                        BUILT_IN_VA_END))
>        continue;
>        }
> 
> --- gcc/gimple-ssa-warn-access.cc.jj    2023-02-16 10:13:23.822208868 +0100
> +++ gcc/gimple-ssa-warn-access.cc    2023-02-22 11:31:36.168555726 +0100
> @@ -1780,8 +1780,7 @@ matching_alloc_calls_p (tree alloc_decl,
> 
>       /* Return false for deallocation functions that are known not
>     to match.  */
> -      if (fndecl_built_in_p (dealloc_decl, BUILT_IN_FREE)
> -      || fndecl_built_in_p (dealloc_decl, BUILT_IN_REALLOC))
> +      if (fndecl_built_in_p (dealloc_decl, BUILT_IN_FREE, BUILT_IN_REALLOC))
>    return false;
>       /* Otherwise proceed below to check the deallocation function's
>     "*dealloc" attributes to look for one that mentions this operator
> @@ -1805,8 +1804,8 @@ matching_alloc_calls_p (tree alloc_decl,
>      if (DECL_IS_OPERATOR_DELETE_P (dealloc_decl))
>        return false;
> 
> -      if (fndecl_built_in_p (dealloc_decl, BUILT_IN_FREE)
> -          || fndecl_built_in_p (dealloc_decl, BUILT_IN_REALLOC))
> +      if (fndecl_built_in_p (dealloc_decl, BUILT_IN_FREE,
> +                           BUILT_IN_REALLOC))
>        return true;
> 
>      alloc_dealloc_kind = alloc_kind_t::builtin;
> --- gcc/ipa-prop.cc.jj    2023-01-02 09:32:46.077942956 +0100
> +++ gcc/ipa-prop.cc    2023-02-22 11:34:15.572251634 +0100
> @@ -3849,7 +3849,8 @@ try_make_edge_direct_virtual_call (struc
>      if (can_refer)
>        {
>          if (!t
> -          || fndecl_built_in_p (t, BUILT_IN_UNREACHABLE)
> +          || fndecl_built_in_p (t, BUILT_IN_UNREACHABLE,
> +                       BUILT_IN_UNREACHABLE_TRAP)
>          || !possible_polymorphic_call_target_p
>               (ie, cgraph_node::get (t)))
>        {
> 
> 
>    Jakub
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] ipa-prop: Fix another case of missing BUILT_IN_UNREACHABLE_TRAP handling [PR106258]
  2023-02-22 18:46             ` Richard Biener
@ 2023-02-23  6:56               ` Jakub Jelinek
  2023-02-23 10:33                 ` Richard Biener
  0 siblings, 1 reply; 11+ messages in thread
From: Jakub Jelinek @ 2023-02-23  6:56 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

On Wed, Feb 22, 2023 at 07:46:46PM +0100, Richard Biener wrote:
> Ok for stage1

Thanks.  In that case, can we get at least following into GCC 13,
another spot that handles in IPA just BUILT_IN_UNREACHABLE and
not BUILT_IN_UNREACHABLE_TRAP?

Bootstrapped/regtested on x86_64-linux and i686-linux.

2023-02-23  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/106258
	* ipa-prop.cc (try_make_edge_direct_virtual_call): Handle
	BUILT_IN_UNREACHABLE_TRAP like BUILT_IN_UNREACHABLE.

--- gcc/ipa-prop.cc.jj	2023-02-22 20:50:27.422519757 +0100
+++ gcc/ipa-prop.cc	2023-02-22 20:52:04.904112685 +0100
@@ -3850,6 +3850,7 @@ try_make_edge_direct_virtual_call (struc
 	    {
 	      if (!t
 		  || fndecl_built_in_p (t, BUILT_IN_UNREACHABLE)
+		  || fndecl_built_in_p (t, BUILT_IN_UNREACHABLE_TRAP)
 		  || !possible_polymorphic_call_target_p
 		       (ie, cgraph_node::get (t)))
 		{


	Jakub


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] ipa-prop: Fix another case of missing BUILT_IN_UNREACHABLE_TRAP handling [PR106258]
  2023-02-23  6:56               ` [PATCH] ipa-prop: Fix another case of missing BUILT_IN_UNREACHABLE_TRAP handling [PR106258] Jakub Jelinek
@ 2023-02-23 10:33                 ` Richard Biener
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Biener @ 2023-02-23 10:33 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On Thu, Feb 23, 2023 at 7:56 AM Jakub Jelinek <jakub@redhat.com> wrote:
>
> On Wed, Feb 22, 2023 at 07:46:46PM +0100, Richard Biener wrote:
> > Ok for stage1
>
> Thanks.  In that case, can we get at least following into GCC 13,
> another spot that handles in IPA just BUILT_IN_UNREACHABLE and
> not BUILT_IN_UNREACHABLE_TRAP?

Sure.

> Bootstrapped/regtested on x86_64-linux and i686-linux.
>
> 2023-02-23  Jakub Jelinek  <jakub@redhat.com>
>
>         PR middle-end/106258
>         * ipa-prop.cc (try_make_edge_direct_virtual_call): Handle
>         BUILT_IN_UNREACHABLE_TRAP like BUILT_IN_UNREACHABLE.
>
> --- gcc/ipa-prop.cc.jj  2023-02-22 20:50:27.422519757 +0100
> +++ gcc/ipa-prop.cc     2023-02-22 20:52:04.904112685 +0100
> @@ -3850,6 +3850,7 @@ try_make_edge_direct_virtual_call (struc
>             {
>               if (!t
>                   || fndecl_built_in_p (t, BUILT_IN_UNREACHABLE)
> +                 || fndecl_built_in_p (t, BUILT_IN_UNREACHABLE_TRAP)
>                   || !possible_polymorphic_call_target_p
>                        (ie, cgraph_node::get (t)))
>                 {
>
>
>         Jakub
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-02-23 10:34 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-22  9:12 [PATCH] cgraph: Handle BUILT_IN_UNREACHABLE_TRAP like BUILT_IN_UNREACHABLE in more spots [PR106258] Jakub Jelinek
2023-02-22  9:52 ` Richard Biener
2023-02-22 11:04   ` [PATCH] tree: Add 3 argument fndecl_built_in_p Jakub Jelinek
2023-02-22 11:43     ` Richard Biener
2023-02-22 12:16       ` Jonathan Wakely
2023-02-22 12:35         ` Jonathan Wakely
2023-02-22 18:33           ` [PATCH] tree, v2: " Jakub Jelinek
2023-02-22 18:46             ` Richard Biener
2023-02-23  6:56               ` [PATCH] ipa-prop: Fix another case of missing BUILT_IN_UNREACHABLE_TRAP handling [PR106258] Jakub Jelinek
2023-02-23 10:33                 ` Richard Biener
2023-02-22 12:49         ` [PATCH] tree: Add 3 argument fndecl_built_in_p Richard Biener

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).