LCOV - code coverage report
Current view: top level - gcc - rtlanal.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 86.5 % 2923 2529
Test Date: 2026-11-14 16:39:50 Functions: 89.1 % 175 156
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Analyze RTL for GNU compiler.
       2              :    Copyright (C) 1987-2026 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 "rtlanal.h"
      28              : #include "tree.h"
      29              : #include "predict.h"
      30              : #include "df.h"
      31              : #include "memmodel.h"
      32              : #include "tm_p.h"
      33              : #include "insn-config.h"
      34              : #include "regs.h"
      35              : #include "emit-rtl.h"  /* FIXME: Can go away once crtl is moved to rtl.h.  */
      36              : #include "recog.h"
      37              : #include "addresses.h"
      38              : #include "rtl-iter.h"
      39              : #include "hard-reg-set.h"
      40              : #include "function-abi.h"
      41              : #include "hash-map.h"
      42              : #include "tree-pass.h"
      43              : 
      44              : /* Forward declarations */
      45              : static void set_of_1 (rtx, const_rtx, void *);
      46              : static bool covers_regno_p (const_rtx, unsigned int);
      47              : static bool covers_regno_no_parallel_p (const_rtx, unsigned int);
      48              : static bool computed_jump_p_1 (const_rtx);
      49              : static void parms_set (rtx, const_rtx, void *);
      50              : 
      51              : static unsigned HOST_WIDE_INT cached_nonzero_bits (const_rtx, scalar_int_mode,
      52              :                                                    const_rtx, machine_mode,
      53              :                                                    unsigned HOST_WIDE_INT);
      54              : static unsigned HOST_WIDE_INT nonzero_bits1 (const_rtx, scalar_int_mode,
      55              :                                              const_rtx, machine_mode,
      56              :                                              unsigned HOST_WIDE_INT);
      57              : static unsigned int cached_num_sign_bit_copies (const_rtx, scalar_int_mode,
      58              :                                                 const_rtx, machine_mode,
      59              :                                                 unsigned int);
      60              : static unsigned int num_sign_bit_copies1 (const_rtx, scalar_int_mode,
      61              :                                           const_rtx, machine_mode,
      62              :                                           unsigned int);
      63              : 
      64              : rtx_subrtx_bound_info rtx_all_subrtx_bounds[NUM_RTX_CODE];
      65              : rtx_subrtx_bound_info rtx_nonconst_subrtx_bounds[NUM_RTX_CODE];
      66              : 
      67              : /* Truncation narrows the mode from SOURCE mode to DESTINATION mode.
      68              :    If TARGET_MODE_REP_EXTENDED (DESTINATION, DESTINATION_REP) is
      69              :    SIGN_EXTEND then while narrowing we also have to enforce the
      70              :    representation and sign-extend the value to mode DESTINATION_REP.
      71              : 
      72              :    If the value is already sign-extended to DESTINATION_REP mode we
      73              :    can just switch to DESTINATION mode on it.  For each pair of
      74              :    integral modes SOURCE and DESTINATION, when truncating from SOURCE
      75              :    to DESTINATION, NUM_SIGN_BIT_COPIES_IN_REP[SOURCE][DESTINATION]
      76              :    contains the number of high-order bits in SOURCE that have to be
      77              :    copies of the sign-bit so that we can do this mode-switch to
      78              :    DESTINATION.  */
      79              : 
      80              : static unsigned int
      81              : num_sign_bit_copies_in_rep[MAX_MODE_INT + 1][MAX_MODE_INT + 1];
      82              : 
      83              : /* Store X into index I of ARRAY.  ARRAY is known to have at least I
      84              :    elements.  Return the new base of ARRAY.  */
      85              : 
      86              : template <typename T>
      87              : typename T::value_type *
      88     15879976 : generic_subrtx_iterator <T>::add_single_to_queue (array_type &array,
      89              :                                                   value_type *base,
      90              :                                                   size_t i, value_type x)
      91              : {
      92     15879976 :   if (base == array.stack)
      93              :     {
      94      7626009 :       if (i < LOCAL_ELEMS)
      95              :         {
      96      7145154 :           base[i] = x;
      97      7145154 :           return base;
      98              :         }
      99       480855 :       gcc_checking_assert (i == LOCAL_ELEMS);
     100              :       /* A previous iteration might also have moved from the stack to the
     101              :          heap, in which case the heap array will already be big enough.  */
     102       480855 :       if (vec_safe_length (array.heap) <= i)
     103       480855 :         vec_safe_grow (array.heap, i + 1, true);
     104       480855 :       base = array.heap->address ();
     105       480855 :       memcpy (base, array.stack, sizeof (array.stack));
     106       480855 :       base[LOCAL_ELEMS] = x;
     107       480855 :       return base;
     108              :     }
     109      8253967 :   unsigned int length = array.heap->length ();
     110      8253967 :   if (length > i)
     111              :     {
     112      1879290 :       gcc_checking_assert (base == array.heap->address ());
     113      1879290 :       base[i] = x;
     114      1879290 :       return base;
     115              :     }
     116              :   else
     117              :     {
     118      6374677 :       gcc_checking_assert (i == length);
     119      6374677 :       vec_safe_push (array.heap, x);
     120      6374677 :       return array.heap->address ();
     121              :     }
     122              : }
     123              : 
     124              : /* Add the subrtxes of X to worklist ARRAY, starting at END.  Return the
     125              :    number of elements added to the worklist.  */
     126              : 
     127              : template <typename T>
     128              : size_t
     129    343551721 : generic_subrtx_iterator <T>::add_subrtxes_to_queue (array_type &array,
     130              :                                                     value_type *base,
     131              :                                                     size_t end, rtx_type x)
     132              : {
     133    343551721 :   enum rtx_code code = GET_CODE (x);
     134    343551721 :   const char *format = GET_RTX_FORMAT (code);
     135    343551721 :   size_t orig_end = end;
     136    343551721 :   if (UNLIKELY (INSN_P (x)))
     137              :     {
     138              :       /* Put the pattern at the top of the queue, since that's what
     139              :          we're likely to want most.  It also allows for the SEQUENCE
     140              :          code below.  */
     141      3784274 :       for (int i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; --i)
     142      3318149 :         if (format[i] == 'e')
     143              :           {
     144       943139 :             value_type subx = T::get_value (x->u.fld[i].rt_rtx);
     145       943139 :             if (LIKELY (end < LOCAL_ELEMS))
     146       943139 :               base[end++] = subx;
     147              :             else
     148            0 :               base = add_single_to_queue (array, base, end++, subx);
     149              :           }
     150              :     }
     151              :   else
     152    750028441 :     for (int i = 0; format[i]; ++i)
     153    406942845 :       if (format[i] == 'e')
     154              :         {
     155      1526129 :           value_type subx = T::get_value (x->u.fld[i].rt_rtx);
     156      1526129 :           if (LIKELY (end < LOCAL_ELEMS))
     157       112940 :             base[end++] = subx;
     158              :           else
     159      1413189 :             base = add_single_to_queue (array, base, end++, subx);
     160              :         }
     161    405416716 :       else if (format[i] == 'E')
     162              :         {
     163    349204030 :           unsigned int length = GET_NUM_ELEM (x->u.fld[i].rt_rtvec);
     164    349204030 :           rtx *vec = x->u.fld[i].rt_rtvec->elem;
     165    349204030 :           if (LIKELY (end + length <= LOCAL_ELEMS))
     166   1075495449 :             for (unsigned int j = 0; j < length; j++)
     167    726853233 :               base[end++] = T::get_value (vec[j]);
     168              :           else
     169     15028601 :             for (unsigned int j = 0; j < length; j++)
     170     14466787 :               base = add_single_to_queue (array, base, end++,
     171     14466787 :                                           T::get_value (vec[j]));
     172    349204030 :           if (code == SEQUENCE && end == length)
     173              :             /* If the subrtxes of the sequence fill the entire array then
     174              :                we know that no other parts of a containing insn are queued.
     175              :                The caller is therefore iterating over the sequence as a
     176              :                PATTERN (...), so we also want the patterns of the
     177              :                subinstructions.  */
     178            0 :             for (unsigned int j = 0; j < length; j++)
     179              :               {
     180            0 :                 typename T::rtx_type x = T::get_rtx (base[j]);
     181            0 :                 if (INSN_P (x))
     182            0 :                   base[j] = T::get_value (PATTERN (x));
     183              :               }
     184              :         }
     185    343551721 :   return end - orig_end;
     186              : }
     187              : 
     188              : template <typename T>
     189              : void
     190       480855 : generic_subrtx_iterator <T>::free_array (array_type &array)
     191              : {
     192    445776271 :   vec_free (array.heap);
     193       241870 : }
     194              : 
     195              : template <typename T>
     196              : const size_t generic_subrtx_iterator <T>::LOCAL_ELEMS;
     197              : 
     198              : template class generic_subrtx_iterator <const_rtx_accessor>;
     199              : template class generic_subrtx_iterator <rtx_var_accessor>;
     200              : template class generic_subrtx_iterator <rtx_ptr_accessor>;
     201              : 
     202              : /* Return true if the value of X is unstable
     203              :    (would be different at a different point in the program).
     204              :    The frame pointer, arg pointer, etc. are considered stable
     205              :    (within one function) and so is anything marked `unchanging'.  */
     206              : 
     207              : bool
     208            0 : rtx_unstable_p (const_rtx x)
     209              : {
     210            0 :   const RTX_CODE code = GET_CODE (x);
     211            0 :   int i;
     212            0 :   const char *fmt;
     213              : 
     214            0 :   switch (code)
     215              :     {
     216            0 :     case MEM:
     217            0 :       return !MEM_READONLY_P (x) || rtx_unstable_p (XEXP (x, 0));
     218              : 
     219              :     case CONST:
     220              :     CASE_CONST_ANY:
     221              :     case SYMBOL_REF:
     222              :     case LABEL_REF:
     223              :       return false;
     224              : 
     225            0 :     case REG:
     226              :       /* As in rtx_varies_p, we have to use the actual rtx, not reg number.  */
     227            0 :       if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
     228              :           /* The arg pointer varies if it is not a fixed register.  */
     229            0 :           || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM]))
     230              :         return false;
     231              :       /* ??? When call-clobbered, the value is stable modulo the restore
     232              :          that must happen after a call.  This currently screws up local-alloc
     233              :          into believing that the restore is not needed.  */
     234            0 :       if (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED && x == pic_offset_table_rtx)
     235              :         return false;
     236              :       return true;
     237              : 
     238            0 :     case ASM_OPERANDS:
     239            0 :       if (MEM_VOLATILE_P (x))
     240              :         return true;
     241              : 
     242              :       /* Fall through.  */
     243              : 
     244            0 :     default:
     245            0 :       break;
     246              :     }
     247              : 
     248            0 :   fmt = GET_RTX_FORMAT (code);
     249            0 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
     250            0 :     if (fmt[i] == 'e')
     251              :       {
     252            0 :         if (rtx_unstable_p (XEXP (x, i)))
     253              :           return true;
     254              :       }
     255            0 :     else if (fmt[i] == 'E')
     256              :       {
     257              :         int j;
     258            0 :         for (j = 0; j < XVECLEN (x, i); j++)
     259            0 :           if (rtx_unstable_p (XVECEXP (x, i, j)))
     260              :             return true;
     261              :       }
     262              : 
     263              :   return false;
     264              : }
     265              : 
     266              : /* Return true if X has a value that can vary even between two
     267              :    executions of the program.  false means X can be compared reliably
     268              :    against certain constants or near-constants.
     269              :    FOR_ALIAS is nonzero if we are called from alias analysis; if it is
     270              :    zero, we are slightly more conservative.
     271              :    The frame pointer and the arg pointer are considered constant.  */
     272              : 
     273              : bool
     274    510246744 : rtx_varies_p (const_rtx x, bool for_alias)
     275              : {
     276    510246744 :   RTX_CODE code;
     277    510246744 :   int i;
     278    510246744 :   const char *fmt;
     279              : 
     280    510246744 :   if (!x)
     281              :     return false;
     282              : 
     283    510246744 :   code = GET_CODE (x);
     284    510246744 :   switch (code)
     285              :     {
     286     93872597 :     case MEM:
     287     93872597 :       return !MEM_READONLY_P (x) || rtx_varies_p (XEXP (x, 0), for_alias);
     288              : 
     289              :     case CONST:
     290              :     CASE_CONST_ANY:
     291              :     case SYMBOL_REF:
     292              :     case LABEL_REF:
     293              :       return false;
     294              : 
     295    163979729 :     case REG:
     296              :       /* Note that we have to test for the actual rtx used for the frame
     297              :          and arg pointers and not just the register number in case we have
     298              :          eliminated the frame and/or arg pointer and are using it
     299              :          for pseudos.  */
     300    163979729 :       if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
     301              :           /* The arg pointer varies if it is not a fixed register.  */
     302    145142483 :           || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM]))
     303              :         return false;
     304    144907617 :       if (x == pic_offset_table_rtx
     305              :           /* ??? When call-clobbered, the value is stable modulo the restore
     306              :              that must happen after a call.  This currently screws up
     307              :              local-alloc into believing that the restore is not needed, so we
     308              :              must return 0 only if we are called from alias analysis.  */
     309              :           && (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED || for_alias))
     310              :         return false;
     311              :       return true;
     312              : 
     313            0 :     case LO_SUM:
     314              :       /* The operand 0 of a LO_SUM is considered constant
     315              :          (in fact it is related specifically to operand 1)
     316              :          during alias analysis.  */
     317            0 :       return (! for_alias && rtx_varies_p (XEXP (x, 0), for_alias))
     318            0 :              || rtx_varies_p (XEXP (x, 1), for_alias);
     319              : 
     320        93986 :     case ASM_OPERANDS:
     321        93986 :       if (MEM_VOLATILE_P (x))
     322              :         return true;
     323              : 
     324              :       /* Fall through.  */
     325              : 
     326    141974741 :     default:
     327    141974741 :       break;
     328              :     }
     329              : 
     330    141974741 :   fmt = GET_RTX_FORMAT (code);
     331    248813150 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
     332    225310660 :     if (fmt[i] == 'e')
     333              :       {
     334    206343035 :         if (rtx_varies_p (XEXP (x, i), for_alias))
     335              :           return true;
     336              :       }
     337     18967625 :     else if (fmt[i] == 'E')
     338              :       {
     339              :         int j;
     340     19979384 :         for (j = 0; j < XVECLEN (x, i); j++)
     341     15729682 :           if (rtx_varies_p (XVECEXP (x, i, j), for_alias))
     342              :             return true;
     343              :       }
     344              : 
     345              :   return false;
     346              : }
     347              : 
     348              : /* Compute an approximation for the offset between the register
     349              :    FROM and TO for the current function, as it was at the start
     350              :    of the routine.  */
     351              : 
     352              : static poly_int64
     353    238952211 : get_initial_register_offset (int from, int to)
     354              : {
     355    238952211 :   static const struct elim_table_t
     356              :   {
     357              :     const int from;
     358              :     const int to;
     359              :   } table[] = ELIMINABLE_REGS;
     360    238952211 :   poly_int64 offset1, offset2;
     361    238952211 :   unsigned int i, j;
     362              : 
     363    238952211 :   if (to == from)
     364            0 :     return 0;
     365              : 
     366              :   /* It is not safe to call INITIAL_ELIMINATION_OFFSET before the epilogue
     367              :      is completed, but we need to give at least an estimate for the stack
     368              :      pointer based on the frame size.  */
     369    238952211 :   if (!epilogue_completed)
     370              :     {
     371    131276287 :       offset1 = crtl->outgoing_args_size + get_frame_size ();
     372              : #if !STACK_GROWS_DOWNWARD
     373              :       offset1 = - offset1;
     374              : #endif
     375    131276287 :       if (to == STACK_POINTER_REGNUM)
     376    130744143 :         return offset1;
     377       532144 :       else if (from == STACK_POINTER_REGNUM)
     378       266072 :         return - offset1;
     379              :       else
     380       266072 :         return 0;
     381              :      }
     382              : 
     383    108821594 :   for (i = 0; i < ARRAY_SIZE (table); i++)
     384    108821594 :       if (table[i].from == from)
     385              :         {
     386    107675924 :           if (table[i].to == to)
     387              :             {
     388    106530254 :               INITIAL_ELIMINATION_OFFSET (table[i].from, table[i].to,
     389              :                                           offset1);
     390    106530254 :               return offset1;
     391              :             }
     392      5728350 :           for (j = 0; j < ARRAY_SIZE (table); j++)
     393              :             {
     394      4582680 :               if (table[j].to == to
     395              :                   && table[j].from == table[i].to)
     396              :                 {
     397              :                   INITIAL_ELIMINATION_OFFSET (table[i].from, table[i].to,
     398              :                                               offset1);
     399              :                   INITIAL_ELIMINATION_OFFSET (table[j].from, table[j].to,
     400              :                                               offset2);
     401              :                   return offset1 + offset2;
     402              :                 }
     403      4582680 :               if (table[j].from == to
     404            0 :                   && table[j].to == table[i].to)
     405              :                 {
     406            0 :                   INITIAL_ELIMINATION_OFFSET (table[i].from, table[i].to,
     407              :                                               offset1);
     408            0 :                   INITIAL_ELIMINATION_OFFSET (table[j].from, table[j].to,
     409              :                                               offset2);
     410            0 :                   return offset1 - offset2;
     411              :                 }
     412              :             }
     413              :         }
     414      1145670 :       else if (table[i].to == from)
     415              :         {
     416      1145670 :           if (table[i].from == to)
     417              :             {
     418            0 :               INITIAL_ELIMINATION_OFFSET (table[i].from, table[i].to,
     419              :                                           offset1);
     420            0 :               return - offset1;
     421              :             }
     422      2291340 :           for (j = 0; j < ARRAY_SIZE (table); j++)
     423              :             {
     424      2291340 :               if (table[j].to == to
     425      1145670 :                   && table[j].from == table[i].from)
     426              :                 {
     427      1145670 :                   INITIAL_ELIMINATION_OFFSET (table[i].from, table[i].to,
     428              :                                               offset1);
     429      1145670 :                   INITIAL_ELIMINATION_OFFSET (table[j].from, table[j].to,
     430              :                                               offset2);
     431      1145670 :                   return - offset1 + offset2;
     432              :                 }
     433      1145670 :               if (table[j].from == to
     434              :                   && table[j].to == table[i].from)
     435              :                 {
     436              :                   INITIAL_ELIMINATION_OFFSET (table[i].from, table[i].to,
     437              :                                               offset1);
     438              :                   INITIAL_ELIMINATION_OFFSET (table[j].from, table[j].to,
     439              :                                               offset2);
     440              :                   return - offset1 - offset2;
     441              :                 }
     442              :             }
     443              :         }
     444              : 
     445              :   /* If the requested register combination was not found,
     446              :      try a different more simple combination.  */
     447            0 :   if (from == ARG_POINTER_REGNUM)
     448              :     return get_initial_register_offset (HARD_FRAME_POINTER_REGNUM, to);
     449            0 :   else if (to == ARG_POINTER_REGNUM)
     450              :     return get_initial_register_offset (from, HARD_FRAME_POINTER_REGNUM);
     451            0 :   else if (from == HARD_FRAME_POINTER_REGNUM)
     452              :     return get_initial_register_offset (FRAME_POINTER_REGNUM, to);
     453            0 :   else if (to == HARD_FRAME_POINTER_REGNUM)
     454              :     return get_initial_register_offset (from, FRAME_POINTER_REGNUM);
     455              :   else
     456            0 :     return 0;
     457              : }
     458              : 
     459              : /* Return true if the use of X+OFFSET as an address in a MEM with SIZE
     460              :    bytes can cause a trap.  MODE is the mode of the MEM (not that of X) and
     461              :    UNALIGNED_MEMS controls whether true is returned for unaligned memory
     462              :    references on strict alignment machines.  */
     463              : 
     464              : static bool
     465    612101559 : rtx_addr_can_trap_p_1 (const_rtx x, poly_int64 offset, poly_int64 size,
     466              :                        machine_mode mode, bool unaligned_mems)
     467              : {
     468    809221017 :   enum rtx_code code = GET_CODE (x);
     469    809221017 :   gcc_checking_assert (mode == BLKmode
     470              :                        || mode == VOIDmode
     471              :                        || known_size_p (size));
     472    809221017 :   poly_int64 const_x1;
     473              : 
     474              :   /* The offset must be a multiple of the mode size if we are considering
     475              :      unaligned memory references on strict alignment machines.  */
     476    809221017 :   if (STRICT_ALIGNMENT
     477              :       && unaligned_mems
     478              :       && mode != BLKmode
     479              :       && mode != VOIDmode)
     480              :     {
     481              :       poly_int64 actual_offset = offset;
     482              : 
     483              : #ifdef SPARC_STACK_BOUNDARY_HACK
     484              :       /* ??? The SPARC port may claim a STACK_BOUNDARY higher than
     485              :              the real alignment of %sp.  However, when it does this, the
     486              :              alignment of %sp+STACK_POINTER_OFFSET is STACK_BOUNDARY.  */
     487              :       if (SPARC_STACK_BOUNDARY_HACK
     488              :           && (x == stack_pointer_rtx || x == hard_frame_pointer_rtx))
     489              :         actual_offset -= STACK_POINTER_OFFSET;
     490              : #endif
     491              : 
     492              :       if (!multiple_p (actual_offset, GET_MODE_SIZE (mode)))
     493              :         return true;
     494              :     }
     495              : 
     496    809221017 :   switch (code)
     497              :     {
     498      6268662 :     case SYMBOL_REF:
     499      6268662 :       if (SYMBOL_REF_WEAK (x))
     500              :         return true;
     501      5943748 :       if (!CONSTANT_POOL_ADDRESS_P (x) && !SYMBOL_REF_FUNCTION_P (x))
     502              :         {
     503       792730 :           tree decl;
     504       792730 :           poly_int64 decl_size;
     505              : 
     506       792730 :           if (maybe_lt (offset, 0))
     507              :             return true;
     508       791749 :           if (!known_size_p (size))
     509          636 :             return maybe_ne (offset, 0);
     510              : 
     511              :           /* If the size of the access or of the symbol is unknown,
     512              :              assume the worst.  */
     513       791113 :           decl = SYMBOL_REF_DECL (x);
     514              : 
     515              :           /* Else check that the access is in bounds.  TODO: restructure
     516              :              expr_size/tree_expr_size/int_expr_size and just use the latter.  */
     517       791113 :           if (!decl)
     518       239337 :             decl_size = -1;
     519       551776 :           else if (DECL_P (decl) && DECL_SIZE_UNIT (decl))
     520              :             {
     521       543783 :               if (!poly_int_tree_p (DECL_SIZE_UNIT (decl), &decl_size))
     522            0 :                 decl_size = -1;
     523              :             }
     524         7993 :           else if (TREE_CODE (decl) == STRING_CST)
     525            0 :             decl_size = TREE_STRING_LENGTH (decl);
     526         7993 :           else if (TYPE_SIZE_UNIT (TREE_TYPE (decl)))
     527            0 :             decl_size = int_size_in_bytes (TREE_TYPE (decl));
     528              :           else
     529         7993 :             decl_size = -1;
     530              : 
     531       791113 :           return (!known_size_p (decl_size) || known_eq (decl_size, 0)
     532       791113 :                   ? maybe_ne (offset, 0)
     533       791113 :                   : !known_subrange_p (offset, size, 0, decl_size));
     534              :         }
     535              : 
     536              :       return false;
     537              : 
     538              :     case LABEL_REF:
     539              :       return false;
     540              : 
     541    404528262 :     case REG:
     542              :       /* Stack references are assumed not to trap, but we need to deal with
     543              :          nonsensical offsets.  */
     544    404528262 :       if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
     545    396525881 :          || x == stack_pointer_rtx
     546              :          /* The arg pointer varies if it is not a fixed register.  */
     547    160394369 :          || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM]))
     548              :         {
     549              : #ifdef RED_ZONE_SIZE
     550    244221856 :           poly_int64 red_zone_size = RED_ZONE_SIZE;
     551              : #else
     552              :           poly_int64 red_zone_size = 0;
     553              : #endif
     554    244221856 :           poly_int64 stack_boundary = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
     555    244221856 :           poly_int64 low_bound, high_bound;
     556              : 
     557    244221856 :           if (!known_size_p (size))
     558              :             return true;
     559              : 
     560    244217991 :           if (x == frame_pointer_rtx)
     561              :             {
     562      6589568 :               if (FRAME_GROWS_DOWNWARD)
     563              :                 {
     564      6589568 :                   high_bound = targetm.starting_frame_offset ();
     565      6589568 :                   low_bound  = high_bound - get_frame_size ();
     566              :                 }
     567              :               else
     568              :                 {
     569              :                   low_bound  = targetm.starting_frame_offset ();
     570              :                   high_bound = low_bound + get_frame_size ();
     571              :                 }
     572              :             }
     573    237628423 :           else if (x == hard_frame_pointer_rtx)
     574              :             {
     575      1411742 :               poly_int64 sp_offset
     576      1411742 :                 = get_initial_register_offset (STACK_POINTER_REGNUM,
     577              :                                                HARD_FRAME_POINTER_REGNUM);
     578      1411742 :               poly_int64 ap_offset
     579      1411742 :                 = get_initial_register_offset (ARG_POINTER_REGNUM,
     580              :                                                HARD_FRAME_POINTER_REGNUM);
     581              : 
     582              : #if STACK_GROWS_DOWNWARD
     583      1411742 :               low_bound  = sp_offset - red_zone_size - stack_boundary;
     584      1411742 :               high_bound = ap_offset
     585      1411742 :                            + FIRST_PARM_OFFSET (current_function_decl)
     586              : #if !ARGS_GROW_DOWNWARD
     587      1411742 :                            + crtl->args.size
     588              : #endif
     589      1411742 :                            + stack_boundary;
     590              : #else
     591              :               high_bound = sp_offset + red_zone_size + stack_boundary;
     592              :               low_bound  = ap_offset
     593              :                            + FIRST_PARM_OFFSET (current_function_decl)
     594              : #if ARGS_GROW_DOWNWARD
     595              :                            - crtl->args.size
     596              : #endif
     597              :                            - stack_boundary;
     598              : #endif
     599              :             }
     600    236216681 :           else if (x == stack_pointer_rtx)
     601              :             {
     602    236128727 :               poly_int64 ap_offset
     603    236128727 :                 = get_initial_register_offset (ARG_POINTER_REGNUM,
     604              :                                                STACK_POINTER_REGNUM);
     605              : 
     606              : #if STACK_GROWS_DOWNWARD
     607    236128727 :               low_bound  = - red_zone_size - stack_boundary;
     608    236128727 :               high_bound = ap_offset
     609    236128727 :                            + FIRST_PARM_OFFSET (current_function_decl)
     610              : #if !ARGS_GROW_DOWNWARD
     611    236128727 :                            + crtl->args.size
     612              : #endif
     613    236128727 :                            + stack_boundary;
     614              : #else
     615              :               high_bound = red_zone_size + stack_boundary;
     616              :               low_bound  = ap_offset
     617              :                            + FIRST_PARM_OFFSET (current_function_decl)
     618              : #if ARGS_GROW_DOWNWARD
     619              :                            - crtl->args.size
     620              : #endif
     621              :                            - stack_boundary;
     622              : #endif
     623              :             }
     624              :           else
     625              :             {
     626              :               /* We assume that accesses are safe to at least the
     627              :                  next stack boundary.
     628              :                  Examples are varargs and __builtin_return_address.  */
     629              : #if ARGS_GROW_DOWNWARD
     630              :               high_bound = FIRST_PARM_OFFSET (current_function_decl)
     631              :                            + stack_boundary;
     632              :               low_bound  = FIRST_PARM_OFFSET (current_function_decl)
     633              :                            - crtl->args.size - stack_boundary;
     634              : #else
     635        87954 :               low_bound  = FIRST_PARM_OFFSET (current_function_decl)
     636        87954 :                            - stack_boundary;
     637        87954 :               high_bound = FIRST_PARM_OFFSET (current_function_decl)
     638        87954 :                            + crtl->args.size + stack_boundary;
     639              : #endif
     640              :             }
     641              : 
     642    244217991 :           if (known_ge (offset, low_bound)
     643    244217991 :               && known_le (offset, high_bound - size))
     644              :             return false;
     645              :           return true;
     646              :         }
     647              :       /* All of the virtual frame registers are stack references.  */
     648    160306406 :       if (VIRTUAL_REGISTER_P (x))
     649              :         return false;
     650              :       return true;
     651              : 
     652       368508 :     case CONST:
     653       368508 :       return rtx_addr_can_trap_p_1 (XEXP (x, 0), offset, size,
     654       368508 :                                     mode, unaligned_mems);
     655              : 
     656    175325136 :     case PLUS:
     657              :       /* An address is assumed not to trap if:
     658              :          - it is the pic register plus a const unspec without offset.  */
     659    175325136 :       if (XEXP (x, 0) == pic_offset_table_rtx
     660        39054 :           && GET_CODE (XEXP (x, 1)) == CONST
     661        39021 :           && GET_CODE (XEXP (XEXP (x, 1), 0)) == UNSPEC
     662    175360835 :           && known_eq (offset, 0))
     663              :         return false;
     664              : 
     665              :       /* - or it is an address that can't trap plus a constant integer.  */
     666    175289437 :       if (poly_int_rtx_p (XEXP (x, 1), &const_x1)
     667    147643078 :           && !rtx_addr_can_trap_p_1 (XEXP (x, 0), offset + const_x1,
     668              :                                      size, mode, unaligned_mems))
     669              :         return false;
     670              : 
     671              :       return true;
     672              : 
     673       415559 :     case LO_SUM:
     674       415559 :     case PRE_MODIFY:
     675       415559 :       return rtx_addr_can_trap_p_1 (XEXP (x, 1), offset, size,
     676       415559 :                                     mode, unaligned_mems);
     677              : 
     678    196335391 :     case PRE_DEC:
     679    196335391 :     case PRE_INC:
     680    196335391 :     case POST_DEC:
     681    196335391 :     case POST_INC:
     682    196335391 :     case POST_MODIFY:
     683    196335391 :       return rtx_addr_can_trap_p_1 (XEXP (x, 0), offset, size,
     684    196335391 :                                     mode, unaligned_mems);
     685              : 
     686              :     default:
     687              :       break;
     688              :     }
     689              : 
     690              :   /* If it isn't one of the case above, it can cause a trap.  */
     691              :   return true;
     692              : }
     693              : 
     694              : /* Return true if the use of X as an address in a MEM can cause a trap.  */
     695              : 
     696              : bool
     697     13480982 : rtx_addr_can_trap_p (const_rtx x)
     698              : {
     699     13480982 :   return rtx_addr_can_trap_p_1 (x, 0, -1, BLKmode, false);
     700              : }
     701              : 
     702              : /* Return true if X contains a MEM subrtx.  */
     703              : 
     704              : bool
     705     23270409 : contains_mem_rtx_p (rtx x)
     706              : {
     707     23270409 :   subrtx_iterator::array_type array;
     708     73474383 :   FOR_EACH_SUBRTX (iter, array, x, ALL)
     709     57616047 :     if (MEM_P (*iter))
     710      7412073 :       return true;
     711              : 
     712     15858336 :   return false;
     713     23270409 : }
     714              : 
     715              : /* Return true if X is an address that is known to not be zero.  */
     716              : 
     717              : bool
     718     58156868 : nonzero_address_p (const_rtx x)
     719              : {
     720     58159282 :   const enum rtx_code code = GET_CODE (x);
     721              : 
     722     58159282 :   switch (code)
     723              :     {
     724         3775 :     case SYMBOL_REF:
     725         3775 :       return flag_delete_null_pointer_checks && !SYMBOL_REF_WEAK (x);
     726              : 
     727              :     case LABEL_REF:
     728              :       return true;
     729              : 
     730     27545440 :     case REG:
     731              :       /* As in rtx_varies_p, we have to use the actual rtx, not reg number.  */
     732     27545440 :       if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
     733     27545377 :           || x == stack_pointer_rtx
     734     27545377 :           || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM]))
     735              :         return true;
     736              :       /* All of the virtual frame registers are stack references.  */
     737     27545369 :       if (VIRTUAL_REGISTER_P (x))
     738              :         return true;
     739              :       return false;
     740              : 
     741         2414 :     case CONST:
     742         2414 :       return nonzero_address_p (XEXP (x, 0));
     743              : 
     744     12925826 :     case PLUS:
     745              :       /* Handle PIC references.  */
     746     12925826 :       if (XEXP (x, 0) == pic_offset_table_rtx
     747            0 :                && CONSTANT_P (XEXP (x, 1)))
     748              :         return true;
     749              :       return false;
     750              : 
     751            0 :     case PRE_MODIFY:
     752              :       /* Similar to the above; allow positive offsets.  Further, since
     753              :          auto-inc is only allowed in memories, the register must be a
     754              :          pointer.  */
     755            0 :       if (CONST_INT_P (XEXP (x, 1))
     756            0 :           && INTVAL (XEXP (x, 1)) > 0)
     757              :         return true;
     758            0 :       return nonzero_address_p (XEXP (x, 0));
     759              : 
     760              :     case PRE_INC:
     761              :       /* Similarly.  Further, the offset is always positive.  */
     762              :       return true;
     763              : 
     764            0 :     case PRE_DEC:
     765            0 :     case POST_DEC:
     766            0 :     case POST_INC:
     767            0 :     case POST_MODIFY:
     768            0 :       return nonzero_address_p (XEXP (x, 0));
     769              : 
     770            0 :     case LO_SUM:
     771            0 :       return nonzero_address_p (XEXP (x, 1));
     772              : 
     773              :     default:
     774              :       break;
     775              :     }
     776              : 
     777              :   /* If it isn't one of the case above, might be zero.  */
     778              :   return false;
     779              : }
     780              : 
     781              : /* Return true if X refers to a memory location whose address
     782              :    cannot be compared reliably with constant addresses,
     783              :    or if X refers to a BLKmode memory object.
     784              :    FOR_ALIAS is nonzero if we are called from alias analysis; if it is
     785              :    zero, we are slightly more conservative.  */
     786              : 
     787              : bool
     788            0 : rtx_addr_varies_p (const_rtx x, bool for_alias)
     789              : {
     790            0 :   enum rtx_code code;
     791            0 :   int i;
     792            0 :   const char *fmt;
     793              : 
     794            0 :   if (x == 0)
     795              :     return false;
     796              : 
     797            0 :   code = GET_CODE (x);
     798            0 :   if (code == MEM)
     799            0 :     return GET_MODE (x) == BLKmode || rtx_varies_p (XEXP (x, 0), for_alias);
     800              : 
     801            0 :   fmt = GET_RTX_FORMAT (code);
     802            0 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
     803            0 :     if (fmt[i] == 'e')
     804              :       {
     805            0 :         if (rtx_addr_varies_p (XEXP (x, i), for_alias))
     806              :           return true;
     807              :       }
     808            0 :     else if (fmt[i] == 'E')
     809              :       {
     810              :         int j;
     811            0 :         for (j = 0; j < XVECLEN (x, i); j++)
     812            0 :           if (rtx_addr_varies_p (XVECEXP (x, i, j), for_alias))
     813              :             return true;
     814              :       }
     815              :   return false;
     816              : }
     817              : 
     818              : /* Get the declaration of the function called by INSN.  */
     819              : 
     820              : tree
     821    325672272 : get_call_fndecl (const rtx_insn *insn)
     822              : {
     823    325672272 :   rtx note, datum;
     824              : 
     825    325672272 :   note = find_reg_note (insn, REG_CALL_DECL, NULL_RTX);
     826    325672272 :   if (note == NULL_RTX)
     827              :     return NULL_TREE;
     828              : 
     829    322158841 :   datum = XEXP (note, 0);
     830    322158841 :   if (datum != NULL_RTX)
     831    310807020 :     return SYMBOL_REF_DECL (datum);
     832              : 
     833              :   return NULL_TREE;
     834              : }
     835              : 
     836              : /* Return the value of the integer term in X, if one is apparent;
     837              :    otherwise return 0.
     838              :    Only obvious integer terms are detected.
     839              :    This is used in cse.cc with the `related_value' field.  */
     840              : 
     841              : HOST_WIDE_INT
     842       454882 : get_integer_term (const_rtx x)
     843              : {
     844       454882 :   if (GET_CODE (x) == CONST)
     845       255271 :     x = XEXP (x, 0);
     846              : 
     847       454882 :   if (GET_CODE (x) == MINUS
     848            0 :       && CONST_INT_P (XEXP (x, 1)))
     849            0 :     return - INTVAL (XEXP (x, 1));
     850       454882 :   if (GET_CODE (x) == PLUS
     851       255271 :       && CONST_INT_P (XEXP (x, 1)))
     852       255271 :     return INTVAL (XEXP (x, 1));
     853              :   return 0;
     854              : }
     855              : 
     856              : /* If X is a constant, return the value sans apparent integer term;
     857              :    otherwise return 0.
     858              :    Only obvious integer terms are detected.  */
     859              : 
     860              : rtx
     861      1453239 : get_related_value (const_rtx x)
     862              : {
     863      1453239 :   if (GET_CODE (x) != CONST)
     864              :     return 0;
     865      1453239 :   x = XEXP (x, 0);
     866      1453239 :   if (GET_CODE (x) == PLUS
     867      1425569 :       && CONST_INT_P (XEXP (x, 1)))
     868      1425569 :     return XEXP (x, 0);
     869        27670 :   else if (GET_CODE (x) == MINUS
     870            0 :            && CONST_INT_P (XEXP (x, 1)))
     871            0 :     return XEXP (x, 0);
     872              :   return 0;
     873              : }
     874              : 
     875              : /* Return true if SYMBOL is a SYMBOL_REF and OFFSET + SYMBOL points
     876              :    to somewhere in the same object or object_block as SYMBOL.  */
     877              : 
     878              : bool
     879            0 : offset_within_block_p (const_rtx symbol, HOST_WIDE_INT offset)
     880              : {
     881            0 :   tree decl;
     882              : 
     883            0 :   if (GET_CODE (symbol) != SYMBOL_REF)
     884              :     return false;
     885              : 
     886            0 :   if (offset == 0)
     887              :     return true;
     888              : 
     889            0 :   if (offset > 0)
     890              :     {
     891            0 :       if (CONSTANT_POOL_ADDRESS_P (symbol)
     892            0 :           && offset < (int) GET_MODE_SIZE (get_pool_mode (symbol)))
     893            0 :         return true;
     894              : 
     895            0 :       decl = SYMBOL_REF_DECL (symbol);
     896            0 :       if (decl && offset < int_size_in_bytes (TREE_TYPE (decl)))
     897              :         return true;
     898              :     }
     899              : 
     900            0 :   if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol)
     901            0 :       && SYMBOL_REF_BLOCK (symbol)
     902            0 :       && SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0
     903            0 :       && ((unsigned HOST_WIDE_INT) offset + SYMBOL_REF_BLOCK_OFFSET (symbol)
     904            0 :           < (unsigned HOST_WIDE_INT) SYMBOL_REF_BLOCK (symbol)->size))
     905            0 :     return true;
     906              : 
     907              :   return false;
     908              : }
     909              : 
     910              : /* Split X into a base and a constant offset, storing them in *BASE_OUT
     911              :    and *OFFSET_OUT respectively.  */
     912              : 
     913              : void
     914            0 : split_const (rtx x, rtx *base_out, rtx *offset_out)
     915              : {
     916            0 :   if (GET_CODE (x) == CONST)
     917              :     {
     918            0 :       x = XEXP (x, 0);
     919            0 :       if (GET_CODE (x) == PLUS && CONST_INT_P (XEXP (x, 1)))
     920              :         {
     921            0 :           *base_out = XEXP (x, 0);
     922            0 :           *offset_out = XEXP (x, 1);
     923            0 :           return;
     924              :         }
     925              :     }
     926            0 :   *base_out = x;
     927            0 :   *offset_out = const0_rtx;
     928              : }
     929              : 
     930              : /* Express integer value X as some value Y plus a polynomial offset,
     931              :    where Y is either const0_rtx, X or something within X (as opposed
     932              :    to a new rtx).  Return the Y and store the offset in *OFFSET_OUT.  */
     933              : 
     934              : rtx
     935    427168264 : strip_offset (rtx x, poly_int64 *offset_out)
     936              : {
     937    427168264 :   rtx base = const0_rtx;
     938    427168264 :   rtx test = x;
     939    427168264 :   if (GET_CODE (test) == CONST)
     940     10018644 :     test = XEXP (test, 0);
     941    427168264 :   if (GET_CODE (test) == PLUS)
     942              :     {
     943    322791766 :       base = XEXP (test, 0);
     944    322791766 :       test = XEXP (test, 1);
     945              :     }
     946    427168264 :   if (poly_int_rtx_p (test, offset_out))
     947    303002207 :     return base;
     948              :   *offset_out = 0;
     949              :   return x;
     950              : }
     951              : 
     952              : /* Return the argument size in REG_ARGS_SIZE note X.  */
     953              : 
     954              : poly_int64
     955      5351455 : get_args_size (const_rtx x)
     956              : {
     957      5351455 :   gcc_checking_assert (REG_NOTE_KIND (x) == REG_ARGS_SIZE);
     958      5351455 :   return rtx_to_poly_int64 (XEXP (x, 0));
     959              : }
     960              : 
     961              : /* Return the number of places FIND appears within X.  If COUNT_DEST is
     962              :    zero, we do not count occurrences inside the destination of a SET.  */
     963              : 
     964              : int
     965      8870215 : count_occurrences (const_rtx x, const_rtx find, int count_dest)
     966              : {
     967      8870215 :   int i, j;
     968      8870215 :   enum rtx_code code;
     969      8870215 :   const char *format_ptr;
     970      8870215 :   int count;
     971              : 
     972      8870215 :   if (x == find)
     973              :     return 1;
     974              : 
     975      6465748 :   code = GET_CODE (x);
     976              : 
     977      6465748 :   switch (code)
     978              :     {
     979              :     case REG:
     980              :     CASE_CONST_ANY:
     981              :     case SYMBOL_REF:
     982              :     case CODE_LABEL:
     983              :     case PC:
     984              :       return 0;
     985              : 
     986            0 :     case EXPR_LIST:
     987            0 :       count = count_occurrences (XEXP (x, 0), find, count_dest);
     988            0 :       if (XEXP (x, 1))
     989            0 :         count += count_occurrences (XEXP (x, 1), find, count_dest);
     990              :       return count;
     991              : 
     992        76654 :     case MEM:
     993        76654 :       if (MEM_P (find) && rtx_equal_p (x, find))
     994              :         return 1;
     995              :       break;
     996              : 
     997            0 :     case SET:
     998            0 :       if (SET_DEST (x) == find && ! count_dest)
     999            0 :         return count_occurrences (SET_SRC (x), find, count_dest);
    1000              :       break;
    1001              : 
    1002              :     default:
    1003              :       break;
    1004              :     }
    1005              : 
    1006      3288186 :   format_ptr = GET_RTX_FORMAT (code);
    1007      3288186 :   count = 0;
    1008              : 
    1009      9722017 :   for (i = 0; i < GET_RTX_LENGTH (code); i++)
    1010              :     {
    1011      6433831 :       switch (*format_ptr++)
    1012              :         {
    1013      6260238 :         case 'e':
    1014      6260238 :           count += count_occurrences (XEXP (x, i), find, count_dest);
    1015      6260238 :           break;
    1016              : 
    1017              :         case 'E':
    1018       143400 :           for (j = 0; j < XVECLEN (x, i); j++)
    1019       119138 :             count += count_occurrences (XVECEXP (x, i, j), find, count_dest);
    1020              :           break;
    1021              :         }
    1022              :     }
    1023              :   return count;
    1024              : }
    1025              : 
    1026              : 
    1027              : /* Return TRUE if OP is a register or subreg of a register that
    1028              :    holds an unsigned quantity.  Otherwise, return FALSE.  */
    1029              : 
    1030              : bool
    1031            0 : unsigned_reg_p (rtx op)
    1032              : {
    1033            0 :   if (REG_P (op)
    1034            0 :       && REG_EXPR (op)
    1035            0 :       && TYPE_UNSIGNED (TREE_TYPE (REG_EXPR (op))))
    1036              :     return true;
    1037              : 
    1038            0 :   if (GET_CODE (op) == SUBREG
    1039            0 :       && SUBREG_PROMOTED_SIGN (op))
    1040            0 :     return true;
    1041              : 
    1042              :   return false;
    1043              : }
    1044              : 
    1045              : 
    1046              : /* Return true if register REG appears somewhere within IN.
    1047              :    Also works if REG is not a register; in this case it checks
    1048              :    for a subexpression of IN that is Lisp "equal" to REG.  */
    1049              : 
    1050              : bool
    1051    383765532 : reg_mentioned_p (const_rtx reg, const_rtx in)
    1052              : {
    1053    383765532 :   const char *fmt;
    1054    383765532 :   int i;
    1055    383765532 :   enum rtx_code code;
    1056              : 
    1057    383765532 :   if (in == 0)
    1058              :     return false;
    1059              : 
    1060    378417463 :   if (reg == in)
    1061              :     return true;
    1062              : 
    1063    365935996 :   if (GET_CODE (in) == LABEL_REF)
    1064      6739576 :     return reg == label_ref_label (in);
    1065              : 
    1066    359196420 :   code = GET_CODE (in);
    1067              : 
    1068    359196420 :   switch (code)
    1069              :     {
    1070              :       /* Compare registers by number.  */
    1071    134128862 :     case REG:
    1072    134128862 :       return REG_P (reg) && REGNO (in) == REGNO (reg);
    1073              : 
    1074              :       /* These codes have no constituent expressions
    1075              :          and are unique.  */
    1076              :     case SCRATCH:
    1077              :     case PC:
    1078              :       return false;
    1079              : 
    1080              :     CASE_CONST_ANY:
    1081              :       /* These are kept unique for a given value.  */
    1082              :       return false;
    1083              : 
    1084    138995656 :     default:
    1085    138995656 :       break;
    1086              :     }
    1087              : 
    1088    138995656 :   if (GET_CODE (reg) == code && rtx_equal_p (reg, in))
    1089              :     return true;
    1090              : 
    1091    138826102 :   fmt = GET_RTX_FORMAT (code);
    1092              : 
    1093    385271405 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    1094              :     {
    1095    265078644 :       if (fmt[i] == 'E')
    1096              :         {
    1097      3799624 :           int j;
    1098     11975268 :           for (j = XVECLEN (in, i) - 1; j >= 0; j--)
    1099      8815150 :             if (reg_mentioned_p (reg, XVECEXP (in, i, j)))
    1100              :               return true;
    1101              :         }
    1102    261279020 :       else if (fmt[i] == 'e'
    1103    261279020 :                && reg_mentioned_p (reg, XEXP (in, i)))
    1104              :         return true;
    1105              :     }
    1106              :   return false;
    1107              : }
    1108              : 
    1109              : /* Return true if in between BEG and END, exclusive of BEG and END, there is
    1110              :    no CODE_LABEL insn.  */
    1111              : 
    1112              : bool
    1113            0 : no_labels_between_p (const rtx_insn *beg, const rtx_insn *end)
    1114              : {
    1115            0 :   rtx_insn *p;
    1116            0 :   if (beg == end)
    1117              :     return false;
    1118            0 :   for (p = NEXT_INSN (beg); p != end; p = NEXT_INSN (p))
    1119            0 :     if (LABEL_P (p))
    1120              :       return false;
    1121              :   return true;
    1122              : }
    1123              : 
    1124              : /* Return true if register REG is used in an insn between
    1125              :    FROM_INSN and TO_INSN (exclusive of those two).  */
    1126              : 
    1127              : bool
    1128     24816621 : reg_used_between_p (const_rtx reg, const rtx_insn *from_insn,
    1129              :                     const rtx_insn *to_insn)
    1130              : {
    1131     24816621 :   rtx_insn *insn;
    1132              : 
    1133     24816621 :   if (from_insn == to_insn)
    1134              :     return false;
    1135              : 
    1136    187487465 :   for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
    1137    138266008 :     if (NONDEBUG_INSN_P (insn)
    1138    138266008 :         && (reg_overlap_mentioned_p (reg, PATTERN (insn))
    1139     75246269 :            || (CALL_P (insn) && find_reg_fusage (insn, USE, reg))))
    1140              :       return true;
    1141              :   return false;
    1142              : }
    1143              : 
    1144              : /* Return true if the old value of X, a register, is referenced in BODY.  If X
    1145              :    is entirely replaced by a new value and the only use is as a SET_DEST,
    1146              :    we do not consider it a reference.  */
    1147              : 
    1148              : bool
    1149    135113798 : reg_referenced_p (const_rtx x, const_rtx body)
    1150              : {
    1151    135113798 :   int i;
    1152              : 
    1153    135113798 :   switch (GET_CODE (body))
    1154              :     {
    1155    100239765 :     case SET:
    1156    100239765 :       if (reg_overlap_mentioned_p (x, SET_SRC (body)))
    1157              :         return true;
    1158              : 
    1159              :       /* If the destination is anything other than PC, a REG or a SUBREG
    1160              :          of a REG that occupies all of the REG, the insn references X if
    1161              :          it is mentioned in the destination.  */
    1162     64105367 :       if (GET_CODE (SET_DEST (body)) != PC
    1163     64105367 :           && !REG_P (SET_DEST (body))
    1164      2836938 :           && ! (GET_CODE (SET_DEST (body)) == SUBREG
    1165       532041 :                 && REG_P (SUBREG_REG (SET_DEST (body)))
    1166       532041 :                 && !read_modify_subreg_p (SET_DEST (body)))
    1167     66075727 :           && reg_overlap_mentioned_p (x, SET_DEST (body)))
    1168              :         return true;
    1169              :       return false;
    1170              : 
    1171         7024 :     case ASM_OPERANDS:
    1172        16270 :       for (i = ASM_OPERANDS_INPUT_LENGTH (body) - 1; i >= 0; i--)
    1173        14862 :         if (reg_overlap_mentioned_p (x, ASM_OPERANDS_INPUT (body, i)))
    1174              :           return true;
    1175              :       return false;
    1176              : 
    1177       446204 :     case CALL:
    1178       446204 :     case USE:
    1179       446204 :     case IF_THEN_ELSE:
    1180       446204 :       return reg_overlap_mentioned_p (x, body);
    1181              : 
    1182            0 :     case TRAP_IF:
    1183            0 :       return reg_overlap_mentioned_p (x, TRAP_CONDITION (body));
    1184              : 
    1185         2108 :     case PREFETCH:
    1186         2108 :       return reg_overlap_mentioned_p (x, XEXP (body, 0));
    1187              : 
    1188        27847 :     case UNSPEC:
    1189        27847 :     case UNSPEC_VOLATILE:
    1190        55860 :       for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
    1191        30164 :         if (reg_overlap_mentioned_p (x, XVECEXP (body, 0, i)))
    1192              :           return true;
    1193              :       return false;
    1194              : 
    1195     17639658 :     case PARALLEL:
    1196     50584508 :       for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
    1197     36380729 :         if (reg_referenced_p (x, XVECEXP (body, 0, i)))
    1198              :           return true;
    1199              :       return false;
    1200              : 
    1201     16746430 :     case CLOBBER:
    1202     16746430 :       if (MEM_P (XEXP (body, 0)))
    1203        13023 :         if (reg_overlap_mentioned_p (x, XEXP (XEXP (body, 0), 0)))
    1204              :           return true;
    1205              :       return false;
    1206              : 
    1207            0 :     case COND_EXEC:
    1208            0 :       if (reg_overlap_mentioned_p (x, COND_EXEC_TEST (body)))
    1209              :         return true;
    1210            0 :       return reg_referenced_p (x, COND_EXEC_CODE (body));
    1211              : 
    1212              :     default:
    1213              :       return false;
    1214              :     }
    1215              : }
    1216              : 
    1217              : /* Return true if register REG is set or clobbered in an insn between
    1218              :    FROM_INSN and TO_INSN (exclusive of those two).  */
    1219              : 
    1220              : bool
    1221     83156179 : reg_set_between_p (const_rtx reg, const rtx_insn *from_insn,
    1222              :                    const rtx_insn *to_insn)
    1223              : {
    1224     83156179 :   const rtx_insn *insn;
    1225              : 
    1226     83156179 :   if (from_insn == to_insn)
    1227              :     return false;
    1228              : 
    1229    375354488 :   for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
    1230    212737445 :     if (INSN_P (insn) && reg_set_p (reg, insn))
    1231              :       return true;
    1232              :   return false;
    1233              : }
    1234              : 
    1235              : /* Return true if REG is set or clobbered inside INSN.  */
    1236              : 
    1237              : bool
    1238   1242766521 : reg_set_p (const_rtx reg, const_rtx uncast_insn)
    1239              : {
    1240   1242766521 :   const rtx_insn *insn = dyn_cast <const rtx_insn *> (uncast_insn);
    1241   1236254416 :   if (!insn)
    1242      6512105 :     return set_of (reg, uncast_insn) != NULL_RTX;
    1243              : 
    1244              :   /* After delay slot handling, call and branch insns might be in a
    1245              :      sequence.  Check all the elements there.  */
    1246   1236254416 :   rtx_sequence *seq;
    1247   1236254416 :   if (INSN_P (insn)
    1248   1236254416 :       && (seq = dyn_cast <rtx_sequence *> (PATTERN (insn))))
    1249              :     {
    1250            0 :       for (int i = 0; i < seq->len (); ++i)
    1251            0 :         if (reg_set_p (reg, seq->element (i)))
    1252              :           return true;
    1253              : 
    1254              :       return false;
    1255              :     }
    1256              : 
    1257              :   /* We can be passed an insn or part of one.  If we are passed an insn,
    1258              :      check if a side-effect of the insn clobbers REG.  */
    1259   1236254416 :   auto call = dyn_cast<const rtx_call_insn *> (insn);
    1260   1236254416 :   if (INSN_P (insn)
    1261   1236254416 :       && (FIND_REG_INC_NOTE (insn, reg)
    1262              :           || (call
    1263     69435567 :               && ((REG_P (reg)
    1264     69435567 :                    && REGNO (reg) < FIRST_PSEUDO_REGISTER
    1265     65180261 :                    && (insn_callee_abi (call)
    1266     65180261 :                        .clobbers_reg_p (GET_MODE (reg), REGNO (reg))))
    1267     67859683 :                   || MEM_P (reg)
    1268     67859683 :                   || find_reg_fusage (insn, CLOBBER, reg)))))
    1269              :     return true;
    1270              : 
    1271              :   /* There are no REG_INC notes for SP autoinc.  */
    1272   1234678532 :   if (reg == stack_pointer_rtx && INSN_P (insn))
    1273              :     {
    1274      6654604 :       subrtx_var_iterator::array_type array;
    1275     54127921 :       FOR_EACH_SUBRTX_VAR (iter, array, PATTERN (insn), NONCONST)
    1276              :         {
    1277     48181275 :           rtx mem = *iter;
    1278     48181275 :           if (mem
    1279     48181275 :               && MEM_P (mem)
    1280      5393256 :               && GET_RTX_CLASS (GET_CODE (XEXP (mem, 0))) == RTX_AUTOINC)
    1281              :             {
    1282       707958 :               if (XEXP (XEXP (mem, 0), 0) == stack_pointer_rtx)
    1283       707958 :                 return true;
    1284            0 :               iter.skip_subrtxes ();
    1285              :             }
    1286              :         }
    1287      6654604 :     }
    1288              : 
    1289   1233970574 :   return set_of (reg, insn) != NULL_RTX;
    1290              : }
    1291              : 
    1292              : /* Similar to reg_set_between_p, but check all registers in X.  Return false
    1293              :    only if none of them are modified between START and END.  Return true if
    1294              :    X contains a MEM; this routine does use memory aliasing.  */
    1295              : 
    1296              : bool
    1297    214030833 : modified_between_p (const_rtx x, const rtx_insn *start, const rtx_insn *end)
    1298              : {
    1299    214030833 :   const enum rtx_code code = GET_CODE (x);
    1300    214030833 :   const char *fmt;
    1301    214030833 :   int i, j;
    1302    214030833 :   rtx_insn *insn;
    1303              : 
    1304    214030833 :   if (start == end)
    1305              :     return false;
    1306              : 
    1307    214030833 :   switch (code)
    1308              :     {
    1309              :     CASE_CONST_ANY:
    1310              :     case CONST:
    1311              :     case SYMBOL_REF:
    1312              :     case LABEL_REF:
    1313              :       return false;
    1314              : 
    1315              :     case PC:
    1316              :       return true;
    1317              : 
    1318     14616577 :     case MEM:
    1319     14616577 :       if (modified_between_p (XEXP (x, 0), start, end))
    1320              :         return true;
    1321     14605080 :       if (MEM_READONLY_P (x))
    1322              :         return false;
    1323     70934936 :       for (insn = NEXT_INSN (start); insn != end; insn = NEXT_INSN (insn))
    1324     42972453 :         if (memory_modified_in_insn_p (x, insn))
    1325              :           return true;
    1326              :       return false;
    1327              : 
    1328     79936795 :     case REG:
    1329     79936795 :       return reg_set_between_p (x, start, end);
    1330              : 
    1331     67916698 :     default:
    1332     67916698 :       break;
    1333              :     }
    1334              : 
    1335     67916698 :   fmt = GET_RTX_FORMAT (code);
    1336    200369545 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    1337              :     {
    1338    133979034 :       if (fmt[i] == 'e' && modified_between_p (XEXP (x, i), start, end))
    1339              :         return true;
    1340              : 
    1341    132453579 :       else if (fmt[i] == 'E')
    1342      3976038 :         for (j = XVECLEN (x, i) - 1; j >= 0; j--)
    1343      2873601 :           if (modified_between_p (XVECEXP (x, i, j), start, end))
    1344              :             return true;
    1345              :     }
    1346              : 
    1347              :   return false;
    1348              : }
    1349              : 
    1350              : /* Similar to reg_set_p, but check all registers in X.  Return false only if
    1351              :    none of them are modified in INSN.  Return true if X contains a MEM; this
    1352              :    routine does use memory aliasing.  */
    1353              : 
    1354              : bool
    1355   1149305904 : modified_in_p (const_rtx x, const_rtx insn)
    1356              : {
    1357   1149305904 :   const enum rtx_code code = GET_CODE (x);
    1358   1149305904 :   const char *fmt;
    1359   1149305904 :   int i, j;
    1360              : 
    1361   1149305904 :   switch (code)
    1362              :     {
    1363              :     CASE_CONST_ANY:
    1364              :     case CONST:
    1365              :     case SYMBOL_REF:
    1366              :     case LABEL_REF:
    1367              :       return false;
    1368              : 
    1369              :     case PC:
    1370              :       return true;
    1371              : 
    1372     11938995 :     case MEM:
    1373     11938995 :       if (modified_in_p (XEXP (x, 0), insn))
    1374              :         return true;
    1375     11892335 :       if (MEM_READONLY_P (x))
    1376              :         return false;
    1377     11630782 :       if (const rtx_insn *mem_insn = dyn_cast<const rtx_insn *> (insn))
    1378     11626128 :         if (memory_modified_in_insn_p (x, mem_insn))
    1379              :           return true;
    1380              :       return false;
    1381              : 
    1382    974401312 :     case REG:
    1383    974401312 :       return reg_set_p (x, insn);
    1384              : 
    1385     91438239 :     default:
    1386     91438239 :       break;
    1387              :     }
    1388              : 
    1389     91438239 :   fmt = GET_RTX_FORMAT (code);
    1390    264490928 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    1391              :     {
    1392    180154996 :       if (fmt[i] == 'e' && modified_in_p (XEXP (x, i), insn))
    1393              :         return true;
    1394              : 
    1395    173065122 :       else if (fmt[i] == 'E')
    1396      1378818 :         for (j = XVECLEN (x, i) - 1; j >= 0; j--)
    1397       715192 :           if (modified_in_p (XVECEXP (x, i, j), insn))
    1398              :             return true;
    1399              :     }
    1400              : 
    1401              :   return false;
    1402              : }
    1403              : 
    1404              : /* Return true if X is a SUBREG and if storing a value to X would
    1405              :    preserve some of its SUBREG_REG.  For example, on a normal 32-bit
    1406              :    target, using a SUBREG to store to one half of a DImode REG would
    1407              :    preserve the other half.  */
    1408              : 
    1409              : bool
    1410    147568575 : read_modify_subreg_p (const_rtx x)
    1411              : {
    1412    147568575 :   if (GET_CODE (x) != SUBREG)
    1413              :     return false;
    1414     51515054 :   poly_uint64 isize = GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)));
    1415     51515054 :   poly_uint64 osize = GET_MODE_SIZE (GET_MODE (x));
    1416     25757527 :   poly_uint64 regsize = REGMODE_NATURAL_SIZE (GET_MODE (SUBREG_REG (x)));
    1417              :   /* The inner and outer modes of a subreg must be ordered, so that we
    1418              :      can tell whether they're paradoxical or partial.  */
    1419     25757527 :   gcc_checking_assert (ordered_p (isize, osize));
    1420     25757527 :   return (maybe_gt (isize, osize) && maybe_gt (isize, regsize));
    1421              : }
    1422              : 
    1423              : /* Helper function for set_of.  */
    1424              : struct set_of_data
    1425              :   {
    1426              :     const_rtx found;
    1427              :     const_rtx pat;
    1428              :   };
    1429              : 
    1430              : static void
    1431   1323517466 : set_of_1 (rtx x, const_rtx pat, void *data1)
    1432              : {
    1433   1323517466 :   struct set_of_data *const data = (struct set_of_data *) (data1);
    1434   1323517466 :   if (rtx_equal_p (x, data->pat)
    1435   1323517466 :       || (!MEM_P (x) && reg_overlap_mentioned_p (data->pat, x)))
    1436     89026367 :     data->found = pat;
    1437   1323517466 : }
    1438              : 
    1439              : /* Give an INSN, return a SET or CLOBBER expression that does modify PAT
    1440              :    (either directly or via STRICT_LOW_PART and similar modifiers).  */
    1441              : const_rtx
    1442   1310796608 : set_of (const_rtx pat, const_rtx insn)
    1443              : {
    1444   1310796608 :   struct set_of_data data;
    1445   1310796608 :   data.found = NULL_RTX;
    1446   1310796608 :   data.pat = pat;
    1447   1310796608 :   note_pattern_stores (INSN_P (insn) ? PATTERN (insn) : insn, set_of_1, &data);
    1448   1310796608 :   return data.found;
    1449              : }
    1450              : 
    1451              : /* Check whether instruction pattern PAT contains a SET with the following
    1452              :    properties:
    1453              : 
    1454              :    - the SET is executed unconditionally; and
    1455              :    - either:
    1456              :      - the destination of the SET is a REG that contains REGNO; or
    1457              :      - both:
    1458              :        - the destination of the SET is a SUBREG of such a REG; and
    1459              :        - writing to the subreg clobbers all of the SUBREG_REG
    1460              :          (in other words, read_modify_subreg_p is false).
    1461              : 
    1462              :    If PAT does have a SET like that, return the set, otherwise return null.
    1463              : 
    1464              :    This is intended to be an alternative to single_set for passes that
    1465              :    can handle patterns with multiple_sets.  */
    1466              : rtx
    1467    144977686 : simple_regno_set (rtx pat, unsigned int regno)
    1468              : {
    1469    144977686 :   if (GET_CODE (pat) == PARALLEL)
    1470              :     {
    1471     24022698 :       int last = XVECLEN (pat, 0) - 1;
    1472     24226552 :       for (int i = 0; i < last; ++i)
    1473     24184144 :         if (rtx set = simple_regno_set (XVECEXP (pat, 0, i), regno))
    1474              :           return set;
    1475              : 
    1476        42408 :       pat = XVECEXP (pat, 0, last);
    1477              :     }
    1478              : 
    1479    120997396 :   if (GET_CODE (pat) == SET
    1480    120997396 :       && covers_regno_no_parallel_p (SET_DEST (pat), regno))
    1481    119262141 :     return pat;
    1482              : 
    1483              :   return nullptr;
    1484              : }
    1485              : 
    1486              : /* Add all hard register in X to *PSET.  */
    1487              : void
    1488      3965383 : find_all_hard_regs (const_rtx x, HARD_REG_SET *pset)
    1489              : {
    1490      3965383 :   subrtx_iterator::array_type array;
    1491     10753341 :   FOR_EACH_SUBRTX (iter, array, x, NONCONST)
    1492              :     {
    1493      6787958 :       const_rtx x = *iter;
    1494      6787958 :       if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
    1495      3363562 :         add_to_hard_reg_set (pset, GET_MODE (x), REGNO (x));
    1496              :     }
    1497      3965383 : }
    1498              : 
    1499              : /* This function, called through note_stores, collects sets and
    1500              :    clobbers of hard registers in a HARD_REG_SET, which is pointed to
    1501              :    by DATA.  */
    1502              : void
    1503     22395709 : record_hard_reg_sets (rtx x, const_rtx pat ATTRIBUTE_UNUSED, void *data)
    1504              : {
    1505     22395709 :   HARD_REG_SET *pset = (HARD_REG_SET *)data;
    1506     22395709 :   if (REG_P (x) && HARD_REGISTER_P (x))
    1507     14759570 :     add_to_hard_reg_set (pset, GET_MODE (x), REGNO (x));
    1508     22395709 : }
    1509              : 
    1510              : /* Examine INSN, and compute the set of hard registers written by it.
    1511              :    Store it in *PSET.  Should only be called after reload.
    1512              : 
    1513              :    IMPLICIT is true if we should include registers that are fully-clobbered
    1514              :    by calls.  This should be used with caution, since it doesn't include
    1515              :    partially-clobbered registers.  */
    1516              : void
    1517     17412786 : find_all_hard_reg_sets (const rtx_insn *insn, HARD_REG_SET *pset, bool implicit)
    1518              : {
    1519     17412786 :   rtx link;
    1520              : 
    1521     17412786 :   CLEAR_HARD_REG_SET (*pset);
    1522     17412786 :   note_stores (insn, record_hard_reg_sets, pset);
    1523     17412786 :   auto call = dyn_cast<const rtx_call_insn *> (insn);
    1524     17412786 :   if (call && implicit)
    1525            0 :     *pset |= insn_callee_abi (call).full_reg_clobbers ();
    1526     34131987 :   for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
    1527     16719201 :     if (REG_NOTE_KIND (link) == REG_INC)
    1528            0 :       record_hard_reg_sets (XEXP (link, 0), NULL, pset);
    1529     17412786 : }
    1530              : 
    1531              : /* Like record_hard_reg_sets, but called through note_uses.  */
    1532              : void
    1533      3965383 : record_hard_reg_uses (rtx *px, void *data)
    1534              : {
    1535      3965383 :   find_all_hard_regs (*px, (HARD_REG_SET *) data);
    1536      3965383 : }
    1537              : 
    1538              : /* Given an INSN, return a SET expression if this insn has only a single SET.
    1539              :    It may also have CLOBBERs, USEs, or SET whose output
    1540              :    will not be used, which we ignore.  */
    1541              : 
    1542              : rtx
    1543   1986372947 : single_set_2 (const rtx_insn *insn, const_rtx pat)
    1544              : {
    1545   1986372947 :   rtx set = NULL;
    1546   1986372947 :   int set_verified = 1;
    1547   1986372947 :   int i;
    1548              : 
    1549   1986372947 :   if (GET_CODE (pat) == PARALLEL)
    1550              :     {
    1551   2253577896 :       for (i = 0; i < XVECLEN (pat, 0); i++)
    1552              :         {
    1553   1533743964 :           rtx sub = XVECEXP (pat, 0, i);
    1554   1533743964 :           switch (GET_CODE (sub))
    1555              :             {
    1556              :             case USE:
    1557              :             case CLOBBER:
    1558   1495933110 :               break;
    1559              : 
    1560              :             default:
    1561     37810854 :               return NULL_RTX;
    1562              : 
    1563    774655870 :             case SET:
    1564              :               /* We can consider insns having multiple sets, where all
    1565              :                  but one are dead as single set insns.  In common case
    1566              :                  only single set is present in the pattern so we want
    1567              :                  to avoid checking for REG_UNUSED notes unless necessary.
    1568              : 
    1569              :                  When we reach set first time, we just expect this is
    1570              :                  the single set we are looking for and only when more
    1571              :                  sets are found in the insn, we check them.  */
    1572    833444214 :               auto unused = [] (const rtx_insn *insn, rtx dest) {
    1573     58788344 :                 if (!df)
    1574              :                   return false;
    1575     57901634 :                 if (df_note)
    1576     32487202 :                   return !!find_reg_note (insn, REG_UNUSED, dest);
    1577     25414432 :                 return (REG_P (dest)
    1578     23247164 :                         && !HARD_REGISTER_P (dest)
    1579      6502942 :                         && REGNO (dest) < df->regs_inited
    1580     31916489 :                         && DF_REG_USE_COUNT (REGNO (dest)) == 0);
    1581              :               };
    1582    774655870 :               if (!set_verified)
    1583              :                 {
    1584     31403265 :                   if (unused (insn, SET_DEST (set)) && !side_effects_p (set))
    1585              :                     set = NULL;
    1586              :                   else
    1587              :                     set_verified = 1;
    1588              :                 }
    1589    774655870 :               if (!set)
    1590              :                 set = sub, set_verified = 0;
    1591     27385079 :               else if (!unused (insn, SET_DEST (sub)) || side_effects_p (sub))
    1592              :                 return NULL_RTX;
    1593              :               break;
    1594              :             }
    1595              :         }
    1596              :     }
    1597              :   return set;
    1598              : }
    1599              : 
    1600              : /* Given an INSN, return true if it has more than one SET, else return
    1601              :    false.  */
    1602              : 
    1603              : bool
    1604    292987162 : multiple_sets (const rtx_insn *insn)
    1605              : {
    1606    292987162 :   bool found;
    1607    292987162 :   int i;
    1608              : 
    1609              :   /* INSN must be an insn.  */
    1610    292987162 :   if (! INSN_P (insn))
    1611              :     return false;
    1612              : 
    1613              :   /* Only a PARALLEL can have multiple SETs.  */
    1614    292987162 :   if (GET_CODE (PATTERN (insn)) == PARALLEL)
    1615              :     {
    1616    264956420 :       for (i = 0, found = false; i < XVECLEN (PATTERN (insn), 0); i++)
    1617    178581895 :         if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
    1618              :           {
    1619              :             /* If we have already found a SET, then return now.  */
    1620     90266260 :             if (found)
    1621              :               return true;
    1622              :             else
    1623              :               found = true;
    1624              :           }
    1625              :     }
    1626              : 
    1627              :   /* Either zero or one SET.  */
    1628              :   return false;
    1629              : }
    1630              : 
    1631              : /* Return true if the destination of SET equals the source
    1632              :    and there are no side effects.  */
    1633              : 
    1634              : bool
    1635   1718798282 : set_noop_p (const_rtx set)
    1636              : {
    1637   1718798282 :   rtx src = SET_SRC (set);
    1638   1718798282 :   rtx dst = SET_DEST (set);
    1639              : 
    1640   1718798282 :   if (dst == pc_rtx && src == pc_rtx)
    1641              :     return true;
    1642              : 
    1643   1718791134 :   if (MEM_P (dst) && MEM_P (src))
    1644      8976607 :     return (rtx_equal_p (dst, src)
    1645         4446 :             && !side_effects_p (dst)
    1646      8980914 :             && !side_effects_p (src));
    1647              : 
    1648   1709814527 :   if (GET_CODE (dst) == ZERO_EXTRACT)
    1649       101157 :     return (rtx_equal_p (XEXP (dst, 0), src)
    1650         6342 :             && !BITS_BIG_ENDIAN && XEXP (dst, 2) == const0_rtx
    1651            0 :             && !side_effects_p (src)
    1652       101157 :             && !side_effects_p (XEXP (dst, 0)));
    1653              : 
    1654   1709713370 :   if (GET_CODE (dst) == STRICT_LOW_PART)
    1655       253601 :     dst = XEXP (dst, 0);
    1656              : 
    1657   1709713370 :   if (GET_CODE (src) == SUBREG && GET_CODE (dst) == SUBREG)
    1658              :     {
    1659       842994 :       if (maybe_ne (SUBREG_BYTE (src), SUBREG_BYTE (dst)))
    1660              :         return false;
    1661       787658 :       src = SUBREG_REG (src);
    1662       787658 :       dst = SUBREG_REG (dst);
    1663       787658 :       if (GET_MODE (src) != GET_MODE (dst))
    1664              :         /* It is hard to tell whether subregs refer to the same bits, so act
    1665              :            conservatively and return false.  */
    1666              :         return false;
    1667              :     }
    1668              : 
    1669              :   /* It is a NOOP if destination overlaps with selected src vector
    1670              :      elements.  */
    1671   1709587945 :   if (GET_CODE (src) == VEC_SELECT
    1672      8203665 :       && REG_P (XEXP (src, 0)) && REG_P (dst)
    1673      2413089 :       && HARD_REGISTER_P (XEXP (src, 0))
    1674   1710139855 :       && HARD_REGISTER_P (dst))
    1675              :     {
    1676       551641 :       int i;
    1677       551641 :       rtx par = XEXP (src, 1);
    1678       551641 :       rtx src0 = XEXP (src, 0);
    1679       551641 :       poly_int64 c0;
    1680       551641 :       if (!poly_int_rtx_p (XVECEXP (par, 0, 0), &c0))
    1681              :         return false;
    1682      1103282 :       poly_int64 offset = GET_MODE_UNIT_SIZE (GET_MODE (src0)) * c0;
    1683              : 
    1684       890689 :       for (i = 1; i < XVECLEN (par, 0); i++)
    1685              :         {
    1686       596125 :           poly_int64 c0i;
    1687       596125 :           if (!poly_int_rtx_p (XVECEXP (par, 0, i), &c0i)
    1688       596125 :               || maybe_ne (c0i, c0 + i))
    1689   1718798282 :             return false;
    1690              :         }
    1691       294564 :       return
    1692       294564 :         REG_CAN_CHANGE_MODE_P (REGNO (dst), GET_MODE (src0), GET_MODE (dst))
    1693       294564 :         && validate_subreg (GET_MODE (dst), GET_MODE (src0), src0, offset)
    1694       691961 :         && simplify_subreg_regno (REGNO (src0), GET_MODE (src0),
    1695       117760 :                                   offset, GET_MODE (dst)) == (int) REGNO (dst);
    1696              :     }
    1697              : 
    1698    434105648 :   return (REG_P (src) && REG_P (dst)
    1699   1950441658 :           && REGNO (src) == REGNO (dst));
    1700              : }
    1701              : 
    1702              : /* Return true if an insn consists only of SETs, each of which only sets a
    1703              :    value to itself.  */
    1704              : 
    1705              : bool
    1706   1176666348 : noop_move_p (const rtx_insn *insn)
    1707              : {
    1708   1176666348 :   rtx pat = PATTERN (insn);
    1709              : 
    1710   1176666348 :   if (INSN_CODE (insn) == NOOP_MOVE_INSN_CODE)
    1711              :     return true;
    1712              : 
    1713              :   /* Check the code to be executed for COND_EXEC.  */
    1714   1176659975 :   if (GET_CODE (pat) == COND_EXEC)
    1715            0 :     pat = COND_EXEC_CODE (pat);
    1716              : 
    1717   1176659975 :   if (GET_CODE (pat) == SET && set_noop_p (pat))
    1718              :     return true;
    1719              : 
    1720   1176627924 :   if (GET_CODE (pat) == PARALLEL)
    1721              :     {
    1722              :       int i;
    1723              :       /* If nothing but SETs of registers to themselves,
    1724              :          this insn can also be deleted.  */
    1725    163330188 :       for (i = 0; i < XVECLEN (pat, 0); i++)
    1726              :         {
    1727    163330077 :           rtx tem = XVECEXP (pat, 0, i);
    1728              : 
    1729    163330077 :           if (GET_CODE (tem) == USE || GET_CODE (tem) == CLOBBER)
    1730        21418 :             continue;
    1731              : 
    1732    163308659 :           if (GET_CODE (tem) != SET || ! set_noop_p (tem))
    1733              :             return false;
    1734              :         }
    1735              : 
    1736              :       return true;
    1737              :     }
    1738              :   return false;
    1739              : }
    1740              : 
    1741              : 
    1742              : /* Return true if register in range [REGNO, ENDREGNO)
    1743              :    appears either explicitly or implicitly in X
    1744              :    other than being stored into.
    1745              : 
    1746              :    References contained within the substructure at LOC do not count.
    1747              :    LOC may be zero, meaning don't ignore anything.  */
    1748              : 
    1749              : bool
    1750   2338360017 : refers_to_regno_p (unsigned int regno, unsigned int endregno, const_rtx x,
    1751              :                    rtx *loc)
    1752              : {
    1753   3112691816 :   int i;
    1754   3112691816 :   unsigned int x_regno;
    1755   3112691816 :   RTX_CODE code;
    1756   3112691816 :   const char *fmt;
    1757              : 
    1758    774331799 :  repeat:
    1759              :   /* The contents of a REG_NONNEG note is always zero, so we must come here
    1760              :      upon repeat in case the last REG_NOTE is a REG_NONNEG note.  */
    1761   3112691816 :   if (x == 0)
    1762              :     return false;
    1763              : 
    1764   3112691808 :   code = GET_CODE (x);
    1765              : 
    1766   3112691808 :   switch (code)
    1767              :     {
    1768   1688513770 :     case REG:
    1769   1688513770 :       x_regno = REGNO (x);
    1770              : 
    1771              :       /* If we modifying the stack, frame, or argument pointer, it will
    1772              :          clobber a virtual register.  In fact, we could be more precise,
    1773              :          but it isn't worth it.  */
    1774   1688513770 :       if ((x_regno == STACK_POINTER_REGNUM
    1775   1688513770 :            || (FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
    1776   1688513770 :                && x_regno == ARG_POINTER_REGNUM)
    1777              :            || x_regno == FRAME_POINTER_REGNUM)
    1778    129274168 :           && VIRTUAL_REGISTER_NUM_P (regno))
    1779              :         return true;
    1780              : 
    1781   1688513768 :       return endregno > x_regno && regno < END_REGNO (x);
    1782              : 
    1783     36258690 :     case SUBREG:
    1784              :       /* If this is a SUBREG of a hard reg, we can see exactly which
    1785              :          registers are being modified.  Otherwise, handle normally.  */
    1786     36258690 :       if (REG_P (SUBREG_REG (x))
    1787     36258690 :           && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
    1788              :         {
    1789         1998 :           unsigned int inner_regno = subreg_regno (x);
    1790         1998 :           unsigned int inner_endregno
    1791              :             = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
    1792         1998 :                              ? subreg_nregs (x) : 1);
    1793              : 
    1794         1998 :           return endregno > inner_regno && regno < inner_endregno;
    1795              :         }
    1796              :       break;
    1797              : 
    1798    106843568 :     case CLOBBER:
    1799    106843568 :     case SET:
    1800    106843568 :       if (&SET_DEST (x) != loc
    1801              :           /* Note setting a SUBREG counts as referring to the REG it is in for
    1802              :              a pseudo but not for hard registers since we can
    1803              :              treat each word individually.  */
    1804    106843568 :           && ((GET_CODE (SET_DEST (x)) == SUBREG
    1805       978162 :                && loc != &SUBREG_REG (SET_DEST (x))
    1806       978162 :                && REG_P (SUBREG_REG (SET_DEST (x)))
    1807       978162 :                && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
    1808       978162 :                && refers_to_regno_p (regno, endregno,
    1809              :                                      SUBREG_REG (SET_DEST (x)), loc))
    1810    106820698 :               || (!REG_P (SET_DEST (x))
    1811     11868106 :                   && refers_to_regno_p (regno, endregno, SET_DEST (x), loc))))
    1812              :         return true;
    1813              : 
    1814    106709448 :       if (code == CLOBBER || loc == &SET_SRC (x))
    1815              :         return false;
    1816     88540549 :       x = SET_SRC (x);
    1817     88540549 :       goto repeat;
    1818              : 
    1819              :     default:
    1820              :       break;
    1821              :     }
    1822              : 
    1823              :   /* X does not match, so try its subexpressions.  */
    1824              : 
    1825   1317332472 :   fmt = GET_RTX_FORMAT (code);
    1826   2565603266 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    1827              :     {
    1828   1941606566 :       if (fmt[i] == 'e' && loc != &XEXP (x, i))
    1829              :         {
    1830   1191730182 :           if (i == 0)
    1831              :             {
    1832    685791250 :               x = XEXP (x, 0);
    1833    685791250 :               goto repeat;
    1834              :             }
    1835              :           else
    1836    505938932 :             if (refers_to_regno_p (regno, endregno, XEXP (x, i), loc))
    1837              :               return true;
    1838              :         }
    1839    749876384 :       else if (fmt[i] == 'E')
    1840              :         {
    1841     49053610 :           int j;
    1842    179621106 :           for (j = XVECLEN (x, i) - 1; j >= 0; j--)
    1843    132318874 :             if (loc != &XVECEXP (x, i, j)
    1844    132318874 :                 && refers_to_regno_p (regno, endregno, XVECEXP (x, i, j), loc))
    1845              :               return true;
    1846              :         }
    1847              :     }
    1848              :   return false;
    1849              : }
    1850              : 
    1851              : /* Rreturn true if modifying X will affect IN.  If X is a register or a SUBREG,
    1852              :    we check if any register number in X conflicts with the relevant register
    1853              :    numbers.  If X is a constant, return false.  If X is a MEM, return true iff
    1854              :    IN contains a MEM (we don't bother checking for memory addresses that can't
    1855              :    conflict because we expect this to be a rare case.  */
    1856              : 
    1857              : bool
    1858   1577924161 : reg_overlap_mentioned_p (const_rtx x, const_rtx in)
    1859              : {
    1860   1577924161 :   unsigned int regno, endregno;
    1861              : 
    1862              :   /* If either argument is a constant, then modifying X cannot
    1863              :      affect IN.  Here we look at IN, we can profitably combine
    1864              :      CONSTANT_P (x) with the switch statement below.  */
    1865   1577924161 :   if (CONSTANT_P (in))
    1866              :     return false;
    1867              : 
    1868   1547836286 :  recurse:
    1869   1547841241 :   switch (GET_CODE (x))
    1870              :     {
    1871         4955 :     case CLOBBER:
    1872         4955 :     case STRICT_LOW_PART:
    1873         4955 :     case ZERO_EXTRACT:
    1874         4955 :     case SIGN_EXTRACT:
    1875              :       /* Overly conservative.  */
    1876         4955 :       x = XEXP (x, 0);
    1877         4955 :       goto recurse;
    1878              : 
    1879      1656734 :     case SUBREG:
    1880      1656734 :       regno = REGNO (SUBREG_REG (x));
    1881      1656734 :       if (regno < FIRST_PSEUDO_REGISTER)
    1882            0 :         regno = subreg_regno (x);
    1883      1656734 :       endregno = regno + (regno < FIRST_PSEUDO_REGISTER
    1884            0 :                           ? subreg_nregs (x) : 1);
    1885      1656734 :       goto do_reg;
    1886              : 
    1887   1539514215 :     case REG:
    1888   1539514215 :       regno = REGNO (x);
    1889   1539514215 :       endregno = END_REGNO (x);
    1890   1541170949 :     do_reg:
    1891   1541170949 :       return refers_to_regno_p (regno, endregno, in, (rtx*) 0);
    1892              : 
    1893      1974700 :     case MEM:
    1894      1974700 :       {
    1895      1974700 :         const char *fmt;
    1896      1974700 :         int i;
    1897              : 
    1898      1974700 :         if (MEM_P (in))
    1899              :           return true;
    1900              : 
    1901      1832685 :         fmt = GET_RTX_FORMAT (GET_CODE (in));
    1902      3907908 :         for (i = GET_RTX_LENGTH (GET_CODE (in)) - 1; i >= 0; i--)
    1903      2129239 :           if (fmt[i] == 'e')
    1904              :             {
    1905       584718 :               if (reg_overlap_mentioned_p (x, XEXP (in, i)))
    1906              :                 return true;
    1907              :             }
    1908      1544521 :           else if (fmt[i] == 'E')
    1909              :             {
    1910        10609 :               int j;
    1911        48902 :               for (j = XVECLEN (in, i) - 1; j >= 0; --j)
    1912        39361 :                 if (reg_overlap_mentioned_p (x, XVECEXP (in, i, j)))
    1913              :                   return true;
    1914              :             }
    1915              : 
    1916              :         return false;
    1917              :       }
    1918              : 
    1919      1911132 :     case SCRATCH:
    1920      1911132 :     case PC:
    1921      1911132 :       return reg_mentioned_p (x, in);
    1922              : 
    1923          674 :     case PARALLEL:
    1924          674 :       {
    1925          674 :         int i;
    1926              : 
    1927              :         /* If any register in here refers to it we return true.  */
    1928         1216 :         for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
    1929         1084 :           if (XEXP (XVECEXP (x, 0, i), 0) != 0
    1930         1084 :               && reg_overlap_mentioned_p (XEXP (XVECEXP (x, 0, i), 0), in))
    1931              :             return true;
    1932              :         return false;
    1933              :       }
    1934              : 
    1935      2778831 :     default:
    1936      2778831 :       gcc_assert (CONSTANT_P (x));
    1937              :       return false;
    1938              :     }
    1939              : }
    1940              : 
    1941              : /* Call FUN on each register or MEM that is stored into or clobbered by X.
    1942              :    (X would be the pattern of an insn).  DATA is an arbitrary pointer,
    1943              :    ignored by note_stores, but passed to FUN.
    1944              : 
    1945              :    FUN receives three arguments:
    1946              :    1. the REG, MEM or PC being stored in or clobbered,
    1947              :    2. the SET or CLOBBER rtx that does the store,
    1948              :    3. the pointer DATA provided to note_stores.
    1949              : 
    1950              :   If the item being stored in or clobbered is a SUBREG of a hard register,
    1951              :   the SUBREG will be passed.  */
    1952              : 
    1953              : void
    1954   7320777100 : note_pattern_stores (const_rtx x,
    1955              :                      void (*fun) (rtx, const_rtx, void *), void *data)
    1956              : {
    1957   7320777100 :   int i;
    1958              : 
    1959   7320777100 :   if (GET_CODE (x) == COND_EXEC)
    1960            0 :     x = COND_EXEC_CODE (x);
    1961              : 
    1962   7320777100 :   if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER)
    1963              :     {
    1964   5361062142 :       rtx dest = SET_DEST (x);
    1965              : 
    1966   5361062142 :       while ((GET_CODE (dest) == SUBREG
    1967     22257503 :               && (!REG_P (SUBREG_REG (dest))
    1968     22257503 :                   || REGNO (SUBREG_REG (dest)) >= FIRST_PSEUDO_REGISTER))
    1969   5361963947 :              || GET_CODE (dest) == ZERO_EXTRACT
    1970  10745912796 :              || GET_CODE (dest) == STRICT_LOW_PART)
    1971     23137253 :         dest = XEXP (dest, 0);
    1972              : 
    1973              :       /* If we have a PARALLEL, SET_DEST is a list of EXPR_LIST expressions,
    1974              :          each of whose first operand is a register.  */
    1975   5361062142 :       if (GET_CODE (dest) == PARALLEL)
    1976              :         {
    1977      1563229 :           for (i = XVECLEN (dest, 0) - 1; i >= 0; i--)
    1978       993689 :             if (XEXP (XVECEXP (dest, 0, i), 0) != 0)
    1979       993689 :               (*fun) (XEXP (XVECEXP (dest, 0, i), 0), x, data);
    1980              :         }
    1981              :       else
    1982   5360492602 :         (*fun) (dest, x, data);
    1983              :     }
    1984              : 
    1985   1959714958 :   else if (GET_CODE (x) == PARALLEL)
    1986   2179471149 :     for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
    1987   1468570869 :       note_pattern_stores (XVECEXP (x, 0, i), fun, data);
    1988   7320777100 : }
    1989              : 
    1990              : /* Same, but for an instruction.  If the instruction is a call, include
    1991              :    any CLOBBERs in its CALL_INSN_FUNCTION_USAGE.  */
    1992              : 
    1993              : void
    1994   3504924489 : note_stores (const rtx_insn *insn,
    1995              :              void (*fun) (rtx, const_rtx, void *), void *data)
    1996              : {
    1997   3504924489 :   if (auto call = dyn_cast<const rtx_call_insn *> (insn))
    1998    170511736 :     for (rtx link = CALL_INSN_FUNCTION_USAGE (call);
    1999    509172463 :          link; link = XEXP (link, 1))
    2000    338660727 :       if (GET_CODE (XEXP (link, 0)) == CLOBBER)
    2001            0 :         note_pattern_stores (XEXP (link, 0), fun, data);
    2002   3504924489 :   note_pattern_stores (PATTERN (insn), fun, data);
    2003   3504924489 : }
    2004              : 
    2005              : /* Like notes_stores, but call FUN for each expression that is being
    2006              :    referenced in PBODY, a pointer to the PATTERN of an insn.  We only call
    2007              :    FUN for each expression, not any interior subexpressions.  FUN receives a
    2008              :    pointer to the expression and the DATA passed to this function.
    2009              : 
    2010              :    Note that this is not quite the same test as that done in reg_referenced_p
    2011              :    since that considers something as being referenced if it is being
    2012              :    partially set, while we do not.  */
    2013              : 
    2014              : void
    2015   1161363136 : note_uses (rtx *pbody, void (*fun) (rtx *, void *), void *data)
    2016              : {
    2017   1161363136 :   rtx body = *pbody;
    2018   1161363136 :   int i;
    2019              : 
    2020   1161363136 :   switch (GET_CODE (body))
    2021              :     {
    2022            0 :     case COND_EXEC:
    2023            0 :       (*fun) (&COND_EXEC_TEST (body), data);
    2024            0 :       note_uses (&COND_EXEC_CODE (body), fun, data);
    2025            0 :       return;
    2026              : 
    2027     88291484 :     case PARALLEL:
    2028    273282991 :       for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
    2029    184991507 :         note_uses (&XVECEXP (body, 0, i), fun, data);
    2030              :       return;
    2031              : 
    2032            0 :     case SEQUENCE:
    2033            0 :       for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
    2034            0 :         note_uses (&PATTERN (XVECEXP (body, 0, i)), fun, data);
    2035              :       return;
    2036              : 
    2037      5140779 :     case USE:
    2038      5140779 :       (*fun) (&XEXP (body, 0), data);
    2039      5140779 :       return;
    2040              : 
    2041       247094 :     case ASM_OPERANDS:
    2042       354352 :       for (i = ASM_OPERANDS_INPUT_LENGTH (body) - 1; i >= 0; i--)
    2043       107258 :         (*fun) (&ASM_OPERANDS_INPUT (body, i), data);
    2044              :       return;
    2045              : 
    2046       140797 :     case TRAP_IF:
    2047       140797 :       (*fun) (&TRAP_CONDITION (body), data);
    2048       140797 :       return;
    2049              : 
    2050        11015 :     case PREFETCH:
    2051        11015 :       (*fun) (&XEXP (body, 0), data);
    2052        11015 :       return;
    2053              : 
    2054      3243405 :     case UNSPEC:
    2055      3243405 :     case UNSPEC_VOLATILE:
    2056      6507324 :       for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
    2057      3263919 :         (*fun) (&XVECEXP (body, 0, i), data);
    2058              :       return;
    2059              : 
    2060     86149793 :     case CLOBBER:
    2061     86149793 :       if (MEM_P (XEXP (body, 0)))
    2062      3517871 :         (*fun) (&XEXP (XEXP (body, 0), 0), data);
    2063              :       return;
    2064              : 
    2065    564961967 :     case SET:
    2066    564961967 :       {
    2067    564961967 :         rtx dest = SET_DEST (body);
    2068              : 
    2069              :         /* For sets we replace everything in source plus registers in memory
    2070              :            expression in store and operands of a ZERO_EXTRACT.  */
    2071    564961967 :         (*fun) (&SET_SRC (body), data);
    2072              : 
    2073    564961967 :         if (GET_CODE (dest) == ZERO_EXTRACT)
    2074              :           {
    2075        30415 :             (*fun) (&XEXP (dest, 1), data);
    2076        30415 :             (*fun) (&XEXP (dest, 2), data);
    2077              :           }
    2078              : 
    2079    567268412 :         while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART)
    2080      2306445 :           dest = XEXP (dest, 0);
    2081              : 
    2082    564961967 :         if (MEM_P (dest))
    2083     97071993 :           (*fun) (&XEXP (dest, 0), data);
    2084              :       }
    2085              :       return;
    2086              : 
    2087    413176802 :     default:
    2088              :       /* All the other possibilities never store.  */
    2089    413176802 :       (*fun) (pbody, data);
    2090    413176802 :       return;
    2091              :     }
    2092              : }
    2093              : 
    2094              : /* Try to add a description of REG X to this object, stopping once
    2095              :    the REF_END limit has been reached.  FLAGS is a bitmask of
    2096              :    rtx_obj_reference flags that describe the context.  */
    2097              : 
    2098              : void
    2099    987574448 : rtx_properties::try_to_add_reg (const_rtx x, unsigned int flags)
    2100              : {
    2101    987574448 :   if (REG_NREGS (x) != 1)
    2102      3045670 :     flags |= rtx_obj_flags::IS_MULTIREG;
    2103    987574448 :   machine_mode mode = GET_MODE (x);
    2104    987574448 :   unsigned int start_regno = REGNO (x);
    2105    987574448 :   unsigned int end_regno = END_REGNO (x);
    2106   1978194566 :   for (unsigned int regno = start_regno; regno < end_regno; ++regno)
    2107    990620118 :     if (ref_iter != ref_end)
    2108    990470861 :       *ref_iter++ = rtx_obj_reference (regno, flags, mode,
    2109    990470861 :                                        regno - start_regno);
    2110    987574448 : }
    2111              : 
    2112              : /* Add a description of destination X to this object.  FLAGS is a bitmask
    2113              :    of rtx_obj_reference flags that describe the context.
    2114              : 
    2115              :    This routine accepts all rtxes that can legitimately appear in a
    2116              :    SET_DEST.  */
    2117              : 
    2118              : void
    2119    507785608 : rtx_properties::try_to_add_dest (const_rtx x, unsigned int flags)
    2120              : {
    2121              :   /* If we have a PARALLEL, SET_DEST is a list of EXPR_LIST expressions,
    2122              :      each of whose first operand is a register.  */
    2123    507785608 :   if (UNLIKELY (GET_CODE (x) == PARALLEL))
    2124              :     {
    2125       155347 :       for (int i = XVECLEN (x, 0) - 1; i >= 0; --i)
    2126        98038 :         if (rtx dest = XEXP (XVECEXP (x, 0, i), 0))
    2127        98038 :           try_to_add_dest (dest, flags);
    2128              :       return;
    2129              :     }
    2130              : 
    2131    507728299 :   unsigned int base_flags = flags & rtx_obj_flags::STICKY_FLAGS;
    2132    507728299 :   flags |= rtx_obj_flags::IS_WRITE;
    2133    509539191 :   for (;;)
    2134    509539191 :     if (GET_CODE (x) == ZERO_EXTRACT)
    2135              :       {
    2136        30599 :         try_to_add_src (XEXP (x, 1), base_flags);
    2137        30599 :         try_to_add_src (XEXP (x, 2), base_flags);
    2138        30599 :         flags |= rtx_obj_flags::IS_READ;
    2139        30599 :         x = XEXP (x, 0);
    2140              :       }
    2141    509508592 :     else if (GET_CODE (x) == STRICT_LOW_PART)
    2142              :       {
    2143        93782 :         flags |= rtx_obj_flags::IS_READ;
    2144        93782 :         x = XEXP (x, 0);
    2145              :       }
    2146    509414810 :     else if (GET_CODE (x) == SUBREG)
    2147              :       {
    2148      1686511 :         flags |= rtx_obj_flags::IN_SUBREG;
    2149      1686511 :         if (read_modify_subreg_p (x))
    2150       940675 :           flags |= rtx_obj_flags::IS_READ;
    2151      1686511 :         x = SUBREG_REG (x);
    2152              :       }
    2153              :     else
    2154              :       break;
    2155              : 
    2156    507728299 :   if (MEM_P (x))
    2157              :     {
    2158     74033528 :       if (ref_iter != ref_end)
    2159     74013568 :         *ref_iter++ = rtx_obj_reference (MEM_REGNO, flags, GET_MODE (x));
    2160              : 
    2161     74033528 :       unsigned int addr_flags = base_flags | rtx_obj_flags::IN_MEM_STORE;
    2162     74033528 :       if (flags & rtx_obj_flags::IS_READ)
    2163         4663 :         addr_flags |= rtx_obj_flags::IN_MEM_LOAD;
    2164     74033528 :       try_to_add_src (XEXP (x, 0), addr_flags);
    2165     74033528 :       return;
    2166              :     }
    2167              : 
    2168    433694771 :   if (LIKELY (REG_P (x)))
    2169              :     {
    2170    383343397 :       if (REGNO (x) == STACK_POINTER_REGNUM)
    2171              :         {
    2172              :           /* Stack accesses are dependent on previous allocations and
    2173              :              anti-dependent on later deallocations, so both types of
    2174              :              stack operation are akin to a memory write.  */
    2175     29904929 :           if (ref_iter != ref_end)
    2176     29904929 :             *ref_iter++ = rtx_obj_reference (MEM_REGNO, flags, BLKmode);
    2177              : 
    2178              :           /* We want to keep sp alive everywhere - by making all
    2179              :              writes to sp also use sp.  */
    2180     29904929 :           flags |= rtx_obj_flags::IS_READ;
    2181              :         }
    2182    383343397 :       try_to_add_reg (x, flags);
    2183    383343397 :       return;
    2184              :     }
    2185              : }
    2186              : 
    2187              : /* Try to add a description of source X to this object, stopping once
    2188              :    the REF_END limit has been reached.  FLAGS is a bitmask of
    2189              :    rtx_obj_reference flags that describe the context.
    2190              : 
    2191              :    This routine accepts all rtxes that can legitimately appear in a SET_SRC.  */
    2192              : 
    2193              : void
    2194   1131410719 : rtx_properties::try_to_add_src (const_rtx x, unsigned int flags)
    2195              : {
    2196   1131410719 :   unsigned int base_flags = flags & rtx_obj_flags::STICKY_FLAGS;
    2197   1131410719 :   subrtx_iterator::array_type array;
    2198   3574790320 :   FOR_EACH_SUBRTX (iter, array, x, NONCONST)
    2199              :     {
    2200   2443379601 :       const_rtx x = *iter;
    2201   2443379601 :       rtx_code code = GET_CODE (x);
    2202   2443379601 :       if (code == REG)
    2203    604231051 :         try_to_add_reg (x, flags | rtx_obj_flags::IS_READ);
    2204              :       else if (code == MEM)
    2205              :         {
    2206    132343713 :           if (MEM_VOLATILE_P (x))
    2207      3729135 :             has_volatile_refs = true;
    2208              : 
    2209    132343713 :           if (!MEM_READONLY_P (x) && ref_iter != ref_end)
    2210              :             {
    2211    126430326 :               auto mem_flags = flags | rtx_obj_flags::IS_READ;
    2212    126430326 :               *ref_iter++ = rtx_obj_reference (MEM_REGNO, mem_flags,
    2213    126430326 :                                                GET_MODE (x));
    2214              :             }
    2215              : 
    2216    132343713 :           try_to_add_src (XEXP (x, 0),
    2217              :                           base_flags | rtx_obj_flags::IN_MEM_LOAD);
    2218    132343713 :           iter.skip_subrtxes ();
    2219              :         }
    2220              :       else if (code == SUBREG)
    2221              :         {
    2222      8938630 :           try_to_add_src (SUBREG_REG (x), flags | rtx_obj_flags::IN_SUBREG);
    2223      8938630 :           iter.skip_subrtxes ();
    2224              :         }
    2225              :       else if (code == UNSPEC_VOLATILE)
    2226      3283323 :         has_volatile_refs = true;
    2227              :       else if (code == ASM_INPUT || code == ASM_OPERANDS)
    2228              :         {
    2229      1326280 :           has_asm = true;
    2230      1326280 :           if (MEM_VOLATILE_P (x))
    2231       430108 :             has_volatile_refs = true;
    2232              :         }
    2233              :       else if (code == PRE_INC
    2234              :                || code == PRE_DEC
    2235              :                || code == POST_INC
    2236              :                || code == POST_DEC
    2237              :                || code == PRE_MODIFY
    2238              :                || code == POST_MODIFY)
    2239              :         {
    2240     16164971 :           has_pre_post_modify = true;
    2241              : 
    2242     16164971 :           unsigned int addr_flags = (flags
    2243              :                                      | rtx_obj_flags::IS_PRE_POST_MODIFY
    2244              :                                      | rtx_obj_flags::IS_READ);
    2245     16164971 :           try_to_add_dest (XEXP (x, 0), addr_flags);
    2246     16164971 :           if (code == PRE_MODIFY || code == POST_MODIFY)
    2247       416227 :             iter.substitute (XEXP (XEXP (x, 1), 1));
    2248              :           else
    2249     15748744 :             iter.skip_subrtxes ();
    2250              :         }
    2251              :       else if (code == CALL)
    2252     32396855 :         has_call = true;
    2253              :     }
    2254   1131410719 : }
    2255              : 
    2256              : /* Try to add a description of instruction pattern PAT to this object,
    2257              :    stopping once the REF_END limit has been reached.  */
    2258              : 
    2259              : void
    2260    886896493 : rtx_properties::try_to_add_pattern (const_rtx pat)
    2261              : {
    2262    948871671 :   switch (GET_CODE (pat))
    2263              :     {
    2264            0 :     case COND_EXEC:
    2265            0 :       try_to_add_src (COND_EXEC_TEST (pat));
    2266            0 :       try_to_add_pattern (COND_EXEC_CODE (pat));
    2267            0 :       break;
    2268              : 
    2269     61975178 :     case PARALLEL:
    2270     61975178 :       {
    2271     61975178 :         int last = XVECLEN (pat, 0) - 1;
    2272    129664014 :         for (int i = 0; i < last; ++i)
    2273     67688836 :           try_to_add_pattern (XVECEXP (pat, 0, i));
    2274     61975178 :         try_to_add_pattern (XVECEXP (pat, 0, last));
    2275     61975178 :         break;
    2276              :       }
    2277              : 
    2278       205117 :     case ASM_OPERANDS:
    2279       286405 :       for (int i = 0, len = ASM_OPERANDS_INPUT_LENGTH (pat); i < len; ++i)
    2280        81288 :         try_to_add_src (ASM_OPERANDS_INPUT (pat, i));
    2281              :       break;
    2282              : 
    2283     62535303 :     case CLOBBER:
    2284     62535303 :       try_to_add_dest (XEXP (pat, 0), rtx_obj_flags::IS_CLOBBER);
    2285     62535303 :       break;
    2286              : 
    2287    428987296 :     case SET:
    2288    428987296 :       try_to_add_dest (SET_DEST (pat));
    2289    428987296 :       try_to_add_src (SET_SRC (pat));
    2290    428987296 :       break;
    2291              : 
    2292    395168777 :     default:
    2293              :       /* All the other possibilities never store and can use a normal
    2294              :          rtx walk.  This includes:
    2295              : 
    2296              :          - USE
    2297              :          - TRAP_IF
    2298              :          - PREFETCH
    2299              :          - UNSPEC
    2300              :          - UNSPEC_VOLATILE.  */
    2301    395168777 :       try_to_add_src (pat);
    2302    395168777 :       break;
    2303              :     }
    2304    886896493 : }
    2305              : 
    2306              : /* Try to add a description of INSN to this object, stopping once
    2307              :    the REF_END limit has been reached.  INCLUDE_NOTES is true if the
    2308              :    description should include REG_EQUAL and REG_EQUIV notes; all such
    2309              :    references will then be marked with rtx_obj_flags::IN_NOTE.
    2310              : 
    2311              :    For calls, this description includes all accesses in
    2312              :    CALL_INSN_FUNCTION_USAGE.  It also include all implicit accesses
    2313              :    to global registers by the target function.  However, it does not
    2314              :    include clobbers performed by the target function; callers that want
    2315              :    this information should instead use the function_abi interface.  */
    2316              : 
    2317              : void
    2318    801305846 : rtx_properties::try_to_add_insn (const rtx_insn *insn, bool include_notes)
    2319              : {
    2320    898446335 :   if (auto call = dyn_cast<const rtx_call_insn *> (insn))
    2321              :     {
    2322              :       /* Non-const functions can read from global registers.  Impure
    2323              :          functions can also set them.
    2324              : 
    2325              :          Adding the global registers first removes a situation in which
    2326              :          a fixed-form clobber of register R could come before a real set
    2327              :          of register R.  */
    2328     32380163 :       if (!hard_reg_set_empty_p (global_reg_set)
    2329     32380163 :           && !RTL_CONST_CALL_P (call))
    2330              :         {
    2331          597 :           unsigned int flags = rtx_obj_flags::IS_READ;
    2332          597 :           if (!RTL_PURE_CALL_P (call))
    2333          547 :             flags |= rtx_obj_flags::IS_WRITE;
    2334        56715 :           for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; ++regno)
    2335              :             /* As a special case, the stack pointer is invariant across calls
    2336              :                even if it has been marked global; see the corresponding
    2337              :                handling in df_get_call_refs.  */
    2338        56118 :             if (regno != STACK_POINTER_REGNUM
    2339        55521 :                 && global_regs[regno]
    2340          511 :                 && ref_iter != ref_end)
    2341          511 :               *ref_iter++ = rtx_obj_reference (regno, flags,
    2342          511 :                                                reg_raw_mode[regno], 0);
    2343              :         }
    2344              :       /* Untyped calls implicitly set all function value registers.
    2345              :          Again, we add them first in case the main pattern contains
    2346              :          a fixed-form clobber.  */
    2347     32380163 :       if (find_reg_note (call, REG_UNTYPED_CALL, NULL_RTX))
    2348       248425 :         for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; ++regno)
    2349       245810 :           if (targetm.calls.function_value_regno_p (regno)
    2350       245810 :               && ref_iter != ref_end)
    2351        15690 :             *ref_iter++ = rtx_obj_reference (regno, rtx_obj_flags::IS_WRITE,
    2352        15690 :                                              reg_raw_mode[regno], 0);
    2353     32380163 :       if (ref_iter != ref_end && !RTL_CONST_CALL_P (call))
    2354              :         {
    2355     31380063 :           auto mem_flags = rtx_obj_flags::IS_READ;
    2356     31380063 :           if (!RTL_PURE_CALL_P (call))
    2357     29420959 :             mem_flags |= rtx_obj_flags::IS_WRITE;
    2358     31380063 :           *ref_iter++ = rtx_obj_reference (MEM_REGNO, mem_flags, BLKmode);
    2359              :         }
    2360     32380163 :       try_to_add_pattern (PATTERN (call));
    2361     96554468 :       for (rtx link = CALL_INSN_FUNCTION_USAGE (call); link;
    2362     64174305 :            link = XEXP (link, 1))
    2363              :         {
    2364     64174305 :           rtx x = XEXP (link, 0);
    2365     64174305 :           if (GET_CODE (x) == CLOBBER)
    2366            0 :             try_to_add_dest (XEXP (x, 0), rtx_obj_flags::IS_CLOBBER);
    2367     64174305 :           else if (GET_CODE (x) == USE)
    2368     63688179 :             try_to_add_src (XEXP (x, 0));
    2369              :         }
    2370              :     }
    2371              :   else
    2372    768925683 :     try_to_add_pattern (PATTERN (insn));
    2373              : 
    2374    801305846 :   if (include_notes)
    2375   1203229334 :     for (rtx note = REG_NOTES (insn); note; note = XEXP (note, 1))
    2376    401924434 :       if (REG_NOTE_KIND (note) == REG_EQUAL
    2377    401924434 :           || REG_NOTE_KIND (note) == REG_EQUIV)
    2378     28108110 :         try_to_add_note (XEXP (note, 0));
    2379    801305846 : }
    2380              : 
    2381              : /* Grow the storage by a bit while keeping the contents of the first
    2382              :    START elements.  */
    2383              : 
    2384              : void
    2385        25481 : vec_rtx_properties_base::grow (ptrdiff_t start)
    2386              : {
    2387              :   /* The same heuristic that vec uses.  */
    2388        25481 :   ptrdiff_t new_elems = (ref_end - ref_begin) * 3 / 2;
    2389        25481 :   if (ref_begin == m_storage)
    2390              :     {
    2391        23491 :       ref_begin = XNEWVEC (rtx_obj_reference, new_elems);
    2392        23491 :       if (start)
    2393            0 :         memcpy (ref_begin, m_storage, start * sizeof (rtx_obj_reference));
    2394              :     }
    2395              :   else
    2396         1990 :     ref_begin = reinterpret_cast<rtx_obj_reference *>
    2397         1990 :       (xrealloc (ref_begin, new_elems * sizeof (rtx_obj_reference)));
    2398        25481 :   ref_iter = ref_begin + start;
    2399        25481 :   ref_end = ref_begin + new_elems;
    2400        25481 : }
    2401              : 
    2402              : /* Return true if X's old contents don't survive after INSN.
    2403              :    This will be true if X is a register and X dies in INSN or because
    2404              :    INSN entirely sets X.
    2405              : 
    2406              :    "Entirely set" means set directly and not through a SUBREG, or
    2407              :    ZERO_EXTRACT, so no trace of the old contents remains.
    2408              :    Likewise, REG_INC does not count.
    2409              : 
    2410              :    REG may be a hard or pseudo reg.  Renumbering is not taken into account,
    2411              :    but for this use that makes no difference, since regs don't overlap
    2412              :    during their lifetimes.  Therefore, this function may be used
    2413              :    at any time after deaths have been computed.
    2414              : 
    2415              :    If REG is a hard reg that occupies multiple machine registers, this
    2416              :    function will only return true if each of those registers will be replaced
    2417              :    by INSN.  */
    2418              : 
    2419              : bool
    2420    120322948 : dead_or_set_p (const rtx_insn *insn, const_rtx x)
    2421              : {
    2422    120322948 :   unsigned int regno, end_regno;
    2423    120322948 :   unsigned int i;
    2424              : 
    2425    120322948 :   gcc_assert (REG_P (x));
    2426              : 
    2427    120322948 :   regno = REGNO (x);
    2428    120322948 :   end_regno = END_REGNO (x);
    2429    213057038 :   for (i = regno; i < end_regno; i++)
    2430    120324058 :     if (! dead_or_set_regno_p (insn, i))
    2431              :       return false;
    2432              : 
    2433              :   return true;
    2434              : }
    2435              : 
    2436              : /* Return TRUE iff DEST is a register or subreg of a register, is a
    2437              :    complete rather than read-modify-write destination, and contains
    2438              :    register TEST_REGNO.  */
    2439              : 
    2440              : static bool
    2441    221743063 : covers_regno_no_parallel_p (const_rtx dest, unsigned int test_regno)
    2442              : {
    2443    221743063 :   unsigned int regno, endregno;
    2444              : 
    2445    221743063 :   if (GET_CODE (dest) == SUBREG && !read_modify_subreg_p (dest))
    2446       544402 :     dest = SUBREG_REG (dest);
    2447              : 
    2448    221743063 :   if (!REG_P (dest))
    2449              :     return false;
    2450              : 
    2451    212763049 :   regno = REGNO (dest);
    2452    212763049 :   endregno = END_REGNO (dest);
    2453    212763049 :   return (test_regno >= regno && test_regno < endregno);
    2454              : }
    2455              : 
    2456              : /* Like covers_regno_no_parallel_p, but also handles PARALLELs where
    2457              :    any member matches the covers_regno_no_parallel_p criteria.  */
    2458              : 
    2459              : static bool
    2460    100854549 : covers_regno_p (const_rtx dest, unsigned int test_regno)
    2461              : {
    2462    100854549 :   if (GET_CODE (dest) == PARALLEL)
    2463              :     {
    2464              :       /* Some targets place small structures in registers for return
    2465              :          values of functions, and those registers are wrapped in
    2466              :          PARALLELs that we may see as the destination of a SET.  */
    2467          336 :       int i;
    2468              : 
    2469          886 :       for (i = XVECLEN (dest, 0) - 1; i >= 0; i--)
    2470              :         {
    2471          550 :           rtx inner = XEXP (XVECEXP (dest, 0, i), 0);
    2472          550 :           if (inner != NULL_RTX
    2473          550 :               && covers_regno_no_parallel_p (inner, test_regno))
    2474              :             return true;
    2475              :         }
    2476              : 
    2477              :       return false;
    2478              :     }
    2479              :   else
    2480    100854213 :     return covers_regno_no_parallel_p (dest, test_regno);
    2481              : }
    2482              : 
    2483              : /* Utility function for dead_or_set_p to check an individual register. */
    2484              : 
    2485              : bool
    2486    122633138 : dead_or_set_regno_p (const rtx_insn *insn, unsigned int test_regno)
    2487              : {
    2488    122633138 :   const_rtx pattern;
    2489              : 
    2490              :   /* See if there is a death note for something that includes TEST_REGNO.  */
    2491    122633138 :   if (find_regno_note (insn, REG_DEAD, test_regno))
    2492              :     return true;
    2493              : 
    2494     79491415 :   if (CALL_P (insn)
    2495     79491415 :       && find_regno_fusage (insn, CLOBBER, test_regno))
    2496              :     return true;
    2497              : 
    2498     79491415 :   pattern = PATTERN (insn);
    2499              : 
    2500              :   /* If a COND_EXEC is not executed, the value survives.  */
    2501     79491415 :   if (GET_CODE (pattern) == COND_EXEC)
    2502              :     return false;
    2503              : 
    2504     79491415 :   if (GET_CODE (pattern) == SET || GET_CODE (pattern) == CLOBBER)
    2505     57766907 :     return covers_regno_p (SET_DEST (pattern), test_regno);
    2506     21724508 :   else if (GET_CODE (pattern) == PARALLEL)
    2507              :     {
    2508     21506352 :       int i;
    2509              : 
    2510     50048154 :       for (i = XVECLEN (pattern, 0) - 1; i >= 0; i--)
    2511              :         {
    2512     43362401 :           rtx body = XVECEXP (pattern, 0, i);
    2513              : 
    2514     43362401 :           if (GET_CODE (body) == COND_EXEC)
    2515            0 :             body = COND_EXEC_CODE (body);
    2516              : 
    2517     21805928 :           if ((GET_CODE (body) == SET || GET_CODE (body) == CLOBBER)
    2518     64893570 :               && covers_regno_p (SET_DEST (body), test_regno))
    2519              :             return true;
    2520              :         }
    2521              :     }
    2522              : 
    2523              :   return false;
    2524              : }
    2525              : 
    2526              : /* Return the reg-note of kind KIND in insn INSN, if there is one.
    2527              :    If DATUM is nonzero, look for one whose datum is DATUM.  */
    2528              : 
    2529              : rtx
    2530   8507001417 : find_reg_note (const rtx_insn *insn, enum reg_note kind, const_rtx datum)
    2531              : {
    2532   8507001417 :   rtx link;
    2533              : 
    2534   8507001417 :   gcc_checking_assert (insn);
    2535              : 
    2536              :   /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN.  */
    2537   8507001417 :   if (! INSN_P (insn))
    2538              :     return 0;
    2539   8388978538 :   if (datum == 0)
    2540              :     {
    2541  16654666481 :       for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
    2542   9900786014 :         if (REG_NOTE_KIND (link) == kind)
    2543              :           return link;
    2544              :       return 0;
    2545              :     }
    2546              : 
    2547    714770524 :   for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
    2548    410258307 :     if (REG_NOTE_KIND (link) == kind && datum == XEXP (link, 0))
    2549              :       return link;
    2550              :   return 0;
    2551              : }
    2552              : 
    2553              : /* Return the reg-note of kind KIND in insn INSN which applies to register
    2554              :    number REGNO, if any.  Return 0 if there is no such reg-note.  Note that
    2555              :    the REGNO of this NOTE need not be REGNO if REGNO is a hard register;
    2556              :    it might be the case that the note overlaps REGNO.  */
    2557              : 
    2558              : rtx
    2559    402321321 : find_regno_note (const rtx_insn *insn, enum reg_note kind, unsigned int regno)
    2560              : {
    2561    402321321 :   rtx link;
    2562              : 
    2563              :   /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN.  */
    2564    402321321 :   if (! INSN_P (insn))
    2565              :     return 0;
    2566              : 
    2567    597187984 :   for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
    2568    375860560 :     if (REG_NOTE_KIND (link) == kind
    2569              :         /* Verify that it is a register, so that scratch and MEM won't cause a
    2570              :            problem here.  */
    2571    264053138 :         && REG_P (XEXP (link, 0))
    2572    264053138 :         && REGNO (XEXP (link, 0)) <= regno
    2573    587583395 :         && END_REGNO (XEXP (link, 0)) > regno)
    2574              :       return link;
    2575              :   return 0;
    2576              : }
    2577              : 
    2578              : /* Return a REG_EQUIV or REG_EQUAL note if insn has only a single set and
    2579              :    has such a note.  */
    2580              : 
    2581              : rtx
    2582   1821332922 : find_reg_equal_equiv_note (const rtx_insn *insn)
    2583              : {
    2584   1821332922 :   rtx link;
    2585              : 
    2586   1821332922 :   if (!INSN_P (insn))
    2587              :     return 0;
    2588              : 
    2589   3138198358 :   for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
    2590   1420321774 :     if (REG_NOTE_KIND (link) == REG_EQUAL
    2591   1420321774 :         || REG_NOTE_KIND (link) == REG_EQUIV)
    2592              :       {
    2593              :         /* FIXME: We should never have REG_EQUAL/REG_EQUIV notes on
    2594              :            insns that have multiple sets.  Checking single_set to
    2595              :            make sure of this is not the proper check, as explained
    2596              :            in the comment in set_unique_reg_note.
    2597              : 
    2598              :            This should be changed into an assert.  */
    2599     97023558 :         if (GET_CODE (PATTERN (insn)) == PARALLEL
    2600     97023558 :             && multiple_sets (insn))
    2601              :           return 0;
    2602     97023558 :         return link;
    2603              :       }
    2604              :   return NULL;
    2605              : }
    2606              : 
    2607              : /* Check whether INSN is a single_set whose source is known to be
    2608              :    equivalent to a constant.  Return that constant if so, otherwise
    2609              :    return null.  */
    2610              : 
    2611              : rtx
    2612      2221624 : find_constant_src (const rtx_insn *insn)
    2613              : {
    2614      2221624 :   rtx note, set, x;
    2615              : 
    2616      2221624 :   set = single_set (insn);
    2617      2221624 :   if (set)
    2618              :     {
    2619      2221624 :       x = avoid_constant_pool_reference (SET_SRC (set));
    2620      2221624 :       if (CONSTANT_P (x))
    2621              :         return x;
    2622              :     }
    2623              : 
    2624      1564851 :   note = find_reg_equal_equiv_note (insn);
    2625      1564851 :   if (note && CONSTANT_P (XEXP (note, 0)))
    2626          613 :     return XEXP (note, 0);
    2627              : 
    2628              :   return NULL_RTX;
    2629              : }
    2630              : 
    2631              : /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found
    2632              :    in the CALL_INSN_FUNCTION_USAGE information of INSN.  */
    2633              : 
    2634              : bool
    2635     91295365 : find_reg_fusage (const rtx_insn *insn, enum rtx_code code, const_rtx datum)
    2636              : {
    2637              :   /* If it's not a CALL_INSN, it can't possibly have a
    2638              :      CALL_INSN_FUNCTION_USAGE field, so don't bother checking.  */
    2639     91295365 :   auto call = dyn_cast<const rtx_call_insn *> (insn);
    2640     91295365 :   if (!call)
    2641              :     return false;
    2642              : 
    2643     91295365 :   gcc_assert (datum);
    2644              : 
    2645     91295365 :   if (!REG_P (datum))
    2646              :     {
    2647        33359 :       rtx link;
    2648              : 
    2649        33359 :       for (link = CALL_INSN_FUNCTION_USAGE (call);
    2650        68972 :            link;
    2651        35613 :            link = XEXP (link, 1))
    2652        35613 :         if (GET_CODE (XEXP (link, 0)) == code
    2653        35613 :             && rtx_equal_p (datum, XEXP (XEXP (link, 0), 0)))
    2654              :           return true;
    2655              :     }
    2656              :   else
    2657              :     {
    2658     91262006 :       unsigned int regno = REGNO (datum);
    2659              : 
    2660              :       /* CALL_INSN_FUNCTION_USAGE information cannot contain references
    2661              :          to pseudo registers, so don't bother checking.  */
    2662              : 
    2663     91262006 :       if (regno < FIRST_PSEUDO_REGISTER)
    2664              :         {
    2665     84396750 :           unsigned int end_regno = END_REGNO (datum);
    2666     84396750 :           unsigned int i;
    2667              : 
    2668    148031794 :           for (i = regno; i < end_regno; i++)
    2669     84396750 :             if (find_regno_fusage (call, code, i))
    2670              :               return true;
    2671              :         }
    2672              :     }
    2673              : 
    2674              :   return false;
    2675              : }
    2676              : 
    2677              : /* Return true if REGNO, or any overlap of REGNO, of kind CODE is found
    2678              :    in the CALL_INSN_FUNCTION_USAGE information of INSN.  */
    2679              : 
    2680              : bool
    2681     84622621 : find_regno_fusage (const rtx_insn *insn, enum rtx_code code, unsigned int regno)
    2682              : {
    2683     84622621 :   rtx link;
    2684              : 
    2685              :   /* CALL_INSN_FUNCTION_USAGE information cannot contain references
    2686              :      to pseudo registers, so don't bother checking.  */
    2687              : 
    2688     84622621 :   auto call = dyn_cast<const rtx_call_insn *> (insn);
    2689     84622621 :   if (regno >= FIRST_PSEUDO_REGISTER || !call)
    2690              :     return false;
    2691              : 
    2692    240647277 :   for (link = CALL_INSN_FUNCTION_USAGE (call); link; link = XEXP (link, 1))
    2693              :     {
    2694    176843130 :       rtx op, reg;
    2695              : 
    2696    176843130 :       if (GET_CODE (op = XEXP (link, 0)) == code
    2697     47820982 :           && REG_P (reg = XEXP (op, 0))
    2698     47812350 :           && REGNO (reg) <= regno
    2699    211469173 :           && END_REGNO (reg) > regno)
    2700              :         return true;
    2701              :     }
    2702              : 
    2703              :   return false;
    2704              : }
    2705              : 
    2706              : 
    2707              : /* Return true if KIND is an integer REG_NOTE.  */
    2708              : 
    2709              : static bool
    2710            0 : int_reg_note_p (enum reg_note kind)
    2711              : {
    2712            0 :   return kind == REG_BR_PROB;
    2713              : }
    2714              : 
    2715              : /* Allocate a register note with kind KIND and datum DATUM.  LIST is
    2716              :    stored as the pointer to the next register note.  */
    2717              : 
    2718              : rtx
    2719    779513550 : alloc_reg_note (enum reg_note kind, rtx datum, rtx list)
    2720              : {
    2721    779513550 :   rtx note;
    2722              : 
    2723    779513550 :   gcc_checking_assert (!int_reg_note_p (kind));
    2724    779513550 :   switch (kind)
    2725              :     {
    2726        27242 :     case REG_LABEL_TARGET:
    2727        27242 :     case REG_LABEL_OPERAND:
    2728        27242 :     case REG_TM:
    2729              :       /* These types of register notes use an INSN_LIST rather than an
    2730              :          EXPR_LIST, so that copying is done right and dumps look
    2731              :          better.  */
    2732        27242 :       note = alloc_INSN_LIST (datum, list);
    2733        27242 :       PUT_REG_NOTE_KIND (note, kind);
    2734        27242 :       break;
    2735              : 
    2736    779486308 :     default:
    2737    779486308 :       note = alloc_EXPR_LIST (kind, datum, list);
    2738    779486308 :       break;
    2739              :     }
    2740              : 
    2741    779513550 :   return note;
    2742              : }
    2743              : 
    2744              : /* Add register note with kind KIND and datum DATUM to INSN.  */
    2745              : 
    2746              : void
    2747    772480946 : add_reg_note (rtx_insn *insn, enum reg_note kind, rtx datum)
    2748              : {
    2749    772480946 :   REG_NOTES (insn) = alloc_reg_note (kind, datum, REG_NOTES (insn));
    2750    772480946 : }
    2751              : 
    2752              : /* Add an integer register note with kind KIND and datum DATUM to INSN.  */
    2753              : 
    2754              : void
    2755      5350508 : add_int_reg_note (rtx_insn *insn, enum reg_note kind, int datum)
    2756              : {
    2757      5350508 :   gcc_checking_assert (int_reg_note_p (kind));
    2758      5350508 :   REG_NOTES (insn) = gen_rtx_INT_LIST ((machine_mode) kind,
    2759              :                                        datum, REG_NOTES (insn));
    2760      5350508 : }
    2761              : 
    2762              : /* Add a REG_ARGS_SIZE note to INSN with value VALUE.  */
    2763              : 
    2764              : void
    2765      5541238 : add_args_size_note (rtx_insn *insn, poly_int64 value)
    2766              : {
    2767      5541238 :   gcc_checking_assert (!find_reg_note (insn, REG_ARGS_SIZE, NULL_RTX));
    2768      9045627 :   add_reg_note (insn, REG_ARGS_SIZE, gen_int_mode (value, Pmode));
    2769      5541238 : }
    2770              : 
    2771              : /* Add a register note like NOTE to INSN.  */
    2772              : 
    2773              : void
    2774            0 : add_shallow_copy_of_reg_note (rtx_insn *insn, rtx note)
    2775              : {
    2776            0 :   if (GET_CODE (note) == INT_LIST)
    2777            0 :     add_int_reg_note (insn, REG_NOTE_KIND (note), XINT (note, 0));
    2778              :   else
    2779            0 :     add_reg_note (insn, REG_NOTE_KIND (note), XEXP (note, 0));
    2780            0 : }
    2781              : 
    2782              : /* Duplicate NOTE and return the copy.  */
    2783              : rtx
    2784      2314335 : duplicate_reg_note (rtx note)
    2785              : {
    2786      2314335 :   reg_note kind = REG_NOTE_KIND (note);
    2787              : 
    2788      2314335 :   if (GET_CODE (note) == INT_LIST)
    2789       314256 :     return gen_rtx_INT_LIST ((machine_mode) kind, XINT (note, 0), NULL_RTX);
    2790      2000079 :   else if (GET_CODE (note) == EXPR_LIST)
    2791      2000079 :     return alloc_reg_note (kind, copy_insn_1 (XEXP (note, 0)), NULL_RTX);
    2792              :   else
    2793            0 :     return alloc_reg_note (kind, XEXP (note, 0), NULL_RTX);
    2794              : }
    2795              : 
    2796              : /* Remove register note NOTE from the REG_NOTES of INSN.  */
    2797              : 
    2798              : void
    2799      8704583 : remove_note (rtx_insn *insn, const_rtx note)
    2800              : {
    2801      8704583 :   rtx link;
    2802              : 
    2803      8704583 :   if (note == NULL_RTX)
    2804              :     return;
    2805              : 
    2806      7856680 :   if (REG_NOTES (insn) == note)
    2807      7334905 :     REG_NOTES (insn) = XEXP (note, 1);
    2808              :   else
    2809      1011212 :     for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
    2810      1011212 :       if (XEXP (link, 1) == note)
    2811              :         {
    2812       521775 :           XEXP (link, 1) = XEXP (note, 1);
    2813       521775 :           break;
    2814              :         }
    2815              : 
    2816      7856680 :   switch (REG_NOTE_KIND (note))
    2817              :     {
    2818      2844696 :     case REG_EQUAL:
    2819      2844696 :     case REG_EQUIV:
    2820      2844696 :       df_notes_rescan (insn);
    2821      2844696 :       break;
    2822              :     default:
    2823              :       break;
    2824              :     }
    2825              : }
    2826              : 
    2827              : /* Remove REG_EQUAL and/or REG_EQUIV notes if INSN has such notes.
    2828              :    If NO_RESCAN is false and any notes were removed, call
    2829              :    df_notes_rescan.  Return true if any note has been removed.  */
    2830              : 
    2831              : bool
    2832        39573 : remove_reg_equal_equiv_notes (rtx_insn *insn, bool no_rescan)
    2833              : {
    2834        39573 :   rtx *loc;
    2835        39573 :   bool ret = false;
    2836              : 
    2837        39573 :   loc = &REG_NOTES (insn);
    2838        50890 :   while (*loc)
    2839              :     {
    2840        11317 :       enum reg_note kind = REG_NOTE_KIND (*loc);
    2841        11317 :       if (kind == REG_EQUAL || kind == REG_EQUIV)
    2842              :         {
    2843          375 :           *loc = XEXP (*loc, 1);
    2844          375 :           ret = true;
    2845              :         }
    2846              :       else
    2847        10942 :         loc = &XEXP (*loc, 1);
    2848              :     }
    2849        39573 :   if (ret && !no_rescan)
    2850          375 :     df_notes_rescan (insn);
    2851        39573 :   return ret;
    2852              : }
    2853              : 
    2854              : /* Remove all REG_EQUAL and REG_EQUIV notes referring to REGNO.  */
    2855              : 
    2856              : void
    2857      3821117 : remove_reg_equal_equiv_notes_for_regno (unsigned int regno)
    2858              : {
    2859      3821117 :   df_ref eq_use;
    2860              : 
    2861      3821117 :   if (!df)
    2862              :     return;
    2863              : 
    2864              :   /* This loop is a little tricky.  We cannot just go down the chain because
    2865              :      it is being modified by some actions in the loop.  So we just iterate
    2866              :      over the head.  We plan to drain the list anyway.  */
    2867      3945871 :   while ((eq_use = DF_REG_EQ_USE_CHAIN (regno)) != NULL)
    2868              :     {
    2869       124754 :       rtx_insn *insn = DF_REF_INSN (eq_use);
    2870       124754 :       rtx note = find_reg_equal_equiv_note (insn);
    2871              : 
    2872              :       /* This assert is generally triggered when someone deletes a REG_EQUAL
    2873              :          or REG_EQUIV note by hacking the list manually rather than calling
    2874              :          remove_note.  */
    2875       124754 :       gcc_assert (note);
    2876              : 
    2877       124754 :       remove_note (insn, note);
    2878              :     }
    2879              : }
    2880              : 
    2881              : /* Search LISTP (an EXPR_LIST) for an entry whose first operand is NODE and
    2882              :    return 1 if it is found.  A simple equality test is used to determine if
    2883              :    NODE matches.  */
    2884              : 
    2885              : bool
    2886           26 : in_insn_list_p (const rtx_insn_list *listp, const rtx_insn *node)
    2887              : {
    2888           26 :   const_rtx x;
    2889              : 
    2890           26 :   for (x = listp; x; x = XEXP (x, 1))
    2891            0 :     if (node == XEXP (x, 0))
    2892              :       return true;
    2893              : 
    2894              :   return false;
    2895              : }
    2896              : 
    2897              : /* Search LISTP (an INSN_LIST) for an entry whose first operand is NODE and
    2898              :    remove that entry from the list if it is found.
    2899              : 
    2900              :    A simple equality test is used to determine if NODE matches.  */
    2901              : 
    2902              : void
    2903      7840295 : remove_node_from_insn_list (const rtx_insn *node, rtx_insn_list **listp)
    2904              : {
    2905      7840295 :   rtx_insn_list *temp = *listp;
    2906      7840295 :   rtx_insn_list *prev = NULL;
    2907              : 
    2908      7856815 :   while (temp)
    2909              :     {
    2910        16546 :       if (node == temp->insn ())
    2911              :         {
    2912              :           /* Splice the node out of the list.  */
    2913           26 :           if (prev)
    2914            0 :             XEXP (prev, 1) = temp->next ();
    2915              :           else
    2916           26 :             *listp = temp->next ();
    2917              : 
    2918           26 :           gcc_checking_assert (!in_insn_list_p (temp->next (), node));
    2919              :           return;
    2920              :         }
    2921              : 
    2922        16520 :       prev = temp;
    2923        16520 :       temp = temp->next ();
    2924              :     }
    2925              : }
    2926              : 
    2927              : /* Return true if X contains any volatile instructions.  These are instructions
    2928              :    which may cause unpredictable machine state instructions, and thus no
    2929              :    instructions or register uses should be moved or combined across them.
    2930              :    This includes only volatile asms and UNSPEC_VOLATILE instructions.  */
    2931              : 
    2932              : bool
    2933    628881508 : volatile_insn_p (const_rtx x)
    2934              : {
    2935    628881508 :   const RTX_CODE code = GET_CODE (x);
    2936    628881508 :   switch (code)
    2937              :     {
    2938              :     case LABEL_REF:
    2939              :     case SYMBOL_REF:
    2940              :     case CONST:
    2941              :     CASE_CONST_ANY:
    2942              :     case PC:
    2943              :     case REG:
    2944              :     case SCRATCH:
    2945              :     case CLOBBER:
    2946              :     case ADDR_VEC:
    2947              :     case ADDR_DIFF_VEC:
    2948              :     case CALL:
    2949              :     case MEM:
    2950              :       return false;
    2951              : 
    2952              :     case UNSPEC_VOLATILE:
    2953              :       return true;
    2954              : 
    2955       130452 :     case ASM_INPUT:
    2956       130452 :     case ASM_OPERANDS:
    2957       130452 :       if (MEM_VOLATILE_P (x))
    2958              :         return true;
    2959              : 
    2960    275053252 :     default:
    2961    275053252 :       break;
    2962              :     }
    2963              : 
    2964              :   /* Recursively scan the operands of this expression.  */
    2965              : 
    2966    275053252 :   {
    2967    275053252 :     const char *const fmt = GET_RTX_FORMAT (code);
    2968    275053252 :     int i;
    2969              : 
    2970    765082651 :     for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    2971              :       {
    2972    490322700 :         if (fmt[i] == 'e')
    2973              :           {
    2974    408186916 :             if (volatile_insn_p (XEXP (x, i)))
    2975              :               return true;
    2976              :           }
    2977     82135784 :         else if (fmt[i] == 'E')
    2978              :           {
    2979              :             int j;
    2980     75551095 :             for (j = 0; j < XVECLEN (x, i); j++)
    2981     51931234 :               if (volatile_insn_p (XVECEXP (x, i, j)))
    2982              :                 return true;
    2983              :           }
    2984              :       }
    2985              :   }
    2986              :   return false;
    2987              : }
    2988              : 
    2989              : /* Return true if X contains any volatile memory references
    2990              :    UNSPEC_VOLATILE operations or volatile ASM_OPERANDS expressions.  */
    2991              : 
    2992              : bool
    2993   5320194240 : volatile_refs_p (const_rtx x)
    2994              : {
    2995   5320194240 :   const RTX_CODE code = GET_CODE (x);
    2996   5320194240 :   switch (code)
    2997              :     {
    2998              :     case LABEL_REF:
    2999              :     case SYMBOL_REF:
    3000              :     case CONST:
    3001              :     CASE_CONST_ANY:
    3002              :     case PC:
    3003              :     case REG:
    3004              :     case SCRATCH:
    3005              :     case CLOBBER:
    3006              :     case ADDR_VEC:
    3007              :     case ADDR_DIFF_VEC:
    3008              :       return false;
    3009              : 
    3010              :     case UNSPEC_VOLATILE:
    3011              :       return true;
    3012              : 
    3013    402046677 :     case MEM:
    3014    402046677 :     case ASM_INPUT:
    3015    402046677 :     case ASM_OPERANDS:
    3016    402046677 :       if (MEM_VOLATILE_P (x))
    3017              :         return true;
    3018              : 
    3019   2263074402 :     default:
    3020   2263074402 :       break;
    3021              :     }
    3022              : 
    3023              :   /* Recursively scan the operands of this expression.  */
    3024              : 
    3025   2263074402 :   {
    3026   2263074402 :     const char *const fmt = GET_RTX_FORMAT (code);
    3027   2263074402 :     int i;
    3028              : 
    3029   6653487800 :     for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    3030              :       {
    3031   4408062730 :         if (fmt[i] == 'e')
    3032              :           {
    3033   3921980285 :             if (volatile_refs_p (XEXP (x, i)))
    3034              :               return true;
    3035              :           }
    3036    486082445 :         else if (fmt[i] == 'E')
    3037              :           {
    3038              :             int j;
    3039    166743896 :             for (j = 0; j < XVECLEN (x, i); j++)
    3040    115594222 :               if (volatile_refs_p (XVECEXP (x, i, j)))
    3041              :                 return true;
    3042              :           }
    3043              :       }
    3044              :   }
    3045              :   return false;
    3046              : }
    3047              : 
    3048              : /* Similar to above, except that it also rejects register pre- and post-
    3049              :    incrementing.  */
    3050              : 
    3051              : bool
    3052   5461039033 : side_effects_p (const_rtx x)
    3053              : {
    3054   5461039033 :   const RTX_CODE code = GET_CODE (x);
    3055   5461039033 :   switch (code)
    3056              :     {
    3057              :     case LABEL_REF:
    3058              :     case SYMBOL_REF:
    3059              :     case CONST:
    3060              :     CASE_CONST_ANY:
    3061              :     case PC:
    3062              :     case REG:
    3063              :     case SCRATCH:
    3064              :     case ADDR_VEC:
    3065              :     case ADDR_DIFF_VEC:
    3066              :     case VAR_LOCATION:
    3067              :       return false;
    3068              : 
    3069     63278595 :     case CLOBBER:
    3070              :       /* Reject CLOBBER with a non-VOID mode.  These are made by combine.cc
    3071              :          when some combination can't be done.  If we see one, don't think
    3072              :          that we can simplify the expression.  */
    3073     63278595 :       return (GET_MODE (x) != VOIDmode);
    3074              : 
    3075              :     case PRE_INC:
    3076              :     case PRE_DEC:
    3077              :     case POST_INC:
    3078              :     case POST_DEC:
    3079              :     case PRE_MODIFY:
    3080              :     case POST_MODIFY:
    3081              :     case CALL:
    3082              :     case UNSPEC_VOLATILE:
    3083              :       return true;
    3084              : 
    3085    335005289 :     case MEM:
    3086    335005289 :     case ASM_INPUT:
    3087    335005289 :     case ASM_OPERANDS:
    3088    335005289 :       if (MEM_VOLATILE_P (x))
    3089              :         return true;
    3090              : 
    3091   1932874791 :     default:
    3092   1932874791 :       break;
    3093              :     }
    3094              : 
    3095              :   /* Recursively scan the operands of this expression.  */
    3096              : 
    3097   1932874791 :   {
    3098   1932874791 :     const char *fmt = GET_RTX_FORMAT (code);
    3099   1932874791 :     int i;
    3100              : 
    3101   5748076375 :     for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    3102              :       {
    3103   3866007813 :         if (fmt[i] == 'e')
    3104              :           {
    3105   3419363662 :             if (side_effects_p (XEXP (x, i)))
    3106              :               return true;
    3107              :           }
    3108    446644151 :         else if (fmt[i] == 'E')
    3109              :           {
    3110              :             int j;
    3111    241300146 :             for (j = 0; j < XVECLEN (x, i); j++)
    3112    163143245 :               if (side_effects_p (XVECEXP (x, i, j)))
    3113              :                 return true;
    3114              :           }
    3115              :       }
    3116              :   }
    3117              :   return false;
    3118              : }
    3119              : 
    3120              : /* Return true if evaluating rtx X might cause a trap.
    3121              :    FLAGS controls how to consider MEMs.  A true means the context
    3122              :    of the access may have changed from the original, such that the
    3123              :    address may have become invalid.  */
    3124              : 
    3125              : bool
    3126   9064082487 : may_trap_p_1 (const_rtx x, unsigned flags)
    3127              : {
    3128   9064082487 :   int i;
    3129   9064082487 :   enum rtx_code code;
    3130   9064082487 :   const char *fmt;
    3131              : 
    3132              :   /* We make no distinction currently, but this function is part of
    3133              :      the internal target-hooks ABI so we keep the parameter as
    3134              :      "unsigned flags".  */
    3135   9064082487 :   bool code_changed = flags != 0;
    3136              : 
    3137   9064082487 :   if (x == 0)
    3138              :     return false;
    3139   9064080606 :   code = GET_CODE (x);
    3140   9064080606 :   switch (code)
    3141              :     {
    3142              :       /* Handle these cases quickly.  */
    3143              :     CASE_CONST_ANY:
    3144              :     case SYMBOL_REF:
    3145              :     case LABEL_REF:
    3146              :     case CONST:
    3147              :     case PC:
    3148              :     case REG:
    3149              :     case SCRATCH:
    3150              :       return false;
    3151              : 
    3152      5922518 :     case UNSPEC:
    3153      5922518 :       return targetm.unspec_may_trap_p (x, flags);
    3154              : 
    3155              :     case UNSPEC_VOLATILE:
    3156              :     case ASM_INPUT:
    3157              :     case TRAP_IF:
    3158              :       return true;
    3159              : 
    3160       181677 :     case ASM_OPERANDS:
    3161       181677 :       return MEM_VOLATILE_P (x);
    3162              : 
    3163              :       /* Memory ref can trap unless it's a static var or a stack slot.  */
    3164   1070702764 :     case MEM:
    3165              :       /* Recognize specific pattern of stack checking probes.  */
    3166   1070702764 :       if (flag_stack_check
    3167         7717 :           && MEM_VOLATILE_P (x)
    3168   1070703560 :           && XEXP (x, 0) == stack_pointer_rtx)
    3169              :         return true;
    3170   1070701969 :       if (/* MEM_NOTRAP_P only relates to the actual position of the memory
    3171              :              reference; moving it out of context such as when moving code
    3172              :              when optimizing, might cause its address to become invalid.  */
    3173              :           code_changed
    3174   1070701969 :           || !MEM_NOTRAP_P (x))
    3175              :         {
    3176    525653426 :           poly_int64 size = MEM_SIZE_KNOWN_P (x) ? MEM_SIZE (x) : -1;
    3177    450977499 :           return rtx_addr_can_trap_p_1 (XEXP (x, 0), 0, size,
    3178    450977499 :                                         GET_MODE (x), code_changed);
    3179              :         }
    3180              : 
    3181              :       return false;
    3182              : 
    3183              :       /* Division by a non-constant might trap.  */
    3184      1066533 :     case DIV:
    3185      1066533 :     case MOD:
    3186      1066533 :     case UDIV:
    3187      1066533 :     case UMOD:
    3188      1066533 :       if (HONOR_SNANS (x))
    3189              :         return true;
    3190      1065858 :       if (FLOAT_MODE_P (GET_MODE (x)))
    3191       430881 :         return flag_trapping_math;
    3192       634977 :       if (!CONSTANT_P (XEXP (x, 1)) || (XEXP (x, 1) == const0_rtx))
    3193              :         return true;
    3194        82427 :       if (GET_CODE (XEXP (x, 1)) == CONST_VECTOR)
    3195              :         {
    3196              :           /* For CONST_VECTOR, return 1 if any element is or might be zero.  */
    3197            0 :           unsigned int n_elts;
    3198            0 :           rtx op = XEXP (x, 1);
    3199            0 :           if (!GET_MODE_NUNITS (GET_MODE (op)).is_constant (&n_elts))
    3200              :             {
    3201              :               if (!CONST_VECTOR_DUPLICATE_P (op))
    3202    294341734 :                 return true;
    3203              :               for (unsigned i = 0; i < (unsigned int) XVECLEN (op, 0); i++)
    3204              :                 if (CONST_VECTOR_ENCODED_ELT (op, i) == const0_rtx)
    3205              :                   return true;
    3206              :             }
    3207              :           else
    3208            0 :             for (unsigned i = 0; i < n_elts; i++)
    3209            0 :               if (CONST_VECTOR_ELT (op, i) == const0_rtx)
    3210              :                 return true;
    3211              :         }
    3212              :       break;
    3213              : 
    3214              :     case EXPR_LIST:
    3215              :       /* An EXPR_LIST is used to represent a function call.  This
    3216              :          certainly may trap.  */
    3217              :       return true;
    3218              : 
    3219    186432212 :     case GE:
    3220    186432212 :     case GT:
    3221    186432212 :     case LE:
    3222    186432212 :     case LT:
    3223    186432212 :     case LTGT:
    3224    186432212 :     case COMPARE:
    3225              :     /* Treat min/max similar as comparisons.  */
    3226    186432212 :     case SMIN:
    3227    186432212 :     case SMAX:
    3228              :       /* Some floating point comparisons may trap.  */
    3229    186432212 :       if (!flag_trapping_math)
    3230              :         break;
    3231              :       /* ??? There is no machine independent way to check for tests that trap
    3232              :          when COMPARE is used, though many targets do make this distinction.
    3233              :          For instance, sparc uses CCFPE for compares which generate exceptions
    3234              :          and CCFP for compares which do not generate exceptions.  */
    3235    184810602 :       if (HONOR_NANS (x))
    3236              :         return true;
    3237              :       /* But often the compare has some CC mode, so check operand
    3238              :          modes as well.  */
    3239    184782085 :       if (HONOR_NANS (XEXP (x, 0))
    3240    184782085 :           || HONOR_NANS (XEXP (x, 1)))
    3241              :         return true;
    3242              :       break;
    3243              : 
    3244     28993532 :     case EQ:
    3245     28993532 :     case NE:
    3246     28993532 :       if (HONOR_SNANS (x))
    3247              :         return true;
    3248              :       /* Often comparison is CC mode, so check operand modes.  */
    3249     28993515 :       if (HONOR_SNANS (XEXP (x, 0))
    3250     28993515 :           || HONOR_SNANS (XEXP (x, 1)))
    3251              :         return true;
    3252              :       break;
    3253              : 
    3254       369371 :     case FIX:
    3255       369371 :     case UNSIGNED_FIX:
    3256              :       /* Conversion of floating point might trap.  */
    3257       369371 :       if (flag_trapping_math && HONOR_NANS (XEXP (x, 0)))
    3258              :         return true;
    3259              :       break;
    3260              : 
    3261              :     case PARALLEL:
    3262              :     case NEG:
    3263              :     case ABS:
    3264              :     case SUBREG:
    3265              :     case VEC_MERGE:
    3266              :     case VEC_SELECT:
    3267              :     case VEC_CONCAT:
    3268              :     case VEC_DUPLICATE:
    3269              :       /* These operations don't trap even with floating point.  */
    3270              :       break;
    3271              : 
    3272   3085271176 :     default:
    3273              :       /* Any floating arithmetic may trap.  */
    3274   3085271176 :       if (FLOAT_MODE_P (GET_MODE (x)) && flag_trapping_math)
    3275              :         return true;
    3276              :     }
    3277              : 
    3278   3719299667 :   fmt = GET_RTX_FORMAT (code);
    3279  10013380278 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    3280              :     {
    3281   6544276927 :       if (fmt[i] == 'e')
    3282              :         {
    3283   6085949676 :           if (may_trap_p_1 (XEXP (x, i), flags))
    3284              :             return true;
    3285              :         }
    3286    458327251 :       else if (fmt[i] == 'E')
    3287              :         {
    3288              :           int j;
    3289    979206256 :           for (j = 0; j < XVECLEN (x, i); j++)
    3290    675375184 :             if (may_trap_p_1 (XVECEXP (x, i, j), flags))
    3291              :               return true;
    3292              :         }
    3293              :     }
    3294              :   return false;
    3295              : }
    3296              : 
    3297              : /* Return true if evaluating rtx X might cause a trap.  */
    3298              : 
    3299              : bool
    3300   2284357748 : may_trap_p (const_rtx x)
    3301              : {
    3302   2284357748 :   return may_trap_p_1 (x, 0);
    3303              : }
    3304              : 
    3305              : /* Same as above, but additionally return true if evaluating rtx X might
    3306              :    cause a fault.  We define a fault for the purpose of this function as a
    3307              :    erroneous execution condition that cannot be encountered during the normal
    3308              :    execution of a valid program; the typical example is an unaligned memory
    3309              :    access on a strict alignment machine.  The compiler guarantees that it
    3310              :    doesn't generate code that will fault from a valid program, but this
    3311              :    guarantee doesn't mean anything for individual instructions.  Consider
    3312              :    the following example:
    3313              : 
    3314              :       struct S { int d; union { char *cp; int *ip; }; };
    3315              : 
    3316              :       int foo(struct S *s)
    3317              :       {
    3318              :         if (s->d == 1)
    3319              :           return *s->ip;
    3320              :         else
    3321              :           return *s->cp;
    3322              :       }
    3323              : 
    3324              :    on a strict alignment machine.  In a valid program, foo will never be
    3325              :    invoked on a structure for which d is equal to 1 and the underlying
    3326              :    unique field of the union not aligned on a 4-byte boundary, but the
    3327              :    expression *s->ip might cause a fault if considered individually.
    3328              : 
    3329              :    At the RTL level, potentially problematic expressions will almost always
    3330              :    verify may_trap_p; for example, the above dereference can be emitted as
    3331              :    (mem:SI (reg:P)) and this expression is may_trap_p for a generic register.
    3332              :    However, suppose that foo is inlined in a caller that causes s->cp to
    3333              :    point to a local character variable and guarantees that s->d is not set
    3334              :    to 1; foo may have been effectively translated into pseudo-RTL as:
    3335              : 
    3336              :       if ((reg:SI) == 1)
    3337              :         (set (reg:SI) (mem:SI (%fp - 7)))
    3338              :       else
    3339              :         (set (reg:QI) (mem:QI (%fp - 7)))
    3340              : 
    3341              :    Now (mem:SI (%fp - 7)) is considered as not may_trap_p since it is a
    3342              :    memory reference to a stack slot, but it will certainly cause a fault
    3343              :    on a strict alignment machine.  */
    3344              : 
    3345              : bool
    3346     10943490 : may_trap_or_fault_p (const_rtx x)
    3347              : {
    3348     10943490 :   return may_trap_p_1 (x, 1);
    3349              : }
    3350              : 
    3351              : /* Replace any occurrence of FROM in X with TO.  The function does
    3352              :    not enter into CONST_DOUBLE for the replace.
    3353              : 
    3354              :    Note that copying is not done so X must not be shared unless all copies
    3355              :    are to be modified.
    3356              : 
    3357              :    ALL_REGS is true if we want to replace all REGs equal to FROM, not just
    3358              :    those pointer-equal ones.  */
    3359              : 
    3360              : rtx
    3361      8915575 : replace_rtx (rtx x, rtx from, rtx to, bool all_regs)
    3362              : {
    3363      8915575 :   int i, j;
    3364      8915575 :   const char *fmt;
    3365              : 
    3366      8915575 :   if (x == from)
    3367              :     return to;
    3368              : 
    3369              :   /* Allow this function to make replacements in EXPR_LISTs.  */
    3370      6477962 :   if (x == 0)
    3371              :     return 0;
    3372              : 
    3373      6477962 :   if (all_regs
    3374            0 :       && REG_P (x)
    3375            0 :       && REG_P (from)
    3376      6477962 :       && REGNO (x) == REGNO (from))
    3377              :     {
    3378            0 :       gcc_assert (GET_MODE (x) == GET_MODE (from));
    3379              :       return to;
    3380              :     }
    3381      6477962 :   else if (GET_CODE (x) == SUBREG)
    3382              :     {
    3383        56761 :       rtx new_rtx = replace_rtx (SUBREG_REG (x), from, to, all_regs);
    3384              : 
    3385        56761 :       if (CONST_SCALAR_INT_P (new_rtx))
    3386              :         {
    3387           14 :           x = simplify_subreg (GET_MODE (x), new_rtx,
    3388            7 :                                GET_MODE (SUBREG_REG (x)),
    3389            7 :                                SUBREG_BYTE (x));
    3390            7 :           gcc_assert (x);
    3391              :         }
    3392              :       else
    3393        56754 :         SUBREG_REG (x) = new_rtx;
    3394              : 
    3395              :       return x;
    3396              :     }
    3397      6421201 :   else if (GET_CODE (x) == ZERO_EXTEND)
    3398              :     {
    3399       200585 :       rtx new_rtx = replace_rtx (XEXP (x, 0), from, to, all_regs);
    3400              : 
    3401       200585 :       if (CONST_SCALAR_INT_P (new_rtx))
    3402              :         {
    3403           14 :           x = simplify_unary_operation (ZERO_EXTEND, GET_MODE (x),
    3404            7 :                                         new_rtx, GET_MODE (XEXP (x, 0)));
    3405            7 :           gcc_assert (x);
    3406              :         }
    3407              :       else
    3408       200578 :         XEXP (x, 0) = new_rtx;
    3409              : 
    3410              :       return x;
    3411              :     }
    3412              : 
    3413      6220616 :   fmt = GET_RTX_FORMAT (GET_CODE (x));
    3414     15426806 :   for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
    3415              :     {
    3416      9206190 :       if (fmt[i] == 'e')
    3417      6014207 :         XEXP (x, i) = replace_rtx (XEXP (x, i), from, to, all_regs);
    3418      3191983 :       else if (fmt[i] == 'E')
    3419       143536 :         for (j = XVECLEN (x, i) - 1; j >= 0; j--)
    3420       119256 :           XVECEXP (x, i, j) = replace_rtx (XVECEXP (x, i, j),
    3421              :                                            from, to, all_regs);
    3422              :     }
    3423              : 
    3424              :   return x;
    3425              : }
    3426              : 
    3427              : /* Replace occurrences of the OLD_LABEL in *LOC with NEW_LABEL.  Also track
    3428              :    the change in LABEL_NUSES if UPDATE_LABEL_NUSES.  */
    3429              : 
    3430              : void
    3431       565781 : replace_label (rtx *loc, rtx_insn *old_label, rtx_insn *new_label,
    3432              :                bool update_label_nuses)
    3433              : {
    3434              :   /* Handle jump tables specially, since ADDR_{DIFF_,}VECs can be long.  */
    3435       565781 :   rtx x = *loc;
    3436       565781 :   if (JUMP_TABLE_DATA_P (x))
    3437              :     {
    3438          750 :       x = PATTERN (x);
    3439          750 :       rtvec vec = XVEC (x, GET_CODE (x) == ADDR_DIFF_VEC);
    3440          750 :       int len = GET_NUM_ELEM (vec);
    3441        11378 :       for (int i = 0; i < len; ++i)
    3442              :         {
    3443        10628 :           rtx ref = RTVEC_ELT (vec, i);
    3444        10628 :           if (XEXP (ref, 0) == old_label)
    3445              :             {
    3446            0 :               XEXP (ref, 0) = new_label;
    3447            0 :               if (update_label_nuses)
    3448              :                 {
    3449            0 :                   ++LABEL_NUSES (new_label);
    3450            0 :                   --LABEL_NUSES (old_label);
    3451              :                 }
    3452              :             }
    3453              :         }
    3454          750 :       return;
    3455              :     }
    3456              : 
    3457              :   /* If this is a JUMP_INSN, then we also need to fix the JUMP_LABEL
    3458              :      field.  This is not handled by the iterator because it doesn't
    3459              :      handle unprinted ('0') fields.  */
    3460       565031 :   auto jump = dyn_cast<rtx_jump_insn *> (x);
    3461        31327 :   if (jump && JUMP_LABEL (jump) == old_label)
    3462          474 :     JUMP_LABEL (jump) = new_label;
    3463              : 
    3464       565031 :   subrtx_ptr_iterator::array_type array;
    3465      3620197 :   FOR_EACH_SUBRTX_PTR (iter, array, loc, ALL)
    3466              :     {
    3467      3055166 :       rtx *loc = *iter;
    3468      3055166 :       if (rtx x = *loc)
    3469              :         {
    3470      2580350 :           if (GET_CODE (x) == SYMBOL_REF
    3471      2580350 :               && CONSTANT_POOL_ADDRESS_P (x))
    3472              :             {
    3473         2496 :               rtx c = get_pool_constant (x);
    3474         2496 :               if (rtx_referenced_p (old_label, c))
    3475              :                 {
    3476              :                   /* Create a copy of constant C; replace the label inside
    3477              :                      but do not update LABEL_NUSES because uses in constant pool
    3478              :                      are not counted.  */
    3479            0 :                   rtx new_c = copy_rtx (c);
    3480            0 :                   replace_label (&new_c, old_label, new_label, false);
    3481              : 
    3482              :                   /* Add the new constant NEW_C to constant pool and replace
    3483              :                      the old reference to constant by new reference.  */
    3484            0 :                   rtx new_mem = force_const_mem (get_pool_mode (x), new_c);
    3485            0 :                   *loc = replace_rtx (x, x, XEXP (new_mem, 0));
    3486              :                 }
    3487              :             }
    3488              : 
    3489      2580350 :           if ((GET_CODE (x) == LABEL_REF
    3490      2548273 :                || GET_CODE (x) == INSN_LIST)
    3491        33016 :               && XEXP (x, 0) == old_label)
    3492              :             {
    3493         1230 :               XEXP (x, 0) = new_label;
    3494         1230 :               if (update_label_nuses)
    3495              :                 {
    3496            0 :                   ++LABEL_NUSES (new_label);
    3497            0 :                   --LABEL_NUSES (old_label);
    3498              :                 }
    3499              :             }
    3500              :         }
    3501              :     }
    3502       565031 : }
    3503              : 
    3504              : void
    3505       565781 : replace_label_in_insn (rtx_insn *insn, rtx_insn *old_label,
    3506              :                        rtx_insn *new_label, bool update_label_nuses)
    3507              : {
    3508       565781 :   rtx insn_as_rtx = insn;
    3509       565781 :   replace_label (&insn_as_rtx, old_label, new_label, update_label_nuses);
    3510       565781 :   gcc_checking_assert (insn_as_rtx == insn);
    3511       565781 : }
    3512              : 
    3513              : /* Return true if X is referenced in BODY.  */
    3514              : 
    3515              : bool
    3516       307105 : rtx_referenced_p (const_rtx x, const_rtx body)
    3517              : {
    3518       307105 :   subrtx_iterator::array_type array;
    3519      1450143 :   FOR_EACH_SUBRTX (iter, array, body, ALL)
    3520      1165746 :     if (const_rtx y = *iter)
    3521              :       {
    3522              :         /* Check if a label_ref Y refers to label X.  */
    3523      1163571 :         if (GET_CODE (y) == LABEL_REF
    3524         3946 :             && LABEL_P (x)
    3525      1167514 :             && label_ref_label (y) == x)
    3526        22708 :           return true;
    3527              : 
    3528      1163571 :         if (rtx_equal_p (x, y))
    3529              :           return true;
    3530              : 
    3531              :         /* If Y is a reference to pool constant traverse the constant.  */
    3532      1140863 :         if (GET_CODE (y) == SYMBOL_REF
    3533      1140863 :             && CONSTANT_POOL_ADDRESS_P (y))
    3534         7729 :           iter.substitute (get_pool_constant (y));
    3535              :       }
    3536       284397 :   return false;
    3537       307105 : }
    3538              : 
    3539              : /* If INSN is a tablejump return true and store the label (before jump table) to
    3540              :    *LABELP and the jump table to *TABLEP.  LABELP and TABLEP may be NULL.  */
    3541              : 
    3542              : bool
    3543   1674005700 : tablejump_p (const rtx_insn *insn, rtx_insn **labelp,
    3544              :              rtx_jump_table_data **tablep)
    3545              : {
    3546   1674005700 :   if (!JUMP_P (insn))
    3547              :     return false;
    3548              : 
    3549   1183410601 :   rtx target = JUMP_LABEL (insn);
    3550   1183410601 :   if (target == NULL_RTX || ANY_RETURN_P (target))
    3551              :     return false;
    3552              : 
    3553   1105418646 :   rtx_insn *label = as_a<rtx_insn *> (target);
    3554   1105418646 :   rtx_insn *table = next_insn (label);
    3555   1105418646 :   if (table == NULL_RTX || !JUMP_TABLE_DATA_P (table))
    3556              :     return false;
    3557              : 
    3558      1307924 :   if (labelp)
    3559       508917 :     *labelp = label;
    3560      1307924 :   if (tablep)
    3561       870981 :     *tablep = as_a <rtx_jump_table_data *> (table);
    3562              :   return true;
    3563              : }
    3564              : 
    3565              : /* Return true if INSN is a tablejump whose table is shared with other
    3566              :    jumps (JUMP_TABLE_SHARED_P).  Store the label and the table as
    3567              :    tablejump_p does.  */
    3568              : 
    3569              : bool
    3570   1107967848 : shared_tablejump_p (const rtx_insn *insn, rtx_insn **labelp,
    3571              :                     rtx_jump_table_data **tablep)
    3572              : {
    3573   1107967848 :   rtx_jump_table_data *table;
    3574   1107967848 :   if (!tablejump_p (insn, labelp, &table)
    3575   1107967848 :       || !JUMP_TABLE_SHARED_P (PATTERN (table)))
    3576              :     return false;
    3577              : 
    3578        52613 :   if (tablep)
    3579        52613 :     *tablep = table;
    3580              :   return true;
    3581              : }
    3582              : 
    3583              : /* Check the tablejump links in the current function's linear RTL chain.
    3584              :    This also works after the CFG has been released.  */
    3585              : 
    3586              : void
    3587     63331133 : verify_jump_tables (void)
    3588              : {
    3589     63331133 :   struct table_users
    3590              :   {
    3591              :     unsigned int total;
    3592              :     unsigned int repeatable;
    3593              :   };
    3594     63331133 :   hash_set<rtx_insn *> live;
    3595     63331133 :   hash_map<rtx_insn *, table_users> users;
    3596     63331133 :   auto_vec<rtx_jump_table_data *> tables;
    3597     63331133 :   auto_vec<rtx_insn *> jumps;
    3598              : 
    3599   8571542342 :   for (rtx_insn *insn = get_insns (); insn; insn = NEXT_INSN (insn))
    3600              :     {
    3601   8508211209 :       if (LABEL_P (insn) || JUMP_TABLE_DATA_P (insn))
    3602    306115157 :         live.add (insn);
    3603   8508211209 :       if (JUMP_TABLE_DATA_P (insn))
    3604              :         {
    3605       365685 :           tables.safe_push (as_a<rtx_jump_table_data *> (insn));
    3606       365685 :           users.put (insn, { 0, 0 });
    3607              :         }
    3608   8507845524 :       else if (JUMP_P (insn))
    3609    437904815 :         jumps.safe_push (insn);
    3610   8069940709 :       else if (NONDEBUG_INSN_P (insn))
    3611   8508211209 :         if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (PATTERN (insn)))
    3612            0 :           for (int i = 0; i < seq->len (); ++i)
    3613              :             {
    3614            0 :               rtx_insn *part = seq->insn (i);
    3615            0 :               if (JUMP_P (part))
    3616            0 :                 jumps.safe_push (part);
    3617              :             }
    3618              :     }
    3619              : 
    3620     64257688 :   for (rtx_jump_table_data *table : tables)
    3621              :     {
    3622       365685 :       rtx_insn *label = PREV_INSN (table);
    3623       365685 :       if (!label || !LABEL_P (label) || !live.contains (label)
    3624       731370 :           || NEXT_INSN (label) != table)
    3625            0 :         fatal_insn ("jump table has no adjacent live label", table);
    3626              :     }
    3627              : 
    3628    598388330 :   for (rtx_insn *jump : jumps)
    3629              :     {
    3630    437904815 :       rtx_insn *label = NULL;
    3631    437904815 :       if (tablejump_p (jump, &label, NULL)
    3632    437904815 :           && !reg_mentioned_p (label, PATTERN (jump)))
    3633            0 :         fatal_insn ("tablejump pattern does not reference its label", jump);
    3634              : 
    3635              :       /* A USE of a label identifies a tablejump even if its JUMP_LABEL
    3636              :          or table was lost.  Also find table references in casesi patterns.  */
    3637    763239823 :       bool indirect = (!any_uncondjump_p (jump) && !any_condjump_p (jump)
    3638    479314737 :                        && !returnjump_p (jump));
    3639    437904815 :       subrtx_iterator::array_type array;
    3640   3097610303 :       FOR_EACH_SUBRTX (iter, array, PATTERN (jump), ALL)
    3641              :         {
    3642   2659705488 :           const_rtx x = *iter;
    3643      4551389 :           bool table_use = (indirect && GET_CODE (x) == USE
    3644   2660113773 :                             && GET_CODE (XEXP (x, 0)) == LABEL_REF);
    3645   2659297203 :           if (table_use)
    3646              :             x = XEXP (x, 0);
    3647   2659297203 :           else if (GET_CODE (x) != LABEL_REF)
    3648   2658562787 :             continue;
    3649    397704393 :           rtx_insn *ref = label_ref_label (x);
    3650    794266085 :           if (!table_use
    3651    397704393 :               && (!LABEL_P (ref) || !NEXT_INSN (ref)
    3652    397296108 :                   || !JUMP_TABLE_DATA_P (NEXT_INSN (ref))))
    3653    396561692 :             continue;
    3654      1142701 :           if (!LABEL_P (ref) || !live.contains (ref))
    3655            0 :             fatal_insn ("tablejump references a label outside the RTL chain",
    3656              :                         jump);
    3657      1142701 :           if (JUMP_LABEL (jump) != ref)
    3658            0 :             fatal_insn ("tablejump pattern and JUMP_LABEL disagree", jump);
    3659      2285402 :           if (!NEXT_INSN (ref) || !JUMP_TABLE_DATA_P (NEXT_INSN (ref))
    3660      2285402 :               || !live.contains (NEXT_INSN (ref)))
    3661            0 :             fatal_insn ("tablejump references a missing jump table", jump);
    3662      1142701 :           label = ref;
    3663              :         }
    3664    437904815 :       if (label)
    3665              :         {
    3666       408285 :           table_users &count = *users.get (NEXT_INSN (label));
    3667       408285 :           ++count.total;
    3668       408285 :           if (!targetm.cannot_copy_insn_p || !targetm.cannot_copy_insn_p (jump))
    3669       408285 :             ++count.repeatable;
    3670              :         }
    3671    437904815 :     }
    3672              : 
    3673     63977253 :   for (rtx_jump_table_data *table : tables)
    3674              :     {
    3675              :       /* A dispatch with private labels can also have an out-of-line
    3676              :          execution template that references the same table.  */
    3677       365685 :       const table_users &count = *users.get (table);
    3678       365685 :       if (count.repeatable > 1 && !JUMP_TABLE_SHARED_P (PATTERN (table)))
    3679            0 :         fatal_insn ("jump table with multiple users is not marked shared",
    3680              :                     table);
    3681       365685 :       if (!count.total)
    3682            0 :         continue;
    3683              : 
    3684              :       /* While the CFG exists, a shared table follows one of the jumps
    3685              :          through it.  Machine reorganization can place other insns between
    3686              :          them later.  */
    3687       365685 :       if ((cfun->curr_properties & PROP_cfg)
    3688       365685 :           && JUMP_TABLE_SHARED_P (PATTERN (table)))
    3689              :         {
    3690        15851 :           rtx_insn *label = PREV_INSN (table);
    3691        15851 :           rtx_insn *prev = prev_nonnote_nondebug_insn (label);
    3692        46107 :           while (prev && BARRIER_P (prev))
    3693        14405 :             prev = prev_nonnote_nondebug_insn (prev);
    3694        15851 :           if (!prev || !JUMP_P (prev) || JUMP_LABEL (prev) != label)
    3695            0 :             fatal_insn ("shared jump table does not follow a jump through it",
    3696              :                         table);
    3697              :         }
    3698       365685 :       subrtx_iterator::array_type array;
    3699      9158182 :       FOR_EACH_SUBRTX (iter, array, PATTERN (table), ALL)
    3700      8792497 :         if (GET_CODE (*iter) == LABEL_REF)
    3701              :           {
    3702      8309212 :             rtx_insn *label = label_ref_label (*iter);
    3703      8309212 :             if (!LABEL_P (label) || !live.contains (label))
    3704            0 :               fatal_insn ("jump table references a label outside the RTL chain",
    3705              :                           table);
    3706              :           }
    3707       365685 :     }
    3708     63331133 : }
    3709              : 
    3710              : /* For INSN known to satisfy tablejump_p, determine if it actually is a
    3711              :    CASESI.  Return the insn pattern if so, NULL_RTX otherwise.  */
    3712              : 
    3713              : rtx
    3714        78346 : tablejump_casesi_pattern (const rtx_insn *insn)
    3715              : {
    3716        78346 :   rtx tmp;
    3717              : 
    3718        78346 :   if ((tmp = single_set (insn)) != NULL
    3719        78346 :       && SET_DEST (tmp) == pc_rtx
    3720        78346 :       && GET_CODE (SET_SRC (tmp)) == IF_THEN_ELSE
    3721        78346 :       && GET_CODE (XEXP (SET_SRC (tmp), 2)) == LABEL_REF)
    3722            0 :     return tmp;
    3723              : 
    3724              :   return NULL_RTX;
    3725              : }
    3726              : 
    3727              : /* A subroutine of computed_jump_p, return true if X contains a REG or MEM or
    3728              :    constant that is not in the constant pool and not in the condition
    3729              :    of an IF_THEN_ELSE.  */
    3730              : 
    3731              : static bool
    3732         2179 : computed_jump_p_1 (const_rtx x)
    3733              : {
    3734         2179 :   const enum rtx_code code = GET_CODE (x);
    3735         2179 :   int i, j;
    3736         2179 :   const char *fmt;
    3737              : 
    3738         2179 :   switch (code)
    3739              :     {
    3740              :     case LABEL_REF:
    3741              :     case PC:
    3742              :       return false;
    3743              : 
    3744              :     case CONST:
    3745              :     CASE_CONST_ANY:
    3746              :     case SYMBOL_REF:
    3747              :     case REG:
    3748              :       return true;
    3749              : 
    3750          430 :     case MEM:
    3751          430 :       return ! (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
    3752           16 :                 && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)));
    3753              : 
    3754            0 :     case IF_THEN_ELSE:
    3755            0 :       return (computed_jump_p_1 (XEXP (x, 1))
    3756            0 :               || computed_jump_p_1 (XEXP (x, 2)));
    3757              : 
    3758            0 :     default:
    3759            0 :       break;
    3760              :     }
    3761              : 
    3762            0 :   fmt = GET_RTX_FORMAT (code);
    3763            0 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    3764              :     {
    3765            0 :       if (fmt[i] == 'e'
    3766            0 :           && computed_jump_p_1 (XEXP (x, i)))
    3767              :         return true;
    3768              : 
    3769            0 :       else if (fmt[i] == 'E')
    3770            0 :         for (j = 0; j < XVECLEN (x, i); j++)
    3771            0 :           if (computed_jump_p_1 (XVECEXP (x, i, j)))
    3772              :             return true;
    3773              :     }
    3774              : 
    3775              :   return false;
    3776              : }
    3777              : 
    3778              : /* Return true if INSN is an indirect jump (aka computed jump).
    3779              : 
    3780              :    Tablejumps and casesi insns are not considered indirect jumps;
    3781              :    we can recognize them by a (use (label_ref)).  */
    3782              : 
    3783              : bool
    3784     53529786 : computed_jump_p (const rtx_insn *insn)
    3785              : {
    3786     53529786 :   int i;
    3787     53529786 :   if (JUMP_P (insn))
    3788              :     {
    3789     47997288 :       rtx pat = PATTERN (insn);
    3790              : 
    3791              :       /* If we have a JUMP_LABEL set, we're not a computed jump.  */
    3792     47997288 :       if (JUMP_LABEL (insn) != NULL)
    3793              :         return false;
    3794              : 
    3795         2700 :       if (GET_CODE (pat) == PARALLEL)
    3796              :         {
    3797          488 :           int len = XVECLEN (pat, 0);
    3798          488 :           bool has_use_labelref = false;
    3799              : 
    3800         1464 :           for (i = len - 1; i >= 0; i--)
    3801          976 :             if (GET_CODE (XVECEXP (pat, 0, i)) == USE
    3802            0 :                 && (GET_CODE (XEXP (XVECEXP (pat, 0, i), 0))
    3803              :                     == LABEL_REF))
    3804              :               {
    3805              :                 has_use_labelref = true;
    3806              :                 break;
    3807              :               }
    3808              : 
    3809          488 :           if (! has_use_labelref)
    3810         1464 :             for (i = len - 1; i >= 0; i--)
    3811          976 :               if (GET_CODE (XVECEXP (pat, 0, i)) == SET
    3812            0 :                   && SET_DEST (XVECEXP (pat, 0, i)) == pc_rtx
    3813          976 :                   && computed_jump_p_1 (SET_SRC (XVECEXP (pat, 0, i))))
    3814              :                 return true;
    3815              :         }
    3816         2212 :       else if (GET_CODE (pat) == SET
    3817         2179 :                && SET_DEST (pat) == pc_rtx
    3818         4391 :                && computed_jump_p_1 (SET_SRC (pat)))
    3819              :         return true;
    3820              :     }
    3821              :   return false;
    3822              : }
    3823              : 
    3824              : 
    3825              : 
    3826              : /* MEM has a PRE/POST-INC/DEC/MODIFY address X.  Extract the operands of
    3827              :    the equivalent add insn and pass the result to FN, using DATA as the
    3828              :    final argument.  */
    3829              : 
    3830              : static int
    3831     19903834 : for_each_inc_dec_find_inc_dec (rtx mem, for_each_inc_dec_fn fn, void *data)
    3832              : {
    3833     19903834 :   rtx x = XEXP (mem, 0);
    3834     19903834 :   switch (GET_CODE (x))
    3835              :     {
    3836      2386799 :     case PRE_INC:
    3837      2386799 :     case POST_INC:
    3838      2386799 :       {
    3839      4773598 :         poly_int64 size = GET_MODE_SIZE (GET_MODE (mem));
    3840      2386799 :         rtx r1 = XEXP (x, 0);
    3841      2386799 :         rtx c = gen_int_mode (size, GET_MODE (r1));
    3842      2386799 :         return fn (mem, x, r1, r1, c, data);
    3843              :       }
    3844              : 
    3845     17116036 :     case PRE_DEC:
    3846     17116036 :     case POST_DEC:
    3847     17116036 :       {
    3848     34232072 :         poly_int64 size = GET_MODE_SIZE (GET_MODE (mem));
    3849     17116036 :         rtx r1 = XEXP (x, 0);
    3850     17116036 :         rtx c = gen_int_mode (-size, GET_MODE (r1));
    3851     17116036 :         return fn (mem, x, r1, r1, c, data);
    3852              :       }
    3853              : 
    3854       400999 :     case PRE_MODIFY:
    3855       400999 :     case POST_MODIFY:
    3856       400999 :       {
    3857       400999 :         rtx r1 = XEXP (x, 0);
    3858       400999 :         rtx add = XEXP (x, 1);
    3859       400999 :         return fn (mem, x, r1, add, NULL, data);
    3860              :       }
    3861              : 
    3862            0 :     default:
    3863            0 :       gcc_unreachable ();
    3864              :     }
    3865              : }
    3866              : 
    3867              : /* Traverse *LOC looking for MEMs that have autoinc addresses.
    3868              :    For each such autoinc operation found, call FN, passing it
    3869              :    the innermost enclosing MEM, the operation itself, the RTX modified
    3870              :    by the operation, two RTXs (the second may be NULL) that, once
    3871              :    added, represent the value to be held by the modified RTX
    3872              :    afterwards, and DATA.  FN is to return 0 to continue the
    3873              :    traversal or any other value to have it returned to the caller of
    3874              :    for_each_inc_dec.  */
    3875              : 
    3876              : int
    3877   1070286163 : for_each_inc_dec (rtx x,
    3878              :                   for_each_inc_dec_fn fn,
    3879              :                   void *data)
    3880              : {
    3881   1070286163 :   subrtx_var_iterator::array_type array;
    3882   5640392601 :   FOR_EACH_SUBRTX_VAR (iter, array, x, NONCONST)
    3883              :     {
    3884   4570106438 :       rtx mem = *iter;
    3885   4570106438 :       if (mem
    3886   4570106438 :           && MEM_P (mem)
    3887    260092318 :           && GET_RTX_CLASS (GET_CODE (XEXP (mem, 0))) == RTX_AUTOINC)
    3888              :         {
    3889     19903834 :           int res = for_each_inc_dec_find_inc_dec (mem, fn, data);
    3890     19903834 :           if (res != 0)
    3891            0 :             return res;
    3892     19903834 :           iter.skip_subrtxes ();
    3893              :         }
    3894              :     }
    3895   1070286163 :   return 0;
    3896   1070286163 : }
    3897              : 
    3898              : 
    3899              : /* Searches X for any reference to REGNO, returning the rtx of the
    3900              :    reference found if any.  Otherwise, returns NULL_RTX.  */
    3901              : 
    3902              : rtx
    3903            0 : regno_use_in (unsigned int regno, rtx x)
    3904              : {
    3905            0 :   const char *fmt;
    3906            0 :   int i, j;
    3907            0 :   rtx tem;
    3908              : 
    3909            0 :   if (REG_P (x) && REGNO (x) == regno)
    3910              :     return x;
    3911              : 
    3912            0 :   fmt = GET_RTX_FORMAT (GET_CODE (x));
    3913            0 :   for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
    3914              :     {
    3915            0 :       if (fmt[i] == 'e')
    3916              :         {
    3917            0 :           if ((tem = regno_use_in (regno, XEXP (x, i))))
    3918              :             return tem;
    3919              :         }
    3920            0 :       else if (fmt[i] == 'E')
    3921            0 :         for (j = XVECLEN (x, i) - 1; j >= 0; j--)
    3922            0 :           if ((tem = regno_use_in (regno , XVECEXP (x, i, j))))
    3923              :             return tem;
    3924              :     }
    3925              : 
    3926              :   return NULL_RTX;
    3927              : }
    3928              : 
    3929              : /* Return a value indicating whether OP, an operand of a commutative
    3930              :    operation, is preferred as the first or second operand.  The more
    3931              :    positive the value, the stronger the preference for being the first
    3932              :    operand.  */
    3933              : 
    3934              : int
    3935   2192902210 : commutative_operand_precedence (rtx op)
    3936              : {
    3937   2192902210 :   enum rtx_code code = GET_CODE (op);
    3938              : 
    3939              :   /* Constants always become the second operand.  Prefer "nice" constants.  */
    3940   2192902210 :   if (code == CONST_INT)
    3941              :     return -10;
    3942              :   if (code == CONST_WIDE_INT)
    3943              :     return -9;
    3944              :   if (code == CONST_POLY_INT)
    3945              :     return -8;
    3946              :   if (code == CONST_DOUBLE)
    3947              :     return -8;
    3948              :   if (code == CONST_FIXED)
    3949              :     return -8;
    3950   1304939536 :   op = avoid_constant_pool_reference (op);
    3951   1304939536 :   code = GET_CODE (op);
    3952              : 
    3953   1304939536 :   switch (GET_RTX_CLASS (code))
    3954              :     {
    3955     26530073 :     case RTX_CONST_OBJ:
    3956     26530073 :       if (code == CONST_INT)
    3957              :         return -7;
    3958              :       if (code == CONST_WIDE_INT)
    3959              :         return -6;
    3960              :       if (code == CONST_POLY_INT)
    3961              :         return -5;
    3962              :       if (code == CONST_DOUBLE)
    3963              :         return -5;
    3964              :       if (code == CONST_FIXED)
    3965              :         return -5;
    3966              :       return -4;
    3967              : 
    3968     51693593 :     case RTX_EXTRA:
    3969              :       /* SUBREGs of objects should come second.  */
    3970     51693593 :       if (code == SUBREG && OBJECT_P (SUBREG_REG (op)))
    3971              :         return -3;
    3972              :       return 0;
    3973              : 
    3974    958263924 :     case RTX_OBJ:
    3975              :       /* Complex expressions should be the first, so decrease priority
    3976              :          of objects.  Prefer pointer objects over non pointer objects.  */
    3977    860310668 :       if ((REG_P (op) && REG_POINTER (op))
    3978   1444961711 :           || (MEM_P (op) && MEM_POINTER (op)))
    3979    391492614 :         return -1;
    3980              :       return -2;
    3981              : 
    3982              :     case RTX_COMM_ARITH:
    3983              :       /* Prefer operands that are themselves commutative to be first.
    3984              :          This helps to make things linear.  In particular,
    3985              :          (and (and (reg) (reg)) (not (reg))) is canonical.  */
    3986              :       return 4;
    3987              : 
    3988     80528788 :     case RTX_BIN_ARITH:
    3989              :       /* If only one operand is a binary expression, it will be the first
    3990              :          operand.  In particular,  (plus (minus (reg) (reg)) (neg (reg)))
    3991              :          is canonical, although it will usually be further simplified.  */
    3992     80528788 :       return 3;
    3993              : 
    3994      9085147 :     case RTX_COMM_COMPARE:
    3995      9085147 :     case RTX_COMPARE:
    3996              :       /* Give comparisons a cost between the unary expressions below
    3997              :          and the other binary expressions above, so that we don't have
    3998              :          a situation where the canonical order is binary, unary, binary.  */
    3999      9085147 :       return 2;
    4000              : 
    4001     28194485 :     case RTX_UNARY:
    4002              :       /* Then prefer NEG and NOT.  */
    4003     28194485 :       if (code == NEG || code == NOT)
    4004              :         return 1;
    4005              :       /* FALLTHRU */
    4006              : 
    4007              :     default:
    4008              :       return 0;
    4009              :     }
    4010              : }
    4011              : 
    4012              : /* Return true iff it is necessary to swap operands of commutative operation
    4013              :    in order to canonicalize expression.  */
    4014              : 
    4015              : bool
    4016    966434437 : swap_commutative_operands_p (rtx x, rtx y)
    4017              : {
    4018    966434437 :   return (commutative_operand_precedence (x)
    4019    966434437 :           < commutative_operand_precedence (y));
    4020              : }
    4021              : 
    4022              : /* Return true if X is an autoincrement side effect and the register is
    4023              :    not the stack pointer.  */
    4024              : bool
    4025            0 : auto_inc_p (const_rtx x)
    4026              : {
    4027            0 :   switch (GET_CODE (x))
    4028              :     {
    4029            0 :     case PRE_INC:
    4030            0 :     case POST_INC:
    4031            0 :     case PRE_DEC:
    4032            0 :     case POST_DEC:
    4033            0 :     case PRE_MODIFY:
    4034            0 :     case POST_MODIFY:
    4035              :       /* There are no REG_INC notes for SP.  */
    4036            0 :       if (XEXP (x, 0) != stack_pointer_rtx)
    4037            0 :         return true;
    4038              :     default:
    4039              :       break;
    4040              :     }
    4041              :   return false;
    4042              : }
    4043              : 
    4044              : /* Return true if IN contains a piece of rtl that has the address LOC.  */
    4045              : bool
    4046      1095763 : loc_mentioned_in_p (rtx *loc, const_rtx in)
    4047              : {
    4048      1095763 :   enum rtx_code code;
    4049      1095763 :   const char *fmt;
    4050      1095763 :   int i, j;
    4051              : 
    4052      1095763 :   if (!in)
    4053              :     return false;
    4054              : 
    4055      1095763 :   code = GET_CODE (in);
    4056      1095763 :   fmt = GET_RTX_FORMAT (code);
    4057      2188923 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    4058              :     {
    4059      1736623 :       if (fmt[i] == 'e')
    4060              :         {
    4061      1071878 :           if (loc == &XEXP (in, i) || loc_mentioned_in_p (loc, XEXP (in, i)))
    4062              :             return true;
    4063              :         }
    4064       664745 :       else if (fmt[i] == 'E')
    4065        31508 :         for (j = XVECLEN (in, i) - 1; j >= 0; j--)
    4066        22275 :           if (loc == &XVECEXP (in, i, j)
    4067        22275 :               || loc_mentioned_in_p (loc, XVECEXP (in, i, j)))
    4068              :             return true;
    4069              :     }
    4070              :   return false;
    4071              : }
    4072              : 
    4073              : /* Reinterpret a subreg as a bit extraction from an integer and return
    4074              :    the position of the least significant bit of the extracted value.
    4075              :    In other words, if the extraction were performed as a shift right
    4076              :    and mask, return the number of bits to shift right.
    4077              : 
    4078              :    The outer value of the subreg has OUTER_BYTES bytes and starts at
    4079              :    byte offset SUBREG_BYTE within an inner value of INNER_BYTES bytes.  */
    4080              : 
    4081              : poly_uint64
    4082     50717282 : subreg_size_lsb (poly_uint64 outer_bytes,
    4083              :                  poly_uint64 inner_bytes,
    4084              :                  poly_uint64 subreg_byte)
    4085              : {
    4086     50717282 :   poly_uint64 subreg_end, trailing_bytes, byte_pos;
    4087              : 
    4088              :   /* A paradoxical subreg begins at bit position 0.  */
    4089     50717282 :   gcc_checking_assert (ordered_p (outer_bytes, inner_bytes));
    4090     50717282 :   if (maybe_gt (outer_bytes, inner_bytes))
    4091              :     {
    4092        45336 :       gcc_checking_assert (known_eq (subreg_byte, 0U));
    4093        45336 :       return 0;
    4094              :     }
    4095              : 
    4096     50671946 :   subreg_end = subreg_byte + outer_bytes;
    4097     50671946 :   trailing_bytes = inner_bytes - subreg_end;
    4098     50671946 :   if (WORDS_BIG_ENDIAN && BYTES_BIG_ENDIAN)
    4099              :     byte_pos = trailing_bytes;
    4100     50671946 :   else if (!WORDS_BIG_ENDIAN && !BYTES_BIG_ENDIAN)
    4101     50671946 :     byte_pos = subreg_byte;
    4102              :   else
    4103              :     {
    4104              :       /* When bytes and words have opposite endianness, we must be able
    4105              :          to split offsets into words and bytes at compile time.  */
    4106              :       poly_uint64 leading_word_part
    4107              :         = force_align_down (subreg_byte, UNITS_PER_WORD);
    4108              :       poly_uint64 trailing_word_part
    4109              :         = force_align_down (trailing_bytes, UNITS_PER_WORD);
    4110              :       /* If the subreg crosses a word boundary ensure that
    4111              :          it also begins and ends on a word boundary.  */
    4112              :       gcc_assert (known_le (subreg_end - leading_word_part,
    4113              :                             (unsigned int) UNITS_PER_WORD)
    4114              :                   || (known_eq (leading_word_part, subreg_byte)
    4115              :                       && known_eq (trailing_word_part, trailing_bytes)));
    4116              :       if (WORDS_BIG_ENDIAN)
    4117              :         byte_pos = trailing_word_part + (subreg_byte - leading_word_part);
    4118              :       else
    4119              :         byte_pos = leading_word_part + (trailing_bytes - trailing_word_part);
    4120              :     }
    4121              : 
    4122     50671946 :   return byte_pos * BITS_PER_UNIT;
    4123              : }
    4124              : 
    4125              : /* Given a subreg X, return the bit offset where the subreg begins
    4126              :    (counting from the least significant bit of the reg).  */
    4127              : 
    4128              : poly_uint64
    4129      3068453 : subreg_lsb (const_rtx x)
    4130              : {
    4131      6136906 :   return subreg_lsb_1 (GET_MODE (x), GET_MODE (SUBREG_REG (x)),
    4132      3068453 :                        SUBREG_BYTE (x));
    4133              : }
    4134              : 
    4135              : /* Return the subreg byte offset for a subreg whose outer value has
    4136              :    OUTER_BYTES bytes, whose inner value has INNER_BYTES bytes, and where
    4137              :    there are LSB_SHIFT *bits* between the lsb of the outer value and the
    4138              :    lsb of the inner value.  This is the inverse of the calculation
    4139              :    performed by subreg_lsb_1 (which converts byte offsets to bit shifts).  */
    4140              : 
    4141              : poly_uint64
    4142     43476342 : subreg_size_offset_from_lsb (poly_uint64 outer_bytes, poly_uint64 inner_bytes,
    4143              :                              poly_uint64 lsb_shift)
    4144              : {
    4145              :   /* A paradoxical subreg begins at bit position 0.  */
    4146     43476342 :   gcc_checking_assert (ordered_p (outer_bytes, inner_bytes));
    4147     43476342 :   if (maybe_gt (outer_bytes, inner_bytes))
    4148              :     {
    4149            0 :       gcc_checking_assert (known_eq (lsb_shift, 0U));
    4150            0 :       return 0;
    4151              :     }
    4152              : 
    4153     43476342 :   poly_uint64 lower_bytes = exact_div (lsb_shift, BITS_PER_UNIT);
    4154     43476342 :   poly_uint64 upper_bytes = inner_bytes - (lower_bytes + outer_bytes);
    4155     43476342 :   if (WORDS_BIG_ENDIAN && BYTES_BIG_ENDIAN)
    4156              :     return upper_bytes;
    4157     43476342 :   else if (!WORDS_BIG_ENDIAN && !BYTES_BIG_ENDIAN)
    4158     43476342 :     return lower_bytes;
    4159              :   else
    4160              :     {
    4161              :       /* When bytes and words have opposite endianness, we must be able
    4162              :          to split offsets into words and bytes at compile time.  */
    4163              :       poly_uint64 lower_word_part = force_align_down (lower_bytes,
    4164              :                                                       UNITS_PER_WORD);
    4165              :       poly_uint64 upper_word_part = force_align_down (upper_bytes,
    4166              :                                                       UNITS_PER_WORD);
    4167              :       if (WORDS_BIG_ENDIAN)
    4168              :         return upper_word_part + (lower_bytes - lower_word_part);
    4169              :       else
    4170              :         return lower_word_part + (upper_bytes - upper_word_part);
    4171              :     }
    4172              : }
    4173              : 
    4174              : /* Fill in information about a subreg of a hard register.
    4175              :    xregno - A regno of an inner hard subreg_reg (or what will become one).
    4176              :    xmode  - The mode of xregno.
    4177              :    offset - The byte offset.
    4178              :    ymode  - The mode of a top level SUBREG (or what may become one).
    4179              :    info   - Pointer to structure to fill in.
    4180              : 
    4181              :    Rather than considering one particular inner register (and thus one
    4182              :    particular "outer" register) in isolation, this function really uses
    4183              :    XREGNO as a model for a sequence of isomorphic hard registers.  Thus the
    4184              :    function does not check whether adding INFO->offset to XREGNO gives
    4185              :    a valid hard register; even if INFO->offset + XREGNO is out of range,
    4186              :    there might be another register of the same type that is in range.
    4187              :    Likewise it doesn't check whether targetm.hard_regno_mode_ok accepts
    4188              :    the new register, since that can depend on things like whether the final
    4189              :    register number is even or odd.  Callers that want to check whether
    4190              :    this particular subreg can be replaced by a simple (reg ...) should
    4191              :    use simplify_subreg_regno.  */
    4192              : 
    4193              : void
    4194     35131266 : subreg_get_info (unsigned int xregno, machine_mode xmode,
    4195              :                  poly_uint64 offset, machine_mode ymode,
    4196              :                  struct subreg_info *info)
    4197              : {
    4198     35131266 :   unsigned int nregs_xmode, nregs_ymode;
    4199              : 
    4200     35131266 :   gcc_assert (xregno < FIRST_PSEUDO_REGISTER);
    4201              : 
    4202     70262532 :   poly_uint64 xsize = GET_MODE_SIZE (xmode);
    4203     70262532 :   poly_uint64 ysize = GET_MODE_SIZE (ymode);
    4204              : 
    4205     35131266 :   bool rknown = false;
    4206              : 
    4207              :   /* If the register representation of a non-scalar mode has holes in it,
    4208              :      we expect the scalar units to be concatenated together, with the holes
    4209              :      distributed evenly among the scalar units.  Each scalar unit must occupy
    4210              :      at least one register.  */
    4211     35131266 :   if (HARD_REGNO_NREGS_HAS_PADDING (xregno, xmode))
    4212              :     {
    4213              :       /* As a consequence, we must be dealing with a constant number of
    4214              :          scalars, and thus a constant offset and number of units.  */
    4215            0 :       HOST_WIDE_INT coffset = offset.to_constant ();
    4216            0 :       HOST_WIDE_INT cysize = ysize.to_constant ();
    4217            0 :       nregs_xmode = HARD_REGNO_NREGS_WITH_PADDING (xregno, xmode);
    4218            0 :       unsigned int nunits = GET_MODE_NUNITS (xmode).to_constant ();
    4219            0 :       scalar_mode xmode_unit = GET_MODE_INNER (xmode);
    4220            0 :       gcc_assert (HARD_REGNO_NREGS_HAS_PADDING (xregno, xmode_unit));
    4221            0 :       gcc_assert (nregs_xmode
    4222              :                   == (nunits
    4223              :                       * HARD_REGNO_NREGS_WITH_PADDING (xregno, xmode_unit)));
    4224            0 :       gcc_assert (hard_regno_nregs (xregno, xmode)
    4225              :                   == hard_regno_nregs (xregno, xmode_unit) * nunits);
    4226              : 
    4227              :       /* You can only ask for a SUBREG of a value with holes in the middle
    4228              :          if you don't cross the holes.  (Such a SUBREG should be done by
    4229              :          picking a different register class, or doing it in memory if
    4230              :          necessary.)  An example of a value with holes is XCmode on 32-bit
    4231              :          x86 with -m128bit-long-double; it's represented in 6 32-bit registers,
    4232              :          3 for each part, but in memory it's two 128-bit parts.
    4233              :          Padding is assumed to be at the end (not necessarily the 'high part')
    4234              :          of each unit.  */
    4235            0 :       if ((coffset / GET_MODE_SIZE (xmode_unit) + 1 < nunits)
    4236            0 :           && (coffset / GET_MODE_SIZE (xmode_unit)
    4237            0 :               != ((coffset + cysize - 1) / GET_MODE_SIZE (xmode_unit))))
    4238              :         {
    4239            0 :           info->representable_p = false;
    4240            0 :           rknown = true;
    4241              :         }
    4242              :     }
    4243              :   else
    4244     35131266 :     nregs_xmode = hard_regno_nregs (xregno, xmode);
    4245              : 
    4246     35131266 :   nregs_ymode = hard_regno_nregs (xregno, ymode);
    4247              : 
    4248              :   /* Subreg sizes must be ordered, so that we can tell whether they are
    4249              :      partial, paradoxical or complete.  */
    4250     35131266 :   gcc_checking_assert (ordered_p (xsize, ysize));
    4251              : 
    4252              :   /* Paradoxical subregs are otherwise valid.  */
    4253     35131266 :   if (!rknown && known_eq (offset, 0U) && maybe_gt (ysize, xsize))
    4254              :     {
    4255     12761531 :       info->representable_p = true;
    4256              :       /* If this is a big endian paradoxical subreg, which uses more
    4257              :          actual hard registers than the original register, we must
    4258              :          return a negative offset so that we find the proper highpart
    4259              :          of the register.
    4260              : 
    4261              :          We assume that the ordering of registers within a multi-register
    4262              :          value has a consistent endianness: if bytes and register words
    4263              :          have different endianness, the hard registers that make up a
    4264              :          multi-register value must be at least word-sized.  */
    4265     12761531 :       if (REG_WORDS_BIG_ENDIAN)
    4266              :         info->offset = (int) nregs_xmode - (int) nregs_ymode;
    4267              :       else
    4268     12761531 :         info->offset = 0;
    4269     12761531 :       info->nregs = nregs_ymode;
    4270     12761531 :       return;
    4271              :     }
    4272              : 
    4273              :   /* If registers store different numbers of bits in the different
    4274              :      modes, we cannot generally form this subreg.  */
    4275     22369735 :   poly_uint64 regsize_xmode, regsize_ymode;
    4276     19348639 :   if (!HARD_REGNO_NREGS_HAS_PADDING (xregno, xmode)
    4277            0 :       && !HARD_REGNO_NREGS_HAS_PADDING (xregno, ymode)
    4278     22369735 :       && multiple_p (xsize, nregs_xmode, &regsize_xmode)
    4279     22369735 :       && multiple_p (ysize, nregs_ymode, &regsize_ymode))
    4280              :     {
    4281     22369735 :       if (!rknown
    4282     22369735 :           && ((nregs_ymode > 1 && maybe_gt (regsize_xmode, regsize_ymode))
    4283     22369723 :               || (nregs_xmode > 1 && maybe_gt (regsize_ymode, regsize_xmode))))
    4284              :         {
    4285         7349 :           info->representable_p = false;
    4286         7349 :           if (!can_div_away_from_zero_p (ysize, regsize_xmode, &info->nregs)
    4287         7349 :               || !can_div_trunc_p (offset, regsize_xmode, &info->offset))
    4288              :             /* Checked by validate_subreg.  We must know at compile time
    4289              :                which inner registers are being accessed.  */
    4290              :             gcc_unreachable ();
    4291     34615528 :           return;
    4292              :         }
    4293              :       /* It's not valid to extract a subreg of mode YMODE at OFFSET that
    4294              :          would go outside of XMODE.  */
    4295     22362386 :       if (!rknown && maybe_gt (ysize + offset, xsize))
    4296              :         {
    4297            0 :           info->representable_p = false;
    4298            0 :           info->nregs = nregs_ymode;
    4299            0 :           if (!can_div_trunc_p (offset, regsize_xmode, &info->offset))
    4300              :             /* Checked by validate_subreg.  We must know at compile time
    4301              :                which inner registers are being accessed.  */
    4302              :             gcc_unreachable ();
    4303            0 :           return;
    4304              :         }
    4305              :       /* Quick exit for the simple and common case of extracting whole
    4306              :          subregisters from a multiregister value.  */
    4307              :       /* ??? It would be better to integrate this into the code below,
    4308              :          if we can generalize the concept enough and figure out how
    4309              :          odd-sized modes can coexist with the other weird cases we support.  */
    4310     22362386 :       HOST_WIDE_INT count;
    4311     22362386 :       if (!rknown
    4312              :           && WORDS_BIG_ENDIAN == REG_WORDS_BIG_ENDIAN
    4313     22362386 :           && known_eq (regsize_xmode, regsize_ymode)
    4314     22362386 :           && constant_multiple_p (offset, regsize_ymode, &count))
    4315              :         {
    4316     14567417 :           info->representable_p = true;
    4317     14567417 :           info->nregs = nregs_ymode;
    4318     14567417 :           info->offset = count;
    4319     14567417 :           gcc_assert (info->offset + info->nregs <= (int) nregs_xmode);
    4320              :           return;
    4321              :         }
    4322              :     }
    4323              : 
    4324              :   /* Lowpart subregs are otherwise valid.  */
    4325      7794969 :   if (!rknown && known_eq (offset, subreg_lowpart_offset (ymode, xmode)))
    4326              :     {
    4327      7279231 :       info->representable_p = true;
    4328      7279231 :       rknown = true;
    4329              : 
    4330      7279231 :       if (known_eq (offset, 0U) || nregs_xmode == nregs_ymode)
    4331              :         {
    4332      7279231 :           info->offset = 0;
    4333      7279231 :           info->nregs = nregs_ymode;
    4334      7279231 :           return;
    4335              :         }
    4336              :     }
    4337              : 
    4338              :   /* Set NUM_BLOCKS to the number of independently-representable YMODE
    4339              :      values there are in (reg:XMODE XREGNO).  We can view the register
    4340              :      as consisting of this number of independent "blocks", where each
    4341              :      block occupies NREGS_YMODE registers and contains exactly one
    4342              :      representable YMODE value.  */
    4343       515738 :   gcc_assert ((nregs_xmode % nregs_ymode) == 0);
    4344       515738 :   unsigned int num_blocks = nregs_xmode / nregs_ymode;
    4345              : 
    4346              :   /* Calculate the number of bytes in each block.  This must always
    4347              :      be exact, otherwise we don't know how to verify the constraint.
    4348              :      These conditions may be relaxed but subreg_regno_offset would
    4349              :      need to be redesigned.  */
    4350       515738 :   poly_uint64 bytes_per_block = exact_div (xsize, num_blocks);
    4351              : 
    4352              :   /* Get the number of the first block that contains the subreg and the byte
    4353              :      offset of the subreg from the start of that block.  */
    4354       515738 :   unsigned int block_number;
    4355       515738 :   poly_uint64 subblock_offset;
    4356       515738 :   if (!can_div_trunc_p (offset, bytes_per_block, &block_number,
    4357              :                         &subblock_offset))
    4358              :     /* Checked by validate_subreg.  We must know at compile time which
    4359              :        inner registers are being accessed.  */
    4360              :     gcc_unreachable ();
    4361              : 
    4362       515738 :   if (!rknown)
    4363              :     {
    4364              :       /* Only the lowpart of each block is representable.  */
    4365       515738 :       info->representable_p
    4366       515738 :         = known_eq (subblock_offset,
    4367              :                     subreg_size_lowpart_offset (ysize, bytes_per_block));
    4368       515738 :       rknown = true;
    4369              :     }
    4370              : 
    4371              :   /* We assume that the ordering of registers within a multi-register
    4372              :      value has a consistent endianness: if bytes and register words
    4373              :      have different endianness, the hard registers that make up a
    4374              :      multi-register value must be at least word-sized.  */
    4375       515738 :   if (WORDS_BIG_ENDIAN != REG_WORDS_BIG_ENDIAN)
    4376              :     /* The block number we calculated above followed memory endianness.
    4377              :        Convert it to register endianness by counting back from the end.
    4378              :        (Note that, because of the assumption above, each block must be
    4379              :        at least word-sized.)  */
    4380              :     info->offset = (num_blocks - block_number - 1) * nregs_ymode;
    4381              :   else
    4382       515738 :     info->offset = block_number * nregs_ymode;
    4383       515738 :   info->nregs = nregs_ymode;
    4384              : }
    4385              : 
    4386              : /* This function returns the regno offset of a subreg expression.
    4387              :    xregno - A regno of an inner hard subreg_reg (or what will become one).
    4388              :    xmode  - The mode of xregno.
    4389              :    offset - The byte offset.
    4390              :    ymode  - The mode of a top level SUBREG (or what may become one).
    4391              :    RETURN - The regno offset which would be used.  */
    4392              : unsigned int
    4393      5654397 : subreg_regno_offset (unsigned int xregno, machine_mode xmode,
    4394              :                      poly_uint64 offset, machine_mode ymode)
    4395              : {
    4396      5654397 :   struct subreg_info info;
    4397      5654397 :   subreg_get_info (xregno, xmode, offset, ymode, &info);
    4398      5654397 :   return info.offset;
    4399              : }
    4400              : 
    4401              : /* This function returns true when the offset is representable via
    4402              :    subreg_offset in the given regno.
    4403              :    xregno - A regno of an inner hard subreg_reg (or what will become one).
    4404              :    xmode  - The mode of xregno.
    4405              :    offset - The byte offset.
    4406              :    ymode  - The mode of a top level SUBREG (or what may become one).
    4407              :    RETURN - Whether the offset is representable.  */
    4408              : bool
    4409            0 : subreg_offset_representable_p (unsigned int xregno, machine_mode xmode,
    4410              :                                poly_uint64 offset, machine_mode ymode)
    4411              : {
    4412            0 :   struct subreg_info info;
    4413            0 :   subreg_get_info (xregno, xmode, offset, ymode, &info);
    4414            0 :   return info.representable_p;
    4415              : }
    4416              : 
    4417              : /* Return the number of a YMODE register to which
    4418              : 
    4419              :        (subreg:YMODE (reg:XMODE XREGNO) OFFSET)
    4420              : 
    4421              :    can be simplified.  Return -1 if the subreg can't be simplified.
    4422              : 
    4423              :    XREGNO is a hard register number.  ALLOW_STACK_REGS is true if
    4424              :    we should allow subregs of stack_pointer_rtx, frame_pointer_rtx.
    4425              :    and arg_pointer_rtx (which are normally expected to be the unique
    4426              :    way of referring to their respective registers).  */
    4427              : 
    4428              : 
    4429              : int
    4430     30348098 : simplify_subreg_regno (unsigned int xregno, machine_mode xmode,
    4431              :                        poly_uint64 offset, machine_mode ymode,
    4432              :                        bool allow_stack_regs)
    4433              : {
    4434     30348098 :   struct subreg_info info;
    4435     30348098 :   unsigned int yregno;
    4436              : 
    4437              :   /* Give the backend a chance to disallow the mode change.  */
    4438     30348098 :   if (GET_MODE_CLASS (xmode) != MODE_COMPLEX_INT
    4439     30348098 :       && GET_MODE_CLASS (xmode) != MODE_COMPLEX_FLOAT
    4440     30348098 :       && !REG_CAN_CHANGE_MODE_P (xregno, xmode, ymode))
    4441              :     return -1;
    4442              : 
    4443     29668220 :   if (!allow_stack_regs)
    4444              :     {
    4445              :       /* We shouldn't simplify stack-related registers.  */
    4446     29354198 :       if ((!reload_completed || frame_pointer_needed)
    4447     25766169 :           && xregno == FRAME_POINTER_REGNUM)
    4448              :         return -1;
    4449              : 
    4450     29228680 :       if (FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
    4451              :           && xregno == ARG_POINTER_REGNUM)
    4452              :         return -1;
    4453              : 
    4454     29106601 :       if (xregno == STACK_POINTER_REGNUM
    4455              :           /* We should convert hard stack register in LRA if it is
    4456              :              possible.  */
    4457       122704 :           && ! lra_in_progress)
    4458              :         return -1;
    4459              :     }
    4460              : 
    4461              :   /* Try to get the register offset.  */
    4462     29299118 :   subreg_get_info (xregno, xmode, offset, ymode, &info);
    4463     29299118 :   if (!info.representable_p)
    4464              :     return -1;
    4465              : 
    4466              :   /* Make sure that the offsetted register value is in range.  */
    4467     28837917 :   yregno = xregno + info.offset;
    4468     28837917 :   if (!HARD_REGISTER_NUM_P (yregno))
    4469              :     return -1;
    4470              : 
    4471              :   /* See whether (reg:YMODE YREGNO) is valid.
    4472              : 
    4473              :      ??? We allow invalid registers if (reg:XMODE XREGNO) is also invalid.
    4474              :      This is a kludge to work around how complex FP arguments are passed
    4475              :      on IA-64 and should be fixed.  See PR target/49226.  */
    4476     28837706 :   if (!targetm.hard_regno_mode_ok (yregno, ymode)
    4477     28837706 :       && targetm.hard_regno_mode_ok (xregno, xmode))
    4478              :     return -1;
    4479              : 
    4480     28565950 :   return (int) yregno;
    4481              : }
    4482              : 
    4483              : /* A wrapper around simplify_subreg_regno that uses subreg_lowpart_offset
    4484              :    (xmode, ymode) as the offset.  */
    4485              : 
    4486              : int
    4487            0 : lowpart_subreg_regno (unsigned int regno, machine_mode xmode,
    4488              :                       machine_mode ymode)
    4489              : {
    4490            0 :   poly_uint64 offset = subreg_lowpart_offset (xmode, ymode);
    4491            0 :   return simplify_subreg_regno (regno, xmode, offset, ymode);
    4492              : }
    4493              : 
    4494              : /* Return the final regno that a subreg expression refers to.  */
    4495              : unsigned int
    4496         9560 : subreg_regno (const_rtx x)
    4497              : {
    4498         9560 :   unsigned int ret;
    4499         9560 :   rtx subreg = SUBREG_REG (x);
    4500         9560 :   int regno = REGNO (subreg);
    4501              : 
    4502        19120 :   ret = regno + subreg_regno_offset (regno,
    4503         9560 :                                      GET_MODE (subreg),
    4504         9560 :                                      SUBREG_BYTE (x),
    4505         9560 :                                      GET_MODE (x));
    4506         9560 :   return ret;
    4507              : 
    4508              : }
    4509              : 
    4510              : /* Return the number of registers that a subreg expression refers
    4511              :    to.  */
    4512              : unsigned int
    4513       172884 : subreg_nregs (const_rtx x)
    4514              : {
    4515       172884 :   return subreg_nregs_with_regno (REGNO (SUBREG_REG (x)), x);
    4516              : }
    4517              : 
    4518              : /* Return the number of registers that a subreg REG with REGNO
    4519              :    expression refers to.  This is a copy of the rtlanal.cc:subreg_nregs
    4520              :    changed so that the regno can be passed in. */
    4521              : 
    4522              : unsigned int
    4523       172884 : subreg_nregs_with_regno (unsigned int regno, const_rtx x)
    4524              : {
    4525       172884 :   struct subreg_info info;
    4526       172884 :   rtx subreg = SUBREG_REG (x);
    4527              : 
    4528       172884 :   subreg_get_info (regno, GET_MODE (subreg), SUBREG_BYTE (x), GET_MODE (x),
    4529              :                    &info);
    4530       172884 :   return info.nregs;
    4531              : }
    4532              : 
    4533              : struct parms_set_data
    4534              : {
    4535              :   int nregs;
    4536              :   HARD_REG_SET regs;
    4537              : };
    4538              : 
    4539              : /* Helper function for noticing stores to parameter registers.  */
    4540              : static void
    4541        68361 : parms_set (rtx x, const_rtx pat ATTRIBUTE_UNUSED, void *data)
    4542              : {
    4543        68361 :   struct parms_set_data *const d = (struct parms_set_data *) data;
    4544        68359 :   if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER
    4545       136720 :       && TEST_HARD_REG_BIT (d->regs, REGNO (x)))
    4546              :     {
    4547        68020 :       CLEAR_HARD_REG_BIT (d->regs, REGNO (x));
    4548        68020 :       d->nregs--;
    4549              :     }
    4550        68361 : }
    4551              : 
    4552              : /* Look backward for first parameter to be loaded.
    4553              :    Note that loads of all parameters will not necessarily be
    4554              :    found if CSE has eliminated some of them (e.g., an argument
    4555              :    to the outer function is passed down as a parameter).
    4556              :    Do not skip BOUNDARY.  */
    4557              : rtx_insn *
    4558        41313 : find_first_parameter_load (rtx_call_insn *call_insn, rtx_insn *boundary)
    4559              : {
    4560        41313 :   struct parms_set_data parm;
    4561        41313 :   rtx p;
    4562        41313 :   rtx_insn *before, *first_set;
    4563              : 
    4564              :   /* Since different machines initialize their parameter registers
    4565              :      in different orders, assume nothing.  Collect the set of all
    4566              :      parameter registers.  */
    4567        41313 :   CLEAR_HARD_REG_SET (parm.regs);
    4568        41313 :   parm.nregs = 0;
    4569       124757 :   for (p = CALL_INSN_FUNCTION_USAGE (call_insn); p; p = XEXP (p, 1))
    4570        83444 :     if (GET_CODE (XEXP (p, 0)) == USE
    4571        83282 :         && REG_P (XEXP (XEXP (p, 0), 0))
    4572       153924 :         && !STATIC_CHAIN_REG_P (XEXP (XEXP (p, 0), 0)))
    4573              :       {
    4574        70205 :         gcc_assert (REGNO (XEXP (XEXP (p, 0), 0)) < FIRST_PSEUDO_REGISTER);
    4575              : 
    4576              :         /* We only care about registers which can hold function
    4577              :            arguments.  */
    4578        70205 :         if (!FUNCTION_ARG_REGNO_P (REGNO (XEXP (XEXP (p, 0), 0))))
    4579         1808 :           continue;
    4580              : 
    4581        68397 :         SET_HARD_REG_BIT (parm.regs, REGNO (XEXP (XEXP (p, 0), 0)));
    4582        68397 :         parm.nregs++;
    4583              :       }
    4584              :   before = call_insn;
    4585              :   first_set = call_insn;
    4586              : 
    4587              :   /* Search backward for the first set of a register in this set.  */
    4588       109333 :   while (parm.nregs && before != boundary)
    4589              :     {
    4590        68361 :       before = PREV_INSN (before);
    4591              : 
    4592              :       /* It is possible that some loads got CSEed from one call to
    4593              :          another.  Stop in that case.  */
    4594        68361 :       if (CALL_P (before))
    4595              :         break;
    4596              : 
    4597              :       /* Our caller needs either ensure that we will find all sets
    4598              :          (in case code has not been optimized yet), or take care
    4599              :          for possible labels in a way by setting boundary to preceding
    4600              :          CODE_LABEL.  */
    4601        68361 :       if (LABEL_P (before))
    4602              :         {
    4603            0 :           gcc_assert (before == boundary);
    4604              :           break;
    4605              :         }
    4606              : 
    4607        68361 :       if (INSN_P (before))
    4608              :         {
    4609        68361 :           int nregs_old = parm.nregs;
    4610        68361 :           note_stores (before, parms_set, &parm);
    4611              :           /* If we found something that did not set a parameter reg,
    4612              :              we're done.  Do not keep going, as that might result
    4613              :              in hoisting an insn before the setting of a pseudo
    4614              :              that is used by the hoisted insn. */
    4615        68361 :           if (nregs_old != parm.nregs)
    4616              :             first_set = before;
    4617              :           else
    4618              :             break;
    4619              :         }
    4620              :     }
    4621        41313 :   return first_set;
    4622              : }
    4623              : 
    4624              : /* Return true if we should avoid inserting code between INSN and preceding
    4625              :    call instruction.  */
    4626              : 
    4627              : bool
    4628     11366487 : keep_with_call_p (const rtx_insn *insn)
    4629              : {
    4630     11531571 :   rtx set;
    4631              : 
    4632     11531571 :   if (INSN_P (insn) && (set = single_set (insn)) != NULL)
    4633              :     {
    4634      7659831 :       if (REG_P (SET_DEST (set))
    4635      2040673 :           && REGNO (SET_DEST (set)) < FIRST_PSEUDO_REGISTER
    4636      2040673 :           && fixed_regs[REGNO (SET_DEST (set))]
    4637      7827348 :           && general_operand (SET_SRC (set), VOIDmode))
    4638              :         return true;
    4639      7659468 :       if (REG_P (SET_SRC (set))
    4640       834625 :           && targetm.calls.function_value_regno_p (REGNO (SET_SRC (set)))
    4641       486451 :           && REG_P (SET_DEST (set))
    4642      7807229 :           && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER)
    4643              :         return true;
    4644              :       /* There may be a stack pop just after the call and before the store
    4645              :          of the return register.  Search for the actual store when deciding
    4646              :          if we can break or not.  */
    4647      7659468 :       if (SET_DEST (set) == stack_pointer_rtx)
    4648              :         {
    4649              :           /* This CONST_CAST is okay because next_nonnote_insn just
    4650              :              returns its argument and we assign it to a const_rtx
    4651              :              variable.  */
    4652       166004 :           const rtx_insn *i2
    4653       166004 :             = next_nonnote_insn (const_cast<rtx_insn *> (insn));
    4654       166004 :           if (i2 && keep_with_call_p (i2))
    4655              :             return true;
    4656              :         }
    4657              :     }
    4658              :   return false;
    4659              : }
    4660              : 
    4661              : /* Return true if LABEL is a target of JUMP_INSN.  This applies only
    4662              :    to non-complex jumps.  That is, direct unconditional, conditional,
    4663              :    and tablejumps, but not computed jumps or returns.  It also does
    4664              :    not apply to the fallthru case of a conditional jump.  */
    4665              : 
    4666              : bool
    4667     24548438 : label_is_jump_target_p (const rtx_insn *label, const rtx_insn *jump_insn)
    4668              : {
    4669     24548438 :   rtx tmp = JUMP_LABEL (jump_insn);
    4670     24548438 :   rtx_jump_table_data *table;
    4671              : 
    4672     24548438 :   if (label == tmp)
    4673              :     return true;
    4674              : 
    4675      4169298 :   if (tablejump_p (jump_insn, NULL, &table))
    4676              :     {
    4677            0 :       rtvec vec = table->get_labels ();
    4678            0 :       int i, veclen = GET_NUM_ELEM (vec);
    4679              : 
    4680            0 :       for (i = 0; i < veclen; ++i)
    4681            0 :         if (XEXP (RTVEC_ELT (vec, i), 0) == label)
    4682              :           return true;
    4683              :     }
    4684              : 
    4685      4169298 :   if (find_reg_note (jump_insn, REG_LABEL_TARGET, label))
    4686         2881 :     return true;
    4687              : 
    4688              :   return false;
    4689              : }
    4690              : 
    4691              : 
    4692              : /* Return an estimate of the cost of computing rtx X.
    4693              :    One use is in cse, to decide which expression to keep in the hash table.
    4694              :    Another is in rtl generation, to pick the cheapest way to multiply.
    4695              :    Other uses like the latter are expected in the future.
    4696              : 
    4697              :    X appears as operand OPNO in an expression with code OUTER_CODE.
    4698              :    SPEED specifies whether costs optimized for speed or size should
    4699              :    be returned.  */
    4700              : 
    4701              : int
    4702  12961093189 : rtx_cost (rtx x, machine_mode mode, enum rtx_code outer_code,
    4703              :           int opno, bool speed)
    4704              : {
    4705  12961093189 :   int i, j;
    4706  12961093189 :   enum rtx_code code;
    4707  12961093189 :   const char *fmt;
    4708  12961093189 :   int total;
    4709  12961093189 :   int factor;
    4710  12961093189 :   unsigned mode_size;
    4711              : 
    4712  12961093189 :   if (x == 0)
    4713              :     return 0;
    4714              : 
    4715  12961093189 :   if (GET_CODE (x) == SET)
    4716              :     /* A SET doesn't have a mode, so let's look at the SET_DEST to get
    4717              :        the mode for the factor.  */
    4718     49895625 :     mode = GET_MODE (SET_DEST (x));
    4719  12911197564 :   else if (GET_MODE (x) != VOIDmode)
    4720   9954947294 :     mode = GET_MODE (x);
    4721              : 
    4722  25922186378 :   mode_size = estimated_poly_value (GET_MODE_SIZE (mode));
    4723              : 
    4724              :   /* A size N times larger than UNITS_PER_WORD likely needs N times as
    4725              :      many insns, taking N times as long.  */
    4726  13470653542 :   factor = mode_size > UNITS_PER_WORD ? mode_size / UNITS_PER_WORD : 1;
    4727              : 
    4728              :   /* Compute the default costs of certain things.
    4729              :      Note that targetm.rtx_costs can override the defaults.  */
    4730              : 
    4731  12961093189 :   code = GET_CODE (x);
    4732  12961093189 :   switch (code)
    4733              :     {
    4734   1810997318 :     case MULT:
    4735   1810997318 :     case FMA:
    4736   1810997318 :     case SS_MULT:
    4737   1810997318 :     case US_MULT:
    4738   1810997318 :     case SMUL_HIGHPART:
    4739   1810997318 :     case UMUL_HIGHPART:
    4740              :       /* Multiplication has time-complexity O(N*N), where N is the
    4741              :          number of units (translated from digits) when using
    4742              :          schoolbook long multiplication.  */
    4743   1810997318 :       total = factor * factor * COSTS_N_INSNS (5);
    4744   1810997318 :       break;
    4745     75201255 :     case DIV:
    4746     75201255 :     case UDIV:
    4747     75201255 :     case MOD:
    4748     75201255 :     case UMOD:
    4749     75201255 :     case SS_DIV:
    4750     75201255 :     case US_DIV:
    4751              :       /* Similarly, complexity for schoolbook long division.  */
    4752     75201255 :       total = factor * factor * COSTS_N_INSNS (7);
    4753     75201255 :       break;
    4754            0 :     case USE:
    4755              :       /* Used in combine.cc as a marker.  */
    4756            0 :       total = 0;
    4757            0 :       break;
    4758  11074894616 :     default:
    4759  11074894616 :       total = factor * COSTS_N_INSNS (1);
    4760              :     }
    4761              : 
    4762  12961093189 :   switch (code)
    4763              :     {
    4764              :     case REG:
    4765              :       return 0;
    4766              : 
    4767     12656323 :     case SUBREG:
    4768     12656323 :       total = 0;
    4769              :       /* If we can't tie these modes, make this expensive.  The larger
    4770              :          the mode, the more expensive it is.  */
    4771     12656323 :       if (!targetm.modes_tieable_p (mode, GET_MODE (SUBREG_REG (x))))
    4772      4658586 :         return COSTS_N_INSNS (2 + factor);
    4773              :       break;
    4774              : 
    4775     17792455 :     case TRUNCATE:
    4776     17792455 :       if (targetm.modes_tieable_p (mode, GET_MODE (XEXP (x, 0))))
    4777              :         {
    4778      3968166 :           total = 0;
    4779      3968166 :           break;
    4780              :         }
    4781              :       /* FALLTHRU */
    4782   7928526391 :     default:
    4783   7928526391 :       if (targetm.rtx_costs (x, mode, outer_code, opno, &total, speed))
    4784   3636587722 :         return total;
    4785              :       break;
    4786              :     }
    4787              : 
    4788              :   /* Sum the costs of the sub-rtx's, plus cost of this operation,
    4789              :      which is already in total.  */
    4790              : 
    4791   4303904572 :   fmt = GET_RTX_FORMAT (code);
    4792  12818490014 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    4793   8514585442 :     if (fmt[i] == 'e')
    4794   8443858188 :       total += rtx_cost (XEXP (x, i), mode, code, i, speed);
    4795     70727254 :     else if (fmt[i] == 'E')
    4796     11970927 :       for (j = 0; j < XVECLEN (x, i); j++)
    4797      6801172 :         total += rtx_cost (XVECEXP (x, i, j), mode, code, i, speed);
    4798              : 
    4799   4303904572 :   return total;
    4800              : }
    4801              : 
    4802              : /* Fill in the structure C with information about both speed and size rtx
    4803              :    costs for X, which is operand OPNO in an expression with code OUTER.  */
    4804              : 
    4805              : void
    4806      2347531 : get_full_rtx_cost (rtx x, machine_mode mode, enum rtx_code outer, int opno,
    4807              :                    struct full_rtx_costs *c)
    4808              : {
    4809      2347531 :   c->speed = rtx_cost (x, mode, outer, opno, true);
    4810      2347531 :   c->size = rtx_cost (x, mode, outer, opno, false);
    4811      2347531 : }
    4812              : 
    4813              : 
    4814              : /* Return cost of address expression X.
    4815              :    Expect that X is properly formed address reference.
    4816              : 
    4817              :    SPEED parameter specify whether costs optimized for speed or size should
    4818              :    be returned.  */
    4819              : 
    4820              : int
    4821     10915816 : address_cost (rtx x, machine_mode mode, addr_space_t as, bool speed)
    4822              : {
    4823              :   /* We may be asked for cost of various unusual addresses, such as operands
    4824              :      of push instruction.  It is not worthwhile to complicate writing
    4825              :      of the target hook by such cases.  */
    4826              : 
    4827     10915816 :   if (!memory_address_addr_space_p (mode, x, as))
    4828              :     return 1000;
    4829              : 
    4830     10839281 :   return targetm.address_cost (x, mode, as, speed);
    4831              : }
    4832              : 
    4833              : /* If the target doesn't override, compute the cost as with arithmetic.  */
    4834              : 
    4835              : int
    4836            0 : default_address_cost (rtx x, machine_mode, addr_space_t, bool speed)
    4837              : {
    4838            0 :   return rtx_cost (x, Pmode, MEM, 0, speed);
    4839              : }
    4840              : 
    4841              : 
    4842              : unsigned HOST_WIDE_INT
    4843    729995910 : nonzero_bits (const_rtx x, machine_mode mode)
    4844              : {
    4845    729995910 :   if (mode == VOIDmode)
    4846            0 :     mode = GET_MODE (x);
    4847    729995910 :   scalar_int_mode int_mode;
    4848    729995910 :   if (!is_a <scalar_int_mode> (mode, &int_mode))
    4849     20788933 :     return GET_MODE_MASK (mode);
    4850    709206977 :   return cached_nonzero_bits (x, int_mode, NULL_RTX, VOIDmode, 0);
    4851              : }
    4852              : 
    4853              : unsigned int
    4854    258086631 : num_sign_bit_copies (const_rtx x, machine_mode mode)
    4855              : {
    4856    258086631 :   if (mode == VOIDmode)
    4857            1 :     mode = GET_MODE (x);
    4858    258086631 :   scalar_int_mode int_mode;
    4859    258086631 :   if (!is_a <scalar_int_mode> (mode, &int_mode))
    4860              :     return 1;
    4861    237662013 :   return cached_num_sign_bit_copies (x, int_mode, NULL_RTX, VOIDmode, 0);
    4862              : }
    4863              : 
    4864              : /* Return true if nonzero_bits1 might recurse into both operands
    4865              :    of X.  */
    4866              : 
    4867              : static inline bool
    4868   1483525350 : nonzero_bits_binary_arith_p (const_rtx x)
    4869              : {
    4870   1483525350 :   if (!ARITHMETIC_P (x))
    4871              :     return false;
    4872    249287546 :   switch (GET_CODE (x))
    4873              :     {
    4874              :     case AND:
    4875              :     case XOR:
    4876              :     case IOR:
    4877              :     case UMIN:
    4878              :     case UMAX:
    4879              :     case SMIN:
    4880              :     case SMAX:
    4881              :     case PLUS:
    4882              :     case MINUS:
    4883              :     case MULT:
    4884              :     case DIV:
    4885              :     case UDIV:
    4886              :     case MOD:
    4887              :     case UMOD:
    4888              :       return true;
    4889              :     default:
    4890              :       return false;
    4891              :     }
    4892              : }
    4893              : 
    4894              : /* The function cached_nonzero_bits is a wrapper around nonzero_bits1.
    4895              :    It avoids exponential behavior in nonzero_bits1 when X has
    4896              :    identical subexpressions on the first or the second level.  */
    4897              : 
    4898              : static unsigned HOST_WIDE_INT
    4899   1199835118 : cached_nonzero_bits (const_rtx x, scalar_int_mode mode, const_rtx known_x,
    4900              :                      machine_mode known_mode,
    4901              :                      unsigned HOST_WIDE_INT known_ret)
    4902              : {
    4903   1199835118 :   if (x == known_x && mode == known_mode)
    4904              :     return known_ret;
    4905              : 
    4906              :   /* Try to find identical subexpressions.  If found call
    4907              :      nonzero_bits1 on X with the subexpressions as KNOWN_X and the
    4908              :      precomputed value for the subexpression as KNOWN_RET.  */
    4909              : 
    4910   1197552753 :   if (nonzero_bits_binary_arith_p (x))
    4911              :     {
    4912    143588604 :       rtx x0 = XEXP (x, 0);
    4913    143588604 :       rtx x1 = XEXP (x, 1);
    4914              : 
    4915              :       /* Check the first level.  */
    4916    143588604 :       if (x0 == x1)
    4917        49446 :         return nonzero_bits1 (x, mode, x0, mode,
    4918              :                               cached_nonzero_bits (x0, mode, known_x,
    4919        49446 :                                                    known_mode, known_ret));
    4920              : 
    4921              :       /* Check the second level.  */
    4922    143539158 :       if (nonzero_bits_binary_arith_p (x0)
    4923    143539158 :           && (x1 == XEXP (x0, 0) || x1 == XEXP (x0, 1)))
    4924      1105719 :         return nonzero_bits1 (x, mode, x1, mode,
    4925              :                               cached_nonzero_bits (x1, mode, known_x,
    4926      1105719 :                                                    known_mode, known_ret));
    4927              : 
    4928    142433439 :       if (nonzero_bits_binary_arith_p (x1)
    4929    142433439 :           && (x0 == XEXP (x1, 0) || x0 == XEXP (x1, 1)))
    4930         6939 :         return nonzero_bits1 (x, mode, x0, mode,
    4931              :                               cached_nonzero_bits (x0, mode, known_x,
    4932         6939 :                                                    known_mode, known_ret));
    4933              :     }
    4934              : 
    4935   1196390649 :   return nonzero_bits1 (x, mode, known_x, known_mode, known_ret);
    4936              : }
    4937              : 
    4938              : /* We let num_sign_bit_copies recur into nonzero_bits as that is useful.
    4939              :    We don't let nonzero_bits recur into num_sign_bit_copies, because that
    4940              :    is less useful.  We can't allow both, because that results in exponential
    4941              :    run time recursion.  There is a nullstone testcase that triggered
    4942              :    this.  This macro avoids accidental uses of num_sign_bit_copies.  */
    4943              : #define cached_num_sign_bit_copies sorry_i_am_preventing_exponential_behavior
    4944              : 
    4945              : /* Given an expression, X, compute which bits in X can be nonzero.
    4946              :    We don't care about bits outside of those defined in MODE.
    4947              : 
    4948              :    For most X this is simply GET_MODE_MASK (GET_MODE (X)), but if X is
    4949              :    an arithmetic operation, we can do better.  */
    4950              : 
    4951              : static unsigned HOST_WIDE_INT
    4952   1197552753 : nonzero_bits1 (const_rtx x, scalar_int_mode mode, const_rtx known_x,
    4953              :                machine_mode known_mode,
    4954              :                unsigned HOST_WIDE_INT known_ret)
    4955              : {
    4956   1197552753 :   unsigned HOST_WIDE_INT nonzero = GET_MODE_MASK (mode);
    4957   1197552753 :   unsigned HOST_WIDE_INT inner_nz;
    4958   1197552753 :   enum rtx_code code = GET_CODE (x);
    4959   1197552753 :   machine_mode inner_mode;
    4960   1197552753 :   unsigned int inner_width;
    4961   1197552753 :   scalar_int_mode xmode, op_imode;
    4962              : 
    4963   1197552753 :   unsigned int mode_width = GET_MODE_PRECISION (mode);
    4964              : 
    4965              :   /* For unary ops like ffs or popcount we want to determine the number of
    4966              :      nonzero bits from the operand.  This only matters with very large
    4967              :      vector modes.  A
    4968              :        (popcount:DI (V128BImode)
    4969              :      should not get a nonzero-bit mask of (1 << 7) - 1 as that could
    4970              :      lead to incorrect optimizations based on it, see PR123501.  */
    4971   1197552753 :   unsigned int op_mode_width = mode_width;
    4972   1197552753 :   machine_mode op_mode = mode;
    4973   1197552753 :   if (UNARY_P (x))
    4974              :     {
    4975     18023472 :       const_rtx op = XEXP (x, 0);
    4976     18023472 :       if (GET_MODE_PRECISION (GET_MODE (op)).is_constant ())
    4977              :         {
    4978     18023472 :           op_mode = GET_MODE (op);
    4979     18023472 :           op_mode_width = GET_MODE_PRECISION (op_mode).to_constant ();
    4980              :         }
    4981              :     }
    4982              : 
    4983   1197552753 :   if (CONST_INT_P (x))
    4984              :     {
    4985    114348938 :       if (SHORT_IMMEDIATES_SIGN_EXTEND
    4986              :           && INTVAL (x) > 0
    4987              :           && mode_width < BITS_PER_WORD
    4988              :           && (UINTVAL (x) & (HOST_WIDE_INT_1U << (mode_width - 1))) != 0)
    4989              :         return UINTVAL (x) | (HOST_WIDE_INT_M1U << mode_width);
    4990              : 
    4991    114348938 :       return UINTVAL (x);
    4992              :     }
    4993              : 
    4994   1083203815 :   if (!is_a <scalar_int_mode> (GET_MODE (x), &xmode))
    4995              :     return nonzero;
    4996   1082394169 :   unsigned int xmode_width = GET_MODE_PRECISION (xmode);
    4997              : 
    4998              :   /* If X is wider than MODE, use its mode instead.  */
    4999   1082394169 :   if (xmode_width > mode_width)
    5000              :     {
    5001     26288108 :       mode = xmode;
    5002     26288108 :       nonzero = GET_MODE_MASK (mode);
    5003     26288108 :       mode_width = xmode_width;
    5004              :     }
    5005              : 
    5006   1082394169 :   if (mode_width > HOST_BITS_PER_WIDE_INT)
    5007              :     /* Our only callers in this case look for single bit values.  So
    5008              :        just return the mode mask.  Those tests will then be false.  */
    5009              :     return nonzero;
    5010              : 
    5011              :   /* If MODE is wider than X, but both are a single word for both the host
    5012              :      and target machines, we can compute this from which bits of the object
    5013              :      might be nonzero in its own mode, taking into account the fact that, on
    5014              :      CISC machines, accessing an object in a wider mode generally causes the
    5015              :      high-order bits to become undefined, so they are not known to be zero.
    5016              :      We extend this reasoning to RISC machines for operations that might not
    5017              :      operate on the full registers.  */
    5018   1080996866 :   if (mode_width > xmode_width
    5019    115854472 :       && xmode_width <= BITS_PER_WORD
    5020              :       && xmode_width <= HOST_BITS_PER_WIDE_INT
    5021              :       && !(WORD_REGISTER_OPERATIONS && word_register_operation_p (x)))
    5022              :     {
    5023     98947771 :       nonzero &= cached_nonzero_bits (x, xmode,
    5024              :                                       known_x, known_mode, known_ret);
    5025     98947771 :       nonzero |= GET_MODE_MASK (mode) & ~GET_MODE_MASK (xmode);
    5026     98947771 :       return nonzero;
    5027              :     }
    5028              : 
    5029              :   /* Please keep nonzero_bits_binary_arith_p above in sync with
    5030              :      the code in the switch below.  */
    5031    982049095 :   switch (code)
    5032              :     {
    5033    544252057 :     case REG:
    5034              : #if defined(POINTERS_EXTEND_UNSIGNED)
    5035              :       /* If pointers extend unsigned and this is a pointer in Pmode, say that
    5036              :          all the bits above ptr_mode are known to be zero.  */
    5037              :       /* As we do not know which address space the pointer is referring to,
    5038              :          we can do this only if the target does not support different pointer
    5039              :          or address modes depending on the address space.  */
    5040    544252057 :       if (target_default_pointer_address_modes_p ()
    5041              :           && POINTERS_EXTEND_UNSIGNED
    5042    610460503 :           && xmode == Pmode
    5043    354471117 :           && REG_POINTER (x)
    5044    632326517 :           && !targetm.have_ptr_extend ())
    5045     88074460 :         nonzero &= GET_MODE_MASK (ptr_mode);
    5046              : #endif
    5047              : 
    5048              :       /* Include declared information about alignment of pointers.  */
    5049              :       /* ??? We don't properly preserve REG_POINTER changes across
    5050              :          pointer-to-integer casts, so we can't trust it except for
    5051              :          things that we know must be pointers.  See execute/960116-1.c.  */
    5052    544252057 :       if ((x == stack_pointer_rtx
    5053    543288021 :            || x == frame_pointer_rtx
    5054    528711395 :            || x == arg_pointer_rtx)
    5055    559413937 :           && REGNO_POINTER_ALIGN (REGNO (x)))
    5056              :         {
    5057     16125916 :           unsigned HOST_WIDE_INT alignment
    5058     16125916 :             = REGNO_POINTER_ALIGN (REGNO (x)) / BITS_PER_UNIT;
    5059              : 
    5060              : #ifdef PUSH_ROUNDING
    5061              :           /* If PUSH_ROUNDING is defined, it is possible for the
    5062              :              stack to be momentarily aligned only to that amount,
    5063              :              so we pick the least alignment.  */
    5064     16125916 :           if (x == stack_pointer_rtx && targetm.calls.push_argument (0))
    5065              :             {
    5066       749043 :               poly_uint64 rounded_1 = PUSH_ROUNDING (poly_int64 (1));
    5067       749043 :               alignment = MIN (known_alignment (rounded_1), alignment);
    5068              :             }
    5069              : #endif
    5070              : 
    5071     16125916 :           nonzero &= ~(alignment - 1);
    5072              :         }
    5073              : 
    5074    544252057 :       {
    5075    544252057 :         unsigned HOST_WIDE_INT nonzero_for_hook = nonzero;
    5076    544252057 :         rtx new_rtx = rtl_hooks.reg_nonzero_bits (x, xmode, mode,
    5077              :                                                   &nonzero_for_hook);
    5078              : 
    5079    544252057 :         if (new_rtx)
    5080            6 :           nonzero_for_hook &= cached_nonzero_bits (new_rtx, mode, known_x,
    5081              :                                                    known_mode, known_ret);
    5082              : 
    5083    544252057 :         return nonzero_for_hook;
    5084              :       }
    5085              : 
    5086              :     case MEM:
    5087              :       /* In many, if not most, RISC machines, reading a byte from memory
    5088              :          zeros the rest of the register.  Noticing that fact saves a lot
    5089              :          of extra zero-extends.  */
    5090              :       if (load_extend_op (xmode) == ZERO_EXTEND)
    5091              :         nonzero &= GET_MODE_MASK (xmode);
    5092              :       break;
    5093              : 
    5094      9448575 :     case EQ:  case NE:
    5095      9448575 :     case UNEQ:  case LTGT:
    5096      9448575 :     case GT:  case GTU:  case UNGT:
    5097      9448575 :     case LT:  case LTU:  case UNLT:
    5098      9448575 :     case GE:  case GEU:  case UNGE:
    5099      9448575 :     case LE:  case LEU:  case UNLE:
    5100      9448575 :     case UNORDERED: case ORDERED:
    5101              :       /* If this produces an integer result, we know which bits are set.
    5102              :          Code here used to clear bits outside the mode of X, but that is
    5103              :          now done above.  */
    5104              :       /* Mind that MODE is the mode the caller wants to look at this
    5105              :          operation in, and not the actual operation mode.  We can wind
    5106              :          up with (subreg:DI (gt:V4HI x y)), and we don't have anything
    5107              :          that describes the results of a vector compare.  */
    5108      9448575 :       if (GET_MODE_CLASS (xmode) == MODE_INT
    5109      9448575 :           && mode_width <= HOST_BITS_PER_WIDE_INT)
    5110      9448575 :         nonzero = STORE_FLAG_VALUE;
    5111              :       break;
    5112              : 
    5113       994605 :     case NEG:
    5114              : #if 0
    5115              :       /* Disabled to avoid exponential mutual recursion between nonzero_bits
    5116              :          and num_sign_bit_copies.  */
    5117              :       if (num_sign_bit_copies (XEXP (x, 0), xmode) == xmode_width)
    5118              :         nonzero = 1;
    5119              : #endif
    5120              : 
    5121       994605 :       if (xmode_width < mode_width)
    5122            0 :         nonzero |= (GET_MODE_MASK (mode) & ~GET_MODE_MASK (xmode));
    5123              :       break;
    5124              : 
    5125              :     case ABS:
    5126              : #if 0
    5127              :       /* Disabled to avoid exponential mutual recursion between nonzero_bits
    5128              :          and num_sign_bit_copies.  */
    5129              :       if (num_sign_bit_copies (XEXP (x, 0), xmode) == xmode_width)
    5130              :         nonzero = 1;
    5131              : #endif
    5132              :       break;
    5133              : 
    5134        11044 :     case TRUNCATE:
    5135        11044 :       nonzero &= (cached_nonzero_bits (XEXP (x, 0), mode,
    5136              :                                        known_x, known_mode, known_ret)
    5137        11044 :                   & GET_MODE_MASK (mode));
    5138        11044 :       break;
    5139              : 
    5140      7294526 :     case ZERO_EXTEND:
    5141      7294526 :       nonzero &= cached_nonzero_bits (XEXP (x, 0), mode,
    5142              :                                       known_x, known_mode, known_ret);
    5143      7294526 :       if (GET_MODE (XEXP (x, 0)) != VOIDmode)
    5144      7294526 :         nonzero &= GET_MODE_MASK (GET_MODE (XEXP (x, 0)));
    5145              :       break;
    5146              : 
    5147      1791303 :     case SIGN_EXTEND:
    5148              :       /* If the sign bit is known clear, this is the same as ZERO_EXTEND.
    5149              :          Otherwise, show all the bits in the outer mode but not the inner
    5150              :          may be nonzero.  */
    5151      1791303 :       inner_nz = cached_nonzero_bits (XEXP (x, 0), mode,
    5152              :                                       known_x, known_mode, known_ret);
    5153      1791303 :       if (GET_MODE (XEXP (x, 0)) != VOIDmode)
    5154              :         {
    5155      1791303 :           inner_nz &= GET_MODE_MASK (GET_MODE (XEXP (x, 0)));
    5156      1791303 :           if (val_signbit_known_set_p (GET_MODE (XEXP (x, 0)), inner_nz))
    5157      1770700 :             inner_nz |= (GET_MODE_MASK (mode)
    5158      1770700 :                          & ~GET_MODE_MASK (GET_MODE (XEXP (x, 0))));
    5159              :         }
    5160              : 
    5161      1791303 :       nonzero &= inner_nz;
    5162      1791303 :       break;
    5163              : 
    5164     17617615 :     case AND:
    5165     17617615 :       nonzero &= cached_nonzero_bits (XEXP (x, 0), mode,
    5166              :                                        known_x, known_mode, known_ret)
    5167     17617615 :                  & cached_nonzero_bits (XEXP (x, 1), mode,
    5168              :                                         known_x, known_mode, known_ret);
    5169     17617615 :       break;
    5170              : 
    5171     10123481 :     case XOR:   case IOR:
    5172     10123481 :     case UMIN:  case UMAX:  case SMIN:  case SMAX:
    5173     10123481 :       {
    5174     10123481 :         unsigned HOST_WIDE_INT nonzero0
    5175     10123481 :            = cached_nonzero_bits (XEXP (x, 0), mode,
    5176              :                                   known_x, known_mode, known_ret);
    5177              : 
    5178              :         /* Don't call nonzero_bits for the second time if it cannot change
    5179              :            anything.  */
    5180     10123481 :         if ((nonzero & nonzero0) != nonzero)
    5181      8433900 :           nonzero &= nonzero0
    5182      4216950 :                      | cached_nonzero_bits (XEXP (x, 1), mode,
    5183              :                                             known_x, known_mode, known_ret);
    5184              :       }
    5185              :       break;
    5186              : 
    5187     93722073 :     case PLUS:  case MINUS:
    5188     93722073 :     case MULT:
    5189     93722073 :     case DIV:   case UDIV:
    5190     93722073 :     case MOD:   case UMOD:
    5191              :       /* We can apply the rules of arithmetic to compute the number of
    5192              :          high- and low-order zero bits of these operations.  We start by
    5193              :          computing the width (position of the highest-order nonzero bit)
    5194              :          and the number of low-order zero bits for each value.  */
    5195     93722073 :       {
    5196     93722073 :         unsigned HOST_WIDE_INT nz0
    5197     93722073 :           = cached_nonzero_bits (XEXP (x, 0), mode,
    5198              :                                  known_x, known_mode, known_ret);
    5199     93722073 :         unsigned HOST_WIDE_INT nz1
    5200     93722073 :           = cached_nonzero_bits (XEXP (x, 1), mode,
    5201              :                                  known_x, known_mode, known_ret);
    5202     93722073 :         int sign_index = xmode_width - 1;
    5203     93722073 :         int width0 = floor_log2 (nz0) + 1;
    5204     93722073 :         int width1 = floor_log2 (nz1) + 1;
    5205     93722073 :         int low0 = ctz_or_zero (nz0);
    5206     93722073 :         int low1 = ctz_or_zero (nz1);
    5207     93722073 :         unsigned HOST_WIDE_INT op0_maybe_minusp
    5208     93722073 :           = nz0 & (HOST_WIDE_INT_1U << sign_index);
    5209     93722073 :         unsigned HOST_WIDE_INT op1_maybe_minusp
    5210              :           = nz1 & (HOST_WIDE_INT_1U << sign_index);
    5211     93722073 :         unsigned int result_width = mode_width;
    5212     93722073 :         int result_low = 0;
    5213              : 
    5214     93722073 :         switch (code)
    5215              :           {
    5216     65934417 :           case PLUS:
    5217     65934417 :             result_width = MAX (width0, width1) + 1;
    5218     65934417 :             result_low = MIN (low0, low1);
    5219              :             break;
    5220     17431846 :           case MINUS:
    5221     17431846 :             result_low = MIN (low0, low1);
    5222              :             break;
    5223      8293739 :           case MULT:
    5224      8293739 :             result_width = width0 + width1;
    5225      8293739 :             result_low = low0 + low1;
    5226      8293739 :             break;
    5227       813305 :           case DIV:
    5228       813305 :             if (width1 == 0)
    5229              :               break;
    5230       799381 :             if (!op0_maybe_minusp && !op1_maybe_minusp)
    5231        23777 :               result_width = width0;
    5232              :             break;
    5233       272567 :           case UDIV:
    5234       272567 :             if (width1 == 0)
    5235              :               break;
    5236       271691 :             result_width = width0;
    5237       271691 :             break;
    5238       570533 :           case MOD:
    5239       570533 :             if (width1 == 0)
    5240              :               break;
    5241       558382 :             if (!op0_maybe_minusp && !op1_maybe_minusp)
    5242        22161 :               result_width = MIN (width0, width1);
    5243       558382 :             result_low = MIN (low0, low1);
    5244              :             break;
    5245       405666 :           case UMOD:
    5246       405666 :             if (width1 == 0)
    5247              :               break;
    5248       405554 :             result_width = MIN (width0, width1);
    5249       405554 :             result_low = MIN (low0, low1);
    5250              :             break;
    5251              :           default:
    5252              :             gcc_unreachable ();
    5253              :           }
    5254              : 
    5255              :         /* Note that mode_width <= HOST_BITS_PER_WIDE_INT, see above.  */
    5256     93722073 :         if (result_width < mode_width)
    5257      4657303 :           nonzero &= (HOST_WIDE_INT_1U << result_width) - 1;
    5258              : 
    5259     93722073 :         if (result_low > 0)
    5260              :           {
    5261      7574439 :             if (result_low < HOST_BITS_PER_WIDE_INT)
    5262      7574427 :               nonzero &= ~((HOST_WIDE_INT_1U << result_low) - 1);
    5263              :             else
    5264              :               nonzero = 0;
    5265              :           }
    5266              :       }
    5267              :       break;
    5268              : 
    5269      1194627 :     case ZERO_EXTRACT:
    5270      1194627 :       if (CONST_INT_P (XEXP (x, 1))
    5271      1194254 :           && INTVAL (XEXP (x, 1)) < HOST_BITS_PER_WIDE_INT)
    5272      1194015 :         nonzero &= (HOST_WIDE_INT_1U << INTVAL (XEXP (x, 1))) - 1;
    5273              :       break;
    5274              : 
    5275     86158907 :     case SUBREG:
    5276              :       /* If this is a SUBREG formed for a promoted variable that has
    5277              :          been zero-extended, we know that at least the high-order bits
    5278              :          are zero, though others might be too.  */
    5279     86158907 :       if (SUBREG_PROMOTED_VAR_P (x) && SUBREG_PROMOTED_UNSIGNED_P (x))
    5280        49755 :         nonzero = GET_MODE_MASK (xmode)
    5281        49755 :                   & cached_nonzero_bits (SUBREG_REG (x), xmode,
    5282              :                                          known_x, known_mode, known_ret);
    5283              : 
    5284              :       /* If the inner mode is a single word for both the host and target
    5285              :          machines, we can compute this from which bits of the inner
    5286              :          object might be nonzero.  */
    5287     86158907 :       inner_mode = GET_MODE (SUBREG_REG (x));
    5288     86158907 :       if (GET_MODE_PRECISION (inner_mode).is_constant (&inner_width)
    5289     91717669 :           && inner_width <= BITS_PER_WORD
    5290              :           && inner_width <= HOST_BITS_PER_WIDE_INT)
    5291              :         {
    5292     81635541 :           nonzero &= cached_nonzero_bits (SUBREG_REG (x), mode,
    5293              :                                           known_x, known_mode, known_ret);
    5294              : 
    5295              :           /* On a typical CISC machine, accessing an object in a wider mode
    5296              :              causes the high-order bits to become undefined.  So they are
    5297              :              not known to be zero.
    5298              : 
    5299              :              On a typical RISC machine, we only have to worry about the way
    5300              :              loads are extended.  Otherwise, if we get a reload for the inner
    5301              :              part, it may be loaded from the stack, and then we may lose all
    5302              :              the zero bits that existed before the store to the stack.  */
    5303     81635541 :           rtx_code extend_op;
    5304     81635541 :           if ((!WORD_REGISTER_OPERATIONS
    5305              :                || ((extend_op = load_extend_op (inner_mode)) == SIGN_EXTEND
    5306              :                    ? val_signbit_known_set_p (inner_mode, nonzero)
    5307              :                    : extend_op != ZERO_EXTEND)
    5308              :                || !MEM_P (SUBREG_REG (x)))
    5309              :               && xmode_width > inner_width)
    5310     57148002 :             nonzero
    5311     57148002 :               |= (GET_MODE_MASK (GET_MODE (x)) & ~GET_MODE_MASK (inner_mode));
    5312              :         }
    5313              :       break;
    5314              : 
    5315     58283854 :     case ASHIFT:
    5316     58283854 :     case ASHIFTRT:
    5317     58283854 :     case LSHIFTRT:
    5318     58283854 :     case ROTATE:
    5319     58283854 :     case ROTATERT:
    5320              :       /* The nonzero bits are in two classes: any bits within MODE
    5321              :          that aren't in xmode are always significant.  The rest of the
    5322              :          nonzero bits are those that are significant in the operand of
    5323              :          the shift when shifted the appropriate number of bits.  This
    5324              :          shows that high-order bits are cleared by the right shift and
    5325              :          low-order bits by left shifts.  */
    5326     58283854 :       if (CONST_INT_P (XEXP (x, 1))
    5327     56664249 :           && INTVAL (XEXP (x, 1)) >= 0
    5328     56664177 :           && INTVAL (XEXP (x, 1)) < HOST_BITS_PER_WIDE_INT
    5329     56664089 :           && INTVAL (XEXP (x, 1)) < xmode_width)
    5330              :         {
    5331     56664016 :           int count = INTVAL (XEXP (x, 1));
    5332     56664016 :           unsigned HOST_WIDE_INT mode_mask = GET_MODE_MASK (xmode);
    5333     56664016 :           unsigned HOST_WIDE_INT op_nonzero
    5334     56664016 :             = cached_nonzero_bits (XEXP (x, 0), mode,
    5335              :                                    known_x, known_mode, known_ret);
    5336     56664016 :           unsigned HOST_WIDE_INT inner = op_nonzero & mode_mask;
    5337     56664016 :           unsigned HOST_WIDE_INT outer = 0;
    5338              : 
    5339     56664016 :           if (mode_width > xmode_width)
    5340            0 :             outer = (op_nonzero & nonzero & ~mode_mask);
    5341              : 
    5342     56664016 :           switch (code)
    5343              :             {
    5344     32434819 :             case ASHIFT:
    5345     32434819 :               inner <<= count;
    5346     32434819 :               break;
    5347              : 
    5348     14725570 :             case LSHIFTRT:
    5349     14725570 :               inner >>= count;
    5350     14725570 :               break;
    5351              : 
    5352      9397471 :             case ASHIFTRT:
    5353      9397471 :               inner >>= count;
    5354              : 
    5355              :               /* If the sign bit may have been nonzero before the shift, we
    5356              :                  need to mark all the places it could have been copied to
    5357              :                  by the shift as possibly nonzero.  */
    5358      9397471 :               if (inner & (HOST_WIDE_INT_1U << (xmode_width - 1 - count)))
    5359      9383457 :                 inner |= (((HOST_WIDE_INT_1U << count) - 1)
    5360      9383457 :                           << (xmode_width - count));
    5361              :               break;
    5362              : 
    5363        69262 :             case ROTATE:
    5364        69262 :               inner = (inner << (count % xmode_width)
    5365        69262 :                        | (inner >> (xmode_width - (count % xmode_width))))
    5366              :                       & mode_mask;
    5367        69262 :               break;
    5368              : 
    5369        36894 :             case ROTATERT:
    5370        36894 :               inner = (inner >> (count % xmode_width)
    5371        36894 :                        | (inner << (xmode_width - (count % xmode_width))))
    5372              :                       & mode_mask;
    5373        36894 :               break;
    5374              : 
    5375              :             default:
    5376              :               gcc_unreachable ();
    5377              :             }
    5378              : 
    5379     56664016 :           nonzero &= (outer | inner);
    5380              :         }
    5381              :       break;
    5382              : 
    5383         5442 :     case FFS:
    5384         5442 :     case POPCOUNT:
    5385              :       /* This is at most the number of bits in the mode.  */
    5386         5442 :       nonzero = (HOST_WIDE_INT_UC (2) << (floor_log2 (op_mode_width))) - 1;
    5387         5442 :       break;
    5388              : 
    5389       542730 :     case CLZ:
    5390              :       /* If CLZ has a known value at zero, then the nonzero bits are
    5391              :          that value, plus the number of bits in the operand minus one.
    5392              :          The operand mode may differ from MODE, but if it is not a scalar
    5393              :          integer mode, don't try to get nonzero bits as currently nonzero
    5394              :          is not a poly_int.  */
    5395       542730 :       if (is_a <scalar_int_mode> (GET_MODE (XEXP (x, 0)), &op_imode)
    5396      1085436 :           && CLZ_DEFINED_VALUE_AT_ZERO (op_imode, nonzero))
    5397         1586 :         nonzero
    5398         3172 :           |= (HOST_WIDE_INT_1U << (floor_log2 (op_mode_width))) - 1;
    5399              :       else
    5400              :         nonzero = -1;
    5401              :       break;
    5402              : 
    5403        72895 :     case CTZ:
    5404              :       /* If CTZ has a known value at zero, then the nonzero bits are
    5405              :          that value, plus the number of bits in the operand minus one.
    5406              :          See above for the operand mode.  */
    5407        72895 :       if (is_a <scalar_int_mode> (GET_MODE (XEXP (x, 0)), &op_imode)
    5408       145790 :           && CTZ_DEFINED_VALUE_AT_ZERO (op_imode, nonzero))
    5409         2381 :         nonzero
    5410         4762 :           |= (HOST_WIDE_INT_1U << (floor_log2 (op_mode_width))) - 1;
    5411              :       else
    5412              :         nonzero = -1;
    5413              :       break;
    5414              : 
    5415            8 :     case CLRSB:
    5416              :       /* This is at most the number of bits in the mode minus 1.  */
    5417            8 :       nonzero = (HOST_WIDE_INT_1U << (floor_log2 (op_mode_width))) - 1;
    5418            8 :       break;
    5419              : 
    5420              :     case PARITY:
    5421      9448575 :       nonzero = 1;
    5422              :       break;
    5423              : 
    5424      4319162 :     case IF_THEN_ELSE:
    5425      4319162 :       {
    5426      4319162 :         unsigned HOST_WIDE_INT nonzero_true
    5427      4319162 :           = cached_nonzero_bits (XEXP (x, 1), mode,
    5428              :                                  known_x, known_mode, known_ret);
    5429              : 
    5430              :         /* Don't call nonzero_bits for the second time if it cannot change
    5431              :            anything.  */
    5432      4319162 :         if ((nonzero & nonzero_true) != nonzero)
    5433      3466212 :           nonzero &= nonzero_true
    5434      1733106 :                      | cached_nonzero_bits (XEXP (x, 2), mode,
    5435              :                                             known_x, known_mode, known_ret);
    5436              :       }
    5437              :       break;
    5438              : 
    5439              :     default:
    5440              :       break;
    5441              :     }
    5442              : 
    5443              :   return nonzero;
    5444              : }
    5445              : 
    5446              : /* See the macro definition above.  */
    5447              : #undef cached_num_sign_bit_copies
    5448              : 
    5449              : 
    5450              : /* Return true if num_sign_bit_copies1 might recurse into both operands
    5451              :    of X.  */
    5452              : 
    5453              : static inline bool
    5454    433846088 : num_sign_bit_copies_binary_arith_p (const_rtx x)
    5455              : {
    5456    433846088 :   if (!ARITHMETIC_P (x))
    5457              :     return false;
    5458     68178094 :   switch (GET_CODE (x))
    5459              :     {
    5460              :     case IOR:
    5461              :     case AND:
    5462              :     case XOR:
    5463              :     case SMIN:
    5464              :     case SMAX:
    5465              :     case UMIN:
    5466              :     case UMAX:
    5467              :     case PLUS:
    5468              :     case MINUS:
    5469              :     case MULT:
    5470              :       return true;
    5471              :     default:
    5472              :       return false;
    5473              :     }
    5474              : }
    5475              : 
    5476              : /* The function cached_num_sign_bit_copies is a wrapper around
    5477              :    num_sign_bit_copies1.  It avoids exponential behavior in
    5478              :    num_sign_bit_copies1 when X has identical subexpressions on the
    5479              :    first or the second level.  */
    5480              : 
    5481              : static unsigned int
    5482    349794061 : cached_num_sign_bit_copies (const_rtx x, scalar_int_mode mode,
    5483              :                             const_rtx known_x, machine_mode known_mode,
    5484              :                             unsigned int known_ret)
    5485              : {
    5486    349794061 :   if (x == known_x && mode == known_mode)
    5487              :     return known_ret;
    5488              : 
    5489              :   /* Try to find identical subexpressions.  If found call
    5490              :      num_sign_bit_copies1 on X with the subexpressions as KNOWN_X and
    5491              :      the precomputed value for the subexpression as KNOWN_RET.  */
    5492              : 
    5493    347949113 :   if (num_sign_bit_copies_binary_arith_p (x))
    5494              :     {
    5495     43359679 :       rtx x0 = XEXP (x, 0);
    5496     43359679 :       rtx x1 = XEXP (x, 1);
    5497              : 
    5498              :       /* Check the first level.  */
    5499     43359679 :       if (x0 == x1)
    5500        15300 :         return
    5501        15300 :           num_sign_bit_copies1 (x, mode, x0, mode,
    5502              :                                 cached_num_sign_bit_copies (x0, mode, known_x,
    5503              :                                                             known_mode,
    5504        15300 :                                                             known_ret));
    5505              : 
    5506              :       /* Check the second level.  */
    5507     43344379 :       if (num_sign_bit_copies_binary_arith_p (x0)
    5508     43344379 :           && (x1 == XEXP (x0, 0) || x1 == XEXP (x0, 1)))
    5509       791783 :         return
    5510       791783 :           num_sign_bit_copies1 (x, mode, x1, mode,
    5511              :                                 cached_num_sign_bit_copies (x1, mode, known_x,
    5512              :                                                             known_mode,
    5513       791783 :                                                             known_ret));
    5514              : 
    5515     42552596 :       if (num_sign_bit_copies_binary_arith_p (x1)
    5516     42552596 :           && (x0 == XEXP (x1, 0) || x0 == XEXP (x1, 1)))
    5517          419 :         return
    5518          419 :           num_sign_bit_copies1 (x, mode, x0, mode,
    5519              :                                 cached_num_sign_bit_copies (x0, mode, known_x,
    5520              :                                                             known_mode,
    5521          419 :                                                             known_ret));
    5522              :     }
    5523              : 
    5524    347141611 :   return num_sign_bit_copies1 (x, mode, known_x, known_mode, known_ret);
    5525              : }
    5526              : 
    5527              : /* Return the number of bits at the high-order end of X that are known to
    5528              :    be equal to the sign bit.  X will be used in mode MODE.  The returned
    5529              :    value will always be between 1 and the number of bits in MODE.  */
    5530              : 
    5531              : static unsigned int
    5532    347949113 : num_sign_bit_copies1 (const_rtx x, scalar_int_mode mode, const_rtx known_x,
    5533              :                       machine_mode known_mode,
    5534              :                       unsigned int known_ret)
    5535              : {
    5536    347949113 :   enum rtx_code code = GET_CODE (x);
    5537    347949113 :   unsigned int bitwidth = GET_MODE_PRECISION (mode);
    5538    347949113 :   int num0, num1, result;
    5539    347949113 :   unsigned HOST_WIDE_INT nonzero;
    5540              : 
    5541    347949113 :   if (CONST_INT_P (x))
    5542              :     {
    5543              :       /* If the constant is negative, take its 1's complement and remask.
    5544              :          Then see how many zero bits we have.  */
    5545     38375748 :       nonzero = UINTVAL (x) & GET_MODE_MASK (mode);
    5546     38375748 :       if (bitwidth <= HOST_BITS_PER_WIDE_INT
    5547     38069398 :           && (nonzero & (HOST_WIDE_INT_1U << (bitwidth - 1))) != 0)
    5548     15973316 :         nonzero = (~nonzero) & GET_MODE_MASK (mode);
    5549              : 
    5550     38375748 :       return (nonzero == 0 ? bitwidth : bitwidth - floor_log2 (nonzero) - 1);
    5551              :     }
    5552              : 
    5553    309573365 :   scalar_int_mode xmode, inner_mode;
    5554    309573365 :   if (!is_a <scalar_int_mode> (GET_MODE (x), &xmode))
    5555              :     return 1;
    5556              : 
    5557    309231537 :   unsigned int xmode_width = GET_MODE_PRECISION (xmode);
    5558              : 
    5559              :   /* For a smaller mode, just ignore the high bits.  */
    5560    309231537 :   if (bitwidth < xmode_width)
    5561              :     {
    5562        33990 :       num0 = cached_num_sign_bit_copies (x, xmode,
    5563              :                                          known_x, known_mode, known_ret);
    5564        33990 :       return MAX (1, num0 - (int) (xmode_width - bitwidth));
    5565              :     }
    5566              : 
    5567    309197547 :   if (bitwidth > xmode_width)
    5568              :     {
    5569              :       /* If this machine does not do all register operations on the entire
    5570              :          register and MODE is wider than the mode of X, we can say nothing
    5571              :          at all about the high-order bits.  We extend this reasoning to RISC
    5572              :          machines for operations that might not operate on full registers.  */
    5573              :       if (!(WORD_REGISTER_OPERATIONS && word_register_operation_p (x)))
    5574              :         return 1;
    5575              : 
    5576              :       /* Likewise on machines that do, if the mode of the object is smaller
    5577              :          than a word and loads of that size don't sign extend, we can say
    5578              :          nothing about the high order bits.  */
    5579              :       if (xmode_width < BITS_PER_WORD
    5580              :           && load_extend_op (xmode) != SIGN_EXTEND)
    5581              :         return 1;
    5582              :     }
    5583              : 
    5584              :   /* Please keep num_sign_bit_copies_binary_arith_p above in sync with
    5585              :      the code in the switch below.  */
    5586    309197490 :   switch (code)
    5587              :     {
    5588    166256402 :     case REG:
    5589              : 
    5590              : #if defined(POINTERS_EXTEND_UNSIGNED)
    5591              :       /* If pointers extend signed and this is a pointer in Pmode, say that
    5592              :          all the bits above ptr_mode are known to be sign bit copies.  */
    5593              :       /* As we do not know which address space the pointer is referring to,
    5594              :          we can do this only if the target does not support different pointer
    5595              :          or address modes depending on the address space.  */
    5596    166256402 :       if (target_default_pointer_address_modes_p ()
    5597              :           && ! POINTERS_EXTEND_UNSIGNED && xmode == Pmode
    5598              :           && mode == Pmode && REG_POINTER (x)
    5599              :           && !targetm.have_ptr_extend ())
    5600              :         return GET_MODE_PRECISION (Pmode) - GET_MODE_PRECISION (ptr_mode) + 1;
    5601              : #endif
    5602              : 
    5603    166256402 :       {
    5604    166256402 :         unsigned int copies_for_hook = 1, copies = 1;
    5605    166256402 :         rtx new_rtx = rtl_hooks.reg_num_sign_bit_copies (x, xmode, mode,
    5606              :                                                          &copies_for_hook);
    5607              : 
    5608    166256402 :         if (new_rtx)
    5609            5 :           copies = cached_num_sign_bit_copies (new_rtx, mode, known_x,
    5610              :                                                known_mode, known_ret);
    5611              : 
    5612    166256402 :         if (copies > 1 || copies_for_hook > 1)
    5613     22871078 :           return MAX (copies, copies_for_hook);
    5614              : 
    5615              :         /* Else, use nonzero_bits to guess num_sign_bit_copies (see below).  */
    5616              :       }
    5617    143385324 :       break;
    5618              : 
    5619              :     case MEM:
    5620              :       /* Some RISC machines sign-extend all loads of smaller than a word.  */
    5621              :       if (load_extend_op (xmode) == SIGN_EXTEND)
    5622              :         return MAX (1, ((int) bitwidth - (int) xmode_width + 1));
    5623              :       break;
    5624              : 
    5625     22618213 :     case SUBREG:
    5626              :       /* If this is a SUBREG for a promoted object that is sign-extended
    5627              :          and we are looking at it in a wider mode, we know that at least the
    5628              :          high-order bits are known to be sign bit copies.  */
    5629              : 
    5630     22618213 :       if (SUBREG_PROMOTED_VAR_P (x) && SUBREG_PROMOTED_SIGNED_P (x))
    5631              :         {
    5632            0 :           num0 = cached_num_sign_bit_copies (SUBREG_REG (x), mode,
    5633              :                                              known_x, known_mode, known_ret);
    5634            0 :           return MAX ((int) bitwidth - (int) xmode_width + 1, num0);
    5635              :         }
    5636              : 
    5637     22618213 :       if (is_a <scalar_int_mode> (GET_MODE (SUBREG_REG (x)), &inner_mode))
    5638              :         {
    5639              :           /* For a smaller object, just ignore the high bits.  */
    5640     22346112 :           if (bitwidth <= GET_MODE_PRECISION (inner_mode))
    5641              :             {
    5642      8470713 :               num0 = cached_num_sign_bit_copies (SUBREG_REG (x), inner_mode,
    5643              :                                                  known_x, known_mode,
    5644              :                                                  known_ret);
    5645      8470713 :               return MAX (1, num0 - (int) (GET_MODE_PRECISION (inner_mode)
    5646              :                                            - bitwidth));
    5647              :             }
    5648              : 
    5649              :           /* For paradoxical SUBREGs on machines where all register operations
    5650              :              affect the entire register, just look inside.  Note that we are
    5651              :              passing MODE to the recursive call, so the number of sign bit
    5652              :              copies will remain relative to that mode, not the inner mode.
    5653              : 
    5654              :              This works only if loads sign extend.  Otherwise, if we get a
    5655              :              reload for the inner part, it may be loaded from the stack, and
    5656              :              then we lose all sign bit copies that existed before the store
    5657              :              to the stack.  */
    5658              :           if (WORD_REGISTER_OPERATIONS
    5659              :               && load_extend_op (inner_mode) == SIGN_EXTEND
    5660              :               && paradoxical_subreg_p (x)
    5661              :               && MEM_P (SUBREG_REG (x)))
    5662              :             return cached_num_sign_bit_copies (SUBREG_REG (x), mode,
    5663              :                                                known_x, known_mode, known_ret);
    5664              :         }
    5665              :       break;
    5666              : 
    5667         3145 :     case SIGN_EXTRACT:
    5668         3145 :       if (CONST_INT_P (XEXP (x, 1)))
    5669         3145 :         return MAX (1, (int) bitwidth - INTVAL (XEXP (x, 1)));
    5670              :       break;
    5671              : 
    5672      1775799 :     case SIGN_EXTEND:
    5673      1775799 :       if (is_a <scalar_int_mode> (GET_MODE (XEXP (x, 0)), &inner_mode))
    5674      1775799 :         return (bitwidth - GET_MODE_PRECISION (inner_mode)
    5675      1775799 :                 + cached_num_sign_bit_copies (XEXP (x, 0), inner_mode,
    5676      1775799 :                                               known_x, known_mode, known_ret));
    5677              :       break;
    5678              : 
    5679          260 :     case TRUNCATE:
    5680              :       /* For a smaller object, just ignore the high bits.  */
    5681          260 :       inner_mode = as_a <scalar_int_mode> (GET_MODE (XEXP (x, 0)));
    5682          260 :       num0 = cached_num_sign_bit_copies (XEXP (x, 0), inner_mode,
    5683              :                                          known_x, known_mode, known_ret);
    5684          260 :       return MAX (1, (num0 - (int) (GET_MODE_PRECISION (inner_mode)
    5685              :                                     - bitwidth)));
    5686              : 
    5687      1470761 :     case NOT:
    5688      1470761 :       return cached_num_sign_bit_copies (XEXP (x, 0), mode,
    5689      1470761 :                                          known_x, known_mode, known_ret);
    5690              : 
    5691        22780 :     case ROTATE:       case ROTATERT:
    5692              :       /* If we are rotating left by a number of bits less than the number
    5693              :          of sign bit copies, we can just subtract that amount from the
    5694              :          number.  */
    5695        22780 :       if (CONST_INT_P (XEXP (x, 1))
    5696        12307 :           && INTVAL (XEXP (x, 1)) >= 0
    5697        12304 :           && INTVAL (XEXP (x, 1)) < (int) bitwidth)
    5698              :         {
    5699        12304 :           num0 = cached_num_sign_bit_copies (XEXP (x, 0), mode,
    5700              :                                              known_x, known_mode, known_ret);
    5701        12304 :           return MAX (1, num0 - (code == ROTATE ? INTVAL (XEXP (x, 1))
    5702              :                                  : (int) bitwidth - INTVAL (XEXP (x, 1))));
    5703              :         }
    5704              :       break;
    5705              : 
    5706       665230 :     case NEG:
    5707              :       /* In general, this subtracts one sign bit copy.  But if the value
    5708              :          is known to be positive, the number of sign bit copies is the
    5709              :          same as that of the input.  Finally, if the input has just one bit
    5710              :          that might be nonzero, all the bits are copies of the sign bit.  */
    5711       665230 :       num0 = cached_num_sign_bit_copies (XEXP (x, 0), mode,
    5712              :                                          known_x, known_mode, known_ret);
    5713       665230 :       if (bitwidth > HOST_BITS_PER_WIDE_INT)
    5714        17138 :         return num0 > 1 ? num0 - 1 : 1;
    5715              : 
    5716       648092 :       nonzero = nonzero_bits (XEXP (x, 0), mode);
    5717       648092 :       if (nonzero == 1)
    5718              :         return bitwidth;
    5719              : 
    5720       356024 :       if (num0 > 1
    5721        87820 :           && ((HOST_WIDE_INT_1U << (bitwidth - 1)) & nonzero))
    5722        51156 :         num0--;
    5723              : 
    5724       356024 :       return num0;
    5725              : 
    5726      5862236 :     case IOR:   case AND:   case XOR:
    5727      5862236 :     case SMIN:  case SMAX:  case UMIN:  case UMAX:
    5728              :       /* Logical operations will preserve the number of sign-bit copies.
    5729              :          MIN and MAX operations always return one of the operands.  */
    5730      5862236 :       num0 = cached_num_sign_bit_copies (XEXP (x, 0), mode,
    5731              :                                          known_x, known_mode, known_ret);
    5732      5862236 :       num1 = cached_num_sign_bit_copies (XEXP (x, 1), mode,
    5733              :                                          known_x, known_mode, known_ret);
    5734              : 
    5735              :       /* If num1 is clearing some of the top bits then regardless of
    5736              :          the other term, we are guaranteed to have at least that many
    5737              :          high-order zero bits.  */
    5738      5862236 :       if (code == AND
    5739      5862236 :           && num1 > 1
    5740      2393930 :           && bitwidth <= HOST_BITS_PER_WIDE_INT
    5741      2387533 :           && CONST_INT_P (XEXP (x, 1))
    5742      2184862 :           && (UINTVAL (XEXP (x, 1))
    5743      2184862 :               & (HOST_WIDE_INT_1U << (bitwidth - 1))) == 0)
    5744              :         return num1;
    5745              : 
    5746              :       /* Similarly for IOR when setting high-order bits.  */
    5747      4398039 :       if (code == IOR
    5748      4398039 :           && num1 > 1
    5749       347544 :           && bitwidth <= HOST_BITS_PER_WIDE_INT
    5750       345956 :           && CONST_INT_P (XEXP (x, 1))
    5751        91248 :           && (UINTVAL (XEXP (x, 1))
    5752        91248 :               & (HOST_WIDE_INT_1U << (bitwidth - 1))) != 0)
    5753              :         return num1;
    5754              : 
    5755      4393839 :       return MIN (num0, num1);
    5756              : 
    5757     36112318 :     case PLUS:  case MINUS:
    5758              :       /* For addition and subtraction, we can have a 1-bit carry.  However,
    5759              :          if we are subtracting 1 from a positive number, there will not
    5760              :          be such a carry.  Furthermore, if the positive number is known to
    5761              :          be 0 or 1, we know the result is either -1 or 0.  */
    5762              : 
    5763     36112318 :       if (code == PLUS && XEXP (x, 1) == constm1_rtx
    5764      1338532 :           && bitwidth <= HOST_BITS_PER_WIDE_INT)
    5765              :         {
    5766      1333454 :           nonzero = nonzero_bits (XEXP (x, 0), mode);
    5767      1333454 :           if (((HOST_WIDE_INT_1U << (bitwidth - 1)) & nonzero) == 0)
    5768        95037 :             return (nonzero == 1 || nonzero == 0 ? bitwidth
    5769        88934 :                     : bitwidth - floor_log2 (nonzero) - 1);
    5770              :         }
    5771              : 
    5772     36017281 :       num0 = cached_num_sign_bit_copies (XEXP (x, 0), mode,
    5773              :                                          known_x, known_mode, known_ret);
    5774     36017281 :       num1 = cached_num_sign_bit_copies (XEXP (x, 1), mode,
    5775              :                                          known_x, known_mode, known_ret);
    5776     36017281 :       result = MAX (1, MIN (num0, num1) - 1);
    5777              : 
    5778     36017281 :       return result;
    5779              : 
    5780      1384943 :     case MULT:
    5781              :       /* The number of bits of the product is the sum of the number of
    5782              :          bits of both terms.  However, unless one of the terms if known
    5783              :          to be positive, we must allow for an additional bit since negating
    5784              :          a negative number can remove one sign bit copy.  */
    5785              : 
    5786      1384943 :       num0 = cached_num_sign_bit_copies (XEXP (x, 0), mode,
    5787              :                                          known_x, known_mode, known_ret);
    5788      1384943 :       num1 = cached_num_sign_bit_copies (XEXP (x, 1), mode,
    5789              :                                          known_x, known_mode, known_ret);
    5790              : 
    5791      1384943 :       result = bitwidth - (bitwidth - num0) - (bitwidth - num1);
    5792      1384943 :       if (result > 0
    5793      1384943 :           && (bitwidth > HOST_BITS_PER_WIDE_INT
    5794       329102 :               || (((nonzero_bits (XEXP (x, 0), mode)
    5795       329102 :                     & (HOST_WIDE_INT_1U << (bitwidth - 1))) != 0)
    5796       184857 :                   && ((nonzero_bits (XEXP (x, 1), mode)
    5797              :                        & (HOST_WIDE_INT_1U << (bitwidth - 1)))
    5798       184857 :                       != 0))))
    5799        32437 :         result--;
    5800              : 
    5801      1384943 :       return MAX (1, result);
    5802              : 
    5803       125567 :     case UDIV:
    5804              :       /* The result must be <= the first operand.  If the first operand
    5805              :          has the high bit set, we know nothing about the number of sign
    5806              :          bit copies.  */
    5807       125567 :       if (bitwidth > HOST_BITS_PER_WIDE_INT)
    5808              :         return 1;
    5809       125567 :       else if ((nonzero_bits (XEXP (x, 0), mode)
    5810       125567 :                 & (HOST_WIDE_INT_1U << (bitwidth - 1))) != 0)
    5811              :         return 1;
    5812              :       else
    5813        23413 :         return cached_num_sign_bit_copies (XEXP (x, 0), mode,
    5814        23413 :                                            known_x, known_mode, known_ret);
    5815              : 
    5816       123089 :     case UMOD:
    5817              :       /* The result must be <= the second operand.  If the second operand
    5818              :          has (or just might have) the high bit set, we know nothing about
    5819              :          the number of sign bit copies.  */
    5820       123089 :       if (bitwidth > HOST_BITS_PER_WIDE_INT)
    5821              :         return 1;
    5822       123089 :       else if ((nonzero_bits (XEXP (x, 1), mode)
    5823       123089 :                 & (HOST_WIDE_INT_1U << (bitwidth - 1))) != 0)
    5824              :         return 1;
    5825              :       else
    5826        30931 :         return cached_num_sign_bit_copies (XEXP (x, 1), mode,
    5827        30931 :                                            known_x, known_mode, known_ret);
    5828              : 
    5829       246645 :     case DIV:
    5830              :       /* Similar to unsigned division, except that we have to worry about
    5831              :          the case where the divisor is negative, in which case we have
    5832              :          to add 1.  */
    5833       246645 :       result = cached_num_sign_bit_copies (XEXP (x, 0), mode,
    5834              :                                            known_x, known_mode, known_ret);
    5835       246645 :       if (result > 1
    5836       246645 :           && (bitwidth > HOST_BITS_PER_WIDE_INT
    5837        21516 :               || (nonzero_bits (XEXP (x, 1), mode)
    5838        21516 :                   & (HOST_WIDE_INT_1U << (bitwidth - 1))) != 0))
    5839        18979 :         result--;
    5840              : 
    5841       246645 :       return result;
    5842              : 
    5843       167425 :     case MOD:
    5844       167425 :       result = cached_num_sign_bit_copies (XEXP (x, 1), mode,
    5845              :                                            known_x, known_mode, known_ret);
    5846       167425 :       if (result > 1
    5847       167425 :           && (bitwidth > HOST_BITS_PER_WIDE_INT
    5848        22960 :               || (nonzero_bits (XEXP (x, 1), mode)
    5849        22960 :                   & (HOST_WIDE_INT_1U << (bitwidth - 1))) != 0))
    5850        10930 :         result--;
    5851              : 
    5852       167425 :       return result;
    5853              : 
    5854      1100366 :     case ASHIFTRT:
    5855              :       /* Shifts by a constant add to the number of bits equal to the
    5856              :          sign bit.  */
    5857      1100366 :       num0 = cached_num_sign_bit_copies (XEXP (x, 0), mode,
    5858              :                                          known_x, known_mode, known_ret);
    5859      1100366 :       if (CONST_INT_P (XEXP (x, 1))
    5860      1056466 :           && INTVAL (XEXP (x, 1)) > 0
    5861      1056466 :           && INTVAL (XEXP (x, 1)) < xmode_width)
    5862      1056466 :         num0 = MIN ((int) bitwidth, num0 + INTVAL (XEXP (x, 1)));
    5863              : 
    5864      1100366 :       return num0;
    5865              : 
    5866      9328359 :     case ASHIFT:
    5867              :       /* Left shifts destroy copies.  */
    5868      9328359 :       if (!CONST_INT_P (XEXP (x, 1))
    5869      9128865 :           || INTVAL (XEXP (x, 1)) < 0
    5870      9128858 :           || INTVAL (XEXP (x, 1)) >= (int) bitwidth
    5871      9128816 :           || INTVAL (XEXP (x, 1)) >= xmode_width)
    5872              :         return 1;
    5873              : 
    5874      9128816 :       num0 = cached_num_sign_bit_copies (XEXP (x, 0), mode,
    5875              :                                          known_x, known_mode, known_ret);
    5876      9128816 :       return MAX (1, num0 - INTVAL (XEXP (x, 1)));
    5877              : 
    5878       834484 :     case IF_THEN_ELSE:
    5879       834484 :       num0 = cached_num_sign_bit_copies (XEXP (x, 1), mode,
    5880              :                                          known_x, known_mode, known_ret);
    5881       834484 :       num1 = cached_num_sign_bit_copies (XEXP (x, 2), mode,
    5882              :                                          known_x, known_mode, known_ret);
    5883       834484 :       return MIN (num0, num1);
    5884              : 
    5885      2210223 :     case EQ:  case NE:  case GE:  case GT:  case LE:  case LT:
    5886      2210223 :     case UNEQ:  case LTGT:  case UNGE:  case UNGT:  case UNLE:  case UNLT:
    5887      2210223 :     case GEU: case GTU: case LEU: case LTU:
    5888      2210223 :     case UNORDERED: case ORDERED:
    5889              :       /* If the constant is negative, take its 1's complement and remask.
    5890              :          Then see how many zero bits we have.  */
    5891      2210223 :       nonzero = STORE_FLAG_VALUE;
    5892      2210223 :       if (bitwidth <= HOST_BITS_PER_WIDE_INT
    5893      2210223 :           && (nonzero & (HOST_WIDE_INT_1U << (bitwidth - 1))) != 0)
    5894            0 :         nonzero = (~nonzero) & GET_MODE_MASK (mode);
    5895              : 
    5896      2210223 :       return (nonzero == 0 ? bitwidth : bitwidth - floor_log2 (nonzero) - 1);
    5897              : 
    5898              :     default:
    5899              :       break;
    5900              :     }
    5901              : 
    5902              :   /* If we haven't been able to figure it out by one of the above rules,
    5903              :      see if some of the high-order bits are known to be zero.  If so,
    5904              :      count those bits and return one less than that amount.  If we can't
    5905              :      safely compute the mask for this mode, always return BITWIDTH.  */
    5906              : 
    5907    216432545 :   bitwidth = GET_MODE_PRECISION (mode);
    5908    216432545 :   if (bitwidth > HOST_BITS_PER_WIDE_INT)
    5909              :     return 1;
    5910              : 
    5911    210358495 :   nonzero = nonzero_bits (x, mode);
    5912    210358495 :   return nonzero & (HOST_WIDE_INT_1U << (bitwidth - 1))
    5913    215892071 :          ? 1 : bitwidth - floor_log2 (nonzero) - 1;
    5914              : }
    5915              : 
    5916              : /* Calculate the rtx_cost of a single instruction pattern.  A return value of
    5917              :    zero indicates an instruction pattern without a known cost.  */
    5918              : 
    5919              : int
    5920    157598851 : pattern_cost (rtx pat, bool speed)
    5921              : {
    5922    157598851 :   int i, cost;
    5923    157598851 :   rtx set;
    5924              : 
    5925              :   /* Extract the single set rtx from the instruction pattern.  We
    5926              :      can't use single_set since we only have the pattern.  We also
    5927              :      consider PARALLELs of a normal set and a single comparison.  In
    5928              :      that case we use the cost of the non-comparison SET operation,
    5929              :      which is most-likely to be the real cost of this operation.  */
    5930    157598851 :   if (GET_CODE (pat) == SET)
    5931              :     set = pat;
    5932     71872204 :   else if (GET_CODE (pat) == PARALLEL)
    5933              :     {
    5934              :       set = NULL_RTX;
    5935              :       rtx comparison = NULL_RTX;
    5936              : 
    5937     48038886 :       for (i = 0; i < XVECLEN (pat, 0); i++)
    5938              :         {
    5939     32335542 :           rtx x = XVECEXP (pat, 0, i);
    5940     32335542 :           if (GET_CODE (x) == SET)
    5941              :             {
    5942     16372988 :               if (GET_CODE (SET_SRC (x)) == COMPARE
    5943     16083920 :                   || GET_MODE_CLASS (GET_MODE (SET_DEST (x))) == MODE_CC)
    5944              :                 {
    5945       356968 :                   if (comparison)
    5946              :                     return 0;
    5947              :                   comparison = x;
    5948              :                 }
    5949              :               else
    5950              :                 {
    5951     16016020 :                   if (set)
    5952              :                     return 0;
    5953              :                   set = x;
    5954              :                 }
    5955              :             }
    5956              :         }
    5957              : 
    5958     15703344 :       if (!set && comparison)
    5959              :         set = comparison;
    5960              : 
    5961     15545925 :       if (!set)
    5962              :         return 0;
    5963              :     }
    5964              :   else
    5965              :     return 0;
    5966              : 
    5967    101364724 :   cost = set_src_cost (SET_SRC (set), GET_MODE (SET_DEST (set)), speed);
    5968    101364724 :   return MAX (COSTS_N_INSNS (1), cost);
    5969              : }
    5970              : 
    5971              : /* Calculate the cost of a single instruction.  A return value of zero
    5972              :    indicates an instruction pattern without a known cost.  */
    5973              : 
    5974              : int
    5975    155505362 : insn_cost (rtx_insn *insn, bool speed)
    5976              : {
    5977    155505362 :   if (targetm.insn_cost)
    5978    155505362 :     return targetm.insn_cost (insn, speed);
    5979              : 
    5980            0 :   return pattern_cost (PATTERN (insn), speed);
    5981              : }
    5982              : 
    5983              : /* Returns estimate on cost of computing SEQ.  */
    5984              : 
    5985              : unsigned
    5986      2198881 : seq_cost (const rtx_insn *seq, bool speed)
    5987              : {
    5988      2198881 :   unsigned cost = 0;
    5989      2198881 :   rtx set;
    5990              : 
    5991      5909157 :   for (; seq; seq = NEXT_INSN (seq))
    5992              :     {
    5993      3710276 :       set = single_set (seq);
    5994      3710276 :       if (set)
    5995      3702240 :         cost += set_rtx_cost (set, speed);
    5996         8036 :       else if (NONDEBUG_INSN_P (seq))
    5997              :         {
    5998         7691 :           int this_cost = insn_cost (const_cast<struct rtx_insn *> (seq),
    5999              :                                      speed);
    6000         7691 :           if (this_cost > 0)
    6001          700 :             cost += this_cost;
    6002              :           else
    6003         6991 :             cost++;
    6004              :         }
    6005              :     }
    6006              : 
    6007      2198881 :   return cost;
    6008              : }
    6009              : 
    6010              : /* Given an insn INSN and condition COND, return the condition in a
    6011              :    canonical form to simplify testing by callers.  Specifically:
    6012              : 
    6013              :    (1) The code will always be a comparison operation (EQ, NE, GT, etc.).
    6014              :    (2) Both operands will be machine operands.
    6015              :    (3) If an operand is a constant, it will be the second operand.
    6016              :    (4) (LE x const) will be replaced with (LT x <const+1>) and similarly
    6017              :        for GE, GEU, and LEU.
    6018              : 
    6019              :    If the condition cannot be understood, or is an inequality floating-point
    6020              :    comparison which needs to be reversed, 0 will be returned.
    6021              : 
    6022              :    If REVERSE is nonzero, then reverse the condition prior to canonizing it.
    6023              : 
    6024              :    If EARLIEST is nonzero, it is a pointer to a place where the earliest
    6025              :    insn used in locating the condition was found.  If a replacement test
    6026              :    of the condition is desired, it should be placed in front of that
    6027              :    insn and we will be sure that the inputs are still valid.
    6028              : 
    6029              :    If WANT_REG is nonzero, we wish the condition to be relative to that
    6030              :    register, if possible.  Therefore, do not canonicalize the condition
    6031              :    further.  If ALLOW_CC_MODE is nonzero, allow the condition returned
    6032              :    to be a compare to a CC mode register.
    6033              : 
    6034              :    If VALID_AT_INSN_P, the condition must be valid at both *EARLIEST
    6035              :    and at INSN.  */
    6036              : 
    6037              : rtx
    6038     53366597 : canonicalize_condition (rtx_insn *insn, rtx cond, int reverse,
    6039              :                         rtx_insn **earliest,
    6040              :                         rtx want_reg, int allow_cc_mode, int valid_at_insn_p)
    6041              : {
    6042     53366597 :   enum rtx_code code;
    6043     53366597 :   rtx_insn *prev = insn;
    6044     53366597 :   const_rtx set;
    6045     53366597 :   rtx tem;
    6046     53366597 :   rtx op0, op1;
    6047     53366597 :   int reverse_code = 0;
    6048     53366597 :   machine_mode mode;
    6049     53366597 :   basic_block bb = BLOCK_FOR_INSN (insn);
    6050              : 
    6051     53366597 :   code = GET_CODE (cond);
    6052     53366597 :   mode = GET_MODE (cond);
    6053     53366597 :   op0 = XEXP (cond, 0);
    6054     53366597 :   op1 = XEXP (cond, 1);
    6055              : 
    6056     53366597 :   if (reverse)
    6057      1911585 :     code = reversed_comparison_code (cond, insn);
    6058     53366597 :   if (code == UNKNOWN)
    6059              :     return 0;
    6060              : 
    6061     53366597 :   if (earliest)
    6062     18289958 :     *earliest = insn;
    6063              : 
    6064              :   /* If we are comparing a register with zero, see if the register is set
    6065              :      in the previous insn to a COMPARE or a comparison operation.  Perform
    6066              :      the same tests as a function of STORE_FLAG_VALUE as find_comparison_args
    6067              :      in cse.cc  */
    6068              : 
    6069    113114536 :   while ((GET_RTX_CLASS (code) == RTX_COMPARE
    6070              :           || GET_RTX_CLASS (code) == RTX_COMM_COMPARE)
    6071    113114536 :          && op1 == CONST0_RTX (GET_MODE (op0))
    6072    198501540 :          && op0 != want_reg)
    6073              :     {
    6074              :       /* Set nonzero when we find something of interest.  */
    6075     85387004 :       rtx x = 0;
    6076              : 
    6077              :       /* If this is a COMPARE, pick up the two things being compared.  */
    6078     85387004 :       if (GET_CODE (op0) == COMPARE)
    6079              :         {
    6080            0 :           op1 = XEXP (op0, 1);
    6081            0 :           op0 = XEXP (op0, 0);
    6082            0 :           continue;
    6083              :         }
    6084     85387004 :       else if (!REG_P (op0))
    6085              :         break;
    6086              : 
    6087              :       /* Go back to the previous insn.  Stop if it is not an INSN.  We also
    6088              :          stop if it isn't a single set or if it has a REG_INC note because
    6089              :          we don't want to bother dealing with it.  */
    6090              : 
    6091     78347706 :       prev = prev_nonnote_nondebug_insn (prev);
    6092              : 
    6093     78347706 :       if (prev == 0
    6094     78101847 :           || !NONJUMP_INSN_P (prev)
    6095              :           || FIND_REG_INC_NOTE (prev, NULL_RTX)
    6096              :           /* In cfglayout mode, there do not have to be labels at the
    6097              :              beginning of a block, or jumps at the end, so the previous
    6098              :              conditions would not stop us when we reach bb boundary.  */
    6099    148573954 :           || BLOCK_FOR_INSN (prev) != bb)
    6100              :         break;
    6101              : 
    6102     70092160 :       set = set_of (op0, prev);
    6103              : 
    6104     70092160 :       if (set
    6105     70092160 :           && (GET_CODE (set) != SET
    6106     60521636 :               || !rtx_equal_p (SET_DEST (set), op0)))
    6107              :         break;
    6108              : 
    6109              :       /* If this is setting OP0, get what it sets it to if it looks
    6110              :          relevant.  */
    6111     69956485 :       if (set)
    6112              :         {
    6113     60385961 :           machine_mode inner_mode = GET_MODE (SET_DEST (set));
    6114              : #ifdef FLOAT_STORE_FLAG_VALUE
    6115              :           REAL_VALUE_TYPE fsfv;
    6116              : #endif
    6117              : 
    6118              :           /* ??? We may not combine comparisons done in a CCmode with
    6119              :              comparisons not done in a CCmode.  This is to aid targets
    6120              :              like Alpha that have an IEEE compliant EQ instruction, and
    6121              :              a non-IEEE compliant BEQ instruction.  The use of CCmode is
    6122              :              actually artificial, simply to prevent the combination, but
    6123              :              should not affect other platforms.
    6124              : 
    6125              :              However, we must allow VOIDmode comparisons to match either
    6126              :              CCmode or non-CCmode comparison, because some ports have
    6127              :              modeless comparisons inside branch patterns.
    6128              : 
    6129              :              ??? This mode check should perhaps look more like the mode check
    6130              :              in simplify_comparison in combine.  */
    6131     60385961 :           if (((GET_MODE_CLASS (mode) == MODE_CC)
    6132     60385961 :                != (GET_MODE_CLASS (inner_mode) == MODE_CC))
    6133     52383599 :               && mode != VOIDmode
    6134            0 :               && inner_mode != VOIDmode)
    6135              :             break;
    6136     60385961 :           if (GET_CODE (SET_SRC (set)) == COMPARE
    6137     60385961 :               || (((code == NE
    6138      6097996 :                     || (code == LT
    6139       190968 :                         && val_signbit_known_set_p (inner_mode,
    6140              :                                                     STORE_FLAG_VALUE))
    6141              : #ifdef FLOAT_STORE_FLAG_VALUE
    6142              :                     || (code == LT
    6143              :                         && SCALAR_FLOAT_MODE_P (inner_mode)
    6144              :                         && (fsfv = FLOAT_STORE_FLAG_VALUE (inner_mode),
    6145              :                             REAL_VALUE_NEGATIVE (fsfv)))
    6146              : #endif
    6147              :                     ))
    6148      3542088 :                   && COMPARISON_P (SET_SRC (set))))
    6149     51157429 :             x = SET_SRC (set);
    6150      9228532 :           else if (((code == EQ
    6151      5208002 :                      || (code == GE
    6152       182077 :                          && val_signbit_known_set_p (inner_mode,
    6153              :                                                      STORE_FLAG_VALUE))
    6154              : #ifdef FLOAT_STORE_FLAG_VALUE
    6155              :                      || (code == GE
    6156              :                          && SCALAR_FLOAT_MODE_P (inner_mode)
    6157              :                          && (fsfv = FLOAT_STORE_FLAG_VALUE (inner_mode),
    6158              :                              REAL_VALUE_NEGATIVE (fsfv)))
    6159              : #endif
    6160              :                      ))
    6161      9228532 :                    && COMPARISON_P (SET_SRC (set)))
    6162              :             {
    6163              :               reverse_code = 1;
    6164              :               x = SET_SRC (set);
    6165              :             }
    6166      8834121 :           else if ((code == EQ || code == NE)
    6167      6756655 :                    && GET_CODE (SET_SRC (set)) == XOR)
    6168              :             /* Handle sequences like:
    6169              : 
    6170              :                (set op0 (xor X Y))
    6171              :                ...(eq|ne op0 (const_int 0))...
    6172              : 
    6173              :                in which case:
    6174              : 
    6175              :                (eq op0 (const_int 0)) reduces to (eq X Y)
    6176              :                (ne op0 (const_int 0)) reduces to (ne X Y)
    6177              : 
    6178              :                This is the form used by MIPS16, for example.  */
    6179              :             x = SET_SRC (set);
    6180              :           else
    6181              :             break;
    6182              :         }
    6183              : 
    6184      9570524 :       else if (reg_set_p (op0, prev))
    6185              :         /* If this sets OP0, but not directly, we have to give up.  */
    6186              :         break;
    6187              : 
    6188     61131756 :       if (x)
    6189              :         {
    6190              :           /* If the caller is expecting the condition to be valid at INSN,
    6191              :              make sure X doesn't change before INSN.  */
    6192     51561232 :           if (valid_at_insn_p)
    6193     38057763 :             if (modified_in_p (x, prev) || modified_between_p (x, prev, insn))
    6194              :               break;
    6195     50177415 :           if (COMPARISON_P (x))
    6196       136540 :             code = GET_CODE (x);
    6197     50177415 :           if (reverse_code)
    6198              :             {
    6199        84856 :               code = reversed_comparison_code (x, prev);
    6200        84856 :               if (code == UNKNOWN)
    6201              :                 return 0;
    6202              :               reverse_code = 0;
    6203              :             }
    6204              : 
    6205     50177415 :           op0 = XEXP (x, 0), op1 = XEXP (x, 1);
    6206     50177415 :           if (earliest)
    6207     17596763 :             *earliest = prev;
    6208              :         }
    6209              :     }
    6210              : 
    6211              :   /* If constant is first, put it last.  */
    6212     53366597 :   if (CONSTANT_P (op0))
    6213        36996 :     code = swap_condition (code), tem = op0, op0 = op1, op1 = tem;
    6214              : 
    6215              :   /* If OP0 is the result of a comparison, we weren't able to find what
    6216              :      was really being compared, so fail.  */
    6217     53366597 :   if (!allow_cc_mode
    6218     35862152 :       && GET_MODE_CLASS (GET_MODE (op0)) == MODE_CC)
    6219              :     return 0;
    6220              : 
    6221              :   /* Canonicalize any ordered comparison with integers involving equality
    6222              :      if we can do computations in the relevant mode and we do not
    6223              :      overflow.  */
    6224              : 
    6225     50819748 :   scalar_int_mode op0_mode;
    6226     50819748 :   if (CONST_INT_P (op1)
    6227     34644723 :       && is_a <scalar_int_mode> (GET_MODE (op0), &op0_mode)
    6228     84776634 :       && GET_MODE_PRECISION (op0_mode) <= HOST_BITS_PER_WIDE_INT)
    6229              :     {
    6230     33928930 :       HOST_WIDE_INT const_val = INTVAL (op1);
    6231     33928930 :       unsigned HOST_WIDE_INT uconst_val = const_val;
    6232     33928930 :       unsigned HOST_WIDE_INT max_val
    6233     33928930 :         = (unsigned HOST_WIDE_INT) GET_MODE_MASK (op0_mode);
    6234              : 
    6235     33928930 :       switch (code)
    6236              :         {
    6237      1343839 :         case LE:
    6238      1343839 :           if ((unsigned HOST_WIDE_INT) const_val != max_val >> 1)
    6239      1343839 :             code = LT, op1 = gen_int_mode (const_val + 1, op0_mode);
    6240              :           break;
    6241              : 
    6242              :         /* When cross-compiling, const_val might be sign-extended from
    6243              :            BITS_PER_WORD to HOST_BITS_PER_WIDE_INT */
    6244       413609 :         case GE:
    6245       413609 :           if ((const_val & max_val)
    6246       413609 :               != (HOST_WIDE_INT_1U << (GET_MODE_PRECISION (op0_mode) - 1)))
    6247       413609 :             code = GT, op1 = gen_int_mode (const_val - 1, op0_mode);
    6248              :           break;
    6249              : 
    6250       935647 :         case LEU:
    6251       935647 :           if (uconst_val < max_val)
    6252       922304 :             code = LTU, op1 = gen_int_mode (uconst_val + 1, op0_mode);
    6253              :           break;
    6254              : 
    6255       229173 :         case GEU:
    6256       229173 :           if (uconst_val != 0)
    6257       229173 :             code = GTU, op1 = gen_int_mode (uconst_val - 1, op0_mode);
    6258              :           break;
    6259              : 
    6260              :         default:
    6261              :           break;
    6262              :         }
    6263              :     }
    6264              : 
    6265              :   /* We promised to return a comparison.  */
    6266     50819748 :   rtx ret = gen_rtx_fmt_ee (code, VOIDmode, op0, op1);
    6267     50819748 :   if (COMPARISON_P (ret))
    6268     50819748 :     return ret;
    6269              :   return 0;
    6270              : }
    6271              : 
    6272              : /* Given a jump insn JUMP, return the condition that will cause it to branch
    6273              :    to its JUMP_LABEL.  If the condition cannot be understood, or is an
    6274              :    inequality floating-point comparison which needs to be reversed, 0 will
    6275              :    be returned.
    6276              : 
    6277              :    If EARLIEST is nonzero, it is a pointer to a place where the earliest
    6278              :    insn used in locating the condition was found.  If a replacement test
    6279              :    of the condition is desired, it should be placed in front of that
    6280              :    insn and we will be sure that the inputs are still valid.  If EARLIEST
    6281              :    is null, the returned condition will be valid at INSN.
    6282              : 
    6283              :    If ALLOW_CC_MODE is nonzero, allow the condition returned to be a
    6284              :    compare CC mode register.
    6285              : 
    6286              :    VALID_AT_INSN_P is the same as for canonicalize_condition.  */
    6287              : 
    6288              : rtx
    6289     52973013 : get_condition (rtx_insn *jump, rtx_insn **earliest, int allow_cc_mode,
    6290              :                int valid_at_insn_p)
    6291              : {
    6292     52973013 :   rtx cond;
    6293     52973013 :   int reverse;
    6294     52973013 :   rtx set;
    6295              : 
    6296              :   /* If this is not a standard conditional jump, we can't parse it.  */
    6297     52973013 :   if (!JUMP_P (jump)
    6298     52973013 :       || ! any_condjump_p (jump))
    6299              :     return 0;
    6300     48953372 :   set = pc_set (jump);
    6301              : 
    6302     48953372 :   cond = XEXP (SET_SRC (set), 0);
    6303              : 
    6304              :   /* If this branches to JUMP_LABEL when the condition is false, reverse
    6305              :      the condition.  */
    6306     48953372 :   reverse
    6307     97906744 :     = GET_CODE (XEXP (SET_SRC (set), 2)) == LABEL_REF
    6308     48953372 :       && label_ref_label (XEXP (SET_SRC (set), 2)) == JUMP_LABEL (jump);
    6309              : 
    6310     48953372 :   return canonicalize_condition (jump, cond, reverse, earliest, NULL_RTX,
    6311     48953372 :                                  allow_cc_mode, valid_at_insn_p);
    6312              : }
    6313              : 
    6314              : /* Initialize the table NUM_SIGN_BIT_COPIES_IN_REP based on
    6315              :    TARGET_MODE_REP_EXTENDED.
    6316              : 
    6317              :    Note that we assume that the property of
    6318              :    TARGET_MODE_REP_EXTENDED(B, C) is sticky to the integral modes
    6319              :    narrower than mode B.  I.e., if A is a mode narrower than B then in
    6320              :    order to be able to operate on it in mode B, mode A needs to
    6321              :    satisfy the requirements set by the representation of mode B.  */
    6322              : 
    6323              : static void
    6324       289641 : init_num_sign_bit_copies_in_rep (void)
    6325              : {
    6326       289641 :   opt_scalar_int_mode in_mode_iter;
    6327       289641 :   scalar_int_mode mode;
    6328              : 
    6329      2317128 :   FOR_EACH_MODE_IN_CLASS (in_mode_iter, MODE_INT)
    6330      8109948 :     FOR_EACH_MODE_UNTIL (mode, in_mode_iter.require ())
    6331              :       {
    6332      6082461 :         scalar_int_mode in_mode = in_mode_iter.require ();
    6333      6082461 :         scalar_int_mode i;
    6334              : 
    6335              :         /* Currently, it is assumed that TARGET_MODE_REP_EXTENDED
    6336              :            extends to the next widest mode.  */
    6337      6082461 :         gcc_assert (targetm.mode_rep_extended (mode, in_mode) == UNKNOWN
    6338              :                     || GET_MODE_WIDER_MODE (mode).require () == in_mode);
    6339              : 
    6340              :         /* We are in in_mode.  Count how many bits outside of mode
    6341              :            have to be copies of the sign-bit.  */
    6342     22302357 :         FOR_EACH_MODE (i, mode, in_mode)
    6343              :           {
    6344              :             /* This must always exist (for the last iteration it will be
    6345              :                IN_MODE).  */
    6346     16219896 :             scalar_int_mode wider = GET_MODE_WIDER_MODE (i).require ();
    6347              : 
    6348     16219896 :             if (targetm.mode_rep_extended (i, wider) == SIGN_EXTEND
    6349              :                 /* We can only check sign-bit copies starting from the
    6350              :                    top-bit.  In order to be able to check the bits we
    6351              :                    have already seen we pretend that subsequent bits
    6352              :                    have to be sign-bit copies too.  */
    6353     16219896 :                 || num_sign_bit_copies_in_rep [in_mode][mode])
    6354            0 :               num_sign_bit_copies_in_rep [in_mode][mode]
    6355            0 :                 += GET_MODE_PRECISION (wider) - GET_MODE_PRECISION (i);
    6356              :           }
    6357              :       }
    6358       289641 : }
    6359              : 
    6360              : /* Suppose that truncation from the machine mode of X to MODE is not a
    6361              :    no-op.  See if there is anything special about X so that we can
    6362              :    assume it already contains a truncated value of MODE.  */
    6363              : 
    6364              : bool
    6365            0 : truncated_to_mode (machine_mode mode, const_rtx x)
    6366              : {
    6367              :   /* This register has already been used in MODE without explicit
    6368              :      truncation.  */
    6369            0 :   if (REG_P (x) && rtl_hooks.reg_truncated_to_mode (mode, x))
    6370              :     return true;
    6371              : 
    6372              :   /* See if we already satisfy the requirements of MODE.  If yes we
    6373              :      can just switch to MODE.  */
    6374            0 :   if (num_sign_bit_copies_in_rep[GET_MODE (x)][mode]
    6375            0 :       && (num_sign_bit_copies (x, GET_MODE (x))
    6376            0 :           >= num_sign_bit_copies_in_rep[GET_MODE (x)][mode] + 1))
    6377            0 :     return true;
    6378              : 
    6379              :   return false;
    6380              : }
    6381              : 
    6382              : /* Return true if RTX code CODE has a single sequence of zero or more
    6383              :    "e" operands and no rtvec operands.  Initialize its rtx_all_subrtx_bounds
    6384              :    entry in that case.  */
    6385              : 
    6386              : static bool
    6387     44604714 : setup_reg_subrtx_bounds (unsigned int code)
    6388              : {
    6389     44604714 :   const char *format = GET_RTX_FORMAT ((enum rtx_code) code);
    6390     44604714 :   unsigned int i = 0;
    6391     62852097 :   for (; format[i] != 'e'; ++i)
    6392              :     {
    6393     28095177 :       if (!format[i])
    6394              :         /* No subrtxes.  Leave start and count as 0.  */
    6395              :         return true;
    6396     20564511 :       if (format[i] == 'E' || format[i] == 'V')
    6397              :         return false;
    6398              :     }
    6399              : 
    6400              :   /* Record the sequence of 'e's.  */
    6401     34756920 :   rtx_all_subrtx_bounds[code].start = i;
    6402     56479995 :   do
    6403     56479995 :     ++i;
    6404     56479995 :   while (format[i] == 'e');
    6405     34756920 :   rtx_all_subrtx_bounds[code].count = i - rtx_all_subrtx_bounds[code].start;
    6406              :   /* rtl-iter.h relies on this.  */
    6407     34756920 :   gcc_checking_assert (rtx_all_subrtx_bounds[code].count <= 3);
    6408              : 
    6409     38811894 :   for (; format[i]; ++i)
    6410      5503179 :     if (format[i] == 'E' || format[i] == 'V' || format[i] == 'e')
    6411              :       return false;
    6412              : 
    6413              :   return true;
    6414              : }
    6415              : 
    6416              : /* Initialize rtx_all_subrtx_bounds.  */
    6417              : void
    6418       289641 : init_rtlanal (void)
    6419              : {
    6420       289641 :   int i;
    6421     44894355 :   for (i = 0; i < NUM_RTX_CODE; i++)
    6422              :     {
    6423     44604714 :       if (!setup_reg_subrtx_bounds (i))
    6424      3765333 :         rtx_all_subrtx_bounds[i].count = UCHAR_MAX;
    6425     44604714 :       if (GET_RTX_CLASS (i) != RTX_CONST_OBJ)
    6426     41708304 :         rtx_nonconst_subrtx_bounds[i] = rtx_all_subrtx_bounds[i];
    6427              :     }
    6428              : 
    6429       289641 :   init_num_sign_bit_copies_in_rep ();
    6430       289641 : }
    6431              : 
    6432              : /* Check whether this is a constant pool constant.  */
    6433              : bool
    6434        11888 : constant_pool_constant_p (rtx x)
    6435              : {
    6436        11888 :   x = avoid_constant_pool_reference (x);
    6437        11888 :   return CONST_DOUBLE_P (x);
    6438              : }
    6439              : 
    6440              : /* If M is a bitmask that selects a field of low-order bits within an item but
    6441              :    not the entire word, return the length of the field.  Return -1 otherwise.
    6442              :    M is used in machine mode MODE.  */
    6443              : 
    6444              : int
    6445        27384 : low_bitmask_len (machine_mode mode, unsigned HOST_WIDE_INT m)
    6446              : {
    6447        27384 :   if (mode != VOIDmode)
    6448              :     {
    6449        27384 :       if (!HWI_COMPUTABLE_MODE_P (mode))
    6450              :         return -1;
    6451        27384 :       m &= GET_MODE_MASK (mode);
    6452              :     }
    6453              : 
    6454        27384 :   return exact_log2 (m + 1);
    6455              : }
    6456              : 
    6457              : /* Return the mode of MEM's address.  */
    6458              : 
    6459              : machine_mode
    6460    183782363 : get_address_mode (rtx mem)
    6461              : {
    6462    183782363 :   machine_mode mode;
    6463              : 
    6464    183782363 :   gcc_assert (MEM_P (mem));
    6465    183782363 :   mode = GET_MODE (XEXP (mem, 0));
    6466    183782363 :   if (mode != VOIDmode)
    6467              :     return mode;
    6468       528644 :   return targetm.addr_space.address_mode (MEM_ADDR_SPACE (mem));
    6469              : }
    6470              : 
    6471              : /* Split up a CONST_DOUBLE or integer constant rtx
    6472              :    into two rtx's for single words,
    6473              :    storing in *FIRST the word that comes first in memory in the target
    6474              :    and in *SECOND the other.
    6475              : 
    6476              :    TODO: This function needs to be rewritten to work on any size
    6477              :    integer.  */
    6478              : 
    6479              : void
    6480            0 : split_double (rtx value, rtx *first, rtx *second)
    6481              : {
    6482            0 :   if (CONST_INT_P (value))
    6483              :     {
    6484            0 :       if (HOST_BITS_PER_WIDE_INT >= (2 * BITS_PER_WORD))
    6485              :         {
    6486              :           /* In this case the CONST_INT holds both target words.
    6487              :              Extract the bits from it into two word-sized pieces.
    6488              :              Sign extend each half to HOST_WIDE_INT.  */
    6489            0 :           unsigned HOST_WIDE_INT low, high;
    6490            0 :           unsigned HOST_WIDE_INT mask, sign_bit, sign_extend;
    6491            0 :           unsigned bits_per_word = BITS_PER_WORD;
    6492              : 
    6493              :           /* Set sign_bit to the most significant bit of a word.  */
    6494            0 :           sign_bit = 1;
    6495            0 :           sign_bit <<= bits_per_word - 1;
    6496              : 
    6497              :           /* Set mask so that all bits of the word are set.  We could
    6498              :              have used 1 << BITS_PER_WORD instead of basing the
    6499              :              calculation on sign_bit.  However, on machines where
    6500              :              HOST_BITS_PER_WIDE_INT == BITS_PER_WORD, it could cause a
    6501              :              compiler warning, even though the code would never be
    6502              :              executed.  */
    6503            0 :           mask = sign_bit << 1;
    6504            0 :           mask--;
    6505              : 
    6506              :           /* Set sign_extend as any remaining bits.  */
    6507            0 :           sign_extend = ~mask;
    6508              : 
    6509              :           /* Pick the lower word and sign-extend it.  */
    6510            0 :           low = INTVAL (value);
    6511            0 :           low &= mask;
    6512            0 :           if (low & sign_bit)
    6513            0 :             low |= sign_extend;
    6514              : 
    6515              :           /* Pick the higher word, shifted to the least significant
    6516              :              bits, and sign-extend it.  */
    6517            0 :           high = INTVAL (value);
    6518            0 :           high >>= bits_per_word - 1;
    6519            0 :           high >>= 1;
    6520            0 :           high &= mask;
    6521            0 :           if (high & sign_bit)
    6522            0 :             high |= sign_extend;
    6523              : 
    6524              :           /* Store the words in the target machine order.  */
    6525            0 :           if (WORDS_BIG_ENDIAN)
    6526              :             {
    6527              :               *first = GEN_INT (high);
    6528              :               *second = GEN_INT (low);
    6529              :             }
    6530              :           else
    6531              :             {
    6532            0 :               *first = GEN_INT (low);
    6533            0 :               *second = GEN_INT (high);
    6534              :             }
    6535              :         }
    6536              :       else
    6537              :         {
    6538              :           /* The rule for using CONST_INT for a wider mode
    6539              :              is that we regard the value as signed.
    6540              :              So sign-extend it.  */
    6541            0 :           rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
    6542            0 :           if (WORDS_BIG_ENDIAN)
    6543              :             {
    6544              :               *first = high;
    6545              :               *second = value;
    6546              :             }
    6547              :           else
    6548              :             {
    6549            0 :               *first = value;
    6550            0 :               *second = high;
    6551              :             }
    6552              :         }
    6553              :     }
    6554            0 :   else if (GET_CODE (value) == CONST_WIDE_INT)
    6555              :     {
    6556              :       /* All of this is scary code and needs to be converted to
    6557              :          properly work with any size integer.  */
    6558            0 :       gcc_assert (CONST_WIDE_INT_NUNITS (value) == 2);
    6559            0 :       if (WORDS_BIG_ENDIAN)
    6560              :         {
    6561              :           *first = GEN_INT (CONST_WIDE_INT_ELT (value, 1));
    6562              :           *second = GEN_INT (CONST_WIDE_INT_ELT (value, 0));
    6563              :         }
    6564              :       else
    6565              :         {
    6566            0 :           *first = GEN_INT (CONST_WIDE_INT_ELT (value, 0));
    6567            0 :           *second = GEN_INT (CONST_WIDE_INT_ELT (value, 1));
    6568              :         }
    6569              :     }
    6570            0 :   else if (!CONST_DOUBLE_P (value))
    6571              :     {
    6572            0 :       if (WORDS_BIG_ENDIAN)
    6573              :         {
    6574              :           *first = const0_rtx;
    6575              :           *second = value;
    6576              :         }
    6577              :       else
    6578              :         {
    6579            0 :           *first = value;
    6580            0 :           *second = const0_rtx;
    6581              :         }
    6582              :     }
    6583            0 :   else if (GET_MODE (value) == VOIDmode
    6584              :            /* This is the old way we did CONST_DOUBLE integers.  */
    6585            0 :            || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
    6586              :     {
    6587              :       /* In an integer, the words are defined as most and least significant.
    6588              :          So order them by the target's convention.  */
    6589            0 :       if (WORDS_BIG_ENDIAN)
    6590              :         {
    6591              :           *first = GEN_INT (CONST_DOUBLE_HIGH (value));
    6592              :           *second = GEN_INT (CONST_DOUBLE_LOW (value));
    6593              :         }
    6594              :       else
    6595              :         {
    6596            0 :           *first = GEN_INT (CONST_DOUBLE_LOW (value));
    6597            0 :           *second = GEN_INT (CONST_DOUBLE_HIGH (value));
    6598              :         }
    6599              :     }
    6600              :   else
    6601              :     {
    6602            0 :       long l[2];
    6603              : 
    6604              :       /* Note, this converts the REAL_VALUE_TYPE to the target's
    6605              :          format, splits up the floating point double and outputs
    6606              :          exactly 32 bits of it into each of l[0] and l[1] --
    6607              :          not necessarily BITS_PER_WORD bits.  */
    6608            0 :       REAL_VALUE_TO_TARGET_DOUBLE (*CONST_DOUBLE_REAL_VALUE (value), l);
    6609              : 
    6610              :       /* If 32 bits is an entire word for the target, but not for the host,
    6611              :          then sign-extend on the host so that the number will look the same
    6612              :          way on the host that it would on the target.  See for instance
    6613              :          simplify_unary_operation.  The #if is needed to avoid compiler
    6614              :          warnings.  */
    6615              : 
    6616              : #if HOST_BITS_PER_LONG > 32
    6617            0 :       if (BITS_PER_WORD < HOST_BITS_PER_LONG && BITS_PER_WORD == 32)
    6618              :         {
    6619            0 :           if (l[0] & ((long) 1 << 31))
    6620            0 :             l[0] |= ((unsigned long) (-1) << 32);
    6621            0 :           if (l[1] & ((long) 1 << 31))
    6622            0 :             l[1] |= ((unsigned long) (-1) << 32);
    6623              :         }
    6624              : #endif
    6625              : 
    6626            0 :       *first = GEN_INT (l[0]);
    6627            0 :       *second = GEN_INT (l[1]);
    6628              :     }
    6629            0 : }
    6630              : 
    6631              : /* Return true if X is a sign_extract or zero_extract from the least
    6632              :    significant bit.  */
    6633              : 
    6634              : static bool
    6635    215791270 : lsb_bitfield_op_p (rtx x)
    6636              : {
    6637            0 :   if (GET_RTX_CLASS (GET_CODE (x)) == RTX_BITFIELD_OPS)
    6638              :     {
    6639            0 :       machine_mode mode = GET_MODE (XEXP (x, 0));
    6640            0 :       HOST_WIDE_INT len = INTVAL (XEXP (x, 1));
    6641            0 :       HOST_WIDE_INT pos = INTVAL (XEXP (x, 2));
    6642            0 :       poly_int64 remaining_bits = GET_MODE_PRECISION (mode) - len;
    6643              : 
    6644            0 :       return known_eq (pos, BITS_BIG_ENDIAN ? remaining_bits : 0);
    6645              :     }
    6646              :   return false;
    6647              : }
    6648              : 
    6649              : /* Strip outer address "mutations" from LOC and return a pointer to the
    6650              :    inner value.  If OUTER_CODE is nonnull, store the code of the innermost
    6651              :    stripped expression there.
    6652              : 
    6653              :    "Mutations" either convert between modes or apply some kind of
    6654              :    extension, truncation or alignment.  */
    6655              : 
    6656              : rtx *
    6657    215788976 : strip_address_mutations (rtx *loc, enum rtx_code *outer_code)
    6658              : {
    6659    215857092 :   for (;;)
    6660              :     {
    6661    215857092 :       enum rtx_code code = GET_CODE (*loc);
    6662    215857092 :       if (GET_RTX_CLASS (code) == RTX_UNARY)
    6663              :         /* Things like SIGN_EXTEND, ZERO_EXTEND and TRUNCATE can be
    6664              :            used to convert between pointer sizes.  */
    6665        65822 :         loc = &XEXP (*loc, 0);
    6666    215791270 :       else if (lsb_bitfield_op_p (*loc))
    6667              :         /* A [SIGN|ZERO]_EXTRACT from the least significant bit effectively
    6668              :            acts as a combined truncation and extension.  */
    6669            0 :         loc = &XEXP (*loc, 0);
    6670    215791270 :       else if (code == AND && CONST_INT_P (XEXP (*loc, 1)))
    6671              :         /* (and ... (const_int -X)) is used to align to X bytes.  */
    6672         2284 :         loc = &XEXP (*loc, 0);
    6673    215788986 :       else if (code == SUBREG
    6674        32479 :                && (!OBJECT_P (SUBREG_REG (*loc))
    6675        32479 :                    || CONSTANT_P (SUBREG_REG (*loc)))
    6676    215788996 :                && subreg_lowpart_p (*loc))
    6677              :         /* (subreg (operator ...) ...) inside AND is used for mode
    6678              :            conversion too.  It is also used for load-address operations
    6679              :            in which an extension can be done for free, such as:
    6680              : 
    6681              :              (zero_extend:DI
    6682              :                (subreg:SI (plus:DI (reg:DI R) (symbol_ref:DI "foo") 0)))
    6683              : 
    6684              :            The latter usage also covers subregs of plain "displacements",
    6685              :            such as:
    6686              : 
    6687              :              (zero_extend:DI (subreg:SI (symbol_ref:DI "foo") 0))
    6688              : 
    6689              :            The inner address should then be the symbol_ref, not the subreg,
    6690              :            similarly to the plus case above.
    6691              : 
    6692              :            In contrast, the subreg in:
    6693              : 
    6694              :              (zero_extend:DI (subreg:SI (reg:DI R) 0))
    6695              : 
    6696              :            should be treated as the base, since it should be replaced by
    6697              :            an SImode hard register during register allocation.  */
    6698           10 :         loc = &SUBREG_REG (*loc);
    6699              :       else
    6700    215788976 :         return loc;
    6701        68116 :       if (outer_code)
    6702        68116 :         *outer_code = code;
    6703              :     }
    6704              : }
    6705              : 
    6706              : /* Return true if CODE applies some kind of scale.  The scaled value is
    6707              :    is the first operand and the scale is the second.  */
    6708              : 
    6709              : static bool
    6710     67493354 : binary_scale_code_p (enum rtx_code code)
    6711              : {
    6712     67493354 :   return (code == MULT
    6713     67493354 :           || code == ASHIFT
    6714              :           /* Needed by ARM targets.  */
    6715              :           || code == ASHIFTRT
    6716              :           || code == LSHIFTRT
    6717     65319770 :           || code == ROTATE
    6718     65319770 :           || code == ROTATERT);
    6719              : }
    6720              : 
    6721              : /* Return true if X appears to be a valid base or index term.  */
    6722              : static bool
    6723    134986708 : valid_base_or_index_term_p (rtx x)
    6724              : {
    6725    134986708 :   if (GET_CODE (x) == SCRATCH)
    6726              :     return true;
    6727              :   /* Handle what appear to be eliminated forms of a register.  If we reach
    6728              :      here, the elimination occurs outside of the outermost PLUS tree,
    6729              :      and so the elimination offset cannot be treated as a displacement
    6730              :      of the main address.  Instead, we need to treat the whole PLUS as
    6731              :      the base or index term.  The address can only be made legitimate by
    6732              :      reloading the PLUS.  */
    6733    134986708 :   if (GET_CODE (x) == PLUS && CONST_SCALAR_INT_P (XEXP (x, 1)))
    6734            0 :     x = XEXP (x, 0);
    6735    134986708 :   if (GET_CODE (x) == SUBREG)
    6736        55620 :     x = SUBREG_REG (x);
    6737    134986708 :   return REG_P (x) || MEM_P (x);
    6738              : }
    6739              : 
    6740              : /* If *INNER can be interpreted as a base, return a pointer to the inner term
    6741              :    (see address_info).  Return null otherwise.  */
    6742              : 
    6743              : static rtx *
    6744     67493354 : get_base_term (rtx *inner)
    6745              : {
    6746     67493354 :   if (GET_CODE (*inner) == LO_SUM)
    6747            0 :     inner = strip_address_mutations (&XEXP (*inner, 0));
    6748     67493354 :   if (valid_base_or_index_term_p (*inner))
    6749     65319770 :     return inner;
    6750              :   return 0;
    6751              : }
    6752              : 
    6753              : /* If *INNER can be interpreted as an index, return a pointer to the inner term
    6754              :    (see address_info).  Return null otherwise.  */
    6755              : 
    6756              : static rtx *
    6757     67493354 : get_index_term (rtx *inner)
    6758              : {
    6759              :   /* At present, only constant scales are allowed.  */
    6760     67493354 :   if (binary_scale_code_p (GET_CODE (*inner)) && CONSTANT_P (XEXP (*inner, 1)))
    6761      2173584 :     inner = strip_address_mutations (&XEXP (*inner, 0));
    6762     67493354 :   if (valid_base_or_index_term_p (*inner))
    6763     67493354 :     return inner;
    6764              :   return 0;
    6765              : }
    6766              : 
    6767              : /* Set the segment part of address INFO to LOC, given that INNER is the
    6768              :    unmutated value.  */
    6769              : 
    6770              : static void
    6771           17 : set_address_segment (struct address_info *info, rtx *loc, rtx *inner)
    6772              : {
    6773           17 :   gcc_assert (!info->segment);
    6774           17 :   info->segment = loc;
    6775           17 :   info->segment_term = inner;
    6776           17 : }
    6777              : 
    6778              : /* Set the base part of address INFO to LOC, given that INNER is the
    6779              :    unmutated value.  */
    6780              : 
    6781              : static void
    6782     66007787 : set_address_base (struct address_info *info, rtx *loc, rtx *inner)
    6783              : {
    6784     66007787 :   gcc_assert (!info->base);
    6785     66007787 :   info->base = loc;
    6786     66007787 :   info->base_term = inner;
    6787     66007787 : }
    6788              : 
    6789              : /* Set the index part of address INFO to LOC, given that INNER is the
    6790              :    unmutated value.  */
    6791              : 
    6792              : static void
    6793      3581347 : set_address_index (struct address_info *info, rtx *loc, rtx *inner)
    6794              : {
    6795      3581347 :   gcc_assert (!info->index);
    6796      3581347 :   info->index = loc;
    6797      3581347 :   info->index_term = inner;
    6798      3581347 : }
    6799              : 
    6800              : /* Set the displacement part of address INFO to LOC, given that INNER
    6801              :    is the constant term.  */
    6802              : 
    6803              : static void
    6804     67372829 : set_address_disp (struct address_info *info, rtx *loc, rtx *inner)
    6805              : {
    6806     67372829 :   gcc_assert (!info->disp);
    6807     67372829 :   info->disp = loc;
    6808     67372829 :   info->disp_term = inner;
    6809     67372829 : }
    6810              : 
    6811              : /* INFO->INNER describes a {PRE,POST}_{INC,DEC} address.  Set up the
    6812              :    rest of INFO accordingly.  */
    6813              : 
    6814              : static void
    6815      1990714 : decompose_incdec_address (struct address_info *info)
    6816              : {
    6817      1990714 :   info->autoinc_p = true;
    6818              : 
    6819      1990714 :   rtx *base = &XEXP (*info->inner, 0);
    6820      1990714 :   set_address_base (info, base, base);
    6821      1990714 :   gcc_checking_assert (info->base == info->base_term);
    6822              : 
    6823              :   /* These addresses are only valid when the size of the addressed
    6824              :      value is known.  */
    6825      1990714 :   gcc_checking_assert (info->mode != VOIDmode);
    6826      1990714 : }
    6827              : 
    6828              : /* INFO->INNER describes a {PRE,POST}_MODIFY address.  Set up the rest
    6829              :    of INFO accordingly.  */
    6830              : 
    6831              : static void
    6832       105066 : decompose_automod_address (struct address_info *info)
    6833              : {
    6834       105066 :   info->autoinc_p = true;
    6835              : 
    6836       105066 :   rtx *base = &XEXP (*info->inner, 0);
    6837       105066 :   set_address_base (info, base, base);
    6838       105066 :   gcc_checking_assert (info->base == info->base_term);
    6839              : 
    6840       105066 :   rtx plus = XEXP (*info->inner, 1);
    6841       105066 :   gcc_assert (GET_CODE (plus) == PLUS);
    6842              : 
    6843       105066 :   info->base_term2 = &XEXP (plus, 0);
    6844       105066 :   gcc_checking_assert (rtx_equal_p (*info->base_term, *info->base_term2));
    6845              : 
    6846       105066 :   rtx *step = &XEXP (plus, 1);
    6847       105066 :   rtx *inner_step = strip_address_mutations (step);
    6848       105066 :   if (CONSTANT_P (*inner_step))
    6849       105066 :     set_address_disp (info, step, inner_step);
    6850              :   else
    6851            0 :     set_address_index (info, step, inner_step);
    6852       105066 : }
    6853              : 
    6854              : /* Treat *LOC as a tree of PLUS operands and store pointers to the summed
    6855              :    values in [PTR, END).  Return a pointer to the end of the used array.  */
    6856              : 
    6857              : static rtx **
    6858    134761134 : extract_plus_operands (rtx *loc, rtx **ptr, rtx **end)
    6859              : {
    6860    192868856 :   rtx x = *loc;
    6861    192868856 :   if (GET_CODE (x) == PLUS)
    6862              :     {
    6863     58107722 :       ptr = extract_plus_operands (&XEXP (x, 0), ptr, end);
    6864     58107722 :       ptr = extract_plus_operands (&XEXP (x, 1), ptr, end);
    6865              :     }
    6866              :   else
    6867              :     {
    6868    134761134 :       gcc_assert (ptr != end);
    6869    134761134 :       *ptr++ = loc;
    6870              :     }
    6871    134761134 :   return ptr;
    6872              : }
    6873              : 
    6874              : /* Evaluate the likelihood of X being a base or index value, returning
    6875              :    positive if it is likely to be a base, negative if it is likely to be
    6876              :    an index, and 0 if we can't tell.  Make the magnitude of the return
    6877              :    value reflect the amount of confidence we have in the answer.
    6878              : 
    6879              :    MODE, AS, OUTER_CODE and INDEX_CODE are as for ok_for_base_p_1.  */
    6880              : 
    6881              : static int
    6882      2815526 : baseness (rtx x, machine_mode mode, addr_space_t as,
    6883              :           enum rtx_code outer_code, enum rtx_code index_code)
    6884              : {
    6885              :   /* Believe *_POINTER unless the address shape requires otherwise.  */
    6886      2815526 :   if (REG_P (x) && REG_POINTER (x))
    6887              :     return 2;
    6888      1638135 :   if (MEM_P (x) && MEM_POINTER (x))
    6889              :     return 2;
    6890              : 
    6891      1638135 :   if (REG_P (x) && HARD_REGISTER_P (x))
    6892              :     {
    6893              :       /* X is a hard register.  If it only fits one of the base
    6894              :          or index classes, choose that interpretation.  */
    6895           12 :       int regno = REGNO (x);
    6896           12 :       bool base_p = ok_for_base_p_1 (regno, mode, as, outer_code, index_code);
    6897           12 :       bool index_p = REGNO_OK_FOR_INDEX_P (regno);
    6898           12 :       if (base_p != index_p)
    6899            0 :         return base_p ? 1 : -1;
    6900              :     }
    6901              :   return 0;
    6902              : }
    6903              : 
    6904              : /* INFO->INNER describes a normal, non-automodified address.
    6905              :    Fill in the rest of INFO accordingly.  */
    6906              : 
    6907              : static void
    6908     76653412 : decompose_normal_address (struct address_info *info)
    6909              : {
    6910              :   /* Treat the address as the sum of up to four values.  */
    6911     76653412 :   rtx *ops[4];
    6912     76653412 :   size_t n_ops = extract_plus_operands (info->inner, ops,
    6913     76653412 :                                         ops + ARRAY_SIZE (ops)) - ops;
    6914              : 
    6915              :   /* If there is more than one component, any base component is in a PLUS.  */
    6916     76653412 :   if (n_ops > 1)
    6917     56705035 :     info->base_outer_code = PLUS;
    6918              : 
    6919              :   /* Try to classify each sum operand now.  Leave those that could be
    6920              :      either a base or an index in OPS.  */
    6921     76653412 :   rtx *inner_ops[4];
    6922     76653412 :   size_t out = 0;
    6923    211414546 :   for (size_t in = 0; in < n_ops; ++in)
    6924              :     {
    6925    134761134 :       rtx *loc = ops[in];
    6926    134761134 :       rtx *inner = strip_address_mutations (loc);
    6927    134761134 :       if (CONSTANT_P (*inner))
    6928     67267763 :         set_address_disp (info, loc, inner);
    6929     67493371 :       else if (GET_CODE (*inner) == UNSPEC)
    6930           17 :         set_address_segment (info, loc, inner);
    6931              :       else
    6932              :         {
    6933              :           /* The only other possibilities are a base or an index.  */
    6934     67493354 :           rtx *base_term = get_base_term (inner);
    6935     67493354 :           rtx *index_term = get_index_term (inner);
    6936     67493354 :           gcc_assert (base_term || index_term);
    6937     67493354 :           if (!base_term)
    6938      2173584 :             set_address_index (info, loc, index_term);
    6939     65319770 :           else if (!index_term)
    6940            0 :             set_address_base (info, loc, base_term);
    6941              :           else
    6942              :             {
    6943     65319770 :               gcc_assert (base_term == index_term);
    6944     65319770 :               ops[out] = loc;
    6945     65319770 :               inner_ops[out] = base_term;
    6946     65319770 :               ++out;
    6947              :             }
    6948              :         }
    6949              :     }
    6950              : 
    6951              :   /* Classify the remaining OPS members as bases and indexes.  */
    6952     76653412 :   if (out == 1)
    6953              :     {
    6954              :       /* If we haven't seen a base or an index yet, assume that this is
    6955              :          the base.  If we were confident that another term was the base
    6956              :          or index, treat the remaining operand as the other kind.  */
    6957     62504244 :       if (!info->base)
    6958     62504244 :         set_address_base (info, ops[0], inner_ops[0]);
    6959              :       else
    6960            0 :         set_address_index (info, ops[0], inner_ops[0]);
    6961              :     }
    6962     14149168 :   else if (out == 2)
    6963              :     {
    6964      1407763 :       auto address_mode = targetm.addr_space.address_mode (info->as);
    6965      1407763 :       rtx inner_op0 = *inner_ops[0];
    6966      1407763 :       rtx inner_op1 = *inner_ops[1];
    6967      1407763 :       int base;
    6968              :       /* If one inner operand has the expected mode for a base and the other
    6969              :          doesn't, assume that the other one is the index.  This is useful
    6970              :          for addresses such as:
    6971              : 
    6972              :            (plus (zero_extend X) Y)
    6973              : 
    6974              :          zero_extend is not in itself enough to assume an index, since bases
    6975              :          can be zero-extended on POINTERS_EXTEND_UNSIGNED targets.  But if
    6976              :          Y has address mode and X doesn't, there should be little doubt that
    6977              :          Y is the base.  */
    6978      1407763 :       if (GET_MODE (inner_op0) == address_mode
    6979      1407763 :           && GET_MODE (inner_op1) != address_mode)
    6980              :         base = 0;
    6981      1407763 :       else if (GET_MODE (inner_op1) == address_mode
    6982      1407763 :                && GET_MODE (inner_op0) != address_mode)
    6983              :         base = 1;
    6984              :       /* In the event of a tie, assume the base comes first.  */
    6985      1407763 :       else if (baseness (inner_op0, info->mode, info->as, PLUS,
    6986      1407763 :                          GET_CODE (*ops[1]))
    6987      1407763 :                >= baseness (inner_op1, info->mode, info->as, PLUS,
    6988      1407763 :                             GET_CODE (*ops[0])))
    6989              :         base = 0;
    6990              :       else
    6991         5794 :         base = 1;
    6992      1407763 :       set_address_base (info, ops[base], inner_ops[base]);
    6993      1407763 :       set_address_index (info, ops[1 - base], inner_ops[1 - base]);
    6994              :     }
    6995              :   else
    6996     12741405 :     gcc_assert (out == 0);
    6997     76653412 : }
    6998              : 
    6999              : /* Describe address *LOC in *INFO.  MODE is the mode of the addressed value,
    7000              :    or VOIDmode if not known.  AS is the address space associated with LOC.
    7001              :    OUTER_CODE is MEM if *LOC is a MEM address and ADDRESS otherwise.  */
    7002              : 
    7003              : void
    7004     78749192 : decompose_address (struct address_info *info, rtx *loc, machine_mode mode,
    7005              :                    addr_space_t as, enum rtx_code outer_code)
    7006              : {
    7007     78749192 :   memset (info, 0, sizeof (*info));
    7008     78749192 :   info->mode = mode;
    7009     78749192 :   info->as = as;
    7010     78749192 :   info->addr_outer_code = outer_code;
    7011     78749192 :   info->outer = loc;
    7012     78749192 :   info->inner = strip_address_mutations (loc, &outer_code);
    7013     78749192 :   info->base_outer_code = outer_code;
    7014     78749192 :   switch (GET_CODE (*info->inner))
    7015              :     {
    7016      1990714 :     case PRE_DEC:
    7017      1990714 :     case PRE_INC:
    7018      1990714 :     case POST_DEC:
    7019      1990714 :     case POST_INC:
    7020      1990714 :       decompose_incdec_address (info);
    7021      1990714 :       break;
    7022              : 
    7023       105066 :     case PRE_MODIFY:
    7024       105066 :     case POST_MODIFY:
    7025       105066 :       decompose_automod_address (info);
    7026       105066 :       break;
    7027              : 
    7028     76653412 :     default:
    7029     76653412 :       decompose_normal_address (info);
    7030     76653412 :       break;
    7031              :     }
    7032     78749192 : }
    7033              : 
    7034              : /* Describe address operand LOC in INFO.  */
    7035              : 
    7036              : void
    7037      3631923 : decompose_lea_address (struct address_info *info, rtx *loc)
    7038              : {
    7039      3631923 :   decompose_address (info, loc, VOIDmode, ADDR_SPACE_GENERIC, ADDRESS);
    7040      3631923 : }
    7041              : 
    7042              : /* Describe the address of MEM X in INFO.  */
    7043              : 
    7044              : void
    7045     75103315 : decompose_mem_address (struct address_info *info, rtx x)
    7046              : {
    7047     75103315 :   gcc_assert (MEM_P (x));
    7048     75103315 :   decompose_address (info, &XEXP (x, 0), GET_MODE (x),
    7049     75103315 :                      MEM_ADDR_SPACE (x), MEM);
    7050     75103315 :   info->mem = x;
    7051     75103315 : }
    7052              : 
    7053              : /* Update INFO after a change to the address it describes.  */
    7054              : 
    7055              : void
    7056        13954 : update_address (struct address_info *info)
    7057              : {
    7058        13954 :   decompose_address (info, info->outer, info->mode, info->as,
    7059              :                      info->addr_outer_code);
    7060        13954 : }
    7061              : 
    7062              : /* Return the scale applied to *INFO->INDEX_TERM, or 0 if the index is
    7063              :    more complicated than that.  */
    7064              : 
    7065              : HOST_WIDE_INT
    7066            1 : get_index_scale (const struct address_info *info)
    7067              : {
    7068            1 :   rtx index = *info->index;
    7069            1 :   if (GET_CODE (index) == MULT
    7070            0 :       && CONST_INT_P (XEXP (index, 1))
    7071            0 :       && info->index_term == &XEXP (index, 0))
    7072            0 :     return INTVAL (XEXP (index, 1));
    7073              : 
    7074            1 :   if (GET_CODE (index) == ASHIFT
    7075            0 :       && CONST_INT_P (XEXP (index, 1))
    7076            0 :       && info->index_term == &XEXP (index, 0))
    7077            0 :     return HOST_WIDE_INT_1 << INTVAL (XEXP (index, 1));
    7078              : 
    7079            1 :   if (info->index == info->index_term)
    7080            1 :     return 1;
    7081              : 
    7082              :   return 0;
    7083              : }
    7084              : 
    7085              : /* Return the "index code" of INFO, in the form required by
    7086              :    ok_for_base_p_1.  */
    7087              : 
    7088              : enum rtx_code
    7089     33987094 : get_index_code (const struct address_info *info)
    7090              : {
    7091     33987094 :   if (info->index)
    7092      1450638 :     return GET_CODE (*info->index);
    7093              : 
    7094     32536456 :   if (info->disp)
    7095     26655927 :     return GET_CODE (*info->disp);
    7096              : 
    7097              :   return SCRATCH;
    7098              : }
    7099              : 
    7100              : /* Return true if RTL X contains a SYMBOL_REF.  */
    7101              : 
    7102              : bool
    7103       760484 : contains_symbol_ref_p (const_rtx x)
    7104              : {
    7105       760484 :   subrtx_iterator::array_type array;
    7106      3142440 :   FOR_EACH_SUBRTX (iter, array, x, ALL)
    7107      2459884 :     if (SYMBOL_REF_P (*iter))
    7108        77928 :       return true;
    7109              : 
    7110       682556 :   return false;
    7111       760484 : }
    7112              : 
    7113              : /* Return true if RTL X contains a SYMBOL_REF or LABEL_REF.  */
    7114              : 
    7115              : bool
    7116       618661 : contains_symbolic_reference_p (const_rtx x)
    7117              : {
    7118       618661 :   subrtx_iterator::array_type array;
    7119      1614551 :   FOR_EACH_SUBRTX (iter, array, x, ALL)
    7120      1000015 :     if (SYMBOL_REF_P (*iter) || GET_CODE (*iter) == LABEL_REF)
    7121         4125 :       return true;
    7122              : 
    7123       614536 :   return false;
    7124       618661 : }
    7125              : 
    7126              : /* Return true if RTL X contains a constant pool address.  */
    7127              : 
    7128              : bool
    7129            0 : contains_constant_pool_address_p (const_rtx x)
    7130              : {
    7131            0 :   subrtx_iterator::array_type array;
    7132            0 :   FOR_EACH_SUBRTX (iter, array, x, ALL)
    7133            0 :     if (SYMBOL_REF_P (*iter) && CONSTANT_POOL_ADDRESS_P (*iter))
    7134            0 :       return true;
    7135              : 
    7136            0 :   return false;
    7137            0 : }
    7138              : 
    7139              : 
    7140              : /* Return true if X contains a thread-local symbol.  */
    7141              : 
    7142              : bool
    7143            0 : tls_referenced_p (const_rtx x)
    7144              : {
    7145            0 :   if (!targetm.have_tls)
    7146              :     return false;
    7147              : 
    7148            0 :   subrtx_iterator::array_type array;
    7149            0 :   FOR_EACH_SUBRTX (iter, array, x, ALL)
    7150            0 :     if (GET_CODE (*iter) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (*iter) != 0)
    7151            0 :       return true;
    7152            0 :   return false;
    7153            0 : }
    7154              : 
    7155              : /* Process recursively X of INSN and add REG_INC notes if necessary.  */
    7156              : void
    7157            0 : add_auto_inc_notes (rtx_insn *insn, rtx x)
    7158              : {
    7159            0 :   enum rtx_code code = GET_CODE (x);
    7160            0 :   const char *fmt;
    7161            0 :   int i, j;
    7162              : 
    7163            0 :   if (code == MEM && auto_inc_p (XEXP (x, 0)))
    7164              :     {
    7165            0 :       add_reg_note (insn, REG_INC, XEXP (XEXP (x, 0), 0));
    7166            0 :       return;
    7167              :     }
    7168              : 
    7169              :   /* Scan all X sub-expressions.  */
    7170            0 :   fmt = GET_RTX_FORMAT (code);
    7171            0 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    7172              :     {
    7173            0 :       if (fmt[i] == 'e')
    7174            0 :         add_auto_inc_notes (insn, XEXP (x, i));
    7175            0 :       else if (fmt[i] == 'E')
    7176            0 :         for (j = XVECLEN (x, i) - 1; j >= 0; j--)
    7177            0 :           add_auto_inc_notes (insn, XVECEXP (x, i, j));
    7178              :     }
    7179              : }
    7180              : 
    7181              : /* Return true if INSN is the second element of a pair of macro-fused
    7182              :    single_sets, both of which having the same register output as another.  */
    7183              : bool
    7184     69481058 : single_output_fused_pair_p (rtx_insn *insn)
    7185              : {
    7186     69481058 :   rtx set, prev_set;
    7187     69481058 :   rtx_insn *prev;
    7188              : 
    7189     69481058 :   return INSN_P (insn)
    7190     69481058 :          && SCHED_GROUP_P (insn)
    7191      4181654 :          && (prev = prev_nonnote_nondebug_insn (insn))
    7192      4181654 :          && (set = single_set (insn)) != NULL_RTX
    7193      4181654 :          && (prev_set = single_set (prev))
    7194              :              != NULL_RTX
    7195      4181503 :          && REG_P (SET_DEST (set))
    7196            0 :          && REG_P (SET_DEST (prev_set))
    7197     69481058 :          && (!reload_completed
    7198            0 :              || REGNO (SET_DEST (set)) == REGNO (SET_DEST (prev_set)));
    7199              : }
    7200              : 
    7201              : /* Return true if X is register asm.  */
    7202              : 
    7203              : bool
    7204     18627721 : register_asm_p (const_rtx x)
    7205              : {
    7206     18627721 :   return (REG_P (x)
    7207     18627721 :           && REG_EXPR (x) != NULL_TREE
    7208      9082031 :           && HAS_DECL_ASSEMBLER_NAME_P (REG_EXPR (x))
    7209      2835097 :           && DECL_ASSEMBLER_NAME_SET_P (REG_EXPR (x))
    7210     18675558 :           && DECL_REGISTER (REG_EXPR (x)));
    7211              : }
    7212              : 
    7213              : /* Return true if, for all OP of mode OP_MODE:
    7214              : 
    7215              :      (vec_select:RESULT_MODE OP SEL)
    7216              : 
    7217              :    is equivalent to the highpart RESULT_MODE of OP.  */
    7218              : 
    7219              : bool
    7220            0 : vec_series_highpart_p (machine_mode result_mode, machine_mode op_mode, rtx sel)
    7221              : {
    7222            0 :   if (!targetm.can_change_mode_class (op_mode, result_mode, ALL_REGS))
    7223              :     return false;
    7224            0 :   if (BYTES_BIG_ENDIAN)
    7225              :     return rtvec_series_p (XVEC (sel, 0), 0);
    7226            0 :   poly_int64 offset = GET_MODE_NUNITS (op_mode) - XVECLEN (sel, 0);
    7227            0 :   return rtvec_series_p (XVEC (sel, 0), offset);
    7228              : }
    7229              : 
    7230              : /* Return true if, for all OP of mode OP_MODE:
    7231              : 
    7232              :      (vec_select:RESULT_MODE OP SEL)
    7233              : 
    7234              :    is equivalent to the lowpart RESULT_MODE of OP.  */
    7235              : 
    7236              : bool
    7237      5839209 : vec_series_lowpart_p (machine_mode result_mode, machine_mode op_mode, rtx sel)
    7238              : {
    7239      5839209 :   if (!targetm.can_change_mode_class (op_mode, result_mode, ALL_REGS))
    7240              :     return false;
    7241       719027 :   if (!BYTES_BIG_ENDIAN)
    7242       719027 :     return rtvec_series_p (XVEC (sel, 0), 0);
    7243              :   poly_int64 offset = GET_MODE_NUNITS (op_mode) - XVECLEN (sel, 0);
    7244              :   return rtvec_series_p (XVEC (sel, 0), offset);
    7245              : }
    7246              : 
    7247              : /* Return true if X contains a paradoxical subreg.  */
    7248              : 
    7249              : bool
    7250      1212165 : contains_paradoxical_subreg_p (rtx x)
    7251              : {
    7252      1212165 :   subrtx_var_iterator::array_type array;
    7253      5109408 :   FOR_EACH_SUBRTX_VAR (iter, array, x, NONCONST)
    7254              :     {
    7255      3947868 :       x = *iter;
    7256      3947868 :       if (SUBREG_P (x) && paradoxical_subreg_p (x))
    7257        50625 :         return true;
    7258              :     }
    7259      1161540 :   return false;
    7260      1212165 : }
    7261              : 
    7262              : /* Analyze X as accessing a consecutive sequence of bytes in some base
    7263              :    rtx that is no smaller than X.  Return the base value and set *OFFSET_PTR
    7264              :    to the byte offset of X from the start of the base.  Like SUBREG_BYTE,
    7265              :    this byte offset follows memory order.  */
    7266              : 
    7267              : rtx
    7268      4149268 : get_ref_base_and_offset (rtx x, poly_uint64 *offset_ptr)
    7269              : {
    7270      8298536 :   poly_uint64 outer_bytes = GET_MODE_SIZE (GET_MODE (x));
    7271      4149268 :   poly_uint64 offset = 0;
    7272      4638290 :   for (;;)
    7273              :     {
    7274      4638290 :       switch (GET_CODE (x))
    7275              :         {
    7276       494141 :         case SUBREG:
    7277       494141 :           if (!paradoxical_subreg_p (x))
    7278              :             {
    7279       458439 :               offset += SUBREG_BYTE (x);
    7280       458439 :               x = SUBREG_REG (x);
    7281       458439 :               continue;
    7282              :             }
    7283              :           break;
    7284              : 
    7285        14831 :         case ASHIFT:
    7286        14831 :         case LSHIFTRT:
    7287        14831 :         case ASHIFTRT:
    7288        14831 :           if (SCALAR_INT_MODE_P (GET_MODE (x))
    7289         4178 :               && CONST_INT_P (XEXP (x, 1))
    7290         2916 :               && UINTVAL (XEXP (x, 1)) % BITS_PER_UNIT == 0)
    7291              :             {
    7292          944 :               auto inner_bytes = GET_MODE_SIZE (GET_MODE (x));
    7293              :               /* Reanalyze the current extraction as a shift right of X.  */
    7294          944 :               poly_uint64 lsb = subreg_size_lsb (outer_bytes, inner_bytes,
    7295              :                                                  offset);
    7296              :               /* Convert it to a shift right of XEXP (x, 0).  This might
    7297              :                  wrap.  */
    7298          944 :               if (GET_CODE (x) == ASHIFT)
    7299           65 :                 lsb -= UINTVAL (XEXP (x, 1));
    7300              :               else
    7301          879 :                 lsb += UINTVAL (XEXP (x, 1));
    7302          944 :               if (known_le (lsb, (inner_bytes - outer_bytes) * BITS_PER_UNIT))
    7303              :                 {
    7304          513 :                   x = XEXP (x, 0);
    7305          513 :                   offset = subreg_size_offset_from_lsb (outer_bytes,
    7306          513 :                                                         inner_bytes, lsb);
    7307          513 :                   continue;
    7308              :                 }
    7309              :             }
    7310              :           break;
    7311              : 
    7312       221004 :         case VEC_SELECT:
    7313       221004 :           {
    7314       221004 :             rtx sel = XEXP (x, 1);
    7315       221004 :             poly_int64 start;
    7316       221004 :             if (poly_int_rtx_p (XVECEXP (sel, 0, 0), &start)
    7317       221004 :                 && rtvec_series_p (XVEC (sel, 0), start))
    7318              :               {
    7319        30070 :                 x = XEXP (x, 0);
    7320        60140 :                 offset += start * GET_MODE_UNIT_SIZE (GET_MODE (x));
    7321        30070 :                 continue;
    7322              :               }
    7323      4149268 :             break;
    7324              :           }
    7325              : 
    7326              :         default:
    7327              :           break;
    7328              :       }
    7329              : 
    7330      4149268 :     *offset_ptr = offset;
    7331      4149268 :      return x;
    7332              :    }
    7333              : }
        

Generated by: LCOV version 2.5.0-beta

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