blob: c7a21abbcf5d3b91e447f782c4469a594d0e6102 [file] [log] [blame]
Derek Schuff4dd67782016-01-27 21:17:39 +00001; RUN: llc < %s -asm-verbose=false -verify-machineinstrs | FileCheck %s
2; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -fast-isel | FileCheck %s
3
4target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
5target triple = "wasm32-unknown-unknown"
6
7%SmallStruct = type { i32 }
8%OddStruct = type { i32, i8, i32 }
9%AlignedStruct = type { double, double }
10%BigStruct = type { double, double, double, double, double, double, double, double, double, double, double, i8, i8, i8 }
Dan Gohmana6771b32016-02-12 21:30:18 +000011%EmptyStruct = type { }
Derek Schuff4dd67782016-01-27 21:17:39 +000012
13%BigArray = type { [33 x i8] }
14
15declare void @ext_func(%SmallStruct*)
Dan Gohmana6771b32016-02-12 21:30:18 +000016declare void @ext_func_empty(%EmptyStruct* byval)
Derek Schuff4dd67782016-01-27 21:17:39 +000017declare void @ext_byval_func(%SmallStruct* byval)
18declare void @ext_byval_func_align8(%SmallStruct* byval align 8)
19declare void @ext_byval_func_alignedstruct(%AlignedStruct* byval)
20declare void @ext_byval_func_bigarray(%BigArray* byval)
Dan Gohmana6771b32016-02-12 21:30:18 +000021declare void @ext_byval_func_empty(%EmptyStruct* byval)
Derek Schuff4dd67782016-01-27 21:17:39 +000022
23; CHECK-LABEL: byval_arg
24define void @byval_arg(%SmallStruct* %ptr) {
25 ; CHECK: .param i32
Dan Gohman0cfb5f82016-05-10 04:24:02 +000026 ; CHECK: i32.const $push[[L4:.+]]=, __stack_pointer
Derek Schuff4dd67782016-01-27 21:17:39 +000027 ; Subtract 16 from SP (SP is 16-byte aligned)
Derek Schuffdc5f6aa2016-02-20 21:46:50 +000028 ; CHECK: i32.const $push[[L1:.+]]=, __stack_pointer
29 ; CHECK-NEXT: i32.load $push[[L2:.+]]=, 0($pop[[L1]])
30 ; CHECK-NEXT: i32.const $push[[L3:.+]]=, 16
Dan Gohman0cfb5f82016-05-10 04:24:02 +000031 ; CHECK-NEXT: i32.sub $push[[L10:.+]]=, $pop[[L2]], $pop[[L3]]
Derek Schuff4dd67782016-01-27 21:17:39 +000032 ; Ensure SP is stored back before the call
Dan Gohman0cfb5f82016-05-10 04:24:02 +000033 ; CHECK-NEXT: i32.store $push[[L12:.+]]=, 0($pop[[L4]]), $pop[[L10]]{{$}}
34 ; CHECK-NEXT: tee_local $push[[L11:.+]]=, $[[SP:.+]]=, $pop[[L12]]{{$}}
Derek Schuff4dd67782016-01-27 21:17:39 +000035 ; Copy the SmallStruct argument to the stack (SP+12, original SP-4)
Dan Gohman0cfb5f82016-05-10 04:24:02 +000036 ; CHECK-NEXT: i32.load $push[[L0:.+]]=, 0($0)
37 ; CHECK-NEXT: i32.store $discard=, 12($pop[[L11]]), $pop[[L0]]
Derek Schuff4dd67782016-01-27 21:17:39 +000038 ; Pass a pointer to the stack slot to the function
Dan Gohman0cfb5f82016-05-10 04:24:02 +000039 ; CHECK-NEXT: i32.const $push[[L5:.+]]=, 12{{$}}
40 ; CHECK-NEXT: i32.add $push[[ARG:.+]]=, $[[SP]], $pop[[L5]]{{$}}
41 ; CHECK-NEXT: call ext_byval_func@FUNCTION, $pop[[ARG]]{{$}}
Derek Schuff4dd67782016-01-27 21:17:39 +000042 call void @ext_byval_func(%SmallStruct* byval %ptr)
43 ; Restore the stack
Derek Schuffdc5f6aa2016-02-20 21:46:50 +000044 ; CHECK-NEXT: i32.const $push[[L7:.+]]=, __stack_pointer
Derek Schuffd4207ba2016-03-17 17:00:29 +000045 ; CHECK-NEXT: i32.const $push[[L6:.+]]=, 16
Dan Gohman0cfb5f82016-05-10 04:24:02 +000046 ; CHECK-NEXT: i32.add $push[[L8:.+]]=, $[[SP]], $pop[[L6]]
Derek Schuffd4207ba2016-03-17 17:00:29 +000047 ; CHECK-NEXT: i32.store {{.*}}=, 0($pop[[L7]]), $pop[[L8]]
Derek Schuff4dd67782016-01-27 21:17:39 +000048 ; CHECK-NEXT: return
49 ret void
50}
51
52; CHECK-LABEL: byval_arg_align8
53define void @byval_arg_align8(%SmallStruct* %ptr) {
54 ; CHECK: .param i32
55 ; Don't check the entire SP sequence, just enough to get the alignment.
Derek Schuffdc5f6aa2016-02-20 21:46:50 +000056 ; CHECK: i32.const $push[[L1:.+]]=, 16
Dan Gohman0cfb5f82016-05-10 04:24:02 +000057 ; CHECK-NEXT: i32.sub $push[[L10:.+]]=, {{.+}}, $pop[[L1]]
58 ; CHECK-NEXT: i32.store $push[[L12:.+]]=, 0($pop{{.+}}), $pop[[L10]]{{$}}
59 ; CHECK-NEXT: tee_local $push[[L11:.+]]=, $[[SP:.+]]=, $pop[[L12]]{{$}}
Derek Schuff4dd67782016-01-27 21:17:39 +000060 ; Copy the SmallStruct argument to the stack (SP+8, original SP-8)
Dan Gohman0cfb5f82016-05-10 04:24:02 +000061 ; CHECK-NEXT: i32.load $push[[L0:.+]]=, 0($0){{$}}
62 ; CHECK-NEXT: i32.store $discard=, 8($pop[[L11]]), $pop[[L0]]{{$}}
Derek Schuff4dd67782016-01-27 21:17:39 +000063 ; Pass a pointer to the stack slot to the function
Dan Gohman0cfb5f82016-05-10 04:24:02 +000064 ; CHECK-NEXT: i32.const $push[[L5:.+]]=, 8{{$}}
65 ; CHECK-NEXT: i32.add $push[[ARG:.+]]=, $[[SP]], $pop[[L5]]{{$}}
66 ; CHECK-NEXT: call ext_byval_func_align8@FUNCTION, $pop[[ARG]]{{$}}
Derek Schuff4dd67782016-01-27 21:17:39 +000067 call void @ext_byval_func_align8(%SmallStruct* byval align 8 %ptr)
68 ret void
69}
70
71; CHECK-LABEL: byval_arg_double
72define void @byval_arg_double(%AlignedStruct* %ptr) {
73 ; CHECK: .param i32
74 ; Subtract 16 from SP (SP is 16-byte aligned)
Derek Schuffdc5f6aa2016-02-20 21:46:50 +000075 ; CHECK: i32.const $push[[L1:.+]]=, 16
Dan Gohman0cfb5f82016-05-10 04:24:02 +000076 ; CHECK-NEXT: i32.sub $push[[L12:.+]]=, {{.+}}, $pop[[L1]]
77 ; CHECK-NEXT: i32.store $push[[L15:.+]]=, {{.+}}, $pop[[L12]]
78 ; CHECK-NEXT: tee_local $push[[L14:.+]]=, $[[SP:.+]]=, $pop[[L15]]
Derek Schuff4dd67782016-01-27 21:17:39 +000079 ; Copy the AlignedStruct argument to the stack (SP+0, original SP-16)
80 ; Just check the last load/store pair of the memcpy
81 ; CHECK: i64.load $push[[L4:.+]]=, 0($0)
Dan Gohman0cfb5f82016-05-10 04:24:02 +000082 ; CHECK-NEXT: i64.store $discard=, 0($[[SP]]), $pop[[L4]]
Derek Schuff4dd67782016-01-27 21:17:39 +000083 ; Pass a pointer to the stack slot to the function
Dan Gohman0cfb5f82016-05-10 04:24:02 +000084 ; CHECK-NEXT: call ext_byval_func_alignedstruct@FUNCTION, $[[SP]]
Derek Schuff4dd67782016-01-27 21:17:39 +000085 tail call void @ext_byval_func_alignedstruct(%AlignedStruct* byval %ptr)
86 ret void
87}
88
Derek Schuff4dd67782016-01-27 21:17:39 +000089; CHECK-LABEL: byval_param
90define void @byval_param(%SmallStruct* byval align 32 %ptr) {
91 ; CHECK: .param i32
92 ; %ptr is just a pointer to a struct, so pass it directly through
93 ; CHECK: call ext_func@FUNCTION, $0
94 call void @ext_func(%SmallStruct* %ptr)
95 ret void
96}
Dan Gohmana6771b32016-02-12 21:30:18 +000097
98; CHECK-LABEL: byval_empty_caller
99define void @byval_empty_caller(%EmptyStruct* %ptr) {
100 ; CHECK: .param i32
101 ; CHECK: call ext_byval_func_empty@FUNCTION, $0
102 call void @ext_byval_func_empty(%EmptyStruct* byval %ptr)
103 ret void
104}
105
106; CHECK-LABEL: byval_empty_callee
107define void @byval_empty_callee(%EmptyStruct* byval %ptr) {
108 ; CHECK: .param i32
109 ; CHECK: call ext_func_empty@FUNCTION, $0
110 call void @ext_func_empty(%EmptyStruct* %ptr)
111 ret void
112}
Dan Gohman476ffce2016-02-17 01:43:37 +0000113
114; Call memcpy for "big" byvals.
Dan Gohman476ffce2016-02-17 01:43:37 +0000115; CHECK-LABEL: big_byval:
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000116; CHECK: i32.const $push[[L4:.+]]=, __stack_pointer
Derek Schuffdc5f6aa2016-02-20 21:46:50 +0000117; CHECK: i32.const $push[[L1:.+]]=, __stack_pointer
118; CHECK-NEXT: i32.load $push[[L2:.+]]=, 0($pop[[L1]])
119; CHECK-NEXT: i32.const $push[[L3:.+]]=, 131072
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000120; CHECK-NEXT: i32.sub $push[[L8:.+]]=, $pop[[L2]], $pop[[L3]]
121; CHECK-NEXT: i32.store $push[[L12:.+]]=, 0($pop[[L4]]), $pop[[L8]]{{$}}
122; CHECK-NEXT: i32.const $push[[L0:.+]]=, 131072
123; CHECK-NEXT: i32.call $push[[L11:.+]]=, memcpy@FUNCTION, $pop{{.+}}, ${{.+}}, $pop{{.+}}
124; CHECK-NEXT: tee_local $push[[L9:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
Dan Gohman476ffce2016-02-17 01:43:37 +0000125; CHECK-NEXT: call big_byval_callee@FUNCTION,
126%big = type [131072 x i8]
127declare void @big_byval_callee(%big* byval align 1)
128define void @big_byval(%big* byval align 1 %x) {
129 call void @big_byval_callee(%big* byval align 1 %x)
130 ret void
131}