Skip to content

Commit 2a35414

Browse files
[Transforms] Use range-based for loops (NFC) (#145252)
Co-authored-by: Matt Arsenault <[email protected]>
1 parent 86026ee commit 2a35414

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

llvm/lib/Transforms/IPO/GlobalOpt.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,10 @@ CleanupPointerRootUsers(GlobalVariable *GV,
250250
}
251251
}
252252

253-
for (int i = 0, e = Dead.size(); i != e; ++i) {
254-
if (IsSafeComputationToRemove(Dead[i].first, GetTLI)) {
255-
Dead[i].second->eraseFromParent();
256-
Instruction *I = Dead[i].first;
253+
for (const auto &[Inst, Store] : Dead) {
254+
if (IsSafeComputationToRemove(Inst, GetTLI)) {
255+
Store->eraseFromParent();
256+
Instruction *I = Inst;
257257
do {
258258
if (isAllocationFn(I, GetTLI))
259259
break;

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3494,13 +3494,13 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
34943494
auto Removable =
34953495
isAllocSiteRemovable(&MI, Users, TLI, KnowInitZero | KnowInitUndef);
34963496
if (Removable) {
3497-
for (unsigned i = 0, e = Users.size(); i != e; ++i) {
3497+
for (WeakTrackingVH &User : Users) {
34983498
// Lowering all @llvm.objectsize and MTI calls first because they may use
34993499
// a bitcast/GEP of the alloca we are removing.
3500-
if (!Users[i])
3501-
continue;
3500+
if (!User)
3501+
continue;
35023502

3503-
Instruction *I = cast<Instruction>(&*Users[i]);
3503+
Instruction *I = cast<Instruction>(&*User);
35043504

35053505
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
35063506
if (II->getIntrinsicID() == Intrinsic::objectsize) {
@@ -3511,7 +3511,7 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
35113511
Worklist.add(Inserted);
35123512
replaceInstUsesWith(*I, Result);
35133513
eraseInstFromFunction(*I);
3514-
Users[i] = nullptr; // Skip examining in the next loop.
3514+
User = nullptr; // Skip examining in the next loop.
35153515
continue;
35163516
}
35173517
if (auto *MTI = dyn_cast<MemTransferInst>(I)) {
@@ -3527,11 +3527,11 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
35273527
}
35283528
}
35293529
}
3530-
for (unsigned i = 0, e = Users.size(); i != e; ++i) {
3531-
if (!Users[i])
3530+
for (WeakTrackingVH &User : Users) {
3531+
if (!User)
35323532
continue;
35333533

3534-
Instruction *I = cast<Instruction>(&*Users[i]);
3534+
Instruction *I = cast<Instruction>(&*User);
35353535

35363536
if (ICmpInst *C = dyn_cast<ICmpInst>(I)) {
35373537
replaceInstUsesWith(*C,

llvm/lib/Transforms/Scalar/LoopInterchange.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ static bool populateDependencyMatrix(CharMatrix &DepMatrix, unsigned Level,
235235
// matrix by exchanging the two columns.
236236
static void interChangeDependencies(CharMatrix &DepMatrix, unsigned FromIndx,
237237
unsigned ToIndx) {
238-
for (unsigned I = 0, E = DepMatrix.size(); I < E; ++I)
239-
std::swap(DepMatrix[I][ToIndx], DepMatrix[I][FromIndx]);
238+
for (auto &Row : DepMatrix)
239+
std::swap(Row[ToIndx], Row[FromIndx]);
240240
}
241241

242242
// Check if a direction vector is lexicographically positive. Return true if it

llvm/lib/Transforms/Scalar/Reassociate.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ static void PrintOps(Instruction *I, const SmallVectorImpl<ValueEntry> &Ops) {
8383
Module *M = I->getModule();
8484
dbgs() << Instruction::getOpcodeName(I->getOpcode()) << " "
8585
<< *Ops[0].Op->getType() << '\t';
86-
for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
86+
for (const ValueEntry &Op : Ops) {
8787
dbgs() << "[ ";
88-
Ops[i].Op->printAsOperand(dbgs(), false, M);
89-
dbgs() << ", #" << Ops[i].Rank << "] ";
88+
Op.Op->printAsOperand(dbgs(), false, M);
89+
dbgs() << ", #" << Op.Rank << "] ";
9090
}
9191
}
9292
#endif
@@ -1585,9 +1585,9 @@ Value *ReassociatePass::OptimizeAdd(Instruction *I,
15851585
// where they are actually the same multiply.
15861586
unsigned MaxOcc = 0;
15871587
Value *MaxOccVal = nullptr;
1588-
for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
1588+
for (const ValueEntry &Op : Ops) {
15891589
BinaryOperator *BOp =
1590-
isReassociableOp(Ops[i].Op, Instruction::Mul, Instruction::FMul);
1590+
isReassociableOp(Op.Op, Instruction::Mul, Instruction::FMul);
15911591
if (!BOp)
15921592
continue;
15931593

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3082,10 +3082,10 @@ bool VectorCombine::foldSelectShuffle(Instruction &I, bool FromReduction) {
30823082
auto *SSV = cast<ShuffleVectorInst>(SVOp0);
30833083
SVOp0 = SSV->getOperand(0);
30843084
SVOp1 = SSV->getOperand(1);
3085-
for (unsigned I = 0, E = Mask.size(); I != E; I++) {
3086-
if (Mask[I] >= static_cast<int>(SSV->getShuffleMask().size()))
3085+
for (int &Elem : Mask) {
3086+
if (Elem >= static_cast<int>(SSV->getShuffleMask().size()))
30873087
return false;
3088-
Mask[I] = Mask[I] < 0 ? Mask[I] : SSV->getMaskValue(Mask[I]);
3088+
Elem = Elem < 0 ? Elem : SSV->getMaskValue(Elem);
30893089
}
30903090
}
30913091
if (SVOp0 == Op1 && SVOp1 == Op0) {

0 commit comments

Comments
 (0)