@@ -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. */
@@ -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);
}