diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index c78ad6532d93..e9e6146c7597 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -5368,43 +5368,38 @@ bool CodeGenPrepare::sinkAndCmp(Function &F) { if (!TLI || !TLI->isMaskAndBranchFoldingLegal()) return false; bool MadeChange = false; - for (Function::iterator I = F.begin(), E = F.end(); I != E; ) { - BasicBlock *BB = &*I++; - + for (BasicBlock &BB : F) { // Does this BB end with the following? // %andVal = and %val, #single-bit-set // %icmpVal = icmp %andResult, 0 // br i1 %cmpVal label %dest1, label %dest2" - BranchInst *Brcc = dyn_cast(BB->getTerminator()); + BranchInst *Brcc = dyn_cast(BB.getTerminator()); if (!Brcc || !Brcc->isConditional()) continue; ICmpInst *Cmp = dyn_cast(Brcc->getOperand(0)); - if (!Cmp || Cmp->getParent() != BB) + if (!Cmp || Cmp->getParent() != &BB) continue; ConstantInt *Zero = dyn_cast(Cmp->getOperand(1)); if (!Zero || !Zero->isZero()) continue; Instruction *And = dyn_cast(Cmp->getOperand(0)); - if (!And || And->getOpcode() != Instruction::And || And->getParent() != BB) + if (!And || And->getOpcode() != Instruction::And || And->getParent() != &BB) continue; ConstantInt* Mask = dyn_cast(And->getOperand(1)); if (!Mask || !Mask->getUniqueInteger().isPowerOf2()) continue; - DEBUG(dbgs() << "found and; icmp ?,0; brcc\n"); DEBUG(BB->dump()); + DEBUG(dbgs() << "found and; icmp ?,0; brcc\n"); DEBUG(BB.dump()); // Push the "and; icmp" for any users that are conditional branches. // Since there can only be one branch use per BB, we don't need to keep // track of which BBs we insert into. - for (Value::use_iterator UI = Cmp->use_begin(), E = Cmp->use_end(); - UI != E; ) { - Use &TheUse = *UI; + for (Use &TheUse : Cmp->uses()) { // Find brcc use. - BranchInst *BrccUser = dyn_cast(*UI); - ++UI; + BranchInst *BrccUser = dyn_cast(TheUse); if (!BrccUser || !BrccUser->isConditional()) continue; BasicBlock *UserBB = BrccUser->getParent(); - if (UserBB == BB) continue; + if (UserBB == &BB) continue; DEBUG(dbgs() << "found Brcc use\n"); // Sink the "and; icmp" to use.