• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: llc -mtriple=armv4t-eabi %s -o -  | FileCheck %s --check-prefix=CHECK --check-prefix=V4T
2; RUN: llc -mtriple=armv6-eabi %s -o -   | FileCheck %s --check-prefix=CHECK --check-prefix=V6
3; RUN: llc -mtriple=armv6t2-eabi %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=V6T2
4
5; Check for several conditions that should result in USAT.
6; For example, the base test is equivalent to
7; x < 0 ? 0 : (x > k ? k : x) in C. All patterns that bound x
8; to the interval [0, k] where k + 1 is a power of 2 can be
9; transformed into USAT. At the end there are some tests
10; checking that conditionals are not transformed if they don't
11; match the right pattern.
12
13;
14; Base tests with different bit widths
15;
16
17; x < 0 ? 0 : (x > k ? k : x)
18; 32-bit base test
19define i32 @unsigned_sat_base_32bit(i32 %x) #0 {
20; CHECK-LABEL: unsigned_sat_base_32bit:
21; V6: usat r0, #23, r0
22; V6T2: usat r0, #23, r0
23; V4T-NOT: usat
24entry:
25  %cmpLow = icmp slt i32 %x, 0
26  %cmpUp = icmp sgt i32 %x, 8388607
27  %saturateUp = select i1 %cmpUp, i32 8388607, i32 %x
28  %saturateLow = select i1 %cmpLow, i32 0, i32 %saturateUp
29  ret i32 %saturateLow
30}
31
32; x < 0 ? 0 : (x > k ? k : x)
33; 16-bit base test
34define i16 @unsigned_sat_base_16bit(i16 %x) #0 {
35; CHECK-LABEL: unsigned_sat_base_16bit:
36; V6: usat r0, #11, r0
37; V6T2: usat r0, #11, r0
38; V4T-NOT: usat
39entry:
40  %cmpLow = icmp slt i16 %x, 0
41  %cmpUp = icmp sgt i16 %x, 2047
42  %saturateUp = select i1 %cmpUp, i16 2047, i16 %x
43  %saturateLow = select i1 %cmpLow, i16 0, i16 %saturateUp
44  ret i16 %saturateLow
45}
46
47; x < 0 ? 0 : (x > k ? k : x)
48; 8-bit base test
49define i8 @unsigned_sat_base_8bit(i8 %x) #0 {
50; CHECK-LABEL: unsigned_sat_base_8bit:
51; V6: usat r0, #5, r0
52; V6T2: usat r0, #5, r0
53; V4T-NOT: usat
54entry:
55  %cmpLow = icmp slt i8 %x, 0
56  %cmpUp = icmp sgt i8 %x, 31
57  %saturateUp = select i1 %cmpUp, i8 31, i8 %x
58  %saturateLow = select i1 %cmpLow, i8 0, i8 %saturateUp
59  ret i8 %saturateLow
60}
61
62;
63; Tests where the conditionals that check for upper and lower bounds,
64; or the < and > operators, are arranged in different ways. Only some
65; of the possible combinations that lead to USAT are tested.
66;
67; x < 0 ? 0 : (x < k ? x : k)
68define i32 @unsigned_sat_lower_upper_1(i32 %x) #0 {
69; CHECK-LABEL: unsigned_sat_lower_upper_1:
70; V6: usat r0, #23, r0
71; V6T2: usat r0, #23, r0
72; V4T-NOT: usat
73entry:
74  %cmpLow = icmp slt i32 %x, 0
75  %cmpUp = icmp slt i32 %x, 8388607
76  %saturateUp = select i1 %cmpUp, i32 %x, i32 8388607
77  %saturateLow = select i1 %cmpLow, i32 0, i32 %saturateUp
78  ret i32 %saturateLow
79}
80
81; x > 0 ? (x > k ? k : x) : 0
82define i32 @unsigned_sat_lower_upper_2(i32 %x) #0 {
83; CHECK-LABEL: unsigned_sat_lower_upper_2:
84; V6: usat    r0, #23, r0
85; V6T2: usat    r0, #23, r0
86; V4T-NOT: usat
87entry:
88  %cmpLow = icmp sgt i32 %x, 0
89  %cmpUp = icmp sgt i32 %x, 8388607
90  %saturateUp = select i1 %cmpUp, i32 8388607, i32 %x
91  %saturateLow = select i1 %cmpLow, i32 %saturateUp, i32 0
92  ret i32 %saturateLow
93}
94
95; x < k ? (x < 0 ? 0 : x) : k
96define i32 @unsigned_sat_upper_lower_1(i32 %x) #0 {
97; CHECK-LABEL: unsigned_sat_upper_lower_1:
98; V6: usat    r0, #23, r0
99; V6T2: usat    r0, #23, r0
100; V4T-NOT: usat
101entry:
102  %cmpUp = icmp slt i32 %x, 8388607
103  %cmpLow = icmp slt i32 %x, 0
104  %saturateLow = select i1 %cmpLow, i32 0, i32 %x
105  %saturateUp = select i1 %cmpUp, i32 %saturateLow, i32 8388607
106  ret i32 %saturateUp
107}
108
109; x > k ? k : (x < 0 ? 0 : x)
110define i32 @unsigned_sat_upper_lower_2(i32 %x) #0 {
111; CHECK-LABEL: unsigned_sat_upper_lower_2:
112; V6: usat    r0, #23, r0
113; V6T2: usat    r0, #23, r0
114; V4T-NOT: usat
115entry:
116  %cmpUp = icmp sgt i32 %x, 8388607
117  %cmpLow = icmp slt i32 %x, 0
118  %saturateLow = select i1 %cmpLow, i32 0, i32 %x
119  %saturateUp = select i1 %cmpUp, i32 8388607, i32 %saturateLow
120  ret i32 %saturateUp
121}
122
123; k < x ? k : (x > 0 ? x : 0)
124define i32 @unsigned_sat_upper_lower_3(i32 %x) #0 {
125; CHECK-LABEL: unsigned_sat_upper_lower_3:
126; V6: usat    r0, #23, r0
127; V6T2: usat    r0, #23, r0
128; V4T-NOT: usat
129entry:
130  %cmpUp = icmp slt i32 8388607, %x
131  %cmpLow = icmp sgt i32 %x, 0
132  %saturateLow = select i1 %cmpLow, i32 %x, i32 0
133  %saturateUp = select i1 %cmpUp, i32 8388607, i32 %saturateLow
134  ret i32 %saturateUp
135}
136
137;
138; The following tests check for patterns that should not transform
139; into USAT but are similar enough that could confuse the selector.
140;
141; x > k ? k : (x > 0 ? 0 : x)
142; First condition upper-saturates, second doesn't lower-saturate.
143define i32 @no_unsigned_sat_missing_lower(i32 %x) #0 {
144; CHECK-LABEL: no_unsigned_sat_missing_lower
145; CHECK-NOT: usat
146entry:
147  %cmpUp = icmp sgt i32 %x, 8388607
148  %cmpLow = icmp sgt i32 %x, 0
149  %saturateLow = select i1 %cmpLow, i32 0, i32 %x
150  %saturateUp = select i1 %cmpUp, i32 8388607, i32 %saturateLow
151  ret i32 %saturateUp
152}
153
154; x < k ? k : (x < 0 ? 0 : x)
155; Second condition lower-saturates, first doesn't upper-saturate.
156define i32 @no_unsigned_sat_missing_upper(i32 %x) #0 {
157; CHECK-LABEL: no_unsigned_sat_missing_upper:
158; CHECK-NOT: usat
159entry:
160  %cmpUp = icmp slt i32 %x, 8388607
161  %cmpLow = icmp slt i32 %x, 0
162  %saturateLow = select i1 %cmpLow, i32 0, i32 %x
163  %saturateUp = select i1 %cmpUp, i32 8388607, i32 %saturateLow
164  ret i32 %saturateUp
165}
166
167; Lower constant is different in the select and in the compare
168define i32 @no_unsigned_sat_incorrect_constant(i32 %x) #0 {
169; CHECK-LABEL: no_unsigned_sat_incorrect_constant:
170; CHECK-NOT: usat
171entry:
172  %cmpUp = icmp sgt i32 %x, 8388607
173  %cmpLow = icmp slt i32 %x, 0
174  %saturateLow = select i1 %cmpLow, i32 -1, i32 %x
175  %saturateUp = select i1 %cmpUp, i32 8388607, i32 %saturateLow
176  ret i32 %saturateUp
177}
178
179; The interval is not [0, k]
180define i32 @no_unsigned_sat_incorrect_interval(i32 %x) #0 {
181; CHECK-LABEL: no_unsigned_sat_incorrect_interval:
182; CHECK-NOT: usat
183entry:
184  %cmpUp = icmp sgt i32 %x, 8388607
185  %cmpLow = icmp slt i32 %x, -4
186  %saturateLow = select i1 %cmpLow, i32 -4, i32 %x
187  %saturateUp = select i1 %cmpUp, i32 8388607, i32 %saturateLow
188  ret i32 %saturateUp
189}
190
191; The returned value (y) is not the same as the tested value (x).
192define i32 @no_unsigned_sat_incorrect_return(i32 %x, i32 %y) #0 {
193; CHECK-LABEL: no_unsigned_sat_incorrect_return:
194; CHECK-NOT: usat
195entry:
196  %cmpUp = icmp sgt i32 %x, 8388607
197  %cmpLow = icmp slt i32 %x, 0
198  %saturateLow = select i1 %cmpLow, i32 0, i32 %y
199  %saturateUp = select i1 %cmpUp, i32 8388607, i32 %saturateLow
200  ret i32 %saturateUp
201}
202
203; One of the values in a compare (y) is not the same as the rest
204; of the compare and select values (x).
205define i32 @no_unsigned_sat_incorrect_compare(i32 %x, i32 %y) #0 {
206; CHECK-LABEL: no_unsigned_sat_incorrect_compare:
207; CHECK-NOT: usat
208entry:
209  %cmpUp = icmp sgt i32 %x, 8388607
210  %cmpLow = icmp slt i32 %y, 0
211  %saturateLow = select i1 %cmpLow, i32 0, i32 %x
212  %saturateUp = select i1 %cmpUp, i32 8388607, i32 %saturateLow
213  ret i32 %saturateUp
214}
215