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

    <tr>
        <th>Summary</th>
        <td>
            Crash in ARM backend when compiling vcvtfxs2fp/shufflevector IR with optimizations
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    When compiling the following IR code using `llc -mtriple=aarch64-none-none -O=1`:
```
; Function Attrs: mustprogress nofree nosync nounwind readnone willreturn uwtable
define dso_local noundef <4 x float> @_Z8do_stuffv() local_unnamed_addr #0 {
  %1 = call <2 x float> @llvm.aarch64.neon.vcvtfxs2fp.v2f32.v2i32(<2 x i32> zeroinitializer, i32 1)
  %2 = shufflevector <2 x float> <float 0x37E0001000000000, float 0x37E0001000000000>, <2 x float> %1, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
  ret <4 x float> %2
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind readnone willreturn
declare <2 x float> @llvm.aarch64.neon.vcvtfxs2fp.v2f32.v2i32(<2 x i32>, i32) #1
```
the compiler crashes with 

```
LLVM ERROR: Cannot select: 0x55c9620c5a20: v2f32 = AArch64ISD::NVCAST 0x55c9620c59b8
  0x55c9620c59b8: v4i16 = AArch64ISD::MOVIshift Constant:i32<16>, Constant:i32<0>
    0x55c9620c5950: i32 = Constant<16>
    0x55c9620c54d8: i32 = Constant<0>
```

[Full crash output](https://github.com/llvm/llvm-project/files/8645750/2022_05_07_llvm_arm_backend_crash_output.txt)

The IR case can be found at this godbolt link: https://godbolt.org/z/7W54sb3Yh

Compiling without optimization does not cause the crash.

I believe the DAG it generates at this stage is:
```
SelectionDAG has 14 nodes:
    t0: ch = EntryToken
          t15: v4i16 = AArch64ISD::MOVIshift Constant:i32<16>, Constant:i32<0>
        t16: v2f32 = AArch64ISD::NVCAST t15
          t3: v2i32 = BUILD_VECTOR Constant:i32<0>, Constant:i32<0>
        t5: v2f32 = llvm.aarch64.neon.vcvtfxs2fp TargetConstant:i64<626>, t3, Constant:i32<24>
      t8: v4f32 = concat_vectors t16, t5
    t9: v2i64 = bitcast t8
  t11: ch,glue = CopyToReg t0, Register:v2i64 $q0, t9
  t12: ch = AArch64ISD::RET_FLAG t11, Register:v2i64 $q0, t11:1
  ```

Here is a godbolt with the original C++ code that triggered the crash:
https://godbolt.org/z/noEz8TrMo

I tested this on Windows using latest trunk (1dda6ad80c1256c280a2c0b9d0104422eb2fcdac) and it's still present.

For context, this crash was found using a fuzzer. It was not in manually written code.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy1Vttu4zYQ_Rr5hYghURfLD35wfGkDJA3gdRO0LwIl0hJ3adIlqTjJ1--QkuNLku0u0AaORGo4M4czZ4YsFX2ZPDZMokptd1xwWSPbMLRRQqi9m92sQEQZao2bBVkoRIWutlbznWBBPCdEV02WXEklmX-gq3v4HMHKIJ4G4TwIp27c_bppfI2WrawsVxJNrdUGVqJta-xOq1ozY5BUG80YvMyLrODVSgBDkWaEeh97LoRmttUStXtLSoDiTVO24SCmRhVCVUR4VfiIgniWoGe0EYrYIF6gIAmLv3OqCmPbzeYpwHmAx8jrFK2UZMtoQSjVKMBxiILRdWcfwTyNwNocwUrhzOILs0I8bYd9VIaSKTl8qp7s5tngzW74hDcxhiePsXPZabsJ6L4yrbjklhPBYRzgmZOgCICdOMfeuWkAtWBPrLJKv0cRz_wYhc_xaBGGYRQe_pzVT2XxwonfWYMd99-TI1qYOXThCcxugA-D2NnrgUOu3qcANtMTYjTvBz_PDxf-klTffoEqB4pUgmj2X6au37FjENAl-pD0rqq6GmMaVZqYhhnAZht0tvVzpdvbhzu0WK3uVy4CMyKlssgwAWl3H8LnNK3GGQ6rlGBXbsiD9AyZTv02br7MXRnG0z8eZtMv61OVcZkf0nPx1RlKeJR9aOju_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