diff options
author | Xin Tong <trent.xin.tong@gmail.com> | 2017-04-19 05:15:57 +0000 |
---|---|---|
committer | Xin Tong <trent.xin.tong@gmail.com> | 2017-04-19 05:15:57 +0000 |
commit | 636a332906b6b773935de7c3774c8b7389473d82 (patch) | |
tree | d72acc2d52918df963beeea6a40f0538ece78e85 /llvm/lib/Transforms/Scalar/JumpThreading.cpp | |
parent | 86652f262a0c8e1ad721d11e9258b6d64eb37369 (diff) | |
download | bcm5719-llvm-636a332906b6b773935de7c3774c8b7389473d82.tar.gz bcm5719-llvm-636a332906b6b773935de7c3774c8b7389473d82.zip |
[JumpThread] We want to fold (not thread) when all predecessor go to single BB's successor. .
Summary: In case all predecessor go to a single successor of current BB. We want to fold (not thread).
Reviewers: efriedma, sanjoy
Reviewed By: sanjoy
Subscribers: dberlin, majnemer, llvm-commits
Differential Revision: https://reviews.llvm.org/D30869
llvm-svn: 300657
Diffstat (limited to 'llvm/lib/Transforms/Scalar/JumpThreading.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/JumpThreading.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index 08eb95a1a3d..5d193c54282 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -1289,6 +1289,33 @@ bool JumpThreadingPass::ProcessThreadableEdges(Value *Cond, BasicBlock *BB, if (PredToDestList.empty()) return false; + // If all the predecessors go to a single known successor, we want to fold, + // not thread. By doing so, we do not need to duplicate the current block and + // also miss potential opportunities in case we don't/can't duplicate. + if (OnlyDest && OnlyDest != MultipleDestSentinel) { + if (PredToDestList.size() == + (size_t)std::distance(pred_begin(BB), pred_end(BB))) { + for (BasicBlock *SuccBB : successors(BB)) { + if (SuccBB != OnlyDest) + SuccBB->removePredecessor(BB, true); // This is unreachable successor. + } + + // Finally update the terminator. + TerminatorInst *Term = BB->getTerminator(); + BranchInst::Create(OnlyDest, Term); + Term->eraseFromParent(); + + // If the condition is now dead due to the removal of the old terminator, + // erase it. + auto *CondInst = dyn_cast<Instruction>(Cond); + if (CondInst && CondInst->use_empty()) + CondInst->eraseFromParent(); + // FIXME: in case this instruction is defined in the current BB and it + // resolves to a single value from all predecessors, we can do RAUW. + return true; + } + } + // Determine which is the most common successor. If we have many inputs and // this block is a switch, we want to start by threading the batch that goes // to the most popular destination first. If we only know about one |