xref: /llvm-project/llvm/test/Transforms/SimplifyCFG/invoke_unwind.ll (revision fbcefff9d0a3f5e97270ef8e7b8e0f2afc33dc1c)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
2; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
3
4declare void @bar()
5
6; This testcase checks to see if the simplifycfg pass is converting invoke
7; instructions to call instructions if the handler just rethrows the exception.
8define i32 @test1() personality ptr @__gxx_personality_v0 {
9; CHECK-LABEL: @test1(
10; CHECK-NEXT:    call void @bar(), !prof [[PROF0:![0-9]+]]
11; CHECK-NEXT:    ret i32 0
12;
13  invoke void @bar( )
14  to label %1 unwind label %Rethrow, !prof !0
15  ret i32 0
16Rethrow:
17  %exn = landingpad {ptr, i32}
18  catch ptr null
19  resume { ptr, i32 } %exn
20}
21
22!0 = !{!"branch_weights", i32 369, i32 2}
23
24define i32 @test2() personality ptr @__gxx_personality_v0 {
25; CHECK-LABEL: @test2(
26; CHECK-NEXT:    call void @bar() [ "foo"(i32 100) ]
27; CHECK-NEXT:    ret i32 0
28;
29  invoke void @bar( ) [ "foo"(i32 100) ]
30  to label %1 unwind label %Rethrow
31  ret i32 0
32Rethrow:
33  %exn = landingpad {ptr, i32}
34  catch ptr null
35  resume { ptr, i32 } %exn
36}
37
38declare i64 @dummy1()
39declare i64 @dummy2()
40
41; This testcase checks to see if simplifycfg pass can convert two invoke
42; instructions to call instructions if they share a common trivial unwind
43; block.
44define i64 @test3(i1 %cond) personality ptr @__gxx_personality_v0 {
45; CHECK-LABEL: @test3(
46; CHECK-NEXT:  entry:
47; CHECK-NEXT:    br i1 [[COND:%.*]], label [[BR1:%.*]], label [[BR2:%.*]]
48; CHECK:       br1:
49; CHECK-NEXT:    [[CALL1:%.*]] = call i64 @dummy1()
50; CHECK-NEXT:    br label [[INVOKE_CONT:%.*]]
51; CHECK:       br2:
52; CHECK-NEXT:    [[CALL2:%.*]] = call i64 @dummy2()
53; CHECK-NEXT:    br label [[INVOKE_CONT]]
54; CHECK:       invoke.cont:
55; CHECK-NEXT:    [[C:%.*]] = phi i64 [ [[CALL1]], [[BR1]] ], [ [[CALL2]], [[BR2]] ]
56; CHECK-NEXT:    ret i64 [[C]]
57;
58entry:
59  br i1 %cond, label %br1, label %br2
60
61br1:
62  %call1 = invoke i64 @dummy1()
63  to label %invoke.cont unwind label %lpad1
64
65br2:
66  %call2 = invoke i64 @dummy2()
67  to label %invoke.cont unwind label %lpad2
68
69invoke.cont:
70  %c = phi i64 [%call1, %br1], [%call2, %br2]
71  ret i64 %c
72
73
74lpad1:
75  %0 = landingpad { ptr, i32 }
76  cleanup
77  br label %rethrow
78
79rethrow:
80  %lp = phi { ptr, i32 } [%0, %lpad1], [%1, %lpad2]
81  resume { ptr, i32 } %lp
82
83lpad2:
84  %1 = landingpad { ptr, i32 }
85  cleanup
86  br label %rethrow
87}
88
89declare i32 @__gxx_personality_v0(...)
90;.
91; CHECK: [[PROF0]] = !{!"branch_weights", i32 371}
92;.
93