Skip to content

Commit 426e335

Browse files
committed
Review comments, fix typos in tests
1 parent b985a17 commit 426e335

File tree

2 files changed

+55
-14
lines changed

2 files changed

+55
-14
lines changed

mlir/lib/Dialect/Affine/IR/ValueBoundsOpInterfaceImpl.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,17 @@ struct AffineDelinearizeIndexOpInterface
106106

107107
SmallVector<OpFoldResult> basis = op.getPaddedBasis();
108108
AffineExpr divisor = cstr.getExpr(1);
109-
for (OpFoldResult basisElem :
110-
ArrayRef<OpFoldResult>(basis).drop_front(resIdx + 1))
109+
for (OpFoldResult basisElem : llvm::drop_begin(basis, resIdx + 1))
111110
divisor = divisor * cstr.getExpr(basisElem);
112111

113-
auto resBound = cstr.bound(result);
114112
if (resIdx == 0) {
115-
resBound == linearIdx.floorDiv(divisor);
113+
cstr.bound(value) == linearIdx.floorDiv(divisor);
116114
if (!basis.front().isNull())
117-
resBound < cstr.getExpr(basis.front());
115+
cstr.bound(value) < cstr.getExpr(basis.front());
118116
return;
119117
}
120118
AffineExpr thisBasis = cstr.getExpr(basis[resIdx]);
121-
resBound == (linearIdx % (thisBasis * divisor)).floorDiv(divisor);
119+
cstr.bound(value) == (linearIdx % (thisBasis * divisor)).floorDiv(divisor);
122120
}
123121
};
124122

@@ -135,19 +133,19 @@ struct AffineLinearizeIndexOpInterface
135133
AffineExpr stride = cstr.getExpr(1);
136134
SmallVector<OpFoldResult> basis = op.getPaddedBasis();
137135
OperandRange multiIndex = op.getMultiIndex();
136+
unsigned numArgs = multiIndex.size();
138137
for (auto [revArgNum, length] : llvm::enumerate(llvm::reverse(basis))) {
139-
unsigned argNum = multiIndex.size() - (revArgNum + 1);
138+
unsigned argNum = numArgs - (revArgNum + 1);
140139
if (argNum == 0)
141140
break;
142141
OpFoldResult indexAsFoldRes = getAsOpFoldResult(multiIndex[argNum]);
143142
bound = bound + cstr.getExpr(indexAsFoldRes) * stride;
144143
stride = stride * cstr.getExpr(length);
145144
}
146145
bound = bound + cstr.getExpr(op.getMultiIndex().front()) * stride;
147-
auto resBound = cstr.bound(value);
148-
resBound == bound;
146+
cstr.bound(value) == bound;
149147
if (op.getDisjoint() && !basis.front().isNull()) {
150-
resBound <= stride *cstr.getExpr(basis.front());
148+
cstr.bound(value) < stride *cstr.getExpr(basis.front());
151149
}
152150
}
153151
};

