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

    <tr>
        <th>Summary</th>
        <td>
            aarch64 unconditionally spills when x86-64 does not
        </td>
    </tr>

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

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

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

<pre>
    Give the following code:
```c++
extern void foo();
struct Vertex {
    float x;
    float y;
    float c;
};

class Foo {
    void write_vertex(float x1, float y1, float c1, float x2, float y2, float c2, float x3, float y3, float c3);
 Vertex *ptr;
};

 int blue;

 void Foo::write_vertex(float x1, float y1, float c1, float x2, float y2, float c2, float x3, float y3, float c3)    {
    Vertex v1 = {x1, y1, c1};
    Vertex v2 = {x2, y2, c2};
    Vertex v3 = {x3, y3, c3};
    if (blue) {
        ptr[0] = v1;
        ptr[1] = v2;
        ptr[3] = v3;
    } else{
 foo();
        ptr[0] = v1;
        ptr[1] = v2;
        ptr[3] = v3;
    }
}
```

The generated x86-64 code only stores to the stack when calling `foo()` however the aarch64 code always spills:
```
Foo::write_vertex(float, float, float, float, float, float, float, float, float):        // @Foo::write_vertex(float, float, float, float, float, float, float, float, float)
        stp     d15, d14, [sp, #-96]!           // 16-byte Folded Spill
        stp     d13, d12, [sp, #16]             // 16-byte Folded Spill
        stp     d11, d10, [sp, #32]             // 16-byte Folded Spill
        stp     d9, d8, [sp, #48] // 16-byte Folded Spill
        stp     x29, x30, [sp, #64] // 16-byte Folded Spill
        str     x19, [sp, #80] // 8-byte Folded Spill
        add     x29, sp, #64
 fmov    s9, s6
        fmov    s10, s5
        adrp    x8, blue
 fmov    s11, s4
        fmov    s12, s3
        ldr     w8, [x8, :lo12:blue]
        fmov    s13, s2
        fmov    s14, s1
 ldr     s8, [x29, #32]
        fmov    s15, s0
        mov     x19, x0
        cbnz    w8, .LBB0_2
        str     s7, [x29, #28] // 4-byte Folded Spill
        bl      foo()
        ldr     s7, [x29, #28]                  // 4-byte Folded Reload
.LBB0_2:
 ldr     x8, [x19]
        stp     s15, s14, [x8]
        stp     s13, s12, [x8, #8]
        stp     s11, s10, [x8, #16]
        stp     s9, s7, [x8, #36]
        str     s8, [x8, #44]
        ldp     x29, x30, [sp, #64]             // 16-byte Folded Reload
        ldr     x19, [sp, #80]                  // 8-byte Folded Reload
        ldp     d9, d8, [sp, #48]               // 16-byte Folded Reload
        ldp     d11, d10, [sp, #32]             // 16-byte Folded Reload
        ldp     d13, d12, [sp, #16]             // 16-byte Folded Reload
        ldp     d15, d14, [sp], #96             // 16-byte Folded Reload
        ret
blue:
 .word   0                
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEV0-PozYU_zTOxZrIfgYCBw5Jo_TSU1v1ujLGSdh6cISdhOynr7CBAAnZ2U61RdHi9fv59_768YYbUxxKKVMUblC4XfCzPeoq_Vq9n4tvUi0ynd_SX4uLxPYo8V4rpa9FecBC5xKxNSJbRNYoIv4nEGyan9uVtZVViS-6yPFeawQxggSxVmpsdRYW_yUrK2uMVu02xhjvleYW1z30vnd7sif6PbTa3tfuX6G4MXin9ViBM-laFVZ-uTj9COJWKUXwS6dssBaDdQ0DzGAtBuuaDTCDtWDDGPTew_pkqxd-4KK0OFNnOd13nuy0blLB1v-fS01URyFuPbtQjNi2EXkzvAGCDl0cwqGHO83eFgFzcNbDnUHeLMGm8GKPEcQufpCM7WyeJvbhhqBw6-gudHT4jqA9AmYQrEewEQKttlgqI--qHy_ET7XmXmjjCzwsrj-PEh9kKStuZY7rOHqLAnfvsS7VDRurK2mw1a4zGMvF3_h6lCUWXKmmRaCI3L2MCD7qq7zIysE5r8Sxo-Pqym8Gm1OhlHlsKv6_L4u8r8ZPLxLE-igi2CHYYRSQn6Z8lEVjT-6d07AB5TRoXijcmJNbAHtLIhRuEVB8f1qrafSW3azEO61ymeM_muDO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