librustc_mir: Propagate constants during copy propagation.

This optimization kicks in a lot when bootstrapping the compiler.
This commit is contained in:
Patrick Walton 2016-09-21 12:17:56 -07:00
parent bdad70213b
commit 79cb2dbfac
5 changed files with 242 additions and 88 deletions

View file

@ -23,9 +23,9 @@ fn helper(_: usize) {
pub fn ref_dst(s: &[u8]) {
// We used to generate an extra alloca and memcpy to ref the dst, so check that we copy
// directly to the alloca for "x"
// CHECK: [[X0:%[0-9]+]] = getelementptr {{.*}} { i8*, [[USIZE]] }* %s, i32 0, i32 0
// CHECK: [[X0:%[0-9]+]] = getelementptr {{.*}} { i8*, [[USIZE]] }* %x, i32 0, i32 0
// CHECK: store i8* %0, i8** [[X0]]
// CHECK: [[X1:%[0-9]+]] = getelementptr {{.*}} { i8*, [[USIZE]] }* %s, i32 0, i32 1
// CHECK: [[X1:%[0-9]+]] = getelementptr {{.*}} { i8*, [[USIZE]] }* %x, i32 0, i32 1
// CHECK: store [[USIZE]] %1, [[USIZE]]* [[X1]]
let x = &*s;

View file

@ -19,17 +19,17 @@ fn main() {
}
// END RUST SOURCE
// START rustc.node4.PreTrans.after.mir
// START rustc.node4.TypeckMir.before.mir
// bb0: {
// nop; // scope 0 at storage_ranges.rs:14:9: 14:10
// StorageLive(var0); // scope 0 at storage_ranges.rs:14:9: 14:10
// var0 = const 0i32; // scope 0 at storage_ranges.rs:14:13: 14:14
// StorageLive(var1); // scope 1 at storage_ranges.rs:16:13: 16:14
// StorageLive(tmp1); // scope 1 at storage_ranges.rs:16:18: 16:25
// nop; // scope 1 at storage_ranges.rs:16:23: 16:24
// nop; // scope 1 at storage_ranges.rs:16:23: 16:24
// tmp1 = std::option::Option<i32>::Some(var0,); // scope 1 at storage_ranges.rs:16:18: 16:25
// StorageLive(tmp2); // scope 1 at storage_ranges.rs:16:23: 16:24
// tmp2 = var0; // scope 1 at storage_ranges.rs:16:23: 16:24
// tmp1 = std::option::Option<i32>::Some(tmp2,); // scope 1 at storage_ranges.rs:16:18: 16:25
// var1 = &tmp1; // scope 1 at storage_ranges.rs:16:17: 16:25
// nop; // scope 1 at storage_ranges.rs:16:23: 16:24
// StorageDead(tmp2); // scope 1 at storage_ranges.rs:16:23: 16:24
// tmp0 = (); // scope 2 at storage_ranges.rs:15:5: 17:6
// StorageDead(tmp1); // scope 1 at storage_ranges.rs:16:18: 16:25
// StorageDead(var1); // scope 1 at storage_ranges.rs:16:13: 16:14
@ -37,11 +37,11 @@ fn main() {
// var2 = const 1i32; // scope 1 at storage_ranges.rs:18:13: 18:14
// return = (); // scope 3 at storage_ranges.rs:13:11: 19:2
// StorageDead(var2); // scope 1 at storage_ranges.rs:18:9: 18:10
// nop; // scope 0 at storage_ranges.rs:14:9: 14:10
// StorageDead(var0); // scope 0 at storage_ranges.rs:14:9: 14:10
// goto -> bb1; // scope 0 at storage_ranges.rs:13:1: 19:2
// }
//
// bb1: {
// return; // scope 0 at storage_ranges.rs:13:1: 19:2
// }
// END rustc.node4.PreTrans.after.mir
// END rustc.node4.TypeckMir.before.mir