1 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers | FileCheck %s
3 ; Test that basic 32-bit integer operations assemble as expected.
5 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
6 target triple = "wasm32-unknown-unknown"
8 declare i32 @llvm.ctlz.i32(i32, i1)
9 declare i32 @llvm.cttz.i32(i32, i1)
10 declare i32 @llvm.ctpop.i32(i32)
13 ; CHECK-NEXT: .functype add32 (i32, i32) -> (i32){{$}}
14 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
15 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
16 ; CHECK-NEXT: i32.add $push0=, $pop[[L0]], $pop[[L1]]{{$}}
17 ; CHECK-NEXT: return $pop0{{$}}
18 define i32 @add32(i32 %x, i32 %y) {
24 ; CHECK-NEXT: .functype sub32 (i32, i32) -> (i32){{$}}
25 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
26 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
27 ; CHECK-NEXT: i32.sub $push0=, $pop[[L0]], $pop[[L1]]{{$}}
28 ; CHECK-NEXT: return $pop0{{$}}
29 define i32 @sub32(i32 %x, i32 %y) {
35 ; CHECK-NEXT: .functype mul32 (i32, i32) -> (i32){{$}}
36 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
37 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
38 ; CHECK-NEXT: i32.mul $push0=, $pop[[L0]], $pop[[L1]]{{$}}
39 ; CHECK-NEXT: return $pop0{{$}}
40 define i32 @mul32(i32 %x, i32 %y) {
45 ; CHECK-LABEL: sdiv32:
46 ; CHECK-NEXT: .functype sdiv32 (i32, i32) -> (i32){{$}}
47 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
48 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
49 ; CHECK-NEXT: i32.div_s $push0=, $pop[[L0]], $pop[[L1]]{{$}}
50 ; CHECK-NEXT: return $pop0{{$}}
51 define i32 @sdiv32(i32 %x, i32 %y) {
56 ; CHECK-LABEL: udiv32:
57 ; CHECK-NEXT: .functype udiv32 (i32, i32) -> (i32){{$}}
58 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
59 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
60 ; CHECK-NEXT: i32.div_u $push0=, $pop[[L0]], $pop[[L1]]{{$}}
61 ; CHECK-NEXT: return $pop0{{$}}
62 define i32 @udiv32(i32 %x, i32 %y) {
67 ; CHECK-LABEL: srem32:
68 ; CHECK-NEXT: .functype srem32 (i32, i32) -> (i32){{$}}
69 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
70 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
71 ; CHECK-NEXT: i32.rem_s $push0=, $pop[[L0]], $pop[[L1]]{{$}}
72 ; CHECK-NEXT: return $pop0{{$}}
73 define i32 @srem32(i32 %x, i32 %y) {
78 ; CHECK-LABEL: urem32:
79 ; CHECK-NEXT: .functype urem32 (i32, i32) -> (i32){{$}}
80 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
81 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
82 ; CHECK-NEXT: i32.rem_u $push0=, $pop[[L0]], $pop[[L1]]{{$}}
83 ; CHECK-NEXT: return $pop0{{$}}
84 define i32 @urem32(i32 %x, i32 %y) {
90 ; CHECK-NEXT: .functype and32 (i32, i32) -> (i32){{$}}
91 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
92 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
93 ; CHECK-NEXT: i32.and $push0=, $pop[[L0]], $pop[[L1]]{{$}}
94 ; CHECK-NEXT: return $pop0{{$}}
95 define i32 @and32(i32 %x, i32 %y) {
101 ; CHECK-NEXT: .functype or32 (i32, i32) -> (i32){{$}}
102 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
103 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
104 ; CHECK-NEXT: i32.or $push0=, $pop[[L0]], $pop[[L1]]{{$}}
105 ; CHECK-NEXT: return $pop0{{$}}
106 define i32 @or32(i32 %x, i32 %y) {
111 ; CHECK-LABEL: xor32:
112 ; CHECK-NEXT: .functype xor32 (i32, i32) -> (i32){{$}}
113 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
114 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
115 ; CHECK-NEXT: i32.xor $push0=, $pop[[L0]], $pop[[L1]]{{$}}
116 ; CHECK-NEXT: return $pop0{{$}}
117 define i32 @xor32(i32 %x, i32 %y) {
122 ; CHECK-LABEL: shl32:
123 ; CHECK-NEXT: .functype shl32 (i32, i32) -> (i32){{$}}
124 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
125 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
126 ; CHECK-NEXT: i32.shl $push0=, $pop[[L0]], $pop[[L1]]{{$}}
127 ; CHECK-NEXT: return $pop0{{$}}
128 define i32 @shl32(i32 %x, i32 %y) {
133 ; CHECK-LABEL: shr32:
134 ; CHECK-NEXT: .functype shr32 (i32, i32) -> (i32){{$}}
135 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
136 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
137 ; CHECK-NEXT: i32.shr_u $push0=, $pop[[L0]], $pop[[L1]]{{$}}
138 ; CHECK-NEXT: return $pop0{{$}}
139 define i32 @shr32(i32 %x, i32 %y) {
144 ; CHECK-LABEL: sar32:
145 ; CHECK-NEXT: .functype sar32 (i32, i32) -> (i32){{$}}
146 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
147 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
148 ; CHECK-NEXT: i32.shr_s $push0=, $pop[[L0]], $pop[[L1]]{{$}}
149 ; CHECK-NEXT: return $pop0{{$}}
150 define i32 @sar32(i32 %x, i32 %y) {
155 ; CHECK-LABEL: clz32:
156 ; CHECK-NEXT: .functype clz32 (i32) -> (i32){{$}}
157 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
158 ; CHECK-NEXT: i32.clz $push0=, $pop[[L0]]{{$}}
159 ; CHECK-NEXT: return $pop0{{$}}
160 define i32 @clz32(i32 %x) {
161 %a = call i32 @llvm.ctlz.i32(i32 %x, i1 false)
165 ; CHECK-LABEL: clz32_zero_undef:
166 ; CHECK-NEXT: .functype clz32_zero_undef (i32) -> (i32){{$}}
167 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
168 ; CHECK-NEXT: i32.clz $push0=, $pop[[L0]]{{$}}
169 ; CHECK-NEXT: return $pop0{{$}}
170 define i32 @clz32_zero_undef(i32 %x) {
171 %a = call i32 @llvm.ctlz.i32(i32 %x, i1 true)
175 ; CHECK-LABEL: ctz32:
176 ; CHECK-NEXT: .functype ctz32 (i32) -> (i32){{$}}
177 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
178 ; CHECK-NEXT: i32.ctz $push0=, $pop[[L0]]{{$}}
179 ; CHECK-NEXT: return $pop0{{$}}
180 define i32 @ctz32(i32 %x) {
181 %a = call i32 @llvm.cttz.i32(i32 %x, i1 false)
185 ; CHECK-LABEL: ctz32_zero_undef:
186 ; CHECK-NEXT: .functype ctz32_zero_undef (i32) -> (i32){{$}}
187 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
188 ; CHECK-NEXT: i32.ctz $push0=, $pop[[L0]]{{$}}
189 ; CHECK-NEXT: return $pop0{{$}}
190 define i32 @ctz32_zero_undef(i32 %x) {
191 %a = call i32 @llvm.cttz.i32(i32 %x, i1 true)
195 ; CHECK-LABEL: popcnt32:
196 ; CHECK-NEXT: .functype popcnt32 (i32) -> (i32){{$}}
197 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
198 ; CHECK-NEXT: i32.popcnt $push0=, $pop[[L0]]{{$}}
199 ; CHECK-NEXT: return $pop0{{$}}
200 define i32 @popcnt32(i32 %x) {
201 %a = call i32 @llvm.ctpop.i32(i32 %x)
205 ; CHECK-LABEL: eqz32:
206 ; CHECK-NEXT: .functype eqz32 (i32) -> (i32){{$}}
207 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
208 ; CHECK-NEXT: i32.eqz $push0=, $pop[[L0]]{{$}}
209 ; CHECK-NEXT: return $pop0{{$}}
210 define i32 @eqz32(i32 %x) {
211 %a = icmp eq i32 %x, 0
212 %b = zext i1 %a to i32
217 ; CHECK-NEXT: .functype rotl (i32, i32) -> (i32){{$}}
218 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
219 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
220 ; CHECK-NEXT: i32.rotl $push0=, $pop[[L0]], $pop[[L1]]
221 ; CHECK-NEXT: return $pop0{{$}}
222 define i32 @rotl(i32 %x, i32 %y) {
230 ; CHECK-LABEL: masked_rotl:
231 ; CHECK-NEXT: .functype masked_rotl (i32, i32) -> (i32){{$}}
232 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
233 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
234 ; CHECK-NEXT: i32.rotl $push0=, $pop[[L0]], $pop[[L1]]
235 ; CHECK-NEXT: return $pop0{{$}}
236 define i32 @masked_rotl(i32 %x, i32 %y) {
246 ; CHECK-NEXT: .functype rotr (i32, i32) -> (i32){{$}}
247 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
248 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
249 ; CHECK-NEXT: i32.rotr $push0=, $pop[[L0]], $pop[[L1]]
250 ; CHECK-NEXT: return $pop0{{$}}
251 define i32 @rotr(i32 %x, i32 %y) {
259 ; CHECK-LABEL: masked_rotr:
260 ; CHECK-NEXT: .functype masked_rotr (i32, i32) -> (i32){{$}}
261 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
262 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
263 ; CHECK-NEXT: i32.rotr $push0=, $pop[[L0]], $pop[[L1]]
264 ; CHECK-NEXT: return $pop0{{$}}
265 define i32 @masked_rotr(i32 %x, i32 %y) {