llvm / llvm/llvm-project

[MLIR] `--affine-loop-fusion` crashes during dependence analysis

Open
#224,224 2 comments 0 reactions 1 assignee Assigned to @purnima-nlp View on GitHub
crash mlir
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

### Description

I encountered a crash when running `--affine-loop-fusion` on the following MLIR input.
The crash is triggered during affine dependence analysis and results in an `UNREACHABLE` assertion in mlir/lib/Dialect/Affine/Analysis/Utils.cpp:256.

### Tested commit

[3b8ee89](https://github.com/llvm/llvm-project/commit/3b8ee89006f5a228fce75528f8dd80b4229abcc1)

### Test case

```mlir
#map = affine_map<(d0) -> (d0)>
#map1 = affine_map<(d0) -> (d0 + 1)>
module {
func.func @main(%arg0: tensor<4xf16>) {
%0 = ub.poison : f16
%cst = arith.constant 1.000000e+00 : f16
%1 = bufferization.to_buffer %arg0 : tensor<4xf16> to memref<4xf16, strided<[?], offset: ?>>
%alloc = memref.alloc() : memref<4xf16, 1>
%alloc_0 = memref.alloc() : memref<4xf16>
affine.for %arg1 = 0 to 4 {
affine.for %arg2 = #map(%arg1) to #map1(%arg1) {
%2 = affine.load %1[%arg2] : memref<4xf16, strided<[?], offset: ?>>
%3 = arith.negf %2 : f16
%4 = math.exp %3 : f16
%5 = arith.addf %4, %cst : f16
%6 = arith.divf %cst, %5 : f16
affine.store %6, %alloc[%arg2] : memref<4xf16, 1>
}
}
affine.for %arg1 = 0 to 4 step 128 {
%2 = vector.transfer_read %alloc[%arg1], %0 : memref<4xf16, 1>, vector<128xf16>
}
return
}
}
```

### Steps to reproduce

```
mlir-opt test.mlir --affine-loop-fusion
```

### stack trace

```
unexpected op
UNREACHABLE executed at /home/workdir/llvm-project-latest/mlir/lib/Dialect/Affine/Analysis/Utils.cpp:256!
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: mlir-opt test.mlir --affine-loop-fusion
#0 0x0000555a2cb1cd0b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (../llvm-project-latest/build/bin/mlir-opt+0x1fc2d0b)
#1 0x0000555a2cb19b11 llvm::sys::RunSignalHandlers() (../llvm-project-latest/build/bin/mlir-opt+0x1fbfb11)
#2 0x0000555a2cb1da3b SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007f0704ff6520 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007f070504a9fc pthread_kill (/usr/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x00007f0704ff6476 gsignal (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007f0704fdc7f3 abort (/usr/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x0000555a2cb0313f (../llvm-project-latest/build/bin/mlir-opt+0x1fa913f)
#8 0x0000555a332e0c1c (../llvm-project-latest/build/bin/mlir-opt+0x8786c1c)
#9 0x0000555a332e098e bool __gnu_cxx::__ops::_Iter_pred, llvm::ArrayRef) const::'lambda'(mlir::Operation*)>::operator()(mlir::Operation* const*) Utils.cpp:0:0
#10 0x0000555a332cb687 mlir::affine::MemRefDependenceGraph::init(bool) (../llvm-project-latest/build/bin/mlir-opt+0x8771687)
#11 0x0000555a33029e56 void llvm::function_ref::callback_fn<(anonymous namespace)::LoopFusion::runOnOperation()::$_0>(long, mlir::Operation*) LoopFusion.cpp:0:0
#12 0x0000555a2cbdb47e void mlir::detail::walk(mlir::Operation*, llvm::function_ref, mlir::WalkOrder) (../llvm-project-latest/build/bin/mlir-opt+0x208147e)
#13 0x0000555a33027c16 (anonymous namespace)::LoopFusion::runOnOperation() LoopFusion.cpp:0:0
#14 0x0000555a34d1c3ee mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (../llvm-project-latest/build/bin/mlir-opt+0xa1c23ee)
#15 0x0000555a34d1d364 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (../llvm-project-latest/build/bin/mlir-opt+0xa1c3364)
#16 0x0000555a34d240fa mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (../llvm-project-latest/build/bin/mlir-opt+0xa1ca0fa)
#17 0x0000555a34d23a5d mlir::PassManager::run(mlir::Operation*) (../llvm-project-latest/build/bin/mlir-opt+0xa1c9a5d)
#18 0x0000555a2cbc858f performActions(llvm::raw_ostream&, std::shared_ptr const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#19 0x0000555a2cbc7761 llvm::LogicalResult llvm::function_ref>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>::callback_fn>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_0>(long, std::unique_ptr>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#20 0x0000555a35076ec6 mlir::splitAndProcessBuffer(std::unique_ptr>, llvm::function_ref>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (../llvm-project-latest/build/bin/mlir-opt+0xa51cec6)
#21 0x0000555a2cbbdba6 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (../llvm-project-latest/build/bin/mlir-opt+0x2063ba6)
#22 0x0000555a2cbbdf7a mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (../llvm-project-latest/build/bin/mlir-opt+0x2063f7a)
#23 0x0000555a2cbbe1eb mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (../llvm-project-latest/build/bin/mlir-opt+0x20641eb)
#24 0x0000555a2cb027cd main (../llvm-project-latest/build/bin/mlir-opt+0x1fa87cd)
#25 0x00007f0704fddd90 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#26 0x00007f0704fdde40 __libc_start_main (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#27 0x0000555a2cb02325 _start (../llvm-project-latest/build/bin/mlir-opt+0x1fa8325)
Aborted (core dumped)
```

Contributor guide

Open the contributing guide

Research direction

Start by running `mlir-opt test.mlir --affine-loop-fusion` with the supplied MLIR input and inspect `mlir/lib/Dialect/Affine/Analysis/Utils.cpp:256`, following the stack through `MemRefDependenceGraph::init` and `LoopFusion.cpp`. Add a regression test using this reproducer and verify that affine loop fusion no longer aborts during dependence analysis.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.