1 ; RUN: llc -mtriple=thumbv7-apple-ios -disable-block-placement < %s | FileCheck %s
2 ; RUN: llc -mtriple=armv7-apple-ios -disable-block-placement < %s | FileCheck %s
4 ; LLVM IR optimizers canonicalize icmp+select this way.
5 ; Make sure that TwoAddressInstructionPass can commute the corresponding
6 ; MOVCC instructions to avoid excessive copies in one of the if blocks.
20 ; This is really an LSR test: Make sure that cmp is using the incremented
23 ; CHECK: add{{(s|\.w)?}} [[IV:r[0-9]+]], {{.*}}#1
24 ; CHECK: cmp [[IV]], #
26 define i32 @f(ptr nocapture %a, i32 %Pref) nounwind ssp {
30 for.body: ; preds = %entry, %if.end8
31 %i.012 = phi i32 [ 0, %entry ], [ %inc, %if.end8 ]
32 %BestCost.011 = phi i32 [ -1, %entry ], [ %BestCost.1, %if.end8 ]
33 %BestIdx.010 = phi i32 [ 0, %entry ], [ %BestIdx.1, %if.end8 ]
34 %arrayidx = getelementptr inbounds i32, ptr %a, i32 %i.012
35 %0 = load i32, ptr %arrayidx, align 4
37 %sub = add nsw i32 %i.012, -5
38 %cmp2 = icmp eq i32 %sub, %Pref
39 br i1 %cmp2, label %if.else, label %if.then
41 if.then: ; preds = %for.body
42 %cmp3 = icmp ult i32 %mul, %BestCost.011
43 %i.0.BestIdx.0 = select i1 %cmp3, i32 %i.012, i32 %BestIdx.010
44 %mul.BestCost.0 = select i1 %cmp3, i32 %mul, i32 %BestCost.011
47 if.else: ; preds = %for.body
48 %cmp5 = icmp ugt i32 %mul, %BestCost.011
49 %BestIdx.0.i.0 = select i1 %cmp5, i32 %BestIdx.010, i32 %i.012
50 %BestCost.0.mul = select i1 %cmp5, i32 %BestCost.011, i32 %mul
53 if.end8: ; preds = %if.else, %if.then
54 %BestIdx.1 = phi i32 [ %i.0.BestIdx.0, %if.then ], [ %BestIdx.0.i.0, %if.else ]
55 %BestCost.1 = phi i32 [ %mul.BestCost.0, %if.then ], [ %BestCost.0.mul, %if.else ]
56 store i32 %mul, ptr %arrayidx, align 4
57 %inc = add i32 %i.012, 1
58 %cmp = icmp eq i32 %inc, 11
59 br i1 %cmp, label %for.end, label %for.body
61 for.end: ; preds = %if.end8