This is a pretty minimalistic implementation of the insn_cost hook: it just counts how many machine instructions will be generated. Some improvements are needed: loads should get extra cost; some instructions like mul and div should be more expensive than others; and it exposes some suboptimalities in our machine description files. Still, good enough for most testing.
--- gcc/config/rs6000/rs6000.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index a7d2e7e..b4fda69 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -1761,6 +1761,8 @@ static const struct attribute_spec rs6000_attribute_table[] = #define TARGET_RTX_COSTS rs6000_rtx_costs #undef TARGET_ADDRESS_COST #define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0 +#undef TARGET_INSN_COST +#define TARGET_INSN_COST rs6000_insn_cost #undef TARGET_INIT_DWARF_REG_SIZES_EXTRA #define TARGET_INIT_DWARF_REG_SIZES_EXTRA rs6000_init_dwarf_reg_sizes_extra @@ -34521,6 +34523,18 @@ rs6000_debug_rtx_costs (rtx x, machine_mode mode, int outer_code, return ret; } +static int +rs6000_insn_cost (rtx_insn *insn, bool speed) +{ + if (recog_memoized (insn) < 0) + return 0; + + if (!speed) + return get_attr_length (insn); + + return COSTS_N_INSNS (get_attr_length (insn) / 4); +} + /* Debug form of ADDRESS_COST that is selected if -mdebug=cost. */ static int -- 1.9.3