Skip to content

#![feature(unchecked_math)] emits slow asm  #91449

Closed
@JakobDegen

Description

@JakobDegen

This code

#![feature(unchecked_math)]

pub fn sub(x: &u8) -> usize {
    unsafe { x.unchecked_sub(10) as usize }
}

currently emits

example::sub:
        mov     al, byte ptr [rdi]
        add     al, -10
        movzx   eax, al
        ret

which should instead be

example::sub2:
        movzx   eax, byte ptr [rdi]
        add     rax, -10
        ret

I unfortunately do not have the background to check whether its rustc or LLVM that's the cause of the issue; I'd be happy to file a bug against LLVM if it is on that side, but would need some pointers on how best to produce a useful bug report.

cc #85122

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationC-enhancementCategory: An issue proposing an enhancement or a PR with one.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