blob: 083d3bd7f29cc43d3aef051bcde93dff3d3e9dfa [file] [log] [blame]
Wouter van Oortmerssen8a9cb242018-08-27 15:45:51 +00001; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -verify-machineinstrs | FileCheck %s
2; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -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
Derek Schuff4dd67782016-01-27 21:17:39 +000013declare void @ext_func(%SmallStruct*)
Dan Gohmana6771b32016-02-12 21:30:18 +000014declare void @ext_func_empty(%EmptyStruct* byval)
Derek Schuff4dd67782016-01-27 21:17:39 +000015declare void @ext_byval_func(%SmallStruct* byval)
16declare void @ext_byval_func_align8(%SmallStruct* byval align 8)
17declare void @ext_byval_func_alignedstruct(%AlignedStruct* byval)
Dan Gohmana6771b32016-02-12 21:30:18 +000018declare void @ext_byval_func_empty(%EmptyStruct* byval)
Derek Schuff4dd67782016-01-27 21:17:39 +000019
20; CHECK-LABEL: byval_arg
21define void @byval_arg(%SmallStruct* %ptr) {
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000022 ; CHECK: .functype byval_arg (i32) -> ()
Derek Schuff4dd67782016-01-27 21:17:39 +000023 ; Subtract 16 from SP (SP is 16-byte aligned)
Sam Clegg275d15e2019-02-23 00:07:39 +000024 ; CHECK-NEXT: global.get $push[[L2:.+]]=, __stack_pointer
Derek Schuffdc5f6aa2016-02-20 21:46:50 +000025 ; CHECK-NEXT: i32.const $push[[L3:.+]]=, 16
Dan Gohmanc9623db2016-08-18 17:51:27 +000026 ; CHECK-NEXT: i32.sub $push[[L11:.+]]=, $pop[[L2]], $pop[[L3]]
Derek Schuff4dd67782016-01-27 21:17:39 +000027 ; Ensure SP is stored back before the call
Thomas Lively6a87dda2019-01-08 06:25:55 +000028 ; CHECK-NEXT: local.tee $push[[L10:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
Sam Clegg275d15e2019-02-23 00:07:39 +000029 ; CHECK-NEXT: global.set __stack_pointer, $pop[[L10]]{{$}}
Derek Schuff4dd67782016-01-27 21:17:39 +000030 ; Copy the SmallStruct argument to the stack (SP+12, original SP-4)
Dan Gohman0cfb5f82016-05-10 04:24:02 +000031 ; CHECK-NEXT: i32.load $push[[L0:.+]]=, 0($0)
Dan Gohman7f1bdb22016-10-06 22:08:28 +000032 ; CHECK-NEXT: i32.store 12($[[SP]]), $pop[[L0]]
Derek Schuff4dd67782016-01-27 21:17:39 +000033 ; Pass a pointer to the stack slot to the function
Dan Gohman0cfb5f82016-05-10 04:24:02 +000034 ; CHECK-NEXT: i32.const $push[[L5:.+]]=, 12{{$}}
35 ; CHECK-NEXT: i32.add $push[[ARG:.+]]=, $[[SP]], $pop[[L5]]{{$}}
Sam Clegg275d15e2019-02-23 00:07:39 +000036 ; CHECK-NEXT: call ext_byval_func, $pop[[ARG]]{{$}}
Derek Schuff4dd67782016-01-27 21:17:39 +000037 call void @ext_byval_func(%SmallStruct* byval %ptr)
38 ; Restore the stack
Derek Schuffd4207ba2016-03-17 17:00:29 +000039 ; CHECK-NEXT: i32.const $push[[L6:.+]]=, 16
Dan Gohman0cfb5f82016-05-10 04:24:02 +000040 ; CHECK-NEXT: i32.add $push[[L8:.+]]=, $[[SP]], $pop[[L6]]
Sam Clegg275d15e2019-02-23 00:07:39 +000041 ; CHECK-NEXT: global.set __stack_pointer, $pop[[L8]]
Derek Schuff4dd67782016-01-27 21:17:39 +000042 ; CHECK-NEXT: return
43 ret void
44}
45
46; CHECK-LABEL: byval_arg_align8
47define void @byval_arg_align8(%SmallStruct* %ptr) {
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000048 ; CHECK: .functype byval_arg_align8 (i32) -> ()
Derek Schuff4dd67782016-01-27 21:17:39 +000049 ; Don't check the entire SP sequence, just enough to get the alignment.
Derek Schuffdc5f6aa2016-02-20 21:46:50 +000050 ; CHECK: i32.const $push[[L1:.+]]=, 16
Dan Gohmanc9623db2016-08-18 17:51:27 +000051 ; CHECK-NEXT: i32.sub $push[[L11:.+]]=, {{.+}}, $pop[[L1]]
Thomas Lively6a87dda2019-01-08 06:25:55 +000052 ; CHECK-NEXT: local.tee $push[[L10:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
Sam Clegg275d15e2019-02-23 00:07:39 +000053 ; CHECK-NEXT: global.set __stack_pointer, $pop[[L10]]{{$}}
Derek Schuff4dd67782016-01-27 21:17:39 +000054 ; Copy the SmallStruct argument to the stack (SP+8, original SP-8)
Dan Gohman0cfb5f82016-05-10 04:24:02 +000055 ; CHECK-NEXT: i32.load $push[[L0:.+]]=, 0($0){{$}}
Dan Gohman7f1bdb22016-10-06 22:08:28 +000056 ; CHECK-NEXT: i32.store 8($[[SP]]), $pop[[L0]]{{$}}
Derek Schuff4dd67782016-01-27 21:17:39 +000057 ; Pass a pointer to the stack slot to the function
Dan Gohman0cfb5f82016-05-10 04:24:02 +000058 ; CHECK-NEXT: i32.const $push[[L5:.+]]=, 8{{$}}
59 ; CHECK-NEXT: i32.add $push[[ARG:.+]]=, $[[SP]], $pop[[L5]]{{$}}
Sam Clegg275d15e2019-02-23 00:07:39 +000060 ; CHECK-NEXT: call ext_byval_func_align8, $pop[[ARG]]{{$}}
Derek Schuff4dd67782016-01-27 21:17:39 +000061 call void @ext_byval_func_align8(%SmallStruct* byval align 8 %ptr)
62 ret void
63}
64
65; CHECK-LABEL: byval_arg_double
66define void @byval_arg_double(%AlignedStruct* %ptr) {
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000067 ; CHECK: .functype byval_arg_double (i32) -> ()
Derek Schuff4dd67782016-01-27 21:17:39 +000068 ; Subtract 16 from SP (SP is 16-byte aligned)
Derek Schuffdc5f6aa2016-02-20 21:46:50 +000069 ; CHECK: i32.const $push[[L1:.+]]=, 16
Dan Gohmanc9623db2016-08-18 17:51:27 +000070 ; CHECK-NEXT: i32.sub $push[[L14:.+]]=, {{.+}}, $pop[[L1]]
Thomas Lively6a87dda2019-01-08 06:25:55 +000071 ; CHECK-NEXT: local.tee $push[[L13:.+]]=, $[[SP:.+]]=, $pop[[L14]]
Sam Clegg275d15e2019-02-23 00:07:39 +000072 ; CHECK-NEXT: global.set __stack_pointer, $pop[[L13]]
Derek Schuff4dd67782016-01-27 21:17:39 +000073 ; Copy the AlignedStruct argument to the stack (SP+0, original SP-16)
74 ; Just check the last load/store pair of the memcpy
75 ; CHECK: i64.load $push[[L4:.+]]=, 0($0)
Dan Gohman7f1bdb22016-10-06 22:08:28 +000076 ; CHECK-NEXT: i64.store 0($[[SP]]), $pop[[L4]]
Derek Schuff4dd67782016-01-27 21:17:39 +000077 ; Pass a pointer to the stack slot to the function
Sam Clegg275d15e2019-02-23 00:07:39 +000078 ; CHECK-NEXT: call ext_byval_func_alignedstruct, $[[SP]]
Derek Schuff4dd67782016-01-27 21:17:39 +000079 tail call void @ext_byval_func_alignedstruct(%AlignedStruct* byval %ptr)
80 ret void
81}
82
Derek Schuff4dd67782016-01-27 21:17:39 +000083; CHECK-LABEL: byval_param
84define void @byval_param(%SmallStruct* byval align 32 %ptr) {
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000085 ; CHECK: .functype byval_param (i32) -> ()
Derek Schuff4dd67782016-01-27 21:17:39 +000086 ; %ptr is just a pointer to a struct, so pass it directly through
Sam Clegg275d15e2019-02-23 00:07:39 +000087 ; CHECK: call ext_func, $0
Derek Schuff4dd67782016-01-27 21:17:39 +000088 call void @ext_func(%SmallStruct* %ptr)
89 ret void
90}
Dan Gohmana6771b32016-02-12 21:30:18 +000091
92; CHECK-LABEL: byval_empty_caller
93define void @byval_empty_caller(%EmptyStruct* %ptr) {
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000094 ; CHECK: .functype byval_empty_caller (i32) -> ()
Sam Clegg275d15e2019-02-23 00:07:39 +000095 ; CHECK: call ext_byval_func_empty, $0
Dan Gohmana6771b32016-02-12 21:30:18 +000096 call void @ext_byval_func_empty(%EmptyStruct* byval %ptr)
97 ret void
98}
99
100; CHECK-LABEL: byval_empty_callee
101define void @byval_empty_callee(%EmptyStruct* byval %ptr) {
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000102 ; CHECK: .functype byval_empty_callee (i32) -> ()
Sam Clegg275d15e2019-02-23 00:07:39 +0000103 ; CHECK: call ext_func_empty, $0
Dan Gohmana6771b32016-02-12 21:30:18 +0000104 call void @ext_func_empty(%EmptyStruct* %ptr)
105 ret void
106}
Dan Gohman476ffce2016-02-17 01:43:37 +0000107
108; Call memcpy for "big" byvals.
Dan Gohman476ffce2016-02-17 01:43:37 +0000109; CHECK-LABEL: big_byval:
Sam Clegg275d15e2019-02-23 00:07:39 +0000110; CHECK: global.get $push[[L2:.+]]=, __stack_pointer{{$}}
Derek Schuffdc5f6aa2016-02-20 21:46:50 +0000111; CHECK-NEXT: i32.const $push[[L3:.+]]=, 131072
Dan Gohmanc9623db2016-08-18 17:51:27 +0000112; CHECK-NEXT: i32.sub $push[[L11:.+]]=, $pop[[L2]], $pop[[L3]]
Thomas Lively6a87dda2019-01-08 06:25:55 +0000113; CHECK-NEXT: local.tee $push[[L10:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
Sam Clegg275d15e2019-02-23 00:07:39 +0000114; CHECK-NEXT: global.set __stack_pointer, $pop[[L10]]{{$}}
Dan Gohman0cfb5f82016-05-10 04:24:02 +0000115; CHECK-NEXT: i32.const $push[[L0:.+]]=, 131072
Sam Clegg275d15e2019-02-23 00:07:39 +0000116; CHECK-NEXT: i32.call $push[[L11:.+]]=, memcpy, $[[SP]], ${{.+}}, $pop{{.+}}
Thomas Lively6a87dda2019-01-08 06:25:55 +0000117; CHECK-NEXT: local.tee $push[[L9:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
Sam Clegg275d15e2019-02-23 00:07:39 +0000118; CHECK-NEXT: call big_byval_callee,
Dan Gohman476ffce2016-02-17 01:43:37 +0000119%big = type [131072 x i8]
120declare void @big_byval_callee(%big* byval align 1)
121define void @big_byval(%big* byval align 1 %x) {
122 call void @big_byval_callee(%big* byval align 1 %x)
123 ret void
124}