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

    <tr>
        <th>Summary</th>
        <td>
            [mlir] --resolve-ranked-shaped-type-result-dims 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: b745ce952560716545e82770bf835e48a567eaf1

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

reproduced with: ```mlir-opt --resolve-ranked-shaped-type-result-dims a.mlir```

a.mlir:

```
module {
  func.func private @func2() {
    %idx28 = index.constant 28
    %c19 = arith.constant 19 : index
    %c28 = arith.constant 28 : index
    %c29 = arith.constant 29 : index
    %3 = bufferization.alloc_tensor(%c29) : tensor<?xi16>
 %dim = tensor.dim %3, %idx28 : tensor<?xi16>
    %alloc_21 = memref.alloc(%c28) : memref<?x26x2xi32>
    %16 = affine.vector_load %alloc_21[%c28, %c19, %dim] : memref<?x26x2xi32>, vector<7xi32>
 vector.print %16 : vector<7xi32>
    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 = mlir::OpFoldResult; <template-parameter-1-2> = void; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::reference = mlir::OpFoldResult&; 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 --resolve-ranked-shaped-type-result-dims a.mlir
 #0 0x0000555e8b4463af llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/bin/llvm-project/build/bin/mlir-opt+0x15ca3af)
 #1 0x0000555e8b443444 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f189262c420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f189211700b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007f18920f6859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x00007f18920f6729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #6 0x00007f1892107fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #7 0x0000555e8c6d8095 (/data/bin/llvm-project/build/bin/mlir-opt+0x285c095)
 #8 0x0000555e8c6d8ad2 (anonymous namespace)::DimOfReifyRankedShapedTypeOpInterface<mlir::tensor::DimOp>::matchAndRewrite(mlir::tensor::DimOp, mlir::PatternRewriter&) const ResolveShapedTypeResultDims.cpp:0:0
 #9 0x0000555e8b8af0aa mlir::detail::OpOrInterfaceRewritePatternBase<mlir::tensor::DimOp>::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const (/data/bin/llvm-project/build/bin/mlir-opt+0x1a330aa)
#10 0x0000555e90c610b8 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>) (/data/bin/llvm-project/build/bin/mlir-opt+0x6de50b8)
#11 0x0000555e8e04116c (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#12 0x0000555e8e0455db mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/data/bin/llvm-project/build/bin/mlir-opt+0x41c95db)
#13 0x0000555e8c6d9933 (anonymous namespace)::ResolveRankedShapeTypeResultDimsPass::runOnOperation() ResolveShapedTypeResultDims.cpp:0:0
#14 0x0000555e8df8c39e mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/bin/llvm-project/build/bin/mlir-opt+0x411039e)
#15 0x0000555e8df8c87a 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+0x411087a)
#16 0x0000555e8df8d0a4 mlir::PassManager::run(mlir::Operation*) (/data/bin/llvm-project/build/bin/mlir-opt+0x41110a4)
#17 0x0000555e8df7d96b performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#18 0x0000555e8df7ee24 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
#19 0x0000555e8df7efd4 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
#20 0x0000555e8e07b8e4 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+0x41ff8e4)
#21 0x0000555e8df782a7 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+0x40fc2a7)
#22 0x0000555e8df7f2fb mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/bin/llvm-project/build/bin/mlir-opt+0x41032fb)
#23 0x0000555e8b37ea1b main (/data/bin/llvm-project/build/bin/mlir-opt+0x1502a1b)
#24 0x00007f18920f8083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#25 0x0000555e8b416cde _start (/data/bin/llvm-project/build/bin/mlir-opt+0x159acde)
Aborted (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWc1y27oVfhp6g5EGBP8XXshS1GYmHntst11qQOJQQgMCLAD6Wnn6DkBKJhUr9o3S29tmEkUiD77z_-GApMbwrQS4DpKbIFld0c7ulL6mUsl9ozpzu3y8KhXbX2-5Rc-gDVcyiBaozOKkgiIhSYqzME3iBHKSZbis8yiBOKdJmgGtwwCvArzoP83eWGjc6iDF_d-_lZ20HSJ4juN5ir48PaKA5GtVUYHWyhgakOIoPMbS0GrFugoY-o3b3QS0EVzPVGvRbKbBKPEMM03lV2Azs6MtsJndt-BudcLOGG8MonO35k1Fw61oMb54Itko1glAQXbT_0ao7mQ1dx-o1fyZWkBBjN1vEpA8IMVYFqGAJJy9kBwF0QpxyeBlXilpLJUWkXwiV4WFl6Ka292rlL-66NdO5QfUE3l_9W35N_HJOfzIS5ddXYPm36jlSs6pEKraWJBGae-uQw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