OSDN Git Service

2007-04-16 H.J. Lu <hongjiu.lu@intel.com>
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / predicates.md
index 3a8eee2..efa5c98 100644 (file)
@@ -1,5 +1,5 @@
 ;; Predicate definitions for IA-32 and x86-64.
-;; Copyright (C) 2004 Free Software Foundation, Inc.
+;; Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
 ;;
 ;; This file is part of GCC.
 ;;
@@ -15,8 +15,8 @@
 ;;
 ;; You should have received a copy of the GNU General Public License
 ;; along with GCC; see the file COPYING.  If not, write to
-;; the Free Software Foundation, 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;; Return nonzero if OP is either a i387 or SSE fp register.
 (define_predicate "any_fp_register_operand"
   return ANY_QI_REG_P (op);
 })
 
-;; Return true if op is a NON_Q_REGS class register.
-(define_predicate "non_q_regs_operand"
-  (match_operand 0 "register_operand")
-{
-  if (GET_CODE (op) == SUBREG)
-    op = SUBREG_REG (op);
-  return NON_QI_REG_P (op);
-})
-
 ;; Match an SI or HImode register for a zero_extract.
 (define_special_predicate "ext_register_operand"
   (match_operand 0 "register_operand")
   return REGNO (op) > LAST_VIRTUAL_REGISTER || REGNO (op) < 4;
 })
 
+;; Return true if op is the AX register.
+(define_predicate "ax_reg_operand"
+  (and (match_code "reg")
+       (match_test "REGNO (op) == 0")))
+
 ;; Return true if op is the flags register.
 (define_predicate "flags_reg_operand"
   (and (match_code "reg")
         library.  Don't count TLS SYMBOL_REFs here, since they should fit
         only if inside of UNSPEC handled below.  */
       /* TLS symbols are not constant.  */
-      if (tls_symbolic_operand (op, Pmode))
+      if (SYMBOL_REF_TLS_MODEL (op))
        return false;
-      return (ix86_cmodel == CM_SMALL || ix86_cmodel == CM_KERNEL);
+      return (ix86_cmodel == CM_SMALL || ix86_cmodel == CM_KERNEL
+             || (ix86_cmodel == CM_MEDIUM && !SYMBOL_REF_FAR_ADDR_P (op)));
 
     case LABEL_REF:
       /* For certain code models, the code is near as well.  */
 
          if (ix86_cmodel == CM_LARGE)
            return 0;
-         if (GET_CODE (op2) != CONST_INT)
+         if (!CONST_INT_P (op2))
            return 0;
          offset = trunc_int_for_mode (INTVAL (op2), DImode);
          switch (GET_CODE (op1))
            {
            case SYMBOL_REF:
+             /* TLS symbols are not constant.  */
+             if (SYMBOL_REF_TLS_MODEL (op1))
+               return 0;
              /* For CM_SMALL assume that latest object is 16MB before
                 end of 31bits boundary.  We may also accept pretty
                 large negative constants knowing that all objects are
                 in the positive half of address space.  */
-             if (ix86_cmodel == CM_SMALL
+             if ((ix86_cmodel == CM_SMALL
+                  || (ix86_cmodel == CM_MEDIUM
+                      && !SYMBOL_REF_FAR_ADDR_P (op1)))
                  && offset < 16*1024*1024
                  && trunc_int_for_mode (offset, SImode) == offset)
                return 1;
       break;
 
       default:
-       abort ();
+       gcc_unreachable ();
     }
 
   return 0;
     case SYMBOL_REF:
       /* For certain code models, the symbolic references are known to fit.  */
       /* TLS symbols are not constant.  */
-      if (tls_symbolic_operand (op, Pmode))
+      if (SYMBOL_REF_TLS_MODEL (op))
        return false;
-      return ix86_cmodel == CM_SMALL;
+      return (ix86_cmodel == CM_SMALL
+             || (ix86_cmodel == CM_MEDIUM
+                 && !SYMBOL_REF_FAR_ADDR_P (op)));
 
     case LABEL_REF:
       /* For certain code models, the code is near as well.  */
          switch (GET_CODE (op1))
            {
            case SYMBOL_REF:
+             /* TLS symbols are not constant.  */
+             if (SYMBOL_REF_TLS_MODEL (op1))
+               return 0;
              /* For small code model we may accept pretty large positive
                 offsets, since one bit is available for free.  Negative
                 offsets are limited by the size of NULL pointer area
                 specified by the ABI.  */
-             if (ix86_cmodel == CM_SMALL
-                 && GET_CODE (op2) == CONST_INT
+             if ((ix86_cmodel == CM_SMALL
+                  || (ix86_cmodel == CM_MEDIUM
+                      && !SYMBOL_REF_FAR_ADDR_P (op1)))
+                 && CONST_INT_P (op2)
                  && trunc_int_for_mode (INTVAL (op2), DImode) > -0x10000
                  && trunc_int_for_mode (INTVAL (op2), SImode) == INTVAL (op2))
                return 1;
              /* These conditions are similar to SYMBOL_REF ones, just the
                 constraints for code models differ.  */
              if ((ix86_cmodel == CM_SMALL || ix86_cmodel == CM_MEDIUM)
-                 && GET_CODE (op2) == CONST_INT
+                 && CONST_INT_P (op2)
                  && trunc_int_for_mode (INTVAL (op2), DImode) > -0x10000
                  && trunc_int_for_mode (INTVAL (op2), SImode) == INTVAL (op2))
                return 1;
       break;
 
     default:
-      abort ();
+      gcc_unreachable ();
     }
   return 0;
 })
              (match_operand 0 "x86_64_zext_immediate_operand")))
     (match_operand 0 "nonmemory_operand")))
 
