Closed
Description
Godbolt link: https://godbolt.org/z/9rm4jF
So I expect these two functions has the same assembly:
pub fn foo(a: i32, b: i32) -> i32 {
a.saturating_add(b)
}
pub fn bar(a: i32, b: i32) -> i32 {
match a.checked_add(b) {
Some(v) => v,
None => i32::max_value(),
}
}
But the result is not:
example::foo:
xor eax, eax
mov ecx, edi
add ecx, esi
setns al
add eax, 2147483647
add edi, esi
cmovno eax, edi
ret
example::bar:
add edi, esi
mov eax, 2147483647
cmovno eax, edi
ret