1 ; RUN: llc < %s -mtriple=arm-apple-darwin | FileCheck %s 2 3 define i32 @f(i32 %a, i32 %b) nounwind ssp { 4 entry: 5 ; CHECK-LABEL: f: 6 ; CHECK: subs 7 ; CHECK-NOT: cmp 8 %cmp = icmp sgt i32 %a, %b 9 %sub = sub nsw i32 %a, %b 10 %sub. = select i1 %cmp, i32 %sub, i32 0 11 ret i32 %sub. 12 } 13 14 define i32 @g(i32 %a, i32 %b) nounwind ssp { 15 entry: 16 ; CHECK-LABEL: g: 17 ; CHECK: subs 18 ; CHECK-NOT: cmp 19 %cmp = icmp slt i32 %a, %b 20 %sub = sub nsw i32 %b, %a 21 %sub. = select i1 %cmp, i32 %sub, i32 0 22 ret i32 %sub. 23 } 24 25 define i32 @h(i32 %a, i32 %b) nounwind ssp { 26 entry: 27 ; CHECK-LABEL: h: 28 ; CHECK: subs 29 ; CHECK-NOT: cmp 30 %cmp = icmp sgt i32 %a, 3 31 %sub = sub nsw i32 %a, 3 32 %sub. = select i1 %cmp, i32 %sub, i32 %b 33 ret i32 %sub. 34 } 35 36 ; rdar://11725965 37 define i32 @i(i32 %a, i32 %b) nounwind readnone ssp { 38 entry: 39 ; CHECK-LABEL: i: 40 ; CHECK: subs 41 ; CHECK-NOT: cmp 42 %cmp = icmp ult i32 %a, %b 43 %sub = sub i32 %b, %a 44 %sub. = select i1 %cmp, i32 %sub, i32 0 45 ret i32 %sub. 46 } 47 ; If CPSR is live-out, we can't remove cmp if there exists 48 ; a swapped sub. 49 define i32 @j(i32 %a, i32 %b) nounwind { 50 entry: 51 ; CHECK-LABEL: j: 52 ; CHECK: sub 53 ; CHECK: cmp 54 %cmp = icmp eq i32 %b, %a 55 %sub = sub nsw i32 %a, %b 56 br i1 %cmp, label %if.then, label %if.else 57 58 if.then: 59 %cmp2 = icmp sgt i32 %b, %a 60 %sel = select i1 %cmp2, i32 %sub, i32 %a 61 ret i32 %sel 62 63 if.else: 64 ret i32 %sub 65 } 66 67 ; If the sub/rsb instruction is predicated, we can't use the flags. 68 ; <rdar://problem/12263428> 69 ; Test case from MultiSource/Benchmarks/Ptrdist/bc/number.s 70 ; CHECK: bc_raise 71 ; CHECK: rsbeq 72 ; CHECK: cmp 73 define i32 @bc_raise() nounwind ssp { 74 entry: 75 %val.2.i = select i1 undef, i32 0, i32 undef 76 %sub.i = sub nsw i32 0, %val.2.i 77 %retval.0.i = select i1 undef, i32 %val.2.i, i32 %sub.i 78 %cmp1 = icmp eq i32 %retval.0.i, 0 79 br i1 %cmp1, label %land.lhs.true, label %if.end11 80 81 land.lhs.true: ; preds = %num2long.exit 82 ret i32 17 83 84 if.end11: ; preds = %num2long.exit 85 ret i32 23 86 } 87