<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58664>58664</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [MLIR Affine]-affine-loop-tile crashed with a assertion error
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          BealZephyr
      </td>
    </tr>
</table>

<pre>
    Hello, I encountered a bug when I tried cmd `mlir-opt -affine-loop-tile`. 

Below is the crash backtrace:
```
mlir-opt: /data/llvm/mlir/lib/Dialect/Affine/Analysis/AffineStructures.cpp:574: void mlir::FlatAffineValueConstraints::addInductionVarOrTerminalSymbol(mlir::Value): Assertion `(isTopLevelValue(val) || isForInductionVar(val)) && "non-terminal symbol / loop IV expected"' 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/llvm/build/bin/mlir-opt temp1.mlir -affine-loop-tile
 #0 0x000055949a8658cf PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x000055949a862c9c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007fecb12a3980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #3 0x00007fecb059fe87 raise /build/glibc-CVJwZb/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #4 0x00007fecb05a17f1 abort /build/glibc-CVJwZb/glibc-2.27/stdlib/abort.c:81:0
 #5 0x00007fecb05913fa __assert_fail_base /build/glibc-CVJwZb/glibc-2.27/assert/assert.c:89:0
 #6 0x00007fecb0591472 (/lib/x86_64-linux-gnu/libc.so.6+0x30472)
 #7 0x000055949bc7c3b5 mlir::FlatAffineValueConstraints::addInductionVarOrTerminalSymbol(mlir::Value) (/data/llvm/build/bin/mlir-opt+0x159b3b5)
 #8 0x000055949bc7ba5f mlir::FlatAffineValueConstraints::addBound(mlir::presburger::IntegerRelation::BoundType, unsigned int, mlir::AffineMap, mlir::ValueRange) (.constprop.281) AffineStructures.cpp:0:0
 #9 0x000055949bc7bca2 mlir::FlatAffineValueConstraints::addAffineForOpDomain(mlir::AffineForOp) (/data/llvm/build/bin/mlir-opt+0x159aca2)
