1 ; RUN: llc < %s -mtriple=aarch64-unknown-unknown | FileCheck %s
3 ; Compare if negative and select of constants where one constant is zero.
5 define i32 @neg_sel_constants(i32 %a) {
6 ; CHECK-LABEL: neg_sel_constants:
8 ; CHECK-NEXT: mov w8, #5
9 ; CHECK-NEXT: and w0, w8, w0, asr #31
12 %tmp.1 = icmp slt i32 %a, 0
13 %retval = select i1 %tmp.1, i32 5, i32 0
17 ; Compare if negative and select of constants where one constant is zero and the other is a single bit.
19 define i32 @neg_sel_special_constant(i32 %a) {
20 ; CHECK-LABEL: neg_sel_special_constant:
22 ; CHECK-NEXT: lsr w8, w0, #22
23 ; CHECK-NEXT: and w0, w8, #0x200
26 %tmp.1 = icmp slt i32 %a, 0
27 %retval = select i1 %tmp.1, i32 512, i32 0
31 ; Compare if negative and select variable or zero.
33 define i32 @neg_sel_variable_and_zero(i32 %a, i32 %b) {
34 ; CHECK-LABEL: neg_sel_variable_and_zero:
36 ; CHECK-NEXT: and w0, w1, w0, asr #31
39 %tmp.1 = icmp slt i32 %a, 0
40 %retval = select i1 %tmp.1, i32 %b, i32 0
44 ; Compare if not positive and select the same variable as being compared: smin(a, 0).
46 define i32 @not_pos_sel_same_variable(i32 %a) {
47 ; CHECK-LABEL: not_pos_sel_same_variable:
49 ; CHECK-NEXT: and w0, w0, w0, asr #31
52 %tmp = icmp slt i32 %a, 1
53 %min = select i1 %tmp, i32 %a, i32 0
57 ; Flipping the comparison condition can be handled by getting the bitwise not of the sign mask.
59 ; Compare if positive and select of constants where one constant is zero.
61 define i32 @pos_sel_constants(i32 %a) {
62 ; CHECK-LABEL: pos_sel_constants:
64 ; CHECK-NEXT: mov w8, #5
65 ; CHECK-NEXT: bic w0, w8, w0, asr #31
68 %tmp.1 = icmp sgt i32 %a, -1
69 %retval = select i1 %tmp.1, i32 5, i32 0
73 ; Compare if positive and select of constants where one constant is zero and the other is a single bit.
75 define i32 @pos_sel_special_constant(i32 %a) {
76 ; CHECK-LABEL: pos_sel_special_constant:
78 ; CHECK-NEXT: orr w8, wzr, #0x200
79 ; CHECK-NEXT: bic w0, w8, w0, lsr #22
82 %tmp.1 = icmp sgt i32 %a, -1
83 %retval = select i1 %tmp.1, i32 512, i32 0
87 ; Compare if positive and select variable or zero.
89 define i32 @pos_sel_variable_and_zero(i32 %a, i32 %b) {
90 ; CHECK-LABEL: pos_sel_variable_and_zero:
92 ; CHECK-NEXT: bic w0, w1, w0, asr #31
95 %tmp.1 = icmp sgt i32 %a, -1
96 %retval = select i1 %tmp.1, i32 %b, i32 0
100 ; Compare if not negative or zero and select the same variable as being compared: smax(a, 0).
102 define i32 @not_neg_sel_same_variable(i32 %a) {
103 ; CHECK-LABEL: not_neg_sel_same_variable:
105 ; CHECK-NEXT: bic w0, w0, w0, asr #31
108 %tmp = icmp sgt i32 %a, 0
109 %min = select i1 %tmp, i32 %a, i32 0
113 ; https://llvm.org/bugs/show_bug.cgi?id=31175
115 ; ret = (x-y) > 0 ? x-y : 0
116 define i32 @PR31175(i32 %x, i32 %y) {
117 ; CHECK-LABEL: PR31175:
119 ; CHECK-NEXT: sub w8, w0, w1
120 ; CHECK-NEXT: bic w0, w8, w8, asr #31
123 %sub = sub nsw i32 %x, %y
124 %cmp = icmp sgt i32 %sub, 0
125 %sel = select i1 %cmp, i32 %sub, i32 0