diff options
author | weiguozhi <57237827+weiguozhi@users.noreply.github.com> | 2023-10-20 08:34:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-20 08:34:43 -0700 |
commit | 24633eac38d46cd4b253ba53258165ee08d886cd (patch) | |
tree | ca9d263b4de27a1fe40ff21cdd6bb6146be9b4d9 /llvm/lib/CodeGen/PeepholeOptimizer.cpp | |
parent | 17baba9fa2728b1b1134f9dccb9318debd5a9a1b (diff) | |
download | llvm-24633eac38d46cd4b253ba53258165ee08d886cd.zip llvm-24633eac38d46cd4b253ba53258165ee08d886cd.tar.gz llvm-24633eac38d46cd4b253ba53258165ee08d886cd.tar.bz2 |
[Peephole] Check instructions from CopyMIs are still COPY (#69511)
Function foldRedundantCopy records COPY instructions in CopyMIs and uses
it later. But other optimizations may delete or modify it. So before
using it we should check if the extracted instruction is existing and
still a COPY instruction.
Diffstat (limited to 'llvm/lib/CodeGen/PeepholeOptimizer.cpp')
-rw-r--r-- | llvm/lib/CodeGen/PeepholeOptimizer.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/PeepholeOptimizer.cpp b/llvm/lib/CodeGen/PeepholeOptimizer.cpp index f413ca5..09ae268 100644 --- a/llvm/lib/CodeGen/PeepholeOptimizer.cpp +++ b/llvm/lib/CodeGen/PeepholeOptimizer.cpp @@ -1445,7 +1445,9 @@ bool PeepholeOptimizer::foldRedundantCopy( } MachineInstr *PrevCopy = CopyMIs.find(SrcPair)->second; - if (!LocalMIs.count(PrevCopy)) + // A COPY instruction can be deleted or changed by other optimizations. + // Check if the previous COPY instruction is existing and still a COPY. + if (!LocalMIs.count(PrevCopy) || !PrevCopy->isCopy()) return false; assert(SrcSubReg == PrevCopy->getOperand(1).getSubReg() && |