1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -two-entry-phi-node-folding-threshold=4 -phi-node-folding-threshold=0 < %s | FileCheck %s
4 declare void @sideeffect0()
5 declare void @sideeffect1()
7 define i32 @unknown(i32 %a, i32 %b, i32 %c, i32 %d) {
8 ; CHECK-LABEL: @unknown(
10 ; CHECK-NEXT: call void @sideeffect0()
11 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], [[B:%.*]]
12 ; CHECK-NEXT: [[V0:%.*]] = add i32 [[C:%.*]], [[D:%.*]]
13 ; CHECK-NEXT: [[V1:%.*]] = sub i32 [[C]], [[D]]
14 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[CMP]], i32 [[V0]], i32 [[V1]]
15 ; CHECK-NEXT: call void @sideeffect1()
16 ; CHECK-NEXT: ret i32 [[RES]]
19 call void @sideeffect0()
20 %cmp = icmp eq i32 %a, %b
21 br i1 %cmp, label %cond.true, label %cond.false
32 %res = phi i32 [ %v0, %cond.true ], [ %v1, %cond.false ]
33 call void @sideeffect1()
37 define i32 @predictably_taken(i32 %a, i32 %b, i32 %c, i32 %d) {
38 ; CHECK-LABEL: @predictably_taken(
40 ; CHECK-NEXT: call void @sideeffect0()
41 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], [[B:%.*]]
42 ; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]], !prof [[PROF0:![0-9]+]]
44 ; CHECK-NEXT: [[V0:%.*]] = add i32 [[C:%.*]], [[D:%.*]]
45 ; CHECK-NEXT: br label [[END:%.*]]
47 ; CHECK-NEXT: [[V1:%.*]] = sub i32 [[C]], [[D]]
48 ; CHECK-NEXT: br label [[END]]
50 ; CHECK-NEXT: [[RES:%.*]] = phi i32 [ [[V0]], [[COND_TRUE]] ], [ [[V1]], [[COND_FALSE]] ]
51 ; CHECK-NEXT: call void @sideeffect1()
52 ; CHECK-NEXT: ret i32 [[RES]]
55 call void @sideeffect0()
56 %cmp = icmp eq i32 %a, %b
57 br i1 %cmp, label %cond.true, label %cond.false, !prof !0 ; likely branches to %cond.true
68 %res = phi i32 [ %v0, %cond.true ], [ %v1, %cond.false ]
69 call void @sideeffect1()
73 define i32 @almost_predictably_taken(i32 %a, i32 %b, i32 %c, i32 %d) {
74 ; CHECK-LABEL: @almost_predictably_taken(
76 ; CHECK-NEXT: call void @sideeffect0()
77 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], [[B:%.*]]
78 ; CHECK-NEXT: [[V0:%.*]] = add i32 [[C:%.*]], [[D:%.*]]
79 ; CHECK-NEXT: [[V1:%.*]] = sub i32 [[C]], [[D]]
80 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[CMP]], i32 [[V0]], i32 [[V1]], !prof [[PROF1:![0-9]+]]
81 ; CHECK-NEXT: call void @sideeffect1()
82 ; CHECK-NEXT: ret i32 [[RES]]
85 call void @sideeffect0()
86 %cmp = icmp eq i32 %a, %b
87 br i1 %cmp, label %cond.true, label %cond.false, !prof !1 ; almost likely branches to %cond.true
98 %res = phi i32 [ %v0, %cond.true ], [ %v1, %cond.false ]
99 call void @sideeffect1()
103 define i32 @predictably_nontaken(i32 %a, i32 %b, i32 %c, i32 %d) {
104 ; CHECK-LABEL: @predictably_nontaken(
106 ; CHECK-NEXT: call void @sideeffect0()
107 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], [[B:%.*]]
108 ; CHECK-NEXT: br i1 [[CMP]], label [[COND_FALSE:%.*]], label [[COND_TRUE:%.*]], !prof [[PROF0]]
110 ; CHECK-NEXT: [[V0:%.*]] = add i32 [[C:%.*]], [[D:%.*]]
111 ; CHECK-NEXT: br label [[END:%.*]]
113 ; CHECK-NEXT: [[V1:%.*]] = sub i32 [[C]], [[D]]
114 ; CHECK-NEXT: br label [[END]]
116 ; CHECK-NEXT: [[RES:%.*]] = phi i32 [ [[V0]], [[COND_TRUE]] ], [ [[V1]], [[COND_FALSE]] ]
117 ; CHECK-NEXT: call void @sideeffect1()
118 ; CHECK-NEXT: ret i32 [[RES]]
121 call void @sideeffect0()
122 %cmp = icmp eq i32 %a, %b
123 br i1 %cmp, label %cond.false, label %cond.true, !prof !0 ; likely branches to %cond.false
134 %res = phi i32 [ %v0, %cond.true ], [ %v1, %cond.false ]
135 call void @sideeffect1()
139 define i32 @almost_predictably_nontaken(i32 %a, i32 %b, i32 %c, i32 %d) {
140 ; CHECK-LABEL: @almost_predictably_nontaken(
142 ; CHECK-NEXT: call void @sideeffect0()
143 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], [[B:%.*]]
144 ; CHECK-NEXT: [[V0:%.*]] = add i32 [[C:%.*]], [[D:%.*]]
145 ; CHECK-NEXT: [[V1:%.*]] = sub i32 [[C]], [[D]]
146 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[CMP]], i32 [[V1]], i32 [[V0]], !prof [[PROF1]]
147 ; CHECK-NEXT: call void @sideeffect1()
148 ; CHECK-NEXT: ret i32 [[RES]]
151 call void @sideeffect0()
152 %cmp = icmp eq i32 %a, %b
153 br i1 %cmp, label %cond.false, label %cond.true, !prof !1 ; probably likely branches to %cond.false
164 %res = phi i32 [ %v0, %cond.true ], [ %v1, %cond.false ]
165 call void @sideeffect1()
169 define i32 @unpredictable(i32 %a, i32 %b, i32 %c, i32 %d) {
170 ; CHECK-LABEL: @unpredictable(
172 ; CHECK-NEXT: call void @sideeffect0()
173 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], [[B:%.*]]
174 ; CHECK-NEXT: [[V0:%.*]] = add i32 [[C:%.*]], [[D:%.*]]
175 ; CHECK-NEXT: [[V1:%.*]] = sub i32 [[C]], [[D]]
176 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[CMP]], i32 [[V0]], i32 [[V1]], !unpredictable [[META2:![0-9]+]]
177 ; CHECK-NEXT: call void @sideeffect1()
178 ; CHECK-NEXT: ret i32 [[RES]]
181 call void @sideeffect0()
182 %cmp = icmp eq i32 %a, %b
183 br i1 %cmp, label %cond.true, label %cond.false, !unpredictable !2 ; unpredictable
194 %res = phi i32 [ %v0, %cond.true ], [ %v1, %cond.false ]
195 call void @sideeffect1()
199 define i32 @unpredictable_yet_taken(i32 %a, i32 %b, i32 %c, i32 %d) {
200 ; CHECK-LABEL: @unpredictable_yet_taken(
202 ; CHECK-NEXT: call void @sideeffect0()
203 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], [[B:%.*]]
204 ; CHECK-NEXT: [[V0:%.*]] = add i32 [[C:%.*]], [[D:%.*]]
205 ; CHECK-NEXT: [[V1:%.*]] = sub i32 [[C]], [[D]]
206 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[CMP]], i32 [[V0]], i32 [[V1]], !prof [[PROF0]], !unpredictable [[META2]]
207 ; CHECK-NEXT: call void @sideeffect1()
208 ; CHECK-NEXT: ret i32 [[RES]]
211 call void @sideeffect0()
212 %cmp = icmp eq i32 %a, %b
213 br i1 %cmp, label %cond.true, label %cond.false, !prof !0, !unpredictable !2 ; likely branches to %cond.true, yet unpredictable
224 %res = phi i32 [ %v0, %cond.true ], [ %v1, %cond.false ]
225 call void @sideeffect1()
229 define i32 @unpredictable_yet_nontaken(i32 %a, i32 %b, i32 %c, i32 %d) {
230 ; CHECK-LABEL: @unpredictable_yet_nontaken(
232 ; CHECK-NEXT: call void @sideeffect0()
233 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], [[B:%.*]]
234 ; CHECK-NEXT: [[V0:%.*]] = add i32 [[C:%.*]], [[D:%.*]]
235 ; CHECK-NEXT: [[V1:%.*]] = sub i32 [[C]], [[D]]
236 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[CMP]], i32 [[V1]], i32 [[V0]], !prof [[PROF0]], !unpredictable [[META2]]
237 ; CHECK-NEXT: call void @sideeffect1()
238 ; CHECK-NEXT: ret i32 [[RES]]
241 call void @sideeffect0()
242 %cmp = icmp eq i32 %a, %b
243 br i1 %cmp, label %cond.false, label %cond.true, !prof !0, !unpredictable !2 ; likely branches to %cond.false, yet unpredictable
254 %res = phi i32 [ %v0, %cond.true ], [ %v1, %cond.false ]
255 call void @sideeffect1()
259 !0 = !{!"branch_weights", i32 99, i32 1}
260 !1 = !{!"branch_weights", i32 70, i32 1}
263 ; CHECK: !0 = !{!"branch_weights", i32 99, i32 1}
264 ; CHECK: !1 = !{!"branch_weights", i32 70, i32 1}