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 datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
6 target triple = "wasm32-unknown-unknown"
8 declare i64 @llvm.ctlz.i64(i64, i1)
9 declare i64 @llvm.cttz.i64(i64, i1)
10 declare i64 @llvm.ctpop.i64(i64)
13 ; CHECK-NEXT: .functype add64 (i64, i64) -> (i64){{$}}
14 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
15 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
16 ; CHECK-NEXT: i64.add $push0=, $pop[[L0]], $pop[[L1]]{{$}}
17 ; CHECK-NEXT: return $pop0{{$}}
18 define i64 @add64(i64 %x, i64 %y) {
24 ; CHECK-NEXT: .functype sub64 (i64, i64) -> (i64){{$}}
25 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
26 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
27 ; CHECK-NEXT: i64.sub $push0=, $pop[[L0]], $pop[[L1]]{{$}}
28 ; CHECK-NEXT: return $pop0{{$}}
29 define i64 @sub64(i64 %x, i64 %y) {
35 ; CHECK-NEXT: .functype mul64 (i64, i64) -> (i64){{$}}
36 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
37 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
38 ; CHECK-NEXT: i64.mul $push0=, $pop[[L0]], $pop[[L1]]{{$}}
39 ; CHECK-NEXT: return $pop0{{$}}
40 define i64 @mul64(i64 %x, i64 %y) {
45 ; CHECK-LABEL: sdiv64:
46 ; CHECK-NEXT: .functype sdiv64 (i64, i64) -> (i64){{$}}
47 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
48 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
49 ; CHECK-NEXT: i64.div_s $push0=, $pop[[L0]], $pop[[L1]]{{$}}
50 ; CHECK-NEXT: return $pop0{{$}}
51 define i64 @sdiv64(i64 %x, i64 %y) {
56 ; CHECK-LABEL: udiv64:
57 ; CHECK-NEXT: .functype udiv64 (i64, i64) -> (i64){{$}}
58 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
59 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
60 ; CHECK-NEXT: i64.div_u $push0=, $pop[[L0]], $pop[[L1]]{{$}}
61 ; CHECK-NEXT: return $pop0{{$}}
62 define i64 @udiv64(i64 %x, i64 %y) {
67 ; CHECK-LABEL: srem64:
68 ; CHECK-NEXT: .functype srem64 (i64, i64) -> (i64){{$}}
69 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
70 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
71 ; CHECK-NEXT: i64.rem_s $push0=, $pop[[L0]], $pop[[L1]]{{$}}
72 ; CHECK-NEXT: return $pop0{{$}}
73 define i64 @srem64(i64 %x, i64 %y) {
78 ; CHECK-LABEL: urem64:
79 ; CHECK-NEXT: .functype urem64 (i64, i64) -> (i64){{$}}
80 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
81 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
82 ; CHECK-NEXT: i64.rem_u $push0=, $pop[[L0]], $pop[[L1]]{{$}}
83 ; CHECK-NEXT: return $pop0{{$}}
84 define i64 @urem64(i64 %x, i64 %y) {
90 ; CHECK-NEXT: .functype and64 (i64, i64) -> (i64){{$}}
91 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
92 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
93 ; CHECK-NEXT: i64.and $push0=, $pop[[L0]], $pop[[L1]]{{$}}
94 ; CHECK-NEXT: return $pop0{{$}}
95 define i64 @and64(i64 %x, i64 %y) {
101 ; CHECK-NEXT: .functype or64 (i64, i64) -> (i64){{$}}
102 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
103 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
104 ; CHECK-NEXT: i64.or $push0=, $pop[[L0]], $pop[[L1]]{{$}}
105 ; CHECK-NEXT: return $pop0{{$}}
106 define i64 @or64(i64 %x, i64 %y) {
111 ; CHECK-LABEL: xor64:
112 ; CHECK-NEXT: .functype xor64 (i64, i64) -> (i64){{$}}
113 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
114 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
115 ; CHECK-NEXT: i64.xor $push0=, $pop[[L0]], $pop[[L1]]{{$}}
116 ; CHECK-NEXT: return $pop0{{$}}
117 define i64 @xor64(i64 %x, i64 %y) {
122 ; CHECK-LABEL: shl64:
123 ; CHECK-NEXT: .functype shl64 (i64, i64) -> (i64){{$}}
124 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
125 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
126 ; CHECK-NEXT: i64.shl $push0=, $pop[[L0]], $pop[[L1]]{{$}}
127 ; CHECK-NEXT: return $pop0{{$}}
128 define i64 @shl64(i64 %x, i64 %y) {
133 ; CHECK-LABEL: shr64:
134 ; CHECK-NEXT: .functype shr64 (i64, i64) -> (i64){{$}}
135 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
136 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
137 ; CHECK-NEXT: i64.shr_u $push0=, $pop[[L0]], $pop[[L1]]{{$}}
138 ; CHECK-NEXT: return $pop0{{$}}
139 define i64 @shr64(i64 %x, i64 %y) {
144 ; CHECK-LABEL: sar64:
145 ; CHECK-NEXT: .functype sar64 (i64, i64) -> (i64){{$}}
146 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
147 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
148 ; CHECK-NEXT: i64.shr_s $push0=, $pop[[L0]], $pop[[L1]]{{$}}
149 ; CHECK-NEXT: return $pop0{{$}}
150 define i64 @sar64(i64 %x, i64 %y) {
155 ; CHECK-LABEL: clz64:
156 ; CHECK-NEXT: .functype clz64 (i64) -> (i64){{$}}
157 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
158 ; CHECK-NEXT: i64.clz $push0=, $pop[[L0]]{{$}}
159 ; CHECK-NEXT: return $pop0{{$}}
160 define i64 @clz64(i64 %x) {
161 %a = call i64 @llvm.ctlz.i64(i64 %x, i1 false)
165 ; CHECK-LABEL: clz64_zero_undef:
166 ; CHECK-NEXT: .functype clz64_zero_undef (i64) -> (i64){{$}}
167 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
168 ; CHECK-NEXT: i64.clz $push0=, $pop[[L0]]{{$}}
169 ; CHECK-NEXT: return $pop0{{$}}
170 define i64 @clz64_zero_undef(i64 %x) {
171 %a = call i64 @llvm.ctlz.i64(i64 %x, i1 true)
175 ; CHECK-LABEL: ctz64:
176 ; CHECK-NEXT: .functype ctz64 (i64) -> (i64){{$}}
177 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
178 ; CHECK-NEXT: i64.ctz $push0=, $pop[[L0]]{{$}}
179 ; CHECK-NEXT: return $pop0{{$}}
180 define i64 @ctz64(i64 %x) {
181 %a = call i64 @llvm.cttz.i64(i64 %x, i1 false)
185 ; CHECK-LABEL: ctz64_zero_undef:
186 ; CHECK-NEXT: .functype ctz64_zero_undef (i64) -> (i64){{$}}
187 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
188 ; CHECK-NEXT: i64.ctz $push0=, $pop[[L0]]{{$}}
189 ; CHECK-NEXT: return $pop0{{$}}
190 define i64 @ctz64_zero_undef(i64 %x) {
191 %a = call i64 @llvm.cttz.i64(i64 %x, i1 true)
195 ; CHECK-LABEL: popcnt64:
196 ; CHECK-NEXT: .functype popcnt64 (i64) -> (i64){{$}}
197 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
198 ; CHECK-NEXT: i64.popcnt $push0=, $pop[[L0]]{{$}}
199 ; CHECK-NEXT: return $pop0{{$}}
200 define i64 @popcnt64(i64 %x) {
201 %a = call i64 @llvm.ctpop.i64(i64 %x)
205 ; CHECK-LABEL: eqz64:
206 ; CHECK-NEXT: .functype eqz64 (i64) -> (i32){{$}}
207 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
208 ; CHECK-NEXT: i64.eqz $push0=, $pop[[L0]]{{$}}
209 ; CHECK-NEXT: return $pop0{{$}}
210 define i32 @eqz64(i64 %x) {
211 %a = icmp eq i64 %x, 0
212 %b = zext i1 %a to i32
217 ; CHECK-NEXT: .functype rotl (i64, i64) -> (i64){{$}}
218 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
219 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
220 ; CHECK-NEXT: i64.rotl $push0=, $pop[[L0]], $pop[[L1]]
221 ; CHECK-NEXT: return $pop0{{$}}
222 define i64 @rotl(i64 %x, i64 %y) {
230 ; CHECK-LABEL: masked_rotl:
231 ; CHECK-NEXT: .functype masked_rotl (i64, i64) -> (i64){{$}}
232 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
233 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
234 ; CHECK-NEXT: i64.rotl $push0=, $pop[[L0]], $pop[[L1]]
235 ; CHECK-NEXT: return $pop0{{$}}
236 define i64 @masked_rotl(i64 %x, i64 %y) {
246 ; CHECK-NEXT: .functype rotr (i64, i64) -> (i64){{$}}
247 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
248 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
249 ; CHECK-NEXT: i64.rotr $push0=, $pop[[L0]], $pop[[L1]]
250 ; CHECK-NEXT: return $pop0{{$}}
251 define i64 @rotr(i64 %x, i64 %y) {
259 ; CHECK-LABEL: masked_rotr:
260 ; CHECK-NEXT: .functype masked_rotr (i64, i64) -> (i64){{$}}
261 ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}
262 ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}
263 ; CHECK-NEXT: i64.rotr $push0=, $pop[[L0]], $pop[[L1]]
264 ; CHECK-NEXT: return $pop0{{$}}
265 define i64 @masked_rotr(i64 %x, i64 %y) {