aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineCopyPropagation.cpp
diff options
context:
space:
mode:
authorpvanhout <pierre.vanhoutryve@amd.com>2023-06-09 09:28:17 +0200
committerpvanhout <pierre.vanhoutryve@amd.com>2023-06-09 14:23:57 +0200
commitdf1782c2a2af9938ba4c5bacfab20d1ddebc82dd (patch)
treea00676098719aa0851aa7b22217e832aec772560 /llvm/lib/CodeGen/MachineCopyPropagation.cpp
parent90431ca2e01489eeff22e141714bb294315d6a3c (diff)
downloadllvm-df1782c2a2af9938ba4c5bacfab20d1ddebc82dd.zip
llvm-df1782c2a2af9938ba4c5bacfab20d1ddebc82dd.tar.gz
llvm-df1782c2a2af9938ba4c5bacfab20d1ddebc82dd.tar.bz2
[MCP] Do not remove redundant copy for COPY from undef
I don't think we can safely remove the second COPY as redundant in such cases. The first COPY (which has undef src) may be lowered to a KILL instruction instead, resulting in no COPY being emitted at all. Testcase is X86 so it's in the same place as other testcases for this function, but this was initially spotted on AMDGPU with the following: ``` renamable $vgpr24 = PRED_COPY undef renamable $vgpr25, implicit $exec renamable $vgpr24 = PRED_COPY killed renamable $vgpr25, implicit $exec ``` The second COPY waas removed as redundant, and the first one was lowered to a KILL (= removed too), causing $vgpr24 to not have $vgpr25's value. Fixes SWDEV-401507 Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D152502
Diffstat (limited to 'llvm/lib/CodeGen/MachineCopyPropagation.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineCopyPropagation.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/MachineCopyPropagation.cpp b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
index 1f1601b..03eac55 100644
--- a/llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -462,7 +462,8 @@ 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())
+ if (PrevCopyOperands->Destination->isDead() ||
+ PrevCopyOperands->Source->isUndef())
return false;
if (!isNopCopy(*PrevCopy, Src, Def, TRI, TII, UseCopyInstr))
return false;