1 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -verify-machineinstrs -mcpu=mvp | FileCheck %s
2 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -verify-machineinstrs -mcpu=mvp -fast-isel | FileCheck %s
4 target triple = "wasm32-unknown-unknown"
6 %SmallStruct = type { i32 }
7 %OddStruct = type { i32, i8, i32 }
8 %AlignedStruct = type { double, double }
9 %BigStruct = type { double, double, double, double, double, double, double, double, double, double, double, i8, i8, i8 }
10 %EmptyStruct = type { }
12 declare void @ext_func(ptr)
13 declare void @ext_func_empty(ptr byval(%EmptyStruct))
14 declare void @ext_byval_func(ptr byval(%SmallStruct))
15 declare void @ext_byval_func_align8(ptr byval(%SmallStruct) align 8)
16 declare void @ext_byval_func_alignedstruct(ptr byval(%AlignedStruct))
17 declare void @ext_byval_func_empty(ptr byval(%EmptyStruct))
19 ; CHECK-LABEL: byval_arg:
20 define void @byval_arg(ptr %ptr) {
21 ; CHECK: .functype byval_arg (i32) -> ()
22 ; Subtract 16 from SP (SP is 16-byte aligned)
23 ; CHECK-NEXT: global.get $push[[L2:.+]]=, __stack_pointer
24 ; CHECK-NEXT: i32.const $push[[L3:.+]]=, 16
25 ; CHECK-NEXT: i32.sub $push[[L11:.+]]=, $pop[[L2]], $pop[[L3]]
26 ; Ensure SP is stored back before the call
27 ; CHECK-NEXT: local.tee $push[[L10:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
28 ; CHECK-NEXT: global.set __stack_pointer, $pop[[L10]]{{$}}
29 ; Copy the SmallStruct argument to the stack (SP+12, original SP-4)
30 ; CHECK-NEXT: i32.load $push[[L0:.+]]=, 0($0)
31 ; CHECK-NEXT: i32.store 12($[[SP]]), $pop[[L0]]
32 ; Pass a pointer to the stack slot to the function
33 ; CHECK-NEXT: i32.const $push[[L5:.+]]=, 12{{$}}
34 ; CHECK-NEXT: i32.add $push[[ARG:.+]]=, $[[SP]], $pop[[L5]]{{$}}
35 ; CHECK-NEXT: call ext_byval_func, $pop[[ARG]]{{$}}
36 call void @ext_byval_func(ptr byval(%SmallStruct) %ptr)
38 ; CHECK-NEXT: i32.const $push[[L6:.+]]=, 16
39 ; CHECK-NEXT: i32.add $push[[L8:.+]]=, $[[SP]], $pop[[L6]]
40 ; CHECK-NEXT: global.set __stack_pointer, $pop[[L8]]
45 ; CHECK-LABEL: byval_arg_align8:
46 define void @byval_arg_align8(ptr %ptr) {
47 ; CHECK: .functype byval_arg_align8 (i32) -> ()
48 ; Don't check the entire SP sequence, just enough to get the alignment.
49 ; CHECK: i32.const $push[[L1:.+]]=, 16
50 ; CHECK-NEXT: i32.sub $push[[L11:.+]]=, {{.+}}, $pop[[L1]]
51 ; CHECK-NEXT: local.tee $push[[L10:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
52 ; CHECK-NEXT: global.set __stack_pointer, $pop[[L10]]{{$}}
53 ; Copy the SmallStruct argument to the stack (SP+8, original SP-8)
54 ; CHECK-NEXT: i32.load $push[[L0:.+]]=, 0($0){{$}}
55 ; CHECK-NEXT: i32.store 8($[[SP]]), $pop[[L0]]{{$}}
56 ; Pass a pointer to the stack slot to the function
57 ; CHECK-NEXT: i32.const $push[[L5:.+]]=, 8{{$}}
58 ; CHECK-NEXT: i32.add $push[[ARG:.+]]=, $[[SP]], $pop[[L5]]{{$}}
59 ; CHECK-NEXT: call ext_byval_func_align8, $pop[[ARG]]{{$}}
60 call void @ext_byval_func_align8(ptr byval(%SmallStruct) align 8 %ptr)
64 ; CHECK-LABEL: byval_arg_double:
65 define void @byval_arg_double(ptr %ptr) {
66 ; CHECK: .functype byval_arg_double (i32) -> ()
67 ; Subtract 16 from SP (SP is 16-byte aligned)
68 ; CHECK: i32.const $push[[L1:.+]]=, 16
69 ; CHECK-NEXT: i32.sub $push[[L14:.+]]=, {{.+}}, $pop[[L1]]
70 ; CHECK-NEXT: local.tee $push[[L13:.+]]=, $[[SP:.+]]=, $pop[[L14]]
71 ; CHECK-NEXT: global.set __stack_pointer, $pop[[L13]]
72 ; Copy the AlignedStruct argument to the stack (SP+0, original SP-16)
73 ; Just check the last load/store pair of the memcpy
74 ; CHECK: i64.load $push[[L4:.+]]=, 0($0)
75 ; CHECK-NEXT: i64.store 0($[[SP]]), $pop[[L4]]
76 ; Pass a pointer to the stack slot to the function
77 ; CHECK-NEXT: call ext_byval_func_alignedstruct, $[[SP]]
78 tail call void @ext_byval_func_alignedstruct(ptr byval(%AlignedStruct) %ptr)
82 ; CHECK-LABEL: byval_param:
83 define void @byval_param(ptr byval(%SmallStruct) align 32 %ptr) {
84 ; CHECK: .functype byval_param (i32) -> ()
85 ; %ptr is just a pointer to a struct, so pass it directly through
86 ; CHECK: call ext_func, $0
87 call void @ext_func(ptr %ptr)
91 ; CHECK-LABEL: byval_empty_caller:
92 define void @byval_empty_caller(ptr %ptr) {
93 ; CHECK: .functype byval_empty_caller (i32) -> ()
94 ; CHECK: call ext_byval_func_empty, $0
95 call void @ext_byval_func_empty(ptr byval(%EmptyStruct) %ptr)
99 ; CHECK-LABEL: byval_empty_callee:
100 define void @byval_empty_callee(ptr byval(%EmptyStruct) %ptr) {
101 ; CHECK: .functype byval_empty_callee (i32) -> ()
102 ; CHECK: call ext_func_empty, $0
103 call void @ext_func_empty(ptr %ptr)
107 ; Call memcpy for "big" byvals.
108 ; CHECK-LABEL: big_byval:
109 ; CHECK: global.get $push[[L2:.+]]=, __stack_pointer{{$}}
110 ; CHECK-NEXT: i32.const $push[[L3:.+]]=, 131072
111 ; CHECK-NEXT: i32.sub $push[[L11:.+]]=, $pop[[L2]], $pop[[L3]]
112 ; CHECK-NEXT: local.tee $push[[L10:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
113 ; CHECK-NEXT: global.set __stack_pointer, $pop[[L10]]{{$}}
114 ; CHECK-NEXT: i32.const $push[[L0:.+]]=, 131072
115 ; CHECK-NEXT: call $push[[L11:.+]]=, memcpy, $[[SP]], ${{.+}}, $pop{{.+}}
116 ; CHECK-NEXT: local.tee $push[[L9:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
117 ; CHECK-NEXT: call big_byval_callee,
118 %big = type [131072 x i8]
119 declare void @big_byval_callee(ptr byval(%big) align 1)
120 define void @big_byval(ptr byval(%big) align 1 %x) {
121 call void @big_byval_callee(ptr byval(%big) align 1 %x)