1 ; RUN: llc < %s -mtriple=arm-apple-darwin | FileCheck %s
2 ; RUN: llc < %s -mtriple=arm-apple-darwin | FileCheck %s --check-prefix=V7
3 ; RUN: llc < %s -mtriple=armv8-none-linux-gnueabi | FileCheck %s -check-prefix=V8
6 define i32 @f(i32 %a, i32 %b) nounwind ssp {
11 %cmp = icmp sgt i32 %a, %b
12 %sub = sub nsw i32 %a, %b
13 %sub. = select i1 %cmp, i32 %sub, i32 0
17 define i32 @g(i32 %a, i32 %b) nounwind ssp {
22 %cmp = icmp slt i32 %a, %b
23 %sub = sub nsw i32 %b, %a
24 %sub. = select i1 %cmp, i32 %sub, i32 0
28 define i32 @h(i32 %a, i32 %b) nounwind ssp {
33 %cmp = icmp sgt i32 %a, 3
34 %sub = sub nsw i32 %a, 3
35 %sub. = select i1 %cmp, i32 %sub, i32 %b
40 define i32 @i(i32 %a, i32 %b) nounwind readnone ssp {
45 %cmp = icmp ult i32 %a, %b
47 %sub. = select i1 %cmp, i32 %sub, i32 0
50 ; If CPSR is live-out, we can't remove cmp if there exists
52 define i32 @j(i32 %a, i32 %b) nounwind {
57 %cmp = icmp eq i32 %b, %a
58 %sub = sub nsw i32 %a, %b
59 br i1 %cmp, label %if.then, label %if.else
62 %cmp2 = icmp sgt i32 %b, %a
63 %sel = select i1 %cmp2, i32 %sub, i32 %a
70 ; If the sub/rsb instruction is predicated, we can't use the flags.
71 ; <rdar://problem/12263428>
72 ; Test case from MultiSource/Benchmarks/Ptrdist/bc/number.s
76 define i32 @bc_raise(i1 %cond) nounwind ssp {
78 %val.2.i = select i1 %cond, i32 0, i32 1
79 %sub.i = sub nsw i32 0, %val.2.i
80 %retval.0.i = select i1 %cond, i32 %val.2.i, i32 %sub.i
81 %cmp1 = icmp eq i32 %retval.0.i, 0
82 br i1 %cmp1, label %land.lhs.true, label %if.end11
84 land.lhs.true: ; preds = %num2long.exit
87 if.end11: ; preds = %num2long.exit
91 ; When considering the producer of cmp's src as the subsuming instruction,
92 ; only consider that when the comparison is to 0.
93 define i32 @cmp_src_nonzero(i32 %a, i32 %b, i32 %x, i32 %y) {
95 ; CHECK-LABEL: cmp_src_nonzero:
99 %cmp = icmp eq i32 %sub, 17
100 %ret = select i1 %cmp, i32 %x, i32 %y
104 define float @float_sel(i32 %a, i32 %b, float %x, float %y) {
106 ; CHECK-LABEL: float_sel:
108 ; V8-LABEL: float_sel:
111 %sub = sub i32 %a, %b
112 %cmp = icmp eq i32 %sub, 0
113 %ret = select i1 %cmp, float %x, float %y
117 define double @double_sel(i32 %a, i32 %b, double %x, double %y) {
119 ; CHECK-LABEL: double_sel:
121 ; V8-LABEL: double_sel:
124 %sub = sub i32 %a, %b
125 %cmp = icmp eq i32 %sub, 0
126 %ret = select i1 %cmp, double %x, double %y
130 @t = common global i32 0
131 define double @double_sub(i32 %a, i32 %b, double %x, double %y) {
133 ; CHECK-LABEL: double_sub:
136 ; V8-LABEL: double_sub:
138 %cmp = icmp sgt i32 %a, %b
139 %sub = sub i32 %a, %b
140 store i32 %sub, i32* @t
141 %ret = select i1 %cmp, double %x, double %y
145 define double @double_sub_swap(i32 %a, i32 %b, double %x, double %y) {
147 ; V7-LABEL: double_sub_swap:
150 ; V8-LABEL: double_sub_swap:
154 %cmp = icmp sgt i32 %a, %b
155 %sub = sub i32 %b, %a
156 %ret = select i1 %cmp, double %x, double %y
157 store i32 %sub, i32* @t
161 declare void @abort()
162 declare void @exit(i32)
164 ; If the comparison uses the V bit (signed overflow/underflow), we can't
165 ; omit the comparison.
166 define i32 @cmp_slt0(i32 %a, i32 %b, i32 %x, i32 %y) {
168 ; CHECK-LABEL: cmp_slt0
172 %load = load i32, i32* @t, align 4
173 %sub = sub i32 %load, 17
174 %cmp = icmp slt i32 %sub, 0
175 br i1 %cmp, label %if.then, label %if.else
182 call void @exit(i32 0)
186 ; Same for the C bit. (Note the ult X, 0 is trivially
187 ; false, so the DAG combiner may or may not optimize it).
188 define i32 @cmp_ult0(i32 %a, i32 %b, i32 %x, i32 %y) {
190 ; CHECK-LABEL: cmp_ult0
194 %load = load i32, i32* @t, align 4
195 %sub = sub i32 %load, 17
196 %cmp = icmp ult i32 %sub, 0
197 br i1 %cmp, label %if.then, label %if.else
204 call void @exit(i32 0)