aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineCopyPropagation.cpp
diff options
context:
space:
mode:
authorpvanhout <pierre.vanhoutryve@amd.com>2023-06-26 17:59:55 +0200
committerpvanhout <pierre.vanhoutryve@amd.com>2023-06-29 15:12:27 +0200
commitc59f9eada1abe369c0470aa2dad8b20ac5269020 (patch)
treeeda8e2fdece60b024c1714f62ddc36f08bb77105 /llvm/lib/CodeGen/MachineCopyPropagation.cpp
parent5e87ec1e19ce0226ff7c812db07aec1734c407b3 (diff)
downloadllvm-c59f9eada1abe369c0470aa2dad8b20ac5269020.zip
llvm-c59f9eada1abe369c0470aa2dad8b20ac5269020.tar.gz
llvm-c59f9eada1abe369c0470aa2dad8b20ac5269020.tar.bz2
[MCP] Optimize copies from undef
Revert 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 Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D153838
Diffstat (limited to 'llvm/lib/CodeGen/MachineCopyPropagation.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineCopyPropagation.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/MachineCopyPropagation.cpp b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
index 26110a1..3453e6c 100644
--- a/llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -462,8 +462,7 @@ bool MachineCopyPropagation::eraseIfRedundant(MachineInstr &Copy,
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 @@ bool MachineCopyPropagation::eraseIfRedundant(MachineInstr &Copy,
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;