public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] predict: Don't emit -Wsuggest-attribute=cold warning for functions which already have that attribute [PR105685]
@ 2023-03-25  9:53 Jakub Jelinek
  2023-03-26 17:57 ` Jeff Law
  2023-03-26 20:01 ` Jan Hubicka
  0 siblings, 2 replies; 3+ messages in thread
From: Jakub Jelinek @ 2023-03-25  9:53 UTC (permalink / raw)
  To: Richard Biener, Jan Hubicka; +Cc: gcc-patches

Hi!

In the following testcase, we predict baz to have cold
entry regardless of the user supplied attribute (as it call
unconditionally a cold function), but still issue
a -Wsuggest-attribute=cold warning despite it having that attribute
already.

The following patch avoids that.

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

2023-03-25  Jakub Jelinek  <jakub@redhat.com>

	PR ipa/105685
	* predict.cc (compute_function_frequency): Don't call
	warn_function_cold if function already has cold attribute.

	* c-c++-common/cold-2.c: New test.

--- gcc/predict.cc.jj	2023-01-02 09:32:38.273055726 +0100
+++ gcc/predict.cc	2023-03-24 16:54:13.658606215 +0100
@@ -4033,7 +4033,9 @@ compute_function_frequency (void)
     }
 
   node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED;
-  warn_function_cold (current_function_decl);
+  if (lookup_attribute ("cold", DECL_ATTRIBUTES (current_function_decl))
+      == NULL)
+    warn_function_cold (current_function_decl);
   if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa() == profile_count::zero ())
     return;
   FOR_EACH_BB_FN (bb, cfun)
--- gcc/testsuite/c-c++-common/cold-2.c.jj	2023-03-24 16:56:07.344000973 +0100
+++ gcc/testsuite/c-c++-common/cold-2.c	2023-03-24 16:55:58.985119001 +0100
@@ -0,0 +1,19 @@
+/* PR ipa/105685 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wsuggest-attribute=cold" } */
+
+extern void foo (char *, char const *, int);
+
+__attribute__((cold)) char *
+bar (int x)
+{
+  static char b[42];
+  foo (b, "foo", x);
+  return b;
+}
+
+__attribute__((cold)) char *
+baz (int x)		/* { dg-bogus "function might be candidate for attribute 'cold'" } */
+{
+  return bar (x);
+}

	Jakub


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

* Re: [PATCH] predict: Don't emit -Wsuggest-attribute=cold warning for functions which already have that attribute [PR105685]
  2023-03-25  9:53 [PATCH] predict: Don't emit -Wsuggest-attribute=cold warning for functions which already have that attribute [PR105685] Jakub Jelinek
@ 2023-03-26 17:57 ` Jeff Law
  2023-03-26 20:01 ` Jan Hubicka
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff Law @ 2023-03-26 17:57 UTC (permalink / raw)
  To: Jakub Jelinek, Richard Biener, Jan Hubicka; +Cc: gcc-patches



On 3/25/23 03:53, Jakub Jelinek via Gcc-patches wrote:
> Hi!
> 
> In the following testcase, we predict baz to have cold
> entry regardless of the user supplied attribute (as it call
> unconditionally a cold function), but still issue
> a -Wsuggest-attribute=cold warning despite it having that attribute
> already.
> 
> The following patch avoids that.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2023-03-25  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR ipa/105685
> 	* predict.cc (compute_function_frequency): Don't call
> 	warn_function_cold if function already has cold attribute.
> 
> 	* c-c++-common/cold-2.c: New test.
OK
jeff

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

* Re: [PATCH] predict: Don't emit -Wsuggest-attribute=cold warning for functions which already have that attribute [PR105685]
  2023-03-25  9:53 [PATCH] predict: Don't emit -Wsuggest-attribute=cold warning for functions which already have that attribute [PR105685] Jakub Jelinek
  2023-03-26 17:57 ` Jeff Law
@ 2023-03-26 20:01 ` Jan Hubicka
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Hubicka @ 2023-03-26 20:01 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Richard Biener, gcc-patches

> Hi!
> 
> In the following testcase, we predict baz to have cold
> entry regardless of the user supplied attribute (as it call
> unconditionally a cold function), but still issue
> a -Wsuggest-attribute=cold warning despite it having that attribute
> already.
> 
> The following patch avoids that.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2023-03-25  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR ipa/105685
> 	* predict.cc (compute_function_frequency): Don't call
> 	warn_function_cold if function already has cold attribute.
> 
> 	* c-c++-common/cold-2.c: New test.
> 
> --- gcc/predict.cc.jj	2023-01-02 09:32:38.273055726 +0100
> +++ gcc/predict.cc	2023-03-24 16:54:13.658606215 +0100
> @@ -4033,7 +4033,9 @@ compute_function_frequency (void)
>      }
>  
>    node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED;
> -  warn_function_cold (current_function_decl);
> +  if (lookup_attribute ("cold", DECL_ATTRIBUTES (current_function_decl))
> +      == NULL)
> +    warn_function_cold (current_function_decl);
OK, tanks!
In general we probably want to walk aliases and suggest warning on
aliases attached to the function, but we get this wrong with other
attributes too, so I will add it to TODo for next stage1.

Honza
>    if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa() == profile_count::zero ())
>      return;
>    FOR_EACH_BB_FN (bb, cfun)
> --- gcc/testsuite/c-c++-common/cold-2.c.jj	2023-03-24 16:56:07.344000973 +0100
> +++ gcc/testsuite/c-c++-common/cold-2.c	2023-03-24 16:55:58.985119001 +0100
> @@ -0,0 +1,19 @@
> +/* PR ipa/105685 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -Wsuggest-attribute=cold" } */
> +
> +extern void foo (char *, char const *, int);
> +
> +__attribute__((cold)) char *
> +bar (int x)
> +{
> +  static char b[42];
> +  foo (b, "foo", x);
> +  return b;
> +}
> +
> +__attribute__((cold)) char *
> +baz (int x)		/* { dg-bogus "function might be candidate for attribute 'cold'" } */
> +{
> +  return bar (x);
> +}
> 
> 	Jakub
> 

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

end of thread, other threads:[~2023-03-26 20:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-25  9:53 [PATCH] predict: Don't emit -Wsuggest-attribute=cold warning for functions which already have that attribute [PR105685] Jakub Jelinek
2023-03-26 17:57 ` Jeff Law
2023-03-26 20:01 ` Jan Hubicka

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