OSDN Git Service

Backported from mainline
[pf3gnuchains/gcc-fork.git] / gcc / postreload.c
index 4d3bae4..5c18912 100644 (file)
@@ -1,7 +1,7 @@
 /* Perform simple optimizations to clean up the result of reload.
    Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
    1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
-   2010 Free Software Foundation, Inc.
+   2010, 2011 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -41,7 +41,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "output.h"
 #include "cselib.h"
 #include "diagnostic-core.h"
-#include "toplev.h"
 #include "except.h"
 #include "tree.h"
 #include "target.h"
@@ -113,7 +112,8 @@ reload_cse_simplify (rtx insn, rtx testreg)
          if (REG_P (value)
              && ! REG_FUNCTION_VALUE_P (value))
            value = 0;
-         delete_insn_and_edges (insn);
+         if (check_for_inc_dec (insn))
+           delete_insn_and_edges (insn);
          return;
        }
 
@@ -164,7 +164,8 @@ reload_cse_simplify (rtx insn, rtx testreg)
 
       if (i < 0)
        {
-         delete_insn_and_edges (insn);
+         if (check_for_inc_dec (insn))
+           delete_insn_and_edges (insn);
          /* We're done with this insn.  */
          return;
        }
@@ -232,7 +233,7 @@ reload_cse_simplify_set (rtx set, rtx insn)
   int did_change = 0;
   int dreg;
   rtx src;
-  enum reg_class dclass;
+  reg_class_t dclass;
   int old_cost;
   cselib_val *val;
   struct elt_loc_list *l;
@@ -263,7 +264,7 @@ reload_cse_simplify_set (rtx set, rtx insn)
     return 0;
 #endif
 
-  val = cselib_lookup (src, GET_MODE (SET_DEST (set)), 0);
+  val = cselib_lookup (src, GET_MODE (SET_DEST (set)), 0, VOIDmode);
   if (! val)
     return 0;
 
@@ -274,7 +275,7 @@ reload_cse_simplify_set (rtx set, rtx insn)
     old_cost = register_move_cost (GET_MODE (src),
                                   REGNO_REG_CLASS (REGNO (src)), dclass);
   else
-    old_cost = rtx_cost (src, SET, speed);
+    old_cost = set_src_cost (src, speed);
 
   for (l = val->locs; l; l = l->next)
     {
@@ -309,7 +310,7 @@ reload_cse_simplify_set (rtx set, rtx insn)
              this_rtx = GEN_INT (this_val);
            }
 #endif
-         this_cost = rtx_cost (this_rtx, SET, speed);
+         this_cost = set_src_cost (this_rtx, speed);
        }
       else if (REG_P (this_rtx))
        {
@@ -317,7 +318,7 @@ reload_cse_simplify_set (rtx set, rtx insn)
          if (extend_op != UNKNOWN)
            {
              this_rtx = gen_rtx_fmt_e (extend_op, word_mode, this_rtx);
-             this_cost = rtx_cost (this_rtx, SET, speed);
+             this_cost = set_src_cost (this_rtx, speed);
            }
          else
 #endif
@@ -477,7 +478,9 @@ reload_cse_simplify_operands (rtx insn, rtx testreg)
            continue;
        }
 #endif /* LOAD_EXTEND_OP */
-      v = cselib_lookup (op, recog_data.operand_mode[i], 0);
+      if (side_effects_p (op))
+       continue;
+      v = cselib_lookup (op, recog_data.operand_mode[i], 0, VOIDmode);
       if (! v)
        continue;
 
