public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: Jan Hubicka <hubicka@ucw.cz>
Cc: Jakub Jelinek <jakub@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] tree-optimization/106912 - IPA profile and pure/const
Date: Fri, 24 Mar 2023 13:07:14 +0000 (UTC)	[thread overview]
Message-ID: <nycvar.YFH.7.77.849.2303241305390.18795@jbgna.fhfr.qr> (raw)
In-Reply-To: <ZB2gCG1lCohNGm07@kam.mff.cuni.cz>

On Fri, 24 Mar 2023, Jan Hubicka wrote:

> > From d438a0d84cafced85c90204cba81de0f60ad0073 Mon Sep 17 00:00:00 2001
> > From: Richard Biener <rguenther@suse.de>
> > Date: Thu, 16 Mar 2023 13:51:19 +0100
> > Subject: [PATCH] tree-optimization/106912 - clear const attribute from fntype
> > To: gcc-patches@gcc.gnu.org
> > 
> > The following makes sure that after clearing pure/const from
> > instrumented function declarations we are adjusting call statements
> > fntype as well to handle indirect calls and because gimple_call_flags
> > looks at both decl and fntype.
> > 
> > Like the pure/const flag clearing on decls we refrain from touching
> > calls to known functions that do not have a body in the current TU.
> > 
> > 	PR tree-optimization/106912
> > 	* tree-profile.cc (tree_profiling): Update stmts only when
> > 	profiling or testing coverage.  Make sure to update calls
> > 	fntype, stripping 'const' there.
> > 
> > 	* gcc.dg/profile-generate-4.c: New testcase.
> > ---
> >  gcc/testsuite/gcc.dg/profile-generate-4.c | 19 ++++++++++++
> >  gcc/tree-profile.cc                       | 38 +++++++++++++++++------
> >  2 files changed, 47 insertions(+), 10 deletions(-)
> >  create mode 100644 gcc/testsuite/gcc.dg/profile-generate-4.c
> > 
> > diff --git a/gcc/testsuite/gcc.dg/profile-generate-4.c b/gcc/testsuite/gcc.dg/profile-generate-4.c
> > new file mode 100644
> > index 00000000000..c2b999fe4cb
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.dg/profile-generate-4.c
> > @@ -0,0 +1,19 @@
> > +/* PR106912 */
> > +/* { dg-require-profiling "-fprofile-generate" } */
> > +/* { dg-options "-O2 -fprofile-generate -ftree-vectorize" } */
> > +
> > +__attribute__ ((__simd__))
> > +__attribute__ ((__nothrow__ , __leaf__ , __const__, __noinline__))
> > +double foo (double x);
> > +
> > +void bar(double *f, int n)
> > +{
> > +  int i;
> > +  for (i = 0; i < n; i++)
> > +    f[i] = foo(f[i]);
> > +}
> > +
> > +double foo(double x)
> > +{
> > +  return x * x / 3.0;
> > +}
> > diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc
> > index ea9d7a23443..7854cd4bc31 100644
> > --- a/gcc/tree-profile.cc
> > +++ b/gcc/tree-profile.cc
> > @@ -835,16 +835,34 @@ tree_profiling (void)
> >  
> >        push_cfun (DECL_STRUCT_FUNCTION (node->decl));
> >  
> > -      FOR_EACH_BB_FN (bb, cfun)
> > -	{
> > -	  gimple_stmt_iterator gsi;
> > -	  for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
> > -	    {
> > -	      gimple *stmt = gsi_stmt (gsi);
> > -	      if (is_gimple_call (stmt))
> > -		update_stmt (stmt);
> > -	    }
> > -	}
> > +      if (profile_arc_flag || flag_test_coverage)
> > +	FOR_EACH_BB_FN (bb, cfun)
> > +	  {
> > +	    gimple_stmt_iterator gsi;
> > +	    for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
> > +	      {
> > +		gcall *call = dyn_cast <gcall *> (gsi_stmt (gsi));
> > +		if (!call)
> > +		  continue;
> > +
> > +		/* We do not clear pure/const on decls without body.  */
> > +		tree fndecl = gimple_call_fndecl (call);
> > +		if (fndecl && !gimple_has_body_p (fndecl))
> > +		  continue;
> 
> Actually on second thought, I think I can break this either by making
> the wraping function to be thunk or alias or by moving it to different
> compilation unit.
> Also with LTO we will get body later.
> 
> So I think we need to drop this optimization.

It's the same condition guarding the set_{const,pure}_flag call earlier
(but yes, I agree).  So it isn't covered by the regression so we
should address this for next stage1.

Richard.

  reply	other threads:[~2023-03-24 13:07 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-25  7:59 Richard Biener
2022-11-25 10:05 ` Jan Hubicka
2022-11-25 12:05   ` Richard Biener
2022-11-25 12:11     ` Jan Hubicka
2022-11-25 13:05       ` Richard Biener
2022-11-25 13:18         ` Jan Hubicka
2022-11-25 20:26           ` Richard Biener
2023-03-16 11:21             ` Jakub Jelinek
2023-03-16 12:05               ` Richard Biener
2023-03-16 12:13                 ` Jakub Jelinek
2023-03-16 12:22                   ` Richard Biener
2023-03-16 14:11                     ` Richard Biener
2023-03-16 14:27                       ` Jakub Jelinek
2023-03-17 19:40                       ` Jan Hubicka
2023-03-17 19:54                         ` Jakub Jelinek
2023-03-20  8:33                           ` Richard Biener
2023-03-24 10:25                             ` Richard Biener
2023-03-24 11:49                             ` Jan Hubicka
2023-03-24 13:05                       ` Jan Hubicka
2023-03-24 13:07                         ` Richard Biener [this message]
2023-03-24 13:18                           ` Jan Hubicka
2023-03-17 19:09                   ` Jan Hubicka
2023-03-17 19:27                     ` Jakub Jelinek

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=nycvar.YFH.7.77.849.2303241305390.18795@jbgna.fhfr.qr \
    --to=rguenther@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hubicka@ucw.cz \
    --cc=jakub@redhat.com \
    /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).