[PATCH] D153838: [MCP] Optimize copies from undef
Pierre van Houtryve via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 27 00:27:37 PDT 2023
Pierre-vh created this revision.
Pierre-vh added reviewers: arsenm, foad, critson, qcolombet.
Herald added subscribers: StephenFan, pengfei, hiraditya.
Herald added a project: All.
Pierre-vh requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.
Revert D152502 <https://reviews.llvm.org/D152502> and instead optimize away copy from undefs, but clear the undef flag on the original copy.
Apparently, not optimizing the COPY can cause performance issues in some cases.
Fixes SWDEV-405813, SWDEV-405899
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D153838
Files:
llvm/lib/CodeGen/MachineCopyPropagation.cpp
llvm/test/CodeGen/X86/machine-copy-prop.mir
Index: llvm/test/CodeGen/X86/machine-copy-prop.mir
===================================================================
--- llvm/test/CodeGen/X86/machine-copy-prop.mir
+++ llvm/test/CodeGen/X86/machine-copy-prop.mir
@@ -220,9 +220,8 @@
# second COPY, otherwise we risk making $rax undef.
# CHECK-LABEL: name: nocopyprop6
# CHECK: bb.0:
-# CHECK: $rax = COPY undef $rdi
-# CHECK-NEXT: NOOP implicit killed $rax
-# CHECK-NEXT: $rax = COPY $rdi
+# CHECK: $rax = COPY $rdi
+# CHECK-NEXT: NOOP implicit $rax
# CHECK-NEXT: NOOP implicit $rax, implicit $rdi
name: nocopyprop6
tracksRegLiveness: true
Index: llvm/lib/CodeGen/MachineCopyPropagation.cpp
===================================================================
--- llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -462,8 +462,7 @@
auto PrevCopyOperands = isCopyInstr(*PrevCopy, *TII, UseCopyInstr);
// Check that the existing copy uses the correct sub registers.
- if (PrevCopyOperands->Destination->isDead() ||
- PrevCopyOperands->Source->isUndef())
+ if (PrevCopyOperands->Destination->isDead())
return false;
if (!isNopCopy(*PrevCopy, Src, Def, TRI, TII, UseCopyInstr))
return false;
@@ -482,6 +481,12 @@
make_range(PrevCopy->getIterator(), Copy.getIterator()))
MI.clearRegisterKills(CopyDef, TRI);
+ // Clear undef flag from remaining copy if needed.
+ if (!CopyOperands->Source->isUndef()) {
+ PrevCopy->getOperand(PrevCopyOperands->Source->getOperandNo())
+ .setIsUndef(false);
+ }
+
Copy.eraseFromParent();
Changed = true;
++NumDeletes;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153838.534854.patch
Type: text/x-patch
Size: 1621 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230627/cd123ab2/attachment.bin>
More information about the llvm-commits
mailing list