Open
Description
I tried this code:
fn f(a: u32, b: bool, c: bool, d: &mut [u128; 2]) {
let mut a = a & 1 != 0;
if b {
a ^= c;
d[0] |= 1;
}
d[a as usize] |= 1;
}
It compiles to the following assembly:
f:
test esi, esi
je .LBB0_1
xor dil, dl
or byte ptr [rcx], 1
jmp .LBB0_3
.LBB0_1:
and dil, 1
.LBB0_3:
movzx eax, dil
and eax, 1
shl eax, 4
or byte ptr [rcx + rax], 1
ret
The jmp .LBB0_3
and and dil, 1
instructions are useless, because dil
is moved to eax
and and
ed with 1
there anyway, and dil
is not used anywhere.
The output improves if you avoid using bool
s.
Meta
rustc --version --verbose
:
rustc 1.79.0-nightly (c9f8f3438 2024-03-27)
binary: rustc
commit-hash: c9f8f3438a8134a413aa5d4903e0196e44e37bbc
commit-date: 2024-03-27
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2
Compiler returned: 0
@rustbot modify labels: -C-bug +C-optimization +A-codegen +A-LLVM +I-slow +I-heavy
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 suchCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Issue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to performance of generated code.Relevant to the compiler team, which will review and decide on the PR/issue.