[llvm] 26d71f9 - [Transforms] Use range-based for loops (NFC) (#138476)
via llvm-commits
llvm-commits at lists.llvm.org
Sun May 4 16:08:35 PDT 2025
Author: Kazu Hirata
Date: 2025-05-04T16:08:31-07:00
New Revision: 26d71f9ef2215081119066d8396afd65e07f7a43
URL: https://github.com/llvm/llvm-project/commit/26d71f9ef2215081119066d8396afd65e07f7a43
DIFF: https://github.com/llvm/llvm-project/commit/26d71f9ef2215081119066d8396afd65e07f7a43.diff
LOG: [Transforms] Use range-based for loops (NFC) (#138476)
Added:
Modified:
llvm/lib/Transforms/IPO/ConstantMerge.cpp
llvm/lib/Transforms/Scalar/GVN.cpp
llvm/lib/Transforms/Scalar/Reassociate.cpp
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/ConstantMerge.cpp b/llvm/lib/Transforms/IPO/ConstantMerge.cpp
index a1face0a6a9c3..6cc35d05ceb1a 100644
--- a/llvm/lib/Transforms/IPO/ConstantMerge.cpp
+++ b/llvm/lib/Transforms/IPO/ConstantMerge.cpp
@@ -226,9 +226,7 @@ static bool mergeConstants(Module &M) {
// Now that we have figured out which replacements must be made, do them all
// now. This avoid invalidating the pointers in CMap, which are unneeded
// now.
- for (unsigned i = 0, e = SameContentReplacements.size(); i != e; ++i) {
- GlobalVariable *Old = SameContentReplacements[i].first;
- GlobalVariable *New = SameContentReplacements[i].second;
+ for (const auto &[Old, New] : SameContentReplacements) {
replace(M, Old, New);
++ChangesMade;
++NumIdenticalMerged;
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index c0ae944ee82f2..3005e65f532ce 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -3036,12 +3036,12 @@ bool GVNPass::performScalarPRE(Instruction *CurInst) {
PHINode *Phi = PHINode::Create(CurInst->getType(), PredMap.size(),
CurInst->getName() + ".pre-phi");
Phi->insertBefore(CurrentBlock->begin());
- for (unsigned I = 0, E = PredMap.size(); I != E; ++I) {
- if (Value *V = PredMap[I].first) {
+ for (auto &[V, BB] : PredMap) {
+ if (V) {
// If we use an existing value in this phi, we have to patch the original
// value because the phi will be used to replace a later value.
patchReplacementInstruction(CurInst, V);
- Phi->addIncoming(V, PredMap[I].second);
+ Phi->addIncoming(V, BB);
} else
Phi->addIncoming(PREInstr, PREPred);
}
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp
index a8a11624be63f..97f9829ce54c5 100644
--- a/llvm/lib/Transforms/Scalar/Reassociate.cpp
+++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp
@@ -1115,10 +1115,8 @@ Value *ReassociatePass::RemoveFactorFromExpression(Value *V, Value *Factor,
MadeChange |= LinearizeExprTree(BO, Tree, RedoInsts, Flags);
SmallVector<ValueEntry, 8> Factors;
Factors.reserve(Tree.size());
- for (unsigned i = 0, e = Tree.size(); i != e; ++i) {
- RepeatedValue E = Tree[i];
+ for (const RepeatedValue &E : Tree)
Factors.append(E.second, ValueEntry(getRank(E.first), E.first));
- }
bool FoundFactor = false;
bool NeedsNegate = false;
@@ -1391,8 +1389,8 @@ Value *ReassociatePass::OptimizeXor(Instruction *I,
APInt ConstOpnd(Ty->getScalarSizeInBits(), 0);
// Step 1: Convert ValueEntry to XorOpnd
- for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
- Value *V = Ops[i].Op;
+ for (const ValueEntry &Op : Ops) {
+ Value *V = Op.Op;
const APInt *C;
// TODO: Support non-splat vectors.
if (match(V, m_APInt(C))) {
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 8094697cdd13a..33af582a9e0a9 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -976,8 +976,8 @@ bool SimplifyCFGOpt::simplifyEqualityComparisonWithOnlyPredecessor(
SwitchInstProfUpdateWrapper SI = *cast<SwitchInst>(TI);
// Okay, TI has cases that are statically dead, prune them away.
SmallPtrSet<Constant *, 16> DeadCases;
- for (unsigned i = 0, e = PredCases.size(); i != e; ++i)
- DeadCases.insert(PredCases[i].Value);
+ for (const ValueEqualityComparisonCase &Case : PredCases)
+ DeadCases.insert(Case.Value);
LLVM_DEBUG(dbgs() << "Threading pred instr: " << *Pred->getTerminator()
<< "Through successor TI: " << *TI);
@@ -1307,14 +1307,14 @@ bool SimplifyCFGOpt::performValueComparisonIntoPredecessorFolding(
// Okay, now we know which constants were sent to BB from the
// predecessor. Figure out where they will all go now.
- for (unsigned i = 0, e = BBCases.size(); i != e; ++i)
- if (PTIHandled.count(BBCases[i].Value)) {
+ for (const ValueEqualityComparisonCase &Case : BBCases)
+ if (PTIHandled.count(Case.Value)) {
// If this is one we are capable of getting...
if (PredHasWeights || SuccHasWeights)
- Weights.push_back(WeightsForHandled[BBCases[i].Value]);
- PredCases.push_back(BBCases[i]);
- ++NewSuccessors[BBCases[i].Dest];
- PTIHandled.erase(BBCases[i].Value); // This constant is taken care of
+ Weights.push_back(WeightsForHandled[Case.Value]);
+ PredCases.push_back(Case);
+ ++NewSuccessors[Case.Dest];
+ PTIHandled.erase(Case.Value); // This constant is taken care of
}
// If there are any constants vectored to BB that TI doesn't handle,
@@ -5177,8 +5177,8 @@ bool SimplifyCFGOpt::simplifyBranchOnICmpChain(BranchInst *BI,
SwitchInst *New = Builder.CreateSwitch(CompVal, DefaultBB, Values.size());
// Add all of the 'cases' to the switch instruction.
- for (unsigned i = 0, e = Values.size(); i != e; ++i)
- New->addCase(Values[i], EdgeBB);
+ for (ConstantInt *Val : Values)
+ New->addCase(Val, EdgeBB);
// We added edges from PI to the EdgeBB. As such, if there were any
// PHI nodes in EdgeBB, they need entries to be added corresponding to
@@ -6453,9 +6453,7 @@ SwitchLookupTable::SwitchLookupTable(
// Build up the table contents.
SmallVector<Constant *, 64> TableContents(TableSize);
- for (size_t I = 0, E = Values.size(); I != E; ++I) {
- ConstantInt *CaseVal = Values[I].first;
- Constant *CaseRes = Values[I].second;
+ for (const auto &[CaseVal, CaseRes] : Values) {
assert(CaseRes->getType() == ValueType);
uint64_t Idx = (CaseVal->getValue() - Offset->getValue()).getLimitedValue();
More information about the llvm-commits
mailing list