Skip to content

codegen regression for bool #101048

Closed
@Nugine

Description

@Nugine

Code

I tried this code:

https://rust.godbolt.org/z/3EW6zoffE

pub fn all_zero(data: &[u64]) -> bool {
    data.iter().copied().fold(true, |acc, x| acc & (x == 0))
}

I expected to see this happen:

.LBB0_3:
        cmp     qword ptr [rdi + rcx], 0
        sete    dl
        and     al, dl
        add     rcx, 8
        cmp     rsi, rcx
        jne     .LBB0_3

Instead, this happened:

.LBB0_3:
        test    al, al
        setne   dl
        cmp     qword ptr [rdi + rcx], 0
        sete    al
        and     al, dl
        add     rcx, 8
        cmp     rsi, rcx
        jne     .LBB0_3

There are two unnecessary instructions:

        test    al, al
        setne   dl

Version it worked on

It most recently worked on: Rust 1.63, Rust beta

Version with regression

rustc --version --verbose:

rustc 1.65.0-nightly (748038961 2022-08-25)
binary: rustc
commit-hash: 7480389611f9d04bd34adf41a2b3029be4eb815e
commit-date: 2022-08-25
host: x86_64-unknown-linux-gnu
release: 1.65.0-nightly
LLVM version: 15.0.0

@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged

Metadata

Metadata

Assignees

Labels

A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-slowIssue: Problems and improvements with respect to performance of generated code.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions