[llvm] [MCP] Enhance MCP copy Instruction removal for special case (PR #70778)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 31 06:19:12 PDT 2023
================
@@ -735,6 +736,27 @@ void MachineCopyPropagation::ForwardCopyPropagateBlock(MachineBasicBlock &MBB) {
MCRegister Def = RegDef.asMCReg();
MCRegister Src = RegSrc.asMCReg();
+ // Target may lost some opportunity to further remove the redundant
+ // copy instruction, consider the following sequence:
+ // L1: r0 = COPY r9 <- TrackMI
+ // L2: r0 = COPY r8 <- TrackMI
+ // L3: use r0 <- Remove L2 from MaybeDeadCopies
+ // L4: early-clobber r9 <- Invalid L2 from Tracker
+ // L5: r0 = COPY r8 <- Miss remove chance
+ // L6: use r0 <- Miss remove L5 chance
+ if (LastMI) {
+ std::optional<DestSourcePair> PrevCopyOperands =
+ isCopyInstr(*LastMI, *TII, UseCopyInstr);
+ if (PrevCopyOperands) {
+ Register PrevRegDef = PrevCopyOperands->Destination->getReg();
+ // We could remove the previous copy from tracker directly.
+ if (TRI->isSubRegisterEq(RegDef, PrevRegDef)) {
----------------
LWenH wrote:
Thank you for your comment. I think it might be a better way to remove the related record(the copy def record) in the tracker when we reach another new copy with the same def.
https://github.com/llvm/llvm-project/pull/70778
More information about the llvm-commits
mailing list