No-op moves are given the code NOOP_MOVE_INSN_CODE if we plan to delete them later. Such insns shouldn't be costed, partly because they're going to disappear, and partly because targets won't recognise the insn code.
gcc/ * rtl-ssa/changes.cc (rtl_ssa::changes_are_worthwhile): Don't cost no-op moves. * rtl-ssa/insns.cc (insn_info::calculate_cost): Likewise. --- gcc/rtl-ssa/changes.cc | 6 +++++- gcc/rtl-ssa/insns.cc | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/gcc/rtl-ssa/changes.cc b/gcc/rtl-ssa/changes.cc index c5ac4956a19..bc80d7da829 100644 --- a/gcc/rtl-ssa/changes.cc +++ b/gcc/rtl-ssa/changes.cc @@ -177,13 +177,17 @@ rtl_ssa::changes_are_worthwhile (array_slice<insn_change *const> changes, auto entry_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count; for (insn_change *change : changes) { + // Count zero for the old cost if the old instruction was a no-op + // move or had an unknown cost. This should reduce the chances of + // making an unprofitable change. old_cost += change->old_cost (); basic_block cfg_bb = change->bb ()->cfg_bb (); bool for_speed = optimize_bb_for_speed_p (cfg_bb); if (for_speed) weighted_old_cost += (cfg_bb->count.to_sreal_scale (entry_count) * change->old_cost ()); - if (!change->is_deletion ()) + if (!change->is_deletion () + && INSN_CODE (change->rtl ()) != NOOP_MOVE_INSN_CODE) { change->new_cost = insn_cost (change->rtl (), for_speed); /* If the cost is unknown, replacement is not worthwhile. */ diff --git a/gcc/rtl-ssa/insns.cc b/gcc/rtl-ssa/insns.cc index 0171d93c357..68365e323ec 100644 --- a/gcc/rtl-ssa/insns.cc +++ b/gcc/rtl-ssa/insns.cc @@ -48,7 +48,12 @@ insn_info::calculate_cost () const { basic_block cfg_bb = BLOCK_FOR_INSN (m_rtl); temporarily_undo_changes (0); - m_cost_or_uid = insn_cost (m_rtl, optimize_bb_for_speed_p (cfg_bb)); + if (INSN_CODE (m_rtl) == NOOP_MOVE_INSN_CODE) + // insn_cost also uses 0 to mean "don't know". Callers that + // want to distinguish the cases will need to check INSN_CODE. + m_cost_or_uid = 0; + else + m_cost_or_uid = insn_cost (m_rtl, optimize_bb_for_speed_p (cfg_bb)); redo_changes (0); } -- 2.25.1