diff --git a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp --- a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp +++ b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp @@ -707,12 +707,7 @@ LLVM_DEBUG(llvm::dbgs() << "Unable to compute source's domain\n"); return std::nullopt; } - // As the set difference utility currently cannot handle symbols in its - // operands, validity of the slice cannot be determined. - if (srcConstraints.getNumSymbolVars() > 0) { - LLVM_DEBUG(llvm::dbgs() << "Cannot handle symbols in source domain\n"); - return std::nullopt; - } + // TODO: Handle local vars in the source domains while using the 'projectOut' // utility below. Currently, aligning is not done assuming that there will be // no local vars in the source domain. @@ -734,6 +729,9 @@ sliceConstraints.projectOut(ivs.size(), sliceConstraints.getNumVars() - ivs.size()); + srcConstraints.projectOut(ivs.size(), + srcConstraints.getNumVars() - ivs.size()); + LLVM_DEBUG(llvm::dbgs() << "Domain of the source of the slice:\n"); LLVM_DEBUG(srcConstraints.dump()); LLVM_DEBUG(llvm::dbgs() << "Domain of the slice if this fusion succeeds " diff --git a/mlir/test/Transforms/loop-fusion-4.mlir b/mlir/test/Transforms/loop-fusion-4.mlir --- a/mlir/test/Transforms/loop-fusion-4.mlir +++ b/mlir/test/Transforms/loop-fusion-4.mlir @@ -1,5 +1,6 @@ // RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline='builtin.module(func.func(affine-loop-fusion{mode=producer}))' -split-input-file | FileCheck %s --check-prefix=PRODUCER-CONSUMER // RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline='builtin.module(func.func(affine-loop-fusion{fusion-maximal mode=sibling}))' -split-input-file | FileCheck %s --check-prefix=SIBLING-MAXIMAL +// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline='builtin.module(func.func(affine-loop-fusion{fusion-maximal mode=producer}))' -split-input-file | FileCheck %s --check-prefix=MAXIMAL // Part I of fusion tests in mlir/test/Transforms/loop-fusion.mlir. // Part II of fusion tests in mlir/test/Transforms/loop-fusion-2.mlir @@ -190,3 +191,32 @@ // PRODUCER-CONSUMER-NEXT: } return } + +// ----- + +// MAXIMAL-LABEL func @fusion@nonconstant_bound +func.func @fusion_nonconstant_bound(%arg0: memref) { + %cst = arith.constant 1.000000e+00 : f32 + %cst_0 = arith.constant 2.000000e+00 : f32 + %c0 = arith.constant 0 : index + %dim = memref.dim %arg0, %c0 : memref + affine.for %arg1 = 0 to %dim { + %0 = affine.load %arg0[%arg1] : memref + %1 = arith.addf %0, %cst : f32 + affine.store %1, %arg0[%arg1] : memref + } + affine.for %arg1 = 0 to %dim { + %0 = affine.load %arg0[%arg1] : memref + %1 = arith.addf %0, %cst_0 : f32 + affine.store %1, %arg0[%arg1] : memref + } + // MAXIMAL: affine.for %[[idx:.*]] = 0 to %{{.*}} { + // MAXIMAL-NEXT: affine.load %[[arr:.*]][%[[idx]]] : memref + // MAXIMAL-NEXT: arith.addf + // MAXIMAL-NEXT: affine.store %{{.*}}, %[[arr]][%[[idx]]] : memref + // MAXIMAL-NEXT: affine.load %[[arr:.*]][%[[idx]]] : memref + // MAXIMAL-NEXT: arith.addf + // MAXIMAL-NEXT: affine.store %{{.*}}, %[[arr]][%[[idx]]] : memref + // MAXIMAL-NEXT: } + return +}