Skip to content

[MLIR][Tensor] --linalg-fold-unit-extent-dims crashes with assertion failure "invalid index for shaped type" in FoldEmptyTensorWithDimOp. #111270

@tju-chenyaosuo

Description

@tju-chenyaosuo

git version: eaff3a7

command to reproduce: mlir-opt --linalg-fold-unit-extent-dims a.mlir

a.mlir:

func.func @func1() -> index {
  %3 = tensor.empty() : tensor<19x15x1xf16>
  %idx10 = index.constant 10
  %dim_162 = tensor.dim %3, %idx10 : tensor<19x15x1xf16>  // index out-of-bounds
  return %dim_162 : index
}

stack trace:

mlir-opt: /data2/src/llvm-project/build/tools/mlir/include/mlir/IR/BuiltinTypeInterfaces.h.inc:242: bool mlir::detail::ShapedTypeTrait<ConcreteType>::isDynamicDim(unsigned int) const [with ConcreteType = mlir::RankedTensorType]: Assertion `idx < getRank() && "invalid index for shaped type"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /data2/src/llvm-project/build/bin/mlir-opt --linalg-fold-unit-extent-dims a.mlir
 #0 0x0000557113fa73cf llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data2/src/llvm-project/build/bin/mlir-opt+0x15853cf)
 #1 0x0000557113fa4434 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007fc8af79e420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007fc8af26b00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007fc8af24a859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x00007fc8af24a729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #6 0x00007fc8af25bfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #7 0x00005571144f3c8d (/data2/src/llvm-project/build/bin/mlir-opt+0x1ad1c8d)
 #8 0x000055711614677d (anonymous namespace)::FoldEmptyTensorWithDimOp::matchAndRewrite(mlir::tensor::DimOp, mlir::PatternRewriter&) const TensorOps.cpp:0:0
 #9 0x00005571144ebe2f mlir::detail::OpOrInterfaceRewritePatternBase<mlir::tensor::DimOp>::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const (/data2/src/llvm-project/build/bin/mlir-opt+0x1ac9e2f)
#10 0x000055711a470f10 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>) (/data2/src/llvm-project/build/bin/mlir-opt+0x7a4ef10)
#11 0x00005571172e2e08 (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#12 0x00005571172e5c5b mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/data2/src/llvm-project/build/bin/mlir-opt+0x48c3c5b)
#13 0x0000557114cfbf9c (anonymous namespace)::LinalgFoldUnitExtentDimsPass::runOnOperation() DropUnitDims.cpp:0:0
#14 0x000055711722f351 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data2/src/llvm-project/build/bin/mlir-opt+0x480d351)
#15 0x000055711722f82a mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data2/src/llvm-project/build/bin/mlir-opt+0x480d82a)
#16 0x0000557117230374 mlir::PassManager::run(mlir::Operation*) (/data2/src/llvm-project/build/bin/mlir-opt+0x480e374)
#17 0x000055711722187b performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#18 0x0000557117222244 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
#19 0x00005571172223f4 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&)::'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
#20 0x0000557117329e3e 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) (/data2/src/llvm-project/build/bin/mlir-opt+0x4907e3e)
#21 0x0000557117219c99 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data2/src/llvm-project/build/bin/mlir-opt+0x47f7c99)
#22 0x0000557117222561 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data2/src/llvm-project/build/bin/mlir-opt+0x4800561)
#23 0x0000557117222a26 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data2/src/llvm-project/build/bin/mlir-opt+0x4800a26)
#24 0x0000557113ebeaab main (/data2/src/llvm-project/build/bin/mlir-opt+0x149caab)
#25 0x00007fc8af24c083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#26 0x0000557113f7a5be _start (/data2/src/llvm-project/build/bin/mlir-opt+0x15585be)
Aborted (core dumped)

Metadata

Metadata

Assignees

Labels

crashPrefer [crash-on-valid] or [crash-on-invalid]good first issuehttps://github.com/llvm/llvm-project/contributemlir:tensor

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions