aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineCopyPropagation.cpp
diff options
context:
space:
mode:
authorAlex Bradbury <asb@igalia.com>2025-05-08 12:33:14 +0100
committerGitHub <noreply@github.com>2025-05-08 12:33:14 +0100
commit52b345d036677e6377ea5e2022a1b6bd403ed91e (patch)
tree9a946397974d40249a3d5e7e5cb52911dccba607 /llvm/lib/CodeGen/MachineCopyPropagation.cpp
parent245def9def7b025644a8cf991ba24c53a50822c6 (diff)
downloadllvm-52b345d036677e6377ea5e2022a1b6bd403ed91e.zip
llvm-52b345d036677e6377ea5e2022a1b6bd403ed91e.tar.gz
llvm-52b345d036677e6377ea5e2022a1b6bd403ed91e.tar.bz2
[RISCV][TII] Add and use new hook to simplify/canonicalize instructions after MachineCopyPropagation (#137973)
PR #136875 was posted as a draft PR that handled a subset of these cases, using the CompressPat mechanism. The consensus from that discussion (and a conclusion I agree with) is that it would be beneficial doing this optimisation earlier on, and in a way that isn't limited just to cases that can be handled by instruction compression. The most common source for instructions that can be optimized/canonicalized in this way is through tail duplication in MachineBlockPlacement followed by machine copy propagation. For RISC-V, choosing a more canonical instruction allows it to be compressed when it couldn't be before. There is the potential that it would make other MI-level optimisations easier. This modifies ~910 instructions across an llvm-test-suite build including SPEC2017, targeting rva22u64. Looking at the diff, it seems there's room for eliminating instructions or further propagating after this. Coverage of instructions is based on observations from a script written to find redundant or improperly canonicalized instructions (though I aim to support all instructions in a 'group' at once, e.g. MUL* even if I only saw some variants of MUL in practice).
Diffstat (limited to 'llvm/lib/CodeGen/MachineCopyPropagation.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineCopyPropagation.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MachineCopyPropagation.cpp b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
index ff75b87..224588b 100644
--- a/llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -870,6 +870,12 @@ void MachineCopyPropagation::forwardUses(MachineInstr &MI) {
++NumCopyForwards;
Changed = true;
}
+ // Attempt to canonicalize/optimize the instruction now its arguments have
+ // been mutated.
+ if (TII->simplifyInstruction(MI)) {
+ Changed = true;
+ LLVM_DEBUG(dbgs() << "MCP: After optimizeInstruction: " << MI);
+ }
}
void MachineCopyPropagation::ForwardCopyPropagateBlock(MachineBasicBlock &MBB) {