1 ; RUN: llc %s -o - | FileCheck %s
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, %edi
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, %edi
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, %edi
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: jbe [[ENTRY_LABEL:LBB[0-9_]+]]
165 ; In PR26107, we use to drop these two basic blocks, because
166 ; the segmentedStack entry block was jumping directly to
167 ; the place where the prologue is actually needed, which is
168 ; the call to memcmp.
169 ; Then, those two basic blocks did not have any predecessors
170 ; anymore and were removed.
172 ; Check if vk1 is null
173 ; CHECK: testq %rdi, %rdi
174 ; CHECK-NEXT: je [[STRINGS_EQUAL:LBB[0-9_]+]]
176 ; Check if vk2 is null
177 ; CHECK: testq %rsi, %rsi
178 ; CHECK-NEXT: je [[STRINGS_EQUAL]]
180 ; CHECK: [[STRINGS_EQUAL]]
183 ; CHECK: [[ENTRY_LABEL]]:
184 ; CHECK: callq ___morestack
188 define zeroext i1 @segmentedStack(i8* readonly %vk1, i8* readonly %vk2, i64 %key_size) #5 {
190 %cmp.i = icmp eq i8* %vk1, null
191 %cmp1.i = icmp eq i8* %vk2, null
192 %brmerge.i = or i1 %cmp.i, %cmp1.i
193 %cmp1.mux.i = and i1 %cmp.i, %cmp1.i
194 br i1 %brmerge.i, label %__go_ptr_strings_equal.exit, label %if.end4.i
196 if.end4.i: ; preds = %entry
197 %tmp = getelementptr inbounds i8, i8* %vk1, i64 8
198 %tmp1 = bitcast i8* %tmp to i64*
199 %tmp2 = load i64, i64* %tmp1, align 8
200 %tmp3 = getelementptr inbounds i8, i8* %vk2, i64 8
201 %tmp4 = bitcast i8* %tmp3 to i64*
202 %tmp5 = load i64, i64* %tmp4, align 8
203 %cmp.i.i = icmp eq i64 %tmp2, %tmp5
204 br i1 %cmp.i.i, label %land.rhs.i.i, label %__go_ptr_strings_equal.exit
206 land.rhs.i.i: ; preds = %if.end4.i
207 %tmp6 = bitcast i8* %vk2 to i8**
208 %tmp7 = load i8*, i8** %tmp6, align 8
209 %tmp8 = bitcast i8* %vk1 to i8**
210 %tmp9 = load i8*, i8** %tmp8, align 8
211 %call.i.i = tail call i32 @memcmp(i8* %tmp9, i8* %tmp7, i64 %tmp2) #5
212 %cmp4.i.i = icmp eq i32 %call.i.i, 0
213 br label %__go_ptr_strings_equal.exit
215 __go_ptr_strings_equal.exit: ; preds = %land.rhs.i.i, %if.end4.i, %entry
216 %retval.0.i = phi i1 [ %cmp1.mux.i, %entry ], [ false, %if.end4.i ], [ %cmp4.i.i, %land.rhs.i.i ]
220 ; Function Attrs: nounwind readonly
221 declare i32 @memcmp(i8* nocapture, i8* nocapture, i64) #5
223 attributes #5 = { nounwind readonly ssp uwtable "split-stack" }
225 ; Check that correctly take into account the jumps to landing pad.
226 ; We used to consider function that may throw like regular
228 ; Therefore, in this example, we were happily inserting the epilogue
229 ; right after the call to throw_exception. Because of that we would not
230 ; execute the epilogue when an execption occur and bad things will
234 ; CHECK-LABEL: with_nounwind:
238 ; Jump to throw_exception:
239 ; CHECK-NEXT: .cfi_def_cfa_offset
240 ; CHECK-NEXT: testb $1, %dil
241 ; CHECK-NEXT: jne [[THROW_LABEL:LBB[0-9_]+]]
246 ; CHECK-NEXT: [[THROW_LABEL]]:
247 ; CHECK: callq _throw_exception
248 ; Unreachable block...
250 ; Epilogue must be after the landing pad.
253 ; Look for the landing pad label.
254 ; CHECK: LBB{{[0-9_]+}}:
255 ; Epilogue on the landing pad
258 define void @with_nounwind(i1 %cond) nounwind personality i32 (...)* @my_personality {
260 br i1 %cond, label %throw, label %return
263 invoke void @throw_exception()
264 to label %unreachable unwind label %landing
270 %pad = landingpad { i8*, i32 }
278 ; Check landing pad again.
279 ; This time checks that we can shrink-wrap when the epilogue does not
280 ; span accross several blocks.
282 ; CHECK-LABEL: with_nounwind_same_succ:
284 ; Jump to throw_exception:
285 ; CHECK: testb $1, %dil
286 ; CHECK-NEXT: je [[RET_LABEL:LBB[0-9_]+]]
290 ; CHECK: callq _throw_exception
293 ; CHECK: [[FALLTHROUGH_LABEL:LBB[0-9_]+]]
297 ; CHECK: [[RET_LABEL]]
300 ; Look for the landing pad label.
301 ; CHECK: LBB{{[0-9_]+}}:
302 ; Landing pad jumps to fallthrough
303 ; CHECK: jmp [[FALLTHROUGH_LABEL]]
304 define void @with_nounwind_same_succ(i1 %cond) nounwind personality i32 (...)* @my_personality2 {
306 br i1 %cond, label %throw, label %return
309 invoke void @throw_exception()
310 to label %fallthrough unwind label %landing
312 %pad = landingpad { i8*, i32 }
314 br label %fallthrough
317 tail call void asm "nop", ""()
324 declare void @throw_exception()
325 declare i32 @my_personality(...)
326 declare i32 @my_personality2(...)