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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR] [Vector] optimization VectorLinearize crashes
        </td>
    </tr>

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

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

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

<pre>
    To reproduce: https://godbolt.org/z/zMx85vh71
Calling VectorLinearize crashes on this snippet of code
`mlir-opt -allow-unregistered-dialect --test-vector-linearize`
```mlir
module {
  func.func @extract_1d_constant() -> () {
    %cst = arith.constant dense<[1, 2, 3, 4]> : vector<4xi32>
    %0 = vector.extract %cst[0] : i32 from vector<4xi32>
    func.return
  }
}
```

```
Stack dump:
0.      Program arguments: /opt/compiler-explorer/mlir-trunk/bin/mlir-opt -o /app/example.out.mlir -allow-unregistered-dialect --test-vector-linearize <source>
 #0 0x000000000151e748 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x151e748)
 #1 0x000000000151c0bc SignalHandler(int) Signals.cpp:0:0
 #2 0x0000729234842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x0000000003ed2353 mlir::VectorType::getScalableDims() const (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3ed2353)
 #4 0x0000000005f842d8 (anonymous namespace)::LinearizeVectorExtract::matchAndRewrite(mlir::vector::ExtractOp, mlir::vector::ExtractOpAdaptor, mlir::ConversionPatternRewriter&) const VectorLinearize.cpp:0:0
 #5 0x00000000037f4e16 mlir::OpConversionPattern<mlir::vector::ExtractOp>::matchAndRewrite(mlir::Operation*, llvm::ArrayRef<mlir::Value>, mlir::ConversionPatternRewriter&) const (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x37f4e16)
 #6 0x0000000003dec1f1 mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3dec1f1)
 #7 0x0000000006a560c2 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x6a560c2)
 #8 0x0000000003df3d75 (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) DialectConversion.cpp:0:0
 #9 0x0000000003df4525 mlir::OperationConverter::convert(mlir::ConversionPatternRewriter&, mlir::Operation*) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3df4525)
#10 0x0000000003df8c5c mlir::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3df8c5c)
#11 0x0000000003dfa072 mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3dfa072)
#12 0x0000000003c6150b (anonymous namespace)::TestVectorLinearize::runOnOperation() TestVectorTransforms.cpp:0:0
#13 0x0000000003d57e41 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3d57e41)
#14 0x0000000003d58449 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3d58449)
#15 0x0000000003d59608 mlir::PassManager::run(mlir::Operation*) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3d59608)
#16 0x0000000003d49a53 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#17 0x0000000003d4a7e3 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPoolInterface*) MlirOptMain.cpp:0:0
#18 0x0000000003d4a8c3 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&)::'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
#19 0x0000000003e49dfe 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) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3e49dfe)
#20 0x0000000003d46a45 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3d46a45)
#21 0x0000000003d4a9f0 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3d4a9f0)
#22 0x0000000003d4ae7f mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3d4ae7f)
#23 0x0000000001437fe7 main (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x1437fe7)
#24 0x0000729234829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#25 0x0000729234829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#26 0x00000000014f89ae _start (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x14f89ae)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWd1yozoSfhrlRmUXCDBw4QvHic9O1aSSmqTOxblxydBg7QiJlUTGmaffksA2EOdnEu_s2Z2a2AakVn9f_6gbUa1ZKQDmKLpE0dUFbcxWqvlfzEhR_rWVzbVi2cVG5k_zB4kV1ErmTQYoWOCtMbVGwQKRFSKrUuYbyc1UqhKR1U_7d7NLosdt7CPvCnmLJeWciRL_CZmR6isTQBX7CThTVG9BYymw2TKNtWB1DQbLAmcyh3YymnkVZ2oia4MnlHP5Y9IIBSXTBhTkk5xRDpnBk4kBbSaPbo0J3y-CZt5BTvvfSmtvVTJvOGAUX7bXGBeNyKb2A6PQg51RNDNrP19nUmhDhUEkQSTFExRc4-53bzbGiESZNhgFV5gqZrbT_UScg9CAgiWKLn1ElpjYj8B-hCi6cvKCBW61R8Ey3LGAoOB6INpzgtsx0067bkkUXXoounJCWEBwoWT1mjQHVIFplNjfRPFVx9Thx56y7vLUzXtDs-84b6ra-oO75U2Rl94pWSpaYarKpgJhrLtgRFayNoisMlnVjIOawK7mUoFCZOWsbFQjviOy2jCxv-UML-1cWteIrGBHq5rDVDZmagd8xCsw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