<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64408>64408</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
--convert-linalg-to-affine-loops crashed with assertion failure "RHS constant has to be positive"
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
anonymousMCS
</td>
</tr>
</table>
<pre>
git version: fe5370dd50e48f827aaee9f5fa80e751b1759a25
system: `Ubuntu 20.04.6 LTS (Focal Fossa)`
reproduced with:
`mlir-opt --convert-linalg-to-affine-loops a.mlir`
a.mlir:
```
#map7 = affine_map<() -> (0)>
#map8 = affine_map<(d0)[s0] -> (d0 * s0)>
#map9 = affine_map<() -> (15)>
#map10 = affine_map<(d0)[s0] -> (d0 mod s0)>
#map11 = affine_map<(d0)[s0] -> (d0 floordiv s0)>
module {
func.func nested @func2(%arg0: tensor<?x?xf32>, %arg1: i32) {
%cst_0 = arith.constant dense<1.82040346E+9> : vector<f32>
%c0 = arith.constant 0 : index
%idx0 = index.constant 0
%cst_20 = arith.constant 0x4BDF80DE : f32
%false = arith.constant false
%c3 = arith.constant 3 : index
%c31 = arith.constant 31 : index
%alloc_26 = memref.alloc(%c3) : memref<?xi32>
%1 = memref.alloca_scope -> (memref<?x17xf32>) {
%alloc_35 = memref.alloc(%c0, %c0) : memref<?x?xf32>
%alloc_36 = memref.alloc(%c0) : memref<?xf32>
%18 = scf.if %false -> (f32) {
%19 = affine.load %alloc_35[%c31, %c31] : memref<?x?xf32>
%alloc_39 = memref.alloc(%idx0, %idx0) : memref<?x?x15xf32>
%20 = affine.apply #map7()
%21 = affine.apply #map7()
%22 = affine.apply #map8(%20)[%21]
%23 = affine.apply #map9()
%24 = affine.apply #map8(%22)[%23]
affine.for %arg2 = 0 to %24 {
%25 = affine.apply #map10(%arg2)[%23]
%26 = affine.apply #map11(%arg2)[%23]
%27 = affine.apply #map10(%26)[%21]
%28 = affine.apply #map11(%26)[%21]
%29 = affine.load %alloc_35[%28, %27] : memref<?x?xf32>
affine.store %29, %alloc_39[%28, %27, %25] : memref<?x?x15xf32>
}
scf.yield %19 : f32
} else {
vector.transfer_write %cst_0, %alloc_36[%idx0] : vector<f32>, memref<?xf32>
scf.yield %cst_20 : f32
}
%alloc_37 = memref.alloc(%idx0) : memref<?x17xf32>
memref.alloca_scope.return %alloc_37 : memref<?x17xf32>
}
%2 = bufferization.to_tensor %alloc_26 : memref<?xi32>
return
}
}
```
trace:
```
mlir-opt: /data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/mlir/lib/IR/AffineExpr.cpp:1328: void mlir::SimpleAffineExprFlattener::visitDivExpr(mlir::AffineBinaryOpExpr, bool): Assertion `rhsConst > 0 && "RHS constant has to be positive"' 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/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt --convert-linalg-to-affine-loops a.mlir
#0 0x0000564b880796ff llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x14096ff)
#1 0x0000564b88076984 SignalHandler(int) Signals.cpp:0:0
#2 0x00007f3d6fa9d420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#3 0x00007f3d6f53a00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
#4 0x00007f3d6f519859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
#5 0x00007f3d6f519729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
#6 0x00007f3d6f52afd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#7 0x0000564b8a983e83 (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x3d13e83)
#8 0x0000564b8a987f38 mlir::simplifyAffineExpr(mlir::AffineExpr, unsigned int, unsigned int) (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x3d17f38)
#9 0x0000564b8a98f56f mlir::simplifyAffineMap(mlir::AffineMap) (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x3d1f56f)
#10 0x0000564b88167ba8 composeAffineMapAndOperands(mlir::AffineMap*, llvm::SmallVectorImpl<mlir::Value>*) (.part.0) AffineOps.cpp:0:0
#11 0x0000564b88168c95 (anonymous namespace)::SimplifyAffineOp<mlir::affine::AffineApplyOp>::matchAndRewrite(mlir::affine::AffineApplyOp, mlir::PatternRewriter&) const AffineOps.cpp:0:0
#12 0x0000564b8d4ec1e8 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/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x687c1e8)
#13 0x0000564b8a9434d7 (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#14 0x0000564b8a94771b mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x3cd771b)
#15 0x0000564b88b818bc void (anonymous namespace)::lowerLinalgToLoopsImpl<mlir::affine::AffineForOp>(mlir::Operation*) Loops.cpp:0:0
#16 0x0000564b8a8a413e mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x3c3413e)
#17 0x0000564b8a8a461a mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x3c3461a)
#18 0x0000564b8a8a4e21 mlir::PassManager::run(mlir::Operation*) (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x3c34e21)
#19 0x0000564b8a8952cb performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#20 0x0000564b8a896784 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
#21 0x0000564b8a896934 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
#22 0x0000564b8a97cff4 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/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x3d0cff4)
#23 0x0000564b8a88fd57 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x3c1fd57)
#24 0x0000564b8a896c5b mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x3c26c5b)
#25 0x0000564b87fb47db main (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x13447db)
#26 0x00007f3d6f51b083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#27 0x0000564b8804b29e _start (/data/chenyaosuo/exp/newest-llvm-reproduce/llvm-project/build/bin/mlir-opt+0x13db29e)
Aborted (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWltz27gV_jX0C8YaEOD1wQ_yRd3MxBNPnG4fNSABSmhAgAVAx95f3wFISSRFRfZ2q912JnYkEuc75zsH50LQxBi-kYzdBPFtEN9fkdZulb4hUsm3WrXm8e75qlD07WbDLXhh2nAlA7wEFYtxCimNIYuyKkMpIYzlVVyRDLI0DoswjXOC4gDeB3DZ_TZvxrLaSQcJ_HvRStsCBBcwWiTg87dnEKBspUoiwEoZQwKUBwkcymvWaEXbklHwg9ttgPvrQQJrwfW1aiy4vi6VfGHaXgsuidhcW3VNqopLdi2UagwgC7d2gtxfHAD2_7qvCNekSUGA70GHta5JE-C7AGUBysF1gB-c8dCZjB-GQtmsEPUr41sDg_h-L04hCNASmBmY_KzuMD6WCuHHtNeKzmoPw4_hVEIpTfnLBKxWtBUMBOlt9x1UrSwX7heQzFhGQRBB9xV5bjHRG-g2i2XSKO104tWr-6kwcqDoDnSrQreKY-T8cUAHwN0ujV33btDcbhelksYSaQFl0rAA34WLDMEI4ih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