1 %AConst = constant int 123
3 %Domain = type { sbyte*, int, int*, int, int, int*, %Domain* }
7 ; Test setting values of different constants in registers.
9 void "testConsts"(int %N, float %X)
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)
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
31 void "unusedBool"(int * %x, int * %y)
33 ; <label>:0 ; [#uses=0]
34 seteq int * %x, %y ; <bool>:0 [#uses=1]
35 xor bool %0, true ; <bool>:1 [#uses=0]
36 setne int * %x, %y ; <bool>:2 [#uses=0]
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
48 void "mergeConstants"(int * %x, int * %y)
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
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
73 int* "castconst"(float)
76 %castbig = cast ulong 99999999 to int
77 %castsmall = cast ulong 1 to int
78 %usebig = add int %castbig, %castsmall
80 %castglob = cast int* %AConst to long*
81 %dummyl = load long* %castglob
83 %castnull = cast ulong 0 to int*
89 ; Test branch-on-comparison-with-zero, in two ways:
91 ; 2. cannot be folded because result of comparison is used twice
93 void "testbool"(int %A, int %B) {
99 br bool %C, label %retlbl, label %loop
105 %E = xor bool %D, true
106 br bool %E, label %loop, label %Top
113 ;; Test use of a boolean result in cast operations.
114 ;; Requires converting a condition code result into a 0/1 value in a reg.
118 int %castbool(int %A, int %B) {
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]
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.
130 bool %boolexpr(bool %b, int %N) {
131 %b2 = setge int %N, 0
132 %b3 = and bool %b, %b2
137 ; Test branch on floating point comparison
139 void "testfloatbool"(float %x, float %y) ; Def %0, %1 - float
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
147 %c = xor bool %b, true ; Def 1 - bool
148 br bool %b, label %Top, label %goon
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.
165 int "checkForward"(int %N, int* %A)
169 %reg114 = shl int %N, ubyte 2 ;;
170 %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 ;;
175 %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.
182 ; Test case for unary NOT operation constructed from XOR.
184 void "checkNot"(bool %b, int %i)
186 %notB = xor bool %b, true
187 %notI = xor int %i, -1
188 %F = setge int %notI, 100
190 %andNotB = and bool %F, %notB ;; should get folded with notB
191 %andNotI = and int %J, %notI ;; should get folded with notI
193 %notB2 = xor bool true, %b ;; should become XNOR
194 %notI2 = xor int -1, %i ;; should become XNOR
200 ; Test case for folding getelementptr into a load/store
202 int "checkFoldGEP"(%Domain* %D, long %idx)
204 %reg841 = getelementptr %Domain* %D, long 0, ubyte 1
205 %reg820 = load int* %reg841