+;; Return true when operand is PIC expression that can be computed by lea
+;; operation.
+(define_predicate "pic_32bit_operand"
+  (match_code "const,symbol_ref,label_ref")
+{
+  if (!flag_pic)
+    return 0;
+  /* Rule out relocations that translate into 64bit constants.  */
+  if (TARGET_64BIT && GET_CODE (op) == CONST)
+    {
+      op = XEXP (op, 0);
+      if (GET_CODE (op) == PLUS && CONST_INT_P (XEXP (op, 1)))
+       op = XEXP (op, 0);
+      if (GET_CODE (op) == UNSPEC
+         && (XINT (op, 1) == UNSPEC_GOTOFF
+             || XINT (op, 1) == UNSPEC_GOT))
+       return 0;
+    }
+  return symbolic_operand (op, mode);
+})
+
+
 ;; Return nonzero if OP is nonmemory operand acceptable by movabs patterns.
 (define_predicate "x86_64_movabs_operand"
   (if_then_else (match_test "!TARGET_64BIT || !flag_pic")
         (and (match_operand 0 "const_double_operand")
              (match_test "GET_MODE_SIZE (mode) <= 8")))))
 
-;; Return nonzero if OP is CONST_INT >= 1 and <= 31 (a valid operand
-;; for shift & compare patterns, as shifting by 0 does not change flags).
-(define_predicate "const_int_1_31_operand"
-  (and (match_code "const_int")
-       (match_test "INTVAL (op) >= 1 && INTVAL (op) <= 31")))
-
 ;; Returns nonzero if OP is either a symbol reference or a sum of a symbol
 ;; reference and a constant.
 (define_predicate "symbolic_operand"
                  || XINT (op, 1) == UNSPEC_GOTPCREL)))
        return 1;
       if (GET_CODE (op) != PLUS
-         || GET_CODE (XEXP (op, 1)) != CONST_INT)
+         || !CONST_INT_P (XEXP (op, 1)))
        return 0;
 
       op = XEXP (op, 0);
       return 0;
 
     default:
