This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Improve inlining heuristics via estimate_num_insns
- From: Richard Guenther <rguenth at tat dot physik dot uni-tuebingen dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 24 Feb 2005 23:54:08 +0100
- Subject: [PATCH] Improve inlining heuristics via estimate_num_insns
Hi!
This patch improves inlining heuristics by tweaking estimate_num_insns
to return numbers that
1. are more close to those of gcc 3.4
2. do not penaltize abstraction. I.e. the size estimate results in
inline int foo(int x) { return x*x; }
int bar(int x) { return foo(x); }
having the same sizes (actually 1) if foo is inlined in bar.
See http://gcc.gnu.org/ml/gcc/2005-02/msg00981.html for more comparisons
with gcc 3.4 and unpatched gcc 4.0.
The patch needs to tweak gcc.dg/winline-6.c because the size estimate
for t changed from 13 to 10 and we now happily inline q into t because
we use q for the large function growth limit, and 10-10+100 == 100 which
is exactly the size of q. Fixed by increasing the size of t by one
which will result in a inlined size of 101 and so we emit the warning.
Bootstrapped and tested on x86_64-unknown-linux-gnu with no regressions.
Ok for 4.0 (suppose it opens)? Ok for mainline?
Anyone willing to throw their favorite benchmark or SPEC against it?
Thanks,
Richard.
2005-Feb-24 Richard Guenther <rguenth@gcc.gnu.org>
* tree-inline.c (estimate_num_insns_1): Ignore stores to decls
with ignored flag set.
* gcc.dg/winline-6.c (t): Adjust function body size for changed
size estimate.
Index: tree-inline.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-inline.c,v
retrieving revision 1.170
diff -c -3 -p -r1.170 tree-inline.c
*** tree-inline.c 27 Jan 2005 14:36:17 -0000 1.170
--- tree-inline.c 24 Feb 2005 20:07:40 -0000
*************** estimate_num_insns_1 (tree *tp, int *wal
*** 1247,1255 ****
big arrays. */
case INIT_EXPR:
case MODIFY_EXPR:
x = TREE_OPERAND (x, 0);
/* FALLTHRU */
- case TARGET_EXPR:
case CONSTRUCTOR:
{
HOST_WIDE_INT size;
--- 1247,1257 ----
big arrays. */
case INIT_EXPR:
case MODIFY_EXPR:
+ case TARGET_EXPR:
x = TREE_OPERAND (x, 0);
+ if (DECL_P (x) && DECL_IGNORED_P (x))
+ break;
/* FALLTHRU */
case CONSTRUCTOR:
{
HOST_WIDE_INT size;
Index: testsuite/gcc.dg/winline-6.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/winline-6.c,v
retrieving revision 1.1
diff -c -3 -p -r1.1 winline-6.c
*** testsuite/gcc.dg/winline-6.c 4 Jan 2004 14:39:13 -0000 1.1
--- testsuite/gcc.dg/winline-6.c 24 Feb 2005 22:36:08 -0000
*************** inline int q(void)
*** 17,21 ****
}
inline int t (void)
{
! return q (); /* { dg-warning "called from here" } */
}
--- 17,21 ----
}
inline int t (void)
{
! return q () + 1; /* { dg-warning "called from here" } */
}