xtensa: Improve shift operations more
[official-gcc.git] / gcc / config / xtensa / predicates.md
blobbcc83ada0ae36c76ac07c51c54d6e58bec29fa40
1 ;; Predicate definitions for Xtensa.
2 ;; Copyright (C) 2005-2022 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
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 3, or (at your option)
9 ;; any later version.
11 ;; GCC is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ;; GNU General Public License for more details.
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/>.
20 (define_predicate "add_operand"
21   (ior (and (match_code "const_int")
22             (match_test "xtensa_simm8 (INTVAL (op))
23                          || xtensa_simm8x256 (INTVAL (op))"))
24        (match_operand 0 "register_operand")))
26 (define_predicate "addsubx_operand"
27   (and (match_code "const_int")
28        (match_test "IN_RANGE (INTVAL (op), 1, 3)")))
30 (define_predicate "arith_operand"
31   (ior (and (match_code "const_int")
32             (match_test "xtensa_simm8 (INTVAL (op))"))
33        (match_operand 0 "register_operand")))
35 ;; Non-immediate operand excluding the constant pool.
36 (define_predicate "nonimmed_operand"
37   (ior (and (match_operand 0 "memory_operand")
38             (match_test "!constantpool_mem_p (op)"))
39        (match_operand 0 "register_operand")))
41 ;; Memory operand excluding the constant pool.
42 (define_predicate "mem_operand"
43   (and (match_operand 0 "memory_operand")
44        (match_test "!constantpool_mem_p (op)")))
46 ;; Memory operand in the constant pool.
47 (define_predicate "constantpool_operand"
48   (match_test "constantpool_mem_p (op)"))
50 (define_predicate "mask_operand"
51   (ior (and (match_code "const_int")
52             (match_test "xtensa_mask_immediate (INTVAL (op))"))
53        (match_operand 0 "register_operand")))
55 (define_predicate "extui_fldsz_operand"
56   (and (match_code "const_int")
57        (match_test "IN_RANGE (INTVAL (op), 1, 16)")))
59 (define_predicate "sext_operand"
60   (if_then_else (match_test "TARGET_SEXT")
61                 (match_operand 0 "nonimmed_operand")
62                 (match_operand 0 "mem_operand")))
64 (define_predicate "sext_fldsz_operand"
65   (and (match_code "const_int")
66        (match_test "IN_RANGE (INTVAL (op), 8, 23)")))
68 (define_predicate "lsbitnum_operand"
69   (and (match_code "const_int")
70        (match_test "BITS_BIG_ENDIAN
71                     ? (INTVAL (op) == BITS_PER_WORD - 1)
72                     : (INTVAL (op) == 0)")))
74 (define_predicate "branch_operand"
75   (ior (and (match_code "const_int")
76             (match_test "xtensa_b4const_or_zero (INTVAL (op))"))
77        (match_operand 0 "register_operand")))
79 (define_predicate "ubranch_operand"
80   (ior (and (match_code "const_int")
81             (match_test "xtensa_b4constu (INTVAL (op))"))
82        (match_operand 0 "register_operand")))
84 (define_predicate "call_insn_operand"
85   (match_code "const_int,const,symbol_ref,reg")
87   if ((GET_CODE (op) == REG)
88       && (op != arg_pointer_rtx)
89       && ((REGNO (op) < FRAME_POINTER_REGNUM)
90           || (REGNO (op) > LAST_VIRTUAL_REGISTER)))
91     return true;
93   if (CONSTANT_ADDRESS_P (op))
94     {
95       /* Direct calls only allowed to static functions with PIC.  */
96       if (flag_pic)
97         {
98           tree callee;
99           const char * callee_sec, * caller_sec;
101           if (GET_CODE (op) != SYMBOL_REF
102               || !SYMBOL_REF_LOCAL_P (op) || SYMBOL_REF_EXTERNAL_P (op))
103             return false;
105           /* Don't attempt a direct call if the callee is known to be in
106              a different section, since there's a good chance it will be
107              out of range.  */
109           if (flag_function_sections
110               || DECL_ONE_ONLY (current_function_decl))
111             return false;
112           caller_sec = DECL_SECTION_NAME (current_function_decl);
113           callee = SYMBOL_REF_DECL (op);
114           if (callee)
115             {
116               if (DECL_ONE_ONLY (callee))
117                 return false;
118               callee_sec = DECL_SECTION_NAME (callee);
119               if (((caller_sec == NULL) ^ (callee_sec == NULL))
120                   || (caller_sec != NULL
121                       && caller_sec != callee_sec))
122                 return false;
123             }
124           else if (caller_sec)
125             return false;
126         }
127       return true;
128     }
130   return false;
133 (define_predicate "move_operand"
134   (ior
135      (ior (match_operand 0 "register_operand")
136           (and (match_operand 0 "memory_operand")
137                (match_test "!constantpool_mem_p (op)
138                             || GET_MODE_SIZE (mode) % UNITS_PER_WORD == 0")))
139      (ior (and (match_code "const_int")
140                (match_test "GET_MODE_CLASS (mode) == MODE_INT
141                             && xtensa_simm12b (INTVAL (op))"))
142           (and (match_code "const_int,const_double,const,symbol_ref,label_ref")
143                (match_test "(TARGET_CONST16 || TARGET_AUTO_LITPOOLS)
144                             && CONSTANT_P (op)
145                             && GET_MODE_SIZE (mode) % UNITS_PER_WORD == 0")))))
147 ;; Accept the floating point constant 1 in the appropriate mode.
148 (define_predicate "const_float_1_operand"
149   (match_code "const_double")
151   return real_equal (CONST_DOUBLE_REAL_VALUE (op), &dconst1);
154 (define_predicate "fpmem_offset_operand"
155   (and (match_code "const_int")
156        (match_test "xtensa_mem_offset (INTVAL (op), SFmode)")))
158 (define_predicate "branch_operator"
159   (match_code "eq,ne,lt,ge"))
161 (define_predicate "ubranch_operator"
162   (match_code "ltu,geu"))
164 (define_predicate "boolean_operator"
165   (match_code "eq,ne"))
167 (define_predicate "logical_shift_operator"
168   (match_code "ashift,lshiftrt"))
170 (define_predicate "xtensa_cstoresi_operator"
171   (match_code "eq,ne,gt,ge,lt,le"))
173 (define_predicate "xtensa_shift_per_byte_operator"
174   (match_code "ashift,ashiftrt,lshiftrt"))
176 (define_predicate "tls_symbol_operand"
177   (and (match_code "symbol_ref")
178        (match_test "SYMBOL_REF_TLS_MODEL (op) != 0")))