aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2024-06-21 15:40:10 +0100
committerRichard Sandiford <richard.sandiford@arm.com>2024-06-21 15:40:10 +0100
commit4a43a06c7b2bcc3402ac69d6e5ce7b8008acc69a (patch)
tree9064895fa23e9190b64f05052d62b59b20f81673
parent747a06017196b6344e3f664706a11231ba712548 (diff)
downloadgcc-4a43a06c7b2bcc3402ac69d6e5ce7b8008acc69a.zip
gcc-4a43a06c7b2bcc3402ac69d6e5ce7b8008acc69a.tar.gz
gcc-4a43a06c7b2bcc3402ac69d6e5ce7b8008acc69a.tar.bz2
rtl-ssa: Don't cost no-op moves
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.
-rw-r--r--gcc/rtl-ssa/changes.cc6
-rw-r--r--gcc/rtl-ssa/insns.cc7
2 files changed, 11 insertions, 2 deletions
diff --git a/gcc/rtl-ssa/changes.cc b/gcc/rtl-ssa/changes.cc
index 11639e8..3101f2d 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);
new_cost += change->new_cost;
diff --git a/gcc/rtl-ssa/insns.cc b/gcc/rtl-ssa/insns.cc
index 0171d93..68365e3 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);
}