Skip to content

Commit 26d71f9

Browse files
[Transforms] Use range-based for loops (NFC) (#138476)
1 parent dc7037d commit 26d71f9

File tree

4 files changed

+18
-24
lines changed

4 files changed

+18
-24
lines changed

llvm/lib/Transforms/IPO/ConstantMerge.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,7 @@ static bool mergeConstants(Module &M) {
226226
// Now that we have figured out which replacements must be made, do them all
227227
// now. This avoid invalidating the pointers in CMap, which are unneeded
228228
// now.
229-
for (unsigned i = 0, e = SameContentReplacements.size(); i != e; ++i) {
230-
GlobalVariable *Old = SameContentReplacements[i].first;
231-
GlobalVariable *New = SameContentReplacements[i].second;
229+
for (const auto &[Old, New] : SameContentReplacements) {
232230
replace(M, Old, New);
233231
++ChangesMade;
234232
++NumIdenticalMerged;

llvm/lib/Transforms/Scalar/GVN.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3036,12 +3036,12 @@ bool GVNPass::performScalarPRE(Instruction *CurInst) {
30363036
PHINode *Phi = PHINode::Create(CurInst->getType(), PredMap.size(),
30373037
CurInst->getName() + ".pre-phi");
30383038
Phi->insertBefore(CurrentBlock->begin());
3039-
for (unsigned I = 0, E = PredMap.size(); I != E; ++I) {
3040-
if (Value *V = PredMap[I].first) {
3039+
for (auto &[V, BB] : PredMap) {
3040+
if (V) {
30413041
// If we use an existing value in this phi, we have to patch the original
30423042
// value because the phi will be used to replace a later value.
30433043
patchReplacementInstruction(CurInst, V);
3044-
Phi->addIncoming(V, PredMap[I].second);
3044+
Phi->addIncoming(V, BB);
30453045
} else
30463046
Phi->addIncoming(PREInstr, PREPred);
30473047
}

llvm/lib/Transforms/Scalar/Reassociate.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,10 +1115,8 @@ Value *ReassociatePass::RemoveFactorFromExpression(Value *V, Value *Factor,
11151115
MadeChange |= LinearizeExprTree(BO, Tree, RedoInsts, Flags);
11161116
SmallVector<ValueEntry, 8> Factors;
11171117
Factors.reserve(Tree.size());
1118-
for (unsigned i = 0, e = Tree.size(); i != e; ++i) {
1119-
RepeatedValue E = Tree[i];
1118+
for (const RepeatedValue &E : Tree)
11201119
Factors.append(E.second, ValueEntry(getRank(E.first), E.first));
1121-
}
11221120

11231121
bool FoundFactor = false;
11241122
bool NeedsNegate = false;
@@ -1391,8 +1389,8 @@ Value *ReassociatePass::OptimizeXor(Instruction *I,
13911389
APInt ConstOpnd(Ty->getScalarSizeInBits(), 0);
13921390

13931391
// Step 1: Convert ValueEntry to XorOpnd
1394-
for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
1395-
Value *V = Ops[i].Op;
1392+
for (const ValueEntry &Op : Ops) {
1393+
Value *V = Op.Op;
13961394
const APInt *C;
13971395
// TODO: Support non-splat vectors.
13981396
if (match(V, m_APInt(C))) {

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -976,8 +976,8 @@ bool SimplifyCFGOpt::simplifyEqualityComparisonWithOnlyPredecessor(
976976
SwitchInstProfUpdateWrapper SI = *cast<SwitchInst>(TI);
977977
// Okay, TI has cases that are statically dead, prune them away.
978978
SmallPtrSet<Constant *, 16> DeadCases;
979-
for (unsigned i = 0, e = PredCases.size(); i != e; ++i)
980-
DeadCases.insert(PredCases[i].Value);
979+
for (const ValueEqualityComparisonCase &Case : PredCases)
980+
DeadCases.insert(Case.Value);
981981

982982
LLVM_DEBUG(dbgs() << "Threading pred instr: " << *Pred->getTerminator()
983983
<< "Through successor TI: " << *TI);
@@ -1307,14 +1307,14 @@ bool SimplifyCFGOpt::performValueComparisonIntoPredecessorFolding(
13071307

13081308
// Okay, now we know which constants were sent to BB from the
13091309
// predecessor. Figure out where they will all go now.
1310-
for (unsigned i = 0, e = BBCases.size(); i != e; ++i)
1311-
if (PTIHandled.count(BBCases[i].Value)) {
1310+
for (const ValueEqualityComparisonCase &Case : BBCases)
1311+
if (PTIHandled.count(Case.Value)) {
13121312
// If this is one we are capable of getting...
13131313
if (PredHasWeights || SuccHasWeights)
1314-
Weights.push_back(WeightsForHandled[BBCases[i].Value]);
1315-
PredCases.push_back(BBCases[i]);
1316-
++NewSuccessors[BBCases[i].Dest];
1317-
PTIHandled.erase(BBCases[i].Value); // This constant is taken care of
1314+
Weights.push_back(WeightsForHandled[Case.Value]);
1315+
PredCases.push_back(Case);
1316+
++NewSuccessors[Case.Dest];
1317+
PTIHandled.erase(Case.Value); // This constant is taken care of
13181318
}
13191319

13201320
// If there are any constants vectored to BB that TI doesn't handle,
@@ -5177,8 +5177,8 @@ bool SimplifyCFGOpt::simplifyBranchOnICmpChain(BranchInst *BI,
51775177
SwitchInst *New = Builder.CreateSwitch(CompVal, DefaultBB, Values.size());
51785178

51795179
// Add all of the 'cases' to the switch instruction.
5180-
for (unsigned i = 0, e = Values.size(); i != e; ++i)
5181-
New->addCase(Values[i], EdgeBB);
5180+
for (ConstantInt *Val : Values)
5181+
New->addCase(Val, EdgeBB);
51825182

51835183
// We added edges from PI to the EdgeBB. As such, if there were any
51845184
// PHI nodes in EdgeBB, they need entries to be added corresponding to
@@ -6453,9 +6453,7 @@ SwitchLookupTable::SwitchLookupTable(
64536453

64546454
// Build up the table contents.
64556455
SmallVector<Constant *, 64> TableContents(TableSize);
6456-
for (size_t I = 0, E = Values.size(); I != E; ++I) {
6457-
ConstantInt *CaseVal = Values[I].first;
6458-
Constant *CaseRes = Values[I].second;
6456+
for (const auto &[CaseVal, CaseRes] : Values) {
64596457
assert(CaseRes->getType() == ValueType);
64606458

64616459
uint64_t Idx = (CaseVal->getValue() - Offset->getValue()).getLimitedValue();

0 commit comments

Comments
 (0)