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

    <tr>
        <th>Summary</th>
        <td>
            clang generates different code when targeting Windows and Linux on Arm64
        </td>
    </tr>

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

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

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

<pre>
    The code generation difference can be seen using this simple program below. 

```
#include <arm_neon.h>

struct vfloat4
{
  inline vfloat4() = default;

  inline explicit vfloat4(float a)
 {
  m = vdupq_n_f32(a);
 }

  inline explicit vfloat4(float32x4_t a)
 {
  m = a;
 }

 float32x4_t m;
};

struct vint4
{
 inline vint4() = default;

  inline explicit vint4(int a)
 {
  m = vdupq_n_s32(a);
 }

  inline explicit vint4(int32x4_t a)
 {
 m = a;
 }

 int32x4_t m;
};

vint4 float_as_int(vfloat4 a)
{
 return vint4(vreinterpretq_s32_f32(a.m));
}
```

With -O2   --target=aarch64-none-windows, the code gen is
```
"?float_as_int@@YA?AUvint4@@Uvfloat4@@@Z": // @"?float_as_int@@YA?AUvint4@@Uvfloat4@@@Z"
        str     q0, [x0]
 ret
```

The corresponding bitcode for the function is below. Note that it returns void, which means that the compiler doesn't treat vint4 as a vector.
```
; Function Attrs: mustprogress noinline optnone uwtable
define dso_local void @"?float_as_int@@YA?AUvint4@@Uvfloat4@@@Z"(ptr inreg noalias sret(%struct.vint4) align 16 %0, [1 x <4 x float>] %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca %struct.vfloat4, align 16
  store ptr %0, ptr %3, align 8
  %5 = getelementptr inbounds %struct.vfloat4, ptr %4, i32 0, i32 0
  store [1 x <4 x float>] %1, ptr %5, align 16
  %6 = getelementptr inbounds %struct.vfloat4, ptr %4, i32 0, i32 0
  %7 = load <4 x float>, ptr %6, align 16
  %8 = call noundef <4 x i32> @"?vreinterpretq_s32_f32@@YA?AT?$__vector@H$03@__clang@@T?$__vector@M$03@2@@Z"(<4 x float> noundef %7)
  %9 = call noundef ptr @"??0vint4@@QEAA@T?$__vector@H$03@__clang@@@Z"(ptr noundef nonnull align 16 dereferenceable(16) %0, <4 x i32> noundef %8)
  ret void
}
```

while with -O2   --target=aarch64-none-linux, the code is instead
```
float_as_int(vfloat4):               // @float_as_int(vfloat4)
        ret
```

And the corresponding bitcode for the function is the following, which returns %struct.vint4 %8.

```
define dso_local %struct.vint4 @_Z12float_as_int7vfloat4([1 x <4 x float>] %0) #0 {
  %2 = alloca %struct.vint4, align 16
  %3 = alloca %struct.vfloat4, align 16
  %4 = getelementptr inbounds %struct.vfloat4, ptr %3, i32 0, i32 0
  store [1 x <4 x float>] %0, ptr %4, align 16
  %5 = getelementptr inbounds %struct.vfloat4, ptr %3, i32 0, i32 0
  %6 = load <4 x float>, ptr %5, align 16
  %7 = call noundef <4 x i32> @_ZL21vreinterpretq_s32_f3213__Float32x4_t(<4 x float> noundef %6)
 call void @_ZN5vint4C2E11__Int32x4_t(ptr noundef nonnull align 16 dereferenceable(16) %2, <4 x i32> noundef %7)
  %8 = load %struct.vint4, ptr %2, align 16
  ret %struct.vint4 %8
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0l99v4joWx_8a83JUlNgJhAceaCnalWZntdKMRtuXyCQH8JVjM7ZTev_7KzsJSUugnc69VQUJ8fn1tc_HDrdW7BXikqT3JF1PeO0O2iyrYicmW13-ufx2QCh0ibBHhYY7oRWUYrdDg6pAKLiCLYJFVFBbofbgDsKCFdVRIhyN3htewRalPk2BRGsSrdrPWdT-N7eUCVXIukQg7IGbKleo1fRA2OPQyjpTFw6ed1Jzl7RP5vfNBYBQUig8P6YZoQsgbA0l7ngtHWH3Q29nA3w5SlEIN7AMF8AJXbRjB2Gq4PO5rI8_c5XvGCU0CyM790Dm618KxOhLkt8Ox697H7qo-hrn6zf1duoJdaldJ1149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