Skip to content

Commit 69ac957

Browse files
committed
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. 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.
1 parent 5bf0886 commit 69ac957

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

gcc/basic-block.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,6 @@ enum cfg_bb_flags
293293
/* Return expected execution frequency of the edge E. */
294294
#define EDGE_FREQUENCY(e) e->count ().to_frequency (cfun)
295295

296-
/* Compute a scale factor (or probability) suitable for scaling of
297-
gcov_type values via apply_probability() and apply_scale(). */
298-
#define GCOV_COMPUTE_SCALE(num,den) \
299-
((den) ? RDIV ((num) * REG_BR_PROB_BASE, (den)) : REG_BR_PROB_BASE)
300-
301296
/* Return nonzero if edge is critical. */
302297
#define EDGE_CRITICAL_P(e) (EDGE_COUNT ((e)->src->succs) >= 2 \
303298
&& EDGE_COUNT ((e)->dest->preds) >= 2)

gcc/ipa-profile.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,11 @@ ipa_profile_generate_summary (void)
316316
count = all;
317317
}
318318
speculative_call_target item (
319-
val, GCOV_COMPUTE_SCALE (count, all));
319+
val,
320+
profile_count::from_gcov_type (count)
321+
.probability_in
322+
(profile_count::from_gcov_type (all))
323+
.to_reg_br_prob_base ());
320324
csum->speculative_call_targets.safe_push (item);
321325
}
322326

gcc/sched-rgn.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,12 @@ compute_trg_info (int trg)
15321532
int tf = prob[trg], cf = prob[i];
15331533

15341534
/* In CFGs with low probability edges TF can possibly be zero. */
1535-
sp->src_prob = (tf ? GCOV_COMPUTE_SCALE (cf, tf) : 0);
1535+
sp->src_prob = (tf ?
1536+
profile_count::from_gcov_type (cf)
1537+
.probability_in
1538+
(profile_count::from_gcov_type (tf))
1539+
.to_reg_br_prob_base ()
1540+
: 0);
15361541
sp->is_valid = (sp->src_prob >= min_spec_prob);
15371542
}
15381543

0 commit comments

Comments
 (0)