1 ; RUN: opt -dfa-jump-threading -dfa-cost-threshold=25 -pass-remarks-missed='dfa-jump-threading' -pass-remarks-output=%t -disable-output %s
2 ; RUN: FileCheck --input-file %t --check-prefix=REMARK %s
3 ; RUN: opt -S -dfa-jump-threading %s | FileCheck %s
5 ; This negative test case checks that the optimization doesn't trigger
6 ; when the code size cost is too high.
7 define i32 @negative1(i32 %num) {
8 ; REMARK: NotProfitable
9 ; REMARK-NEXT: negative1
14 %count = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
15 %state = phi i32 [ 1, %entry ], [ %state.next, %for.inc ]
16 switch i32 %state, label %for.inc [
25 %cmp = icmp eq i32 %count, 50
26 %sel = select i1 %cmp, i32 1, i32 2
30 %state.next = phi i32 [ %sel, %case2 ], [ 1, %for.body ], [ 2, %case1 ]
31 %add1 = add i32 %num, %num
32 %add2 = add i32 %add1, %add1
33 %add3 = add i32 %add2, %add2
34 %add4 = add i32 %add3, %add3
35 %add5 = add i32 %add4, %add4
36 %add6 = add i32 %add5, %add5
37 %add7 = add i32 %add6, %add6
38 %add8 = add i32 %add7, %add7
39 %add9 = add i32 %add8, %add8
40 %add10 = add i32 %add9, %add9
41 %add11 = add i32 %add10, %add10
42 %add12 = add i32 %add11, %add11
43 %add13 = add i32 %add12, %add12
44 %add14 = add i32 %add13, %add13
45 %add15 = add i32 %add14, %add14
46 %add16 = add i32 %add15, %add15
47 %add17 = add i32 %add16, %add16
48 %add18 = add i32 %add17, %add17
49 %add19 = add i32 %add18, %add18
50 %add20 = add i32 %add19, %add19
51 %add21 = add i32 %add20, %add20
52 %add22 = add i32 %add21, %add21
53 %inc = add nsw i32 %count, 1
54 %cmp.exit = icmp slt i32 %inc, %num
55 br i1 %cmp.exit, label %for.body, label %for.end
63 define i32 @negative2(i32 %num) {
64 ; REMARK: NonDuplicatableInst
65 ; REMARK-NEXT: negative2
70 %count = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
71 %state = phi i32 [ 1, %entry ], [ %state.next, %for.inc ]
72 switch i32 %state, label %for.inc [
81 %cmp = icmp eq i32 %count, 50
82 %sel = select i1 %cmp, i32 1, i32 2
86 %state.next = phi i32 [ %sel, %case2 ], [ 1, %for.body ], [ 2, %case1 ]
87 call void @func() noduplicate
88 %inc = add nsw i32 %count, 1
89 %cmp.exit = icmp slt i32 %inc, %num
90 br i1 %cmp.exit, label %for.body, label %for.end
96 define i32 @negative3(i32 %num) {
97 ; REMARK: ConvergentInst
98 ; REMARK-NEXT: negative3
103 %count = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
104 %state = phi i32 [ 1, %entry ], [ %state.next, %for.inc ]
105 switch i32 %state, label %for.inc [
114 %cmp = icmp eq i32 %count, 50
115 %sel = select i1 %cmp, i32 1, i32 2
119 %state.next = phi i32 [ %sel, %case2 ], [ 1, %for.body ], [ 2, %case1 ]
120 call void @func() convergent
121 %inc = add nsw i32 %count, 1
122 %cmp.exit = icmp slt i32 %inc, %num
123 br i1 %cmp.exit, label %for.body, label %for.end
129 define i32 @negative4(i32 %num) {
130 ; REMARK: SwitchNotPredictable
131 ; REMARK-NEXT: negative4
136 %count = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
137 %state = phi i32 [ 1, %entry ], [ %state.next, %for.inc ]
138 switch i32 %state, label %for.inc [
147 %cmp = icmp eq i32 %count, 50
148 %sel = select i1 %cmp, i32 1, i32 2
152 ; the switch variable is not predictable since the exit value for %case1
153 ; is defined through a non-instruction (function argument).
154 %state.next = phi i32 [ %sel, %case2 ], [ 1, %for.body ], [ %num, %case1 ]
155 %inc = add nsw i32 %count, 1
156 %cmp.exit = icmp slt i32 %inc, %num
157 br i1 %cmp.exit, label %for.body, label %for.end
163 ; Do not optimize if marked minsize.
164 define i32 @negative5(i32 %num) minsize {
165 ; CHECK-LABEL: @negative5(
167 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
169 ; CHECK-NEXT: [[COUNT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
170 ; CHECK-NEXT: [[STATE:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[STATE_NEXT:%.*]], [[FOR_INC]] ]
171 ; CHECK-NEXT: switch i32 [[STATE]], label [[FOR_INC]] [
172 ; CHECK-NEXT: i32 1, label [[CASE1:%.*]]
173 ; CHECK-NEXT: i32 2, label [[CASE2:%.*]]
176 ; CHECK-NEXT: br label [[FOR_INC]]
178 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[COUNT]], 50
179 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 1, i32 2
180 ; CHECK-NEXT: br label [[FOR_INC]]
182 ; CHECK-NEXT: [[STATE_NEXT]] = phi i32 [ [[SEL]], [[CASE2]] ], [ 1, [[FOR_BODY]] ], [ 2, [[CASE1]] ]
183 ; CHECK-NEXT: [[INC]] = add nsw i32 [[COUNT]], 1
184 ; CHECK-NEXT: [[CMP_EXIT:%.*]] = icmp slt i32 [[INC]], [[NUM:%.*]]
185 ; CHECK-NEXT: br i1 [[CMP_EXIT]], label [[FOR_BODY]], label [[FOR_END:%.*]]
187 ; CHECK-NEXT: ret i32 0
193 %count = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
194 %state = phi i32 [ 1, %entry ], [ %state.next, %for.inc ]
195 switch i32 %state, label %for.inc [
204 %cmp = icmp eq i32 %count, 50
205 %sel = select i1 %cmp, i32 1, i32 2
209 %state.next = phi i32 [ %sel, %case2 ], [ 1, %for.body ], [ 2, %case1 ]
210 %inc = add nsw i32 %count, 1
211 %cmp.exit = icmp slt i32 %inc, %num
212 br i1 %cmp.exit, label %for.body, label %for.end