blob: 837cb0b2e10fa811a2dccfa9224d8753b281a9c0 [file] [log] [blame]
Jan Voung0ac50dc2014-09-30 08:36:06 -07001; This tries to be a comprehensive test of i8 operations.
2
Jim Stichnoth729dbd02015-02-25 14:48:43 -08003; RUN: %p2i --filetype=obj --disassemble -i %s --args -O2 | FileCheck %s
4; RUN: %p2i --filetype=obj --disassemble -i %s --args -Om1 | FileCheck %s
Jan Voung0ac50dc2014-09-30 08:36:06 -07005
Jim Stichnotha59ae6f2015-05-17 10:11:41 -07006declare void @useInt(i32 %x)
7
Jan Voung0ac50dc2014-09-30 08:36:06 -07008define internal i32 @add8Bit(i32 %a, i32 %b) {
9entry:
10 %a_8 = trunc i32 %a to i8
11 %b_8 = trunc i32 %b to i8
12 %add = add i8 %b_8, %a_8
13 %ret = zext i8 %add to i32
14 ret i32 %ret
15}
16; CHECK-LABEL: add8Bit
17; CHECK: add {{[abcd]l}}
18
Jan Vounge4dc61b2014-10-06 08:53:52 -070019define internal i32 @add8BitConst(i32 %a) {
Jan Voung0ac50dc2014-09-30 08:36:06 -070020entry:
21 %a_8 = trunc i32 %a to i8
22 %add = add i8 %a_8, 123
23 %ret = zext i8 %add to i32
24 ret i32 %ret
25}
26; CHECK-LABEL: add8BitConst
27; CHECK: add {{[abcd]l}}
28
29define internal i32 @sub8Bit(i32 %a, i32 %b) {
30entry:
31 %a_8 = trunc i32 %a to i8
32 %b_8 = trunc i32 %b to i8
33 %sub = sub i8 %b_8, %a_8
34 %ret = zext i8 %sub to i32
35 ret i32 %ret
36}
37; CHECK-LABEL: sub8Bit
Jan Voung7b300672015-02-13 09:47:09 -080038; CHECK: sub {{[abcd]l}}
Jan Voung0ac50dc2014-09-30 08:36:06 -070039
Jan Vounge4dc61b2014-10-06 08:53:52 -070040define internal i32 @sub8BitConst(i32 %a) {
Jan Voung0ac50dc2014-09-30 08:36:06 -070041entry:
42 %a_8 = trunc i32 %a to i8
43 %sub = sub i8 %a_8, 123
44 %ret = zext i8 %sub to i32
45 ret i32 %ret
46}
47; CHECK-LABEL: sub8BitConst
Jan Voung7b300672015-02-13 09:47:09 -080048; CHECK: sub {{[abcd]l}}
Jan Voung0ac50dc2014-09-30 08:36:06 -070049
50define internal i32 @mul8Bit(i32 %a, i32 %b) {
51entry:
52 %a_8 = trunc i32 %a to i8
53 %b_8 = trunc i32 %b to i8
54 %mul = mul i8 %b_8, %a_8
55 %ret = zext i8 %mul to i32
56 ret i32 %ret
57}
58; CHECK-LABEL: mul8Bit
Jan Vounga2703ae2015-02-19 11:27:44 -080059; CHECK: mul {{[abcd]l|BYTE PTR}}
Jan Voung0ac50dc2014-09-30 08:36:06 -070060
Jan Vounge4dc61b2014-10-06 08:53:52 -070061define internal i32 @mul8BitConst(i32 %a) {
Jan Voung0ac50dc2014-09-30 08:36:06 -070062entry:
63 %a_8 = trunc i32 %a to i8
64 %mul = mul i8 %a_8, 56
65 %ret = zext i8 %mul to i32
66 ret i32 %ret
67}
68; CHECK-LABEL: mul8BitConst
69; 8-bit imul only accepts r/m, not imm
Jan Vounga2703ae2015-02-19 11:27:44 -080070; CHECK: mov {{.*}},0x38
71; CHECK: mul {{[abcd]l|BYTE PTR}}
Jan Voung0ac50dc2014-09-30 08:36:06 -070072
73define internal i32 @udiv8Bit(i32 %a, i32 %b) {
74entry:
75 %a_8 = trunc i32 %a to i8
76 %b_8 = trunc i32 %b to i8
77 %udiv = udiv i8 %b_8, %a_8
78 %ret = zext i8 %udiv to i32
79 ret i32 %ret
80}
81; CHECK-LABEL: udiv8Bit
Jan Vounga2703ae2015-02-19 11:27:44 -080082; CHECK: div {{[abcd]l|BYTE PTR}}
Jan Voung0ac50dc2014-09-30 08:36:06 -070083
Jan Vounge4dc61b2014-10-06 08:53:52 -070084define internal i32 @udiv8BitConst(i32 %a) {
Jan Voung0ac50dc2014-09-30 08:36:06 -070085entry:
86 %a_8 = trunc i32 %a to i8
87 %udiv = udiv i8 %a_8, 123
88 %ret = zext i8 %udiv to i32
89 ret i32 %ret
90}
91; CHECK-LABEL: udiv8BitConst
Jan Vounga2703ae2015-02-19 11:27:44 -080092; CHECK: div {{[abcd]l|BYTE PTR}}
Jan Voung0ac50dc2014-09-30 08:36:06 -070093
94define internal i32 @urem8Bit(i32 %a, i32 %b) {
95entry:
96 %a_8 = trunc i32 %a to i8
97 %b_8 = trunc i32 %b to i8
98 %urem = urem i8 %b_8, %a_8
99 %ret = zext i8 %urem to i32
100 ret i32 %ret
101}
102; CHECK-LABEL: urem8Bit
Jan Vounga2703ae2015-02-19 11:27:44 -0800103; CHECK: div {{[abcd]l|BYTE PTR}}
Jan Voung0ac50dc2014-09-30 08:36:06 -0700104
Jan Vounge4dc61b2014-10-06 08:53:52 -0700105define internal i32 @urem8BitConst(i32 %a) {
Jan Voung0ac50dc2014-09-30 08:36:06 -0700106entry:
107 %a_8 = trunc i32 %a to i8
108 %urem = urem i8 %a_8, 123
109 %ret = zext i8 %urem to i32
110 ret i32 %ret
111}
112; CHECK-LABEL: urem8BitConst
Jan Vounga2703ae2015-02-19 11:27:44 -0800113; CHECK: div {{[abcd]l|BYTE PTR}}
Jan Voung0ac50dc2014-09-30 08:36:06 -0700114
115
116define internal i32 @sdiv8Bit(i32 %a, i32 %b) {
117entry:
118 %a_8 = trunc i32 %a to i8
119 %b_8 = trunc i32 %b to i8
120 %sdiv = sdiv i8 %b_8, %a_8
121 %ret = zext i8 %sdiv to i32
122 ret i32 %ret
123}
124; CHECK-LABEL: sdiv8Bit
Jan Vounga2703ae2015-02-19 11:27:44 -0800125; CHECK: idiv {{[abcd]l|BYTE PTR}}
Jan Voung0ac50dc2014-09-30 08:36:06 -0700126
Jan Vounge4dc61b2014-10-06 08:53:52 -0700127define internal i32 @sdiv8BitConst(i32 %a) {
Jan Voung0ac50dc2014-09-30 08:36:06 -0700128entry:
129 %a_8 = trunc i32 %a to i8
130 %sdiv = sdiv i8 %a_8, 123
131 %ret = zext i8 %sdiv to i32
132 ret i32 %ret
133}
134; CHECK-LABEL: sdiv8BitConst
Jan Vounga2703ae2015-02-19 11:27:44 -0800135; CHECK: idiv {{[abcd]l|BYTE PTR}}
Jan Voung0ac50dc2014-09-30 08:36:06 -0700136
137define internal i32 @srem8Bit(i32 %a, i32 %b) {
138entry:
139 %a_8 = trunc i32 %a to i8
140 %b_8 = trunc i32 %b to i8
141 %srem = srem i8 %b_8, %a_8
142 %ret = zext i8 %srem to i32
143 ret i32 %ret
144}
145; CHECK-LABEL: srem8Bit
Jan Vounga2703ae2015-02-19 11:27:44 -0800146; CHECK: idiv {{[abcd]l|BYTE PTR}}
Jan Voung0ac50dc2014-09-30 08:36:06 -0700147
Jan Vounge4dc61b2014-10-06 08:53:52 -0700148define internal i32 @srem8BitConst(i32 %a) {
Jan Voung0ac50dc2014-09-30 08:36:06 -0700149entry:
150 %a_8 = trunc i32 %a to i8
151 %srem = srem i8 %a_8, 123
152 %ret = zext i8 %srem to i32
153 ret i32 %ret
154}
155; CHECK-LABEL: srem8BitConst
Jan Vounga2703ae2015-02-19 11:27:44 -0800156; CHECK: idiv {{[abcd]l|BYTE PTR}}
Jan Voung0ac50dc2014-09-30 08:36:06 -0700157
Jan Voung8bcca042014-10-03 21:58:02 -0700158define internal i32 @shl8Bit(i32 %a, i32 %b) {
159entry:
160 %a_8 = trunc i32 %a to i8
161 %b_8 = trunc i32 %b to i8
162 %shl = shl i8 %b_8, %a_8
163 %ret = zext i8 %shl to i32
164 ret i32 %ret
165}
166; CHECK-LABEL: shl8Bit
Jan Vounga2703ae2015-02-19 11:27:44 -0800167; CHECK: shl {{[abd]l|BYTE PTR}},cl
Jan Voung8bcca042014-10-03 21:58:02 -0700168
169define internal i32 @shl8BitConst(i32 %a, i32 %b) {
170entry:
171 %a_8 = trunc i32 %a to i8
172 %shl = shl i8 %a_8, 6
173 %ret = zext i8 %shl to i32
174 ret i32 %ret
175}
176; CHECK-LABEL: shl8BitConst
Jan Vounga2703ae2015-02-19 11:27:44 -0800177; CHECK: shl {{[abcd]l|BYTE PTR}},0x6
Jan Voung8bcca042014-10-03 21:58:02 -0700178
179define internal i32 @lshr8Bit(i32 %a, i32 %b) {
180entry:
181 %a_8 = trunc i32 %a to i8
182 %b_8 = trunc i32 %b to i8
183 %lshr = lshr i8 %b_8, %a_8
184 %ret = zext i8 %lshr to i32
185 ret i32 %ret
186}
187; CHECK-LABEL: lshr8Bit
Jan Vounga2703ae2015-02-19 11:27:44 -0800188; CHECK: shr {{[abd]l|BYTE PTR}},cl
Jan Voung8bcca042014-10-03 21:58:02 -0700189
190define internal i32 @lshr8BitConst(i32 %a, i32 %b) {
191entry:
192 %a_8 = trunc i32 %a to i8
193 %lshr = lshr i8 %a_8, 6
194 %ret = zext i8 %lshr to i32
195 ret i32 %ret
196}
197; CHECK-LABEL: lshr8BitConst
Jan Vounga2703ae2015-02-19 11:27:44 -0800198; CHECK: shr {{[abcd]l|BYTE PTR}},0x6
Jan Voung8bcca042014-10-03 21:58:02 -0700199
200define internal i32 @ashr8Bit(i32 %a, i32 %b) {
201entry:
202 %a_8 = trunc i32 %a to i8
203 %b_8 = trunc i32 %b to i8
204 %ashr = ashr i8 %b_8, %a_8
205 %ret = zext i8 %ashr to i32
206 ret i32 %ret
207}
208; CHECK-LABEL: ashr8Bit
Jan Vounga2703ae2015-02-19 11:27:44 -0800209; CHECK: sar {{[abd]l|BYTE PTR}},cl
Jan Voung8bcca042014-10-03 21:58:02 -0700210
211define internal i32 @ashr8BitConst(i32 %a, i32 %b) {
212entry:
213 %a_8 = trunc i32 %a to i8
214 %ashr = ashr i8 %a_8, 6
215 %ret = zext i8 %ashr to i32
216 ret i32 %ret
217}
218; CHECK-LABEL: ashr8BitConst
Jan Vounga2703ae2015-02-19 11:27:44 -0800219; CHECK: sar {{[abcd]l|BYTE PTR}},0x6
Jan Voung8bcca042014-10-03 21:58:02 -0700220
Jan Vounge4dc61b2014-10-06 08:53:52 -0700221define internal i32 @icmp8Bit(i32 %a, i32 %b) {
222entry:
223 %a_8 = trunc i32 %a to i8
224 %b_8 = trunc i32 %b to i8
225 %icmp = icmp ne i8 %b_8, %a_8
226 %ret = zext i1 %icmp to i32
227 ret i32 %ret
228}
229; CHECK-LABEL: icmp8Bit
Jan Vounga2703ae2015-02-19 11:27:44 -0800230; CHECK: cmp {{[abcd]l|BYTE PTR}}
Jan Vounge4dc61b2014-10-06 08:53:52 -0700231
232define internal i32 @icmp8BitConst(i32 %a) {
233entry:
234 %a_8 = trunc i32 %a to i8
235 %icmp = icmp ne i8 %a_8, 123
236 %ret = zext i1 %icmp to i32
237 ret i32 %ret
238}
239; CHECK-LABEL: icmp8BitConst
Jan Vounga2703ae2015-02-19 11:27:44 -0800240; CHECK: cmp {{[abcd]l|BYTE PTR}}
Jan Vounge4dc61b2014-10-06 08:53:52 -0700241
242define internal i32 @icmp8BitConstSwapped(i32 %a) {
243entry:
244 %a_8 = trunc i32 %a to i8
245 %icmp = icmp ne i8 123, %a_8
246 %ret = zext i1 %icmp to i32
247 ret i32 %ret
248}
249; CHECK-LABEL: icmp8BitConstSwapped
Jan Vounga2703ae2015-02-19 11:27:44 -0800250; CHECK: cmp {{[abcd]l|BYTE PTR}}
Jan Vounge4dc61b2014-10-06 08:53:52 -0700251
252define internal i32 @icmp8BitMem(i32 %a, i32 %b_iptr) {
253entry:
254 %a_8 = trunc i32 %a to i8
255 %bptr = inttoptr i32 %b_iptr to i8*
Jim Stichnothe5b58fb2015-06-01 15:17:20 -0700256 %b_8 = load i8, i8* %bptr, align 1
Jan Vounge4dc61b2014-10-06 08:53:52 -0700257 %icmp = icmp ne i8 %b_8, %a_8
258 %ret = zext i1 %icmp to i32
259 ret i32 %ret
260}
261; CHECK-LABEL: icmp8BitMem
Jan Vounga2703ae2015-02-19 11:27:44 -0800262; CHECK: cmp {{[abcd]l|BYTE PTR}}
Jan Vounge4dc61b2014-10-06 08:53:52 -0700263
264define internal i32 @icmp8BitMemSwapped(i32 %a, i32 %b_iptr) {
265entry:
266 %a_8 = trunc i32 %a to i8
267 %bptr = inttoptr i32 %b_iptr to i8*
Jim Stichnothe5b58fb2015-06-01 15:17:20 -0700268 %b_8 = load i8, i8* %bptr, align 1
Jan Vounge4dc61b2014-10-06 08:53:52 -0700269 %icmp = icmp ne i8 %a_8, %b_8
270 %ret = zext i1 %icmp to i32
271 ret i32 %ret
272}
273; CHECK-LABEL: icmp8BitMemSwapped
Jan Vounga2703ae2015-02-19 11:27:44 -0800274; CHECK: cmp {{[abcd]l|BYTE PTR}}
Jan Voung0ac50dc2014-09-30 08:36:06 -0700275
Jan Voung198b2942014-10-16 09:40:02 -0700276define internal i32 @selectI8Var(i32 %a, i32 %b) {
277entry:
278 %a_8 = trunc i32 %a to i8
279 %b_8 = trunc i32 %b to i8
280 %cmp = icmp slt i8 %a_8, %b_8
281 %ret = select i1 %cmp, i8 %a_8, i8 %b_8
282 %ret_ext = zext i8 %ret to i32
Jim Stichnotha59ae6f2015-05-17 10:11:41 -0700283 ; Create a "fake" use of %cmp to prevent O2 bool folding.
284 %d1 = zext i1 %cmp to i32
285 call void @useInt(i32 %d1)
Jan Voung198b2942014-10-16 09:40:02 -0700286 ret i32 %ret_ext
287}
288; CHECK-LABEL: selectI8Var
289; CHECK: cmp
Jim Stichnothf48b3202015-05-04 10:22:17 -0700290; CHECK: setl
Jan Voung198b2942014-10-16 09:40:02 -0700291; CHECK: mov {{[a-d]l}}
292
Jan Voungfe14fb82014-10-13 15:56:32 -0700293define internal i32 @testPhi8(i32 %arg, i32 %arg2, i32 %arg3, i32 %arg4, i32 %arg5, i32 %arg6, i32 %arg7, i32 %arg8, i32 %arg9, i32 %arg10) {
294entry:
295 %trunc = trunc i32 %arg to i8
296 %trunc2 = trunc i32 %arg2 to i8
297 %trunc3 = trunc i32 %arg3 to i8
298 %trunc4 = trunc i32 %arg4 to i8
299 %trunc5 = trunc i32 %arg5 to i8
300 %cmp1 = icmp sgt i32 %arg, 0
301 br i1 %cmp1, label %next, label %target
302next:
303 %trunc6_16 = trunc i32 %arg6 to i16
304 %trunc7_16 = trunc i32 %arg7 to i16
305 %trunc8_16 = trunc i32 %arg8 to i16
306 %trunc9 = trunc i32 %arg9 to i8
307 %trunc10 = trunc i32 %arg10 to i8
308 %trunc7_8 = trunc i16 %trunc7_16 to i8
309 %trunc6_8 = trunc i16 %trunc6_16 to i8
310 %trunc8_8 = trunc i16 %trunc8_16 to i8
311 br label %target
312target:
313 %merge1 = phi i1 [ %cmp1, %entry ], [ false, %next ]
314 %merge2 = phi i8 [ %trunc, %entry ], [ %trunc6_8, %next ]
315 %merge3 = phi i8 [ %trunc2, %entry ], [ %trunc7_8, %next ]
316 %merge5 = phi i8 [ %trunc4, %entry ], [ %trunc9, %next ]
317 %merge6 = phi i8 [ %trunc5, %entry ], [ %trunc10, %next ]
318 %merge4 = phi i8 [ %trunc3, %entry ], [ %trunc8_8, %next ]
319 %res1 = select i1 %merge1, i8 %merge2, i8 %merge3
320 %res2 = select i1 %merge1, i8 %merge4, i8 %merge5
321 %res1_2 = select i1 %merge1, i8 %res1, i8 %res2
322 %res123 = select i1 %merge1, i8 %merge6, i8 %res1_2
323 %result = zext i8 %res123 to i32
324 ret i32 %result
325}
326; CHECK-LABEL: testPhi8
327; This assumes there will be some copy from an 8-bit register / stack slot.
Jan Vounga2703ae2015-02-19 11:27:44 -0800328; CHECK-DAG: mov {{.*}},{{[a-d]}}l
329; CHECK-DAG: mov {{.*}},BYTE PTR
330; CHECK-DAG: mov BYTE PTR {{.*}}
Jan Voungfe14fb82014-10-13 15:56:32 -0700331
Jan Voung198b2942014-10-16 09:40:02 -0700332@global8 = internal global [1 x i8] c"\01", align 4
333
334define i32 @load_i8(i32 %addr_arg) {
335entry:
336 %addr = inttoptr i32 %addr_arg to i8*
Jim Stichnothe5b58fb2015-06-01 15:17:20 -0700337 %ret = load i8, i8* %addr, align 1
Jim Stichnothc77f8172015-05-31 23:34:44 -0700338 %ret2 = sub i8 %ret, 0
339 %ret_ext = zext i8 %ret2 to i32
Jan Voung198b2942014-10-16 09:40:02 -0700340 ret i32 %ret_ext
341}
342; CHECK-LABEL: load_i8
Jan Vounga2703ae2015-02-19 11:27:44 -0800343; CHECK: mov {{[a-d]l}},BYTE PTR
Jan Voung198b2942014-10-16 09:40:02 -0700344
345define i32 @load_i8_global(i32 %addr_arg) {
346entry:
347 %addr = bitcast [1 x i8]* @global8 to i8*
Jim Stichnothe5b58fb2015-06-01 15:17:20 -0700348 %ret = load i8, i8* %addr, align 1
Jim Stichnothc77f8172015-05-31 23:34:44 -0700349 %ret2 = sub i8 %ret, 0
350 %ret_ext = zext i8 %ret2 to i32
Jan Voung198b2942014-10-16 09:40:02 -0700351 ret i32 %ret_ext
352}
353; CHECK-LABEL: load_i8_global
Jan Vounga2703ae2015-02-19 11:27:44 -0800354; CHECK: mov {{[a-d]l}},BYTE PTR
Jan Voung198b2942014-10-16 09:40:02 -0700355
356define void @store_i8(i32 %addr_arg, i32 %val) {
357entry:
358 %val_trunc = trunc i32 %val to i8
359 %addr = inttoptr i32 %addr_arg to i8*
360 store i8 %val_trunc, i8* %addr, align 1
361 ret void
362}
363; CHECK-LABEL: store_i8
Jan Vounga2703ae2015-02-19 11:27:44 -0800364; CHECK: mov BYTE PTR {{.*}},{{[a-d]l}}
Jan Voung198b2942014-10-16 09:40:02 -0700365
366define void @store_i8_const(i32 %addr_arg) {
367entry:
368 %addr = inttoptr i32 %addr_arg to i8*
369 store i8 123, i8* %addr, align 1
370 ret void
371}
372; CHECK-LABEL: store_i8_const
Jan Vounga2703ae2015-02-19 11:27:44 -0800373; CHECK: mov BYTE PTR {{.*}},0x7b