-      abort ();
+      gcc_unreachable ();
     }
 })
 
       if (GET_CODE (op) == UNSPEC)
        return 1;
       if (GET_CODE (op) != PLUS
-         || GET_CODE (XEXP (op, 1)) != CONST_INT)
+         || !CONST_INT_P (XEXP (op, 1)))
        return 0;
       op = XEXP (op, 0);
       if (GET_CODE (op) == UNSPEC)
 {
   if (GET_CODE (op) == CONST
       && GET_CODE (XEXP (op, 0)) == PLUS
-      && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT)
+      && CONST_INT_P (XEXP (XEXP (op, 0), 1)))
     op = XEXP (XEXP (op, 0), 0);
 
   if (GET_CODE (op) == LABEL_REF)
   if (GET_CODE (op) != SYMBOL_REF)
     return 0;
 
+  if (SYMBOL_REF_TLS_MODEL (op) != 0)
+    return 0;
+
   if (SYMBOL_REF_LOCAL_P (op))
     return 1;
 
   return 0;
 })
 
+;; Test for a legitimate @GOTOFF operand.
+;;
+;; VxWorks does not impose a fixed gap between segments; the run-time
+;; gap can be different from the object-file gap.  We therefore can't
+;; use @GOTOFF unless we are absolutely sure that the symbol is in the
+;; same segment as the GOT.  Unfortunately, the flexibility of linker
+;; scripts means that we can't be sure of that in general, so assume
+;; that @GOTOFF is never valid on VxWorks.
+(define_predicate "gotoff_operand"
+  (and (match_test "!TARGET_VXWORKS_RTP")
+       (match_operand 0 "local_symbolic_operand")))
+
 ;; Test for various thread-local symbols.
 (define_predicate "tls_symbolic_operand"
   (and (match_code "symbol_ref")
        (match_test "SYMBOL_REF_TLS_MODEL (op) != 0")))
 
