summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorKarl-Johan Karlsson <karl-johan.karlsson@ericsson.com>2018-05-24 06:09:02 +0000
committerKarl-Johan Karlsson <karl-johan.karlsson@ericsson.com>2018-05-24 06:09:02 +0000
commit478232d52fe7023d0c00163d1a3099943cd71db0 (patch)
tree57082564b89c7d7d6d9b7b2a45e0bb4b16aa9cc9 /llvm/lib
parentc27ad9bbc8bf851235cdb87a09157016b0fac04b (diff)
downloadbcm5719-llvm-478232d52fe7023d0c00163d1a3099943cd71db0.tar.gz
bcm5719-llvm-478232d52fe7023d0c00163d1a3099943cd71db0.zip
[NaryReassociate] Detect deleted instr with WeakVH
Summary: If NaryReassociate succeed it will, when replacing the old instruction with the new instruction, also recursively delete trivially dead instructions from the old instruction. However, if the input to the NaryReassociate pass contain dead code it is not save to recursively delete trivially deadinstructions as it might lead to deleting the newly created instruction. This patch will fix the problem by using WeakVH to detect this rare case, when the newly created instruction is dead, and it will then restart the basic block iteration from the beginning. This fixes pr37539 Reviewers: tra, meheff, grosser, sanjoy Reviewed By: sanjoy Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D47139 llvm-svn: 333155
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/NaryReassociate.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/NaryReassociate.cpp b/llvm/lib/Transforms/Scalar/NaryReassociate.cpp
index 64e5e1c7cb1..e0370a5fe42 100644
--- a/llvm/lib/Transforms/Scalar/NaryReassociate.cpp
+++ b/llvm/lib/Transforms/Scalar/NaryReassociate.cpp
@@ -240,10 +240,17 @@ bool NaryReassociatePass::doOneIteration(Function &F) {
Changed = true;
SE->forgetValue(&*I);
I->replaceAllUsesWith(NewI);
- // If SeenExprs constains I's WeakTrackingVH, that entry will be
- // replaced with
- // nullptr.
+ WeakVH NewIExist = NewI;
+ // If SeenExprs/NewIExist contains I's WeakTrackingVH/WeakVH, that
+ // entry will be replaced with nullptr if deleted.
RecursivelyDeleteTriviallyDeadInstructions(&*I, TLI);
+ if (!NewIExist) {
+ // Rare occation where the new instruction (NewI) have been removed,
+ // probably due to parts of the input code was dead from the
+ // beginning, reset the iterator and start over from the beginning
+ I = BB->begin();
+ continue;
+ }
I = NewI->getIterator();
}
// Add the rewritten instruction to SeenExprs; the original instruction
OpenPOWER on IntegriCloud