blob: 45c9a94bee7bff60f9be14add47da50991d246ea [file] [log] [blame]
Wouter van Oortmerssen8a9cb242018-08-27 15:45:51 +00001; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers | FileCheck %s
JF Bastienb9073fb2015-07-22 21:28:15 +00002
JF Bastien8f9aea02015-08-01 04:48:44 +00003; Test that basic 32-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"
Sam Clegga5908002018-05-10 17:49:11 +00006target triple = "wasm32-unknown-unknown"
JF Bastienb9073fb2015-07-22 21:28:15 +00007
JF Bastien600aee92015-07-31 17:53:38 +00008declare i32 @llvm.ctlz.i32(i32, i1)
9declare i32 @llvm.cttz.i32(i32, i1)
10declare i32 @llvm.ctpop.i32(i32)
11
Dan Gohmane51c0582015-10-06 00:27:55 +000012; CHECK-LABEL: add32:
Dan Gohman53828fd2015-11-23 16:50:18 +000013; CHECK-NEXT: .param i32, i32{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000014; CHECK-NEXT: .result i32{{$}}
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: i32.add $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000018; CHECK-NEXT: return $pop0{{$}}
JF Bastienb9073fb2015-07-22 21:28:15 +000019define i32 @add32(i32 %x, i32 %y) {
20 %a = add i32 %x, %y
21 ret i32 %a
22}
JF Bastien600aee92015-07-31 17:53:38 +000023
Dan Gohmane51c0582015-10-06 00:27:55 +000024; CHECK-LABEL: sub32:
Dan Gohman53828fd2015-11-23 16:50:18 +000025; CHECK-NEXT: .param i32, i32{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000026; CHECK-NEXT: .result i32{{$}}
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: i32.sub $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000030; CHECK-NEXT: return $pop0{{$}}
JF Bastien600aee92015-07-31 17:53:38 +000031define i32 @sub32(i32 %x, i32 %y) {
32 %a = sub i32 %x, %y
33 ret i32 %a
34}
35
Dan Gohmane51c0582015-10-06 00:27:55 +000036; CHECK-LABEL: mul32:
Dan Gohman53828fd2015-11-23 16:50:18 +000037; CHECK-NEXT: .param i32, i32{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000038; CHECK-NEXT: .result i32{{$}}
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: i32.mul $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000042; CHECK-NEXT: return $pop0{{$}}
JF Bastien600aee92015-07-31 17:53:38 +000043define i32 @mul32(i32 %x, i32 %y) {
44 %a = mul i32 %x, %y
45 ret i32 %a
46}
47
Dan Gohmane51c0582015-10-06 00:27:55 +000048; CHECK-LABEL: sdiv32:
Dan Gohman53828fd2015-11-23 16:50:18 +000049; CHECK-NEXT: .param i32, i32{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000050; CHECK-NEXT: .result i32{{$}}
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: i32.div_s $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000054; CHECK-NEXT: return $pop0{{$}}
JF Bastien600aee92015-07-31 17:53:38 +000055define i32 @sdiv32(i32 %x, i32 %y) {
56 %a = sdiv i32 %x, %y
57 ret i32 %a
58}
59
Dan Gohmane51c0582015-10-06 00:27:55 +000060; CHECK-LABEL: udiv32:
Dan Gohman53828fd2015-11-23 16:50:18 +000061; CHECK-NEXT: .param i32, i32{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000062; CHECK-NEXT: .result i32{{$}}
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: i32.div_u $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000066; CHECK-NEXT: return $pop0{{$}}
JF Bastien600aee92015-07-31 17:53:38 +000067define i32 @udiv32(i32 %x, i32 %y) {
68 %a = udiv i32 %x, %y
69 ret i32 %a
70}
71
Dan Gohmane51c0582015-10-06 00:27:55 +000072; CHECK-LABEL: srem32:
Dan Gohman53828fd2015-11-23 16:50:18 +000073; CHECK-NEXT: .param i32, i32{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000074; CHECK-NEXT: .result i32{{$}}
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: i32.rem_s $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000078; CHECK-NEXT: return $pop0{{$}}
JF Bastien600aee92015-07-31 17:53:38 +000079define i32 @srem32(i32 %x, i32 %y) {
80 %a = srem i32 %x, %y
81 ret i32 %a
82}
83
Dan Gohmane51c0582015-10-06 00:27:55 +000084; CHECK-LABEL: urem32:
Dan Gohman53828fd2015-11-23 16:50:18 +000085; CHECK-NEXT: .param i32, i32{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000086; CHECK-NEXT: .result i32{{$}}
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: i32.rem_u $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000090; CHECK-NEXT: return $pop0{{$}}
JF Bastien600aee92015-07-31 17:53:38 +000091define i32 @urem32(i32 %x, i32 %y) {
92 %a = urem i32 %x, %y
93 ret i32 %a
94}
95
Dan Gohmane51c0582015-10-06 00:27:55 +000096; CHECK-LABEL: and32:
Dan Gohman53828fd2015-11-23 16:50:18 +000097; CHECK-NEXT: .param i32, i32{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +000098; CHECK-NEXT: .result i32{{$}}
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: i32.and $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000102; CHECK-NEXT: return $pop0{{$}}
JF Bastien600aee92015-07-31 17:53:38 +0000103define i32 @and32(i32 %x, i32 %y) {
104 %a = and i32 %x, %y
105 ret i32 %a
106}
107
Derek Schuff8a76b042015-11-05 17:08:11 +0000108; CHECK-LABEL: or32:
Dan Gohman53828fd2015-11-23 16:50:18 +0000109; CHECK-NEXT: .param i32, i32{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +0000110; CHECK-NEXT: .result i32{{$}}
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: i32.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 i32 @or32(i32 %x, i32 %y) {
JF Bastien600aee92015-07-31 17:53:38 +0000116 %a = or i32 %x, %y
117 ret i32 %a
118}
119
Dan Gohmane51c0582015-10-06 00:27:55 +0000120; CHECK-LABEL: xor32:
Dan Gohman53828fd2015-11-23 16:50:18 +0000121; CHECK-NEXT: .param i32, i32{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +0000122; CHECK-NEXT: .result i32{{$}}
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: i32.xor $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000126; CHECK-NEXT: return $pop0{{$}}
JF Bastien600aee92015-07-31 17:53:38 +0000127define i32 @xor32(i32 %x, i32 %y) {
128 %a = xor i32 %x, %y
129 ret i32 %a
130}
131
Dan Gohmane51c0582015-10-06 00:27:55 +0000132; CHECK-LABEL: shl32:
Dan Gohman53828fd2015-11-23 16:50:18 +0000133; CHECK-NEXT: .param i32, i32{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +0000134; CHECK-NEXT: .result i32{{$}}
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: i32.shl $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000138; CHECK-NEXT: return $pop0{{$}}
JF Bastien600aee92015-07-31 17:53:38 +0000139define i32 @shl32(i32 %x, i32 %y) {
140 %a = shl i32 %x, %y
141 ret i32 %a
142}
143
Dan Gohmane51c0582015-10-06 00:27:55 +0000144; CHECK-LABEL: shr32:
Dan Gohman53828fd2015-11-23 16:50:18 +0000145; CHECK-NEXT: .param i32, i32{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +0000146; CHECK-NEXT: .result i32{{$}}
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: i32.shr_u $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000150; CHECK-NEXT: return $pop0{{$}}
JF Bastien600aee92015-07-31 17:53:38 +0000151define i32 @shr32(i32 %x, i32 %y) {
152 %a = lshr i32 %x, %y
153 ret i32 %a
154}
155
Dan Gohmane51c0582015-10-06 00:27:55 +0000156; CHECK-LABEL: sar32:
Dan Gohman53828fd2015-11-23 16:50:18 +0000157; CHECK-NEXT: .param i32, i32{{$}}
Dan Gohmane51c0582015-10-06 00:27:55 +0000158; CHECK-NEXT: .result i32{{$}}
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: i32.shr_s $push0=, $pop[[L0]], $pop[[L1]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000162; CHECK-NEXT: return $pop0{{$}}
JF Bastien600aee92015-07-31 17:53:38 +0000163define i32 @sar32(i32 %x, i32 %y) {
164 %a = ashr i32 %x, %y
165 ret i32 %a
166}
167
Dan Gohmane51c0582015-10-06 00:27:55 +0000168; CHECK-LABEL: clz32:
169; CHECK-NEXT: .param i32{{$}}
170; CHECK-NEXT: .result i32{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +0000171; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
172; CHECK-NEXT: i32.clz $push0=, $pop[[L0]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000173; CHECK-NEXT: return $pop0{{$}}
JF Bastien600aee92015-07-31 17:53:38 +0000174define i32 @clz32(i32 %x) {
175 %a = call i32 @llvm.ctlz.i32(i32 %x, i1 false)
176 ret i32 %a
177}
178
Dan Gohmane51c0582015-10-06 00:27:55 +0000179; CHECK-LABEL: clz32_zero_undef:
180; CHECK-NEXT: .param i32{{$}}
181; CHECK-NEXT: .result i32{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +0000182; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
183; CHECK-NEXT: i32.clz $push0=, $pop[[L0]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000184; CHECK-NEXT: return $pop0{{$}}
Dan Gohman08fc9662015-08-24 16:39:37 +0000185define i32 @clz32_zero_undef(i32 %x) {
186 %a = call i32 @llvm.ctlz.i32(i32 %x, i1 true)
187 ret i32 %a
188}
189
Dan Gohmane51c0582015-10-06 00:27:55 +0000190; CHECK-LABEL: ctz32:
191; CHECK-NEXT: .param i32{{$}}
192; CHECK-NEXT: .result i32{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +0000193; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
194; CHECK-NEXT: i32.ctz $push0=, $pop[[L0]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000195; CHECK-NEXT: return $pop0{{$}}
JF Bastien600aee92015-07-31 17:53:38 +0000196define i32 @ctz32(i32 %x) {
197 %a = call i32 @llvm.cttz.i32(i32 %x, i1 false)
198 ret i32 %a
199}
200
Dan Gohmane51c0582015-10-06 00:27:55 +0000201; CHECK-LABEL: ctz32_zero_undef:
202; CHECK-NEXT: .param i32{{$}}
203; CHECK-NEXT: .result i32{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +0000204; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
205; CHECK-NEXT: i32.ctz $push0=, $pop[[L0]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000206; CHECK-NEXT: return $pop0{{$}}
Dan Gohman08fc9662015-08-24 16:39:37 +0000207define i32 @ctz32_zero_undef(i32 %x) {
208 %a = call i32 @llvm.cttz.i32(i32 %x, i1 true)
209 ret i32 %a
210}
211
Dan Gohmane51c0582015-10-06 00:27:55 +0000212; CHECK-LABEL: popcnt32:
213; CHECK-NEXT: .param i32{{$}}
214; CHECK-NEXT: .result i32{{$}}
Dan Gohmand934cb82017-02-24 23:18:00 +0000215; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}}
216; CHECK-NEXT: i32.popcnt $push0=, $pop[[L0]]{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000217; CHECK-NEXT: return $pop0{{$}}
JF Bastien600aee92015-07-31 17:53:38 +0000218define i32 @popcnt32(i32 %x) {
219 %a = call i32 @llvm.ctpop.i32(i32 %x)
220 ret i32 %a
221}
Dan Gohmanc8d7f142016-03-21 19:54:41 +0000222
223; CHECK-LABEL: eqz32:
224; CHECK-NEXT: .param i32{{$}}
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: i32.eqz $push0=, $pop[[L0]]{{$}}
Dan Gohmanc8d7f142016-03-21 19:54:41 +0000228; CHECK-NEXT: return $pop0{{$}}
229define i32 @eqz32(i32 %x) {
230 %a = icmp eq i32 %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 i32, i32{{$}}
237; CHECK-NEXT: .result i32{{$}}
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: i32.rotl $push0=, $pop[[L0]], $pop[[L1]]
Dan Gohman665d7e32016-03-22 18:01:49 +0000241; CHECK-NEXT: return $pop0{{$}}
242define i32 @rotl(i32 %x, i32 %y) {
243 %z = sub i32 32, %y
244 %b = shl i32 %x, %y
245 %c = lshr i32 %x, %z
246 %d = or i32 %b, %c
247 ret i32 %d
248}
249
250; CHECK-LABEL: masked_rotl:
251; CHECK-NEXT: .param i32, i32{{$}}
252; CHECK-NEXT: .result i32{{$}}
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: i32.rotl $push0=, $pop[[L0]], $pop[[L1]]
Dan Gohman665d7e32016-03-22 18:01:49 +0000256; CHECK-NEXT: return $pop0{{$}}
257define i32 @masked_rotl(i32 %x, i32 %y) {
258 %a = and i32 %y, 31
259 %z = sub i32 32, %a
260 %b = shl i32 %x, %a
261 %c = lshr i32 %x, %z
262 %d = or i32 %b, %c
263 ret i32 %d
264}
265
266; CHECK-LABEL: rotr:
267; CHECK-NEXT: .param i32, i32{{$}}
268; CHECK-NEXT: .result i32{{$}}
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: i32.rotr $push0=, $pop[[L0]], $pop[[L1]]
Dan Gohman665d7e32016-03-22 18:01:49 +0000272; CHECK-NEXT: return $pop0{{$}}
273define i32 @rotr(i32 %x, i32 %y) {
274 %z = sub i32 32, %y
275 %b = lshr i32 %x, %y
276 %c = shl i32 %x, %z
277 %d = or i32 %b, %c
278 ret i32 %d
279}
280
281; CHECK-LABEL: masked_rotr:
282; CHECK-NEXT: .param i32, i32{{$}}
283; CHECK-NEXT: .result i32{{$}}
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: i32.rotr $push0=, $pop[[L0]], $pop[[L1]]
Dan Gohman665d7e32016-03-22 18:01:49 +0000287; CHECK-NEXT: return $pop0{{$}}
288define i32 @masked_rotr(i32 %x, i32 %y) {
289 %a = and i32 %y, 31
290 %z = sub i32 32, %a
291 %b = lshr i32 %x, %a
292 %c = shl i32 %x, %z
293 %d = or i32 %b, %c
294 ret i32 %d
295}