aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/o3licm.zc
blob: 43abfb93866c0c532c7b2afff9b2f5e6fb839069 (plain) (blame)
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
namespace;
include rt;

// loop invariants are built once in front of the loop, and a value two blocks both build is shared.
// every result below has to match the plain run (ZYNOSHARE=1 turns the pass off).
unchecked o3 int nest(int n, int k) {
	int s = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			s = s + (k * 37 + 11) * (i + j);
		}
	}
	return s;
}
unchecked o3 int loads(int* a, int n) {
	int s = 0;
	for (int i = 0; i < n; i++) s = s + a[0] * a[1] + i;
	return s;
}
unchecked o3 int stores(int* a, int n) {
	int s = 0;
	for (int i = 0; i < n; i++) { a[0] = a[0] + 1; s = s + a[0] * 3; }
	return s;
}
unchecked o3 int branchy(int x, int y, int n) {
	int s = 0;
	for (int i = 0; i < n; i++) {
		if (i & 1) s = s + x * y * 5;
		else s = s - x * y * 5 + i;
	}
	return s;
}
unchecked o3 int twice(int x, int y) {
	int r = 0;
	if (x > 0) r = (x * y + 3) * (x * y + 3);
	else r = x * y + 3;
	return r + (x * y + 3) * 7;
}
unchecked fn main() {
	int* a = rt.new(int, 4);
	a[0] = 5; a[1] = 6;
	rt.put_n(nest(30, 3)); rt.put_c(' ');
	rt.put_n(loads(a, 100)); rt.put_c(' ');
	rt.put_n(stores(a, 10)); rt.put_c(' ');
	rt.put_n(branchy(3, 4, 21)); rt.put_c(' ');
	rt.put_n(twice(5, 2)); rt.put_c(' ');
	rt.put_n(twice(-5, 2)); rt.put_c(10);
	return 0;
}