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

    <tr>
        <th>Summary</th>
        <td>
            arithmetic miscompile from AArch64 backend
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:AArch64,
            llvm:codegen,
            miscompilation
      </td>
    </tr>

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

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

<pre>
    this function: 
```llvm
declare void @mumble(i32)

define i32 @f(i32 %0) {
  %2 = sub nuw i32 0, %0
  call void @mumble(i32 %2)
  %3 = sub i32 1, %0
  %4 = sub i32 3, %0
  %5 = mul i32 %0, 1
  %6 = add i32 %3, %5
  %7 = add i32 %6, %4
  ret i32 %7
}
```
is getting lowered to always return 4:
```
_f: 
        stp     x29, x30, [sp, #-16]!       
        .cfi_def_cfa_offset 16
        .cfi_offset w30, -8
        .cfi_offset w29, -16
        mov     w0, wzr
        bl      _mumble
        mov     w0, #4             
        ldp     x29, x30, [sp], #16        
        ret
```
but that's not right. for example, `f(9)` should give `-5`

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0lN-OqzgMxp_G3FitggNpueCiM1VfowokgewGUiWhnbNPv-LP9PTMdlGlCvv3fXYSExmj7Uatayg_oDxnckq9D3XQne5D1nj1q069jWimsU3Wj8BPCOwM7ASCrT_n7sMaUrp1Mmi8e6sQCjZMQ-M00NFyAqo23YYaO2q0nGbQrAwClQyoQjh8rBjOIULgZ4xTg-P0WCQM6HOFN6qVzr0tu-iftRc7_rSb8_lPK6Cy-IPgb4hyIYbJ4e-2PzF_IcRCSKW-iW-b8gU6_ITEBhXfUNDpO3fY9u9w_nEA66uN2OmU7Nih8w8dtMLkUbqH_BVnmymMWAA_vRVfzcvBsiqmG7Dqi6q5nS--bnf5EW9re3yXCyjPQDmuz1O4b429Km2urZFXb0zUCXPxZ3oLP1bb3fF9dq29exEP_g6seiyqxz_hGW8csOq6Hfo7GIgX-Po8Kaf-b53z6hZlLv6jCjq93cRmSph6mYAOEUefMNiuT3s0PqD-ksNtHspPBLHMezVPpWAYez85hZ296zm1K59-maq5qnglM13nh7xiOSNxzPo6l5IxUzVtJY1uRMvz8ngoK66b_Hg8mGNma2JUMEE5UZmz474krrRplFFkStFKKJgepHX7-ePd-9BlNsZJ15XgQmRONtrF5UogamT7tx4V8NPpFNpeFEAE9AlEy4fPT61XutPjMzzY2PrhZp1cLgyi-V4J9UzvmqmLUDBnY4q_ayebnK5lsKkfdLItPi00muAH3Crj1ks2BVf3Kd3iPM90Abp0NvVTs2_9AHRZGlv_drfg_9JtArosK4xAl3WR95r-DQAA__-Ww1kg">