1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc --mtriple=loongarch32 -mattr=+d < %s | FileCheck %s --check-prefix=LA32
3 ; RUN: llc --mtriple=loongarch64 -mattr=+d < %s | FileCheck %s --check-prefix=LA64
5 ;; Compare if positive and select variable or zero.
6 define i8 @pos_sel_variable_and_zero_i8(i8 signext %a, i8 signext %b) {
7 ; LA32-LABEL: pos_sel_variable_and_zero_i8:
9 ; LA32-NEXT: srai.w $a0, $a0, 7
10 ; LA32-NEXT: andn $a0, $a1, $a0
13 ; LA64-LABEL: pos_sel_variable_and_zero_i8:
15 ; LA64-NEXT: srai.d $a0, $a0, 7
16 ; LA64-NEXT: andn $a0, $a1, $a0
18 %cmp = icmp sgt i8 %a, -1
19 %sel = select i1 %cmp, i8 %b, i8 0
23 define i16 @pos_sel_variable_and_zero_i16(i16 signext %a, i16 signext %b) {
24 ; LA32-LABEL: pos_sel_variable_and_zero_i16:
26 ; LA32-NEXT: srai.w $a0, $a0, 15
27 ; LA32-NEXT: andn $a0, $a1, $a0
30 ; LA64-LABEL: pos_sel_variable_and_zero_i16:
32 ; LA64-NEXT: srai.d $a0, $a0, 15
33 ; LA64-NEXT: andn $a0, $a1, $a0
35 %cmp = icmp sgt i16 %a, -1
36 %sel = select i1 %cmp, i16 %b, i16 0
40 define i32 @pos_sel_variable_and_zero_i32(i32 signext %a, i32 signext %b) {
41 ; LA32-LABEL: pos_sel_variable_and_zero_i32:
43 ; LA32-NEXT: srai.w $a0, $a0, 31
44 ; LA32-NEXT: andn $a0, $a1, $a0
47 ; LA64-LABEL: pos_sel_variable_and_zero_i32:
49 ; LA64-NEXT: srai.d $a0, $a0, 31
50 ; LA64-NEXT: andn $a0, $a1, $a0
52 %cmp = icmp sgt i32 %a, -1
53 %sel = select i1 %cmp, i32 %b, i32 0
57 define i64 @pos_sel_variable_and_zero_i64(i64 signext %a, i64 signext %b) {
58 ; LA32-LABEL: pos_sel_variable_and_zero_i64:
60 ; LA32-NEXT: srai.w $a1, $a1, 31
61 ; LA32-NEXT: andn $a0, $a2, $a1
62 ; LA32-NEXT: andn $a1, $a3, $a1
65 ; LA64-LABEL: pos_sel_variable_and_zero_i64:
67 ; LA64-NEXT: srai.d $a0, $a0, 63
68 ; LA64-NEXT: andn $a0, $a1, $a0
70 %cmp = icmp sgt i64 %a, -1
71 %sel = select i1 %cmp, i64 %b, i64 0
75 ;; Compare if not negative or zero and select the same variable as being
76 ;; compared: smax(a, 0).
77 define i8 @not_neg_not_zero_sel_same_variable_i8(i8 signext %a) {
78 ; LA32-LABEL: not_neg_not_zero_sel_same_variable_i8:
80 ; LA32-NEXT: srai.w $a1, $a0, 7
81 ; LA32-NEXT: andn $a0, $a0, $a1
84 ; LA64-LABEL: not_neg_not_zero_sel_same_variable_i8:
86 ; LA64-NEXT: srai.d $a1, $a0, 7
87 ; LA64-NEXT: andn $a0, $a0, $a1
89 %cmp = icmp sgt i8 %a, 0
90 %sel = select i1 %cmp, i8 %a, i8 0
94 define i16 @not_neg_not_zero_sel_same_variable_i16(i16 signext %a) {
95 ; LA32-LABEL: not_neg_not_zero_sel_same_variable_i16:
97 ; LA32-NEXT: srai.w $a1, $a0, 15
98 ; LA32-NEXT: andn $a0, $a0, $a1
101 ; LA64-LABEL: not_neg_not_zero_sel_same_variable_i16:
103 ; LA64-NEXT: srai.d $a1, $a0, 15
104 ; LA64-NEXT: andn $a0, $a0, $a1
106 %cmp = icmp sgt i16 %a, 0
107 %sel = select i1 %cmp, i16 %a, i16 0
111 define i32 @not_neg_not_zero_sel_same_variable_i32(i32 signext %a) {
112 ; LA32-LABEL: not_neg_not_zero_sel_same_variable_i32:
114 ; LA32-NEXT: srai.w $a1, $a0, 31
115 ; LA32-NEXT: andn $a0, $a0, $a1
118 ; LA64-LABEL: not_neg_not_zero_sel_same_variable_i32:
120 ; LA64-NEXT: srai.d $a1, $a0, 31
121 ; LA64-NEXT: andn $a0, $a0, $a1
123 %cmp = icmp sgt i32 %a, 0
124 %sel = select i1 %cmp, i32 %a, i32 0
128 define i64 @not_neg_not_zero_sel_same_variable_i64(i64 signext %a) {
129 ; LA32-LABEL: not_neg_not_zero_sel_same_variable_i64:
131 ; LA32-NEXT: srai.w $a2, $a1, 31
132 ; LA32-NEXT: andn $a0, $a0, $a2
133 ; LA32-NEXT: andn $a1, $a1, $a2
136 ; LA64-LABEL: not_neg_not_zero_sel_same_variable_i64:
138 ; LA64-NEXT: srai.d $a1, $a0, 63
139 ; LA64-NEXT: andn $a0, $a0, $a1
141 %cmp = icmp sgt i64 %a, 0
142 %sel = select i1 %cmp, i64 %a, i64 0
146 ;; ret = (x-y) > 0 ? x-y : 0
147 define i8 @sub_clamp_zero_i8(i8 signext %x, i8 signext %y) {
148 ; LA32-LABEL: sub_clamp_zero_i8:
150 ; LA32-NEXT: sub.w $a0, $a0, $a1
151 ; LA32-NEXT: ext.w.b $a1, $a0
152 ; LA32-NEXT: srai.w $a1, $a1, 7
153 ; LA32-NEXT: andn $a0, $a0, $a1
156 ; LA64-LABEL: sub_clamp_zero_i8:
158 ; LA64-NEXT: sub.d $a0, $a0, $a1
159 ; LA64-NEXT: ext.w.b $a1, $a0
160 ; LA64-NEXT: srai.d $a1, $a1, 7
161 ; LA64-NEXT: andn $a0, $a0, $a1
163 %sub = sub nsw i8 %x, %y
164 %cmp = icmp sgt i8 %sub, 0
165 %sel = select i1 %cmp, i8 %sub, i8 0
169 define i16 @sub_clamp_zero_i16(i16 signext %x, i16 signext %y) {
170 ; LA32-LABEL: sub_clamp_zero_i16:
172 ; LA32-NEXT: sub.w $a0, $a0, $a1
173 ; LA32-NEXT: ext.w.h $a1, $a0
174 ; LA32-NEXT: srai.w $a1, $a1, 15
175 ; LA32-NEXT: andn $a0, $a0, $a1
178 ; LA64-LABEL: sub_clamp_zero_i16:
180 ; LA64-NEXT: sub.d $a0, $a0, $a1
181 ; LA64-NEXT: ext.w.h $a1, $a0
182 ; LA64-NEXT: srai.d $a1, $a1, 15
183 ; LA64-NEXT: andn $a0, $a0, $a1
185 %sub = sub nsw i16 %x, %y
186 %cmp = icmp sgt i16 %sub, 0
187 %sel = select i1 %cmp, i16 %sub, i16 0
191 define i32 @sub_clamp_zero_i32(i32 signext %x, i32 signext %y) {
192 ; LA32-LABEL: sub_clamp_zero_i32:
194 ; LA32-NEXT: sub.w $a0, $a0, $a1
195 ; LA32-NEXT: srai.w $a1, $a0, 31
196 ; LA32-NEXT: andn $a0, $a0, $a1
199 ; LA64-LABEL: sub_clamp_zero_i32:
201 ; LA64-NEXT: sub.w $a0, $a0, $a1
202 ; LA64-NEXT: srai.d $a1, $a0, 31
203 ; LA64-NEXT: andn $a0, $a0, $a1
205 %sub = sub nsw i32 %x, %y
206 %cmp = icmp sgt i32 %sub, 0
207 %sel = select i1 %cmp, i32 %sub, i32 0
211 define i64 @sub_clamp_zero_i64(i64 signext %x, i64 signext %y) {
212 ; LA32-LABEL: sub_clamp_zero_i64:
214 ; LA32-NEXT: sltu $a4, $a0, $a2
215 ; LA32-NEXT: sub.w $a1, $a1, $a3
216 ; LA32-NEXT: sub.w $a1, $a1, $a4
217 ; LA32-NEXT: sub.w $a0, $a0, $a2
218 ; LA32-NEXT: srai.w $a2, $a1, 31
219 ; LA32-NEXT: andn $a1, $a1, $a2
220 ; LA32-NEXT: andn $a0, $a0, $a2
223 ; LA64-LABEL: sub_clamp_zero_i64:
225 ; LA64-NEXT: sub.d $a0, $a0, $a1
226 ; LA64-NEXT: srai.d $a1, $a0, 63
227 ; LA64-NEXT: andn $a0, $a0, $a1
229 %sub = sub nsw i64 %x, %y
230 %cmp = icmp sgt i64 %sub, 0
231 %sel = select i1 %cmp, i64 %sub, i64 0