Fix overflow in ipa_profile_generate_summary
With profile count scaling we now get overflow in ipa_profile_generate_summary
which uses old macro GCOV_COMPUTE_SCALE that is not ready for very large
counts. This patch replaces remaining two uses of it by (somewhat elaborate)
profile-count based equivalent which is overflow safe.
Bootstrapped/regtested x86_64-linux, comitted.
gcc/ChangeLog:
* basic-block.h (GCOV_COMPUTE_SCALE): Remove.
* ipa-profile.cc (ipa_profile_generate_summary): Use
profile-count scaling.
* sched-rgn.cc (compute_trg_info): Likewise.
diff --git a/gcc/basic-block.h b/gcc/basic-block.h
index 049631de49b..410a03c6a5a 100644
--- a/gcc/basic-block.h
+++ b/gcc/basic-block.h
@@ -293,11 +293,6 @@ enum cfg_bb_flags
/* Return expected execution frequency of the edge E. */
#define EDGE_FREQUENCY(e) e->count ().to_frequency (cfun)
-/* Compute a scale factor (or probability) suitable for scaling of
- gcov_type values via apply_probability() and apply_scale(). */
-#define GCOV_COMPUTE_SCALE(num,den) \
- ((den) ? RDIV ((num) * REG_BR_PROB_BASE, (den)) : REG_BR_PROB_BASE)
-
/* Return nonzero if edge is critical. */
#define EDGE_CRITICAL_P(e) (EDGE_COUNT ((e)->src->succs) >= 2 \
&& EDGE_COUNT ((e)->dest->preds) >= 2)
diff --git a/gcc/ipa-profile.cc b/gcc/ipa-profile.cc
index d4725ce6262..4d0a8c98fbd 100644
--- a/gcc/ipa-profile.cc
+++ b/gcc/ipa-profile.cc
@@ -316,7 +316,11 @@ ipa_profile_generate_summary (void)
count = all;
}
speculative_call_target item (
- val, GCOV_COMPUTE_SCALE (count, all));
+ val,
+ profile_count::from_gcov_type (count)
+ .probability_in
+ (profile_count::from_gcov_type (all))
+ .to_reg_br_prob_base ());
csum->speculative_call_targets.safe_push (item);
}
diff --git a/gcc/sched-rgn.cc b/gcc/sched-rgn.cc
index adae7844916..5382fde1c31 100644
--- a/gcc/sched-rgn.cc
+++ b/gcc/sched-rgn.cc
@@ -1532,7 +1532,12 @@ compute_trg_info (int trg)
int tf = prob[trg], cf = prob[i];
/* In CFGs with low probability edges TF can possibly be zero. */
- sp->src_prob = (tf ? GCOV_COMPUTE_SCALE (cf, tf) : 0);
+ sp->src_prob = (tf ?
+ profile_count::from_gcov_type (cf)
+ .probability_in
+ (profile_count::from_gcov_type (tf))
+ .to_reg_br_prob_base ()
+ : 0);
sp->is_valid = (sp->src_prob >= min_spec_prob);
}