https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103252
--- Comment #13 from Hongtao.liu <crazylht at gmail dot com> --- > > So for short live range reg, we may lose opportunity to allocate best > regclass, maybe add peephole2 to handle those cases instead of tune RA. No, r132 is also used as addr, but currently lra only add cost of movement from mask to gpr, but we could possibly run out of gpr which means there will be an extra spill, and this is not counted by record_address_regs. modified gcc/ira-costs.c @@ -1226,7 +1226,7 @@ record_address_regs (machine_mode mode, addr_space_t as, rtx x, struct costs *pp; int *pp_costs; enum reg_class i; - int k, regno, add_cost; + int k, regno, add_cost, potential_spill_cost; cost_classes_t cost_classes_ptr; enum reg_class *cost_classes; move_table *move_in_cost; @@ -1239,6 +1239,7 @@ record_address_regs (machine_mode mode, addr_space_t as, rtx x, ALLOCNO_BAD_SPILL_P (ira_curr_regno_allocno_map[regno]) = true; pp = COSTS (costs, COST_INDEX (regno)); add_cost = (ira_memory_move_cost[Pmode][rclass][1] * scale) / 2; + potential_spill_cost = add_cost / 5; if (INT_MAX - add_cost < pp->mem_cost) pp->mem_cost = INT_MAX; else @@ -1252,6 +1253,10 @@ record_address_regs (machine_mode mode, addr_space_t as, rtx x, { i = cost_classes[k]; add_cost = (move_in_cost[i][rclass] * scale) / 2; + /* If we run out of rclass regs, there could be an extra spill, + Let's say 20% possibility. */ + if (!ira_class_subset_p[i][rclass]) + add_cost += potential_spill_cost; if (INT_MAX - add_cost < pp_costs[k]) pp_costs[k] = INT_MAX;