@@ -625,8 +625,8 @@ bool LoopIdiomRecognize::runOnLoopBlock(
625
625
// We can only promote stores in this block if they are unconditionally
626
626
// executed in the loop. For a block to be unconditionally executed, it has
627
627
// to dominate all the exit blocks of the loop. Verify this now.
628
- for (unsigned i = 0 , e = ExitBlocks. size (); i != e; ++i )
629
- if (!DT->dominates (BB, ExitBlocks[i] ))
628
+ for (BasicBlock *ExitBlock : ExitBlocks)
629
+ if (!DT->dominates (BB, ExitBlock ))
630
630
return false ;
631
631
632
632
bool MadeChange = false ;
@@ -750,16 +750,13 @@ bool LoopIdiomRecognize::processLoopStores(SmallVectorImpl<StoreInst *> &SL,
750
750
bool Changed = false ;
751
751
752
752
// For stores that start but don't end a link in the chain:
753
- for (SetVector<StoreInst *>::iterator it = Heads.begin (), e = Heads.end ();
754
- it != e; ++it) {
755
- if (Tails.count (*it))
753
+ for (StoreInst *I : Heads) {
754
+ if (Tails.count (I))
756
755
continue ;
757
756
758
757
// We found a store instr that starts a chain. Now follow the chain and try
759
758
// to transform it.
760
759
SmallPtrSet<Instruction *, 8 > AdjacentStores;
761
- StoreInst *I = *it;
762
-
763
760
StoreInst *HeadStore = I;
764
761
unsigned StoreSize = 0 ;
765
762
@@ -1020,9 +1017,8 @@ mayLoopAccessLocation(Value *Ptr, ModRefInfo Access, Loop *L,
1020
1017
// which will then no-alias a store to &A[100].
1021
1018
MemoryLocation StoreLoc (Ptr, AccessSize);
1022
1019
1023
- for (Loop::block_iterator BI = L->block_begin (), E = L->block_end (); BI != E;
1024
- ++BI)
1025
- for (Instruction &I : **BI)
1020
+ for (BasicBlock *B : L->blocks ())
1021
+ for (Instruction &I : *B)
1026
1022
if (IgnoredInsts.count (&I) == 0 &&
1027
1023
isModOrRefSet (
1028
1024
intersectModRef (AA.getModRefInfo (&I, StoreLoc), Access)))
@@ -1675,32 +1671,30 @@ static bool detectPopcountIdiom(Loop *CurLoop, BasicBlock *PreCondBB,
1675
1671
// step 4: Find the instruction which count the population: cnt2 = cnt1 + 1
1676
1672
{
1677
1673
CountInst = nullptr ;
1678
- for (BasicBlock::iterator Iter = LoopEntry->getFirstNonPHI ()->getIterator (),
1679
- IterE = LoopEntry->end ();
1680
- Iter != IterE; Iter++) {
1681
- Instruction *Inst = &*Iter;
1682
- if (Inst->getOpcode () != Instruction::Add)
1674
+ for (Instruction &Inst : llvm::make_range (
1675
+ LoopEntry->getFirstNonPHI ()->getIterator (), LoopEntry->end ())) {
1676
+ if (Inst.getOpcode () != Instruction::Add)
1683
1677
continue ;
1684
1678
1685
- ConstantInt *Inc = dyn_cast<ConstantInt>(Inst-> getOperand (1 ));
1679
+ ConstantInt *Inc = dyn_cast<ConstantInt>(Inst. getOperand (1 ));
1686
1680
if (!Inc || !Inc->isOne ())
1687
1681
continue ;
1688
1682
1689
- PHINode *Phi = getRecurrenceVar (Inst-> getOperand (0 ), Inst, LoopEntry);
1683
+ PHINode *Phi = getRecurrenceVar (Inst. getOperand (0 ), & Inst, LoopEntry);
1690
1684
if (!Phi)
1691
1685
continue ;
1692
1686
1693
1687
// Check if the result of the instruction is live of the loop.
1694
1688
bool LiveOutLoop = false ;
1695
- for (User *U : Inst-> users ()) {
1689
+ for (User *U : Inst. users ()) {
1696
1690
if ((cast<Instruction>(U))->getParent () != LoopEntry) {
1697
1691
LiveOutLoop = true ;
1698
1692
break ;
1699
1693
}
1700
1694
}
1701
1695
1702
1696
if (LiveOutLoop) {
1703
- CountInst = Inst;
1697
+ CountInst = & Inst;
1704
1698
CountPhi = Phi;
1705
1699
break ;
1706
1700
}
@@ -1801,22 +1795,20 @@ static bool detectShiftUntilZeroIdiom(Loop *CurLoop, const DataLayout &DL,
1801
1795
// plus "cnt0". Currently it is not optimized.
1802
1796
// This step could be used to detect POPCNT instruction:
1803
1797
// cnt.next = cnt + (x.next & 1)
1804
- for (BasicBlock::iterator Iter = LoopEntry->getFirstNonPHI ()->getIterator (),
1805
- IterE = LoopEntry->end ();
1806
- Iter != IterE; Iter++) {
1807
- Instruction *Inst = &*Iter;
1808
- if (Inst->getOpcode () != Instruction::Add)
1798
+ for (Instruction &Inst : llvm::make_range (
1799
+ LoopEntry->getFirstNonPHI ()->getIterator (), LoopEntry->end ())) {
1800
+ if (Inst.getOpcode () != Instruction::Add)
1809
1801
continue ;
1810
1802
1811
- ConstantInt *Inc = dyn_cast<ConstantInt>(Inst-> getOperand (1 ));
1803
+ ConstantInt *Inc = dyn_cast<ConstantInt>(Inst. getOperand (1 ));
1812
1804
if (!Inc || (!Inc->isOne () && !Inc->isMinusOne ()))
1813
1805
continue ;
1814
1806
1815
- PHINode *Phi = getRecurrenceVar (Inst-> getOperand (0 ), Inst, LoopEntry);
1807
+ PHINode *Phi = getRecurrenceVar (Inst. getOperand (0 ), & Inst, LoopEntry);
1816
1808
if (!Phi)
1817
1809
continue ;
1818
1810
1819
- CntInst = Inst;
1811
+ CntInst = & Inst;
1820
1812
CntPhi = Phi;
1821
1813
break ;
1822
1814
}
0 commit comments