[ShrinkWrap] Make sure we do not mess up with EH funclet lowering.
[oota-llvm.git] / test / CodeGen / X86 / late-address-taken.ll
1 ; RUN: llc -mtriple=x86_64-pc-windows-msvc < %s -enable-shrink-wrap=false | FileCheck %s
2 ; Make sure shrink-wrapping does not break the lowering of exception handling.
3 ; RUN: llc -mtriple=x86_64-pc-windows-msvc < %s -enable-shrink-wrap=true | FileCheck %s
4
5 ; Repro cases from PR25168
6
7 ; test @catchret - catchret target is not address-taken until PEI
8 ; splits it into lea/mov followed by ret.  Make sure the MBB is
9 ; handled, both by tempting BranchFolding to merge it with %early_out
10 ; and delete it, and by checking that we emit a proper reference
11 ; to it in the LEA
12
13 declare void @ProcessCLRException()
14 declare void @f()
15
16 define void @catchret(i1 %b) personality void ()* @ProcessCLRException {
17 entry:
18   br i1 %b, label %body, label %early_out
19 early_out:
20   ret void
21 body:
22   invoke void @f()
23           to label %exit unwind label %catch.pad
24 catch.pad:
25   %catch = catchpad [i32 33554467]
26           to label %catch.body unwind label %catch.end
27 catch.body:
28   catchret %catch to label %exit
29 catch.end:
30   catchendpad unwind to caller
31 exit:
32   ret void
33 }
34 ; CHECK-LABEL: catchret:  # @catchret
35 ; CHECK: [[Exit:^[^ :]+]]: # Block address taken
36 ; CHECK-NEXT:              # %exit
37 ; CHECK: # %catch.pad
38 ; CHECK: .seh_endprolog
39 ; CHECK: leaq [[Exit]](%rip), %rax
40 ; CHECK: retq # CATCHRET
41
42
43 ; test @setjmp - similar to @catchret, but the MBB in question
44 ; is the one generated when the setjmp's block is split
45
46 @buf = internal global [5 x i8*] zeroinitializer
47 declare i8* @llvm.frameaddress(i32) nounwind readnone
48 declare i8* @llvm.stacksave() nounwind
49 declare i32 @llvm.eh.sjlj.setjmp(i8*) nounwind
50 declare void @llvm.eh.sjlj.longjmp(i8*) nounwind
51
52 define void @setjmp(i1 %b) nounwind {
53 entry:
54   br i1 %b, label %early_out, label %sj
55 early_out:
56   ret void
57 sj:
58   %fp = call i8* @llvm.frameaddress(i32 0)
59   store i8* %fp, i8** getelementptr inbounds ([5 x i8*], [5 x i8*]* @buf, i64 0, i64 0), align 16
60   %sp = call i8* @llvm.stacksave()
61   store i8* %sp, i8** getelementptr inbounds ([5 x i8*], [5 x i8*]* @buf, i64 0, i64 2), align 16
62   call i32 @llvm.eh.sjlj.setjmp(i8* bitcast ([5 x i8*]* @buf to i8*))
63   ret void
64 }
65 ; CHECK-LABEL: setjmp: # @setjmp
66 ; CHECK: # %sj
67 ; CHECK: leaq [[Label:\..+]](%rip), %[[Reg:.+]]{{$}}
68 ; CHECK-NEXT: movq %[[Reg]], buf
69 ; CHECK: {{^}}[[Label]]:  # Block address taken
70 ; CHECK-NEXT:              # %sj