blob: 8321664a281fbfa37947d51183e35a1c46f45b87 [file] [log] [blame]
Wouter van Oortmerssena7be3752018-08-13 23:12:49 +00001; 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
Derek Schuff4dd67782016-01-27 21:17:39 +00003
4target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
Sam Clegga5908002018-05-10 17:49:11 +00005target triple = "wasm32-unknown-unknown"
Derek Schuff4dd67782016-01-27 21:17:39 +00006
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)
Nicholas Wilsone408a892018-08-03 14:33:37 +000027 ; CHECK-NEXT: get_global $push[[L2:.+]]=, __stack_pointer@GLOBAL
Derek Schuffdc5f6aa2016-02-20 21:46:50 +000028 ; CHECK-NEXT: i32.const $push[[L3:.+]]=, 16
Dan Gohmanc9623db2016-08-18 17:51:27 +000029 ; CHECK-NEXT: i32.sub $push[[L11:.+]]=, $pop[[L2]], $pop[[L3]]
Derek Schuff4dd67782016-01-27 21:17:39 +000030 ; Ensure SP is stored back before the call
Dan Gohmanc9623db2016-08-18 17:51:27 +000031 ; CHECK-NEXT: tee_local $push[[L10:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
Nicholas Wilsone408a892018-08-03 14:33:37 +000032 ; CHECK-NEXT: set_global __stack_pointer@GLOBAL, $pop[[L10]]{{$}}
Derek Schuff4dd67782016-01-27 21:17:39 +000033 ; Copy the SmallStruct argument to the stack (SP+12, original SP-4)
Dan Gohman0cfb5f82016-05-10 04:24:02 +000034 ; CHECK-NEXT: i32.load $push[[L0:.+]]=, 0($0)
Dan Gohman7f1bdb22016-10-06 22:08:28 +000035 ; CHECK-NEXT: i32.store 12($[[SP]]), $pop[[L0]]
Derek Schuff4dd67782016-01-27 21:17:39 +000036 ; Pass a pointer to the stack slot to the function
Dan Gohman0cfb5f82016-05-10 04:24:02 +000037 ; 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]]{{$}}
Derek Schuff4dd67782016-01-27 21:17:39 +000040 call void @ext_byval_func(%SmallStruct* byval %ptr)
41 ; Restore the stack
Derek Schuffd4207ba2016-03-17 17:00:29 +000042 ; CHECK-NEXT: i32.const $push[[L6:.+]]=, 16
Dan Gohman0cfb5f82016-05-10 04:24:02 +000043 ; CHECK-NEXT: i32.add $push[[L8:.+]]=, $[[SP]], $pop[[L6]]
Nicholas Wilsone408a892018-08-03 14:33:37 +000044 ; CHECK-NEXT: set_global __stack_pointer@GLOBAL, $pop[[L8]]
Derek Schuff4dd67782016-01-27 21:17:39 +000045 ; CHECK-NEXT: return
46 ret void
47}
48
49; CHECK-LABEL: byval_arg_align8
50define void @byval_arg_align8(%SmallStruct* %ptr) {
51 ; CHECK: .param i32
52 ; Don't check the entire SP sequence, just enough to get the alignment.
Derek Schuffdc5f6aa2016-02-20 21:46:50 +000053 ; CHECK: i32.const $push[[L1:.+]]=, 16
Dan Gohmanc9623db2016-08-18 17:51:27 +000054 ; CHECK-NEXT: i32.sub $push[[L11:.+]]=, {{.+}}, $pop[[L1]]
55 ; CHECK-NEXT: tee_local $push[[L10:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
Nicholas Wilsone408a892018-08-03 14:33:37 +000056 ; CHECK-NEXT: set_global __stack_pointer@GLOBAL, $pop[[L10]]{{$}}
Derek Schuff4dd67782016-01-27 21:17:39 +000057 ; Copy the SmallStruct argument to the stack (SP+8, original SP-8)
Dan Gohman0cfb5f82016-05-10 04:24:02 +000058 ; CHECK-NEXT: i32.load $push[[L0:.+]]=, 0($0){{$}}
Dan Gohman7f1bdb22016-10-06 22:08:28 +000059 ; CHECK-NEXT: i32.store 8($[[SP]]), $pop[[L0]]{{$}}
Derek Schuff4dd67782016-01-27 21:17:39 +000060 ; Pass a pointer to the stack slot to the function
Dan Gohman0cfb5f82016-05-10 04:24:02 +000061 ; 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]]{{$}}
Derek Schuff4dd67782016-01-27 21:17:39 +000064 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)
Derek Schuffdc5f6aa2016-02-20 21:46:50 +000072 ; CHECK: i32.const $push[[L1:.+]]=, 16
Dan Gohmanc9623db2016-08-18 17:51:27 +000073 ; CHECK-NEXT: i32.sub $push[[L14:.+]]=, {{.+}}, $pop[[L1]]
74 ; CHECK-NEXT: tee_local $push[[L13:.+]]=, $[[SP:.+]]=, $pop[[L14]]
Nicholas Wilsone408a892018-08-03 14:33:37 +000075 ; CHECK-NEXT: set_global __stack_pointer@GLOBAL, $pop[[L13]]
Derek Schuff4dd67782016-01-27 21:17:39 +000076 ; 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)
Dan Gohman7f1bdb22016-10-06 22:08:28 +000079 ; CHECK-NEXT: i64.store 0($[[SP]]), $pop[[L4]]
Derek Schuff4dd67782016-01-27 21:17:39 +000080 ; Pass a pointer to the stack slot to the function
Dan Gohman0cfb5f82016-05-10 04:24:02 +000081 ; CHECK-NEXT: call ext_byval_func_alignedstruct@FUNCTION, $[[SP]]
Derek Schuff4dd67782016-01-27 21:17:39 +000082 tail call void @ext_byval_func_alignedstruct(%AlignedStruct* byval %ptr)
83 ret void
84}
85
Derek Schuff4dd67782016-01-27 21:17:39 +000086; CHECK-LABEL: byval_param
87define 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}
Dan Gohmana6771b32016-02-12 21:30:18 +000094
95; CHECK-LABEL: byval_empty_caller
96define 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
104define 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}
Dan Gohman476ffce2016-02-17 01:43:37 +0000110
111; Call memcpy for "big" byvals.
Dan Gohman476ffce2016-02-17 01:43:37 +0000112; CHECK-LABEL: big_byval:
Nicholas Wilsone408a892018-08-03 14:33:37 +0000113; CHECK: get_global $push[[L2:.+]]=, __stack_pointer@GLOBAL{{$}}
Derek Schuffdc5f6aa2016-02-20 21:46:50 +0000114; CHECK-NEXT: i32.const $push[[L3:.+]]=, 131072
Dan Gohmanc9623db2016-08-18 17:51:27 +0000115; CHECK-NEXT: i32.sub $push[[L11:.+]]=, $pop[[L2]], $pop[[L3]]
116; CHECK-NEXT: tee_local $push[[L10:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
Nicholas Wilsone408a892018-08-03 14:33:37 +0000117; CHECK-NEXT: set_global __stack_pointer@GLOBAL, $pop[[L10]]{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000118; CHECK-NEXT: i32.const $push[[L0:.+]]=, 131072
Dan Gohmanc9623db2016-08-18 17:51:27 +0000119; CHECK-NEXT: i32.call $push[[L11:.+]]=, memcpy@FUNCTION, $[[SP]], ${{.+}}, $pop{{.+}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000120; CHECK-NEXT: tee_local $push[[L9:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
Dan Gohman476ffce2016-02-17 01:43:37 +0000121; CHECK-NEXT: call big_byval_callee@FUNCTION,
122%big = type [131072 x i8]
123declare void @big_byval_callee(%big* byval align 1)
124define void @big_byval(%big* byval align 1 %x) {
125 call void @big_byval_callee(%big* byval align 1 %x)
126 ret void
127}