Skip to content

Codegen regression in Ipv6Addr [u16; 8] to [u8; 16] conversion #122805

Closed
@paolobarbolini

Description

@paolobarbolini

Code

I tried this code:

// Taken from `Ipv6Addr::new`

pub fn convert1(value: [u16; 8]) -> [u8; 16] {
    let addr16 = [
        value[0].to_be(),
        value[1].to_be(),
        value[2].to_be(),
        value[3].to_be(),
        value[4].to_be(),
        value[5].to_be(),
        value[6].to_be(),
        value[7].to_be(),
    ];
    unsafe { std::mem::transmute::<_, [u8; 16]>(addr16) }
}

pub fn convert2(value: [u16; 8]) -> [u8; 16] {
    let addr16 = value.map(|val| val.to_be());
    unsafe { std::mem::transmute::<_, [u8; 16]>(addr16) }
}

I expected to see this happen: these two pieces of code produced the same assembly

Instead, this happened: the first version generates worse code https://rust.godbolt.org/z/qrz7Pn1a7

Version it worked on

It most recently worked on: 1.76

Version with regression

rustc --version --verbose:

rustc 1.78.0-beta.1 (efd9d2df1 2024-03-18)
binary: rustc
commit-hash: efd9d2df12b5e17fac0b4d0fb89f612ecd79f259
commit-date: 2024-03-18
host: x86_64-unknown-linux-gnu
release: 1.78.0-beta.1
LLVM version: 18.1.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationC-bugCategory: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.P-mediumMedium priorityllvm-fixed-upstreamIssue expected to be fixed by the next major LLVM upgrade, or backported fixesregression-untriagedUntriaged performance or correctness regression.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions