Skip to content

[MLIR][Affine] Make isValidLoopInterchangePermutation efficient #128863

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

Conversation

arnab-polymage
Copy link
Contributor

Avoid doing dependency checks for the trivial case when size of loops is 1.

@llvmbot
Copy link
Member

llvmbot commented Feb 26, 2025

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-affine

Author: Arnab Dutta (arnab-polymage)

Changes

Avoid doing dependency checks for the trivial case when size of loops is 1.


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

1 Files Affected:

  • (modified) mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp (+4-2)
diff --git a/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp b/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp
index 82b96e9876a6f..6833d6583c27a 100644
--- a/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp
+++ b/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp
@@ -1351,10 +1351,12 @@ static bool checkLoopInterchangeDependences(
 /// nested sequence of loops in 'loops' would violate dependences.
 bool mlir::affine::isValidLoopInterchangePermutation(
     ArrayRef<AffineForOp> loops, ArrayRef<unsigned> loopPermMap) {
+  assert(loopPermMap.size() == loops.size() && "invalid loop perm map");
+  unsigned maxLoopDepth = loops.size();
+  if (maxLoopDepth == 1)
+    return true;
   // Gather dependence components for dependences between all ops in loop nest
   // rooted at 'loops[0]', at loop depths in range [1, maxLoopDepth].
-  assert(loopPermMap.size() == loops.size());
-  unsigned maxLoopDepth = loops.size();
   std::vector<SmallVector<DependenceComponent, 2>> depCompsVec;
   getDependenceComponents(loops[0], maxLoopDepth, &depCompsVec);
   return checkLoopInterchangeDependences(depCompsVec, loops, loopPermMap);

@arnab-polymage arnab-polymage force-pushed the ornib/isValidLoopInterchangePermutation branch from f29dc1f to aa77f17 Compare February 26, 2025 11:20
@arnab-polymage arnab-polymage changed the title Make isValidLoopInterchangePermutation efficient [MLIR][Affine] Make isValidLoopInterchangePermutation efficient Feb 26, 2025
Avoid doing dependency checks for the trivial case when
size of `loops` is 1.
@arnab-polymage arnab-polymage force-pushed the ornib/isValidLoopInterchangePermutation branch from aa77f17 to be21243 Compare February 26, 2025 11:58
@arnab-polymage
Copy link
Contributor Author

@joker-eph @andydavis1 please review

@bondhugula bondhugula self-requested a review February 26, 2025 15:12
@bondhugula bondhugula merged commit ea294e3 into llvm:main Feb 26, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants