forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
WIP: Trying to promote const local array using GVN pass #5
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
Closed
Closed
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ff0c6b7
add regression test
tesuji 46a0ead
wip
tesuji 49b77d1
wip
tesuji 2ab8340
set memplace as immutable
tesuji d67fe2d
interpret: use trace to reduce noice
tesuji 9d58e3f
remove redundant condition
tesuji 2505da6
clearer reasoning
tesuji c4d3149
ignore nested arrays
tesuji 54741c0
cache propagated const
tesuji 5ae4fcb
bless
tesuji 5f8d330
add codegen test
tesuji 95c131f
fmt
tesuji 6c0fe34
bless else
tesuji File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| - // MIR for `main` before GVN | ||
| + // MIR for `main` after GVN | ||
|
|
||
| fn main() -> () { | ||
| let mut _0: (); | ||
| let _1: [i32; 32]; | ||
| let mut _4: &[i32; 32]; | ||
| let _5: [i32; 32]; | ||
| scope 1 { | ||
| debug _arr => _1; | ||
| let _2: [i32; 32]; | ||
| scope 2 { | ||
| debug _barr => _2; | ||
| let _3: [i32; 32]; | ||
| let mut _6: &[i32; 32]; | ||
| scope 3 { | ||
| debug _darr => _3; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| bb0: { | ||
| - StorageLive(_1); | ||
| + nop; | ||
| _1 = [const 255_i32, const 105_i32, const 15_i32, const 39_i32, const 62_i32, const 251_i32, const 191_i32, const 178_i32, const 9_i32, const 4_i32, const 56_i32, const 221_i32, const 193_i32, const 164_i32, const 194_i32, const 197_i32, const 6_i32, const 243_i32, const 218_i32, const 171_i32, const 87_i32, const 247_i32, const 104_i32, const 159_i32, const 22_i32, const 157_i32, const 105_i32, const 31_i32, const 96_i32, const 173_i32, const 50_i32, const 1_i32]; | ||
| StorageLive(_2); | ||
| - _2 = [const 255_i32, const 105_i32, const 15_i32, const 39_i32, const 62_i32, const 251_i32, const 191_i32, const 178_i32, const 9_i32, const 4_i32, const 56_i32, const 221_i32, const 193_i32, const 164_i32, const 194_i32, const 197_i32, const 6_i32, const 243_i32, const 218_i32, const 171_i32, const 87_i32, const 247_i32, const 104_i32, const 159_i32, const 22_i32, const 157_i32, const 105_i32, const 31_i32, const 96_i32, const 173_i32, const 50_i32, const 1_i32]; | ||
| + _2 = _1; | ||
| StorageLive(_3); | ||
| StorageLive(_4); | ||
| _6 = const main::promoted[0]; | ||
| _4 = &(*_6); | ||
| - _3 = (*_4); | ||
| + _3 = (*_6); | ||
| StorageDead(_4); | ||
| _0 = const (); | ||
| StorageDead(_3); | ||
| StorageDead(_2); | ||
| - StorageDead(_1); | ||
| + nop; | ||
| return; | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| //@ test-mir-pass: GVN | ||
| #![feature(repr_simd)] | ||
|
|
||
| // #[repr(simd)] | ||
| // struct F32x8([f32; 8]); | ||
|
|
||
| // EMIT_MIR const_array_locals.main.GVN.diff | ||
| // CHECK-LABEL: fn main( | ||
| #[rustfmt::skip] | ||
| pub fn main() { | ||
| // CHECK: let [[array_lit:_.*]]: [i32; 32]; | ||
| // CHECK: debug _arr => [[arr:_.*]]; | ||
|
|
||
| let _arr = [ | ||
| 255, 105, 15, 39, 62, 251, 191, 178, 9, 4, 56, 221, | ||
| 193, 164, 194, 197, 6, 243, 218, 171, 87, 247, 104, | ||
| 159, 22, 157, 105, 31, 96, 173, 50, 1, | ||
| ]; | ||
| let _barr = [ | ||
| 255, 105, 15, 39, 62, 251, 191, 178, 9, 4, 56, 221, | ||
| 193, 164, 194, 197, 6, 243, 218, 171, 87, 247, 104, | ||
| 159, 22, 157, 105, 31, 96, 173, 50, 1, | ||
| ]; | ||
| // let _foo = [ | ||
| // [255, 105, 15, 39, 62, 251, 191, 178, 9, 4, 56, 221], | ||
| // [193, 164, 194, 197, 6, 243, 218, 171, 87, 247, 104, 42], | ||
| // ]; | ||
| let _darr = *&[ | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This returns |
||
| 255, 105, 15, 39, 62, 251, 191, 178, 9, 4, 56, 221, | ||
| 193, 164, 194, 197, 6, 243, 218, 171, 87, 247, 104, | ||
| 159, 22, 157, 105, 31, 96, 173, 50, 1, | ||
| ]; | ||
|
|
||
| // consume([255, 105, 15, 39, 62, 251, 191, 178, 9, 4, 56, 221, | ||
| // 193, 164, 194, 197, 6, 243, 218, 171, 87, 247, 104, | ||
| // 159, 22, 157, 105, 31, 96, 173, 50, 1,]); | ||
|
|
||
| // let _f = F32x8([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]); | ||
|
|
||
| // // ice | ||
| // [[1, 0, 0], [0, 1, 0], [0, 0, 1]]; // 2D array | ||
| } | ||
|
|
||
| // fn consume(_arr: [u16; 32]) { | ||
| // unimplemented!() | ||
| // } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With commits[3], this now returns as a immutable memplace:
Some(OpTy { op: Indirect(MemPlace { ptr: alloc3<imm>, meta: None, misaligned: None }), ty: [i32; 32] }).But in the mir diff, _arr still is not promoted.