1 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers | FileCheck %s
3 ; Test that basic 128-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 i128 @llvm.ctlz.i128(i128, i1)
9 declare i128 @llvm.cttz.i128(i128, i1)
10 declare i128 @llvm.ctpop.i128(i128)
12 ; CHECK-LABEL: add128:
13 ; CHECK-NEXT: .functype add128 (i32, i64, i64, i64, i64) -> (){{$}}
19 ; CHECK-NEXT: return{{$}}
20 define i128 @add128(i128 %x, i128 %y) {
25 ; CHECK-LABEL: sub128:
26 ; CHECK-NEXT: .functype sub128 (i32, i64, i64, i64, i64) -> (){{$}}
31 ; CHECK-NEXT: return{{$}}
32 define i128 @sub128(i128 %x, i128 %y) {
37 ; CHECK-LABEL: mul128:
38 ; CHECK-NEXT: .functype mul128 (i32, i64, i64, i64, i64) -> (){{$}}
39 ; CHECK: call __multi3, ${{.+}}, ${{.+}}, ${{.+}}, ${{.+}}, ${{.+}}{{$}}
41 define i128 @mul128(i128 %x, i128 %y) {
46 ; CHECK-LABEL: sdiv128:
47 ; CHECK-NEXT: .functype sdiv128 (i32, i64, i64, i64, i64) -> (){{$}}
48 ; CHECK: call __divti3, ${{.+}}, ${{.+}}, ${{.+}}, ${{.+}}, ${{.+}}{{$}}
50 define i128 @sdiv128(i128 %x, i128 %y) {
55 ; CHECK-LABEL: udiv128:
56 ; CHECK-NEXT: .functype udiv128 (i32, i64, i64, i64, i64) -> (){{$}}
57 ; CHECK: call __udivti3, ${{.+}}, ${{.+}}, ${{.+}}, ${{.+}}, ${{.+}}{{$}}
59 define i128 @udiv128(i128 %x, i128 %y) {
64 ; CHECK-LABEL: srem128:
65 ; CHECK-NEXT: .functype srem128 (i32, i64, i64, i64, i64) -> (){{$}}
66 ; CHECK: call __modti3, ${{.+}}, ${{.+}}, ${{.+}}, ${{.+}}, ${{.+}}{{$}}
68 define i128 @srem128(i128 %x, i128 %y) {
73 ; CHECK-LABEL: urem128:
74 ; CHECK-NEXT: .functype urem128 (i32, i64, i64, i64, i64) -> (){{$}}
75 ; CHECK: call __umodti3, ${{.+}}, ${{.+}}, ${{.+}}, ${{.+}}, ${{.+}}{{$}}
77 define i128 @urem128(i128 %x, i128 %y) {
82 ; CHECK-LABEL: and128:
83 ; CHECK-NEXT: .functype and128 (i32, i64, i64, i64, i64) -> (){{$}}
89 ; CHECK-NEXT: return{{$}}
90 define i128 @and128(i128 %x, i128 %y) {
96 ; CHECK-NEXT: .functype or128 (i32, i64, i64, i64, i64) -> (){{$}}
101 ; CHECK-NEXT: return{{$}}
102 define i128 @or128(i128 %x, i128 %y) {
107 ; CHECK-LABEL: xor128:
108 ; CHECK-NEXT: .functype xor128 (i32, i64, i64, i64, i64) -> (){{$}}
113 ; CHECK-NEXT: return{{$}}
114 define i128 @xor128(i128 %x, i128 %y) {
119 ; CHECK-LABEL: shl128:
120 ; CHECK-NEXT: .functype shl128 (i32, i64, i64, i64, i64) -> (){{$}}
121 ; CHECK: call __ashlti3, ${{.+}}, ${{.+}}, ${{.+}}, ${{.+}}{{$}}
123 define i128 @shl128(i128 %x, i128 %y) {
128 ; CHECK-LABEL: shr128:
129 ; CHECK-NEXT: .functype shr128 (i32, i64, i64, i64, i64) -> (){{$}}
130 ; CHECK: call __lshrti3, ${{.+}}, ${{.+}}, ${{.+}}, ${{.+}}{{$}}
132 define i128 @shr128(i128 %x, i128 %y) {
133 %a = lshr i128 %x, %y
137 ; CHECK-LABEL: sar128:
138 ; CHECK-NEXT: .functype sar128 (i32, i64, i64, i64, i64) -> (){{$}}
139 ; CHECK: call __ashrti3, ${{.+}}, ${{.+}}, ${{.+}}, ${{.+}}{{$}}
141 define i128 @sar128(i128 %x, i128 %y) {
142 %a = ashr i128 %x, %y
146 ; CHECK-LABEL: clz128:
147 ; CHECK-NEXT: .functype clz128 (i32, i64, i64) -> (){{$}}
152 define i128 @clz128(i128 %x) {
153 %a = call i128 @llvm.ctlz.i128(i128 %x, i1 false)
157 ; CHECK-LABEL: clz128_zero_undef:
158 ; CHECK-NEXT: .functype clz128_zero_undef (i32, i64, i64) -> (){{$}}
162 define i128 @clz128_zero_undef(i128 %x) {
163 %a = call i128 @llvm.ctlz.i128(i128 %x, i1 true)
167 ; CHECK-LABEL: ctz128:
168 ; CHECK-NEXT: .functype ctz128 (i32, i64, i64) -> (){{$}}
172 define i128 @ctz128(i128 %x) {
173 %a = call i128 @llvm.cttz.i128(i128 %x, i1 false)
177 ; CHECK-LABEL: ctz128_zero_undef:
178 ; CHECK-NEXT: .functype ctz128_zero_undef (i32, i64, i64) -> (){{$}}
182 define i128 @ctz128_zero_undef(i128 %x) {
183 %a = call i128 @llvm.cttz.i128(i128 %x, i1 true)
187 ; CHECK-LABEL: popcnt128:
188 ; CHECK-NEXT: .functype popcnt128 (i32, i64, i64) -> (){{$}}
192 define i128 @popcnt128(i128 %x) {
193 %a = call i128 @llvm.ctpop.i128(i128 %x)
197 ; CHECK-LABEL: eqz128:
198 ; CHECK-NEXT: .functype eqz128 (i64, i64) -> (i32){{$}}
202 define i32 @eqz128(i128 %x) {
203 %a = icmp eq i128 %x, 0
204 %b = zext i1 %a to i32
209 ; CHECK-NEXT: .functype rotl (i32, i64, i64, i64, i64) -> (){{$}}
210 ; CHECK: call __ashlti3, ${{.+}}, ${{.+}}, ${{.+}}, ${{.+}}{{$}}
211 ; CHECK: call __lshrti3, ${{.+}}, ${{.+}}, ${{.+}}, ${{.+}}{{$}}
213 define i128 @rotl(i128 %x, i128 %y) {
214 %z = sub i128 128, %y
216 %c = lshr i128 %x, %z
221 ; CHECK-LABEL: masked_rotl:
222 ; CHECK-NEXT: .functype masked_rotl (i32, i64, i64, i64, i64) -> (){{$}}
223 ; CHECK: call __ashlti3, ${{.+}}, ${{.+}}, ${{.+}}, ${{.+}}{{$}}
224 ; CHECK: call __lshrti3, ${{.+}}, ${{.+}}, ${{.+}}, ${{.+}}{{$}}
226 define i128 @masked_rotl(i128 %x, i128 %y) {
227 %a = and i128 %y, 127
228 %z = sub i128 128, %a
230 %c = lshr i128 %x, %z
236 ; CHECK-NEXT: .functype rotr (i32, i64, i64, i64, i64) -> (){{$}}
237 ; CHECK: call __lshrti3, ${{.+}}, ${{.+}}, ${{.+}}, ${{.+}}{{$}}
238 ; CHECK: call __ashlti3, ${{.+}}, ${{.+}}, ${{.+}}, ${{.+}}{{$}}
240 define i128 @rotr(i128 %x, i128 %y) {
241 %z = sub i128 128, %y
242 %b = lshr i128 %x, %y
248 ; CHECK-LABEL: masked_rotr:
249 ; CHECK-NEXT: .functype masked_rotr (i32, i64, i64, i64, i64) -> (){{$}}
250 ; CHECK: call __lshrti3, ${{.+}}, ${{.+}}, ${{.+}}, ${{.+}}{{$}}
251 ; CHECK: call __ashlti3, ${{.+}}, ${{.+}}, ${{.+}}, ${{.+}}{{$}}
253 define i128 @masked_rotr(i128 %x, i128 %y) {
254 %a = and i128 %y, 127
255 %z = sub i128 128, %a
256 %b = lshr i128 %x, %a