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