OSDN Git Service

Merge basic-improvements-branch to trunk
[pf3gnuchains/gcc-fork.git] / gcc / recog.c
index 1028745..48d2915 100644 (file)
@@ -22,6 +22,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 
 #include "config.h"
 #include "system.h"
+#include "coretypes.h"
+#include "tm.h"
 #include "rtl.h"
 #include "tm_p.h"
 #include "insn-config.h"
@@ -191,7 +193,7 @@ static int num_changes = 0;
    an INSN, CALL_INSN, or JUMP_INSN, the insn will be re-recognized with
    the change in place.
 
-   IN_GROUP is non-zero if this is part of a group of changes that must be
+   IN_GROUP is nonzero if this is part of a group of changes that must be
    performed as a group.  In that case, the changes will be stored.  The
    function `apply_change_group' will validate and apply the changes.
 
@@ -308,6 +310,13 @@ insn_invalid_p (insn)
   return 0;
 }
 
+/* Return number of changes made and not validated yet.  */
+int
+num_changes_pending ()
+{
+  return num_changes;
+}
+
 /* Apply a group of changes previously issued with `validate_change'.
    Return 1 if all changes are valid, zero otherwise.  */
 
@@ -397,9 +406,6 @@ apply_change_group ()
       for (i = 0; i < num_changes; i++)
        if (changes[i].object
            && INSN_P (changes[i].object)
-           && basic_block_for_insn
-           && ((unsigned int)INSN_UID (changes[i].object)
-               < basic_block_for_insn->num_elements)
            && (bb = BLOCK_FOR_INSN (changes[i].object)))
          bb->flags |= BB_DIRTY;
 
@@ -518,10 +524,10 @@ validate_replace_rtx_1 (loc, from, to, object)
     {
     case PLUS:
       /* If we have a PLUS whose second operand is now a CONST_INT, use
-         plus_constant to try to simplify it.
+         simplify_gen_binary to try to simplify it.
          ??? We may want later to remove this, once simplification is
          separated from this function.  */
-      if (GET_CODE (XEXP (x, 1)) == CONST_INT)
+      if (GET_CODE (XEXP (x, 1)) == CONST_INT && XEXP (x, 1) == to)
        validate_change (object, loc,
                         simplify_gen_binary
                         (PLUS, GET_MODE (x), XEXP (x, 0), XEXP (x, 1)), 1);
@@ -674,11 +680,10 @@ validate_replace_src_1 (x, data)
 }
 
 /* Try replacing every occurrence of FROM in INSN with TO, avoiding
-   SET_DESTs.  After all changes have been made, validate by seeing if
-   INSN is still valid.  */
+   SET_DESTs.  */
 
-int
-validate_replace_src (from, to, insn)
+void
+validate_replace_src_group (from, to, insn)
      rtx from, to, insn;
 {
   struct validate_replace_src_data d;
@@ -687,6 +692,15 @@ validate_replace_src (from, to, insn)
   d.to = to;
   d.insn = insn;
   note_uses (&PATTERN (insn), validate_replace_src_1, &d);
+}
+
+/* Same as validate_repalace_src_group, but validate by seeing if
+   INSN is still valid.  */
+int
+validate_replace_src (from, to, insn)
+     rtx from, to, insn;
+{
+  validate_replace_src_group (from, to, insn);
   return apply_change_group ();
 }
 \f
@@ -844,7 +858,7 @@ find_single_use_1 (dest, loc)
    sequel.  If so, return a pointer to the innermost rtx expression in which
    it is used.
 
-   If PLOC is non-zero, *PLOC is set to the insn containing the single use.
+   If PLOC is nonzero, *PLOC is set to the insn containing the single use.
 
    This routine will return usually zero either before flow is called (because
    there will be no LOG_LINKS notes) or after reload (because the REG_DEAD
@@ -942,6 +956,7 @@ general_operand (op, mode)
     return 0;
 
   if (GET_CODE (op) == CONST_INT
+      && mode != VOIDmode
       && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
     return 0;
 
@@ -961,11 +976,13 @@ general_operand (op, mode)
 
   if (code == SUBREG)
     {
+      rtx sub = SUBREG_REG (op);
+
 #ifdef INSN_SCHEDULING
       /* On machines that have insn scheduling, we want all memory
         reference to be explicit, so outlaw paradoxical SUBREGs.  */
-      if (GET_CODE (SUBREG_REG (op)) == MEM
-         && GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))))
+      if (GET_CODE (sub) == MEM
+         && GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (sub)))
        return 0;
 #endif
       /* Avoid memories with nonzero SUBREG_BYTE, as offsetting the memory
@@ -975,10 +992,16 @@ general_operand (op, mode)
 
         ??? This is a kludge.  */
       if (!reload_completed && SUBREG_BYTE (op) != 0
-         && GET_CODE (SUBREG_REG (op)) == MEM)
+         && GET_CODE (sub) == MEM)
        return 0;
 
