Skip to content

Conversation

@banach-space
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Nov 26, 2024

@llvm/pr-subscribers-mlir

Author: Andrzej Warzyński (banach-space)

Changes

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

1 Files Affected:

  • (modified) mlir/unittests/IR/AffineMapTest.cpp (+12-22)
diff --git a/mlir/unittests/IR/AffineMapTest.cpp b/mlir/unittests/IR/AffineMapTest.cpp
index 166692f731d1cf..ff1f28235d4093 100644
--- a/mlir/unittests/IR/AffineMapTest.cpp
+++ b/mlir/unittests/IR/AffineMapTest.cpp
@@ -97,17 +97,12 @@ TEST(AffineMapTest, getInversePermutation) {
   auto resultsInv1 = inverseMap1.getResults();
   EXPECT_EQ(resultsInv1.size(), 3UL);
 
-  // 1.1 Expect d2
-  AffineDimExpr expr = llvm::dyn_cast<AffineDimExpr>(resultsInv1[0]);
-  EXPECT_TRUE(expr && expr.getPosition() == 2);
-
-  // 1.2 Expect d0
-  expr = llvm::dyn_cast<AffineDimExpr>(resultsInv1[1]);
-  EXPECT_TRUE(expr && expr.getPosition() == 0);
-
-  // 1.3 Expect d3
-  expr = llvm::dyn_cast<AffineDimExpr>(resultsInv1[2]);
-  EXPECT_TRUE(expr && expr.getPosition() == 3);
+  // Expect (d2, d0, d3)
+  SmallVector<unsigned> expected = {2, 0, 3};
+  for (auto [idx, res] : llvm::enumerate(resultsInv1)) {
+    AffineDimExpr expr = llvm::dyn_cast<AffineDimExpr>(res);
+    EXPECT_TRUE(expr && expr.getPosition() == expected[idx]);
+  }
 
   // 2.   (d0, d1, d2) -> (d1, d0 + d1, d0, d2, d1, d2, d1, d0)
   auto sum = d0 + d1;
@@ -118,15 +113,10 @@ TEST(AffineMapTest, getInversePermutation) {
   auto resultsInv2 = inverseMap2.getResults();
   EXPECT_EQ(resultsInv2.size(), 3UL);
 
-  // 2.1 Expect d2
-  expr = llvm::dyn_cast<AffineDimExpr>(resultsInv2[0]);
-  EXPECT_TRUE(expr && expr.getPosition() == 2);
-
-  // 2.2 Expect d0
-  expr = llvm::dyn_cast<AffineDimExpr>(resultsInv2[1]);
-  EXPECT_TRUE(expr && expr.getPosition() == 0);
-
-  // 2.3 Expect d3
-  expr = llvm::dyn_cast<AffineDimExpr>(resultsInv2[2]);
-  EXPECT_TRUE(expr && expr.getPosition() == 3);
+  // Expect (d2, d0, d3)
+  expected = {2, 0, 3};
+  for (auto [idx, res] : llvm::enumerate(resultsInv2)) {
+    AffineDimExpr expr = llvm::dyn_cast<AffineDimExpr>(res);
+    EXPECT_TRUE(expr && expr.getPosition() == expected[idx]);
+  }
 }

Copy link
Contributor

@javedabsar1 javedabsar1 left a comment

Choose a reason for hiding this comment

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

Thanks for making it neat. Neat code is a great teacher to others.

for (auto [idx, res] : llvm::enumerate(resultsInv1)) {
AffineDimExpr expr = llvm::dyn_cast<AffineDimExpr>(res);
EXPECT_TRUE(expr && expr.getPosition() == expected[idx]);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Beautiful.

@banach-space banach-space merged commit 6f5e5b6 into llvm:main Nov 26, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants