blob: c3f53b5523a38e9bbede2529bb2c3dd554d289e0 [file] [log] [blame]
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +00001%AConst = constant int 123
2
Vikram S. Advef2899112002-10-13 00:44:00 +00003%Domain = type { sbyte*, int, int*, int, int, int*, %Domain* }
4
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +00005implementation
6
7; Test setting values of different constants in registers.
8;
9void "testConsts"(int %N, float %X)
10begin
11; <label>:0
12 %a = add int %N, 1 ; 1 should be put in immed field
13 %a2= add int %N, 12345678 ; constant has to be loaded
14 %b = add short 4, 3 ; one of the operands shd be immed
15 %c = add float %X, 0.0 ; will this be optimzzed?
16 %d = add float %X, 3.1415 ; constant has to be loaded
17 %f = add uint 4294967295, 10 ; result shd be 9 (not in immed fld)
18 %g = add ushort 20, 65535 ; result shd be 19 (65536 in immed fld)
19 %g = add ushort 65535, 30 ; result shd be 29 (not in immed fld)
20 %h = add ubyte 40, 255 ; result shd be 39 (255 in immed fld)
21 %h = add ubyte 255, 50 ; result shd be 49 (not in immed fld)
22
23 ret void
24end
25
26; A SetCC whose result is used should produce instructions to
27; compute the boolean value in a register. One whose result
28; is unused will only generate the condition code but not
29; the boolean result.
30;
31void "unusedBool"(int * %x, int * %y)
32begin
33; <label>:0 ; [#uses=0]
34 seteq int * %x, %y ; <bool>:0 [#uses=1]
Chris Lattnerd0224712002-08-14 19:29:38 +000035 xor bool %0, true ; <bool>:1 [#uses=0]
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +000036 setne int * %x, %y ; <bool>:2 [#uses=0]
37 ret void
38end
39
40; A constant argument to a Phi produces a Cast instruction in the
41; corresponding predecessor basic block. This checks a few things:
42; -- phi arguments coming from the bottom of the same basic block
43; (they should not be forward substituted in the machine code!)
44; -- code generation for casts of various types
45; -- use of immediate fields for integral constants of different sizes
46; -- branch on a constant condition
47;
48void "mergeConstants"(int * %x, int * %y)
49begin
50; <label>:0
51 br label %Top
52Top:
53 phi int [ 0, %0 ], [ 1, %Top ], [ 524288, %Next ]
54 phi float [ 0.0, %0 ], [ 1.0, %Top ], [ 2.0, %Next ]
55 phi double [ 0.5, %0 ], [ 1.5, %Top ], [ 2.5, %Next ]
56 phi bool [ true, %0 ], [ false,%Top ], [ true, %Next ]
57 br bool true, label %Top, label %Next
58Next:
59 br label %Top
60end
61
62
63
64; A constant argument to a cast used only once should be forward substituted
65; and loaded where needed, which happens is:
66; -- User of cast has no immediate field
67; -- User of cast has immediate field but constant is too large to fit
68; or constant is not resolved until later (e.g., global address)
69; -- User of cast uses it as a call arg. or return value so it is an implicit
70; use but has to be loaded into a virtual register so that the reg.
71; allocator can allocate the appropriate phys. reg. for it
72;
73int* "castconst"(float)
74begin
75; <label>:0
76 %castbig = cast ulong 99999999 to int
77 %castsmall = cast ulong 1 to int
78 %usebig = add int %castbig, %castsmall
79
80 %castglob = cast int* %AConst to long*
81 %dummyl = load long* %castglob
82
83 %castnull = cast ulong 0 to int*
84 ret int* %castnull
85end
86
87
88
89; Test branch-on-comparison-with-zero, in two ways:
90; 1. can be folded
91; 2. cannot be folded because result of comparison is used twice
92;
Chris Lattner92ae9012002-08-01 20:48:21 +000093void "testbool"(int %A, int %B) {
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +000094 br label %Top
95Top:
Chris Lattner92ae9012002-08-01 20:48:21 +000096 %D = add int %A, %B
97 %E = sub int %D, -4
98 %C = setle int %E, 0
99 br bool %C, label %retlbl, label %loop
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +0000100
101loop:
Chris Lattner92ae9012002-08-01 20:48:21 +0000102 %F = add int %A, %B
103 %G = sub int %D, -4
104 %D = setle int %G, 0
Chris Lattnerd0224712002-08-14 19:29:38 +0000105 %E = xor bool %D, true
Chris Lattner92ae9012002-08-01 20:48:21 +0000106 br bool %E, label %loop, label %Top
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +0000107
108retlbl:
109 ret void
110end
111
112
Vikram S. Adveddd57512002-08-22 03:05:13 +0000113;; Test use of a boolean result in cast operations.
114;; Requires converting a condition code result into a 0/1 value in a reg.
115;;
116implementation
117
118int %castbool(int %A, int %B) {
119bb0: ; [#uses=0]
120 %cond213 = setlt int %A, %B ; <bool> [#uses=1]
121 %cast110 = cast bool %cond213 to ubyte ; <ubyte> [#uses=1]
122 %cast109 = cast ubyte %cast110 to int ; <int> [#uses=1]
123 ret int %cast109
124}
125
126
127;; Test use of a boolean result in arithmetic and logical operations.
128;; Requires converting a condition code result into a 0/1 value in a reg.
129;;
130bool %boolexpr(bool %b, int %N) {
131 %b2 = setge int %N, 0
132 %b3 = and bool %b, %b2
133 ret bool %b3
134}
135
136
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +0000137; Test branch on floating point comparison
138;
139void "testfloatbool"(float %x, float %y) ; Def %0, %1 - float
140begin
141; <label>:0
142 br label %Top
143Top:
144 %p = add float %x, %y ; Def 2 - float
145 %z = sub float %x, %y ; Def 3 - float
146 %b = setle float %p, %z ; Def 0 - bool
Chris Lattnerd0224712002-08-14 19:29:38 +0000147 %c = xor bool %b, true ; Def 1 - bool
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +0000148 br bool %b, label %Top, label %goon
149goon:
150 ret void
151end
152
153
154; Test cases where an LLVM instruction requires no machine
155; instructions (e.g., cast int* to long). But there are 2 cases:
156; 1. If the result register has only a single use and the use is in the
157; same basic block, the operand will be copy-propagated during
158; instruction selection.
159; 2. If the result register has multiple uses or is in a different
160; basic block, it cannot (or will not) be copy propagated during
161; instruction selection. It will generate a
162; copy instruction (add-with-0), but this copy should get coalesced
163; away by the register allocator.
164;
165int "checkForward"(int %N, int* %A)
166begin
167
168bb2: ;;<label>
169 %reg114 = shl int %N, ubyte 2 ;;
Vikram S. Adveba3b3e82002-09-20 00:57:37 +0000170 %cast115 = cast int %reg114 to long ;; reg114 will be propagated
171 %cast116 = cast int* %A to long ;; %A will be propagated
172 %reg116 = add long %cast116, %cast115 ;;
173 %castPtr = cast long %reg116 to int* ;; %A will be propagated
174 %reg118 = load int* %castPtr ;;
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +0000175 %cast117 = cast int %reg118 to long ;; reg118 will be copied 'cos
176 %reg159 = add long 1234567, %cast117 ;; cast117 has 2 uses, here
177 %reg160 = add long 7654321, %cast117 ;; and here.
Chris Lattner92ae9012002-08-01 20:48:21 +0000178 ret int 0
Vikram S. Advea7a1c7e2002-07-10 21:54:05 +0000179end
Vikram S. Adve0f63e222002-08-15 14:09:56 +0000180
181
182; Test case for unary NOT operation constructed from XOR.
183;
184void "checkNot"(bool %b, int %i)
185begin
186 %notB = xor bool %b, true
187 %notI = xor int %i, -1
188 %F = setge int %notI, 100
189 %J = add int %i, %i
190 %andNotB = and bool %F, %notB ;; should get folded with notB
191 %andNotI = and int %J, %notI ;; should get folded with notI
192
193 %notB2 = xor bool true, %b ;; should become XNOR
194 %notI2 = xor int -1, %i ;; should become XNOR
195
196 ret void
197end
Vikram S. Advef2899112002-10-13 00:44:00 +0000198
199
200; Test case for folding getelementptr into a load/store
201;
202int "checkFoldGEP"(%Domain* %D, long %idx)
203begin
Chris Lattner1fbaa0a2003-01-15 18:06:37 +0000204 %reg841 = getelementptr %Domain* %D, long 0, ubyte 1
Vikram S. Advef2899112002-10-13 00:44:00 +0000205 %reg820 = load int* %reg841
206 ret int %reg820
207end