1; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt | FileCheck %s
2
3; Test zeroext and signext ABI keywords
4
5target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
6target triple = "wasm32-unknown-unknown"
7
8; CHECK-LABEL: z2s_func:
9; CHECK-NEXT: .param i32{{$}}
10; CHECK-NEXT: .result i32{{$}}
11; CHECK-NEXT: i32.const $push[[NUM0:[0-9]+]]=, 24{{$}}
12; CHECK-NEXT: i32.shl $push[[NUM2:[0-9]+]]=, $0, $pop[[NUM0]]{{$}}
13; CHECK-NEXT: i32.const $push[[NUM1:[0-9]+]]=, 24{{$}}
14; CHECK-NEXT: i32.shr_s $push[[NUM3:[0-9]+]]=, $pop[[NUM2]], $pop[[NUM1]]{{$}}
15; CHECK-NEXT: return $pop[[NUM3]]{{$}}
16define signext i8 @z2s_func(i8 zeroext %t) {
17  ret i8 %t
18}
19
20; CHECK-LABEL: s2z_func:
21; CHECK-NEXT: .param i32{{$}}
22; CHECK-NEXT: .result i32{{$}}
23; CHECK-NEXT: i32.const $push[[NUM0:[0-9]+]]=, 255{{$}}
24; CHECK-NEXT: i32.and $push[[NUM1:[0-9]+]]=, $0, $pop[[NUM0]]{{$}}
25; CHECK-NEXT: return $pop[[NUM1]]{{$}}
26define zeroext i8 @s2z_func(i8 signext %t) {
27  ret i8 %t
28}
29
30; CHECK-LABEL: z2s_call:
31; CHECK-NEXT: .param i32{{$}}
32; CHECK-NEXT: .result i32{{$}}
33; CHECK-NEXT: i32.const $push[[NUM0:[0-9]+]]=, 255{{$}}
34; CHECK-NEXT: i32.and $push[[NUM1:[0-9]+]]=, $0, $pop[[NUM0]]{{$}}
35; CHECK-NEXT: call $push[[NUM2:[0-9]+]]=, z2s_func@FUNCTION, $pop[[NUM1]]{{$}}
36; CHECK-NEXT: return $pop[[NUM2]]{{$}}
37define i32 @z2s_call(i32 %t) {
38  %s = trunc i32 %t to i8
39  %u = call signext i8 @z2s_func(i8 zeroext %s)
40  %v = sext i8 %u to i32
41  ret i32 %v
42}
43
44; CHECK-LABEL: s2z_call:
45; CHECK-NEXT: .param i32{{$}}
46; CHECK-NEXT: .result i32{{$}}
47; CHECK-NEXT: i32.const $push[[NUM0:[0-9]+]]=, 24{{$}}
48; CHECK-NEXT: i32.shl $push[[NUM1:[0-9]+]]=, $0, $pop[[NUM0]]{{$}}
49; CHECK-NEXT: i32.const $push[[NUM6:[0-9]+]]=, 24{{$}}
50; CHECK-NEXT: i32.shr_s $push[[NUM2:[0-9]+]]=, $pop[[NUM1]], $pop[[NUM6]]{{$}}
51; CHECK-NEXT: call $push[[NUM3:[0-9]]]=, s2z_func@FUNCTION, $pop[[NUM2]]{{$}}
52; CHECK-NEXT: i32.const $push[[NUM7:[0-9]+]]=, 24{{$}}
53; CHECK-NEXT: i32.shl $push[[NUM4:[0-9]+]]=, $pop[[NUM3]], $pop[[NUM7]]{{$}}
54; CHECK-NEXT: i32.const $push[[NUM8:[0-9]+]]=, 24{{$}}
55; CHECK-NEXT: i32.shr_s $push[[NUM5:[0-9]+]]=, $pop[[NUM4]], $pop[[NUM8]]{{$}}
56; CHECK-NEXT: return $pop[[NUM5]]{{$}}
57define i32 @s2z_call(i32 %t) {
58  %s = trunc i32 %t to i8
59  %u = call zeroext i8 @s2z_func(i8 signext %s)
60  %v = sext i8 %u to i32
61  ret i32 %v
62}
63