Skip to content

Commit e8746ac

Browse files
fix tests and opt the code.
1 parent c8551ce commit e8746ac

File tree

3 files changed

+58
-13
lines changed

3 files changed

+58
-13
lines changed

mlir/docs/Dialects/Affine.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ immediately enclosed by the latter),
6969
3. a value that dominates the `AffineScope` op enclosing the value's
7070
use,
7171
4. the result of a constant operation,
72-
5. the result of a `Pure` operation that its operands are the valid symbolic identifiers.
72+
5. the result of a `Pure` operation whose operands are valid symbolic identifiers.
7373
6. the result of a
7474
[`dim` operation](MemRef.md/#memrefdim-mlirmemrefdimop) on either a memref that
7575
is an argument to a `AffineScope` op or a memref where the corresponding

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,8 @@ bool mlir::affine::isValidSymbol(Value value) {
410410
/// A value can be used as a symbol for `region` iff it meets one of the
411411
/// following conditions:
412412
/// *) It is a constant.
413-
/// *) It is a result of a `Pure` operation that its operands are the valid
414-
/// *) symbolic identifiers.
413+
/// *) It is a result of a `Pure` operation whose operands are valid symbolic
414+
/// *) identifiers.
415415
/// *) It is a result of the dim op on a memref whose corresponding size is
416416
/// a valid symbol.
417417
/// *) It is defined at the top level of 'region' or is its argument.
@@ -444,14 +444,11 @@ bool mlir::affine::isValidSymbol(Value value, Region *region) {
444444
if (matchPattern(defOp, m_Constant(&operandCst)))
445445
return true;
446446

447-
// `Pure` operation that its operands are the valid symbolic identifiers.
448-
if (isPure(defOp)) {
449-
bool operandVaildSymbol =
450-
llvm::all_of(defOp->getOperands(), [&](Value operand) {
451-
return affine::isValidSymbol(operand, region);
452-
});
453-
if (operandVaildSymbol)
454-
return true;
447+
// `Pure` operation that whose operands are valid symbolic identifiers.
448+
if (isPure(defOp) && llvm::all_of(defOp->getOperands(), [&](Value operand) {
449+
return affine::isValidSymbol(operand, region);
450+
})) {
451+
return true;
455452
}
456453

457454
// Dim op results could be valid symbols at any level.

mlir/test/Dialect/Affine/ops.mlir

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ module attributes {gpu.container_module} {
331331

332332
// CHECK: #[[$ATTR_0:.+]] = affine_map<()[s0] -> (s0 mod 32)>
333333

334-
// CHECK-LABEL: @affine_thread_id
334+
// CHECK-LABEL: gpu.func @affine_thread_id
335335

336336
module {
337337
gpu.module @gpu {
@@ -360,4 +360,52 @@ module {
360360
// CHECK: %[[VAL_5:.*]] = gpu.thread_id x
361361
// CHECK: %[[VAL_6:.*]] = affine.apply #[[$ATTR_0]](){{\[}}%[[VAL_5]]]
362362
// CHECK: %[[VAL_7:.*]] = arith.constant 128 : index
363-
// CHECK: affine.for %[[VAL_8:.*]] = %[[VAL_6]] to %[[VAL_7]] step 8 {
363+
// CHECK: affine.for %{{.*}} = %[[VAL_6]] to %[[VAL_7]] step 8 {
364+
365+
// -----
366+
367+
#map = affine_map<(d0)[s0] -> (d0 + s0)>
368+
369+
// CHECK: #[[$ATTR_0:.+]] = affine_map<(d0)[s0] -> (d0 + s0)>
370+
371+
// CHECK-LABEL: func @arith_add_vaild_symbol_upper_bound
372+
373+
func.func @arith_add_vaild_symbol_upper_bound(%arg : index) {
374+
affine.for %n0 = 0 to 7 {
375+
%dim = arith.addi %arg, %arg : index
376+
affine.for %n1 = 0 to #map(%dim)[%arg] {
377+
}
378+
}
379+
return
380+
}
381+
382+
// CHECK-SAME: %[[VAL_0:.*]]: index) {
383+
// CHECK: affine.for %[[VAL_1:.*]] = 0 to 7 {
384+
// CHECK: %[[VAL_2:.*]] = arith.addi %[[VAL_0]], %[[VAL_0]] : index
385+
// CHECK: affine.for %[[VAL_3:.*]] = 0 to #[[$ATTR_0]](%[[VAL_2]]){{\[}}%[[VAL_0]]] {
386+
// CHECK: }
387+
// CHECK: }
388+
389+
// -----
390+
391+
#map = affine_map<(d0)[s0] -> (d0 + s0)>
392+
393+
// CHECK: #[[$ATTR_0:.+]] = affine_map<(d0)[s0] -> (d0 + s0)>
394+
395+
// CHECK-LABEL: func @arith_add_vaild_symbol_lower_bound
396+
397+
func.func @arith_add_vaild_symbol_lower_bound(%arg : index) {
398+
affine.for %n0 = 0 to 7 {
399+
%dim = arith.addi %arg, %arg : index
400+
affine.for %n1 = #map(%dim)[%arg] to 7 {
401+
}
402+
}
403+
return
404+
}
405+
406+
// CHECK-SAME: %[[VAL_0:.*]]: index) {
407+
// CHECK: affine.for %[[VAL_1:.*]] = 0 to 7 {
408+
// CHECK: %[[VAL_2:.*]] = arith.addi %[[VAL_0]], %[[VAL_0]] : index
409+
// CHECK: affine.for %[[VAL_3:.*]] = #[[$ATTR_0]](%[[VAL_2]]){{\[}}%[[VAL_0]]] to 7 {
410+
// CHECK: }
411+
// CHECK: }

0 commit comments

Comments
 (0)