llvm.org GIT mirror llvm / a7a1c7e
Some of these are feature tests, not regression tests. This directory needs to be reorganized and some of the tests need changes to make them executable. Also comments would help... git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2865 91177308-0d34-0410-b5e6-96231b3b80d8 Vikram S. Adve 18 years ago
20 changed file(s) with 1208 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 implementation
1
2 int "main"()
3 begin
4 bb0:
5 %reg109 = malloc int, uint 100
6 br label %bb2
7
8 bb2:
9 %cann-indvar1 = phi int [ 0, %bb0 ], [ %add1-indvar1, %bb2 ]
10 %reg127 = mul int %cann-indvar1, 2
11 %add1-indvar1 = add int %cann-indvar1, 1
12 store int 999, int * %reg109, uint 0
13 %cond1015 = setle int 1, 99
14 %reg128 = add int %reg127, 2
15 br bool %cond1015, label %bb2, label %bb4
16
17 bb4: ;[#uses=3]
18 %cann-indvar = phi uint [ %add1-indvar, %bb4 ], [ 0, %bb2 ]
19 %add1-indvar = add uint %cann-indvar, 1 ; [#uses=1]
20 store int 333, int * %reg109, uint 0
21 %reg131 = add uint %add1-indvar, 3 ; [#uses=1]
22 %cond1017 = setle uint %reg131, 99 ; [#uses=1]
23 br bool %cond1017, label %bb4, label %bb5
24
25 bb5:
26 ret int 0
27 end
0 ; Test that a sequence of constant indices are folded correctly
1 ; into the equivalent offset at compile-time.
2
3 %MixedA = type { float, [15 x int], sbyte, float }
4
5 %MixedB = type { float, %MixedA, float }
6
7 %fmtArg = internal global [44 x sbyte] c"sqrt(2) = %g\0Aexp(1) = %g\0Api = %g\0Afive = %g\0A\00"; <[44 x sbyte]*> [#uses=1]
8
9 implementation
10
11 declare int "printf"(sbyte*, ...)
12
13 int "main"()
14 begin
15 %ScalarA = alloca %MixedA
16 %ScalarB = alloca %MixedB
17 %ArrayA = alloca %MixedA, uint 4
18 %ArrayB = alloca %MixedB, uint 3
19
20 store float 1.4142, %MixedA* %ScalarA, uint 0, ubyte 0
21 store float 2.7183, %MixedB* %ScalarB, uint 0, ubyte 1, ubyte 0
22
23 %fptrA = getelementptr %MixedA* %ArrayA, uint 1, ubyte 0
24 %fptrB = getelementptr %MixedB* %ArrayB, uint 2, ubyte 1, ubyte 0
25
26 store float 3.1415, float* %fptrA
27 store float 5.0, float* %fptrB
28
29 %sqrtTwo = load %MixedA* %ScalarA, uint 0, ubyte 0
30 %exp = load %MixedB* %ScalarB, uint 0, ubyte 1, ubyte 0
31 %pi = load %MixedA* %ArrayA, uint 1, ubyte 0
32 %five = load %MixedB* %ArrayB, uint 2, ubyte 1, ubyte 0
33
34 %dsqrtTwo = cast float %sqrtTwo to double
35 %dexp = cast float %exp to double
36 %dpi = cast float %pi to double
37 %dfive = cast float %five to double
38
39 %castFmt = getelementptr [44 x sbyte]* %fmtArg, uint 0, uint 0
40 call int (sbyte*, ...)* %printf(sbyte* %castFmt, double %dsqrtTwo, double %dexp, double %dpi, double %dfive)
41
42 ret int 0
43 end
0 ;;
1 ;; Test the sequence:
2 ;; cast -> setle 0, %cast -> br %cond
3 ;; This sequence should cause the cast value to be forwarded twice,
4 ;; i.e., cast is forwarded to the setle and teh setle is forwarded
5 ;; to the branch.
6 ;; register argument of the "branch-on-register" instruction, i.e.,
7 ;;
8 ;; This produces the bogus output instruction:
9 ;; brlez , .L_SumArray_bb3.
10 ;; This came from %bb1 of sumarrray.ll generated from sumarray.c.
11
12
13 ;;;; ******************************************************
14 implementation
15 ;;;; ******************************************************
16
17 int "SumArray"(int %Num)
18 begin
19 bb0: ;[#uses=3]
20 br label %Top
21 Top:
22 %Num = alloca int ; [#uses=2]
23 store int %Num, int * %Num
24 %reg108 = load int * %Num ; [#uses=2]
25 %cast1006 = cast int %reg108 to uint ; [#uses=1]
26 %cond1001 = setle uint %cast1006, 0 ; [#uses=1]
27 br bool %cond1001, label %bb6, label %Top
28
29 bb6:
30 ret int 42
31 end
32
0 ; Test that a negative constant smaller than 64 bits (e.g., int)
1 ; is correctly implemented with sign-extension.
2 ; In particular, the current code generated is:
3 ;
4 ; main:
5 ; .L_main_LL_0:
6 ; save %o6, -224, %o6
7 ; setx .G_fmtArg_1, %o1, %o0
8 ; setuw 1, %o1 ! i = 1
9 ; setuw 4294967295, %o3 ! THE BUG: 0x00000000ffffffff
10 ; setsw 0, %i0
11 ; add %i6, 1999, %o2 ! fval
12 ; add %o1, %g0, %o1
13 ; add %o0, 0, %o0
14 ; mulx %o1, %o3, %o1 ! ERROR: 0xffffffff; should be -1
15 ; add %o1, 3, %o1 ! ERROR: 0x100000002; should be 0x2
16 ; mulx %o1, 12, %o3 !
17 ; add %o2, %o3, %o3 ! produces bad address!
18 ; call printf
19 ; nop
20 ; jmpl %i7+8, %g0
21 ; restore %g0, 0, %g0
22 ;
23 ; llc produces:
24 ; ioff = 2 fval = 0xffffffff7fffec90 &fval[2] = 0xb7fffeca8
25 ; instead of:
26 ; ioff = 2 fval = 0xffffffff7fffec90 &fval[2] = 0xffffffff7fffeca8
27 ;
28
29 %Results = type { float, float, float }
30
31 %fmtArg = internal global [39 x sbyte] c"ioff = %u\09fval = 0x%p\09&fval[2] = 0x%p\0A\00"; <[39 x sbyte]*> [#uses=1]
32
33 implementation
34
35 declare int "printf"(sbyte*, ...)
36
37 int "main"()
38 begin
39 %fval = alloca %Results, uint 4
40 %i = add uint 1, 0 ; i = 1
41 %iscale = mul uint %i, 4294967295 ; i*-1 = -1
42 %ioff = add uint %iscale, 3 ; 3+(-i) = 2
43 %fptr = getelementptr %Results* %fval, uint %ioff ; &fval[2]
44 %castFmt = getelementptr [39 x sbyte]* %fmtArg, uint 0, uint 0
45 call int (sbyte*, ...)* %printf(sbyte* %castFmt, uint %ioff, %Results* %fval, %Results* %fptr)
46 ret int 0
47 end
0 implementation
1 declare int "printf"(sbyte*, int, float)
2
3
4 int "testissue"(int %i, float %x, float %y)
5 begin
6 bb1:
7 %x1 = mul float %x, %y ;; x1
8 %y1 = mul float %y, 0.75 ;; y1
9 %z1 = add float %x1, %y1 ;; z1 = x1 + y1
10
11 %x2 = mul float %x, 0.5 ;; x2
12 %y2 = mul float %y, 0.9 ;; y2
13 %z2 = add float %x2, %y2 ;; z2 = x2 + y2
14
15 %z3 = add float %z1, %z2 ;; z3 = z1 + z2
16
17 %i1 = shl int %i, ubyte 3 ;; i1
18 %j1 = add int %i, 7 ;; j1
19 %m1 = add int %i1, %j1 ;; k1 = i1 + j1
20 ;; %m1 = div int %k1, 99 ;; m1 = k1 / 99
21
22 %b = setle int %m1, 6 ;; (m1 <= 6)?
23 br bool %b, label %bb1, label %bb2
24
25 bb2:
26 %Msg = cast ulong 0 to sbyte *
27 call int %printf(sbyte* %Msg, int %m1, float %z3)
28 ret int 0
29 end
0 %AConst = constant int 123
1
2 implementation
3
4 ; Test setting values of different constants in registers.
5 ;
6 void "testConsts"(int %N, float %X)
7 begin
8 ;
9 %a = add int %N, 1 ; 1 should be put in immed field
10 %a2= add int %N, 12345678 ; constant has to be loaded
11 %b = add short 4, 3 ; one of the operands shd be immed
12 %c = add float %X, 0.0 ; will this be optimzzed?
13 %d = add float %X, 3.1415 ; constant has to be loaded
14 %f = add uint 4294967295, 10 ; result shd be 9 (not in immed fld)
15 %g = add ushort 20, 65535 ; result shd be 19 (65536 in immed fld)
16 %g = add ushort 65535, 30 ; result shd be 29 (not in immed fld)
17 %h = add ubyte 40, 255 ; result shd be 39 (255 in immed fld)
18 %h = add ubyte 255, 50 ; result shd be 49 (not in immed fld)
19
20 ret void
21 end
22
23 ; A SetCC whose result is used should produce instructions to
24 ; compute the boolean value in a register. One whose result
25 ; is unused will only generate the condition code but not
26 ; the boolean result.
27 ;
28 void "unusedBool"(int * %x, int * %y)
29 begin
30 ;
31 seteq int * %x, %y ; :0 [#uses=1]
32 not bool %0 ; :1 [#uses=0]
33 setne int * %x, %y ; :2 [#uses=0]
34 ret void
35 end
36
37 ; A constant argument to a Phi produces a Cast instruction in the
38 ; corresponding predecessor basic block. This checks a few things:
39 ; -- phi arguments coming from the bottom of the same basic block
40 ; (they should not be forward substituted in the machine code!)
41 ; -- code generation for casts of various types
42 ; -- use of immediate fields for integral constants of different sizes
43 ; -- branch on a constant condition
44 ;
45 void "mergeConstants"(int * %x, int * %y)
46 begin
47 ;
48 br label %Top
49 Top:
50 phi int [ 0, %0 ], [ 1, %Top ], [ 524288, %Next ]
51 phi float [ 0.0, %0 ], [ 1.0, %Top ], [ 2.0, %Next ]
52 phi double [ 0.5, %0 ], [ 1.5, %Top ], [ 2.5, %Next ]
53 phi bool [ true, %0 ], [ false,%Top ], [ true, %Next ]
54 br bool true, label %Top, label %Next
55 Next:
56 br label %Top
57 end
58
59
60
61 ; A constant argument to a cast used only once should be forward substituted
62 ; and loaded where needed, which happens is:
63 ; -- User of cast has no immediate field
64 ; -- User of cast has immediate field but constant is too large to fit
65 ; or constant is not resolved until later (e.g., global address)
66 ; -- User of cast uses it as a call arg. or return value so it is an implicit
67 ; use but has to be loaded into a virtual register so that the reg.
68 ; allocator can allocate the appropriate phys. reg. for it
69 ;
70 int* "castconst"(float)
71 begin
72 ;
73 %castbig = cast ulong 99999999 to int
74 %castsmall = cast ulong 1 to int
75 %usebig = add int %castbig, %castsmall
76
77 %castglob = cast int* %AConst to long*
78 %dummyl = load long* %castglob
79
80 %castnull = cast ulong 0 to int*
81 ret int* %castnull
82 end
83
84
85
86 ; Test branch-on-comparison-with-zero, in two ways:
87 ; 1. can be folded
88 ; 2. cannot be folded because result of comparison is used twice
89 ;
90 void "testbool"(int, int) ; Def %0, %1
91 const int 0 ; Def 2
92 const int -4 ; Def 3
93 begin
94 ;
95 br label %Top
96 Top:
97 add int %0, %1 ; Def 4
98 sub int %4, %3 ; Def 5
99 setle int %5, %2 ; Def 0 - bool plane
100 br bool %0, label %retlbl, label %loop
101
102 loop:
103 add int %0, %1 ; Def 6
104 sub int %4, %3 ; Def 7
105 setle int %7, %2 ; Def 1 - bool
106 not bool %1 ; Def 2 - bool. first use of bool %1
107 br bool %1, label %loop, label %Top ; second use of bool %1
108
109 retlbl:
110 ret void
111 end
112
113
114 ; Test branch on floating point comparison
115 ;
116 void "testfloatbool"(float %x, float %y) ; Def %0, %1 - float
117 begin
118 ;
119 br label %Top
120 Top:
121 %p = add float %x, %y ; Def 2 - float
122 %z = sub float %x, %y ; Def 3 - float
123 %b = setle float %p, %z ; Def 0 - bool
124 %c = not bool %b ; Def 1 - bool
125 br bool %b, label %Top, label %goon
126 goon:
127 ret void
128 end
129
130
131 ; Test cases where an LLVM instruction requires no machine
132 ; instructions (e.g., cast int* to long). But there are 2 cases:
133 ; 1. If the result register has only a single use and the use is in the
134 ; same basic block, the operand will be copy-propagated during
135 ; instruction selection.
136 ; 2. If the result register has multiple uses or is in a different
137 ; basic block, it cannot (or will not) be copy propagated during
138 ; instruction selection. It will generate a
139 ; copy instruction (add-with-0), but this copy should get coalesced
140 ; away by the register allocator.
141 ;
142 int "checkForward"(int %N, int* %A)
143 begin
144
145 bb2: ;;
146 %reg114 = shl int %N, ubyte 2 ;;
147 %cast115 = cast int %reg114 to int* ;; reg114 will be propagated
148 %reg116 = add int* %A, %cast115 ;;
149 %reg118 = load int* %reg116 ;;
150 %cast117 = cast int %reg118 to long ;; reg118 will be copied 'cos
151 %reg159 = add long 1234567, %cast117 ;; cast117 has 2 uses, here
152 %reg160 = add long 7654321, %cast117 ;; and here.
153 ret void
154 end
0 ; July 6, 2002 -- LLC Regression test
1 ; This test case checks if the integer CC register %xcc (or %ccr)
2 ; is correctly spilled. The code fragment came from function
3 ; MakeGraph in Olden-mst.
4 ; The original code made all comparisons with 0, so that the %xcc
5 ; register is not needed for the branch in the first basic block.
6 ; Replace 0 with 1 in the first comparson so that the
7 ; branch-on-register instruction cannot be used directly, i.e.,
8 ; the %xcc register is needed for the first branch.
9 ;
10 %Graph = type %struct.graph_st*
11 %Hash = type %struct.hash*
12 %HashEntry = type %struct.hash_entry*
13 %Vertex = type %struct.vert_st*
14 %struct.graph_st = type { [1 x %Vertex] }
15 %struct.hash = type { %HashEntry*, int (uint)*, int }
16 %struct.hash_entry = type { uint, sbyte*, %HashEntry }
17 %struct.vert_st = type { int, %Vertex, %Hash }
18 %HashRange = internal uninitialized global int ; [#uses=1]
19 %.LC0 = internal global [13 x sbyte] c"Make phase 2\00" ; <[13 x sbyte]*> [#uses=1]
20 %.LC1 = internal global [13 x sbyte] c"Make phase 3\00" ; <[13 x sbyte]*> [#uses=1]
21 %.LC2 = internal global [13 x sbyte] c"Make phase 4\00" ; <[13 x sbyte]*> [#uses=1]
22 %.LC3 = internal global [15 x sbyte] c"Make returning\00" ; <[15 x sbyte]*> [#uses=1]
23
24 implementation ; Functions:
25
26 %Graph %MakeGraph(int %numvert, int %numproc) {
27 bb1: ;[#uses=1]
28 %reg111 = add int %numproc, -1 ; [#uses=3]
29 %cond275 = setlt int %reg111, 1 ; [#uses=2]
30 %cond276 = setle int %reg111, 0 ; [#uses=1]
31 %cond277 = setge int %numvert, 0 ; [#uses=2]
32 %reg162 = add int %numvert, 3 ; [#uses=2]
33 br bool %cond275, label %bb7, label %bb4
34
35 bb4:
36 br bool %cond276, label %bb7, label %bb5
37
38 bb5:
39 br bool %cond277, label %bb7, label %bb6
40
41 bb6: ;[#uses=2]
42 ret %Graph null
43
44 bb7: ;[#uses=2]
45 ret %Graph null
46 }
47
48 int %main(int argc, sbyte** argv) {
49 bb1:
50 %reg100 = call %struct.graph_st* (int, int)* %MakeGraph(1, 1)
51
0 /*
1 * Program: llc
2 *
3 * Test Name: badfuncptr.c
4 *
5 * Test Problem:
6 * Indirect call via function pointer is mishandled in reg. alloc.
7 * The indirect call address was allocated the same register as the
8 * first outgoing argument, so it was overwritten before the call.
9 *
10 * Test Resolution:
11 * In PhyRegAlloc.cpp, mark the live range for the indirect call
12 * address as having a Call Interference. This has to be done
13 * as a special case since it may not be live after the call.
14 *
15 * Resolution Status:
16 * Fixed on 3/29/02 -- Adve.
17 */
18 /* For copyright information, see olden_v1.0/COPYRIGHT */
19
20 #include
21 /* #include "hash.h" */
22 /*--------*/
23 /* hash.h */
24 /*--------*/
25 /* For copyright information, see olden_v1.0/COPYRIGHT */
26
27 #include "stdio.h"
28
29 typedef struct hash_entry {
30 unsigned int key;
31 void *entry;
32 struct hash_entry *next;
33 } *HashEntry;
34
35 typedef struct hash {
36 HashEntry *array;
37 int (*mapfunc)(unsigned int);
38 int size;
39 } *Hash;
40
41 Hash MakeHash(int size, int (*map)(unsigned int));
42 void *HashLookup(unsigned int key, Hash hash);
43 void HashInsert(void *entry,unsigned int key, Hash hash);
44 void HashDelete(unsigned int key, Hash hash);
45 /*--------*/
46 /* END hash.h */
47 /*--------*/
48
49 #define assert(num,a) if (!(a)) {printf("Assertion failure:%d in hash\n",num); exit(-1);}
50
51 void *HashLookup(unsigned int key, Hash hash)
52 {
53 int j;
54 HashEntry ent;
55
56 j = (hash->mapfunc)(key); /* 14% miss in hash->mapfunc */
57 assert(1,j>=0);
58 assert(2,jsize);
59 for (ent = hash->array[j]; /* 17% miss in hash->array[j] */ /* adt_pf can't detect :( */
60 ent && /* 47% miss in ent->key */ /* adt_pf can detect :) */
61 ent->key!=key;
62 ent=ent->next); /* 8% miss in ent->next */ /* adt_pf can detect :) */
63 if (ent) return ent->entry;
64 return NULL;
65 }
66
67 /* essentially dummy main so testing does not fail */
68 int
69 main()
70 {
71 printf("&HashLookup = 0x%p\n", HashLookup);
72 return 0;
73 }
0 implementation
1
2 int "main"()
3 begin
4 bb0:
5 %reg109 = malloc int, uint 100
6 br label %bb2
7
8 bb2:
9 %cann-indvar1 = phi int [ 0, %bb0 ], [ %add1-indvar1, %bb2 ]
10 %reg127 = mul int %cann-indvar1, 2
11 %add1-indvar1 = add int %cann-indvar1, 1
12 store int 999, int * %reg109, uint 0
13 %cond1015 = setle int 1, 99
14 %reg128 = add int %reg127, 2
15 br bool %cond1015, label %bb2, label %bb4
16
17 bb4: ;[#uses=3]
18 %cann-indvar = phi uint [ %add1-indvar, %bb4 ], [ 0, %bb2 ]
19 %add1-indvar = add uint %cann-indvar, 1 ; [#uses=1]
20 store int 333, int * %reg109, uint 0
21 %reg131 = add uint %add1-indvar, 3 ; [#uses=1]
22 %cond1017 = setle uint %reg131, 99 ; [#uses=1]
23 br bool %cond1017, label %bb4, label %bb5
24
25 bb5:
26 ret int 0
27 end
0 #include
1 #include
2
3
4 #undef LLVM_CAN_PASS_STRUCTS_BY_VALUE
5 #ifdef LLVM_CAN_PASS_STRUCTS_BY_VALUE
6 typedef struct SmallStruct_struct {
7 char c1, c2, c3, c4;
8 int n;
9 } SmallStruct;
10
11
12 typedef struct BigStruct_struct {
13 char c1, c2, c3, c4;
14 double d1, d2; /* Note: d1 will need padding */
15 int n;
16 struct BigStruct_struct* next; /* Note: next will need padding */
17 } BigStruct;
18
19
20 SmallStruct
21 printStructArgs(SmallStruct s1, /* Could fit in reg */
22 int a1, float a2, char a3, double a4, char* a5,
23 BigStruct s2, /* Must go on stack */
24 int a6, float a7, char a8, double a9, char* a10,
25 SmallStruct s3, /* Probably no available regs */
26 int a11, float a12, char a13, double a14, char* a15)
27 {
28 SmallStruct result;
29
30 printf("\nprintStructArgs with 13 arguments:\n");
31 printf("\tArg 1 : %c %c %c %c %d\n", s1.c1, s1.c2, s1.c3, s1.c4, s1.n);
32 printf("\tArgs 2-6 : %d %f %c %lf %c\n", a1, a2, a3, a4, *a5);
33 printf("\tArg 7 : %c %c %c %c %lf %lf %d %p\n",
34 s2.c1, s2.c2, s2.c3, s2.c4, s2.d1, s2.d2, s2.n,s2.next);
35 printf("\tArg 8 : %c %c %c %c %d\n", s3.c1, s3.c2, s3.c3, s3.c4, s3.n);
36 printf("\tArgs 9-13 : %d %f %c %lf %c\n", a6, a7, a8, a9, *a10);
37 printf("\tArgs 14-18: %d %f %c %lf %c\n", a11, a12, a13, a14, *a15);
38 printf("\n");
39
40 result.c1 = s2.c1;
41 result.c2 = s2.c2;
42 result.c3 = s2.c3;
43 result.c4 = s2.c4;
44 result.n = s2.n;
45
46 return result;
47 }
48 #endif /* LLVM_CAN_PASS_STRUCTS_BY_VALUE */
49
50 #undef LLC_SUPPORTS_VARARGS_FUNCTIONS
51 #ifdef LLC_SUPPORTS_VARARGS_FUNCTIONS
52 void
53 printVarArgs(int a1, ...)
54 {
55 double a2, a7, a12; /* float is promoted to double! */
56 int a3, a8, a13; /* char is promoted to int! */
57 double a4, a9, a14;
58 char *a5, *a10, *a15;
59 int a6, a11;
60
61 va_list ap;
62 va_start(ap, a1);
63 a2 = va_arg(ap, double);
64 a3 = va_arg(ap, int);
65 a4 = va_arg(ap, double);
66 a5 = va_arg(ap, char*);
67
68 a6 = va_arg(ap, int);
69 a7 = va_arg(ap, double);
70 a8 = va_arg(ap, int);
71 a9 = va_arg(ap, double);
72 a10 = va_arg(ap, char*);
73
74 a11 = va_arg(ap, int);
75 a12 = va_arg(ap, double);
76 a13 = va_arg(ap, int);
77 a14 = va_arg(ap, double);
78 a15 = va_arg(ap, char*);
79
80 printf("\nprintVarArgs with 15 arguments:\n");
81 printf("\tArgs 1-5 : %d %f %c %lf %c\n", a1, a2, a3, a4, *a5);
82 printf("\tArgs 6-10 : %d %f %c %lf %c\n", a6, a7, a8, a9, *a10);
83 printf("\tArgs 11-14: %d %f %c %lf %c\n", a11, a12, a13, a14, *a15);
84 printf("\n");
85 return;
86 }
87 #endif /* LLC_SUPPORTS_VARARGS_FUNCTIONS */
88
89
90 void
91 printArgsNoRet(int a1, float a2, char a3, double a4, char* a5,
92 int a6, float a7, char a8, double a9, char* a10,
93 int a11, float a12, char a13, double a14, char* a15)
94 {
95 printf("\nprintArgsNoRet with 15 arguments:\n");
96 printf("\tArgs 1-5 : %d %f %c %lf %c\n", a1, a2, a3, a4, *a5);
97 printf("\tArgs 6-10 : %d %f %c %lf %c\n", a6, a7, a8, a9, *a10);
98 printf("\tArgs 11-14: %d %f %c %lf %c\n", a11, a12, a13, a14, *a15);
99 printf("\n");
100 return;
101 }
102
103
104 int
105 main(int argc, char** argv)
106 {
107 #ifdef LLVM_CAN_PASS_STRUCTS_BY_VALUE
108 SmallStruct s1, s3, result;
109 BigStruct s2;
110 #endif /* LLVM_CAN_PASS_STRUCTS_BY_VALUE */
111
112 printArgsNoRet(1, 2.1, 'c', 4.1, "e",
113 6, 7.1, 'h', 9.1, "j",
114 11, 12.1, 'm', 14.1, "o");
115
116 #ifdef LLC_SUPPORTS_VARARGS_FUNCTIONS
117 printVarArgs(1, 2.2, 'c', 4.2, "e",
118 6, 7.2, 'h', 9.2, "j",
119 11, 12.2, 'm', 14.2, "o");
120 #endif /* LLC_SUPPORTS_VARARGS_FUNCTIONS */
121
122 #ifdef LLVM_CAN_PASS_STRUCTS_BY_VALUE
123 s1.c1 = 'a';
124 s1.c2 = 'b';
125 s1.c3 = 'c';
126 s1.c4 = 'd';
127 s1.n = 111;
128
129 s2.c1 = 'h';
130 s2.c2 = 'i';
131 s2.c3 = 'j';
132 s2.c4 = 'k';
133 s2.d1 = 1.1;
134 s2.d2 = 2.2;
135 s2.n = 222;
136 s2.next = &s2;
137
138 s3.c1 = 'w';
139 s3.c2 = 'x';
140 s3.c3 = 'y';
141 s3.c4 = 'z';
142 s3.n = 333;
143
144 result = printStructArgs(s1,
145 1, 2.0, 'c', 4.0, "e",
146 s2,
147 6, 7.0, 'h', 9.0, "j",
148 s3);
149
150 printf("\nprintStructArgs returns:\n\t%c %c %c %c %d\n\n",
151 result.c1, result.c2, result.c3, result.c4, result.n);
152 #endif /* LLVM_CAN_PASS_STRUCTS_BY_VALUE */
153
154 return 0;
155 }
0 #include
1 #include
2 #include
3
4 int
5 main(int argc, char** argv)
6 {
7 char c1;
8 short s1, ssf1, ssd1;
9 uint8_t ubs0;
10 int8_t bs0;
11 unsigned char ubc0, uc2;
12 unsigned short us2, usf1, usd1;
13 int ic3, is3, sif1, sid1;
14 uint uic4, uis4, uif1, uid1;
15 long slf1, sld1;
16 ulong ulf1, uld1;
17 float f1;
18 double d1;
19
20 /* Test integer to integer conversions */
21
22 c1 = (char) (argc >= 2)? atoi(argv[1]) : 0xff64; /* 100 = 'd' */
23 s1 = (short) (argc >= 3)? atoi(argv[2]) : -769; /* 0xf7ff = -769 */
24
25 ubc0 = (unsigned char) c1; /* 100 = 'd' */
26 ubs0 = (uint8_t) s1; /* 0xff = 255 */
27 bs0 = (int8_t) s1; /* 0xff = -1 */
28
29 uc2 = (unsigned char) c1; /* 100 = 'd' */
30 us2 = (unsigned short) s1; /* 0xf7ff = 64767 */
31
32 ic3 = (int) c1; /* 100 = 'd' */
33 is3 = (int) s1; /* 0xfffff7ff = -769 */
34
35 uic4 = (unsigned int) c1; /* 100 = 'd' */
36 uis4 = (unsigned int) s1; /* 0xfffff7ff = 4294966527 */
37
38 printf("ubc0 = '%c'\n", ubc0);
39 printf("ubs0 = %u\n", ubs0);
40 printf("bs0 = %d\n", bs0);
41 printf("c1 = '%c'\n", c1);
42 printf("s1 = %d\n", s1);
43 printf("uc2 = '%c'\n", uc2);
44 printf("us2 = %u\n", us2);
45 printf("ic3 = '%c'\n", ic3);
46 printf("is3 = %d\n", is3);
47 printf("uic4 = '%c'\n", uic4);
48 printf("uis4 = %u\n", uis4);
49
50 /* Test floating-point to integer conversions */
51 f1 = (float) (argc >= 4)? atof(argv[3]) : 1.0;
52 d1 = (argc >= 5)? atof(argv[4]) : 2.0;
53
54 usf1 = (unsigned short) f1;
55 usd1 = (unsigned short) d1;
56 uif1 = (unsigned int) f1;
57 uid1 = (unsigned int) d1;
58 ulf1 = (unsigned long) f1;
59 uld1 = (unsigned long) d1;
60
61 ssf1 = (short) f1;
62 ssd1 = (short) d1;
63 sif1 = (int) f1;
64 sid1 = (int) d1;
65 slf1 = (long) f1;
66 sld1 = (long) d1;
67
68 printf("usf1 = %u\n", usf1);
69 printf("usd1 = %u\n", usd1);
70 printf("uif1 = %u\n", uif1);
71 printf("uid1 = %u\n", uid1);
72 printf("ulf1 = %u\n", ulf1);
73 printf("uld1 = %u\n", uld1);
74
75 printf("ssf1 = %d\n", ssf1);
76 printf("ssd1 = %d\n", ssd1);
77 printf("sif1 = %d\n", sif1);
78 printf("sid1 = %d\n", sid1);
79 printf("slf1 = %d\n", slf1);
80 printf("sld1 = %d\n", sld1);
81
82 return 0;
83 }
0 ; Test that a sequence of constant indices are folded correctly
1 ; into the equivalent offset at compile-time.
2
3 %MixedA = type { float, [15 x int], sbyte, float }
4
5 %MixedB = type { float, %MixedA, float }
6
7 %fmtArg = internal global [44 x sbyte] c"sqrt(2) = %g\0Aexp(1) = %g\0Api = %g\0Afive = %g\0A\00"; <[44 x sbyte]*> [#uses=1]
8
9 implementation
10
11 declare int "printf"(sbyte*, ...)
12
13 int "main"()
14 begin
15 %ScalarA = alloca %MixedA
16 %ScalarB = alloca %MixedB
17 %ArrayA = alloca %MixedA, uint 4
18 %ArrayB = alloca %MixedB, uint 3
19
20 store float 1.4142, %MixedA* %ScalarA, uint 0, ubyte 0
21 store float 2.7183, %MixedB* %ScalarB, uint 0, ubyte 1, ubyte 0
22
23 %fptrA = getelementptr %MixedA* %ArrayA, uint 1, ubyte 0
24 %fptrB = getelementptr %MixedB* %ArrayB, uint 2, ubyte 1, ubyte 0
25
26 store float 3.1415, float* %fptrA
27 store float 5.0, float* %fptrB
28
29 %sqrtTwo = load %MixedA* %ScalarA, uint 0, ubyte 0
30 %exp = load %MixedB* %ScalarB, uint 0, ubyte 1, ubyte 0
31 %pi = load %MixedA* %ArrayA, uint 1, ubyte 0
32 %five = load %MixedB* %ArrayB, uint 2, ubyte 1, ubyte 0
33
34 %dsqrtTwo = cast float %sqrtTwo to double
35 %dexp = cast float %exp to double
36 %dpi = cast float %pi to double
37 %dfive = cast float %five to double
38
39 %castFmt = getelementptr [44 x sbyte]* %fmtArg, uint 0, uint 0
40 call int (sbyte*, ...)* %printf(sbyte* %castFmt, double %dsqrtTwo, double %dexp, double %dpi, double %dfive)
41
42 ret int 0
43 end
0 ;;
1 ;; Test the sequence:
2 ;; cast -> setle 0, %cast -> br %cond
3 ;; This sequence should cause the cast value to be forwarded twice,
4 ;; i.e., cast is forwarded to the setle and teh setle is forwarded
5 ;; to the branch.
6 ;; register argument of the "branch-on-register" instruction, i.e.,
7 ;;
8 ;; This produces the bogus output instruction:
9 ;; brlez , .L_SumArray_bb3.
10 ;; This came from %bb1 of sumarrray.ll generated from sumarray.c.
11
12
13 ;;;; ******************************************************
14 implementation
15 ;;;; ******************************************************
16
17 int "SumArray"(int %Num)
18 begin
19 bb0: ;[#uses=3]
20 br label %Top
21 Top:
22 %Num = alloca int ; [#uses=2]
23 store int %Num, int * %Num
24 %reg108 = load int * %Num ; [#uses=2]
25 %cast1006 = cast int %reg108 to uint ; [#uses=1]
26 %cond1001 = setle uint %cast1006, 0 ; [#uses=1]
27 br bool %cond1001, label %bb6, label %Top
28
29 bb6:
30 ret int 42
31 end
32
0 ; Test that a negative constant smaller than 64 bits (e.g., int)
1 ; is correctly implemented with sign-extension.
2 ; In particular, the current code generated is:
3 ;
4 ; main:
5 ; .L_main_LL_0:
6 ; save %o6, -224, %o6
7 ; setx .G_fmtArg_1, %o1, %o0
8 ; setuw 1, %o1 ! i = 1
9 ; setuw 4294967295, %o3 ! THE BUG: 0x00000000ffffffff
10 ; setsw 0, %i0
11 ; add %i6, 1999, %o2 ! fval
12 ; add %o1, %g0, %o1
13 ; add %o0, 0, %o0
14 ; mulx %o1, %o3, %o1 ! ERROR: 0xffffffff; should be -1
15 ; add %o1, 3, %o1 ! ERROR: 0x100000002; should be 0x2
16 ; mulx %o1, 12, %o3 !
17 ; add %o2, %o3, %o3 ! produces bad address!
18 ; call printf
19 ; nop
20 ; jmpl %i7+8, %g0
21 ; restore %g0, 0, %g0
22 ;
23 ; llc produces:
24 ; ioff = 2 fval = 0xffffffff7fffec90 &fval[2] = 0xb7fffeca8
25 ; instead of:
26 ; ioff = 2 fval = 0xffffffff7fffec90 &fval[2] = 0xffffffff7fffeca8
27 ;
28
29 %Results = type { float, float, float }
30
31 %fmtArg = internal global [39 x sbyte] c"ioff = %u\09fval = 0x%p\09&fval[2] = 0x%p\0A\00"; <[39 x sbyte]*> [#uses=1]
32
33 implementation
34
35 declare int "printf"(sbyte*, ...)
36
37 int "main"()
38 begin
39 %fval = alloca %Results, uint 4
40 %i = add uint 1, 0 ; i = 1
41 %iscale = mul uint %i, 4294967295 ; i*-1 = -1
42 %ioff = add uint %iscale, 3 ; 3+(-i) = 2
43 %fptr = getelementptr %Results* %fval, uint %ioff ; &fval[2]
44 %castFmt = getelementptr [39 x sbyte]* %fmtArg, uint 0, uint 0
45 call int (sbyte*, ...)* %printf(sbyte* %castFmt, uint %ioff, %Results* %fval, %Results* %fptr)
46 ret int 0
47 end
0 /* For copyright information, see olden_v1.0/COPYRIGHT */
1
2 /**********************************************************
3 * poisson.c: handles math routines for health.c *
4 **********************************************************/
5
6 #include
7 #include
8
9 /* From health.h */
10 #define IA 16807
11 #define IM 2147483647
12 #define AM (1.0 / IM)
13 #define IQ 127773
14 #define IR 2836
15 #define MASK 123459876
16
17 float my_rand(long idum)
18 {
19 long k;
20 float answer;
21
22 idum ^= MASK;
23 k = idum / IQ;
24 idum = IA * (idum - k * IQ) - IR * k;
25 idum ^= MASK;
26 if (idum < 0)
27 idum += IM;
28 answer = AM * idum;
29 return answer;
30 }
31
32 int
33 main(int argc, char** argv)
34 {
35 printf("my_rand(%d) = %g\n", 2555540, my_rand(2555540));
36 printf("my_rand(%d) = %g\n", 2427763, my_rand(2427763));
37 return 0;
38 }
39
40
0 implementation
1 declare int "printf"(sbyte*, int, float)
2
3
4 int "testissue"(int %i, float %x, float %y)
5 begin
6 bb1:
7 %x1 = mul float %x, %y ;; x1
8 %y1 = mul float %y, 0.75 ;; y1
9 %z1 = add float %x1, %y1 ;; z1 = x1 + y1
10
11 %x2 = mul float %x, 0.5 ;; x2
12 %y2 = mul float %y, 0.9 ;; y2
13 %z2 = add float %x2, %y2 ;; z2 = x2 + y2
14
15 %z3 = add float %z1, %z2 ;; z3 = z1 + z2
16
17 %i1 = shl int %i, ubyte 3 ;; i1
18 %j1 = add int %i, 7 ;; j1
19 %m1 = add int %i1, %j1 ;; k1 = i1 + j1
20 ;; %m1 = div int %k1, 99 ;; m1 = k1 / 99
21
22 %b = setle int %m1, 6 ;; (m1 <= 6)?
23 br bool %b, label %bb1, label %bb2
24
25 bb2:
26 %Msg = cast ulong 0 to sbyte *
27 call int %printf(sbyte* %Msg, int %m1, float %z3)
28 ret int 0
29 end
0 %AConst = constant int 123
1
2 implementation
3
4 ; Test setting values of different constants in registers.
5 ;
6 void "testConsts"(int %N, float %X)
7 begin
8 ;
9 %a = add int %N, 1 ; 1 should be put in immed field
10 %a2= add int %N, 12345678 ; constant has to be loaded
11 %b = add short 4, 3 ; one of the operands shd be immed
12 %c = add float %X, 0.0 ; will this be optimzzed?
13 %d = add float %X, 3.1415 ; constant has to be loaded
14 %f = add uint 4294967295, 10 ; result shd be 9 (not in immed fld)
15 %g = add ushort 20, 65535 ; result shd be 19 (65536 in immed fld)
16 %g = add ushort 65535, 30 ; result shd be 29 (not in immed fld)
17 %h = add ubyte 40, 255 ; result shd be 39 (255 in immed fld)
18 %h = add ubyte 255, 50 ; result shd be 49 (not in immed fld)
19
20 ret void
21 end
22
23 ; A SetCC whose result is used should produce instructions to
24 ; compute the boolean value in a register. One whose result
25 ; is unused will only generate the condition code but not
26 ; the boolean result.
27 ;
28 void "unusedBool"(int * %x, int * %y)
29 begin
30 ;
31 seteq int * %x, %y ; :0 [#uses=1]
32 not bool %0 ; :1 [#uses=0]
33 setne int * %x, %y ; :2 [#uses=0]
34 ret void
35 end
36
37 ; A constant argument to a Phi produces a Cast instruction in the
38 ; corresponding predecessor basic block. This checks a few things:
39 ; -- phi arguments coming from the bottom of the same basic block
40 ; (they should not be forward substituted in the machine code!)
41 ; -- code generation for casts of various types
42 ; -- use of immediate fields for integral constants of different sizes
43 ; -- branch on a constant condition
44 ;
45 void "mergeConstants"(int * %x, int * %y)
46 begin
47 ;
48 br label %Top
49 Top:
50 phi int [ 0, %0 ], [ 1, %Top ], [ 524288, %Next ]
51 phi float [ 0.0, %0 ], [ 1.0, %Top ], [ 2.0, %Next ]
52 phi double [ 0.5, %0 ], [ 1.5, %Top ], [ 2.5, %Next ]
53 phi bool [ true, %0 ], [ false,%Top ], [ true, %Next ]
54 br bool true, label %Top, label %Next
55 Next:
56 br label %Top
57 end
58
59
60
61 ; A constant argument to a cast used only once should be forward substituted
62 ; and loaded where needed, which happens is:
63 ; -- User of cast has no immediate field
64 ; -- User of cast has immediate field but constant is too large to fit
65 ; or constant is not resolved until later (e.g., global address)
66 ; -- User of cast uses it as a call arg. or return value so it is an implicit
67 ; use but has to be loaded into a virtual register so that the reg.
68 ; allocator can allocate the appropriate phys. reg. for it
69 ;
70 int* "castconst"(float)
71 begin
72 ;
73 %castbig = cast ulong 99999999 to int
74 %castsmall = cast ulong 1 to int
75 %usebig = add int %castbig, %castsmall
76
77 %castglob = cast int* %AConst to long*
78 %dummyl = load long* %castglob
79
80 %castnull = cast ulong 0 to int*
81 ret int* %castnull
82 end
83
84
85
86 ; Test branch-on-comparison-with-zero, in two ways:
87 ; 1. can be folded
88 ; 2. cannot be folded because result of comparison is used twice
89 ;
90 void "testbool"(int, int) ; Def %0, %1
91 const int 0 ; Def 2
92 const int -4 ; Def 3
93 begin
94 ;
95 br label %Top
96 Top:
97 add int %0, %1 ; Def 4
98 sub int %4, %3 ; Def 5
99 setle int %5, %2 ; Def 0 - bool plane
100 br bool %0, label %retlbl, label %loop
101
102 loop:
103 add int %0, %1 ; Def 6
104 sub int %4, %3 ; Def 7
105 setle int %7, %2 ; Def 1 - bool
106 not bool %1 ; Def 2 - bool. first use of bool %1
107 br bool %1, label %loop, label %Top ; second use of bool %1
108
109 retlbl:
110 ret void
111 end
112
113
114 ; Test branch on floating point comparison
115 ;
116 void "testfloatbool"(float %x, float %y) ; Def %0, %1 - float
117 begin
118 ;
119 br label %Top
120 Top:
121 %p = add float %x, %y ; Def 2 - float
122 %z = sub float %x, %y ; Def 3 - float
123 %b = setle float %p, %z ; Def 0 - bool
124 %c = not bool %b ; Def 1 - bool
125 br bool %b, label %Top, label %goon
126 goon:
127 ret void
128 end
129
130
131 ; Test cases where an LLVM instruction requires no machine
132 ; instructions (e.g., cast int* to long). But there are 2 cases:
133 ; 1. If the result register has only a single use and the use is in the
134 ; same basic block, the operand will be copy-propagated during
135 ; instruction selection.
136 ; 2. If the result register has multiple uses or is in a different
137 ; basic block, it cannot (or will not) be copy propagated during
138 ; instruction selection. It will generate a
139 ; copy instruction (add-with-0), but this copy should get coalesced
140 ; away by the register allocator.
141 ;
142 int "checkForward"(int %N, int* %A)
143 begin
144
145 bb2: ;;
146 %reg114 = shl int %N, ubyte 2 ;;
147 %cast115 = cast int %reg114 to int* ;; reg114 will be propagated
148 %reg116 = add int* %A, %cast115 ;;
149 %reg118 = load int* %reg116 ;;
150 %cast117 = cast int %reg118 to long ;; reg118 will be copied 'cos
151 %reg159 = add long 1234567, %cast117 ;; cast117 has 2 uses, here
152 %reg160 = add long 7654321, %cast117 ;; and here.
153 ret void
154 end
0 ; July 6, 2002 -- LLC Regression test
1 ; This test case checks if the integer CC register %xcc (or %ccr)
2 ; is correctly spilled. The code fragment came from function
3 ; MakeGraph in Olden-mst.
4 ; The original code made all comparisons with 0, so that the %xcc
5 ; register is not needed for the branch in the first basic block.
6 ; Replace 0 with 1 in the first comparson so that the
7 ; branch-on-register instruction cannot be used directly, i.e.,
8 ; the %xcc register is needed for the first branch.
9 ;
10 %Graph = type %struct.graph_st*
11 %Hash = type %struct.hash*
12 %HashEntry = type %struct.hash_entry*
13 %Vertex = type %struct.vert_st*
14 %struct.graph_st = type { [1 x %Vertex] }
15 %struct.hash = type { %HashEntry*, int (uint)*, int }
16 %struct.hash_entry = type { uint, sbyte*, %HashEntry }
17 %struct.vert_st = type { int, %Vertex, %Hash }
18 %HashRange = internal uninitialized global int ; [#uses=1]
19 %.LC0 = internal global [13 x sbyte] c"Make phase 2\00" ; <[13 x sbyte]*> [#uses=1]
20 %.LC1 = internal global [13 x sbyte] c"Make phase 3\00" ; <[13 x sbyte]*> [#uses=1]
21 %.LC2 = internal global [13 x sbyte] c"Make phase 4\00" ; <[13 x sbyte]*> [#uses=1]
22 %.LC3 = internal global [15 x sbyte] c"Make returning\00" ; <[15 x sbyte]*> [#uses=1]
23
24 implementation ; Functions:
25
26 %Graph %MakeGraph(int %numvert, int %numproc) {
27 bb1: ;[#uses=1]
28 %reg111 = add int %numproc, -1 ; [#uses=3]
29 %cond275 = setlt int %reg111, 1 ; [#uses=2]
30 %cond276 = setle int %reg111, 0 ; [#uses=1]
31 %cond277 = setge int %numvert, 0 ; [#uses=2]
32 %reg162 = add int %numvert, 3 ; [#uses=2]
33 br bool %cond275, label %bb7, label %bb4
34
35 bb4:
36 br bool %cond276, label %bb7, label %bb5
37
38 bb5:
39 br bool %cond277, label %bb7, label %bb6
40
41 bb6: ;[#uses=2]
42 ret %Graph null
43
44 bb7: ;[#uses=2]
45 ret %Graph null
46 }
47
48 int %main(int argc, sbyte** argv) {
49 bb1:
50 %reg100 = call %struct.graph_st* (int, int)* %MakeGraph(1, 1)
51
0 #include
1
2 /*
3 * Test routines for testing the tracing code.
4 */
5
6 struct DummyStruct {
7 struct DummyStruct* next;
8 int seqnum;
9 };
10
11 int
12 AddCounts(struct DummyStruct* S1,
13 struct DummyStruct* S2,
14 struct DummyStruct* S3, int noPrint)
15 {
16 if (!noPrint)
17 printf("&S1 = %p\t&S2 = %p\t&S3 = %p\n", S1, S2, S3);
18 return S1->seqnum + S2->seqnum + S3->seqnum;
19 }
20
21 void
22 testAllocaOrder(int noPrint)
23 {
24 static int count = 0;
25 struct DummyStruct S1, S2, S3;
26
27 S1.seqnum = ++count;
28 S2.seqnum = ++count;
29 S3.seqnum = ++count;
30
31 printf("sum = %d\n", AddCounts(&S1, &S2, &S3, noPrint));
32 }
33
34 int
35 main(int argc, char** argv)
36 {
37 unsigned int i, noPrint = 1;
38 if (argc > 1 && ! strcmp(argv[1], "-d"))
39 noPrint = 0;
40 for (i=0; i < 10; ++i)
41 testAllocaOrder(noPrint);
42 return 0;
43 }
0 #include
1 #include
2
3 #define A 16807.0
4 #define M 2147483647.0
5
6 /*
7 * This function calls floor() which does not have a prototype.
8 * Test that the argument to floor is passed correctly.
9 */
10 double
11 my_rand(double seed)
12 {
13 double t = A*seed + 1;
14 double floor();
15
16 seed = t - (M * floor(t / M)); /* t%M if t > M; t otherwise */
17 return seed;
18
19 } /* end of random */
20
21
22 int
23 main(int argc, char** argv)
24 {
25 double seed = 123 * ((argc > 1)? atof(argv[1]) : 3.1415926);
26 printf("my_rand(%lf) = %lf\n", seed, my_rand(seed));
27 return 0;
28 }