diff --git a/mlir/lib/Analysis/AffineStructures.cpp b/mlir/lib/Analysis/AffineStructures.cpp --- a/mlir/lib/Analysis/AffineStructures.cpp +++ b/mlir/lib/Analysis/AffineStructures.cpp @@ -731,8 +731,11 @@ SmallVector operands = ifOp.getOperands(); cst.setIdValues(0, cst.getNumDimAndSymbolIds(), operands); - // Merge the constraints from ifOp to the current domain. + // Merge the constraints from ifOp to the current domain. We need first merge + // and align the IDs from both constraints, and then append the constraints + // from the ifOp into the current one. mergeAndAlignIdsWithOther(0, &cst); + append(cst); } // Searches for a constraint with a non-zero coefficient at 'colIdx' in diff --git a/mlir/test/Transforms/memref-dependence-check.mlir b/mlir/test/Transforms/memref-dependence-check.mlir --- a/mlir/test/Transforms/memref-dependence-check.mlir +++ b/mlir/test/Transforms/memref-dependence-check.mlir @@ -9,15 +9,15 @@ %m = alloc() : memref<10xf32> %cf7 = constant 7.0 : f32 %c0 = constant 4 : index - // There is a dependence from store 0 to load 1 at depth 1 because the - // ancestor IfOp of the store, dominates the ancestor ForSmt of the load, - // and thus the store "may" conditionally execute before the load. + // There is no dependence from store 0 to load 1 at depth if we take into account + // the constraint introduced by the following `affine.if`, which indicate that + // the store 0 will never be executed. affine.if #set0(%c0) { affine.for %i0 = 0 to 10 { affine.store %cf7, %m[%i0] : memref<10xf32> // 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 1 at depth 1 = true}} + // expected-remark@above {{dependence from 0 to 1 at depth 1 = false}} } } affine.for %i1 = 0 to 10 { @@ -1044,7 +1044,7 @@ %N = dim %0, %c0 : memref<101xf32> %cf7 = constant 7.0 : f32 - affine.for %i0 = 0 to 100 { + affine.for %i0 = 0 to 101 { affine.if #set1(%i0)[%N] { %1 = affine.load %0[%i0] : memref<101xf32> // expected-remark@above {{dependence from 0 to 0 at depth 1 = false}}