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

    <tr>
        <th>Summary</th>
        <td>
            [mlir] Canonicalize Pass crashed on  0-ranked vector type with assertion failure "invalid index for shaped type"
        </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/97a1c98f
Reproduced with: 
`mlir-opt --canonicalize temp.mlir`

temp.mlir:
``` milr 
func.func @func(%arg0: vector<f32>) -> f32 {
  %0 = vector.reduction <add>, %arg0 : vector<f32> into f32
  return %0 : f32
}
```
 
trace:
```console  
Assertion failed: (idx < getRank() && "invalid index for shaped type"), function getDimSize, file BuiltinTypeInterfaces.h.inc, line 270.
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 --canonicalize 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                 0x0000000102f078c4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  mlir-opt 0x0000000102f0692c llvm::sys::RunSignalHandlers() + 112
2 mlir-opt                 0x0000000102f07f5c SignalHandler(int) + 344
3 libsystem_platform.dylib 0x00000001aad414c4 _sigtramp + 56
4 libsystem_pthread.dylib  0x00000001aad29ee0 pthread_kill + 288
5 libsystem_c.dylib        0x00000001aac64340 abort + 168
6 libsystem_c.dylib        0x00000001aac63754 err + 0
7  mlir-opt 0x0000000104bd96f0 (anonymous namespace)::ElideSingleElementReduction::matchAndRewrite(mlir::vector::ReductionOp, mlir::PatternRewriter&) const (.cold.6) + 0
8  mlir-opt 0x0000000103f7725c (anonymous namespace)::ElideSingleElementReduction::matchAndRewrite(mlir::vector::ReductionOp, mlir::PatternRewriter&) const + 428
9  mlir-opt 0x000000010482353c 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&)>) + 1420
10 mlir-opt                 0x00000001045d2a08 mlir::applyPatternsAndFoldGreedily(llvm::MutableArrayRef<mlir::Region>, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig) + 3976
11 mlir-opt                 0x00000001045987f0 (anonymous namespace)::Canonicalizer::runOnOperation() + 124
12 mlir-opt 0x0000000104583518 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) + 428
13 mlir-opt                 0x0000000104583a48 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) + 320
14 mlir-opt                 0x00000001045853c4 mlir::PassManager::run(mlir::Operation*) + 1148
15 mlir-opt 0x000000010457e788 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
16 mlir-opt                 0x000000010457e358 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
17 mlir-opt                 0x00000001045e904c 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
18 mlir-opt 0x000000010457c780 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
19 mlir-opt                 0x000000010457cc74 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) + 1208
20 mlir-opt 0x0000000102da9cf0 main + 108
21 dyld 0x0000000107f01088 start + 516

```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWFtv47oR_jXyCxFDou4PflCcpGeBBAmcRYH2xaDJkcwuRaoklV3vry9ISb7FOetzzhZYFDUCK7CGH-eb-WZ4IcbwRgIsgvQ2SO9mpLdbpRdLJYTqlLa9CWcbxXaLp8dPK7TpubCIWERV23KLttZ2JoirAD8E-KHhdttv5lS1AX4Q4m163HRa_QuoDfDDMC7AD2VOIloWdRDeBWG1gk4r1lNg6Cu32yCu0PAiyMJWcH2jOotubiiRSnJKBP8OyELbzd3LIAtHY_99-D2u9iDDH2q50CNy3Us6d18oSEL3DHAR4JToJnTTvwG1Sgfxso5xEN8HuEQ3QXyP6hijIL8dMBAKcBqiIL4b7ecaWE8tVxIF8ZIw5ocu0QiMLiAjLq1ysBOkBttrOSFXh1dBfnfGZxwy8taEwnvOVEmjBKDRqjIGtHewJlwA86HGBWffnMeoAbsi8ouPRYkCnAU4QwHGXL4RwRniksE3VCuNzJZ0wJDddRBg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