From c5d0600d09df75581455e2152500866aa5d49f2e Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Wed, 10 Nov 2010 21:23:09 +0100 Subject: [PATCH] re PR tree-optimization/46228 (code produced for STL container is worse in 4.5.1 than in 4.4.5) PR tree-optimize/46228 * doc/invoke.texi (comdat-sharing-probability): Document. * ipa-inline.c (cgraph_estimate_growth): Handle COMDATs * params.def (PARAM_COMDAT_SHARING_PROBABILITY): New param. * g++.dg/tree-ssa/pr46228.C: New testcase. From-SVN: r166555 --- gcc/doc/invoke.texi | 5 +++++ gcc/ipa-inline.c | 6 ++++++ gcc/params.def | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/tree-ssa/pr46228.C | 23 +++++++++++++++++++++++ 5 files changed, 45 insertions(+) create mode 100644 gcc/testsuite/g++.dg/tree-ssa/pr46228.C diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index d3b702b7de09..dc79b8803aaf 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -8343,6 +8343,11 @@ Limit of iterations of early inliner. This basically bounds number of nested indirect calls early inliner can resolve. Deeper chains are still handled by late inlining. +@item comdat-sharing-probability +@itemx comdat-sharing-probability +Probability (in percent) that C++ inline function with comdat visibility +will be shared acroess multiple compilation units. The default value is 20. + @item min-vect-loop-bound The minimum number of iterations under which a loop will not get vectorized when @option{-ftree-vectorize} is used. The number of iterations after diff --git a/gcc/ipa-inline.c b/gcc/ipa-inline.c index 61fc6b9992ec..d4109c5a21f1 100644 --- a/gcc/ipa-inline.c +++ b/gcc/ipa-inline.c @@ -404,6 +404,12 @@ cgraph_estimate_growth (struct cgraph_node *node) if (cgraph_will_be_removed_from_program_if_no_direct_calls (node) && !DECL_EXTERNAL (node->decl) && !self_recursive) growth -= node->global.size; + /* COMDAT functions are very often not shared across multiple units since they + come from various template instantiations. Take this into account. */ + else if (DECL_COMDAT (node->decl) && !self_recursive + && cgraph_can_remove_if_no_direct_calls_p (node)) + growth -= (node->global.size + * (100 - PARAM_VALUE (PARAM_COMDAT_SHARING_PROBABILITY)) + 50) / 100; node->global.estimated_growth = growth; return growth; diff --git a/gcc/params.def b/gcc/params.def index 49a6185d48b5..6e55db63fcb5 100644 --- a/gcc/params.def +++ b/gcc/params.def @@ -117,6 +117,12 @@ DEFPARAM (PARAM_EARLY_INLINER_MAX_ITERATIONS, "The maximum number of nested indirect inlining performed by early inliner", 10, 0, 0) +/* Limit on probability of entry BB. */ +DEFPARAM (PARAM_COMDAT_SHARING_PROBABILITY, + "comdat-sharing-probability", + "Probability that COMDAT function will be shared with different compilatoin unit", + 20, 0, 0) + /* Limit on probability of entry BB. */ DEFPARAM (PARAM_PARTIAL_INLINING_ENTRY_PROBABILITY, "partial-inlining-entry-probability", diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b00c673d3d91..661e55bd7bc4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-11-10 Jan Hubicka + + PR tree-optimize/46228 + * g++.dg/tree-ssa/pr46228.C: New testcase. + 2010-11-10 H.J. Lu PR tree-optimization/46414 diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr46228.C b/gcc/testsuite/g++.dg/tree-ssa/pr46228.C new file mode 100644 index 000000000000..a720dbe3b8c2 --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/pr46228.C @@ -0,0 +1,23 @@ +// { dg-options "-fdump-tree-optimized -Os" } +#include +#include + +int main() +{ + static const int array[] = { 1,2,3,4,5,6,7,8,9,10,6 }; + std::set the_set; + int count = 0; + for (unsigned i = 0; i < sizeof(array)/sizeof(*array); i++) + { + std::pair::iterator, bool> result = + the_set.insert(array[i]); + if (result.second) + count++; + } + printf("%d unique items in array.\n", count); + return 0; +} + +// This function is small enough to be inlined even at -Os. +// { dg-final { scan-tree-dump-not "_ZNSt8_Rb_treeIiiSt9_IdentityIiESt4lessIiESaIiEED2Ev" "optimized" } } +// { dg-final { cleanup-tree-dump "optimized" } }