ipa-split: Don't split returns_twice functions [PR106923]

Message ID Y+IO2AZAm6WPtrQh@tucnak
State New
Headers
Series ipa-split: Don't split returns_twice functions [PR106923] |

Commit Message

Jakub Jelinek Feb. 7, 2023, 8:42 a.m. UTC
  Hi!

As discussed in the PR, returns_twice functions are rare/special beasts
that need special treatment in the cfg, and inside of their bodies
we don't know which part actually works the weird returns twice way
(either in the fork/vfork sense, or in the setjmp) and aren't updating
ab edges to reflect that.

I think easiest is just to never split these, like we already never
split noreturn or malloc functions.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

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

	PR tree-optimization/106923
	* ipa-split.cc (execute_split_functions): Don't split returns_twice
	functions.

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


	Jakub
  

Comments

Richard Biener Feb. 7, 2023, 9:26 a.m. UTC | #1
> Am 07.02.2023 um 09:42 schrieb Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org>:
> 
> Hi!
> 
> As discussed in the PR, returns_twice functions are rare/special beasts
> that need special treatment in the cfg, and inside of their bodies
> we don't know which part actually works the weird returns twice way
> (either in the fork/vfork sense, or in the setjmp) and aren't updating
> ab edges to reflect that.
> 
> I think easiest is just to never split these, like we already never
> split noreturn or malloc functions.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok.

Richard 

> 2023-02-07  Jakub Jelinek  <jakub@redhat.com>
> 
>    PR tree-optimization/106923
>    * ipa-split.cc (execute_split_functions): Don't split returns_twice
>    functions.
> 
>    * gcc.dg/pr106923.c: New test.
> 
> --- gcc/ipa-split.cc.jj    2023-01-02 09:32:22.492283737 +0100
> +++ gcc/ipa-split.cc    2023-02-06 14:15:08.343271251 +0100
> @@ -1715,10 +1715,11 @@ execute_split_functions (void)
>   struct cgraph_node *node = cgraph_node::get (current_function_decl);
> 
>   if (flags_from_decl_or_type (current_function_decl)
> -      & (ECF_NORETURN|ECF_MALLOC))
> +      & (ECF_NORETURN|ECF_MALLOC|ECF_RETURNS_TWICE))
>     {
>       if (dump_file)
> -    fprintf (dump_file, "Not splitting: noreturn/malloc function.\n");
> +    fprintf (dump_file, "Not splitting: noreturn/malloc/returns_twice "
> +                "function.\n");
>       return 0;
>     }
>   if (MAIN_NAME_P (DECL_NAME (current_function_decl)))
> --- gcc/testsuite/gcc.dg/pr106923.c.jj    2023-02-06 14:19:33.464449400 +0100
> +++ gcc/testsuite/gcc.dg/pr106923.c    2023-02-06 14:18:25.498429162 +0100
> @@ -0,0 +1,23 @@
> +/* PR tree-optimization/106923 */
> +/* { dg-do compile } */
> +/* { dg-options "-O1 -finline-small-functions -fpartial-inlining --param max-inline-insns-single=1 --param uninlined-function-insns=10000" } */
> +
> +int n;
> +
> +int
> +baz (void);
> +
> +__attribute__ ((returns_twice)) int
> +bar (void)
> +{
> +  if (baz ())
> +    ++n;
> +
> +  return 0;
> +}
> +
> +int
> +foo (void)
> +{
> +  return bar ();
> +}
> 
>    Jakub
>
  
Jan Hubicka Feb. 8, 2023, 5:05 p.m. UTC | #2
> Hi!
> 
> As discussed in the PR, returns_twice functions are rare/special beasts
> that need special treatment in the cfg, and inside of their bodies
> we don't know which part actually works the weird returns twice way
> (either in the fork/vfork sense, or in the setjmp) and aren't updating
> ab edges to reflect that.
> 
> I think easiest is just to never split these, like we already never
> split noreturn or malloc functions.

I think so too - anyone who puts returns twice function on the hot path
should be punished.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2023-02-07  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR tree-optimization/106923
> 	* ipa-split.cc (execute_split_functions): Don't split returns_twice
> 	functions.
> 
> 	* gcc.dg/pr106923.c: New test.
OK,
Thanks!
Honza
> 
> --- gcc/ipa-split.cc.jj	2023-01-02 09:32:22.492283737 +0100
> +++ gcc/ipa-split.cc	2023-02-06 14:15:08.343271251 +0100
> @@ -1715,10 +1715,11 @@ execute_split_functions (void)
>    struct cgraph_node *node = cgraph_node::get (current_function_decl);
>  
>    if (flags_from_decl_or_type (current_function_decl)
> -      & (ECF_NORETURN|ECF_MALLOC))
> +      & (ECF_NORETURN|ECF_MALLOC|ECF_RETURNS_TWICE))
>      {
>        if (dump_file)
> -	fprintf (dump_file, "Not splitting: noreturn/malloc function.\n");
> +	fprintf (dump_file, "Not splitting: noreturn/malloc/returns_twice "
> +			    "function.\n");
>        return 0;
>      }
>    if (MAIN_NAME_P (DECL_NAME (current_function_decl)))
> --- gcc/testsuite/gcc.dg/pr106923.c.jj	2023-02-06 14:19:33.464449400 +0100
> +++ gcc/testsuite/gcc.dg/pr106923.c	2023-02-06 14:18:25.498429162 +0100
> @@ -0,0 +1,23 @@
> +/* PR tree-optimization/106923 */
> +/* { dg-do compile } */
> +/* { dg-options "-O1 -finline-small-functions -fpartial-inlining --param max-inline-insns-single=1 --param uninlined-function-insns=10000" } */
> +
> +int n;
> +
> +int
> +baz (void);
> +
> +__attribute__ ((returns_twice)) int
> +bar (void)
> +{
> +  if (baz ())
> +    ++n;
> +
> +  return 0;
> +}
> +
> +int
> +foo (void)
> +{
> +  return bar ();
> +}
> 
> 	Jakub
>
  

Patch

--- gcc/ipa-split.cc.jj	2023-01-02 09:32:22.492283737 +0100
+++ gcc/ipa-split.cc	2023-02-06 14:15:08.343271251 +0100
@@ -1715,10 +1715,11 @@  execute_split_functions (void)
   struct cgraph_node *node = cgraph_node::get (current_function_decl);
 
   if (flags_from_decl_or_type (current_function_decl)
-      & (ECF_NORETURN|ECF_MALLOC))
+      & (ECF_NORETURN|ECF_MALLOC|ECF_RETURNS_TWICE))
     {
       if (dump_file)
-	fprintf (dump_file, "Not splitting: noreturn/malloc function.\n");
+	fprintf (dump_file, "Not splitting: noreturn/malloc/returns_twice "
+			    "function.\n");
       return 0;
     }
   if (MAIN_NAME_P (DECL_NAME (current_function_decl)))
--- gcc/testsuite/gcc.dg/pr106923.c.jj	2023-02-06 14:19:33.464449400 +0100
+++ gcc/testsuite/gcc.dg/pr106923.c	2023-02-06 14:18:25.498429162 +0100
@@ -0,0 +1,23 @@ 
+/* PR tree-optimization/106923 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -finline-small-functions -fpartial-inlining --param max-inline-insns-single=1 --param uninlined-function-insns=10000" } */
+
+int n;
+
+int
+baz (void);
+
+__attribute__ ((returns_twice)) int
+bar (void)
+{
+  if (baz ())
+    ++n;
+
+  return 0;
+}
+
+int
+foo (void)
+{
+  return bar ();
+}