Skip to content

Commit

Permalink
[MLIR][Affine] Fix affine.parallel op domain add
Browse files Browse the repository at this point in the history
Fix obvious bug in `addAffineParallelOpDomain` that would lead to
incorrect domain constraints for any affine.parallel op with
dimensionality greater than one.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D144349
  • Loading branch information
bondhugula committed Feb 21, 2023
1 parent 8a583dd commit 332b8cf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mlir/lib/Dialect/Affine/Analysis/AffineStructures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ FlatAffineValueConstraints::addAffineForOpDomain(AffineForOp forOp) {
LogicalResult FlatAffineValueConstraints::addAffineParallelOpDomain(
AffineParallelOp parallelOp) {
size_t ivPos = 0;
for (auto iv : parallelOp.getIVs()) {
for (Value iv : parallelOp.getIVs()) {
unsigned pos;
if (!findVar(iv, &pos)) {
assert(false && "variable expected for the IV value");
Expand All @@ -668,6 +668,7 @@ LogicalResult FlatAffineValueConstraints::addAffineParallelOpDomain(
else if (failed(addBound(BoundType::UB, pos, upperBound,
parallelOp.getUpperBoundsOperands())))
return failure();
++ivPos;
}
return success();
}
Expand Down
28 changes: 28 additions & 0 deletions mlir/test/Transforms/memref-dependence-check.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -1102,3 +1102,31 @@ func.func @affine_if_no_dependence() {
}
return
}

// -----

// CHECK-LABEL: func @affine_parallel_dep_check
func.func @affine_parallel_dep_check() {
%memref_23 = memref.alloc() : memref<1x130xf32>
%memref_25 = memref.alloc() : memref<1x130x130xf32>
%cst = arith.constant 0.0 : f32
affine.parallel (%arg4, %arg5) = (0, 0) to (1, 130) {
affine.store %cst, %memref_25[%arg4, %arg5, 129] : memref<1x130x130xf32>
// expected-remark@above {{dependence from 0 to 0 at depth 1 = false}}
// expected-remark@above {{dependence from 0 to 0 at depth 2 = false}}
// expected-remark@above {{dependence from 0 to 0 at depth 3 = false}}
// expected-remark@above {{dependence from 0 to 1 at depth 1 = true}}
}
%memref_27 = memref.alloc() : memref<1x128x128xf32>
affine.parallel (%arg4) = (0) to (130) {
affine.parallel (%arg5, %arg6) = (0, 0) to (1, 130) {
affine.load %memref_25[0, %arg4 + %arg5, %arg6] : memref<1x130x130xf32>
// expected-remark@above {{dependence from 1 to 1 at depth 1 = false}}
// expected-remark@above {{dependence from 1 to 1 at depth 2 = false}}
// expected-remark@above {{dependence from 1 to 1 at depth 3 = false}}
// expected-remark@above {{dependence from 1 to 1 at depth 4 = false}}
// expected-remark@above {{dependence from 1 to 0 at depth 1 = false}}
}
}
return
}

0 comments on commit 332b8cf

Please sign in to comment.