<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64622>64622</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir][linalg] --linalg-fuse-elementwise-ops crashed with assertion failure "rhs >= 1"
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wangzhiyingh
</td>
</tr>
</table>
<pre>
git version: c7b537bf0923df05254f9fa4722b298eb8f4790d
system: `Ubuntu 20.04.6 LTS (Focal Fossa)`
reproduced with:`mlir-opt --linalg-fuse-elementwise-ops a.mlir`
a.mlir:
```
#map = affine_map<(d0)[s0] -> (d0 mod s0)>
#map1 = affine_map<(d0)[s0] -> (d0 floordiv s0)>
#set = affine_set<() : (-1 >= 0, -88 >= 0, 0 >= 0, 39 >= 0)>
module {
func.func @func1(%arg0: f32, %arg1: memref<32xf16>) {
%c32 = arith.constant 32 : index
%idx0 = index.constant 0
%c0 = arith.constant 0 : index
%alloc = memref.alloc() : memref<26x26x1xi16>
%alloc_20 = memref.alloc(%idx0, %idx0) : memref<?x?x32xi1>
%9 = affine.if #set() -> memref<26x26x1xi16> {
affine.yield %alloc : memref<26x26x1xi16>
} else {
%22 = index.divu %idx0, %idx0
%23 = index.maxs %22, %22
%alloc_23 = memref.alloc(%23, %23) : memref<?x?x32x32xi1>
affine.for %arg2 = 0 to 0 {
%24 = affine.apply #map(%arg2)[%c32]
%25 = affine.apply #map1(%arg2)[%c32]
%26 = affine.apply #map(%25)[%c32]
%27 = affine.apply #map1(%25)[%c32]
%28 = affine.apply #map(%27)[%c0]
%29 = affine.apply #map1(%27)[%c0]
%30 = affine.load %alloc_20[%29, %28, %26] : memref<?x?x32xi1>
affine.store %30, %alloc_23[%29, %28, %26, %24] : memref<?x?x32x32xi1>
}
affine.yield %alloc : memref<26x26x1xi16>
}
return
}
}
```
trace:
```
mlir-opt: /data/bin/llvm-project/mlir/include/mlir/Support/MathExtras.h:46: int64_t mlir::mod(int64_t, int64_t): Assertion `rhs >= 1' 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 --linalg-fuse-elementwise-ops bug1.mlir
#0 0x0000555b65f26a2f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/bin/llvm-project/build/bin/mlir-opt+0x14a8a2f)
#1 0x0000555b65f23cb4 SignalHandler(int) Signals.cpp:0:0
#2 0x00007f4c9cd90420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#3 0x00007f4c9c87b00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
#4 0x00007f4c9c85a859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
#5 0x00007f4c9c85a729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
#6 0x00007f4c9c86bfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#7 0x0000555b688e1732 mlir::AffineMap::partialConstantFold(llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<long>*) const (/data/bin/llvm-project/build/bin/mlir-opt+0x3e63732)
#8 0x0000555b688e186b mlir::AffineMap::constantFold(llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::Attribute>&) const (/data/bin/llvm-project/build/bin/mlir-opt+0x3e6386b)
#9 0x0000555b65fee362 mlir::affine::AffineApplyOp::fold(mlir::affine::AffineApplyOpGenericAdaptor<llvm::ArrayRef<mlir::Attribute>>) (/data/bin/llvm-project/build/bin/mlir-opt+0x1570362)
#10 0x0000555b65fee4dd mlir::LogicalResult llvm::detail::UniqueFunctionBase<mlir::LogicalResult, mlir::Operation*, llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&>::CallImpl<mlir::Op<mlir::affine::AffineApplyOp, mlir::OpTrait::ZeroRegions, mlir::OpTrait::OneResult, mlir::OpTrait::OneTypedResult<mlir::IndexType>::Impl, mlir::OpTrait::ZeroSuccessors, mlir::OpTrait::VariadicOperands, mlir::OpTrait::OpInvariants, mlir::BytecodeOpInterface::Trait, mlir::ConditionallySpeculatable::Trait, mlir::OpTrait::AlwaysSpeculatableImplTrait, mlir::MemoryEffectOpInterface::Trait>::getFoldHookFn()::'lambda'(mlir::Operation*, llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) const>(void*, mlir::Operation*, llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (/data/bin/llvm-project/build/bin/mlir-opt+0x15704dd)
#11 0x0000555b66022996 mlir::RegisteredOperationName::Model<mlir::affine::AffineApplyOp>::foldHook(mlir::Operation*, llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (/data/bin/llvm-project/build/bin/mlir-opt+0x15a4996)
#12 0x0000555b689ef1e2 mlir::Operation::fold(llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (/data/bin/llvm-project/build/bin/mlir-opt+0x3f711e2)
#13 0x0000555b689ef520 mlir::Operation::fold(llvm::SmallVectorImpl<mlir::OpFoldResult>&) (/data/bin/llvm-project/build/bin/mlir-opt+0x3f71520)
#14 0x0000555b688941b2 mlir::OperationFolder::tryToFold(mlir::Operation*, bool*) (/data/bin/llvm-project/build/bin/mlir-opt+0x3e161b2)
#15 0x0000555b68897788 (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#16 0x0000555b6889bb4b mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/data/bin/llvm-project/build/bin/mlir-opt+0x3e1db4b)
#17 0x0000555b66a27302 (anonymous namespace)::LinalgElementwiseOpFusionPass::runOnOperation() ElementwiseOpFusion.cpp:0:0
#18 0x0000555b687eb01e mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/bin/llvm-project/build/bin/mlir-opt+0x3d6d01e)
#19 0x0000555b687eb4fa 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+0x3d6d4fa)
#20 0x0000555b687ebd01 mlir::PassManager::run(mlir::Operation*) (/data/bin/llvm-project/build/bin/mlir-opt+0x3d6dd01)
#21 0x0000555b687dc1ab performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#22 0x0000555b687dd664 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
#23 0x0000555b687dd814 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
#24 0x0000555b688d1404 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+0x3e53404)
#25 0x0000555b687d6c37 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+0x3d58c37)
#26 0x0000555b687ddb3b mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/bin/llvm-project/build/bin/mlir-opt+0x3d5fb3b)
#27 0x0000555b65e60f2b main (/data/bin/llvm-project/build/bin/mlir-opt+0x13e2f2b)
#28 0x00007f4c9c85c083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#29 0x0000555b65ef841e _start (/data/bin/llvm-project/build/bin/mlir-opt+0x147a41e)
Aborted (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWl9z4ygS_zTKCxUXAv19yIPzx7tTNbmkJtm9qntxIYFsbjDoACX2fvorkGxLip04m9zO7FXNOJKAX_evu2kaJGIMX0jGLoL4Moivz0hjl0pfPBO5-GPJN1wulmeFopuLBbfgiWnDlQzwFJRpEeO0qGCOMK1gjOKoyisSpQgVKM9YkVVRmkMawOsATvu_ZmMsWzmMIIG_FY20DUBwAqNJAr4-PoAAZTNVEgFmyhgSoDxI4EsUzWqtaFMyCp65XQZ4GiRwJbg-V7UF5-eCSyIW51Vj2DkTbMWkfeaGnavaADJxHUew3UO8lZLA7l97i_CK1CDA14BUFZdsviJ1gK8ClFHodIwvDQzia3Ae4Bvgn4KVosD4RnzTRwnfB1MJpTTlTy-xDLN9KMNsCxWgHHj7ouzcCbtxnWCArsB5lg3u4eAO573bvaSVoo1gIEgv23sAqkaWE_cDggi6v6GXGhO9gE5whZHDa5-E7smKrTSrAnyF0boKE4ftlNxD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