Skip to content

Small structs should be passed in registers #6612

Closed
@huonw

Description

@huonw

In the following code, there is an extra layer of indirection in foo in the final code.

pub struct IString(uint);
impl Eq for IString {
    fn eq(&self, other: &IString) -> bool { **self == **other }
    fn ne(&self, other: &IString) -> bool { **self != **other }
}

pub fn foo(a: IString, b: IString) -> bool { a==b }
pub fn bar(a: uint, b: uint) -> bool { a==b }

Compiling with -O -S generates the following (trimmed to the relevant parts):

_ZN3foo17_4341c964988316ba3_00E:
    movq    (%rdx), %rax
    cmpq    (%rcx), %rax
    sete    %al
    popq    %rbp
    ret

_ZN3bar16_df80e259bc1a8923_00E:
    cmpq    %rcx, %rdx
    sete    %al
    popq    %rbp
    ret

i.e. the IStrings are passed as pointers, not directly in registers.

(I'm on x64 linux.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions