1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=aarch64-unknown-unknown | FileCheck %s
4 ; Compare if negative and select of constants where one constant is zero.
6 define i32 @neg_sel_constants(i32 %a) {
7 ; CHECK-LABEL: neg_sel_constants:
9 ; CHECK-NEXT: mov w8, #5
10 ; 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
25 %tmp.1 = icmp slt i32 %a, 0
26 %retval = select i1 %tmp.1, i32 512, i32 0
30 ; Compare if negative and select variable or zero.
32 define i32 @neg_sel_variable_and_zero(i32 %a, i32 %b) {
33 ; CHECK-LABEL: neg_sel_variable_and_zero:
35 ; CHECK-NEXT: and w0, w1, w0, asr #31
37 %tmp.1 = icmp slt i32 %a, 0
38 %retval = select i1 %tmp.1, i32 %b, i32 0
42 ; Compare if not positive and select the same variable as being compared: smin(a, 0).
44 define i32 @not_pos_sel_same_variable(i32 %a) {
45 ; CHECK-LABEL: not_pos_sel_same_variable:
47 ; CHECK-NEXT: and w0, w0, w0, asr #31
49 %tmp = icmp slt i32 %a, 1
50 %min = select i1 %tmp, i32 %a, i32 0
54 ; Flipping the comparison condition can be handled by getting the bitwise not of the sign mask.
56 ; Compare if positive and select of constants where one constant is zero.
58 define i32 @pos_sel_constants(i32 %a) {
59 ; CHECK-LABEL: pos_sel_constants:
61 ; CHECK-NEXT: mov w8, #5
62 ; CHECK-NEXT: bic w0, w8, w0, asr #31
64 %tmp.1 = icmp sgt i32 %a, -1
65 %retval = select i1 %tmp.1, i32 5, i32 0
69 ; Compare if positive and select of constants where one constant is zero and the other is a single bit.
71 define i32 @pos_sel_special_constant(i32 %a) {
72 ; CHECK-LABEL: pos_sel_special_constant:
74 ; CHECK-NEXT: mov w8, #512
75 ; CHECK-NEXT: bic w0, w8, w0, lsr #22
77 %tmp.1 = icmp sgt i32 %a, -1
78 %retval = select i1 %tmp.1, i32 512, i32 0
82 ; Compare if positive and select variable or zero.
84 define i32 @pos_sel_variable_and_zero(i32 %a, i32 %b) {
85 ; CHECK-LABEL: pos_sel_variable_and_zero:
87 ; CHECK-NEXT: bic w0, w1, w0, asr #31
89 %tmp.1 = icmp sgt i32 %a, -1
90 %retval = select i1 %tmp.1, i32 %b, i32 0
94 ; Compare if not negative or zero and select the same variable as being compared: smax(a, 0).
96 define i32 @not_neg_sel_same_variable(i32 %a) {
97 ; CHECK-LABEL: not_neg_sel_same_variable:
99 ; CHECK-NEXT: bic w0, w0, w0, asr #31
101 %tmp = icmp sgt i32 %a, 0
102 %min = select i1 %tmp, i32 %a, i32 0
106 ; https://llvm.org/bugs/show_bug.cgi?id=31175
108 ; ret = (x-y) > 0 ? x-y : 0
109 define i32 @PR31175(i32 %x, i32 %y) {
110 ; CHECK-LABEL: PR31175:
112 ; CHECK-NEXT: sub w8, w0, w1
113 ; CHECK-NEXT: bic w0, w8, w8, asr #31
115 %sub = sub nsw i32 %x, %y
116 %cmp = icmp sgt i32 %sub, 0
117 %sel = select i1 %cmp, i32 %sub, i32 0