OSDN Git Service

7613900c97fb72aca4d17ed8e572a347d186532e
[android-x86/external-swiftshader.git] / tests_lit / llvm2ice_tests / arith.ll
1 ; Assembly test for simple arithmetic operations.
2
3 ; RUN: %if --need=target_X8632 --command %p2i --filetype=obj --disassemble \
4 ; RUN:   --target x8632 -i %s --args -O2 \
5 ; RUN:   | %if --need=target_X8632 --command FileCheck %s
6
7 ; TODO(jvoung): Stop skipping unimplemented parts (via --skip-unimplemented)
8 ; once enough infrastructure is in. Also, switch to --filetype=obj
9 ; when possible.
10 ; RUN: %if --need=target_ARM32 --need=allow_dump \
11 ; RUN:   --command %p2i --filetype=asm --assemble --disassemble --target arm32 \
12 ; RUN:   -i %s --args -O2 --skip-unimplemented \
13 ; RUN:   | %if --need=target_ARM32 --need=allow_dump \
14 ; RUN:   --command FileCheck --check-prefix ARM32 --check-prefix ARM-OPT2 %s
15 ; RUN: %if --need=target_ARM32 --need=allow_dump \
16 ; RUN:   --command %p2i --filetype=asm --assemble --disassemble --target arm32 \
17 ; RUN:   -i %s --args -O2 --mattr=hwdiv-arm --skip-unimplemented \
18 ; RUN:   | %if --need=target_ARM32 --need=allow_dump \
19 ; RUN:   --command FileCheck --check-prefix ARM32HWDIV %s
20 ; RUN: %if --need=target_ARM32 --need=allow_dump \
21 ; RUN:   --command %p2i --filetype=asm --assemble --disassemble --target arm32 \
22 ; RUN:   -i %s --args -Om1 --skip-unimplemented \
23 ; RUN:   | %if --need=target_ARM32 --need=allow_dump \
24 ; RUN:   --command FileCheck --check-prefix ARM32 --check-prefix ARM32-OPTM1 %s
25 ;
26 ; RUN: %if --need=target_MIPS32 --need=allow_dump \
27 ; RUN:   --command %p2i --filetype=asm --assemble --disassemble --target mips32\
28 ; RUN:   -i %s --args -O2 --skip-unimplemented \
29 ; RUN:   | %if --need=target_MIPS32 --need=allow_dump \
30 ; RUN:   --command FileCheck --check-prefix MIPS32 %s
31
32 ; RUN: %if --need=target_MIPS32 --need=allow_dump \
33 ; RUN:   --command %p2i --filetype=asm --assemble --disassemble --target mips32\
34 ; RUN:   -i %s --args -Om1 --skip-unimplemented \
35 ; RUN:   | %if --need=target_MIPS32 --need=allow_dump \
36 ; RUN:   --command FileCheck --check-prefix MIPS32 %s
37
38 define internal i32 @Add(i32 %a, i32 %b) {
39 entry:
40   %add = add i32 %b, %a
41   ret i32 %add
42 }
43 ; CHECK-LABEL: Add
44 ; CHECK: add e
45 ; ARM32-LABEL: Add
46 ; ARM32: add r
47 ; MIPS32-LABEL: Add
48 ; MIPS32: add
49
50 define internal i32 @And(i32 %a, i32 %b) {
51 entry:
52   %and = and i32 %b, %a
53   ret i32 %and
54 }
55 ; CHECK-LABEL: And
56 ; CHECK: and e
57 ; ARM32-LABEL: And
58 ; ARM32: and r
59 ; MIPS32-LABEL: And
60 ; MIPS32: and
61
62 define internal i32 @Or(i32 %a, i32 %b) {
63 entry:
64   %or = or i32 %b, %a
65   ret i32 %or
66 }
67 ; CHECK-LABEL: Or
68 ; CHECK: or e
69 ; ARM32-LABEL: Or
70 ; ARM32: orr r
71 ; MIPS32-LABEL: Or
72 ; MIPS32: or
73
74 define internal i32 @Xor(i32 %a, i32 %b) {
75 entry:
76   %xor = xor i32 %b, %a
77   ret i32 %xor
78 }
79 ; CHECK-LABEL: Xor
80 ; CHECK: xor e
81 ; ARM32-LABEL: Xor
82 ; ARM32: eor r
83 ; MIPS32-LABEL: Xor
84 ; MIPS32: xor
85
86 define internal i32 @Sub(i32 %a, i32 %b) {
87 entry:
88   %sub = sub i32 %a, %b
89   ret i32 %sub
90 }
91 ; CHECK-LABEL: Sub
92 ; CHECK: sub e
93 ; ARM32-LABEL: Sub
94 ; ARM32: sub r
95 ; MIPS32-LABEL: Sub
96 ; MIPS32: sub
97
98 define internal i32 @Mul(i32 %a, i32 %b) {
99 entry:
100   %mul = mul i32 %b, %a
101   ret i32 %mul
102 }
103 ; CHECK-LABEL: Mul
104 ; CHECK: imul e
105 ; ARM32-LABEL: Mul
106 ; ARM32: mul r
107 ; MIPS32-LABEL: Mul
108 ; MIPS32: mul
109
110 ; Check for a valid ARM mul instruction where operands have to be registers.
111 ; On the other hand x86-32 does allow an immediate.
112 define internal i32 @MulImm(i32 %a, i32 %b) {
113 entry:
114   %mul = mul i32 %a, 99
115   ret i32 %mul
116 }
117 ; CHECK-LABEL: MulImm
118 ; CHECK: imul e{{.*}},e{{.*}},0x63
119 ; ARM32-LABEL: MulImm
120 ; ARM32-OPTM1: mov {{.*}}, #99
121 ; ARM32-OPTM1: mul r{{.*}}, r{{.*}}, r{{.*}}
122 ; ARM32-OPT2: rsb [[T:r[0-9]+]], [[S:r[0-9]+]], [[S]], lsl #2
123 ; ARM32-OPT2-DAG: add [[T]], [[T]], [[S]], lsl #7
124 ; ARM32-OPT2-DAG: sub [[T]], [[T]], [[S]], lsl #5
125 ; MIPS32-LABEL: MulImm
126 ; MIPS32: mul
127
128 ; Check for a valid addressing mode in the x86-32 mul instruction when
129 ; the second source operand is an immediate.
130 define internal i64 @MulImm64(i64 %a) {
131 entry:
132   %mul = mul i64 %a, 99
133   ret i64 %mul
134 }
135 ; NOTE: the lowering is currently a bit inefficient for small 64-bit constants.
136 ; The top bits of the immediate are 0, but the instructions modeling that
137 ; multiply by 0 are not eliminated (see expanded 64-bit ARM lowering).
138 ; CHECK-LABEL: MulImm64
139 ; CHECK: mov {{.*}},0x63
140 ; CHECK: mov {{.*}},0x0
141 ; CHECK-NOT: mul {{[0-9]+}}
142 ;
143 ; ARM32-LABEL: MulImm64
144 ; ARM32: mov {{.*}}, #99
145 ; ARM32: mov {{.*}}, #0
146 ; ARM32: mul r
147 ; ARM32: mla r
148 ; ARM32: umull r
149 ; ARM32: add r
150
151 ; MIPS32-LABEL: MulImm64
152
153 define internal i32 @Sdiv(i32 %a, i32 %b) {
154 entry:
155   %div = sdiv i32 %a, %b
156   ret i32 %div
157 }
158 ; CHECK-LABEL: Sdiv
159 ; CHECK: cdq
160 ; CHECK: idiv e
161 ;
162 ; ARM32-LABEL: Sdiv
163 ; ARM32: tst [[DENOM:r.*]], [[DENOM]]
164 ; ARM32: bne
165 ; ARM32: .word 0xe7fedef0
166 ; ARM32: {{.*}} bl {{.*}} __divsi3
167 ; ARM32HWDIV-LABEL: Sdiv
168 ; ARM32HWDIV: tst
169 ; ARM32HWDIV: bne
170 ; ARM32HWDIV: sdiv
171
172 ; MIPS32-LABEL: Sdiv
173
174 define internal i32 @SdivConst(i32 %a) {
175 entry:
176   %div = sdiv i32 %a, 219
177   ret i32 %div
178 }
179 ; CHECK-LABEL: SdivConst
180 ; CHECK: cdq
181 ; CHECK: idiv e
182 ;
183 ; ARM32-LABEL: SdivConst
184 ; ARM32-NOT: tst
185 ; ARM32: bl {{.*}} __divsi3
186 ; ARM32HWDIV-LABEL: SdivConst
187 ; ARM32HWDIV-NOT: tst
188 ; ARM32HWDIV: sdiv
189
190 ; MIPS32-LABEL: SdivConst
191
192 define internal i32 @Srem(i32 %a, i32 %b) {
193 entry:
194   %rem = srem i32 %a, %b
195   ret i32 %rem
196 }
197 ; CHECK-LABEL: Srem
198 ; CHECK: cdq
199 ; CHECK: idiv e
200 ;
201 ; ARM32-LABEL: Srem
202 ; ARM32: tst [[DENOM:r.*]], [[DENOM]]
203 ; ARM32: bne
204 ; ARM32: bl {{.*}} __modsi3
205 ; ARM32HWDIV-LABEL: Srem
206 ; ARM32HWDIV: tst
207 ; ARM32HWDIV: bne
208 ; ARM32HWDIV: sdiv
209 ; ARM32HWDIV: mls
210
211 ; MIPS32-LABEL: Srem
212
213 define internal i32 @Udiv(i32 %a, i32 %b) {
214 entry:
215   %div = udiv i32 %a, %b
216   ret i32 %div
217 }
218 ; CHECK-LABEL: Udiv
219 ; CHECK: div e
220 ;
221 ; ARM32-LABEL: Udiv
222 ; ARM32: tst [[DENOM:r.*]], [[DENOM]]
223 ; ARM32: bne
224 ; ARM32: bl {{.*}} __udivsi3
225 ; ARM32HWDIV-LABEL: Udiv
226 ; ARM32HWDIV: tst
227 ; ARM32HWDIV: bne
228 ; ARM32HWDIV: udiv
229
230 ; MIPS32-LABEL: Udiv
231
232 define internal i32 @Urem(i32 %a, i32 %b) {
233 entry:
234   %rem = urem i32 %a, %b
235   ret i32 %rem
236 }
237 ; CHECK-LABEL: Urem
238 ; CHECK: div e
239 ;
240 ; ARM32-LABEL: Urem
241 ; ARM32: tst [[DENOM:r.*]], [[DENOM]]
242 ; ARM32: bne
243 ; ARM32: bl {{.*}} __umodsi3
244 ; ARM32HWDIV-LABEL: Urem
245 ; ARM32HWDIV: tst
246 ; ARM32HWDIV: bne
247 ; ARM32HWDIV: udiv
248 ; ARM32HWDIV: mls
249
250 ; MIPS32-LABEL: Urem
251
252 ; The following tests check that shift instructions don't try to use a
253 ; ConstantRelocatable as an immediate operand.
254
255 @G = internal global [4 x i8] zeroinitializer, align 4
256
257 define internal i32 @ShlReloc(i32 %a) {
258 entry:
259   %opnd = ptrtoint [4 x i8]* @G to i32
260   %result = shl i32 %a, %opnd
261   ret i32 %result
262 }
263 ; CHECK-LABEL: ShlReloc
264 ; CHECK: shl {{.*}},cl
265
266 define internal i32 @LshrReloc(i32 %a) {
267 entry:
268   %opnd = ptrtoint [4 x i8]* @G to i32
269   %result = lshr i32 %a, %opnd
270   ret i32 %result
271 }
272 ; CHECK-LABEL: LshrReloc
273 ; CHECK: shr {{.*}},cl
274
275 define internal i32 @AshrReloc(i32 %a) {
276 entry:
277   %opnd = ptrtoint [4 x i8]* @G to i32
278   %result = ashr i32 %a, %opnd
279   ret i32 %result
280 }
281 ; CHECK-LABEL: AshrReloc
282 ; CHECK: sar {{.*}},cl