blob: 9a9ab6500c8a6634e5bcd1b3fea9703ad2658196 [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
26 ; Subtract 16 from SP (SP is 16-byte aligned)
27 ; CHECK: i32.const [[L1:.+]]=, __stack_pointer
28 ; CHECK-NEXT: i32.load [[L1]]=, 0([[L1]])
29 ; CHECK-NEXT: i32.const [[L2:.+]]=, 16
30 ; CHECK-NEXT: i32.sub [[SP:.+]]=, [[L1]], [[L2]]
31 ; Ensure SP is stored back before the call
32 ; CHECK-NEXT: i32.const [[L3:.+]]=, __stack_pointer
33 ; CHECK-NEXT: i32.store {{.*}}=, 0([[L3]]), [[SP]]
34 ; Copy the SmallStruct argument to the stack (SP+12, original SP-4)
35 ; CHECK-NEXT: i32.load $push[[L4:.+]]=, 0($0)
36 ; CHECK-NEXT: i32.store {{.*}}=, 12([[SP]]), $pop[[L4]]
37 ; Pass a pointer to the stack slot to the function
38 ; CHECK-NEXT: i32.const [[L5:.+]]=, 12
39 ; CHECK-NEXT: i32.add [[ARG:.+]]=, [[SP]], [[L5]]
40 ; CHECK-NEXT: call ext_byval_func@FUNCTION, [[L5]]
41 call void @ext_byval_func(%SmallStruct* byval %ptr)
42 ; Restore the stack
43 ; CHECK-NEXT: i32.const [[L6:.+]]=, 16
44 ; CHECK-NEXT: i32.add [[SP]]=, [[SP]], [[L6]]
45 ; CHECK-NEXT: i32.const [[L7:.+]]=, __stack_pointer
46 ; CHECK-NEXT: i32.store {{.*}}=, 0([[L7]]), [[SP]]
47 ; CHECK-NEXT: return
48 ret void
49}
50
51; CHECK-LABEL: byval_arg_align8
52define void @byval_arg_align8(%SmallStruct* %ptr) {
53 ; CHECK: .param i32
54 ; Don't check the entire SP sequence, just enough to get the alignment.
55 ; CHECK: i32.const [[L2:.+]]=, 16
56 ; CHECK-NEXT: i32.sub [[SP:.+]]=, {{.+}}, [[L2]]
57 ; Copy the SmallStruct argument to the stack (SP+8, original SP-8)
58 ; CHECK: i32.load $push[[L4:.+]]=, 0($0):p2align=3
59 ; CHECK-NEXT: i32.store {{.*}}=, 8([[SP]]):p2align=3, $pop[[L4]]
60 ; Pass a pointer to the stack slot to the function
61 ; CHECK-NEXT: i32.const [[L5:.+]]=, 8
62 ; CHECK-NEXT: i32.add [[ARG:.+]]=, [[SP]], [[L5]]
63 ; CHECK-NEXT: call ext_byval_func_align8@FUNCTION, [[L5]]
64 call void @ext_byval_func_align8(%SmallStruct* byval align 8 %ptr)
65 ret void
66}
67
68; CHECK-LABEL: byval_arg_double
69define void @byval_arg_double(%AlignedStruct* %ptr) {
70 ; CHECK: .param i32
71 ; Subtract 16 from SP (SP is 16-byte aligned)
72 ; CHECK: i32.const [[L2:.+]]=, 16
73 ; CHECK-NEXT: i32.sub [[SP:.+]]=, {{.+}}, [[L2]]
74 ; Copy the AlignedStruct argument to the stack (SP+0, original SP-16)
75 ; Just check the last load/store pair of the memcpy
76 ; CHECK: i64.load $push[[L4:.+]]=, 0($0)
77 ; CHECK-NEXT: i64.store {{.*}}=, 0([[SP]]), $pop[[L4]]
78 ; Pass a pointer to the stack slot to the function
79 ; CHECK-NEXT: call ext_byval_func_alignedstruct@FUNCTION, [[SP]]
80 tail call void @ext_byval_func_alignedstruct(%AlignedStruct* byval %ptr)
81 ret void
82}
83
84; CHECK-LABEL: byval_arg_big
85define void @byval_arg_big(%BigArray* %ptr) {
86 ; CHECK: .param i32
87 ; Subtract 48 from SP (SP is 16-byte aligned)
88 ; CHECK: i32.const [[L2:.+]]=, 48
89 ; CHECK-NEXT: i32.sub [[SP:.+]]=, {{.+}}, [[L2]]
90 ; Copy the AlignedStruct argument to the stack (SP+12, original SP-36)
91 ; CHECK: i64.load $push[[L4:.+]]=, 0($0):p2align=0
92 ; CHECK: i64.store {{.*}}=, 12([[SP]]):p2align=2, $pop[[L4]]
93 ; Pass a pointer to the stack slot to the function
94 ; CHECK-NEXT: i32.const [[L5:.+]]=, 12
95 ; CHECK-NEXT: i32.add [[ARG:.+]]=, [[SP]], [[L5]]
96 ; CHECK-NEXT: call ext_byval_func_bigarray@FUNCTION, [[ARG]]
97 call void @ext_byval_func_bigarray(%BigArray* byval %ptr)
98 ret void
99}
100
101; CHECK-LABEL: byval_param
102define void @byval_param(%SmallStruct* byval align 32 %ptr) {
103 ; CHECK: .param i32
104 ; %ptr is just a pointer to a struct, so pass it directly through
105 ; CHECK: call ext_func@FUNCTION, $0
106 call void @ext_func(%SmallStruct* %ptr)
107 ret void
108}
Dan Gohmana6771b32016-02-12 21:30:18 +0000109
110; CHECK-LABEL: byval_empty_caller
111define void @byval_empty_caller(%EmptyStruct* %ptr) {
112 ; CHECK: .param i32
113 ; CHECK: call ext_byval_func_empty@FUNCTION, $0
114 call void @ext_byval_func_empty(%EmptyStruct* byval %ptr)
115 ret void
116}
117
118; CHECK-LABEL: byval_empty_callee
119define void @byval_empty_callee(%EmptyStruct* byval %ptr) {
120 ; CHECK: .param i32
121 ; CHECK: call ext_func_empty@FUNCTION, $0
122 call void @ext_func_empty(%EmptyStruct* %ptr)
123 ret void
124}