LCOV - code coverage report
Current view: top level - gcc - fold-const.c (source / functions) Hit Total Coverage
Test: gcc.info Lines: 6434 7189 89.5 %
Date: 2020-04-04 11:58:09 Functions: 176 193 91.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* Fold a constant sub-tree into a single node for C-compiler
       2                 :            :    Copyright (C) 1987-2020 Free Software Foundation, Inc.
       3                 :            : 
       4                 :            : This file is part of GCC.
       5                 :            : 
       6                 :            : GCC is free software; you can redistribute it and/or modify it under
       7                 :            : the terms of the GNU General Public License as published by the Free
       8                 :            : Software Foundation; either version 3, or (at your option) any later
       9                 :            : version.
      10                 :            : 
      11                 :            : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      12                 :            : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13                 :            : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14                 :            : for more details.
      15                 :            : 
      16                 :            : You should have received a copy of the GNU General Public License
      17                 :            : along with GCC; see the file COPYING3.  If not see
      18                 :            : <http://www.gnu.org/licenses/>.  */
      19                 :            : 
      20                 :            : /*@@ This file should be rewritten to use an arbitrary precision
      21                 :            :   @@ representation for "struct tree_int_cst" and "struct tree_real_cst".
      22                 :            :   @@ Perhaps the routines could also be used for bc/dc, and made a lib.
      23                 :            :   @@ The routines that translate from the ap rep should
      24                 :            :   @@ warn if precision et. al. is lost.
      25                 :            :   @@ This would also make life easier when this technology is used
      26                 :            :   @@ for cross-compilers.  */
      27                 :            : 
      28                 :            : /* The entry points in this file are fold, size_int_wide and size_binop.
      29                 :            : 
      30                 :            :    fold takes a tree as argument and returns a simplified tree.
      31                 :            : 
      32                 :            :    size_binop takes a tree code for an arithmetic operation
      33                 :            :    and two operands that are trees, and produces a tree for the
      34                 :            :    result, assuming the type comes from `sizetype'.
      35                 :            : 
      36                 :            :    size_int takes an integer value, and creates a tree constant
      37                 :            :    with type from `sizetype'.
      38                 :            : 
      39                 :            :    Note: Since the folders get called on non-gimple code as well as
      40                 :            :    gimple code, we need to handle GIMPLE tuples as well as their
      41                 :            :    corresponding tree equivalents.  */
      42                 :            : 
      43                 :            : #include "config.h"
      44                 :            : #include "system.h"
      45                 :            : #include "coretypes.h"
      46                 :            : #include "backend.h"
      47                 :            : #include "target.h"
      48                 :            : #include "rtl.h"
      49                 :            : #include "tree.h"
      50                 :            : #include "gimple.h"
      51                 :            : #include "predict.h"
      52                 :            : #include "memmodel.h"
      53                 :            : #include "tm_p.h"
      54                 :            : #include "tree-ssa-operands.h"
      55                 :            : #include "optabs-query.h"
      56                 :            : #include "cgraph.h"
      57                 :            : #include "diagnostic-core.h"
      58                 :            : #include "flags.h"
      59                 :            : #include "alias.h"
      60                 :            : #include "fold-const.h"
      61                 :            : #include "fold-const-call.h"
      62                 :            : #include "stor-layout.h"
      63                 :            : #include "calls.h"
      64                 :            : #include "tree-iterator.h"
      65                 :            : #include "expr.h"
      66                 :            : #include "intl.h"
      67                 :            : #include "langhooks.h"
      68                 :            : #include "tree-eh.h"
      69                 :            : #include "gimplify.h"
      70                 :            : #include "tree-dfa.h"
      71                 :            : #include "builtins.h"
      72                 :            : #include "generic-match.h"
      73                 :            : #include "gimple-fold.h"
      74                 :            : #include "tree-into-ssa.h"
      75                 :            : #include "md5.h"
      76                 :            : #include "case-cfn-macros.h"
      77                 :            : #include "stringpool.h"
      78                 :            : #include "tree-vrp.h"
      79                 :            : #include "tree-ssanames.h"
      80                 :            : #include "selftest.h"
      81                 :            : #include "stringpool.h"
      82                 :            : #include "attribs.h"
      83                 :            : #include "tree-vector-builder.h"
      84                 :            : #include "vec-perm-indices.h"
      85                 :            : 
      86                 :            : /* Nonzero if we are folding constants inside an initializer; zero
      87                 :            :    otherwise.  */
      88                 :            : int folding_initializer = 0;
      89                 :            : 
      90                 :            : /* The following constants represent a bit based encoding of GCC's
      91                 :            :    comparison operators.  This encoding simplifies transformations
      92                 :            :    on relational comparison operators, such as AND and OR.  */
      93                 :            : enum comparison_code {
      94                 :            :   COMPCODE_FALSE = 0,
      95                 :            :   COMPCODE_LT = 1,
      96                 :            :   COMPCODE_EQ = 2,
      97                 :            :   COMPCODE_LE = 3,
      98                 :            :   COMPCODE_GT = 4,
      99                 :            :   COMPCODE_LTGT = 5,
     100                 :            :   COMPCODE_GE = 6,
     101                 :            :   COMPCODE_ORD = 7,
     102                 :            :   COMPCODE_UNORD = 8,
     103                 :            :   COMPCODE_UNLT = 9,
     104                 :            :   COMPCODE_UNEQ = 10,
     105                 :            :   COMPCODE_UNLE = 11,
     106                 :            :   COMPCODE_UNGT = 12,
     107                 :            :   COMPCODE_NE = 13,
     108                 :            :   COMPCODE_UNGE = 14,
     109                 :            :   COMPCODE_TRUE = 15
     110                 :            : };
     111                 :            : 
     112                 :            : static bool negate_expr_p (tree);
     113                 :            : static tree negate_expr (tree);
     114                 :            : static tree associate_trees (location_t, tree, tree, enum tree_code, tree);
     115                 :            : static enum comparison_code comparison_to_compcode (enum tree_code);
     116                 :            : static enum tree_code compcode_to_comparison (enum comparison_code);
     117                 :            : static bool twoval_comparison_p (tree, tree *, tree *);
     118                 :            : static tree eval_subst (location_t, tree, tree, tree, tree, tree);
     119                 :            : static tree optimize_bit_field_compare (location_t, enum tree_code,
     120                 :            :                                         tree, tree, tree);
     121                 :            : static bool simple_operand_p (const_tree);
     122                 :            : static bool simple_operand_p_2 (tree);
     123                 :            : static tree range_binop (enum tree_code, tree, tree, int, tree, int);
     124                 :            : static tree range_predecessor (tree);
     125                 :            : static tree range_successor (tree);
     126                 :            : static tree fold_range_test (location_t, enum tree_code, tree, tree, tree);
     127                 :            : static tree fold_cond_expr_with_comparison (location_t, tree, tree, tree, tree);
     128                 :            : static tree unextend (tree, int, int, tree);
     129                 :            : static tree extract_muldiv (tree, tree, enum tree_code, tree, bool *);
     130                 :            : static tree extract_muldiv_1 (tree, tree, enum tree_code, tree, bool *);
     131                 :            : static tree fold_binary_op_with_conditional_arg (location_t,
     132                 :            :                                                  enum tree_code, tree,
     133                 :            :                                                  tree, tree,
     134                 :            :                                                  tree, tree, int);
     135                 :            : static tree fold_negate_const (tree, tree);
     136                 :            : static tree fold_not_const (const_tree, tree);
     137                 :            : static tree fold_relational_const (enum tree_code, tree, tree, tree);
     138                 :            : static tree fold_convert_const (enum tree_code, tree, tree);
     139                 :            : static tree fold_view_convert_expr (tree, tree);
     140                 :            : static tree fold_negate_expr (location_t, tree);
     141                 :            : 
     142                 :            : 
     143                 :            : /* Return EXPR_LOCATION of T if it is not UNKNOWN_LOCATION.
     144                 :            :    Otherwise, return LOC.  */
     145                 :            : 
     146                 :            : static location_t
     147                 :     977776 : expr_location_or (tree t, location_t loc)
     148                 :            : {
     149                 :     101307 :   location_t tloc = EXPR_LOCATION (t);
     150                 :     967859 :   return tloc == UNKNOWN_LOCATION ? loc : tloc;
     151                 :            : }
     152                 :            : 
     153                 :            : /* Similar to protected_set_expr_location, but never modify x in place,
     154                 :            :    if location can and needs to be set, unshare it.  */
     155                 :            : 
     156                 :            : static inline tree
     157                 :     419741 : protected_set_expr_location_unshare (tree x, location_t loc)
     158                 :            : {
     159                 :     419741 :   if (CAN_HAVE_LOCATION_P (x)
     160                 :     358572 :       && EXPR_LOCATION (x) != loc
     161                 :      95794 :       && !(TREE_CODE (x) == SAVE_EXPR
     162                 :      48040 :            || TREE_CODE (x) == TARGET_EXPR
     163                 :            :            || TREE_CODE (x) == BIND_EXPR))
     164                 :            :     {
     165                 :      44940 :       x = copy_node (x);
     166                 :      44940 :       SET_EXPR_LOCATION (x, loc);
     167                 :            :     }
     168                 :     419741 :   return x;
     169                 :            : }
     170                 :            : 
     171                 :            : /* If ARG2 divides ARG1 with zero remainder, carries out the exact
     172                 :            :    division and returns the quotient.  Otherwise returns
     173                 :            :    NULL_TREE.  */
     174                 :            : 
     175                 :            : tree
     176                 :          0 : div_if_zero_remainder (const_tree arg1, const_tree arg2)
     177                 :            : {
     178                 :          0 :   widest_int quo;
     179                 :            : 
     180                 :          0 :   if (wi::multiple_of_p (wi::to_widest (arg1), wi::to_widest (arg2),
     181                 :            :                          SIGNED, &quo))
     182                 :          0 :     return wide_int_to_tree (TREE_TYPE (arg1), quo);
     183                 :            : 
     184                 :            :   return NULL_TREE; 
     185                 :            : }
     186                 :            : 
     187                 :            : /* This is nonzero if we should defer warnings about undefined
     188                 :            :    overflow.  This facility exists because these warnings are a
     189                 :            :    special case.  The code to estimate loop iterations does not want
     190                 :            :    to issue any warnings, since it works with expressions which do not
     191                 :            :    occur in user code.  Various bits of cleanup code call fold(), but
     192                 :            :    only use the result if it has certain characteristics (e.g., is a
     193                 :            :    constant); that code only wants to issue a warning if the result is
     194                 :            :    used.  */
     195                 :            : 
     196                 :            : static int fold_deferring_overflow_warnings;
     197                 :            : 
     198                 :            : /* If a warning about undefined overflow is deferred, this is the
     199                 :            :    warning.  Note that this may cause us to turn two warnings into
     200                 :            :    one, but that is fine since it is sufficient to only give one
     201                 :            :    warning per expression.  */
     202                 :            : 
     203                 :            : static const char* fold_deferred_overflow_warning;
     204                 :            : 
     205                 :            : /* If a warning about undefined overflow is deferred, this is the
     206                 :            :    level at which the warning should be emitted.  */
     207                 :            : 
     208                 :            : static enum warn_strict_overflow_code fold_deferred_overflow_code;
     209                 :            : 
     210                 :            : /* Start deferring overflow warnings.  We could use a stack here to
     211                 :            :    permit nested calls, but at present it is not necessary.  */
     212                 :            : 
     213                 :            : void
     214                 :  705916000 : fold_defer_overflow_warnings (void)
     215                 :            : {
     216                 :  705916000 :   ++fold_deferring_overflow_warnings;
     217                 :  705916000 : }
     218                 :            : 
     219                 :            : /* Stop deferring overflow warnings.  If there is a pending warning,
     220                 :            :    and ISSUE is true, then issue the warning if appropriate.  STMT is
     221                 :            :    the statement with which the warning should be associated (used for
     222                 :            :    location information); STMT may be NULL.  CODE is the level of the
     223                 :            :    warning--a warn_strict_overflow_code value.  This function will use
     224                 :            :    the smaller of CODE and the deferred code when deciding whether to
     225                 :            :    issue the warning.  CODE may be zero to mean to always use the
     226                 :            :    deferred code.  */
     227                 :            : 
     228                 :            : void
     229                 :  705916000 : fold_undefer_overflow_warnings (bool issue, const gimple *stmt, int code)
     230                 :            : {
     231                 :  705916000 :   const char *warnmsg;
     232                 :  705916000 :   location_t locus;
     233                 :            : 
     234                 :  705916000 :   gcc_assert (fold_deferring_overflow_warnings > 0);
     235                 :  705916000 :   --fold_deferring_overflow_warnings;
     236                 :  705916000 :   if (fold_deferring_overflow_warnings > 0)
     237                 :            :     {
     238                 :    5283960 :       if (fold_deferred_overflow_warning != NULL
     239                 :    1315400 :           && code != 0
     240                 :          0 :           && code < (int) fold_deferred_overflow_code)
     241                 :          0 :         fold_deferred_overflow_code = (enum warn_strict_overflow_code) code;
     242                 :    5283960 :       return;
     243                 :            :     }
     244                 :            : 
     245                 :  700632000 :   warnmsg = fold_deferred_overflow_warning;
     246                 :  700632000 :   fold_deferred_overflow_warning = NULL;
     247                 :            : 
     248                 :  700632000 :   if (!issue || warnmsg == NULL)
     249                 :            :     return;
     250                 :            : 
     251                 :       5225 :   if (gimple_no_warning_p (stmt))
     252                 :            :     return;
     253                 :            : 
     254                 :            :   /* Use the smallest code level when deciding to issue the
     255                 :            :      warning.  */
     256                 :       5225 :   if (code == 0 || code > (int) fold_deferred_overflow_code)
     257                 :       5224 :     code = fold_deferred_overflow_code;
     258                 :            : 
     259                 :       5225 :   if (!issue_strict_overflow_warning (code))
     260                 :            :     return;
     261                 :            : 
     262                 :          0 :   if (stmt == NULL)
     263                 :            :     locus = input_location;
     264                 :            :   else
     265                 :          0 :     locus = gimple_location (stmt);
     266                 :          0 :   warning_at (locus, OPT_Wstrict_overflow, "%s", warnmsg);
     267                 :            : }
     268                 :            : 
     269                 :            : /* Stop deferring overflow warnings, ignoring any deferred
     270                 :            :    warnings.  */
     271                 :            : 
     272                 :            : void
     273                 :   98660300 : fold_undefer_and_ignore_overflow_warnings (void)
     274                 :            : {
     275                 :   98660300 :   fold_undefer_overflow_warnings (false, NULL, 0);
     276                 :   98660300 : }
     277                 :            : 
     278                 :            : /* Whether we are deferring overflow warnings.  */
     279                 :            : 
     280                 :            : bool
     281                 :  182426000 : fold_deferring_overflow_warnings_p (void)
     282                 :            : {
     283                 :  182426000 :   return fold_deferring_overflow_warnings > 0;
     284                 :            : }
     285                 :            : 
     286                 :            : /* This is called when we fold something based on the fact that signed
     287                 :            :    overflow is undefined.  */
     288                 :            : 
     289                 :            : void
     290                 :    1227660 : fold_overflow_warning (const char* gmsgid, enum warn_strict_overflow_code wc)
     291                 :            : {
     292                 :    1227660 :   if (fold_deferring_overflow_warnings > 0)
     293                 :            :     {
     294                 :    1198930 :       if (fold_deferred_overflow_warning == NULL
     295                 :     591536 :           || wc < fold_deferred_overflow_code)
     296                 :            :         {
     297                 :     616655 :           fold_deferred_overflow_warning = gmsgid;
     298                 :     616655 :           fold_deferred_overflow_code = wc;
     299                 :            :         }
     300                 :            :     }
     301                 :      28731 :   else if (issue_strict_overflow_warning (wc))
     302                 :          7 :     warning (OPT_Wstrict_overflow, gmsgid);
     303                 :    1227660 : }
     304                 :            : 
     305                 :            : /* Return true if the built-in mathematical function specified by CODE
     306                 :            :    is odd, i.e. -f(x) == f(-x).  */
     307                 :            : 
     308                 :            : bool
     309                 :     477583 : negate_mathfn_p (combined_fn fn)
     310                 :            : {
     311                 :     477583 :   switch (fn)
     312                 :            :     {
     313                 :            :     CASE_CFN_ASIN:
     314                 :            :     CASE_CFN_ASINH:
     315                 :            :     CASE_CFN_ATAN:
     316                 :            :     CASE_CFN_ATANH:
     317                 :            :     CASE_CFN_CASIN:
     318                 :            :     CASE_CFN_CASINH:
     319                 :            :     CASE_CFN_CATAN:
     320                 :            :     CASE_CFN_CATANH:
     321                 :            :     CASE_CFN_CBRT:
     322                 :            :     CASE_CFN_CPROJ:
     323                 :            :     CASE_CFN_CSIN:
     324                 :            :     CASE_CFN_CSINH:
     325                 :            :     CASE_CFN_CTAN:
     326                 :            :     CASE_CFN_CTANH:
     327                 :            :     CASE_CFN_ERF:
     328                 :            :     CASE_CFN_LLROUND:
     329                 :            :     CASE_CFN_LROUND:
     330                 :            :     CASE_CFN_ROUND:
     331                 :            :     CASE_CFN_ROUNDEVEN:
     332                 :            :     CASE_CFN_ROUNDEVEN_FN:
     333                 :            :     CASE_CFN_SIN:
     334                 :            :     CASE_CFN_SINH:
     335                 :            :     CASE_CFN_TAN:
     336                 :            :     CASE_CFN_TANH:
     337                 :            :     CASE_CFN_TRUNC:
     338                 :            :       return true;
     339                 :            : 
     340                 :        248 :     CASE_CFN_LLRINT:
     341                 :        248 :     CASE_CFN_LRINT:
     342                 :        248 :     CASE_CFN_NEARBYINT:
     343                 :        248 :     CASE_CFN_RINT:
     344                 :        248 :       return !flag_rounding_math;
     345                 :            : 
     346                 :     474568 :     default:
     347                 :     474568 :       break;
     348                 :            :     }
     349                 :     474568 :   return false;
     350                 :            : }
     351                 :            : 
     352                 :            : /* Check whether we may negate an integer constant T without causing
     353                 :            :    overflow.  */
     354                 :            : 
     355                 :            : bool
     356                 :    1596470 : may_negate_without_overflow_p (const_tree t)
     357                 :            : {
     358                 :    1596470 :   tree type;
     359                 :            : 
     360                 :    1596470 :   gcc_assert (TREE_CODE (t) == INTEGER_CST);
     361                 :            : 
     362                 :    1596470 :   type = TREE_TYPE (t);
     363                 :    1596470 :   if (TYPE_UNSIGNED (type))
     364                 :            :     return false;
     365                 :            : 
     366                 :    1596470 :   return !wi::only_sign_bit_p (wi::to_wide (t));
     367                 :            : }
     368                 :            : 
     369                 :            : /* Determine whether an expression T can be cheaply negated using
     370                 :            :    the function negate_expr without introducing undefined overflow.  */
     371                 :            : 
     372                 :            : static bool
     373                 :    7354910 : negate_expr_p (tree t)
     374                 :            : {
     375                 :    7354910 :   tree type;
     376                 :            : 
     377                 :    7354910 :   if (t == 0)
     378                 :            :     return false;
     379                 :            : 
     380                 :    7354910 :   type = TREE_TYPE (t);
     381                 :            : 
     382                 :    7354910 :   STRIP_SIGN_NOPS (t);
     383                 :    7354910 :   switch (TREE_CODE (t))
     384                 :            :     {
     385                 :     909701 :     case INTEGER_CST:
     386                 :    1819400 :       if (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type))
     387                 :            :         return true;
     388                 :            : 
     389                 :            :       /* Check that -CST will not overflow type.  */
     390                 :     174761 :       return may_negate_without_overflow_p (t);
     391                 :        557 :     case BIT_NOT_EXPR:
     392                 :        557 :       return (INTEGRAL_TYPE_P (type)
     393                 :        939 :               && TYPE_OVERFLOW_WRAPS (type));
     394                 :            : 
     395                 :            :     case FIXED_CST:
     396                 :            :       return true;
     397                 :            : 
     398                 :       1310 :     case NEGATE_EXPR:
     399                 :       1380 :       return !TYPE_OVERFLOW_SANITIZED (type);
     400                 :            : 
     401                 :     132331 :     case REAL_CST:
     402                 :            :       /* We want to canonicalize to positive real constants.  Pretend
     403                 :            :          that only negative ones can be easily negated.  */
     404                 :     132331 :       return REAL_VALUE_NEGATIVE (TREE_REAL_CST (t));
     405                 :            : 
     406                 :        414 :     case COMPLEX_CST:
     407                 :        414 :       return negate_expr_p (TREE_REALPART (t))
     408                 :        522 :              && negate_expr_p (TREE_IMAGPART (t));
     409                 :            : 
     410                 :        258 :     case VECTOR_CST:
     411                 :        258 :       {
     412                 :        516 :         if (FLOAT_TYPE_P (TREE_TYPE (type)) || TYPE_OVERFLOW_WRAPS (type))
     413                 :            :           return true;
     414                 :            : 
     415                 :            :         /* Steps don't prevent negation.  */
     416                 :        258 :         unsigned int count = vector_cst_encoded_nelts (t);
     417                 :        516 :         for (unsigned int i = 0; i < count; ++i)
     418                 :        258 :           if (!negate_expr_p (VECTOR_CST_ENCODED_ELT (t, i)))
     419                 :            :             return false;
     420                 :            : 
     421                 :            :         return true;
     422                 :            :       }
     423                 :            : 
     424                 :        537 :     case COMPLEX_EXPR:
     425                 :        537 :       return negate_expr_p (TREE_OPERAND (t, 0))
     426                 :        537 :              && negate_expr_p (TREE_OPERAND (t, 1));
     427                 :            : 
     428                 :         33 :     case CONJ_EXPR:
     429                 :         33 :       return negate_expr_p (TREE_OPERAND (t, 0));
     430                 :            : 
     431                 :     611094 :     case PLUS_EXPR:
     432                 :     611094 :       if (HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (type))
     433                 :     611094 :           || HONOR_SIGNED_ZEROS (element_mode (type))
     434                 :    1213560 :           || (ANY_INTEGRAL_TYPE_P (type)
     435                 :     755340 :               && ! TYPE_OVERFLOW_WRAPS (type)))
     436                 :     161621 :         return false;
     437                 :            :       /* -(A + B) -> (-B) - A.  */
     438                 :     449473 :       if (negate_expr_p (TREE_OPERAND (t, 1)))
     439                 :            :         return true;
     440                 :            :       /* -(A + B) -> (-A) - B.  */
     441                 :      72097 :       return negate_expr_p (TREE_OPERAND (t, 0));
     442                 :            : 
     443                 :      37879 :     case MINUS_EXPR:
     444                 :            :       /* We can't turn -(A-B) into B-A when we honor signed zeros.  */
     445                 :      37879 :       return !HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (type))
     446                 :      37879 :              && !HONOR_SIGNED_ZEROS (element_mode (type))
     447                 :      71502 :              && (! ANY_INTEGRAL_TYPE_P (type)
     448                 :      54957 :                  || TYPE_OVERFLOW_WRAPS (type));
     449                 :            : 
     450                 :     418015 :     case MULT_EXPR:
     451                 :     418015 :       if (TYPE_UNSIGNED (type))
     452                 :            :         break;
     453                 :            :       /* INT_MIN/n * n doesn't overflow while negating one operand it does
     454                 :            :          if n is a (negative) power of two.  */
     455                 :     387846 :       if (INTEGRAL_TYPE_P (TREE_TYPE (t))
     456                 :     254827 :           && ! TYPE_OVERFLOW_WRAPS (TREE_TYPE (t))
     457                 :     319828 :           && ! ((TREE_CODE (TREE_OPERAND (t, 0)) == INTEGER_CST
     458                 :          0 :                  && (wi::popcount
     459                 :          0 :                      (wi::abs (wi::to_wide (TREE_OPERAND (t, 0))))) != 1)
     460                 :     125905 :                 || (TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST
     461                 :     123556 :                     && (wi::popcount
     462                 :     317479 :                         (wi::abs (wi::to_wide (TREE_OPERAND (t, 1))))) != 1)))
     463                 :            :         break;
     464                 :            : 
     465                 :            :       /* Fall through.  */
     466                 :            : 
     467                 :      91215 :     case RDIV_EXPR:
     468                 :      91215 :       if (! HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (TREE_TYPE (t))))
     469                 :      91214 :         return negate_expr_p (TREE_OPERAND (t, 1))
     470                 :      91214 :                || negate_expr_p (TREE_OPERAND (t, 0));
     471                 :            :       break;
     472                 :            : 
     473                 :       1815 :     case TRUNC_DIV_EXPR:
     474                 :       1815 :     case ROUND_DIV_EXPR:
     475                 :       1815 :     case EXACT_DIV_EXPR:
     476                 :       1815 :       if (TYPE_UNSIGNED (type))
     477                 :            :         break;
     478                 :            :       /* In general we can't negate A in A / B, because if A is INT_MIN and
     479                 :            :          B is not 1 we change the sign of the result.  */
     480                 :        331 :       if (TREE_CODE (TREE_OPERAND (t, 0)) == INTEGER_CST
     481                 :        331 :           && negate_expr_p (TREE_OPERAND (t, 0)))
     482                 :            :         return true;
     483                 :            :       /* In general we can't negate B in A / B, because if A is INT_MIN and
     484                 :            :          B is 1, we may turn this into INT_MIN / -1 which is undefined
     485                 :            :          and actually traps on some architectures.  */
     486                 :        332 :       if (! ANY_INTEGRAL_TYPE_P (TREE_TYPE (t))
     487                 :        281 :           || TYPE_OVERFLOW_WRAPS (TREE_TYPE (t))
     488                 :        281 :           || (TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST
     489                 :        108 :               && ! integer_onep (TREE_OPERAND (t, 1))))
     490                 :        159 :         return negate_expr_p (TREE_OPERAND (t, 1));
     491                 :            :       break;
     492                 :            : 
     493                 :    2712110 :     case NOP_EXPR:
     494                 :            :       /* Negate -((double)float) as (double)(-float).  */
     495                 :    2712110 :       if (TREE_CODE (type) == REAL_TYPE)
     496                 :            :         {
     497                 :       1246 :           tree tem = strip_float_extensions (t);
     498                 :       1246 :           if (tem != t)
     499                 :       1044 :             return negate_expr_p (tem);
     500                 :            :         }
     501                 :            :       break;
     502                 :            : 
     503                 :      56501 :     case CALL_EXPR:
     504                 :            :       /* Negate -f(x) as f(-x).  */
     505                 :      56501 :       if (negate_mathfn_p (get_call_combined_fn (t)))
     506                 :         35 :         return negate_expr_p (CALL_EXPR_ARG (t, 0));
     507                 :            :       break;
     508                 :            : 
     509                 :        321 :     case RSHIFT_EXPR:
     510                 :            :       /* Optimize -((int)x >> 31) into (unsigned)x >> 31 for int.  */
     511                 :        321 :       if (TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST)
     512                 :            :         {
     513                 :        255 :           tree op1 = TREE_OPERAND (t, 1);
     514                 :        255 :           if (wi::to_wide (op1) == TYPE_PRECISION (type) - 1)
     515                 :         72 :             return true;
     516                 :            :         }
     517                 :            :       break;
     518                 :            : 
     519                 :            :     default:
     520                 :            :       break;
     521                 :            :     }
     522                 :            :   return false;
     523                 :            : }
     524                 :            : 
     525                 :            : /* Given T, an expression, return a folded tree for -T or NULL_TREE, if no
     526                 :            :    simplification is possible.
     527                 :            :    If negate_expr_p would return true for T, NULL_TREE will never be
     528                 :            :    returned.  */
     529                 :            : 
     530                 :            : static tree
     531                 :   14629200 : fold_negate_expr_1 (location_t loc, tree t)
     532                 :            : {
     533                 :   14629200 :   tree type = TREE_TYPE (t);
     534                 :   14629200 :   tree tem;
     535                 :            : 
     536                 :   14629200 :   switch (TREE_CODE (t))
     537                 :            :     {
     538                 :            :     /* Convert - (~A) to A + 1.  */
     539                 :        167 :     case BIT_NOT_EXPR:
     540                 :        167 :       if (INTEGRAL_TYPE_P (type))
     541                 :        167 :         return fold_build2_loc (loc, PLUS_EXPR, type, TREE_OPERAND (t, 0),
     542                 :        167 :                                 build_one_cst (type));
     543                 :            :       break;
     544                 :            : 
     545                 :   11829400 :     case INTEGER_CST:
     546                 :   11829400 :       tem = fold_negate_const (t, type);
     547                 :   11829400 :       if (TREE_OVERFLOW (tem) == TREE_OVERFLOW (t)
     548                 :      12097 :           || (ANY_INTEGRAL_TYPE_P (type)
     549                 :      12097 :               && !TYPE_OVERFLOW_TRAPS (type)
     550                 :      18320 :               && TYPE_OVERFLOW_WRAPS (type))
     551                 :   11835600 :           || (flag_sanitize & SANITIZE_SI_OVERFLOW) == 0)
     552                 :   11829200 :         return tem;
     553                 :            :       break;
     554                 :            : 
     555                 :     383214 :     case POLY_INT_CST:
     556                 :     383214 :     case REAL_CST:
     557                 :     383214 :     case FIXED_CST:
     558                 :     383214 :       tem = fold_negate_const (t, type);
     559                 :     383214 :       return tem;
     560                 :            : 
     561                 :      62938 :     case COMPLEX_CST:
     562                 :      62938 :       {
     563                 :      62938 :         tree rpart = fold_negate_expr (loc, TREE_REALPART (t));
     564                 :      62938 :         tree ipart = fold_negate_expr (loc, TREE_IMAGPART (t));
     565                 :      62938 :         if (rpart && ipart)
     566                 :      62938 :           return build_complex (type, rpart, ipart);
     567                 :            :       }
     568                 :            :       break;
     569                 :            : 
     570                 :       1558 :     case VECTOR_CST:
     571                 :       1558 :       {
     572                 :       3116 :         tree_vector_builder elts;
     573                 :       1558 :         elts.new_unary_operation (type, t, true);
     574                 :       1558 :         unsigned int count = elts.encoded_nelts ();
     575                 :       3564 :         for (unsigned int i = 0; i < count; ++i)
     576                 :            :           {
     577                 :       2006 :             tree elt = fold_negate_expr (loc, VECTOR_CST_ELT (t, i));
     578                 :       2006 :             if (elt == NULL_TREE)
     579                 :       1558 :               return NULL_TREE;
     580                 :       2006 :             elts.quick_push (elt);
     581                 :            :           }
     582                 :            : 
     583                 :       1558 :         return elts.build ();
     584                 :            :       }
     585                 :            : 
     586                 :         32 :     case COMPLEX_EXPR:
     587                 :         32 :       if (negate_expr_p (t))
     588                 :         40 :         return fold_build2_loc (loc, COMPLEX_EXPR, type,
     589                 :         20 :                                 fold_negate_expr (loc, TREE_OPERAND (t, 0)),
     590                 :         40 :                                 fold_negate_expr (loc, TREE_OPERAND (t, 1)));
     591                 :            :       break;
     592                 :            : 
     593                 :         21 :     case CONJ_EXPR:
     594                 :         21 :       if (negate_expr_p (t))
     595                 :         21 :         return fold_build1_loc (loc, CONJ_EXPR, type,
     596                 :         42 :                                 fold_negate_expr (loc, TREE_OPERAND (t, 0)));
     597                 :            :       break;
     598                 :            : 
     599                 :       1228 :     case NEGATE_EXPR:
     600                 :       1249 :       if (!TYPE_OVERFLOW_SANITIZED (type))
     601                 :       1207 :         return TREE_OPERAND (t, 0);
     602                 :            :       break;
     603                 :            : 
     604                 :     407853 :     case PLUS_EXPR:
     605                 :     407853 :       if (!HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (type))
     606                 :     407853 :           && !HONOR_SIGNED_ZEROS (element_mode (type)))
     607                 :            :         {
     608                 :            :           /* -(A + B) -> (-B) - A.  */
     609                 :     407743 :           if (negate_expr_p (TREE_OPERAND (t, 1)))
     610                 :            :             {
     611                 :     378600 :               tem = negate_expr (TREE_OPERAND (t, 1));
     612                 :     378600 :               return fold_build2_loc (loc, MINUS_EXPR, type,
     613                 :     757200 :                                       tem, TREE_OPERAND (t, 0));
     614                 :            :             }
     615                 :            : 
     616                 :            :           /* -(A + B) -> (-A) - B.  */
     617                 :      29143 :           if (negate_expr_p (TREE_OPERAND (t, 0)))
     618                 :            :             {
     619                 :       1132 :               tem = negate_expr (TREE_OPERAND (t, 0));
     620                 :       1132 :               return fold_build2_loc (loc, MINUS_EXPR, type,
     621                 :       2264 :                                       tem, TREE_OPERAND (t, 1));
     622                 :            :             }
     623                 :            :         }
     624                 :            :       break;
     625                 :            : 
     626                 :      12261 :     case MINUS_EXPR:
     627                 :            :       /* - (A - B) -> B - A  */
     628                 :      12261 :       if (!HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (type))
     629                 :      12261 :           && !HONOR_SIGNED_ZEROS (element_mode (type)))
     630                 :      10404 :         return fold_build2_loc (loc, MINUS_EXPR, type,
     631                 :      20808 :                                 TREE_OPERAND (t, 1), TREE_OPERAND (t, 0));
     632                 :            :       break;
     633                 :            : 
     634                 :     115061 :     case MULT_EXPR:
     635                 :     115061 :       if (TYPE_UNSIGNED (type))
     636                 :            :         break;
     637                 :            : 
     638                 :            :       /* Fall through.  */
     639                 :            : 
     640                 :      65092 :     case RDIV_EXPR:
     641                 :      65092 :       if (! HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (type)))
     642                 :            :         {
     643                 :      65092 :           tem = TREE_OPERAND (t, 1);
     644                 :      65092 :           if (negate_expr_p (tem))
     645                 :     127616 :             return fold_build2_loc (loc, TREE_CODE (t), type,
     646                 :     127616 :                                     TREE_OPERAND (t, 0), negate_expr (tem));
     647                 :       1284 :           tem = TREE_OPERAND (t, 0);
     648                 :       1284 :           if (negate_expr_p (tem))
     649                 :         70 :             return fold_build2_loc (loc, TREE_CODE (t), type,
     650                 :        140 :                                     negate_expr (tem), TREE_OPERAND (t, 1));
     651                 :            :         }
     652                 :            :       break;
     653                 :            : 
     654                 :       1406 :     case TRUNC_DIV_EXPR:
     655                 :       1406 :     case ROUND_DIV_EXPR:
     656                 :       1406 :     case EXACT_DIV_EXPR:
     657                 :       1406 :       if (TYPE_UNSIGNED (type))
     658                 :            :         break;
     659                 :            :       /* In general we can't negate A in A / B, because if A is INT_MIN and
     660                 :            :          B is not 1 we change the sign of the result.  */
     661                 :        485 :       if (TREE_CODE (TREE_OPERAND (t, 0)) == INTEGER_CST
     662                 :        485 :           && negate_expr_p (TREE_OPERAND (t, 0)))
     663                 :        297 :         return fold_build2_loc (loc, TREE_CODE (t), type,
     664                 :        297 :                                 negate_expr (TREE_OPERAND (t, 0)),
     665                 :        594 :                                 TREE_OPERAND (t, 1));
     666                 :            :       /* In general we can't negate B in A / B, because if A is INT_MIN and
     667                 :            :          B is 1, we may turn this into INT_MIN / -1 which is undefined
     668                 :            :          and actually traps on some architectures.  */
     669                 :        376 :       if ((! ANY_INTEGRAL_TYPE_P (TREE_TYPE (t))
     670                 :        326 :            || TYPE_OVERFLOW_WRAPS (TREE_TYPE (t))
     671                 :        138 :            || (TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST
     672                 :        115 :                && ! integer_onep (TREE_OPERAND (t, 1))))
     673                 :        353 :           && negate_expr_p (TREE_OPERAND (t, 1)))
     674                 :        318 :         return fold_build2_loc (loc, TREE_CODE (t), type,
     675                 :        159 :                                 TREE_OPERAND (t, 0),
     676                 :        318 :                                 negate_expr (TREE_OPERAND (t, 1)));
     677                 :            :       break;
     678                 :            : 
     679                 :     955943 :     case NOP_EXPR:
     680                 :            :       /* Convert -((double)float) into (double)(-float).  */
     681                 :     955943 :       if (TREE_CODE (type) == REAL_TYPE)
     682                 :            :         {
     683                 :       1580 :           tem = strip_float_extensions (t);
     684                 :       1580 :           if (tem != t && negate_expr_p (tem))
     685                 :          0 :             return fold_convert_loc (loc, type, negate_expr (tem));
     686                 :            :         }
     687                 :            :       break;
     688                 :            : 
     689                 :      11820 :     case CALL_EXPR:
     690                 :            :       /* Negate -f(x) as f(-x).  */
     691                 :      11820 :       if (negate_mathfn_p (get_call_combined_fn (t))
     692                 :      13027 :           && negate_expr_p (CALL_EXPR_ARG (t, 0)))
     693                 :            :         {
     694                 :       1191 :           tree fndecl, arg;
     695                 :            : 
     696                 :       1191 :           fndecl = get_callee_fndecl (t);
     697                 :       1191 :           arg = negate_expr (CALL_EXPR_ARG (t, 0));
     698                 :       1191 :           return build_call_expr_loc (loc, fndecl, 1, arg);
     699                 :            :         }
     700                 :            :       break;
     701                 :            : 
     702                 :        145 :     case RSHIFT_EXPR:
     703                 :            :       /* Optimize -((int)x >> 31) into (unsigned)x >> 31 for int.  */
     704                 :        145 :       if (TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST)
     705                 :            :         {
     706                 :        128 :           tree op1 = TREE_OPERAND (t, 1);
     707                 :        128 :           if (wi::to_wide (op1) == TYPE_PRECISION (type) - 1)
     708                 :            :             {
     709                 :         91 :               tree ntype = TYPE_UNSIGNED (type)
     710                 :         12 :                            ? signed_type_for (type)
     711                 :         91 :                            : unsigned_type_for (type);
     712                 :         91 :               tree temp = fold_convert_loc (loc, ntype, TREE_OPERAND (t, 0));
     713                 :         91 :               temp = fold_build2_loc (loc, RSHIFT_EXPR, ntype, temp, op1);
     714                 :         91 :               return fold_convert_loc (loc, type, temp);
     715                 :            :             }
     716                 :            :         }
     717                 :            :       break;
     718                 :            : 
     719                 :            :     default:
     720                 :            :       break;
     721                 :            :     }
     722                 :            : 
     723                 :            :   return NULL_TREE;
     724                 :            : }
     725                 :            : 
     726                 :            : /* A wrapper for fold_negate_expr_1.  */
     727                 :            : 
     728                 :            : static tree
     729                 :   14629200 : fold_negate_expr (location_t loc, tree t)
     730                 :            : {
     731                 :   14629200 :   tree type = TREE_TYPE (t);
     732                 :   14629200 :   STRIP_SIGN_NOPS (t);
     733                 :   14629200 :   tree tem = fold_negate_expr_1 (loc, t);
     734                 :   14629200 :   if (tem == NULL_TREE)
     735                 :            :     return NULL_TREE;
     736                 :   12734100 :   return fold_convert_loc (loc, type, tem);
     737                 :            : }
     738                 :            : 
     739                 :            : /* Like fold_negate_expr, but return a NEGATE_EXPR tree, if T cannot be
     740                 :            :    negated in a simpler way.  Also allow for T to be NULL_TREE, in which case
     741                 :            :    return NULL_TREE. */
     742                 :            : 
     743                 :            : static tree
     744                 :    2044460 : negate_expr (tree t)
     745                 :            : {
     746                 :    2044460 :   tree type, tem;
     747                 :    2044460 :   location_t loc;
     748                 :            : 
     749                 :    2044460 :   if (t == NULL_TREE)
     750                 :            :     return NULL_TREE;
     751                 :            : 
     752                 :    2044460 :   loc = EXPR_LOCATION (t);
     753                 :    2044460 :   type = TREE_TYPE (t);
     754                 :    2044460 :   STRIP_SIGN_NOPS (t);
     755                 :            : 
     756                 :    2044460 :   tem = fold_negate_expr (loc, t);
     757                 :    2044460 :   if (!tem)
     758                 :     928289 :     tem = build1_loc (loc, NEGATE_EXPR, TREE_TYPE (t), t);
     759                 :    2044460 :   return fold_convert_loc (loc, type, tem);
     760                 :            : }
     761                 :            : 
     762                 :            : /* Split a tree IN into a constant, literal and variable parts that could be
     763                 :            :    combined with CODE to make IN.  "constant" means an expression with
     764                 :            :    TREE_CONSTANT but that isn't an actual constant.  CODE must be a
     765                 :            :    commutative arithmetic operation.  Store the constant part into *CONP,
     766                 :            :    the literal in *LITP and return the variable part.  If a part isn't
     767                 :            :    present, set it to null.  If the tree does not decompose in this way,
     768                 :            :    return the entire tree as the variable part and the other parts as null.
     769                 :            : 
     770                 :            :    If CODE is PLUS_EXPR we also split trees that use MINUS_EXPR.  In that
     771                 :            :    case, we negate an operand that was subtracted.  Except if it is a
     772                 :            :    literal for which we use *MINUS_LITP instead.
     773                 :            : 
     774                 :            :    If NEGATE_P is true, we are negating all of IN, again except a literal
     775                 :            :    for which we use *MINUS_LITP instead.  If a variable part is of pointer
     776                 :            :    type, it is negated after converting to TYPE.  This prevents us from
     777                 :            :    generating illegal MINUS pointer expression.  LOC is the location of
     778                 :            :    the converted variable part.
     779                 :            : 
     780                 :            :    If IN is itself a literal or constant, return it as appropriate.
     781                 :            : 
     782                 :            :    Note that we do not guarantee that any of the three values will be the
     783                 :            :    same type as IN, but they will have the same signedness and mode.  */
     784                 :            : 
     785                 :            : static tree
     786                 :   97723400 : split_tree (tree in, tree type, enum tree_code code,
     787                 :            :             tree *minus_varp, tree *conp, tree *minus_conp,
     788                 :            :             tree *litp, tree *minus_litp, int negate_p)
     789                 :            : {
     790                 :   97723400 :   tree var = 0;
     791                 :   97723400 :   *minus_varp = 0;
     792                 :   97723400 :   *conp = 0;
     793                 :   97723400 :   *minus_conp = 0;
     794                 :   97723400 :   *litp = 0;
     795                 :   97723400 :   *minus_litp = 0;
     796                 :            : 
     797                 :            :   /* Strip any conversions that don't change the machine mode or signedness.  */
     798                 :   97723400 :   STRIP_SIGN_NOPS (in);
     799                 :            : 
     800                 :   97723400 :   if (TREE_CODE (in) == INTEGER_CST || TREE_CODE (in) == REAL_CST
     801                 :   62014300 :       || TREE_CODE (in) == FIXED_CST)
     802                 :   35709200 :     *litp = in;
     803                 :   62014300 :   else if (TREE_CODE (in) == code
     804                 :  121616000 :            || ((! FLOAT_TYPE_P (TREE_TYPE (in)) || flag_associative_math)
     805                 :   59601600 :                && ! SAT_FIXED_POINT_TYPE_P (TREE_TYPE (in))
     806                 :            :                /* We can associate addition and subtraction together (even
     807                 :            :                   though the C standard doesn't say so) for integers because
     808                 :            :                   the value is not affected.  For reals, the value might be
     809                 :            :                   affected, so we can't.  */
     810                 :   59601600 :                && ((code == PLUS_EXPR && TREE_CODE (in) == POINTER_PLUS_EXPR)
     811                 :   28563500 :                    || (code == PLUS_EXPR && TREE_CODE (in) == MINUS_EXPR)
     812                 :   58577100 :                    || (code == MINUS_EXPR
     813                 :    9122940 :                        && (TREE_CODE (in) == PLUS_EXPR
     814                 :    8346380 :                            || TREE_CODE (in) == POINTER_PLUS_EXPR)))))
     815                 :            :     {
     816                 :    4433380 :       tree op0 = TREE_OPERAND (in, 0);
     817                 :    4433380 :       tree op1 = TREE_OPERAND (in, 1);
     818                 :    4433380 :       int neg1_p = TREE_CODE (in) == MINUS_EXPR;
     819                 :    4433380 :       int neg_litp_p = 0, neg_conp_p = 0, neg_var_p = 0;
     820                 :            : 
     821                 :            :       /* First see if either of the operands is a literal, then a constant.  */
     822                 :    4433380 :       if (TREE_CODE (op0) == INTEGER_CST || TREE_CODE (op0) == REAL_CST
     823                 :    4326730 :           || TREE_CODE (op0) == FIXED_CST)
     824                 :     106648 :         *litp = op0, op0 = 0;
     825                 :    4326730 :       else if (TREE_CODE (op1) == INTEGER_CST || TREE_CODE (op1) == REAL_CST
     826                 :    2843090 :                || TREE_CODE (op1) == FIXED_CST)
     827                 :    1483640 :         *litp = op1, neg_litp_p = neg1_p, op1 = 0;
     828                 :            : 
     829                 :    8760110 :       if (op0 != 0 && TREE_CONSTANT (op0))
     830                 :      12460 :         *conp = op0, op0 = 0;
     831                 :    7369640 :       else if (op1 != 0 && TREE_CONSTANT (op1))
     832                 :      23040 :         *conp = op1, neg_conp_p = neg1_p, op1 = 0;
     833                 :            : 
     834                 :            :       /* If we haven't dealt with either operand, this is not a case we can
     835                 :            :          decompose.  Otherwise, VAR is either of the ones remaining, if any.  */
     836                 :    4433380 :       if (op0 != 0 && op1 != 0)
     837                 :            :         var = in;
     838                 :    1609840 :       else if (op0 != 0)
     839                 :            :         var = op0;
     840                 :            :       else
     841                 :     119108 :         var = op1, neg_var_p = neg1_p;
     842                 :            : 
     843                 :            :       /* Now do any needed negations.  */
     844                 :    4433380 :       if (neg_litp_p)
     845                 :      13674 :         *minus_litp = *litp, *litp = 0;
     846                 :    4433380 :       if (neg_conp_p && *conp)
     847                 :       5412 :         *minus_conp = *conp, *conp = 0;
     848                 :    4433380 :       if (neg_var_p && var)
     849                 :     102549 :         *minus_varp = var, var = 0;
     850                 :            :     }
     851                 :   57580900 :   else if (TREE_CONSTANT (in))
     852                 :     237559 :     *conp = in;
     853                 :   57343300 :   else if (TREE_CODE (in) == BIT_NOT_EXPR
     854                 :     217382 :            && code == PLUS_EXPR)
     855                 :            :     {
     856                 :            :       /* -1 - X is folded to ~X, undo that here.  Do _not_ do this
     857                 :            :          when IN is constant.  */
     858                 :     197538 :       *litp = build_minus_one_cst (type);
     859                 :     197538 :       *minus_varp = TREE_OPERAND (in, 0);
     860                 :            :     }
     861                 :            :   else
     862                 :            :     var = in;
     863                 :            : 
     864                 :   97723400 :   if (negate_p)
     865                 :            :     {
     866                 :    5072250 :       if (*litp)
     867                 :     589812 :         *minus_litp = *litp, *litp = 0;
     868                 :    4482440 :       else if (*minus_litp)
     869                 :         21 :         *litp = *minus_litp, *minus_litp = 0;
     870                 :    5072250 :       if (*conp)
     871                 :      27392 :         *minus_conp = *conp, *conp = 0;
     872                 :    5044860 :       else if (*minus_conp)
     873                 :          0 :         *conp = *minus_conp, *minus_conp = 0;
     874                 :    5072250 :       if (var)
     875                 :    5029710 :         *minus_varp = var, var = 0;
     876                 :      42541 :       else if (*minus_varp)
     877                 :        569 :         var = *minus_varp, *minus_varp = 0;
     878                 :            :     }
     879                 :            : 
     880                 :   97723400 :   if (*litp
     881                 :   97723400 :       && TREE_OVERFLOW_P (*litp))
     882                 :      14864 :     *litp = drop_tree_overflow (*litp);
     883                 :   97723400 :   if (*minus_litp
     884                 :   97723400 :       && TREE_OVERFLOW_P (*minus_litp))
     885                 :          0 :     *minus_litp = drop_tree_overflow (*minus_litp);
     886                 :            : 
     887                 :   97723400 :   return var;
     888                 :            : }
     889                 :            : 
     890                 :            : /* Re-associate trees split by the above function.  T1 and T2 are
     891                 :            :    either expressions to associate or null.  Return the new
     892                 :            :    expression, if any.  LOC is the location of the new expression.  If
     893                 :            :    we build an operation, do it in TYPE and with CODE.  */
     894                 :            : 
     895                 :            : static tree
     896                 :   10670200 : associate_trees (location_t loc, tree t1, tree t2, enum tree_code code, tree type)
     897                 :            : {
     898                 :   10670200 :   if (t1 == 0)
     899                 :            :     {
     900                 :    6780740 :       gcc_assert (t2 == 0 || code != MINUS_EXPR);
     901                 :            :       return t2;
     902                 :            :     }
     903                 :    3889420 :   else if (t2 == 0)
     904                 :            :     return t1;
     905                 :            : 
     906                 :            :   /* If either input is CODE, a PLUS_EXPR, or a MINUS_EXPR, don't
     907                 :            :      try to fold this since we will have infinite recursion.  But do
     908                 :            :      deal with any NEGATE_EXPRs.  */
     909                 :    2117870 :   if (TREE_CODE (t1) == code || TREE_CODE (t2) == code
     910                 :    1648520 :       || TREE_CODE (t1) == PLUS_EXPR || TREE_CODE (t2) == PLUS_EXPR
     911                 :    1623900 :       || TREE_CODE (t1) == MINUS_EXPR || TREE_CODE (t2) == MINUS_EXPR)
     912                 :            :     {
     913                 :     816555 :       if (code == PLUS_EXPR)
     914                 :            :         {
     915                 :     386876 :           if (TREE_CODE (t1) == NEGATE_EXPR)
     916                 :         12 :             return build2_loc (loc, MINUS_EXPR, type,
     917                 :            :                                fold_convert_loc (loc, type, t2),
     918                 :            :                                fold_convert_loc (loc, type,
     919                 :         12 :                                                  TREE_OPERAND (t1, 0)));
     920                 :     386864 :           else if (TREE_CODE (t2) == NEGATE_EXPR)
     921                 :          2 :             return build2_loc (loc, MINUS_EXPR, type,
     922                 :            :                                fold_convert_loc (loc, type, t1),
     923                 :            :                                fold_convert_loc (loc, type,
     924                 :          2 :                                                  TREE_OPERAND (t2, 0)));
     925                 :     386862 :           else if (integer_zerop (t2))
     926                 :      14923 :             return fold_convert_loc (loc, type, t1);
     927                 :            :         }
     928                 :     429679 :       else if (code == MINUS_EXPR)
     929                 :            :         {
     930                 :     422041 :           if (integer_zerop (t2))
     931                 :         75 :             return fold_convert_loc (loc, type, t1);
     932                 :            :         }
     933                 :            : 
     934                 :     801543 :       return build2_loc (loc, code, type, fold_convert_loc (loc, type, t1),
     935                 :            :                          fold_convert_loc (loc, type, t2));
     936                 :            :     }
     937                 :            : 
     938                 :    1301310 :   return fold_build2_loc (loc, code, type, fold_convert_loc (loc, type, t1),
     939                 :    1301310 :                           fold_convert_loc (loc, type, t2));
     940                 :            : }
     941                 :            : 
     942                 :            : /* Check whether TYPE1 and TYPE2 are equivalent integer types, suitable
     943                 :            :    for use in int_const_binop, size_binop and size_diffop.  */
     944                 :            : 
     945                 :            : static bool
     946                 :  648202000 : int_binop_types_match_p (enum tree_code code, const_tree type1, const_tree type2)
     947                 :            : {
     948                 :  648202000 :   if (!INTEGRAL_TYPE_P (type1) && !POINTER_TYPE_P (type1))
     949                 :            :     return false;
     950                 :  648202000 :   if (!INTEGRAL_TYPE_P (type2) && !POINTER_TYPE_P (type2))
     951                 :            :     return false;
     952                 :            : 
     953                 :  648202000 :   switch (code)
     954                 :            :     {
     955                 :            :     case LSHIFT_EXPR:
     956                 :            :     case RSHIFT_EXPR:
     957                 :            :     case LROTATE_EXPR:
     958                 :            :     case RROTATE_EXPR:
     959                 :            :       return true;
     960                 :            : 
     961                 :  648202000 :     default:
     962                 :  648202000 :       break;
     963                 :            :     }
     964                 :            : 
     965                 :  648202000 :   return TYPE_UNSIGNED (type1) == TYPE_UNSIGNED (type2)
     966                 :  648202000 :          && TYPE_PRECISION (type1) == TYPE_PRECISION (type2)
     967                 : 1944610000 :          && TYPE_MODE (type1) == TYPE_MODE (type2);
     968                 :            : }
     969                 :            : 
     970                 :            : /* Combine two wide ints ARG1 and ARG2 under operation CODE to produce
     971                 :            :    a new constant in RES.  Return FALSE if we don't know how to
     972                 :            :    evaluate CODE at compile-time.  */
     973                 :            : 
     974                 :            : bool
     975                 :  443657000 : wide_int_binop (wide_int &res,
     976                 :            :                 enum tree_code code, const wide_int &arg1, const wide_int &arg2,
     977                 :            :                 signop sign, wi::overflow_type *overflow)
     978                 :            : {
     979                 :  443657000 :   wide_int tmp;
     980                 :  443657000 :   *overflow = wi::OVF_NONE;
     981                 :  443657000 :   switch (code)
     982                 :            :     {
     983                 :     647270 :     case BIT_IOR_EXPR:
     984                 :     647270 :       res = wi::bit_or (arg1, arg2);
     985                 :     647270 :       break;
     986                 :            : 
     987                 :      57739 :     case BIT_XOR_EXPR:
     988                 :      57739 :       res = wi::bit_xor (arg1, arg2);
     989                 :      57739 :       break;
     990                 :            : 
     991                 :    7587940 :     case BIT_AND_EXPR:
     992                 :    7587940 :       res = wi::bit_and (arg1, arg2);
     993                 :    7587940 :       break;
     994                 :            : 
     995                 :    5022290 :     case RSHIFT_EXPR:
     996                 :    5022290 :     case LSHIFT_EXPR:
     997                 :    5022290 :       if (wi::neg_p (arg2))
     998                 :            :         {
     999                 :      29230 :           tmp = -arg2;
    1000                 :      29230 :           if (code == RSHIFT_EXPR)
    1001                 :            :             code = LSHIFT_EXPR;
    1002                 :            :           else
    1003                 :            :             code = RSHIFT_EXPR;
    1004                 :            :         }
    1005                 :            :       else
    1006                 :    4993060 :         tmp = arg2;
    1007                 :            : 
    1008                 :    4993060 :       if (code == RSHIFT_EXPR)
    1009                 :            :         /* It's unclear from the C standard whether shifts can overflow.
    1010                 :            :            The following code ignores overflow; perhaps a C standard
    1011                 :            :            interpretation ruling is needed.  */
    1012                 :    2075940 :         res = wi::rshift (arg1, tmp, sign);
    1013                 :            :       else
    1014                 :    2946350 :         res = wi::lshift (arg1, tmp);
    1015                 :            :       break;
    1016                 :            : 
    1017                 :        661 :     case RROTATE_EXPR:
    1018                 :        661 :     case LROTATE_EXPR:
    1019                 :        661 :       if (wi::neg_p (arg2))
    1020                 :            :         {
    1021                 :          8 :           tmp = -arg2;
    1022                 :          8 :           if (code == RROTATE_EXPR)
    1023                 :            :             code = LROTATE_EXPR;
    1024                 :            :           else
    1025                 :            :             code = RROTATE_EXPR;
    1026                 :            :         }
    1027                 :            :       else
    1028                 :        653 :         tmp = arg2;
    1029                 :            : 
    1030                 :        653 :       if (code == RROTATE_EXPR)
    1031                 :        635 :         res = wi::rrotate (arg1, tmp);
    1032                 :            :       else
    1033                 :         26 :         res = wi::lrotate (arg1, tmp);
    1034                 :            :       break;
    1035                 :            : 
    1036                 :  105650000 :     case PLUS_EXPR:
    1037                 :  105650000 :       res = wi::add (arg1, arg2, sign, overflow);
    1038                 :  105650000 :       break;
    1039                 :            : 
    1040                 :   32481500 :     case MINUS_EXPR:
    1041                 :   32481500 :       res = wi::sub (arg1, arg2, sign, overflow);
    1042                 :   32481500 :       break;
    1043                 :            : 
    1044                 :  121750000 :     case MULT_EXPR:
    1045                 :  121750000 :       res = wi::mul (arg1, arg2, sign, overflow);
    1046                 :  121750000 :       break;
    1047                 :            : 
    1048                 :       2044 :     case MULT_HIGHPART_EXPR:
    1049                 :       2044 :       res = wi::mul_high (arg1, arg2, sign);
    1050                 :       2044 :       break;
    1051                 :            : 
    1052                 :   85232700 :     case TRUNC_DIV_EXPR:
    1053                 :   85232700 :     case EXACT_DIV_EXPR:
    1054                 :   85232700 :       if (arg2 == 0)
    1055                 :            :         return false;
    1056                 :   85227000 :       res = wi::div_trunc (arg1, arg2, sign, overflow);
    1057                 :   85227000 :       break;
    1058                 :            : 
    1059                 :   26025800 :     case FLOOR_DIV_EXPR:
    1060                 :   26025800 :       if (arg2 == 0)
    1061                 :            :         return false;
    1062                 :   26025800 :       res = wi::div_floor (arg1, arg2, sign, overflow);
    1063                 :   26025800 :       break;
    1064                 :            : 
    1065                 :   15898900 :     case CEIL_DIV_EXPR:
    1066                 :   15898900 :       if (arg2 == 0)
    1067                 :            :         return false;
    1068                 :   15898900 :       res = wi::div_ceil (arg1, arg2, sign, overflow);
    1069                 :   15898900 :       break;
    1070                 :            : 
    1071                 :          0 :     case ROUND_DIV_EXPR:
    1072                 :          0 :       if (arg2 == 0)
    1073                 :            :         return false;
    1074                 :          0 :       res = wi::div_round (arg1, arg2, sign, overflow);
    1075                 :          0 :       break;
    1076                 :            : 
    1077                 :     175503 :     case TRUNC_MOD_EXPR:
    1078                 :     175503 :       if (arg2 == 0)
    1079                 :            :         return false;
    1080                 :     174599 :       res = wi::mod_trunc (arg1, arg2, sign, overflow);
    1081                 :     174599 :       break;
    1082                 :            : 
    1083                 :   19386400 :     case FLOOR_MOD_EXPR:
    1084                 :   19386400 :       if (arg2 == 0)
    1085                 :            :         return false;
    1086                 :   19386400 :       res = wi::mod_floor (arg1, arg2, sign, overflow);
    1087                 :   19386400 :       break;
    1088                 :            : 
    1089                 :          0 :     case CEIL_MOD_EXPR:
    1090                 :          0 :       if (arg2 == 0)
    1091                 :            :         return false;
    1092                 :          0 :       res = wi::mod_ceil (arg1, arg2, sign, overflow);
    1093                 :          0 :       break;
    1094                 :            : 
    1095                 :          0 :     case ROUND_MOD_EXPR:
    1096                 :          0 :       if (arg2 == 0)
    1097                 :            :         return false;
    1098                 :          0 :       res = wi::mod_round (arg1, arg2, sign, overflow);
    1099                 :          0 :       break;
    1100                 :            : 
    1101                 :      13103 :     case MIN_EXPR:
    1102                 :      13103 :       res = wi::min (arg1, arg2, sign);
    1103                 :      13103 :       break;
    1104                 :            : 
    1105                 :   23725800 :     case MAX_EXPR:
    1106                 :   23725800 :       res = wi::max (arg1, arg2, sign);
    1107                 :   23725800 :       break;
    1108                 :            : 
    1109                 :            :     default:
    1110                 :            :       return false;
    1111                 :            :     }
    1112                 :            :   return true;
    1113                 :            : }
    1114                 :            : 
    1115                 :            : /* Combine two poly int's ARG1 and ARG2 under operation CODE to
    1116                 :            :    produce a new constant in RES.  Return FALSE if we don't know how
    1117                 :            :    to evaluate CODE at compile-time.  */
    1118                 :            : 
    1119                 :            : static bool
    1120                 :          0 : poly_int_binop (poly_wide_int &res, enum tree_code code,
    1121                 :            :                 const_tree arg1, const_tree arg2,
    1122                 :            :                 signop sign, wi::overflow_type *overflow)
    1123                 :            : {
    1124                 :          0 :   gcc_assert (NUM_POLY_INT_COEFFS != 1);
    1125                 :            :   gcc_assert (poly_int_tree_p (arg1) && poly_int_tree_p (arg2));
    1126                 :            :   switch (code)
    1127                 :            :     {
    1128                 :            :     case PLUS_EXPR:
    1129                 :            :       res = wi::add (wi::to_poly_wide (arg1),
    1130                 :            :                      wi::to_poly_wide (arg2), sign, overflow);
    1131                 :            :       break;
    1132                 :            : 
    1133                 :            :     case MINUS_EXPR:
    1134                 :            :       res = wi::sub (wi::to_poly_wide (arg1),
    1135                 :            :                      wi::to_poly_wide (arg2), sign, overflow);
    1136                 :            :       break;
    1137                 :            : 
    1138                 :            :     case MULT_EXPR:
    1139                 :            :       if (TREE_CODE (arg2) == INTEGER_CST)
    1140                 :            :         res = wi::mul (wi::to_poly_wide (arg1),
    1141                 :            :                        wi::to_wide (arg2), sign, overflow);
    1142                 :            :       else if (TREE_CODE (arg1) == INTEGER_CST)
    1143                 :            :         res = wi::mul (wi::to_poly_wide (arg2),
    1144                 :            :                        wi::to_wide (arg1), sign, overflow);
    1145                 :            :       else
    1146                 :            :         return NULL_TREE;
    1147                 :            :       break;
    1148                 :            : 
    1149                 :            :     case LSHIFT_EXPR:
    1150                 :            :       if (TREE_CODE (arg2) == INTEGER_CST)
    1151                 :            :         res = wi::to_poly_wide (arg1) << wi::to_wide (arg2);
    1152                 :            :       else
    1153                 :            :         return false;
    1154                 :            :       break;
    1155                 :            : 
    1156                 :            :     case BIT_IOR_EXPR:
    1157                 :            :       if (TREE_CODE (arg2) != INTEGER_CST
    1158                 :            :           || !can_ior_p (wi::to_poly_wide (arg1), wi::to_wide (arg2),
    1159                 :            :                          &res))
    1160                 :            :         return false;
    1161                 :            :       break;
    1162                 :            : 
    1163                 :            :     default:
    1164                 :            :       return false;
    1165                 :            :     }
    1166                 :            :   return true;
    1167                 :            : }
    1168                 :            : 
    1169                 :            : /* Combine two integer constants ARG1 and ARG2 under operation CODE to
    1170                 :            :    produce a new constant.  Return NULL_TREE if we don't know how to
    1171                 :            :    evaluate CODE at compile-time.  */
    1172                 :            : 
    1173                 :            : tree
    1174                 :  443657000 : int_const_binop (enum tree_code code, const_tree arg1, const_tree arg2,
    1175                 :            :                  int overflowable)
    1176                 :            : {
    1177                 :  443657000 :   poly_wide_int poly_res;
    1178                 :  443657000 :   tree type = TREE_TYPE (arg1);
    1179                 :  443657000 :   signop sign = TYPE_SIGN (type);
    1180                 :  443657000 :   wi::overflow_type overflow = wi::OVF_NONE;
    1181                 :            : 
    1182                 :  443657000 :   if (TREE_CODE (arg1) == INTEGER_CST && TREE_CODE (arg2) == INTEGER_CST)
    1183                 :            :     {
    1184                 :  443657000 :       wide_int warg1 = wi::to_wide (arg1), res;
    1185                 :  443657000 :       wide_int warg2 = wi::to_wide (arg2, TYPE_PRECISION (type));
    1186                 :  443657000 :       if (!wide_int_binop (res, code, warg1, warg2, sign, &overflow))
    1187                 :       6720 :         return NULL_TREE;
    1188                 :  443651000 :       poly_res = res;
    1189                 :            :     }
    1190                 :          0 :   else if (!poly_int_tree_p (arg1)
    1191                 :          0 :            || !poly_int_tree_p (arg2)
    1192                 :          0 :            || !poly_int_binop (poly_res, code, arg1, arg2, sign, &overflow))
    1193                 :            :     return NULL_TREE;
    1194                 :  443651000 :   return force_fit_type (type, poly_res, overflowable,
    1195                 :  443651000 :                          (((sign == SIGNED || overflowable == -1)
    1196                 :  887221000 :                            && overflow)
    1197                 :  443651000 :                           | TREE_OVERFLOW (arg1) | TREE_OVERFLOW (arg2)));
    1198                 :            : }
    1199                 :            : 
    1200                 :            : /* Return true if binary operation OP distributes over addition in operand
    1201                 :            :    OPNO, with the other operand being held constant.  OPNO counts from 1.  */
    1202                 :            : 
    1203                 :            : static bool
    1204                 :      27949 : distributes_over_addition_p (tree_code op, int opno)
    1205                 :            : {
    1206                 :          0 :   switch (op)
    1207                 :            :     {
    1208                 :            :     case PLUS_EXPR:
    1209                 :            :     case MINUS_EXPR:
    1210                 :            :     case MULT_EXPR:
    1211                 :            :       return true;
    1212                 :            : 
    1213                 :         66 :     case LSHIFT_EXPR:
    1214                 :         66 :       return opno == 1;
    1215                 :            : 
    1216                 :       2781 :     default:
    1217                 :       2781 :       return false;
    1218                 :            :     }
    1219                 :            : }
    1220                 :            : 
    1221                 :            : /* Combine two constants ARG1 and ARG2 under operation CODE to produce a new
    1222                 :            :    constant.  We assume ARG1 and ARG2 have the same data type, or at least
    1223                 :            :    are the same kind of constant and the same machine mode.  Return zero if
    1224                 :            :    combining the constants is not allowed in the current operating mode.  */
    1225                 :            : 
    1226                 :            : static tree
    1227                 :   76321900 : const_binop (enum tree_code code, tree arg1, tree arg2)
    1228                 :            : {
    1229                 :            :   /* Sanity check for the recursive cases.  */
    1230                 :   76321900 :   if (!arg1 || !arg2)
    1231                 :            :     return NULL_TREE;
    1232                 :            : 
    1233                 :   76320700 :   STRIP_NOPS (arg1);
    1234                 :   76320700 :   STRIP_NOPS (arg2);
    1235                 :            : 
    1236                 :   76320700 :   if (poly_int_tree_p (arg1) && poly_int_tree_p (arg2))
    1237                 :            :     {
    1238                 :   74036700 :       if (code == POINTER_PLUS_EXPR)
    1239                 :     177342 :         return int_const_binop (PLUS_EXPR,
    1240                 :     177342 :                                 arg1, fold_convert (TREE_TYPE (arg1), arg2));
    1241                 :            : 
    1242                 :   73948000 :       return int_const_binop (code, arg1, arg2);
    1243                 :            :     }
    1244                 :            : 
    1245                 :    2283970 :   if (TREE_CODE (arg1) == REAL_CST && TREE_CODE (arg2) == REAL_CST)
    1246                 :            :     {
    1247                 :    2204280 :       machine_mode mode;
    1248                 :    2204280 :       REAL_VALUE_TYPE d1;
    1249                 :    2204280 :       REAL_VALUE_TYPE d2;
    1250                 :    2204280 :       REAL_VALUE_TYPE value;
    1251                 :    2204280 :       REAL_VALUE_TYPE result;
    1252                 :    2204280 :       bool inexact;
    1253                 :    2204280 :       tree t, type;
    1254                 :            : 
    1255                 :            :       /* The following codes are handled by real_arithmetic.  */
    1256                 :    2204280 :       switch (code)
    1257                 :            :         {
    1258                 :    2204280 :         case PLUS_EXPR:
    1259                 :    2204280 :         case MINUS_EXPR:
    1260                 :    2204280 :         case MULT_EXPR:
    1261                 :    2204280 :         case RDIV_EXPR:
    1262                 :    2204280 :         case MIN_EXPR:
    1263                 :    2204280 :         case MAX_EXPR:
    1264                 :    2204280 :           break;
    1265                 :            : 
    1266                 :            :         default:
    1267                 :            :           return NULL_TREE;
    1268                 :            :         }
    1269                 :            : 
    1270                 :    2204280 :       d1 = TREE_REAL_CST (arg1);
    1271                 :    2204280 :       d2 = TREE_REAL_CST (arg2);
    1272                 :            : 
    1273                 :    2204280 :       type = TREE_TYPE (arg1);
    1274                 :    2204280 :       mode = TYPE_MODE (type);
    1275                 :            : 
    1276                 :            :       /* Don't perform operation if we honor signaling NaNs and
    1277                 :            :          either operand is a signaling NaN.  */
    1278                 :    2204280 :       if (HONOR_SNANS (mode)
    1279                 :    2204280 :           && (REAL_VALUE_ISSIGNALING_NAN (d1)
    1280                 :       2207 :               || REAL_VALUE_ISSIGNALING_NAN (d2)))
    1281                 :         30 :         return NULL_TREE;
    1282                 :            : 
    1283                 :            :       /* Don't perform operation if it would raise a division
    1284                 :            :          by zero exception.  */
    1285                 :    2204260 :       if (code == RDIV_EXPR
    1286                 :     127901 :           && real_equal (&d2, &dconst0)
    1287                 :    2216490 :           && (flag_trapping_math || ! MODE_HAS_INFINITIES (mode)))
    1288                 :            :         return NULL_TREE;
    1289                 :            : 
    1290                 :            :       /* If either operand is a NaN, just return it.  Otherwise, set up
    1291                 :            :          for floating-point trap; we return an overflow.  */
    1292                 :    2195200 :       if (REAL_VALUE_ISNAN (d1))
    1293                 :            :       {
    1294                 :            :         /* Make resulting NaN value to be qNaN when flag_signaling_nans
    1295                 :            :            is off.  */
    1296                 :        261 :         d1.signalling = 0;
    1297                 :        261 :         t = build_real (type, d1);
    1298                 :        261 :         return t;
    1299                 :            :       }
    1300                 :    2194940 :       else if (REAL_VALUE_ISNAN (d2))
    1301                 :            :       {
    1302                 :            :         /* Make resulting NaN value to be qNaN when flag_signaling_nans
    1303                 :            :            is off.  */
    1304                 :        634 :         d2.signalling = 0;
    1305                 :        634 :         t = build_real (type, d2);
    1306                 :        634 :         return t;
    1307                 :            :       }
    1308                 :            : 
    1309                 :    2194300 :       inexact = real_arithmetic (&value, code, &d1, &d2);
    1310                 :    2194300 :       real_convert (&result, mode, &value);
    1311                 :            : 
    1312                 :            :       /* Don't constant fold this floating point operation if
    1313                 :            :          the result has overflowed and flag_trapping_math.  */
    1314                 :    2194300 :       if (flag_trapping_math
    1315                 :    8204950 :           && MODE_HAS_INFINITIES (mode)
    1316                 :    2178740 :           && REAL_VALUE_ISINF (result)
    1317                 :       8306 :           && !REAL_VALUE_ISINF (d1)
    1318                 :    2202050 :           && !REAL_VALUE_ISINF (d2))
    1319                 :            :         return NULL_TREE;
    1320                 :            : 
    1321                 :            :       /* Don't constant fold this floating point operation if the
    1322                 :            :          result may dependent upon the run-time rounding mode and
    1323                 :            :          flag_rounding_math is set, or if GCC's software emulation
    1324                 :            :          is unable to accurately represent the result.  */
    1325                 :    2188860 :       if ((flag_rounding_math
    1326                 :   14298700 :            || (MODE_COMPOSITE_P (mode) && !flag_unsafe_math_optimizations))
    1327                 :    2188860 :           && (inexact || !real_identical (&result, &value)))
    1328                 :        667 :         return NULL_TREE;
    1329                 :            : 
    1330                 :    2188190 :       t = build_real (type, result);
    1331                 :            : 
    1332                 :    2188190 :       TREE_OVERFLOW (t) = TREE_OVERFLOW (arg1) | TREE_OVERFLOW (arg2);
    1333                 :    2188190 :       return t;
    1334                 :            :     }
    1335                 :            : 
    1336                 :      79686 :   if (TREE_CODE (arg1) == FIXED_CST)
    1337                 :            :     {
    1338                 :          0 :       FIXED_VALUE_TYPE f1;
    1339                 :          0 :       FIXED_VALUE_TYPE f2;
    1340                 :          0 :       FIXED_VALUE_TYPE result;
    1341                 :          0 :       tree t, type;
    1342                 :          0 :       int sat_p;
    1343                 :          0 :       bool overflow_p;
    1344                 :            : 
    1345                 :            :       /* The following codes are handled by fixed_arithmetic.  */
    1346                 :          0 :       switch (code)
    1347                 :            :         {
    1348                 :          0 :         case PLUS_EXPR:
    1349                 :          0 :         case MINUS_EXPR:
    1350                 :          0 :         case MULT_EXPR:
    1351                 :          0 :         case TRUNC_DIV_EXPR:
    1352                 :          0 :           if (TREE_CODE (arg2) != FIXED_CST)
    1353                 :            :             return NULL_TREE;
    1354                 :          0 :           f2 = TREE_FIXED_CST (arg2);
    1355                 :          0 :           break;
    1356                 :            : 
    1357                 :          0 :         case LSHIFT_EXPR:
    1358                 :          0 :         case RSHIFT_EXPR:
    1359                 :          0 :           {
    1360                 :          0 :             if (TREE_CODE (arg2) != INTEGER_CST)
    1361                 :          0 :               return NULL_TREE;
    1362                 :          0 :             wi::tree_to_wide_ref w2 = wi::to_wide (arg2);
    1363                 :          0 :             f2.data.high = w2.elt (1);
    1364                 :          0 :             f2.data.low = w2.ulow ();
    1365                 :          0 :             f2.mode = SImode;
    1366                 :            :           }
    1367                 :          0 :           break;
    1368                 :            : 
    1369                 :            :         default:
    1370                 :            :           return NULL_TREE;
    1371                 :            :         }
    1372                 :            : 
    1373                 :          0 :       f1 = TREE_FIXED_CST (arg1);
    1374                 :          0 :       type = TREE_TYPE (arg1);
    1375                 :          0 :       sat_p = TYPE_SATURATING (type);
    1376                 :          0 :       overflow_p = fixed_arithmetic (&result, code, &f1, &f2, sat_p);
    1377                 :          0 :       t = build_fixed (type, result);
    1378                 :            :       /* Propagate overflow flags.  */
    1379                 :          0 :       if (overflow_p | TREE_OVERFLOW (arg1) | TREE_OVERFLOW (arg2))
    1380                 :          0 :         TREE_OVERFLOW (t) = 1;
    1381                 :          0 :       return t;
    1382                 :            :     }
    1383                 :            : 
    1384                 :      79686 :   if (TREE_CODE (arg1) == COMPLEX_CST && TREE_CODE (arg2) == COMPLEX_CST)
    1385                 :            :     {
    1386                 :      10243 :       tree type = TREE_TYPE (arg1);
    1387                 :      10243 :       tree r1 = TREE_REALPART (arg1);
    1388                 :      10243 :       tree i1 = TREE_IMAGPART (arg1);
    1389                 :      10243 :       tree r2 = TREE_REALPART (arg2);
    1390                 :      10243 :       tree i2 = TREE_IMAGPART (arg2);
    1391                 :      10243 :       tree real, imag;
    1392                 :            : 
    1393                 :      10243 :       switch (code)
    1394                 :            :         {
    1395                 :       4781 :         case PLUS_EXPR:
    1396                 :       4781 :         case MINUS_EXPR:
    1397                 :       4781 :           real = const_binop (code, r1, r2);
    1398                 :       4781 :           imag = const_binop (code, i1, i2);
    1399                 :       4781 :           break;
    1400                 :            : 
    1401                 :       3642 :         case MULT_EXPR:
    1402                 :       7284 :           if (COMPLEX_FLOAT_TYPE_P (type))
    1403                 :       2492 :             return do_mpc_arg2 (arg1, arg2, type,
    1404                 :            :                                 /* do_nonfinite= */ folding_initializer,
    1405                 :       2492 :                                 mpc_mul);
    1406                 :            : 
    1407                 :       1150 :           real = const_binop (MINUS_EXPR,
    1408                 :            :                               const_binop (MULT_EXPR, r1, r2),
    1409                 :            :                               const_binop (MULT_EXPR, i1, i2));
    1410                 :       1150 :           imag = const_binop (PLUS_EXPR,
    1411                 :            :                               const_binop (MULT_EXPR, r1, i2),
    1412                 :            :                               const_binop (MULT_EXPR, i1, r2));
    1413                 :       1150 :           break;
    1414                 :            : 
    1415                 :       1572 :         case RDIV_EXPR:
    1416                 :       3144 :           if (COMPLEX_FLOAT_TYPE_P (type))
    1417                 :       1572 :             return do_mpc_arg2 (arg1, arg2, type,
    1418                 :            :                                 /* do_nonfinite= */ folding_initializer,
    1419                 :       1572 :                                 mpc_div);
    1420                 :            :           /* Fallthru. */
    1421                 :        248 :         case TRUNC_DIV_EXPR:
    1422                 :        248 :         case CEIL_DIV_EXPR:
    1423                 :        248 :         case FLOOR_DIV_EXPR:
    1424                 :        248 :         case ROUND_DIV_EXPR:
    1425                 :        248 :           if (flag_complex_method == 0)
    1426                 :            :           {
    1427                 :            :             /* Keep this algorithm in sync with
    1428                 :            :                tree-complex.c:expand_complex_div_straight().
    1429                 :            : 
    1430                 :            :                Expand complex division to scalars, straightforward algorithm.
    1431                 :            :                a / b = ((ar*br + ai*bi)/t) + i((ai*br - ar*bi)/t)
    1432                 :            :                t = br*br + bi*bi
    1433                 :            :             */
    1434                 :          0 :             tree magsquared
    1435                 :          0 :               = const_binop (PLUS_EXPR,
    1436                 :            :                              const_binop (MULT_EXPR, r2, r2),
    1437                 :            :                              const_binop (MULT_EXPR, i2, i2));
    1438                 :          0 :             tree t1
    1439                 :          0 :               = const_binop (PLUS_EXPR,
    1440                 :            :                              const_binop (MULT_EXPR, r1, r2),
    1441                 :            :                              const_binop (MULT_EXPR, i1, i2));
    1442                 :          0 :             tree t2
    1443                 :          0 :               = const_binop (MINUS_EXPR,
    1444                 :            :                              const_binop (MULT_EXPR, i1, r2),
    1445                 :            :                              const_binop (MULT_EXPR, r1, i2));
    1446                 :            : 
    1447                 :          0 :             real = const_binop (code, t1, magsquared);
    1448                 :          0 :             imag = const_binop (code, t2, magsquared);
    1449                 :            :           }
    1450                 :            :           else
    1451                 :            :           {
    1452                 :            :             /* Keep this algorithm in sync with
    1453                 :            :                tree-complex.c:expand_complex_div_wide().
    1454                 :            : 
    1455                 :            :                Expand complex division to scalars, modified algorithm to minimize
    1456                 :            :                overflow with wide input ranges.  */
    1457                 :        248 :             tree compare = fold_build2 (LT_EXPR, boolean_type_node,
    1458                 :            :                                         fold_abs_const (r2, TREE_TYPE (type)),
    1459                 :            :                                         fold_abs_const (i2, TREE_TYPE (type)));
    1460                 :            : 
    1461                 :        248 :             if (integer_nonzerop (compare))
    1462                 :            :               {
    1463                 :            :                 /* In the TRUE branch, we compute
    1464                 :            :                    ratio = br/bi;
    1465                 :            :                    div = (br * ratio) + bi;
    1466                 :            :                    tr = (ar * ratio) + ai;
    1467                 :            :                    ti = (ai * ratio) - ar;
    1468                 :            :                    tr = tr / div;
    1469                 :            :                    ti = ti / div;  */
    1470                 :         48 :                 tree ratio = const_binop (code, r2, i2);
    1471                 :         48 :                 tree div = const_binop (PLUS_EXPR, i2,
    1472                 :            :                                         const_binop (MULT_EXPR, r2, ratio));
    1473                 :         48 :                 real = const_binop (MULT_EXPR, r1, ratio);
    1474                 :         48 :                 real = const_binop (PLUS_EXPR, real, i1);
    1475                 :         48 :                 real = const_binop (code, real, div);
    1476                 :            : 
    1477                 :         48 :                 imag = const_binop (MULT_EXPR, i1, ratio);
    1478                 :         48 :                 imag = const_binop (MINUS_EXPR, imag, r1);
    1479                 :         48 :                 imag = const_binop (code, imag, div);
    1480                 :            :               }
    1481                 :            :             else
    1482                 :            :               {
    1483                 :            :                 /* In the FALSE branch, we compute
    1484                 :            :                    ratio = d/c;
    1485                 :            :                    divisor = (d * ratio) + c;
    1486                 :            :                    tr = (b * ratio) + a;
    1487                 :            :                    ti = b - (a * ratio);
    1488                 :            :                    tr = tr / div;
    1489                 :            :                    ti = ti / div;  */
    1490                 :        200 :                 tree ratio = const_binop (code, i2, r2);
    1491                 :        200 :                 tree div = const_binop (PLUS_EXPR, r2,
    1492                 :            :                                         const_binop (MULT_EXPR, i2, ratio));
    1493                 :            : 
    1494                 :        200 :                 real = const_binop (MULT_EXPR, i1, ratio);
    1495                 :        200 :                 real = const_binop (PLUS_EXPR, real, r1);
    1496                 :        200 :                 real = const_binop (code, real, div);
    1497                 :            : 
    1498                 :        200 :                 imag = const_binop (MULT_EXPR, r1, ratio);
    1499                 :        200 :                 imag = const_binop (MINUS_EXPR, i1, imag);
    1500                 :        200 :                 imag = const_binop (code, imag, div);
    1501                 :            :               }
    1502                 :            :           }
    1503                 :            :           break;
    1504                 :            : 
    1505                 :            :         default:
    1506                 :            :           return NULL_TREE;
    1507                 :            :         }
    1508                 :            : 
    1509                 :       6179 :       if (real && imag)
    1510                 :       6027 :         return build_complex (type, real, imag);
    1511                 :            :     }
    1512                 :            : 
    1513                 :      69595 :   if (TREE_CODE (arg1) == VECTOR_CST
    1514                 :      28527 :       && TREE_CODE (arg2) == VECTOR_CST
    1515                 :      96111 :       && known_eq (TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg1)),
    1516                 :            :                    TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg2))))
    1517                 :            :     {
    1518                 :      26516 :       tree type = TREE_TYPE (arg1);
    1519                 :      26516 :       bool step_ok_p;
    1520                 :      26516 :       if (VECTOR_CST_STEPPED_P (arg1)
    1521                 :      39375 :           && VECTOR_CST_STEPPED_P (arg2))
    1522                 :            :         /* We can operate directly on the encoding if:
    1523                 :            : 
    1524                 :            :               a3 - a2 == a2 - a1 && b3 - b2 == b2 - b1
    1525                 :            :             implies
    1526                 :            :               (a3 op b3) - (a2 op b2) == (a2 op b2) - (a1 op b1)
    1527                 :            : 
    1528                 :            :            Addition and subtraction are the supported operators
    1529                 :            :            for which this is true.  */
    1530                 :        578 :         step_ok_p = (code == PLUS_EXPR || code == MINUS_EXPR);
    1531                 :      25938 :       else if (VECTOR_CST_STEPPED_P (arg1))
    1532                 :            :         /* We can operate directly on stepped encodings if:
    1533                 :            : 
    1534                 :            :              a3 - a2 == a2 - a1
    1535                 :            :            implies:
    1536                 :            :              (a3 op c) - (a2 op c) == (a2 op c) - (a1 op c)
    1537                 :            : 
    1538                 :            :            which is true if (x -> x op c) distributes over addition.  */
    1539                 :      12281 :         step_ok_p = distributes_over_addition_p (code, 1);
    1540                 :            :       else
    1541                 :            :         /* Similarly in reverse.  */
    1542                 :      13657 :         step_ok_p = distributes_over_addition_p (code, 2);
    1543                 :      53032 :       tree_vector_builder elts;
    1544                 :      26516 :       if (!elts.new_binary_operation (type, arg1, arg2, step_ok_p))
    1545                 :            :         return NULL_TREE;
    1546                 :      26516 :       unsigned int count = elts.encoded_nelts ();
    1547                 :     110226 :       for (unsigned int i = 0; i < count; ++i)
    1548                 :            :         {
    1549                 :      83926 :           tree elem1 = VECTOR_CST_ELT (arg1, i);
    1550                 :      83926 :           tree elem2 = VECTOR_CST_ELT (arg2, i);
    1551                 :            : 
    1552                 :      83926 :           tree elt = const_binop (code, elem1, elem2);
    1553                 :            : 
    1554                 :            :           /* It is possible that const_binop cannot handle the given
    1555                 :            :              code and return NULL_TREE */
    1556                 :      83926 :           if (elt == NULL_TREE)
    1557                 :      26516 :             return NULL_TREE;
    1558                 :      83710 :           elts.quick_push (elt);
    1559                 :            :         }
    1560                 :            : 
    1561                 :      26300 :       return elts.build ();
    1562                 :            :     }
    1563                 :            : 
    1564                 :            :   /* Shifts allow a scalar offset for a vector.  */
    1565                 :      43079 :   if (TREE_CODE (arg1) == VECTOR_CST
    1566                 :       2011 :       && TREE_CODE (arg2) == INTEGER_CST)
    1567                 :            :     {
    1568                 :       2011 :       tree type = TREE_TYPE (arg1);
    1569                 :       2011 :       bool step_ok_p = distributes_over_addition_p (code, 1);
    1570                 :       4022 :       tree_vector_builder elts;
    1571                 :       2011 :       if (!elts.new_unary_operation (type, arg1, step_ok_p))
    1572                 :            :         return NULL_TREE;
    1573                 :       2011 :       unsigned int count = elts.encoded_nelts ();
    1574                 :      10091 :       for (unsigned int i = 0; i < count; ++i)
    1575                 :            :         {
    1576                 :       8080 :           tree elem1 = VECTOR_CST_ELT (arg1, i);
    1577                 :            : 
    1578                 :       8080 :           tree elt = const_binop (code, elem1, arg2);
    1579                 :            : 
    1580                 :            :           /* It is possible that const_binop cannot handle the given
    1581                 :            :              code and return NULL_TREE.  */
    1582                 :       8080 :           if (elt == NULL_TREE)
    1583                 :       2011 :             return NULL_TREE;
    1584                 :       8080 :           elts.quick_push (elt);
    1585                 :            :         }
    1586                 :            : 
    1587                 :       2011 :       return elts.build ();
    1588                 :            :     }
    1589                 :            :   return NULL_TREE;
    1590                 :            : }
    1591                 :            : 
    1592                 :            : /* Overload that adds a TYPE parameter to be able to dispatch
    1593                 :            :    to fold_relational_const.  */
    1594                 :            : 
    1595                 :            : tree
    1596                 :   93327600 : const_binop (enum tree_code code, tree type, tree arg1, tree arg2)
    1597                 :            : {
    1598                 :   93327600 :   if (TREE_CODE_CLASS (code) == tcc_comparison)
    1599                 :   21347600 :     return fold_relational_const (code, type, arg1, arg2);
    1600                 :            : 
    1601                 :            :   /* ???  Until we make the const_binop worker take the type of the
    1602                 :            :      result as argument put those cases that need it here.  */
    1603                 :   71980000 :   switch (code)
    1604                 :            :     {
    1605                 :          0 :     case VEC_SERIES_EXPR:
    1606                 :          0 :       if (CONSTANT_CLASS_P (arg1)
    1607                 :          0 :           && CONSTANT_CLASS_P (arg2))
    1608                 :          0 :         return build_vec_series (type, arg1, arg2);
    1609                 :            :       return NULL_TREE;
    1610                 :            : 
    1611                 :     236609 :     case COMPLEX_EXPR:
    1612                 :     236609 :       if ((TREE_CODE (arg1) == REAL_CST
    1613                 :     226436 :            && TREE_CODE (arg2) == REAL_CST)
    1614                 :      10173 :           || (TREE_CODE (arg1) == INTEGER_CST
    1615                 :      10173 :               && TREE_CODE (arg2) == INTEGER_CST))
    1616                 :     236609 :         return build_complex (type, arg1, arg2);
    1617                 :            :       return NULL_TREE;
    1618                 :            : 
    1619                 :       2606 :     case POINTER_DIFF_EXPR:
    1620                 :       2606 :       if (poly_int_tree_p (arg1) && poly_int_tree_p (arg2))
    1621                 :            :         {
    1622                 :       4922 :           poly_offset_int res = (wi::to_poly_offset (arg1)
    1623                 :       2461 :                                  - wi::to_poly_offset (arg2));
    1624                 :       4922 :           return force_fit_type (type, res, 1,
    1625                 :       2461 :                                  TREE_OVERFLOW (arg1) | TREE_OVERFLOW (arg2));
    1626                 :            :         }
    1627                 :            :       return NULL_TREE;
    1628                 :            : 
    1629                 :       2449 :     case VEC_PACK_TRUNC_EXPR:
    1630                 :       2449 :     case VEC_PACK_FIX_TRUNC_EXPR:
    1631                 :       2449 :     case VEC_PACK_FLOAT_EXPR:
    1632                 :       2449 :       {
    1633                 :       2449 :         unsigned int HOST_WIDE_INT out_nelts, in_nelts, i;
    1634                 :            : 
    1635                 :       2449 :         if (TREE_CODE (arg1) != VECTOR_CST
    1636                 :       2449 :             || TREE_CODE (arg2) != VECTOR_CST)
    1637                 :            :           return NULL_TREE;
    1638                 :            : 
    1639                 :       2449 :         if (!VECTOR_CST_NELTS (arg1).is_constant (&in_nelts))
    1640                 :            :           return NULL_TREE;
    1641                 :            : 
    1642                 :       2449 :         out_nelts = in_nelts * 2;
    1643                 :       2449 :         gcc_assert (known_eq (in_nelts, VECTOR_CST_NELTS (arg2))
    1644                 :            :                     && known_eq (out_nelts, TYPE_VECTOR_SUBPARTS (type)));
    1645                 :            : 
    1646                 :       2449 :         tree_vector_builder elts (type, out_nelts, 1);
    1647                 :      28901 :         for (i = 0; i < out_nelts; i++)
    1648                 :            :           {
    1649                 :      26452 :             tree elt = (i < in_nelts
    1650                 :      26452 :                         ? VECTOR_CST_ELT (arg1, i)
    1651                 :      13226 :                         : VECTOR_CST_ELT (arg2, i - in_nelts));
    1652                 :      52904 :             elt = fold_convert_const (code == VEC_PACK_TRUNC_EXPR
    1653                 :            :                                       ? NOP_EXPR
    1654                 :            :                                       : code == VEC_PACK_FLOAT_EXPR
    1655                 :         28 :                                       ? FLOAT_EXPR : FIX_TRUNC_EXPR,
    1656                 :      26452 :                                       TREE_TYPE (type), elt);
    1657                 :      26452 :             if (elt == NULL_TREE || !CONSTANT_CLASS_P (elt))
    1658                 :       2449 :               return NULL_TREE;
    1659                 :      26452 :             elts.quick_push (elt);
    1660                 :            :           }
    1661                 :            : 
    1662                 :       2449 :         return elts.build ();
    1663                 :            :       }
    1664                 :            : 
    1665                 :        292 :     case VEC_WIDEN_MULT_LO_EXPR:
    1666                 :        292 :     case VEC_WIDEN_MULT_HI_EXPR:
    1667                 :        292 :     case VEC_WIDEN_MULT_EVEN_EXPR:
    1668                 :        292 :     case VEC_WIDEN_MULT_ODD_EXPR:
    1669                 :        292 :       {
    1670                 :        292 :         unsigned HOST_WIDE_INT out_nelts, in_nelts, out, ofs, scale;
    1671                 :            : 
    1672                 :        292 :         if (TREE_CODE (arg1) != VECTOR_CST || TREE_CODE (arg2) != VECTOR_CST)
    1673                 :            :           return NULL_TREE;
    1674                 :            : 
    1675                 :        292 :         if (!VECTOR_CST_NELTS (arg1).is_constant (&in_nelts))
    1676                 :            :           return NULL_TREE;
    1677                 :        292 :         out_nelts = in_nelts / 2;
    1678                 :        292 :         gcc_assert (known_eq (in_nelts, VECTOR_CST_NELTS (arg2))
    1679                 :            :                     && known_eq (out_nelts, TYPE_VECTOR_SUBPARTS (type)));
    1680                 :            : 
    1681                 :        292 :         if (code == VEC_WIDEN_MULT_LO_EXPR)
    1682                 :            :           scale = 0, ofs = BYTES_BIG_ENDIAN ? out_nelts : 0;
    1683                 :        148 :         else if (code == VEC_WIDEN_MULT_HI_EXPR)
    1684                 :            :           scale = 0, ofs = BYTES_BIG_ENDIAN ? 0 : out_nelts;
    1685                 :          0 :         else if (code == VEC_WIDEN_MULT_EVEN_EXPR)
    1686                 :            :           scale = 1, ofs = 0;
    1687                 :            :         else /* if (code == VEC_WIDEN_MULT_ODD_EXPR) */
    1688                 :          0 :           scale = 1, ofs = 1;
    1689                 :            : 
    1690                 :        292 :         tree_vector_builder elts (type, out_nelts, 1);
    1691                 :        892 :         for (out = 0; out < out_nelts; out++)
    1692                 :            :           {
    1693                 :        600 :             unsigned int in = (out << scale) + ofs;
    1694                 :        600 :             tree t1 = fold_convert_const (NOP_EXPR, TREE_TYPE (type),
    1695                 :            :                                           VECTOR_CST_ELT (arg1, in));
    1696                 :        600 :             tree t2 = fold_convert_const (NOP_EXPR, TREE_TYPE (type),
    1697                 :            :                                           VECTOR_CST_ELT (arg2, in));
    1698                 :            : 
    1699                 :        600 :             if (t1 == NULL_TREE || t2 == NULL_TREE)
    1700                 :        292 :               return NULL_TREE;
    1701                 :        600 :             tree elt = const_binop (MULT_EXPR, t1, t2);
    1702                 :        600 :             if (elt == NULL_TREE || !CONSTANT_CLASS_P (elt))
    1703                 :            :               return NULL_TREE;
    1704                 :        600 :             elts.quick_push (elt);
    1705                 :            :           }
    1706                 :            : 
    1707                 :        292 :         return elts.build ();
    1708                 :            :       }
    1709                 :            : 
    1710                 :   71738000 :     default:;
    1711                 :            :     }
    1712                 :            : 
    1713                 :   71738000 :   if (TREE_CODE_CLASS (code) != tcc_binary)
    1714                 :            :     return NULL_TREE;
    1715                 :            : 
    1716                 :            :   /* Make sure type and arg0 have the same saturating flag.  */
    1717                 :   71001800 :   gcc_checking_assert (TYPE_SATURATING (type)
    1718                 :            :                        == TYPE_SATURATING (TREE_TYPE (arg1)));
    1719                 :            : 
    1720                 :   71001800 :   return const_binop (code, arg1, arg2);
    1721                 :            : }
    1722                 :            : 
    1723                 :            : /* Compute CODE ARG1 with resulting type TYPE with ARG1 being constant.
    1724                 :            :    Return zero if computing the constants is not possible.  */
    1725                 :            : 
    1726                 :            : tree
    1727                 :   59875900 : const_unop (enum tree_code code, tree type, tree arg0)
    1728                 :            : {
    1729                 :            :   /* Don't perform the operation, other than NEGATE and ABS, if
    1730                 :            :      flag_signaling_nans is on and the operand is a signaling NaN.  */
    1731                 :   59875900 :   if (TREE_CODE (arg0) == REAL_CST
    1732                 :    1196330 :       && HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0)))
    1733                 :       1153 :       && REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (arg0))
    1734                 :         41 :       && code != NEGATE_EXPR
    1735                 :         41 :       && code != ABS_EXPR
    1736                 :   59876000 :       && code != ABSU_EXPR)
    1737                 :            :     return NULL_TREE;
    1738                 :            : 
    1739                 :   59875900 :   switch (code)
    1740                 :            :     {
    1741                 :   38887900 :     CASE_CONVERT:
    1742                 :   38887900 :     case FLOAT_EXPR:
    1743                 :   38887900 :     case FIX_TRUNC_EXPR:
    1744                 :   38887900 :     case FIXED_CONVERT_EXPR:
    1745                 :   38887900 :       return fold_convert_const (code, type, arg0);
    1746                 :            : 
    1747                 :          0 :     case ADDR_SPACE_CONVERT_EXPR:
    1748                 :            :       /* If the source address is 0, and the source address space
    1749                 :            :          cannot have a valid object at 0, fold to dest type null.  */
    1750                 :          0 :       if (integer_zerop (arg0)
    1751                 :          0 :           && !(targetm.addr_space.zero_address_valid
    1752                 :          0 :                (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (arg0))))))
    1753                 :          0 :         return fold_convert_const (code, type, arg0);
    1754                 :            :       break;
    1755                 :            : 
    1756                 :    2897450 :     case VIEW_CONVERT_EXPR:
    1757                 :    2897450 :       return fold_view_convert_expr (type, arg0);
    1758                 :            : 
    1759                 :   11494000 :     case NEGATE_EXPR:
    1760                 :   11494000 :       {
    1761                 :            :         /* Can't call fold_negate_const directly here as that doesn't
    1762                 :            :            handle all cases and we might not be able to negate some
    1763                 :            :            constants.  */
    1764                 :   11494000 :         tree tem = fold_negate_expr (UNKNOWN_LOCATION, arg0);
    1765                 :   11494000 :         if (tem && CONSTANT_CLASS_P (tem))
    1766                 :   11488000 :           return tem;
    1767                 :            :         break;
    1768                 :            :       }
    1769                 :            : 
    1770                 :      25314 :     case ABS_EXPR:
    1771                 :      25314 :     case ABSU_EXPR:
    1772                 :      25314 :       if (TREE_CODE (arg0) == INTEGER_CST || TREE_CODE (arg0) == REAL_CST)
    1773                 :      25306 :         return fold_abs_const (arg0, type);
    1774                 :            :       break;
    1775                 :            : 
    1776                 :      24569 :     case CONJ_EXPR:
    1777                 :      24569 :       if (TREE_CODE (arg0) == COMPLEX_CST)
    1778                 :            :         {
    1779                 :      24569 :           tree ipart = fold_negate_const (TREE_IMAGPART (arg0),
    1780                 :      24569 :                                           TREE_TYPE (type));
    1781                 :      24569 :           return build_complex (type, TREE_REALPART (arg0), ipart);
    1782                 :            :         }
    1783                 :            :       break;
    1784                 :            : 
    1785                 :    1142650 :     case BIT_NOT_EXPR:
    1786                 :    1142650 :       if (TREE_CODE (arg0) == INTEGER_CST)
    1787                 :    1141970 :         return fold_not_const (arg0, type);
    1788                 :        680 :       else if (POLY_INT_CST_P (arg0))
    1789                 :            :         return wide_int_to_tree (type, -poly_int_cst_value (arg0));
    1790                 :            :       /* Perform BIT_NOT_EXPR on each element individually.  */
    1791                 :        680 :       else if (TREE_CODE (arg0) == VECTOR_CST)
    1792                 :            :         {
    1793                 :         29 :           tree elem;
    1794                 :            : 
    1795                 :            :           /* This can cope with stepped encodings because ~x == -1 - x.  */
    1796                 :         29 :           tree_vector_builder elements;
    1797                 :         29 :           elements.new_unary_operation (type, arg0, true);
    1798                 :         29 :           unsigned int i, count = elements.encoded_nelts ();
    1799                 :        136 :           for (i = 0; i < count; ++i)
    1800                 :            :             {
    1801                 :        107 :               elem = VECTOR_CST_ELT (arg0, i);
    1802                 :        107 :               elem = const_unop (BIT_NOT_EXPR, TREE_TYPE (type), elem);
    1803                 :        107 :               if (elem == NULL_TREE)
    1804                 :            :                 break;
    1805                 :        107 :               elements.quick_push (elem);
    1806                 :            :             }
    1807                 :         29 :           if (i == count)
    1808                 :         58 :             return elements.build ();
    1809                 :            :         }
    1810                 :            :       break;
    1811                 :            : 
    1812                 :    1856420 :     case TRUTH_NOT_EXPR:
    1813                 :    1856420 :       if (TREE_CODE (arg0) == INTEGER_CST)
    1814                 :    1850100 :         return constant_boolean_node (integer_zerop (arg0), type);
    1815                 :            :       break;
    1816                 :            : 
    1817                 :     191172 :     case REALPART_EXPR:
    1818                 :     191172 :       if (TREE_CODE (arg0) == COMPLEX_CST)
    1819                 :     191077 :         return fold_convert (type, TREE_REALPART (arg0));
    1820                 :            :       break;
    1821                 :            : 
    1822                 :     195230 :     case IMAGPART_EXPR:
    1823                 :     195230 :       if (TREE_CODE (arg0) == COMPLEX_CST)
    1824                 :     195154 :         return fold_convert (type, TREE_IMAGPART (arg0));
    1825                 :            :       break;
    1826                 :            : 
    1827                 :       2076 :     case VEC_UNPACK_LO_EXPR:
    1828                 :       2076 :     case VEC_UNPACK_HI_EXPR:
    1829                 :       2076 :     case VEC_UNPACK_FLOAT_LO_EXPR:
    1830                 :       2076 :     case VEC_UNPACK_FLOAT_HI_EXPR:
    1831                 :       2076 :     case VEC_UNPACK_FIX_TRUNC_LO_EXPR:
    1832                 :       2076 :     case VEC_UNPACK_FIX_TRUNC_HI_EXPR:
    1833                 :       2076 :       {
    1834                 :       2076 :         unsigned HOST_WIDE_INT out_nelts, in_nelts, i;
    1835                 :       2076 :         enum tree_code subcode;
    1836                 :            : 
    1837                 :       2076 :         if (TREE_CODE (arg0) != VECTOR_CST)
    1838                 :            :           return NULL_TREE;
    1839                 :            : 
    1840                 :       2076 :         if (!VECTOR_CST_NELTS (arg0).is_constant (&in_nelts))
    1841                 :            :           return NULL_TREE;
    1842                 :       2076 :         out_nelts = in_nelts / 2;
    1843                 :       2076 :         gcc_assert (known_eq (out_nelts, TYPE_VECTOR_SUBPARTS (type)));
    1844                 :            : 
    1845                 :       2076 :         unsigned int offset = 0;
    1846                 :       2076 :         if ((!BYTES_BIG_ENDIAN) ^ (code == VEC_UNPACK_LO_EXPR
    1847                 :       2076 :                                    || code == VEC_UNPACK_FLOAT_LO_EXPR
    1848                 :       2076 :                                    || code == VEC_UNPACK_FIX_TRUNC_LO_EXPR))
    1849                 :       1032 :           offset = out_nelts;
    1850                 :            : 
    1851                 :       2076 :         if (code == VEC_UNPACK_LO_EXPR || code == VEC_UNPACK_HI_EXPR)
    1852                 :            :           subcode = NOP_EXPR;
    1853                 :        868 :         else if (code == VEC_UNPACK_FLOAT_LO_EXPR
    1854                 :        868 :                  || code == VEC_UNPACK_FLOAT_HI_EXPR)
    1855                 :            :           subcode = FLOAT_EXPR;
    1856                 :            :         else
    1857                 :          0 :           subcode = FIX_TRUNC_EXPR;
    1858                 :            : 
    1859                 :       2076 :         tree_vector_builder elts (type, out_nelts, 1);
    1860                 :       8196 :         for (i = 0; i < out_nelts; i++)
    1861                 :            :           {
    1862                 :       6120 :             tree elt = fold_convert_const (subcode, TREE_TYPE (type),
    1863                 :       6120 :                                            VECTOR_CST_ELT (arg0, i + offset));
    1864                 :       6120 :             if (elt == NULL_TREE || !CONSTANT_CLASS_P (elt))
    1865                 :       2076 :               return NULL_TREE;
    1866                 :       6120 :             elts.quick_push (elt);
    1867                 :            :           }
    1868                 :            : 
    1869                 :       2076 :         return elts.build ();
    1870                 :            :       }
    1871                 :            : 
    1872                 :          2 :     case VEC_DUPLICATE_EXPR:
    1873                 :          2 :       if (CONSTANT_CLASS_P (arg0))
    1874                 :          2 :         return build_vector_from_val (type, arg0);
    1875                 :            :       return NULL_TREE;
    1876                 :            : 
    1877                 :            :     default:
    1878                 :            :       break;
    1879                 :            :     }
    1880                 :            : 
    1881                 :            :   return NULL_TREE;
    1882                 :            : }
    1883                 :            : 
    1884                 :            : /* Create a sizetype INT_CST node with NUMBER sign extended.  KIND
    1885                 :            :    indicates which particular sizetype to create.  */
    1886                 :            : 
    1887                 :            : tree
    1888                 :  832484000 : size_int_kind (poly_int64 number, enum size_type_kind kind)
    1889                 :            : {
    1890                 :  832484000 :   return build_int_cst (sizetype_tab[(int) kind], number);
    1891                 :            : }
    1892                 :            : 
    1893                 :            : /* Combine operands OP1 and OP2 with arithmetic operation CODE.  CODE
    1894                 :            :    is a tree code.  The type of the result is taken from the operands.
    1895                 :            :    Both must be equivalent integer types, ala int_binop_types_match_p.
    1896                 :            :    If the operands are constant, so is the result.  */
    1897                 :            : 
    1898                 :            : tree
    1899                 :  638859000 : size_binop_loc (location_t loc, enum tree_code code, tree arg0, tree arg1)
    1900                 :            : {
    1901                 :  638859000 :   tree type = TREE_TYPE (arg0);
    1902                 :            : 
    1903                 :  638859000 :   if (arg0 == error_mark_node || arg1 == error_mark_node)
    1904                 :            :     return error_mark_node;
    1905                 :            : 
    1906                 :  638859000 :   gcc_assert (int_binop_types_match_p (code, TREE_TYPE (arg0),
    1907                 :            :                                        TREE_TYPE (arg1)));
    1908                 :            : 
    1909                 :            :   /* Handle the special case of two poly_int constants faster.  */
    1910                 :  638859000 :   if (poly_int_tree_p (arg0) && poly_int_tree_p (arg1))
    1911                 :            :     {
    1912                 :            :       /* And some specific cases even faster than that.  */
    1913                 :  631254000 :       if (code == PLUS_EXPR)
    1914                 :            :         {
    1915                 :  297808000 :           if (integer_zerop (arg0)
    1916                 :  297808000 :               && !TREE_OVERFLOW (tree_strip_any_location_wrapper (arg0)))
    1917                 :            :             return arg1;
    1918                 :   73685800 :           if (integer_zerop (arg1)
    1919                 :   73685800 :               && !TREE_OVERFLOW (tree_strip_any_location_wrapper (arg1)))
    1920                 :            :             return arg0;
    1921                 :            :         }
    1922                 :  333446000 :       else if (code == MINUS_EXPR)
    1923                 :            :         {
    1924                 :   23645700 :           if (integer_zerop (arg1)
    1925                 :   23645700 :               && !TREE_OVERFLOW (tree_strip_any_location_wrapper (arg1)))
    1926                 :            :             return arg0;
    1927                 :            :         }
    1928                 :  309800000 :       else if (code == MULT_EXPR)
    1929                 :            :         {
    1930                 :  141590000 :           if (integer_onep (arg0)
    1931                 :  141590000 :               && !TREE_OVERFLOW (tree_strip_any_location_wrapper (arg0)))
    1932                 :            :             return arg1;
    1933                 :            :         }
    1934                 :            : 
    1935                 :            :       /* Handle general case of two integer constants.  For sizetype
    1936                 :            :          constant calculations we always want to know about overflow,
    1937                 :            :          even in the unsigned case.  */
    1938                 :  304892000 :       tree res = int_const_binop (code, arg0, arg1, -1);
    1939                 :  304892000 :       if (res != NULL_TREE)
    1940                 :            :         return res;
    1941                 :            :     }
    1942                 :            : 
    1943                 :    7605700 :   return fold_build2_loc (loc, code, type, arg0, arg1);
    1944                 :            : }
    1945                 :            : 
    1946                 :            : /* Given two values, either both of sizetype or both of bitsizetype,
    1947                 :            :    compute the difference between the two values.  Return the value
    1948                 :            :    in signed type corresponding to the type of the operands.  */
    1949                 :            : 
    1950                 :            : tree
    1951                 :    9343020 : size_diffop_loc (location_t loc, tree arg0, tree arg1)
    1952                 :            : {
    1953                 :    9343020 :   tree type = TREE_TYPE (arg0);
    1954                 :    9343020 :   tree ctype;
    1955                 :            : 
    1956                 :    9343020 :   gcc_assert (int_binop_types_match_p (MINUS_EXPR, TREE_TYPE (arg0),
    1957                 :            :                                        TREE_TYPE (arg1)));
    1958                 :            : 
    1959                 :            :   /* If the type is already signed, just do the simple thing.  */
    1960                 :    9343020 :   if (!TYPE_UNSIGNED (type))
    1961                 :     779987 :     return size_binop_loc (loc, MINUS_EXPR, arg0, arg1);
    1962                 :            : 
    1963                 :    8563030 :   if (type == sizetype)
    1964                 :    8563030 :     ctype = ssizetype;
    1965                 :          0 :   else if (type == bitsizetype)
    1966                 :          0 :     ctype = sbitsizetype;
    1967                 :            :   else
    1968                 :          0 :     ctype = signed_type_for (type);
    1969                 :            : 
    1970                 :            :   /* If either operand is not a constant, do the conversions to the signed
    1971                 :            :      type and subtract.  The hardware will do the right thing with any
    1972                 :            :      overflow in the subtraction.  */
    1973                 :    8563030 :   if (TREE_CODE (arg0) != INTEGER_CST || TREE_CODE (arg1) != INTEGER_CST)
    1974                 :       5073 :     return size_binop_loc (loc, MINUS_EXPR,
    1975                 :            :                            fold_convert_loc (loc, ctype, arg0),
    1976                 :       5073 :                            fold_convert_loc (loc, ctype, arg1));
    1977                 :            : 
    1978                 :            :   /* If ARG0 is larger than ARG1, subtract and return the result in CTYPE.
    1979                 :            :      Otherwise, subtract the other way, convert to CTYPE (we know that can't
    1980                 :            :      overflow) and negate (which can't either).  Special-case a result
    1981                 :            :      of zero while we're here.  */
    1982                 :    8557960 :   if (tree_int_cst_equal (arg0, arg1))
    1983                 :    6751870 :     return build_int_cst (ctype, 0);
    1984                 :    1806090 :   else if (tree_int_cst_lt (arg1, arg0))
    1985                 :    1562380 :     return fold_convert_loc (loc, ctype,
    1986                 :    1562380 :                              size_binop_loc (loc, MINUS_EXPR, arg0, arg1));
    1987                 :            :   else
    1988                 :     243711 :     return size_binop_loc (loc, MINUS_EXPR, build_int_cst (ctype, 0),
    1989                 :            :                            fold_convert_loc (loc, ctype,
    1990                 :            :                                              size_binop_loc (loc,
    1991                 :            :                                                              MINUS_EXPR,
    1992                 :            :                                                              arg1, arg0)));
    1993                 :            : }
    1994                 :            : 
    1995                 :            : /* A subroutine of fold_convert_const handling conversions of an
    1996                 :            :    INTEGER_CST to another integer type.  */
    1997                 :            : 
    1998                 :            : static tree
    1999                 :  351444000 : fold_convert_const_int_from_int (tree type, const_tree arg1)
    2000                 :            : {
    2001                 :            :   /* Given an integer constant, make new constant with new type,
    2002                 :            :      appropriately sign-extended or truncated.  Use widest_int
    2003                 :            :      so that any extension is done according ARG1's type.  */
    2004                 :  702887000 :   return force_fit_type (type, wi::to_widest (arg1),
    2005                 :  351444000 :                          !POINTER_TYPE_P (TREE_TYPE (arg1)),
    2006                 :  351444000 :                          TREE_OVERFLOW (arg1));
    2007                 :            : }
    2008                 :            : 
    2009                 :            : /* A subroutine of fold_convert_const handling conversions a REAL_CST
    2010                 :            :    to an integer type.  */
    2011                 :            : 
    2012                 :            : static tree
    2013                 :      20933 : fold_convert_const_int_from_real (enum tree_code code, tree type, const_tree arg1)
    2014                 :            : {
    2015                 :      20933 :   bool overflow = false;
    2016                 :      20933 :   tree t;
    2017                 :            : 
    2018                 :            :   /* The following code implements the floating point to integer
    2019                 :            :      conversion rules required by the Java Language Specification,
    2020                 :            :      that IEEE NaNs are mapped to zero and values that overflow
    2021                 :            :      the target precision saturate, i.e. values greater than
    2022                 :            :      INT_MAX are mapped to INT_MAX, and values less than INT_MIN
    2023                 :            :      are mapped to INT_MIN.  These semantics are allowed by the
    2024                 :            :      C and C++ standards that simply state that the behavior of
    2025                 :            :      FP-to-integer conversion is unspecified upon overflow.  */
    2026                 :            : 
    2027                 :      20933 :   wide_int val;
    2028                 :      20933 :   REAL_VALUE_TYPE r;
    2029                 :      20933 :   REAL_VALUE_TYPE x = TREE_REAL_CST (arg1);
    2030                 :            : 
    2031                 :      20933 :   switch (code)
    2032                 :            :     {
    2033                 :      20933 :     case FIX_TRUNC_EXPR:
    2034                 :      20933 :       real_trunc (&r, VOIDmode, &x);
    2035                 :      20933 :       break;
    2036                 :            : 
    2037                 :          0 :     default:
    2038                 :          0 :       gcc_unreachable ();
    2039                 :            :     }
    2040                 :            : 
    2041                 :            :   /* If R is NaN, return zero and show we have an overflow.  */
    2042                 :      20933 :   if (REAL_VALUE_ISNAN (r))
    2043                 :            :     {
    2044                 :        364 :       overflow = true;
    2045                 :        364 :       val = wi::zero (TYPE_PRECISION (type));
    2046                 :            :     }
    2047                 :            : 
    2048                 :            :   /* See if R is less than the lower bound or greater than the
    2049                 :            :      upper bound.  */
    2050                 :            : 
    2051                 :      20933 :   if (! overflow)
    2052                 :            :     {
    2053                 :      20569 :       tree lt = TYPE_MIN_VALUE (type);
    2054                 :      20569 :       REAL_VALUE_TYPE l = real_value_from_int_cst (NULL_TREE, lt);
    2055                 :      20569 :       if (real_less (&r, &l))
    2056                 :            :         {
    2057                 :        358 :           overflow = true;
    2058                 :        358 :           val = wi::to_wide (lt);
    2059                 :            :         }
    2060                 :            :     }
    2061                 :            : 
    2062                 :      20933 :   if (! overflow)
    2063                 :            :     {
    2064                 :      20211 :       tree ut = TYPE_MAX_VALUE (type);
    2065                 :      20211 :       if (ut)
    2066                 :            :         {
    2067                 :      20211 :           REAL_VALUE_TYPE u = real_value_from_int_cst (NULL_TREE, ut);
    2068                 :      20211 :           if (real_less (&u, &r))
    2069                 :            :             {
    2070                 :        439 :               overflow = true;
    2071                 :        439 :               val = wi::to_wide (ut);
    2072                 :            :             }
    2073                 :            :         }
    2074                 :            :     }
    2075                 :            : 
    2076                 :      20933 :   if (! overflow)
    2077                 :      19772 :     val = real_to_integer (&r, &overflow, TYPE_PRECISION (type));
    2078                 :            : 
    2079                 :      20933 :   t = force_fit_type (type, val, -1, overflow | TREE_OVERFLOW (arg1));
    2080                 :      20933 :   return t;
    2081                 :            : }
    2082                 :            : 
    2083                 :            : /* A subroutine of fold_convert_const handling conversions of a
    2084                 :            :    FIXED_CST to an integer type.  */
    2085                 :            : 
    2086                 :            : static tree
    2087                 :          0 : fold_convert_const_int_from_fixed (tree type, const_tree arg1)
    2088                 :            : {
    2089                 :          0 :   tree t;
    2090                 :          0 :   double_int temp, temp_trunc;
    2091                 :          0 :   scalar_mode mode;
    2092                 :            : 
    2093                 :            :   /* Right shift FIXED_CST to temp by fbit.  */
    2094                 :          0 :   temp = TREE_FIXED_CST (arg1).data;
    2095                 :          0 :   mode = TREE_FIXED_CST (arg1).mode;
    2096                 :          0 :   if (GET_MODE_FBIT (mode) < HOST_BITS_PER_DOUBLE_INT)
    2097                 :            :     {
    2098                 :          0 :       temp = temp.rshift (GET_MODE_FBIT (mode),
    2099                 :            :                           HOST_BITS_PER_DOUBLE_INT,
    2100                 :          0 :                           SIGNED_FIXED_POINT_MODE_P (mode));
    2101                 :            : 
    2102                 :            :       /* Left shift temp to temp_trunc by fbit.  */
    2103                 :          0 :       temp_trunc = temp.lshift (GET_MODE_FBIT (mode),
    2104                 :            :                                 HOST_BITS_PER_DOUBLE_INT,
    2105                 :          0 :                                 SIGNED_FIXED_POINT_MODE_P (mode));
    2106                 :            :     }
    2107                 :            :   else
    2108                 :            :     {
    2109                 :          0 :       temp = double_int_zero;
    2110                 :          0 :       temp_trunc = double_int_zero;
    2111                 :            :     }
    2112                 :            : 
    2113                 :            :   /* If FIXED_CST is negative, we need to round the value toward 0.
    2114                 :            :      By checking if the fractional bits are not zero to add 1 to temp.  */
    2115                 :          0 :   if (SIGNED_FIXED_POINT_MODE_P (mode)
    2116                 :          0 :       && temp_trunc.is_negative ()
    2117                 :          0 :       && TREE_FIXED_CST (arg1).data != temp_trunc)
    2118                 :          0 :     temp += double_int_one;
    2119                 :            : 
    2120                 :            :   /* Given a fixed-point constant, make new constant with new type,
    2121                 :            :      appropriately sign-extended or truncated.  */
    2122                 :          0 :   t = force_fit_type (type, temp, -1,
    2123                 :          0 :                       (temp.is_negative ()
    2124                 :          0 :                        && (TYPE_UNSIGNED (type)
    2125                 :          0 :                            < TYPE_UNSIGNED (TREE_TYPE (arg1))))
    2126                 :          0 :                       | TREE_OVERFLOW (arg1));
    2127                 :            : 
    2128                 :          0 :   return t;
    2129                 :            : }
    2130                 :            : 
    2131                 :            : /* A subroutine of fold_convert_const handling conversions a REAL_CST
    2132                 :            :    to another floating point type.  */
    2133                 :            : 
    2134                 :            : static tree
    2135                 :     525576 : fold_convert_const_real_from_real (tree type, const_tree arg1)
    2136                 :            : {
    2137                 :     525576 :   REAL_VALUE_TYPE value;
    2138                 :     525576 :   tree t;
    2139                 :            : 
    2140                 :            :   /* Don't perform the operation if flag_signaling_nans is on
    2141                 :            :      and the operand is a signaling NaN.  */
    2142                 :     525576 :   if (HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg1)))
    2143                 :     526021 :       && REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (arg1)))
    2144                 :            :     return NULL_TREE; 
    2145                 :            : 
    2146                 :     525576 :   real_convert (&value, TYPE_MODE (type), &TREE_REAL_CST (arg1));
    2147                 :     525576 :   t = build_real (type, value);
    2148                 :            : 
    2149                 :            :   /* If converting an infinity or NAN to a representation that doesn't
    2150                 :            :      have one, set the overflow bit so that we can produce some kind of
    2151                 :            :      error message at the appropriate point if necessary.  It's not the
    2152                 :            :      most user-friendly message, but it's better than nothing.  */
    2153                 :     525576 :   if (REAL_VALUE_ISINF (TREE_REAL_CST (arg1))
    2154                 :     543727 :       && !MODE_HAS_INFINITIES (TYPE_MODE (type)))
    2155                 :          0 :     TREE_OVERFLOW (t) = 1;
    2156                 :     525576 :   else if (REAL_VALUE_ISNAN (TREE_REAL_CST (arg1))
    2157                 :     533677 :            && !MODE_HAS_NANS (TYPE_MODE (type)))
    2158                 :          0 :     TREE_OVERFLOW (t) = 1;
    2159                 :            :   /* Regular overflow, conversion produced an infinity in a mode that
    2160                 :            :      can't represent them.  */
    2161                 :    3671690 :   else if (!MODE_HAS_INFINITIES (TYPE_MODE (type))
    2162                 :          0 :            && REAL_VALUE_ISINF (value)
    2163                 :     525576 :            && !REAL_VALUE_ISINF (TREE_REAL_CST (arg1)))
    2164                 :          0 :     TREE_OVERFLOW (t) = 1;
    2165                 :            :   else
    2166                 :     525576 :     TREE_OVERFLOW (t) = TREE_OVERFLOW (arg1);
    2167                 :            :   return t;
    2168                 :            : }
    2169                 :            : 
    2170                 :            : /* A subroutine of fold_convert_const handling conversions a FIXED_CST
    2171                 :            :    to a floating point type.  */
    2172                 :            : 
    2173                 :            : static tree
    2174                 :          0 : fold_convert_const_real_from_fixed (tree type, const_tree arg1)
    2175                 :            : {
    2176                 :          0 :   REAL_VALUE_TYPE value;
    2177                 :          0 :   tree t;
    2178                 :            : 
    2179                 :          0 :   real_convert_from_fixed (&value, SCALAR_FLOAT_TYPE_MODE (type),
    2180                 :          0 :                            &TREE_FIXED_CST (arg1));
    2181                 :          0 :   t = build_real (type, value);
    2182                 :            : 
    2183                 :          0 :   TREE_OVERFLOW (t) = TREE_OVERFLOW (arg1);
    2184                 :          0 :   return t;
    2185                 :            : }
    2186                 :            : 
    2187                 :            : /* A subroutine of fold_convert_const handling conversions a FIXED_CST
    2188                 :            :    to another fixed-point type.  */
    2189                 :            : 
    2190                 :            : static tree
    2191                 :          0 : fold_convert_const_fixed_from_fixed (tree type, const_tree arg1)
    2192                 :            : {
    2193                 :          0 :   FIXED_VALUE_TYPE value;
    2194                 :          0 :   tree t;
    2195                 :          0 :   bool overflow_p;
    2196                 :            : 
    2197                 :          0 :   overflow_p = fixed_convert (&value, SCALAR_TYPE_MODE (type),
    2198                 :          0 :                               &TREE_FIXED_CST (arg1), TYPE_SATURATING (type));
    2199                 :          0 :   t = build_fixed (type, value);
    2200                 :            : 
    2201                 :            :   /* Propagate overflow flags.  */
    2202                 :          0 :   if (overflow_p | TREE_OVERFLOW (arg1))
    2203                 :          0 :     TREE_OVERFLOW (t) = 1;
    2204                 :          0 :   return t;
    2205                 :            : }
    2206                 :            : 
    2207                 :            : /* A subroutine of fold_convert_const handling conversions an INTEGER_CST
    2208                 :            :    to a fixed-point type.  */
    2209                 :            : 
    2210                 :            : static tree
    2211                 :          0 : fold_convert_const_fixed_from_int (tree type, const_tree arg1)
    2212                 :            : {
    2213                 :          0 :   FIXED_VALUE_TYPE value;
    2214                 :          0 :   tree t;
    2215                 :          0 :   bool overflow_p;
    2216                 :          0 :   double_int di;
    2217                 :            : 
    2218                 :          0 :   gcc_assert (TREE_INT_CST_NUNITS (arg1) <= 2);
    2219                 :            : 
    2220                 :          0 :   di.low = TREE_INT_CST_ELT (arg1, 0);
    2221                 :          0 :   if (TREE_INT_CST_NUNITS (arg1) == 1)
    2222                 :          0 :     di.high = (HOST_WIDE_INT) di.low < 0 ? HOST_WIDE_INT_M1 : 0;
    2223                 :            :   else
    2224                 :          0 :     di.high = TREE_INT_CST_ELT (arg1, 1);
    2225                 :            : 
    2226                 :          0 :   overflow_p = fixed_convert_from_int (&value, SCALAR_TYPE_MODE (type), di,
    2227                 :          0 :                                        TYPE_UNSIGNED (TREE_TYPE (arg1)),
    2228                 :          0 :                                        TYPE_SATURATING (type));
    2229                 :          0 :   t = build_fixed (type, value);
    2230                 :            : 
    2231                 :            :   /* Propagate overflow flags.  */
    2232                 :          0 :   if (overflow_p | TREE_OVERFLOW (arg1))
    2233                 :          0 :     TREE_OVERFLOW (t) = 1;
    2234                 :          0 :   return t;
    2235                 :            : }
    2236                 :            : 
    2237                 :            : /* A subroutine of fold_convert_const handling conversions a REAL_CST
    2238                 :            :    to a fixed-point type.  */
    2239                 :            : 
    2240                 :            : static tree
    2241                 :          0 : fold_convert_const_fixed_from_real (tree type, const_tree arg1)
    2242                 :            : {
    2243                 :          0 :   FIXED_VALUE_TYPE value;
    2244                 :          0 :   tree t;
    2245                 :          0 :   bool overflow_p;
    2246                 :            : 
    2247                 :          0 :   overflow_p = fixed_convert_from_real (&value, SCALAR_TYPE_MODE (type),
    2248                 :          0 :                                         &TREE_REAL_CST (arg1),
    2249                 :          0 :                                         TYPE_SATURATING (type));
    2250                 :          0 :   t = build_fixed (type, value);
    2251                 :            : 
    2252                 :            :   /* Propagate overflow flags.  */
    2253                 :          0 :   if (overflow_p | TREE_OVERFLOW (arg1))
    2254                 :          0 :     TREE_OVERFLOW (t) = 1;
    2255                 :          0 :   return t;
    2256                 :            : }
    2257                 :            : 
    2258                 :            : /* Attempt to fold type conversion operation CODE of expression ARG1 to
    2259                 :            :    type TYPE.  If no simplification can be done return NULL_TREE.  */
    2260                 :            : 
    2261                 :            : static tree
    2262                 :  358890000 : fold_convert_const (enum tree_code code, tree type, tree arg1)
    2263                 :            : {
    2264                 :  358890000 :   tree arg_type = TREE_TYPE (arg1);
    2265                 :  358890000 :   if (arg_type == type)
    2266                 :            :     return arg1;
    2267                 :            : 
    2268                 :            :   /* We can't widen types, since the runtime value could overflow the
    2269                 :            :      original type before being extended to the new type.  */
    2270                 :  357250000 :   if (POLY_INT_CST_P (arg1)
    2271                 :            :       && (POINTER_TYPE_P (type) || INTEGRAL_TYPE_P (type))
    2272                 :            :       && TYPE_PRECISION (type) <= TYPE_PRECISION (arg_type))
    2273                 :            :     return build_poly_int_cst (type,
    2274                 :            :                                poly_wide_int::from (poly_int_cst_value (arg1),
    2275                 :            :                                                     TYPE_PRECISION (type),
    2276                 :            :                                                     TYPE_SIGN (arg_type)));
    2277                 :            : 
    2278                 :  357250000 :   if (POINTER_TYPE_P (type) || INTEGRAL_TYPE_P (type)
    2279                 :    2471780 :       || TREE_CODE (type) == OFFSET_TYPE)
    2280                 :            :     {
    2281                 :  354780000 :       if (TREE_CODE (arg1) == INTEGER_CST)
    2282                 :  351444000 :         return fold_convert_const_int_from_int (type, arg1);
    2283                 :    3336740 :       else if (TREE_CODE (arg1) == REAL_CST)
    2284                 :      20933 :         return fold_convert_const_int_from_real (code, type, arg1);
    2285                 :    3315810 :       else if (TREE_CODE (arg1) == FIXED_CST)
    2286                 :          0 :         return fold_convert_const_int_from_fixed (type, arg1);
    2287                 :            :     }
    2288                 :    2469880 :   else if (TREE_CODE (type) == REAL_TYPE)
    2289                 :            :     {
    2290                 :    2433840 :       if (TREE_CODE (arg1) == INTEGER_CST)
    2291                 :    1576480 :         return build_real_from_int_cst (type, arg1);
    2292                 :     857365 :       else if (TREE_CODE (arg1) == REAL_CST)
    2293                 :     525576 :         return fold_convert_const_real_from_real (type, arg1);
    2294                 :     331789 :       else if (TREE_CODE (arg1) == FIXED_CST)
    2295                 :          0 :         return fold_convert_const_real_from_fixed (type, arg1);
    2296                 :            :     }
    2297                 :      36043 :   else if (TREE_CODE (type) == FIXED_POINT_TYPE)
    2298                 :            :     {
    2299                 :          0 :       if (TREE_CODE (arg1) == FIXED_CST)
    2300                 :          0 :         return fold_convert_const_fixed_from_fixed (type, arg1);
    2301                 :          0 :       else if (TREE_CODE (arg1) == INTEGER_CST)
    2302                 :          0 :         return fold_convert_const_fixed_from_int (type, arg1);
    2303                 :          0 :       else if (TREE_CODE (arg1) == REAL_CST)
    2304                 :          0 :         return fold_convert_const_fixed_from_real (type, arg1);
    2305                 :            :     }
    2306                 :      36043 :   else if (TREE_CODE (type) == VECTOR_TYPE)
    2307                 :            :     {
    2308                 :       1282 :       if (TREE_CODE (arg1) == VECTOR_CST
    2309                 :       1282 :           && known_eq (TYPE_VECTOR_SUBPARTS (type), VECTOR_CST_NELTS (arg1)))
    2310                 :            :         {
    2311                 :       1282 :           tree elttype = TREE_TYPE (type);
    2312                 :       1282 :           tree arg1_elttype = TREE_TYPE (TREE_TYPE (arg1));
    2313                 :            :           /* We can't handle steps directly when extending, since the
    2314                 :            :              values need to wrap at the original precision first.  */
    2315                 :       1282 :           bool step_ok_p
    2316                 :       1282 :             = (INTEGRAL_TYPE_P (elttype)
    2317                 :         64 :                && INTEGRAL_TYPE_P (arg1_elttype)
    2318                 :       1320 :                && TYPE_PRECISION (elttype) <= TYPE_PRECISION (arg1_elttype));
    2319                 :       2564 :           tree_vector_builder v;
    2320                 :       1282 :           if (!v.new_unary_operation (type, arg1, step_ok_p))
    2321                 :            :             return NULL_TREE;
    2322                 :       1282 :           unsigned int len = v.encoded_nelts ();
    2323                 :       6496 :           for (unsigned int i = 0; i < len; ++i)
    2324                 :            :             {
    2325                 :       5214 :               tree elt = VECTOR_CST_ELT (arg1, i);
    2326                 :       5214 :               tree cvt = fold_convert_const (code, elttype, elt);
    2327                 :       5214 :               if (cvt == NULL_TREE)
    2328                 :       1282 :                 return NULL_TREE;
    2329                 :       5214 :               v.quick_push (cvt);
    2330                 :            :             }
    2331                 :       1282 :           return v.build ();
    2332                 :            :         }
    2333                 :            :     }
    2334                 :            :   return NULL_TREE;
    2335                 :            : }
    2336                 :            : 
    2337                 :            : /* Construct a vector of zero elements of vector type TYPE.  */
    2338                 :            : 
    2339                 :            : static tree
    2340                 :       4456 : build_zero_vector (tree type)
    2341                 :            : {
    2342                 :       4456 :   tree t;
    2343                 :            : 
    2344                 :       4456 :   t = fold_convert_const (NOP_EXPR, TREE_TYPE (type), integer_zero_node);
    2345                 :       4456 :   return build_vector_from_val (type, t);
    2346                 :            : }
    2347                 :            : 
    2348                 :            : /* Returns true, if ARG is convertible to TYPE using a NOP_EXPR.  */
    2349                 :            : 
    2350                 :            : bool
    2351                 :      99052 : fold_convertible_p (const_tree type, const_tree arg)
    2352                 :            : {
    2353                 :      99052 :   tree orig = TREE_TYPE (arg);
    2354                 :            : 
    2355                 :      99052 :   if (type == orig)
    2356                 :            :     return true;
    2357                 :            : 
    2358                 :      99052 :   if (TREE_CODE (arg) == ERROR_MARK
    2359                 :      99052 :       || TREE_CODE (type) == ERROR_MARK
    2360                 :      99052 :       || TREE_CODE (orig) == ERROR_MARK)
    2361                 :            :     return false;
    2362                 :            : 
    2363                 :      99052 :   if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (orig))
    2364                 :            :     return true;
    2365                 :            : 
    2366                 :      99052 :   switch (TREE_CODE (type))
    2367                 :            :     {
    2368                 :      98999 :     case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
    2369                 :      98999 :     case POINTER_TYPE: case REFERENCE_TYPE:
    2370                 :      98999 :     case OFFSET_TYPE:
    2371                 :      98999 :       return (INTEGRAL_TYPE_P (orig)
    2372                 :        170 :               || (POINTER_TYPE_P (orig)
    2373                 :        139 :                   && TYPE_PRECISION (type) <= TYPE_PRECISION (orig))
    2374                 :      99036 :               || TREE_CODE (orig) == OFFSET_TYPE);
    2375                 :            : 
    2376                 :         39 :     case REAL_TYPE:
    2377                 :         39 :     case FIXED_POINT_TYPE:
    2378                 :         39 :     case VOID_TYPE:
    2379                 :         39 :       return TREE_CODE (type) == TREE_CODE (orig);
    2380                 :            : 
    2381                 :          1 :     case VECTOR_TYPE:
    2382                 :          1 :       return (VECTOR_TYPE_P (orig)
    2383                 :          1 :               && known_eq (TYPE_VECTOR_SUBPARTS (type),
    2384                 :            :                            TYPE_VECTOR_SUBPARTS (orig))
    2385                 :          1 :               && fold_convertible_p (TREE_TYPE (type), TREE_TYPE (orig)));
    2386                 :            : 
    2387                 :            :     default:
    2388                 :            :       return false;
    2389                 :            :     }
    2390                 :            : }
    2391                 :            : 
    2392                 :            : /* Convert expression ARG to type TYPE.  Used by the middle-end for
    2393                 :            :    simple conversions in preference to calling the front-end's convert.  */
    2394                 :            : 
    2395                 :            : tree
    2396                 :  597364000 : fold_convert_loc (location_t loc, tree type, tree arg)
    2397                 :            : {
    2398                 :  597364000 :   tree orig = TREE_TYPE (arg);
    2399                 :  597364000 :   tree tem;
    2400                 :            : 
    2401                 :  597364000 :   if (type == orig)
    2402                 :            :     return arg;
    2403                 :            : 
    2404                 :  408150000 :   if (TREE_CODE (arg) == ERROR_MARK
    2405                 :  408149000 :       || TREE_CODE (type) == ERROR_MARK
    2406                 :  408149000 :       || TREE_CODE (orig) == ERROR_MARK)
    2407                 :        706 :     return error_mark_node;
    2408                 :            : 
    2409                 :  408149000 :   switch (TREE_CODE (type))
    2410                 :            :     {
    2411                 :   17853900 :     case POINTER_TYPE:
    2412                 :   17853900 :     case REFERENCE_TYPE:
    2413                 :            :       /* Handle conversions between pointers to different address spaces.  */
    2414                 :   17853900 :       if (POINTER_TYPE_P (orig)
    2415                 :   31893900 :           && (TYPE_ADDR_SPACE (TREE_TYPE (type))
    2416                 :   14040000 :               != TYPE_ADDR_SPACE (TREE_TYPE (orig))))
    2417                 :         69 :         return fold_build1_loc (loc, ADDR_SPACE_CONVERT_EXPR, type, arg);
    2418                 :            :       /* fall through */
    2419                 :            : 
    2420                 :  392045000 :     case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
    2421                 :  392045000 :     case OFFSET_TYPE:
    2422                 :  392045000 :       if (TREE_CODE (arg) == INTEGER_CST)
    2423                 :            :         {
    2424                 :  319813000 :           tem = fold_convert_const (NOP_EXPR, type, arg);
    2425                 :  319813000 :           if (tem != NULL_TREE)
    2426                 :            :             return tem;
    2427                 :            :         }
    2428                 :   72231300 :       if (INTEGRAL_TYPE_P (orig) || POINTER_TYPE_P (orig)
    2429                 :       1313 :           || TREE_CODE (orig) == OFFSET_TYPE)
    2430                 :   72231300 :         return fold_build1_loc (loc, NOP_EXPR, type, arg);
    2431                 :          2 :       if (TREE_CODE (orig) == COMPLEX_TYPE)
    2432                 :          2 :         return fold_convert_loc (loc, type,
    2433                 :            :                                  fold_build1_loc (loc, REALPART_EXPR,
    2434                 :          2 :                                                   TREE_TYPE (orig), arg));
    2435                 :          0 :       gcc_assert (TREE_CODE (orig) == VECTOR_TYPE
    2436                 :            :                   && tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (orig)));
    2437                 :          0 :       return fold_build1_loc (loc, VIEW_CONVERT_EXPR, type, arg);
    2438                 :            : 
    2439                 :     238467 :     case REAL_TYPE:
    2440                 :     238467 :       if (TREE_CODE (arg) == INTEGER_CST)
    2441                 :            :         {
    2442                 :      86250 :           tem = fold_convert_const (FLOAT_EXPR, type, arg);
    2443                 :      86250 :           if (tem != NULL_TREE)
    2444                 :            :             return tem;
    2445                 :            :         }
    2446                 :     152217 :       else if (TREE_CODE (arg) == REAL_CST)
    2447                 :            :         {
    2448                 :      59464 :           tem = fold_convert_const (NOP_EXPR, type, arg);
    2449                 :      59464 :           if (tem != NULL_TREE)
    2450                 :            :             return tem;
    2451                 :            :         }
    2452                 :      92753 :       else if (TREE_CODE (arg) == FIXED_CST)
    2453                 :            :         {
    2454                 :          0 :           tem = fold_convert_const (FIXED_CONVERT_EXPR, type, arg);
    2455                 :          0 :           if (tem != NULL_TREE)
    2456                 :            :             return tem;
    2457                 :            :         }
    2458                 :            : 
    2459                 :      92753 :       switch (TREE_CODE (orig))
    2460                 :            :         {
    2461                 :        351 :         case INTEGER_TYPE:
    2462                 :        351 :         case BOOLEAN_TYPE: case ENUMERAL_TYPE:
    2463                 :        351 :         case POINTER_TYPE: case REFERENCE_TYPE:
    2464                 :        351 :           return fold_build1_loc (loc, FLOAT_EXPR, type, arg);
    2465                 :            : 
    2466                 :      92402 :         case REAL_TYPE:
    2467                 :      92402 :           return fold_build1_loc (loc, NOP_EXPR, type, arg);
    2468                 :            : 
    2469                 :          0 :         case FIXED_POINT_TYPE:
    2470                 :          0 :           return fold_build1_loc (loc, FIXED_CONVERT_EXPR, type, arg);
    2471                 :            : 
    2472                 :          0 :         case COMPLEX_TYPE:
    2473                 :          0 :           tem = fold_build1_loc (loc, REALPART_EXPR, TREE_TYPE (orig), arg);
    2474                 :          0 :           return fold_convert_loc (loc, type, tem);
    2475                 :            : 
    2476                 :          0 :         default:
    2477                 :          0 :           gcc_unreachable ();
    2478                 :            :         }
    2479                 :            : 
    2480                 :          0 :     case FIXED_POINT_TYPE:
    2481                 :          0 :       if (TREE_CODE (arg) == FIXED_CST || TREE_CODE (arg) == INTEGER_CST
    2482                 :          0 :           || TREE_CODE (arg) == REAL_CST)
    2483                 :            :         {
    2484                 :          0 :           tem = fold_convert_const (FIXED_CONVERT_EXPR, type, arg);
    2485                 :          0 :           if (tem != NULL_TREE)
    2486                 :          0 :             goto fold_convert_exit;
    2487                 :            :         }
    2488                 :            : 
    2489                 :          0 :       switch (TREE_CODE (orig))
    2490                 :            :         {
    2491                 :          0 :         case FIXED_POINT_TYPE:
    2492                 :          0 :         case INTEGER_TYPE:
    2493                 :          0 :         case ENUMERAL_TYPE:
    2494                 :          0 :         case BOOLEAN_TYPE:
    2495                 :          0 :         case REAL_TYPE:
    2496                 :          0 :           return fold_build1_loc (loc, FIXED_CONVERT_EXPR, type, arg);
    2497                 :            : 
    2498                 :          0 :         case COMPLEX_TYPE:
    2499                 :          0 :           tem = fold_build1_loc (loc, REALPART_EXPR, TREE_TYPE (orig), arg);
    2500                 :          0 :           return fold_convert_loc (loc, type, tem);
    2501                 :            : 
    2502                 :          0 :         default:
    2503                 :          0 :           gcc_unreachable ();
    2504                 :            :         }
    2505                 :            : 
    2506                 :       1639 :     case COMPLEX_TYPE:
    2507                 :       1639 :       switch (TREE_CODE (orig))
    2508                 :            :         {
    2509                 :         51 :         case INTEGER_TYPE:
    2510                 :         51 :         case BOOLEAN_TYPE: case ENUMERAL_TYPE:
    2511                 :         51 :         case POINTER_TYPE: case REFERENCE_TYPE:
    2512                 :         51 :         case REAL_TYPE:
    2513                 :         51 :         case FIXED_POINT_TYPE:
    2514                 :        153 :           return fold_build2_loc (loc, COMPLEX_EXPR, type,
    2515                 :         51 :                               fold_convert_loc (loc, TREE_TYPE (type), arg),
    2516                 :         51 :                               fold_convert_loc (loc, TREE_TYPE (type),
    2517                 :         51 :                                             integer_zero_node));
    2518                 :       1588 :         case COMPLEX_TYPE:
    2519                 :       1588 :           {
    2520                 :       1588 :             tree rpart, ipart;
    2521                 :            : 
    2522                 :       1588 :             if (TREE_CODE (arg) == COMPLEX_EXPR)
    2523                 :            :               {
    2524                 :       1486 :                 rpart = fold_convert_loc (loc, TREE_TYPE (type),
    2525                 :       1486 :                                       TREE_OPERAND (arg, 0));
    2526                 :       1486 :                 ipart = fold_convert_loc (loc, TREE_TYPE (type),
    2527                 :       1486 :                                       TREE_OPERAND (arg, 1));
    2528                 :       1486 :                 return fold_build2_loc (loc, COMPLEX_EXPR, type, rpart, ipart);
    2529                 :            :               }
    2530                 :            : 
    2531                 :        102 :             arg = save_expr (arg);
    2532                 :        102 :             rpart = fold_build1_loc (loc, REALPART_EXPR, TREE_TYPE (orig), arg);
    2533                 :        102 :             ipart = fold_build1_loc (loc, IMAGPART_EXPR, TREE_TYPE (orig), arg);
    2534                 :        102 :             rpart = fold_convert_loc (loc, TREE_TYPE (type), rpart);
    2535                 :        102 :             ipart = fold_convert_loc (loc, TREE_TYPE (type), ipart);
    2536                 :        102 :             return fold_build2_loc (loc, COMPLEX_EXPR, type, rpart, ipart);
    2537                 :            :           }
    2538                 :            : 
    2539                 :          0 :         default:
    2540                 :          0 :           gcc_unreachable ();
    2541                 :            :         }
    2542                 :            : 
    2543                 :   15790800 :     case VECTOR_TYPE:
    2544                 :   15790800 :       if (integer_zerop (arg))
    2545                 :       4456 :         return build_zero_vector (type);
    2546                 :   15786400 :       gcc_assert (tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (orig)));
    2547                 :   15786400 :       gcc_assert (INTEGRAL_TYPE_P (orig) || POINTER_TYPE_P (orig)
    2548                 :            :                   || TREE_CODE (orig) == VECTOR_TYPE);
    2549                 :   15786400 :       return fold_build1_loc (loc, VIEW_CONVERT_EXPR, type, arg);
    2550                 :            : 
    2551                 :      70571 :     case VOID_TYPE:
    2552                 :      70571 :       tem = fold_ignored_result (arg);
    2553                 :      70571 :       return fold_build1_loc (loc, NOP_EXPR, type, tem);
    2554                 :            : 
    2555                 :       2628 :     default:
    2556                 :       2628 :       if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (orig))
    2557                 :       2628 :         return fold_build1_loc (loc, NOP_EXPR, type, arg);
    2558                 :          0 :       gcc_unreachable ();
    2559                 :            :     }
    2560                 :          0 :  fold_convert_exit:
    2561                 :          0 :   protected_set_expr_location_unshare (tem, loc);
    2562                 :          0 :   return tem;
    2563                 :            : }
    2564                 :            : 
    2565                 :            : /* Return false if expr can be assumed not to be an lvalue, true
    2566                 :            :    otherwise.  */
    2567                 :            : 
    2568                 :            : static bool
    2569                 :    7813710 : maybe_lvalue_p (const_tree x)
    2570                 :            : {
    2571                 :            :   /* We only need to wrap lvalue tree codes.  */
    2572                 :    7813710 :   switch (TREE_CODE (x))
    2573                 :            :   {
    2574                 :            :   case VAR_DECL:
    2575                 :            :   case PARM_DECL:
    2576                 :            :   case RESULT_DECL:
    2577                 :            :   case LABEL_DECL:
    2578                 :            :   case FUNCTION_DECL:
    2579                 :            :   case SSA_NAME:
    2580                 :            : 
    2581                 :            :   case COMPONENT_REF:
    2582                 :            :   case MEM_REF:
    2583                 :            :   case INDIRECT_REF:
    2584                 :            :   case ARRAY_REF:
    2585                 :            :   case ARRAY_RANGE_REF:
    2586                 :            :   case BIT_FIELD_REF:
    2587                 :            :   case OBJ_TYPE_REF:
    2588                 :            : 
    2589                 :            :   case REALPART_EXPR:
    2590                 :            :   case IMAGPART_EXPR:
    2591                 :            :   case PREINCREMENT_EXPR:
    2592                 :            :   case PREDECREMENT_EXPR:
    2593                 :            :   case SAVE_EXPR:
    2594                 :            :   case TRY_CATCH_EXPR:
    2595                 :            :   case WITH_CLEANUP_EXPR:
    2596                 :            :   case COMPOUND_EXPR:
    2597                 :            :   case MODIFY_EXPR:
    2598                 :            :   case TARGET_EXPR:
    2599                 :            :   case COND_EXPR:
    2600                 :            :   case BIND_EXPR:
    2601                 :            :   case VIEW_CONVERT_EXPR:
    2602                 :            :     break;
    2603                 :            : 
    2604                 :    4564780 :   default:
    2605                 :            :     /* Assume the worst for front-end tree codes.  */
    2606                 :    4564780 :     if ((int)TREE_CODE (x) >= NUM_TREE_CODES)
    2607                 :            :       break;
    2608                 :            :     return false;
    2609                 :            :   }
    2610                 :            : 
    2611                 :    3250840 :   return true;
    2612                 :            : }
    2613                 :            : 
    2614                 :            : /* Return an expr equal to X but certainly not valid as an lvalue.  */
    2615                 :            : 
    2616                 :            : tree
    2617                 :   19852900 : non_lvalue_loc (location_t loc, tree x)
    2618                 :            : {
    2619                 :            :   /* While we are in GIMPLE, NON_LVALUE_EXPR doesn't mean anything to
    2620                 :            :      us.  */
    2621                 :   19852900 :   if (in_gimple_form)
    2622                 :            :     return x;
    2623                 :            : 
    2624                 :    2418160 :   if (! maybe_lvalue_p (x))
    2625                 :            :     return x;
    2626                 :     786995 :   return build1_loc (loc, NON_LVALUE_EXPR, TREE_TYPE (x), x);
    2627                 :            : }
    2628                 :            : 
    2629                 :            : /* When pedantic, return an expr equal to X but certainly not valid as a
    2630                 :            :    pedantic lvalue.  Otherwise, return X.  */
    2631                 :            : 
    2632                 :            : static tree
    2633                 :     419741 : pedantic_non_lvalue_loc (location_t loc, tree x)
    2634                 :            : {
    2635                 :          0 :   return protected_set_expr_location_unshare (x, loc);
    2636                 :            : }
    2637                 :            : 
    2638                 :            : /* Given a tree comparison code, return the code that is the logical inverse.
    2639                 :            :    It is generally not safe to do this for floating-point comparisons, except
    2640                 :            :    for EQ_EXPR, NE_EXPR, ORDERED_EXPR and UNORDERED_EXPR, so we return
    2641                 :            :    ERROR_MARK in this case.  */
    2642                 :            : 
    2643                 :            : enum tree_code
    2644                 :   95988700 : invert_tree_comparison (enum tree_code code, bool honor_nans)
    2645                 :            : {
    2646                 :   95988700 :   if (honor_nans && flag_trapping_math && code != EQ_EXPR && code != NE_EXPR
    2647                 :     319665 :       && code != ORDERED_EXPR && code != UNORDERED_EXPR)
    2648                 :            :     return ERROR_MARK;
    2649                 :            : 
    2650                 :   95737700 :   switch (code)
    2651                 :            :     {
    2652                 :            :     case EQ_EXPR:
    2653                 :            :       return NE_EXPR;
    2654                 :   41202000 :     case NE_EXPR:
    2655                 :   41202000 :       return EQ_EXPR;
    2656                 :    9124560 :     case GT_EXPR:
    2657                 :    9124560 :       return honor_nans ? UNLE_EXPR : LE_EXPR;
    2658                 :    7568800 :     case GE_EXPR:
    2659                 :    7568800 :       return honor_nans ? UNLT_EXPR : LT_EXPR;
    2660                 :    6734370 :     case LT_EXPR:
    2661                 :    6734370 :       return honor_nans ? UNGE_EXPR : GE_EXPR;
    2662                 :    6707850 :     case LE_EXPR:
    2663                 :    6707850 :       return honor_nans ? UNGT_EXPR : GT_EXPR;
    2664                 :        284 :     case LTGT_EXPR:
    2665                 :        284 :       return UNEQ_EXPR;
    2666                 :        311 :     case UNEQ_EXPR:
    2667                 :        311 :       return LTGT_EXPR;
    2668                 :       3113 :     case UNGT_EXPR:
    2669                 :       3113 :       return LE_EXPR;
    2670                 :      28604 :     case UNGE_EXPR:
    2671                 :      28604 :       return LT_EXPR;
    2672                 :       1921 :     case UNLT_EXPR:
    2673                 :       1921 :       return GE_EXPR;
    2674                 :      27394 :     case UNLE_EXPR:
    2675                 :      27394 :       return GT_EXPR;
    2676                 :      40922 :     case ORDERED_EXPR:
    2677                 :      40922 :       return UNORDERED_EXPR;
    2678                 :      45784 :     case UNORDERED_EXPR:
    2679                 :      45784 :       return ORDERED_EXPR;
    2680                 :          0 :     default:
    2681                 :          0 :       gcc_unreachable ();
    2682                 :            :     }
    2683                 :            : }
    2684                 :            : 
    2685                 :            : /* Similar, but return the comparison that results if the operands are
    2686                 :            :    swapped.  This is safe for floating-point.  */
    2687                 :            : 
    2688                 :            : enum tree_code
    2689                 :  172762000 : swap_tree_comparison (enum tree_code code)
    2690                 :            : {
    2691                 :  172762000 :   switch (code)
    2692                 :            :     {
    2693                 :            :     case EQ_EXPR:
    2694                 :            :     case NE_EXPR:
    2695                 :            :     case ORDERED_EXPR:
    2696                 :            :     case UNORDERED_EXPR:
    2697                 :            :     case LTGT_EXPR:
    2698                 :            :     case UNEQ_EXPR:
    2699                 :            :       return code;
    2700                 :   28787600 :     case GT_EXPR:
    2701                 :   28787600 :       return LT_EXPR;
    2702                 :    9512440 :     case GE_EXPR:
    2703                 :    9512440 :       return LE_EXPR;
    2704                 :   21828600 :     case LT_EXPR:
    2705                 :   21828600 :       return GT_EXPR;
    2706                 :   13309300 :     case LE_EXPR:
    2707                 :   13309300 :       return GE_EXPR;
    2708                 :       7132 :     case UNGT_EXPR:
    2709                 :       7132 :       return UNLT_EXPR;
    2710                 :      29330 :     case UNGE_EXPR:
    2711                 :      29330 :       return UNLE_EXPR;
    2712                 :       6059 :     case UNLT_EXPR:
    2713                 :       6059 :       return UNGT_EXPR;
    2714                 :       9762 :     case UNLE_EXPR:
    2715                 :       9762 :       return UNGE_EXPR;
    2716                 :          0 :     default:
    2717                 :          0 :       gcc_unreachable ();
    2718                 :            :     }
    2719                 :            : }
    2720                 :            : 
    2721                 :            : 
    2722                 :            : /* Convert a comparison tree code from an enum tree_code representation
    2723                 :            :    into a compcode bit-based encoding.  This function is the inverse of
    2724                 :            :    compcode_to_comparison.  */
    2725                 :            : 
    2726                 :            : static enum comparison_code
    2727                 :      15994 : comparison_to_compcode (enum tree_code code)
    2728                 :            : {
    2729                 :          0 :   switch (code)
    2730                 :            :     {
    2731                 :            :     case LT_EXPR:
    2732                 :            :       return COMPCODE_LT;
    2733                 :            :     case EQ_EXPR:
    2734                 :            :       return COMPCODE_EQ;
    2735                 :            :     case LE_EXPR:
    2736                 :            :       return COMPCODE_LE;
    2737                 :            :     case GT_EXPR:
    2738                 :            :       return COMPCODE_GT;
    2739                 :            :     case NE_EXPR:
    2740                 :            :       return COMPCODE_NE;
    2741                 :            :     case GE_EXPR:
    2742                 :            :       return COMPCODE_GE;
    2743                 :            :     case ORDERED_EXPR:
    2744                 :            :       return COMPCODE_ORD;
    2745                 :            :     case UNORDERED_EXPR:
    2746                 :            :       return COMPCODE_UNORD;
    2747                 :            :     case UNLT_EXPR:
    2748                 :            :       return COMPCODE_UNLT;
    2749                 :            :     case UNEQ_EXPR:
    2750                 :            :       return COMPCODE_UNEQ;
    2751                 :            :     case UNLE_EXPR:
    2752                 :            :       return COMPCODE_UNLE;
    2753                 :            :     case UNGT_EXPR:
    2754                 :            :       return COMPCODE_UNGT;
    2755                 :            :     case LTGT_EXPR:
    2756                 :            :       return COMPCODE_LTGT;
    2757                 :            :     case UNGE_EXPR:
    2758                 :            :       return COMPCODE_UNGE;
    2759                 :          0 :     default:
    2760                 :          0 :       gcc_unreachable ();
    2761                 :            :     }
    2762                 :            : }
    2763                 :            : 
    2764                 :            : /* Convert a compcode bit-based encoding of a comparison operator back
    2765                 :            :    to GCC's enum tree_code representation.  This function is the
    2766                 :            :    inverse of comparison_to_compcode.  */
    2767                 :            : 
    2768                 :            : static enum tree_code
    2769                 :       6948 : compcode_to_comparison (enum comparison_code code)
    2770                 :            : {
    2771                 :          0 :   switch (code)
    2772                 :            :     {
    2773                 :            :     case COMPCODE_LT:
    2774                 :            :       return LT_EXPR;
    2775                 :            :     case COMPCODE_EQ:
    2776                 :            :       return EQ_EXPR;
    2777                 :            :     case COMPCODE_LE:
    2778                 :            :       return LE_EXPR;
    2779                 :            :     case COMPCODE_GT:
    2780                 :            :       return GT_EXPR;
    2781                 :            :     case COMPCODE_NE:
    2782                 :            :       return NE_EXPR;
    2783                 :            :     case COMPCODE_GE:
    2784                 :            :       return GE_EXPR;
    2785                 :            :     case COMPCODE_ORD:
    2786                 :            :       return ORDERED_EXPR;
    2787                 :            :     case COMPCODE_UNORD:
    2788                 :            :       return UNORDERED_EXPR;
    2789                 :            :     case COMPCODE_UNLT:
    2790                 :            :       return UNLT_EXPR;
    2791                 :            :     case COMPCODE_UNEQ:
    2792                 :            :       return UNEQ_EXPR;
    2793                 :            :     case COMPCODE_UNLE:
    2794                 :            :       return UNLE_EXPR;
    2795                 :            :     case COMPCODE_UNGT:
    2796                 :            :       return UNGT_EXPR;
    2797                 :            :     case COMPCODE_LTGT:
    2798                 :            :       return LTGT_EXPR;
    2799                 :            :     case COMPCODE_UNGE:
    2800                 :            :       return UNGE_EXPR;
    2801                 :          0 :     default:
    2802                 :          0 :       gcc_unreachable ();
    2803                 :            :     }
    2804                 :            : }
    2805                 :            : 
    2806                 :            : /* Return true if COND1 tests the opposite condition of COND2.  */
    2807                 :            : 
    2808                 :            : bool
    2809                 :      67422 : inverse_conditions_p (const_tree cond1, const_tree cond2)
    2810                 :            : {
    2811                 :      67422 :   return (COMPARISON_CLASS_P (cond1)
    2812                 :      47259 :           && COMPARISON_CLASS_P (cond2)
    2813                 :      45337 :           && (invert_tree_comparison
    2814                 :      45337 :               (TREE_CODE (cond1),
    2815                 :      90674 :                HONOR_NANS (TREE_OPERAND (cond1, 0))) == TREE_CODE (cond2))
    2816                 :       3547 :           && operand_equal_p (TREE_OPERAND (cond1, 0),
    2817                 :       3547 :                               TREE_OPERAND (cond2, 0), 0)
    2818                 :      68878 :           && operand_equal_p (TREE_OPERAND (cond1, 1),
    2819                 :       1456 :                               TREE_OPERAND (cond2, 1), 0));
    2820                 :            : }
    2821                 :            : 
    2822                 :            : /* Return a tree for the comparison which is the combination of
    2823                 :            :    doing the AND or OR (depending on CODE) of the two operations LCODE
    2824                 :            :    and RCODE on the identical operands LL_ARG and LR_ARG.  Take into account
    2825                 :            :    the possibility of trapping if the mode has NaNs, and return NULL_TREE
    2826                 :            :    if this makes the transformation invalid.  */
    2827                 :            : 
    2828                 :            : tree
    2829                 :       7997 : combine_comparisons (location_t loc,
    2830                 :            :                      enum tree_code code, enum tree_code lcode,
    2831                 :            :                      enum tree_code rcode, tree truth_type,
    2832                 :            :                      tree ll_arg, tree lr_arg)
    2833                 :            : {
    2834                 :       7997 :   bool honor_nans = HONOR_NANS (ll_arg);
    2835                 :       7997 :   enum comparison_code lcompcode = comparison_to_compcode (lcode);
    2836                 :       7997 :   enum comparison_code rcompcode = comparison_to_compcode (rcode);
    2837                 :       7997 :   int compcode;
    2838                 :            : 
    2839                 :       7997 :   switch (code)
    2840                 :            :     {
    2841                 :       4017 :     case TRUTH_AND_EXPR: case TRUTH_ANDIF_EXPR:
    2842                 :       4017 :       compcode = lcompcode & rcompcode;
    2843                 :       4017 :       break;
    2844                 :            : 
    2845                 :       3980 :     case TRUTH_OR_EXPR: case TRUTH_ORIF_EXPR:
    2846                 :       3980 :       compcode = lcompcode | rcompcode;
    2847                 :       3980 :       break;
    2848                 :            : 
    2849                 :            :     default:
    2850                 :            :       return NULL_TREE;
    2851                 :            :     }
    2852                 :            : 
    2853                 :       7997 :   if (!honor_nans)
    2854                 :            :     {
    2855                 :            :       /* Eliminate unordered comparisons, as well as LTGT and ORD
    2856                 :            :          which are not used unless the mode has NaNs.  */
    2857                 :       5731 :       compcode &= ~COMPCODE_UNORD;
    2858                 :       5731 :       if (compcode == COMPCODE_LTGT)
    2859                 :            :         compcode = COMPCODE_NE;
    2860                 :       5421 :       else if (compcode == COMPCODE_ORD)
    2861                 :            :         compcode = COMPCODE_TRUE;
    2862                 :            :     }
    2863                 :       2266 :    else if (flag_trapping_math)
    2864                 :            :      {
    2865                 :            :         /* Check that the original operation and the optimized ones will trap
    2866                 :            :            under the same condition.  */
    2867                 :       2648 :         bool ltrap = (lcompcode & COMPCODE_UNORD) == 0
    2868                 :        648 :                      && (lcompcode != COMPCODE_EQ)
    2869                 :       1324 :                      && (lcompcode != COMPCODE_ORD);
    2870                 :       2648 :         bool rtrap = (rcompcode & COMPCODE_UNORD) == 0
    2871                 :        840 :                      && (rcompcode != COMPCODE_EQ)
    2872                 :       1324 :                      && (rcompcode != COMPCODE_ORD);
    2873                 :       2648 :         bool trap = (compcode & COMPCODE_UNORD) == 0
    2874                 :        942 :                     && (compcode != COMPCODE_EQ)
    2875                 :       1324 :                     && (compcode != COMPCODE_ORD);
    2876                 :            : 
    2877                 :            :         /* In a short-circuited boolean expression the LHS might be
    2878                 :            :            such that the RHS, if evaluated, will never trap.  For
    2879                 :            :            example, in ORD (x, y) && (x < y), we evaluate the RHS only
    2880                 :            :            if neither x nor y is NaN.  (This is a mixed blessing: for
    2881                 :            :            example, the expression above will never trap, hence
    2882                 :            :            optimizing it to x < y would be invalid).  */
    2883                 :       1324 :         if ((code == TRUTH_ORIF_EXPR && (lcompcode & COMPCODE_UNORD))
    2884                 :        964 :             || (code == TRUTH_ANDIF_EXPR && !(lcompcode & COMPCODE_UNORD)))
    2885                 :        784 :           rtrap = false;
    2886                 :            : 
    2887                 :            :         /* If the comparison was short-circuited, and only the RHS
    2888                 :            :            trapped, we may now generate a spurious trap.  */
    2889                 :       1324 :         if (rtrap && !ltrap
    2890                 :        112 :             && (code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR))
    2891                 :            :           return NULL_TREE;
    2892                 :            : 
    2893                 :            :         /* If we changed the conditions that cause a trap, we lose.  */
    2894                 :       1212 :         if ((ltrap || rtrap) != trap)
    2895                 :            :           return NULL_TREE;
    2896                 :            :       }
    2897                 :            : 
    2898                 :       6868 :   if (compcode == COMPCODE_TRUE)
    2899                 :        123 :     return constant_boolean_node (true, truth_type);
    2900                 :       7150 :   else if (compcode == COMPCODE_FALSE)
    2901                 :        202 :     return constant_boolean_node (false, truth_type);
    2902                 :            :   else
    2903                 :            :     {
    2904                 :       6948 :       enum tree_code tcode;
    2905                 :            : 
    2906                 :       6948 :       tcode = compcode_to_comparison ((enum comparison_code) compcode);
    2907                 :       6948 :       return fold_build2_loc (loc, tcode, truth_type, ll_arg, lr_arg);
    2908                 :            :     }
    2909                 :            : }
    2910                 :            : 
    2911                 :            : /* Return nonzero if two operands (typically of the same tree node)
    2912                 :            :    are necessarily equal. FLAGS modifies behavior as follows:
    2913                 :            : 
    2914                 :            :    If OEP_ONLY_CONST is set, only return nonzero for constants.
    2915                 :            :    This function tests whether the operands are indistinguishable;
    2916                 :            :    it does not test whether they are equal using C's == operation.
    2917                 :            :    The distinction is important for IEEE floating point, because
    2918                 :            :    (1) -0.0 and 0.0 are distinguishable, but -0.0==0.0, and
    2919                 :            :    (2) two NaNs may be indistinguishable, but NaN!=NaN.
    2920                 :            : 
    2921                 :            :    If OEP_ONLY_CONST is unset, a VAR_DECL is considered equal to itself
    2922                 :            :    even though it may hold multiple values during a function.
    2923                 :            :    This is because a GCC tree node guarantees that nothing else is
    2924                 :            :    executed between the evaluation of its "operands" (which may often
    2925                 :            :    be evaluated in arbitrary order).  Hence if the operands themselves
    2926                 :            :    don't side-effect, the VAR_DECLs, PARM_DECLs etc... must hold the
    2927                 :            :    same value in each operand/subexpression.  Hence leaving OEP_ONLY_CONST
    2928                 :            :    unset means assuming isochronic (or instantaneous) tree equivalence.
    2929                 :            :    Unless comparing arbitrary expression trees, such as from different
    2930                 :            :    statements, this flag can usually be left unset.
    2931                 :            : 
    2932                 :            :    If OEP_PURE_SAME is set, then pure functions with identical arguments
    2933                 :            :    are considered the same.  It is used when the caller has other ways
    2934                 :            :    to ensure that global memory is unchanged in between.
    2935                 :            : 
    2936                 :            :    If OEP_ADDRESS_OF is set, we are actually comparing addresses of objects,
    2937                 :            :    not values of expressions.
    2938                 :            : 
    2939                 :            :    If OEP_LEXICOGRAPHIC is set, then also handle expressions with side-effects
    2940                 :            :    such as MODIFY_EXPR, RETURN_EXPR, as well as STATEMENT_LISTs.
    2941                 :            : 
    2942                 :            :    If OEP_BITWISE is set, then require the values to be bitwise identical
    2943                 :            :    rather than simply numerically equal.  Do not take advantage of things
    2944                 :            :    like math-related flags or undefined behavior; only return true for
    2945                 :            :    values that are provably bitwise identical in all circumstances.
    2946                 :            : 
    2947                 :            :    Unless OEP_MATCH_SIDE_EFFECTS is set, the function returns false on
    2948                 :            :    any operand with side effect.  This is unnecesarily conservative in the
    2949                 :            :    case we know that arg0 and arg1 are in disjoint code paths (such as in
    2950                 :            :    ?: operator).  In addition OEP_MATCH_SIDE_EFFECTS is used when comparing
    2951                 :            :    addresses with TREE_CONSTANT flag set so we know that &var == &var
    2952                 :            :    even if var is volatile.  */
    2953                 :            : 
    2954                 :            : bool
    2955                 : 4101840000 : operand_compare::operand_equal_p (const_tree arg0, const_tree arg1,
    2956                 :            :                                   unsigned int flags)
    2957                 :            : {
    2958                 : 4101840000 :   bool r;
    2959                 : 4101840000 :   if (verify_hash_value (arg0, arg1, flags, &r))
    2960                 : 1884000000 :     return r;
    2961                 :            : 
    2962                 : 2217840000 :   STRIP_ANY_LOCATION_WRAPPER (arg0);
    2963                 : 2217840000 :   STRIP_ANY_LOCATION_WRAPPER (arg1);
    2964                 :            : 
    2965                 :            :   /* If either is ERROR_MARK, they aren't equal.  */
    2966                 : 2217840000 :   if (TREE_CODE (arg0) == ERROR_MARK || TREE_CODE (arg1) == ERROR_MARK
    2967                 : 2217840000 :       || TREE_TYPE (arg0) == error_mark_node
    2968                 : 4435680000 :       || TREE_TYPE (arg1) == error_mark_node)
    2969                 :            :     return false;
    2970                 :            : 
    2971                 :            :   /* Similar, if either does not have a type (like a template id),
    2972                 :            :      they aren't equal.  */
    2973                 : 2217840000 :   if (!TREE_TYPE (arg0) || !TREE_TYPE (arg1))
    2974                 :            :     return false;
    2975                 :            : 
    2976                 :            :   /* Bitwise identity makes no sense if the values have different layouts.  */
    2977                 : 2217840000 :   if ((flags & OEP_BITWISE)
    2978                 : 2217840000 :       && !tree_nop_conversion_p (TREE_TYPE (arg0), TREE_TYPE (arg1)))
    2979                 :            :     return false;
    2980                 :            : 
    2981                 :            :   /* We cannot consider pointers to different address space equal.  */
    2982                 : 3931110000 :   if (POINTER_TYPE_P (TREE_TYPE (arg0))
    2983                 :  523990000 :       && POINTER_TYPE_P (TREE_TYPE (arg1))
    2984                 : 2683610000 :       && (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (arg0)))
    2985                 :  465772000 :           != TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (arg1)))))
    2986                 :            :     return false;
    2987                 :            : 
    2988                 :            :   /* Check equality of integer constants before bailing out due to
    2989                 :            :      precision differences.  */
    2990                 : 2217840000 :   if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
    2991                 :            :     {
    2992                 :            :       /* Address of INTEGER_CST is not defined; check that we did not forget
    2993                 :            :          to drop the OEP_ADDRESS_OF flags.  */
    2994                 :  685273000 :       gcc_checking_assert (!(flags & OEP_ADDRESS_OF));
    2995                 :  685273000 :       return tree_int_cst_equal (arg0, arg1);
    2996                 :            :     }
    2997                 :            : 
    2998                 : 1532570000 :   if (!(flags & OEP_ADDRESS_OF))
    2999                 :            :     {
    3000                 :            :       /* If both types don't have the same signedness, then we can't consider
    3001                 :            :          them equal.  We must check this before the STRIP_NOPS calls
    3002                 :            :          because they may change the signedness of the arguments.  As pointers
    3003                 :            :          strictly don't have a signedness, require either two pointers or
    3004                 :            :          two non-pointers as well.  */
    3005                 : 1248290000 :       if (TYPE_UNSIGNED (TREE_TYPE (arg0)) != TYPE_UNSIGNED (TREE_TYPE (arg1))
    3006                 : 2071760000 :           || POINTER_TYPE_P (TREE_TYPE (arg0))
    3007                 : 1104860000 :                              != POINTER_TYPE_P (TREE_TYPE (arg1)))
    3008                 :            :         return false;
    3009                 :            : 
    3010                 :            :       /* If both types don't have the same precision, then it is not safe
    3011                 :            :          to strip NOPs.  */
    3012                 : 2175280000 :       if (element_precision (TREE_TYPE (arg0))
    3013                 : 1087640000 :           != element_precision (TREE_TYPE (arg1)))
    3014                 :            :         return false;
    3015                 :            : 
    3016                 : 1011290000 :       STRIP_NOPS (arg0);
    3017                 : 1011290000 :       STRIP_NOPS (arg1);
    3018                 :            :     }
    3019                 :            : #if 0
    3020                 :            :   /* FIXME: Fortran FE currently produce ADDR_EXPR of NOP_EXPR. Enable the
    3021                 :            :      sanity check once the issue is solved.  */
    3022                 :            :   else
    3023                 :            :     /* Addresses of conversions and SSA_NAMEs (and many other things)
    3024                 :            :        are not defined.  Check that we did not forget to drop the
    3025                 :            :        OEP_ADDRESS_OF/OEP_CONSTANT_ADDRESS_OF flags.  */
    3026                 :            :     gcc_checking_assert (!CONVERT_EXPR_P (arg0) && !CONVERT_EXPR_P (arg1)
    3027                 :            :                          && TREE_CODE (arg0) != SSA_NAME);
    3028                 :            : #endif
    3029                 :            : 
    3030                 :            :   /* In case both args are comparisons but with different comparison
    3031                 :            :      code, try to swap the comparison operands of one arg to produce
    3032                 :            :      a match and compare that variant.  */
    3033                 : 1295570000 :   if (TREE_CODE (arg0) != TREE_CODE (arg1)
    3034                 :  528340000 :       && COMPARISON_CLASS_P (arg0)
    3035                 :    2375070 :       && COMPARISON_CLASS_P (arg1))
    3036                 :            :     {
    3037                 :    1755000 :       enum tree_code swap_code = swap_tree_comparison (TREE_CODE (arg1));
    3038                 :            : 
    3039                 :    1755000 :       if (TREE_CODE (arg0) == swap_code)
    3040                 :     661135 :         return operand_equal_p (TREE_OPERAND (arg0, 0),
    3041                 :     661135 :                                 TREE_OPERAND (arg1, 1), flags)
    3042                 :     674307 :                && operand_equal_p (TREE_OPERAND (arg0, 1),
    3043                 :      13172 :                                    TREE_OPERAND (arg1, 0), flags);
    3044                 :            :     }
    3045                 :            : 
    3046                 : 1294910000 :   if (TREE_CODE (arg0) != TREE_CODE (arg1))
    3047                 :            :     {
    3048                 :            :       /* NOP_EXPR and CONVERT_EXPR are considered equal.  */
    3049                 :  527679000 :       if (CONVERT_EXPR_P (arg0) && CONVERT_EXPR_P (arg1))
    3050                 :            :         ;
    3051                 :  527675000 :       else if (flags & OEP_ADDRESS_OF)
    3052                 :            :         {
    3053                 :            :           /* If we are interested in comparing addresses ignore
    3054                 :            :              MEM_REF wrappings of the base that can appear just for
    3055                 :            :              TBAA reasons.  */
    3056                 :   17071100 :           if (TREE_CODE (arg0) == MEM_REF
    3057                 :    1700240 :               && DECL_P (arg1)
    3058                 :    1517880 :               && TREE_CODE (TREE_OPERAND (arg0, 0)) == ADDR_EXPR
    3059                 :     303411 :               && TREE_OPERAND (TREE_OPERAND (arg0, 0), 0) == arg1
    3060                 :   17341300 :               && integer_zerop (TREE_OPERAND (arg0, 1)))
    3061                 :            :             return true;
    3062                 :   17003700 :           else if (TREE_CODE (arg1) == MEM_REF
    3063                 :   13496900 :                    && DECL_P (arg0)
    3064                 :    3914570 :                    && TREE_CODE (TREE_OPERAND (arg1, 0)) == ADDR_EXPR
    3065                 :     382082 :                    && TREE_OPERAND (TREE_OPERAND (arg1, 0), 0) == arg0
    3066                 :   17269700 :                    && integer_zerop (TREE_OPERAND (arg1, 1)))
    3067                 :            :             return true;
    3068                 :   16939300 :           return false;
    3069                 :            :         }
    3070                 :            :       else
    3071                 :            :         return false;
    3072                 :            :     }
    3073                 :            : 
    3074                 :            :   /* When not checking adddresses, this is needed for conversions and for
    3075                 :            :      COMPONENT_REF.  Might as well play it safe and always test this.  */
    3076                 :  767233000 :   if (TREE_CODE (TREE_TYPE (arg0)) == ERROR_MARK
    3077                 :  767233000 :       || TREE_CODE (TREE_TYPE (arg1)) == ERROR_MARK
    3078                 : 2301700000 :       || (TYPE_MODE (TREE_TYPE (arg0)) != TYPE_MODE (TREE_TYPE (arg1))
    3079                 :    7474250 :           && !(flags & OEP_ADDRESS_OF)))
    3080                 :    1799130 :     return false;
    3081                 :            : 
    3082                 :            :   /* If ARG0 and ARG1 are the same SAVE_EXPR, they are necessarily equal.
    3083                 :            :      We don't care about side effects in that case because the SAVE_EXPR
    3084                 :            :      takes care of that for us. In all other cases, two expressions are
    3085                 :            :      equal if they have no side effects.  If we have two identical
    3086                 :            :      expressions with side effects that should be treated the same due
    3087                 :            :      to the only side effects being identical SAVE_EXPR's, that will
    3088                 :            :      be detected in the recursive calls below.
    3089                 :            :      If we are taking an invariant address of two identical objects
    3090                 :            :      they are necessarily equal as well.  */
    3091                 :  266973000 :   if (arg0 == arg1 && ! (flags & OEP_ONLY_CONST)
    3092                 : 1032410000 :       && (TREE_CODE (arg0) == SAVE_EXPR
    3093                 :  266969000 :           || (flags & OEP_MATCH_SIDE_EFFECTS)
    3094                 :  436208000 :           || (! TREE_SIDE_EFFECTS (arg0) && ! TREE_SIDE_EFFECTS (arg1))))
    3095                 :            :     return true;
    3096                 :            : 
    3097                 :            :   /* Next handle constant cases, those for which we can return 1 even
    3098                 :            :      if ONLY_CONST is set.  */
    3099                 :  519280000 :   if (TREE_CONSTANT (arg0) && TREE_CONSTANT (arg1))
    3100                 :   20236700 :     switch (TREE_CODE (arg0))
    3101                 :            :       {
    3102                 :          6 :       case INTEGER_CST:
    3103                 :          6 :         return tree_int_cst_equal (arg0, arg1);
    3104                 :            : 
    3105                 :          0 :       case FIXED_CST:
    3106                 :          0 :         return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (arg0),
    3107                 :            :                                        TREE_FIXED_CST (arg1));
    3108                 :            : 
    3109                 :     939594 :       case REAL_CST:
    3110                 :     939594 :         if (real_identical (&TREE_REAL_CST (arg0), &TREE_REAL_CST (arg1)))
    3111                 :            :           return true;
    3112                 :            : 
    3113                 :     422954 :         if (!(flags & OEP_BITWISE) && !HONOR_SIGNED_ZEROS (arg0))
    3114                 :            :           {
    3115                 :            :             /* If we do not distinguish between signed and unsigned zero,
    3116                 :            :                consider them equal.  */
    3117                 :       4122 :             if (real_zerop (arg0) && real_zerop (arg1))
    3118                 :            :               return true;
    3119                 :            :           }
    3120                 :     422950 :         return false;
    3121                 :            : 
    3122                 :     208874 :       case VECTOR_CST:
    3123                 :     208874 :         {
    3124                 :     208874 :           if (VECTOR_CST_LOG2_NPATTERNS (arg0)
    3125                 :     208874 :               != VECTOR_CST_LOG2_NPATTERNS (arg1))
    3126                 :            :             return false;
    3127                 :            : 
    3128                 :     204184 :           if (VECTOR_CST_NELTS_PER_PATTERN (arg0)
    3129                 :     204184 :               != VECTOR_CST_NELTS_PER_PATTERN (arg1))
    3130                 :            :             return false;
    3131                 :            : 
    3132                 :     193550 :           unsigned int count = vector_cst_encoded_nelts (arg0);
    3133                 :     233404 :           for (unsigned int i = 0; i < count; ++i)
    3134                 :     225635 :             if (!operand_equal_p (VECTOR_CST_ENCODED_ELT (arg0, i),
    3135                 :     225635 :                                   VECTOR_CST_ENCODED_ELT (arg1, i), flags))
    3136                 :            :               return false;
    3137                 :            :           return true;
    3138                 :            :         }
    3139                 :            : 
    3140                 :       8393 :       case COMPLEX_CST:
    3141                 :       8393 :         return (operand_equal_p (TREE_REALPART (arg0), TREE_REALPART (arg1),
    3142                 :       8393 :                                  flags)
    3143                 :      11986 :                 && operand_equal_p (TREE_IMAGPART (arg0), TREE_IMAGPART (arg1),
    3144                 :       3593 :                                     flags));
    3145                 :            : 
    3146                 :    1570390 :       case STRING_CST:
    3147                 :    1570390 :         return (TREE_STRING_LENGTH (arg0) == TREE_STRING_LENGTH (arg1)
    3148                 :    1570390 :                 && ! memcmp (TREE_STRING_POINTER (arg0),
    3149                 :     991314 :                               TREE_STRING_POINTER (arg1),
    3150                 :     991314 :                               TREE_STRING_LENGTH (arg0)));
    3151                 :            : 
    3152                 :   10191500 :       case ADDR_EXPR:
    3153                 :   10191500 :         gcc_checking_assert (!(flags & OEP_ADDRESS_OF));
    3154                 :   10191500 :         return operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1, 0),
    3155                 :            :                                 flags | OEP_ADDRESS_OF
    3156                 :   10191500 :                                 | OEP_MATCH_SIDE_EFFECTS);
    3157                 :     409009 :       case CONSTRUCTOR:
    3158                 :            :         /* In GIMPLE empty constructors are allowed in initializers of
    3159                 :            :            aggregates.  */
    3160                 :     409009 :         return !CONSTRUCTOR_NELTS (arg0) && !CONSTRUCTOR_NELTS (arg1);
    3161                 :            :       default:
    3162                 :            :         break;
    3163                 :            :       }
    3164                 :            : 
    3165                 :            :   /* Don't handle more cases for OEP_BITWISE, since we can't guarantee that
    3166                 :            :      two instances of undefined behavior will give identical results.  */
    3167                 :  485384000 :   if (flags & (OEP_ONLY_CONST | OEP_BITWISE))
    3168                 :            :     return false;
    3169                 :            : 
    3170                 :            : /* Define macros to test an operand from arg0 and arg1 for equality and a
    3171                 :            :    variant that allows null and views null as being different from any
    3172                 :            :    non-null value.  In the latter case, if either is null, the both
    3173                 :            :    must be; otherwise, do the normal comparison.  */
    3174                 :            : #define OP_SAME(N) operand_equal_p (TREE_OPERAND (arg0, N),     \
    3175                 :            :                                     TREE_OPERAND (arg1, N), flags)
    3176                 :            : 
    3177                 :            : #define OP_SAME_WITH_NULL(N)                            \
    3178                 :            :   ((!TREE_OPERAND (arg0, N) || !TREE_OPERAND (arg1, N)) \
    3179                 :            :    ? TREE_OPERAND (arg0, N) == TREE_OPERAND (arg1, N) : OP_SAME (N))
    3180                 :            : 
    3181                 :  485384000 :   switch (TREE_CODE_CLASS (TREE_CODE (arg0)))
    3182                 :            :     {
    3183                 :    3414240 :     case tcc_unary:
    3184                 :            :       /* Two conversions are equal only if signedness and modes match.  */
    3185                 :    3414240 :       switch (TREE_CODE (arg0))
    3186                 :            :         {
    3187                 :    3364790 :         CASE_CONVERT:
    3188                 :    3364790 :         case FIX_TRUNC_EXPR:
    3189                 :    3364790 :           if (TYPE_UNSIGNED (TREE_TYPE (arg0))
    3190                 :    3364790 :               != TYPE_UNSIGNED (TREE_TYPE (arg1)))
    3191                 :            :             return false;
    3192                 :            :           break;
    3193                 :            :         default:
    3194                 :            :           break;
    3195                 :            :         }
    3196                 :            : 
    3197                 :    3414220 :       return OP_SAME (0);
    3198                 :            : 
    3199                 :            : 
    3200                 :    9990090 :     case tcc_comparison:
    3201                 :    9990090 :     case tcc_binary:
    3202                 :    9990090 :       if (OP_SAME (0) && OP_SAME (1))
    3203                 :            :         return true;
    3204                 :            : 
    3205                 :            :       /* For commutative ops, allow the other order.  */
    3206                 :    6328990 :       return (commutative_tree_code (TREE_CODE (arg0))
    3207                 :    4779210 :               && operand_equal_p (TREE_OPERAND (arg0, 0),
    3208                 :    4779210 :                                   TREE_OPERAND (arg1, 1), flags)
    3209                 :    6421720 :               && operand_equal_p (TREE_OPERAND (arg0, 1),
    3210                 :      92734 :                                   TREE_OPERAND (arg1, 0), flags));
    3211                 :            : 
    3212                 :  152149000 :     case tcc_reference:
    3213                 :            :       /* If either of the pointer (or reference) expressions we are
    3214                 :            :          dereferencing contain a side effect, these cannot be equal,
    3215                 :            :          but their addresses can be.  */
    3216                 :  152149000 :       if ((flags & OEP_MATCH_SIDE_EFFECTS) == 0
    3217                 :  152149000 :           && (TREE_SIDE_EFFECTS (arg0)
    3218                 :  170821000 :               || TREE_SIDE_EFFECTS (arg1)))
    3219                 :            :         return false;
    3220                 :            : 
    3221                 :  147085000 :       switch (TREE_CODE (arg0))
    3222                 :            :         {
    3223                 :     778434 :         case INDIRECT_REF:
    3224                 :     778434 :           if (!(flags & OEP_ADDRESS_OF))
    3225                 :            :             {
    3226                 :    1552110 :               if (TYPE_ALIGN (TREE_TYPE (arg0))
    3227                 :     776054 :                   != TYPE_ALIGN (TREE_TYPE (arg1)))
    3228                 :            :                 return false;
    3229                 :            :               /* Verify that the access types are compatible.  */
    3230                 :     775459 :               if (TYPE_MAIN_VARIANT (TREE_TYPE (arg0))
    3231                 :     775459 :                   != TYPE_MAIN_VARIANT (TREE_TYPE (arg1)))
    3232                 :            :                 return false;
    3233                 :            :             }
    3234                 :     748561 :           flags &= ~OEP_ADDRESS_OF;
    3235                 :     748561 :           return OP_SAME (0);
    3236                 :            : 
    3237                 :     344900 :         case IMAGPART_EXPR:
    3238                 :            :           /* Require the same offset.  */
    3239                 :     344900 :           if (!operand_equal_p (TYPE_SIZE (TREE_TYPE (arg0)),
    3240                 :     344900 :                                 TYPE_SIZE (TREE_TYPE (arg1)),
    3241                 :     344900 :                                 flags & ~OEP_ADDRESS_OF))
    3242                 :            :             return false;
    3243                 :            : 
    3244                 :            :         /* Fallthru.  */
    3245                 :    1066630 :         case REALPART_EXPR:
    3246                 :    1066630 :         case VIEW_CONVERT_EXPR:
    3247                 :    1066630 :           return OP_SAME (0);
    3248                 :            : 
    3249                 :   67084700 :         case TARGET_MEM_REF:
    3250                 :   67084700 :         case MEM_REF:
    3251                 :   67084700 :           if (!(flags & OEP_ADDRESS_OF))
    3252                 :            :             {
    3253                 :            :               /* Require equal access sizes */
    3254                 :   10284400 :               if (TYPE_SIZE (TREE_TYPE (arg0)) != TYPE_SIZE (TREE_TYPE (arg1))
    3255                 :   10284400 :                   && (!TYPE_SIZE (TREE_TYPE (arg0))
    3256                 :     871897 :                       || !TYPE_SIZE (TREE_TYPE (arg1))
    3257                 :     868611 :                       || !operand_equal_p (TYPE_SIZE (TREE_TYPE (arg0)),
    3258                 :     868611 :                                            TYPE_SIZE (TREE_TYPE (arg1)),
    3259                 :     868611 :                                            flags)))
    3260                 :     876032 :                 return false;
    3261                 :            :               /* Verify that access happens in similar types.  */
    3262                 :    9408380 :               if (!types_compatible_p (TREE_TYPE (arg0), TREE_TYPE (arg1)))
    3263                 :            :                 return false;
    3264                 :            :               /* Verify that accesses are TBAA compatible.  */
    3265                 :    9137990 :               if (!alias_ptr_types_compatible_p
    3266                 :    9137990 :                     (TREE_TYPE (TREE_OPERAND (arg0, 1)),
    3267                 :    9137990 :                      TREE_TYPE (TREE_OPERAND (arg1, 1)))
    3268                 :    7902160 :                   || (MR_DEPENDENCE_CLIQUE (arg0)
    3269                 :    7902160 :                       != MR_DEPENDENCE_CLIQUE (arg1))
    3270                 :   16297700 :                   || (MR_DEPENDENCE_BASE (arg0)
    3271                 :    7159670 :                       != MR_DEPENDENCE_BASE (arg1)))
    3272                 :            :                 return false;
    3273                 :            :              /* Verify that alignment is compatible.  */
    3274                 :   14017200 :              if (TYPE_ALIGN (TREE_TYPE (arg0))
    3275                 :    7008620 :                  != TYPE_ALIGN (TREE_TYPE (arg1)))
    3276                 :            :                 return false;
    3277                 :            :             }
    3278                 :   63782800 :           flags &= ~OEP_ADDRESS_OF;
    3279                 :  120343000 :           return (OP_SAME (0) && OP_SAME (1)
    3280                 :            :                   /* TARGET_MEM_REF require equal extra operands.  */
    3281                 :   77072900 :                   && (TREE_CODE (arg0) != TARGET_MEM_REF
    3282                 :     269031 :                       || (OP_SAME_WITH_NULL (2)
    3283                 :     206383 :                           && OP_SAME_WITH_NULL (3)
    3284                 :     205987 :                           && OP_SAME_WITH_NULL (4))));
    3285                 :            : 
    3286                 :   20914500 :         case ARRAY_REF:
    3287                 :   20914500 :         case ARRAY_RANGE_REF:
    3288                 :   20914500 :           if (!OP_SAME (0))
    3289                 :            :             return false;
    3290                 :   18750100 :           flags &= ~OEP_ADDRESS_OF;
    3291                 :            :           /* Compare the array index by value if it is constant first as we
    3292                 :            :              may have different types but same value here.  */
    3293                 :   18750100 :           return ((tree_int_cst_equal (TREE_OPERAND (arg0, 1),
    3294                 :   18750100 :                                        TREE_OPERAND (arg1, 1))
    3295                 :   17149900 :                    || OP_SAME (1))
    3296                 :    3221210 :                   && OP_SAME_WITH_NULL (2)
    3297                 :    3221210 :                   && OP_SAME_WITH_NULL (3)
    3298                 :            :                   /* Compare low bound and element size as with OEP_ADDRESS_OF
    3299                 :            :                      we have to account for the offset of the ref.  */
    3300                 :   23581900 :                   && (TREE_TYPE (TREE_OPERAND (arg0, 0))
    3301                 :    1610600 :                       == TREE_TYPE (TREE_OPERAND (arg1, 0))
    3302                 :        765 :                       || (operand_equal_p (array_ref_low_bound
    3303                 :        765 :                                              (CONST_CAST_TREE (arg0)),
    3304                 :            :                                            array_ref_low_bound
    3305                 :        765 :                                              (CONST_CAST_TREE (arg1)), flags)
    3306                 :        765 :                           && operand_equal_p (array_ref_element_size
    3307                 :        765 :                                                 (CONST_CAST_TREE (arg0)),
    3308                 :            :                                               array_ref_element_size
    3309                 :        765 :                                                 (CONST_CAST_TREE (arg1)),
    3310                 :        765 :                                               flags))));
    3311                 :            : 
    3312                 :   57056500 :         case COMPONENT_REF:
    3313                 :            :           /* Handle operand 2 the same as for ARRAY_REF.  Operand 0
    3314                 :            :              may be NULL when we're called to compare MEM_EXPRs.  */
    3315                 :  114113000 :           if (!OP_SAME_WITH_NULL (0)
    3316                 :   92439800 :               || !OP_SAME (1))
    3317                 :   42384800 :             return false;
    3318                 :   14671700 :           flags &= ~OEP_ADDRESS_OF;
    3319                 :   14671700 :           return OP_SAME_WITH_NULL (2);
    3320                 :            : 
    3321                 :     183967 :         case BIT_FIELD_REF:
    3322                 :     183967 :           if (!OP_SAME (0))
    3323                 :            :             return false;
    3324                 :     175840 :           flags &= ~OEP_ADDRESS_OF;
    3325                 :     175840 :           return OP_SAME (1) && OP_SAME (2);
    3326                 :            : 
    3327                 :            :         /* Virtual table call.  */
    3328                 :          0 :         case OBJ_TYPE_REF:
    3329                 :          0 :           {
    3330                 :          0 :             if (!operand_equal_p (OBJ_TYPE_REF_EXPR (arg0),
    3331                 :          0 :                                   OBJ_TYPE_REF_EXPR (arg1), flags))
    3332                 :            :               return false;
    3333                 :          0 :             if (tree_to_uhwi (OBJ_TYPE_REF_TOKEN (arg0))
    3334                 :          0 :                 != tree_to_uhwi (OBJ_TYPE_REF_TOKEN (arg1)))
    3335                 :            :               return false;
    3336                 :          0 :             if (!operand_equal_p (OBJ_TYPE_REF_OBJECT (arg0),
    3337                 :          0 :                                   OBJ_TYPE_REF_OBJECT (arg1), flags))
    3338                 :            :               return false;
    3339                 :          0 :             if (!types_same_for_odr (obj_type_ref_class (arg0),
    3340                 :          0 :                                      obj_type_ref_class (arg1)))
    3341                 :          0 :               return false;
    3342                 :            :             return true;
    3343                 :            :           }
    3344                 :            : 
    3345                 :            :         default:
    3346                 :            :           return false;
    3347                 :            :         }
    3348                 :            : 
    3349                 :   45170000 :     case tcc_expression:
    3350                 :   45170000 :       switch (TREE_CODE (arg0))
    3351                 :            :         {
    3352                 :   45076500 :         case ADDR_EXPR:
    3353                 :            :           /* Be sure we pass right ADDRESS_OF flag.  */
    3354                 :   45076500 :           gcc_checking_assert (!(flags & OEP_ADDRESS_OF));
    3355                 :   45076500 :           return operand_equal_p (TREE_OPERAND (arg0, 0),
    3356                 :   45076500 :                                   TREE_OPERAND (arg1, 0),
    3357                 :   45076500 :                                   flags | OEP_ADDRESS_OF);
    3358                 :            : 
    3359                 :       6888 :         case TRUTH_NOT_EXPR:
    3360                 :       6888 :           return OP_SAME (0);
    3361                 :            : 
    3362                 :       4157 :         case TRUTH_ANDIF_EXPR:
    3363                 :       4157 :         case TRUTH_ORIF_EXPR:
    3364                 :       4157 :           return OP_SAME (0) && OP_SAME (1);
    3365                 :            : 
    3366                 :          0 :         case WIDEN_MULT_PLUS_EXPR:
    3367                 :          0 :         case WIDEN_MULT_MINUS_EXPR:
    3368                 :          0 :           if (!OP_SAME (2))
    3369                 :            :             return false;
    3370                 :            :           /* The multiplcation operands are commutative.  */
    3371                 :            :           /* FALLTHRU */
    3372                 :            : 
    3373                 :       7155 :         case TRUTH_AND_EXPR:
    3374                 :       7155 :         case TRUTH_OR_EXPR:
    3375                 :       7155 :         case TRUTH_XOR_EXPR:
    3376                 :       7155 :           if (OP_SAME (0) && OP_SAME (1))
    3377                 :            :             return true;
    3378                 :            : 
    3379                 :            :           /* Otherwise take into account this is a commutative operation.  */
    3380                 :       7137 :           return (operand_equal_p (TREE_OPERAND (arg0, 0),
    3381                 :       7137 :                                    TREE_OPERAND (arg1, 1), flags)
    3382                 :       7138 :                   && operand_equal_p (TREE_OPERAND (arg0, 1),
    3383                 :          1 :                                       TREE_OPERAND (arg1, 0), flags));
    3384                 :            : 
    3385                 :       3921 :         case COND_EXPR:
    3386                 :       3921 :           if (! OP_SAME (1) || ! OP_SAME_WITH_NULL (2))
    3387                 :       3119 :             return false;
    3388                 :        802 :           flags &= ~OEP_ADDRESS_OF;
    3389                 :        802 :           return OP_SAME (0);
    3390                 :            : 
    3391                 :          0 :         case BIT_INSERT_EXPR:
    3392                 :            :           /* BIT_INSERT_EXPR has an implict operand as the type precision
    3393                 :            :              of op1.  Need to check to make sure they are the same.  */
    3394                 :          0 :           if (TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
    3395                 :          0 :               && TREE_CODE (TREE_OPERAND (arg1, 1)) == INTEGER_CST
    3396                 :          0 :               && TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 1)))
    3397                 :          0 :                  != TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg1, 1))))
    3398                 :            :             return false;
    3399                 :            :           /* FALLTHRU */
    3400                 :            : 
    3401                 :         45 :         case VEC_COND_EXPR:
    3402                 :         45 :         case DOT_PROD_EXPR:
    3403                 :         45 :           return OP_SAME (0) && OP_SAME (1) && OP_SAME (2);
    3404                 :            : 
    3405                 :      11150 :         case MODIFY_EXPR:
    3406                 :      11150 :         case INIT_EXPR:
    3407                 :      11150 :         case COMPOUND_EXPR:
    3408                 :      11150 :         case PREDECREMENT_EXPR:
    3409                 :      11150 :         case PREINCREMENT_EXPR:
    3410                 :      11150 :         case POSTDECREMENT_EXPR:
    3411                 :      11150 :         case POSTINCREMENT_EXPR:
    3412                 :      11150 :           if (flags & OEP_LEXICOGRAPHIC)
    3413                 :        199 :             return OP_SAME (0) && OP_SAME (1);
    3414                 :            :           return false;
    3415                 :            : 
    3416                 :      20193 :         case CLEANUP_POINT_EXPR:
    3417                 :      20193 :         case EXPR_STMT:
    3418                 :      20193 :         case SAVE_EXPR:
    3419                 :      20193 :           if (flags & OEP_LEXICOGRAPHIC)
    3420                 :        267 :             return OP_SAME (0);
    3421                 :            :           return false;
    3422                 :            : 
    3423                 :            :         default:
    3424                 :            :           return false;
    3425                 :            :         }
    3426                 :            : 
    3427                 :     242672 :     case tcc_vl_exp:
    3428                 :     242672 :       switch (TREE_CODE (arg0))
    3429                 :            :         {
    3430                 :     242672 :         case CALL_EXPR:
    3431                 :     242672 :           if ((CALL_EXPR_FN (arg0) == NULL_TREE)
    3432                 :     242672 :               != (CALL_EXPR_FN (arg1) == NULL_TREE))
    3433                 :            :             /* If not both CALL_EXPRs are either internal or normal function
    3434                 :            :                functions, then they are not equal.  */
    3435                 :            :             return false;
    3436                 :     242672 :           else if (CALL_EXPR_FN (arg0) == NULL_TREE)
    3437                 :            :             {
    3438                 :            :               /* If the CALL_EXPRs call different internal functions, then they
    3439                 :            :                  are not equal.  */
    3440                 :       1117 :               if (CALL_EXPR_IFN (arg0) != CALL_EXPR_IFN (arg1))
    3441                 :            :                 return false;
    3442                 :            :             }
    3443                 :            :           else
    3444                 :            :             {
    3445                 :            :               /* If the CALL_EXPRs call different functions, then they are not
    3446                 :            :                  equal.  */
    3447                 :     241555 :               if (! operand_equal_p (CALL_EXPR_FN (arg0), CALL_EXPR_FN (arg1),
    3448                 :     241555 :                                      flags))
    3449                 :            :                 return false;
    3450                 :            :             }
    3451                 :            : 
    3452                 :            :           /* FIXME: We could skip this test for OEP_MATCH_SIDE_EFFECTS.  */
    3453                 :     116333 :           {
    3454                 :     116333 :             unsigned int cef = call_expr_flags (arg0);
    3455                 :     116333 :             if (flags & OEP_PURE_SAME)
    3456                 :          0 :               cef &= ECF_CONST | ECF_PURE;
    3457                 :            :             else
    3458                 :     116333 :               cef &= ECF_CONST;
    3459                 :     116333 :             if (!cef && !(flags & OEP_LEXICOGRAPHIC))
    3460                 :            :               return false;
    3461                 :            :           }
    3462                 :            : 
    3463                 :            :           /* Now see if all the arguments are the same.  */
    3464                 :      24841 :           {
    3465                 :      24841 :             const_call_expr_arg_iterator iter0, iter1;
    3466                 :      24841 :             const_tree a0, a1;
    3467                 :      49682 :             for (a0 = first_const_call_expr_arg (arg0, &iter0),
    3468                 :      24841 :                    a1 = first_const_call_expr_arg (arg1, &iter1);
    3469                 :      32597 :                  a0 && a1;
    3470                 :       7756 :                  a0 = next_const_call_expr_arg (&iter0),
    3471                 :       7756 :                    a1 = next_const_call_expr_arg (&iter1))
    3472                 :      26283 :               if (! operand_equal_p (a0, a1, flags))
    3473                 :            :                 return false;
    3474                 :            : 
    3475                 :            :             /* If we get here and both argument lists are exhausted
    3476                 :            :                then the CALL_EXPRs are equal.  */
    3477                 :       6314 :             return ! (a0 || a1);
    3478                 :            :           }
    3479                 :            :         default:
    3480                 :            :           return false;
    3481                 :            :         }
    3482                 :            : 
    3483                 :   70027700 :     case tcc_declaration:
    3484                 :            :       /* Consider __builtin_sqrt equal to sqrt.  */
    3485                 :   70027700 :       return (TREE_CODE (arg0) == FUNCTION_DECL
    3486                 :    3872040 :               && fndecl_built_in_p (arg0) && fndecl_built_in_p (arg1)
    3487                 :     157026 :               && DECL_BUILT_IN_CLASS (arg0) == DECL_BUILT_IN_CLASS (arg1)
    3488                 :   70027700 :               && (DECL_UNCHECKED_FUNCTION_CODE (arg0)
    3489                 :     157026 :                   == DECL_UNCHECKED_FUNCTION_CODE (arg1)));
    3490                 :            : 
    3491                 :  204139000 :     case tcc_exceptional:
    3492                 :  204139000 :       if (TREE_CODE (arg0) == CONSTRUCTOR)
    3493                 :            :         {
    3494                 :      14190 :           if (CONSTRUCTOR_NO_CLEARING (arg0) != CONSTRUCTOR_NO_CLEARING (arg1))
    3495                 :            :             return false;
    3496                 :            : 
    3497                 :            :           /* In GIMPLE constructors are used only to build vectors from
    3498                 :            :              elements.  Individual elements in the constructor must be
    3499                 :            :              indexed in increasing order and form an initial sequence.
    3500                 :            : 
    3501                 :            :              We make no effort to compare constructors in generic.
    3502                 :            :              (see sem_variable::equals in ipa-icf which can do so for
    3503                 :            :               constants).  */
    3504                 :      14190 :           if (!VECTOR_TYPE_P (TREE_TYPE (arg0))
    3505                 :      14648 :               || !VECTOR_TYPE_P (TREE_TYPE (arg1)))
    3506                 :            :             return false;
    3507                 :            : 
    3508                 :            :           /* Be sure that vectors constructed have the same representation.
    3509                 :            :              We only tested element precision and modes to match.
    3510                 :            :              Vectors may be BLKmode and thus also check that the number of
    3511                 :            :              parts match.  */
    3512                 :        916 :           if (maybe_ne (TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0)),
    3513                 :        916 :                         TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg1))))
    3514                 :            :             return false;
    3515                 :            : 
    3516                 :        458 :           vec<constructor_elt, va_gc> *v0 = CONSTRUCTOR_ELTS (arg0);
    3517                 :        458 :           vec<constructor_elt, va_gc> *v1 = CONSTRUCTOR_ELTS (arg1);
    3518                 :        458 :           unsigned int len = vec_safe_length (v0);
    3519                 :            : 
    3520                 :        916 :           if (len != vec_safe_length (v1))
    3521                 :            :             return false;
    3522                 :            : 
    3523                 :       2070 :           for (unsigned int i = 0; i < len; i++)
    3524                 :            :             {
    3525                 :       1718 :               constructor_elt *c0 = &(*v0)[i];
    3526                 :       1718 :               constructor_elt *c1 = &(*v1)[i];
    3527                 :            : 
    3528                 :       1718 :               if (!operand_equal_p (c0->value, c1->value, flags)
    3529                 :            :                   /* In GIMPLE the indexes can be either NULL or matching i.
    3530                 :            :                      Double check this so we won't get false
    3531                 :            :                      positives for GENERIC.  */
    3532                 :       1612 :                   || (c0->index
    3533                 :        912 :                       && (TREE_CODE (c0->index) != INTEGER_CST 
    3534                 :        912 :                           || compare_tree_int (c0->index, i)))
    3535                 :       3330 :                   || (c1->index
    3536                 :        912 :                       && (TREE_CODE (c1->index) != INTEGER_CST 
    3537                 :        912 :                           || compare_tree_int (c1->index, i))))
    3538                 :        106 :                 return false;
    3539                 :            :             }
    3540                 :            :           return true;
    3541                 :            :         }
    3542                 :  204125000 :       else if (TREE_CODE (arg0) == STATEMENT_LIST
    3543                 :       1568 :                && (flags & OEP_LEXICOGRAPHIC))
    3544                 :            :         {
    3545                 :            :           /* Compare the STATEMENT_LISTs.  */
    3546                 :         20 :           tree_stmt_iterator tsi1, tsi2;
    3547                 :         20 :           tree body1 = CONST_CAST_TREE (arg0);
    3548                 :         20 :           tree body2 = CONST_CAST_TREE (arg1);
    3549                 :         20 :           for (tsi1 = tsi_start (body1), tsi2 = tsi_start (body2); ;
    3550                 :         50 :                tsi_next (&tsi1), tsi_next (&tsi2))
    3551                 :            :             {
    3552                 :            :               /* The lists don't have the same number of statements.  */
    3553                 :         70 :               if (tsi_end_p (tsi1) ^ tsi_end_p (tsi2))
    3554                 :            :                 return false;
    3555                 :         70 :               if (tsi_end_p (tsi1) && tsi_end_p (tsi2))
    3556                 :            :                 return true;
    3557                 :         50 :               if (!operand_equal_p (tsi_stmt (tsi1), tsi_stmt (tsi2),
    3558                 :            :                                     flags & (OEP_LEXICOGRAPHIC
    3559                 :         50 :                                              | OEP_NO_HASH_CHECK)))
    3560                 :            :                 return false;
    3561                 :            :             }
    3562                 :            :         }
    3563                 :            :       return false;
    3564                 :            : 
    3565                 :     250519 :     case tcc_statement:
    3566                 :     250519 :       switch (TREE_CODE (arg0))
    3567                 :            :         {
    3568                 :         65 :         case RETURN_EXPR:
    3569                 :         65 :           if (flags & OEP_LEXICOGRAPHIC)
    3570                 :         65 :             return OP_SAME_WITH_NULL (0);
    3571                 :            :           return false;
    3572                 :          5 :         case DEBUG_BEGIN_STMT:
    3573                 :          5 :           if (flags & OEP_LEXICOGRAPHIC)
    3574                 :          5 :             return true;
    3575                 :            :           return false;
    3576                 :            :         default:
    3577                 :            :           return false;
    3578                 :            :          }
    3579                 :            : 
    3580                 :            :     default:
    3581                 :            :       return false;
    3582                 :            :     }
    3583                 :            : 
    3584                 :            : #undef OP_SAME
    3585                 :            : #undef OP_SAME_WITH_NULL
    3586                 :            : }
    3587                 :            : 
    3588                 :            : /* Generate a hash value for an expression.  This can be used iteratively
    3589                 :            :    by passing a previous result as the HSTATE argument.  */
    3590                 :            : 
    3591                 :            : void
    3592                 : 1416150000 : operand_compare::hash_operand (const_tree t, inchash::hash &hstate,
    3593                 :            :                                unsigned int flags)
    3594                 :            : {
    3595                 : 1416150000 :   int i;
    3596                 : 1416150000 :   enum tree_code code;
    3597                 : 1416150000 :   enum tree_code_class tclass;
    3598                 :            : 
    3599                 : 1416150000 :   if (t == NULL_TREE || t == error_mark_node)
    3600                 :            :     {
    3601                 :   49316400 :       hstate.merge_hash (0);
    3602                 :   49316400 :       return;
    3603                 :            :     }
    3604                 :            : 
    3605                 : 1366840000 :   STRIP_ANY_LOCATION_WRAPPER (t);
    3606                 :            : 
    3607                 : 1366840000 :   if (!(flags & OEP_ADDRESS_OF))
    3608                 : 1266440000 :     STRIP_NOPS (t);
    3609                 :            : 
    3610                 : 1366840000 :   code = TREE_CODE (t);
    3611                 :            : 
    3612                 : 1366840000 :   switch (code)
    3613                 :            :     {
    3614                 :            :     /* Alas, constants aren't shared, so we can't rely on pointer
    3615                 :            :        identity.  */
    3616                 :         87 :     case VOID_CST:
    3617                 :         87 :       hstate.merge_hash (0);
    3618                 :            :       return;
    3619                 :  429996000 :     case INTEGER_CST:
    3620                 :  429996000 :       gcc_checking_assert (!(flags & OEP_ADDRESS_OF));
    3621                 :  871035000 :       for (i = 0; i < TREE_INT_CST_EXT_NUNITS (t); i++)
    3622                 :  441039000 :         hstate.add_hwi (TREE_INT_CST_ELT (t, i));
    3623                 :            :       return;
    3624                 :    9938100 :     case REAL_CST:
    3625                 :    9938100 :       {
    3626                 :    9938100 :         unsigned int val2;
    3627                 :    9938100 :         if (!HONOR_SIGNED_ZEROS (t) && real_zerop (t))
    3628                 :            :           val2 = rvc_zero;
    3629                 :            :         else
    3630                 :    9785570 :           val2 = real_hash (TREE_REAL_CST_PTR (t));
    3631                 :    9938100 :         hstate.merge_hash (val2);
    3632                 :            :         return;
    3633                 :            :       }
    3634                 :          0 :     case FIXED_CST:
    3635                 :          0 :       {
    3636                 :          0 :         unsigned int val2 = fixed_hash (TREE_FIXED_CST_PTR (t));
    3637                 :          0 :         hstate.merge_hash (val2);
    3638                 :            :         return;
    3639                 :            :       }
    3640                 :    6064150 :     case STRING_CST:
    3641                 :    6064150 :       hstate.add ((const void *) TREE_STRING_POINTER (t),
    3642                 :    6064150 :                   TREE_STRING_LENGTH (t));
    3643                 :            :       return;
    3644                 :     206798 :     case COMPLEX_CST:
    3645                 :     206798 :       hash_operand (TREE_REALPART (t), hstate, flags);
    3646                 :     206798 :       hash_operand (TREE_IMAGPART (t), hstate, flags);
    3647                 :     206798 :       return;
    3648                 :     817484 :     case VECTOR_CST:
    3649                 :     817484 :       {
    3650                 :     817484 :         hstate.add_int (VECTOR_CST_NPATTERNS (t));
    3651                 :     817484 :         hstate.add_int (VECTOR_CST_NELTS_PER_PATTERN (t));
    3652                 :     817484 :         unsigned int count = vector_cst_encoded_nelts (t);
    3653                 :    2896590 :         for (unsigned int i = 0; i < count; ++i)
    3654                 :    2079100 :           hash_operand (VECTOR_CST_ENCODED_ELT (t, i), hstate, flags);
    3655                 :            :         return;
    3656                 :            :       }
    3657                 :  537661000 :     case SSA_NAME:
    3658                 :            :       /* We can just compare by pointer.  */
    3659                 :  537661000 :       hstate.add_hwi (SSA_NAME_VERSION (t));
    3660                 :            :       return;
    3661                 :            :     case PLACEHOLDER_EXPR:
    3662                 :            :       /* The node itself doesn't matter.  */
    3663                 :            :       return;
    3664                 :            :     case BLOCK:
    3665                 :            :     case OMP_CLAUSE:
    3666                 :            :       /* Ignore.  */
    3667                 :            :       return;
    3668                 :     294074 :     case TREE_LIST:
    3669                 :            :       /* A list of expressions, for a CALL_EXPR or as the elements of a
    3670                 :            :          VECTOR_CST.  */
    3671                 :     294074 :       for (; t; t = TREE_CHAIN (t))
    3672                 :     147037 :         hash_operand (TREE_VALUE (t), hstate, flags);
    3673                 :            :       return;
    3674                 :    4590930 :     case CONSTRUCTOR:
    3675                 :    4590930 :       {
    3676                 :    4590930 :         unsigned HOST_WIDE_INT idx;
    3677                 :    4590930 :         tree field, value;
    3678                 :    4590930 :         flags &= ~OEP_ADDRESS_OF;
    3679                 :    4590930 :         hstate.add_int (CONSTRUCTOR_NO_CLEARING (t));
    3680                 :   31729400 :         FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), idx, field, value)
    3681                 :            :           {
    3682                 :            :             /* In GIMPLE the indexes can be either NULL or matching i.  */
    3683                 :   11926500 :             if (field == NULL_TREE)
    3684                 :     720134 :               field = bitsize_int (idx);
    3685                 :   11926500 :             hash_operand (field, hstate, flags);
    3686                 :   11926500 :             hash_operand (value, hstate, flags);
    3687                 :            :           }
    3688                 :            :         return;
    3689                 :            :       }
    3690                 :        225 :     case STATEMENT_LIST:
    3691                 :        225 :       {
    3692                 :        225 :         tree_stmt_iterator i;
    3693                 :        225 :         for (i = tsi_start (CONST_CAST_TREE (t));
    3694                 :        647 :              !tsi_end_p (i); tsi_next (&i))
    3695                 :        422 :           hash_operand (tsi_stmt (i), hstate, flags);
    3696                 :        225 :         return;
    3697                 :            :       }
    3698                 :            :     case TREE_VEC:
    3699                 :         32 :       for (i = 0; i < TREE_VEC_LENGTH (t); ++i)
    3700                 :         16 :         hash_operand (TREE_VEC_ELT (t, i), hstate, flags);
    3701                 :            :       return;
    3702                 :          5 :     case IDENTIFIER_NODE:
    3703                 :          5 :       hstate.add_object (IDENTIFIER_HASH_VALUE (t));
    3704                 :            :       return;
    3705                 :   12658400 :     case FUNCTION_DECL:
    3706                 :            :       /* When referring to a built-in FUNCTION_DECL, use the __builtin__ form.
    3707                 :            :          Otherwise nodes that compare equal according to operand_equal_p might
    3708                 :            :          get different hash codes.  However, don't do this for machine specific
    3709                 :            :          or front end builtins, since the function code is overloaded in those
    3710                 :            :          cases.  */
    3711                 :   12658400 :       if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL
    3712                 :   12658400 :           && builtin_decl_explicit_p (DECL_FUNCTION_CODE (t)))
    3713                 :            :         {
    3714                 :    3180240 :           t = builtin_decl_explicit (DECL_FUNCTION_CODE (t));
    3715                 :    3180240 :           code = TREE_CODE (t);
    3716                 :            :         }
    3717                 :            :       /* FALL THROUGH */
    3718                 :  377414000 :     default:
    3719                 :  377414000 :       if (POLY_INT_CST_P (t))
    3720                 :            :         {
    3721                 :            :           for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
    3722                 :            :             hstate.add_wide_int (wi::to_wide (POLY_INT_CST_COEFF (t, i)));
    3723                 :            :           return;
    3724                 :            :         }
    3725                 :  377414000 :       tclass = TREE_CODE_CLASS (code);
    3726                 :            : 
    3727                 :  377414000 :       if (tclass == tcc_declaration)
    3728                 :            :         {
    3729                 :            :           /* DECL's have a unique ID */
    3730                 :  197845000 :           hstate.add_hwi (DECL_UID (t));
    3731                 :            :         }
    3732                 :  179569000 :       else if (tclass == tcc_comparison && !commutative_tree_code (code))
    3733                 :            :         {
    3734                 :            :           /* For comparisons that can be swapped, use the lower
    3735                 :            :              tree code.  */
    3736                 :     253496 :           enum tree_code ccode = swap_tree_comparison (code);
    3737                 :     253496 :           if (code < ccode)
    3738                 :     105378 :             ccode = code;
    3739                 :     253496 :           hstate.add_object (ccode);
    3740                 :     253496 :           hash_operand (TREE_OPERAND (t, ccode != code), hstate, flags);
    3741                 :     253496 :           hash_operand (TREE_OPERAND (t, ccode == code), hstate, flags);
    3742                 :            :         }
    3743                 :  179316000 :       else if (CONVERT_EXPR_CODE_P (code))
    3744                 :            :         {
    3745                 :            :           /* NOP_EXPR and CONVERT_EXPR are considered equal by
    3746                 :            :              operand_equal_p.  */
    3747                 :    3319160 :           enum tree_code ccode = NOP_EXPR;
    3748                 :    3319160 :           hstate.add_object (ccode);
    3749                 :            : 
    3750                 :            :           /* Don't hash the type, that can lead to having nodes which
    3751                 :            :              compare equal according to operand_equal_p, but which
    3752                 :            :              have different hash codes.  Make sure to include signedness
    3753                 :            :              in the hash computation.  */
    3754                 :    3319160 :           hstate.add_int (TYPE_UNSIGNED (TREE_TYPE (t)));
    3755                 :    3319160 :           hash_operand (TREE_OPERAND (t, 0), hstate, flags);
    3756                 :            :         }
    3757                 :            :       /* For OEP_ADDRESS_OF, hash MEM_EXPR[&decl, 0] the same as decl.  */
    3758                 :  175996000 :       else if (code == MEM_REF
    3759                 :   44705600 :                && (flags & OEP_ADDRESS_OF) != 0
    3760                 :   33123200 :                && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR
    3761                 :    3587820 :                && DECL_P (TREE_OPERAND (TREE_OPERAND (t, 0), 0))
    3762                 :  179471000 :                && integer_zerop (TREE_OPERAND (t, 1)))
    3763                 :    2036220 :         hash_operand (TREE_OPERAND (TREE_OPERAND (t, 0), 0),
    3764                 :    2036220 :                       hstate, flags);
    3765                 :            :       /* Don't ICE on FE specific trees, or their arguments etc.
    3766                 :            :          during operand_equal_p hash verification.  */
    3767                 :  173960000 :       else if (!IS_EXPR_CODE_CLASS (tclass))
    3768                 :         52 :         gcc_assert (flags & OEP_HASH_CHECK);
    3769                 :            :       else
    3770                 :            :         {
    3771                 :  173960000 :           unsigned int sflags = flags;
    3772                 :            : 
    3773                 :  173960000 :           hstate.add_object (code);
    3774                 :            : 
    3775                 :  173960000 :           switch (code)
    3776                 :            :             {
    3777                 :   65496300 :             case ADDR_EXPR:
    3778                 :   65496300 :               gcc_checking_assert (!(flags & OEP_ADDRESS_OF));
    3779                 :   65496300 :               flags |= OEP_ADDRESS_OF;
    3780                 :   65496300 :               sflags = flags;
    3781                 :   65496300 :               break;
    3782                 :            : 
    3783                 :   45090700 :             case INDIRECT_REF:
    3784                 :   45090700 :             case MEM_REF:
    3785                 :   45090700 :             case TARGET_MEM_REF:
    3786                 :   45090700 :               flags &= ~OEP_ADDRESS_OF;
    3787                 :   45090700 :               sflags = flags;
    3788                 :   45090700 :               break;
    3789                 :            : 
    3790                 :   47258200 :             case ARRAY_REF:
    3791                 :   47258200 :             case ARRAY_RANGE_REF:
    3792                 :   47258200 :             case COMPONENT_REF:
    3793                 :   47258200 :             case BIT_FIELD_REF:
    3794                 :   47258200 :               sflags &= ~OEP_ADDRESS_OF;
    3795                 :   47258200 :               break;
    3796                 :            : 
    3797                 :      11171 :             case COND_EXPR:
    3798                 :      11171 :               flags &= ~OEP_ADDRESS_OF;
    3799                 :      11171 :               break;
    3800                 :            : 
    3801                 :          0 :             case WIDEN_MULT_PLUS_EXPR:
    3802                 :          0 :             case WIDEN_MULT_MINUS_EXPR:
    3803                 :          0 :               {
    3804                 :            :                 /* The multiplication operands are commutative.  */
    3805                 :          0 :                 inchash::hash one, two;
    3806                 :          0 :                 hash_operand (TREE_OPERAND (t, 0), one, flags);
    3807                 :          0 :                 hash_operand (TREE_OPERAND (t, 1), two, flags);
    3808                 :          0 :                 hstate.add_commutative (one, two);
    3809                 :          0 :                 hash_operand (TREE_OPERAND (t, 2), two, flags);
    3810                 :          0 :                 return;
    3811                 :            :               }
    3812                 :            : 
    3813                 :      53832 :             case CALL_EXPR:
    3814                 :      53832 :               if (CALL_EXPR_FN (t) == NULL_TREE)
    3815                 :       7049 :                 hstate.add_int (CALL_EXPR_IFN (t));
    3816                 :            :               break;
    3817                 :            : 
    3818                 :         32 :             case TARGET_EXPR:
    3819                 :            :               /* For TARGET_EXPR, just hash on the TARGET_EXPR_SLOT.
    3820                 :            :                  Usually different TARGET_EXPRs just should use
    3821                 :            :                  different temporaries in their slots.  */
    3822                 :         32 :               hash_operand (TARGET_EXPR_SLOT (t), hstate, flags);
    3823                 :         32 :               return;
    3824                 :            : 
    3825                 :            :             /* Virtual table call.  */
    3826                 :     144210 :             case OBJ_TYPE_REF:
    3827                 :     144210 :               inchash::add_expr (OBJ_TYPE_REF_EXPR (t), hstate, flags);
    3828                 :     144210 :               inchash::add_expr (OBJ_TYPE_REF_TOKEN (t), hstate, flags);
    3829                 :     144210 :               inchash::add_expr (OBJ_TYPE_REF_OBJECT (t), hstate, flags);
    3830                 :     144210 :               return;
    3831                 :            :             default:
    3832                 :            :               break;
    3833                 :            :             }
    3834                 :            : 
    3835                 :            :           /* Don't hash the type, that can lead to having nodes which
    3836                 :            :              compare equal according to operand_equal_p, but which
    3837                 :            :              have different hash codes.  */
    3838                 :  173816000 :           if (code == NON_LVALUE_EXPR)
    3839                 :            :             {
    3840                 :            :               /* Make sure to include signness in the hash computation.  */
    3841                 :          0 :               hstate.add_int (TYPE_UNSIGNED (TREE_TYPE (t)));
    3842                 :          0 :               hash_operand (TREE_OPERAND (t, 0), hstate, flags);
    3843                 :            :             }
    3844                 :            : 
    3845                 :  173816000 :           else if (commutative_tree_code (code))
    3846                 :            :             {
    3847                 :            :               /* It's a commutative expression.  We want to hash it the same
    3848                 :            :                  however it appears.  We do this by first hashing both operands
    3849                 :            :                  and then rehashing based on the order of their independent
    3850                 :            :                  hashes.  */
    3851                 :   12124000 :               inchash::hash one, two;
    3852                 :   12124000 :               hash_operand (TREE_OPERAND (t, 0), one, flags);
    3853                 :   12124000 :               hash_operand (TREE_OPERAND (t, 1), two, flags);
    3854                 :   12124000 :               hstate.add_commutative (one, two);
    3855                 :            :             }
    3856                 :            :           else
    3857                 :  478629000 :             for (i = TREE_OPERAND_LENGTH (t) - 1; i >= 0; --i)
    3858                 :  316937000 :               hash_operand (TREE_OPERAND (t, i), hstate,
    3859                 :  316937000 :                             i == 0 ? flags : sflags);
    3860                 :            :         }
    3861                 :            :       return;
    3862                 :            :     }
    3863                 :            : }
    3864                 :            : 
    3865                 :            : bool
    3866                 : 4109880000 : operand_compare::verify_hash_value (const_tree arg0, const_tree arg1,
    3867                 :            :                                     unsigned int flags, bool *ret)
    3868                 :            : {
    3869                 :            :   /* When checking, verify at the outermost operand_equal_p call that
    3870                 :            :      if operand_equal_p returns non-zero then ARG0 and ARG1 has the same
    3871                 :            :      hash value.  */
    3872                 : 4109880000 :   if (flag_checking && !(flags & OEP_NO_HASH_CHECK))
    3873                 :            :     {
    3874                 : 1887230000 :       if (operand_equal_p (arg0, arg1, flags | OEP_NO_HASH_CHECK))
    3875                 :            :         {
    3876                 :  267667000 :           if (arg0 != arg1)
    3877                 :            :             {
    3878                 :   57062300 :               inchash::hash hstate0 (0), hstate1 (0);
    3879                 :   57062300 :               hash_operand (arg0, hstate0, flags | OEP_HASH_CHECK);
    3880                 :   57062300 :               hash_operand (arg1, hstate1, flags | OEP_HASH_CHECK);
    3881                 :   57062300 :               hashval_t h0 = hstate0.end ();
    3882                 :   57062300 :               hashval_t h1 = hstate1.end ();
    3883                 :   57062300 :               gcc_assert (h0 == h1);
    3884                 :            :             }
    3885                 :  267667000 :           *ret = true;
    3886                 :            :         }
    3887                 :            :       else
    3888                 : 1619560000 :         *ret = false;
    3889                 :            : 
    3890                 : 1887230000 :       return true;
    3891                 :            :     }
    3892                 :            : 
    3893                 :            :   return false;
    3894                 :            : }
    3895                 :            : 
    3896                 :            : 
    3897                 :            : static operand_compare default_compare_instance;
    3898                 :            : 
    3899                 :            : /* Conveinece wrapper around operand_compare class because usually we do
    3900                 :            :    not need to play with the valueizer.  */
    3901                 :            : 
    3902                 :            : bool
    3903                 : 1884010000 : operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
    3904                 :            : {
    3905                 : 1884010000 :   return default_compare_instance.operand_equal_p (arg0, arg1, flags);
    3906                 :            : }
    3907                 :            : 
    3908                 :            : namespace inchash
    3909                 :            : {
    3910                 :            : 
    3911                 :            : /* Generate a hash value for an expression.  This can be used iteratively
    3912                 :            :    by passing a previous result as the HSTATE argument.
    3913                 :            : 
    3914                 :            :    This function is intended to produce the same hash for expressions which
    3915                 :            :    would compare equal using operand_equal_p.  */
    3916                 :            : void
    3917                 :  951195000 : add_expr (const_tree t, inchash::hash &hstate, unsigned int flags)
    3918                 :            : {
    3919                 :  951195000 :   default_compare_instance.hash_operand (t, hstate, flags);
    3920                 :  951195000 : }
    3921                 :            : 
    3922                 :            : }
    3923                 :            : 
    3924                 :            : /* Similar to operand_equal_p, but see if ARG0 might be a variant of ARG1
    3925                 :            :    with a different signedness or a narrower precision.  */
    3926                 :            : 
    3927                 :            : static bool
    3928                 :    6176210 : operand_equal_for_comparison_p (tree arg0, tree arg1)
    3929                 :            : {
    3930                 :    6176210 :   if (operand_equal_p (arg0, arg1, 0))
    3931                 :            :     return true;
    3932                 :            : 
    3933                 :   11737700 :   if (! INTEGRAL_TYPE_P (TREE_TYPE (arg0))
    3934                 :   10755400 :       || ! INTEGRAL_TYPE_P (TREE_TYPE (arg1)))
    3935                 :            :     return false;
    3936                 :            : 
    3937                 :            :   /* Discard any conversions that don't change the modes of ARG0 and ARG1
    3938                 :            :      and see if the inner values are the same.  This removes any
    3939                 :            :      signedness comparison, which doesn't matter here.  */
    3940                 :    2932330 :   tree op0 = arg0;
    3941                 :    2932330 :   tree op1 = arg1;
    3942                 :    2932330 :   STRIP_NOPS (op0);
    3943                 :    2932330 :   STRIP_NOPS (op1);
    3944                 :    2932330 :   if (operand_equal_p (op0, op1, 0))
    3945                 :            :     return true;
    3946                 :            : 
    3947                 :            :   /* Discard a single widening conversion from ARG1 and see if the inner
    3948                 :            :      value is the same as ARG0.  */
    3949                 :    2784020 :   if (CONVERT_EXPR_P (arg1)
    3950                 :     424453 :       && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (arg1, 0)))
    3951                 :     424363 :       && TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg1, 0)))
    3952                 :     424363 :          < TYPE_PRECISION (TREE_TYPE (arg1))
    3953                 :    2907430 :       && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
    3954                 :      26923 :     return true;
    3955                 :            : 
    3956                 :            :   return false;
    3957                 :            : }
    3958                 :            : 
    3959                 :            : /* See if ARG is an expression that is either a comparison or is performing
    3960                 :            :    arithmetic on comparisons.  The comparisons must only be comparing
    3961                 :            :    two different values, which will be stored in *CVAL1 and *CVAL2; if
    3962                 :            :    they are nonzero it means that some operands have already been found.
    3963                 :            :    No variables may be used anywhere else in the expression except in the
    3964                 :            :    comparisons.  
    3965                 :            : 
    3966                 :            :    If this is true, return 1.  Otherwise, return zero.  */
    3967                 :            : 
    3968                 :            : static bool
    3969                 :   44495500 : twoval_comparison_p (tree arg, tree *cval1, tree *cval2)
    3970                 :            : {
    3971                 :   46150200 :   enum tree_code code = TREE_CODE (arg);
    3972                 :   46150200 :   enum tree_code_class tclass = TREE_CODE_CLASS (code);
    3973                 :            : 
    3974                 :            :   /* We can handle some of the tcc_expression cases here.  */
    3975                 :   46150200 :   if (tclass == tcc_expression && code == TRUTH_NOT_EXPR)
    3976                 :            :     tclass = tcc_unary;
    3977                 :   46142000 :   else if (tclass == tcc_expression
    3978                 :    3917190 :            && (code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR
    3979                 :    3917190 :                || code == COMPOUND_EXPR))
    3980                 :            :     tclass = tcc_binary;
    3981                 :            : 
    3982                 :   46135200 :   switch (tclass)
    3983                 :            :     {
    3984                 :    1654720 :     case tcc_unary:
    3985                 :    1654720 :       return twoval_comparison_p (TREE_OPERAND (arg, 0), cval1, cval2);
    3986                 :            : 
    3987                 :    2666180 :     case tcc_binary:
    3988                 :    2666180 :       return (twoval_comparison_p (TREE_OPERAND (arg, 0), cval1, cval2)
    3989                 :    2666180 :               && twoval_comparison_p (TREE_OPERAND (arg, 1), cval1, cval2));
    3990                 :            : 
    3991                 :            :     case tcc_constant:
    3992                 :            :       return true;
    3993                 :            : 
    3994                 :    3910330 :     case tcc_expression:
    3995                 :    3910330 :       if (code == COND_EXPR)
    3996                 :        462 :         return (twoval_comparison_p (TREE_OPERAND (arg, 0), cval1, cval2)
    3997                 :        462 :                 && twoval_comparison_p (TREE_OPERAND (arg, 1), cval1, cval2)
    3998                 :        499 :                 && twoval_comparison_p (TREE_OPERAND (arg, 2), cval1, cval2));
    3999                 :            :       return false;
    4000                 :            : 
    4001                 :       9813 :     case tcc_comparison:
    4002                 :            :       /* First see if we can handle the first operand, then the second.  For
    4003                 :            :          the second operand, we know *CVAL1 can't be zero.  It must be that
    4004                 :            :          one side of the comparison is each of the values; test for the
    4005                 :            :          case where this isn't true by failing if the two operands
    4006                 :            :          are the same.  */
    4007                 :            : 
    4008                 :       9813 :       if (operand_equal_p (TREE_OPERAND (arg, 0),
    4009                 :       9813 :                            TREE_OPERAND (arg, 1), 0))
    4010                 :            :         return false;
    4011                 :            : 
    4012                 :       9813 :       if (*cval1 == 0)
    4013                 :       9226 :         *cval1 = TREE_OPERAND (arg, 0);
    4014                 :        587 :       else if (operand_equal_p (*cval1, TREE_OPERAND (arg, 0), 0))
    4015                 :            :         ;
    4016                 :        479 :       else if (*cval2 == 0)
    4017                 :          0 :         *cval2 = TREE_OPERAND (arg, 0);
    4018                 :        479 :       else if (operand_equal_p (*cval2, TREE_OPERAND (arg, 0), 0))
    4019                 :            :         ;
    4020                 :            :       else
    4021                 :            :         return false;
    4022                 :            : 
    4023                 :       9334 :       if (operand_equal_p (*cval1, TREE_OPERAND (arg, 1), 0))
    4024                 :            :         ;
    4025                 :       9334 :       else if (*cval2 == 0)
    4026                 :       9226 :         *cval2 = TREE_OPERAND (arg, 1);
    4027                 :        108 :       else if (operand_equal_p (*cval2, TREE_OPERAND (arg, 1), 0))
    4028                 :            :         ;
    4029                 :            :       else
    4030                 :         97 :         return false;
    4031                 :            : 
    4032                 :            :       return true;
    4033                 :            : 
    4034                 :   37533900 :     default:
    4035                 :   37533900 :       return false;
    4036                 :            :     }
    4037                 :            : }
    4038                 :            : 
    4039                 :            : /* ARG is a tree that is known to contain just arithmetic operations and
    4040                 :            :    comparisons.  Evaluate the operations in the tree substituting NEW0 for
    4041                 :            :    any occurrence of OLD0 as an operand of a comparison and likewise for
    4042                 :            :    NEW1 and OLD1.  */
    4043                 :            : 
    4044                 :            : static tree
    4045                 :        303 : eval_subst (location_t loc, tree arg, tree old0, tree new0,
    4046                 :            :             tree old1, tree new1)
    4047                 :            : {
    4048                 :        303 :   tree type = TREE_TYPE (arg);
    4049                 :        303 :   enum tree_code code = TREE_CODE (arg);
    4050                 :        303 :   enum tree_code_class tclass = TREE_CODE_CLASS (code);
    4051                 :            : 
    4052                 :            :   /* We can handle some of the tcc_expression cases here.  */
    4053                 :        303 :   if (tclass == tcc_expression && code == TRUTH_NOT_EXPR)
    4054                 :            :     tclass = tcc_unary;
    4055                 :        303 :   else if (tclass == tcc_expression
    4056                 :          9 :            && (code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR))
    4057                 :            :     tclass = tcc_binary;
    4058                 :            : 
    4059                 :        294 :   switch (tclass)
    4060                 :            :     {
    4061                 :         66 :     case tcc_unary:
    4062                 :         66 :       return fold_build1_loc (loc, code, type,
    4063                 :         66 :                           eval_subst (loc, TREE_OPERAND (arg, 0),
    4064                 :         66 :                                       old0, new0, old1, new1));
    4065                 :            : 
    4066                 :         57 :     case tcc_binary:
    4067                 :        114 :       return fold_build2_loc (loc, code, type,
    4068                 :         57 :                           eval_subst (loc, TREE_OPERAND (arg, 0),
    4069                 :            :                                       old0, new0, old1, new1),
    4070                 :         57 :                           eval_subst (loc, TREE_OPERAND (arg, 1),
    4071                 :         57 :                                       old0, new0, old1, new1));
    4072                 :            : 
    4073                 :          0 :     case tcc_expression:
    4074                 :          0 :       switch (code)
    4075                 :            :         {
    4076                 :          0 :         case SAVE_EXPR:
    4077                 :          0 :           return eval_subst (loc, TREE_OPERAND (arg, 0), old0, new0,
    4078                 :          0 :                              old1, new1);
    4079                 :            : 
    4080                 :          0 :         case COMPOUND_EXPR:
    4081                 :          0 :           return eval_subst (loc, TREE_OPERAND (arg, 1), old0, new0,
    4082                 :          0 :                              old1, new1);
    4083                 :            : 
    4084                 :          0 :         case COND_EXPR:
    4085                 :          0 :           return fold_build3_loc (loc, code, type,
    4086                 :          0 :                               eval_subst (loc, TREE_OPERAND (arg, 0),
    4087                 :            :                                           old0, new0, old1, new1),
    4088                 :          0 :                               eval_subst (loc, TREE_OPERAND (arg, 1),
    4089                 :            :                                           old0, new0, old1, new1),
    4090                 :          0 :                               eval_subst (loc, TREE_OPERAND (arg, 2),
    4091                 :          0 :                                           old0, new0, old1, new1));
    4092                 :            :         default:
    4093                 :            :           break;
    4094                 :            :         }
    4095                 :            :       /* Fall through - ???  */
    4096                 :            : 
    4097                 :        129 :     case tcc_comparison:
    4098                 :        129 :       {
    4099                 :        129 :         tree arg0 = TREE_OPERAND (arg, 0);
    4100                 :        129 :         tree arg1 = TREE_OPERAND (arg, 1);
    4101                 :            : 
    4102                 :            :         /* We need to check both for exact equality and tree equality.  The
    4103                 :            :            former will be true if the operand has a side-effect.  In that
    4104                 :            :            case, we know the operand occurred exactly once.  */
    4105                 :            : 
    4106                 :        129 :         if (arg0 == old0 || operand_equal_p (arg0, old0, 0))
    4107                 :            :           arg0 = new0;
    4108                 :          0 :         else if (arg0 == old1 || operand_equal_p (arg0, old1, 0))
    4109                 :            :           arg0 = new1;
    4110                 :            : 
    4111                 :        129 :         if (arg1 == old0 || operand_equal_p (arg1, old0, 0))
    4112                 :            :           arg1 = new0;
    4113                 :        129 :         else if (arg1 == old1 || operand_equal_p (arg1, old1, 0))
    4114                 :            :           arg1 = new1;
    4115                 :            : 
    4116                 :        129 :         return fold_build2_loc (loc, code, type, arg0, arg1);
    4117                 :            :       }
    4118                 :            : 
    4119                 :            :     default:
    4120                 :            :       return arg;
    4121                 :            :     }
    4122                 :            : }
    4123                 :            : 
    4124                 :            : /* Return a tree for the case when the result of an expression is RESULT
    4125                 :            :    converted to TYPE and OMITTED was previously an operand of the expression
    4126                 :            :    but is now not needed (e.g., we folded OMITTED * 0).
    4127                 :            : 
    4128                 :            :    If OMITTED has side effects, we must evaluate it.  Otherwise, just do
    4129                 :            :    the conversion of RESULT to TYPE.  */
    4130                 :            : 
    4131                 :            : tree
    4132                 :     156021 : omit_one_operand_loc (location_t loc, tree type, tree result, tree omitted)
    4133                 :            : {
    4134                 :     156021 :   tree t = fold_convert_loc (loc, type, result);
    4135                 :            : 
    4136                 :            :   /* If the resulting operand is an empty statement, just return the omitted
    4137                 :            :      statement casted to void. */
    4138                 :     191120 :   if (IS_EMPTY_STMT (t) && TREE_SIDE_EFFECTS (omitted))
    4139                 :          0 :     return build1_loc (loc, NOP_EXPR, void_type_node,
    4140                 :            :                        fold_ignored_result (omitted));
    4141                 :            : 
    4142                 :     156021 :   if (TREE_SIDE_EFFECTS (omitted))
    4143                 :       1892 :     return build2_loc (loc, COMPOUND_EXPR, type,
    4144                 :            :                        fold_ignored_result (omitted), t);
    4145                 :            : 
    4146                 :     154129 :   return non_lvalue_loc (loc, t);
    4147                 :            : }
    4148                 :            : 
    4149                 :            : /* Return a tree for the case when the result of an expression is RESULT
    4150                 :            :    converted to TYPE and OMITTED1 and OMITTED2 were previously operands
    4151                 :            :    of the expression but are now not needed.
    4152                 :            : 
    4153                 :            :    If OMITTED1 or OMITTED2 has side effects, they must be evaluated.
    4154                 :            :    If both OMITTED1 and OMITTED2 have side effects, OMITTED1 is
    4155                 :            :    evaluated before OMITTED2.  Otherwise, if neither has side effects,
    4156                 :            :    just do the conversion of RESULT to TYPE.  */
    4157                 :            : 
    4158                 :            : tree
    4159                 :        727 : omit_two_operands_loc (location_t loc, tree type, tree result,
    4160                 :            :                        tree omitted1, tree omitted2)
    4161                 :            : {
    4162                 :        727 :   tree t = fold_convert_loc (loc, type, result);
    4163                 :            : 
    4164                 :        727 :   if (TREE_SIDE_EFFECTS (omitted2))
    4165                 :         53 :     t = build2_loc (loc, COMPOUND_EXPR, type, omitted2, t);
    4166                 :        727 :   if (TREE_SIDE_EFFECTS (omitted1))
    4167                 :        130 :     t = build2_loc (loc, COMPOUND_EXPR, type, omitted1, t);
    4168                 :            : 
    4169                 :        727 :   return TREE_CODE (t) != COMPOUND_EXPR ? non_lvalue_loc (loc, t) : t;
    4170                 :            : }
    4171                 :            : 
    4172                 :            : 
    4173                 :            : /* Return a simplified tree node for the truth-negation of ARG.  This
    4174                 :            :    never alters ARG itself.  We assume that ARG is an operation that
    4175                 :            :    returns a truth value (0 or 1).
    4176                 :            : 
    4177                 :            :    FIXME: one would think we would fold the result, but it causes
    4178                 :            :    problems with the dominator optimizer.  */
    4179                 :            : 
    4180                 :            : static tree
    4181                 :   27068700 : fold_truth_not_expr (location_t loc, tree arg)
    4182                 :            : {
    4183                 :   27068700 :   tree type = TREE_TYPE (arg);
    4184                 :   27068700 :   enum tree_code code = TREE_CODE (arg);
    4185                 :   27068700 :   location_t loc1, loc2;
    4186                 :            : 
    4187                 :            :   /* If this is a comparison, we can simply invert it, except for
    4188                 :            :      floating-point non-equality comparisons, in which case we just
    4189                 :            :      enclose a TRUTH_NOT_EXPR around what we have.  */
    4190                 :            : 
    4191                 :   27068700 :   if (TREE_CODE_CLASS (code) == tcc_comparison)
    4192                 :            :     {
    4193                 :   23587700 :       tree op_type = TREE_TYPE (TREE_OPERAND (arg, 0));
    4194                 :   22641300 :       if (FLOAT_TYPE_P (op_type)
    4195                 :     957555 :           && flag_trapping_math
    4196                 :     929685 :           && code != ORDERED_EXPR && code != UNORDERED_EXPR
    4197                 :   24481700 :           && code != NE_EXPR && code != EQ_EXPR)
    4198                 :            :         return NULL_TREE;
    4199                 :            : 
    4200                 :   23228000 :       code = invert_tree_comparison (code, HONOR_NANS (op_type));
    4201                 :   23228000 :       if (code == ERROR_MARK)
    4202                 :            :         return NULL_TREE;
    4203                 :            : 
    4204                 :   23228000 :       tree ret = build2_loc (loc, code, type, TREE_OPERAND (arg, 0),
    4205                 :   23228000 :                              TREE_OPERAND (arg, 1));
    4206                 :   23228000 :       if (TREE_NO_WARNING (arg))
    4207                 :      86028 :         TREE_NO_WARNING (ret) = 1;
    4208                 :   23228000 :       return ret;
    4209                 :            :     }
    4210                 :            : 
    4211                 :    3480990 :   switch (code)
    4212                 :            :     {
    4213                 :          0 :     case INTEGER_CST:
    4214                 :          0 :       return constant_boolean_node (integer_zerop (arg), type);
    4215                 :            : 
    4216                 :      16183 :     case TRUTH_AND_EXPR:
    4217                 :      16183 :       loc1 = expr_location_or (TREE_OPERAND (arg, 0), loc);
    4218                 :      16183 :       loc2 = expr_location_or (TREE_OPERAND (arg, 1), loc);
    4219                 :      32366 :       return build2_loc (loc, TRUTH_OR_EXPR, type,
    4220                 :      16183 :                          invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)),
    4221                 :      16183 :                          invert_truthvalue_loc (loc2, TREE_OPERAND (arg, 1)));
    4222                 :            : 
    4223                 :       3079 :     case TRUTH_OR_EXPR:
    4224                 :       3079 :       loc1 = expr_location_or (TREE_OPERAND (arg, 0), loc);
    4225                 :       3079 :       loc2 = expr_location_or (TREE_OPERAND (arg, 1), loc);
    4226                 :       6158 :       return build2_loc (loc, TRUTH_AND_EXPR, type,
    4227                 :       3079 :                          invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)),
    4228                 :       3079 :                          invert_truthvalue_loc (loc2, TREE_OPERAND (arg, 1)));
    4229                 :            : 
    4230                 :       4121 :     case TRUTH_XOR_EXPR:
    4231                 :            :       /* Here we can invert either operand.  We invert the first operand
    4232                 :            :          unless the second operand is a TRUTH_NOT_EXPR in which case our
    4233                 :            :          result is the XOR of the first operand with the inside of the
    4234                 :            :          negation of the second operand.  */
    4235                 :            : 
    4236                 :       4121 :       if (TREE_CODE (TREE_OPERAND (arg, 1)) == TRUTH_NOT_EXPR)
    4237                 :          0 :         return build2_loc (loc, TRUTH_XOR_EXPR, type, TREE_OPERAND (arg, 0),
    4238                 :          0 :                            TREE_OPERAND (TREE_OPERAND (arg, 1), 0));
    4239                 :            :       else
    4240                 :       4121 :         return build2_loc (loc, TRUTH_XOR_EXPR, type,
    4241                 :       4121 :                            invert_truthvalue_loc (loc, TREE_OPERAND (arg, 0)),
    4242                 :       4121 :                            TREE_OPERAND (arg, 1));
    4243                 :            : 
    4244                 :      16986 :     case TRUTH_ANDIF_EXPR:
    4245                 :      16986 :       loc1 = expr_location_or (TREE_OPERAND (arg, 0), loc);
    4246                 :      16986 :       loc2 = expr_location_or (TREE_OPERAND (arg, 1), loc);
    4247                 :      33972 :       return build2_loc (loc, TRUTH_ORIF_EXPR, type,
    4248                 :      16986 :                          invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)),
    4249                 :      16986 :                          invert_truthvalue_loc (loc2, TREE_OPERAND (arg, 1)));
    4250                 :            : 
    4251                 :       8607 :     case TRUTH_ORIF_EXPR:
    4252                 :       8607 :       loc1 = expr_location_or (TREE_OPERAND (arg, 0), loc);
    4253                 :       8607 :       loc2 = expr_location_or (TREE_OPERAND (arg, 1), loc);
    4254                 :      17214 :       return build2_loc (loc, TRUTH_ANDIF_EXPR, type,
    4255                 :       8607 :                          invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)),
    4256                 :       8607 :                          invert_truthvalue_loc (loc2, TREE_OPERAND (arg, 1)));
    4257                 :            : 
    4258                 :     456057 :     case TRUTH_NOT_EXPR:
    4259                 :     456057 :       return TREE_OPERAND (arg, 0);
    4260                 :            : 
    4261                 :       5725 :     case COND_EXPR:
    4262                 :       5725 :       {
    4263                 :       5725 :         tree arg1 = TREE_OPERAND (arg, 1);
    4264                 :       5725 :         tree arg2 = TREE_OPERAND (arg, 2);
    4265                 :            : 
    4266                 :       5725 :         loc1 = expr_location_or (TREE_OPERAND (arg, 1), loc);
    4267                 :       5725 :         loc2 = expr_location_or (TREE_OPERAND (arg, 2), loc);
    4268                 :            : 
    4269                 :            :         /* A COND_EXPR may have a throw as one operand, which
    4270                 :            :            then has void type.  Just leave void operands
    4271                 :            :            as they are.  */
    4272                 :      11450 :         return build3_loc (loc, COND_EXPR, type, TREE_OPERAND (arg, 0),
    4273                 :       5725 :                            VOID_TYPE_P (TREE_TYPE (arg1))
    4274                 :       5725 :                            ? arg1 : invert_truthvalue_loc (loc1, arg1),
    4275                 :       5725 :                            VOID_TYPE_P (TREE_TYPE (arg2))
    4276                 :       5721 :                            ? arg2 : invert_truthvalue_loc (loc2, arg2));
    4277                 :            :       }
    4278                 :            : 
    4279                 :         62 :     case COMPOUND_EXPR:
    4280                 :         62 :       loc1 = expr_location_or (TREE_OPERAND (arg, 1), loc);
    4281                 :        124 :       return build2_loc (loc, COMPOUND_EXPR, type,
    4282                 :         62 :                          TREE_OPERAND (arg, 0),
    4283                 :         62 :                          invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 1)));
    4284                 :            : 
    4285                 :          0 :     case NON_LVALUE_EXPR:
    4286                 :          0 :       loc1 = expr_location_or (TREE_OPERAND (arg, 0), loc);
    4287                 :          0 :       return invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0));
    4288                 :            : 
    4289                 :      47155 :     CASE_CONVERT:
    4290                 :      47155 :       if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE)
    4291                 :      47091 :         return build1_loc (loc, TRUTH_NOT_EXPR, type, arg);
    4292                 :            : 
    4293                 :            :       /* fall through */
    4294                 :            : 
    4295                 :         64 :     case FLOAT_EXPR:
    4296                 :         64 :       loc1 = expr_location_or (TREE_OPERAND (arg, 0), loc);
    4297                 :         64 :       return build1_loc (loc, TREE_CODE (arg), type,
    4298                 :         64 :                          invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)));
    4299                 :            : 
    4300                 :        318 :     case BIT_AND_EXPR:
    4301                 :        318 :       if (!integer_onep (TREE_OPERAND (arg, 1)))
    4302                 :            :         return NULL_TREE;
    4303                 :          0 :       return build2_loc (loc, EQ_EXPR, type, arg, build_int_cst (type, 0));
    4304                 :            : 
    4305                 :          2 :     case SAVE_EXPR:
    4306                 :          2 :       return build1_loc (loc, TRUTH_NOT_EXPR, type, arg);
    4307                 :            : 
    4308                 :         21 :     case CLEANUP_POINT_EXPR:
    4309                 :         21 :       loc1 = expr_location_or (TREE_OPERAND (arg, 0), loc);
    4310                 :         21 :       return build1_loc (loc, CLEANUP_POINT_EXPR, type,
    4311                 :         21 :                          invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)));
    4312                 :            : 
    4313                 :            :     default:
    4314                 :            :       return NULL_TREE;
    4315                 :            :     }
    4316                 :            : }
    4317                 :            : 
    4318                 :            : /* Fold the truth-negation of ARG.  This never alters ARG itself.  We
    4319                 :            :    assume that ARG is an operation that returns a truth value (0 or 1
    4320                 :            :    for scalars, 0 or -1 for vectors).  Return the folded expression if
    4321                 :            :    folding is successful.  Otherwise, return NULL_TREE.  */
    4322                 :            : 
    4323                 :            : static tree
    4324                 :     876469 : fold_invert_truthvalue (location_t loc, tree arg)
    4325                 :            : {
    4326                 :     876469 :   tree type = TREE_TYPE (arg);
    4327                 :    1750610 :   return fold_unary_loc (loc, VECTOR_TYPE_P (type)
    4328                 :            :                               ? BIT_NOT_EXPR
    4329                 :            :                               : TRUTH_NOT_EXPR,
    4330                 :     876469 :                          type, arg);
    4331                 :            : }
    4332                 :            : 
    4333                 :            : /* Return a simplified tree node for the truth-negation of ARG.  This
    4334                 :            :    never alters ARG itself.  We assume that ARG is an operation that
    4335                 :            :    returns a truth value (0 or 1 for scalars, 0 or -1 for vectors).  */
    4336                 :            : 
    4337                 :            : tree
    4338                 :   25919700 : invert_truthvalue_loc (location_t loc, tree arg)
    4339                 :            : {
    4340                 :   25919700 :   if (TREE_CODE (arg) == ERROR_MARK)
    4341                 :            :     return arg;
    4342                 :            : 
    4343                 :   25919700 :   tree type = TREE_TYPE (arg);
    4344                 :   51839400 :   return fold_build1_loc (loc, VECTOR_TYPE_P (type)
    4345                 :            :                                ? BIT_NOT_EXPR
    4346                 :            :                                : TRUTH_NOT_EXPR,
    4347                 :   25919700 :                           type, arg);
    4348                 :            : }
    4349                 :            : 
    4350                 :            : /* Return a BIT_FIELD_REF of type TYPE to refer to BITSIZE bits of INNER
    4351                 :            :    starting at BITPOS.  The field is unsigned if UNSIGNEDP is nonzero
    4352                 :            :    and uses reverse storage order if REVERSEP is nonzero.  ORIG_INNER
    4353                 :            :    is the original memory reference used to preserve the alias set of
    4354                 :            :    the access.  */
    4355                 :            : 
    4356                 :            : static tree
    4357                 :      10823 : make_bit_field_ref (location_t loc, tree inner, tree orig_inner, tree type,
    4358                 :            :                     HOST_WIDE_INT bitsize, poly_int64 bitpos,
    4359                 :            :                     int unsignedp, int reversep)
    4360                 :            : {
    4361                 :      10823 :   tree result, bftype;
    4362                 :            : 
    4363                 :            :   /* Attempt not to lose the access path if possible.  */
    4364                 :      10823 :   if (TREE_CODE (orig_inner) == COMPONENT_REF)
    4365                 :            :     {
    4366                 :       9064 :       tree ninner = TREE_OPERAND (orig_inner, 0);
    4367                 :       9064 :       machine_mode nmode;
    4368                 :       9064 :       poly_int64 nbitsize, nbitpos;
    4369                 :       9064 :       tree noffset;
    4370                 :       9064 :       int nunsignedp, nreversep, nvolatilep = 0;
    4371                 :       9064 :       tree base = get_inner_reference (ninner, &nbitsize, &nbitpos,
    4372                 :            :                                        &noffset, &nmode, &nunsignedp,
    4373                 :            :                                        &nreversep, &nvolatilep);
    4374                 :       9064 :       if (base == inner
    4375                 :       9064 :           && noffset == NULL_TREE
    4376                 :      18128 :           && known_subrange_p (bitpos, bitsize, nbitpos, nbitsize)
    4377                 :       9064 :           && !reversep
    4378                 :       8996 :           && !nreversep
    4379                 :      18060 :           && !nvolatilep)
    4380                 :            :         {
    4381                 :       8996 :           inner = ninner;
    4382                 :       9064 :           bitpos -= nbitpos;
    4383                 :            :         }
    4384                 :            :     }
    4385                 :            : 
    4386                 :      10823 :   alias_set_type iset = get_alias_set (orig_inner);
    4387                 :      10823 :   if (iset == 0 && get_alias_set (inner) != iset)
    4388                 :        200 :     inner = fold_build2 (MEM_REF, TREE_TYPE (inner),
    4389                 :            :                          build_fold_addr_expr (inner),
    4390                 :            :                          build_int_cst (ptr_type_node, 0));
    4391                 :            : 
    4392                 :      10823 :   if (known_eq (bitpos, 0) && !reversep)
    4393                 :            :     {
    4394                 :       6260 :       tree size = TYPE_SIZE (TREE_TYPE (inner));
    4395                 :       6260 :       if ((INTEGRAL_TYPE_P (TREE_TYPE (inner))
    4396                 :       5552 :            || POINTER_TYPE_P (TREE_TYPE (inner)))
    4397                 :        714 :           && tree_fits_shwi_p (size)
    4398                 :       6974 :           && tree_to_shwi (size) == bitsize)
    4399                 :        714 :         return fold_convert_loc (loc, type, inner);
    4400                 :            :     }
    4401                 :            : 
    4402                 :      10109 :   bftype = type;
    4403                 :      10109 :   if (TYPE_PRECISION (bftype) != bitsize
    4404                 :      10109 :       || TYPE_UNSIGNED (bftype) == !unsignedp)
    4405                 :        637 :     bftype = build_nonstandard_integer_type (bitsize, 0);
    4406                 :            : 
    4407                 :      10109 :   result = build3_loc (loc, BIT_FIELD_REF, bftype, inner,
    4408                 :            :                        bitsize_int (bitsize), bitsize_int (bitpos));
    4409                 :      10109 :   REF_REVERSE_STORAGE_ORDER (result) = reversep;
    4410                 :            : 
    4411                 :      10109 :   if (bftype != type)
    4412                 :        637 :     result = fold_convert_loc (loc, type, result);
    4413                 :            : 
    4414                 :            :   return result;
    4415                 :            : }
    4416                 :            : 
    4417                 :            : /* Optimize a bit-field compare.
    4418                 :            : 
    4419                 :            :    There are two cases:  First is a compare against a constant and the
    4420                 :            :    second is a comparison of two items where the fields are at the same
    4421                 :            :    bit position relative to the start of a chunk (byte, halfword, word)
    4422                 :            :    large enough to contain it.  In these cases we can avoid the shift
    4423                 :            :    implicit in bitfield extractions.
    4424                 :            : 
    4425                 :            :    For constants, we emit a compare of the shifted constant with the
    4426                 :            :    BIT_AND_EXPR of a mask and a byte, halfword, or word of the operand being
    4427                 :            :    compared.  For two fields at the same position, we do the ANDs with the
    4428                 :            :    similar mask and compare the result of the ANDs.
    4429                 :            : 
    4430                 :            :    CODE is the comparison code, known to be either NE_EXPR or EQ_EXPR.
    4431                 :            :    COMPARE_TYPE is the type of the comparison, and LHS and RHS
    4432                 :            :    are the left and right operands of the comparison, respectively.
    4433                 :            : 
    4434                 :            :    If the optimization described above can be done, we return the resulting
    4435                 :            :    tree.  Otherwise we return zero.  */
    4436                 :            : 
    4437                 :            : static tree
    4438                 :     642864 : optimize_bit_field_compare (location_t loc, enum tree_code code,
    4439                 :            :                             tree compare_type, tree lhs, tree rhs)
    4440                 :            : {
    4441                 :     642864 :   poly_int64 plbitpos, plbitsize, rbitpos, rbitsize;
    4442                 :     642864 :   HOST_WIDE_INT lbitpos, lbitsize, nbitpos, nbitsize;
    4443                 :     642864 :   tree type = TREE_TYPE (lhs);
    4444                 :     642864 :   tree unsigned_type;
    4445                 :     642864 :   int const_p = TREE_CODE (rhs) == INTEGER_CST;
    4446                 :     642864 :   machine_mode lmode, rmode;
    4447                 :     642864 :   scalar_int_mode nmode;
    4448                 :     642864 :   int lunsignedp, runsignedp;
    4449                 :     642864 :   int lreversep, rreversep;
    4450                 :     642864 :   int lvolatilep = 0, rvolatilep = 0;
    4451                 :     642864 :   tree linner, rinner = NULL_TREE;
    4452                 :     642864 :   tree mask;
    4453                 :     642864 :   tree offset;
    4454                 :            : 
    4455                 :            :   /* Get all the information about the extractions being done.  If the bit size
    4456                 :            :      is the same as the size of the underlying object, we aren't doing an
    4457                 :            :      extraction at all and so can do nothing.  We also don't want to
    4458                 :            :      do anything if the inner expression is a PLACEHOLDER_EXPR since we
    4459                 :            :      then will no longer be able to replace it.  */
    4460                 :     642864 :   linner = get_inner_reference (lhs, &plbitsize, &plbitpos, &offset, &lmode,
    4461                 :            :                                 &lunsignedp, &lreversep, &lvolatilep);
    4462                 :     642864 :   if (linner == lhs
    4463                 :     642864 :       || !known_size_p (plbitsize)
    4464                 :     642864 :       || !plbitsize.is_constant (&lbitsize)
    4465                 :     642864 :       || !plbitpos.is_constant (&lbitpos)
    4466                 :    1285730 :       || known_eq (lbitsize, GET_MODE_BITSIZE (lmode))
    4467                 :       7394 :       || offset != 0
    4468                 :       7392 :       || TREE_CODE (linner) == PLACEHOLDER_EXPR
    4469                 :     650256 :       || lvolatilep)
    4470                 :     635532 :     return 0;
    4471                 :            : 
    4472                 :       7332 :   if (const_p)
    4473                 :       2691 :     rreversep = lreversep;
    4474                 :            :   else
    4475                 :            :    {
    4476                 :            :      /* If this is not a constant, we can only do something if bit positions,
    4477                 :            :         sizes, signedness and storage order are the same.  */
    4478                 :       4641 :      rinner
    4479                 :       4641 :        = get_inner_reference (rhs, &rbitsize, &rbitpos, &offset, &rmode,
    4480                 :            :                               &runsignedp, &rreversep, &rvolatilep);
    4481                 :            : 
    4482                 :       4641 :      if (rinner == rhs
    4483                 :       4599 :          || maybe_ne (lbitpos, rbitpos)
    4484                 :       4567 :          || maybe_ne (lbitsize, rbitsize)
    4485                 :       4567 :          || lunsignedp != runsignedp
    4486                 :       4567 :          || lreversep != rreversep
    4487                 :       4567 :          || offset != 0
    4488                 :       4567 :          || TREE_CODE (rinner) == PLACEHOLDER_EXPR
    4489                 :       9208 :          || rvolatilep)
    4490                 :            :        return 0;
    4491                 :            :    }
    4492                 :            : 
    4493                 :            :   /* Honor the C++ memory model and mimic what RTL expansion does.  */
    4494                 :       7258 :   poly_uint64 bitstart = 0;
    4495                 :       7258 :   poly_uint64 bitend = 0;
    4496                 :       7258 :   if (TREE_CODE (lhs) == COMPONENT_REF)
    4497                 :            :     {
    4498                 :       7141 :       get_bit_range (&bitstart, &bitend, lhs, &plbitpos, &offset);
    4499                 :       7141 :       if (!plbitpos.is_constant (&lbitpos) || offset != NULL_TREE)
    4500                 :            :         return 0;
    4501                 :            :     }
    4502                 :            : 
    4503                 :            :   /* See if we can find a mode to refer to this field.  We should be able to,
    4504                 :            :      but fail if we can't.  */
    4505                 :      14516 :   if (!get_best_mode (lbitsize, lbitpos, bitstart, bitend,
    4506                 :       2691 :                       const_p ? TYPE_ALIGN (TREE_TYPE (linner))
    4507                 :      16392 :                       : MIN (TYPE_ALIGN (TREE_TYPE (linner)),
    4508                 :            :                              TYPE_ALIGN (TREE_TYPE (rinner))),
    4509                 :       7258 :                       BITS_PER_WORD, false, &nmode))
    4510                 :            :     return 0;
    4511                 :            : 
    4512                 :            :   /* Set signed and unsigned types of the precision of this mode for the
    4513                 :            :      shifts below.  */
    4514                 :       5607 :   unsigned_type = lang_hooks.types.type_for_mode (nmode, 1);
    4515                 :            : 
    4516                 :            :   /* Compute the bit position and size for the new reference and our offset
    4517                 :            :      within it. If the new reference is the same size as the original, we
    4518                 :            :      won't optimize anything, so return zero.  */
    4519                 :       5607 :   nbitsize = GET_MODE_BITSIZE (nmode);
    4520                 :       5607 :   nbitpos = lbitpos & ~ (nbitsize - 1);
    4521                 :       5607 :   lbitpos -= nbitpos;
    4522                 :       5607 :   if (nbitsize == lbitsize)
    4523                 :            :     return 0;
    4524                 :            : 
    4525                 :       5490 :   if (lreversep ? !BYTES_BIG_ENDIAN : BYTES_BIG_ENDIAN)
    4526                 :         53 :     lbitpos = nbitsize - lbitsize - lbitpos;
    4527                 :            : 
    4528                 :            :   /* Make the mask to be used against the extracted field.  */
    4529                 :       5490 :   mask = build_int_cst_type (unsigned_type, -1);
    4530                 :       5490 :   mask = const_binop (LSHIFT_EXPR, mask, size_int (nbitsize - lbitsize));
    4531                 :       5490 :   mask = const_binop (RSHIFT_EXPR, mask,
    4532                 :       5490 :                       size_int (nbitsize - lbitsize - lbitpos));
    4533                 :            : 
    4534                 :       5490 :   if (! const_p)
    4535                 :            :     {
    4536                 :       3009 :       if (nbitpos < 0)
    4537                 :            :         return 0;
    4538                 :            : 
    4539                 :            :       /* If not comparing with constant, just rework the comparison
    4540                 :            :          and return.  */
    4541                 :       3009 :       tree t1 = make_bit_field_ref (loc, linner, lhs, unsigned_type,
    4542                 :            :                                     nbitsize, nbitpos, 1, lreversep);
    4543                 :       3009 :       t1 = fold_build2_loc (loc, BIT_AND_EXPR, unsigned_type, t1, mask);
    4544                 :       3009 :       tree t2 = make_bit_field_ref (loc, rinner, rhs, unsigned_type,
    4545                 :            :                                     nbitsize, nbitpos, 1, rreversep);
    4546                 :       3009 :       t2 = fold_build2_loc (loc, BIT_AND_EXPR, unsigned_type, t2, mask);
    4547                 :       3009 :       return fold_build2_loc (loc, code, compare_type, t1, t2);
    4548                 :            :     }
    4549                 :            : 
    4550                 :            :   /* Otherwise, we are handling the constant case.  See if the constant is too
    4551                 :            :      big for the field.  Warn and return a tree for 0 (false) if so.  We do
    4552                 :            :      this not only for its own sake, but to avoid having to test for this
    4553                 :            :      error case below.  If we didn't, we might generate wrong code.
    4554                 :            : 
    4555                 :            :      For unsigned fields, the constant shifted right by the field length should
    4556                 :            :      be all zero.  For signed fields, the high-order bits should agree with
    4557                 :            :      the sign bit.  */
    4558                 :            : 
    4559                 :       2481 :   if (lunsignedp)
    4560                 :            :     {
    4561                 :       3668 :       if (wi::lrshift (wi::to_wide (rhs), lbitsize) != 0)
    4562                 :            :         {
    4563                 :          0 :           warning (0, "comparison is always %d due to width of bit-field",
    4564                 :            :                    code == NE_EXPR);
    4565                 :          0 :           return constant_boolean_node (code == NE_EXPR, compare_type);
    4566                 :            :         }
    4567                 :            :     }
    4568                 :            :   else
    4569                 :            :     {
    4570                 :        647 :       wide_int tem = wi::arshift (wi::to_wide (rhs), lbitsize - 1);
    4571                 :       1466 :       if (tem != 0 && tem != -1)
    4572                 :            :         {
    4573                 :          0 :           warning (0, "comparison is always %d due to width of bit-field",
    4574                 :            :                    code == NE_EXPR);
    4575                 :          0 :           return constant_boolean_node (code == NE_EXPR, compare_type);
    4576                 :            :         }
    4577                 :            :     }
    4578                 :            : 
    4579                 :       2481 :   if (nbitpos < 0)
    4580                 :            :     return 0;
    4581                 :            : 
    4582                 :            :   /* Single-bit compares should always be against zero.  */
    4583                 :       2481 :   if (lbitsize == 1 && ! integer_zerop (rhs))
    4584                 :            :     {
    4585                 :        152 :       code = code == EQ_EXPR ? NE_EXPR : EQ_EXPR;
    4586                 :        152 :       rhs = build_int_cst (type, 0);
    4587                 :            :     }
    4588                 :            : 
    4589                 :            :   /* Make a new bitfield reference, shift the constant over the
    4590                 :            :      appropriate number of bits and mask it with the computed mask
    4591                 :            :      (in case this was a signed field).  If we changed it, make a new one.  */
    4592                 :       2481 :   lhs = make_bit_field_ref (loc, linner, lhs, unsigned_type,
    4593                 :            :                             nbitsize, nbitpos, 1, lreversep);
    4594                 :            : 
    4595                 :       2481 :   rhs = const_binop (BIT_AND_EXPR,
    4596                 :            :                      const_binop (LSHIFT_EXPR,
    4597                 :            :                                   fold_convert_loc (loc, unsigned_type, rhs),
    4598                 :            :                                   size_int (lbitpos)),
    4599                 :            :                      mask);
    4600                 :            : 
    4601                 :       2481 :   lhs = build2_loc (loc, code, compare_type,
    4602                 :            :                     build2 (BIT_AND_EXPR, unsigned_type, lhs, mask), rhs);
    4603                 :            :   return lhs;
    4604                 :            : }
    4605                 :            : 
    4606                 :            : /* Subroutine for fold_truth_andor_1: decode a field reference.
    4607                 :            : 
    4608                 :            :    If EXP is a comparison reference, we return the innermost reference.
    4609                 :            : 
    4610                 :            :    *PBITSIZE is set to the number of bits in the reference, *PBITPOS is
    4611                 :            :    set to the starting bit number.
    4612                 :            : 
    4613                 :            :    If the innermost field can be completely contained in a mode-sized
    4614                 :            :    unit, *PMODE is set to that mode.  Otherwise, it is set to VOIDmode.
    4615                 :            : 
    4616                 :            :    *PVOLATILEP is set to 1 if the any expression encountered is volatile;
    4617                 :            :    otherwise it is not changed.
    4618                 :            : 
    4619                 :            :    *PUNSIGNEDP is set to the signedness of the field.
    4620                 :            : 
    4621                 :            :    *PREVERSEP is set to the storage order of the field.
    4622                 :            : 
    4623                 :            :    *PMASK is set to the mask used.  This is either contained in a
    4624                 :            :    BIT_AND_EXPR or derived from the width of the field.
    4625                 :            : 
    4626                 :            :    *PAND_MASK is set to the mask found in a BIT_AND_EXPR, if any.
    4627                 :            : 
    4628                 :            :    Return 0 if this is not a component reference or is one that we can't
    4629                 :            :    do anything with.  */
    4630                 :            : 
    4631                 :            : static tree
    4632                 :    6838290 : decode_field_reference (location_t loc, tree *exp_, HOST_WIDE_INT *pbitsize,
    4633                 :            :                         HOST_WIDE_INT *pbitpos, machine_mode *pmode,
    4634                 :            :                         int *punsignedp, int *preversep, int *pvolatilep,
    4635                 :            :                         tree *pmask, tree *pand_mask)
    4636                 :            : {
    4637                 :    6838290 :   tree exp = *exp_;
    4638                 :    6838290 :   tree outer_type = 0;
    4639                 :    6838290 :   tree and_mask = 0;
    4640                 :    6838290 :   tree mask, inner, offset;
    4641                 :    6838290 :   tree unsigned_type;
    4642                 :    6838290 :   unsigned int precision;
    4643                 :            : 
    4644                 :            :   /* All the optimizations using this function assume integer fields.
    4645                 :            :      There are problems with FP fields since the type_for_size call
    4646                 :            :      below can fail for, e.g., XFmode.  */
    4647                 :    6838290 :   if (! INTEGRAL_TYPE_P (TREE_TYPE (exp)))
    4648                 :            :     return NULL_TREE;
    4649                 :            : 
    4650                 :            :   /* We are interested in the bare arrangement of bits, so strip everything
    4651                 :            :      that doesn't affect the machine mode.  However, record the type of the
    4652                 :            :      outermost expression if it may matter below.  */
    4653                 :    5083940 :   if (CONVERT_EXPR_P (exp)
    4654                 :    5000940 :       || TREE_CODE (exp) == NON_LVALUE_EXPR)
    4655                 :      83097 :     outer_type = TREE_TYPE (exp);
    4656                 :    5083940 :   STRIP_NOPS (exp);
    4657                 :            : 
    4658                 :    5083940 :   if (TREE_CODE (exp) == BIT_AND_EXPR)
    4659                 :            :     {
    4660                 :     905086 :       and_mask = TREE_OPERAND (exp, 1);
    4661                 :     905086 :       exp = TREE_OPERAND (exp, 0);
    4662                 :     905086 :       STRIP_NOPS (exp); STRIP_NOPS (and_mask);
    4663                 :     905086 :       if (TREE_CODE (and_mask) != INTEGER_CST)
    4664                 :            :         return NULL_TREE;
    4665                 :            :     }
    4666                 :            : 
    4667                 :    5081880 :   poly_int64 poly_bitsize, poly_bitpos;
    4668                 :    5081880 :   inner = get_inner_reference (exp, &poly_bitsize, &poly_bitpos, &offset,
    4669                 :            :                                pmode, punsignedp, preversep, pvolatilep);
    4670                 :    5081880 :   if ((inner == exp && and_mask == 0)
    4671                 :     958187 :       || !poly_bitsize.is_constant (pbitsize)
    4672                 :     958187 :       || !poly_bitpos.is_constant (pbitpos)
    4673                 :     958187 :       || *pbitsize < 0
    4674                 :     958187 :       || offset != 0
    4675                 :     950544 :       || TREE_CODE (inner) == PLACEHOLDER_EXPR
    4676                 :            :       /* Reject out-of-bound accesses (PR79731).  */
    4677                 :    6032430 :       || (! AGGREGATE_TYPE_P (TREE_TYPE (inner))
    4678                 :     901393 :           && compare_tree_int (TYPE_SIZE (TREE_TYPE (inner)),
    4679                 :     901393 :                                *pbitpos + *pbitsize) < 0))
    4680                 :    4131380 :     return NULL_TREE;
    4681                 :            : 
    4682                 :     950502 :   unsigned_type = lang_hooks.types.type_for_size (*pbitsize, 1);
    4683                 :     950502 :   if (unsigned_type == NULL_TREE)
    4684                 :            :     return NULL_TREE;
    4685                 :            : 
    4686                 :     950496 :   *exp_ = exp;
    4687                 :            : 
    4688                 :            :   /* If the number of bits in the reference is the same as the bitsize of
    4689                 :            :      the outer type, then the outer type gives the signedness. Otherwise
    4690                 :            :      (in case of a small bitfield) the signedness is unchanged.  */
    4691                 :     950496 :   if (outer_type && *pbitsize == TYPE_PRECISION (outer_type))
    4692                 :        267 :     *punsignedp = TYPE_UNSIGNED (outer_type);
    4693                 :            : 
    4694                 :            :   /* Compute the mask to access the bitfield.  */
    4695                 :     950496 :   precision = TYPE_PRECISION (unsigned_type);
    4696                 :            : 
    4697                 :     950496 :   mask = build_int_cst_type (unsigned_type, -1);
    4698                 :            : 
    4699                 :     950496 :   mask = const_binop (LSHIFT_EXPR, mask, size_int (precision - *pbitsize));
    4700                 :     950496 :   mask = const_binop (RSHIFT_EXPR, mask, size_int (precision - *pbitsize));
    4701                 :            : 
    4702                 :            :   /* Merge it with the mask we found in the BIT_AND_EXPR, if any.  */
    4703                 :     950496 :   if (and_mask != 0)
    4704                 :     902881 :     mask = fold_build2_loc (loc, BIT_AND_EXPR, unsigned_type,
    4705                 :            :                         fold_convert_loc (loc, unsigned_type, and_mask), mask);
    4706                 :            : 
    4707                 :     950496 :   *pmask = mask;
    4708                 :     950496 :   *pand_mask = and_mask;
    4709                 :     950496 :   return inner;
    4710                 :            : }
    4711                 :            : 
    4712                 :            : /* Return nonzero if MASK represents a mask of SIZE ones in the low-order
    4713                 :            :    bit positions and MASK is SIGNED.  */
    4714                 :            : 
    4715                 :            : static bool
    4716                 :       2324 : all_ones_mask_p (const_tree mask, unsigned int size)
    4717                 :            : {
    4718                 :       2324 :   tree type = TREE_TYPE (mask);
    4719                 :       2324 :   unsigned int precision = TYPE_PRECISION (type);
    4720                 :            : 
    4721                 :            :   /* If this function returns true when the type of the mask is
    4722                 :            :      UNSIGNED, then there will be errors.  In particular see
    4723                 :            :      gcc.c-torture/execute/990326-1.c.  There does not appear to be
    4724                 :            :      any documentation paper trail as to why this is so.  But the pre
    4725                 :            :      wide-int worked with that restriction and it has been preserved
    4726                 :            :      here.  */
    4727                 :       2324 :   if (size > precision || TYPE_SIGN (type) == UNSIGNED)
    4728                 :            :     return false;
    4729                 :            : 
    4730                 :          0 :   return wi::mask (size, false, precision) == wi::to_wide (mask);
    4731                 :            : }
    4732                 :            : 
    4733                 :            : /* Subroutine for fold: determine if VAL is the INTEGER_CONST that
    4734                 :            :    represents the sign bit of EXP's type.  If EXP represents a sign
    4735                 :            :    or zero extension, also test VAL against the unextended type.
    4736                 :            :    The return value is the (sub)expression whose sign bit is VAL,
    4737                 :            :    or NULL_TREE otherwise.  */
    4738                 :            : 
    4739                 :            : tree
    4740                 :       7910 : sign_bit_p (tree exp, const_tree val)
    4741                 :            : {
    4742                 :       7910 :   int width;
    4743                 :       7910 :   tree t;
    4744                 :            : 
    4745                 :            :   /* Tree EXP must have an integral type.  */
    4746                 :       7910 :   t = TREE_TYPE (exp);
    4747                 :       7910 :   if (! INTEGRAL_TYPE_P (t))
    4748                 :            :     return NULL_TREE;
    4749                 :            : 
    4750                 :            :   /* Tree VAL must be an integer constant.  */
    4751                 :       5922 :   if (TREE_CODE (val) != INTEGER_CST
    4752                 :      10576 :       || TREE_OVERFLOW (val))
    4753                 :            :     return NULL_TREE;
    4754                 :            : 
    4755                 :       4654 :   width = TYPE_PRECISION (t);
    4756                 :       4654 :   if (wi::only_sign_bit_p (wi::to_wide (val), width))
    4757                 :            :     return exp;
    4758                 :            : 
    4759                 :            :   /* Handle extension from a narrower type.  */
    4760                 :       4556 :   if (TREE_CODE (exp) == NOP_EXPR
    4761                 :       4556 :       && TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp, 0))) < width)
    4762                 :          0 :     return sign_bit_p (TREE_OPERAND (exp, 0), val);
    4763                 :            : 
    4764                 :            :   return NULL_TREE;
    4765                 :            : }
    4766                 :            : 
    4767                 :            : /* Subroutine for fold_truth_andor_1: determine if an operand is simple enough
    4768                 :            :    to be evaluated unconditionally.  */
    4769                 :            : 
    4770                 :            : static bool
    4771                 :   37428700 : simple_operand_p (const_tree exp)
    4772                 :            : {
    4773                 :            :   /* Strip any conversions that don't change the machine mode.  */
    4774                 :   37428700 :   STRIP_NOPS (exp);
    4775                 :            : 
    4776                 :   37428700 :   return (CONSTANT_CLASS_P (exp)
    4777                 :   26406800 :           || TREE_CODE (exp) == SSA_NAME
    4778                 :   43797900 :           || (DECL_P (exp)
    4779                 :            :               && ! TREE_ADDRESSABLE (exp)
    4780                 :    1251700 :               && ! TREE_THIS_VOLATILE (exp)
    4781                 :    1238780 :               && ! DECL_NONLOCAL (exp)
    4782                 :            :               /* Don't regard global variables as simple.  They may be
    4783                 :            :                  allocated in ways unknown to the compiler (shared memory,
    4784                 :            :                  #pragma weak, etc).  */
    4785                 :    1237520 :               && ! TREE_PUBLIC (exp)
    4786                 :    1225320 :               && ! DECL_EXTERNAL (exp)
    4787                 :            :               /* Weakrefs are not safe to be read, since they can be NULL.
    4788                 :            :                  They are !TREE_PUBLIC && !DECL_EXTERNAL but still
    4789                 :            :                  have DECL_WEAK flag set.  */
    4790                 :    2190700 :               && (! VAR_OR_FUNCTION_DECL_P (exp) || ! DECL_WEAK (exp))
    4791                 :            :               /* Loading a static variable is unduly expensive, but global
    4792                 :            :                  registers aren't expensive.  */
    4793                 :    1226500 :               && (! TREE_STATIC (exp) || DECL_REGISTER (exp))));
    4794                 :            : }
    4795                 :            : 
    4796                 :            : /* Subroutine for fold_truth_andor: determine if an operand is simple enough
    4797                 :            :    to be evaluated unconditionally.
    4798                 :            :    I addition to simple_operand_p, we assume that comparisons, conversions,
    4799                 :            :    and logic-not operations are simple, if their operands are simple, too.  */
    4800                 :            : 
    4801                 :            : static bool
    4802                 :    1186030 : simple_operand_p_2 (tree exp)
    4803                 :            : {
    4804                 :    1199320 :   enum tree_code code;
    4805                 :            : 
    4806                 :    1199320 :   if (TREE_SIDE_EFFECTS (exp) || generic_expr_could_trap_p (exp))
    4807                 :     797967 :     return false;
    4808                 :            : 
    4809                 :     402034 :   while (CONVERT_EXPR_P (exp))
    4810                 :        676 :     exp = TREE_OPERAND (exp, 0);
    4811                 :            : 
    4812                 :     401358 :   code = TREE_CODE (exp);
    4813                 :            : 
    4814                 :     401358 :   if (TREE_CODE_CLASS (code) == tcc_comparison)
    4815                 :     336449 :     return (simple_operand_p (TREE_OPERAND (exp, 0))
    4816                 :     336449 :             && simple_operand_p (TREE_OPERAND (exp, 1)));
    4817                 :            : 
    4818                 :      64909 :   if (code == TRUTH_NOT_EXPR)
    4819                 :      13292 :       return simple_operand_p_2 (TREE_OPERAND (exp, 0));
    4820                 :            : 
    4821                 :      51617 :   return simple_operand_p (exp);
    4822                 :            : }
    4823                 :            : 
    4824                 :            : 
    4825                 :            : /* The following functions are subroutines to fold_range_test and allow it to
    4826                 :            :    try to change a logical combination of comparisons into a range test.
    4827                 :            : 
    4828                 :            :    For example, both
    4829                 :            :         X == 2 || X == 3 || X == 4 || X == 5
    4830                 :            :    and
    4831                 :            :         X >= 2 && X <= 5
    4832                 :            :    are converted to
    4833                 :            :         (unsigned) (X - 2) <= 3
    4834                 :            : 
    4835                 :            :    We describe each set of comparisons as being either inside or outside
    4836                 :            :    a range, using a variable named like IN_P, and then describe the
    4837                 :            :    range with a lower and upper bound.  If one of the bounds is omitted,
    4838                 :            :    it represents either the highest or lowest value of the type.
    4839                 :            : 
    4840                 :            :    In the comments below, we represent a range by two numbers in brackets
    4841                 :            :    preceded by a "+" to designate being inside that range, or a "-" to
    4842                 :            :    designate being outside that range, so the condition can be inverted by
    4843                 :            :    flipping the prefix.  An omitted bound is represented by a "-".  For
    4844                 :            :    example, "- [-, 10]" means being outside the range starting at the lowest
    4845                 :            :    possible value and ending at 10, in other words, being greater than 10.
    4846                 :            :    The range "+ [-, -]" is always true and hence the range "- [-, -]" is
    4847                 :            :    always false.
    4848                 :            : 
    4849                 :            :    We set up things so that the missing bounds are handled in a consistent
    4850                 :            :    manner so neither a missing bound nor "true" and "false" need to be
    4851                 :            :    handled using a special case.  */
    4852                 :            : 
    4853                 :            : /* Return the result of applying CODE to ARG0 and ARG1, but handle the case
    4854                 :            :    of ARG0 and/or ARG1 being omitted, meaning an unlimited range. UPPER0_P
    4855                 :            :    and UPPER1_P are nonzero if the respective argument is an upper bound
    4856                 :            :    and zero for a lower.  TYPE, if nonzero, is the type of the result; it
    4857                 :            :    must be specified for a comparison.  ARG1 will be converted to ARG0's
    4858                 :            :    type if both are specified.  */
    4859                 :            : 
    4860                 :            : static tree
    4861                 :    6839830 : range_binop (enum tree_code code, tree type, tree arg0, int upper0_p,
    4862                 :            :              tree arg1, int upper1_p)
    4863                 :            : {
    4864                 :    6839830 :   tree tem;
    4865                 :    6839830 :   int result;
    4866                 :    6839830 :   int sgn0, sgn1;
    4867                 :            : 
    4868                 :            :   /* If neither arg represents infinity, do the normal operation.
    4869                 :            :      Else, if not a comparison, return infinity.  Else handle the special
    4870                 :            :      comparison rules. Note that most of the cases below won't occur, but
    4871                 :            :      are handled for consistency.  */
    4872                 :            : 
    4873                 :    6839830 :   if (arg0 != 0 && arg1 != 0)
    4874                 :            :     {
    4875                 :    4638270 :       tem = fold_build2 (code, type != 0 ? type : TREE_TYPE (arg0),
    4876                 :            :                          arg0, fold_convert (TREE_TYPE (arg0), arg1));
    4877                 :    3723100 :       STRIP_NOPS (tem);
    4878                 :    3723100 :       return TREE_CODE (tem) == INTEGER_CST ? tem : 0;
    4879                 :            :     }
    4880                 :            : 
    4881                 :    3116730 :   if (TREE_CODE_CLASS (code) != tcc_comparison)
    4882                 :            :     return 0;
    4883                 :            : 
    4884                 :            :   /* Set SGN[01] to -1 if ARG[01] is a lower bound, 1 for upper, and 0
    4885                 :            :      for neither.  In real maths, we cannot assume open ended ranges are
    4886                 :            :      the same. But, this is computer arithmetic, where numbers are finite.
    4887                 :            :      We can therefore make the transformation of any unbounded range with
    4888                 :            :      the value Z, Z being greater than any representable number. This permits
    4889                 :            :      us to treat unbounded ranges as equal.  */
    4890                 :    3112360 :   sgn0 = arg0 != 0 ? 0 : (upper0_p ? 1 : -1);
    4891                 :    3112360 :   sgn1 = arg1 != 0 ? 0 : (upper1_p ? 1 : -1);
    4892                 :    3112360 :   switch (code)
    4893                 :            :     {
    4894                 :    1430620 :     case EQ_EXPR:
    4895                 :    1430620 :       result = sgn0 == sgn1;
    4896                 :    1430620 :       break;
    4897                 :          0 :     case NE_EXPR:
    4898                 :          0 :       result = sgn0 != sgn1;
    4899                 :          0 :       break;
    4900                 :     145809 :     case LT_EXPR:
    4901                 :     145809 :       result = sgn0 < sgn1;
    4902                 :     145809 :       break;
    4903                 :     700153 :     case LE_EXPR:
    4904                 :     700153 :       result = sgn0 <= sgn1;
    4905                 :     700153 :       break;
    4906                 :     835783 :     case GT_EXPR:
    4907                 :     835783 :       result = sgn0 > sgn1;
    4908                 :     835783 :       break;
    4909                 :          0 :     case GE_EXPR:
    4910                 :          0 :       result = sgn0 >= sgn1;
    4911                 :          0 :       break;
    4912                 :          0 :     default:
    4913                 :          0 :       gcc_unreachable ();
    4914                 :            :     }
    4915                 :            : 
    4916                 :    3112360 :   return constant_boolean_node (result, type);
    4917                 :            : }
    4918                 :            : 
    4919                 :            : /* Helper routine for make_range.  Perform one step for it, return
    4920                 :            :    new expression if the loop should continue or NULL_TREE if it should
    4921                 :            :    stop.  */
    4922                 :            : 
    4923                 :            : tree
    4924                 :   28549100 : make_range_step (location_t loc, enum tree_code code, tree arg0, tree arg1,
    4925                 :            :                  tree exp_type, tree *p_low, tree *p_high, int *p_in_p,
    4926                 :            :                  bool *strict_overflow_p)
    4927                 :            : {
    4928                 :   28549100 :   tree arg0_type = TREE_TYPE (arg0);
    4929                 :   28549100 :   tree n_low, n_high, low = *p_low, high = *p_high;
    4930                 :   28549100 :   int in_p = *p_in_p, n_in_p;
    4931                 :            : 
    4932                 :   28549100 :   switch (code)
    4933                 :            :     {
    4934                 :     757346 :     case TRUTH_NOT_EXPR:
    4935                 :            :       /* We can only do something if the range is testing for zero.  */
    4936                 :     757346 :       if (low == NULL_TREE || high == NULL_TREE
    4937                 :     757346 :           || ! integer_zerop (low) || ! integer_zerop (high))
    4938                 :          0 :         return NULL_TREE;
    4939                 :     757346 :       *p_in_p = ! in_p;
    4940                 :     757346 :       return arg0;
    4941                 :            : 
    4942                 :   24025300 :     case EQ_EXPR: case NE_EXPR:
    4943                 :   24025300 :     case LT_EXPR: case LE_EXPR: case GE_EXPR: case GT_EXPR:
    4944                 :            :       /* We can only do something if the range is testing for zero
    4945                 :            :          and if the second operand is an integer constant.  Note that
    4946                 :            :          saying something is "in" the range we make is done by
    4947                 :            :          complementing IN_P since it will set in the initial case of
    4948                 :            :          being not equal to zero; "out" is leaving it alone.  */
    4949                 :   24025300 :       if (low == NULL_TREE || high == NULL_TREE
    4950                 :   24025300 :           || ! integer_zerop (low) || ! integer_zerop (high)
    4951                 :   48050500 :           || TREE_CODE (arg1) != INTEGER_CST)
    4952                 :    9185120 :         return NULL_TREE;
    4953                 :            : 
    4954                 :   14840100 :       switch (code)
    4955                 :            :         {
    4956                 :            :         case NE_EXPR:  /* - [c, c]  */
    4957                 :            :           low = high = arg1;
    4958                 :            :           break;
    4959                 :    3768190 :         case EQ_EXPR:  /* + [c, c]  */
    4960                 :    3768190 :           in_p = ! in_p, low = high = arg1;
    4961                 :    3768190 :           break;
    4962                 :    1142260 :         case GT_EXPR:  /* - [-, c] */
    4963                 :    1142260 :           low = 0, high = arg1;
    4964                 :    1142260 :           break;
    4965                 :     585341 :         case GE_EXPR:  /* + [c, -] */
    4966                 :     585341 :           in_p = ! in_p, low = arg1, high = 0;
    4967                 :     585341 :           break;
    4968                 :    3363920 :         case LT_EXPR:  /* - [c, -] */
    4969                 :    3363920 :           low = arg1, high = 0;
    4970                 :    3363920 :           break;
    4971                 :    2343920 :         case LE_EXPR:  /* + [-, c] */
    4972                 :    2343920 :           in_p = ! in_p, low = 0, high = arg1;
    4973                 :    2343920 :           break;
    4974                 :          0 :         default:
    4975                 :          0 :           gcc_unreachable ();
    4976                 :            :         }
    4977                 :            : 
    4978                 :            :       /* If this is an unsigned comparison, we also know that EXP is
    4979                 :            :          greater than or equal to zero.  We base the range tests we make
    4980                 :            :          on that fact, so we record it here so we can parse existing
    4981                 :            :          range tests.  We test arg0_type since often the return type
    4982                 :            :          of, e.g. EQ_EXPR, is boolean.  */
    4983                 :   14840100 :       if (TYPE_UNSIGNED (arg0_type) && (low == 0 || high == 0))
    4984                 :            :         {
    4985                 :     465586 :           if (! merge_ranges (&n_in_p, &n_low, &n_high,
    4986                 :            :                               in_p, low, high, 1,
    4987                 :     465586 :                               build_int_cst (arg0_type, 0),
    4988                 :            :                               NULL_TREE))
    4989                 :            :             return NULL_TREE;
    4990                 :            : 
    4991                 :     465586 :           in_p = n_in_p, low = n_low, high = n_high;
    4992                 :            : 
    4993                 :            :           /* If the high bound is missing, but we have a nonzero low
    4994                 :            :              bound, reverse the range so it goes from zero to the low bound
    4995                 :            :              minus 1.  */
    4996                 :     465586 :           if (high == 0 && low && ! integer_zerop (low))
    4997                 :            :             {
    4998                 :     246201 :               in_p = ! in_p;
    4999                 :     246201 :               high = range_binop (MINUS_EXPR, NULL_TREE, low, 0,
    5000                 :     246201 :                                   build_int_cst (TREE_TYPE (low), 1), 0);
    5001                 :     246201 :               low = build_int_cst (arg0_type, 0);
    5002                 :            :             }
    5003                 :            :         }
    5004                 :            : 
    5005                 :   14840100 :       *p_low = low;
    5006                 :   14840100 :       *p_high = high;
    5007                 :   14840100 :       *p_in_p = in_p;
    5008                 :   14840100 :       return arg0;
    5009                 :            : 
    5010                 :        149 :     case NEGATE_EXPR:
    5011                 :            :       /* If flag_wrapv and ARG0_TYPE is signed, make sure
    5012                 :            :          low and high are non-NULL, then normalize will DTRT.  */
    5013                 :        149 :       if (!TYPE_UNSIGNED (arg0_type)
    5014                 :        149 :           && !TYPE_OVERFLOW_UNDEFINED (arg0_type))
    5015                 :            :         {
    5016                 :         57 :           if (low == NULL_TREE)
    5017                 :         12 :             low = TYPE_MIN_VALUE (arg0_type);
    5018                 :         57 :           if (high == NULL_TREE)
    5019                 :         45 :             high = TYPE_MAX_VALUE (arg0_type);
    5020                 :            :         }
    5021                 :            : 
    5022                 :            :       /* (-x) IN [a,b] -> x in [-b, -a]  */
    5023                 :        149 :       n_low = range_binop (MINUS_EXPR, exp_type,
    5024                 :        149 :                            build_int_cst (exp_type, 0),
    5025                 :            :                            0, high, 1);
    5026                 :        149 :       n_high = range_binop (MINUS_EXPR, exp_type,
    5027                 :        149 :                             build_int_cst (exp_type, 0),
    5028                 :            :                             0, low, 0);
    5029                 :        149 :       if (n_high != 0 && TREE_OVERFLOW (n_high))
    5030                 :            :         return NULL_TREE;
    5031                 :        137 :       goto normalize;
    5032                 :            : 
    5033                 :          0 :     case BIT_NOT_EXPR:
    5034                 :            :       /* ~ X -> -X - 1  */
    5035                 :          0 :       return build2_loc (loc, MINUS_EXPR, exp_type, negate_expr (arg0),
    5036                 :          0 :                          build_int_cst (exp_type, 1));
    5037                 :            : 
    5038                 :     408097 :     case PLUS_EXPR:
    5039                 :     408097 :     case MINUS_EXPR:
    5040                 :     408097 :       if (TREE_CODE (arg1) != INTEGER_CST)
    5041                 :            :         return NULL_TREE;
    5042                 :            : 
    5043                 :            :       /* If flag_wrapv and ARG0_TYPE is signed, then we cannot
    5044                 :            :          move a constant to the other side.  */
    5045                 :     344767 :       if (!TYPE_UNSIGNED (arg0_type)
    5046                 :     344767 :           && !TYPE_OVERFLOW_UNDEFINED (arg0_type))
    5047                 :            :         return NULL_TREE;
    5048                 :            : 
    5049                 :            :       /* If EXP is signed, any overflow in the computation is undefined,
    5050                 :            :          so we don't worry about it so long as our computations on
    5051                 :            :          the bounds don't overflow.  For unsigned, overflow is defined
    5052                 :            :          and this is exactly the right thing.  */
    5053                 :     335167 :       n_low = range_binop (code == MINUS_EXPR ? PLUS_EXPR : MINUS_EXPR,
    5054                 :            :                            arg0_type, low, 0, arg1, 0);
    5055                 :     167683 :       n_high = range_binop (code == MINUS_EXPR ? PLUS_EXPR : MINUS_EXPR,
    5056                 :            :                             arg0_type, high, 1, arg1, 0);
    5057                 :     166689 :       if ((n_low != 0 && TREE_OVERFLOW (n_low))
    5058                 :     334366 :           || (n_high != 0 && TREE_OVERFLOW (n_high)))
    5059                 :          6 :         return NULL_TREE;
    5060                 :            : 
    5061                 :     167677 :       if (TYPE_OVERFLOW_UNDEFINED (arg0_type))
    5062                 :       7233 :         *strict_overflow_p = true;
    5063                 :            : 
    5064                 :          0 :       normalize:
    5065                 :            :         /* Check for an unsigned range which has wrapped around the maximum
    5066                 :            :            value thus making n_high < n_low, and normalize it.  */
    5067                 :     167814 :         if (n_low && n_high && tree_int_cst_lt (n_high, n_low))
    5068                 :            :           {
    5069                 :      84401 :             low = range_binop (PLUS_EXPR, arg0_type, n_high, 0,
    5070                 :      84401 :                                build_int_cst (TREE_TYPE (n_high), 1), 0);
    5071                 :      84401 :             high = range_binop (MINUS_EXPR, arg0_type, n_low, 0,
    5072                 :      84401 :                                 build_int_cst (TREE_TYPE (n_low), 1), 0);
    5073                 :            : 
    5074                 :            :             /* If the range is of the form +/- [ x+1, x ], we won't
    5075                 :            :                be able to normalize it.  But then, it represents the
    5076                 :            :                whole range or the empty set, so make it
    5077                 :            :                +/- [ -, - ].  */
    5078                 :      84401 :             if (tree_int_cst_equal (n_low, low)
    5079                 :      84401 :                 && tree_int_cst_equal (n_high, high))
    5080                 :            :               low = high = 0;
    5081                 :            :             else
    5082                 :      84401 :               in_p = ! in_p;
    5083                 :            :           }
    5084                 :            :         else
    5085                 :      83413 :           low = n_low, high = n_high;
    5086                 :            : 
    5087                 :     167814 :         *p_low = low;
    5088                 :     167814 :         *p_high = high;
    5089                 :     167814 :         *p_in_p = in_p;
    5090                 :     167814 :         return arg0;
    5091                 :            : 
    5092                 :     949481 :     CASE_CONVERT:
    5093                 :     949481 :     case NON_LVALUE_EXPR:
    5094                 :     949481 :       if (TYPE_PRECISION (arg0_type) > TYPE_PRECISION (exp_type))
    5095                 :            :         return NULL_TREE;
    5096                 :            : 
    5097                 :     520199 :       if (! INTEGRAL_TYPE_P (arg0_type)
    5098                 :     501472 :           || (low != 0 && ! int_fits_type_p (low, arg0_type))
    5099                 :     437170 :           || (high != 0 && ! int_fits_type_p (high, arg0_type)))
    5100                 :            :         return NULL_TREE;
    5101                 :            : 
    5102                 :     422076 :       n_low = low, n_high = high;
    5103                 :            : 
    5104                 :     422076 :       if (n_low != 0)
    5105                 :     360643 :         n_low = fold_convert_loc (loc, arg0_type, n_low);
    5106                 :            : 
    5107                 :     422076 :       if (n_high != 0)
    5108                 :     369053 :         n_high = fold_convert_loc (loc, arg0_type, n_high);
    5109                 :            : 
    5110                 :            :       /* If we're converting arg0 from an unsigned type, to exp,
    5111                 :            :          a signed type,  we will be doing the comparison as unsigned.
    5112                 :            :          The tests above have already verified that LOW and HIGH
    5113                 :            :          are both positive.
    5114                 :            : 
    5115                 :            :          So we have to ensure that we will handle large unsigned
    5116                 :            :          values the same way that the current signed bounds treat
    5117                 :            :          negative values.  */
    5118                 :            : 
    5119                 :     580347 :       if (!TYPE_UNSIGNED (exp_type) && TYPE_UNSIGNED (arg0_type))
    5120                 :            :         {
    5121                 :     147810 :           tree high_positive;
    5122                 :     147810 :           tree equiv_type;
    5123                 :            :           /* For fixed-point modes, we need to pass the saturating flag
    5124                 :            :              as the 2nd parameter.  */
    5125                 :    1182480 :           if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (arg0_type)))
    5126                 :          0 :             equiv_type
    5127                 :          0 :               = lang_hooks.types.type_for_mode (TYPE_MODE (arg0_type),
    5128                 :          0 :                                                 TYPE_SATURATING (arg0_type));
    5129                 :            :           else
    5130                 :     147810 :             equiv_type
    5131                 :     147810 :               = lang_hooks.types.type_for_mode (TYPE_MODE (arg0_type), 1);
    5132                 :            : 
    5133                 :            :           /* A range without an upper bound is, naturally, unbounded.
    5134                 :            :              Since convert would have cropped a very large value, use
    5135                 :            :              the max value for the destination type.  */
    5136                 :     147810 :           high_positive
    5137                 :     147810 :             = TYPE_MAX_VALUE (equiv_type) ? TYPE_MAX_VALUE (equiv_type)
    5138                 :          0 :               : TYPE_MAX_VALUE (arg0_type);
    5139                 :            : 
    5140                 :     147810 :           if (TYPE_PRECISION (exp_type) == TYPE_PRECISION (arg0_type))
    5141                 :     132729 :             high_positive = fold_build2_loc (loc, RSHIFT_EXPR, arg0_type,
    5142                 :            :                                              fold_convert_loc (loc, arg0_type,
    5143                 :            :                                                                high_positive),
    5144                 :     132729 :                                              build_int_cst (arg0_type, 1));
    5145                 :            : 
    5146                 :            :           /* If the low bound is specified, "and" the range with the
    5147                 :            :              range for which the original unsigned value will be
    5148                 :            :              positive.  */
    5149                 :     147810 :           if (low != 0)
    5150                 :            :             {
    5151                 :      88156 :               if (! merge_ranges (&n_in_p, &n_low, &n_high, 1, n_low, n_high,
    5152                 :            :                                   1, fold_convert_loc (loc, arg0_type,
    5153                 :            :                                                        integer_zero_node),
    5154                 :            :                                   high_positive))
    5155                 :            :                 return NULL_TREE;
    5156                 :            : 
    5157                 :      88156 :               in_p = (n_in_p == in_p);
    5158                 :            :             }
    5159                 :            :           else
    5160                 :            :             {
    5161                 :            :               /* Otherwise, "or" the range with the range of the input
    5162                 :            :                  that will be interpreted as negative.  */
    5163                 :      59654 :               if (! merge_ranges (&n_in_p, &n_low, &n_high, 0, n_low, n_high,
    5164                 :            :                                   1, fold_convert_loc (loc, arg0_type,
    5165                 :            :                                                        integer_zero_node),
    5166                 :            :                                   high_positive))
    5167                 :            :                 return NULL_TREE;
    5168                 :            : 
    5169                 :      59654 :               in_p = (in_p != n_in_p);
    5170                 :            :             }
    5171                 :            :         }
    5172                 :            : 
    5173                 :     422076 :       *p_low = n_low;
    5174                 :     422076 :       *p_high = n_high;
    5175                 :     422076 :       *p_in_p = in_p;
    5176                 :     422076 :       return arg0;
    5177                 :            : 
    5178                 :            :     default:
    5179                 :            :       return NULL_TREE;
    5180                 :            :     }
    5181                 :            : }
    5182                 :            : 
    5183                 :            : /* Given EXP, a logical expression, set the range it is testing into
    5184                 :            :    variables denoted by PIN_P, PLOW, and PHIGH.  Return the expression
    5185                 :            :    actually being tested.  *PLOW and *PHIGH will be made of the same
    5186                 :            :    type as the returned expression.  If EXP is not a comparison, we
    5187                 :            :    will most likely not be returning a useful value and range.  Set
    5188                 :            :    *STRICT_OVERFLOW_P to true if the return value is only valid
    5189                 :            :    because signed overflow is undefined; otherwise, do not change
    5190                 :            :    *STRICT_OVERFLOW_P.  */
    5191                 :            : 
    5192                 :            : tree
    5193                 :   25487500 : make_range (tree exp, int *pin_p, tree *plow, tree *phigh,
    5194                 :            :             bool *strict_overflow_p)
    5195                 :            : {
    5196                 :   25487500 :   enum tree_code code;
    5197                 :   25487500 :   tree arg0, arg1 = NULL_TREE;
    5198                 :   25487500 :   tree exp_type, nexp;
    5199                 :   25487500 :   int in_p;
    5200                 :   25487500 :   tree low, high;
    5201                 :   25487500 :   location_t loc = EXPR_LOCATION (exp);
    5202                 :            : 
    5203                 :            :   /* Start with simply saying "EXP != 0" and then look at the code of EXP
    5204                 :            :      and see if we can refine the range.  Some of the cases below may not
    5205                 :            :      happen, but it doesn't seem worth worrying about this.  We "continue"
    5206                 :            :      the outer loop when we've changed something; otherwise we "break"
    5207                 :            :      the switch, which will "break" the while.  */
    5208                 :            : 
    5209                 :   25487500 :   in_p = 0;
    5210                 :   25487500 :   low = high = build_int_cst (TREE_TYPE (exp), 0);
    5211                 :            : 
    5212                 :   41216100 :   while (1)
    5213                 :            :     {
    5214                 :   41216100 :       code = TREE_CODE (exp);
    5215                 :   41216100 :       exp_type = TREE_TYPE (exp);
    5216                 :   41216100 :       arg0 = NULL_TREE;
    5217                 :            : 
    5218                 :   41216100 :       if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)))
    5219                 :            :         {
    5220                 :   27699600 :           if (TREE_OPERAND_LENGTH (exp) > 0)
    5221                 :   27699600 :             arg0 = TREE_OPERAND (exp, 0);
    5222                 :   27699600 :           if (TREE_CODE_CLASS (code) == tcc_binary
    5223                 :   27699600 :               || TREE_CODE_CLASS (code) == tcc_comparison
    5224                 :   27699600 :               || (TREE_CODE_CLASS (code) == tcc_expression
    5225                 :    1002420 :                   && TREE_OPERAND_LENGTH (exp) > 1))
    5226                 :   25525200 :             arg1 = TREE_OPERAND (exp, 1);
    5227                 :            :         }
    5228                 :   27699600 :       if (arg0 == NULL_TREE)
    5229                 :            :         break;
    5230                 :            : 
    5231                 :   27699600 :       nexp = make_range_step (loc, code, arg0, arg1, exp_type, &low,
    5232                 :            :                               &high, &in_p, strict_overflow_p);
    5233                 :   27699600 :       if (nexp == NULL_TREE)
    5234                 :            :         break;
    5235                 :            :       exp = nexp;
    5236                 :            :     }
    5237                 :            : 
    5238                 :            :   /* If EXP is a constant, we can evaluate whether this is true or false.  */
    5239                 :   25487500 :   if (TREE_CODE (exp) == INTEGER_CST)
    5240                 :            :     {
    5241                 :       8842 :       in_p = in_p == (integer_onep (range_binop (GE_EXPR, integer_type_node,
    5242                 :            :                                                  exp, 0, low, 0))
    5243                 :       8842 :                       && integer_onep (range_binop (LE_EXPR, integer_type_node,
    5244                 :            :                                                     exp, 1, high, 1)));
    5245                 :       8842 :       low = high = 0;
    5246                 :       8842 :       exp = 0;
    5247                 :            :     }
    5248                 :            : 
    5249                 :   25487500 :   *pin_p = in_p, *plow = low, *phigh = high;
    5250                 :   25487500 :   return exp;
    5251                 :            : }
    5252                 :            : 
    5253                 :            : /* Returns TRUE if [LOW, HIGH] range check can be optimized to
    5254                 :            :    a bitwise check i.e. when
    5255                 :            :      LOW  == 0xXX...X00...0
    5256                 :            :      HIGH == 0xXX...X11...1
    5257                 :            :    Return corresponding mask in MASK and stem in VALUE.  */
    5258                 :            : 
    5259                 :            : static bool
    5260                 :        199 : maskable_range_p (const_tree low, const_tree high, tree type, tree *mask,
    5261                 :            :                   tree *value)
    5262                 :            : {
    5263                 :        199 :   if (TREE_CODE (low) != INTEGER_CST
    5264                 :        199 :       || TREE_CODE (high) != INTEGER_CST)
    5265                 :            :     return false;
    5266                 :            : 
    5267                 :        199 :   unsigned prec = TYPE_PRECISION (type);
    5268                 :        199 :   wide_int lo = wi::to_wide (low, prec);
    5269                 :        199 :   wide_int hi = wi::to_wide (high, prec);
    5270                 :            : 
    5271                 :        199 :   wide_int end_mask = lo ^ hi;
    5272                 :        199 :   if ((end_mask & (end_mask + 1)) != 0
    5273                 :        151 :       || (lo & end_mask) != 0)
    5274                 :        112 :     return false;
    5275                 :            : 
    5276                 :         87 :   wide_int stem_mask = ~end_mask;
    5277                 :         87 :   wide_int stem = lo & stem_mask;
    5278                 :         87 :   if (stem != (hi & stem_mask))
    5279                 :            :     return false;
    5280                 :            : 
    5281                 :         87 :   *mask = wide_int_to_tree (type, stem_mask);
    5282                 :         87 :   *value = wide_int_to_tree (type, stem);
    5283                 :            : 
    5284                 :         87 :   return true;
    5285                 :            : }
    5286                 :            : 
    5287                 :            : /* Helper routine for build_range_check and match.pd.  Return the type to
    5288                 :            :    perform the check or NULL if it shouldn't be optimized.  */
    5289                 :            : 
    5290                 :            : tree
    5291                 :     128226 : range_check_type (tree etype)
    5292                 :            : {
    5293                 :            :   /* First make sure that arithmetics in this type is valid, then make sure
    5294                 :            :      that it wraps around.  */
    5295                 :     128226 :   if (TREE_CODE (etype) == ENUMERAL_TYPE || TREE_CODE (etype) == BOOLEAN_TYPE)
    5296                 :       6360 :     etype = lang_hooks.types.type_for_size (TYPE_PRECISION (etype), 1);
    5297                 :            : 
    5298                 :     256267 :   if (TREE_CODE (etype) == INTEGER_TYPE && !TYPE_UNSIGNED (etype))
    5299                 :            :     {
    5300                 :      99473 :       tree utype, minv, maxv;
    5301                 :            : 
    5302                 :            :       /* Check if (unsigned) INT_MAX + 1 == (unsigned) INT_MIN
    5303                 :            :          for the type in question, as we rely on this here.  */
    5304                 :      99473 :       utype = unsigned_type_for (etype);
    5305                 :      99473 :       maxv = fold_convert (utype, TYPE_MAX_VALUE (etype));
    5306                 :      99473 :       maxv = range_binop (PLUS_EXPR, NULL_TREE, maxv, 1,
    5307                 :      99473 :                           build_int_cst (TREE_TYPE (maxv), 1), 1);
    5308                 :      99473 :       minv = fold_convert (utype, TYPE_MIN_VALUE (etype));
    5309                 :            : 
    5310                 :      99473 :       if (integer_zerop (range_binop (NE_EXPR, integer_type_node,
    5311                 :            :                                       minv, 1, maxv, 1)))
    5312                 :            :         etype = utype;
    5313                 :            :       else
    5314                 :          0 :         return NULL_TREE;
    5315                 :            :     }
    5316                 :      28753 :   else if (POINTER_TYPE_P (etype))
    5317                 :        185 :     etype = unsigned_type_for (etype);
    5318                 :            :   return etype;
    5319                 :            : }
    5320                 :            : 
    5321                 :            : /* Given a range, LOW, HIGH, and IN_P, an expression, EXP, and a result
    5322                 :            :    type, TYPE, return an expression to test if EXP is in (or out of, depending
    5323                 :            :    on IN_P) the range.  Return 0 if the test couldn't be created.  */
    5324                 :            : 
    5325                 :            : tree
    5326                 :     658400 : build_range_check (location_t loc, tree type, tree exp, int in_p,
    5327                 :            :                    tree low, tree high)
    5328                 :            : {
    5329                 :     658400 :   tree etype = TREE_TYPE (exp), mask, value;
    5330                 :            : 
    5331                 :            :   /* Disable this optimization for function pointer expressions
    5332                 :            :      on targets that require function pointer canonicalization.  */
    5333                 :     658400 :   if (targetm.have_canonicalize_funcptr_for_compare ()
    5334                 :          0 :       && POINTER_TYPE_P (etype)
    5335                 :     658400 :       && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (etype)))
    5336                 :            :     return NULL_TREE;
    5337                 :            : 
    5338                 :     658400 :   if (! in_p)
    5339                 :            :     {
    5340                 :     125874 :       value = build_range_check (loc, type, exp, 1, low, high);
    5341                 :     125874 :       if (value != 0)
    5342                 :     125874 :         return invert_truthvalue_loc (loc, value);
    5343                 :            : 
    5344                 :            :       return 0;
    5345                 :            :     }
    5346                 :            : 
    5347                 :     532526 :   if (low == 0 && high == 0)
    5348                 :      49532 :     return omit_one_operand_loc (loc, type, build_int_cst (type, 1), exp);
    5349                 :            : 
    5350                 :     482994 :   if (low == 0)
    5351                 :     185399 :     return fold_build2_loc (loc, LE_EXPR, type, exp,
    5352                 :     185399 :                             fold_convert_loc (loc, etype, high));
    5353                 :            : 
    5354                 :     297595 :   if (high == 0)
    5355                 :      33315 :     return fold_build2_loc (loc, GE_EXPR, type, exp,
    5356                 :      33315 :                             fold_convert_loc (loc, etype, low));
    5357                 :            : 
    5358                 :     264280 :   if (operand_equal_p (low, high, 0))
    5359                 :      35092 :     return fold_build2_loc (loc, EQ_EXPR, type, exp,
    5360                 :      35092 :                             fold_convert_loc (loc, etype, low));
    5361                 :            : 
    5362                 :     229188 :   if (TREE_CODE (exp) == BIT_AND_EXPR
    5363                 :     229188 :       && maskable_range_p (low, high, etype, &mask, &value))
    5364                 :         87 :     return fold_build2_loc (loc, EQ_EXPR, type,
    5365                 :            :                             fold_build2_loc (loc, BIT_AND_EXPR, etype,
    5366                 :            :                                              exp, mask),
    5367                 :         87 :                             value);
    5368                 :            : 
    5369                 :     229101 :   if (integer_zerop (low))
    5370                 :            :     {
    5371                 :     137377 :       if (! TYPE_UNSIGNED (etype))
    5372                 :            :         {
    5373                 :      41238 :           etype = unsigned_type_for (etype);
    5374                 :      41238 :           high = fold_convert_loc (loc, etype, high);
    5375                 :      41238 :           exp = fold_convert_loc (loc, etype, exp);
    5376                 :            :         }
    5377                 :     137377 :       return build_range_check (loc, type, exp, 1, 0, high);
    5378                 :            :     }
    5379                 :            : 
    5380                 :            :   /* Optimize (c>=1) && (c<=127) into (signed char)c > 0.  */
    5381                 :      91724 :   if (integer_onep (low) && TREE_CODE (high) == INTEGER_CST)
    5382                 :            :     {
    5383                 :      24617 :       int prec = TYPE_PRECISION (etype);
    5384                 :            : 
    5385                 :      24617 :       if (wi::mask <widest_int> (prec - 1, false) == wi::to_widest (high))
    5386                 :            :         {
    5387                 :        162 :           if (TYPE_UNSIGNED (etype))
    5388                 :            :             {
    5389                 :        155 :               tree signed_etype = signed_type_for (etype);
    5390                 :        155 :               if (TYPE_PRECISION (signed_etype) != TYPE_PRECISION (etype))
    5391                 :          0 :                 etype
    5392                 :          0 :                   = build_nonstandard_integer_type (TYPE_PRECISION (etype), 0);
    5393                 :            :               else
    5394                 :            :                 etype = signed_etype;
    5395                 :        155 :               exp = fold_convert_loc (loc, etype, exp);
    5396                 :            :             }
    5397                 :        162 :           return fold_build2_loc (loc, GT_EXPR, type, exp,
    5398                 :        162 :                                   build_int_cst (etype, 0));
    5399                 :            :         }
    5400                 :            :     }
    5401                 :            : 
    5402                 :            :   /* Optimize (c>=low) && (c<=high) into (c-low>=0) && (c-low<=high-low).
    5403                 :            :      This requires wrap-around arithmetics for the type of the expression.  */
    5404                 :      91562 :   etype = range_check_type (etype);
    5405                 :      91562 :   if (etype == NULL_TREE)
    5406                 :            :     return NULL_TREE;
    5407                 :            : 
    5408                 :      91562 :   high = fold_convert_loc (loc, etype, high);
    5409                 :      91562 :   low = fold_convert_loc (loc, etype, low);
    5410                 :      91562 :   exp = fold_convert_loc (loc, etype, exp);
    5411                 :            : 
    5412                 :      91562 :   value = const_binop (MINUS_EXPR, high, low);
    5413                 :            : 
    5414                 :      91562 :   if (value != 0 && !TREE_OVERFLOW (value))
    5415                 :      91562 :     return build_range_check (loc, type,
    5416                 :            :                               fold_build2_loc (loc, MINUS_EXPR, etype, exp, low),
    5417                 :      91562 :                               1, build_int_cst (etype, 0), value);
    5418                 :            : 
    5419                 :            :   return 0;
    5420                 :            : }
    5421                 :            : 
    5422                 :            : /* Return the predecessor of VAL in its type, handling the infinite case.  */
    5423                 :            : 
    5424                 :            : static tree
    5425                 :     118352 : range_predecessor (tree val)
    5426                 :            : {
    5427                 :     118352 :   tree type = TREE_TYPE (val);
    5428                 :            : 
    5429                 :     118352 :   if (INTEGRAL_TYPE_P (type)
    5430                 :     118352 :       && operand_equal_p (val, TYPE_MIN_VALUE (type), 0))
    5431                 :            :     return 0;
    5432                 :            :   else
    5433                 :     118352 :     return range_binop (MINUS_EXPR, NULL_TREE, val, 0,
    5434                 :     118352 :                         build_int_cst (TREE_TYPE (val), 1), 0);
    5435                 :            : }
    5436                 :            : 
    5437                 :            : /* Return the successor of VAL in its type, handling the infinite case.  */
    5438                 :            : 
    5439                 :            : static tree
    5440                 :     450976 : range_successor (tree val)
    5441                 :            : {
    5442                 :     450976 :   tree type = TREE_TYPE (val);
    5443                 :            : 
    5444                 :     450976 :   if (INTEGRAL_TYPE_P (type)
    5445                 :     450976 :       && operand_equal_p (val, TYPE_MAX_VALUE (type), 0))
    5446                 :            :     return 0;
    5447                 :            :   else
    5448                 :     450976 :     return range_binop (PLUS_EXPR, NULL_TREE, val, 0,
    5449                 :     450976 :                         build_int_cst (TREE_TYPE (val), 1), 0);
    5450                 :            : }
    5451                 :            : 
    5452                 :            : /* Given two ranges, see if we can merge them into one.  Return 1 if we
    5453                 :            :    can, 0 if we can't.  Set the output range into the specified parameters.  */
    5454                 :            : 
    5455                 :            : bool
    5456                 :    1066370 : merge_ranges (int *pin_p, tree *plow, tree *phigh, int in0_p, tree low0,
    5457                 :            :               tree high0, int in1_p, tree low1, tree high1)
    5458                 :            : {
    5459                 :    1066370 :   int no_overlap;
    5460                 :    1066370 :   int subset;
    5461                 :    1066370 :   int temp;
    5462                 :    1066370 :   tree tem;
    5463                 :    1066370 :   int in_p;
    5464                 :    1066370 :   tree low, high;
    5465                 :    1066370 :   int lowequal = ((low0 == 0 && low1 == 0)
    5466                 :    1066370 :                   || integer_onep (range_binop (EQ_EXPR, integer_type_node,
    5467                 :    1066370 :                                                 low0, 0, low1, 0)));
    5468                 :    1066370 :   int highequal = ((high0 == 0 && high1 == 0)
    5469                 :    1066370 :                    || integer_onep (range_binop (EQ_EXPR, integer_type_node,
    5470                 :    1066370 :                                                  high0, 1, high1, 1)));
    5471                 :            : 
    5472                 :            :   /* Make range 0 be the range that starts first, or ends last if they
    5473                 :            :      start at the same value.  Swap them if it isn't.  */
    5474                 :    1066370 :   if (integer_onep (range_binop (GT_EXPR, integer_type_node,
    5475                 :            :                                  low0, 0, low1, 0))
    5476                 :    1066370 :       || (lowequal
    5477                 :     214690 :           && integer_onep (range_binop (GT_EXPR, integer_type_node,
    5478                 :            :                                         high1, 1, high0, 1))))
    5479                 :            :     {
    5480                 :    1066370 :       temp = in0_p, in0_p = in1_p, in1_p = temp;
    5481                 :            :       tem = low0, low0 = low1, low1 = tem;
    5482                 :    1066370 :       tem = high0, high0 = high1, high1 = tem;
    5483                 :            :     }
    5484                 :            : 
    5485                 :            :   /* If the second range is != high1 where high1 is the type maximum of
    5486                 :            :      the type, try first merging with < high1 range.  */
    5487                 :    1066370 :   if (low1
    5488                 :    1066370 :       && high1
    5489                 :     377834 :       && TREE_CODE (low1) == INTEGER_CST
    5490                 :     377834 :       && (TREE_CODE (TREE_TYPE (low1)) == INTEGER_TYPE
    5491                 :      16525 :           || (TREE_CODE (TREE_TYPE (low1)) == ENUMERAL_TYPE
    5492                 :       8260 :               && known_eq (TYPE_PRECISION (TREE_TYPE (low1)),
    5493                 :            :                            GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (low1))))))
    5494                 :    1431810 :       && operand_equal_p (low1, high1, 0))
    5495                 :            :     {
    5496                 :     211438 :       if (tree_int_cst_equal (low1, TYPE_MAX_VALUE (TREE_TYPE (low1)))
    5497                 :     211438 :           && merge_ranges (pin_p, plow, phigh, in0_p, low0, high0,
    5498                 :            :                            !in1_p, NULL_TREE, range_predecessor (low1)))
    5499                 :            :         return true;
    5500                 :            :       /* Similarly for the second range != low1 where low1 is the type minimum
    5501                 :            :          of the type, try first merging with > low1 range.  */
    5502                 :     146878 :       if (tree_int_cst_equal (low1, TYPE_MIN_VALUE (TREE_TYPE (low1)))
    5503                 :     146878 :           && merge_ranges (pin_p, plow, phigh, in0_p, low0, high0,
    5504                 :            :                            !in1_p, range_successor (low1), NULL_TREE))
    5505                 :            :         return true;
    5506                 :            :     }
    5507                 :            : 
    5508                 :            :   /* Now flag two cases, whether the ranges are disjoint or whether the
    5509                 :            :      second range is totally subsumed in the first.  Note that the tests
    5510                 :            :      below are simplified by the ones above.  */
    5511                 :     954831 :   no_overlap = integer_onep (range_binop (LT_EXPR, integer_type_node,
    5512                 :            :                                           high0, 1, low1, 0));
    5513                 :     954831 :   subset = integer_onep (range_binop (LE_EXPR, integer_type_node,
    5514                 :            :                                       high1, 1, high0, 1));
    5515                 :            : 
    5516                 :            :   /* We now have four cases, depending on whether we are including or
    5517                 :            :      excluding the two ranges.  */
    5518                 :     954831 :   if (in0_p && in1_p)
    5519                 :            :     {
    5520                 :            :       /* If they don't overlap, the result is false.  If the second range
    5521                 :            :          is a subset it is the result.  Otherwise, the range is from the start
    5522                 :            :          of the second to the end of the first.  */
    5523                 :     380812 :       if (no_overlap)
    5524                 :            :         in_p = 0, low = high = 0;
    5525                 :     380418 :       else if (subset)
    5526                 :            :         in_p = 1, low = low1, high = high1;
    5527                 :            :       else
    5528                 :     315480 :         in_p = 1, low = low1, high = high0;
    5529                 :            :     }
    5530                 :            : 
    5531                 :     574019 :   else if (in0_p && ! in1_p)
    5532                 :            :     {
    5533                 :            :       /* If they don't overlap, the result is the first range.  If they are
    5534                 :            :          equal, the result is false.  If the second range is a subset of the
    5535                 :            :          first, and the ranges begin at the same place, we go from just after
    5536                 :            :          the end of the second range to the end of the first.  If the second
    5537                 :            :          range is not a subset of the first, or if it is a subset and both
    5538                 :            :          ranges end at the same place, the range starts at the start of the
    5539                 :            :          first range and ends just before the second range.
    5540                 :            :          Otherwise, we can't describe this as a single range.  */
    5541                 :      92490 :       if (no_overlap)
    5542                 :            :         in_p = 1, low = low0, high = high0;
    5543                 :      91254 :       else if (lowequal && highequal)
    5544                 :            :         in_p = 0, low = high = 0;
    5545                 :      90815 :       else if (subset && lowequal)
    5546                 :            :         {
    5547                 :      30591 :           low = range_successor (high1);
    5548                 :      30591 :           high = high0;
    5549                 :      30591 :           in_p = 1;
    5550                 :      30591 :           if (low == 0)
    5551                 :            :             {
    5552                 :            :               /* We are in the weird situation where high0 > high1 but
    5553                 :            :                  high1 has no successor.  Punt.  */
    5554                 :            :               return 0;
    5555                 :            :             }
    5556                 :            :         }
    5557                 :      60224 :       else if (! subset || highequal)
    5558                 :            :         {
    5559                 :      46050 :           low = low0;
    5560                 :      46050 :           high = range_predecessor (low1);
    5561                 :      46050 :           in_p = 1;
    5562                 :      46050 :           if (high == 0)
    5563                 :            :             {
    5564                 :            :               /* low0 < low1 but low1 has no predecessor.  Punt.  */
    5565                 :            :               return 0;
    5566                 :            :             }
    5567                 :            :         }
    5568                 :            :       else
    5569                 :            :         return 0;
    5570                 :            :     }
    5571                 :            : 
    5572                 :     481529 :   else if (! in0_p && in1_p)
    5573                 :            :     {
    5574                 :            :       /* If they don't overlap, the result is the second range.  If the second
    5575                 :            :          is a subset of the first, the result is false.  Otherwise,
    5576                 :            :          the range starts just after the first range and ends at the
    5577                 :            :          end of the second.  */
    5578                 :     374809 :       if (no_overlap)
    5579                 :            :         in_p = 1, low = low1, high = high1;
    5580                 :     372641 :       else if (subset || highequal)
    5581                 :            :         in_p = 0, low = high = 0;
    5582                 :            :       else
    5583                 :            :         {
    5584                 :     325178 :           low = range_successor (high0);
    5585                 :     325178 :           high = high1;
    5586                 :     325178 :           in_p = 1;
    5587                 :     325178 :           if (low == 0)
    5588                 :            :             {
    5589                 :            :               /* high1 > high0 but high0 has no successor.  Punt.  */
    5590                 :            :               return 0;
    5591                 :            :             }
    5592                 :            :         }
    5593                 :            :     }
    5594                 :            : 
    5595                 :            :   else
    5596                 :            :     {
    5597                 :            :       /* The case where we are excluding both ranges.  Here the complex case
    5598                 :            :          is if they don't overlap.  In that case, the only time we have a
    5599                 :            :          range is if they are adjacent.  If the second is a subset of the
    5600                 :            :          first, the result is the first.  Otherwise, the range to exclude
    5601                 :            :          starts at the beginning of the first range and ends at the end of the
    5602                 :            :          second.  */
    5603                 :     106720 :       if (no_overlap)
    5604                 :            :         {
    5605                 :      47351 :           if (integer_onep (range_binop (EQ_EXPR, integer_type_node,
    5606                 :            :                                          range_successor (high0),
    5607                 :            :                                          1, low1, 0)))
    5608                 :            :             in_p = 0, low = low0, high = high1;
    5609                 :            :           else
    5610                 :            :             {
    5611                 :            :               /* Canonicalize - [min, x] into - [-, x].  */
    5612                 :      39468 :               if (low0 && TREE_CODE (low0) == INTEGER_CST)
    5613                 :      39219 :                 switch (TREE_CODE (TREE_TYPE (low0)))
    5614                 :            :                   {
    5615                 :       2190 :                   case ENUMERAL_TYPE:
    5616                 :       4380 :                     if (maybe_ne (TYPE_PRECISION (TREE_TYPE (low0)),
    5617                 :            :                                   GET_MODE_BITSIZE
    5618                 :       4380 :                                     (TYPE_MODE (TREE_TYPE (low0)))))
    5619                 :            :                       break;
    5620                 :            :                     /* FALLTHROUGH */
    5621                 :      39051 :                   case INTEGER_TYPE:
    5622                 :      78102 :                     if (tree_int_cst_equal (low0,
    5623                 :      39051 :                                             TYPE_MIN_VALUE (TREE_TYPE (low0))))
    5624                 :       2166 :                       low0 = 0;
    5625                 :            :                     break;
    5626                 :        168 :                   case POINTER_TYPE:
    5627                 :        168 :                     if (TYPE_UNSIGNED (TREE_TYPE (low0))
    5628                 :        168 :                         && integer_zerop (low0))
    5629                 :            :                       low0 = 0;
    5630                 :            :                     break;
    5631                 :            :                   default:
    5632                 :            :                     break;
    5633                 :            :                   }
    5634                 :            : 
    5635                 :            :               /* Canonicalize - [x, max] into - [x, -].  */
    5636                 :      39468 :               if (high1 && TREE_CODE (high1) == INTEGER_CST)
    5637                 :      39290 :                 switch (TREE_CODE (TREE_TYPE (high1)))
    5638                 :            :                   {
    5639                 :       2190 :                   case ENUMERAL_TYPE:
    5640                 :       4380 :                     if (maybe_ne (TYPE_PRECISION (TREE_TYPE (high1)),
    5641                 :            :                                   GET_MODE_BITSIZE
    5642                 :       4380 :                                     (TYPE_MODE (TREE_TYPE (high1)))))
    5643                 :            :                       break;
    5644                 :            :                     /* FALLTHROUGH */
    5645                 :      39122 :                   case INTEGER_TYPE:
    5646                 :      78244 :                     if (tree_int_cst_equal (high1,
    5647                 :      39122 :                                             TYPE_MAX_VALUE (TREE_TYPE (high1))))
    5648                 :       6890 :                       high1 = 0;
    5649                 :            :                     break;
    5650                 :        168 :                   case POINTER_TYPE:
    5651                 :        168 :                     if (TYPE_UNSIGNED (TREE_TYPE (high1))
    5652                 :        168 :                         && integer_zerop (range_binop (PLUS_EXPR, NULL_TREE,
    5653                 :            :                                                        high1, 1,
    5654                 :        168 :                                                        build_int_cst (TREE_TYPE (high1), 1),
    5655                 :        168 :                                                        1)))
    5656                 :            :                       high1 = 0;
    5657                 :            :                     break;
    5658                 :            :                   default:
    5659                 :            :                     break;
    5660                 :            :                   }
    5661                 :            : 
    5662                 :            :               /* The ranges might be also adjacent between the maximum and
    5663                 :            :                  minimum values of the given type.  For
    5664                 :            :                  - [{min,-}, x] and - [y, {max,-}] ranges where x + 1 < y
    5665                 :            :                  return + [x + 1, y - 1].  */
    5666                 :      39468 :               if (low0 == 0 && high1 == 0)
    5667                 :            :                 {
    5668                 :        879 :                   low = range_successor (high0);
    5669                 :        879 :                   high = range_predecessor (low1);
    5670                 :        879 :                   if (low == 0 || high == 0)
    5671                 :            :                     return 0;
    5672                 :            : 
    5673                 :            :                   in_p = 1;
    5674                 :            :                 }
    5675                 :            :               else
    5676                 :            :                 return 0;
    5677                 :            :             }
    5678                 :            :         }
    5679                 :      59369 :       else if (subset)
    5680                 :            :         in_p = 0, low = low0, high = high0;
    5681                 :            :       else
    5682                 :       1329 :         in_p = 0, low = low0, high = high1;
    5683                 :            :     }
    5684                 :            : 
    5685                 :     902068 :   *pin_p = in_p, *plow = low, *phigh = high;
    5686                 :     902068 :   return 1;
    5687                 :            : }
    5688                 :            : 
    5689                 :            : 
    5690                 :            : /* Subroutine of fold, looking inside expressions of the form
    5691                 :            :    A op B ? A : C, where ARG0, ARG1 and ARG2 are the three operands
    5692                 :            :    of the COND_EXPR.  This function is being used also to optimize
    5693                 :            :    A op B ? C : A, by reversing the comparison first.
    5694                 :            : 
    5695                 :            :    Return a folded expression whose code is not a COND_EXPR
    5696                 :            :    anymore, or NULL_TREE if no folding opportunity is found.  */
    5697                 :            : 
    5698                 :            : static tree
    5699                 :     279325 : fold_cond_expr_with_comparison (location_t loc, tree type,
    5700                 :            :                                 tree arg0, tree arg1, tree arg2)
    5701                 :            : {
    5702                 :     279325 :   enum tree_code comp_code = TREE_CODE (arg0);
    5703                 :     279325 :   tree arg00 = TREE_OPERAND (arg0, 0);
    5704                 :     279325 :   tree arg01 = TREE_OPERAND (arg0, 1);
    5705                 :     279325 :   tree arg1_type = TREE_TYPE (arg1);
    5706                 :     279325 :   tree tem;
    5707                 :            : 
    5708                 :     279325 :   STRIP_NOPS (arg1);
    5709                 :     279325 :   STRIP_NOPS (arg2);
    5710                 :            : 
    5711                 :            :   /* If we have A op 0 ? A : -A, consider applying the following
    5712                 :            :      transformations:
    5713                 :            : 
    5714                 :            :      A == 0? A : -A    same as -A
    5715                 :            :      A != 0? A : -A    same as A
    5716                 :            :      A >= 0? A : -A    same as abs (A)
    5717                 :            :      A > 0?  A : -A    same as abs (A)
    5718                 :            :      A <= 0? A : -A    same as -abs (A)
    5719                 :            :      A < 0?  A : -A    same as -abs (A)
    5720                 :            : 
    5721                 :            :      None of these transformations work for modes with signed
    5722                 :            :      zeros.  If A is +/-0, the first two transformations will
    5723                 :            :      change the sign of the result (from +0 to -0, or vice
    5724                 :            :      versa).  The last four will fix the sign of the result,
    5725                 :            :      even though the original expressions could be positive or
    5726                 :            :      negative, depending on the sign of A.
    5727                 :            : 
    5728                 :            :      Note that all these transformations are correct if A is
    5729                 :            :      NaN, since the two alternatives (A and -A) are also NaNs.  */
    5730                 :     279325 :   if (!HONOR_SIGNED_ZEROS (element_mode (type))
    5731                 :     279382 :       && (FLOAT_TYPE_P (TREE_TYPE (arg01))
    5732                 :     279325 :           ? real_zerop (arg01)
    5733                 :     278461 :           : integer_zerop (arg01))
    5734                 :     765754 :       && ((TREE_CODE (arg2) == NEGATE_EXPR
    5735                 :       4167 :            && operand_equal_p (TREE_OPERAND (arg2, 0), arg1, 0))
    5736                 :            :              /* In the case that A is of the form X-Y, '-A' (arg2) may
    5737                 :            :                 have already been folded to Y-X, check for that. */
    5738                 :     203011 :           || (TREE_CODE (arg1) == MINUS_EXPR
    5739                 :       1979 :               && TREE_CODE (arg2) == MINUS_EXPR
    5740                 :         10 :               && operand_equal_p (TREE_OPERAND (arg1, 0),
    5741                 :         10 :                                   TREE_OPERAND (arg2, 1), 0)
    5742                 :         10 :               && operand_equal_p (TREE_OPERAND (arg1, 1),
    5743                 :         10 :                                   TREE_OPERAND (arg2, 0), 0))))
    5744                 :       4103 :     switch (comp_code)
    5745                 :            :       {
    5746                 :          0 :       case EQ_EXPR:
    5747                 :          0 :       case UNEQ_EXPR:
    5748                 :          0 :         tem = fold_convert_loc (loc, arg1_type, arg1);
    5749                 :          0 :         return fold_convert_loc (loc, type, negate_expr (tem));
    5750                 :          0 :       case NE_EXPR:
    5751                 :          0 :       case LTGT_EXPR:
    5752                 :          0 :         return fold_convert_loc (loc, type, arg1);
    5753                 :          0 :       case UNGE_EXPR:
    5754                 :          0 :       case UNGT_EXPR:
    5755                 :          0 :         if (flag_trapping_math)
    5756                 :            :           break;
    5757                 :            :         /* Fall through.  */
    5758                 :       4103 :       case GE_EXPR:
    5759                 :       4103 :       case GT_EXPR:
    5760                 :       4103 :         if (TYPE_UNSIGNED (TREE_TYPE (arg1)))
    5761                 :            :           break;
    5762                 :       4059 :         tem = fold_build1_loc (loc, ABS_EXPR, TREE_TYPE (arg1), arg1);
    5763                 :       4059 :         return fold_convert_loc (loc, type, tem);
    5764                 :          0 :       case UNLE_EXPR:
    5765                 :          0 :       case UNLT_EXPR:
    5766                 :          0 :         if (flag_trapping_math)
    5767                 :            :           break;
    5768                 :            :         /* FALLTHRU */
    5769                 :          0 :       case LE_EXPR:
    5770                 :          0 :       case LT_EXPR:
    5771                 :          0 :         if (TYPE_UNSIGNED (TREE_TYPE (arg1)))
    5772                 :            :           break;
    5773                 :          0 :         tem = fold_build1_loc (loc, ABS_EXPR, TREE_TYPE (arg1), arg1);
    5774                 :          0 :         return negate_expr (fold_convert_loc (loc, type, tem));
    5775                 :          0 :       default:
    5776                 :          0 :         gcc_assert (TREE_CODE_CLASS (comp_code) == tcc_comparison);
    5777                 :            :         break;
    5778                 :            :       }
    5779                 :            : 
    5780                 :            :   /* A != 0 ? A : 0 is simply A, unless A is -0.  Likewise
    5781                 :            :      A == 0 ? A : 0 is always 0 unless A is -0.  Note that
    5782                 :            :      both transformations are correct when A is NaN: A != 0
    5783                 :            :      is then true, and A == 0 is false.  */
    5784                 :            : 
    5785                 :     275266 :   if (!HONOR_SIGNED_ZEROS (element_mode (type))
    5786                 :     275266 :       && integer_zerop (arg01) && integer_zerop (arg2))
    5787                 :            :     {
    5788                 :     170268 :       if (comp_code == NE_EXPR)
    5789                 :        189 :         return fold_convert_loc (loc, type, arg1);
    5790                 :     170079 :       else if (comp_code == EQ_EXPR)
    5791                 :         16 :         return build_zero_cst (type);
    5792                 :            :     }
    5793                 :            : 
    5794                 :            :   /* Try some transformations of A op B ? A : B.
    5795                 :            : 
    5796                 :            :      A == B? A : B    same as B
    5797                 :            :      A != B? A : B    same as A
    5798                 :            :      A >= B? A : B    same as max (A, B)
    5799                 :            :      A > B?  A : B    same as max (B, A)
    5800                 :            :      A <= B? A : B    same as min (A, B)
    5801                 :            :      A < B?  A : B    same as min (B, A)
    5802                 :            : 
    5803                 :            :      As above, these transformations don't work in the presence
    5804                 :            :      of signed zeros.  For example, if A and B are zeros of
    5805                 :            :      opposite sign, the first two transformations will change
    5806                 :            :      the sign of the result.  In the last four, the original
    5807                 :            :      expressions give different results for (A=+0, B=-0) and
    5808                 :            :      (A=-0, B=+0), but the transformed expressions do not.
    5809                 :            : 
    5810                 :            :      The first two transformations are correct if either A or B
    5811                 :            :      is a NaN.  In the first transformation, the condition will
    5812                 :            :      be false, and B will indeed be chosen.  In the case of the
    5813                 :            :      second transformation, the condition A != B will be true,
    5814                 :            :      and A will be chosen.
    5815                 :            : 
    5816                 :            :      The conversions to max() and min() are not correct if B is
    5817                 :            :      a number and A is not.  The conditions in the original
    5818                 :            :      expressions will be false, so all four give B.  The min()
    5819                 :            :      and max() versions would give a NaN instead.  */
    5820                 :     275061 :   if (!HONOR_SIGNED_ZEROS (element_mode (type))
    5821                 :     275061 :       && operand_equal_for_comparison_p (arg01, arg2)
    5822                 :            :       /* Avoid these transformations if the COND_EXPR may be used
    5823                 :            :          as an lvalue in the C++ front-end.  PR c++/19199.  */
    5824                 :     451737 :       && (in_gimple_form
    5825                 :      10727 :           || VECTOR_TYPE_P (type)
    5826                 :      10719 :           || (! lang_GNU_CXX ()
    5827                 :       9034 :               && strcmp (lang_hooks.name, "GNU Objective-C++") != 0)
    5828                 :       1685 :           || ! maybe_lvalue_p (arg1)
    5829                 :       1670 :           || ! maybe_lvalue_p (arg2)))
    5830                 :            :     {
    5831                 :     175383 :       tree comp_op0 = arg00;
    5832                 :     175383 :       tree comp_op1 = arg01;
    5833                 :     175383 :       tree comp_type = TREE_TYPE (comp_op0);
    5834                 :            : 
    5835                 :     175383 :       switch (comp_code)
    5836                 :            :         {
    5837                 :          0 :         case EQ_EXPR:
    5838                 :          0 :           return fold_convert_loc (loc, type, arg2);
    5839                 :          5 :         case NE_EXPR:
    5840                 :          5 :           return fold_convert_loc (loc, type, arg1);
    5841                 :       4864 :         case LE_EXPR:
    5842                 :       4864 :         case LT_EXPR:
    5843                 :       4864 :         case UNLE_EXPR:
    5844                 :       4864 :         case UNLT_EXPR:
    5845                 :            :           /* In C++ a ?: expression can be an lvalue, so put the
    5846                 :            :              operand which will be used if they are equal first
    5847                 :            :              so that we can convert this back to the
    5848                 :            :              corresponding COND_EXPR.  */
    5849                 :       4864 :           if (!HONOR_NANS (arg1))
    5850                 :            :             {
    5851                 :       4864 :               comp_op0 = fold_convert_loc (loc, comp_type, comp_op0);
    5852                 :       4864 :               comp_op1 = fold_convert_loc (loc, comp_type, comp_op1);
    5853                 :       9728 :               tem = (comp_code == LE_EXPR || comp_code == UNLE_EXPR)
    5854                 :       4864 :                     ? fold_build2_loc (loc, MIN_EXPR, comp_type, comp_op0, comp_op1)
    5855                 :       3699 :                     : fold_build2_loc (loc, MIN_EXPR, comp_type,
    5856                 :            :                                    comp_op1, comp_op0);
    5857                 :       4864 :               return fold_convert_loc (loc, type, tem);
    5858                 :            :             }
    5859                 :            :           break;
    5860                 :     170514 :         case GE_EXPR:
    5861                 :     170514 :         case GT_EXPR:
    5862                 :     170514 :         case UNGE_EXPR:
    5863                 :     170514 :         case UNGT_EXPR:
    5864                 :     170514 :           if (!HONOR_NANS (arg1))
    5865                 :            :             {
    5866                 :     170512 :               comp_op0 = fold_convert_loc (loc, comp_type, comp_op0);
    5867                 :     170512 :               comp_op1 = fold_convert_loc (loc, comp_type, comp_op1);
    5868                 :     341024 :               tem = (comp_code == GE_EXPR || comp_code == UNGE_EXPR)
    5869                 :     170512 :                     ? fold_build2_loc (loc, MAX_EXPR, comp_type, comp_op0, comp_op1)
    5870                 :       2527 :                     : fold_build2_loc (loc, MAX_EXPR, comp_type,
    5871                 :            :                                    comp_op1, comp_op0);
    5872                 :     170512 :               return fold_convert_loc (loc, type, tem);
    5873                 :            :             }
    5874                 :            :           break;
    5875                 :          0 :         case UNEQ_EXPR:
    5876                 :          0 :           if (!HONOR_NANS (arg1))
    5877                 :          0 :             return fold_convert_loc (loc, type, arg2);
    5878                 :            :           break;
    5879                 :          0 :         case LTGT_EXPR:
    5880                 :          0 :           if (!HONOR_NANS (arg1))
    5881                 :          0 :             return fold_convert_loc (loc, type, arg1);
    5882                 :            :           break;
    5883                 :          0 :         default:
    5884                 :          0 :           gcc_assert (TREE_CODE_CLASS (comp_code) == tcc_comparison);
    5885                 :            :           break;
    5886                 :            :         }
    5887                 :            :     }
    5888                 :            : 
    5889                 :            :   return NULL_TREE;
    5890                 :            : }
    5891                 :            : 
    5892                 :            : 
    5893                 :            : 
    5894                 :            : #ifndef LOGICAL_OP_NON_SHORT_CIRCUIT
    5895                 :            : #define LOGICAL_OP_NON_SHORT_CIRCUIT \
    5896                 :            :   (BRANCH_COST (optimize_function_for_speed_p (cfun), \
    5897                 :            :                 false) >= 2)
    5898                 :            : #endif
    5899                 :            : 
    5900                 :            : /* EXP is some logical combination of boolean tests.  See if we can
    5901                 :            :    merge it into some range test.  Return the new tree if so.  */
    5902                 :            : 
    5903                 :            : static tree
    5904                 :   12743100 : fold_range_test (location_t loc, enum tree_code code, tree type,
    5905                 :            :                  tree op0, tree op1)
    5906                 :            : {
    5907                 :   12743100 :   int or_op = (code == TRUTH_ORIF_EXPR
    5908                 :   12743100 :                || code == TRUTH_OR_EXPR);
    5909                 :   12743100 :   int in0_p, in1_p, in_p;
    5910                 :   12743100 :   tree low0, low1, low, high0, high1, high;
    5911                 :   12743100 :   bool strict_overflow_p = false;
    5912                 :   12743100 :   tree tem, lhs, rhs;
    5913                 :   12743100 :   const char * const warnmsg = G_("assuming signed overflow does not occur "
    5914                 :            :                                   "when simplifying range test");
    5915                 :            : 
    5916                 :   12743100 :   if (!INTEGRAL_TYPE_P (type))
    5917                 :            :     return 0;
    5918                 :            : 
    5919                 :   12743100 :   lhs = make_range (op0, &in0_p, &low0, &high0, &strict_overflow_p);
    5920                 :   12743100 :   rhs = make_range (op1, &in1_p, &low1, &high1, &strict_overflow_p);
    5921                 :            : 
    5922                 :            :   /* If this is an OR operation, invert both sides; we will invert
    5923                 :            :      again at the end.  */
    5924                 :   12743100 :   if (or_op)
    5925                 :    6450550 :     in0_p = ! in0_p, in1_p = ! in1_p;
    5926                 :            : 
    5927                 :            :   /* If both expressions are the same, if we can merge the ranges, and we
    5928                 :            :      can build the range test, return it or it inverted.  If one of the
    5929                 :            :      ranges is always true or always false, consider it to be the same
    5930                 :            :      expression as the other.  */
    5931                 :   12734300 :   if ((lhs == 0 || rhs == 0 || operand_equal_p (lhs, rhs, 0))
    5932                 :     307288 :       && merge_ranges (&in_p, &low, &high, in0_p, low0, high0,
    5933                 :            :                        in1_p, low1, high1)
    5934                 :   13021700 :       && (tem = (build_range_check (loc, type,
    5935                 :            :                                     lhs != 0 ? lhs
    5936                 :          0 :                                     : rhs != 0 ? rhs : integer_zero_node,
    5937                 :            :                                     in_p, low, high))) != 0)
    5938                 :            :     {
    5939                 :     278556 :       if (strict_overflow_p)
    5940                 :         91 :         fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_COMPARISON);
    5941                 :     278556 :       return or_op ? invert_truthvalue_loc (loc, tem) : tem;
    5942                 :            :     }
    5943                 :            : 
    5944                 :            :   /* On machines where the branch cost is expensive, if this is a
    5945                 :            :      short-circuited branch and the underlying object on both sides
    5946                 :            :      is the same, make a non-short-circuit operation.  */
    5947                 :   12464600 :   bool logical_op_non_short_circuit = LOGICAL_OP_NON_SHORT_CIRCUIT;
    5948                 :   12464600 :   if (param_logical_op_non_short_circuit != -1)
    5949                 :       4105 :     logical_op_non_short_circuit
    5950                 :       4105 :       = param_logical_op_non_short_circuit;
    5951                 :   12464600 :   if (logical_op_non_short_circuit
    5952                 :   12464500 :       && !flag_sanitize_coverage
    5953                 :   12464500 :       && lhs != 0 && rhs != 0
    5954                 :   12464300 :       && (code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR)
    5955                 :   13357800 :       && operand_equal_p (lhs, rhs, 0))
    5956                 :            :     {
    5957                 :            :       /* If simple enough, just rewrite.  Otherwise, make a SAVE_EXPR
    5958                 :            :          unless we are at top level or LHS contains a PLACEHOLDER_EXPR, in
    5959                 :            :          which cases we can't do this.  */
    5960                 :      10313 :       if (simple_operand_p (lhs))
    5961                 :       8202 :         return build2_loc (loc, code == TRUTH_ANDIF_EXPR
    5962                 :            :                            ? TRUTH_AND_EXPR : TRUTH_OR_EXPR,
    5963                 :            :                            type, op0, op1);
    5964                 :            : 
    5965                 :       2111 :       else if (!lang_hooks.decls.global_bindings_p ()
    5966                 :       3694 :                && !CONTAINS_PLACEHOLDER_P (lhs))
    5967                 :            :         {
    5968                 :       1583 :           tree common = save_expr (lhs);
    5969                 :            : 
    5970                 :       2112 :           if ((lhs = build_range_check (loc, type, common,
    5971                 :        529 :                                         or_op ? ! in0_p : in0_p,
    5972                 :            :                                         low0, high0)) != 0
    5973                 :       2112 :               && (rhs = build_range_check (loc, type, common,
    5974                 :        529 :                                            or_op ? ! in1_p : in1_p,
    5975                 :            :                                            low1, high1)) != 0)
    5976                 :            :             {
    5977                 :       1583 :               if (strict_overflow_p)
    5978                 :          0 :                 fold_overflow_warning (warnmsg,
    5979                 :            :                                        WARN_STRICT_OVERFLOW_COMPARISON);
    5980                 :       1583 :               return build2_loc (loc, code == TRUTH_ANDIF_EXPR
    5981                 :            :                                  ? TRUTH_AND_EXPR : TRUTH_OR_EXPR,
    5982                 :            :                                  type, lhs, rhs);
    5983                 :            :             }
    5984                 :            :         }
    5985                 :            :     }
    5986                 :            : 
    5987                 :            :   return 0;
    5988                 :            : }
    5989                 :            : 
    5990                 :            : /* Subroutine for fold_truth_andor_1: C is an INTEGER_CST interpreted as a P
    5991                 :            :    bit value.  Arrange things so the extra bits will be set to zero if and
    5992                 :            :    only if C is signed-extended to its full width.  If MASK is nonzero,
    5993                 :            :    it is an INTEGER_CST that should be AND'ed with the extra bits.  */
    5994                 :            : 
    5995                 :            : static tree
    5996                 :       4260 : unextend (tree c, int p, int unsignedp, tree mask)
    5997                 :            : {
    5998                 :       4260 :   tree type = TREE_TYPE (c);
    5999                 :       4260 :   int modesize = GET_MODE_BITSIZE (SCALAR_INT_TYPE_MODE (type));
    6000                 :       4260 :   tree temp;
    6001                 :            : 
    6002                 :       4260 :   if (p == modesize || unsignedp)
    6003                 :            :     return c;
    6004                 :            : 
    6005                 :            :   /* We work by getting just the sign bit into the low-order bit, then
    6006                 :            :      into the high-order bit, then sign-extend.  We then XOR that value
    6007                 :            :      with C.  */
    6008                 :        923 :   temp = build_int_cst (TREE_TYPE (c),
    6009                 :        923 :                         wi::extract_uhwi (wi::to_wide (c), p - 1, 1));
    6010                 :            : 
    6011                 :            :   /* We must use a signed type in order to get an arithmetic right shift.
    6012                 :            :      However, we must also avoid introducing accidental overflows, so that
    6013                 :            :      a subsequent call to integer_zerop will work.  Hence we must
    6014                 :            :      do the type conversion here.  At this point, the constant is either
    6015                 :            :      zero or one, and the conversion to a signed type can never overflow.
    6016                 :            :      We could get an overflow if this conversion is done anywhere else.  */
    6017                 :        923 :   if (TYPE_UNSIGNED (type))
    6018                 :        923 :     temp = fold_convert (signed_type_for (type), temp);
    6019                 :            : 
    6020                 :        923 :   temp = const_binop (LSHIFT_EXPR, temp, size_int (modesize - 1));
    6021                 :        923 :   temp = const_binop (RSHIFT_EXPR, temp, size_int (modesize - p - 1));
    6022                 :        923 :   if (mask != 0)
    6023                 :        176 :     temp = const_binop (BIT_AND_EXPR, temp,
    6024                 :         88 :                         fold_convert (TREE_TYPE (c), mask));
    6025                 :            :   /* If necessary, convert the type back to match the type of C.  */
    6026                 :        923 :   if (TYPE_UNSIGNED (type))
    6027                 :        923 :     temp = fold_convert (type, temp);
    6028                 :            : 
    6029                 :        923 :   return fold_convert (type, const_binop (BIT_XOR_EXPR, c, temp));
    6030                 :            : }
    6031                 :            : 
    6032                 :            : /* For an expression that has the form
    6033                 :            :      (A && B) || ~B
    6034                 :            :    or
    6035                 :            :      (A || B) && ~B,
    6036                 :            :    we can drop one of the inner expressions and simplify to
    6037                 :            :      A || ~B
    6038                 :            :    or
    6039                 :            :      A && ~B
    6040                 :            :    LOC is the location of the resulting expression.  OP is the inner 
    6041                 :            :    logical operation; the left-hand side in the examples above, while CMPOP
    6042                 :            :    is the right-hand side.  RHS_ONLY is used to prevent us from accidentally
    6043                 :            :    removing a condition that guards another, as in
    6044                 :            :      (A != NULL && A->...) || A == NULL
    6045                 :            :    which we must not transform.  If RHS_ONLY is true, only eliminate the
    6046                 :            :    right-most operand of the inner logical operation.  */
    6047                 :            : 
    6048                 :            : static tree
    6049                 :      36247 : merge_truthop_with_opposite_arm (location_t loc, tree op, tree cmpop,
    6050                 :            :                                  bool rhs_only)
    6051                 :            : {
    6052                 :      36247 :   tree type = TREE_TYPE (cmpop);
    6053                 :      36247 :   enum tree_code code = TREE_CODE (cmpop);
    6054                 :      36247 :   enum tree_code truthop_code = TREE_CODE (op);
    6055                 :      36247 :   tree lhs = TREE_OPERAND (op, 0);
    6056                 :      36247 :   tree rhs = TREE_OPERAND (op, 1);
    6057                 :      36247 :   tree orig_lhs = lhs, orig_rhs = rhs;
    6058                 :      36247 :   enum tree_code rhs_code = TREE_CODE (rhs);
    6059                 :      36247 :   enum tree_code lhs_code = TREE_CODE (lhs);
    6060                 :      36247 :   enum tree_code inv_code;
    6061                 :            : 
    6062                 :      50977 :   if (TREE_SIDE_EFFECTS (op) || TREE_SIDE_EFFECTS (cmpop))
    6063                 :            :     return NULL_TREE;
    6064                 :            : 
    6065                 :      14452 :   if (TREE_CODE_CLASS (code) != tcc_comparison)
    6066                 :            :     return NULL_TREE;
    6067                 :            : 
    6068                 :       9323 :   if (rhs_code == truthop_code)
    6069                 :            :     {
    6070                 :          2 :       tree newrhs = merge_truthop_with_opposite_arm (loc, rhs, cmpop, rhs_only);
    6071                 :          2 :       if (newrhs != NULL_TREE)
    6072                 :            :         {
    6073                 :          0 :           rhs = newrhs;
    6074                 :          0 :           rhs_code = TREE_CODE (rhs);
    6075                 :            :         }
    6076                 :            :     }
    6077                 :       9323 :   if (lhs_code == truthop_code && !rhs_only)
    6078                 :            :     {
    6079                 :        244 :       tree newlhs = merge_truthop_with_opposite_arm (loc, lhs, cmpop, false);
    6080                 :        244 :       if (newlhs != NULL_TREE)
    6081                 :            :         {
    6082                 :          0 :           lhs = newlhs;
    6083                 :          0 :           lhs_code = TREE_CODE (lhs);
    6084                 :            :         }
    6085                 :            :     }
    6086                 :            : 
    6087                 :       9323 :   inv_code = invert_tree_comparison (code, HONOR_NANS (type));
    6088                 :       9323 :   if (inv_code == rhs_code
    6089                 :       1019 :       && operand_equal_p (TREE_OPERAND (rhs, 0), TREE_OPERAND (cmpop, 0), 0)
    6090                 :       9708 :       && operand_equal_p (TREE_OPERAND (rhs, 1), TREE_OPERAND (cmpop, 1), 0))
    6091                 :            :     return lhs;
    6092                 :       9310 :   if (!rhs_only && inv_code == lhs_code
    6093                 :       2896 :       && operand_equal_p (TREE_OPERAND (lhs, 0), TREE_OPERAND (cmpop, 0), 0)
    6094                 :       9355 :       && operand_equal_p (TREE_OPERAND (lhs, 1), TREE_OPERAND (cmpop, 1), 0))
    6095                 :            :     return rhs;
    6096                 :       9266 :   if (rhs != orig_rhs || lhs != orig_lhs)
    6097                 :          0 :     return fold_build2_loc (loc, truthop_code, TREE_TYPE (cmpop),
    6098                 :          0 :                             lhs, rhs);
    6099                 :            :   return NULL_TREE;
    6100                 :            : }
    6101                 :            : 
    6102                 :            : /* Find ways of folding logical expressions of LHS and RHS:
    6103                 :            :    Try to merge two comparisons to the same innermost item.
    6104                 :            :    Look for range tests like "ch >= '0' && ch <= '9'".
    6105                 :            :    Look for combinations of simple terms on machines with expensive branches
    6106                 :            :    and evaluate the RHS unconditionally.
    6107                 :            : 
    6108                 :            :    For example, if we have p->a == 2 && p->b == 4 and we can make an
    6109                 :            :    object large enough to span both A and B, we can do this with a comparison
    6110                 :            :    against the object ANDed with the a mask.
    6111                 :            : 
    6112                 :            :    If we have p->a == q->a && p->b == q->b, we may be able to use bit masking
    6113                 :            :    operations to do this with one comparison.
    6114                 :            : 
    6115                 :            :    We check for both normal comparisons and the BIT_AND_EXPRs made this by
    6116                 :            :    function and the one above.
    6117                 :            : 
    6118                 :            :    CODE is the logical operation being done.  It can be TRUTH_ANDIF_EXPR,
    6119                 :            :    TRUTH_AND_EXPR, TRUTH_ORIF_EXPR, or TRUTH_OR_EXPR.
    6120                 :            : 
    6121                 :            :    TRUTH_TYPE is the type of the logical operand and LHS and RHS are its
    6122                 :            :    two operands.
    6123                 :            : 
    6124                 :            :    We return the simplified tree or 0 if no optimization is possible.  */
    6125                 :            : 
    6126                 :            : static tree
    6127                 :   12602400 : fold_truth_andor_1 (location_t loc, enum tree_code code, tree truth_type,
    6128                 :            :                     tree lhs, tree rhs)
    6129                 :            : {
    6130                 :            :   /* If this is the "or" of two comparisons, we can do something if
    6131                 :            :      the comparisons are NE_EXPR.  If this is the "and", we can do something
    6132                 :            :      if the comparisons are EQ_EXPR.  I.e.,
    6133                 :            :         (a->b == 2 && a->c == 4) can become (a->new == NEW).
    6134                 :            : 
    6135                 :            :      WANTED_CODE is this operation code.  For single bit fields, we can
    6136                 :            :      convert EQ_EXPR to NE_EXPR so we need not reject the "wrong"
    6137                 :            :      comparison for one-bit fields.  */
    6138                 :            : 
    6139                 :   12602400 :   enum tree_code wanted_code;
    6140                 :   12602400 :   enum tree_code lcode, rcode;
    6141                 :   12602400 :   tree ll_arg, lr_arg, rl_arg, rr_arg;
    6142                 :   12602400 :   tree ll_inner, lr_inner, rl_inner, rr_inner;
    6143                 :   12602400 :   HOST_WIDE_INT ll_bitsize, ll_bitpos, lr_bitsize, lr_bitpos;
    6144                 :   12602400 :   HOST_WIDE_INT rl_bitsize, rl_bitpos, rr_bitsize, rr_bitpos;
    6145                 :   12602400 :   HOST_WIDE_INT xll_bitpos, xlr_bitpos, xrl_bitpos, xrr_bitpos;
    6146                 :   12602400 :   HOST_WIDE_INT lnbitsize, lnbitpos, rnbitsize, rnbitpos;
    6147                 :   12602400 :   int ll_unsignedp, lr_unsignedp, rl_unsignedp, rr_unsignedp;
    6148                 :   12602400 :   int ll_reversep, lr_reversep, rl_reversep, rr_reversep;
    6149                 :   12602400 :   machine_mode ll_mode, lr_mode, rl_mode, rr_mode;
    6150                 :   12602400 :   scalar_int_mode lnmode, rnmode;
    6151                 :   12602400 :   tree ll_mask, lr_mask, rl_mask, rr_mask;
    6152                 :   12602400 :   tree ll_and_mask, lr_and_mask, rl_and_mask, rr_and_mask;
    6153                 :   12602400 :   tree l_const, r_const;
    6154                 :   12602400 :   tree lntype, rntype, result;
    6155                 :   12602400 :   HOST_WIDE_INT first_bit, end_bit;
    6156                 :   12602400 :   int volatilep;
    6157                 :            : 
    6158                 :            :   /* Start by getting the comparison codes.  Fail if anything is volatile.
    6159                 :            :      If one operand is a BIT_AND_EXPR with the constant one, treat it as if
    6160                 :            :      it were surrounded with a NE_EXPR.  */
    6161                 :            : 
    6162                 :   24860600 :   if (TREE_SIDE_EFFECTS (lhs) || TREE_SIDE_EFFECTS (rhs))
    6163                 :            :     return 0;
    6164                 :            : 
    6165                 :   12049400 :   lcode = TREE_CODE (lhs);
    6166                 :   12049400 :   rcode = TREE_CODE (rhs);
    6167                 :            : 
    6168                 :   12049400 :   if (lcode == BIT_AND_EXPR && integer_onep (TREE_OPERAND (lhs, 1)))
    6169                 :            :     {
    6170                 :          0 :       lhs = build2 (NE_EXPR, truth_type, lhs,
    6171                 :          0 :                     build_int_cst (TREE_TYPE (lhs), 0));
    6172                 :          0 :       lcode = NE_EXPR;
    6173                 :            :     }
    6174                 :            : 
    6175                 :   12049400 :   if (rcode == BIT_AND_EXPR && integer_onep (TREE_OPERAND (rhs, 1)))
    6176                 :            :     {
    6177                 :          0 :       rhs = build2 (NE_EXPR, truth_type, rhs,
    6178                 :          0 :                     build_int_cst (TREE_TYPE (rhs), 0));
    6179                 :          0 :       rcode = NE_EXPR;
    6180                 :            :     }
    6181                 :            : 
    6182                 :   12049400 :   if (TREE_CODE_CLASS (lcode) != tcc_comparison
    6183                 :   11152500 :       || TREE_CODE_CLASS (rcode) != tcc_comparison)
    6184                 :            :     return 0;
    6185                 :            : 
    6186                 :   10490200 :   ll_arg = TREE_OPERAND (lhs, 0);
    6187                 :   10490200 :   lr_arg = TREE_OPERAND (lhs, 1);
    6188                 :   10490200 :   rl_arg = TREE_OPERAND (rhs, 0);
    6189                 :   10490200 :   rr_arg = TREE_OPERAND (rhs, 1);
    6190                 :            : 
    6191                 :            :   /* Simplify (x<y) && (x==y) into (x<=y) and related optimizations.  */
    6192                 :   10490200 :   if (simple_operand_p (ll_arg)
    6193                 :   10490200 :       && simple_operand_p (lr_arg))
    6194                 :            :     {
    6195                 :    8861250 :       if (operand_equal_p (ll_arg, rl_arg, 0)
    6196                 :    8861250 :           && operand_equal_p (lr_arg, rr_arg, 0))
    6197                 :            :         {
    6198                 :       6304 :           result = combine_comparisons (loc, code, lcode, rcode,
    6199                 :            :                                         truth_type, ll_arg, lr_arg);
    6200                 :       6304 :           if (result)
    6201                 :            :             return result;
    6202                 :            :         }
    6203                 :    8854940 :       else if (operand_equal_p (ll_arg, rr_arg, 0)
    6204                 :    8854940 :                && operand_equal_p (lr_arg, rl_arg, 0))
    6205                 :            :         {
    6206                 :        262 :           result = combine_comparisons (loc, code, lcode,
    6207                 :            :                                         swap_tree_comparison (rcode),
    6208                 :            :                                         truth_type, ll_arg, lr_arg);
    6209                 :        262 :           if (result)
    6210                 :            :             return result;
    6211                 :            :         }
    6212                 :            :     }
    6213                 :            : 
    6214                 :   20968100 :   code = ((code == TRUTH_AND_EXPR || code == TRUTH_ANDIF_EXPR)
    6215                 :   10484000 :           ? TRUTH_AND_EXPR : TRUTH_OR_EXPR);
    6216                 :            : 
    6217                 :            :   /* If the RHS can be evaluated unconditionally and its operands are
    6218                 :            :      simple, it wins to evaluate the RHS unconditionally on machines
    6219                 :            :      with expensive branches.  In this case, this isn't a comparison
    6220                 :            :      that can be merged.  */
    6221                 :            : 
    6222                 :   10484000 :   if (BRANCH_COST (optimize_function_for_speed_p (cfun),
    6223                 :            :                    false) >= 2
    6224                 :   10484000 :       && ! FLOAT_TYPE_P (TREE_TYPE (rl_arg))
    6225                 :   10350600 :       && simple_operand_p (rl_arg)
    6226                 :   16740000 :       && simple_operand_p (rr_arg))
    6227                 :            :     {
    6228                 :            :       /* Convert (a != 0) || (b != 0) into (a | b) != 0.  */
    6229                 :    6929380 :       if (code == TRUTH_OR_EXPR
    6230                 :     935542 :           && lcode == NE_EXPR && integer_zerop (lr_arg)
    6231                 :     360652 :           && rcode == NE_EXPR && integer_zerop (rr_arg)
    6232                 :       9263 :           && TREE_TYPE (ll_arg) == TREE_TYPE (rl_arg)
    6233                 :    6936460 :           && INTEGRAL_TYPE_P (TREE_TYPE (ll_arg)))
    6234                 :      13608 :         return build2_loc (loc, NE_EXPR, truth_type,
    6235                 :       6804 :                            build2 (BIT_IOR_EXPR, TREE_TYPE (ll_arg),
    6236                 :            :                                    ll_arg, rl_arg),
    6237                 :       6804 :                            build_int_cst (TREE_TYPE (ll_arg), 0));
    6238                 :            : 
    6239                 :            :       /* Convert (a == 0) && (b == 0) into (a | b) == 0.  */
    6240                 :    6922580 :       if (code == TRUTH_AND_EXPR
    6241                 :     943642 :           && lcode == EQ_EXPR && integer_zerop (lr_arg)
    6242                 :     361337 :           && rcode == EQ_EXPR && integer_zerop (rr_arg)
    6243                 :       2192 :           && TREE_TYPE (ll_arg) == TREE_TYPE (rl_arg)
    6244                 :    6923550 :           && INTEGRAL_TYPE_P (TREE_TYPE (ll_arg)))
    6245                 :       1762 :         return build2_loc (loc, EQ_EXPR, truth_type,
    6246                 :        881 :                            build2 (BIT_IOR_EXPR, TREE_TYPE (ll_arg),
    6247                 :            :                                    ll_arg, rl_arg),
    6248                 :        881 :                            build_int_cst (TREE_TYPE (ll_arg), 0));
    6249                 :            :     }
    6250                 :            : 
    6251                 :            :   /* See if the comparisons can be merged.  Then get all the parameters for
    6252                 :            :      each side.  */
    6253                 :            : 
    6254                 :   10476400 :   if ((lcode != EQ_EXPR && lcode != NE_EXPR)
    6255                 :    5220770 :       || (rcode != EQ_EXPR && rcode != NE_EXPR))
    6256                 :            :     return 0;
    6257                 :            : 
    6258                 :    1709570 :   ll_reversep = lr_reversep = rl_reversep = rr_reversep = 0;
    6259                 :    1709570 :   volatilep = 0;
    6260                 :    1709570 :   ll_inner = decode_field_reference (loc, &ll_arg,
    6261                 :            :                                      &ll_bitsize, &ll_bitpos, &ll_mode,
    6262                 :            :                                      &ll_unsignedp, &ll_reversep, &volatilep,
    6263                 :            :                                      &ll_mask, &ll_and_mask);
    6264                 :    1709570 :   lr_inner = decode_field_reference (loc, &lr_arg,
    6265                 :            :                                      &lr_bitsize, &lr_bitpos, &lr_mode,
    6266                 :            :                                      &lr_unsignedp, &lr_reversep, &volatilep,
    6267                 :            :                                      &lr_mask, &lr_and_mask);
    6268                 :    1709570 :   rl_inner = decode_field_reference (loc, &rl_arg,
    6269                 :            :                                      &rl_bitsize, &rl_bitpos, &rl_mode,
    6270                 :            :                                      &rl_unsignedp, &rl_reversep, &volatilep,
    6271                 :            :                                      &rl_mask, &rl_and_mask);
    6272                 :    1709570 :   rr_inner = decode_field_reference (loc, &rr_arg,
    6273                 :            :                                      &rr_bitsize, &rr_bitpos, &rr_mode,
    6274                 :            :                                      &rr_unsignedp, &rr_reversep, &volatilep,
    6275                 :            :                                      &rr_mask, &rr_and_mask);
    6276                 :            : 
    6277                 :            :   /* It must be true that the inner operation on the lhs of each
    6278                 :            :      comparison must be the same if we are to be able to do anything.
    6279                 :            :      Then see if we have constants.  If not, the same must be true for
    6280                 :            :      the rhs's.  */
    6281                 :    1709570 :   if (volatilep
    6282                 :    1709570 :       || ll_reversep != rl_reversep
    6283                 :    1709550 :       || ll_inner == 0 || rl_inner == 0
    6284                 :    1729190 :       || ! operand_equal_p (ll_inner, rl_inner, 0))
    6285                 :    1695160 :     return 0;
    6286                 :            : 
    6287                 :      14414 :   if (TREE_CODE (lr_arg) == INTEGER_CST
    6288                 :      10984 :       && TREE_CODE (rr_arg) == INTEGER_CST)
    6289                 :            :     {
    6290                 :      10452 :       l_const = lr_arg, r_const = rr_arg;
    6291                 :      10452 :       lr_reversep = ll_reversep;
    6292                 :            :     }
    6293                 :       3962 :   else if (lr_reversep != rr_reversep
    6294                 :       3962 :            || lr_inner == 0 || rr_inner == 0
    6295                 :       5987 :            || ! operand_equal_p (lr_inner, rr_inner, 0))
    6296                 :       1957 :     return 0;
    6297                 :            :   else
    6298                 :            :     l_const = r_const = 0;
    6299                 :            : 
    6300                 :            :   /* If either comparison code is not correct for our logical operation,
    6301                 :            :      fail.  However, we can convert a one-bit comparison against zero into
    6302                 :            :      the opposite comparison against that bit being set in the field.  */
    6303                 :            : 
    6304                 :      12457 :   wanted_code = (code == TRUTH_AND_EXPR ? EQ_EXPR : NE_EXPR);
    6305                 :      12457 :   if (lcode != wanted_code)
    6306                 :            :     {
    6307                 :       1240 :       if (l_const && integer_zerop (l_const) && integer_pow2p (ll_mask))
    6308                 :            :         {
    6309                 :            :           /* Make the left operand unsigned, since we are only interested
    6310                 :            :              in the value of one bit.  Otherwise we are doing the wrong
    6311                 :            :              thing below.  */
    6312                 :        473 :           ll_unsignedp = 1;
    6313                 :        473 :           l_const = ll_mask;
    6314                 :            :         }
    6315                 :            :       else
    6316                 :        767 :         return 0;
    6317                 :            :     }
    6318                 :            : 
    6319                 :            :   /* This is analogous to the code for l_const above.  */
    6320                 :      11690 :   if (rcode != wanted_code)
    6321                 :            :     {
    6322                 :        602 :       if (r_const && integer_zerop (r_const) && integer_pow2p (rl_mask))
    6323                 :            :         {
    6324                 :        461 :           rl_unsignedp = 1;
    6325                 :        461 :           r_const = rl_mask;
    6326                 :            :         }
    6327                 :            :       else
    6328                 :        141 :         return 0;
    6329                 :            :     }
    6330                 :            : 
    6331                 :            :   /* See if we can find a mode that contains both fields being compared on
    6332                 :            :      the left.  If we can't, fail.  Otherwise, update all constants and masks
    6333                 :            :      to be relative to a field of that size.  */
    6334                 :      11549 :   first_bit = MIN (ll_bitpos, rl_bitpos);
    6335                 :      11549 :   end_bit = MAX (ll_bitpos + ll_bitsize, rl_bitpos + rl_bitsize);
    6336                 :      11549 :   if (!get_best_mode (end_bit - first_bit, first_bit, 0, 0,
    6337                 :      23098 :                       TYPE_ALIGN (TREE_TYPE (ll_inner)), BITS_PER_WORD,
    6338                 :            :                       volatilep, &lnmode))
    6339                 :            :     return 0;
    6340                 :            : 
    6341                 :       2236 :   lnbitsize = GET_MODE_BITSIZE (lnmode);
    6342                 :       2236 :   lnbitpos = first_bit & ~ (lnbitsize - 1);
    6343                 :       2236 :   lntype = lang_hooks.types.type_for_size (lnbitsize, 1);
    6344                 :       2236 :   xll_bitpos = ll_bitpos - lnbitpos, xrl_bitpos = rl_bitpos - lnbitpos;
    6345                 :            : 
    6346                 :       2236 :   if (ll_reversep ? !BYTES_BIG_ENDIAN : BYTES_BIG_ENDIAN)
    6347                 :            :     {
    6348                 :          6 :       xll_bitpos = lnbitsize - xll_bitpos - ll_bitsize;
    6349                 :          6 :       xrl_bitpos = lnbitsize - xrl_bitpos - rl_bitsize;
    6350                 :            :     }
    6351                 :            : 
    6352                 :       2236 :   ll_mask = const_binop (LSHIFT_EXPR, fold_convert_loc (loc, lntype, ll_mask),
    6353                 :            :                          size_int (xll_bitpos));
    6354                 :       2236 :   rl_mask = const_binop (LSHIFT_EXPR, fold_convert_loc (loc, lntype, rl_mask),
    6355                 :            :                          size_int (xrl_bitpos));
    6356                 :            : 
    6357                 :       2236 :   if (l_const)
    6358                 :            :     {
    6359                 :       2130 :       l_const = fold_convert_loc (loc, lntype, l_const);
    6360                 :       2130 :       l_const = unextend (l_const, ll_bitsize, ll_unsignedp, ll_and_mask);
    6361                 :       2130 :       l_const = const_binop (LSHIFT_EXPR, l_const, size_int (xll_bitpos));
    6362                 :       2130 :       if (! integer_zerop (const_binop (BIT_AND_EXPR, l_const,
    6363                 :            :                                         fold_build1_loc (loc, BIT_NOT_EXPR,
    6364                 :            :                                                      lntype, ll_mask))))
    6365                 :            :         {
    6366                 :          0 :           warning (0, "comparison is always %d", wanted_code == NE_EXPR);
    6367                 :            : 
    6368                 :          0 :           return constant_boolean_node (wanted_code == NE_EXPR, truth_type);
    6369                 :            :         }
    6370                 :            :     }
    6371                 :       2236 :   if (r_const)
    6372                 :            :     {
    6373                 :       2130 :       r_const = fold_convert_loc (loc, lntype, r_const);
    6374                 :       2130 :       r_const = unextend (r_const, rl_bitsize, rl_unsignedp, rl_and_mask);
    6375                 :       2130 :       r_const = const_binop (LSHIFT_EXPR, r_const, size_int (xrl_bitpos));
    6376                 :       2130 :       if (! integer_zerop (const_binop (BIT_AND_EXPR, r_const,
    6377                 :            :                                         fold_build1_loc (loc, BIT_NOT_EXPR,
    6378                 :            :                                                      lntype, rl_mask))))
    6379                 :            :         {
    6380                 :          0 :           warning (0, "comparison is always %d", wanted_code == NE_EXPR);
    6381                 :            : 
    6382                 :          0 :           return constant_boolean_node (wanted_code == NE_EXPR, truth_type);
    6383                 :            :         }
    6384                 :            :     }
    6385                 :            : 
    6386                 :            :   /* If the right sides are not constant, do the same for it.  Also,
    6387                 :            :      disallow this optimization if a size, signedness or storage order
    6388                 :            :      mismatch occurs between the left and right sides.  */
    6389                 :       2236 :   if (l_const == 0)
    6390                 :            :     {
    6391                 :        106 :       if (ll_bitsize != lr_bitsize || rl_bitsize != rr_bitsize
    6392                 :        106 :           || ll_unsignedp != lr_unsignedp || rl_unsignedp != rr_unsignedp
    6393                 :        106 :           || ll_reversep != lr_reversep
    6394                 :            :           /* Make sure the two fields on the right
    6395                 :            :              correspond to the left without being swapped.  */
    6396                 :        100 :           || ll_bitpos - rl_bitpos != lr_bitpos - rr_bitpos)
    6397                 :            :         return 0;
    6398                 :            : 
    6399                 :        100 :       first_bit = MIN (lr_bitpos, rr_bitpos);
    6400                 :        100 :       end_bit = MAX (lr_bitpos + lr_bitsize, rr_bitpos + rr_bitsize);
    6401                 :        100 :       if (!get_best_mode (end_bit - first_bit, first_bit, 0, 0,
    6402                 :        200 :                           TYPE_ALIGN (TREE_TYPE (lr_inner)), BITS_PER_WORD,
    6403                 :            :                           volatilep, &rnmode))
    6404                 :            :         return 0;
    6405                 :            : 
    6406                 :        100 :       rnbitsize = GET_MODE_BITSIZE (rnmode);
    6407                 :        100 :       rnbitpos = first_bit & ~ (rnbitsize - 1);
    6408                 :        100 :       rntype = lang_hooks.types.type_for_size (rnbitsize, 1);
    6409                 :        100 :       xlr_bitpos = lr_bitpos - rnbitpos, xrr_bitpos = rr_bitpos - rnbitpos;
    6410                 :            : 
    6411                 :        100 :       if (lr_reversep ? !BYTES_BIG_ENDIAN : BYTES_BIG_ENDIAN)
    6412                 :            :         {
    6413                 :          0 :           xlr_bitpos = rnbitsize - xlr_bitpos - lr_bitsize;
    6414                 :          0 :           xrr_bitpos = rnbitsize - xrr_bitpos - rr_bitsize;
    6415                 :            :         }
    6416                 :            : 
    6417                 :        100 :       lr_mask = const_binop (LSHIFT_EXPR, fold_convert_loc (loc,
    6418                 :            :                                                             rntype, lr_mask),
    6419                 :            :                              size_int (xlr_bitpos));
    6420                 :        100 :       rr_mask = const_binop (LSHIFT_EXPR, fold_convert_loc (loc,
    6421                 :            :                                                             rntype, rr_mask),
    6422                 :            :                              size_int (xrr_bitpos));
    6423                 :            : 
    6424                 :            :       /* Make a mask that corresponds to both fields being compared.
    6425                 :            :          Do this for both items being compared.  If the operands are the
    6426                 :            :          same size and the bits being compared are in the same position
    6427                 :            :          then we can do this by masking both and comparing the masked
    6428                 :            :          results.  */
    6429                 :        100 :       ll_mask = const_binop (BIT_IOR_EXPR, ll_mask, rl_mask);
    6430                 :        100 :       lr_mask = const_binop (BIT_IOR_EXPR, lr_mask, rr_mask);
    6431                 :        100 :       if (lnbitsize == rnbitsize
    6432                 :        100 :           && xll_bitpos == xlr_bitpos
    6433                 :         64 :           && lnbitpos >= 0
    6434                 :         64 :           && rnbitpos >= 0)
    6435                 :            :         {
    6436                 :         64 :           lhs = make_bit_field_ref (loc, ll_inner, ll_arg,
    6437                 :            :                                     lntype, lnbitsize, lnbitpos,
    6438                 :         64 :                                     ll_unsignedp || rl_unsignedp, ll_reversep);
    6439                 :         64 :           if (! all_ones_mask_p (ll_mask, lnbitsize))
    6440                 :         64 :             lhs = build2 (BIT_AND_EXPR, lntype, lhs, ll_mask);
    6441                 :            : 
    6442                 :         64 :           rhs = make_bit_field_ref (loc, lr_inner, lr_arg,
    6443                 :            :                                     rntype, rnbitsize, rnbitpos,
    6444                 :         64 :                                     lr_unsignedp || rr_unsignedp, lr_reversep);
    6445                 :         64 :           if (! all_ones_mask_p (lr_mask, rnbitsize))
    6446                 :         64 :             rhs = build2 (BIT_AND_EXPR, rntype, rhs, lr_mask);
    6447                 :            : 
    6448                 :         64 :           return build2_loc (loc, wanted_code, truth_type, lhs, rhs);
    6449                 :            :         }
    6450                 :            : 
    6451                 :            :       /* There is still another way we can do something:  If both pairs of
    6452                 :            :          fields being compared are adjacent, we may be able to make a wider
    6453                 :            :          field containing them both.
    6454                 :            : 
    6455                 :            :          Note that we still must mask the lhs/rhs expressions.  Furthermore,
    6456                 :            :          the mask must be shifted to account for the shift done by
    6457                 :            :          make_bit_field_ref.  */
    6458                 :         36 :       if (((ll_bitsize + ll_bitpos == rl_bitpos
    6459                 :         18 :             && lr_bitsize + lr_bitpos == rr_bitpos)
    6460                 :         18 :            || (ll_bitpos == rl_bitpos + rl_bitsize
    6461                 :         18 :                && lr_bitpos == rr_bitpos + rr_bitsize))
    6462                 :         36 :           && ll_bitpos >= 0
    6463                 :         36 :           && rl_bitpos >= 0
    6464                 :         36 :           && lr_bitpos >= 0
    6465                 :         36 :           && rr_bitpos >= 0)
    6466                 :            :         {
    6467                 :         36 :           tree type;
    6468                 :            : 
    6469                 :         54 :           lhs = make_bit_field_ref (loc, ll_inner, ll_arg, lntype,
    6470                 :            :                                     ll_bitsize + rl_bitsize,
    6471                 :            :                                     MIN (ll_bitpos, rl_bitpos),
    6472                 :            :                                     ll_unsignedp, ll_reversep);
    6473                 :         36 :           rhs = make_bit_field_ref (loc, lr_inner, lr_arg, rntype,
    6474                 :            :                                     lr_bitsize + rr_bitsize,
    6475                 :         36 :                                     MIN (lr_bitpos, rr_bitpos),
    6476                 :            :                                     lr_unsignedp, lr_reversep);
    6477                 :            : 
    6478                 :         54 :           ll_mask = const_binop (RSHIFT_EXPR, ll_mask,
    6479                 :            :                                  size_int (MIN (xll_bitpos, xrl_bitpos)));
    6480                 :         54 :           lr_mask = const_binop (RSHIFT_EXPR, lr_mask,
    6481                 :            :                                  size_int (MIN (xlr_bitpos, xrr_bitpos)));
    6482                 :            : 
    6483                 :            :           /* Convert to the smaller type before masking out unwanted bits.  */
    6484                 :         36 :           type = lntype;
    6485                 :         36 :           if (lntype != rntype)
    6486                 :            :             {
    6487                 :          0 :               if (lnbitsize > rnbitsize)
    6488                 :            :                 {
    6489                 :          0 :                   lhs = fold_convert_loc (loc, rntype, lhs);
    6490                 :          0 :                   ll_mask = fold_convert_loc (loc, rntype, ll_mask);
    6491                 :          0 :                   type = rntype;
    6492                 :            :                 }
    6493                 :          0 :               else if (lnbitsize < rnbitsize)
    6494                 :            :                 {
    6495                 :          0 :                   rhs = fold_convert_loc (loc, lntype, rhs);
    6496                 :          0 :                   lr_mask = fold_convert_loc (loc, lntype, lr_mask);
    6497                 :          0 :                   type = lntype;
    6498                 :            :                 }
    6499                 :            :             }
    6500                 :            : 
    6501                 :         36 :           if (! all_ones_mask_p (ll_mask, ll_bitsize + rl_bitsize))
    6502                 :         36 :             lhs = build2 (BIT_AND_EXPR, type, lhs, ll_mask);
    6503                 :            : 
    6504                 :         36 :           if (! all_ones_mask_p (lr_mask, lr_bitsize + rr_bitsize))
    6505                 :         36 :             rhs = build2 (BIT_AND_EXPR, type, rhs, lr_mask);
    6506                 :            : 
    6507                 :         36 :           return build2_loc (loc, wanted_code, truth_type, lhs, rhs);
    6508                 :            :         }
    6509                 :            : 
    6510                 :            :       return 0;
    6511                 :            :     }
    6512                 :            : 
    6513                 :            :   /* Handle the case of comparisons with constants.  If there is something in
    6514                 :            :      common between the masks, those bits of the constants must be the same.
    6515                 :            :      If not, the condition is always false.  Test for this to avoid generating
    6516                 :            :      incorrect code below.  */
    6517                 :       2130 :   result = const_binop (BIT_AND_EXPR, ll_mask, rl_mask);
    6518                 :       2130 :   if (! integer_zerop (result)
    6519                 :       2142 :       && simple_cst_equal (const_binop (BIT_AND_EXPR, result, l_const),
    6520                 :         12 :                            const_binop (BIT_AND_EXPR, result, r_const)) != 1)
    6521                 :            :     {
    6522                 :          0 :       if (wanted_code == NE_EXPR)
    6523                 :            :         {
    6524                 :          0 :           warning (0, "%<or%> of unmatched not-equal tests is always 1");
    6525                 :          0 :           return constant_boolean_node (true, truth_type);
    6526                 :            :         }
    6527                 :            :       else
    6528                 :            :         {
    6529                 :          0 :           warning (0, "%<and%> of mutually exclusive equal-tests is always 0");
    6530                 :          0 :           return constant_boolean_node (false, truth_type);
    6531                 :            :         }
    6532                 :            :     }
    6533                 :            : 
    6534                 :       2130 :   if (lnbitpos < 0)
    6535                 :            :     return 0;
    6536                 :            : 
    6537                 :            :   /* Construct the expression we will return.  First get the component
    6538                 :            :      reference we will make.  Unless the mask is all ones the width of
    6539                 :            :      that field, perform the mask operation.  Then compare with the
    6540                 :            :      merged constant.  */
    6541                 :       2124 :   result = make_bit_field_ref (loc, ll_inner, ll_arg,
    6542                 :            :                                lntype, lnbitsize, lnbitpos,
    6543                 :       2124 :                                ll_unsignedp || rl_unsignedp, ll_reversep);
    6544                 :            : 
    6545                 :       2124 :   ll_mask = const_binop (BIT_IOR_EXPR, ll_mask, rl_mask);
    6546                 :       2124 :   if (! all_ones_mask_p (ll_mask, lnbitsize))
    6547                 :       2124 :     result = build2_loc (loc, BIT_AND_EXPR, lntype, result, ll_mask);
    6548                 :            : 
    6549                 :       2124 :   return build2_loc (loc, wanted_code, truth_type, result,
    6550                 :            :                      const_binop (BIT_IOR_EXPR, l_const, r_const));
    6551                 :            : }
    6552                 :            : 
    6553                 :            : /* T is an integer expression that is being multiplied, divided, or taken a
    6554                 :            :    modulus (CODE says which and what kind of divide or modulus) by a
    6555                 :            :    constant C.  See if we can eliminate that operation by folding it with
    6556                 :            :    other operations already in T.  WIDE_TYPE, if non-null, is a type that
    6557                 :            :    should be used for the computation if wider than our type.
    6558                 :            : 
    6559                 :            :    For example, if we are dividing (X * 8) + (Y * 16) by 4, we can return
    6560                 :            :    (X * 2) + (Y * 4).  We must, however, be assured that either the original
    6561                 :            :    expression would not overflow or that overflow is undefined for the type
    6562                 :            :    in the language in question.
    6563                 :            : 
    6564                 :            :    If we return a non-null expression, it is an equivalent form of the
    6565                 :            :    original computation, but need not be in the original type.
    6566                 :            : 
    6567                 :            :    We set *STRICT_OVERFLOW_P to true if the return values depends on
    6568                 :            :    signed overflow being undefined.  Otherwise we do not change
    6569                 :            :    *STRICT_OVERFLOW_P.  */
    6570                 :            : 
    6571                 :            : static tree
    6572                 :   38813600 : extract_muldiv (tree t, tree c, enum tree_code code, tree wide_type,
    6573                 :            :                 bool *strict_overflow_p)
    6574                 :            : {
    6575                 :            :   /* To avoid exponential search depth, refuse to allow recursion past
    6576                 :            :      three levels.  Beyond that (1) it's highly unlikely that we'll find
    6577                 :            :      something interesting and (2) we've probably processed it before
    6578                 :            :      when we built the inner expression.  */
    6579                 :            : 
    6580                 :   38813600 :   static int depth;
    6581                 :   38813600 :   tree ret;
    6582                 :            : 
    6583                 :   38813600 :   if (depth > 3)
    6584                 :            :     return NULL;
    6585                 :            : 
    6586                 :   37443500 :   depth++;
    6587                 :   37443500 :   ret = extract_muldiv_1 (t, c, code, wide_type, strict_overflow_p);
    6588                 :   37443500 :   depth--;
    6589                 :            : 
    6590                 :   37443500 :   return ret;
    6591                 :            : }
    6592                 :            : 
    6593                 :            : static tree
    6594                 :   37443500 : extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type,
    6595                 :            :                   bool *strict_overflow_p)
    6596                 :            : {
    6597                 :   37443500 :   tree type = TREE_TYPE (t);
    6598                 :   37443500 :   enum tree_code tcode = TREE_CODE (t);
    6599                 :   37443500 :   tree ctype = (wide_type != 0
    6600                 :   22406000 :                 && (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (wide_type))
    6601                 :   22406000 :                     > GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (type)))
    6602                 :   37443500 :                 ? wide_type : type);
    6603                 :   37443500 :   tree t1, t2;
    6604                 :   37443500 :   int same_p = tcode == code;
    6605                 :   37443500 :   tree op0 = NULL_TREE, op1 = NULL_TREE;
    6606                 :   37443500 :   bool sub_strict_overflow_p;
    6607                 :            : 
    6608                 :            :   /* Don't deal with constants of zero here; they confuse the code below.  */
    6609                 :   37443500 :   if (integer_zerop (c))
    6610                 :            :     return NULL_TREE;
    6611                 :            : 
    6612                 :   37440100 :   if (TREE_CODE_CLASS (tcode) == tcc_unary)
    6613                 :   15031700 :     op0 = TREE_OPERAND (t, 0);
    6614                 :            : 
    6615                 :   37440100 :   if (TREE_CODE_CLASS (tcode) == tcc_binary)
    6616                 :    5385870 :     op0 = TREE_OPERAND (t, 0), op1 = TREE_OPERAND (t, 1);
    6617                 :            : 
    6618                 :            :   /* Note that we need not handle conditional operations here since fold
    6619                 :            :      already handles those cases.  So just do arithmetic here.  */
    6620                 :   37440100 :   switch (tcode)
    6621                 :            :     {
    6622                 :    2053610 :     case INTEGER_CST:
    6623                 :            :       /* For a constant, we can always simplify if we are a multiply
    6624                 :            :          or (for divide and modulus) if it is a multiple of our constant.  */
    6625                 :    2053610 :       if (code == MULT_EXPR
    6626                 :    2696110 :           || wi::multiple_of_p (wi::to_wide (t), wi::to_wide (c),
    6627                 :     642503 :                                 TYPE_SIGN (type)))
    6628                 :            :         {
    6629                 :    1685840 :           tree tem = const_binop (code, fold_convert (ctype, t),
    6630                 :            :                                   fold_convert (ctype, c));
    6631                 :            :           /* If the multiplication overflowed, we lost information on it.
    6632                 :            :              See PR68142 and PR69845.  */
    6633                 :    1685840 :           if (TREE_OVERFLOW (tem))
    6634                 :            :             return NULL_TREE;
    6635                 :    1683650 :           return tem;
    6636                 :            :         }
    6637                 :            :       break;
    6638                 :            : 
    6639                 :   14588900 :     CASE_CONVERT: case NON_LVALUE_EXPR:
    6640                 :            :       /* If op0 is an expression ...  */
    6641                 :   14588900 :       if ((COMPARISON_CLASS_P (op0)
    6642                 :            :            || UNARY_CLASS_P (op0)
    6643                 :   14588900 :            || BINARY_CLASS_P (op0)
    6644                 :   12516800 :            || VL_EXP_CLASS_P (op0)
    6645                 :   12513300 :            || EXPRESSION_CLASS_P (op0))
    6646                 :            :           /* ... and has wrapping overflow, and its type is smaller
    6647                 :            :              than ctype, then we cannot pass through as widening.  */
    6648                 :   16566700 :           && (((ANY_INTEGRAL_TYPE_P (TREE_TYPE (op0))
    6649                 :    3730240 :                 && TYPE_OVERFLOW_WRAPS (TREE_TYPE (op0)))
    6650                 :     994936 :                && (TYPE_PRECISION (ctype)
    6651                 :     497468 :                    > TYPE_PRECISION (TREE_TYPE (op0))))
    6652                 :            :               /* ... or this is a truncation (t is narrower than op0),
    6653                 :            :                  then we cannot pass through this narrowing.  */
    6654                 :    3999610 :               || (TYPE_PRECISION (type)
    6655                 :    1999810 :                   < TYPE_PRECISION (TREE_TYPE (op0)))
    6656                 :            :               /* ... or signedness changes for division or modulus,
    6657                 :            :                  then we cannot pass through this conversion.  */
    6658                 :    1955010 :               || (code != MULT_EXPR
    6659                 :      47005 :                   && (TYPE_UNSIGNED (ctype)
    6660                 :      47005 :                       != TYPE_UNSIGNED (TREE_TYPE (op0))))
    6661                 :            :               /* ... or has undefined overflow while the converted to
    6662                 :            :                  type has not, we cannot do the operation in the inner type
    6663                 :            :                  as that would introduce undefined overflow.  */
    6664                 :    1935380 :               || ((ANY_INTEGRAL_TYPE_P (TREE_TYPE (op0))
    6665                 :    1906580 :                    && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (op0)))
    6666                 :    1587290 :                   && !TYPE_OVERFLOW_UNDEFINED (type))))
    6667                 :            :         break;
    6668                 :            : 
    6669                 :            :       /* Pass the constant down and see if we can make a simplification.  If
    6670                 :            :          we can, replace this expression with the inner simplification for
    6671                 :            :          possible later conversion to our or some other type.  */
    6672                 :   12813500 :       if ((t2 = fold_convert (TREE_TYPE (op0), c)) != 0
    6673                 :   12813500 :           && TREE_CODE (t2) == INTEGER_CST
    6674                 :   12813500 :           && !TREE_OVERFLOW (t2)
    6675                 :   36717600 :           && (t1 = extract_muldiv (op0, t2, code,
    6676                 :            :                                    code == MULT_EXPR ? ctype : NULL_TREE,
    6677                 :            :                                    strict_overflow_p)) != 0)
    6678                 :      37003 :         return t1;
    6679                 :            :       break;
    6680                 :            : 
    6681                 :         57 :     case ABS_EXPR:
    6682                 :            :       /* If widening the type changes it from signed to unsigned, then we
    6683                 :            :          must avoid building ABS_EXPR itself as unsigned.  */
    6684                 :         57 :       if (TYPE_UNSIGNED (ctype) && !TYPE_UNSIGNED (type))
    6685                 :            :         {
    6686                 :          0 :           tree cstype = (*signed_type_for) (ctype);
    6687                 :          0 :           if ((t1 = extract_muldiv (op0, c, code, cstype, strict_overflow_p))
    6688                 :            :               != 0)
    6689                 :            :             {
    6690                 :          0 :               t1 = fold_build1 (tcode, cstype, fold_convert (cstype, t1));
    6691                 :          0 :               return fold_convert (ctype, t1);
    6692                 :            :             }
    6693                 :            :           break;
    6694                 :            :         }
    6695                 :            :       /* If the constant is negative, we cannot simplify this.  */
    6696                 :         57 :       if (tree_int_cst_sgn (c) == -1)
    6697                 :            :         break;
    6698                 :            :       /* FALLTHROUGH */
    6699                 :      12129 :     case NEGATE_EXPR:
    6700                 :            :       /* For division and modulus, type can't be unsigned, as e.g.
    6701                 :            :          (-(x / 2U)) / 2U isn't equal to -((x / 2U) / 2U) for x >= 2.
    6702                 :            :          For signed types, even with wrapping overflow, this is fine.  */
    6703                 :      12643 :       if (code != MULT_EXPR && TYPE_UNSIGNED (type))
    6704                 :            :         break;
    6705                 :      11623 :       if ((t1 = extract_muldiv (op0, c, code, wide_type, strict_overflow_p))
    6706                 :            :           != 0)
    6707                 :          0 :         return fold_build1 (tcode, ctype, fold_convert (ctype, t1));
    6708                 :            :       break;
    6709                 :            : 
    6710                 :        122 :     case MIN_EXPR:  case MAX_EXPR:
    6711                 :            :       /* If widening the type changes the signedness, then we can't perform
    6712                 :            :          this optimization as that changes the result.  */
    6713                 :        122 :       if (TYPE_UNSIGNED (ctype) != TYPE_UNSIGNED (type))
    6714                 :            :         break;
    6715                 :            : 
    6716                 :            :       /* MIN (a, b) / 5 -> MIN (a / 5, b / 5)  */
    6717                 :        122 :       sub_strict_overflow_p = false;
    6718                 :        122 :       if ((t1 = extract_muldiv (op0, c, code, wide_type,
    6719                 :            :                                 &sub_strict_overflow_p)) != 0
    6720                 :        122 :           && (t2 = extract_muldiv (op1, c, code, wide_type,
    6721                 :            :                                    &sub_strict_overflow_p)) != 0)
    6722                 :            :         {
    6723                 :          0 :           if (tree_int_cst_sgn (c) < 0)
    6724                 :          0 :             tcode = (tcode == MIN_EXPR ? MAX_EXPR : MIN_EXPR);
    6725                 :          0 :           if (sub_strict_overflow_p)
    6726                 :          0 :             *strict_overflow_p = true;
    6727                 :          0 :           return fold_build2 (tcode, ctype, fold_convert (ctype, t1),
    6728                 :            :                               fold_convert (ctype, t2));
    6729                 :            :         }
    6730                 :            :       break;
    6731                 :            : 
    6732                 :        834 :     case LSHIFT_EXPR:  case RSHIFT_EXPR:
    6733                 :            :       /* If the second operand is constant, this is a multiplication
    6734                 :            :          or floor division, by a power of two, so we can treat it that
    6735                 :            :          way unless the multiplier or divisor overflows.  Signed
    6736                 :            :          left-shift overflow is implementation-defined rather than
    6737                 :            :          undefined in C90, so do not convert signed left shift into
    6738                 :            :          multiplication.  */
    6739                 :        834 :       if (TREE_CODE (op1) == INTEGER_CST
    6740                 :        808 :           && (tcode == RSHIFT_EXPR || TYPE_UNSIGNED (TREE_TYPE (op0)))
    6741                 :            :           /* const_binop may not detect overflow correctly,
    6742                 :            :              so check for it explicitly here.  */
    6743                 :        775 :           && wi::gtu_p (TYPE_PRECISION (TREE_TYPE (size_one_node)),
    6744                 :        843 :                         wi::to_wide (op1))
    6745                 :        766 :           && (t1 = fold_convert (ctype,
    6746                 :            :                                  const_binop (LSHIFT_EXPR, size_one_node,
    6747                 :            :                                               op1))) != 0
    6748                 :       1600 :           && !TREE_OVERFLOW (t1))
    6749                 :       1186 :         return extract_muldiv (build2 (tcode == LSHIFT_EXPR
    6750                 :            :                                        ? MULT_EXPR : FLOOR_DIV_EXPR,
    6751                 :            :                                        ctype,
    6752                 :            :                                        fold_convert (ctype, op0),
    6753                 :            :                                        t1),
    6754                 :        766 :                                c, code, wide_type, strict_overflow_p);
    6755                 :            :       break;
    6756                 :            : 
    6757                 :    3767490 :     case PLUS_EXPR:  case MINUS_EXPR:
    6758                 :            :       /* See if we can eliminate the operation on both sides.  If we can, we
    6759                 :            :          can return a new PLUS or MINUS.  If we can't, the only remaining
    6760                 :            :          cases where we can do anything are if the second operand is a
    6761                 :            :          constant.  */
    6762                 :    3767490 :       sub_strict_overflow_p = false;
    6763                 :    3767490 :       t1 = extract_muldiv (op0, c, code, wide_type, &sub_strict_overflow_p);
    6764                 :    3767490 :       t2 = extract_muldiv (op1, c, code, wide_type, &sub_strict_overflow_p);
    6765                 :     289009 :       if (t1 != 0 && t2 != 0
    6766                 :      71212 :           && TYPE_OVERFLOW_WRAPS (ctype)
    6767                 :    3833340 :           && (code == MULT_EXPR
    6768                 :            :               /* If not multiplication, we can only do this if both operands
    6769                 :            :                  are divisible by c.  */
    6770                 :          0 :               || (multiple_of_p (ctype, op0, c)
    6771                 :          0 :                   && multiple_of_p (ctype, op1, c))))
    6772                 :            :         {
    6773                 :      65852 :           if (sub_strict_overflow_p)
    6774                 :          0 :             *strict_overflow_p = true;
    6775                 :      65852 :           return fold_build2 (tcode, ctype, fold_convert (ctype, t1),
    6776                 :            :                               fold_convert (ctype, t2));
    6777                 :            :         }
    6778                 :            : 
    6779                 :            :       /* If this was a subtraction, negate OP1 and set it to be an addition.
    6780                 :            :          This simplifies the logic below.  */
    6781                 :    3701640 :       if (tcode == MINUS_EXPR)
    6782                 :            :         {
    6783                 :    1139100 :           tcode = PLUS_EXPR, op1 = negate_expr (op1);
    6784                 :            :           /* If OP1 was not easily negatable, the constant may be OP0.  */
    6785                 :    1139100 :           if (TREE_CODE (op0) == INTEGER_CST)
    6786                 :            :             {
    6787                 :     157429 :               std::swap (op0, op1);
    6788                 :     157429 :               std::swap (t1, t2);
    6789                 :            :             }
    6790                 :            :         }
    6791                 :            : 
    6792                 :    3701640 :       if (TREE_CODE (op1) != INTEGER_CST)
    6793                 :            :         break;
    6794                 :            : 
    6795                 :            :       /* If either OP1 or C are negative, this optimization is not safe for
    6796                 :            :          some of the division and remainder types while for others we need
    6797                 :            :          to change the code.  */
    6798                 :    1858540 :       if (tree_int_cst_sgn (op1) < 0 || tree_int_cst_sgn (c) < 0)
    6799                 :            :         {
    6800                 :      64767 :           if (code == CEIL_DIV_EXPR)
    6801                 :            :             code = FLOOR_DIV_EXPR;
    6802                 :      64767 :           else if (code == FLOOR_DIV_EXPR)
    6803                 :            :             code = CEIL_DIV_EXPR;
    6804                 :      64600 :           else if (code != MULT_EXPR
    6805                 :      64600 :                    && code != CEIL_MOD_EXPR && code != FLOOR_MOD_EXPR)
    6806                 :            :             break;
    6807                 :            :         }
    6808                 :            : 
    6809                 :            :       /* If it's a multiply or a division/modulus operation of a multiple
    6810                 :            :          of our constant, do the operation and verify it doesn't overflow.  */
    6811                 :    1856310 :       if (code == MULT_EXPR
    6812                 :    2496840 :           || wi::multiple_of_p (wi::to_wide (op1), wi::to_wide (c),
    6813                 :     640530 :                                 TYPE_SIGN (type)))
    6814                 :            :         {
    6815                 :    1489870 :           op1 = const_binop (code, fold_convert (ctype, op1),
    6816                 :            :                              fold_convert (ctype, c));
    6817                 :            :           /* We allow the constant to overflow with wrapping semantics.  */
    6818                 :    1489870 :           if (op1 == 0
    6819                 :    1492040 :               || (TREE_OVERFLOW (op1) && !TYPE_OVERFLOW_WRAPS (ctype)))
    6820                 :            :             break;
    6821                 :            :         }
    6822                 :            :       else
    6823                 :            :         break;
    6824                 :            : 
    6825                 :            :       /* If we have an unsigned type, we cannot widen the operation since it
    6826                 :            :          will change the result if the original computation overflowed.  */
    6827                 :    1487700 :       if (TYPE_UNSIGNED (ctype) && ctype != type)
    6828                 :            :         break;
    6829                 :            : 
    6830                 :            :       /* The last case is if we are a multiply.  In that case, we can
    6831                 :            :          apply the distributive law to commute the multiply and addition
    6832                 :            :          if the multiplication of the constants doesn't overflow
    6833                 :            :          and overflow is defined.  With undefined overflow
    6834                 :            :          op0 * c might overflow, while (op0 + orig_op1) * c doesn't.
    6835                 :            :          But fold_plusminus_mult_expr would factor back any power-of-two
    6836                 :            :          value so do not distribute in the first place in this case.  */
    6837                 :    1487700 :       if (code == MULT_EXPR
    6838                 :    1359240 :           && TYPE_OVERFLOW_WRAPS (ctype)
    6839                 :    3607260 :           && !(tree_fits_shwi_p (c) && pow2p_hwi (absu_hwi (tree_to_shwi (c)))))
    6840                 :     144608 :         return fold_build2 (tcode, ctype,
    6841                 :            :                             fold_build2 (code, ctype,
    6842                 :            :                                          fold_convert (ctype, op0),
    6843                 :            :                                          fold_convert (ctype, c)),
    6844                 :            :                             op1);
    6845                 :            : 
    6846                 :            :       break;
    6847                 :            : 
    6848                 :    1247840 :     case MULT_EXPR:
    6849                 :            :       /* We have a special case here if we are doing something like
    6850                 :            :          (C * 8) % 4 since we know that's zero.  */
    6851                 :    1247840 :       if ((code == TRUNC_MOD_EXPR || code == CEIL_MOD_EXPR
    6852                 :    1247840 :            || code == FLOOR_MOD_EXPR || code == ROUND_MOD_EXPR)
    6853                 :            :           /* If the multiplication can overflow we cannot optimize this.  */
    6854                 :        442 :           && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (t))
    6855                 :        295 :           && TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST
    6856                 :    1248720 :           && wi::multiple_of_p (wi::to_wide (op1), wi::to_wide (c),
    6857                 :        264 :                                 TYPE_SIGN (type)))
    6858                 :            :         {
    6859                 :          6 :           *strict_overflow_p = true;
    6860                 :          6 :           return omit_one_operand (type, integer_zero_node, op0);
    6861                 :            :         }
    6862                 :            : 
    6863                 :            :       /* ... fall through ...  */
    6864                 :            : 
    6865                 :    1362400 :     case TRUNC_DIV_EXPR:  case CEIL_DIV_EXPR:  case FLOOR_DIV_EXPR:
    6866                 :    1362400 :     case ROUND_DIV_EXPR:  case EXACT_DIV_EXPR:
    6867                 :            :       /* If we can extract our operation from the LHS, do so and return a
    6868                 :            :          new operation.  Likewise for the RHS from a MULT_EXPR.  Otherwise,
    6869                 :            :          do something only if the second operand is a constant.  */
    6870                 :    1362400 :       if (same_p
    6871                 :    1309870 :           && TYPE_OVERFLOW_WRAPS (ctype)
    6872                 :    2439780 :           && (t1 = extract_muldiv (op0, c, code, wide_type,
    6873                 :            :                                    strict_overflow_p)) != 0)
    6874                 :      41896 :         return fold_build2 (tcode, ctype, fold_convert (ctype, t1),
    6875                 :            :                             fold_convert (ctype, op1));
    6876                 :    1320500 :       else if (tcode == MULT_EXPR && code == MULT_EXPR
    6877                 :    1267890 :                && TYPE_OVERFLOW_WRAPS (ctype)
    6878                 :    2355970 :                && (t1 = extract_muldiv (op1, c, code, wide_type,
    6879                 :            :                                         strict_overflow_p)) != 0)
    6880                 :     279156 :         return fold_build2 (tcode, ctype, fold_convert (ctype, op0),
    6881                 :            :                             fold_convert (ctype, t1));
    6882                 :    1041350 :       else if (TREE_CODE (op1) != INTEGER_CST)
    6883                 :            :         return 0;
    6884                 :            : 
    6885                 :            :       /* If these are the same operation types, we can associate them
    6886                 :            :          assuming no overflow.  */
    6887                 :     283470 :       if (tcode == code)
    6888                 :            :         {
    6889                 :     114904 :           bool overflow_p = false;
    6890                 :     114904 :           wi::overflow_type overflow_mul;
    6891                 :     114904 :           signop sign = TYPE_SIGN (ctype);
    6892                 :     114904 :           unsigned prec = TYPE_PRECISION (ctype);
    6893                 :     114904 :           wide_int mul = wi::mul (wi::to_wide (op1, prec),
    6894                 :     114904 :                                   wi::to_wide (c, prec),
    6895                 :     114904 :                                   sign, &overflow_mul);
    6896                 :     114904 :           overflow_p = TREE_OVERFLOW (c) | TREE_OVERFLOW (op1);
    6897                 :     114904 :           if (overflow_mul
    6898                 :     114904 :               && ((sign == UNSIGNED && tcode != MULT_EXPR) || sign == SIGNED))
    6899                 :            :             overflow_p = true;
    6900                 :     114840 :           if (!overflow_p)
    6901                 :     114840 :             return fold_build2 (tcode, ctype, fold_convert (ctype, op0),
    6902                 :            :                                 wide_int_to_tree (ctype, mul));
    6903                 :            :         }
    6904                 :            : 
    6905                 :            :       /* If these operations "cancel" each other, we have the main
    6906                 :            :          optimizations of this pass, which occur when either constant is a
    6907                 :            :          multiple of the other, in which case we replace this with either an
    6908                 :            :          operation or CODE or TCODE.
    6909                 :            : 
    6910                 :            :          If we have an unsigned type, we cannot do this since it will change
    6911                 :            :          the result if the original computation overflowed.  */
    6912                 :     168630 :       if (TYPE_OVERFLOW_UNDEFINED (ctype)
    6913                 :     172076 :           && ((code == MULT_EXPR && tcode == EXACT_DIV_EXPR)
    6914                 :       2414 :               || (tcode == MULT_EXPR
    6915                 :       2414 :                   && code != TRUNC_MOD_EXPR && code != CEIL_MOD_EXPR
    6916                 :        647 :                   && code != FLOOR_MOD_EXPR && code != ROUND_MOD_EXPR
    6917                 :        623 :                   && code != MULT_EXPR)))
    6918                 :            :         {
    6919                 :       3252 :           if (wi::multiple_of_p (wi::to_wide (op1), wi::to_wide (c),
    6920                 :       1626 :                                  TYPE_SIGN (type)))
    6921                 :            :             {
    6922                 :         48 :               if (TYPE_OVERFLOW_UNDEFINED (ctype))
    6923                 :         48 :                 *strict_overflow_p = true;
    6924                 :         48 :               return fold_build2 (tcode, ctype, fold_convert (ctype, op0),
    6925                 :            :                                   fold_convert (ctype,
    6926                 :            :                                                 const_binop (TRUNC_DIV_EXPR,
    6927                 :            :                                                              op1, c)));
    6928                 :            :             }
    6929                 :       3156 :           else if (wi::multiple_of_p (wi::to_wide (c), wi::to_wide (op1),
    6930                 :       1578 :                                       TYPE_SIGN (type)))
    6931                 :            :             {
    6932                 :       1027 :               if (TYPE_OVERFLOW_UNDEFINED (ctype))
    6933                 :       1027 :                 *strict_overflow_p = true;
    6934                 :       1027 :               return fold_build2 (code, ctype, fold_convert (ctype, op0),
    6935                 :            :                                   fold_convert (ctype,
    6936                 :            :                                                 const_binop (TRUNC_DIV_EXPR,
    6937                 :            :                                                              c, op1)));
    6938                 :            :             }
    6939                 :            :         }
    6940                 :            :       break;
    6941                 :            : 
    6942                 :            :     default:
    6943                 :            :       break;
    6944                 :            :     }
    6945                 :            : 
    6946                 :            :   return 0;
    6947                 :            : }
    6948                 :            : 
    6949                 :            : /* Return a node which has the indicated constant VALUE (either 0 or
    6950                 :            :    1 for scalars or {-1,-1,..} or {0,0,...} for vectors),
    6951                 :            :    and is of the indicated TYPE.  */
    6952                 :            : 
    6953                 :            : tree
    6954                 :   35106700 : constant_boolean_node (bool value, tree type)
    6955                 :            : {
    6956                 :   35106700 :   if (type == integer_type_node)
    6957                 :    6001580 :     return value ? integer_one_node : integer_zero_node;
    6958                 :   29105100 :   else if (type == boolean_type_node)
    6959                 :   27566800 :     return value ? boolean_true_node : boolean_false_node;
    6960                 :    1538260 :   else if (TREE_CODE (type) == VECTOR_TYPE)
    6961                 :        432 :     return build_vector_from_val (type,
    6962                 :        216 :                                   build_int_cst (TREE_TYPE (type),
    6963                 :        341 :                                                  value ? -1 : 0));
    6964                 :            :   else
    6965                 :    1538040 :     return fold_convert (type, value ? integer_one_node : integer_zero_node);
    6966                 :            : }
    6967                 :            : 
    6968                 :            : 
    6969                 :            : /* Transform `a + (b ? x : y)' into `b ? (a + x) : (a + y)'.
    6970                 :            :    Transform, `a + (x < y)' into `(x < y) ? (a + 1) : (a + 0)'.  Here
    6971                 :            :    CODE corresponds to the `+', COND to the `(b ? x : y)' or `(x < y)'
    6972                 :            :    expression, and ARG to `a'.  If COND_FIRST_P is nonzero, then the
    6973                 :            :    COND is the first argument to CODE; otherwise (as in the example
    6974                 :            :    given here), it is the second argument.  TYPE is the type of the
    6975                 :            :    original expression.  Return NULL_TREE if no simplification is
    6976                 :            :    possible.  */
    6977                 :            : 
    6978                 :            : static tree
    6979                 :     479853 : fold_binary_op_with_conditional_arg (location_t loc,
    6980                 :            :                                      enum tree_code code,
    6981                 :            :                                      tree type, tree op0, tree op1,
    6982                 :            :                                      tree cond, tree arg, int cond_first_p)
    6983                 :            : {
    6984                 :     959706 :   tree cond_type = cond_first_p ? TREE_TYPE (op0) : TREE_TYPE (op1);
    6985                 :     959706 :   tree arg_type = cond_first_p ? TREE_TYPE (op1) : TREE_TYPE (op0);
    6986                 :     479853 :   tree test, true_value, false_value;
    6987                 :     479853 :   tree lhs = NULL_TREE;
    6988                 :     479853 :   tree rhs = NULL_TREE;
    6989                 :     479853 :   enum tree_code cond_code = COND_EXPR;
    6990                 :            : 
    6991                 :            :   /* Do not move possibly trapping operations into the conditional as this
    6992                 :            :      pessimizes code and causes gimplification issues when applied late.  */
    6993                 :     480245 :   if (operation_could_trap_p (code, FLOAT_TYPE_P (type),
    6994                 :     148667 :                               ANY_INTEGRAL_TYPE_P (type)
    6995                 :     480245 :                               && TYPE_OVERFLOW_TRAPS (type), op1))
    6996                 :            :     return NULL_TREE;
    6997                 :            : 
    6998                 :     478711 :   if (TREE_CODE (cond) == COND_EXPR
    6999                 :     138858 :       || TREE_CODE (cond) == VEC_COND_EXPR)
    7000                 :            :     {
    7001                 :     340240 :       test = TREE_OPERAND (cond, 0);
    7002                 :     340240 :       true_value = TREE_OPERAND (cond, 1);
    7003                 :     340240 :       false_value = TREE_OPERAND (cond, 2);
    7004                 :            :       /* If this operand throws an expression, then it does not make
    7005                 :            :          sense to try to perform a logical or arithmetic operation
    7006                 :            :          involving it.  */
    7007                 :     340240 :       if (VOID_TYPE_P (TREE_TYPE (true_value)))
    7008                 :       5692 :         lhs = true_value;
    7009                 :     340240 :       if (VOID_TYPE_P (TREE_TYPE (false_value)))
    7010                 :          8 :         rhs = false_value;
    7011                 :            :     }
    7012                 :     138471 :   else if (!(TREE_CODE (type) != VECTOR_TYPE
    7013                 :     138471 :              && TREE_CODE (TREE_TYPE (cond)) == VECTOR_TYPE))
    7014                 :            :     {
    7015                 :     138265 :       tree testtype = TREE_TYPE (cond);
    7016                 :     138265 :       test = cond;
    7017                 :     138265 :       true_value = constant_boolean_node (true, testtype);
    7018                 :     138265 :       false_value = constant_boolean_node (false, testtype);
    7019                 :            :     }
    7020                 :            :   else
    7021                 :            :     /* Detect the case of mixing vector and scalar types - bail out.  */
    7022                 :            :     return NULL_TREE;
    7023                 :            : 
    7024                 :     478505 :   if (TREE_CODE (TREE_TYPE (test)) == VECTOR_TYPE)
    7025                 :        387 :     cond_code = VEC_COND_EXPR;
    7026                 :            : 
    7027                 :            :   /* This transformation is only worthwhile if we don't have to wrap ARG
    7028                 :            :      in a SAVE_EXPR and the operation can be simplified without recursing
    7029                 :            :      on at least one of the branches once its pushed inside the COND_EXPR.  */
    7030                 :     478505 :   if (!TREE_CONSTANT (arg)
    7031                 :     478505 :       && (TREE_SIDE_EFFECTS (arg)
    7032                 :     233883 :           || TREE_CODE (arg) == COND_EXPR || TREE_CODE (arg) == VEC_COND_EXPR
    7033                 :     329245 :           || TREE_CONSTANT (true_value) || TREE_CONSTANT (false_value)))
    7034                 :            :     return NULL_TREE;
    7035                 :            : 
    7036                 :     255567 :   arg = fold_convert_loc (loc, arg_type, arg);
    7037                 :     255567 :   if (lhs == 0)
    7038                 :            :     {
    7039                 :     251368 :       true_value = fold_convert_loc (loc, cond_type, true_value);
    7040                 :     251368 :       if (cond_first_p)
    7041                 :     249602 :         lhs = fold_build2_loc (loc, code, type, true_value, arg);
    7042                 :            :       else
    7043                 :       1766 :         lhs = fold_build2_loc (loc, code, type, arg, true_value);
    7044                 :            :     }
    7045                 :     255567 :   if (rhs == 0)
    7046                 :            :     {
    7047                 :     255559 :       false_value = fold_convert_loc (loc, cond_type, false_value);
    7048                 :     255559 :       if (cond_first_p)
    7049                 :     253431 :         rhs = fold_build2_loc (loc, code, type, false_value, arg);
    7050                 :            :       else
    7051                 :       2128 :         rhs = fold_build2_loc (loc, code, type, arg, false_value);
    7052                 :            :     }
    7053                 :            : 
    7054                 :            :   /* Check that we have simplified at least one of the branches.  */
    7055                 :     277428 :   if (!TREE_CONSTANT (arg) && !TREE_CONSTANT (lhs) && !TREE_CONSTANT (rhs))
    7056                 :            :     return NULL_TREE;
    7057                 :            : 
    7058                 :     244651 :   return fold_build3_loc (loc, cond_code, type, test, lhs, rhs);
    7059                 :            : }
    7060                 :            : 
    7061                 :            : 
    7062                 :            : /* Subroutine of fold() that checks for the addition of +/- 0.0.
    7063                 :            : 
    7064                 :            :    If !NEGATE, return true if ADDEND is +/-0.0 and, for all X of type
    7065                 :            :    TYPE, X + ADDEND is the same as X.  If NEGATE, return true if X -
    7066                 :            :    ADDEND is the same as X.
    7067                 :            : 
    7068                 :            :    X + 0 and X - 0 both give X when X is NaN, infinite, or nonzero
    7069                 :            :    and finite.  The problematic cases are when X is zero, and its mode
    7070                 :            :    has signed zeros.  In the case of rounding towards -infinity,
    7071                 :            :    X - 0 is not the same as X because 0 - 0 is -0.  In other rounding
    7072                 :            :    modes, X + 0 is not the same as X because -0 + 0 is 0.  */
    7073                 :            : 
    7074                 :            : bool
    7075                 :     129667 : fold_real_zero_addition_p (const_tree type, const_tree addend, int negate)
    7076                 :            : {
    7077                 :     129667 :   if (!real_zerop (addend))
    7078                 :            :     return false;
    7079                 :            : 
    7080                 :            :   /* Don't allow the fold with -fsignaling-nans.  */
    7081                 :     129085 :   if (HONOR_SNANS (type))
    7082                 :            :     return false;
    7083                 :            : 
    7084                 :            :   /* Allow the fold if zeros aren't signed, or their sign isn't important.  */
    7085                 :     128194 :   if (!HONOR_SIGNED_ZEROS (type))
    7086                 :            :     return true;
    7087                 :            : 
    7088                 :            :   /* There is no case that is safe for all rounding modes.  */
    7089                 :     114265 :   if (HONOR_SIGN_DEPENDENT_ROUNDING (type))
    7090                 :            :     return false;
    7091                 :            : 
    7092                 :            :   /* In a vector or complex, we would need to check the sign of all zeros.  */
    7093                 :     113705 :   if (TREE_CODE (addend) == VECTOR_CST)
    7094                 :        283 :     addend = uniform_vector_p (addend);
    7095                 :     113705 :   if (!addend || TREE_CODE (addend) != REAL_CST)
    7096                 :            :     return false;
    7097                 :            : 
    7098                 :            :   /* Treat x + -0 as x - 0 and x - -0 as x + 0.  */
    7099                 :     112451 :   if (REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (addend)))
    7100                 :         80 :     negate = !negate;
    7101                 :            : 
    7102                 :            :   /* The mode has signed zeros, and we have to honor their sign.
    7103                 :            :      In this situation, there is only one case we can return true for.
    7104                 :            :      X - 0 is the same as X with default rounding.  */
    7105                 :     112451 :   return negate;
    7106                 :            : }
    7107                 :            : 
    7108                 :            : /* Subroutine of match.pd that optimizes comparisons of a division by
    7109                 :            :    a nonzero integer constant against an integer constant, i.e.
    7110                 :            :    X/C1 op C2.
    7111                 :            : 
    7112                 :            :    CODE is the comparison operator: EQ_EXPR, NE_EXPR, GT_EXPR, LT_EXPR,
    7113                 :            :    GE_EXPR or LE_EXPR.  ARG01 and ARG1 must be a INTEGER_CST.  */
    7114                 :            : 
    7115                 :            : enum tree_code
    7116                 :    1427470 : fold_div_compare (enum tree_code code, tree c1, tree c2, tree *lo,
    7117                 :            :                   tree *hi, bool *neg_overflow)
    7118                 :            : {
    7119                 :    1427470 :   tree prod, tmp, type = TREE_TYPE (c1);
    7120                 :    1427470 :   signop sign = TYPE_SIGN (type);
    7121                 :    1427470 :   wi::overflow_type overflow;
    7122                 :            : 
    7123                 :            :   /* We have to do this the hard way to detect unsigned overflow.
    7124                 :            :      prod = int_const_binop (MULT_EXPR, c1, c2);  */
    7125                 :    1427470 :   wide_int val = wi::mul (wi::to_wide (c1), wi::to_wide (c2), sign, &overflow);
    7126                 :    1427470 :   prod = force_fit_type (type, val, -1, overflow);
    7127                 :    1427470 :   *neg_overflow = false;
    7128                 :            : 
    7129                 :    1427470 :   if (sign == UNSIGNED)
    7130                 :            :     {
    7131                 :    1412180 :       tmp = int_const_binop (MINUS_EXPR, c1, build_int_cst (type, 1));
    7132                 :    1412180 :       *lo = prod;
    7133                 :            : 
    7134                 :            :       /* Likewise *hi = int_const_binop (PLUS_EXPR, prod, tmp).  */
    7135                 :    1412180 :       val = wi::add (wi::to_wide (prod), wi::to_wide (tmp), sign, &overflow);
    7136                 :    1412180 :       *hi = force_fit_type (type, val, -1, overflow | TREE_OVERFLOW (prod));
    7137                 :            :     }
    7138                 :      15290 :   else if (tree_int_cst_sgn (c1) >= 0)
    7139                 :            :     {
    7140                 :      14388 :       tmp = int_const_binop (MINUS_EXPR, c1, build_int_cst (type, 1));
    7141                 :      14388 :       switch (tree_int_cst_sgn (c2))
    7142                 :            :         {
    7143                 :       2631 :         case -1:
    7144                 :       2631 :           *neg_overflow = true;
    7145                 :       2631 :           *lo = int_const_binop (MINUS_EXPR, prod, tmp);
    7146                 :       2631 :           *hi = prod;
    7147                 :       2631 :           break;
    7148                 :            : 
    7149                 :       8225 :         case 0:
    7150                 :       8225 :           *lo = fold_negate_const (tmp, type);
    7151                 :       8225 :           *hi = tmp;
    7152                 :       8225 :           break;
    7153                 :            : 
    7154                 :       3532 :         case 1:
    7155                 :       3532 :           *hi = int_const_binop (PLUS_EXPR, prod, tmp);
    7156                 :       3532 :           *lo = prod;
    7157                 :       3532 :           break;
    7158                 :            : 
    7159                 :          0 :         default:
    7160                 :          0 :           gcc_unreachable ();
    7161                 :            :         }
    7162                 :            :     }
    7163                 :            :   else
    7164                 :            :     {
    7165                 :            :       /* A negative divisor reverses the relational operators.  */
    7166                 :        902 :       code = swap_tree_comparison (code);
    7167                 :            : 
    7168                 :        902 :       tmp = int_const_binop (PLUS_EXPR, c1, build_int_cst (type, 1));
    7169                 :        902 :       switch (tree_int_cst_sgn (c2))
    7170                 :            :         {
    7171                 :         91 :         case -1:
    7172                 :         91 :           *hi = int_const_binop (MINUS_EXPR, prod, tmp);
    7173                 :         91 :           *lo = prod;
    7174                 :         91 :           break;
    7175                 :            : 
    7176                 :        121 :         case 0:
    7177                 :        121 :           *hi = fold_negate_const (tmp, type);
    7178                 :        121 :           *lo = tmp;
    7179                 :        121 :           break;
    7180                 :            : 
    7181                 :        690 :         case 1:
    7182                 :        690 :           *neg_overflow = true;
    7183                 :        690 :           *lo = int_const_binop (PLUS_EXPR, prod, tmp);
    7184                 :        690 :           *hi = prod;
    7185                 :        690 :           break;
    7186                 :            : 
    7187                 :          0 :         default:
    7188                 :          0 :           gcc_unreachable ();
    7189                 :            :         }
    7190                 :            :     }
    7191                 :            : 
    7192                 :    1427470 :   if (code != EQ_EXPR && code != NE_EXPR)
    7193                 :            :     return code;
    7194                 :            : 
    7195                 :       8001 :   if (TREE_OVERFLOW (*lo)
    7196                 :       8001 :       || operand_equal_p (*lo, TYPE_MIN_VALUE (type), 0))
    7197                 :        646 :     *lo = NULL_TREE;
    7198                 :       8001 :   if (TREE_OVERFLOW (*hi)
    7199                 :       8001 :       || operand_equal_p (*hi, TYPE_MAX_VALUE (type), 0))
    7200                 :         87 :     *hi = NULL_TREE;
    7201                 :            : 
    7202                 :            :   return code;
    7203                 :            : }
    7204                 :            : 
    7205                 :            : 
    7206                 :            : /* If CODE with arguments ARG0 and ARG1 represents a single bit
    7207                 :            :    equality/inequality test, then return a simplified form of the test
    7208                 :            :    using a sign testing.  Otherwise return NULL.  TYPE is the desired
    7209                 :            :    result type.  */
    7210                 :            : 
    7211                 :            : static tree
    7212                 :       2368 : fold_single_bit_test_into_sign_test (location_t loc,
    7213                 :            :                                      enum tree_code code, tree arg0, tree arg1,
    7214                 :            :                                      tree result_type)
    7215                 :            : {
    7216                 :            :   /* If this is testing a single bit, we can optimize the test.  */
    7217                 :       2368 :   if ((code == NE_EXPR || code == EQ_EXPR)
    7218                 :       2368 :       && TREE_CODE (arg0) == BIT_AND_EXPR && integer_zerop (arg1)
    7219                 :       4736 :       && integer_pow2p (TREE_OPERAND (arg0, 1)))
    7220                 :            :     {
    7221                 :            :       /* If we have (A & C) != 0 where C is the sign bit of A, convert
    7222                 :            :          this into A < 0.  Similarly for (A & C) == 0 into A >= 0.  */
    7223                 :       2368 :       tree arg00 = sign_bit_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg0, 1));
    7224                 :            : 
    7225                 :       2368 :       if (arg00 != NULL_TREE
    7226                 :            :           /* This is only a win if casting to a signed type is cheap,
    7227                 :            :              i.e. when arg00's type is not a partial mode.  */
    7228                 :       2372 :           && type_has_mode_precision_p (TREE_TYPE (arg00)))
    7229                 :            :         {
    7230                 :          0 :           tree stype = signed_type_for (TREE_TYPE (arg00));
    7231                 :          0 :           return fold_build2_loc (loc, code == EQ_EXPR ? GE_EXPR : LT_EXPR,
    7232                 :            :                               result_type,
    7233                 :            :                               fold_convert_loc (loc, stype, arg00),
    7234                 :          0 :                               build_int_cst (stype, 0));
    7235                 :            :         }
    7236                 :            :     }
    7237                 :            : 
    7238                 :            :   return NULL_TREE;
    7239                 :            : }
    7240                 :            : 
    7241                 :            : /* If CODE with arguments ARG0 and ARG1 represents a single bit
    7242                 :            :    equality/inequality test, then return a simplified form of
    7243                 :            :    the test using shifts and logical operations.  Otherwise return
    7244                 :            :    NULL.  TYPE is the desired result type.  */
    7245                 :            : 
    7246                 :            : tree
    7247                 :       2368 : fold_single_bit_test (location_t loc, enum tree_code code,
    7248                 :            :                       tree arg0, tree arg1, tree result_type)
    7249                 :            : {
    7250                 :            :   /* If this is testing a single bit, we can optimize the test.  */
    7251                 :       2368 :   if ((code == NE_EXPR || code == EQ_EXPR)
    7252                 :       2368 :       && TREE_CODE (arg0) == BIT_AND_EXPR && integer_zerop (arg1)
    7253                 :       4736 :       && integer_pow2p (TREE_OPERAND (arg0, 1)))
    7254                 :            :     {
    7255                 :       2368 :       tree inner = TREE_OPERAND (arg0, 0);
    7256                 :       2368 :       tree type = TREE_TYPE (arg0);
    7257                 :       2368 :       int bitnum = tree_log2 (TREE_OPERAND (arg0, 1));
    7258                 :       2368 :       scalar_int_mode operand_mode = SCALAR_INT_TYPE_MODE (type);
    7259                 :       2368 :       int ops_unsigned;
    7260                 :       2368 :       tree signed_type, unsigned_type, intermediate_type;
    7261                 :       2368 :       tree tem, one;
    7262                 :            : 
    7263                 :            :       /* First, see if we can fold the single bit test into a sign-bit
    7264                 :            :          test.  */
    7265                 :       2368 :       tem = fold_single_bit_test_into_sign_test (loc, code, arg0, arg1,
    7266                 :            :                                                  result_type);
    7267                 :       2368 :       if (tem)
    7268                 :            :         return tem;
    7269                 :            : 
    7270                 :            :       /* Otherwise we have (A & C) != 0 where C is a single bit,
    7271                 :            :          convert that into ((A >> C2) & 1).  Where C2 = log2(C).
    7272                 :            :          Similarly for (A & C) == 0.  */
    7273                 :            : 
    7274                 :            :       /* If INNER is a right shift of a constant and it plus BITNUM does
    7275                 :            :          not overflow, adjust BITNUM and INNER.  */
    7276                 :       2368 :       if (TREE_CODE (inner) == RSHIFT_EXPR
    7277                 :          0 :           && TREE_CODE (TREE_OPERAND (inner, 1)) == INTEGER_CST
    7278                 :          0 :           && bitnum < TYPE_PRECISION (type)
    7279                 :       2368 :           && wi::ltu_p (wi::to_wide (TREE_OPERAND (inner, 1)),
    7280                 :       2368 :                         TYPE_PRECISION (type) - bitnum))
    7281                 :            :         {
    7282                 :          0 :           bitnum += tree_to_uhwi (TREE_OPERAND (inner, 1));
    7283                 :          0 :           inner = TREE_OPERAND (inner, 0);
    7284                 :            :         }
    7285                 :            : 
    7286                 :            :       /* If we are going to be able to omit the AND below, we must do our
    7287                 :            :          operations as unsigned.  If we must use the AND, we have a choice.
    7288                 :            :          Normally unsigned is faster, but for some machines signed is.  */
    7289                 :       2368 :       ops_unsigned = (load_extend_op (operand_mode) == SIGN_EXTEND
    7290                 :            :                       && !flag_syntax_only) ? 0 : 1;
    7291                 :            : 
    7292                 :       2368 :       signed_type = lang_hooks.types.type_for_mode (operand_mode, 0);
    7293                 :       2368 :       unsigned_type = lang_hooks.types.type_for_mode (operand_mode, 1);
    7294                 :       2368 :       intermediate_type = ops_unsigned ? unsigned_type : signed_type;
    7295                 :       2368 :       inner = fold_convert_loc (loc, intermediate_type, inner);
    7296                 :            : 
    7297                 :       2368 :       if (bitnum != 0)
    7298                 :       2320 :         inner = build2 (RSHIFT_EXPR, intermediate_type,
    7299                 :            :                         inner, size_int (bitnum));
    7300                 :            : 
    7301                 :       2368 :       one = build_int_cst (intermediate_type, 1);
    7302                 :            : 
    7303                 :       2368 :       if (code == EQ_EXPR)
    7304                 :        378 :         inner = fold_build2_loc (loc, BIT_XOR_EXPR, intermediate_type, inner, one);
    7305                 :            : 
    7306                 :            :       /* Put the AND last so it can combine with more things.  */
    7307                 :       2368 :       inner = build2 (BIT_AND_EXPR, intermediate_type, inner, one);
    7308                 :            : 
    7309                 :            :       /* Make sure to return the proper type.  */
    7310                 :       2368 :       inner = fold_convert_loc (loc, result_type, inner);
    7311                 :            : 
    7312                 :       2368 :       return inner;
    7313                 :            :     }
    7314                 :            :   return NULL_TREE;
    7315                 :            : }
    7316                 :            : 
    7317                 :            : /* Test whether it is preferable two swap two operands, ARG0 and
    7318                 :            :    ARG1, for example because ARG0 is an integer constant and ARG1
    7319                 :            :    isn't.  */
    7320                 :            : 
    7321                 :            : bool
    7322                 :  775090000 : tree_swap_operands_p (const_tree arg0, const_tree arg1)
    7323                 :            : {
    7324                 :  775090000 :   if (CONSTANT_CLASS_P (arg1))
    7325                 :            :     return 0;
    7326                 :  230619000 :   if (CONSTANT_CLASS_P (arg0))
    7327                 :            :     return 1;
    7328                 :            : 
    7329                 :  213894000 :   STRIP_NOPS (arg0);
    7330                 :  213894000 :   STRIP_NOPS (arg1);
    7331                 :            : 
    7332                 :  213894000 :   if (TREE_CONSTANT (arg1))
    7333                 :            :     return 0;
    7334                 :  201949000 :   if (TREE_CONSTANT (arg0))
    7335                 :            :     return 1;
    7336                 :            : 
    7337                 :            :   /* It is preferable to swap two SSA_NAME to ensure a canonical form
    7338                 :            :      for commutative and comparison operators.  Ensuring a canonical
    7339                 :            :      form allows the optimizers to find additional redundancies without
    7340                 :            :      having to explicitly check for both orderings.  */
    7341                 :  201567000 :   if (TREE_CODE (arg0) == SSA_NAME
    7342                 :  164451000 :       && TREE_CODE (arg1) == SSA_NAME
    7343                 :  361964000 :       && SSA_NAME_VERSION (arg0) > SSA_NAME_VERSION (arg1))
    7344                 :            :     return 1;
    7345                 :            : 
    7346                 :            :   /* Put SSA_NAMEs last.  */
    7347                 :  186367000 :   if (TREE_CODE (arg1) == SSA_NAME)
    7348                 :            :     return 0;
    7349                 :   28410100 :   if (TREE_CODE (arg0) == SSA_NAME)
    7350                 :            :     return 1;
    7351                 :            : 
    7352                 :            :   /* Put variables last.  */
    7353                 :   24355900 :   if (DECL_P (arg1))
    7354                 :            :     return 0;
    7355                 :   18411700 :   if (DECL_P (arg0))
    7356                 :     498834 :     return 1;
    7357                 :            : 
    7358                 :            :   return 0;
    7359                 :            : }
    7360                 :            : 
    7361                 :            : 
    7362                 :            : /* Fold A < X && A + 1 > Y to A < X && A >= Y.  Normally A + 1 > Y
    7363                 :            :    means A >= Y && A != MAX, but in this case we know that
    7364                 :            :    A < X <= MAX.  INEQ is A + 1 > Y, BOUND is A < X.  */
    7365                 :            : 
    7366                 :            : static tree
    7367                 :   12371100 : fold_to_nonsharp_ineq_using_bound (location_t loc, tree ineq, tree bound)
    7368                 :            : {
    7369                 :   12371100 :   tree a, typea, type = TREE_TYPE (ineq), a1, diff, y;
    7370                 :            : 
    7371                 :   12371100 :   if (TREE_CODE (bound) == LT_EXPR)
    7372                 :    3006620 :     a = TREE_OPERAND (bound, 0);
    7373                 :    9364480 :   else if (TREE_CODE (bound) == GT_EXPR)
    7374                 :    1686090 :     a = TREE_OPERAND (bound, 1);
    7375                 :            :   else
    7376                 :            :     return NULL_TREE;
    7377                 :            : 
    7378                 :    4692710 :   typea = TREE_TYPE (a);
    7379                 :    4692710 :   if (!INTEGRAL_TYPE_P (typea)
    7380                 :      43314 :       && !POINTER_TYPE_P (typea))
    7381                 :            :     return NULL_TREE;
    7382                 :            : 
    7383                 :    4682750 :   if (TREE_CODE (ineq) == LT_EXPR)
    7384                 :            :     {
    7385                 :     958890 :       a1 = TREE_OPERAND (ineq, 1);
    7386                 :     958890 :       y = TREE_OPERAND (ineq, 0);
    7387                 :            :     }
    7388                 :    3723860 :   else if (TREE_CODE (ineq) == GT_EXPR)
    7389                 :            :     {
    7390                 :     687151 :       a1 = TREE_OPERAND (ineq, 0);
    7391                 :     687151 :       y = TREE_OPERAND (ineq, 1);
    7392                 :            :     }
    7393                 :            :   else
    7394                 :            :     return NULL_TREE;
    7395                 :            : 
    7396                 :    1646040 :   if (TREE_TYPE (a1) != typea)
    7397                 :            :     return NULL_TREE;
    7398                 :            : 
    7399                 :    1159760 :   if (POINTER_TYPE_P (typea))
    7400                 :            :     {
    7401                 :            :       /* Convert the pointer types into integer before taking the difference.  */
    7402                 :       1468 :       tree ta = fold_convert_loc (loc, ssizetype, a);
    7403                 :       1468 :       tree ta1 = fold_convert_loc (loc, ssizetype, a1);
    7404                 :       1468 :       diff = fold_binary_loc (loc, MINUS_EXPR, ssizetype, ta1, ta);
    7405                 :            :     }
    7406                 :            :   else
    7407                 :    1158300 :     diff = fold_binary_loc (loc, MINUS_EXPR, typea, a1, a);
    7408                 :            : 
    7409                 :    1159760 :   if (!diff || !integer_onep (diff))
    7410                 :    1155980 :    return NULL_TREE;
    7411                 :            : 
    7412                 :       3783 :   return fold_build2_loc (loc, GE_EXPR, type, a, y);
    7413                 :            : }
    7414                 :            : 
    7415                 :            : /* Fold a sum or difference of at least one multiplication.
    7416                 :            :    Returns the folded tree or NULL if no simplification could be made.  */
    7417                 :            : 
    7418                 :            : static tree
    7419                 :    4323730 : fold_plusminus_mult_expr (location_t loc, enum tree_code code, tree type,
    7420                 :            :                           tree arg0, tree arg1)
    7421                 :            : {
    7422                 :    4323730 :   tree arg00, arg01, arg10, arg11;
    7423                 :    4323730 :   tree alt0 = NULL_TREE, alt1 = NULL_TREE, same;
    7424                 :            : 
    7425                 :            :   /* (A * C) +- (B * C) -> (A+-B) * C.
    7426                 :            :      (A * C) +- A -> A * (C+-1).
    7427                 :            :      We are most concerned about the case where C is a constant,
    7428                 :            :      but other combinations show up during loop reduction.  Since
    7429                 :            :      it is not difficult, try all four possibilities.  */
    7430                 :            : 
    7431                 :    4323730 :   if (TREE_CODE (arg0) == MULT_EXPR)
    7432                 :            :     {
    7433                 :    3540490 :       arg00 = TREE_OPERAND (arg0, 0);
    7434                 :    3540490 :       arg01 = TREE_OPERAND (arg0, 1);
    7435                 :            :     }
    7436                 :     783242 :   else if (TREE_CODE (arg0) == INTEGER_CST)
    7437                 :            :     {
    7438                 :      85398 :       arg00 = build_one_cst (type);
    7439                 :      85398 :       arg01 = arg0;
    7440                 :            :     }
    7441                 :            :   else
    7442                 :            :     {
    7443                 :            :       /* We cannot generate constant 1 for fract.  */
    7444                 :    2791380 :       if (ALL_FRACT_MODE_P (TYPE_MODE (type)))
    7445                 :          0 :         return NULL_TREE;
    7446                 :     697844 :       arg00 = arg0;
    7447                 :     697844 :       arg01 = build_one_cst (type);
    7448                 :            :     }
    7449                 :    4323730 :   if (TREE_CODE (arg1) == MULT_EXPR)
    7450                 :            :     {
    7451                 :    1340670 :       arg10 = TREE_OPERAND (arg1, 0);
    7452                 :    1340670 :       arg11 = TREE_OPERAND (arg1, 1);
    7453                 :            :     }
    7454                 :    2983050 :   else if (TREE_CODE (arg1) == INTEGER_CST)
    7455                 :            :     {
    7456                 :    1493540 :       arg10 = build_one_cst (type);
    7457                 :            :       /* As we canonicalize A - 2 to A + -2 get rid of that sign for
    7458                 :            :          the purpose of this canonicalization.  */
    7459                 :    1615840 :       if (wi::neg_p (wi::to_wide (arg1), TYPE_SIGN (TREE_TYPE (arg1)))
    7460                 :      62103 :           && negate_expr_p (arg1)
    7461                 :     242074 :           && code == PLUS_EXPR)
    7462                 :            :         {
    7463                 :      59891 :           arg11 = negate_expr (arg1);
    7464                 :      59891 :           code = MINUS_EXPR;
    7465                 :            :         }
    7466                 :            :       else
    7467                 :            :         arg11 = arg1;
    7468                 :            :     }
    7469                 :            :   else
    7470                 :            :     {
    7471                 :            :       /* We cannot generate constant 1 for fract.  */
    7472                 :    5958040 :       if (ALL_FRACT_MODE_P (TYPE_MODE (type)))
    7473                 :          0 :         return NULL_TREE;
    7474                 :    1489510 :       arg10 = arg1;
    7475                 :    1489510 :       arg11 = build_one_cst (type);
    7476                 :            :     }
    7477                 :    4323730 :   same = NULL_TREE;
    7478                 :            : 
    7479                 :            :   /* Prefer factoring a common non-constant.  */
    7480                 :    4323730 :   if (operand_equal_p (arg00, arg10, 0))
    7481                 :            :     same = arg00, alt0 = arg01, alt1 = arg11;
    7482                 :    4321240 :   else if (operand_equal_p (arg01, arg11, 0))
    7483                 :            :     same = arg01, alt0 = arg00, alt1 = arg10;
    7484                 :    4297930 :   else if (operand_equal_p (arg00, arg11, 0))
    7485                 :            :     same = arg00, alt0 = arg01, alt1 = arg10;
    7486                 :    4297360 :   else if (operand_equal_p (arg01, arg10, 0))
    7487                 :            :     same = arg01, alt0 = arg00, alt1 = arg11;
    7488                 :            : 
    7489                 :            :   /* No identical multiplicands; see if we can find a common
    7490                 :            :      power-of-two factor in non-power-of-two multiplies.  This
    7491                 :            :      can help in multi-dimensional array access.  */
    7492                 :    4294000 :   else if (tree_fits_shwi_p (arg01) && tree_fits_shwi_p (arg11))
    7493                 :            :     {
    7494                 :    3256920 :       HOST_WIDE_INT int01 = tree_to_shwi (arg01);
    7495                 :    3256920 :       HOST_WIDE_INT int11 = tree_to_shwi (arg11);
    7496                 :    3256920 :       HOST_WIDE_INT tmp;
    7497                 :    3256920 :       bool swap = false;
    7498                 :    3256920 :       tree maybe_same;
    7499                 :            : 
    7500                 :            :       /* Move min of absolute values to int11.  */
    7501                 :    9770770 :       if (absu_hwi (int01) < absu_hwi (int11))
    7502                 :            :         {
    7503                 :    3256920 :           tmp = int01, int01 = int11, int11 = tmp;
    7504                 :            :           alt0 = arg00, arg00 = arg10, arg10 = alt0;
    7505                 :            :           maybe_same = arg01;
    7506                 :            :           swap = true;
    7507                 :            :         }
    7508                 :            :       else
    7509                 :    1717590 :         maybe_same = arg11;
    7510                 :            : 
    7511                 :    3256920 :       const unsigned HOST_WIDE_INT factor = absu_hwi (int11);
    7512                 :    3256920 :       if (factor > 1
    7513                 :    5226470 :           && pow2p_hwi (factor)
    7514                 :     902744 :           && (int01 & (factor - 1)) == 0
    7515                 :            :           /* The remainder should not be a constant, otherwise we
    7516                 :            :              end up folding i * 4 + 2 to (i * 2 + 1) * 2 which has
    7517                 :            :              increased the number of multiplications necessary.  */
    7518                 :    3987080 :           && TREE_CODE (arg10) != INTEGER_CST)
    7519                 :            :         {
    7520                 :     572903 :           alt0 = fold_build2_loc (loc, MULT_EXPR, TREE_TYPE (arg00), arg00,
    7521                 :     572903 :                               build_int_cst (TREE_TYPE (arg00),
    7522                 :     572903 :                                              int01 / int11));
    7523                 :     572903 :           alt1 = arg10;
    7524                 :     572903 :           same = maybe_same;
    7525                 :     572903 :           if (swap)
    7526                 :     510772 :             maybe_same = alt0, alt0 = alt1, alt1 = maybe_same;
    7527                 :            :         }
    7528                 :            :     }
    7529                 :            : 
    7530                 :    4323730 :   if (!same)
    7531                 :            :     return NULL_TREE;
    7532                 :            : 
    7533                 :         14 :   if (! ANY_INTEGRAL_TYPE_P (type)
    7534                 :     703037 :       || TYPE_OVERFLOW_WRAPS (type)
    7535                 :            :       /* We are neither factoring zero nor minus one.  */
    7536                 :     703037 :       || TREE_CODE (same) == INTEGER_CST)
    7537                 :     598590 :     return fold_build2_loc (loc, MULT_EXPR, type,
    7538                 :            :                         fold_build2_loc (loc, code, type,
    7539                 :            :                                      fold_convert_loc (loc, type, alt0),
    7540                 :            :                                      fold_convert_loc (loc, type, alt1)),
    7541                 :     598590 :                         fold_convert_loc (loc, type, same));
    7542                 :            : 
    7543                 :            :   /* Same may be zero and thus the operation 'code' may overflow.  Likewise
    7544                 :            :      same may be minus one and thus the multiplication may overflow.  Perform
    7545                 :            :      the sum operation in an unsigned type.  */
    7546                 :       4045 :   tree utype = unsigned_type_for (type);
    7547                 :       4045 :   tree tem = fold_build2_loc (loc, code, utype,
    7548                 :            :                               fold_convert_loc (loc, utype, alt0),
    7549                 :            :                               fold_convert_loc (loc, utype, alt1));
    7550                 :            :   /* If the sum evaluated to a constant that is not -INF the multiplication
    7551                 :            :      cannot overflow.  */
    7552                 :       4045 :   if (TREE_CODE (tem) == INTEGER_CST
    7553                 :       5071 :       && (wi::to_wide (tem)
    7554                 :       5071 :           != wi::min_value (TYPE_PRECISION (utype), SIGNED)))
    7555                 :       1012 :     return fold_build2_loc (loc, MULT_EXPR, type,
    7556                 :       1012 :                             fold_convert (type, tem), same);
    7557                 :            : 
    7558                 :            :   /* Do not resort to unsigned multiplication because
    7559                 :            :      we lose the no-overflow property of the expression.  */
    7560                 :            :   return NULL_TREE;
    7561                 :            : }
    7562                 :            : 
    7563                 :            : /* Subroutine of native_encode_expr.  Encode the INTEGER_CST
    7564                 :            :    specified by EXPR into the buffer PTR of length LEN bytes.
    7565                 :            :    Return the number of bytes placed in the buffer, or zero
    7566                 :            :    upon failure.  */
    7567                 :            : 
    7568                 :            : static int
    7569                 :    6524690 : native_encode_int (const_tree expr, unsigned char *ptr, int len, int off)
    7570                 :            : {
    7571                 :    6524690 :   tree type = TREE_TYPE (expr);
    7572                 :    6524690 :   int total_bytes = GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (type));
    7573                 :    6524690 :   int byte, offset, word, words;
    7574                 :    6524690 :   unsigned char value;
    7575                 :            : 
    7576                 :    6524690 :   if ((off == -1 && total_bytes > len) || off >= total_bytes)
    7577                 :            :     return 0;
    7578                 :    6524670 :   if (off == -1)
    7579                 :    6071240 :     off = 0;
    7580                 :            : 
    7581                 :    6524670 :   if (ptr == NULL)
    7582                 :            :     /* Dry run.  */
    7583                 :    1573540 :     return MIN (len, total_bytes - off);
    7584                 :            : 
    7585                 :   25101800 :   words = total_bytes / UNITS_PER_WORD;
    7586                 :            : 
    7587                 :   25101800 :   for (byte = 0; byte < total_bytes; byte++)
    7588                 :            :     {
    7589                 :   20150600 :       int bitpos = byte * BITS_PER_UNIT;
    7590                 :            :       /* Extend EXPR according to TYPE_SIGN if the precision isn't a whole
    7591                 :            :          number of bytes.  */
    7592                 :   20150600 :       value = wi::extract_uhwi (wi::to_widest (expr), bitpos, BITS_PER_UNIT);
    7593                 :            : 
    7594                 :   22213700 :       if (total_bytes > UNITS_PER_WORD)
    7595                 :            :         {
    7596                 :     325856 :           word = byte / UNITS_PER_WORD;
    7597                 :     325856 :           if (WORDS_BIG_ENDIAN)
    7598                 :            :             word = (words - 1) - word;
    7599                 :     325856 :           offset = word * UNITS_PER_WORD;
    7600                 :     325856 :           if (BYTES_BIG_ENDIAN)
    7601                 :            :             offset += (UNITS_PER_WORD - 1) - (byte % UNITS_PER_WORD);
    7602                 :            :           else
    7603                 :     325856 :             offset += byte % UNITS_PER_WORD;
    7604                 :            :         }
    7605                 :            :       else
    7606                 :            :         offset = BYTES_BIG_ENDIAN ? (total_bytes - 1) - byte : byte;
    7607                 :   20150600 :       if (offset >= off && offset - off < len)
    7608                 :   20138200 :         ptr[offset - off] = value;
    7609                 :            :     }
    7610                 :    4951140 :   return MIN (len, total_bytes - off);
    7611                 :            : }
    7612                 :            : 
    7613                 :            : 
    7614                 :            : /* Subroutine of native_encode_expr.  Encode the FIXED_CST
    7615                 :            :    specified by EXPR into the buffer PTR of length LEN bytes.
    7616                 :            :    Return the number of bytes placed in the buffer, or zero
    7617                 :            :    upon failure.  */
    7618                 :            : 
    7619                 :            : static int
    7620                 :          0 : native_encode_fixed (const_tree expr, unsigned char *ptr, int len, int off)
    7621                 :            : {
    7622                 :          0 :   tree type = TREE_TYPE (expr);
    7623                 :          0 :   scalar_mode mode = SCALAR_TYPE_MODE (type);
    7624                 :          0 :   int total_bytes = GET_MODE_SIZE (mode);
    7625                 :          0 :   FIXED_VALUE_TYPE value;
    7626                 :          0 :   tree i_value, i_type;
    7627                 :            : 
    7628                 :          0 :   if (total_bytes * BITS_PER_UNIT > HOST_BITS_PER_DOUBLE_INT)
    7629                 :            :     return 0;
    7630                 :            : 
    7631                 :          0 :   i_type = lang_hooks.types.type_for_size (GET_MODE_BITSIZE (mode), 1);
    7632                 :            : 
    7633                 :          0 :   if (NULL_TREE == i_type || TYPE_PRECISION (i_type) != total_bytes)
    7634                 :            :     return 0;
    7635                 :            :   
    7636                 :          0 :   value = TREE_FIXED_CST (expr);
    7637                 :          0 :   i_value = double_int_to_tree (i_type, value.data);
    7638                 :            : 
    7639                 :          0 :   return native_encode_int (i_value, ptr, len, off);
    7640                 :            : }
    7641                 :            : 
    7642                 :            : 
    7643                 :            : /* Subroutine of native_encode_expr.  Encode the REAL_CST