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] -tosa-to-arith crashes #118268

Open
Emilyaxe opened this issue Dec 2, 2024 · 3 comments · May be fixed by #128682
Open

[mlir] -tosa-to-arith crashes #118268

Emilyaxe opened this issue Dec 2, 2024 · 3 comments · May be fixed by #128682
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] mlir:tosa

Comments

@Emilyaxe
Copy link

Emilyaxe commented Dec 2, 2024

git version: 0a44b24

system: Ubuntu 18.04.6 LTS

reproduce with: mlir-opt -tosa-to-arith" a.mlir

-remove-dead-values also will trigger this crash.

a.mlir:

module {
  func.func @main() {
    %1 = "tosa.const"() <{value = dense<0> : tensor<1x24x2xi32>}> : () -> tensor<1x24x2xi32>
    %4 = "tosa.const"() <{value = dense<20> : tensor<1x24x2xi32>}> : () -> tensor<1x24x2xi32>
    %16 = tosa.int_div %4, %1 : (tensor<1x24x2xi32>, tensor<1x24x2xi32>) -> tensor<1x24x2xi32>
    return
  }
}

stack trace:

mlir-opt: /data/szy/MLIR/llvm-release/llvm-project/llvm/lib/Support/APInt.cpp:1552: 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.
Stack dump:
0.      Program arguments: /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt a.mlir -tosa-to-arith
 #0 0x0000561baebecf88 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1185f88)
 #1 0x0000561baebeaa9e llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1183a9e)
 #2 0x0000561baebed91d SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f4ba3f4d420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f4ba358a00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007f4ba3569859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
 #6 0x00007f4ba3569729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
 #7 0x00007f4ba3569729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
 #8 0x00007f4ba357afd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #9 0x0000561baec6b548 llvm::APInt::udiv(llvm::APInt const&) const (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1204548)
#10 0x0000561baec6cc2f llvm::APInt::sdiv(llvm::APInt const&) const (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1205c2f)
#11 0x0000561bb1222ab7 mlir::tosa::IntDivOp::fold(mlir::tosa::IntDivOpGenericAdaptor<llvm::ArrayRef<mlir::Attribute>>) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x37bbab7)
#12 0x0000561bb11d5ec1 llvm::LogicalResult mlir::Op<mlir::tosa::IntDivOp, mlir::OpTrait::ZeroRegions, mlir::OpTrait::OneResult, mlir::OpTrait::OneTypedResult<mlir::TensorType>::Impl, mlir::OpTrait::ZeroSuccessors, mlir::OpTrait::NOperands<2u>::Impl, mlir::OpTrait::OpInvariants, mlir::OpTrait::SameOperandsAndResultElementType, mlir::InferShapedTypeOpInterface::Trait, mlir::OpTrait::ResultsBroadcastableShape, mlir::OpTrait::tosa::TosaElementwiseOperator, mlir::ConditionallySpeculatable::Trait, mlir::OpTrait::AlwaysSpeculatableImplTrait, mlir::MemoryEffectOpInterface::Trait, mlir::tosa::TosaOp::Trait>::foldSingleResultHook<mlir::tosa::IntDivOp>(mlir::Operation*, llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x376eec1)
#13 0x0000561bb11d5260 mlir::RegisteredOperationName::Model<mlir::tosa::IntDivOp>::foldHook(mlir::Operation*, llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x376e260)
#14 0x0000561bb21cc93d mlir::Operation::fold(llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x476593d)
#15 0x0000561bb21ccce3 mlir::Operation::fold(llvm::SmallVectorImpl<mlir::OpFoldResult>&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4765ce3)
#16 0x0000561bb210d06a mlir::OpBuilder::tryFold(mlir::Operation*, llvm::SmallVectorImpl<mlir::Value>&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x46a606a)
#17 0x0000561bb208706c (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) DialectConversion.cpp:0:0
#18 0x0000561bb2086437 mlir::OperationConverter::convert(mlir::ConversionPatternRewriter&, mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x461f437)
#19 0x0000561bb208760f mlir::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x462060f)
#20 0x0000561bb208d7cb mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x46267cb)
#21 0x0000561bb19a57f9 (anonymous namespace)::TosaToArith::runOnOperation() TosaToArithPass.cpp:0:0
#22 0x0000561bb2027316 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x45c0316)
#23 0x0000561bb2027c40 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+0x45c0c40)
#24 0x0000561bb202a212 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x45c3212)
#25 0x0000561bb2022aba performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#26 0x0000561bb202270d 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
#27 0x0000561bb20ce985 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+0x4667985)
#28 0x0000561bb201c6f5 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+0x45b56f5)
#29 0x0000561bb201c99f mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x45b599f)
#30 0x0000561bb201ccce mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x45b5cce)
#31 0x0000561baebcda77 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1166a77)
#32 0x00007f4ba356b083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#33 0x0000561baebcd5ee _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11665ee)
@github-actions github-actions bot added the mlir label Dec 2, 2024
@EugeneZelenko EugeneZelenko added crash Prefer [crash-on-valid] or [crash-on-invalid] mlir:tosa and removed mlir labels Dec 2, 2024
@CoTinker
Copy link
Contributor

CoTinker commented Dec 23, 2024

Do we need to verify the division-by-zero scenario? @eric-k256 @GeorgeARM

@GeorgeARM
Copy link
Contributor

Hey @CoTinker just saw this.
Think we can add something to the verifier itself in case it is a constant tensor. But in general, in the operator specification it is a requirement for the denominator to be non-zero.

@lhutton1 can you have a look.

lhutton1 added a commit to lhutton1/llvm-project that referenced this issue Feb 25, 2025
Fixes llvm#118268.

Change-Id: Ib3eeed6e796a573b30f04a992f4213862f0e0eb6
Signed-off-by: Luke Hutton <[email protected]>
@lhutton1
Copy link
Contributor

Thanks for reporting @Emilyaxe, apologies for only just getting round to taking a look. I've just pushed a patch to fix this #128682

lhutton1 added a commit to lhutton1/llvm-project that referenced this issue Feb 25, 2025
Fixes llvm#118268.

Change-Id: Ib3eeed6e796a573b30f04a992f4213862f0e0eb6
Signed-off-by: Luke Hutton <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] mlir:tosa
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants