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: [[RES:%.*]] = select i1 [[CMP]], i32 [[V0]], i32 0
14 ; CHECK-NEXT: call void @sideeffect1()
15 ; CHECK-NEXT: ret i32 [[RES]]
18 call void @sideeffect0()
19 %cmp = icmp eq i32 %a, %b
20 br i1 %cmp, label %cond.true, label %end
27 %res = phi i32 [ %v0, %cond.true ], [ 0, %entry ]
28 call void @sideeffect1()
32 define i32 @predictably_taken(i32 %a, i32 %b, i32 %c, i32 %d) {
33 ; CHECK-LABEL: @predictably_taken(
35 ; CHECK-NEXT: call void @sideeffect0()
36 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], [[B:%.*]]
37 ; CHECK-NEXT: [[V0:%.*]] = add i32 [[C:%.*]], [[D:%.*]]
38 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[CMP]], i32 [[V0]], i32 0, !prof [[PROF0:![0-9]+]]
39 ; CHECK-NEXT: call void @sideeffect1()
40 ; CHECK-NEXT: ret i32 [[RES]]
43 call void @sideeffect0()
44 %cmp = icmp eq i32 %a, %b
45 br i1 %cmp, label %cond.true, label %end, !prof !0 ; likely branches to %cond.true
52 %res = phi i32 [ %v0, %cond.true ], [ 0, %entry ]
53 call void @sideeffect1()
57 define i32 @predictably_nontaken(i32 %a, i32 %b, i32 %c, i32 %d) {
58 ; CHECK-LABEL: @predictably_nontaken(
60 ; CHECK-NEXT: call void @sideeffect0()
61 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], [[B:%.*]]
62 ; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[COND_TRUE:%.*]], !prof [[PROF0]]
64 ; CHECK-NEXT: [[V0:%.*]] = add i32 [[C:%.*]], [[D:%.*]]
65 ; CHECK-NEXT: br label [[END]]
67 ; CHECK-NEXT: [[RES:%.*]] = phi i32 [ [[V0]], [[COND_TRUE]] ], [ 0, [[ENTRY:%.*]] ]
68 ; CHECK-NEXT: call void @sideeffect1()
69 ; CHECK-NEXT: ret i32 [[RES]]
72 call void @sideeffect0()
73 %cmp = icmp eq i32 %a, %b
74 br i1 %cmp, label %end, label %cond.true, !prof !0 ; likely branches to %end
81 %res = phi i32 [ %v0, %cond.true ], [ 0, %entry ]
82 call void @sideeffect1()
86 define i32 @almost_predictably_nontaken(i32 %a, i32 %b, i32 %c, i32 %d) {
87 ; CHECK-LABEL: @almost_predictably_nontaken(
89 ; CHECK-NEXT: call void @sideeffect0()
90 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], [[B:%.*]]
91 ; CHECK-NEXT: [[V0:%.*]] = add i32 [[C:%.*]], [[D:%.*]]
92 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[CMP]], i32 0, i32 [[V0]], !prof [[PROF1:![0-9]+]]
93 ; CHECK-NEXT: call void @sideeffect1()
94 ; CHECK-NEXT: ret i32 [[RES]]
97 call void @sideeffect0()
98 %cmp = icmp eq i32 %a, %b
99 br i1 %cmp, label %end, label %cond.true, !prof !1 ; probably likely branches to %end
106 %res = phi i32 [ %v0, %cond.true ], [ 0, %entry ]
107 call void @sideeffect1()
111 define i32 @unpredictable(i32 %a, i32 %b, i32 %c, i32 %d) {
112 ; CHECK-LABEL: @unpredictable(
114 ; CHECK-NEXT: call void @sideeffect0()
115 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], [[B:%.*]]
116 ; CHECK-NEXT: [[V0:%.*]] = add i32 [[C:%.*]], [[D:%.*]]
117 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[CMP]], i32 [[V0]], i32 0, !unpredictable [[META2:![0-9]+]]
118 ; CHECK-NEXT: call void @sideeffect1()
119 ; CHECK-NEXT: ret i32 [[RES]]
122 call void @sideeffect0()
123 %cmp = icmp eq i32 %a, %b
124 br i1 %cmp, label %cond.true, label %end, !unpredictable !2 ; unpredictable
131 %res = phi i32 [ %v0, %cond.true ], [ 0, %entry ]
132 call void @sideeffect1()
136 define i32 @unpredictable_yet_taken(i32 %a, i32 %b, i32 %c, i32 %d) {
137 ; CHECK-LABEL: @unpredictable_yet_taken(
139 ; CHECK-NEXT: call void @sideeffect0()
140 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], [[B:%.*]]
141 ; CHECK-NEXT: [[V0:%.*]] = add i32 [[C:%.*]], [[D:%.*]]
142 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[CMP]], i32 [[V0]], i32 0, !prof [[PROF0]], !unpredictable [[META2]]
143 ; CHECK-NEXT: call void @sideeffect1()
144 ; CHECK-NEXT: ret i32 [[RES]]
147 call void @sideeffect0()
148 %cmp = icmp eq i32 %a, %b
149 br i1 %cmp, label %cond.true, label %end, !prof !0, !unpredictable !2 ; likely branches to %cond.true, yet unpredictable
156 %res = phi i32 [ %v0, %cond.true ], [ 0, %entry ]
157 call void @sideeffect1()
161 define i32 @unpredictable_yet_nontaken(i32 %a, i32 %b, i32 %c, i32 %d) {
162 ; CHECK-LABEL: @unpredictable_yet_nontaken(
164 ; CHECK-NEXT: call void @sideeffect0()
165 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], [[B:%.*]]
166 ; CHECK-NEXT: [[V0:%.*]] = add i32 [[C:%.*]], [[D:%.*]]
167 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[CMP]], i32 0, i32 [[V0]], !prof [[PROF0]], !unpredictable [[META2]]
168 ; CHECK-NEXT: call void @sideeffect1()
169 ; CHECK-NEXT: ret i32 [[RES]]
172 call void @sideeffect0()
173 %cmp = icmp eq i32 %a, %b
174 br i1 %cmp, label %end, label %cond.true, !prof !0, !unpredictable !2 ; likely branches to %end, yet unpredictable
181 %res = phi i32 [ %v0, %cond.true ], [ 0, %entry ]
182 call void @sideeffect1()
186 !0 = !{!"branch_weights", i32 99, i32 1}
187 !1 = !{!"branch_weights", i32 70, i32 1}
190 ; CHECK: !0 = !{!"branch_weights", i32 99, i32 1}
191 ; CHECK: !1 = !{!"branch_weights", i32 70, i32 1}