Skip to content

Consider using pair mode to return scalar pair bools as i1 #52198

Open
@cuviper

Description

@cuviper
Member

Starting in #51583, we're representing scalar pair bools as i8 in LLVM aggregates to match their memory storage, whereas they are i1 as immediate values.

When a pair is the argument to a function, we use PassMode::Pair and pass each part like independent immediate values. We don't use that mode for return values though, so a paired bool will be extended to i8 for return, then truncated back to i1 when the caller unpacks it.

Quoting @eddyb in #51583 (comment):

I wonder if they should be using the pair "passing mode" that arguments do, and create a LLVM aggregate type on the fly, using the immediate types for the pair components. That way we'd get {i1, i1} for returns, but everything else would see {i8, i8}.

Not sure it's worth the complexity though. When inlining, LLVM should collapse the zext followed by trunc, just like it gets rid of packing into a pair and unpacking it.

Activity

added
A-codegenArea: Code generation
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Jul 10, 2018
eddyb

eddyb commented on Jul 13, 2018

@eddyb
Member

I think that for compatibility with backends that support "true multiple return" (i.e. Cranelift), we should be using PassMode::Pair for returns as well, with more explicit packing. cc @sunfishcode

sunfishcode

sunfishcode commented on Jul 13, 2018

@sunfishcode
Member

That sounds right to me. Even in LLVM, an aggregate return type in LLVM is essentially LLVM's convention for multiple return values, so it sounds desirable to use i1 there too.

added
A-craneliftThings relevant to the [future] cranelift backend
on Mar 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationA-craneliftThings relevant to the [future] cranelift backendT-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

        Participants

        @cuviper@eddyb@Centril@sunfishcode

        Issue actions

          Consider using pair mode to return scalar pair bools as i1 · Issue #52198 · rust-lang/rust