aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineCopyPropagation.cpp
diff options
context:
space:
mode:
authorAlex Bradbury <asb@igalia.com>2025-03-10 13:22:59 +0000
committerGitHub <noreply@github.com>2025-03-10 13:22:59 +0000
commitdffbc030e75b758e7512518abd499a0f680addbf (patch)
tree28ef53e3b2ee904aa4cc8263550521f7a65e0162 /llvm/lib/CodeGen/MachineCopyPropagation.cpp
parent4e453d52920b1808321ec9bca28f5161165d12ee (diff)
downloadllvm-dffbc030e75b758e7512518abd499a0f680addbf.zip
llvm-dffbc030e75b758e7512518abd499a0f680addbf.tar.gz
llvm-dffbc030e75b758e7512518abd499a0f680addbf.tar.bz2
[MachineCopyPropagation] Recognise and delete no-op moves produced after forwarded uses (#129889)
This change removes 189 static instances of no-op reg-reg moves (i.e. where src == dest) across llvm-test-suite when compiled for RISC-V rv64gc and with SPEC included.
Diffstat (limited to 'llvm/lib/CodeGen/MachineCopyPropagation.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineCopyPropagation.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MachineCopyPropagation.cpp b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
index 1105b8c..5102639 100644
--- a/llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -971,6 +971,19 @@ void MachineCopyPropagation::ForwardCopyPropagateBlock(MachineBasicBlock &MBB) {
forwardUses(MI);
+ // It's possible that the previous transformation has resulted in a no-op
+ // register move (i.e. one where source and destination registers are the
+ // same and are not referring to a reserved register). If so, delete it.
+ CopyOperands = isCopyInstr(MI, *TII, UseCopyInstr);
+ if (CopyOperands &&
+ CopyOperands->Source->getReg() == CopyOperands->Destination->getReg() &&
+ !MRI->isReserved(CopyOperands->Source->getReg())) {
+ MI.eraseFromParent();
+ NumDeletes++;
+ Changed = true;
+ continue;
+ }
+
// Not a copy.
SmallVector<Register, 4> Defs;
const MachineOperand *RegMask = nullptr;