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