From: Richard Biener Date: Mon, 2 Feb 2026 14:29:44 +0000 (+0100) Subject: middle-end/45273 - avoid host double in profiling X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ee3f1197b6f2889276edd2dca956eaeec3449ee6;p=thirdparty%2Fgcc.git 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. --- diff --git a/gcc/predict.cc b/gcc/predict.cc index de8f9c2211f..2859f64964b 100644 --- a/gcc/predict.cc +++ b/gcc/predict.cc @@ -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); } }