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