[Mlir-commits] [mlir] [mlir][affine] Treat failed dependence checks conservatively (PR #211014)
Akimasa Watanuki
llvmlistbot at llvm.org
Sat Aug 22 09:02:53 PDT 2026
================
@@ -1466,7 +1467,8 @@ AffineForOp mlir::affine::sinkSequentialLoops(AffineForOp forOp) {
// rooted at 'loops[0]', at loop depths in range [1, maxLoopDepth].
unsigned maxLoopDepth = loops.size();
std::vector<SmallVector<DependenceComponent, 2>> depCompsVec;
- getDependenceComponents(loops[0], maxLoopDepth, &depCompsVec);
+ if (failed(getDependenceComponents(loops[0], maxLoopDepth, &depCompsVec)))
----------------
Men-cotton wrote:
Could you also cover the `sinkSequentialLoops` failure path? The new test only exercises tiling and validity-checked permutation.
For example:
```mlir
// RUN: mlir-opt %s -pass-pipeline='builtin.module(func.func(affine-loop-fusion{mode=producer}))' | FileCheck %s
#dynamic_index = affine_map<()[s0, s1] -> (s0 * s1)>
// CHECK-LABEL: func.func @sink_unknown_dependence
func.func @sink_unknown_dependence(
%unknown: memref<?x9x9xi32>, %unknown_out: memref<9x9xi32>,
%carried: memref<9x9xi32>, %carried_out: memref<9x9xi32>,
%dummy: memref<1xi32>, %p: index, %q: index, %value: i32) {
// CHECK: affine.for %[[I:.*]] = 1 to 8
// CHECK-NEXT: affine.for %[[J:.*]] = 1 to 8
affine.for %i = 1 to 8 {
affine.for %j = 1 to 8 {
// Record an analyzable loop-carried dependence first.
// CHECK: affine.store %{{.*}}, %{{.*}}[%[[I]], %[[J]]]
affine.store %value, %carried[%i, %j] : memref<9x9xi32>
%previous = affine.load %carried[%i - 1, %j] : memref<9x9xi32>
affine.store %previous, %carried_out[%i, %j] : memref<9x9xi32>
// This access makes dependence analysis fail.
%z = affine.apply #dynamic_index()[%p, %q]
affine.store %value, %unknown[%z, %i, %j] : memref<?x9x9xi32>
%loaded = affine.load %unknown[%z, %i, %j] : memref<?x9x9xi32>
affine.store %loaded, %unknown_out[%i, %j] : memref<9x9xi32>
}
}
// Make the block eligible for affine-loop-fusion.
affine.for %k = 0 to 1 {
affine.store %value, %dummy[%k] : memref<1xi32>
}
return
}
```
https://github.com/llvm/llvm-project/pull/211014
More information about the Mlir-commits
mailing list