summaryrefslogtreecommitdiff
path: root/tools/mir_opt_test/tests/trivial.rs
blob: 80d78620fe931228d46e9c6132bfdaf33a9dc4b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// No-op test
#[test="test_trivial"]
fn test_trivial()
{
	bb0: {
		ASSIGN retval = ();
	} RETURN;
}

// Dead code elimination, should remove any useless code
// - Unused assignments 
// - Unused locals
// - Unused drop flags
// - Unused blocks
#[test="dce_exp"]
fn dce()
{
	let df0 = false;
	let useless: ();
	bb0: {
		ASSIGN useless = ();
		ASSIGN useless = useless;	// Never read, so will be removed
		ASSIGN retval = ();
		//ASSIGN retval = ();	// Note: won't be de-duplicated (TODO)
	} RETURN;
	// Never referenced, will be removed
	bb_unused: {
	} GOTO bb_unused_indir;
	// Indirectly unused, will still be removed
	bb_unused_indir: {
	} DIVERGE;
	// References itself without other reference, will be removed
	bb_unused_self: {
	} GOTO bb_unused_self;
}
fn dce_exp()
{
	bb0: {
		ASSIGN retval = ();
	} RETURN;
}

// Inlining
#[test="inlining_exp"]
fn inlining()
{
	bb0: {
	} CALL retval = ::""::inlining_target() => bb1 else bb2;
	bb1: {
	} RETURN;
	bb2: {
	} DIVERGE;
}
fn inlining_target()
{
	bb0: {
		ASSIGN retval = ();
	} RETURN;
}
fn inlining_exp()
{
	bb0: {
		ASSIGN retval = ();
	} RETURN;
}

// Constant propagation leading to DCE
#[test="constprop_exp"]
fn constprop()
{
	let v1: bool;
	bb0: {
		ASSIGN v1 = true;
	} IF v1 => bb1 else bb2;
	bb1: {
		ASSIGN retval = ();
	} RETURN;
	bb2: {
	} DIVERGE;
}
fn constprop_exp()
{
	bb0: {
		ASSIGN retval = ();
	} RETURN;
}