<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61345>61345</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR]Crashed on '-normalize-memrefs' pass with assertion failure `other.getNumSymbols() == getNumSymbolVars() && "symbol mismatch"' '
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
BealZephyr
</td>
</tr>
</table>
<pre>
Test on commit: https://github.com/llvm/llvm-project/commit/3b4cb1e96c645bb833fe710856479c31383859bb
The same crash occurred in [llvm16](https://github.com/llvm/llvm-project/tree/release/16.x)
steps to reproduce:
```
mlir-opt -normalize-memrefs test.mlir
```
test case:
```
module {
func.func @cast_extract_slice(%arg0: tensor<128x512xf32>, %arg1: index, %arg2: index) -> tensor<16x512xf32> attributes {llvm.emit_c_interface} {
%c0 = arith.constant 0 : index
%0 = bufferization.to_memref %arg0 : memref<128x512xf32, strided<[?, ?], offset: ?>>
%subview = memref.subview %0[%arg2, 0] [%arg1, 512] [1, 1] : memref<128x512xf32, strided<[?, ?], offset: ?>> to memref<?x512xf32, strided<[?, ?], offset: ?>>
%cast = memref.cast %subview : memref<?x512xf32, strided<[?, ?], offset: ?>> to memref<16x512xf32, strided<[?, ?], offset: ?>>
%1 = bufferization.to_tensor %cast : memref<16x512xf32, strided<[?, ?], offset: ?>>
return %1 : tensor<16x512xf32>
}
}
```
crash trace:
```
mlir-opt: /home/verify/llvm-project-3b4cb1e96c645bb833fe710856479c31383859bb/mlir/lib/Dialect/Affine/Analysis/AffineStructures.cpp:465: mlir::LogicalResult mlir::FlatAffineValueConstraints::composeMatchingMap(mlir::AffineMap): Assertion `other.getNumSymbols() == getNumSymbolVars() && "symbol mismatch"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /home/verify/llvm-project-3b4cb1e96c645bb833fe710856479c31383859bb/build/bin/mlir-opt -normalize-memrefs test.mlir
#0 0x000055e1fe15bf1a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/verify/llvm-project-3b4cb1e96c645bb833fe710856479c31383859bb/build/bin/mlir-opt+0x221f1a)
#1 0x000055e1fe15941c SignalHandler(int) Signals.cpp:0:0
#2 0x00007f49986a2980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
#3 0x00007f499779ae87 raise /build/glibc-CVJwZb/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
#4 0x00007f499779c7f1 abort /build/glibc-CVJwZb/glibc-2.27/stdlib/abort.c:81:0
#5 0x00007f499778c3fa __assert_fail_base /build/glibc-CVJwZb/glibc-2.27/assert/assert.c:89:0
#6 0x00007f499778c472 (/lib/x86_64-linux-gnu/libc.so.6+0x30472)
#7 0x000055e1ff9a6cfa mlir::FlatAffineValueConstraints::composeMatchingMap(mlir::AffineMap) (/home/verify/llvm-project-3b4cb1e96c645bb833fe710856479c31383859bb/build/bin/mlir-opt+0x1a6ccfa)
#8 0x000055e1fe279eb2 mlir::normalizeMemRefType(mlir::MemRefType, unsigned int) (/home/verify/llvm-project-3b4cb1e96c645bb833fe710856479c31383859bb/build/bin/mlir-opt+0x33feb2)
#9 0x000055e1feb2cae2 (anonymous namespace)::NormalizeMemRefs::createOpResultsNormalized(mlir::func::FuncOp, mlir::Operation*) (.isra.233) NormalizeMemRefs.cpp:0:0
#10 0x000055e1feb2d30b void llvm::function_ref<void (mlir::Operation*)>::callback_fn<(anonymous namespace)::NormalizeMemRefs::normalizeFuncOpMemRefs(mlir::func::FuncOp, mlir::ModuleOp)::'lambda1'(mlir::Operation*)>(long, mlir::Operation*) NormalizeMemRefs.cpp:0:0
#11 0x000055e1feb31c5d (anonymous namespace)::NormalizeMemRefs::normalizeFuncOpMemRefs(mlir::func::FuncOp, mlir::ModuleOp) NormalizeMemRefs.cpp:0:0
#12 0x000055e1feb3359d (anonymous namespace)::NormalizeMemRefs::runOnOperation() NormalizeMemRefs.cpp:0:0
#13 0x000055e1ffa13759 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/home/verify/llvm-project-3b4cb1e96c645bb833fe710856479c31383859bb/build/bin/mlir-opt+0x1ad9759)
#14 0x000055e1ffa145b3 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (.constprop.495) Pass.cpp:0:0
#15 0x000055e1ffa14c9d mlir::PassManager::run(mlir::Operation*) (/home/verify/llvm-project-3b4cb1e96c645bb833fe710856479c31383859bb/build/bin/mlir-opt+0x1adac9d)
#16 0x000055e1ffa07ca3 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#17 0x000055e1ffa083d9 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
#18 0x000055e1ffa08701 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
#19 0x000055e1ffacd380 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) (/home/verify/llvm-project-3b4cb1e96c645bb833fe710856479c31383859bb/build/bin/mlir-opt+0x1b93380)
#20 0x000055e1ffa053e3 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/home/verify/llvm-project-3b4cb1e96c645bb833fe710856479c31383859bb/build/bin/mlir-opt+0x1acb3e3)
#21 0x000055e1ffa08ae8 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) (/home/verify/llvm-project-3b4cb1e96c645bb833fe710856479c31383859bb/build/bin/mlir-opt+0x1aceae8)
#22 0x000055e1fe128330 main (/home/verify/llvm-project-3b4cb1e96c645bb833fe710856479c31383859bb/build/bin/mlir-opt+0x1ee330)
#23 0x00007f499777dc87 __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:344:0
#24 0x000055e1fe13afca _start (/home/verify/llvm-project-3b4cb1e96c645bb833fe710856479c31383859bb/build/bin/mlir-opt+0x200fca)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWltv2zgW_jXMCxFBInV9yIPjxNhZNJOgKfowLwJFHdnckUgtSbXx_PoFKV8kN2ndbprpLpDE5vWc7zsXHlFhxoi1BLhCyTVKbi7YYDdKX10Da_-AfrPVF5Wqt1covEHh4gMYi5XEXHWdsIgu8Mba3iC6QGSFyGot7GaoAq46RFZt-2n_cdlr9S_gFpHVbilZ0SrmVQRFytM4qaqc0gayKMyTNM4KTiOa0zwpqmoneQPYsA4w18xssOJ80BpqLCRGybWTEaUouUEk_26NrAZAZKWhBWbctygN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