-
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.
Add an InstCombine for redundant casts
- Loading branch information
Showing
5 changed files
with
80 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
- // MIR for `redundant` before InstCombine | ||
+ // MIR for `redundant` after InstCombine | ||
|
||
fn redundant(_1: *const &u8) -> *const &u8 { | ||
debug x => _1; // in scope 0 at $DIR/casts.rs:+0:30: +0:31 | ||
let mut _0: *const &u8; // return place in scope 0 at $DIR/casts.rs:+0:51: +0:64 | ||
let mut _2: *const &u8; // in scope 0 at $DIR/casts.rs:+1:5: +1:55 | ||
let mut _3: *const &u8; // in scope 0 at $DIR/casts.rs:+1:36: +1:37 | ||
scope 1 (inlined generic_cast::<&u8, &u8>) { // at $DIR/casts.rs:6:5: 6:38 | ||
debug x => _3; // in scope 1 at $DIR/casts.rs:10:23: 10:24 | ||
} | ||
|
||
bb0: { | ||
StorageLive(_2); // scope 0 at $DIR/casts.rs:+1:5: +1:55 | ||
StorageLive(_3); // scope 0 at $DIR/casts.rs:+1:36: +1:37 | ||
_3 = _1; // scope 0 at $DIR/casts.rs:+1:36: +1:37 | ||
- _2 = _3 as *const &u8 (PtrToPtr); // scope 1 at $DIR/casts.rs:11:5: 11:18 | ||
+ _2 = _3; // scope 1 at $DIR/casts.rs:11:5: 11:18 | ||
StorageDead(_3); // scope 0 at $DIR/casts.rs:+1:37: +1:38 | ||
_0 = _2; // scope 0 at $DIR/casts.rs:+1:5: +1:55 | ||
StorageDead(_2); // scope 0 at $DIR/casts.rs:+2:1: +2:2 | ||
return; // scope 0 at $DIR/casts.rs:+2:2: +2:2 | ||
} | ||
} | ||
|
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,14 @@ | ||
// MIR for `redundant` after PreCodegen | ||
|
||
fn redundant(_1: *const &u8) -> *const &u8 { | ||
debug x => _1; // in scope 0 at $DIR/casts.rs:+0:30: +0:31 | ||
let mut _0: *const &u8; // return place in scope 0 at $DIR/casts.rs:+0:51: +0:64 | ||
scope 1 (inlined generic_cast::<&u8, &u8>) { // at $DIR/casts.rs:6:5: 6:38 | ||
debug x => _1; // in scope 1 at $DIR/casts.rs:10:23: 10:24 | ||
} | ||
|
||
bb0: { | ||
_0 = _1; // scope 0 at $DIR/casts.rs:+1:5: +1:55 | ||
return; // scope 0 at $DIR/casts.rs:+2:2: +2:2 | ||
} | ||
} |
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,15 @@ | ||
// MIR for `roundtrip` after PreCodegen | ||
|
||
fn roundtrip(_1: *const u8) -> *const u8 { | ||
debug x => _1; // in scope 0 at $DIR/casts.rs:+0:18: +0:19 | ||
let mut _0: *const u8; // return place in scope 0 at $DIR/casts.rs:+0:35: +0:44 | ||
let mut _2: *mut u8; // in scope 0 at $DIR/casts.rs:+1:5: +1:17 | ||
|
||
bb0: { | ||
StorageLive(_2); // scope 0 at $DIR/casts.rs:+1:5: +1:17 | ||
_2 = _1 as *mut u8 (PtrToPtr); // scope 0 at $DIR/casts.rs:+1:5: +1:17 | ||
_0 = move _2 as *const u8 (Pointer(MutToConstPointer)); // scope 0 at $DIR/casts.rs:+1:5: +1:17 | ||
StorageDead(_2); // scope 0 at $DIR/casts.rs:+1:16: +1:17 | ||
return; // scope 0 at $DIR/casts.rs:+2:2: +2:2 | ||
} | ||
} |
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,17 @@ | ||
#![crate_type = "lib"] | ||
|
||
// EMIT_MIR casts.redundant.InstCombine.diff | ||
// EMIT_MIR casts.redundant.PreCodegen.after.mir | ||
pub fn redundant<'a, 'b: 'a>(x: *const &'a u8) -> *const &'a u8 { | ||
generic_cast::<&'a u8, &'b u8>(x) as *const &'a u8 | ||
} | ||
|
||
#[inline] | ||
fn generic_cast<T, U>(x: *const T) -> *const U { | ||
x as *const U | ||
} | ||
|
||
// EMIT_MIR casts.roundtrip.PreCodegen.after.mir | ||
pub fn roundtrip(x: *const u8) -> *const u8 { | ||
x as *mut u8 as *const u8 | ||
} |