Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
64afc5e
Make BitVec::contains panic-less
nagisa Aug 2, 2016
5fdc839
Expand BitVec functionality slightly
nagisa Aug 2, 2016
34d0545
[MIR] Utility to retrieve base variable of Lvalue
nagisa Aug 2, 2016
ccdc81a
Add a MIR dataflow framework (again)
nagisa Aug 5, 2016
8b8ccf0
[MIR] Constant propagation
nagisa Aug 6, 2016
ba6a8fb
Count time taken by MIR passes
nagisa Aug 6, 2016
2cc114c
Count and report time taken by MIR passes
nagisa Aug 7, 2016
d203b9c
Comments, todos and small improvements
nagisa Aug 7, 2016
18f65dd
Add Rvalue::is_pure
nagisa Aug 7, 2016
97bfde3
Fix compilation
nagisa Aug 9, 2016
61a58f1
Fix join function for CsLattice
nagisa Aug 11, 2016
efbea54
Rename dead code removal pass to a proper-er name
nagisa Aug 11, 2016
b15bb6d
Add some constant propagation tests
nagisa Aug 11, 2016
f78274c
Clean-up the ConstLattice; Propagate global state
nagisa Aug 15, 2016
61871d4
Re-add a way to specify initial state
nagisa Aug 15, 2016
1b3e945
Rebase fallout
nagisa Aug 15, 2016
935dc8d
Make SwitchInt switch on Operand
nagisa Aug 15, 2016
3e2e8b9
Disallow to optimise out constants in OOB tests
nagisa Aug 15, 2016
e00862b
A way to remove otherwise unused locals from MIR
nagisa Aug 16, 2016
c352ae2
Do not run the DA+ConstProp before DropElab
nagisa Aug 16, 2016
708487b
Rebase fallout
nagisa Aug 16, 2016
0791d56
Do not be overly aggressive optimising MIR with -g
nagisa Aug 18, 2016
9b227dd
More bitvec tests
nagisa Aug 18, 2016
ec8e500
Fix aliasing in const-propagate
nagisa Aug 19, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add some constant propagation tests
  • Loading branch information
nagisa committed Aug 18, 2016
commit b15bb6db9076bec6abcd47e4d83a97df1cf31613
59 changes: 59 additions & 0 deletions src/test/mir-opt/const-prop-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
let x = 10;
let y = 20;
if x == 12 {
[42u8][y];
} else {
return;
}
}

// END RUST SOURCE
// START rustc.node4.CsPropagate.before.mir
// bb0: {
// var0 = const 10i32;
// var1 = const 20usize;
// tmp1 = var0;
// tmp0 = Eq(tmp1, const 12i32);
// if(tmp0) -> [true: bb1, false: bb2];
// }
//
// bb1: {
// tmp4 = [const 42u8];
// tmp5 = var1;
// tmp6 = Len(tmp4);
// tmp7 = Lt(tmp5, tmp6);
// assert(tmp7, "index out of bounds: the len is {} but the index is {}", tmp6, tmp5) -> bb3;
// }
//
// bb2: {
// return = ();
// goto -> bb4;
// }
//
// bb3: {
// tmp3 = tmp4[tmp5];
// tmp2 = tmp3;
// return = ();
// goto -> bb4;
// }
// END rustc.node4.CsPropagate.before.mir
// START rustc.node4.DeadCode.after.mir
// bb0: {
// goto -> bb1;
// }
//
// bb1: {
// return = ();
// return;
// }
// END rustc.node4.DeadCode.after.mir
45 changes: 45 additions & 0 deletions src/test/mir-opt/const-prop-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
let cfg = cfg!(never_ever_set);
let x = 42 + if cfg { 42 } else { 0 };
::std::process::exit(x - 42);
}

// END RUST SOURCE
// START rustc.node4.CsPropagate.before.mir
// bb0: {
// var0 = const false;
// tmp1 = var0;
// if(tmp1) -> [true: bb1, false: bb2];
// }
//
// bb1: {
// tmp0 = const 42i32;
// goto -> bb3;
// }
//
// bb2: {
// tmp0 = const 0i32;
// goto -> bb3;
// }
//
// bb3: {
// var1 = Add(const 42i32, tmp0);
// tmp4 = var1;
// tmp3 = Sub(tmp4, const 42i32);
// std::process::exit(tmp3);
// }
// END rustc.node4.CsPropagate.before.mir
// START rustc.node4.DeadCode.after.mir
// bb1: {
// std::process::exit(const 0i32);
// }
// END rustc.node4.DeadCode.after.mir
80 changes: 80 additions & 0 deletions src/test/mir-opt/const-prop-loop-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn hdrty() -> usize { 6 }

fn inc(idx: u16) -> usize { 1 }

fn main() {
let hdrty = hdrty();
let max = match hdrty {
0 => 6,
1 => 2,
_ => 0,
};
let mut i = 0;
while i < max {
let next = inc(i as u16);
i = next;
}
}

// END RUST SOURCE
// START rustc.node17.CsPropagate.before.mir
// bb6: {
// tmp1 = var2;
// tmp2 = var1;
// tmp0 = Lt(tmp1, tmp2);
// if(tmp0) -> [true: bb8, false: bb7];
// }
//
// bb7: {
// return = ();
// return;
// }
//
// bb8: {
// tmp5 = var2;
// tmp4 = tmp5 as u16 (Misc);
// var3 = inc(tmp4) -> bb9;
// }
//
// bb9: {
// tmp6 = var3;
// var2 = tmp6;
// tmp3 = ();
// goto -> bb6;
// }
// END rustc.node17.CsPropagate.before.mir
// START rustc.node17.CsPropagate.after.mir
// bb6: {
// tmp1 = var2;
// tmp2 = var1;
// tmp0 = Lt(tmp1, tmp2);
// if(tmp0) -> [true: bb8, false: bb7];
// }
//
// bb7: {
// return = ();
// return;
// }
//
// bb8: {
// tmp5 = var2;
// tmp4 = tmp5 as u16 (Misc);
// var3 = inc(tmp4) -> bb9;
// }
//
// bb9: {
// tmp6 = var3;
// var2 = tmp6;
// tmp3 = ();
// goto -> bb6;
// }
// END rustc.node17.CsPropagate.after.mir