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

    <tr>
        <th>Summary</th>
        <td>
            [aarch64] bitcasting between small vectors and integers always spills to the stack.
        </td>
    </tr>

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

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

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

<pre>
    I tried this code:
```ll
define <2 x i16> @from_int(i32 %word) {
 %ret = bitcast i32 %word to <2 x i16>
    ret <2 x i16> %ret
}

define i32 @to_int(<2 x i16> %vec) {
    %ret = bitcast <2 x i16> %vec to i32
    ret i32 %ret
}
```

I expected to see something similar to this:

```asm
from_int:
        fmov s0, w0
        ret

to_int:
        fmov w0, s0
 ret
```

But LLVM currently generates this:

```asm
from_int:
        sub     sp, sp, #16
 add     x8, sp, #12
        str     w0, [sp, #12]
        ld1     { v0.h }[0], [x8]
        orr     x8, x8, #0x2
        ld1     { v0.h }[2], [x8]
        add     sp, sp, #16
        ret
to_int:
 sub     sp, sp, #16
        mov     w8, v0.s[1]
        fmov    w9, s0
        strh    w9, [sp, #12]
        strh    w8, [sp, #14]
 ldr     w0, [sp, #12]
        add     sp, sp, #16
 ret
```

For 64/128-Bit vectors the codegen matches the expected output.

Interestingly, if you use `<4 x i8>` instead of `<2 x i16>` in the example, `to_int` allocates stack space but never accesses it:
```asm
to_int: 
        sub     sp, sp, #16
        xtn v0.8b, v0.8h
        fmov    w0, s0
        add     sp, sp, #16
 ret
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVUuvqzYQ_jXOZnQiYwOBBYubk0a60u2qUreVgQm4NRjZJo9_X9mQBye59_SoVmQHzzfjbx4eC2tl0yMWJNmSZLcSo2u1Kf4YKB3aVanrS_EdnJFYg2ulhUrXSPg3QneEfiMpnX5KTRs1HmSPQPg7gzP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