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

    <tr>
        <th>Summary</th>
        <td>
            [mlir] Linalg-fold-unit-extent-dims crashes with assertion violation : N+M <= size() && "Invalid specifier"
        </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 https://github.com/llvm/llvm-project/commit/a0138390
Reproduced with: 
`mlir-opt --linalg-fold-unit-extent-dims temp.mlir`

temp.mlir:
``` 
module {
  func.func @func(%arg0: tensor<128x128x128x128xf32>, %arg1: tensor<1x?x1xf32>, %arg2: tensor<?xf32>, %arg3: index, %arg4: index) -> tensor<128x128x128x128xf32> {
 %inserted_slice = tensor.insert_slice %arg2 into %arg1[0, 0, 0] [1, %arg4, 1] [1, 1, 1] : tensor<?xf32> into tensor<1x?x1xf32>
    %inserted_slice_0 = tensor.insert_slice %inserted_slice into %arg0[6, 7, 8, %arg3] [1, 1, %arg4, 1] [1, 1, 1, 1] : tensor<1x?x1xf32> into tensor<128x128x128x128xf32>
 return %inserted_slice_0 : tensor<128x128x128x128xf32>
 }
}

```
 
trace:
```console  
Assertion failed: (N+M <= size() && "Invalid specifier"), function slice, file ArrayRef.h, line 194.
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 --linalg-fold-unit-extent-dims temp.mlir
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  mlir-opt 0x00000001042e05bc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  mlir-opt                 0x00000001042df624 llvm::sys::RunSignalHandlers() + 112
2  mlir-opt 0x00000001042e0c54 SignalHandler(int) + 344
3  libsystem_platform.dylib 0x00000001a56894c4 _sigtramp + 56
4  libsystem_pthread.dylib 0x00000001a5671ee0 pthread_kill + 288
5  libsystem_c.dylib 0x00000001a55ac340 abort + 168
6  libsystem_c.dylib 0x00000001a55ab754 err + 0
7  mlir-opt                 0x0000000105ad52f0 computeTensorReshapeCollapsedType(mlir::RankedTensorType, llvm::ArrayRef<mlir::AffineMap>) (.cold.2) + 0
8  mlir-opt 0x0000000104e7d158 computeTensorReshapeCollapsedType(mlir::RankedTensorType, llvm::ArrayRef<mlir::AffineMap>) + 888
9  mlir-opt 0x0000000104e7cc78 mlir::tensor::CollapseShapeOp::build(mlir::OpBuilder&, mlir::OperationState&, mlir::Value, llvm::ArrayRef<llvm::SmallVector<long long, 2u>>, llvm::ArrayRef<mlir::NamedAttribute>) + 168
10 mlir-opt 0x0000000104772150 mlir::tensor::CollapseShapeOp mlir::OpBuilder::create<mlir::tensor::CollapseShapeOp, mlir::detail::TypedValue<mlir::TensorType>, llvm::SmallVector<llvm::SmallVector<long long, 2u>, 1u>&>(mlir::Location, mlir::detail::TypedValue<mlir::TensorType>&&, llvm::SmallVector<llvm::SmallVector<long long, 2u>, 1u>&) + 148
11 mlir-opt                 0x0000000104771f04 (anonymous namespace)::RankReducedInsertSliceOp<mlir::tensor::InsertSliceOp>::matchAndRewrite(mlir::tensor::InsertSliceOp, mlir::PatternRewriter&) const + 484
12 mlir-opt 0x000000010577fbd0 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&)>) + 1440
13 mlir-opt                 0x000000010553a328 mlir::applyPatternsAndFoldGreedily(llvm::MutableArrayRef<mlir::Region>, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig) + 3808
14 mlir-opt                 0x00000001047753b0 (anonymous namespace)::LinalgFoldUnitExtentDimsPass::runOnOperation() + 900
15 mlir-opt                 0x00000001054eb4dc mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) + 420
16 mlir-opt 0x00000001054eba0c mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) + 320
17 mlir-opt                 0x00000001054ed388 mlir::PassManager::run(mlir::Operation*) + 1148
18 mlir-opt 0x00000001054e6840 performActions(llvm::raw_ostream&, bool, bool, std::__1::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, bool, bool) + 504
19 mlir-opt                 0x00000001054e6410 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>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool)::$_0>(long, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) + 704
20 mlir-opt                 0x000000010555102c 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) + 656
21 mlir-opt 0x00000001054e4838 mlir::MlirOptMain(llvm::raw_ostream&, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool) + 216
22 mlir-opt                 0x00000001054e4d2c mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) + 1208
23 mlir-opt 0x00000001041830a0 main + 108
24 dyld 0x0000000108b81088 start + 516

```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWVtv47oR_jXMCxGDoiRbfsiDnUtPgPgkcLYHaF8MShzb7FKkSlLZeH99QUqy5dvGewG6KBrsSjI5HH5zH1HMWrFSADconaL07orVbq3Nza2WUlfauNqSq1zzzQ0id4hMZk-Pc5zXQjrMHC50WQqH185VFsUTRB8QfVgJt67zQaFLRB-kfOtu15XR_4LCIfrQrEP0gZEozuIxaZjPoTKa1wVw_EW4NYonuJlAQ1JKYa515fD1tRSKydX1Ukt-XSvhruHdgXLXXJQWOyirgSdGw5Zrc92Nx5Mt0-Zfu0mpeS0Bo9G0-Y3xslbFwF8wSoi_I5ohmjKzIh6bA2W1QfFtRLP3_v9lTFF8j-gtbqijfep3FD-8R0dUdI_K0xxSxJ5CKA7vu7GkNzbG1yi-_whXT0JEU6EsGAd8YaUoAKP4rl0_aGa68QYiFsrprVTplHgg7SW9wyidRn1o9BZH_fFoN3Ja1ob_OVW1ZsHHuBfkW8gPZOzJQFA6HXpQI3_J-qo-hP2BTCcF28d_KNxpr2mENOBqo84I-rHrteYd3bWuvn3Y9_yOrokQwwo4jo5CK6sl4JZqYj0coRVeMiGBhyCl2Z-ITmc42PIOW_EVQqiMMaJDRIcYUfqo3pgUHNsKCrEUYBCliI694nxoBZZBxDAiJOCJMWwzh-Vg7YekUICjcTJocLw83U9e77Gtc5-BGM7rFTbgMxZ2-vszkrC2BovoA2aKY6EKWXPAbg24MMyucc6Kz0FB7favjhWfMa_LaqsxMkBk_GL0yrASM7OqS1DOg8Dfn7sO9gjpUNcO202Za4kVK8F6tYOytQG80TVeszfAQaqGSHwFg4Xycwa_TD79g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