Home | History | Annotate | Download | only in WebAssembly
      1 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -verify-machineinstrs | FileCheck %s
      2 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -verify-machineinstrs -fast-isel | FileCheck %s
      3 
      4 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
      5 target 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 
     15 declare void @ext_func(%SmallStruct*)
     16 declare void @ext_func_empty(%EmptyStruct* byval)
     17 declare void @ext_byval_func(%SmallStruct* byval)
     18 declare void @ext_byval_func_align8(%SmallStruct* byval align 8)
     19 declare void @ext_byval_func_alignedstruct(%AlignedStruct* byval)
     20 declare void @ext_byval_func_bigarray(%BigArray* byval)
     21 declare void @ext_byval_func_empty(%EmptyStruct* byval)
     22 
     23 ; CHECK-LABEL: byval_arg
     24 define void @byval_arg(%SmallStruct* %ptr) {
     25  ; CHECK: .param i32
     26  ; CHECK: i32.const $push[[L4:.+]]=, 0
     27  ; Subtract 16 from SP (SP is 16-byte aligned)
     28  ; CHECK: i32.const $push[[L1:.+]]=, 0
     29  ; CHECK-NEXT: i32.load $push[[L2:.+]]=, __stack_pointer($pop[[L1]])
     30  ; CHECK-NEXT: i32.const $push[[L3:.+]]=, 16
     31  ; CHECK-NEXT: i32.sub $push[[L10:.+]]=, $pop[[L2]], $pop[[L3]]
     32  ; Ensure SP is stored back before the call
     33  ; CHECK-NEXT: i32.store $push[[L12:.+]]=, __stack_pointer($pop[[L4]]), $pop[[L10]]{{$}}
     34  ; CHECK-NEXT: tee_local $push[[L11:.+]]=, $[[SP:.+]]=, $pop[[L12]]{{$}}
     35  ; Copy the SmallStruct argument to the stack (SP+12, original SP-4)
     36  ; CHECK-NEXT: i32.load $push[[L0:.+]]=, 0($0)
     37  ; CHECK-NEXT: i32.store $drop=, 12($pop[[L11]]), $pop[[L0]]
     38  ; Pass a pointer to the stack slot to the function
     39  ; CHECK-NEXT: i32.const $push[[L5:.+]]=, 12{{$}}
     40  ; CHECK-NEXT: i32.add $push[[ARG:.+]]=, $[[SP]], $pop[[L5]]{{$}}
     41  ; CHECK-NEXT: call ext_byval_func@FUNCTION, $pop[[ARG]]{{$}}
     42  call void @ext_byval_func(%SmallStruct* byval %ptr)
     43  ; Restore the stack
     44  ; CHECK-NEXT: i32.const $push[[L7:.+]]=, 0
     45  ; CHECK-NEXT: i32.const $push[[L6:.+]]=, 16
     46  ; CHECK-NEXT: i32.add $push[[L8:.+]]=, $[[SP]], $pop[[L6]]
     47  ; CHECK-NEXT: i32.store {{.*}}=, __stack_pointer($pop[[L7]]), $pop[[L8]]
     48  ; CHECK-NEXT: return
     49  ret void
     50 }
     51 
     52 ; CHECK-LABEL: byval_arg_align8
     53 define void @byval_arg_align8(%SmallStruct* %ptr) {
     54  ; CHECK: .param i32
     55  ; Don't check the entire SP sequence, just enough to get the alignment.
     56  ; CHECK: i32.const $push[[L1:.+]]=, 16
     57  ; CHECK-NEXT: i32.sub $push[[L10:.+]]=, {{.+}}, $pop[[L1]]
     58  ; CHECK-NEXT: i32.store $push[[L12:.+]]=, __stack_pointer($pop{{.+}}), $pop[[L10]]{{$}}
     59  ; CHECK-NEXT: tee_local $push[[L11:.+]]=, $[[SP:.+]]=, $pop[[L12]]{{$}}
     60  ; Copy the SmallStruct argument to the stack (SP+8, original SP-8)
     61  ; CHECK-NEXT: i32.load $push[[L0:.+]]=, 0($0){{$}}
     62  ; CHECK-NEXT: i32.store $drop=, 8($pop[[L11]]), $pop[[L0]]{{$}}
     63  ; Pass a pointer to the stack slot to the function
     64  ; CHECK-NEXT: i32.const $push[[L5:.+]]=, 8{{$}}
     65  ; CHECK-NEXT: i32.add $push[[ARG:.+]]=, $[[SP]], $pop[[L5]]{{$}}
     66  ; CHECK-NEXT: call ext_byval_func_align8@FUNCTION, $pop[[ARG]]{{$}}
     67  call void @ext_byval_func_align8(%SmallStruct* byval align 8 %ptr)
     68  ret void
     69 }
     70 
     71 ; CHECK-LABEL: byval_arg_double
     72 define void @byval_arg_double(%AlignedStruct* %ptr) {
     73  ; CHECK: .param i32
     74  ; Subtract 16 from SP (SP is 16-byte aligned)
     75  ; CHECK: i32.const $push[[L1:.+]]=, 16
     76  ; CHECK-NEXT: i32.sub $push[[L12:.+]]=, {{.+}}, $pop[[L1]]
     77  ; CHECK-NEXT: i32.store $push[[L15:.+]]=, {{.+}}, $pop[[L12]]
     78  ; CHECK-NEXT: tee_local $push[[L14:.+]]=, $[[SP:.+]]=, $pop[[L15]]
     79  ; Copy the AlignedStruct argument to the stack (SP+0, original SP-16)
     80  ; Just check the last load/store pair of the memcpy
     81  ; CHECK: i64.load $push[[L4:.+]]=, 0($0)
     82  ; CHECK-NEXT: i64.store $drop=, 0($[[SP]]), $pop[[L4]]
     83  ; Pass a pointer to the stack slot to the function
     84  ; CHECK-NEXT: call ext_byval_func_alignedstruct@FUNCTION, $[[SP]]
     85  tail call void @ext_byval_func_alignedstruct(%AlignedStruct* byval %ptr)
     86  ret void
     87 }
     88 
     89 ; CHECK-LABEL: byval_param
     90 define void @byval_param(%SmallStruct* byval align 32 %ptr) {
     91  ; CHECK: .param i32
     92  ; %ptr is just a pointer to a struct, so pass it directly through
     93  ; CHECK: call ext_func@FUNCTION, $0
     94  call void @ext_func(%SmallStruct* %ptr)
     95  ret void
     96 }
     97 
     98 ; CHECK-LABEL: byval_empty_caller
     99 define void @byval_empty_caller(%EmptyStruct* %ptr) {
    100  ; CHECK: .param i32
    101  ; CHECK: call ext_byval_func_empty@FUNCTION, $0
    102  call void @ext_byval_func_empty(%EmptyStruct* byval %ptr)
    103  ret void
    104 }
    105 
    106 ; CHECK-LABEL: byval_empty_callee
    107 define void @byval_empty_callee(%EmptyStruct* byval %ptr) {
    108  ; CHECK: .param i32
    109  ; CHECK: call ext_func_empty@FUNCTION, $0
    110  call void @ext_func_empty(%EmptyStruct* %ptr)
    111  ret void
    112 }
    113 
    114 ; Call memcpy for "big" byvals.
    115 ; CHECK-LABEL: big_byval:
    116 ; CHECK: i32.const $push[[L4:.+]]=, 0
    117 ; CHECK: i32.const $push[[L1:.+]]=, 0
    118 ; CHECK-NEXT: i32.load $push[[L2:.+]]=, __stack_pointer($pop[[L1]])
    119 ; CHECK-NEXT: i32.const $push[[L3:.+]]=, 131072
    120 ; CHECK-NEXT: i32.sub $push[[L8:.+]]=, $pop[[L2]], $pop[[L3]]
    121 ; CHECK-NEXT: i32.store $push[[L12:.+]]=, __stack_pointer($pop[[L4]]), $pop[[L8]]{{$}}
    122 ; CHECK-NEXT: i32.const $push[[L0:.+]]=, 131072
    123 ; CHECK-NEXT: i32.call       $push[[L11:.+]]=, memcpy@FUNCTION, $pop{{.+}}, ${{.+}}, $pop{{.+}}
    124 ; CHECK-NEXT: tee_local      $push[[L9:.+]]=, $[[SP:.+]]=, $pop[[L11]]{{$}}
    125 ; CHECK-NEXT: call           big_byval_callee@FUNCTION,
    126 %big = type [131072 x i8]
    127 declare void @big_byval_callee(%big* byval align 1)
    128 define void @big_byval(%big* byval align 1 %x) {
    129   call void @big_byval_callee(%big* byval align 1 %x)
    130   ret void
    131 }
    132