[GISel][NFC] Use ranged-for/enumerate in a few places.#143185
Merged
Conversation
Member
|
@llvm/pr-subscribers-llvm-globalisel Author: Jason Eckhardt (nvjle) ChangesFollow-up to #143113. Full diff: https://github.com/llvm/llvm-project/pull/143185.diff 1 Files Affected:
diff --git a/llvm/lib/CodeGen/GlobalISel/GISelValueTracking.cpp b/llvm/lib/CodeGen/GlobalISel/GISelValueTracking.cpp
index 135e1d2163e23..6650ad25bed04 100644
--- a/llvm/lib/CodeGen/GlobalISel/GISelValueTracking.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/GISelValueTracking.cpp
@@ -222,12 +222,11 @@ void GISelValueTracking::computeKnownBitsImpl(Register R, KnownBits &Known,
// Collect the known bits that are shared by every demanded vector element.
Known.Zero.setAllBits();
Known.One.setAllBits();
- for (unsigned I = 0, E = MI.getNumOperands() - 1; I < E; ++I) {
+ for (const auto &[I, MO] : enumerate(drop_begin(MI.operands()))) {
if (!DemandedElts[I])
continue;
- computeKnownBitsImpl(MI.getOperand(I + 1).getReg(), Known2, APInt(1, 1),
- Depth + 1);
+ computeKnownBitsImpl(MO.getReg(), Known2, APInt(1, 1), Depth + 1);
// Known bits are the values that are shared by every demanded element.
Known = Known.intersectWith(Known2);
@@ -683,14 +682,12 @@ void GISelValueTracking::computeKnownBitsImpl(Register R, KnownBits &Known,
Known.One.setAllBits();
unsigned NumSubVectorElts =
MRI.getType(MI.getOperand(1).getReg()).getNumElements();
- unsigned NumSubVectors = MI.getNumOperands() - 1;
- for (unsigned I = 0; I != NumSubVectors; ++I) {
+ for (const auto &[I, MO] : enumerate(drop_begin(MI.operands()))) {
APInt DemandedSub =
DemandedElts.extractBits(NumSubVectorElts, I * NumSubVectorElts);
if (!!DemandedSub) {
- computeKnownBitsImpl(MI.getOperand(I + 1).getReg(), Known2, DemandedSub,
- Depth + 1);
+ computeKnownBitsImpl(MO.getReg(), Known2, DemandedSub, Depth + 1);
Known = Known.intersectWith(Known2);
}
@@ -1944,12 +1941,12 @@ unsigned GISelValueTracking::computeNumSignBits(Register R,
// Collect the known bits that are shared by every demanded vector element.
FirstAnswer = TyBits;
APInt SingleDemandedElt(1, 1);
- for (unsigned I = 0, E = MI.getNumOperands() - 1; I < E; ++I) {
+ for (const auto &[I, MO] : enumerate(drop_begin(MI.operands()))) {
if (!DemandedElts[I])
continue;
- unsigned Tmp2 = computeNumSignBits(MI.getOperand(I + 1).getReg(),
- SingleDemandedElt, Depth + 1);
+ unsigned Tmp2 =
+ computeNumSignBits(MO.getReg(), SingleDemandedElt, Depth + 1);
FirstAnswer = std::min(FirstAnswer, Tmp2);
// If we don't know any bits, early out.
@@ -1966,14 +1963,12 @@ unsigned GISelValueTracking::computeNumSignBits(Register R,
// elts of the input vectors. Early out if the result is already 1.
unsigned NumSubVectorElts =
MRI.getType(MI.getOperand(1).getReg()).getNumElements();
- unsigned NumSubVectors = MI.getNumOperands() - 1;
- for (unsigned I = 0; I < NumSubVectors; ++I) {
+ for (const auto &[I, MO] : enumerate(drop_begin(MI.operands()))) {
APInt DemandedSub =
DemandedElts.extractBits(NumSubVectorElts, I * NumSubVectorElts);
if (!DemandedSub)
continue;
- unsigned Tmp2 = computeNumSignBits(MI.getOperand(I + 1).getReg(),
- DemandedSub, Depth + 1);
+ unsigned Tmp2 = computeNumSignBits(MO.getReg(), DemandedSub, Depth + 1);
FirstAnswer = std::min(FirstAnswer, Tmp2);
|
tgymnich
approved these changes
Jun 7, 2025
tomtor
pushed a commit
to tomtor/llvm-project
that referenced
this pull request
Jun 14, 2025
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
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.
Follow-up to #143113.