Index: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp =================================================================== --- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp +++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1864,12 +1864,9 @@ // Look for a store to the same pointer in BrBB. unsigned MaxNumInstToLookAt = 9; - for (Instruction &CurI : reverse(*BrBB)) { + for (Instruction &CurI : reverse(BrBB->instructionsWithoutDebug())) { if (!MaxNumInstToLookAt) break; - // Skip debug info. - if (isa(CurI)) - continue; --MaxNumInstToLookAt; // Could be calling an instruction that affects memory like free(). @@ -2119,19 +2116,16 @@ /// Return true if we can thread a branch across this block. static bool BlockIsSimpleEnoughToThreadThrough(BasicBlock *BB) { - BranchInst *BI = cast(BB->getTerminator()); unsigned Size = 0; - for (BasicBlock::iterator BBI = BB->begin(); &*BBI != BI; ++BBI) { - if (isa(BBI)) - continue; + for (Instruction &I : BB->instructionsWithoutDebug()) { if (Size > 10) return false; // Don't clone large BB's. ++Size; // We can only support instructions that do not define values that are // live outside of the current basic block. - for (User *U : BBI->users()) { + for (User *U : I.users()) { Instruction *UI = cast(U); if (UI->getParent() != BB || isa(UI)) return false; @@ -2920,14 +2914,13 @@ // instructions inside are all cheap (arithmetic/GEPs), it's worthwhile to // thread this store. unsigned N = 0; - for (auto &I : *BB) { + for (auto &I : BB->instructionsWithoutDebug()) { // Cheap instructions viable for folding. if (isa(I) || isa(I) || isa(I)) ++N; // Free instructions. - else if (isa(I) || isa(I) || - IsaBitcastOfPointerType(I)) + else if (isa(I) || IsaBitcastOfPointerType(I)) continue; else return false; @@ -3232,11 +3225,9 @@ // If this is a conditional branch in an empty block, and if any // predecessors are a conditional branch to one of our destinations, // fold the conditions into logical ops and one cond br. - BasicBlock::iterator BBI = BB->begin(); + // Ignore dbg intrinsics. - while (isa(BBI)) - ++BBI; - if (&*BBI != BI) + if (&*BB->instructionsWithoutDebug().begin() != BI) return false; int PBIOp, BIOp; @@ -4639,24 +4630,20 @@ // which we can constant-propagate the CaseVal, continue to its successor. SmallDenseMap ConstantPool; ConstantPool.insert(std::make_pair(SI->getCondition(), CaseVal)); - for (BasicBlock::iterator I = CaseDest->begin(), E = CaseDest->end(); I != E; - ++I) { - if (TerminatorInst *T = dyn_cast(I)) { + for (Instruction &I :CaseDest->instructionsWithoutDebug()) { + if (TerminatorInst *T = dyn_cast(&I)) { // If the terminator is a simple branch, continue to the next block. if (T->getNumSuccessors() != 1 || T->isExceptional()) return false; Pred = CaseDest; CaseDest = T->getSuccessor(0); - } else if (isa(I)) { - // Skip debug intrinsic. - continue; - } else if (Constant *C = ConstantFold(&*I, DL, ConstantPool)) { + } else if (Constant *C = ConstantFold(&I, DL, ConstantPool)) { // Instruction is side-effect free and constant. // If the instruction has uses outside this block or a phi node slot for // the block, it is not safe to bypass the instruction since it would then // no longer dominate all its uses. - for (auto &Use : I->uses()) { + for (auto &Use : I.uses()) { User *User = Use.getUser(); if (Instruction *I = dyn_cast(User)) if (I->getParent() == CaseDest) @@ -4667,7 +4654,7 @@ return false; } - ConstantPool.insert(std::make_pair(&*I, C)); + ConstantPool.insert(std::make_pair(&I, C)); } else { break; } @@ -5602,11 +5589,7 @@ // If the block only contains the switch, see if we can fold the block // away into any preds. - BasicBlock::iterator BBI = BB->begin(); - // Ignore dbg intrinsics. - while (isa(BBI)) - ++BBI; - if (SI == &*BBI) + if (SI == &*BB->instructionsWithoutDebug().begin()) if (FoldValueComparisonIntoPredecessors(SI, Builder)) return simplifyCFG(BB, TTI, Options) | true; } @@ -5833,18 +5816,12 @@ // This block must be empty, except for the setcond inst, if it exists. // Ignore dbg intrinsics. - BasicBlock::iterator I = BB->begin(); - // Ignore dbg intrinsics. - while (isa(I)) - ++I; + auto I = BB->instructionsWithoutDebug().begin(); if (&*I == BI) { if (FoldValueComparisonIntoPredecessors(BI, Builder)) return simplifyCFG(BB, TTI, Options) | true; } else if (&*I == cast(BI->getCondition())) { ++I; - // Ignore dbg intrinsics. - while (isa(I)) - ++I; if (&*I == BI && FoldValueComparisonIntoPredecessors(BI, Builder)) return simplifyCFG(BB, TTI, Options) | true; }