[mlir](tosa-to-tensor) mlir-opt crashes at BuiltinAttributes.cpp:1115 with assertion `newType.getElementType() == curType.getElementType() && "expected the same element type"' failed.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
git version: 092858485f00e6786da8a88c0c4d462247e64571
MLIR Program:
```mlir
module {
func.func @fold_double_transpose(%arg0: memref<1x2x3x4x5xf32>) -> memref<5x3x2x4x1xf32, strided<[1, 20, 60, 5, 120]>> {
%transpose = memref.transpose %arg0 (d0, d1, d2, d3, d4) -> (d1, d0, d4, d3, d2) : memref<1x2x3x4x5xf32> to memref<2x1x5x4x3xf32, strided<[60, 120, 1, 5, 20]>>
%transpose_0 = memref.transpose %transpose (d0, d1, d2, d3, d4) -> (d2, d4, d0, d3, d1) : memref<2x1x5x4x3xf32, strided<[60, 120, 1, 5, 20]>> to memref<5x3x2x4x1xf32, strided<[1, 20, 60, 5, 120]>>
%0 = "tosa.const"() <{values = dense<[1, 2, 3]> : tensor<3xi8>}> : () -> tensor<3x!quant.uniform>
%1 = tosa.const_shape {values = dense<[1, 3]> : tensor<2xindex>} : () -> !tosa.shape<2>
%2 = tosa.reshape %0, %1 : (tensor<3x!quant.uniform>, !tosa.shape<2>) -> tensor<1x3x!quant.uniform>
return %transpose_0 : memref<5x3x2x4x1xf32, strided<[1, 20, 60, 5, 120]>>
}
}
```
Reproduce Command: `mlir-opt -tosa-to-tensor a.mlir`
StackTrace:
```
mlir-opt: /data2/dependency/dev/llvm-project/mlir/lib/IR/BuiltinAttributes.cpp:1115: mlir::DenseElementsAttr mlir::DenseElementsAttr::reshape(mlir::ShapedType): Assertion `newType.getElementType() == curType.getElementType() && "expected the same element type"' 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 -tosa-to-tensor a.mlir
#0 0x000055db84f3c15f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x25c715f)
#1 0x000055db84f3892c llvm::sys::RunSignalHandlers() (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x25c392c)
#2 0x000055db84f38ac7 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007f3a00bfb420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#4 0x00007f3a006e600b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
#5 0x00007f3a006c5859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
#6 0x00007f3a006c5729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
#7 0x00007f3a006d6fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#8 0x000055db8e01ef2f (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb6a9f2f)
#9 0x000055db8d87290b mlir::OpFoldResult mlir::foldReshapeOp(mlir::tensor::ExpandShapeOp, llvm::ArrayRef) TensorOps.cpp:0:0
#10 0x000055db8d81380e llvm::LogicalResult llvm::detail::UniqueFunctionBase, llvm::SmallVectorImpl&>::CallImpl::Impl, mlir::OpTrait::ZeroSuccessors, mlir::OpTrait::AtLeastNOperands<1u>::Impl, mlir::OpTrait::OpInvariants, mlir::BytecodeOpInterface::Trait, mlir::OpAsmOpInterface::Trait, mlir::ConditionallySpeculatable::Trait, mlir::OpTrait::AlwaysSpeculatableImplTrait, mlir::MemoryEffectOpInterface::Trait>::getFoldHookFn()::'lambda'(mlir::Operation*, llvm::ArrayRef, llvm::SmallVectorImpl&) const>(void*, mlir::Operation*, llvm::ArrayRef, llvm::SmallVectorImpl&) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xae9e80e)
#11 0x000055db8d821bd6 mlir::RegisteredOperationName::Model::foldHook(mlir::Operation*, llvm::ArrayRef, llvm::SmallVectorImpl&) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xaeacbd6)
#12 0x000055db8e0d77e4 mlir::Operation::fold(llvm::ArrayRef, llvm::SmallVectorImpl&) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb7627e4)
#13 0x000055db8e0d7b10 mlir::Operation::fold(llvm::SmallVectorImpl&) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb762b10)
#14 0x000055db8e00943a mlir::OpBuilder::tryFold(mlir::Operation*, llvm::SmallVectorImpl&, llvm::SmallVectorImpl*) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb69443a)
#15 0x000055db897c4eb3 (anonymous namespace)::ReshapeConverter::matchAndRewrite(mlir::tosa::ReshapeOp, mlir::tosa::ReshapeOpAdaptor, mlir::ConversionPatternRewriter&) const TosaToTensor.cpp:0:0
#16 0x000055db897b60b7 llvm::LogicalResult mlir::ConversionPattern::dispatchTo1To1, mlir::tosa::ReshapeOp>(mlir::OpConversionPattern const&, mlir::tosa::ReshapeOp, mlir::tosa::ReshapeOp::GenericAdaptor>, mlir::ConversionPatternRewriter&) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x6e410b7)
#17 0x000055db897b6209 mlir::OpConversionPattern::matchAndRewrite(mlir::Operation*, llvm::ArrayRef, mlir::ConversionPatternRewriter&) const (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x6e41209)
#18 0x000055db8dca1078 mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb32c078)
#19 0x000055db8dce7cc2 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref, llvm::function_ref, llvm::function_ref)::'lambda'()::operator()() const PatternApplicator.cpp:0:0
#20 0x000055db8dce91b8 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref, llvm::function_ref, llvm::function_ref) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb3741b8)
#21 0x000055db8dc9bd0b (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*) DialectConversion.cpp:0:0
#22 0x000055db8dc9c206 mlir::OperationConverter::convert(mlir::Operation*, bool) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb327206)
#23 0x000055db8dca713a mlir::OperationConverter::applyConversion(llvm::ArrayRef) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb33213a)
#24 0x000055db8dca8a18 applyConversion(llvm::ArrayRef, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig, (anonymous namespace)::OpConversionMode) DialectConversion.cpp:0:0
#25 0x000055db8dca8bf6 mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb333bf6)
#26 0x000055db897bd8b6 (anonymous namespace)::TosaToTensor::runOnOperation() TosaToTensorPass.cpp:0:0
#27 0x000055db8dd53e11 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb3dee11)
#28 0x000055db8dd541a0 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+0xb3df1a0)
#29 0x000055db8dd56254 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb3e1254)
#30 0x000055db8dd572e1 mlir::PassManager::run(mlir::Operation*) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0xb3e22e1)
#31 0x000055db850021bb performActions(llvm::raw_ostream&, std::shared_ptr const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#32 0x000055db85002c63 processBuffer(llvm::raw_ostream&, std::unique_ptr>, llvm::MemoryBufferRef, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, mlir::SourceMgrDiagnosticVerifierHandler*, llvm::ThreadPoolInterface*) MlirOptMain.cpp:0:0
#33 0x000055db85002eeb 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
#34 0x000055db8e12ed65 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+0xb7b9d65)
#35 0x000055db84ff8ff4 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (.part.0) MlirOptMain.cpp:0:0
#36 0x000055db85003407 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x268e407)
#37 0x000055db85003643 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x268e643)
#38 0x000055db84e68b1c main (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x24f3b1c)
#39 0x00007f3a006c7083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#40 0x000055db84f1886e _start (/data2/dependency/dev/llvm-project/build/bin/mlir-opt+0x25a386e)
Aborted (core dumped)
```
Contributor guide
Research direction
Reproduce the crash with `mlir-opt -tosa-to-tensor a.mlir` using the MLIR program in the report. Start in `TosaToTensor.cpp` at `ReshapeConverter::matchAndRewrite`, then inspect `TensorOps.cpp` at `foldReshapeOp` and the `DenseElementsAttr::reshape` assertion in `BuiltinAttributes.cpp`. Done means the reproducer no longer aborts and the regression is covered by an appropriate test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 50/100