-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a few basic InstCombine optimizations
- Loading branch information
Showing
31 changed files
with
1,211 additions
and
458 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
22 changes: 22 additions & 0 deletions
22
tests/mir-opt/instcombine/place_projection.place_projection.InstCombine.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,22 @@ | ||
- // MIR for `place_projection` before InstCombine | ||
+ // MIR for `place_projection` after InstCombine | ||
|
||
fn place_projection(_1: Outer) -> u8 { | ||
debug o => _1; | ||
let mut _0: u8; | ||
let _2: Inner; | ||
scope 1 { | ||
debug temp => _2; | ||
} | ||
|
||
bb0: { | ||
StorageLive(_2); | ||
- _2 = move (_1.0: Inner); | ||
- _0 = (_2.0: u8); | ||
+ _0 = ((_1.0: Inner).0: u8); | ||
+ nop; | ||
StorageDead(_2); | ||
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,16 @@ | ||
// unit-test: InstCombine | ||
#![crate_type = "lib"] | ||
|
||
pub struct Outer { | ||
inner: Inner, | ||
} | ||
|
||
struct Inner { | ||
field: u8, | ||
} | ||
|
||
// EMIT_MIR place_projection.place_projection.InstCombine.diff | ||
pub fn place_projection(o: Outer) -> u8 { | ||
let temp = o.inner; | ||
temp.field | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/mir-opt/instcombine/ptr_cast.ptr_cast.InstCombine.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,23 @@ | ||
- // MIR for `ptr_cast` before InstCombine | ||
+ // MIR for `ptr_cast` after InstCombine | ||
|
||
fn ptr_cast(_1: *const u8) -> *mut () { | ||
debug p => _1; | ||
let mut _0: *mut (); | ||
let mut _2: *mut u8; | ||
let mut _3: *const u8; | ||
|
||
bb0: { | ||
StorageLive(_2); | ||
StorageLive(_3); | ||
_3 = _1; | ||
- _2 = move _3 as *mut u8 (PtrToPtr); | ||
+ _0 = move _3 as *mut () (PtrToPtr); | ||
+ nop; | ||
StorageDead(_3); | ||
- _0 = move _2 as *mut () (PtrToPtr); | ||
StorageDead(_2); | ||
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,7 @@ | ||
// unit-test: InstCombine | ||
#![crate_type = "lib"] | ||
|
||
// EMIT_MIR ptr_cast.ptr_cast.InstCombine.diff | ||
pub fn ptr_cast(p: *const u8) -> *mut () { | ||
p as *mut u8 as *mut () | ||
} |
44 changes: 44 additions & 0 deletions
44
tests/mir-opt/instcombine/ref_addressof.ref_addressof.InstCombine.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,44 @@ | ||
- // MIR for `ref_addressof` before InstCombine | ||
+ // MIR for `ref_addressof` after InstCombine | ||
|
||
fn ref_addressof(_1: T) -> () { | ||
debug t => _1; | ||
let mut _0: (); | ||
let _2: &T; | ||
let _4: (); | ||
let mut _5: *const T; | ||
scope 1 { | ||
debug r => _2; | ||
let _3: *const T; | ||
scope 2 { | ||
debug ptr => _3; | ||
} | ||
} | ||
|
||
bb0: { | ||
StorageLive(_2); | ||
- _2 = &_1; | ||
StorageLive(_3); | ||
- _3 = &raw const (*_2); | ||
+ _3 = &raw const _1; | ||
+ nop; | ||
StorageLive(_4); | ||
StorageLive(_5); | ||
_5 = _3; | ||
_4 = std::mem::drop::<*const T>(move _5) -> [return: bb1, unwind unreachable]; | ||
} | ||
|
||
bb1: { | ||
StorageDead(_5); | ||
StorageDead(_4); | ||
_0 = const (); | ||
StorageDead(_3); | ||
StorageDead(_2); | ||
drop(_1) -> [return: bb2, unwind unreachable]; | ||
} | ||
|
||
bb2: { | ||
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,9 @@ | ||
// unit-test: InstCombine | ||
#![crate_type = "lib"] | ||
|
||
// EMIT_MIR ref_addressof.ref_addressof.InstCombine.diff | ||
pub fn ref_addressof<T>(t: T) { | ||
let r = &t; | ||
let ptr = std::ptr::addr_of!(*r); | ||
drop(ptr); | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/mir-opt/instcombine/ref_deref.ref_deref.InstCombine.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,22 @@ | ||
- // MIR for `ref_deref` before InstCombine | ||
+ // MIR for `ref_deref` after InstCombine | ||
|
||
fn ref_deref(_1: T) -> T { | ||
debug t => _1; | ||
let mut _0: T; | ||
let _2: &T; | ||
scope 1 { | ||
debug r => _2; | ||
} | ||
|
||
bb0: { | ||
StorageLive(_2); | ||
- _2 = &_1; | ||
- _0 = (*_2); | ||
+ _0 = _1; | ||
+ nop; | ||
StorageDead(_2); | ||
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,8 @@ | ||
// unit-test: InstCombine | ||
#![crate_type = "lib"] | ||
|
||
// EMIT_MIR ref_deref.ref_deref.InstCombine.diff | ||
pub fn ref_deref<T: Copy>(t: T) -> T { | ||
let r = &t; | ||
*r | ||
} |
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,18 @@ | ||
- // MIR for `outer_get` before InstCombine | ||
+ // MIR for `outer_get` after InstCombine | ||
|
||
fn outer_get(_1: &Outer) -> u8 { | ||
debug this => _1; | ||
let mut _0: u8; | ||
let mut _2: &Inner; | ||
let _3: &Inner; | ||
scope 1 (inlined inner_get) { | ||
debug this => &((*_1).0: Inner); | ||
} | ||
|
||
bb0: { | ||
_0 = (((*_1).0: Inner).0: u8); | ||
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
Oops, something went wrong.