middle-end/45273 - avoid host double in profiling

The following replaces the last host double computation by using
int64_t instead to avoid overflow of 32bit (but capped to
REG_BR_PROB_BASE) values.

	PR middle-end/45273
	* predict.cc (combine_predictions_for_insn): Use int64_t
	math instead of double.
This commit is contained in:
Richard Biener
2026-02-02 15:29:44 +01:00
parent a40655524e
commit ee3f1197b6

View File

@@ -1046,13 +1046,14 @@ combine_predictions_for_insn (rtx_insn *insn, basic_block bb)
+ (REG_BR_PROB_BASE - combined_probability)
* (REG_BR_PROB_BASE - probability));
/* Use FP math to avoid overflows of 32bit integers. */
/* Use int64_t math to avoid overflows of 32bit integers. */
if (d == 0)
/* If one probability is 0% and one 100%, avoid division by zero. */
combined_probability = REG_BR_PROB_BASE / 2;
else
combined_probability = (((double) combined_probability) * probability
* REG_BR_PROB_BASE / d + 0.5);
combined_probability = ((((int64_t) combined_probability)
* probability
* REG_BR_PROB_BASE + (d / 2)) / d);
}
/* Decide which heuristic to use. In case we didn't match anything,
@@ -1399,14 +1400,14 @@ combine_predictions_for_bb (basic_block bb, bool dry_run)
+ (REG_BR_PROB_BASE - combined_probability)
* (REG_BR_PROB_BASE - probability));
/* Use FP math to avoid overflows of 32bit integers. */
/* Use int64_t math to avoid overflows of 32bit integers. */
if (d == 0)
/* If one probability is 0% and one 100%, avoid division by zero. */
combined_probability = REG_BR_PROB_BASE / 2;
else
combined_probability = (((double) combined_probability)
* probability
* REG_BR_PROB_BASE / d + 0.5);
combined_probability = ((((int64_t) combined_probability)
* probability
* REG_BR_PROB_BASE + (d / 2)) / d);
}
}