annotate gcc/config/riscv/predicates.md @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ;; Predicate description for RISC-V target.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 ;; Copyright (C) 2011-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 ;; Contributed by Andrew Waterman (andrew@sifive.com).
kono
parents:
diff changeset
4 ;; Based on MIPS target for GNU compiler.
kono
parents:
diff changeset
5 ;;
kono
parents:
diff changeset
6 ;; This file is part of GCC.
kono
parents:
diff changeset
7 ;;
kono
parents:
diff changeset
8 ;; GCC is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
9 ;; it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
10 ;; the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
11 ;; any later version.
kono
parents:
diff changeset
12 ;;
kono
parents:
diff changeset
13 ;; GCC is distributed in the hope that it will be useful,
kono
parents:
diff changeset
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
16 ;; GNU General Public License for more details.
kono
parents:
diff changeset
17 ;;
kono
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
19 ;; along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
20 ;; <http://www.gnu.org/licenses/>.
kono
parents:
diff changeset
21
kono
parents:
diff changeset
22 (define_predicate "const_arith_operand"
kono
parents:
diff changeset
23 (and (match_code "const_int")
kono
parents:
diff changeset
24 (match_test "SMALL_OPERAND (INTVAL (op))")))
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 (define_predicate "arith_operand"
kono
parents:
diff changeset
27 (ior (match_operand 0 "const_arith_operand")
kono
parents:
diff changeset
28 (match_operand 0 "register_operand")))
kono
parents:
diff changeset
29
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
30 (define_predicate "lui_operand"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
31 (and (match_code "const_int")
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
32 (match_test "LUI_OPERAND (INTVAL (op))")))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
33
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
34 (define_predicate "sfb_alu_operand"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
35 (ior (match_operand 0 "arith_operand")
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
36 (match_operand 0 "lui_operand")))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
37
111
kono
parents:
diff changeset
38 (define_predicate "const_csr_operand"
kono
parents:
diff changeset
39 (and (match_code "const_int")
kono
parents:
diff changeset
40 (match_test "IN_RANGE (INTVAL (op), 0, 31)")))
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 (define_predicate "csr_operand"
kono
parents:
diff changeset
43 (ior (match_operand 0 "const_csr_operand")
kono
parents:
diff changeset
44 (match_operand 0 "register_operand")))
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 (define_predicate "sle_operand"
kono
parents:
diff changeset
47 (and (match_code "const_int")
kono
parents:
diff changeset
48 (match_test "SMALL_OPERAND (INTVAL (op) + 1)")))
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 (define_predicate "sleu_operand"
kono
parents:
diff changeset
51 (and (match_operand 0 "sle_operand")
kono
parents:
diff changeset
52 (match_test "INTVAL (op) + 1 != 0")))
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 (define_predicate "const_0_operand"
kono
parents:
diff changeset
55 (and (match_code "const_int,const_wide_int,const_double,const_vector")
kono
parents:
diff changeset
56 (match_test "op == CONST0_RTX (GET_MODE (op))")))
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 (define_predicate "reg_or_0_operand"
kono
parents:
diff changeset
59 (ior (match_operand 0 "const_0_operand")
kono
parents:
diff changeset
60 (match_operand 0 "register_operand")))
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 ;; Only use branch-on-bit sequences when the mask is not an ANDI immediate.
kono
parents:
diff changeset
63 (define_predicate "branch_on_bit_operand"
kono
parents:
diff changeset
64 (and (match_code "const_int")
kono
parents:
diff changeset
65 (match_test "INTVAL (op) >= IMM_BITS - 1")))
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 ;; A legitimate CONST_INT operand that takes more than one instruction
kono
parents:
diff changeset
68 ;; to load.
kono
parents:
diff changeset
69 (define_predicate "splittable_const_int_operand"
kono
parents:
diff changeset
70 (match_code "const_int")
kono
parents:
diff changeset
71 {
kono
parents:
diff changeset
72 /* Don't handle multi-word moves this way; we don't want to introduce
kono
parents:
diff changeset
73 the individual word-mode moves until after reload. */
kono
parents:
diff changeset
74 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
kono
parents:
diff changeset
75 return false;
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 /* Otherwise check whether the constant can be loaded in a single
kono
parents:
diff changeset
78 instruction. */
kono
parents:
diff changeset
79 return !LUI_OPERAND (INTVAL (op)) && !SMALL_OPERAND (INTVAL (op));
kono
parents:
diff changeset
80 })
kono
parents:
diff changeset
81
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
82 (define_predicate "p2m1_shift_operand"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
83 (match_code "const_int")
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
84 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
85 int val = exact_log2 (INTVAL (op) + 1);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
86 if (val < 12)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
87 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
88 return true;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
89 })
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
90
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
91 (define_predicate "high_mask_shift_operand"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
92 (match_code "const_int")
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
93 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
94 int val1 = clz_hwi (~ INTVAL (op));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
95 int val0 = ctz_hwi (INTVAL (op));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
96 if ((val0 + val1 == BITS_PER_WORD)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
97 && val0 > 31 && val0 < 64)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
98 return true;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
99 return false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
100 })
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
101
111
kono
parents:
diff changeset
102 (define_predicate "move_operand"
kono
parents:
diff changeset
103 (match_operand 0 "general_operand")
kono
parents:
diff changeset
104 {
kono
parents:
diff changeset
105 enum riscv_symbol_type symbol_type;
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 /* The thinking here is as follows:
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 (1) The move expanders should split complex load sequences into
kono
parents:
diff changeset
110 individual instructions. Those individual instructions can
kono
parents:
diff changeset
111 then be optimized by all rtl passes.
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 (2) The target of pre-reload load sequences should not be used
kono
parents:
diff changeset
114 to store temporary results. If the target register is only
kono
parents:
diff changeset
115 assigned one value, reload can rematerialize that value
kono
parents:
diff changeset
116 on demand, rather than spill it to the stack.
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 (3) If we allowed pre-reload passes like combine and cse to recreate
kono
parents:
diff changeset
119 complex load sequences, we would want to be able to split the
kono
parents:
diff changeset
120 sequences before reload as well, so that the pre-reload scheduler
kono
parents:
diff changeset
121 can see the individual instructions. This falls foul of (2);
kono
parents:
diff changeset
122 the splitter would be forced to reuse the target register for
kono
parents:
diff changeset
123 intermediate results.
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 (4) We want to define complex load splitters for combine. These
kono
parents:
diff changeset
126 splitters can request a temporary scratch register, which avoids
kono
parents:
diff changeset
127 the problem in (2). They allow things like:
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 (set (reg T1) (high SYM))
kono
parents:
diff changeset
130 (set (reg T2) (low (reg T1) SYM))
kono
parents:
diff changeset
131 (set (reg X) (plus (reg T2) (const_int OFFSET)))
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 to be combined into:
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 (set (reg T3) (high SYM+OFFSET))
kono
parents:
diff changeset
136 (set (reg X) (lo_sum (reg T3) SYM+OFFSET))
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 if T2 is only used this once. */
kono
parents:
diff changeset
139 switch (GET_CODE (op))
kono
parents:
diff changeset
140 {
kono
parents:
diff changeset
141 case CONST_INT:
kono
parents:
diff changeset
142 return !splittable_const_int_operand (op, mode);
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 case CONST:
kono
parents:
diff changeset
145 case SYMBOL_REF:
kono
parents:
diff changeset
146 case LABEL_REF:
kono
parents:
diff changeset
147 return riscv_symbolic_constant_p (op, &symbol_type)
kono
parents:
diff changeset
148 && !riscv_split_symbol_type (symbol_type);
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 case HIGH:
kono
parents:
diff changeset
151 op = XEXP (op, 0);
kono
parents:
diff changeset
152 return riscv_symbolic_constant_p (op, &symbol_type)
kono
parents:
diff changeset
153 && riscv_split_symbol_type (symbol_type)
kono
parents:
diff changeset
154 && symbol_type != SYMBOL_PCREL;
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 default:
kono
parents:
diff changeset
157 return true;
kono
parents:
diff changeset
158 }
kono
parents:
diff changeset
159 })
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 (define_predicate "symbolic_operand"
kono
parents:
diff changeset
162 (match_code "const,symbol_ref,label_ref")
kono
parents:
diff changeset
163 {
kono
parents:
diff changeset
164 enum riscv_symbol_type type;
kono
parents:
diff changeset
165 return riscv_symbolic_constant_p (op, &type);
kono
parents:
diff changeset
166 })
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 (define_predicate "absolute_symbolic_operand"
kono
parents:
diff changeset
169 (match_code "const,symbol_ref,label_ref")
kono
parents:
diff changeset
170 {
kono
parents:
diff changeset
171 enum riscv_symbol_type type;
kono
parents:
diff changeset
172 return (riscv_symbolic_constant_p (op, &type)
kono
parents:
diff changeset
173 && (type == SYMBOL_ABSOLUTE || type == SYMBOL_PCREL));
kono
parents:
diff changeset
174 })
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 (define_predicate "plt_symbolic_operand"
kono
parents:
diff changeset
177 (match_code "const,symbol_ref,label_ref")
kono
parents:
diff changeset
178 {
kono
parents:
diff changeset
179 enum riscv_symbol_type type;
kono
parents:
diff changeset
180 return (riscv_symbolic_constant_p (op, &type)
kono
parents:
diff changeset
181 && type == SYMBOL_GOT_DISP && !SYMBOL_REF_WEAK (op) && TARGET_PLT);
kono
parents:
diff changeset
182 })
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 (define_predicate "call_insn_operand"
kono
parents:
diff changeset
185 (ior (match_operand 0 "absolute_symbolic_operand")
kono
parents:
diff changeset
186 (match_operand 0 "plt_symbolic_operand")
kono
parents:
diff changeset
187 (match_operand 0 "register_operand")))
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 (define_predicate "modular_operator"
kono
parents:
diff changeset
190 (match_code "plus,minus,mult,ashift"))
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 (define_predicate "equality_operator"
kono
parents:
diff changeset
193 (match_code "eq,ne"))
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195 (define_predicate "order_operator"
kono
parents:
diff changeset
196 (match_code "eq,ne,lt,ltu,le,leu,ge,geu,gt,gtu"))
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 (define_predicate "signed_order_operator"
kono
parents:
diff changeset
199 (match_code "eq,ne,lt,le,ge,gt"))
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 (define_predicate "fp_native_comparison"
kono
parents:
diff changeset
202 (match_code "eq,lt,le,gt,ge"))
kono
parents:
diff changeset
203
kono
parents:
diff changeset
204 (define_predicate "fp_scc_comparison"
kono
parents:
diff changeset
205 (match_code "unordered,ordered,unlt,unge,unle,ungt,ltgt,ne,eq,lt,le,gt,ge"))
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 (define_predicate "fp_branch_comparison"
kono
parents:
diff changeset
208 (match_code "unordered,ordered,unlt,unge,unle,ungt,uneq,ltgt,ne,eq,lt,le,gt,ge"))