Skip to content

Commit ed5aab1

Browse files
committed
fixup! [mlir][test] Add unittests for getInversePermutation
Make the checks more restrictive
1 parent 9d41db6 commit ed5aab1

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

mlir/unittests/IR/AffineMapTest.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,18 @@ TEST(AffineMapTest, getInversePermutation) {
9696
AffineMap inverseMap1 = inversePermutation(map1);
9797
auto resultsInv1 = inverseMap1.getResults();
9898
EXPECT_EQ(resultsInv1.size(), 3UL);
99-
EXPECT_TRUE(resultsInv1[0].isFunctionOfDim(2));
100-
EXPECT_TRUE(resultsInv1[1].isFunctionOfDim(0));
101-
EXPECT_TRUE(resultsInv1[2].isFunctionOfDim(3));
99+
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);
102111

103112
// 2. (d0, d1, d2) -> (d1, d0 + d1, d0, d2, d1, d2, d1, d0)
104113
auto sum = d0 + d1;
@@ -108,7 +117,16 @@ TEST(AffineMapTest, getInversePermutation) {
108117
AffineMap inverseMap2 = inversePermutation(map2);
109118
auto resultsInv2 = inverseMap2.getResults();
110119
EXPECT_EQ(resultsInv2.size(), 3UL);
111-
EXPECT_TRUE(resultsInv1[0].isFunctionOfDim(2));
112-
EXPECT_TRUE(resultsInv1[1].isFunctionOfDim(0));
113-
EXPECT_TRUE(resultsInv1[2].isFunctionOfDim(3));
120+
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);
114132
}

0 commit comments

Comments
 (0)