aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index 1159cd36f5..3c6c02f7e9 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1426,8 +1426,8 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
PBI->setSuccessor(1, OldTrue);
}
- if (PBI->getSuccessor(0) == TrueDest ||
- PBI->getSuccessor(1) == FalseDest) {
+ if ((PBI->getSuccessor(0) == TrueDest && FalseDest != BB) ||
+ (PBI->getSuccessor(1) == FalseDest && TrueDest != BB)) {
// Clone Cond into the predecessor basic block, and or/and the
// two conditions together.
Instruction *New = Cond->clone();
@@ -1512,6 +1512,12 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
PBIOp = BIOp = -1;
}
+ // Check to make sure that the other destination of this branch
+ // isn't BB itself. If so, this is an infinite loop that will
+ // keep getting unwound.
+ if (PBIOp != -1 && PBI->getSuccessor(PBIOp) == BB)
+ PBIOp = BIOp = -1;
+
// Finally, if everything is ok, fold the branches to logical ops.
if (PBIOp != -1) {
BasicBlock *CommonDest = PBI->getSuccessor(PBIOp);