LCOV - code coverage report
Current view: top level - gcc - simplify-rtx.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 88.7 % 4585 4068
Test Date: 2025-03-22 13:13:03 Functions: 96.0 % 75 72
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* RTL simplification functions for GNU compiler.
       2                 :             :    Copyright (C) 1987-2025 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                 :             : 
      21                 :             : #include "config.h"
      22                 :             : #include "system.h"
      23                 :             : #include "coretypes.h"
      24                 :             : #include "backend.h"
      25                 :             : #include "target.h"
      26                 :             : #include "rtl.h"
      27                 :             : #include "tree.h"
      28                 :             : #include "predict.h"
      29                 :             : #include "memmodel.h"
      30                 :             : #include "optabs.h"
      31                 :             : #include "emit-rtl.h"
      32                 :             : #include "recog.h"
      33                 :             : #include "diagnostic-core.h"
      34                 :             : #include "varasm.h"
      35                 :             : #include "flags.h"
      36                 :             : #include "selftest.h"
      37                 :             : #include "selftest-rtl.h"
      38                 :             : #include "rtx-vector-builder.h"
      39                 :             : #include "rtlanal.h"
      40                 :             : 
      41                 :             : /* Simplification and canonicalization of RTL.  */
      42                 :             : 
      43                 :             : /* Much code operates on (low, high) pairs; the low value is an
      44                 :             :    unsigned wide int, the high value a signed wide int.  We
      45                 :             :    occasionally need to sign extend from low to high as if low were a
      46                 :             :    signed wide int.  */
      47                 :             : #define HWI_SIGN_EXTEND(low) \
      48                 :             :   ((((HOST_WIDE_INT) low) < 0) ? HOST_WIDE_INT_M1 : HOST_WIDE_INT_0)
      49                 :             : 
      50                 :             : static bool plus_minus_operand_p (const_rtx);
      51                 :             : 
      52                 :             : /* Negate I, which satisfies poly_int_rtx_p.  MODE is the mode of I.  */
      53                 :             : 
      54                 :             : static rtx
      55                 :     8476850 : neg_poly_int_rtx (machine_mode mode, const_rtx i)
      56                 :             : {
      57                 :     8476850 :   return immed_wide_int_const (-wi::to_poly_wide (i, mode), mode);
      58                 :             : }
      59                 :             : 
      60                 :             : /* Test whether expression, X, is an immediate constant that represents
      61                 :             :    the most significant bit of machine mode MODE.  */
      62                 :             : 
      63                 :             : bool
      64                 :     5915509 : mode_signbit_p (machine_mode mode, const_rtx x)
      65                 :             : {
      66                 :     5915509 :   unsigned HOST_WIDE_INT val;
      67                 :     5915509 :   unsigned int width;
      68                 :     5915509 :   scalar_int_mode int_mode;
      69                 :             : 
      70                 :     5915509 :   if (!is_int_mode (mode, &int_mode))
      71                 :             :     return false;
      72                 :             : 
      73                 :     5915501 :   width = GET_MODE_PRECISION (int_mode);
      74                 :     5915501 :   if (width == 0)
      75                 :             :     return false;
      76                 :             : 
      77                 :     5915501 :   if (width <= HOST_BITS_PER_WIDE_INT
      78                 :     5913983 :       && CONST_INT_P (x))
      79                 :     5797280 :     val = INTVAL (x);
      80                 :             : #if TARGET_SUPPORTS_WIDE_INT
      81                 :      118221 :   else if (CONST_WIDE_INT_P (x))
      82                 :             :     {
      83                 :         474 :       unsigned int i;
      84                 :         474 :       unsigned int elts = CONST_WIDE_INT_NUNITS (x);
      85                 :         474 :       if (elts != (width + HOST_BITS_PER_WIDE_INT - 1) / HOST_BITS_PER_WIDE_INT)
      86                 :             :         return false;
      87                 :         888 :       for (i = 0; i < elts - 1; i++)
      88                 :         474 :         if (CONST_WIDE_INT_ELT (x, i) != 0)
      89                 :             :           return false;
      90                 :         414 :       val = CONST_WIDE_INT_ELT (x, elts - 1);
      91                 :         414 :       width %= HOST_BITS_PER_WIDE_INT;
      92                 :         414 :       if (width == 0)
      93                 :             :         width = HOST_BITS_PER_WIDE_INT;
      94                 :             :     }
      95                 :             : #else
      96                 :             :   else if (width <= HOST_BITS_PER_DOUBLE_INT
      97                 :             :            && CONST_DOUBLE_AS_INT_P (x)
      98                 :             :            && CONST_DOUBLE_LOW (x) == 0)
      99                 :             :     {
     100                 :             :       val = CONST_DOUBLE_HIGH (x);
     101                 :             :       width -= HOST_BITS_PER_WIDE_INT;
     102                 :             :     }
     103                 :             : #endif
     104                 :             :   else
     105                 :             :     /* X is not an integer constant.  */
     106                 :             :     return false;
     107                 :             : 
     108                 :     5797280 :   if (width < HOST_BITS_PER_WIDE_INT)
     109                 :     5267986 :     val &= (HOST_WIDE_INT_1U << width) - 1;
     110                 :     5797694 :   return val == (HOST_WIDE_INT_1U << (width - 1));
     111                 :             : }
     112                 :             : 
     113                 :             : /* Test whether VAL is equal to the most significant bit of mode MODE
     114                 :             :    (after masking with the mode mask of MODE).  Returns false if the
     115                 :             :    precision of MODE is too large to handle.  */
     116                 :             : 
     117                 :             : bool
     118                 :     3418906 : val_signbit_p (machine_mode mode, unsigned HOST_WIDE_INT val)
     119                 :             : {
     120                 :     3418906 :   unsigned int width;
     121                 :     3418906 :   scalar_int_mode int_mode;
     122                 :             : 
     123                 :     3418906 :   if (!is_int_mode (mode, &int_mode))
     124                 :             :     return false;
     125                 :             : 
     126                 :     3418870 :   width = GET_MODE_PRECISION (int_mode);
     127                 :     3418870 :   if (width == 0 || width > HOST_BITS_PER_WIDE_INT)
     128                 :             :     return false;
     129                 :             : 
     130                 :     3414273 :   val &= GET_MODE_MASK (int_mode);
     131                 :     3414273 :   return val == (HOST_WIDE_INT_1U << (width - 1));
     132                 :             : }
     133                 :             : 
     134                 :             : /* Test whether the most significant bit of mode MODE is set in VAL.
     135                 :             :    Returns false if the precision of MODE is too large to handle.  */
     136                 :             : bool
     137                 :     2699088 : val_signbit_known_set_p (machine_mode mode, unsigned HOST_WIDE_INT val)
     138                 :             : {
     139                 :     2699088 :   unsigned int width;
     140                 :             : 
     141                 :     2699088 :   scalar_int_mode int_mode;
     142                 :     2699088 :   if (!is_int_mode (mode, &int_mode))
     143                 :             :     return false;
     144                 :             : 
     145                 :     2668973 :   width = GET_MODE_PRECISION (int_mode);
     146                 :     2668973 :   if (width == 0 || width > HOST_BITS_PER_WIDE_INT)
     147                 :             :     return false;
     148                 :             : 
     149                 :     2668973 :   val &= HOST_WIDE_INT_1U << (width - 1);
     150                 :     2668973 :   return val != 0;
     151                 :             : }
     152                 :             : 
     153                 :             : /* Test whether the most significant bit of mode MODE is clear in VAL.
     154                 :             :    Returns false if the precision of MODE is too large to handle.  */
     155                 :             : bool
     156                 :     8048165 : val_signbit_known_clear_p (machine_mode mode, unsigned HOST_WIDE_INT val)
     157                 :             : {
     158                 :     8048165 :   unsigned int width;
     159                 :             : 
     160                 :     8048165 :   scalar_int_mode int_mode;
     161                 :     8048165 :   if (!is_int_mode (mode, &int_mode))
     162                 :             :     return false;
     163                 :             : 
     164                 :     7753161 :   width = GET_MODE_PRECISION (int_mode);
     165                 :     7753161 :   if (width == 0 || width > HOST_BITS_PER_WIDE_INT)
     166                 :             :     return false;
     167                 :             : 
     168                 :     7643108 :   val &= HOST_WIDE_INT_1U << (width - 1);
     169                 :     7643108 :   return val == 0;
     170                 :             : }
     171                 :             : 
     172                 :             : /* Make a binary operation by properly ordering the operands and
     173                 :             :    seeing if the expression folds.  */
     174                 :             : 
     175                 :             : rtx
     176                 :   107286150 : simplify_context::simplify_gen_binary (rtx_code code, machine_mode mode,
     177                 :             :                                        rtx op0, rtx op1)
     178                 :             : {
     179                 :   107286150 :   rtx tem;
     180                 :             : 
     181                 :             :   /* If this simplifies, do it.  */
     182                 :   107286150 :   tem = simplify_binary_operation (code, mode, op0, op1);
     183                 :   107286150 :   if (tem)
     184                 :             :     return tem;
     185                 :             : 
     186                 :             :   /* Put complex operands first and constants second if commutative.  */
     187                 :    68472614 :   if (GET_RTX_CLASS (code) == RTX_COMM_ARITH
     188                 :    68472614 :       && swap_commutative_operands_p (op0, op1))
     189                 :             :     std::swap (op0, op1);
     190                 :             : 
     191                 :    68472614 :   return gen_rtx_fmt_ee (code, mode, op0, op1);
     192                 :             : }
     193                 :             : 
     194                 :             : /* If X is a MEM referencing the constant pool, return the real value.
     195                 :             :    Otherwise return X.  */
     196                 :             : rtx
     197                 :  2516342125 : avoid_constant_pool_reference (rtx x)
     198                 :             : {
     199                 :  2516342125 :   rtx c, tmp, addr;
     200                 :  2516342125 :   machine_mode cmode;
     201                 :  2516342125 :   poly_int64 offset = 0;
     202                 :             : 
     203                 :  2516342125 :   switch (GET_CODE (x))
     204                 :             :     {
     205                 :   235831065 :     case MEM:
     206                 :   235831065 :       break;
     207                 :             : 
     208                 :      859694 :     case FLOAT_EXTEND:
     209                 :             :       /* Handle float extensions of constant pool references.  */
     210                 :      859694 :       tmp = XEXP (x, 0);
     211                 :      859694 :       c = avoid_constant_pool_reference (tmp);
     212                 :      859694 :       if (c != tmp && CONST_DOUBLE_AS_FLOAT_P (c))
     213                 :      115012 :         return const_double_from_real_value (*CONST_DOUBLE_REAL_VALUE (c),
     214                 :      115012 :                                              GET_MODE (x));
     215                 :             :       return x;
     216                 :             : 
     217                 :             :     default:
     218                 :             :       return x;
     219                 :             :     }
     220                 :             : 
     221                 :   235831065 :   if (GET_MODE (x) == BLKmode)
     222                 :             :     return x;
     223                 :             : 
     224                 :   233584684 :   addr = XEXP (x, 0);
     225                 :             : 
     226                 :             :   /* Call target hook to avoid the effects of -fpic etc....  */
     227                 :   233584684 :   addr = targetm.delegitimize_address (addr);
     228                 :             : 
     229                 :             :   /* Split the address into a base and integer offset.  */
     230                 :   233584684 :   addr = strip_offset (addr, &offset);
     231                 :             : 
     232                 :   233584684 :   if (GET_CODE (addr) == LO_SUM)
     233                 :           0 :     addr = XEXP (addr, 1);
     234                 :             : 
     235                 :             :   /* If this is a constant pool reference, we can turn it into its
     236                 :             :      constant and hope that simplifications happen.  */
     237                 :   233584684 :   if (GET_CODE (addr) == SYMBOL_REF
     238                 :   233584684 :       && CONSTANT_POOL_ADDRESS_P (addr))
     239                 :             :     {
     240                 :     5265427 :       c = get_pool_constant (addr);
     241                 :     5265427 :       cmode = get_pool_mode (addr);
     242                 :             : 
     243                 :             :       /* If we're accessing the constant in a different mode than it was
     244                 :             :          originally stored, attempt to fix that up via subreg simplifications.
     245                 :             :          If that fails we have no choice but to return the original memory.  */
     246                 :     5265427 :       if (known_eq (offset, 0) && cmode == GET_MODE (x))
     247                 :             :         return c;
     248                 :       13104 :       else if (known_in_range_p (offset, 0, GET_MODE_SIZE (cmode)))
     249                 :             :         {
     250                 :        6552 :           rtx tem = simplify_subreg (GET_MODE (x), c, cmode, offset);
     251                 :        6552 :           if (tem && CONSTANT_P (tem))
     252                 :             :             return tem;
     253                 :             :         }
     254                 :             :     }
     255                 :             : 
     256                 :             :   return x;
     257                 :             : }
     258                 :             : 
     259                 :             : /* Simplify a MEM based on its attributes.  This is the default
     260                 :             :    delegitimize_address target hook, and it's recommended that every
     261                 :             :    overrider call it.  */
     262                 :             : 
     263                 :             : rtx
     264                 :  3469907574 : delegitimize_mem_from_attrs (rtx x)
     265                 :             : {
     266                 :             :   /* MEMs without MEM_OFFSETs may have been offset, so we can't just
     267                 :             :      use their base addresses as equivalent.  */
     268                 :  3469907574 :   if (MEM_P (x)
     269                 :    59287168 :       && MEM_EXPR (x)
     270                 :  3506705314 :       && MEM_OFFSET_KNOWN_P (x))
     271                 :             :     {
     272                 :    34044630 :       tree decl = MEM_EXPR (x);
     273                 :    34044630 :       machine_mode mode = GET_MODE (x);
     274                 :    34044630 :       poly_int64 offset = 0;
     275                 :             : 
     276                 :    34044630 :       switch (TREE_CODE (decl))
     277                 :             :         {
     278                 :             :         default:
     279                 :             :           decl = NULL;
     280                 :             :           break;
     281                 :             : 
     282                 :             :         case VAR_DECL:
     283                 :             :           break;
     284                 :             : 
     285                 :     9990150 :         case ARRAY_REF:
     286                 :     9990150 :         case ARRAY_RANGE_REF:
     287                 :     9990150 :         case COMPONENT_REF:
     288                 :     9990150 :         case BIT_FIELD_REF:
     289                 :     9990150 :         case REALPART_EXPR:
     290                 :     9990150 :         case IMAGPART_EXPR:
     291                 :     9990150 :         case VIEW_CONVERT_EXPR:
     292                 :     9990150 :           {
     293                 :     9990150 :             poly_int64 bitsize, bitpos, bytepos, toffset_val = 0;
     294                 :     9990150 :             tree toffset;
     295                 :     9990150 :             int unsignedp, reversep, volatilep = 0;
     296                 :             : 
     297                 :     9990150 :             decl
     298                 :     9990150 :               = get_inner_reference (decl, &bitsize, &bitpos, &toffset, &mode,
     299                 :             :                                      &unsignedp, &reversep, &volatilep);
     300                 :    19980300 :             if (maybe_ne (bitsize, GET_MODE_BITSIZE (mode))
     301                 :    10286981 :                 || !multiple_p (bitpos, BITS_PER_UNIT, &bytepos)
     302                 :    19535317 :                 || (toffset && !poly_int_tree_p (toffset, &toffset_val)))
     303                 :             :               decl = NULL;
     304                 :             :             else
     305                 :     9248336 :               offset += bytepos + toffset_val;
     306                 :     9990150 :             break;
     307                 :             :           }
     308                 :             :         }
     309                 :             : 
     310                 :      741814 :       if (decl
     311                 :    20346245 :           && mode == GET_MODE (x)
     312                 :    20095783 :           && VAR_P (decl)
     313                 :    13145283 :           && (TREE_STATIC (decl)
     314                 :    11971983 :               || DECL_THREAD_LOCAL_P (decl))
     315                 :     1207527 :           && DECL_RTL_SET_P (decl)
     316                 :    10455372 :           && MEM_P (DECL_RTL (decl)))
     317                 :             :         {
     318                 :     1207036 :           rtx newx;
     319                 :             : 
     320                 :     1207036 :           offset += MEM_OFFSET (x);
     321                 :             : 
     322                 :     1207036 :           newx = DECL_RTL (decl);
     323                 :             : 
     324                 :     1207036 :           if (MEM_P (newx))
     325                 :             :             {
     326                 :     1207036 :               rtx n = XEXP (newx, 0), o = XEXP (x, 0);
     327                 :     1207036 :               poly_int64 n_offset, o_offset;
     328                 :             : 
     329                 :             :               /* Avoid creating a new MEM needlessly if we already had
     330                 :             :                  the same address.  We do if there's no OFFSET and the
     331                 :             :                  old address X is identical to NEWX, or if X is of the
     332                 :             :                  form (plus NEWX OFFSET), or the NEWX is of the form
     333                 :             :                  (plus Y (const_int Z)) and X is that with the offset
     334                 :             :                  added: (plus Y (const_int Z+OFFSET)).  */
     335                 :     1207036 :               n = strip_offset (n, &n_offset);
     336                 :     1207036 :               o = strip_offset (o, &o_offset);
     337                 :     2388074 :               if (!(known_eq (o_offset, n_offset + offset)
     338                 :     1181038 :                     && rtx_equal_p (o, n)))
     339                 :      204269 :                 x = adjust_address_nv (newx, mode, offset);
     340                 :             :             }
     341                 :           0 :           else if (GET_MODE (x) == GET_MODE (newx)
     342                 :           0 :                    && known_eq (offset, 0))
     343                 :             :             x = newx;
     344                 :             :         }
     345                 :             :     }
     346                 :             : 
     347                 :  3469907574 :   return x;
     348                 :             : }
     349                 :             : 
     350                 :             : /* Make a unary operation by first seeing if it folds and otherwise making
     351                 :             :    the specified operation.  */
     352                 :             : 
     353                 :             : rtx
     354                 :     5137286 : simplify_context::simplify_gen_unary (rtx_code code, machine_mode mode, rtx op,
     355                 :             :                                       machine_mode op_mode)
     356                 :             : {
     357                 :     5137286 :   rtx tem;
     358                 :             : 
     359                 :             :   /* If this simplifies, use it.  */
     360                 :     5137286 :   if ((tem = simplify_unary_operation (code, mode, op, op_mode)) != 0)
     361                 :             :     return tem;
     362                 :             : 
     363                 :     1882002 :   return gen_rtx_fmt_e (code, mode, op);
     364                 :             : }
     365                 :             : 
     366                 :             : /* Likewise for ternary operations.  */
     367                 :             : 
     368                 :             : rtx
     369                 :     2028343 : simplify_context::simplify_gen_ternary (rtx_code code, machine_mode mode,
     370                 :             :                                         machine_mode op0_mode,
     371                 :             :                                         rtx op0, rtx op1, rtx op2)
     372                 :             : {
     373                 :     2028343 :   rtx tem;
     374                 :             : 
     375                 :             :   /* If this simplifies, use it.  */
     376                 :     2028343 :   if ((tem = simplify_ternary_operation (code, mode, op0_mode,
     377                 :             :                                          op0, op1, op2)) != 0)
     378                 :             :     return tem;
     379                 :             : 
     380                 :     1811086 :   return gen_rtx_fmt_eee (code, mode, op0, op1, op2);
     381                 :             : }
     382                 :             : 
     383                 :             : /* Likewise, for relational operations.
     384                 :             :    CMP_MODE specifies mode comparison is done in.  */
     385                 :             : 
     386                 :             : rtx
     387                 :    19603239 : simplify_context::simplify_gen_relational (rtx_code code, machine_mode mode,
     388                 :             :                                            machine_mode cmp_mode,
     389                 :             :                                            rtx op0, rtx op1)
     390                 :             : {
     391                 :    19603239 :   rtx tem;
     392                 :             : 
     393                 :    19603239 :   if ((tem = simplify_relational_operation (code, mode, cmp_mode,
     394                 :             :                                             op0, op1)) != 0)
     395                 :             :     return tem;
     396                 :             : 
     397                 :    17521215 :   return gen_rtx_fmt_ee (code, mode, op0, op1);
     398                 :             : }
     399                 :             : 
     400                 :             : /* If FN is NULL, replace all occurrences of OLD_RTX in X with copy_rtx (DATA)
     401                 :             :    and simplify the result.  If FN is non-NULL, call this callback on each
     402                 :             :    X, if it returns non-NULL, replace X with its return value and simplify the
     403                 :             :    result.  */
     404                 :             : 
     405                 :             : rtx
     406                 :   438564528 : simplify_replace_fn_rtx (rtx x, const_rtx old_rtx,
     407                 :             :                          rtx (*fn) (rtx, const_rtx, void *), void *data)
     408                 :             : {
     409                 :   438564528 :   enum rtx_code code = GET_CODE (x);
     410                 :   438564528 :   machine_mode mode = GET_MODE (x);
     411                 :   438564528 :   machine_mode op_mode;
     412                 :   438564528 :   const char *fmt;
     413                 :   438564528 :   rtx op0, op1, op2, newx, op;
     414                 :   438564528 :   rtvec vec, newvec;
     415                 :   438564528 :   int i, j;
     416                 :             : 
     417                 :   438564528 :   if (UNLIKELY (fn != NULL))
     418                 :             :     {
     419                 :   380237600 :       newx = fn (x, old_rtx, data);
     420                 :   380237600 :       if (newx)
     421                 :             :         return newx;
     422                 :             :     }
     423                 :    58326928 :   else if (rtx_equal_p (x, old_rtx))
     424                 :     4929964 :     return copy_rtx ((rtx) data);
     425                 :             : 
     426                 :   340652822 :   switch (GET_RTX_CLASS (code))
     427                 :             :     {
     428                 :     1959190 :     case RTX_UNARY:
     429                 :     1959190 :       op0 = XEXP (x, 0);
     430                 :     1959190 :       op_mode = GET_MODE (op0);
     431                 :     1959190 :       op0 = simplify_replace_fn_rtx (op0, old_rtx, fn, data);
     432                 :     1959190 :       if (op0 == XEXP (x, 0))
     433                 :             :         return x;
     434                 :      607285 :       return simplify_gen_unary (code, mode, op0, op_mode);
     435                 :             : 
     436                 :    69211025 :     case RTX_BIN_ARITH:
     437                 :    69211025 :     case RTX_COMM_ARITH:
     438                 :    69211025 :       op0 = simplify_replace_fn_rtx (XEXP (x, 0), old_rtx, fn, data);
     439                 :    69211025 :       op1 = simplify_replace_fn_rtx (XEXP (x, 1), old_rtx, fn, data);
     440                 :    69211025 :       if (op0 == XEXP (x, 0) && op1 == XEXP (x, 1))
     441                 :             :         return x;
     442                 :    21995134 :       return simplify_gen_binary (code, mode, op0, op1);
     443                 :             : 
     444                 :     9137345 :     case RTX_COMPARE:
     445                 :     9137345 :     case RTX_COMM_COMPARE:
     446                 :     9137345 :       op0 = XEXP (x, 0);
     447                 :     9137345 :       op1 = XEXP (x, 1);
     448                 :     9137345 :       op_mode = GET_MODE (op0) != VOIDmode ? GET_MODE (op0) : GET_MODE (op1);
     449                 :     9137345 :       op0 = simplify_replace_fn_rtx (op0, old_rtx, fn, data);
     450                 :     9137345 :       op1 = simplify_replace_fn_rtx (op1, old_rtx, fn, data);
     451                 :     9137345 :       if (op0 == XEXP (x, 0) && op1 == XEXP (x, 1))
     452                 :             :         return x;
     453                 :     2167055 :       return simplify_gen_relational (code, mode, op_mode, op0, op1);
     454                 :             : 
     455                 :     5329291 :     case RTX_TERNARY:
     456                 :     5329291 :     case RTX_BITFIELD_OPS:
     457                 :     5329291 :       op0 = XEXP (x, 0);
     458                 :     5329291 :       op_mode = GET_MODE (op0);
     459                 :     5329291 :       op0 = simplify_replace_fn_rtx (op0, old_rtx, fn, data);
     460                 :     5329291 :       op1 = simplify_replace_fn_rtx (XEXP (x, 1), old_rtx, fn, data);
     461                 :     5329291 :       op2 = simplify_replace_fn_rtx (XEXP (x, 2), old_rtx, fn, data);
     462                 :     5329291 :       if (op0 == XEXP (x, 0) && op1 == XEXP (x, 1) && op2 == XEXP (x, 2))
     463                 :             :         return x;
     464                 :     1558286 :       if (op_mode == VOIDmode)
     465                 :     1531526 :         op_mode = GET_MODE (op0);
     466                 :     1558286 :       return simplify_gen_ternary (code, mode, op_mode, op0, op1, op2);
     467                 :             : 
     468                 :    70390392 :     case RTX_EXTRA:
     469                 :    70390392 :       if (code == SUBREG)
     470                 :             :         {
     471                 :      620153 :           op0 = simplify_replace_fn_rtx (SUBREG_REG (x), old_rtx, fn, data);
     472                 :      620153 :           if (op0 == SUBREG_REG (x))
     473                 :             :             return x;
     474                 :       88376 :           op0 = simplify_gen_subreg (GET_MODE (x), op0,
     475                 :       44188 :                                      GET_MODE (SUBREG_REG (x)),
     476                 :       44188 :                                      SUBREG_BYTE (x));
     477                 :       44188 :           return op0 ? op0 : x;
     478                 :             :         }
     479                 :             :       break;
     480                 :             : 
     481                 :    55119117 :     case RTX_OBJ:
     482                 :    55119117 :       if (code == MEM)
     483                 :             :         {
     484                 :    10073438 :           op0 = simplify_replace_fn_rtx (XEXP (x, 0), old_rtx, fn, data);
     485                 :    10073438 :           if (op0 == XEXP (x, 0))
     486                 :             :             return x;
     487                 :      165867 :           return replace_equiv_address_nv (x, op0);
     488                 :             :         }
     489                 :    45045679 :       else if (code == LO_SUM)
     490                 :             :         {
     491                 :           0 :           op0 = simplify_replace_fn_rtx (XEXP (x, 0), old_rtx, fn, data);
     492                 :           0 :           op1 = simplify_replace_fn_rtx (XEXP (x, 1), old_rtx, fn, data);
     493                 :             : 
     494                 :             :           /* (lo_sum (high x) y) -> y where x and y have the same base.  */
     495                 :           0 :           if (GET_CODE (op0) == HIGH)
     496                 :             :             {
     497                 :           0 :               rtx base0, base1, offset0, offset1;
     498                 :           0 :               split_const (XEXP (op0, 0), &base0, &offset0);
     499                 :           0 :               split_const (op1, &base1, &offset1);
     500                 :           0 :               if (rtx_equal_p (base0, base1))
     501                 :           0 :                 return op1;
     502                 :             :             }
     503                 :             : 
     504                 :           0 :           if (op0 == XEXP (x, 0) && op1 == XEXP (x, 1))
     505                 :             :             return x;
     506                 :           0 :           return gen_rtx_LO_SUM (mode, op0, op1);
     507                 :             :         }
     508                 :             :       break;
     509                 :             : 
     510                 :             :     default:
     511                 :             :       break;
     512                 :             :     }
     513                 :             : 
     514                 :   244322380 :   newx = x;
     515                 :   244322380 :   fmt = GET_RTX_FORMAT (code);
     516                 :   527269656 :   for (i = 0; fmt[i]; i++)
     517                 :   282947276 :     switch (fmt[i])
     518                 :             :       {
     519                 :     2950938 :       case 'E':
     520                 :     2950938 :         vec = XVEC (x, i);
     521                 :     2950938 :         newvec = XVEC (newx, i);
     522                 :    11931525 :         for (j = 0; j < GET_NUM_ELEM (vec); j++)
     523                 :             :           {
     524                 :     8980587 :             op = simplify_replace_fn_rtx (RTVEC_ELT (vec, j),
     525                 :             :                                           old_rtx, fn, data);
     526                 :     8980587 :             if (op != RTVEC_ELT (vec, j))
     527                 :             :               {
     528                 :      350426 :                 if (newvec == vec)
     529                 :             :                   {
     530                 :      334339 :                     newvec = shallow_copy_rtvec (vec);
     531                 :      334339 :                     if (x == newx)
     532                 :      334339 :                       newx = shallow_copy_rtx (x);
     533                 :      334339 :                     XVEC (newx, i) = newvec;
     534                 :             :                   }
     535                 :      350426 :                 RTVEC_ELT (newvec, j) = op;
     536                 :             :               }
     537                 :             :           }
     538                 :             :         break;
     539                 :             : 
     540                 :    63016745 :       case 'e':
     541                 :    63016745 :         if (XEXP (x, i))
     542                 :             :           {
     543                 :    63016745 :             op = simplify_replace_fn_rtx (XEXP (x, i), old_rtx, fn, data);
     544                 :    63016745 :             if (op != XEXP (x, i))
     545                 :             :               {
     546                 :     3792909 :                 if (x == newx)
     547                 :     3789461 :                   newx = shallow_copy_rtx (x);
     548                 :     3792909 :                 XEXP (newx, i) = op;
     549                 :             :               }
     550                 :             :           }
     551                 :             :         break;
     552                 :             :       }
     553                 :             :   return newx;
     554                 :             : }
     555                 :             : 
     556                 :             : /* Replace all occurrences of OLD_RTX in X with NEW_RTX and try to simplify the
     557                 :             :    resulting RTX.  Return a new RTX which is as simplified as possible.  */
     558                 :             : 
     559                 :             : rtx
     560                 :    12202012 : simplify_replace_rtx (rtx x, const_rtx old_rtx, rtx new_rtx)
     561                 :             : {
     562                 :    12202012 :   return simplify_replace_fn_rtx (x, old_rtx, 0, new_rtx);
     563                 :             : }
     564                 :             : 
     565                 :             : /* Try to simplify a MODE truncation of OP, which has OP_MODE.
     566                 :             :    Only handle cases where the truncated value is inherently an rvalue.
     567                 :             : 
     568                 :             :    RTL provides two ways of truncating a value:
     569                 :             : 
     570                 :             :    1. a lowpart subreg.  This form is only a truncation when both
     571                 :             :       the outer and inner modes (here MODE and OP_MODE respectively)
     572                 :             :       are scalar integers, and only then when the subreg is used as
     573                 :             :       an rvalue.
     574                 :             : 
     575                 :             :       It is only valid to form such truncating subregs if the
     576                 :             :       truncation requires no action by the target.  The onus for
     577                 :             :       proving this is on the creator of the subreg -- e.g. the
     578                 :             :       caller to simplify_subreg or simplify_gen_subreg -- and typically
     579                 :             :       involves either TRULY_NOOP_TRUNCATION_MODES_P or truncated_to_mode.
     580                 :             : 
     581                 :             :    2. a TRUNCATE.  This form handles both scalar and compound integers.
     582                 :             : 
     583                 :             :    The first form is preferred where valid.  However, the TRUNCATE
     584                 :             :    handling in simplify_unary_operation turns the second form into the
     585                 :             :    first form when TRULY_NOOP_TRUNCATION_MODES_P or truncated_to_mode allow,
     586                 :             :    so it is generally safe to form rvalue truncations using:
     587                 :             : 
     588                 :             :       simplify_gen_unary (TRUNCATE, ...)
     589                 :             : 
     590                 :             :    and leave simplify_unary_operation to work out which representation
     591                 :             :    should be used.
     592                 :             : 
     593                 :             :    Because of the proof requirements on (1), simplify_truncation must
     594                 :             :    also use simplify_gen_unary (TRUNCATE, ...) to truncate parts of OP,
     595                 :             :    regardless of whether the outer truncation came from a SUBREG or a
     596                 :             :    TRUNCATE.  For example, if the caller has proven that an SImode
     597                 :             :    truncation of:
     598                 :             : 
     599                 :             :       (and:DI X Y)
     600                 :             : 
     601                 :             :    is a no-op and can be represented as a subreg, it does not follow
     602                 :             :    that SImode truncations of X and Y are also no-ops.  On a target
     603                 :             :    like 64-bit MIPS that requires SImode values to be stored in
     604                 :             :    sign-extended form, an SImode truncation of:
     605                 :             : 
     606                 :             :       (and:DI (reg:DI X) (const_int 63))
     607                 :             : 
     608                 :             :    is trivially a no-op because only the lower 6 bits can be set.
     609                 :             :    However, X is still an arbitrary 64-bit number and so we cannot
     610                 :             :    assume that truncating it too is a no-op.  */
     611                 :             : 
     612                 :             : rtx
     613                 :    19886909 : simplify_context::simplify_truncation (machine_mode mode, rtx op,
     614                 :             :                                        machine_mode op_mode)
     615                 :             : {
     616                 :    19886909 :   unsigned int precision = GET_MODE_UNIT_PRECISION (mode);
     617                 :    19886909 :   unsigned int op_precision = GET_MODE_UNIT_PRECISION (op_mode);
     618                 :    19886909 :   scalar_int_mode int_mode, int_op_mode, subreg_mode;
     619                 :             : 
     620                 :    19886909 :   gcc_assert (precision <= op_precision);
     621                 :             : 
     622                 :             :   /* Optimize truncations of zero and sign extended values.  */
     623                 :    19886909 :   if (GET_CODE (op) == ZERO_EXTEND
     624                 :    19886909 :       || GET_CODE (op) == SIGN_EXTEND)
     625                 :             :     {
     626                 :             :       /* There are three possibilities.  If MODE is the same as the
     627                 :             :          origmode, we can omit both the extension and the subreg.
     628                 :             :          If MODE is not larger than the origmode, we can apply the
     629                 :             :          truncation without the extension.  Finally, if the outermode
     630                 :             :          is larger than the origmode, we can just extend to the appropriate
     631                 :             :          mode.  */
     632                 :      304767 :       machine_mode origmode = GET_MODE (XEXP (op, 0));
     633                 :      304767 :       if (mode == origmode)
     634                 :             :         return XEXP (op, 0);
     635                 :       23202 :       else if (precision <= GET_MODE_UNIT_PRECISION (origmode))
     636                 :        7391 :         return simplify_gen_unary (TRUNCATE, mode,
     637                 :        7391 :                                    XEXP (op, 0), origmode);
     638                 :             :       else
     639                 :        4210 :         return simplify_gen_unary (GET_CODE (op), mode,
     640                 :        4210 :                                    XEXP (op, 0), origmode);
     641                 :             :     }
     642                 :             : 
     643                 :             :   /* If the machine can perform operations in the truncated mode, distribute
     644                 :             :      the truncation, i.e. simplify (truncate:QI (op:SI (x:SI) (y:SI))) into
     645                 :             :      (op:QI (truncate:QI (x:SI)) (truncate:QI (y:SI))).  */
     646                 :    19582142 :   if (1
     647                 :             :       && (!WORD_REGISTER_OPERATIONS || precision >= BITS_PER_WORD)
     648                 :             :       && (GET_CODE (op) == PLUS
     649                 :             :           || GET_CODE (op) == MINUS
     650                 :    19582142 :           || GET_CODE (op) == MULT))
     651                 :             :     {
     652                 :      840825 :       rtx op0 = simplify_gen_unary (TRUNCATE, mode, XEXP (op, 0), op_mode);
     653                 :      840825 :       if (op0)
     654                 :             :         {
     655                 :      840825 :           rtx op1 = simplify_gen_unary (TRUNCATE, mode, XEXP (op, 1), op_mode);
     656                 :      840825 :           if (op1)
     657                 :      840825 :             return simplify_gen_binary (GET_CODE (op), mode, op0, op1);
     658                 :             :         }
     659                 :             :     }
     660                 :             : 
     661                 :             :   /* Simplify (truncate:QI (lshiftrt:SI (sign_extend:SI (x:QI)) C)) into
     662                 :             :      to (ashiftrt:QI (x:QI) C), where C is a suitable small constant and
     663                 :             :      the outer subreg is effectively a truncation to the original mode.  */
     664                 :    18741317 :   if ((GET_CODE (op) == LSHIFTRT
     665                 :    18741317 :        || GET_CODE (op) == ASHIFTRT)
     666                 :             :       /* Ensure that OP_MODE is at least twice as wide as MODE
     667                 :             :          to avoid the possibility that an outer LSHIFTRT shifts by more
     668                 :             :          than the sign extension's sign_bit_copies and introduces zeros
     669                 :             :          into the high bits of the result.  */
     670                 :     1803446 :       && 2 * precision <= op_precision
     671                 :     1803446 :       && CONST_INT_P (XEXP (op, 1))
     672                 :     1709006 :       && GET_CODE (XEXP (op, 0)) == SIGN_EXTEND
     673                 :          22 :       && GET_MODE (XEXP (XEXP (op, 0), 0)) == mode
     674                 :          19 :       && UINTVAL (XEXP (op, 1)) < precision)
     675                 :          15 :     return simplify_gen_binary (ASHIFTRT, mode,
     676                 :          15 :                                 XEXP (XEXP (op, 0), 0), XEXP (op, 1));
     677                 :             : 
     678                 :             :   /* Likewise (truncate:QI (lshiftrt:SI (zero_extend:SI (x:QI)) C)) into
     679                 :             :      to (lshiftrt:QI (x:QI) C), where C is a suitable small constant and
     680                 :             :      the outer subreg is effectively a truncation to the original mode.  */
     681                 :    18741302 :   if ((GET_CODE (op) == LSHIFTRT
     682                 :             :        || GET_CODE (op) == ASHIFTRT)
     683                 :     1803431 :       && CONST_INT_P (XEXP (op, 1))
     684                 :     1708991 :       && GET_CODE (XEXP (op, 0)) == ZERO_EXTEND
     685                 :         655 :       && GET_MODE (XEXP (XEXP (op, 0), 0)) == mode
     686                 :         599 :       && UINTVAL (XEXP (op, 1)) < precision)
     687                 :         589 :     return simplify_gen_binary (LSHIFTRT, mode,
     688                 :         589 :                                 XEXP (XEXP (op, 0), 0), XEXP (op, 1));
     689                 :             : 
     690                 :             :   /* Likewise (truncate:QI (ashift:SI (zero_extend:SI (x:QI)) C)) into
     691                 :             :      to (ashift:QI (x:QI) C), where C is a suitable small constant and
     692                 :             :      the outer subreg is effectively a truncation to the original mode.  */
     693                 :    18740713 :   if (GET_CODE (op) == ASHIFT
     694                 :      650725 :       && CONST_INT_P (XEXP (op, 1))
     695                 :      598124 :       && (GET_CODE (XEXP (op, 0)) == ZERO_EXTEND
     696                 :      598124 :           || GET_CODE (XEXP (op, 0)) == SIGN_EXTEND)
     697                 :         865 :       && GET_MODE (XEXP (XEXP (op, 0), 0)) == mode
     698                 :         849 :       && UINTVAL (XEXP (op, 1)) < precision)
     699                 :         842 :     return simplify_gen_binary (ASHIFT, mode,
     700                 :         842 :                                 XEXP (XEXP (op, 0), 0), XEXP (op, 1));
     701                 :             : 
     702                 :             :   /* Likewise (truncate:QI (and:SI (lshiftrt:SI (x:SI) C) C2)) into
     703                 :             :      (and:QI (lshiftrt:QI (truncate:QI (x:SI)) C) C2) for suitable C
     704                 :             :      and C2.  */
     705                 :    18739871 :   if (GET_CODE (op) == AND
     706                 :      670700 :       && (GET_CODE (XEXP (op, 0)) == LSHIFTRT
     707                 :      670700 :           || GET_CODE (XEXP (op, 0)) == ASHIFTRT)
     708                 :       47842 :       && CONST_INT_P (XEXP (XEXP (op, 0), 1))
     709                 :       47739 :       && CONST_INT_P (XEXP (op, 1)))
     710                 :             :     {
     711                 :       47739 :       rtx op0 = (XEXP (XEXP (op, 0), 0));
     712                 :       47739 :       rtx shift_op = XEXP (XEXP (op, 0), 1);
     713                 :       47739 :       rtx mask_op = XEXP (op, 1);
     714                 :       47739 :       unsigned HOST_WIDE_INT shift = UINTVAL (shift_op);
     715                 :       47739 :       unsigned HOST_WIDE_INT mask = UINTVAL (mask_op);
     716                 :             : 
     717                 :       47739 :       if (shift < precision
     718                 :             :           /* If doing this transform works for an X with all bits set,
     719                 :             :              it works for any X.  */
     720                 :       35522 :           && ((GET_MODE_MASK (mode) >> shift) & mask)
     721                 :       35522 :              == ((GET_MODE_MASK (op_mode) >> shift) & mask)
     722                 :        3339 :           && (op0 = simplify_gen_unary (TRUNCATE, mode, op0, op_mode))
     723                 :       51078 :           && (op0 = simplify_gen_binary (LSHIFTRT, mode, op0, shift_op)))
     724                 :             :         {
     725                 :        3339 :           mask_op = GEN_INT (trunc_int_for_mode (mask, mode));
     726                 :        3339 :           return simplify_gen_binary (AND, mode, op0, mask_op);
     727                 :             :         }
     728                 :             :     }
     729                 :             : 
     730                 :             :   /* Turn (truncate:M1 (*_extract:M2 (reg:M2) (len) (pos))) into
     731                 :             :      (*_extract:M1 (truncate:M1 (reg:M2)) (len) (pos')) if possible without
     732                 :             :      changing len.  */
     733                 :    18736532 :   if ((GET_CODE (op) == ZERO_EXTRACT || GET_CODE (op) == SIGN_EXTRACT)
     734                 :      433507 :       && REG_P (XEXP (op, 0))
     735                 :      305586 :       && GET_MODE (XEXP (op, 0)) == GET_MODE (op)
     736                 :      304175 :       && CONST_INT_P (XEXP (op, 1))
     737                 :      304175 :       && CONST_INT_P (XEXP (op, 2)))
     738                 :             :     {
     739                 :      273188 :       rtx op0 = XEXP (op, 0);
     740                 :      273188 :       unsigned HOST_WIDE_INT len = UINTVAL (XEXP (op, 1));
     741                 :      273188 :       unsigned HOST_WIDE_INT pos = UINTVAL (XEXP (op, 2));
     742                 :      273188 :       if (BITS_BIG_ENDIAN && pos >= op_precision - precision)
     743                 :             :         {
     744                 :             :           op0 = simplify_gen_unary (TRUNCATE, mode, op0, GET_MODE (op0));
     745                 :             :           if (op0)
     746                 :             :             {
     747                 :             :               pos -= op_precision - precision;
     748                 :             :               return simplify_gen_ternary (GET_CODE (op), mode, mode, op0,
     749                 :             :                                            XEXP (op, 1), GEN_INT (pos));
     750                 :             :             }
     751                 :             :         }
     752                 :      273188 :       else if (!BITS_BIG_ENDIAN && precision >= len + pos)
     753                 :             :         {
     754                 :        7458 :           op0 = simplify_gen_unary (TRUNCATE, mode, op0, GET_MODE (op0));
     755                 :        7458 :           if (op0)
     756                 :        7458 :             return simplify_gen_ternary (GET_CODE (op), mode, mode, op0,
     757                 :        7458 :                                          XEXP (op, 1), XEXP (op, 2));
     758                 :             :         }
     759                 :             :     }
     760                 :             : 
     761                 :             :   /* Recognize a word extraction from a multi-word subreg.  */
     762                 :    18729074 :   if ((GET_CODE (op) == LSHIFTRT
     763                 :    18729074 :        || GET_CODE (op) == ASHIFTRT)
     764                 :     1802842 :       && SCALAR_INT_MODE_P (mode)
     765                 :     1800200 :       && SCALAR_INT_MODE_P (op_mode)
     766                 :     1933988 :       && precision >= BITS_PER_WORD
     767                 :       60173 :       && 2 * precision <= op_precision
     768                 :       60173 :       && CONST_INT_P (XEXP (op, 1))
     769                 :       52525 :       && (INTVAL (XEXP (op, 1)) & (precision - 1)) == 0
     770                 :        1928 :       && UINTVAL (XEXP (op, 1)) < op_precision)
     771                 :             :     {
     772                 :        1928 :       poly_int64 byte = subreg_lowpart_offset (mode, op_mode);
     773                 :        1928 :       int shifted_bytes = INTVAL (XEXP (op, 1)) / BITS_PER_UNIT;
     774                 :        1928 :       return simplify_gen_subreg (mode, XEXP (op, 0), op_mode,
     775                 :             :                                   (WORDS_BIG_ENDIAN
     776                 :             :                                    ? byte - shifted_bytes
     777                 :        1928 :                                    : byte + shifted_bytes));
     778                 :             :     }
     779                 :             : 
     780                 :             :   /* If we have a TRUNCATE of a right shift of MEM, make a new MEM
     781                 :             :      and try replacing the TRUNCATE and shift with it.  Don't do this
     782                 :             :      if the MEM has a mode-dependent address.  */
     783                 :    18727146 :   if ((GET_CODE (op) == LSHIFTRT
     784                 :             :        || GET_CODE (op) == ASHIFTRT)
     785                 :     1798272 :       && is_a <scalar_int_mode> (mode, &int_mode)
     786                 :    20524310 :       && is_a <scalar_int_mode> (op_mode, &int_op_mode)
     787                 :     1798272 :       && MEM_P (XEXP (op, 0))
     788                 :       10892 :       && CONST_INT_P (XEXP (op, 1))
     789                 :       20146 :       && INTVAL (XEXP (op, 1)) % GET_MODE_BITSIZE (int_mode) == 0
     790                 :        1141 :       && INTVAL (XEXP (op, 1)) > 0
     791                 :        2282 :       && INTVAL (XEXP (op, 1)) < GET_MODE_BITSIZE (int_op_mode)
     792                 :        1141 :       && ! mode_dependent_address_p (XEXP (XEXP (op, 0), 0),
     793                 :        1141 :                                      MEM_ADDR_SPACE (XEXP (op, 0)))
     794                 :        1141 :       && ! MEM_VOLATILE_P (XEXP (op, 0))
     795                 :    18727146 :       && (GET_MODE_SIZE (int_mode) >= UNITS_PER_WORD
     796                 :             :           || WORDS_BIG_ENDIAN == BYTES_BIG_ENDIAN))
     797                 :             :     {
     798                 :        1108 :       poly_int64 byte = subreg_lowpart_offset (int_mode, int_op_mode);
     799                 :        1108 :       int shifted_bytes = INTVAL (XEXP (op, 1)) / BITS_PER_UNIT;
     800                 :        1108 :       return adjust_address_nv (XEXP (op, 0), int_mode,
     801                 :             :                                 (WORDS_BIG_ENDIAN
     802                 :             :                                  ? byte - shifted_bytes
     803                 :             :                                  : byte + shifted_bytes));
     804                 :             :     }
     805                 :             : 
     806                 :             :   /* (truncate:SI (OP:DI ({sign,zero}_extend:DI foo:SI))) is
     807                 :             :      (OP:SI foo:SI) if OP is NEG or ABS.  */
     808                 :    18726038 :   if ((GET_CODE (op) == ABS
     809                 :    18726038 :        || GET_CODE (op) == NEG)
     810                 :       20362 :       && (GET_CODE (XEXP (op, 0)) == SIGN_EXTEND
     811                 :       20362 :           || GET_CODE (XEXP (op, 0)) == ZERO_EXTEND)
     812                 :          17 :       && GET_MODE (XEXP (XEXP (op, 0), 0)) == mode)
     813                 :           1 :     return simplify_gen_unary (GET_CODE (op), mode,
     814                 :           1 :                                XEXP (XEXP (op, 0), 0), mode);
     815                 :             : 
     816                 :             :   /* Simplifications of (truncate:A (subreg:B X 0)).  */
     817                 :    18726037 :   if (GET_CODE (op) == SUBREG
     818                 :    18726076 :       && is_a <scalar_int_mode> (mode, &int_mode)
     819                 :       47305 :       && SCALAR_INT_MODE_P (op_mode)
     820                 :       47305 :       && is_a <scalar_int_mode> (GET_MODE (SUBREG_REG (op)), &subreg_mode)
     821                 :    18773340 :       && subreg_lowpart_p (op))
     822                 :             :     {
     823                 :             :       /* (truncate:A (subreg:B (truncate:C X) 0)) is (truncate:A X).  */
     824                 :       47300 :       if (GET_CODE (SUBREG_REG (op)) == TRUNCATE)
     825                 :             :         {
     826                 :           0 :           rtx inner = XEXP (SUBREG_REG (op), 0);
     827                 :           0 :           if (GET_MODE_PRECISION (int_mode)
     828                 :           0 :               <= GET_MODE_PRECISION (subreg_mode))
     829                 :           0 :             return simplify_gen_unary (TRUNCATE, int_mode, inner,
     830                 :           0 :                                        GET_MODE (inner));
     831                 :             :           else
     832                 :             :             /* If subreg above is paradoxical and C is narrower
     833                 :             :                than A, return (subreg:A (truncate:C X) 0).  */
     834                 :           0 :             return simplify_gen_subreg (int_mode, SUBREG_REG (op),
     835                 :           0 :                                         subreg_mode, 0);
     836                 :             :         }
     837                 :             : 
     838                 :             :       /* Simplifications of (truncate:A (subreg:B X:C 0)) with
     839                 :             :          paradoxical subregs (B is wider than C).  */
     840                 :       47300 :       if (is_a <scalar_int_mode> (op_mode, &int_op_mode))
     841                 :             :         {
     842                 :       47300 :           unsigned int int_op_prec = GET_MODE_PRECISION (int_op_mode);
     843                 :       47300 :           unsigned int subreg_prec = GET_MODE_PRECISION (subreg_mode);
     844                 :       47300 :           if (int_op_prec > subreg_prec)
     845                 :             :             {
     846                 :        1477 :               if (int_mode == subreg_mode)
     847                 :             :                 return SUBREG_REG (op);
     848                 :          61 :               if (GET_MODE_PRECISION (int_mode) < subreg_prec)
     849                 :          27 :                 return simplify_gen_unary (TRUNCATE, int_mode,
     850                 :          27 :                                            SUBREG_REG (op), subreg_mode);
     851                 :             :             }
     852                 :             :           /* Simplification of (truncate:A (subreg:B X:C 0)) where
     853                 :             :              A is narrower than B and B is narrower than C.  */
     854                 :       45823 :           else if (int_op_prec < subreg_prec
     855                 :       45823 :                    && GET_MODE_PRECISION (int_mode) < int_op_prec)
     856                 :       45823 :             return simplify_gen_unary (TRUNCATE, int_mode,
     857                 :       45823 :                                        SUBREG_REG (op), subreg_mode);
     858                 :             :         }
     859                 :             :     }
     860                 :             : 
     861                 :             :   /* (truncate:A (truncate:B X)) is (truncate:A X).  */
     862                 :    18678771 :   if (GET_CODE (op) == TRUNCATE)
     863                 :           0 :     return simplify_gen_unary (TRUNCATE, mode, XEXP (op, 0),
     864                 :           0 :                                GET_MODE (XEXP (op, 0)));
     865                 :             : 
     866                 :             :   /* (truncate:A (ior X C)) is (const_int -1) if C is equal to that already,
     867                 :             :      in mode A.  */
     868                 :    18678771 :   if (GET_CODE (op) == IOR
     869                 :       91609 :       && SCALAR_INT_MODE_P (mode)
     870                 :       91609 :       && SCALAR_INT_MODE_P (op_mode)
     871                 :       91609 :       && CONST_INT_P (XEXP (op, 1))
     872                 :    18687543 :       && trunc_int_for_mode (INTVAL (XEXP (op, 1)), mode) == -1)
     873                 :          18 :     return constm1_rtx;
     874                 :             : 
     875                 :             :   return NULL_RTX;
     876                 :             : }
     877                 :             : 
     878                 :             : /* Try to simplify a unary operation CODE whose output mode is to be
     879                 :             :    MODE with input operand OP whose mode was originally OP_MODE.
     880                 :             :    Return zero if no simplification can be made.  */
     881                 :             : rtx
     882                 :    26436688 : simplify_context::simplify_unary_operation (rtx_code code, machine_mode mode,
     883                 :             :                                             rtx op, machine_mode op_mode)
     884                 :             : {
     885                 :    26436688 :   rtx trueop, tem;
     886                 :             : 
     887                 :    26436688 :   trueop = avoid_constant_pool_reference (op);
     888                 :             : 
     889                 :    26436688 :   tem = simplify_const_unary_operation (code, mode, trueop, op_mode);
     890                 :    26436688 :   if (tem)
     891                 :             :     return tem;
     892                 :             : 
     893                 :    21572580 :   return simplify_unary_operation_1 (code, mode, op);
     894                 :             : }
     895                 :             : 
     896                 :             : /* Return true if FLOAT or UNSIGNED_FLOAT operation OP is known
     897                 :             :    to be exact.  */
     898                 :             : 
     899                 :             : static bool
     900                 :        2756 : exact_int_to_float_conversion_p (const_rtx op)
     901                 :             : {
     902                 :        2756 :   machine_mode op0_mode = GET_MODE (XEXP (op, 0));
     903                 :             :   /* Constants can reach here with -frounding-math, if they do then
     904                 :             :      the conversion isn't exact.  */
     905                 :        2756 :   if (op0_mode == VOIDmode)
     906                 :             :     return false;
     907                 :        5510 :   int out_bits = significand_size (GET_MODE_INNER (GET_MODE (op)));
     908                 :        2755 :   int in_prec = GET_MODE_UNIT_PRECISION (op0_mode);
     909                 :        2755 :   int in_bits = in_prec;
     910                 :        2755 :   if (HWI_COMPUTABLE_MODE_P (op0_mode))
     911                 :             :     {
     912                 :        2665 :       unsigned HOST_WIDE_INT nonzero = nonzero_bits (XEXP (op, 0), op0_mode);
     913                 :        2665 :       if (GET_CODE (op) == FLOAT)
     914                 :        2523 :         in_bits -= num_sign_bit_copies (XEXP (op, 0), op0_mode);
     915                 :         142 :       else if (GET_CODE (op) == UNSIGNED_FLOAT)
     916                 :         142 :         in_bits = wi::min_precision (wi::uhwi (nonzero, in_prec), UNSIGNED);
     917                 :             :       else
     918                 :           0 :         gcc_unreachable ();
     919                 :        2665 :       in_bits -= wi::ctz (wi::uhwi (nonzero, in_prec));
     920                 :             :     }
     921                 :        2755 :   return in_bits <= out_bits;
     922                 :             : }
     923                 :             : 
     924                 :             : /* Perform some simplifications we can do even if the operands
     925                 :             :    aren't constant.  */
     926                 :             : rtx
     927                 :    21572580 : simplify_context::simplify_unary_operation_1 (rtx_code code, machine_mode mode,
     928                 :             :                                               rtx op)
     929                 :             : {
     930                 :    21572580 :   enum rtx_code reversed;
     931                 :    21572580 :   rtx temp, elt, base, step;
     932                 :    21572580 :   scalar_int_mode inner, int_mode, op_mode, op0_mode;
     933                 :             : 
     934                 :    21572580 :   switch (code)
     935                 :             :     {
     936                 :     1649965 :     case NOT:
     937                 :             :       /* (not (not X)) == X.  */
     938                 :     1649965 :       if (GET_CODE (op) == NOT)
     939                 :        2313 :         return XEXP (op, 0);
     940                 :             : 
     941                 :             :       /* (not (eq X Y)) == (ne X Y), etc. if BImode or the result of the
     942                 :             :          comparison is all ones.   */
     943                 :     1647652 :       if (COMPARISON_P (op)
     944                 :       10862 :           && (mode == BImode || STORE_FLAG_VALUE == -1)
     945                 :     1647652 :           && ((reversed = reversed_comparison_code (op, NULL)) != UNKNOWN))
     946                 :           0 :         return simplify_gen_relational (reversed, mode, VOIDmode,
     947                 :           0 :                                         XEXP (op, 0), XEXP (op, 1));
     948                 :             : 
     949                 :             :       /* (not (plus X -1)) can become (neg X).  */
     950                 :     1647652 :       if (GET_CODE (op) == PLUS
     951                 :      283496 :           && XEXP (op, 1) == constm1_rtx)
     952                 :        6784 :         return simplify_gen_unary (NEG, mode, XEXP (op, 0), mode);
     953                 :             : 
     954                 :             :       /* Similarly, (not (neg X)) is (plus X -1).  Only do this for
     955                 :             :          modes that have CONSTM1_RTX, i.e. MODE_INT, MODE_PARTIAL_INT
     956                 :             :          and MODE_VECTOR_INT.  */
     957                 :     1640868 :       if (GET_CODE (op) == NEG && CONSTM1_RTX (mode))
     958                 :       71722 :         return simplify_gen_binary (PLUS, mode, XEXP (op, 0),
     959                 :       71722 :                                     CONSTM1_RTX (mode));
     960                 :             : 
     961                 :             :       /* (not (xor X C)) for C constant is (xor X D) with D = ~C.  */
     962                 :     1569146 :       if (GET_CODE (op) == XOR
     963                 :       12122 :           && CONST_INT_P (XEXP (op, 1))
     964                 :     1571140 :           && (temp = simplify_unary_operation (NOT, mode,
     965                 :             :                                                XEXP (op, 1), mode)) != 0)
     966                 :        1994 :         return simplify_gen_binary (XOR, mode, XEXP (op, 0), temp);
     967                 :             : 
     968                 :             :       /* (not (plus X C)) for signbit C is (xor X D) with D = ~C.  */
     969                 :     1567152 :       if (GET_CODE (op) == PLUS
     970                 :      276712 :           && CONST_INT_P (XEXP (op, 1))
     971                 :      160786 :           && mode_signbit_p (mode, XEXP (op, 1))
     972                 :     1570136 :           && (temp = simplify_unary_operation (NOT, mode,
     973                 :             :                                                XEXP (op, 1), mode)) != 0)
     974                 :        2984 :         return simplify_gen_binary (XOR, mode, XEXP (op, 0), temp);
     975                 :             : 
     976                 :             : 
     977                 :             :       /* (not (ashift 1 X)) is (rotate ~1 X).  We used to do this for
     978                 :             :          operands other than 1, but that is not valid.  We could do a
     979                 :             :          similar simplification for (not (lshiftrt C X)) where C is
     980                 :             :          just the sign bit, but this doesn't seem common enough to
     981                 :             :          bother with.  */
     982                 :     1564168 :       if (GET_CODE (op) == ASHIFT
     983                 :       29465 :           && XEXP (op, 0) == const1_rtx)
     984                 :             :         {
     985                 :        1013 :           temp = simplify_gen_unary (NOT, mode, const1_rtx, mode);
     986                 :        1013 :           return simplify_gen_binary (ROTATE, mode, temp, XEXP (op, 1));
     987                 :             :         }
     988                 :             : 
     989                 :             :       /* (not (ashiftrt foo C)) where C is the number of bits in FOO
     990                 :             :          minus 1 is (ge foo (const_int 0)) if STORE_FLAG_VALUE is -1,
     991                 :             :          so we can perform the above simplification.  */
     992                 :     1563155 :       if (STORE_FLAG_VALUE == -1
     993                 :             :           && is_a <scalar_int_mode> (mode, &int_mode)
     994                 :             :           && GET_CODE (op) == ASHIFTRT
     995                 :             :           && CONST_INT_P (XEXP (op, 1))
     996                 :             :           && INTVAL (XEXP (op, 1)) == GET_MODE_PRECISION (int_mode) - 1)
     997                 :             :         return simplify_gen_relational (GE, int_mode, VOIDmode,
     998                 :             :                                         XEXP (op, 0), const0_rtx);
     999                 :             : 
    1000                 :             : 
    1001                 :     1563155 :       if (partial_subreg_p (op)
    1002                 :       70254 :           && subreg_lowpart_p (op)
    1003                 :       69992 :           && GET_CODE (SUBREG_REG (op)) == ASHIFT
    1004                 :     1563595 :           && XEXP (SUBREG_REG (op), 0) == const1_rtx)
    1005                 :             :         {
    1006                 :          35 :           machine_mode inner_mode = GET_MODE (SUBREG_REG (op));
    1007                 :          35 :           rtx x;
    1008                 :             : 
    1009                 :          35 :           x = gen_rtx_ROTATE (inner_mode,
    1010                 :             :                               simplify_gen_unary (NOT, inner_mode, const1_rtx,
    1011                 :             :                                                   inner_mode),
    1012                 :             :                               XEXP (SUBREG_REG (op), 1));
    1013                 :          35 :           temp = rtl_hooks.gen_lowpart_no_emit (mode, x);
    1014                 :          35 :           if (temp)
    1015                 :             :             return temp;
    1016                 :             :         }
    1017                 :             : 
    1018                 :             :       /* Apply De Morgan's laws to reduce number of patterns for machines
    1019                 :             :          with negating logical insns (and-not, nand, etc.).  If result has
    1020                 :             :          only one NOT, put it first, since that is how the patterns are
    1021                 :             :          coded.  */
    1022                 :     1563120 :       if (GET_CODE (op) == IOR || GET_CODE (op) == AND)
    1023                 :             :         {
    1024                 :       10252 :           rtx in1 = XEXP (op, 0), in2 = XEXP (op, 1);
    1025                 :       10252 :           machine_mode op_mode;
    1026                 :             : 
    1027                 :       10252 :           op_mode = GET_MODE (in1);
    1028                 :       10252 :           in1 = simplify_gen_unary (NOT, op_mode, in1, op_mode);
    1029                 :             : 
    1030                 :       10252 :           op_mode = GET_MODE (in2);
    1031                 :       10252 :           if (op_mode == VOIDmode)
    1032                 :        5017 :             op_mode = mode;
    1033                 :       10252 :           in2 = simplify_gen_unary (NOT, op_mode, in2, op_mode);
    1034                 :             : 
    1035                 :       10252 :           if (GET_CODE (in2) == NOT && GET_CODE (in1) != NOT)
    1036                 :             :             std::swap (in1, in2);
    1037                 :             : 
    1038                 :       20504 :           return gen_rtx_fmt_ee (GET_CODE (op) == IOR ? AND : IOR,
    1039                 :             :                                  mode, in1, in2);
    1040                 :             :         }
    1041                 :             : 
    1042                 :             :       /* (not (bswap x)) -> (bswap (not x)).  */
    1043                 :     1552868 :       if (GET_CODE (op) == BSWAP || GET_CODE (op) == BITREVERSE)
    1044                 :             :         {
    1045                 :           0 :           rtx x = simplify_gen_unary (NOT, mode, XEXP (op, 0), mode);
    1046                 :           0 :           return simplify_gen_unary (GET_CODE (op), mode, x, mode);
    1047                 :             :         }
    1048                 :             :       break;
    1049                 :             : 
    1050                 :     1590245 :     case NEG:
    1051                 :             :       /* (neg (neg X)) == X.  */
    1052                 :     1590245 :       if (GET_CODE (op) == NEG)
    1053                 :        6147 :         return XEXP (op, 0);
    1054                 :             : 
    1055                 :             :       /* (neg (x ? (neg y) : y)) == !x ? (neg y) : y.
    1056                 :             :          If comparison is not reversible use
    1057                 :             :          x ? y : (neg y).  */
    1058                 :     1584098 :       if (GET_CODE (op) == IF_THEN_ELSE)
    1059                 :             :         {
    1060                 :        2201 :           rtx cond = XEXP (op, 0);
    1061                 :        2201 :           rtx true_rtx = XEXP (op, 1);
    1062                 :        2201 :           rtx false_rtx = XEXP (op, 2);
    1063                 :             : 
    1064                 :        2201 :           if ((GET_CODE (true_rtx) == NEG
    1065                 :           0 :                && rtx_equal_p (XEXP (true_rtx, 0), false_rtx))
    1066                 :        2201 :                || (GET_CODE (false_rtx) == NEG
    1067                 :           0 :                    && rtx_equal_p (XEXP (false_rtx, 0), true_rtx)))
    1068                 :             :             {
    1069                 :           0 :               if (reversed_comparison_code (cond, NULL) != UNKNOWN)
    1070                 :           0 :                 temp = reversed_comparison (cond, mode);
    1071                 :             :               else
    1072                 :             :                 {
    1073                 :             :                   temp = cond;
    1074                 :             :                   std::swap (true_rtx, false_rtx);
    1075                 :             :                 }
    1076                 :           0 :               return simplify_gen_ternary (IF_THEN_ELSE, mode,
    1077                 :           0 :                                             mode, temp, true_rtx, false_rtx);
    1078                 :             :             }
    1079                 :             :         }
    1080                 :             : 
    1081                 :             :       /* (neg (plus X 1)) can become (not X).  */
    1082                 :     1584098 :       if (GET_CODE (op) == PLUS
    1083                 :      125340 :           && XEXP (op, 1) == const1_rtx)
    1084                 :       51267 :         return simplify_gen_unary (NOT, mode, XEXP (op, 0), mode);
    1085                 :             : 
    1086                 :             :       /* Similarly, (neg (not X)) is (plus X 1).  */
    1087                 :     1532831 :       if (GET_CODE (op) == NOT)
    1088                 :         466 :         return simplify_gen_binary (PLUS, mode, XEXP (op, 0),
    1089                 :         466 :                                     CONST1_RTX (mode));
    1090                 :             : 
    1091                 :             :       /* (neg (minus X Y)) can become (minus Y X).  This transformation
    1092                 :             :          isn't safe for modes with signed zeros, since if X and Y are
    1093                 :             :          both +0, (minus Y X) is the same as (minus X Y).  If the
    1094                 :             :          rounding mode is towards +infinity (or -infinity) then the two
    1095                 :             :          expressions will be rounded differently.  */
    1096                 :     1532365 :       if (GET_CODE (op) == MINUS
    1097                 :       22210 :           && !HONOR_SIGNED_ZEROS (mode)
    1098                 :     1553161 :           && !HONOR_SIGN_DEPENDENT_ROUNDING (mode))
    1099                 :       20796 :         return simplify_gen_binary (MINUS, mode, XEXP (op, 1), XEXP (op, 0));
    1100                 :             : 
    1101                 :     1511569 :       if (GET_CODE (op) == PLUS
    1102                 :       74073 :           && !HONOR_SIGNED_ZEROS (mode)
    1103                 :     1585286 :           && !HONOR_SIGN_DEPENDENT_ROUNDING (mode))
    1104                 :             :         {
    1105                 :             :           /* (neg (plus A C)) is simplified to (minus -C A).  */
    1106                 :       73717 :           if (CONST_SCALAR_INT_P (XEXP (op, 1))
    1107                 :        5047 :               || CONST_DOUBLE_AS_FLOAT_P (XEXP (op, 1)))
    1108                 :             :             {
    1109                 :       68671 :               temp = simplify_unary_operation (NEG, mode, XEXP (op, 1), mode);
    1110                 :       68671 :               if (temp)
    1111                 :       68671 :                 return simplify_gen_binary (MINUS, mode, temp, XEXP (op, 0));
    1112                 :             :             }
    1113                 :             : 
    1114                 :             :           /* (neg (plus A B)) is canonicalized to (minus (neg A) B).  */
    1115                 :        5046 :           temp = simplify_gen_unary (NEG, mode, XEXP (op, 0), mode);
    1116                 :        5046 :           return simplify_gen_binary (MINUS, mode, temp, XEXP (op, 1));
    1117                 :             :         }
    1118                 :             : 
    1119                 :             :       /* (neg (mult A B)) becomes (mult A (neg B)).
    1120                 :             :          This works even for floating-point values.  */
    1121                 :     1437852 :       if (GET_CODE (op) == MULT
    1122                 :     1437852 :           && !HONOR_SIGN_DEPENDENT_ROUNDING (mode))
    1123                 :             :         {
    1124                 :       20350 :           temp = simplify_gen_unary (NEG, mode, XEXP (op, 1), mode);
    1125                 :       20350 :           return simplify_gen_binary (MULT, mode, XEXP (op, 0), temp);
    1126                 :             :         }
    1127                 :             : 
    1128                 :             :       /* NEG commutes with ASHIFT since it is multiplication.  Only do
    1129                 :             :          this if we can then eliminate the NEG (e.g., if the operand
    1130                 :             :          is a constant).  */
    1131                 :     1417502 :       if (GET_CODE (op) == ASHIFT)
    1132                 :             :         {
    1133                 :       52528 :           temp = simplify_unary_operation (NEG, mode, XEXP (op, 0), mode);
    1134                 :       52528 :           if (temp)
    1135                 :       13024 :             return simplify_gen_binary (ASHIFT, mode, temp, XEXP (op, 1));
    1136                 :             :         }
    1137                 :             : 
    1138                 :             :       /* (neg (ashiftrt X C)) can be replaced by (lshiftrt X C) when
    1139                 :             :          C is equal to the width of MODE minus 1.  */
    1140                 :     1404478 :       if (GET_CODE (op) == ASHIFTRT
    1141                 :       26670 :           && CONST_INT_P (XEXP (op, 1))
    1142                 :     1457738 :           && INTVAL (XEXP (op, 1)) == GET_MODE_UNIT_PRECISION (mode) - 1)
    1143                 :         429 :         return simplify_gen_binary (LSHIFTRT, mode,
    1144                 :         429 :                                     XEXP (op, 0), XEXP (op, 1));
    1145                 :             : 
    1146                 :             :       /* (neg (lshiftrt X C)) can be replaced by (ashiftrt X C) when
    1147                 :             :          C is equal to the width of MODE minus 1.  */
    1148                 :     1404049 :       if (GET_CODE (op) == LSHIFTRT
    1149                 :        6737 :           && CONST_INT_P (XEXP (op, 1))
    1150                 :     1417363 :           && INTVAL (XEXP (op, 1)) == GET_MODE_UNIT_PRECISION (mode) - 1)
    1151                 :        2415 :         return simplify_gen_binary (ASHIFTRT, mode,
    1152                 :        2415 :                                     XEXP (op, 0), XEXP (op, 1));
    1153                 :             : 
    1154                 :             :       /* (neg (xor A 1)) is (plus A -1) if A is known to be either 0 or 1.  */
    1155                 :     1401634 :       if (GET_CODE (op) == XOR
    1156                 :        8391 :           && XEXP (op, 1) == const1_rtx
    1157                 :     1401782 :           && nonzero_bits (XEXP (op, 0), mode) == 1)
    1158                 :          52 :         return plus_constant (mode, XEXP (op, 0), -1);
    1159                 :             : 
    1160                 :             :       /* (neg (lt x 0)) is (ashiftrt X C) if STORE_FLAG_VALUE is 1.  */
    1161                 :             :       /* (neg (lt x 0)) is (lshiftrt X C) if STORE_FLAG_VALUE is -1.  */
    1162                 :     1401582 :       if (GET_CODE (op) == LT
    1163                 :        1569 :           && XEXP (op, 1) == const0_rtx
    1164                 :     1402674 :           && is_a <scalar_int_mode> (GET_MODE (XEXP (op, 0)), &inner))
    1165                 :             :         {
    1166                 :         249 :           int_mode = as_a <scalar_int_mode> (mode);
    1167                 :         249 :           int isize = GET_MODE_PRECISION (inner);
    1168                 :         249 :           if (STORE_FLAG_VALUE == 1)
    1169                 :             :             {
    1170                 :         249 :               temp = simplify_gen_binary (ASHIFTRT, inner, XEXP (op, 0),
    1171                 :         249 :                                           gen_int_shift_amount (inner,
    1172                 :         249 :                                                                 isize - 1));
    1173                 :         249 :               if (int_mode == inner)
    1174                 :             :                 return temp;
    1175                 :         129 :               if (GET_MODE_PRECISION (int_mode) > isize)
    1176                 :          65 :                 return simplify_gen_unary (SIGN_EXTEND, int_mode, temp, inner);
    1177                 :          64 :               return simplify_gen_unary (TRUNCATE, int_mode, temp, inner);
    1178                 :             :             }
    1179                 :             :           else if (STORE_FLAG_VALUE == -1)
    1180                 :             :             {
    1181                 :             :               temp = simplify_gen_binary (LSHIFTRT, inner, XEXP (op, 0),
    1182                 :             :                                           gen_int_shift_amount (inner,
    1183                 :             :                                                                 isize - 1));
    1184                 :             :               if (int_mode == inner)
    1185                 :             :                 return temp;
    1186                 :             :               if (GET_MODE_PRECISION (int_mode) > isize)
    1187                 :             :                 return simplify_gen_unary (ZERO_EXTEND, int_mode, temp, inner);
    1188                 :             :               return simplify_gen_unary (TRUNCATE, int_mode, temp, inner);
    1189                 :             :             }
    1190                 :             :         }
    1191                 :             : 
    1192                 :     1401333 :       if (vec_series_p (op, &base, &step))
    1193                 :             :         {
    1194                 :             :           /* Only create a new series if we can simplify both parts.  In other
    1195                 :             :              cases this isn't really a simplification, and it's not necessarily
    1196                 :             :              a win to replace a vector operation with a scalar operation.  */
    1197                 :         288 :           scalar_mode inner_mode = GET_MODE_INNER (mode);
    1198                 :         288 :           base = simplify_unary_operation (NEG, inner_mode, base, inner_mode);
    1199                 :         288 :           if (base)
    1200                 :             :             {
    1201                 :         288 :               step = simplify_unary_operation (NEG, inner_mode,
    1202                 :             :                                                step, inner_mode);
    1203                 :         288 :               if (step)
    1204                 :         288 :                 return gen_vec_series (mode, base, step);
    1205                 :             :             }
    1206                 :             :         }
    1207                 :             :       break;
    1208                 :             : 
    1209                 :     1463764 :     case TRUNCATE:
    1210                 :             :       /* Don't optimize (lshiftrt (mult ...)) as it would interfere
    1211                 :             :          with the umulXi3_highpart patterns.  */
    1212                 :     1463764 :       if (GET_CODE (op) == LSHIFTRT
    1213                 :       17994 :           && GET_CODE (XEXP (op, 0)) == MULT)
    1214                 :             :         break;
    1215                 :             : 
    1216                 :     1456005 :       if (GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
    1217                 :             :         {
    1218                 :          12 :           if (TRULY_NOOP_TRUNCATION_MODES_P (mode, GET_MODE (op)))
    1219                 :             :             {
    1220                 :          12 :               temp = rtl_hooks.gen_lowpart_no_emit (mode, op);
    1221                 :          12 :               if (temp)
    1222                 :             :                 return temp;
    1223                 :             :             }
    1224                 :             :           /* We can't handle truncation to a partial integer mode here
    1225                 :             :              because we don't know the real bitsize of the partial
    1226                 :             :              integer mode.  */
    1227                 :             :           break;
    1228                 :             :         }
    1229                 :             : 
    1230                 :     1455993 :       if (GET_MODE (op) != VOIDmode)
    1231                 :             :         {
    1232                 :     1455993 :           temp = simplify_truncation (mode, op, GET_MODE (op));
    1233                 :     1455993 :           if (temp)
    1234                 :             :             return temp;
    1235                 :             :         }
    1236                 :             : 
    1237                 :             :       /* If we know that the value is already truncated, we can
    1238                 :             :          replace the TRUNCATE with a SUBREG.  */
    1239                 :     1303507 :       if (known_eq (GET_MODE_NUNITS (mode), 1)
    1240                 :     1303507 :           && (TRULY_NOOP_TRUNCATION_MODES_P (mode, GET_MODE (op))
    1241                 :           0 :               || truncated_to_mode (mode, op)))
    1242                 :             :         {
    1243                 :     1292904 :           temp = rtl_hooks.gen_lowpart_no_emit (mode, op);
    1244                 :     1292904 :           if (temp)
    1245                 :             :             return temp;
    1246                 :             :         }
    1247                 :             : 
    1248                 :             :       /* A truncate of a comparison can be replaced with a subreg if
    1249                 :             :          STORE_FLAG_VALUE permits.  This is like the previous test,
    1250                 :             :          but it works even if the comparison is done in a mode larger
    1251                 :             :          than HOST_BITS_PER_WIDE_INT.  */
    1252                 :       10796 :       if (HWI_COMPUTABLE_MODE_P (mode)
    1253                 :         193 :           && COMPARISON_P (op)
    1254                 :           0 :           && (STORE_FLAG_VALUE & ~GET_MODE_MASK (mode)) == 0
    1255                 :       10796 :           && TRULY_NOOP_TRUNCATION_MODES_P (mode, GET_MODE (op)))
    1256                 :             :         {
    1257                 :           0 :           temp = rtl_hooks.gen_lowpart_no_emit (mode, op);
    1258                 :           0 :           if (temp)
    1259                 :             :             return temp;
    1260                 :             :         }
    1261                 :             : 
    1262                 :             :       /* A truncate of a memory is just loading the low part of the memory
    1263                 :             :          if we are not changing the meaning of the address. */
    1264                 :       10796 :       if (GET_CODE (op) == MEM
    1265                 :         301 :           && !VECTOR_MODE_P (mode)
    1266                 :         191 :           && !MEM_VOLATILE_P (op)
    1267                 :       10987 :           && !mode_dependent_address_p (XEXP (op, 0), MEM_ADDR_SPACE (op)))
    1268                 :             :         {
    1269                 :         191 :           temp = rtl_hooks.gen_lowpart_no_emit (mode, op);
    1270                 :         191 :           if (temp)
    1271                 :             :             return temp;
    1272                 :             :         }
    1273                 :             : 
    1274                 :             :       /* Check for useless truncation.  */
    1275                 :       10796 :       if (GET_MODE (op) == mode)
    1276                 :             :         return op;
    1277                 :             :       break;
    1278                 :             : 
    1279                 :      172816 :     case FLOAT_TRUNCATE:
    1280                 :             :       /* Check for useless truncation.  */
    1281                 :      172816 :       if (GET_MODE (op) == mode)
    1282                 :             :         return op;
    1283                 :             : 
    1284                 :      172816 :       if (DECIMAL_FLOAT_MODE_P (mode))
    1285                 :             :         break;
    1286                 :             : 
    1287                 :             :       /* (float_truncate:SF (float_extend:DF foo:SF)) = foo:SF.  */
    1288                 :      172662 :       if (GET_CODE (op) == FLOAT_EXTEND
    1289                 :           4 :           && GET_MODE (XEXP (op, 0)) == mode)
    1290                 :             :         return XEXP (op, 0);
    1291                 :             : 
    1292                 :             :       /* (float_truncate:SF (float_truncate:DF foo:XF))
    1293                 :             :          = (float_truncate:SF foo:XF).
    1294                 :             :          This may eliminate double rounding, so it is unsafe.
    1295                 :             : 
    1296                 :             :          (float_truncate:SF (float_extend:XF foo:DF))
    1297                 :             :          = (float_truncate:SF foo:DF).
    1298                 :             : 
    1299                 :             :          (float_truncate:DF (float_extend:XF foo:SF))
    1300                 :             :          = (float_extend:DF foo:SF).  */
    1301                 :      172660 :       if ((GET_CODE (op) == FLOAT_TRUNCATE
    1302                 :         133 :            && flag_unsafe_math_optimizations)
    1303                 :      172656 :           || GET_CODE (op) == FLOAT_EXTEND)
    1304                 :          12 :         return simplify_gen_unary (GET_MODE_UNIT_SIZE (GET_MODE (XEXP (op, 0)))
    1305                 :           6 :                                    > GET_MODE_UNIT_SIZE (mode)
    1306                 :             :                                    ? FLOAT_TRUNCATE : FLOAT_EXTEND,
    1307                 :             :                                    mode,
    1308                 :          12 :                                    XEXP (op, 0), GET_MODE (XEXP (op, 0)));
    1309                 :             : 
    1310                 :             :       /*  (float_truncate (float x)) is (float x)  */
    1311                 :      172654 :       if ((GET_CODE (op) == FLOAT || GET_CODE (op) == UNSIGNED_FLOAT)
    1312                 :      172654 :           && (flag_unsafe_math_optimizations
    1313                 :        1455 :               || exact_int_to_float_conversion_p (op)))
    1314                 :        1454 :         return simplify_gen_unary (GET_CODE (op), mode,
    1315                 :             :                                    XEXP (op, 0),
    1316                 :        1454 :                                    GET_MODE (XEXP (op, 0)));
    1317                 :             : 
    1318                 :             :       /* (float_truncate:SF (OP:DF (float_extend:DF foo:sf))) is
    1319                 :             :          (OP:SF foo:SF) if OP is NEG or ABS.  */
    1320                 :      171200 :       if ((GET_CODE (op) == ABS
    1321                 :      171200 :            || GET_CODE (op) == NEG)
    1322                 :         209 :           && GET_CODE (XEXP (op, 0)) == FLOAT_EXTEND
    1323                 :          28 :           && GET_MODE (XEXP (XEXP (op, 0), 0)) == mode)
    1324                 :          28 :         return simplify_gen_unary (GET_CODE (op), mode,
    1325                 :          28 :                                    XEXP (XEXP (op, 0), 0), mode);
    1326                 :             : 
    1327                 :             :       /* (float_truncate:SF (subreg:DF (float_truncate:SF X) 0))
    1328                 :             :          is (float_truncate:SF x).  */
    1329                 :      171172 :       if (GET_CODE (op) == SUBREG
    1330                 :         299 :           && subreg_lowpart_p (op)
    1331                 :      171467 :           && GET_CODE (SUBREG_REG (op)) == FLOAT_TRUNCATE)
    1332                 :             :         return SUBREG_REG (op);
    1333                 :             :       break;
    1334                 :             : 
    1335                 :      578373 :     case FLOAT_EXTEND:
    1336                 :             :       /* Check for useless extension.  */
    1337                 :      578373 :       if (GET_MODE (op) == mode)
    1338                 :             :         return op;
    1339                 :             : 
    1340                 :      578373 :       if (DECIMAL_FLOAT_MODE_P (mode))
    1341                 :             :         break;
    1342                 :             : 
    1343                 :             :       /*  (float_extend (float_extend x)) is (float_extend x)
    1344                 :             : 
    1345                 :             :           (float_extend (float x)) is (float x) assuming that double
    1346                 :             :           rounding can't happen.
    1347                 :             :           */
    1348                 :      578270 :       if (GET_CODE (op) == FLOAT_EXTEND
    1349                 :      578270 :           || ((GET_CODE (op) == FLOAT || GET_CODE (op) == UNSIGNED_FLOAT)
    1350                 :        1301 :               && exact_int_to_float_conversion_p (op)))
    1351                 :         544 :         return simplify_gen_unary (GET_CODE (op), mode,
    1352                 :             :                                    XEXP (op, 0),
    1353                 :         544 :                                    GET_MODE (XEXP (op, 0)));
    1354                 :             : 
    1355                 :             :       break;
    1356                 :             : 
    1357                 :      269030 :     case ABS:
    1358                 :             :       /* (abs (neg <foo>)) -> (abs <foo>) */
    1359                 :      269030 :       if (GET_CODE (op) == NEG)
    1360                 :          56 :         return simplify_gen_unary (ABS, mode, XEXP (op, 0),
    1361                 :          56 :                                    GET_MODE (XEXP (op, 0)));
    1362                 :             : 
    1363                 :             :       /* If the mode of the operand is VOIDmode (i.e. if it is ASM_OPERANDS),
    1364                 :             :          do nothing.  */
    1365                 :      268974 :       if (GET_MODE (op) == VOIDmode)
    1366                 :             :         break;
    1367                 :             : 
    1368                 :             :       /* If operand is something known to be positive, ignore the ABS.  */
    1369                 :      268974 :       if (val_signbit_known_clear_p (GET_MODE (op),
    1370                 :             :                                      nonzero_bits (op, GET_MODE (op))))
    1371                 :             :         return op;
    1372                 :             : 
    1373                 :             :       /* Using nonzero_bits doesn't (currently) work for modes wider than
    1374                 :             :          HOST_WIDE_INT, so the following transformations help simplify
    1375                 :             :          ABS for TImode and wider.  */
    1376                 :      268802 :       switch (GET_CODE (op))
    1377                 :             :         {
    1378                 :             :         case ABS:
    1379                 :             :         case CLRSB:
    1380                 :             :         case FFS:
    1381                 :             :         case PARITY:
    1382                 :             :         case POPCOUNT:
    1383                 :             :         case SS_ABS:
    1384                 :             :           return op;
    1385                 :             : 
    1386                 :           0 :         case LSHIFTRT:
    1387                 :           0 :           if (CONST_INT_P (XEXP (op, 1))
    1388                 :           0 :               && INTVAL (XEXP (op, 1)) > 0
    1389                 :      268802 :               && is_a <scalar_int_mode> (mode, &int_mode)
    1390                 :           0 :               && INTVAL (XEXP (op, 1)) < GET_MODE_PRECISION (int_mode))
    1391                 :             :             return op;
    1392                 :             :           break;
    1393                 :             : 
    1394                 :             :         default:
    1395                 :             :           break;
    1396                 :             :         }
    1397                 :             : 
    1398                 :             :       /* If operand is known to be only -1 or 0, convert ABS to NEG.  */
    1399                 :      268802 :       if (is_a <scalar_int_mode> (mode, &int_mode)
    1400                 :       42338 :           && (num_sign_bit_copies (op, int_mode)
    1401                 :       42338 :               == GET_MODE_PRECISION (int_mode)))
    1402                 :           4 :         return gen_rtx_NEG (int_mode, op);
    1403                 :             : 
    1404                 :             :       break;
    1405                 :             : 
    1406                 :           0 :     case FFS:
    1407                 :             :       /* (ffs (*_extend <X>)) = (*_extend (ffs <X>)).  */
    1408                 :           0 :       if (GET_CODE (op) == SIGN_EXTEND
    1409                 :           0 :           || GET_CODE (op) == ZERO_EXTEND)
    1410                 :             :         {
    1411                 :           0 :           temp = simplify_gen_unary (FFS, GET_MODE (XEXP (op, 0)),
    1412                 :           0 :                                      XEXP (op, 0), GET_MODE (XEXP (op, 0)));
    1413                 :           0 :           return simplify_gen_unary (GET_CODE (op), mode, temp,
    1414                 :           0 :                                      GET_MODE (temp));
    1415                 :             :         }
    1416                 :             :       break;
    1417                 :             : 
    1418                 :        3254 :     case POPCOUNT:
    1419                 :        3254 :       switch (GET_CODE (op))
    1420                 :             :         {
    1421                 :           0 :         case BSWAP:
    1422                 :           0 :         case BITREVERSE:
    1423                 :             :           /* (popcount (bswap <X>)) = (popcount <X>).  */
    1424                 :           0 :           return simplify_gen_unary (POPCOUNT, mode, XEXP (op, 0),
    1425                 :           0 :                                      GET_MODE (XEXP (op, 0)));
    1426                 :             : 
    1427                 :          34 :         case ZERO_EXTEND:
    1428                 :             :           /* (popcount (zero_extend <X>)) = (zero_extend (popcount <X>)).  */
    1429                 :          68 :           temp = simplify_gen_unary (POPCOUNT, GET_MODE (XEXP (op, 0)),
    1430                 :          34 :                                      XEXP (op, 0), GET_MODE (XEXP (op, 0)));
    1431                 :          34 :           return simplify_gen_unary (ZERO_EXTEND, mode, temp,
    1432                 :          34 :                                      GET_MODE (temp));
    1433                 :             : 
    1434                 :           0 :         case ROTATE:
    1435                 :           0 :         case ROTATERT:
    1436                 :             :           /* Rotations don't affect popcount.  */
    1437                 :           0 :           if (!side_effects_p (XEXP (op, 1)))
    1438                 :           0 :             return simplify_gen_unary (POPCOUNT, mode, XEXP (op, 0),
    1439                 :           0 :                                        GET_MODE (XEXP (op, 0)));
    1440                 :             :           break;
    1441                 :             : 
    1442                 :             :         default:
    1443                 :             :           break;
    1444                 :             :         }
    1445                 :             :       break;
    1446                 :             : 
    1447                 :           0 :     case PARITY:
    1448                 :           0 :       switch (GET_CODE (op))
    1449                 :             :         {
    1450                 :           0 :         case NOT:
    1451                 :           0 :         case BSWAP:
    1452                 :           0 :         case BITREVERSE:
    1453                 :           0 :           return simplify_gen_unary (PARITY, mode, XEXP (op, 0),
    1454                 :           0 :                                      GET_MODE (XEXP (op, 0)));
    1455                 :             : 
    1456                 :           0 :         case ZERO_EXTEND:
    1457                 :           0 :         case SIGN_EXTEND:
    1458                 :           0 :           temp = simplify_gen_unary (PARITY, GET_MODE (XEXP (op, 0)),
    1459                 :           0 :                                      XEXP (op, 0), GET_MODE (XEXP (op, 0)));
    1460                 :           0 :           return simplify_gen_unary (GET_CODE (op), mode, temp,
    1461                 :           0 :                                      GET_MODE (temp));
    1462                 :             : 
    1463                 :           0 :         case ROTATE:
    1464                 :           0 :         case ROTATERT:
    1465                 :             :           /* Rotations don't affect parity.  */
    1466                 :           0 :           if (!side_effects_p (XEXP (op, 1)))
    1467                 :           0 :             return simplify_gen_unary (PARITY, mode, XEXP (op, 0),
    1468                 :           0 :                                        GET_MODE (XEXP (op, 0)));
    1469                 :             :           break;
    1470                 :             : 
    1471                 :             :         case PARITY:
    1472                 :             :           /* (parity (parity x)) -> parity (x).  */
    1473                 :             :           return op;
    1474                 :             : 
    1475                 :             :         default:
    1476                 :             :           break;
    1477                 :             :         }
    1478                 :             :       break;
    1479                 :             : 
    1480                 :       27989 :     case BSWAP:
    1481                 :             :       /* (bswap (bswap x)) -> x.  */
    1482                 :       27989 :       if (GET_CODE (op) == BSWAP)
    1483                 :         163 :         return XEXP (op, 0);
    1484                 :             :       break;
    1485                 :             : 
    1486                 :           0 :     case BITREVERSE:
    1487                 :             :       /* (bitreverse (bitreverse x)) -> x.  */
    1488                 :           0 :       if (GET_CODE (op) == BITREVERSE)
    1489                 :           0 :         return XEXP (op, 0);
    1490                 :             :       break;
    1491                 :             : 
    1492                 :      910243 :     case FLOAT:
    1493                 :             :       /* (float (sign_extend <X>)) = (float <X>).  */
    1494                 :      910243 :       if (GET_CODE (op) == SIGN_EXTEND)
    1495                 :       11207 :         return simplify_gen_unary (FLOAT, mode, XEXP (op, 0),
    1496                 :       11207 :                                    GET_MODE (XEXP (op, 0)));
    1497                 :             :       break;
    1498                 :             : 
    1499                 :     3362135 :     case SIGN_EXTEND:
    1500                 :             :       /* Check for useless extension.  */
    1501                 :     3362135 :       if (GET_MODE (op) == mode)
    1502                 :             :         return op;
    1503                 :             : 
    1504                 :             :       /* (sign_extend (truncate (minus (label_ref L1) (label_ref L2))))
    1505                 :             :          becomes just the MINUS if its mode is MODE.  This allows
    1506                 :             :          folding switch statements on machines using casesi (such as
    1507                 :             :          the VAX).  */
    1508                 :     3362095 :       if (GET_CODE (op) == TRUNCATE
    1509                 :          56 :           && GET_MODE (XEXP (op, 0)) == mode
    1510                 :          56 :           && GET_CODE (XEXP (op, 0)) == MINUS
    1511                 :           0 :           && GET_CODE (XEXP (XEXP (op, 0), 0)) == LABEL_REF
    1512                 :           0 :           && GET_CODE (XEXP (XEXP (op, 0), 1)) == LABEL_REF)
    1513                 :             :         return XEXP (op, 0);
    1514                 :             : 
    1515                 :             :       /* Extending a widening multiplication should be canonicalized to
    1516                 :             :          a wider widening multiplication.  */
    1517                 :     3362095 :       if (GET_CODE (op) == MULT)
    1518                 :             :         {
    1519                 :       70482 :           rtx lhs = XEXP (op, 0);
    1520                 :       70482 :           rtx rhs = XEXP (op, 1);
    1521                 :       70482 :           enum rtx_code lcode = GET_CODE (lhs);
    1522                 :       70482 :           enum rtx_code rcode = GET_CODE (rhs);
    1523                 :             : 
    1524                 :             :           /* Widening multiplies usually extend both operands, but sometimes
    1525                 :             :              they use a shift to extract a portion of a register.  */
    1526                 :       70482 :           if ((lcode == SIGN_EXTEND
    1527                 :       70331 :                || (lcode == ASHIFTRT && CONST_INT_P (XEXP (lhs, 1))))
    1528                 :         877 :               && (rcode == SIGN_EXTEND
    1529                 :         833 :                   || (rcode == ASHIFTRT && CONST_INT_P (XEXP (rhs, 1)))))
    1530                 :             :             {
    1531                 :         165 :               machine_mode lmode = GET_MODE (lhs);
    1532                 :         165 :               machine_mode rmode = GET_MODE (rhs);
    1533                 :         165 :               int bits;
    1534                 :             : 
    1535                 :         165 :               if (lcode == ASHIFTRT)
    1536                 :             :                 /* Number of bits not shifted off the end.  */
    1537                 :         125 :                 bits = (GET_MODE_UNIT_PRECISION (lmode)
    1538                 :         125 :                         - INTVAL (XEXP (lhs, 1)));
    1539                 :             :               else /* lcode == SIGN_EXTEND */
    1540                 :             :                 /* Size of inner mode.  */
    1541                 :          80 :                 bits = GET_MODE_UNIT_PRECISION (GET_MODE (XEXP (lhs, 0)));
    1542                 :             : 
    1543                 :         165 :               if (rcode == ASHIFTRT)
    1544                 :         121 :                 bits += (GET_MODE_UNIT_PRECISION (rmode)
    1545                 :         121 :                          - INTVAL (XEXP (rhs, 1)));
    1546                 :             :               else /* rcode == SIGN_EXTEND */
    1547                 :          88 :                 bits += GET_MODE_UNIT_PRECISION (GET_MODE (XEXP (rhs, 0)));
    1548                 :             : 
    1549                 :             :               /* We can only widen multiplies if the result is mathematiclly
    1550                 :             :                  equivalent.  I.e. if overflow was impossible.  */
    1551                 :         330 :               if (bits <= GET_MODE_UNIT_PRECISION (GET_MODE (op)))
    1552                 :         108 :                 return simplify_gen_binary
    1553                 :         108 :                          (MULT, mode,
    1554                 :             :                           simplify_gen_unary (SIGN_EXTEND, mode, lhs, lmode),
    1555                 :         108 :                           simplify_gen_unary (SIGN_EXTEND, mode, rhs, rmode));
    1556                 :             :             }
    1557                 :             :         }
    1558                 :             : 
    1559                 :             :       /* Check for a sign extension of a subreg of a promoted
    1560                 :             :          variable, where the promotion is sign-extended, and the
    1561                 :             :          target mode is the same as the variable's promotion.  */
    1562                 :     3361987 :       if (GET_CODE (op) == SUBREG
    1563                 :      274031 :           && SUBREG_PROMOTED_VAR_P (op)
    1564                 :     3368281 :           && SUBREG_PROMOTED_SIGNED_P (op))
    1565                 :             :         {
    1566                 :           0 :           rtx subreg = SUBREG_REG (op);
    1567                 :           0 :           machine_mode subreg_mode = GET_MODE (subreg);
    1568                 :           0 :           if (!paradoxical_subreg_p (mode, subreg_mode))
    1569                 :             :             {
    1570                 :           0 :               temp = rtl_hooks.gen_lowpart_no_emit (mode, subreg);
    1571                 :           0 :               if (temp)
    1572                 :             :                 {
    1573                 :             :                   /* Preserve SUBREG_PROMOTED_VAR_P.  */
    1574                 :           0 :                   if (partial_subreg_p (temp))
    1575                 :             :                     {
    1576                 :           0 :                       SUBREG_PROMOTED_VAR_P (temp) = 1;
    1577                 :           0 :                       SUBREG_PROMOTED_SET (temp, SRP_SIGNED);
    1578                 :             :                     }
    1579                 :           0 :                   return temp;
    1580                 :             :                 }
    1581                 :             :             }
    1582                 :             :           else
    1583                 :             :             /* Sign-extending a sign-extended subreg.  */
    1584                 :           0 :             return simplify_gen_unary (SIGN_EXTEND, mode,
    1585                 :           0 :                                        subreg, subreg_mode);
    1586                 :             :         }
    1587                 :             : 
    1588                 :             :       /* (sign_extend:M (sign_extend:N <X>)) is (sign_extend:M <X>).
    1589                 :             :          (sign_extend:M (zero_extend:N <X>)) is (zero_extend:M <X>).  */
    1590                 :     3361987 :       if (GET_CODE (op) == SIGN_EXTEND || GET_CODE (op) == ZERO_EXTEND)
    1591                 :             :         {
    1592                 :       37614 :           gcc_assert (GET_MODE_UNIT_PRECISION (mode)
    1593                 :             :                       > GET_MODE_UNIT_PRECISION (GET_MODE (op)));
    1594                 :       12538 :           return simplify_gen_unary (GET_CODE (op), mode, XEXP (op, 0),
    1595                 :       12538 :                                      GET_MODE (XEXP (op, 0)));
    1596                 :             :         }
    1597                 :             : 
    1598                 :             :       /* (sign_extend:M (ashiftrt:N (ashift <X> (const_int I)) (const_int I)))
    1599                 :             :          is (sign_extend:M (subreg:O <X>)) if there is mode with
    1600                 :             :          GET_MODE_BITSIZE (N) - I bits.
    1601                 :             :          (sign_extend:M (lshiftrt:N (ashift <X> (const_int I)) (const_int I)))
    1602                 :             :          is similarly (zero_extend:M (subreg:O <X>)).  */
    1603                 :     3349449 :       if ((GET_CODE (op) == ASHIFTRT || GET_CODE (op) == LSHIFTRT)
    1604                 :       94322 :           && GET_CODE (XEXP (op, 0)) == ASHIFT
    1605                 :     3351947 :           && is_a <scalar_int_mode> (mode, &int_mode)
    1606                 :        5026 :           && CONST_INT_P (XEXP (op, 1))
    1607                 :        5026 :           && XEXP (XEXP (op, 0), 1) == XEXP (op, 1)
    1608                 :     3354351 :           && (op_mode = as_a <scalar_int_mode> (GET_MODE (op)),
    1609                 :        4902 :               GET_MODE_PRECISION (op_mode) > INTVAL (XEXP (op, 1))))
    1610                 :             :         {
    1611                 :        4902 :           scalar_int_mode tmode;
    1612                 :        4902 :           gcc_assert (GET_MODE_PRECISION (int_mode)
    1613                 :             :                       > GET_MODE_PRECISION (op_mode));
    1614                 :        4902 :           if (int_mode_for_size (GET_MODE_PRECISION (op_mode)
    1615                 :        7276 :                                  - INTVAL (XEXP (op, 1)), 1).exists (&tmode))
    1616                 :             :             {
    1617                 :        2528 :               rtx inner =
    1618                 :        2528 :                 rtl_hooks.gen_lowpart_no_emit (tmode, XEXP (XEXP (op, 0), 0));
    1619                 :        2528 :               if (inner)
    1620                 :        2528 :                 return simplify_gen_unary (GET_CODE (op) == ASHIFTRT
    1621                 :             :                                            ? SIGN_EXTEND : ZERO_EXTEND,
    1622                 :        2528 :                                            int_mode, inner, tmode);
    1623                 :             :             }
    1624                 :             :         }
    1625                 :             : 
    1626                 :             :       /* (sign_extend:M (lshiftrt:N <X> (const_int I))) is better as
    1627                 :             :          (zero_extend:M (lshiftrt:N <X> (const_int I))) if I is not 0.  */
    1628                 :     3346921 :       if (GET_CODE (op) == LSHIFTRT
    1629                 :         446 :           && CONST_INT_P (XEXP (op, 1))
    1630                 :         446 :           && XEXP (op, 1) != const0_rtx)
    1631                 :         446 :         return simplify_gen_unary (ZERO_EXTEND, mode, op, GET_MODE (op));
    1632                 :             : 
    1633                 :             :       /* (sign_extend:M (truncate:N (lshiftrt:O <X> (const_int I)))) where
    1634                 :             :          I is GET_MODE_PRECISION(O) - GET_MODE_PRECISION(N), simplifies to
    1635                 :             :          (ashiftrt:M <X> (const_int I)) if modes M and O are the same, and
    1636                 :             :          (truncate:M (ashiftrt:O <X> (const_int I))) if M is narrower than
    1637                 :             :          O, and (sign_extend:M (ashiftrt:O <X> (const_int I))) if M is
    1638                 :             :          wider than O.  */
    1639                 :     3346475 :       if (GET_CODE (op) == TRUNCATE
    1640                 :          56 :           && GET_CODE (XEXP (op, 0)) == LSHIFTRT
    1641                 :           0 :           && CONST_INT_P (XEXP (XEXP (op, 0), 1)))
    1642                 :             :         {
    1643                 :           0 :           scalar_int_mode m_mode, n_mode, o_mode;
    1644                 :           0 :           rtx old_shift = XEXP (op, 0);
    1645                 :           0 :           if (is_a <scalar_int_mode> (mode, &m_mode)
    1646                 :           0 :               && is_a <scalar_int_mode> (GET_MODE (op), &n_mode)
    1647                 :           0 :               && is_a <scalar_int_mode> (GET_MODE (old_shift), &o_mode)
    1648                 :           0 :               && GET_MODE_PRECISION (o_mode) - GET_MODE_PRECISION (n_mode)
    1649                 :           0 :                  == INTVAL (XEXP (old_shift, 1)))
    1650                 :             :             {
    1651                 :           0 :               rtx new_shift = simplify_gen_binary (ASHIFTRT,
    1652                 :             :                                                    GET_MODE (old_shift),
    1653                 :             :                                                    XEXP (old_shift, 0),
    1654                 :             :                                                    XEXP (old_shift, 1));
    1655                 :           0 :               if (GET_MODE_PRECISION (m_mode) > GET_MODE_PRECISION (o_mode))
    1656                 :           0 :                 return simplify_gen_unary (SIGN_EXTEND, mode, new_shift,
    1657                 :           0 :                                            GET_MODE (new_shift));
    1658                 :           0 :               if (mode != GET_MODE (new_shift))
    1659                 :           0 :                 return simplify_gen_unary (TRUNCATE, mode, new_shift,
    1660                 :           0 :                                            GET_MODE (new_shift));
    1661                 :             :               return new_shift;
    1662                 :             :             }
    1663                 :             :         }
    1664                 :             : 
    1665                 :             :       /* We can canonicalize SIGN_EXTEND (op) as ZERO_EXTEND (op) when
    1666                 :             :          we know the sign bit of OP must be clear.  */
    1667                 :     3346475 :       if (val_signbit_known_clear_p (GET_MODE (op),
    1668                 :     3346475 :                                      nonzero_bits (op, GET_MODE (op))))
    1669                 :       53398 :         return simplify_gen_unary (ZERO_EXTEND, mode, op, GET_MODE (op));
    1670                 :             : 
    1671                 :             :       /* (sign_extend:DI (subreg:SI (ctz:DI ...))) is (ctz:DI ...).  */
    1672                 :     3293077 :       if (GET_CODE (op) == SUBREG
    1673                 :      273641 :           && subreg_lowpart_p (op)
    1674                 :      273556 :           && GET_MODE (SUBREG_REG (op)) == mode
    1675                 :     3502555 :           && is_a <scalar_int_mode> (mode, &int_mode)
    1676                 :      216220 :           && is_a <scalar_int_mode> (GET_MODE (op), &op_mode)
    1677                 :      216220 :           && GET_MODE_PRECISION (int_mode) <= HOST_BITS_PER_WIDE_INT
    1678                 :      214392 :           && GET_MODE_PRECISION (op_mode) < GET_MODE_PRECISION (int_mode)
    1679                 :     3507469 :           && (nonzero_bits (SUBREG_REG (op), mode)
    1680                 :      214392 :               & ~(GET_MODE_MASK (op_mode) >> 1)) == 0)
    1681                 :        6742 :         return SUBREG_REG (op);
    1682                 :             : 
    1683                 :             : #if defined(POINTERS_EXTEND_UNSIGNED)
    1684                 :             :       /* As we do not know which address space the pointer is referring to,
    1685                 :             :          we can do this only if the target does not support different pointer
    1686                 :             :          or address modes depending on the address space.  */
    1687                 :     3286335 :       if (target_default_pointer_address_modes_p ()
    1688                 :             :           && ! POINTERS_EXTEND_UNSIGNED
    1689                 :             :           && mode == Pmode && GET_MODE (op) == ptr_mode
    1690                 :             :           && (CONSTANT_P (op)
    1691                 :             :               || (GET_CODE (op) == SUBREG
    1692                 :             :                   && REG_P (SUBREG_REG (op))
    1693                 :             :                   && REG_POINTER (SUBREG_REG (op))
    1694                 :             :                   && GET_MODE (SUBREG_REG (op)) == Pmode))
    1695                 :             :           && !targetm.have_ptr_extend ())
    1696                 :             :         {
    1697                 :             :           temp
    1698                 :             :             = convert_memory_address_addr_space_1 (Pmode, op,
    1699                 :             :                                                    ADDR_SPACE_GENERIC, false,
    1700                 :             :                                                    true);
    1701                 :             :           if (temp)
    1702                 :             :             return temp;
    1703                 :             :         }
    1704                 :             : #endif
    1705                 :             :       break;
    1706                 :             : 
    1707                 :    10592825 :     case ZERO_EXTEND:
    1708                 :             :       /* Check for useless extension.  */
    1709                 :    10592825 :       if (GET_MODE (op) == mode)
    1710                 :             :         return op;
    1711                 :             : 
    1712                 :             :       /* Check for a zero extension of a subreg of a promoted
    1713                 :             :          variable, where the promotion is zero-extended, and the
    1714                 :             :          target mode is the same as the variable's promotion.  */
    1715                 :    10592785 :       if (GET_CODE (op) == SUBREG
    1716                 :     1491317 :           && SUBREG_PROMOTED_VAR_P (op)
    1717                 :    10593298 :           && SUBREG_PROMOTED_UNSIGNED_P (op))
    1718                 :             :         {
    1719                 :         513 :           rtx subreg = SUBREG_REG (op);
    1720                 :         513 :           machine_mode subreg_mode = GET_MODE (subreg);
    1721                 :         513 :           if (!paradoxical_subreg_p (mode, subreg_mode))
    1722                 :             :             {
    1723                 :         361 :               temp = rtl_hooks.gen_lowpart_no_emit (mode, subreg);
    1724                 :         361 :               if (temp)
    1725                 :             :                 {
    1726                 :             :                   /* Preserve SUBREG_PROMOTED_VAR_P.  */
    1727                 :         361 :                   if (partial_subreg_p (temp))
    1728                 :             :                     {
    1729                 :         129 :                       SUBREG_PROMOTED_VAR_P (temp) = 1;
    1730                 :         129 :                       SUBREG_PROMOTED_SET (temp, SRP_UNSIGNED);
    1731                 :             :                     }
    1732                 :         361 :                   return temp;
    1733                 :             :                 }
    1734                 :             :             }
    1735                 :             :           else
    1736                 :             :             /* Zero-extending a zero-extended subreg.  */
    1737                 :         152 :             return simplify_gen_unary (ZERO_EXTEND, mode,
    1738                 :         152 :                                        subreg, subreg_mode);
    1739                 :             :         }
    1740                 :             : 
    1741                 :             :       /* Extending a widening multiplication should be canonicalized to
    1742                 :             :          a wider widening multiplication.  */
    1743                 :    10592272 :       if (GET_CODE (op) == MULT)
    1744                 :             :         {
    1745                 :      171893 :           rtx lhs = XEXP (op, 0);
    1746                 :      171893 :           rtx rhs = XEXP (op, 1);
    1747                 :      171893 :           enum rtx_code lcode = GET_CODE (lhs);
    1748                 :      171893 :           enum rtx_code rcode = GET_CODE (rhs);
    1749                 :             : 
    1750                 :             :           /* Widening multiplies usually extend both operands, but sometimes
    1751                 :             :              they use a shift to extract a portion of a register.  */
    1752                 :      171893 :           if ((lcode == ZERO_EXTEND
    1753                 :      171305 :                || (lcode == LSHIFTRT && CONST_INT_P (XEXP (lhs, 1))))
    1754                 :         636 :               && (rcode == ZERO_EXTEND
    1755                 :         572 :                   || (rcode == LSHIFTRT && CONST_INT_P (XEXP (rhs, 1)))))
    1756                 :             :             {
    1757                 :          64 :               machine_mode lmode = GET_MODE (lhs);
    1758                 :          64 :               machine_mode rmode = GET_MODE (rhs);
    1759                 :          64 :               int bits;
    1760                 :             : 
    1761                 :          64 :               if (lcode == LSHIFTRT)
    1762                 :             :                 /* Number of bits not shifted off the end.  */
    1763                 :           0 :                 bits = (GET_MODE_UNIT_PRECISION (lmode)
    1764                 :           0 :                         - INTVAL (XEXP (lhs, 1)));
    1765                 :             :               else /* lcode == ZERO_EXTEND */
    1766                 :             :                 /* Size of inner mode.  */
    1767                 :         128 :                 bits = GET_MODE_UNIT_PRECISION (GET_MODE (XEXP (lhs, 0)));
    1768                 :             : 
    1769                 :          64 :               if (rcode == LSHIFTRT)
    1770                 :           0 :                 bits += (GET_MODE_UNIT_PRECISION (rmode)
    1771                 :           0 :                          - INTVAL (XEXP (rhs, 1)));
    1772                 :             :               else /* rcode == ZERO_EXTEND */
    1773                 :         128 :                 bits += GET_MODE_UNIT_PRECISION (GET_MODE (XEXP (rhs, 0)));
    1774                 :             : 
    1775                 :             :               /* We can only widen multiplies if the result is mathematiclly
    1776                 :             :                  equivalent.  I.e. if overflow was impossible.  */
    1777                 :         128 :               if (bits <= GET_MODE_UNIT_PRECISION (GET_MODE (op)))
    1778                 :          64 :                 return simplify_gen_binary
    1779                 :          64 :                          (MULT, mode,
    1780                 :             :                           simplify_gen_unary (ZERO_EXTEND, mode, lhs, lmode),
    1781                 :          64 :                           simplify_gen_unary (ZERO_EXTEND, mode, rhs, rmode));
    1782                 :             :             }
    1783                 :             :         }
    1784                 :             : 
    1785                 :             :       /* (zero_extend:M (zero_extend:N <X>)) is (zero_extend:M <X>).  */
    1786                 :    10592208 :       if (GET_CODE (op) == ZERO_EXTEND)
    1787                 :       19466 :         return simplify_gen_unary (ZERO_EXTEND, mode, XEXP (op, 0),
    1788                 :       19466 :                                    GET_MODE (XEXP (op, 0)));
    1789                 :             : 
    1790                 :             :       /* (zero_extend:M (lshiftrt:N (ashift <X> (const_int I)) (const_int I)))
    1791                 :             :          is (zero_extend:M (subreg:O <X>)) if there is mode with
    1792                 :             :          GET_MODE_PRECISION (N) - I bits.  */
    1793                 :    10572742 :       if (GET_CODE (op) == LSHIFTRT
    1794                 :       72618 :           && GET_CODE (XEXP (op, 0)) == ASHIFT
    1795                 :    10572765 :           && is_a <scalar_int_mode> (mode, &int_mode)
    1796                 :          23 :           && CONST_INT_P (XEXP (op, 1))
    1797                 :          18 :           && XEXP (XEXP (op, 0), 1) == XEXP (op, 1)
    1798                 :    10572742 :           && (op_mode = as_a <scalar_int_mode> (GET_MODE (op)),
    1799                 :           0 :               GET_MODE_PRECISION (op_mode) > INTVAL (XEXP (op, 1))))
    1800                 :             :         {
    1801                 :           0 :           scalar_int_mode tmode;
    1802                 :           0 :           if (int_mode_for_size (GET_MODE_PRECISION (op_mode)
    1803                 :           0 :                                  - INTVAL (XEXP (op, 1)), 1).exists (&tmode))
    1804                 :             :             {
    1805                 :           0 :               rtx inner =
    1806                 :           0 :                 rtl_hooks.gen_lowpart_no_emit (tmode, XEXP (XEXP (op, 0), 0));
    1807                 :           0 :               if (inner)
    1808                 :           0 :                 return simplify_gen_unary (ZERO_EXTEND, int_mode,
    1809                 :           0 :                                            inner, tmode);
    1810                 :             :             }
    1811                 :             :         }
    1812                 :             : 
    1813                 :             :       /* (zero_extend:M (subreg:N <X:O>)) is <X:O> (for M == O) or
    1814                 :             :          (zero_extend:M <X:O>), if X doesn't have any non-zero bits outside
    1815                 :             :          of mode N.  E.g.
    1816                 :             :          (zero_extend:SI (subreg:QI (and:SI (reg:SI) (const_int 63)) 0)) is
    1817                 :             :          (and:SI (reg:SI) (const_int 63)).  */
    1818                 :    10572742 :       if (partial_subreg_p (op)
    1819                 :    12017121 :           && is_a <scalar_int_mode> (mode, &int_mode)
    1820                 :     1475084 :           && is_a <scalar_int_mode> (GET_MODE (SUBREG_REG (op)), &op0_mode)
    1821                 :     1473746 :           && GET_MODE_PRECISION (op0_mode) <= HOST_BITS_PER_WIDE_INT
    1822                 :     1112514 :           && GET_MODE_PRECISION (int_mode) >= GET_MODE_PRECISION (op0_mode)
    1823                 :     1051848 :           && subreg_lowpart_p (op)
    1824                 :    11324497 :           && (nonzero_bits (SUBREG_REG (op), op0_mode)
    1825                 :      751755 :               & ~GET_MODE_MASK (GET_MODE (op))) == 0)
    1826                 :             :         {
    1827                 :       30705 :           if (GET_MODE_PRECISION (int_mode) == GET_MODE_PRECISION (op0_mode))
    1828                 :       22437 :             return SUBREG_REG (op);
    1829                 :        8268 :           return simplify_gen_unary (ZERO_EXTEND, int_mode, SUBREG_REG (op),
    1830                 :        8268 :                                      op0_mode);
    1831                 :             :         }
    1832                 :             : 
    1833                 :             :       /* (zero_extend:DI (subreg:SI (ctz:DI ...))) is (ctz:DI ...).  */
    1834                 :    10542037 :       if (GET_CODE (op) == SUBREG
    1835                 :     1460099 :           && subreg_lowpart_p (op)
    1836                 :      869614 :           && GET_MODE (SUBREG_REG (op)) == mode
    1837                 :    11265204 :           && is_a <scalar_int_mode> (mode, &int_mode)
    1838                 :      723167 :           && is_a <scalar_int_mode> (GET_MODE (op), &op_mode)
    1839                 :      723167 :           && GET_MODE_PRECISION (int_mode) <= HOST_BITS_PER_WIDE_INT
    1840                 :      653073 :           && GET_MODE_PRECISION (op_mode) < GET_MODE_PRECISION (int_mode)
    1841                 :    11195110 :           && (nonzero_bits (SUBREG_REG (op), mode)
    1842                 :      653073 :               & ~GET_MODE_MASK (op_mode)) == 0)
    1843                 :           0 :         return SUBREG_REG (op);
    1844                 :             : 
    1845                 :             :       /* Trying to optimize:
    1846                 :             :          (zero_extend:M (subreg:N (not:M (X:M)))) ->
    1847                 :             :          (xor:M (zero_extend:M (subreg:N (X:M)), mask))
    1848                 :             :          where the mask is GET_MODE_MASK (N).
    1849                 :             :          For the cases when X:M doesn't have any non-zero bits
    1850                 :             :          outside of mode N, (zero_extend:M (subreg:N (X:M))
    1851                 :             :          will be simplified to just (X:M)
    1852                 :             :          and whole optimization will be -> (xor:M (X:M, mask)).  */
    1853                 :    10542037 :       if (partial_subreg_p (op)
    1854                 :     1444379 :           && GET_CODE (XEXP (op, 0)) == NOT
    1855                 :         639 :           && GET_MODE (XEXP (op, 0)) == mode
    1856                 :         636 :           && subreg_lowpart_p (op)
    1857                 :    10542317 :           && HWI_COMPUTABLE_MODE_P (mode)
    1858                 :         283 :           && is_a <scalar_int_mode> (GET_MODE (op), &op_mode)
    1859                 :    10542320 :           && (nonzero_bits (XEXP (XEXP (op, 0), 0), mode)
    1860                 :         283 :               & ~GET_MODE_MASK (op_mode)) == 0)
    1861                 :             :       {
    1862                 :           3 :         unsigned HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
    1863                 :           6 :         return simplify_gen_binary (XOR, mode,
    1864                 :           3 :                                     XEXP (XEXP (op, 0), 0),
    1865                 :           3 :                                     gen_int_mode (mask, mode));
    1866                 :             :       }
    1867                 :             : 
    1868                 :             : #if defined(POINTERS_EXTEND_UNSIGNED)
    1869                 :             :       /* As we do not know which address space the pointer is referring to,
    1870                 :             :          we can do this only if the target does not support different pointer
    1871                 :             :          or address modes depending on the address space.  */
    1872                 :    10542034 :       if (target_default_pointer_address_modes_p ()
    1873                 :             :           && POINTERS_EXTEND_UNSIGNED > 0
    1874                 :    10542034 :           && mode == Pmode && GET_MODE (op) == ptr_mode
    1875                 :         697 :           && (CONSTANT_P (op)
    1876                 :         672 :               || (GET_CODE (op) == SUBREG
    1877                 :           0 :                   && REG_P (SUBREG_REG (op))
    1878                 :           0 :                   && REG_POINTER (SUBREG_REG (op))
    1879                 :           0 :                   && GET_MODE (SUBREG_REG (op)) == Pmode))
    1880                 :    10542059 :           && !targetm.have_ptr_extend ())
    1881                 :             :         {
    1882                 :          25 :           temp
    1883                 :          25 :             = convert_memory_address_addr_space_1 (Pmode, op,
    1884                 :             :                                                    ADDR_SPACE_GENERIC, false,
    1885                 :             :                                                    true);
    1886                 :          25 :           if (temp)
    1887                 :             :             return temp;
    1888                 :             :         }
    1889                 :             : #endif
    1890                 :             :       break;
    1891                 :             : 
    1892                 :             :     default:
    1893                 :             :       break;
    1894                 :             :     }
    1895                 :             : 
    1896                 :    18203098 :   if (VECTOR_MODE_P (mode)
    1897                 :     1497690 :       && vec_duplicate_p (op, &elt)
    1898                 :    19706243 :       && code != VEC_DUPLICATE)
    1899                 :             :     {
    1900                 :        5451 :       if (code == SIGN_EXTEND || code == ZERO_EXTEND)
    1901                 :             :         /* Enforce a canonical order of VEC_DUPLICATE wrt other unary
    1902                 :             :            operations by promoting VEC_DUPLICATE to the root of the expression
    1903                 :             :            (as far as possible).  */
    1904                 :        4369 :         temp = simplify_gen_unary (code, GET_MODE_INNER (mode),
    1905                 :        8738 :                                    elt, GET_MODE_INNER (GET_MODE (op)));
    1906                 :             :       else
    1907                 :             :         /* Try applying the operator to ELT and see if that simplifies.
    1908                 :             :            We can duplicate the result if so.
    1909                 :             : 
    1910                 :             :            The reason we traditionally haven't used simplify_gen_unary
    1911                 :             :            for these codes is that it didn't necessarily seem to be a
    1912                 :             :            win to convert things like:
    1913                 :             : 
    1914                 :             :              (neg:V (vec_duplicate:V (reg:S R)))
    1915                 :             : 
    1916                 :             :            to:
    1917                 :             : 
    1918                 :             :              (vec_duplicate:V (neg:S (reg:S R)))
    1919                 :             : 
    1920                 :             :            The first might be done entirely in vector registers while the
    1921                 :             :            second might need a move between register files.
    1922                 :             : 
    1923                 :             :            However, there also cases where promoting the vec_duplicate is
    1924                 :             :            more efficient, and there is definite value in having a canonical
    1925                 :             :            form when matching instruction patterns.  We should consider
    1926                 :             :            extending the simplify_gen_unary code above to more cases.  */
    1927                 :        1082 :         temp = simplify_unary_operation (code, GET_MODE_INNER (mode),
    1928                 :        2164 :                                          elt, GET_MODE_INNER (GET_MODE (op)));
    1929                 :        5451 :       if (temp)
    1930                 :        4953 :         return gen_vec_duplicate (mode, temp);
    1931                 :             :     }
    1932                 :             : 
    1933                 :             :   return 0;
    1934                 :             : }
    1935                 :             : 
    1936                 :             : /* Try to compute the value of a unary operation CODE whose output mode is to
    1937                 :             :    be MODE with input operand OP whose mode was originally OP_MODE.
    1938                 :             :    Return zero if the value cannot be computed.  */
    1939                 :             : rtx
    1940                 :    26437557 : simplify_const_unary_operation (enum rtx_code code, machine_mode mode,
    1941                 :             :                                 rtx op, machine_mode op_mode)
    1942                 :             : {
    1943                 :    26437557 :   scalar_int_mode result_mode;
    1944                 :             : 
    1945                 :    26437557 :   if (code == VEC_DUPLICATE)
    1946                 :             :     {
    1947                 :     1677426 :       gcc_assert (VECTOR_MODE_P (mode));
    1948                 :     1677426 :       if (GET_MODE (op) != VOIDmode)
    1949                 :             :       {
    1950                 :      590248 :         if (!VECTOR_MODE_P (GET_MODE (op)))
    1951                 :     1167278 :           gcc_assert (GET_MODE_INNER (mode) == GET_MODE (op));
    1952                 :             :         else
    1953                 :       19827 :           gcc_assert (GET_MODE_INNER (mode) == GET_MODE_INNER
    1954                 :             :                                                 (GET_MODE (op)));
    1955                 :             :       }
    1956                 :     1677426 :       if (CONST_SCALAR_INT_P (op) || CONST_DOUBLE_AS_FLOAT_P (op))
    1957                 :     1121198 :         return gen_const_vec_duplicate (mode, op);
    1958                 :      556228 :       if (GET_CODE (op) == CONST_VECTOR
    1959                 :      556228 :           && (CONST_VECTOR_DUPLICATE_P (op)
    1960                 :             :               || CONST_VECTOR_NUNITS (op).is_constant ()))
    1961                 :             :         {
    1962                 :         739 :           unsigned int npatterns = (CONST_VECTOR_DUPLICATE_P (op)
    1963                 :         739 :                                     ? CONST_VECTOR_NPATTERNS (op)
    1964                 :        1476 :                                     : CONST_VECTOR_NUNITS (op).to_constant ());
    1965                 :        2217 :           gcc_assert (multiple_p (GET_MODE_NUNITS (mode), npatterns));
    1966                 :         739 :           rtx_vector_builder builder (mode, npatterns, 1);
    1967                 :        3050 :           for (unsigned i = 0; i < npatterns; i++)
    1968                 :        2311 :             builder.quick_push (CONST_VECTOR_ELT (op, i));
    1969                 :         739 :           return builder.build ();
    1970                 :         739 :         }
    1971                 :             :     }
    1972                 :             : 
    1973                 :    24090335 :   if (VECTOR_MODE_P (mode)
    1974                 :     1554243 :       && GET_CODE (op) == CONST_VECTOR
    1975                 :    25468563 :       && known_eq (GET_MODE_NUNITS (mode), CONST_VECTOR_NUNITS (op)))
    1976                 :             :     {
    1977                 :       50981 :       gcc_assert (GET_MODE (op) == op_mode);
    1978                 :             : 
    1979                 :       50981 :       rtx_vector_builder builder;
    1980                 :       50981 :       if (!builder.new_unary_operation (mode, op, false))
    1981                 :             :         return 0;
    1982                 :             : 
    1983                 :       50981 :       unsigned int count = builder.encoded_nelts ();
    1984                 :      194396 :       for (unsigned int i = 0; i < count; i++)
    1985                 :             :         {
    1986                 :      288032 :           rtx x = simplify_unary_operation (code, GET_MODE_INNER (mode),
    1987                 :             :                                             CONST_VECTOR_ELT (op, i),
    1988                 :      288032 :                                             GET_MODE_INNER (op_mode));
    1989                 :      144016 :           if (!x || !valid_for_const_vector_p (mode, x))
    1990                 :         601 :             return 0;
    1991                 :      143415 :           builder.quick_push (x);
    1992                 :             :         }
    1993                 :       50380 :       return builder.build ();
    1994                 :       50981 :     }
    1995                 :             : 
    1996                 :             :   /* The order of these tests is critical so that, for example, we don't
    1997                 :             :      check the wrong mode (input vs. output) for a conversion operation,
    1998                 :             :      such as FIX.  At some point, this should be simplified.  */
    1999                 :             : 
    2000                 :    25264639 :   if (code == FLOAT && CONST_SCALAR_INT_P (op))
    2001                 :             :     {
    2002                 :        7074 :       REAL_VALUE_TYPE d;
    2003                 :             : 
    2004                 :        7074 :       if (op_mode == VOIDmode)
    2005                 :             :         {
    2006                 :             :           /* CONST_INT have VOIDmode as the mode.  We assume that all
    2007                 :             :              the bits of the constant are significant, though, this is
    2008                 :             :              a dangerous assumption as many times CONST_INTs are
    2009                 :             :              created and used with garbage in the bits outside of the
    2010                 :             :              precision of the implied mode of the const_int.  */
    2011                 :          63 :           op_mode = MAX_MODE_INT;
    2012                 :             :         }
    2013                 :             : 
    2014                 :        7074 :       real_from_integer (&d, mode, rtx_mode_t (op, op_mode), SIGNED);
    2015                 :             : 
    2016                 :             :       /* Avoid the folding if flag_signaling_nans is on and
    2017                 :             :          operand is a signaling NaN.  */
    2018                 :        7074 :       if (HONOR_SNANS (mode) && REAL_VALUE_ISSIGNALING_NAN (d))
    2019                 :             :         return 0;
    2020                 :             : 
    2021                 :        7074 :       d = real_value_truncate (mode, d);
    2022                 :             : 
    2023                 :             :       /* Avoid the folding if flag_rounding_math is on and the
    2024                 :             :          conversion is not exact.  */
    2025                 :        7074 :       if (HONOR_SIGN_DEPENDENT_ROUNDING (mode))
    2026                 :             :         {
    2027                 :        1004 :           bool fail = false;
    2028                 :        1004 :           wide_int w = real_to_integer (&d, &fail,
    2029                 :             :                                         GET_MODE_PRECISION
    2030                 :        1004 :                                           (as_a <scalar_int_mode> (op_mode)));
    2031                 :        2008 :           if (fail || wi::ne_p (w, wide_int (rtx_mode_t (op, op_mode))))
    2032                 :         898 :             return 0;
    2033                 :        1004 :         }
    2034                 :             : 
    2035                 :        6176 :       return const_double_from_real_value (d, mode);
    2036                 :             :     }
    2037                 :    25257565 :   else if (code == UNSIGNED_FLOAT && CONST_SCALAR_INT_P (op))
    2038                 :             :     {
    2039                 :        2059 :       REAL_VALUE_TYPE d;
    2040                 :             : 
    2041                 :        2059 :       if (op_mode == VOIDmode)
    2042                 :             :         {
    2043                 :             :           /* CONST_INT have VOIDmode as the mode.  We assume that all
    2044                 :             :              the bits of the constant are significant, though, this is
    2045                 :             :              a dangerous assumption as many times CONST_INTs are
    2046                 :             :              created and used with garbage in the bits outside of the
    2047                 :             :              precision of the implied mode of the const_int.  */
    2048                 :           8 :           op_mode = MAX_MODE_INT;
    2049                 :             :         }
    2050                 :             : 
    2051                 :        2059 :       real_from_integer (&d, mode, rtx_mode_t (op, op_mode), UNSIGNED);
    2052                 :             : 
    2053                 :             :       /* Avoid the folding if flag_signaling_nans is on and
    2054                 :             :          operand is a signaling NaN.  */
    2055                 :        2059 :       if (HONOR_SNANS (mode) && REAL_VALUE_ISSIGNALING_NAN (d))
    2056                 :             :         return 0;
    2057                 :             : 
    2058                 :        2059 :       d = real_value_truncate (mode, d);
    2059                 :             : 
    2060                 :             :       /* Avoid the folding if flag_rounding_math is on and the
    2061                 :             :          conversion is not exact.  */
    2062                 :        2059 :       if (HONOR_SIGN_DEPENDENT_ROUNDING (mode))
    2063                 :             :         {
    2064                 :          16 :           bool fail = false;
    2065                 :          16 :           wide_int w = real_to_integer (&d, &fail,
    2066                 :             :                                         GET_MODE_PRECISION
    2067                 :          16 :                                           (as_a <scalar_int_mode> (op_mode)));
    2068                 :          28 :           if (fail || wi::ne_p (w, wide_int (rtx_mode_t (op, op_mode))))
    2069                 :          16 :             return 0;
    2070                 :          16 :         }
    2071                 :             : 
    2072                 :        2043 :       return const_double_from_real_value (d, mode);
    2073                 :             :     }
    2074                 :             : 
    2075                 :    25255506 :   if (CONST_SCALAR_INT_P (op) && is_a <scalar_int_mode> (mode, &result_mode))
    2076                 :             :     {
    2077                 :     3204229 :       unsigned int width = GET_MODE_PRECISION (result_mode);
    2078                 :     3204229 :       if (width > MAX_BITSIZE_MODE_ANY_INT)
    2079                 :             :         return 0;
    2080                 :             : 
    2081                 :     3204229 :       wide_int result;
    2082                 :     3204229 :       scalar_int_mode imode = (op_mode == VOIDmode
    2083                 :     3204229 :                                ? result_mode
    2084                 :     3201065 :                                : as_a <scalar_int_mode> (op_mode));
    2085                 :     3204229 :       rtx_mode_t op0 = rtx_mode_t (op, imode);
    2086                 :     3204229 :       int int_value;
    2087                 :             : 
    2088                 :             : #if TARGET_SUPPORTS_WIDE_INT == 0
    2089                 :             :       /* This assert keeps the simplification from producing a result
    2090                 :             :          that cannot be represented in a CONST_DOUBLE but a lot of
    2091                 :             :          upstream callers expect that this function never fails to
    2092                 :             :          simplify something and so you if you added this to the test
    2093                 :             :          above the code would die later anyway.  If this assert
    2094                 :             :          happens, you just need to make the port support wide int.  */
    2095                 :             :       gcc_assert (width <= HOST_BITS_PER_DOUBLE_INT);
    2096                 :             : #endif
    2097                 :             : 
    2098                 :     3204229 :       switch (code)
    2099                 :             :         {
    2100                 :      167409 :         case NOT:
    2101                 :      167409 :           result = wi::bit_not (op0);
    2102                 :      167409 :           break;
    2103                 :             : 
    2104                 :     1854856 :         case NEG:
    2105                 :     1854856 :           result = wi::neg (op0);
    2106                 :     1854856 :           break;
    2107                 :             : 
    2108                 :        6637 :         case ABS:
    2109                 :        6637 :           result = wi::abs (op0);
    2110                 :        6637 :           break;
    2111                 :             : 
    2112                 :           0 :         case FFS:
    2113                 :           0 :           result = wi::shwi (wi::ffs (op0), result_mode);
    2114                 :           0 :           break;
    2115                 :             : 
    2116                 :         198 :         case CLZ:
    2117                 :         198 :           if (wi::ne_p (op0, 0))
    2118                 :          20 :             int_value = wi::clz (op0);
    2119                 :         356 :           else if (! CLZ_DEFINED_VALUE_AT_ZERO (imode, int_value))
    2120                 :             :             return NULL_RTX;
    2121                 :          20 :           result = wi::shwi (int_value, result_mode);
    2122                 :          20 :           break;
    2123                 :             : 
    2124                 :           0 :         case CLRSB:
    2125                 :           0 :           result = wi::shwi (wi::clrsb (op0), result_mode);
    2126                 :           0 :           break;
    2127                 :             : 
    2128                 :           0 :         case CTZ:
    2129                 :           0 :           if (wi::ne_p (op0, 0))
    2130                 :           0 :             int_value = wi::ctz (op0);
    2131                 :           0 :           else if (! CTZ_DEFINED_VALUE_AT_ZERO (imode, int_value))
    2132                 :             :             return NULL_RTX;
    2133                 :           0 :           result = wi::shwi (int_value, result_mode);
    2134                 :           0 :           break;
    2135                 :             : 
    2136                 :         160 :         case POPCOUNT:
    2137                 :         160 :           result = wi::shwi (wi::popcount (op0), result_mode);
    2138                 :         160 :           break;
    2139                 :             : 
    2140                 :           0 :         case PARITY:
    2141                 :           0 :           result = wi::shwi (wi::parity (op0), result_mode);
    2142                 :           0 :           break;
    2143                 :             : 
    2144                 :        1980 :         case BSWAP:
    2145                 :        1980 :           result = wi::bswap (op0);
    2146                 :        1980 :           break;
    2147                 :             : 
    2148                 :           0 :         case BITREVERSE:
    2149                 :           0 :           result = wi::bitreverse (op0);
    2150                 :           0 :           break;
    2151                 :             : 
    2152                 :     1010643 :         case TRUNCATE:
    2153                 :     1010643 :         case ZERO_EXTEND:
    2154                 :     1010643 :           result = wide_int::from (op0, width, UNSIGNED);
    2155                 :     1010643 :           break;
    2156                 :             : 
    2157                 :       13328 :         case US_TRUNCATE:
    2158                 :       13328 :         case SS_TRUNCATE:
    2159                 :       13328 :           {
    2160                 :       13328 :             signop sgn = code == US_TRUNCATE ? UNSIGNED : SIGNED;
    2161                 :       13328 :             wide_int nmax
    2162                 :       13328 :               = wide_int::from (wi::max_value (width, sgn),
    2163                 :       26656 :                                 GET_MODE_PRECISION (imode), sgn);
    2164                 :       13328 :             wide_int nmin
    2165                 :       13328 :               = wide_int::from (wi::min_value (width, sgn),
    2166                 :       26656 :                                 GET_MODE_PRECISION (imode), sgn);
    2167                 :       13328 :             result = wi::min (wi::max (op0, nmin, sgn), nmax, sgn);
    2168                 :       13328 :             result = wide_int::from (result, width, sgn);
    2169                 :       13328 :             break;
    2170                 :       13328 :           }
    2171                 :      149018 :         case SIGN_EXTEND:
    2172                 :      149018 :           result = wide_int::from (op0, width, SIGNED);
    2173                 :      149018 :           break;
    2174                 :             : 
    2175                 :           0 :         case SS_NEG:
    2176                 :           0 :           if (wi::only_sign_bit_p (op0))
    2177                 :           0 :             result = wi::max_value (GET_MODE_PRECISION (imode), SIGNED);
    2178                 :             :           else
    2179                 :           0 :             result = wi::neg (op0);
    2180                 :             :           break;
    2181                 :             : 
    2182                 :           0 :         case SS_ABS:
    2183                 :           0 :           if (wi::only_sign_bit_p (op0))
    2184                 :           0 :             result = wi::max_value (GET_MODE_PRECISION (imode), SIGNED);
    2185                 :             :           else
    2186                 :           0 :             result = wi::abs (op0);
    2187                 :             :           break;
    2188                 :             : 
    2189                 :             :         case SQRT:
    2190                 :             :         default:
    2191                 :             :           return 0;
    2192                 :             :         }
    2193                 :             : 
    2194                 :     3204051 :       return immed_wide_int_const (result, result_mode);
    2195                 :     3204229 :     }
    2196                 :             : 
    2197                 :    22051277 :   else if (CONST_DOUBLE_AS_FLOAT_P (op)
    2198                 :      483205 :            && SCALAR_FLOAT_MODE_P (mode)
    2199                 :      481203 :            && SCALAR_FLOAT_MODE_P (GET_MODE (op)))
    2200                 :             :     {
    2201                 :      481203 :       REAL_VALUE_TYPE d = *CONST_DOUBLE_REAL_VALUE (op);
    2202                 :      481203 :       switch (code)
    2203                 :             :         {
    2204                 :             :         case SQRT:
    2205                 :             :           return 0;
    2206                 :       23077 :         case ABS:
    2207                 :       23077 :           d = real_value_abs (&d);
    2208                 :       23077 :           break;
    2209                 :       15727 :         case NEG:
    2210                 :       15727 :           d = real_value_negate (&d);
    2211                 :       15727 :           break;
    2212                 :         923 :         case FLOAT_TRUNCATE:
    2213                 :             :           /* Don't perform the operation if flag_signaling_nans is on
    2214                 :             :              and the operand is a signaling NaN.  */
    2215                 :         923 :           if (HONOR_SNANS (mode) && REAL_VALUE_ISSIGNALING_NAN (d))
    2216                 :             :             return NULL_RTX;
    2217                 :             :           /* Or if flag_rounding_math is on and the truncation is not
    2218                 :             :              exact.  */
    2219                 :         923 :           if (HONOR_SIGN_DEPENDENT_ROUNDING (mode)
    2220                 :         923 :               && !exact_real_truncate (mode, &d))
    2221                 :         231 :             return NULL_RTX;
    2222                 :         692 :           d = real_value_truncate (mode, d);
    2223                 :         692 :           break;
    2224                 :      393372 :         case FLOAT_EXTEND:
    2225                 :             :           /* Don't perform the operation if flag_signaling_nans is on
    2226                 :             :              and the operand is a signaling NaN.  */
    2227                 :      393372 :           if (HONOR_SNANS (mode) && REAL_VALUE_ISSIGNALING_NAN (d))
    2228                 :             :             return NULL_RTX;
    2229                 :             :           /* All this does is change the mode, unless changing
    2230                 :             :              mode class.  */
    2231                 :      393370 :           if (GET_MODE_CLASS (mode) != GET_MODE_CLASS (GET_MODE (op)))
    2232                 :           0 :             real_convert (&d, mode, &d);
    2233                 :             :           break;
    2234                 :           0 :         case FIX:
    2235                 :             :           /* Don't perform the operation if flag_signaling_nans is on
    2236                 :             :              and the operand is a signaling NaN.  */
    2237                 :           0 :           if (HONOR_SNANS (mode) && REAL_VALUE_ISSIGNALING_NAN (d))
    2238                 :             :             return NULL_RTX;
    2239                 :           0 :           real_arithmetic (&d, FIX_TRUNC_EXPR, &d, NULL);
    2240                 :           0 :           break;
    2241                 :       47420 :         case NOT:
    2242                 :       47420 :           {
    2243                 :       47420 :             long tmp[4];
    2244                 :       47420 :             int i;
    2245                 :             : 
    2246                 :       47420 :             real_to_target (tmp, &d, GET_MODE (op));
    2247                 :      237100 :             for (i = 0; i < 4; i++)
    2248                 :      189680 :               tmp[i] = ~tmp[i];
    2249                 :       47420 :             real_from_target (&d, tmp, mode);
    2250                 :       47420 :             break;
    2251                 :             :           }
    2252                 :           0 :         default:
    2253                 :           0 :           gcc_unreachable ();
    2254                 :             :         }
    2255                 :      480286 :       return const_double_from_real_value (d, mode);
    2256                 :             :     }
    2257                 :        2002 :   else if (CONST_DOUBLE_AS_FLOAT_P (op)
    2258                 :        2002 :            && SCALAR_FLOAT_MODE_P (GET_MODE (op))
    2259                 :    21572076 :            && is_int_mode (mode, &result_mode))
    2260                 :             :     {
    2261                 :        2002 :       unsigned int width = GET_MODE_PRECISION (result_mode);
    2262                 :        2002 :       if (width > MAX_BITSIZE_MODE_ANY_INT)
    2263                 :             :         return 0;
    2264                 :             : 
    2265                 :             :       /* Although the overflow semantics of RTL's FIX and UNSIGNED_FIX
    2266                 :             :          operators are intentionally left unspecified (to ease implementation
    2267                 :             :          by target backends), for consistency, this routine implements the
    2268                 :             :          same semantics for constant folding as used by the middle-end.  */
    2269                 :             : 
    2270                 :             :       /* This was formerly used only for non-IEEE float.
    2271                 :             :          eggert@twinsun.com says it is safe for IEEE also.  */
    2272                 :        2002 :       REAL_VALUE_TYPE t;
    2273                 :        2002 :       const REAL_VALUE_TYPE *x = CONST_DOUBLE_REAL_VALUE (op);
    2274                 :        2002 :       wide_int wmax, wmin;
    2275                 :             :       /* This is part of the abi to real_to_integer, but we check
    2276                 :             :          things before making this call.  */
    2277                 :        2002 :       bool fail;
    2278                 :             : 
    2279                 :        2002 :       switch (code)
    2280                 :             :         {
    2281                 :        1994 :         case FIX:
    2282                 :             :           /* According to IEEE standard, for conversions from floating point to
    2283                 :             :              integer. When a NaN or infinite operand cannot be represented in
    2284                 :             :              the destination format and this cannot otherwise be indicated, the
    2285                 :             :              invalid operation exception shall be signaled. When a numeric
    2286                 :             :              operand would convert to an integer outside the range of the
    2287                 :             :              destination format, the invalid operation exception shall be
    2288                 :             :              signaled if this situation cannot otherwise be indicated.  */
    2289                 :        1994 :           if (REAL_VALUE_ISNAN (*x))
    2290                 :         941 :             return flag_trapping_math ? NULL_RTX : const0_rtx;
    2291                 :             : 
    2292                 :        1053 :           if (REAL_VALUE_ISINF (*x) && flag_trapping_math)
    2293                 :             :             return NULL_RTX;
    2294                 :             : 
    2295                 :             :           /* Test against the signed upper bound.  */
    2296                 :         106 :           wmax = wi::max_value (width, SIGNED);
    2297                 :         106 :           real_from_integer (&t, VOIDmode, wmax, SIGNED);
    2298                 :         106 :           if (real_less (&t, x))
    2299                 :           3 :             return (flag_trapping_math
    2300                 :           3 :                     ? NULL_RTX : immed_wide_int_const (wmax, mode));
    2301                 :             : 
    2302                 :             :           /* Test against the signed lower bound.  */
    2303                 :         103 :           wmin = wi::min_value (width, SIGNED);
    2304                 :         103 :           real_from_integer (&t, VOIDmode, wmin, SIGNED);
    2305                 :         103 :           if (real_less (x, &t))
    2306                 :           8 :             return immed_wide_int_const (wmin, mode);
    2307                 :             : 
    2308                 :          95 :           return immed_wide_int_const (real_to_integer (x, &fail, width),
    2309                 :             :                                        mode);
    2310                 :             : 
    2311                 :           8 :         case UNSIGNED_FIX:
    2312                 :           8 :           if (REAL_VALUE_ISNAN (*x) || REAL_VALUE_NEGATIVE (*x))
    2313                 :           6 :             return flag_trapping_math ? NULL_RTX : const0_rtx;
    2314                 :             : 
    2315                 :           2 :           if (REAL_VALUE_ISINF (*x) && flag_trapping_math)
    2316                 :             :             return NULL_RTX;
    2317                 :             : 
    2318                 :             :           /* Test against the unsigned upper bound.  */
    2319                 :           0 :           wmax = wi::max_value (width, UNSIGNED);
    2320                 :           0 :           real_from_integer (&t, VOIDmode, wmax, UNSIGNED);
    2321                 :           0 :           if (real_less (&t, x))
    2322                 :           0 :             return (flag_trapping_math
    2323                 :           0 :                     ? NULL_RTX : immed_wide_int_const (wmax, mode));
    2324                 :             : 
    2325                 :           0 :           return immed_wide_int_const (real_to_integer (x, &fail, width),
    2326                 :             :                                        mode);
    2327                 :             : 
    2328                 :           0 :         default:
    2329                 :           0 :           gcc_unreachable ();
    2330                 :             :         }
    2331                 :        2002 :     }
    2332                 :             : 
    2333                 :             :   /* Handle polynomial integers.  */
    2334                 :             :   else if (CONST_POLY_INT_P (op))
    2335                 :             :     {
    2336                 :             :       poly_wide_int result;
    2337                 :             :       switch (code)
    2338                 :             :         {
    2339                 :             :         case NEG:
    2340                 :             :           result = -const_poly_int_value (op);
    2341                 :             :           break;
    2342                 :             : 
    2343                 :             :         case NOT:
    2344                 :             :           result = ~const_poly_int_value (op);
    2345                 :             :           break;
    2346                 :             : 
    2347                 :             :         default:
    2348                 :             :           return NULL_RTX;
    2349                 :             :         }
    2350                 :             :       return immed_wide_int_const (result, mode);
    2351                 :             :     }
    2352                 :             : 
    2353                 :             :   return NULL_RTX;
    2354                 :             : }
    2355                 :             : 
    2356                 :             : /* Subroutine of simplify_binary_operation to simplify a binary operation
    2357                 :             :    CODE that can commute with byte swapping, with result mode MODE and
    2358                 :             :    operating on OP0 and OP1.  CODE is currently one of AND, IOR or XOR.
    2359                 :             :    Return zero if no simplification or canonicalization is possible.  */
    2360                 :             : 
    2361                 :             : rtx
    2362                 :    35461597 : simplify_context::simplify_byte_swapping_operation (rtx_code code,
    2363                 :             :                                                     machine_mode mode,
    2364                 :             :                                                     rtx op0, rtx op1)
    2365                 :             : {
    2366                 :    35461597 :   rtx tem;
    2367                 :             : 
    2368                 :             :   /* (op (bswap x) C1)) -> (bswap (op x C2)) with C2 swapped.  */
    2369                 :    35461597 :   if (GET_CODE (op0) == BSWAP && CONST_SCALAR_INT_P (op1))
    2370                 :             :     {
    2371                 :         513 :       tem = simplify_gen_binary (code, mode, XEXP (op0, 0),
    2372                 :             :                                  simplify_gen_unary (BSWAP, mode, op1, mode));
    2373                 :         513 :       return simplify_gen_unary (BSWAP, mode, tem, mode);
    2374                 :             :     }
    2375                 :             : 
    2376                 :             :   /* (op (bswap x) (bswap y)) -> (bswap (op x y)).  */
    2377                 :    35461084 :   if (GET_CODE (op0) == BSWAP && GET_CODE (op1) == BSWAP)
    2378                 :             :     {
    2379                 :           0 :       tem = simplify_gen_binary (code, mode, XEXP (op0, 0), XEXP (op1, 0));
    2380                 :           0 :       return simplify_gen_unary (BSWAP, mode, tem, mode);
    2381                 :             :     }
    2382                 :             : 
    2383                 :             :   return NULL_RTX;
    2384                 :             : }
    2385                 :             : 
    2386                 :             : /* Subroutine of simplify_binary_operation to simplify a commutative,
    2387                 :             :    associative binary operation CODE with result mode MODE, operating
    2388                 :             :    on OP0 and OP1.  CODE is currently one of PLUS, MULT, AND, IOR, XOR,
    2389                 :             :    SMIN, SMAX, UMIN or UMAX.  Return zero if no simplification or
    2390                 :             :    canonicalization is possible.  */
    2391                 :             : 
    2392                 :             : rtx
    2393                 :    45061689 : simplify_context::simplify_associative_operation (rtx_code code,
    2394                 :             :                                                   machine_mode mode,
    2395                 :             :                                                   rtx op0, rtx op1)
    2396                 :             : {
    2397                 :    45061689 :   rtx tem;
    2398                 :             : 
    2399                 :             :   /* Normally expressions simplified by simplify-rtx.cc are combined
    2400                 :             :      at most from a few machine instructions and therefore the
    2401                 :             :      expressions should be fairly small.  During var-tracking
    2402                 :             :      we can see arbitrarily large expressions though and reassociating
    2403                 :             :      those can be quadratic, so punt after encountering max_assoc_count
    2404                 :             :      simplify_associative_operation calls during outermost simplify_*
    2405                 :             :      call.  */
    2406                 :    45061689 :   if (++assoc_count >= max_assoc_count)
    2407                 :             :     return NULL_RTX;
    2408                 :             : 
    2409                 :             :   /* Linearize the operator to the left.  */
    2410                 :    45061075 :   if (GET_CODE (op1) == code)
    2411                 :             :     {
    2412                 :             :       /* "(a op b) op (c op d)" becomes "((a op b) op c) op d)".  */
    2413                 :       16530 :       if (GET_CODE (op0) == code)
    2414                 :             :         {
    2415                 :        4673 :           tem = simplify_gen_binary (code, mode, op0, XEXP (op1, 0));
    2416                 :        4673 :           return simplify_gen_binary (code, mode, tem, XEXP (op1, 1));
    2417                 :             :         }
    2418                 :             : 
    2419                 :             :       /* "a op (b op c)" becomes "(b op c) op a".  */
    2420                 :       11857 :       if (! swap_commutative_operands_p (op1, op0))
    2421                 :       11857 :         return simplify_gen_binary (code, mode, op1, op0);
    2422                 :             : 
    2423                 :             :       std::swap (op0, op1);
    2424                 :             :     }
    2425                 :             : 
    2426                 :    45044545 :   if (GET_CODE (op0) == code)
    2427                 :             :     {
    2428                 :             :       /* Canonicalize "(x op c) op y" as "(x op y) op c".  */
    2429                 :     1261062 :       if (swap_commutative_operands_p (XEXP (op0, 1), op1))
    2430                 :             :         {
    2431                 :      230521 :           tem = simplify_gen_binary (code, mode, XEXP (op0, 0), op1);
    2432                 :      230521 :           return simplify_gen_binary (code, mode, tem, XEXP (op0, 1));
    2433                 :             :         }
    2434                 :             : 
    2435                 :             :       /* Attempt to simplify "(a op b) op c" as "a op (b op c)".  */
    2436                 :     1030541 :       tem = simplify_binary_operation (code, mode, XEXP (op0, 1), op1);
    2437                 :     1030541 :       if (tem != 0)
    2438                 :       88496 :         return simplify_gen_binary (code, mode, XEXP (op0, 0), tem);
    2439                 :             : 
    2440                 :             :       /* Attempt to simplify "(a op b) op c" as "(a op c) op b".  */
    2441                 :      942045 :       tem = simplify_binary_operation (code, mode, XEXP (op0, 0), op1);
    2442                 :      942045 :       if (tem != 0)
    2443                 :        2593 :         return simplify_gen_binary (code, mode, tem, XEXP (op0, 1));
    2444                 :             :     }
    2445                 :             : 
    2446                 :             :   return 0;
    2447                 :             : }
    2448                 :             : 
    2449                 :             : /* If COMPARISON can be treated as an unsigned comparison, return a mask
    2450                 :             :    that represents it (8 if it includes <, 4 if it includes > and 2
    2451                 :             :    if it includes ==).  Return 0 otherwise.  */
    2452                 :             : static int
    2453                 :       18706 : unsigned_comparison_to_mask (rtx_code comparison)
    2454                 :             : {
    2455                 :           0 :   switch (comparison)
    2456                 :             :     {
    2457                 :             :     case LTU:
    2458                 :             :       return 8;
    2459                 :             :     case GTU:
    2460                 :             :       return 4;
    2461                 :             :     case EQ:
    2462                 :             :       return 2;
    2463                 :             : 
    2464                 :             :     case LEU:
    2465                 :             :       return 10;
    2466                 :             :     case GEU:
    2467                 :             :       return 6;
    2468                 :             : 
    2469                 :             :     case NE:
    2470                 :             :       return 12;
    2471                 :             : 
    2472                 :             :     default:
    2473                 :             :       return 0;
    2474                 :             :     }
    2475                 :             : }
    2476                 :             : 
    2477                 :             : /* Reverse the mapping in unsigned_comparison_to_mask, going from masks
    2478                 :             :    to comparisons.  */
    2479                 :             : static rtx_code
    2480                 :        6517 : mask_to_unsigned_comparison (int mask)
    2481                 :             : {
    2482                 :        6517 :   switch (mask)
    2483                 :             :     {
    2484                 :             :     case 8:
    2485                 :             :       return LTU;
    2486                 :         160 :     case 4:
    2487                 :         160 :       return GTU;
    2488                 :        2551 :     case 2:
    2489                 :        2551 :       return EQ;
    2490                 :             : 
    2491                 :         160 :     case 10:
    2492                 :         160 :       return LEU;
    2493                 :         160 :     case 6:
    2494                 :         160 :       return GEU;
    2495                 :             : 
    2496                 :        3326 :     case 12:
    2497                 :        3326 :       return NE;
    2498                 :             : 
    2499                 :           0 :     default:
    2500                 :           0 :       gcc_unreachable ();
    2501                 :             :     }
    2502                 :             : }
    2503                 :             : 
    2504                 :             : /* Return a mask describing the COMPARISON.  */
    2505                 :             : static int
    2506                 :        2664 : comparison_to_mask (enum rtx_code comparison)
    2507                 :             : {
    2508                 :        2664 :   switch (comparison)
    2509                 :             :     {
    2510                 :             :     case LT:
    2511                 :             :       return 8;
    2512                 :         472 :     case GT:
    2513                 :         472 :       return 4;
    2514                 :         418 :     case EQ:
    2515                 :         418 :       return 2;
    2516                 :          18 :     case UNORDERED:
    2517                 :          18 :       return 1;
    2518                 :             : 
    2519                 :           0 :     case LTGT:
    2520                 :           0 :       return 12;
    2521                 :         441 :     case LE:
    2522                 :         441 :       return 10;
    2523                 :         441 :     case GE:
    2524                 :         441 :       return 6;
    2525                 :           0 :     case UNLT:
    2526                 :           0 :       return 9;
    2527                 :           0 :     case UNGT:
    2528                 :           0 :       return 5;
    2529                 :           0 :     case UNEQ:
    2530                 :           0 :       return 3;
    2531                 :             : 
    2532                 :           0 :     case ORDERED:
    2533                 :           0 :       return 14;
    2534                 :         400 :     case NE:
    2535                 :         400 :       return 13;
    2536                 :           0 :     case UNLE:
    2537                 :           0 :       return 11;
    2538                 :           0 :     case UNGE:
    2539                 :           0 :       return 7;
    2540                 :             : 
    2541                 :           0 :     default:
    2542                 :           0 :       gcc_unreachable ();
    2543                 :             :     }
    2544                 :             : }
    2545                 :             : 
    2546                 :             : /* Return a comparison corresponding to the MASK.  */
    2547                 :             : static enum rtx_code
    2548                 :        1013 : mask_to_comparison (int mask)
    2549                 :             : {
    2550                 :        1013 :   switch (mask)
    2551                 :             :     {
    2552                 :             :     case 8:
    2553                 :             :       return LT;
    2554                 :             :     case 4:
    2555                 :             :       return GT;
    2556                 :             :     case 2:
    2557                 :             :       return EQ;
    2558                 :             :     case 1:
    2559                 :             :       return UNORDERED;
    2560                 :             : 
    2561                 :             :     case 12:
    2562                 :             :       return LTGT;
    2563                 :             :     case 10:
    2564                 :             :       return LE;
    2565                 :             :     case 6:
    2566                 :             :       return GE;
    2567                 :             :     case 9:
    2568                 :             :       return UNLT;
    2569                 :             :     case 5:
    2570                 :             :       return UNGT;
    2571                 :             :     case 3:
    2572                 :             :       return UNEQ;
    2573                 :             : 
    2574                 :             :     case 14:
    2575                 :             :       return ORDERED;
    2576                 :             :     case 13:
    2577                 :             :       return NE;
    2578                 :             :     case 11:
    2579                 :             :       return UNLE;
    2580                 :             :     case 7:
    2581                 :             :       return UNGE;
    2582                 :             : 
    2583                 :           0 :     default:
    2584                 :           0 :       gcc_unreachable ();
    2585                 :             :     }
    2586                 :             : }
    2587                 :             : 
    2588                 :             : /* Canonicalize RES, a scalar const0_rtx/const_true_rtx to the right
    2589                 :             :    false/true value of comparison with MODE where comparison operands
    2590                 :             :    have CMP_MODE.  */
    2591                 :             : 
    2592                 :             : static rtx
    2593                 :      781324 : relational_result (machine_mode mode, machine_mode cmp_mode, rtx res)
    2594                 :             : {
    2595                 :      781324 :   if (SCALAR_FLOAT_MODE_P (mode))
    2596                 :             :     {
    2597                 :         202 :       if (res == const0_rtx)
    2598                 :         198 :         return CONST0_RTX (mode);
    2599                 :             : #ifdef FLOAT_STORE_FLAG_VALUE
    2600                 :             :       REAL_VALUE_TYPE val = FLOAT_STORE_FLAG_VALUE (mode);
    2601                 :             :       return const_double_from_real_value (val, mode);
    2602                 :             : #else
    2603                 :             :       return NULL_RTX;
    2604                 :             : #endif
    2605                 :             :     }
    2606                 :      781122 :   if (VECTOR_MODE_P (mode))
    2607                 :             :     {
    2608                 :         109 :       if (res == const0_rtx)
    2609                 :          62 :         return CONST0_RTX (mode);
    2610                 :             : #ifdef VECTOR_STORE_FLAG_VALUE
    2611                 :          47 :       rtx val = VECTOR_STORE_FLAG_VALUE (mode);
    2612                 :          47 :       if (val == NULL_RTX)
    2613                 :             :         return NULL_RTX;
    2614                 :          47 :       if (val == const1_rtx)
    2615                 :           0 :         return CONST1_RTX (mode);
    2616                 :             : 
    2617                 :          47 :       return gen_const_vec_duplicate (mode, val);
    2618                 :             : #else
    2619                 :             :       return NULL_RTX;
    2620                 :             : #endif
    2621                 :             :     }
    2622                 :             :   /* For vector comparison with scalar int result, it is unknown
    2623                 :             :      if the target means here a comparison into an integral bitmask,
    2624                 :             :      or comparison where all comparisons true mean const_true_rtx
    2625                 :             :      whole result, or where any comparisons true mean const_true_rtx
    2626                 :             :      whole result.  For const0_rtx all the cases are the same.  */
    2627                 :      781013 :   if (VECTOR_MODE_P (cmp_mode)
    2628                 :           0 :       && SCALAR_INT_MODE_P (mode)
    2629                 :           0 :       && res == const_true_rtx)
    2630                 :           0 :     return NULL_RTX;
    2631                 :             : 
    2632                 :             :   return res;
    2633                 :             : }
    2634                 :             : 
    2635                 :             : /* Simplify a logical operation CODE with result mode MODE, operating on OP0
    2636                 :             :    and OP1, in the case where both are relational operations.  Assume that
    2637                 :             :    OP0 is inverted if INVERT0_P is true.
    2638                 :             : 
    2639                 :             :    Return 0 if no such simplification is possible.  */
    2640                 :             : rtx
    2641                 :    13549704 : simplify_context::simplify_logical_relational_operation (rtx_code code,
    2642                 :             :                                                          machine_mode mode,
    2643                 :             :                                                          rtx op0, rtx op1,
    2644                 :             :                                                          bool invert0_p)
    2645                 :             : {
    2646                 :    13549704 :   if (!(COMPARISON_P (op0) && COMPARISON_P (op1)))
    2647                 :             :     return 0;
    2648                 :             : 
    2649                 :       21497 :   if (!(rtx_equal_p (XEXP (op0, 0), XEXP (op1, 0))
    2650                 :        9776 :         && rtx_equal_p (XEXP (op0, 1), XEXP (op1, 1))))
    2651                 :        2368 :     return 0;
    2652                 :             : 
    2653                 :        9353 :   if (side_effects_p (op0))
    2654                 :             :     return 0;
    2655                 :             : 
    2656                 :        9353 :   enum rtx_code code0 = GET_CODE (op0);
    2657                 :        9353 :   enum rtx_code code1 = GET_CODE (op1);
    2658                 :        9353 :   machine_mode cmp_mode = GET_MODE (XEXP (op0, 0));
    2659                 :        9353 :   if (cmp_mode == VOIDmode)
    2660                 :           0 :     cmp_mode = GET_MODE (XEXP (op0, 1));
    2661                 :             : 
    2662                 :             :   /* Assume at first that the comparisons are on integers, and that the
    2663                 :             :      operands are therefore ordered.  */
    2664                 :        9353 :   int all = 14;
    2665                 :        9353 :   int mask0 = unsigned_comparison_to_mask (code0);
    2666                 :        9353 :   int mask1 = unsigned_comparison_to_mask (code1);
    2667                 :       18706 :   bool unsigned_p = (IN_RANGE (mask0 & 12, 4, 8)
    2668                 :        9353 :                      || IN_RANGE (mask1 & 12, 4, 8));
    2669                 :        1332 :   if (unsigned_p)
    2670                 :             :     {
    2671                 :             :       /* We only reach here when comparing integers.  Reject mixtures of signed
    2672                 :             :          and unsigned comparisons.  */
    2673                 :        8021 :       if (mask0 == 0 || mask1 == 0)
    2674                 :             :         return 0;
    2675                 :             :     }
    2676                 :             :   else
    2677                 :             :     {
    2678                 :             :       /* See whether the operands might be unordered.  Assume that all
    2679                 :             :          results are possible for CC modes, and punt later if we don't get an
    2680                 :             :          always-true or always-false answer.  */
    2681                 :        1332 :       if (GET_MODE_CLASS (cmp_mode) == MODE_CC || HONOR_NANS (cmp_mode))
    2682                 :             :         all = 15;
    2683                 :        1332 :       mask0 = comparison_to_mask (code0) & all;
    2684                 :        1332 :       mask1 = comparison_to_mask (code1) & all;
    2685                 :             :     }
    2686                 :             : 
    2687                 :        8073 :   if (invert0_p)
    2688                 :        4619 :     mask0 = mask0 ^ all;
    2689                 :             : 
    2690                 :        8073 :   int mask;
    2691                 :        8073 :   if (code == AND)
    2692                 :         960 :     mask = mask0 & mask1;
    2693                 :        7113 :   else if (code == IOR)
    2694                 :         947 :     mask = mask0 | mask1;
    2695                 :        6166 :   else if (code == XOR)
    2696                 :        6166 :     mask = mask0 ^ mask1;
    2697                 :             :   else
    2698                 :             :     return 0;
    2699                 :             : 
    2700                 :        8073 :   if (mask == all)
    2701                 :         232 :     return relational_result (mode, GET_MODE (op0), const_true_rtx);
    2702                 :             : 
    2703                 :        7841 :   if (mask == 0)
    2704                 :         232 :     return relational_result (mode, GET_MODE (op0), const0_rtx);
    2705                 :             : 
    2706                 :        7609 :   if (unsigned_p)
    2707                 :        6517 :     code = mask_to_unsigned_comparison (mask);
    2708                 :             :   else
    2709                 :             :     {
    2710                 :        1092 :       if (GET_MODE_CLASS (cmp_mode) == MODE_CC)
    2711                 :             :         return 0;
    2712                 :             : 
    2713                 :        1013 :       code = mask_to_comparison (mask);
    2714                 :             :       /* LTGT and NE are arithmetically equivalent for ordered operands,
    2715                 :             :          with NE being the canonical choice.  */
    2716                 :        1013 :       if (code == LTGT && all == 14)
    2717                 :         184 :         code = NE;
    2718                 :             :     }
    2719                 :             : 
    2720                 :        7530 :   op0 = XEXP (op1, 0);
    2721                 :        7530 :   op1 = XEXP (op1, 1);
    2722                 :             : 
    2723                 :        7530 :   return simplify_gen_relational (code, mode, VOIDmode, op0, op1);
    2724                 :             : }
    2725                 :             : 
    2726                 :             : /* Simplify a binary operation CODE with result mode MODE, operating on OP0
    2727                 :             :    and OP1.  Return 0 if no simplification is possible.
    2728                 :             : 
    2729                 :             :    Don't use this for relational operations such as EQ or LT.
    2730                 :             :    Use simplify_relational_operation instead.  */
    2731                 :             : rtx
    2732                 :   431536351 : simplify_context::simplify_binary_operation (rtx_code code, machine_mode mode,
    2733                 :             :                                              rtx op0, rtx op1)
    2734                 :             : {
    2735                 :   431536351 :   rtx trueop0, trueop1;
    2736                 :   431536351 :   rtx tem;
    2737                 :             : 
    2738                 :             :   /* Relational operations don't work here.  We must know the mode
    2739                 :             :      of the operands in order to do the comparison correctly.
    2740                 :             :      Assuming a full word can give incorrect results.
    2741                 :             :      Consider comparing 128 with -128 in QImode.  */
    2742                 :   431536351 :   gcc_assert (GET_RTX_CLASS (code) != RTX_COMPARE);
    2743                 :   431536351 :   gcc_assert (GET_RTX_CLASS (code) != RTX_COMM_COMPARE);
    2744                 :             : 
    2745                 :             :   /* Make sure the constant is second.  */
    2746                 :   431536351 :   if (GET_RTX_CLASS (code) == RTX_COMM_ARITH
    2747                 :   431536351 :       && swap_commutative_operands_p (op0, op1))
    2748                 :             :     std::swap (op0, op1);
    2749                 :             : 
    2750                 :   431536351 :   trueop0 = avoid_constant_pool_reference (op0);
    2751                 :   431536351 :   trueop1 = avoid_constant_pool_reference (op1);
    2752                 :             : 
    2753                 :   431536351 :   tem = simplify_const_binary_operation (code, mode, trueop0, trueop1);
    2754                 :   431536351 :   if (tem)
    2755                 :             :     return tem;
    2756                 :   403875062 :   tem = simplify_binary_operation_1 (code, mode, op0, op1, trueop0, trueop1);
    2757                 :             : 
    2758                 :   403875062 :   if (tem)
    2759                 :             :     return tem;
    2760                 :             : 
    2761                 :             :   /* If the above steps did not result in a simplification and op0 or op1
    2762                 :             :      were constant pool references, use the referenced constants directly.  */
    2763                 :   347131042 :   if (trueop0 != op0 || trueop1 != op1)
    2764                 :      572507 :     return simplify_gen_binary (code, mode, trueop0, trueop1);
    2765                 :             : 
    2766                 :             :   return NULL_RTX;
    2767                 :             : }
    2768                 :             : 
    2769                 :             : /* Subroutine of simplify_binary_operation_1 that looks for cases in
    2770                 :             :    which OP0 and OP1 are both vector series or vector duplicates
    2771                 :             :    (which are really just series with a step of 0).  If so, try to
    2772                 :             :    form a new series by applying CODE to the bases and to the steps.
    2773                 :             :    Return null if no simplification is possible.
    2774                 :             : 
    2775                 :             :    MODE is the mode of the operation and is known to be a vector
    2776                 :             :    integer mode.  */
    2777                 :             : 
    2778                 :             : rtx
    2779                 :     2147427 : simplify_context::simplify_binary_operation_series (rtx_code code,
    2780                 :             :                                                     machine_mode mode,
    2781                 :             :                                                     rtx op0, rtx op1)
    2782                 :             : {
    2783                 :     2147427 :   rtx base0, step0;
    2784                 :     2147427 :   if (vec_duplicate_p (op0, &base0))
    2785                 :       65309 :     step0 = const0_rtx;
    2786                 :     2082118 :   else if (!vec_series_p (op0, &base0, &step0))
    2787                 :             :     return NULL_RTX;
    2788                 :             : 
    2789                 :       65649 :   rtx base1, step1;
    2790                 :       65649 :   if (vec_duplicate_p (op1, &base1))
    2791                 :         356 :     step1 = const0_rtx;
    2792                 :       65293 :   else if (!vec_series_p (op1, &base1, &step1))
    2793                 :             :     return NULL_RTX;
    2794                 :             : 
    2795                 :             :   /* Only create a new series if we can simplify both parts.  In other
    2796                 :             :      cases this isn't really a simplification, and it's not necessarily
    2797                 :             :      a win to replace a vector operation with a scalar operation.  */
    2798                 :        3234 :   scalar_mode inner_mode = GET_MODE_INNER (mode);
    2799                 :        3234 :   rtx new_base = simplify_binary_operation (code, inner_mode, base0, base1);
    2800                 :        3234 :   if (!new_base)
    2801                 :             :     return NULL_RTX;
    2802                 :             : 
    2803                 :        2953 :   rtx new_step = simplify_binary_operation (code, inner_mode, step0, step1);
    2804                 :        2953 :   if (!new_step)
    2805                 :             :     return NULL_RTX;
    2806                 :             : 
    2807                 :        2953 :   return gen_vec_series (mode, new_base, new_step);
    2808                 :             : }
    2809                 :             : 
    2810                 :             : /* Subroutine of simplify_binary_operation_1.  Un-distribute a binary
    2811                 :             :    operation CODE with result mode MODE, operating on OP0 and OP1.
    2812                 :             :    e.g. simplify (xor (and A C) (and (B C)) to (and (xor (A B) C).
    2813                 :             :    Returns NULL_RTX if no simplification is possible.  */
    2814                 :             : 
    2815                 :             : rtx
    2816                 :     1357162 : simplify_context::simplify_distributive_operation (rtx_code code,
    2817                 :             :                                                    machine_mode mode,
    2818                 :             :                                                    rtx op0, rtx op1)
    2819                 :             : {
    2820                 :     1357162 :   enum rtx_code op = GET_CODE (op0);
    2821                 :     1357162 :   gcc_assert (GET_CODE (op1) == op);
    2822                 :             : 
    2823                 :     1357162 :   if (rtx_equal_p (XEXP (op0, 1), XEXP (op1, 1))
    2824                 :     1357162 :       && ! side_effects_p (XEXP (op0, 1)))
    2825                 :      302701 :     return simplify_gen_binary (op, mode,
    2826                 :             :                                 simplify_gen_binary (code, mode,
    2827                 :             :                                                      XEXP (op0, 0),
    2828                 :             :                                                      XEXP (op1, 0)),
    2829                 :      302701 :                                 XEXP (op0, 1));
    2830                 :             : 
    2831                 :     1054461 :   if (GET_RTX_CLASS (op) == RTX_COMM_ARITH)
    2832                 :             :     {
    2833                 :     1030195 :       if (rtx_equal_p (XEXP (op0, 0), XEXP (op1, 0))
    2834                 :     1030195 :           && ! side_effects_p (XEXP (op0, 0)))
    2835                 :      501984 :         return simplify_gen_binary (op, mode,
    2836                 :             :                                     simplify_gen_binary (code, mode,
    2837                 :             :                                                          XEXP (op0, 1),
    2838                 :             :                                                          XEXP (op1, 1)),
    2839                 :      501984 :                                     XEXP (op0, 0));
    2840                 :      528211 :       if (rtx_equal_p (XEXP (op0, 0), XEXP (op1, 1))
    2841                 :      528211 :           && ! side_effects_p (XEXP (op0, 0)))
    2842                 :          58 :         return simplify_gen_binary (op, mode,
    2843                 :             :                                     simplify_gen_binary (code, mode,
    2844                 :             :                                                          XEXP (op0, 1),
    2845                 :             :                                                          XEXP (op1, 0)),
    2846                 :          58 :                                     XEXP (op0, 0));
    2847                 :      528153 :       if (rtx_equal_p (XEXP (op0, 1), XEXP (op1, 0))
    2848                 :      528153 :           && ! side_effects_p (XEXP (op0, 1)))
    2849                 :      296528 :         return simplify_gen_binary (op, mode,
    2850                 :             :                                     simplify_gen_binary (code, mode,
    2851                 :             :                                                          XEXP (op0, 0),
    2852                 :             :                                                          XEXP (op1, 1)),
    2853                 :      296528 :                                     XEXP (op0, 1));
    2854                 :             :     }
    2855                 :             : 
    2856                 :             :   return NULL_RTX;
    2857                 :             : }
    2858                 :             : 
    2859                 :             : /* Return TRUE if a rotate in mode MODE with a constant count in OP1
    2860                 :             :    should be reversed.
    2861                 :             : 
    2862                 :             :    If the rotate should not be reversed, return FALSE.
    2863                 :             : 
    2864                 :             :    LEFT indicates if this is a rotate left or a rotate right.  */
    2865                 :             : 
    2866                 :             : bool
    2867                 :      138652 : reverse_rotate_by_imm_p (machine_mode mode, unsigned int left, rtx op1)
    2868                 :             : {
    2869                 :      138652 :   if (!CONST_INT_P (op1))
    2870                 :             :     return false;
    2871                 :             : 
    2872                 :             :   /* Some targets may only be able to rotate by a constant
    2873                 :             :      in one direction.  So we need to query the optab interface
    2874                 :             :      to see what is possible.  */
    2875                 :      107371 :   optab binoptab = left ? rotl_optab : rotr_optab;
    2876                 :       45619 :   optab re_binoptab = left ? rotr_optab : rotl_optab;
    2877                 :      107371 :   enum insn_code icode = optab_handler (binoptab, mode);
    2878                 :      107371 :   enum insn_code re_icode = optab_handler (re_binoptab, mode);
    2879                 :             : 
    2880                 :             :   /* If the target can not support the reversed optab, then there
    2881                 :             :      is nothing to do.  */
    2882                 :      107371 :   if (re_icode == CODE_FOR_nothing)
    2883                 :             :     return false;
    2884                 :             : 
    2885                 :             :   /* If the target does not support the requested rotate-by-immediate,
    2886                 :             :      then we want to try reversing the rotate.  We also want to try
    2887                 :             :      reversing to minimize the count.  */
    2888                 :      104871 :   if ((icode == CODE_FOR_nothing)
    2889                 :      104871 :       || (!insn_operand_matches (icode, 2, op1))
    2890                 :      524355 :       || (IN_RANGE (INTVAL (op1),
    2891                 :             :                     GET_MODE_UNIT_PRECISION (mode) / 2 + left,
    2892                 :             :                     GET_MODE_UNIT_PRECISION (mode) - 1)))
    2893                 :       14119 :     return (insn_operand_matches (re_icode, 2, op1));
    2894                 :             :   return false;
    2895                 :             : }
    2896                 :             : 
    2897                 :             : /* Analyse argument X to see if it represents an (ASHIFT X Y) operation
    2898                 :             :    and return the expression to be shifted in SHIFT_OPND and the shift amount
    2899                 :             :    in SHIFT_AMNT.  This is primarily used to group handling of ASHIFT (X, CST)
    2900                 :             :    and (PLUS (X, X)) in one place.  If the expression is not equivalent to an
    2901                 :             :    ASHIFT then return FALSE and set SHIFT_OPND and SHIFT_AMNT to NULL.  */
    2902                 :             : 
    2903                 :             : static bool
    2904                 :   475789580 : extract_ashift_operands_p (rtx x, rtx *shift_opnd, rtx *shift_amnt)
    2905                 :             : {
    2906                 :   475789580 :   if (GET_CODE (x) == ASHIFT)
    2907                 :             :     {
    2908                 :    13386987 :       *shift_opnd = XEXP (x, 0);
    2909                 :    13386987 :       *shift_amnt = XEXP (x, 1);
    2910                 :    13386987 :       return true;
    2911                 :             :     }
    2912                 :   462402593 :   if (GET_CODE (x) == PLUS && rtx_equal_p (XEXP (x, 0), XEXP (x, 1)))
    2913                 :             :     {
    2914                 :       10542 :       *shift_opnd = XEXP (x, 0);
    2915                 :       10542 :       *shift_amnt = CONST1_RTX (GET_MODE (x));
    2916                 :       10542 :       return true;
    2917                 :             :     }
    2918                 :   462392051 :   *shift_opnd = NULL_RTX;
    2919                 :   462392051 :   *shift_amnt = NULL_RTX;
    2920                 :   462392051 :   return false;
    2921                 :             : }
    2922                 :             : 
    2923                 :             : /* OP0 and OP1 are combined under an operation of mode MODE that can
    2924                 :             :    potentially result in a ROTATE expression.  Analyze the OP0 and OP1
    2925                 :             :    and return the resulting ROTATE expression if so.  Return NULL otherwise.
    2926                 :             :    This is used in detecting the patterns (X << C1) [+,|,^] (X >> C2) where
    2927                 :             :    C1 + C2 == GET_MODE_UNIT_PRECISION (mode).
    2928                 :             :    (X << C1) and (C >> C2) would be OP0 and OP1.  */
    2929                 :             : 
    2930                 :             : static rtx
    2931                 :   240172253 : simplify_rotate_op (rtx op0, rtx op1, machine_mode mode)
    2932                 :             : {
    2933                 :             :   /* Convert (ior (ashift A CX) (lshiftrt A CY)) where CX+CY equals the
    2934                 :             :      mode size to (rotate A CX).  */
    2935                 :             : 
    2936                 :   240172253 :   rtx opleft = op0;
    2937                 :   240172253 :   rtx opright = op1;
    2938                 :   240172253 :   rtx ashift_opnd, ashift_amnt;
    2939                 :             :   /* In some cases the ASHIFT is not a direct ASHIFT.  Look deeper and extract
    2940                 :             :      the relevant operands here.  */
    2941                 :   240172253 :   bool ashift_op_p
    2942                 :   240172253 :     = extract_ashift_operands_p (op1, &ashift_opnd, &ashift_amnt);
    2943                 :             : 
    2944                 :   240172253 :   if (ashift_op_p
    2945                 :   238409979 :      || GET_CODE (op1) == SUBREG)
    2946                 :             :     {
    2947                 :             :       opleft = op1;
    2948                 :             :       opright = op0;
    2949                 :             :     }
    2950                 :             :   else
    2951                 :             :     {
    2952                 :   235617327 :       opright = op1;
    2953                 :   235617327 :       opleft = op0;
    2954                 :   235617327 :       ashift_op_p
    2955                 :   235617327 :         = extract_ashift_operands_p (opleft, &ashift_opnd, &ashift_amnt);
    2956                 :             :     }
    2957                 :             : 
    2958                 :    13397529 :   if (ashift_op_p && GET_CODE (opright) == LSHIFTRT
    2959                 :   238453793 :       && rtx_equal_p (ashift_opnd, XEXP (opright, 0)))
    2960                 :             :     {
    2961                 :        9776 :       rtx leftcst = unwrap_const_vec_duplicate (ashift_amnt);
    2962                 :        9776 :       rtx rightcst = unwrap_const_vec_duplicate (XEXP (opright, 1));
    2963                 :             : 
    2964                 :        5953 :       if (CONST_INT_P (leftcst) && CONST_INT_P (rightcst)
    2965                 :       15729 :           && (INTVAL (leftcst) + INTVAL (rightcst)
    2966                 :        5953 :               == GET_MODE_UNIT_PRECISION (mode)))
    2967                 :        5419 :         return gen_rtx_ROTATE (mode, XEXP (opright, 0), ashift_amnt);
    2968                 :             :     }
    2969                 :             : 
    2970                 :             :   /* Same, but for ashift that has been "simplified" to a wider mode
    2971                 :             :      by simplify_shift_const.  */
    2972                 :   240166834 :   scalar_int_mode int_mode, inner_mode;
    2973                 :             : 
    2974                 :   240166834 :   if (GET_CODE (opleft) == SUBREG
    2975                 :   244250754 :       && is_a <scalar_int_mode> (mode, &int_mode)
    2976                 :     4078501 :       && is_a <scalar_int_mode> (GET_MODE (SUBREG_REG (opleft)),
    2977                 :             :                                  &inner_mode)
    2978                 :     4053274 :       && GET_CODE (SUBREG_REG (opleft)) == ASHIFT
    2979                 :      159352 :       && GET_CODE (opright) == LSHIFTRT
    2980                 :         875 :       && GET_CODE (XEXP (opright, 0)) == SUBREG
    2981                 :         230 :       && known_eq (SUBREG_BYTE (opleft), SUBREG_BYTE (XEXP (opright, 0)))
    2982                 :         456 :       && GET_MODE_SIZE (int_mode) < GET_MODE_SIZE (inner_mode)
    2983                 :         214 :       && rtx_equal_p (XEXP (SUBREG_REG (opleft), 0),
    2984                 :         214 :                       SUBREG_REG (XEXP (opright, 0)))
    2985                 :         102 :       && CONST_INT_P (XEXP (SUBREG_REG (opleft), 1))
    2986                 :         102 :       && CONST_INT_P (XEXP (opright, 1))
    2987                 :   240166834 :       && (INTVAL (XEXP (SUBREG_REG (opleft), 1))
    2988                 :         102 :             + INTVAL (XEXP (opright, 1))
    2989                 :         102 :          == GET_MODE_PRECISION (int_mode)))
    2990                 :          96 :         return gen_rtx_ROTATE (int_mode, XEXP (opright, 0),
    2991                 :             :                                XEXP (SUBREG_REG (opleft), 1));
    2992                 :             :   return NULL_RTX;
    2993                 :             : }
    2994                 :             : 
    2995                 :             : /* Returns true if OP0 and OP1 match the pattern (OP (plus (A - 1)) (neg A)),
    2996                 :             :    and the pattern can be simplified (there are no side effects).  */
    2997                 :             : 
    2998                 :             : static bool
    2999                 :    37396653 : match_plus_neg_pattern (rtx op0, rtx op1, machine_mode mode)
    3000                 :             : {
    3001                 :             :   /* Remove SUBREG from OP0 and OP1, if needed.  */
    3002                 :    37396653 :   if (GET_CODE (op0) == SUBREG
    3003                 :     6470712 :       && GET_CODE (op1) == SUBREG
    3004                 :      277311 :       && subreg_lowpart_p (op0)
    3005                 :    37672448 :       && subreg_lowpart_p (op1))
    3006                 :             :     {
    3007                 :      275788 :       op0 = XEXP (op0, 0);
    3008                 :      275788 :       op1 = XEXP (op1, 0);
    3009                 :             :     }
    3010                 :             : 
    3011                 :             :   /* Check for the pattern (OP (plus (A - 1)) (neg A)).  */
    3012                 :    37396653 :   if (((GET_CODE (op1) == NEG
    3013                 :        3609 :         && GET_CODE (op0) == PLUS
    3014                 :        2192 :         && XEXP (op0, 1) == CONSTM1_RTX (mode))
    3015                 :    37396007 :        || (GET_CODE (op0) == NEG
    3016                 :       75148 :            && GET_CODE (op1) == PLUS
    3017                 :           0 :            && XEXP (op1, 1) == CONSTM1_RTX (mode)))
    3018                 :         646 :       && rtx_equal_p (XEXP (op0, 0), XEXP (op1, 0))
    3019                 :    37396653 :       && !side_effects_p (XEXP (op0, 0)))
    3020                 :             :     return true;
    3021                 :             :   return false;
    3022                 :             : }
    3023                 :             : 
    3024                 :             : /* Subroutine of simplify_binary_operation.  Simplify a binary operation
    3025                 :             :    CODE with result mode MODE, operating on OP0 and OP1.  If OP0 and/or
    3026                 :             :    OP1 are constant pool references, TRUEOP0 and TRUEOP1 represent the
    3027                 :             :    actual constants.  */
    3028                 :             : 
    3029                 :             : rtx
    3030                 :   403875062 : simplify_context::simplify_binary_operation_1 (rtx_code code,
    3031                 :             :                                                machine_mode mode,
    3032                 :             :                                                rtx op0, rtx op1,
    3033                 :             :                                                rtx trueop0, rtx trueop1)
    3034                 :             : {
    3035                 :   403875062 :   rtx tem, reversed, elt0, elt1;
    3036                 :   403875062 :   HOST_WIDE_INT val;
    3037                 :   403875062 :   scalar_int_mode int_mode, inner_mode;
    3038                 :   403875062 :   poly_int64 offset;
    3039                 :             : 
    3040                 :             :   /* Even if we can't compute a constant result,
    3041                 :             :      there are some cases worth simplifying.  */
    3042                 :             : 
    3043                 :   403875062 :   switch (code)
    3044                 :             :     {
    3045                 :   229339104 :     case PLUS:
    3046                 :             :       /* Maybe simplify x + 0 to x.  The two expressions are equivalent
    3047                 :             :          when x is NaN, infinite, or finite and nonzero.  They aren't
    3048                 :             :          when x is -0 and the rounding mode is not towards -infinity,
    3049                 :             :          since (-0) + 0 is then 0.  */
    3050                 :   454804157 :       if (!HONOR_SIGNED_ZEROS (mode) && !HONOR_SNANS (mode)
    3051                 :   454804145 :           && trueop1 == CONST0_RTX (mode))
    3052                 :             :         return op0;
    3053                 :             : 
    3054                 :             :       /* ((-a) + b) -> (b - a) and similarly for (a + (-b)).  These
    3055                 :             :          transformations are safe even for IEEE.  */
    3056                 :   228076256 :       if (GET_CODE (op0) == NEG)
    3057                 :       30023 :         return simplify_gen_binary (MINUS, mode, op1, XEXP (op0, 0));
    3058                 :   228046233 :       else if (GET_CODE (op1) == NEG)
    3059                 :        7761 :         return simplify_gen_binary (MINUS, mode, op0, XEXP (op1, 0));
    3060                 :             : 
    3061                 :             :       /* (~a) + 1 -> -a */
    3062                 :   228038472 :       if (INTEGRAL_MODE_P (mode)
    3063                 :   223257312 :           && GET_CODE (op0) == NOT
    3064                 :      576365 :           && trueop1 == const1_rtx)
    3065                 :        3337 :         return simplify_gen_unary (NEG, mode, XEXP (op0, 0), mode);
    3066                 :             : 
    3067                 :             :       /* Handle both-operands-constant cases.  We can only add
    3068                 :             :          CONST_INTs to constants since the sum of relocatable symbols
    3069                 :             :          can't be handled by most assemblers.  Don't add CONST_INT
    3070                 :             :          to CONST_INT since overflow won't be computed properly if wider
    3071                 :             :          than HOST_BITS_PER_WIDE_INT.  */
    3072                 :             : 
    3073                 :   228035135 :       if ((GET_CODE (op0) == CONST
    3074                 :   228035135 :            || GET_CODE (op0) == SYMBOL_REF
    3075                 :   225877337 :            || GET_CODE (op0) == LABEL_REF)
    3076                 :   228035135 :           && poly_int_rtx_p (op1, &offset))
    3077                 :     2156809 :         return plus_constant (mode, op0, offset);
    3078                 :   225878326 :       else if ((GET_CODE (op1) == CONST
    3079                 :   225878326 :                 || GET_CODE (op1) == SYMBOL_REF
    3080                 :   222480557 :                 || GET_CODE (op1) == LABEL_REF)
    3081                 :   225878326 :                && poly_int_rtx_p (op0, &offset))
    3082                 :           0 :         return plus_constant (mode, op1, offset);
    3083                 :             : 
    3084                 :             :       /* See if this is something like X * C - X or vice versa or
    3085                 :             :          if the multiplication is written as a shift.  If so, we can
    3086                 :             :          distribute and make a new multiply, shift, or maybe just
    3087                 :             :          have X (if C is 2 in the example above).  But don't make
    3088                 :             :          something more expensive than we had before.  */
    3089                 :             : 
    3090                 :   225878326 :       if (is_a <scalar_int_mode> (mode, &int_mode))
    3091                 :             :         {
    3092                 :   219152037 :           rtx lhs = op0, rhs = op1;
    3093                 :             : 
    3094                 :   219152037 :           wide_int coeff0 = wi::one (GET_MODE_PRECISION (int_mode));
    3095                 :   219152037 :           wide_int coeff1 = wi::one (GET_MODE_PRECISION (int_mode));
    3096                 :             : 
    3097                 :   219152037 :           if (GET_CODE (lhs) == NEG)
    3098                 :             :             {
    3099                 :           0 :               coeff0 = wi::minus_one (GET_MODE_PRECISION (int_mode));
    3100                 :           0 :               lhs = XEXP (lhs, 0);
    3101                 :             :             }
    3102                 :   219152037 :           else if (GET_CODE (lhs) == MULT
    3103                 :     6497516 :                    && CONST_SCALAR_INT_P (XEXP (lhs, 1)))
    3104                 :             :             {
    3105                 :     5422007 :               coeff0 = rtx_mode_t (XEXP (lhs, 1), int_mode);
    3106                 :     5422007 :               lhs = XEXP (lhs, 0);
    3107                 :             :             }
    3108                 :   213730030 :           else if (GET_CODE (lhs) == ASHIFT
    3109                 :    10408164 :                    && CONST_INT_P (XEXP (lhs, 1))
    3110                 :    10338489 :                    && INTVAL (XEXP (lhs, 1)) >= 0
    3111                 :   224068507 :                    && INTVAL (XEXP (lhs, 1)) < GET_MODE_PRECISION (int_mode))
    3112                 :             :             {
    3113                 :    10338477 :               coeff0 = wi::set_bit_in_zero (INTVAL (XEXP (lhs, 1)),
    3114                 :    20676954 :                                             GET_MODE_PRECISION (int_mode));
    3115                 :    10338477 :               lhs = XEXP (lhs, 0);
    3116                 :             :             }
    3117                 :             : 
    3118                 :   219152037 :           if (GET_CODE (rhs) == NEG)
    3119                 :             :             {
    3120                 :           0 :               coeff1 = wi::minus_one (GET_MODE_PRECISION (int_mode));
    3121                 :           0 :               rhs = XEXP (rhs, 0);
    3122                 :             :             }
    3123                 :   219152037 :           else if (GET_CODE (rhs) == MULT
    3124                 :      266596 :                    && CONST_INT_P (XEXP (rhs, 1)))
    3125                 :             :             {
    3126                 :      169718 :               coeff1 = rtx_mode_t (XEXP (rhs, 1), int_mode);
    3127                 :      169718 :               rhs = XEXP (rhs, 0);
    3128                 :             :             }
    3129                 :   218982319 :           else if (GET_CODE (rhs) == ASHIFT
    3130                 :      554649 :                    && CONST_INT_P (XEXP (rhs, 1))
    3131                 :      544926 :                    && INTVAL (XEXP (rhs, 1)) >= 0
    3132                 :   219527245 :                    && INTVAL (XEXP (rhs, 1)) < GET_MODE_PRECISION (int_mode))
    3133                 :             :             {
    3134                 :      544926 :               coeff1 = wi::set_bit_in_zero (INTVAL (XEXP (rhs, 1)),
    3135                 :     1089852 :                                             GET_MODE_PRECISION (int_mode));
    3136                 :      544926 :               rhs = XEXP (rhs, 0);
    3137                 :             :             }
    3138                 :             : 
    3139                 :   219152037 :           if (rtx_equal_p (lhs, rhs))
    3140                 :             :             {
    3141                 :      713240 :               rtx orig = gen_rtx_PLUS (int_mode, op0, op1);
    3142                 :      713240 :               rtx coeff;
    3143                 :      713240 :               bool speed = optimize_function_for_speed_p (cfun);
    3144                 :             : 
    3145                 :      713240 :               coeff = immed_wide_int_const (coeff0 + coeff1, int_mode);
    3146                 :             : 
    3147                 :      713240 :               tem = simplify_gen_binary (MULT, int_mode, lhs, coeff);
    3148                 :      713240 :               return (set_src_cost (tem, int_mode, speed)
    3149                 :      713240 :                       <= set_src_cost (orig, int_mode, speed) ? tem : 0);
    3150                 :             :             }
    3151                 :             : 
    3152                 :             :           /* Optimize (X - 1) * Y + Y to X * Y.  */
    3153                 :   218438797 :           lhs = op0;
    3154                 :   218438797 :           rhs = op1;
    3155                 :   218438797 :           if (GET_CODE (op0) == MULT)
    3156                 :             :             {
    3157                 :     6474886 :               if (((GET_CODE (XEXP (op0, 0)) == PLUS
    3158                 :      284915 :                     && XEXP (XEXP (op0, 0), 1) == constm1_rtx)
    3159                 :     6434668 :                    || (GET_CODE (XEXP (op0, 0)) == MINUS
    3160                 :       34819 :                        && XEXP (XEXP (op0, 0), 1) == const1_rtx))
    3161                 :     6515104 :                   && rtx_equal_p (XEXP (op0, 1), op1))
    3162                 :          42 :                 lhs = XEXP (XEXP (op0, 0), 0);
    3163                 :     6474844 :               else if (((GET_CODE (XEXP (op0, 1)) == PLUS
    3164                 :        1001 :                          && XEXP (XEXP (op0, 1), 1) == constm1_rtx)
    3165                 :     6474809 :                         || (GET_CODE (XEXP (op0, 1)) == MINUS
    3166                 :         239 :                             && XEXP (XEXP (op0, 1), 1) == const1_rtx))
    3167                 :     6474879 :                        && rtx_equal_p (XEXP (op0, 0), op1))
    3168                 :           0 :                 lhs = XEXP (XEXP (op0, 1), 0);
    3169                 :             :             }
    3170                 :   211963911 :           else if (GET_CODE (op1) == MULT)
    3171                 :             :             {
    3172                 :      122188 :               if (((GET_CODE (XEXP (op1, 0)) == PLUS
    3173                 :          35 :                     && XEXP (XEXP (op1, 0), 1) == constm1_rtx)
    3174                 :      122186 :                    || (GET_CODE (XEXP (op1, 0)) == MINUS
    3175                 :          29 :                        && XEXP (XEXP (op1, 0), 1) == const1_rtx))
    3176                 :      122190 :                   && rtx_equal_p (XEXP (op1, 1), op0))
    3177                 :           0 :                 rhs = XEXP (XEXP (op1, 0), 0);
    3178                 :      122188 :               else if (((GET_CODE (XEXP (op1, 1)) == PLUS
    3179                 :           0 :                          && XEXP (XEXP (op1, 1), 1) == constm1_rtx)
    3180                 :      122188 :                         || (GET_CODE (XEXP (op1, 1)) == MINUS
    3181                 :           0 :                             && XEXP (XEXP (op1, 1), 1) == const1_rtx))
    3182                 :      122188 :                        && rtx_equal_p (XEXP (op1, 0), op0))
    3183                 :           0 :                 rhs = XEXP (XEXP (op1, 1), 0);
    3184                 :             :             }
    3185                 :   218438797 :           if (lhs != op0 || rhs != op1)
    3186                 :          42 :             return simplify_gen_binary (MULT, int_mode, lhs, rhs);
    3187                 :   219152037 :         }
    3188                 :             : 
    3189                 :             :       /* (plus (xor X C1) C2) is (xor X (C1^C2)) if C2 is signbit.  */
    3190                 :   225165044 :       if (CONST_SCALAR_INT_P (op1)
    3191                 :   174028261 :           && GET_CODE (op0) == XOR
    3192                 :       21490 :           && CONST_SCALAR_INT_P (XEXP (op0, 1))
    3193                 :   225178063 :           && mode_signbit_p (mode, op1))
    3194                 :         122 :         return simplify_gen_binary (XOR, mode, XEXP (op0, 0),
    3195                 :             :                                     simplify_gen_binary (XOR, mode, op1,
    3196                 :         122 :                                                          XEXP (op0, 1)));
    3197                 :             : 
    3198                 :             :       /* (plus (xor X C1) C2) is (xor X (C1^C2)) if X is either 0 or 1 and
    3199                 :             :          2 * ((X ^ C1) & C2) == 0; based on A + B == A ^ B + 2 * (A & B). */
    3200                 :   225164922 :       if (CONST_SCALAR_INT_P (op1)
    3201                 :   174028139 :           && GET_CODE (op0) == XOR
    3202                 :       21368 :           && CONST_SCALAR_INT_P (XEXP (op0, 1))
    3203                 :       12897 :           && nonzero_bits (XEXP (op0, 0), mode) == 1
    3204                 :         113 :           && 2 * (INTVAL (XEXP (op0, 1)) & INTVAL (op1)) == 0
    3205                 :   225164925 :           && 2 * ((1 ^ INTVAL (XEXP (op0, 1))) & INTVAL (op1)) == 0)
    3206                 :           3 :         return simplify_gen_binary (XOR, mode, XEXP (op0, 0),
    3207                 :             :                                     simplify_gen_binary (XOR, mode, op1,
    3208                 :           3 :                                                          XEXP (op0, 1)));
    3209                 :             : 
    3210                 :             :       /* Canonicalize (plus (mult (neg B) C) A) to (minus A (mult B C)).  */
    3211                 :   225164919 :       if (!HONOR_SIGN_DEPENDENT_ROUNDING (mode)
    3212                 :   225162440 :           && GET_CODE (op0) == MULT
    3213                 :   231998044 :           && GET_CODE (XEXP (op0, 0)) == NEG)
    3214                 :             :         {
    3215                 :        5429 :           rtx in1, in2;
    3216                 :             : 
    3217                 :        5429 :           in1 = XEXP (XEXP (op0, 0), 0);
    3218                 :        5429 :           in2 = XEXP (op0, 1);
    3219                 :        5429 :           return simplify_gen_binary (MINUS, mode, op1,
    3220                 :             :                                       simplify_gen_binary (MULT, mode,
    3221                 :        5429 :                                                            in1, in2));
    3222                 :             :         }
    3223                 :             : 
    3224                 :             :       /* (plus (comparison A B) C) can become (neg (rev-comp A B)) if
    3225                 :             :          C is 1 and STORE_FLAG_VALUE is -1 or if C is -1 and STORE_FLAG_VALUE
    3226                 :             :          is 1.  */
    3227                 :   225159490 :       if (COMPARISON_P (op0)
    3228                 :     2090559 :           && ((STORE_FLAG_VALUE == -1 && trueop1 == const1_rtx)
    3229                 :     2090559 :               || (STORE_FLAG_VALUE == 1 && trueop1 == constm1_rtx))
    3230                 :   225205090 :           && (reversed = reversed_comparison (op0, mode)))
    3231                 :       45284 :         return
    3232                 :       45284 :           simplify_gen_unary (NEG, mode, reversed, mode);
    3233                 :             : 
    3234                 :             :       /* Convert (plus (ashift A CX) (lshiftrt A CY)) where CX+CY equals the
    3235                 :             :          mode size to (rotate A CX).  */
    3236                 :   225114206 :       if ((tem = simplify_rotate_op (op0, op1, mode)))
    3237                 :             :         return tem;
    3238                 :             : 
    3239                 :             :       /* If one of the operands is a PLUS or a MINUS, see if we can
    3240                 :             :          simplify this by the associative law.
    3241                 :             :          Don't use the associative law for floating point.
    3242                 :             :          The inaccuracy makes it nonassociative,
    3243                 :             :          and subtle programs can break if operations are associated.  */
    3244                 :             : 
    3245                 :   225112682 :       if (INTEGRAL_MODE_P (mode)
    3246                 :   220331559 :           && (plus_minus_operand_p (op0)
    3247                 :   190382722 :               || plus_minus_operand_p (op1))
    3248                 :    30842512 :           && (tem = simplify_plus_minus (code, mode, op0, op1)) != 0)
    3249                 :             :         return tem;
    3250                 :             : 
    3251                 :             :       /* Reassociate floating point addition only when the user
    3252                 :             :          specifies associative math operations.  */
    3253                 :   194952609 :       if (FLOAT_MODE_P (mode)
    3254                 :     4781123 :           && flag_associative_math)
    3255                 :             :         {
    3256                 :      907038 :           tem = simplify_associative_operation (code, mode, op0, op1);
    3257                 :      907038 :           if (tem)
    3258                 :             :             return tem;
    3259                 :             :         }
    3260                 :             : 
    3261                 :             :       /* Handle vector series.  */
    3262                 :   194939471 :       if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
    3263                 :             :         {
    3264                 :     1793879 :           tem = simplify_binary_operation_series (code, mode, op0, op1);
    3265                 :     1793879 :           if (tem)
    3266                 :             :             return tem;
    3267                 :             :         }
    3268                 :             :       break;
    3269                 :             : 
    3270                 :             :     case COMPARE:
    3271                 :             :       break;
    3272                 :             : 
    3273                 :    38670325 :     case MINUS:
    3274                 :             :       /* We can't assume x-x is 0 even with non-IEEE floating point,
    3275                 :             :          but since it is zero except in very strange circumstances, we
    3276                 :             :          will treat it as zero with -ffinite-math-only.  */
    3277                 :    38670325 :       if (rtx_equal_p (trueop0, trueop1)
    3278                 :      211950 :           && ! side_effects_p (op0)
    3279                 :    38881257 :           && (!FLOAT_MODE_P (mode) || !HONOR_NANS (mode)))
    3280                 :      208645 :         return CONST0_RTX (mode);
    3281                 :             : 
    3282                 :             :       /* Change subtraction from zero into negation.  (0 - x) is the
    3283                 :             :          same as -x when x is NaN, infinite, or finite and nonzero.
    3284                 :             :          But if the mode has signed zeros, and does not round towards
    3285                 :             :          -infinity, then 0 - 0 is 0, not -0.  */
    3286                 :    38461680 :       if (!HONOR_SIGNED_ZEROS (mode) && trueop0 == CONST0_RTX (mode))
    3287                 :      274863 :         return simplify_gen_unary (NEG, mode, op1, mode);
    3288                 :             : 
    3289                 :             :       /* (-1 - a) is ~a, unless the expression contains symbolic
    3290                 :             :          constants, in which case not retaining additions and
    3291                 :             :          subtractions could cause invalid assembly to be produced.  */
    3292                 :    38186817 :       if (trueop0 == CONSTM1_RTX (mode)
    3293                 :    38186817 :           && !contains_symbolic_reference_p (op1))
    3294                 :      336217 :         return simplify_gen_unary (NOT, mode, op1, mode);
    3295                 :             : 
    3296                 :             :       /* Subtracting 0 has no effect unless the mode has signalling NaNs,
    3297                 :             :          or has signed zeros and supports rounding towards -infinity.
    3298                 :             :          In such a case, 0 - 0 is -0.  */
    3299                 :    38529977 :       if (!(HONOR_SIGNED_ZEROS (mode)
    3300                 :      679377 :             && HONOR_SIGN_DEPENDENT_ROUNDING (mode))
    3301                 :    37849422 :           && !HONOR_SNANS (mode)
    3302                 :    75699986 :           && trueop1 == CONST0_RTX (mode))
    3303                 :             :         return op0;
    3304                 :             : 
    3305                 :             :       /* See if this is something like X * C - X or vice versa or
    3306                 :             :          if the multiplication is written as a shift.  If so, we can
    3307                 :             :          distribute and make a new multiply, shift, or maybe just
    3308                 :             :          have X (if C is 2 in the example above).  But don't make
    3309                 :             :          something more expensive than we had before.  */
    3310                 :             : 
    3311                 :    36850244 :       if (is_a <scalar_int_mode> (mode, &int_mode))
    3312                 :             :         {
    3313                 :    35689757 :           rtx lhs = op0, rhs = op1;
    3314                 :             : 
    3315                 :    35689757 :           wide_int coeff0 = wi::one (GET_MODE_PRECISION (int_mode));
    3316                 :    35689757 :           wide_int negcoeff1 = wi::minus_one (GET_MODE_PRECISION (int_mode));
    3317                 :             : 
    3318                 :    35689757 :           if (GET_CODE (lhs) == NEG)
    3319                 :             :             {
    3320                 :      106051 :               coeff0 = wi::minus_one (GET_MODE_PRECISION (int_mode));
    3321                 :      106051 :               lhs = XEXP (lhs, 0);
    3322                 :             :             }
    3323                 :    35583706 :           else if (GET_CODE (lhs) == MULT
    3324                 :      191234 :                    && CONST_SCALAR_INT_P (XEXP (lhs, 1)))
    3325                 :             :             {
    3326                 :       75621 :               coeff0 = rtx_mode_t (XEXP (lhs, 1), int_mode);
    3327                 :       75621 :               lhs = XEXP (lhs, 0);
    3328                 :             :             }
    3329                 :    35508085 :           else if (GET_CODE (lhs) == ASHIFT
    3330                 :      290762 :                    && CONST_INT_P (XEXP (lhs, 1))
    3331                 :      287687 :                    && INTVAL (XEXP (lhs, 1)) >= 0
    3332                 :    35795751 :                    && INTVAL (XEXP (lhs, 1)) < GET_MODE_PRECISION (int_mode))
    3333                 :             :             {
    3334                 :      287666 :               coeff0 = wi::set_bit_in_zero (INTVAL (XEXP (lhs, 1)),
    3335                 :      575332 :                                             GET_MODE_PRECISION (int_mode));
    3336                 :      287666 :               lhs = XEXP (lhs, 0);
    3337                 :             :             }
    3338                 :             : 
    3339                 :    35689757 :           if (GET_CODE (rhs) == NEG)
    3340                 :             :             {
    3341                 :        7000 :               negcoeff1 = wi::one (GET_MODE_PRECISION (int_mode));
    3342                 :        7000 :               rhs = XEXP (rhs, 0);
    3343                 :             :             }
    3344                 :    35682757 :           else if (GET_CODE (rhs) == MULT
    3345                 :      193949 :                    && CONST_INT_P (XEXP (rhs, 1)))
    3346                 :             :             {
    3347                 :      162219 :               negcoeff1 = wi::neg (rtx_mode_t (XEXP (rhs, 1), int_mode));
    3348                 :      162219 :               rhs = XEXP (rhs, 0);
    3349                 :             :             }
    3350                 :    35520538 :           else if (GET_CODE (rhs) == ASHIFT
    3351                 :      353436 :                    && CONST_INT_P (XEXP (rhs, 1))
    3352                 :      352998 :                    && INTVAL (XEXP (rhs, 1)) >= 0
    3353                 :    35873536 :                    && INTVAL (XEXP (rhs, 1)) < GET_MODE_PRECISION (int_mode))
    3354                 :             :             {
    3355                 :      352998 :               negcoeff1 = wi::set_bit_in_zero (INTVAL (XEXP (rhs, 1)),
    3356                 :      705996 :                                                GET_MODE_PRECISION (int_mode));
    3357                 :      352998 :               negcoeff1 = -negcoeff1;
    3358                 :      352998 :               rhs = XEXP (rhs, 0);
    3359                 :             :             }
    3360                 :             : 
    3361                 :    35689757 :           if (rtx_equal_p (lhs, rhs))
    3362                 :             :             {
    3363                 :      120271 :               rtx orig = gen_rtx_MINUS (int_mode, op0, op1);
    3364                 :      120271 :               rtx coeff;
    3365                 :      120271 :               bool speed = optimize_function_for_speed_p (cfun);
    3366                 :             : 
    3367                 :      120271 :               coeff = immed_wide_int_const (coeff0 + negcoeff1, int_mode);
    3368                 :             : 
    3369                 :      120271 :               tem = simplify_gen_binary (MULT, int_mode, lhs, coeff);
    3370                 :      120271 :               return (set_src_cost (tem, int_mode, speed)
    3371                 :      120271 :                       <= set_src_cost (orig, int_mode, speed) ? tem : 0);
    3372                 :             :             }
    3373                 :             : 
    3374                 :             :           /* Optimize (X + 1) * Y - Y to X * Y.  */
    3375                 :    35569486 :           lhs = op0;
    3376                 :    35569486 :           if (GET_CODE (op0) == MULT)
    3377                 :             :             {
    3378                 :      191107 :               if (((GET_CODE (XEXP (op0, 0)) == PLUS
    3379                 :        4290 :                     && XEXP (XEXP (op0, 0), 1) == const1_rtx)
    3380                 :      189779 :                    || (GET_CODE (XEXP (op0, 0)) == MINUS
    3381                 :        3515 :                        && XEXP (XEXP (op0, 0), 1) == constm1_rtx))
    3382                 :      192435 :                   && rtx_equal_p (XEXP (op0, 1), op1))
    3383                 :          16 :                 lhs = XEXP (XEXP (op0, 0), 0);
    3384                 :      191091 :               else if (((GET_CODE (XEXP (op0, 1)) == PLUS
    3385                 :          12 :                          && XEXP (XEXP (op0, 1), 1) == const1_rtx)
    3386                 :      191087 :                         || (GET_CODE (XEXP (op0, 1)) == MINUS
    3387                 :          46 :                             && XEXP (XEXP (op0, 1), 1) == constm1_rtx))
    3388                 :      191095 :                        && rtx_equal_p (XEXP (op0, 0), op1))
    3389                 :           0 :                 lhs = XEXP (XEXP (op0, 1), 0);
    3390                 :             :             }
    3391                 :    35569486 :           if (lhs != op0)
    3392                 :          16 :             return simplify_gen_binary (MULT, int_mode, lhs, op1);
    3393                 :    35689757 :         }
    3394                 :             : 
    3395                 :             :       /* (a - (-b)) -> (a + b).  True even for IEEE.  */
    3396                 :    36729957 :       if (GET_CODE (op1) == NEG)
    3397                 :        6970 :         return simplify_gen_binary (PLUS, mode, op0, XEXP (op1, 0));
    3398                 :             : 
    3399                 :             :       /* (-x - c) may be simplified as (-c - x).  */
    3400                 :    36722987 :       if (GET_CODE (op0) == NEG
    3401                 :      110209 :           && (CONST_SCALAR_INT_P (op1) || CONST_DOUBLE_AS_FLOAT_P (op1)))
    3402                 :             :         {
    3403                 :         492 :           tem = simplify_unary_operation (NEG, mode, op1, mode);
    3404                 :         492 :           if (tem)
    3405                 :         492 :             return simplify_gen_binary (MINUS, mode, tem, XEXP (op0, 0));
    3406                 :             :         }
    3407                 :             : 
    3408                 :    36722495 :       if ((GET_CODE (op0) == CONST
    3409                 :    36722495 :            || GET_CODE (op0) == SYMBOL_REF
    3410                 :    31863290 :            || GET_CODE (op0) == LABEL_REF)
    3411                 :    36722495 :           && poly_int_rtx_p (op1, &offset))
    3412                 :       40277 :         return plus_constant (mode, op0, trunc_int_for_mode (-offset, mode));
    3413                 :             : 
    3414                 :             :       /* Don't let a relocatable value get a negative coeff.  */
    3415                 :    36682218 :       if (poly_int_rtx_p (op1) && GET_MODE (op0) != VOIDmode)
    3416                 :     6792507 :         return simplify_gen_binary (PLUS, mode,
    3417                 :             :                                     op0,
    3418                 :     6792507 :                                     neg_poly_int_rtx (mode, op1));
    3419                 :             : 
    3420                 :             :       /* (x - (x & y)) -> (x & ~y) */
    3421                 :    29889711 :       if (INTEGRAL_MODE_P (mode) && GET_CODE (op1) == AND)
    3422                 :             :         {
    3423                 :      382503 :           if (rtx_equal_p (op0, XEXP (op1, 0)))
    3424                 :             :             {
    3425                 :        6404 :               tem = simplify_gen_unary (NOT, mode, XEXP (op1, 1),
    3426                 :        3202 :                                         GET_MODE (XEXP (op1, 1)));
    3427                 :        3202 :               return simplify_gen_binary (AND, mode, op0, tem);
    3428                 :             :             }
    3429                 :      379301 :           if (rtx_equal_p (op0, XEXP (op1, 1)))
    3430                 :             :             {
    3431                 :        3098 :               tem = simplify_gen_unary (NOT, mode, XEXP (op1, 0),
    3432                 :        1549 :                                         GET_MODE (XEXP (op1, 0)));
    3433                 :        1549 :               return simplify_gen_binary (AND, mode, op0, tem);
    3434                 :             :             }
    3435                 :             :         }
    3436                 :             : 
    3437                 :             :       /* If STORE_FLAG_VALUE is 1, (minus 1 (comparison foo bar)) can be done
    3438                 :             :          by reversing the comparison code if valid.  */
    3439                 :    29884960 :       if (STORE_FLAG_VALUE == 1
    3440                 :    29884960 :           && trueop0 == const1_rtx
    3441                 :     1001100 :           && COMPARISON_P (op1)
    3442                 :    29964685 :           && (reversed = reversed_comparison (op1, mode)))
    3443                 :             :         return reversed;
    3444                 :             : 
    3445                 :             :       /* Canonicalize (minus A (mult (neg B) C)) to (plus (mult B C) A).  */
    3446                 :    29805258 :       if (!HONOR_SIGN_DEPENDENT_ROUNDING (mode)
    3447                 :    29803880 :           && GET_CODE (op1) == MULT
    3448                 :    30092929 :           && GET_CODE (XEXP (op1, 0)) == NEG)
    3449                 :             :         {
    3450                 :         168 :           rtx in1, in2;
    3451                 :             : 
    3452                 :         168 :           in1 = XEXP (XEXP (op1, 0), 0);
    3453                 :         168 :           in2 = XEXP (op1, 1);
    3454                 :         168 :           return simplify_gen_binary (PLUS, mode,
    3455                 :             :                                       simplify_gen_binary (MULT, mode,
    3456                 :             :                                                            in1, in2),
    3457                 :         168 :                                       op0);
    3458                 :             :         }
    3459                 :             : 
    3460                 :             :       /* Canonicalize (minus (neg A) (mult B C)) to
    3461                 :             :          (minus (mult (neg B) C) A).  */
    3462                 :    29805090 :       if (!HONOR_SIGN_DEPENDENT_ROUNDING (mode)
    3463                 :    29803712 :           && GET_CODE (op1) == MULT
    3464                 :    30092593 :           && GET_CODE (op0) == NEG)
    3465                 :             :         {
    3466                 :         683 :           rtx in1, in2;
    3467                 :             : 
    3468                 :         683 :           in1 = simplify_gen_unary (NEG, mode, XEXP (op1, 0), mode);
    3469                 :         683 :           in2 = XEXP (op1, 1);
    3470                 :         683 :           return simplify_gen_binary (MINUS, mode,
    3471                 :             :                                       simplify_gen_binary (MULT, mode,
    3472                 :             :                                                            in1, in2),
    3473                 :         683 :                                       XEXP (op0, 0));
    3474                 :             :         }
    3475                 :             : 
    3476                 :             :       /* If one of the operands is a PLUS or a MINUS, see if we can
    3477                 :             :          simplify this by the associative law.  This will, for example,
    3478                 :             :          canonicalize (minus A (plus B C)) to (minus (minus A B) C).
    3479                 :             :          Don't use the associative law for floating point.
    3480                 :             :          The inaccuracy makes it nonassociative,
    3481                 :             :          and subtle programs can break if operations are associated.  */
    3482                 :             : 
    3483                 :    29804407 :       if (INTEGRAL_MODE_P (mode)
    3484                 :    29016701 :           && (plus_minus_operand_p (op0)
    3485                 :    26812985 :               || plus_minus_operand_p (op1))
    3486                 :     3333478 :           && (tem = simplify_plus_minus (code, mode, op0, op1)) != 0)
    3487                 :             :         return tem;
    3488                 :             : 
    3489                 :             :       /* Handle vector series.  */
    3490                 :    26588513 :       if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
    3491                 :             :         {
    3492                 :      353548 :           tem = simplify_binary_operation_series (code, mode, op0, op1);
    3493                 :      353548 :           if (tem)
    3494                 :             :             return tem;
    3495                 :             :         }
    3496                 :             :       break;
    3497                 :             : 
    3498                 :    11961516 :     case MULT:
    3499                 :    11961516 :       if (trueop1 == constm1_rtx)
    3500                 :       29363 :         return simplify_gen_unary (NEG, mode, op0, mode);
    3501                 :             : 
    3502                 :    11932153 :       if (GET_CODE (op0) == NEG)
    3503                 :             :         {
    3504                 :       32920 :           rtx temp = simplify_unary_operation (NEG, mode, op1, mode);
    3505                 :             :           /* If op1 is a MULT as well and simplify_unary_operation
    3506                 :             :              just moved the NEG to the second operand, simplify_gen_binary
    3507                 :             :              below could through simplify_associative_operation move
    3508                 :             :              the NEG around again and recurse endlessly.  */
    3509                 :       32920 :           if (temp
    3510                 :        1472 :               && GET_CODE (op1) == MULT
    3511                 :           0 :               && GET_CODE (temp) == MULT
    3512                 :           0 :               && XEXP (op1, 0) == XEXP (temp, 0)
    3513                 :           0 :               && GET_CODE (XEXP (temp, 1)) == NEG
    3514                 :           0 :               && XEXP (op1, 1) == XEXP (XEXP (temp, 1), 0))
    3515                 :             :             temp = NULL_RTX;
    3516                 :             :           if (temp)
    3517                 :        1472 :             return simplify_gen_binary (MULT, mode, XEXP (op0, 0), temp);
    3518                 :             :         }
    3519                 :    11930681 :       if (GET_CODE (op1) == NEG)
    3520                 :             :         {
    3521                 :         887 :           rtx temp = simplify_unary_operation (NEG, mode, op0, mode);
    3522                 :             :           /* If op0 is a MULT as well and simplify_unary_operation
    3523                 :             :              just moved the NEG to the second operand, simplify_gen_binary
    3524                 :             :              below could through simplify_associative_operation move
    3525                 :             :              the NEG around again and recurse endlessly.  */
    3526                 :         887 :           if (temp
    3527                 :         386 :               && GET_CODE (op0) == MULT
    3528                 :         305 :               && GET_CODE (temp) == MULT
    3529                 :         305 :               && XEXP (op0, 0) == XEXP (temp, 0)
    3530                 :           6 :               && GET_CODE (XEXP (temp, 1)) == NEG
    3531                 :           5 :               && XEXP (op0, 1) == XEXP (XEXP (temp, 1), 0))
    3532                 :             :             temp = NULL_RTX;
    3533                 :             :           if (temp)
    3534                 :         381 :             return simplify_gen_binary (MULT, mode, temp, XEXP (op1, 0));
    3535                 :             :         }
    3536                 :             : 
    3537                 :             :       /* Maybe simplify x * 0 to 0.  The reduction is not valid if
    3538                 :             :          x is NaN, since x * 0 is then also NaN.  Nor is it valid
    3539                 :             :          when the mode has signed zeros, since multiplying a negative
    3540                 :             :          number by 0 will give -0, not 0.  */
    3541                 :    11930300 :       if (!HONOR_NANS (mode)
    3542                 :    10985859 :           && !HONOR_SIGNED_ZEROS (mode)
    3543                 :    10985463 :           && trueop1 == CONST0_RTX (mode)
    3544                 :    11988858 :           && ! side_effects_p (op0))
    3545                 :             :         return op1;
    3546                 :             : 
    3547                 :             :       /* In IEEE floating point, x*1 is not equivalent to x for
    3548                 :             :          signalling NaNs.  */
    3549                 :    11872761 :       if (!HONOR_SNANS (mode)
    3550                 :    11872761 :           && trueop1 == CONST1_RTX (mode))
    3551                 :             :         return op0;
    3552                 :             : 
    3553                 :             :       /* Convert multiply by constant power of two into shift.  */
    3554                 :    11362196 :       if (mem_depth == 0 && CONST_SCALAR_INT_P (trueop1))
    3555                 :             :         {
    3556                 :     6286994 :           val = wi::exact_log2 (rtx_mode_t (trueop1, mode));
    3557                 :     6286994 :           if (val >= 0)
    3558                 :     2768869 :             return simplify_gen_binary (ASHIFT, mode, op0,
    3559                 :     2768869 :                                         gen_int_shift_amount (mode, val));
    3560                 :             :         }
    3561                 :             : 
    3562                 :             :       /* x*2 is x+x and x*(-1) is -x */
    3563                 :     8593327 :       if (CONST_DOUBLE_AS_FLOAT_P (trueop1)
    3564                 :      166388 :           && SCALAR_FLOAT_MODE_P (GET_MODE (trueop1))
    3565                 :      166388 :           && !DECIMAL_FLOAT_MODE_P (GET_MODE (trueop1))
    3566                 :      166110 :           && GET_MODE (op0) == mode)
    3567                 :             :         {
    3568                 :      166110 :           const REAL_VALUE_TYPE *d1 = CONST_DOUBLE_REAL_VALUE (trueop1);
    3569                 :             : 
    3570                 :      166110 :           if (real_equal (d1, &dconst2))
    3571                 :         688 :             return simplify_gen_binary (PLUS, mode, op0, copy_rtx (op0));
    3572                 :             : 
    3573                 :      165422 :           if (!HONOR_SNANS (mode)
    3574                 :      165422 :               && real_equal (d1, &dconstm1))
    3575                 :          22 :             return simplify_gen_unary (NEG, mode, op0, mode);
    3576                 :             :         }
    3577                 :             : 
    3578                 :             :       /* Optimize -x * -x as x * x.  */
    3579                 :     8592617 :       if (FLOAT_MODE_P (mode)
    3580                 :     1351304 :           && GET_CODE (op0) == NEG
    3581                 :        7881 :           && GET_CODE (op1) == NEG
    3582                 :           0 :           && rtx_equal_p (XEXP (op0, 0), XEXP (op1, 0))
    3583                 :           0 :           && !side_effects_p (XEXP (op0, 0)))
    3584                 :           0 :         return simplify_gen_binary (MULT, mode, XEXP (op0, 0), XEXP (op1, 0));
    3585                 :             : 
    3586                 :             :       /* Likewise, optimize abs(x) * abs(x) as x * x.  */
    3587                 :     8592617 :       if (SCALAR_FLOAT_MODE_P (mode)
    3588                 :     1101643 :           && GET_CODE (op0) == ABS
    3589                 :        1375 :           && GET_CODE (op1) == ABS
    3590                 :           0 :           && rtx_equal_p (XEXP (op0, 0), XEXP (op1, 0))
    3591                 :     8592617 :           && !side_effects_p (XEXP (op0, 0)))
    3592                 :           0 :         return simplify_gen_binary (MULT, mode, XEXP (op0, 0), XEXP (op1, 0));
    3593                 :             : 
    3594                 :             :       /* Reassociate multiplication, but for floating point MULTs
    3595                 :             :          only when the user specifies unsafe math optimizations.  */
    3596                 :     8592617 :       if (! FLOAT_MODE_P (mode)
    3597                 :     1351304 :           || flag_unsafe_math_optimizations)
    3598                 :             :         {
    3599                 :     7649404 :           tem = simplify_associative_operation (code, mode, op0, op1);
    3600                 :     7649404 :           if (tem)
    3601                 :             :             return tem;
    3602                 :             :         }
    3603                 :             :       break;
    3604                 :             : 
    3605                 :    15042218 :     case IOR:
    3606                 :    15042218 :       if (trueop1 == CONST0_RTX (mode))
    3607                 :             :         return op0;
    3608                 :    14282295 :       if (INTEGRAL_MODE_P (mode)
    3609                 :    14077005 :           && trueop1 == CONSTM1_RTX (mode)
    3610                 :        4959 :           && !side_effects_p (op0))
    3611                 :             :         return op1;
    3612                 :    14277336 :       if (rtx_equal_p (trueop0, trueop1) && ! side_effects_p (op0))
    3613                 :             :         return op0;
    3614                 :             :       /* A | (~A) -> -1 */
    3615                 :       69155 :       if (((GET_CODE (op0) == NOT && rtx_equal_p (XEXP (op0, 0), op1))
    3616                 :    14260788 :            || (GET_CODE (op1) == NOT && rtx_equal_p (XEXP (op1, 0), op0)))
    3617                 :           8 :           && ! side_effects_p (op0)
    3618                 :    14260804 :           && GET_MODE_CLASS (mode) != MODE_CC)
    3619                 :           8 :         return CONSTM1_RTX (mode);
    3620                 :             : 
    3621                 :             :       /* Convert (ior (plus (A - 1)) (neg A)) to -1.  */
    3622                 :    14260788 :       if (match_plus_neg_pattern (op0, op1, mode))
    3623                 :           0 :         return CONSTM1_RTX (mode);
    3624                 :             : 
    3625                 :             :       /* (ior A C) is C if all bits of A that might be nonzero are on in C.  */
    3626                 :    14260788 :       if (CONST_INT_P (op1)
    3627                 :     3492348 :           && HWI_COMPUTABLE_MODE_P (mode)
    3628                 :     3462093 :           && (nonzero_bits (op0, mode) & ~UINTVAL (op1)) == 0
    3629                 :    14599125 :           && !side_effects_p (op0))
    3630                 :             :         return op1;
    3631                 :             : 
    3632                 :             :       /* Canonicalize (X & C1) | C2.  */
    3633                 :    13922451 :       if (GET_CODE (op0) == AND
    3634                 :     4019131 :           && CONST_INT_P (trueop1)
    3635                 :      612975 :           && CONST_INT_P (XEXP (op0, 1)))
    3636                 :             :         {
    3637                 :      487510 :           HOST_WIDE_INT mask = GET_MODE_MASK (mode);
    3638                 :      487510 :           HOST_WIDE_INT c1 = INTVAL (XEXP (op0, 1));
    3639                 :      487510 :           HOST_WIDE_INT c2 = INTVAL (trueop1);
    3640                 :             : 
    3641                 :             :           /* If (C1&C2) == C1, then (X&C1)|C2 becomes C2.  */
    3642                 :      487510 :           if ((c1 & c2) == c1
    3643                 :      487510 :               && !side_effects_p (XEXP (op0, 0)))
    3644                 :             :             return trueop1;
    3645                 :             : 
    3646                 :             :           /* If (C1|C2) == ~0 then (X&C1)|C2 becomes X|C2.  */
    3647                 :      487510 :           if (((c1|c2) & mask) == mask)
    3648                 :       61625 :             return simplify_gen_binary (IOR, mode, XEXP (op0, 0), op1);
    3649                 :             :         }
    3650                 :             : 
    3651                 :             :       /* Convert (A & B) | A to A.  */
    3652                 :    13860826 :       if (GET_CODE (op0) == AND
    3653                 :     3957506 :           && (rtx_equal_p (XEXP (op0, 0), op1)
    3654                 :     3957388 :               || rtx_equal_p (XEXP (op0, 1), op1))
    3655                 :        3681 :           && ! side_effects_p (XEXP (op0, 0))
    3656                 :    13864507 :           && ! side_effects_p (XEXP (op0, 1)))
    3657                 :             :         return op1;
    3658                 :             : 
    3659                 :             :       /* Convert (ior (ashift A CX) (lshiftrt A CY)) where CX+CY equals the
    3660                 :             :          mode size to (rotate A CX).  */
    3661                 :    13857145 :       tem = simplify_rotate_op (op0, op1, mode);
    3662                 :    13857145 :       if (tem)
    3663                 :             :         return tem;
    3664                 :             : 
    3665                 :             :       /* If OP0 is (ashiftrt (plus ...) C), it might actually be
    3666                 :             :          a (sign_extend (plus ...)).  Then check if OP1 is a CONST_INT and
    3667                 :             :          the PLUS does not affect any of the bits in OP1: then we can do
    3668                 :             :          the IOR as a PLUS and we can associate.  This is valid if OP1
    3669                 :             :          can be safely shifted left C bits.  */
    3670                 :    13854594 :       if (CONST_INT_P (trueop1) && GET_CODE (op0) == ASHIFTRT
    3671                 :        7552 :           && GET_CODE (XEXP (op0, 0)) == PLUS
    3672                 :         141 :           && CONST_INT_P (XEXP (XEXP (op0, 0), 1))
    3673                 :          87 :           && CONST_INT_P (XEXP (op0, 1))
    3674                 :          87 :           && INTVAL (XEXP (op0, 1)) < HOST_BITS_PER_WIDE_INT)
    3675                 :             :         {
    3676                 :          87 :           int count = INTVAL (XEXP (op0, 1));
    3677                 :          87 :           HOST_WIDE_INT mask = UINTVAL (trueop1) << count;
    3678                 :             : 
    3679                 :          87 :           if (mask >> count == INTVAL (trueop1)
    3680                 :          80 :               && trunc_int_for_mode (mask, mode) == mask
    3681                 :         154 :               && (mask & nonzero_bits (XEXP (op0, 0), mode)) == 0)
    3682                 :           0 :             return simplify_gen_binary (ASHIFTRT, mode,
    3683                 :           0 :                                         plus_constant (mode, XEXP (op0, 0),
    3684                 :             :                                                        mask),
    3685                 :             :                                         XEXP (op0, 1));
    3686                 :             :         }
    3687                 :             : 
    3688                 :             :       /* The following happens with bitfield merging.
    3689                 :             :          (X & C) | ((X | Y) & ~C) -> X | (Y & ~C) */
    3690                 :    13854594 :       if (GET_CODE (op0) == AND
    3691                 :     3953825 :           && GET_CODE (op1) == AND
    3692                 :      277182 :           && CONST_INT_P (XEXP (op0, 1))
    3693                 :      120744 :           && CONST_INT_P (XEXP (op1, 1))
    3694                 :      115073 :           && (INTVAL (XEXP (op0, 1))
    3695                 :      115073 :               == ~INTVAL (XEXP (op1, 1))))
    3696                 :             :         {
    3697                 :             :           /* The IOR may be on both sides.  */
    3698                 :       29600 :           rtx top0 = NULL_RTX, top1 = NULL_RTX;
    3699                 :       29600 :           if (GET_CODE (XEXP (op1, 0)) == IOR)
    3700                 :             :             top0 = op0, top1 = op1;
    3701                 :       29554 :           else if (GET_CODE (XEXP (op0, 0)) == IOR)
    3702                 :           0 :             top0 = op1, top1 = op0;
    3703                 :       29600 :           if (top0 && top1)
    3704                 :             :             {
    3705                 :             :               /* X may be on either side of the inner IOR.  */
    3706                 :          46 :               rtx tem = NULL_RTX;
    3707                 :          46 :               if (rtx_equal_p (XEXP (top0, 0),
    3708                 :          46 :                                XEXP (XEXP (top1, 0), 0)))
    3709                 :          43 :                 tem = XEXP (XEXP (top1, 0), 1);
    3710                 :           3 :               else if (rtx_equal_p (XEXP (top0, 0),
    3711                 :           3 :                                     XEXP (XEXP (top1, 0), 1)))
    3712                 :           3 :                 tem = XEXP (XEXP (top1, 0), 0);
    3713                 :          46 :               if (tem)
    3714                 :          46 :                 return simplify_gen_binary (IOR, mode, XEXP (top0, 0),
    3715                 :             :                                             simplify_gen_binary
    3716                 :          46 :                                               (AND, mode, tem, XEXP (top1, 1)));
    3717                 :             :             }
    3718                 :             :         }
    3719                 :             : 
    3720                 :             :       /* Convert (ior (and A C) (and B C)) into (and (ior A B) C).  */
    3721                 :    13854548 :       if (GET_CODE (op0) == GET_CODE (op1)
    3722                 :     3359966 :           && (GET_CODE (op0) == AND
    3723                 :             :               || GET_CODE (op0) == IOR
    3724                 :     3359966 :               || GET_CODE (op0) == LSHIFTRT
    3725                 :     3082084 :               || GET_CODE (op0) == ASHIFTRT
    3726                 :     3081991 :               || GET_CODE (op0) == ASHIFT
    3727                 :     3059402 :               || GET_CODE (op0) == ROTATE
    3728                 :     3059402 :               || GET_CODE (op0) == ROTATERT))
    3729                 :             :         {
    3730                 :      300564 :           tem = simplify_distributive_operation (code, mode, op0, op1);
    3731                 :      300564 :           if (tem)
    3732                 :             :             return tem;
    3733                 :             :         }
    3734                 :             : 
    3735                 :             :       /* Convert (ior (and (not A) B) A) into A | B.  */
    3736                 :    13769015 :       if (GET_CODE (op0) == AND
    3737                 :     3868377 :           && GET_CODE (XEXP (op0, 0)) == NOT
    3738                 :    13909817 :           && rtx_equal_p (XEXP (XEXP (op0, 0), 0), op1))
    3739                 :        3027 :         return simplify_gen_binary (IOR, mode, XEXP (op0, 1), op1);
    3740                 :             : 
    3741                 :    13765988 :       tem = simplify_byte_swapping_operation (code, mode, op0, op1);
    3742                 :    13765988 :       if (tem)
    3743                 :             :         return tem;
    3744                 :             : 
    3745                 :    13765959 :       tem = simplify_associative_operation (code, mode, op0, op1);
    3746                 :    13765959 :       if (tem)
    3747                 :             :         return tem;
    3748                 :             : 
    3749                 :    13539809 :       tem = simplify_logical_relational_operation (code, mode, op0, op1);
    3750                 :    13539809 :       if (tem)
    3751                 :             :         return tem;
    3752                 :             :       break;
    3753                 :             : 
    3754                 :     1424492 :     case XOR:
    3755                 :     1424492 :       if (trueop1 == CONST0_RTX (mode))
    3756                 :             :         return op0;
    3757                 :     1377298 :       if (INTEGRAL_MODE_P (mode) && trueop1 == CONSTM1_RTX (mode))
    3758                 :       23412 :         return simplify_gen_unary (NOT, mode, op0, mode);
    3759                 :     1353886 :       if (rtx_equal_p (trueop0, trueop1)
    3760                 :        2465 :           && ! side_effects_p (op0)
    3761                 :     1356351 :           && GET_MODE_CLASS (mode) != MODE_CC)
    3762                 :        2465 :          return CONST0_RTX (mode);
    3763                 :             : 
    3764                 :             :       /* Canonicalize XOR of the most significant bit to PLUS.  */
    3765                 :     1351421 :       if (CONST_SCALAR_INT_P (op1)
    3766                 :     1351421 :           && mode_signbit_p (mode, op1))
    3767                 :       38877 :         return simplify_gen_binary (PLUS, mode, op0, op1);
    3768                 :             :       /* (xor (plus X C1) C2) is (xor X (C1^C2)) if C1 is signbit.  */
    3769                 :     1312544 :       if (CONST_SCALAR_INT_P (op1)
    3770                 :      452353 :           && GET_CODE (op0) == PLUS
    3771                 :        2474 :           && CONST_SCALAR_INT_P (XEXP (op0, 1))
    3772                 :     1314101 :           && mode_signbit_p (mode, XEXP (op0, 1)))
    3773                 :         188 :         return simplify_gen_binary (XOR, mode, XEXP (op0, 0),
    3774                 :             :                                     simplify_gen_binary (XOR, mode, op1,
    3775                 :         188 :                                                          XEXP (op0, 1)));
    3776                 :             : 
    3777                 :             :       /* If we are XORing two things that have no bits in common,
    3778                 :             :          convert them into an IOR.  This helps to detect rotation encoded
    3779                 :             :          using those methods and possibly other simplifications.  */
    3780                 :             : 
    3781                 :     1312356 :       if (HWI_COMPUTABLE_MODE_P (mode)
    3782                 :     1150554 :           && (nonzero_bits (op0, mode)
    3783                 :     1150554 :               & nonzero_bits (op1, mode)) == 0)
    3784                 :        8409 :         return (simplify_gen_binary (IOR, mode, op0, op1));
    3785                 :             : 
    3786                 :             :       /* Convert (xor (plus (A - 1)) (neg A)) to -1.  */
    3787                 :     1303947 :       if (match_plus_neg_pattern (op0, op1, mode))
    3788                 :           0 :         return CONSTM1_RTX (mode);
    3789                 :             : 
    3790                 :             :       /* Convert (XOR (NOT x) (NOT y)) to (XOR x y).
    3791                 :             :          Also convert (XOR (NOT x) y) to (NOT (XOR x y)), similarly for
    3792                 :             :          (NOT y).  */
    3793                 :     1303947 :       {
    3794                 :     1303947 :         int num_negated = 0;
    3795                 :             : 
    3796                 :     1303947 :         if (GET_CODE (op0) == NOT)
    3797                 :         796 :           num_negated++, op0 = XEXP (op0, 0);
    3798                 :     1303947 :         if (GET_CODE (op1) == NOT)
    3799                 :           0 :           num_negated++, op1 = XEXP (op1, 0);
    3800                 :             : 
    3801                 :           0 :         if (num_negated == 2)
    3802                 :           0 :           return simplify_gen_binary (XOR, mode, op0, op1);
    3803                 :     1303947 :         else if (num_negated == 1)
    3804                 :         796 :           return simplify_gen_unary (NOT, mode,
    3805                 :             :                                      simplify_gen_binary (XOR, mode, op0, op1),
    3806                 :         796 :                                      mode);
    3807                 :             :       }
    3808                 :             : 
    3809                 :             :       /* Convert (xor (and A B) B) to (and (not A) B).  The latter may
    3810                 :             :          correspond to a machine insn or result in further simplifications
    3811                 :             :          if B is a constant.  */
    3812                 :             : 
    3813                 :     1303151 :       if (GET_CODE (op0) == AND
    3814                 :      128053 :           && rtx_equal_p (XEXP (op0, 1), op1)
    3815                 :     1317623 :           && ! side_effects_p (op1))
    3816                 :       14472 :         return simplify_gen_binary (AND, mode,
    3817                 :             :                                     simplify_gen_unary (NOT, mode,
    3818                 :             :                                                         XEXP (op0, 0), mode),
    3819                 :       14472 :                                     op1);
    3820                 :             : 
    3821                 :     1288679 :       else if (GET_CODE (op0) == AND
    3822                 :      113581 :                && rtx_equal_p (XEXP (op0, 0), op1)
    3823                 :     1290128 :                && ! side_effects_p (op1))
    3824                 :        1449 :         return simplify_gen_binary (AND, mode,
    3825                 :             :                                     simplify_gen_unary (NOT, mode,
    3826                 :             :                                                         XEXP (op0, 1), mode),
    3827                 :        1449 :                                     op1);
    3828                 :             : 
    3829                 :             :       /* Given (xor (ior (xor A B) C) D), where B, C and D are
    3830                 :             :          constants, simplify to (xor (ior A C) (B&~C)^D), canceling
    3831                 :             :          out bits inverted twice and not set by C.  Similarly, given
    3832                 :             :          (xor (and (xor A B) C) D), simplify without inverting C in
    3833                 :             :          the xor operand: (xor (and A C) (B&C)^D).
    3834                 :             :       */
    3835                 :     1287230 :       else if ((GET_CODE (op0) == IOR || GET_CODE (op0) == AND)
    3836                 :      129984 :                && GET_CODE (XEXP (op0, 0)) == XOR
    3837                 :        5696 :                && CONST_INT_P (op1)
    3838                 :         135 :                && CONST_INT_P (XEXP (op0, 1))
    3839                 :          90 :                && CONST_INT_P (XEXP (XEXP (op0, 0), 1)))
    3840                 :             :         {
    3841                 :          90 :           enum rtx_code op = GET_CODE (op0);
    3842                 :          90 :           rtx a = XEXP (XEXP (op0, 0), 0);
    3843                 :          90 :           rtx b = XEXP (XEXP (op0, 0), 1);
    3844                 :          90 :           rtx c = XEXP (op0, 1);
    3845                 :          90 :           rtx d = op1;
    3846                 :          90 :           HOST_WIDE_INT bval = INTVAL (b);
    3847                 :          90 :           HOST_WIDE_INT cval = INTVAL (c);
    3848                 :          90 :           HOST_WIDE_INT dval = INTVAL (d);
    3849                 :          90 :           HOST_WIDE_INT xcval;
    3850                 :             : 
    3851                 :          90 :           if (op == IOR)
    3852                 :           8 :             xcval = ~cval;
    3853                 :             :           else
    3854                 :             :             xcval = cval;
    3855                 :             : 
    3856                 :          90 :           return simplify_gen_binary (XOR, mode,
    3857                 :             :                                       simplify_gen_binary (op, mode, a, c),
    3858                 :          90 :                                       gen_int_mode ((bval & xcval) ^ dval,
    3859                 :             :                                                     mode));
    3860                 :             :         }
    3861                 :             : 
    3862                 :             :       /* Given (xor (and A B) C), using P^Q == (~P&Q) | (~Q&P),
    3863                 :             :          we can transform like this:
    3864                 :             :             (A&B)^C == ~(A&B)&C | ~C&(A&B)
    3865                 :             :                     == (~A|~B)&C | ~C&(A&B)    * DeMorgan's Law
    3866                 :             :                     == ~A&C | ~B&C | A&(~C&B)  * Distribute and re-order
    3867                 :             :          Attempt a few simplifications when B and C are both constants.  */
    3868                 :     1287140 :       if (GET_CODE (op0) == AND
    3869                 :      112050 :           && CONST_INT_P (op1)
    3870                 :       10659 :           && CONST_INT_P (XEXP (op0, 1)))
    3871                 :             :         {
    3872                 :        8918 :           rtx a = XEXP (op0, 0);
    3873                 :        8918 :           rtx b = XEXP (op0, 1);
    3874                 :        8918 :           rtx c = op1;
    3875                 :        8918 :           HOST_WIDE_INT bval = INTVAL (b);
    3876                 :        8918 :           HOST_WIDE_INT cval = INTVAL (c);
    3877                 :             : 
    3878                 :             :           /* Instead of computing ~A&C, we compute its negated value,
    3879                 :             :              ~(A|~C).  If it yields -1, ~A&C is zero, so we can
    3880                 :             :              optimize for sure.  If it does not simplify, we still try
    3881                 :             :              to compute ~A&C below, but since that always allocates
    3882                 :             :              RTL, we don't try that before committing to returning a
    3883                 :             :              simplified expression.  */
    3884                 :        8918 :           rtx n_na_c = simplify_binary_operation (IOR, mode, a,
    3885                 :             :                                                   GEN_INT (~cval));
    3886                 :             : 
    3887                 :        8918 :           if ((~cval & bval) == 0)
    3888                 :             :             {
    3889                 :         425 :               rtx na_c = NULL_RTX;
    3890                 :         425 :               if (n_na_c)
    3891                 :           0 :                 na_c = simplify_gen_unary (NOT, mode, n_na_c, mode);
    3892                 :             :               else
    3893                 :             :                 {
    3894                 :             :                   /* If ~A does not simplify, don't bother: we don't
    3895                 :             :                      want to simplify 2 operations into 3, and if na_c
    3896                 :             :                      were to simplify with na, n_na_c would have
    3897                 :             :                      simplified as well.  */
    3898                 :         425 :                   rtx na = simplify_unary_operation (NOT, mode, a, mode);
    3899                 :         425 :                   if (na)
    3900                 :           0 :                     na_c = simplify_gen_binary (AND, mode, na, c);
    3901                 :             :                 }
    3902                 :             : 
    3903                 :             :               /* Try to simplify ~A&C | ~B&C.  */
    3904                 :           0 :               if (na_c != NULL_RTX)
    3905                 :           0 :                 return simplify_gen_binary (IOR, mode, na_c,
    3906                 :           0 :                                             gen_int_mode (~bval & cval, mode));
    3907                 :             :             }
    3908                 :             :           else
    3909                 :             :             {
    3910                 :             :               /* If ~A&C is zero, simplify A&(~C&B) | ~B&C.  */
    3911                 :        8493 :               if (n_na_c == CONSTM1_RTX (mode))
    3912                 :             :                 {
    3913                 :           0 :                   rtx a_nc_b = simplify_gen_binary (AND, mode, a,
    3914                 :           0 :                                                     gen_int_mode (~cval & bval,
    3915                 :             :                                                                   mode));
    3916                 :           0 :                   return simplify_gen_binary (IOR, mode, a_nc_b,
    3917                 :           0 :                                               gen_int_mode (~bval & cval,
    3918                 :             :                                                             mode));
    3919                 :             :                 }
    3920                 :             :             }
    3921                 :             :         }
    3922                 :             : 
    3923                 :             :       /* If we have (xor (and (xor A B) C) A) with C a constant we can instead
    3924                 :             :          do (ior (and A ~C) (and B C)) which is a machine instruction on some
    3925                 :             :          machines, and also has shorter instruction path length.  */
    3926                 :     1287140 :       if (GET_CODE (op0) == AND
    3927                 :      112050 :           && GET_CODE (XEXP (op0, 0)) == XOR
    3928                 :        5180 :           && CONST_INT_P (XEXP (op0, 1))
    3929                 :     1289102 :           && rtx_equal_p (XEXP (XEXP (op0, 0), 0), trueop1))
    3930                 :             :         {
    3931                 :           7 :           rtx a = trueop1;
    3932                 :           7 :           rtx b = XEXP (XEXP (op0, 0), 1);
    3933                 :           7 :           rtx c = XEXP (op0, 1);
    3934                 :           7 :           rtx nc = simplify_gen_unary (NOT, mode, c, mode);
    3935                 :           7 :           rtx a_nc = simplify_gen_binary (AND, mode, a, nc);
    3936                 :           7 :           rtx bc = simplify_gen_binary (AND, mode, b, c);
    3937                 :           7 :           return simplify_gen_binary (IOR, mode, a_nc, bc);
    3938                 :             :         }
    3939                 :             :       /* Similarly, (xor (and (xor A B) C) B) as (ior (and A C) (and B ~C))  */
    3940                 :     1287133 :       else if (GET_CODE (op0) == AND
    3941                 :      112043 :           && GET_CODE (XEXP (op0, 0)) == XOR
    3942                 :        5173 :           && CONST_INT_P (XEXP (op0, 1))
    3943                 :     1289088 :           && rtx_equal_p (XEXP (XEXP (op0, 0), 1), trueop1))
    3944                 :             :         {
    3945                 :           8 :           rtx a = XEXP (XEXP (op0, 0), 0);
    3946                 :           8 :           rtx b = trueop1;
    3947                 :           8 :           rtx c = XEXP (op0, 1);
    3948                 :           8 :           rtx nc = simplify_gen_unary (NOT, mode, c, mode);
    3949                 :           8 :           rtx b_nc = simplify_gen_binary (AND, mode, b, nc);
    3950                 :           8 :           rtx ac = simplify_gen_binary (AND, mode, a, c);
    3951                 :           8 :           return simplify_gen_binary (IOR, mode, ac, b_nc);
    3952                 :             :         }
    3953                 :             : 
    3954                 :             :       /* (xor (comparison foo bar) (const_int 1)) can become the reversed
    3955                 :             :          comparison if STORE_FLAG_VALUE is 1.  */
    3956                 :     1287125 :       if (STORE_FLAG_VALUE == 1
    3957                 :     1287125 :           && trueop1 == const1_rtx
    3958                 :      167407 :           && COMPARISON_P (op0)
    3959                 :     1291271 :           && (reversed = reversed_comparison (op0, mode)))
    3960                 :             :         return reversed;
    3961                 :             : 
    3962                 :             :       /* (lshiftrt foo C) where C is the number of bits in FOO minus 1
    3963                 :             :          is (lt foo (const_int 0)), so we can perform the above
    3964                 :             :          simplification if STORE_FLAG_VALUE is 1.  */
    3965                 :             : 
    3966                 :     1283067 :       if (is_a <scalar_int_mode> (mode, &int_mode)
    3967                 :             :           && STORE_FLAG_VALUE == 1
    3968                 :     1125437 :           && trueop1 == const1_rtx
    3969                 :      163349 :           && GET_CODE (op0) == LSHIFTRT
    3970                 :       34531 :           && CONST_INT_P (XEXP (op0, 1))
    3971                 :       34531 :           && INTVAL (XEXP (op0, 1)) == GET_MODE_PRECISION (int_mode) - 1)
    3972                 :       33553 :         return gen_rtx_GE (int_mode, XEXP (op0, 0), const0_rtx);
    3973                 :             : 
    3974                 :             :       /* (xor (comparison foo bar) (const_int sign-bit))
    3975                 :             :          when STORE_FLAG_VALUE is the sign bit.  */
    3976                 :     1249514 :       if (is_a <scalar_int_mode> (mode, &int_mode)
    3977                 :     1091884 :           && val_signbit_p (int_mode, STORE_FLAG_VALUE)
    3978                 :           0 :           && trueop1 == const_true_rtx
    3979                 :           0 :           && COMPARISON_P (op0)
    3980                 :           0 :           && (reversed = reversed_comparison (op0, int_mode)))
    3981                 :             :         return reversed;
    3982                 :             : 
    3983                 :             :       /* Convert (xor (and A C) (and B C)) into (and (xor A B) C).  */
    3984                 :     1249514 :       if (GET_CODE (op0) == GET_CODE (op1)
    3985                 :      372911 :           && (GET_CODE (op0) == AND
    3986                 :      372911 :               || GET_CODE (op0) == LSHIFTRT
    3987                 :      320971 :               || GET_CODE (op0) == ASHIFTRT
    3988                 :      320921 :               || GET_CODE (op0) == ASHIFT
    3989                 :      320761 :               || GET_CODE (op0) == ROTATE
    3990                 :      320664 :               || GET_CODE (op0) == ROTATERT))
    3991                 :             :         {
    3992                 :       52783 :           tem = simplify_distributive_operation (code, mode, op0, op1);
    3993                 :       52783 :           if (tem)
    3994                 :             :             return tem;
    3995                 :             :         }
    3996                 :             : 
    3997                 :             :       /* Convert (xor (ashift A CX) (lshiftrt A CY)) where CX+CY equals the
    3998                 :             :          mode size to (rotate A CX).  */
    3999                 :     1200902 :       tem = simplify_rotate_op (op0, op1, mode);
    4000                 :     1200902 :       if (tem)
    4001                 :             :         return tem;
    4002                 :             : 
    4003                 :             :       /* Convert (xor (and (not A) B) A) into A | B.  */
    4004                 :     1199462 :       if (GET_CODE (op0) == AND
    4005                 :       63690 :           && GET_CODE (XEXP (op0, 0)) == NOT
    4006                 :     1201357 :           && rtx_equal_p (XEXP (XEXP (op0, 0), 0), op1))
    4007                 :           1 :         return simplify_gen_binary (IOR, mode, XEXP (op0, 1), op1);
    4008                 :             : 
    4009                 :     1199461 :       tem = simplify_byte_swapping_operation (code, mode, op0, op1);
    4010                 :     1199461 :       if (tem)
    4011                 :             :         return tem;
    4012                 :             : 
    4013                 :     1199461 :       tem = simplify_associative_operation (code, mode, op0, op1);
    4014                 :     1199461 :       if (tem)
    4015                 :             :         return tem;
    4016                 :             :       break;
    4017                 :             : 
    4018                 :    22885760 :     case AND:
    4019                 :    22885760 :       if (trueop1 == CONST0_RTX (mode) && ! side_effects_p (op0))
    4020                 :             :         return trueop1;
    4021                 :    22663699 :       if (INTEGRAL_MODE_P (mode) && trueop1 == CONSTM1_RTX (mode))
    4022                 :             :         return op0;
    4023                 :    22267631 :       if (HWI_COMPUTABLE_MODE_P (mode))
    4024                 :             :         {
    4025                 :             :           /* When WORD_REGISTER_OPERATIONS is true, we need to know the
    4026                 :             :              nonzero bits in WORD_MODE rather than MODE.  */
    4027                 :    19537649 :           scalar_int_mode tmode = as_a <scalar_int_mode> (mode);
    4028                 :    19537649 :           if (WORD_REGISTER_OPERATIONS
    4029                 :             :               && GET_MODE_BITSIZE (tmode) < BITS_PER_WORD)
    4030                 :             :             tmode = word_mode;
    4031                 :    19537649 :           HOST_WIDE_INT nzop0 = nonzero_bits (trueop0, tmode);
    4032                 :    19537649 :           HOST_WIDE_INT nzop1;
    4033                 :    19537649 :           if (CONST_INT_P (trueop1))
    4034                 :             :             {
    4035                 :    16656161 :               HOST_WIDE_INT val1 = INTVAL (trueop1);
    4036                 :             :               /* If we are turning off bits already known off in OP0, we need
    4037                 :             :                  not do an AND.  */
    4038                 :    16656161 :               if ((nzop0 & ~val1) == 0)
    4039                 :      428444 :                 return op0;
    4040                 :             :             }
    4041                 :    19174010 :           nzop1 = nonzero_bits (trueop1, mode);
    4042                 :             :           /* If we are clearing all the nonzero bits, the result is zero.  */
    4043                 :    19174010 :           if ((nzop1 & nzop0) == 0
    4044                 :    19174010 :               && !side_effects_p (op0) && !side_effects_p (op1))
    4045                 :       64805 :             return CONST0_RTX (mode);
    4046                 :             :         }
    4047                 :    21842473 :       if (rtx_equal_p (trueop0, trueop1) && ! side_effects_p (op0)
    4048                 :    21842473 :           && GET_MODE_CLASS (mode) != MODE_CC)
    4049                 :             :         return op0;
    4050                 :             :       /* A & (~A) -> 0 */
    4051                 :      560663 :       if (((GET_CODE (op0) == NOT && rtx_equal_p (XEXP (op0, 0), op1))
    4052                 :    21831964 :            || (GET_CODE (op1) == NOT && rtx_equal_p (XEXP (op1, 0), op0)))
    4053                 :        3983 :           && ! side_effects_p (op0)
    4054                 :    21839884 :           && GET_MODE_CLASS (mode) != MODE_CC)
    4055                 :        3983 :         return CONST0_RTX (mode);
    4056                 :             : 
    4057                 :             :       /* Convert (and (plus (A - 1)) (neg A)) to 0.  */
    4058                 :    21831918 :       if (match_plus_neg_pattern (op0, op1, mode))
    4059                 :           0 :         return CONST0_RTX (mode);
    4060                 :             : 
    4061                 :             :       /* Transform (and (extend X) C) into (zero_extend (and X C)) if
    4062                 :             :          there are no nonzero bits of C outside of X's mode.  */
    4063                 :    43663836 :       if ((GET_CODE (op0) == SIGN_EXTEND
    4064                 :    21831918 :            || GET_CODE (op0) == ZERO_EXTEND)
    4065                 :       95908 :           && CONST_SCALAR_INT_P (trueop1)
    4066                 :       84116 :           && is_a <scalar_int_mode> (mode, &int_mode)
    4067                 :       84116 :           && is_a <scalar_int_mode> (GET_MODE (XEXP (op0, 0)), &inner_mode)
    4068                 :    21916034 :           && (wi::mask (GET_MODE_PRECISION (inner_mode), true,
    4069                 :       84116 :                         GET_MODE_PRECISION (int_mode))
    4070                 :    21916034 :               & rtx_mode_t (trueop1, mode)) == 0)
    4071                 :             :         {
    4072                 :       81473 :           machine_mode imode = GET_MODE (XEXP (op0, 0));
    4073                 :       81473 :           tem = immed_wide_int_const (rtx_mode_t (trueop1, mode), imode);
    4074                 :       81473 :           tem = simplify_gen_binary (AND, imode, XEXP (op0, 0), tem);
    4075                 :       81473 :           return simplify_gen_unary (ZERO_EXTEND, mode, tem, imode);
    4076                 :             :         }
    4077                 :             : 
    4078                 :             :       /* Transform (and (truncate X) C) into (truncate (and X C)).  This way
    4079                 :             :          we might be able to further simplify the AND with X and potentially
    4080                 :             :          remove the truncation altogether.  */
    4081                 :    21750445 :       if (GET_CODE (op0) == TRUNCATE && CONST_INT_P (trueop1))
    4082                 :             :         {
    4083                 :           6 :           rtx x = XEXP (op0, 0);
    4084                 :           6 :           machine_mode xmode = GET_MODE (x);
    4085                 :           6 :           tem = simplify_gen_binary (AND, xmode, x,
    4086                 :           6 :                                      gen_int_mode (INTVAL (trueop1), xmode));
    4087                 :           6 :           return simplify_gen_unary (TRUNCATE, mode, tem, xmode);
    4088                 :             :         }
    4089                 :             : 
    4090                 :             :       /* Canonicalize (A | C1) & C2 as (A & C2) | (C1 & C2).  */
    4091                 :    21750439 :       if (GET_CODE (op0) == IOR
    4092                 :     1451536 :           && CONST_INT_P (trueop1)
    4093                 :      230043 :           && CONST_INT_P (XEXP (op0, 1)))
    4094                 :             :         {
    4095                 :      137015 :           HOST_WIDE_INT tmp = INTVAL (trueop1) & INTVAL (XEXP (op0, 1));
    4096                 :      137015 :           return simplify_gen_binary (IOR, mode,
    4097                 :             :                                       simplify_gen_binary (AND, mode,
    4098                 :             :                                                            XEXP (op0, 0), op1),
    4099                 :      137015 :                                       gen_int_mode (tmp, mode));
    4100                 :             :         }
    4101                 :             : 
    4102                 :             :       /* Convert (A ^ B) & A to A & (~B) since the latter is often a single
    4103                 :             :          insn (and may simplify more).  */
    4104                 :    21613424 :       if (GET_CODE (op0) == XOR
    4105                 :      108304 :           && rtx_equal_p (XEXP (op0, 0), op1)
    4106                 :    21614560 :           && ! side_effects_p (op1))
    4107                 :        1136 :         return simplify_gen_binary (AND, mode,
    4108                 :             :                                     simplify_gen_unary (NOT, mode,
    4109                 :             :                                                         XEXP (op0, 1), mode),
    4110                 :        1136 :                                     op1);
    4111                 :             : 
    4112                 :    21612288 :       if (GET_CODE (op0) == XOR
    4113                 :      107168 :           && rtx_equal_p (XEXP (op0, 1), op1)
    4114                 :    21614948 :           && ! side_effects_p (op1))
    4115                 :        2660 :         return simplify_gen_binary (AND, mode,
    4116                 :             :                                     simplify_gen_unary (NOT, mode,
    4117                 :             :                                                         XEXP (op0, 0), mode),
    4118                 :        2660 :                                     op1);
    4119                 :             : 
    4120                 :             :       /* Similarly for (~(A ^ B)) & A.  */
    4121                 :    21609628 :       if (GET_CODE (op0) == NOT
    4122                 :      556726 :           && GET_CODE (XEXP (op0, 0)) == XOR
    4123                 :        2816 :           && rtx_equal_p (XEXP (XEXP (op0, 0), 0), op1)
    4124                 :    21609682 :           && ! side_effects_p (op1))
    4125                 :          54 :         return simplify_gen_binary (AND, mode, XEXP (XEXP (op0, 0), 1), op1);
    4126                 :             : 
    4127                 :    21609574 :       if (GET_CODE (op0) == NOT
    4128                 :      556672 :           && GET_CODE (XEXP (op0, 0)) == XOR
    4129                 :        2762 :           && rtx_equal_p (XEXP (XEXP (op0, 0), 1), op1)
    4130                 :    21609611 :           && ! side_effects_p (op1))
    4131                 :          37 :         return simplify_gen_binary (AND, mode, XEXP (XEXP (op0, 0), 0), op1);
    4132                 :             : 
    4133                 :             :       /* Convert (A | B) & A to A.  */
    4134                 :    21609537 :       if (GET_CODE (op0) == IOR
    4135                 :     1314521 :           && (rtx_equal_p (XEXP (op0, 0), op1)
    4136                 :     1313965 :               || rtx_equal_p (XEXP (op0, 1), op1))
    4137                 :         704 :           && ! side_effects_p (XEXP (op0, 0))
    4138                 :    21610241 :           && ! side_effects_p (XEXP (op0, 1)))
    4139                 :             :         return op1;
    4140                 :             : 
    4141                 :             :       /* For constants M and N, if M == (1LL << cst) - 1 && (N & M) == M,
    4142                 :             :          ((A & N) + B) & M -> (A + B) & M
    4143                 :             :          Similarly if (N & M) == 0,
    4144                 :             :          ((A | N) + B) & M -> (A + B) & M
    4145                 :             :          and for - instead of + and/or ^ instead of |.
    4146                 :             :          Also, if (N & M) == 0, then
    4147                 :             :          (A +- N) & M -> A & M.  */
    4148                 :    21608833 :       if (CONST_INT_P (trueop1)
    4149                 :    16112158 :           && HWI_COMPUTABLE_MODE_P (mode)
    4150                 :    16084340 :           && ~UINTVAL (trueop1)
    4151                 :    16084340 :           && (UINTVAL (trueop1) & (UINTVAL (trueop1) + 1)) == 0
    4152                 :    31625763 :           && (GET_CODE (op0) == PLUS || GET_CODE (op0) == MINUS))
    4153                 :             :         {
    4154                 :      896135 :           rtx pmop[2];
    4155                 :      896135 :           int which;
    4156                 :             : 
    4157                 :      896135 :           pmop[0] = XEXP (op0, 0);
    4158                 :      896135 :           pmop[1] = XEXP (op0, 1);
    4159                 :             : 
    4160                 :      896135 :           if (CONST_INT_P (pmop[1])
    4161                 :      469142 :               && (UINTVAL (pmop[1]) & UINTVAL (trueop1)) == 0)
    4162                 :      145522 :             return simplify_gen_binary (AND, mode, pmop[0], op1);
    4163                 :             : 
    4164                 :     2273211 :           for (which = 0; which < 2; which++)
    4165                 :             :             {
    4166                 :     1515474 :               tem = pmop[which];
    4167                 :     1515474 :               switch (GET_CODE (tem))
    4168                 :             :                 {
    4169                 :       10575 :                 case AND:
    4170                 :       10575 :                   if (CONST_INT_P (XEXP (tem, 1))
    4171                 :        9097 :                       && (UINTVAL (XEXP (tem, 1)) & UINTVAL (trueop1))
    4172                 :             :                       == UINTVAL (trueop1))
    4173                 :        7069 :                     pmop[which] = XEXP (tem, 0);
    4174                 :             :                   break;
    4175                 :        1402 :                 case IOR:
    4176                 :        1402 :                 case XOR:
    4177                 :        1402 :                   if (CONST_INT_P (XEXP (tem, 1))
    4178                 :         306 :                       && (UINTVAL (XEXP (tem, 1)) & UINTVAL (trueop1)) == 0)
    4179                 :          55 :                     pmop[which] = XEXP (tem, 0);
    4180                 :             :                   break;
    4181                 :             :                 default:
    4182                 :             :                   break;
    4183                 :             :                 }
    4184                 :             :             }
    4185                 :             : 
    4186                 :      757737 :           if (pmop[0] != XEXP (op0, 0) || pmop[1] != XEXP (op0, 1))
    4187                 :             :             {
    4188                 :        7124 :               tem = simplify_gen_binary (GET_CODE (op0), mode,
    4189                 :             :                                          pmop[0], pmop[1]);
    4190                 :        7124 :               return simplify_gen_binary (code, mode, tem, op1);
    4191                 :             :             }
    4192                 :             :         }
    4193                 :             : 
    4194                 :             :       /* (and X (ior (not X) Y) -> (and X Y) */
    4195                 :    21463311 :       if (GET_CODE (op1) == IOR
    4196                 :     1004101 :           && GET_CODE (XEXP (op1, 0)) == NOT
    4197                 :    21468494 :           && rtx_equal_p (op0, XEXP (XEXP (op1, 0), 0)))
    4198                 :           0 :        return simplify_gen_binary (AND, mode, op0, XEXP (op1, 1));
    4199                 :             : 
    4200                 :             :       /* (and (ior (not X) Y) X) -> (and X Y) */
    4201                 :    21463311 :       if (GET_CODE (op0) == IOR
    4202                 :     1313817 :           && GET_CODE (XEXP (op0, 0)) == NOT
    4203                 :    21509544 :           && rtx_equal_p (op1, XEXP (XEXP (op0, 0), 0)))
    4204                 :           6 :         return simplify_gen_binary (AND, mode, op1, XEXP (op0, 1));
    4205                 :             : 
    4206                 :             :       /* (and X (ior Y (not X)) -> (and X Y) */
    4207                 :    21463305 :       if (GET_CODE (op1) == IOR
    4208                 :     1004101 :           && GET_CODE (XEXP (op1, 1)) == NOT
    4209                 :    21463571 :           && rtx_equal_p (op0, XEXP (XEXP (op1, 1), 0)))
    4210                 :           0 :        return simplify_gen_binary (AND, mode, op0, XEXP (op1, 0));
    4211                 :             : 
    4212                 :             :       /* (and (ior Y (not X)) X) -> (and X Y) */
    4213                 :    21463305 :       if (GET_CODE (op0) == IOR
    4214                 :     1313811 :           && GET_CODE (XEXP (op0, 1)) == NOT
    4215                 :    21471343 :           && rtx_equal_p (op1, XEXP (XEXP (op0, 1), 0)))
    4216                 :           5 :         return simplify_gen_binary (AND, mode, op1, XEXP (op0, 0));
    4217                 :             : 
    4218                 :             :       /* (and (ior/xor (X Y) (not Y)) -> X & ~Y */
    4219                 :    21463300 :       if ((GET_CODE (op0) == IOR || GET_CODE (op0) == XOR)
    4220                 :     1418314 :           && GET_CODE (op1) == NOT
    4221                 :    21572883 :           && rtx_equal_p (XEXP (op1, 0), XEXP (op0, 1)))
    4222                 :          12 :         return simplify_gen_binary (AND, mode, XEXP (op0, 0),
    4223                 :             :                                     simplify_gen_unary (NOT, mode,
    4224                 :             :                                                         XEXP (op1, 0),
    4225                 :          12 :                                                         mode));
    4226                 :             :       /* (and (ior/xor (Y X) (not Y)) -> X & ~Y */
    4227                 :    21463288 :       if ((GET_CODE (op0) == IOR || GET_CODE (op0) == XOR)
    4228                 :     1418302 :           && GET_CODE (op1) == NOT
    4229                 :    21572859 :           && rtx_equal_p (XEXP (op1, 0), XEXP (op0, 0)))
    4230                 :           2 :         return simplify_gen_binary (AND, mode, XEXP (op0, 1),
    4231                 :             :                                     simplify_gen_unary (NOT, mode,
    4232                 :             :                                                         XEXP (op1, 0),
    4233                 :           2 :                                                         mode));
    4234                 :             : 
    4235                 :             :       /* Convert (and (ior A C) (ior B C)) into (ior (and A B) C).  */
    4236                 :    21463286 :       if (GET_CODE (op0) == GET_CODE (op1)
    4237                 :     2106441 :           && (GET_CODE (op0) == AND
    4238                 :             :               || GET_CODE (op0) == IOR
    4239                 :     2106441 :               || GET_CODE (op0) == LSHIFTRT
    4240                 :     1102852 :               || GET_CODE (op0) == ASHIFTRT
    4241                 :     1102755 :               || GET_CODE (op0) == ASHIFT
    4242                 :     1102626 :               || GET_CODE (op0) == ROTATE
    4243                 :     1102626 :               || GET_CODE (op0) == ROTATERT))
    4244                 :             :         {
    4245                 :     1003815 :           tem = simplify_distributive_operation (code, mode, op0, op1);
    4246                 :     1003815 :           if (tem)
    4247                 :             :             return tem;
    4248                 :             :         }
    4249                 :             : 
    4250                 :             :       /* (and:v4si
    4251                 :             :            (ashiftrt:v4si A 16)
    4252                 :             :            (const_vector: 0xffff x4))
    4253                 :             :          is just (lshiftrt:v4si A 16).  */
    4254                 :    20496160 :       if (VECTOR_MODE_P (mode) && GET_CODE (op0) == ASHIFTRT
    4255                 :        4596 :           && (CONST_INT_P (XEXP (op0, 1))
    4256                 :        2521 :               || (GET_CODE (XEXP (op0, 1)) == CONST_VECTOR
    4257                 :         150 :                   && const_vec_duplicate_p (XEXP (op0, 1))
    4258                 :           0 :                   && CONST_INT_P (XVECEXP (XEXP (op0, 1), 0, 0))))
    4259                 :        2075 :           && GET_CODE (op1) == CONST_VECTOR
    4260                 :    20496178 :           && const_vec_duplicate_p (op1)
    4261                 :    20496190 :           && CONST_INT_P (XVECEXP (op1, 0, 0)))
    4262                 :             :         {
    4263                 :          56 :           unsigned HOST_WIDE_INT shift_count
    4264                 :             :             = (CONST_INT_P (XEXP (op0, 1))
    4265                 :          28 :                ? UINTVAL (XEXP (op0, 1))
    4266                 :           0 :                : UINTVAL (XVECEXP (XEXP (op0, 1), 0, 0)));
    4267                 :          28 :           unsigned HOST_WIDE_INT inner_prec
    4268                 :          56 :             = GET_MODE_PRECISION (GET_MODE_INNER (mode));
    4269                 :             : 
    4270                 :             :           /* Avoid UD shift count.  */
    4271                 :          28 :           if (shift_count < inner_prec
    4272                 :          28 :               && (UINTVAL (XVECEXP (op1, 0, 0))
    4273                 :          28 :                   == (HOST_WIDE_INT_1U << (inner_prec - shift_count)) - 1))
    4274                 :          12 :             return simplify_gen_binary (LSHIFTRT, mode, XEXP (op0, 0), XEXP (op0, 1));
    4275                 :             :         }
    4276                 :             : 
    4277                 :    20496148 :       tem = simplify_byte_swapping_operation (code, mode, op0, op1);
    4278                 :    20496148 :       if (tem)
    4279                 :             :         return tem;
    4280                 :             : 
    4281                 :    20495664 :       tem = simplify_associative_operation (code, mode, op0, op1);
    4282                 :    20495664 :       if (tem)
    4283                 :             :         return tem;
    4284                 :             :       break;
    4285                 :             : 
    4286                 :      867283 :     case UDIV:
    4287                 :             :       /* 0/x is 0 (or x&0 if x has side-effects).  */
    4288                 :      867283 :       if (trueop0 == CONST0_RTX (mode)
    4289                 :         270 :           && !cfun->can_throw_non_call_exceptions)
    4290                 :             :         {
    4291                 :         270 :           if (side_effects_p (op1))
    4292                 :           0 :             return simplify_gen_binary (AND, mode, op1, trueop0);
    4293                 :             :           return trueop0;
    4294                 :             :         }
    4295                 :             :       /* x/1 is x.  */
    4296                 :      867013 :       if (trueop1 == CONST1_RTX (mode))
    4297                 :             :         {
    4298                 :      230027 :           tem = rtl_hooks.gen_lowpart_no_emit (mode, op0);
    4299                 :      230027 :           if (tem)
    4300                 :             :             return tem;
    4301                 :             :         }
    4302                 :             :       /* Convert divide by power of two into shift.  */
    4303                 :      636986 :       if (CONST_INT_P (trueop1)
    4304                 :      927162 :           && (val = exact_log2 (UINTVAL (trueop1))) > 0)
    4305                 :      290176 :         return simplify_gen_binary (LSHIFTRT, mode, op0,
    4306                 :      290176 :                                     gen_int_shift_amount (mode, val));
    4307                 :             :       break;
    4308                 :             : 
    4309                 :     1032114 :     case DIV:
    4310                 :             :       /* Handle floating point and integers separately.  */
    4311                 :     1032114 :       if (SCALAR_FLOAT_MODE_P (mode))
    4312                 :             :         {
    4313                 :             :           /* Maybe change 0.0 / x to 0.0.  This transformation isn't
    4314                 :             :              safe for modes with NaNs, since 0.0 / 0.0 will then be
    4315                 :             :              NaN rather than 0.0.  Nor is it safe for modes with signed
    4316                 :             :              zeros, since dividing 0 by a negative number gives -0.0  */
    4317                 :      311708 :           if (trueop0 == CONST0_RTX (mode)
    4318                 :        2952 :               && !HONOR_NANS (mode)
    4319                 :          13 :               && !HONOR_SIGNED_ZEROS (mode)
    4320                 :      311721 :               && ! side_effects_p (op1))
    4321                 :             :             return op0;
    4322                 :             :           /* x/1.0 is x.  */
    4323                 :      311695 :           if (trueop1 == CONST1_RTX (mode)
    4324                 :      311695 :               && !HONOR_SNANS (mode))
    4325                 :             :             return op0;
    4326                 :             : 
    4327                 :      311665 :           if (CONST_DOUBLE_AS_FLOAT_P (trueop1)
    4328                 :       28856 :               && trueop1 != CONST0_RTX (mode))
    4329                 :             :             {
    4330                 :       22670 :               const REAL_VALUE_TYPE *d1 = CONST_DOUBLE_REAL_VALUE (trueop1);
    4331                 :             : 
    4332                 :             :               /* x/-1.0 is -x.  */
    4333                 :       22670 :               if (real_equal (d1, &dconstm1)
    4334                 :       22670 :                   && !HONOR_SNANS (mode))
    4335                 :           0 :                 return simplify_gen_unary (NEG, mode, op0, mode);
    4336                 :             : 
    4337                 :             :               /* Change FP division by a constant into multiplication.
    4338                 :             :                  Only do this with -freciprocal-math.  */
    4339                 :       22670 :               if (flag_reciprocal_math
    4340                 :       22670 :                   && !real_equal (d1, &dconst0))
    4341                 :             :                 {
    4342                 :           7 :                   REAL_VALUE_TYPE d;
    4343                 :           7 :                   real_arithmetic (&d, RDIV_EXPR, &dconst1, d1);
    4344                 :           7 :                   tem = const_double_from_real_value (d, mode);
    4345                 :           7 :                   return simplify_gen_binary (MULT, mode, op0, tem);
    4346                 :             :                 }
    4347                 :             :             }
    4348                 :             :         }
    4349                 :      720406 :       else if (SCALAR_INT_MODE_P (mode) || GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
    4350                 :             :         {
    4351                 :             :           /* 0/x is 0 (or x&0 if x has side-effects).  */
    4352                 :      698924 :           if (trueop0 == CONST0_RTX (mode)
    4353                 :         609 :               && !cfun->can_throw_non_call_exceptions)
    4354                 :             :             {
    4355                 :         555 :               if (side_effects_p (op1))
    4356                 :           8 :                 return simplify_gen_binary (AND, mode, op1, trueop0);
    4357                 :             :               return trueop0;
    4358                 :             :             }
    4359                 :             :           /* x/1 is x.  */
    4360                 :      698369 :           if (trueop1 == CONST1_RTX (mode))
    4361                 :             :             {
    4362                 :         303 :               tem = rtl_hooks.gen_lowpart_no_emit (mode, op0);
    4363                 :         303 :               if (tem)
    4364                 :             :                 return tem;
    4365                 :             :             }
    4366                 :             :           /* x/-1 is -x.  */
    4367                 :      698066 :           if (trueop1 == CONSTM1_RTX (mode))
    4368                 :             :             {
    4369                 :         230 :               rtx x = rtl_hooks.gen_lowpart_no_emit (mode, op0);
    4370                 :         230 :               if (x)
    4371                 :         230 :                 return simplify_gen_unary (NEG, mode, x, mode);
    4372                 :             :             }
    4373                 :             :         }
    4374                 :             :       break;
    4375                 :             : 
    4376                 :      843632 :     case UMOD:
    4377                 :             :       /* 0%x is 0 (or x&0 if x has side-effects).  */
    4378                 :      843632 :       if (trueop0 == CONST0_RTX (mode))
    4379                 :             :         {
    4380                 :         732 :           if (side_effects_p (op1))
    4381                 :           0 :             return simplify_gen_binary (AND, mode, op1, trueop0);
    4382                 :             :           return trueop0;
    4383                 :             :         }
    4384                 :             :       /* x%1 is 0 (of x&0 if x has side-effects).  */
    4385                 :      842900 :       if (trueop1 == CONST1_RTX (mode))
    4386                 :             :         {
    4387                 :      261936 :           if (side_effects_p (op0))
    4388                 :           0 :             return simplify_gen_binary (AND, mode, op0, CONST0_RTX (mode));
    4389                 :      261936 :           return CONST0_RTX (mode);
    4390                 :             :         }
    4391                 :             :       /* Implement modulus by power of two as AND.  */
    4392                 :      580964 :       if (CONST_INT_P (trueop1)
    4393                 :      839505 :           && exact_log2 (UINTVAL (trueop1)) > 0)
    4394                 :      258541 :         return simplify_gen_binary (AND, mode, op0,
    4395                 :      258541 :                                     gen_int_mode (UINTVAL (trueop1) - 1,
    4396                 :             :                                                   mode));
    4397                 :             :       break;
    4398                 :             : 
    4399                 :      337892 :     case MOD:
    4400                 :             :       /* 0%x is 0 (or x&0 if x has side-effects).  */
    4401                 :      337892 :       if (trueop0 == CONST0_RTX (mode))
    4402                 :             :         {
    4403                 :         600 :           if (side_effects_p (op1))
    4404                 :           8 :             return simplify_gen_binary (AND, mode, op1, trueop0);
    4405                 :             :           return trueop0;
    4406                 :             :         }
    4407                 :             :       /* x%1 and x%-1 is 0 (or x&0 if x has side-effects).  */
    4408                 :      337292 :       if (trueop1 == CONST1_RTX (mode) || trueop1 == constm1_rtx)
    4409                 :             :         {
    4410                 :         428 :           if (side_effects_p (op0))
    4411                 :           0 :             return simplify_gen_binary (AND, mode, op0, CONST0_RTX (mode));
    4412                 :         428 :           return CONST0_RTX (mode);
    4413                 :             :         }
    4414                 :             :       break;
    4415                 :             : 
    4416                 :      131533 :     case ROTATERT:
    4417                 :      131533 :     case ROTATE:
    4418                 :      131533 :       if (trueop1 == CONST0_RTX (mode))
    4419                 :             :         return op0;
    4420                 :             :       /* Canonicalize rotates by constant amount.  If the condition of
    4421                 :             :          reversing direction is met, then reverse the direction. */
    4422                 :             : #if defined(HAVE_rotate) && defined(HAVE_rotatert)
    4423                 :      131437 :       if (reverse_rotate_by_imm_p (mode, (code == ROTATE), trueop1))
    4424                 :             :         {
    4425                 :       11476 :           int new_amount = GET_MODE_UNIT_PRECISION (mode) - INTVAL (trueop1);
    4426                 :       11476 :           rtx new_amount_rtx = gen_int_shift_amount (mode, new_amount);
    4427                 :       11798 :           return simplify_gen_binary (code == ROTATE ? ROTATERT : ROTATE,
    4428                 :             :                                       mode, op0, new_amount_rtx);
    4429                 :             :         }
    4430                 :             : #endif
    4431                 :             :       /* ROTATE/ROTATERT:HI (X:HI, 8) is BSWAP:HI (X).  Other combinations
    4432                 :             :          such as SImode with a count of 16 do not correspond to RTL BSWAP
    4433                 :             :          semantics.  */
    4434                 :      119961 :       tem = unwrap_const_vec_duplicate (trueop1);
    4435                 :      119961 :       if (GET_MODE_UNIT_BITSIZE (mode) == (2 * BITS_PER_UNIT)
    4436                 :      119961 :           && CONST_INT_P (tem) && INTVAL (tem) == BITS_PER_UNIT)
    4437                 :         380 :         return simplify_gen_unary (BSWAP, mode, op0, mode);
    4438                 :             : 
    4439                 :             :       /* FALLTHRU */
    4440                 :     5214673 :     case ASHIFTRT:
    4441                 :     5214673 :       if (trueop1 == CONST0_RTX (mode))
    4442                 :             :         return op0;
    4443                 :     5212901 :       if (trueop0 == CONST0_RTX (mode) && ! side_effects_p (op1))
    4444                 :             :         return op0;
    4445                 :             :       /* Rotating ~0 always results in ~0.  */
    4446                 :     5212746 :       if (CONST_INT_P (trueop0)
    4447                 :       14716 :           && HWI_COMPUTABLE_MODE_P (mode)
    4448                 :       14668 :           && UINTVAL (trueop0) == GET_MODE_MASK (mode)
    4449                 :     5212746 :           && ! side_effects_p (op1))
    4450                 :             :         return op0;
    4451                 :             : 
    4452                 :    29811694 :     canonicalize_shift:
    4453                 :             :       /* Given:
    4454                 :             :          scalar modes M1, M2
    4455                 :             :          scalar constants c1, c2
    4456                 :             :          size (M2) > size (M1)
    4457                 :             :          c1 == size (M2) - size (M1)
    4458                 :             :          optimize:
    4459                 :             :          ([a|l]shiftrt:M1 (subreg:M1 (lshiftrt:M2 (reg:M2) (const_int <c1>))
    4460                 :             :                                  <low_part>)
    4461                 :             :                       (const_int <c2>))
    4462                 :             :          to:
    4463                 :             :          (subreg:M1 ([a|l]shiftrt:M2 (reg:M2) (const_int <c1 + c2>))
    4464                 :             :                     <low_part>).  */
    4465                 :    29811694 :       if ((code == ASHIFTRT || code == LSHIFTRT)
    4466                 :    11519109 :           && is_a <scalar_int_mode> (mode, &int_mode)
    4467                 :    10778215 :           && SUBREG_P (op0)
    4468                 :     1017008 :           && CONST_INT_P (op1)
    4469                 :     1016030 :           && GET_CODE (SUBREG_REG (op0)) == LSHIFTRT
    4470                 :       21144 :           && is_a <scalar_int_mode> (GET_MODE (SUBREG_REG (op0)),
    4471                 :             :                                      &inner_mode)
    4472                 :       21144 :           && CONST_INT_P (XEXP (SUBREG_REG (op0), 1))
    4473                 :       41982 :           && GET_MODE_BITSIZE (inner_mode) > GET_MODE_BITSIZE (int_mode)
    4474                 :       20989 :           && (INTVAL (XEXP (SUBREG_REG (op0), 1))
    4475                 :       41978 :               == GET_MODE_BITSIZE (inner_mode) - GET_MODE_BITSIZE (int_mode))
    4476                 :    29832315 :           && subreg_lowpart_p (op0))
    4477                 :             :         {
    4478                 :       20621 :           rtx tmp = gen_int_shift_amount
    4479                 :       20621 :             (inner_mode, INTVAL (XEXP (SUBREG_REG (op0), 1)) + INTVAL (op1));
    4480                 :             : 
    4481                 :             :          /* Combine would usually zero out the value when combining two
    4482                 :             :             local shifts and the range becomes larger or equal to the mode.
    4483                 :             :             However since we fold away one of the shifts here combine won't
    4484                 :             :             see it so we should immediately zero the result if it's out of
    4485                 :             :             range.  */
    4486                 :       20621 :          if (code == LSHIFTRT
    4487                 :       37920 :              && INTVAL (tmp) >= GET_MODE_BITSIZE (inner_mode))
    4488                 :           0 :           tmp = const0_rtx;
    4489                 :             :          else
    4490                 :       20621 :            tmp = simplify_gen_binary (code,
    4491                 :             :                                       inner_mode,
    4492                 :       20621 :                                       XEXP (SUBREG_REG (op0), 0),
    4493                 :             :                                       tmp);
    4494                 :             : 
    4495                 :       20621 :           return lowpart_subreg (int_mode, tmp, inner_mode);
    4496                 :             :         }
    4497                 :             : 
    4498                 :    29791073 :       if (SHIFT_COUNT_TRUNCATED && CONST_INT_P (op1))
    4499                 :             :         {
    4500                 :             :           val = INTVAL (op1) & (GET_MODE_UNIT_PRECISION (mode) - 1);
    4501                 :             :           if (val != INTVAL (op1))
    4502                 :             :             return simplify_gen_binary (code, mode, op0,
    4503                 :             :                                         gen_int_shift_amount (mode, val));
    4504                 :             :         }
    4505                 :             : 
    4506                 :             :       /* Simplify:
    4507                 :             : 
    4508                 :             :            (code:M1
    4509                 :             :              (subreg:M1
    4510                 :             :                ([al]shiftrt:M2
    4511                 :             :                  (subreg:M2
    4512                 :             :                    (ashift:M1 X C1))
    4513                 :             :                  C2))
    4514                 :             :              C3)
    4515                 :             : 
    4516                 :             :          to:
    4517                 :             : 
    4518                 :             :            (code:M1
    4519                 :             :              ([al]shiftrt:M1
    4520                 :             :                (ashift:M1 X C1+N)
    4521                 :             :                C2+N)
    4522                 :             :              C3)
    4523                 :             : 
    4524                 :             :          where M1 is N bits wider than M2.  Optimizing the (subreg:M1 ...)
    4525                 :             :          directly would be arithmetically correct, but restricting the
    4526                 :             :          simplification to shifts by constants is more conservative,
    4527                 :             :          since it is more likely to lead to further simplifications.  */
    4528                 :    29791073 :       if (is_a<scalar_int_mode> (mode, &int_mode)
    4529                 :    28876340 :           && paradoxical_subreg_p (op0)
    4530                 :     4488843 :           && is_a<scalar_int_mode> (GET_MODE (SUBREG_REG (op0)), &inner_mode)
    4531                 :     4488664 :           && (GET_CODE (SUBREG_REG (op0)) == ASHIFTRT
    4532                 :     4488664 :               || GET_CODE (SUBREG_REG (op0)) == LSHIFTRT)
    4533                 :      131747 :           && CONST_INT_P (op1))
    4534                 :             :         {
    4535                 :      131747 :           auto xcode = GET_CODE (SUBREG_REG (op0));
    4536                 :      131747 :           rtx xop0 = XEXP (SUBREG_REG (op0), 0);
    4537                 :      131747 :           rtx xop1 = XEXP (SUBREG_REG (op0), 1);
    4538                 :      131747 :           if (SUBREG_P (xop0)
    4539                 :        5176 :               && GET_MODE (SUBREG_REG (xop0)) == mode
    4540                 :        5031 :               && GET_CODE (SUBREG_REG (xop0)) == ASHIFT
    4541                 :         617 :               && CONST_INT_P (xop1)
    4542                 :      132364 :               && UINTVAL (xop1) < GET_MODE_PRECISION (inner_mode))
    4543                 :             :             {
    4544                 :         617 :               rtx yop0 = XEXP (SUBREG_REG (xop0), 0);
    4545                 :         617 :               rtx yop1 = XEXP (SUBREG_REG (xop0), 1);
    4546                 :         617 :               if (CONST_INT_P (yop1)
    4547                 :         617 :                   && UINTVAL (yop1) < GET_MODE_PRECISION (inner_mode))
    4548                 :             :                 {
    4549                 :        1234 :                   auto bias = (GET_MODE_BITSIZE (int_mode)
    4550                 :         617 :                                - GET_MODE_BITSIZE (inner_mode));
    4551                 :         617 :                   tem = simplify_gen_binary (ASHIFT, mode, yop0,
    4552                 :         617 :                                              GEN_INT (INTVAL (yop1) + bias));
    4553                 :         617 :                   tem = simplify_gen_binary (xcode, mode, tem,
    4554                 :         617 :                                              GEN_INT (INTVAL (xop1) + bias));
    4555                 :         617 :                   return simplify_gen_binary (code, mode, tem, op1);
    4556                 :             :                 }
    4557                 :             :             }
    4558                 :             :         }
    4559                 :             :       break;
    4560                 :             : 
    4561                 :           0 :     case SS_ASHIFT:
    4562                 :           0 :       if (CONST_INT_P (trueop0)
    4563                 :           0 :           && HWI_COMPUTABLE_MODE_P (mode)
    4564                 :           0 :           && (UINTVAL (trueop0) == (GET_MODE_MASK (mode) >> 1)
    4565                 :           0 :               || mode_signbit_p (mode, trueop0))
    4566                 :           0 :           && ! side_effects_p (op1))
    4567                 :             :         return op0;
    4568                 :           0 :       goto simplify_ashift;
    4569                 :             : 
    4570                 :           0 :     case US_ASHIFT:
    4571                 :           0 :       if (CONST_INT_P (trueop0)
    4572                 :           0 :           && HWI_COMPUTABLE_MODE_P (mode)
    4573                 :           0 :           && UINTVAL (trueop0) == GET_MODE_MASK (mode)
    4574                 :           0 :           && ! side_effects_p (op1))
    4575                 :             :         return op0;
    4576                 :             :       /* FALLTHRU */
    4577                 :             : 
    4578                 :    18589576 :     case ASHIFT:
    4579                 :    18589576 : simplify_ashift:
    4580                 :    18589576 :       if (trueop1 == CONST0_RTX (mode))
    4581                 :             :         return op0;
    4582                 :    18422652 :       if (trueop0 == CONST0_RTX (mode) && ! side_effects_p (op1))
    4583                 :             :         return op0;
    4584                 :    18399179 :       if (mem_depth
    4585                 :      226160 :           && code == ASHIFT
    4586                 :      226160 :           && CONST_INT_P (trueop1)
    4587                 :      226152 :           && is_a <scalar_int_mode> (mode, &int_mode)
    4588                 :    18625319 :           && IN_RANGE (UINTVAL (trueop1),
    4589                 :             :                        1, GET_MODE_PRECISION (int_mode) - 1))
    4590                 :             :         {
    4591                 :      226140 :           auto c = (wi::one (GET_MODE_PRECISION (int_mode))
    4592                 :      226140 :                     << UINTVAL (trueop1));
    4593                 :      226140 :           rtx new_op1 = immed_wide_int_const (c, int_mode);
    4594                 :      226140 :           return simplify_gen_binary (MULT, int_mode, op0, new_op1);
    4595                 :      226140 :         }
    4596                 :    18173039 :       goto canonicalize_shift;
    4597                 :             : 
    4598                 :     8113061 :     case LSHIFTRT:
    4599                 :     8113061 :       if (trueop1 == CONST0_RTX (mode))
    4600                 :             :         return op0;
    4601                 :     6427191 :       if (trueop0 == CONST0_RTX (mode) && ! side_effects_p (op1))
    4602                 :             :         return op0;
    4603                 :             :       /* Optimize (lshiftrt (clz X) C) as (eq X 0).  */
    4604                 :     6425909 :       if (GET_CODE (op0) == CLZ
    4605                 :           0 :           && is_a <scalar_int_mode> (GET_MODE (XEXP (op0, 0)), &inner_mode)
    4606                 :           0 :           && CONST_INT_P (trueop1)
    4607                 :             :           && STORE_FLAG_VALUE == 1
    4608                 :     6425909 :           && INTVAL (trueop1) < GET_MODE_UNIT_PRECISION (mode))
    4609                 :             :         {
    4610                 :           0 :           unsigned HOST_WIDE_INT zero_val = 0;
    4611                 :             : 
    4612                 :           0 :           if (CLZ_DEFINED_VALUE_AT_ZERO (inner_mode, zero_val)
    4613                 :           0 :               && zero_val == GET_MODE_PRECISION (inner_mode)
    4614                 :           0 :               && INTVAL (trueop1) == exact_log2 (zero_val))
    4615                 :           0 :             return simplify_gen_relational (EQ, mode, inner_mode,
    4616                 :           0 :                                             XEXP (op0, 0), const0_rtx);
    4617                 :             :         }
    4618                 :     6425909 :       goto canonicalize_shift;
    4619                 :             : 
    4620                 :      190959 :     case SMIN:
    4621                 :      190959 :       if (HWI_COMPUTABLE_MODE_P (mode)
    4622                 :      171732 :           && mode_signbit_p (mode, trueop1)
    4623                 :           0 :           && ! side_effects_p (op0))
    4624                 :             :         return op1;
    4625                 :      190959 :       if (rtx_equal_p (trueop0, trueop1) && ! side_effects_p (op0))
    4626                 :             :         return op0;
    4627                 :      190822 :       tem = simplify_associative_operation (code, mode, op0, op1);
    4628                 :      190822 :       if (tem)
    4629                 :             :         return tem;
    4630                 :             :       break;
    4631                 :             : 
    4632                 :      439966 :     case SMAX:
    4633                 :      439966 :       if (HWI_COMPUTABLE_MODE_P (mode)
    4634                 :      413634 :           && CONST_INT_P (trueop1)
    4635                 :      387891 :           && (UINTVAL (trueop1) == GET_MODE_MASK (mode) >> 1)
    4636                 :           0 :           && ! side_effects_p (op0))
    4637                 :             :         return op1;
    4638                 :      439966 :       if (rtx_equal_p (trueop0, trueop1) && ! side_effects_p (op0))
    4639                 :             :         return op0;
    4640                 :      439861 :       tem = simplify_associative_operation (code, mode, op0, op1);
    4641                 :      439861 :       if (tem)
    4642                 :             :         return tem;
    4643                 :             :       break;
    4644                 :             : 
    4645                 :      208593 :     case UMIN:
    4646                 :      208593 :       if (trueop1 == CONST0_RTX (mode) && ! side_effects_p (op0))
    4647                 :             :         return op1;
    4648                 :      208568 :       if (rtx_equal_p (trueop0, trueop1) && ! side_effects_p (op0))
    4649                 :             :         return op0;
    4650                 :      208469 :       tem = simplify_associative_operation (code, mode, op0, op1);
    4651                 :      208469 :       if (tem)
    4652                 :             :         return tem;
    4653                 :             :       break;
    4654                 :             : 
    4655                 :      205101 :     case UMAX:
    4656                 :      205101 :       if (trueop1 == constm1_rtx && ! side_effects_p (op0))
    4657                 :             :         return op1;
    4658                 :      205101 :       if (rtx_equal_p (trueop0, trueop1) && ! side_effects_p (op0))
    4659                 :             :         return op0;
    4660                 :      205011 :       tem = simplify_associative_operation (code, mode, op0, op1);
    4661                 :      205011 :       if (tem)
    4662                 :             :         return tem;
    4663                 :             :       break;
    4664                 :             : 
    4665                 :       10806 :     case SS_PLUS:
    4666                 :       10806 :     case US_PLUS:
    4667                 :       10806 :     case SS_MINUS:
    4668                 :       10806 :     case US_MINUS:
    4669                 :             :       /* Simplify x +/- 0 to x, if possible.  */
    4670                 :       10806 :       if (trueop1 == CONST0_RTX (mode))
    4671                 :             :         return op0;
    4672                 :             :       return 0;
    4673                 :             : 
    4674                 :           0 :     case SS_MULT:
    4675                 :           0 :     case US_MULT:
    4676                 :             :       /* Simplify x * 0 to 0, if possible.  */
    4677                 :           0 :       if (trueop1 == CONST0_RTX (mode)
    4678                 :           0 :           && !side_effects_p (op0))
    4679                 :             :         return op1;
    4680                 :             : 
    4681                 :             :       /* Simplify x * 1 to x, if possible.  */
    4682                 :           0 :       if (trueop1 == CONST1_RTX (mode))
    4683                 :             :         return op0;
    4684                 :             :       return 0;
    4685                 :             : 
    4686                 :      601948 :     case SMUL_HIGHPART:
    4687                 :      601948 :     case UMUL_HIGHPART:
    4688                 :             :       /* Simplify x * 0 to 0, if possible.  */
    4689                 :      601948 :       if (trueop1 == CONST0_RTX (mode)
    4690                 :      601948 :           && !side_effects_p (op0))
    4691                 :             :         return op1;
    4692                 :             :       return 0;
    4693                 :             : 
    4694                 :           0 :     case SS_DIV:
    4695                 :           0 :     case US_DIV:
    4696                 :             :       /* Simplify x / 1 to x, if possible.  */
    4697                 :           0 :       if (trueop1 == CONST1_RTX (mode))
    4698                 :             :         return op0;
    4699                 :             :       return 0;
    4700                 :             : 
    4701                 :           0 :     case COPYSIGN:
    4702                 :           0 :       if (rtx_equal_p (trueop0, trueop1) && ! side_effects_p (op0))
    4703                 :             :         return op0;
    4704                 :           0 :       if (CONST_DOUBLE_AS_FLOAT_P (trueop1))
    4705                 :             :         {
    4706                 :           0 :           REAL_VALUE_TYPE f1;
    4707                 :           0 :           real_convert (&f1, mode, CONST_DOUBLE_REAL_VALUE (trueop1));
    4708                 :           0 :           rtx tmp = simplify_gen_unary (ABS, mode, op0, mode);
    4709                 :           0 :           if (REAL_VALUE_NEGATIVE (f1))
    4710                 :           0 :             tmp = simplify_unary_operation (NEG, mode, tmp, mode);
    4711                 :           0 :           return tmp;
    4712                 :             :         }
    4713                 :           0 :       if (GET_CODE (op0) == NEG || GET_CODE (op0) == ABS)
    4714                 :           0 :         return simplify_gen_binary (COPYSIGN, mode, XEXP (op0, 0), op1);
    4715                 :           0 :       if (GET_CODE (op1) == ABS
    4716                 :           0 :           && ! side_effects_p (op1))
    4717                 :           0 :         return simplify_gen_unary (ABS, mode, op0, mode);
    4718                 :           0 :       if (GET_CODE (op0) == COPYSIGN
    4719                 :           0 :           && ! side_effects_p (XEXP (op0, 1)))
    4720                 :           0 :         return simplify_gen_binary (COPYSIGN, mode, XEXP (op0, 0), op1);
    4721                 :           0 :       if (GET_CODE (op1) == COPYSIGN
    4722                 :           0 :           && ! side_effects_p (XEXP (op1, 0)))
    4723                 :           0 :         return simplify_gen_binary (COPYSIGN, mode, op0, XEXP (op1, 1));
    4724                 :             :       return 0;
    4725                 :             : 
    4726                 :        1221 :     case VEC_SERIES:
    4727                 :        2442 :       if (op1 == CONST0_RTX (GET_MODE_INNER (mode)))
    4728                 :          96 :         return gen_vec_duplicate (mode, op0);
    4729                 :        1125 :       if (valid_for_const_vector_p (mode, op0)
    4730                 :        1125 :           && valid_for_const_vector_p (mode, op1))
    4731                 :          96 :         return gen_const_vec_series (mode, op0, op1);
    4732                 :             :       return 0;
    4733                 :             : 
    4734                 :     3187690 :     case VEC_SELECT:
    4735                 :     3187690 :       if (!VECTOR_MODE_P (mode))
    4736                 :             :         {
    4737                 :      844281 :           gcc_assert (VECTOR_MODE_P (GET_MODE (trueop0)));
    4738                 :     1688562 :           gcc_assert (mode == GET_MODE_INNER (GET_MODE (trueop0)));
    4739                 :      844281 :           gcc_assert (GET_CODE (trueop1) == PARALLEL);
    4740                 :      844281 :           gcc_assert (XVECLEN (trueop1, 0) == 1);
    4741                 :             : 
    4742                 :             :           /* We can't reason about selections made at runtime.  */
    4743                 :      844281 :           if (!CONST_INT_P (XVECEXP (trueop1, 0, 0)))
    4744                 :   403875062 :             return 0;
    4745                 :             : 
    4746                 :      844281 :           if (vec_duplicate_p (trueop0, &elt0))
    4747                 :        2174 :             return elt0;
    4748                 :             : 
    4749                 :      842107 :           if (GET_CODE (trueop0) == CONST_VECTOR)
    4750                 :        7215 :             return CONST_VECTOR_ELT (trueop0, INTVAL (XVECEXP
    4751                 :             :                                                       (trueop1, 0, 0)));
    4752                 :             : 
    4753                 :             :           /* Extract a scalar element from a nested VEC_SELECT expression
    4754                 :             :              (with optional nested VEC_CONCAT expression).  Some targets
    4755                 :             :              (i386) extract scalar element from a vector using chain of
    4756                 :             :              nested VEC_SELECT expressions.  When input operand is a memory
    4757                 :             :              operand, this operation can be simplified to a simple scalar
    4758                 :             :              load from an offseted memory address.  */
    4759                 :      834892 :           int n_elts;
    4760                 :      834892 :           if (GET_CODE (trueop0) == VEC_SELECT
    4761                 :      900939 :               && (GET_MODE_NUNITS (GET_MODE (XEXP (trueop0, 0)))
    4762                 :       66047 :                   .is_constant (&n_elts)))
    4763                 :             :             {
    4764                 :       66047 :               rtx op0 = XEXP (trueop0, 0);
    4765                 :       66047 :               rtx op1 = XEXP (trueop0, 1);
    4766                 :             : 
    4767                 :       66047 :               int i = INTVAL (XVECEXP (trueop1, 0, 0));
    4768                 :       66047 :               int elem;
    4769                 :             : 
    4770                 :       66047 :               rtvec vec;
    4771                 :       66047 :               rtx tmp_op, tmp;
    4772                 :             : 
    4773                 :       66047 :               gcc_assert (GET_CODE (op1) == PARALLEL);
    4774                 :       66047 :               gcc_assert (i < n_elts);
    4775                 :             : 
    4776                 :             :               /* Select element, pointed by nested selector.  */
    4777                 :       66047 :               elem = INTVAL (XVECEXP (op1, 0, i));
    4778                 :             : 
    4779                 :             :               /* Handle the case when nested VEC_SELECT wraps VEC_CONCAT.  */
    4780                 :       66047 :               if (GET_CODE (op0) == VEC_CONCAT)
    4781                 :             :                 {
    4782                 :       26490 :                   rtx op00 = XEXP (op0, 0);
    4783                 :       26490 :                   rtx op01 = XEXP (op0, 1);
    4784                 :             : 
    4785                 :       26490 :                   machine_mode mode00, mode01;
    4786                 :       26490 :                   int n_elts00, n_elts01;
    4787                 :             : 
    4788                 :       26490 :                   mode00 = GET_MODE (op00);
    4789                 :       26490 :                   mode01 = GET_MODE (op01);
    4790                 :             : 
    4791                 :             :                   /* Find out the number of elements of each operand.
    4792                 :             :                      Since the concatenated result has a constant number
    4793                 :             :                      of elements, the operands must too.  */
    4794                 :       26490 :                   n_elts00 = GET_MODE_NUNITS (mode00).to_constant ();
    4795                 :       26490 :                   n_elts01 = GET_MODE_NUNITS (mode01).to_constant ();
    4796                 :             : 
    4797                 :       26490 :                   gcc_assert (n_elts == n_elts00 + n_elts01);
    4798                 :             : 
    4799                 :             :                   /* Select correct operand of VEC_CONCAT
    4800                 :             :                      and adjust selector. */
    4801                 :       26490 :                   if (elem < n_elts01)
    4802                 :             :                     tmp_op = op00;
    4803                 :             :                   else
    4804                 :             :                     {
    4805                 :          38 :                       tmp_op = op01;
    4806                 :          38 :                       elem -= n_elts00;
    4807                 :             :                     }
    4808                 :             :                 }
    4809                 :             :               else
    4810                 :             :                 tmp_op = op0;
    4811                 :             : 
    4812                 :       66047 :               vec = rtvec_alloc (1);
    4813                 :       66047 :               RTVEC_ELT (vec, 0) = GEN_INT (elem);
    4814                 :             : 
    4815                 :       66047 :               tmp = gen_rtx_fmt_ee (code, mode,
    4816                 :             :                                     tmp_op, gen_rtx_PARALLEL (VOIDmode, vec));
    4817                 :       66047 :               return tmp;
    4818                 :             :             }
    4819                 :             :         }
    4820                 :             :       else
    4821                 :             :         {
    4822                 :     2343409 :           gcc_assert (VECTOR_MODE_P (GET_MODE (trueop0)));
    4823                 :     7030227 :           gcc_assert (GET_MODE_INNER (mode)
    4824                 :             :                       == GET_MODE_INNER (GET_MODE (trueop0)));
    4825                 :     2343409 :           gcc_assert (GET_CODE (trueop1) == PARALLEL);
    4826                 :             : 
    4827                 :     2343409 :           if (vec_duplicate_p (trueop0, &elt0))
    4828                 :             :             /* It doesn't matter which elements are selected by trueop1,
    4829                 :             :                because they are all the same.  */
    4830                 :       14315 :             return gen_vec_duplicate (mode, elt0);
    4831                 :             : 
    4832                 :     2329094 :           if (GET_CODE (trueop0) == CONST_VECTOR)
    4833                 :             :             {
    4834                 :       16710 :               unsigned n_elts = XVECLEN (trueop1, 0);
    4835                 :       16710 :               rtvec v = rtvec_alloc (n_elts);
    4836                 :       16710 :               unsigned int i;
    4837                 :             : 
    4838                 :       33420 :               gcc_assert (known_eq (n_elts, GET_MODE_NUNITS (mode)));
    4839                 :       86816 :               for (i = 0; i < n_elts; i++)
    4840                 :             :                 {
    4841                 :       70106 :                   rtx x = XVECEXP (trueop1, 0, i);
    4842                 :             : 
    4843                 :       70106 :                   if (!CONST_INT_P (x))
    4844                 :             :                     return 0;
    4845                 :             : 
    4846                 :       70106 :                   RTVEC_ELT (v, i) = CONST_VECTOR_ELT (trueop0,
    4847                 :             :                                                        INTVAL (x));
    4848                 :             :                 }
    4849                 :             : 
    4850                 :       16710 :               return gen_rtx_CONST_VECTOR (mode, v);
    4851                 :             :             }
    4852                 :             : 
    4853                 :             :           /* Recognize the identity.  */
    4854                 :     2312384 :           if (GET_MODE (trueop0) == mode)
    4855                 :             :             {
    4856                 :      525692 :               bool maybe_ident = true;
    4857                 :      525692 :               for (int i = 0; i < XVECLEN (trueop1, 0); i++)
    4858                 :             :                 {
    4859                 :      525330 :                   rtx j = XVECEXP (trueop1, 0, i);
    4860                 :      525330 :                   if (!CONST_INT_P (j) || INTVAL (j) != i)
    4861                 :             :                     {
    4862                 :             :                       maybe_ident = false;
    4863                 :             :                       break;
    4864                 :             :                     }
    4865                 :             :                 }
    4866                 :      313097 :               if (maybe_ident)
    4867                 :             :                 return trueop0;
    4868                 :             :             }
    4869                 :             : 
    4870                 :             :           /* If we select a low-part subreg, return that.  */
    4871                 :     2312022 :           if (vec_series_lowpart_p (mode, GET_MODE (trueop0), trueop1))
    4872                 :             :             {
    4873                 :           0 :               rtx new_rtx = lowpart_subreg (mode, trueop0,
    4874                 :           0 :                                             GET_MODE (trueop0));
    4875                 :           0 :               if (new_rtx != NULL_RTX)
    4876                 :             :                 return new_rtx;
    4877                 :             :             }
    4878                 :             : 
    4879                 :             :           /* If we build {a,b} then permute it, build the result directly.  */
    4880                 :     2312022 :           if (XVECLEN (trueop1, 0) == 2
    4881                 :      535174 :               && CONST_INT_P (XVECEXP (trueop1, 0, 0))
    4882                 :      535174 :               && CONST_INT_P (XVECEXP (trueop1, 0, 1))
    4883                 :      535174 :               && GET_CODE (trueop0) == VEC_CONCAT
    4884                 :      164606 :               && GET_CODE (XEXP (trueop0, 0)) == VEC_CONCAT
    4885                 :          73 :               && GET_MODE (XEXP (trueop0, 0)) == mode
    4886                 :          73 :               && GET_CODE (XEXP (trueop0, 1)) == VEC_CONCAT
    4887                 :          50 :               && GET_MODE (XEXP (trueop0, 1)) == mode)
    4888                 :             :             {
    4889                 :          50 :               unsigned int i0 = INTVAL (XVECEXP (trueop1, 0, 0));
    4890                 :          50 :               unsigned int i1 = INTVAL (XVECEXP (trueop1, 0, 1));
    4891                 :          50 :               rtx subop0, subop1;
    4892                 :             : 
    4893                 :          50 :               gcc_assert (i0 < 4 && i1 < 4);
    4894                 :          50 :               subop0 = XEXP (XEXP (trueop0, i0 / 2), i0 % 2);
    4895                 :          50 :               subop1 = XEXP (XEXP (trueop0, i1 / 2), i1 % 2);
    4896                 :             : 
    4897                 :          50 :               return simplify_gen_binary (VEC_CONCAT, mode, subop0, subop1);
    4898                 :             :             }
    4899                 :             : 
    4900                 :     2311972 :           if (XVECLEN (trueop1, 0) == 2
    4901                 :      535124 :               && CONST_INT_P (XVECEXP (trueop1, 0, 0))
    4902                 :      535124 :               && CONST_INT_P (XVECEXP (trueop1, 0, 1))
    4903                 :      535124 :               && GET_CODE (trueop0) == VEC_CONCAT
    4904                 :      164556 :               && GET_MODE (trueop0) == mode)
    4905                 :             :             {
    4906                 :           2 :               unsigned int i0 = INTVAL (XVECEXP (trueop1, 0, 0));
    4907                 :           2 :               unsigned int i1 = INTVAL (XVECEXP (trueop1, 0, 1));
    4908                 :           2 :               rtx subop0, subop1;
    4909                 :             : 
    4910                 :           2 :               gcc_assert (i0 < 2 && i1 < 2);
    4911                 :           2 :               subop0 = XEXP (trueop0, i0);
    4912                 :           2 :               subop1 = XEXP (trueop0, i1);
    4913                 :             : 
    4914                 :           2 :               return simplify_gen_binary (VEC_CONCAT, mode, subop0, subop1);
    4915                 :             :             }
    4916                 :             : 
    4917                 :             :           /* If we select one half of a vec_concat, return that.  */
    4918                 :     2311970 :           int l0, l1;
    4919                 :     2311970 :           if (GET_CODE (trueop0) == VEC_CONCAT
    4920                 :     2895750 :               && (GET_MODE_NUNITS (GET_MODE (XEXP (trueop0, 0)))
    4921                 :     1447875 :                   .is_constant (&l0))
    4922                 :     2895750 :               && (GET_MODE_NUNITS (GET_MODE (XEXP (trueop0, 1)))
    4923                 :     1447875 :                   .is_constant (&l1))
    4924                 :     3759845 :               && CONST_INT_P (XVECEXP (trueop1, 0, 0)))
    4925                 :             :             {
    4926                 :     1447875 :               rtx subop0 = XEXP (trueop0, 0);
    4927                 :     1447875 :               rtx subop1 = XEXP (trueop0, 1);
    4928                 :     1447875 :               machine_mode mode0 = GET_MODE (subop0);
    4929                 :     1447875 :               machine_mode mode1 = GET_MODE (subop1);
    4930                 :     1447875 :               int i0 = INTVAL (XVECEXP (trueop1, 0, 0));
    4931                 :     1447875 :               if (i0 == 0 && !side_effects_p (op1) && mode == mode0)
    4932                 :             :                 {
    4933                 :      927914 :                   bool success = true;
    4934                 :      927914 :                   for (int i = 1; i < l0; ++i)
    4935                 :             :                     {
    4936                 :      927625 :                       rtx j = XVECEXP (trueop1, 0, i);
    4937                 :      927625 :                       if (!CONST_INT_P (j) || INTVAL (j) != i)
    4938                 :             :                         {
    4939                 :             :                           success = false;
    4940                 :             :                           break;
    4941                 :             :                         }
    4942                 :             :                     }
    4943                 :      844919 :                   if (success)
    4944                 :             :                     return subop0;
    4945                 :             :                 }
    4946                 :     1447586 :               if (i0 == l0 && !side_effects_p (op0) && mode == mode1)
    4947                 :             :                 {
    4948                 :         440 :                   bool success = true;
    4949                 :         440 :                   for (int i = 1; i < l1; ++i)
    4950                 :             :                     {
    4951                 :         404 :                       rtx j = XVECEXP (trueop1, 0, i);
    4952                 :         404 :                       if (!CONST_INT_P (j) || INTVAL (j) != i0 + i)
    4953                 :             :                         {
    4954                 :             :                           success = false;
    4955                 :             :                           break;
    4956                 :             :                         }
    4957                 :             :                     }
    4958                 :          65 :                   if (success)
    4959                 :             :                     return subop1;
    4960                 :             :                 }
    4961                 :             :             }
    4962                 :             : 
    4963                 :             :           /* Simplify vec_select of a subreg of X to just a vec_select of X
    4964                 :             :              when X has same component mode as vec_select.  */
    4965                 :     2311645 :           unsigned HOST_WIDE_INT subreg_offset = 0;
    4966                 :     2311645 :           if (GET_CODE (trueop0) == SUBREG
    4967                 :      345183 :               && GET_MODE_INNER (mode)
    4968                 :      690366 :                  == GET_MODE_INNER (GET_MODE (SUBREG_REG (trueop0)))
    4969                 :       27010 :               && GET_MODE_NUNITS (mode).is_constant (&l1)
    4970                 :     2656828 :               && constant_multiple_p (subreg_memory_offset (trueop0),
    4971                 :       27010 :                                       GET_MODE_UNIT_BITSIZE (mode),
    4972                 :             :                                       &subreg_offset))
    4973                 :             :             {
    4974                 :       13505 :               poly_uint64 nunits
    4975                 :       27010 :                 = GET_MODE_NUNITS (GET_MODE (SUBREG_REG (trueop0)));
    4976                 :       13505 :               bool success = true;
    4977                 :       78483 :               for (int i = 0; i != l1; i++)
    4978                 :             :                 {
    4979                 :       75223 :                   rtx idx = XVECEXP (trueop1, 0, i);
    4980                 :       75223 :                   if (!CONST_INT_P (idx)
    4981                 :       75223 :                       || maybe_ge (UINTVAL (idx) + subreg_offset, nunits))
    4982                 :             :                     {
    4983                 :             :                       success = false;
    4984                 :             :                       break;
    4985                 :             :                     }
    4986                 :             :                 }
    4987                 :             : 
    4988                 :       13505 :               if (success)
    4989                 :             :                 {
    4990                 :        3260 :                   rtx par = trueop1;
    4991                 :        3260 :                   if (subreg_offset)
    4992                 :             :                     {
    4993                 :           0 :                       rtvec vec = rtvec_alloc (l1);
    4994                 :           0 :                       for (int i = 0; i < l1; i++)
    4995                 :           0 :                         RTVEC_ELT (vec, i)
    4996                 :           0 :                           = GEN_INT (INTVAL (XVECEXP (trueop1, 0, i))
    4997                 :             :                                      + subreg_offset);
    4998                 :           0 :                       par = gen_rtx_PARALLEL (VOIDmode, vec);
    4999                 :             :                     }
    5000                 :        3260 :                   return gen_rtx_VEC_SELECT (mode, SUBREG_REG (trueop0), par);
    5001                 :             :                 }
    5002                 :             :             }
    5003                 :             :         }
    5004                 :             : 
    5005                 :     3077230 :       if (XVECLEN (trueop1, 0) == 1
    5006                 :      768929 :           && CONST_INT_P (XVECEXP (trueop1, 0, 0))
    5007                 :      768929 :           && GET_CODE (trueop0) == VEC_CONCAT)
    5008                 :             :         {
    5009                 :        1110 :           rtx vec = trueop0;
    5010                 :        2220 :           offset = INTVAL (XVECEXP (trueop1, 0, 0)) * GET_MODE_SIZE (mode);
    5011                 :             : 
    5012                 :             :           /* Try to find the element in the VEC_CONCAT.  */
    5013                 :        1110 :           while (GET_MODE (vec) != mode
    5014                 :        2220 :                  && GET_CODE (vec) == VEC_CONCAT)
    5015                 :             :             {
    5016                 :        1110 :               poly_int64 vec_size;
    5017                 :             : 
    5018                 :        1110 :               if (CONST_INT_P (XEXP (vec, 0)))
    5019                 :             :                 {
    5020                 :             :                   /* vec_concat of two const_ints doesn't make sense with
    5021                 :             :                      respect to modes.  */
    5022                 :           1 :                   if (CONST_INT_P (XEXP (vec, 1)))
    5023                 :   346486628 :                     return 0;
    5024                 :             : 
    5025                 :           1 :                   vec_size = GET_MODE_SIZE (GET_MODE (trueop0))
    5026                 :           3 :                              - GET_MODE_SIZE (GET_MODE (XEXP (vec, 1)));
    5027                 :             :                 }
    5028                 :             :               else
    5029                 :        2218 :                 vec_size = GET_MODE_SIZE (GET_MODE (XEXP (vec, 0)));
    5030                 :             : 
    5031                 :        1110 :               if (known_lt (offset, vec_size))
    5032                 :             :                 vec = XEXP (vec, 0);
    5033                 :         273 :               else if (known_ge (offset, vec_size))
    5034                 :             :                 {
    5035                 :         273 :                   offset -= vec_size;
    5036                 :         273 :                   vec = XEXP (vec, 1);
    5037                 :             :                 }
    5038                 :             :               else
    5039                 :             :                 break;
    5040                 :        1110 :               vec = avoid_constant_pool_reference (vec);
    5041                 :             :             }
    5042                 :             : 
    5043                 :        1110 :           if (GET_MODE (vec) == mode)
    5044                 :             :             return vec;
    5045                 :             :         }
    5046                 :             : 
    5047                 :             :       /* If we select elements in a vec_merge that all come from the same
    5048                 :             :          operand, select from that operand directly.  */
    5049                 :     3076326 :       if (GET_CODE (op0) == VEC_MERGE)
    5050                 :             :         {
    5051                 :        7245 :           rtx trueop02 = avoid_constant_pool_reference (XEXP (op0, 2));
    5052                 :        7245 :           if (CONST_INT_P (trueop02))
    5053                 :             :             {
    5054                 :        2465 :               unsigned HOST_WIDE_INT sel = UINTVAL (trueop02);
    5055                 :        2465 :               bool all_operand0 = true;
    5056                 :        2465 :               bool all_operand1 = true;
    5057                 :        9044 :               for (int i = 0; i < XVECLEN (trueop1, 0); i++)
    5058                 :             :                 {
    5059                 :        6579 :                   rtx j = XVECEXP (trueop1, 0, i);
    5060                 :        6579 :                   if (sel & (HOST_WIDE_INT_1U << UINTVAL (j)))
    5061                 :             :                     all_operand1 = false;
    5062                 :             :                   else
    5063                 :        3230 :                     all_operand0 = false;
    5064                 :             :                 }
    5065                 :        2465 :               if (all_operand0 && !side_effects_p (XEXP (op0, 1)))
    5066                 :         732 :                 return simplify_gen_binary (VEC_SELECT, mode, XEXP (op0, 0), op1);
    5067                 :        1733 :               if (all_operand1 && !side_effects_p (XEXP (op0, 0)))
    5068                 :          22 :                 return simplify_gen_binary (VEC_SELECT, mode, XEXP (op0, 1), op1);
    5069                 :             :             }
    5070                 :             :         }
    5071                 :             : 
    5072                 :             :       /* If we have two nested selects that are inverses of each
    5073                 :             :          other, replace them with the source operand.  */
    5074                 :     3075572 :       if (GET_CODE (trueop0) == VEC_SELECT
    5075                 :       67932 :           && GET_MODE (XEXP (trueop0, 0)) == mode)
    5076                 :             :         {
    5077                 :        1275 :           rtx op0_subop1 = XEXP (trueop0, 1);
    5078                 :        1275 :           gcc_assert (GET_CODE (op0_subop1) == PARALLEL);
    5079                 :        2550 :           gcc_assert (known_eq (XVECLEN (trueop1, 0), GET_MODE_NUNITS (mode)));
    5080                 :             : 
    5081                 :             :           /* Apply the outer ordering vector to the inner one.  (The inner
    5082                 :             :              ordering vector is expressly permitted to be of a different
    5083                 :             :              length than the outer one.)  If the result is { 0, 1, ..., n-1 }
    5084                 :             :              then the two VEC_SELECTs cancel.  */
    5085                 :        1581 :           for (int i = 0; i < XVECLEN (trueop1, 0); ++i)
    5086                 :             :             {
    5087                 :        1581 :               rtx x = XVECEXP (trueop1, 0, i);
    5088                 :        1581 :               if (!CONST_INT_P (x))
    5089                 :             :                 return 0;
    5090                 :        1581 :               rtx y = XVECEXP (op0_subop1, 0, INTVAL (x));
    5091                 :        1581 :               if (!CONST_INT_P (y) || i != INTVAL (y))
    5092                 :             :                 return 0;
    5093                 :             :             }
    5094                 :             :           return XEXP (trueop0, 0);
    5095                 :             :         }
    5096                 :             : 
    5097                 :             :       return 0;
    5098                 :     4175830 :     case VEC_CONCAT:
    5099                 :     4175830 :       {
    5100                 :     4175830 :         machine_mode op0_mode = (GET_MODE (trueop0) != VOIDmode
    5101                 :     4175830 :                                       ? GET_MODE (trueop0)
    5102                 :      169596 :                                       : GET_MODE_INNER (mode));
    5103                 :     4175830 :         machine_mode op1_mode = (GET_MODE (trueop1) != VOIDmode
    5104                 :     4175830 :                                       ? GET_MODE (trueop1)
    5105                 :      218314 :                                       : GET_MODE_INNER (mode));
    5106                 :             : 
    5107                 :     4175830 :         gcc_assert (VECTOR_MODE_P (mode));
    5108                 :    16703320 :         gcc_assert (known_eq (GET_MODE_SIZE (op0_mode)
    5109                 :             :                               + GET_MODE_SIZE (op1_mode),
    5110                 :             :                               GET_MODE_SIZE (mode)));
    5111                 :             : 
    5112                 :     4175830 :         if (VECTOR_MODE_P (op0_mode))
    5113                 :     5461629 :           gcc_assert (GET_MODE_INNER (mode)
    5114                 :             :                       == GET_MODE_INNER (op0_mode));
    5115                 :             :         else
    5116                 :     4710574 :           gcc_assert (GET_MODE_INNER (mode) == op0_mode);
    5117                 :             : 
    5118                 :     4175830 :         if (VECTOR_MODE_P (op1_mode))
    5119                 :     5461629 :           gcc_assert (GET_MODE_INNER (mode)
    5120                 :             :                       == GET_MODE_INNER (op1_mode));
    5121                 :             :         else
    5122                 :     4710574 :           gcc_assert (GET_MODE_INNER (mode) == op1_mode);
    5123                 :             : 
    5124                 :     4175830 :         unsigned int n_elts, in_n_elts;
    5125                 :     4175830 :         if ((GET_CODE (trueop0) == CONST_VECTOR
    5126                 :     4175830 :              || CONST_SCALAR_INT_P (trueop0)
    5127                 :     3985047 :              || CONST_DOUBLE_AS_FLOAT_P (trueop0))
    5128                 :      191936 :             && (GET_CODE (trueop1) == CONST_VECTOR
    5129                 :      191936 :                 || CONST_SCALAR_INT_P (trueop1)
    5130                 :      184981 :                 || CONST_DOUBLE_AS_FLOAT_P (trueop1))
    5131                 :       13910 :             && GET_MODE_NUNITS (mode).is_constant (&n_elts)
    5132                 :     4182785 :             && GET_MODE_NUNITS (op0_mode).is_constant (&in_n_elts))
    5133                 :             :           {
    5134                 :        6955 :             rtvec v = rtvec_alloc (n_elts);
    5135                 :        6955 :             unsigned int i;
    5136                 :      120922 :             for (i = 0; i < n_elts; i++)
    5137                 :             :               {
    5138                 :      107012 :                 if (i < in_n_elts)
    5139                 :             :                   {
    5140                 :       53410 :                     if (!VECTOR_MODE_P (op0_mode))
    5141                 :           0 :                       RTVEC_ELT (v, i) = trueop0;
    5142                 :             :                     else
    5143                 :       53410 :                       RTVEC_ELT (v, i) = CONST_VECTOR_ELT (trueop0, i);
    5144                 :             :                   }
    5145                 :             :                 else
    5146                 :             :                   {
    5147                 :       53602 :                     if (!VECTOR_MODE_P (op1_mode))
    5148                 :           0 :                       RTVEC_ELT (v, i) = trueop1;
    5149                 :             :                     else
    5150                 :       53602 :                       RTVEC_ELT (v, i) = CONST_VECTOR_ELT (trueop1,
    5151                 :             :                                                            i - in_n_elts);
    5152                 :             :                   }
    5153                 :             :               }
    5154                 :             : 
    5155                 :        6955 :             return gen_rtx_CONST_VECTOR (mode, v);
    5156                 :             :           }
    5157                 :             : 
    5158                 :             :         /* Try to merge two VEC_SELECTs from the same vector into a single one.
    5159                 :             :            Restrict the transformation to avoid generating a VEC_SELECT with a
    5160                 :             :            mode unrelated to its operand.  */
    5161                 :     4168875 :         if (GET_CODE (trueop0) == VEC_SELECT
    5162                 :      115331 :             && GET_CODE (trueop1) == VEC_SELECT
    5163                 :       23302 :             && rtx_equal_p (XEXP (trueop0, 0), XEXP (trueop1, 0))
    5164                 :     4185142 :             && GET_MODE_INNER (GET_MODE (XEXP (trueop0, 0)))
    5165                 :       32534 :                == GET_MODE_INNER(mode))
    5166                 :             :           {
    5167                 :       16267 :             rtx par0 = XEXP (trueop0, 1);
    5168                 :       16267 :             rtx par1 = XEXP (trueop1, 1);
    5169                 :       16267 :             int len0 = XVECLEN (par0, 0);
    5170                 :       16267 :             int len1 = XVECLEN (par1, 0);
    5171                 :       16267 :             rtvec vec = rtvec_alloc (len0 + len1);
    5172                 :       98619 :             for (int i = 0; i < len0; i++)
    5173                 :       82352 :               RTVEC_ELT (vec, i) = XVECEXP (par0, 0, i);
    5174                 :       98619 :             for (int i = 0; i < len1; i++)
    5175                 :       82352 :               RTVEC_ELT (vec, len0 + i) = XVECEXP (par1, 0, i);
    5176                 :       16267 :             return simplify_gen_binary (VEC_SELECT, mode, XEXP (trueop0, 0),
    5177                 :       16267 :                                         gen_rtx_PARALLEL (VOIDmode, vec));
    5178                 :             :           }
    5179                 :             :         /* (vec_concat:
    5180                 :             :              (subreg_lowpart:N OP)
    5181                 :             :              (vec_select:N OP P))  -->  OP when P selects the high half
    5182                 :             :             of the OP.  */
    5183                 :     4152608 :         if (GET_CODE (trueop0) == SUBREG
    5184                 :      457485 :             && subreg_lowpart_p (trueop0)
    5185                 :      456641 :             && GET_CODE (trueop1) == VEC_SELECT
    5186                 :           5 :             && SUBREG_REG (trueop0) == XEXP (trueop1, 0)
    5187                 :           0 :             && !side_effects_p (XEXP (trueop1, 0))
    5188                 :     4152608 :             && vec_series_highpart_p (op1_mode, mode, XEXP (trueop1, 1)))
    5189                 :           0 :           return XEXP (trueop1, 0);
    5190                 :             :       }
    5191                 :             :       return 0;
    5192                 :             : 
    5193                 :           0 :     default:
    5194                 :           0 :       gcc_unreachable ();
    5195                 :             :     }
    5196                 :             : 
    5197                 :   338644753 :   if (mode == GET_MODE (op0)
    5198                 :   293175770 :       && mode == GET_MODE (op1)
    5199                 :    89398717 :       && vec_duplicate_p (op0, &elt0)
    5200                 :   338753732 :       && vec_duplicate_p (op1, &elt1))
    5201                 :             :     {
    5202                 :             :       /* Try applying the operator to ELT and see if that simplifies.
    5203                 :             :          We can duplicate the result if so.
    5204                 :             : 
    5205                 :             :          The reason we don't use simplify_gen_binary is that it isn't
    5206                 :             :          necessarily a win to convert things like:
    5207                 :             : 
    5208                 :             :            (plus:V (vec_duplicate:V (reg:S R1))
    5209                 :             :                    (vec_duplicate:V (reg:S R2)))
    5210                 :             : 
    5211                 :             :          to:
    5212                 :             : 
    5213                 :             :            (vec_duplicate:V (plus:S (reg:S R1) (reg:S R2)))
    5214                 :             : 
    5215                 :             :          The first might be done entirely in vector registers while the
    5216                 :             :          second might need a move between register files.  */
    5217                 :          82 :       tem = simplify_binary_operation (code, GET_MODE_INNER (mode),
    5218                 :             :                                        elt0, elt1);
    5219                 :          41 :       if (tem)
    5220                 :           2 :         return gen_vec_duplicate (mode, tem);
    5221                 :             :     }
    5222                 :             : 
    5223                 :             :   return 0;
    5224                 :             : }
    5225                 :             : 
    5226                 :             : /* Return true if binary operation OP distributes over addition in operand
    5227                 :             :    OPNO, with the other operand being held constant.  OPNO counts from 1.  */
    5228                 :             : 
    5229                 :             : static bool
    5230                 :       24973 : distributes_over_addition_p (rtx_code op, int opno)
    5231                 :             : {
    5232                 :           0 :   switch (op)
    5233                 :             :     {
    5234                 :             :     case PLUS:
    5235                 :             :     case MINUS:
    5236                 :             :     case MULT:
    5237                 :             :       return true;
    5238                 :             : 
    5239                 :           0 :     case ASHIFT:
    5240                 :           0 :       return opno == 1;
    5241                 :             : 
    5242                 :           0 :     default:
    5243                 :           0 :       return false;
    5244                 :             :     }
    5245                 :             : }
    5246                 :             : 
    5247                 :             : rtx
    5248                 :   434954561 : simplify_const_binary_operation (enum rtx_code code, machine_mode mode,
    5249                 :             :                                  rtx op0, rtx op1)
    5250                 :             : {
    5251                 :   434954561 :   if (VECTOR_MODE_P (mode)
    5252                 :    13902406 :       && code != VEC_CONCAT
    5253                 :     9723076 :       && GET_CODE (op0) == CONST_VECTOR
    5254                 :      203985 :       && GET_CODE (op1) == CONST_VECTOR)
    5255                 :             :     {
    5256                 :       25701 :       bool step_ok_p;
    5257                 :       25701 :       if (CONST_VECTOR_STEPPED_P (op0)
    5258                 :       25701 :           && CONST_VECTOR_STEPPED_P (op1))
    5259                 :             :         /* We can operate directly on the encoding if:
    5260                 :             : 
    5261                 :             :               a3 - a2 == a2 - a1 && b3 - b2 == b2 - b1
    5262                 :             :             implies
    5263                 :             :               (a3 op b3) - (a2 op b2) == (a2 op b2) - (a1 op b1)
    5264                 :             : 
    5265                 :             :            Addition and subtraction are the supported operators
    5266                 :             :            for which this is true.  */
    5267                 :         728 :         step_ok_p = (code == PLUS || code == MINUS);
    5268                 :       24973 :       else if (CONST_VECTOR_STEPPED_P (op0))
    5269                 :             :         /* We can operate directly on stepped encodings if:
    5270                 :             : 
    5271                 :             :              a3 - a2 == a2 - a1
    5272                 :             :            implies:
    5273                 :             :              (a3 op c) - (a2 op c) == (a2 op c) - (a1 op c)
    5274                 :             : 
    5275                 :             :            which is true if (x -> x op c) distributes over addition.  */
    5276                 :        1007 :         step_ok_p = distributes_over_addition_p (code, 1);
    5277                 :             :       else
    5278                 :             :         /* Similarly in reverse.  */
    5279                 :       23966 :         step_ok_p = distributes_over_addition_p (code, 2);
    5280                 :       25701 :       rtx_vector_builder builder;
    5281                 :       25701 :       if (!builder.new_binary_operation (mode, op0, op1, step_ok_p))
    5282                 :             :         return 0;
    5283                 :             : 
    5284                 :       25701 :       unsigned int count = builder.encoded_nelts ();
    5285                 :      102311 :       for (unsigned int i = 0; i < count; i++)
    5286                 :             :         {
    5287                 :      153488 :           rtx x = simplify_binary_operation (code, GET_MODE_INNER (mode),
    5288                 :             :                                              CONST_VECTOR_ELT (op0, i),
    5289                 :       76744 :                                              CONST_VECTOR_ELT (op1, i));
    5290                 :       76744 :           if (!x || !valid_for_const_vector_p (mode, x))
    5291                 :         134 :             return 0;
    5292                 :       76610 :           builder.quick_push (x);
    5293                 :             :         }
    5294                 :       25567 :       return builder.build ();
    5295                 :       25701 :     }
    5296                 :             : 
    5297                 :   434928860 :   if (VECTOR_MODE_P (mode)
    5298                 :    13876705 :       && code == VEC_CONCAT
    5299                 :     4179330 :       && (CONST_SCALAR_INT_P (op0)
    5300                 :     4007562 :           || CONST_FIXED_P (op0)
    5301                 :     4007562 :           || CONST_DOUBLE_AS_FLOAT_P (op0))
    5302                 :      174249 :       && (CONST_SCALAR_INT_P (op1)
    5303                 :      172077 :           || CONST_DOUBLE_AS_FLOAT_P (op1)
    5304                 :      170749 :           || CONST_FIXED_P (op1)))
    5305                 :             :     {
    5306                 :             :       /* Both inputs have a constant number of elements, so the result
    5307                 :             :          must too.  */
    5308                 :        3500 :       unsigned n_elts = GET_MODE_NUNITS (mode).to_constant ();
    5309                 :        3500 :       rtvec v = rtvec_alloc (n_elts);
    5310                 :             : 
    5311                 :        3500 :       gcc_assert (n_elts >= 2);
    5312                 :        3500 :       if (n_elts == 2)
    5313                 :             :         {
    5314                 :        3500 :           gcc_assert (GET_CODE (op0) != CONST_VECTOR);
    5315                 :        3500 :           gcc_assert (GET_CODE (op1) != CONST_VECTOR);
    5316                 :             : 
    5317                 :        3500 :           RTVEC_ELT (v, 0) = op0;
    5318                 :        3500 :           RTVEC_ELT (v, 1) = op1;
    5319                 :             :         }
    5320                 :             :       else
    5321                 :             :         {
    5322                 :           0 :           unsigned op0_n_elts = GET_MODE_NUNITS (GET_MODE (op0)).to_constant ();
    5323                 :           0 :           unsigned op1_n_elts = GET_MODE_NUNITS (GET_MODE (op1)).to_constant ();
    5324                 :           0 :           unsigned i;
    5325                 :             : 
    5326                 :           0 :           gcc_assert (GET_CODE (op0) == CONST_VECTOR);
    5327                 :           0 :           gcc_assert (GET_CODE (op1) == CONST_VECTOR);
    5328                 :           0 :           gcc_assert (op0_n_elts + op1_n_elts == n_elts);
    5329                 :             : 
    5330                 :           0 :           for (i = 0; i < op0_n_elts; ++i)
    5331                 :           0 :             RTVEC_ELT (v, i) = CONST_VECTOR_ELT (op0, i);
    5332                 :           0 :           for (i = 0; i < op1_n_elts; ++i)
    5333                 :           0 :             RTVEC_ELT (v, op0_n_elts+i) = CONST_VECTOR_ELT (op1, i);
    5334                 :             :         }
    5335                 :             : 
    5336                 :        3500 :       return gen_rtx_CONST_VECTOR (mode, v);
    5337                 :             :     }
    5338                 :             : 
    5339                 :   423863315 :   if (VECTOR_MODE_P (mode)
    5340                 :    13873205 :       && GET_CODE (op0) == CONST_VECTOR
    5341                 :      199471 :       && (CONST_SCALAR_INT_P (op1) || CONST_DOUBLE_AS_FLOAT_P (op1))
    5342                 :   434925360 :       && (CONST_VECTOR_DUPLICATE_P (op0)
    5343                 :             :           || CONST_VECTOR_NUNITS (op0).is_constant ()))
    5344                 :             :     {
    5345                 :      138819 :       switch (code)
    5346                 :             :         {
    5347                 :      138819 :         case PLUS:
    5348                 :      138819 :         case MINUS:
    5349                 :      138819 :         case MULT:
    5350                 :      138819 :         case DIV:
    5351                 :      138819 :         case MOD:
    5352                 :      138819 :         case UDIV:
    5353                 :      138819 :         case UMOD:
    5354                 :      138819 :         case AND:
    5355                 :      138819 :         case IOR:
    5356                 :      138819 :         case XOR:
    5357                 :      138819 :         case SMIN:
    5358                 :      138819 :         case SMAX:
    5359                 :      138819 :         case UMIN:
    5360                 :      138819 :         case UMAX:
    5361                 :      138819 :         case LSHIFTRT:
    5362                 :      138819 :         case ASHIFTRT:
    5363                 :      138819 :         case ASHIFT:
    5364                 :      138819 :         case ROTATE:
    5365                 :      138819 :         case ROTATERT:
    5366                 :      138819 :         case SS_PLUS:
    5367                 :      138819 :         case US_PLUS:
    5368                 :      138819 :         case SS_MINUS:
    5369                 :      138819 :         case US_MINUS:
    5370                 :      138819 :         case SS_ASHIFT:
    5371                 :      138819 :         case US_ASHIFT:
    5372                 :      138819 :         case COPYSIGN:
    5373                 :      138819 :           break;
    5374                 :             :         default:
    5375                 :             :           return NULL_RTX;
    5376                 :             :         }
    5377                 :             : 
    5378                 :      138819 :       unsigned int npatterns = (CONST_VECTOR_DUPLICATE_P (op0)
    5379                 :      138819 :                                 ? CONST_VECTOR_NPATTERNS (op0)
    5380                 :       14876 :                                 : CONST_VECTOR_NUNITS (op0).to_constant ());
    5381                 :      138819 :       rtx_vector_builder builder (mode, npatterns, 1);
    5382                 :      289798 :       for (unsigned i = 0; i < npatterns; i++)
    5383                 :             :         {
    5384                 :      301958 :           rtx x = simplify_binary_operation (code, GET_MODE_INNER (mode),
    5385                 :      150979 :                                              CONST_VECTOR_ELT (op0, i), op1);
    5386                 :      150979 :           if (!x || !valid_for_const_vector_p (mode, x))
    5387                 :           0 :             return 0;
    5388                 :      150979 :           builder.quick_push (x);
    5389                 :             :         }
    5390                 :      138819 :       return builder.build ();
    5391                 :             :     }
    5392                 :             : 
    5393                 :   434786541 :   if (SCALAR_FLOAT_MODE_P (mode)
    5394                 :     6415520 :       && CONST_DOUBLE_AS_FLOAT_P (op0)
    5395                 :      109387 :       && CONST_DOUBLE_AS_FLOAT_P (op1)
    5396                 :       47806 :       && mode == GET_MODE (op0) && mode == GET_MODE (op1))
    5397                 :             :     {
    5398                 :       47806 :       if (code == AND
    5399                 :             :           || code == IOR
    5400                 :       47806 :           || code == XOR)
    5401                 :             :         {
    5402                 :       38466 :           long tmp0[4];
    5403                 :       38466 :           long tmp1[4];
    5404                 :       38466 :           REAL_VALUE_TYPE r;
    5405                 :       38466 :           int i;
    5406                 :             : 
    5407                 :       38466 :           real_to_target (tmp0, CONST_DOUBLE_REAL_VALUE (op0),
    5408                 :       38466 :                           GET_MODE (op0));
    5409                 :       38466 :           real_to_target (tmp1, CONST_DOUBLE_REAL_VALUE (op1),
    5410                 :       38466 :                           GET_MODE (op1));
    5411                 :      192330 :           for (i = 0; i < 4; i++)
    5412                 :             :             {
    5413                 :      153864 :               switch (code)
    5414                 :             :               {
    5415                 :      149504 :               case AND:
    5416                 :      149504 :                 tmp0[i] &= tmp1[i];
    5417                 :      149504 :                 break;
    5418                 :        2416 :               case IOR:
    5419                 :        2416 :                 tmp0[i] |= tmp1[i];
    5420                 :        2416 :                 break;
    5421                 :        1944 :               case XOR:
    5422                 :        1944 :                 tmp0[i] ^= tmp1[i];
    5423                 :        1944 :                 break;
    5424                 :             :               default:
    5425                 :             :                 gcc_unreachable ();
    5426                 :             :               }
    5427                 :             :             }
    5428                 :       38466 :            real_from_target (&r, tmp0, mode);
    5429                 :       38466 :            return const_double_from_real_value (r, mode);
    5430                 :             :         }
    5431                 :        9340 :       else if (code == COPYSIGN)
    5432                 :             :         {
    5433                 :           0 :           REAL_VALUE_TYPE f0, f1;
    5434                 :           0 :           real_convert (&f0, mode, CONST_DOUBLE_REAL_VALUE (op0));
    5435                 :           0 :           real_convert (&f1, mode, CONST_DOUBLE_REAL_VALUE (op1));
    5436                 :           0 :           real_copysign (&f0, &f1);
    5437                 :           0 :           return const_double_from_real_value (f0, mode);
    5438                 :             :         }
    5439                 :             :       else
    5440                 :             :         {
    5441                 :        9340 :           REAL_VALUE_TYPE f0, f1, value, result;
    5442                 :        9340 :           const REAL_VALUE_TYPE *opr0, *opr1;
    5443                 :        9340 :           bool inexact;
    5444                 :             : 
    5445                 :        9340 :           opr0 = CONST_DOUBLE_REAL_VALUE (op0);
    5446                 :        9340 :           opr1 = CONST_DOUBLE_REAL_VALUE (op1);
    5447                 :             : 
    5448                 :        9340 :           if (HONOR_SNANS (mode)
    5449                 :        9340 :               && (REAL_VALUE_ISSIGNALING_NAN (*opr0)
    5450                 :         803 :                   || REAL_VALUE_ISSIGNALING_NAN (*opr1)))
    5451                 :          10 :             return 0;
    5452                 :             : 
    5453                 :        9330 :           real_convert (&f0, mode, opr0);
    5454                 :        9330 :           real_convert (&f1, mode, opr1);
    5455                 :             : 
    5456                 :        9330 :           if (code == DIV
    5457                 :        4191 :               && real_equal (&f1, &dconst0)
    5458                 :       13036 :               && (flag_trapping_math || ! MODE_HAS_INFINITIES (mode)))
    5459                 :        3702 :             return 0;
    5460                 :             : 
    5461                 :       28034 :           if (MODE_HAS_INFINITIES (mode) && HONOR_NANS (mode)
    5462                 :        5533 :               && flag_trapping_math
    5463                 :        5457 :               && REAL_VALUE_ISINF (f0) && REAL_VALUE_ISINF (f1))
    5464                 :             :             {
    5465                 :           9 :               int s0 = REAL_VALUE_NEGATIVE (f0);
    5466                 :           9 :               int s1 = REAL_VALUE_NEGATIVE (f1);
    5467                 :             : 
    5468                 :           9 :               switch (code)
    5469                 :             :                 {
    5470                 :           0 :                 case PLUS:
    5471                 :             :                   /* Inf + -Inf = NaN plus exception.  */
    5472                 :           0 :                   if (s0 != s1)
    5473                 :             :                     return 0;
    5474                 :             :                   break;
    5475                 :           0 :                 case MINUS:
    5476                 :             :                   /* Inf - Inf = NaN plus exception.  */
    5477                 :           0 :                   if (s0 == s1)
    5478                 :             :                     return 0;
    5479                 :             :                   break;
    5480                 :             :                 case DIV:
    5481                 :             :                   /* Inf / Inf = NaN plus exception.  */
    5482                 :             :                   return 0;
    5483                 :             :                 default:
    5484                 :             :                   break;
    5485                 :             :                 }
    5486                 :             :             }
    5487                 :             : 
    5488                 :        8126 :           if (code == MULT && MODE_HAS_INFINITIES (mode) && HONOR_NANS (mode)
    5489                 :        1995 :               && flag_trapping_math
    5490                 :        7568 :               && ((REAL_VALUE_ISINF (f0) && real_equal (&f1, &dconst0))
    5491                 :        1941 :                   || (REAL_VALUE_ISINF (f1)
    5492                 :          10 :                       && real_equal (&f0, &dconst0))))
    5493                 :             :             /* Inf * 0 = NaN plus exception.  */
    5494                 :          18 :             return 0;
    5495                 :             : 
    5496                 :        5601 :           inexact = real_arithmetic (&value, rtx_to_tree_code (code),
    5497                 :             :                                      &f0, &f1);
    5498                 :        5601 :           real_convert (&result, mode, &value);
    5499                 :             : 
    5500                 :             :           /* Don't constant fold this floating point operation if
    5501                 :             :              the result has overflowed and flag_trapping_math.  */
    5502                 :             : 
    5503                 :        5601 :           if (flag_trapping_math
    5504                 :       21718 :               && MODE_HAS_INFINITIES (mode)
    5505                 :        5430 :               && REAL_VALUE_ISINF (result)
    5506                 :        1104 :               && !REAL_VALUE_ISINF (f0)
    5507                 :        6691 :               && !REAL_VALUE_ISINF (f1))
    5508                 :             :             /* Overflow plus exception.  */
    5509                 :        1090 :             return 0;
    5510                 :             : 
    5511                 :             :           /* Don't constant fold this floating point operation if the
    5512                 :             :              result may dependent upon the run-time rounding mode and
    5513                 :             :              flag_rounding_math is set, or if GCC's software emulation
    5514                 :             :              is unable to accurately represent the result.  */
    5515                 :             : 
    5516                 :        4511 :           if ((flag_rounding_math
    5517                 :       28892 :                || (MODE_COMPOSITE_P (mode) && !flag_unsafe_math_optimizations))
    5518                 :        4511 :               && (inexact || !real_identical (&result, &value)))
    5519                 :         378 :             return NULL_RTX;
    5520                 :             : 
    5521                 :        4133 :           return const_double_from_real_value (result, mode);
    5522                 :             :         }
    5523                 :             :     }
    5524                 :             : 
    5525                 :             :   /* We can fold some multi-word operations.  */
    5526                 :   434738735 :   scalar_int_mode int_mode;
    5527                 :   434738735 :   if (is_a <scalar_int_mode> (mode, &int_mode)
    5528                 :   374117271 :       && CONST_SCALAR_INT_P (op0)
    5529                 :    36705058 :       && CONST_SCALAR_INT_P (op1)
    5530                 :    30869756 :       && GET_MODE_PRECISION (int_mode) <= MAX_BITSIZE_MODE_ANY_INT)
    5531                 :             :     {
    5532                 :    30869756 :       wide_int result;
    5533                 :    30869756 :       wi::overflow_type overflow;
    5534                 :    30869756 :       rtx_mode_t pop0 = rtx_mode_t (op0, int_mode);
    5535                 :    30869756 :       rtx_mode_t pop1 = rtx_mode_t (op1, int_mode);
    5536                 :             : 
    5537                 :             : #if TARGET_SUPPORTS_WIDE_INT == 0
    5538                 :             :       /* This assert keeps the simplification from producing a result
    5539                 :             :          that cannot be represented in a CONST_DOUBLE but a lot of
    5540                 :             :          upstream callers expect that this function never fails to
    5541                 :             :          simplify something and so you if you added this to the test
    5542                 :             :          above the code would die later anyway.  If this assert
    5543                 :             :          happens, you just need to make the port support wide int.  */
    5544                 :             :       gcc_assert (GET_MODE_PRECISION (int_mode) <= HOST_BITS_PER_DOUBLE_INT);
    5545                 :             : #endif
    5546                 :    30869756 :       switch (code)
    5547                 :             :         {
    5548                 :     1002792 :         case MINUS:
    5549                 :     1002792 :           result = wi::sub (pop0, pop1);
    5550                 :     1002792 :           break;
    5551                 :             : 
    5552                 :    24039257 :         case PLUS:
    5553                 :    24039257 :           result = wi::add (pop0, pop1);
    5554                 :    24039257 :           break;
    5555                 :             : 
    5556                 :      328004 :         case MULT:
    5557                 :      328004 :           result = wi::mul (pop0, pop1);
    5558                 :      328004 :           break;
    5559                 :             : 
    5560                 :        4707 :         case DIV:
    5561                 :        4707 :           result = wi::div_trunc (pop0, pop1, SIGNED, &overflow);
    5562                 :        4707 :           if (overflow)
    5563                 :             :             return NULL_RTX;
    5564                 :             :           break;
    5565                 :             : 
    5566                 :         224 :         case MOD:
    5567                 :         224 :           result = wi::mod_trunc (pop0, pop1, SIGNED, &overflow);
    5568                 :         224 :           if (overflow)
    5569                 :             :             return NULL_RTX;
    5570                 :             :           break;
    5571                 :             : 
    5572                 :        6423 :         case UDIV:
    5573                 :        6423 :           result = wi::div_trunc (pop0, pop1, UNSIGNED, &overflow);
    5574                 :        6423 :           if (overflow)
    5575                 :             :             return NULL_RTX;
    5576                 :             :           break;
    5577                 :             : 
    5578                 :        7514 :         case UMOD:
    5579                 :        7514 :           result = wi::mod_trunc (pop0, pop1, UNSIGNED, &overflow);
    5580                 :        7514 :           if (overflow)
    5581                 :             :             return NULL_RTX;
    5582                 :             :           break;
    5583                 :             : 
    5584                 :      486959 :         case AND:
    5585                 :      486959 :           result = wi::bit_and (pop0, pop1);
    5586                 :      486959 :           break;
    5587                 :             : 
    5588                 :      209698 :         case IOR:
    5589                 :      209698 :           result = wi::bit_or (pop0, pop1);
    5590                 :      209698 :           break;
    5591                 :             : 
    5592                 :       32652 :         case XOR:
    5593                 :       32652 :           result = wi::bit_xor (pop0, pop1);
    5594                 :       32652 :           break;
    5595                 :             : 
    5596                 :        1759 :         case SMIN:
    5597                 :        1759 :           result = wi::smin (pop0, pop1);
    5598                 :        1759 :           break;
    5599                 :             : 
    5600                 :        1811 :         case SMAX:
    5601                 :        1811 :           result = wi::smax (pop0, pop1);
    5602                 :        1811 :           break;
    5603                 :             : 
    5604                 :        3003 :         case UMIN:
    5605                 :        3003 :           result = wi::umin (pop0, pop1);
    5606                 :        3003 :           break;
    5607                 :             : 
    5608                 :        2568 :         case UMAX:
    5609                 :        2568 :           result = wi::umax (pop0, pop1);
    5610                 :        2568 :           break;
    5611                 :             : 
    5612                 :     4702645 :         case LSHIFTRT:
    5613                 :     4702645 :         case ASHIFTRT:
    5614                 :     4702645 :         case ASHIFT:
    5615                 :     4702645 :         case SS_ASHIFT:
    5616                 :     4702645 :         case US_ASHIFT:
    5617                 :     4702645 :           {
    5618                 :             :             /* The shift count might be in SImode while int_mode might
    5619                 :             :                be narrower.  On IA-64 it is even DImode.  If the shift
    5620                 :             :                count is too large and doesn't fit into int_mode, we'd
    5621                 :             :                ICE.  So, if int_mode is narrower than word, use
    5622                 :             :                word_mode for the shift count.  */
    5623                 :     4702645 :             if (GET_MODE (op1) == VOIDmode
    5624                 :     5173270 :                 && GET_MODE_PRECISION (int_mode) < BITS_PER_WORD)
    5625                 :     1399596 :               pop1 = rtx_mode_t (op1, word_mode);
    5626                 :             : 
    5627                 :     4702645 :             wide_int wop1 = pop1;
    5628                 :     4702645 :             if (SHIFT_COUNT_TRUNCATED)
    5629                 :             :               wop1 = wi::umod_trunc (wop1, GET_MODE_PRECISION (int_mode));
    5630                 :     4702645 :             else if (wi::geu_p (wop1, GET_MODE_PRECISION (int_mode)))
    5631                 :         120 :               return NULL_RTX;
    5632                 :             : 
    5633                 :     4702525 :             switch (code)
    5634                 :             :               {
    5635                 :     2509477 :               case LSHIFTRT:
    5636                 :     2509477 :                 result = wi::lrshift (pop0, wop1);
    5637                 :     2509477 :                 break;
    5638                 :             : 
    5639                 :       51588 :               case ASHIFTRT:
    5640                 :       51588 :                 result = wi::arshift (pop0, wop1);
    5641                 :       51588 :                 break;
    5642                 :             : 
    5643                 :     2141460 :               case ASHIFT:
    5644                 :     2141460 :                 result = wi::lshift (pop0, wop1);
    5645                 :     2141460 :                 break;
    5646                 :             : 
    5647                 :           0 :               case SS_ASHIFT:
    5648                 :           0 :                 if (wi::leu_p (wop1, wi::clrsb (pop0)))
    5649                 :           0 :                   result = wi::lshift (pop0, wop1);
    5650                 :           0 :                 else if (wi::neg_p (pop0))
    5651                 :           0 :                   result = wi::min_value (int_mode, SIGNED);
    5652                 :             :                 else
    5653                 :           0 :                   result = wi::max_value (int_mode, SIGNED);
    5654                 :             :                 break;
    5655                 :             : 
    5656                 :           0 :               case US_ASHIFT:
    5657                 :           0 :                 if (wi::eq_p (pop0, 0))
    5658                 :           0 :                   result = pop0;
    5659                 :           0 :                 else if (wi::leu_p (wop1, wi::clz (pop0)))
    5660                 :           0 :                   result = wi::lshift (pop0, wop1);
    5661                 :             :                 else
    5662                 :           0 :                   result = wi::max_value (int_mode, UNSIGNED);
    5663                 :             :                 break;
    5664                 :             : 
    5665                 :           0 :               default:
    5666                 :           0 :                 gcc_unreachable ();
    5667                 :             :               }
    5668                 :     4702525 :             break;
    5669                 :     4702645 :           }
    5670                 :       32592 :         case ROTATE:
    5671                 :       32592 :         case ROTATERT:
    5672                 :       32592 :           {
    5673                 :             :             /* The rotate count might be in SImode while int_mode might
    5674                 :             :                be narrower.  On IA-64 it is even DImode.  If the shift
    5675                 :             :                count is too large and doesn't fit into int_mode, we'd
    5676                 :             :                ICE.  So, if int_mode is narrower than word, use
    5677                 :             :                word_mode for the shift count.  */
    5678                 :       32592 :             if (GET_MODE (op1) == VOIDmode
    5679                 :       41455 :                 && GET_MODE_PRECISION (int_mode) < BITS_PER_WORD)
    5680                 :       19168 :               pop1 = rtx_mode_t (op1, word_mode);
    5681                 :             : 
    5682                 :       32592 :             if (wi::neg_p (pop1))
    5683                 :             :               return NULL_RTX;
    5684                 :             : 
    5685                 :       32522 :             switch (code)
    5686                 :             :               {
    5687                 :       11254 :               case ROTATE:
    5688                 :       11254 :                 result = wi::lrotate (pop0, pop1);
    5689                 :       11254 :                 break;
    5690                 :             : 
    5691                 :       21268 :               case ROTATERT:
    5692                 :       21268 :                 result = wi::rrotate (pop0, pop1);
    5693                 :       21268 :                 break;
    5694                 :             : 
    5695                 :           0 :               default:
    5696                 :           0 :                 gcc_unreachable ();
    5697                 :             :               }
    5698                 :             :             break;
    5699                 :             :           }
    5700                 :             : 
    5701                 :        1910 :         case SS_PLUS:
    5702                 :        1910 :           result = wi::add (pop0, pop1, SIGNED, &overflow);
    5703                 :        3764 :  clamp_signed_saturation:
    5704                 :        3764 :           if (overflow == wi::OVF_OVERFLOW)
    5705                 :         252 :             result = wi::max_value (GET_MODE_PRECISION (int_mode), SIGNED);
    5706                 :        3512 :           else if (overflow == wi::OVF_UNDERFLOW)
    5707                 :         227 :             result = wi::min_value (GET_MODE_PRECISION (int_mode), SIGNED);
    5708                 :        3285 :           else if (overflow != wi::OVF_NONE)
    5709                 :             :             return NULL_RTX;
    5710                 :             :           break;
    5711                 :             : 
    5712                 :        1860 :         case US_PLUS:
    5713                 :        1860 :           result = wi::add (pop0, pop1, UNSIGNED, &overflow);
    5714                 :        1860 :  clamp_unsigned_saturation:
    5715                 :        1860 :           if (overflow != wi::OVF_NONE)
    5716                 :         378 :             result = wi::max_value (GET_MODE_PRECISION (int_mode), UNSIGNED);
    5717                 :             :           break;
    5718                 :             : 
    5719                 :        1854 :         case SS_MINUS:
    5720                 :        1854 :           result = wi::sub (pop0, pop1, SIGNED, &overflow);
    5721                 :        1854 :           goto clamp_signed_saturation;
    5722                 :             : 
    5723                 :        1516 :         case US_MINUS:
    5724                 :        1516 :           result = wi::sub (pop0, pop1, UNSIGNED, &overflow);
    5725                 :        1516 :           if (overflow != wi::OVF_NONE)
    5726                 :         966 :             result = wi::min_value (GET_MODE_PRECISION (int_mode), UNSIGNED);
    5727                 :             :           break;
    5728                 :             : 
    5729                 :           0 :         case SS_MULT:
    5730                 :           0 :           result = wi::mul (pop0, pop1, SIGNED, &overflow);
    5731                 :           0 :           goto clamp_signed_saturation;
    5732                 :             : 
    5733                 :           0 :         case US_MULT:
    5734                 :           0 :           result = wi::mul (pop0, pop1, UNSIGNED, &overflow);
    5735                 :           0 :           goto clamp_unsigned_saturation;
    5736                 :             : 
    5737                 :           8 :         case SMUL_HIGHPART:
    5738                 :           8 :           result = wi::mul_high (pop0, pop1, SIGNED);
    5739                 :           8 :           break;
    5740                 :             : 
    5741                 :           0 :         case UMUL_HIGHPART:
    5742                 :           0 :           result = wi::mul_high (pop0, pop1, UNSIGNED);
    5743                 :           0 :           break;
    5744                 :             : 
    5745                 :             :         default:
    5746                 :             :           return NULL_RTX;
    5747                 :             :         }
    5748                 :    30869014 :       return immed_wide_int_const (result, int_mode);
    5749                 :    30869756 :     }
    5750                 :             : 
    5751                 :             :   /* Handle polynomial integers.  */
    5752                 :             :   if (NUM_POLY_INT_COEFFS > 1
    5753                 :             :       && is_a <scalar_int_mode> (mode, &int_mode)
    5754                 :             :       && poly_int_rtx_p (op0)
    5755                 :             :       && poly_int_rtx_p (op1))
    5756                 :             :     {
    5757                 :             :       poly_wide_int result;
    5758                 :             :       switch (code)
    5759                 :             :         {
    5760                 :             :         case PLUS:
    5761                 :             :           result = wi::to_poly_wide (op0, mode) + wi::to_poly_wide (op1, mode);
    5762                 :             :           break;
    5763                 :             : 
    5764                 :             :         case MINUS:
    5765                 :             :           result = wi::to_poly_wide (op0, mode) - wi::to_poly_wide (op1, mode);
    5766                 :             :           break;
    5767                 :             : 
    5768                 :             :         case MULT:
    5769                 :             :           if (CONST_SCALAR_INT_P (op1))
    5770                 :             :             result = wi::to_poly_wide (op0, mode) * rtx_mode_t (op1, mode);
    5771                 :             :           else
    5772                 :             :             return NULL_RTX;
    5773                 :             :           break;
    5774                 :             : 
    5775                 :             :         case ASHIFT:
    5776                 :             :           if (CONST_SCALAR_INT_P (op1))
    5777                 :             :             {
    5778                 :             :               wide_int shift
    5779                 :             :                 = rtx_mode_t (op1,
    5780                 :             :                               GET_MODE (op1) == VOIDmode
    5781                 :             :                               && GET_MODE_PRECISION (int_mode) < BITS_PER_WORD
    5782                 :             :                               ? word_mode : mode);
    5783                 :             :               if (SHIFT_COUNT_TRUNCATED)
    5784                 :             :                 shift = wi::umod_trunc (shift, GET_MODE_PRECISION (int_mode));
    5785                 :             :               else if (wi::geu_p (shift, GET_MODE_PRECISION (int_mode)))
    5786                 :             :                 return NULL_RTX;
    5787                 :             :               result = wi::to_poly_wide (op0, mode) << shift;
    5788                 :             :             }
    5789                 :             :           else
    5790                 :             :             return NULL_RTX;
    5791                 :             :           break;
    5792                 :             : 
    5793                 :             :         case IOR:
    5794                 :             :           if (!CONST_SCALAR_INT_P (op1)
    5795                 :             :               || !can_ior_p (wi::to_poly_wide (op0, mode),
    5796                 :             :                              rtx_mode_t (op1, mode), &result))
    5797                 :             :             return NULL_RTX;
    5798                 :             :           break;
    5799                 :             : 
    5800                 :             :         default:
    5801                 :             :           return NULL_RTX;
    5802                 :             :         }
    5803                 :             :       return immed_wide_int_const (result, int_mode);
    5804                 :             :     }
    5805                 :             : 
    5806                 :             :   return NULL_RTX;
    5807                 :             : }
    5808                 :             : 
    5809                 :             : 
    5810                 :             : 
    5811                 :             : /* Return a positive integer if X should sort after Y.  The value
    5812                 :             :    returned is 1 if and only if X and Y are both regs.  */
    5813                 :             : 
    5814                 :             : static int
    5815                 :   101006883 : simplify_plus_minus_op_data_cmp (rtx x, rtx y)
    5816                 :             : {
    5817                 :   101006883 :   int result;
    5818                 :             : 
    5819                 :   101006883 :   result = (commutative_operand_precedence (y)
    5820                 :   101006883 :             - commutative_operand_precedence (x));
    5821                 :   101006883 :   if (result)
    5822                 :    69314425 :     return result + result;
    5823                 :             : 
    5824                 :             :   /* Group together equal REGs to do more simplification.  */
    5825                 :    31692458 :   if (REG_P (x) && REG_P (y))
    5826                 :     8092913 :     return REGNO (x) > REGNO (y);
    5827                 :             : 
    5828                 :             :   return 0;
    5829                 :             : }
    5830                 :             : 
    5831                 :             : /* Simplify and canonicalize a PLUS or MINUS, at least one of whose
    5832                 :             :    operands may be another PLUS or MINUS.
    5833                 :             : 
    5834                 :             :    Rather than test for specific case, we do this by a brute-force method
    5835                 :             :    and do all possible simplifications until no more changes occur.  Then
    5836                 :             :    we rebuild the operation.
    5837                 :             : 
    5838                 :             :    May return NULL_RTX when no changes were made.  */
    5839                 :             : 
    5840                 :             : rtx
    5841                 :    34175990 : simplify_context::simplify_plus_minus (rtx_code code, machine_mode mode,
    5842                 :             :                                        rtx op0, rtx op1)
    5843                 :             : {
    5844                 :    34175990 :   struct simplify_plus_minus_op_data
    5845                 :             :   {
    5846                 :             :     rtx op;
    5847                 :             :     short neg;
    5848                 :             :   } ops[16];
    5849                 :    34175990 :   rtx result, tem;
    5850                 :    34175990 :   int n_ops = 2;
    5851                 :    34175990 :   int changed, n_constants, canonicalized = 0;
    5852                 :    34175990 :   int i, j;
    5853                 :             : 
    5854                 :    34175990 :   memset (ops, 0, sizeof ops);
    5855                 :             : 
    5856                 :             :   /* Set up the two operands and then expand them until nothing has been
    5857                 :             :      changed.  If we run out of room in our array, give up; this should
    5858                 :             :      almost never happen.  */
    5859                 :             : 
    5860                 :    34175990 :   ops[0].op = op0;
    5861                 :    34175990 :   ops[0].neg = 0;
    5862                 :    34175990 :   ops[1].op = op1;
    5863                 :    34175990 :   ops[1].neg = (code == MINUS);
    5864                 :             : 
    5865                 :    69337350 :   do
    5866                 :             :     {
    5867                 :    69337350 :       changed = 0;
    5868                 :    69337350 :       n_constants = 0;
    5869                 :             : 
    5870                 :   280405293 :       for (i = 0; i < n_ops; i++)
    5871                 :             :         {
    5872                 :   211067969 :           rtx this_op = ops[i].op;
    5873                 :   211067969 :           int this_neg = ops[i].neg;
    5874                 :   211067969 :           enum rtx_code this_code = GET_CODE (this_op);
    5875                 :             : 
    5876                 :   211067969 :           switch (this_code)
    5877                 :             :             {
    5878                 :    34424210 :             case PLUS:
    5879                 :    34424210 :             case MINUS:
    5880                 :    34424210 :               if (n_ops == ARRAY_SIZE (ops))
    5881                 :             :                 return NULL_RTX;
    5882                 :             : 
    5883                 :    34424184 :               ops[n_ops].op = XEXP (this_op, 1);
    5884                 :    34424184 :               ops[n_ops].neg = (this_code == MINUS) ^ this_neg;
    5885                 :    34424184 :               n_ops++;
    5886                 :             : 
    5887                 :    34424184 :               ops[i].op = XEXP (this_op, 0);
    5888                 :    34424184 :               changed = 1;
    5889                 :             :               /* If this operand was negated then we will potentially
    5890                 :             :                  canonicalize the expression.  Similarly if we don't
    5891                 :             :                  place the operands adjacent we're re-ordering the
    5892                 :             :                  expression and thus might be performing a
    5893                 :             :                  canonicalization.  Ignore register re-ordering.
    5894                 :             :                  ??? It might be better to shuffle the ops array here,
    5895                 :             :                  but then (plus (plus (A, B), plus (C, D))) wouldn't
    5896                 :             :                  be seen as non-canonical.  */
    5897                 :    34424184 :               if (this_neg
    5898                 :    33751431 :                   || (i != n_ops - 2
    5899                 :    33103343 :                       && !(REG_P (ops[i].op) && REG_P (ops[n_ops - 1].op))))
    5900                 :   211067943 :                 canonicalized = 1;
    5901                 :             :               break;
    5902                 :             : 
    5903                 :        2022 :             case NEG:
    5904                 :        2022 :               ops[i].op = XEXP (this_op, 0);
    5905                 :        2022 :               ops[i].neg = ! this_neg;
    5906                 :        2022 :               changed = 1;
    5907                 :        2022 :               canonicalized = 1;
    5908                 :        2022 :               break;
    5909                 :             : 
    5910                 :     1310163 :             case CONST:
    5911                 :     1310163 :               if (n_ops != ARRAY_SIZE (ops)
    5912                 :     1310163 :                   && GET_CODE (XEXP (this_op, 0)) == PLUS
    5913                 :     1194340 :                   && CONSTANT_P (XEXP (XEXP (this_op, 0), 0))
    5914                 :     1171019 :                   && CONSTANT_P (XEXP (XEXP (this_op, 0), 1)))
    5915                 :             :                 {
    5916                 :     1171019 :                   ops[i].op = XEXP (XEXP (this_op, 0), 0);
    5917                 :     1171019 :                   ops[n_ops].op = XEXP (XEXP (this_op, 0), 1);
    5918                 :     1171019 :                   ops[n_ops].neg = this_neg;
    5919                 :     1171019 :                   n_ops++;
    5920                 :     1171019 :                   changed = 1;
    5921                 :     1171019 :                   canonicalized = 1;
    5922                 :             :                 }
    5923                 :             :               break;
    5924                 :             : 
    5925                 :       40158 :             case NOT:
    5926                 :             :               /* ~a -> (-a - 1) */
    5927                 :       40158 :               if (n_ops != ARRAY_SIZE (ops))
    5928                 :             :                 {
    5929                 :       40158 :                   ops[n_ops].op = CONSTM1_RTX (mode);
    5930                 :       40158 :                   ops[n_ops++].neg = this_neg;
    5931                 :       40158 :                   ops[i].op = XEXP (this_op, 0);
    5932                 :       40158 :                   ops[i].neg = !this_neg;
    5933                 :       40158 :                   changed = 1;
    5934                 :       40158 :                   canonicalized = 1;
    5935                 :             :                 }
    5936                 :             :               break;
    5937                 :             : 
    5938                 :   106497164 :             CASE_CONST_SCALAR_INT:
    5939                 :   106497164 :             case CONST_POLY_INT:
    5940                 :   106497164 :               n_constants++;
    5941                 :   106497164 :               if (this_neg)
    5942                 :             :                 {
    5943                 :     1067101 :                   ops[i].op = neg_poly_int_rtx (mode, this_op);
    5944                 :     1067101 :                   ops[i].neg = 0;
    5945                 :     1067101 :                   changed = 1;
    5946                 :     1067101 :                   canonicalized = 1;
    5947                 :             :                 }
    5948                 :             :               break;
    5949                 :             : 
    5950                 :             :             default:
    5951                 :             :               break;
    5952                 :             :             }
    5953                 :             :         }
    5954                 :             :     }
    5955                 :    69337324 :   while (changed);
    5956                 :             : 
    5957                 :    34175964 :   if (n_constants > 1)
    5958                 :    21768656 :     canonicalized = 1;
    5959                 :             : 
    5960                 :    34175964 :   gcc_assert (n_ops >= 2);
    5961                 :             : 
    5962                 :             :   /* If we only have two operands, we can avoid the loops.  */
    5963                 :    34175964 :   if (n_ops == 2)
    5964                 :             :     {
    5965                 :           0 :       enum rtx_code code = ops[0].neg || ops[1].neg ? MINUS : PLUS;
    5966                 :           0 :       rtx lhs, rhs;
    5967                 :             : 
    5968                 :             :       /* Get the two operands.  Be careful with the order, especially for
    5969                 :             :          the cases where code == MINUS.  */
    5970                 :           0 :       if (ops[0].neg && ops[1].neg)
    5971                 :             :         {
    5972                 :           0 :           lhs = gen_rtx_NEG (mode, ops[0].op);
    5973                 :           0 :           rhs = ops[1].op;
    5974                 :             :         }
    5975                 :           0 :       else if (ops[0].neg)
    5976                 :             :         {
    5977                 :           0 :           lhs = ops[1].op;
    5978                 :           0 :           rhs = ops[0].op;
    5979                 :             :         }
    5980                 :             :       else
    5981                 :             :         {
    5982                 :           0 :           lhs = ops[0].op;
    5983                 :           0 :           rhs = ops[1].op;
    5984                 :             :         }
    5985                 :             : 
    5986                 :           0 :       return simplify_const_binary_operation (code, mode, lhs, rhs);
    5987                 :             :     }
    5988                 :             : 
    5989                 :             :   /* Now simplify each pair of operands until nothing changes.  */
    5990                 :    56688727 :   while (1)
    5991                 :             :     {
    5992                 :             :       /* Insertion sort is good enough for a small array.  */
    5993                 :   149071844 :       for (i = 1; i < n_ops; i++)
    5994                 :             :         {
    5995                 :    92383117 :           struct simplify_plus_minus_op_data save;
    5996                 :    92383117 :           int cmp;
    5997                 :             : 
    5998                 :    92383117 :           j = i - 1;
    5999                 :    92383117 :           cmp = simplify_plus_minus_op_data_cmp (ops[j].op, ops[i].op);
    6000                 :    92383117 :           if (cmp <= 0)
    6001                 :    81824059 :             continue;
    6002                 :             :           /* Just swapping registers doesn't count as canonicalization.  */
    6003                 :    10559058 :           if (cmp != 1)
    6004                 :     7741194 :             canonicalized = 1;
    6005                 :             : 
    6006                 :    10559058 :           save = ops[i];
    6007                 :    12600212 :           do
    6008                 :    12600212 :             ops[j + 1] = ops[j];
    6009                 :    12600212 :           while (j--
    6010                 :    23159270 :                  && simplify_plus_minus_op_data_cmp (ops[j].op, save.op) > 0);
    6011                 :    10559058 :           ops[j + 1] = save;
    6012                 :             :         }
    6013                 :             : 
    6014                 :    56688727 :       changed = 0;
    6015                 :   149071844 :       for (i = n_ops - 1; i > 0; i--)
    6016                 :   221215693 :         for (j = i - 1; j >= 0; j--)
    6017                 :             :           {
    6018                 :   129512128 :             rtx lhs = ops[j].op, rhs = ops[i].op;
    6019                 :   129512128 :             int lneg = ops[j].neg, rneg = ops[i].neg;
    6020                 :             : 
    6021                 :   129512128 :             if (lhs != 0 && rhs != 0)
    6022                 :             :               {
    6023                 :   106640235 :                 enum rtx_code ncode = PLUS;
    6024                 :             : 
    6025                 :   106640235 :                 if (lneg != rneg)
    6026                 :             :                   {
    6027                 :     9573607 :                     ncode = MINUS;
    6028                 :     9573607 :                     if (lneg)
    6029                 :     6160820 :                       std::swap (lhs, rhs);
    6030                 :             :                   }
    6031                 :    97066628 :                 else if (swap_commutative_operands_p (lhs, rhs))
    6032                 :      194292 :                   std::swap (lhs, rhs);
    6033                 :             : 
    6034                 :   106640235 :                 if ((GET_CODE (lhs) == CONST || CONST_INT_P (lhs))
    6035                 :    25750678 :                     && (GET_CODE (rhs) == CONST || CONST_INT_P (rhs)))
    6036                 :             :                   {
    6037                 :    21909008 :                     rtx tem_lhs, tem_rhs;
    6038                 :             : 
    6039                 :    21909008 :                     tem_lhs = GET_CODE (lhs) == CONST ? XEXP (lhs, 0) : lhs;
    6040                 :    21909008 :                     tem_rhs = GET_CODE (rhs) == CONST ? XEXP (rhs, 0) : rhs;
    6041                 :    21909008 :                     tem = simplify_binary_operation (ncode, mode, tem_lhs,
    6042                 :             :                                                      tem_rhs);
    6043                 :             : 
    6044                 :    21909008 :                     if (tem && !CONSTANT_P (tem))
    6045                 :        1746 :                       tem = gen_rtx_CONST (GET_MODE (tem), tem);
    6046                 :             :                   }
    6047                 :             :                 else
    6048                 :    84731227 :                   tem = simplify_binary_operation (ncode, mode, lhs, rhs);
    6049                 :             : 
    6050                 :    84732973 :                 if (tem)
    6051                 :             :                   {
    6052                 :             :                     /* Reject "simplifications" that just wrap the two
    6053                 :             :                        arguments in a CONST.  Failure to do so can result
    6054                 :             :                        in infinite recursion with simplify_binary_operation
    6055                 :             :                        when it calls us to simplify CONST operations.
    6056                 :             :                        Also, if we find such a simplification, don't try
    6057                 :             :                        any more combinations with this rhs:  We must have
    6058                 :             :                        something like symbol+offset, ie. one of the
    6059                 :             :                        trivial CONST expressions we handle later.  */
    6060                 :    23627532 :                     if (GET_CODE (tem) == CONST
    6061                 :      681298 :                         && GET_CODE (XEXP (tem, 0)) == ncode
    6062                 :      680754 :                         && XEXP (XEXP (tem, 0), 0) == lhs
    6063                 :      679552 :                         && XEXP (XEXP (tem, 0), 1) == rhs)
    6064                 :             :                       break;
    6065                 :    22947980 :                     lneg &= rneg;
    6066                 :    22947980 :                     if (GET_CODE (tem) == NEG)
    6067                 :       42488 :                       tem = XEXP (tem, 0), lneg = !lneg;
    6068                 :    22947980 :                     if (poly_int_rtx_p (tem) && lneg)
    6069                 :           0 :                       tem = neg_poly_int_rtx (mode, tem), lneg = 0;
    6070                 :             : 
    6071                 :    22947980 :                     ops[i].op = tem;
    6072                 :    22947980 :                     ops[i].neg = lneg;
    6073                 :    22947980 :                     ops[j].op = NULL_RTX;
    6074                 :    22947980 :                     changed = 1;
    6075                 :    22947980 :                     canonicalized = 1;
    6076                 :             :                   }
    6077                 :             :               }
    6078                 :             :           }
    6079                 :             : 
    6080                 :    56688727 :       if (!changed)
    6081                 :             :         break;
    6082                 :             : 
    6083                 :             :       /* Pack all the operands to the lower-numbered entries.  */
    6084                 :    90545662 :       for (i = 0, j = 0; j < n_ops; j++)
    6085                 :    68032899 :         if (ops[j].op)
    6086                 :             :           {
    6087                 :    45084919 :             ops[i] = ops[j];
    6088                 :    45084919 :             i++;
    6089                 :             :           }
    6090                 :             :       n_ops = i;
    6091                 :             :     }
    6092                 :             : 
    6093                 :             :   /* If nothing changed, check that rematerialization of rtl instructions
    6094                 :             :      is still required.  */
    6095                 :    34175964 :   if (!canonicalized)
    6096                 :             :     {
    6097                 :             :       /* Perform rematerialization if only all operands are registers and
    6098                 :             :          all operations are PLUS.  */
    6099                 :             :       /* ??? Also disallow (non-global, non-frame) fixed registers to work
    6100                 :             :          around rs6000 and how it uses the CA register.  See PR67145.  */
    6101                 :     4847857 :       for (i = 0; i < n_ops; i++)
    6102                 :     3902169 :         if (ops[i].neg
    6103                 :     3649105 :             || !REG_P (ops[i].op)
    6104                 :     7004341 :             || (REGNO (ops[i].op) < FIRST_PSEUDO_REGISTER
    6105                 :      315930 :                 && fixed_regs[REGNO (ops[i].op)]
    6106                 :         204 :                 && !global_regs[REGNO (ops[i].op)]
    6107                 :         204 :                 && ops[i].op != frame_pointer_rtx
    6108                 :          99 :                 && ops[i].op != arg_pointer_rtx
    6109                 :          96 :                 && ops[i].op != stack_pointer_rtx))
    6110                 :             :           return NULL_RTX;
    6111                 :      945688 :       goto gen_result;
    6112                 :             :     }
    6113                 :             : 
    6114                 :             :   /* Create (minus -C X) instead of (neg (const (plus X C))).  */
    6115                 :    32430279 :   if (n_ops == 2
    6116                 :    21315319 :       && CONST_INT_P (ops[1].op)
    6117                 :    20899184 :       && CONSTANT_P (ops[0].op)
    6118                 :         157 :       && ops[0].neg)
    6119                 :         120 :     return gen_rtx_fmt_ee (MINUS, mode, ops[1].op, ops[0].op);
    6120                 :             : 
    6121                 :             :   /* We suppressed creation of trivial CONST expressions in the
    6122                 :             :      combination loop to avoid recursion.  Create one manually now.
    6123                 :             :      The combination loop should have ensured that there is exactly
    6124                 :             :      one CONST_INT, and the sort will have ensured that it is last
    6125                 :             :      in the array and that any other constant will be next-to-last.  */
    6126                 :             : 
    6127                 :    32430159 :   if (n_ops > 1
    6128                 :    31924456 :       && poly_int_rtx_p (ops[n_ops - 1].op)
    6129                 :    62146936 :       && CONSTANT_P (ops[n_ops - 2].op))
    6130                 :             :     {
    6131                 :     1226811 :       rtx value = ops[n_ops - 1].op;
    6132                 :     1226811 :       if (ops[n_ops - 1].neg ^ ops[n_ops - 2].neg)
    6133                 :      617242 :         value = neg_poly_int_rtx (mode, value);
    6134                 :     1226811 :       if (CONST_INT_P (value))
    6135                 :             :         {
    6136                 :     2453622 :           ops[n_ops - 2].op = plus_constant (mode, ops[n_ops - 2].op,
    6137                 :     1226811 :                                              INTVAL (value));
    6138                 :     1226811 :           n_ops--;
    6139                 :             :         }
    6140                 :             :     }
    6141                 :             : 
    6142                 :             :   /* Put a non-negated operand first, if possible.  */
    6143                 :             : 
    6144                 :    33986892 :   for (i = 0; i < n_ops && ops[i].neg; i++)
    6145                 :     1556733 :     continue;
    6146                 :    32430159 :   if (i == n_ops)
    6147                 :        9630 :     ops[0].op = gen_rtx_NEG (mode, ops[0].op);
    6148                 :    32420529 :   else if (i != 0)
    6149                 :             :     {
    6150                 :     1459246 :       tem = ops[0].op;
    6151                 :     1459246 :       ops[0] = ops[i];
    6152                 :     1459246 :       ops[i].op = tem;
    6153                 :     1459246 :       ops[i].neg = 1;
    6154                 :             :     }
    6155                 :             : 
    6156                 :             :   /* Now make the result by performing the requested operations.  */
    6157                 :    30961283 :  gen_result:
    6158                 :    33375847 :   result = ops[0].op;
    6159                 :    77410242 :   for (i = 1; i < n_ops; i++)
    6160                 :    88068790 :     result = gen_rtx_fmt_ee (ops[i].neg ? MINUS : PLUS,
    6161                 :             :                              mode, result, ops[i].op);
    6162                 :             : 
    6163                 :             :   return result;
    6164                 :     1556733 : }
    6165                 :             : 
    6166                 :             : /* Check whether an operand is suitable for calling simplify_plus_minus.  */
    6167                 :             : static bool
    6168                 :   466543967 : plus_minus_operand_p (const_rtx x)
    6169                 :             : {
    6170                 :   466543967 :   return GET_CODE (x) == PLUS
    6171                 :   466543967 :          || GET_CODE (x) == MINUS
    6172                 :   466543967 :          || (GET_CODE (x) == CONST
    6173                 :     1678712 :              && GET_CODE (XEXP (x, 0)) == PLUS
    6174                 :     1103303 :              && CONSTANT_P (XEXP (XEXP (x, 0), 0))
    6175                 :     1028696 :              && CONSTANT_P (XEXP (XEXP (x, 0), 1)));
    6176                 :             : }
    6177                 :             : 
    6178                 :             : /* Like simplify_binary_operation except used for relational operators.
    6179                 :             :    MODE is the mode of the result. If MODE is VOIDmode, both operands must
    6180                 :             :    not also be VOIDmode.
    6181                 :             : 
    6182                 :             :    CMP_MODE specifies in which mode the comparison is done in, so it is
    6183                 :             :    the mode of the operands.  If CMP_MODE is VOIDmode, it is taken from
    6184                 :             :    the operands or, if both are VOIDmode, the operands are compared in
    6185                 :             :    "infinite precision".  */
    6186                 :             : rtx
    6187                 :   118595766 : simplify_context::simplify_relational_operation (rtx_code code,
    6188                 :             :                                                  machine_mode mode,
    6189                 :             :                                                  machine_mode cmp_mode,
    6190                 :             :                                                  rtx op0, rtx op1)
    6191                 :             : {
    6192                 :   118595766 :   rtx tem, trueop0, trueop1;
    6193                 :             : 
    6194                 :   118595766 :   if (cmp_mode == VOIDmode)
    6195                 :    26114506 :     cmp_mode = GET_MODE (op0);
    6196                 :    26114506 :   if (cmp_mode == VOIDmode)
    6197                 :      436054 :     cmp_mode = GET_MODE (op1);
    6198                 :             : 
    6199                 :   118595766 :   tem = simplify_const_relational_operation (code, cmp_mode, op0, op1);
    6200                 :   118595766 :   if (tem)
    6201                 :      780860 :     return relational_result (mode, cmp_mode, tem);
    6202                 :             : 
    6203                 :             :   /* For the following tests, ensure const0_rtx is op1.  */
    6204                 :   117814906 :   if (swap_commutative_operands_p (op0, op1)
    6205                 :   117814906 :       || (op0 == const0_rtx && op1 != const0_rtx))
    6206                 :     2376124 :     std::swap (op0, op1), code = swap_condition (code);
    6207                 :             : 
    6208                 :             :   /* If op0 is a compare, extract the comparison arguments from it.  */
    6209                 :   117814906 :   if (GET_CODE (op0) == COMPARE && op1 == const0_rtx)
    6210                 :    12718095 :     return simplify_gen_relational (code, mode, VOIDmode,
    6211                 :    12718095 :                                     XEXP (op0, 0), XEXP (op0, 1));
    6212                 :             : 
    6213                 :   105096811 :   if (GET_MODE_CLASS (cmp_mode) == MODE_CC)
    6214                 :             :     return NULL_RTX;
    6215                 :             : 
    6216                 :    77262236 :   trueop0 = avoid_constant_pool_reference (op0);
    6217                 :    77262236 :   trueop1 = avoid_constant_pool_reference (op1);
    6218                 :    77262236 :   return simplify_relational_operation_1 (code, mode, cmp_mode,
    6219                 :    77262236 :                                           trueop0, trueop1);
    6220                 :             : }
    6221                 :             : 
    6222                 :             : /* This part of simplify_relational_operation is only used when CMP_MODE
    6223                 :             :    is not in class MODE_CC (i.e. it is a real comparison).
    6224                 :             : 
    6225                 :             :    MODE is the mode of the result, while CMP_MODE specifies in which
    6226                 :             :    mode the comparison is done in, so it is the mode of the operands.  */
    6227                 :             : 
    6228                 :             : rtx
    6229                 :    77262236 : simplify_context::simplify_relational_operation_1 (rtx_code code,
    6230                 :             :                                                    machine_mode mode,
    6231                 :             :                                                    machine_mode cmp_mode,
    6232                 :             :                                                    rtx op0, rtx op1)
    6233                 :             : {
    6234                 :    77262236 :   enum rtx_code op0code = GET_CODE (op0);
    6235                 :             : 
    6236                 :    77262236 :   if (op1 == const0_rtx && COMPARISON_P (op0))
    6237                 :             :     {
    6238                 :             :       /* If op0 is a comparison, extract the comparison arguments
    6239                 :             :          from it.  */
    6240                 :      434280 :       if (code == NE)
    6241                 :             :         {
    6242                 :      212710 :           if (GET_MODE (op0) == mode)
    6243                 :         161 :             return simplify_rtx (op0);
    6244                 :             :           else
    6245                 :      212549 :             return simplify_gen_relational (GET_CODE (op0), mode, VOIDmode,
    6246                 :      212549 :                                             XEXP (op0, 0), XEXP (op0, 1));
    6247                 :             :         }
    6248                 :      221570 :       else if (code == EQ)
    6249                 :             :         {
    6250                 :       98527 :           enum rtx_code new_code = reversed_comparison_code (op0, NULL);
    6251                 :       98527 :           if (new_code != UNKNOWN)
    6252                 :       98211 :             return simplify_gen_relational (new_code, mode, VOIDmode,
    6253                 :       98211 :                                             XEXP (op0, 0), XEXP (op0, 1));
    6254                 :             :         }
    6255                 :             :     }
    6256                 :             : 
    6257                 :             :   /* (LTU/GEU (PLUS a C) C), where C is constant, can be simplified to
    6258                 :             :      (GEU/LTU a -C).  Likewise for (LTU/GEU (PLUS a C) a).  */
    6259                 :    76951315 :   if ((code == LTU || code == GEU)
    6260                 :     4048338 :       && GET_CODE (op0) == PLUS
    6261                 :      589738 :       && CONST_INT_P (XEXP (op0, 1))
    6262                 :      380794 :       && (rtx_equal_p (op1, XEXP (op0, 0))
    6263                 :      268154 :           || rtx_equal_p (op1, XEXP (op0, 1)))
    6264                 :             :       /* (LTU/GEU (PLUS a 0) 0) is not the same as (GEU/LTU a 0). */
    6265                 :    77126743 :       && XEXP (op0, 1) != const0_rtx)
    6266                 :             :     {
    6267                 :      175428 :       rtx new_cmp
    6268                 :      175428 :         = simplify_gen_unary (NEG, cmp_mode, XEXP (op0, 1), cmp_mode);
    6269                 :      177060 :       return simplify_gen_relational ((code == LTU ? GEU : LTU), mode,
    6270                 :      175428 :                                       cmp_mode, XEXP (op0, 0), new_cmp);
    6271                 :             :     }
    6272                 :             : 
    6273                 :             :   /* (GTU (PLUS a C) (C - 1)) where C is a non-zero constant can be
    6274                 :             :      transformed into (LTU a -C).  */
    6275                 :    76775887 :   if (code == GTU && GET_CODE (op0) == PLUS && CONST_INT_P (op1)
    6276                 :      324045 :       && CONST_INT_P (XEXP (op0, 1))
    6277                 :      255393 :       && (UINTVAL (op1) == UINTVAL (XEXP (op0, 1)) - 1)
    6278                 :       25139 :       && XEXP (op0, 1) != const0_rtx)
    6279                 :             :     {
    6280                 :       25139 :       rtx new_cmp
    6281                 :       25139 :         = simplify_gen_unary (NEG, cmp_mode, XEXP (op0, 1), cmp_mode);
    6282                 :       25139 :       return simplify_gen_relational (LTU, mode, cmp_mode,
    6283                 :       25139 :                                        XEXP (op0, 0), new_cmp);
    6284                 :             :     }
    6285                 :             : 
    6286                 :             :   /* Canonicalize (LTU/GEU (PLUS a b) b) as (LTU/GEU (PLUS a b) a).  */
    6287                 :    76750748 :   if ((code == LTU || code == GEU)
    6288                 :     3872910 :       && GET_CODE (op0) == PLUS
    6289                 :      414310 :       && rtx_equal_p (op1, XEXP (op0, 1))
    6290                 :             :       /* Don't recurse "infinitely" for (LTU/GEU (PLUS b b) b).  */
    6291                 :    76756342 :       && !rtx_equal_p (op1, XEXP (op0, 0)))
    6292                 :        5594 :     return simplify_gen_relational (code, mode, cmp_mode, op0,
    6293                 :        5594 :                                     copy_rtx (XEXP (op0, 0)));
    6294                 :             : 
    6295                 :    76745154 :   if (op1 == const0_rtx)
    6296                 :             :     {
    6297                 :             :       /* Canonicalize (GTU x 0) as (NE x 0).  */
    6298                 :    35097106 :       if (code == GTU)
    6299                 :      167543 :         return simplify_gen_relational (NE, mode, cmp_mode, op0, op1);
    6300                 :             :       /* Canonicalize (LEU x 0) as (EQ x 0).  */
    6301                 :    34929563 :       if (code == LEU)
    6302                 :       43975 :         return simplify_gen_relational (EQ, mode, cmp_mode, op0, op1);
    6303                 :             :     }
    6304                 :    41648048 :   else if (op1 == const1_rtx)
    6305                 :             :     {
    6306                 :     2805215 :       switch (code)
    6307                 :             :         {
    6308                 :        7363 :         case GE:
    6309                 :             :           /* Canonicalize (GE x 1) as (GT x 0).  */
    6310                 :        7363 :           return simplify_gen_relational (GT, mode, cmp_mode,
    6311                 :        7363 :                                           op0, const0_rtx);
    6312                 :      165248 :         case GEU:
    6313                 :             :           /* Canonicalize (GEU x 1) as (NE x 0).  */
    6314                 :      165248 :           return simplify_gen_relational (NE, mode, cmp_mode,
    6315                 :      165248 :                                           op0, const0_rtx);
    6316                 :        9778 :         case LT:
    6317                 :             :           /* Canonicalize (LT x 1) as (LE x 0).  */
    6318                 :        9778 :           return simplify_gen_relational (LE, mode, cmp_mode,
    6319                 :        9778 :                                           op0, const0_rtx);
    6320                 :       33458 :         case LTU:
    6321                 :             :           /* Canonicalize (LTU x 1) as (EQ x 0).  */
    6322                 :       33458 :           return simplify_gen_relational (EQ, mode, cmp_mode,
    6323                 :       33458 :                                           op0, const0_rtx);
    6324                 :             :         default:
    6325                 :             :           break;
    6326                 :             :         }
    6327                 :             :     }
    6328                 :    38842833 :   else if (op1 == constm1_rtx)
    6329                 :             :     {
    6330                 :             :       /* Canonicalize (LE x -1) as (LT x 0).  */
    6331                 :     1042543 :       if (code == LE)
    6332                 :        1563 :         return simplify_gen_relational (LT, mode, cmp_mode, op0, const0_rtx);
    6333                 :             :       /* Canonicalize (GT x -1) as (GE x 0).  */
    6334                 :     1040980 :       if (code == GT)
    6335                 :        5189 :         return simplify_gen_relational (GE, mode, cmp_mode, op0, const0_rtx);
    6336                 :             :     }
    6337                 :             : 
    6338                 :             :   /* (eq/ne (plus x cst1) cst2) simplifies to (eq/ne x (cst2 - cst1))  */
    6339                 :    76311037 :   if ((code == EQ || code == NE)
    6340                 :    57686259 :       && (op0code == PLUS || op0code == MINUS)
    6341                 :     2013580 :       && CONSTANT_P (op1)
    6342                 :      801752 :       && CONSTANT_P (XEXP (op0, 1))
    6343                 :      468817 :       && (INTEGRAL_MODE_P (cmp_mode) || flag_unsafe_math_optimizations))
    6344                 :             :     {
    6345                 :      468785 :       rtx x = XEXP (op0, 0);
    6346                 :      468785 :       rtx c = XEXP (op0, 1);
    6347                 :      468785 :       enum rtx_code invcode = op0code == PLUS ? MINUS : PLUS;
    6348                 :      468785 :       rtx tem = simplify_gen_binary (invcode, cmp_mode, op1, c);
    6349                 :             : 
    6350                 :             :       /* Detect an infinite recursive condition, where we oscillate at this
    6351                 :             :          simplification case between:
    6352                 :             :             A + B == C  <--->  C - B == A,
    6353                 :             :          where A, B, and C are all constants with non-simplifiable expressions,
    6354                 :             :          usually SYMBOL_REFs.  */
    6355                 :      468785 :       if (GET_CODE (tem) == invcode
    6356                 :          56 :           && CONSTANT_P (x)
    6357                 :      468803 :           && rtx_equal_p (c, XEXP (tem, 1)))
    6358                 :             :         return NULL_RTX;
    6359                 :             : 
    6360                 :      468767 :       return simplify_gen_relational (code, mode, cmp_mode, x, tem);
    6361                 :             :     }
    6362                 :             : 
    6363                 :             :   /* (ne:SI (zero_extract:SI FOO (const_int 1) BAR) (const_int 0))) is
    6364                 :             :      the same as (zero_extract:SI FOO (const_int 1) BAR).  */
    6365                 :    57217474 :   scalar_int_mode int_mode, int_cmp_mode;
    6366                 :    57217474 :   if (code == NE
    6367                 :    30605327 :       && op1 == const0_rtx
    6368                 :     2012346 :       && is_int_mode (mode, &int_mode)
    6369                 :    75793768 :       && is_a <scalar_int_mode> (cmp_mode, &int_cmp_mode)
    6370                 :             :       /* ??? Work-around BImode bugs in the ia64 backend.  */
    6371                 :     2012346 :       && int_mode != BImode
    6372                 :     2012322 :       && int_cmp_mode != BImode
    6373                 :     2012322 :       && nonzero_bits (op0, int_cmp_mode) == 1
    6374                 :    57217474 :       && STORE_FLAG_VALUE == 1)
    6375                 :       96968 :     return GET_MODE_SIZE (int_mode) > GET_MODE_SIZE (int_cmp_mode)
    6376                 :       48484 :            ? simplify_gen_unary (ZERO_EXTEND, int_mode, op0, int_cmp_mode)
    6377                 :       15485 :            : lowpart_subreg (int_mode, op0, int_cmp_mode);
    6378                 :             : 
    6379                 :             :   /* (eq/ne (xor x y) 0) simplifies to (eq/ne x y).  */
    6380                 :    75793768 :   if ((code == EQ || code == NE)
    6381                 :    57168990 :       && op1 == const0_rtx
    6382                 :    31300091 :       && op0code == XOR)
    6383                 :       15787 :     return simplify_gen_relational (code, mode, cmp_mode,
    6384                 :       15787 :                                     XEXP (op0, 0), XEXP (op0, 1));
    6385                 :             : 
    6386                 :             :   /* (eq/ne (xor x y) x) simplifies to (eq/ne y 0).  */
    6387                 :    57153203 :   if ((code == EQ || code == NE)
    6388                 :    57153203 :       && op0code == XOR
    6389                 :        6255 :       && rtx_equal_p (XEXP (op0, 0), op1)
    6390                 :           0 :       && !side_effects_p (XEXP (op0, 0)))
    6391                 :           0 :     return simplify_gen_relational (code, mode, cmp_mode, XEXP (op0, 1),
    6392                 :           0 :                                     CONST0_RTX (mode));
    6393                 :             : 
    6394                 :             :   /* Likewise (eq/ne (xor x y) y) simplifies to (eq/ne x 0).  */
    6395                 :    75777981 :   if ((code == EQ || code == NE)
    6396                 :    57153203 :       && op0code == XOR
    6397                 :        6255 :       && rtx_equal_p (XEXP (op0, 1), op1)
    6398                 :    75778115 :       && !side_effects_p (XEXP (op0, 1)))
    6399                 :         134 :     return simplify_gen_relational (code, mode, cmp_mode, XEXP (op0, 0),
    6400                 :         134 :                                     CONST0_RTX (mode));
    6401                 :             : 
    6402                 :             :   /* (eq/ne (xor x C1) C2) simplifies to (eq/ne x (C1^C2)).  */
    6403                 :    75777847 :   if ((code == EQ || code == NE)
    6404                 :    57153069 :       && op0code == XOR
    6405                 :        6121 :       && CONST_SCALAR_INT_P (op1)
    6406                 :        2955 :       && CONST_SCALAR_INT_P (XEXP (op0, 1)))
    6407                 :        2425 :     return simplify_gen_relational (code, mode, cmp_mode, XEXP (op0, 0),
    6408                 :             :                                     simplify_gen_binary (XOR, cmp_mode,
    6409                 :        2425 :                                                          XEXP (op0, 1), op1));
    6410                 :             : 
    6411                 :             :   /* Simplify eq/ne (and/ior x y) x/y) for targets with a BICS instruction or
    6412                 :             :      constant folding if x/y is a constant.  */
    6413                 :    57150644 :   if ((code == EQ || code == NE)
    6414                 :    57150644 :       && (op0code == AND || op0code == IOR)
    6415                 :     3526164 :       && !side_effects_p (op1)
    6416                 :     3526120 :       && op1 != CONST0_RTX (cmp_mode))
    6417                 :             :     {
    6418                 :             :       /* Both (eq/ne (and x y) x) and (eq/ne (ior x y) y) simplify to
    6419                 :             :          (eq/ne (and (not y) x) 0).  */
    6420                 :      501944 :       if ((op0code == AND && rtx_equal_p (XEXP (op0, 0), op1))
    6421                 :      998048 :           || (op0code == IOR && rtx_equal_p (XEXP (op0, 1), op1)))
    6422                 :             :         {
    6423                 :       26658 :           rtx not_y = simplify_gen_unary (NOT, cmp_mode, XEXP (op0, 1),
    6424                 :             :                                           cmp_mode);
    6425                 :       26658 :           rtx lhs = simplify_gen_binary (AND, cmp_mode, not_y, XEXP (op0, 0));
    6426                 :             : 
    6427                 :       26658 :           return simplify_gen_relational (code, mode, cmp_mode, lhs,
    6428                 :       26658 :                                           CONST0_RTX (cmp_mode));
    6429                 :             :         }
    6430                 :             : 
    6431                 :             :       /* Both (eq/ne (and x y) y) and (eq/ne (ior x y) x) simplify to
    6432                 :             :          (eq/ne (and (not x) y) 0).  */
    6433                 :      475352 :       if ((op0code == AND && rtx_equal_p (XEXP (op0, 1), op1))
    6434                 :      929386 :           || (op0code == IOR && rtx_equal_p (XEXP (op0, 0), op1)))
    6435                 :             :         {
    6436                 :       42024 :           rtx not_x = simplify_gen_unary (NOT, cmp_mode, XEXP (op0, 0),
    6437                 :             :                                           cmp_mode);
    6438                 :       42024 :           rtx lhs = simplify_gen_binary (AND, cmp_mode, not_x, XEXP (op0, 1));
    6439                 :             : 
    6440                 :       42024 :           return simplify_gen_relational (code, mode, cmp_mode, lhs,
    6441                 :       42024 :                                           CONST0_RTX (cmp_mode));
    6442                 :             :         }
    6443                 :             :     }
    6444                 :             : 
    6445                 :             :   /* (eq/ne (bswap x) C1) simplifies to (eq/ne x C2) with C2 swapped.  */
    6446                 :    75706740 :   if ((code == EQ || code == NE)
    6447                 :    57081962 :       && GET_CODE (op0) == BSWAP
    6448                 :         118 :       && CONST_SCALAR_INT_P (op1))
    6449                 :          31 :     return simplify_gen_relational (code, mode, cmp_mode, XEXP (op0, 0),
    6450                 :             :                                     simplify_gen_unary (BSWAP, cmp_mode,
    6451                 :          31 :                                                         op1, cmp_mode));
    6452                 :             : 
    6453                 :             :   /* (eq/ne (bswap x) (bswap y)) simplifies to (eq/ne x y).  */
    6454                 :    57081931 :   if ((code == EQ || code == NE)
    6455                 :    57081931 :       && GET_CODE (op0) == BSWAP
    6456                 :          87 :       && GET_CODE (op1) == BSWAP)
    6457                 :           0 :     return simplify_gen_relational (code, mode, cmp_mode,
    6458                 :           0 :                                     XEXP (op0, 0), XEXP (op1, 0));
    6459                 :             : 
    6460                 :    75706709 :   if (op0code == POPCOUNT && op1 == const0_rtx)
    6461                 :           0 :     switch (code)
    6462                 :             :       {
    6463                 :           0 :       case EQ:
    6464                 :           0 :       case LE:
    6465                 :           0 :       case LEU:
    6466                 :             :         /* (eq (popcount x) (const_int 0)) -> (eq x (const_int 0)).  */
    6467                 :           0 :         return simplify_gen_relational (EQ, mode, GET_MODE (XEXP (op0, 0)),
    6468                 :           0 :                                         XEXP (op0, 0), const0_rtx);
    6469                 :             : 
    6470                 :           0 :       case NE:
    6471                 :           0 :       case GT:
    6472                 :           0 :       case GTU:
    6473                 :             :         /* (ne (popcount x) (const_int 0)) -> (ne x (const_int 0)).  */
    6474                 :           0 :         return simplify_gen_relational (NE, mode, GET_MODE (XEXP (op0, 0)),
    6475                 :           0 :                                         XEXP (op0, 0), const0_rtx);
    6476                 :             : 
    6477                 :             :       default:
    6478                 :             :         break;
    6479                 :             :       }
    6480                 :             : 
    6481                 :             :   /* (ne:SI (subreg:QI (ashift:SI x 7) 0) 0) -> (and:SI x 1).  */
    6482                 :    75706709 :   if (code == NE
    6483                 :    30511971 :       && op1 == const0_rtx
    6484                 :    15824363 :       && (op0code == TRUNCATE
    6485                 :    15824363 :           || (partial_subreg_p (op0)
    6486                 :      191615 :               && subreg_lowpart_p (op0)))
    6487                 :      168253 :       && SCALAR_INT_MODE_P (mode)
    6488                 :    75706709 :       && STORE_FLAG_VALUE == 1)
    6489                 :             :     {
    6490                 :       37021 :       rtx tmp = XEXP (op0, 0);
    6491                 :       37021 :       if (GET_CODE (tmp) == ASHIFT
    6492                 :        1489 :           && GET_MODE (tmp) == mode
    6493                 :         174 :           && CONST_INT_P (XEXP (tmp, 1))
    6494                 :         174 :           && is_int_mode (GET_MODE (op0), &int_mode)
    6495                 :       37195 :           && INTVAL (XEXP (tmp, 1)) == GET_MODE_PRECISION (int_mode) - 1)
    6496                 :         174 :         return simplify_gen_binary (AND, mode, XEXP (tmp, 0), const1_rtx);
    6497                 :             :     }
    6498                 :             : 
    6499                 :             :   /* For two unsigned booleans A and B:
    6500                 :             : 
    6501                 :             :      A >  B == ~B & A
    6502                 :             :      A >= B == ~B | A
    6503                 :             :      A <  B == ~A & B
    6504                 :             :      A <= B == ~A | B
    6505                 :             :      A == B == ~A ^ B (== ~B ^ A)
    6506                 :             :      A != B ==  A ^ B
    6507                 :             : 
    6508                 :             :      For signed comparisons, we have to take STORE_FLAG_VALUE into account,
    6509                 :             :      with the rules above applying for positive STORE_FLAG_VALUE and with
    6510                 :             :      the relations reversed for negative STORE_FLAG_VALUE.  */
    6511                 :    75706535 :   if (is_a<scalar_int_mode> (cmp_mode)
    6512                 :    73403648 :       && COMPARISON_P (op0)
    6513                 :    75770436 :       && COMPARISON_P (op1))
    6514                 :             :     {
    6515                 :        9895 :       rtx t = NULL_RTX;
    6516                 :        9895 :       if (code == GTU || code == (STORE_FLAG_VALUE > 0 ? GT : LT))
    6517                 :         755 :         t = simplify_logical_relational_operation (AND, mode, op1, op0, true);
    6518                 :             :       else if (code == GEU || code == (STORE_FLAG_VALUE > 0 ? GE : LE))
    6519                 :         720 :         t = simplify_logical_relational_operation (IOR, mode, op1, op0, true);
    6520                 :             :       else if (code == LTU || code == (STORE_FLAG_VALUE > 0 ? LT : GT))
    6521                 :         720 :         t = simplify_logical_relational_operation (AND, mode, op0, op1, true);
    6522                 :             :       else if (code == LEU || code == (STORE_FLAG_VALUE > 0 ? LE : GE))
    6523                 :         720 :         t = simplify_logical_relational_operation (IOR, mode, op0, op1, true);
    6524                 :             :       else if (code == EQ)
    6525                 :        3210 :         t = simplify_logical_relational_operation (XOR, mode, op0, op1, true);
    6526                 :             :       else if (code == NE)
    6527                 :        3770 :         t = simplify_logical_relational_operation (XOR, mode, op0, op1);
    6528                 :        9895 :       if (t)
    6529                 :             :         return t;
    6530                 :             :     }
    6531                 :             : 
    6532                 :             :   return NULL_RTX;
    6533                 :             : }
    6534                 :             : 
    6535                 :             : enum
    6536                 :             : {
    6537                 :             :   CMP_EQ = 1,
    6538                 :             :   CMP_LT = 2,
    6539                 :             :   CMP_GT = 4,
    6540                 :             :   CMP_LTU = 8,
    6541                 :             :   CMP_GTU = 16
    6542                 :             : };
    6543                 :             : 
    6544                 :             : 
    6545                 :             : /* Convert the known results for EQ, LT, GT, LTU, GTU contained in
    6546                 :             :    KNOWN_RESULT to a CONST_INT, based on the requested comparison CODE
    6547                 :             :    For KNOWN_RESULT to make sense it should be either CMP_EQ, or the
    6548                 :             :    logical OR of one of (CMP_LT, CMP_GT) and one of (CMP_LTU, CMP_GTU).
    6549                 :             :    For floating-point comparisons, assume that the operands were ordered.  */
    6550                 :             : 
    6551                 :             : static rtx
    6552                 :      640243 : comparison_result (enum rtx_code code, int known_results)
    6553                 :             : {
    6554                 :      640243 :   switch (code)
    6555                 :             :     {
    6556                 :      119563 :     case EQ:
    6557                 :      119563 :     case UNEQ:
    6558                 :      119563 :       return (known_results & CMP_EQ) ? const_true_rtx : const0_rtx;
    6559                 :      424159 :     case NE:
    6560                 :      424159 :     case LTGT:
    6561                 :      424159 :       return (known_results & CMP_EQ) ? const0_rtx : const_true_rtx;
    6562                 :             : 
    6563                 :        9489 :     case LT:
    6564                 :        9489 :     case UNLT:
    6565                 :        9489 :       return (known_results & CMP_LT) ? const_true_rtx : const0_rtx;
    6566                 :        8478 :     case GE:
    6567                 :        8478 :     case UNGE:
    6568                 :        8478 :       return (known_results & CMP_LT) ? const0_rtx : const_true_rtx;
    6569                 :             : 
    6570                 :       12290 :     case GT:
    6571                 :       12290 :     case UNGT:
    6572                 :       12290 :       return (known_results & CMP_GT) ? const_true_rtx : const0_rtx;
    6573                 :       14152 :     case LE:
    6574                 :       14152 :     case UNLE:
    6575                 :       14152 :       return (known_results & CMP_GT) ? const0_rtx : const_true_rtx;
    6576                 :             : 
    6577                 :       10307 :     case LTU:
    6578                 :       10307 :       return (known_results & CMP_LTU) ? const_true_rtx : const0_rtx;
    6579                 :        8817 :     case GEU:
    6580                 :        8817 :       return (known_results & CMP_LTU) ? const0_rtx : const_true_rtx;
    6581                 :             : 
    6582                 :       22897 :     case GTU:
    6583                 :       22897 :       return (known_results & CMP_GTU) ? const_true_rtx : const0_rtx;
    6584                 :       10083 :     case LEU:
    6585                 :       10083 :       return (known_results & CMP_GTU) ? const0_rtx : const_true_rtx;
    6586                 :             : 
    6587                 :           0 :     case ORDERED:
    6588                 :           0 :       return const_true_rtx;
    6589                 :           8 :     case UNORDERED:
    6590                 :           8 :       return const0_rtx;
    6591                 :           0 :     default:
    6592                 :           0 :       gcc_unreachable ();
    6593                 :             :     }
    6594                 :             : }
    6595                 :             : 
    6596                 :             : /* Check if the given comparison (done in the given MODE) is actually
    6597                 :             :    a tautology or a contradiction.  If the mode is VOIDmode, the
    6598                 :             :    comparison is done in "infinite precision".  If no simplification
    6599                 :             :    is possible, this function returns zero.  Otherwise, it returns
    6600                 :             :    either const_true_rtx or const0_rtx.  */
    6601                 :             : 
    6602                 :             : rtx
    6603                 :   118685910 : simplify_const_relational_operation (enum rtx_code code,
    6604                 :             :                                      machine_mode mode,
    6605                 :             :                                      rtx op0, rtx op1)
    6606                 :             : {
    6607                 :   125009665 :   rtx tem;
    6608                 :   125009665 :   rtx trueop0;
    6609                 :   125009665 :   rtx trueop1;
    6610                 :             : 
    6611                 :   125009665 :   gcc_assert (mode != VOIDmode
    6612                 :             :               || (GET_MODE (op0) == VOIDmode
    6613                 :             :                   && GET_MODE (op1) == VOIDmode));
    6614                 :             : 
    6615                 :             :   /* We only handle MODE_CC comparisons that are COMPARE against zero.  */
    6616                 :   125009665 :   if (GET_MODE_CLASS (mode) == MODE_CC
    6617                 :    40557300 :       && (op1 != const0_rtx
    6618                 :    40557300 :           || GET_CODE (op0) != COMPARE))
    6619                 :             :     return NULL_RTX;
    6620                 :             : 
    6621                 :             :   /* If op0 is a compare, extract the comparison arguments from it.  */
    6622                 :    97175090 :   if (GET_CODE (op0) == COMPARE && op1 == const0_rtx)
    6623                 :             :     {
    6624                 :    12722725 :       op1 = XEXP (op0, 1);
    6625                 :    12722725 :       op0 = XEXP (op0, 0);
    6626                 :             : 
    6627                 :    12722725 :       if (GET_MODE (op0) != VOIDmode)
    6628                 :    12618931 :         mode = GET_MODE (op0);
    6629                 :      103794 :       else if (GET_MODE (op1) != VOIDmode)
    6630                 :       94455 :         mode = GET_MODE (op1);
    6631                 :             :       else
    6632                 :             :         return 0;
    6633                 :             :     }
    6634                 :             : 
    6635                 :             :   /* We can't simplify MODE_CC values since we don't know what the
    6636                 :             :      actual comparison is.  */
    6637                 :    97165751 :   if (GET_MODE_CLASS (GET_MODE (op0)) == MODE_CC)
    6638                 :             :     return 0;
    6639                 :             : 
    6640                 :             :   /* Make sure the constant is second.  */
    6641                 :    97165751 :   if (swap_commutative_operands_p (op0, op1))
    6642                 :             :     {
    6643                 :     2832221 :       std::swap (op0, op1);
    6644                 :     2832221 :       code = swap_condition (code);
    6645                 :             :     }
    6646                 :             : 
    6647                 :    97165751 :   trueop0 = avoid_constant_pool_reference (op0);
    6648                 :    97165751 :   trueop1 = avoid_constant_pool_reference (op1);
    6649                 :             : 
    6650                 :             :   /* For integer comparisons of A and B maybe we can simplify A - B and can
    6651                 :             :      then simplify a comparison of that with zero.  If A and B are both either
    6652                 :             :      a register or a CONST_INT, this can't help; testing for these cases will
    6653                 :             :      prevent infinite recursion here and speed things up.
    6654                 :             : 
    6655                 :             :      We can only do this for EQ and NE comparisons as otherwise we may
    6656                 :             :      lose or introduce overflow which we cannot disregard as undefined as
    6657                 :             :      we do not know the signedness of the operation on either the left or
    6658                 :             :      the right hand side of the comparison.  */
    6659                 :             : 
    6660                 :    97165751 :   if (INTEGRAL_MODE_P (mode) && trueop1 != const0_rtx
    6661                 :    47356037 :       && (code == EQ || code == NE)
    6662                 :    30458719 :       && ! ((REG_P (op0) || CONST_INT_P (trueop0))
    6663                 :    21976053 :             && (REG_P (op1) || CONST_INT_P (trueop1)))
    6664                 :    11376783 :       && (tem = simplify_binary_operation (MINUS, mode, op0, op1)) != 0
    6665                 :             :       /* We cannot do this if tem is a nonzero address.  */
    6666                 :     6323757 :       && ! nonzero_address_p (tem))
    6667                 :     6323755 :     return simplify_const_relational_operation (signed_condition (code),
    6668                 :     6323755 :                                                 mode, tem, const0_rtx);
    6669                 :             : 
    6670                 :    90841996 :   if (! HONOR_NANS (mode) && code == ORDERED)
    6671                 :           0 :     return const_true_rtx;
    6672                 :             : 
    6673                 :    90841996 :   if (! HONOR_NANS (mode) && code == UNORDERED)
    6674                 :           8 :     return const0_rtx;
    6675                 :             : 
    6676                 :             :   /* For modes without NaNs, if the two operands are equal, we know the
    6677                 :             :      result except if they have side-effects.  Even with NaNs we know
    6678                 :             :      the result of unordered comparisons and, if signaling NaNs are
    6679                 :             :      irrelevant, also the result of LT/GT/LTGT.  */
    6680                 :    90841988 :   if ((! HONOR_NANS (trueop0)
    6681                 :     2029737 :        || code == UNEQ || code == UNLE || code == UNGE
    6682                 :             :        || ((code == LT || code == GT || code == LTGT)
    6683                 :      778945 :            && ! HONOR_SNANS (trueop0)))
    6684                 :    89699306 :       && rtx_equal_p (trueop0, trueop1)
    6685                 :    91306140 :       && ! side_effects_p (trueop0))
    6686                 :      464152 :     return comparison_result (code, CMP_EQ);
    6687                 :             : 
    6688                 :             :   /* If the operands are floating-point constants, see if we can fold
    6689                 :             :      the result.  */
    6690                 :    90377836 :   if (CONST_DOUBLE_AS_FLOAT_P (trueop0)
    6691                 :        1256 :       && CONST_DOUBLE_AS_FLOAT_P (trueop1)
    6692                 :        1256 :       && SCALAR_FLOAT_MODE_P (GET_MODE (trueop0)))
    6693                 :             :     {
    6694                 :        1256 :       const REAL_VALUE_TYPE *d0 = CONST_DOUBLE_REAL_VALUE (trueop0);
    6695                 :        1256 :       const REAL_VALUE_TYPE *d1 = CONST_DOUBLE_REAL_VALUE (trueop1);
    6696                 :             : 
    6697                 :             :       /* Comparisons are unordered iff at least one of the values is NaN.  */
    6698                 :        1256 :       if (REAL_VALUE_ISNAN (*d0) || REAL_VALUE_ISNAN (*d1))
    6699                 :         180 :         switch (code)
    6700                 :             :           {
    6701                 :           0 :           case UNEQ:
    6702                 :           0 :           case UNLT:
    6703                 :           0 :           case UNGT:
    6704                 :           0 :           case UNLE:
    6705                 :           0 :           case UNGE:
    6706                 :           0 :           case NE:
    6707                 :           0 :           case UNORDERED:
    6708                 :           0 :             return const_true_rtx;
    6709                 :         180 :           case EQ:
    6710                 :         180 :           case LT:
    6711                 :         180 :           case GT:
    6712                 :         180 :           case LE:
    6713                 :         180 :           case GE:
    6714                 :         180 :           case LTGT:
    6715                 :         180 :           case ORDERED:
    6716                 :         180 :             return const0_rtx;
    6717                 :             :           default:
    6718                 :             :             return 0;
    6719                 :             :           }
    6720                 :             : 
    6721                 :        1129 :       return comparison_result (code,
    6722                 :        1129 :                                 (real_equal (d0, d1) ? CMP_EQ :
    6723                 :        1129 :                                  real_less (d0, d1) ? CMP_LT : CMP_GT));
    6724                 :             :     }
    6725                 :             : 
    6726                 :             :   /* Otherwise, see if the operands are both integers.  */
    6727                 :    90376580 :   if ((GET_MODE_CLASS (mode) == MODE_INT || mode == VOIDmode)
    6728                 :    87786203 :       && CONST_SCALAR_INT_P (trueop0) && CONST_SCALAR_INT_P (trueop1))
    6729                 :             :     {
    6730                 :             :       /* It would be nice if we really had a mode here.  However, the
    6731                 :             :          largest int representable on the target is as good as
    6732                 :             :          infinite.  */
    6733                 :      175015 :       machine_mode cmode = (mode == VOIDmode) ? MAX_MODE_INT : mode;
    6734                 :      175015 :       rtx_mode_t ptrueop0 = rtx_mode_t (trueop0, cmode);
    6735                 :      175015 :       rtx_mode_t ptrueop1 = rtx_mode_t (trueop1, cmode);
    6736                 :             : 
    6737                 :      175015 :       if (wi::eq_p (ptrueop0, ptrueop1))
    6738                 :           0 :         return comparison_result (code, CMP_EQ);
    6739                 :             :       else
    6740                 :             :         {
    6741                 :      175015 :           int cr = wi::lts_p (ptrueop0, ptrueop1) ? CMP_LT : CMP_GT;
    6742                 :      175015 :           cr |= wi::ltu_p (ptrueop0, ptrueop1) ? CMP_LTU : CMP_GTU;
    6743                 :      175015 :           return comparison_result (code, cr);
    6744                 :             :         }
    6745                 :             :     }
    6746                 :             : 
    6747                 :             :   /* Optimize comparisons with upper and lower bounds.  */
    6748                 :    90201565 :   scalar_int_mode int_mode;
    6749                 :    90201565 :   if (CONST_INT_P (trueop1)
    6750                 :    64508651 :       && is_a <scalar_int_mode> (mode, &int_mode)
    6751                 :    64508651 :       && HWI_COMPUTABLE_MODE_P (int_mode)
    6752                 :   154144961 :       && !side_effects_p (trueop0))
    6753                 :             :     {
    6754                 :    63856522 :       int sign;
    6755                 :    63856522 :       unsigned HOST_WIDE_INT nonzero = nonzero_bits (trueop0, int_mode);
    6756                 :    63856522 :       HOST_WIDE_INT val = INTVAL (trueop1);
    6757                 :    63856522 :       HOST_WIDE_INT mmin, mmax;
    6758                 :             : 
    6759                 :    63856522 :       if (code == GEU
    6760                 :    63856522 :           || code == LEU
    6761                 :    61187116 :           || code == GTU
    6762                 :    61187116 :           || code == LTU)
    6763                 :             :         sign = 0;
    6764                 :             :       else
    6765                 :    63856522 :         sign = 1;
    6766                 :             : 
    6767                 :             :       /* Get a reduced range if the sign bit is zero.  */
    6768                 :    63856522 :       if (nonzero <= (GET_MODE_MASK (int_mode) >> 1))
    6769                 :             :         {
    6770                 :     6123737 :           mmin = 0;
    6771                 :     6123737 :           mmax = nonzero;
    6772                 :             :         }
    6773                 :             :       else
    6774                 :             :         {
    6775                 :    57732785 :           rtx mmin_rtx, mmax_rtx;
    6776                 :    57732785 :           get_mode_bounds (int_mode, sign, int_mode, &mmin_rtx, &mmax_rtx);
    6777                 :             : 
    6778                 :    57732785 :           mmin = INTVAL (mmin_rtx);
    6779                 :    57732785 :           mmax = INTVAL (mmax_rtx);
    6780                 :    57732785 :           if (sign)
    6781                 :             :             {
    6782                 :    52798650 :               unsigned int sign_copies
    6783                 :    52798650 :                 = num_sign_bit_copies (trueop0, int_mode);
    6784                 :             : 
    6785                 :    52798650 :               mmin >>= (sign_copies - 1);
    6786                 :    52798650 :               mmax >>= (sign_copies - 1);
    6787                 :             :             }
    6788                 :             :         }
    6789                 :             : 
    6790                 :    63856522 :       switch (code)
    6791                 :             :         {
    6792                 :             :         /* x >= y is always true for y <= mmin, always false for y > mmax.  */
    6793                 :      387297 :         case GEU:
    6794                 :      387297 :           if ((unsigned HOST_WIDE_INT) val <= (unsigned HOST_WIDE_INT) mmin)
    6795                 :       10939 :             return const_true_rtx;
    6796                 :      376358 :           if ((unsigned HOST_WIDE_INT) val > (unsigned HOST_WIDE_INT) mmax)
    6797                 :          54 :             return const0_rtx;
    6798                 :             :           break;
    6799                 :      945833 :         case GE:
    6800                 :      945833 :           if (val <= mmin)
    6801                 :        1720 :             return const_true_rtx;
    6802                 :      944113 :           if (val > mmax)
    6803                 :           0 :             return const0_rtx;
    6804                 :             :           break;
    6805                 :             : 
    6806                 :             :         /* x <= y is always true for y >= mmax, always false for y < mmin.  */
    6807                 :     2282109 :         case LEU:
    6808                 :     2282109 :           if ((unsigned HOST_WIDE_INT) val >= (unsigned HOST_WIDE_INT) mmax)
    6809                 :       10907 :             return const_true_rtx;
    6810                 :     2271202 :           if ((unsigned HOST_WIDE_INT) val < (unsigned HOST_WIDE_INT) mmin)
    6811                 :           0 :             return const0_rtx;
    6812                 :             :           break;
    6813                 :     2012230 :         case LE:
    6814                 :     2012230 :           if (val >= mmax)
    6815                 :         228 :             return const_true_rtx;
    6816                 :     2012002 :           if (val < mmin)
    6817                 :           0 :             return const0_rtx;
    6818                 :             :           break;
    6819                 :             : 
    6820                 :    23840952 :         case EQ:
    6821                 :             :           /* x == y is always false for y out of range.  */
    6822                 :    23840952 :           if (val < mmin || val > mmax)
    6823                 :         406 :             return const0_rtx;
    6824                 :             :           break;
    6825                 :             : 
    6826                 :             :         /* x > y is always false for y >= mmax, always true for y < mmin.  */
    6827                 :     2213081 :         case GTU:
    6828                 :     2213081 :           if ((unsigned HOST_WIDE_INT) val >= (unsigned HOST_WIDE_INT) mmax)
    6829                 :      126390 :             return const0_rtx;
    6830                 :     2086691 :           if ((unsigned HOST_WIDE_INT) val < (unsigned HOST_WIDE_INT) mmin)
    6831                 :           0 :             return const_true_rtx;
    6832                 :             :           break;
    6833                 :     1900101 :         case GT:
    6834                 :     1900101 :           if (val >= mmax)
    6835                 :          93 :             return const0_rtx;
    6836                 :     1900008 :           if (val < mmin)
    6837                 :           5 :             return const_true_rtx;
    6838                 :             :           break;
    6839                 :             : 
    6840                 :             :         /* x < y is always false for y <= mmin, always true for y > mmax.  */
    6841                 :      589743 :         case LTU:
    6842                 :      589743 :           if ((unsigned HOST_WIDE_INT) val <= (unsigned HOST_WIDE_INT) mmin)
    6843                 :        2796 :             return const0_rtx;
    6844                 :      586947 :           if ((unsigned HOST_WIDE_INT) val > (unsigned HOST_WIDE_INT) mmax)
    6845                 :       71008 :             return const_true_rtx;
    6846                 :             :           break;
    6847                 :     1031877 :         case LT:
    6848                 :     1031877 :           if (val <= mmin)
    6849                 :        2036 :             return const0_rtx;
    6850                 :     1029841 :           if (val > mmax)
    6851                 :        3218 :             return const_true_rtx;
    6852                 :             :           break;
    6853                 :             : 
    6854                 :    28653299 :         case NE:
    6855                 :             :           /* x != y is always true for y out of range.  */
    6856                 :    28653299 :           if (val < mmin || val > mmax)
    6857                 :         140 :             return const_true_rtx;
    6858                 :             :           break;
    6859                 :             : 
    6860                 :             :         default:
    6861                 :             :           break;
    6862                 :             :         }
    6863                 :             :     }
    6864                 :             : 
    6865                 :             :   /* Optimize integer comparisons with zero.  */
    6866                 :    89971625 :   if (is_a <scalar_int_mode> (mode, &int_mode)
    6867                 :    87423780 :       && trueop1 == const0_rtx
    6868                 :    46932375 :       && !side_effects_p (trueop0))
    6869                 :             :     {
    6870                 :             :       /* Some addresses are known to be nonzero.  We don't know
    6871                 :             :          their sign, but equality comparisons are known.  */
    6872                 :    46843949 :       if (nonzero_address_p (trueop0))
    6873                 :             :         {
    6874                 :         433 :           if (code == EQ || code == LEU)
    6875                 :         277 :             return const0_rtx;
    6876                 :         156 :           if (code == NE || code == GTU)
    6877                 :         156 :             return const_true_rtx;
    6878                 :             :         }
    6879                 :             : 
    6880                 :             :       /* See if the first operand is an IOR with a constant.  If so, we
    6881                 :             :          may be able to determine the result of this comparison.  */
    6882                 :    46843516 :       if (GET_CODE (op0) == IOR)
    6883                 :             :         {
    6884                 :      582048 :           rtx inner_const = avoid_constant_pool_reference (XEXP (op0, 1));
    6885                 :      582048 :           if (CONST_INT_P (inner_const) && inner_const != const0_rtx)
    6886                 :             :             {
    6887                 :         276 :               int sign_bitnum = GET_MODE_PRECISION (int_mode) - 1;
    6888                 :         552 :               int has_sign = (HOST_BITS_PER_WIDE_INT >= sign_bitnum
    6889                 :         276 :                               && (UINTVAL (inner_const)
    6890                 :         276 :                                   & (HOST_WIDE_INT_1U
    6891                 :             :                                      << sign_bitnum)));
    6892                 :             : 
    6893                 :         276 :               switch (code)
    6894                 :             :                 {
    6895                 :             :                 case EQ:
    6896                 :             :                 case LEU:
    6897                 :             :                   return const0_rtx;
    6898                 :           4 :                 case NE:
    6899                 :           4 :                 case GTU:
    6900                 :           4 :                   return const_true_rtx;
    6901                 :          68 :                 case LT:
    6902                 :          68 :                 case LE:
    6903                 :          68 :                   if (has_sign)
    6904                 :           0 :                     return const_true_rtx;
    6905                 :             :                   break;
    6906                 :         200 :                 case GT:
    6907                 :         200 :                 case GE:
    6908                 :         200 :                   if (has_sign)
    6909                 :             :                     return const0_rtx;
    6910                 :             :                   break;
    6911                 :             :                 default:
    6912                 :             :                   break;
    6913                 :             :                 }
    6914                 :             :             }
    6915                 :             :         }
    6916                 :             :     }
    6917                 :             : 
    6918                 :             :   /* Optimize comparison of ABS with zero.  */
    6919                 :    47175757 :   if (trueop1 == CONST0_RTX (mode) && !side_effects_p (trueop0)
    6920                 :   137058094 :       && (GET_CODE (trueop0) == ABS
    6921                 :    47086583 :           || (GET_CODE (trueop0) == FLOAT_EXTEND
    6922                 :          46 :               && GET_CODE (XEXP (trueop0, 0)) == ABS)))
    6923                 :             :     {
    6924                 :         519 :       switch (code)
    6925                 :             :         {
    6926                 :          44 :         case LT:
    6927                 :             :           /* Optimize abs(x) < 0.0.  */
    6928                 :          44 :           if (!INTEGRAL_MODE_P (mode) && !HONOR_SNANS (mode))
    6929                 :           0 :             return const0_rtx;
    6930                 :             :           break;
    6931                 :             : 
    6932                 :          42 :         case GE:
    6933                 :             :           /* Optimize abs(x) >= 0.0.  */
    6934                 :          42 :           if (!INTEGRAL_MODE_P (mode) && !HONOR_NANS (mode))
    6935                 :           0 :             return const_true_rtx;
    6936                 :             :           break;
    6937                 :             : 
    6938                 :           0 :         case UNGE:
    6939                 :             :           /* Optimize ! (abs(x) < 0.0).  */
    6940                 :           0 :           return const_true_rtx;
    6941                 :             : 
    6942                 :             :         default:
    6943                 :             :           break;
    6944                 :             :         }
    6945                 :             :     }
    6946                 :             : 
    6947                 :             :   return 0;
    6948                 :             : }
    6949                 :             : 
    6950                 :             : /* Recognize expressions of the form (X CMP 0) ? VAL : OP (X)
    6951                 :             :    where OP is CLZ or CTZ and VAL is the value from CLZ_DEFINED_VALUE_AT_ZERO
    6952                 :             :    or CTZ_DEFINED_VALUE_AT_ZERO respectively and return OP (X) if the expression
    6953                 :             :    can be simplified to that or NULL_RTX if not.
    6954                 :             :    Assume X is compared against zero with CMP_CODE and the true
    6955                 :             :    arm is TRUE_VAL and the false arm is FALSE_VAL.  */
    6956                 :             : 
    6957                 :             : rtx
    6958                 :    28598295 : simplify_context::simplify_cond_clz_ctz (rtx x, rtx_code cmp_code,
    6959                 :             :                                          rtx true_val, rtx false_val)
    6960                 :             : {
    6961                 :    28598295 :   if (cmp_code != EQ && cmp_code != NE)
    6962                 :             :     return NULL_RTX;
    6963                 :             : 
    6964                 :             :   /* Result on X == 0 and X !=0 respectively.  */
    6965                 :    20808939 :   rtx on_zero, on_nonzero;
    6966                 :    20808939 :   if (cmp_code == EQ)
    6967                 :             :     {
    6968                 :             :       on_zero = true_val;
    6969                 :             :       on_nonzero = false_val;
    6970                 :             :     }
    6971                 :             :   else
    6972                 :             :     {
    6973                 :    11162489 :       on_zero = false_val;
    6974                 :    11162489 :       on_nonzero = true_val;
    6975                 :             :     }
    6976                 :             : 
    6977                 :    20808939 :   rtx_code op_code = GET_CODE (on_nonzero);
    6978                 :    20808939 :   if ((op_code != CLZ && op_code != CTZ)
    6979                 :        1798 :       || !rtx_equal_p (XEXP (on_nonzero, 0), x)
    6980                 :    20809851 :       || !CONST_INT_P (on_zero))
    6981                 :    20808659 :     return NULL_RTX;
    6982                 :             : 
    6983                 :         280 :   HOST_WIDE_INT op_val;
    6984                 :         280 :   scalar_int_mode mode ATTRIBUTE_UNUSED
    6985                 :         280 :     = as_a <scalar_int_mode> (GET_MODE (XEXP (on_nonzero, 0)));
    6986                 :           0 :   if (((op_code == CLZ && CLZ_DEFINED_VALUE_AT_ZERO (mode, op_val))
    6987                 :         560 :        || (op_code == CTZ && CTZ_DEFINED_VALUE_AT_ZERO (mode, op_val)))
    6988                 :         304 :       && op_val == INTVAL (on_zero))
    6989                 :             :     return on_nonzero;
    6990                 :             : 
    6991                 :             :   return NULL_RTX;
    6992                 :             : }
    6993                 :             : 
    6994                 :             : /* Try to simplify X given that it appears within operand OP of a
    6995                 :             :    VEC_MERGE operation whose mask is MASK.  X need not use the same
    6996                 :             :    vector mode as the VEC_MERGE, but it must have the same number of
    6997                 :             :    elements.
    6998                 :             : 
    6999                 :             :    Return the simplified X on success, otherwise return NULL_RTX.  */
    7000                 :             : 
    7001                 :             : rtx
    7002                 :     1390133 : simplify_context::simplify_merge_mask (rtx x, rtx mask, int op)
    7003                 :             : {
    7004                 :     1390133 :   gcc_assert (VECTOR_MODE_P (GET_MODE (x)));
    7005                 :     2780266 :   poly_uint64 nunits = GET_MODE_NUNITS (GET_MODE (x));
    7006                 :     1390133 :   if (GET_CODE (x) == VEC_MERGE && rtx_equal_p (XEXP (x, 2), mask))
    7007                 :             :     {
    7008                 :        5535 :       if (side_effects_p (XEXP (x, 1 - op)))
    7009                 :             :         return NULL_RTX;
    7010                 :             : 
    7011                 :        5287 :       return XEXP (x, op);
    7012                 :             :     }
    7013                 :     1384598 :   if (UNARY_P (x)
    7014                 :      175225 :       && VECTOR_MODE_P (GET_MODE (XEXP (x, 0)))
    7015                 :     1446190 :       && known_eq (GET_MODE_NUNITS (GET_MODE (XEXP (x, 0))), nunits))
    7016                 :             :     {
    7017                 :       25901 :       rtx top0 = simplify_merge_mask (XEXP (x, 0), mask, op);
    7018                 :       25901 :       if (top0)
    7019                 :         496 :         return simplify_gen_unary (GET_CODE (x), GET_MODE (x), top0,
    7020                 :         496 :                                    GET_MODE (XEXP (x, 0)));
    7021                 :             :     }
    7022                 :     1384102 :   if (BINARY_P (x)
    7023                 :      148559 :       && VECTOR_MODE_P (GET_MODE (XEXP (x, 0)))
    7024                 :      293836 :       && known_eq (GET_MODE_NUNITS (GET_MODE (XEXP (x, 0))), nunits)
    7025                 :      120210 :       && VECTOR_MODE_P (GET_MODE (XEXP (x, 1)))
    7026                 :     1560780 :       && known_eq (GET_MODE_NUNITS (GET_MODE (XEXP (x, 1))), nunits))
    7027                 :             :     {
    7028                 :       88339 :       rtx top0 = simplify_merge_mask (XEXP (x, 0), mask, op);
    7029                 :       88339 :       rtx top1 = simplify_merge_mask (XEXP (x, 1), mask, op);
    7030                 :       88339 :       if (top0 || top1)
    7031                 :             :         {
    7032                 :         817 :           if (COMPARISON_P (x))
    7033                 :           0 :             return simplify_gen_relational (GET_CODE (x), GET_MODE (x),
    7034                 :           0 :                                             GET_MODE (XEXP (x, 0)) != VOIDmode
    7035                 :             :                                             ? GET_MODE (XEXP (x, 0))
    7036                 :           0 :                                             : GET_MODE (XEXP (x, 1)),
    7037                 :             :                                             top0 ? top0 : XEXP (x, 0),
    7038                 :           0 :                                             top1 ? top1 : XEXP (x, 1));
    7039                 :             :           else
    7040                 :         817 :             return simplify_gen_binary (GET_CODE (x), GET_MODE (x),
    7041                 :             :                                         top0 ? top0 : XEXP (x, 0),
    7042                 :         817 :                                         top1 ? top1 : XEXP (x, 1));
    7043                 :             :         }
    7044                 :             :     }
    7045                 :     1383285 :   if (GET_RTX_CLASS (GET_CODE (x)) == RTX_TERNARY
    7046                 :       26200 :       && VECTOR_MODE_P (GET_MODE (XEXP (x, 0)))
    7047                 :       52400 :       && known_eq (GET_MODE_NUNITS (GET_MODE (XEXP (x, 0))), nunits)
    7048                 :       26200 :       && VECTOR_MODE_P (GET_MODE (XEXP (x, 1)))
    7049                 :       52400 :       && known_eq (GET_MODE_NUNITS (GET_MODE (XEXP (x, 1))), nunits)
    7050                 :       26200 :       && VECTOR_MODE_P (GET_MODE (XEXP (x, 2)))
    7051                 :     1391287 :       && known_eq (GET_MODE_NUNITS (GET_MODE (XEXP (x, 2))), nunits))
    7052                 :             :     {
    7053                 :        4001 :       rtx top0 = simplify_merge_mask (XEXP (x, 0), mask, op);
    7054                 :        4001 :       rtx top1 = simplify_merge_mask (XEXP (x, 1), mask, op);
    7055                 :        4001 :       rtx top2 = simplify_merge_mask (XEXP (x, 2), mask, op);
    7056                 :        4001 :       if (top0 || top1 || top2)
    7057                 :         496 :         return simplify_gen_ternary (GET_CODE (x), GET_MODE (x),
    7058                 :         496 :                                      GET_MODE (XEXP (x, 0)),
    7059                 :             :                                      top0 ? top0 : XEXP (x, 0),
    7060                 :             :                                      top1 ? top1 : XEXP (x, 1),
    7061                 :         496 :                                      top2 ? top2 : XEXP (x, 2));
    7062                 :             :     }
    7063                 :             :   return NULL_RTX;
    7064                 :             : }
    7065                 :             : 
    7066                 :             : 
    7067                 :             : /* Simplify CODE, an operation with result mode MODE and three operands,
    7068                 :             :    OP0, OP1, and OP2.  OP0_MODE was the mode of OP0 before it became
    7069                 :             :    a constant.  Return 0 if no simplifications is possible.  */
    7070                 :             : 
    7071                 :             : rtx
    7072                 :    38781343 : simplify_context::simplify_ternary_operation (rtx_code code, machine_mode mode,
    7073                 :             :                                               machine_mode op0_mode,
    7074                 :             :                                               rtx op0, rtx op1, rtx op2)
    7075                 :             : {
    7076                 :    38781343 :   bool any_change = false;
    7077                 :    38781343 :   rtx tem, trueop2;
    7078                 :    38781343 :   scalar_int_mode int_mode, int_op0_mode;
    7079                 :    38781343 :   unsigned int n_elts;
    7080                 :             : 
    7081                 :    38781343 :   switch (code)
    7082                 :             :     {
    7083                 :      329908 :     case FMA:
    7084                 :             :       /* Simplify negations around the multiplication.  */
    7085                 :             :       /* -a * -b + c  =>  a * b + c.  */
    7086                 :      329908 :       if (GET_CODE (op0) == NEG)
    7087                 :             :         {
    7088                 :       87095 :           tem = simplify_unary_operation (NEG, mode, op1, mode);
    7089                 :       87095 :           if (tem)
    7090                 :         231 :             op1 = tem, op0 = XEXP (op0, 0), any_change = true;
    7091                 :             :         }
    7092                 :      242813 :       else if (GET_CODE (op1) == NEG)
    7093                 :             :         {
    7094                 :        1108 :           tem = simplify_unary_operation (NEG, mode, op0, mode);
    7095                 :        1108 :           if (tem)
    7096                 :           0 :             op0 = tem, op1 = XEXP (op1, 0), any_change = true;
    7097                 :             :         }
    7098                 :             : 
    7099                 :             :       /* Canonicalize the two multiplication operands.  */
    7100                 :             :       /* a * -b + c  =>  -b * a + c.  */
    7101                 :      329908 :       if (swap_commutative_operands_p (op0, op1))
    7102                 :             :         std::swap (op0, op1), any_change = true;
    7103                 :             : 
    7104                 :      304415 :       if (any_change)
    7105                 :       25714 :         return gen_rtx_FMA (mode, op0, op1, op2);
    7106                 :             :       return NULL_RTX;
    7107                 :             : 
    7108                 :      563329 :     case SIGN_EXTRACT:
    7109                 :      563329 :     case ZERO_EXTRACT:
    7110                 :      563329 :       if (CONST_INT_P (op0)
    7111                 :       15661 :           && CONST_INT_P (op1)
    7112                 :       15661 :           && CONST_INT_P (op2)
    7113                 :    38781368 :           && is_a <scalar_int_mode> (mode, &int_mode)
    7114                 :          25 :           && INTVAL (op1) + INTVAL (op2) <= GET_MODE_PRECISION (int_mode)
    7115                 :      563354 :           && HWI_COMPUTABLE_MODE_P (int_mode))
    7116                 :             :         {
    7117                 :             :           /* Extracting a bit-field from a constant */
    7118                 :          25 :           unsigned HOST_WIDE_INT val = UINTVAL (op0);
    7119                 :          25 :           HOST_WIDE_INT op1val = INTVAL (op1);
    7120                 :          25 :           HOST_WIDE_INT op2val = INTVAL (op2);
    7121                 :          25 :           if (!BITS_BIG_ENDIAN)
    7122                 :          25 :             val >>= op2val;
    7123                 :             :           else if (is_a <scalar_int_mode> (op0_mode, &int_op0_mode))
    7124                 :             :             val >>= GET_MODE_PRECISION (int_op0_mode) - op2val - op1val;
    7125                 :             :           else
    7126                 :             :             /* Not enough information to calculate the bit position.  */
    7127                 :             :             break;
    7128                 :             : 
    7129                 :          25 :           if (HOST_BITS_PER_WIDE_INT != op1val)
    7130                 :             :             {
    7131                 :             :               /* First zero-extend.  */
    7132                 :          22 :               val &= (HOST_WIDE_INT_1U << op1val) - 1;
    7133                 :             :               /* If desired, propagate sign bit.  */
    7134                 :          22 :               if (code == SIGN_EXTRACT
    7135                 :           4 :                   && (val & (HOST_WIDE_INT_1U << (op1val - 1)))
    7136                 :           4 :                      != 0)
    7137                 :           1 :                 val |= ~ ((HOST_WIDE_INT_1U << op1val) - 1);
    7138                 :             :             }
    7139                 :             : 
    7140                 :          25 :           return gen_int_mode (val, int_mode);
    7141                 :             :         }
    7142                 :             :       break;
    7143                 :             : 
    7144                 :    37221717 :     case IF_THEN_ELSE:
    7145                 :    37221717 :       if (CONST_INT_P (op0))
    7146                 :      286209 :         return op0 != const0_rtx ? op1 : op2;
    7147                 :             : 
    7148                 :             :       /* Convert c ? a : a into "a".  */
    7149                 :    37026816 :       if (rtx_equal_p (op1, op2) && ! side_effects_p (op0))
    7150                 :             :         return op1;
    7151                 :             : 
    7152                 :             :       /* Convert a != b ? a : b into "a".  */
    7153                 :    37023748 :       if (GET_CODE (op0) == NE
    7154                 :    14602713 :           && ! side_effects_p (op0)
    7155                 :    14564972 :           && ! HONOR_NANS (mode)
    7156                 :    14561146 :           && ! HONOR_SIGNED_ZEROS (mode)
    7157                 :    51584894 :           && ((rtx_equal_p (XEXP (op0, 0), op1)
    7158                 :       75307 :                && rtx_equal_p (XEXP (op0, 1), op2))
    7159                 :    14561127 :               || (rtx_equal_p (XEXP (op0, 0), op2)
    7160                 :        3349 :                   && rtx_equal_p (XEXP (op0, 1), op1))))
    7161                 :         161 :         return op1;
    7162                 :             : 
    7163                 :             :       /* Convert a == b ? a : b into "b".  */
    7164                 :    37023587 :       if (GET_CODE (op0) == EQ
    7165                 :    11765649 :           && ! side_effects_p (op0)
    7166                 :    11755524 :           && ! HONOR_NANS (mode)
    7167                 :    11654980 :           && ! HONOR_SIGNED_ZEROS (mode)
    7168                 :    48678567 :           && ((rtx_equal_p (XEXP (op0, 0), op1)
    7169                 :       14535 :                && rtx_equal_p (XEXP (op0, 1), op2))
    7170                 :    11654962 :               || (rtx_equal_p (XEXP (op0, 0), op2)
    7171                 :        6690 :                   && rtx_equal_p (XEXP (op0, 1), op1))))
    7172                 :          29 :         return op2;
    7173                 :             : 
    7174                 :             :       /* Convert a != 0 ? -a : 0 into "-a".  */
    7175                 :    37023558 :       if (GET_CODE (op0) == NE
    7176                 :    14602552 :           && ! side_effects_p (op0)
    7177                 :    14564811 :           && ! HONOR_NANS (mode)
    7178                 :    14560985 :           && ! HONOR_SIGNED_ZEROS (mode)
    7179                 :    14560985 :           && XEXP (op0, 1) == CONST0_RTX (mode)
    7180                 :    11158644 :           && op2 == CONST0_RTX (mode)
    7181                 :       76074 :           && GET_CODE (op1) == NEG
    7182                 :    37023609 :           && rtx_equal_p (XEXP (op0, 0), XEXP (op1, 0)))
    7183                 :             :         return op1;
    7184                 :             : 
    7185                 :             :       /* Convert a == 0 ? 0 : -a into "-a".  */
    7186                 :    37023553 :       if (GET_CODE (op0) == EQ
    7187                 :    11765620 :           && ! side_effects_p (op0)
    7188                 :    11755495 :           && ! HONOR_NANS (mode)
    7189                 :    11654951 :           && ! HONOR_SIGNED_ZEROS (mode)
    7190                 :    11654951 :           && op1 == CONST0_RTX (mode)
    7191                 :       38527 :           && XEXP (op0, 1) == CONST0_RTX (mode)
    7192                 :       19820 :           && GET_CODE (op2) == NEG
    7193                 :    37023557 :           && rtx_equal_p (XEXP (op0, 0), XEXP (op2, 0)))
    7194                 :             :         return op2;
    7195                 :             : 
    7196                 :             :       /* Convert (!c) != {0,...,0} ? a : b into
    7197                 :             :          c != {0,...,0} ? b : a for vector modes.  */
    7198                 :    37023549 :       if (VECTOR_MODE_P (GET_MODE (op1))
    7199                 :       11547 :           && GET_CODE (op0) == NE
    7200                 :         465 :           && GET_CODE (XEXP (op0, 0)) == NOT
    7201                 :           0 :           && GET_CODE (XEXP (op0, 1)) == CONST_VECTOR)
    7202                 :             :         {
    7203                 :           0 :           rtx cv = XEXP (op0, 1);
    7204                 :           0 :           int nunits;
    7205                 :           0 :           bool ok = true;
    7206                 :           0 :           if (!CONST_VECTOR_NUNITS (cv).is_constant (&nunits))
    7207                 :             :             ok = false;
    7208                 :             :           else
    7209                 :           0 :             for (int i = 0; i < nunits; ++i)
    7210                 :           0 :               if (CONST_VECTOR_ELT (cv, i) != const0_rtx)
    7211                 :             :                 {
    7212                 :             :                   ok = false;
    7213                 :             :                   break;
    7214                 :             :                 }
    7215                 :           0 :           if (ok)
    7216                 :             :             {
    7217                 :           0 :               rtx new_op0 = gen_rtx_NE (GET_MODE (op0),
    7218                 :             :                                         XEXP (XEXP (op0, 0), 0),
    7219                 :             :                                         XEXP (op0, 1));
    7220                 :           0 :               rtx retval = gen_rtx_IF_THEN_ELSE (mode, new_op0, op2, op1);
    7221                 :           0 :               return retval;
    7222                 :             :             }
    7223                 :             :         }
    7224                 :             : 
    7225                 :             :       /* Convert x == 0 ? N : clz (x) into clz (x) when
    7226                 :             :          CLZ_DEFINED_VALUE_AT_ZERO is defined to N for the mode of x.
    7227                 :             :          Similarly for ctz (x).  */
    7228                 :    37022599 :       if (COMPARISON_P (op0) && !side_effects_p (op0)
    7229                 :    73961435 :           && XEXP (op0, 1) == const0_rtx)
    7230                 :             :         {
    7231                 :    28598295 :           rtx simplified
    7232                 :    28598295 :             = simplify_cond_clz_ctz (XEXP (op0, 0), GET_CODE (op0),
    7233                 :             :                                      op1, op2);
    7234                 :    28598295 :           if (simplified)
    7235                 :             :             return simplified;
    7236                 :             :         }
    7237                 :             : 
    7238                 :    37023549 :       if (COMPARISON_P (op0) && ! side_effects_p (op0))
    7239                 :             :         {
    7240                 :    73875772 :           machine_mode cmp_mode = (GET_MODE (XEXP (op0, 0)) == VOIDmode
    7241                 :    36937886 :                                         ? GET_MODE (XEXP (op0, 1))
    7242                 :             :                                         : GET_MODE (XEXP (op0, 0)));
    7243                 :    36937886 :           rtx temp;
    7244                 :             : 
    7245                 :             :           /* Look for happy constants in op1 and op2.  */
    7246                 :    36937886 :           if (CONST_INT_P (op1) && CONST_INT_P (op2))
    7247                 :             :             {
    7248                 :      167925 :               HOST_WIDE_INT t = INTVAL (op1);
    7249                 :      167925 :               HOST_WIDE_INT f = INTVAL (op2);
    7250                 :             : 
    7251                 :      167925 :               if (t == STORE_FLAG_VALUE && f == 0)
    7252                 :       30222 :                 code = GET_CODE (op0);
    7253                 :      137703 :               else if (t == 0 && f == STORE_FLAG_VALUE)
    7254                 :             :                 {
    7255                 :       31530 :                   enum rtx_code tmp;
    7256                 :       31530 :                   tmp = reversed_comparison_code (op0, NULL);
    7257                 :       31530 :                   if (tmp == UNKNOWN)
    7258                 :             :                     break;
    7259                 :             :                   code = tmp;
    7260                 :             :                 }
    7261                 :             :               else
    7262                 :             :                 break;
    7263                 :             : 
    7264                 :       56397 :               return simplify_gen_relational (code, mode, cmp_mode,
    7265                 :       56397 :                                               XEXP (op0, 0), XEXP (op0, 1));
    7266                 :             :             }
    7267                 :             : 
    7268                 :    36769961 :           temp = simplify_relational_operation (GET_CODE (op0), op0_mode,
    7269                 :             :                                                 cmp_mode, XEXP (op0, 0),
    7270                 :             :                                                 XEXP (op0, 1));
    7271                 :             : 
    7272                 :             :           /* See if any simplifications were possible.  */
    7273                 :    36769961 :           if (temp)
    7274                 :             :             {
    7275                 :        5914 :               if (CONST_INT_P (temp))
    7276                 :         106 :                 return temp == const0_rtx ? op2 : op1;
    7277                 :        5857 :               else if (temp)
    7278                 :        5857 :                 return gen_rtx_IF_THEN_ELSE (mode, temp, op1, op2);
    7279                 :             :             }
    7280                 :             :         }
    7281                 :             :       break;
    7282                 :             : 
    7283                 :      666389 :     case VEC_MERGE:
    7284                 :      666389 :       gcc_assert (GET_MODE (op0) == mode);
    7285                 :      666389 :       gcc_assert (GET_MODE (op1) == mode);
    7286                 :      666389 :       gcc_assert (VECTOR_MODE_P (mode));
    7287                 :      666389 :       trueop2 = avoid_constant_pool_reference (op2);
    7288                 :      666389 :       if (CONST_INT_P (trueop2)
    7289                 :     1008712 :           && GET_MODE_NUNITS (mode).is_constant (&n_elts))
    7290                 :             :         {
    7291                 :      342323 :           unsigned HOST_WIDE_INT sel = UINTVAL (trueop2);
    7292                 :      342323 :           unsigned HOST_WIDE_INT mask;
    7293                 :      342323 :           if (n_elts == HOST_BITS_PER_WIDE_INT)
    7294                 :             :             mask = -1;
    7295                 :             :           else
    7296                 :      341149 :             mask = (HOST_WIDE_INT_1U << n_elts) - 1;
    7297                 :             : 
    7298                 :      342323 :           if (!(sel & mask) && !side_effects_p (op0))
    7299                 :             :             return op1;
    7300                 :      341784 :           if ((sel & mask) == mask && !side_effects_p (op1))
    7301                 :             :             return op0;
    7302                 :             : 
    7303                 :      330695 :           rtx trueop0 = avoid_constant_pool_reference (op0);
    7304                 :      330695 :           rtx trueop1 = avoid_constant_pool_reference (op1);
    7305                 :      330695 :           if (GET_CODE (trueop0) == CONST_VECTOR
    7306                 :        9147 :               && GET_CODE (trueop1) == CONST_VECTOR)
    7307                 :             :             {
    7308                 :        4408 :               rtvec v = rtvec_alloc (n_elts);
    7309                 :        4408 :               unsigned int i;
    7310                 :             : 
    7311                 :       51546 :               for (i = 0; i < n_elts; i++)
    7312                 :       42730 :                 RTVEC_ELT (v, i) = ((sel & (HOST_WIDE_INT_1U << i))
    7313                 :       42730 :                                     ? CONST_VECTOR_ELT (trueop0, i)
    7314                 :       23797 :                                     : CONST_VECTOR_ELT (trueop1, i));
    7315                 :        4408 :               return gen_rtx_CONST_VECTOR (mode, v);
    7316                 :             :             }
    7317                 :             : 
    7318                 :             :           /* Replace (vec_merge (vec_merge a b m) c n) with (vec_merge b c n)
    7319                 :             :              if no element from a appears in the result.  */
    7320                 :      326287 :           if (GET_CODE (op0) == VEC_MERGE)
    7321                 :             :             {
    7322                 :       19496 :               tem = avoid_constant_pool_reference (XEXP (op0, 2));
    7323                 :       19496 :               if (CONST_INT_P (tem))
    7324                 :             :                 {
    7325                 :        1208 :                   unsigned HOST_WIDE_INT sel0 = UINTVAL (tem);
    7326                 :        1208 :                   if (!(sel & sel0 & mask) && !side_effects_p (XEXP (op0, 0)))
    7327                 :         106 :                     return simplify_gen_ternary (code, mode, mode,
    7328                 :         106 :                                                  XEXP (op0, 1), op1, op2);
    7329                 :        1102 :                   if (!(sel & ~sel0 & mask) && !side_effects_p (XEXP (op0, 1)))
    7330                 :         857 :                     return simplify_gen_ternary (code, mode, mode,
    7331                 :         857 :                                                  XEXP (op0, 0), op1, op2);
    7332                 :             :                 }
    7333                 :             :             }
    7334                 :      325324 :           if (GET_CODE (op1) == VEC_MERGE)
    7335                 :             :             {
    7336                 :         549 :               tem = avoid_constant_pool_reference (XEXP (op1, 2));
    7337                 :         549 :               if (CONST_INT_P (tem))
    7338                 :             :                 {
    7339                 :         521 :                   unsigned HOST_WIDE_INT sel1 = UINTVAL (tem);
    7340                 :         521 :                   if (!(~sel & sel1 & mask) && !side_effects_p (XEXP (op1, 0)))
    7341                 :         108 :                     return simplify_gen_ternary (code, mode, mode,
    7342                 :         108 :                                                  op0, XEXP (op1, 1), op2);
    7343                 :         413 :                   if (!(~sel & ~sel1 & mask) && !side_effects_p (XEXP (op1, 1)))
    7344                 :           1 :                     return simplify_gen_ternary (code, mode, mode,
    7345                 :           1 :                                                  op0, XEXP (op1, 0), op2);
    7346                 :             :                 }
    7347                 :             :             }
    7348                 :             : 
    7349                 :             :           /* Replace (vec_merge (vec_duplicate (vec_select a parallel (i))) a 1 << i)
    7350                 :             :              with a.  */
    7351                 :      325215 :           if (GET_CODE (op0) == VEC_DUPLICATE
    7352                 :      134256 :               && GET_CODE (XEXP (op0, 0)) == VEC_SELECT
    7353                 :         565 :               && GET_CODE (XEXP (XEXP (op0, 0), 1)) == PARALLEL
    7354                 :      326345 :               && known_eq (GET_MODE_NUNITS (GET_MODE (XEXP (op0, 0))), 1))
    7355                 :             :             {
    7356                 :         499 :               tem = XVECEXP ((XEXP (XEXP (op0, 0), 1)), 0, 0);
    7357                 :         499 :               if (CONST_INT_P (tem) && CONST_INT_P (op2))
    7358                 :             :                 {
    7359                 :         499 :                   if (XEXP (XEXP (op0, 0), 0) == op1
    7360                 :           2 :                       && UINTVAL (op2) == HOST_WIDE_INT_1U << UINTVAL (tem))
    7361                 :             :                     return op1;
    7362                 :             :                 }
    7363                 :             :             }
    7364                 :             :           /* Replace (vec_merge (vec_duplicate (X)) (const_vector [A, B])
    7365                 :             :              (const_int N))
    7366                 :             :              with (vec_concat (X) (B)) if N == 1 or
    7367                 :             :              (vec_concat (A) (X)) if N == 2.  */
    7368                 :      325213 :           if (GET_CODE (op0) == VEC_DUPLICATE
    7369                 :      134254 :               && GET_CODE (op1) == CONST_VECTOR
    7370                 :      130368 :               && known_eq (CONST_VECTOR_NUNITS (op1), 2)
    7371                 :        1222 :               && known_eq (GET_MODE_NUNITS (GET_MODE (op0)), 2)
    7372                 :      325824 :               && IN_RANGE (sel, 1, 2))
    7373                 :             :             {
    7374                 :         609 :               rtx newop0 = XEXP (op0, 0);
    7375                 :         609 :               rtx newop1 = CONST_VECTOR_ELT (op1, 2 - sel);
    7376                 :         609 :               if (sel == 2)
    7377                 :         126 :                 std::swap (newop0, newop1);
    7378                 :         609 :               return simplify_gen_binary (VEC_CONCAT, mode, newop0, newop1);
    7379                 :             :             }
    7380                 :             :           /* Replace (vec_merge (vec_duplicate x) (vec_concat (y) (z)) (const_int N))
    7381                 :             :              with (vec_concat x z) if N == 1, or (vec_concat y x) if N == 2.
    7382                 :             :              Only applies for vectors of two elements.  */
    7383                 :      324604 :           if (GET_CODE (op0) == VEC_DUPLICATE
    7384                 :      133645 :               && GET_CODE (op1) == VEC_CONCAT
    7385                 :           0 :               && known_eq (GET_MODE_NUNITS (GET_MODE (op0)), 2)
    7386                 :           0 :               && known_eq (GET_MODE_NUNITS (GET_MODE (op1)), 2)
    7387                 :      324604 :               && IN_RANGE (sel, 1, 2))
    7388                 :             :             {
    7389                 :           0 :               rtx newop0 = XEXP (op0, 0);
    7390                 :           0 :               rtx newop1 = XEXP (op1, 2 - sel);
    7391                 :           0 :               rtx otherop = XEXP (op1, sel - 1);
    7392                 :           0 :               if (sel == 2)
    7393                 :           0 :                 std::swap (newop0, newop1);
    7394                 :             :               /* Don't want to throw away the other part of the vec_concat if
    7395                 :             :                  it has side-effects.  */
    7396                 :           0 :               if (!side_effects_p (otherop))
    7397                 :           0 :                 return simplify_gen_binary (VEC_CONCAT, mode, newop0, newop1);
    7398                 :             :             }
    7399                 :             : 
    7400                 :             :           /* Replace:
    7401                 :             : 
    7402                 :             :               (vec_merge:outer (vec_duplicate:outer x:inner)
    7403                 :             :                                (subreg:outer y:inner 0)
    7404                 :             :                                (const_int N))
    7405                 :             : 
    7406                 :             :              with (vec_concat:outer x:inner y:inner) if N == 1,
    7407                 :             :              or (vec_concat:outer y:inner x:inner) if N == 2.
    7408                 :             : 
    7409                 :             :              Implicitly, this means we have a paradoxical subreg, but such
    7410                 :             :              a check is cheap, so make it anyway.
    7411                 :             : 
    7412                 :             :              Only applies for vectors of two elements.  */
    7413                 :      324604 :           if (GET_CODE (op0) == VEC_DUPLICATE
    7414                 :      133645 :               && GET_CODE (op1) == SUBREG
    7415                 :       47847 :               && GET_MODE (op1) == GET_MODE (op0)
    7416                 :       47847 :               && GET_MODE (SUBREG_REG (op1)) == GET_MODE (XEXP (op0, 0))
    7417                 :           0 :               && paradoxical_subreg_p (op1)
    7418                 :           0 :               && subreg_lowpart_p (op1)
    7419                 :           0 :               && known_eq (GET_MODE_NUNITS (GET_MODE (op0)), 2)
    7420                 :           0 :               && known_eq (GET_MODE_NUNITS (GET_MODE (op1)), 2)
    7421                 :      324604 :               && IN_RANGE (sel, 1, 2))
    7422                 :             :             {
    7423                 :           0 :               rtx newop0 = XEXP (op0, 0);
    7424                 :           0 :               rtx newop1 = SUBREG_REG (op1);
    7425                 :           0 :               if (sel == 2)
    7426                 :           0 :                 std::swap (newop0, newop1);
    7427                 :           0 :               return simplify_gen_binary (VEC_CONCAT, mode, newop0, newop1);
    7428                 :             :             }
    7429                 :             : 
    7430                 :             :           /* Same as above but with switched operands:
    7431                 :             :                 Replace (vec_merge:outer (subreg:outer x:inner 0)
    7432                 :             :                                          (vec_duplicate:outer y:inner)
    7433                 :             :                                (const_int N))
    7434                 :             : 
    7435                 :             :              with (vec_concat:outer x:inner y:inner) if N == 1,
    7436                 :             :              or (vec_concat:outer y:inner x:inner) if N == 2.  */
    7437                 :      324604 :           if (GET_CODE (op1) == VEC_DUPLICATE
    7438                 :       18773 :               && GET_CODE (op0) == SUBREG
    7439                 :       16001 :               && GET_MODE (op0) == GET_MODE (op1)
    7440                 :       16001 :               && GET_MODE (SUBREG_REG (op0)) == GET_MODE (XEXP (op1, 0))
    7441                 :           0 :               && paradoxical_subreg_p (op0)
    7442                 :           0 :               && subreg_lowpart_p (op0)
    7443                 :           0 :               && known_eq (GET_MODE_NUNITS (GET_MODE (op1)), 2)
    7444                 :           0 :               && known_eq (GET_MODE_NUNITS (GET_MODE (op0)), 2)
    7445                 :      324604 :               && IN_RANGE (sel, 1, 2))
    7446                 :             :             {
    7447                 :           0 :               rtx newop0 = SUBREG_REG (op0);
    7448                 :           0 :               rtx newop1 = XEXP (op1, 0);
    7449                 :           0 :               if (sel == 2)
    7450                 :           0 :                 std::swap (newop0, newop1);
    7451                 :           0 :               return simplify_gen_binary (VEC_CONCAT, mode, newop0, newop1);
    7452                 :             :             }
    7453                 :             : 
    7454                 :             :           /* Replace (vec_merge (vec_duplicate x) (vec_duplicate y)
    7455                 :             :                                  (const_int n))
    7456                 :             :              with (vec_concat x y) or (vec_concat y x) depending on value
    7457                 :             :              of N.  */
    7458                 :      324604 :           if (GET_CODE (op0) == VEC_DUPLICATE
    7459                 :      133645 :               && GET_CODE (op1) == VEC_DUPLICATE
    7460                 :         202 :               && known_eq (GET_MODE_NUNITS (GET_MODE (op0)), 2)
    7461                 :           0 :               && known_eq (GET_MODE_NUNITS (GET_MODE (op1)), 2)
    7462                 :      324604 :               && IN_RANGE (sel, 1, 2))
    7463                 :             :             {
    7464                 :           0 :               rtx newop0 = XEXP (op0, 0);
    7465                 :           0 :               rtx newop1 = XEXP (op1, 0);
    7466                 :           0 :               if (sel == 2)
    7467                 :           0 :                 std::swap (newop0, newop1);
    7468                 :             : 
    7469                 :           0 :               return simplify_gen_binary (VEC_CONCAT, mode, newop0, newop1);
    7470                 :             :             }
    7471                 :             :         }
    7472                 :             : 
    7473                 :      648670 :       if (rtx_equal_p (op0, op1)
    7474                 :      648670 :           && !side_effects_p (op2) && !side_effects_p (op1))
    7475                 :             :         return op0;
    7476                 :             : 
    7477                 :      648412 :       if (!side_effects_p (op2))
    7478                 :             :         {
    7479                 :      645074 :           rtx top0
    7480                 :      645074 :             = may_trap_p (op0) ? NULL_RTX : simplify_merge_mask (op0, op2, 0);
    7481                 :      645074 :           rtx top1
    7482                 :      645074 :             = may_trap_p (op1) ? NULL_RTX : simplify_merge_mask (op1, op2, 1);
    7483                 :      645074 :           if (top0 || top1)
    7484                 :         810 :             return simplify_gen_ternary (code, mode, mode,
    7485                 :             :                                          top0 ? top0 : op0,
    7486                 :         627 :                                          top1 ? top1 : op1, op2);
    7487                 :             :         }
    7488                 :             : 
    7489                 :             :       break;
    7490                 :             : 
    7491                 :           0 :     default:
    7492                 :           0 :       gcc_unreachable ();
    7493                 :             :     }
    7494                 :             : 
    7495                 :             :   return 0;
    7496                 :             : }
    7497                 :             : 
    7498                 :             : /* Try to calculate NUM_BYTES bytes of the target memory image of X,
    7499                 :             :    starting at byte FIRST_BYTE.  Return true on success and add the
    7500                 :             :    bytes to BYTES, such that each byte has BITS_PER_UNIT bits and such
    7501                 :             :    that the bytes follow target memory order.  Leave BYTES unmodified
    7502                 :             :    on failure.
    7503                 :             : 
    7504                 :             :    MODE is the mode of X.  The caller must reserve NUM_BYTES bytes in
    7505                 :             :    BYTES before calling this function.  */
    7506                 :             : 
    7507                 :             : bool
    7508                 :    11626291 : native_encode_rtx (machine_mode mode, rtx x, vec<target_unit> &bytes,
    7509                 :             :                    unsigned int first_byte, unsigned int num_bytes)
    7510                 :             : {
    7511                 :             :   /* Check the mode is sensible.  */
    7512                 :    11626291 :   gcc_assert (GET_MODE (x) == VOIDmode
    7513                 :             :               ? is_a <scalar_int_mode> (mode)
    7514                 :             :               : mode == GET_MODE (x));
    7515                 :             : 
    7516                 :    11626291 :   if (GET_CODE (x) == CONST_VECTOR)
    7517                 :             :     {
    7518                 :             :       /* CONST_VECTOR_ELT follows target memory order, so no shuffling
    7519                 :             :          is necessary.  The only complication is that MODE_VECTOR_BOOL
    7520                 :             :          vectors can have several elements per byte.  */
    7521                 :      768924 :       unsigned int elt_bits = vector_element_size (GET_MODE_PRECISION (mode),
    7522                 :             :                                                    GET_MODE_NUNITS (mode));
    7523                 :      384462 :       unsigned int elt = first_byte * BITS_PER_UNIT / elt_bits;
    7524                 :      384462 :       if (elt_bits < BITS_PER_UNIT)
    7525                 :             :         {
    7526                 :             :           /* This is the only case in which elements can be smaller than
    7527                 :             :              a byte.  */
    7528                 :           0 :           gcc_assert (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL);
    7529                 :           0 :           auto mask = GET_MODE_MASK (GET_MODE_INNER (mode));
    7530                 :           0 :           for (unsigned int i = 0; i < num_bytes; ++i)
    7531                 :             :             {
    7532                 :           0 :               target_unit value = 0;
    7533                 :           0 :               for (unsigned int j = 0; j < BITS_PER_UNIT; j += elt_bits)
    7534                 :             :                 {
    7535                 :           0 :                   if (INTVAL (CONST_VECTOR_ELT (x, elt)))
    7536                 :           0 :                     value |= mask << j;
    7537                 :           0 :                   elt += 1;
    7538                 :             :                 }
    7539                 :           0 :               bytes.quick_push (value);
    7540                 :             :             }
    7541                 :             :           return true;
    7542                 :             :         }
    7543                 :             : 
    7544                 :      384462 :       unsigned int start = bytes.length ();
    7545                 :      384462 :       unsigned int elt_bytes = GET_MODE_UNIT_SIZE (mode);
    7546                 :             :       /* Make FIRST_BYTE relative to ELT.  */
    7547                 :      384462 :       first_byte %= elt_bytes;
    7548                 :     1814834 :       while (num_bytes > 0)
    7549                 :             :         {
    7550                 :             :           /* Work out how many bytes we want from element ELT.  */
    7551                 :     1430372 :           unsigned int chunk_bytes = MIN (num_bytes, elt_bytes - first_byte);
    7552                 :     2860744 :           if (!native_encode_rtx (GET_MODE_INNER (mode),
    7553                 :             :                                   CONST_VECTOR_ELT (x, elt), bytes,
    7554                 :             :                                   first_byte, chunk_bytes))
    7555                 :             :             {
    7556                 :           0 :               bytes.truncate (start);
    7557                 :           0 :               return false;
    7558                 :             :             }
    7559                 :     1430372 :           elt += 1;
    7560                 :     1430372 :           first_byte = 0;
    7561                 :     1430372 :           num_bytes -= chunk_bytes;
    7562                 :             :         }
    7563                 :             :       return true;
    7564                 :             :     }
    7565                 :             : 
    7566                 :             :   /* All subsequent cases are limited to scalars.  */
    7567                 :    11241829 :   scalar_mode smode;
    7568                 :    11273308 :   if (!is_a <scalar_mode> (mode, &smode))
    7569                 :             :     return false;
    7570                 :             : 
    7571                 :             :   /* Make sure that the region is in range.  */
    7572                 :    11241829 :   unsigned int end_byte = first_byte + num_bytes;
    7573                 :    11241829 :   unsigned int mode_bytes = GET_MODE_SIZE (smode);
    7574                 :    11241829 :   gcc_assert (end_byte <= mode_bytes);
    7575                 :             : 
    7576                 :    11241829 :   if (CONST_SCALAR_INT_P (x))
    7577                 :             :     {
    7578                 :             :       /* The target memory layout is affected by both BYTES_BIG_ENDIAN
    7579                 :             :          and WORDS_BIG_ENDIAN.  Use the subreg machinery to get the lsb
    7580                 :             :          position of each byte.  */
    7581                 :    10718036 :       rtx_mode_t value (x, smode);
    7582                 :    10718036 :       wide_int_ref value_wi (value);
    7583                 :    48217384 :       for (unsigned int byte = first_byte; byte < end_byte; ++byte)
    7584                 :             :         {
    7585                 :             :           /* Always constant because the inputs are.  */
    7586                 :    37499348 :           unsigned int lsb
    7587                 :    37499348 :             = subreg_size_lsb (1, mode_bytes, byte).to_constant ();
    7588                 :             :           /* Operate directly on the encoding rather than using
    7589                 :             :              wi::extract_uhwi, so that we preserve the sign or zero
    7590                 :             :              extension for modes that are not a whole number of bits in
    7591                 :             :              size.  (Zero extension is only used for the combination of
    7592                 :             :              innermode == BImode && STORE_FLAG_VALUE == 1).  */
    7593                 :    37499348 :           unsigned int elt = lsb / HOST_BITS_PER_WIDE_INT;
    7594                 :    37499348 :           unsigned int shift = lsb % HOST_BITS_PER_WIDE_INT;
    7595                 :    37499348 :           unsigned HOST_WIDE_INT uhwi = value_wi.elt (elt);
    7596                 :    37499348 :           bytes.quick_push (uhwi >> shift);
    7597                 :             :         }
    7598                 :    10718036 :       return true;
    7599                 :             :     }
    7600                 :             : 
    7601                 :      523793 :   if (CONST_DOUBLE_P (x))
    7602                 :             :     {
    7603                 :             :       /* real_to_target produces an array of integers in target memory order.
    7604                 :             :          All integers before the last one have 32 bits; the last one may
    7605                 :             :          have 32 bits or fewer, depending on whether the mode bitsize
    7606                 :             :          is divisible by 32.  Each of these integers is then laid out
    7607                 :             :          in target memory as any other integer would be.  */
    7608                 :      492314 :       long el32[MAX_BITSIZE_MODE_ANY_MODE / 32];
    7609                 :      492314 :       real_to_target (el32, CONST_DOUBLE_REAL_VALUE (x), smode);
    7610                 :             : 
    7611                 :             :       /* The (maximum) number of target bytes per element of el32.  */
    7612                 :      492314 :       unsigned int bytes_per_el32 = 32 / BITS_PER_UNIT;
    7613                 :      492314 :       gcc_assert (bytes_per_el32 != 0);
    7614                 :             : 
    7615                 :             :       /* Build up the integers in a similar way to the CONST_SCALAR_INT_P
    7616                 :             :          handling above.  */
    7617                 :     3387013 :       for (unsigned int byte = first_byte; byte < end_byte; ++byte)
    7618                 :             :         {
    7619                 :     2894699 :           unsigned int index = byte / bytes_per_el32;
    7620                 :     2894699 :           unsigned int subbyte = byte % bytes_per_el32;
    7621                 :     2894699 :           unsigned int int_bytes = MIN (bytes_per_el32,
    7622                 :             :                                         mode_bytes - index * bytes_per_el32);
    7623                 :             :           /* Always constant because the inputs are.  */
    7624                 :     2894699 :           unsigned int lsb
    7625                 :     2894699 :             = subreg_size_lsb (1, int_bytes, subbyte).to_constant ();
    7626                 :     2894699 :           bytes.quick_push ((unsigned long) el32[index] >> lsb);
    7627                 :             :         }
    7628                 :      492314 :       return true;
    7629                 :             :     }
    7630                 :             : 
    7631                 :       31479 :   if (GET_CODE (x) == CONST_FIXED)
    7632                 :             :     {
    7633                 :           0 :       for (unsigned int byte = first_byte; byte < end_byte; ++byte)
    7634                 :             :         {
    7635                 :             :           /* Always constant because the inputs are.  */
    7636                 :           0 :           unsigned int lsb
    7637                 :           0 :             = subreg_size_lsb (1, mode_bytes, byte).to_constant ();
    7638                 :           0 :           unsigned HOST_WIDE_INT piece = CONST_FIXED_VALUE_LOW (x);
    7639                 :           0 :           if (lsb >= HOST_BITS_PER_WIDE_INT)
    7640                 :             :             {
    7641                 :           0 :               lsb -= HOST_BITS_PER_WIDE_INT;
    7642                 :           0 :               piece = CONST_FIXED_VALUE_HIGH (x);
    7643                 :             :             }
    7644                 :           0 :           bytes.quick_push (piece >> lsb);
    7645                 :             :         }
    7646                 :             :       return true;
    7647                 :             :     }
    7648                 :             : 
    7649                 :             :   return false;
    7650                 :             : }
    7651                 :             : 
    7652                 :             : /* Read a vector of mode MODE from the target memory image given by BYTES,
    7653                 :             :    starting at byte FIRST_BYTE.  The vector is known to be encodable using
    7654                 :             :    NPATTERNS interleaved patterns with NELTS_PER_PATTERN elements each,
    7655                 :             :    and BYTES is known to have enough bytes to supply NPATTERNS *
    7656                 :             :    NELTS_PER_PATTERN vector elements.  Each element of BYTES contains
    7657                 :             :    BITS_PER_UNIT bits and the bytes are in target memory order.
    7658                 :             : 
    7659                 :             :    Return the vector on success, otherwise return NULL_RTX.  */
    7660                 :             : 
    7661                 :             : rtx
    7662                 :      106878 : native_decode_vector_rtx (machine_mode mode, const vec<target_unit> &bytes,
    7663                 :             :                           unsigned int first_byte, unsigned int npatterns,
    7664                 :             :                           unsigned int nelts_per_pattern)
    7665                 :             : {
    7666                 :      106878 :   rtx_vector_builder builder (mode, npatterns, nelts_per_pattern);
    7667                 :             : 
    7668                 :      213756 :   unsigned int elt_bits = vector_element_size (GET_MODE_PRECISION (mode),
    7669                 :             :                                                GET_MODE_NUNITS (mode));
    7670                 :      106878 :   if (elt_bits < BITS_PER_UNIT)
    7671                 :             :     {
    7672                 :             :       /* This is the only case in which elements can be smaller than a byte.
    7673                 :             :          Element 0 is always in the lsb of the containing byte.  */
    7674                 :           0 :       gcc_assert (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL);
    7675                 :           0 :       for (unsigned int i = 0; i < builder.encoded_nelts (); ++i)
    7676                 :             :         {
    7677                 :           0 :           unsigned int bit_index = first_byte * BITS_PER_UNIT + i * elt_bits;
    7678                 :           0 :           unsigned int byte_index = bit_index / BITS_PER_UNIT;
    7679                 :           0 :           unsigned int lsb = bit_index % BITS_PER_UNIT;
    7680                 :           0 :           unsigned int value = bytes[byte_index] >> lsb;
    7681                 :           0 :           builder.quick_push (gen_int_mode (value, GET_MODE_INNER (mode)));
    7682                 :             :         }
    7683                 :             :     }
    7684                 :             :   else
    7685                 :             :     {
    7686                 :      464451 :       for (unsigned int i = 0; i < builder.encoded_nelts (); ++i)
    7687                 :             :         {
    7688                 :      715146 :           rtx x = native_decode_rtx (GET_MODE_INNER (mode), bytes, first_byte);
    7689                 :      357573 :           if (!x)
    7690                 :           0 :             return NULL_RTX;
    7691                 :      357573 :           builder.quick_push (x);
    7692                 :      357573 :           first_byte += elt_bits / BITS_PER_UNIT;
    7693                 :             :         }
    7694                 :             :     }
    7695                 :      106878 :   return builder.build ();
    7696                 :      106878 : }
    7697                 :             : 
    7698                 :             : /* Read an rtx of mode MODE from the target memory image given by BYTES,
    7699                 :             :    starting at byte FIRST_BYTE.  Each element of BYTES contains BITS_PER_UNIT
    7700                 :             :    bits and the bytes are in target memory order.  The image has enough
    7701                 :             :    values to specify all bytes of MODE.
    7702                 :             : 
    7703                 :             :    Return the rtx on success, otherwise return NULL_RTX.  */
    7704                 :             : 
    7705                 :             : rtx
    7706                 :    10233586 : native_decode_rtx (machine_mode mode, const vec<target_unit> &bytes,
    7707                 :             :                    unsigned int first_byte)
    7708                 :             : {
    7709                 :    10233586 :   if (VECTOR_MODE_P (mode))
    7710                 :             :     {
    7711                 :             :       /* If we know at compile time how many elements there are,
    7712                 :             :          pull each element directly from BYTES.  */
    7713                 :       24706 :       unsigned int nelts;
    7714                 :       49412 :       if (GET_MODE_NUNITS (mode).is_constant (&nelts))
    7715                 :       24706 :         return native_decode_vector_rtx (mode, bytes, first_byte, nelts, 1);
    7716                 :             :       return NULL_RTX;
    7717                 :             :     }
    7718                 :             : 
    7719                 :    10208880 :   scalar_int_mode imode;
    7720                 :    10208880 :   if (is_a <scalar_int_mode> (mode, &imode)
    7721                 :    10110429 :       && GET_MODE_PRECISION (imode) <= MAX_BITSIZE_MODE_ANY_INT)
    7722                 :             :     {
    7723                 :             :       /* Pull the bytes msb first, so that we can use simple
    7724                 :             :          shift-and-insert wide_int operations.  */
    7725                 :    10110429 :       unsigned int size = GET_MODE_SIZE (imode);
    7726                 :    10110429 :       wide_int result (wi::zero (GET_MODE_PRECISION (imode)));
    7727                 :    48268739 :       for (unsigned int i = 0; i < size; ++i)
    7728                 :             :         {
    7729                 :    38158310 :           unsigned int lsb = (size - i - 1) * BITS_PER_UNIT;
    7730                 :             :           /* Always constant because the inputs are.  */
    7731                 :    38158310 :           unsigned int subbyte
    7732                 :    38158310 :             = subreg_size_offset_from_lsb (1, size, lsb).to_constant ();
    7733                 :    38158310 :           result <<= BITS_PER_UNIT;
    7734                 :    38158310 :           result |= bytes[first_byte + subbyte];
    7735                 :             :         }
    7736                 :    10110429 :       return immed_wide_int_const (result, imode);
    7737                 :    10110429 :     }
    7738                 :             : 
    7739                 :       98451 :   scalar_float_mode fmode;
    7740                 :       98451 :   if (is_a <scalar_float_mode> (mode, &fmode))
    7741                 :             :     {
    7742                 :             :       /* We need to build an array of integers in target memory order.
    7743                 :             :          All integers before the last one have 32 bits; the last one may
    7744                 :             :          have 32 bits or fewer, depending on whether the mode bitsize
    7745                 :             :          is divisible by 32.  */
    7746                 :       98429 :       long el32[MAX_BITSIZE_MODE_ANY_MODE / 32];
    7747                 :       98429 :       unsigned int num_el32 = CEIL (GET_MODE_BITSIZE (fmode), 32);
    7748                 :       98429 :       memset (el32, 0, num_el32 * sizeof (long));
    7749                 :             : 
    7750                 :             :       /* The (maximum) number of target bytes per element of el32.  */
    7751                 :       98429 :       unsigned int bytes_per_el32 = 32 / BITS_PER_UNIT;
    7752                 :       98429 :       gcc_assert (bytes_per_el32 != 0);
    7753                 :             : 
    7754                 :       98429 :       unsigned int mode_bytes = GET_MODE_SIZE (fmode);
    7755                 :      720441 :       for (unsigned int byte = 0; byte < mode_bytes; ++byte)
    7756                 :             :         {
    7757                 :      622012 :           unsigned int index = byte / bytes_per_el32;
    7758                 :      622012 :           unsigned int subbyte = byte % bytes_per_el32;
    7759                 :      622012 :           unsigned int int_bytes = MIN (bytes_per_el32,
    7760                 :             :                                         mode_bytes - index * bytes_per_el32);
    7761                 :             :           /* Always constant because the inputs are.  */
    7762                 :      622012 :           unsigned int lsb
    7763                 :      622012 :             = subreg_size_lsb (1, int_bytes, subbyte).to_constant ();
    7764                 :      622012 :           el32[index] |= (unsigned long) bytes[first_byte + byte] << lsb;
    7765                 :             :         }
    7766                 :       98429 :       REAL_VALUE_TYPE r;
    7767                 :       98429 :       real_from_target (&r, el32, fmode);
    7768                 :       98429 :       return const_double_from_real_value (r, fmode);
    7769                 :             :     }
    7770                 :             : 
    7771                 :          22 :   if (ALL_SCALAR_FIXED_POINT_MODE_P (mode))
    7772                 :             :     {
    7773                 :           0 :       scalar_mode smode = as_a <scalar_mode> (mode);
    7774                 :           0 :       FIXED_VALUE_TYPE f;
    7775                 :           0 :       f.data.low = 0;
    7776                 :           0 :       f.data.high = 0;
    7777                 :           0 :       f.mode = smode;
    7778                 :             : 
    7779                 :           0 :       unsigned int mode_bytes = GET_MODE_SIZE (smode);
    7780                 :           0 :       for (unsigned int byte = 0; byte < mode_bytes; ++byte)
    7781                 :             :         {
    7782                 :             :           /* Always constant because the inputs are.  */
    7783                 :           0 :           unsigned int lsb
    7784                 :           0 :             = subreg_size_lsb (1, mode_bytes, byte).to_constant ();
    7785                 :           0 :           unsigned HOST_WIDE_INT unit = bytes[first_byte + byte];
    7786                 :           0 :           if (lsb >= HOST_BITS_PER_WIDE_INT)
    7787                 :           0 :             f.data.high |= unit << (lsb - HOST_BITS_PER_WIDE_INT);
    7788                 :             :           else
    7789                 :           0 :             f.data.low |= unit << lsb;
    7790                 :             :         }
    7791                 :           0 :       return CONST_FIXED_FROM_FIXED_VALUE (f, mode);
    7792                 :             :     }
    7793                 :             : 
    7794                 :             :   return NULL_RTX;
    7795                 :             : }
    7796                 :             : 
    7797                 :             : /* Simplify a byte offset BYTE into CONST_VECTOR X.  The main purpose
    7798                 :             :    is to convert a runtime BYTE value into a constant one.  */
    7799                 :             : 
    7800                 :             : static poly_uint64
    7801                 :      176570 : simplify_const_vector_byte_offset (rtx x, poly_uint64 byte)
    7802                 :             : {
    7803                 :             :   /* Cope with MODE_VECTOR_BOOL by operating on bits rather than bytes.  */
    7804                 :      176570 :   machine_mode mode = GET_MODE (x);
    7805                 :      353140 :   unsigned int elt_bits = vector_element_size (GET_MODE_PRECISION (mode),
    7806                 :             :                                                GET_MODE_NUNITS (mode));
    7807                 :             :   /* The number of bits needed to encode one element from each pattern.  */
    7808                 :      176570 :   unsigned int sequence_bits = CONST_VECTOR_NPATTERNS (x) * elt_bits;
    7809                 :             : 
    7810                 :             :   /* Identify the start point in terms of a sequence number and a byte offset
    7811                 :             :      within that sequence.  */
    7812                 :      176570 :   poly_uint64 first_sequence;
    7813                 :      176570 :   unsigned HOST_WIDE_INT subbit;
    7814                 :      176570 :   if (can_div_trunc_p (byte * BITS_PER_UNIT, sequence_bits,
    7815                 :             :                        &first_sequence, &subbit))
    7816                 :             :     {
    7817                 :      176570 :       unsigned int nelts_per_pattern = CONST_VECTOR_NELTS_PER_PATTERN (x);
    7818                 :      176570 :       if (nelts_per_pattern == 1)
    7819                 :             :         /* This is a duplicated vector, so the value of FIRST_SEQUENCE
    7820                 :             :            doesn't matter.  */
    7821                 :      126128 :         byte = subbit / BITS_PER_UNIT;
    7822                 :       50442 :       else if (nelts_per_pattern == 2 && known_gt (first_sequence, 0U))
    7823                 :             :         {
    7824                 :             :           /* The subreg drops the first element from each pattern and
    7825                 :             :              only uses the second element.  Find the first sequence
    7826                 :             :              that starts on a byte boundary.  */
    7827                 :        6987 :           subbit += least_common_multiple (sequence_bits, BITS_PER_UNIT);
    7828                 :        6987 :           byte = subbit / BITS_PER_UNIT;
    7829                 :             :         }
    7830                 :             :     }
    7831                 :      176570 :   return byte;
    7832                 :             : }
    7833                 :             : 
    7834                 :             : /* Subroutine of simplify_subreg in which:
    7835                 :             : 
    7836                 :             :    - X is known to be a CONST_VECTOR
    7837                 :             :    - OUTERMODE is known to be a vector mode
    7838                 :             : 
    7839                 :             :    Try to handle the subreg by operating on the CONST_VECTOR encoding
    7840                 :             :    rather than on each individual element of the CONST_VECTOR.
    7841                 :             : 
    7842                 :             :    Return the simplified subreg on success, otherwise return NULL_RTX.  */
    7843                 :             : 
    7844                 :             : static rtx
    7845                 :       89593 : simplify_const_vector_subreg (machine_mode outermode, rtx x,
    7846                 :             :                               machine_mode innermode, unsigned int first_byte)
    7847                 :             : {
    7848                 :             :   /* Paradoxical subregs of vectors have dubious semantics.  */
    7849                 :       89593 :   if (paradoxical_subreg_p (outermode, innermode))
    7850                 :             :     return NULL_RTX;
    7851                 :             : 
    7852                 :             :   /* We can only preserve the semantics of a stepped pattern if the new
    7853                 :             :      vector element is the same as the original one.  */
    7854                 :       89521 :   if (CONST_VECTOR_STEPPED_P (x)
    7855                 :      110451 :       && GET_MODE_INNER (outermode) != GET_MODE_INNER (innermode))
    7856                 :             :     return NULL_RTX;
    7857                 :             : 
    7858                 :             :   /* Cope with MODE_VECTOR_BOOL by operating on bits rather than bytes.  */
    7859                 :       82172 :   unsigned int x_elt_bits
    7860                 :       82172 :     = vector_element_size (GET_MODE_PRECISION (innermode),
    7861                 :             :                            GET_MODE_NUNITS (innermode));
    7862                 :       82172 :   unsigned int out_elt_bits
    7863                 :       82172 :     = vector_element_size (GET_MODE_PRECISION (outermode),
    7864                 :             :                            GET_MODE_NUNITS (outermode));
    7865                 :             : 
    7866                 :             :   /* The number of bits needed to encode one element from every pattern
    7867                 :             :      of the original vector.  */
    7868                 :       82172 :   unsigned int x_sequence_bits = CONST_VECTOR_NPATTERNS (x) * x_elt_bits;
    7869                 :             : 
    7870                 :             :   /* The number of bits needed to encode one element from every pattern
    7871                 :             :      of the result.  */
    7872                 :       82172 :   unsigned int out_sequence_bits
    7873                 :       82172 :     = least_common_multiple (x_sequence_bits, out_elt_bits);
    7874                 :             : 
    7875                 :             :   /* Work out the number of interleaved patterns in the output vector
    7876                 :             :      and the number of encoded elements per pattern.  */
    7877                 :       82172 :   unsigned int out_npatterns = out_sequence_bits / out_elt_bits;
    7878                 :       82172 :   unsigned int nelts_per_pattern = CONST_VECTOR_NELTS_PER_PATTERN (x);
    7879                 :             : 
    7880                 :             :   /* The encoding scheme requires the number of elements to be a multiple
    7881                 :             :      of the number of patterns, so that each pattern appears at least once
    7882                 :             :      and so that the same number of elements appear from each pattern.  */
    7883                 :      164344 :   bool ok_p = multiple_p (GET_MODE_NUNITS (outermode), out_npatterns);
    7884                 :       82172 :   unsigned int const_nunits;
    7885                 :      164344 :   if (GET_MODE_NUNITS (outermode).is_constant (&const_nunits)
    7886                 :       82172 :       && (!ok_p || out_npatterns * nelts_per_pattern > const_nunits))
    7887                 :             :     {
    7888                 :             :       /* Either the encoding is invalid, or applying it would give us
    7889                 :             :          more elements than we need.  Just encode each element directly.  */
    7890                 :             :       out_npatterns = const_nunits;
    7891                 :             :       nelts_per_pattern = 1;
    7892                 :             :     }
    7893                 :             :   else if (!ok_p)
    7894                 :             :     return NULL_RTX;
    7895                 :             : 
    7896                 :             :   /* Get enough bytes of X to form the new encoding.  */
    7897                 :       82172 :   unsigned int buffer_bits = out_npatterns * nelts_per_pattern * out_elt_bits;
    7898                 :       82172 :   unsigned int buffer_bytes = CEIL (buffer_bits, BITS_PER_UNIT);
    7899                 :       82172 :   auto_vec<target_unit, 128> buffer (buffer_bytes);
    7900                 :       82172 :   if (!native_encode_rtx (innermode, x, buffer, first_byte, buffer_bytes))
    7901                 :             :     return NULL_RTX;
    7902                 :             : 
    7903                 :             :   /* Reencode the bytes as OUTERMODE.  */
    7904                 :       82172 :   return native_decode_vector_rtx (outermode, buffer, 0, out_npatterns,
    7905                 :       82172 :                                    nelts_per_pattern);
    7906                 :       82172 : }
    7907                 :             : 
    7908                 :             : /* Try to simplify a subreg of a constant by encoding the subreg region
    7909                 :             :    as a sequence of target bytes and reading them back in the new mode.
    7910                 :             :    Return the new value on success, otherwise return null.
    7911                 :             : 
    7912                 :             :    The subreg has outer mode OUTERMODE, inner mode INNERMODE, inner value X
    7913                 :             :    and byte offset FIRST_BYTE.  */
    7914                 :             : 
    7915                 :             : static rtx
    7916                 :     9616021 : simplify_immed_subreg (fixed_size_mode outermode, rtx x,
    7917                 :             :                        machine_mode innermode, unsigned int first_byte)
    7918                 :             : {
    7919                 :     9616021 :   unsigned int buffer_bytes = GET_MODE_SIZE (outermode);
    7920                 :     9616021 :   auto_vec<target_unit, 128> buffer (buffer_bytes);
    7921                 :             : 
    7922                 :             :   /* Some ports misuse CCmode.  */
    7923                 :     9616021 :   if (GET_MODE_CLASS (outermode) == MODE_CC && CONST_INT_P (x))
    7924                 :             :     return x;
    7925                 :             : 
    7926                 :             :   /* Paradoxical subregs read undefined values for bytes outside of the
    7927                 :             :      inner value.  However, we have traditionally always sign-extended
    7928                 :             :      integer constants and zero-extended others.  */
    7929                 :     9615436 :   unsigned int inner_bytes = buffer_bytes;
    7930                 :     9615436 :   if (paradoxical_subreg_p (outermode, innermode))
    7931                 :             :     {
    7932                 :      798694 :       if (!GET_MODE_SIZE (innermode).is_constant (&inner_bytes))
    7933                 :           0 :         return NULL_RTX;
    7934                 :             : 
    7935                 :      399347 :       target_unit filler = 0;
    7936                 :      399347 :       if (CONST_SCALAR_INT_P (x) && wi::neg_p (rtx_mode_t (x, innermode)))
    7937                 :       33554 :         filler = -1;
    7938                 :             : 
    7939                 :             :       /* Add any leading bytes due to big-endian layout.  The number of
    7940                 :             :          bytes must be constant because both modes have constant size.  */
    7941                 :      399347 :       unsigned int leading_bytes
    7942                 :      399347 :         = -byte_lowpart_offset (outermode, innermode).to_constant ();
    7943                 :      399347 :       for (unsigned int i = 0; i < leading_bytes; ++i)
    7944                 :           0 :         buffer.quick_push (filler);
    7945                 :             : 
    7946                 :      399347 :       if (!native_encode_rtx (innermode, x, buffer, first_byte, inner_bytes))
    7947                 :           0 :         return NULL_RTX;
    7948                 :             : 
    7949                 :             :       /* Add any trailing bytes due to little-endian layout.  */
    7950                 :     4386226 :       while (buffer.length () < buffer_bytes)
    7951                 :     1793766 :         buffer.quick_push (filler);
    7952                 :             :     }
    7953                 :     9216089 :   else if (!native_encode_rtx (innermode, x, buffer, first_byte, inner_bytes))
    7954                 :             :     return NULL_RTX;
    7955                 :     9615436 :   rtx ret = native_decode_rtx (outermode, buffer, 0);
    7956                 :     9615436 :   if (ret && FLOAT_MODE_P (outermode))
    7957                 :             :     {
    7958                 :       68508 :       auto_vec<target_unit, 128> buffer2 (buffer_bytes);
    7959                 :       68508 :       if (!native_encode_rtx (outermode, ret, buffer2, 0, buffer_bytes))
    7960                 :             :         return NULL_RTX;
    7961                 :      659993 :       for (unsigned int i = 0; i < buffer_bytes; ++i)
    7962                 :      591525 :         if (buffer[i] != buffer2[i])
    7963                 :             :           return NULL_RTX;
    7964                 :       68508 :     }
    7965                 :             :   return ret;
    7966                 :     9616021 : }
    7967                 :             : 
    7968                 :             : /* Simplify SUBREG:OUTERMODE(OP:INNERMODE, BYTE)
    7969                 :             :    Return 0 if no simplifications are possible.  */
    7970                 :             : rtx
    7971                 :    66286487 : simplify_context::simplify_subreg (machine_mode outermode, rtx op,
    7972                 :             :                                    machine_mode innermode, poly_uint64 byte)
    7973                 :             : {
    7974                 :             :   /* Little bit of sanity checking.  */
    7975                 :    66286487 :   gcc_assert (innermode != VOIDmode);
    7976                 :    66286487 :   gcc_assert (outermode != VOIDmode);
    7977                 :    66286487 :   gcc_assert (innermode != BLKmode);
    7978                 :    66286487 :   gcc_assert (outermode != BLKmode);
    7979                 :             : 
    7980                 :    66286487 :   gcc_assert (GET_MODE (op) == innermode
    7981                 :             :               || GET_MODE (op) == VOIDmode);
    7982                 :             : 
    7983                 :   132572974 :   poly_uint64 outersize = GET_MODE_SIZE (outermode);
    7984                 :    66286487 :   if (!multiple_p (byte, outersize))
    7985                 :             :     return NULL_RTX;
    7986                 :             : 
    7987                 :   132572966 :   poly_uint64 innersize = GET_MODE_SIZE (innermode);
    7988                 :    66286483 :   if (maybe_ge (byte, innersize))
    7989                 :             :     return NULL_RTX;
    7990                 :             : 
    7991                 :    66286483 :   if (outermode == innermode && known_eq (byte, 0U))
    7992                 :     4302439 :     return op;
    7993                 :             : 
    7994                 :    61984044 :   if (GET_CODE (op) == CONST_VECTOR)
    7995                 :      176570 :     byte = simplify_const_vector_byte_offset (op, byte);
    7996                 :             : 
    7997                 :   123968088 :   if (multiple_p (byte, GET_MODE_UNIT_SIZE (innermode)))
    7998                 :             :     {
    7999                 :    56201375 :       rtx elt;
    8000                 :             : 
    8001                 :    48602359 :       if (VECTOR_MODE_P (outermode)
    8002                 :    15198032 :           && GET_MODE_INNER (outermode) == GET_MODE_INNER (innermode)
    8003                 :    57701991 :           && vec_duplicate_p (op, &elt))
    8004                 :        9266 :         return gen_vec_duplicate (outermode, elt);
    8005                 :             : 
    8006                 :    56199326 :       if (outermode == GET_MODE_INNER (innermode)
    8007                 :    56199326 :           && vec_duplicate_p (op, &elt))
    8008                 :        7217 :         return elt;
    8009                 :             :     }
    8010                 :             : 
    8011                 :    61974778 :   if (CONST_SCALAR_INT_P (op)
    8012                 :    52473898 :       || CONST_DOUBLE_AS_FLOAT_P (op)
    8013                 :    52449851 :       || CONST_FIXED_P (op)
    8014                 :    52449851 :       || GET_CODE (op) == CONST_VECTOR)
    8015                 :             :     {
    8016                 :     9698193 :       unsigned HOST_WIDE_INT cbyte;
    8017                 :     9698193 :       if (byte.is_constant (&cbyte))
    8018                 :             :         {
    8019                 :     9698193 :           if (GET_CODE (op) == CONST_VECTOR && VECTOR_MODE_P (outermode))
    8020                 :             :             {
    8021                 :       89593 :               rtx tmp = simplify_const_vector_subreg (outermode, op,
    8022                 :             :                                                       innermode, cbyte);
    8023                 :       89593 :               if (tmp)
    8024                 :     9698193 :                 return tmp;
    8025                 :             :             }
    8026                 :             : 
    8027                 :     9616021 :           fixed_size_mode fs_outermode;
    8028                 :     9616021 :           if (is_a <fixed_size_mode> (outermode, &fs_outermode))
    8029                 :     9616021 :             return simplify_immed_subreg (fs_outermode, op, innermode, cbyte);
    8030                 :             :         }
    8031                 :             :     }
    8032                 :             : 
    8033                 :             :   /* Changing mode twice with SUBREG => just change it once,
    8034                 :             :      or not at all if changing back op starting mode.  */
    8035                 :    52276585 :   if (GET_CODE (op) == SUBREG)
    8036                 :             :     {
    8037                 :     1261583 :       machine_mode innermostmode = GET_MODE (SUBREG_REG (op));
    8038                 :     2523166 :       poly_uint64 innermostsize = GET_MODE_SIZE (innermostmode);
    8039                 :     1261583 :       rtx newx;
    8040                 :             : 
    8041                 :             :       /* Make sure that the relationship between the two subregs is
    8042                 :             :          known at compile time.  */
    8043                 :     1261583 :       if (!ordered_p (outersize, innermostsize))
    8044                 :             :         return NULL_RTX;
    8045                 :             : 
    8046                 :     1261583 :       if (outermode == innermostmode
    8047                 :      649537 :           && known_eq (byte, subreg_lowpart_offset (outermode, innermode))
    8048                 :     1911118 :           && known_eq (SUBREG_BYTE (op),
    8049                 :             :                        subreg_lowpart_offset (innermode, innermostmode)))
    8050                 :      649535 :         return SUBREG_REG (op);
    8051                 :             : 
    8052                 :             :       /* Work out the memory offset of the final OUTERMODE value relative
    8053                 :             :          to the inner value of OP.  */
    8054                 :      612048 :       poly_int64 mem_offset = subreg_memory_offset (outermode,
    8055                 :             :                                                     innermode, byte);
    8056                 :      612048 :       poly_int64 op_mem_offset = subreg_memory_offset (op);
    8057                 :      612048 :       poly_int64 final_offset = mem_offset + op_mem_offset;
    8058                 :             : 
    8059                 :             :       /* See whether resulting subreg will be paradoxical.  */
    8060                 :      612048 :       if (!paradoxical_subreg_p (outermode, innermostmode))
    8061                 :             :         {
    8062                 :             :           /* Bail out in case resulting subreg would be incorrect.  */
    8063                 :      984894 :           if (maybe_lt (final_offset, 0)
    8064                 :      984888 :               || maybe_ge (poly_uint64 (final_offset), innermostsize)
    8065                 :      984892 :               || !multiple_p (final_offset, outersize))
    8066                 :           6 :             return NULL_RTX;
    8067                 :             :         }
    8068                 :             :       else
    8069                 :             :         {
    8070                 :      119601 :           poly_int64 required_offset = subreg_memory_offset (outermode,
    8071                 :      119601 :                                                              innermostmode, 0);
    8072                 :      119601 :           if (maybe_ne (final_offset, required_offset))
    8073                 :           0 :             return NULL_RTX;
    8074                 :             :           /* Paradoxical subregs always have byte offset 0.  */
    8075                 :      119601 :           final_offset = 0;
    8076                 :             :         }
    8077                 :             : 
    8078                 :             :       /* Recurse for further possible simplifications.  */
    8079                 :      612042 :       newx = simplify_subreg (outermode, SUBREG_REG (op), innermostmode,
    8080                 :             :                               final_offset);
    8081                 :      612042 :       if (newx)
    8082                 :             :         return newx;
    8083                 :     1223498 :       if (validate_subreg (outermode, innermostmode,
    8084                 :      611749 :                            SUBREG_REG (op), final_offset))
    8085                 :             :         {
    8086                 :      563402 :           newx = gen_rtx_SUBREG (outermode, SUBREG_REG (op), final_offset);
    8087                 :      563402 :           if (SUBREG_PROMOTED_VAR_P (op)
    8088                 :         298 :               && SUBREG_PROMOTED_SIGN (op) >= 0
    8089                 :         298 :               && GET_MODE_CLASS (outermode) == MODE_INT
    8090                 :         293 :               && known_ge (outersize, innersize)
    8091                 :         292 :               && known_le (outersize, innermostsize)
    8092                 :      563406 :               && subreg_lowpart_p (newx))
    8093                 :             :             {
    8094                 :           4 :               SUBREG_PROMOTED_VAR_P (newx) = 1;
    8095                 :           4 :               SUBREG_PROMOTED_SET (newx, SUBREG_PROMOTED_GET (op));
    8096                 :             :             }
    8097                 :      563402 :           return newx;
    8098                 :             :         }
    8099                 :             :       return NULL_RTX;
    8100                 :             :     }
    8101                 :             : 
    8102                 :             :   /* SUBREG of a hard register => just change the register number
    8103                 :             :      and/or mode.  If the hard register is not valid in that mode,
    8104                 :             :      suppress this simplification.  If the hard register is the stack,
    8105                 :             :      frame, or argument pointer, leave this as a SUBREG.  */
    8106                 :             : 
    8107                 :    51015002 :   if (REG_P (op) && HARD_REGISTER_P (op))
    8108                 :             :     {
    8109                 :    10629770 :       unsigned int regno, final_regno;
    8110                 :             : 
    8111                 :    10629770 :       regno = REGNO (op);
    8112                 :    10629770 :       final_regno = simplify_subreg_regno (regno, innermode, byte, outermode);
    8113                 :    10629770 :       if (HARD_REGISTER_NUM_P (final_regno))
    8114                 :             :         {
    8115                 :    10615142 :           rtx x = gen_rtx_REG_offset (op, outermode, final_regno,
    8116                 :             :                                       subreg_memory_offset (outermode,
    8117                 :             :                                                             innermode, byte));
    8118                 :             : 
    8119                 :             :           /* Propagate original regno.  We don't have any way to specify
    8120                 :             :              the offset inside original regno, so do so only for lowpart.
    8121                 :             :              The information is used only by alias analysis that cannot
    8122                 :             :              grog partial register anyway.  */
    8123                 :             : 
    8124                 :    10615142 :           if (known_eq (subreg_lowpart_offset (outermode, innermode), byte))
    8125                 :     7959946 :             ORIGINAL_REGNO (x) = ORIGINAL_REGNO (op);
    8126                 :    10615142 :           return x;
    8127                 :             :         }
    8128                 :             :     }
    8129                 :             : 
    8130                 :             :   /* If we have a SUBREG of a register that we are replacing and we are
    8131                 :             :      replacing it with a MEM, make a new MEM and try replacing the
    8132                 :             :      SUBREG with it.  Don't do this if the MEM has a mode-dependent address
    8133                 :             :      or if we would be widening it.  */
    8134                 :             : 
    8135                 :    40399860 :   if (MEM_P (op)
    8136                 :     1608113 :       && ! mode_dependent_address_p (XEXP (op, 0), MEM_ADDR_SPACE (op))
    8137                 :             :       /* Allow splitting of volatile memory references in case we don't
    8138                 :             :          have instruction to move the whole thing.  */
    8139                 :     1608110 :       && (! MEM_VOLATILE_P (op)
    8140                 :       44250 :           || ! have_insn_for (SET, innermode))
    8141                 :             :       && !(STRICT_ALIGNMENT && MEM_ALIGN (op) < GET_MODE_ALIGNMENT (outermode))
    8142                 :    41963720 :       && known_le (outersize, innersize))
    8143                 :      801247 :     return adjust_address_nv (op, outermode, byte);
    8144                 :             : 
    8145                 :             :   /* Handle complex or vector values represented as CONCAT or VEC_CONCAT
    8146                 :             :      of two parts.  */
    8147                 :    39598613 :   if (GET_CODE (op) == CONCAT
    8148                 :    39598613 :       || GET_CODE (op) == VEC_CONCAT)
    8149                 :             :     {
    8150                 :      187487 :       poly_uint64 final_offset;
    8151                 :      187487 :       rtx part, res;
    8152                 :             : 
    8153                 :      187487 :       machine_mode part_mode = GET_MODE (XEXP (op, 0));
    8154                 :      187487 :       if (part_mode == VOIDmode)
    8155                 :         100 :         part_mode = GET_MODE_INNER (GET_MODE (op));
    8156                 :      374974 :       poly_uint64 part_size = GET_MODE_SIZE (part_mode);
    8157                 :      187487 :       if (known_lt (byte, part_size))
    8158                 :             :         {
    8159                 :      186194 :           part = XEXP (op, 0);
    8160                 :      186194 :           final_offset = byte;
    8161                 :             :         }
    8162                 :        1293 :       else if (known_ge (byte, part_size))
    8163                 :             :         {
    8164                 :        1293 :           part = XEXP (op, 1);
    8165                 :        1293 :           final_offset = byte - part_size;
    8166                 :             :         }
    8167                 :             :       else
    8168                 :             :         return NULL_RTX;
    8169                 :             : 
    8170                 :      187487 :       if (maybe_gt (final_offset + outersize, part_size))
    8171                 :             :         return NULL_RTX;
    8172                 :             : 
    8173                 :      130200 :       part_mode = GET_MODE (part);
    8174                 :      130200 :       if (part_mode == VOIDmode)
    8175                 :           0 :         part_mode = GET_MODE_INNER (GET_MODE (op));
    8176                 :      130200 :       res = simplify_subreg (outermode, part, part_mode, final_offset);
    8177                 :      130200 :       if (res)
    8178                 :             :         return res;
    8179                 :         218 :       if (validate_subreg (outermode, part_mode, part, final_offset))
    8180                 :         212 :         return gen_rtx_SUBREG (outermode, part, final_offset);
    8181                 :             :       return NULL_RTX;
    8182                 :             :     }
    8183                 :             : 
    8184                 :             :   /* Simplify
    8185                 :             :         (subreg (vec_merge (X)
    8186                 :             :                            (vector)
    8187                 :             :                            (const_int ((1 << N) | M)))
    8188                 :             :                 (N * sizeof (outermode)))
    8189                 :             :      to
    8190                 :             :         (subreg (X) (N * sizeof (outermode)))
    8191                 :             :    */
    8192                 :    39411126 :   unsigned int idx;
    8193                 :    78822252 :   if (constant_multiple_p (byte, GET_MODE_SIZE (outermode), &idx)
    8194                 :    39411126 :       && idx < HOST_BITS_PER_WIDE_INT
    8195                 :    39411126 :       && GET_CODE (op) == VEC_MERGE
    8196                 :      297775 :       && GET_MODE_INNER (innermode) == outermode
    8197                 :        5877 :       && CONST_INT_P (XEXP (op, 2))
    8198                 :    39416530 :       && (UINTVAL (XEXP (op, 2)) & (HOST_WIDE_INT_1U << idx)) != 0)
    8199                 :        5398 :     return simplify_gen_subreg (outermode, XEXP (op, 0), innermode, byte);
    8200                 :             : 
    8201                 :             :   /* A SUBREG resulting from a zero extension may fold to zero if
    8202                 :             :      it extracts higher bits that the ZERO_EXTEND's source bits.  */
    8203                 :    39405728 :   if (GET_CODE (op) == ZERO_EXTEND && SCALAR_INT_MODE_P (innermode))
    8204                 :             :     {
    8205                 :      249708 :       poly_uint64 bitpos = subreg_lsb_1 (outermode, innermode, byte);
    8206                 :      249708 :       if (known_ge (bitpos, GET_MODE_PRECISION (GET_MODE (XEXP (op, 0)))))
    8207                 :       53368 :         return CONST0_RTX (outermode);
    8208                 :             :     }
    8209                 :             : 
    8210                 :             :   /* Optimize SUBREGS of scalar integral ASHIFT by a valid constant.  */
    8211                 :    39352360 :   if (GET_CODE (op) == ASHIFT
    8212                 :      975946 :       && SCALAR_INT_MODE_P (innermode)
    8213                 :      949141 :       && CONST_INT_P (XEXP (op, 1))
    8214                 :      883406 :       && INTVAL (XEXP (op, 1)) > 0
    8215                 :    41211696 :       && known_gt (GET_MODE_BITSIZE (innermode), INTVAL (XEXP (op, 1))))
    8216                 :             :     {
    8217                 :      883389 :       HOST_WIDE_INT val = INTVAL (XEXP (op, 1));
    8218                 :             :       /* A lowpart SUBREG of a ASHIFT by a constant may fold to zero.  */
    8219                 :      883389 :       if (known_eq (subreg_lowpart_offset (outermode, innermode), byte)
    8220                 :     1722057 :           && known_le (GET_MODE_BITSIZE (outermode), val))
    8221                 :      253060 :         return CONST0_RTX (outermode);
    8222                 :             :       /* Optimize the highpart SUBREG of a suitable ASHIFT (ZERO_EXTEND).  */
    8223                 :      673200 :       if (GET_CODE (XEXP (op, 0)) == ZERO_EXTEND
    8224                 :       43918 :           && GET_MODE (XEXP (XEXP (op, 0), 0)) == outermode
    8225                 :       43730 :           && known_eq (GET_MODE_BITSIZE (outermode), val)
    8226                 :       85742 :           && known_eq (GET_MODE_BITSIZE (innermode), 2 * val)
    8227                 :      717118 :           && known_eq (subreg_highpart_offset (outermode, innermode), byte))
    8228                 :       42871 :         return XEXP (XEXP (op, 0), 0);
    8229                 :             :     }
    8230                 :             : 
    8231                 :             :   /* Attempt to simplify WORD_MODE SUBREGs of bitwise expressions.  */
    8232                 :    39099300 :   if (outermode == word_mode
    8233                 :    13695258 :       && (GET_CODE (op) == IOR || GET_CODE (op) == XOR || GET_CODE (op) == AND)
    8234                 :    39603196 :       && SCALAR_INT_MODE_P (innermode))
    8235                 :             :     {
    8236                 :      502878 :       rtx op0 = simplify_subreg (outermode, XEXP (op, 0), innermode, byte);
    8237                 :      502878 :       rtx op1 = simplify_subreg (outermode, XEXP (op, 1), innermode, byte);
    8238                 :      502878 :       if (op0 && op1)
    8239                 :      141717 :         return simplify_gen_binary (GET_CODE (op), outermode, op0, op1);
    8240                 :             :     }
    8241                 :             : 
    8242                 :    38957583 :   scalar_int_mode int_outermode, int_innermode;
    8243                 :    38957583 :   if (is_a <scalar_int_mode> (outermode, &int_outermode)
    8244                 :    32953004 :       && is_a <scalar_int_mode> (innermode, &int_innermode)
    8245                 :    71910587 :       && known_eq (byte, subreg_lowpart_offset (int_outermode, int_innermode)))
    8246                 :             :     {
    8247                 :             :       /* Handle polynomial integers.  The upper bits of a paradoxical
    8248                 :             :          subreg are undefined, so this is safe regardless of whether
    8249                 :             :          we're truncating or extending.  */
    8250                 :    29836314 :       if (CONST_POLY_INT_P (op))
    8251                 :             :         {
    8252                 :             :           poly_wide_int val
    8253                 :             :             = poly_wide_int::from (const_poly_int_value (op),
    8254                 :             :                                    GET_MODE_PRECISION (int_outermode),
    8255                 :             :                                    SIGNED);
    8256                 :             :           return immed_wide_int_const (val, int_outermode);
    8257                 :             :         }
    8258                 :             : 
    8259                 :    29836314 :       if (GET_MODE_PRECISION (int_outermode)
    8260                 :    29836314 :           < GET_MODE_PRECISION (int_innermode))
    8261                 :             :         {
    8262                 :    18430916 :           rtx tem = simplify_truncation (int_outermode, op, int_innermode);
    8263                 :    18430916 :           if (tem)
    8264                 :             :             return tem;
    8265                 :             :         }
    8266                 :             :     }
    8267                 :             : 
    8268                 :             :   /* If the outer mode is not integral, try taking a subreg with the equivalent
    8269                 :             :      integer outer mode and then bitcasting the result.
    8270                 :             :      Other simplifications rely on integer to integer subregs and we'd
    8271                 :             :      potentially miss out on optimizations otherwise.  */
    8272                 :    75803826 :   if (known_gt (GET_MODE_SIZE (innermode),
    8273                 :             :                 GET_MODE_SIZE (outermode))
    8274                 :    20461623 :       && SCALAR_INT_MODE_P (innermode)
    8275                 :    19589355 :       && !SCALAR_INT_MODE_P (outermode)
    8276                 :    58435048 :       && int_mode_for_size (GET_MODE_BITSIZE (outermode),
    8277                 :       71512 :                             0).exists (&int_outermode))
    8278                 :             :     {
    8279                 :       71512 :       rtx tem = simplify_subreg (int_outermode, op, innermode, byte);
    8280                 :       71512 :       if (tem)
    8281                 :         972 :         return lowpart_subreg (outermode, tem, int_outermode);
    8282                 :             :     }
    8283                 :             : 
    8284                 :             :   /* If OP is a vector comparison and the subreg is not changing the
    8285                 :             :      number of elements or the size of the elements, change the result
    8286                 :             :      of the comparison to the new mode.  */
    8287                 :    37900941 :   if (COMPARISON_P (op)
    8288                 :      226065 :       && VECTOR_MODE_P (outermode)
    8289                 :      165486 :       && VECTOR_MODE_P (innermode)
    8290                 :      330956 :       && known_eq (GET_MODE_NUNITS (outermode), GET_MODE_NUNITS (innermode))
    8291                 :    38242205 :       && known_eq (GET_MODE_UNIT_SIZE (outermode),
    8292                 :             :                     GET_MODE_UNIT_SIZE (innermode)))
    8293                 :      114855 :     return simplify_gen_relational (GET_CODE (op), outermode, innermode,
    8294                 :      114855 :                                     XEXP (op, 0), XEXP (op, 1));
    8295                 :             :   return NULL_RTX;
    8296                 :             : }
    8297                 :             : 
    8298                 :             : /* Make a SUBREG operation or equivalent if it folds.  */
    8299                 :             : 
    8300                 :             : rtx
    8301                 :    41845934 : simplify_context::simplify_gen_subreg (machine_mode outermode, rtx op,
    8302                 :             :                                        machine_mode innermode,
    8303                 :             :                                        poly_uint64 byte)
    8304                 :             : {
    8305                 :    41845934 :   rtx newx;
    8306                 :             : 
    8307                 :    41845934 :   newx = simplify_subreg (outermode, op, innermode, byte);
    8308                 :    41845934 :   if (newx)
    8309                 :             :     return newx;
    8310                 :             : 
    8311                 :    19648957 :   if (GET_CODE (op) == SUBREG
    8312                 :    19648957 :       || GET_CODE (op) == CONCAT
    8313                 :    19622229 :       || GET_MODE (op) == VOIDmode)
    8314                 :             :     return NULL_RTX;
    8315                 :             : 
    8316                 :    21640445 :   if (MODE_COMPOSITE_P (outermode)
    8317                 :           0 :       && (CONST_SCALAR_INT_P (op)
    8318                 :           0 :           || CONST_DOUBLE_AS_FLOAT_P (op)
    8319                 :           0 :           || CONST_FIXED_P (op)
    8320                 :           0 :           || GET_CODE (op) == CONST_VECTOR))
    8321                 :           0 :     return NULL_RTX;
    8322                 :             : 
    8323                 :    19622211 :   if (validate_subreg (outermode, innermode, op, byte))
    8324                 :    19603267 :     return gen_rtx_SUBREG (outermode, op, byte);
    8325                 :             : 
    8326                 :             :   return NULL_RTX;
    8327                 :             : }
    8328                 :             : 
    8329                 :             : /* Generates a subreg to get the least significant part of EXPR (in mode
    8330                 :             :    INNER_MODE) to OUTER_MODE.  */
    8331                 :             : 
    8332                 :             : rtx
    8333                 :    31224300 : simplify_context::lowpart_subreg (machine_mode outer_mode, rtx expr,
    8334                 :             :                                   machine_mode inner_mode)
    8335                 :             : {
    8336                 :    31224300 :   return simplify_gen_subreg (outer_mode, expr, inner_mode,
    8337                 :    31224300 :                               subreg_lowpart_offset (outer_mode, inner_mode));
    8338                 :             : }
    8339                 :             : 
    8340                 :             : /* Generate RTX to select element at INDEX out of vector OP.  */
    8341                 :             : 
    8342                 :             : rtx
    8343                 :      534987 : simplify_context::simplify_gen_vec_select (rtx op, unsigned int index)
    8344                 :             : {
    8345                 :      534987 :   gcc_assert (VECTOR_MODE_P (GET_MODE (op)));
    8346                 :             : 
    8347                 :      534987 :   scalar_mode imode = GET_MODE_INNER (GET_MODE (op));
    8348                 :             : 
    8349                 :     1069974 :   if (known_eq (index * GET_MODE_SIZE (imode),
    8350                 :             :                 subreg_lowpart_offset (imode, GET_MODE (op))))
    8351                 :             :     {
    8352                 :      534837 :       rtx res = lowpart_subreg (imode, op, GET_MODE (op));
    8353                 :      534837 :       if (res)
    8354                 :             :         return res;
    8355                 :             :     }
    8356                 :             : 
    8357                 :         184 :   rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (index)));
    8358                 :         184 :   return gen_rtx_VEC_SELECT (imode, op, tmp);
    8359                 :             : }
    8360                 :             : 
    8361                 :             : 
    8362                 :             : /* Simplify X, an rtx expression.
    8363                 :             : 
    8364                 :             :    Return the simplified expression or NULL if no simplifications
    8365                 :             :    were possible.
    8366                 :             : 
    8367                 :             :    This is the preferred entry point into the simplification routines;
    8368                 :             :    however, we still allow passes to call the more specific routines.
    8369                 :             : 
    8370                 :             :    Right now GCC has three (yes, three) major bodies of RTL simplification
    8371                 :             :    code that need to be unified.
    8372                 :             : 
    8373                 :             :         1. fold_rtx in cse.cc.  This code uses various CSE specific
    8374                 :             :            information to aid in RTL simplification.
    8375                 :             : 
    8376                 :             :         2. simplify_rtx in combine.cc.  Similar to fold_rtx, except that
    8377                 :             :            it uses combine specific information to aid in RTL
    8378                 :             :            simplification.
    8379                 :             : 
    8380                 :             :         3. The routines in this file.
    8381                 :             : 
    8382                 :             : 
    8383                 :             :    Long term we want to only have one body of simplification code; to
    8384                 :             :    get to that state I recommend the following steps:
    8385                 :             : 
    8386                 :             :         1. Pour over fold_rtx & simplify_rtx and move any simplifications
    8387                 :             :            which are not pass dependent state into these routines.
    8388                 :             : 
    8389                 :             :         2. As code is moved by #1, change fold_rtx & simplify_rtx to
    8390                 :             :            use this routine whenever possible.
    8391                 :             : 
    8392                 :             :         3. Allow for pass dependent state to be provided to these
    8393                 :             :            routines and add simplifications based on the pass dependent
    8394                 :             :            state.  Remove code from cse.cc & combine.cc that becomes
    8395                 :             :            redundant/dead.
    8396                 :             : 
    8397                 :             :     It will take time, but ultimately the compiler will be easier to
    8398                 :             :     maintain and improve.  It's totally silly that when we add a
    8399                 :             :     simplification that it needs to be added to 4 places (3 for RTL
    8400                 :             :     simplification and 1 for tree simplification.  */
    8401                 :             : 
    8402                 :             : rtx
    8403                 :    43003581 : simplify_rtx (const_rtx x)
    8404                 :             : {
    8405                 :    43003581 :   const enum rtx_code code = GET_CODE (x);
    8406                 :    43003581 :   const machine_mode mode = GET_MODE (x);
    8407                 :             : 
    8408                 :    43003581 :   switch (GET_RTX_CLASS (code))
    8409                 :             :     {
    8410                 :      743088 :     case RTX_UNARY:
    8411                 :     1486176 :       return simplify_unary_operation (code, mode,
    8412                 :      743088 :                                        XEXP (x, 0), GET_MODE (XEXP (x, 0)));
    8413                 :    23927159 :     case RTX_COMM_ARITH:
    8414                 :    23927159 :       if (swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
    8415                 :      391676 :         return simplify_gen_binary (code, mode, XEXP (x, 1), XEXP (x, 0));
    8416                 :             : 
    8417                 :             :       /* Fall through.  */
    8418                 :             : 
    8419                 :    29324457 :     case RTX_BIN_ARITH:
    8420                 :    29324457 :       return simplify_binary_operation (code, mode, XEXP (x, 0), XEXP (x, 1));
    8421                 :             : 
    8422                 :       52895 :     case RTX_TERNARY:
    8423                 :       52895 :     case RTX_BITFIELD_OPS:
    8424                 :       52895 :       return simplify_ternary_operation (code, mode, GET_MODE (XEXP (x, 0)),
    8425                 :       52895 :                                          XEXP (x, 0), XEXP (x, 1),
    8426                 :       52895 :                                          XEXP (x, 2));
    8427                 :             : 
    8428                 :      171980 :     case RTX_COMPARE:
    8429                 :      171980 :     case RTX_COMM_COMPARE:
    8430                 :      171980 :       return simplify_relational_operation (code, mode,
    8431                 :      171980 :                                             ((GET_MODE (XEXP (x, 0))
    8432                 :             :                                              != VOIDmode)
    8433                 :             :                                             ? GET_MODE (XEXP (x, 0))
    8434                 :         350 :                                             : GET_MODE (XEXP (x, 1))),
    8435                 :      171980 :                                             XEXP (x, 0),
    8436                 :      343960 :                                             XEXP (x, 1));
    8437                 :             : 
    8438                 :      223151 :     case RTX_EXTRA:
    8439                 :      223151 :       if (code == SUBREG)
    8440                 :        1793 :         return simplify_subreg (mode, SUBREG_REG (x),
    8441                 :        1793 :                                 GET_MODE (SUBREG_REG (x)),
    8442                 :        1793 :                                 SUBREG_BYTE (x));
    8443                 :             :       break;
    8444                 :             : 
    8445                 :     6104755 :     case RTX_OBJ:
    8446                 :     6104755 :       if (code == LO_SUM)
    8447                 :             :         {
    8448                 :             :           /* Convert (lo_sum (high FOO) FOO) to FOO.  */
    8449                 :           0 :           if (GET_CODE (XEXP (x, 0)) == HIGH
    8450                 :           0 :               && rtx_equal_p (XEXP (XEXP (x, 0), 0), XEXP (x, 1)))
    8451                 :           0 :           return XEXP (x, 1);
    8452                 :             :         }
    8453                 :             :       break;
    8454                 :             : 
    8455                 :             :     default:
    8456                 :             :       break;
    8457                 :             :     }
    8458                 :             :   return NULL;
    8459                 :             : }
    8460                 :             : 
    8461                 :             : #if CHECKING_P
    8462                 :             : 
    8463                 :             : namespace selftest {
    8464                 :             : 
    8465                 :             : /* Make a unique pseudo REG of mode MODE for use by selftests.  */
    8466                 :             : 
    8467                 :             : static rtx
    8468                 :        2888 : make_test_reg (machine_mode mode)
    8469                 :             : {
    8470                 :        2888 :   static int test_reg_num = LAST_VIRTUAL_REGISTER + 1;
    8471                 :             : 
    8472                 :        2888 :   return gen_rtx_REG (mode, test_reg_num++);
    8473                 :             : }
    8474                 :             : 
    8475                 :             : static void
    8476                 :          40 : test_scalar_int_ops (machine_mode mode)
    8477                 :             : {
    8478                 :          40 :   rtx op0 = make_test_reg (mode);
    8479                 :          40 :   rtx op1 = make_test_reg (mode);
    8480                 :          40 :   rtx six = GEN_INT (6);
    8481                 :             : 
    8482                 :          40 :   rtx neg_op0 = simplify_gen_unary (NEG, mode, op0, mode);
    8483                 :          40 :   rtx not_op0 = simplify_gen_unary (NOT, mode, op0, mode);
    8484                 :          40 :   rtx bswap_op0 = simplify_gen_unary (BSWAP, mode, op0, mode);
    8485                 :             : 
    8486                 :          40 :   rtx and_op0_op1 = simplify_gen_binary (AND, mode, op0, op1);
    8487                 :          40 :   rtx ior_op0_op1 = simplify_gen_binary (IOR, mode, op0, op1);
    8488                 :          40 :   rtx xor_op0_op1 = simplify_gen_binary (XOR, mode, op0, op1);
    8489                 :             : 
    8490                 :          40 :   rtx and_op0_6 = simplify_gen_binary (AND, mode, op0, six);
    8491                 :          40 :   rtx and_op1_6 = simplify_gen_binary (AND, mode, op1, six);
    8492                 :             : 
    8493                 :             :   /* Test some binary identities.  */
    8494                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (PLUS, mode, op0, const0_rtx));
    8495                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (PLUS, mode, const0_rtx, op0));
    8496                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (MINUS, mode, op0, const0_rtx));
    8497                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (MULT, mode, op0, const1_rtx));
    8498                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (MULT, mode, const1_rtx, op0));
    8499                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (DIV, mode, op0, const1_rtx));
    8500                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (AND, mode, op0, constm1_rtx));
    8501                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (AND, mode, constm1_rtx, op0));
    8502                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (IOR, mode, op0, const0_rtx));
    8503                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (IOR, mode, const0_rtx, op0));
    8504                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (XOR, mode, op0, const0_rtx));
    8505                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (XOR, mode, const0_rtx, op0));
    8506                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (ASHIFT, mode, op0, const0_rtx));
    8507                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (ROTATE, mode, op0, const0_rtx));
    8508                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (ASHIFTRT, mode, op0, const0_rtx));
    8509                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (LSHIFTRT, mode, op0, const0_rtx));
    8510                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (ROTATERT, mode, op0, const0_rtx));
    8511                 :             : 
    8512                 :             :   /* Test some self-inverse operations.  */
    8513                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_unary (NEG, mode, neg_op0, mode));
    8514                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_unary (NOT, mode, not_op0, mode));
    8515                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_unary (BSWAP, mode, bswap_op0, mode));
    8516                 :             : 
    8517                 :             :   /* Test some reflexive operations.  */
    8518                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (AND, mode, op0, op0));
    8519                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (IOR, mode, op0, op0));
    8520                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (SMIN, mode, op0, op0));
    8521                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (SMAX, mode, op0, op0));
    8522                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (UMIN, mode, op0, op0));
    8523                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_binary (UMAX, mode, op0, op0));
    8524                 :             : 
    8525                 :          40 :   ASSERT_RTX_EQ (const0_rtx, simplify_gen_binary (MINUS, mode, op0, op0));
    8526                 :          40 :   ASSERT_RTX_EQ (const0_rtx, simplify_gen_binary (XOR, mode, op0, op0));
    8527                 :             : 
    8528                 :             :   /* Test simplify_distributive_operation.  */
    8529                 :          40 :   ASSERT_RTX_EQ (simplify_gen_binary (AND, mode, xor_op0_op1, six),
    8530                 :             :                  simplify_gen_binary (XOR, mode, and_op0_6, and_op1_6));
    8531                 :          40 :   ASSERT_RTX_EQ (simplify_gen_binary (AND, mode, ior_op0_op1, six),
    8532                 :             :                  simplify_gen_binary (IOR, mode, and_op0_6, and_op1_6));
    8533                 :          40 :   ASSERT_RTX_EQ (simplify_gen_binary (AND, mode, and_op0_op1, six),
    8534                 :             :                  simplify_gen_binary (AND, mode, and_op0_6, and_op1_6));
    8535                 :             : 
    8536                 :             :   /* Test useless extensions are eliminated.  */
    8537                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_unary (TRUNCATE, mode, op0, mode));
    8538                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_unary (ZERO_EXTEND, mode, op0, mode));
    8539                 :          40 :   ASSERT_RTX_EQ (op0, simplify_gen_unary (SIGN_EXTEND, mode, op0, mode));
    8540                 :          40 :   ASSERT_RTX_EQ (op0, lowpart_subreg (mode, op0, mode));
    8541                 :          40 : }
    8542                 :             : 
    8543                 :             : /* Verify some simplifications of integer extension/truncation.
    8544                 :             :    Machine mode BMODE is the guaranteed wider than SMODE.  */
    8545                 :             : 
    8546                 :             : static void
    8547                 :          24 : test_scalar_int_ext_ops (machine_mode bmode, machine_mode smode)
    8548                 :             : {
    8549                 :          24 :   rtx sreg = make_test_reg (smode);
    8550                 :             : 
    8551                 :             :   /* Check truncation of extension.  */
    8552                 :          24 :   ASSERT_RTX_EQ (simplify_gen_unary (TRUNCATE, smode,
    8553                 :             :                                      simplify_gen_unary (ZERO_EXTEND, bmode,
    8554                 :             :                                                          sreg, smode),
    8555                 :             :                                      bmode),
    8556                 :             :                  sreg);
    8557                 :          24 :   ASSERT_RTX_EQ (simplify_gen_unary (TRUNCATE, smode,
    8558                 :             :                                      simplify_gen_unary (SIGN_EXTEND, bmode,
    8559                 :             :                                                          sreg, smode),
    8560                 :             :                                      bmode),
    8561                 :             :                  sreg);
    8562                 :          24 :   ASSERT_RTX_EQ (simplify_gen_unary (TRUNCATE, smode,
    8563                 :             :                                      lowpart_subreg (bmode, sreg, smode),
    8564                 :             :                                      bmode),
    8565                 :             :                  sreg);
    8566                 :          24 : }
    8567                 :             : 
    8568                 :             : /* Verify more simplifications of integer extension/truncation.
    8569                 :             :    BMODE is wider than MMODE which is wider than SMODE.  */
    8570                 :             : 
    8571                 :             : static void
    8572                 :          16 : test_scalar_int_ext_ops2 (machine_mode bmode, machine_mode mmode,
    8573                 :             :                           machine_mode smode)
    8574                 :             : {
    8575                 :          16 :   rtx breg = make_test_reg (bmode);
    8576                 :          16 :   rtx mreg = make_test_reg (mmode);
    8577                 :          16 :   rtx sreg = make_test_reg (smode);
    8578                 :             : 
    8579                 :             :   /* Check truncate of truncate.  */
    8580                 :          16 :   ASSERT_RTX_EQ (simplify_gen_unary (TRUNCATE, smode,
    8581                 :             :                                      simplify_gen_unary (TRUNCATE, mmode,
    8582                 :             :                                                          breg, bmode),
    8583                 :             :                                      mmode),
    8584                 :             :                  simplify_gen_unary (TRUNCATE, smode, breg, bmode));
    8585                 :             : 
    8586                 :             :   /* Check extension of extension.  */
    8587                 :          16 :   ASSERT_RTX_EQ (simplify_gen_unary (ZERO_EXTEND, bmode,
    8588                 :             :                                      simplify_gen_unary (ZERO_EXTEND, mmode,
    8589                 :             :                                                          sreg, smode),
    8590                 :             :                                      mmode),
    8591                 :             :                  simplify_gen_unary (ZERO_EXTEND, bmode, sreg, smode));
    8592                 :          16 :   ASSERT_RTX_EQ (simplify_gen_unary (SIGN_EXTEND, bmode,
    8593                 :             :                                      simplify_gen_unary (SIGN_EXTEND, mmode,
    8594                 :             :                                                          sreg, smode),
    8595                 :             :                                      mmode),
    8596                 :             :                  simplify_gen_unary (SIGN_EXTEND, bmode, sreg, smode));
    8597                 :          16 :   ASSERT_RTX_EQ (simplify_gen_unary (SIGN_EXTEND, bmode,
    8598                 :             :                                      simplify_gen_unary (ZERO_EXTEND, mmode,
    8599                 :             :                                                          sreg, smode),
    8600                 :             :                                      mmode),
    8601                 :             :                  simplify_gen_unary (ZERO_EXTEND, bmode, sreg, smode));
    8602                 :             : 
    8603                 :             :   /* Check truncation of extension.  */
    8604                 :          16 :   ASSERT_RTX_EQ (simplify_gen_unary (TRUNCATE, smode,
    8605                 :             :                                      simplify_gen_unary (ZERO_EXTEND, bmode,
    8606                 :             :                                                          mreg, mmode),
    8607                 :             :                                      bmode),
    8608                 :             :                  simplify_gen_unary (TRUNCATE, smode, mreg, mmode));
    8609                 :          16 :   ASSERT_RTX_EQ (simplify_gen_unary (TRUNCATE, smode,
    8610                 :             :                                      simplify_gen_unary (SIGN_EXTEND, bmode,
    8611                 :             :                                                          mreg, mmode),
    8612                 :             :                                      bmode),
    8613                 :             :                  simplify_gen_unary (TRUNCATE, smode, mreg, mmode));
    8614                 :          16 :   ASSERT_RTX_EQ (simplify_gen_unary (TRUNCATE, smode,
    8615                 :             :                                      lowpart_subreg (bmode, mreg, mmode),
    8616                 :             :                                      bmode),
    8617                 :             :                  simplify_gen_unary (TRUNCATE, smode, mreg, mmode));
    8618                 :          16 : }
    8619                 :             : 
    8620                 :             : /* Test comparisons of comparisons, with the inner comparisons being
    8621                 :             :    between values of mode MODE2 and producing results of mode MODE1,
    8622                 :             :    and with the outer comparisons producing results of mode MODE0.  */
    8623                 :             : 
    8624                 :             : static void
    8625                 :           4 : test_comparisons (machine_mode mode0, machine_mode mode1, machine_mode mode2)
    8626                 :             : {
    8627                 :           4 :   rtx reg0 = make_test_reg (mode2);
    8628                 :           4 :   rtx reg1 = make_test_reg (mode2);
    8629                 :             : 
    8630                 :           4 :   static const rtx_code codes[] = {
    8631                 :             :     EQ, NE, LT, LTU, LE, LEU, GE, GEU, GT, GTU
    8632                 :             :   };
    8633                 :           4 :   constexpr auto num_codes = ARRAY_SIZE (codes);
    8634                 :           4 :   rtx cmps[num_codes];
    8635                 :           4 :   rtx vals[] = { constm1_rtx, const0_rtx, const1_rtx };
    8636                 :             : 
    8637                 :          44 :   for (unsigned int i = 0; i < num_codes; ++i)
    8638                 :          40 :     cmps[i] = gen_rtx_fmt_ee (codes[i], mode1, reg0, reg1);
    8639                 :             : 
    8640                 :          44 :   for (auto code : codes)
    8641                 :         440 :     for (unsigned int i0 = 0; i0 < num_codes; ++i0)
    8642                 :        4400 :       for (unsigned int i1 = 0; i1 < num_codes; ++i1)
    8643                 :             :         {
    8644                 :        4000 :           rtx cmp_res = simplify_relational_operation (code, mode0, mode1,
    8645                 :             :                                                        cmps[i0], cmps[i1]);
    8646                 :        4000 :           if (i0 >= 2 && i1 >= 2 && (i0 ^ i1) & 1)
    8647                 :        1280 :             ASSERT_TRUE (cmp_res == NULL_RTX);
    8648                 :             :           else
    8649                 :             :             {
    8650                 :        2720 :               ASSERT_TRUE (cmp_res != NULL_RTX
    8651                 :             :                            && (CONSTANT_P (cmp_res)
    8652                 :             :                                || (COMPARISON_P (cmp_res)
    8653                 :             :                                    && GET_MODE (cmp_res) == mode0
    8654                 :             :                                    && REG_P (XEXP (cmp_res, 0))
    8655                 :             :                                    && REG_P (XEXP (cmp_res, 1)))));
    8656                 :       10880 :               for (rtx reg0_val : vals)
    8657                 :       32640 :                 for (rtx reg1_val : vals)
    8658                 :             :                   {
    8659                 :       24480 :                     rtx val0 = simplify_const_relational_operation
    8660                 :       24480 :                       (codes[i0], mode1, reg0_val, reg1_val);
    8661                 :       24480 :                     rtx val1 = simplify_const_relational_operation
    8662                 :       24480 :                       (codes[i1], mode1, reg0_val, reg1_val);
    8663                 :       24480 :                     rtx val = simplify_const_relational_operation
    8664                 :       24480 :                       (code, mode0, val0, val1);
    8665                 :       24480 :                     rtx folded = cmp_res;
    8666                 :       24480 :                     if (COMPARISON_P (cmp_res))
    8667                 :       16704 :                       folded = simplify_const_relational_operation
    8668                 :       16704 :                         (GET_CODE (cmp_res), mode0,
    8669                 :       16704 :                          XEXP (cmp_res, 0) == reg0 ? reg0_val : reg1_val,
    8670                 :       16704 :                          XEXP (cmp_res, 1) == reg0 ? reg0_val : reg1_val);
    8671                 :       24480 :                     ASSERT_RTX_EQ (val, folded);
    8672                 :             :                   }
    8673                 :             :             }
    8674                 :             :         }
    8675                 :           4 : }
    8676                 :             : 
    8677                 :             : 
    8678                 :             : /* Verify some simplifications involving scalar expressions.  */
    8679                 :             : 
    8680                 :             : static void
    8681                 :           4 : test_scalar_ops ()
    8682                 :             : {
    8683                 :         524 :   for (unsigned int i = 0; i < NUM_MACHINE_MODES; ++i)
    8684                 :             :     {
    8685                 :         520 :       machine_mode mode = (machine_mode) i;
    8686                 :         520 :       if (SCALAR_INT_MODE_P (mode) && mode != BImode)
    8687                 :          40 :         test_scalar_int_ops (mode);
    8688                 :             :     }
    8689                 :             : 
    8690                 :           4 :   test_scalar_int_ext_ops (HImode, QImode);
    8691                 :           4 :   test_scalar_int_ext_ops (SImode, QImode);
    8692                 :           4 :   test_scalar_int_ext_ops (SImode, HImode);
    8693                 :           4 :   test_scalar_int_ext_ops (DImode, QImode);
    8694                 :           4 :   test_scalar_int_ext_ops (DImode, HImode);
    8695                 :           4 :   test_scalar_int_ext_ops (DImode, SImode);
    8696                 :             : 
    8697                 :           4 :   test_scalar_int_ext_ops2 (SImode, HImode, QImode);
    8698                 :           4 :   test_scalar_int_ext_ops2 (DImode, HImode, QImode);
    8699                 :           4 :   test_scalar_int_ext_ops2 (DImode, SImode, QImode);
    8700                 :           4 :   test_scalar_int_ext_ops2 (DImode, SImode, HImode);
    8701                 :             : 
    8702                 :           4 :   test_comparisons (QImode, HImode, SImode);
    8703                 :           4 : }
    8704                 :             : 
    8705                 :             : /* Test vector simplifications involving VEC_DUPLICATE in which the
    8706                 :             :    operands and result have vector mode MODE.  SCALAR_REG is a pseudo
    8707                 :             :    register that holds one element of MODE.  */
    8708                 :             : 
    8709                 :             : static void
    8710                 :         248 : test_vector_ops_duplicate (machine_mode mode, rtx scalar_reg)
    8711                 :             : {
    8712                 :         248 :   scalar_mode inner_mode = GET_MODE_INNER (mode);
    8713                 :         248 :   rtx duplicate = gen_rtx_VEC_DUPLICATE (mode, scalar_reg);
    8714                 :         496 :   poly_uint64 nunits = GET_MODE_NUNITS (mode);
    8715                 :         248 :   if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
    8716                 :             :     {
    8717                 :             :       /* Test some simple unary cases with VEC_DUPLICATE arguments.  */
    8718                 :         128 :       rtx not_scalar_reg = gen_rtx_NOT (inner_mode, scalar_reg);
    8719                 :         128 :       rtx duplicate_not = gen_rtx_VEC_DUPLICATE (mode, not_scalar_reg);
    8720                 :         128 :       ASSERT_RTX_EQ (duplicate,
    8721                 :             :                      simplify_unary_operation (NOT, mode,
    8722                 :             :                                                duplicate_not, mode));
    8723                 :             : 
    8724                 :         128 :       rtx neg_scalar_reg = gen_rtx_NEG (inner_mode, scalar_reg);
    8725                 :         128 :       rtx duplicate_neg = gen_rtx_VEC_DUPLICATE (mode, neg_scalar_reg);
    8726                 :         128 :       ASSERT_RTX_EQ (duplicate,
    8727                 :             :                      simplify_unary_operation (NEG, mode,
    8728                 :             :                                                duplicate_neg, mode));
    8729                 :             : 
    8730                 :             :       /* Test some simple binary cases with VEC_DUPLICATE arguments.  */
    8731                 :         128 :       ASSERT_RTX_EQ (duplicate,
    8732                 :             :                      simplify_binary_operation (PLUS, mode, duplicate,
    8733                 :             :                                                 CONST0_RTX (mode)));
    8734                 :             : 
    8735                 :         128 :       ASSERT_RTX_EQ (duplicate,
    8736                 :             :                      simplify_binary_operation (MINUS, mode, duplicate,
    8737                 :             :                                                 CONST0_RTX (mode)));
    8738                 :             : 
    8739                 :         128 :       ASSERT_RTX_PTR_EQ (CONST0_RTX (mode),
    8740                 :             :                          simplify_binary_operation (MINUS, mode, duplicate,
    8741                 :             :                                                     duplicate));
    8742                 :             :     }
    8743                 :             : 
    8744                 :             :   /* Test a scalar VEC_SELECT of a VEC_DUPLICATE.  */
    8745                 :         248 :   rtx zero_par = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
    8746                 :         248 :   ASSERT_RTX_PTR_EQ (scalar_reg,
    8747                 :             :                      simplify_binary_operation (VEC_SELECT, inner_mode,
    8748                 :             :                                                 duplicate, zero_par));
    8749                 :             : 
    8750                 :         248 :   unsigned HOST_WIDE_INT const_nunits;
    8751                 :         248 :   if (nunits.is_constant (&const_nunits))
    8752                 :             :     {
    8753                 :             :       /* And again with the final element.  */
    8754                 :         248 :       rtx last_index = gen_int_mode (const_nunits - 1, word_mode);
    8755                 :         248 :       rtx last_par = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, last_index));
    8756                 :         248 :       ASSERT_RTX_PTR_EQ (scalar_reg,
    8757                 :             :                          simplify_binary_operation (VEC_SELECT, inner_mode,
    8758                 :             :                                                     duplicate, last_par));
    8759                 :             : 
    8760                 :             :       /* Test a scalar subreg of a VEC_MERGE of a VEC_DUPLICATE.  */
    8761                 :             :       /* Skip this test for vectors of booleans, because offset is in bytes,
    8762                 :             :          while vec_merge indices are in elements (usually bits).  */
    8763                 :         248 :       if (GET_MODE_CLASS (mode) != MODE_VECTOR_BOOL)
    8764                 :             :         {
    8765                 :         248 :           rtx vector_reg = make_test_reg (mode);
    8766                 :        4748 :           for (unsigned HOST_WIDE_INT i = 0; i < const_nunits; i++)
    8767                 :             :             {
    8768                 :        4512 :               if (i >= HOST_BITS_PER_WIDE_INT)
    8769                 :             :                 break;
    8770                 :        4500 :               rtx mask = GEN_INT ((HOST_WIDE_INT_1U << i) | (i + 1));
    8771                 :        4500 :               rtx vm = gen_rtx_VEC_MERGE (mode, duplicate, vector_reg, mask);
    8772                 :        9000 :               poly_uint64 offset = i * GET_MODE_SIZE (inner_mode);
    8773                 :             : 
    8774                 :        4500 :               ASSERT_RTX_EQ (scalar_reg,
    8775                 :             :                              simplify_gen_subreg (inner_mode, vm,
    8776                 :             :                                                   mode, offset));
    8777                 :             :             }
    8778                 :             :         }
    8779                 :             :     }
    8780                 :             : 
    8781                 :             :   /* Test a scalar subreg of a VEC_DUPLICATE.  */
    8782                 :         248 :   poly_uint64 offset = subreg_lowpart_offset (inner_mode, mode);
    8783                 :         248 :   ASSERT_RTX_EQ (scalar_reg,
    8784                 :             :                  simplify_gen_subreg (inner_mode, duplicate,
    8785                 :             :                                       mode, offset));
    8786                 :             : 
    8787                 :         248 :   machine_mode narrower_mode;
    8788                 :         248 :   if (maybe_ne (nunits, 2U)
    8789                 :         208 :       && multiple_p (nunits, 2)
    8790                 :         444 :       && mode_for_vector (inner_mode, 2).exists (&narrower_mode)
    8791                 :         444 :       && VECTOR_MODE_P (narrower_mode))
    8792                 :             :     {
    8793                 :             :       /* Test VEC_DUPLICATE of a vector.  */
    8794                 :         196 :       rtx_vector_builder nbuilder (narrower_mode, 2, 1);
    8795                 :         196 :       nbuilder.quick_push (const0_rtx);
    8796                 :         196 :       nbuilder.quick_push (const1_rtx);
    8797                 :         196 :       rtx_vector_builder builder (mode, 2, 1);
    8798                 :         196 :       builder.quick_push (const0_rtx);
    8799                 :         196 :       builder.quick_push (const1_rtx);
    8800                 :         196 :       ASSERT_RTX_EQ (builder.build (),
    8801                 :             :                      simplify_unary_operation (VEC_DUPLICATE, mode,
    8802                 :             :                                                nbuilder.build (),
    8803                 :             :                                                narrower_mode));
    8804                 :             : 
    8805                 :             :       /* Test VEC_SELECT of a vector.  */
    8806                 :         196 :       rtx vec_par
    8807                 :         196 :         = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, const1_rtx, const0_rtx));
    8808                 :         196 :       rtx narrower_duplicate
    8809                 :         196 :         = gen_rtx_VEC_DUPLICATE (narrower_mode, scalar_reg);
    8810                 :         196 :       ASSERT_RTX_EQ (narrower_duplicate,
    8811                 :             :                      simplify_binary_operation (VEC_SELECT, narrower_mode,
    8812                 :             :                                                 duplicate, vec_par));
    8813                 :             : 
    8814                 :             :       /* Test a vector subreg of a VEC_DUPLICATE.  */
    8815                 :         196 :       poly_uint64 offset = subreg_lowpart_offset (narrower_mode, mode);
    8816                 :         196 :       ASSERT_RTX_EQ (narrower_duplicate,
    8817                 :             :                      simplify_gen_subreg (narrower_mode, duplicate,
    8818                 :             :                                           mode, offset));
    8819                 :         196 :     }
    8820                 :         248 : }
    8821                 :             : 
    8822                 :             : /* Test vector simplifications involving VEC_SERIES in which the
    8823                 :             :    operands and result have vector mode MODE.  SCALAR_REG is a pseudo
    8824                 :             :    register that holds one element of MODE.  */
    8825                 :             : 
    8826                 :             : static void
    8827                 :          96 : test_vector_ops_series (machine_mode mode, rtx scalar_reg)
    8828                 :             : {
    8829                 :             :   /* Test unary cases with VEC_SERIES arguments.  */
    8830                 :          96 :   scalar_mode inner_mode = GET_MODE_INNER (mode);
    8831                 :          96 :   rtx duplicate = gen_rtx_VEC_DUPLICATE (mode, scalar_reg);
    8832                 :          96 :   rtx neg_scalar_reg = gen_rtx_NEG (inner_mode, scalar_reg);
    8833                 :          96 :   rtx series_0_r = gen_rtx_VEC_SERIES (mode, const0_rtx, scalar_reg);
    8834                 :          96 :   rtx series_0_nr = gen_rtx_VEC_SERIES (mode, const0_rtx, neg_scalar_reg);
    8835                 :          96 :   rtx series_nr_1 = gen_rtx_VEC_SERIES (mode, neg_scalar_reg, const1_rtx);
    8836                 :          96 :   rtx series_r_m1 = gen_rtx_VEC_SERIES (mode, scalar_reg, constm1_rtx);
    8837                 :          96 :   rtx series_r_r = gen_rtx_VEC_SERIES (mode, scalar_reg, scalar_reg);
    8838                 :          96 :   rtx series_nr_nr = gen_rtx_VEC_SERIES (mode, neg_scalar_reg,
    8839                 :             :                                          neg_scalar_reg);
    8840                 :          96 :   ASSERT_RTX_EQ (series_0_r,
    8841                 :             :                  simplify_unary_operation (NEG, mode, series_0_nr, mode));
    8842                 :          96 :   ASSERT_RTX_EQ (series_r_m1,
    8843                 :             :                  simplify_unary_operation (NEG, mode, series_nr_1, mode));
    8844                 :          96 :   ASSERT_RTX_EQ (series_r_r,
    8845                 :             :                  simplify_unary_operation (NEG, mode, series_nr_nr, mode));
    8846                 :             : 
    8847                 :             :   /* Test that a VEC_SERIES with a zero step is simplified away.  */
    8848                 :          96 :   ASSERT_RTX_EQ (duplicate,
    8849                 :             :                  simplify_binary_operation (VEC_SERIES, mode,
    8850                 :             :                                             scalar_reg, const0_rtx));
    8851                 :             : 
    8852                 :             :   /* Test PLUS and MINUS with VEC_SERIES.  */
    8853                 :          96 :   rtx series_0_1 = gen_const_vec_series (mode, const0_rtx, const1_rtx);
    8854                 :          96 :   rtx series_0_m1 = gen_const_vec_series (mode, const0_rtx, constm1_rtx);
    8855                 :          96 :   rtx series_r_1 = gen_rtx_VEC_SERIES (mode, scalar_reg, const1_rtx);
    8856                 :          96 :   ASSERT_RTX_EQ (series_r_r,
    8857                 :             :                  simplify_binary_operation (PLUS, mode, series_0_r,
    8858                 :             :                                             duplicate));
    8859                 :          96 :   ASSERT_RTX_EQ (series_r_1,
    8860                 :             :                  simplify_binary_operation (PLUS, mode, duplicate,
    8861                 :             :                                             series_0_1));
    8862                 :          96 :   ASSERT_RTX_EQ (series_r_m1,
    8863                 :             :                  simplify_binary_operation (PLUS, mode, duplicate,
    8864                 :             :                                             series_0_m1));
    8865                 :          96 :   ASSERT_RTX_EQ (series_0_r,
    8866                 :             :                  simplify_binary_operation (MINUS, mode, series_r_r,
    8867                 :             :                                             duplicate));
    8868                 :          96 :   ASSERT_RTX_EQ (series_r_m1,
    8869                 :             :                  simplify_binary_operation (MINUS, mode, duplicate,
    8870                 :             :                                             series_0_1));
    8871                 :          96 :   ASSERT_RTX_EQ (series_r_1,
    8872                 :             :                  simplify_binary_operation (MINUS, mode, duplicate,
    8873                 :             :                                             series_0_m1));
    8874                 :          96 :   ASSERT_RTX_EQ (series_0_m1,
    8875                 :             :                  simplify_binary_operation (VEC_SERIES, mode, const0_rtx,
    8876                 :             :                                             constm1_rtx));
    8877                 :             : 
    8878                 :             :   /* Test NEG on constant vector series.  */
    8879                 :          96 :   ASSERT_RTX_EQ (series_0_m1,
    8880                 :             :                  simplify_unary_operation (NEG, mode, series_0_1, mode));
    8881                 :          96 :   ASSERT_RTX_EQ (series_0_1,
    8882                 :             :                  simplify_unary_operation (NEG, mode, series_0_m1, mode));
    8883                 :             : 
    8884                 :             :   /* Test PLUS and MINUS on constant vector series.  */
    8885                 :          96 :   rtx scalar2 = gen_int_mode (2, inner_mode);
    8886                 :          96 :   rtx scalar3 = gen_int_mode (3, inner_mode);
    8887                 :          96 :   rtx series_1_1 = gen_const_vec_series (mode, const1_rtx, const1_rtx);
    8888                 :          96 :   rtx series_0_2 = gen_const_vec_series (mode, const0_rtx, scalar2);
    8889                 :          96 :   rtx series_1_3 = gen_const_vec_series (mode, const1_rtx, scalar3);
    8890                 :          96 :   ASSERT_RTX_EQ (series_1_1,
    8891                 :             :                  simplify_binary_operation (PLUS, mode, series_0_1,
    8892                 :             :                                             CONST1_RTX (mode)));
    8893                 :          96 :   ASSERT_RTX_EQ (series_0_m1,
    8894                 :             :                  simplify_binary_operation (PLUS, mode, CONST0_RTX (mode),
    8895                 :             :                                             series_0_m1));
    8896                 :          96 :   ASSERT_RTX_EQ (series_1_3,
    8897                 :             :                  simplify_binary_operation (PLUS, mode, series_1_1,
    8898                 :             :                                             series_0_2));
    8899                 :          96 :   ASSERT_RTX_EQ (series_0_1,
    8900                 :             :                  simplify_binary_operation (MINUS, mode, series_1_1,
    8901                 :             :                                             CONST1_RTX (mode)));
    8902                 :          96 :   ASSERT_RTX_EQ (series_1_1,
    8903                 :             :                  simplify_binary_operation (MINUS, mode, CONST1_RTX (mode),
    8904                 :             :                                             series_0_m1));
    8905                 :          96 :   ASSERT_RTX_EQ (series_1_1,
    8906                 :             :                  simplify_binary_operation (MINUS, mode, series_1_3,
    8907                 :             :                                             series_0_2));
    8908                 :             : 
    8909                 :             :   /* Test MULT between constant vectors.  */
    8910                 :          96 :   rtx vec2 = gen_const_vec_duplicate (mode, scalar2);
    8911                 :          96 :   rtx vec3 = gen_const_vec_duplicate (mode, scalar3);
    8912                 :          96 :   rtx scalar9 = gen_int_mode (9, inner_mode);
    8913                 :          96 :   rtx series_3_9 = gen_const_vec_series (mode, scalar3, scalar9);
    8914                 :          96 :   ASSERT_RTX_EQ (series_0_2,
    8915                 :             :                  simplify_binary_operation (MULT, mode, series_0_1, vec2));
    8916                 :          96 :   ASSERT_RTX_EQ (series_3_9,
    8917                 :             :                  simplify_binary_operation (MULT, mode, vec3, series_1_3));
    8918                 :          96 :   if (!GET_MODE_NUNITS (mode).is_constant ())
    8919                 :             :     ASSERT_FALSE (simplify_binary_operation (MULT, mode, series_0_1,
    8920                 :             :                                              series_0_1));
    8921                 :             : 
    8922                 :             :   /* Test ASHIFT between constant vectors.  */
    8923                 :          96 :   ASSERT_RTX_EQ (series_0_2,
    8924                 :             :                  simplify_binary_operation (ASHIFT, mode, series_0_1,
    8925                 :             :                                             CONST1_RTX (mode)));
    8926                 :          96 :   if (!GET_MODE_NUNITS (mode).is_constant ())
    8927                 :             :     ASSERT_FALSE (simplify_binary_operation (ASHIFT, mode, CONST1_RTX (mode),
    8928                 :             :                                              series_0_1));
    8929                 :          96 : }
    8930                 :             : 
    8931                 :             : static rtx
    8932                 :        3472 : simplify_merge_mask (rtx x, rtx mask, int op)
    8933                 :             : {
    8934                 :           0 :   return simplify_context ().simplify_merge_mask (x, mask, op);
    8935                 :             : }
    8936                 :             : 
    8937                 :             : /* Verify simplify_merge_mask works correctly.  */
    8938                 :             : 
    8939                 :             : static void
    8940                 :         248 : test_vec_merge (machine_mode mode)
    8941                 :             : {
    8942                 :         248 :   rtx op0 = make_test_reg (mode);
    8943                 :         248 :   rtx op1 = make_test_reg (mode);
    8944                 :         248 :   rtx op2 = make_test_reg (mode);
    8945                 :         248 :   rtx op3 = make_test_reg (mode);
    8946                 :         248 :   rtx op4 = make_test_reg (mode);
    8947                 :         248 :   rtx op5 = make_test_reg (mode);
    8948                 :         248 :   rtx mask1 = make_test_reg (SImode);
    8949                 :         248 :   rtx mask2 = make_test_reg (SImode);
    8950                 :         248 :   rtx vm1 = gen_rtx_VEC_MERGE (mode, op0, op1, mask1);
    8951                 :         248 :   rtx vm2 = gen_rtx_VEC_MERGE (mode, op2, op3, mask1);
    8952                 :         248 :   rtx vm3 = gen_rtx_VEC_MERGE (mode, op4, op5, mask1);
    8953                 :             : 
    8954                 :             :   /* Simple vec_merge.  */
    8955                 :         248 :   ASSERT_EQ (op0, simplify_merge_mask (vm1, mask1, 0));
    8956                 :         248 :   ASSERT_EQ (op1, simplify_merge_mask (vm1, mask1, 1));
    8957                 :         248 :   ASSERT_EQ (NULL_RTX, simplify_merge_mask (vm1, mask2, 0));
    8958                 :         248 :   ASSERT_EQ (NULL_RTX, simplify_merge_mask (vm1, mask2, 1));
    8959                 :             : 
    8960                 :             :   /* Nested vec_merge.
    8961                 :             :      It's tempting to make this simplify right down to opN, but we don't
    8962                 :             :      because all the simplify_* functions assume that the operands have
    8963                 :             :      already been simplified.  */
    8964                 :         248 :   rtx nvm = gen_rtx_VEC_MERGE (mode, vm1, vm2, mask1);
    8965                 :         248 :   ASSERT_EQ (vm1, simplify_merge_mask (nvm, mask1, 0));
    8966                 :         248 :   ASSERT_EQ (vm2, simplify_merge_mask (nvm, mask1, 1));
    8967                 :             : 
    8968                 :             :   /* Intermediate unary op. */
    8969                 :         248 :   rtx unop = gen_rtx_NOT (mode, vm1);
    8970                 :         248 :   ASSERT_RTX_EQ (gen_rtx_NOT (mode, op0),
    8971                 :             :                  simplify_merge_mask (unop, mask1, 0));
    8972                 :         248 :   ASSERT_RTX_EQ (gen_rtx_NOT (mode, op1),
    8973                 :             :                  simplify_merge_mask (unop, mask1, 1));
    8974                 :             : 
    8975                 :             :   /* Intermediate binary op. */
    8976                 :         248 :   rtx binop = gen_rtx_PLUS (mode, vm1, vm2);
    8977                 :         248 :   ASSERT_RTX_EQ (gen_rtx_PLUS (mode, op0, op2),
    8978                 :             :                  simplify_merge_mask (binop, mask1, 0));
    8979                 :         248 :   ASSERT_RTX_EQ (gen_rtx_PLUS (mode, op1, op3),
    8980                 :             :                  simplify_merge_mask (binop, mask1, 1));
    8981                 :             : 
    8982                 :             :   /* Intermediate ternary op. */
    8983                 :         248 :   rtx tenop = gen_rtx_FMA (mode, vm1, vm2, vm3);
    8984                 :         248 :   ASSERT_RTX_EQ (gen_rtx_FMA (mode, op0, op2, op4),
    8985                 :             :                  simplify_merge_mask (tenop, mask1, 0));
    8986                 :         248 :   ASSERT_RTX_EQ (gen_rtx_FMA (mode, op1, op3, op5),
    8987                 :             :                  simplify_merge_mask (tenop, mask1, 1));
    8988                 :             : 
    8989                 :             :   /* Side effects.  */
    8990                 :         248 :   rtx badop0 = gen_rtx_PRE_INC (mode, op0);
    8991                 :         248 :   rtx badvm = gen_rtx_VEC_MERGE (mode, badop0, op1, mask1);
    8992                 :         248 :   ASSERT_EQ (badop0, simplify_merge_mask (badvm, mask1, 0));
    8993                 :         248 :   ASSERT_EQ (NULL_RTX, simplify_merge_mask (badvm, mask1, 1));
    8994                 :             : 
    8995                 :             :   /* Called indirectly.  */
    8996                 :         248 :   ASSERT_RTX_EQ (gen_rtx_VEC_MERGE (mode, op0, op3, mask1),
    8997                 :             :                  simplify_rtx (nvm));
    8998                 :         248 : }
    8999                 :             : 
    9000                 :             : /* Test that vector rotate formation works at RTL level.  Try various
    9001                 :             :    combinations of (REG << C) [|,^,+] (REG >> (<bitwidth> - C)).  */
    9002                 :             : 
    9003                 :             : static void
    9004                 :          96 : test_vector_rotate (rtx reg)
    9005                 :             : {
    9006                 :          96 :   machine_mode mode = GET_MODE (reg);
    9007                 :          96 :   unsigned bitwidth = GET_MODE_UNIT_SIZE (mode) * BITS_PER_UNIT;
    9008                 :          96 :   rtx plus_rtx = gen_rtx_PLUS (mode, reg, reg);
    9009                 :          96 :   rtx lshftrt_amnt = GEN_INT (bitwidth - 1);
    9010                 :          96 :   lshftrt_amnt = gen_const_vec_duplicate (mode, lshftrt_amnt);
    9011                 :          96 :   rtx lshiftrt_rtx = gen_rtx_LSHIFTRT (mode, reg, lshftrt_amnt);
    9012                 :          96 :   rtx rotate_rtx = gen_rtx_ROTATE (mode, reg, CONST1_RTX (mode));
    9013                 :             :   /* Test explicitly the case where ASHIFT (x, 1) is a PLUS (x, x).  */
    9014                 :          96 :   ASSERT_RTX_EQ (rotate_rtx,
    9015                 :             :              simplify_rtx (gen_rtx_IOR (mode, plus_rtx, lshiftrt_rtx)));
    9016                 :          96 :   ASSERT_RTX_EQ (rotate_rtx,
    9017                 :             :              simplify_rtx (gen_rtx_XOR (mode, plus_rtx, lshiftrt_rtx)));
    9018                 :          96 :   ASSERT_RTX_EQ (rotate_rtx,
    9019                 :             :              simplify_rtx (gen_rtx_PLUS (mode, plus_rtx, lshiftrt_rtx)));
    9020                 :             : 
    9021                 :             :   /* Don't go through every possible rotate amount to save execution time.
    9022                 :             :      Multiple of BITS_PER_UNIT amounts could conceivably be simplified to
    9023                 :             :      other bswap operations sometimes. Go through just the odd amounts.  */
    9024                 :        1440 :   for (unsigned i = 3; i < bitwidth - 2; i += 2)
    9025                 :             :     {
    9026                 :        1344 :       rtx rot_amnt = gen_const_vec_duplicate (mode, GEN_INT (i));
    9027                 :        1344 :       rtx ashift_rtx = gen_rtx_ASHIFT (mode, reg, rot_amnt);
    9028                 :        1344 :       lshftrt_amnt = gen_const_vec_duplicate (mode, GEN_INT (bitwidth - i));
    9029                 :        1344 :       lshiftrt_rtx = gen_rtx_LSHIFTRT (mode, reg, lshftrt_amnt);
    9030                 :        1344 :       rotate_rtx = gen_rtx_ROTATE (mode, reg, rot_amnt);
    9031                 :        1344 :       ASSERT_RTX_EQ (rotate_rtx,
    9032                 :             :                  simplify_rtx (gen_rtx_IOR (mode, ashift_rtx, lshiftrt_rtx)));
    9033                 :        1344 :       ASSERT_RTX_EQ (rotate_rtx,
    9034                 :             :                  simplify_rtx (gen_rtx_XOR (mode, ashift_rtx, lshiftrt_rtx)));
    9035                 :        1344 :       ASSERT_RTX_EQ (rotate_rtx,
    9036                 :             :                  simplify_rtx (gen_rtx_PLUS (mode, ashift_rtx, lshiftrt_rtx)));
    9037                 :             :     }
    9038                 :          96 : }
    9039                 :             : 
    9040                 :             : /* Test subregs of integer vector constant X, trying elements in
    9041                 :             :    the range [ELT_BIAS, ELT_BIAS + constant_lower_bound (NELTS)),
    9042                 :             :    where NELTS is the number of elements in X.  Subregs involving
    9043                 :             :    elements [ELT_BIAS, ELT_BIAS + FIRST_VALID) are expected to fail.  */
    9044                 :             : 
    9045                 :             : static void
    9046                 :         288 : test_vector_subregs_modes (rtx x, poly_uint64 elt_bias = 0,
    9047                 :             :                            unsigned int first_valid = 0)
    9048                 :             : {
    9049                 :         288 :   machine_mode inner_mode = GET_MODE (x);
    9050                 :         288 :   scalar_mode int_mode = GET_MODE_INNER (inner_mode);
    9051                 :             : 
    9052                 :       37728 :   for (unsigned int modei = 0; modei < NUM_MACHINE_MODES; ++modei)
    9053                 :             :     {
    9054                 :       37440 :       machine_mode outer_mode = (machine_mode) modei;
    9055                 :       37440 :       if (!VECTOR_MODE_P (outer_mode))
    9056                 :       19584 :         continue;
    9057                 :             : 
    9058                 :       17856 :       unsigned int outer_nunits;
    9059                 :       17856 :       if (GET_MODE_INNER (outer_mode) == int_mode
    9060                 :        2064 :           && GET_MODE_NUNITS (outer_mode).is_constant (&outer_nunits)
    9061                 :       23160 :           && multiple_p (GET_MODE_NUNITS (inner_mode), outer_nunits))
    9062                 :             :         {
    9063                 :             :           /* Test subregs in which the outer mode is a smaller,
    9064                 :             :              constant-sized vector of the same element type.  */
    9065                 :        1176 :           unsigned int limit
    9066                 :        1176 :             = constant_lower_bound (GET_MODE_NUNITS (inner_mode));
    9067                 :        9636 :           for (unsigned int elt = 0; elt < limit; elt += outer_nunits)
    9068                 :             :             {
    9069                 :        8460 :               rtx expected = NULL_RTX;
    9070                 :        8460 :               if (elt >= first_valid)
    9071                 :             :                 {
    9072                 :        8460 :                   rtx_vector_builder builder (outer_mode, outer_nunits, 1);
    9073                 :       46668 :                   for (unsigned int i = 0; i < outer_nunits; ++i)
    9074                 :       38208 :                     builder.quick_push (CONST_VECTOR_ELT (x, elt + i));
    9075                 :        8460 :                   expected = builder.build ();
    9076                 :        8460 :                 }
    9077                 :       16920 :               poly_uint64 byte = (elt_bias + elt) * GET_MODE_SIZE (int_mode);
    9078                 :        8460 :               ASSERT_RTX_EQ (expected,
    9079                 :             :                              simplify_subreg (outer_mode, x,
    9080                 :             :                                               inner_mode, byte));
    9081                 :             :             }
    9082                 :             :         }
    9083                 :       33360 :       else if (known_eq (GET_MODE_SIZE (outer_mode),
    9084                 :             :                          GET_MODE_SIZE (inner_mode))
    9085                 :        2100 :                && known_eq (elt_bias, 0U)
    9086                 :        2100 :                && (GET_MODE_CLASS (outer_mode) != MODE_VECTOR_BOOL
    9087                 :           0 :                    || known_eq (GET_MODE_BITSIZE (outer_mode),
    9088                 :             :                                 GET_MODE_NUNITS (outer_mode)))
    9089                 :        2100 :                && (!FLOAT_MODE_P (outer_mode)
    9090                 :       18324 :                    || (FLOAT_MODE_FORMAT (outer_mode)->ieee_bits
    9091                 :        1164 :                        == GET_MODE_UNIT_PRECISION (outer_mode)))
    9092                 :       16680 :                && (GET_MODE_SIZE (inner_mode).is_constant ()
    9093                 :             :                    || !CONST_VECTOR_STEPPED_P (x)))
    9094                 :             :         {
    9095                 :             :           /* Try converting to OUTER_MODE and back.  */
    9096                 :        1848 :           rtx outer_x = simplify_subreg (outer_mode, x, inner_mode, 0);
    9097                 :        1848 :           ASSERT_TRUE (outer_x != NULL_RTX);
    9098                 :        1848 :           ASSERT_RTX_EQ (x, simplify_subreg (inner_mode, outer_x,
    9099                 :             :                                              outer_mode, 0));
    9100                 :             :         }
    9101                 :             :     }
    9102                 :             : 
    9103                 :         288 :   if (BYTES_BIG_ENDIAN == WORDS_BIG_ENDIAN)
    9104                 :             :     {
    9105                 :             :       /* Test each byte in the element range.  */
    9106                 :         288 :       unsigned int limit
    9107                 :         288 :         = constant_lower_bound (GET_MODE_SIZE (inner_mode));
    9108                 :       17688 :       for (unsigned int i = 0; i < limit; ++i)
    9109                 :             :         {
    9110                 :       17400 :           unsigned int elt = i / GET_MODE_SIZE (int_mode);
    9111                 :       17400 :           rtx expected = NULL_RTX;
    9112                 :       17400 :           if (elt >= first_valid)
    9113                 :             :             {
    9114                 :       17400 :               unsigned int byte_shift = i % GET_MODE_SIZE (int_mode);
    9115                 :       17400 :               if (BYTES_BIG_ENDIAN)
    9116                 :             :                 byte_shift = GET_MODE_SIZE (int_mode) - byte_shift - 1;
    9117                 :       17400 :               rtx_mode_t vec_elt (CONST_VECTOR_ELT (x, elt), int_mode);
    9118                 :       17400 :               wide_int shifted_elt
    9119                 :       17400 :                 = wi::lrshift (vec_elt, byte_shift * BITS_PER_UNIT);
    9120                 :       17400 :               expected = immed_wide_int_const (shifted_elt, QImode);
    9121                 :       17400 :             }
    9122                 :       34800 :           poly_uint64 byte = elt_bias * GET_MODE_SIZE (int_mode) + i;
    9123                 :       17400 :           ASSERT_RTX_EQ (expected,
    9124                 :             :                          simplify_subreg (QImode, x, inner_mode, byte));
    9125                 :             :         }
    9126                 :             :     }
    9127                 :         288 : }
    9128                 :             : 
    9129                 :             : /* Test constant subregs of integer vector mode INNER_MODE, using 1
    9130                 :             :    element per pattern.  */
    9131                 :             : 
    9132                 :             : static void
    9133                 :          96 : test_vector_subregs_repeating (machine_mode inner_mode)
    9134                 :             : {
    9135                 :         192 :   poly_uint64 nunits = GET_MODE_NUNITS (inner_mode);
    9136                 :          96 :   unsigned int min_nunits = constant_lower_bound (nunits);
    9137                 :          96 :   scalar_mode int_mode = GET_MODE_INNER (inner_mode);
    9138                 :          96 :   unsigned int count = gcd (min_nunits, 8);
    9139                 :             : 
    9140                 :          96 :   rtx_vector_builder builder (inner_mode, count, 1);
    9141                 :         720 :   for (unsigned int i = 0; i < count; ++i)
    9142                 :         624 :     builder.quick_push (gen_int_mode (8 - i, int_mode));
    9143                 :          96 :   rtx x = builder.build ();
    9144                 :             : 
    9145                 :          96 :   test_vector_subregs_modes (x);
    9146                 :          96 :   if (!nunits.is_constant ())
    9147                 :             :     test_vector_subregs_modes (x, nunits - min_nunits);
    9148                 :          96 : }
    9149                 :             : 
    9150                 :             : /* Test constant subregs of integer vector mode INNER_MODE, using 2
    9151                 :             :    elements per pattern.  */
    9152                 :             : 
    9153                 :             : static void
    9154                 :          96 : test_vector_subregs_fore_back (machine_mode inner_mode)
    9155                 :             : {
    9156                 :         192 :   poly_uint64 nunits = GET_MODE_NUNITS (inner_mode);
    9157                 :          96 :   unsigned int min_nunits = constant_lower_bound (nunits);
    9158                 :          96 :   scalar_mode int_mode = GET_MODE_INNER (inner_mode);
    9159                 :          96 :   unsigned int count = gcd (min_nunits, 4);
    9160                 :             : 
    9161                 :          96 :   rtx_vector_builder builder (inner_mode, count, 2);
    9162                 :         464 :   for (unsigned int i = 0; i < count; ++i)
    9163                 :         368 :     builder.quick_push (gen_int_mode (i, int_mode));
    9164                 :         464 :   for (unsigned int i = 0; i < count; ++i)
    9165                 :         368 :     builder.quick_push (gen_int_mode (-1 - (int) i, int_mode));
    9166                 :          96 :   rtx x = builder.build ();
    9167                 :             : 
    9168                 :          96 :   test_vector_subregs_modes (x);
    9169                 :          96 :   if (!nunits.is_constant ())
    9170                 :             :     test_vector_subregs_modes (x, nunits - min_nunits, count);
    9171                 :          96 : }
    9172                 :             : 
    9173                 :             : /* Test constant subregs of integer vector mode INNER_MODE, using 3
    9174                 :             :    elements per pattern.  */
    9175                 :             : 
    9176                 :             : static void
    9177                 :          96 : test_vector_subregs_stepped (machine_mode inner_mode)
    9178                 :             : {
    9179                 :             :   /* Build { 0, 1, 2, 3, ... }.  */
    9180                 :          96 :   scalar_mode int_mode = GET_MODE_INNER (inner_mode);
    9181                 :          96 :   rtx_vector_builder builder (inner_mode, 1, 3);
    9182                 :         384 :   for (unsigned int i = 0; i < 3; ++i)
    9183                 :         288 :     builder.quick_push (gen_int_mode (i, int_mode));
    9184                 :          96 :   rtx x = builder.build ();
    9185                 :             : 
    9186                 :          96 :   test_vector_subregs_modes (x);
    9187                 :          96 : }
    9188                 :             : 
    9189                 :             : /* Test constant subregs of integer vector mode INNER_MODE.  */
    9190                 :             : 
    9191                 :             : static void
    9192                 :          96 : test_vector_subregs (machine_mode inner_mode)
    9193                 :             : {
    9194                 :          96 :   test_vector_subregs_repeating (inner_mode);
    9195                 :          96 :   test_vector_subregs_fore_back (inner_mode);
    9196                 :          96 :   test_vector_subregs_stepped (inner_mode);
    9197                 :          96 : }
    9198                 :             : 
    9199                 :             : /* Verify some simplifications involving vectors.  */
    9200                 :             : 
    9201                 :             : static void
    9202                 :           4 : test_vector_ops ()
    9203                 :             : {
    9204                 :         524 :   for (unsigned int i = 0; i < NUM_MACHINE_MODES; ++i)
    9205                 :             :     {
    9206                 :         520 :       machine_mode mode = (machine_mode) i;
    9207                 :         520 :       if (VECTOR_MODE_P (mode))
    9208                 :             :         {
    9209                 :         496 :           rtx scalar_reg = make_test_reg (GET_MODE_INNER (mode));
    9210                 :         248 :           test_vector_ops_duplicate (mode, scalar_reg);
    9211                 :         248 :           rtx vector_reg = make_test_reg (mode);
    9212                 :         248 :           if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
    9213                 :         376 :               && maybe_gt (GET_MODE_NUNITS (mode), 2))
    9214                 :             :             {
    9215                 :          96 :               test_vector_ops_series (mode, scalar_reg);
    9216                 :          96 :               test_vector_subregs (mode);
    9217                 :          96 :               test_vector_rotate (vector_reg);
    9218                 :             :             }
    9219                 :         248 :           test_vec_merge (mode);
    9220                 :             :         }
    9221                 :             :     }
    9222                 :           4 : }
    9223                 :             : 
    9224                 :             : template<unsigned int N>
    9225                 :             : struct simplify_const_poly_int_tests
    9226                 :             : {
    9227                 :             :   static void run ();
    9228                 :             : };
    9229                 :             : 
    9230                 :             : template<>
    9231                 :             : struct simplify_const_poly_int_tests<1>
    9232                 :             : {
    9233                 :             :   static void run () {}
    9234                 :             : };
    9235                 :             : 
    9236                 :             : /* Test various CONST_POLY_INT properties.  */
    9237                 :             : 
    9238                 :             : template<unsigned int N>
    9239                 :             : void
    9240                 :             : simplify_const_poly_int_tests<N>::run ()
    9241                 :             : {
    9242                 :             :   using poly_int64 = poly_int<N, HOST_WIDE_INT>;
    9243                 :             :   rtx x1 = gen_int_mode (poly_int64 (1, 1), QImode);
    9244                 :             :   rtx x2 = gen_int_mode (poly_int64 (-80, 127), QImode);
    9245                 :             :   rtx x3 = gen_int_mode (poly_int64 (-79, -128), QImode);
    9246                 :             :   rtx x4 = gen_int_mode (poly_int64 (5, 4), QImode);
    9247                 :             :   rtx x5 = gen_int_mode (poly_int64 (30, 24), QImode);
    9248                 :             :   rtx x6 = gen_int_mode (poly_int64 (20, 16), QImode);
    9249                 :             :   rtx x7 = gen_int_mode (poly_int64 (7, 4), QImode);
    9250                 :             :   rtx x8 = gen_int_mode (poly_int64 (30, 24), HImode);
    9251                 :             :   rtx x9 = gen_int_mode (poly_int64 (-30, -24), HImode);
    9252                 :             :   rtx x10 = gen_int_mode (poly_int64 (-31, -24), HImode);
    9253                 :             :   rtx two = GEN_INT (2);
    9254                 :             :   rtx six = GEN_INT (6);
    9255                 :             :   poly_uint64 offset = subreg_lowpart_offset (QImode, HImode);
    9256                 :             : 
    9257                 :             :   /* These tests only try limited operation combinations.  Fuller arithmetic
    9258                 :             :      testing is done directly on poly_ints.  */
    9259                 :             :   ASSERT_EQ (simplify_unary_operation (NEG, HImode, x8, HImode), x9);
    9260                 :             :   ASSERT_EQ (simplify_unary_operation (NOT, HImode, x8, HImode), x10);
    9261                 :             :   ASSERT_EQ (simplify_unary_operation (TRUNCATE, QImode, x8, HImode), x5);
    9262                 :             :   ASSERT_EQ (simplify_binary_operation (PLUS, QImode, x1, x2), x3);
    9263                 :             :   ASSERT_EQ (simplify_binary_operation (MINUS, QImode, x3, x1), x2);
    9264                 :             :   ASSERT_EQ (simplify_binary_operation (MULT, QImode, x4, six), x5);
    9265                 :             :   ASSERT_EQ (simplify_binary_operation (MULT, QImode, six, x4), x5);
    9266                 :             :   ASSERT_EQ (simplify_binary_operation (ASHIFT, QImode, x4, two), x6);
    9267                 :             :   ASSERT_EQ (simplify_binary_operation (IOR, QImode, x4, two), x7);
    9268                 :             :   ASSERT_EQ (simplify_subreg (HImode, x5, QImode, 0), x8);
    9269                 :             :   ASSERT_EQ (simplify_subreg (QImode, x8, HImode, offset), x5);
    9270                 :             : }
    9271                 :             : 
    9272                 :             : /* Run all of the selftests within this file.  */
    9273                 :             : 
    9274                 :             : void
    9275                 :           4 : simplify_rtx_cc_tests ()
    9276                 :             : {
    9277                 :           4 :   test_scalar_ops ();
    9278                 :           4 :   test_vector_ops ();
    9279                 :           4 :   simplify_const_poly_int_tests<NUM_POLY_INT_COEFFS>::run ();
    9280                 :           4 : }
    9281                 :             : 
    9282                 :             : } // namespace selftest
    9283                 :             : 
    9284                 :             : #endif /* CHECKING_P */
        

Generated by: LCOV version 2.1-beta

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