Skip to content

Conversation

linuxlonelyeagle
Copy link
Member

This PR simplifies the process of obtaining the argument index.

@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Oct 11, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 11, 2025

@llvm/pr-subscribers-mlir-core

@llvm/pr-subscribers-mlir

Author: lonely eagle (linuxlonelyeagle)

Changes

This PR simplifies the process of obtaining the argument index.


Full diff: https://github.com/llvm/llvm-project/pull/162959.diff

1 Files Affected:

  • (modified) mlir/lib/Transforms/Utils/LoopInvariantCodeMotionUtils.cpp (+1-2)
diff --git a/mlir/lib/Transforms/Utils/LoopInvariantCodeMotionUtils.cpp b/mlir/lib/Transforms/Utils/LoopInvariantCodeMotionUtils.cpp
index 111f58ef92f51..b6ca18c760ebf 100644
--- a/mlir/lib/Transforms/Utils/LoopInvariantCodeMotionUtils.cpp
+++ b/mlir/lib/Transforms/Utils/LoopInvariantCodeMotionUtils.cpp
@@ -324,8 +324,7 @@ static LoopLikeOpInterface hoistSubsetAtIterArg(RewriterBase &rewriter,
                                                 LoopLikeOpInterface loopLike,
                                                 BlockArgument iterArg) {
   assert(iterArg.getOwner()->getParentOp() == loopLike && "invalid iter_arg");
-  BlockArgument *it = llvm::find(loopLike.getRegionIterArgs(), iterArg);
-  int64_t iterArgIdx = std::distance(loopLike.getRegionIterArgs().begin(), it);
+  int64_t iterArgIdx = iterArg.getArgNumber() - 1;
   MatchingSubsets subsets;
   if (failed(subsets.populateSubsetOpsAtIterArg(loopLike, iterArg)))
     return loopLike;

assert(iterArg.getOwner()->getParentOp() == loopLike && "invalid iter_arg");
BlockArgument *it = llvm::find(loopLike.getRegionIterArgs(), iterArg);
int64_t iterArgIdx = std::distance(loopLike.getRegionIterArgs().begin(), it);
int64_t iterArgIdx = iterArg.getArgNumber() - 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I think it can be iterArg.getArgNumber() - N depending on how getRegionIterArgs() is defined for the specific looplike op? For scf.for it can always be N = 1, but is it applicable for other ops (forall, while..)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing this out. However, there's a fact that the tests for loop-invariant-subset-hoisting only include scf.for. Is this pass designed solely for scf.for loops?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mlir:core MLIR Core Infrastructure mlir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants