1 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers | FileCheck %s
3 ; Test that basic 64-bit integer operations assemble as expected.
5 target triple = "wasm32-unknown-unknown"
7 declare i64 @llvm.ctlz.i64(i64, i1)
8 declare i64 @llvm.cttz.i64(i64, i1)
9 declare i64 @llvm.ctpop.i64(i64)
12 ; CHECK-NEXT: .functype add64 (i64, i64) -> (i64){{$}}
13 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
14 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
15 ; CHECK-NEXT: i64.add $push0=, $pop[[L0]], $pop[[L1]]{{$}}
16 ; CHECK-NEXT: return $pop0{{$}}
17 define i64 @add64(i64 %x, i64 %y) {
23 ; CHECK-NEXT: .functype sub64 (i64, i64) -> (i64){{$}}
24 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
25 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
26 ; CHECK-NEXT: i64.sub $push0=, $pop[[L0]], $pop[[L1]]{{$}}
27 ; CHECK-NEXT: return $pop0{{$}}
28 define i64 @sub64(i64 %x, i64 %y) {
34 ; CHECK-NEXT: .functype mul64 (i64, i64) -> (i64){{$}}
35 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
36 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
37 ; CHECK-NEXT: i64.mul $push0=, $pop[[L0]], $pop[[L1]]{{$}}
38 ; CHECK-NEXT: return $pop0{{$}}
39 define i64 @mul64(i64 %x, i64 %y) {
44 ; CHECK-LABEL: sdiv64:
45 ; CHECK-NEXT: .functype sdiv64 (i64, i64) -> (i64){{$}}
46 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
47 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
48 ; CHECK-NEXT: i64.div_s $push0=, $pop[[L0]], $pop[[L1]]{{$}}
49 ; CHECK-NEXT: return $pop0{{$}}
50 define i64 @sdiv64(i64 %x, i64 %y) {
55 ; CHECK-LABEL: udiv64:
56 ; CHECK-NEXT: .functype udiv64 (i64, i64) -> (i64){{$}}
57 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
58 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
59 ; CHECK-NEXT: i64.div_u $push0=, $pop[[L0]], $pop[[L1]]{{$}}
60 ; CHECK-NEXT: return $pop0{{$}}
61 define i64 @udiv64(i64 %x, i64 %y) {
66 ; CHECK-LABEL: srem64:
67 ; CHECK-NEXT: .functype srem64 (i64, i64) -> (i64){{$}}
68 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
69 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
70 ; CHECK-NEXT: i64.rem_s $push0=, $pop[[L0]], $pop[[L1]]{{$}}
71 ; CHECK-NEXT: return $pop0{{$}}
72 define i64 @srem64(i64 %x, i64 %y) {
77 ; CHECK-LABEL: urem64:
78 ; CHECK-NEXT: .functype urem64 (i64, i64) -> (i64){{$}}
79 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
80 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
81 ; CHECK-NEXT: i64.rem_u $push0=, $pop[[L0]], $pop[[L1]]{{$}}
82 ; CHECK-NEXT: return $pop0{{$}}
83 define i64 @urem64(i64 %x, i64 %y) {
89 ; CHECK-NEXT: .functype and64 (i64, i64) -> (i64){{$}}
90 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
91 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
92 ; CHECK-NEXT: i64.and $push0=, $pop[[L0]], $pop[[L1]]{{$}}
93 ; CHECK-NEXT: return $pop0{{$}}
94 define i64 @and64(i64 %x, i64 %y) {
100 ; CHECK-NEXT: .functype or64 (i64, i64) -> (i64){{$}}
101 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
102 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
103 ; CHECK-NEXT: i64.or $push0=, $pop[[L0]], $pop[[L1]]{{$}}
104 ; CHECK-NEXT: return $pop0{{$}}
105 define i64 @or64(i64 %x, i64 %y) {
110 ; CHECK-LABEL: xor64:
111 ; CHECK-NEXT: .functype xor64 (i64, i64) -> (i64){{$}}
112 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
113 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
114 ; CHECK-NEXT: i64.xor $push0=, $pop[[L0]], $pop[[L1]]{{$}}
115 ; CHECK-NEXT: return $pop0{{$}}
116 define i64 @xor64(i64 %x, i64 %y) {
121 ; CHECK-LABEL: shl64:
122 ; CHECK-NEXT: .functype shl64 (i64, i64) -> (i64){{$}}
123 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
124 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
125 ; CHECK-NEXT: i64.shl $push0=, $pop[[L0]], $pop[[L1]]{{$}}
126 ; CHECK-NEXT: return $pop0{{$}}
127 define i64 @shl64(i64 %x, i64 %y) {
132 ; CHECK-LABEL: shr64:
133 ; CHECK-NEXT: .functype shr64 (i64, i64) -> (i64){{$}}
134 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
135 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
136 ; CHECK-NEXT: i64.shr_u $push0=, $pop[[L0]], $pop[[L1]]{{$}}
137 ; CHECK-NEXT: return $pop0{{$}}
138 define i64 @shr64(i64 %x, i64 %y) {
143 ; CHECK-LABEL: sar64:
144 ; CHECK-NEXT: .functype sar64 (i64, i64) -> (i64){{$}}
145 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
146 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
147 ; CHECK-NEXT: i64.shr_s $push0=, $pop[[L0]], $pop[[L1]]{{$}}
148 ; CHECK-NEXT: return $pop0{{$}}
149 define i64 @sar64(i64 %x, i64 %y) {
154 ; CHECK-LABEL: clz64:
155 ; CHECK-NEXT: .functype clz64 (i64) -> (i64){{$}}
156 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
157 ; CHECK-NEXT: i64.clz $push0=, $pop[[L0]]{{$}}
158 ; CHECK-NEXT: return $pop0{{$}}
159 define i64 @clz64(i64 %x) {
160 %a = call i64 @llvm.ctlz.i64(i64 %x, i1 false)
164 ; CHECK-LABEL: clz64_zero_undef:
165 ; CHECK-NEXT: .functype clz64_zero_undef (i64) -> (i64){{$}}
166 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
167 ; CHECK-NEXT: i64.clz $push0=, $pop[[L0]]{{$}}
168 ; CHECK-NEXT: return $pop0{{$}}
169 define i64 @clz64_zero_undef(i64 %x) {
170 %a = call i64 @llvm.ctlz.i64(i64 %x, i1 true)
174 ; CHECK-LABEL: ctz64:
175 ; CHECK-NEXT: .functype ctz64 (i64) -> (i64){{$}}
176 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
177 ; CHECK-NEXT: i64.ctz $push0=, $pop[[L0]]{{$}}
178 ; CHECK-NEXT: return $pop0{{$}}
179 define i64 @ctz64(i64 %x) {
180 %a = call i64 @llvm.cttz.i64(i64 %x, i1 false)
184 ; CHECK-LABEL: ctz64_zero_undef:
185 ; CHECK-NEXT: .functype ctz64_zero_undef (i64) -> (i64){{$}}
186 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
187 ; CHECK-NEXT: i64.ctz $push0=, $pop[[L0]]{{$}}
188 ; CHECK-NEXT: return $pop0{{$}}
189 define i64 @ctz64_zero_undef(i64 %x) {
190 %a = call i64 @llvm.cttz.i64(i64 %x, i1 true)
194 ; CHECK-LABEL: popcnt64:
195 ; CHECK-NEXT: .functype popcnt64 (i64) -> (i64){{$}}
196 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
197 ; CHECK-NEXT: i64.popcnt $push0=, $pop[[L0]]{{$}}
198 ; CHECK-NEXT: return $pop0{{$}}
199 define i64 @popcnt64(i64 %x) {
200 %a = call i64 @llvm.ctpop.i64(i64 %x)
204 ; CHECK-LABEL: eqz64:
205 ; CHECK-NEXT: .functype eqz64 (i64) -> (i32){{$}}
206 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
207 ; CHECK-NEXT: i64.eqz $push0=, $pop[[L0]]{{$}}
208 ; CHECK-NEXT: return $pop0{{$}}
209 define i32 @eqz64(i64 %x) {
210 %a = icmp eq i64 %x, 0
211 %b = zext i1 %a to i32
216 ; CHECK-NEXT: .functype rotl (i64, i64) -> (i64){{$}}
217 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
218 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
219 ; CHECK-NEXT: i64.rotl $push0=, $pop[[L0]], $pop[[L1]]
220 ; CHECK-NEXT: return $pop0{{$}}
221 define i64 @rotl(i64 %x, i64 %y) {
229 ; CHECK-LABEL: masked_rotl:
230 ; CHECK-NEXT: .functype masked_rotl (i64, i64) -> (i64){{$}}
231 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
232 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
233 ; CHECK-NEXT: i64.rotl $push0=, $pop[[L0]], $pop[[L1]]
234 ; CHECK-NEXT: return $pop0{{$}}
235 define i64 @masked_rotl(i64 %x, i64 %y) {
245 ; CHECK-NEXT: .functype rotr (i64, i64) -> (i64){{$}}
246 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
247 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
248 ; CHECK-NEXT: i64.rotr $push0=, $pop[[L0]], $pop[[L1]]
249 ; CHECK-NEXT: return $pop0{{$}}
250 define i64 @rotr(i64 %x, i64 %y) {
258 ; CHECK-LABEL: masked_rotr:
259 ; CHECK-NEXT: .functype masked_rotr (i64, i64) -> (i64){{$}}
260 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
261 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
262 ; CHECK-NEXT: i64.rotr $push0=, $pop[[L0]], $pop[[L1]]
263 ; CHECK-NEXT: return $pop0{{$}}
264 define i64 @masked_rotr(i64 %x, i64 %y) {