LCOV - code coverage report
Current view: top level - gcc - range-op-ptr.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 86.2 % 513 442
Test Date: 2026-11-14 16:39:50 Functions: 79.5 % 78 62
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Code for range operators.
       2              :    Copyright (C) 2017-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 "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              : bool
      53            0 : range_operator::fold_range (prange &, tree, const prange &, const prange &,
      54              :                             relation_trio) const
      55              : {
      56            0 :   return false;
      57              : }
      58              : 
      59              : bool
      60            0 : range_operator::fold_range (prange &, tree, const prange &, const irange &,
      61              :                             relation_trio) const
      62              : {
      63            0 :   return false;
      64              : }
      65              : 
      66              : bool
      67            0 : range_operator::fold_range (irange &, tree, const prange &, const prange &,
      68              :                             relation_trio) const
      69              : {
      70            0 :   return false;
      71              : }
      72              : 
      73              : bool
      74            0 : range_operator::fold_range (prange &, tree, const irange &, const prange &,
      75              :                             relation_trio) const
      76              : {
      77            0 :   return false;
      78              : }
      79              : 
      80              : bool
      81          369 : range_operator::fold_range (irange &, tree, const prange &, const irange &,
      82              :                             relation_trio) const
      83              : {
      84          369 :   return false;
      85              : }
      86              : 
      87              : bool
      88            0 : range_operator::op1_op2_relation_effect (prange &, tree,
      89              :                                          const prange &,
      90              :                                          const prange &,
      91              :                                          relation_kind) const
      92              : {
      93            0 :   return false;
      94              : }
      95              : 
      96              : bool
      97            0 : range_operator::op1_op2_relation_effect (prange &, tree,
      98              :                                          const prange &,
      99              :                                          const irange &,
     100              :                                          relation_kind) const
     101              : {
     102            0 :   return false;
     103              : }
     104              : 
     105              : bool
     106            0 : range_operator::op1_op2_relation_effect (irange &, tree,
     107              :                                          const prange &,
     108              :                                          const prange &,
     109              :                                          relation_kind) const
     110              : {
     111            0 :   return false;
     112              : }
     113              : 
     114              : bool
     115            0 : range_operator::op1_op2_relation_effect (prange &, tree,
     116              :                                          const irange &,
     117              :                                          const prange &,
     118              :                                          relation_kind) const
     119              : {
     120            0 :   return false;
     121              : }
     122              : 
     123              : bool
     124            0 : range_operator::op1_op2_relation_effect (irange &, tree,
     125              :                                          const prange &,
     126              :                                          const irange &,
     127              :                                          relation_kind) const
     128              : {
     129            0 :   return false;
     130              : }
     131              : 
     132              : bool
     133          202 : range_operator::op1_range (prange &, tree,
     134              :                            const prange &lhs ATTRIBUTE_UNUSED,
     135              :                            const prange &op2 ATTRIBUTE_UNUSED,
     136              :                            relation_trio) const
     137              : {
     138          202 :   return false;
     139              : }
     140              : 
     141              : bool
     142      2514824 : range_operator::op1_range (prange &, tree,
     143              :                            const irange &lhs ATTRIBUTE_UNUSED,
     144              :                            const prange &op2 ATTRIBUTE_UNUSED,
     145              :                            relation_trio) const
     146              : {
     147      2514824 :   return false;
     148              : }
     149              : 
     150              : bool
     151       408290 : range_operator::op1_range (prange &, tree,
     152              :                            const prange &lhs ATTRIBUTE_UNUSED,
     153              :                            const irange &op2 ATTRIBUTE_UNUSED,
     154              :                            relation_trio) const
     155              : {
     156       408290 :   return false;
     157              : }
     158              : 
     159              : bool
     160            0 : range_operator::op1_range (irange &, tree,
     161              :                            const prange &lhs ATTRIBUTE_UNUSED,
     162              :                            const irange &op2 ATTRIBUTE_UNUSED,
     163              :                            relation_trio) const
     164              : {
     165            0 :   return false;
     166              : }
     167              : 
     168              : bool
     169      2841799 : range_operator::op2_range (prange &, tree,
     170              :                            const irange &lhs ATTRIBUTE_UNUSED,
     171              :                            const prange &op1 ATTRIBUTE_UNUSED,
     172              :                            relation_trio) const
     173              : {
     174      2841799 :   return false;
     175              : }
     176              : 
     177              : bool
     178            0 : range_operator::op2_range (irange &, tree,
     179              :                            const prange &lhs ATTRIBUTE_UNUSED,
     180              :                            const prange &op1 ATTRIBUTE_UNUSED,
     181              :                            relation_trio) const
     182              : {
     183            0 :   return false;
     184              : }
     185              : 
     186              : relation_kind
     187            0 : range_operator::op1_op2_relation (const irange &lhs ATTRIBUTE_UNUSED,
     188              :                                   const prange &op1 ATTRIBUTE_UNUSED,
     189              :                                   const prange &op2 ATTRIBUTE_UNUSED) const
     190              : {
     191            0 :   return VREL_VARYING;
     192              : }
     193              : 
     194              : relation_kind
     195            0 : range_operator::lhs_op1_relation (const prange &lhs ATTRIBUTE_UNUSED,
     196              :                                   const irange &op1 ATTRIBUTE_UNUSED,
     197              :                                   const irange &op2 ATTRIBUTE_UNUSED,
     198              :                                   relation_kind rel ATTRIBUTE_UNUSED) const
     199              : {
     200            0 :   return VREL_VARYING;
     201              : }
     202              : 
     203              : relation_kind
     204      4466830 : range_operator::lhs_op1_relation (const irange &lhs ATTRIBUTE_UNUSED,
     205              :                                   const prange &op1 ATTRIBUTE_UNUSED,
     206              :                                   const prange &op2 ATTRIBUTE_UNUSED,
     207              :                                   relation_kind rel ATTRIBUTE_UNUSED) const
     208              : {
     209      4466830 :   return VREL_VARYING;
     210              : }
     211              : 
     212              : relation_kind
     213        78128 : range_operator::lhs_op1_relation (const prange &lhs ATTRIBUTE_UNUSED,
     214              :                                   const prange &op1 ATTRIBUTE_UNUSED,
     215              :                                   const prange &op2 ATTRIBUTE_UNUSED,
     216              :                                   relation_kind rel ATTRIBUTE_UNUSED) const
     217              : {
     218        78128 :   return VREL_VARYING;
     219              : }
     220              : 
     221              : relation_kind
     222            0 : range_operator::lhs_op1_relation (const prange &lhs ATTRIBUTE_UNUSED,
     223              :                                   const prange &op1 ATTRIBUTE_UNUSED,
     224              :                                   const irange &op2 ATTRIBUTE_UNUSED,
     225              :                                   relation_kind rel ATTRIBUTE_UNUSED) const
     226              : {
     227            0 :   return VREL_VARYING;
     228              : }
     229              : 
     230              : void
     231            0 : range_operator::update_bitmask (irange &,
     232              :                                 const prange &,
     233              :                                 const prange &) const
     234              : {
     235            0 : }
     236              : 
     237              : // Return the upper limit for a type.
     238              : 
     239              : static inline wide_int
     240       871137 : max_limit (const_tree type)
     241              : {
     242       871137 :   return wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type));
     243              : }
     244              : 
     245              : // Return the lower limit for a type.
     246              : 
     247              : static inline wide_int
     248       885394 : min_limit (const_tree type)
     249              : {
     250       885394 :   return wi::min_value (TYPE_PRECISION (type), TYPE_SIGN (type));
     251              : }
     252              : 
     253              : // Build a range that is < VAL and store it in R.
     254              : 
     255              : static void
     256       533635 : build_lt (prange &r, tree type, const prange &val)
     257              : {
     258       533635 :   wi::overflow_type ov;
     259       533635 :   wide_int lim = wi::sub (val.upper_bound (), 1, UNSIGNED, &ov);
     260              : 
     261              :   // If val - 1 underflows, check if X < MIN, which is an empty range.
     262       533635 :   if (ov)
     263            0 :     r.set_undefined ();
     264              :   else
     265       533635 :     r.set (type, min_limit (type), lim);
     266       533635 : }
     267              : 
     268              : // Build a range that is <= VAL and store it in R.
     269              : 
     270              : static void
     271       351759 : build_le (prange &r, tree type, const prange &val)
     272              : {
     273       351759 :   r.set (type, min_limit (type), val.upper_bound ());
     274       351759 : }
     275              : 
     276              : // Build a range that is > VAL and store it in R.
     277              : 
     278              : static void
     279       455316 : build_gt (prange &r, tree type, const prange &val)
     280              : {
     281       455316 :   wi::overflow_type ov;
     282       455316 :   wide_int lim = wi::add (val.lower_bound (), 1, UNSIGNED, &ov);
     283              : 
     284              :   // If val + 1 overflows, check is for X > MAX, which is an empty range.
     285       455316 :   if (ov)
     286            0 :     r.set_undefined ();
     287              :   else
     288       455316 :     r.set (type, lim, max_limit (type));
     289              : 
     290       455316 : }
     291              : 
     292              : // Build a range that is >= VAL and store it in R.
     293              : 
     294              : static void
     295       415821 : build_ge (prange &r, tree type, const prange &val)
     296              : {
     297       415821 :   r.set (type, val.lower_bound (), max_limit (type));
     298       415821 : }
     299              : 
     300              : class pointer_plus_operator : public range_operator
     301              : {
     302              :   using range_operator::update_bitmask;
     303              :   using range_operator::fold_range;
     304              :   using range_operator::op2_range;
     305              :   using range_operator::lhs_op1_relation;
     306              : public:
     307              :   virtual bool fold_range (prange &r, tree type,
     308              :                            const prange &op1,
     309              :                            const irange &op2,
     310              :                            relation_trio) const final override;
     311              :   virtual bool op2_range (irange &r, tree type,
     312              :                           const prange &lhs,
     313              :                           const prange &op1,
     314              :                           relation_trio = TRIO_VARYING) const final override;
     315              :   virtual relation_kind lhs_op1_relation (const prange &lhs,
     316              :                                           const prange &op1,
     317              :                                           const irange &op2,
     318              :                                           relation_kind) const final override;
     319              :   void update_bitmask (prange &r, const prange &lh, const irange &rh) const
     320              :     { update_known_bitmask (r, POINTER_PLUS_EXPR, lh, rh); }
     321              : };
     322              : static const pointer_plus_operator op_pointer_plus;
     323              : 
     324              : bool
     325      9100718 : pointer_plus_operator::fold_range (prange &r, tree type,
     326              :                                    const prange &op1,
     327              :                                    const irange &op2,
     328              :                                    relation_trio) const
     329              : {
     330      9100718 :   if (empty_range_varying (r, type, op1, op2))
     331         6516 :     return true;
     332              : 
     333      9094202 :   const wide_int lh_lb = op1.lower_bound ();
     334      9094202 :   const wide_int lh_ub = op1.upper_bound ();
     335      9094202 :   const wide_int rh_lb = op2.lower_bound ();
     336      9094202 :   const wide_int rh_ub = op2.upper_bound ();
     337              : 
     338              :   // Check for [0,0] + const, and simply return the const.
     339      9102152 :   if (lh_lb == 0 && lh_ub == 0 && rh_lb == rh_ub)
     340              :     {
     341          565 :       r.set (type, rh_lb, rh_lb);
     342          565 :       return true;
     343              :     }
     344              : 
     345              :   // For pointer types, we are really only interested in asserting
     346              :   // whether the expression evaluates to non-NULL.
     347              :   //
     348              :   // With -fno-delete-null-pointer-checks we need to be more
     349              :   // conservative.  As some object might reside at address 0,
     350              :   // then some offset could be added to it and the same offset
     351              :   // subtracted again and the result would be NULL.
     352              :   // E.g.
     353              :   // static int a[12]; where &a[0] is NULL and
     354              :   // ptr = &a[6];
     355              :   // ptr -= 6;
     356              :   // ptr will be NULL here, even when there is POINTER_PLUS_EXPR
     357              :   // where the first range doesn't include zero and the second one
     358              :   // doesn't either.  As the second operand is sizetype (unsigned),
     359              :   // consider all ranges where the MSB could be set as possible
     360              :   // subtractions where the result might be NULL.
     361      9093637 :   if ((!wi_includes_zero_p (type, lh_lb, lh_ub)
     362      5367672 :        || !wi_includes_zero_p (type, rh_lb, rh_ub))
     363      5945933 :       && !TYPE_OVERFLOW_WRAPS (type)
     364     15038740 :       && (flag_delete_null_pointer_checks
     365         1191 :           || !wi::sign_mask (rh_ub)))
     366      5944712 :     r.set_nonzero (type);
     367      3155549 :   else if (lh_lb == lh_ub && lh_lb == 0
     368      3155549 :            && rh_lb == rh_ub && rh_lb == 0)
     369            0 :     r.set_zero (type);
     370              :   else
     371      3148925 :    r.set_varying (type);
     372              : 
     373              :   // If op1 refers to an object, op1 + 0 will also refer to the object.
     374      9093637 :   if (rh_lb == rh_ub && rh_lb == 0)
     375        22972 :     r.set_addr (op1);
     376              : 
     377      9093637 :   update_known_bitmask (r, POINTER_PLUS_EXPR, op1, op2);
     378      9093637 :   return true;
     379      9094202 : }
     380              : 
     381              : bool
     382       352385 : pointer_plus_operator::op2_range (irange &r, tree type,
     383              :                                   const prange &lhs,
     384              :                                   const prange &op1,
     385              :                                   relation_trio trio) const
     386              : {
     387       352385 :   relation_kind rel = trio.lhs_op1 ();
     388       352385 :   r.set_varying (type);
     389              : 
     390              :   // If the LHS and OP1 are equal, the op2 must be zero.
     391       352385 :   if (rel == VREL_EQ || lhs.addr_same_known_p (op1))
     392          156 :     r.set_zero (type);
     393              :   // If the LHS and OP1 are not equal, the offset must be non-zero.
     394              :   // AWM: Check if aliasing may mean we can't do the not_equal check.
     395       352229 :   else if (rel == VREL_NE || lhs.addr_inverted_p (op1))
     396          527 :     r.set_nonzero (type);
     397              :   else
     398              :     return false;
     399              :   return true;
     400              : }
     401              : 
     402              : // Return the relation between the LHS and OP1 based on the value of the
     403              : // operand being added.  Pointer_plus is define to have a size_type for
     404              : // operand 2 which can be interpreted as negative, so always used SIGNED.
     405              : // Any overflow is considered UB and thus ignored.
     406              : 
     407              : relation_kind
     408      7883414 : pointer_plus_operator::lhs_op1_relation (const prange &lhs,
     409              :                                          const prange &op1,
     410              :                                          const irange &op2,
     411              :                                          relation_kind) const
     412              : {
     413      7883414 :   if (lhs.undefined_p () || op1.undefined_p () || op2.undefined_p ())
     414              :     return VREL_VARYING;
     415              : 
     416      7877252 :   unsigned prec = TYPE_PRECISION (op2.type ());
     417              : 
     418              :   // LHS = OP1 + 0  indicates LHS == OP1.
     419      7877252 :   if (op2.zero_p ())
     420              :     return VREL_EQ;
     421              : 
     422      7856611 :   tree val;
     423              :   // Only deal with singletons for now.
     424      7856611 :   if (TYPE_OVERFLOW_UNDEFINED (lhs.type ()) && op2.singleton_p (&val))
     425              :     {
     426              :       // Always interpret VALUE as a signed value.  Positive will increase
     427              :       // the pointer value, and negative will decrease the poiinter value.
     428              :       // It cannot be zero or the earlier zero_p () condition will catch it.
     429      3889319 :       wide_int value = wi::to_wide (val);
     430              : 
     431              :       // Positive op2 means lhs > op1.
     432      3889319 :       if (wi::gt_p (value, wi::zero (prec), SIGNED))
     433              :         return VREL_GT;
     434              : 
     435              :       // Negative op2 means lhs < op1.
     436       441399 :       if (wi::lt_p (value, wi::zero (prec), SIGNED))
     437              :         return VREL_LT;
     438      3889319 :     }
     439              : 
     440              :   // If op2 does not contain 0, then LHS and OP1 can never be equal.
     441      3967292 :   if (!range_includes_zero_p (op2))
     442       552425 :     return VREL_NE;
     443              : 
     444              :   return VREL_VARYING;
     445              : }
     446              : 
     447              : bool
     448            0 : operator_bitwise_or::fold_range (prange &r, tree type,
     449              :                                  const prange &op1,
     450              :                                  const prange &op2,
     451              :                                  relation_trio) const
     452              : {
     453              :   // For pointer types, we are really only interested in asserting
     454              :   // whether the expression evaluates to non-NULL.
     455            0 :   if (!range_includes_zero_p (op1) || !range_includes_zero_p (op2))
     456            0 :     r.set_nonzero (type);
     457            0 :   else if (op1.zero_p () && op2.zero_p ())
     458            0 :     r.set_zero (type);
     459              :   else
     460            0 :     r.set_varying (type);
     461              : 
     462            0 :   update_known_bitmask (r, BIT_IOR_EXPR, op1, op2);
     463            0 :   return true;
     464              : }
     465              : 
     466              : 
     467              : class operator_pointer_diff : public range_operator
     468              : {
     469              :   using range_operator::fold_range;
     470              :   using range_operator::update_bitmask;
     471              :   using range_operator::op1_op2_relation_effect;
     472              :   using range_operator::op1_op2_relation;
     473              :   virtual bool fold_range (irange &r, tree type,
     474              :                            const prange &op1,
     475              :                            const prange &op2,
     476              :                            relation_trio trio) const final override;
     477              :   virtual bool op1_op2_relation_effect (irange &lhs_range,
     478              :                                         tree type,
     479              :                                         const prange &op1_range,
     480              :                                         const prange &op2_range,
     481              :                                         relation_kind rel) const final override;
     482              :   virtual relation_kind op1_op2_relation (const irange &lhs,
     483              :                                           const prange &rhs1,
     484              :                                           const prange &rhs2) const final override;
     485      3193822 :   void update_bitmask (irange &r,
     486              :                        const prange &lh, const prange &rh) const final override
     487            0 :   { update_known_bitmask (r, POINTER_DIFF_EXPR, lh, rh); }
     488              : };
     489              : static const operator_pointer_diff op_pointer_diff;
     490              : 
     491              : bool
     492      3193822 : operator_pointer_diff::fold_range (irange &r, tree type,
     493              :                                    const prange &op1,
     494              :                                    const prange &op2,
     495              :                                    relation_trio trio) const
     496              : {
     497      3193822 :   gcc_checking_assert (r.supports_type_p (type));
     498              : 
     499      3193822 :   r.set_varying (type);
     500      3193822 :   relation_kind rel = trio.op1_op2 ();
     501      3193822 :   op1_op2_relation_effect (r, type, op1, op2, rel);
     502              :   // if op1 and op2 point to the same object, the diff is 0.
     503      3193822 :   if (op1.addr_same_known_p (op2))
     504          774 :     r.set_zero (type);
     505      3193822 :   update_bitmask (r, op1, op2);
     506      3193822 :   return true;
     507              : }
     508              : 
     509              : bool
     510      3193822 : operator_pointer_diff::op1_op2_relation_effect (irange &lhs_range, tree type,
     511              :                                                 const prange &op1_range,
     512              :                                                 const prange &op2_range,
     513              :                                                 relation_kind rel) const
     514              : {
     515      3193822 :   int_range<2> op1, op2, tmp;
     516      3193822 :   range_op_handler cast (CONVERT_EXPR);
     517              : 
     518      3193822 :   if (!cast.fold_range (op1, type, op1_range, tmp)
     519      3193822 :       || !cast.fold_range (op2, type, op2_range, tmp))
     520              :     return false;
     521              : 
     522      3193822 :   return minus_op1_op2_relation_effect (lhs_range, type, op1, op2, rel);
     523      3193822 : }
     524              : 
     525              : 
     526              : // Check if the LHS range indicates a relation between OP1 and OP2.
     527              : // OP1 - OP2 == 0 implies OP1 == OP2 even with wrapping arithmetic.
     528              : // For signed types, when both OP1 and OP2 are both positive, infer
     529              : // a relationship if there were it is overflow free.
     530              : 
     531              : relation_kind
     532      7044921 : operator_pointer_diff::op1_op2_relation (const irange &lhs, const prange &rhs1,
     533              :                                          const prange &) const
     534              : {
     535      7044921 :   if (lhs.undefined_p ())
     536              :     return VREL_UNDEFINED;
     537              : 
     538      7044921 :   if (lhs.zero_p ())
     539              :     return VREL_EQ;
     540              : 
     541      6809603 :   bool contains_z = lhs.contains_zero_p ();
     542              :   // When a - b does not overflow and signed,
     543              :   // we can figure out the relationship between
     544              :   // a and b if the result is non-negative or non-positive.
     545      6809603 :   if (TYPE_OVERFLOW_UNDEFINED (rhs1.type ()))
     546              :     {
     547      6809603 :       if (lhs.nonnegative_p ())
     548      3599748 :         return contains_z ? VREL_GE : VREL_GT;
     549      3209855 :       if (lhs.nonpositive_p ())
     550       493879 :         return contains_z ? VREL_LE : VREL_LT;
     551              :     }
     552              : 
     553      2715976 :   if (!contains_z)
     554       883352 :     return VREL_NE;
     555              : 
     556              :   return VREL_VARYING;
     557              : }
     558              : 
     559              : bool
     560      2180213 : operator_identity::fold_range (prange &r, tree type ATTRIBUTE_UNUSED,
     561              :                                const prange &lh ATTRIBUTE_UNUSED,
     562              :                                const prange &rh ATTRIBUTE_UNUSED,
     563              :                                relation_trio) const
     564              : {
     565      2180213 :   r = lh;
     566      2180213 :   return true;
     567              : }
     568              : 
     569              : relation_kind
     570      2021585 : operator_identity::lhs_op1_relation (const prange &lhs,
     571              :                                      const prange &op1 ATTRIBUTE_UNUSED,
     572              :                                      const prange &op2 ATTRIBUTE_UNUSED,
     573              :                                      relation_kind) const
     574              : {
     575      2021585 :   if (lhs.undefined_p ())
     576          812 :     return VREL_VARYING;
     577              :   // Simply a copy, so they are equivalent.
     578              :   return VREL_EQ;
     579              : }
     580              : 
     581              : bool
     582       189896 : operator_identity::op1_range (prange &r, tree type ATTRIBUTE_UNUSED,
     583              :                               const prange &lhs,
     584              :                               const prange &op2 ATTRIBUTE_UNUSED,
     585              :                               relation_trio) const
     586              : {
     587       189896 :   r = lhs;
     588       189896 :   return true;
     589              : }
     590              : 
     591              : bool
     592        78589 : operator_cst::fold_range (prange &r, tree type ATTRIBUTE_UNUSED,
     593              :                           const prange &lh,
     594              :                           const prange & ATTRIBUTE_UNUSED,
     595              :                           relation_trio) const
     596              : {
     597        78589 :   r = lh;
     598        78589 :   return true;
     599              : }
     600              : 
     601              : // Cast between pointers.
     602              : 
     603              : bool
     604     16792902 : operator_cast::fold_range (prange &r, tree type,
     605              :                            const prange &inner,
     606              :                            const prange &outer,
     607              :                            relation_trio) const
     608              : {
     609     16792902 :   if (empty_range_varying (r, type, inner, outer))
     610          437 :     return true;
     611              : 
     612     16792465 :   r.set (type, inner.lower_bound (), inner.upper_bound ());
     613              : 
     614              :   // The resulting pointer still points to the same object.
     615     16792465 :   r.set_addr (inner);
     616              : 
     617     16792465 :   r.update_bitmask (inner.get_bitmask ());
     618     16792465 :   return true;
     619              : }
     620              : 
     621              : // Cast a pointer to an integer.
     622              : 
     623              : bool
     624     12540805 : operator_cast::fold_range (irange &r, tree type,
     625              :                            const prange &inner,
     626              :                            const irange &outer,
     627              :                            relation_trio) const
     628              : {
     629     12540805 :   if (empty_range_varying (r, type, inner, outer))
     630      6389176 :     return true;
     631              : 
     632              :   // Represent INNER as an integer of the same size, and then cast it
     633              :   // to the resulting integer type.
     634      6151629 :   tree pointer_uint_type = make_unsigned_type (TYPE_PRECISION (inner.type ()));
     635      6151629 :   r.set (pointer_uint_type, inner.lower_bound (), inner.upper_bound ());
     636      6151629 :   r.update_bitmask (inner.get_bitmask ());
     637      6151629 :   range_cast (r, type);
     638      6151629 :   return true;
     639              : }
     640              : 
     641              : // Cast an integer to a pointer.
     642              : 
     643              : bool
     644      1927453 : operator_cast::fold_range (prange &r, tree type,
     645              :                            const irange &inner,
     646              :                            const prange &outer,
     647              :                            relation_trio) const
     648              : {
     649      1927453 :   if (empty_range_varying (r, type, inner, outer))
     650         1761 :     return true;
     651              : 
     652              :   // Cast INNER to an integer of the same size as the pointer we want,
     653              :   // and then copy the bounds to the resulting pointer range.
     654      1925692 :   int_range<2> tmp = inner;
     655      1925692 :   tree pointer_uint_type = make_unsigned_type (TYPE_PRECISION (type));
     656      1925692 :   range_cast (tmp, pointer_uint_type);
     657              :   // Casts may cause ranges to become UNDEFINED based on bitmasks.
     658      1925692 :   if (tmp.undefined_p ())
     659            0 :     r.set_varying (type);
     660              :   else
     661              :     {
     662      1925692 :       r.set (type, tmp.lower_bound (), tmp.upper_bound ());
     663      1925692 :       r.update_bitmask (tmp.get_bitmask ());
     664              :     }
     665      1925692 :   return true;
     666      1925692 : }
     667              : 
     668              : bool
     669           69 : operator_cast::op1_range (prange &r, tree type,
     670              :                           const prange &lhs,
     671              :                           const prange &op2,
     672              :                           relation_trio trio) const
     673              : {
     674           69 :   if (lhs.undefined_p ())
     675              :     return false;
     676           69 :   gcc_checking_assert (types_compatible_p (op2.type(), type));
     677              : 
     678              :   // Conversion from other pointers or a constant (including 0/NULL)
     679              :   // are straightforward.
     680           69 :   if (POINTER_TYPE_P (lhs.type ())
     681           69 :       || (lhs.singleton_p ()
     682            0 :           && TYPE_PRECISION (lhs.type ()) >= TYPE_PRECISION (type)))
     683           69 :     fold_range (r, type, lhs, op2, trio);
     684              :   else
     685              :     {
     686              :       // If the LHS is not a pointer nor a singleton, then it is
     687              :       // either VARYING or non-zero.
     688            0 :       if (!lhs.undefined_p () && !range_includes_zero_p (lhs))
     689            0 :         r.set_nonzero (type);
     690              :       else
     691            0 :         r.set_varying (type);
     692              :     }
     693           69 :   r.intersect (op2);
     694           69 :   return true;
     695              : }
     696              : 
     697              : bool
     698       353660 : operator_cast::op1_range (irange &r, tree type,
     699              :                           const prange &lhs,
     700              :                           const irange &op2,
     701              :                           relation_trio trio) const
     702              : {
     703       353660 :   if (lhs.undefined_p ())
     704              :     return false;
     705       353660 :   gcc_checking_assert (types_compatible_p (op2.type(), type));
     706              : 
     707              :   // Conversion from other pointers or a constant (including 0/NULL)
     708              :   // are straightforward.
     709       353670 :   if (POINTER_TYPE_P (lhs.type ())
     710       353660 :       || (lhs.singleton_p ()
     711            0 :           && TYPE_PRECISION (lhs.type ()) >= TYPE_PRECISION (type)))
     712       353660 :     fold_range (r, type, lhs, op2, trio);
     713              :   else
     714              :     {
     715              :       // If the LHS is not a pointer nor a singleton, then it is
     716              :       // either VARYING or non-zero.
     717            0 :       if (!lhs.undefined_p () && !range_includes_zero_p (lhs))
     718            0 :         r.set_nonzero (type);
     719              :       else
     720            0 :         r.set_varying (type);
     721              :     }
     722       353660 :   r.intersect (op2);
     723       353660 :   return true;
     724              : }
     725              : 
     726              : bool
     727       620380 : operator_cast::op1_range (prange &r, tree type,
     728              :                           const irange &lhs,
     729              :                           const prange &op2,
     730              :                           relation_trio trio) const
     731              : {
     732       620380 :   if (lhs.undefined_p ())
     733              :     return false;
     734       620380 :   gcc_checking_assert (types_compatible_p (op2.type(), type));
     735              : 
     736              :   // Conversion from other pointers or a constant (including 0/NULL)
     737              :   // are straightforward.
     738      1240760 :   if (POINTER_TYPE_P (lhs.type ())
     739      1240760 :       || (lhs.singleton_p ()
     740         1710 :           && TYPE_PRECISION (lhs.type ()) >= TYPE_PRECISION (type)))
     741         1704 :     fold_range (r, type, lhs, op2, trio);
     742              :   else
     743              :     {
     744              :       // If the LHS is not a pointer nor a singleton, then it is
     745              :       // either VARYING or non-zero.
     746       618676 :       if (!lhs.undefined_p () && !range_includes_zero_p (lhs))
     747       301492 :         r.set_nonzero (type);
     748              :       else
     749       317184 :         r.set_varying (type);
     750              :     }
     751       620380 :   r.intersect (op2);
     752       620380 :   return true;
     753              : }
     754              : 
     755              : relation_kind
     756       137325 : operator_cast::lhs_op1_relation (const prange &lhs,
     757              :                                  const prange &op1,
     758              :                                  const prange &op2 ATTRIBUTE_UNUSED,
     759              :                                  relation_kind) const
     760              : {
     761       137325 :   if (lhs.undefined_p () || op1.undefined_p ())
     762              :     return VREL_VARYING;
     763       137325 :   unsigned lhs_prec = TYPE_PRECISION (lhs.type ());
     764       137325 :   unsigned op1_prec = TYPE_PRECISION (op1.type ());
     765              :   // If the result gets sign extended into a larger type check first if this
     766              :   // qualifies as a partial equivalence.
     767       137325 :   if (TYPE_SIGN (op1.type ()) == SIGNED && lhs_prec > op1_prec)
     768              :     {
     769              :       // If the result is sign extended, and the LHS is larger than op1,
     770              :       // check if op1's range can be negative as the sign extension will
     771              :       // cause the upper bits to be 1 instead of 0, invalidating the PE.
     772            0 :       int_range<3> negs = range_negatives (op1.type ());
     773            0 :       negs.intersect (op1);
     774            0 :       if (!negs.undefined_p ())
     775            0 :         return VREL_VARYING;
     776            0 :     }
     777              : 
     778              :   // If the pointer precisions are the same, check for equality and
     779              :   // inequality in the points to fields.
     780       137325 :   if (lhs_prec == op1_prec)
     781              :     {
     782       137325 :       if (lhs.addr_same_known_p (op1))
     783              :         return VREL_EQ;
     784       137174 :       if (lhs.addr_inverted_p (op1))
     785              :         return VREL_NE;
     786              :     }
     787       137174 :   unsigned prec = MIN (lhs_prec, op1_prec);
     788       137174 :   return bits_to_pe (prec);
     789              : }
     790              : 
     791              : relation_kind
     792      1445509 : operator_cast::lhs_op1_relation (const prange &lhs,
     793              :                                  const irange &op1,
     794              :                                  const irange &op2 ATTRIBUTE_UNUSED,
     795              :                                  relation_kind) const
     796              : {
     797      1445509 :   if (lhs.undefined_p () || op1.undefined_p ())
     798              :     return VREL_VARYING;
     799      1443752 :   unsigned lhs_prec = TYPE_PRECISION (lhs.type ());
     800      1443752 :   unsigned op1_prec = TYPE_PRECISION (op1.type ());
     801              :   // If the result gets sign extended into a larger type check first if this
     802              :   // qualifies as a partial equivalence.
     803      1443752 :   if (TYPE_SIGN (op1.type ()) == SIGNED && lhs_prec > op1_prec)
     804              :     {
     805              :       // If the result is sign extended, and the LHS is larger than op1,
     806              :       // check if op1's range can be negative as the sign extension will
     807              :       // cause the upper bits to be 1 instead of 0, invalidating the PE.
     808          410 :       int_range<3> negs = range_negatives (op1.type ());
     809          410 :       negs.intersect (op1);
     810          410 :       if (!negs.undefined_p ())
     811          402 :         return VREL_VARYING;
     812          410 :     }
     813              : 
     814      1443350 :   unsigned prec = MIN (lhs_prec, op1_prec);
     815      1443350 :   return bits_to_pe (prec);
     816              : }
     817              : 
     818              : relation_kind
     819      2387250 : operator_cast::lhs_op1_relation (const irange &lhs,
     820              :                                  const prange &op1,
     821              :                                  const prange &op2 ATTRIBUTE_UNUSED,
     822              :                                  relation_kind) const
     823              : {
     824      2387250 :   if (lhs.undefined_p () || op1.undefined_p ())
     825              :     return VREL_VARYING;
     826      2386114 :   unsigned lhs_prec = TYPE_PRECISION (lhs.type ());
     827      2386114 :   unsigned op1_prec = TYPE_PRECISION (op1.type ());
     828              :   // If the result gets sign extended into a larger type check first if this
     829              :   // qualifies as a partial equivalence.
     830      2386114 :   if (TYPE_SIGN (op1.type ()) == SIGNED && lhs_prec > op1_prec)
     831              :     {
     832              :       // If the result is sign extended, and the LHS is larger than op1,
     833              :       // check if op1's range can be negative as the sign extension will
     834              :       // cause the upper bits to be 1 instead of 0, invalidating the PE.
     835            0 :       int_range<3> negs = range_negatives (op1.type ());
     836            0 :       negs.intersect (op1);
     837            0 :       if (!negs.undefined_p ())
     838            0 :         return VREL_VARYING;
     839            0 :     }
     840              : 
     841      2386114 :   unsigned prec = MIN (lhs_prec, op1_prec);
     842      2386114 :   return bits_to_pe (prec);
     843              : }
     844              : 
     845              : bool
     846         1171 : operator_min::fold_range (prange &r, tree type,
     847              :                           const prange &op1,
     848              :                           const prange &op2,
     849              :                           relation_trio) const
     850              : {
     851              :   // For MIN/MAX expressions with pointers, we only care about
     852              :   // nullness.  If both are non null, then the result is nonnull.
     853              :   // If both are null, then the result is null.  Otherwise they
     854              :   // are varying.
     855         1171 :   if (!range_includes_zero_p (op1)
     856         1171 :       && !range_includes_zero_p (op2))
     857          148 :     r.set_nonzero (type);
     858         1023 :   else if (op1.zero_p () && op2.zero_p ())
     859            0 :     r.set_zero (type);
     860              :   else
     861         1023 :     r.set_varying (type);
     862              : 
     863         1171 :   update_known_bitmask (r, MIN_EXPR, op1, op2);
     864         1171 :   return true;
     865              : }
     866              : 
     867              : bool
     868         1143 : operator_max::fold_range (prange &r, tree type,
     869              :                           const prange &op1,
     870              :                           const prange &op2,
     871              :                           relation_trio) const
     872              : {
     873              :   // For MIN/MAX expressions with pointers, we only care about
     874              :   // nullness.  If both are non null, then the result is nonnull.
     875              :   // If both are null, then the result is null.  Otherwise they
     876              :   // are varying.
     877         1143 :   if (!range_includes_zero_p (op1)
     878         1143 :       && !range_includes_zero_p (op2))
     879          114 :     r.set_nonzero (type);
     880         1029 :   else if (op1.zero_p () && op2.zero_p ())
     881            0 :     r.set_zero (type);
     882              :   else
     883         1029 :     r.set_varying (type);
     884              : 
     885         1143 :   update_known_bitmask (r, MAX_EXPR, op1, op2);
     886         1143 :   return true;
     887              : }
     888              : 
     889              : bool
     890       568336 : operator_addr_expr::op1_range (prange &r, tree type,
     891              :                                const prange &lhs,
     892              :                                const prange &op2,
     893              :                                relation_trio) const
     894              : {
     895       568336 :   if (empty_range_varying (r, type, lhs, op2))
     896            0 :     return true;
     897              : 
     898              :   // Return a non-null pointer of the LHS type (passed in op2), but only
     899              :   // if we cant overflow, eitherwise a no-zero offset could wrap to zero.
     900              :   // See PR 111009.
     901       568336 :   if (!lhs.undefined_p ()
     902       568336 :       && !range_includes_zero_p (lhs)
     903       563444 :       && TYPE_OVERFLOW_UNDEFINED (type))
     904       563428 :     r.set_nonzero (type);
     905              :   else
     906         4908 :     r.set_varying (type);
     907              :   return true;
     908              : }
     909              : 
     910              : bool
     911          881 : operator_bitwise_and::fold_range (prange &r, tree type,
     912              :                                   const prange &op1,
     913              :                                   const prange &op2 ATTRIBUTE_UNUSED,
     914              :                                   relation_trio) const
     915              : {
     916              :   // For pointer types, we are really only interested in asserting
     917              :   // whether the expression evaluates to non-NULL.
     918          881 :   if (op1.zero_p () || op2.zero_p ())
     919            0 :     r.set_zero (type);
     920              :   else
     921          881 :     r.set_varying (type);
     922              : 
     923          881 :   update_known_bitmask (r, BIT_AND_EXPR, op1, op2);
     924          881 :   return true;
     925              : }
     926              : 
     927              : bool
     928      6679175 : operator_equal::fold_range (irange &r, tree type,
     929              :                             const prange &op1,
     930              :                             const prange &op2,
     931              :                             relation_trio rel) const
     932              : {
     933      6679175 :   if (relop_early_resolve (r, type, op1, op2, rel, VREL_EQ))
     934              :     return true;
     935              : 
     936              :   // We can be sure the values are always equal or not if both ranges
     937              :   // consist of a single value, and then compare them.
     938      6656597 :   bool op1_const = wi::eq_p (op1.lower_bound (), op1.upper_bound ());
     939      6656597 :   bool op2_const = wi::eq_p (op2.lower_bound (), op2.upper_bound ());
     940              :   // Check for points to equality and inequality first.
     941      6656597 :   if (op1.addr_same_known_p (op2))
     942        14030 :     r = range_true (type);
     943      6642567 :   else if (op1.addr_inverted_p (op2))
     944         8991 :     r = range_false (type);
     945      6633576 :   else if (op1_const && op2_const)
     946              :     {
     947        32158 :       if (wi::eq_p (op1.lower_bound (), op2.upper_bound()))
     948        31995 :         r = range_true (type);
     949              :       else
     950          163 :         r = range_false (type);
     951              :     }
     952              :   else
     953              :     {
     954              :       // If ranges do not intersect, we know the range is not equal,
     955              :       // otherwise we don't know anything for sure.
     956      6601418 :       prange tmp = op1;
     957      6601418 :       tmp.intersect (op2);
     958      6601418 :       if (tmp.undefined_p ())
     959       177550 :         r = range_false (type);
     960              :       // Check if a constant cannot satisfy the bitmask requirements.
     961     11231516 :       else if (op2_const && !op1.get_bitmask ().member_p (op2.lower_bound ()))
     962            0 :          r = range_false (type);
     963      6432152 :       else if (op1_const && !op2.get_bitmask ().member_p (op1.lower_bound ()))
     964            0 :          r = range_false (type);
     965              :       else
     966      6423868 :         r = range_true_and_false (type);
     967      6601418 :     }
     968              : 
     969              :   //update_known_bitmask (r, EQ_EXPR, op1, op2);
     970              :   return true;
     971              : }
     972              : 
     973              : bool
     974      4396157 : operator_equal::op1_range (prange &r, tree type,
     975              :                            const irange &lhs,
     976              :                            const prange &op2,
     977              :                            relation_trio) const
     978              : {
     979      4396157 :   switch (get_bool_state (r, lhs, type))
     980              :     {
     981      1224223 :     case BRS_TRUE:
     982              :       // If it's true, the result is the same as OP2.
     983      1224223 :       r = op2;
     984      1224223 :       break;
     985              : 
     986      3164031 :     case BRS_FALSE:
     987              :       // If the result is false, the only time we know anything is
     988              :       // if OP2 is a constant, or refers to a known object.
     989      3164031 :       if (!op2.undefined_p ()
     990      9492093 :           && wi::eq_p (op2.lower_bound(), op2.upper_bound()))
     991              :         {
     992      1054757 :           r = op2;
     993      1054757 :           if (!r.invert ())
     994              :             return false;
     995              :         }
     996              :       else
     997              :         {
     998      2109274 :           r.set_varying (type);
     999              :           // OP2 refers to OBJ, so OP1 does not refer to OBJ.
    1000      2109274 :           if (tree obj = op2.addr_known ())
    1001       565583 :             r.set_addr (obj, false);
    1002              :         }
    1003              :       break;
    1004              : 
    1005              :     default:
    1006              :       break;
    1007              :     }
    1008              :   return true;
    1009              : }
    1010              : 
    1011              : bool
    1012      1444622 : operator_equal::op2_range (prange &r, tree type,
    1013              :                            const irange &lhs,
    1014              :                            const prange &op1,
    1015              :                            relation_trio rel) const
    1016              : {
    1017      1444622 :   return operator_equal::op1_range (r, type, lhs, op1, rel.swap_op1_op2 ());
    1018              : }
    1019              : 
    1020              : relation_kind
    1021      5496402 : operator_equal::op1_op2_relation (const irange &lhs, const prange &,
    1022              :                                   const prange &) const
    1023              : {
    1024      5496402 :   if (lhs.undefined_p ())
    1025              :     return VREL_UNDEFINED;
    1026              : 
    1027              :   // FALSE = op1 == op2 indicates NE_EXPR.
    1028      5496402 :   if (lhs.zero_p ())
    1029              :     return VREL_NE;
    1030              : 
    1031              :   // TRUE = op1 == op2 indicates EQ_EXPR.
    1032      2489596 :   if (!range_includes_zero_p (lhs))
    1033      2488664 :     return VREL_EQ;
    1034              :   return VREL_VARYING;
    1035              : }
    1036              : 
    1037              : bool
    1038      8121469 : operator_not_equal::fold_range (irange &r, tree type,
    1039              :                                 const prange &op1,
    1040              :                                 const prange &op2,
    1041              :                                 relation_trio rel) const
    1042              : {
    1043      8121469 :   if (relop_early_resolve (r, type, op1, op2, rel, VREL_NE))
    1044              :     return true;
    1045              : 
    1046              :   // We can be sure the values are always equal or not if both ranges
    1047              :   // consist of a single value, and then compare them.
    1048      8100086 :   bool op1_const = wi::eq_p (op1.lower_bound (), op1.upper_bound ());
    1049      8100086 :   bool op2_const = wi::eq_p (op2.lower_bound (), op2.upper_bound ());
    1050              :   // Check for points to equality and inequality first.
    1051      8100086 :   if (op1.addr_inverted_p (op2))
    1052         1246 :     r = range_true (type);
    1053      8098840 :   else if (op1.addr_same_known_p (op2))
    1054         2597 :     r = range_false (type);
    1055      8096243 :   else if (op1_const && op2_const)
    1056              :     {
    1057        62028 :       if (wi::ne_p (op1.lower_bound (), op2.upper_bound()))
    1058          182 :         r = range_true (type);
    1059              :       else
    1060        61846 :         r = range_false (type);
    1061              :     }
    1062              :   else
    1063              :     {
    1064              :       // If ranges do not intersect, we know the range is not equal,
    1065              :       // otherwise we don't know anything for sure.
    1066      8034215 :       prange tmp = op1;
    1067      8034215 :       tmp.intersect (op2);
    1068      8034215 :       if (tmp.undefined_p ())
    1069       196484 :         r = range_true (type);
    1070              :       // Check if a constant cannot satisfy the bitmask requirements.
    1071     16801031 :       else if (op2_const && !op1.get_bitmask ().member_p (op2.lower_bound ()))
    1072            0 :          r = range_true (type);
    1073      7841433 :       else if (op1_const && !op2.get_bitmask ().member_p (op1.lower_bound ()))
    1074            0 :          r = range_true (type);
    1075              :       else
    1076      7837731 :         r = range_true_and_false (type);
    1077      8034215 :     }
    1078              : 
    1079              :   //update_known_bitmask (r, NE_EXPR, op1, op2);
    1080              :   return true;
    1081              : }
    1082              : 
    1083              : bool
    1084      5529253 : operator_not_equal::op1_range (prange &r, tree type,
    1085              :                                const irange &lhs,
    1086              :                                const prange &op2,
    1087              :                                relation_trio) const
    1088              : {
    1089      5529253 :   switch (get_bool_state (r, lhs, type))
    1090              :     {
    1091      4323093 :     case BRS_TRUE:
    1092              :       // If the result is true, the only time we know anything is if
    1093              :       // OP2 is a constant, or refers to a known object.
    1094      4323093 :       if (!op2.undefined_p ()
    1095     12969279 :           && wi::eq_p (op2.lower_bound(), op2.upper_bound()))
    1096              :         {
    1097      1720679 :           r = op2;
    1098      1720679 :           if (!r.invert ())
    1099              :             return false;
    1100              :         }
    1101              :       else
    1102              :         {
    1103      2602414 :           r.set_varying (type);
    1104              :           // Check if op1 is known not to refer to op2 points to object.
    1105      2602414 :           if (tree obj = op2.addr_known ())
    1106       489012 :             r.set_addr (obj, false);
    1107              :         }
    1108              :       break;
    1109              : 
    1110      1134328 :     case BRS_FALSE:
    1111              :       // If it's false, the result is the same as OP2.
    1112      1134328 :       r = op2;
    1113      1134328 :       break;
    1114              : 
    1115              :     default:
    1116              :       break;
    1117              :     }
    1118              :   return true;
    1119              : }
    1120              : 
    1121              : 
    1122              : bool
    1123      1646800 : operator_not_equal::op2_range (prange &r, tree type,
    1124              :                                const irange &lhs,
    1125              :                                const prange &op1,
    1126              :                                relation_trio rel) const
    1127              : {
    1128      1646800 :   return operator_not_equal::op1_range (r, type, lhs, op1, rel.swap_op1_op2 ());
    1129              : }
    1130              : 
    1131              : relation_kind
    1132      6124731 : operator_not_equal::op1_op2_relation (const irange &lhs, const prange &,
    1133              :                                       const prange &) const
    1134              : {
    1135      6124731 :   if (lhs.undefined_p ())
    1136              :     return VREL_UNDEFINED;
    1137              : 
    1138              :   // FALSE = op1 != op2  indicates EQ_EXPR.
    1139      6124731 :   if (lhs.zero_p ())
    1140              :     return VREL_EQ;
    1141              : 
    1142              :   // TRUE = op1 != op2  indicates NE_EXPR.
    1143      4082279 :   if (!range_includes_zero_p (lhs))
    1144      4075136 :     return VREL_NE;
    1145              :   return VREL_VARYING;
    1146              : }
    1147              : 
    1148              : bool
    1149       395941 : operator_lt::fold_range (irange &r, tree type,
    1150              :                          const prange &op1,
    1151              :                          const prange &op2,
    1152              :                          relation_trio rel) const
    1153              : {
    1154       395941 :   if (relop_early_resolve (r, type, op1, op2, rel, VREL_LT))
    1155              :     return true;
    1156              : 
    1157       393503 :   signop sign = TYPE_SIGN (op1.type ());
    1158       393503 :   gcc_checking_assert (sign == TYPE_SIGN (op2.type ()));
    1159              : 
    1160       393503 :   if (wi::lt_p (op1.upper_bound (), op2.lower_bound (), sign))
    1161            2 :     r = range_true (type);
    1162       393501 :   else if (!wi::lt_p (op1.lower_bound (), op2.upper_bound (), sign))
    1163           28 :     r = range_false (type);
    1164              :   // Use nonzero bits to determine if < 0 is false.
    1165       393473 :   else if (op2.zero_p () && !wi::neg_p (op1.get_nonzero_bits (), sign))
    1166            0 :     r = range_false (type);
    1167              :   else
    1168       393473 :     r = range_true_and_false (type);
    1169              : 
    1170              :   //update_known_bitmask (r, LT_EXPR, op1, op2);
    1171              :   return true;
    1172              : }
    1173              : 
    1174              : bool
    1175       326265 : operator_lt::op1_range (prange &r, tree type,
    1176              :                         const irange &lhs,
    1177              :                         const prange &op2,
    1178              :                         relation_trio) const
    1179              : {
    1180       326265 :   if (op2.undefined_p ())
    1181              :     return false;
    1182              : 
    1183       326265 :   switch (get_bool_state (r, lhs, type))
    1184              :     {
    1185       272651 :     case BRS_TRUE:
    1186       272651 :       build_lt (r, type, op2);
    1187       272651 :       break;
    1188              : 
    1189        53614 :     case BRS_FALSE:
    1190        53614 :       build_ge (r, type, op2);
    1191        53614 :       break;
    1192              : 
    1193              :     default:
    1194              :       break;
    1195              :     }
    1196              :   return true;
    1197              : }
    1198              : 
    1199              : bool
    1200       236725 : operator_lt::op2_range (prange &r, tree type,
    1201              :                         const irange &lhs,
    1202              :                         const prange &op1,
    1203              :                         relation_trio) const
    1204              : {
    1205       236725 :   if (op1.undefined_p ())
    1206              :     return false;
    1207              : 
    1208       236725 :   switch (get_bool_state (r, lhs, type))
    1209              :     {
    1210       166998 :     case BRS_TRUE:
    1211       166998 :       build_gt (r, type, op1);
    1212       166998 :       break;
    1213              : 
    1214        69723 :     case BRS_FALSE:
    1215        69723 :       build_le (r, type, op1);
    1216        69723 :       break;
    1217              : 
    1218              :     default:
    1219              :       break;
    1220              :     }
    1221              :   return true;
    1222              : }
    1223              : 
    1224              : relation_kind
    1225       907249 : operator_lt::op1_op2_relation (const irange &lhs, const prange &,
    1226              :                                const prange &) const
    1227              : {
    1228       907249 :   if (lhs.undefined_p ())
    1229              :     return VREL_UNDEFINED;
    1230              : 
    1231              :   // FALSE = op1 < op2 indicates GE_EXPR.
    1232       907249 :   if (lhs.zero_p ())
    1233              :     return VREL_GE;
    1234              : 
    1235              :   // TRUE = op1 < op2 indicates LT_EXPR.
    1236       655408 :   if (!range_includes_zero_p (lhs))
    1237       655350 :     return VREL_LT;
    1238              :   return VREL_VARYING;
    1239              : }
    1240              : 
    1241              : bool
    1242       125272 : operator_le::fold_range (irange &r, tree type,
    1243              :                          const prange &op1,
    1244              :                          const prange &op2,
    1245              :                          relation_trio rel) const
    1246              : {
    1247       125272 :   if (relop_early_resolve (r, type, op1, op2, rel, VREL_LE))
    1248              :     return true;
    1249              : 
    1250       124871 :   signop sign = TYPE_SIGN (op1.type ());
    1251       124871 :   gcc_checking_assert (sign == TYPE_SIGN (op2.type ()));
    1252              : 
    1253       124871 :   if (wi::le_p (op1.upper_bound (), op2.lower_bound (), sign))
    1254           40 :     r = range_true (type);
    1255       124831 :   else if (!wi::le_p (op1.lower_bound (), op2.upper_bound (), sign))
    1256           12 :     r = range_false (type);
    1257              :   else
    1258       124819 :     r = range_true_and_false (type);
    1259              : 
    1260              :   //update_known_bitmask (r, LE_EXPR, op1, op2);
    1261              :   return true;
    1262              : }
    1263              : 
    1264              : bool
    1265       102304 : operator_le::op1_range (prange &r, tree type,
    1266              :                         const irange &lhs,
    1267              :                         const prange &op2,
    1268              :                         relation_trio) const
    1269              : {
    1270       102304 :   if (op2.undefined_p ())
    1271              :     return false;
    1272              : 
    1273       102304 :   switch (get_bool_state (r, lhs, type))
    1274              :     {
    1275        77109 :     case BRS_TRUE:
    1276        77109 :       build_le (r, type, op2);
    1277        77109 :       break;
    1278              : 
    1279        25195 :     case BRS_FALSE:
    1280        25195 :       build_gt (r, type, op2);
    1281        25195 :       break;
    1282              : 
    1283              :     default:
    1284              :       break;
    1285              :     }
    1286              :   return true;
    1287              : }
    1288              : 
    1289              : bool
    1290       135372 : operator_le::op2_range (prange &r, tree type,
    1291              :                         const irange &lhs,
    1292              :                         const prange &op1,
    1293              :                         relation_trio) const
    1294              : {
    1295       135372 :   if (op1.undefined_p ())
    1296              :     return false;
    1297              : 
    1298       135372 :   switch (get_bool_state (r, lhs, type))
    1299              :     {
    1300       110919 :     case BRS_TRUE:
    1301       110919 :       build_ge (r, type, op1);
    1302       110919 :       break;
    1303              : 
    1304        24453 :     case BRS_FALSE:
    1305        24453 :       build_lt (r, type, op1);
    1306        24453 :       break;
    1307              : 
    1308              :     default:
    1309              :       break;
    1310              :     }
    1311              :   return true;
    1312              : }
    1313              : 
    1314              : relation_kind
    1315       390408 : operator_le::op1_op2_relation (const irange &lhs, const prange &,
    1316              :                                const prange &) const
    1317              : {
    1318       390408 :   if (lhs.undefined_p ())
    1319              :     return VREL_UNDEFINED;
    1320              : 
    1321              :   // FALSE = op1 <= op2 indicates GT_EXPR.
    1322       390408 :   if (lhs.zero_p ())
    1323              :     return VREL_GT;
    1324              : 
    1325              :   // TRUE = op1 <= op2 indicates LE_EXPR.
    1326       287125 :   if (!range_includes_zero_p (lhs))
    1327       286839 :     return VREL_LE;
    1328              :   return VREL_VARYING;
    1329              : }
    1330              : 
    1331              : bool
    1332       417265 : operator_gt::fold_range (irange &r, tree type,
    1333              :                          const prange &op1, const prange &op2,
    1334              :                          relation_trio rel) const
    1335              : {
    1336       417265 :   if (relop_early_resolve (r, type, op1, op2, rel, VREL_GT))
    1337              :     return true;
    1338              : 
    1339       414766 :   signop sign = TYPE_SIGN (op1.type ());
    1340       414766 :   gcc_checking_assert (sign == TYPE_SIGN (op2.type ()));
    1341              : 
    1342       414766 :   if (wi::gt_p (op1.lower_bound (), op2.upper_bound (), sign))
    1343            2 :     r = range_true (type);
    1344       414764 :   else if (!wi::gt_p (op1.upper_bound (), op2.lower_bound (), sign))
    1345            9 :     r = range_false (type);
    1346              :   else
    1347       414755 :     r = range_true_and_false (type);
    1348              : 
    1349              :   //update_known_bitmask (r, GT_EXPR, op1, op2);
    1350              :   return true;
    1351              : }
    1352              : 
    1353              : bool
    1354       369013 : operator_gt::op1_range (prange &r, tree type,
    1355              :                         const irange &lhs, const prange &op2,
    1356              :                         relation_trio) const
    1357              : {
    1358       369013 :   if (op2.undefined_p ())
    1359              :     return false;
    1360              : 
    1361       369013 :   switch (get_bool_state (r, lhs, type))
    1362              :     {
    1363       234614 :     case BRS_TRUE:
    1364       234614 :       build_gt (r, type, op2);
    1365       234614 :       break;
    1366              : 
    1367       134399 :     case BRS_FALSE:
    1368       134399 :       build_le (r, type, op2);
    1369       134399 :       break;
    1370              : 
    1371              :     default:
    1372              :       break;
    1373              :     }
    1374              :   return true;
    1375              : }
    1376              : 
    1377              : bool
    1378       284093 : operator_gt::op2_range (prange &r, tree type,
    1379              :                         const irange &lhs,
    1380              :                         const prange &op1,
    1381              :                         relation_trio) const
    1382              : {
    1383       284093 :   if (op1.undefined_p ())
    1384              :     return false;
    1385              : 
    1386       284093 :   switch (get_bool_state (r, lhs, type))
    1387              :     {
    1388       208947 :     case BRS_TRUE:
    1389       208947 :       build_lt (r, type, op1);
    1390       208947 :       break;
    1391              : 
    1392        75146 :     case BRS_FALSE:
    1393        75146 :       build_ge (r, type, op1);
    1394        75146 :       break;
    1395              : 
    1396              :     default:
    1397              :       break;
    1398              :     }
    1399              :   return true;
    1400              : }
    1401              : 
    1402              : relation_kind
    1403      1048260 : operator_gt::op1_op2_relation (const irange &lhs, const prange &,
    1404              :                                const prange &) const
    1405              : {
    1406      1048260 :   if (lhs.undefined_p ())
    1407              :     return VREL_UNDEFINED;
    1408              : 
    1409              :   // FALSE = op1 > op2 indicates LE_EXPR.
    1410      1048260 :   if (lhs.zero_p ())
    1411              :     return VREL_LE;
    1412              : 
    1413              :   // TRUE = op1 > op2 indicates GT_EXPR.
    1414       700163 :   if (!range_includes_zero_p (lhs))
    1415       700157 :     return VREL_GT;
    1416              :   return VREL_VARYING;
    1417              : }
    1418              : 
    1419              : bool
    1420       198258 : operator_ge::fold_range (irange &r, tree type,
    1421              :                          const prange &op1,
    1422              :                          const prange &op2,
    1423              :                          relation_trio rel) const
    1424              : {
    1425       198258 :   if (relop_early_resolve (r, type, op1, op2, rel, VREL_GE))
    1426              :     return true;
    1427              : 
    1428       197931 :   signop sign = TYPE_SIGN (op1.type ());
    1429       197931 :   gcc_checking_assert (sign == TYPE_SIGN (op2.type ()));
    1430              : 
    1431       197931 :   if (wi::ge_p (op1.lower_bound (), op2.upper_bound (), sign))
    1432           64 :     r = range_true (type);
    1433       197867 :   else if (!wi::ge_p (op1.upper_bound (), op2.lower_bound (), sign))
    1434            0 :     r = range_false (type);
    1435              :   else
    1436       197867 :     r = range_true_and_false (type);
    1437              : 
    1438              :   //update_known_bitmask (r, GE_EXPR, op1, op2);
    1439              :   return true;
    1440              : }
    1441              : 
    1442              : bool
    1443       203726 : operator_ge::op1_range (prange &r, tree type,
    1444              :                         const irange &lhs,
    1445              :                         const prange &op2,
    1446              :                         relation_trio) const
    1447              : {
    1448       203726 :   if (op2.undefined_p ())
    1449              :     return false;
    1450              : 
    1451       203726 :   switch (get_bool_state (r, lhs, type))
    1452              :     {
    1453       176142 :     case BRS_TRUE:
    1454       176142 :       build_ge (r, type, op2);
    1455       176142 :       break;
    1456              : 
    1457        27584 :     case BRS_FALSE:
    1458        27584 :       build_lt (r, type, op2);
    1459        27584 :       break;
    1460              : 
    1461              :     default:
    1462              :       break;
    1463              :     }
    1464              :   return true;
    1465              : }
    1466              : 
    1467              : bool
    1468        99037 : operator_ge::op2_range (prange &r, tree type,
    1469              :                         const irange &lhs,
    1470              :                         const prange &op1,
    1471              :                         relation_trio) const
    1472              : {
    1473        99037 :   if (op1.undefined_p ())
    1474              :     return false;
    1475              : 
    1476        99037 :   switch (get_bool_state (r, lhs, type))
    1477              :     {
    1478        70528 :     case BRS_TRUE:
    1479        70528 :       build_le (r, type, op1);
    1480        70528 :       break;
    1481              : 
    1482        28509 :     case BRS_FALSE:
    1483        28509 :       build_gt (r, type, op1);
    1484        28509 :       break;
    1485              : 
    1486              :     default:
    1487              :       break;
    1488              :     }
    1489              :   return true;
    1490              : }
    1491              : 
    1492              : relation_kind
    1493       514873 : operator_ge::op1_op2_relation (const irange &lhs, const prange &,
    1494              :                                const prange &) const
    1495              : {
    1496       514873 :   if (lhs.undefined_p ())
    1497              :     return VREL_UNDEFINED;
    1498              : 
    1499              :   // FALSE = op1 >= op2 indicates LT_EXPR.
    1500       514873 :   if (lhs.zero_p ())
    1501              :     return VREL_LT;
    1502              : 
    1503              :   // TRUE = op1 >= op2 indicates GE_EXPR.
    1504       385963 :   if (!range_includes_zero_p (lhs))
    1505       385963 :     return VREL_GE;
    1506              :   return VREL_VARYING;
    1507              : }
    1508              : 
    1509              : // Initialize any pointer operators to the primary table
    1510              : 
    1511              : void
    1512       296010 : range_op_table::initialize_pointer_ops ()
    1513              : {
    1514       296010 :   set (POINTER_PLUS_EXPR, op_pointer_plus);
    1515       296010 :   set (POINTER_DIFF_EXPR, op_pointer_diff);
    1516       296010 : }
        

Generated by: LCOV version 2.5.0-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.