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

    <tr>
        <th>Summary</th>
        <td>
            [mlir] Inconsistent results and crash for vector.bitcast
        </td>
    </tr>

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

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

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

<pre>
    I have the following MLIR program:
test.mlir:
```
module {
 func.func @func1() -> f32{
    %idx0 = index.constant 0

    %cst_6 = arith.constant -0.0 : f32
    %173 = vector.broadcast %cst_6 : f32 to vector<5x1xf32>
    %176 = vector.bitcast %173 : vector<5x1xf32> to vector<5x1xi32>
   
    %554 = vector.shape_cast %176 : vector<5x1xi32> to vector<5xi32>
    %555 = vector.extract %554[%idx0] : i32 from vector<5xi32>
   
    vector.print %555 : i32
    %0 = arith.sitofp %555 : i32 to f32
    return %0 : f32
  }
}
```
When I ran ```/data/tmp/v1107/llvm-project/build/bin/mlir-opt --convert-vector-to-llvm --convert-index-to-llvm --convert-arith-to-llvm --convert-scf-to-cf --convert-func-to-llvm --reconcile-unrealized-casts test.mlir | /data/tmp/v1107/llvm-project/build/bin/mlir-cpu-runner -e func1 --shared-libs=/data/tmp/v1107/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v1107/llvm-project/build/lib/libmlir_c_runner_utils.so``` on the program, I got the result of:
```
0
0.000000e+00
```
However, when I ran ```/data/tmp/v1107/llvm-project/build/bin/mlir-opt --test-vector-linearize --convert-vector-to-llvm --convert-index-to-llvm --convert-arith-to-llvm --convert-scf-to-cf --convert-func-to-llvm --reconcile-unrealized-casts test.mlir | /data/tmp/v1107/llvm-project/build/bin/mlir-cpu-runner -e func1 --shared-libs=/data/tmp/v1107/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v1107/llvm-project/build/lib/libmlir_c_runner_utils.so``` on the program, I got the result of:
```
-2147483648
-2.147484e+09
```

The above two results seem to be inconsistent. I'm not sure if there is any bug in my program or if the wrong usage of the above passes caused these results.


