blob: f1e3c2772ac9e7b5eba67452aad318ac617417f3 [file] [log] [blame]
Dan Gohmancaf71ab2010-06-22 23:07:13 +00001; RUN: llc < %s -march=x86-64 -asm-verbose=false | FileCheck %s
Dan Gohman1d367982010-04-24 03:13:44 +00002
3; LSR's OptimizeMax should eliminate the select (max).
4
5; CHECK: foo:
6; CHECK-NOT: cmov
7; CHECK: jle
8
9define void @foo(i64 %n, double* nocapture %p) nounwind {
10entry:
11 %cmp6 = icmp slt i64 %n, 0 ; <i1> [#uses=1]
12 br i1 %cmp6, label %for.end, label %for.body.preheader
13
14for.body.preheader: ; preds = %entry
15 %tmp = icmp sgt i64 %n, 0 ; <i1> [#uses=1]
16 %n.op = add i64 %n, 1 ; <i64> [#uses=1]
17 %tmp1 = select i1 %tmp, i64 %n.op, i64 1 ; <i64> [#uses=1]
18 br label %for.body
19
20for.body: ; preds = %for.body.preheader, %for.body
21 %i = phi i64 [ %i.next, %for.body ], [ 0, %for.body.preheader ] ; <i64> [#uses=2]
22 %arrayidx = getelementptr double* %p, i64 %i ; <double*> [#uses=2]
23 %t4 = load double* %arrayidx ; <double> [#uses=1]
24 %mul = fmul double %t4, 2.200000e+00 ; <double> [#uses=1]
25 store double %mul, double* %arrayidx
26 %i.next = add nsw i64 %i, 1 ; <i64> [#uses=2]
27 %exitcond = icmp eq i64 %i.next, %tmp1 ; <i1> [#uses=1]
28 br i1 %exitcond, label %for.end, label %for.body
29
30for.end: ; preds = %for.body, %entry
31 ret void
32}
Dan Gohmancaf71ab2010-06-22 23:07:13 +000033
34; In this case, one of the max operands is another max, which folds,
35; leaving a two-operand max which doesn't fit the usual pattern.
36; OptimizeMax should handle this case.
37; PR7454
38
39; CHECK: _Z18GenerateStatusPagei:
40
41; CHECK: jle
Dan Gohmandd2fa4b2010-06-22 23:32:47 +000042; CHECK-NOT: cmov
43; CHECK: xorl %edi, %edi
Dan Gohmancaf71ab2010-06-22 23:07:13 +000044; CHECK-NEXT: align
45; CHECK-NEXT: BB1_2:
46; CHECK-NEXT: callq
47; CHECK-NEXT: incl %ebx
48; CHECK-NEXT: cmpl %r14d, %ebx
49; CHECK-NEXT: movq %rax, %rdi
50; CHECK-NEXT: jl
51
52define void @_Z18GenerateStatusPagei(i32 %jobs_to_display) nounwind {
53entry:
54 %cmp.i = icmp sgt i32 %jobs_to_display, 0 ; <i1> [#uses=1]
55 %tmp = select i1 %cmp.i, i32 %jobs_to_display, i32 0 ; <i32> [#uses=3]
56 %cmp8 = icmp sgt i32 %tmp, 0 ; <i1> [#uses=1]
57 br i1 %cmp8, label %bb.nph, label %for.end
58
59bb.nph: ; preds = %entry
60 %tmp11 = icmp sgt i32 %tmp, 1 ; <i1> [#uses=1]
61 %smax = select i1 %tmp11, i32 %tmp, i32 1 ; <i32> [#uses=1]
62 br label %for.body
63
64for.body: ; preds = %for.body, %bb.nph
65 %i.010 = phi i32 [ 0, %bb.nph ], [ %inc, %for.body ] ; <i32> [#uses=1]
66 %it.0.09 = phi float* [ null, %bb.nph ], [ %call.i, %for.body ] ; <float*> [#uses=1]
67 %call.i = call float* @_ZSt18_Rb_tree_decrementPKSt18_Rb_tree_node_base(float* %it.0.09) ; <float*> [#uses=1]
68 %inc = add nsw i32 %i.010, 1 ; <i32> [#uses=2]
69 %exitcond = icmp eq i32 %inc, %smax ; <i1> [#uses=1]
70 br i1 %exitcond, label %for.end, label %for.body
71
72for.end: ; preds = %for.body, %entry
73 ret void
74}
75
76declare float* @_ZSt18_Rb_tree_decrementPKSt18_Rb_tree_node_base(float*)