Closed as duplicate of#122734
Description
This is similar to #49892, but different.
It's not limited to non-zero integer types. This happens for any types that have holes but no uninitialized bits.
I think comparing Option<some fieldless enum>
values is not uncommon, so it adds to the severity of the issue.
To reproduce
- Create the following program:
pub fn eq(x: Option<bool>, y: Option<bool>) -> bool { x == y }
- Inspect generated code, for example by running
Or just visit godbolt.
cargo rustc --release --lib -- --emit asm -Cllvm-args=--x86-asm-syntax=intel
Expected result
eq:
cmp dil, sil
sete al
ret
Actual result
eq:
cmp dil, 2
sete al
cmp sil, 2
setne cl
cmp al, cl
je .LBB0_1
mov al, 1
cmp dil, 2
je .LBB0_5
cmp sil, 2
je .LBB0_5
test dil, dil
sete cl
test sil, sil
setne al
xor al, cl
.LBB0_5:
ret
.LBB0_1:
xor eax, eax
ret
Meta
This happens both on 1.43.0 stable and on the recent nightly:
> rustc --version --verbose
rustc 1.45.0-nightly (8970e8bcf 2020-05-23)
binary: rustc
commit-hash: 8970e8bcf6153d1ead2283f1a0ed7b192230eca6
commit-date: 2020-05-23
host: x86_64-pc-windows-msvc
release: 1.45.0-nightly
LLVM version: 10.0
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Category: An issue proposing an enhancement or a PR with one.Category: An issue highlighting optimization opportunities or PRs implementing suchIssue: Problems and improvements with respect to performance of generated code.Relevant to the compiler team, which will review and decide on the PR/issue.Issue expected to be fixed by the next major LLVM upgrade, or backported fixes