Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constprop can create aggregates that won't get deaggregated anymore #75481

Closed
bjorn3 opened this issue Aug 13, 2020 · 5 comments · Fixed by #75562
Closed

Constprop can create aggregates that won't get deaggregated anymore #75481

bjorn3 opened this issue Aug 13, 2020 · 5 comments · Fixed by #75562
Labels
A-cranelift Things relevant to the [future] cranelift backend A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html A-mir-opt Area: MIR optimizations C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bjorn3
Copy link
Member

bjorn3 commented Aug 13, 2020

Before #73656 the deaggregator ran after aggregates. Now it doesn't anymore, breaking cg_clif.

static mut NUM: i32 = 0;

fn store_42() {
    unsafe {
        NUM = 6 * 7;
    }
}
// WARNING: This output format is intended for human consumers only
// and is subject to change without notice. Knock yourself out.
fn store_42() -> () {
    let mut _0: ();                      // return place in scope 0 at src/lib.rs:3:15: 3:15
    let mut _1: (i32, bool);             // in scope 0 at src/lib.rs:5:15: 5:20
    let mut _2: *mut i32;                // in scope 0 at src/lib.rs:5:9: 5:12
    scope 1 {
    }

    bb0: {
        _1 = (const 42_i32, const false); // scope 1 at src/lib.rs:5:15: 5:20
                                         // ty::Const
                                         // + ty: i32
                                         // + val: Value(Scalar(0x0000002a))
                                         // mir::Constant
                                         // + span: src/lib.rs:5:15: 5:20
                                         // + literal: Const { ty: i32, val: Value(Scalar(0x0000002a)) }
                                         // ty::Const
                                         // + ty: bool
                                         // + val: Value(Scalar(0x00))
                                         // mir::Constant
                                         // + span: src/lib.rs:5:15: 5:20
                                         // + literal: Const { ty: bool, val: Value(Scalar(0x00)) }
        StorageLive(_2);                 // scope 1 at src/lib.rs:5:9: 5:12
        _2 = const {alloc0: *mut i32};   // scope 1 at src/lib.rs:5:9: 5:12
                                         // ty::Const
                                         // + ty: *mut i32
                                         // + val: Value(Scalar(alloc0))
                                         // mir::Constant
                                         // + span: src/lib.rs:5:9: 5:12
                                         // + literal: Const { ty: *mut i32, val: Value(Scalar(alloc0)) }
        (*_2) = move (_1.0: i32);        // scope 1 at src/lib.rs:5:9: 5:20
        StorageDead(_2);                 // scope 1 at src/lib.rs:5:20: 5:21
        _0 = const ();                   // scope 1 at src/lib.rs:4:5: 6:6
                                         // ty::Const
                                         // + ty: ()
                                         // + val: Value(Scalar(<ZST>))
                                         // mir::Constant
                                         // + span: src/lib.rs:4:5: 6:6
                                         // + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
        return;                          // scope 0 at src/lib.rs:7:2: 7:2
    }
}

alloc0 (static: NUM, size: 4, align: 4) {
    00 00 00 00                                     │ ....
}

static mut NUM: i32 = {
    let mut _0: i32;                     // return place in scope 0 at src/lib.rs:1:17: 1:20

    bb0: {
        _0 = const 0_i32;                // scope 0 at src/lib.rs:1:23: 1:24
                                         // ty::Const
                                         // + ty: i32
                                         // + val: Value(Scalar(0x00000000))
                                         // mir::Constant
                                         // + span: src/lib.rs:1:23: 1:24
                                         // + literal: Const { ty: i32, val: Value(Scalar(0x00000000)) }
        return;                          // scope 0 at src/lib.rs:1:1: 1:25
    }
}

@rustbot modify labels: +A-mir +A-mir-opt +A-cranelift +C-bug +T-compiler

cc @oli-obk (PR author)

@rustbot rustbot added A-cranelift Things relevant to the [future] cranelift backend A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html A-mir-opt Area: MIR optimizations C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 13, 2020
@oli-obk
Copy link
Contributor

oli-obk commented Aug 13, 2020

Are you talking about _1 = (const 42_i32, const false) not being separate assignments to _1.0 and _1.1?

@bjorn3
Copy link
Member Author

bjorn3 commented Aug 13, 2020

Yes

@oli-obk
Copy link
Contributor

oli-obk commented Aug 13, 2020

oh oops, optimizations should not be producing new Rvalue::Aggregates, maybe we should add this to the mir validator, so after a certain point it would check that there are no Rvalue::Aggregates (cc @RalfJung does that sound like too horrible a thing to do to the validator).

@RalfJung
Copy link
Member

No that sounds totally reasonable. We gave several MIR dialects (like before and after drop elaboration), and formalizing this through an explicit enum would make a lot of sense.

I am just not sure how to best integrate this with our MIR pass system.

@wesleywiser
Copy link
Member

That sounds a bit like MirPhase

pub enum MirPhase {
Build = 0,
Const = 1,
Validated = 2,
DropElab = 3,
Optimized = 4,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cranelift Things relevant to the [future] cranelift backend A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html A-mir-opt Area: MIR optimizations C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants