-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[CodeGen] Use range-based for loops (NFC) #145251
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 1 commit into
llvm:main
from
kazutakahirata:cleanup_20250622_range_for_llvm_CodeGen
Jun 23, 2025
Merged
[CodeGen] Use range-based for loops (NFC) #145251
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_20250622_range_for_llvm_CodeGen
Jun 23, 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
@llvm/pr-subscribers-llvm-selectiondag @llvm/pr-subscribers-llvm-regalloc Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/145251.diff 3 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
index 06217337a46f6..92da4ef7f0556 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
@@ -1700,9 +1700,9 @@ class ShuffleVectorSDNode : public SDNode {
static int getSplatMaskIndex(ArrayRef<int> Mask) {
assert(isSplatMask(Mask) && "Cannot get splat index for non-splat!");
- for (unsigned i = 0, e = Mask.size(); i != e; ++i)
- if (Mask[i] >= 0)
- return Mask[i];
+ for (int Elem : Mask)
+ if (Elem >= 0)
+ return Elem;
// We can choose any index value here and be correct because all elements
// are undefined. Return 0 for better potential for callers to simplify.
diff --git a/llvm/lib/CodeGen/LiveInterval.cpp b/llvm/lib/CodeGen/LiveInterval.cpp
index 0238ce3bae3ea..b682998c329bc 100644
--- a/llvm/lib/CodeGen/LiveInterval.cpp
+++ b/llvm/lib/CodeGen/LiveInterval.cpp
@@ -1162,8 +1162,8 @@ void LiveRangeUpdater::print(raw_ostream &OS) const {
for (const auto &S : make_range(LR->begin(), WriteI))
OS << ' ' << S;
OS << "\n Spills:";
- for (unsigned I = 0, E = Spills.size(); I != E; ++I)
- OS << ' ' << Spills[I];
+ for (const LiveRange::Segment &Spill : Spills)
+ OS << ' ' << Spill;
OS << "\n Area 2:";
for (const auto &S : make_range(ReadI, LR->end()))
OS << ' ' << S;
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 4f91f90b0469d..56a5643e13442 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -19448,12 +19448,12 @@ bool DAGCombiner::CombineToPreIndexedLoadStore(SDNode *N) {
std::swap(BasePtr, Offset);
// Replace other uses of BasePtr that can be updated to use Ptr
- for (unsigned i = 0, e = OtherUses.size(); i != e; ++i) {
+ for (SDNode *OtherUse : OtherUses) {
unsigned OffsetIdx = 1;
- if (OtherUses[i]->getOperand(OffsetIdx).getNode() == BasePtr.getNode())
+ if (OtherUse->getOperand(OffsetIdx).getNode() == BasePtr.getNode())
OffsetIdx = 0;
- assert(OtherUses[i]->getOperand(!OffsetIdx).getNode() ==
- BasePtr.getNode() && "Expected BasePtr operand");
+ assert(OtherUse->getOperand(!OffsetIdx).getNode() == BasePtr.getNode() &&
+ "Expected BasePtr operand");
// We need to replace ptr0 in the following expression:
// x0 * offset0 + y0 * ptr0 = t0
@@ -19466,11 +19466,11 @@ bool DAGCombiner::CombineToPreIndexedLoadStore(SDNode *N) {
// Therefore, we have:
// t0 = (x0 * offset0 - x1 * y0 * y1 *offset1) + (y0 * y1) * t1
- auto *CN = cast<ConstantSDNode>(OtherUses[i]->getOperand(OffsetIdx));
+ auto *CN = cast<ConstantSDNode>(OtherUse->getOperand(OffsetIdx));
const APInt &Offset0 = CN->getAPIntValue();
const APInt &Offset1 = Offset->getAsAPIntVal();
- int X0 = (OtherUses[i]->getOpcode() == ISD::SUB && OffsetIdx == 1) ? -1 : 1;
- int Y0 = (OtherUses[i]->getOpcode() == ISD::SUB && OffsetIdx == 0) ? -1 : 1;
+ int X0 = (OtherUse->getOpcode() == ISD::SUB && OffsetIdx == 1) ? -1 : 1;
+ int Y0 = (OtherUse->getOpcode() == ISD::SUB && OffsetIdx == 0) ? -1 : 1;
int X1 = (AM == ISD::PRE_DEC && !Swapped) ? -1 : 1;
int Y1 = (AM == ISD::PRE_DEC && Swapped) ? -1 : 1;
@@ -19481,17 +19481,16 @@ bool DAGCombiner::CombineToPreIndexedLoadStore(SDNode *N) {
if (X1 * Y0 * Y1 < 0) CNV = CNV + Offset1;
else CNV = CNV - Offset1;
- SDLoc DL(OtherUses[i]);
+ SDLoc DL(OtherUse);
// We can now generate the new expression.
SDValue NewOp1 = DAG.getConstant(CNV, DL, CN->getValueType(0));
SDValue NewOp2 = Result.getValue(IsLoad ? 1 : 0);
- SDValue NewUse = DAG.getNode(Opcode,
- DL,
- OtherUses[i]->getValueType(0), NewOp1, NewOp2);
- DAG.ReplaceAllUsesOfValueWith(SDValue(OtherUses[i], 0), NewUse);
- deleteAndRecombine(OtherUses[i]);
+ SDValue NewUse =
+ DAG.getNode(Opcode, DL, OtherUse->getValueType(0), NewOp1, NewOp2);
+ DAG.ReplaceAllUsesOfValueWith(SDValue(OtherUse, 0), NewUse);
+ deleteAndRecombine(OtherUse);
}
// Replace the uses of Ptr with uses of the updated base value.
|
arsenm
approved these changes
Jun 23, 2025
miguelcsx
pushed a commit
to miguelcsx/llvm-project
that referenced
this pull request
Jun 23, 2025
Jaddyen
pushed a commit
to Jaddyen/llvm-project
that referenced
this pull request
Jun 23, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.