-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[Transforms] Use range-based for loops (NFC) #145252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kazutakahirata
merged 3 commits into
llvm:main
from
kazutakahirata:cleanup_20250622_range_for_llvm_Transforms
Jun 25, 2025
Merged
[Transforms] Use range-based for loops (NFC) #145252
kazutakahirata
merged 3 commits into
llvm:main
from
kazutakahirata:cleanup_20250622_range_for_llvm_Transforms
Jun 25, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
|
@llvm/pr-subscribers-vectorizers @llvm/pr-subscribers-llvm-transforms Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/145252.diff 5 Files Affected:
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 4a06e0fa619c0..5099cb7deb9c4 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -250,10 +250,10 @@ CleanupPointerRootUsers(GlobalVariable *GV,
}
}
- for (int i = 0, e = Dead.size(); i != e; ++i) {
- if (IsSafeComputationToRemove(Dead[i].first, GetTLI)) {
- Dead[i].second->eraseFromParent();
- Instruction *I = Dead[i].first;
+ for (const auto &Pair : Dead) {
+ if (IsSafeComputationToRemove(Pair.first, GetTLI)) {
+ Pair.second->eraseFromParent();
+ Instruction *I = Pair.first;
do {
if (isAllocationFn(I, GetTLI))
break;
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index ce42029261359..a1d9173b68dbd 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -3472,13 +3472,13 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
auto Removable =
isAllocSiteRemovable(&MI, Users, TLI, KnowInitZero | KnowInitUndef);
if (Removable) {
- for (unsigned i = 0, e = Users.size(); i != e; ++i) {
+ for (WeakTrackingVH &User : Users) {
// Lowering all @llvm.objectsize and MTI calls first because they may use
// a bitcast/GEP of the alloca we are removing.
- if (!Users[i])
- continue;
+ if (!User)
+ continue;
- Instruction *I = cast<Instruction>(&*Users[i]);
+ Instruction *I = cast<Instruction>(&*User);
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
if (II->getIntrinsicID() == Intrinsic::objectsize) {
@@ -3489,7 +3489,7 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
Worklist.add(Inserted);
replaceInstUsesWith(*I, Result);
eraseInstFromFunction(*I);
- Users[i] = nullptr; // Skip examining in the next loop.
+ User = nullptr; // Skip examining in the next loop.
continue;
}
if (auto *MTI = dyn_cast<MemTransferInst>(I)) {
@@ -3505,11 +3505,11 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
}
}
}
- for (unsigned i = 0, e = Users.size(); i != e; ++i) {
- if (!Users[i])
+ for (WeakTrackingVH &User : Users) {
+ if (!User)
continue;
- Instruction *I = cast<Instruction>(&*Users[i]);
+ Instruction *I = cast<Instruction>(&*User);
if (ICmpInst *C = dyn_cast<ICmpInst>(I)) {
replaceInstUsesWith(*C,
diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
index 1e16677e5a56f..9e3b4b82cc454 100644
--- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
@@ -235,8 +235,8 @@ static bool populateDependencyMatrix(CharMatrix &DepMatrix, unsigned Level,
// matrix by exchanging the two columns.
static void interChangeDependencies(CharMatrix &DepMatrix, unsigned FromIndx,
unsigned ToIndx) {
- for (unsigned I = 0, E = DepMatrix.size(); I < E; ++I)
- std::swap(DepMatrix[I][ToIndx], DepMatrix[I][FromIndx]);
+ for (auto &Row : DepMatrix)
+ std::swap(Row[ToIndx], Row[FromIndx]);
}
// Check if a direction vector is lexicographically positive. Return true if it
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp
index 778a6a012556b..343da5b2e4704 100644
--- a/llvm/lib/Transforms/Scalar/Reassociate.cpp
+++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp
@@ -83,10 +83,10 @@ static void PrintOps(Instruction *I, const SmallVectorImpl<ValueEntry> &Ops) {
Module *M = I->getModule();
dbgs() << Instruction::getOpcodeName(I->getOpcode()) << " "
<< *Ops[0].Op->getType() << '\t';
- for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
+ for (const ValueEntry &Op : Ops) {
dbgs() << "[ ";
- Ops[i].Op->printAsOperand(dbgs(), false, M);
- dbgs() << ", #" << Ops[i].Rank << "] ";
+ Op.Op->printAsOperand(dbgs(), false, M);
+ dbgs() << ", #" << Op.Rank << "] ";
}
}
#endif
@@ -1585,9 +1585,9 @@ Value *ReassociatePass::OptimizeAdd(Instruction *I,
// where they are actually the same multiply.
unsigned MaxOcc = 0;
Value *MaxOccVal = nullptr;
- for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
+ for (const ValueEntry &Op : Ops) {
BinaryOperator *BOp =
- isReassociableOp(Ops[i].Op, Instruction::Mul, Instruction::FMul);
+ isReassociableOp(Op.Op, Instruction::Mul, Instruction::FMul);
if (!BOp)
continue;
diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index 3e459f5ea4ce5..a4bfdcabaa314 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -3082,10 +3082,10 @@ bool VectorCombine::foldSelectShuffle(Instruction &I, bool FromReduction) {
auto *SSV = cast<ShuffleVectorInst>(SVOp0);
SVOp0 = SSV->getOperand(0);
SVOp1 = SSV->getOperand(1);
- for (unsigned I = 0, E = Mask.size(); I != E; I++) {
- if (Mask[I] >= static_cast<int>(SSV->getShuffleMask().size()))
+ for (int &Elem : Mask) {
+ if (Elem >= static_cast<int>(SSV->getShuffleMask().size()))
return false;
- Mask[I] = Mask[I] < 0 ? Mask[I] : SSV->getMaskValue(Mask[I]);
+ Elem = Elem < 0 ? Elem : SSV->getMaskValue(Elem);
}
}
if (SVOp0 == Op1 && SVOp1 == Op0) {
|
arsenm
reviewed
Jun 23, 2025
Co-authored-by: Matt Arsenault <[email protected]>
Contributor
Author
|
@arsenm I'd appreciate another look. Thanks! |
tgymnich
approved these changes
Jun 25, 2025
anthonyhatran
pushed a commit
to anthonyhatran/llvm-project
that referenced
this pull request
Jun 26, 2025
Co-authored-by: Matt Arsenault <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
llvm:instcombine
Covers the InstCombine, InstSimplify and AggressiveInstCombine passes
llvm:transforms
vectorizers
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.