Skip to content

Commit

Permalink
[LoopIdiomRecognize] Replace more unchecked dyn_casts with cast.
Browse files Browse the repository at this point in the history
Two of these are immediately dereferenced on the next line. The other two are passed immediately to the IRBuilder constructor which can't handle a nullptr.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331500 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
topperc committed May 4, 2018
1 parent 928cd2f commit eecfb9c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/Transforms/Scalar/LoopIdiomRecognize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,7 @@ static CallInst *createCTLZIntrinsic(IRBuilder<> &IRBuilder, Value *Val,
void LoopIdiomRecognize::transformLoopToCountable(
BasicBlock *Preheader, Instruction *CntInst, PHINode *CntPhi, Value *InitX,
const DebugLoc DL, bool ZeroCheck, bool IsCntPhiUsedOutsideLoop) {
BranchInst *PreheaderBr = dyn_cast<BranchInst>(Preheader->getTerminator());
BranchInst *PreheaderBr = cast<BranchInst>(Preheader->getTerminator());

// Step 1: Insert the CTLZ instruction at the end of the preheader block
// Count = BitWidth - CTLZ(InitX);
Expand Down Expand Up @@ -1587,7 +1587,7 @@ void LoopIdiomRecognize::transformLoopToCountable(
// ...
// Br: loop if (Dec != 0)
BasicBlock *Body = *(CurLoop->block_begin());
auto *LbBr = dyn_cast<BranchInst>(Body->getTerminator());
auto *LbBr = cast<BranchInst>(Body->getTerminator());
ICmpInst *LbCond = cast<ICmpInst>(LbBr->getCondition());
Type *Ty = Count->getType();

Expand Down Expand Up @@ -1624,7 +1624,7 @@ void LoopIdiomRecognize::transformLoopToPopcount(BasicBlock *PreCondBB,
Instruction *CntInst,
PHINode *CntPhi, Value *Var) {
BasicBlock *PreHead = CurLoop->getLoopPreheader();
auto *PreCondBr = dyn_cast<BranchInst>(PreCondBB->getTerminator());
auto *PreCondBr = cast<BranchInst>(PreCondBB->getTerminator());
const DebugLoc DL = CntInst->getDebugLoc();

// Assuming before transformation, the loop is following:
Expand Down Expand Up @@ -1695,7 +1695,7 @@ void LoopIdiomRecognize::transformLoopToPopcount(BasicBlock *PreCondBB,
// do { cnt++; x &= x-1; t--) } while (t > 0);
BasicBlock *Body = *(CurLoop->block_begin());
{
auto *LbBr = dyn_cast<BranchInst>(Body->getTerminator());
auto *LbBr = cast<BranchInst>(Body->getTerminator());
ICmpInst *LbCond = cast<ICmpInst>(LbBr->getCondition());
Type *Ty = TripCnt->getType();

Expand Down

0 comments on commit eecfb9c

Please sign in to comment.