1; 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 } 11%EmptyStruct = type { } 12 13%BigArray = type { [33 x i8] } 14 15declare void @ext_func(%SmallStruct*) 16declare void @ext_func_empty(%EmptyStruct* byval) 17declare 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) 21declare void @ext_byval_func_empty(%EmptyStruct* byval) 22 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 $push[[L1:.+]]=, __stack_pointer 28 ; CHECK-NEXT: i32.load $push[[L2:.+]]=, 0($pop[[L1]]) 29 ; CHECK-NEXT: i32.const $push[[L3:.+]]=, 16 30 ; CHECK-NEXT: i32.sub [[SP:.+]]=, $pop[[L2]], $pop[[L3]] 31 ; Ensure SP is stored back before the call 32 ; CHECK-NEXT: i32.const $push[[L4:.+]]=, __stack_pointer 33 ; CHECK-NEXT: i32.store {{.*}}=, 0($pop[[L4]]), [[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 $push[[L5:.+]]=, 12 39 ; CHECK-NEXT: i32.add $push[[ARG:.+]]=, [[SP]], $pop[[L5]] 40 ; CHECK-NEXT: call ext_byval_func@FUNCTION, $pop[[ARG]] 41 call void @ext_byval_func(%SmallStruct* byval %ptr) 42 ; Restore the stack 43 ; CHECK-NEXT: i32.const $push[[L7:.+]]=, __stack_pointer 44 ; CHECK-NEXT: i32.const $push[[L6:.+]]=, 16 45 ; CHECK-NEXT: i32.add $push[[L8:.+]]=, [[SP]], $pop[[L6]] 46 ; CHECK-NEXT: i32.store {{.*}}=, 0($pop[[L7]]), $pop[[L8]] 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 $push[[L1:.+]]=, 16 56 ; CHECK-NEXT: i32.sub [[SP:.+]]=, {{.+}}, $pop[[L1]] 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 $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 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 $push[[L1:.+]]=, 16 73 ; CHECK-NEXT: i32.sub [[SP:.+]]=, {{.+}}, $pop[[L1]] 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_param 85define void @byval_param(%SmallStruct* byval align 32 %ptr) { 86 ; CHECK: .param i32 87 ; %ptr is just a pointer to a struct, so pass it directly through 88 ; CHECK: call ext_func@FUNCTION, $0 89 call void @ext_func(%SmallStruct* %ptr) 90 ret void 91} 92 93; CHECK-LABEL: byval_empty_caller 94define void @byval_empty_caller(%EmptyStruct* %ptr) { 95 ; CHECK: .param i32 96 ; CHECK: call ext_byval_func_empty@FUNCTION, $0 97 call void @ext_byval_func_empty(%EmptyStruct* byval %ptr) 98 ret void 99} 100 101; CHECK-LABEL: byval_empty_callee 102define void @byval_empty_callee(%EmptyStruct* byval %ptr) { 103 ; CHECK: .param i32 104 ; CHECK: call ext_func_empty@FUNCTION, $0 105 call void @ext_func_empty(%EmptyStruct* %ptr) 106 ret void 107} 108 109; Call memcpy for "big" byvals. 110; CHECK-LABEL: big_byval: 111; CHECK: i32.const $push[[L1:.+]]=, __stack_pointer 112; CHECK-NEXT: i32.load $push[[L2:.+]]=, 0($pop[[L1]]) 113; CHECK-NEXT: i32.const $push[[L3:.+]]=, 131072 114; CHECK-NEXT: i32.sub [[SP:.+]]=, $pop[[L2]], $pop[[L3]] 115; CHECK: i32.call ${{[^,]+}}=, memcpy@FUNCTION, 116; CHECK-NEXT: call big_byval_callee@FUNCTION, 117%big = type [131072 x i8] 118declare void @big_byval_callee(%big* byval align 1) 119define void @big_byval(%big* byval align 1 %x) { 120 call void @big_byval_callee(%big* byval align 1 %x) 121 ret void 122} 123