LCOV - code coverage report
Current view: top level - gcc - range-op-ptr.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 85.1 % 484 412
Test Date: 2025-07-05 13:26:22 Functions: 77.9 % 77 60
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Code for range operators.
       2                 :             :    Copyright (C) 2017-2025 Free Software Foundation, Inc.
       3                 :             :    Contributed by Andrew MacLeod <amacleod@redhat.com>
       4                 :             :    and Aldy Hernandez <aldyh@redhat.com>.
       5                 :             : 
       6                 :             : This file is part of GCC.
       7                 :             : 
       8                 :             : GCC is free software; you can redistribute it and/or modify
       9                 :             : it under the terms of the GNU General Public License as published by
      10                 :             : the Free Software Foundation; either version 3, or (at your option)
      11                 :             : any later version.
      12                 :             : 
      13                 :             : GCC is distributed in the hope that it will be useful,
      14                 :             : but WITHOUT ANY WARRANTY; without even the implied warranty of
      15                 :             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16                 :             : GNU General Public License for more details.
      17                 :             : 
      18                 :             : You should have received a copy of the GNU General Public License
      19                 :             : along with GCC; see the file COPYING3.  If not see
      20                 :             : <http://www.gnu.org/licenses/>.  */
      21                 :             : 
      22                 :             : #include "config.h"
      23                 :             : #include "system.h"
      24                 :             : #include "coretypes.h"
      25                 :             : #include "backend.h"
      26                 :             : #include "insn-codes.h"
      27                 :             : #include "rtl.h"
      28                 :             : #include "tree.h"
      29                 :             : #include "gimple.h"
      30                 :             : #include "cfghooks.h"
      31                 :             : #include "tree-pass.h"
      32                 :             : #include "ssa.h"
      33                 :             : #include "optabs-tree.h"
      34                 :             : #include "gimple-pretty-print.h"
      35                 :             : #include "diagnostic-core.h"
      36                 :             : #include "flags.h"
      37                 :             : #include "fold-const.h"
      38                 :             : #include "stor-layout.h"
      39                 :             : #include "calls.h"
      40                 :             : #include "cfganal.h"
      41                 :             : #include "gimple-iterator.h"
      42                 :             : #include "gimple-fold.h"
      43                 :             : #include "tree-eh.h"
      44                 :             : #include "gimple-walk.h"
      45                 :             : #include "tree-cfg.h"
      46                 :             : #include "wide-int.h"
      47                 :             : #include "value-relation.h"
      48                 :             : #include "range-op.h"
      49                 :             : #include "tree-ssa-ccp.h"
      50                 :             : #include "range-op-mixed.h"
      51                 :             : 
      52                 :             : 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                 :           0 : range_operator::fold_range (irange &, tree, const prange &, const irange &,
      82                 :             :                             relation_trio) const
      83                 :             : {
      84                 :           0 :   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                 :         122 : range_operator::op1_range (prange &, tree,
     134                 :             :                            const prange &lhs ATTRIBUTE_UNUSED,
     135                 :             :                            const prange &op2 ATTRIBUTE_UNUSED,
     136                 :             :                            relation_trio) const
     137                 :             : {
     138                 :         122 :   return false;
     139                 :             : }
     140                 :             : 
     141                 :             : bool
     142                 :      639874 : range_operator::op1_range (prange &, tree,
     143                 :             :                            const irange &lhs ATTRIBUTE_UNUSED,
     144                 :             :                            const prange &op2 ATTRIBUTE_UNUSED,
     145                 :             :                            relation_trio) const
     146                 :             : {
     147                 :      639874 :   return false;
     148                 :             : }
     149                 :             : 
     150                 :             : bool
     151                 :      429927 : range_operator::op1_range (prange &, tree,
     152                 :             :                            const prange &lhs ATTRIBUTE_UNUSED,
     153                 :             :                            const irange &op2 ATTRIBUTE_UNUSED,
     154                 :             :                            relation_trio) const
     155                 :             : {
     156                 :      429927 :   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                 :     1044197 : range_operator::op2_range (prange &, tree,
     170                 :             :                            const irange &lhs ATTRIBUTE_UNUSED,
     171                 :             :                            const prange &op1 ATTRIBUTE_UNUSED,
     172                 :             :                            relation_trio) const
     173                 :             : {
     174                 :     1044197 :   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                 :     1642372 : 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                 :     1642372 :   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                 :     3725992 : 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                 :     3725992 :   return VREL_VARYING;
     210                 :             : }
     211                 :             : 
     212                 :             : relation_kind
     213                 :       68425 : 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                 :       68425 :   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                 :      641189 : max_limit (const_tree type)
     241                 :             : {
     242                 :      641189 :   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                 :      708955 : min_limit (const_tree type)
     249                 :             : {
     250                 :      708955 :   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                 :      506516 : build_lt (prange &r, tree type, const prange &val)
     257                 :             : {
     258                 :      506516 :   wi::overflow_type ov;
     259                 :      506516 :   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                 :      506516 :   if (ov)
     263                 :           0 :     r.set_undefined ();
     264                 :             :   else
     265                 :      506516 :     r.set (type, min_limit (type), lim);
     266                 :      506516 : }
     267                 :             : 
     268                 :             : // Build a range that is <= VAL and store it in R.
     269                 :             : 
     270                 :             : static void
     271                 :      202439 : build_le (prange &r, tree type, const prange &val)
     272                 :             : {
     273                 :      202439 :   r.set (type, min_limit (type), val.upper_bound ());
     274                 :      202439 : }
     275                 :             : 
     276                 :             : // Build a range that is > VAL and store it in R.
     277                 :             : 
     278                 :             : static void
     279                 :      328976 : build_gt (prange &r, tree type, const prange &val)
     280                 :             : {
     281                 :      328976 :   wi::overflow_type ov;
     282                 :      328976 :   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                 :      328976 :   if (ov)
     286                 :           0 :     r.set_undefined ();
     287                 :             :   else
     288                 :      328976 :     r.set (type, lim, max_limit (type));
     289                 :             : 
     290                 :      328976 : }
     291                 :             : 
     292                 :             : // Build a range that is >= VAL and store it in R.
     293                 :             : 
     294                 :             : static void
     295                 :      312213 : build_ge (prange &r, tree type, const prange &val)
     296                 :             : {
     297                 :      312213 :   r.set (type, val.lower_bound (), max_limit (type));
     298                 :      312213 : }
     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                 :             : } op_pointer_plus;
     322                 :             : 
     323                 :             : bool
     324                 :     9166081 : pointer_plus_operator::fold_range (prange &r, tree type,
     325                 :             :                                    const prange &op1,
     326                 :             :                                    const irange &op2,
     327                 :             :                                    relation_trio) const
     328                 :             : {
     329                 :     9166081 :   if (empty_range_varying (r, type, op1, op2))
     330                 :        3846 :     return true;
     331                 :             : 
     332                 :     9162235 :   const wide_int lh_lb = op1.lower_bound ();
     333                 :     9162235 :   const wide_int lh_ub = op1.upper_bound ();
     334                 :     9162235 :   const wide_int rh_lb = op2.lower_bound ();
     335                 :     9162235 :   const wide_int rh_ub = op2.upper_bound ();
     336                 :             : 
     337                 :             :   // Check for [0,0] + const, and simply return the const.
     338                 :     9172126 :   if (lh_lb == 0 && lh_ub == 0 && rh_lb == rh_ub)
     339                 :             :     {
     340                 :         859 :       r.set (type, rh_lb, rh_lb);
     341                 :         859 :       return true;
     342                 :             :     }
     343                 :             : 
     344                 :             :   // For pointer types, we are really only interested in asserting
     345                 :             :   // whether the expression evaluates to non-NULL.
     346                 :             :   //
     347                 :             :   // With -fno-delete-null-pointer-checks we need to be more
     348                 :             :   // conservative.  As some object might reside at address 0,
     349                 :             :   // then some offset could be added to it and the same offset
     350                 :             :   // subtracted again and the result would be NULL.
     351                 :             :   // E.g.
     352                 :             :   // static int a[12]; where &a[0] is NULL and
     353                 :             :   // ptr = &a[6];
     354                 :             :   // ptr -= 6;
     355                 :             :   // ptr will be NULL here, even when there is POINTER_PLUS_EXPR
     356                 :             :   // where the first range doesn't include zero and the second one
     357                 :             :   // doesn't either.  As the second operand is sizetype (unsigned),
     358                 :             :   // consider all ranges where the MSB could be set as possible
     359                 :             :   // subtractions where the result might be NULL.
     360                 :     9161376 :   if ((!wi_includes_zero_p (type, lh_lb, lh_ub)
     361                 :     5341679 :        || !wi_includes_zero_p (type, rh_lb, rh_ub))
     362                 :     6065007 :       && !TYPE_OVERFLOW_WRAPS (type)
     363                 :    15225725 :       && (flag_delete_null_pointer_checks
     364                 :        1280 :           || !wi::sign_mask (rh_ub)))
     365                 :     6063943 :     r.set_nonzero (type);
     366                 :     3105123 :   else if (lh_lb == lh_ub && lh_lb == 0
     367                 :     3105123 :            && rh_lb == rh_ub && rh_lb == 0)
     368                 :           0 :     r.set_zero (type);
     369                 :             :   else
     370                 :     3097433 :    r.set_varying (type);
     371                 :             : 
     372                 :     9161376 :   update_known_bitmask (r, POINTER_PLUS_EXPR, op1, op2);
     373                 :     9161376 :   return true;
     374                 :     9162235 : }
     375                 :             : 
     376                 :             : bool
     377                 :      178505 : pointer_plus_operator::op2_range (irange &r, tree type,
     378                 :             :                                   const prange &lhs ATTRIBUTE_UNUSED,
     379                 :             :                                   const prange &op1 ATTRIBUTE_UNUSED,
     380                 :             :                                   relation_trio trio) const
     381                 :             : {
     382                 :      178505 :   relation_kind rel = trio.lhs_op1 ();
     383                 :      178505 :   r.set_varying (type);
     384                 :             : 
     385                 :             :   // If the LHS and OP1 are equal, the op2 must be zero.
     386                 :      178505 :   if (rel == VREL_EQ)
     387                 :        7921 :     r.set_zero (type);
     388                 :             :   // If the LHS and OP1 are not equal, the offset must be non-zero.
     389                 :      170584 :   else if (rel == VREL_NE)
     390                 :       11710 :     r.set_nonzero (type);
     391                 :             :   else
     392                 :             :     return false;
     393                 :             :   return true;
     394                 :             : }
     395                 :             : 
     396                 :             : // Return the relation between the LHS and OP1 based on the value of the
     397                 :             : // operand being added.  Pointer_plus is define to have a size_type for
     398                 :             : // operand 2 which can be interpreted as negative, so always used SIGNED.
     399                 :             : // Any overflow is considered UB and thus ignored.
     400                 :             : 
     401                 :             : relation_kind
     402                 :     7923223 : pointer_plus_operator::lhs_op1_relation (const prange &lhs,
     403                 :             :                                          const prange &op1,
     404                 :             :                                          const irange &op2,
     405                 :             :                                          relation_kind) const
     406                 :             : {
     407                 :     7923223 :   if (lhs.undefined_p () || op1.undefined_p () || op2.undefined_p ())
     408                 :             :     return VREL_VARYING;
     409                 :             : 
     410                 :     7919712 :   unsigned prec = TYPE_PRECISION (op2.type ());
     411                 :             : 
     412                 :             :   // LHS = OP1 + 0  indicates LHS == OP1.
     413                 :     7919712 :   if (op2.zero_p ())
     414                 :             :     return VREL_EQ;
     415                 :             : 
     416                 :     7903302 :   tree val;
     417                 :             :   // Only deal with singletons for now.
     418                 :     7903302 :   if (TYPE_OVERFLOW_UNDEFINED (lhs.type ()) && op2.singleton_p (&val))
     419                 :             :     {
     420                 :             :       // Always interpret VALUE as a signed value.  Positive will increase
     421                 :             :       // the pointer value, and negative will decrease the poiinter value.
     422                 :             :       // It cannot be zero or the earlier zero_p () condition will catch it.
     423                 :     4009018 :       wide_int value = wi::to_wide (val);
     424                 :             : 
     425                 :             :       // Positive op2 means lhs > op1.
     426                 :     4009018 :       if (wi::gt_p (value, wi::zero (prec), SIGNED))
     427                 :             :         return VREL_GT;
     428                 :             : 
     429                 :             :       // Negative op2 means lhs < op1.
     430                 :      435651 :       if (wi::lt_p (value, wi::zero (prec), SIGNED))
     431                 :             :         return VREL_LT;
     432                 :     4009018 :     }
     433                 :             : 
     434                 :             :   // If op2 does not contain 0, then LHS and OP1 can never be equal.
     435                 :     3894284 :   if (!range_includes_zero_p (op2))
     436                 :             :     return VREL_NE;
     437                 :             : 
     438                 :             :   return VREL_VARYING;
     439                 :             : }
     440                 :             : 
     441                 :             : bool
     442                 :           0 : operator_bitwise_or::fold_range (prange &r, tree type,
     443                 :             :                                  const prange &op1,
     444                 :             :                                  const prange &op2,
     445                 :             :                                  relation_trio) const
     446                 :             : {
     447                 :             :   // For pointer types, we are really only interested in asserting
     448                 :             :   // whether the expression evaluates to non-NULL.
     449                 :           0 :   if (!range_includes_zero_p (op1) || !range_includes_zero_p (op2))
     450                 :           0 :     r.set_nonzero (type);
     451                 :           0 :   else if (op1.zero_p () && op2.zero_p ())
     452                 :           0 :     r.set_zero (type);
     453                 :             :   else
     454                 :           0 :     r.set_varying (type);
     455                 :             : 
     456                 :           0 :   update_known_bitmask (r, BIT_IOR_EXPR, op1, op2);
     457                 :           0 :   return true;
     458                 :             : }
     459                 :             : 
     460                 :             : 
     461                 :             : class operator_pointer_diff : public range_operator
     462                 :             : {
     463                 :             :   using range_operator::fold_range;
     464                 :             :   using range_operator::update_bitmask;
     465                 :             :   using range_operator::op1_op2_relation_effect;
     466                 :             :   virtual bool fold_range (irange &r, tree type,
     467                 :             :                            const prange &op1,
     468                 :             :                            const prange &op2,
     469                 :             :                            relation_trio trio) const final override;
     470                 :             :   virtual bool op1_op2_relation_effect (irange &lhs_range,
     471                 :             :                                         tree type,
     472                 :             :                                         const prange &op1_range,
     473                 :             :                                         const prange &op2_range,
     474                 :             :                                         relation_kind rel) const final override;
     475                 :     2499322 :   void update_bitmask (irange &r,
     476                 :             :                        const prange &lh, const prange &rh) const final override
     477                 :           0 :   { update_known_bitmask (r, POINTER_DIFF_EXPR, lh, rh); }
     478                 :             : } op_pointer_diff;
     479                 :             : 
     480                 :             : bool
     481                 :     2499322 : operator_pointer_diff::fold_range (irange &r, tree type,
     482                 :             :                                    const prange &op1,
     483                 :             :                                    const prange &op2,
     484                 :             :                                    relation_trio trio) const
     485                 :             : {
     486                 :     2499322 :   gcc_checking_assert (r.supports_type_p (type));
     487                 :             : 
     488                 :     2499322 :   r.set_varying (type);
     489                 :     2499322 :   relation_kind rel = trio.op1_op2 ();
     490                 :     2499322 :   op1_op2_relation_effect (r, type, op1, op2, rel);
     491                 :     2499322 :   update_bitmask (r, op1, op2);
     492                 :     2499322 :   return true;
     493                 :             : }
     494                 :             : 
     495                 :             : bool
     496                 :     2499322 : operator_pointer_diff::op1_op2_relation_effect (irange &lhs_range, tree type,
     497                 :             :                                                 const prange &op1_range,
     498                 :             :                                                 const prange &op2_range,
     499                 :             :                                                 relation_kind rel) const
     500                 :             : {
     501                 :     2499322 :   int_range<2> op1, op2, tmp;
     502                 :     2499322 :   range_op_handler cast (CONVERT_EXPR);
     503                 :             : 
     504                 :     2499322 :   if (!cast.fold_range (op1, type, op1_range, tmp)
     505                 :     2499322 :       || !cast.fold_range (op2, type, op2_range, tmp))
     506                 :           0 :     return false;
     507                 :             : 
     508                 :     2499322 :   return minus_op1_op2_relation_effect (lhs_range, type, op1, op2, rel);
     509                 :     2499322 : }
     510                 :             : 
     511                 :             : bool
     512                 :     1214434 : operator_identity::fold_range (prange &r, tree type ATTRIBUTE_UNUSED,
     513                 :             :                                const prange &lh ATTRIBUTE_UNUSED,
     514                 :             :                                const prange &rh ATTRIBUTE_UNUSED,
     515                 :             :                                relation_trio) const
     516                 :             : {
     517                 :     1214434 :   r = lh;
     518                 :     1214434 :   return true;
     519                 :             : }
     520                 :             : 
     521                 :             : relation_kind
     522                 :     1153890 : operator_identity::lhs_op1_relation (const prange &lhs,
     523                 :             :                                      const prange &op1 ATTRIBUTE_UNUSED,
     524                 :             :                                      const prange &op2 ATTRIBUTE_UNUSED,
     525                 :             :                                      relation_kind) const
     526                 :             : {
     527                 :     1153890 :   if (lhs.undefined_p ())
     528                 :         486 :     return VREL_VARYING;
     529                 :             :   // Simply a copy, so they are equivalent.
     530                 :             :   return VREL_EQ;
     531                 :             : }
     532                 :             : 
     533                 :             : bool
     534                 :      196365 : operator_identity::op1_range (prange &r, tree type ATTRIBUTE_UNUSED,
     535                 :             :                               const prange &lhs,
     536                 :             :                               const prange &op2 ATTRIBUTE_UNUSED,
     537                 :             :                               relation_trio) const
     538                 :             : {
     539                 :      196365 :   r = lhs;
     540                 :      196365 :   return true;
     541                 :             : }
     542                 :             : 
     543                 :             : bool
     544                 :       21602 : operator_cst::fold_range (prange &r, tree type ATTRIBUTE_UNUSED,
     545                 :             :                           const prange &lh,
     546                 :             :                           const prange & ATTRIBUTE_UNUSED,
     547                 :             :                           relation_trio) const
     548                 :             : {
     549                 :       21602 :   r = lh;
     550                 :       21602 :   return true;
     551                 :             : }
     552                 :             : 
     553                 :             : // Cast between pointers.
     554                 :             : 
     555                 :             : bool
     556                 :    15659622 : operator_cast::fold_range (prange &r, tree type,
     557                 :             :                            const prange &inner,
     558                 :             :                            const prange &outer,
     559                 :             :                            relation_trio) const
     560                 :             : {
     561                 :    15659622 :   if (empty_range_varying (r, type, inner, outer))
     562                 :         453 :     return true;
     563                 :             : 
     564                 :    15659169 :   r.set (type, inner.lower_bound (), inner.upper_bound ());
     565                 :    15659169 :   r.update_bitmask (inner.get_bitmask ());
     566                 :    15659169 :   return true;
     567                 :             : }
     568                 :             : 
     569                 :             : // Cast a pointer to an integer.
     570                 :             : 
     571                 :             : bool
     572                 :     9274246 : operator_cast::fold_range (irange &r, tree type,
     573                 :             :                            const prange &inner,
     574                 :             :                            const irange &outer,
     575                 :             :                            relation_trio) const
     576                 :             : {
     577                 :     9274246 :   if (empty_range_varying (r, type, inner, outer))
     578                 :     4999699 :     return true;
     579                 :             : 
     580                 :             :   // Represent INNER as an integer of the same size, and then cast it
     581                 :             :   // to the resulting integer type.
     582                 :     4274547 :   tree pointer_uint_type = make_unsigned_type (TYPE_PRECISION (inner.type ()));
     583                 :     4274547 :   r.set (pointer_uint_type, inner.lower_bound (), inner.upper_bound ());
     584                 :     4274547 :   r.update_bitmask (inner.get_bitmask ());
     585                 :     4274547 :   range_cast (r, type);
     586                 :     4274547 :   return true;
     587                 :             : }
     588                 :             : 
     589                 :             : // Cast an integer to a pointer.
     590                 :             : 
     591                 :             : bool
     592                 :     1783727 : operator_cast::fold_range (prange &r, tree type,
     593                 :             :                            const irange &inner,
     594                 :             :                            const prange &outer,
     595                 :             :                            relation_trio) const
     596                 :             : {
     597                 :     1783727 :   if (empty_range_varying (r, type, inner, outer))
     598                 :        1789 :     return true;
     599                 :             : 
     600                 :             :   // Cast INNER to an integer of the same size as the pointer we want,
     601                 :             :   // and then copy the bounds to the resulting pointer range.
     602                 :     1781938 :   int_range<2> tmp = inner;
     603                 :     1781938 :   tree pointer_uint_type = make_unsigned_type (TYPE_PRECISION (type));
     604                 :     1781938 :   range_cast (tmp, pointer_uint_type);
     605                 :             :   // Casts may cause ranges to become UNDEFINED based on bitmasks.
     606                 :     1781938 :   if (tmp.undefined_p ())
     607                 :           0 :     r.set_varying (type);
     608                 :             :   else
     609                 :             :     {
     610                 :     1781938 :       r.set (type, tmp.lower_bound (), tmp.upper_bound ());
     611                 :     1781938 :       r.update_bitmask (tmp.get_bitmask ());
     612                 :             :     }
     613                 :     1781938 :   return true;
     614                 :     1781938 : }
     615                 :             : 
     616                 :             : bool
     617                 :          69 : operator_cast::op1_range (prange &r, tree type,
     618                 :             :                           const prange &lhs,
     619                 :             :                           const prange &op2,
     620                 :             :                           relation_trio trio) const
     621                 :             : {
     622                 :          69 :   if (lhs.undefined_p ())
     623                 :             :     return false;
     624                 :          69 :   gcc_checking_assert (types_compatible_p (op2.type(), type));
     625                 :             : 
     626                 :             :   // Conversion from other pointers or a constant (including 0/NULL)
     627                 :             :   // are straightforward.
     628                 :          69 :   if (POINTER_TYPE_P (lhs.type ())
     629                 :          69 :       || (lhs.singleton_p ()
     630                 :           0 :           && TYPE_PRECISION (lhs.type ()) >= TYPE_PRECISION (type)))
     631                 :          69 :     fold_range (r, type, lhs, op2, trio);
     632                 :             :   else
     633                 :             :     {
     634                 :             :       // If the LHS is not a pointer nor a singleton, then it is
     635                 :             :       // either VARYING or non-zero.
     636                 :           0 :       if (!lhs.undefined_p () && !range_includes_zero_p (lhs))
     637                 :           0 :         r.set_nonzero (type);
     638                 :             :       else
     639                 :           0 :         r.set_varying (type);
     640                 :             :     }
     641                 :          69 :   r.intersect (op2);
     642                 :          69 :   return true;
     643                 :             : }
     644                 :             : 
     645                 :             : bool
     646                 :      243611 : operator_cast::op1_range (irange &r, tree type,
     647                 :             :                           const prange &lhs,
     648                 :             :                           const irange &op2,
     649                 :             :                           relation_trio trio) const
     650                 :             : {
     651                 :      243611 :   if (lhs.undefined_p ())
     652                 :             :     return false;
     653                 :      243611 :   gcc_checking_assert (types_compatible_p (op2.type(), type));
     654                 :             : 
     655                 :             :   // Conversion from other pointers or a constant (including 0/NULL)
     656                 :             :   // are straightforward.
     657                 :      243611 :   if (POINTER_TYPE_P (lhs.type ())
     658                 :      243611 :       || (lhs.singleton_p ()
     659                 :           0 :           && TYPE_PRECISION (lhs.type ()) >= TYPE_PRECISION (type)))
     660                 :      243611 :     fold_range (r, type, lhs, op2, trio);
     661                 :             :   else
     662                 :             :     {
     663                 :             :       // If the LHS is not a pointer nor a singleton, then it is
     664                 :             :       // either VARYING or non-zero.
     665                 :           0 :       if (!lhs.undefined_p () && !range_includes_zero_p (lhs))
     666                 :           0 :         r.set_nonzero (type);
     667                 :             :       else
     668                 :           0 :         r.set_varying (type);
     669                 :             :     }
     670                 :      243611 :   r.intersect (op2);
     671                 :      243611 :   return true;
     672                 :             : }
     673                 :             : 
     674                 :             : bool
     675                 :      348439 : operator_cast::op1_range (prange &r, tree type,
     676                 :             :                           const irange &lhs,
     677                 :             :                           const prange &op2,
     678                 :             :                           relation_trio trio) const
     679                 :             : {
     680                 :      348439 :   if (lhs.undefined_p ())
     681                 :             :     return false;
     682                 :      348439 :   gcc_checking_assert (types_compatible_p (op2.type(), type));
     683                 :             : 
     684                 :             :   // Conversion from other pointers or a constant (including 0/NULL)
     685                 :             :   // are straightforward.
     686                 :      696878 :   if (POINTER_TYPE_P (lhs.type ())
     687                 :      696878 :       || (lhs.singleton_p ()
     688                 :        1109 :           && TYPE_PRECISION (lhs.type ()) >= TYPE_PRECISION (type)))
     689                 :        1099 :     fold_range (r, type, lhs, op2, trio);
     690                 :             :   else
     691                 :             :     {
     692                 :             :       // If the LHS is not a pointer nor a singleton, then it is
     693                 :             :       // either VARYING or non-zero.
     694                 :      347340 :       if (!lhs.undefined_p () && !range_includes_zero_p (lhs))
     695                 :      170687 :         r.set_nonzero (type);
     696                 :             :       else
     697                 :      176653 :         r.set_varying (type);
     698                 :             :     }
     699                 :      348439 :   r.intersect (op2);
     700                 :      348439 :   return true;
     701                 :             : }
     702                 :             : 
     703                 :             : relation_kind
     704                 :      136797 : operator_cast::lhs_op1_relation (const prange &lhs,
     705                 :             :                                  const prange &op1,
     706                 :             :                                  const prange &op2 ATTRIBUTE_UNUSED,
     707                 :             :                                  relation_kind) const
     708                 :             : {
     709                 :      136797 :   if (lhs.undefined_p () || op1.undefined_p ())
     710                 :             :     return VREL_VARYING;
     711                 :      136797 :   unsigned lhs_prec = TYPE_PRECISION (lhs.type ());
     712                 :      136797 :   unsigned op1_prec = TYPE_PRECISION (op1.type ());
     713                 :             :   // If the result gets sign extended into a larger type check first if this
     714                 :             :   // qualifies as a partial equivalence.
     715                 :      136797 :   if (TYPE_SIGN (op1.type ()) == SIGNED && lhs_prec > op1_prec)
     716                 :             :     {
     717                 :             :       // If the result is sign extended, and the LHS is larger than op1,
     718                 :             :       // check if op1's range can be negative as the sign extension will
     719                 :             :       // cause the upper bits to be 1 instead of 0, invalidating the PE.
     720                 :           0 :       int_range<3> negs = range_negatives (op1.type ());
     721                 :           0 :       negs.intersect (op1);
     722                 :           0 :       if (!negs.undefined_p ())
     723                 :           0 :         return VREL_VARYING;
     724                 :           0 :     }
     725                 :             : 
     726                 :      136797 :   unsigned prec = MIN (lhs_prec, op1_prec);
     727                 :      136797 :   return bits_to_pe (prec);
     728                 :             : }
     729                 :             : 
     730                 :             : relation_kind
     731                 :     1360592 : operator_cast::lhs_op1_relation (const prange &lhs,
     732                 :             :                                  const irange &op1,
     733                 :             :                                  const irange &op2 ATTRIBUTE_UNUSED,
     734                 :             :                                  relation_kind) const
     735                 :             : {
     736                 :     1360592 :   if (lhs.undefined_p () || op1.undefined_p ())
     737                 :             :     return VREL_VARYING;
     738                 :     1358823 :   unsigned lhs_prec = TYPE_PRECISION (lhs.type ());
     739                 :     1358823 :   unsigned op1_prec = TYPE_PRECISION (op1.type ());
     740                 :             :   // If the result gets sign extended into a larger type check first if this
     741                 :             :   // qualifies as a partial equivalence.
     742                 :     1358823 :   if (TYPE_SIGN (op1.type ()) == SIGNED && lhs_prec > op1_prec)
     743                 :             :     {
     744                 :             :       // If the result is sign extended, and the LHS is larger than op1,
     745                 :             :       // check if op1's range can be negative as the sign extension will
     746                 :             :       // cause the upper bits to be 1 instead of 0, invalidating the PE.
     747                 :         284 :       int_range<3> negs = range_negatives (op1.type ());
     748                 :         284 :       negs.intersect (op1);
     749                 :         284 :       if (!negs.undefined_p ())
     750                 :         276 :         return VREL_VARYING;
     751                 :         284 :     }
     752                 :             : 
     753                 :     1358547 :   unsigned prec = MIN (lhs_prec, op1_prec);
     754                 :     1358547 :   return bits_to_pe (prec);
     755                 :             : }
     756                 :             : 
     757                 :             : relation_kind
     758                 :     1888691 : operator_cast::lhs_op1_relation (const irange &lhs,
     759                 :             :                                  const prange &op1,
     760                 :             :                                  const prange &op2 ATTRIBUTE_UNUSED,
     761                 :             :                                  relation_kind) const
     762                 :             : {
     763                 :     1888691 :   if (lhs.undefined_p () || op1.undefined_p ())
     764                 :             :     return VREL_VARYING;
     765                 :     1887896 :   unsigned lhs_prec = TYPE_PRECISION (lhs.type ());
     766                 :     1887896 :   unsigned op1_prec = TYPE_PRECISION (op1.type ());
     767                 :             :   // If the result gets sign extended into a larger type check first if this
     768                 :             :   // qualifies as a partial equivalence.
     769                 :     1887896 :   if (TYPE_SIGN (op1.type ()) == SIGNED && lhs_prec > op1_prec)
     770                 :             :     {
     771                 :             :       // If the result is sign extended, and the LHS is larger than op1,
     772                 :             :       // check if op1's range can be negative as the sign extension will
     773                 :             :       // cause the upper bits to be 1 instead of 0, invalidating the PE.
     774                 :           0 :       int_range<3> negs = range_negatives (op1.type ());
     775                 :           0 :       negs.intersect (op1);
     776                 :           0 :       if (!negs.undefined_p ())
     777                 :           0 :         return VREL_VARYING;
     778                 :           0 :     }
     779                 :             : 
     780                 :     1887896 :   unsigned prec = MIN (lhs_prec, op1_prec);
     781                 :     1887896 :   return bits_to_pe (prec);
     782                 :             : }
     783                 :             : 
     784                 :             : bool
     785                 :         819 : operator_min::fold_range (prange &r, tree type,
     786                 :             :                           const prange &op1,
     787                 :             :                           const prange &op2,
     788                 :             :                           relation_trio) const
     789                 :             : {
     790                 :             :   // For MIN/MAX expressions with pointers, we only care about
     791                 :             :   // nullness.  If both are non null, then the result is nonnull.
     792                 :             :   // If both are null, then the result is null.  Otherwise they
     793                 :             :   // are varying.
     794                 :         819 :   if (!range_includes_zero_p (op1)
     795                 :         819 :       && !range_includes_zero_p (op2))
     796                 :         142 :     r.set_nonzero (type);
     797                 :         677 :   else if (op1.zero_p () && op2.zero_p ())
     798                 :           0 :     r.set_zero (type);
     799                 :             :   else
     800                 :         677 :     r.set_varying (type);
     801                 :             : 
     802                 :         819 :   update_known_bitmask (r, MIN_EXPR, op1, op2);
     803                 :         819 :   return true;
     804                 :             : }
     805                 :             : 
     806                 :             : bool
     807                 :         891 : operator_max::fold_range (prange &r, tree type,
     808                 :             :                           const prange &op1,
     809                 :             :                           const prange &op2,
     810                 :             :                           relation_trio) const
     811                 :             : {
     812                 :             :   // For MIN/MAX expressions with pointers, we only care about
     813                 :             :   // nullness.  If both are non null, then the result is nonnull.
     814                 :             :   // If both are null, then the result is null.  Otherwise they
     815                 :             :   // are varying.
     816                 :         891 :   if (!range_includes_zero_p (op1)
     817                 :         891 :       && !range_includes_zero_p (op2))
     818                 :         106 :     r.set_nonzero (type);
     819                 :         785 :   else if (op1.zero_p () && op2.zero_p ())
     820                 :           0 :     r.set_zero (type);
     821                 :             :   else
     822                 :         785 :     r.set_varying (type);
     823                 :             : 
     824                 :         891 :   update_known_bitmask (r, MAX_EXPR, op1, op2);
     825                 :         891 :   return true;
     826                 :             : }
     827                 :             : 
     828                 :             : bool
     829                 :      443777 : operator_addr_expr::op1_range (prange &r, tree type,
     830                 :             :                                const prange &lhs,
     831                 :             :                                const prange &op2,
     832                 :             :                                relation_trio) const
     833                 :             : {
     834                 :      443777 :   if (empty_range_varying (r, type, lhs, op2))
     835                 :           0 :     return true;
     836                 :             : 
     837                 :             :   // Return a non-null pointer of the LHS type (passed in op2), but only
     838                 :             :   // if we cant overflow, eitherwise a no-zero offset could wrap to zero.
     839                 :             :   // See PR 111009.
     840                 :      443777 :   if (!lhs.undefined_p ()
     841                 :      443777 :       && !range_includes_zero_p (lhs)
     842                 :      437756 :       && TYPE_OVERFLOW_UNDEFINED (type))
     843                 :      437738 :     r.set_nonzero (type);
     844                 :             :   else
     845                 :        6039 :     r.set_varying (type);
     846                 :             :   return true;
     847                 :             : }
     848                 :             : 
     849                 :             : bool
     850                 :         766 : operator_bitwise_and::fold_range (prange &r, tree type,
     851                 :             :                                   const prange &op1,
     852                 :             :                                   const prange &op2 ATTRIBUTE_UNUSED,
     853                 :             :                                   relation_trio) const
     854                 :             : {
     855                 :             :   // For pointer types, we are really only interested in asserting
     856                 :             :   // whether the expression evaluates to non-NULL.
     857                 :         766 :   if (op1.zero_p () || op2.zero_p ())
     858                 :           0 :     r.set_zero (type);
     859                 :             :   else
     860                 :         766 :     r.set_varying (type);
     861                 :             : 
     862                 :         766 :   update_known_bitmask (r, BIT_AND_EXPR, op1, op2);
     863                 :         766 :   return true;
     864                 :             : }
     865                 :             : 
     866                 :             : bool
     867                 :     6226946 : operator_equal::fold_range (irange &r, tree type,
     868                 :             :                             const prange &op1,
     869                 :             :                             const prange &op2,
     870                 :             :                             relation_trio rel) const
     871                 :             : {
     872                 :     6226946 :   if (relop_early_resolve (r, type, op1, op2, rel, VREL_EQ))
     873                 :             :     return true;
     874                 :             : 
     875                 :             :   // We can be sure the values are always equal or not if both ranges
     876                 :             :   // consist of a single value, and then compare them.
     877                 :     6211389 :   bool op1_const = wi::eq_p (op1.lower_bound (), op1.upper_bound ());
     878                 :     6211389 :   bool op2_const = wi::eq_p (op2.lower_bound (), op2.upper_bound ());
     879                 :     6211389 :   if (op1_const && op2_const)
     880                 :             :     {
     881                 :       25233 :       if (wi::eq_p (op1.lower_bound (), op2.upper_bound()))
     882                 :       25030 :         r = range_true (type);
     883                 :             :       else
     884                 :         203 :         r = range_false (type);
     885                 :             :     }
     886                 :             :   else
     887                 :             :     {
     888                 :             :       // If ranges do not intersect, we know the range is not equal,
     889                 :             :       // otherwise we don't know anything for sure.
     890                 :     6186156 :       prange tmp = op1;
     891                 :     6186156 :       tmp.intersect (op2);
     892                 :     6186156 :       if (tmp.undefined_p ())
     893                 :      172106 :         r = range_false (type);
     894                 :             :       // Check if a constant cannot satisfy the bitmask requirements.
     895                 :    11045458 :       else if (op2_const && !op1.get_bitmask ().member_p (op2.lower_bound ()))
     896                 :           0 :          r = range_false (type);
     897                 :     6023582 :       else if (op1_const && !op2.get_bitmask ().member_p (op1.lower_bound ()))
     898                 :           0 :          r = range_false (type);
     899                 :             :       else
     900                 :     6014050 :         r = range_true_and_false (type);
     901                 :     6186156 :     }
     902                 :             : 
     903                 :             :   //update_known_bitmask (r, EQ_EXPR, op1, op2);
     904                 :             :   return true;
     905                 :             : }
     906                 :             : 
     907                 :             : bool
     908                 :     3885839 : operator_equal::op1_range (prange &r, tree type,
     909                 :             :                            const irange &lhs,
     910                 :             :                            const prange &op2,
     911                 :             :                            relation_trio) const
     912                 :             : {
     913                 :     3885839 :   switch (get_bool_state (r, lhs, type))
     914                 :             :     {
     915                 :      965960 :     case BRS_TRUE:
     916                 :             :       // If it's true, the result is the same as OP2.
     917                 :      965960 :       r = op2;
     918                 :      965960 :       break;
     919                 :             : 
     920                 :     2912889 :     case BRS_FALSE:
     921                 :             :       // If the result is false, the only time we know anything is
     922                 :             :       // if OP2 is a constant.
     923                 :     2912889 :       if (!op2.undefined_p ()
     924                 :     8738667 :           && wi::eq_p (op2.lower_bound(), op2.upper_bound()))
     925                 :             :         {
     926                 :      983638 :           r = op2;
     927                 :      983638 :           r.invert ();
     928                 :             :         }
     929                 :             :       else
     930                 :     1929251 :         r.set_varying (type);
     931                 :             :       break;
     932                 :             : 
     933                 :             :     default:
     934                 :             :       break;
     935                 :             :     }
     936                 :     3885839 :   return true;
     937                 :             : }
     938                 :             : 
     939                 :             : bool
     940                 :     1286397 : operator_equal::op2_range (prange &r, tree type,
     941                 :             :                            const irange &lhs,
     942                 :             :                            const prange &op1,
     943                 :             :                            relation_trio rel) const
     944                 :             : {
     945                 :     1286397 :   return operator_equal::op1_range (r, type, lhs, op1, rel.swap_op1_op2 ());
     946                 :             : }
     947                 :             : 
     948                 :             : relation_kind
     949                 :     4572354 : operator_equal::op1_op2_relation (const irange &lhs, const prange &,
     950                 :             :                                   const prange &) const
     951                 :             : {
     952                 :     4572354 :   if (lhs.undefined_p ())
     953                 :             :     return VREL_UNDEFINED;
     954                 :             : 
     955                 :             :   // FALSE = op1 == op2 indicates NE_EXPR.
     956                 :     4572354 :   if (lhs.zero_p ())
     957                 :             :     return VREL_NE;
     958                 :             : 
     959                 :             :   // TRUE = op1 == op2 indicates EQ_EXPR.
     960                 :     1845539 :   if (!range_includes_zero_p (lhs))
     961                 :     1845460 :     return VREL_EQ;
     962                 :             :   return VREL_VARYING;
     963                 :             : }
     964                 :             : 
     965                 :             : bool
     966                 :     7617713 : operator_not_equal::fold_range (irange &r, tree type,
     967                 :             :                                 const prange &op1,
     968                 :             :                                 const prange &op2,
     969                 :             :                                 relation_trio rel) const
     970                 :             : {
     971                 :     7617713 :   if (relop_early_resolve (r, type, op1, op2, rel, VREL_NE))
     972                 :             :     return true;
     973                 :             : 
     974                 :             :   // We can be sure the values are always equal or not if both ranges
     975                 :             :   // consist of a single value, and then compare them.
     976                 :     7599233 :   bool op1_const = wi::eq_p (op1.lower_bound (), op1.upper_bound ());
     977                 :     7599233 :   bool op2_const = wi::eq_p (op2.lower_bound (), op2.upper_bound ());
     978                 :     7599233 :   if (op1_const && op2_const)
     979                 :             :     {
     980                 :       44962 :       if (wi::ne_p (op1.lower_bound (), op2.upper_bound()))
     981                 :         175 :         r = range_true (type);
     982                 :             :       else
     983                 :       44787 :         r = range_false (type);
     984                 :             :     }
     985                 :             :   else
     986                 :             :     {
     987                 :             :       // If ranges do not intersect, we know the range is not equal,
     988                 :             :       // otherwise we don't know anything for sure.
     989                 :     7554271 :       prange tmp = op1;
     990                 :     7554271 :       tmp.intersect (op2);
     991                 :     7554271 :       if (tmp.undefined_p ())
     992                 :      174553 :         r = range_true (type);
     993                 :             :       // Check if a constant cannot satisfy the bitmask requirements.
     994                 :    15472256 :       else if (op2_const && !op1.get_bitmask ().member_p (op2.lower_bound ()))
     995                 :          12 :          r = range_true (type);
     996                 :     7382746 :       else if (op1_const && !op2.get_bitmask ().member_p (op1.lower_bound ()))
     997                 :           0 :          r = range_true (type);
     998                 :             :       else
     999                 :     7379706 :         r = range_true_and_false (type);
    1000                 :     7554271 :     }
    1001                 :             : 
    1002                 :             :   //update_known_bitmask (r, NE_EXPR, op1, op2);
    1003                 :             :   return true;
    1004                 :             : }
    1005                 :             : 
    1006                 :             : bool
    1007                 :     4982469 : operator_not_equal::op1_range (prange &r, tree type,
    1008                 :             :                                const irange &lhs,
    1009                 :             :                                const prange &op2,
    1010                 :             :                                relation_trio) const
    1011                 :             : {
    1012                 :     4982469 :   switch (get_bool_state (r, lhs, type))
    1013                 :             :     {
    1014                 :     4046543 :     case BRS_TRUE:
    1015                 :             :       // If the result is true, the only time we know anything is if
    1016                 :             :       // OP2 is a constant.
    1017                 :     4046543 :       if (!op2.undefined_p ()
    1018                 :    12139629 :           && wi::eq_p (op2.lower_bound(), op2.upper_bound()))
    1019                 :             :         {
    1020                 :     1529364 :           r = op2;
    1021                 :     1529364 :           r.invert ();
    1022                 :             :         }
    1023                 :             :       else
    1024                 :     2517179 :         r.set_varying (type);
    1025                 :             :       break;
    1026                 :             : 
    1027                 :      912147 :     case BRS_FALSE:
    1028                 :             :       // If it's false, the result is the same as OP2.
    1029                 :      912147 :       r = op2;
    1030                 :      912147 :       break;
    1031                 :             : 
    1032                 :             :     default:
    1033                 :             :       break;
    1034                 :             :     }
    1035                 :     4982469 :   return true;
    1036                 :             : }
    1037                 :             : 
    1038                 :             : 
    1039                 :             : bool
    1040                 :     1510082 : operator_not_equal::op2_range (prange &r, tree type,
    1041                 :             :                                const irange &lhs,
    1042                 :             :                                const prange &op1,
    1043                 :             :                                relation_trio rel) const
    1044                 :             : {
    1045                 :     1510082 :   return operator_not_equal::op1_range (r, type, lhs, op1, rel.swap_op1_op2 ());
    1046                 :             : }
    1047                 :             : 
    1048                 :             : relation_kind
    1049                 :     5554892 : operator_not_equal::op1_op2_relation (const irange &lhs, const prange &,
    1050                 :             :                                       const prange &) const
    1051                 :             : {
    1052                 :     5554892 :   if (lhs.undefined_p ())
    1053                 :             :     return VREL_UNDEFINED;
    1054                 :             : 
    1055                 :             :   // FALSE = op1 != op2  indicates EQ_EXPR.
    1056                 :     5554892 :   if (lhs.zero_p ())
    1057                 :             :     return VREL_EQ;
    1058                 :             : 
    1059                 :             :   // TRUE = op1 != op2  indicates NE_EXPR.
    1060                 :     3791177 :   if (!range_includes_zero_p (lhs))
    1061                 :     3787734 :     return VREL_NE;
    1062                 :             :   return VREL_VARYING;
    1063                 :             : }
    1064                 :             : 
    1065                 :             : bool
    1066                 :      327006 : operator_lt::fold_range (irange &r, tree type,
    1067                 :             :                          const prange &op1,
    1068                 :             :                          const prange &op2,
    1069                 :             :                          relation_trio rel) const
    1070                 :             : {
    1071                 :      327006 :   if (relop_early_resolve (r, type, op1, op2, rel, VREL_LT))
    1072                 :             :     return true;
    1073                 :             : 
    1074                 :      326484 :   signop sign = TYPE_SIGN (op1.type ());
    1075                 :      326484 :   gcc_checking_assert (sign == TYPE_SIGN (op2.type ()));
    1076                 :             : 
    1077                 :      326484 :   if (wi::lt_p (op1.upper_bound (), op2.lower_bound (), sign))
    1078                 :           0 :     r = range_true (type);
    1079                 :      326484 :   else if (!wi::lt_p (op1.lower_bound (), op2.upper_bound (), sign))
    1080                 :          37 :     r = range_false (type);
    1081                 :             :   // Use nonzero bits to determine if < 0 is false.
    1082                 :      326447 :   else if (op2.zero_p () && !wi::neg_p (op1.get_nonzero_bits (), sign))
    1083                 :           0 :     r = range_false (type);
    1084                 :             :   else
    1085                 :      326447 :     r = range_true_and_false (type);
    1086                 :             : 
    1087                 :             :   //update_known_bitmask (r, LT_EXPR, op1, op2);
    1088                 :             :   return true;
    1089                 :             : }
    1090                 :             : 
    1091                 :             : bool
    1092                 :      266222 : operator_lt::op1_range (prange &r, tree type,
    1093                 :             :                         const irange &lhs,
    1094                 :             :                         const prange &op2,
    1095                 :             :                         relation_trio) const
    1096                 :             : {
    1097                 :      266222 :   if (op2.undefined_p ())
    1098                 :             :     return false;
    1099                 :             : 
    1100                 :      266222 :   switch (get_bool_state (r, lhs, type))
    1101                 :             :     {
    1102                 :       98337 :     case BRS_TRUE:
    1103                 :       98337 :       build_lt (r, type, op2);
    1104                 :       98337 :       break;
    1105                 :             : 
    1106                 :      167885 :     case BRS_FALSE:
    1107                 :      167885 :       build_ge (r, type, op2);
    1108                 :      167885 :       break;
    1109                 :             : 
    1110                 :             :     default:
    1111                 :             :       break;
    1112                 :             :     }
    1113                 :             :   return true;
    1114                 :             : }
    1115                 :             : 
    1116                 :             : bool
    1117                 :      168826 : operator_lt::op2_range (prange &r, tree type,
    1118                 :             :                         const irange &lhs,
    1119                 :             :                         const prange &op1,
    1120                 :             :                         relation_trio) const
    1121                 :             : {
    1122                 :      168826 :   if (op1.undefined_p ())
    1123                 :             :     return false;
    1124                 :             : 
    1125                 :      168826 :   switch (get_bool_state (r, lhs, type))
    1126                 :             :     {
    1127                 :       89902 :     case BRS_TRUE:
    1128                 :       89902 :       build_gt (r, type, op1);
    1129                 :       89902 :       break;
    1130                 :             : 
    1131                 :       78920 :     case BRS_FALSE:
    1132                 :       78920 :       build_le (r, type, op1);
    1133                 :       78920 :       break;
    1134                 :             : 
    1135                 :             :     default:
    1136                 :             :       break;
    1137                 :             :     }
    1138                 :             :   return true;
    1139                 :             : }
    1140                 :             : 
    1141                 :             : relation_kind
    1142                 :      713509 : operator_lt::op1_op2_relation (const irange &lhs, const prange &,
    1143                 :             :                                const prange &) const
    1144                 :             : {
    1145                 :      713509 :   if (lhs.undefined_p ())
    1146                 :             :     return VREL_UNDEFINED;
    1147                 :             : 
    1148                 :             :   // FALSE = op1 < op2 indicates GE_EXPR.
    1149                 :      713509 :   if (lhs.zero_p ())
    1150                 :             :     return VREL_GE;
    1151                 :             : 
    1152                 :             :   // TRUE = op1 < op2 indicates LT_EXPR.
    1153                 :      316437 :   if (!range_includes_zero_p (lhs))
    1154                 :      316433 :     return VREL_LT;
    1155                 :             :   return VREL_VARYING;
    1156                 :             : }
    1157                 :             : 
    1158                 :             : bool
    1159                 :      159558 : operator_le::fold_range (irange &r, tree type,
    1160                 :             :                          const prange &op1,
    1161                 :             :                          const prange &op2,
    1162                 :             :                          relation_trio rel) const
    1163                 :             : {
    1164                 :      159558 :   if (relop_early_resolve (r, type, op1, op2, rel, VREL_LE))
    1165                 :             :     return true;
    1166                 :             : 
    1167                 :      158454 :   signop sign = TYPE_SIGN (op1.type ());
    1168                 :      158454 :   gcc_checking_assert (sign == TYPE_SIGN (op2.type ()));
    1169                 :             : 
    1170                 :      158454 :   if (wi::le_p (op1.upper_bound (), op2.lower_bound (), sign))
    1171                 :          12 :     r = range_true (type);
    1172                 :      158442 :   else if (!wi::le_p (op1.lower_bound (), op2.upper_bound (), sign))
    1173                 :           5 :     r = range_false (type);
    1174                 :             :   else
    1175                 :      158437 :     r = range_true_and_false (type);
    1176                 :             : 
    1177                 :             :   //update_known_bitmask (r, LE_EXPR, op1, op2);
    1178                 :             :   return true;
    1179                 :             : }
    1180                 :             : 
    1181                 :             : bool
    1182                 :       86223 : operator_le::op1_range (prange &r, tree type,
    1183                 :             :                         const irange &lhs,
    1184                 :             :                         const prange &op2,
    1185                 :             :                         relation_trio) const
    1186                 :             : {
    1187                 :       86223 :   if (op2.undefined_p ())
    1188                 :             :     return false;
    1189                 :             : 
    1190                 :       86223 :   switch (get_bool_state (r, lhs, type))
    1191                 :             :     {
    1192                 :       14302 :     case BRS_TRUE:
    1193                 :       14302 :       build_le (r, type, op2);
    1194                 :       14302 :       break;
    1195                 :             : 
    1196                 :       71921 :     case BRS_FALSE:
    1197                 :       71921 :       build_gt (r, type, op2);
    1198                 :       71921 :       break;
    1199                 :             : 
    1200                 :             :     default:
    1201                 :             :       break;
    1202                 :             :     }
    1203                 :             :   return true;
    1204                 :             : }
    1205                 :             : 
    1206                 :             : bool
    1207                 :      136241 : operator_le::op2_range (prange &r, tree type,
    1208                 :             :                         const irange &lhs,
    1209                 :             :                         const prange &op1,
    1210                 :             :                         relation_trio) const
    1211                 :             : {
    1212                 :      136241 :   if (op1.undefined_p ())
    1213                 :             :     return false;
    1214                 :             : 
    1215                 :      136241 :   switch (get_bool_state (r, lhs, type))
    1216                 :             :     {
    1217                 :       12822 :     case BRS_TRUE:
    1218                 :       12822 :       build_ge (r, type, op1);
    1219                 :       12822 :       break;
    1220                 :             : 
    1221                 :      123419 :     case BRS_FALSE:
    1222                 :      123419 :       build_lt (r, type, op1);
    1223                 :      123419 :       break;
    1224                 :             : 
    1225                 :             :     default:
    1226                 :             :       break;
    1227                 :             :     }
    1228                 :             :   return true;
    1229                 :             : }
    1230                 :             : 
    1231                 :             : relation_kind
    1232                 :      416916 : operator_le::op1_op2_relation (const irange &lhs, const prange &,
    1233                 :             :                                const prange &) const
    1234                 :             : {
    1235                 :      416916 :   if (lhs.undefined_p ())
    1236                 :             :     return VREL_UNDEFINED;
    1237                 :             : 
    1238                 :             :   // FALSE = op1 <= op2 indicates GT_EXPR.
    1239                 :      416916 :   if (lhs.zero_p ())
    1240                 :             :     return VREL_GT;
    1241                 :             : 
    1242                 :             :   // TRUE = op1 <= op2 indicates LE_EXPR.
    1243                 :       81829 :   if (!range_includes_zero_p (lhs))
    1244                 :       81829 :     return VREL_LE;
    1245                 :             :   return VREL_VARYING;
    1246                 :             : }
    1247                 :             : 
    1248                 :             : bool
    1249                 :      306296 : operator_gt::fold_range (irange &r, tree type,
    1250                 :             :                          const prange &op1, const prange &op2,
    1251                 :             :                          relation_trio rel) const
    1252                 :             : {
    1253                 :      306296 :   if (relop_early_resolve (r, type, op1, op2, rel, VREL_GT))
    1254                 :             :     return true;
    1255                 :             : 
    1256                 :      305783 :   signop sign = TYPE_SIGN (op1.type ());
    1257                 :      305783 :   gcc_checking_assert (sign == TYPE_SIGN (op2.type ()));
    1258                 :             : 
    1259                 :      305783 :   if (wi::gt_p (op1.lower_bound (), op2.upper_bound (), sign))
    1260                 :           2 :     r = range_true (type);
    1261                 :      305781 :   else if (!wi::gt_p (op1.upper_bound (), op2.lower_bound (), sign))
    1262                 :           9 :     r = range_false (type);
    1263                 :             :   else
    1264                 :      305772 :     r = range_true_and_false (type);
    1265                 :             : 
    1266                 :             :   //update_known_bitmask (r, GT_EXPR, op1, op2);
    1267                 :             :   return true;
    1268                 :             : }
    1269                 :             : 
    1270                 :             : bool
    1271                 :      216552 : operator_gt::op1_range (prange &r, tree type,
    1272                 :             :                         const irange &lhs, const prange &op2,
    1273                 :             :                         relation_trio) const
    1274                 :             : {
    1275                 :      216552 :   if (op2.undefined_p ())
    1276                 :             :     return false;
    1277                 :             : 
    1278                 :      216552 :   switch (get_bool_state (r, lhs, type))
    1279                 :             :     {
    1280                 :      116829 :     case BRS_TRUE:
    1281                 :      116829 :       build_gt (r, type, op2);
    1282                 :      116829 :       break;
    1283                 :             : 
    1284                 :       99723 :     case BRS_FALSE:
    1285                 :       99723 :       build_le (r, type, op2);
    1286                 :       99723 :       break;
    1287                 :             : 
    1288                 :             :     default:
    1289                 :             :       break;
    1290                 :             :     }
    1291                 :             :   return true;
    1292                 :             : }
    1293                 :             : 
    1294                 :             : bool
    1295                 :      236393 : operator_gt::op2_range (prange &r, tree type,
    1296                 :             :                         const irange &lhs,
    1297                 :             :                         const prange &op1,
    1298                 :             :                         relation_trio) const
    1299                 :             : {
    1300                 :      236393 :   if (op1.undefined_p ())
    1301                 :             :     return false;
    1302                 :             : 
    1303                 :      236393 :   switch (get_bool_state (r, lhs, type))
    1304                 :             :     {
    1305                 :      118343 :     case BRS_TRUE:
    1306                 :      118343 :       build_lt (r, type, op1);
    1307                 :      118343 :       break;
    1308                 :             : 
    1309                 :      118050 :     case BRS_FALSE:
    1310                 :      118050 :       build_ge (r, type, op1);
    1311                 :      118050 :       break;
    1312                 :             : 
    1313                 :             :     default:
    1314                 :             :       break;
    1315                 :             :     }
    1316                 :             :   return true;
    1317                 :             : }
    1318                 :             : 
    1319                 :             : relation_kind
    1320                 :      734826 : operator_gt::op1_op2_relation (const irange &lhs, const prange &,
    1321                 :             :                                const prange &) const
    1322                 :             : {
    1323                 :      734826 :   if (lhs.undefined_p ())
    1324                 :             :     return VREL_UNDEFINED;
    1325                 :             : 
    1326                 :             :   // FALSE = op1 > op2 indicates LE_EXPR.
    1327                 :      734826 :   if (lhs.zero_p ())
    1328                 :             :     return VREL_LE;
    1329                 :             : 
    1330                 :             :   // TRUE = op1 > op2 indicates GT_EXPR.
    1331                 :      382559 :   if (!range_includes_zero_p (lhs))
    1332                 :      382559 :     return VREL_GT;
    1333                 :             :   return VREL_VARYING;
    1334                 :             : }
    1335                 :             : 
    1336                 :             : bool
    1337                 :      226986 : operator_ge::fold_range (irange &r, tree type,
    1338                 :             :                          const prange &op1,
    1339                 :             :                          const prange &op2,
    1340                 :             :                          relation_trio rel) const
    1341                 :             : {
    1342                 :      226986 :   if (relop_early_resolve (r, type, op1, op2, rel, VREL_GE))
    1343                 :             :     return true;
    1344                 :             : 
    1345                 :      226484 :   signop sign = TYPE_SIGN (op1.type ());
    1346                 :      226484 :   gcc_checking_assert (sign == TYPE_SIGN (op2.type ()));
    1347                 :             : 
    1348                 :      226484 :   if (wi::ge_p (op1.lower_bound (), op2.upper_bound (), sign))
    1349                 :          62 :     r = range_true (type);
    1350                 :      226422 :   else if (!wi::ge_p (op1.upper_bound (), op2.lower_bound (), sign))
    1351                 :           0 :     r = range_false (type);
    1352                 :             :   else
    1353                 :      226422 :     r = range_true_and_false (type);
    1354                 :             : 
    1355                 :             :   //update_known_bitmask (r, GE_EXPR, op1, op2);
    1356                 :             :   return true;
    1357                 :             : }
    1358                 :             : 
    1359                 :             : bool
    1360                 :      179873 : operator_ge::op1_range (prange &r, tree type,
    1361                 :             :                         const irange &lhs,
    1362                 :             :                         const prange &op2,
    1363                 :             :                         relation_trio) const
    1364                 :             : {
    1365                 :      179873 :   if (op2.undefined_p ())
    1366                 :             :     return false;
    1367                 :             : 
    1368                 :      179873 :   switch (get_bool_state (r, lhs, type))
    1369                 :             :     {
    1370                 :       13456 :     case BRS_TRUE:
    1371                 :       13456 :       build_ge (r, type, op2);
    1372                 :       13456 :       break;
    1373                 :             : 
    1374                 :      166417 :     case BRS_FALSE:
    1375                 :      166417 :       build_lt (r, type, op2);
    1376                 :      166417 :       break;
    1377                 :             : 
    1378                 :             :     default:
    1379                 :             :       break;
    1380                 :             :     }
    1381                 :             :   return true;
    1382                 :             : }
    1383                 :             : 
    1384                 :             : bool
    1385                 :       59818 : operator_ge::op2_range (prange &r, tree type,
    1386                 :             :                         const irange &lhs,
    1387                 :             :                         const prange &op1,
    1388                 :             :                         relation_trio) const
    1389                 :             : {
    1390                 :       59818 :   if (op1.undefined_p ())
    1391                 :             :     return false;
    1392                 :             : 
    1393                 :       59818 :   switch (get_bool_state (r, lhs, type))
    1394                 :             :     {
    1395                 :        9494 :     case BRS_TRUE:
    1396                 :        9494 :       build_le (r, type, op1);
    1397                 :        9494 :       break;
    1398                 :             : 
    1399                 :       50324 :     case BRS_FALSE:
    1400                 :       50324 :       build_gt (r, type, op1);
    1401                 :       50324 :       break;
    1402                 :             : 
    1403                 :             :     default:
    1404                 :             :       break;
    1405                 :             :     }
    1406                 :             :   return true;
    1407                 :             : }
    1408                 :             : 
    1409                 :             : relation_kind
    1410                 :      437555 : operator_ge::op1_op2_relation (const irange &lhs, const prange &,
    1411                 :             :                                const prange &) const
    1412                 :             : {
    1413                 :      437555 :   if (lhs.undefined_p ())
    1414                 :             :     return VREL_UNDEFINED;
    1415                 :             : 
    1416                 :             :   // FALSE = op1 >= op2 indicates LT_EXPR.
    1417                 :      437555 :   if (lhs.zero_p ())
    1418                 :             :     return VREL_LT;
    1419                 :             : 
    1420                 :             :   // TRUE = op1 >= op2 indicates GE_EXPR.
    1421                 :       74196 :   if (!range_includes_zero_p (lhs))
    1422                 :       74196 :     return VREL_GE;
    1423                 :             :   return VREL_VARYING;
    1424                 :             : }
    1425                 :             : 
    1426                 :             : // Initialize any pointer operators to the primary table
    1427                 :             : 
    1428                 :             : void
    1429                 :      285621 : range_op_table::initialize_pointer_ops ()
    1430                 :             : {
    1431                 :      285621 :   set (POINTER_PLUS_EXPR, op_pointer_plus);
    1432                 :      285621 :   set (POINTER_DIFF_EXPR, op_pointer_diff);
    1433                 :      285621 : }
        

Generated by: LCOV version 2.1-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.