From: Vladimir N. Makarov Date: Thu, 14 Sep 2023 14:26:48 +0000 (-0400) Subject: [RA]: Improve cost calculation of pseudos with equivalences X-Git-Tag: basepoints/gcc-15~6140 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3c834d85f2ec42c60995c2b678196a06cb744959;p=thirdparty%2Fgcc.git [RA]: Improve cost calculation of pseudos with equivalences RISCV target developers reported that RA can spill pseudo used in a loop although there are enough registers to assign. It happens when the pseudo has an equivalence outside the loop and the equivalence is not merged into insns using the pseudo. IRA sets up that memory cost to zero when the pseudo has an equivalence and it means that the pseudo will be probably spilled. This approach worked well for i686 (different approaches were benchmarked long time ago on spec2k). Although common sense says that the code is wrong and this was confirmed by RISCV developers. I've tried the following patch on I7-9700k and it improved spec17 fp by 1.5% (21.1 vs 20.8) although spec17 int is a bit worse by 0.45% (8.54 vs 8.58). The average generated code size is practically the same (0.001% difference). In the future we probably need to try more sophisticated cost calculation which should take into account that the equiv can not be combined in usage insns and the costs of reloads because of this. gcc/ChangeLog: * ira-costs.cc (find_costs_and_classes): Decrease memory cost by equiv savings. --- diff --git a/gcc/ira-costs.cc b/gcc/ira-costs.cc index d9e700e89473..8c93ace5094a 100644 --- a/gcc/ira-costs.cc +++ b/gcc/ira-costs.cc @@ -1947,15 +1947,8 @@ find_costs_and_classes (FILE *dump_file) } if (i >= first_moveable_pseudo && i < last_moveable_pseudo) i_mem_cost = 0; - else if (equiv_savings < 0) - i_mem_cost = -equiv_savings; - else if (equiv_savings > 0) - { - i_mem_cost = 0; - for (k = cost_classes_ptr->num - 1; k >= 0; k--) - i_costs[k] += equiv_savings; - } - + else + i_mem_cost -= equiv_savings; best_cost = (1 << (HOST_BITS_PER_INT - 2)) - 1; best = ALL_REGS; alt_class = NO_REGS;