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