diff options
author | David Stenberg <david.stenberg@ericsson.com> | 2018-05-18 08:52:15 +0000 |
---|---|---|
committer | David Stenberg <david.stenberg@ericsson.com> | 2018-05-18 08:52:15 +0000 |
commit | 0af67e5b651b49220af5101f1592bd9a2e314c0e (patch) | |
tree | b4db302439f7c7ab1d414100eafab6f40374006c /llvm/lib/Transforms/Utils/SimplifyCFG.cpp | |
parent | da3f49a435004f588baa4e2bb2dd352bef753a15 (diff) | |
download | bcm5719-llvm-0af67e5b651b49220af5101f1592bd9a2e314c0e.tar.gz bcm5719-llvm-0af67e5b651b49220af5101f1592bd9a2e314c0e.zip |
[SimplifyCFG] Fix a debug invariant bug in FoldBranchToCommonDest()
Summary:
Fix a case where FoldBranchToCommonDest() would bail out from doing CSE
when encountering a debug intrinsic. Handle that by skipping past the
debug intrinsics.
Also, as a minor refactoring, rename checkCSEInPredecessor() to
tryCSEWithPredecessor() to make it a bit more clear that the function
may remove instructions.
Reviewers: fhahn, craig.topper, dblaikie, xbolva00
Reviewed By: fhahn, xbolva00
Subscribers: vsk, davide, llvm-commits
Differential Revision: https://reviews.llvm.org/D46635
llvm-svn: 332698
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 833e13f890d..c38164e6bd1 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -2498,7 +2498,7 @@ static bool SimplifyCondBranchToTwoReturns(BranchInst *BI, /// Return true if the given instruction is available /// in its predecessor block. If yes, the instruction will be removed. -static bool checkCSEInPredecessor(Instruction *Inst, BasicBlock *PB) { +static bool tryCSEWithPredecessor(Instruction *Inst, BasicBlock *PB) { if (!isa<BinaryOperator>(Inst) && !isa<CmpInst>(Inst)) return false; for (Instruction &I : *PB) { @@ -2555,14 +2555,16 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, unsigned BonusInstThreshold) { if (PBI->isConditional() && (BI->getSuccessor(0) == PBI->getSuccessor(0) || BI->getSuccessor(0) == PBI->getSuccessor(1))) { - for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;) { + for (auto I = BB->instructionsWithoutDebug().begin(), + E = BB->instructionsWithoutDebug().end(); + I != E;) { Instruction *Curr = &*I++; if (isa<CmpInst>(Curr)) { Cond = Curr; break; } // Quit if we can't remove this instruction. - if (!checkCSEInPredecessor(Curr, PB)) + if (!tryCSEWithPredecessor(Curr, PB)) return false; } } |