summaryrefslogtreecommitdiff
path: root/tools/mir_opt_test/tests/trivial.rs
blob: f2f125b8653f8f5b0a450f8d10ed4c39dbbf9084 (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
#[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;
}

#[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;
}