"H.J. Lu" <hjl.to...@gmail.com> writes: >> gcc/ >> PR rtl-optimization/117477 >> * config/aarch64/aarch64.cc (aarch64_count_saves): New function. >> (aarch64_count_above_hard_fp_saves, aarch64_callee_save_cost) >> (aarch64_frame_allocation_cost): Likewise. >> (TARGET_CALLEE_SAVE_COST): Define. >> (TARGET_FRAME_ALLOCATION_COST): Likewise. >> * config/i386/i386.cc (ix86_ira_callee_saved_register_cost_scale): >> Replace with... >> (ix86_callee_save_cost): ...this new hook. >> (TARGET_IRA_CALLEE_SAVED_REGISTER_COST_SCALE): Delete. >> (TARGET_CALLEE_SAVE_COST): Define. >> * target.h (spill_cost_type, frame_cost_type): New enums. >> * target.def (callee_save_cost, frame_allocation_cost): New hooks. >> (ira_callee_saved_register_cost_scale): Delete. >> * doc/tm.texi.in (TARGET_IRA_CALLEE_SAVED_REGISTER_COST_SCALE): >> Delete. >> (TARGET_CALLEE_SAVE_COST, TARGET_FRAME_ALLOCATION_COST): New hooks. >> * doc/tm.texi: Regenerate. >> * hard-reg-set.h (hard_reg_set_popcount): New function. >> * ira-color.cc (allocated_memory_p): New variable. >> (allocated_callee_save_regs): Likewise. >> (record_allocation): New function. >> (assign_hard_reg): Use targetm.frame_allocation_cost to model >> the cost of the first spill or first caller save. Use >> targetm.callee_save_cost to model the cost of using new callee-saved >> registers. Apply the exit rather than entry frequency to the cost >> of restoring a register or deallocating the frame. Update the >> new variables above. >> (improve_allocation): Use record_allocation. >> (color): Initialize allocated_callee_save_regs. >> (ira_color): Initialize allocated_memory_p. >> * targhooks.h (default_callee_save_cost): Declare. >> (default_frame_allocation_cost): Likewise. >> * targhooks.cc (default_callee_save_cost): New function. >> (default_frame_allocation_cost): Likewise. >> >> gcc/testsuite/ >> PR rtl-optimization/117477 >> * gcc.target/aarch64/callee_save_1.c: New test. >> * gcc.target/aarch64/callee_save_2.c: Likewise. >> * gcc.target/aarch64/callee_save_3.c: Likewise. >> * gcc.target/aarch64/pr103350-1.c: Add -fno-caller-saves. >> >> Co-authored-by: Jan Hubicka <hubi...@ucw.cz> > > Here is the v2 patch. The only change is > > if (GENERAL_REGNO_P (hard_regno)) > { > /* push is 1 byte while typical spill is 4-5 bytes. > ??? We probably should adjust size costs accordingly. > Costs are relative to reg-reg move that has 2 bytes for 32bit > and 3 bytes otherwise. Be sure that no cost table sets cost > to 2, so we end up with 0. */ > if (mem_cost <= 2 || optimize_function_for_size_p (cfun)) > return 1; > return mem_cost - 2; > } > > in ix86_callee_save_cost. > > Tested on x86-64 with > > $ make check RUNTESTFLAGS="--target_board='unix{-m32,}'" > > OK for master?
Thanks for picking this up! I'm not qualified to review the change, but just noticed: > gcc/ > PR rtl-optimization/117477 > * config/aarch64/aarch64.cc (aarch64_count_saves): New function. > (aarch64_count_above_hard_fp_saves, aarch64_callee_save_cost) > (aarch64_frame_allocation_cost): Likewise. > (TARGET_CALLEE_SAVE_COST): Define. > (TARGET_FRAME_ALLOCATION_COST): Likewise. > * config/i386/i386.cc (ix86_ira_callee_saved_register_cost_scale): > Replace with... > (ix86_callee_save_cost): ...this new hook. > (TARGET_IRA_CALLEE_SAVED_REGISTER_COST_SCALE): Delete. > (TARGET_CALLEE_SAVE_COST): Define. > * target.h (spill_cost_type, frame_cost_type): New enums. > * target.def (callee_save_cost, frame_allocation_cost): New hooks. > (ira_callee_saved_register_cost_scale): Delete. > * doc/tm.texi.in (TARGET_IRA_CALLEE_SAVED_REGISTER_COST_SCALE): Delete. > (TARGET_CALLEE_SAVE_COST, TARGET_FRAME_ALLOCATION_COST): New hooks. > * doc/tm.texi: Regenerate. > * hard-reg-set.h (hard_reg_set_popcount): New function. > * ira-color.cc (allocated_memory_p): New variable. > (allocated_callee_save_regs): Likewise. > (record_allocation): New function. > (assign_hard_reg): Use targetm.frame_allocation_cost to model > the cost of the first spill or first caller save. Use > targetm.callee_save_cost to model the cost of using new callee-saved > registers. Apply the exit rather than entry frequency to the cost > of restoring a register or deallocating the frame. Update the > new variables above. > (improve_allocation): Use record_allocation. > (color): Initialize allocated_callee_save_regs. > (ira_color): Initialize allocated_memory_p. > * targhooks.h (default_callee_save_cost): Declare. > (default_frame_allocation_cost): Likewise. > * targhooks.cc (default_callee_save_cost): New function. > (default_frame_allocation_cost): Likewise. > > gcc/testsuite/ > PR rtl-optimization/117477 > * gcc.target/aarch64/callee_save_1.c: New test. > * gcc.target/aarch64/callee_save_2.c: Likewise. > * gcc.target/aarch64/callee_save_3.c: Likewise. > * gcc.target/aarch64/pr103350-1.c: Add -fno-caller-saves. Please keep the: Co-authored-by: Jan Hubicka <hubi...@ucw.cz> and add yourself as co-author too. That way, all three names should get included in the ChangeLog entry. Thanks, Richard