Issue 237998
Summary [MLIR] `-affine-parallelize` crashes with incompatible Presburger spaces assertion
Labels mlir
Assignees
Reporter frida-albrecht
    
### Description

The `-affine-parallelize` pass crashes with an assertion failure in` mlir::presburger::mergeLocalVars` when processing nested affine loops containing memory accesses with affine index expressions.

The crash occurs during memory dependence analysis, where incompatible Presburger spaces are encountered while constructing access relations.

### test commit
[880b33a](https://github.com/llvm/llvm-project/commit/880b33a6c8e7e2fd9a0e6d9c131b3b2780a8e77e)

### test case:
``` mlir
module {
  func.func @main()  {
    %c1 = arith.constant 1 : index
    %cst_0 = arith.constant 0.000000e+00 : f32
 %alloc_1 = memref.alloc() alignment = 64 : memref<7x7x8xf32, #spirv.storage_class<StorageBuffer>>
    %expand_shape = memref.expand_shape %alloc_1 [[0, 1], [2], [3]] output_shape [1, 7, 7, 8] : memref<7x7x8xf32, #spirv.storage_class<StorageBuffer>> into memref<1x7x7x8xf32, #spirv.storage_class<StorageBuffer>>
    gpu.launch blocks(%arg0, %arg1, %arg2) in (%arg6 = %c1, %arg7 = %c1, %arg8 = %c1) threads(%arg3, %arg4, %arg5) in (%arg9 = %c1, %arg10 = %c1, %arg11 = %c1) {
      affine.for %arg12 = 0 to 7 {
        affine.for %arg13 = 0 to 7 {
          affine.for %arg14 = 0 to 8 {
            %1 = affine.linearize_index disjoint [%arg0, %arg12] by (1, 7) : index
            affine.store %cst_0, %alloc_1[%1, %arg13, %arg14] : memref<7x7x8xf32, #spirv.storage_class<StorageBuffer>>
 }
        }
      }
      gpu.terminator
    }
    return
 }
}


```



### Step to reproduce:
```
mlir-opt test.mlir -affine-parallelize
```

### Crash backtrace:
```
mlir-opt: /home/workdir/llvm-project-latest/mlir/lib/Analysis/Presburger/Utils.cpp:292: void mlir::presburger::mergeLocalVars(IntegerRelation &, IntegerRelation &, llvm::function_ref<bool (unsigned int, unsigned int)>): Assertion `relA.getSpace().isCompatible(relB.getSpace()) && "Spaces should be compatible."' 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: bin/mlir-opt test.mlir -affine-parallelize
 #0 0x0000562078b4b93b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (bin/mlir-opt+0x21e393b)
 #1 0x0000562078b48741 llvm::sys::RunSignalHandlers() (bin/mlir-opt+0x21e0741)
 #2 0x0000562078b4c66b SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007f0b1d0a4520 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f0b1d0f89fc pthread_kill (/usr/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007f0b1d0a4476 gsignal (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007f0b1d08a7f3 abort (/usr/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007f0b1d08a71b (/usr/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007f0b1d09be96 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x000056208126cbb9 (bin/mlir-opt+0xa904bb9)
#10 0x0000562081201af2 mlir::presburger::IntegerRelation::mergeLocalVars(mlir::presburger::IntegerRelation&) (bin/mlir-opt+0xa899af2)
#11 0x000056207f7caa33 mlir::affine::getAccessRelation(mlir::affine::AffineValueMap const&, mlir::affine::FlatAffineValueConstraints const&, mlir::presburger::IntegerRelation&) (bin/mlir-opt+0x8e62a33)
#12 0x000056207f7caca6 mlir::affine::MemRefAccess::getAccessRelation(mlir::presburger::IntegerRelation&) const (bin/mlir-opt+0x8e62ca6)
#13 0x000056207f7c9ba1 mlir::affine::checkMemrefAccessDependence(mlir::affine::MemRefAccess const&, mlir::affine::MemRefAccess const&, unsigned int, mlir::affine::FlatAffineValueConstraints*, llvm::SmallVector<mlir::affine::DependenceComponent, 2u>*, bool) (bin/mlir-opt+0x8e61ba1)
#14 0x000056207f7c98a3 mlir::affine::isLoopMemoryParallel(mlir::affine::AffineForOp) (bin/mlir-opt+0x8e618a3)
#15 0x000056207f7c9742 mlir::affine::isLoopParallel(mlir::affine::AffineForOp, llvm::SmallVectorImpl<mlir::affine::LoopReduction>*) (bin/mlir-opt+0x8e61742)
#16 0x000056207f690247 void llvm::function_ref<void (mlir::Operation*)>::callback_fn<std::enable_if<!llvm::is_one_of<mlir::affine::AffineForOp, mlir::Operation*, mlir::Region*, mlir::Block*>::value && std::is_same<void, void>::value, void>::type mlir::detail::walk<(mlir::WalkOrder)0, mlir::ForwardIterator, (anonymous namespace)::AffineParallelize::runOnOperation()::$_0, mlir::affine::AffineForOp, void>(mlir::Operation*, (anonymous namespace)::AffineParallelize::runOnOperation()::$_0&&)::'lambda'(mlir::Operation*)>(long, mlir::Operation*) AffineParallelize.cpp:0:0
#17 0x0000562078c0f7b6 void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (bin/mlir-opt+0x22a77b6)
#18 0x0000562078c0f84e void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (bin/mlir-opt+0x22a784e)
#19 0x0000562078c0f84e void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (bin/mlir-opt+0x22a784e)
#20 0x000056207f68fc9b (anonymous namespace)::AffineParallelize::runOnOperation() AffineParallelize.cpp:0:0
#21 0x00005620810b3d08 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (bin/mlir-opt+0xa74bd08)
#22 0x00005620810b4cf7 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (bin/mlir-opt+0xa74ccf7)
#23 0x00005620810b792e mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (bin/mlir-opt+0xa74f92e)
#24 0x00005620810b405e mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (bin/mlir-opt+0xa74c05e)
#25 0x00005620810b4cf7 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (bin/mlir-opt+0xa74ccf7)
#26 0x00005620810bbb3a mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (bin/mlir-opt+0xa753b3a)
#27 0x00005620810bb49d mlir::PassManager::run(mlir::Operation*) (bin/mlir-opt+0xa75349d)
#28 0x0000562078bfb999 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#29 0x0000562078bfab1f 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&)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#30 0x00005620813ac486 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) (bin/mlir-opt+0xaa44486)
#31 0x0000562078bf0206 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (bin/mlir-opt+0x2288206)
#32 0x0000562078bf05d5 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (bin/mlir-opt+0x22885d5)
#33 0x0000562078bf084b mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (bin/mlir-opt+0x228884b)
#34 0x0000562078b313a2 main (bin/mlir-opt+0x21c93a2)
#35 0x00007f0b1d08bd90 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#36 0x00007f0b1d08be40 __libc_start_main (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#37 0x0000562078b30ef5 _start (bin/mlir-opt+0x21c8ef5)
Aborted (core dumped)
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to