<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64287>64287</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir] `affine-parallelize` pass crashed with assertion failure "non-terminal symbol / loop IV expected".
</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 b4c54b20
Reproduced with:
`mlir-opt --affine-parallelize="max-nested=1 parallel-reductions" temp.mlir`
temp.mlir:
``` milr
func.func @func1(%arg0: memref<9x9xi32>, %arg1: i1) {
%idx1879048192 = index.constant 1879048192
%idx0 = index.constant 0
%c6 = arith.constant 6 : index
%c0_i64 = arith.constant 0 : i64
%c1_i64 = arith.constant 1 : i64
%c807538455_i64 = arith.constant 807538455 : i64
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%c2 = arith.constant 2 : index
%8 = tensor.empty(%c1, %c1) : tensor<?x?x6xi1>
%14 = tensor.empty() : tensor<31x31xf16>
%20 = bufferization.to_memref %8 : memref<?x?x6xi1>
%26 = scf.index_switch %c1 -> tensor<?x31x6xf16>
case 2 {
%alloc_62 = memref.alloc(%c1, %c2) : memref<?x?x6x9xi1>
%dim = memref.dim %20, %c0 : memref<?x?x6xi1>
%dim_63 = memref.dim %20, %c1 : memref<?x?x6xi1>
affine.for %arg2 = 0 to %dim {
affine.for %arg3 = 0 to %dim_63 {
affine.for %arg4 = 0 to 6 {
affine.for %arg5 = 0 to 9 {
%38 = affine.load %20[%arg2, %arg3, %arg4] : memref<?x?x6xi1>
affine.store %38, %alloc_62[%arg2, %arg3, %arg4, %arg5] : memref<?x?x6x9xi1>
}
}
}
}
%38 = tensor.empty(%idx0) : tensor<?x31x6xf16>
scf.yield %38 : tensor<?x31x6xf16>
}
default {
%37 = scf.parallel (%arg2) = (%c1) to (%c2) step (%c1) init (%c807538455_i64) -> i64 {
scf.reduce(%c0_i64) : i64 {
^bb0(%arg3: i64, %arg4: i64):
%extracted_62 = tensor.extract %14[%c1, %c0] : tensor<31x31xf16>
scf.reduce.return %c1_i64 : i64
}
scf.yield
}
%38 = tensor.empty(%c6) : tensor<?x31x6xf16>
scf.yield %38 : tensor<?x31x6xf16>
}
return
}
```
trace:
```console
Assertion failed: ((isTopLevelValue(val) || isAffineInductionVar(val)) && "non-terminal symbol / loop IV expected"), function addInductionVarOrTerminalSymbol, file AffineStructures.cpp, line 44.
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 "--affine-parallelize=max-nested=1 parallel-reductions" temp.mlir
#0 0x00000001026a0548 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/workspace/build/bin/mlir-opt+0x1002f8548)
#1 0x000000010269e7e4 llvm::sys::RunSignalHandlers() (/workspace/build/bin/mlir-opt+0x1002f67e4)
#2 0x00000001026a0bf4 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 0x00000001064be744 mlir::affine::FlatAffineValueConstraints::addAffineForOpDomain(mlir::affine::AffineForOp) (.cold.1) (/workspace/build/bin/mlir-opt+0x104116744)
#8 0x00000001026ec348 mlir::affine::FlatAffineValueConstraints::addInductionVarOrTerminalSymbol(mlir::Value) (/workspace/build/bin/mlir-opt+0x100344348)
#9 0x00000001026ecc44 mlir::affine::FlatAffineValueConstraints::addBound(mlir::presburger::BoundType, unsigned int, mlir::AffineMap, mlir::ValueRange) (/workspace/build/bin/mlir-opt+0x100344c44)
#10 0x00000001026ec8c0 mlir::affine::FlatAffineValueConstraints::addAffineForOpDomain(mlir::affine::AffineForOp) (/workspace/build/bin/mlir-opt+0x1003448c0)
#11 0x00000001026ea4e8 mlir::affine::getIndexSet(llvm::MutableArrayRef<mlir::Operation*>, mlir::affine::FlatAffineValueConstraints*) (/workspace/build/bin/mlir-opt+0x1003424e8)
#12 0x00000001026ea6b8 mlir::affine::MemRefAccess::getAccessRelation(mlir::affine::FlatAffineRelation&) const (/workspace/build/bin/mlir-opt+0x1003426b8)
#13 0x00000001026e93fc mlir::affine::checkMemrefAccessDependence(mlir::affine::MemRefAccess const&, mlir::affine::MemRefAccess const&, unsigned int, mlir::affine::FlatAffineValueConstraints*, llvm::SmallVector<mlir::affine::DependenceComponent, 2u>*, bool) (/workspace/build/bin/mlir-opt+0x1003413fc)
#14 0x00000001026e9044 mlir::affine::isLoopMemoryParallel(mlir::affine::AffineForOp) (/workspace/build/bin/mlir-opt+0x100341044)
#15 0x00000001026e8e70 mlir::affine::isLoopParallel(mlir::affine::AffineForOp, llvm::SmallVectorImpl<mlir::affine::LoopReduction>*) (/workspace/build/bin/mlir-opt+0x100340e70)
#16 0x000000010275baa8 void llvm::function_ref<void (mlir::Operation*)>::callback_fn<std::__1::enable_if<!llvm::is_one_of<mlir::affine::AffineForOp, mlir::Operation*, mlir::Region*, mlir::Block*>::value && std::is_same<void, void>::value, void>::type mlir::detail::walk<(mlir::WalkOrder)0, mlir::ForwardIterator, (anonymous namespace)::AffineParallelize::runOnOperation()::$_0, mlir::affine::AffineForOp, void>(mlir::Operation*, (anonymous namespace)::AffineParallelize::runOnOperation()::$_0&&)::'lambda'(mlir::Operation*)>(long, mlir::Operation*) (/workspace/build/bin/mlir-opt+0x1003b3aa8)
#17 0x0000000102a43b2c void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (/workspace/build/bin/mlir-opt+0x10069bb2c)
#18 0x0000000102a43ba0 void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (/workspace/build/bin/mlir-opt+0x10069bba0)
#19 0x0000000102a43ba0 void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (/workspace/build/bin/mlir-opt+0x10069bba0)
#20 0x000000010275b49c (anonymous namespace)::AffineParallelize::runOnOperation() (/workspace/build/bin/mlir-opt+0x1003b349c)
#21 0x0000000104d29e34 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/workspace/build/bin/mlir-opt+0x102981e34)
#22 0x0000000104d2a524 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 0x0000000104d2b5d8 mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (/workspace/build/bin/mlir-opt+0x1029835d8)
#24 0x0000000104d29f90 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/workspace/build/bin/mlir-opt+0x102981f90)
#25 0x0000000104d2a524 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)
#26 0x0000000104d2c3bc mlir::PassManager::run(mlir::Operation*) (/workspace/build/bin/mlir-opt+0x1029843bc)
#27 0x0000000104d24808 performActions(llvm::raw_ostream&, std::__1::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) (/workspace/build/bin/mlir-opt+0x10297c808)
#28 0x0000000104d23d30 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)
#29 0x0000000104da2be0 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)
#30 0x0000000104d1e6e4 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)
#31 0x0000000104d1eb54 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/workspace/build/bin/mlir-opt+0x102976b54)
#32 0x00000001023ab58c main (/workspace/build/bin/mlir-opt+0x10000358c)
#33 0x000000010dced088
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWktv47iT_zTKhYhBUQ9LhxzcTgcboIMESaP3aFBSydGGErUk1bHn0y9ISrYo2-nY89jB_GcwHctksZ6_KhZlUimrdQNw40VfvOj2inbqlYubJWeMt1yoTuKrjBfbm4dv988o6yqmEFUo53VdKYSyMI_CjGAP33p48Qyt4EWXQ4HeK_XqBQuE7IwX45pV4pq3Cl1f07KsGrhuqaCMAat-Ay-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