1 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers | FileCheck %s
3 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
4 target triple = "wasm32-unknown-unknown"
6 declare void @somefunc(i32*)
8 ; CHECK-LABEL: underalign:
9 ; CHECK: global.get $push[[L1:.+]]=, __stack_pointer{{$}}
10 ; CHECK-NEXT: i32.const $push[[L2:.+]]=, 16
11 ; CHECK-NEXT: i32.sub $push[[L10:.+]]=, $pop[[L1]], $pop[[L2]]
12 ; CHECK-NEXT: local.tee $push{{.+}}=, [[SP:.+]], $pop[[L10]]
14 ; CHECK: local.get $push[[L3:.+]]=, [[SP]]{{$}}
15 ; CHECK: i32.add $push[[underaligned:.+]]=, $pop[[L3]], $pop{{.+}}
16 ; CHECK-NEXT: call somefunc, $pop[[underaligned]]
18 ; CHECK: local.get $push[[M4:.+]]=, [[SP]]{{$}}
19 ; CHECK: i32.add $push[[L5:.+]]=, $pop[[M4]], $pop{{.+}}
20 ; CHECK-NEXT: global.set __stack_pointer, $pop[[L5]]
21 define void @underalign() {
23 %underaligned = alloca i32, align 8
24 call void @somefunc(i32* %underaligned)
28 ; CHECK-LABEL: overalign:
29 ; CHECK: global.get $push[[L10:.+]]=, __stack_pointer{{$}}
30 ; CHECK-NEXT: local.tee $push[[L9:.+]]=, [[BP:.+]], $pop[[L10]]
31 ; CHECK-NEXT: i32.const $push[[L2:.+]]=, 32
32 ; CHECK-NEXT: i32.sub $push[[L8:.+]]=, $pop[[L9]], $pop[[L2]]
33 ; CHECK-NEXT: i32.const $push[[L3:.+]]=, -32
34 ; CHECK-NEXT: i32.and $push[[L7:.+]]=, $pop[[L8]], $pop[[L3]]
35 ; CHECK-NEXT: local.tee $push{{.+}}=, [[SP:.+]], $pop[[L7]]
37 ; CHECK: local.get $push[[M5:.+]]=, [[SP]]{{$}}
38 ; CHECK: call somefunc, $pop[[M5]]{{$}}
40 ; CHECK: local.get $push[[M6:.+]]=, [[BP]]{{$}}
41 ; CHECK-NEXT: global.set __stack_pointer, $pop[[M6]]
42 define void @overalign() {
44 %overaligned = alloca i32, align 32
45 call void @somefunc(i32* %overaligned)
49 ; CHECK-LABEL: over_and_normal_align:
50 ; CHECK: global.get $push[[L14:.+]]=, __stack_pointer{{$}}
51 ; CHECK-NEXT: local.tee $push[[L13:.+]]=, [[BP:.+]], $pop[[L14]]
52 ; CHECK: i32.sub $push[[L12:.+]]=, $pop[[L13]], $pop{{.+}}
53 ; CHECK: i32.and $push[[L11:.+]]=, $pop[[L12]], $pop{{.+}}
54 ; CHECK-NEXT: local.tee $push{{.+}}=, [[SP:.+]], $pop[[L11]]
56 ; CHECK: local.get $push[[M6:.+]]=, [[SP]]{{$}}
57 ; CHECK: i32.add $push[[L6:.+]]=, $pop[[M6]], $pop{{.+}}
58 ; CHECK-NEXT: call somefunc, $pop[[L6]]
59 ; CHECK: local.get $push[[M7:.+]]=, [[SP]]{{$}}
60 ; CHECK: i32.add $push[[L8:.+]]=, $pop[[M7]], $pop{{.+}}
61 ; CHECK-NEXT: call somefunc, $pop[[L8]]
63 ; CHECK: local.get $push[[L6:.+]]=, [[BP]]{{$}}
64 ; CHECK-NEXT: global.set __stack_pointer, $pop[[L6]]
65 define void @over_and_normal_align() {
67 %over = alloca i32, align 32
69 call void @somefunc(i32* %over)
70 call void @somefunc(i32* %normal)
74 ; CHECK-LABEL: dynamic_overalign:
75 ; CHECK: global.get $push[[L18:.+]]=, __stack_pointer{{$}}
76 ; CHECK-NEXT: local.tee $push[[L17:.+]]=, [[SP:.+]], $pop[[L18]]
77 ; CHECK-NEXT: local.set [[BP:.+]], $pop[[L17]]
78 ; CHECK: local.tee $push{{.+}}=, [[SP_2:.+]], $pop{{.+}}
80 ; CHECK: local.get $push[[M8:.+]]=, [[SP_2]]{{$}}
81 ; CHECK: call somefunc, $pop[[M8]]
83 ; CHECK: local.get $push[[M9:.+]]=, [[BP]]{{$}}
84 ; CHECK-NEXT: global.set __stack_pointer, $pop[[M9]]
85 define void @dynamic_overalign(i32 %num) {
87 %dynamic = alloca i32, i32 %num, align 32
88 call void @somefunc(i32* %dynamic)
92 ; CHECK-LABEL: overalign_and_dynamic:
93 ; CHECK: global.get $push[[L21:.+]]=, __stack_pointer{{$}}
94 ; CHECK-NEXT: local.tee $push[[L20:.+]]=, [[BP:.+]], $pop[[L21]]
95 ; CHECK: i32.sub $push[[L19:.+]]=, $pop[[L20]], $pop{{.+}}
96 ; CHECK: i32.and $push[[L18:.+]]=, $pop[[L19]], $pop{{.+}}
97 ; CHECK: local.tee $push{{.+}}=, [[FP:.+]], $pop[[L18]]
98 ; CHECK: local.get $push[[M10:.+]]=, [[FP]]{{$}}
99 ; CHECK: i32.sub $push[[L16:.+]]=, $pop[[M10]], $pop{{.+}}
100 ; CHECK-NEXT: local.tee $push{{.+}}=, [[SP:.+]], $pop[[L16]]
102 ; CHECK: local.get $push[[over:.+]]=, [[FP]]
103 ; CHECK-NEXT: call somefunc, $pop[[over]]
104 ; CHECK: local.get $push[[another:.+]]=, [[SP]]
105 ; CHECK-NEXT: call somefunc, $pop[[another]]
107 ; CHECK: local.get $push[[M11:.+]]=, [[BP]]{{$}}
108 ; CHECK-NEXT: global.set __stack_pointer, $pop[[M11]]
109 define void @overalign_and_dynamic(i32 %num) {
111 %over = alloca i32, align 32
112 %dynamic = alloca i32, i32 %num
113 call void @somefunc(i32* %over)
114 call void @somefunc(i32* %dynamic)
118 ; CHECK-LABEL: overalign_static_and_dynamic:
119 ; CHECK: global.get $push[[L26:.+]]=, __stack_pointer{{$}}
120 ; CHECK-NEXT: local.tee $push[[L25:.+]]=, [[BP:.+]], $pop[[L26]]
121 ; CHECK: i32.sub $push[[L24:.+]]=, $pop[[L25]], $pop{{.+}}
122 ; CHECK: i32.and $push[[L23:.+]]=, $pop[[L24]], $pop{{.+}}
123 ; CHECK: local.tee $push{{.+}}=, [[FP:.+]], $pop[[L23]]
124 ; CHECK: local.get $push[[M12:.+]]=, [[FP]]{{$}}
125 ; CHECK: i32.sub $push[[L21:.+]]=, $pop[[M12]], $pop{{.+}}
126 ; CHECK-NEXT: local.tee $push{{.+}}=, [[SP:.+]], $pop[[L21]]
128 ; CHECK: local.get $push[[L19:.+]]=, [[FP]]
129 ; CHECK: local.tee $push[[L18:.+]]=, [[FP_2:.+]], $pop[[L19]]
130 ; CHECK: i32.add $push[[over:.+]]=, $pop[[L18]], $pop{{.+}}
131 ; CHECK-NEXT: call somefunc, $pop[[over]]
132 ; CHECK: local.get $push[[M12:.+]]=, [[SP]]
133 ; CHECK: call somefunc, $pop[[M12]]
134 ; CHECK: local.get $push[[M13:.+]]=, [[FP_2]]
135 ; CHECK: i32.add $push[[static:.+]]=, $pop[[M13]], $pop{{.+}}
136 ; CHECK-NEXT: call somefunc, $pop[[static]]
138 ; CHECK: local.get $push[[M14:.+]]=, [[BP]]{{$}}
139 ; CHECK-NEXT: global.set __stack_pointer, $pop[[M14]]
140 define void @overalign_static_and_dynamic(i32 %num) {
142 %over = alloca i32, align 32
143 %dynamic = alloca i32, i32 %num
145 call void @somefunc(i32* %over)
146 call void @somefunc(i32* %dynamic)
147 call void @somefunc(i32* %static)