Skip to content

[MIR] when should we not deaggregate? #35259

@scottcarr

Description

@scottcarr
Contributor

#35168 adds the capability of deaggregating structs like:

tmp0 = ...;
tmp1 = ...;
tmp2 = Foo { a: ..., b: ... };

Into:

tmp2.0 = ...
tmp2.1 = ...

But, one could imagine situations where this is counter productive.

It's not clear if this should be handled by the Deaggregator or MIR trans.

Activity

added
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html
on Aug 3, 2016
nagisa

nagisa commented on Aug 4, 2016

@nagisa
Member

I can’t think of a trivial way to reverse deaggregation, especially after multiple optimisation passes go through the MIR.

The newtype concern raised by Ariel could be easily handled by replacing

tmpx: Newtype(T1, T2, ...);
tmpx.0 = ...;
tmpx.1 = ...;

with

tmpx_1: T1;
tmpx_2: T2; 
tmpx_1 = ...;
tmpx_2 = ...;

(This is probably the same thing as SRoA, which @eddyb mentioned) This likely would allow us to discard some of the Pair stuff in the translator as well, but would need a good heuristic to not become a pessimisation itself.

nagisa

nagisa commented on Aug 4, 2016

@nagisa
Member

That being said, I feel like LLVM should be more than capable to handle such case quite quickly by itself.

eddyb

eddyb commented on Aug 4, 2016

@eddyb
Member

@nagisa There's 2 reasons SRoA isn't enough to replace Pair: fat pointers use Pair and CheckedBinOp produces one. And yes, LLVM can handle most of these by itself anyway.

Newtypes (including those with extra ZST fields) are more relevant because of "zero-cost abstractions".

Aatch

Aatch commented on Aug 4, 2016

@Aatch
Contributor

@nagisa I think the issue is about not deaggregating in some cases, rather than trying to reverse it.

added
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
on Jul 25, 2017
eddyb

eddyb commented on Feb 7, 2018

@eddyb
Member

I have a prototype of optimizing through fields of locals and it's much more straight-forward to do it after deaggregation than trying to understand the creation of aggregates as a whole.
Feel free to reopen this if anything changes, but we're more likely to remove Aggregate from MIR.
(which we can do in a borrowck-friendly way via SetDiscriminant(x, 0) on all aggregates)

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Apr 5, 2023
bjorn3

bjorn3 commented on Jul 15, 2023

@bjorn3
Member

#107267 fixed this, right?

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-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-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

        @eddyb@oli-obk@Aatch@scottcarr@nagisa

        Issue actions

          [MIR] when should we not deaggregate? · Issue #35259 · rust-lang/rust