[mlir] 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: 81a8c66fdc96a7bf6927bf3f88d4b2e24a5c71e7
system: `Ubuntu 18.04.6 LTS`
reproduce with: `mlir-opt -arith-int-range-narrowing a.mlir`
a.mlir:
```mlir
#map = affine_map<() -> (12)>
#map1 = affine_map<(d0)[s0] -> (d0 * s0)>
#map2 = affine_map<(d0)[s0] -> (d0 mod s0)>
#map3 = affine_map<(d0)[s0] -> (d0 floordiv s0)>
module {
pdl_interp.func @matcher(%arg0: !pdl.operation) {
pdl_interp.finalize
}
module @rewriters {
}
func.func @test_vectorize_unsupported(%arg0: memref<8xf32>, %arg1: memref<8xf32>) {
%0 = affine.load %arg0[0] : memref<8xf32>
%1 = affine.apply #map()
%2 = affine.load %arg0[0] : memref<8xf32>
%3 = affine.apply #map1(%1)[%1]
%4 = affine.load %arg0[0] : memref<8xf32>
%5 = affine.apply #map2(%3)[%3]
%6 = affine.load %arg0[0] : memref<8xf32>
%7 = affine.apply #map3(%5)[%5]
%8 = affine.load %arg0[0] : memref<8xf32>
%9 = affine.load %arg1[0] : memref<8xf32>
return
}
}
```
stack trace:
```
mlir-opt: /data/szy/MLIR/llvm-release/llvm-project/llvm/lib/Support/APInt.cpp:1604: APInt llvm::APInt::udiv(const 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: /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt -arith-int-range-narrowing 89.mlir
#0 0x000055cdb99750c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x20360c8)
#1 0x000055cdb9971f61 llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x2032f61)
#2 0x000055cdb99761e6 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007f0ce44ed420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#4 0x00007f0ce3b2a00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
#5 0x00007f0ce3b09859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
#6 0x00007f0ce3b09729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
#7 0x00007f0ce3b09729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
#8 0x00007f0ce3b1afd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#9 0x000055cdb99ffa28 llvm::APInt::udiv(llvm::APInt const&) const (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x20c0a28)
#10 0x000055cdb9a00eb9 llvm::APInt::sdiv(llvm::APInt const&) const (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x20c1eb9)
#11 0x000055cdb9a0538e llvm::APInt::sdiv_ov(llvm::APInt const&, bool&) const (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x20c638e)
#12 0x000055cdc22547c1 std::optional llvm::function_ref (llvm::APInt const&, llvm::APInt const&)>::callback_fn (llvm::APInt const&, llvm::APInt const&, llvm::APInt const&)>)::$_0>(long, llvm::APInt const&, llvm::APInt const&) InferIntRangeCommon.cpp:0:0
#13 0x000055cdc224efe7 minMaxBy(llvm::function_ref (llvm::APInt const&, llvm::APInt const&)>, llvm::ArrayRef, llvm::ArrayRef, bool) InferIntRangeCommon.cpp:0:0
#14 0x000055cdc224f79f inferDivSRange(mlir::ConstantIntRanges const&, mlir::ConstantIntRanges const&, llvm::function_ref (llvm::APInt const&, llvm::APInt const&, llvm::APInt const&)>) InferIntRangeCommon.cpp:0:0
#15 0x000055cdc225387e mlir::intrange::inferAffineExpr(mlir::AffineExpr, llvm::ArrayRef, llvm::ArrayRef) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xa91487e)
#16 0x000055cdc1f687f7 mlir::affine::AffineApplyOp::inferResultRanges(llvm::ArrayRef, llvm::function_ref) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xa6297f7)
#17 0x000055cdc1f31731 mlir::detail::InferIntRangeInterfaceInterfaceTraits::Model::inferResultRanges(mlir::detail::InferIntRangeInterfaceInterfaceTraits::Concept const*, mlir::Operation*, llvm::ArrayRef, llvm::function_ref) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xa5f2731)
#18 0x000055cdc2574906 mlir::intrange::detail::defaultInferResultRanges(mlir::InferIntRangeInterface, llvm::ArrayRef, llvm::function_ref) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xac35906)
#19 0x000055cdc24a9ff6 mlir::dataflow::IntegerRangeAnalysis::visitOperation(mlir::Operation*, llvm::ArrayRef, llvm::ArrayRef) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xab6aff6)
#20 0x000055cdc24b3869 mlir::dataflow::AbstractSparseForwardDataFlowAnalysis::visitOperation(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xab74869)
#21 0x000055cdc24b19b5 mlir::dataflow::AbstractSparseForwardDataFlowAnalysis::initializeRecursively(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xab729b5)
#22 0x000055cdc24b277b mlir::dataflow::AbstractSparseForwardDataFlowAnalysis::initializeRecursively(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xab7377b)
#23 0x000055cdc24b277b mlir::dataflow::AbstractSparseForwardDataFlowAnalysis::initializeRecursively(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xab7377b)
#24 0x000055cdc2459edf mlir::DataFlowSolver::initializeAndRun(mlir::Operation*, llvm::function_ref) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xab1aedf)
#25 0x000055cdc09897d7 (anonymous namespace)::IntRangeNarrowingPass::runOnOperation() IntRangeOptimizations.cpp:0:0
#26 0x000055cdc235d662 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xaa1e662)
#27 0x000055cdc235e4a4 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+0xaa1f4a4)
#28 0x000055cdc23653ba mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xaa263ba)
#29 0x000055cdc2364cef mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xaa25cef)
#30 0x000055cdb9a243c0 performActions(llvm::raw_ostream&, std::shared_ptr const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#31 0x000055cdb9a235f6 llvm::LogicalResult llvm::function_ref>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>::callback_fn>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_0>(long, std::unique_ptr>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#32 0x000055cdc26b0e55 mlir::splitAndProcessBuffer(std::unique_ptr>, llvm::function_ref>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0xad71e55)
#33 0x000055cdb9a1a656 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x20db656)
#34 0x000055cdb9a1aa35 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x20dba35)
#35 0x000055cdb9a1ad95 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x20dbd95)
#36 0x000055cdb995ab52 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x201bb52)
#37 0x00007f0ce3b0b083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#38 0x000055cdb995a68e _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x201b68e)
Aborted (core dumped)
```
Contributor guide
Research direction
Reproduce the crash with mlir-opt -arith-int-range-narrowing a.mlir, then inspect InferIntRangeCommon.cpp and IntRangeOptimizations.cpp along the stack-trace path. Trace how the affine expressions in a.mlir reach signed division and add coverage for this input. Done means the reproducer no longer aborts on divide-by-zero.
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
- 45/100