<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/74227>74227</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir] --sparsification crashed with assertion failure.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
anonymousMCS
</td>
</tr>
</table>
<pre>
git version: e9c6f3f5e7e23b23de4eeaa182ebfcb7d2188495
system: ```Ubuntu 20.04.6 LTS (Focal Fossa)```
reproduced with: ```mlir-opt --sparsification a.mlir```
a.mlir:
```
func.func private @func2() {
%false = arith.constant false
// Though this line is not used, the crash will disappear if delete this line.
%c2105432605_i64 = arith.constant 2105432605 : i64
%false_7 = arith.constant false
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%c4 = arith.constant 4 : index
%c7 = arith.constant 7 : index
%c8 = arith.constant 8 : index
%c11 = arith.constant 11 : index
%c12 = arith.constant 12 : index
%c21 = arith.constant 21 : index
%c27 = arith.constant 27 : index
%alloc_22 = memref.alloc(%c21) {alignment = 64 : i64} : memref<?x5xf32>
%14 = bufferization.to_tensor %alloc_22 : memref<?x5xf32>
%alloc_34 = memref.alloc() : memref<20x5x5xi1>
%16 = index.shrs %c1, %c27
%c0_i32 = arith.constant 0 : i32
%23 = arith.ceildivsi %false, %false_7 : i1
%28 = index.maxu %16, %c4
%40 = index.maxs %c7, %c12
%c2105432605_i64_55 = arith.constant 2105432605 : i64
%57 = index.add %c11, %c0
%c1_68 = arith.constant 1 : index
%71 = index.shru %28, %c8
%alloc_72 = memref.alloc() {alignment = 64 : i64} : memref<20x5x5xi1>
%72 = bufferization.to_tensor %alloc_72 : memref<20x5x5xi1>
%76 = index.add %c1_68, %71
%alloc_75 = memref.alloc() {alignment = 64 : i64} : memref<20x5x5xi1>
%c20_77 = arith.constant 20 : index
%c5_79 = arith.constant 5 : index
%c5_81 = arith.constant 5 : index
%77 = arith.index_cast %c0_i32 : i32 to index
%subview = memref.subview %alloc_75[%57, %77, %c0] [%40, %c1, %c5_81] [%c1, %c1, %c1] : memref<20x5x5xi1> to memref<?x?x?xi1, strided<[?, ?, ?], offset: ?>>
%78 = scf.for %arg0 = %c0 to %c20_77 step %40 iter_args(%arg1 = %72) -> (tensor<20x5x5xi1>) {
%119 = scf.for %arg2 = %c0 to %c5_79 step %c1 iter_args(%arg3 = %arg1) -> (tensor<20x5x5xi1>) {
%subview_102 = memref.subview %alloc_75[%arg0, %arg2, %c0] [%16, %57, %c5_81] [%76, %c1, %c1] : memref<20x5x5xi1> to memref<?x?x?xi1, strided<[?, ?, ?], offset: ?>>
%alloc_103 = memref.alloc() {alignment = 64 : i64} : memref<20x5x5xi1>
memref.copy %subview_102, %subview : memref<?x?x?xi1, strided<[?, ?, ?], offset: ?>> to memref<?x?x?xi1, strided<[?, ?, ?], offset: ?>>
%122 = bufferization.to_tensor %alloc_103 : memref<20x5x5xi1>
scf.yield %122 : tensor<20x5x5xi1>
}
scf.yield %119 : tensor<20x5x5xi1>
}
vector.warp_execute_on_lane_0(%c1_68)[32] {
%mapped_108 = linalg.map ins(%78, %alloc_34, %78 : tensor<20x5x5xi1>, memref<20x5x5xi1>, tensor<20x5x5xi1>) outs(%78 : tensor<20x5x5xi1>)
(%in: i1, %in_109: i1, %in_110: i1) {
%alloc_119 = memref.alloc() {alignment = 64 : i64} : memref<13x26x13xi64>
memref.store %c2105432605_i64_55, %alloc_119[%c21, %c1, %c12] : memref<13x26x13xi64>
linalg.yield %23 : i1
}
}
return
}
```
trace:
```
mlir-opt: /data/bin/llvm-project/llvm/include/llvm/ADT/SmallVector.h:294: T& llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::operator[](llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::size_type) [with T = mlir::Value; <template-parameter-1-2> = void; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::reference = mlir::Value&; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::size_type = long unsigned int]: Assertion `idx < size()' 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/bin/llvm-project/build/bin/mlir-opt --sparsification a.mlir
#0 0x00005577cebbee8f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/bin/llvm-project/build/bin/mlir-opt+0x1640e8f)
#1 0x00005577cebbbee4 SignalHandler(int) Signals.cpp:0:0
#2 0x00007f914fc4d420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#3 0x00007f914f73800b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
#4 0x00007f914f717859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
#5 0x00007f914f717729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
#6 0x00007f914f728fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#7 0x00005577d0240b58 (/data/bin/llvm-project/build/bin/mlir-opt+0x2cc2b58)
#8 0x00005577d1a4db8a mlir::RewriterBase::replaceOpWithIf(mlir::Operation*, mlir::ValueRange, bool*, llvm::unique_function<bool (mlir::OpOperand&) const>) (/data/bin/llvm-project/build/bin/mlir-opt+0x44cfb8a)
#9 0x00005577d027fe09 (anonymous namespace)::LastTensorLoadCanonicalization::matchAndRewrite(mlir::scf::ForOp, mlir::PatternRewriter&) const SCF.cpp:0:0
#10 0x00005577d4573038 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>) (/data/bin/llvm-project/build/bin/mlir-opt+0x6ff5038)
#11 0x00005577d18e81cc (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#12 0x00005577d18ec63b mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/data/bin/llvm-project/build/bin/mlir-opt+0x436e63b)
#13 0x00005577d044a7ba mlir::applyPatternsAndFoldGreedily(mlir::Operation*, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (.constprop.0) SparseTensorPasses.cpp:0:0
#14 0x00005577d044f108 (anonymous namespace)::SparsificationPass::runOnOperation() SparseTensorPasses.cpp:0:0
#15 0x00005577d183285e mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/bin/llvm-project/build/bin/mlir-opt+0x42b485e)
#16 0x00005577d1832d3a mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/bin/llvm-project/build/bin/mlir-opt+0x42b4d3a)
#17 0x00005577d1833564 mlir::PassManager::run(mlir::Operation*) (/data/bin/llvm-project/build/bin/mlir-opt+0x42b5564)
#18 0x00005577d18242d3 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#19 0x00005577d18257a4 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPool*) MlirOptMain.cpp:0:0
#20 0x00005577d1825954 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
#21 0x00005577d1924c44 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&, bool, bool) (/data/bin/llvm-project/build/bin/mlir-opt+0x43a6c44)
#22 0x00005577d181e1b7 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/bin/llvm-project/build/bin/mlir-opt+0x42a01b7)
#23 0x00005577d1825aa1 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/bin/llvm-project/build/bin/mlir-opt+0x42a7aa1)
#24 0x00005577d1825f06 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/bin/llvm-project/build/bin/mlir-opt+0x42a7f06)
#25 0x00005577ceaf650b main (/data/bin/llvm-project/build/bin/mlir-opt+0x157850b)
#26 0x00007f914f719083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#27 0x00005577ceb8f1ee _start (/data/bin/llvm-project/build/bin/mlir-opt+0x16111ee)
Aborted (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWl1znDrS_jX4RuUpIfF54YuxfeZ9U5VUXLH3nEtKQDOjDSOxknDG59dvScAMYMZ24uTs2U3FNgOt1tPdT7daYpjWfCsArrzw2gtvL1hrdlJdMSHF0162-tPN_UUuy6erLTfoEZTmUnh0jSAtoopWIcRAaE5oCQEAY35CIK-KPC6JnyR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