Skip to content

Commit 6f5e5b6

Browse files
authored
[mlir][unittest][nfc] Simplify getInversePermutation (llvm#117698)
1 parent f94bd3c commit 6f5e5b6

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

mlir/unittests/IR/AffineMapTest.cpp

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,12 @@ TEST(AffineMapTest, getInversePermutation) {
9797
auto resultsInv1 = inverseMap1.getResults();
9898
EXPECT_EQ(resultsInv1.size(), 3UL);
9999

100-
// 1.1 Expect d2
101-
AffineDimExpr expr = llvm::dyn_cast<AffineDimExpr>(resultsInv1[0]);
102-
EXPECT_TRUE(expr && expr.getPosition() == 2);
103-
104-
// 1.2 Expect d0
105-
expr = llvm::dyn_cast<AffineDimExpr>(resultsInv1[1]);
106-
EXPECT_TRUE(expr && expr.getPosition() == 0);
107-
108-
// 1.3 Expect d3
109-
expr = llvm::dyn_cast<AffineDimExpr>(resultsInv1[2]);
110-
EXPECT_TRUE(expr && expr.getPosition() == 3);
100+
// Expect (d2, d0, d3)
101+
SmallVector<unsigned> expected = {2, 0, 3};
102+
for (auto [idx, res] : llvm::enumerate(resultsInv1)) {
103+
AffineDimExpr expr = llvm::dyn_cast<AffineDimExpr>(res);
104+
EXPECT_TRUE(expr && expr.getPosition() == expected[idx]);
105+
}
111106

112107
// 2. (d0, d1, d2) -> (d1, d0 + d1, d0, d2, d1, d2, d1, d0)
113108
auto sum = d0 + d1;
@@ -118,15 +113,10 @@ TEST(AffineMapTest, getInversePermutation) {
118113
auto resultsInv2 = inverseMap2.getResults();
119114
EXPECT_EQ(resultsInv2.size(), 3UL);
120115

121-
// 2.1 Expect d2
122-
expr = llvm::dyn_cast<AffineDimExpr>(resultsInv2[0]);
123-
EXPECT_TRUE(expr && expr.getPosition() == 2);
124-
125-
// 2.2 Expect d0
126-
expr = llvm::dyn_cast<AffineDimExpr>(resultsInv2[1]);
127-
EXPECT_TRUE(expr && expr.getPosition() == 0);
128-
129-
// 2.3 Expect d3
130-
expr = llvm::dyn_cast<AffineDimExpr>(resultsInv2[2]);
131-
EXPECT_TRUE(expr && expr.getPosition() == 3);
116+
// Expect (d2, d0, d3)
117+
expected = {2, 0, 3};
118+
for (auto [idx, res] : llvm::enumerate(resultsInv2)) {
119+
AffineDimExpr expr = llvm::dyn_cast<AffineDimExpr>(res);
120+
EXPECT_TRUE(expr && expr.getPosition() == expected[idx]);
121+
}
132122
}

0 commit comments

Comments
 (0)