-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
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
Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.