Line data Source code
1 : /* Code for GIMPLE range related routines.
2 : Copyright (C) 2019-2026 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 "tree.h"
28 : #include "gimple.h"
29 : #include "ssa.h"
30 : #include "gimple-pretty-print.h"
31 : #include "optabs-tree.h"
32 : #include "gimple-iterator.h"
33 : #include "gimple-fold.h"
34 : #include "wide-int.h"
35 : #include "fold-const.h"
36 : #include "case-cfn-macros.h"
37 : #include "omp-general.h"
38 : #include "cfgloop.h"
39 : #include "tree-ssa-loop.h"
40 : #include "tree-scalar-evolution.h"
41 : #include "langhooks.h"
42 : #include "vr-values.h"
43 : #include "range.h"
44 : #include "value-query.h"
45 : #include "gimple-range-op.h"
46 : #include "gimple-range.h"
47 : #include "cgraph.h"
48 : #include "alloc-pool.h"
49 : #include "symbol-summary.h"
50 : #include "ipa-utils.h"
51 : #include "sreal.h"
52 : #include "ipa-cp.h"
53 : #include "ipa-prop.h"
54 : #include "rtl.h"
55 : // Construct a fur_source, and set the m_query field.
56 :
57 473401608 : fur_source::fur_source (range_query *q)
58 : {
59 473401608 : if (q)
60 473400669 : m_query = q;
61 : else
62 1878 : m_query = get_range_query (cfun);
63 473401608 : m_depend_p = false;
64 473401608 : }
65 :
66 : // Invoke range_of_expr on EXPR.
67 :
68 : bool
69 0 : fur_source::get_operand (vrange &r, tree expr)
70 : {
71 0 : return m_query->range_of_expr (r, expr);
72 : }
73 :
74 : // Evaluate EXPR for this stmt as a PHI argument on edge E. Use the current
75 : // range_query to get the range on the edge.
76 :
77 : bool
78 0 : fur_source::get_phi_operand (vrange &r, tree expr, edge e)
79 : {
80 0 : return m_query->range_on_edge (r, e, expr);
81 : }
82 :
83 : // Default is no relation.
84 :
85 : relation_kind
86 5547819 : fur_source::query_relation (tree op1 ATTRIBUTE_UNUSED,
87 : tree op2 ATTRIBUTE_UNUSED)
88 : {
89 5547819 : return VREL_VARYING;
90 : }
91 :
92 : // Default registers nothing and returns false meaning nothing changed.
93 :
94 : bool
95 25166655 : fur_source::register_relation (gimple *s ATTRIBUTE_UNUSED,
96 : relation_kind k ATTRIBUTE_UNUSED,
97 : tree op1 ATTRIBUTE_UNUSED,
98 : tree op2 ATTRIBUTE_UNUSED)
99 : {
100 25166655 : return false;
101 : }
102 :
103 : // Default registers nothing and returns false meaning nothing changed.
104 :
105 : bool
106 6127749 : fur_source::register_relation (edge e ATTRIBUTE_UNUSED,
107 : relation_kind k ATTRIBUTE_UNUSED,
108 : tree op1 ATTRIBUTE_UNUSED,
109 : tree op2 ATTRIBUTE_UNUSED)
110 : {
111 6127749 : return false;
112 : }
113 :
114 : // Get the value of EXPR on edge m_edge.
115 :
116 : bool
117 61297811 : fur_edge::get_operand (vrange &r, tree expr)
118 : {
119 61297811 : return m_query->range_on_edge (r, m_edge, expr);
120 : }
121 :
122 : // Evaluate EXPR for this stmt as a PHI argument on edge E. Use the current
123 : // range_query to get the range on the edge.
124 :
125 : bool
126 0 : fur_edge::get_phi_operand (vrange &r, tree expr, edge e)
127 : {
128 : // Edge to edge recalculations not supported yet, until we sort it out.
129 0 : gcc_checking_assert (e == m_edge);
130 0 : return m_query->range_on_edge (r, e, expr);
131 : }
132 :
133 : // Instantiate a stmt based fur_source.
134 :
135 415920733 : fur_stmt::fur_stmt (gimple *s, range_query *q) : fur_source (q)
136 : {
137 415920733 : m_stmt = s;
138 415920733 : }
139 :
140 : // Retrieve range of EXPR as it occurs as a use on stmt M_STMT.
141 :
142 : bool
143 549934129 : fur_stmt::get_operand (vrange &r, tree expr)
144 : {
145 549934129 : return m_query->range_of_expr (r, expr, m_stmt);
146 : }
147 :
148 : // Evaluate EXPR for this stmt as a PHI argument on edge E. Use the current
149 : // range_query to get the range on the edge.
150 :
151 : bool
152 49161386 : fur_stmt::get_phi_operand (vrange &r, tree expr, edge e)
153 : {
154 : // Pick up the range of expr from edge E.
155 49161386 : fur_edge e_src (e, m_query);
156 49161386 : return e_src.get_operand (r, expr);
157 : }
158 :
159 : // Return relation based from m_stmt.
160 :
161 : relation_kind
162 105070436 : fur_stmt::query_relation (tree op1, tree op2)
163 : {
164 105070436 : return m_query->relation ().query (m_stmt, op1, op2);
165 : }
166 :
167 : // Instantiate a stmt based fur_source with a GORI object and a ranger cache.
168 :
169 230498889 : fur_depend::fur_depend (gimple *s, range_query *q, ranger_cache *c)
170 230498889 : : fur_stmt (s, q), m_cache (c)
171 : {
172 230498889 : m_depend_p = true;
173 230498889 : }
174 :
175 : // Register a relation on a stmt if there is an oracle. Return false if
176 : // no new relation is registered.
177 :
178 : bool
179 30515249 : fur_depend::register_relation (gimple *s, relation_kind k, tree op1, tree op2)
180 : {
181 30515249 : if (!m_query->relation ().record (s, k, op1, op2))
182 : return false;
183 :
184 : // This new relation could cause different calculations, so mark the operands
185 : // with a new timestamp, forcing recalculations.
186 24608717 : if (m_cache)
187 : {
188 24608681 : m_cache->update_consumers (op1);
189 24608681 : m_cache->update_consumers (op2);
190 : }
191 : return true;
192 : }
193 :
194 : // Register a relation on an edge if there is an oracle. Return false if
195 : // no new relation is registered.
196 :
197 : bool
198 6608706 : fur_depend::register_relation (edge e, relation_kind k, tree op1, tree op2)
199 : {
200 6608706 : if (!m_query->relation ().record (e, k, op1, op2))
201 : return false;
202 :
203 : // This new relation could cause different calculations, so mark the operands
204 : // with a new timestamp, forcing recalculations.
205 6591157 : if (m_cache)
206 : {
207 6591155 : m_cache->update_consumers (op1);
208 6591155 : m_cache->update_consumers (op2);
209 : }
210 : return true;
211 : }
212 :
213 : // This version of fur_source will pick a range up from a list of ranges
214 : // supplied by the caller.
215 :
216 : class fur_list : public fur_source
217 : {
218 : public:
219 : fur_list (vrange &r1, range_query *q = NULL);
220 : fur_list (vrange &r1, vrange &r2, range_query *q = NULL);
221 : fur_list (unsigned num, vrange **list, range_query *q = NULL);
222 : virtual bool get_operand (vrange &r, tree expr) override;
223 : virtual bool get_phi_operand (vrange &r, tree expr, edge e) override;
224 : private:
225 : vrange *m_local[2];
226 : vrange **m_list;
227 : unsigned m_index;
228 : unsigned m_limit;
229 : };
230 :
231 : // One range supplied for unary operations.
232 :
233 869298 : fur_list::fur_list (vrange &r1, range_query *q) : fur_source (q)
234 : {
235 869298 : m_list = m_local;
236 869298 : m_index = 0;
237 869298 : m_limit = 1;
238 869298 : m_local[0] = &r1;
239 869298 : }
240 :
241 : // Two ranges supplied for binary operations.
242 :
243 0 : fur_list::fur_list (vrange &r1, vrange &r2, range_query *q) : fur_source (q)
244 : {
245 0 : m_list = m_local;
246 0 : m_index = 0;
247 0 : m_limit = 2;
248 0 : m_local[0] = &r1;
249 0 : m_local[1] = &r2;
250 0 : }
251 :
252 : // Arbitrary number of ranges in a vector.
253 :
254 0 : fur_list::fur_list (unsigned num, vrange **list, range_query *q)
255 0 : : fur_source (q)
256 : {
257 0 : m_list = list;
258 0 : m_index = 0;
259 0 : m_limit = num;
260 0 : }
261 :
262 : // Get the next operand from the vector, ensure types are compatible.
263 :
264 : bool
265 1730889 : fur_list::get_operand (vrange &r, tree expr)
266 : {
267 : // Do not use the vector for non-ssa-names, or if it has been emptied.
268 1730889 : if (TREE_CODE (expr) != SSA_NAME || m_index >= m_limit)
269 861591 : return m_query->range_of_expr (r, expr);
270 869298 : r = *m_list[m_index++];
271 869298 : gcc_checking_assert (range_compatible_p (TREE_TYPE (expr), r.type ()));
272 : return true;
273 : }
274 :
275 : // This will simply pick the next operand from the vector.
276 : bool
277 0 : fur_list::get_phi_operand (vrange &r, tree expr, edge e ATTRIBUTE_UNUSED)
278 : {
279 0 : return get_operand (r, expr);
280 : }
281 :
282 : // Fold stmt S into range R using R1 as the first operand.
283 :
284 : bool
285 869298 : fold_range (vrange &r, gimple *s, vrange &r1, range_query *q)
286 : {
287 869298 : fold_using_range f;
288 869298 : fur_list src (r1, q);
289 869298 : return f.fold_stmt (r, s, src);
290 : }
291 :
292 : // Fold stmt S into range R using R1 and R2 as the first two operands.
293 :
294 : bool
295 0 : fold_range (vrange &r, gimple *s, vrange &r1, vrange &r2, range_query *q)
296 : {
297 0 : fold_using_range f;
298 0 : fur_list src (r1, r2, q);
299 0 : return f.fold_stmt (r, s, src);
300 : }
301 :
302 : // Fold stmt S into range R using NUM_ELEMENTS from VECTOR as the initial
303 : // operands encountered.
304 :
305 : bool
306 0 : fold_range (vrange &r, gimple *s, unsigned num_elements, vrange **vector,
307 : range_query *q)
308 : {
309 0 : fold_using_range f;
310 0 : fur_list src (num_elements, vector, q);
311 0 : return f.fold_stmt (r, s, src);
312 : }
313 :
314 : // Fold stmt S into range R using range query Q.
315 :
316 : bool
317 77607989 : fold_range (vrange &r, gimple *s, range_query *q)
318 : {
319 77607989 : fold_using_range f;
320 77607989 : fur_stmt src (s, q);
321 77607989 : return f.fold_stmt (r, s, src);
322 : }
323 :
324 : // Recalculate stmt S into R using range query Q as if it were on edge ON_EDGE.
325 :
326 : bool
327 7450185 : fold_range (vrange &r, gimple *s, edge on_edge, range_query *q)
328 : {
329 7450185 : fold_using_range f;
330 7450185 : fur_edge src (on_edge, q);
331 7450185 : return f.fold_stmt (r, s, src);
332 : }
333 :
334 : // Calculate op1 on statetemt S with LHS into range R using range query Q
335 : // to resolve any other operands.
336 :
337 : bool
338 0 : op1_range (vrange &r, gimple *s, const vrange &lhs, range_query *q)
339 : {
340 0 : gimple_range_op_handler handler (s);
341 0 : if (!handler)
342 : return false;
343 :
344 0 : fur_stmt src (s, q);
345 :
346 0 : tree op2_expr = handler.operand2 ();
347 0 : if (!op2_expr)
348 0 : return handler.calc_op1 (r, lhs);
349 :
350 0 : value_range op2 (TREE_TYPE (op2_expr));
351 0 : if (!src.get_operand (op2, op2_expr))
352 : return false;
353 :
354 0 : return handler.calc_op1 (r, lhs, op2);
355 0 : }
356 :
357 : // Calculate op1 on statetemt S into range R using range query Q.
358 : // LHS is set to VARYING in this case.
359 :
360 : bool
361 0 : op1_range (vrange &r, gimple *s, range_query *q)
362 : {
363 0 : tree lhs_type = gimple_range_type (s);
364 0 : if (!lhs_type)
365 : return false;
366 0 : value_range lhs_range;
367 0 : lhs_range.set_varying (lhs_type);
368 0 : return op1_range (r, s, lhs_range, q);
369 0 : }
370 :
371 : // Calculate op2 on statetemt S with LHS into range R using range query Q
372 : // to resolve any other operands.
373 :
374 : bool
375 0 : op2_range (vrange &r, gimple *s, const vrange &lhs, range_query *q)
376 : {
377 :
378 0 : gimple_range_op_handler handler (s);
379 0 : if (!handler)
380 : return false;
381 :
382 0 : fur_stmt src (s, q);
383 :
384 0 : value_range op1 (TREE_TYPE (handler.operand1 ()));
385 0 : if (!src.get_operand (op1, handler.operand1 ()))
386 : return false;
387 :
388 0 : return handler.calc_op2 (r, lhs, op1);
389 0 : }
390 :
391 : // Calculate op2 on statetemt S into range R using range query Q.
392 : // LHS is set to VARYING in this case.
393 :
394 : bool
395 0 : op2_range (vrange &r, gimple *s, range_query *q)
396 : {
397 0 : tree lhs_type = gimple_range_type (s);
398 0 : if (!lhs_type)
399 : return false;
400 0 : value_range lhs_range;
401 0 : lhs_range.set_varying (lhs_type);
402 0 : return op2_range (r, s, lhs_range, q);
403 0 : }
404 :
405 : // Provide a fur_source which can be used to determine any relations on
406 : // a statement. It manages the callback from fold_using_ranges to determine
407 : // a relation_trio for a statement.
408 :
409 : class fur_relation : public fur_stmt
410 : {
411 : public:
412 : fur_relation (gimple *s, range_query *q = NULL);
413 : virtual bool register_relation (gimple *stmt, relation_kind k, tree op1,
414 : tree op2);
415 : virtual bool register_relation (edge e, relation_kind k, tree op1,
416 : tree op2);
417 : relation_trio trio() const;
418 : private:
419 : relation_kind def_op1, def_op2, op1_op2;
420 : };
421 :
422 1084577 : fur_relation::fur_relation (gimple *s, range_query *q) : fur_stmt (s, q)
423 : {
424 1084577 : def_op1 = def_op2 = op1_op2 = VREL_VARYING;
425 1084577 : }
426 :
427 : // Construct a trio from what is known.
428 :
429 : relation_trio
430 1084577 : fur_relation::trio () const
431 : {
432 1084577 : return relation_trio (def_op1, def_op2, op1_op2);
433 : }
434 :
435 : // Don't support edges, but avoid a compiler warning by providing the routine.
436 : // Return false indicating nothing has changed.
437 :
438 : bool
439 0 : fur_relation::register_relation (edge, relation_kind, tree, tree)
440 : {
441 0 : return false;
442 : }
443 :
444 : // Register relation K between OP1 and OP2 on STMT. Return false if there
445 : // is no relation.
446 :
447 : bool
448 1066577 : fur_relation::register_relation (gimple *stmt, relation_kind k, tree op1,
449 : tree op2)
450 : {
451 1066577 : tree lhs = gimple_get_lhs (stmt);
452 1066577 : tree a1 = NULL_TREE;
453 1066577 : tree a2 = NULL_TREE;
454 1066577 : switch (gimple_code (stmt))
455 : {
456 0 : case GIMPLE_COND:
457 0 : a1 = gimple_cond_lhs (stmt);
458 0 : a2 = gimple_cond_rhs (stmt);
459 0 : break;
460 1066577 : case GIMPLE_ASSIGN:
461 1066577 : a1 = gimple_assign_rhs1 (stmt);
462 1066577 : if (gimple_num_ops (stmt) >= 3)
463 1066577 : a2 = gimple_assign_rhs2 (stmt);
464 : break;
465 : default:
466 : break;
467 : }
468 : // STMT is of the form LHS = A1 op A2, now map the relation to these
469 : // operands, if possible.
470 1066577 : if (op1 == lhs)
471 : {
472 1066577 : if (op2 == a1)
473 1066577 : def_op1 = k;
474 0 : else if (op2 == a2)
475 0 : def_op2 = k;
476 : }
477 0 : else if (op2 == lhs)
478 : {
479 0 : if (op1 == a1)
480 0 : def_op1 = relation_swap (k);
481 0 : else if (op1 == a2)
482 0 : def_op2 = relation_swap (k);
483 : }
484 : else
485 : {
486 0 : if (op1 == a1 && op2 == a2)
487 0 : op1_op2 = k;
488 0 : else if (op2 == a1 && op1 == a2)
489 0 : op1_op2 = relation_swap (k);
490 : }
491 0 : return def_op1 == VREL_VARYING && def_op2 == VREL_VARYING
492 1066577 : && op1_op2 == VREL_VARYING;
493 : }
494 :
495 : // Return the relation trio for stmt S using query Q.
496 :
497 : relation_trio
498 1084577 : fold_relations (gimple *s, range_query *q)
499 : {
500 1084577 : fold_using_range f;
501 1084577 : fur_relation src (s, q);
502 1084577 : tree lhs = gimple_range_ssa_p (gimple_get_lhs (s));
503 1084577 : if (lhs)
504 : {
505 1084577 : value_range vr(TREE_TYPE (lhs));
506 1084577 : if (f.fold_stmt (vr, s, src))
507 1084577 : return src.trio ();
508 1084577 : }
509 0 : return TRIO_VARYING;
510 : }
511 :
512 : // -------------------------------------------------------------------------
513 :
514 : // Adjust the range for a pointer difference where the operands came
515 : // from a memchr.
516 : //
517 : // This notices the following sequence:
518 : //
519 : // def = __builtin_memchr (arg, 0, sz)
520 : // n = def - arg
521 : //
522 : // The range for N can be narrowed to [0, PTRDIFF_MAX - 1].
523 :
524 : static void
525 2735995 : adjust_pointer_diff_expr (irange &res, const gimple *diff_stmt)
526 : {
527 2735995 : tree op0 = gimple_assign_rhs1 (diff_stmt);
528 2735995 : tree op1 = gimple_assign_rhs2 (diff_stmt);
529 2735995 : tree op0_ptype = TREE_TYPE (TREE_TYPE (op0));
530 2735995 : tree op1_ptype = TREE_TYPE (TREE_TYPE (op1));
531 2735995 : gimple *call;
532 :
533 2735995 : if (TREE_CODE (op0) == SSA_NAME
534 2709329 : && TREE_CODE (op1) == SSA_NAME
535 2665044 : && (call = SSA_NAME_DEF_STMT (op0))
536 2665044 : && is_gimple_call (call)
537 83561 : && gimple_call_builtin_p (call, BUILT_IN_MEMCHR)
538 64964 : && TYPE_MODE (op0_ptype) == TYPE_MODE (char_type_node)
539 64720 : && TYPE_PRECISION (op0_ptype) == TYPE_PRECISION (char_type_node)
540 64720 : && TYPE_MODE (op1_ptype) == TYPE_MODE (char_type_node)
541 64162 : && TYPE_PRECISION (op1_ptype) == TYPE_PRECISION (char_type_node)
542 64162 : && gimple_call_builtin_p (call, BUILT_IN_MEMCHR)
543 64162 : && vrp_operand_equal_p (op1, gimple_call_arg (call, 0))
544 2775147 : && integer_zerop (gimple_call_arg (call, 1)))
545 : {
546 26 : wide_int maxm1 = irange_val_max (ptrdiff_type_node) - 1;
547 26 : res.intersect (int_range<2> (ptrdiff_type_node,
548 52 : wi::zero (TYPE_PRECISION (ptrdiff_type_node)),
549 26 : maxm1));
550 26 : }
551 2735995 : }
552 :
553 : // Adjust the range for an IMAGPART_EXPR.
554 :
555 : static void
556 944659 : adjust_imagpart_expr (vrange &res, const gimple *stmt)
557 : {
558 944659 : tree name = TREE_OPERAND (gimple_assign_rhs1 (stmt), 0);
559 :
560 944659 : if (TREE_CODE (name) != SSA_NAME || !SSA_NAME_DEF_STMT (name))
561 : return;
562 :
563 815353 : gimple *def_stmt = SSA_NAME_DEF_STMT (name);
564 815353 : if (is_gimple_call (def_stmt) && gimple_call_internal_p (def_stmt))
565 : {
566 400393 : switch (gimple_call_internal_fn (def_stmt))
567 : {
568 382938 : case IFN_ADD_OVERFLOW:
569 382938 : case IFN_SUB_OVERFLOW:
570 382938 : case IFN_MUL_OVERFLOW:
571 382938 : case IFN_UADDC:
572 382938 : case IFN_USUBC:
573 382938 : case IFN_ATOMIC_COMPARE_EXCHANGE:
574 382938 : {
575 382938 : int_range<2> r;
576 382938 : r.set_varying (boolean_type_node);
577 382938 : tree type = TREE_TYPE (gimple_assign_lhs (stmt));
578 382938 : range_cast (r, type);
579 382938 : res.intersect (r);
580 382938 : }
581 400393 : default:
582 400393 : break;
583 : }
584 400393 : return;
585 : }
586 414960 : if (is_gimple_assign (def_stmt)
587 414960 : && gimple_assign_rhs_code (def_stmt) == COMPLEX_CST)
588 : {
589 15 : tree cst = gimple_assign_rhs1 (def_stmt);
590 15 : if (TREE_CODE (cst) == COMPLEX_CST
591 15 : && TREE_CODE (TREE_TYPE (TREE_TYPE (cst))) == INTEGER_TYPE)
592 : {
593 4 : wide_int w = wi::to_wide (TREE_IMAGPART (cst));
594 4 : int_range<1> imag (TREE_TYPE (TREE_IMAGPART (cst)), w, w);
595 4 : res.intersect (imag);
596 4 : }
597 : }
598 : }
599 :
600 : // Adjust the range for a REALPART_EXPR.
601 :
602 : static void
603 893998 : adjust_realpart_expr (vrange &res, const gimple *stmt)
604 : {
605 893998 : tree name = TREE_OPERAND (gimple_assign_rhs1 (stmt), 0);
606 :
607 893998 : if (TREE_CODE (name) != SSA_NAME)
608 : return;
609 :
610 756906 : gimple *def_stmt = SSA_NAME_DEF_STMT (name);
611 756906 : if (!SSA_NAME_DEF_STMT (name))
612 : return;
613 :
614 756906 : if (is_gimple_assign (def_stmt)
615 756906 : && gimple_assign_rhs_code (def_stmt) == COMPLEX_CST)
616 : {
617 10 : tree cst = gimple_assign_rhs1 (def_stmt);
618 10 : if (TREE_CODE (cst) == COMPLEX_CST
619 10 : && TREE_CODE (TREE_TYPE (TREE_TYPE (cst))) == INTEGER_TYPE)
620 : {
621 0 : wide_int imag = wi::to_wide (TREE_REALPART (cst));
622 0 : int_range<2> tmp (TREE_TYPE (TREE_REALPART (cst)), imag, imag);
623 0 : res.intersect (tmp);
624 0 : }
625 : }
626 : }
627 :
628 : // This function looks for situations when walking the use/def chains
629 : // may provide additional contextual range information not exposed on
630 : // this statement.
631 :
632 : static void
633 184556357 : gimple_range_adjustment (vrange &res, const gimple *stmt)
634 : {
635 184556357 : switch (gimple_expr_code (stmt))
636 : {
637 2735995 : case POINTER_DIFF_EXPR:
638 2735995 : adjust_pointer_diff_expr (as_a <irange> (res), stmt);
639 2735995 : return;
640 :
641 944659 : case IMAGPART_EXPR:
642 944659 : adjust_imagpart_expr (res, stmt);
643 944659 : return;
644 :
645 893998 : case REALPART_EXPR:
646 893998 : adjust_realpart_expr (res, stmt);
647 893998 : return;
648 :
649 : default:
650 : break;
651 : }
652 : }
653 :
654 : // Provide context to the gimple fold callback.
655 :
656 : static struct
657 : {
658 : gimple *m_stmt;
659 : range_query *m_query;
660 : } x_fold_context;
661 :
662 : // Gimple fold callback.
663 :
664 : static tree
665 53983115 : pta_valueize (tree name)
666 : {
667 53983115 : tree ret
668 53983115 : = x_fold_context.m_query->value_of_expr (name, x_fold_context.m_stmt);
669 :
670 53983115 : return ret ? ret : name;
671 : }
672 :
673 : // Calculate a range for statement S and return it in R. If NAME is provided it
674 : // represents the SSA_NAME on the LHS of the statement. It is only required
675 : // if there is more than one lhs/output. If a range cannot
676 : // be calculated, return false.
677 :
678 : bool
679 294621007 : fold_using_range::fold_stmt (vrange &r, gimple *s, fur_source &src, tree name)
680 : {
681 294621007 : bool res = false;
682 : // If name and S are specified, make sure it is an LHS of S.
683 294621007 : gcc_checking_assert (!name || !gimple_get_lhs (s) ||
684 : name == gimple_get_lhs (s));
685 :
686 161382952 : if (!name)
687 161382952 : name = gimple_get_lhs (s);
688 :
689 : // Process addresses and loads from static constructors.
690 294621007 : if (gimple_code (s) == GIMPLE_ASSIGN && range_from_readonly_var (r, s))
691 : return true;
692 :
693 294519848 : gimple_range_op_handler handler (s);
694 294519848 : if (gimple_code (s) == GIMPLE_ASSIGN
695 294519848 : && gimple_assign_rhs_code (s) == ADDR_EXPR)
696 4298842 : res = range_of_address (as_a <prange> (r), s, src);
697 290221006 : else if (handler)
698 184557463 : res = range_of_range_op (r, handler, src);
699 105663543 : else if (is_a<gphi *>(s))
700 23856839 : res = range_of_phi (r, as_a<gphi *> (s), src);
701 81806704 : else if (is_a<gcall *>(s))
702 12678444 : res = range_of_call (r, as_a<gcall *> (s), src);
703 69128260 : else if (is_a<gassign *> (s) && gimple_assign_rhs_code (s) == COND_EXPR)
704 151135 : res = range_of_cond_expr (r, as_a<gassign *> (s), src);
705 :
706 : // If the result is varying, use the type's min/max if either is not
707 : // the same as the full precision min/max. This helps with strict enum
708 : // e.g. `g++.dg/warn/pr33738.C`.
709 225542723 : if (res && r.varying_p () && INTEGRAL_TYPE_P (r.type ()))
710 : {
711 116655332 : irange &ir = as_a <irange> (r);
712 116655332 : tree type = r.type ();
713 116655332 : auto typemax = wi::to_wide (TYPE_MAX_VALUE (type));
714 116655332 : auto typemin = wi::to_wide (TYPE_MIN_VALUE (type));
715 116655332 : auto precisionmax = wi::max_value (TYPE_PRECISION (type),
716 233310664 : TYPE_SIGN (type));
717 116655332 : auto precisionmin = wi::min_value (TYPE_PRECISION (type),
718 233310664 : TYPE_SIGN (type));
719 233240633 : if (typemax != precisionmax || typemin != precisionmin)
720 70031 : ir.set (type, typemin, typemax);
721 116656155 : }
722 :
723 294519848 : if (!res)
724 : {
725 : // If no name specified or range is unsupported, bail.
726 68977125 : if (!name || !gimple_range_ssa_p (name))
727 50191 : return false;
728 : // We don't understand the stmt, so return the global range.
729 68926934 : gimple_range_global (r, name);
730 68926934 : return true;
731 : }
732 :
733 225542723 : if (r.undefined_p ())
734 : return true;
735 :
736 : // We sometimes get compatible types copied from operands, make sure
737 : // the correct type is being returned.
738 225491995 : if (name && TREE_TYPE (name) != r.type ())
739 : {
740 3718780 : gcc_checking_assert (range_compatible_p (r.type (), TREE_TYPE (name)));
741 3718780 : range_cast (r, TREE_TYPE (name));
742 : }
743 :
744 : // IF this is not a prange, we are done.
745 225491995 : if (!is_a <prange> (r))
746 : return true;
747 :
748 26062308 : prange &p = as_a <prange> (r);
749 : // Check to see if points_to should be set.
750 26062308 : if (p.pt_unknown_p () && name && gimple_code (s) == GIMPLE_ASSIGN)
751 : {
752 15743920 : tree rhs = gimple_assign_rhs1 (s);
753 15743920 : tree_code code = gimple_assign_rhs_code (s);
754 : // If code is SSA_NAME, any points to would already be copied.
755 14536840 : if (code != SSA_NAME && get_gimple_rhs_class (code) == GIMPLE_SINGLE_RHS
756 20220722 : && TREE_CODE (rhs) == ADDR_EXPR)
757 : {
758 4296888 : p.set_pt (rhs, true);
759 : }
760 : // PR 125854 - Do not attempt to invoke the fold machinery unless this
761 : // query is the same as the current query (which fold may invoke).
762 22894064 : else if (src.query () == get_range_query (cfun))
763 : {
764 : // If we couldn't find anything, try fold.
765 6126758 : x_fold_context = { s, src.query () };
766 6126758 : rhs = gimple_fold_stmt_to_constant_1 (s, pta_valueize, pta_valueize);
767 6126758 : if (rhs && TREE_CODE (rhs) == ADDR_EXPR)
768 : {
769 12197 : p.set_pt (rhs, true);
770 : }
771 : }
772 : }
773 : return true;
774 : }
775 :
776 : // Calculate a range for range_op statement S and return it in R. If any
777 : // If a range cannot be calculated, return false.
778 :
779 : bool
780 184557463 : fold_using_range::range_of_range_op (vrange &r,
781 : gimple_range_op_handler &handler,
782 : fur_source &src)
783 : {
784 184557463 : gcc_checking_assert (handler);
785 184557463 : gimple *s = handler.stmt ();
786 184557463 : tree type = gimple_range_type (s);
787 184557463 : if (!type)
788 : return false;
789 :
790 184557463 : tree lhs = handler.lhs ();
791 184557463 : tree op1 = handler.operand1 ();
792 184557463 : tree op2 = handler.operand2 ();
793 :
794 : // Certain types of builtin functions may have no arguments.
795 184557463 : if (!op1)
796 : {
797 1106 : value_range r1 (type);
798 1106 : if (!handler.fold_range (r, type, r1, r1))
799 0 : r.set_varying (type);
800 1106 : return true;
801 1106 : }
802 :
803 184556357 : value_range range1 (TREE_TYPE (op1));
804 184556357 : value_range range2 (op2 ? TREE_TYPE (op2) : TREE_TYPE (op1));
805 :
806 184556357 : if (src.get_operand (range1, op1))
807 : {
808 184556357 : if (!op2)
809 : {
810 : // Fold range, and register any dependency if available.
811 37664394 : value_range r2 (type);
812 37664394 : r2.set_varying (type);
813 37664394 : if (!handler.fold_range (r, type, range1, r2))
814 295147 : r.set_varying (type);
815 37664394 : if (lhs && gimple_range_ssa_p (op1))
816 : {
817 54600180 : if (src.gori_ssa ())
818 20198377 : src.gori_ssa ()->register_dependency (lhs, op1);
819 34401770 : relation_kind rel;
820 34401770 : rel = handler.lhs_op1_relation (r, range1, range1);
821 34401770 : if (rel != VREL_VARYING)
822 25158759 : src.register_relation (s, rel, lhs, op1);
823 : }
824 37664394 : }
825 146891963 : else if (src.get_operand (range2, op2))
826 : {
827 146891963 : relation_kind rel = src.query_relation (op1, op2);
828 146891963 : if (dump_file && (dump_flags & TDF_DETAILS) && rel != VREL_VARYING)
829 : {
830 143 : fprintf (dump_file, " folding with relation ");
831 143 : print_generic_expr (dump_file, op1, TDF_SLIM);
832 143 : print_relation (dump_file, rel);
833 143 : print_generic_expr (dump_file, op2, TDF_SLIM);
834 143 : fputc ('\n', dump_file);
835 : }
836 : // Fold range, and register any dependency if available.
837 146891963 : if (!handler.fold_range (r, type, range1, range2,
838 : relation_trio::op1_op2 (rel)))
839 0 : r.set_varying (type);
840 146891963 : if (irange::supports_p (type))
841 134208889 : relation_fold_and_or (as_a <irange> (r), s, src, range1, range2);
842 146891963 : if (lhs)
843 : {
844 147097517 : if (src.gori_ssa ())
845 : {
846 56363591 : src.gori_ssa ()->register_dependency (lhs, op1);
847 112727182 : src.gori_ssa ()->register_dependency (lhs, op2);
848 : }
849 90733862 : if (gimple_range_ssa_p (op1))
850 : {
851 88082617 : relation_kind rel2 = handler.lhs_op1_relation (r, range1,
852 88082617 : range2, rel);
853 88082617 : if (rel2 != VREL_VARYING)
854 36840119 : src.register_relation (s, rel2, lhs, op1);
855 : }
856 90733862 : if (gimple_range_ssa_p (op2))
857 : {
858 36812610 : relation_kind rel2 = handler.lhs_op2_relation (r, range1,
859 36812610 : range2, rel);
860 36812610 : if (rel2 != VREL_VARYING)
861 2463917 : src.register_relation (s, rel2, lhs, op2);
862 : }
863 : }
864 : // Check for an existing BB, as we maybe asked to fold an
865 : // artificial statement not in the CFG.
866 56158101 : else if (is_a<gcond *> (s) && gimple_bb (s))
867 : {
868 47456185 : basic_block bb = gimple_bb (s);
869 47456185 : edge e0 = EDGE_SUCC (bb, 0);
870 : /* During RTL expansion one of the edges can be removed
871 : if expansion proves the jump is unconditional. */
872 47456185 : edge e1 = single_succ_p (bb) ? NULL : EDGE_SUCC (bb, 1);
873 :
874 47456185 : gcc_checking_assert (e1 || currently_expanding_to_rtl);
875 47456185 : if (!single_pred_p (e0->dest))
876 11899812 : e0 = NULL;
877 47456185 : if (e1 && !single_pred_p (e1->dest))
878 : e1 = NULL;
879 47456185 : src.register_outgoing_edges (as_a<gcond *> (s),
880 : as_a <irange> (r), e0, e1);
881 : }
882 : }
883 : else
884 0 : r.set_varying (type);
885 : }
886 : else
887 0 : r.set_varying (type);
888 : // Make certain range-op adjustments that aren't handled any other way.
889 184556357 : gimple_range_adjustment (r, s);
890 184556357 : return true;
891 184556357 : }
892 :
893 : // Calculate the range of an assignment containing an ADDR_EXPR.
894 : // Return the range in R.
895 : // If a range cannot be calculated, set it to VARYING and return true.
896 :
897 : bool
898 4298842 : fold_using_range::range_of_address (prange &r, gimple *stmt, fur_source &src)
899 : {
900 4298842 : gcc_checking_assert (gimple_code (stmt) == GIMPLE_ASSIGN);
901 4298842 : gcc_checking_assert (gimple_assign_rhs_code (stmt) == ADDR_EXPR);
902 :
903 4298842 : tree expr = gimple_assign_rhs1 (stmt);
904 4298842 : poly_int64 bitsize, bitpos;
905 4298842 : tree offset;
906 4298842 : machine_mode mode;
907 4298842 : int unsignedp, reversep, volatilep;
908 4298842 : tree base = get_inner_reference (TREE_OPERAND (expr, 0), &bitsize,
909 : &bitpos, &offset, &mode, &unsignedp,
910 : &reversep, &volatilep);
911 :
912 :
913 4298842 : if (base != NULL_TREE
914 4298842 : && TREE_CODE (base) == MEM_REF
915 8450046 : && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME)
916 : {
917 4151155 : tree ssa = TREE_OPERAND (base, 0);
918 4151155 : tree lhs = gimple_get_lhs (stmt);
919 6693151 : if (lhs && gimple_range_ssa_p (ssa) && src.gori_ssa ())
920 2541996 : src.gori_ssa ()->register_dependency (lhs, ssa);
921 4151155 : src.get_operand (r, ssa);
922 4151155 : range_cast (r, TREE_TYPE (gimple_assign_rhs1 (stmt)));
923 :
924 4151155 : poly_offset_int off = 0;
925 4151155 : bool off_cst = false;
926 4151155 : if (offset == NULL_TREE || TREE_CODE (offset) == INTEGER_CST)
927 : {
928 4069199 : off = mem_ref_offset (base);
929 4069199 : if (offset)
930 48 : off += poly_offset_int::from (wi::to_poly_wide (offset),
931 48 : SIGNED);
932 4069199 : off <<= LOG2_BITS_PER_UNIT;
933 4069199 : off += bitpos;
934 : off_cst = true;
935 : }
936 : /* If &X->a is equal to X, the range of X is the result. */
937 4069199 : if (off_cst && known_eq (off, 0))
938 1453348 : return true;
939 2697807 : else if (flag_delete_null_pointer_checks
940 2697807 : && !TYPE_OVERFLOW_WRAPS (TREE_TYPE (expr)))
941 : {
942 : /* For -fdelete-null-pointer-checks -fno-wrapv-pointer we don't
943 : allow going from non-NULL pointer to NULL. */
944 2696330 : if (r.undefined_p ()
945 5392660 : || !r.contains_p (wi::zero (TYPE_PRECISION (TREE_TYPE (expr)))))
946 : {
947 : /* We could here instead adjust r by off >> LOG2_BITS_PER_UNIT
948 : using POINTER_PLUS_EXPR if off_cst and just fall back to
949 : this. */
950 1991777 : r.set_nonzero (TREE_TYPE (gimple_assign_rhs1 (stmt)));
951 1991777 : return true;
952 : }
953 : }
954 : /* If MEM_REF has a "positive" offset, consider it non-NULL
955 : always, for -fdelete-null-pointer-checks also "negative"
956 : ones. Punt for unknown offsets (e.g. variable ones). */
957 706030 : if (!TYPE_OVERFLOW_WRAPS (TREE_TYPE (expr))
958 705820 : && off_cst
959 646679 : && known_ne (off, 0)
960 1352709 : && (flag_delete_null_pointer_checks || known_gt (off, 0)))
961 : {
962 646679 : r.set_nonzero (TREE_TYPE (gimple_assign_rhs1 (stmt)));
963 646679 : return true;
964 : }
965 59351 : r.set_varying (TREE_TYPE (gimple_assign_rhs1 (stmt)));
966 59351 : return true;
967 : }
968 :
969 : // Handle "= &a".
970 147687 : if (tree_single_nonzero_p (expr))
971 : {
972 146625 : r.set_nonzero (TREE_TYPE (gimple_assign_rhs1 (stmt)));
973 146625 : return true;
974 : }
975 :
976 : // Otherwise return varying.
977 1062 : r.set_varying (TREE_TYPE (gimple_assign_rhs1 (stmt)));
978 1062 : return true;
979 : }
980 :
981 : /* If TYPE is a pointer, return false. Otherwise, add zero of TYPE (which must
982 : be an integer) to R and return true. */
983 :
984 : static bool
985 1180 : range_from_missing_constructor_part (vrange &r, tree type)
986 : {
987 1180 : if (POINTER_TYPE_P (type))
988 : return false;
989 1031 : gcc_checking_assert (irange::supports_p (type));
990 1031 : wide_int zero = wi::zero (TYPE_PRECISION (type));
991 1031 : r.union_ (int_range<1> (type, zero, zero));
992 1031 : return true;
993 1031 : }
994 :
995 : // One step of fold_using_range::range_from_readonly_var. Process expressions
996 : // in COMPS which together load a value of TYPE, from index I to 0 according to
997 : // the corresponding static initializer in CST which should be either a scalar
998 : // invariant or a constructor. Currently TYPE must be either a pointer or an
999 : // integer. If TYPE is a pointer, return true if all potentially loaded values
1000 : // are known not to be zero and false if any of them can be zero. Otherwise
1001 : // return true if it is possible to add all constants which can be loaded from
1002 : // CST (which must be storable to TYPE) to R and do so.
1003 : // TODO: Add support for franges.
1004 :
1005 : static bool
1006 771828 : range_from_readonly_load (vrange &r, tree type, tree cst,
1007 : const vec <tree> &comps, unsigned i)
1008 : {
1009 782769 : if (i == 0)
1010 : {
1011 665936 : if (!useless_type_conversion_p (type, TREE_TYPE (cst)))
1012 : return false;
1013 :
1014 665936 : if (POINTER_TYPE_P (type))
1015 : {
1016 149392 : return tree_single_nonzero_p (cst);
1017 : }
1018 :
1019 516544 : if (TREE_CODE (cst) != INTEGER_CST)
1020 : return false;
1021 :
1022 516473 : wide_int wi_cst = wi::to_wide (cst);
1023 516473 : r.union_ (int_range<1> (type, wi_cst, wi_cst));
1024 516473 : return true;
1025 516473 : }
1026 : /* TODO: Perhaps handle RAW_DATA_CST too. */
1027 116833 : if (TREE_CODE (cst) != CONSTRUCTOR)
1028 : return false;
1029 :
1030 116086 : i--;
1031 116086 : tree expr = comps[i];
1032 116086 : unsigned ix;
1033 116086 : tree index, val;
1034 :
1035 116086 : if (TREE_CODE (expr) == COMPONENT_REF)
1036 : {
1037 10988 : tree ref_fld = TREE_OPERAND (expr, 1);
1038 17521 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (cst), ix, index, val)
1039 : {
1040 17474 : if (index != ref_fld)
1041 6533 : continue;
1042 : return range_from_readonly_load (r, type, val, comps, i);
1043 : }
1044 47 : if (TREE_CODE (TREE_TYPE (cst)) == RECORD_TYPE)
1045 7 : return range_from_missing_constructor_part (r, type);
1046 : else
1047 : /* Missing constructor of a union field just isn't like other missing
1048 : constructor parts. */
1049 : return false;
1050 : }
1051 :
1052 105098 : gcc_assert (TREE_CODE (expr) == ARRAY_REF);
1053 105098 : tree op1 = TREE_OPERAND (expr, 1);
1054 :
1055 105098 : if (TREE_CODE (op1) == INTEGER_CST)
1056 : {
1057 3312 : unsigned ctor_idx;
1058 3312 : val = get_array_ctor_element_at_index (cst, wi::to_offset (op1),
1059 : &ctor_idx);
1060 3312 : if (!val)
1061 : {
1062 96 : if (ctor_idx < CONSTRUCTOR_NELTS (cst))
1063 : return false;
1064 96 : return range_from_missing_constructor_part (r, type);
1065 : }
1066 3216 : return range_from_readonly_load (r, type, val, comps, i);
1067 : }
1068 :
1069 101786 : tree arr_type = TREE_TYPE (cst);
1070 101786 : tree domain = TYPE_DOMAIN (arr_type);
1071 101786 : if (!TYPE_MIN_VALUE (domain)
1072 101786 : || !TYPE_MAX_VALUE (domain)
1073 101786 : || !tree_fits_uhwi_p (TYPE_MIN_VALUE (domain))
1074 203572 : || !tree_fits_uhwi_p (TYPE_MAX_VALUE (domain)))
1075 : return false;
1076 101711 : unsigned HOST_WIDE_INT needed_count
1077 101711 : = (tree_to_uhwi (TYPE_MAX_VALUE (domain))
1078 101711 : - tree_to_uhwi (TYPE_MIN_VALUE (domain)) + 1);
1079 203362 : if (CONSTRUCTOR_NELTS (cst) < needed_count)
1080 : {
1081 1077 : if (!range_from_missing_constructor_part (r, type))
1082 : return false;
1083 : }
1084 :
1085 766958 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (cst), ix, index, val)
1086 : {
1087 : /* TODO: If the array index in the expr is an SSA_NAME with a known
1088 : range, we could use just values loaded from the corresponding array
1089 : elements. */
1090 666273 : if (!range_from_readonly_load (r, type, val, comps, i))
1091 : return false;
1092 : }
1093 :
1094 : return true;
1095 : }
1096 :
1097 : // Attempt to calculate the range of value loaded by STMT (which must be an
1098 : // assignment) if it is a load from a read-only aggregate variable. If
1099 : // successful, return true and set the discovered range in R. Otherwise return
1100 : // false and leave R untouched.
1101 :
1102 : bool
1103 190042122 : fold_using_range::range_from_readonly_var (vrange &r, gimple *stmt)
1104 : {
1105 190042122 : gcc_checking_assert (gimple_code (stmt) == GIMPLE_ASSIGN);
1106 190042122 : tree type = TREE_TYPE (gimple_assign_lhs (stmt));
1107 : /* TODO: Add support for frange. */
1108 190042122 : if (!irange::supports_p (type)
1109 190042122 : && !prange::supports_p (type))
1110 : return false;
1111 :
1112 180232527 : unsigned HOST_WIDE_INT limit = param_vrp_cstload_limit;
1113 180232527 : if (!limit)
1114 : return false;
1115 :
1116 180213828 : tree t = gimple_assign_rhs1 (stmt);
1117 180213828 : if (!tree_fits_uhwi_p (TYPE_SIZE_UNIT (TREE_TYPE (t))))
1118 : return false;
1119 180213828 : limit *= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (t)));
1120 :
1121 180213828 : unsigned count = 0;
1122 180213828 : while (TREE_CODE (t) == ARRAY_REF
1123 230490477 : || TREE_CODE (t) == COMPONENT_REF)
1124 : {
1125 50276649 : count++;
1126 50276649 : t = TREE_OPERAND (t, 0);
1127 : }
1128 180213828 : if (!count
1129 32449731 : || (TREE_CODE (t) != VAR_DECL
1130 32449731 : && TREE_CODE (t) != CONST_DECL))
1131 : return false;
1132 :
1133 9043315 : if (!tree_fits_uhwi_p (DECL_SIZE_UNIT (t))
1134 9043315 : || tree_to_uhwi (DECL_SIZE_UNIT (t)) > limit)
1135 : return false;
1136 :
1137 : /* TODO: We perhaps should try to handle at least some cases when the
1138 : declaration is wrapped in a MEM_REF, but we need to be careful to look at
1139 : the right part of the constructor then. */
1140 8052309 : tree ctor = ctor_for_folding (t);
1141 8052309 : if (!ctor
1142 8052302 : || TREE_CODE (ctor) != CONSTRUCTOR)
1143 : return false;
1144 :
1145 102339 : t = gimple_assign_rhs1 (stmt);
1146 102339 : auto_vec <tree, 4> comps;
1147 102339 : comps.safe_grow (count, true);
1148 102339 : int i = 0;
1149 102339 : while (TREE_CODE (t) == ARRAY_REF
1150 209317 : || TREE_CODE (t) == COMPONENT_REF)
1151 : {
1152 106978 : comps[i] = t;
1153 106978 : t = TREE_OPERAND (t, 0);
1154 106978 : i++;
1155 : }
1156 :
1157 102339 : value_range tmp (type);
1158 102339 : bool res = range_from_readonly_load (tmp, type, ctor, comps, count);
1159 102339 : if (res)
1160 : {
1161 101159 : if (POINTER_TYPE_P (type))
1162 24866 : r.set_nonzero (type);
1163 : else
1164 76293 : r = tmp;
1165 : }
1166 102339 : return res;
1167 102339 : }
1168 :
1169 : // Calculate a range for phi statement S and return it in R.
1170 : // If a range cannot be calculated, return false.
1171 :
1172 : bool
1173 23856839 : fold_using_range::range_of_phi (vrange &r, gphi *phi, fur_source &src)
1174 : {
1175 23856839 : tree phi_def = gimple_phi_result (phi);
1176 23856839 : tree type = gimple_range_type (phi);
1177 23856839 : value_range arg_range (type);
1178 23856839 : value_range equiv_range (type);
1179 23856839 : unsigned x;
1180 :
1181 23856839 : if (!type)
1182 : return false;
1183 :
1184 : // Track if all executable arguments are the same.
1185 23856839 : tree single_arg = NULL_TREE;
1186 23856839 : bool seen_arg = false;
1187 :
1188 23856839 : relation_oracle *oracle = &(src.query()->relation ());
1189 : // Start with an empty range, unioning in each argument's range.
1190 23856839 : r.set_undefined ();
1191 61491162 : for (x = 0; x < gimple_phi_num_args (phi); x++)
1192 : {
1193 49178979 : tree arg = gimple_phi_arg_def (phi, x);
1194 : // An argument that is the same as the def provides no new range.
1195 49178979 : if (arg == phi_def)
1196 17593 : continue;
1197 :
1198 49161386 : edge e = gimple_phi_arg_edge (phi, x);
1199 :
1200 : // Get the range of the argument on its edge.
1201 49161386 : src.get_phi_operand (arg_range, arg, e);
1202 :
1203 49161386 : if (!arg_range.undefined_p ())
1204 : {
1205 : // Register potential dependencies for stale value tracking.
1206 : // Likewise, if the incoming PHI argument is equivalent to this
1207 : // PHI definition, it provides no new info. Accumulate these ranges
1208 : // in case all arguments are equivalences.
1209 48924143 : if (oracle->query (e, arg, phi_def) == VREL_EQ)
1210 218555 : equiv_range.union_(arg_range);
1211 : else
1212 48705588 : r.union_ (arg_range);
1213 :
1214 79505552 : if (gimple_range_ssa_p (arg) && src.gori_ssa ())
1215 30581403 : src.gori_ssa ()->register_dependency (phi_def, arg);
1216 : }
1217 :
1218 : // Track if all arguments are the same.
1219 49161386 : if (!seen_arg)
1220 : {
1221 : seen_arg = true;
1222 : single_arg = arg;
1223 : }
1224 25304547 : else if (!vrp_operand_equal_p (single_arg, arg))
1225 24156335 : single_arg = NULL_TREE;
1226 :
1227 : // Once the value reaches varying, stop looking.
1228 49161386 : if (r.varying_p () && single_arg == NULL_TREE)
1229 : break;
1230 : }
1231 :
1232 : // If all arguments were equivalences, use the equivalence ranges as no
1233 : // arguments were processed.
1234 23856839 : if (r.undefined_p () && !equiv_range.undefined_p ())
1235 73505 : r = equiv_range;
1236 :
1237 : // If the PHI boils down to a single effective argument, look at it.
1238 23856839 : if (single_arg)
1239 : {
1240 : // Symbolic arguments can be equivalences.
1241 2271445 : if (gimple_range_ssa_p (single_arg))
1242 : {
1243 : // Only allow the equivalence if the PHI definition does not
1244 : // dominate any incoming edge for SINGLE_ARG.
1245 : // See PR 108139 and 109462.
1246 1784470 : basic_block bb = gimple_bb (phi);
1247 1784470 : if (!dom_info_available_p (CDI_DOMINATORS))
1248 : single_arg = NULL;
1249 : else
1250 3776680 : for (x = 0; x < gimple_phi_num_args (phi); x++)
1251 1997278 : if (gimple_phi_arg_def (phi, x) == single_arg
1252 3985492 : && dominated_by_p (CDI_DOMINATORS,
1253 1988214 : gimple_phi_arg_edge (phi, x)->src,
1254 : bb))
1255 : {
1256 : single_arg = NULL;
1257 : break;
1258 : }
1259 1783501 : if (single_arg)
1260 1779402 : src.register_relation (phi, VREL_EQ, phi_def, single_arg);
1261 : }
1262 486975 : else if (src.get_operand (arg_range, single_arg))
1263 : {
1264 : // Check if the single argument points to a specific object.
1265 486975 : if (is_a <prange> (arg_range))
1266 : {
1267 44354 : prange &ptr = as_a <prange> (arg_range);
1268 : // If it doesn't already point at something, set points to.
1269 44354 : if (ptr.pt_unknown_p () && TREE_CODE (single_arg) == ADDR_EXPR)
1270 0 : ptr.set_pt (single_arg, true);
1271 44354 : r = ptr;
1272 44354 : return true;
1273 : }
1274 : // Numerical arguments that are a constant can be returned as
1275 : // the constant. This can help fold later cases where even this
1276 : // constant might have been UNDEFINED via an unreachable edge.
1277 442621 : if (arg_range.singleton_p ())
1278 : {
1279 440851 : r = arg_range;
1280 440851 : return true;
1281 : }
1282 : }
1283 : }
1284 :
1285 : // Incorporate any global value. If a PHI analysis phase was run, there may
1286 : // be a restricted global range already. Query the range with no context
1287 : // to get a global range.
1288 :
1289 : // If SCEV is available, query if this PHI has any known values.
1290 23371634 : if (scev_initialized_p ()
1291 23371634 : && !POINTER_TYPE_P (TREE_TYPE (phi_def)))
1292 : {
1293 9254879 : class loop *l = loop_containing_stmt (phi);
1294 9254879 : if (l && loop_outer (l))
1295 : {
1296 6793802 : value_range loop_range (type);
1297 6793802 : range_of_ssa_name_with_loop_info (loop_range, phi_def, l, phi, src);
1298 6793802 : if (!loop_range.varying_p ())
1299 : {
1300 1875855 : if (dump_file && (dump_flags & TDF_DETAILS))
1301 : {
1302 14229 : fprintf (dump_file, "Loops range found for ");
1303 14229 : print_generic_expr (dump_file, phi_def, TDF_SLIM);
1304 14229 : fprintf (dump_file, ": ");
1305 14229 : loop_range.dump (dump_file);
1306 14229 : fprintf (dump_file, " and calculated range :");
1307 14229 : r.dump (dump_file);
1308 14229 : fprintf (dump_file, "\n");
1309 : }
1310 1875855 : r.intersect (loop_range);
1311 : }
1312 6793802 : }
1313 : }
1314 :
1315 : return true;
1316 23856839 : }
1317 :
1318 : // Calculate a range for call statement S and return it in R.
1319 : // If a range cannot be calculated, return false.
1320 :
1321 : bool
1322 12678444 : fold_using_range::range_of_call (vrange &r, gcall *call, fur_source &)
1323 : {
1324 12678444 : tree type = gimple_range_type (call);
1325 12678444 : if (!type)
1326 : return false;
1327 :
1328 12678444 : tree lhs = gimple_call_lhs (call);
1329 :
1330 12678444 : if (gimple_stmt_nonnegative_p (call))
1331 45738 : r.set_nonnegative (type);
1332 12632706 : else if (gimple_call_nonnull_result_p (call)
1333 12632706 : || gimple_call_nonnull_arg (call))
1334 650964 : r.set_nonzero (type);
1335 : else
1336 11981742 : r.set_varying (type);
1337 :
1338 12678444 : tree callee = gimple_call_fndecl (call);
1339 12678444 : if (callee
1340 12678444 : && useless_type_conversion_p (TREE_TYPE (TREE_TYPE (callee)), type))
1341 : {
1342 11527917 : value_range val;
1343 11527917 : if (ipa_return_value_range (val, callee))
1344 : {
1345 605893 : r.intersect (val);
1346 605893 : if (dump_file && (dump_flags & TDF_DETAILS))
1347 : {
1348 28 : fprintf (dump_file, "Using return value range of ");
1349 28 : print_generic_expr (dump_file, callee, TDF_SLIM);
1350 28 : fprintf (dump_file, ": ");
1351 28 : val.dump (dump_file);
1352 28 : fprintf (dump_file, "\n");
1353 : }
1354 : }
1355 11527917 : }
1356 :
1357 : // If there is an LHS, intersect that with what is known.
1358 12678444 : if (gimple_range_ssa_p (lhs))
1359 : {
1360 12678444 : value_range def (TREE_TYPE (lhs));
1361 12678444 : gimple_range_global (def, lhs);
1362 12678444 : r.intersect (def);
1363 12678444 : }
1364 : return true;
1365 : }
1366 :
1367 : // Given COND ? OP1 : OP2 with ranges R1 for OP1 and R2 for OP2, Use gori
1368 : // to further resolve R1 and R2 if there are any dependencies between
1369 : // OP1 and COND or OP2 and COND. All values can are to be calculated using SRC
1370 : // as the origination source location for operands..
1371 : // Effectively, use COND an the edge condition and solve for OP1 on the true
1372 : // edge and OP2 on the false edge.
1373 :
1374 : bool
1375 151135 : fold_using_range::condexpr_adjust (vrange &r1, vrange &r2, gimple *, tree cond,
1376 : tree op1, tree op2, fur_source &src)
1377 : {
1378 151135 : if (!src.gori () || !src.gori_ssa ())
1379 : return false;
1380 :
1381 112041 : tree ssa1 = gimple_range_ssa_p (op1);
1382 112041 : tree ssa2 = gimple_range_ssa_p (op2);
1383 112041 : if (!ssa1 && !ssa2)
1384 : return false;
1385 100866 : if (TREE_CODE (cond) != SSA_NAME)
1386 : return false;
1387 225185 : gassign *cond_def = dyn_cast <gassign *> (SSA_NAME_DEF_STMT (cond));
1388 100749 : if (!cond_def
1389 100749 : || TREE_CODE_CLASS (gimple_assign_rhs_code (cond_def)) != tcc_comparison)
1390 : return false;
1391 96063 : tree type = TREE_TYPE (gimple_assign_rhs1 (cond_def));
1392 96063 : if (!value_range::supports_type_p (type)
1393 192122 : || !range_compatible_p (type, TREE_TYPE (gimple_assign_rhs2 (cond_def))))
1394 : return false;
1395 96059 : range_op_handler hand (gimple_assign_rhs_code (cond_def));
1396 96059 : if (!hand)
1397 : return false;
1398 :
1399 96059 : tree c1 = gimple_range_ssa_p (gimple_assign_rhs1 (cond_def));
1400 192118 : tree c2 = gimple_range_ssa_p (gimple_assign_rhs2 (cond_def));
1401 :
1402 : // Only solve if there is one SSA name in the condition.
1403 96059 : if ((!c1 && !c2) || (c1 && c2))
1404 : return false;
1405 :
1406 : // Pick up the current values of each part of the condition.
1407 26699 : tree rhs1 = gimple_assign_rhs1 (cond_def);
1408 26699 : tree rhs2 = gimple_assign_rhs2 (cond_def);
1409 26699 : value_range cl (TREE_TYPE (rhs1));
1410 26699 : value_range cr (TREE_TYPE (rhs2));
1411 26699 : src.get_operand (cl, rhs1);
1412 26699 : src.get_operand (cr, rhs2);
1413 :
1414 26699 : tree cond_name = c1 ? c1 : c2;
1415 26699 : gimple *def_stmt = SSA_NAME_DEF_STMT (cond_name);
1416 :
1417 : // Evaluate the value of COND_NAME on the true and false edges, using either
1418 : // the op1 or op2 routines based on its location.
1419 26699 : value_range cond_true (type), cond_false (type);
1420 26699 : if (c1)
1421 : {
1422 26699 : if (!hand.op1_range (cond_false, type, range_false (), cr))
1423 : return false;
1424 26699 : if (!hand.op1_range (cond_true, type, range_true (), cr))
1425 : return false;
1426 26699 : cond_false.intersect (cl);
1427 26699 : cond_true.intersect (cl);
1428 : }
1429 : else
1430 : {
1431 0 : if (!hand.op2_range (cond_false, type, range_false (), cl))
1432 : return false;
1433 0 : if (!hand.op2_range (cond_true, type, range_true (), cl))
1434 : return false;
1435 0 : cond_false.intersect (cr);
1436 0 : cond_true.intersect (cr);
1437 : }
1438 :
1439 : // Now solve for SSA1 or SSA2 if they are in the dependency chain.
1440 49014 : if (ssa1 && src.gori_ssa()->in_chain_p (ssa1, cond_name))
1441 : {
1442 913 : value_range tmp1 (TREE_TYPE (ssa1));
1443 1826 : if (src.gori ()->compute_operand_range (tmp1, def_stmt, cond_true,
1444 : ssa1, src))
1445 573 : r1.intersect (tmp1);
1446 913 : }
1447 44115 : if (ssa2 && src.gori_ssa ()->in_chain_p (ssa2, cond_name))
1448 : {
1449 246 : value_range tmp2 (TREE_TYPE (ssa2));
1450 492 : if (src.gori ()->compute_operand_range (tmp2, def_stmt, cond_false,
1451 : ssa2, src))
1452 198 : r2.intersect (tmp2);
1453 246 : }
1454 : // If the same name is specified in the condition and COND_EXPR,
1455 : // combine the calculated condition range and the other one provided. ie:
1456 : // c_1 = b_2 < 10
1457 : // f_3 = c_1 ? 0 : b_2
1458 : // With b_2 providing the false value, the value of f_3 will be
1459 : // either 0 UNION (0 = b_2 < 10), which is [-INF, 9].
1460 : // COND_EXPR is
1461 26699 : if (ssa1 && cond_name == ssa1)
1462 2148 : r1 = cond_true;
1463 24551 : else if (ssa2 && cond_name == ssa2)
1464 3001 : r2 = cond_false;
1465 : return true;
1466 26699 : }
1467 :
1468 : // Calculate a range for COND_EXPR statement S and return it in R.
1469 : // If a range cannot be calculated, return false.
1470 :
1471 : bool
1472 151135 : fold_using_range::range_of_cond_expr (vrange &r, gassign *s, fur_source &src)
1473 : {
1474 151135 : tree cond = gimple_assign_rhs1 (s);
1475 151135 : tree op1 = gimple_assign_rhs2 (s);
1476 151135 : tree op2 = gimple_assign_rhs3 (s);
1477 :
1478 151135 : tree type = gimple_range_type (s);
1479 151135 : if (!type)
1480 : return false;
1481 :
1482 151135 : value_range range1 (TREE_TYPE (op1));
1483 151135 : value_range range2 (TREE_TYPE (op2));
1484 151135 : value_range cond_range (TREE_TYPE (cond));
1485 151135 : gcc_checking_assert (gimple_assign_rhs_code (s) == COND_EXPR);
1486 151135 : gcc_checking_assert (range_compatible_p (TREE_TYPE (op1), TREE_TYPE (op2)));
1487 151135 : src.get_operand (cond_range, cond);
1488 151135 : src.get_operand (range1, op1);
1489 151135 : src.get_operand (range2, op2);
1490 :
1491 : // Try to see if there is a dependence between the COND and either operand
1492 151135 : if (condexpr_adjust (range1, range2, s, cond, op1, op2, src))
1493 26699 : if (dump_file && (dump_flags & TDF_DETAILS))
1494 : {
1495 559 : fprintf (dump_file, "Possible COND_EXPR adjustment. Range op1 : ");
1496 559 : range1.dump(dump_file);
1497 559 : fprintf (dump_file, " and Range op2: ");
1498 559 : range2.dump(dump_file);
1499 559 : fprintf (dump_file, "\n");
1500 : }
1501 :
1502 : // If the condition is known, choose the appropriate expression.
1503 151135 : if (cond_range.singleton_p ())
1504 : {
1505 : // False, pick second operand.
1506 2131 : if (cond_range.zero_p ())
1507 1075 : r = range2;
1508 : else
1509 1056 : r = range1;
1510 : }
1511 : else
1512 : {
1513 149004 : r = range1;
1514 149004 : r.union_ (range2);
1515 : }
1516 151135 : gcc_checking_assert (r.undefined_p ()
1517 : || range_compatible_p (r.type (), type));
1518 151135 : return true;
1519 151135 : }
1520 :
1521 : // If SCEV has any information about phi node NAME, return it as a range in R.
1522 :
1523 : void
1524 6793802 : fold_using_range::range_of_ssa_name_with_loop_info (vrange &r, tree name,
1525 : class loop *l, gphi *phi,
1526 : fur_source &src)
1527 : {
1528 6793802 : static bool in_scev_call = false;
1529 6793802 : gcc_checking_assert (TREE_CODE (name) == SSA_NAME);
1530 : // Avoid SCEV callbacks causing infinite recursion.
1531 6793802 : if (in_scev_call)
1532 392856 : r.set_varying (TREE_TYPE (name));
1533 : // SCEV currently invokes get_range_query () for values. If the query
1534 : // being passed in is not the same SCEV will use, do not invoke SCEV.
1535 : // This can be remove if/when SCEV uses a passed in range-query.
1536 12801892 : else if (src.query () != get_range_query (cfun))
1537 : {
1538 1714236 : r.set_varying (TREE_TYPE (name));
1539 : // Report the msmatch if SRC is not the global query. The cache
1540 : // uses a global query and would provide numerous false positives.
1541 132 : if (dump_file && (dump_flags & TDF_DETAILS)
1542 1714320 : && src.query () != get_global_range_query ())
1543 39 : fprintf (dump_file,
1544 : "fold_using-range:: SCEV not invoked due to mismatched queries\n");
1545 : }
1546 : else
1547 : {
1548 4686710 : in_scev_call = true;
1549 4686710 : if (!range_of_var_in_loop (r, name, l, phi, src.query ()))
1550 250 : r.set_varying (TREE_TYPE (name));
1551 4686710 : in_scev_call = false;
1552 : }
1553 6793802 : }
1554 :
1555 : // -----------------------------------------------------------------------
1556 :
1557 : // Check if an && or || expression can be folded based on relations. ie
1558 : // c_2 = a_6 > b_7
1559 : // c_3 = a_6 < b_7
1560 : // c_4 = c_2 && c_3
1561 : // c_2 and c_3 can never be true at the same time,
1562 : // Therefore c_4 can always resolve to false based purely on the relations.
1563 :
1564 : void
1565 134208889 : fold_using_range::relation_fold_and_or (irange& lhs_range, gimple *s,
1566 : fur_source &src, vrange &op1,
1567 : vrange &op2)
1568 : {
1569 : // No queries or already folded.
1570 134208889 : if (!src.gori () || lhs_range.singleton_p ())
1571 46419715 : return;
1572 :
1573 : // Only care about AND and OR expressions.
1574 87789174 : enum tree_code code = gimple_expr_code (s);
1575 87789174 : bool is_and = false;
1576 87789174 : if (code == BIT_AND_EXPR || code == TRUTH_AND_EXPR)
1577 : is_and = true;
1578 84174440 : else if (code != BIT_IOR_EXPR && code != TRUTH_OR_EXPR)
1579 : return;
1580 :
1581 5119703 : gimple_range_op_handler handler (s);
1582 5119703 : tree lhs = handler.lhs ();
1583 5119703 : tree ssa1 = gimple_range_ssa_p (handler.operand1 ());
1584 5119703 : tree ssa2 = gimple_range_ssa_p (handler.operand2 ());
1585 :
1586 : // Deal with || and && only when there is a full set of symbolics.
1587 5119517 : if (!lhs || !ssa1 || !ssa2
1588 2798383 : || (TREE_CODE (TREE_TYPE (lhs)) != BOOLEAN_TYPE)
1589 1958798 : || (TREE_CODE (TREE_TYPE (ssa1)) != BOOLEAN_TYPE)
1590 7077265 : || (TREE_CODE (TREE_TYPE (ssa2)) != BOOLEAN_TYPE))
1591 : return;
1592 :
1593 : // Now we know its a boolean AND or OR expression with boolean operands.
1594 : // Ideally we search dependencies for common names, and see what pops out.
1595 : // until then, simply try to resolve direct dependencies.
1596 :
1597 1954883 : gimple *ssa1_stmt = SSA_NAME_DEF_STMT (ssa1);
1598 1954883 : gimple *ssa2_stmt = SSA_NAME_DEF_STMT (ssa2);
1599 :
1600 1954883 : gimple_range_op_handler handler1 (ssa1_stmt);
1601 1954883 : gimple_range_op_handler handler2 (ssa2_stmt);
1602 :
1603 : // If either handler is not present, no relation can be found.
1604 1954883 : if (!handler1 || !handler2)
1605 124053 : return;
1606 :
1607 : // Both stmts will need to have 2 ssa names in the stmt.
1608 1830830 : tree ssa1_dep1 = gimple_range_ssa_p (handler1.operand1 ());
1609 1830830 : tree ssa1_dep2 = gimple_range_ssa_p (handler1.operand2 ());
1610 1830830 : tree ssa2_dep1 = gimple_range_ssa_p (handler2.operand1 ());
1611 1830830 : tree ssa2_dep2 = gimple_range_ssa_p (handler2.operand2 ());
1612 :
1613 1830830 : if (!ssa1_dep1 || !ssa1_dep2 || !ssa2_dep1 || !ssa2_dep2)
1614 : return;
1615 :
1616 222923 : if (HONOR_NANS (TREE_TYPE (ssa1_dep1)))
1617 : return;
1618 :
1619 : // Make sure they are the same dependencies, and detect the order of the
1620 : // relationship.
1621 207754 : bool reverse_op2 = true;
1622 207754 : if (ssa1_dep1 == ssa2_dep1 && ssa1_dep2 == ssa2_dep2)
1623 : reverse_op2 = false;
1624 207671 : else if (ssa1_dep1 != ssa2_dep2 || ssa1_dep2 != ssa2_dep1)
1625 : return;
1626 :
1627 88 : int_range<2> bool_one = range_true ();
1628 88 : relation_kind relation1 = handler1.op1_op2_relation (bool_one, op1, op2);
1629 88 : relation_kind relation2 = handler2.op1_op2_relation (bool_one, op1, op2);
1630 88 : if (relation1 == VREL_VARYING || relation2 == VREL_VARYING)
1631 : return;
1632 :
1633 52 : if (reverse_op2)
1634 5 : relation2 = relation_swap (relation2);
1635 :
1636 : // x && y is false if the relation intersection of the true cases is NULL.
1637 52 : if (is_and && relation_intersect (relation1, relation2) == VREL_UNDEFINED)
1638 0 : lhs_range = range_false (boolean_type_node);
1639 : // x || y is true if the union of the true cases is NO-RELATION..
1640 : // ie, one or the other being true covers the full range of possibilities.
1641 52 : else if (!is_and && relation_union (relation1, relation2) == VREL_VARYING)
1642 0 : lhs_range = bool_one;
1643 : else
1644 52 : return;
1645 :
1646 0 : range_cast (lhs_range, TREE_TYPE (lhs));
1647 0 : if (dump_file && (dump_flags & TDF_DETAILS))
1648 : {
1649 0 : fprintf (dump_file, " Relation adjustment: ");
1650 0 : print_generic_expr (dump_file, ssa1, TDF_SLIM);
1651 0 : fprintf (dump_file, " and ");
1652 0 : print_generic_expr (dump_file, ssa2, TDF_SLIM);
1653 0 : fprintf (dump_file, " combine to produce ");
1654 0 : lhs_range.dump (dump_file);
1655 0 : fputc ('\n', dump_file);
1656 : }
1657 :
1658 : return;
1659 88 : }
1660 :
1661 : // Register any outgoing edge relations from a conditional branch.
1662 :
1663 : void
1664 70346037 : fur_source::register_outgoing_edges (gcond *s, irange &lhs_range,
1665 : edge e0, edge e1)
1666 : {
1667 70346037 : int_range<2> e0_range, e1_range;
1668 70346037 : tree name;
1669 70346037 : basic_block bb = gimple_bb (s);
1670 :
1671 70346037 : gimple_range_op_handler handler (s);
1672 70346037 : if (!handler)
1673 : return;
1674 :
1675 70336403 : if (e0)
1676 : {
1677 : // If this edge is never taken, ignore it.
1678 58436591 : gcond_edge_range (e0_range, e0);
1679 58436591 : e0_range.intersect (lhs_range);
1680 58436591 : if (e0_range.undefined_p ())
1681 25865550 : e0 = NULL;
1682 : }
1683 :
1684 70336403 : if (e1)
1685 : {
1686 : // If this edge is never taken, ignore it.
1687 51292523 : gcond_edge_range (e1_range, e1);
1688 51292523 : e1_range.intersect (lhs_range);
1689 51292523 : if (e1_range.undefined_p ())
1690 29348762 : e1 = NULL;
1691 : }
1692 :
1693 70336403 : if (!e0 && !e1)
1694 : return;
1695 :
1696 : // First, register the gcond itself. This will catch statements like
1697 : // if (a_2 < b_5)
1698 67151301 : tree ssa1 = gimple_range_ssa_p (handler.operand1 ());
1699 67151301 : tree ssa2 = gimple_range_ssa_p (handler.operand2 ());
1700 67151301 : value_range r1,r2;
1701 67151301 : if (ssa1 && ssa2)
1702 : {
1703 19900530 : r1.set_varying (TREE_TYPE (ssa1));
1704 19900530 : r2.set_varying (TREE_TYPE (ssa2));
1705 19900530 : if (e0)
1706 : {
1707 13369217 : relation_kind relation = handler.op1_op2_relation (e0_range, r1, r2);
1708 13369217 : if (relation != VREL_VARYING)
1709 13293652 : register_relation (e0, relation, ssa1, ssa2);
1710 : }
1711 19900530 : if (e1)
1712 : {
1713 11625440 : relation_kind relation = handler.op1_op2_relation (e1_range, r1, r2);
1714 11625440 : if (relation != VREL_VARYING)
1715 11565392 : register_relation (e1, relation, ssa1, ssa2);
1716 : }
1717 : }
1718 :
1719 : // Outgoing relations of GORI exports require a gori engine.
1720 121478745 : if (!gori_ssa ())
1721 12823869 : return;
1722 :
1723 : // Now look for other relations in the exports. This will find stmts
1724 : // leading to the condition such as:
1725 : // c_2 = a_4 < b_7
1726 : // if (c_2)
1727 172591073 : FOR_EACH_GORI_EXPORT_NAME (gori_ssa (), bb, name)
1728 : {
1729 118263641 : if (TREE_CODE (TREE_TYPE (name)) != BOOLEAN_TYPE)
1730 112551600 : continue;
1731 9297303 : gimple *stmt = SSA_NAME_DEF_STMT (name);
1732 9297303 : gimple_range_op_handler handler (stmt);
1733 9297303 : if (!handler)
1734 3585262 : continue;
1735 5712041 : tree ssa1 = gimple_range_ssa_p (handler.operand1 ());
1736 5712041 : tree ssa2 = gimple_range_ssa_p (handler.operand2 ());
1737 5712041 : value_range r (TREE_TYPE (name));
1738 5712041 : if (ssa1 && ssa2)
1739 : {
1740 2433806 : r1.set_varying (TREE_TYPE (ssa1));
1741 2433806 : r2.set_varying (TREE_TYPE (ssa2));
1742 1474830 : if (e0 && gori ()->edge_range_p (r, e0, name, *m_query)
1743 3874166 : && r.singleton_p ())
1744 : {
1745 1310027 : relation_kind relation = handler.op1_op2_relation (r, r1, r2);
1746 1310027 : if (relation != VREL_VARYING)
1747 428087 : register_relation (e0, relation, ssa1, ssa2);
1748 : }
1749 1559829 : if (e1 && gori ()->edge_range_p (r, e1, name, *m_query)
1750 3946835 : && r.singleton_p ())
1751 : {
1752 1128305 : relation_kind relation = handler.op1_op2_relation (r, r1, r2);
1753 1128305 : if (relation != VREL_VARYING)
1754 166463 : register_relation (e1, relation, ssa1, ssa2);
1755 : }
1756 : }
1757 5712041 : }
1758 70346037 : }
|