1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
8 define i32 @test_01(ptr %p, i32 %x, i1 %cond) {
9 ; CHECK-LABEL: @test_01(
11 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB:%.*]], label [[COMMON_RET:%.*]]
13 ; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = phi i32 [ [[R:%.*]], [[BB]] ], [ 0, [[ENTRY:%.*]] ]
14 ; CHECK-NEXT: ret i32 [[COMMON_RET_OP]]
16 ; CHECK-NEXT: [[R]] = load i32, ptr [[P:%.*]], align 4
17 ; CHECK-NEXT: br label [[COMMON_RET]]
20 br i1 %cond, label %bb, label %pred
23 switch i32 %x, label %other_succ [i32 42, label %bb
25 i32 -654321, label %bb]
28 %phi = phi ptr [null, %pred], [null, %pred], [null, %pred], [%p, %entry]
29 %r = load i32, ptr %phi
36 define i32 @test_02(ptr %p, i32 %x, i1 %cond) {
37 ; CHECK-LABEL: @test_02(
39 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB:%.*]], label [[COMMON_RET:%.*]]
41 ; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = phi i32 [ [[R:%.*]], [[BB]] ], [ 0, [[ENTRY:%.*]] ]
42 ; CHECK-NEXT: ret i32 [[COMMON_RET_OP]]
44 ; CHECK-NEXT: [[R]] = load i32, ptr [[P:%.*]], align 4
45 ; CHECK-NEXT: br label [[COMMON_RET]]
48 br i1 %cond, label %bb, label %pred
51 switch i32 %x, label %bb [i32 42, label %other_succ
52 i32 123456, label %other_succ
53 i32 -654321, label %other_succ]
56 %phi = phi ptr [null, %pred], [%p, %entry]
57 %r = load i32, ptr %phi
64 define i32 @test_03(ptr %p, i32 %x, i1 %cond) {
65 ; CHECK-LABEL: @test_03(
67 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB:%.*]], label [[PRED:%.*]]
69 ; CHECK-NEXT: switch i32 [[X:%.*]], label [[UNREACHABLE:%.*]] [
70 ; CHECK-NEXT: i32 42, label [[COMMON_RET:%.*]]
71 ; CHECK-NEXT: i32 123456, label [[COMMON_RET]]
72 ; CHECK-NEXT: i32 -654321, label [[COMMON_RET]]
73 ; CHECK-NEXT: i32 1, label [[DO_1:%.*]]
74 ; CHECK-NEXT: i32 2, label [[DO_2:%.*]]
75 ; CHECK-NEXT: i32 3, label [[DO_3:%.*]]
78 ; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = phi i32 [ [[R:%.*]], [[BB]] ], [ 1, [[DO_1]] ], [ 1, [[DO_2]] ], [ 1, [[DO_3]] ], [ 0, [[PRED]] ], [ 0, [[PRED]] ], [ 0, [[PRED]] ]
79 ; CHECK-NEXT: ret i32 [[COMMON_RET_OP]]
81 ; CHECK-NEXT: unreachable
83 ; CHECK-NEXT: [[R]] = load i32, ptr [[P:%.*]], align 4
84 ; CHECK-NEXT: br label [[COMMON_RET]]
86 ; CHECK-NEXT: call void @foo_01()
87 ; CHECK-NEXT: br label [[COMMON_RET]]
89 ; CHECK-NEXT: call void @foo_02()
90 ; CHECK-NEXT: br label [[COMMON_RET]]
92 ; CHECK-NEXT: call void @foo_03()
93 ; CHECK-NEXT: br label [[COMMON_RET]]
96 br i1 %cond, label %bb, label %pred
99 switch i32 %x, label %bb [i32 42, label %other_succ
100 i32 123456, label %other_succ
101 i32 -654321, label %other_succ
107 %phi = phi ptr [null, %pred], [%p, %entry]
108 %r = load i32, ptr %phi
127 define i32 @test_04(ptr %p, i32 %x, i1 %cond) {
128 ; CHECK-LABEL: @test_04(
130 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB:%.*]], label [[PRED:%.*]]
132 ; CHECK-NEXT: switch i32 [[X:%.*]], label [[COMMON_RET:%.*]] [
133 ; CHECK-NEXT: i32 3, label [[DO_3:%.*]]
134 ; CHECK-NEXT: i32 2, label [[DO_2:%.*]]
135 ; CHECK-NEXT: i32 1, label [[DO_1:%.*]]
138 ; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = phi i32 [ [[R:%.*]], [[BB]] ], [ 1, [[DO_1]] ], [ 1, [[DO_2]] ], [ 1, [[DO_3]] ], [ 0, [[PRED]] ]
139 ; CHECK-NEXT: ret i32 [[COMMON_RET_OP]]
141 ; CHECK-NEXT: [[R]] = load i32, ptr [[P:%.*]], align 4
142 ; CHECK-NEXT: br label [[COMMON_RET]]
144 ; CHECK-NEXT: call void @foo_01()
145 ; CHECK-NEXT: br label [[COMMON_RET]]
147 ; CHECK-NEXT: call void @foo_02()
148 ; CHECK-NEXT: br label [[COMMON_RET]]
150 ; CHECK-NEXT: call void @foo_03()
151 ; CHECK-NEXT: br label [[COMMON_RET]]
154 br i1 %cond, label %bb, label %pred
157 switch i32 %x, label %other_succ [i32 42, label %bb
158 i32 123456, label %bb
159 i32 -654321, label %bb
165 %phi = phi ptr [null, %pred], [null, %pred], [null, %pred], [%p, %entry]
166 %r = load i32, ptr %phi