121
|
1 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -disable-wasm-explicit-locals -verify-machineinstrs | FileCheck %s
|
|
2 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -disable-wasm-explicit-locals -verify-machineinstrs -fast-isel | FileCheck %s
|
120
|
3
|
|
4 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
|
121
|
5 target triple = "wasm32-unknown-unknown-wasm"
|
120
|
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 }
|
|
11 %EmptyStruct = type { }
|
|
12
|
|
13 %BigArray = type { [33 x i8] }
|
|
14
|
|
15 declare void @ext_func(%SmallStruct*)
|
|
16 declare void @ext_func_empty(%EmptyStruct* byval)
|
|
17 declare void @ext_byval_func(%SmallStruct* byval)
|
|
18 declare void @ext_byval_func_align8(%SmallStruct* byval align 8)
|
|
19 declare void @ext_byval_func_alignedstruct(%AlignedStruct* byval)
|
|
20 declare void @ext_byval_func_bigarray(%BigArray* byval)
|
|
21 declare void @ext_byval_func_empty(%EmptyStruct* byval)
|
|
22
|
|
23 ; CHECK-LABEL: byval_arg
|
|
24 define void @byval_arg(%SmallStruct* %ptr) {
|
|
25 ; CHECK: .param i32
|
|
26 ; Subtract 16 from SP (SP is 16-byte aligned)
|
121
|
27 ; CHECK-NEXT: get_global $push[[L2:.+]]=, __stack_pointer
|
120
|
28 ; CHECK-NEXT: i32.const $push[[L3:.+]]=, 16
|
|
29 ; CHECK-NEXT: i32.sub $push[[L11:.+]]=, $pop[[L2]], $pop[[L3]]
|
|
30 ; Ensure SP is stored back before the call
|
|
31 ; CHECK-NEXT: tee_local $push[[L10:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
|
121
|
32 ; CHECK-NEXT: set_global __stack_pointer, $pop[[L10]]{{$}}
|
120
|
33 ; Copy the SmallStruct argument to the stack (SP+12, original SP-4)
|
|
34 ; CHECK-NEXT: i32.load $push[[L0:.+]]=, 0($0)
|
|
35 ; CHECK-NEXT: i32.store 12($[[SP]]), $pop[[L0]]
|
|
36 ; Pass a pointer to the stack slot to the function
|
|
37 ; CHECK-NEXT: i32.const $push[[L5:.+]]=, 12{{$}}
|
|
38 ; CHECK-NEXT: i32.add $push[[ARG:.+]]=, $[[SP]], $pop[[L5]]{{$}}
|
|
39 ; CHECK-NEXT: call ext_byval_func@FUNCTION, $pop[[ARG]]{{$}}
|
|
40 call void @ext_byval_func(%SmallStruct* byval %ptr)
|
|
41 ; Restore the stack
|
|
42 ; CHECK-NEXT: i32.const $push[[L6:.+]]=, 16
|
|
43 ; CHECK-NEXT: i32.add $push[[L8:.+]]=, $[[SP]], $pop[[L6]]
|
121
|
44 ; CHECK-NEXT: set_global __stack_pointer, $pop[[L8]]
|
120
|
45 ; CHECK-NEXT: return
|
|
46 ret void
|
|
47 }
|
|
48
|
|
49 ; CHECK-LABEL: byval_arg_align8
|
|
50 define void @byval_arg_align8(%SmallStruct* %ptr) {
|
|
51 ; CHECK: .param i32
|
|
52 ; Don't check the entire SP sequence, just enough to get the alignment.
|
|
53 ; CHECK: i32.const $push[[L1:.+]]=, 16
|
|
54 ; CHECK-NEXT: i32.sub $push[[L11:.+]]=, {{.+}}, $pop[[L1]]
|
|
55 ; CHECK-NEXT: tee_local $push[[L10:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
|
121
|
56 ; CHECK-NEXT: set_global __stack_pointer, $pop[[L10]]{{$}}
|
120
|
57 ; Copy the SmallStruct argument to the stack (SP+8, original SP-8)
|
|
58 ; CHECK-NEXT: i32.load $push[[L0:.+]]=, 0($0){{$}}
|
|
59 ; CHECK-NEXT: i32.store 8($[[SP]]), $pop[[L0]]{{$}}
|
|
60 ; Pass a pointer to the stack slot to the function
|
|
61 ; CHECK-NEXT: i32.const $push[[L5:.+]]=, 8{{$}}
|
|
62 ; CHECK-NEXT: i32.add $push[[ARG:.+]]=, $[[SP]], $pop[[L5]]{{$}}
|
|
63 ; CHECK-NEXT: call ext_byval_func_align8@FUNCTION, $pop[[ARG]]{{$}}
|
|
64 call void @ext_byval_func_align8(%SmallStruct* byval align 8 %ptr)
|
|
65 ret void
|
|
66 }
|
|
67
|
|
68 ; CHECK-LABEL: byval_arg_double
|
|
69 define void @byval_arg_double(%AlignedStruct* %ptr) {
|
|
70 ; CHECK: .param i32
|
|
71 ; Subtract 16 from SP (SP is 16-byte aligned)
|
|
72 ; CHECK: i32.const $push[[L1:.+]]=, 16
|
|
73 ; CHECK-NEXT: i32.sub $push[[L14:.+]]=, {{.+}}, $pop[[L1]]
|
|
74 ; CHECK-NEXT: tee_local $push[[L13:.+]]=, $[[SP:.+]]=, $pop[[L14]]
|
121
|
75 ; CHECK-NEXT: set_global __stack_pointer, $pop[[L13]]
|
120
|
76 ; Copy the AlignedStruct argument to the stack (SP+0, original SP-16)
|
|
77 ; Just check the last load/store pair of the memcpy
|
|
78 ; CHECK: i64.load $push[[L4:.+]]=, 0($0)
|
|
79 ; CHECK-NEXT: i64.store 0($[[SP]]), $pop[[L4]]
|
|
80 ; Pass a pointer to the stack slot to the function
|
|
81 ; CHECK-NEXT: call ext_byval_func_alignedstruct@FUNCTION, $[[SP]]
|
|
82 tail call void @ext_byval_func_alignedstruct(%AlignedStruct* byval %ptr)
|
|
83 ret void
|
|
84 }
|
|
85
|
|
86 ; CHECK-LABEL: byval_param
|
|
87 define void @byval_param(%SmallStruct* byval align 32 %ptr) {
|
|
88 ; CHECK: .param i32
|
|
89 ; %ptr is just a pointer to a struct, so pass it directly through
|
|
90 ; CHECK: call ext_func@FUNCTION, $0
|
|
91 call void @ext_func(%SmallStruct* %ptr)
|
|
92 ret void
|
|
93 }
|
|
94
|
|
95 ; CHECK-LABEL: byval_empty_caller
|
|
96 define void @byval_empty_caller(%EmptyStruct* %ptr) {
|
|
97 ; CHECK: .param i32
|
|
98 ; CHECK: call ext_byval_func_empty@FUNCTION, $0
|
|
99 call void @ext_byval_func_empty(%EmptyStruct* byval %ptr)
|
|
100 ret void
|
|
101 }
|
|
102
|
|
103 ; CHECK-LABEL: byval_empty_callee
|
|
104 define void @byval_empty_callee(%EmptyStruct* byval %ptr) {
|
|
105 ; CHECK: .param i32
|
|
106 ; CHECK: call ext_func_empty@FUNCTION, $0
|
|
107 call void @ext_func_empty(%EmptyStruct* %ptr)
|
|
108 ret void
|
|
109 }
|
|
110
|
|
111 ; Call memcpy for "big" byvals.
|
|
112 ; CHECK-LABEL: big_byval:
|
121
|
113 ; CHECK: get_global $push[[L2:.+]]=, __stack_pointer{{$}}
|
120
|
114 ; CHECK-NEXT: i32.const $push[[L3:.+]]=, 131072
|
|
115 ; CHECK-NEXT: i32.sub $push[[L11:.+]]=, $pop[[L2]], $pop[[L3]]
|
|
116 ; CHECK-NEXT: tee_local $push[[L10:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
|
121
|
117 ; CHECK-NEXT: set_global __stack_pointer, $pop[[L10]]{{$}}
|
120
|
118 ; CHECK-NEXT: i32.const $push[[L0:.+]]=, 131072
|
|
119 ; CHECK-NEXT: i32.call $push[[L11:.+]]=, memcpy@FUNCTION, $[[SP]], ${{.+}}, $pop{{.+}}
|
|
120 ; CHECK-NEXT: tee_local $push[[L9:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
|
|
121 ; CHECK-NEXT: call big_byval_callee@FUNCTION,
|
|
122 %big = type [131072 x i8]
|
|
123 declare void @big_byval_callee(%big* byval align 1)
|
|
124 define void @big_byval(%big* byval align 1 %x) {
|
|
125 call void @big_byval_callee(%big* byval align 1 %x)
|
|
126 ret void
|
|
127 }
|