Expressions like `a + b > a ? a : a + b` can reuse the overflow flag from `a + b` to avoid a second comparison.
[C++ examples](https://godbolt.org/z/W5Yjq5rGT)
[Alive proofs](https://alive2.llvm.org/ce/z/ft4Yar)
```asm
; AArch64
src_umax_add:
add w8, w1, w0
cmp w0, w8
csel w0, w0, w8, hi
ret
tgt_umax_add:
adds w8, w0, w1
csel w0, w0, w8, hs
ret
```
```asm
; x86-64
src_umax_add:
lea eax, [rsi + rdi]
cmp edi, eax
cmova eax, edi
ret
tgt_umax_add:
mov eax, esi
add eax, edi
cmovb eax, edi
ret
```
Expressions like `a + b > a ? a : a + b` can reuse the overflow flag from `a + b` to avoid a second comparison.
[C++ examples](https://godbolt.org/z/W5Yjq5rGT)
[Alive proofs](https://alive2.llvm.org/ce/z/ft4Yar)
```asm
; AArch64
src_umax_add:
add w8, w1, w0
cmp w0, w8
csel w0, w0, w8, hi
ret
tgt_umax_add:
adds w8, w0, w1
csel w0, w0, w8, hs
ret
```
```asm
; x86-64
src_umax_add:
lea eax, [rsi + rdi]
cmp edi, eax
cmova eax, edi
ret
tgt_umax_add:
mov eax, esi
add eax, edi
cmovb eax, edi
ret
```
Expressions like
a + b > a ? a : a + b
can reuse the overflow flag froma + b
to avoid a second comparison.C++ examples Alive proofs