* [PATCH] Add attribute hot judgement for INLINE_HINT_known_hot hint. @ 2022-09-20 8:48 Cui,Lili 2022-09-20 16:17 ` Jan Hubicka 0 siblings, 1 reply; 9+ messages in thread From: Cui,Lili @ 2022-09-20 8:48 UTC (permalink / raw) To: gcc-patches; +Cc: hubicka, hongtao.liu, hongjiu.lu Hi Honza, This patch is to add attribute hot judgement for INLINE_HINT_known_hot hint. We set up INLINE_HINT_known_hot hint only when we have profile feedback, now add function attribute judgement for it, when both caller and callee have __attribute__((hot)), we will also set up INLINE_HINT_known_hot hint for it. With this patch applied Ratio Codesize ADL Multi-copy: 538.imagic_r 16.7% 1.6% SPR Multi-copy: 538.imagic_r 15% 1.7% ICX Multi-copy: 538.imagic_r 15.2% 1.7% CLX Multi-copy: 538.imagic_r 12.7% 1.7% Znver3 Multi-copy: 538.imagic_r 10.6% 1.5% Bootstrap and regtest pending on x86_64-unknown-linux-gnu. OK for trunk? Thanks, Lili. gcc/ChangeLog * ipa-inline-analysis.cc (do_estimate_edge_time): Add function attribute judgement for INLINE_HINT_known_hot hint. --- gcc/ipa-inline-analysis.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/gcc/ipa-inline-analysis.cc b/gcc/ipa-inline-analysis.cc index 1ca685d1b0e..7bd29c36590 100644 --- a/gcc/ipa-inline-analysis.cc +++ b/gcc/ipa-inline-analysis.cc @@ -48,6 +48,7 @@ along with GCC; see the file COPYING3. If not see #include "ipa-utils.h" #include "cfgexpand.h" #include "gimplify.h" +#include "attribs.h" /* Cached node/edge growths. */ fast_call_summary<edge_growth_cache_entry *, va_heap> *edge_growth_cache = NULL; @@ -249,15 +250,19 @@ do_estimate_edge_time (struct cgraph_edge *edge, sreal *ret_nonspec_time) hints = estimates.hints; } - /* When we have profile feedback, we can quite safely identify hot - edges and for those we disable size limits. Don't do that when - probability that caller will call the callee is low however, since it + /* When we have profile feedback or function attribute, we can quite safely + identify hot edges and for those we disable size limits. Don't do that + when probability that caller will call the callee is low however, since it may hurt optimization of the caller's hot path. */ - if (edge->count.ipa ().initialized_p () && edge->maybe_hot_p () + if ((edge->count.ipa ().initialized_p () && edge->maybe_hot_p () && (edge->count.ipa () * 2 > (edge->caller->inlined_to ? edge->caller->inlined_to->count.ipa () : edge->caller->count.ipa ()))) + || (lookup_attribute ("hot", DECL_ATTRIBUTES (edge->caller->decl)) + != NULL + && lookup_attribute ("hot", DECL_ATTRIBUTES (edge->callee->decl)) + != NULL)) hints |= INLINE_HINT_known_hot; gcc_checking_assert (size >= 0); -- 2.17.1 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Add attribute hot judgement for INLINE_HINT_known_hot hint. 2022-09-20 8:48 [PATCH] Add attribute hot judgement for INLINE_HINT_known_hot hint Cui,Lili @ 2022-09-20 16:17 ` Jan Hubicka 2022-09-21 9:21 ` Cui, Lili 0 siblings, 1 reply; 9+ messages in thread From: Jan Hubicka @ 2022-09-20 16:17 UTC (permalink / raw) To: Cui,Lili; +Cc: gcc-patches, hongtao.liu, hongjiu.lu > Hi Honza, > > This patch is to add attribute hot judgement for INLINE_HINT_known_hot hint. > > We set up INLINE_HINT_known_hot hint only when we have profile feedback, > now add function attribute judgement for it, when both caller and callee > have __attribute__((hot)), we will also set up INLINE_HINT_known_hot hint > for it. > > With this patch applied > Ratio Codesize > ADL Multi-copy: 538.imagic_r 16.7% 1.6% > SPR Multi-copy: 538.imagic_r 15% 1.7% > ICX Multi-copy: 538.imagic_r 15.2% 1.7% > CLX Multi-copy: 538.imagic_r 12.7% 1.7% > Znver3 Multi-copy: 538.imagic_r 10.6% 1.5% > > Bootstrap and regtest pending on x86_64-unknown-linux-gnu. > OK for trunk? > > Thanks, > Lili. > > gcc/ChangeLog > > * ipa-inline-analysis.cc (do_estimate_edge_time): Add function attribute > judgement for INLINE_HINT_known_hot hint. Thank you. Can you please also add a testcase that tests for this. So you modify imagemagick marking attribute hot on the specific inline? I will try to also look again at your earlier patch - I had very busy summer and unfortunately lost track on this one. Honza > --- > gcc/ipa-inline-analysis.cc | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) > > diff --git a/gcc/ipa-inline-analysis.cc b/gcc/ipa-inline-analysis.cc > index 1ca685d1b0e..7bd29c36590 100644 > --- a/gcc/ipa-inline-analysis.cc > +++ b/gcc/ipa-inline-analysis.cc > @@ -48,6 +48,7 @@ along with GCC; see the file COPYING3. If not see > #include "ipa-utils.h" > #include "cfgexpand.h" > #include "gimplify.h" > +#include "attribs.h" > > /* Cached node/edge growths. */ > fast_call_summary<edge_growth_cache_entry *, va_heap> *edge_growth_cache = NULL; > @@ -249,15 +250,19 @@ do_estimate_edge_time (struct cgraph_edge *edge, sreal *ret_nonspec_time) > hints = estimates.hints; > } > > - /* When we have profile feedback, we can quite safely identify hot > - edges and for those we disable size limits. Don't do that when > - probability that caller will call the callee is low however, since it > + /* When we have profile feedback or function attribute, we can quite safely > + identify hot edges and for those we disable size limits. Don't do that > + when probability that caller will call the callee is low however, since it > may hurt optimization of the caller's hot path. */ > - if (edge->count.ipa ().initialized_p () && edge->maybe_hot_p () > + if ((edge->count.ipa ().initialized_p () && edge->maybe_hot_p () > && (edge->count.ipa () * 2 > > (edge->caller->inlined_to > ? edge->caller->inlined_to->count.ipa () > : edge->caller->count.ipa ()))) > + || (lookup_attribute ("hot", DECL_ATTRIBUTES (edge->caller->decl)) > + != NULL > + && lookup_attribute ("hot", DECL_ATTRIBUTES (edge->callee->decl)) > + != NULL)) > hints |= INLINE_HINT_known_hot; > > gcc_checking_assert (size >= 0); > -- > 2.17.1 > ^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH] Add attribute hot judgement for INLINE_HINT_known_hot hint. 2022-09-20 16:17 ` Jan Hubicka @ 2022-09-21 9:21 ` Cui, Lili 2022-10-08 0:33 ` Ping^1 " Cui, Lili 0 siblings, 1 reply; 9+ messages in thread From: Cui, Lili @ 2022-09-21 9:21 UTC (permalink / raw) To: Jan Hubicka; +Cc: gcc-patches, Liu, Hongtao, Lu, Hongjiu [-- Attachment #1: Type: text/plain, Size: 4127 bytes --] > Thank you. Can you please also add a testcase that tests for this. > So you modify imagemagick marking attribute hot on the specific inline? Thanks Honza. Added the testcase. I didn't modify source code of 538.imagic_r, the original source code has attribute like: #define magick_hot_spot __attribute__((__hot__)) static Cache *SetPixelCacheNexusPixels( ... ) magick_hot_spot; > I will try to also look again at your earlier patch - I had very busy summer and > unfortunately lost track on this one. > NP, I guessed you were busy during that time, my earlier patch was partially duplicated with function "Elimination_by_inlining_prob", except "parameter points to caller local memory" part, maybe we can find a suitable place to add local memory part to the IPA. > Honza gcc/ChangeLog * ipa-inline-analysis.cc (do_estimate_edge_time): Add function attribute judgement for INLINE_HINT_known_hot hint. gcc/testsuite/ChangeLog: * gcc.dg/ipa/inlinehint-6.c: New test. --- gcc/ipa-inline-analysis.cc | 13 ++++--- gcc/testsuite/gcc.dg/ipa/inlinehint-6.c | 47 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/inlinehint-6.c diff --git a/gcc/ipa-inline-analysis.cc b/gcc/ipa-inline-analysis.cc index 1ca685d1b0e..7bd29c36590 100644 --- a/gcc/ipa-inline-analysis.cc +++ b/gcc/ipa-inline-analysis.cc @@ -48,6 +48,7 @@ along with GCC; see the file COPYING3. If not see #include "ipa-utils.h" #include "cfgexpand.h" #include "gimplify.h" +#include "attribs.h" /* Cached node/edge growths. */ fast_call_summary<edge_growth_cache_entry *, va_heap> *edge_growth_cache = NULL; @@ -249,15 +250,19 @@ do_estimate_edge_time (struct cgraph_edge *edge, sreal *ret_nonspec_time) hints = estimates.hints; } - /* When we have profile feedback, we can quite safely identify hot - edges and for those we disable size limits. Don't do that when - probability that caller will call the callee is low however, since it + /* When we have profile feedback or function attribute, we can quite safely + identify hot edges and for those we disable size limits. Don't do that + when probability that caller will call the callee is low however, since it may hurt optimization of the caller's hot path. */ - if (edge->count.ipa ().initialized_p () && edge->maybe_hot_p () + if ((edge->count.ipa ().initialized_p () && edge->maybe_hot_p () && (edge->count.ipa () * 2 > (edge->caller->inlined_to ? edge->caller->inlined_to->count.ipa () : edge->caller->count.ipa ()))) + || (lookup_attribute ("hot", DECL_ATTRIBUTES (edge->caller->decl)) + != NULL + && lookup_attribute ("hot", DECL_ATTRIBUTES (edge->callee->decl)) + != NULL)) hints |= INLINE_HINT_known_hot; gcc_checking_assert (size >= 0); diff --git a/gcc/testsuite/gcc.dg/ipa/inlinehint-6.c b/gcc/testsuite/gcc.dg/ipa/inlinehint-6.c new file mode 100644 index 00000000000..1f3be641c6d --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/inlinehint-6.c @@ -0,0 +1,47 @@ +/* { dg-options "-O3 -c -fdump-ipa-inline-details -fno-early-inlining -fno-ipa-cp" } */ +/* { dg-add-options bind_pic_locally } */ + +#define size_t long long int + +struct A +{ + size_t f1, f2, f3, f4; +}; +struct C +{ + struct A a; + size_t b; +}; +struct C x; + +__attribute__((hot)) struct C callee (struct A *a, struct C *c) +{ + c->a=(*a); + + if((c->b + 7) & 17) + { + c->a.f1 = c->a.f2 + c->a.f1; + c->a.f2 = c->a.f3 - c->a.f2; + c->a.f3 = c->a.f2 + c->a.f3; + c->a.f4 = c->a.f2 - c->a.f4; + c->b = c->a.f2; + + } + return *c; +} + +__attribute__((hot)) struct C caller (size_t d, size_t e, size_t f, size_t g, struct C *c) +{ + struct A a; + a.f1 = 1 + d; + a.f2 = e; + a.f3 = 12 + f; + a.f4 = 68 + g; + if (c->b > 0) + return callee (&a, c); + else + return *c; +} + +/* { dg-final { scan-ipa-dump "known_hot" "inline" } } */ + -- 2.17.1 Thanks, Lili. [-- Attachment #2: 0001-Add-attribute-hot-judgement-for-INLINE_HINT_known_ho.patch --] [-- Type: application/octet-stream, Size: 3942 bytes --] From 8e268572deba097158686eeb10ed45ed33cd2ef5 Mon Sep 17 00:00:00 2001 From: "Cui,Lili" <lili.cui@intel.com> Date: Wed, 14 Sep 2022 20:08:35 +0800 Subject: [PATCH] Add attribute hot judgement for INLINE_HINT_known_hot hint. We set up INLINE_HINT_known_hot hint only when we have profile feedback, now add function attribute judgement for it, when both caller and callee have __attribute__((hot)), we will also set up INLINE_HINT_known_hot hint for it. With this patch applied, Ratio Code size ADL Multi-copy: 538.imagic_r 16.7% 1.6% SPR Multi-copy: 538.imagic_r 15% 1.7% ICX Multi-copy: 538.imagic_r 15.2% 1.7% CLX Multi-copy: 538.imagic_r 12.7% 1.7% Znver3 Multi-copy: 538.imagic_r 10.6% 1.5% gcc/ChangeLog * ipa-inline-analysis.cc (do_estimate_edge_time): Add function attribute judgement for INLINE_HINT_known_hot hint. gcc/testsuite/ChangeLog: * gcc.dg/ipa/inlinehint-6.c: New test. --- gcc/ipa-inline-analysis.cc | 13 ++++--- gcc/testsuite/gcc.dg/ipa/inlinehint-6.c | 47 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/inlinehint-6.c diff --git a/gcc/ipa-inline-analysis.cc b/gcc/ipa-inline-analysis.cc index 1ca685d1b0e..7bd29c36590 100644 --- a/gcc/ipa-inline-analysis.cc +++ b/gcc/ipa-inline-analysis.cc @@ -48,6 +48,7 @@ along with GCC; see the file COPYING3. If not see #include "ipa-utils.h" #include "cfgexpand.h" #include "gimplify.h" +#include "attribs.h" /* Cached node/edge growths. */ fast_call_summary<edge_growth_cache_entry *, va_heap> *edge_growth_cache = NULL; @@ -249,15 +250,19 @@ do_estimate_edge_time (struct cgraph_edge *edge, sreal *ret_nonspec_time) hints = estimates.hints; } - /* When we have profile feedback, we can quite safely identify hot - edges and for those we disable size limits. Don't do that when - probability that caller will call the callee is low however, since it + /* When we have profile feedback or function attribute, we can quite safely + identify hot edges and for those we disable size limits. Don't do that + when probability that caller will call the callee is low however, since it may hurt optimization of the caller's hot path. */ - if (edge->count.ipa ().initialized_p () && edge->maybe_hot_p () + if ((edge->count.ipa ().initialized_p () && edge->maybe_hot_p () && (edge->count.ipa () * 2 > (edge->caller->inlined_to ? edge->caller->inlined_to->count.ipa () : edge->caller->count.ipa ()))) + || (lookup_attribute ("hot", DECL_ATTRIBUTES (edge->caller->decl)) + != NULL + && lookup_attribute ("hot", DECL_ATTRIBUTES (edge->callee->decl)) + != NULL)) hints |= INLINE_HINT_known_hot; gcc_checking_assert (size >= 0); diff --git a/gcc/testsuite/gcc.dg/ipa/inlinehint-6.c b/gcc/testsuite/gcc.dg/ipa/inlinehint-6.c new file mode 100644 index 00000000000..1f3be641c6d --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/inlinehint-6.c @@ -0,0 +1,47 @@ +/* { dg-options "-O3 -c -fdump-ipa-inline-details -fno-early-inlining -fno-ipa-cp" } */ +/* { dg-add-options bind_pic_locally } */ + +#define size_t long long int + +struct A +{ + size_t f1, f2, f3, f4; +}; +struct C +{ + struct A a; + size_t b; +}; +struct C x; + +__attribute__((hot)) struct C callee (struct A *a, struct C *c) +{ + c->a=(*a); + + if((c->b + 7) & 17) + { + c->a.f1 = c->a.f2 + c->a.f1; + c->a.f2 = c->a.f3 - c->a.f2; + c->a.f3 = c->a.f2 + c->a.f3; + c->a.f4 = c->a.f2 - c->a.f4; + c->b = c->a.f2; + + } + return *c; +} + +__attribute__((hot)) struct C caller (size_t d, size_t e, size_t f, size_t g, struct C *c) +{ + struct A a; + a.f1 = 1 + d; + a.f2 = e; + a.f3 = 12 + f; + a.f4 = 68 + g; + if (c->b > 0) + return callee (&a, c); + else + return *c; +} + +/* { dg-final { scan-ipa-dump "known_hot" "inline" } } */ + -- 2.17.1 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Ping^1 [PATCH] Add attribute hot judgement for INLINE_HINT_known_hot hint. 2022-09-21 9:21 ` Cui, Lili @ 2022-10-08 0:33 ` Cui, Lili 2022-10-14 6:28 ` Ping^2 " Cui, Lili 0 siblings, 1 reply; 9+ messages in thread From: Cui, Lili @ 2022-10-08 0:33 UTC (permalink / raw) To: Cui, Lili, Jan Hubicka; +Cc: Lu, Hongjiu, Liu, Hongtao, gcc-patches Hi Honza, Gentle ping https://gcc.gnu.org/pipermail/gcc-patches/2022-September/601934.html Thanks, Lili. > -----Original Message----- > From: Gcc-patches <gcc-patches-bounces+lili.cui=intel.com@gcc.gnu.org> On > Behalf Of Cui, Lili via Gcc-patches > Sent: Wednesday, September 21, 2022 5:22 PM > To: Jan Hubicka <hubicka@ucw.cz> > Cc: Lu, Hongjiu <hongjiu.lu@intel.com>; Liu, Hongtao > <hongtao.liu@intel.com>; gcc-patches@gcc.gnu.org > Subject: RE: [PATCH] Add attribute hot judgement for > INLINE_HINT_known_hot hint. > > > Thank you. Can you please also add a testcase that tests for this. > > So you modify imagemagick marking attribute hot on the specific inline? > > Thanks Honza. Added the testcase. I didn't modify source code of > 538.imagic_r, the original source code has attribute like: > > #define magick_hot_spot __attribute__((__hot__)) static Cache > *SetPixelCacheNexusPixels( ... ) magick_hot_spot; > > > I will try to also look again at your earlier patch - I had very busy > > summer and unfortunately lost track on this one. > > > NP, I guessed you were busy during that time, my earlier patch was partially > duplicated with function "Elimination_by_inlining_prob", except "parameter > points to caller local memory" part, maybe we can find a suitable place to > add local memory part to the IPA. > > > Honza > > gcc/ChangeLog > > * ipa-inline-analysis.cc (do_estimate_edge_time): Add function attribute > judgement for INLINE_HINT_known_hot hint. > > gcc/testsuite/ChangeLog: > > * gcc.dg/ipa/inlinehint-6.c: New test. > --- > gcc/ipa-inline-analysis.cc | 13 ++++--- > gcc/testsuite/gcc.dg/ipa/inlinehint-6.c | 47 +++++++++++++++++++++++++ > 2 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 > gcc/testsuite/gcc.dg/ipa/inlinehint-6.c > > diff --git a/gcc/ipa-inline-analysis.cc b/gcc/ipa-inline-analysis.cc index > 1ca685d1b0e..7bd29c36590 100644 > --- a/gcc/ipa-inline-analysis.cc > +++ b/gcc/ipa-inline-analysis.cc > @@ -48,6 +48,7 @@ along with GCC; see the file COPYING3. If not see > #include "ipa-utils.h" > #include "cfgexpand.h" > #include "gimplify.h" > +#include "attribs.h" > > /* Cached node/edge growths. */ > fast_call_summary<edge_growth_cache_entry *, va_heap> > *edge_growth_cache = NULL; @@ -249,15 +250,19 @@ > do_estimate_edge_time (struct cgraph_edge *edge, sreal *ret_nonspec_time) > hints = estimates.hints; > } > > - /* When we have profile feedback, we can quite safely identify hot > - edges and for those we disable size limits. Don't do that when > - probability that caller will call the callee is low however, since it > + /* When we have profile feedback or function attribute, we can quite > safely > + identify hot edges and for those we disable size limits. Don't do that > + when probability that caller will call the callee is low however, > + since it > may hurt optimization of the caller's hot path. */ > - if (edge->count.ipa ().initialized_p () && edge->maybe_hot_p () > + if ((edge->count.ipa ().initialized_p () && edge->maybe_hot_p () > && (edge->count.ipa () * 2 > > (edge->caller->inlined_to > ? edge->caller->inlined_to->count.ipa () > : edge->caller->count.ipa ()))) > + || (lookup_attribute ("hot", DECL_ATTRIBUTES (edge->caller->decl)) > + != NULL > + && lookup_attribute ("hot", DECL_ATTRIBUTES (edge->callee->decl)) > + != NULL)) > hints |= INLINE_HINT_known_hot; > > gcc_checking_assert (size >= 0); > diff --git a/gcc/testsuite/gcc.dg/ipa/inlinehint-6.c > b/gcc/testsuite/gcc.dg/ipa/inlinehint-6.c > new file mode 100644 > index 00000000000..1f3be641c6d > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/ipa/inlinehint-6.c > @@ -0,0 +1,47 @@ > +/* { dg-options "-O3 -c -fdump-ipa-inline-details -fno-early-inlining > +-fno-ipa-cp" } */ > +/* { dg-add-options bind_pic_locally } */ > + > +#define size_t long long int > + > +struct A > +{ > + size_t f1, f2, f3, f4; > +}; > +struct C > +{ > + struct A a; > + size_t b; > +}; > +struct C x; > + > +__attribute__((hot)) struct C callee (struct A *a, struct C *c) { > + c->a=(*a); > + > + if((c->b + 7) & 17) > + { > + c->a.f1 = c->a.f2 + c->a.f1; > + c->a.f2 = c->a.f3 - c->a.f2; > + c->a.f3 = c->a.f2 + c->a.f3; > + c->a.f4 = c->a.f2 - c->a.f4; > + c->b = c->a.f2; > + > + } > + return *c; > +} > + > +__attribute__((hot)) struct C caller (size_t d, size_t e, size_t f, > +size_t g, struct C *c) { > + struct A a; > + a.f1 = 1 + d; > + a.f2 = e; > + a.f3 = 12 + f; > + a.f4 = 68 + g; > + if (c->b > 0) > + return callee (&a, c); > + else > + return *c; > +} > + > +/* { dg-final { scan-ipa-dump "known_hot" "inline" } } */ > + > -- > 2.17.1 > > Thanks, > Lili. ^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: Ping^2 [PATCH] Add attribute hot judgement for INLINE_HINT_known_hot hint. 2022-10-08 0:33 ` Ping^1 " Cui, Lili @ 2022-10-14 6:28 ` Cui, Lili 2022-10-21 1:52 ` Ping^3 [PATCH V2] " Cui, Lili 0 siblings, 1 reply; 9+ messages in thread From: Cui, Lili @ 2022-10-14 6:28 UTC (permalink / raw) To: Jan Hubicka; +Cc: Lu, Hongjiu, Liu, Hongtao, gcc-patches Hi Honza, Gentle ping https://gcc.gnu.org/pipermail/gcc-patches/2022-September/601934.html Thanks, Lili. > -----Original Message----- > From: Cui, Lili <lili.cui@intel.com> > Sent: Saturday, October 8, 2022 8:33 AM > To: Cui, Lili <lili.cui@intel.com>; Jan Hubicka <hubicka@ucw.cz> > Cc: Lu, Hongjiu <hongjiu.lu@intel.com>; Liu, Hongtao > <hongtao.liu@intel.com>; gcc-patches@gcc.gnu.org > Subject: Ping^1 [PATCH] Add attribute hot judgement for > INLINE_HINT_known_hot hint. > > Hi Honza, > > Gentle ping https://gcc.gnu.org/pipermail/gcc-patches/2022- > September/601934.html > > Thanks, > Lili. > > > -----Original Message----- > > From: Gcc-patches <gcc-patches-bounces+lili.cui=intel.com@gcc.gnu.org> > > On Behalf Of Cui, Lili via Gcc-patches > > Sent: Wednesday, September 21, 2022 5:22 PM > > To: Jan Hubicka <hubicka@ucw.cz> > > Cc: Lu, Hongjiu <hongjiu.lu@intel.com>; Liu, Hongtao > > <hongtao.liu@intel.com>; gcc-patches@gcc.gnu.org > > Subject: RE: [PATCH] Add attribute hot judgement for > > INLINE_HINT_known_hot hint. > > > > > Thank you. Can you please also add a testcase that tests for this. > > > So you modify imagemagick marking attribute hot on the specific inline? > > > > Thanks Honza. Added the testcase. I didn't modify source code of > > 538.imagic_r, the original source code has attribute like: > > > > #define magick_hot_spot __attribute__((__hot__)) static Cache > > *SetPixelCacheNexusPixels( ... ) magick_hot_spot; > > > > > I will try to also look again at your earlier patch - I had very > > > busy summer and unfortunately lost track on this one. > > > > > NP, I guessed you were busy during that time, my earlier patch was > > partially duplicated with function "Elimination_by_inlining_prob", > > except "parameter points to caller local memory" part, maybe we can > > find a suitable place to add local memory part to the IPA. > > > > > Honza > > > > gcc/ChangeLog > > > > * ipa-inline-analysis.cc (do_estimate_edge_time): Add function attribute > > judgement for INLINE_HINT_known_hot hint. > > > > gcc/testsuite/ChangeLog: > > > > * gcc.dg/ipa/inlinehint-6.c: New test. > > --- > > gcc/ipa-inline-analysis.cc | 13 ++++--- > > gcc/testsuite/gcc.dg/ipa/inlinehint-6.c | 47 > > +++++++++++++++++++++++++ > > 2 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 > > gcc/testsuite/gcc.dg/ipa/inlinehint-6.c > > > > diff --git a/gcc/ipa-inline-analysis.cc b/gcc/ipa-inline-analysis.cc > > index > > 1ca685d1b0e..7bd29c36590 100644 > > --- a/gcc/ipa-inline-analysis.cc > > +++ b/gcc/ipa-inline-analysis.cc > > @@ -48,6 +48,7 @@ along with GCC; see the file COPYING3. If not see > > #include "ipa-utils.h" > > #include "cfgexpand.h" > > #include "gimplify.h" > > +#include "attribs.h" > > > > /* Cached node/edge growths. */ > > fast_call_summary<edge_growth_cache_entry *, va_heap> > > *edge_growth_cache = NULL; @@ -249,15 +250,19 @@ > do_estimate_edge_time > > (struct cgraph_edge *edge, sreal *ret_nonspec_time) > > hints = estimates.hints; > > } > > > > - /* When we have profile feedback, we can quite safely identify hot > > - edges and for those we disable size limits. Don't do that when > > - probability that caller will call the callee is low however, since it > > + /* When we have profile feedback or function attribute, we can > > + quite > > safely > > + identify hot edges and for those we disable size limits. Don't do that > > + when probability that caller will call the callee is low > > + however, since it > > may hurt optimization of the caller's hot path. */ > > - if (edge->count.ipa ().initialized_p () && edge->maybe_hot_p () > > + if ((edge->count.ipa ().initialized_p () && edge->maybe_hot_p () > > && (edge->count.ipa () * 2 > > > (edge->caller->inlined_to > > ? edge->caller->inlined_to->count.ipa () > > : edge->caller->count.ipa ()))) > > + || (lookup_attribute ("hot", DECL_ATTRIBUTES (edge->caller->decl)) > > + != NULL > > + && lookup_attribute ("hot", DECL_ATTRIBUTES (edge->callee->decl)) > > + != NULL)) > > hints |= INLINE_HINT_known_hot; > > > > gcc_checking_assert (size >= 0); > > diff --git a/gcc/testsuite/gcc.dg/ipa/inlinehint-6.c > > b/gcc/testsuite/gcc.dg/ipa/inlinehint-6.c > > new file mode 100644 > > index 00000000000..1f3be641c6d > > --- /dev/null > > +++ b/gcc/testsuite/gcc.dg/ipa/inlinehint-6.c > > @@ -0,0 +1,47 @@ > > +/* { dg-options "-O3 -c -fdump-ipa-inline-details -fno-early-inlining > > +-fno-ipa-cp" } */ > > +/* { dg-add-options bind_pic_locally } */ > > + > > +#define size_t long long int > > + > > +struct A > > +{ > > + size_t f1, f2, f3, f4; > > +}; > > +struct C > > +{ > > + struct A a; > > + size_t b; > > +}; > > +struct C x; > > + > > +__attribute__((hot)) struct C callee (struct A *a, struct C *c) { > > + c->a=(*a); > > + > > + if((c->b + 7) & 17) > > + { > > + c->a.f1 = c->a.f2 + c->a.f1; > > + c->a.f2 = c->a.f3 - c->a.f2; > > + c->a.f3 = c->a.f2 + c->a.f3; > > + c->a.f4 = c->a.f2 - c->a.f4; > > + c->b = c->a.f2; > > + > > + } > > + return *c; > > +} > > + > > +__attribute__((hot)) struct C caller (size_t d, size_t e, size_t f, > > +size_t g, struct C *c) { > > + struct A a; > > + a.f1 = 1 + d; > > + a.f2 = e; > > + a.f3 = 12 + f; > > + a.f4 = 68 + g; > > + if (c->b > 0) > > + return callee (&a, c); > > + else > > + return *c; > > +} > > + > > +/* { dg-final { scan-ipa-dump "known_hot" "inline" } } */ > > + > > -- > > 2.17.1 > > > > Thanks, > > Lili. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Ping^3 [PATCH V2] Add attribute hot judgement for INLINE_HINT_known_hot hint. 2022-10-14 6:28 ` Ping^2 " Cui, Lili @ 2022-10-21 1:52 ` Cui, Lili 2022-10-29 4:28 ` Jeff Law 0 siblings, 1 reply; 9+ messages in thread From: Cui, Lili @ 2022-10-21 1:52 UTC (permalink / raw) To: Cui, Lili, Jan Hubicka, jh; +Cc: gcc-patches, Liu, Hongtao, Lu, Hongjiu Hi Honza, Gentle ping https://gcc.gnu.org/pipermail/gcc-patches/2022-September/601934.html gcc/ChangeLog * ipa-inline-analysis.cc (do_estimate_edge_time): Add function attribute judgement for INLINE_HINT_known_hot hint. gcc/testsuite/ChangeLog: * gcc.dg/ipa/inlinehint-6.c: New test. --- gcc/ipa-inline-analysis.cc | 13 ++++--- gcc/testsuite/gcc.dg/ipa/inlinehint-6.c | 47 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/inlinehint-6.c diff --git a/gcc/ipa-inline-analysis.cc b/gcc/ipa-inline-analysis.cc index 1ca685d1b0e..7bd29c36590 100644 --- a/gcc/ipa-inline-analysis.cc +++ b/gcc/ipa-inline-analysis.cc @@ -48,6 +48,7 @@ along with GCC; see the file COPYING3. If not see #include "ipa-utils.h" #include "cfgexpand.h" #include "gimplify.h" +#include "attribs.h" /* Cached node/edge growths. */ fast_call_summary<edge_growth_cache_entry *, va_heap> *edge_growth_cache = NULL; @@ -249,15 +250,19 @@ do_estimate_edge_time (struct cgraph_edge *edge, sreal *ret_nonspec_time) hints = estimates.hints; } - /* When we have profile feedback, we can quite safely identify hot - edges and for those we disable size limits. Don't do that when - probability that caller will call the callee is low however, since it + /* When we have profile feedback or function attribute, we can quite safely + identify hot edges and for those we disable size limits. Don't do that + when probability that caller will call the callee is low however, since it may hurt optimization of the caller's hot path. */ - if (edge->count.ipa ().initialized_p () && edge->maybe_hot_p () + if ((edge->count.ipa ().initialized_p () && edge->maybe_hot_p () && (edge->count.ipa () * 2 > (edge->caller->inlined_to ? edge->caller->inlined_to->count.ipa () : edge->caller->count.ipa ()))) + || (lookup_attribute ("hot", DECL_ATTRIBUTES (edge->caller->decl)) + != NULL + && lookup_attribute ("hot", DECL_ATTRIBUTES (edge->callee->decl)) + != NULL)) hints |= INLINE_HINT_known_hot; gcc_checking_assert (size >= 0); diff --git a/gcc/testsuite/gcc.dg/ipa/inlinehint-6.c b/gcc/testsuite/gcc.dg/ipa/inlinehint-6.c new file mode 100644 index 00000000000..1f3be641c6d --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/inlinehint-6.c @@ -0,0 +1,47 @@ +/* { dg-options "-O3 -c -fdump-ipa-inline-details -fno-early-inlining -fno-ipa-cp" } */ +/* { dg-add-options bind_pic_locally } */ + +#define size_t long long int + +struct A +{ + size_t f1, f2, f3, f4; +}; +struct C +{ + struct A a; + size_t b; +}; +struct C x; + +__attribute__((hot)) struct C callee (struct A *a, struct C *c) +{ + c->a=(*a); + + if((c->b + 7) & 17) + { + c->a.f1 = c->a.f2 + c->a.f1; + c->a.f2 = c->a.f3 - c->a.f2; + c->a.f3 = c->a.f2 + c->a.f3; + c->a.f4 = c->a.f2 - c->a.f4; + c->b = c->a.f2; + + } + return *c; +} + +__attribute__((hot)) struct C caller (size_t d, size_t e, size_t f, size_t g, struct C *c) +{ + struct A a; + a.f1 = 1 + d; + a.f2 = e; + a.f3 = 12 + f; + a.f4 = 68 + g; + if (c->b > 0) + return callee (&a, c); + else + return *c; +} + +/* { dg-final { scan-ipa-dump "known_hot" "inline" } } */ + -- 2.17.1 Thanks, Lili. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Ping^3 [PATCH V2] Add attribute hot judgement for INLINE_HINT_known_hot hint. 2022-10-21 1:52 ` Ping^3 [PATCH V2] " Cui, Lili @ 2022-10-29 4:28 ` Jeff Law 2022-10-31 1:44 ` Cui, Lili 0 siblings, 1 reply; 9+ messages in thread From: Jeff Law @ 2022-10-29 4:28 UTC (permalink / raw) To: Cui, Lili, Jan Hubicka, jh; +Cc: Lu, Hongjiu, Liu, Hongtao, gcc-patches On 10/20/22 19:52, Cui, Lili via Gcc-patches wrote: > Hi Honza, > > Gentle ping https://gcc.gnu.org/pipermail/gcc-patches/2022-September/601934.html > > gcc/ChangeLog > > * ipa-inline-analysis.cc (do_estimate_edge_time): Add function attribute > judgement for INLINE_HINT_known_hot hint. > > gcc/testsuite/ChangeLog: > > * gcc.dg/ipa/inlinehint-6.c: New test. > --- > gcc/ipa-inline-analysis.cc | 13 ++++--- > gcc/testsuite/gcc.dg/ipa/inlinehint-6.c | 47 +++++++++++++++++++++++++ > 2 files changed, 56 insertions(+), 4 deletions(-) > create mode 100644 gcc/testsuite/gcc.dg/ipa/inlinehint-6.c > > diff --git a/gcc/ipa-inline-analysis.cc b/gcc/ipa-inline-analysis.cc > index 1ca685d1b0e..7bd29c36590 100644 > --- a/gcc/ipa-inline-analysis.cc > +++ b/gcc/ipa-inline-analysis.cc > @@ -48,6 +48,7 @@ along with GCC; see the file COPYING3. If not see > #include "ipa-utils.h" > #include "cfgexpand.h" > #include "gimplify.h" > +#include "attribs.h" > > /* Cached node/edge growths. */ > fast_call_summary<edge_growth_cache_entry *, va_heap> *edge_growth_cache = NULL; > @@ -249,15 +250,19 @@ do_estimate_edge_time (struct cgraph_edge *edge, sreal *ret_nonspec_time) > hints = estimates.hints; > } > > - /* When we have profile feedback, we can quite safely identify hot > - edges and for those we disable size limits. Don't do that when > - probability that caller will call the callee is low however, since it > + /* When we have profile feedback or function attribute, we can quite safely > + identify hot edges and for those we disable size limits. Don't do that > + when probability that caller will call the callee is low however, since it > may hurt optimization of the caller's hot path. */ > - if (edge->count.ipa ().initialized_p () && edge->maybe_hot_p () > + if ((edge->count.ipa ().initialized_p () && edge->maybe_hot_p () > && (edge->count.ipa () * 2 > > (edge->caller->inlined_to > ? edge->caller->inlined_to->count.ipa () > : edge->caller->count.ipa ()))) > + || (lookup_attribute ("hot", DECL_ATTRIBUTES (edge->caller->decl)) > + != NULL > + && lookup_attribute ("hot", DECL_ATTRIBUTES (edge->callee->decl)) > + != NULL)) > hints |= INLINE_HINT_known_hot; Is the theory here that if the user has marked the caller and callee as hot, then we're going to assume an edge between them is hot too? That's not necessarily true, it could be they're both hot, but via other call chains. But it's probably a reasonable heuristic in practice. OK jeff ^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: Ping^3 [PATCH V2] Add attribute hot judgement for INLINE_HINT_known_hot hint. 2022-10-29 4:28 ` Jeff Law @ 2022-10-31 1:44 ` Cui, Lili 2022-10-31 16:35 ` Jeff Law 0 siblings, 1 reply; 9+ messages in thread From: Cui, Lili @ 2022-10-31 1:44 UTC (permalink / raw) To: Jeff Law, Jan Hubicka, jh; +Cc: Lu, Hongjiu, Liu, Hongtao, gcc-patches > > On 10/20/22 19:52, Cui, Lili via Gcc-patches wrote: > > Hi Honza, > > > > Gentle ping > > https://gcc.gnu.org/pipermail/gcc-patches/2022-September/601934.html > > > > gcc/ChangeLog > > > > * ipa-inline-analysis.cc (do_estimate_edge_time): Add function attribute > > judgement for INLINE_HINT_known_hot hint. > > > > gcc/testsuite/ChangeLog: > > > > * gcc.dg/ipa/inlinehint-6.c: New test. > > --- > > gcc/ipa-inline-analysis.cc | 13 ++++--- > > gcc/testsuite/gcc.dg/ipa/inlinehint-6.c | 47 > +++++++++++++++++++++++++ > > 2 files changed, 56 insertions(+), 4 deletions(-) > > create mode 100644 gcc/testsuite/gcc.dg/ipa/inlinehint-6.c > > > > diff --git a/gcc/ipa-inline-analysis.cc b/gcc/ipa-inline-analysis.cc > > index 1ca685d1b0e..7bd29c36590 100644 > > --- a/gcc/ipa-inline-analysis.cc > > +++ b/gcc/ipa-inline-analysis.cc > > @@ -48,6 +48,7 @@ along with GCC; see the file COPYING3. If not see > > #include "ipa-utils.h" > > #include "cfgexpand.h" > > #include "gimplify.h" > > +#include "attribs.h" > > > > /* Cached node/edge growths. */ > > fast_call_summary<edge_growth_cache_entry *, va_heap> > > *edge_growth_cache = NULL; @@ -249,15 +250,19 @@ > do_estimate_edge_time (struct cgraph_edge *edge, sreal > *ret_nonspec_time) > > hints = estimates.hints; > > } > > > > - /* When we have profile feedback, we can quite safely identify hot > > - edges and for those we disable size limits. Don't do that when > > - probability that caller will call the callee is low however, since it > > + /* When we have profile feedback or function attribute, we can quite > safely > > + identify hot edges and for those we disable size limits. Don't do that > > + when probability that caller will call the callee is low > > + however, since it > > may hurt optimization of the caller's hot path. */ > > - if (edge->count.ipa ().initialized_p () && edge->maybe_hot_p () > > + if ((edge->count.ipa ().initialized_p () && edge->maybe_hot_p () > > && (edge->count.ipa () * 2 > > > (edge->caller->inlined_to > > ? edge->caller->inlined_to->count.ipa () > > : edge->caller->count.ipa ()))) > > + || (lookup_attribute ("hot", DECL_ATTRIBUTES (edge->caller->decl)) > > + != NULL > > + && lookup_attribute ("hot", DECL_ATTRIBUTES (edge->callee->decl)) > > + != NULL)) > > hints |= INLINE_HINT_known_hot; > > Is the theory here that if the user has marked the caller and callee as hot, > then we're going to assume an edge between them is hot too? That's not > necessarily true, it could be they're both hot, but via other call chains. But it's > probably a reasonable heuristic in practice. > Yes, thanks Jeff. Lili. > > OK > > > jeff > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Ping^3 [PATCH V2] Add attribute hot judgement for INLINE_HINT_known_hot hint. 2022-10-31 1:44 ` Cui, Lili @ 2022-10-31 16:35 ` Jeff Law 0 siblings, 0 replies; 9+ messages in thread From: Jeff Law @ 2022-10-31 16:35 UTC (permalink / raw) To: Cui, Lili, Jan Hubicka, jh; +Cc: Lu, Hongjiu, Liu, Hongtao, gcc-patches On 10/30/22 19:44, Cui, Lili wrote: >> On 10/20/22 19:52, Cui, Lili via Gcc-patches wrote: >>> Hi Honza, >>> >>> Gentle ping >>> https://gcc.gnu.org/pipermail/gcc-patches/2022-September/601934.html >>> >>> gcc/ChangeLog >>> >>> * ipa-inline-analysis.cc (do_estimate_edge_time): Add function attribute >>> judgement for INLINE_HINT_known_hot hint. >>> >>> gcc/testsuite/ChangeLog: >>> >>> * gcc.dg/ipa/inlinehint-6.c: New test. >>> --- >>> gcc/ipa-inline-analysis.cc | 13 ++++--- >>> gcc/testsuite/gcc.dg/ipa/inlinehint-6.c | 47 >> +++++++++++++++++++++++++ >>> 2 files changed, 56 insertions(+), 4 deletions(-) >>> create mode 100644 gcc/testsuite/gcc.dg/ipa/inlinehint-6.c >>> >>> diff --git a/gcc/ipa-inline-analysis.cc b/gcc/ipa-inline-analysis.cc >>> index 1ca685d1b0e..7bd29c36590 100644 >>> --- a/gcc/ipa-inline-analysis.cc >>> +++ b/gcc/ipa-inline-analysis.cc >>> @@ -48,6 +48,7 @@ along with GCC; see the file COPYING3. If not see >>> #include "ipa-utils.h" >>> #include "cfgexpand.h" >>> #include "gimplify.h" >>> +#include "attribs.h" >>> >>> /* Cached node/edge growths. */ >>> fast_call_summary<edge_growth_cache_entry *, va_heap> >>> *edge_growth_cache = NULL; @@ -249,15 +250,19 @@ >> do_estimate_edge_time (struct cgraph_edge *edge, sreal >> *ret_nonspec_time) >>> hints = estimates.hints; >>> } >>> >>> - /* When we have profile feedback, we can quite safely identify hot >>> - edges and for those we disable size limits. Don't do that when >>> - probability that caller will call the callee is low however, since it >>> + /* When we have profile feedback or function attribute, we can quite >> safely >>> + identify hot edges and for those we disable size limits. Don't do that >>> + when probability that caller will call the callee is low >>> + however, since it >>> may hurt optimization of the caller's hot path. */ >>> - if (edge->count.ipa ().initialized_p () && edge->maybe_hot_p () >>> + if ((edge->count.ipa ().initialized_p () && edge->maybe_hot_p () >>> && (edge->count.ipa () * 2 >>> > (edge->caller->inlined_to >>> ? edge->caller->inlined_to->count.ipa () >>> : edge->caller->count.ipa ()))) >>> + || (lookup_attribute ("hot", DECL_ATTRIBUTES (edge->caller->decl)) >>> + != NULL >>> + && lookup_attribute ("hot", DECL_ATTRIBUTES (edge->callee->decl)) >>> + != NULL)) >>> hints |= INLINE_HINT_known_hot; >> Is the theory here that if the user has marked the caller and callee as hot, >> then we're going to assume an edge between them is hot too? That's not >> necessarily true, it could be they're both hot, but via other call chains. But it's >> probably a reasonable heuristic in practice. >> > Yes, thanks Jeff. Thanks for the confirmation. This is OK for the trunk. jeff ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-10-31 16:35 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-09-20 8:48 [PATCH] Add attribute hot judgement for INLINE_HINT_known_hot hint Cui,Lili 2022-09-20 16:17 ` Jan Hubicka 2022-09-21 9:21 ` Cui, Lili 2022-10-08 0:33 ` Ping^1 " Cui, Lili 2022-10-14 6:28 ` Ping^2 " Cui, Lili 2022-10-21 1:52 ` Ping^3 [PATCH V2] " Cui, Lili 2022-10-29 4:28 ` Jeff Law 2022-10-31 1:44 ` Cui, Lili 2022-10-31 16:35 ` Jeff Law
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).