1 ; RUN: llc < %s -march=x86 -mcpu=pentiumpro -verify-machineinstrs | FileCheck %s
3 define i32 @func_f(i32 %X) {
7 %tmp1 = add i32 %X, 1 ; <i32> [#uses=1]
8 %tmp = icmp slt i32 %tmp1, 0 ; <i1> [#uses=1]
9 br i1 %tmp, label %cond_true, label %cond_next
11 cond_true: ; preds = %entry
12 %tmp2 = tail call i32 (...)* @bar( ) ; <i32> [#uses=0]
15 cond_next: ; preds = %cond_true, %entry
16 %tmp3 = tail call i32 (...)* @baz( ) ; <i32> [#uses=0]
26 define i32 @func_g(i32 %a, i32 %b) nounwind {
28 ; CHECK-LABEL: func_g:
31 %sub = sub nsw i32 %a, %b
32 %cmp = icmp sgt i32 %sub, 0
33 %cond = select i1 %cmp, i32 %sub, i32 0
38 define i32 @func_h(i32 %a, i32 %b) nounwind {
40 ; CHECK-LABEL: func_h:
45 %cmp = icmp slt i32 %b, %a
46 %sub = sub nsw i32 %a, %b
47 %cond = select i1 %cmp, i32 %sub, i32 0
50 define i32 @func_i(i32 %a, i32 %b) nounwind {
52 ; CHECK-LABEL: func_i:
57 %cmp = icmp sgt i32 %a, %b
58 %sub = sub nsw i32 %a, %b
59 %cond = select i1 %cmp, i32 %sub, i32 0
62 define i32 @func_j(i32 %a, i32 %b) nounwind {
64 ; CHECK-LABEL: func_j:
69 %cmp = icmp ugt i32 %a, %b
71 %cond = select i1 %cmp, i32 %sub, i32 0
74 define i32 @func_k(i32 %a, i32 %b) nounwind {
76 ; CHECK-LABEL: func_k:
81 %cmp = icmp ult i32 %b, %a
83 %cond = select i1 %cmp, i32 %sub, i32 0
86 ; redundant cmp instruction
87 define i32 @func_l(i32 %a, i32 %b) nounwind {
89 ; CHECK-LABEL: func_l:
91 %cmp = icmp slt i32 %b, %a
92 %sub = sub nsw i32 %a, %b
93 %cond = select i1 %cmp, i32 %sub, i32 %a
96 define i32 @func_m(i32 %a, i32 %b) nounwind {
98 ; CHECK-LABEL: func_m:
100 %cmp = icmp sgt i32 %a, %b
101 %sub = sub nsw i32 %a, %b
102 %cond = select i1 %cmp, i32 %b, i32 %sub
105 ; If EFLAGS is live-out, we can't remove cmp if there exists
107 define i32 @func_l2(i32 %a, i32 %b) nounwind {
109 ; CHECK-LABEL: func_l2:
111 %cmp = icmp eq i32 %b, %a
112 %sub = sub nsw i32 %a, %b
113 br i1 %cmp, label %if.then, label %if.else
116 %cmp2 = icmp sgt i32 %b, %a
117 %sel = select i1 %cmp2, i32 %sub, i32 %a
123 define i32 @func_l3(i32 %a, i32 %b) nounwind {
125 ; CHECK-LABEL: func_l3:
129 %cmp = icmp sgt i32 %b, %a
130 %sub = sub nsw i32 %a, %b
131 br i1 %cmp, label %if.then, label %if.else
137 %add = add nsw i32 %sub, 1
141 ; When Movr0 is between sub and cmp, we need to move "Movr0" before sub.
142 define i32 @func_l4(i32 %a, i32 %b) nounwind {
144 ; CHECK-LABEL: func_l4:
148 %cmp = icmp sgt i32 %b, %a
149 %sub = sub i32 %a, %b
150 %.sub = select i1 %cmp, i32 0, i32 %sub
154 define i32 @func_n(i32 %x, i32 %y) nounwind {
156 ; CHECK-LABEL: func_n:
159 %sub = sub nsw i32 %x, %y
160 %cmp = icmp slt i32 %sub, 0
161 %y.x = select i1 %cmp, i32 %y, i32 %x
165 define void @func_o() nounwind uwtable {
167 %0 = load i16* undef, align 2
168 br i1 undef, label %if.then.i, label %if.end.i
170 if.then.i: ; preds = %entry
173 if.end.i: ; preds = %entry
174 br i1 undef, label %sw.bb, label %sw.default
176 sw.bb: ; preds = %if.end.i
177 br i1 undef, label %if.then44, label %if.end29
179 if.end29: ; preds = %sw.bb
180 ; CHECK-LABEL: func_o:
183 %cmp25 = icmp eq i16 %1, 0
184 %. = select i1 %cmp25, i16 2, i16 0
185 br i1 %cmp25, label %if.then44, label %sw.default
187 sw.default: ; preds = %if.end29, %if.end.i
188 br i1 undef, label %if.then.i96, label %if.else.i97
190 if.then.i96: ; preds = %sw.default
193 if.else.i97: ; preds = %sw.default
196 if.then44: ; preds = %if.end29, %sw.bb
197 %aModeRefSel.1.ph = phi i16 [ %., %if.end29 ], [ 3, %sw.bb ]
198 br i1 undef, label %if.then.i103, label %if.else.i104
200 if.then.i103: ; preds = %if.then44
203 if.else.i104: ; preds = %if.then44
207 define i32 @func_p(i32 %a, i32 %b) nounwind {
209 ; CHECK-LABEL: func_p:
212 %add = add nsw i32 %b, %a
213 %cmp = icmp sgt i32 %add, 0
214 %add. = select i1 %cmp, i32 %add, i32 0
218 ; If we have sub a, b and cmp b, a and the result of cmp is used
219 ; by sbb, we should not optimize cmp away.
220 define i32 @func_q(i32 %j.4, i32 %w, i32 %el) {
221 ; CHECK-LABEL: func_q:
224 %tmp532 = add i32 %j.4, %w
225 %tmp533 = icmp ugt i32 %tmp532, %el
226 %tmp534 = icmp ult i32 %w, %el
227 %or.cond = and i1 %tmp533, %tmp534
228 %tmp535 = sub i32 %el, %w
229 %j.5 = select i1 %or.cond, i32 %tmp535, i32 %j.4
233 define i8* @func_r(i8* %base, i32* nocapture %offset, i32 %size) nounwind {
235 ; CHECK-LABEL: func_r:
241 %0 = load i32* %offset, align 8
242 %cmp = icmp slt i32 %0, %size
243 br i1 %cmp, label %return, label %if.end
246 %sub = sub nsw i32 %0, %size
247 store i32 %sub, i32* %offset, align 8
248 %add.ptr = getelementptr inbounds i8* %base, i32 %sub
252 %retval.0 = phi i8* [ %add.ptr, %if.end ], [ null, %entry ]
256 ; Test optimizations of dec/inc.
257 define i32 @func_dec(i32 %a) nounwind {
259 ; CHECK-LABEL: func_dec:
263 %sub = sub nsw i32 %a, 1
264 %cmp = icmp sgt i32 %sub, 0
265 %cond = select i1 %cmp, i32 %sub, i32 0
269 define i32 @func_inc(i32 %a) nounwind {
271 ; CHECK-LABEL: func_inc:
275 %add = add nsw i32 %a, 1
276 %cmp = icmp sgt i32 %add, 0
277 %cond = select i1 %cmp, i32 %add, i32 0
282 @b = common global i32 0, align 4
283 @a = common global i32 0, align 4
284 define i32 @func_test1(i32 %p1) nounwind uwtable {
286 ; CHECK-LABEL: func_test1:
290 %0 = load i32* @b, align 4
291 %cmp = icmp ult i32 %0, %p1
292 %conv = zext i1 %cmp to i32
293 %1 = load i32* @a, align 4
294 %and = and i32 %conv, %1
295 %conv1 = trunc i32 %and to i8
296 %2 = urem i8 %conv1, 3
297 %tobool = icmp eq i8 %2, 0
298 br i1 %tobool, label %if.end, label %if.then
301 %dec = add nsw i32 %1, -1
302 store i32 %dec, i32* @a, align 4