Open
Description
I tried this code:
pub fn parse_u32_digit(acc: u32, byte: u8) -> Option<u32> {
match (acc.checked_mul(10), byte.checked_sub(b'0')) {
(Some(next), Some(v @ 0..=9)) => next.checked_add(v as u32),
_ => None,
}
}
I expected to see this happen: assembly that looks something like this:
parse_u32_digit:
mov eax, edi
xor ecx, ecx
mov edx, 10
mul edx
jo .LBB0_1
mov edx, eax
lea eax, [rsi - 58]
cmp al, -10
jb .LBB0_4
add sil, -48
movzx eax, sil
xor ecx, ecx
add edx, eax
setae cl
.LBB0_1:
.LBB0_4:
mov eax, ecx
ret
Instead, this happened: the following assembly:
parse_u32_digit:
mov eax, edi
xor ecx, ecx
mov edx, 10
mul edx
jo .LBB0_1
mov edx, eax
lea eax, [rsi - 58]
cmp al, -10
jb .LBB0_4
add sil, -48
movzx eax, sil
xor ecx, ecx
add edx, eax
setae cl
jmp .LBB0_4
.LBB0_1:
.LBB0_4:
mov eax, ecx
ret
Meta
rustc --version --verbose
:
rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-unknown-linux-gnu
release: 1.79.0
LLVM version: 18.1.7
Compiler returned: 0
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generationCategory: An issue highlighting optimization opportunities or PRs implementing suchIssue: Problems and improvements with respect to binary size of generated code.Relevant to the compiler team, which will review and decide on the PR/issue.