1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -sink-common-insts -S < %s | FileCheck %s
4 ; Test that we tail merge resume blocks and phi operands properly.
6 declare void @maybe_throws()
13 declare void @common()
15 define void @merge_simple(i1 %cond) personality ptr @__gxx_personality_v0 {
16 ; CHECK-LABEL: @merge_simple(
17 ; CHECK-NEXT: invoke void @maybe_throws()
18 ; CHECK-NEXT: to label [[INVOKE_CONT:%.*]] unwind label [[LPAD:%.*]]
20 ; CHECK-NEXT: invoke void @maybe_throws()
21 ; CHECK-NEXT: to label [[INVOKE_CONT2:%.*]] unwind label [[LPAD2:%.*]]
22 ; CHECK: invoke.cont2:
23 ; CHECK-NEXT: invoke void @maybe_throws()
24 ; CHECK-NEXT: to label [[INVOKE_CONT3:%.*]] unwind label [[LPAD3:%.*]]
25 ; CHECK: invoke.cont3:
26 ; CHECK-NEXT: ret void
28 ; CHECK-NEXT: [[LP:%.*]] = landingpad { ptr, i32 }
30 ; CHECK-NEXT: call void @foo()
31 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[RESUME0:%.*]], label [[RESUME1:%.*]]
33 ; CHECK-NEXT: [[LP2:%.*]] = landingpad { ptr, i32 }
35 ; CHECK-NEXT: call void @bar()
36 ; CHECK-NEXT: br label [[RESUME2:%.*]]
38 ; CHECK-NEXT: [[LP3:%.*]] = landingpad { ptr, i32 }
40 ; CHECK-NEXT: call void @baz()
41 ; CHECK-NEXT: br label [[RESUME2]]
42 ; CHECK: common.resume:
43 ; CHECK-NEXT: [[COMMON_RESUME_OP:%.*]] = phi { ptr, i32 } [ [[LP]], [[RESUME0]] ], [ [[LP]], [[RESUME1]] ], [ [[SEMICOMMON_LP:%.*]], [[RESUME2]] ]
44 ; CHECK-NEXT: call void @common()
45 ; CHECK-NEXT: resume { ptr, i32 } [[COMMON_RESUME_OP]]
47 ; CHECK-NEXT: call void @qux()
48 ; CHECK-NEXT: br label [[COMMON_RESUME:%.*]]
50 ; CHECK-NEXT: call void @quux()
51 ; CHECK-NEXT: br label [[COMMON_RESUME]]
53 ; CHECK-NEXT: [[SEMICOMMON_LP]] = phi { ptr, i32 } [ [[LP2]], [[LPAD2]] ], [ [[LP3]], [[LPAD3]] ]
54 ; CHECK-NEXT: call void @quuz()
55 ; CHECK-NEXT: br label [[COMMON_RESUME]]
57 invoke void @maybe_throws() to label %invoke.cont unwind label %lpad
60 invoke void @maybe_throws() to label %invoke.cont2 unwind label %lpad2
63 invoke void @maybe_throws() to label %invoke.cont3 unwind label %lpad3
69 %lp = landingpad { ptr, i32 } cleanup
71 br i1 %cond, label %resume0, label %resume1
74 %lp2 = landingpad { ptr, i32 } cleanup
79 %lp3 = landingpad { ptr, i32 } cleanup
86 resume { ptr, i32 } %lp
91 resume { ptr, i32 } %lp
94 %semicommon.lp = phi { ptr, i32 } [ %lp2, %lpad2 ], [ %lp3, %lpad3 ]
97 resume { ptr, i32 } %semicommon.lp
100 declare dso_local i32 @__gxx_personality_v0(...)