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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR]`-test-extract-fixed-outer-loops` triggers Assertion Failure `!empty()'
        </td>
    </tr>

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

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

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

<pre>
    Test on commit: https://github.com/llvm/llvm-project/commit/6548b6354d1d990e1c98736f5e7c3de876bedc8e
steps to reproduce:
```
mlir-opt test.mlir --test-extract-fixed-outer-loops
```
test case:
```
module {
 func.func @main(%arg0: tensor<4xi32>) -> () {
    %c4 = arith.constant 4 : index
    %c0 = arith.constant 0 : index
    %c1 = arith.constant 1 : index
    %2 = bufferization.to_memref %arg0 : memref<4xi32>
    %alloc = memref.alloc() {alignment = 64 : i64} : memref<4xi32>
    scf.for %arg4 = %c0 to %c4 step %c1 {
      %19 = memref.load %2[%arg4] : memref<4xi32>
      %20 = math.ctlz %19 : i32
      memref.store %20, %alloc[%arg4] : memref<4xi32>
    }
    return
 }
}
```
crash trace:
```
mlir-opt: /home/workdir/llvm-project-19/llvm/include/llvm/ADT/SmallVector.h:309: reference llvm::SmallVectorTemplateCommon<mlir::scf::ForOp>::back() [T = mlir::scf::ForOp]: Assertion `!empty()' failed.
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 /home/workdir/test.mlir --test-extract-fixed-outer-loops
^[[A #0 0x000055c40f1e53b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./mlir-opt+0x10723b8)
 #1 0x000055c40f1e2ede llvm::sys::RunSignalHandlers() (./mlir-opt+0x106fede)
 #2 0x000055c40f1e5dc8 SignalHandler(int) Signals.cpp:0:0
 #3 0x000070577cebe520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x000070577cf129fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x000070577cebe476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x000070577cea47f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x000070577cea471b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x000070577ceb5e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x000055c41100ce2a mlir::extractFixedOuterLoops(mlir::scf::ForOp, llvm::ArrayRef<long>) (./mlir-opt+0x2e99e2a)
#10 0x000055c411ef97b5 void llvm::function_ref<void (mlir::Operation*)>::callback_fn<std::enable_if<!llvm::is_one_of<mlir::scf::ForOp, mlir::Operation*, mlir::Region*, mlir::Block*>::value && std::is_same<void, void>::value, void>::type mlir::detail::walk<(mlir::WalkOrder)1, mlir::ForwardIterator, (anonymous namespace)::SimpleParametricLoopTilingPass::runOnOperation()::'lambda'(mlir::scf::ForOp), mlir::scf::ForOp, void>(mlir::Operation*, (anonymous namespace)::SimpleParametricLoopTilingPass::runOnOperation()::'lambda'(mlir::scf::ForOp)&&)::'lambda'(mlir::Operation*)>(long, mlir::Operation*) TestLoopParametricTiling.cpp:0:0
#11 0x000055c40f2f371e void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (./mlir-opt+0x118071e)
#12 0x000055c40f2f371e void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (./mlir-opt+0x118071e)
#13 0x000055c411ef95dd (anonymous namespace)::SimpleParametricLoopTilingPass::runOnOperation() TestLoopParametricTiling.cpp:0:0
#14 0x000055c4124616df mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (./mlir-opt+0x42ee6df)
#15 0x000055c412461ec2 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (./mlir-opt+0x42eeec2)
#16 0x000055c41246466e mlir::PassManager::run(mlir::Operation*) (./mlir-opt+0x42f166e)
#17 0x000055c41245d192 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#18 0x000055c41245cdfb llvm::LogicalResult llvm::function_ref<llvm::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&)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#19 0x000055c412506ae5 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (./mlir-opt+0x4393ae5)
#20 0x000055c412457ff2 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (./mlir-opt+0x42e4ff2)
#21 0x000055c4124582a3 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x42e52a3)
#22 0x000055c4124584b2 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x42e54b2)
#23 0x000055c40f1c45d7 main (./mlir-opt+0x10515d7)
#24 0x000070577cea5d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#25 0x000070577cea5e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#26 0x000055c40f1c4145 _start (./mlir-opt+0x1051145)
Aborted (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWV1v47rR_jXMDWFDor4vcuEka7wL7CLBbvD20qDEkcwuRaoktZucX1-Qkm3JsZL6tAc9bQEnlsThzDMzzwwpmhrDGwlwi5I7lDzc0N7ulb594YbKJrgpFXu9fQZjsZK4Um3LLYo2eG9tZ1C0QWSLyLbhdt-X60q1iGyF-Hn4WnVa_RUqi8h2nEq2aRLnZRolMQtZUQQQVkWeRWmdQFZFDPIsLYFVOaDgAQUbY6Ez2CqsodOK9RU4o34IpcH48bet4HqlOostGLt2d3i1ctcreLGaVnZV8xdgK9Vb0CuhVGcu6nFTcEXNsiHFegEYZXfDPa57Wa3dP4zioKVcIpIjklDdBC5UFqRRGkX38QuPCIo-IVLgFYo-YS9XTDRhjBFJqhij6AFTze1-XSlpLJUWu4cbzCWDl7l0cEk6WJIOL0mHC9LEC5d9XYPmv1HLlVxbtWuh1VDj0Uc_d3g0dXKqhwqhKq9rkFv7Byf3qeCNbEFaL5OOrqYxyh4-0m6qel0rPYIZIjdExaoxmI5DB9-nofbQwmKKSyjKvOOuGAaNKPkQwxCrIQ8tdYG14rej8g128hPh0ZaxSsMwE5H7Y5iusoyyh9ONBttrOd4fR04XcxpXmpo9dpXxYUk5EIhs96oFRLa_lP7BuD4r8VVYnGqfy0r0DE4PNg_PiGy_t1SI_4fKKr3eo2gTBYVTraEGDbIC7KWjDYo2E9FnaDtBLdyrtlUSRfcO1iBlqnq42Cr92LnI-LuSVj8O5Erunoe8LE1KHhyGjTGgHb-x856E0Hb2ddCBSIZrygWw9R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