<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/118757>118757</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir] -linalg-fold-unit-extent-dims crashes
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wwy6191
</td>
</tr>
</table>
<pre>
git version: adf892d743d91afc1af7893f97c770db31c26916
system: `Ubuntu 18.04.6 LTS`
reproduce with: `mlir-opt -linalg-fold-unit-extent-dims a.mlir`
a.mlir:
```
module {
pdl_interp.func @matcher(%arg0:!pdl.operation) {
pdl_interp.finalize
}
module @rewriters {
}
func.func @test_reshape_3_3_sparse(%arg0: tensor<3x?xf32>) -> tensor<?x?xf32> {
%c0 = arith.constant 0 : index
%c3 = arith.constant 3 : index
%c4 = arith.constant 4 : index
%collapsed = tensor.collapse_shape %arg0 [[0, 1]] : tensor<3x?xf32> into tensor<?xf32>
%c0_0 = arith.constant 0 : index
%dim = tensor.dim %collapsed, %c0_0 : tensor<?xf32>
%c3_1 = arith.constant 3 : index
%dim_2 = tensor.dim %collapsed, %c3_1 : tensor<?xf32>
%c1 = arith.constant 1 : index
%expanded = tensor.expand_shape %collapsed [[0, 1]] output_shape [%dim, %dim_2] : tensor<?xf32> into tensor<?x?xf32>
return %expanded : tensor<?x?xf32>
}
}
```
stack trace:
```
mlir-opt: /data/szy/MLIR/llvm-release/llvm-project/build/tools/mlir/include/mlir/IR/BuiltinTypeInterfaces.h.inc:242: bool mlir::detail::ShapedTypeTrait<mlir::RankedTensorType>::isDynamicDim(unsigned int) const [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: /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt -linalg-fold-unit-extent-dims /data/szy/MLIR/seed/seed0/tmp.I5Q4qvqwct.mlir
#0 0x0000555c3beec048 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1188048)
#1 0x0000555c3bee9b5e llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1185b5e)
#2 0x0000555c3beec9dd SignalHandler(int) Signals.cpp:0:0
#3 0x00007f389e96e420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#4 0x00007f389dfab00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
#5 0x00007f389df8a859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
#6 0x00007f389df8a729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
#7 0x00007f389df8a729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
#8 0x00007f389df9bfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#9 0x0000555c3c414d9b mlir::detail::ShapedTypeTrait<mlir::RankedTensorType>::isDynamicDim(unsigned int) const (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x16b0d9b)
#10 0x0000555c3e3d56eb (anonymous namespace)::FoldDimOfCollapseShape::matchAndRewrite(mlir::tensor::DimOp, mlir::PatternRewriter&) const TensorOps.cpp:0:0
#11 0x0000555c41e4c851 void llvm::function_ref<void ()>::callback_fn<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&)>)::$_0>(long) PatternApplicator.cpp:0:0
#12 0x0000555c41e4951b 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&)>) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x70e551b)
#13 0x0000555c3f3a2eef (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#14 0x0000555c3f39f87f mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x463b87f)
#15 0x0000555c3cd452a1 (anonymous namespace)::LinalgFoldUnitExtentDimsPass::runOnOperation() DropUnitDims.cpp:0:0
#16 0x0000555c3f3287a6 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x45c47a6)
#17 0x0000555c3f3290d0 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+0x45c50d0)
#18 0x0000555c3f32b6a2 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x45c76a2)
#19 0x0000555c3f323f4a performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#20 0x0000555c3f323b9d 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
#21 0x0000555c3f3cfd75 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+0x466bd75)
#22 0x0000555c3f31db85 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+0x45b9b85)
#23 0x0000555c3f31de2f mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x45b9e2f)
#24 0x0000555c3f31e15e mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x45ba15e)
#25 0x0000555c3beccb37 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1168b37)
#26 0x00007f389df8c083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#27 0x0000555c3becc6ae _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11686ae)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWltz2zjS_TXwC8oqEuD1wQ-0FX1fqpKy187UPrJAAJSwgQAOADrS_PotgNSFsnyZyWimdmtTSSwRje5z-jQaIGlir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