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

    <tr>
        <th>Summary</th>
        <td>
            [mlir][tosa] --tosa-infer-shapes crashed with assertion failure `idx < size()'
        </td>
    </tr>

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

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

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

<pre>
    git version: 8641cdf397d86f33ac45e4c691ca4f843c359370

system: ```Ubuntu 20.04.6 LTS (Focal Fossa)```

reproduced with: ```mlir-opt --tosa-infer-shapes a.mlir```

a.mlir:

```
func.func private @func2() {
  %c25 = arith.constant 25 : index
  %11 = tensor.empty(%c25) : tensor<?x31xi16>
  %55 = tosa.slice %11 {size = array<i64>, start = array<i64>} : (tensor<?x31xi16>) -> tensor<*xi16>
 %105 = tosa.reduce_min %55 {axis = 0 : i32} : (tensor<*xi16>) -> tensor<1x31xi16>
  return
}
```

trace:
```
mlir-opt: /data/bin/llvm-project/llvm/include/llvm/ADT/SmallVector.h:294: T& llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::operator[](llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::size_type) [with T = long int; <template-parameter-1-2> = void; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::reference = long int&; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::size_type = long unsigned int]: Assertion `idx < size()' 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 --tosa-infer-shapes a.mlir
 #0 0x0000555e213412ef llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/bin/llvm-project/build/bin/mlir-opt+0x158f2ef)
 #1 0x0000555e2133e384 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f1ed6543420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f1ed602e00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007f1ed600d859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x00007f1ed600d729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #6 0x00007f1ed601efd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #7 0x0000555e23022b43 ReduceInferReturnTypes(mlir::ShapeAdaptor, mlir::Type, mlir::IntegerAttr, llvm::SmallVectorImpl<mlir::ShapedTypeComponents>&) TosaOps.cpp:0:0
 #8 0x0000555e23023b82 mlir::tosa::ReduceMinOp::inferReturnTypeComponents(mlir::MLIRContext*, std::optional<mlir::Location>, mlir::ValueShapeRange, mlir::DictionaryAttr, mlir::OpaqueProperties, mlir::RegionRange, llvm::SmallVectorImpl<mlir::ShapedTypeComponents>&) (/data/bin/llvm-project/build/bin/mlir-opt+0x3271b82)
 #9 0x0000555e2307b0aa (anonymous namespace)::propagateShapesInRegion(mlir::Region&) TosaInferShapes.cpp:0:0
#10 0x0000555e2307cb3e (anonymous namespace)::TosaInferShapes::runOnOperation() TosaInferShapes.cpp:0:0
#11 0x0000555e23da388e mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/bin/llvm-project/build/bin/mlir-opt+0x3ff188e)
#12 0x0000555e23da3d6a 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+0x3ff1d6a)
#13 0x0000555e23da476c mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::'lambda'(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&)::operator()(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&) const Pass.cpp:0:0
#14 0x0000555e23da2ec5 mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (/data/bin/llvm-project/build/bin/mlir-opt+0x3ff0ec5)
#15 0x0000555e23da362a mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/bin/llvm-project/build/bin/mlir-opt+0x3ff162a)
#16 0x0000555e23da3d6a 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+0x3ff1d6a)
#17 0x0000555e23da4594 mlir::PassManager::run(mlir::Operation*) (/data/bin/llvm-project/build/bin/mlir-opt+0x3ff2594)
#18 0x0000555e23d94e5b performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#19 0x0000555e23d96314 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
#20 0x0000555e23d964c4 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
#21 0x0000555e23e949c4 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+0x40e29c4)
#22 0x0000555e23d8f797 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+0x3fdd797)
#23 0x0000555e23d967eb mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/bin/llvm-project/build/bin/mlir-opt+0x3fe47eb)
#24 0x0000555e2127a27b main (/data/bin/llvm-project/build/bin/mlir-opt+0x14c827b)
#25 0x00007f1ed600f083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#26 0x0000555e21311f1e _start (/data/bin/llvm-project/build/bin/mlir-opt+0x155ff1e)
Aborted (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWV1v2zjW_jXKDWGDIvV5kQvFjvEGaJAg8Tu3BiUd2dxKpIakOvH--gUpf0iK06aTbHdmsUXr2iL5nK_nHB2STGu-FQDXXnjjhcsr1pmdVNdMSLFvZKfvF89XuSz311tu0DdQmkvh0QwlUeAXZUXTuEyiilJWBCEERZT6BQuqJKAFDVMaYw8vPZz1n3qvDTR2tRfh_u__550wHSJ4joN5hL6sn5FHkpUsWI1WUmvmkfQ0eYiloFWy7Aoo0R_c7EagTc3VTLYGzWZGajbjogI10zvWgkZsbocvYh6GaDZ8OJlZdaKY2w_UKv6NGUBegO1v4pHEIyny4pt-JkIeCQsSIo8uEVPc7OaFFNowYZ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