[PATCH] D41463: [CodeGen] Add a new pass to sink Copy instructions after RA
Jun Bum Lim via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 20 13:58:03 PST 2017
junbuml created this revision.
junbuml added reviewers: qcolombet, MatzeB, thegameg, mcrosier, gberry, hfinkel.
Herald added subscribers: kristof.beyls, javed.absar, mgorny, aemerson.
This pass sink COPY instructions into a successor close to their use, if
unused in the current block. In the CodeGen phase, COPY instructions are
added in some passes (e.g., ISel and PhiElimination), which are not handled
in MachineSink pass. For example, in AArch64, ISel adds Copy instructions to
move function parameters (PhyReg) to virtual registers in the entry block.
Before RA, MachineSink cannot sink such Copy instructions because SrcReg is
an allocatable PhyReg. By sinking such COPY instructions to successors close
to its actual use, we can avoid executing instructions in case the result is
not used. Also, it will open up more opportunities for other optimizations
(e.g., dead copy elimination in MachineCopyPropagation and shrink-wrapping).
For example, for the machine IR below, this pass will sink %w19 in the entry
into its successor (%bb.1) because %w19 is only live-in in %bb.1.
%bb.0:
%wzr = SUBSWri %w1, 1
%w19 = COPY %w0
Bcc 11, %bb.2
%bb.1:
Live Ins: %w19
BL @fun
%w0 = ADDWrr %w0, %w19
RET %w0
%bb.2:
%w0 = COPY %wzr
RET %w0
As we sink %w19 (CSR in AArch64) into %bb.1, the shrink-wrapping pass will be
able to see %bb.0 as a candidate.
With this change I observed 12% more shrink-wrapping candidate and 13% more dead copies deleted in spec2000/2006/2017 on AArch64.
https://reviews.llvm.org/D41463
Files:
include/llvm/CodeGen/Passes.h
include/llvm/InitializePasses.h
lib/CodeGen/CMakeLists.txt
lib/CodeGen/CodeGen.cpp
lib/CodeGen/MachineCopySink.cpp
lib/CodeGen/TargetPassConfig.cpp
test/CodeGen/AArch64/post-rs-copy-sink.mir
test/CodeGen/AArch64/sink-copy-for-shrink-wrap.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41463.127782.patch
Type: text/x-patch
Size: 18479 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171220/bdd6331c/attachment.bin>
More information about the llvm-commits
mailing list