| Issue |
241120
|
| Summary |
[mlir][bug][fuzzer-found] affine-loop-fusion asserts while aligning slice-union spaces of a nested affine.parallel store
|
| Labels |
mlir
|
| Assignees |
|
| Reporter |
Kiritobl
|
#### Version
git commit hash: 0fdfbb6f057f1a01a9bc6fc025c502471f106f23
LLVM/MLIR 24.0.0git, optimized build with assertions.
#### Bug Description
`affine-loop-fusion{mode=producer}` aborts in `mergeAndAlignVars` while `computeSliceUnion` merges the slice constraint systems of two dependent accesses of the same producer/consumer pair. The source nest has an IV-dependent inner bound and contains an `affine.parallel` whose store writes the memref that the consumer reads.
Assertion:
```cpp
assert(loc < b->getNumDimVars() &&
"A's dim appears in B's non-dim position"); // FlatLinearValueConstraints.cpp:1346
```
The minimized input below parses and verifies successfully without the pass. It aborted in 5/5 runs (SIGABRT, shell exit 134).
Ablations on this input (all verified on this build): removing the `affine.parallel` store (keeping only its load), removing the `affine.parallel`, or making the source nest's inner bound constant all avoid the crash; making the *destination* bounds constant does not.
#### Crash Chain & Root Cause
Crash chain:
```text
affine-loop-fusion{mode=producer}
→ (anonymous namespace)::GreedyFusion::performFusionsIntoDest
→ mlir::affine::canFuseLoops
→ mlir::affine::computeSliceUnion
→ FlatLinearValueConstraints::mergeAndAlignVarsWithOther
→ mergeAndAlignVars(unsigned, FlatLinearValueConstraints*, FlatLinearValueConstraints*)
→ "A's dim appears in B's non-dim position"
```
`computeSliceUnion` (`mlir/lib/Dialect/Affine/Analysis/Utils.cpp:1645`) builds one constraint system per dependent pair with `ComputationSliceState::getAsConstraints` and then aligns them with `mergeAndAlignVarsWithOther(/*offset=*/0, &tmpSliceCst)` (`:1719`).
`getAsConstraints` (`:913-941`) puts the slice IVs into the **dim** range and every slice-bound operand into the **symbol** range (`numSymbols = lbOperands[0].size()`). The two pairs here are the store inside the `affine.parallel` body and the store in the loop body; they produce constraint systems with different IV/bound-operand sets, so a value that is a dim in one system also occurs in the other system at a symbol position. `mergeAndAlignVars` only accepts a hit inside `b->getNumDimVars()` and asserts otherwise, instead of aligning or skipping the pair.
Expected: `computeSliceUnion` should keep the two slice systems in a common space (or skip the union) instead of aborting.
#### Steps to Reproduce
```bash
mlir-opt '--pass-pipeline=builtin.module(func.func(affine-loop-fusion{mode=producer}))' reproducer.mlir -o /dev/null
```
The process terminates with SIGABRT (exit status 134) in 5/5 runs. Running `mlir-opt reproducer.mlir -o /dev/null` without the pass succeeds.
#### Reproducer (`reproducer.mlir`)
```mlir
#map = affine_map<(d0) -> (d0)>
#map1 = affine_map<(d0) -> (d0 + 1)>
func.func @f() {
%alloc = memref.alloc() : memref<2xf32>
%cst = arith.constant 6.000000e-01 : f32
affine.for %i = 0 to 1 {
affine.for %j = #map(%i) to #map1(%i) {
%c0 = arith.constant 0 : index
%dim = memref.dim %alloc, %c0 : memref<2xf32>
affine.parallel (%p) = (0) to (%dim mod 5 + 4) step (2) {
%5 = affine.load %alloc[%p] : memref<2xf32>
affine.store %5, %alloc[%p] : memref<2xf32>
}
affine.store %cst, %alloc[%j] : memref<2xf32>
}
}
affine.for %i = 0 to 4 {
affine.for %j = 0 to 1 {
affine.for %k = #map(%i) to #map1(%i) {
%1 = affine.load %alloc[%j] : memref<2xf32>
}
}
}
return
}
```
#### Stack Dump
The following block is the unmodified stderr from running the command above with this build:
```text
mlir-opt: /12T/qin/Fuzzing/MLIR_latest_20261104/llvm-project/mlir/lib/Analysis/FlatLinearValueConstraints.cpp:1346: void mergeAndAlignVars(unsigned int, mlir::FlatLinearValueConstraints*, mlir::FlatLinearValueConstraints*): Assertion `loc < b->getNumDimVars() && "A's dim appears in B's non-dim position"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0. Program arguments: /12T/qin/Fuzzing/MLIR_latest_20261104/install/bin/mlir-opt --mlir-disable-threading reproducer.mlir --pass-pipeline=builtin.module(func.func(affine-loop-fusion{mode=producer})) -o /dev/null
#0 0x00005607b5e61a29 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/12T/qin/Fuzzing/MLIR_latest_20261104/install/bin/mlir-opt+0x1fb9a29)
#1 0x00005607b5e5e22c llvm::sys::RunSignalHandlers() (/12T/qin/Fuzzing/MLIR_latest_20261104/install/bin/mlir-opt+0x1fb622c)
#2 0x00005607b5e5e396 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007f2898e6e520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007f2898ec29bc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007f2898ec29bc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x00007f2898ec29bc pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x00007f2898e6e476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007f2898e547f3 abort ./stdlib/abort.c:81:7
#9 0x00007f2898e5471b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007f2898e65e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x00005607b69207d6 mergeAndAlignVars(unsigned int, mlir::FlatLinearValueConstraints*, mlir::FlatLinearValueConstraints*) FlatLinearValueConstraints.cpp:0:0
#12 0x00005607bcdc9611 mlir::affine::computeSliceUnion(llvm::ArrayRef<mlir::Operation*>, llvm::ArrayRef<mlir::Operation*>, unsigned int, unsigned int, bool, mlir::affine::ComputationSliceState*) (/12T/qin/Fuzzing/MLIR_latest_20261104/install/bin/mlir-opt+0x8f21611)
#13 0x00005607bcd1dc53 mlir::affine::canFuseLoops(mlir::affine::AffineForOp, mlir::affine::AffineForOp, unsigned int, mlir::affine::ComputationSliceState*, mlir::affine::FusionStrategy) (/12T/qin/Fuzzing/MLIR_latest_20261104/install/bin/mlir-opt+0x8e75c53)
#14 0x00005607bccd0220 (anonymous namespace)::GreedyFusion::performFusionsIntoDest(unsigned int, unsigned int) LoopFusion.cpp:0:0
#15 0x00005607bccd1cea (anonymous namespace)::GreedyFusion::fuseProducerConsumerNodes(unsigned int) LoopFusion.cpp:0:0
#16 0x00005607bccd47d7 (anonymous namespace)::LoopFusion::runOnBlock(mlir::Block*) LoopFusion.cpp:0:0
#17 0x00005607bccd4b67 void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (.constprop.0) LoopFusion.cpp:0:0
#18 0x00005607bccd4c1c (anonymous namespace)::LoopFusion::runOnOperation() LoopFusion.cpp:0:0
#19 0x00005607be4be6d9 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/12T/qin/Fuzzing/MLIR_latest_20261104/install/bin/mlir-opt+0xa6166d9)
#20 0x00005607be4be9b4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/12T/qin/Fuzzing/MLIR_latest_20261104/install/bin/mlir-opt+0xa6169b4)
#21 0x00005607be4bf8b4 mlir::detail::OpToOpPassAdaptor::runOnOperationImpl(bool) (/12T/qin/Fuzzing/MLIR_latest_20261104/install/bin/mlir-opt+0xa6178b4)
#22 0x00005607be4be5b1 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/12T/qin/Fuzzing/MLIR_latest_20261104/install/bin/mlir-opt+0xa6165b1)
#23 0x00005607be4be9b4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/12T/qin/Fuzzing/MLIR_latest_20261104/install/bin/mlir-opt+0xa6169b4)
#24 0x00005607be4c0602 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (/12T/qin/Fuzzing/MLIR_latest_20261104/install/bin/mlir-opt+0xa618602)
#25 0x00005607be4c15d9 mlir::PassManager::run(mlir::Operation*) (/12T/qin/Fuzzing/MLIR_latest_20261104/install/bin/mlir-opt+0xa6195d9)
#26 0x00005607b5f2c0e6 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#27 0x00005607b5f2d69e processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, mlir::SourceMgrDiagnosticVerifierHandler*, llvm::ThreadPoolInterface*) MlirOptMain.cpp:0:0
#28 0x00005607b5f2d8e1 llvm::LogicalResult llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::'lambda'(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#29 0x00005607be7fc30d mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (/12T/qin/Fuzzing/MLIR_latest_20261104/install/bin/mlir-opt+0xa95430d)
#30 0x00005607b5f275da mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (.part.0) MlirOptMain.cpp:0:0
#31 0x00005607b5f2df21 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/12T/qin/Fuzzing/MLIR_latest_20261104/install/bin/mlir-opt+0x2085f21)
#32 0x00005607b5f2e174 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/12T/qin/Fuzzing/MLIR_latest_20261104/install/bin/mlir-opt+0x2086174)
#33 0x00005607b5e0592c main (/12T/qin/Fuzzing/MLIR_latest_20261104/install/bin/mlir-opt+0x1f5d92c)
#34 0x00007f2898e55d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#35 0x00007f2898e55e40 call_init ./csu/../csu/libc-start.c:128:20
#36 0x00007f2898e55e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#37 0x00005607b5e412c5 _start (/12T/qin/Fuzzing/MLIR_latest_20261104/install/bin/mlir-opt+0x1f992c5)
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs