public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] ipa-inline: Improve growth accumulation for recursive calls
@ 2020-08-12 10:19 Xionghu Luo
  2020-08-12 17:53 ` Jan Hubicka
  0 siblings, 1 reply; 21+ messages in thread
From: Xionghu Luo @ 2020-08-12 10:19 UTC (permalink / raw)
  To: gcc-patches
  Cc: segher, dje.gcc, wschmidt, guojiufu, linkw, hubicka, mliska,
	mjambor, fxue, Xiong Hu Luo

From: Xiong Hu Luo <luoxhu@linux.ibm.com>

For SPEC2017 exchange2, there is a large recursive functiondigits_2(function
size 1300) generates specialized node from digits_2.1 to digits_2.8 with added
build option:

--param ipa-cp-eval-threshold=1 --param ipa-cp-unit-growth=80

ipa-inline pass will consider inline these nodes called only once, but these
large functions inlined too deeply will cause serious register spill and
performance down as followed.

inlineA: brute (inline digits_2.1, 2.2, 2.3, 2.4) -> digits_2.5 (inline 2.6, 2.7, 2.8)
inlineB: digits_2.1 (inline digits_2.2, 2.3) -> call digits_2.4 (inline digits_2.5, 2.6) -> call digits_2.7 (inline 2.8)
inlineC: brute (inline digits_2) -> call 2.1 -> 2.2 (inline 2.3) -> 2.4 -> 2.5 -> 2.6 (inline 2.7 ) -> 2.8
inlineD: brute -> call digits_2 -> call 2.1 -> call 2.2 -> 2.3 -> 2.4 -> 2.5 -> 2.6 -> 2.7 -> 2.8

Performance diff:
inlineB is ~25% faster than inlineA;
inlineC is ~20% faster than inlineB;
inlineD is ~30% faster than inlineC.

The master GCC code now generates inline sequence like inlineB, this patch
makes the ipa-inline pass behavior like inlineD by:
 1) The growth acumulation for recursive calls by adding the growth data
to the edge when edge's caller is inlined into another function to avoid
inline too deeply;
 2) And if caller and callee are both specialized from same node, the edge
should also be considered as recursive edge.

SPEC2017 test shows GEOMEAN improve +2.75% in total(+0.56% without exchange2).
Any comments?  Thanks.

523.xalancbmk_r +1.32%
541.leela_r     +1.51%
548.exchange2_r +31.87%
507.cactuBSSN_r +0.80%
526.blender_r   +1.25%
538.imagick_r   +1.82%

gcc/ChangeLog:

2020-08-12  Xionghu Luo  <luoxhu@linux.ibm.com>

	* cgraph.h (cgraph_edge::recursive_p): Return true if caller and
	callee and specialized from same node.
	* ipa-inline-analysis.c (do_estimate_growth_1): Add caller's
	inlined_to growth to edge whose caller is inlined.
---
 gcc/cgraph.h              | 2 ++
 gcc/ipa-inline-analysis.c | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index 0211f08964f..11903ac1960 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -3314,6 +3314,8 @@ cgraph_edge::recursive_p (void)
   cgraph_node *c = callee->ultimate_alias_target ();
   if (caller->inlined_to)
     return caller->inlined_to->decl == c->decl;
+  else if (caller->clone_of && c->clone_of)
+    return caller->clone_of->decl == c->clone_of->decl;
   else
     return caller->decl == c->decl;
 }
diff --git a/gcc/ipa-inline-analysis.c b/gcc/ipa-inline-analysis.c
index 148efbc09ef..ba0cf836364 100644
--- a/gcc/ipa-inline-analysis.c
+++ b/gcc/ipa-inline-analysis.c
@@ -434,6 +434,9 @@ do_estimate_growth_1 (struct cgraph_node *node, void *data)
 	  continue;
 	}
       d->growth += estimate_edge_growth (e);
+      if (e->caller->inlined_to)
+	d->growth += ipa_fn_summaries->get (e->caller->inlined_to)->growth;
+
       if (d->growth > d->cap)
 	return true;
     }
-- 
2.25.1


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

end of thread, other threads:[~2021-01-21 15:11 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-12 10:19 [PATCH] ipa-inline: Improve growth accumulation for recursive calls Xionghu Luo
2020-08-12 17:53 ` Jan Hubicka
2020-08-12 19:03   ` Richard Biener
2020-08-13  0:29     ` Segher Boessenkool
2020-08-13  7:53       ` Jan Hubicka
2020-08-13  3:59   ` Feng Xue OS
2020-08-13  6:51   ` luoxhu
2020-08-13 12:52     ` Jan Hubicka
2020-08-14  9:04       ` luoxhu
2020-08-20  9:31         ` Richard Sandiford
2020-08-20 10:49           ` [PATCH] ipa-inline: Improve growth accumulation for recursive callsg Jan Hubicka
2020-08-20 12:04           ` [PATCH] ipa-inline: Improve growth accumulation for recursive calls Martin Jambor
2020-08-21  9:17             ` Tamar Christina
2020-09-08 14:00               ` Martin Jambor
2020-09-11 10:38                 ` Tamar Christina
2020-09-11 12:45                   ` Martin Jambor
2020-09-11 17:36                     ` Tamar Christina
2020-09-16  8:35                       ` Hongyu Wang
2020-10-16  8:46                       ` Xionghu Luo
2021-01-21 14:34                         ` Tamar Christina
2021-01-21 15:11                           ` 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).