summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/IR/Instruction.cpp7
-rw-r--r--llvm/lib/Transforms/Utils/LoopSimplify.cpp4
2 files changed, 8 insertions, 3 deletions
diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp
index f15bd601727..42a7a1cce7f 100644
--- a/llvm/lib/IR/Instruction.cpp
+++ b/llvm/lib/IR/Instruction.cpp
@@ -675,6 +675,13 @@ void Instruction::setSuccessor(unsigned idx, BasicBlock *B) {
llvm_unreachable("not a terminator");
}
+void Instruction::replaceSuccessorWith(BasicBlock *OldBB, BasicBlock *NewBB) {
+ for (unsigned Idx = 0, NumSuccessors = Instruction::getNumSuccessors();
+ Idx != NumSuccessors; ++Idx)
+ if (getSuccessor(Idx) == OldBB)
+ setSuccessor(Idx, NewBB);
+}
+
Instruction *Instruction::cloneImpl() const {
llvm_unreachable("Subclass of Instruction failed to implement cloneImpl");
}
diff --git a/llvm/lib/Transforms/Utils/LoopSimplify.cpp b/llvm/lib/Transforms/Utils/LoopSimplify.cpp
index b076e6ffc53..194cb5d302d 100644
--- a/llvm/lib/Transforms/Utils/LoopSimplify.cpp
+++ b/llvm/lib/Transforms/Utils/LoopSimplify.cpp
@@ -443,9 +443,7 @@ static BasicBlock *insertUniqueBackedgeBlock(Loop *L, BasicBlock *Preheader,
if (!LoopMD)
LoopMD = TI->getMetadata(LoopMDKind);
TI->setMetadata(LoopMDKind, nullptr);
- for (unsigned Op = 0, e = TI->getNumSuccessors(); Op != e; ++Op)
- if (TI->getSuccessor(Op) == Header)
- TI->setSuccessor(Op, BEBlock);
+ TI->replaceSuccessorWith(Header, BEBlock);
}
BEBlock->getTerminator()->setMetadata(LoopMDKind, LoopMD);
OpenPOWER on IntegriCloud