Skip to content

Missing optimization when transmuting enums #109958

Closed
@Jarcho

Description

@Jarcho

Transmuting a fieldless enum to it's integer type causes the optimizer to lose track of it's possible values. Note that as casts are optimized correctly.

Example:

#[repr(u32)]
enum E { X = 0 }
fn f(x: E) {
    assert_eq!(unsafe { core::mem::transmute::<E, i32>(x) }, 0); // Not optimized out
    assert_eq!(x as i32, 0); // optimized out
}

cc Lokathor/bytemuck#175

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions