1*9880d681SAndroid Build Coastguard Worker; RUN: llc -mtriple=thumbv7-apple-ios -disable-block-placement < %s | FileCheck %s 2*9880d681SAndroid Build Coastguard Worker; RUN: llc -mtriple=armv7-apple-ios -disable-block-placement < %s | FileCheck %s 3*9880d681SAndroid Build Coastguard Worker 4*9880d681SAndroid Build Coastguard Worker; LLVM IR optimizers canonicalize icmp+select this way. 5*9880d681SAndroid Build Coastguard Worker; Make sure that TwoAddressInstructionPass can commute the corresponding 6*9880d681SAndroid Build Coastguard Worker; MOVCC instructions to avoid excessive copies in one of the if blocks. 7*9880d681SAndroid Build Coastguard Worker; 8*9880d681SAndroid Build Coastguard Worker; CHECK: %if.then 9*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: mov 10*9880d681SAndroid Build Coastguard Worker; CHECK: movlo 11*9880d681SAndroid Build Coastguard Worker; CHECK: movlo 12*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: mov 13*9880d681SAndroid Build Coastguard Worker 14*9880d681SAndroid Build Coastguard Worker; CHECK: %if.else 15*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: mov 16*9880d681SAndroid Build Coastguard Worker; CHECK: movls 17*9880d681SAndroid Build Coastguard Worker; CHECK: movls 18*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: mov 19*9880d681SAndroid Build Coastguard Worker 20*9880d681SAndroid Build Coastguard Worker; This is really an LSR test: Make sure that cmp is using the incremented 21*9880d681SAndroid Build Coastguard Worker; induction variable. 22*9880d681SAndroid Build Coastguard Worker; CHECK: %if.end8 23*9880d681SAndroid Build Coastguard Worker; CHECK: add{{(s|\.w)?}} [[IV:r[0-9]+]], {{.*}}#1 24*9880d681SAndroid Build Coastguard Worker; CHECK: cmp [[IV]], # 25*9880d681SAndroid Build Coastguard Worker 26*9880d681SAndroid Build Coastguard Workerdefine i32 @f(i32* nocapture %a, i32 %Pref) nounwind ssp { 27*9880d681SAndroid Build Coastguard Workerentry: 28*9880d681SAndroid Build Coastguard Worker br label %for.body 29*9880d681SAndroid Build Coastguard Worker 30*9880d681SAndroid Build Coastguard Workerfor.body: ; preds = %entry, %if.end8 31*9880d681SAndroid Build Coastguard Worker %i.012 = phi i32 [ 0, %entry ], [ %inc, %if.end8 ] 32*9880d681SAndroid Build Coastguard Worker %BestCost.011 = phi i32 [ -1, %entry ], [ %BestCost.1, %if.end8 ] 33*9880d681SAndroid Build Coastguard Worker %BestIdx.010 = phi i32 [ 0, %entry ], [ %BestIdx.1, %if.end8 ] 34*9880d681SAndroid Build Coastguard Worker %arrayidx = getelementptr inbounds i32, i32* %a, i32 %i.012 35*9880d681SAndroid Build Coastguard Worker %0 = load i32, i32* %arrayidx, align 4 36*9880d681SAndroid Build Coastguard Worker %mul = mul i32 %0, %0 37*9880d681SAndroid Build Coastguard Worker %sub = add nsw i32 %i.012, -5 38*9880d681SAndroid Build Coastguard Worker %cmp2 = icmp eq i32 %sub, %Pref 39*9880d681SAndroid Build Coastguard Worker br i1 %cmp2, label %if.else, label %if.then 40*9880d681SAndroid Build Coastguard Worker 41*9880d681SAndroid Build Coastguard Workerif.then: ; preds = %for.body 42*9880d681SAndroid Build Coastguard Worker %cmp3 = icmp ult i32 %mul, %BestCost.011 43*9880d681SAndroid Build Coastguard Worker %i.0.BestIdx.0 = select i1 %cmp3, i32 %i.012, i32 %BestIdx.010 44*9880d681SAndroid Build Coastguard Worker %mul.BestCost.0 = select i1 %cmp3, i32 %mul, i32 %BestCost.011 45*9880d681SAndroid Build Coastguard Worker br label %if.end8 46*9880d681SAndroid Build Coastguard Worker 47*9880d681SAndroid Build Coastguard Workerif.else: ; preds = %for.body 48*9880d681SAndroid Build Coastguard Worker %cmp5 = icmp ugt i32 %mul, %BestCost.011 49*9880d681SAndroid Build Coastguard Worker %BestIdx.0.i.0 = select i1 %cmp5, i32 %BestIdx.010, i32 %i.012 50*9880d681SAndroid Build Coastguard Worker %BestCost.0.mul = select i1 %cmp5, i32 %BestCost.011, i32 %mul 51*9880d681SAndroid Build Coastguard Worker br label %if.end8 52*9880d681SAndroid Build Coastguard Worker 53*9880d681SAndroid Build Coastguard Workerif.end8: ; preds = %if.else, %if.then 54*9880d681SAndroid Build Coastguard Worker %BestIdx.1 = phi i32 [ %i.0.BestIdx.0, %if.then ], [ %BestIdx.0.i.0, %if.else ] 55*9880d681SAndroid Build Coastguard Worker %BestCost.1 = phi i32 [ %mul.BestCost.0, %if.then ], [ %BestCost.0.mul, %if.else ] 56*9880d681SAndroid Build Coastguard Worker store i32 %mul, i32* %arrayidx, align 4 57*9880d681SAndroid Build Coastguard Worker %inc = add i32 %i.012, 1 58*9880d681SAndroid Build Coastguard Worker %cmp = icmp eq i32 %inc, 11 59*9880d681SAndroid Build Coastguard Worker br i1 %cmp, label %for.end, label %for.body 60*9880d681SAndroid Build Coastguard Worker 61*9880d681SAndroid Build Coastguard Workerfor.end: ; preds = %if.end8 62*9880d681SAndroid Build Coastguard Worker ret i32 %BestIdx.1 63*9880d681SAndroid Build Coastguard Worker} 64