-(define_predicate "global_dynamic_symbolic_operand"
-  (and (match_code "symbol_ref")
-       (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_GLOBAL_DYNAMIC")))
-
-(define_predicate "local_dynamic_symbolic_operand"
+(define_predicate "tls_modbase_operand"
   (and (match_code "symbol_ref")
-       (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_DYNAMIC")))
+       (match_test "op == ix86_tls_module_base ()")))
 
-(define_predicate "initial_exec_symbolic_operand"
-  (and (match_code "symbol_ref")
-       (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_INITIAL_EXEC")))
-
-(define_predicate "local_exec_symbolic_operand"
-  (and (match_code "symbol_ref")
-       (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_EXEC")))
+(define_predicate "tp_or_register_operand"
+  (ior (match_operand 0 "register_operand")
+       (and (match_code "unspec")
+           (match_test "XINT (op, 1) == UNSPEC_TP"))))
 
 ;; Test for a pc-relative call operand
 (define_predicate "constant_call_address_operand"
-  (ior (match_code "symbol_ref")
-       (match_operand 0 "local_symbolic_operand")))
+  (match_code "symbol_ref")
+{
+  if (ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC)
+    return false;
+  if (TARGET_DLLIMPORT_DECL_ATTRIBUTES && SYMBOL_REF_DLLIMPORT_P (op))
+    return false;
+  return true;
+})
 
 ;; True for any non-virtual or eliminable register.  Used in places where
 ;; instantiation of such a register may cause the pattern to not be recognized.
     op = SUBREG_REG (op);
   return !(op == arg_pointer_rtx
           || op == frame_pointer_rtx
-          || (REGNO (op) >= FIRST_PSEUDO_REGISTER
-              && REGNO (op) <= LAST_VIRTUAL_REGISTER));
+          || IN_RANGE (REGNO (op),
+                       FIRST_PSEUDO_REGISTER, LAST_VIRTUAL_REGISTER));
 })
 
 ;; Similarly, but include the stack pointer.  This is used to prevent esp
        (ior (match_operand 0 "register_no_elim_operand")
            (match_operand 0 "memory_operand"))))
 
-;; Simiarly, but for tail calls, in which we cannot allow memory references.
+;; Similarly, but for tail calls, in which we cannot allow memory references.
 (define_predicate "sibcall_insn_operand"
   (ior (match_operand 0 "constant_call_address_operand")
        (match_operand 0 "register_no_elim_operand")))
 
 ;; Match exactly zero.
 (define_predicate "const0_operand"
-  (and (match_code "const_int,const_double,const_vector")
-       (match_test "op == CONST0_RTX (mode)")))
+  (match_code "const_int,const_double,const_vector")
+{
+  if (mode == VOIDmode)
+    mode = GET_MODE (op);
+  return op == CONST0_RTX (mode);
+})
 
 ;; Match exactly one.
 (define_predicate "const1_operand"
   (and (match_code "const_int")
        (match_test "op == const1_rtx")))
 
+;; Match exactly eight.
+(define_predicate "const8_operand"
+  (and (match_code "const_int")
+       (match_test "INTVAL (op) == 8")))
+
 ;; Match 2, 4, or 8.  Used for leal multiplicands.
 (define_predicate "const248_operand"
   (match_code "const_int")
   return i == 2 || i == 4 || i == 8;
 })
 
+;; Match 0 or 1.
+(define_predicate "const_0_to_1_operand"
+  (and (match_code "const_int")
+       (match_test "op == const0_rtx || op == const1_rtx")))
+
 ;; Match 0 to 3.
 (define_predicate "const_0_to_3_operand"
   (and (match_code "const_int")
-       (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 3")))
+       (match_test "IN_RANGE (INTVAL (op), 0, 3)")))
 
 ;; Match 0 to 7.
 (define_predicate "const_0_to_7_operand"
   (and (match_code "const_int")
-       (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 7")))
+       (match_test "IN_RANGE (INTVAL (op), 0, 7)")))
 
 ;; Match 0 to 15.
 (define_predicate "const_0_to_15_operand"
   (and (match_code "const_int")
-       (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 15")))
+       (match_test "IN_RANGE (INTVAL (op), 0, 15)")))
+
+;; Match 0 to 63.
+(define_predicate "const_0_to_63_operand"
+  (and (match_code "const_int")
+       (match_test "IN_RANGE (INTVAL (op), 0, 63)")))
 
 ;; Match 0 to 255.
 (define_predicate "const_0_to_255_operand"
   (and (match_code "const_int")
-       (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 255")))
+       (match_test "IN_RANGE (INTVAL (op), 0, 255)")))
+
+;; Match (0 to 255) * 8
+(define_predicate "const_0_to_255_mul_8_operand"
+  (match_code "const_int")
+{
+  unsigned HOST_WIDE_INT val = INTVAL (op);
+  return val <= 255*8 && val % 8 == 0;
+})
+
+;; Return nonzero if OP is CONST_INT >= 1 and <= 31 (a valid operand
+;; for shift & compare patterns, as shifting by 0 does not change flags).
+(define_predicate "const_1_to_31_operand"
+  (and (match_code "const_int")
+       (match_test "IN_RANGE (INTVAL (op), 1, 31)")))
+
+;; Match 2 or 3.
+(define_predicate "const_2_to_3_operand"
+  (and (match_code "const_int")
+       (match_test "IN_RANGE (INTVAL (op), 2, 3)")))
+
+;; Match 4 to 7.
+(define_predicate "const_4_to_7_operand"
+  (and (match_code "const_int")
+       (match_test "IN_RANGE (INTVAL (op), 4, 7)")))
+
+;; Match exactly one bit in 4-bit mask.
+(define_predicate "const_pow2_1_to_8_operand"
+  (match_code "const_int")
+{
+  unsigned int log = exact_log2 (INTVAL (op));
+  return log <= 3;
+})
+
+;; Match exactly one bit in 8-bit mask.
+(define_predicate "const_pow2_1_to_128_operand"
+  (match_code "const_int")
+{
+  unsigned int log = exact_log2 (INTVAL (op));
+  return log <= 7;
+})
 
 ;; True if this is a constant appropriate for an increment or decrement.
 (define_predicate "incdec_operand"
 {
   /* On Pentium4, the inc and dec operations causes extra dependency on flag
      registers, since carry flag is not set.  */
-  if ((TARGET_PENTIUM4 || TARGET_NOCONA) && !optimize_size)
+  if (!TARGET_USE_INCDEC && !optimize_size)
     return 0;
   return op == const1_rtx || op == constm1_rtx;
 })
   return 1;
 })
 
-;; Return 1 when OP is operand acceptable for standard SSE move.
+/* Return true if operand is a vector constant that is all ones. */
+(define_predicate "vector_all_ones_operand"
+  (match_code "const_vector")
+{
+  int nunits = GET_MODE_NUNITS (mode);
+
+  if (GET_CODE (op) == CONST_VECTOR
+      && CONST_VECTOR_NUNITS (op) == nunits)
+    {
+      int i;
+      for (i = 0; i < nunits; ++i)
+        {
+          rtx x = CONST_VECTOR_ELT (op, i);
+          if (x != constm1_rtx)
+            return 0;
+        }
+      return 1;
+    }
+
+  return 0;
+})
+
+; Return 1 when OP is operand acceptable for standard SSE move.
 (define_predicate "vector_move_operand"
   (ior (match_operand 0 "nonimmediate_operand")
        (match_operand 0 "const0_operand")))
 
+;; Return 1 when OP is nonimmediate or standard SSE constant.
+(define_predicate "nonimmediate_or_sse_const_operand"
+  (match_operand 0 "general_operand")
+{
+  if (nonimmediate_operand (op, mode))
+    return 1;
+  if (standard_sse_constant_p (op) > 0)
+    return 1;
+  return 0;
+})
+
+;; Return true if OP is a register or a zero.
+(define_predicate "reg_or_0_operand"
+  (ior (match_operand 0 "register_operand")
+       (match_operand 0 "const0_operand")))
+
 ;; Return true if op if a valid address, and does not contain
 ;; a segment override.
 (define_special_predicate "no_seg_address_operand"
   (match_operand 0 "address_operand")
 {
   struct ix86_address parts;
-  if (! ix86_decompose_address (op, &parts))
-    abort ();
+  int ok;
+
+  ok = ix86_decompose_address (op, &parts);
+  gcc_assert (ok);
   return parts.seg == SEG_DEFAULT;
 })
 
-;; Return nonzero if the rtx is known aligned.
+;; Return nonzero if the rtx is known to be at least 32 bits aligned.
 (define_predicate "aligned_operand"
   (match_operand 0 "general_operand")
 {
   struct ix86_address parts;
+  int ok;
 
   /* Registers and immediate operands are always "aligned".  */
   if (GET_CODE (op) != MEM)
     return 1;
 
+  /* All patterns using aligned_operand on memory operands ends up
+     in promoting memory operand to 64bit and thus causing memory mismatch.  */
+  if (TARGET_MEMORY_MISMATCH_STALL && !optimize_size)
+    return 0;
+
   /* Don't even try to do any aligned optimizations with volatiles.  */
   if (MEM_VOLATILE_P (op))
     return 0;
+
+  if (MEM_ALIGN (op) >= 32)
+    return 1;
+
   op = XEXP (op, 0);
 
   /* Pushes and pops are only valid on the stack pointer.  */
     return 1;
 
   /* Decode the address.  */
-  if (!ix86_decompose_address (op, &parts))
-    abort ();
+  ok = ix86_decompose_address (op, &parts);
+  gcc_assert (ok);
 
   /* Look for some component that isn't known to be aligned.  */
   if (parts.index)
     }
   if (parts.disp)
     {
-      if (GET_CODE (parts.disp) != CONST_INT
+      if (!CONST_INT_P (parts.disp)
          || (INTVAL (parts.disp) & 3) != 0)
        return 0;
     }
   (match_operand 0 "memory_operand")
 {
   struct ix86_address parts;
-  if (!ix86_decompose_address (XEXP (op, 0), &parts))
-    abort ();
+  int ok;
+
+  ok = ix86_decompose_address (XEXP (op, 0), &parts);
+  gcc_assert (ok);
+  return parts.disp != NULL_RTX;
+})
+
+;; Returns 1 if OP is memory operand with a displacement only.
+(define_predicate "memory_displacement_only_operand"
+  (match_operand 0 "memory_operand")
+{
+  struct ix86_address parts;
+  int ok;
+
+  ok = ix86_decompose_address (XEXP (op, 0), &parts);
+  gcc_assert (ok);
+
+  if (parts.base || parts.index)
+    return 0;
+
   return parts.disp != NULL_RTX;
 })
 
 ;; predicate.
 
 (define_special_predicate "sse_comparison_operator"
-  (ior (match_code "eq,lt,le,unordered,ne,unge,ungt,ordered")
-       (and (match_code "uneq,unlt,unle,ltgt,ge,gt")
-           (match_code "!TARGET_IEEE_FP"))))
+  (match_code "eq,lt,le,unordered,ne,unge,ungt,ordered"))
 
 ;; Return 1 if OP is a valid comparison operator in valid mode.
 (define_predicate "ix86_comparison_operator"
   enum machine_mode inmode = GET_MODE (XEXP (op, 0));
   enum rtx_code code = GET_CODE (op);
 
-  if (GET_CODE (XEXP (op, 0)) != REG
+  if (!REG_P (XEXP (op, 0))
       || REGNO (XEXP (op, 0)) != FLAGS_REG
       || XEXP (op, 1) != const0_rtx)
     return 0;
 
 ;; Return true for ARITHMETIC_P.
 (define_predicate "arith_or_logical_operator"
-  (match_code "PLUS,MULT,AND,IOR,XOR,SMIN,SMAX,UMIN,UMAX,COMPARE,MINUS,DIV,
-              MOD,UDIV,UMOD,ASHIFT,ROTATE,ASHIFTRT,LSHIFTRT,ROTATERT"))
+  (match_code "plus,mult,and,ior,xor,smin,smax,umin,umax,compare,minus,div,
+              mod,udiv,umod,ashift,rotate,ashiftrt,lshiftrt,rotatert"))
 
 ;; Return 1 if OP is a binary operator that can be promoted to wider mode.
-;; Modern CPUs have same latency for HImode and SImode multiply,
-;; but 386 and 486 do HImode multiply faster.  */
 (define_predicate "promotable_binary_operator"
   (ior (match_code "plus,and,ior,xor,ashift")
        (and (match_code "mult")
-           (match_test "ix86_tune > PROCESSOR_I486"))))
+           (match_test "TARGET_TUNE_PROMOTE_HIMODE_IMUL"))))
 
 ;; To avoid problems when jump re-emits comparisons like testqi_ext_ccno_0,
 ;; re-recognize the operand to avoid a copy_to_mode_reg that will fail.
 ;; ??? It seems likely that this will only work because cmpsi is an
 ;; expander, and no actual insns use this.
 
-(define_predicate "cmpsi_operand_1"
-  (match_code "and")
-{
-  return (GET_MODE (op) == SImode
-         && GET_CODE (XEXP (op, 0)) == ZERO_EXTRACT
-         && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
-         && GET_CODE (XEXP (XEXP (op, 0), 2)) == CONST_INT
-         && INTVAL (XEXP (XEXP (op, 0), 1)) == 8
-         && INTVAL (XEXP (XEXP (op, 0), 2)) == 8
-         && GET_CODE (XEXP (op, 1)) == CONST_INT);
-})
-
 (define_predicate "cmpsi_operand"
   (ior (match_operand 0 "nonimmediate_operand")
-       (match_operand 0 "cmpsi_operand_1")))
+       (and (match_code "and")
+           (match_code "zero_extract" "0")
+           (match_code "const_int"    "1")
+           (match_code "const_int"    "01")
+           (match_code "const_int"    "02")
+           (match_test "INTVAL (XEXP (XEXP (op, 0), 1)) == 8")
+           (match_test "INTVAL (XEXP (XEXP (op, 0), 2)) == 8")
+       )))
 
 (define_predicate "compare_operator"
   (match_code "compare"))
+
+(define_predicate "absneg_operator"
+  (match_code "abs,neg"))