From: Chandler Carruth Date: Thu, 18 Oct 2018 08:16:20 +0000 (+0000) Subject: [TI removal] Test predicate rather than casting to detect a terminator X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=59ea295b9359a868fdc5776898b31f449673bf8a;p=clang [TI removal] Test predicate rather than casting to detect a terminator and use the range based successor API. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@344730 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGLoopInfo.cpp b/lib/CodeGen/CGLoopInfo.cpp index 8f9a9b9607..be69e26d44 100644 --- a/lib/CodeGen/CGLoopInfo.cpp +++ b/lib/CodeGen/CGLoopInfo.cpp @@ -12,6 +12,7 @@ #include "clang/AST/Attr.h" #include "clang/Sema/LoopHint.h" #include "llvm/IR/BasicBlock.h" +#include "llvm/IR/CFG.h" #include "llvm/IR/Constants.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/Instructions.h" @@ -335,10 +336,10 @@ void LoopInfoStack::InsertHelper(Instruction *I) const { if (!L.getLoopID()) return; - if (TerminatorInst *TI = dyn_cast(I)) { - for (unsigned i = 0, ie = TI->getNumSuccessors(); i < ie; ++i) - if (TI->getSuccessor(i) == L.getHeader()) { - TI->setMetadata(llvm::LLVMContext::MD_loop, L.getLoopID()); + if (I->isTerminator()) { + for (BasicBlock *Succ : successors(I)) + if (Succ == L.getHeader()) { + I->setMetadata(llvm::LLVMContext::MD_loop, L.getLoopID()); break; } return;