mlir/test/Dialect/Affine/value-bounds-op-interface-impl.mlir

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ func.func @compare_maps(%a: index, %b: index) {
163163
// CHECK-DAG: #[[$map3:.+]] = affine_map<()[s0] -> (s0 mod 5)>
164164
// CHECK-LABEL: func.func @delinearize_static
165165
// CHECK-SAME: (%[[arg0:.+]]: index)
166-
// CHECK-DAG: %[[v1:.+]] = affine.apply #[[$map1]](}[%[[arg0]]]
167-
// CHECK-DAG: %[[v2:.+]] = affine.apply #[[$map2]](}[%[[arg0]]]
166+
// CHECK-DAG: %[[v1:.+]] = affine.apply #[[$map1]]()[%[[arg0]]]
167+
// CHECK-DAG: %[[v2:.+]] = affine.apply #[[$map2]]()[%[[arg0]]]
168168
// CHECK-DAG: %[[v3:.+]] = affine.apply #[[$map3]]()[%[[arg0]]]
169169
// CHECK: return %[[v1]], %[[v2]], %[[v3]]
170170
func.func @delinearize_static(%arg0: index) -> (index, index, index) {
@@ -174,7 +174,31 @@ func.func @delinearize_static(%arg0: index) -> (index, index, index) {
174174
%1 = "test.reify_bound"(%0#0) {type = "EQ"} : (index) -> (index)
175175
%2 = "test.reify_bound"(%0#1) {type = "EQ"} : (index) -> (index)
176176
%3 = "test.reify_bound"(%0#2) {type = "EQ"} : (index) -> (index)
177-
// TODO: why doesn't this return true? I'm setting the bound.
177+
// expected-remark @below{{true}}
178+
"test.compare"(%0#0, %c2) {cmp = "LT"} : (index, index) -> ()
179+
// expected-remark @below{{true}}
180+
"test.compare"(%0#1, %c3) {cmp = "LT"} : (index, index) -> ()
181+
return %1, %2, %3 : index, index, index
182+
}
183+
184+
// -----
185+
186+
// CHECK-DAG: #[[$map1:.+]] = affine_map<()[s0] -> (s0 floordiv 15)>
187+
// CHECK-DAG: #[[$map2:.+]] = affine_map<()[s0] -> ((s0 mod 15) floordiv 5)>
188+
// CHECK-DAG: #[[$map3:.+]] = affine_map<()[s0] -> (s0 mod 5)>
189+
// CHECK-LABEL: func.func @delinearize_static_no_outer_bound
190+
// CHECK-SAME: (%[[arg0:.+]]: index)
191+
// CHECK-DAG: %[[v1:.+]] = affine.apply #[[$map1]]()[%[[arg0]]]
192+
// CHECK-DAG: %[[v2:.+]] = affine.apply #[[$map2]]()[%[[arg0]]]
193+
// CHECK-DAG: %[[v3:.+]] = affine.apply #[[$map3]]()[%[[arg0]]]
194+
// CHECK: return %[[v1]], %[[v2]], %[[v3]]
195+
func.func @delinearize_static_no_outer_bound(%arg0: index) -> (index, index, index) {
196+
%c2 = arith.constant 2 : index
197+
%c3 = arith.constant 3 : index
198+
%0:3 = affine.delinearize_index %arg0 into (3, 5) : index, index, index
199+
%1 = "test.reify_bound"(%0#0) {type = "EQ"} : (index) -> (index)
200+
%2 = "test.reify_bound"(%0#1) {type = "EQ"} : (index) -> (index)
201+
%3 = "test.reify_bound"(%0#2) {type = "EQ"} : (index) -> (index)
178202
"test.compaare"(%0#0, %c2) {cmp = "LT"} : (index, index) -> ()
179203
// expected-remark @below{{true}}
180204
"test.compare"(%0#1, %c3) {cmp = "LT"} : (index, index) -> ()
@@ -186,10 +210,29 @@ func.func @delinearize_static(%arg0: index) -> (index, index, index) {
186210
// CHECK: #[[$map:.+]] = affine_map<()[s0, s1] -> (s0 + s1 * 3)>
187211
// CHECK-LABEL: func.func @linearize_static
188212
// CHECK-SAME: (%[[arg0:.+]]: index, %[[arg1:.+]]: index)
189-
// CHECK: %[[v1:.+]] = affine.apply #[[$map]]()[%[[arg0]], %[[arg1]]]
213+
// CHECK: %[[v1:.+]] = affine.apply #[[$map]]()[%[[arg1]], %[[arg0]]]
190214
// CHECK: return %[[v1]]
191215
func.func @linearize_static(%arg0: index, %arg1: index) -> index {
216+
%c6 = arith.constant 6 : index
192217
%0 = affine.linearize_index disjoint [%arg0, %arg1] by (2, 3) : index
193218
%1 = "test.reify_bound"(%0) {type = "EQ"} : (index) -> (index)
219+
// expected-remark @below{{true}}
220+
"test.compare"(%0, %c6) {cmp = "LT"} : (index, index) -> ()
221+
return %1 : index
222+
}
223+
224+
// -----
225+
226+
// CHECK: #[[$map:.+]] = affine_map<()[s0, s1] -> (s0 + s1 * 3)>
227+
// CHECK-LABEL: func.func @linearize_static_no_outer_bound
228+
// CHECK-SAME: (%[[arg0:.+]]: index, %[[arg1:.+]]: index)
229+
// CHECK: %[[v1:.+]] = affine.apply #[[$map]]()[%[[arg1]], %[[arg0]]]
230+
// CHECK: return %[[v1]]
231+
func.func @linearize_static_no_outer_bound(%arg0: index, %arg1: index) -> index {
232+
%c6 = arith.constant 6 : index
233+
%0 = affine.linearize_index disjoint [%arg0, %arg1] by (3) : index
234+
%1 = "test.reify_bound"(%0) {type = "EQ"} : (index) -> (index)
235+
// expected-error @below{{unknown}}
236+
"test.compare"(%0, %c6) {cmp = "LT"} : (index, index) -> ()
194237
return %1 : index
195238
}

0 commit comments

Comments
 (0)