1 ; RUN: llc -O3 < %s | FileCheck %s
2 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-n32:64"
3 target triple = "arm64-unknown-unknown"
6 ; CHECK: cinc w{{[0-9]+}}, w{{[0-9]+}}, ne
7 define i32 @foo1(i32 %b, i32 %c) nounwind readnone ssp {
9 %not.tobool = icmp ne i32 %c, 0
10 %add = zext i1 %not.tobool to i32
11 %b.add = add i32 %c, %b
12 %add1 = add i32 %b.add, %add
17 ; CHECK: cneg w{{[0-9]+}}, w{{[0-9]+}}, ne
18 define i32 @foo2(i32 %b, i32 %c) nounwind readnone ssp {
21 %tobool = icmp eq i32 %c, 0
22 %b.mul = select i1 %tobool, i32 %b, i32 %mul
23 %add = add nsw i32 %b.mul, %c
28 ; CHECK: cinv w{{[0-9]+}}, w{{[0-9]+}}, ne
29 define i32 @foo3(i32 %b, i32 %c) nounwind readnone ssp {
31 %not.tobool = icmp ne i32 %c, 0
32 %xor = sext i1 %not.tobool to i32
33 %b.xor = xor i32 %xor, %b
34 %add = add nsw i32 %b.xor, %c
39 define i32@foo4(i32 %a) nounwind ssp {
43 %cmp = icmp sgt i32 %a, -1
44 %neg = sub nsw i32 0, %a
45 %cond = select i1 %cmp, i32 %a, i32 %neg
49 define i32@foo5(i32 %a, i32 %b) nounwind ssp {
55 %sub = sub nsw i32 %a, %b
56 %cmp = icmp sgt i32 %sub, -1
57 %sub3 = sub nsw i32 0, %sub
58 %cond = select i1 %cmp, i32 %sub, i32 %sub3
62 ; make sure we can handle branch instruction in optimizeCompare.
63 define i32@foo6(i32 %a, i32 %b) nounwind ssp {
66 %sub = sub nsw i32 %a, %b
67 %cmp = icmp sgt i32 %sub, 0
68 br i1 %cmp, label %l.if, label %l.else
77 ; If CPSR is used multiple times and V flag is used, we don't remove cmp.
78 define i32 @foo7(i32 %a, i32 %b) nounwind {
82 ; FIXME: Misspelled CHECK-NEXT
86 %sub = sub nsw i32 %a, %b
87 %cmp = icmp sgt i32 %sub, -1
88 %sub3 = sub nsw i32 0, %sub
89 %cond = select i1 %cmp, i32 %sub, i32 %sub3
90 br i1 %cmp, label %if.then, label %if.else
93 %cmp2 = icmp slt i32 %sub, -1
94 %sel = select i1 %cmp2, i32 %cond, i32 %a
101 define i32 @foo8(i32 %v, i32 %a, i32 %b) nounwind readnone ssp {
105 ; CHECK: csinv w0, w1, w2, ne
106 %tobool = icmp eq i32 %v, 0
107 %neg = xor i32 -1, %b
108 %cond = select i1 %tobool, i32 %neg, i32 %a
112 define i32 @foo9(i32 %v) nounwind readnone optsize ssp {
116 ; CHECK: mov w[[REG:[0-9]+]], #4
117 ; CHECK: cinv w0, w[[REG]], eq
118 %tobool = icmp ne i32 %v, 0
119 %cond = select i1 %tobool, i32 4, i32 -5
123 define i64 @foo10(i64 %v) nounwind readnone optsize ssp {
125 ; CHECK-LABEL: foo10:
127 ; CHECK: mov w[[REG:[0-9]+]], #4
128 ; CHECK: cinv x0, x[[REG]], eq
129 %tobool = icmp ne i64 %v, 0
130 %cond = select i1 %tobool, i64 4, i64 -5
134 define i32 @foo11(i32 %v) nounwind readnone optsize ssp {
136 ; CHECK-LABEL: foo11:
138 ; CHECK: mov w[[REG:[0-9]+]], #4
139 ; CHECK: cneg w0, w[[REG]], eq
140 %tobool = icmp ne i32 %v, 0
141 %cond = select i1 %tobool, i32 4, i32 -4
145 define i64 @foo12(i64 %v) nounwind readnone optsize ssp {
147 ; CHECK-LABEL: foo12:
149 ; CHECK: mov w[[REG:[0-9]+]], #4
150 ; CHECK: cneg x0, x[[REG]], eq
151 %tobool = icmp ne i64 %v, 0
152 %cond = select i1 %tobool, i64 4, i64 -4
156 define i32 @foo13(i32 %v, i32 %a, i32 %b) nounwind readnone optsize ssp {
158 ; CHECK-LABEL: foo13:
160 ; CHECK: csneg w0, w1, w2, ne
161 %tobool = icmp eq i32 %v, 0
163 %cond = select i1 %tobool, i32 %sub, i32 %a
167 define i64 @foo14(i64 %v, i64 %a, i64 %b) nounwind readnone optsize ssp {
169 ; CHECK-LABEL: foo14:
171 ; CHECK: csneg x0, x1, x2, ne
172 %tobool = icmp eq i64 %v, 0
174 %cond = select i1 %tobool, i64 %sub, i64 %a
178 define i32 @foo15(i32 %a, i32 %b) nounwind readnone optsize ssp {
180 ; CHECK-LABEL: foo15:
182 ; CHECK: mov w[[REG:[0-9]+]], #1
183 ; CHECK: cinc w0, w[[REG]], gt
184 %cmp = icmp sgt i32 %a, %b
185 %. = select i1 %cmp, i32 2, i32 1
189 define i32 @foo16(i32 %a, i32 %b) nounwind readnone optsize ssp {
191 ; CHECK-LABEL: foo16:
193 ; CHECK: mov w[[REG:[0-9]+]], #1
194 ; CHECK: cinc w0, w[[REG]], le
195 %cmp = icmp sgt i32 %a, %b
196 %. = select i1 %cmp, i32 1, i32 2
200 define i64 @foo17(i64 %a, i64 %b) nounwind readnone optsize ssp {
202 ; CHECK-LABEL: foo17:
204 ; CHECK: mov w[[REG:[0-9]+]], #1
205 ; CHECK: cinc x0, x[[REG]], gt
206 %cmp = icmp sgt i64 %a, %b
207 %. = select i1 %cmp, i64 2, i64 1
211 define i64 @foo18(i64 %a, i64 %b) nounwind readnone optsize ssp {
213 ; CHECK-LABEL: foo18:
215 ; CHECK: mov w[[REG:[0-9]+]], #1
216 ; CHECK: cinc x0, x[[REG]], le
217 %cmp = icmp sgt i64 %a, %b
218 %. = select i1 %cmp, i64 1, i64 2
222 define i64 @foo19(i64 %a, i64 %b, i64 %c) {
224 ; CHECK-LABEL: foo19:
227 %cmp = icmp ult i64 %a, %b
228 %inc = zext i1 %cmp to i64
229 %inc.c = add i64 %inc, %c
233 define i32 @foo20(i32 %x) {
234 ; CHECK-LABEL: foo20:
236 ; CHECK: mov w[[REG:[0-9]+]], #6
237 ; CHECK: csinc w0, w[[REG]], wzr, eq
238 %cmp = icmp eq i32 %x, 5
239 %res = select i1 %cmp, i32 6, i32 1
243 define i64 @foo21(i64 %x) {
244 ; CHECK-LABEL: foo21:
246 ; CHECK: mov w[[REG:[0-9]+]], #6
247 ; CHECK: csinc x0, x[[REG]], xzr, eq
248 %cmp = icmp eq i64 %x, 5
249 %res = select i1 %cmp, i64 6, i64 1
253 define i32 @foo22(i32 %x) {
254 ; CHECK-LABEL: foo22:
256 ; CHECK: mov w[[REG:[0-9]+]], #6
257 ; CHECK: csinc w0, w[[REG]], wzr, ne
258 %cmp = icmp eq i32 %x, 5
259 %res = select i1 %cmp, i32 1, i32 6
263 define i64 @foo23(i64 %x) {
264 ; CHECK-LABEL: foo23:
266 ; CHECK: mov w[[REG:[0-9]+]], #6
267 ; CHECK: csinc x0, x[[REG]], xzr, ne
268 %cmp = icmp eq i64 %x, 5
269 %res = select i1 %cmp, i64 1, i64 6