-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`PtrMetadata` doesn't care about `*const`/`*mut`/`&`/`&mut`, so GVN away those casts in its argument. This includes updating MIR to allow calling PtrMetadata on references too, not just raw pointers. That means that `[T]::len` can be just `_0 = PtrMetadata(_1)`, for example. # Conflicts: # tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir # tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir
- Loading branch information
Showing
14 changed files
with
319 additions
and
78 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,31 @@ | ||
- // MIR for `array_len` before GVN | ||
+ // MIR for `array_len` after GVN | ||
|
||
fn array_len(_1: &mut [i32; 42]) -> usize { | ||
debug x => _1; | ||
let mut _0: usize; | ||
let _2: &[i32]; | ||
let mut _3: &[i32; 42]; | ||
let mut _4: *const [i32]; | ||
scope 1 { | ||
debug x => _2; | ||
} | ||
|
||
bb0: { | ||
- StorageLive(_2); | ||
+ nop; | ||
StorageLive(_3); | ||
_3 = &(*_1); | ||
_2 = move _3 as &[i32] (PointerCoercion(Unsize)); | ||
StorageDead(_3); | ||
StorageLive(_4); | ||
_4 = &raw const (*_2); | ||
- _0 = PtrMetadata(move _4); | ||
+ _0 = const 42_usize; | ||
StorageDead(_4); | ||
- StorageDead(_2); | ||
+ nop; | ||
return; | ||
} | ||
} | ||
|
This file contains 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,31 @@ | ||
- // MIR for `array_len` before GVN | ||
+ // MIR for `array_len` after GVN | ||
|
||
fn array_len(_1: &mut [i32; 42]) -> usize { | ||
debug x => _1; | ||
let mut _0: usize; | ||
let _2: &[i32]; | ||
let mut _3: &[i32; 42]; | ||
let mut _4: *const [i32]; | ||
scope 1 { | ||
debug x => _2; | ||
} | ||
|
||
bb0: { | ||
- StorageLive(_2); | ||
+ nop; | ||
StorageLive(_3); | ||
_3 = &(*_1); | ||
_2 = move _3 as &[i32] (PointerCoercion(Unsize)); | ||
StorageDead(_3); | ||
StorageLive(_4); | ||
_4 = &raw const (*_2); | ||
- _0 = PtrMetadata(move _4); | ||
+ _0 = const 42_usize; | ||
StorageDead(_4); | ||
- StorageDead(_2); | ||
+ nop; | ||
return; | ||
} | ||
} | ||
|
This file contains 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 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
41 changes: 41 additions & 0 deletions
41
tests/mir-opt/gvn.manual_slice_mut_len.GVN.panic-abort.diff
This file contains 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,41 @@ | ||
- // MIR for `manual_slice_mut_len` before GVN | ||
+ // MIR for `manual_slice_mut_len` after GVN | ||
|
||
fn manual_slice_mut_len(_1: &mut [i32]) -> usize { | ||
debug x => _1; | ||
let mut _0: usize; | ||
let _2: *mut [i32]; | ||
let mut _4: *mut [i32]; | ||
let mut _5: *const [i32]; | ||
scope 1 { | ||
debug x => _2; | ||
let _3: *const [i32]; | ||
scope 2 { | ||
debug x => _3; | ||
} | ||
} | ||
|
||
bb0: { | ||
- StorageLive(_2); | ||
+ nop; | ||
_2 = &raw mut (*_1); | ||
- StorageLive(_3); | ||
+ nop; | ||
StorageLive(_4); | ||
_4 = _2; | ||
- _3 = move _4 as *const [i32] (PtrToPtr); | ||
+ _3 = _2 as *const [i32] (PtrToPtr); | ||
StorageDead(_4); | ||
StorageLive(_5); | ||
_5 = _3; | ||
- _0 = PtrMetadata(move _5); | ||
+ _0 = PtrMetadata(_1); | ||
StorageDead(_5); | ||
- StorageDead(_3); | ||
- StorageDead(_2); | ||
+ nop; | ||
+ nop; | ||
return; | ||
} | ||
} | ||
|
Oops, something went wrong.