-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[mir-opt] Allow SRoA when an object is transmuted to a field type #158291
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 all commits
Commits
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
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 |
|---|---|---|
|
|
@@ -4,13 +4,13 @@ fn unaligned_copy_generic(_1: *const T, _2: *mut T) -> () { | |
| debug src => _1; | ||
| debug dst => _2; | ||
| let mut _0: (); | ||
| let _5: T; | ||
| let _4: T; | ||
| scope 1 { | ||
| debug val => _5; | ||
| debug val => _4; | ||
| scope 8 (inlined #[track_caller] write_unaligned::<T>) { | ||
| let _6: *mut std::ptr::Packed<T>; | ||
| let _5: *mut std::ptr::Packed<T>; | ||
| scope 9 { | ||
| let _7: std::ptr::Packed<T>; | ||
| let _6: std::ptr::Packed<T>; | ||
| scope 10 { | ||
| scope 12 (inlined #[track_caller] std::ptr::write::<std::ptr::Packed<T>>) { | ||
| } | ||
|
|
@@ -23,7 +23,6 @@ fn unaligned_copy_generic(_1: *const T, _2: *mut T) -> () { | |
| scope 2 (inlined #[track_caller] read_unaligned::<T>) { | ||
| let _3: *const std::ptr::Packed<T>; | ||
| scope 3 { | ||
| let _4: std::ptr::Packed<T>; | ||
| scope 4 { | ||
| scope 7 (inlined transmute_neo::<std::ptr::Packed<T>, T>) { | ||
| } | ||
|
|
@@ -36,22 +35,19 @@ fn unaligned_copy_generic(_1: *const T, _2: *mut T) -> () { | |
| } | ||
|
|
||
| bb0: { | ||
| StorageLive(_5); | ||
| StorageLive(_4); | ||
| StorageLive(_3); | ||
| _3 = copy _1 as *const std::ptr::Packed<T> (PtrToPtr); | ||
| StorageLive(_4); | ||
| _4 = copy (*_3); | ||
| _5 = copy _4 as T (Transmute); | ||
| StorageDead(_4); | ||
| _4 = copy ((*_3).0: T); | ||
|
Comment on lines
-42
to
+41
Member
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. The library change to use |
||
| StorageDead(_3); | ||
| StorageLive(_5); | ||
| _5 = copy _2 as *mut std::ptr::Packed<T> (PtrToPtr); | ||
| StorageLive(_6); | ||
| _6 = copy _2 as *mut std::ptr::Packed<T> (PtrToPtr); | ||
| StorageLive(_7); | ||
| _7 = std::ptr::Packed::<T>(copy _5); | ||
| (*_6) = copy _7; | ||
| StorageDead(_7); | ||
| _6 = std::ptr::Packed::<T>(copy _4); | ||
| (*_5) = copy _6; | ||
| StorageDead(_6); | ||
| StorageDead(_5); | ||
| StorageDead(_4); | ||
| return; | ||
| } | ||
| } | ||
59 changes: 59 additions & 0 deletions
59
tests/mir-opt/sroa/read_packed.read_unaligned.ScalarReplacementOfAggregates.diff
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,59 @@ | ||
| - // MIR for `read_unaligned` before ScalarReplacementOfAggregates | ||
| + // MIR for `read_unaligned` after ScalarReplacementOfAggregates | ||
|
|
||
| fn read_unaligned(_1: *const T) -> T { | ||
| debug ptr => _1; | ||
| let mut _0: T; | ||
| let _2: *const Packed<T>; | ||
| let mut _3: *const Packed<T>; | ||
| let mut _4: *const T; | ||
| let mut _6: *const Packed<T>; | ||
| let mut _7: Packed<T>; | ||
| + let mut _8: T; | ||
| scope 1 { | ||
| debug packed_ptr => _2; | ||
| let _5: Packed<T>; | ||
| + let _9: T; | ||
| scope 2 { | ||
| - debug packed_val => _5; | ||
| + debug ((packed_val: Packed<T>).0: T) => _9; | ||
| } | ||
| } | ||
|
|
||
| bb0: { | ||
| StorageLive(_2); | ||
| StorageLive(_3); | ||
| StorageLive(_4); | ||
| _4 = copy _1; | ||
| _3 = move _4 as *const Packed<T> (PtrToPtr); | ||
| _2 = copy _3; | ||
| StorageDead(_4); | ||
| StorageDead(_3); | ||
| - StorageLive(_5); | ||
| + StorageLive(_9); | ||
| + nop; | ||
| StorageLive(_6); | ||
| _6 = copy _2; | ||
| - _5 = copy (*_6); | ||
| + _9 = copy ((*_6).0: T); | ||
| + nop; | ||
| StorageDead(_6); | ||
| - StorageLive(_7); | ||
| - _7 = move _5; | ||
| - _0 = move _7 as T (Transmute); | ||
| - StorageDead(_7); | ||
| - StorageDead(_5); | ||
| + StorageLive(_8); | ||
| + nop; | ||
| + _8 = move _9; | ||
| + nop; | ||
| + _0 = move _8; | ||
| + StorageDead(_8); | ||
| + nop; | ||
| + StorageDead(_9); | ||
| + nop; | ||
| StorageDead(_2); | ||
| 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,26 @@ | ||
| //@ test-mir-pass: ScalarReplacementOfAggregates | ||
| //@ compile-flags: -Cpanic=abort | ||
| //@ no-prefer-dynamic | ||
|
|
||
| #![crate_type = "lib"] | ||
| #![feature(core_intrinsics)] | ||
|
|
||
| use std::intrinsics::{read_via_copy, transmute_unchecked}; | ||
|
|
||
| #[repr(packed)] | ||
| struct Packed<T>(T); | ||
|
|
||
| // EMIT_MIR read_packed.read_unaligned.ScalarReplacementOfAggregates.diff | ||
| pub const unsafe fn read_unaligned<T>(ptr: *const T) -> T { | ||
| // CHECK-LABEL: fn read_unaligned(_1: *const T) -> T | ||
| // CHECK: debug packed_ptr => [[PPTR:_.+]]; | ||
| // CHECK: debug ((packed_val: Packed<T>).0: T) => [[VAL:_.+]]; | ||
| // CHECK: [[TEMP:_.+]] = copy [[PPTR]]; | ||
| // CHECK: [[VAL]] = copy ((*{{_.+}}).0: T); | ||
| unsafe { | ||
| let packed_ptr = ptr as *const Packed<T>; | ||
| let packed_val = read_via_copy(packed_ptr); | ||
| // transmute because you can't destructure it in a `const fn` | ||
| transmute_unchecked(packed_val) | ||
| } | ||
| } |
Oops, something went wrong.
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.
...which then means these loads get metadata on them without codegen changes.
View changes since the review