-      op = SUBREG_REG (op);
+      /* FLOAT_MODE subregs can't be paradoxical.  Combine will occasionally
+        create such rtl, and we must reject it.  */
+      if (GET_MODE_CLASS (GET_MODE (op)) == MODE_FLOAT
+         && GET_MODE_SIZE (GET_MODE (op)) > GET_MODE_SIZE (GET_MODE (sub)))
+       return 0;
+
+      op = sub;
       code = GET_CODE (op);
     }
 
@@ -1051,28 +1074,33 @@ register_operand (op, mode)
 
   if (GET_CODE (op) == SUBREG)
     {
+      rtx sub = SUBREG_REG (op);
+
       /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
         because it is guaranteed to be reloaded into one.
         Just make sure the MEM is valid in itself.
         (Ideally, (SUBREG (MEM)...) should not exist after reload,
         but currently it does result from (SUBREG (REG)...) where the
         reg went on the stack.)  */
-      if (! reload_completed && GET_CODE (SUBREG_REG (op)) == MEM)
+      if (! reload_completed && GET_CODE (sub) == MEM)
        return general_operand (op, mode);
 
-#ifdef CLASS_CANNOT_CHANGE_MODE
-      if (GET_CODE (SUBREG_REG (op)) == REG
-         && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER
-         && (TEST_HARD_REG_BIT
-             (reg_class_contents[(int) CLASS_CANNOT_CHANGE_MODE],
-              REGNO (SUBREG_REG (op))))
-         && CLASS_CANNOT_CHANGE_MODE_P (mode, GET_MODE (SUBREG_REG (op)))
-         && GET_MODE_CLASS (GET_MODE (SUBREG_REG (op))) != MODE_COMPLEX_INT
-         && GET_MODE_CLASS (GET_MODE (SUBREG_REG (op))) != MODE_COMPLEX_FLOAT)
+#ifdef CANNOT_CHANGE_MODE_CLASS
+      if (GET_CODE (sub) == REG
+         && REGNO (sub) < FIRST_PSEUDO_REGISTER
+         && REG_CANNOT_CHANGE_MODE_P (REGNO (sub), mode, GET_MODE (sub))
+         && GET_MODE_CLASS (GET_MODE (sub)) != MODE_COMPLEX_INT
+         && GET_MODE_CLASS (GET_MODE (sub)) != MODE_COMPLEX_FLOAT)
        return 0;
 #endif
 
-      op = SUBREG_REG (op);
+      /* FLOAT_MODE subregs can't be paradoxical.  Combine will occasionally
+        create such rtl, and we must reject it.  */
+      if (GET_MODE_CLASS (GET_MODE (op)) == MODE_FLOAT
+         && GET_MODE_SIZE (GET_MODE (op)) > GET_MODE_SIZE (GET_MODE (sub)))
+       return 0;
+
+      op = sub;
     }
 
   /* If we have an ADDRESSOF, consider it valid since it will be
@@ -1131,6 +1159,7 @@ immediate_operand (op, mode)
     return 0;
 
   if (GET_CODE (op) == CONST_INT
+      && mode != VOIDmode
       && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
     return 0;
 
@@ -1213,6 +1242,7 @@ nonmemory_operand (op, mode)
        return 0;
 
       if (GET_CODE (op) == CONST_INT
+         && mode != VOIDmode
          && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
        return 0;
 
@@ -1717,7 +1747,9 @@ asm_operand_ok (op, constraint)
 
        case 'E':
        case 'F':
-         if (GET_CODE (op) == CONST_DOUBLE)
+         if (GET_CODE (op) == CONST_DOUBLE
+             || (GET_CODE (op) == CONST_VECTOR
+                 && GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_FLOAT))
            return 1;
          break;
 
@@ -1818,6 +1850,18 @@ asm_operand_ok (op, constraint)
 #ifdef EXTRA_CONSTRAINT
          if (EXTRA_CONSTRAINT (op, c))
            return 1;
+         if (EXTRA_MEMORY_CONSTRAINT (c))
+           {
+             /* Every memory operand can be reloaded to fit.  */
+             if (memory_operand (op, VOIDmode))
+               return 1;
+           }
+         if (EXTRA_ADDRESS_CONSTRAINT (c))
+           {
+             /* Every address operand can be reloaded to fit.  */
+             if (address_operand (op, VOIDmode))
+               return 1;
+           }
 #endif
          break;
        }
