LCOV - code coverage report
Current view: top level - gcc - postreload.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 97.5 % 1020 994
Test Date: 2024-04-20 14:03:02 Functions: 100.0 % 27 27
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Perform simple optimizations to clean up the result of reload.
       2                 :             :    Copyright (C) 1987-2024 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                 :             : #include "config.h"
      21                 :             : #include "system.h"
      22                 :             : #include "coretypes.h"
      23                 :             : #include "backend.h"
      24                 :             : #include "target.h"
      25                 :             : #include "rtl.h"
      26                 :             : #include "tree.h"
      27                 :             : #include "predict.h"
      28                 :             : #include "df.h"
      29                 :             : #include "memmodel.h"
      30                 :             : #include "tm_p.h"
      31                 :             : #include "optabs.h"
      32                 :             : #include "regs.h"
      33                 :             : #include "emit-rtl.h"
      34                 :             : #include "recog.h"
      35                 :             : 
      36                 :             : #include "cfgrtl.h"
      37                 :             : #include "cfgbuild.h"
      38                 :             : #include "cfgcleanup.h"
      39                 :             : #include "reload.h"
      40                 :             : #include "cselib.h"
      41                 :             : #include "tree-pass.h"
      42                 :             : #include "dbgcnt.h"
      43                 :             : #include "function-abi.h"
      44                 :             : #include "rtl-iter.h"
      45                 :             : 
      46                 :             : static bool reload_cse_simplify (rtx_insn *, rtx);
      47                 :             : static void reload_cse_regs_1 (void);
      48                 :             : static int reload_cse_simplify_set (rtx, rtx_insn *);
      49                 :             : static int reload_cse_simplify_operands (rtx_insn *, rtx);
      50                 :             : 
      51                 :             : static void reload_combine (void);
      52                 :             : static void reload_combine_note_use (rtx *, rtx_insn *, int, rtx);
      53                 :             : static void reload_combine_note_store (rtx, const_rtx, void *);
      54                 :             : 
      55                 :             : static bool reload_cse_move2add (rtx_insn *);
      56                 :             : static void move2add_note_store (rtx, const_rtx, void *);
      57                 :             : 
      58                 :             : /* Call cse / combine like post-reload optimization phases.
      59                 :             :    FIRST is the first instruction.  */
      60                 :             : 
      61                 :             : static void
      62                 :      987683 : reload_cse_regs (rtx_insn *first ATTRIBUTE_UNUSED)
      63                 :             : {
      64                 :      987683 :   bool moves_converted;
      65                 :      987683 :   reload_cse_regs_1 ();
      66                 :      987683 :   reload_combine ();
      67                 :      987683 :   moves_converted = reload_cse_move2add (first);
      68                 :      987683 :   if (flag_expensive_optimizations)
      69                 :             :     {
      70                 :      914366 :       if (moves_converted)
      71                 :        7992 :         reload_combine ();
      72                 :      914366 :       reload_cse_regs_1 ();
      73                 :             :     }
      74                 :      987683 : }
      75                 :             : 
      76                 :             : /* Try to simplify INSN.  Return true if the CFG may have changed.  */
      77                 :             : static bool
      78                 :   179711222 : reload_cse_simplify (rtx_insn *insn, rtx testreg)
      79                 :             : {
      80                 :   179711222 :   rtx body = PATTERN (insn);
      81                 :   179711222 :   basic_block insn_bb = BLOCK_FOR_INSN (insn);
      82                 :   179711222 :   unsigned insn_bb_succs = EDGE_COUNT (insn_bb->succs);
      83                 :             : 
      84                 :             :   /* If NO_FUNCTION_CSE has been set by the target, then we should not try
      85                 :             :      to cse function calls.  */
      86                 :   179711222 :   if (NO_FUNCTION_CSE && CALL_P (insn))
      87                 :             :     return false;
      88                 :             : 
      89                 :             :   /* Remember if this insn has been sp += const_int.  */
      90                 :   171159358 :   rtx sp_set = set_for_reg_notes (insn);
      91                 :   171159358 :   rtx sp_addend = NULL_RTX;
      92                 :   171159358 :   if (sp_set
      93                 :    62262578 :       && SET_DEST (sp_set) == stack_pointer_rtx
      94                 :     3279225 :       && GET_CODE (SET_SRC (sp_set)) == PLUS
      95                 :     3250113 :       && XEXP (SET_SRC (sp_set), 0) == stack_pointer_rtx
      96                 :     3250107 :       && CONST_INT_P (XEXP (SET_SRC (sp_set), 1)))
      97                 :   171159358 :     sp_addend = XEXP (SET_SRC (sp_set), 1);
      98                 :             : 
      99                 :   171159358 :   if (GET_CODE (body) == SET)
     100                 :             :     {
     101                 :    79661420 :       int count = 0;
     102                 :             : 
     103                 :             :       /* Simplify even if we may think it is a no-op.
     104                 :             :          We may think a memory load of a value smaller than WORD_SIZE
     105                 :             :          is redundant because we haven't taken into account possible
     106                 :             :          implicit extension.  reload_cse_simplify_set() will bring
     107                 :             :          this out, so it's safer to simplify before we delete.  */
     108                 :    79661420 :       count += reload_cse_simplify_set (body, insn);
     109                 :             : 
     110                 :    79661420 :       if (!count && cselib_redundant_set_p (body))
     111                 :             :         {
     112                 :      207238 :           if (check_for_inc_dec (insn))
     113                 :      207238 :             delete_insn_and_edges (insn);
     114                 :             :           /* We're done with this insn.  */
     115                 :      207238 :           goto done;
     116                 :             :         }
     117                 :             : 
     118                 :    79454182 :       if (count > 0)
     119                 :      124555 :         apply_change_group ();
     120                 :             :       else
     121                 :    79329627 :         reload_cse_simplify_operands (insn, testreg);
     122                 :             :     }
     123                 :    91497938 :   else if (GET_CODE (body) == PARALLEL)
     124                 :             :     {
     125                 :    13095279 :       int i;
     126                 :    13095279 :       int count = 0;
     127                 :    13095279 :       rtx value = NULL_RTX;
     128                 :             : 
     129                 :             :       /* Registers mentioned in the clobber list for an asm cannot be reused
     130                 :             :          within the body of the asm.  Invalidate those registers now so that
     131                 :             :          we don't try to substitute values for them.  */
     132                 :    13095279 :       if (asm_noperands (body) >= 0)
     133                 :             :         {
     134                 :      679747 :           for (i = XVECLEN (body, 0) - 1; i >= 0; --i)
     135                 :             :             {
     136                 :      524309 :               rtx part = XVECEXP (body, 0, i);
     137                 :      524309 :               if (GET_CODE (part) == CLOBBER && REG_P (XEXP (part, 0)))
     138                 :      221154 :                 cselib_invalidate_rtx (XEXP (part, 0));
     139                 :             :             }
     140                 :             :         }
     141                 :             : 
     142                 :             :       /* If every action in a PARALLEL is a noop, we can delete
     143                 :             :          the entire PARALLEL.  */
     144                 :    26268875 :       for (i = XVECLEN (body, 0) - 1; i >= 0; --i)
     145                 :             :         {
     146                 :    26264931 :           rtx part = XVECEXP (body, 0, i);
     147                 :    26264931 :           if (GET_CODE (part) == SET)
     148                 :             :             {
     149                 :    12993204 :               if (! cselib_redundant_set_p (part))
     150                 :             :                 break;
     151                 :        4051 :               if (REG_P (SET_DEST (part))
     152                 :        4051 :                   && REG_FUNCTION_VALUE_P (SET_DEST (part)))
     153                 :             :                 {
     154                 :           0 :                   if (value)
     155                 :             :                     break;
     156                 :             :                   value = SET_DEST (part);
     157                 :             :                 }
     158                 :             :             }
     159                 :    13271727 :           else if (GET_CODE (part) != CLOBBER && GET_CODE (part) != USE)
     160                 :             :             break;
     161                 :             :         }
     162                 :             : 
     163                 :    13095279 :       if (i < 0)
     164                 :             :         {
     165                 :        3944 :           if (check_for_inc_dec (insn))
     166                 :        3944 :             delete_insn_and_edges (insn);
     167                 :             :           /* We're done with this insn.  */
     168                 :        3944 :           goto done;
     169                 :             :         }
     170                 :             : 
     171                 :             :       /* It's not a no-op, but we can try to simplify it.  */
     172                 :    40123415 :       for (i = XVECLEN (body, 0) - 1; i >= 0; --i)
     173                 :    27032080 :         if (GET_CODE (XVECEXP (body, 0, i)) == SET)
     174                 :    13764205 :           count += reload_cse_simplify_set (XVECEXP (body, 0, i), insn);
     175                 :             : 
     176                 :    13091335 :       if (count > 0)
     177                 :        6583 :         apply_change_group ();
     178                 :             :       else
     179                 :    13084752 :         reload_cse_simplify_operands (insn, testreg);
     180                 :             :     }
     181                 :             : 
     182                 :             :   /* If sp += const_int insn is changed into sp = reg;, add REG_EQUAL
     183                 :             :      note so that the stack_adjustments pass can undo it if beneficial.  */
     184                 :   170948176 :   if (sp_addend
     185                 :     3250107 :       && SET_DEST (sp_set) == stack_pointer_rtx
     186                 :     3250107 :       && REG_P (SET_SRC (sp_set)))
     187                 :        4632 :     set_dst_reg_note (insn, REG_EQUAL,
     188                 :        4632 :                       gen_rtx_PLUS (Pmode, stack_pointer_rtx,
     189                 :             :                                     sp_addend), stack_pointer_rtx);
     190                 :             : 
     191                 :   170943544 : done:
     192                 :   342316957 :   return (EDGE_COUNT (insn_bb->succs) != insn_bb_succs);
     193                 :             : }
     194                 :             : 
     195                 :             : /* Do a very simple CSE pass over the hard registers.
     196                 :             : 
     197                 :             :    This function detects no-op moves where we happened to assign two
     198                 :             :    different pseudo-registers to the same hard register, and then
     199                 :             :    copied one to the other.  Reload will generate a useless
     200                 :             :    instruction copying a register to itself.
     201                 :             : 
     202                 :             :    This function also detects cases where we load a value from memory
     203                 :             :    into two different registers, and (if memory is more expensive than
     204                 :             :    registers) changes it to simply copy the first register into the
     205                 :             :    second register.
     206                 :             : 
     207                 :             :    Another optimization is performed that scans the operands of each
     208                 :             :    instruction to see whether the value is already available in a
     209                 :             :    hard register.  It then replaces the operand with the hard register
     210                 :             :    if possible, much like an optional reload would.  */
     211                 :             : 
     212                 :             : static void
     213                 :     1902049 : reload_cse_regs_1 (void)
     214                 :             : {
     215                 :     1902049 :   bool cfg_changed = false;
     216                 :     1902049 :   basic_block bb;
     217                 :     1902049 :   rtx_insn *insn;
     218                 :     1902049 :   rtx testreg = gen_rtx_REG (word_mode, LAST_VIRTUAL_REGISTER + 1);
     219                 :             : 
     220                 :     1902049 :   cselib_init (CSELIB_RECORD_MEMORY);
     221                 :     1902049 :   init_alias_analysis ();
     222                 :             : 
     223                 :    21190682 :   FOR_EACH_BB_FN (bb, cfun)
     224                 :   238962909 :     FOR_BB_INSNS (bb, insn)
     225                 :             :       {
     226                 :   219674276 :         if (INSN_P (insn))
     227                 :   179711222 :           cfg_changed |= reload_cse_simplify (insn, testreg);
     228                 :             : 
     229                 :   219674276 :         cselib_process_insn (insn);
     230                 :             :       }
     231                 :             : 
     232                 :             :   /* Clean up.  */
     233                 :     1902049 :   end_alias_analysis ();
     234                 :     1902049 :   cselib_finish ();
     235                 :     1902049 :   if (cfg_changed)
     236                 :          92 :     cleanup_cfg (0);
     237                 :     1902049 : }
     238                 :             : 
     239                 :             : /* Try to simplify a single SET instruction.  SET is the set pattern.
     240                 :             :    INSN is the instruction it came from.
     241                 :             :    This function only handles one case: if we set a register to a value
     242                 :             :    which is not a register, we try to find that value in some other register
     243                 :             :    and change the set into a register copy.  */
     244                 :             : 
     245                 :             : static int
     246                 :    93425625 : reload_cse_simplify_set (rtx set, rtx_insn *insn)
     247                 :             : {
     248                 :    93425625 :   int did_change = 0;
     249                 :    93425625 :   int dreg;
     250                 :    93425625 :   rtx src;
     251                 :    93425625 :   reg_class_t dclass;
     252                 :    93425625 :   int old_cost;
     253                 :    93425625 :   cselib_val *val;
     254                 :    93425625 :   struct elt_loc_list *l;
     255                 :    93425625 :   enum rtx_code extend_op = UNKNOWN;
     256                 :    93425625 :   bool speed = optimize_bb_for_speed_p (BLOCK_FOR_INSN (insn));
     257                 :             : 
     258                 :    93425625 :   dreg = true_regnum (SET_DEST (set));
     259                 :    93425625 :   if (dreg < 0)
     260                 :             :     return 0;
     261                 :             : 
     262                 :    63444733 :   src = SET_SRC (set);
     263                 :    63444733 :   if (side_effects_p (src) || true_regnum (src) >= 0)
     264                 :    11060879 :     return 0;
     265                 :             : 
     266                 :    52383854 :   dclass = REGNO_REG_CLASS (dreg);
     267                 :             : 
     268                 :             :   /* When replacing a memory with a register, we need to honor assumptions
     269                 :             :      that combine made wrt the contents of sign bits.  We'll do this by
     270                 :             :      generating an extend instruction instead of a reg->reg copy.  Thus
     271                 :             :      the destination must be a register that we can widen.  */
     272                 :    52383854 :   if (MEM_P (src)
     273                 :             :       && (extend_op = load_extend_op (GET_MODE (src))) != UNKNOWN
     274                 :             :       && !REG_P (SET_DEST (set)))
     275                 :             :     return 0;
     276                 :             : 
     277                 :    52383854 :   val = cselib_lookup (src, GET_MODE (SET_DEST (set)), 0, VOIDmode);
     278                 :    52383854 :   if (! val)
     279                 :             :     return 0;
     280                 :             : 
     281                 :             :   /* If memory loads are cheaper than register copies, don't change them.  */
     282                 :     5026619 :   if (MEM_P (src))
     283                 :      573884 :     old_cost = memory_move_cost (GET_MODE (src), dclass, true);
     284                 :     4452735 :   else if (REG_P (src))
     285                 :           0 :     old_cost = register_move_cost (GET_MODE (src),
     286                 :           0 :                                    REGNO_REG_CLASS (REGNO (src)), dclass);
     287                 :             :   else
     288                 :     4452735 :     old_cost = set_src_cost (src, GET_MODE (SET_DEST (set)), speed);
     289                 :             : 
     290                 :    10051497 :   for (l = val->locs; l; l = l->next)
     291                 :             :     {
     292                 :     5024878 :       rtx this_rtx = l->loc;
     293                 :     5024878 :       int this_cost;
     294                 :             : 
     295                 :     5024878 :       if (CONSTANT_P (this_rtx) && ! references_value_p (this_rtx, 0))
     296                 :             :         {
     297                 :     1875072 :           if (extend_op != UNKNOWN)
     298                 :             :             {
     299                 :             :               wide_int result;
     300                 :             : 
     301                 :             :               if (!CONST_SCALAR_INT_P (this_rtx))
     302                 :             :                 continue;
     303                 :             : 
     304                 :             :               switch (extend_op)
     305                 :             :                 {
     306                 :             :                 case ZERO_EXTEND:
     307                 :             :                   result = wide_int::from (rtx_mode_t (this_rtx,
     308                 :             :                                                        GET_MODE (src)),
     309                 :             :                                            BITS_PER_WORD, UNSIGNED);
     310                 :             :                   break;
     311                 :             :                 case SIGN_EXTEND:
     312                 :             :                   result = wide_int::from (rtx_mode_t (this_rtx,
     313                 :             :                                                        GET_MODE (src)),
     314                 :             :                                            BITS_PER_WORD, SIGNED);
     315                 :             :                   break;
     316                 :             :                 default:
     317                 :             :                   gcc_unreachable ();
     318                 :             :                 }
     319                 :             :               this_rtx = immed_wide_int_const (result, word_mode);
     320                 :             :             }
     321                 :             : 
     322                 :     1875072 :           this_cost = set_src_cost (this_rtx, GET_MODE (SET_DEST (set)), speed);
     323                 :             :         }
     324                 :     3149806 :       else if (REG_P (this_rtx))
     325                 :             :         {
     326                 :      765746 :           if (extend_op != UNKNOWN)
     327                 :             :             {
     328                 :             :               this_rtx = gen_rtx_fmt_e (extend_op, word_mode, this_rtx);
     329                 :             :               this_cost = set_src_cost (this_rtx, word_mode, speed);
     330                 :             :             }
     331                 :             :           else
     332                 :      765746 :             this_cost = register_move_cost (GET_MODE (this_rtx),
     333                 :      765746 :                                             REGNO_REG_CLASS (REGNO (this_rtx)),
     334                 :             :                                             dclass);
     335                 :             :         }
     336                 :             :       else
     337                 :     2384060 :         continue;
     338                 :             : 
     339                 :             :       /* If equal costs, prefer registers over anything else.  That
     340                 :             :          tends to lead to smaller instructions on some machines.  */
     341                 :     2640818 :       if (this_cost < old_cost
     342                 :     2514993 :           || (this_cost == old_cost
     343                 :     1891319 :               && REG_P (this_rtx)
     344                 :       16962 :               && !REG_P (SET_SRC (set))))
     345                 :             :         {
     346                 :      131314 :           if (extend_op != UNKNOWN
     347                 :             :               && REG_CAN_CHANGE_MODE_P (REGNO (SET_DEST (set)),
     348                 :             :                                         GET_MODE (SET_DEST (set)), word_mode))
     349                 :             :             {
     350                 :             :               rtx wide_dest = gen_rtx_REG (word_mode, REGNO (SET_DEST (set)));
     351                 :             :               ORIGINAL_REGNO (wide_dest) = ORIGINAL_REGNO (SET_DEST (set));
     352                 :             :               validate_change (insn, &SET_DEST (set), wide_dest, 1);
     353                 :             :             }
     354                 :             : 
     355                 :      131314 :           validate_unshare_change (insn, &SET_SRC (set), this_rtx, 1);
     356                 :      131314 :           old_cost = this_cost, did_change = 1;
     357                 :             :         }
     358                 :             :     }
     359                 :             : 
     360                 :             :   return did_change;
     361                 :             : }
     362                 :             : 
     363                 :             : /* Try to replace operands in INSN with equivalent values that are already
     364                 :             :    in registers.  This can be viewed as optional reloading.
     365                 :             : 
     366                 :             :    For each non-register operand in the insn, see if any hard regs are
     367                 :             :    known to be equivalent to that operand.  Record the alternatives which
     368                 :             :    can accept these hard registers.  Among all alternatives, select the
     369                 :             :    ones which are better or equal to the one currently matching, where
     370                 :             :    "better" is in terms of '?' and '!' constraints.  Among the remaining
     371                 :             :    alternatives, select the one which replaces most operands with
     372                 :             :    hard registers.  */
     373                 :             : 
     374                 :             : static int
     375                 :    92414379 : reload_cse_simplify_operands (rtx_insn *insn, rtx testreg)
     376                 :             : {
     377                 :    92414379 :   int i, j;
     378                 :             : 
     379                 :             :   /* For each operand, all registers that are equivalent to it.  */
     380                 :    92414379 :   HARD_REG_SET equiv_regs[MAX_RECOG_OPERANDS];
     381                 :             : 
     382                 :    92414379 :   const char *constraints[MAX_RECOG_OPERANDS];
     383                 :             : 
     384                 :             :   /* Vector recording how bad an alternative is.  */
     385                 :    92414379 :   int *alternative_reject;
     386                 :             :   /* Vector recording how many registers can be introduced by choosing
     387                 :             :      this alternative.  */
     388                 :    92414379 :   int *alternative_nregs;
     389                 :             :   /* Array of vectors recording, for each operand and each alternative,
     390                 :             :      which hard register to substitute, or -1 if the operand should be
     391                 :             :      left as it is.  */
     392                 :    92414379 :   int *op_alt_regno[MAX_RECOG_OPERANDS];
     393                 :             :   /* Array of alternatives, sorted in order of decreasing desirability.  */
     394                 :    92414379 :   int *alternative_order;
     395                 :             : 
     396                 :    92414379 :   extract_constrain_insn (insn);
     397                 :             : 
     398                 :    92414379 :   if (recog_data.n_alternatives == 0 || recog_data.n_operands == 0)
     399                 :             :     return 0;
     400                 :             : 
     401                 :    79925706 :   alternative_reject = XALLOCAVEC (int, recog_data.n_alternatives);
     402                 :    79925706 :   alternative_nregs = XALLOCAVEC (int, recog_data.n_alternatives);
     403                 :    79925706 :   alternative_order = XALLOCAVEC (int, recog_data.n_alternatives);
     404                 :    79925706 :   memset (alternative_reject, 0, recog_data.n_alternatives * sizeof (int));
     405                 :    79925706 :   memset (alternative_nregs, 0, recog_data.n_alternatives * sizeof (int));
     406                 :             : 
     407                 :             :   /* For each operand, find out which regs are equivalent.  */
     408                 :   258456951 :   for (i = 0; i < recog_data.n_operands; i++)
     409                 :             :     {
     410                 :             :       cselib_val *v;
     411                 :             :       struct elt_loc_list *l;
     412                 :             :       rtx op;
     413                 :             : 
     414                 :   178531245 :       CLEAR_HARD_REG_SET (equiv_regs[i]);
     415                 :             : 
     416                 :             :       /* cselib blows up on CODE_LABELs.  Trying to fix that doesn't seem
     417                 :             :          right, so avoid the problem here.  Similarly NOTE_INSN_DELETED_LABEL.
     418                 :             :          Likewise if we have a constant and the insn pattern doesn't tell us
     419                 :             :          the mode we need.  */
     420                 :   178531245 :       if (LABEL_P (recog_data.operand[i])
     421                 :   178518995 :           || (NOTE_P (recog_data.operand[i])
     422                 :          80 :               && NOTE_KIND (recog_data.operand[i]) == NOTE_INSN_DELETED_LABEL)
     423                 :   178518915 :           || (CONSTANT_P (recog_data.operand[i])
     424                 :    30831128 :               && recog_data.operand_mode[i] == VOIDmode))
     425                 :      432593 :         continue;
     426                 :             : 
     427                 :   178098652 :       op = recog_data.operand[i];
     428                 :   178098652 :       if (MEM_P (op) && load_extend_op (GET_MODE (op)) != UNKNOWN)
     429                 :             :         {
     430                 :             :           rtx set = single_set (insn);
     431                 :             : 
     432                 :             :           /* We might have multiple sets, some of which do implicit
     433                 :             :              extension.  Punt on this for now.  */
     434                 :             :           if (! set)
     435                 :             :             continue;
     436                 :             :           /* If the destination is also a MEM or a STRICT_LOW_PART, no
     437                 :             :              extension applies.
     438                 :             :              Also, if there is an explicit extension, we don't have to
     439                 :             :              worry about an implicit one.  */
     440                 :             :           else if (MEM_P (SET_DEST (set))
     441                 :             :                    || GET_CODE (SET_DEST (set)) == STRICT_LOW_PART
     442                 :             :                    || GET_CODE (SET_SRC (set)) == ZERO_EXTEND
     443                 :             :                    || GET_CODE (SET_SRC (set)) == SIGN_EXTEND)
     444                 :             :             ; /* Continue ordinary processing.  */
     445                 :             :           /* If the register cannot change mode to word_mode, it follows that
     446                 :             :              it cannot have been used in word_mode.  */
     447                 :             :           else if (REG_P (SET_DEST (set))
     448                 :             :                    && !REG_CAN_CHANGE_MODE_P (REGNO (SET_DEST (set)),
     449                 :             :                                               GET_MODE (SET_DEST (set)),
     450                 :             :                                               word_mode))
     451                 :             :             ; /* Continue ordinary processing.  */
     452                 :             :           /* If this is a straight load, make the extension explicit.  */
     453                 :             :           else if (REG_P (SET_DEST (set))
     454                 :             :                    && recog_data.n_operands == 2
     455                 :             :                    && SET_SRC (set) == op
     456                 :             :                    && SET_DEST (set) == recog_data.operand[1-i])
     457                 :             :             {
     458                 :             :               validate_change (insn, recog_data.operand_loc[i],
     459                 :             :                                gen_rtx_fmt_e (load_extend_op (GET_MODE (op)),
     460                 :             :                                               word_mode, op),
     461                 :             :                                1);
     462                 :             :               validate_change (insn, recog_data.operand_loc[1-i],
     463                 :             :                                gen_rtx_REG (word_mode, REGNO (SET_DEST (set))),
     464                 :             :                                1);
     465                 :             :               if (! apply_change_group ())
     466                 :             :                 return 0;
     467                 :             :               return reload_cse_simplify_operands (insn, testreg);
     468                 :             :             }
     469                 :             :           else
     470                 :             :             /* ??? There might be arithmetic operations with memory that are
     471                 :             :                safe to optimize, but is it worth the trouble?  */
     472                 :             :             continue;
     473                 :             :         }
     474                 :             : 
     475                 :   178098652 :       if (side_effects_p (op))
     476                 :     4463033 :         continue;
     477                 :   173635619 :       v = cselib_lookup (op, recog_data.operand_mode[i], 0, VOIDmode);
     478                 :   173635619 :       if (! v)
     479                 :   114995990 :         continue;
     480                 :             : 
     481                 :   172257836 :       for (l = v->locs; l; l = l->next)
     482                 :   113618207 :         if (REG_P (l->loc))
     483                 :    61433896 :           SET_HARD_REG_BIT (equiv_regs[i], REGNO (l->loc));
     484                 :             :     }
     485                 :             : 
     486                 :    79925706 :   alternative_mask preferred = get_preferred_alternatives (insn);
     487                 :   258456951 :   for (i = 0; i < recog_data.n_operands; i++)
     488                 :             :     {
     489                 :   178531245 :       machine_mode mode;
     490                 :   178531245 :       int regno;
     491                 :   178531245 :       const char *p;
     492                 :             : 
     493                 :   178531245 :       op_alt_regno[i] = XALLOCAVEC (int, recog_data.n_alternatives);
     494                 :  2621208804 :       for (j = 0; j < recog_data.n_alternatives; j++)
     495                 :  2442677559 :         op_alt_regno[i][j] = -1;
     496                 :             : 
     497                 :   178531245 :       p = constraints[i] = recog_data.constraints[i];
     498                 :   178531245 :       mode = recog_data.operand_mode[i];
     499                 :             : 
     500                 :             :       /* Add the reject values for each alternative given by the constraints
     501                 :             :          for this operand.  */
     502                 :   178531245 :       j = 0;
     503                 :  7109995103 :       while (*p != '\0')
     504                 :             :         {
     505                 :  6931463858 :           char c = *p++;
     506                 :  6931463858 :           if (c == ',')
     507                 :  2256301509 :             j++;
     508                 :  4675162349 :           else if (c == '?')
     509                 :   565233565 :             alternative_reject[j] += 3;
     510                 :  4109928784 :           else if (c == '!')
     511                 :    18722425 :             alternative_reject[j] += 300;
     512                 :             :         }
     513                 :             : 
     514                 :             :       /* We won't change operands which are already registers.  We
     515                 :             :          also don't want to modify output operands.  */
     516                 :   178531245 :       regno = true_regnum (recog_data.operand[i]);
     517                 :   178531245 :       if (regno >= 0
     518                 :    70431201 :           || constraints[i][0] == '='
     519                 :    53091925 :           || constraints[i][0] == '+')
     520                 :   125554367 :         continue;
     521                 :             : 
     522                 :  4926849654 :       for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
     523                 :             :         {
     524                 :  4873872776 :           enum reg_class rclass = NO_REGS;
     525                 :             : 
     526                 :  4873872776 :           if (! TEST_HARD_REG_BIT (equiv_regs[i], regno))
     527                 :  4873135656 :             continue;
     528                 :             : 
     529                 :      737120 :           set_mode_and_regno (testreg, mode, regno);
     530                 :             : 
     531                 :             :           /* We found a register equal to this operand.  Now look for all
     532                 :             :              alternatives that can accept this register and have not been
     533                 :             :              assigned a register they can use yet.  */
     534                 :      737120 :           j = 0;
     535                 :      737120 :           p = constraints[i];
     536                 :    38480385 :           for (;;)
     537                 :             :             {
     538                 :    38480385 :               char c = *p;
     539                 :             : 
     540                 :    38480385 :               switch (c)
     541                 :             :                 {
     542                 :      193101 :                 case 'g':
     543                 :      193101 :                   rclass = reg_class_subunion[rclass][GENERAL_REGS];
     544                 :      193101 :                   break;
     545                 :             : 
     546                 :    24309163 :                 default:
     547                 :    24309163 :                   rclass
     548                 :    24309163 :                     = (reg_class_subunion
     549                 :    24309163 :                        [rclass]
     550                 :    24309163 :                        [reg_class_for_constraint (lookup_constraint (p))]);
     551                 :    24309163 :                   break;
     552                 :             : 
     553                 :    13978121 :                 case ',': case '\0':
     554                 :             :                   /* See if REGNO fits this alternative, and set it up as the
     555                 :             :                      replacement register if we don't have one for this
     556                 :             :                      alternative yet and the operand being replaced is not
     557                 :             :                      a cheap CONST_INT.  */
     558                 :    13978121 :                   if (op_alt_regno[i][j] == -1
     559                 :    13913650 :                       && TEST_BIT (preferred, j)
     560                 :    11981038 :                       && reg_fits_class_p (testreg, rclass, 0, mode)
     561                 :    16879260 :                       && (!CONST_INT_P (recog_data.operand[i])
     562                 :     2766054 :                           || (set_src_cost (recog_data.operand[i], mode,
     563                 :             :                                             optimize_bb_for_speed_p
     564                 :     2766054 :                                              (BLOCK_FOR_INSN (insn)))
     565                 :     2766054 :                               > set_src_cost (testreg, mode,
     566                 :             :                                               optimize_bb_for_speed_p
     567                 :     2766054 :                                                (BLOCK_FOR_INSN (insn))))))
     568                 :             :                     {
     569                 :      140515 :                       alternative_nregs[j]++;
     570                 :      140515 :                       op_alt_regno[i][j] = regno;
     571                 :             :                     }
     572                 :    13978121 :                   j++;
     573                 :    13978121 :                   rclass = NO_REGS;
     574                 :    13978121 :                   break;
     575                 :             :                 }
     576                 :    38480385 :               p += CONSTRAINT_LEN (c, p);
     577                 :             : 
     578                 :    38480385 :               if (c == '\0')
     579                 :             :                 break;
     580                 :             :             }
     581                 :             :         }
     582                 :             :     }
     583                 :             : 
     584                 :             :   /* The loop below sets alternative_order[0] but -Wmaybe-uninitialized
     585                 :             :      can't know that.  Clear it here to avoid the warning.  */
     586                 :    79925706 :   alternative_order[0] = 0;
     587                 :    79925706 :   gcc_assert (!recog_data.n_alternatives
     588                 :             :               || (which_alternative >= 0
     589                 :             :                   && which_alternative < recog_data.n_alternatives));
     590                 :             : 
     591                 :             :   /* Record all alternatives which are better or equal to the currently
     592                 :             :      matching one in the alternative_order array.  */
     593                 :  1252587172 :   for (i = j = 0; i < recog_data.n_alternatives; i++)
     594                 :  1172661466 :     if (alternative_reject[i] <= alternative_reject[which_alternative])
     595                 :   676325290 :       alternative_order[j++] = i;
     596                 :    79925706 :   recog_data.n_alternatives = j;
     597                 :             : 
     598                 :             :   /* Sort it.  Given a small number of alternatives, a dumb algorithm
     599                 :             :      won't hurt too much.  */
     600                 :   676325290 :   for (i = 0; i < recog_data.n_alternatives - 1; i++)
     601                 :             :     {
     602                 :   596399584 :       int best = i;
     603                 :   596399584 :       int best_reject = alternative_reject[alternative_order[i]];
     604                 :   596399584 :       int best_nregs = alternative_nregs[alternative_order[i]];
     605                 :             : 
     606                 :  4150975801 :       for (j = i + 1; j < recog_data.n_alternatives; j++)
     607                 :             :         {
     608                 :  3554576217 :           int this_reject = alternative_reject[alternative_order[j]];
     609                 :  3554576217 :           int this_nregs = alternative_nregs[alternative_order[j]];
     610                 :             : 
     611                 :  3554576217 :           if (this_reject < best_reject
     612                 :  3547417174 :               || (this_reject == best_reject && this_nregs > best_nregs))
     613                 :             :             {
     614                 :     7248566 :               best = j;
     615                 :     7248566 :               best_reject = this_reject;
     616                 :     7248566 :               best_nregs = this_nregs;
     617                 :             :             }
     618                 :             :         }
     619                 :             : 
     620                 :   596399584 :       std::swap (alternative_order[best], alternative_order[i]);
     621                 :             :     }
     622                 :             : 
     623                 :             :   /* Substitute the operands as determined by op_alt_regno for the best
     624                 :             :      alternative.  */
     625                 :    79925706 :   j = alternative_order[0];
     626                 :             : 
     627                 :   258456951 :   for (i = 0; i < recog_data.n_operands; i++)
     628                 :             :     {
     629                 :   178531245 :       machine_mode mode = recog_data.operand_mode[i];
     630                 :   178531245 :       if (op_alt_regno[i][j] == -1)
     631                 :   178482718 :         continue;
     632                 :             : 
     633                 :       48527 :       validate_change (insn, recog_data.operand_loc[i],
     634                 :             :                        gen_rtx_REG (mode, op_alt_regno[i][j]), 1);
     635                 :             :     }
     636                 :             : 
     637                 :    81182786 :   for (i = recog_data.n_dups - 1; i >= 0; i--)
     638                 :             :     {
     639                 :     1257080 :       int op = recog_data.dup_num[i];
     640                 :     1257080 :       machine_mode mode = recog_data.operand_mode[op];
     641                 :             : 
     642                 :     1257080 :       if (op_alt_regno[op][j] == -1)
     643                 :     1256768 :         continue;
     644                 :             : 
     645                 :         312 :       validate_change (insn, recog_data.dup_loc[i],
     646                 :             :                        gen_rtx_REG (mode, op_alt_regno[op][j]), 1);
     647                 :             :     }
     648                 :             : 
     649                 :    79925706 :   return apply_change_group ();
     650                 :             : }
     651                 :             : 
     652                 :             : /* If reload couldn't use reg+reg+offset addressing, try to use reg+reg
     653                 :             :    addressing now.
     654                 :             :    This code might also be useful when reload gave up on reg+reg addressing
     655                 :             :    because of clashes between the return register and INDEX_REG_CLASS.  */
     656                 :             : 
     657                 :             : /* The maximum number of uses of a register we can keep track of to
     658                 :             :    replace them with reg+reg addressing.  */
     659                 :             : #define RELOAD_COMBINE_MAX_USES 16
     660                 :             : 
     661                 :             : /* Describes a recorded use of a register.  */
     662                 :             : struct reg_use
     663                 :             : {
     664                 :             :   /* The insn where a register has been used.  */
     665                 :             :   rtx_insn *insn;
     666                 :             :   /* Points to the memory reference enclosing the use, if any, NULL_RTX
     667                 :             :      otherwise.  */
     668                 :             :   rtx containing_mem;
     669                 :             :   /* Location of the register within INSN.  */
     670                 :             :   rtx *usep;
     671                 :             :   /* The reverse uid of the insn.  */
     672                 :             :   int ruid;
     673                 :             : };
     674                 :             : 
     675                 :             : /* If the register is used in some unknown fashion, USE_INDEX is negative.
     676                 :             :    If it is dead, USE_INDEX is RELOAD_COMBINE_MAX_USES, and STORE_RUID
     677                 :             :    indicates where it is first set or clobbered.
     678                 :             :    Otherwise, USE_INDEX is the index of the last encountered use of the
     679                 :             :    register (which is first among these we have seen since we scan backwards).
     680                 :             :    USE_RUID indicates the first encountered, i.e. last, of these uses.
     681                 :             :    If ALL_OFFSETS_MATCH is true, all encountered uses were inside a PLUS
     682                 :             :    with a constant offset; OFFSET contains this constant in that case.
     683                 :             :    STORE_RUID is always meaningful if we only want to use a value in a
     684                 :             :    register in a different place: it denotes the next insn in the insn
     685                 :             :    stream (i.e. the last encountered) that sets or clobbers the register.
     686                 :             :    REAL_STORE_RUID is similar, but clobbers are ignored when updating it.
     687                 :             :    EXPR is the expression used when storing the register.  */
     688                 :             : static struct
     689                 :             :   {
     690                 :             :     struct reg_use reg_use[RELOAD_COMBINE_MAX_USES];
     691                 :             :     rtx offset;
     692                 :             :     int use_index;
     693                 :             :     int store_ruid;
     694                 :             :     int real_store_ruid;
     695                 :             :     int use_ruid;
     696                 :             :     bool all_offsets_match;
     697                 :             :     rtx expr;
     698                 :             :   } reg_state[FIRST_PSEUDO_REGISTER];
     699                 :             : 
     700                 :             : /* Reverse linear uid.  This is increased in reload_combine while scanning
     701                 :             :    the instructions from last to first.  It is used to set last_label_ruid
     702                 :             :    and the store_ruid / use_ruid fields in reg_state.  */
     703                 :             : static int reload_combine_ruid;
     704                 :             : 
     705                 :             : /* The RUID of the last label we encountered in reload_combine.  */
     706                 :             : static int last_label_ruid;
     707                 :             : 
     708                 :             : /* The RUID of the last jump we encountered in reload_combine.  */
     709                 :             : static int last_jump_ruid;
     710                 :             : 
     711                 :             : /* The register numbers of the first and last index register.  A value of
     712                 :             :    -1 in LAST_INDEX_REG indicates that we've previously computed these
     713                 :             :    values and found no suitable index registers.  */
     714                 :             : static int first_index_reg = -1;
     715                 :             : static int last_index_reg;
     716                 :             : 
     717                 :             : #define LABEL_LIVE(LABEL) \
     718                 :             :   (label_live[CODE_LABEL_NUMBER (LABEL) - min_labelno])
     719                 :             : 
     720                 :             : /* Subroutine of reload_combine_split_ruids, called to fix up a single
     721                 :             :    ruid pointed to by *PRUID if it is higher than SPLIT_RUID.  */
     722                 :             : 
     723                 :             : static inline void
     724                 :      216076 : reload_combine_split_one_ruid (int *pruid, int split_ruid)
     725                 :             : {
     726                 :      216076 :   if (*pruid > split_ruid)
     727                 :        9260 :     (*pruid)++;
     728                 :             : }
     729                 :             : 
     730                 :             : /* Called when we insert a new insn in a position we've already passed in
     731                 :             :    the scan.  Examine all our state, increasing all ruids that are higher
     732                 :             :    than SPLIT_RUID by one in order to make room for a new insn.  */
     733                 :             : 
     734                 :             : static void
     735                 :         765 : reload_combine_split_ruids (int split_ruid)
     736                 :             : {
     737                 :         765 :   unsigned i;
     738                 :             : 
     739                 :         765 :   reload_combine_split_one_ruid (&reload_combine_ruid, split_ruid);
     740                 :         765 :   reload_combine_split_one_ruid (&last_label_ruid, split_ruid);
     741                 :         765 :   reload_combine_split_one_ruid (&last_jump_ruid, split_ruid);
     742                 :             : 
     743                 :       71145 :   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
     744                 :             :     {
     745                 :       70380 :       int j, idx = reg_state[i].use_index;
     746                 :       70380 :       reload_combine_split_one_ruid (&reg_state[i].use_ruid, split_ruid);
     747                 :       70380 :       reload_combine_split_one_ruid (&reg_state[i].store_ruid, split_ruid);
     748                 :       70380 :       reload_combine_split_one_ruid (&reg_state[i].real_store_ruid,
     749                 :             :                                      split_ruid);
     750                 :       70380 :       if (idx < 0)
     751                 :       28528 :         continue;
     752                 :       44493 :       for (j = idx; j < RELOAD_COMBINE_MAX_USES; j++)
     753                 :             :         {
     754                 :        4560 :           reload_combine_split_one_ruid (&reg_state[i].reg_use[j].ruid,
     755                 :             :                                          split_ruid);
     756                 :             :         }
     757                 :             :     }
     758                 :         765 : }
     759                 :             : 
     760                 :             : /* Called when we are about to rescan a previously encountered insn with
     761                 :             :    reload_combine_note_use after modifying some part of it.  This clears all
     762                 :             :    information about uses in that particular insn.  */
     763                 :             : 
     764                 :             : static void
     765                 :       24563 : reload_combine_purge_insn_uses (rtx_insn *insn)
     766                 :             : {
     767                 :       24563 :   unsigned i;
     768                 :             : 
     769                 :     2284359 :   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
     770                 :             :     {
     771                 :     2259796 :       int j, k, idx = reg_state[i].use_index;
     772                 :     2259796 :       if (idx < 0)
     773                 :      480391 :         continue;
     774                 :             :       j = k = RELOAD_COMBINE_MAX_USES;
     775                 :     2059485 :       while (j-- > idx)
     776                 :             :         {
     777                 :      280080 :           if (reg_state[i].reg_use[j].insn != insn)
     778                 :             :             {
     779                 :      253650 :               k--;
     780                 :      253650 :               if (k != j)
     781                 :        5998 :                 reg_state[i].reg_use[k] = reg_state[i].reg_use[j];
     782                 :             :             }
     783                 :             :         }
     784                 :     1779405 :       reg_state[i].use_index = k;
     785                 :             :     }
     786                 :       24563 : }
     787                 :             : 
     788                 :             : /* Called when we need to forget about all uses of REGNO after an insn
     789                 :             :    which is identified by RUID.  */
     790                 :             : 
     791                 :             : static void
     792                 :         765 : reload_combine_purge_reg_uses_after_ruid (unsigned regno, int ruid)
     793                 :             : {
     794                 :         765 :   int j, k, idx = reg_state[regno].use_index;
     795                 :         765 :   if (idx < 0)
     796                 :             :     return;
     797                 :             :   j = k = RELOAD_COMBINE_MAX_USES;
     798                 :        3045 :   while (j-- > idx)
     799                 :             :     {
     800                 :        2280 :       if (reg_state[regno].reg_use[j].ruid >= ruid)
     801                 :             :         {
     802                 :        1146 :           k--;
     803                 :        1146 :           if (k != j)
     804                 :         735 :             reg_state[regno].reg_use[k] = reg_state[regno].reg_use[j];
     805                 :             :         }
     806                 :             :     }
     807                 :         765 :   reg_state[regno].use_index = k;
     808                 :             : }
     809                 :             : 
     810                 :             : /* Find the use of REGNO with the ruid that is highest among those
     811                 :             :    lower than RUID_LIMIT, and return it if it is the only use of this
     812                 :             :    reg in the insn.  Return NULL otherwise.  */
     813                 :             : 
     814                 :             : static struct reg_use *
     815                 :     3109422 : reload_combine_closest_single_use (unsigned regno, int ruid_limit)
     816                 :             : {
     817                 :     3109422 :   int i, best_ruid = 0;
     818                 :     3109422 :   int use_idx = reg_state[regno].use_index;
     819                 :     3109422 :   struct reg_use *retval;
     820                 :             : 
     821                 :     3109422 :   if (use_idx < 0)
     822                 :             :     return NULL;
     823                 :             :   retval = NULL;
     824                 :     3661793 :   for (i = use_idx; i < RELOAD_COMBINE_MAX_USES; i++)
     825                 :             :     {
     826                 :     2183233 :       struct reg_use *use = reg_state[regno].reg_use + i; 
     827                 :     2183233 :       int this_ruid = use->ruid;
     828                 :     2183233 :       if (this_ruid >= ruid_limit)
     829                 :      826400 :         continue;
     830                 :     1356833 :       if (this_ruid > best_ruid)
     831                 :             :         {
     832                 :             :           best_ruid = this_ruid;
     833                 :             :           retval = use;
     834                 :             :         }
     835                 :      414567 :       else if (this_ruid == best_ruid)
     836                 :     2183233 :         retval = NULL;
     837                 :             :     }
     838                 :     1478560 :   if (last_label_ruid >= best_ruid)
     839                 :      597840 :     return NULL;
     840                 :             :   return retval;
     841                 :             : }
     842                 :             : 
     843                 :             : /* After we've moved an add insn, fix up any debug insns that occur
     844                 :             :    between the old location of the add and the new location.  REG is
     845                 :             :    the destination register of the add insn; REPLACEMENT is the
     846                 :             :    SET_SRC of the add.  FROM and TO specify the range in which we
     847                 :             :    should make this change on debug insns.  */
     848                 :             : 
     849                 :             : static void
     850                 :        1060 : fixup_debug_insns (rtx reg, rtx replacement, rtx_insn *from, rtx_insn *to)
     851                 :             : {
     852                 :        1060 :   rtx_insn *insn;
     853                 :       18829 :   for (insn = from; insn != to; insn = NEXT_INSN (insn))
     854                 :             :     {
     855                 :       17769 :       rtx t;
     856                 :             : 
     857                 :       17769 :       if (!DEBUG_BIND_INSN_P (insn))
     858                 :       12239 :         continue;
     859                 :             :       
     860                 :        5530 :       t = INSN_VAR_LOCATION_LOC (insn);
     861                 :        5530 :       t = simplify_replace_rtx (t, reg, replacement);
     862                 :        5530 :       validate_change (insn, &INSN_VAR_LOCATION_LOC (insn), t, 0);
     863                 :             :     }
     864                 :        1060 : }
     865                 :             : 
     866                 :             : /* Subroutine of reload_combine_recognize_const_pattern.  Try to replace REG
     867                 :             :    with SRC in the insn described by USE, taking costs into account.  Return
     868                 :             :    true if we made the replacement.  */
     869                 :             : 
     870                 :             : static bool
     871                 :      754762 : try_replace_in_use (struct reg_use *use, rtx reg, rtx src)
     872                 :             : {
     873                 :      754762 :   rtx_insn *use_insn = use->insn;
     874                 :      754762 :   rtx mem = use->containing_mem;
     875                 :      754762 :   bool speed = optimize_bb_for_speed_p (BLOCK_FOR_INSN (use_insn));
     876                 :             : 
     877                 :      754762 :   if (mem != NULL_RTX)
     878                 :             :     {
     879                 :       33998 :       addr_space_t as = MEM_ADDR_SPACE (mem);
     880                 :       33998 :       rtx oldaddr = XEXP (mem, 0);
     881                 :       33998 :       rtx newaddr = NULL_RTX;
     882                 :       33998 :       int old_cost = address_cost (oldaddr, GET_MODE (mem), as, speed);
     883                 :       33998 :       int new_cost;
     884                 :             : 
     885                 :       33998 :       newaddr = simplify_replace_rtx (oldaddr, reg, src);
     886                 :       33998 :       if (memory_address_addr_space_p (GET_MODE (mem), newaddr, as))
     887                 :             :         {
     888                 :       24460 :           XEXP (mem, 0) = newaddr;
     889                 :       24460 :           new_cost = address_cost (newaddr, GET_MODE (mem), as, speed);
     890                 :       24460 :           XEXP (mem, 0) = oldaddr;
     891                 :       24460 :           if (new_cost <= old_cost
     892                 :       24460 :               && validate_change (use_insn,
     893                 :             :                                   &XEXP (mem, 0), newaddr, 0))
     894                 :             :             return true;
     895                 :             :         }
     896                 :             :     }
     897                 :             :   else
     898                 :             :     {
     899                 :      720764 :       rtx new_set = single_set (use_insn);
     900                 :      720764 :       if (new_set
     901                 :      719878 :           && REG_P (SET_DEST (new_set))
     902                 :      283288 :           && GET_CODE (SET_SRC (new_set)) == PLUS
     903                 :       13214 :           && REG_P (XEXP (SET_SRC (new_set), 0))
     904                 :       12732 :           && CONSTANT_P (XEXP (SET_SRC (new_set), 1)))
     905                 :             :         {
     906                 :        1211 :           rtx new_src;
     907                 :        1211 :           machine_mode mode = GET_MODE (SET_DEST (new_set));
     908                 :        1211 :           int old_cost = set_src_cost (SET_SRC (new_set), mode, speed);
     909                 :             : 
     910                 :        1211 :           gcc_assert (rtx_equal_p (XEXP (SET_SRC (new_set), 0), reg));
     911                 :        1211 :           new_src = simplify_replace_rtx (SET_SRC (new_set), reg, src);
     912                 :             : 
     913                 :        1211 :           if (set_src_cost (new_src, mode, speed) <= old_cost
     914                 :        1211 :               && validate_change (use_insn, &SET_SRC (new_set),
     915                 :             :                                   new_src, 0))
     916                 :             :             return true;
     917                 :             :         }
     918                 :             :     }
     919                 :             :   return false;
     920                 :             : }
     921                 :             : 
     922                 :             : /* Called by reload_combine when scanning INSN.  This function tries to detect
     923                 :             :    patterns where a constant is added to a register, and the result is used
     924                 :             :    in an address.
     925                 :             :    Return true if no further processing is needed on INSN; false if it wasn't
     926                 :             :    recognized and should be handled normally.  */
     927                 :             : 
     928                 :             : static bool
     929                 :    55735385 : reload_combine_recognize_const_pattern (rtx_insn *insn)
     930                 :             : {
     931                 :    55735385 :   int from_ruid = reload_combine_ruid;
     932                 :    55735385 :   rtx set, pat, reg, src, addreg;
     933                 :    55735385 :   unsigned int regno;
     934                 :    55735385 :   struct reg_use *use;
     935                 :    55735385 :   bool must_move_add;
     936                 :    55735385 :   rtx_insn *add_moved_after_insn = NULL;
     937                 :    55735385 :   int add_moved_after_ruid = 0;
     938                 :    55735385 :   int clobbered_regno = -1;
     939                 :             : 
     940                 :    55735385 :   set = single_set (insn);
     941                 :    55735385 :   if (set == NULL_RTX)
     942                 :             :     return false;
     943                 :             : 
     944                 :    51782206 :   reg = SET_DEST (set);
     945                 :    51782206 :   src = SET_SRC (set);
     946                 :    51782206 :   if (!REG_P (reg)
     947                 :    35536684 :       || REG_NREGS (reg) != 1
     948                 :    34956263 :       || GET_MODE (reg) != Pmode
     949                 :    72018432 :       || reg == stack_pointer_rtx)
     950                 :             :     return false;
     951                 :             : 
     952                 :    18547588 :   regno = REGNO (reg);
     953                 :             : 
     954                 :             :   /* We look for a REG1 = REG2 + CONSTANT insn, followed by either
     955                 :             :      uses of REG1 inside an address, or inside another add insn.  If
     956                 :             :      possible and profitable, merge the addition into subsequent
     957                 :             :      uses.  */
     958                 :    18547588 :   if (GET_CODE (src) != PLUS
     959                 :     3209067 :       || !REG_P (XEXP (src, 0))
     960                 :     3000941 :       || !CONSTANT_P (XEXP (src, 1)))
     961                 :             :     return false;
     962                 :             : 
     963                 :     2442012 :   addreg = XEXP (src, 0);
     964                 :     2442012 :   must_move_add = rtx_equal_p (reg, addreg);
     965                 :             : 
     966                 :     2442012 :   pat = PATTERN (insn);
     967                 :     2442012 :   if (must_move_add && set != pat)
     968                 :             :     {
     969                 :             :       /* We have to be careful when moving the add; apart from the
     970                 :             :          single_set there may also be clobbers.  Recognize one special
     971                 :             :          case, that of one clobber alongside the set (likely a clobber
     972                 :             :          of the CC register).  */
     973                 :      693867 :       gcc_assert (GET_CODE (PATTERN (insn)) == PARALLEL);
     974                 :      693867 :       if (XVECLEN (pat, 0) != 2 || XVECEXP (pat, 0, 0) != set
     975                 :      693867 :           || GET_CODE (XVECEXP (pat, 0, 1)) != CLOBBER
     976                 :      693867 :           || !REG_P (XEXP (XVECEXP (pat, 0, 1), 0)))
     977                 :             :         return false;
     978                 :      693867 :       clobbered_regno = REGNO (XEXP (XVECEXP (pat, 0, 1), 0));
     979                 :             :     }
     980                 :             : 
     981                 :     3109422 :   do
     982                 :             :     {
     983                 :     3109422 :       use = reload_combine_closest_single_use (regno, from_ruid);
     984                 :             : 
     985                 :     3109422 :       if (use)
     986                 :             :         /* Start the search for the next use from here.  */
     987                 :      855302 :         from_ruid = use->ruid;
     988                 :             : 
     989                 :      855302 :       if (use && GET_MODE (*use->usep) == Pmode)
     990                 :             :         {
     991                 :      850124 :           bool delete_add = false;
     992                 :      850124 :           rtx_insn *use_insn = use->insn;
     993                 :      850124 :           int use_ruid = use->ruid;
     994                 :             : 
     995                 :             :           /* Avoid moving the add insn past a jump.  */
     996                 :      850124 :           if (must_move_add && use_ruid <= last_jump_ruid)
     997                 :             :             break;
     998                 :             : 
     999                 :             :           /* If the add clobbers another hard reg in parallel, don't move
    1000                 :             :              it past a real set of this hard reg.  */
    1001                 :      849829 :           if (must_move_add && clobbered_regno >= 0
    1002                 :      100977 :               && reg_state[clobbered_regno].real_store_ruid >= use_ruid)
    1003                 :             :             break;
    1004                 :             : 
    1005                 :      831368 :           gcc_assert (reg_state[regno].store_ruid <= use_ruid);
    1006                 :             :           /* Avoid moving a use of ADDREG past a point where it is stored.  */
    1007                 :      831368 :           if (reg_state[REGNO (addreg)].store_ruid > use_ruid)
    1008                 :             :             break;
    1009                 :             : 
    1010                 :             :           /* We also must not move the addition past an insn that sets
    1011                 :             :              the same register, unless we can combine two add insns.  */
    1012                 :      754808 :           if (must_move_add && reg_state[regno].store_ruid == use_ruid)
    1013                 :             :             {
    1014                 :       25522 :               if (use->containing_mem == NULL_RTX)
    1015                 :             :                 delete_add = true;
    1016                 :             :               else
    1017                 :             :                 break;
    1018                 :             :             }
    1019                 :             : 
    1020                 :      754762 :           if (try_replace_in_use (use, reg, src))
    1021                 :             :             {
    1022                 :       24563 :               reload_combine_purge_insn_uses (use_insn);
    1023                 :       24563 :               reload_combine_note_use (&PATTERN (use_insn), use_insn,
    1024                 :             :                                        use_ruid, NULL_RTX);
    1025                 :             : 
    1026                 :       24563 :               if (delete_add)
    1027                 :             :                 {
    1028                 :         239 :                   fixup_debug_insns (reg, src, insn, use_insn);
    1029                 :         239 :                   delete_insn (insn);
    1030                 :         239 :                   return true;
    1031                 :             :                 }
    1032                 :       24324 :               if (must_move_add)
    1033                 :             :                 {
    1034                 :        1803 :                   add_moved_after_insn = use_insn;
    1035                 :        1803 :                   add_moved_after_ruid = use_ruid;
    1036                 :             :                 }
    1037                 :       24324 :               continue;
    1038                 :             :             }
    1039                 :             :         }
    1040                 :             :       /* If we get here, we couldn't handle this use.  */
    1041                 :     2989497 :       if (must_move_add)
    1042                 :             :         break;
    1043                 :             :     }
    1044                 :     2320210 :   while (use);
    1045                 :             : 
    1046                 :     2441773 :   if (!must_move_add || add_moved_after_insn == NULL_RTX)
    1047                 :             :     /* Process the add normally.  */
    1048                 :             :     return false;
    1049                 :             : 
    1050                 :         765 :   fixup_debug_insns (reg, src, insn, add_moved_after_insn);
    1051                 :             : 
    1052                 :         765 :   reorder_insns (insn, insn, add_moved_after_insn);
    1053                 :         765 :   reload_combine_purge_reg_uses_after_ruid (regno, add_moved_after_ruid);
    1054                 :         765 :   reload_combine_split_ruids (add_moved_after_ruid - 1);
    1055                 :         765 :   reload_combine_note_use (&PATTERN (insn), insn,
    1056                 :             :                            add_moved_after_ruid, NULL_RTX);
    1057                 :         765 :   reg_state[regno].store_ruid = add_moved_after_ruid;
    1058                 :             : 
    1059                 :         765 :   return true;
    1060                 :             : }
    1061                 :             : 
    1062                 :             : /* Called by reload_combine when scanning INSN.  Try to detect a pattern we
    1063                 :             :    can handle and improve.  Return true if no further processing is needed on
    1064                 :             :    INSN; false if it wasn't recognized and should be handled normally.  */
    1065                 :             : 
    1066                 :             : static bool
    1067                 :    55734381 : reload_combine_recognize_pattern (rtx_insn *insn)
    1068                 :             : {
    1069                 :    55734381 :   rtx set, reg, src;
    1070                 :             : 
    1071                 :    55734381 :   set = single_set (insn);
    1072                 :    55734381 :   if (set == NULL_RTX)
    1073                 :             :     return false;
    1074                 :             : 
    1075                 :    51781202 :   reg = SET_DEST (set);
    1076                 :    51781202 :   src = SET_SRC (set);
    1077                 :    51781202 :   if (!REG_P (reg) || REG_NREGS (reg) != 1)
    1078                 :             :     return false;
    1079                 :             : 
    1080                 :    34955259 :   unsigned int regno = REGNO (reg);
    1081                 :    34955259 :   machine_mode mode = GET_MODE (reg);
    1082                 :             : 
    1083                 :    34955259 :   if (reg_state[regno].use_index < 0
    1084                 :    34955259 :       || reg_state[regno].use_index >= RELOAD_COMBINE_MAX_USES)
    1085                 :             :     return false;
    1086                 :             : 
    1087                 :    22363879 :   for (int i = reg_state[regno].use_index;
    1088                 :    41011637 :        i < RELOAD_COMBINE_MAX_USES; i++)
    1089                 :             :     {
    1090                 :    23059201 :       struct reg_use *use = reg_state[regno].reg_use + i;
    1091                 :    23059201 :       if (GET_MODE (*use->usep) != mode)
    1092                 :             :         return false;
    1093                 :             :       /* Don't try to adjust (use (REGX)).  */
    1094                 :    22368190 :       if (GET_CODE (PATTERN (use->insn)) == USE
    1095                 :    22368190 :           && &XEXP (PATTERN (use->insn), 0) == use->usep)
    1096                 :             :         return false;
    1097                 :             :     }
    1098                 :             : 
    1099                 :             :   /* Look for (set (REGX) (CONST_INT))
    1100                 :             :      (set (REGX) (PLUS (REGX) (REGY)))
    1101                 :             :      ...
    1102                 :             :      ... (MEM (REGX)) ...
    1103                 :             :      and convert it to
    1104                 :             :      (set (REGZ) (CONST_INT))
    1105                 :             :      ...
    1106                 :             :      ... (MEM (PLUS (REGZ) (REGY)))... .
    1107                 :             : 
    1108                 :             :      First, check that we have (set (REGX) (PLUS (REGX) (REGY)))
    1109                 :             :      and that we know all uses of REGX before it dies.
    1110                 :             :      Also, explicitly check that REGX != REGY; our life information
    1111                 :             :      does not yet show whether REGY changes in this insn.  */
    1112                 :             : 
    1113                 :    17952436 :   if (GET_CODE (src) == PLUS
    1114                 :     2184826 :       && reg_state[regno].all_offsets_match
    1115                 :     1963277 :       && last_index_reg != -1
    1116                 :     1963277 :       && REG_P (XEXP (src, 1))
    1117                 :      650337 :       && rtx_equal_p (XEXP (src, 0), reg)
    1118                 :      474110 :       && !rtx_equal_p (XEXP (src, 1), reg)
    1119                 :    18419972 :       && last_label_ruid < reg_state[regno].use_ruid)
    1120                 :             :     {
    1121                 :      441446 :       rtx base = XEXP (src, 1);
    1122                 :      441446 :       rtx_insn *prev = prev_nonnote_nondebug_insn (insn);
    1123                 :      441446 :       rtx prev_set = prev ? single_set (prev) : NULL_RTX;
    1124                 :      441446 :       rtx index_reg = NULL_RTX;
    1125                 :      441446 :       rtx reg_sum = NULL_RTX;
    1126                 :      441446 :       int i;
    1127                 :             : 
    1128                 :             :       /* Now we need to set INDEX_REG to an index register (denoted as
    1129                 :             :          REGZ in the illustration above) and REG_SUM to the expression
    1130                 :             :          register+register that we want to use to substitute uses of REG
    1131                 :             :          (typically in MEMs) with.  First check REG and BASE for being
    1132                 :             :          index registers; we can use them even if they are not dead.  */
    1133                 :      441446 :       if (TEST_HARD_REG_BIT (reg_class_contents[INDEX_REG_CLASS], regno)
    1134                 :      441446 :           || TEST_HARD_REG_BIT (reg_class_contents[INDEX_REG_CLASS],
    1135                 :             :                                 REGNO (base)))
    1136                 :             :         {
    1137                 :             :           index_reg = reg;
    1138                 :             :           reg_sum = src;
    1139                 :             :         }
    1140                 :             :       else
    1141                 :             :         {
    1142                 :             :           /* Otherwise, look for a free index register.  Since we have
    1143                 :             :              checked above that neither REG nor BASE are index registers,
    1144                 :             :              if we find anything at all, it will be different from these
    1145                 :             :              two registers.  */
    1146                 :     7924133 :           for (i = first_index_reg; i <= last_index_reg; i++)
    1147                 :             :             {
    1148                 :     7844712 :               if (TEST_HARD_REG_BIT (reg_class_contents[INDEX_REG_CLASS], i)
    1149                 :     2743468 :                   && reg_state[i].use_index == RELOAD_COMBINE_MAX_USES
    1150                 :     1414979 :                   && reg_state[i].store_ruid <= reg_state[regno].use_ruid
    1151                 :     1399871 :                   && (crtl->abi->clobbers_full_reg_p (i)
    1152                 :      273034 :                       || df_regs_ever_live_p (i))
    1153                 :     1196936 :                   && (!frame_pointer_needed || i != HARD_FRAME_POINTER_REGNUM)
    1154                 :     1196012 :                   && !fixed_regs[i] && !global_regs[i]
    1155                 :      486732 :                   && hard_regno_nregs (i, GET_MODE (reg)) == 1
    1156                 :     7977620 :                   && targetm.hard_regno_scratch_ok (i))
    1157                 :             :                 {
    1158                 :      132908 :                   index_reg = gen_rtx_REG (GET_MODE (reg), i);
    1159                 :      132908 :                   reg_sum = gen_rtx_PLUS (GET_MODE (reg), index_reg, base);
    1160                 :      132908 :                   break;
    1161                 :             :                 }
    1162                 :             :             }
    1163                 :             :         }
    1164                 :             : 
    1165                 :             :       /* Check that PREV_SET is indeed (set (REGX) (CONST_INT)) and that
    1166                 :             :          (REGY), i.e. BASE, is not clobbered before the last use we'll
    1167                 :             :          create.  */
    1168                 :      441446 :       if (reg_sum
    1169                 :      441446 :           && prev_set
    1170                 :      355164 :           && CONST_INT_P (SET_SRC (prev_set))
    1171                 :        6528 :           && rtx_equal_p (SET_DEST (prev_set), reg)
    1172                 :      441446 :           && (reg_state[REGNO (base)].store_ruid
    1173                 :        1838 :               <= reg_state[regno].use_ruid))
    1174                 :             :         {
    1175                 :             :           /* Change destination register and, if necessary, the constant
    1176                 :             :              value in PREV, the constant loading instruction.  */
    1177                 :        1806 :           validate_change (prev, &SET_DEST (prev_set), index_reg, 1);
    1178                 :        1806 :           if (reg_state[regno].offset != const0_rtx)
    1179                 :             :             {
    1180                 :           0 :               HOST_WIDE_INT c
    1181                 :           0 :                 = trunc_int_for_mode (UINTVAL (SET_SRC (prev_set))
    1182                 :           0 :                                       + UINTVAL (reg_state[regno].offset),
    1183                 :           0 :                                       GET_MODE (index_reg));
    1184                 :           0 :               validate_change (prev, &SET_SRC (prev_set), GEN_INT (c), 1);
    1185                 :             :             }
    1186                 :             : 
    1187                 :             :           /* Now for every use of REG that we have recorded, replace REG
    1188                 :             :              with REG_SUM.  */
    1189                 :        3693 :           for (i = reg_state[regno].use_index;
    1190                 :        3693 :                i < RELOAD_COMBINE_MAX_USES; i++)
    1191                 :        1887 :             validate_unshare_change (reg_state[regno].reg_use[i].insn,
    1192                 :             :                                      reg_state[regno].reg_use[i].usep,
    1193                 :             :                                      /* Each change must have its own
    1194                 :             :                                         replacement.  */
    1195                 :             :                                      reg_sum, 1);
    1196                 :             : 
    1197                 :        1806 :           if (apply_change_group ())
    1198                 :             :             {
    1199                 :          56 :               struct reg_use *lowest_ruid = NULL;
    1200                 :             : 
    1201                 :             :               /* For every new use of REG_SUM, we have to record the use
    1202                 :             :                  of BASE therein, i.e. operand 1.  */
    1203                 :         135 :               for (i = reg_state[regno].use_index;
    1204                 :         135 :                    i < RELOAD_COMBINE_MAX_USES; i++)
    1205                 :             :                 {
    1206                 :          79 :                   struct reg_use *use = reg_state[regno].reg_use + i;
    1207                 :          79 :                   reload_combine_note_use (&XEXP (*use->usep, 1), use->insn,
    1208                 :             :                                            use->ruid, use->containing_mem);
    1209                 :          79 :                   if (lowest_ruid == NULL || use->ruid < lowest_ruid->ruid)
    1210                 :          79 :                     lowest_ruid = use;
    1211                 :             :                 }
    1212                 :             : 
    1213                 :          56 :               fixup_debug_insns (reg, reg_sum, insn, lowest_ruid->insn);
    1214                 :             : 
    1215                 :             :               /* Delete the reg-reg addition.  */
    1216                 :          56 :               delete_insn (insn);
    1217                 :             : 
    1218                 :          56 :               if (reg_state[regno].offset != const0_rtx)
    1219                 :             :                 /* Previous REG_EQUIV / REG_EQUAL notes for PREV
    1220                 :             :                    are now invalid.  */
    1221                 :           0 :                 remove_reg_equal_equiv_notes (prev);
    1222                 :             : 
    1223                 :          56 :               reg_state[regno].use_index = RELOAD_COMBINE_MAX_USES;
    1224                 :          56 :               return true;
    1225                 :             :             }
    1226                 :             :         }
    1227                 :             :     }
    1228                 :             :   return false;
    1229                 :             : }
    1230                 :             : 
    1231                 :             : static void
    1232                 :      995675 : reload_combine (void)
    1233                 :             : {
    1234                 :      995675 :   rtx_insn *insn, *prev;
    1235                 :      995675 :   basic_block bb;
    1236                 :      995675 :   unsigned int r;
    1237                 :      995675 :   int min_labelno, n_labels;
    1238                 :      995675 :   HARD_REG_SET ever_live_at_start, *label_live;
    1239                 :             : 
    1240                 :             :   /* To avoid wasting too much time later searching for an index register,
    1241                 :             :      determine the minimum and maximum index register numbers.  */
    1242                 :      995675 :   if (INDEX_REG_CLASS == NO_REGS)
    1243                 :             :     last_index_reg = -1;
    1244                 :      995675 :   else if (first_index_reg == -1 && last_index_reg == 0)
    1245                 :             :     {
    1246                 :    12687153 :       for (r = 0; r < FIRST_PSEUDO_REGISTER; r++)
    1247                 :    12550732 :         if (TEST_HARD_REG_BIT (reg_class_contents[INDEX_REG_CLASS], r))
    1248                 :             :           {
    1249                 :     4229051 :             if (first_index_reg == -1)
    1250                 :      136421 :               first_index_reg = r;
    1251                 :             : 
    1252                 :     4229051 :             last_index_reg = r;
    1253                 :             :           }
    1254                 :             : 
    1255                 :             :       /* If no index register is available, we can quit now.  Set LAST_INDEX_REG
    1256                 :             :          to -1 so we'll know to quit early the next time we get here.  */
    1257                 :      136421 :       if (first_index_reg == -1)
    1258                 :             :         {
    1259                 :           0 :           last_index_reg = -1;
    1260                 :           0 :           return;
    1261                 :             :         }
    1262                 :             :     }
    1263                 :             : 
    1264                 :             :   /* Set up LABEL_LIVE and EVER_LIVE_AT_START.  The register lifetime
    1265                 :             :      information is a bit fuzzy immediately after reload, but it's
    1266                 :             :      still good enough to determine which registers are live at a jump
    1267                 :             :      destination.  */
    1268                 :      995675 :   min_labelno = get_first_label_num ();
    1269                 :      995675 :   n_labels = max_label_num () - min_labelno;
    1270                 :      995675 :   label_live = XNEWVEC (HARD_REG_SET, n_labels);
    1271                 :      995675 :   CLEAR_HARD_REG_SET (ever_live_at_start);
    1272                 :             : 
    1273                 :    11401947 :   FOR_EACH_BB_REVERSE_FN (bb, cfun)
    1274                 :             :     {
    1275                 :    10406272 :       insn = BB_HEAD (bb);
    1276                 :    10406272 :       if (LABEL_P (insn))
    1277                 :             :         {
    1278                 :     4815223 :           HARD_REG_SET live;
    1279                 :     4815223 :           bitmap live_in = df_get_live_in (bb);
    1280                 :             : 
    1281                 :     9630446 :           REG_SET_TO_HARD_REG_SET (live, live_in);
    1282                 :     4815223 :           compute_use_by_pseudos (&live, live_in);
    1283                 :     4815223 :           LABEL_LIVE (insn) = live;
    1284                 :     9630446 :           ever_live_at_start |= live;
    1285                 :             :         }
    1286                 :             :     }
    1287                 :             : 
    1288                 :             :   /* Initialize last_label_ruid, reload_combine_ruid and reg_state.  */
    1289                 :      995675 :   last_label_ruid = last_jump_ruid = reload_combine_ruid = 0;
    1290                 :    92597775 :   for (r = 0; r < FIRST_PSEUDO_REGISTER; r++)
    1291                 :             :     {
    1292                 :    91602100 :       reg_state[r].store_ruid = 0;
    1293                 :    91602100 :       reg_state[r].real_store_ruid = 0;
    1294                 :    91602100 :       if (fixed_regs[r])
    1295                 :    45575408 :         reg_state[r].use_index = -1;
    1296                 :             :       else
    1297                 :    46026692 :         reg_state[r].use_index = RELOAD_COMBINE_MAX_USES;
    1298                 :             :     }
    1299                 :             : 
    1300                 :   123544147 :   for (insn = get_last_insn (); insn; insn = prev)
    1301                 :             :     {
    1302                 :   122548472 :       bool control_flow_insn;
    1303                 :   122548472 :       rtx note;
    1304                 :             : 
    1305                 :   122548472 :       prev = PREV_INSN (insn);
    1306                 :             : 
    1307                 :             :       /* We cannot do our optimization across labels.  Invalidating all the use
    1308                 :             :          information we have would be costly, so we just note where the label
    1309                 :             :          is and then later disable any optimization that would cross it.  */
    1310                 :   122548472 :       if (LABEL_P (insn))
    1311                 :     4821643 :         last_label_ruid = reload_combine_ruid;
    1312                 :   117726829 :       else if (BARRIER_P (insn))
    1313                 :             :         {
    1314                 :             :           /* Crossing a barrier resets all the use information.  */
    1315                 :   263744094 :           for (r = 0; r < FIRST_PSEUDO_REGISTER; r++)
    1316                 :   260908136 :             if (! fixed_regs[r])
    1317                 :   126471394 :               reg_state[r].use_index = RELOAD_COMBINE_MAX_USES;
    1318                 :             :         }
    1319                 :   114890871 :       else if (INSN_P (insn) && volatile_insn_p (PATTERN (insn)))
    1320                 :             :         /* Optimizations across insns being marked as volatile must be
    1321                 :             :            prevented.  All the usage information is invalidated
    1322                 :             :            here.  */
    1323                 :    42543222 :         for (r = 0; r < FIRST_PSEUDO_REGISTER; r++)
    1324                 :    42085768 :           if (! fixed_regs[r]
    1325                 :    19899676 :               && reg_state[r].use_index != RELOAD_COMBINE_MAX_USES)
    1326                 :      693837 :             reg_state[r].use_index = -1;
    1327                 :             : 
    1328                 :   122548472 :       if (! NONDEBUG_INSN_P (insn))
    1329                 :    66813087 :         continue;
    1330                 :             : 
    1331                 :    55735385 :       reload_combine_ruid++;
    1332                 :             : 
    1333                 :    55735385 :       control_flow_insn = control_flow_insn_p (insn);
    1334                 :    55735385 :       if (control_flow_insn)
    1335                 :     7973604 :         last_jump_ruid = reload_combine_ruid;
    1336                 :             : 
    1337                 :    55735385 :       if (reload_combine_recognize_const_pattern (insn)
    1338                 :    55735385 :           || reload_combine_recognize_pattern (insn))
    1339                 :        1060 :         continue;
    1340                 :             : 
    1341                 :    55734325 :       note_stores (insn, reload_combine_note_store, NULL);
    1342                 :             : 
    1343                 :    55734325 :       if (CALL_P (insn))
    1344                 :             :         {
    1345                 :     4615762 :           rtx link;
    1346                 :     4615762 :           HARD_REG_SET used_regs = insn_callee_abi (insn).full_reg_clobbers ();
    1347                 :             : 
    1348                 :   429265866 :           for (r = 0; r < FIRST_PSEUDO_REGISTER; r++)
    1349                 :   424650104 :             if (TEST_HARD_REG_BIT (used_regs, r))
    1350                 :             :               {
    1351                 :   376419796 :                 reg_state[r].use_index = RELOAD_COMBINE_MAX_USES;
    1352                 :   376419796 :                 reg_state[r].store_ruid = reload_combine_ruid;
    1353                 :             :               }
    1354                 :             : 
    1355                 :    13444508 :           for (link = CALL_INSN_FUNCTION_USAGE (insn); link;
    1356                 :     8828746 :                link = XEXP (link, 1))
    1357                 :             :             {
    1358                 :     8828746 :               rtx setuse = XEXP (link, 0);
    1359                 :     8828746 :               rtx usage_rtx = XEXP (setuse, 0);
    1360                 :             : 
    1361                 :     8828746 :               if (GET_CODE (setuse) == USE && REG_P (usage_rtx))
    1362                 :             :                 {
    1363                 :     8302632 :                   unsigned int end_regno = END_REGNO (usage_rtx);
    1364                 :    16654237 :                   for (unsigned int i = REGNO (usage_rtx); i < end_regno; ++i)
    1365                 :     8351605 :                     reg_state[i].use_index = -1;
    1366                 :             :                  }
    1367                 :             :              }
    1368                 :             :         }
    1369                 :             : 
    1370                 :    55734325 :       if (control_flow_insn && !ANY_RETURN_P (PATTERN (insn)))
    1371                 :             :         {
    1372                 :             :           /* Non-spill registers might be used at the call destination in
    1373                 :             :              some unknown fashion, so we have to mark the unknown use.  */
    1374                 :     7973604 :           HARD_REG_SET *live;
    1375                 :             : 
    1376                 :     9302250 :           if ((condjump_p (insn) || condjump_in_parallel_p (insn))
    1377                 :     7973616 :               && JUMP_LABEL (insn))
    1378                 :             :             {
    1379                 :     6644970 :               if (ANY_RETURN_P (JUMP_LABEL (insn)))
    1380                 :             :                 live = NULL;
    1381                 :             :               else
    1382                 :     6644970 :                 live = &LABEL_LIVE (JUMP_LABEL (insn));
    1383                 :             :             }
    1384                 :             :           else
    1385                 :             :             live = &ever_live_at_start;
    1386                 :             : 
    1387                 :     7973604 :           if (live)
    1388                 :   741545172 :             for (r = 0; r < FIRST_PSEUDO_REGISTER; r++)
    1389                 :   733571568 :               if (TEST_HARD_REG_BIT (*live, r))
    1390                 :    39751336 :                 reg_state[r].use_index = -1;
    1391                 :             :         }
    1392                 :             : 
    1393                 :    55734325 :       reload_combine_note_use (&PATTERN (insn), insn, reload_combine_ruid,
    1394                 :             :                                NULL_RTX);
    1395                 :             : 
    1396                 :    78565089 :       for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
    1397                 :             :         {
    1398                 :    22830764 :           if (REG_NOTE_KIND (note) == REG_INC && REG_P (XEXP (note, 0)))
    1399                 :             :             {
    1400                 :           0 :               int regno = REGNO (XEXP (note, 0));
    1401                 :           0 :               reg_state[regno].store_ruid = reload_combine_ruid;
    1402                 :           0 :               reg_state[regno].real_store_ruid = reload_combine_ruid;
    1403                 :           0 :               reg_state[regno].use_index = -1;
    1404                 :             :             }
    1405                 :             :         }
    1406                 :             :     }
    1407                 :             : 
    1408                 :      995675 :   free (label_live);
    1409                 :             : }
    1410                 :             : 
    1411                 :             : /* Check if DST is a register or a subreg of a register; if it is,
    1412                 :             :    update store_ruid, real_store_ruid and use_index in the reg_state
    1413                 :             :    structure accordingly.  Called via note_stores from reload_combine.  */
    1414                 :             : 
    1415                 :             : static void
    1416                 :    60105315 : reload_combine_note_store (rtx dst, const_rtx set, void *data ATTRIBUTE_UNUSED)
    1417                 :             : {
    1418                 :    60105315 :   int regno = 0;
    1419                 :    60105315 :   int i;
    1420                 :    60105315 :   machine_mode mode = GET_MODE (dst);
    1421                 :             : 
    1422                 :    60105315 :   if (GET_CODE (dst) == SUBREG)
    1423                 :             :     {
    1424                 :        6544 :       regno = subreg_regno_offset (REGNO (SUBREG_REG (dst)),
    1425                 :        3272 :                                    GET_MODE (SUBREG_REG (dst)),
    1426                 :        3272 :                                    SUBREG_BYTE (dst),
    1427                 :             :                                    GET_MODE (dst));
    1428                 :        3272 :       dst = SUBREG_REG (dst);
    1429                 :             :     }
    1430                 :             : 
    1431                 :             :   /* Some targets do argument pushes without adding REG_INC notes.  */
    1432                 :             : 
    1433                 :    60105315 :   if (MEM_P (dst))
    1434                 :             :     {
    1435                 :     9712679 :       dst = XEXP (dst, 0);
    1436                 :     9712679 :       if (GET_CODE (dst) == PRE_INC || GET_CODE (dst) == POST_INC
    1437                 :     9712679 :           || GET_CODE (dst) == PRE_DEC || GET_CODE (dst) == POST_DEC
    1438                 :     8098808 :           || GET_CODE (dst) == PRE_MODIFY || GET_CODE (dst) == POST_MODIFY)
    1439                 :             :         {
    1440                 :     1700127 :           unsigned int end_regno = END_REGNO (XEXP (dst, 0));
    1441                 :     3400254 :           for (unsigned int i = REGNO (XEXP (dst, 0)); i < end_regno; ++i)
    1442                 :             :             {
    1443                 :             :               /* We could probably do better, but for now mark the register
    1444                 :             :                  as used in an unknown fashion and set/clobbered at this
    1445                 :             :                  insn.  */
    1446                 :     1700127 :               reg_state[i].use_index = -1;
    1447                 :     1700127 :               reg_state[i].store_ruid = reload_combine_ruid;
    1448                 :     1700127 :               reg_state[i].real_store_ruid = reload_combine_ruid;
    1449                 :             :             }
    1450                 :             :         }
    1451                 :             :       else
    1452                 :             :         return;
    1453                 :             :     }
    1454                 :             : 
    1455                 :    52092763 :   if (!REG_P (dst))
    1456                 :             :     return;
    1457                 :    43735682 :   regno += REGNO (dst);
    1458                 :             : 
    1459                 :             :   /* note_stores might have stripped a STRICT_LOW_PART, so we have to be
    1460                 :             :      careful with registers / register parts that are not full words.
    1461                 :             :      Similarly for ZERO_EXTRACT.  */
    1462                 :    43735682 :   if (GET_CODE (SET_DEST (set)) == ZERO_EXTRACT
    1463                 :    43734283 :       || GET_CODE (SET_DEST (set)) == STRICT_LOW_PART)
    1464                 :             :     {
    1465                 :       10028 :       for (i = end_hard_regno (mode, regno) - 1; i >= regno; i--)
    1466                 :             :         {
    1467                 :        5014 :           reg_state[i].use_index = -1;
    1468                 :        5014 :           reg_state[i].store_ruid = reload_combine_ruid;
    1469                 :        5014 :           reg_state[i].real_store_ruid = reload_combine_ruid;
    1470                 :             :         }
    1471                 :             :     }
    1472                 :             :   else
    1473                 :             :     {
    1474                 :    88048175 :       for (i = end_hard_regno (mode, regno) - 1; i >= regno; i--)
    1475                 :             :         {
    1476                 :    44317507 :           reg_state[i].store_ruid = reload_combine_ruid;
    1477                 :    44317507 :           if (GET_CODE (set) == SET)
    1478                 :    36916155 :             reg_state[i].real_store_ruid = reload_combine_ruid;
    1479                 :    44317507 :           reg_state[i].use_index = RELOAD_COMBINE_MAX_USES;
    1480                 :             :         }
    1481                 :             :     }
    1482                 :             : }
    1483                 :             : 
    1484                 :             : /* XP points to a piece of rtl that has to be checked for any uses of
    1485                 :             :    registers.
    1486                 :             :    *XP is the pattern of INSN, or a part of it.
    1487                 :             :    Called from reload_combine, and recursively by itself.  */
    1488                 :             : static void
    1489                 :   196215958 : reload_combine_note_use (rtx *xp, rtx_insn *insn, int ruid, rtx containing_mem)
    1490                 :             : {
    1491                 :   232544307 :   rtx x = *xp;
    1492                 :   232544307 :   enum rtx_code code = x->code;
    1493                 :   232544307 :   const char *fmt;
    1494                 :   232544307 :   int i, j;
    1495                 :   232544307 :   rtx offset = const0_rtx; /* For the REG case below.  */
    1496                 :             : 
    1497                 :   232544307 :   switch (code)
    1498                 :             :     {
    1499                 :    52670733 :     case SET:
    1500                 :    52670733 :       if (REG_P (SET_DEST (x)))
    1501                 :             :         {
    1502                 :    36328349 :           reload_combine_note_use (&SET_SRC (x), insn, ruid, NULL_RTX);
    1503                 :    36328349 :           return;
    1504                 :             :         }
    1505                 :             :       break;
    1506                 :             : 
    1507                 :      641270 :     case USE:
    1508                 :             :       /* If this is the USE of a return value, we can't change it.  */
    1509                 :      641270 :       if (REG_P (XEXP (x, 0)) && REG_FUNCTION_VALUE_P (XEXP (x, 0)))
    1510                 :             :         {
    1511                 :             :           /* Mark the return register as used in an unknown fashion.  */
    1512                 :      535025 :           rtx reg = XEXP (x, 0);
    1513                 :      535025 :           unsigned int end_regno = END_REGNO (reg);
    1514                 :     1098000 :           for (unsigned int regno = REGNO (reg); regno < end_regno; ++regno)
    1515                 :      562975 :             reg_state[regno].use_index = -1;
    1516                 :             :           return;
    1517                 :             :         }
    1518                 :             :       break;
    1519                 :             : 
    1520                 :     7033106 :     case CLOBBER:
    1521                 :     7033106 :       if (REG_P (SET_DEST (x)))
    1522                 :             :         {
    1523                 :             :           /* No spurious CLOBBERs of pseudo registers may remain.  */
    1524                 :     6978717 :           gcc_assert (REGNO (SET_DEST (x)) < FIRST_PSEUDO_REGISTER);
    1525                 :             :           return;
    1526                 :             :         }
    1527                 :             :       break;
    1528                 :             : 
    1529                 :    20532401 :     case PLUS:
    1530                 :             :       /* We are interested in (plus (reg) (const_int)) .  */
    1531                 :    20532401 :       if (!REG_P (XEXP (x, 0))
    1532                 :    18565032 :           || !CONST_INT_P (XEXP (x, 1)))
    1533                 :             :         break;
    1534                 :             :       offset = XEXP (x, 1);
    1535                 :             :       x = XEXP (x, 0);
    1536                 :             :       /* Fall through.  */
    1537                 :    53882253 :     case REG:
    1538                 :    53882253 :       {
    1539                 :    53882253 :         int regno = REGNO (x);
    1540                 :    53882253 :         int use_index;
    1541                 :    53882253 :         int nregs;
    1542                 :             : 
    1543                 :             :         /* No spurious USEs of pseudo registers may remain.  */
    1544                 :    53882253 :         gcc_assert (regno < FIRST_PSEUDO_REGISTER);
    1545                 :             : 
    1546                 :    53882253 :         nregs = REG_NREGS (x);
    1547                 :             : 
    1548                 :             :         /* We can't substitute into multi-hard-reg uses.  */
    1549                 :    53882253 :         if (nregs > 1)
    1550                 :             :           {
    1551                 :     1151979 :             while (--nregs >= 0)
    1552                 :      768070 :               reg_state[regno + nregs].use_index = -1;
    1553                 :             :             return;
    1554                 :             :           }
    1555                 :             : 
    1556                 :             :         /* We may be called to update uses in previously seen insns.
    1557                 :             :            Don't add uses beyond the last store we saw.  */
    1558                 :    53498344 :         if (ruid < reg_state[regno].store_ruid)
    1559                 :             :           return;
    1560                 :             : 
    1561                 :             :         /* If this register is already used in some unknown fashion, we
    1562                 :             :            can't do anything.
    1563                 :             :            If we decrement the index from zero to -1, we can't store more
    1564                 :             :            uses, so this register becomes used in an unknown fashion.  */
    1565                 :    53489475 :         use_index = --reg_state[regno].use_index;
    1566                 :    53489475 :         if (use_index < 0)
    1567                 :             :           return;
    1568                 :             : 
    1569                 :    32589609 :         if (use_index == RELOAD_COMBINE_MAX_USES - 1)
    1570                 :             :           {
    1571                 :             :             /* This is the first use of this register we have seen since we
    1572                 :             :                marked it as dead.  */
    1573                 :    24808730 :             reg_state[regno].offset = offset;
    1574                 :    24808730 :             reg_state[regno].all_offsets_match = true;
    1575                 :    24808730 :             reg_state[regno].use_ruid = ruid;
    1576                 :             :           }
    1577                 :             :         else
    1578                 :             :           {
    1579                 :     7780879 :             if (reg_state[regno].use_ruid > ruid)
    1580                 :        2544 :               reg_state[regno].use_ruid = ruid;
    1581                 :             : 
    1582                 :     7780879 :             if (! rtx_equal_p (offset, reg_state[regno].offset))
    1583                 :     3613783 :               reg_state[regno].all_offsets_match = false;
    1584                 :             :           }
    1585                 :             : 
    1586                 :    32589609 :         reg_state[regno].reg_use[use_index].insn = insn;
    1587                 :    32589609 :         reg_state[regno].reg_use[use_index].ruid = ruid;
    1588                 :    32589609 :         reg_state[regno].reg_use[use_index].containing_mem = containing_mem;
    1589                 :    32589609 :         reg_state[regno].reg_use[use_index].usep = xp;
    1590                 :    32589609 :         return;
    1591                 :             :       }
    1592                 :             : 
    1593                 :             :     case MEM:
    1594                 :   134819963 :       containing_mem = x;
    1595                 :             :       break;
    1596                 :             : 
    1597                 :             :     default:
    1598                 :             :       break;
    1599                 :             :     }
    1600                 :             : 
    1601                 :             :   /* Recursively process the components of X.  */
    1602                 :   134819963 :   fmt = GET_RTX_FORMAT (code);
    1603                 :   344768312 :   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    1604                 :             :     {
    1605                 :   209948349 :       if (fmt[i] == 'e')
    1606                 :   121936870 :         reload_combine_note_use (&XEXP (x, i), insn, ruid, containing_mem);
    1607                 :    88011479 :       else if (fmt[i] == 'E')
    1608                 :             :         {
    1609                 :    27749835 :           for (j = XVECLEN (x, i) - 1; j >= 0; j--)
    1610                 :    18519356 :             reload_combine_note_use (&XVECEXP (x, i, j), insn, ruid,
    1611                 :             :                                      containing_mem);
    1612                 :             :         }
    1613                 :             :     }
    1614                 :             : }
    1615                 :             : 
    1616                 :             : /* See if we can reduce the cost of a constant by replacing a move
    1617                 :             :    with an add.  We track situations in which a register is set to a
    1618                 :             :    constant or to a register plus a constant.  */
    1619                 :             : /* We cannot do our optimization across labels.  Invalidating all the
    1620                 :             :    information about register contents we have would be costly, so we
    1621                 :             :    use move2add_last_label_luid to note where the label is and then
    1622                 :             :    later disable any optimization that would cross it.
    1623                 :             :    reg_offset[n] / reg_base_reg[n] / reg_symbol_ref[n] / reg_mode[n]
    1624                 :             :    are only valid if reg_set_luid[n] is greater than
    1625                 :             :    move2add_last_label_luid.
    1626                 :             :    For a set that established a new (potential) base register with
    1627                 :             :    non-constant value, we use move2add_luid from the place where the
    1628                 :             :    setting insn is encountered; registers based off that base then
    1629                 :             :    get the same reg_set_luid.  Constants all get
    1630                 :             :    move2add_last_label_luid + 1 as their reg_set_luid.  */
    1631                 :             : static int reg_set_luid[FIRST_PSEUDO_REGISTER];
    1632                 :             : 
    1633                 :             : /* If reg_base_reg[n] is negative, register n has been set to
    1634                 :             :    reg_offset[n] or reg_symbol_ref[n] + reg_offset[n] in mode reg_mode[n].
    1635                 :             :    If reg_base_reg[n] is non-negative, register n has been set to the
    1636                 :             :    sum of reg_offset[n] and the value of register reg_base_reg[n]
    1637                 :             :    before reg_set_luid[n], calculated in mode reg_mode[n] .
    1638                 :             :    For multi-hard-register registers, all but the first one are
    1639                 :             :    recorded as BLKmode in reg_mode.  Setting reg_mode to VOIDmode
    1640                 :             :    marks it as invalid.  */
    1641                 :             : static HOST_WIDE_INT reg_offset[FIRST_PSEUDO_REGISTER];
    1642                 :             : static int reg_base_reg[FIRST_PSEUDO_REGISTER];
    1643                 :             : static rtx reg_symbol_ref[FIRST_PSEUDO_REGISTER];
    1644                 :             : static machine_mode reg_mode[FIRST_PSEUDO_REGISTER];
    1645                 :             : 
    1646                 :             : /* move2add_luid is linearly increased while scanning the instructions
    1647                 :             :    from first to last.  It is used to set reg_set_luid in
    1648                 :             :    reload_cse_move2add and move2add_note_store.  */
    1649                 :             : static int move2add_luid;
    1650                 :             : 
    1651                 :             : /* move2add_last_label_luid is set whenever a label is found.  Labels
    1652                 :             :    invalidate all previously collected reg_offset data.  */
    1653                 :             : static int move2add_last_label_luid;
    1654                 :             : 
    1655                 :             : /* ??? We don't know how zero / sign extension is handled, hence we
    1656                 :             :    can't go from a narrower to a wider mode.  */
    1657                 :             : #define MODES_OK_FOR_MOVE2ADD(OUTMODE, INMODE) \
    1658                 :             :   (GET_MODE_SIZE (OUTMODE) == GET_MODE_SIZE (INMODE) \
    1659                 :             :    || (GET_MODE_SIZE (OUTMODE) <= GET_MODE_SIZE (INMODE) \
    1660                 :             :        && TRULY_NOOP_TRUNCATION_MODES_P (OUTMODE, INMODE)))
    1661                 :             : 
    1662                 :             : /* Record that REG is being set to a value with the mode of REG.  */
    1663                 :             : 
    1664                 :             : static void
    1665                 :    49010390 : move2add_record_mode (rtx reg)
    1666                 :             : {
    1667                 :    49010390 :   int regno, nregs;
    1668                 :    49010390 :   machine_mode mode = GET_MODE (reg);
    1669                 :             : 
    1670                 :    49010390 :   if (GET_CODE (reg) == SUBREG)
    1671                 :             :     {
    1672                 :        3255 :       regno = subreg_regno (reg);
    1673                 :        3255 :       nregs = subreg_nregs (reg);
    1674                 :             :     }
    1675                 :    49007135 :   else if (REG_P (reg))
    1676                 :             :     {
    1677                 :    49007135 :       regno = REGNO (reg);
    1678                 :    49007135 :       nregs = REG_NREGS (reg);
    1679                 :             :     }
    1680                 :             :   else
    1681                 :           0 :     gcc_unreachable ();
    1682                 :    49641331 :   for (int i = nregs - 1; i > 0; i--)
    1683                 :      630941 :     reg_mode[regno + i] = BLKmode;
    1684                 :    49010390 :   reg_mode[regno] = mode;
    1685                 :    49010390 : }
    1686                 :             : 
    1687                 :             : /* Record that REG is being set to the sum of SYM and OFF.  */
    1688                 :             : 
    1689                 :             : static void
    1690                 :     1982516 : move2add_record_sym_value (rtx reg, rtx sym, rtx off)
    1691                 :             : {
    1692                 :     1982516 :   int regno = REGNO (reg);
    1693                 :             : 
    1694                 :     1982516 :   move2add_record_mode (reg);
    1695                 :     1982516 :   reg_set_luid[regno] = move2add_luid;
    1696                 :     1982516 :   reg_base_reg[regno] = -1;
    1697                 :     1982516 :   reg_symbol_ref[regno] = sym;
    1698                 :     1982516 :   reg_offset[regno] = INTVAL (off);
    1699                 :     1982516 : }
    1700                 :             : 
    1701                 :             : /* Check if REGNO contains a valid value in MODE.  */
    1702                 :             : 
    1703                 :             : static bool
    1704                 :   198470634 : move2add_valid_value_p (int regno, scalar_int_mode mode)
    1705                 :             : {
    1706                 :   198470634 :   if (reg_set_luid[regno] <= move2add_last_label_luid)
    1707                 :             :     return false;
    1708                 :             : 
    1709                 :    20102617 :   if (mode != reg_mode[regno])
    1710                 :             :     {
    1711                 :    10595199 :       scalar_int_mode old_mode;
    1712                 :    10595199 :       if (!is_a <scalar_int_mode> (reg_mode[regno], &old_mode)
    1713                 :     6650964 :           || !MODES_OK_FOR_MOVE2ADD (mode, old_mode)
    1714                 :    11091101 :           || !REG_CAN_CHANGE_MODE_P (regno, old_mode, mode))
    1715                 :    10099297 :         return false;
    1716                 :             :       /* The value loaded into regno in reg_mode[regno] is also valid in
    1717                 :             :          mode after truncation only if (REG:mode regno) is the lowpart of
    1718                 :             :          (REG:reg_mode[regno] regno).  Now, for big endian, the starting
    1719                 :             :          regno of the lowpart might be different.  */
    1720                 :      495902 :       poly_int64 s_off = subreg_lowpart_offset (mode, old_mode);
    1721                 :      495902 :       s_off = subreg_regno_offset (regno, old_mode, s_off, mode);
    1722                 :      495902 :       if (maybe_ne (s_off, 0))
    1723                 :             :         /* We could in principle adjust regno, check reg_mode[regno] to be
    1724                 :             :            BLKmode, and return s_off to the caller (vs. -1 for failure),
    1725                 :             :            but we currently have no callers that could make use of this
    1726                 :             :            information.  */
    1727                 :             :         return false;
    1728                 :             :     }
    1729                 :             : 
    1730                 :    10048044 :   for (int i = end_hard_regno (mode, regno) - 1; i > regno; i--)
    1731                 :       50571 :     if (reg_mode[i] != BLKmode)
    1732                 :             :       return false;
    1733                 :             :   return true;
    1734                 :             : }
    1735                 :             : 
    1736                 :             : /* This function is called with INSN that sets REG (of mode MODE)
    1737                 :             :    to (SYM + OFF), while REG is known to already have value (SYM + offset).
    1738                 :             :    This function tries to change INSN into an add instruction
    1739                 :             :    (set (REG) (plus (REG) (OFF - offset))) using the known value.
    1740                 :             :    It also updates the information about REG's known value.
    1741                 :             :    Return true if we made a change.  */
    1742                 :             : 
    1743                 :             : static bool
    1744                 :      139494 : move2add_use_add2_insn (scalar_int_mode mode, rtx reg, rtx sym, rtx off,
    1745                 :             :                         rtx_insn *insn)
    1746                 :             : {
    1747                 :      139494 :   rtx set = single_set (insn);
    1748                 :      139494 :   rtx src = SET_SRC (set);
    1749                 :      139494 :   int regno = REGNO (reg);
    1750                 :      139494 :   rtx new_src = gen_int_mode (UINTVAL (off) - reg_offset[regno], mode);
    1751                 :      139494 :   bool speed = optimize_bb_for_speed_p (BLOCK_FOR_INSN (insn));
    1752                 :      139494 :   bool changed = false;
    1753                 :             : 
    1754                 :             :   /* (set (reg) (plus (reg) (const_int 0))) is not canonical;
    1755                 :             :      use (set (reg) (reg)) instead.
    1756                 :             :      We don't delete this insn, nor do we convert it into a
    1757                 :             :      note, to avoid losing register notes or the return
    1758                 :             :      value flag.  jump2 already knows how to get rid of
    1759                 :             :      no-op moves.  */
    1760                 :      139494 :   if (new_src == const0_rtx)
    1761                 :             :     {
    1762                 :             :       /* If the constants are different, this is a
    1763                 :             :          truncation, that, if turned into (set (reg)
    1764                 :             :          (reg)), would be discarded.  Maybe we should
    1765                 :             :          try a truncMN pattern?  */
    1766                 :       16209 :       if (INTVAL (off) == reg_offset [regno])
    1767                 :       14874 :         changed = validate_change (insn, &SET_SRC (set), reg, 0);
    1768                 :             :     }
    1769                 :             :   else
    1770                 :             :     {
    1771                 :      123285 :       struct full_rtx_costs oldcst, newcst;
    1772                 :      123285 :       rtx tem = gen_rtx_PLUS (mode, reg, new_src);
    1773                 :             : 
    1774                 :      123285 :       get_full_set_rtx_cost (set, &oldcst);
    1775                 :      123285 :       SET_SRC (set) = tem;
    1776                 :      123285 :       get_full_set_rtx_cost (set, &newcst);
    1777                 :      123285 :       SET_SRC (set) = src;
    1778                 :             : 
    1779                 :      123285 :       if (costs_lt_p (&newcst, &oldcst, speed)
    1780                 :      123285 :           && have_add2_insn (reg, new_src))
    1781                 :        2453 :         changed = validate_change (insn, &SET_SRC (set), tem, 0);
    1782                 :      120832 :       else if (sym == NULL_RTX && mode != BImode)
    1783                 :             :         {
    1784                 :      119368 :           scalar_int_mode narrow_mode;
    1785                 :      396848 :           FOR_EACH_MODE_UNTIL (narrow_mode, mode)
    1786                 :             :             {
    1787                 :      277480 :               if (have_insn_for (STRICT_LOW_PART, narrow_mode)
    1788                 :      277480 :                   && ((reg_offset[regno] & ~GET_MODE_MASK (narrow_mode))
    1789                 :      210410 :                       == (INTVAL (off) & ~GET_MODE_MASK (narrow_mode))))
    1790                 :             :                 {
    1791                 :      104992 :                   rtx narrow_reg = gen_lowpart_common (narrow_mode, reg);
    1792                 :      104992 :                   rtx narrow_src = gen_int_mode (INTVAL (off),
    1793                 :             :                                                  narrow_mode);
    1794                 :      104992 :                   rtx new_set
    1795                 :      104992 :                     = gen_rtx_SET (gen_rtx_STRICT_LOW_PART (VOIDmode,
    1796                 :             :                                                             narrow_reg),
    1797                 :             :                                    narrow_src);
    1798                 :      104992 :                   get_full_set_rtx_cost (new_set, &newcst);
    1799                 :             : 
    1800                 :             :                   /* We perform this replacement only if NEXT is either a
    1801                 :             :                      naked SET, or else its single_set is the first element
    1802                 :             :                      in a PARALLEL.  */
    1803                 :      104992 :                   rtx *setloc = GET_CODE (PATTERN (insn)) == PARALLEL
    1804                 :      104992 :                     ? &XVECEXP (PATTERN (insn), 0, 0) : &PATTERN (insn);
    1805                 :      104992 :                   if (*setloc == set && costs_lt_p (&newcst, &oldcst, speed))
    1806                 :             :                     {
    1807                 :           0 :                       changed = validate_change (insn, setloc, new_set, 0);
    1808                 :           0 :                       if (changed)
    1809                 :             :                         break;
    1810                 :             :                     }
    1811                 :             :                 }
    1812                 :             :             }
    1813                 :             :         }
    1814                 :             :     }
    1815                 :      139494 :   move2add_record_sym_value (reg, sym, off);
    1816                 :      139494 :   return changed;
    1817                 :             : }
    1818                 :             : 
    1819                 :             : 
    1820                 :             : /* This function is called with INSN that sets REG (of mode MODE) to
    1821                 :             :    (SYM + OFF), but REG doesn't have known value (SYM + offset).  This
    1822                 :             :    function tries to find another register which is known to already have
    1823                 :             :    value (SYM + offset) and change INSN into an add instruction
    1824                 :             :    (set (REG) (plus (the found register) (OFF - offset))) if such
    1825                 :             :    a register is found.  It also updates the information about
    1826                 :             :    REG's known value.
    1827                 :             :    Return true iff we made a change.  */
    1828                 :             : 
    1829                 :             : static bool
    1830                 :     1757234 : move2add_use_add3_insn (scalar_int_mode mode, rtx reg, rtx sym, rtx off,
    1831                 :             :                         rtx_insn *insn)
    1832                 :             : {
    1833                 :     1757234 :   rtx set = single_set (insn);
    1834                 :     1757234 :   rtx src = SET_SRC (set);
    1835                 :     1757234 :   int regno = REGNO (reg);
    1836                 :     1757234 :   int min_regno = 0;
    1837                 :     1757234 :   bool speed = optimize_bb_for_speed_p (BLOCK_FOR_INSN (insn));
    1838                 :     1757234 :   int i;
    1839                 :     1757234 :   bool changed = false;
    1840                 :     1757234 :   struct full_rtx_costs oldcst, newcst, mincst;
    1841                 :     1757234 :   rtx plus_expr;
    1842                 :             : 
    1843                 :     1757234 :   init_costs_to_max (&mincst);
    1844                 :     1757234 :   get_full_set_rtx_cost (set, &oldcst);
    1845                 :             : 
    1846                 :     1757234 :   plus_expr = gen_rtx_PLUS (GET_MODE (reg), reg, const0_rtx);
    1847                 :     1757234 :   SET_SRC (set) = plus_expr;
    1848                 :             : 
    1849                 :   163422762 :   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
    1850                 :   161665528 :     if (move2add_valid_value_p (i, mode)
    1851                 :     3531038 :         && reg_base_reg[i] < 0
    1852                 :     1366302 :         && reg_symbol_ref[i] != NULL_RTX
    1853                 :   162506699 :         && rtx_equal_p (sym, reg_symbol_ref[i]))
    1854                 :             :       {
    1855                 :       42770 :         rtx new_src = gen_int_mode (UINTVAL (off) - reg_offset[i],
    1856                 :       21385 :                                     GET_MODE (reg));
    1857                 :             :         /* (set (reg) (plus (reg) (const_int 0))) is not canonical;
    1858                 :             :            use (set (reg) (reg)) instead.
    1859                 :             :            We don't delete this insn, nor do we convert it into a
    1860                 :             :            note, to avoid losing register notes or the return
    1861                 :             :            value flag.  jump2 already knows how to get rid of
    1862                 :             :            no-op moves.  */
    1863                 :       21385 :         if (new_src == const0_rtx)
    1864                 :             :           {
    1865                 :           0 :             init_costs_to_zero (&mincst);
    1866                 :           0 :             min_regno = i;
    1867                 :           0 :             break;
    1868                 :             :           }
    1869                 :             :         else
    1870                 :             :           {
    1871                 :       21385 :             XEXP (plus_expr, 1) = new_src;
    1872                 :       21385 :             get_full_set_rtx_cost (set, &newcst);
    1873                 :             : 
    1874                 :       21385 :             if (costs_lt_p (&newcst, &mincst, speed))
    1875                 :             :               {
    1876                 :       20777 :                 mincst = newcst;
    1877                 :       20777 :                 min_regno = i;
    1878                 :             :               }
    1879                 :             :           }
    1880                 :             :       }
    1881                 :     1757234 :   SET_SRC (set) = src;
    1882                 :             : 
    1883                 :     1757234 :   if (costs_lt_p (&mincst, &oldcst, speed))
    1884                 :             :     {
    1885                 :         660 :       rtx tem;
    1886                 :             : 
    1887                 :         660 :       tem = gen_rtx_REG (GET_MODE (reg), min_regno);
    1888                 :         660 :       if (i != min_regno)
    1889                 :             :         {
    1890                 :        1320 :           rtx new_src = gen_int_mode (UINTVAL (off) - reg_offset[min_regno],
    1891                 :         660 :                                       GET_MODE (reg));
    1892                 :         660 :           tem = gen_rtx_PLUS (GET_MODE (reg), tem, new_src);
    1893                 :             :         }
    1894                 :         660 :       if (validate_change (insn, &SET_SRC (set), tem, 0))
    1895                 :     1757234 :         changed = true;
    1896                 :             :     }
    1897                 :     1757234 :   reg_set_luid[regno] = move2add_luid;
    1898                 :     1757234 :   move2add_record_sym_value (reg, sym, off);
    1899                 :     1757234 :   return changed;
    1900                 :             : }
    1901                 :             : 
    1902                 :             : /* Perform any invalidations necessary for INSN.  */
    1903                 :             : 
    1904                 :             : static void
    1905                 :    89543432 : reload_cse_move2add_invalidate (rtx_insn *insn)
    1906                 :             : {
    1907                 :   111116337 :   for (rtx note = REG_NOTES (insn); note; note = XEXP (note, 1))
    1908                 :             :     {
    1909                 :    21572905 :       if (REG_NOTE_KIND (note) == REG_INC
    1910                 :           0 :           && REG_P (XEXP (note, 0)))
    1911                 :             :         {
    1912                 :             :           /* Reset the information about this register.  */
    1913                 :           0 :           int regno = REGNO (XEXP (note, 0));
    1914                 :           0 :           if (regno < FIRST_PSEUDO_REGISTER)
    1915                 :             :             {
    1916                 :           0 :               move2add_record_mode (XEXP (note, 0));
    1917                 :           0 :               reg_mode[regno] = VOIDmode;
    1918                 :             :             }
    1919                 :             :         }
    1920                 :             :     }
    1921                 :             : 
    1922                 :             :   /* There are no REG_INC notes for SP autoinc.  */
    1923                 :    89543432 :   subrtx_var_iterator::array_type array;
    1924                 :   465474051 :   FOR_EACH_SUBRTX_VAR (iter, array, PATTERN (insn), NONCONST)
    1925                 :             :     {
    1926                 :   375930619 :       rtx mem = *iter;
    1927                 :   375930619 :       if (mem
    1928                 :   375930619 :           && MEM_P (mem)
    1929                 :    25185251 :           && GET_RTX_CLASS (GET_CODE (XEXP (mem, 0))) == RTX_AUTOINC)
    1930                 :             :         {
    1931                 :     1640586 :           if (XEXP (XEXP (mem, 0), 0) == stack_pointer_rtx)
    1932                 :     1640586 :             reg_mode[STACK_POINTER_REGNUM] = VOIDmode;
    1933                 :             :         }
    1934                 :             :     }
    1935                 :             : 
    1936                 :    89543432 :   note_stores (insn, move2add_note_store, insn);
    1937                 :             : 
    1938                 :             :   /* If INSN is a conditional branch, we try to extract an
    1939                 :             :      implicit set out of it.  */
    1940                 :    89543432 :   if (any_condjump_p (insn))
    1941                 :             :     {
    1942                 :     4273959 :       rtx cnd = fis_get_condition (insn);
    1943                 :             : 
    1944                 :     4273959 :       if (cnd != NULL_RTX
    1945                 :     3827648 :           && GET_CODE (cnd) == NE
    1946                 :     1720254 :           && REG_P (XEXP (cnd, 0))
    1947                 :     1154356 :           && !reg_set_p (XEXP (cnd, 0), insn)
    1948                 :             :           /* The following two checks, which are also in
    1949                 :             :              move2add_note_store, are intended to reduce the
    1950                 :             :              number of calls to gen_rtx_SET to avoid memory
    1951                 :             :              allocation if possible.  */
    1952                 :     1154356 :           && SCALAR_INT_MODE_P (GET_MODE (XEXP (cnd, 0)))
    1953                 :     1154356 :           && REG_NREGS (XEXP (cnd, 0)) == 1
    1954                 :     5428315 :           && CONST_INT_P (XEXP (cnd, 1)))
    1955                 :             :         {
    1956                 :      805949 :           rtx implicit_set = gen_rtx_SET (XEXP (cnd, 0), XEXP (cnd, 1));
    1957                 :      805949 :           move2add_note_store (SET_DEST (implicit_set), implicit_set, insn);
    1958                 :             :         }
    1959                 :             :     }
    1960                 :             : 
    1961                 :             :   /* If this is a CALL_INSN, all call used registers are stored with
    1962                 :             :      unknown values.  */
    1963                 :    89543432 :   if (CALL_P (insn))
    1964                 :             :     {
    1965                 :     4414272 :       function_abi callee_abi = insn_callee_abi (insn);
    1966                 :   410527296 :       for (int i = FIRST_PSEUDO_REGISTER - 1; i >= 0; i--)
    1967                 :   406113024 :         if (reg_mode[i] != VOIDmode
    1968                 :    21455350 :             && reg_mode[i] != BLKmode
    1969                 :   427024719 :             && callee_abi.clobbers_reg_p (reg_mode[i], i))
    1970                 :             :             /* Reset the information about this register.  */
    1971                 :     7424218 :           reg_mode[i] = VOIDmode;
    1972                 :             :     }
    1973                 :    89543432 : }
    1974                 :             : 
    1975                 :             : /* Convert move insns with constant inputs to additions if they are cheaper.
    1976                 :             :    Return true if any changes were made.  */
    1977                 :             : static bool
    1978                 :      987683 : reload_cse_move2add (rtx_insn *first)
    1979                 :             : {
    1980                 :      987683 :   int i;
    1981                 :      987683 :   rtx_insn *insn;
    1982                 :      987683 :   bool changed = false;
    1983                 :             : 
    1984                 :    91854519 :   for (i = FIRST_PSEUDO_REGISTER - 1; i >= 0; i--)
    1985                 :             :     {
    1986                 :    90866836 :       reg_set_luid[i] = 0;
    1987                 :    90866836 :       reg_offset[i] = 0;
    1988                 :    90866836 :       reg_base_reg[i] = 0;
    1989                 :    90866836 :       reg_symbol_ref[i] = NULL_RTX;
    1990                 :    90866836 :       reg_mode[i] = VOIDmode;
    1991                 :             :     }
    1992                 :             : 
    1993                 :      987683 :   move2add_last_label_luid = 0;
    1994                 :      987683 :   move2add_luid = 2;
    1995                 :   117670182 :   for (insn = first; insn; insn = NEXT_INSN (insn), move2add_luid++)
    1996                 :             :     {
    1997                 :   116682499 :       rtx set;
    1998                 :             : 
    1999                 :   116682499 :       if (LABEL_P (insn))
    2000                 :             :         {
    2001                 :     4607183 :           move2add_last_label_luid = move2add_luid;
    2002                 :             :           /* We're going to increment move2add_luid twice after a
    2003                 :             :              label, so that we can use move2add_last_label_luid + 1 as
    2004                 :             :              the luid for constants.  */
    2005                 :     4607183 :           move2add_luid++;
    2006                 :   121289682 :           continue;
    2007                 :             :         }
    2008                 :   112075316 :       if (! INSN_P (insn))
    2009                 :    20635156 :         continue;
    2010                 :    91440160 :       set = single_set (insn);
    2011                 :             :       /* For simplicity, we only perform this optimization on
    2012                 :             :          single-sets.  */
    2013                 :    91440160 :       scalar_int_mode mode;
    2014                 :    91440160 :       if (set
    2015                 :    49207902 :           && REG_P (SET_DEST (set))
    2016                 :   125242252 :           && is_a <scalar_int_mode> (GET_MODE (SET_DEST (set)), &mode))
    2017                 :             :         {
    2018                 :    25183600 :           rtx reg = SET_DEST (set);
    2019                 :    25183600 :           int regno = REGNO (reg);
    2020                 :    25183600 :           rtx src = SET_SRC (set);
    2021                 :             : 
    2022                 :             :           /* Check if we have valid information on the contents of this
    2023                 :             :              register in the mode of REG.  */
    2024                 :    25183600 :           if (move2add_valid_value_p (regno, mode)
    2025                 :    25183600 :               && dbg_cnt (cse2_move2add))
    2026                 :             :             {
    2027                 :             :               /* Try to transform (set (REGX) (CONST_INT A))
    2028                 :             :                                   ...
    2029                 :             :                                   (set (REGX) (CONST_INT B))
    2030                 :             :                  to
    2031                 :             :                                   (set (REGX) (CONST_INT A))
    2032                 :             :                                   ...
    2033                 :             :                                   (set (REGX) (plus (REGX) (CONST_INT B-A)))
    2034                 :             :                  or
    2035                 :             :                                   (set (REGX) (CONST_INT A))
    2036                 :             :                                   ...
    2037                 :             :                                   (set (STRICT_LOW_PART (REGX)) (CONST_INT B))
    2038                 :             :               */
    2039                 :             : 
    2040                 :     3568989 :               if (CONST_INT_P (src)
    2041                 :      300098 :                   && reg_base_reg[regno] < 0
    2042                 :      139912 :                   && reg_symbol_ref[regno] == NULL_RTX)
    2043                 :             :                 {
    2044                 :      137691 :                   changed |= move2add_use_add2_insn (mode, reg, NULL_RTX,
    2045                 :             :                                                      src, insn);
    2046                 :      137691 :                   continue;
    2047                 :             :                 }
    2048                 :             : 
    2049                 :             :               /* Try to transform (set (REGX) (REGY))
    2050                 :             :                                   (set (REGX) (PLUS (REGX) (CONST_INT A)))
    2051                 :             :                                   ...
    2052                 :             :                                   (set (REGX) (REGY))
    2053                 :             :                                   (set (REGX) (PLUS (REGX) (CONST_INT B)))
    2054                 :             :                  to
    2055                 :             :                                   (set (REGX) (REGY))
    2056                 :             :                                   (set (REGX) (PLUS (REGX) (CONST_INT A)))
    2057                 :             :                                   ...
    2058                 :             :                                   (set (REGX) (plus (REGX) (CONST_INT B-A)))  */
    2059                 :     3431298 :               else if (REG_P (src)
    2060                 :      446546 :                        && reg_set_luid[regno] == reg_set_luid[REGNO (src)]
    2061                 :      113144 :                        && reg_base_reg[regno] == reg_base_reg[REGNO (src)]
    2062                 :     3544442 :                        && move2add_valid_value_p (REGNO (src), mode))
    2063                 :             :                 {
    2064                 :       90088 :                   rtx_insn *next = next_nonnote_nondebug_insn (insn);
    2065                 :       90088 :                   rtx set = NULL_RTX;
    2066                 :       90088 :                   if (next)
    2067                 :       90074 :                     set = single_set (next);
    2068                 :       90074 :                   if (set
    2069                 :       68721 :                       && SET_DEST (set) == reg
    2070                 :        6441 :                       && GET_CODE (SET_SRC (set)) == PLUS
    2071                 :         656 :                       && XEXP (SET_SRC (set), 0) == reg
    2072                 :         650 :                       && CONST_INT_P (XEXP (SET_SRC (set), 1)))
    2073                 :             :                     {
    2074                 :         463 :                       rtx src3 = XEXP (SET_SRC (set), 1);
    2075                 :         463 :                       unsigned HOST_WIDE_INT added_offset = UINTVAL (src3);
    2076                 :         463 :                       HOST_WIDE_INT base_offset = reg_offset[REGNO (src)];
    2077                 :         463 :                       HOST_WIDE_INT regno_offset = reg_offset[regno];
    2078                 :         463 :                       rtx new_src =
    2079                 :         926 :                         gen_int_mode (added_offset
    2080                 :         463 :                                       + base_offset
    2081                 :         463 :                                       - regno_offset,
    2082                 :             :                                       mode);
    2083                 :         463 :                       bool success = false;
    2084                 :         463 :                       bool speed = optimize_bb_for_speed_p (BLOCK_FOR_INSN (insn));
    2085                 :             : 
    2086                 :         463 :                       if (new_src == const0_rtx)
    2087                 :             :                         /* See above why we create (set (reg) (reg)) here.  */
    2088                 :          40 :                         success
    2089                 :          40 :                           = validate_change (next, &SET_SRC (set), reg, 0);
    2090                 :             :                       else
    2091                 :             :                         {
    2092                 :         423 :                           rtx old_src = SET_SRC (set);
    2093                 :         423 :                           struct full_rtx_costs oldcst, newcst;
    2094                 :         423 :                           rtx tem = gen_rtx_PLUS (mode, reg, new_src);
    2095                 :             : 
    2096                 :         423 :                           get_full_set_rtx_cost (set, &oldcst);
    2097                 :         423 :                           SET_SRC (set) = tem;
    2098                 :         423 :                           get_full_set_src_cost (tem, mode, &newcst);
    2099                 :         423 :                           SET_SRC (set) = old_src;
    2100                 :         423 :                           costs_add_n_insns (&oldcst, 1);
    2101                 :             : 
    2102                 :         423 :                           rtx *setloc = GET_CODE (PATTERN (next)) == PARALLEL
    2103                 :         423 :                             ? &XVECEXP (PATTERN (next), 0, 0) : &PATTERN (next);
    2104                 :         423 :                           if (*setloc == set
    2105                 :         423 :                               && costs_lt_p (&newcst, &oldcst, speed)
    2106                 :         846 :                               && have_add2_insn (reg, new_src))
    2107                 :             :                             {
    2108                 :         423 :                               rtx newpat = gen_rtx_SET (reg, tem);
    2109                 :         423 :                               success
    2110                 :         423 :                                 = validate_change (next, setloc, newpat, 0);
    2111                 :             :                             }
    2112                 :             :                         }
    2113                 :         463 :                       if (success)
    2114                 :         463 :                         delete_insn (insn);
    2115                 :         463 :                       changed |= success;
    2116                 :         463 :                       insn = next;
    2117                 :             :                       /* Make sure to perform any invalidations related to
    2118                 :             :                          NEXT/INSN since we're going to bypass the normal
    2119                 :             :                          flow with the continue below.
    2120                 :             : 
    2121                 :             :                          Do this before recording the new mode/offset.  */
    2122                 :         463 :                       reload_cse_move2add_invalidate (insn);
    2123                 :         463 :                       move2add_record_mode (reg);
    2124                 :         463 :                       reg_offset[regno]
    2125                 :         463 :                         = trunc_int_for_mode (added_offset + base_offset,
    2126                 :             :                                               mode);
    2127                 :         463 :                       continue;
    2128                 :         463 :                     }
    2129                 :             :                 }
    2130                 :             :             }
    2131                 :             : 
    2132                 :             :           /* Try to transform
    2133                 :             :              (set (REGX) (CONST (PLUS (SYMBOL_REF) (CONST_INT A))))
    2134                 :             :              ...
    2135                 :             :              (set (REGY) (CONST (PLUS (SYMBOL_REF) (CONST_INT B))))
    2136                 :             :              to
    2137                 :             :              (set (REGX) (CONST (PLUS (SYMBOL_REF) (CONST_INT A))))
    2138                 :             :              ...
    2139                 :             :              (set (REGY) (CONST (PLUS (REGX) (CONST_INT B-A))))  */
    2140                 :    25045446 :           if ((GET_CODE (src) == SYMBOL_REF
    2141                 :    23348519 :                || (GET_CODE (src) == CONST
    2142                 :       62345 :                    && GET_CODE (XEXP (src, 0)) == PLUS
    2143                 :       62133 :                    && GET_CODE (XEXP (XEXP (src, 0), 0)) == SYMBOL_REF
    2144                 :       62110 :                    && CONST_INT_P (XEXP (XEXP (src, 0), 1))))
    2145                 :    25107556 :               && dbg_cnt (cse2_move2add))
    2146                 :             :             {
    2147                 :     1759037 :               rtx sym, off;
    2148                 :             : 
    2149                 :     1759037 :               if (GET_CODE (src) == SYMBOL_REF)
    2150                 :             :                 {
    2151                 :     1696927 :                   sym = src;
    2152                 :     1696927 :                   off = const0_rtx;
    2153                 :             :                 }
    2154                 :             :               else
    2155                 :             :                 {
    2156                 :       62110 :                   sym = XEXP (XEXP (src, 0), 0);
    2157                 :       62110 :                   off = XEXP (XEXP (src, 0), 1);
    2158                 :             :                 }
    2159                 :             : 
    2160                 :             :               /* If the reg already contains the value which is sum of
    2161                 :             :                  sym and some constant value, we can use an add2 insn.  */
    2162                 :     1759037 :               if (move2add_valid_value_p (regno, mode)
    2163                 :      182418 :                   && reg_base_reg[regno] < 0
    2164                 :      122241 :                   && reg_symbol_ref[regno] != NULL_RTX
    2165                 :     1813926 :                   && rtx_equal_p (sym, reg_symbol_ref[regno]))
    2166                 :        1803 :                 changed |= move2add_use_add2_insn (mode, reg, sym, off, insn);
    2167                 :             : 
    2168                 :             :               /* Otherwise, we have to find a register whose value is sum
    2169                 :             :                  of sym and some constant value.  */
    2170                 :             :               else
    2171                 :     1757234 :                 changed |= move2add_use_add3_insn (mode, reg, sym, off, insn);
    2172                 :             : 
    2173                 :     1759037 :               continue;
    2174                 :     1759037 :             }
    2175                 :             :         }
    2176                 :    89542969 :       reload_cse_move2add_invalidate (insn);
    2177                 :             :     }
    2178                 :      987683 :   return changed;
    2179                 :             : }
    2180                 :             : 
    2181                 :             : /* SET is a SET or CLOBBER that sets DST.  DATA is the insn which
    2182                 :             :    contains SET.
    2183                 :             :    Update reg_set_luid, reg_offset and reg_base_reg accordingly.
    2184                 :             :    Called from reload_cse_move2add via note_stores.  */
    2185                 :             : 
    2186                 :             : static void
    2187                 :    56078234 : move2add_note_store (rtx dst, const_rtx set, void *data)
    2188                 :             : {
    2189                 :    56078234 :   rtx_insn *insn = (rtx_insn *) data;
    2190                 :    56078234 :   unsigned int regno = 0;
    2191                 :    56078234 :   scalar_int_mode mode;
    2192                 :             : 
    2193                 :    56078234 :   if (GET_CODE (dst) == SUBREG)
    2194                 :        3255 :     regno = subreg_regno (dst);
    2195                 :    56074979 :   else if (REG_P (dst))
    2196                 :    40551551 :     regno = REGNO (dst);
    2197                 :             :   else
    2198                 :    56078234 :     return;
    2199                 :             : 
    2200                 :    40554806 :   if (!is_a <scalar_int_mode> (GET_MODE (dst), &mode))
    2201                 :    15320289 :     goto invalidate;
    2202                 :             : 
    2203                 :    25234517 :   if (GET_CODE (set) == SET)
    2204                 :             :     {
    2205                 :    24677170 :       rtx note, sym = NULL_RTX;
    2206                 :    24677170 :       rtx off;
    2207                 :             : 
    2208                 :    24677170 :       note = find_reg_equal_equiv_note (insn);
    2209                 :    24677170 :       if (note && GET_CODE (XEXP (note, 0)) == SYMBOL_REF)
    2210                 :             :         {
    2211                 :       76387 :           sym = XEXP (note, 0);
    2212                 :       76387 :           off = const0_rtx;
    2213                 :             :         }
    2214                 :     4407763 :       else if (note && GET_CODE (XEXP (note, 0)) == CONST
    2215                 :        9613 :                && GET_CODE (XEXP (XEXP (note, 0), 0)) == PLUS
    2216                 :        9421 :                && GET_CODE (XEXP (XEXP (XEXP (note, 0), 0), 0)) == SYMBOL_REF
    2217                 :        9401 :                && CONST_INT_P (XEXP (XEXP (XEXP (note, 0), 0), 1)))
    2218                 :             :         {
    2219                 :             :           sym = XEXP (XEXP (XEXP (note, 0), 0), 0);
    2220                 :             :           off = XEXP (XEXP (XEXP (note, 0), 0), 1);
    2221                 :             :         }
    2222                 :             : 
    2223                 :       85788 :       if (sym != NULL_RTX)
    2224                 :             :         {
    2225                 :       85788 :           move2add_record_sym_value (dst, sym, off);
    2226                 :       85788 :           return;
    2227                 :             :         }
    2228                 :             :     }
    2229                 :             : 
    2230                 :    25148729 :   if (GET_CODE (set) == SET
    2231                 :    24591382 :       && GET_CODE (SET_DEST (set)) != ZERO_EXTRACT
    2232                 :    24590021 :       && GET_CODE (SET_DEST (set)) != STRICT_LOW_PART)
    2233                 :             :     {
    2234                 :    24586529 :       rtx src = SET_SRC (set);
    2235                 :    24586529 :       rtx base_reg;
    2236                 :    24586529 :       unsigned HOST_WIDE_INT offset;
    2237                 :    24586529 :       int base_regno;
    2238                 :             : 
    2239                 :    24586529 :       switch (GET_CODE (src))
    2240                 :             :         {
    2241                 :     5243291 :         case PLUS:
    2242                 :     5243291 :           if (REG_P (XEXP (src, 0)))
    2243                 :             :             {
    2244                 :     4978260 :               base_reg = XEXP (src, 0);
    2245                 :             : 
    2246                 :     4978260 :               if (CONST_INT_P (XEXP (src, 1)))
    2247                 :     4280558 :                 offset = UINTVAL (XEXP (src, 1));
    2248                 :      697702 :               else if (REG_P (XEXP (src, 1))
    2249                 :      697702 :                        && move2add_valid_value_p (REGNO (XEXP (src, 1)), mode))
    2250                 :             :                 {
    2251                 :       81145 :                   if (reg_base_reg[REGNO (XEXP (src, 1))] < 0
    2252                 :       81145 :                       && reg_symbol_ref[REGNO (XEXP (src, 1))] == NULL_RTX)
    2253                 :        7184 :                     offset = reg_offset[REGNO (XEXP (src, 1))];
    2254                 :             :                   /* Maybe the first register is known to be a
    2255                 :             :                      constant.  */
    2256                 :       73961 :                   else if (move2add_valid_value_p (REGNO (base_reg), mode)
    2257                 :       18161 :                            && reg_base_reg[REGNO (base_reg)] < 0
    2258                 :       74711 :                            && reg_symbol_ref[REGNO (base_reg)] == NULL_RTX)
    2259                 :             :                     {
    2260                 :         636 :                       offset = reg_offset[REGNO (base_reg)];
    2261                 :         636 :                       base_reg = XEXP (src, 1);
    2262                 :             :                     }
    2263                 :             :                   else
    2264                 :       73325 :                     goto invalidate;
    2265                 :             :                 }
    2266                 :             :               else
    2267                 :      616557 :                 goto invalidate;
    2268                 :             : 
    2269                 :             :               break;
    2270                 :             :             }
    2271                 :             : 
    2272                 :      265031 :           goto invalidate;
    2273                 :             : 
    2274                 :             :         case REG:
    2275                 :             :           base_reg = src;
    2276                 :             :           offset = 0;
    2277                 :             :           break;
    2278                 :             : 
    2279                 :     4023197 :         case CONST_INT:
    2280                 :             :           /* Start tracking the register as a constant.  */
    2281                 :     4023197 :           reg_base_reg[regno] = -1;
    2282                 :     4023197 :           reg_symbol_ref[regno] = NULL_RTX;
    2283                 :     4023197 :           reg_offset[regno] = INTVAL (SET_SRC (set));
    2284                 :             :           /* We assign the same luid to all registers set to constants.  */
    2285                 :     4023197 :           reg_set_luid[regno] = move2add_last_label_luid + 1;
    2286                 :     4023197 :           move2add_record_mode (dst);
    2287                 :     4023197 :           return;
    2288                 :             : 
    2289                 :    10524392 :         default:
    2290                 :    10524392 :           goto invalidate;
    2291                 :             :         }
    2292                 :             : 
    2293                 :     9084027 :       base_regno = REGNO (base_reg);
    2294                 :             :       /* If information about the base register is not valid, set it
    2295                 :             :          up as a new base register, pretending its value is known
    2296                 :             :          starting from the current insn.  */
    2297                 :     9084027 :       if (!move2add_valid_value_p (base_regno, mode))
    2298                 :             :         {
    2299                 :     6558393 :           reg_base_reg[base_regno] = base_regno;
    2300                 :     6558393 :           reg_symbol_ref[base_regno] = NULL_RTX;
    2301                 :     6558393 :           reg_offset[base_regno] = 0;
    2302                 :     6558393 :           reg_set_luid[base_regno] = move2add_luid;
    2303                 :     6558393 :           gcc_assert (GET_MODE (base_reg) == mode);
    2304                 :     6558393 :           move2add_record_mode (base_reg);
    2305                 :             :         }
    2306                 :             : 
    2307                 :             :       /* Copy base information from our base register.  */
    2308                 :     9084027 :       reg_set_luid[regno] = reg_set_luid[base_regno];
    2309                 :     9084027 :       reg_base_reg[regno] = reg_base_reg[base_regno];
    2310                 :     9084027 :       reg_symbol_ref[regno] = reg_symbol_ref[base_regno];
    2311                 :             : 
    2312                 :             :       /* Compute the sum of the offsets or constants.  */
    2313                 :     9084027 :       reg_offset[regno]
    2314                 :     9084027 :         = trunc_int_for_mode (offset + reg_offset[base_regno], mode);
    2315                 :             : 
    2316                 :     9084027 :       move2add_record_mode (dst);
    2317                 :     9084027 :     }
    2318                 :             :   else
    2319                 :             :     {
    2320                 :      562200 :     invalidate:
    2321                 :             :       /* Invalidate the contents of the register.  */
    2322                 :    27361794 :       move2add_record_mode (dst);
    2323                 :    27361794 :       reg_mode[regno] = VOIDmode;
    2324                 :             :     }
    2325                 :             : }
    2326                 :             : 
    2327                 :             : namespace {
    2328                 :             : 
    2329                 :             : const pass_data pass_data_postreload_cse =
    2330                 :             : {
    2331                 :             :   RTL_PASS, /* type */
    2332                 :             :   "postreload", /* name */
    2333                 :             :   OPTGROUP_NONE, /* optinfo_flags */
    2334                 :             :   TV_RELOAD_CSE_REGS, /* tv_id */
    2335                 :             :   0, /* properties_required */
    2336                 :             :   0, /* properties_provided */
    2337                 :             :   0, /* properties_destroyed */
    2338                 :             :   0, /* todo_flags_start */
    2339                 :             :   TODO_df_finish, /* todo_flags_finish */
    2340                 :             : };
    2341                 :             : 
    2342                 :             : class pass_postreload_cse : public rtl_opt_pass
    2343                 :             : {
    2344                 :             : public:
    2345                 :      281914 :   pass_postreload_cse (gcc::context *ctxt)
    2346                 :      563828 :     : rtl_opt_pass (pass_data_postreload_cse, ctxt)
    2347                 :             :   {}
    2348                 :             : 
    2349                 :             :   /* opt_pass methods: */
    2350                 :     1426773 :   bool gate (function *) final override
    2351                 :             :   {
    2352                 :     1426773 :     return (optimize > 0 && reload_completed);
    2353                 :             :   }
    2354                 :             : 
    2355                 :             :   unsigned int execute (function *) final override;
    2356                 :             : 
    2357                 :             : }; // class pass_postreload_cse
    2358                 :             : 
    2359                 :             : unsigned int
    2360                 :      987683 : pass_postreload_cse::execute (function *fun)
    2361                 :             : {
    2362                 :      987683 :   if (!dbg_cnt (postreload_cse))
    2363                 :             :     return 0;
    2364                 :             : 
    2365                 :             :   /* Do a very simple CSE pass over just the hard registers.  */
    2366                 :      987683 :   reload_cse_regs (get_insns ());
    2367                 :             :   /* Reload_cse_regs can eliminate potentially-trapping MEMs.
    2368                 :             :      Remove any EH edges associated with them.  */
    2369                 :      987683 :   if (fun->can_throw_non_call_exceptions
    2370                 :      987683 :       && purge_all_dead_edges ())
    2371                 :         108 :     cleanup_cfg (0);
    2372                 :             : 
    2373                 :             :   return 0;
    2374                 :             : }
    2375                 :             : 
    2376                 :             : } // anon namespace
    2377                 :             : 
    2378                 :             : rtl_opt_pass *
    2379                 :      281914 : make_pass_postreload_cse (gcc::context *ctxt)
    2380                 :             : {
    2381                 :      281914 :   return new pass_postreload_cse (ctxt);
    2382                 :             : }
        

Generated by: LCOV version 2.1-beta

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