<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60558>60558</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir] Canonicalize Pass crashed when invoking StaticTensorGenerate::matchAndRewrite on a negative index value.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Colloportus0
</td>
</tr>
</table>
<pre>
MLIR built at commit https://github.com/llvm/llvm-project/commit/cad708b9
Reproduced with:
` mlir-opt --canonicalize temp.mlir`
temp.mlir:
``` milr
module {
func.func @func1(%arg0: tensor<4x11xi32>, %arg1: memref<10x12xi1>, %arg2: tensor<4xi1>) {
%c0 = arith.constant 0 : index
%alloc_264 = memref.alloc() : memref<4xi32>
%alloc_390 = memref.alloc() : memref<10x12xf32>
%alloc_803 = memref.alloc() : memref<10xi1>
%84 = affine.load %alloc_803[%c0] : memref<10xi1>
%85 = tensor.empty() : tensor<10x12xi32>
%99 = affine.load %alloc_264[%c0] : memref<4xi32>
%111 = affine.max affine_map<(d0) -> (d0 mod 64 - 8)>(%c0)
%cst_830 = arith.constant 1.000000e+00 : f32
%167 = affine.if affine_set<(d0, d1) : ((d1 ceildiv 32) floordiv 128 == 0, d1 floordiv 16 >= 0, d1 * 2 == 0)>(%c0, %c0) -> i1 {
%generated_848 = tensor.generate %111 {
^bb0(%arg3: index, %arg4: index):
affine.store %cst_830, %alloc_390[%c0, %c0] : memref<10x12xf32>
tensor.yield %99 : i32
} : tensor<?x12xi32>
affine.yield %84 : i1
}
return
}
}
```
Here the value of `%111` is -8, then it crashed with following err:
trace:
```console
Assertion failed: (succeeded(ConcreteT::verify(getDefaultDiagnosticEmitFn(ctx), args...))), function get, file StorageUniquerSupport.h, line 174.
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 --canonicalize temp.mlir
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 mlir-opt 0x0000000102feddd8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 mlir-opt 0x0000000102fece40 llvm::sys::RunSignalHandlers() + 112
2 mlir-opt 0x0000000102fee470 SignalHandler(int) + 344
3 libsystem_platform.dylib 0x00000001b4cd14c4 _sigtramp + 56
4 libsystem_pthread.dylib 0x00000001b4cb9ee0 pthread_kill + 288
5 libsystem_c.dylib 0x00000001b4bf4340 abort + 168
6 libsystem_c.dylib 0x00000001b4bf3754 err + 0
7 mlir-opt 0x0000000104e1ce94 mlir::detail::skipDefaultMemorySpace(mlir::Attribute) (.cold.1) + 0
8 mlir-opt 0x000000010477efb4 mlir::RankedTensorType::getShape() const + 0
9 mlir-opt 0x000000010477eec8 mlir::RankedTensorType::get(llvm::ArrayRef<long long>, mlir::Type, mlir::Attribute) + 64
10 mlir-opt 0x0000000103f251c8 (anonymous namespace)::StaticTensorGenerate::matchAndRewrite(mlir::tensor::GenerateOp, mlir::PatternRewriter&) const + 1072
11 mlir-opt 0x00000001049509a0 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&)>) + 1420
12 mlir-opt 0x00000001046ff214 (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() + 2432
13 mlir-opt 0x00000001046fc86c mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig) + 1516
14 mlir-opt 0x00000001046c3520 (anonymous namespace)::Canonicalizer::runOnOperation() + 156
15 mlir-opt 0x00000001046ae194 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) + 428
16 mlir-opt 0x00000001046ae6c4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) + 320
17 mlir-opt 0x00000001046b0034 mlir::PassManager::run(mlir::Operation*) + 1148
18 mlir-opt 0x00000001046a9404 performActions(llvm::raw_ostream&, bool, bool, std::__1::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, bool, bool) + 476
19 mlir-opt 0x00000001046a8ff0 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>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool)::$_0>(long, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) + 704
20 mlir-opt 0x0000000104713544 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) + 656
21 mlir-opt 0x00000001046a7418 mlir::MlirOptMain(llvm::raw_ostream&, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool) + 216
22 mlir-opt 0x00000001046a790c mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) + 1208
23 mlir-opt 0x0000000102e8d8a0 main + 108
24 dyld 0x0000000108139088 start + 516
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWVtv67gR_jXKCxGDoi6WH_LgOMnuARIkSE5btC8GJY1kNhSpklROvL--ICnJUmJvvJeHRdEgsCVxOPpm-M2FNNWa1QLgKkiug-TmgnZmJ9XVRnIuW6lMp_FFLsv91cP9t2eUd4wbRA0qZNMwg3bGtDqI1gG5C8hdzcyuyxeFbAJyx_nb8HXZKvlvKExA7vw8e0HLJc7yVYBvArx-hlbJsiugRD-Y2QXRGvmBIMWo4Uxdytagy8uCCilYQTn7BZCBpl3YwSDFvbT7PDyP1qMW_48axlWvupFlxwEFy2t_j1DViWJhP1AQY_sdBiQLSEJVjS0kA0JLFUSb-D0M31lEgug2IBvkRUIr0kCjoAqiTYjfQ_LOwpkI-aClH15NQSArW2AURDeIKmZ2i0IKbagwyD5cIyZKeJ9JU85lsSVp7CZ5CAv30OFfoRmyeED-WUW0wmep8MZVp9RkODpXjffAVEXmraBVxQQsuKTlTLGlqfVPkNz8qjKrKXGavL8X0LRmP0ExLkO_Up-NWa1OIyFpfBLJUQeHYTjV1tD3_nLb0DaINgHJSmyxXQbRLXJ3qJElSmN0iSxox5TMv5Gs5mzRZptFRykTLrD7g4BcY88fu2yjj8J0OYXFqgGVBnNAtUFlOPjNgcjKEBXAeMneUETsUMWlVPY2JJnVaJX2MydjKbJmTIYCskZkIj83c4MGe71bWDiPFGd9DQIUNVBuszibrvgwMLr_w9TkNs_xGOHRIbbGeI0nz1ZjNhmcpY1UMPH_MG8IpZEgox1HOPsxjnrsewa8HEm4RmxcNI99eTMncRDdHWMxGrCO-lx4rRELJwxa3hxuFJhOCTQ8GMcOF_OMOn34MyhAZgfojfIOkKyQFXDOt7mXaXSZWWeYHQjEDCoU1bs-5aPKVpwfTNQIlJoUAJ_SFS3gczq3NJccUC-71hqUYVKgijIOZU9X3RUFQAllQLKNFIUCA9-tsm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