#10 0x000055949bc8fabb mlir::MemRefRegion::compute(mlir::Operation*, unsigned int, mlir::ComputationSliceState const*, bool) (.constprop.341) Utils.cpp:0:0
#11 0x000055949bc90c64 getMemoryFootprintBytes(mlir::Block&, llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, true, false, void>, false, false>, llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, true, false, void>, false, false>, int)::'lambda'(mlir::Operation*)::operator()(mlir::Operation*) const Utils.cpp:0:0
#12 0x000055949be8b66c mlir::detail::walk(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (/data/llvm/build/bin/mlir-opt+0x17aa66c)
#13 0x000055949be8b66c mlir::detail::walk(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (/data/llvm/build/bin/mlir-opt+0x17aa66c)
#14 0x000055949be8b66c mlir::detail::walk(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (/data/llvm/build/bin/mlir-opt+0x17aa66c)
#15 0x000055949be8b66c mlir::detail::walk(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (/data/llvm/build/bin/mlir-opt+0x17aa66c)
#16 0x000055949bc8a40c mlir::getMemoryFootprintBytes(mlir::AffineForOp, int) (/data/llvm/build/bin/mlir-opt+0x15a940c)
#17 0x000055949a92c55c (anonymous namespace)::LoopTiling::runOnOperation() LoopTiling.cpp:0:0
#18 0x000055949bce8c69 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/llvm/build/bin/mlir-opt+0x1607c69)
#19 0x000055949bce8fb0 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/llvm/build/bin/mlir-opt+0x1607fb0)
#20 0x000055949bce92d0 mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::'lambda'(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&)::operator()(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&) const Pass.cpp:0:0
#21 0x000055949bce8195 mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (/data/llvm/build/bin/mlir-opt+0x1607195)
#22 0x000055949bce8bca mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/llvm/build/bin/mlir-opt+0x1607bca)
#23 0x000055949bce9a09 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (.constprop.485) Pass.cpp:0:0
#24 0x000055949bce9fbd mlir::PassManager::run(mlir::Operation*) (/data/llvm/build/bin/mlir-opt+0x1608fbd)
#25 0x000055949bcdbcdb performActions(llvm::raw_ostream&, bool, bool, llvm::SourceMgr&, mlir::MLIRContext*, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, bool, bool) (.constprop.193) MlirOptMain.cpp:0:0
#26 0x000055949bcdc402 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, bool, bool, bool, bool, bool, bool, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, llvm::ThreadPool*) MlirOptMain.cpp:0:0
#27 0x000055949bcdc73f 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>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool)::'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
#28 0x000055949bd9f410 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/llvm/build/bin/mlir-opt+0x16be410)
#29 0x000055949bcdaba6 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::PassPipelineCLParser const&, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool, bool) (/data/llvm/build/bin/mlir-opt+0x15f9ba6)
#30 0x000055949bcdcb5b mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) (/data/llvm/build/bin/mlir-opt+0x15fbb5b)
#31 0x000055949a833210 main (/data/llvm/build/bin/mlir-opt+0x152210)
#32 0x00007fecb0582c87 __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:344:0
#33 0x000055949a84587a _start (/data/llvm/build/bin/mlir-opt+0x16487a)
Aborted (core dumped)
```
The test case is attached [here](https://github.com/llvm/llvm-project/files/9887355/temp.mlir.txt). You can reproduce this crash by following the steps:
```
mlir-opt temp.mlir -pass-pipeline="func.func(tosa-to-linalg)"  -linalg-bufferize  -convert-linalg-to-affine-loops  -affine-loop-coalescing -affine-data-copy-generate="generate-dma=false fast-mem-space=0 skip-non-unit-stride-loops"   -affine-loop-fusion  -affine-parallelize  -o temp1.mlir 
```
```
mlir-opt temp1.mlir  -affine-loop-tile
```
Test commit: [#e6c23f4](https://github.com/llvm/llvm-project/commit/e6c23f4724ecf10219552e3df3047ebfe10cdb83)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlWltT47gS_jXhRZWU75eHPARmqOUUFBRw5tTZl5QstRPv2JaPLAPZX39ashNsEwKhZnapnakMtm7dX1_UallKBN_Mf4M8FxPnjFwQKJloSgUSOKEkaVbkcQ0lNiiZYRUrOJkEVpFncioqRaY0TbMSprkQ1VRlOWDjjEysLxNr0f49hVw8kqwmag2ESVqvSULZdyUpg4nbdcJR3c8Ut-SxnUycc04VxUeePxT40I26lCX490tGc2AK3xYGiH4pab6ps3pXd6dkw1QjoZ6xqkKafuhpyg8i48RQQxju4jynqh3wjeYNnImyRpBZqeq2nXJ-UXKklInyG5XX8h5kkSGzu02RiHziRM-0DIWJE2s2i7oGqQdpxWGvrL4X1SU8QN71ih4ojo7JJDzDH6rqXMg-p10P08kJ8IcPpxTlVHUQSG0waGURbQpy8Y3AU4WaAY5dJ05IUorW4bNWwTeXXxd3X0ndJEWmOjtLqIRURAmyVqoyQjvn-Ftlat0kMyaKZxvox7SS4o9W91ldN6AVTmjJSVayvOGwz-Ad-zuFFYQ3RbXzAAub4hspVpIWhMpVU0Cr-ZcOkDRZzvUzKzt3MK6ooKjsmS7u8UrDA0m5FrGeLPzn-7EX0yjwI5aSG4lmNqDuNcq7bIU6_Q1lycFoHx1l4iy0-tumrSNZ5v-Otj2i7bCYkTEx5PQmIacjFKbAEtuhbhxZZLlED1ZCwhKthIR2c-ApCpaBN82zsnmarsqmbajUWgLls1r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