Besides, if I change the test.mlir to :
```
module {
  func.func @func1() -> f32{
    %idx0 = index.constant 0

 %cst_6 = arith.constant -0.0 : f32
    %173 = vector.broadcast %cst_6 : f32 to vector<5x1xf32>
    %176 = vector.bitcast %173 : vector<5x1xf32> to vector<5x1xi32>

    %555 = vector.extract %176[%idx0] : i32 from vector<5x1xi32>
   
    vector.print %555 : i32
    %0 = arith.sitofp %555 : i32 to f32
    return %0 : f32
 }
}
```
The above MLIR program will cause a crash when using the following command:
```
mlir-opt --convert-vector-to-llvm test.mlir
```
And the crash backtrace is:
```
incompatible with LLVM vector type
UNREACHABLE executed at /data/tmp/v1107/llvm-project/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp:897!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /data/tmp/v1107/llvm-project/build/bin/mlir-opt --convert-vector-to-llvm test.mlir
 #0 0x00005564ab6437af llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/tmp/v1107/llvm-project/build/bin/mlir-opt+0x15d17af)
 #1 0x00005564ab640834 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f232257d420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f232204a00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007f2322029859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x00005564ab66859e (/data/tmp/v1107/llvm-project/build/bin/mlir-opt+0x15f659e)
 #6 0x00005564ac987f8f mlir::LLVM::getVectorElementType(mlir::Type) (/data/tmp/v1107/llvm-project/build/bin/mlir-opt+0x2915f8f)
 #7 0x00005564ac7b5f47 mlir::LLVM::ExtractElementOp::build(mlir::OpBuilder&, mlir::OperationState&, mlir::Value, mlir::Value) (/data/tmp/v1107/llvm-project/build/bin/mlir-opt+0x2743f47)
 #8 0x00005564ae2758b4 (anonymous namespace)::VectorExtractOpConversion::matchAndRewrite(mlir::vector::ExtractOp, mlir::vector::ExtractOpAdaptor, mlir::ConversionPatternRewriter&) const ConvertVectorToLLVM.cpp:0:0
 #9 0x00005564ae2581b2 mlir::ConvertOpToLLVMPattern<mlir::vector::ExtractOp>::matchAndRewrite(mlir::Operation*, llvm::ArrayRef<mlir::Value>, mlir::ConversionPatternRewriter&) const (/data/tmp/v1107/llvm-project/build/bin/mlir-opt+0x41e61b2)
#10 0x00005564aea0052a mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const (/data/tmp/v1107/llvm-project/build/bin/mlir-opt+0x498e52a)
#11 0x00005564b1c335c0 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&)>) (/data/tmp/v1107/llvm-project/build/bin/mlir-opt+0x7bc15c0)
#12 0x00005564aea0889b (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) DialectConversion.cpp:0:0
#13 0x00005564aea09efe mlir::OperationConverter::convert(mlir::ConversionPatternRewriter&, mlir::Operation*) (/data/tmp/v1107/llvm-project/build/bin/mlir-opt+0x4997efe)
#14 0x00005564aea0d8eb mlir::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>) (/data/tmp/v1107/llvm-project/build/bin/mlir-opt+0x499b8eb)
#15 0x00005564aea0fe09 mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) (/data/tmp/v1107/llvm-project/build/bin/mlir-opt+0x499de09)
#16 0x00005564ae27b4a4 (anonymous namespace)::ConvertVectorToLLVMPass::runOnOperation() ConvertVectorToLLVMPass.cpp:0:0
#17 0x00005564ae965081 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/tmp/v1107/llvm-project/build/bin/mlir-opt+0x48f3081)
#18 0x00005564ae96557a mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/tmp/v1107/llvm-project/build/bin/mlir-opt+0x48f357a)
#19 0x00005564ae966114 mlir::PassManager::run(mlir::Operation*) (/data/tmp/v1107/llvm-project/build/bin/mlir-opt+0x48f4114)
#20 0x00005564ae95748b performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#21 0x00005564ae957e54 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
#22 0x00005564ae958004 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
#23 0x00005564aea616ee 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) (/data/tmp/v1107/llvm-project/build/bin/mlir-opt+0x49ef6ee)
#24 0x00005564ae94f8a9 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/tmp/v1107/llvm-project/build/bin/mlir-opt+0x48dd8a9)
#25 0x00005564ae958171 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/tmp/v1107/llvm-project/build/bin/mlir-opt+0x48e6171)
#26 0x00005564ae958636 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/tmp/v1107/llvm-project/build/bin/mlir-opt+0x48e6636)
#27 0x00005564ab55907b main (/data/tmp/v1107/llvm-project/build/bin/mlir-opt+0x14e707b)
#28 0x00007f232202b083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#29 0x00005564ab616a5e _start (/data/tmp/v1107/llvm-project/build/bin/mlir-opt+0x15a4a5e)
Aborted (core dumped)
```

My git version is 1469d82e1cb3edc939d6b93089046edfef0cf36c.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWltz46jy_zTKC2UXQveHPDi32lQl_6SS_Pc8upDUktmVQQdQEu-nPwWSY-FL4pnx7O7ZOqkZ2Yamu3_dTdOAqFKs5gDnXnThRVdntNMLIc_fKK9Xgte_-fQsF-Xq_BYt6CsgvQBUiaYRb4zX6P7u9gm1UtSSLr1g5uErD880KD1dNkx-tHgxHv7Zn0tRdg0gL7nof6Oq48XUPJAXYvPpeyT1SIYmXnCNqoBsSBFCHolY-Y6RF1whxkt4nxaCK025RoMAh7ZQeh5bYiqZXmyIJ3hqmMysgPEIPwks_SsUWshpLgUtC6r0mJsdhbQYiLzgMnr33w2n4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