> Am 02.02.2025 um 08:00 schrieb H.J. Lu <hjl.to...@gmail.com>:
>
> Don't increase callee-saved register cost by 1000x, which leads to that
> callee-saved registers aren't used to preserve local variable values
> across calls, by capping the scale to 300.
> PR rtl-optimization/111673
> PR rtl-optimization/115932
> PR rtl-optimization/116028
> PR rtl-optimization/117081
> PR rtl-optimization/118497
> * ira-color.cc (assign_hard_reg): Cap callee-saved register cost
> scale to 300.
>
> Signed-off-by: H.J. Lu <hjl.to...@gmail.com>
> ---
> gcc/ira-color.cc | 16 ++++++++++++++--
> 1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/ira-color.cc b/gcc/ira-color.cc
> index 0699b349a1a..707ff188250 100644
> --- a/gcc/ira-color.cc
> +++ b/gcc/ira-color.cc
> @@ -2175,13 +2175,25 @@ assign_hard_reg (ira_allocno_t a, bool retry_p)
> /* We need to save/restore the hard register in
> epilogue/prologue. Therefore we increase the cost. */
> {
> + int scale;
> + if (optimize_size)
> + scale = 1;
> + else
> + {
> + scale = REG_FREQ_FROM_BB (ENTRY_BLOCK_PTR_FOR_FN (cfun));
> + /* Don't increase callee-saved register cost by 1000x,
> + which leads to that callee-saved registers aren't
> + used to preserve local variable values across calls,
> + by capping the scale to 300. */
> + if (REG_FREQ_MAX == 1000 && scale == REG_FREQ_MAX)
> + scale = 300;
That leads to 300 for 1000 but 999 for 999 which is odd. I’d have expected to
scale this down to [0, 300] or is MAX a magic value?
> + }
> rclass = REGNO_REG_CLASS (hard_regno);
> add_cost = ((ira_memory_move_cost[mode][rclass][0]
> + ira_memory_move_cost[mode][rclass][1])
> * saved_nregs / hard_regno_nregs (hard_regno,
> mode) - 1)
> - * (optimize_size ? 1 :
> - REG_FREQ_FROM_BB (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
> + * scale;
> cost += add_cost;
> full_cost += add_cost;
> }
> --
> 2.48.1
>