@@ -576,10 +579,12 @@ reload_cse_simplify_operands (rtx insn, rtx testreg)
                      && recog_data.alternative_enabled_p[j]
                      && reg_fits_class_p (testreg, rclass, 0, mode)
                      && (!CONST_INT_P (recog_data.operand[i])
-                         || (rtx_cost (recog_data.operand[i], SET,
-                                       optimize_bb_for_speed_p (BLOCK_FOR_INSN (insn)))
-                             > rtx_cost (testreg, SET,
-                                       optimize_bb_for_speed_p (BLOCK_FOR_INSN (insn))))))
+                         || (set_src_cost (recog_data.operand[i],
+                                           optimize_bb_for_speed_p
+                                            (BLOCK_FOR_INSN (insn)))
+                             > set_src_cost (testreg,
+                                             optimize_bb_for_speed_p
+                                              (BLOCK_FOR_INSN (insn))))))
                    {
                      alternative_nregs[j]++;
                      op_alt_regno[i][j] = regno;
@@ -913,12 +918,12 @@ try_replace_in_use (struct reg_use *use, rtx reg, rtx src)
          && CONSTANT_P (XEXP (SET_SRC (new_set), 1)))
        {
          rtx new_src;
-         int old_cost = rtx_cost (SET_SRC (new_set), SET, speed);
+         int old_cost = set_src_cost (SET_SRC (new_set), speed);
 
          gcc_assert (rtx_equal_p (XEXP (SET_SRC (new_set), 0), reg));
          new_src = simplify_replace_rtx (SET_SRC (new_set), reg, src);
 
-         if (rtx_cost (new_src, SET, speed) <= old_cost
+         if (set_src_cost (new_src, speed) <= old_cost
              && validate_change (use_insn, &SET_SRC (new_set),
                                  new_src, 0))
            return true;
@@ -1010,6 +1015,12 @@ reload_combine_recognize_const_pattern (rtx insn)
              && reg_state[clobbered_regno].real_store_ruid >= use_ruid)
            break;
 
+#ifdef HAVE_cc0
+         /* Do not separate cc0 setter and cc0 user on HAVE_cc0 targets.  */
+         if (must_move_add && sets_cc0_p (PATTERN (use_insn)))
+           break;
+#endif
+
          gcc_assert (reg_state[regno].store_ruid <= use_ruid);
          /* Avoid moving a use of ADDREG past a point where it is stored.  */
          if (reg_state[REGNO (addreg)].store_ruid > use_ruid)
@@ -1224,7 +1235,6 @@ static void
 reload_combine (void)
 {
   rtx insn, prev;
-  int i;
   basic_block bb;
   unsigned int r;
   int min_labelno, n_labels;
@@ -1292,6 +1302,7 @@ reload_combine (void)
 
   for (insn = get_last_insn (); insn; insn = prev)
     {
+      bool control_flow_insn;
       rtx note;
 
       prev = PREV_INSN (insn);
@@ -1302,16 +1313,28 @@ reload_combine (void)
       if (LABEL_P (insn))
        last_label_ruid = reload_combine_ruid;
       else if (BARRIER_P (insn))
-       for (r = 0; r < FIRST_PSEUDO_REGISTER; r++)
-         if (! fixed_regs[r])
+       {
+         /* Crossing a barrier resets all the use information.  */
+         for (r = 0; r < FIRST_PSEUDO_REGISTER; r++)
+           if (! fixed_regs[r])
              reg_state[r].use_index = RELOAD_COMBINE_MAX_USES;
+       }
+      else if (INSN_P (insn) && volatile_insn_p (PATTERN (insn)))
+       /* Optimizations across insns being marked as volatile must be
+          prevented.  All the usage information is invalidated
+          here.  */
+       for (r = 0; r < FIRST_PSEUDO_REGISTER; r++)
+         if (! fixed_regs[r]
+             && reg_state[r].use_index != RELOAD_COMBINE_MAX_USES)
+           reg_state[r].use_index = -1;
 
       if (! NONDEBUG_INSN_P (insn))
        continue;
 
       reload_combine_ruid++;
 
-      if (control_flow_insn_p (insn))
+      control_flow_insn = control_flow_insn_p (insn);
+      if (control_flow_insn)
        last_jump_ruid = reload_combine_ruid;
 
       if (reload_combine_recognize_const_pattern (insn)
@@ -1339,9 +1362,9 @@ reload_combine (void)
                {
                  unsigned int i;
                  unsigned int start_reg = REGNO (usage_rtx);
-                 unsigned int num_regs =
-                       hard_regno_nregs[start_reg][GET_MODE (usage_rtx)];
-                 unsigned int end_reg  = start_reg + num_regs - 1;
+                 unsigned int num_regs
+                   = hard_regno_nregs[start_reg][GET_MODE (usage_rtx)];
+                 unsigned int end_reg = start_reg + num_regs - 1;
                  for (i = start_reg; i <= end_reg; i++)
                    if (GET_CODE (XEXP (link, 0)) == CLOBBER)
                      {
@@ -1352,10 +1375,9 @@ reload_combine (void)
                      reg_state[i].use_index = -1;
                 }
             }
-
        }
 
-      if (control_flow_insn_p (insn) && GET_CODE (PATTERN (insn)) != RETURN)
+      if (control_flow_insn && GET_CODE (PATTERN (insn)) != RETURN)
        {
          /* Non-spill registers might be used at the call destination in
             some unknown fashion, so we have to mark the unknown use.  */
@@ -1367,20 +1389,19 @@ reload_combine (void)
          else
            live = &ever_live_at_start;
 
-         for (i = FIRST_PSEUDO_REGISTER - 1; i >= 0; --i)
-           if (TEST_HARD_REG_BIT (*live, i))
-             reg_state[i].use_index = -1;
+         for (r = 0; r < FIRST_PSEUDO_REGISTER; r++)
+           if (TEST_HARD_REG_BIT (*live, r))
+             reg_state[r].use_index = -1;
        }
 
-      reload_combine_note_use (&PATTERN (insn), insn,
-                              reload_combine_ruid, NULL_RTX);
+      reload_combine_note_use (&PATTERN (insn), insn, reload_combine_ruid,
+                              NULL_RTX);
+
       for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
        {
-         if (REG_NOTE_KIND (note) == REG_INC
-             && REG_P (XEXP (note, 0)))
+         if (REG_NOTE_KIND (note) == REG_INC && REG_P (XEXP (note, 0)))
            {
              int regno = REGNO (XEXP (note, 0));
-
              reg_state[regno].store_ruid = reload_combine_ruid;
              reg_state[regno].real_store_ruid = reload_combine_ruid;
              reg_state[regno].use_index = -1;
@@ -1410,6 +1431,32 @@ reload_combine_note_store (rtx dst, const_rtx set, void *data ATTRIBUTE_UNUSED)
                                   GET_MODE (dst));
       dst = SUBREG_REG (dst);
     }
+
+  /* Some targets do argument pushes without adding REG_INC notes.  */
+
+  if (MEM_P (dst))
+    {
+      dst = XEXP (dst, 0);
+      if (GET_CODE (dst) == PRE_INC || GET_CODE (dst) == POST_INC
+         || GET_CODE (dst) == PRE_DEC || GET_CODE (dst) == POST_DEC
+         || GET_CODE (dst) == PRE_MODIFY || GET_CODE (dst) == POST_MODIFY)
+       {
+         regno = REGNO (XEXP (dst, 0));
+         mode = GET_MODE (XEXP (dst, 0));
+         for (i = hard_regno_nregs[regno][mode] - 1 + regno; i >= regno; i--)
+           {
+             /* We could probably do better, but for now mark the register
+                as used in an unknown fashion and set/clobbered at this
+                insn.  */
+             reg_state[i].use_index = -1;
+             reg_state[i].store_ruid = reload_combine_ruid;
+             reg_state[i].real_store_ruid = reload_combine_ruid;
+           }
+       }
+      else
+        return;
+    }
+
   if (!REG_P (dst))
     return;
   regno += REGNO (dst);
@@ -1609,8 +1656,7 @@ static int move2add_last_label_luid;
 #define MODES_OK_FOR_MOVE2ADD(OUTMODE, INMODE) \
   (GET_MODE_SIZE (OUTMODE) == GET_MODE_SIZE (INMODE) \
    || (GET_MODE_SIZE (OUTMODE) <= GET_MODE_SIZE (INMODE) \
-       && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (OUTMODE), \
-                                GET_MODE_BITSIZE (INMODE))))
+       && TRULY_NOOP_TRUNCATION_MODES_P (OUTMODE, INMODE)))
 
 /* This function is called with INSN that sets REG to (SYM + OFF),
    while REG is known to already have value (SYM + offset).
@@ -1650,9 +1696,9 @@ move2add_use_add2_insn (rtx reg, rtx sym, rtx off, rtx insn)
       struct full_rtx_costs oldcst, newcst;
       rtx tem = gen_rtx_PLUS (GET_MODE (reg), reg, new_src);
 
-      get_full_rtx_cost (pat, SET, &oldcst);
+      get_full_set_rtx_cost (pat, &oldcst);
       SET_SRC (pat) = tem;
-      get_full_rtx_cost (pat, SET, &newcst);
+      get_full_set_rtx_cost (pat, &newcst);
       SET_SRC (pat) = src;
 
       if (costs_lt_p (&newcst, &oldcst, speed)
@@ -1719,7 +1765,7 @@ move2add_use_add3_insn (rtx reg, rtx sym, rtx off, rtx insn)
   rtx plus_expr;
 
   init_costs_to_max (&mincst);
-  get_full_rtx_cost (pat, SET, &oldcst);
+  get_full_set_rtx_cost (pat, &oldcst);
 
   plus_expr = gen_rtx_PLUS (GET_MODE (reg), reg, const0_rtx);
   SET_SRC (pat) = plus_expr;
@@ -1748,7 +1794,7 @@ move2add_use_add3_insn (rtx reg, rtx sym, rtx off, rtx insn)
        else
          {
            XEXP (plus_expr, 1) = new_src;
-           get_full_rtx_cost (pat, SET, &newcst);
+           get_full_set_rtx_cost (pat, &newcst);
 
            if (costs_lt_p (&newcst, &mincst, speed))
              {
@@ -1901,9 +1947,9 @@ reload_cse_move2add (rtx first)
                          struct full_rtx_costs oldcst, newcst;
                          rtx tem = gen_rtx_PLUS (GET_MODE (reg), reg, new_src);
 
-                         get_full_rtx_cost (set, SET, &oldcst);
+                         get_full_set_rtx_cost (set, &oldcst);
                          SET_SRC (set) = tem;
-                         get_full_rtx_cost (tem, SET, &newcst);
+                         get_full_set_src_cost (tem, &newcst);
                          SET_SRC (set) = old_src;
                          costs_add_n_insns (&oldcst, 1);
 
@@ -2253,6 +2299,6 @@ struct rtl_opt_pass pass_postreload_cse =
   0,                                    /* properties_destroyed */
   0,                                    /* todo_flags_start */
   TODO_df_finish | TODO_verify_rtl_sharing |
-  TODO_dump_func                        /* todo_flags_finish */
+  0                                     /* todo_flags_finish */
  }
 };