-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[LoopInterchange] Modernize loops (NFC) #146105
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
Merged
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-transforms Author: Ramkumar Ramachandra (artagnon) ChangesFull diff: https://github.com/llvm/llvm-project/pull/146105.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
index 9e3b4b82cc454..51971a47527bd 100644
--- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
@@ -551,12 +551,10 @@ struct LoopInterchange {
//
// For the old pass manager CacheCost would be null.
DenseMap<const Loop *, unsigned> CostMap;
- if (CC != nullptr) {
- const auto &LoopCosts = CC->getLoopCosts();
- for (unsigned i = 0; i < LoopCosts.size(); i++) {
- CostMap[LoopCosts[i].first] = i;
- }
- }
+ if (CC)
+ for (auto [Idx, Cost] : enumerate(CC->getLoopCosts()))
+ CostMap[Cost.first] = Idx;
+
// We try to achieve the globally optimal memory access for the loopnest,
// and do interchange based on a bubble-sort fasion. We start from
// the innermost loop, move it outwards to the best possible position
@@ -972,8 +970,8 @@ areInnerLoopExitPHIsSupported(Loop *InnerL, Loop *OuterL,
static bool areOuterLoopExitPHIsSupported(Loop *OuterLoop, Loop *InnerLoop) {
BasicBlock *LoopNestExit = OuterLoop->getUniqueExitBlock();
for (PHINode &PHI : LoopNestExit->phis()) {
- for (unsigned i = 0; i < PHI.getNumIncomingValues(); i++) {
- Instruction *IncomingI = dyn_cast<Instruction>(PHI.getIncomingValue(i));
+ for (Value *Incoming : PHI.incoming_values()) {
+ Instruction *IncomingI = dyn_cast<Instruction>(Incoming);
if (!IncomingI || IncomingI->getParent() != OuterLoop->getLoopLatch())
continue;
@@ -1132,15 +1130,14 @@ int LoopInterchangeProfitability::getInstrOrderCost() {
for (BasicBlock *BB : InnerLoop->blocks()) {
for (Instruction &Ins : *BB) {
if (const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(&Ins)) {
- unsigned NumOp = GEP->getNumOperands();
bool FoundInnerInduction = false;
bool FoundOuterInduction = false;
- for (unsigned i = 0; i < NumOp; ++i) {
+ for (Value *Op : GEP->operands()) {
// Skip operands that are not SCEV-able.
- if (!SE->isSCEVable(GEP->getOperand(i)->getType()))
+ if (!SE->isSCEVable(Op->getType()))
continue;
- const SCEV *OperandVal = SE->getSCEV(GEP->getOperand(i));
+ const SCEV *OperandVal = SE->getSCEV(Op);
const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(OperandVal);
if (!AR)
continue;
@@ -1220,8 +1217,8 @@ LoopInterchangeProfitability::isProfitablePerInstrOrderCost() {
/// Return true if we can vectorize the loop specified by \p LoopId.
static bool canVectorize(const CharMatrix &DepMatrix, unsigned LoopId) {
- for (unsigned I = 0; I != DepMatrix.size(); I++) {
- char Dir = DepMatrix[I][LoopId];
+ for (auto Dep : DepMatrix) {
+ char Dir = Dep[LoopId];
if (Dir != 'I' && Dir != '=')
return false;
}
|
kasuga-fj
reviewed
Jun 27, 2025
kasuga-fj
approved these changes
Jun 27, 2025
rlavaee
pushed a commit
to rlavaee/llvm-project
that referenced
this pull request
Jul 1, 2025
rlavaee
pushed a commit
to rlavaee/llvm-project
that referenced
this pull request
Jul 1, 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.