blob: 4386bed4ebf788e968a9dda650ce60892227de1e [file] [log] [blame]
Dan Gohmanb7c24002016-05-21 00:21:56 +00001; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt | FileCheck %s
JF Bastien8f9aea02015-08-01 04:48:44 +00002
3; Test that basic 64-bit integer operations assemble as expected.
4
Dan Gohman0c6f5ac2016-01-07 03:19:23 +00005target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
Dan Gohmand934cb82017-02-24 23:18:00 +00006target triple = "wasm32-unknown-unknown-wasm"
JF Bastien8f9aea02015-08-01 04:48:44 +00007
8declare i64 @llvm.ctlz.i64(i64, i1)
9declare i64 @llvm.cttz.i64(i64, i1)
10declare i64 @llvm.ctpop.i64(i64)
11
Dan Gohmane51c0582015-10-06 00:27:55 +000012; CHECK-LABEL: add64:
Dan Gohman53828fd2015-11-23 16:50:18 +000013; CHECK-NEXT: .param i64, i64{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000014; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +000015; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
16; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 1{{$}}
17; CHECK-NEXT: i64.add $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000018; CHECK-NEXT: return $pop0{{$}}
JF Bastien8f9aea02015-08-01 04:48:44 +000019define i64 @add64(i64 %x, i64 %y) {
20 %a = add i64 %x, %y
21 ret i64 %a
22}
23
Dan Gohmane51c0582015-10-06 00:27:55 +000024; CHECK-LABEL: sub64:
Dan Gohman53828fd2015-11-23 16:50:18 +000025; CHECK-NEXT: .param i64, i64{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000026; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +000027; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
28; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 1{{$}}
29; CHECK-NEXT: i64.sub $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000030; CHECK-NEXT: return $pop0{{$}}
JF Bastien8f9aea02015-08-01 04:48:44 +000031define i64 @sub64(i64 %x, i64 %y) {
32 %a = sub i64 %x, %y
33 ret i64 %a
34}
35
Dan Gohmane51c0582015-10-06 00:27:55 +000036; CHECK-LABEL: mul64:
Dan Gohman53828fd2015-11-23 16:50:18 +000037; CHECK-NEXT: .param i64, i64{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000038; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +000039; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
40; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 1{{$}}
41; CHECK-NEXT: i64.mul $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000042; CHECK-NEXT: return $pop0{{$}}
JF Bastien8f9aea02015-08-01 04:48:44 +000043define i64 @mul64(i64 %x, i64 %y) {
44 %a = mul i64 %x, %y
45 ret i64 %a
46}
47
Dan Gohmane51c0582015-10-06 00:27:55 +000048; CHECK-LABEL: sdiv64:
Dan Gohman53828fd2015-11-23 16:50:18 +000049; CHECK-NEXT: .param i64, i64{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000050; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +000051; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
52; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 1{{$}}
53; CHECK-NEXT: i64.div_s $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000054; CHECK-NEXT: return $pop0{{$}}
JF Bastien8f9aea02015-08-01 04:48:44 +000055define i64 @sdiv64(i64 %x, i64 %y) {
56 %a = sdiv i64 %x, %y
57 ret i64 %a
58}
59
Dan Gohmane51c0582015-10-06 00:27:55 +000060; CHECK-LABEL: udiv64:
Dan Gohman53828fd2015-11-23 16:50:18 +000061; CHECK-NEXT: .param i64, i64{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000062; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +000063; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
64; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 1{{$}}
65; CHECK-NEXT: i64.div_u $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000066; CHECK-NEXT: return $pop0{{$}}
JF Bastien8f9aea02015-08-01 04:48:44 +000067define i64 @udiv64(i64 %x, i64 %y) {
68 %a = udiv i64 %x, %y
69 ret i64 %a
70}
71
Dan Gohmane51c0582015-10-06 00:27:55 +000072; CHECK-LABEL: srem64:
Dan Gohman53828fd2015-11-23 16:50:18 +000073; CHECK-NEXT: .param i64, i64{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000074; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +000075; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
76; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 1{{$}}
77; CHECK-NEXT: i64.rem_s $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000078; CHECK-NEXT: return $pop0{{$}}
JF Bastien8f9aea02015-08-01 04:48:44 +000079define i64 @srem64(i64 %x, i64 %y) {
80 %a = srem i64 %x, %y
81 ret i64 %a
82}
83
Dan Gohmane51c0582015-10-06 00:27:55 +000084; CHECK-LABEL: urem64:
Dan Gohman53828fd2015-11-23 16:50:18 +000085; CHECK-NEXT: .param i64, i64{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000086; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +000087; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
88; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 1{{$}}
89; CHECK-NEXT: i64.rem_u $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000090; CHECK-NEXT: return $pop0{{$}}
JF Bastien8f9aea02015-08-01 04:48:44 +000091define i64 @urem64(i64 %x, i64 %y) {
92 %a = urem i64 %x, %y
93 ret i64 %a
94}
95
Dan Gohmane51c0582015-10-06 00:27:55 +000096; CHECK-LABEL: and64:
Dan Gohman53828fd2015-11-23 16:50:18 +000097; CHECK-NEXT: .param i64, i64{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000098; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +000099; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
100; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 1{{$}}
101; CHECK-NEXT: i64.and $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000102; CHECK-NEXT: return $pop0{{$}}
JF Bastien8f9aea02015-08-01 04:48:44 +0000103define i64 @and64(i64 %x, i64 %y) {
104 %a = and i64 %x, %y
105 ret i64 %a
106}
107
Derek Schuff8a76b042015-11-05 17:08:11 +0000108; CHECK-LABEL: or64:
Dan Gohman53828fd2015-11-23 16:50:18 +0000109; CHECK-NEXT: .param i64, i64{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +0000110; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +0000111; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
112; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 1{{$}}
113; CHECK-NEXT: i64.or $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000114; CHECK-NEXT: return $pop0{{$}}
Derek Schuff8a76b042015-11-05 17:08:11 +0000115define i64 @or64(i64 %x, i64 %y) {
JF Bastien8f9aea02015-08-01 04:48:44 +0000116 %a = or i64 %x, %y
117 ret i64 %a
118}
119
Dan Gohmane51c0582015-10-06 00:27:55 +0000120; CHECK-LABEL: xor64:
Dan Gohman53828fd2015-11-23 16:50:18 +0000121; CHECK-NEXT: .param i64, i64{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +0000122; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +0000123; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
124; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 1{{$}}
125; CHECK-NEXT: i64.xor $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000126; CHECK-NEXT: return $pop0{{$}}
JF Bastien8f9aea02015-08-01 04:48:44 +0000127define i64 @xor64(i64 %x, i64 %y) {
128 %a = xor i64 %x, %y
129 ret i64 %a
130}
131
Dan Gohmane51c0582015-10-06 00:27:55 +0000132; CHECK-LABEL: shl64:
Dan Gohman53828fd2015-11-23 16:50:18 +0000133; CHECK-NEXT: .param i64, i64{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +0000134; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +0000135; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
136; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 1{{$}}
137; CHECK-NEXT: i64.shl $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000138; CHECK-NEXT: return $pop0{{$}}
JF Bastienfda53372015-08-03 00:00:11 +0000139define i64 @shl64(i64 %x, i64 %y) {
140 %a = shl i64 %x, %y
141 ret i64 %a
142}
JF Bastien8f9aea02015-08-01 04:48:44 +0000143
Dan Gohmane51c0582015-10-06 00:27:55 +0000144; CHECK-LABEL: shr64:
Dan Gohman53828fd2015-11-23 16:50:18 +0000145; CHECK-NEXT: .param i64, i64{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +0000146; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +0000147; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
148; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 1{{$}}
149; CHECK-NEXT: i64.shr_u $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000150; CHECK-NEXT: return $pop0{{$}}
JF Bastienfda53372015-08-03 00:00:11 +0000151define i64 @shr64(i64 %x, i64 %y) {
152 %a = lshr i64 %x, %y
153 ret i64 %a
154}
JF Bastien8f9aea02015-08-01 04:48:44 +0000155
Dan Gohmane51c0582015-10-06 00:27:55 +0000156; CHECK-LABEL: sar64:
Dan Gohman53828fd2015-11-23 16:50:18 +0000157; CHECK-NEXT: .param i64, i64{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +0000158; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +0000159; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
160; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 1{{$}}
161; CHECK-NEXT: i64.shr_s $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000162; CHECK-NEXT: return $pop0{{$}}
JF Bastienfda53372015-08-03 00:00:11 +0000163define i64 @sar64(i64 %x, i64 %y) {
164 %a = ashr i64 %x, %y
165 ret i64 %a
166}
JF Bastien8f9aea02015-08-01 04:48:44 +0000167
Dan Gohmane51c0582015-10-06 00:27:55 +0000168; CHECK-LABEL: clz64:
169; CHECK-NEXT: .param i64{{$}}
170; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +0000171; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
172; CHECK-NEXT: i64.clz $push0=, $pop[[L0]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000173; CHECK-NEXT: return $pop0{{$}}
JF Bastien8f9aea02015-08-01 04:48:44 +0000174define i64 @clz64(i64 %x) {
175 %a = call i64 @llvm.ctlz.i64(i64 %x, i1 false)
176 ret i64 %a
177}
178
Dan Gohmane51c0582015-10-06 00:27:55 +0000179; CHECK-LABEL: clz64_zero_undef:
180; CHECK-NEXT: .param i64{{$}}
181; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +0000182; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
183; CHECK-NEXT: i64.clz $push0=, $pop[[L0]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000184; CHECK-NEXT: return $pop0{{$}}
Dan Gohman08fc9662015-08-24 16:39:37 +0000185define i64 @clz64_zero_undef(i64 %x) {
186 %a = call i64 @llvm.ctlz.i64(i64 %x, i1 true)
187 ret i64 %a
188}
189
Dan Gohmane51c0582015-10-06 00:27:55 +0000190; CHECK-LABEL: ctz64:
191; CHECK-NEXT: .param i64{{$}}
192; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +0000193; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
194; CHECK-NEXT: i64.ctz $push0=, $pop[[L0]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000195; CHECK-NEXT: return $pop0{{$}}
JF Bastien8f9aea02015-08-01 04:48:44 +0000196define i64 @ctz64(i64 %x) {
197 %a = call i64 @llvm.cttz.i64(i64 %x, i1 false)
198 ret i64 %a
199}
200
Dan Gohmane51c0582015-10-06 00:27:55 +0000201; CHECK-LABEL: ctz64_zero_undef:
202; CHECK-NEXT: .param i64{{$}}
203; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +0000204; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
205; CHECK-NEXT: i64.ctz $push0=, $pop[[L0]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000206; CHECK-NEXT: return $pop0{{$}}
Dan Gohman08fc9662015-08-24 16:39:37 +0000207define i64 @ctz64_zero_undef(i64 %x) {
208 %a = call i64 @llvm.cttz.i64(i64 %x, i1 true)
209 ret i64 %a
210}
211
Dan Gohmane51c0582015-10-06 00:27:55 +0000212; CHECK-LABEL: popcnt64:
213; CHECK-NEXT: .param i64{{$}}
214; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +0000215; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
216; CHECK-NEXT: i64.popcnt $push0=, $pop[[L0]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000217; CHECK-NEXT: return $pop0{{$}}
JF Bastien8f9aea02015-08-01 04:48:44 +0000218define i64 @popcnt64(i64 %x) {
219 %a = call i64 @llvm.ctpop.i64(i64 %x)
220 ret i64 %a
221}
Dan Gohmanc8d7f142016-03-21 19:54:41 +0000222
223; CHECK-LABEL: eqz64:
224; CHECK-NEXT: .param i64{{$}}
225; CHECK-NEXT: .result i32{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +0000226; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
227; CHECK-NEXT: i64.eqz $push0=, $pop[[L0]]{{$}}
Dan Gohmanc8d7f142016-03-21 19:54:41 +0000228; CHECK-NEXT: return $pop0{{$}}
229define i32 @eqz64(i64 %x) {
230 %a = icmp eq i64 %x, 0
231 %b = zext i1 %a to i32
232 ret i32 %b
233}
Dan Gohman665d7e32016-03-22 18:01:49 +0000234
235; CHECK-LABEL: rotl:
236; CHECK-NEXT: .param i64, i64{{$}}
237; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +0000238; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
239; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 1{{$}}
240; CHECK-NEXT: i64.rotl $push0=, $pop[[L0]], $pop[[L1]]
Dan Gohman665d7e32016-03-22 18:01:49 +0000241; CHECK-NEXT: return $pop0{{$}}
242define i64 @rotl(i64 %x, i64 %y) {
243 %z = sub i64 64, %y
244 %b = shl i64 %x, %y
245 %c = lshr i64 %x, %z
246 %d = or i64 %b, %c
247 ret i64 %d
248}
249
250; CHECK-LABEL: masked_rotl:
251; CHECK-NEXT: .param i64, i64{{$}}
252; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +0000253; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
254; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 1{{$}}
255; CHECK-NEXT: i64.rotl $push0=, $pop[[L0]], $pop[[L1]]
Dan Gohman665d7e32016-03-22 18:01:49 +0000256; CHECK-NEXT: return $pop0{{$}}
257define i64 @masked_rotl(i64 %x, i64 %y) {
258 %a = and i64 %y, 63
259 %z = sub i64 64, %a
260 %b = shl i64 %x, %a
261 %c = lshr i64 %x, %z
262 %d = or i64 %b, %c
263 ret i64 %d
264}
265
266; CHECK-LABEL: rotr:
267; CHECK-NEXT: .param i64, i64{{$}}
268; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +0000269; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
270; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 1{{$}}
271; CHECK-NEXT: i64.rotr $push0=, $pop[[L0]], $pop[[L1]]
Dan Gohman665d7e32016-03-22 18:01:49 +0000272; CHECK-NEXT: return $pop0{{$}}
273define i64 @rotr(i64 %x, i64 %y) {
274 %z = sub i64 64, %y
275 %b = lshr i64 %x, %y
276 %c = shl i64 %x, %z
277 %d = or i64 %b, %c
278 ret i64 %d
279}
280
281; CHECK-LABEL: masked_rotr:
282; CHECK-NEXT: .param i64, i64{{$}}
283; CHECK-NEXT: .result i64{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +0000284; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
285; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 1{{$}}
286; CHECK-NEXT: i64.rotr $push0=, $pop[[L0]], $pop[[L1]]
Dan Gohman665d7e32016-03-22 18:01:49 +0000287; CHECK-NEXT: return $pop0{{$}}
288define i64 @masked_rotr(i64 %x, i64 %y) {
289 %a = and i64 %y, 63
290 %z = sub i64 64, %a
291 %b = lshr i64 %x, %a
292 %c = shl i64 %x, %z
293 %d = or i64 %b, %c
294 ret i64 %d
295}