summaryrefslogtreecommitdiff
path: root/gcc/ipa-inline.c
diff options
context:
space:
mode:
authordehao <dehao@138bc75d-0d04-0410-961f-82ee72b054a4>2013-08-28 18:11:33 +0000
committerdehao <dehao@138bc75d-0d04-0410-961f-82ee72b054a4>2013-08-28 18:11:33 +0000
commitf4905b9aea8c10eec1ad07f3068ad17eebb8ff1d (patch)
tree7f87a14a6a1787f530faf7553847e01964c5c1b3 /gcc/ipa-inline.c
parentc643445e58ce556601c1b2940efb44ecf612d15f (diff)
downloadgcc-f4905b9aea8c10eec1ad07f3068ad17eebb8ff1d.tar.gz
2013-08-28 Dehao Chen <dehao@google.com>
* ipa-inline.c (edge_badness): Fix integer underflow. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@202059 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ipa-inline.c')
-rw-r--r--gcc/ipa-inline.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/gcc/ipa-inline.c b/gcc/ipa-inline.c
index 2cdf87519c5..11526957190 100644
--- a/gcc/ipa-inline.c
+++ b/gcc/ipa-inline.c
@@ -113,10 +113,12 @@ along with GCC; see the file COPYING3. If not see
#include "target.h"
#include "ipa-inline.h"
#include "ipa-utils.h"
+#include "sreal.h"
/* Statistics we collect about inlining algorithm. */
static int overall_size;
static gcov_type max_count;
+static sreal max_count_real, max_relbenefit_real, half_int_min_real;
/* Return false when inlining edge E would lead to violating
limits on function unit growth or stack usage growth.
@@ -891,12 +893,26 @@ edge_badness (struct cgraph_edge *edge, bool dump)
else if (max_count)
{
+ sreal tmp, relbenefit_real, growth_real;
int relbenefit = relative_time_benefit (callee_info, edge, edge_time);
- badness =
- ((int)
- ((double) edge->count * INT_MIN / 2 / max_count / RELATIVE_TIME_BENEFIT_RANGE) *
- relbenefit) / growth;
-
+
+ sreal_init(&relbenefit_real, relbenefit, 0);
+ sreal_init(&growth_real, growth, 0);
+
+ /* relative_edge_count. */
+ sreal_init (&tmp, edge->count, 0);
+ sreal_div (&tmp, &tmp, &max_count_real);
+
+ /* relative_time_benefit. */
+ sreal_mul (&tmp, &tmp, &relbenefit_real);
+ sreal_div (&tmp, &tmp, &max_relbenefit_real);
+
+ /* growth_f_caller. */
+ sreal_mul (&tmp, &tmp, &half_int_min_real);
+ sreal_div (&tmp, &tmp, &growth_real);
+
+ badness = -1 * sreal_to_int (&tmp);
+
/* Be sure that insanity of the profile won't lead to increasing counts
in the scalling and thus to overflow in the computation above. */
gcc_assert (max_count >= edge->count);
@@ -1542,6 +1558,9 @@ inline_small_functions (void)
if (max_count < edge->count)
max_count = edge->count;
}
+ sreal_init (&max_count_real, max_count, 0);
+ sreal_init (&max_relbenefit_real, RELATIVE_TIME_BENEFIT_RANGE, 0);
+ sreal_init (&half_int_min_real, INT_MAX / 2, 0);
ipa_free_postorder_info ();
initialize_growth_caches ();