llvm.org GIT mirror llvm / 5b160f1
Simple hand-coded tests to aid in early development of backends, along with a Makefile to run ad-hoc tests easily. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15664 91177308-0d34-0410-b5e6-96231b3b80d8 Misha Brukman 15 years ago
20 changed file(s) with 511 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 # Makefile for running ad-hoc custom LLVM tests
1 #
2 %.bc: %.ll
3 llvm-as -f $<
4
5 %.llc.s: %.bc
6 llc -f $< -o $@
7
8 %.gcc.s: %.c
9 gcc -O0 -S $< -o $@
10
11 %.nat: %.s
12 gcc -O0 -lm $< -o $@
13
14 %.cbe.out: %.cbe.nat
15 ./$< > $@
16
17 %.out: %.nat
18 ./$< > $@
19
20 %.clean:
21 rm -f $(patsubst %.clean,%.bc,$@) $(patsubst %.clean,%.*.s,$@) \
22 $(patsubst %.clean,%.*.nat,$@) $(patsubst %.clean,%.*.out,$@)
0 #include
1 int a = 1, b = 2;
2
3 int main() {
4 int i,j;
5 for (i=15; i>=0; --i) {
6 if (a < i) printf("%d < %d\n", a, i);
7 else printf("%d >= %d\n", a, i);
8 for (j=2; j <= 25; j++) {
9 printf("%d, ", j);
10 }
11 printf("\n");
12 }
13 return 0;
14 }
0 int %foo(int %x) {
1 ret int %x
2 }
3
4 int %main() {
5 %r = call int %foo(int 0)
6 ret int %r
7 }
0 int %foo(int %x) {
1 ret int 42
2 }
3
4 int %main() {
5 %r = call int %foo(int 15)
6 ret int %r
7 }
0 void %foo() {
1 ret void
2 }
3
4 int %main() {
5 call void ()* %foo()
6 ret int 0
7 }
0 int %bar(int %x) {
1 ret int 0
2 }
3
4 int %foo(int %x) {
5 %q = call int %bar(int 1)
6 ret int %q
7 }
8
9 int %main() {
10 %r = call int %foo(int 2)
11 ret int %r
12 }
0 %a_fstr = internal constant [8 x sbyte] c"a = %f\0A\00"
1 %a_lstr = internal constant [10 x sbyte] c"a = %lld\0A\00"
2 %a_dstr = internal constant [8 x sbyte] c"a = %d\0A\00"
3
4 %b_dstr = internal constant [8 x sbyte] c"b = %d\0A\00"
5 %b_fstr = internal constant [8 x sbyte] c"b = %f\0A\00"
6
7 declare int %printf(sbyte*, ...)
8 %A = global double 2.0
9 %B = global int 2
10
11 int %main() {
12 ;; A
13 %a = load double* %A
14 %a_fs = getelementptr [8 x sbyte]* %a_fstr, long 0, long 0
15 call int (sbyte*, ...)* %printf(sbyte* %a_fs, double %a)
16
17 ;; cast double to long
18 %a_d2l = cast double %a to long
19 %a_ls = getelementptr [10 x sbyte]* %a_lstr, long 0, long 0
20 call int (sbyte*, ...)* %printf(sbyte* %a_ls, long %a_d2l)
21
22 ;; cast double to int
23 %a_d2i = cast double %a to int
24 %a_ds = getelementptr [8 x sbyte]* %a_dstr, long 0, long 0
25 call int (sbyte*, ...)* %printf(sbyte* %a_ds, int %a_d2i)
26
27 ;; cast double to sbyte
28 %a_d2sb = cast double %a to sbyte
29 call int (sbyte*, ...)* %printf(sbyte* %a_ds, sbyte %a_d2sb)
30
31 ;; cast int to sbyte
32 %a_d2i2sb = cast int %a_d2i to sbyte
33 call int (sbyte*, ...)* %printf(sbyte* %a_ds, sbyte %a_d2i2sb)
34
35 ;; B
36 %b = load int* %B
37 %b_ds = getelementptr [8 x sbyte]* %b_dstr, long 0, long 0
38 call int (sbyte*, ...)* %printf(sbyte* %b_ds, int %b)
39
40 ;; cast int to double
41 %b_i2d = cast int %b to double
42 %b_fs = getelementptr [8 x sbyte]* %b_fstr, long 0, long 0
43 call int (sbyte*, ...)* %printf(sbyte* %b_fs, double %b_i2d)
44
45 ret int 0
46 }
0 %g = global int 0
1
2 int %main() {
3 %h = load int* %g
4 ret int %h
5 }
0 %.str_1 = internal constant [7 x sbyte] c"hello\0A\00"
1
2 declare int %printf(sbyte*, ...)
3
4 int %main() {
5 %s = getelementptr [7 x sbyte]* %.str_1, long 0, long 0
6 call int (sbyte*, ...)* %printf(sbyte* %s)
7 ret int 0
8 }
0 %.str_1 = internal constant [4 x sbyte] c"%d\0A\00"
1
2 declare int %printf(sbyte*, ...)
3
4 int %main() {
5 %f = getelementptr [4 x sbyte]* %.str_1, long 0, long 0
6 %d = add int 1, 0
7 call int (sbyte*, ...)* %printf(sbyte* %f, int %d)
8 %e = add int 38, 2
9 call int (sbyte*, ...)* %printf(sbyte* %f, int %e)
10 %g = add int %d, %d
11 %h = add int %e, %g
12 call int (sbyte*, ...)* %printf(sbyte* %f, int %h)
13 ret int 0
14 }
15
0 %a_str = internal constant [8 x sbyte] c"a = %f\0A\00"
1 %b_str = internal constant [8 x sbyte] c"b = %f\0A\00"
2 ;; binary ops: arith
3 %add_str = internal constant [12 x sbyte] c"a + b = %f\0A\00"
4 %sub_str = internal constant [12 x sbyte] c"a - b = %f\0A\00"
5 %mul_str = internal constant [12 x sbyte] c"a * b = %f\0A\00"
6 %div_str = internal constant [12 x sbyte] c"b / a = %f\0A\00"
7 %rem_str = internal constant [13 x sbyte] c"b %% a = %f\0A\00"
8 ;; binary ops: setcc
9 %lt_str = internal constant [12 x sbyte] c"a < b = %d\0A\00"
10 %le_str = internal constant [13 x sbyte] c"a <= b = %d\0A\00"
11 %gt_str = internal constant [12 x sbyte] c"a > b = %d\0A\00"
12 %ge_str = internal constant [13 x sbyte] c"a >= b = %d\0A\00"
13 %eq_str = internal constant [13 x sbyte] c"a == b = %d\0A\00"
14 %ne_str = internal constant [13 x sbyte] c"a != b = %d\0A\00"
15
16 declare int %printf(sbyte*, ...)
17 %A = global double 2.0
18 %B = global double 5.0
19
20 int %main() {
21 ;; main vars
22 %a = load double* %A
23 %b = load double* %B
24
25 %a_s = getelementptr [8 x sbyte]* %a_str, long 0, long 0
26 %b_s = getelementptr [8 x sbyte]* %b_str, long 0, long 0
27
28 call int (sbyte*, ...)* %printf(sbyte* %a_s, double %a)
29 call int (sbyte*, ...)* %printf(sbyte* %b_s, double %b)
30
31 ;; arithmetic
32 %add_r = add double %a, %b
33 %sub_r = sub double %a, %b
34 %mul_r = mul double %a, %b
35 %div_r = div double %b, %a
36 %rem_r = rem double %b, %a
37
38 %add_s = getelementptr [12 x sbyte]* %add_str, long 0, long 0
39 %sub_s = getelementptr [12 x sbyte]* %sub_str, long 0, long 0
40 %mul_s = getelementptr [12 x sbyte]* %mul_str, long 0, long 0
41 %div_s = getelementptr [12 x sbyte]* %div_str, long 0, long 0
42 %rem_s = getelementptr [13 x sbyte]* %rem_str, long 0, long 0
43
44 call int (sbyte*, ...)* %printf(sbyte* %add_s, double %add_r)
45 call int (sbyte*, ...)* %printf(sbyte* %sub_s, double %sub_r)
46 call int (sbyte*, ...)* %printf(sbyte* %mul_s, double %mul_r)
47 call int (sbyte*, ...)* %printf(sbyte* %div_s, double %div_r)
48 call int (sbyte*, ...)* %printf(sbyte* %rem_s, double %rem_r)
49
50 ;; setcc
51 %lt_r = setlt double %a, %b
52 %le_r = setle double %a, %b
53 %gt_r = setgt double %a, %b
54 %ge_r = setge double %a, %b
55 %eq_r = seteq double %a, %b
56 %ne_r = setne double %a, %b
57
58 %lt_s = getelementptr [12 x sbyte]* %lt_str, long 0, long 0
59 %le_s = getelementptr [13 x sbyte]* %le_str, long 0, long 0
60 %gt_s = getelementptr [12 x sbyte]* %gt_str, long 0, long 0
61 %ge_s = getelementptr [13 x sbyte]* %ge_str, long 0, long 0
62 %eq_s = getelementptr [13 x sbyte]* %eq_str, long 0, long 0
63 %ne_s = getelementptr [13 x sbyte]* %ne_str, long 0, long 0
64
65 call int (sbyte*, ...)* %printf(sbyte* %lt_s, bool %lt_r)
66 call int (sbyte*, ...)* %printf(sbyte* %le_s, bool %le_r)
67 call int (sbyte*, ...)* %printf(sbyte* %gt_s, bool %gt_r)
68 call int (sbyte*, ...)* %printf(sbyte* %ge_s, bool %ge_r)
69 call int (sbyte*, ...)* %printf(sbyte* %eq_s, bool %eq_r)
70 call int (sbyte*, ...)* %printf(sbyte* %ne_s, bool %ne_r)
71
72 ret int 0
73 }
0 %a_str = internal constant [8 x sbyte] c"a = %d\0A\00"
1 %b_str = internal constant [8 x sbyte] c"b = %d\0A\00"
2 ;; binary ops: arith
3 %add_str = internal constant [12 x sbyte] c"a + b = %d\0A\00"
4 %sub_str = internal constant [12 x sbyte] c"a - b = %d\0A\00"
5 %mul_str = internal constant [12 x sbyte] c"a * b = %d\0A\00"
6 %div_str = internal constant [12 x sbyte] c"b / a = %d\0A\00"
7 %rem_str = internal constant [13 x sbyte] c"b \% a = %d\0A\00"
8 ;; binary ops: setcc
9 %lt_str = internal constant [12 x sbyte] c"a < b = %d\0A\00"
10 %le_str = internal constant [13 x sbyte] c"a <= b = %d\0A\00"
11 %gt_str = internal constant [12 x sbyte] c"a > b = %d\0A\00"
12 %ge_str = internal constant [13 x sbyte] c"a >= b = %d\0A\00"
13 %eq_str = internal constant [13 x sbyte] c"a == b = %d\0A\00"
14 %ne_str = internal constant [13 x sbyte] c"a != b = %d\0A\00"
15 ;; logical
16 %and_str = internal constant [12 x sbyte] c"a & b = %d\0A\00"
17 %or_str = internal constant [12 x sbyte] c"a | b = %d\0A\00"
18 %xor_str = internal constant [12 x sbyte] c"a ^ b = %d\0A\00"
19 %shl_str = internal constant [13 x sbyte] c"b << a = %d\0A\00"
20 %shr_str = internal constant [13 x sbyte] c"b >> a = %d\0A\00"
21
22 declare int %printf(sbyte*, ...)
23 %A = global int 2
24 %B = global int 5
25
26 int %main() {
27 ;; main vars
28 %a = load int* %A
29 %b = load int* %B
30
31 %a_s = getelementptr [8 x sbyte]* %a_str, long 0, long 0
32 %b_s = getelementptr [8 x sbyte]* %b_str, long 0, long 0
33
34 call int (sbyte*, ...)* %printf(sbyte* %a_s, int %a)
35 call int (sbyte*, ...)* %printf(sbyte* %b_s, int %b)
36
37 ;; arithmetic
38 %add_r = add int %a, %b
39 %sub_r = sub int %a, %b
40 %mul_r = mul int %a, %b
41 %div_r = div int %b, %a
42 %rem_r = rem int %b, %a
43
44 %add_s = getelementptr [12 x sbyte]* %add_str, long 0, long 0
45 %sub_s = getelementptr [12 x sbyte]* %sub_str, long 0, long 0
46 %mul_s = getelementptr [12 x sbyte]* %mul_str, long 0, long 0
47 %div_s = getelementptr [12 x sbyte]* %div_str, long 0, long 0
48 %rem_s = getelementptr [13 x sbyte]* %rem_str, long 0, long 0
49
50 call int (sbyte*, ...)* %printf(sbyte* %add_s, int %add_r)
51 call int (sbyte*, ...)* %printf(sbyte* %sub_s, int %sub_r)
52 call int (sbyte*, ...)* %printf(sbyte* %mul_s, int %mul_r)
53 call int (sbyte*, ...)* %printf(sbyte* %div_s, int %div_r)
54 call int (sbyte*, ...)* %printf(sbyte* %rem_s, int %rem_r)
55
56 ;; setcc
57 %lt_r = setlt int %a, %b
58 %le_r = setle int %a, %b
59 %gt_r = setgt int %a, %b
60 %ge_r = setge int %a, %b
61 %eq_r = seteq int %a, %b
62 %ne_r = setne int %a, %b
63
64 %lt_s = getelementptr [12 x sbyte]* %lt_str, long 0, long 0
65 %le_s = getelementptr [13 x sbyte]* %le_str, long 0, long 0
66 %gt_s = getelementptr [12 x sbyte]* %gt_str, long 0, long 0
67 %ge_s = getelementptr [13 x sbyte]* %ge_str, long 0, long 0
68 %eq_s = getelementptr [13 x sbyte]* %eq_str, long 0, long 0
69 %ne_s = getelementptr [13 x sbyte]* %ne_str, long 0, long 0
70
71 call int (sbyte*, ...)* %printf(sbyte* %lt_s, bool %lt_r)
72 call int (sbyte*, ...)* %printf(sbyte* %le_s, bool %le_r)
73 call int (sbyte*, ...)* %printf(sbyte* %gt_s, bool %gt_r)
74 call int (sbyte*, ...)* %printf(sbyte* %ge_s, bool %ge_r)
75 call int (sbyte*, ...)* %printf(sbyte* %eq_s, bool %eq_r)
76 call int (sbyte*, ...)* %printf(sbyte* %ne_s, bool %ne_r)
77
78 ;; logical
79 %and_r = and int %a, %b
80 %or_r = or int %a, %b
81 %xor_r = xor int %a, %b
82 %u = cast int %a to ubyte
83 %shl_r = shl int %b, ubyte %u
84 %shr_r = shr int %b, ubyte %u
85
86 %and_s = getelementptr [12 x sbyte]* %and_str, long 0, long 0
87 %or_s = getelementptr [12 x sbyte]* %or_str, long 0, long 0
88 %xor_s = getelementptr [12 x sbyte]* %xor_str, long 0, long 0
89 %shl_s = getelementptr [13 x sbyte]* %shl_str, long 0, long 0
90 %shr_s = getelementptr [13 x sbyte]* %shr_str, long 0, long 0
91
92 call int (sbyte*, ...)* %printf(sbyte* %and_s, int %and_r)
93 call int (sbyte*, ...)* %printf(sbyte* %or_s, int %or_r)
94 call int (sbyte*, ...)* %printf(sbyte* %xor_s, int %xor_r)
95 call int (sbyte*, ...)* %printf(sbyte* %shl_s, int %shl_r)
96 call int (sbyte*, ...)* %printf(sbyte* %shr_s, int %shr_r)
97
98 ret int 0
99 }
0 %.str_1 = internal constant [4 x sbyte] c"%d\0A\00"
1
2 declare int %printf(sbyte*, ...)
3
4 int %main() {
5 %f = getelementptr [4 x sbyte]* %.str_1, long 0, long 0
6 %d = add int 0, 0
7 %tmp.0 = call int (sbyte*, ...)* %printf(sbyte* %f, int %d)
8 ret int 0
9 }
10
0 %a_str = internal constant [8 x sbyte] c"a = %d\0A\00"
1 %a_mul_str = internal constant [13 x sbyte] c"a * %d = %d\0A\00"
2 %A = global int 2
3 declare int %printf(sbyte*, ...)
4
5 int %main() {
6 %a = load int* %A
7 %a_s = getelementptr [8 x sbyte]* %a_str, long 0, long 0
8 %a_mul_s = getelementptr [13 x sbyte]* %a_mul_str, long 0, long 0
9 call int (sbyte*, ...)* %printf(sbyte* %a_s, int %a)
10
11 %r_0 = mul int %a, 0
12 %r_1 = mul int %a, 1
13 %r_2 = mul int %a, 2
14 %r_3 = mul int %a, 3
15 %r_4 = mul int %a, 4
16 %r_5 = mul int %a, 5
17 %r_6 = mul int %a, 6
18 %r_7 = mul int %a, 7
19 %r_8 = mul int %a, 8
20 %r_9 = mul int %a, 9
21 %r_10 = mul int %a, 10
22 %r_11 = mul int %a, 11
23 %r_12 = mul int %a, 12
24 %r_13 = mul int %a, 13
25 %r_14 = mul int %a, 14
26 %r_15 = mul int %a, 15
27 %r_16 = mul int %a, 16
28 %r_17 = mul int %a, 17
29 %r_18 = mul int %a, 18
30 %r_19 = mul int %a, 19
31
32 call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 0, int %r_0)
33 call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 1, int %r_1)
34 call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 2, int %r_2)
35 call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 3, int %r_3)
36 call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 4, int %r_4)
37 call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 5, int %r_5)
38 call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 6, int %r_6)
39 call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 7, int %r_7)
40 call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 8, int %r_8)
41 call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 9, int %r_9)
42 call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 10, int %r_10)
43 call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 11, int %r_11)
44 call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 12, int %r_12)
45 call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 13, int %r_13)
46 call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 14, int %r_14)
47 call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 15, int %r_15)
48 call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 16, int %r_16)
49 call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 17, int %r_17)
50 call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 18, int %r_18)
51 call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 19, int %r_19)
52
53 ret int 0
54 }
0 %a_str = internal constant [8 x sbyte] c"a = %d\0A\00"
1 %b_str = internal constant [8 x sbyte] c"b = %d\0A\00"
2
3 ;; mul
4 %a_mul_str = internal constant [13 x sbyte] c"a * %d = %d\0A\00"
5
6 declare int %printf(sbyte*, ...)
7 %A = global int 2
8 %B = global int 5
9
10 int %main() {
11 entry:
12 %a = load int* %A
13 %b = load int* %B
14 %a_s = getelementptr [8 x sbyte]* %a_str, long 0, long 0
15 %b_s = getelementptr [8 x sbyte]* %b_str, long 0, long 0
16 %a_mul_s = getelementptr [13 x sbyte]* %a_mul_str, long 0, long 0
17 call int (sbyte*, ...)* %printf(sbyte* %a_s, int %a)
18 call int (sbyte*, ...)* %printf(sbyte* %b_s, int %b)
19 br label %shl_test
20
21 shl_test:
22 ;; test mul by 0-255
23 %s = phi int [ 0, %entry ], [ %s_inc, %shl_test ]
24 %result = mul int %a, %s
25 call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int %s, int %result)
26 %s_inc = add int %s, 1
27 %done = seteq int %s, 256
28 br bool %done, label %fini, label %shl_test
29
30 fini:
31 ret int 0
32 }
0 %a_str = internal constant [8 x sbyte] c"a = %d\0A\00"
1 %b_str = internal constant [8 x sbyte] c"b = %d\0A\00"
2
3 ;; shl
4 %a_shl_str = internal constant [14 x sbyte] c"a << %d = %d\0A\00"
5
6 declare int %printf(sbyte*, ...)
7 %A = global int 2
8 %B = global int 5
9
10 int %main() {
11 entry:
12 %a = load int* %A
13 %b = load int* %B
14 %a_s = getelementptr [8 x sbyte]* %a_str, long 0, long 0
15 %b_s = getelementptr [8 x sbyte]* %b_str, long 0, long 0
16 %a_shl_s = getelementptr [14 x sbyte]* %a_shl_str, long 0, long 0
17 call int (sbyte*, ...)* %printf(sbyte* %a_s, int %a)
18 call int (sbyte*, ...)* %printf(sbyte* %b_s, int %b)
19 br label %shl_test
20
21 shl_test:
22 ;; test left shifts 0-31
23 %s = phi ubyte [ 0, %entry ], [ %s_inc, %shl_test ]
24 %result = shl int %a, ubyte %s
25 call int (sbyte*, ...)* %printf(sbyte* %a_shl_s, ubyte %s, int %result)
26 %s_inc = add ubyte %s, 1
27 %done = seteq ubyte %s, 32
28 br bool %done, label %fini, label %shl_test
29
30 fini:
31 ret int 0
32 }
0 void printf(char*, ...);
1
2 int main() {
3 printf("%f, %d, %f, %d, %f\n", //, %d, %f, %d, %f, %d\n",
4 1.0, 2, 3.0, 4, 5.0 /*, 6, 7.0, 8, 9.0, 10*/);
5 return 0;
6 }
0 int %main() {
1 ret int 0
2 }
0 int %main() {
1 ret int 42
2 }
0 void printf(char*, ...);
1
2 typedef struct params_ {
3 int i1;
4 float f1;
5 double d1;
6 short s1;
7 double d2;
8 char c1;
9 unsigned short s2;
10 float f2;
11 int i2;
12 } params;
13
14 void print_param(params p) {
15 printf("%d, %f, %f, %d, %f, %c, %d, %f, %d\n",
16 p.i1, p.f1, p.d1, p.s1, p.d2, p.c1, p.s2, p.f2, p.i2);
17 }
18
19 void print_param_addr(params *p) {
20 printf("%d, %f, %f, %d, %f, %c, %d, %f, %d\n",
21 p->i1, p->f1, p->d1, p->s1, p->d2, p->c1, p->s2, p->f2, p->i2);
22 }
23
24 int main() {
25 params p;
26 p.i1 = 1;
27 p.f1 = 2.0;
28 p.d1 = 3.0;
29 p.s1 = 4;
30 p.d2 = 5.0;
31 p.c1 = '6';
32 p.s2 = 7;
33 p.f2 = 8.0;
34 p.i2 = 9;
35 print_param(p);
36 print_param_addr(&p);
37 return 0;
38 }