[mlir]Error in using -affine-data-copy-generate
Hello, when trying to use some passes to lower MLIR, I got an error (commit: #e6c23f4). I think this error is caused by
-affine-data-copy-generate="generate-dma".
I tried to change the parameter as -affine-data-copy-generate="generate-dma=false".
However, the conversion failed with a crash.
Here is my code:
module {
func.func @main(%arg0: tensor<1xi1>) {
%10 = "tosa.argmax"(%arg0) {axis = 0 : i64} : (tensor<1xi1>) -> tensor<i32>
return
}
}
Execution command:
mlir-opt temp.mlir -pass-pipeline="func.func(tosa-to-linalg)" -linalg-bufferize -linalg-fold-unit-extent-dims -convert-linalg-to-affine-loops -o temp.mlir
mlir-opt temp1.mlir -affine-data-copy-generate="generate-dma"
The error as displayed below:
temp1.mlir:15:10: error: operand #0 does not dominate this use
%1 = affine.load %collapse_shape[] : memref<i1>
^
temp1.mlir:15:10: note: see current operation: "affine.dma_start"(%34, %19, %20, %13, %12) {dst_map = affine_map<() -> ()>, src_map = affine_map<() -> ()>, tag_map = affine_map<(d0) -> (d0)>} : (memref<i1>, memref<i1, 1>, memref<1xi32>, index, index) -> ()
temp1.mlir:14:23: note: operand defined here (op in the same block)
%collapse_shape = memref.collapse_shape %0 [] : memref<1xi1> into memref<i1>
^
However, when I tired cmd mlir-opt temp1.mlir -affine-data-copy-generate="generate-dma=false",
it crashed with following backtrace:
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /data/llvm/build/bin/mlir-opt temp1.mlir -affine-data-copy-generate=generate-dma=false
#0 0x0000557df30778cf PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
#1 0x0000557df3074c9c SignalHandler(int) Signals.cpp:0:0
#2 0x00007f3adafac980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
#3 0x0000557df3174bfd generateCopy(mlir::MemRefRegion const&, mlir::Block*, llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, true, false, void>, false, false>, llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, true, false, void>, false, false>, mlir::Block*, llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, true, false, void>, false, false>, llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, true, false, void>, false, false>, mlir::AffineCopyOptions, llvm::DenseMap<mlir::Value, mlir::Value, llvm::DenseMapInfo<mlir::Value, void>, llvm::detail::DenseMapPair<mlir::Value, mlir::Value>>&, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void>>&, unsigned long*, llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, true, false, void>, false, false>*, llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, true, false, void>, false, false>*) (.isra.634) LoopUtils.cpp:0:0
#4 0x0000557df3177323 mlir::affineDataCopyGenerate(llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, true, false, void>, false, false>, llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, true, false, void>, false, false>, mlir::AffineCopyOptions const&, llvm::Optional<mlir::Value>, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void>>&)::'lambda0'(llvm::SmallMapVector<mlir::Value, std::unique_ptr<mlir::MemRefRegion, std::default_delete<mlir::MemRefRegion>>, 4u> const&)::operator()(llvm::SmallMapVector<mlir::Value, std::unique_ptr<mlir::MemRefRegion, std::default_delete<mlir::MemRefRegion>>, 4u> const&) const LoopUtils.cpp:0:0
#5 0x0000557df3177ae3 mlir::affineDataCopyGenerate(llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, true, false, void>, false, false>, llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, true, false, void>, false, false>, mlir::AffineCopyOptions const&, llvm::Optional<mlir::Value>, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void>>&) (/data/llvm/build/bin/mlir-opt+0x284ae3)
#6 0x0000557df3115be2 (anonymous namespace)::AffineDataCopyGeneration::runOnBlock(mlir::Block*, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void>>&) AffineDataCopyGeneration.cpp:0:0
#7 0x0000557df3116753 (anonymous namespace)::AffineDataCopyGeneration::runOnOperation() AffineDataCopyGeneration.cpp:0:0
#8 0x0000557df44fac69 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/llvm/build/bin/mlir-opt+0x1607c69)
#9 0x0000557df44fafb0 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/llvm/build/bin/mlir-opt+0x1607fb0)
#10 0x0000557df44fb2d0 mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::'lambda'(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&)::operator()(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&) const Pass.cpp:0:0
#11 0x0000557df44fa195 mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (/data/llvm/build/bin/mlir-opt+0x1607195)
#12 0x0000557df44fabca mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/llvm/build/bin/mlir-opt+0x1607bca)
#13 0x0000557df44fba09 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (.constprop.485) Pass.cpp:0:0
#14 0x0000557df44fbfbd mlir::PassManager::run(mlir::Operation*) (/data/llvm/build/bin/mlir-opt+0x1608fbd)
#15 0x0000557df44edcdb performActions(llvm::raw_ostream&, bool, bool, llvm::SourceMgr&, mlir::MLIRContext*, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, bool, bool) (.constprop.193) MlirOptMain.cpp:0:0
#16 0x0000557df44ee402 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, bool, bool, bool, bool, bool, bool, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, llvm::ThreadPool*) MlirOptMain.cpp:0:0
#17 0x0000557df44ee73f mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool)::'lambda'(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#18 0x0000557df45b1410 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, bool, bool) (/data/llvm/build/bin/mlir-opt+0x16be410)
#19 0x0000557df44ecba6 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::PassPipelineCLParser const&, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool, bool) (/data/llvm/build/bin/mlir-opt+0x15f9ba6)
#20 0x0000557df44eeb5b mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) (/data/llvm/build/bin/mlir-opt+0x15fbb5b)
#21 0x0000557df3045210 main (/data/llvm/build/bin/mlir-opt+0x152210)
#22 0x00007f3ada28bc87 __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:344:0
#23 0x0000557df305787a _start (/data/llvm/build/bin/mlir-opt+0x16487a)
@llvm/issue-subscribers-mlir-affine
The issue is no longer reproducible on main:
mlir-opt tosa.mlir -pass-pipeline='builtin.module(func.func(tosa-to-linalg,linalg-bufferize,linalg-fold-unit-extent-dims,convert-linalg-to-affine-loops))'
module {
func.func @main(%arg0: tensor<1xi1>) {
%true = arith.constant true
%c0_i32 = arith.constant 0 : i32
%0 = bufferization.to_memref %arg0 : memref<1xi1>
%alloc = memref.alloc() {alignment = 64 : i64} : memref<i32>
affine.store %c0_i32, %alloc[] : memref<i32>
%alloc_0 = memref.alloc() {alignment = 64 : i64} : memref<i1>
affine.store %true, %alloc_0[] : memref<i1>
%alloc_1 = memref.alloc() {alignment = 64 : i64} : memref<i32>
memref.copy %alloc, %alloc_1 : memref<i32> to memref<i32>
%alloc_2 = memref.alloc() {alignment = 64 : i64} : memref<i1>
memref.copy %alloc_0, %alloc_2 : memref<i1> to memref<i1>
%collapse_shape = memref.collapse_shape %0 [] : memref<1xi1> into memref<i1>
%1 = affine.load %collapse_shape[] : memref<i1>
%2 = affine.load %alloc_1[] : memref<i32>
%3 = affine.load %alloc_2[] : memref<i1>
%4 = arith.cmpi sgt, %1, %3 : i1
%5 = arith.select %4, %1, %3 : i1
%6 = arith.select %4, %c0_i32, %2 : i32
affine.store %6, %alloc_1[] : memref<i32>
affine.store %5, %alloc_2[] : memref<i1>
return
}
}