Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mlir] Crash when using --arith-unsigned-when-equivalent #94423

Closed
wangyongj1a opened this issue Jun 5, 2024 · 0 comments · Fixed by #96429
Closed

[mlir] Crash when using --arith-unsigned-when-equivalent #94423

wangyongj1a opened this issue Jun 5, 2024 · 0 comments · Fixed by #96429
Assignees
Labels

Comments

@wangyongj1a
Copy link

I have the following MLIR program:
test.mlir:

func.func @func1() {
  %c1 = arith.constant 1 : index
  %127 = scf.for %arg0 = %c1 to %c1 step %c1 iter_args(%arg1 = %c1) -> (index) {
    %138 = index.floordivs %arg0, %arg0
    scf.yield %c1 : index
  }
  return
}

The above MLIR program will cause a crash when using the following command:

mlir-opt --arith-unsigned-when-equivalent test.mlir

And the crash backtrace is:

mlir-opt: /data/tmp/v0605/llvm-project/llvm/lib/Support/APInt.cpp:1548: 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.
Stack dump:
0.	Program arguments: /data/tmp/v0605/llvm-project/build/bin/mlir-opt --arith-unsigned-when-equivalent test.mlir
 #0 0x000055c890751cef llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x14b6cef)
 #1 0x000055c89074ed44 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f94ec05e420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f94ebb2b00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007f94ebb0a859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x00007f94ebb0a729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #6 0x00007f94ebb1bfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #7 0x000055c8907e1151 llvm::APInt::udiv(llvm::APInt const&) const (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x1546151)
 #8 0x000055c8907e159e llvm::APInt::sdiv(llvm::APInt const&) const (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x154659e)
 #9 0x000055c8907e36eb llvm::APInt::sdiv_ov(llvm::APInt const&, bool&) const (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x15486eb)
