1 ; RUN: llc %s -o - | FileCheck %s --check-prefix=CHECK
3 ; Note: This test cannot be merged with the shrink-wrapping tests
4 ; because the booleans set on the command line take precedence on
5 ; the target logic that disable shrink-wrapping.
6 target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
7 target triple = "x86_64-apple-macosx"
10 ; This test checks that we do not use shrink-wrapping when
11 ; the function does not have any frame pointer and may unwind.
12 ; This is a workaround for a limitation in the emission of
13 ; the CFI directives, that are not correct in such case.
16 ; No shrink-wrapping should occur here, until the CFI information are fixed.
17 ; CHECK-LABEL: framelessUnwind:
20 ; (What we push does not matter. It should be some random sratch register.)
23 ; Compare the arguments and jump to exit.
24 ; After the prologue is set.
25 ; CHECK: movl %edi, [[ARG0CPY:%e[a-z]+]]
26 ; CHECK-NEXT: cmpl %esi, [[ARG0CPY]]
27 ; CHECK-NEXT: jge [[EXIT_LABEL:LBB[0-9_]+]]
29 ; Store %a in the alloca.
30 ; CHECK: movl [[ARG0CPY]], 4(%rsp)
31 ; Set the alloca address in the second argument.
32 ; CHECK-NEXT: leaq 4(%rsp), %rsi
33 ; Set the first argument to zero.
34 ; CHECK-NEXT: xorl %edi, %edi
35 ; CHECK-NEXT: callq _doSomething
37 ; CHECK: [[EXIT_LABEL]]:
39 ; Without shrink-wrapping, epilogue is in the exit block.
40 ; Epilogue code. (What we pop does not matter.)
44 define i32 @framelessUnwind(i32 %a, i32 %b) #0 {
45 %tmp = alloca i32, align 4
46 %tmp2 = icmp slt i32 %a, %b
47 br i1 %tmp2, label %true, label %false
50 store i32 %a, i32* %tmp, align 4
51 %tmp4 = call i32 @doSomething(i32 0, i32* %tmp)
55 %tmp.0 = phi i32 [ %tmp4, %true ], [ %a, %0 ]
59 declare i32 @doSomething(i32, i32*)
61 attributes #0 = { "no-frame-pointer-elim"="false" }
63 ; Shrink-wrapping should occur here. We have a frame pointer.
64 ; CHECK-LABEL: frameUnwind:
66 ; Compare the arguments and jump to exit.
69 ; Compare the arguments and jump to exit.
70 ; After the prologue is set.
71 ; CHECK: movl %edi, [[ARG0CPY:%e[a-z]+]]
72 ; CHECK-NEXT: cmpl %esi, [[ARG0CPY]]
73 ; CHECK-NEXT: jge [[EXIT_LABEL:LBB[0-9_]+]]
77 ; CHECK: movq %rsp, %rbp
79 ; Store %a in the alloca.
80 ; CHECK: movl [[ARG0CPY]], -4(%rbp)
81 ; Set the alloca address in the second argument.
82 ; CHECK-NEXT: leaq -4(%rbp), %rsi
83 ; Set the first argument to zero.
84 ; CHECK-NEXT: xorl %edi, %edi
85 ; CHECK-NEXT: callq _doSomething
87 ; Epilogue code. (What we pop does not matter.)
90 ; CHECK: [[EXIT_LABEL]]:
92 define i32 @frameUnwind(i32 %a, i32 %b) #1 {
93 %tmp = alloca i32, align 4
94 %tmp2 = icmp slt i32 %a, %b
95 br i1 %tmp2, label %true, label %false
98 store i32 %a, i32* %tmp, align 4
99 %tmp4 = call i32 @doSomething(i32 0, i32* %tmp)
103 %tmp.0 = phi i32 [ %tmp4, %true ], [ %a, %0 ]
107 attributes #1 = { "no-frame-pointer-elim"="true" }
109 ; Shrink-wrapping should occur here. We do not have to unwind.
110 ; CHECK-LABEL: framelessnoUnwind:
112 ; Compare the arguments and jump to exit.
113 ; No prologue needed.
115 ; Compare the arguments and jump to exit.
116 ; After the prologue is set.
117 ; CHECK: movl %edi, [[ARG0CPY:%e[a-z]+]]
118 ; CHECK-NEXT: cmpl %esi, [[ARG0CPY]]
119 ; CHECK-NEXT: jge [[EXIT_LABEL:LBB[0-9_]+]]
122 ; (What we push does not matter. It should be some random sratch register.)
125 ; Store %a in the alloca.
126 ; CHECK: movl [[ARG0CPY]], 4(%rsp)
127 ; Set the alloca address in the second argument.
128 ; CHECK-NEXT: leaq 4(%rsp), %rsi
129 ; Set the first argument to zero.
130 ; CHECK-NEXT: xorl %edi, %edi
131 ; CHECK-NEXT: callq _doSomething
136 ; CHECK: [[EXIT_LABEL]]:
138 define i32 @framelessnoUnwind(i32 %a, i32 %b) #2 {
139 %tmp = alloca i32, align 4
140 %tmp2 = icmp slt i32 %a, %b
141 br i1 %tmp2, label %true, label %false
144 store i32 %a, i32* %tmp, align 4
145 %tmp4 = call i32 @doSomething(i32 0, i32* %tmp)
149 %tmp.0 = phi i32 [ %tmp4, %true ], [ %a, %0 ]
153 attributes #2 = { "no-frame-pointer-elim"="false" nounwind }
156 ; Check that we generate correct code for segmented stack.
157 ; We used to emit the code at the entry point of the function
158 ; instead of just before the prologue.
159 ; For now, shrink-wrapping is disabled on segmented stack functions: PR26107.
161 ; CHECK-LABEL: segmentedStack:
163 ; CHECK-NEXT: ja [[ENTRY_LABEL:LBB[0-9_]+]]
165 ; CHECK: callq ___morestack
168 ; CHECK: [[ENTRY_LABEL]]:
172 ; In PR26107, we use to drop these two basic blocks, because
173 ; the segmentedStack entry block was jumping directly to
174 ; the place where the prologue is actually needed, which is
175 ; the call to memcmp.
176 ; Then, those two basic blocks did not have any predecessors
177 ; anymore and were removed.
179 ; Check if vk1 is null
180 ; CHECK: testq %rdi, %rdi
181 ; CHECK-NEXT: je [[STRINGS_EQUAL:LBB[0-9_]+]]
183 ; Check if vk2 is null
184 ; CHECK: testq %rsi, %rsi
185 ; CHECK-NEXT: je [[STRINGS_EQUAL]]
187 ; CHECK: [[STRINGS_EQUAL]]
189 define zeroext i1 @segmentedStack(i8* readonly %vk1, i8* readonly %vk2, i64 %key_size) #5 {
191 %cmp.i = icmp eq i8* %vk1, null
192 %cmp1.i = icmp eq i8* %vk2, null
193 %brmerge.i = or i1 %cmp.i, %cmp1.i
194 %cmp1.mux.i = and i1 %cmp.i, %cmp1.i
195 br i1 %brmerge.i, label %__go_ptr_strings_equal.exit, label %if.end4.i
197 if.end4.i: ; preds = %entry
198 %tmp = getelementptr inbounds i8, i8* %vk1, i64 8
199 %tmp1 = bitcast i8* %tmp to i64*
200 %tmp2 = load i64, i64* %tmp1, align 8
201 %tmp3 = getelementptr inbounds i8, i8* %vk2, i64 8
202 %tmp4 = bitcast i8* %tmp3 to i64*
203 %tmp5 = load i64, i64* %tmp4, align 8
204 %cmp.i.i = icmp eq i64 %tmp2, %tmp5
205 br i1 %cmp.i.i, label %land.rhs.i.i, label %__go_ptr_strings_equal.exit
207 land.rhs.i.i: ; preds = %if.end4.i
208 %tmp6 = bitcast i8* %vk2 to i8**
209 %tmp7 = load i8*, i8** %tmp6, align 8
210 %tmp8 = bitcast i8* %vk1 to i8**
211 %tmp9 = load i8*, i8** %tmp8, align 8
212 %call.i.i = tail call i32 @memcmp(i8* %tmp9, i8* %tmp7, i64 %tmp2) #5
213 %cmp4.i.i = icmp eq i32 %call.i.i, 0
214 br label %__go_ptr_strings_equal.exit
216 __go_ptr_strings_equal.exit: ; preds = %land.rhs.i.i, %if.end4.i, %entry
217 %retval.0.i = phi i1 [ %cmp1.mux.i, %entry ], [ false, %if.end4.i ], [ %cmp4.i.i, %land.rhs.i.i ]
221 ; Function Attrs: nounwind readonly
222 declare i32 @memcmp(i8* nocapture, i8* nocapture, i64) #5
224 attributes #5 = { nounwind readonly ssp uwtable "split-stack" }