llvm / llvm-project

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

[mlir] [affine] -affine-loop-unroll crashes in T llvm::divideCeilSigned(U, V) [U = long, V = long, T = long]: Assertion `Denominator && "Division by zero"' failed. #107812

Open axeabc opened 1 week ago

axeabc commented 1 week ago

git version: 0f5033053a3d4

system: Ubuntu 18.04.6 LTS

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

a.mlir:

  func.func @test_vectorize_unpack_no_masks(%source : memref<8xf16>, %dest: memref<8x16xf16>) {
      affine.for %arg1 = 0 to 8 step 4 {
        affine.for %arg2 = 0 to 8 step 0 {
          %0 = affine.load %source[%arg2] : memref<8xf16>
          %1 = affine.load %source[%arg2] : memref<8xf16>
          %2 = arith.addf %0, %1 : f16
          affine.store %2, %dest[%arg1, %arg2] : memref<8x16xf16>
        }
      }
    return
  }

stack trace:

mlir-opt: /data/szy/MLIR/llvm-release/llvm-project/llvm/include/llvm/Support/MathExtras.h:427: T llvm::divideCeilSigned(U, V) [U = long, V = long, T = long]: Assertion `Denominator && "Division by zero"' 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-unroll a.mlir
 #0 0x000055a73171eff8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10d3ff8)
 #1 0x000055a73171cb0e llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10d1b0e)
 #2 0x000055a73171f98d SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f7f3e466420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f7f3daa300b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007f7f3da82859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
 #6 0x00007f7f3da82729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
 #7 0x00007f7f3da82729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
 #8 0x00007f7f3da93fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #9 0x000055a7347ab4fc (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41604fc)
#10 0x000055a7347ab53f mlir::affine::getConstantTripCount(mlir::affine::AffineForOp) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x416053f)
#11 0x000055a731864205 mlir::affine::loopUnrollByFactor(mlir::affine::AffineForOp, unsigned long, llvm::function_ref<void (unsigned int, mlir::Operation*, mlir::OpBuilder)>, bool) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1219205)
#12 0x000055a73183bae3 (anonymous namespace)::LoopUnroll::runOnOperation() LoopUnroll.cpp:0:0
#13 0x000055a73480be26 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41c0e26)
#14 0x000055a73480c790 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+0x41c1790)
#15 0x000055a734811b4e mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_0::operator()(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&) const Pass.cpp:0:0
#16 0x000055a73480de6b mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41c2e6b)
#17 0x000055a73480bf78 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41c0f78)
#18 0x000055a73480c790 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+0x41c1790)
#19 0x000055a73480edd2 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41c3dd2)
#20 0x000055a734807601 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#21 0x000055a73480725b 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
#22 0x000055a7348b3ef5 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+0x4268ef5)
#23 0x000055a734802685 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+0x41b7685)
#24 0x000055a73480292f mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41b792f)
#25 0x000055a734802c5e mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41b7c5e)
#26 0x000055a7316ffc37 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10b4c37)
#27 0x00007f7f3da84083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#28 0x000055a7316ff7be _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10b47be)
CoTinker commented 1 week ago

affine.for with zero step is invalid, it's similar to #103703. Can we report an error when the step is zero to prevent crashes? @joker-eph