llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.01k stars 11.96k forks source link

[mlir][affine] -affine-loop-fusion crashes in AffineOps.cpp:2402: void mlir::affine::AffineForOp::setLowerBound(ValueRange, AffineMap): Assertion `map.getNumResults() >= 1 && "bound map has at least one result"' failed. #108374

Open axeabc opened 1 month ago

axeabc commented 1 month ago

git version: 8168088f0a9015b

system: Ubuntu 18.04.6 LTS

reproduce with: mlir-opt -affine-loop-fusion a.mlir

a.mlir:

#map = affine_map<(d0) -> (d0)>
#map1 = affine_map<(d0) -> (d0 + 1)>
module {
  func.func @test_add_slice_bounds() {
    %alloc = memref.alloc() : memref<10xf32>
    %cst = arith.constant 0.619152 : f32
    affine.for %arg0 = 0 to 10 {
      affine.for %arg1 = #map(%arg0) to #map1(%arg0) {
        affine.store %cst, %alloc[%arg1] : memref<10xf32>
      }
    }
    affine.for %arg0 = 0 to 3 {
      affine.for %arg1 = 0 to 10 {
        affine.for %arg2 = #map(%arg0) to #map1(%arg0) {
          affine.for %arg3 = #map(%arg1) to #map1(%arg1) {
            %0 = affine.apply #map1(%arg3)
            %1 = affine.load %alloc[%0] : memref<10xf32>
          }
        }
      }
    }
    return
  }
}

stack trace:

mlir-opt: /data/szy/MLIR/llvm-release/llvm-project/mlir/lib/Dialect/Affine/IR/AffineOps.cpp:2402: void mlir::affine::AffineForOp::setLowerBound(ValueRange, AffineMap): Assertion `map.getNumResults() >= 1 && "bound map has at least one result"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  Program arguments: /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt -affine-loop-fusion a.mlir
 #0 0x000055725a2b72c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10dc2c8)
 #1 0x000055725a2b4dde llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10d9dde)
 #2 0x000055725a2b7c5d SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f456da40420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f456d07d00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007f456d05c859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
 #6 0x00007f456d05c729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
 #7 0x00007f456d05c729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
 #8 0x00007f456d06dfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #9 0x000055725a3568df (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x117b8df)
#10 0x000055725a3f2396 mlir::affine::fuseLoops(mlir::affine::AffineForOp, mlir::affine::AffineForOp, mlir::affine::ComputationSliceState const&, bool) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1217396)
#11 0x000055725a3c7d9e (anonymous namespace)::GreedyFusion::performFusionsIntoDest(unsigned int, unsigned int) LoopFusion.cpp:0:0
#12 0x000055725a3c5b35 (anonymous namespace)::GreedyFusion::fuseProducerConsumerNodes(unsigned int) LoopFusion.cpp:0:0
#13 0x000055725a3c55c9 void llvm::function_ref<void (mlir::Operation*)>::callback_fn<(anonymous namespace)::LoopFusion::runOnOperation()::$_0>(long, mlir::Operation*) LoopFusion.cpp:0:0
#14 0x000055725a3bb84e void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11e084e)
#15 0x000055725a3c2b2d (anonymous namespace)::LoopFusion::runOnOperation() LoopFusion.cpp:0:0
#16 0x000055725d3de156 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4203156)
#17 0x000055725d3deac0 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4203ac0)
#18 0x000055725d3e1102 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4206102)
#19 0x000055725d3d9931 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#20 0x000055725d3d958b llvm::LogicalResult llvm::function_ref<llvm::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>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#21 0x000055725d485f25 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::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x42aaf25)
#22 0x000055725d3d49b5 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41f99b5)
#23 0x000055725d3d4c5f mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41f9c5f)
#24 0x000055725d3d4f8e mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41f9f8e)
#25 0x000055725a297f07 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10bcf07)
#26 0x00007f456d05e083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#27 0x000055725a297a8e _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10bca8e)
llvmbot commented 1 month ago

@llvm/issue-subscribers-mlir-affine

Author: None (axeabc)

git version: 8168088f0a9015b system: `Ubuntu 18.04.6 LTS` reproduce with: `mlir-opt -affine-loop-fusion a.mlir` a.mlir: ``` #map = affine_map<(d0) -> (d0)> #map1 = affine_map<(d0) -> (d0 + 1)> module { func.func @test_add_slice_bounds() { %alloc = memref.alloc() : memref<10xf32> %cst = arith.constant 0.619152 : f32 affine.for %arg0 = 0 to 10 { affine.for %arg1 = #map(%arg0) to #map1(%arg0) { affine.store %cst, %alloc[%arg1] : memref<10xf32> } } affine.for %arg0 = 0 to 3 { affine.for %arg1 = 0 to 10 { affine.for %arg2 = #map(%arg0) to #map1(%arg0) { affine.for %arg3 = #map(%arg1) to #map1(%arg1) { %0 = affine.apply #map1(%arg3) %1 = affine.load %alloc[%0] : memref<10xf32> } } } } return } } ``` stack trace: ``` mlir-opt: /data/szy/MLIR/llvm-release/llvm-project/mlir/lib/Dialect/Affine/IR/AffineOps.cpp:2402: void mlir::affine::AffineForOp::setLowerBound(ValueRange, AffineMap): Assertion `map.getNumResults() >= 1 && "bound map has at least one result"' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt -affine-loop-fusion a.mlir #0 0x000055725a2b72c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10dc2c8) #1 0x000055725a2b4dde llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10d9dde) #2 0x000055725a2b7c5d SignalHandler(int) Signals.cpp:0:0 #3 0x00007f456da40420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420) #4 0x00007f456d07d00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1 #5 0x00007f456d05c859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7 #6 0x00007f456d05c729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8 #7 0x00007f456d05c729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34 #8 0x00007f456d06dfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6) #9 0x000055725a3568df (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x117b8df) #10 0x000055725a3f2396 mlir::affine::fuseLoops(mlir::affine::AffineForOp, mlir::affine::AffineForOp, mlir::affine::ComputationSliceState const&, bool) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1217396) #11 0x000055725a3c7d9e (anonymous namespace)::GreedyFusion::performFusionsIntoDest(unsigned int, unsigned int) LoopFusion.cpp:0:0 #12 0x000055725a3c5b35 (anonymous namespace)::GreedyFusion::fuseProducerConsumerNodes(unsigned int) LoopFusion.cpp:0:0 #13 0x000055725a3c55c9 void llvm::function_ref<void (mlir::Operation*)>::callback_fn<(anonymous namespace)::LoopFusion::runOnOperation()::$_0>(long, mlir::Operation*) LoopFusion.cpp:0:0 #14 0x000055725a3bb84e void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11e084e) #15 0x000055725a3c2b2d (anonymous namespace)::LoopFusion::runOnOperation() LoopFusion.cpp:0:0 #16 0x000055725d3de156 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4203156) #17 0x000055725d3deac0 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4203ac0) #18 0x000055725d3e1102 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4206102) #19 0x000055725d3d9931 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0 #20 0x000055725d3d958b llvm::LogicalResult llvm::function_ref<llvm::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>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0 #21 0x000055725d485f25 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::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x42aaf25) #22 0x000055725d3d49b5 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41f99b5) #23 0x000055725d3d4c5f mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41f9c5f) #24 0x000055725d3d4f8e mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41f9f8e) #25 0x000055725a297f07 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10bcf07) #26 0x00007f456d05e083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3 #27 0x000055725a297a8e _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10bca8e) ```