#10 0x000055c895be3049 std::optional<llvm::APInt> llvm::function_ref<std::optional<llvm::APInt> (llvm::APInt const&, llvm::APInt const&)>::callback_fn<inferDivSRange(mlir::ConstantIntRanges const&, mlir::ConstantIntRanges const&, llvm::function_ref<std::optional<llvm::APInt> (llvm::APInt const&, llvm::APInt const&, llvm::APInt const&)>)::'lambda'(llvm::APInt const&, llvm::APInt const&)>(long, llvm::APInt const&, llvm::APInt const&) InferIntRangeCommon.cpp:0:0
#11 0x000055c895be54e4 minMaxBy(llvm::function_ref<std::optional<llvm::APInt> (llvm::APInt const&, llvm::APInt const&)>, llvm::ArrayRef<llvm::APInt>, llvm::ArrayRef<llvm::APInt>, bool) (.constprop.1) InferIntRangeCommon.cpp:0:0
#12 0x000055c895be5880 inferDivSRange(mlir::ConstantIntRanges const&, mlir::ConstantIntRanges const&, llvm::function_ref<std::optional<llvm::APInt> (llvm::APInt const&, llvm::APInt const&, llvm::APInt const&)>) InferIntRangeCommon.cpp:0:0
#13 0x000055c895be8008 mlir::intrange::inferFloorDivS(llvm::ArrayRef<mlir::ConstantIntRanges>) (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x694d008)
#14 0x000055c890fd1c7a std::_Function_handler<mlir::ConstantIntRanges (llvm::ArrayRef<mlir::ConstantIntRanges>), mlir::ConstantIntRanges (*)(llvm::ArrayRef<mlir::ConstantIntRanges>)>::_M_invoke(std::_Any_data const&, llvm::ArrayRef<mlir::ConstantIntRanges>&&) (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x1d36c7a)
#15 0x000055c895bea8ae mlir::intrange::inferIndexOp(std::function<mlir::ConstantIntRanges (llvm::ArrayRef<mlir::ConstantIntRanges>)> const&, llvm::ArrayRef<mlir::ConstantIntRanges>, mlir::intrange::CmpMode) (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x694f8ae)
#16 0x000055c890fd2efb mlir::index::FloorDivSOp::inferResultRanges(llvm::ArrayRef<mlir::ConstantIntRanges>, llvm::function_ref<void (mlir::Value, mlir::ConstantIntRanges const&)>) (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x1d37efb)
#17 0x000055c890fbf37a mlir::detail::InferIntRangeInterfaceInterfaceTraits::Model<mlir::index::FloorDivSOp>::inferResultRanges(mlir::detail::InferIntRangeInterfaceInterfaceTraits::Concept const*, mlir::Operation*, llvm::ArrayRef<mlir::ConstantIntRanges>, llvm::function_ref<void (mlir::Value, mlir::ConstantIntRanges const&)>) (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x1d2437a)
#18 0x000055c89689285e mlir::intrange::detail::defaultInferResultRanges(mlir::InferIntRangeInterface, llvm::ArrayRef<mlir::IntegerValueRange>, llvm::function_ref<void (mlir::Value, mlir::IntegerValueRange const&)>) (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x75f785e)
#19 0x000055c8936dc283 mlir::dataflow::IntegerRangeAnalysis::visitOperation(mlir::Operation*, llvm::ArrayRef<mlir::dataflow::IntegerValueRangeLattice const*>, llvm::ArrayRef<mlir::dataflow::IntegerValueRangeLattice*>) (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x4441283)
#20 0x000055c8936e64ce mlir::dataflow::AbstractSparseForwardDataFlowAnalysis::visitOperation(mlir::Operation*) (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x444b4ce)
#21 0x000055c8936e699b mlir::dataflow::AbstractSparseForwardDataFlowAnalysis::visit(mlir::ProgramPoint) (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x444b99b)
#22 0x000055c8936902fd mlir::DataFlowSolver::initializeAndRun(mlir::Operation*) (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x43f52fd)
#23 0x000055c890a94cce (anonymous namespace)::ArithUnsignedWhenEquivalentPass::runOnOperation() UnsignedWhenEquivalent.cpp:0:0
#24 0x000055c8937026f1 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x44676f1)
#25 0x000055c893702bda mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x4467bda)
#26 0x000055c893703394 mlir::PassManager::run(mlir::Operation*) (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x4468394)
#27 0x000055c8936f481b performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#28 0x000055c8936f51d4 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPoolInterface*) MlirOptMain.cpp:0:0
#29 0x000055c8936f5384 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>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::'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
#30 0x000055c8937fdcfe 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&, llvm::StringRef, llvm::StringRef) (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x4562cfe)
#31 0x000055c8936ecf84 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x4451f84)
#32 0x000055c8936f54dc mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x445a4dc)
#33 0x000055c8936f59a6 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x445a9a6)
#34 0x000055c89066c8cb main (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x13d18cb)
#35 0x00007f94ebb0c083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#36 0x000055c890720ffe _start (/data/tmp/v0605/llvm-project/build/bin/mlir-opt+0x1485ffe)

My git version is dd82fd4.

@github-actions github-actions bot added the mlir label Jun 5, 2024
@ubfx ubfx self-assigned this Jun 22, 2024
ubfx added a commit that referenced this issue Jun 24, 2024
When lower bound and exclusive upper bound of a loop are the same, and
the zero-trip loop is not canonicalized away before the analysis, this
leads to a meaningless range for the induction variable being inferred.
This patch adds a check to make sure that the inferred range for the IV
is meaningful before updating the analysis state.

Fix #94423
AlexisPerry pushed a commit to llvm-project-tlp/llvm-project that referenced this issue Jul 9, 2024
When lower bound and exclusive upper bound of a loop are the same, and
the zero-trip loop is not canonicalized away before the analysis, this
leads to a meaningless range for the induction variable being inferred.
This patch adds a check to make sure that the inferred range for the IV
is meaningful before updating the analysis state.

Fix llvm#94423
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants