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
9 ; This function can't be merged
13 ; CHECK-NEXT: br label [[BB_NOMERGE:%.*]]
15 ; CHECK-NEXT: [[A:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ 0, [[COMMON:%.*]] ]
16 ; CHECK-NEXT: br label [[SUCC:%.*]]
18 ; CHECK-NEXT: [[B:%.*]] = phi i32 [ [[A]], [[BB_NOMERGE]] ], [ 2, [[COMMON]] ]
19 ; CHECK-NEXT: [[CONDE:%.*]] = call i1 @foo()
20 ; CHECK-NEXT: br i1 [[CONDE]], label [[COMMON]], label [[EXIT:%.*]]
22 ; CHECK-NEXT: [[COND:%.*]] = call i1 @foo()
23 ; CHECK-NEXT: br i1 [[COND]], label [[BB_NOMERGE]], label [[SUCC]]
25 ; CHECK-NEXT: ret void
30 BB.nomerge: ; preds = %Common, %entry
31 ; This phi has a conflicting value (0) with below phi (2), so blocks
33 %a = phi i32 [ 1, %entry ], [ 0, %Common ] ; <i32> [#uses=1]
36 Succ: ; preds = %Common, %BB.nomerge
37 %b = phi i32 [ %a, %BB.nomerge ], [ 2, %Common ] ; <i32> [#uses=0]
38 %conde = call i1 @foo( ) ; <i1> [#uses=1]
39 br i1 %conde, label %Common, label %Exit
41 Common: ; preds = %Succ
42 %cond = call i1 @foo( ) ; <i1> [#uses=1]
43 br i1 %cond, label %BB.nomerge, label %Succ
49 ; This function can't be merged
53 ; CHECK-NEXT: br label [[BB_NOMERGE:%.*]]
55 ; CHECK-NEXT: br label [[SUCC:%.*]]
57 ; CHECK-NEXT: [[B:%.*]] = phi i32 [ 1, [[BB_NOMERGE]] ], [ 2, [[COMMON:%.*]] ]
58 ; CHECK-NEXT: [[CONDE:%.*]] = call i1 @foo()
59 ; CHECK-NEXT: br i1 [[CONDE]], label [[COMMON]], label [[EXIT:%.*]]
61 ; CHECK-NEXT: [[COND:%.*]] = call i1 @foo()
62 ; CHECK-NEXT: br i1 [[COND]], label [[BB_NOMERGE]], label [[SUCC]]
64 ; CHECK-NEXT: ret void
69 BB.nomerge: ; preds = %Common, %entry
72 Succ: ; preds = %Common, %BB.nomerge
73 ; This phi has confliction values for Common and (through BB) Common,
74 ; blocks can't be merged
75 %b = phi i32 [ 1, %BB.nomerge ], [ 2, %Common ] ; <i32> [#uses=0]
76 %conde = call i1 @foo( ) ; <i1> [#uses=1]
77 br i1 %conde, label %Common, label %Exit
79 Common: ; preds = %Succ
80 %cond = call i1 @foo( ) ; <i1> [#uses=1]
81 br i1 %cond, label %BB.nomerge, label %Succ
87 ; This function can't be merged (for keeping canonical loop structures)
91 ; CHECK-NEXT: br label [[BB_NOMERGE:%.*]]
93 ; CHECK-NEXT: br label [[SUCC:%.*]]
95 ; CHECK-NEXT: [[B:%.*]] = phi i32 [ 1, [[BB_NOMERGE]] ], [ 1, [[COMMON:%.*]] ], [ 2, [[PRE_EXIT:%.*]] ]
96 ; CHECK-NEXT: [[CONDE:%.*]] = call i1 @foo()
97 ; CHECK-NEXT: br i1 [[CONDE]], label [[COMMON]], label [[PRE_EXIT]]
99 ; CHECK-NEXT: [[COND:%.*]] = call i1 @foo()
100 ; CHECK-NEXT: br i1 [[COND]], label [[BB_NOMERGE]], label [[SUCC]]
102 ; CHECK-NEXT: [[COND2:%.*]] = call i1 @foo()
103 ; CHECK-NEXT: br i1 [[COND2]], label [[SUCC]], label [[EXIT:%.*]]
105 ; CHECK-NEXT: ret void
110 BB.nomerge: ; preds = %Common, %entry
113 Succ: ; preds = %Common, %BB.tomerge, %Pre-Exit
114 ; This phi has identical values for Common and (through BB) Common,
115 ; blocks can't be merged
116 %b = phi i32 [ 1, %BB.nomerge ], [ 1, %Common ], [ 2, %Pre-Exit ]
117 %conde = call i1 @foo( ) ; <i1> [#uses=1]
118 br i1 %conde, label %Common, label %Pre-Exit
120 Common: ; preds = %Succ
121 %cond = call i1 @foo( ) ; <i1> [#uses=1]
122 br i1 %cond, label %BB.nomerge, label %Succ
124 Pre-Exit: ; preds = %Succ
125 ; This adds a backedge, so the %b phi node gets a third branch and is
126 ; not completely trivial
127 %cond2 = call i1 @foo( ) ; <i1> [#uses=1]
128 br i1 %cond2, label %Succ, label %Exit
130 Exit: ; preds = %Pre-Exit
134 ; This function can't be merged (for keeping canonical loop structures)
138 ; CHECK-NEXT: br label [[BB_NOMERGE:%.*]]
140 ; CHECK-NEXT: [[A:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ 0, [[COMMON:%.*]] ]
141 ; CHECK-NEXT: br label [[SUCC:%.*]]
143 ; CHECK-NEXT: [[B:%.*]] = phi i32 [ [[A]], [[BB_NOMERGE]] ], [ 0, [[COMMON]] ]
144 ; CHECK-NEXT: [[CONDE:%.*]] = call i1 @foo()
145 ; CHECK-NEXT: br i1 [[CONDE]], label [[COMMON]], label [[EXIT:%.*]]
147 ; CHECK-NEXT: [[COND:%.*]] = call i1 @foo()
148 ; CHECK-NEXT: br i1 [[COND]], label [[BB_NOMERGE]], label [[SUCC]]
150 ; CHECK-NEXT: ret void
155 BB.nomerge: ; preds = %Common, %entry
156 ; This phi has a matching value (0) with below phi (0), so blocks
158 %a = phi i32 [ 1, %entry ], [ 0, %Common ] ; <i32> [#uses=1]
161 Succ: ; preds = %Common, %BB.tomerge
162 %b = phi i32 [ %a, %BB.nomerge ], [ 0, %Common ] ; <i32> [#uses=0]
163 %conde = call i1 @foo( ) ; <i1> [#uses=1]
164 br i1 %conde, label %Common, label %Exit
166 Common: ; preds = %Succ
167 %cond = call i1 @foo( ) ; <i1> [#uses=1]
168 br i1 %cond, label %BB.nomerge, label %Succ
170 Exit: ; preds = %Succ
174 ; This function can be merged
178 ; CHECK-NEXT: br label [[SUCC:%.*]]
180 ; CHECK-NEXT: [[A:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ 0, [[USE:%.*]] ]
181 ; CHECK-NEXT: [[CONDE:%.*]] = call i1 @foo()
182 ; CHECK-NEXT: br i1 [[CONDE]], label [[USE]], label [[EXIT:%.*]]
184 ; CHECK-NEXT: [[COND:%.*]] = call i1 @bar(i32 [[A]])
185 ; CHECK-NEXT: br i1 [[COND]], label [[SUCC]], label [[EXIT]]
187 ; CHECK-NEXT: ret void
192 Succ: ; preds = %Use, %entry
193 ; This phi is used somewhere else than Succ, but this should not prevent
195 %a = phi i32 [ 1, %entry ], [ 0, %Use ] ; <i32> [#uses=1]
198 BB.tomerge: ; preds = %BB.tomerge
199 %conde = call i1 @foo( ) ; <i1> [#uses=1]
200 br i1 %conde, label %Use, label %Exit
203 %cond = call i1 @bar( i32 %a ) ; <i1> [#uses=1]
204 br i1 %cond, label %Succ, label %Exit
206 Exit: ; preds = %Use, %Succ