<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64288>64288</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir] `AllocaScopeOpLowering::matchAndRewrite` crashed with assertion failure "cast<Ty>() argument of incompatible type!"
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Colloportus0
</td>
</tr>
</table>
<pre>
MLIR built at commit b4c54b20
Reproduced with:
`mlir-opt --generate-runtime-verification --vp-counters-per-site=1 "--gpu-to-llvm=use-bare-pointers-for-host use-bare-pointers-for-kernels" temp.mlir`
temp.mlir:
``` milr
module {
func.func private @func2(%arg0: tensor<8x32xi32>, %arg1: vector<8x32xi1>, %arg2: vector<32x16xf16>) -> memref<32x16xf32> {
%c1 = arith.constant 1 : index
%c6 = arith.constant 6 : index
%9 = tensor.empty(%c1, %c6) : tensor<?x?xi64>
%alloc = memref.alloc() : memref<8x32xi64>
%alloc_6 = memref.alloc(%c6) : memref<?x16xi1>
%alloc_16 = memref.alloc(%c6) : memref<?xi1>
%true_22 = index.bool.constant true
%72 = scf.while (%arg3 = %9) : (tensor<?x?xi64>) -> tensor<?x?xi64> {
%147 = tensor.empty(%c1, %c6) : tensor<?x?xi64>
scf.condition(%true_22) %147 : tensor<?x?xi64>
} do {
^bb0(%arg3: tensor<?x?xi64>):
%139 = memref.alloca_scope -> (index) {
%cast_35 = memref.cast %alloc : memref<8x32xi64> to memref<?x?xi64>
%168 = memref.realloc %alloc_16 : memref<?xi1> to memref<19xi1>
%c0_40 = arith.constant 0 : index
memref.alloca_scope.return %c0_40 : index
}
%155 = tensor.empty(%c1, %c6) : tensor<?x?xi64>
scf.yield %155 : tensor<?x?xi64>
}
%alloc_32 = memref.alloc() : memref<32x16xf32>
return %alloc_32 : memref<32x16xf32>
}
}
```
trace:
```console
Assertion failed: (isa<To>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file Casting.h, line 578.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: mlir-opt --generate-runtime-verification --vp-counters-per-site=1 "--gpu-to-llvm=use-bare-pointers-for-host use-bare-pointers-for-kernels" temp.mlir
#0 0x0000000100ab8548 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/workspace/build/bin/mlir-opt+0x1002f8548)
#1 0x0000000100ab67e4 llvm::sys::RunSignalHandlers() (/workspace/build/bin/mlir-opt+0x1002f67e4)
#2 0x0000000100ab8bf4 SignalHandler(int) (/workspace/build/bin/mlir-opt+0x1002f8bf4)
#3 0x00000001a46cd4c4 (/usr/lib/system/libsystem_platform.dylib+0x1803414c4)
#4 0x00000001a46b5ee0 (/usr/lib/system/libsystem_pthread.dylib+0x180329ee0)
#5 0x00000001a45f0340 (/usr/lib/system/libsystem_c.dylib+0x180264340)
#6 0x00000001a45ef754 (/usr/lib/system/libsystem_c.dylib+0x180263754)
#7 0x0000000104f5ee7c (anonymous namespace)::AllocaScopeOpLowering::matchAndRewrite(mlir::memref::AllocaScopeOp, mlir::memref::AllocaScopeOpAdaptor, mlir::ConversionPatternRewriter&) const (.cold.2) (/workspace/build/bin/mlir-opt+0x10479ee7c)
#8 0x0000000102a93d78 mlir::LLVM::StackSaveOp mlir::OpBuilder::create<mlir::LLVM::StackSaveOp, mlir::Type>(mlir::Location, mlir::Type&&) (/workspace/build/bin/mlir-opt+0x1022d3d78)
#9 0x0000000102a9384c mlir::ConvertOpToLLVMPattern<mlir::memref::AllocaScopeOp>::matchAndRewrite(mlir::Operation*, llvm::ArrayRef<mlir::Value>, mlir::ConversionPatternRewriter&) const (/workspace/build/bin/mlir-opt+0x1022d384c)
#10 0x0000000103186e44 mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const (/workspace/build/bin/mlir-opt+0x1029c6e44)
#11 0x000000010475bb74 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&)>)::$_2::operator()() const (/workspace/build/bin/mlir-opt+0x103f9bb74)
#12 0x0000000104758e70 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&)>) (/workspace/build/bin/mlir-opt+0x103f98e70)
#13 0x00000001031928a8 (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) (/workspace/build/bin/mlir-opt+0x1029d28a8)
#14 0x0000000103194378 mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>::callback_fn<(anonymous namespace)::OperationLegalizer::legalizeWithPattern(mlir::Operation*, mlir::ConversionPatternRewriter&)::$_20>(long, mlir::Pattern const&) (/workspace/build/bin/mlir-opt+0x1029d4378)
#15 0x000000010475b928 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&)>)::$_2::operator()() const (/workspace/build/bin/mlir-opt+0x103f9b928)
#16 0x0000000104758e70 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&)>) (/workspace/build/bin/mlir-opt+0x103f98e70)
#17 0x00000001031928a8 (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) (/workspace/build/bin/mlir-opt+0x1029d28a8)
#18 0x000000010318adac (anonymous namespace)::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>, llvm::function_ref<void (mlir::Diagnostic&)>) (/workspace/build/bin/mlir-opt+0x1029cadac)
#19 0x000000010318cf00 mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget&, mlir::FrozenRewritePatternSet const&, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void>>*) (/workspace/build/bin/mlir-opt+0x1029ccf00)
#20 0x00000001029bf020 (anonymous namespace)::GpuToLLVMConversionPass::runOnOperation() (/workspace/build/bin/mlir-opt+0x1021ff020)
#21 0x0000000103141e34 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/workspace/build/bin/mlir-opt+0x102981e34)
#22 0x0000000103142524 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/workspace/build/bin/mlir-opt+0x102982524)
#23 0x00000001031443bc mlir::PassManager::run(mlir::Operation*) (/workspace/build/bin/mlir-opt+0x1029843bc)
#24 0x000000010313c808 performActions(llvm::raw_ostream&, std::__1::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) (/workspace/build/bin/mlir-opt+0x10297c808)
#25 0x000000010313bd30 mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_1>(long, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) (/workspace/build/bin/mlir-opt+0x10297bd30)
#26 0x00000001031babe0 mlir::splitAndProcessBuffer(std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, bool, bool) (/workspace/build/bin/mlir-opt+0x1029fabe0)
#27 0x00000001031366e4 mlir::MlirOptMain(llvm::raw_ostream&, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/workspace/build/bin/mlir-opt+0x1029766e4)
#28 0x0000000103136b54 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/workspace/build/bin/mlir-opt+0x102976b54)
#29 0x00000001007c358c main (/workspace/build/bin/mlir-opt+0x10000358c)
#30 0x000000010c0e1088
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWktv4zgS_jXKhbBBUQ9Lhxzceew2kCBB0pg9GpRUsrlNkVqSSuL59QtSsi3azsudXcwMpjETyyJZVd9XL1IW1ZotBcB5kHwLkssz2pmVVOcXknPZSmU6jc8KWa3Pb2--P6CiY9wgalApm4YZhIq4TOKC4ABfBnj-AK2SVVdChZ6ZWQXRHKF-JEhxw5mayNagyWQJAhQ1MFGdMKyByRMoVrOSGiYFmkye2kkpO2FA6UkLaqKZgSC6DFFAyGSybLuJkRPOn5oguuw0TAqqYNJK1q-opZqspDbo-NBPUAK4DghBBpp2au0K0gFB_3d3P5pv7e__Qw3jagDVyKrjgILZt-EGQnUnyqn9g1rFnqgBFMTYficByQKSULXElhYDQksVRBfZS0ReWESC6CogF6ifEtopT1Ca0ZTQm0G8GRF5CdOXOkzdnBxNgugKNdAoqHejToc1dmMrsrLKEAXRJaKKmdW0lEIbKgyyN-eIiQpe_Nnpsdnpbjbypududo91Ck1r1j0LZTggKVNrrkdIEF2_2P9Z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