@@ -2257,6 +2301,19 @@ preprocess_constraints ()
                  break;
 
                default:
+                 if (EXTRA_MEMORY_CONSTRAINT (c))
+                   {
+                     op_alt[j].memory_ok = 1;
+                     break;
+                   }
+                 if (EXTRA_ADDRESS_CONSTRAINT (c))
+                   {
+                     op_alt[j].is_address = 1;
+                     op_alt[j].class = reg_class_subunion[(int) op_alt[j].class]
+                       [(int) MODE_BASE_REG_CLASS (VOIDmode)];
+                     break;
+                   }
+
                  op_alt[j].class = reg_class_subunion[(int) op_alt[j].class][(int) REG_CLASS_FROM_LETTER ((unsigned char) c)];
                  break;
                }
@@ -2283,7 +2340,7 @@ preprocess_constraints ()
    This is used in final, just before printing the assembler code and by
    the routines that determine an insn's attribute.
 
-   If STRICT is a positive non-zero value, it means that we have been
+   If STRICT is a positive nonzero value, it means that we have been
    called after reload has been completed.  In that case, we must
    do all checks strictly.  If it is zero, it means that we have been called
    before reload has completed.  In that case, we first try to see if we can
@@ -2485,7 +2542,9 @@ constrain_operands (strict)
 
              case 'E':
              case 'F':
-               if (GET_CODE (op) == CONST_DOUBLE)
+               if (GET_CODE (op) == CONST_DOUBLE
+                   || (GET_CODE (op) == CONST_VECTOR
+                       && GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_FLOAT))
                  win = 1;
                break;
 
@@ -2568,6 +2627,28 @@ constrain_operands (strict)
 #ifdef EXTRA_CONSTRAINT
                  else if (EXTRA_CONSTRAINT (op, c))
                    win = 1;
+
+                 if (EXTRA_MEMORY_CONSTRAINT (c))
+                   {
+                     /* Every memory operand can be reloaded to fit.  */
+                     if (strict < 0 && GET_CODE (op) == MEM)
+                       win = 1;
+       
+                     /* Before reload, accept what reload can turn into mem.  */
+                     if (strict < 0 && CONSTANT_P (op))
+                       win = 1;
+
+                     /* During reload, accept a pseudo  */
+                     if (reload_in_progress && GET_CODE (op) == REG
+                         && REGNO (op) >= FIRST_PSEUDO_REGISTER)
+                       win = 1;
+                   }
+                 if (EXTRA_ADDRESS_CONSTRAINT (c))
+                   {
+                     /* Every address operand can be reloaded to fit.  */
+                     if (strict < 0)
+                       win = 1;
+                   }
 #endif
                  break;
                }
@@ -3068,7 +3149,7 @@ peephole2_optimize (dump_file)
                     cfg-related call notes.  */
                  for (i = 0; i <= match_len; ++i)
                    {
-                     int j, k;
+                     int j;
                      rtx old_insn, new_insn, note;
 
                      j = i + peep2_current;
@@ -3079,20 +3160,15 @@ peephole2_optimize (dump_file)
                        continue;
                      was_call = true;
 
-                     new_insn = NULL_RTX;
-                     if (GET_CODE (try) == SEQUENCE)
-                       for (k = XVECLEN (try, 0) - 1; k >= 0; k--)
-                         {
-                           rtx x = XVECEXP (try, 0, k);
-                           if (GET_CODE (x) == CALL_INSN)
-                             {
-                               new_insn = x;
-                               break;
-                             }
-                         }
-                     else if (GET_CODE (try) == CALL_INSN)
-                       new_insn = try;
-                     if (! new_insn)
+                     new_insn = try;
+                     while (new_insn != NULL_RTX)
+                       {
+                         if (GET_CODE (new_insn) == CALL_INSN)
+                           break;
+                         new_insn = NEXT_INSN (new_insn);
+                       }
+
+                     if (new_insn == NULL_RTX)
                        abort ();
 
                      CALL_INSN_FUNCTION_USAGE (new_insn)
@@ -3136,7 +3212,8 @@ peephole2_optimize (dump_file)
                                        REG_EH_REGION, NULL_RTX);
 
                  /* Replace the old sequence with the new.  */
-                 try = emit_insn_after (try, peep2_insn_data[i].insn);
+                 try = emit_insn_after_scope (try, peep2_insn_data[i].insn,
+                                              INSN_SCOPE (peep2_insn_data[i].insn));
                  before_try = PREV_INSN (insn);
                  delete_insn_chain (insn, peep2_insn_data[i].insn);