[mlir](arith-int-range-narrowing) mlir-opt crashes at APInt.cpp:1604 with assertion `RHS.U.VAL != 0 && "Divide by zero?"' failed.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
git version: 2e87cf8c2b8ec6453ccfa7e448d5b33f1d71a2ca
MLIR Program:
```mlir
#map4 = affine_map<(d0)[s0] -> (d0 mod 0)>
#map5 = affine_map<(d0)[s0] -> (d0 floordiv 0)>
#map6 = affine_map<(d0)[s0] -> (d0 ceildiv 0)>
module {
func.func @m0() {
%c16 = arith.constant 16 : index
%10 = affine.apply #map4(%c16)[%c16]
%11 = affine.apply #map5(%c16)[%c16]
%12 = affine.apply #map6(%c16)[%c16]
%alloc = memref.alloc(%10, %11, %12) : memref
%13 = affine.load %alloc[%10, %11, %12] : memref
affine.store %13, %alloc[%10, %11, %12] : memref
return
}
}
```
Reproduce Command: `mlir-opt -arith-int-range-narrowing a.mlir`
StackTrace:
```
mlir-opt: /data2/dependency/dev/llvm-project/llvm/lib/Support/APInt.cpp:1604: llvm::APInt llvm::APInt::udiv(const llvm::APInt&) const: Assertion `RHS.U.VAL != 0 && "Divide by zero?"' 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: /data2/dependency/dev/llvm-project/build/bin/mlir-opt -arith-int-range-narrowing a.mlir
#0 0x0000563e24f401cf llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x25c71cf)
#1 0x0000563e24f3c99c llvm::sys::RunSignalHandlers() (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x25c399c)
#2 0x0000563e24f3cb37 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007f4c363b8420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#4 0x00007f4c35ea300b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
#5 0x00007f4c35e82859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
#6 0x00007f4c35e82729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
#7 0x00007f4c35e93fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#8 0x0000563e24fdfaa7 llvm::APInt::udiv(llvm::APInt const&) const (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x2666aa7)
#9 0x0000563e24fdfebe llvm::APInt::sdiv(llvm::APInt const&) const (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x2666ebe)
#10 0x0000563e24fe216b llvm::APInt::sdiv_ov(llvm::APInt const&, bool&) const (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x266916b)
#11 0x0000563e2dc00e3b inferDivSRange(mlir::ConstantIntRanges const&, mlir::ConstantIntRanges const&, llvm::function_ref (llvm::APInt const&, llvm::APInt const&, llvm::APInt const&)>) InferIntRangeCommon.cpp:0:0
#12 0x0000563e2dc08bea mlir::intrange::inferAffineExpr(mlir::AffineExpr, llvm::ArrayRef, llvm::ArrayRef) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb28fbea)
#13 0x0000563e2d9291a6 mlir::affine::AffineApplyOp::inferResultRanges(llvm::ArrayRef, llvm::function_ref) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xafb01a6)
#14 0x0000563e2d8abb41 mlir::detail::InferIntRangeInterfaceInterfaceTraits::Model::inferResultRanges(mlir::detail::InferIntRangeInterfaceInterfaceTraits::Concept const*, mlir::Operation*, llvm::ArrayRef, llvm::function_ref) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xaf32b41)
#15 0x0000563e2dfc321e mlir::intrange::detail::defaultInferResultRanges(mlir::InferIntRangeInterface, llvm::ArrayRef, llvm::function_ref) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb64a21e)
#16 0x0000563e2d8ab89c mlir::detail::InferIntRangeInterfaceInterfaceTraits::Model::inferResultRangesFromOptional(mlir::detail::InferIntRangeInterfaceInterfaceTraits::Concept const*, mlir::Operation*, llvm::ArrayRef, llvm::function_ref) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xaf3289c)
#17 0x0000563e2debcbbf mlir::dataflow::IntegerRangeAnalysis::visitOperation(mlir::Operation*, llvm::ArrayRef, llvm::ArrayRef) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb543bbf)
#18 0x0000563e2deccfbb mlir::dataflow::AbstractSparseForwardDataFlowAnalysis::visitOperation(mlir::Operation*) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb553fbb)
#19 0x0000563e2decfd5d mlir::dataflow::AbstractSparseForwardDataFlowAnalysis::initializeRecursively(mlir::Operation*) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb556d5d)
#20 0x0000563e2ded02bd mlir::dataflow::AbstractSparseForwardDataFlowAnalysis::initializeRecursively(mlir::Operation*) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb5572bd)
#21 0x0000563e2ded02bd mlir::dataflow::AbstractSparseForwardDataFlowAnalysis::initializeRecursively(mlir::Operation*) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb5572bd)
#22 0x0000563e2de5dbdc mlir::DataFlowSolver::initializeAndRun(mlir::Operation*, llvm::function_ref) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb4e4bdc)
#23 0x0000563e2c39e370 (anonymous namespace)::IntRangeNarrowingPass::runOnOperation() IntRangeOptimizations.cpp:0:0
#24 0x0000563e2dd5d5e1 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb3e45e1)
#25 0x0000563e2dd5d970 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb3e4970)
#26 0x0000563e2dd5fa24 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb3e6a24)
#27 0x0000563e2dd60ab1 mlir::PassManager::run(mlir::Operation*) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb3e7ab1)
#28 0x0000563e2500622b performActions(llvm::raw_ostream&, std::shared_ptr const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#29 0x0000563e25006cd3 processBuffer(llvm::raw_ostream&, std::unique_ptr>, llvm::MemoryBufferRef, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, mlir::SourceMgrDiagnosticVerifierHandler*, llvm::ThreadPoolInterface*) MlirOptMain.cpp:0:0
#30 0x0000563e25006f5b llvm::LogicalResult llvm::function_ref>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>::callback_fn>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::'lambda'(std::unique_ptr>, llvm::MemoryBufferRef, llvm::raw_ostream&)>(long, std::unique_ptr>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#31 0x0000563e2e138535 mlir::splitAndProcessBuffer(std::unique_ptr>, llvm::function_ref>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb7bf535)
#32 0x0000563e24ffd064 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (.part.0) MlirOptMain.cpp:0:0
#33 0x0000563e25007477 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x268e477)
#34 0x0000563e250076b3 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x268e6b3)
#35 0x0000563e24e6cb8c main (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x24f3b8c)
#36 0x00007f4c35e84083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#37 0x0000563e24f1c8de _start (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x25a38de)
Aborted (core dumped)
```
Contributor guide
Research direction
Reproduce the crash with the supplied MLIR input and `mlir-opt -arith-int-range-narrowing a.mlir`. Inspect `inferDivSRange` in `InferIntRangeCommon.cpp`, the affine range inference path, and `IntRangeOptimizations.cpp`; the work is done when this input no longer triggers the APInt divide-by-zero assertion and regression coverage is added.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100