Branch data Line data Source code
1 : : /* Code for range operators.
2 : : Copyright (C) 2017-2025 Free Software Foundation, Inc.
3 : : Contributed by Andrew MacLeod <amacleod@redhat.com>
4 : : and Aldy Hernandez <aldyh@redhat.com>.
5 : :
6 : : This file is part of GCC.
7 : :
8 : : GCC is free software; you can redistribute it and/or modify
9 : : it under the terms of the GNU General Public License as published by
10 : : the Free Software Foundation; either version 3, or (at your option)
11 : : any later version.
12 : :
13 : : GCC is distributed in the hope that it will be useful,
14 : : but WITHOUT ANY WARRANTY; without even the implied warranty of
15 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 : : GNU General Public License for more details.
17 : :
18 : : You should have received a copy of the GNU General Public License
19 : : along with GCC; see the file COPYING3. If not see
20 : : <http://www.gnu.org/licenses/>. */
21 : :
22 : : #include "config.h"
23 : : #include "system.h"
24 : : #include "coretypes.h"
25 : : #include "backend.h"
26 : : #include "insn-codes.h"
27 : : #include "rtl.h"
28 : : #include "tree.h"
29 : : #include "gimple.h"
30 : : #include "cfghooks.h"
31 : : #include "tree-pass.h"
32 : : #include "ssa.h"
33 : : #include "optabs-tree.h"
34 : : #include "gimple-pretty-print.h"
35 : : #include "diagnostic-core.h"
36 : : #include "flags.h"
37 : : #include "fold-const.h"
38 : : #include "stor-layout.h"
39 : : #include "calls.h"
40 : : #include "cfganal.h"
41 : : #include "gimple-iterator.h"
42 : : #include "gimple-fold.h"
43 : : #include "tree-eh.h"
44 : : #include "gimple-walk.h"
45 : : #include "tree-cfg.h"
46 : : #include "wide-int.h"
47 : : #include "value-relation.h"
48 : : #include "range-op.h"
49 : : #include "tree-ssa-ccp.h"
50 : : #include "range-op-mixed.h"
51 : :
52 : : // Instantiate the operators which apply to multiple types here.
53 : :
54 : : operator_equal op_equal;
55 : : operator_not_equal op_not_equal;
56 : : operator_lt op_lt;
57 : : operator_le op_le;
58 : : operator_gt op_gt;
59 : : operator_ge op_ge;
60 : : operator_identity op_ident;
61 : : operator_cst op_cst;
62 : : operator_cast op_cast;
63 : : operator_view op_view;
64 : : operator_plus op_plus;
65 : : operator_abs op_abs;
66 : : operator_minus op_minus;
67 : : operator_negate op_negate;
68 : : operator_mult op_mult;
69 : : operator_addr_expr op_addr;
70 : : operator_bitwise_not op_bitwise_not;
71 : : operator_bitwise_xor op_bitwise_xor;
72 : : operator_bitwise_and op_bitwise_and;
73 : : operator_bitwise_or op_bitwise_or;
74 : : operator_min op_min;
75 : : operator_max op_max;
76 : :
77 : : // Instantaite a range operator table.
78 : : range_op_table operator_table;
79 : :
80 : : // Invoke the initialization routines for each class of range.
81 : :
82 : 288171 : range_op_table::range_op_table ()
83 : : {
84 : 288171 : initialize_integral_ops ();
85 : 288171 : initialize_pointer_ops ();
86 : 288171 : initialize_float_ops ();
87 : :
88 : 288171 : set (EQ_EXPR, op_equal);
89 : 288171 : set (NE_EXPR, op_not_equal);
90 : 288171 : set (LT_EXPR, op_lt);
91 : 288171 : set (LE_EXPR, op_le);
92 : 288171 : set (GT_EXPR, op_gt);
93 : 288171 : set (GE_EXPR, op_ge);
94 : 288171 : set (SSA_NAME, op_ident);
95 : 288171 : set (PAREN_EXPR, op_ident);
96 : 288171 : set (OBJ_TYPE_REF, op_ident);
97 : 288171 : set (REAL_CST, op_cst);
98 : 288171 : set (INTEGER_CST, op_cst);
99 : 288171 : set (NOP_EXPR, op_cast);
100 : 288171 : set (CONVERT_EXPR, op_cast);
101 : 288171 : set (VIEW_CONVERT_EXPR, op_view);
102 : 288171 : set (FLOAT_EXPR, op_cast);
103 : 288171 : set (FIX_TRUNC_EXPR, op_cast);
104 : 288171 : set (PLUS_EXPR, op_plus);
105 : 288171 : set (ABS_EXPR, op_abs);
106 : 288171 : set (MINUS_EXPR, op_minus);
107 : 288171 : set (NEGATE_EXPR, op_negate);
108 : 288171 : set (MULT_EXPR, op_mult);
109 : 288171 : set (ADDR_EXPR, op_addr);
110 : 288171 : set (BIT_NOT_EXPR, op_bitwise_not);
111 : 288171 : set (BIT_XOR_EXPR, op_bitwise_xor);
112 : 288171 : set (BIT_AND_EXPR, op_bitwise_and);
113 : 288171 : set (BIT_IOR_EXPR, op_bitwise_or);
114 : 288171 : set (MIN_EXPR, op_min);
115 : 288171 : set (MAX_EXPR, op_max);
116 : 288171 : }
117 : :
118 : : // Instantiate a default range operator for opcodes with no entry.
119 : :
120 : : range_operator default_operator;
121 : :
122 : : // Create a default range_op_handler.
123 : :
124 : 900945254 : range_op_handler::range_op_handler ()
125 : : {
126 : 900945254 : m_operator = &default_operator;
127 : 900945254 : }
128 : :
129 : : // Create a range_op_handler for CODE. Use a default operatoer if CODE
130 : : // does not have an entry.
131 : :
132 : 1998653300 : range_op_handler::range_op_handler (unsigned code)
133 : : {
134 : 1998653300 : m_operator = operator_table[code];
135 : 1998653300 : if (!m_operator)
136 : 473659012 : m_operator = &default_operator;
137 : 1998653300 : }
138 : :
139 : : // Return TRUE if this handler has a non-default operator.
140 : :
141 : 3040207176 : range_op_handler::operator bool () const
142 : : {
143 : 3040207176 : return m_operator != &default_operator;
144 : : }
145 : :
146 : : // Return a pointer to the range operator assocaited with this handler.
147 : : // If it is a default operator, return NULL.
148 : : // This is the equivalent of indexing the range table.
149 : :
150 : : range_operator *
151 : 537493791 : range_op_handler::range_op () const
152 : : {
153 : 537493791 : if (m_operator != &default_operator)
154 : 537493791 : return m_operator;
155 : : return NULL;
156 : : }
157 : :
158 : : // Create a dispatch pattern for value range discriminators LHS, OP1, and OP2.
159 : : // This is used to produce a unique value for each dispatch pattern. Shift
160 : : // values are based on the size of the m_discriminator field in value_range.h.
161 : :
162 : : constexpr unsigned
163 : 658197561 : dispatch_trio (unsigned lhs, unsigned op1, unsigned op2)
164 : : {
165 : 658197561 : return ((lhs << 8) + (op1 << 4) + (op2));
166 : : }
167 : :
168 : : // These are the supported dispatch patterns. These map to the parameter list
169 : : // of the routines in range_operator. Note the last 3 characters are
170 : : // shorthand for the LHS, OP1, and OP2 range discriminator class.
171 : : // Reminder, single operand instructions use the LHS type for op2, even if
172 : : // unused. So FLOAT = INT would be RO_FIF.
173 : :
174 : : const unsigned RO_III = dispatch_trio (VR_IRANGE, VR_IRANGE, VR_IRANGE);
175 : : const unsigned RO_IFI = dispatch_trio (VR_IRANGE, VR_FRANGE, VR_IRANGE);
176 : : const unsigned RO_IFF = dispatch_trio (VR_IRANGE, VR_FRANGE, VR_FRANGE);
177 : : const unsigned RO_FFF = dispatch_trio (VR_FRANGE, VR_FRANGE, VR_FRANGE);
178 : : const unsigned RO_FIF = dispatch_trio (VR_FRANGE, VR_IRANGE, VR_FRANGE);
179 : : const unsigned RO_FII = dispatch_trio (VR_FRANGE, VR_IRANGE, VR_IRANGE);
180 : : const unsigned RO_PPP = dispatch_trio (VR_PRANGE, VR_PRANGE, VR_PRANGE);
181 : : const unsigned RO_PPI = dispatch_trio (VR_PRANGE, VR_PRANGE, VR_IRANGE);
182 : : const unsigned RO_IPP = dispatch_trio (VR_IRANGE, VR_PRANGE, VR_PRANGE);
183 : : const unsigned RO_IPI = dispatch_trio (VR_IRANGE, VR_PRANGE, VR_IRANGE);
184 : : const unsigned RO_PIP = dispatch_trio (VR_PRANGE, VR_IRANGE, VR_PRANGE);
185 : : const unsigned RO_PII = dispatch_trio (VR_PRANGE, VR_IRANGE, VR_IRANGE);
186 : :
187 : : // Return a dispatch value for parameter types LHS, OP1 and OP2.
188 : :
189 : : unsigned
190 : 658197561 : range_op_handler::dispatch_kind (const vrange &lhs, const vrange &op1,
191 : : const vrange& op2) const
192 : : {
193 : 658197561 : return dispatch_trio (lhs.m_discriminator, op1.m_discriminator,
194 : 658197561 : op2.m_discriminator);
195 : : }
196 : :
197 : : void
198 : 0 : range_op_handler::discriminator_fail (const vrange &r1,
199 : : const vrange &r2,
200 : : const vrange &r3) const
201 : : {
202 : 0 : const char name[] = "IPF";
203 : 0 : gcc_checking_assert (r1.m_discriminator < sizeof (name) - 1);
204 : 0 : gcc_checking_assert (r2.m_discriminator < sizeof (name) - 1);
205 : 0 : gcc_checking_assert (r3.m_discriminator < sizeof (name) - 1);
206 : 0 : fprintf (stderr,
207 : : "Unsupported operand combination in dispatch: RO_%c%c%c\n",
208 : 0 : name[r1.m_discriminator],
209 : 0 : name[r2.m_discriminator],
210 : 0 : name[r3.m_discriminator]);
211 : 0 : gcc_unreachable ();
212 : : }
213 : :
214 : : static inline bool
215 : : has_pointer_operand_p (const vrange &r1, const vrange &r2, const vrange &r3)
216 : : {
217 : : return is_a <prange> (r1) || is_a <prange> (r2) || is_a <prange> (r3);
218 : : }
219 : :
220 : : // Dispatch a call to fold_range based on the types of R, LH and RH.
221 : :
222 : : bool
223 : 294823805 : range_op_handler::fold_range (vrange &r, tree type,
224 : : const vrange &lh,
225 : : const vrange &rh,
226 : : relation_trio rel) const
227 : : {
228 : 294823805 : gcc_checking_assert (m_operator);
229 : : #if CHECKING_P
230 : 294823805 : if (!lh.undefined_p () && !rh.undefined_p ())
231 : 289247872 : gcc_assert (m_operator->operand_check_p (type, lh.type (), rh.type ()));
232 : : #endif
233 : 294823805 : switch (dispatch_kind (r, lh, rh))
234 : : {
235 : 224662230 : case RO_III:
236 : 224662230 : return m_operator->fold_range (as_a <irange> (r), type,
237 : : as_a <irange> (lh),
238 : 224662230 : as_a <irange> (rh), rel);
239 : 369773 : case RO_IFI:
240 : 369773 : return m_operator->fold_range (as_a <irange> (r), type,
241 : : as_a <frange> (lh),
242 : 369773 : as_a <irange> (rh), rel);
243 : 2653799 : case RO_IFF:
244 : 2653799 : return m_operator->fold_range (as_a <irange> (r), type,
245 : : as_a <frange> (lh),
246 : 2653799 : as_a <frange> (rh), rel);
247 : 7602464 : case RO_FFF:
248 : 7602464 : return m_operator->fold_range (as_a <frange> (r), type,
249 : : as_a <frange> (lh),
250 : 7602464 : as_a <frange> (rh), rel);
251 : 0 : case RO_FII:
252 : 0 : return m_operator->fold_range (as_a <frange> (r), type,
253 : : as_a <irange> (lh),
254 : 0 : as_a <irange> (rh), rel);
255 : 920324 : case RO_FIF:
256 : 920324 : return m_operator->fold_range (as_a <frange> (r), type,
257 : : as_a <irange> (lh),
258 : 920324 : as_a <frange> (rh), rel);
259 : 17947618 : case RO_PPP:
260 : 17947618 : return m_operator->fold_range (as_a <prange> (r), type,
261 : : as_a <prange> (lh),
262 : 17947618 : as_a <prange> (rh), rel);
263 : 9679960 : case RO_PPI:
264 : 9679960 : return m_operator->fold_range (as_a <prange> (r), type,
265 : : as_a <prange> (lh),
266 : 9679960 : as_a <irange> (rh), rel);
267 : 18242193 : case RO_IPP:
268 : 18242193 : return m_operator->fold_range (as_a <irange> (r), type,
269 : : as_a <prange> (lh),
270 : 18242193 : as_a <prange> (rh), rel);
271 : 1890104 : case RO_PIP:
272 : 1890104 : return m_operator->fold_range (as_a <prange> (r), type,
273 : : as_a <irange> (lh),
274 : 1890104 : as_a <prange> (rh), rel);
275 : 10855308 : case RO_IPI:
276 : 10855308 : return m_operator->fold_range (as_a <irange> (r), type,
277 : : as_a <prange> (lh),
278 : 10855308 : as_a <irange> (rh), rel);
279 : : default:
280 : : return false;
281 : : }
282 : : }
283 : :
284 : : // Dispatch a call to op1_range based on the types of R, LHS and OP2.
285 : :
286 : : bool
287 : 91595072 : range_op_handler::op1_range (vrange &r, tree type,
288 : : const vrange &lhs,
289 : : const vrange &op2,
290 : : relation_trio rel) const
291 : : {
292 : 91595072 : gcc_checking_assert (m_operator);
293 : 91595072 : if (lhs.undefined_p ())
294 : : return false;
295 : : #if CHECKING_P
296 : 91593856 : if (!op2.undefined_p ())
297 : 91593744 : gcc_assert (m_operator->operand_check_p (lhs.type (), type, op2.type ()));
298 : : #endif
299 : 91593856 : switch (dispatch_kind (r, lhs, op2))
300 : : {
301 : 79253177 : case RO_III:
302 : 79253177 : return m_operator->op1_range (as_a <irange> (r), type,
303 : : as_a <irange> (lhs),
304 : 79253177 : as_a <irange> (op2), rel);
305 : 247502 : case RO_IFI:
306 : 247502 : return m_operator->op1_range (as_a <irange> (r), type,
307 : : as_a <frange> (lhs),
308 : 247502 : as_a <irange> (op2), rel);
309 : 697671 : case RO_PPP:
310 : 697671 : return m_operator->op1_range (as_a <prange> (r), type,
311 : : as_a <prange> (lhs),
312 : 697671 : as_a <prange> (op2), rel);
313 : 8253334 : case RO_PIP:
314 : 8253334 : return m_operator->op1_range (as_a <prange> (r), type,
315 : : as_a <irange> (lhs),
316 : 8253334 : as_a <prange> (op2), rel);
317 : 468828 : case RO_PPI:
318 : 468828 : return m_operator->op1_range (as_a <prange> (r), type,
319 : : as_a <prange> (lhs),
320 : 468828 : as_a <irange> (op2), rel);
321 : 258859 : case RO_IPI:
322 : 258859 : return m_operator->op1_range (as_a <irange> (r), type,
323 : : as_a <prange> (lhs),
324 : 258859 : as_a <irange> (op2), rel);
325 : 1496331 : case RO_FIF:
326 : 1496331 : return m_operator->op1_range (as_a <frange> (r), type,
327 : : as_a <irange> (lhs),
328 : 1496331 : as_a <frange> (op2), rel);
329 : 918154 : case RO_FFF:
330 : 918154 : return m_operator->op1_range (as_a <frange> (r), type,
331 : : as_a <frange> (lhs),
332 : 918154 : as_a <frange> (op2), rel);
333 : : default:
334 : : return false;
335 : : }
336 : : }
337 : :
338 : : // Dispatch a call to op2_range based on the types of R, LHS and OP1.
339 : :
340 : : bool
341 : 26141519 : range_op_handler::op2_range (vrange &r, tree type,
342 : : const vrange &lhs,
343 : : const vrange &op1,
344 : : relation_trio rel) const
345 : : {
346 : 26141519 : gcc_checking_assert (m_operator);
347 : 26141519 : if (lhs.undefined_p ())
348 : : return false;
349 : : #if CHECKING_P
350 : 26141466 : if (!op1.undefined_p ())
351 : 26141306 : gcc_assert (m_operator->operand_check_p (lhs.type (), op1.type (), type));
352 : : #endif
353 : 26141466 : switch (dispatch_kind (r, lhs, op1))
354 : : {
355 : 20311186 : case RO_III:
356 : 20311186 : return m_operator->op2_range (as_a <irange> (r), type,
357 : : as_a <irange> (lhs),
358 : 20311186 : as_a <irange> (op1), rel);
359 : 4688920 : case RO_PIP:
360 : 4688920 : return m_operator->op2_range (as_a <prange> (r), type,
361 : : as_a <irange> (lhs),
362 : 4688920 : as_a <prange> (op1), rel);
363 : 205056 : case RO_IPP:
364 : 205056 : return m_operator->op2_range (as_a <irange> (r), type,
365 : : as_a <prange> (lhs),
366 : 205056 : as_a <prange> (op1), rel);
367 : 560684 : case RO_FIF:
368 : 560684 : return m_operator->op2_range (as_a <frange> (r), type,
369 : : as_a <irange> (lhs),
370 : 560684 : as_a <frange> (op1), rel);
371 : 375470 : case RO_FFF:
372 : 375470 : return m_operator->op2_range (as_a <frange> (r), type,
373 : : as_a <frange> (lhs),
374 : 375470 : as_a <frange> (op1), rel);
375 : : default:
376 : : return false;
377 : : }
378 : : }
379 : :
380 : : // Dispatch a call to lhs_op1_relation based on the types of LHS, OP1 and OP2.
381 : :
382 : : relation_kind
383 : 126816608 : range_op_handler::lhs_op1_relation (const vrange &lhs,
384 : : const vrange &op1,
385 : : const vrange &op2,
386 : : relation_kind rel) const
387 : : {
388 : 126816608 : gcc_checking_assert (m_operator);
389 : 126816608 : switch (dispatch_kind (lhs, op1, op2))
390 : : {
391 : 101750238 : case RO_III:
392 : 101750238 : return m_operator->lhs_op1_relation (as_a <irange> (lhs),
393 : : as_a <irange> (op1),
394 : 101750238 : as_a <irange> (op2), rel);
395 : 1424429 : case RO_PPP:
396 : 1424429 : return m_operator->lhs_op1_relation (as_a <prange> (lhs),
397 : : as_a <prange> (op1),
398 : 1424429 : as_a <prange> (op2), rel);
399 : 6070066 : case RO_IPP:
400 : 6070066 : return m_operator->lhs_op1_relation (as_a <irange> (lhs),
401 : : as_a <prange> (op1),
402 : 6070066 : as_a <prange> (op2), rel);
403 : 1435230 : case RO_PII:
404 : 1435230 : return m_operator->lhs_op1_relation (as_a <prange> (lhs),
405 : : as_a <irange> (op1),
406 : 1435230 : as_a <irange> (op2), rel);
407 : 8352120 : case RO_PPI:
408 : 8352120 : return m_operator->lhs_op1_relation (as_a <prange> (lhs),
409 : : as_a <prange> (op1),
410 : 8352120 : as_a <irange> (op2), rel);
411 : 1047481 : case RO_IFF:
412 : 1047481 : return m_operator->lhs_op1_relation (as_a <irange> (lhs),
413 : : as_a <frange> (op1),
414 : 1047481 : as_a <frange> (op2), rel);
415 : 5817261 : case RO_FFF:
416 : 5817261 : return m_operator->lhs_op1_relation (as_a <frange> (lhs),
417 : : as_a <frange> (op1),
418 : 5817261 : as_a <frange> (op2), rel);
419 : : default:
420 : : return VREL_VARYING;
421 : : }
422 : : }
423 : :
424 : : // Dispatch a call to lhs_op2_relation based on the types of LHS, OP1 and OP2.
425 : :
426 : : relation_kind
427 : 37491062 : range_op_handler::lhs_op2_relation (const vrange &lhs,
428 : : const vrange &op1,
429 : : const vrange &op2,
430 : : relation_kind rel) const
431 : : {
432 : 37491062 : gcc_checking_assert (m_operator);
433 : 37491062 : switch (dispatch_kind (lhs, op1, op2))
434 : : {
435 : 25735100 : case RO_III:
436 : 25735100 : return m_operator->lhs_op2_relation (as_a <irange> (lhs),
437 : : as_a <irange> (op1),
438 : 25735100 : as_a <irange> (op2), rel);
439 : 169640 : case RO_IFF:
440 : 169640 : return m_operator->lhs_op2_relation (as_a <irange> (lhs),
441 : : as_a <frange> (op1),
442 : 169640 : as_a <frange> (op2), rel);
443 : 3642642 : case RO_FFF:
444 : 3642642 : return m_operator->lhs_op2_relation (as_a <frange> (lhs),
445 : : as_a <frange> (op1),
446 : 3642642 : as_a <frange> (op2), rel);
447 : : default:
448 : : return VREL_VARYING;
449 : : }
450 : : }
451 : :
452 : : // Dispatch a call to op1_op2_relation based on the type of LHS.
453 : :
454 : : relation_kind
455 : 81285290 : range_op_handler::op1_op2_relation (const vrange &lhs,
456 : : const vrange &op1,
457 : : const vrange &op2) const
458 : : {
459 : 81285290 : gcc_checking_assert (m_operator);
460 : :
461 : 81285290 : switch (dispatch_kind (lhs, op1, op2))
462 : : {
463 : 63567079 : case RO_III:
464 : 63567079 : return m_operator->op1_op2_relation (as_a <irange> (lhs),
465 : : as_a <irange> (op1),
466 : 63567079 : as_a <irange> (op2));
467 : :
468 : 14863168 : case RO_IPP:
469 : 14863168 : return m_operator->op1_op2_relation (as_a <irange> (lhs),
470 : : as_a <prange> (op1),
471 : 14863168 : as_a <prange> (op2));
472 : :
473 : 1878502 : case RO_IFF:
474 : 1878502 : return m_operator->op1_op2_relation (as_a <irange> (lhs),
475 : : as_a <frange> (op1),
476 : 1878502 : as_a <frange> (op2));
477 : :
478 : 660657 : case RO_FFF:
479 : 660657 : return m_operator->op1_op2_relation (as_a <frange> (lhs),
480 : : as_a <frange> (op1),
481 : 660657 : as_a <frange> (op2));
482 : :
483 : : default:
484 : : return VREL_VARYING;
485 : : }
486 : : }
487 : :
488 : : bool
489 : 45474 : range_op_handler::overflow_free_p (const vrange &lh,
490 : : const vrange &rh,
491 : : relation_trio rel) const
492 : : {
493 : 45474 : gcc_checking_assert (m_operator);
494 : 45474 : switch (dispatch_kind (lh, lh, rh))
495 : : {
496 : 45474 : case RO_III:
497 : 45474 : return m_operator->overflow_free_p(as_a <irange> (lh),
498 : : as_a <irange> (rh),
499 : 45474 : rel);
500 : : default:
501 : : return false;
502 : : }
503 : : }
504 : :
505 : : bool
506 : 9106443 : range_op_handler::operand_check_p (tree t1, tree t2, tree t3) const
507 : : {
508 : 9106443 : gcc_checking_assert (m_operator);
509 : 9106443 : return m_operator->operand_check_p (t1, t2, t3);
510 : : }
511 : :
512 : : // Update the known bitmasks in R when applying the operation CODE to
513 : : // LH and RH.
514 : :
515 : : void
516 : 174055351 : update_known_bitmask (vrange &r, tree_code code,
517 : : const vrange &lh, const vrange &rh)
518 : : {
519 : 174055351 : if (r.undefined_p () || lh.undefined_p () || rh.undefined_p ()
520 : 348106224 : || r.singleton_p ())
521 : 9401319 : return;
522 : :
523 : 164654032 : widest_int widest_value, widest_mask;
524 : 164654032 : tree type = r.type ();
525 : 164654032 : signop sign = TYPE_SIGN (type);
526 : 164654032 : int prec = TYPE_PRECISION (type);
527 : 164654032 : irange_bitmask lh_bits = lh.get_bitmask ();
528 : 164654032 : irange_bitmask rh_bits = rh.get_bitmask ();
529 : :
530 : 164654032 : switch (get_gimple_rhs_class (code))
531 : : {
532 : 55109865 : case GIMPLE_UNARY_RHS:
533 : 55109865 : bit_value_unop (code, sign, prec, &widest_value, &widest_mask,
534 : 55109865 : TYPE_SIGN (lh.type ()),
535 : 55109865 : TYPE_PRECISION (lh.type ()),
536 : 110220190 : widest_int::from (lh_bits.value (),
537 : 55109865 : TYPE_SIGN (lh.type ())),
538 : 110219730 : widest_int::from (lh_bits.mask (),
539 : 55109865 : TYPE_SIGN (lh.type ())));
540 : 55109865 : break;
541 : 109544167 : case GIMPLE_BINARY_RHS:
542 : 219088334 : bit_value_binop (code, sign, prec, &widest_value, &widest_mask,
543 : 109544167 : TYPE_SIGN (lh.type ()),
544 : 109544167 : TYPE_PRECISION (lh.type ()),
545 : 219089223 : widest_int::from (lh_bits.value (), sign),
546 : 219089223 : widest_int::from (lh_bits.mask (), sign),
547 : 109544167 : TYPE_SIGN (rh.type ()),
548 : 109544167 : TYPE_PRECISION (rh.type ()),
549 : 219089193 : widest_int::from (rh_bits.value (), sign),
550 : 219088334 : widest_int::from (rh_bits.mask (), sign));
551 : 109544167 : break;
552 : 0 : default:
553 : 0 : gcc_unreachable ();
554 : : }
555 : :
556 : 164654032 : wide_int mask = wide_int::from (widest_mask, prec, sign);
557 : 329308064 : wide_int value = wide_int::from (widest_value, prec, sign);
558 : : // Bitmasks must have the unknown value bits cleared.
559 : 164654032 : value &= ~mask;
560 : 329308064 : irange_bitmask bm (value, mask);
561 : 164654032 : r.update_bitmask (bm);
562 : 164654971 : }
563 : :
564 : : // Return the upper limit for a type.
565 : :
566 : : static inline wide_int
567 : 16474718 : max_limit (const_tree type)
568 : : {
569 : 16474718 : return irange_val_max (type);
570 : : }
571 : :
572 : : // Return the lower limit for a type.
573 : :
574 : : static inline wide_int
575 : 19565301 : min_limit (const_tree type)
576 : : {
577 : 19565301 : return irange_val_min (type);
578 : : }
579 : :
580 : : // Return false if shifting by OP is undefined behavior. Otherwise, return
581 : : // true and the range it is to be shifted by. This allows trimming out of
582 : : // undefined ranges, leaving only valid ranges if there are any.
583 : :
584 : : static inline bool
585 : 4996552 : get_shift_range (irange &r, tree type, const irange &op)
586 : : {
587 : 4996552 : if (op.undefined_p ())
588 : : return false;
589 : :
590 : : // Build valid range and intersect it with the shift range.
591 : 4996067 : r.set (op.type (),
592 : 9992134 : wi::shwi (0, TYPE_PRECISION (op.type ())),
593 : 4996067 : wi::shwi (TYPE_PRECISION (type) - 1, TYPE_PRECISION (op.type ())));
594 : 4996067 : r.intersect (op);
595 : :
596 : : // If there are no valid ranges in the shift range, returned false.
597 : 4996067 : if (r.undefined_p ())
598 : : return false;
599 : : return true;
600 : : }
601 : :
602 : : // Default wide_int fold operation returns [MIN, MAX].
603 : :
604 : : void
605 : 0 : range_operator::wi_fold (irange &r, tree type,
606 : : const wide_int &lh_lb ATTRIBUTE_UNUSED,
607 : : const wide_int &lh_ub ATTRIBUTE_UNUSED,
608 : : const wide_int &rh_lb ATTRIBUTE_UNUSED,
609 : : const wide_int &rh_ub ATTRIBUTE_UNUSED) const
610 : : {
611 : 0 : gcc_checking_assert (r.supports_type_p (type));
612 : 0 : r.set_varying (type);
613 : 0 : }
614 : :
615 : : // Call wi_fold when both op1 and op2 are equivalent. Further split small
616 : : // subranges into constants. This can provide better precision.
617 : : // For x + y, when x == y with a range of [0,4] instead of [0, 8] produce
618 : : // [0,0][2, 2][4,4][6, 6][8, 8]
619 : : // LIMIT is the maximum number of elements in range allowed before we
620 : : // do not process them individually.
621 : :
622 : : void
623 : 57223 : range_operator::wi_fold_in_parts_equiv (irange &r, tree type,
624 : : const wide_int &lh_lb,
625 : : const wide_int &lh_ub,
626 : : unsigned limit) const
627 : : {
628 : 57223 : int_range_max tmp;
629 : 114446 : widest_int lh_range = wi::sub (widest_int::from (lh_ub, TYPE_SIGN (type)),
630 : 114446 : widest_int::from (lh_lb, TYPE_SIGN (type)));
631 : : // if there are 1 to 8 values in the LH range, split them up.
632 : 57223 : r.set_undefined ();
633 : 114446 : if (lh_range >= 0 && lh_range < limit)
634 : : {
635 : 18483 : for (unsigned x = 0; x <= lh_range; x++)
636 : : {
637 : 12716 : wide_int val = lh_lb + x;
638 : 12716 : wi_fold (tmp, type, val, val, val, val);
639 : 12716 : r.union_ (tmp);
640 : 12716 : }
641 : : }
642 : : // Otherwise just call wi_fold.
643 : : else
644 : 51456 : wi_fold (r, type, lh_lb, lh_ub, lh_lb, lh_ub);
645 : 57223 : }
646 : :
647 : : // Call wi_fold, except further split small subranges into constants.
648 : : // This can provide better precision. For something 8 >> [0,1]
649 : : // Instead of [8, 16], we will produce [8,8][16,16]
650 : :
651 : : void
652 : 146808580 : range_operator::wi_fold_in_parts (irange &r, tree type,
653 : : const wide_int &lh_lb,
654 : : const wide_int &lh_ub,
655 : : const wide_int &rh_lb,
656 : : const wide_int &rh_ub) const
657 : : {
658 : 146808580 : int_range_max tmp;
659 : 293617160 : widest_int rh_range = wi::sub (widest_int::from (rh_ub, TYPE_SIGN (type)),
660 : 293617160 : widest_int::from (rh_lb, TYPE_SIGN (type)));
661 : 293617160 : widest_int lh_range = wi::sub (widest_int::from (lh_ub, TYPE_SIGN (type)),
662 : 293617160 : widest_int::from (lh_lb, TYPE_SIGN (type)));
663 : : // If there are 2, 3, or 4 values in the RH range, do them separately.
664 : : // Call wi_fold_in_parts to check the RH side.
665 : 146808580 : if (rh_range > 0 && rh_range < 4)
666 : : {
667 : 5244378 : wi_fold_in_parts (r, type, lh_lb, lh_ub, rh_lb, rh_lb);
668 : 5244378 : if (rh_range > 1)
669 : : {
670 : 575788 : wi_fold_in_parts (tmp, type, lh_lb, lh_ub, rh_lb + 1, rh_lb + 1);
671 : 575788 : r.union_ (tmp);
672 : 575788 : if (rh_range == 3)
673 : : {
674 : 358803 : wi_fold_in_parts (tmp, type, lh_lb, lh_ub, rh_lb + 2, rh_lb + 2);
675 : 358803 : r.union_ (tmp);
676 : : }
677 : : }
678 : 5244378 : wi_fold_in_parts (tmp, type, lh_lb, lh_ub, rh_ub, rh_ub);
679 : 5244378 : r.union_ (tmp);
680 : : }
681 : : // Otherwise check for 2, 3, or 4 values in the LH range and split them up.
682 : : // The RH side has been checked, so no recursion needed.
683 : 141564202 : else if (lh_range > 0 && lh_range < 4)
684 : : {
685 : 10342271 : wi_fold (r, type, lh_lb, lh_lb, rh_lb, rh_ub);
686 : 10342271 : if (lh_range > 1)
687 : : {
688 : 1798247 : wi_fold (tmp, type, lh_lb + 1, lh_lb + 1, rh_lb, rh_ub);
689 : 1798239 : r.union_ (tmp);
690 : 1798239 : if (lh_range == 3)
691 : : {
692 : 760520 : wi_fold (tmp, type, lh_lb + 2, lh_lb + 2, rh_lb, rh_ub);
693 : 760516 : r.union_ (tmp);
694 : : }
695 : : }
696 : 10342271 : wi_fold (tmp, type, lh_ub, lh_ub, rh_lb, rh_ub);
697 : 10342271 : r.union_ (tmp);
698 : : }
699 : : // Otherwise just call wi_fold.
700 : : else
701 : 131221931 : wi_fold (r, type, lh_lb, lh_ub, rh_lb, rh_ub);
702 : 146808930 : }
703 : :
704 : : // The default for fold is to break all ranges into sub-ranges and
705 : : // invoke the wi_fold method on each sub-range pair.
706 : :
707 : : bool
708 : 102551128 : range_operator::fold_range (irange &r, tree type,
709 : : const irange &lh,
710 : : const irange &rh,
711 : : relation_trio trio) const
712 : : {
713 : 102551128 : gcc_checking_assert (r.supports_type_p (type));
714 : 102551128 : if (empty_range_varying (r, type, lh, rh))
715 : 48560 : return true;
716 : :
717 : 102502568 : relation_kind rel = trio.op1_op2 ();
718 : 102502568 : unsigned num_lh = lh.num_pairs ();
719 : 102502568 : unsigned num_rh = rh.num_pairs ();
720 : :
721 : : // If op1 and op2 are equivalences, then we don't need a complete cross
722 : : // product, just pairs of matching elements.
723 : 102502950 : if (relation_equiv_p (rel) && lh == rh)
724 : : {
725 : 53447 : int_range_max tmp;
726 : 53447 : r.set_undefined ();
727 : 95179 : for (unsigned x = 0; x < num_lh; ++x)
728 : : {
729 : : // If the number of subranges is too high, limit subrange creation.
730 : 57223 : unsigned limit = (r.num_pairs () > 32) ? 0 : 8;
731 : 57223 : wide_int lh_lb = lh.lower_bound (x);
732 : 57223 : wide_int lh_ub = lh.upper_bound (x);
733 : 57223 : wi_fold_in_parts_equiv (tmp, type, lh_lb, lh_ub, limit);
734 : 57223 : r.union_ (tmp);
735 : 57223 : if (r.varying_p ())
736 : : break;
737 : 57223 : }
738 : 53447 : op1_op2_relation_effect (r, type, lh, rh, rel);
739 : 53447 : update_bitmask (r, lh, rh);
740 : 53447 : return true;
741 : 53447 : }
742 : :
743 : : // If both ranges are single pairs, fold directly into the result range.
744 : : // If the number of subranges grows too high, produce a summary result as the
745 : : // loop becomes exponential with little benefit. See PR 103821.
746 : 102449121 : if ((num_lh == 1 && num_rh == 1) || num_lh * num_rh > 12)
747 : : {
748 : 84720507 : wi_fold_in_parts (r, type, lh.lower_bound (), lh.upper_bound (),
749 : 169438730 : rh.lower_bound (), rh.upper_bound ());
750 : 84719365 : op1_op2_relation_effect (r, type, lh, rh, rel);
751 : 84719365 : update_bitmask (r, lh, rh);
752 : 84719365 : return true;
753 : : }
754 : :
755 : 17729756 : int_range_max tmp;
756 : 17729756 : r.set_undefined ();
757 : 56023061 : for (unsigned x = 0; x < num_lh; ++x)
758 : 88959173 : for (unsigned y = 0; y < num_rh; ++y)
759 : : {
760 : 50665868 : wide_int lh_lb = lh.lower_bound (x);
761 : 50665868 : wide_int lh_ub = lh.upper_bound (x);
762 : 50665868 : wide_int rh_lb = rh.lower_bound (y);
763 : 50665868 : wide_int rh_ub = rh.upper_bound (y);
764 : 50665868 : wi_fold_in_parts (tmp, type, lh_lb, lh_ub, rh_lb, rh_ub);
765 : 50665868 : r.union_ (tmp);
766 : 50665868 : if (r.varying_p ())
767 : : {
768 : 4035757 : op1_op2_relation_effect (r, type, lh, rh, rel);
769 : 4035757 : update_bitmask (r, lh, rh);
770 : 4035757 : return true;
771 : : }
772 : 50666957 : }
773 : 13693999 : op1_op2_relation_effect (r, type, lh, rh, rel);
774 : 13693999 : update_bitmask (r, lh, rh);
775 : 13693999 : return true;
776 : 17729756 : }
777 : :
778 : :
779 : : bool
780 : 72298 : range_operator::fold_range (frange &, tree, const irange &,
781 : : const frange &, relation_trio) const
782 : : {
783 : 72298 : return false;
784 : : }
785 : :
786 : : bool
787 : 1553 : range_operator::op1_range (irange &, tree, const frange &,
788 : : const irange &, relation_trio) const
789 : : {
790 : 1553 : return false;
791 : : }
792 : :
793 : :
794 : :
795 : : // The default for op1_range is to return false.
796 : :
797 : : bool
798 : 762595 : range_operator::op1_range (irange &r ATTRIBUTE_UNUSED,
799 : : tree type ATTRIBUTE_UNUSED,
800 : : const irange &lhs ATTRIBUTE_UNUSED,
801 : : const irange &op2 ATTRIBUTE_UNUSED,
802 : : relation_trio) const
803 : : {
804 : 762595 : return false;
805 : : }
806 : :
807 : : // The default for op2_range is to return false.
808 : :
809 : : bool
810 : 559054 : range_operator::op2_range (irange &r ATTRIBUTE_UNUSED,
811 : : tree type ATTRIBUTE_UNUSED,
812 : : const irange &lhs ATTRIBUTE_UNUSED,
813 : : const irange &op1 ATTRIBUTE_UNUSED,
814 : : relation_trio) const
815 : : {
816 : 559054 : return false;
817 : : }
818 : :
819 : : // The default relation routines return VREL_VARYING.
820 : :
821 : : relation_kind
822 : 23435739 : range_operator::lhs_op1_relation (const irange &lhs ATTRIBUTE_UNUSED,
823 : : const irange &op1 ATTRIBUTE_UNUSED,
824 : : const irange &op2 ATTRIBUTE_UNUSED,
825 : : relation_kind rel ATTRIBUTE_UNUSED) const
826 : : {
827 : 23435739 : return VREL_VARYING;
828 : : }
829 : :
830 : : relation_kind
831 : 17586048 : range_operator::lhs_op2_relation (const irange &lhs ATTRIBUTE_UNUSED,
832 : : const irange &op1 ATTRIBUTE_UNUSED,
833 : : const irange &op2 ATTRIBUTE_UNUSED,
834 : : relation_kind rel ATTRIBUTE_UNUSED) const
835 : : {
836 : 17586048 : return VREL_VARYING;
837 : : }
838 : :
839 : : relation_kind
840 : 14642413 : range_operator::op1_op2_relation (const irange &lhs ATTRIBUTE_UNUSED,
841 : : const irange &op1 ATTRIBUTE_UNUSED,
842 : : const irange &op2 ATTRIBUTE_UNUSED) const
843 : : {
844 : 14642413 : return VREL_VARYING;
845 : : }
846 : :
847 : : // Default is no relation affects the LHS.
848 : :
849 : : bool
850 : 84032829 : range_operator::op1_op2_relation_effect (irange &lhs_range ATTRIBUTE_UNUSED,
851 : : tree type ATTRIBUTE_UNUSED,
852 : : const irange &op1_range
853 : : ATTRIBUTE_UNUSED,
854 : : const irange &op2_range
855 : : ATTRIBUTE_UNUSED,
856 : : relation_kind rel
857 : : ATTRIBUTE_UNUSED) const
858 : : {
859 : 84032829 : return false;
860 : : }
861 : :
862 : : bool
863 : 0 : range_operator::overflow_free_p (const irange &, const irange &,
864 : : relation_trio) const
865 : : {
866 : 0 : return false;
867 : : }
868 : :
869 : : // Apply any known bitmask updates based on this operator.
870 : :
871 : : void
872 : 6243 : range_operator::update_bitmask (irange &, const irange &,
873 : : const irange &) const
874 : : {
875 : 6243 : }
876 : :
877 : : // Check that operand types are OK. Default to always OK.
878 : :
879 : : bool
880 : 123116721 : range_operator::operand_check_p (tree, tree, tree) const
881 : : {
882 : 123116721 : return true;
883 : : }
884 : :
885 : : // Create and return a range from a pair of wide-ints that are known
886 : : // to have overflowed (or underflowed).
887 : :
888 : : static void
889 : 42361735 : value_range_from_overflowed_bounds (irange &r, tree type,
890 : : const wide_int &wmin,
891 : : const wide_int &wmax)
892 : : {
893 : 42361735 : const signop sgn = TYPE_SIGN (type);
894 : 42361735 : const unsigned int prec = TYPE_PRECISION (type);
895 : :
896 : 42361735 : wide_int tmin = wide_int::from (wmin, prec, sgn);
897 : 42361735 : wide_int tmax = wide_int::from (wmax, prec, sgn);
898 : :
899 : 42361735 : bool covers = false;
900 : 42361735 : wide_int tem = tmin;
901 : 42361735 : tmin = tmax + 1;
902 : 42361735 : if (wi::cmp (tmin, tmax, sgn) < 0)
903 : 2824635 : covers = true;
904 : 42361735 : tmax = tem - 1;
905 : 42361735 : if (wi::cmp (tmax, tem, sgn) > 0)
906 : : covers = true;
907 : :
908 : : // If the anti-range would cover nothing, drop to varying.
909 : : // Likewise if the anti-range bounds are outside of the types
910 : : // values.
911 : 39742317 : if (covers || wi::cmp (tmin, tmax, sgn) > 0)
912 : 29019307 : r.set_varying (type);
913 : : else
914 : 13342428 : r.set (type, tmin, tmax, VR_ANTI_RANGE);
915 : 42362330 : }
916 : :
917 : : // Create and return a range from a pair of wide-ints. MIN_OVF and
918 : : // MAX_OVF describe any overflow that might have occurred while
919 : : // calculating WMIN and WMAX respectively.
920 : :
921 : : static void
922 : 143541953 : value_range_with_overflow (irange &r, tree type,
923 : : const wide_int &wmin, const wide_int &wmax,
924 : : wi::overflow_type min_ovf = wi::OVF_NONE,
925 : : wi::overflow_type max_ovf = wi::OVF_NONE)
926 : : {
927 : 143541953 : const signop sgn = TYPE_SIGN (type);
928 : 143541953 : const unsigned int prec = TYPE_PRECISION (type);
929 : 227917011 : const bool overflow_wraps = TYPE_OVERFLOW_WRAPS (type);
930 : :
931 : : // For one bit precision if max != min, then the range covers all
932 : : // values.
933 : 158466213 : if (prec == 1 && wi::ne_p (wmax, wmin))
934 : : {
935 : 0 : r.set_varying (type);
936 : 0 : return;
937 : : }
938 : :
939 : 143541953 : if (overflow_wraps)
940 : : {
941 : : // If overflow wraps, truncate the values and adjust the range,
942 : : // kind, and bounds appropriately.
943 : 84375058 : if ((min_ovf != wi::OVF_NONE) == (max_ovf != wi::OVF_NONE))
944 : : {
945 : 59081185 : wide_int tmin = wide_int::from (wmin, prec, sgn);
946 : 59081185 : wide_int tmax = wide_int::from (wmax, prec, sgn);
947 : : // If the limits are swapped, we wrapped around and cover
948 : : // the entire range.
949 : 59081185 : if (wi::gt_p (tmin, tmax, sgn))
950 : 543017 : r.set_varying (type);
951 : : else
952 : : // No overflow or both overflow or underflow. The range
953 : : // kind stays normal.
954 : 58538168 : r.set (type, tmin, tmax);
955 : 59081185 : return;
956 : 59081323 : }
957 : :
958 : 25293873 : if ((min_ovf == wi::OVF_UNDERFLOW && max_ovf == wi::OVF_NONE)
959 : 17785523 : || (max_ovf == wi::OVF_OVERFLOW && min_ovf == wi::OVF_NONE))
960 : 25293873 : value_range_from_overflowed_bounds (r, type, wmin, wmax);
961 : : else
962 : : // Other underflow and/or overflow, drop to VR_VARYING.
963 : 0 : r.set_varying (type);
964 : : }
965 : : else
966 : : {
967 : : // If both bounds either underflowed or overflowed, then the result
968 : : // is undefined.
969 : 59166895 : if ((min_ovf == wi::OVF_OVERFLOW && max_ovf == wi::OVF_OVERFLOW)
970 : 59164361 : || (min_ovf == wi::OVF_UNDERFLOW && max_ovf == wi::OVF_UNDERFLOW))
971 : : {
972 : 4032 : r.set_undefined ();
973 : 4032 : return;
974 : : }
975 : :
976 : : // If overflow does not wrap, saturate to [MIN, MAX].
977 : 59162863 : wide_int new_lb, new_ub;
978 : 59162863 : if (min_ovf == wi::OVF_UNDERFLOW)
979 : 7163567 : new_lb = wi::min_value (prec, sgn);
980 : 51999507 : else if (min_ovf == wi::OVF_OVERFLOW)
981 : 0 : new_lb = wi::max_value (prec, sgn);
982 : : else
983 : 51999507 : new_lb = wmin;
984 : :
985 : 59162863 : if (max_ovf == wi::OVF_UNDERFLOW)
986 : 0 : new_ub = wi::min_value (prec, sgn);
987 : 59162863 : else if (max_ovf == wi::OVF_OVERFLOW)
988 : 12018947 : new_ub = wi::max_value (prec, sgn);
989 : : else
990 : 47144171 : new_ub = wmax;
991 : :
992 : 59162863 : r.set (type, new_lb, new_ub);
993 : 59163437 : }
994 : : }
995 : :
996 : : // Create and return a range from a pair of wide-ints. Canonicalize
997 : : // the case where the bounds are swapped. In which case, we transform
998 : : // [10,5] into [MIN,5][10,MAX].
999 : :
1000 : : static inline void
1001 : 84929126 : create_possibly_reversed_range (irange &r, tree type,
1002 : : const wide_int &new_lb, const wide_int &new_ub)
1003 : : {
1004 : 84929126 : signop s = TYPE_SIGN (type);
1005 : : // If the bounds are swapped, treat the result as if an overflow occurred.
1006 : 84929126 : if (wi::gt_p (new_lb, new_ub, s))
1007 : 17067862 : value_range_from_overflowed_bounds (r, type, new_lb, new_ub);
1008 : : else
1009 : : // Otherwise it's just a normal range.
1010 : 67861264 : r.set (type, new_lb, new_ub);
1011 : 84929126 : }
1012 : :
1013 : : // Return the summary information about boolean range LHS. If EMPTY/FULL,
1014 : : // return the equivalent range for TYPE in R; if FALSE/TRUE, do nothing.
1015 : :
1016 : : bool_range_state
1017 : 84081774 : get_bool_state (vrange &r, const vrange &lhs, tree val_type)
1018 : : {
1019 : : // If there is no result, then this is unexecutable.
1020 : 84081774 : if (lhs.undefined_p ())
1021 : : {
1022 : 0 : r.set_undefined ();
1023 : 0 : return BRS_EMPTY;
1024 : : }
1025 : :
1026 : 84081774 : if (lhs.zero_p ())
1027 : : return BRS_FALSE;
1028 : :
1029 : : // For TRUE, we can't just test for [1,1] because Ada can have
1030 : : // multi-bit booleans, and TRUE values can be: [1, MAX], ~[0], etc.
1031 : 43166102 : if (lhs.contains_p (build_zero_cst (lhs.type ())))
1032 : : {
1033 : 177451 : r.set_varying (val_type);
1034 : 177451 : return BRS_FULL;
1035 : : }
1036 : :
1037 : : return BRS_TRUE;
1038 : : }
1039 : :
1040 : : // ------------------------------------------------------------------------
1041 : :
1042 : : void
1043 : 0 : operator_equal::update_bitmask (irange &r, const irange &lh,
1044 : : const irange &rh) const
1045 : : {
1046 : 0 : update_known_bitmask (r, EQ_EXPR, lh, rh);
1047 : 0 : }
1048 : :
1049 : : // Check if the LHS range indicates a relation between OP1 and OP2.
1050 : :
1051 : : relation_kind
1052 : 5927201 : operator_equal::op1_op2_relation (const irange &lhs, const irange &,
1053 : : const irange &) const
1054 : : {
1055 : 5927201 : if (lhs.undefined_p ())
1056 : : return VREL_UNDEFINED;
1057 : :
1058 : : // FALSE = op1 == op2 indicates NE_EXPR.
1059 : 5927201 : if (lhs.zero_p ())
1060 : : return VREL_NE;
1061 : :
1062 : : // TRUE = op1 == op2 indicates EQ_EXPR.
1063 : 3108885 : if (!contains_zero_p (lhs))
1064 : 3073505 : return VREL_EQ;
1065 : : return VREL_VARYING;
1066 : : }
1067 : :
1068 : : bool
1069 : 18538980 : operator_equal::fold_range (irange &r, tree type,
1070 : : const irange &op1,
1071 : : const irange &op2,
1072 : : relation_trio rel) const
1073 : : {
1074 : 18538980 : if (relop_early_resolve (r, type, op1, op2, rel, VREL_EQ))
1075 : : return true;
1076 : :
1077 : : // We can be sure the values are always equal or not if both ranges
1078 : : // consist of a single value, and then compare them.
1079 : 18506133 : bool op1_const = wi::eq_p (op1.lower_bound (), op1.upper_bound ());
1080 : 18506133 : bool op2_const = wi::eq_p (op2.lower_bound (), op2.upper_bound ());
1081 : 18506123 : if (op1_const && op2_const)
1082 : : {
1083 : 300627 : if (wi::eq_p (op1.lower_bound (), op2.upper_bound()))
1084 : 158796 : r = range_true (type);
1085 : : else
1086 : 141831 : r = range_false (type);
1087 : : }
1088 : : else
1089 : : {
1090 : : // If ranges do not intersect, we know the range is not equal,
1091 : : // otherwise we don't know anything for sure.
1092 : 18205496 : int_range_max tmp = op1;
1093 : 18205496 : tmp.intersect (op2);
1094 : 18205496 : if (tmp.undefined_p ())
1095 : 241407 : r = range_false (type);
1096 : : // Check if a constant cannot satisfy the bitmask requirements.
1097 : 33512821 : else if (op2_const && !op1.get_bitmask ().member_p (op2.lower_bound ()))
1098 : 506 : r = range_false (type);
1099 : 18022258 : else if (op1_const && !op2.get_bitmask ().member_p (op1.lower_bound ()))
1100 : 0 : r = range_false (type);
1101 : : else
1102 : 17963583 : r = range_true_and_false (type);
1103 : 18205496 : }
1104 : : return true;
1105 : : }
1106 : :
1107 : : bool
1108 : 11798089 : operator_equal::op1_range (irange &r, tree type,
1109 : : const irange &lhs,
1110 : : const irange &op2,
1111 : : relation_trio) const
1112 : : {
1113 : 11798089 : switch (get_bool_state (r, lhs, type))
1114 : : {
1115 : 3406890 : case BRS_TRUE:
1116 : : // If it's true, the result is the same as OP2.
1117 : 3406890 : r = op2;
1118 : 3406890 : break;
1119 : :
1120 : 8350149 : case BRS_FALSE:
1121 : : // If the result is false, the only time we know anything is
1122 : : // if OP2 is a constant.
1123 : 8350149 : if (!op2.undefined_p ()
1124 : 25050447 : && wi::eq_p (op2.lower_bound(), op2.upper_bound()))
1125 : : {
1126 : 6664702 : r = op2;
1127 : 6664702 : r.invert ();
1128 : : }
1129 : : else
1130 : 1685447 : r.set_varying (type);
1131 : : break;
1132 : :
1133 : : default:
1134 : : break;
1135 : : }
1136 : 11798089 : return true;
1137 : : }
1138 : :
1139 : : bool
1140 : 1559272 : operator_equal::op2_range (irange &r, tree type,
1141 : : const irange &lhs,
1142 : : const irange &op1,
1143 : : relation_trio rel) const
1144 : : {
1145 : 1559272 : return operator_equal::op1_range (r, type, lhs, op1, rel.swap_op1_op2 ());
1146 : : }
1147 : :
1148 : : // -------------------------------------------------------------------------
1149 : :
1150 : : void
1151 : 0 : operator_not_equal::update_bitmask (irange &r, const irange &lh,
1152 : : const irange &rh) const
1153 : : {
1154 : 0 : update_known_bitmask (r, NE_EXPR, lh, rh);
1155 : 0 : }
1156 : :
1157 : : // Check if the LHS range indicates a relation between OP1 and OP2.
1158 : :
1159 : : relation_kind
1160 : 10864117 : operator_not_equal::op1_op2_relation (const irange &lhs, const irange &,
1161 : : const irange &) const
1162 : : {
1163 : 10864117 : if (lhs.undefined_p ())
1164 : : return VREL_UNDEFINED;
1165 : :
1166 : : // FALSE = op1 != op2 indicates EQ_EXPR.
1167 : 10864117 : if (lhs.zero_p ())
1168 : : return VREL_EQ;
1169 : :
1170 : : // TRUE = op1 != op2 indicates NE_EXPR.
1171 : 5495248 : if (!contains_zero_p (lhs))
1172 : 5455661 : return VREL_NE;
1173 : : return VREL_VARYING;
1174 : : }
1175 : :
1176 : : bool
1177 : 27328419 : operator_not_equal::fold_range (irange &r, tree type,
1178 : : const irange &op1,
1179 : : const irange &op2,
1180 : : relation_trio rel) const
1181 : : {
1182 : 27328419 : if (relop_early_resolve (r, type, op1, op2, rel, VREL_NE))
1183 : : return true;
1184 : :
1185 : : // We can be sure the values are always equal or not if both ranges
1186 : : // consist of a single value, and then compare them.
1187 : 27306680 : bool op1_const = wi::eq_p (op1.lower_bound (), op1.upper_bound ());
1188 : 27306680 : bool op2_const = wi::eq_p (op2.lower_bound (), op2.upper_bound ());
1189 : 27306347 : if (op1_const && op2_const)
1190 : : {
1191 : 1129497 : if (wi::ne_p (op1.lower_bound (), op2.upper_bound()))
1192 : 637919 : r = range_true (type);
1193 : : else
1194 : 491576 : r = range_false (type);
1195 : : }
1196 : : else
1197 : : {
1198 : : // If ranges do not intersect, we know the range is not equal,
1199 : : // otherwise we don't know anything for sure.
1200 : 26176852 : int_range_max tmp = op1;
1201 : 26176852 : tmp.intersect (op2);
1202 : 26176852 : if (tmp.undefined_p ())
1203 : 202670 : r = range_true (type);
1204 : : // Check if a constant cannot satisfy the bitmask requirements.
1205 : 47423700 : else if (op2_const && !op1.get_bitmask ().member_p (op2.lower_bound ()))
1206 : 491 : r = range_true (type);
1207 : 26012232 : else if (op1_const && !op2.get_bitmask ().member_p (op1.lower_bound ()))
1208 : 0 : r = range_true (type);
1209 : : else
1210 : 25973691 : r = range_true_and_false (type);
1211 : 26176852 : }
1212 : : return true;
1213 : : }
1214 : :
1215 : : bool
1216 : 22063086 : operator_not_equal::op1_range (irange &r, tree type,
1217 : : const irange &lhs,
1218 : : const irange &op2,
1219 : : relation_trio) const
1220 : : {
1221 : 22063086 : switch (get_bool_state (r, lhs, type))
1222 : : {
1223 : 13916925 : case BRS_TRUE:
1224 : : // If the result is true, the only time we know anything is if
1225 : : // OP2 is a constant.
1226 : 13916925 : if (!op2.undefined_p ()
1227 : 41750775 : && wi::eq_p (op2.lower_bound(), op2.upper_bound()))
1228 : : {
1229 : 10915924 : r = op2;
1230 : 10915924 : r.invert ();
1231 : : }
1232 : : else
1233 : 3001001 : r.set_varying (type);
1234 : : break;
1235 : :
1236 : 8119879 : case BRS_FALSE:
1237 : : // If it's false, the result is the same as OP2.
1238 : 8119879 : r = op2;
1239 : 8119879 : break;
1240 : :
1241 : : default:
1242 : : break;
1243 : : }
1244 : 22063086 : return true;
1245 : : }
1246 : :
1247 : :
1248 : : bool
1249 : 2754242 : operator_not_equal::op2_range (irange &r, tree type,
1250 : : const irange &lhs,
1251 : : const irange &op1,
1252 : : relation_trio rel) const
1253 : : {
1254 : 2754242 : return operator_not_equal::op1_range (r, type, lhs, op1, rel.swap_op1_op2 ());
1255 : : }
1256 : :
1257 : : // (X < VAL) produces the range of [MIN, VAL - 1].
1258 : :
1259 : : static void
1260 : 6515070 : build_lt (irange &r, tree type, const wide_int &val)
1261 : : {
1262 : 6515070 : wi::overflow_type ov;
1263 : 6515070 : wide_int lim;
1264 : 6515070 : signop sgn = TYPE_SIGN (type);
1265 : :
1266 : : // Signed 1 bit cannot represent 1 for subtraction.
1267 : 6515070 : if (sgn == SIGNED)
1268 : 4454110 : lim = wi::add (val, -1, sgn, &ov);
1269 : : else
1270 : 2061020 : lim = wi::sub (val, 1, sgn, &ov);
1271 : :
1272 : : // If val - 1 underflows, check if X < MIN, which is an empty range.
1273 : 6515070 : if (ov)
1274 : 513 : r.set_undefined ();
1275 : : else
1276 : 6514617 : r = int_range<1> (type, min_limit (type), lim);
1277 : 6515070 : }
1278 : :
1279 : : // (X <= VAL) produces the range of [MIN, VAL].
1280 : :
1281 : : static void
1282 : 13050716 : build_le (irange &r, tree type, const wide_int &val)
1283 : : {
1284 : 13050716 : r = int_range<1> (type, min_limit (type), val);
1285 : 13050716 : }
1286 : :
1287 : : // (X > VAL) produces the range of [VAL + 1, MAX].
1288 : :
1289 : : static void
1290 : 9746764 : build_gt (irange &r, tree type, const wide_int &val)
1291 : : {
1292 : 9746764 : wi::overflow_type ov;
1293 : 9746764 : wide_int lim;
1294 : 9746764 : signop sgn = TYPE_SIGN (type);
1295 : :
1296 : : // Signed 1 bit cannot represent 1 for addition.
1297 : 9746764 : if (sgn == SIGNED)
1298 : 5271910 : lim = wi::sub (val, -1, sgn, &ov);
1299 : : else
1300 : 4474940 : lim = wi::add (val, 1, sgn, &ov);
1301 : : // If val + 1 overflows, check is for X > MAX, which is an empty range.
1302 : 9746764 : if (ov)
1303 : 0 : r.set_undefined ();
1304 : : else
1305 : 9746850 : r = int_range<1> (type, lim, max_limit (type));
1306 : 9746764 : }
1307 : :
1308 : : // (X >= val) produces the range of [VAL, MAX].
1309 : :
1310 : : static void
1311 : 6727926 : build_ge (irange &r, tree type, const wide_int &val)
1312 : : {
1313 : 6727926 : r = int_range<1> (type, val, max_limit (type));
1314 : 6727926 : }
1315 : :
1316 : :
1317 : : void
1318 : 0 : operator_lt::update_bitmask (irange &r, const irange &lh,
1319 : : const irange &rh) const
1320 : : {
1321 : 0 : update_known_bitmask (r, LT_EXPR, lh, rh);
1322 : 0 : }
1323 : :
1324 : : // Check if the LHS range indicates a relation between OP1 and OP2.
1325 : :
1326 : : relation_kind
1327 : 11729900 : operator_lt::op1_op2_relation (const irange &lhs, const irange &,
1328 : : const irange &) const
1329 : : {
1330 : 11729900 : if (lhs.undefined_p ())
1331 : : return VREL_UNDEFINED;
1332 : :
1333 : : // FALSE = op1 < op2 indicates GE_EXPR.
1334 : 11729900 : if (lhs.zero_p ())
1335 : : return VREL_GE;
1336 : :
1337 : : // TRUE = op1 < op2 indicates LT_EXPR.
1338 : 5926960 : if (!contains_zero_p (lhs))
1339 : 5919395 : return VREL_LT;
1340 : : return VREL_VARYING;
1341 : : }
1342 : :
1343 : : bool
1344 : 6273998 : operator_lt::fold_range (irange &r, tree type,
1345 : : const irange &op1,
1346 : : const irange &op2,
1347 : : relation_trio rel) const
1348 : : {
1349 : 6273998 : if (relop_early_resolve (r, type, op1, op2, rel, VREL_LT))
1350 : : return true;
1351 : :
1352 : 6250878 : signop sign = TYPE_SIGN (op1.type ());
1353 : 6250878 : gcc_checking_assert (sign == TYPE_SIGN (op2.type ()));
1354 : :
1355 : 6250914 : if (wi::lt_p (op1.upper_bound (), op2.lower_bound (), sign))
1356 : 22098 : r = range_true (type);
1357 : 6228816 : else if (!wi::lt_p (op1.lower_bound (), op2.upper_bound (), sign))
1358 : 64435 : r = range_false (type);
1359 : : // Use nonzero bits to determine if < 0 is false.
1360 : 8065914 : else if (op2.zero_p () && !wi::neg_p (op1.get_nonzero_bits (), sign))
1361 : 0 : r = range_false (type);
1362 : : else
1363 : 6164345 : r = range_true_and_false (type);
1364 : : return true;
1365 : : }
1366 : :
1367 : : bool
1368 : 5089851 : operator_lt::op1_range (irange &r, tree type,
1369 : : const irange &lhs,
1370 : : const irange &op2,
1371 : : relation_trio) const
1372 : : {
1373 : 5089851 : if (op2.undefined_p ())
1374 : : return false;
1375 : :
1376 : 5089851 : switch (get_bool_state (r, lhs, type))
1377 : : {
1378 : 2383862 : case BRS_TRUE:
1379 : 2383862 : build_lt (r, type, op2.upper_bound ());
1380 : 2383862 : break;
1381 : :
1382 : 2701249 : case BRS_FALSE:
1383 : 2701249 : build_ge (r, type, op2.lower_bound ());
1384 : 2701249 : break;
1385 : :
1386 : : default:
1387 : : break;
1388 : : }
1389 : : return true;
1390 : : }
1391 : :
1392 : : bool
1393 : 3874404 : operator_lt::op2_range (irange &r, tree type,
1394 : : const irange &lhs,
1395 : : const irange &op1,
1396 : : relation_trio) const
1397 : : {
1398 : 3874404 : if (op1.undefined_p ())
1399 : : return false;
1400 : :
1401 : 3874402 : switch (get_bool_state (r, lhs, type))
1402 : : {
1403 : 1662641 : case BRS_TRUE:
1404 : 1662641 : build_gt (r, type, op1.lower_bound ());
1405 : 1662641 : break;
1406 : :
1407 : 2208251 : case BRS_FALSE:
1408 : 2208251 : build_le (r, type, op1.upper_bound ());
1409 : 2208251 : break;
1410 : :
1411 : : default:
1412 : : break;
1413 : : }
1414 : : return true;
1415 : : }
1416 : :
1417 : :
1418 : : void
1419 : 0 : operator_le::update_bitmask (irange &r, const irange &lh,
1420 : : const irange &rh) const
1421 : : {
1422 : 0 : update_known_bitmask (r, LE_EXPR, lh, rh);
1423 : 0 : }
1424 : :
1425 : : // Check if the LHS range indicates a relation between OP1 and OP2.
1426 : :
1427 : : relation_kind
1428 : 4237643 : operator_le::op1_op2_relation (const irange &lhs, const irange &,
1429 : : const irange &) const
1430 : : {
1431 : 4237643 : if (lhs.undefined_p ())
1432 : : return VREL_UNDEFINED;
1433 : :
1434 : : // FALSE = op1 <= op2 indicates GT_EXPR.
1435 : 4237643 : if (lhs.zero_p ())
1436 : : return VREL_GT;
1437 : :
1438 : : // TRUE = op1 <= op2 indicates LE_EXPR.
1439 : 2480744 : if (!contains_zero_p (lhs))
1440 : 2471426 : return VREL_LE;
1441 : : return VREL_VARYING;
1442 : : }
1443 : :
1444 : : bool
1445 : 5235047 : operator_le::fold_range (irange &r, tree type,
1446 : : const irange &op1,
1447 : : const irange &op2,
1448 : : relation_trio rel) const
1449 : : {
1450 : 5235047 : if (relop_early_resolve (r, type, op1, op2, rel, VREL_LE))
1451 : : return true;
1452 : :
1453 : 5221034 : signop sign = TYPE_SIGN (op1.type ());
1454 : 5221034 : gcc_checking_assert (sign == TYPE_SIGN (op2.type ()));
1455 : :
1456 : 5221034 : if (wi::le_p (op1.upper_bound (), op2.lower_bound (), sign))
1457 : 111997 : r = range_true (type);
1458 : 5109037 : else if (!wi::le_p (op1.lower_bound (), op2.upper_bound (), sign))
1459 : 78600 : r = range_false (type);
1460 : : else
1461 : 5030437 : r = range_true_and_false (type);
1462 : : return true;
1463 : : }
1464 : :
1465 : : bool
1466 : 5919687 : operator_le::op1_range (irange &r, tree type,
1467 : : const irange &lhs,
1468 : : const irange &op2,
1469 : : relation_trio) const
1470 : : {
1471 : 5919687 : if (op2.undefined_p ())
1472 : : return false;
1473 : :
1474 : 5919687 : switch (get_bool_state (r, lhs, type))
1475 : : {
1476 : 3162232 : case BRS_TRUE:
1477 : 3162232 : build_le (r, type, op2.upper_bound ());
1478 : 3162232 : break;
1479 : :
1480 : 2744514 : case BRS_FALSE:
1481 : 2744514 : build_gt (r, type, op2.lower_bound ());
1482 : 2744514 : break;
1483 : :
1484 : : default:
1485 : : break;
1486 : : }
1487 : : return true;
1488 : : }
1489 : :
1490 : : bool
1491 : 1117003 : operator_le::op2_range (irange &r, tree type,
1492 : : const irange &lhs,
1493 : : const irange &op1,
1494 : : relation_trio) const
1495 : : {
1496 : 1117003 : if (op1.undefined_p ())
1497 : : return false;
1498 : :
1499 : 1117003 : switch (get_bool_state (r, lhs, type))
1500 : : {
1501 : 517275 : case BRS_TRUE:
1502 : 517275 : build_ge (r, type, op1.lower_bound ());
1503 : 517275 : break;
1504 : :
1505 : 595900 : case BRS_FALSE:
1506 : 595900 : build_lt (r, type, op1.upper_bound ());
1507 : 595900 : break;
1508 : :
1509 : : default:
1510 : : break;
1511 : : }
1512 : : return true;
1513 : : }
1514 : :
1515 : :
1516 : : void
1517 : 0 : operator_gt::update_bitmask (irange &r, const irange &lh,
1518 : : const irange &rh) const
1519 : : {
1520 : 0 : update_known_bitmask (r, GT_EXPR, lh, rh);
1521 : 0 : }
1522 : :
1523 : : // Check if the LHS range indicates a relation between OP1 and OP2.
1524 : :
1525 : : relation_kind
1526 : 11873944 : operator_gt::op1_op2_relation (const irange &lhs, const irange &,
1527 : : const irange &) const
1528 : : {
1529 : 11873944 : if (lhs.undefined_p ())
1530 : : return VREL_UNDEFINED;
1531 : :
1532 : : // FALSE = op1 > op2 indicates LE_EXPR.
1533 : 11873944 : if (lhs.zero_p ())
1534 : : return VREL_LE;
1535 : :
1536 : : // TRUE = op1 > op2 indicates GT_EXPR.
1537 : 6431822 : if (!contains_zero_p (lhs))
1538 : 6418149 : return VREL_GT;
1539 : : return VREL_VARYING;
1540 : : }
1541 : :
1542 : : bool
1543 : 11356853 : operator_gt::fold_range (irange &r, tree type,
1544 : : const irange &op1, const irange &op2,
1545 : : relation_trio rel) const
1546 : : {
1547 : 11356853 : if (relop_early_resolve (r, type, op1, op2, rel, VREL_GT))
1548 : : return true;
1549 : :
1550 : 11304052 : signop sign = TYPE_SIGN (op1.type ());
1551 : 11304052 : gcc_checking_assert (sign == TYPE_SIGN (op2.type ()));
1552 : :
1553 : 11304078 : if (wi::gt_p (op1.lower_bound (), op2.upper_bound (), sign))
1554 : 91066 : r = range_true (type);
1555 : 11213012 : else if (!wi::gt_p (op1.upper_bound (), op2.lower_bound (), sign))
1556 : 357587 : r = range_false (type);
1557 : : else
1558 : 10855399 : r = range_true_and_false (type);
1559 : : return true;
1560 : : }
1561 : :
1562 : : bool
1563 : 11593630 : operator_gt::op1_range (irange &r, tree type,
1564 : : const irange &lhs, const irange &op2,
1565 : : relation_trio) const
1566 : : {
1567 : 11593630 : if (op2.undefined_p ())
1568 : : return false;
1569 : :
1570 : 11593630 : switch (get_bool_state (r, lhs, type))
1571 : : {
1572 : 4756349 : case BRS_TRUE:
1573 : 4756349 : build_gt (r, type, op2.lower_bound ());
1574 : 4756349 : break;
1575 : :
1576 : 6828025 : case BRS_FALSE:
1577 : 6828025 : build_le (r, type, op2.upper_bound ());
1578 : 6828025 : break;
1579 : :
1580 : : default:
1581 : : break;
1582 : : }
1583 : : return true;
1584 : : }
1585 : :
1586 : : bool
1587 : 3743157 : operator_gt::op2_range (irange &r, tree type,
1588 : : const irange &lhs,
1589 : : const irange &op1,
1590 : : relation_trio) const
1591 : : {
1592 : 3743157 : if (op1.undefined_p ())
1593 : : return false;
1594 : :
1595 : 3743157 : switch (get_bool_state (r, lhs, type))
1596 : : {
1597 : 2291440 : case BRS_TRUE:
1598 : 2291440 : build_lt (r, type, op1.upper_bound ());
1599 : 2291440 : break;
1600 : :
1601 : 1442943 : case BRS_FALSE:
1602 : 1442943 : build_ge (r, type, op1.lower_bound ());
1603 : 1442943 : break;
1604 : :
1605 : : default:
1606 : : break;
1607 : : }
1608 : : return true;
1609 : : }
1610 : :
1611 : :
1612 : : void
1613 : 0 : operator_ge::update_bitmask (irange &r, const irange &lh,
1614 : : const irange &rh) const
1615 : : {
1616 : 0 : update_known_bitmask (r, GE_EXPR, lh, rh);
1617 : 0 : }
1618 : :
1619 : : // Check if the LHS range indicates a relation between OP1 and OP2.
1620 : :
1621 : : relation_kind
1622 : 4291861 : operator_ge::op1_op2_relation (const irange &lhs, const irange &,
1623 : : const irange &) const
1624 : : {
1625 : 4291861 : if (lhs.undefined_p ())
1626 : : return VREL_UNDEFINED;
1627 : :
1628 : : // FALSE = op1 >= op2 indicates LT_EXPR.
1629 : 4291861 : if (lhs.zero_p ())
1630 : : return VREL_LT;
1631 : :
1632 : : // TRUE = op1 >= op2 indicates GE_EXPR.
1633 : 2301390 : if (!contains_zero_p (lhs))
1634 : 2295656 : return VREL_GE;
1635 : : return VREL_VARYING;
1636 : : }
1637 : :
1638 : : bool
1639 : 2772355 : operator_ge::fold_range (irange &r, tree type,
1640 : : const irange &op1,
1641 : : const irange &op2,
1642 : : relation_trio rel) const
1643 : : {
1644 : 2772355 : if (relop_early_resolve (r, type, op1, op2, rel, VREL_GE))
1645 : : return true;
1646 : :
1647 : 2760604 : signop sign = TYPE_SIGN (op1.type ());
1648 : 2760604 : gcc_checking_assert (sign == TYPE_SIGN (op2.type ()));
1649 : :
1650 : 2760636 : if (wi::ge_p (op1.lower_bound (), op2.upper_bound (), sign))
1651 : 172338 : r = range_true (type);
1652 : 2588298 : else if (!wi::ge_p (op1.upper_bound (), op2.lower_bound (), sign))
1653 : 6308 : r = range_false (type);
1654 : : else
1655 : 2581958 : r = range_true_and_false (type);
1656 : : return true;
1657 : : }
1658 : :
1659 : : bool
1660 : 3316610 : operator_ge::op1_range (irange &r, tree type,
1661 : : const irange &lhs,
1662 : : const irange &op2,
1663 : : relation_trio) const
1664 : : {
1665 : 3316610 : if (op2.undefined_p ())
1666 : : return false;
1667 : :
1668 : 3316610 : switch (get_bool_state (r, lhs, type))
1669 : : {
1670 : 2066459 : case BRS_TRUE:
1671 : 2066459 : build_ge (r, type, op2.lower_bound ());
1672 : 2066459 : break;
1673 : :
1674 : 1243868 : case BRS_FALSE:
1675 : 1243868 : build_lt (r, type, op2.upper_bound ());
1676 : 1243868 : break;
1677 : :
1678 : : default:
1679 : : break;
1680 : : }
1681 : : return true;
1682 : : }
1683 : :
1684 : : bool
1685 : 1438262 : operator_ge::op2_range (irange &r, tree type,
1686 : : const irange &lhs,
1687 : : const irange &op1,
1688 : : relation_trio) const
1689 : : {
1690 : 1438262 : if (op1.undefined_p ())
1691 : : return false;
1692 : :
1693 : 1438262 : switch (get_bool_state (r, lhs, type))
1694 : : {
1695 : 852208 : case BRS_TRUE:
1696 : 852208 : build_le (r, type, op1.upper_bound ());
1697 : 852208 : break;
1698 : :
1699 : 583260 : case BRS_FALSE:
1700 : 583260 : build_gt (r, type, op1.lower_bound ());
1701 : 583260 : break;
1702 : :
1703 : : default:
1704 : : break;
1705 : : }
1706 : : return true;
1707 : : }
1708 : :
1709 : :
1710 : : void
1711 : 50929767 : operator_plus::update_bitmask (irange &r, const irange &lh,
1712 : : const irange &rh) const
1713 : : {
1714 : 50929767 : update_known_bitmask (r, PLUS_EXPR, lh, rh);
1715 : 50929767 : }
1716 : :
1717 : : // Check to see if the range of OP2 indicates anything about the relation
1718 : : // between LHS and OP1.
1719 : :
1720 : : relation_kind
1721 : 47225978 : operator_plus::lhs_op1_relation (const irange &lhs,
1722 : : const irange &op1,
1723 : : const irange &op2,
1724 : : relation_kind) const
1725 : : {
1726 : 47225978 : if (lhs.undefined_p () || op1.undefined_p () || op2.undefined_p ())
1727 : : return VREL_VARYING;
1728 : :
1729 : 47194439 : tree type = lhs.type ();
1730 : 47194439 : unsigned prec = TYPE_PRECISION (type);
1731 : 47194439 : wi::overflow_type ovf1, ovf2;
1732 : 47194439 : signop sign = TYPE_SIGN (type);
1733 : :
1734 : : // LHS = OP1 + 0 indicates LHS == OP1.
1735 : 47194439 : if (op2.zero_p ())
1736 : : return VREL_EQ;
1737 : :
1738 : 47024627 : if (TYPE_OVERFLOW_WRAPS (type))
1739 : : {
1740 : 26912636 : wi::add (op1.lower_bound (), op2.lower_bound (), sign, &ovf1);
1741 : 26912858 : wi::add (op1.upper_bound (), op2.upper_bound (), sign, &ovf2);
1742 : : }
1743 : : else
1744 : 20112435 : ovf1 = ovf2 = wi::OVF_NONE;
1745 : :
1746 : : // Never wrapping additions.
1747 : 47024627 : if (!ovf1 && !ovf2)
1748 : : {
1749 : : // Positive op2 means lhs > op1.
1750 : 27217388 : if (wi::gt_p (op2.lower_bound (), wi::zero (prec), sign))
1751 : : return VREL_GT;
1752 : 10237797 : if (wi::ge_p (op2.lower_bound (), wi::zero (prec), sign))
1753 : : return VREL_GE;
1754 : :
1755 : : // Negative op2 means lhs < op1.
1756 : 8476833 : if (wi::lt_p (op2.upper_bound (), wi::zero (prec), sign))
1757 : : return VREL_LT;
1758 : 5201619 : if (wi::le_p (op2.upper_bound (), wi::zero (prec), sign))
1759 : : return VREL_LE;
1760 : : }
1761 : : // Always wrapping additions.
1762 : 19807618 : else if (ovf1 && ovf1 == ovf2)
1763 : : {
1764 : : // Positive op2 means lhs < op1.
1765 : 755116 : if (wi::gt_p (op2.lower_bound (), wi::zero (prec), sign))
1766 : : return VREL_LT;
1767 : 20 : if (wi::ge_p (op2.lower_bound (), wi::zero (prec), sign))
1768 : : return VREL_LE;
1769 : :
1770 : : // Negative op2 means lhs > op1.
1771 : 20 : if (wi::lt_p (op2.upper_bound (), wi::zero (prec), sign))
1772 : : return VREL_GT;
1773 : 0 : if (wi::le_p (op2.upper_bound (), wi::zero (prec), sign))
1774 : : return VREL_GE;
1775 : : }
1776 : :
1777 : : // If op2 does not contain 0, then LHS and OP1 can never be equal.
1778 : 24241790 : if (!range_includes_zero_p (op2))
1779 : : return VREL_NE;
1780 : :
1781 : : return VREL_VARYING;
1782 : : }
1783 : :
1784 : : // PLUS is symmetrical, so we can simply call lhs_op1_relation with reversed
1785 : : // operands.
1786 : :
1787 : : relation_kind
1788 : 8149052 : operator_plus::lhs_op2_relation (const irange &lhs, const irange &op1,
1789 : : const irange &op2, relation_kind rel) const
1790 : : {
1791 : 8149052 : return lhs_op1_relation (lhs, op2, op1, rel);
1792 : : }
1793 : :
1794 : : void
1795 : 76174239 : operator_plus::wi_fold (irange &r, tree type,
1796 : : const wide_int &lh_lb, const wide_int &lh_ub,
1797 : : const wide_int &rh_lb, const wide_int &rh_ub) const
1798 : : {
1799 : 76174239 : wi::overflow_type ov_lb, ov_ub;
1800 : 76174239 : signop s = TYPE_SIGN (type);
1801 : 76174239 : wide_int new_lb = wi::add (lh_lb, rh_lb, s, &ov_lb);
1802 : 76174239 : wide_int new_ub = wi::add (lh_ub, rh_ub, s, &ov_ub);
1803 : 76174239 : value_range_with_overflow (r, type, new_lb, new_ub, ov_lb, ov_ub);
1804 : 76174239 : }
1805 : :
1806 : : // Given addition or subtraction, determine the possible NORMAL ranges and
1807 : : // OVERFLOW ranges given an OFFSET range. ADD_P is true for addition.
1808 : : // Return the relation that exists between the LHS and OP1 in order for the
1809 : : // NORMAL range to apply.
1810 : : // a return value of VREL_VARYING means no ranges were applicable.
1811 : :
1812 : : static relation_kind
1813 : 742814 : plus_minus_ranges (irange &r_ov, irange &r_normal, const irange &offset,
1814 : : bool add_p)
1815 : : {
1816 : 742814 : relation_kind kind = VREL_VARYING;
1817 : : // For now, only deal with constant adds. This could be extended to ranges
1818 : : // when someone is so motivated.
1819 : 742814 : if (!offset.singleton_p () || offset.zero_p ())
1820 : 725527 : return kind;
1821 : :
1822 : : // Always work with a positive offset. ie a+ -2 -> a-2 and a- -2 > a+2
1823 : 17287 : wide_int off = offset.lower_bound ();
1824 : 17287 : if (wi::neg_p (off, SIGNED))
1825 : : {
1826 : 831 : add_p = !add_p;
1827 : 831 : off = wi::neg (off);
1828 : : }
1829 : :
1830 : 17287 : wi::overflow_type ov;
1831 : 17287 : tree type = offset.type ();
1832 : 17287 : unsigned prec = TYPE_PRECISION (type);
1833 : 17287 : wide_int ub;
1834 : 17287 : wide_int lb;
1835 : : // calculate the normal range and relation for the operation.
1836 : 17287 : if (add_p)
1837 : : {
1838 : : // [ 0 , INF - OFF]
1839 : 16456 : lb = wi::zero (prec);
1840 : 16456 : ub = wi::sub (irange_val_max (type), off, UNSIGNED, &ov);
1841 : 16456 : kind = VREL_GT;
1842 : : }
1843 : : else
1844 : : {
1845 : : // [ OFF, INF ]
1846 : 831 : lb = off;
1847 : 831 : ub = irange_val_max (type);
1848 : 831 : kind = VREL_LT;
1849 : : }
1850 : 17287 : int_range<2> normal_range (type, lb, ub);
1851 : 17287 : int_range<2> ov_range (type, lb, ub, VR_ANTI_RANGE);
1852 : :
1853 : 17287 : r_ov = ov_range;
1854 : 17287 : r_normal = normal_range;
1855 : 17287 : return kind;
1856 : 17287 : }
1857 : :
1858 : : // Once op1 has been calculated by operator_plus or operator_minus, check
1859 : : // to see if the relation passed causes any part of the calculation to
1860 : : // be not possible. ie
1861 : : // a_2 = b_3 + 1 with a_2 < b_3 can refine the range of b_3 to [INF, INF]
1862 : : // and that further refines a_2 to [0, 0].
1863 : : // R is the value of op1, OP2 is the offset being added/subtracted, REL is the
1864 : : // relation between LHS relation OP1 and ADD_P is true for PLUS, false for
1865 : : // MINUS. IF any adjustment can be made, R will reflect it.
1866 : :
1867 : : static void
1868 : 10454919 : adjust_op1_for_overflow (irange &r, const irange &op2, relation_kind rel,
1869 : : bool add_p)
1870 : : {
1871 : 10454919 : if (r.undefined_p ())
1872 : : return;
1873 : 10454917 : tree type = r.type ();
1874 : : // Check for unsigned overflow and calculate the overflow part.
1875 : 10454917 : signop s = TYPE_SIGN (type);
1876 : 10454917 : if (!TYPE_OVERFLOW_WRAPS (type) || s == SIGNED)
1877 : : return;
1878 : :
1879 : : // Only work with <, <=, >, >= relations.
1880 : 5344161 : if (!relation_lt_le_gt_ge_p (rel))
1881 : : return;
1882 : :
1883 : : // Get the ranges for this offset.
1884 : 742814 : int_range_max normal, overflow;
1885 : 742814 : relation_kind k = plus_minus_ranges (overflow, normal, op2, add_p);
1886 : :
1887 : : // VREL_VARYING means there are no adjustments.
1888 : 742814 : if (k == VREL_VARYING)
1889 : : return;
1890 : :
1891 : : // If the relations match use the normal range, otherwise use overflow range.
1892 : 17287 : if (relation_intersect (k, rel) == k)
1893 : 11999 : r.intersect (normal);
1894 : : else
1895 : 5288 : r.intersect (overflow);
1896 : : return;
1897 : 742814 : }
1898 : :
1899 : : bool
1900 : 9424158 : operator_plus::op1_range (irange &r, tree type,
1901 : : const irange &lhs,
1902 : : const irange &op2,
1903 : : relation_trio trio) const
1904 : : {
1905 : 9424158 : if (lhs.undefined_p ())
1906 : : return false;
1907 : : // Start with the default operation.
1908 : 9424158 : range_op_handler minus (MINUS_EXPR);
1909 : 9424158 : if (!minus)
1910 : : return false;
1911 : 9424158 : bool res = minus.fold_range (r, type, lhs, op2);
1912 : 9424158 : relation_kind rel = trio.lhs_op1 ();
1913 : : // Check for a relation refinement.
1914 : 9424158 : if (res)
1915 : 9424158 : adjust_op1_for_overflow (r, op2, rel, true /* PLUS_EXPR */);
1916 : : return res;
1917 : : }
1918 : :
1919 : : bool
1920 : 1976978 : operator_plus::op2_range (irange &r, tree type,
1921 : : const irange &lhs,
1922 : : const irange &op1,
1923 : : relation_trio rel) const
1924 : : {
1925 : 1976978 : return op1_range (r, type, lhs, op1, rel.swap_op1_op2 ());
1926 : : }
1927 : :
1928 : : class operator_widen_plus_signed : public range_operator
1929 : : {
1930 : : public:
1931 : : virtual void wi_fold (irange &r, tree type,
1932 : : const wide_int &lh_lb,
1933 : : const wide_int &lh_ub,
1934 : : const wide_int &rh_lb,
1935 : : const wide_int &rh_ub) const;
1936 : : } op_widen_plus_signed;
1937 : :
1938 : : void
1939 : 0 : operator_widen_plus_signed::wi_fold (irange &r, tree type,
1940 : : const wide_int &lh_lb,
1941 : : const wide_int &lh_ub,
1942 : : const wide_int &rh_lb,
1943 : : const wide_int &rh_ub) const
1944 : : {
1945 : 0 : wi::overflow_type ov_lb, ov_ub;
1946 : 0 : signop s = TYPE_SIGN (type);
1947 : :
1948 : 0 : wide_int lh_wlb
1949 : 0 : = wide_int::from (lh_lb, wi::get_precision (lh_lb) * 2, SIGNED);
1950 : 0 : wide_int lh_wub
1951 : 0 : = wide_int::from (lh_ub, wi::get_precision (lh_ub) * 2, SIGNED);
1952 : 0 : wide_int rh_wlb = wide_int::from (rh_lb, wi::get_precision (rh_lb) * 2, s);
1953 : 0 : wide_int rh_wub = wide_int::from (rh_ub, wi::get_precision (rh_ub) * 2, s);
1954 : :
1955 : 0 : wide_int new_lb = wi::add (lh_wlb, rh_wlb, s, &ov_lb);
1956 : 0 : wide_int new_ub = wi::add (lh_wub, rh_wub, s, &ov_ub);
1957 : :
1958 : 0 : r = int_range<2> (type, new_lb, new_ub);
1959 : 0 : }
1960 : :
1961 : : class operator_widen_plus_unsigned : public range_operator
1962 : : {
1963 : : public:
1964 : : virtual void wi_fold (irange &r, tree type,
1965 : : const wide_int &lh_lb,
1966 : : const wide_int &lh_ub,
1967 : : const wide_int &rh_lb,
1968 : : const wide_int &rh_ub) const;
1969 : : } op_widen_plus_unsigned;
1970 : :
1971 : : void
1972 : 0 : operator_widen_plus_unsigned::wi_fold (irange &r, tree type,
1973 : : const wide_int &lh_lb,
1974 : : const wide_int &lh_ub,
1975 : : const wide_int &rh_lb,
1976 : : const wide_int &rh_ub) const
1977 : : {
1978 : 0 : wi::overflow_type ov_lb, ov_ub;
1979 : 0 : signop s = TYPE_SIGN (type);
1980 : :
1981 : 0 : wide_int lh_wlb
1982 : 0 : = wide_int::from (lh_lb, wi::get_precision (lh_lb) * 2, UNSIGNED);
1983 : 0 : wide_int lh_wub
1984 : 0 : = wide_int::from (lh_ub, wi::get_precision (lh_ub) * 2, UNSIGNED);
1985 : 0 : wide_int rh_wlb = wide_int::from (rh_lb, wi::get_precision (rh_lb) * 2, s);
1986 : 0 : wide_int rh_wub = wide_int::from (rh_ub, wi::get_precision (rh_ub) * 2, s);
1987 : :
1988 : 0 : wide_int new_lb = wi::add (lh_wlb, rh_wlb, s, &ov_lb);
1989 : 0 : wide_int new_ub = wi::add (lh_wub, rh_wub, s, &ov_ub);
1990 : :
1991 : 0 : r = int_range<2> (type, new_lb, new_ub);
1992 : 0 : }
1993 : :
1994 : : void
1995 : 18382465 : operator_minus::update_bitmask (irange &r, const irange &lh,
1996 : : const irange &rh) const
1997 : : {
1998 : 18382465 : update_known_bitmask (r, MINUS_EXPR, lh, rh);
1999 : 18382465 : }
2000 : :
2001 : : void
2002 : 26072908 : operator_minus::wi_fold (irange &r, tree type,
2003 : : const wide_int &lh_lb, const wide_int &lh_ub,
2004 : : const wide_int &rh_lb, const wide_int &rh_ub) const
2005 : : {
2006 : 26072908 : wi::overflow_type ov_lb, ov_ub;
2007 : 26072908 : signop s = TYPE_SIGN (type);
2008 : 26072908 : wide_int new_lb = wi::sub (lh_lb, rh_ub, s, &ov_lb);
2009 : 26072908 : wide_int new_ub = wi::sub (lh_ub, rh_lb, s, &ov_ub);
2010 : 26072908 : value_range_with_overflow (r, type, new_lb, new_ub, ov_lb, ov_ub);
2011 : 26072908 : }
2012 : :
2013 : :
2014 : : // Return the relation between LHS and OP1 based on the relation between
2015 : : // OP1 and OP2.
2016 : :
2017 : : relation_kind
2018 : 4813859 : operator_minus::lhs_op1_relation (const irange &, const irange &op1,
2019 : : const irange &, relation_kind rel) const
2020 : : {
2021 : 4813859 : if (!op1.undefined_p () && TYPE_SIGN (op1.type ()) == UNSIGNED)
2022 : 2484223 : switch (rel)
2023 : : {
2024 : : case VREL_GT:
2025 : : case VREL_GE:
2026 : : return VREL_LE;
2027 : : default:
2028 : : break;
2029 : : }
2030 : : return VREL_VARYING;
2031 : : }
2032 : :
2033 : : // Check to see if the relation REL between OP1 and OP2 has any effect on the
2034 : : // LHS of the expression. If so, apply it to LHS_RANGE. This is a helper
2035 : : // function for both MINUS_EXPR and POINTER_DIFF_EXPR.
2036 : :
2037 : : bool
2038 : 21068167 : minus_op1_op2_relation_effect (irange &lhs_range, tree type,
2039 : : const irange &op1_range ATTRIBUTE_UNUSED,
2040 : : const irange &op2_range ATTRIBUTE_UNUSED,
2041 : : relation_kind rel)
2042 : : {
2043 : 21068167 : if (rel == VREL_VARYING)
2044 : : return false;
2045 : :
2046 : 262696 : int_range<2> rel_range;
2047 : 262696 : unsigned prec = TYPE_PRECISION (type);
2048 : 262696 : signop sgn = TYPE_SIGN (type);
2049 : :
2050 : : // == and != produce [0,0] and ~[0,0] regardless of wrapping.
2051 : 262696 : if (rel == VREL_EQ)
2052 : 8104 : rel_range = int_range<2> (type, wi::zero (prec), wi::zero (prec));
2053 : 254592 : else if (rel == VREL_NE)
2054 : 102452 : rel_range = int_range<2> (type, wi::zero (prec), wi::zero (prec),
2055 : 51226 : VR_ANTI_RANGE);
2056 : 203366 : else if (TYPE_OVERFLOW_WRAPS (type))
2057 : : {
2058 : 134093 : switch (rel)
2059 : : {
2060 : : // For wrapping signed values and unsigned, if op1 > op2 or
2061 : : // op1 < op2, then op1 - op2 can be restricted to ~[0, 0].
2062 : 50986 : case VREL_GT:
2063 : 50986 : case VREL_LT:
2064 : 101972 : rel_range = int_range<2> (type, wi::zero (prec), wi::zero (prec),
2065 : 50986 : VR_ANTI_RANGE);
2066 : 50986 : break;
2067 : : default:
2068 : : return false;
2069 : : }
2070 : : }
2071 : : else
2072 : : {
2073 : 69273 : switch (rel)
2074 : : {
2075 : : // op1 > op2, op1 - op2 can be restricted to [1, +INF]
2076 : 21951 : case VREL_GT:
2077 : 43902 : rel_range = int_range<2> (type, wi::one (prec),
2078 : 43902 : wi::max_value (prec, sgn));
2079 : 21951 : break;
2080 : : // op1 >= op2, op1 - op2 can be restricted to [0, +INF]
2081 : 46593 : case VREL_GE:
2082 : 93186 : rel_range = int_range<2> (type, wi::zero (prec),
2083 : 93186 : wi::max_value (prec, sgn));
2084 : 46593 : break;
2085 : : // op1 < op2, op1 - op2 can be restricted to [-INF, -1]
2086 : 288 : case VREL_LT:
2087 : 576 : rel_range = int_range<2> (type, wi::min_value (prec, sgn),
2088 : 288 : wi::minus_one (prec));
2089 : 288 : break;
2090 : : // op1 <= op2, op1 - op2 can be restricted to [-INF, 0]
2091 : 275 : case VREL_LE:
2092 : 550 : rel_range = int_range<2> (type, wi::min_value (prec, sgn),
2093 : 275 : wi::zero (prec));
2094 : 275 : break;
2095 : : default:
2096 : : return false;
2097 : : }
2098 : : }
2099 : 179423 : lhs_range.intersect (rel_range);
2100 : 179423 : return true;
2101 : 262696 : }
2102 : :
2103 : : bool
2104 : 18382465 : operator_minus::op1_op2_relation_effect (irange &lhs_range, tree type,
2105 : : const irange &op1_range,
2106 : : const irange &op2_range,
2107 : : relation_kind rel) const
2108 : : {
2109 : 18382465 : return minus_op1_op2_relation_effect (lhs_range, type, op1_range, op2_range,
2110 : 18382465 : rel);
2111 : : }
2112 : :
2113 : : bool
2114 : 1030761 : operator_minus::op1_range (irange &r, tree type,
2115 : : const irange &lhs,
2116 : : const irange &op2,
2117 : : relation_trio trio) const
2118 : : {
2119 : 1030761 : if (lhs.undefined_p ())
2120 : : return false;
2121 : : // Start with the default operation.
2122 : 1030761 : range_op_handler minus (PLUS_EXPR);
2123 : 1030761 : if (!minus)
2124 : : return false;
2125 : 1030761 : bool res = minus.fold_range (r, type, lhs, op2);
2126 : 1030761 : relation_kind rel = trio.lhs_op1 ();
2127 : 1030761 : if (res)
2128 : 1030761 : adjust_op1_for_overflow (r, op2, rel, false /* PLUS_EXPR */);
2129 : : return res;
2130 : :
2131 : : }
2132 : :
2133 : : bool
2134 : 1684177 : operator_minus::op2_range (irange &r, tree type,
2135 : : const irange &lhs,
2136 : : const irange &op1,
2137 : : relation_trio) const
2138 : : {
2139 : 1684177 : if (lhs.undefined_p ())
2140 : : return false;
2141 : 1684177 : return fold_range (r, type, op1, lhs);
2142 : : }
2143 : :
2144 : : void
2145 : 855947 : operator_min::update_bitmask (irange &r, const irange &lh,
2146 : : const irange &rh) const
2147 : : {
2148 : 855947 : update_known_bitmask (r, MIN_EXPR, lh, rh);
2149 : 855947 : }
2150 : :
2151 : : void
2152 : 1362591 : operator_min::wi_fold (irange &r, tree type,
2153 : : const wide_int &lh_lb, const wide_int &lh_ub,
2154 : : const wide_int &rh_lb, const wide_int &rh_ub) const
2155 : : {
2156 : 1362591 : signop s = TYPE_SIGN (type);
2157 : 1362591 : wide_int new_lb = wi::min (lh_lb, rh_lb, s);
2158 : 1362591 : wide_int new_ub = wi::min (lh_ub, rh_ub, s);
2159 : 1362591 : value_range_with_overflow (r, type, new_lb, new_ub);
2160 : 1362591 : }
2161 : :
2162 : :
2163 : : void
2164 : 657737 : operator_max::update_bitmask (irange &r, const irange &lh,
2165 : : const irange &rh) const
2166 : : {
2167 : 657737 : update_known_bitmask (r, MAX_EXPR, lh, rh);
2168 : 657737 : }
2169 : :
2170 : : void
2171 : 777216 : operator_max::wi_fold (irange &r, tree type,
2172 : : const wide_int &lh_lb, const wide_int &lh_ub,
2173 : : const wide_int &rh_lb, const wide_int &rh_ub) const
2174 : : {
2175 : 777216 : signop s = TYPE_SIGN (type);
2176 : 777216 : wide_int new_lb = wi::max (lh_lb, rh_lb, s);
2177 : 777216 : wide_int new_ub = wi::max (lh_ub, rh_ub, s);
2178 : 777216 : value_range_with_overflow (r, type, new_lb, new_ub);
2179 : 777216 : }
2180 : :
2181 : :
2182 : : // Calculate the cross product of two sets of ranges and return it.
2183 : : //
2184 : : // Multiplications, divisions and shifts are a bit tricky to handle,
2185 : : // depending on the mix of signs we have in the two ranges, we need to
2186 : : // operate on different values to get the minimum and maximum values
2187 : : // for the new range. One approach is to figure out all the
2188 : : // variations of range combinations and do the operations.
2189 : : //
2190 : : // However, this involves several calls to compare_values and it is
2191 : : // pretty convoluted. It's simpler to do the 4 operations (MIN0 OP
2192 : : // MIN1, MIN0 OP MAX1, MAX0 OP MIN1 and MAX0 OP MAX0 OP MAX1) and then
2193 : : // figure the smallest and largest values to form the new range.
2194 : :
2195 : : void
2196 : 14311878 : cross_product_operator::wi_cross_product (irange &r, tree type,
2197 : : const wide_int &lh_lb,
2198 : : const wide_int &lh_ub,
2199 : : const wide_int &rh_lb,
2200 : : const wide_int &rh_ub) const
2201 : : {
2202 : 14311878 : wide_int cp1, cp2, cp3, cp4;
2203 : : // Default to varying.
2204 : 14311878 : r.set_varying (type);
2205 : :
2206 : : // Compute the 4 cross operations, bailing if we get an overflow we
2207 : : // can't handle.
2208 : 14311878 : if (wi_op_overflows (cp1, type, lh_lb, rh_lb))
2209 : : return;
2210 : 14311874 : if (wi::eq_p (lh_lb, lh_ub))
2211 : 4237373 : cp3 = cp1;
2212 : 10074501 : else if (wi_op_overflows (cp3, type, lh_ub, rh_lb))
2213 : : return;
2214 : 14311874 : if (wi::eq_p (rh_lb, rh_ub))
2215 : 11069429 : cp2 = cp1;
2216 : 3242445 : else if (wi_op_overflows (cp2, type, lh_lb, rh_ub))
2217 : : return;
2218 : 14309604 : if (wi::eq_p (lh_lb, lh_ub))
2219 : 4237353 : cp4 = cp2;
2220 : 10072251 : else if (wi_op_overflows (cp4, type, lh_ub, rh_ub))
2221 : : return;
2222 : :
2223 : : // Order pairs.
2224 : 14309604 : signop sign = TYPE_SIGN (type);
2225 : 14309604 : if (wi::gt_p (cp1, cp2, sign))
2226 : 1469515 : std::swap (cp1, cp2);
2227 : 14309604 : if (wi::gt_p (cp3, cp4, sign))
2228 : 1464075 : std::swap (cp3, cp4);
2229 : :
2230 : : // Choose min and max from the ordered pairs.
2231 : 14309604 : wide_int res_lb = wi::min (cp1, cp3, sign);
2232 : 14309604 : wide_int res_ub = wi::max (cp2, cp4, sign);
2233 : 14309604 : value_range_with_overflow (r, type, res_lb, res_ub);
2234 : 14313433 : }
2235 : :
2236 : :
2237 : : void
2238 : 13514118 : operator_mult::update_bitmask (irange &r, const irange &lh,
2239 : : const irange &rh) const
2240 : : {
2241 : 13514118 : update_known_bitmask (r, MULT_EXPR, lh, rh);
2242 : 13514118 : }
2243 : :
2244 : : bool
2245 : 1174178 : operator_mult::op1_range (irange &r, tree type,
2246 : : const irange &lhs, const irange &op2,
2247 : : relation_trio) const
2248 : : {
2249 : 1174178 : if (lhs.undefined_p ())
2250 : : return false;
2251 : :
2252 : : // We can't solve 0 = OP1 * N by dividing by N with a wrapping type.
2253 : : // For example: For 0 = OP1 * 2, OP1 could be 0, or MAXINT, whereas
2254 : : // for 4 = OP1 * 2, OP1 could be 2 or 130 (unsigned 8-bit)
2255 : 1174178 : if (TYPE_OVERFLOW_WRAPS (type))
2256 : : return false;
2257 : :
2258 : 330770 : wide_int offset;
2259 : 330770 : if (op2.singleton_p (offset) && offset != 0)
2260 : 233160 : return range_op_handler (TRUNC_DIV_EXPR).fold_range (r, type, lhs, op2);
2261 : :
2262 : : // ~[0, 0] = op1 * op2 defines op1 and op2 as non-zero.
2263 : 97610 : if (!lhs.contains_p (wi::zero (TYPE_PRECISION (lhs.type ()))))
2264 : : {
2265 : 21220 : r.set_nonzero (type);
2266 : 21220 : return true;
2267 : : }
2268 : : return false;
2269 : 330770 : }
2270 : :
2271 : : bool
2272 : 120536 : operator_mult::op2_range (irange &r, tree type,
2273 : : const irange &lhs, const irange &op1,
2274 : : relation_trio rel) const
2275 : : {
2276 : 120536 : return operator_mult::op1_range (r, type, lhs, op1, rel.swap_op1_op2 ());
2277 : : }
2278 : :
2279 : : bool
2280 : 13808902 : operator_mult::wi_op_overflows (wide_int &res, tree type,
2281 : : const wide_int &w0, const wide_int &w1) const
2282 : : {
2283 : 13808902 : wi::overflow_type overflow = wi::OVF_NONE;
2284 : 13808902 : signop sign = TYPE_SIGN (type);
2285 : 13808902 : res = wi::mul (w0, w1, sign, &overflow);
2286 : 13808902 : if (overflow && TYPE_OVERFLOW_UNDEFINED (type))
2287 : : {
2288 : : // For multiplication, the sign of the overflow is given
2289 : : // by the comparison of the signs of the operands.
2290 : 6524390 : if (sign == UNSIGNED || w0.sign_mask () == w1.sign_mask ())
2291 : 3596103 : res = wi::max_value (w0.get_precision (), sign);
2292 : : else
2293 : 2928467 : res = wi::min_value (w0.get_precision (), sign);
2294 : 6524390 : return false;
2295 : : }
2296 : 7284512 : return overflow;
2297 : : }
2298 : :
2299 : : void
2300 : 17152897 : operator_mult::wi_fold (irange &r, tree type,
2301 : : const wide_int &lh_lb, const wide_int &lh_ub,
2302 : : const wide_int &rh_lb, const wide_int &rh_ub) const
2303 : : {
2304 : 17152897 : if (TYPE_OVERFLOW_UNDEFINED (type))
2305 : : {
2306 : 5757716 : wi_cross_product (r, type, lh_lb, lh_ub, rh_lb, rh_ub);
2307 : 5757716 : return;
2308 : : }
2309 : :
2310 : : // Multiply the ranges when overflow wraps. This is basically fancy
2311 : : // code so we don't drop to varying with an unsigned
2312 : : // [-3,-1]*[-3,-1].
2313 : : //
2314 : : // This test requires 2*prec bits if both operands are signed and
2315 : : // 2*prec + 2 bits if either is not. Therefore, extend the values
2316 : : // using the sign of the result to PREC2. From here on out,
2317 : : // everything is just signed math no matter what the input types
2318 : : // were.
2319 : :
2320 : 11395181 : signop sign = TYPE_SIGN (type);
2321 : 11395181 : unsigned prec = TYPE_PRECISION (type);
2322 : 11395181 : widest2_int min0 = widest2_int::from (lh_lb, sign);
2323 : 11395181 : widest2_int max0 = widest2_int::from (lh_ub, sign);
2324 : 11395181 : widest2_int min1 = widest2_int::from (rh_lb, sign);
2325 : 11395181 : widest2_int max1 = widest2_int::from (rh_ub, sign);
2326 : 11395181 : widest2_int sizem1 = wi::mask <widest2_int> (prec, false);
2327 : 11395181 : widest2_int size = sizem1 + 1;
2328 : :
2329 : : // Canonicalize the intervals.
2330 : 11395181 : if (sign == UNSIGNED)
2331 : : {
2332 : 10711443 : if (wi::ltu_p (size, min0 + max0))
2333 : : {
2334 : 1525744 : min0 -= size;
2335 : 1525744 : max0 -= size;
2336 : : }
2337 : 10711410 : if (wi::ltu_p (size, min1 + max1))
2338 : : {
2339 : 156773 : min1 -= size;
2340 : 156773 : max1 -= size;
2341 : : }
2342 : : }
2343 : :
2344 : : // Sort the 4 products so that min is in prod0 and max is in
2345 : : // prod3.
2346 : 11395181 : widest2_int prod0 = min0 * min1;
2347 : 11395181 : widest2_int prod1 = min0 * max1;
2348 : 11395181 : widest2_int prod2 = max0 * min1;
2349 : 11395181 : widest2_int prod3 = max0 * max1;
2350 : :
2351 : : // min0min1 > max0max1
2352 : 11395181 : if (prod0 > prod3)
2353 : 183804 : std::swap (prod0, prod3);
2354 : :
2355 : : // min0max1 > max0min1
2356 : 11395181 : if (prod1 > prod2)
2357 : 292463 : std::swap (prod1, prod2);
2358 : :
2359 : 11395181 : if (prod0 > prod1)
2360 : 78734 : std::swap (prod0, prod1);
2361 : :
2362 : 11395181 : if (prod2 > prod3)
2363 : 4002 : std::swap (prod2, prod3);
2364 : :
2365 : : // diff = max - min
2366 : 11395181 : prod2 = prod3 - prod0;
2367 : 11395181 : if (wi::geu_p (prod2, sizem1))
2368 : : {
2369 : : // Multiplying by X, where X is a power of 2 is [0,0][X,+INF].
2370 : 7637337 : if (TYPE_UNSIGNED (type) && rh_lb == rh_ub
2371 : 7049763 : && wi::exact_log2 (rh_lb) != -1 && prec > 1)
2372 : : {
2373 : 2644842 : r.set (type, rh_lb, wi::max_value (prec, sign));
2374 : 2644842 : int_range<2> zero;
2375 : 2644842 : zero.set_zero (type);
2376 : 2644842 : r.union_ (zero);
2377 : 2644842 : }
2378 : : else
2379 : : // The range covers all values.
2380 : 1245000 : r.set_varying (type);
2381 : : }
2382 : : else
2383 : : {
2384 : 7505339 : wide_int new_lb = wide_int::from (prod0, prec, sign);
2385 : 7505339 : wide_int new_ub = wide_int::from (prod3, prec, sign);
2386 : 7505339 : create_possibly_reversed_range (r, type, new_lb, new_ub);
2387 : 7505382 : }
2388 : 11395777 : }
2389 : :
2390 : : class operator_widen_mult_signed : public range_operator
2391 : : {
2392 : : public:
2393 : : virtual void wi_fold (irange &r, tree type,
2394 : : const wide_int &lh_lb,
2395 : : const wide_int &lh_ub,
2396 : : const wide_int &rh_lb,
2397 : : const wide_int &rh_ub)
2398 : : const;
2399 : : } op_widen_mult_signed;
2400 : :
2401 : : void
2402 : 1347 : operator_widen_mult_signed::wi_fold (irange &r, tree type,
2403 : : const wide_int &lh_lb,
2404 : : const wide_int &lh_ub,
2405 : : const wide_int &rh_lb,
2406 : : const wide_int &rh_ub) const
2407 : : {
2408 : 1347 : signop s = TYPE_SIGN (type);
2409 : :
2410 : 1347 : wide_int lh_wlb = wide_int::from (lh_lb, wi::get_precision (lh_lb) * 2, SIGNED);
2411 : 1347 : wide_int lh_wub = wide_int::from (lh_ub, wi::get_precision (lh_ub) * 2, SIGNED);
2412 : 1347 : wide_int rh_wlb = wide_int::from (rh_lb, wi::get_precision (rh_lb) * 2, s);
2413 : 1347 : wide_int rh_wub = wide_int::from (rh_ub, wi::get_precision (rh_ub) * 2, s);
2414 : :
2415 : : /* We don't expect a widening multiplication to be able to overflow but range
2416 : : calculations for multiplications are complicated. After widening the
2417 : : operands lets call the base class. */
2418 : 1347 : return op_mult.wi_fold (r, type, lh_wlb, lh_wub, rh_wlb, rh_wub);
2419 : 1347 : }
2420 : :
2421 : :
2422 : : class operator_widen_mult_unsigned : public range_operator
2423 : : {
2424 : : public:
2425 : : virtual void wi_fold (irange &r, tree type,
2426 : : const wide_int &lh_lb,
2427 : : const wide_int &lh_ub,
2428 : : const wide_int &rh_lb,
2429 : : const wide_int &rh_ub)
2430 : : const;
2431 : : } op_widen_mult_unsigned;
2432 : :
2433 : : void
2434 : 5497 : operator_widen_mult_unsigned::wi_fold (irange &r, tree type,
2435 : : const wide_int &lh_lb,
2436 : : const wide_int &lh_ub,
2437 : : const wide_int &rh_lb,
2438 : : const wide_int &rh_ub) const
2439 : : {
2440 : 5497 : signop s = TYPE_SIGN (type);
2441 : :
2442 : 5497 : wide_int lh_wlb = wide_int::from (lh_lb, wi::get_precision (lh_lb) * 2, UNSIGNED);
2443 : 5497 : wide_int lh_wub = wide_int::from (lh_ub, wi::get_precision (lh_ub) * 2, UNSIGNED);
2444 : 5497 : wide_int rh_wlb = wide_int::from (rh_lb, wi::get_precision (rh_lb) * 2, s);
2445 : 5497 : wide_int rh_wub = wide_int::from (rh_ub, wi::get_precision (rh_ub) * 2, s);
2446 : :
2447 : : /* We don't expect a widening multiplication to be able to overflow but range
2448 : : calculations for multiplications are complicated. After widening the
2449 : : operands lets call the base class. */
2450 : 5497 : return op_mult.wi_fold (r, type, lh_wlb, lh_wub, rh_wlb, rh_wub);
2451 : 5497 : }
2452 : :
2453 : : class operator_div : public cross_product_operator
2454 : : {
2455 : : using range_operator::update_bitmask;
2456 : : using range_operator::op2_range;
2457 : : public:
2458 : : operator_div (tree_code div_kind) { m_code = div_kind; }
2459 : : bool op2_range (irange &r, tree type, const irange &lhs, const irange &,
2460 : : relation_trio) const final override;
2461 : : virtual void wi_fold (irange &r, tree type,
2462 : : const wide_int &lh_lb,
2463 : : const wide_int &lh_ub,
2464 : : const wide_int &rh_lb,
2465 : : const wide_int &rh_ub) const final override;
2466 : : virtual bool wi_op_overflows (wide_int &res, tree type,
2467 : : const wide_int &, const wide_int &)
2468 : : const final override;
2469 : 2799072 : void update_bitmask (irange &r, const irange &lh, const irange &rh)
2470 : : const final override
2471 : 2799072 : { update_known_bitmask (r, m_code, lh, rh); }
2472 : : protected:
2473 : : tree_code m_code;
2474 : : };
2475 : :
2476 : : static operator_div op_trunc_div (TRUNC_DIV_EXPR);
2477 : : static operator_div op_floor_div (FLOOR_DIV_EXPR);
2478 : : static operator_div op_round_div (ROUND_DIV_EXPR);
2479 : : static operator_div op_ceil_div (CEIL_DIV_EXPR);
2480 : :
2481 : : // Set OP2 to non-zero if the LHS isn't UNDEFINED.
2482 : : bool
2483 : 38691 : operator_div::op2_range (irange &r, tree type, const irange &lhs,
2484 : : const irange &, relation_trio) const
2485 : : {
2486 : 38691 : if (!lhs.undefined_p ())
2487 : : {
2488 : 38691 : r.set_nonzero (type);
2489 : 38691 : return true;
2490 : : }
2491 : : return false;
2492 : : }
2493 : :
2494 : : bool
2495 : 12095380 : operator_div::wi_op_overflows (wide_int &res, tree type,
2496 : : const wide_int &w0, const wide_int &w1) const
2497 : : {
2498 : 12095380 : if (w1 == 0)
2499 : : return true;
2500 : :
2501 : 12095380 : wi::overflow_type overflow = wi::OVF_NONE;
2502 : 12095380 : signop sign = TYPE_SIGN (type);
2503 : :
2504 : 12095380 : switch (m_code)
2505 : : {
2506 : 11990297 : case EXACT_DIV_EXPR:
2507 : 11990297 : case TRUNC_DIV_EXPR:
2508 : 11990297 : res = wi::div_trunc (w0, w1, sign, &overflow);
2509 : 11990297 : break;
2510 : 93186 : case FLOOR_DIV_EXPR:
2511 : 93186 : res = wi::div_floor (w0, w1, sign, &overflow);
2512 : 93186 : break;
2513 : 288 : case ROUND_DIV_EXPR:
2514 : 288 : res = wi::div_round (w0, w1, sign, &overflow);
2515 : 288 : break;
2516 : 11609 : case CEIL_DIV_EXPR:
2517 : 11609 : res = wi::div_ceil (w0, w1, sign, &overflow);
2518 : 11609 : break;
2519 : 0 : default:
2520 : 0 : gcc_unreachable ();
2521 : : }
2522 : :
2523 : 12095380 : if (overflow && TYPE_OVERFLOW_UNDEFINED (type))
2524 : : {
2525 : : // For division, the only case is -INF / -1 = +INF.
2526 : 208884 : res = wi::max_value (w0.get_precision (), sign);
2527 : 208884 : return false;
2528 : : }
2529 : 11886496 : return overflow;
2530 : : }
2531 : :
2532 : : void
2533 : 3885620 : operator_div::wi_fold (irange &r, tree type,
2534 : : const wide_int &lh_lb, const wide_int &lh_ub,
2535 : : const wide_int &rh_lb, const wide_int &rh_ub) const
2536 : : {
2537 : 3885620 : const wide_int dividend_min = lh_lb;
2538 : 3885620 : const wide_int dividend_max = lh_ub;
2539 : 3885620 : const wide_int divisor_min = rh_lb;
2540 : 3885620 : const wide_int divisor_max = rh_ub;
2541 : 3885620 : signop sign = TYPE_SIGN (type);
2542 : 3885620 : unsigned prec = TYPE_PRECISION (type);
2543 : 3885620 : wide_int extra_min, extra_max;
2544 : :
2545 : : // If we know we won't divide by zero, just do the division.
2546 : 3885620 : if (!wi_includes_zero_p (type, divisor_min, divisor_max))
2547 : : {
2548 : 3201164 : wi_cross_product (r, type, dividend_min, dividend_max,
2549 : : divisor_min, divisor_max);
2550 : 3201164 : return;
2551 : : }
2552 : :
2553 : : // If we're definitely dividing by zero, there's nothing to do.
2554 : 684456 : if (wi_zero_p (type, divisor_min, divisor_max))
2555 : : {
2556 : 16803 : r.set_undefined ();
2557 : 16803 : return;
2558 : : }
2559 : :
2560 : : // Perform the division in 2 parts, [LB, -1] and [1, UB], which will
2561 : : // skip any division by zero.
2562 : :
2563 : : // First divide by the negative numbers, if any.
2564 : 667653 : if (wi::neg_p (divisor_min, sign))
2565 : 855948 : wi_cross_product (r, type, dividend_min, dividend_max,
2566 : 855948 : divisor_min, wi::minus_one (prec));
2567 : : else
2568 : 239679 : r.set_undefined ();
2569 : :
2570 : : // Then divide by the non-zero positive numbers, if any.
2571 : 667653 : if (wi::gt_p (divisor_max, wi::zero (prec), sign))
2572 : : {
2573 : 666897 : int_range_max tmp;
2574 : 1333794 : wi_cross_product (tmp, type, dividend_min, dividend_max,
2575 : 666897 : wi::one (prec), divisor_max);
2576 : 666897 : r.union_ (tmp);
2577 : 666897 : }
2578 : : // We shouldn't still have undefined here.
2579 : 667653 : gcc_checking_assert (!r.undefined_p ());
2580 : 3886272 : }
2581 : :
2582 : :
2583 : : class operator_exact_divide : public operator_div
2584 : : {
2585 : : using range_operator::op1_range;
2586 : : public:
2587 : : operator_exact_divide () : operator_div (EXACT_DIV_EXPR) { }
2588 : : virtual bool op1_range (irange &r, tree type,
2589 : : const irange &lhs,
2590 : : const irange &op2,
2591 : : relation_trio) const;
2592 : :
2593 : : } op_exact_div;
2594 : :
2595 : : bool
2596 : 486368 : operator_exact_divide::op1_range (irange &r, tree type,
2597 : : const irange &lhs,
2598 : : const irange &op2,
2599 : : relation_trio) const
2600 : : {
2601 : 486368 : if (lhs.undefined_p ())
2602 : : return false;
2603 : 486368 : wide_int offset;
2604 : : // [2, 4] = op1 / [3,3] since its exact divide, no need to worry about
2605 : : // remainders in the endpoints, so op1 = [2,4] * [3,3] = [6,12].
2606 : : // We wont bother trying to enumerate all the in between stuff :-P
2607 : : // TRUE accuracy is [6,6][9,9][12,12]. This is unlikely to matter most of
2608 : : // the time however.
2609 : : // If op2 is a multiple of 2, we would be able to set some non-zero bits.
2610 : 486368 : if (op2.singleton_p (offset) && offset != 0)
2611 : 486368 : return range_op_handler (MULT_EXPR).fold_range (r, type, lhs, op2);
2612 : : return false;
2613 : 486368 : }
2614 : :
2615 : :
2616 : : class operator_lshift : public cross_product_operator
2617 : : {
2618 : : using range_operator::fold_range;
2619 : : using range_operator::op1_range;
2620 : : using range_operator::update_bitmask;
2621 : : public:
2622 : : virtual bool op1_range (irange &r, tree type, const irange &lhs,
2623 : : const irange &op2, relation_trio rel = TRIO_VARYING)
2624 : : const final override;
2625 : : virtual bool fold_range (irange &r, tree type, const irange &op1,
2626 : : const irange &op2, relation_trio rel = TRIO_VARYING)
2627 : : const final override;
2628 : :
2629 : : virtual void wi_fold (irange &r, tree type,
2630 : : const wide_int &lh_lb, const wide_int &lh_ub,
2631 : : const wide_int &rh_lb,
2632 : : const wide_int &rh_ub) const final override;
2633 : : virtual bool wi_op_overflows (wide_int &res,
2634 : : tree type,
2635 : : const wide_int &,
2636 : : const wide_int &) const final override;
2637 : 457052 : void update_bitmask (irange &r, const irange &lh,
2638 : : const irange &rh) const final override
2639 : 457052 : { update_known_bitmask (r, LSHIFT_EXPR, lh, rh); }
2640 : : // Check compatibility of LHS and op1.
2641 : 1057480 : bool operand_check_p (tree t1, tree t2, tree) const final override
2642 : 1057480 : { return range_compatible_p (t1, t2); }
2643 : : } op_lshift;
2644 : :
2645 : : class operator_rshift : public cross_product_operator
2646 : : {
2647 : : using range_operator::fold_range;
2648 : : using range_operator::op1_range;
2649 : : using range_operator::lhs_op1_relation;
2650 : : using range_operator::update_bitmask;
2651 : : public:
2652 : : virtual bool fold_range (irange &r, tree type, const irange &op1,
2653 : : const irange &op2, relation_trio rel = TRIO_VARYING)
2654 : : const final override;
2655 : : virtual void wi_fold (irange &r, tree type,
2656 : : const wide_int &lh_lb,
2657 : : const wide_int &lh_ub,
2658 : : const wide_int &rh_lb,
2659 : : const wide_int &rh_ub) const final override;
2660 : : virtual bool wi_op_overflows (wide_int &res,
2661 : : tree type,
2662 : : const wide_int &w0,
2663 : : const wide_int &w1) const final override;
2664 : : virtual bool op1_range (irange &, tree type, const irange &lhs,
2665 : : const irange &op2, relation_trio rel = TRIO_VARYING)
2666 : : const final override;
2667 : : virtual relation_kind lhs_op1_relation (const irange &lhs, const irange &op1,
2668 : : const irange &op2, relation_kind rel)
2669 : : const final override;
2670 : 3381143 : void update_bitmask (irange &r, const irange &lh,
2671 : : const irange &rh) const final override
2672 : 3381143 : { update_known_bitmask (r, RSHIFT_EXPR, lh, rh); }
2673 : : // Check compatibility of LHS and op1.
2674 : 3480352 : bool operand_check_p (tree t1, tree t2, tree) const final override
2675 : 3480352 : { return range_compatible_p (t1, t2); }
2676 : : } op_rshift;
2677 : :
2678 : :
2679 : : relation_kind
2680 : 2470984 : operator_rshift::lhs_op1_relation (const irange &lhs ATTRIBUTE_UNUSED,
2681 : : const irange &op1,
2682 : : const irange &op2,
2683 : : relation_kind) const
2684 : : {
2685 : : // If both operands range are >= 0, then the LHS <= op1.
2686 : 2470984 : if (!op1.undefined_p () && !op2.undefined_p ()
2687 : 4941120 : && wi::ge_p (op1.lower_bound (), 0, TYPE_SIGN (op1.type ()))
2688 : 7213331 : && wi::ge_p (op2.lower_bound (), 0, TYPE_SIGN (op2.type ())))
2689 : 2245418 : return VREL_LE;
2690 : : return VREL_VARYING;
2691 : : }
2692 : :
2693 : : bool
2694 : 1614123 : operator_lshift::fold_range (irange &r, tree type,
2695 : : const irange &op1,
2696 : : const irange &op2,
2697 : : relation_trio rel) const
2698 : : {
2699 : 1614123 : int_range_max shift_range;
2700 : 1614123 : if (!get_shift_range (shift_range, type, op2))
2701 : : {
2702 : 565 : if (op2.undefined_p ())
2703 : 230 : r.set_undefined ();
2704 : : else
2705 : 335 : r.set_zero (type);
2706 : 565 : return true;
2707 : : }
2708 : :
2709 : : // Transform left shifts by constants into multiplies.
2710 : 1613558 : if (shift_range.singleton_p ())
2711 : : {
2712 : 1156479 : unsigned shift = shift_range.lower_bound ().to_uhwi ();
2713 : 1156479 : wide_int tmp = wi::set_bit_in_zero (shift, TYPE_PRECISION (type));
2714 : 1156479 : int_range<1> mult (type, tmp, tmp);
2715 : :
2716 : : // Force wrapping multiplication.
2717 : 1156479 : bool saved_flag_wrapv = flag_wrapv;
2718 : 1156479 : bool saved_flag_wrapv_pointer = flag_wrapv_pointer;
2719 : 1156479 : flag_wrapv = 1;
2720 : 1156479 : flag_wrapv_pointer = 1;
2721 : 1156479 : bool b = op_mult.fold_range (r, type, op1, mult);
2722 : 1156479 : flag_wrapv = saved_flag_wrapv;
2723 : 1156479 : flag_wrapv_pointer = saved_flag_wrapv_pointer;
2724 : 1156479 : return b;
2725 : 1156488 : }
2726 : : else
2727 : : // Otherwise, invoke the generic fold routine.
2728 : 457079 : return range_operator::fold_range (r, type, op1, shift_range, rel);
2729 : 1614123 : }
2730 : :
2731 : : void
2732 : 547760 : operator_lshift::wi_fold (irange &r, tree type,
2733 : : const wide_int &lh_lb, const wide_int &lh_ub,
2734 : : const wide_int &rh_lb, const wide_int &rh_ub) const
2735 : : {
2736 : 547760 : signop sign = TYPE_SIGN (type);
2737 : 547760 : unsigned prec = TYPE_PRECISION (type);
2738 : 547760 : int overflow_pos = sign == SIGNED ? prec - 1 : prec;
2739 : 547760 : int bound_shift = overflow_pos - rh_ub.to_shwi ();
2740 : : // If bound_shift == HOST_BITS_PER_WIDE_INT, the llshift can
2741 : : // overflow. However, for that to happen, rh.max needs to be zero,
2742 : : // which means rh is a singleton range of zero, which means we simply return
2743 : : // [lh_lb, lh_ub] as the range.
2744 : 547760 : if (wi::eq_p (rh_ub, rh_lb) && wi::eq_p (rh_ub, 0))
2745 : : {
2746 : 24622 : r = int_range<2> (type, lh_lb, lh_ub);
2747 : 24622 : return;
2748 : : }
2749 : :
2750 : 523138 : wide_int bound = wi::set_bit_in_zero (bound_shift, prec);
2751 : 523138 : wide_int complement = ~(bound - 1);
2752 : 523138 : wide_int low_bound, high_bound;
2753 : 523138 : bool in_bounds = false;
2754 : :
2755 : 523138 : if (sign == UNSIGNED)
2756 : : {
2757 : 270763 : low_bound = bound;
2758 : 270763 : high_bound = complement;
2759 : 270763 : if (wi::ltu_p (lh_ub, low_bound))
2760 : : {
2761 : : // [5, 6] << [1, 2] == [10, 24].
2762 : : // We're shifting out only zeroes, the value increases
2763 : : // monotonically.
2764 : : in_bounds = true;
2765 : : }
2766 : 85505 : else if (wi::ltu_p (high_bound, lh_lb))
2767 : : {
2768 : : // [0xffffff00, 0xffffffff] << [1, 2]
2769 : : // == [0xfffffc00, 0xfffffffe].
2770 : : // We're shifting out only ones, the value decreases
2771 : : // monotonically.
2772 : : in_bounds = true;
2773 : : }
2774 : : }
2775 : : else
2776 : : {
2777 : : // [-1, 1] << [1, 2] == [-4, 4]
2778 : 252375 : low_bound = complement;
2779 : 252375 : high_bound = bound;
2780 : 252375 : if (wi::lts_p (lh_ub, high_bound)
2781 : 252375 : && wi::lts_p (low_bound, lh_lb))
2782 : : {
2783 : : // For non-negative numbers, we're shifting out only zeroes,
2784 : : // the value increases monotonically. For negative numbers,
2785 : : // we're shifting out only ones, the value decreases
2786 : : // monotonically.
2787 : : in_bounds = true;
2788 : : }
2789 : : }
2790 : :
2791 : : if (in_bounds)
2792 : 311835 : wi_cross_product (r, type, lh_lb, lh_ub, rh_lb, rh_ub);
2793 : : else
2794 : 211303 : r.set_varying (type);
2795 : 523147 : }
2796 : :
2797 : : bool
2798 : 600323 : operator_lshift::wi_op_overflows (wide_int &res, tree type,
2799 : : const wide_int &w0, const wide_int &w1) const
2800 : : {
2801 : 600323 : signop sign = TYPE_SIGN (type);
2802 : 600323 : if (wi::neg_p (w1))
2803 : : {
2804 : : // It's unclear from the C standard whether shifts can overflow.
2805 : : // The following code ignores overflow; perhaps a C standard
2806 : : // interpretation ruling is needed.
2807 : 0 : res = wi::rshift (w0, -w1, sign);
2808 : : }
2809 : : else
2810 : 600323 : res = wi::lshift (w0, w1);
2811 : 600323 : return false;
2812 : : }
2813 : :
2814 : : bool
2815 : 44314 : operator_lshift::op1_range (irange &r,
2816 : : tree type,
2817 : : const irange &lhs,
2818 : : const irange &op2,
2819 : : relation_trio) const
2820 : : {
2821 : 44314 : if (lhs.undefined_p ())
2822 : : return false;
2823 : :
2824 : 44314 : if (!contains_zero_p (lhs))
2825 : 21251 : r.set_nonzero (type);
2826 : : else
2827 : 23063 : r.set_varying (type);
2828 : :
2829 : 44314 : wide_int shift;
2830 : 44314 : if (op2.singleton_p (shift))
2831 : : {
2832 : 39126 : if (wi::lt_p (shift, 0, SIGNED))
2833 : : return false;
2834 : 39126 : if (wi::ge_p (shift, wi::uhwi (TYPE_PRECISION (type),
2835 : 39126 : TYPE_PRECISION (op2.type ())),
2836 : : UNSIGNED))
2837 : : return false;
2838 : 39126 : if (shift == 0)
2839 : : {
2840 : 6 : r.intersect (lhs);
2841 : 6 : return true;
2842 : : }
2843 : :
2844 : : // Work completely in unsigned mode to start.
2845 : 39120 : tree utype = type;
2846 : 39120 : int_range_max tmp_range;
2847 : 39120 : if (TYPE_SIGN (type) == SIGNED)
2848 : : {
2849 : 7249 : int_range_max tmp = lhs;
2850 : 7249 : utype = unsigned_type_for (type);
2851 : 7249 : range_cast (tmp, utype);
2852 : 7249 : op_rshift.fold_range (tmp_range, utype, tmp, op2);
2853 : 7249 : }
2854 : : else
2855 : 31871 : op_rshift.fold_range (tmp_range, utype, lhs, op2);
2856 : :
2857 : : // Start with ranges which can produce the LHS by right shifting the
2858 : : // result by the shift amount.
2859 : : // ie [0x08, 0xF0] = op1 << 2 will start with
2860 : : // [00001000, 11110000] = op1 << 2
2861 : : // [0x02, 0x4C] aka [00000010, 00111100]
2862 : :
2863 : : // Then create a range from the LB with the least significant upper bit
2864 : : // set, to the upper bound with all the bits set.
2865 : : // This would be [0x42, 0xFC] aka [01000010, 11111100].
2866 : :
2867 : : // Ideally we do this for each subrange, but just lump them all for now.
2868 : 39120 : unsigned low_bits = TYPE_PRECISION (utype) - shift.to_uhwi ();
2869 : 39120 : wide_int up_mask = wi::mask (low_bits, true, TYPE_PRECISION (utype));
2870 : 39120 : wide_int new_ub = wi::bit_or (up_mask, tmp_range.upper_bound ());
2871 : 39120 : wide_int new_lb = wi::set_bit (tmp_range.lower_bound (), low_bits);
2872 : 39120 : int_range<2> fill_range (utype, new_lb, new_ub);
2873 : 39120 : tmp_range.union_ (fill_range);
2874 : :
2875 : 39120 : if (utype != type)
2876 : 7249 : range_cast (tmp_range, type);
2877 : :
2878 : 39120 : r.intersect (tmp_range);
2879 : 39120 : return true;
2880 : 39120 : }
2881 : :
2882 : 5188 : return !r.varying_p ();
2883 : 44314 : }
2884 : :
2885 : : bool
2886 : 820990 : operator_rshift::op1_range (irange &r,
2887 : : tree type,
2888 : : const irange &lhs,
2889 : : const irange &op2,
2890 : : relation_trio) const
2891 : : {
2892 : 820990 : if (lhs.undefined_p ())
2893 : : return false;
2894 : 820990 : wide_int shift;
2895 : 820990 : if (op2.singleton_p (shift))
2896 : : {
2897 : : // Ignore nonsensical shifts.
2898 : 795452 : unsigned prec = TYPE_PRECISION (type);
2899 : 1590904 : if (wi::ge_p (shift,
2900 : 795452 : wi::uhwi (prec, TYPE_PRECISION (op2.type ())),
2901 : : UNSIGNED))
2902 : : return false;
2903 : 795452 : if (shift == 0)
2904 : : {
2905 : 75 : r = lhs;
2906 : 75 : return true;
2907 : : }
2908 : :
2909 : : // Folding the original operation may discard some impossible
2910 : : // ranges from the LHS.
2911 : 795377 : int_range_max lhs_refined;
2912 : 795377 : op_rshift.fold_range (lhs_refined, type, int_range<1> (type), op2);
2913 : 795377 : lhs_refined.intersect (lhs);
2914 : 795377 : if (lhs_refined.undefined_p ())
2915 : : {
2916 : 4 : r.set_undefined ();
2917 : 4 : return true;
2918 : : }
2919 : 795373 : int_range_max shift_range (op2.type (), shift, shift);
2920 : 795373 : int_range_max lb, ub;
2921 : 795373 : op_lshift.fold_range (lb, type, lhs_refined, shift_range);
2922 : : // LHS
2923 : : // 0000 0111 = OP1 >> 3
2924 : : //
2925 : : // OP1 is anything from 0011 1000 to 0011 1111. That is, a
2926 : : // range from LHS<<3 plus a mask of the 3 bits we shifted on the
2927 : : // right hand side (0x07).
2928 : 795373 : wide_int mask = wi::mask (shift.to_uhwi (), false, prec);
2929 : 795373 : int_range_max mask_range (type,
2930 : 795373 : wi::zero (TYPE_PRECISION (type)),
2931 : 795373 : mask);
2932 : 795373 : op_plus.fold_range (ub, type, lb, mask_range);
2933 : 795373 : r = lb;
2934 : 795373 : r.union_ (ub);
2935 : 795373 : if (!contains_zero_p (lhs_refined))
2936 : : {
2937 : 456547 : mask_range.invert ();
2938 : 456547 : r.intersect (mask_range);
2939 : : }
2940 : 795373 : return true;
2941 : 795377 : }
2942 : : return false;
2943 : 820990 : }
2944 : :
2945 : : bool
2946 : 11196470 : operator_rshift::wi_op_overflows (wide_int &res,
2947 : : tree type,
2948 : : const wide_int &w0,
2949 : : const wide_int &w1) const
2950 : : {
2951 : 11196470 : signop sign = TYPE_SIGN (type);
2952 : 11196470 : if (wi::neg_p (w1))
2953 : 0 : res = wi::lshift (w0, -w1);
2954 : : else
2955 : : {
2956 : : // It's unclear from the C standard whether shifts can overflow.
2957 : : // The following code ignores overflow; perhaps a C standard
2958 : : // interpretation ruling is needed.
2959 : 11196561 : res = wi::rshift (w0, w1, sign);
2960 : : }
2961 : 11196470 : return false;
2962 : : }
2963 : :
2964 : : bool
2965 : 3382429 : operator_rshift::fold_range (irange &r, tree type,
2966 : : const irange &op1,
2967 : : const irange &op2,
2968 : : relation_trio rel) const
2969 : : {
2970 : 3382429 : int_range_max shift;
2971 : 3382429 : if (!get_shift_range (shift, type, op2))
2972 : : {
2973 : 662 : if (op2.undefined_p ())
2974 : 255 : r.set_undefined ();
2975 : : else
2976 : 407 : r.set_zero (type);
2977 : 662 : return true;
2978 : : }
2979 : :
2980 : 3381767 : return range_operator::fold_range (r, type, op1, shift, rel);
2981 : 3382429 : }
2982 : :
2983 : : void
2984 : 3946292 : operator_rshift::wi_fold (irange &r, tree type,
2985 : : const wide_int &lh_lb, const wide_int &lh_ub,
2986 : : const wide_int &rh_lb, const wide_int &rh_ub) const
2987 : : {
2988 : 3946292 : wi_cross_product (r, type, lh_lb, lh_ub, rh_lb, rh_ub);
2989 : 3946292 : }
2990 : :
2991 : :
2992 : : // Add a partial equivalence between the LHS and op1 for casts.
2993 : :
2994 : : relation_kind
2995 : 23939212 : operator_cast::lhs_op1_relation (const irange &lhs,
2996 : : const irange &op1,
2997 : : const irange &op2 ATTRIBUTE_UNUSED,
2998 : : relation_kind) const
2999 : : {
3000 : 23939212 : if (lhs.undefined_p () || op1.undefined_p ())
3001 : : return VREL_VARYING;
3002 : 23917769 : unsigned lhs_prec = TYPE_PRECISION (lhs.type ());
3003 : 23917769 : unsigned op1_prec = TYPE_PRECISION (op1.type ());
3004 : : // If the result gets sign extended into a larger type check first if this
3005 : : // qualifies as a partial equivalence.
3006 : 23917769 : if (TYPE_SIGN (op1.type ()) == SIGNED && lhs_prec > op1_prec)
3007 : : {
3008 : : // If the result is sign extended, and the LHS is larger than op1,
3009 : : // check if op1's range can be negative as the sign extension will
3010 : : // cause the upper bits to be 1 instead of 0, invalidating the PE.
3011 : 3699222 : int_range<3> negs = range_negatives (op1.type ());
3012 : 3699222 : negs.intersect (op1);
3013 : 3699222 : if (!negs.undefined_p ())
3014 : 2583833 : return VREL_VARYING;
3015 : 3699222 : }
3016 : :
3017 : 21333936 : unsigned prec = MIN (lhs_prec, op1_prec);
3018 : 21333936 : return bits_to_pe (prec);
3019 : : }
3020 : :
3021 : : // Return TRUE if casting from INNER to OUTER is a truncating cast.
3022 : :
3023 : : inline bool
3024 : 81395922 : operator_cast::truncating_cast_p (const irange &inner,
3025 : : const irange &outer) const
3026 : : {
3027 : 81395922 : return TYPE_PRECISION (outer.type ()) < TYPE_PRECISION (inner.type ());
3028 : : }
3029 : :
3030 : : // Return TRUE if [MIN,MAX] is inside the domain of RANGE's type.
3031 : :
3032 : : bool
3033 : 70481841 : operator_cast::inside_domain_p (const wide_int &min,
3034 : : const wide_int &max,
3035 : : const irange &range) const
3036 : : {
3037 : 70481841 : wide_int domain_min = irange_val_min (range.type ());
3038 : 70481841 : wide_int domain_max = irange_val_max (range.type ());
3039 : 70481841 : signop domain_sign = TYPE_SIGN (range.type ());
3040 : 70481841 : return (wi::le_p (min, domain_max, domain_sign)
3041 : 70481841 : && wi::le_p (max, domain_max, domain_sign)
3042 : 70481841 : && wi::ge_p (min, domain_min, domain_sign)
3043 : 140963682 : && wi::ge_p (max, domain_min, domain_sign));
3044 : 70481841 : }
3045 : :
3046 : :
3047 : : // Helper for fold_range which work on a pair at a time.
3048 : :
3049 : : void
3050 : 73619607 : operator_cast::fold_pair (irange &r, unsigned index,
3051 : : const irange &inner,
3052 : : const irange &outer) const
3053 : : {
3054 : 73619607 : tree inner_type = inner.type ();
3055 : 73619607 : tree outer_type = outer.type ();
3056 : 73619607 : signop inner_sign = TYPE_SIGN (inner_type);
3057 : 73619607 : unsigned outer_prec = TYPE_PRECISION (outer_type);
3058 : :
3059 : : // check to see if casting from INNER to OUTER is a conversion that
3060 : : // fits in the resulting OUTER type.
3061 : 73619607 : wide_int inner_lb = inner.lower_bound (index);
3062 : 73619607 : wide_int inner_ub = inner.upper_bound (index);
3063 : 73619607 : if (truncating_cast_p (inner, outer))
3064 : : {
3065 : : // We may be able to accommodate a truncating cast if the
3066 : : // resulting range can be represented in the target type...
3067 : 14448236 : if (wi::rshift (wi::sub (inner_ub, inner_lb),
3068 : 7224118 : wi::uhwi (outer_prec, TYPE_PRECISION (inner.type ())),
3069 : 21672354 : inner_sign) != 0)
3070 : : {
3071 : 3137766 : r.set_varying (outer_type);
3072 : 3137766 : return;
3073 : : }
3074 : : }
3075 : : // ...but we must still verify that the final range fits in the
3076 : : // domain. This catches -fstrict-enum restrictions where the domain
3077 : : // range is smaller than what fits in the underlying type.
3078 : 70481841 : wide_int min = wide_int::from (inner_lb, outer_prec, inner_sign);
3079 : 70481841 : wide_int max = wide_int::from (inner_ub, outer_prec, inner_sign);
3080 : 70481841 : if (inside_domain_p (min, max, outer))
3081 : 70481841 : create_possibly_reversed_range (r, outer_type, min, max);
3082 : : else
3083 : 0 : r.set_varying (outer_type);
3084 : 73622028 : }
3085 : :
3086 : :
3087 : : bool
3088 : 59226771 : operator_cast::fold_range (irange &r, tree type ATTRIBUTE_UNUSED,
3089 : : const irange &inner,
3090 : : const irange &outer,
3091 : : relation_trio) const
3092 : : {
3093 : 59226771 : if (empty_range_varying (r, type, inner, outer))
3094 : 31355 : return true;
3095 : :
3096 : 59195416 : gcc_checking_assert (outer.varying_p ());
3097 : 59195416 : gcc_checking_assert (inner.num_pairs () > 0);
3098 : :
3099 : : // Avoid a temporary by folding the first pair directly into the result.
3100 : 59195416 : fold_pair (r, 0, inner, outer);
3101 : :
3102 : : // Then process any additional pairs by unioning with their results.
3103 : 72916407 : for (unsigned x = 1; x < inner.num_pairs (); ++x)
3104 : : {
3105 : 14424191 : int_range_max tmp;
3106 : 14424191 : fold_pair (tmp, x, inner, outer);
3107 : 14424191 : r.union_ (tmp);
3108 : : // If we hit varying, go update the bitmask.
3109 : 14424191 : if (r.varying_p ())
3110 : : break;
3111 : 14424191 : }
3112 : :
3113 : 59195416 : update_bitmask (r, inner, outer);
3114 : 59195416 : return true;
3115 : : }
3116 : :
3117 : : void
3118 : 59195416 : operator_cast::update_bitmask (irange &r, const irange &lh,
3119 : : const irange &rh) const
3120 : : {
3121 : 59195416 : update_known_bitmask (r, CONVERT_EXPR, lh, rh);
3122 : 59195416 : }
3123 : :
3124 : : bool
3125 : 7776315 : operator_cast::op1_range (irange &r, tree type,
3126 : : const irange &lhs,
3127 : : const irange &op2,
3128 : : relation_trio) const
3129 : : {
3130 : 7776315 : if (lhs.undefined_p ())
3131 : : return false;
3132 : 7776315 : tree lhs_type = lhs.type ();
3133 : 7776315 : gcc_checking_assert (types_compatible_p (op2.type(), type));
3134 : :
3135 : : // If we are calculating a pointer, shortcut to what we really care about.
3136 : 7776315 : if (POINTER_TYPE_P (type))
3137 : : {
3138 : : // Conversion from other pointers or a constant (including 0/NULL)
3139 : : // are straightforward.
3140 : 0 : if (POINTER_TYPE_P (lhs.type ())
3141 : 0 : || (lhs.singleton_p ()
3142 : 0 : && TYPE_PRECISION (lhs.type ()) >= TYPE_PRECISION (type)))
3143 : : {
3144 : 0 : r = lhs;
3145 : 0 : range_cast (r, type);
3146 : : }
3147 : : else
3148 : : {
3149 : : // If the LHS is not a pointer nor a singleton, then it is
3150 : : // either VARYING or non-zero.
3151 : 0 : if (!lhs.undefined_p () && !contains_zero_p (lhs))
3152 : 0 : r.set_nonzero (type);
3153 : : else
3154 : 0 : r.set_varying (type);
3155 : : }
3156 : 0 : r.intersect (op2);
3157 : 0 : return true;
3158 : : }
3159 : :
3160 : 7776315 : if (truncating_cast_p (op2, lhs))
3161 : : {
3162 : 1352463 : if (lhs.varying_p ())
3163 : 163955 : r.set_varying (type);
3164 : : else
3165 : : {
3166 : : // We want to insert the LHS as an unsigned value since it
3167 : : // would not trigger the signed bit of the larger type.
3168 : 1188508 : int_range_max converted_lhs = lhs;
3169 : 1188508 : range_cast (converted_lhs, unsigned_type_for (lhs_type));
3170 : 1188508 : range_cast (converted_lhs, type);
3171 : : // Start by building the positive signed outer range for the type.
3172 : 1188508 : wide_int lim = wi::set_bit_in_zero (TYPE_PRECISION (lhs_type),
3173 : 2377016 : TYPE_PRECISION (type));
3174 : 1188508 : create_possibly_reversed_range (r, type, lim,
3175 : 1188508 : wi::max_value (TYPE_PRECISION (type),
3176 : : SIGNED));
3177 : : // For the signed part, we need to simply union the 2 ranges now.
3178 : 1188508 : r.union_ (converted_lhs);
3179 : :
3180 : : // Create maximal negative number outside of LHS bits.
3181 : 1188508 : lim = wi::mask (TYPE_PRECISION (lhs_type), true,
3182 : 2377016 : TYPE_PRECISION (type));
3183 : : // Add this to the unsigned LHS range(s).
3184 : 1188508 : int_range_max lim_range (type, lim, lim);
3185 : 1188508 : int_range_max lhs_neg;
3186 : 1188508 : range_op_handler (PLUS_EXPR).fold_range (lhs_neg, type,
3187 : : converted_lhs, lim_range);
3188 : : // lhs_neg now has all the negative versions of the LHS.
3189 : : // Now union in all the values from SIGNED MIN (0x80000) to
3190 : : // lim-1 in order to fill in all the ranges with the upper
3191 : : // bits set.
3192 : :
3193 : : // PR 97317. If the lhs has only 1 bit less precision than the rhs,
3194 : : // we don't need to create a range from min to lim-1
3195 : : // calculate neg range traps trying to create [lim, lim - 1].
3196 : 1188508 : wide_int min_val = wi::min_value (TYPE_PRECISION (type), SIGNED);
3197 : 1188508 : if (lim != min_val)
3198 : : {
3199 : 1186801 : int_range_max neg (type,
3200 : 2373602 : wi::min_value (TYPE_PRECISION (type),
3201 : : SIGNED),
3202 : 2373602 : lim - 1);
3203 : 1186801 : lhs_neg.union_ (neg);
3204 : 1186801 : }
3205 : : // And finally, munge the signed and unsigned portions.
3206 : 1188508 : r.union_ (lhs_neg);
3207 : 1188508 : }
3208 : : // And intersect with any known value passed in the extra operand.
3209 : 1352463 : r.intersect (op2);
3210 : 1352463 : if (r.undefined_p ())
3211 : : return true;
3212 : :
3213 : : // Now create a bitmask indicating that the lower bit must match the
3214 : : // bits in the LHS. Zero-extend LHS bitmask to precision of op1.
3215 : 1352404 : irange_bitmask bm = lhs.get_bitmask ();
3216 : 2704808 : wide_int mask = wide_int::from (bm.mask (), TYPE_PRECISION (type),
3217 : 2704808 : UNSIGNED);
3218 : 2704808 : wide_int value = wide_int::from (bm.value (), TYPE_PRECISION (type),
3219 : 2704808 : UNSIGNED);
3220 : :
3221 : : // Set then additonal unknown bits in mask.
3222 : 1352404 : wide_int lim = wi::mask (TYPE_PRECISION (lhs_type), true,
3223 : 2704808 : TYPE_PRECISION (type));
3224 : 1352404 : mask = mask | lim;
3225 : :
3226 : : // Now set the new bitmask for the range.
3227 : 1352404 : irange_bitmask new_bm (value, mask);
3228 : 1352404 : r.update_bitmask (new_bm);
3229 : 1352404 : return true;
3230 : 1352404 : }
3231 : :
3232 : 6423852 : int_range_max tmp;
3233 : 6423852 : if (TYPE_PRECISION (lhs_type) == TYPE_PRECISION (type))
3234 : 4776413 : tmp = lhs;
3235 : : else
3236 : : {
3237 : : // The cast is not truncating, and the range is restricted to
3238 : : // the range of the RHS by this assignment.
3239 : : //
3240 : : // Cast the range of the RHS to the type of the LHS.
3241 : 1647439 : fold_range (tmp, lhs_type, int_range<1> (type), int_range<1> (lhs_type));
3242 : : // Intersect this with the LHS range will produce the range,
3243 : : // which will be cast to the RHS type before returning.
3244 : 1647439 : tmp.intersect (lhs);
3245 : : }
3246 : :
3247 : : // Cast the calculated range to the type of the RHS.
3248 : 6423852 : fold_range (r, type, tmp, int_range<1> (type));
3249 : 6423852 : return true;
3250 : 6423852 : }
3251 : :
3252 : : // VIEW_CONVERT_EXPR works like a cast between integral values.
3253 : : // If the number of bits are not the same, behaviour is undefined,
3254 : : // so cast behaviour still works.
3255 : :
3256 : : bool
3257 : 277342 : operator_view::fold_range (irange &r, tree type,
3258 : : const irange &op1, const irange &op2,
3259 : : relation_trio rel) const
3260 : : {
3261 : 277342 : return m_cast.fold_range (r, type, op1, op2, rel);
3262 : : }
3263 : :
3264 : : bool
3265 : 0 : operator_view::fold_range (prange &r, tree type,
3266 : : const prange &op1, const prange &op2,
3267 : : relation_trio rel) const
3268 : : {
3269 : 0 : return m_cast.fold_range (r, type, op1, op2, rel);
3270 : : }
3271 : : bool
3272 : 262525 : operator_view::fold_range (irange &r, tree type,
3273 : : const prange &op1, const irange &op2,
3274 : : relation_trio rel) const
3275 : : {
3276 : 262525 : return m_cast.fold_range (r, type, op1, op2, rel);
3277 : : }
3278 : :
3279 : : bool
3280 : 0 : operator_view::fold_range (prange &r, tree type,
3281 : : const irange &op1, const prange &op2,
3282 : : relation_trio rel) const
3283 : : {
3284 : 0 : return m_cast.fold_range (r, type, op1, op2, rel);
3285 : : }
3286 : :
3287 : : bool
3288 : 13633 : operator_view::op1_range (irange &r, tree type,
3289 : : const irange &lhs, const irange &op2,
3290 : : relation_trio rel) const
3291 : : {
3292 : 13633 : return m_cast.op1_range (r, type, lhs, op2, rel);
3293 : : }
3294 : :
3295 : : bool
3296 : 0 : operator_view::op1_range (prange &r, tree type,
3297 : : const prange &lhs, const prange &op2,
3298 : : relation_trio rel) const
3299 : : {
3300 : 0 : return m_cast.op1_range (r, type, lhs, op2, rel);
3301 : : }
3302 : :
3303 : : bool
3304 : 0 : operator_view::op1_range (irange &r, tree type,
3305 : : const prange &lhs, const irange &op2,
3306 : : relation_trio rel) const
3307 : : {
3308 : 0 : return m_cast.op1_range (r, type, lhs, op2, rel);
3309 : : }
3310 : :
3311 : : bool
3312 : 0 : operator_view::op1_range (prange &r, tree type,
3313 : : const irange &lhs, const prange &op2,
3314 : : relation_trio rel) const
3315 : : {
3316 : 0 : return m_cast.op1_range (r, type, lhs, op2, rel);
3317 : : }
3318 : :
3319 : : void
3320 : 0 : operator_view::update_bitmask (irange &r, const irange &lh,
3321 : : const irange &rh) const
3322 : : {
3323 : 0 : m_cast.update_bitmask (r, lh, rh);
3324 : 0 : }
3325 : :
3326 : :
3327 : : class operator_logical_and : public range_operator
3328 : : {
3329 : : using range_operator::fold_range;
3330 : : using range_operator::op1_range;
3331 : : using range_operator::op2_range;
3332 : : public:
3333 : : bool fold_range (irange &r, tree type,
3334 : : const irange &lh,
3335 : : const irange &rh,
3336 : : relation_trio rel = TRIO_VARYING) const final override;
3337 : : bool op1_range (irange &r, tree type,
3338 : : const irange &lhs,
3339 : : const irange &op2,
3340 : : relation_trio rel = TRIO_VARYING) const final override;
3341 : : bool op2_range (irange &r, tree type,
3342 : : const irange &lhs,
3343 : : const irange &op1,
3344 : : relation_trio rel = TRIO_VARYING) const final override;
3345 : : // Check compatibility of all operands.
3346 : 0 : bool operand_check_p (tree t1, tree t2, tree t3) const final override
3347 : 0 : { return range_compatible_p (t1, t2) && range_compatible_p (t1, t3); }
3348 : : } op_logical_and;
3349 : :
3350 : : bool
3351 : 0 : operator_logical_and::fold_range (irange &r, tree type,
3352 : : const irange &lh,
3353 : : const irange &rh,
3354 : : relation_trio) const
3355 : : {
3356 : 0 : if (empty_range_varying (r, type, lh, rh))
3357 : 0 : return true;
3358 : :
3359 : : // Precision of LHS and both operands must match.
3360 : 0 : if (TYPE_PRECISION (lh.type ()) != TYPE_PRECISION (type)
3361 : 0 : || TYPE_PRECISION (type) != TYPE_PRECISION (rh.type ()))
3362 : 0 : return false;
3363 : :
3364 : : // 0 && anything is 0.
3365 : 0 : if ((wi::eq_p (lh.lower_bound (), 0) && wi::eq_p (lh.upper_bound (), 0))
3366 : 0 : || (wi::eq_p (lh.lower_bound (), 0) && wi::eq_p (rh.upper_bound (), 0)))
3367 : 0 : r = range_false (type);
3368 : 0 : else if (contains_zero_p (lh) || contains_zero_p (rh))
3369 : : // To reach this point, there must be a logical 1 on each side, and
3370 : : // the only remaining question is whether there is a zero or not.
3371 : 0 : r = range_true_and_false (type);
3372 : : else
3373 : 0 : r = range_true (type);
3374 : : return true;
3375 : : }
3376 : :
3377 : : bool
3378 : 901076 : operator_logical_and::op1_range (irange &r, tree type,
3379 : : const irange &lhs,
3380 : : const irange &op2 ATTRIBUTE_UNUSED,
3381 : : relation_trio) const
3382 : : {
3383 : 901076 : switch (get_bool_state (r, lhs, type))
3384 : : {
3385 : 479399 : case BRS_TRUE:
3386 : : // A true result means both sides of the AND must be true.
3387 : 479399 : r = range_true (type);
3388 : 479399 : break;
3389 : 421677 : default:
3390 : : // Any other result means only one side has to be false, the
3391 : : // other side can be anything. So we cannot be sure of any
3392 : : // result here.
3393 : 421677 : r = range_true_and_false (type);
3394 : 421677 : break;
3395 : : }
3396 : 901076 : return true;
3397 : : }
3398 : :
3399 : : bool
3400 : 0 : operator_logical_and::op2_range (irange &r, tree type,
3401 : : const irange &lhs,
3402 : : const irange &op1,
3403 : : relation_trio) const
3404 : : {
3405 : 0 : return operator_logical_and::op1_range (r, type, lhs, op1);
3406 : : }
3407 : :
3408 : :
3409 : : void
3410 : 7812181 : operator_bitwise_and::update_bitmask (irange &r, const irange &lh,
3411 : : const irange &rh) const
3412 : : {
3413 : 7812181 : update_known_bitmask (r, BIT_AND_EXPR, lh, rh);
3414 : 7812181 : }
3415 : :
3416 : : // Optimize BIT_AND_EXPR, BIT_IOR_EXPR and BIT_XOR_EXPR of signed types
3417 : : // by considering the number of leading redundant sign bit copies.
3418 : : // clrsb (X op Y) = min (clrsb (X), clrsb (Y)), so for example
3419 : : // [-1, 0] op [-1, 0] is [-1, 0] (where nonzero_bits doesn't help).
3420 : : static bool
3421 : 185045 : wi_optimize_signed_bitwise_op (irange &r, tree type,
3422 : : const wide_int &lh_lb, const wide_int &lh_ub,
3423 : : const wide_int &rh_lb, const wide_int &rh_ub)
3424 : : {
3425 : 370090 : int lh_clrsb = MIN (wi::clrsb (lh_lb), wi::clrsb (lh_ub));
3426 : 370090 : int rh_clrsb = MIN (wi::clrsb (rh_lb), wi::clrsb (rh_ub));
3427 : 185045 : int new_clrsb = MIN (lh_clrsb, rh_clrsb);
3428 : 185045 : if (new_clrsb == 0)
3429 : : return false;
3430 : 13823 : int type_prec = TYPE_PRECISION (type);
3431 : 13823 : int rprec = (type_prec - new_clrsb) - 1;
3432 : 13823 : value_range_with_overflow (r, type,
3433 : 27646 : wi::mask (rprec, true, type_prec),
3434 : 13823 : wi::mask (rprec, false, type_prec));
3435 : 13823 : return true;
3436 : : }
3437 : :
3438 : : // An AND of 8,16, 32 or 64 bits can produce a partial equivalence between
3439 : : // the LHS and op1.
3440 : :
3441 : : relation_kind
3442 : 7079228 : operator_bitwise_and::lhs_op1_relation (const irange &lhs,
3443 : : const irange &op1,
3444 : : const irange &op2,
3445 : : relation_kind) const
3446 : : {
3447 : 7079228 : if (lhs.undefined_p () || op1.undefined_p () || op2.undefined_p ())
3448 : : return VREL_VARYING;
3449 : 7075085 : if (!op2.singleton_p ())
3450 : : return VREL_VARYING;
3451 : : // if val == 0xff or 0xFFFF OR 0Xffffffff OR 0Xffffffffffffffff, return TRUE
3452 : 4067671 : int prec1 = TYPE_PRECISION (op1.type ());
3453 : 4067671 : int prec2 = TYPE_PRECISION (op2.type ());
3454 : 4067671 : int mask_prec = 0;
3455 : 4067671 : wide_int mask = op2.lower_bound ();
3456 : 4067671 : if (wi::eq_p (mask, wi::mask (8, false, prec2)))
3457 : : mask_prec = 8;
3458 : 3970626 : else if (wi::eq_p (mask, wi::mask (16, false, prec2)))
3459 : : mask_prec = 16;
3460 : 3953301 : else if (wi::eq_p (mask, wi::mask (32, false, prec2)))
3461 : : mask_prec = 32;
3462 : 3753907 : else if (wi::eq_p (mask, wi::mask (64, false, prec2)))
3463 : 791 : mask_prec = 64;
3464 : 4067671 : return bits_to_pe (MIN (prec1, mask_prec));
3465 : 4067671 : }
3466 : :
3467 : : // Optimize BIT_AND_EXPR and BIT_IOR_EXPR in terms of a mask if
3468 : : // possible. Basically, see if we can optimize:
3469 : : //
3470 : : // [LB, UB] op Z
3471 : : // into:
3472 : : // [LB op Z, UB op Z]
3473 : : //
3474 : : // If the optimization was successful, accumulate the range in R and
3475 : : // return TRUE.
3476 : :
3477 : : static bool
3478 : 23623632 : wi_optimize_and_or (irange &r,
3479 : : enum tree_code code,
3480 : : tree type,
3481 : : const wide_int &lh_lb, const wide_int &lh_ub,
3482 : : const wide_int &rh_lb, const wide_int &rh_ub)
3483 : : {
3484 : : // Calculate the singleton mask among the ranges, if any.
3485 : 23623632 : wide_int lower_bound, upper_bound, mask;
3486 : 23623632 : if (wi::eq_p (rh_lb, rh_ub))
3487 : : {
3488 : 22010926 : mask = rh_lb;
3489 : 22010926 : lower_bound = lh_lb;
3490 : 22010926 : upper_bound = lh_ub;
3491 : : }
3492 : 1612706 : else if (wi::eq_p (lh_lb, lh_ub))
3493 : : {
3494 : 316018 : mask = lh_lb;
3495 : 316018 : lower_bound = rh_lb;
3496 : 316018 : upper_bound = rh_ub;
3497 : : }
3498 : : else
3499 : : return false;
3500 : :
3501 : : // If Z is a constant which (for op | its bitwise not) has n
3502 : : // consecutive least significant bits cleared followed by m 1
3503 : : // consecutive bits set immediately above it and either
3504 : : // m + n == precision, or (x >> (m + n)) == (y >> (m + n)).
3505 : : //
3506 : : // The least significant n bits of all the values in the range are
3507 : : // cleared or set, the m bits above it are preserved and any bits
3508 : : // above these are required to be the same for all values in the
3509 : : // range.
3510 : 22326944 : wide_int w = mask;
3511 : 22326944 : int m = 0, n = 0;
3512 : 22326944 : if (code == BIT_IOR_EXPR)
3513 : 6527138 : w = ~w;
3514 : 22326944 : if (wi::eq_p (w, 0))
3515 : 7522261 : n = w.get_precision ();
3516 : : else
3517 : : {
3518 : 14804683 : n = wi::ctz (w);
3519 : 14804689 : w = ~(w | wi::mask (n, false, w.get_precision ()));
3520 : 14804683 : if (wi::eq_p (w, 0))
3521 : 8741680 : m = w.get_precision () - n;
3522 : : else
3523 : 6063003 : m = wi::ctz (w) - n;
3524 : : }
3525 : 22326944 : wide_int new_mask = wi::mask (m + n, true, w.get_precision ());
3526 : 22326950 : if ((new_mask & lower_bound) != (new_mask & upper_bound))
3527 : : return false;
3528 : :
3529 : 17120393 : wide_int res_lb, res_ub;
3530 : 17120393 : if (code == BIT_AND_EXPR)
3531 : : {
3532 : 10851846 : res_lb = wi::bit_and (lower_bound, mask);
3533 : 10851846 : res_ub = wi::bit_and (upper_bound, mask);
3534 : : }
3535 : 6268547 : else if (code == BIT_IOR_EXPR)
3536 : : {
3537 : 6268547 : res_lb = wi::bit_or (lower_bound, mask);
3538 : 6268547 : res_ub = wi::bit_or (upper_bound, mask);
3539 : : }
3540 : : else
3541 : 0 : gcc_unreachable ();
3542 : 17120393 : value_range_with_overflow (r, type, res_lb, res_ub);
3543 : :
3544 : : // Furthermore, if the mask is non-zero, an IOR cannot contain zero.
3545 : 17120393 : if (code == BIT_IOR_EXPR && wi::ne_p (mask, 0))
3546 : : {
3547 : 3184779 : int_range<2> tmp;
3548 : 3184779 : tmp.set_nonzero (type);
3549 : 3184779 : r.intersect (tmp);
3550 : 3184779 : }
3551 : 17120393 : return true;
3552 : 63070975 : }
3553 : :
3554 : : // For range [LB, UB] compute two wide_int bit masks.
3555 : : //
3556 : : // In the MAYBE_NONZERO bit mask, if some bit is unset, it means that
3557 : : // for all numbers in the range the bit is 0, otherwise it might be 0
3558 : : // or 1.
3559 : : //
3560 : : // In the MUSTBE_NONZERO bit mask, if some bit is set, it means that
3561 : : // for all numbers in the range the bit is 1, otherwise it might be 0
3562 : : // or 1.
3563 : :
3564 : : void
3565 : 14073231 : wi_set_zero_nonzero_bits (tree type,
3566 : : const wide_int &lb, const wide_int &ub,
3567 : : wide_int &maybe_nonzero,
3568 : : wide_int &mustbe_nonzero)
3569 : : {
3570 : 14073231 : signop sign = TYPE_SIGN (type);
3571 : :
3572 : 14073231 : if (wi::eq_p (lb, ub))
3573 : 5705540 : maybe_nonzero = mustbe_nonzero = lb;
3574 : 8367691 : else if (wi::ge_p (lb, 0, sign) || wi::lt_p (ub, 0, sign))
3575 : : {
3576 : 7910274 : wide_int xor_mask = lb ^ ub;
3577 : 7910274 : maybe_nonzero = lb | ub;
3578 : 7910274 : mustbe_nonzero = lb & ub;
3579 : 7910274 : if (xor_mask != 0)
3580 : : {
3581 : 7910274 : wide_int mask = wi::mask (wi::floor_log2 (xor_mask), false,
3582 : 15820548 : maybe_nonzero.get_precision ());
3583 : 7910274 : maybe_nonzero = maybe_nonzero | mask;
3584 : 7910279 : mustbe_nonzero = wi::bit_and_not (mustbe_nonzero, mask);
3585 : 7910274 : }
3586 : 7910274 : }
3587 : : else
3588 : : {
3589 : 457417 : maybe_nonzero = wi::minus_one (lb.get_precision ());
3590 : 457417 : mustbe_nonzero = wi::zero (lb.get_precision ());
3591 : : }
3592 : 14073231 : }
3593 : :
3594 : : void
3595 : 17078212 : operator_bitwise_and::wi_fold (irange &r, tree type,
3596 : : const wide_int &lh_lb,
3597 : : const wide_int &lh_ub,
3598 : : const wide_int &rh_lb,
3599 : : const wide_int &rh_ub) const
3600 : : {
3601 : : // The AND algorithm does not handle complex signed operations well.
3602 : : // If a signed range crosses the boundry between signed and unsigned
3603 : : // proces sit as 2 ranges and union the results.
3604 : 17078212 : if (TYPE_SIGN (type) == SIGNED
3605 : 17078212 : && wi::neg_p (lh_lb, SIGNED) != wi::neg_p (lh_ub, SIGNED))
3606 : : {
3607 : 610025 : int prec = TYPE_PRECISION (type);
3608 : 610025 : int_range_max tmp;
3609 : : // Process [lh_lb, -1]
3610 : 610025 : wi_fold (tmp, type, lh_lb, wi::minus_one (prec), rh_lb, rh_ub);
3611 : : // Now Process [0, rh_ub]
3612 : 610025 : wi_fold (r, type, wi::zero (prec), lh_ub, rh_lb, rh_ub);
3613 : 610025 : r.union_ (tmp);
3614 : 610025 : return;
3615 : 610025 : }
3616 : :
3617 : 16468187 : if (wi_optimize_and_or (r, BIT_AND_EXPR, type, lh_lb, lh_ub, rh_lb, rh_ub))
3618 : : return;
3619 : :
3620 : 5616341 : wide_int maybe_nonzero_lh, mustbe_nonzero_lh;
3621 : 5616341 : wide_int maybe_nonzero_rh, mustbe_nonzero_rh;
3622 : 5616341 : wi_set_zero_nonzero_bits (type, lh_lb, lh_ub,
3623 : : maybe_nonzero_lh, mustbe_nonzero_lh);
3624 : 5616341 : wi_set_zero_nonzero_bits (type, rh_lb, rh_ub,
3625 : : maybe_nonzero_rh, mustbe_nonzero_rh);
3626 : :
3627 : 5616341 : wide_int new_lb = mustbe_nonzero_lh & mustbe_nonzero_rh;
3628 : 5616341 : wide_int new_ub = maybe_nonzero_lh & maybe_nonzero_rh;
3629 : 5616341 : signop sign = TYPE_SIGN (type);
3630 : 5616341 : unsigned prec = TYPE_PRECISION (type);
3631 : : // If both input ranges contain only negative values, we can
3632 : : // truncate the result range maximum to the minimum of the
3633 : : // input range maxima.
3634 : 5616341 : if (wi::lt_p (lh_ub, 0, sign) && wi::lt_p (rh_ub, 0, sign))
3635 : : {
3636 : 49029 : new_ub = wi::min (new_ub, lh_ub, sign);
3637 : 49029 : new_ub = wi::min (new_ub, rh_ub, sign);
3638 : : }
3639 : : // If either input range contains only non-negative values
3640 : : // we can truncate the result range maximum to the respective
3641 : : // maximum of the input range.
3642 : 5616341 : if (wi::ge_p (lh_lb, 0, sign))
3643 : 4866345 : new_ub = wi::min (new_ub, lh_ub, sign);
3644 : 5616341 : if (wi::ge_p (rh_lb, 0, sign))
3645 : 5375425 : new_ub = wi::min (new_ub, rh_ub, sign);
3646 : : // PR68217: In case of signed & sign-bit-CST should
3647 : : // result in [-INF, 0] instead of [-INF, INF].
3648 : 5616341 : if (wi::gt_p (new_lb, new_ub, sign))
3649 : : {
3650 : 58829 : wide_int sign_bit = wi::set_bit_in_zero (prec - 1, prec);
3651 : 58829 : if (sign == SIGNED
3652 : 58829 : && ((wi::eq_p (lh_lb, lh_ub)
3653 : 69 : && !wi::cmps (lh_lb, sign_bit))
3654 : 58829 : || (wi::eq_p (rh_lb, rh_ub)
3655 : 0 : && !wi::cmps (rh_lb, sign_bit))))
3656 : : {
3657 : 0 : new_lb = wi::min_value (prec, sign);
3658 : 0 : new_ub = wi::zero (prec);
3659 : : }
3660 : 58829 : }
3661 : : // If the limits got swapped around, return varying.
3662 : 5616341 : if (wi::gt_p (new_lb, new_ub,sign))
3663 : : {
3664 : 58829 : if (sign == SIGNED
3665 : 58829 : && wi_optimize_signed_bitwise_op (r, type,
3666 : : lh_lb, lh_ub,
3667 : : rh_lb, rh_ub))
3668 : 4780 : return;
3669 : 54049 : r.set_varying (type);
3670 : : }
3671 : : else
3672 : 5557512 : value_range_with_overflow (r, type, new_lb, new_ub);
3673 : 5616341 : }
3674 : :
3675 : : static void
3676 : 521215 : set_nonzero_range_from_mask (irange &r, tree type, const irange &lhs)
3677 : : {
3678 : 521215 : if (lhs.undefined_p () || contains_zero_p (lhs))
3679 : 274563 : r.set_varying (type);
3680 : : else
3681 : 246652 : r.set_nonzero (type);
3682 : 521215 : }
3683 : :
3684 : : /* Find out smallest RES where RES > VAL && (RES & MASK) == RES, if any
3685 : : (otherwise return VAL). VAL and MASK must be zero-extended for
3686 : : precision PREC. If SGNBIT is non-zero, first xor VAL with SGNBIT
3687 : : (to transform signed values into unsigned) and at the end xor
3688 : : SGNBIT back. */
3689 : :
3690 : : wide_int
3691 : 36685 : masked_increment (const wide_int &val_in, const wide_int &mask,
3692 : : const wide_int &sgnbit, unsigned int prec)
3693 : : {
3694 : 36685 : wide_int bit = wi::one (prec), res;
3695 : 36685 : unsigned int i;
3696 : :
3697 : 36685 : wide_int val = val_in ^ sgnbit;
3698 : 564626 : for (i = 0; i < prec; i++, bit += bit)
3699 : : {
3700 : 518593 : res = mask;
3701 : 518593 : if ((res & bit) == 0)
3702 : 431261 : continue;
3703 : 87332 : res = bit - 1;
3704 : 87332 : res = wi::bit_and_not (val + bit, res);
3705 : 87332 : res &= mask;
3706 : 87332 : if (wi::gtu_p (res, val))
3707 : 27337 : return res ^ sgnbit;
3708 : : }
3709 : 9348 : return val ^ sgnbit;
3710 : 36685 : }
3711 : :
3712 : : // This was shamelessly stolen from register_edge_assert_for_2 and
3713 : : // adjusted to work with iranges.
3714 : :
3715 : : void
3716 : 3401685 : operator_bitwise_and::simple_op1_range_solver (irange &r, tree type,
3717 : : const irange &lhs,
3718 : : const irange &op2) const
3719 : : {
3720 : 3401685 : if (!op2.singleton_p ())
3721 : : {
3722 : 520292 : set_nonzero_range_from_mask (r, type, lhs);
3723 : 1046335 : return;
3724 : : }
3725 : 2881393 : unsigned int nprec = TYPE_PRECISION (type);
3726 : 2881393 : wide_int cst2v = op2.lower_bound ();
3727 : 2881393 : bool cst2n = wi::neg_p (cst2v, TYPE_SIGN (type));
3728 : 2881393 : wide_int sgnbit;
3729 : 2881393 : if (cst2n)
3730 : 574718 : sgnbit = wi::set_bit_in_zero (nprec - 1, nprec);
3731 : : else
3732 : 2306675 : sgnbit = wi::zero (nprec);
3733 : :
3734 : : // Solve [lhs.lower_bound (), +INF] = x & MASK.
3735 : : //
3736 : : // Minimum unsigned value for >= if (VAL & CST2) == VAL is VAL and
3737 : : // maximum unsigned value is ~0. For signed comparison, if CST2
3738 : : // doesn't have the most significant bit set, handle it similarly. If
3739 : : // CST2 has MSB set, the minimum is the same, and maximum is ~0U/2.
3740 : 2881393 : wide_int valv = lhs.lower_bound ();
3741 : 2881393 : wide_int minv = valv & cst2v, maxv;
3742 : 2881393 : bool we_know_nothing = false;
3743 : 2881393 : if (minv != valv)
3744 : : {
3745 : : // If (VAL & CST2) != VAL, X & CST2 can't be equal to VAL.
3746 : 7865 : minv = masked_increment (valv, cst2v, sgnbit, nprec);
3747 : 7865 : if (minv == valv)
3748 : : {
3749 : : // If we can't determine anything on this bound, fall
3750 : : // through and conservatively solve for the other end point.
3751 : 2881393 : we_know_nothing = true;
3752 : : }
3753 : : }
3754 : 5188068 : maxv = wi::mask (nprec - (cst2n ? 1 : 0), false, nprec);
3755 : 2881393 : if (we_know_nothing)
3756 : 3597 : r.set_varying (type);
3757 : : else
3758 : 2877796 : create_possibly_reversed_range (r, type, minv, maxv);
3759 : :
3760 : : // Solve [-INF, lhs.upper_bound ()] = x & MASK.
3761 : : //
3762 : : // Minimum unsigned value for <= is 0 and maximum unsigned value is
3763 : : // VAL | ~CST2 if (VAL & CST2) == VAL. Otherwise, find smallest
3764 : : // VAL2 where
3765 : : // VAL2 > VAL && (VAL2 & CST2) == VAL2 and use (VAL2 - 1) | ~CST2
3766 : : // as maximum.
3767 : : // For signed comparison, if CST2 doesn't have most significant bit
3768 : : // set, handle it similarly. If CST2 has MSB set, the maximum is
3769 : : // the same and minimum is INT_MIN.
3770 : 2881393 : valv = lhs.upper_bound ();
3771 : 2881393 : minv = valv & cst2v;
3772 : 2881393 : if (minv == valv)
3773 : 2852573 : maxv = valv;
3774 : : else
3775 : : {
3776 : 28820 : maxv = masked_increment (valv, cst2v, sgnbit, nprec);
3777 : 28820 : if (maxv == valv)
3778 : : {
3779 : : // If we couldn't determine anything on either bound, return
3780 : : // undefined.
3781 : 5751 : if (we_know_nothing)
3782 : 2632 : r.set_undefined ();
3783 : 5751 : return;
3784 : : }
3785 : 23069 : maxv -= 1;
3786 : : }
3787 : 2875642 : maxv |= ~cst2v;
3788 : 2875642 : minv = sgnbit;
3789 : 2875642 : int_range<2> upper_bits;
3790 : 2875642 : create_possibly_reversed_range (upper_bits, type, minv, maxv);
3791 : 2875642 : r.intersect (upper_bits);
3792 : 2881393 : }
3793 : :
3794 : : bool
3795 : 3529283 : operator_bitwise_and::op1_range (irange &r, tree type,
3796 : : const irange &lhs,
3797 : : const irange &op2,
3798 : : relation_trio) const
3799 : : {
3800 : 3529283 : if (lhs.undefined_p ())
3801 : : return false;
3802 : 3529283 : if (types_compatible_p (type, boolean_type_node))
3803 : 901076 : return op_logical_and.op1_range (r, type, lhs, op2);
3804 : :
3805 : 2628207 : r.set_undefined ();
3806 : 6029892 : for (unsigned i = 0; i < lhs.num_pairs (); ++i)
3807 : : {
3808 : 6803370 : int_range_max chunk (lhs.type (),
3809 : 6803370 : lhs.lower_bound (i),
3810 : 6803370 : lhs.upper_bound (i));
3811 : 3401685 : int_range_max res;
3812 : 3401685 : simple_op1_range_solver (res, type, chunk, op2);
3813 : 3401685 : r.union_ (res);
3814 : 3401685 : }
3815 : 2628207 : if (r.undefined_p ())
3816 : 923 : set_nonzero_range_from_mask (r, type, lhs);
3817 : :
3818 : : // For MASK == op1 & MASK, all the bits in MASK must be set in op1.
3819 : 2628207 : wide_int mask;
3820 : 2628207 : if (lhs == op2 && lhs.singleton_p (mask))
3821 : : {
3822 : 364242 : r.update_bitmask (irange_bitmask (mask, ~mask));
3823 : 364242 : return true;
3824 : : }
3825 : :
3826 : 2263965 : if (!op2.singleton_p (mask))
3827 : : return true;
3828 : :
3829 : : // For 0 = op1 & MASK, op1 is ~MASK.
3830 : 1796575 : if (lhs.zero_p ())
3831 : : {
3832 : 656039 : wide_int nz = wi::bit_not (op2.get_nonzero_bits ());
3833 : 656039 : int_range<2> tmp (type);
3834 : 656039 : tmp.set_nonzero_bits (nz);
3835 : 656039 : r.intersect (tmp);
3836 : 656039 : }
3837 : :
3838 : 1796575 : irange_bitmask lhs_bm = lhs.get_bitmask ();
3839 : : // given [5,7] mask 0x3 value 0x4 = N & [7, 7] mask 0x0 value 0x7
3840 : : // Nothing is known about the bits not specified in the mask value (op2),
3841 : : // Start with the mask, 1's will occur where values were masked.
3842 : 1796575 : wide_int op1_mask = ~mask;
3843 : : // Any bits that are unknown on the LHS are also unknown in op1,
3844 : : // so union the current mask with the LHS mask.
3845 : 1796575 : op1_mask |= lhs_bm.mask ();
3846 : : // The resulting zeros correspond to known bits in the LHS mask, and
3847 : : // the LHS value should tell us what they are. Mask off any
3848 : : // extraneous values thats are not convered by the mask.
3849 : 1796575 : wide_int op1_value = lhs_bm.value () & ~op1_mask;
3850 : 1796575 : irange_bitmask op1_bm (op1_value, op1_mask);
3851 : : // INtersect this mask with anything already known about the value.
3852 : 1796575 : op1_bm.intersect (r.get_bitmask ());
3853 : 1796575 : r.update_bitmask (op1_bm);
3854 : 1796575 : return true;
3855 : 4424782 : }
3856 : :
3857 : : bool
3858 : 775603 : operator_bitwise_and::op2_range (irange &r, tree type,
3859 : : const irange &lhs,
3860 : : const irange &op1,
3861 : : relation_trio) const
3862 : : {
3863 : 775603 : return operator_bitwise_and::op1_range (r, type, lhs, op1);
3864 : : }
3865 : :
3866 : :
3867 : : class operator_logical_or : public range_operator
3868 : : {
3869 : : using range_operator::fold_range;
3870 : : using range_operator::op1_range;
3871 : : using range_operator::op2_range;
3872 : : public:
3873 : : bool fold_range (irange &r, tree type,
3874 : : const irange &lh,
3875 : : const irange &rh,
3876 : : relation_trio rel = TRIO_VARYING) const final override;
3877 : : bool op1_range (irange &r, tree type,
3878 : : const irange &lhs,
3879 : : const irange &op2,
3880 : : relation_trio rel = TRIO_VARYING) const final override;
3881 : : bool op2_range (irange &r, tree type,
3882 : : const irange &lhs,
3883 : : const irange &op1,
3884 : : relation_trio rel = TRIO_VARYING) const final override;
3885 : : // Check compatibility of all operands.
3886 : 0 : bool operand_check_p (tree t1, tree t2, tree t3) const final override
3887 : 0 : { return range_compatible_p (t1, t2) && range_compatible_p (t1, t3); }
3888 : : } op_logical_or;
3889 : :
3890 : : bool
3891 : 0 : operator_logical_or::fold_range (irange &r, tree type ATTRIBUTE_UNUSED,
3892 : : const irange &lh,
3893 : : const irange &rh,
3894 : : relation_trio) const
3895 : : {
3896 : 0 : if (empty_range_varying (r, type, lh, rh))
3897 : 0 : return true;
3898 : :
3899 : 0 : r = lh;
3900 : 0 : r.union_ (rh);
3901 : 0 : return true;
3902 : : }
3903 : :
3904 : : bool
3905 : 336802 : operator_logical_or::op1_range (irange &r, tree type,
3906 : : const irange &lhs,
3907 : : const irange &op2 ATTRIBUTE_UNUSED,
3908 : : relation_trio) const
3909 : : {
3910 : 336802 : switch (get_bool_state (r, lhs, type))
3911 : : {
3912 : 203567 : case BRS_FALSE:
3913 : : // A false result means both sides of the OR must be false.
3914 : 203567 : r = range_false (type);
3915 : 203567 : break;
3916 : 133235 : default:
3917 : : // Any other result means only one side has to be true, the
3918 : : // other side can be anything. so we can't be sure of any result
3919 : : // here.
3920 : 133235 : r = range_true_and_false (type);
3921 : 133235 : break;
3922 : : }
3923 : 336802 : return true;
3924 : : }
3925 : :
3926 : : bool
3927 : 0 : operator_logical_or::op2_range (irange &r, tree type,
3928 : : const irange &lhs,
3929 : : const irange &op1,
3930 : : relation_trio) const
3931 : : {
3932 : 0 : return operator_logical_or::op1_range (r, type, lhs, op1);
3933 : : }
3934 : :
3935 : :
3936 : : void
3937 : 2464577 : operator_bitwise_or::update_bitmask (irange &r, const irange &lh,
3938 : : const irange &rh) const
3939 : : {
3940 : 2464577 : update_known_bitmask (r, BIT_IOR_EXPR, lh, rh);
3941 : 2464577 : }
3942 : :
3943 : : void
3944 : 7155445 : operator_bitwise_or::wi_fold (irange &r, tree type,
3945 : : const wide_int &lh_lb,
3946 : : const wide_int &lh_ub,
3947 : : const wide_int &rh_lb,
3948 : : const wide_int &rh_ub) const
3949 : : {
3950 : 7155445 : if (wi_optimize_and_or (r, BIT_IOR_EXPR, type, lh_lb, lh_ub, rh_lb, rh_ub))
3951 : 6460171 : return;
3952 : :
3953 : 886898 : wide_int maybe_nonzero_lh, mustbe_nonzero_lh;
3954 : 886898 : wide_int maybe_nonzero_rh, mustbe_nonzero_rh;
3955 : 886898 : wi_set_zero_nonzero_bits (type, lh_lb, lh_ub,
3956 : : maybe_nonzero_lh, mustbe_nonzero_lh);
3957 : 886898 : wi_set_zero_nonzero_bits (type, rh_lb, rh_ub,
3958 : : maybe_nonzero_rh, mustbe_nonzero_rh);
3959 : 886898 : wide_int new_lb = mustbe_nonzero_lh | mustbe_nonzero_rh;
3960 : 886898 : wide_int new_ub = maybe_nonzero_lh | maybe_nonzero_rh;
3961 : 886898 : signop sign = TYPE_SIGN (type);
3962 : : // If the input ranges contain only positive values we can
3963 : : // truncate the minimum of the result range to the maximum
3964 : : // of the input range minima.
3965 : 886898 : if (wi::ge_p (lh_lb, 0, sign)
3966 : 886898 : && wi::ge_p (rh_lb, 0, sign))
3967 : : {
3968 : 664029 : new_lb = wi::max (new_lb, lh_lb, sign);
3969 : 664029 : new_lb = wi::max (new_lb, rh_lb, sign);
3970 : : }
3971 : : // If either input range contains only negative values
3972 : : // we can truncate the minimum of the result range to the
3973 : : // respective minimum range.
3974 : 886898 : if (wi::lt_p (lh_ub, 0, sign))
3975 : 21398 : new_lb = wi::max (new_lb, lh_lb, sign);
3976 : 886898 : if (wi::lt_p (rh_ub, 0, sign))
3977 : 10844 : new_lb = wi::max (new_lb, rh_lb, sign);
3978 : : // If the limits got swapped around, return a conservative range.
3979 : 886898 : if (wi::gt_p (new_lb, new_ub, sign))
3980 : : {
3981 : : // Make sure that nonzero|X is nonzero.
3982 : 191624 : if (wi::gt_p (lh_lb, 0, sign)
3983 : 187416 : || wi::gt_p (rh_lb, 0, sign)
3984 : 119149 : || wi::lt_p (lh_ub, 0, sign)
3985 : 310773 : || wi::lt_p (rh_ub, 0, sign))
3986 : 72475 : r.set_nonzero (type);
3987 : 119149 : else if (sign == SIGNED
3988 : 119149 : && wi_optimize_signed_bitwise_op (r, type,
3989 : : lh_lb, lh_ub,
3990 : : rh_lb, rh_ub))
3991 : : return;
3992 : : else
3993 : 116313 : r.set_varying (type);
3994 : 188788 : return;
3995 : : }
3996 : 695274 : value_range_with_overflow (r, type, new_lb, new_ub);
3997 : 886928 : }
3998 : :
3999 : : bool
4000 : 582051 : operator_bitwise_or::op1_range (irange &r, tree type,
4001 : : const irange &lhs,
4002 : : const irange &op2,
4003 : : relation_trio) const
4004 : : {
4005 : 582051 : if (lhs.undefined_p ())
4006 : : return false;
4007 : : // If this is really a logical wi_fold, call that.
4008 : 582051 : if (types_compatible_p (type, boolean_type_node))
4009 : 336802 : return op_logical_or.op1_range (r, type, lhs, op2);
4010 : :
4011 : 245249 : if (lhs.zero_p ())
4012 : : {
4013 : 77714 : r.set_zero (type);
4014 : 77714 : return true;
4015 : : }
4016 : :
4017 : : // if (A < 0 && B < 0)
4018 : : // Sometimes gets translated to
4019 : : // _1 = A | B
4020 : : // if (_1 < 0))
4021 : : // It is useful for ranger to recognize a positive LHS means the RHS
4022 : : // operands are also positive when dealing with the ELSE range..
4023 : 236489 : if (TYPE_SIGN (type) == SIGNED && wi::ge_p (lhs.lower_bound (), 0, SIGNED))
4024 : : {
4025 : 26938 : unsigned prec = TYPE_PRECISION (type);
4026 : 26938 : r.set (type, wi::zero (prec), wi::max_value (prec, SIGNED));
4027 : 26938 : return true;
4028 : : }
4029 : 140597 : r.set_varying (type);
4030 : 140597 : return true;
4031 : : }
4032 : :
4033 : : bool
4034 : 282047 : operator_bitwise_or::op2_range (irange &r, tree type,
4035 : : const irange &lhs,
4036 : : const irange &op1,
4037 : : relation_trio) const
4038 : : {
4039 : 282047 : return operator_bitwise_or::op1_range (r, type, lhs, op1);
4040 : : }
4041 : :
4042 : : void
4043 : 87274 : operator_bitwise_xor::update_bitmask (irange &r, const irange &lh,
4044 : : const irange &rh) const
4045 : : {
4046 : 87274 : update_known_bitmask (r, BIT_XOR_EXPR, lh, rh);
4047 : 87274 : }
4048 : :
4049 : : bool
4050 : 295760 : operator_bitwise_xor::fold_range (irange &r, tree type,
4051 : : const irange &lh, const irange &rh,
4052 : : relation_trio rel) const
4053 : : {
4054 : : // Handle X ^ UNDEFINED = UNDEFINED.
4055 : 295760 : if (lh.undefined_p () || rh.undefined_p ())
4056 : : {
4057 : 406 : r.set_undefined ();
4058 : 406 : return true;
4059 : : }
4060 : :
4061 : : // Next, handle X ^ X == [0, 0].
4062 : 295354 : if (rel.op1_op2 () == VREL_EQ)
4063 : : {
4064 : 40 : r.set_zero (type);
4065 : 40 : return true;
4066 : : }
4067 : :
4068 : : // If either operand is VARYING, the result is VARYING.
4069 : 295314 : if (lh.varying_p () || rh.varying_p ())
4070 : : {
4071 : : // If the operands are not equal, zero is not possible.
4072 : 205898 : if (rel.op1_op2 () != VREL_NE)
4073 : 204929 : r.set_varying (type);
4074 : : else
4075 : 969 : r.set_nonzero (type);
4076 : 205898 : return true;
4077 : : }
4078 : :
4079 : : // Now deal with X ^ 0 == X.
4080 : 89416 : if (lh.zero_p ())
4081 : : {
4082 : 1888 : r = rh;
4083 : 1888 : return true;
4084 : : }
4085 : 87528 : if (rh.zero_p ())
4086 : : {
4087 : 254 : r = lh;
4088 : 254 : return true;
4089 : : }
4090 : :
4091 : : // Start with the legacy range. This can sometimes pick up values
4092 : : // when there are a lot of subranges and fold_range aggregates them.
4093 : 87274 : bool res = range_operator::fold_range (r, type, lh, rh, rel);
4094 : :
4095 : : // Calculate the XOR identity : x ^ y = (x | y) & ~(x & y)
4096 : : // AND and OR are already much better optimized.
4097 : 87274 : int_range_max tmp1, tmp2, tmp3, new_result;
4098 : 87274 : int_range<2> varying;
4099 : 87274 : varying.set_varying (type);
4100 : :
4101 : 87274 : if (m_or.fold_range (tmp1, type, lh, rh, rel)
4102 : 87274 : && m_and.fold_range (tmp2, type, lh, rh, rel)
4103 : 87274 : && m_not.fold_range (tmp3, type, tmp2, varying, rel)
4104 : 174548 : && m_and.fold_range (new_result, type, tmp1, tmp3, rel))
4105 : : {
4106 : : // If the operands are not equal, or the LH does not contain any
4107 : : // element of the RH, zero is not possible.
4108 : 87274 : tmp1 = lh;
4109 : 87274 : if (rel.op1_op2 () == VREL_NE
4110 : 87274 : || (tmp1.intersect (rh) && tmp1.undefined_p ()))
4111 : : {
4112 : 14192 : tmp1.set_nonzero (type);
4113 : 14192 : new_result.intersect (tmp1);
4114 : : }
4115 : :
4116 : : // Combine with the legacy range if there was one.
4117 : 87274 : if (res)
4118 : 87274 : r.intersect (new_result);
4119 : : else
4120 : 0 : r = new_result;
4121 : 87274 : return true;
4122 : : }
4123 : : return res;
4124 : 87274 : }
4125 : :
4126 : : void
4127 : 178227 : operator_bitwise_xor::wi_fold (irange &r, tree type,
4128 : : const wide_int &lh_lb,
4129 : : const wide_int &lh_ub,
4130 : : const wide_int &rh_lb,
4131 : : const wide_int &rh_ub) const
4132 : : {
4133 : 178227 : signop sign = TYPE_SIGN (type);
4134 : 178227 : wide_int maybe_nonzero_lh, mustbe_nonzero_lh;
4135 : 178227 : wide_int maybe_nonzero_rh, mustbe_nonzero_rh;
4136 : 178227 : wi_set_zero_nonzero_bits (type, lh_lb, lh_ub,
4137 : : maybe_nonzero_lh, mustbe_nonzero_lh);
4138 : 178227 : wi_set_zero_nonzero_bits (type, rh_lb, rh_ub,
4139 : : maybe_nonzero_rh, mustbe_nonzero_rh);
4140 : :
4141 : 534681 : wide_int result_zero_bits = ((mustbe_nonzero_lh & mustbe_nonzero_rh)
4142 : 534681 : | ~(maybe_nonzero_lh | maybe_nonzero_rh));
4143 : 178227 : wide_int result_one_bits
4144 : 356454 : = (wi::bit_and_not (mustbe_nonzero_lh, maybe_nonzero_rh)
4145 : 356454 : | wi::bit_and_not (mustbe_nonzero_rh, maybe_nonzero_lh));
4146 : 178227 : wide_int new_ub = ~result_zero_bits;
4147 : 178227 : wide_int new_lb = result_one_bits;
4148 : :
4149 : : // If the range has all positive or all negative values, the result
4150 : : // is better than VARYING.
4151 : 178227 : if (wi::lt_p (new_lb, 0, sign) || wi::ge_p (new_ub, 0, sign))
4152 : 171160 : value_range_with_overflow (r, type, new_lb, new_ub);
4153 : 7067 : else if (sign == SIGNED
4154 : 7067 : && wi_optimize_signed_bitwise_op (r, type,
4155 : : lh_lb, lh_ub,
4156 : : rh_lb, rh_ub))
4157 : : ; /* Do nothing. */
4158 : : else
4159 : 860 : r.set_varying (type);
4160 : :
4161 : : /* Furthermore, XOR is non-zero if its arguments can't be equal. */
4162 : 178227 : if (wi::lt_p (lh_ub, rh_lb, sign)
4163 : 116178 : || wi::lt_p (rh_ub, lh_lb, sign)
4164 : 273200 : || wi::ne_p (result_one_bits, 0))
4165 : : {
4166 : 83254 : int_range<2> tmp;
4167 : 83254 : tmp.set_nonzero (type);
4168 : 83254 : r.intersect (tmp);
4169 : 83254 : }
4170 : 178227 : }
4171 : :
4172 : : bool
4173 : 87274 : operator_bitwise_xor::op1_op2_relation_effect (irange &lhs_range,
4174 : : tree type,
4175 : : const irange &,
4176 : : const irange &,
4177 : : relation_kind rel) const
4178 : : {
4179 : 87274 : if (rel == VREL_VARYING)
4180 : : return false;
4181 : :
4182 : 6256 : int_range<2> rel_range;
4183 : :
4184 : 6256 : switch (rel)
4185 : : {
4186 : 0 : case VREL_EQ:
4187 : 0 : rel_range.set_zero (type);
4188 : 0 : break;
4189 : 407 : case VREL_NE:
4190 : 407 : rel_range.set_nonzero (type);
4191 : 407 : break;
4192 : : default:
4193 : : return false;
4194 : : }
4195 : :
4196 : 407 : lhs_range.intersect (rel_range);
4197 : 407 : return true;
4198 : 6256 : }
4199 : :
4200 : : bool
4201 : 78366 : operator_bitwise_xor::op1_range (irange &r, tree type,
4202 : : const irange &lhs,
4203 : : const irange &op2,
4204 : : relation_trio) const
4205 : : {
4206 : 78366 : if (lhs.undefined_p () || lhs.varying_p ())
4207 : : {
4208 : 8043 : r = lhs;
4209 : 8043 : return true;
4210 : : }
4211 : 70323 : if (types_compatible_p (type, boolean_type_node))
4212 : : {
4213 : 2511 : switch (get_bool_state (r, lhs, type))
4214 : : {
4215 : 1162 : case BRS_TRUE:
4216 : 1162 : if (op2.varying_p ())
4217 : 1098 : r.set_varying (type);
4218 : 64 : else if (op2.zero_p ())
4219 : 48 : r = range_true (type);
4220 : : // See get_bool_state for the rationale
4221 : 16 : else if (op2.undefined_p () || contains_zero_p (op2))
4222 : 0 : r = range_true_and_false (type);
4223 : : else
4224 : 16 : r = range_false (type);
4225 : : break;
4226 : 1349 : case BRS_FALSE:
4227 : 1349 : r = op2;
4228 : 1349 : break;
4229 : : default:
4230 : : break;
4231 : : }
4232 : 2511 : return true;
4233 : : }
4234 : 67812 : r.set_varying (type);
4235 : 67812 : return true;
4236 : : }
4237 : :
4238 : : bool
4239 : 33402 : operator_bitwise_xor::op2_range (irange &r, tree type,
4240 : : const irange &lhs,
4241 : : const irange &op1,
4242 : : relation_trio) const
4243 : : {
4244 : 33402 : return operator_bitwise_xor::op1_range (r, type, lhs, op1);
4245 : : }
4246 : :
4247 : : class operator_trunc_mod : public range_operator
4248 : : {
4249 : : using range_operator::op1_range;
4250 : : using range_operator::op2_range;
4251 : : using range_operator::update_bitmask;
4252 : : public:
4253 : : virtual void wi_fold (irange &r, tree type,
4254 : : const wide_int &lh_lb,
4255 : : const wide_int &lh_ub,
4256 : : const wide_int &rh_lb,
4257 : : const wide_int &rh_ub) const;
4258 : : virtual bool op1_range (irange &r, tree type,
4259 : : const irange &lhs,
4260 : : const irange &op2,
4261 : : relation_trio) const;
4262 : : virtual bool op2_range (irange &r, tree type,
4263 : : const irange &lhs,
4264 : : const irange &op1,
4265 : : relation_trio) const;
4266 : 1063831 : void update_bitmask (irange &r, const irange &lh, const irange &rh) const
4267 : 1063831 : { update_known_bitmask (r, TRUNC_MOD_EXPR, lh, rh); }
4268 : : } op_trunc_mod;
4269 : :
4270 : : void
4271 : 1318207 : operator_trunc_mod::wi_fold (irange &r, tree type,
4272 : : const wide_int &lh_lb,
4273 : : const wide_int &lh_ub,
4274 : : const wide_int &rh_lb,
4275 : : const wide_int &rh_ub) const
4276 : : {
4277 : 1318207 : wide_int new_lb, new_ub, tmp;
4278 : 1318207 : signop sign = TYPE_SIGN (type);
4279 : 1318207 : unsigned prec = TYPE_PRECISION (type);
4280 : :
4281 : : // Mod 0 is undefined.
4282 : 1318207 : if (wi_zero_p (type, rh_lb, rh_ub))
4283 : : {
4284 : 8077 : r.set_undefined ();
4285 : 8077 : return;
4286 : : }
4287 : :
4288 : : // Check for constant and try to fold.
4289 : 1523934 : if (lh_lb == lh_ub && rh_lb == rh_ub)
4290 : : {
4291 : 22897 : wi::overflow_type ov = wi::OVF_NONE;
4292 : 22897 : tmp = wi::mod_trunc (lh_lb, rh_lb, sign, &ov);
4293 : 22897 : if (ov == wi::OVF_NONE)
4294 : : {
4295 : 22897 : r = int_range<2> (type, tmp, tmp);
4296 : 22897 : return;
4297 : : }
4298 : : }
4299 : :
4300 : : // ABS (A % B) < ABS (B) and either 0 <= A % B <= A or A <= A % B <= 0.
4301 : 1287233 : new_ub = rh_ub - 1;
4302 : 1287233 : if (sign == SIGNED)
4303 : : {
4304 : 544748 : tmp = -1 - rh_lb;
4305 : 544748 : new_ub = wi::smax (new_ub, tmp);
4306 : : }
4307 : :
4308 : 1287233 : if (sign == UNSIGNED)
4309 : 742485 : new_lb = wi::zero (prec);
4310 : : else
4311 : : {
4312 : 544748 : new_lb = -new_ub;
4313 : 544748 : tmp = lh_lb;
4314 : 544748 : if (wi::gts_p (tmp, 0))
4315 : 134124 : tmp = wi::zero (prec);
4316 : 544772 : new_lb = wi::smax (new_lb, tmp);
4317 : : }
4318 : 1287233 : tmp = lh_ub;
4319 : 1287233 : if (sign == SIGNED && wi::neg_p (tmp))
4320 : 26849 : tmp = wi::zero (prec);
4321 : 1287233 : new_ub = wi::min (new_ub, tmp, sign);
4322 : :
4323 : 1287233 : value_range_with_overflow (r, type, new_lb, new_ub);
4324 : 1318331 : }
4325 : :
4326 : : bool
4327 : 548986 : operator_trunc_mod::op1_range (irange &r, tree type,
4328 : : const irange &lhs,
4329 : : const irange &,
4330 : : relation_trio) const
4331 : : {
4332 : 548986 : if (lhs.undefined_p ())
4333 : : return false;
4334 : : // PR 91029.
4335 : 548986 : signop sign = TYPE_SIGN (type);
4336 : 548986 : unsigned prec = TYPE_PRECISION (type);
4337 : : // (a % b) >= x && x > 0 , then a >= x.
4338 : 549078 : if (wi::gt_p (lhs.lower_bound (), 0, sign))
4339 : : {
4340 : 133501 : r.set (type, lhs.lower_bound (), wi::max_value (prec, sign));
4341 : 133468 : return true;
4342 : : }
4343 : : // (a % b) <= x && x < 0 , then a <= x.
4344 : 415577 : if (wi::lt_p (lhs.upper_bound (), 0, sign))
4345 : : {
4346 : 5633 : r.set (type, wi::min_value (prec, sign), lhs.upper_bound ());
4347 : 5633 : return true;
4348 : : }
4349 : : return false;
4350 : : }
4351 : :
4352 : : bool
4353 : 354358 : operator_trunc_mod::op2_range (irange &r, tree type,
4354 : : const irange &lhs,
4355 : : const irange &,
4356 : : relation_trio) const
4357 : : {
4358 : 354358 : if (lhs.undefined_p ())
4359 : : return false;
4360 : : // PR 91029.
4361 : 354358 : signop sign = TYPE_SIGN (type);
4362 : 354358 : unsigned prec = TYPE_PRECISION (type);
4363 : : // (a % b) >= x && x > 0 , then b is in ~[-x, x] for signed
4364 : : // or b > x for unsigned.
4365 : 354391 : if (wi::gt_p (lhs.lower_bound (), 0, sign))
4366 : : {
4367 : 56084 : if (sign == SIGNED)
4368 : 2158 : r.set (type, wi::neg (lhs.lower_bound ()),
4369 : 4316 : lhs.lower_bound (), VR_ANTI_RANGE);
4370 : 53938 : else if (wi::lt_p (lhs.lower_bound (), wi::max_value (prec, sign),
4371 : : sign))
4372 : 53944 : r.set (type, lhs.lower_bound () + 1, wi::max_value (prec, sign));
4373 : : else
4374 : : return false;
4375 : 56084 : return true;
4376 : : }
4377 : : // (a % b) <= x && x < 0 , then b is in ~[x, -x].
4378 : 298301 : if (wi::lt_p (lhs.upper_bound (), 0, sign))
4379 : : {
4380 : 5282 : if (wi::gt_p (lhs.upper_bound (), wi::min_value (prec, sign), sign))
4381 : 5282 : r.set (type, lhs.upper_bound (),
4382 : 10564 : wi::neg (lhs.upper_bound ()), VR_ANTI_RANGE);
4383 : : else
4384 : : return false;
4385 : 5282 : return true;
4386 : : }
4387 : : return false;
4388 : : }
4389 : :
4390 : :
4391 : : class operator_logical_not : public range_operator
4392 : : {
4393 : : using range_operator::fold_range;
4394 : : using range_operator::op1_range;
4395 : : public:
4396 : : bool fold_range (irange &r, tree type,
4397 : : const irange &lh,
4398 : : const irange &rh,
4399 : : relation_trio rel = TRIO_VARYING) const final override;
4400 : : bool op1_range (irange &r, tree type,
4401 : : const irange &lhs,
4402 : : const irange &op2,
4403 : : relation_trio rel = TRIO_VARYING) const final override;
4404 : : // Check compatibility of LHS and op1.
4405 : 0 : bool operand_check_p (tree t1, tree t2, tree) const final override
4406 : 0 : { return range_compatible_p (t1, t2); }
4407 : : } op_logical_not;
4408 : :
4409 : : // Folding a logical NOT, oddly enough, involves doing nothing on the
4410 : : // forward pass through. During the initial walk backwards, the
4411 : : // logical NOT reversed the desired outcome on the way back, so on the
4412 : : // way forward all we do is pass the range forward.
4413 : : //
4414 : : // b_2 = x_1 < 20
4415 : : // b_3 = !b_2
4416 : : // if (b_3)
4417 : : // to determine the TRUE branch, walking backward
4418 : : // if (b_3) if ([1,1])
4419 : : // b_3 = !b_2 [1,1] = ![0,0]
4420 : : // b_2 = x_1 < 20 [0,0] = x_1 < 20, false, so x_1 == [20, 255]
4421 : : // which is the result we are looking for.. so.. pass it through.
4422 : :
4423 : : bool
4424 : 242635 : operator_logical_not::fold_range (irange &r, tree type,
4425 : : const irange &lh,
4426 : : const irange &rh ATTRIBUTE_UNUSED,
4427 : : relation_trio) const
4428 : : {
4429 : 242635 : if (empty_range_varying (r, type, lh, rh))
4430 : 0 : return true;
4431 : :
4432 : 242635 : r = lh;
4433 : 242635 : if (!lh.varying_p () && !lh.undefined_p ())
4434 : 50104 : r.invert ();
4435 : :
4436 : : return true;
4437 : : }
4438 : :
4439 : : bool
4440 : 26376 : operator_logical_not::op1_range (irange &r,
4441 : : tree type,
4442 : : const irange &lhs,
4443 : : const irange &op2,
4444 : : relation_trio) const
4445 : : {
4446 : : // Logical NOT is involutary...do it again.
4447 : 26376 : return fold_range (r, type, lhs, op2);
4448 : : }
4449 : :
4450 : : bool
4451 : 608559 : operator_bitwise_not::fold_range (irange &r, tree type,
4452 : : const irange &lh,
4453 : : const irange &rh,
4454 : : relation_trio) const
4455 : : {
4456 : 608559 : if (empty_range_varying (r, type, lh, rh))
4457 : 98 : return true;
4458 : :
4459 : 608461 : if (types_compatible_p (type, boolean_type_node))
4460 : 216259 : return op_logical_not.fold_range (r, type, lh, rh);
4461 : :
4462 : : // ~X is simply -1 - X.
4463 : 784404 : int_range<1> minusone (type, wi::minus_one (TYPE_PRECISION (type)),
4464 : 784404 : wi::minus_one (TYPE_PRECISION (type)));
4465 : 392202 : return range_op_handler (MINUS_EXPR).fold_range (r, type, minusone, lh);
4466 : 392202 : }
4467 : :
4468 : : bool
4469 : 51239 : operator_bitwise_not::op1_range (irange &r, tree type,
4470 : : const irange &lhs,
4471 : : const irange &op2,
4472 : : relation_trio) const
4473 : : {
4474 : 51239 : if (lhs.undefined_p ())
4475 : : return false;
4476 : 51239 : if (types_compatible_p (type, boolean_type_node))
4477 : 26376 : return op_logical_not.op1_range (r, type, lhs, op2);
4478 : :
4479 : : // ~X is -1 - X and since bitwise NOT is involutary...do it again.
4480 : 24863 : return fold_range (r, type, lhs, op2);
4481 : : }
4482 : :
4483 : : void
4484 : 0 : operator_bitwise_not::update_bitmask (irange &r, const irange &lh,
4485 : : const irange &rh) const
4486 : : {
4487 : 0 : update_known_bitmask (r, BIT_NOT_EXPR, lh, rh);
4488 : 0 : }
4489 : :
4490 : :
4491 : : bool
4492 : 306215 : operator_cst::fold_range (irange &r, tree type ATTRIBUTE_UNUSED,
4493 : : const irange &lh,
4494 : : const irange &rh ATTRIBUTE_UNUSED,
4495 : : relation_trio) const
4496 : : {
4497 : 306215 : r = lh;
4498 : 306215 : return true;
4499 : : }
4500 : :
4501 : :
4502 : : // Determine if there is a relationship between LHS and OP1.
4503 : :
4504 : : relation_kind
4505 : 934302 : operator_identity::lhs_op1_relation (const irange &lhs,
4506 : : const irange &op1 ATTRIBUTE_UNUSED,
4507 : : const irange &op2 ATTRIBUTE_UNUSED,
4508 : : relation_kind) const
4509 : : {
4510 : 934302 : if (lhs.undefined_p ())
4511 : 483 : return VREL_VARYING;
4512 : : // Simply a copy, so they are equivalent.
4513 : : return VREL_EQ;
4514 : : }
4515 : :
4516 : : bool
4517 : 934869 : operator_identity::fold_range (irange &r, tree type ATTRIBUTE_UNUSED,
4518 : : const irange &lh,
4519 : : const irange &rh ATTRIBUTE_UNUSED,
4520 : : relation_trio) const
4521 : : {
4522 : 934869 : r = lh;
4523 : 934869 : return true;
4524 : : }
4525 : :
4526 : : bool
4527 : 281515 : operator_identity::op1_range (irange &r, tree type ATTRIBUTE_UNUSED,
4528 : : const irange &lhs,
4529 : : const irange &op2 ATTRIBUTE_UNUSED,
4530 : : relation_trio) const
4531 : : {
4532 : 281515 : r = lhs;
4533 : 281515 : return true;
4534 : : }
4535 : :
4536 : :
4537 : : class operator_unknown : public range_operator
4538 : : {
4539 : : using range_operator::fold_range;
4540 : : public:
4541 : : virtual bool fold_range (irange &r, tree type,
4542 : : const irange &op1,
4543 : : const irange &op2,
4544 : : relation_trio rel = TRIO_VARYING) const;
4545 : : } op_unknown;
4546 : :
4547 : : bool
4548 : 821810 : operator_unknown::fold_range (irange &r, tree type,
4549 : : const irange &lh ATTRIBUTE_UNUSED,
4550 : : const irange &rh ATTRIBUTE_UNUSED,
4551 : : relation_trio) const
4552 : : {
4553 : 821810 : r.set_varying (type);
4554 : 821810 : return true;
4555 : : }
4556 : :
4557 : :
4558 : : void
4559 : 82513 : operator_abs::wi_fold (irange &r, tree type,
4560 : : const wide_int &lh_lb, const wide_int &lh_ub,
4561 : : const wide_int &rh_lb ATTRIBUTE_UNUSED,
4562 : : const wide_int &rh_ub ATTRIBUTE_UNUSED) const
4563 : : {
4564 : 82513 : wide_int min, max;
4565 : 82513 : signop sign = TYPE_SIGN (type);
4566 : 82513 : unsigned prec = TYPE_PRECISION (type);
4567 : :
4568 : : // Pass through LH for the easy cases.
4569 : 82513 : if (sign == UNSIGNED || wi::ge_p (lh_lb, 0, sign))
4570 : : {
4571 : 12266 : r = int_range<1> (type, lh_lb, lh_ub);
4572 : 12266 : return;
4573 : : }
4574 : :
4575 : : // -TYPE_MIN_VALUE = TYPE_MIN_VALUE with flag_wrapv so we can't get
4576 : : // a useful range.
4577 : 70247 : wide_int min_value = wi::min_value (prec, sign);
4578 : 70247 : wide_int max_value = wi::max_value (prec, sign);
4579 : 70247 : if (!TYPE_OVERFLOW_UNDEFINED (type) && wi::eq_p (lh_lb, min_value))
4580 : : {
4581 : 640 : r.set_varying (type);
4582 : 640 : return;
4583 : : }
4584 : :
4585 : : // ABS_EXPR may flip the range around, if the original range
4586 : : // included negative values.
4587 : 69607 : if (wi::eq_p (lh_lb, min_value))
4588 : : {
4589 : : // ABS ([-MIN, -MIN]) isn't representable, but we have traditionally
4590 : : // returned [-MIN,-MIN] so this preserves that behavior. PR37078
4591 : 36898 : if (wi::eq_p (lh_ub, min_value))
4592 : : {
4593 : 113 : r = int_range<1> (type, min_value, min_value);
4594 : 113 : return;
4595 : : }
4596 : 36785 : min = max_value;
4597 : : }
4598 : : else
4599 : 32709 : min = wi::abs (lh_lb);
4600 : :
4601 : 69494 : if (wi::eq_p (lh_ub, min_value))
4602 : 0 : max = max_value;
4603 : : else
4604 : 69494 : max = wi::abs (lh_ub);
4605 : :
4606 : : // If the range contains zero then we know that the minimum value in the
4607 : : // range will be zero.
4608 : 69494 : if (wi::le_p (lh_lb, 0, sign) && wi::ge_p (lh_ub, 0, sign))
4609 : : {
4610 : 59549 : if (wi::gt_p (min, max, sign))
4611 : 21474 : max = min;
4612 : 59549 : min = wi::zero (prec);
4613 : : }
4614 : : else
4615 : : {
4616 : : // If the range was reversed, swap MIN and MAX.
4617 : 9945 : if (wi::gt_p (min, max, sign))
4618 : 9347 : std::swap (min, max);
4619 : : }
4620 : :
4621 : : // If the new range has its limits swapped around (MIN > MAX), then
4622 : : // the operation caused one of them to wrap around. The only thing
4623 : : // we know is that the result is positive.
4624 : 69494 : if (wi::gt_p (min, max, sign))
4625 : : {
4626 : 0 : min = wi::zero (prec);
4627 : 0 : max = max_value;
4628 : : }
4629 : 69494 : r = int_range<1> (type, min, max);
4630 : 83266 : }
4631 : :
4632 : : bool
4633 : 59167 : operator_abs::op1_range (irange &r, tree type,
4634 : : const irange &lhs,
4635 : : const irange &op2,
4636 : : relation_trio) const
4637 : : {
4638 : 59167 : if (empty_range_varying (r, type, lhs, op2))
4639 : 0 : return true;
4640 : 59167 : if (TYPE_UNSIGNED (type))
4641 : : {
4642 : 0 : r = lhs;
4643 : 0 : return true;
4644 : : }
4645 : : // Start with the positives because negatives are an impossible result.
4646 : 59167 : int_range_max positives = range_positives (type);
4647 : 59167 : positives.intersect (lhs);
4648 : 59167 : r = positives;
4649 : : // Then add the negative of each pair:
4650 : : // ABS(op1) = [5,20] would yield op1 => [-20,-5][5,20].
4651 : 119121 : for (unsigned i = 0; i < positives.num_pairs (); ++i)
4652 : 59954 : r.union_ (int_range<1> (type,
4653 : 119908 : -positives.upper_bound (i),
4654 : 179862 : -positives.lower_bound (i)));
4655 : : // With flag_wrapv, -TYPE_MIN_VALUE = TYPE_MIN_VALUE which is
4656 : : // unrepresentable. Add -TYPE_MIN_VALUE in this case.
4657 : 59167 : wide_int min_value = wi::min_value (TYPE_PRECISION (type), TYPE_SIGN (type));
4658 : 59167 : wide_int lb = lhs.lower_bound ();
4659 : 59167 : if (!TYPE_OVERFLOW_UNDEFINED (type) && wi::eq_p (lb, min_value))
4660 : 168 : r.union_ (int_range<2> (type, lb, lb));
4661 : 59167 : return true;
4662 : 59167 : }
4663 : :
4664 : : void
4665 : 75202 : operator_abs::update_bitmask (irange &r, const irange &lh,
4666 : : const irange &rh) const
4667 : : {
4668 : 75202 : update_known_bitmask (r, ABS_EXPR, lh, rh);
4669 : 75202 : }
4670 : :
4671 : : class operator_absu : public range_operator
4672 : : {
4673 : : using range_operator::update_bitmask;
4674 : : public:
4675 : : virtual void wi_fold (irange &r, tree type,
4676 : : const wide_int &lh_lb, const wide_int &lh_ub,
4677 : : const wide_int &rh_lb, const wide_int &rh_ub)
4678 : : const final override;
4679 : : virtual void update_bitmask (irange &r, const irange &lh,
4680 : : const irange &rh) const final override;
4681 : : } op_absu;
4682 : :
4683 : : void
4684 : 17323 : operator_absu::wi_fold (irange &r, tree type,
4685 : : const wide_int &lh_lb, const wide_int &lh_ub,
4686 : : const wide_int &rh_lb ATTRIBUTE_UNUSED,
4687 : : const wide_int &rh_ub ATTRIBUTE_UNUSED) const
4688 : : {
4689 : 17323 : wide_int new_lb, new_ub;
4690 : :
4691 : : // Pass through VR0 the easy cases.
4692 : 17323 : if (wi::ges_p (lh_lb, 0))
4693 : : {
4694 : 2479 : new_lb = lh_lb;
4695 : 2479 : new_ub = lh_ub;
4696 : : }
4697 : : else
4698 : : {
4699 : 14844 : new_lb = wi::abs (lh_lb);
4700 : 14844 : new_ub = wi::abs (lh_ub);
4701 : :
4702 : : // If the range contains zero then we know that the minimum
4703 : : // value in the range will be zero.
4704 : 14844 : if (wi::ges_p (lh_ub, 0))
4705 : : {
4706 : 11622 : if (wi::gtu_p (new_lb, new_ub))
4707 : 10328 : new_ub = new_lb;
4708 : 11622 : new_lb = wi::zero (TYPE_PRECISION (type));
4709 : : }
4710 : : else
4711 : 3222 : std::swap (new_lb, new_ub);
4712 : : }
4713 : :
4714 : 17323 : gcc_checking_assert (TYPE_UNSIGNED (type));
4715 : 17323 : r = int_range<1> (type, new_lb, new_ub);
4716 : 17323 : }
4717 : :
4718 : : void
4719 : 15959 : operator_absu::update_bitmask (irange &r, const irange &lh,
4720 : : const irange &rh) const
4721 : : {
4722 : 15959 : update_known_bitmask (r, ABSU_EXPR, lh, rh);
4723 : 15959 : }
4724 : :
4725 : :
4726 : : bool
4727 : 602433 : operator_negate::fold_range (irange &r, tree type,
4728 : : const irange &lh,
4729 : : const irange &rh,
4730 : : relation_trio) const
4731 : : {
4732 : 602433 : if (empty_range_varying (r, type, lh, rh))
4733 : 968 : return true;
4734 : :
4735 : : // -X is simply 0 - X.
4736 : 601465 : int_range<1> zero;
4737 : 601465 : zero.set_zero (type);
4738 : 601465 : return range_op_handler (MINUS_EXPR).fold_range (r, type, zero, lh);
4739 : 601465 : }
4740 : :
4741 : : bool
4742 : 75347 : operator_negate::op1_range (irange &r, tree type,
4743 : : const irange &lhs,
4744 : : const irange &op2,
4745 : : relation_trio) const
4746 : : {
4747 : : // NEGATE is involutory.
4748 : 75347 : return fold_range (r, type, lhs, op2);
4749 : : }
4750 : :
4751 : :
4752 : : bool
4753 : 0 : operator_addr_expr::fold_range (irange &r, tree type,
4754 : : const irange &lh,
4755 : : const irange &rh,
4756 : : relation_trio) const
4757 : : {
4758 : 0 : if (empty_range_varying (r, type, lh, rh))
4759 : 0 : return true;
4760 : :
4761 : : // Return a non-null pointer of the LHS type (passed in op2).
4762 : 0 : if (lh.zero_p ())
4763 : 0 : r.set_zero (type);
4764 : 0 : else if (lh.undefined_p () || contains_zero_p (lh))
4765 : 0 : r.set_varying (type);
4766 : : else
4767 : 0 : r.set_nonzero (type);
4768 : : return true;
4769 : : }
4770 : :
4771 : : bool
4772 : 0 : operator_addr_expr::op1_range (irange &r, tree type,
4773 : : const irange &lhs,
4774 : : const irange &op2,
4775 : : relation_trio) const
4776 : : {
4777 : 0 : if (empty_range_varying (r, type, lhs, op2))
4778 : 0 : return true;
4779 : :
4780 : : // Return a non-null pointer of the LHS type (passed in op2), but only
4781 : : // if we cant overflow, eitherwise a no-zero offset could wrap to zero.
4782 : : // See PR 111009.
4783 : 0 : if (!lhs.undefined_p () && !contains_zero_p (lhs) && TYPE_OVERFLOW_UNDEFINED (type))
4784 : 0 : r.set_nonzero (type);
4785 : : else
4786 : 0 : r.set_varying (type);
4787 : : return true;
4788 : : }
4789 : :
4790 : : // Initialize any integral operators to the primary table
4791 : :
4792 : : void
4793 : 288171 : range_op_table::initialize_integral_ops ()
4794 : : {
4795 : 288171 : set (TRUNC_DIV_EXPR, op_trunc_div);
4796 : 288171 : set (FLOOR_DIV_EXPR, op_floor_div);
4797 : 288171 : set (ROUND_DIV_EXPR, op_round_div);
4798 : 288171 : set (CEIL_DIV_EXPR, op_ceil_div);
4799 : 288171 : set (EXACT_DIV_EXPR, op_exact_div);
4800 : 288171 : set (LSHIFT_EXPR, op_lshift);
4801 : 288171 : set (RSHIFT_EXPR, op_rshift);
4802 : 288171 : set (TRUTH_AND_EXPR, op_logical_and);
4803 : 288171 : set (TRUTH_OR_EXPR, op_logical_or);
4804 : 288171 : set (TRUNC_MOD_EXPR, op_trunc_mod);
4805 : 288171 : set (TRUTH_NOT_EXPR, op_logical_not);
4806 : 288171 : set (IMAGPART_EXPR, op_unknown);
4807 : 288171 : set (REALPART_EXPR, op_unknown);
4808 : 288171 : set (ABSU_EXPR, op_absu);
4809 : 288171 : set (OP_WIDEN_MULT_SIGNED, op_widen_mult_signed);
4810 : 288171 : set (OP_WIDEN_MULT_UNSIGNED, op_widen_mult_unsigned);
4811 : 288171 : set (OP_WIDEN_PLUS_SIGNED, op_widen_plus_signed);
4812 : 288171 : set (OP_WIDEN_PLUS_UNSIGNED, op_widen_plus_unsigned);
4813 : :
4814 : 288171 : }
4815 : :
4816 : : bool
4817 : 42122 : operator_plus::overflow_free_p (const irange &lh, const irange &rh,
4818 : : relation_trio) const
4819 : : {
4820 : 42122 : if (lh.undefined_p () || rh.undefined_p ())
4821 : : return false;
4822 : :
4823 : 42118 : tree type = lh.type ();
4824 : 42118 : if (TYPE_OVERFLOW_UNDEFINED (type))
4825 : : return true;
4826 : :
4827 : 10714 : wi::overflow_type ovf;
4828 : 10714 : signop sgn = TYPE_SIGN (type);
4829 : 10714 : wide_int wmax0 = lh.upper_bound ();
4830 : 10714 : wide_int wmax1 = rh.upper_bound ();
4831 : 10714 : wi::add (wmax0, wmax1, sgn, &ovf);
4832 : 10714 : if (ovf != wi::OVF_NONE)
4833 : : return false;
4834 : :
4835 : 1319 : if (TYPE_UNSIGNED (type))
4836 : : return true;
4837 : :
4838 : 372 : wide_int wmin0 = lh.lower_bound ();
4839 : 372 : wide_int wmin1 = rh.lower_bound ();
4840 : 372 : wi::add (wmin0, wmin1, sgn, &ovf);
4841 : 372 : if (ovf != wi::OVF_NONE)
4842 : 261 : return false;
4843 : :
4844 : : return true;
4845 : 11086 : }
4846 : :
4847 : : bool
4848 : 31 : operator_minus::overflow_free_p (const irange &lh, const irange &rh,
4849 : : relation_trio) const
4850 : : {
4851 : 31 : if (lh.undefined_p () || rh.undefined_p ())
4852 : : return false;
4853 : :
4854 : 31 : tree type = lh.type ();
4855 : 31 : if (TYPE_OVERFLOW_UNDEFINED (type))
4856 : : return true;
4857 : :
4858 : 10 : wi::overflow_type ovf;
4859 : 10 : signop sgn = TYPE_SIGN (type);
4860 : 10 : wide_int wmin0 = lh.lower_bound ();
4861 : 10 : wide_int wmax1 = rh.upper_bound ();
4862 : 10 : wi::sub (wmin0, wmax1, sgn, &ovf);
4863 : 10 : if (ovf != wi::OVF_NONE)
4864 : : return false;
4865 : :
4866 : 7 : if (TYPE_UNSIGNED (type))
4867 : : return true;
4868 : :
4869 : 6 : wide_int wmax0 = lh.upper_bound ();
4870 : 6 : wide_int wmin1 = rh.lower_bound ();
4871 : 6 : wi::sub (wmax0, wmin1, sgn, &ovf);
4872 : 6 : if (ovf != wi::OVF_NONE)
4873 : 0 : return false;
4874 : :
4875 : : return true;
4876 : 16 : }
4877 : :
4878 : : bool
4879 : 3321 : operator_mult::overflow_free_p (const irange &lh, const irange &rh,
4880 : : relation_trio) const
4881 : : {
4882 : 3321 : if (lh.undefined_p () || rh.undefined_p ())
4883 : : return false;
4884 : :
4885 : 3321 : tree type = lh.type ();
4886 : 3321 : if (TYPE_OVERFLOW_UNDEFINED (type))
4887 : : return true;
4888 : :
4889 : 2778 : wi::overflow_type ovf;
4890 : 2778 : signop sgn = TYPE_SIGN (type);
4891 : 2778 : wide_int wmax0 = lh.upper_bound ();
4892 : 2778 : wide_int wmax1 = rh.upper_bound ();
4893 : 2778 : wi::mul (wmax0, wmax1, sgn, &ovf);
4894 : 2778 : if (ovf != wi::OVF_NONE)
4895 : : return false;
4896 : :
4897 : 105 : if (TYPE_UNSIGNED (type))
4898 : : return true;
4899 : :
4900 : 22 : wide_int wmin0 = lh.lower_bound ();
4901 : 22 : wide_int wmin1 = rh.lower_bound ();
4902 : 22 : wi::mul (wmin0, wmin1, sgn, &ovf);
4903 : 22 : if (ovf != wi::OVF_NONE)
4904 : : return false;
4905 : :
4906 : 22 : wi::mul (wmin0, wmax1, sgn, &ovf);
4907 : 22 : if (ovf != wi::OVF_NONE)
4908 : : return false;
4909 : :
4910 : 22 : wi::mul (wmax0, wmin1, sgn, &ovf);
4911 : 22 : if (ovf != wi::OVF_NONE)
4912 : : return false;
4913 : :
4914 : : return true;
4915 : 2800 : }
4916 : :
4917 : : #if CHECKING_P
4918 : : #include "selftest.h"
4919 : :
4920 : : namespace selftest
4921 : : {
4922 : : #define INT(x) wi::shwi ((x), TYPE_PRECISION (integer_type_node))
4923 : : #define UINT(x) wi::uhwi ((x), TYPE_PRECISION (unsigned_type_node))
4924 : : #define INT16(x) wi::shwi ((x), TYPE_PRECISION (short_integer_type_node))
4925 : : #define UINT16(x) wi::uhwi ((x), TYPE_PRECISION (short_unsigned_type_node))
4926 : : #define SCHAR(x) wi::shwi ((x), TYPE_PRECISION (signed_char_type_node))
4927 : : #define UCHAR(x) wi::uhwi ((x), TYPE_PRECISION (unsigned_char_type_node))
4928 : :
4929 : : static void
4930 : 4 : range_op_cast_tests ()
4931 : : {
4932 : 4 : int_range<2> r0, r1, r2, rold;
4933 : 4 : r0.set_varying (integer_type_node);
4934 : 4 : wide_int maxint = r0.upper_bound ();
4935 : :
4936 : : // If a range is in any way outside of the range for the converted
4937 : : // to range, default to the range for the new type.
4938 : 4 : r0.set_varying (short_integer_type_node);
4939 : 4 : wide_int minshort = r0.lower_bound ();
4940 : 4 : wide_int maxshort = r0.upper_bound ();
4941 : 4 : if (TYPE_PRECISION (integer_type_node)
4942 : 4 : > TYPE_PRECISION (short_integer_type_node))
4943 : : {
4944 : 8 : r1 = int_range<1> (integer_type_node,
4945 : 4 : wi::zero (TYPE_PRECISION (integer_type_node)),
4946 : 8 : maxint);
4947 : 4 : range_cast (r1, short_integer_type_node);
4948 : 4 : ASSERT_TRUE (r1.lower_bound () == minshort
4949 : : && r1.upper_bound() == maxshort);
4950 : : }
4951 : :
4952 : : // (unsigned char)[-5,-1] => [251,255].
4953 : 4 : r0 = rold = int_range<1> (signed_char_type_node, SCHAR (-5), SCHAR (-1));
4954 : 4 : range_cast (r0, unsigned_char_type_node);
4955 : 4 : ASSERT_TRUE (r0 == int_range<1> (unsigned_char_type_node,
4956 : : UCHAR (251), UCHAR (255)));
4957 : 4 : range_cast (r0, signed_char_type_node);
4958 : 4 : ASSERT_TRUE (r0 == rold);
4959 : :
4960 : : // (signed char)[15, 150] => [-128,-106][15,127].
4961 : 4 : r0 = rold = int_range<1> (unsigned_char_type_node, UCHAR (15), UCHAR (150));
4962 : 4 : range_cast (r0, signed_char_type_node);
4963 : 4 : r1 = int_range<1> (signed_char_type_node, SCHAR (15), SCHAR (127));
4964 : 4 : r2 = int_range<1> (signed_char_type_node, SCHAR (-128), SCHAR (-106));
4965 : 4 : r1.union_ (r2);
4966 : 4 : ASSERT_TRUE (r1 == r0);
4967 : 4 : range_cast (r0, unsigned_char_type_node);
4968 : 4 : ASSERT_TRUE (r0 == rold);
4969 : :
4970 : : // (unsigned char)[-5, 5] => [0,5][251,255].
4971 : 4 : r0 = rold = int_range<1> (signed_char_type_node, SCHAR (-5), SCHAR (5));
4972 : 4 : range_cast (r0, unsigned_char_type_node);
4973 : 4 : r1 = int_range<1> (unsigned_char_type_node, UCHAR (251), UCHAR (255));
4974 : 4 : r2 = int_range<1> (unsigned_char_type_node, UCHAR (0), UCHAR (5));
4975 : 4 : r1.union_ (r2);
4976 : 4 : ASSERT_TRUE (r0 == r1);
4977 : 4 : range_cast (r0, signed_char_type_node);
4978 : 4 : ASSERT_TRUE (r0 == rold);
4979 : :
4980 : : // (unsigned char)[-5,5] => [0,5][251,255].
4981 : 4 : r0 = int_range<1> (integer_type_node, INT (-5), INT (5));
4982 : 4 : range_cast (r0, unsigned_char_type_node);
4983 : 4 : r1 = int_range<1> (unsigned_char_type_node, UCHAR (0), UCHAR (5));
4984 : 4 : r1.union_ (int_range<1> (unsigned_char_type_node, UCHAR (251), UCHAR (255)));
4985 : 4 : ASSERT_TRUE (r0 == r1);
4986 : :
4987 : : // (unsigned char)[5U,1974U] => [0,255].
4988 : 4 : r0 = int_range<1> (unsigned_type_node, UINT (5), UINT (1974));
4989 : 4 : range_cast (r0, unsigned_char_type_node);
4990 : 4 : ASSERT_TRUE (r0 == int_range<1> (unsigned_char_type_node, UCHAR (0), UCHAR (255)));
4991 : 4 : range_cast (r0, integer_type_node);
4992 : : // Going to a wider range should not sign extend.
4993 : 4 : ASSERT_TRUE (r0 == int_range<1> (integer_type_node, INT (0), INT (255)));
4994 : :
4995 : : // (unsigned char)[-350,15] => [0,255].
4996 : 4 : r0 = int_range<1> (integer_type_node, INT (-350), INT (15));
4997 : 4 : range_cast (r0, unsigned_char_type_node);
4998 : 4 : ASSERT_TRUE (r0 == (int_range<1>
4999 : : (unsigned_char_type_node,
5000 : : min_limit (unsigned_char_type_node),
5001 : : max_limit (unsigned_char_type_node))));
5002 : :
5003 : : // Casting [-120,20] from signed char to unsigned short.
5004 : : // => [0, 20][0xff88, 0xffff].
5005 : 4 : r0 = int_range<1> (signed_char_type_node, SCHAR (-120), SCHAR (20));
5006 : 4 : range_cast (r0, short_unsigned_type_node);
5007 : 4 : r1 = int_range<1> (short_unsigned_type_node, UINT16 (0), UINT16 (20));
5008 : 8 : r2 = int_range<1> (short_unsigned_type_node,
5009 : 12 : UINT16 (0xff88), UINT16 (0xffff));
5010 : 4 : r1.union_ (r2);
5011 : 4 : ASSERT_TRUE (r0 == r1);
5012 : : // A truncating cast back to signed char will work because [-120, 20]
5013 : : // is representable in signed char.
5014 : 4 : range_cast (r0, signed_char_type_node);
5015 : 4 : ASSERT_TRUE (r0 == int_range<1> (signed_char_type_node,
5016 : : SCHAR (-120), SCHAR (20)));
5017 : :
5018 : : // unsigned char -> signed short
5019 : : // (signed short)[(unsigned char)25, (unsigned char)250]
5020 : : // => [(signed short)25, (signed short)250]
5021 : 4 : r0 = rold = int_range<1> (unsigned_char_type_node, UCHAR (25), UCHAR (250));
5022 : 4 : range_cast (r0, short_integer_type_node);
5023 : 4 : r1 = int_range<1> (short_integer_type_node, INT16 (25), INT16 (250));
5024 : 4 : ASSERT_TRUE (r0 == r1);
5025 : 4 : range_cast (r0, unsigned_char_type_node);
5026 : 4 : ASSERT_TRUE (r0 == rold);
5027 : :
5028 : : // Test casting a wider signed [-MIN,MAX] to a narrower unsigned.
5029 : 8 : r0 = int_range<1> (long_long_integer_type_node,
5030 : 4 : min_limit (long_long_integer_type_node),
5031 : 8 : max_limit (long_long_integer_type_node));
5032 : 4 : range_cast (r0, short_unsigned_type_node);
5033 : 8 : r1 = int_range<1> (short_unsigned_type_node,
5034 : 4 : min_limit (short_unsigned_type_node),
5035 : 8 : max_limit (short_unsigned_type_node));
5036 : 4 : ASSERT_TRUE (r0 == r1);
5037 : :
5038 : : // Casting NONZERO to a narrower type will wrap/overflow so
5039 : : // it's just the entire range for the narrower type.
5040 : : //
5041 : : // "NOT 0 at signed 32-bits" ==> [-MIN_32,-1][1, +MAX_32]. This is
5042 : : // is outside of the range of a smaller range, return the full
5043 : : // smaller range.
5044 : 4 : if (TYPE_PRECISION (integer_type_node)
5045 : 4 : > TYPE_PRECISION (short_integer_type_node))
5046 : : {
5047 : 4 : r0.set_nonzero (integer_type_node);
5048 : 4 : range_cast (r0, short_integer_type_node);
5049 : 8 : r1 = int_range<1> (short_integer_type_node,
5050 : 4 : min_limit (short_integer_type_node),
5051 : 8 : max_limit (short_integer_type_node));
5052 : 4 : ASSERT_TRUE (r0 == r1);
5053 : : }
5054 : :
5055 : : // Casting NONZERO from a narrower signed to a wider signed.
5056 : : //
5057 : : // NONZERO signed 16-bits is [-MIN_16,-1][1, +MAX_16].
5058 : : // Converting this to 32-bits signed is [-MIN_16,-1][1, +MAX_16].
5059 : 4 : r0.set_nonzero (short_integer_type_node);
5060 : 4 : range_cast (r0, integer_type_node);
5061 : 4 : r1 = int_range<1> (integer_type_node, INT (-32768), INT (-1));
5062 : 4 : r2 = int_range<1> (integer_type_node, INT (1), INT (32767));
5063 : 4 : r1.union_ (r2);
5064 : 4 : ASSERT_TRUE (r0 == r1);
5065 : 4 : }
5066 : :
5067 : : static void
5068 : 4 : range_op_lshift_tests ()
5069 : : {
5070 : : // Test that 0x808.... & 0x8.... still contains 0x8....
5071 : : // for a large set of numbers.
5072 : 4 : {
5073 : 4 : int_range_max res;
5074 : 4 : tree big_type = long_long_unsigned_type_node;
5075 : 4 : unsigned big_prec = TYPE_PRECISION (big_type);
5076 : : // big_num = 0x808,0000,0000,0000
5077 : 4 : wide_int big_num = wi::lshift (wi::uhwi (0x808, big_prec),
5078 : 8 : wi::uhwi (48, big_prec));
5079 : 8 : op_bitwise_and.fold_range (res, big_type,
5080 : 8 : int_range <1> (big_type),
5081 : 8 : int_range <1> (big_type, big_num, big_num));
5082 : : // val = 0x8,0000,0000,0000
5083 : 4 : wide_int val = wi::lshift (wi::uhwi (8, big_prec),
5084 : 8 : wi::uhwi (48, big_prec));
5085 : 4 : ASSERT_TRUE (res.contains_p (val));
5086 : 4 : }
5087 : :
5088 : 4 : if (TYPE_PRECISION (unsigned_type_node) > 31)
5089 : : {
5090 : : // unsigned VARYING = op1 << 1 should be VARYING.
5091 : 4 : int_range<2> lhs (unsigned_type_node);
5092 : 4 : int_range<2> shift (unsigned_type_node, INT (1), INT (1));
5093 : 4 : int_range_max op1;
5094 : 4 : op_lshift.op1_range (op1, unsigned_type_node, lhs, shift);
5095 : 4 : ASSERT_TRUE (op1.varying_p ());
5096 : :
5097 : : // 0 = op1 << 1 should be [0,0], [0x8000000, 0x8000000].
5098 : 4 : int_range<2> zero (unsigned_type_node, UINT (0), UINT (0));
5099 : 4 : op_lshift.op1_range (op1, unsigned_type_node, zero, shift);
5100 : 4 : ASSERT_TRUE (op1.num_pairs () == 2);
5101 : : // Remove the [0,0] range.
5102 : 4 : op1.intersect (zero);
5103 : 4 : ASSERT_TRUE (op1.num_pairs () == 1);
5104 : : // op1 << 1 should be [0x8000,0x8000] << 1,
5105 : : // which should result in [0,0].
5106 : 4 : int_range_max result;
5107 : 4 : op_lshift.fold_range (result, unsigned_type_node, op1, shift);
5108 : 4 : ASSERT_TRUE (result == zero);
5109 : 4 : }
5110 : : // signed VARYING = op1 << 1 should be VARYING.
5111 : 4 : if (TYPE_PRECISION (integer_type_node) > 31)
5112 : : {
5113 : : // unsigned VARYING = op1 << 1 should be VARYING.
5114 : 4 : int_range<2> lhs (integer_type_node);
5115 : 4 : int_range<2> shift (integer_type_node, INT (1), INT (1));
5116 : 4 : int_range_max op1;
5117 : 4 : op_lshift.op1_range (op1, integer_type_node, lhs, shift);
5118 : 4 : ASSERT_TRUE (op1.varying_p ());
5119 : :
5120 : : // 0 = op1 << 1 should be [0,0], [0x8000000, 0x8000000].
5121 : 4 : int_range<2> zero (integer_type_node, INT (0), INT (0));
5122 : 4 : op_lshift.op1_range (op1, integer_type_node, zero, shift);
5123 : 4 : ASSERT_TRUE (op1.num_pairs () == 2);
5124 : : // Remove the [0,0] range.
5125 : 4 : op1.intersect (zero);
5126 : 4 : ASSERT_TRUE (op1.num_pairs () == 1);
5127 : : // op1 << 1 should be [0x8000,0x8000] << 1,
5128 : : // which should result in [0,0].
5129 : 4 : int_range_max result;
5130 : 4 : op_lshift.fold_range (result, unsigned_type_node, op1, shift);
5131 : 4 : ASSERT_TRUE (result == zero);
5132 : 4 : }
5133 : 4 : }
5134 : :
5135 : : static void
5136 : 4 : range_op_rshift_tests ()
5137 : : {
5138 : : // unsigned: [3, MAX] = OP1 >> 1
5139 : 4 : {
5140 : 4 : int_range_max lhs (unsigned_type_node,
5141 : 4 : UINT (3), max_limit (unsigned_type_node));
5142 : 4 : int_range_max one (unsigned_type_node,
5143 : 8 : wi::one (TYPE_PRECISION (unsigned_type_node)),
5144 : 8 : wi::one (TYPE_PRECISION (unsigned_type_node)));
5145 : 4 : int_range_max op1;
5146 : 4 : op_rshift.op1_range (op1, unsigned_type_node, lhs, one);
5147 : 4 : ASSERT_FALSE (op1.contains_p (UINT (3)));
5148 : 4 : }
5149 : :
5150 : : // signed: [3, MAX] = OP1 >> 1
5151 : 4 : {
5152 : 4 : int_range_max lhs (integer_type_node,
5153 : 4 : INT (3), max_limit (integer_type_node));
5154 : 4 : int_range_max one (integer_type_node, INT (1), INT (1));
5155 : 4 : int_range_max op1;
5156 : 4 : op_rshift.op1_range (op1, integer_type_node, lhs, one);
5157 : 4 : ASSERT_FALSE (op1.contains_p (INT (-2)));
5158 : 4 : }
5159 : :
5160 : : // This is impossible, so OP1 should be [].
5161 : : // signed: [MIN, MIN] = OP1 >> 1
5162 : 4 : {
5163 : 4 : int_range_max lhs (integer_type_node,
5164 : 4 : min_limit (integer_type_node),
5165 : 4 : min_limit (integer_type_node));
5166 : 4 : int_range_max one (integer_type_node, INT (1), INT (1));
5167 : 4 : int_range_max op1;
5168 : 4 : op_rshift.op1_range (op1, integer_type_node, lhs, one);
5169 : 4 : ASSERT_TRUE (op1.undefined_p ());
5170 : 4 : }
5171 : :
5172 : : // signed: ~[-1] = OP1 >> 31
5173 : 4 : if (TYPE_PRECISION (integer_type_node) > 31)
5174 : : {
5175 : 4 : int_range_max lhs (integer_type_node, INT (-1), INT (-1), VR_ANTI_RANGE);
5176 : 4 : int_range_max shift (integer_type_node, INT (31), INT (31));
5177 : 4 : int_range_max op1;
5178 : 4 : op_rshift.op1_range (op1, integer_type_node, lhs, shift);
5179 : 4 : int_range_max negatives = range_negatives (integer_type_node);
5180 : 4 : negatives.intersect (op1);
5181 : 4 : ASSERT_TRUE (negatives.undefined_p ());
5182 : 4 : }
5183 : 4 : }
5184 : :
5185 : : static void
5186 : 4 : range_op_bitwise_and_tests ()
5187 : : {
5188 : 4 : int_range_max res;
5189 : 4 : wide_int min = min_limit (integer_type_node);
5190 : 4 : wide_int max = max_limit (integer_type_node);
5191 : 4 : wide_int tiny = wi::add (min, wi::one (TYPE_PRECISION (integer_type_node)));
5192 : 4 : int_range_max i1 (integer_type_node, tiny, max);
5193 : 4 : int_range_max i2 (integer_type_node, INT (255), INT (255));
5194 : :
5195 : : // [MIN+1, MAX] = OP1 & 255: OP1 is VARYING
5196 : 4 : op_bitwise_and.op1_range (res, integer_type_node, i1, i2);
5197 : 4 : ASSERT_TRUE (res == int_range<1> (integer_type_node));
5198 : :
5199 : : // VARYING = OP1 & 255: OP1 is VARYING
5200 : 4 : i1 = int_range<1> (integer_type_node);
5201 : 4 : op_bitwise_and.op1_range (res, integer_type_node, i1, i2);
5202 : 4 : ASSERT_TRUE (res == int_range<1> (integer_type_node));
5203 : :
5204 : : // For 0 = x & MASK, x is ~MASK.
5205 : 4 : {
5206 : 4 : int_range<2> zero (integer_type_node, INT (0), INT (0));
5207 : 4 : int_range<2> mask = int_range<2> (integer_type_node, INT (7), INT (7));
5208 : 4 : op_bitwise_and.op1_range (res, integer_type_node, zero, mask);
5209 : 4 : wide_int inv = wi::shwi (~7U, TYPE_PRECISION (integer_type_node));
5210 : 4 : ASSERT_TRUE (res.get_nonzero_bits () == inv);
5211 : 4 : }
5212 : :
5213 : : // (NONZERO | X) is nonzero.
5214 : 4 : i1.set_nonzero (integer_type_node);
5215 : 4 : i2.set_varying (integer_type_node);
5216 : 4 : op_bitwise_or.fold_range (res, integer_type_node, i1, i2);
5217 : 4 : ASSERT_TRUE (res.nonzero_p ());
5218 : :
5219 : : // (NEGATIVE | X) is nonzero.
5220 : 4 : i1 = int_range<1> (integer_type_node, INT (-5), INT (-3));
5221 : 4 : i2.set_varying (integer_type_node);
5222 : 4 : op_bitwise_or.fold_range (res, integer_type_node, i1, i2);
5223 : 4 : ASSERT_FALSE (res.contains_p (INT (0)));
5224 : 4 : }
5225 : :
5226 : : static void
5227 : 4 : range_relational_tests ()
5228 : : {
5229 : 4 : int_range<2> lhs (unsigned_char_type_node);
5230 : 4 : int_range<2> op1 (unsigned_char_type_node, UCHAR (8), UCHAR (10));
5231 : 4 : int_range<2> op2 (unsigned_char_type_node, UCHAR (20), UCHAR (20));
5232 : :
5233 : : // Never wrapping additions mean LHS > OP1.
5234 : 4 : relation_kind code = op_plus.lhs_op1_relation (lhs, op1, op2, VREL_VARYING);
5235 : 4 : ASSERT_TRUE (code == VREL_GT);
5236 : :
5237 : : // Most wrapping additions mean nothing...
5238 : 4 : op1 = int_range<2> (unsigned_char_type_node, UCHAR (8), UCHAR (10));
5239 : 4 : op2 = int_range<2> (unsigned_char_type_node, UCHAR (0), UCHAR (255));
5240 : 4 : code = op_plus.lhs_op1_relation (lhs, op1, op2, VREL_VARYING);
5241 : 4 : ASSERT_TRUE (code == VREL_VARYING);
5242 : :
5243 : : // However, always wrapping additions mean LHS < OP1.
5244 : 4 : op1 = int_range<2> (unsigned_char_type_node, UCHAR (1), UCHAR (255));
5245 : 4 : op2 = int_range<2> (unsigned_char_type_node, UCHAR (255), UCHAR (255));
5246 : 4 : code = op_plus.lhs_op1_relation (lhs, op1, op2, VREL_VARYING);
5247 : 4 : ASSERT_TRUE (code == VREL_LT);
5248 : 4 : }
5249 : :
5250 : : void
5251 : 4 : range_op_tests ()
5252 : : {
5253 : 4 : range_op_rshift_tests ();
5254 : 4 : range_op_lshift_tests ();
5255 : 4 : range_op_bitwise_and_tests ();
5256 : 4 : range_op_cast_tests ();
5257 : 4 : range_relational_tests ();
5258 : :
5259 : 4 : extern void range_op_float_tests ();
5260 : 4 : range_op_float_tests ();
5261 : 4 : }
5262 : :
5263 : : } // namespace selftest
5264 : :
5265 : : #endif // CHECKING_P
|