summaryrefslogtreecommitdiff
path: root/tools/mir_opt_test/tests/single-set-and-use.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tools/mir_opt_test/tests/single-set-and-use.rs')
-rw-r--r--tools/mir_opt_test/tests/single-set-and-use.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/tools/mir_opt_test/tests/single-set-and-use.rs b/tools/mir_opt_test/tests/single-set-and-use.rs
new file mode 100644
index 00000000..1cd5e542
--- /dev/null
+++ b/tools/mir_opt_test/tests/single-set-and-use.rs
@@ -0,0 +1,53 @@
+//
+// Tests for single-use-variable elimination
+//
+
+// Check forward movement of values
+#[test="simple_fwd_exp"]
+fn simple_fwd(a: i32) -> (i32,)
+{
+ let v: i32;
+ bb0: {
+ ASSIGN v = a;
+ ASSIGN retval = (v,);
+ } RETURN;
+}
+fn simple_fwd_exp(a: i32) -> (i32,)
+{
+ bb0: {
+ ASSIGN retval = (a,);
+ } RETURN;
+}
+
+// Reverse (upwards) movement
+#[test="simple_rev_exp"]
+fn simple_rev(a: i32) -> (i32,)
+{
+ let v: (i32,);
+ bb0: {
+ ASSIGN v = (a,);
+ ASSIGN retval = v;
+ } RETURN;
+}
+fn simple_rev_exp(a: i32) -> (i32,)
+{
+ bb0: {
+ ASSIGN retval = (a,);
+ } RETURN;
+}
+
+// Check that if there's a mutable borrow of the source, that the source isn't propagated forwards
+// - NOTE: This relies on the optimiser not being smart enough to move the `retval` construction up
+#[test="nomut"]
+fn nomut(a: i32) -> (i32,)
+{
+ let v: i32;
+ let ba: &mut i32;
+ bb0: {
+ ASSIGN v = a;
+ ASSIGN ba = &mut a;
+ //ASSIGN a* = +0;
+ ASSIGN retval = (v,);
+ DROP ba;
+ } RETURN;
+}