Debian Codegraph @

gcc/config/aarch64/aarch64-ldpstp.md

raw
1 ;; AArch64 ldp/stp peephole optimizations.
2 ;; Copyright (C) 2014-2025 Free Software Foundation, Inc.
3 ;; Contributed by ARM Ltd.
4 ;;
5 ;; This file is part of GCC.
6 ;;
7 ;; GCC is free software; you can redistribute it and/or modify it
8 ;; under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3, or (at your option)
10 ;; any later version.
11 ;;
12 ;; GCC is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
16 ;;
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3. If not see
19 ;; <http://www.gnu.org/licenses/>.
20
21 (define_peephole2
22 [(set (match_operand:GPI 0 "register_operand" "")
23 (match_operand:GPI 1 "memory_operand" ""))
24 (set (match_operand:GPI 2 "register_operand" "")
25 (match_operand:GPI 3 "memory_operand" ""))]
26 "aarch64_operands_ok_for_ldpstp (operands, true)"
27 [(const_int 0)]
28 {
29 aarch64_finish_ldpstp_peephole (operands, true);
30 DONE;
31 })
32
33 (define_peephole2
34 [(set (match_operand:GPI 0 "memory_operand" "")
35 (match_operand:GPI 1 "aarch64_reg_or_zero" ""))
36 (set (match_operand:GPI 2 "memory_operand" "")
37 (match_operand:GPI 3 "aarch64_reg_or_zero" ""))]
38 "aarch64_operands_ok_for_ldpstp (operands, false)"
39 [(const_int 0)]
40 {
41 aarch64_finish_ldpstp_peephole (operands, false);
42 DONE;
43 })
44
45 (define_peephole2
46 [(set (match_operand:GPF 0 "register_operand" "")
47 (match_operand:GPF 1 "memory_operand" ""))
48 (set (match_operand:GPF 2 "register_operand" "")
49 (match_operand:GPF 3 "memory_operand" ""))]
50 "aarch64_operands_ok_for_ldpstp (operands, true)"
51 [(const_int 0)]
52 {
53 aarch64_finish_ldpstp_peephole (operands, true);
54 DONE;
55 })
56
57 (define_peephole2
58 [(set (match_operand:GPF 0 "memory_operand" "")
59 (match_operand:GPF 1 "aarch64_reg_or_fp_zero" ""))
60 (set (match_operand:GPF 2 "memory_operand" "")
61 (match_operand:GPF 3 "aarch64_reg_or_fp_zero" ""))]
62 "aarch64_operands_ok_for_ldpstp (operands, false)"
63 [(const_int 0)]
64 {
65 aarch64_finish_ldpstp_peephole (operands, false);
66 DONE;
67 })
68
69 (define_peephole2
70 [(set (match_operand:DREG 0 "register_operand" "")
71 (match_operand:DREG 1 "memory_operand" ""))
72 (set (match_operand:DREG2 2 "register_operand" "")
73 (match_operand:DREG2 3 "memory_operand" ""))]
74 "aarch64_operands_ok_for_ldpstp (operands, true)"
75 [(const_int 0)]
76 {
77 aarch64_finish_ldpstp_peephole (operands, true);
78 DONE;
79 })
80
81 (define_peephole2
82 [(set (match_operand:DREG 0 "memory_operand" "")
83 (match_operand:DREG 1 "register_operand" ""))
84 (set (match_operand:DREG2 2 "memory_operand" "")
85 (match_operand:DREG2 3 "register_operand" ""))]
86 "aarch64_operands_ok_for_ldpstp (operands, false)"
87 [(const_int 0)]
88 {
89 aarch64_finish_ldpstp_peephole (operands, false);
90 DONE;
91 })
92
93 (define_peephole2
94 [(set (match_operand:VQ 0 "register_operand" "")
95 (match_operand:VQ 1 "memory_operand" ""))
96 (set (match_operand:VQ2 2 "register_operand" "")
97 (match_operand:VQ2 3 "memory_operand" ""))]
98 "TARGET_FLOAT
99 && aarch64_operands_ok_for_ldpstp (operands, true)"
100 [(const_int 0)]
101 {
102 aarch64_finish_ldpstp_peephole (operands, true);
103 DONE;
104 })
105
106 (define_peephole2
107 [(set (match_operand:VQ 0 "memory_operand" "")
108 (match_operand:VQ 1 "register_operand" ""))
109 (set (match_operand:VQ2 2 "memory_operand" "")
110 (match_operand:VQ2 3 "register_operand" ""))]
111 "TARGET_FLOAT
112 && aarch64_operands_ok_for_ldpstp (operands, false)"
113 [(const_int 0)]
114 {
115 aarch64_finish_ldpstp_peephole (operands, false);
116 DONE;
117 })
118
119
120 ;; Handle sign/zero extended consecutive load/store.
121
122 (define_peephole2
123 [(set (match_operand:DI 0 "register_operand" "")
124 (sign_extend:DI (match_operand:SI 1 "memory_operand" "")))
125 (set (match_operand:DI 2 "register_operand" "")
126 (sign_extend:DI (match_operand:SI 3 "memory_operand" "")))]
127 "aarch64_operands_ok_for_ldpstp (operands, true)"
128 [(const_int 0)]
129 {
130 aarch64_finish_ldpstp_peephole (operands, true, SIGN_EXTEND);
131 DONE;
132 })
133
134 (define_peephole2
135 [(set (match_operand:DI 0 "register_operand" "")
136 (zero_extend:DI (match_operand:SI 1 "memory_operand" "")))
137 (set (match_operand:DI 2 "register_operand" "")
138 (zero_extend:DI (match_operand:SI 3 "memory_operand" "")))]
139 "aarch64_operands_ok_for_ldpstp (operands, true)"
140 [(const_int 0)]
141 {
142 aarch64_finish_ldpstp_peephole (operands, true, ZERO_EXTEND);
143 DONE;
144 })
145
146 ;; Handle storing of a floating point zero with integer data.
147 ;; This handles cases like:
148 ;; struct pair { int a; float b; }
149 ;;
150 ;; p->a = 1;
151 ;; p->b = 0.0;
152 ;;
153 ;; We can match modes that won't work for a stp instruction
154 ;; as aarch64_operands_ok_for_ldpstp checks that the modes are
155 ;; compatible.
156 (define_peephole2
157 [(set (match_operand:DSX 0 "memory_operand" "")
158 (match_operand:DSX 1 "aarch64_reg_zero_or_fp_zero" ""))
159 (set (match_operand:<FCVT_TARGET> 2 "memory_operand" "")
160 (match_operand:<FCVT_TARGET> 3 "aarch64_reg_zero_or_fp_zero" ""))]
161 "aarch64_operands_ok_for_ldpstp (operands, false)"
162 [(const_int 0)]
163 {
164 aarch64_finish_ldpstp_peephole (operands, false);
165 DONE;
166 })
167
168 ;; Handle consecutive load/store whose offset is out of the range
169 ;; supported by ldp/ldpsw/stp. We firstly adjust offset in a scratch
170 ;; register, then merge them into ldp/ldpsw/stp by using the adjusted
171 ;; offset.
172
173 (define_peephole2
174 [(match_scratch:DI 8 "r")
175 (set (match_operand:GPI 0 "register_operand" "")
176 (match_operand:GPI 1 "memory_operand" ""))
177 (set (match_operand:GPI 2 "register_operand" "")
178 (match_operand:GPI 3 "memory_operand" ""))
179 (set (match_operand:GPI 4 "register_operand" "")
180 (match_operand:GPI 5 "memory_operand" ""))
181 (set (match_operand:GPI 6 "register_operand" "")
182 (match_operand:GPI 7 "memory_operand" ""))
183 (match_dup 8)]
184 "aarch64_operands_adjust_ok_for_ldpstp (operands, true, <MODE>mode)"
185 [(const_int 0)]
186 {
187 if (aarch64_gen_adjusted_ldpstp (operands, true, <MODE>mode, UNKNOWN))
188 DONE;
189 else
190 FAIL;
191 })
192
193 (define_peephole2
194 [(match_scratch:DI 8 "r")
195 (set (match_operand:GPF 0 "register_operand" "")
196 (match_operand:GPF 1 "memory_operand" ""))
197 (set (match_operand:GPF 2 "register_operand" "")
198 (match_operand:GPF 3 "memory_operand" ""))
199 (set (match_operand:GPF 4 "register_operand" "")
200 (match_operand:GPF 5 "memory_operand" ""))
201 (set (match_operand:GPF 6 "register_operand" "")
202 (match_operand:GPF 7 "memory_operand" ""))
203 (match_dup 8)]
204 "aarch64_operands_adjust_ok_for_ldpstp (operands, true, <MODE>mode)"
205 [(const_int 0)]
206 {
207 if (aarch64_gen_adjusted_ldpstp (operands, true, <MODE>mode, UNKNOWN))
208 DONE;
209 else
210 FAIL;
211 })
212
213 (define_peephole2
214 [(match_scratch:DI 8 "r")
215 (set (match_operand:DI 0 "register_operand" "")
216 (sign_extend:DI (match_operand:SI 1 "memory_operand" "")))
217 (set (match_operand:DI 2 "register_operand" "")
218 (sign_extend:DI (match_operand:SI 3 "memory_operand" "")))
219 (set (match_operand:DI 4 "register_operand" "")
220 (sign_extend:DI (match_operand:SI 5 "memory_operand" "")))
221 (set (match_operand:DI 6 "register_operand" "")
222 (sign_extend:DI (match_operand:SI 7 "memory_operand" "")))
223 (match_dup 8)]
224 "aarch64_operands_adjust_ok_for_ldpstp (operands, true, SImode)"
225 [(const_int 0)]
226 {
227 if (aarch64_gen_adjusted_ldpstp (operands, true, SImode, SIGN_EXTEND))
228 DONE;
229 else
230 FAIL;
231 })
232
233 (define_peephole2
234 [(match_scratch:DI 8 "r")
235 (set (match_operand:DI 0 "register_operand" "")
236 (zero_extend:DI (match_operand:SI 1 "memory_operand" "")))
237 (set (match_operand:DI 2 "register_operand" "")
238 (zero_extend:DI (match_operand:SI 3 "memory_operand" "")))
239 (set (match_operand:DI 4 "register_operand" "")
240 (zero_extend:DI (match_operand:SI 5 "memory_operand" "")))
241 (set (match_operand:DI 6 "register_operand" "")
242 (zero_extend:DI (match_operand:SI 7 "memory_operand" "")))
243 (match_dup 8)]
244 "aarch64_operands_adjust_ok_for_ldpstp (operands, true, SImode)"
245 [(const_int 0)]
246 {
247 if (aarch64_gen_adjusted_ldpstp (operands, true, SImode, ZERO_EXTEND))
248 DONE;
249 else
250 FAIL;
251 })
252
253 (define_peephole2
254 [(match_scratch:DI 8 "r")
255 (set (match_operand:GPI 0 "memory_operand" "")
256 (match_operand:GPI 1 "aarch64_reg_or_zero" ""))
257 (set (match_operand:GPI 2 "memory_operand" "")
258 (match_operand:GPI 3 "aarch64_reg_or_zero" ""))
259 (set (match_operand:GPI 4 "memory_operand" "")
260 (match_operand:GPI 5 "aarch64_reg_or_zero" ""))
261 (set (match_operand:GPI 6 "memory_operand" "")
262 (match_operand:GPI 7 "aarch64_reg_or_zero" ""))
263 (match_dup 8)]
264 "aarch64_operands_adjust_ok_for_ldpstp (operands, false, <MODE>mode)"
265 [(const_int 0)]
266 {
267 if (aarch64_gen_adjusted_ldpstp (operands, false, <MODE>mode, UNKNOWN))
268 DONE;
269 else
270 FAIL;
271 })
272
273 (define_peephole2
274 [(match_scratch:DI 8 "r")
275 (set (match_operand:GPF 0 "memory_operand" "")
276 (match_operand:GPF 1 "aarch64_reg_or_fp_zero" ""))
277 (set (match_operand:GPF 2 "memory_operand" "")
278 (match_operand:GPF 3 "aarch64_reg_or_fp_zero" ""))
279 (set (match_operand:GPF 4 "memory_operand" "")
280 (match_operand:GPF 5 "aarch64_reg_or_fp_zero" ""))
281 (set (match_operand:GPF 6 "memory_operand" "")
282 (match_operand:GPF 7 "aarch64_reg_or_fp_zero" ""))
283 (match_dup 8)]
284 "aarch64_operands_adjust_ok_for_ldpstp (operands, false, <MODE>mode)"
285 [(const_int 0)]
286 {
287 if (aarch64_gen_adjusted_ldpstp (operands, false, <MODE>mode, UNKNOWN))
288 DONE;
289 else
290 FAIL;
291 })
292
293 (define_peephole2
294 [(match_scratch:DI 8 "r")
295 (set (match_operand:VP_2E 0 "memory_operand" "")
296 (match_operand:VP_2E 1 "aarch64_reg_or_zero" ""))
297 (set (match_operand:VP_2E 2 "memory_operand" "")
298 (match_operand:VP_2E 3 "aarch64_reg_or_zero" ""))
299 (set (match_operand:VP_2E 4 "memory_operand" "")
300 (match_operand:VP_2E 5 "aarch64_reg_or_zero" ""))
301 (set (match_operand:VP_2E 6 "memory_operand" "")
302 (match_operand:VP_2E 7 "aarch64_reg_or_zero" ""))
303 (match_dup 8)]
304 "TARGET_FLOAT
305 && aarch64_operands_adjust_ok_for_ldpstp (operands, false, <MODE>mode)"
306 [(const_int 0)]
307 {
308 if (aarch64_gen_adjusted_ldpstp (operands, false, <MODE>mode, UNKNOWN))
309 DONE;
310 else
311 FAIL;
312 })
313
314 (define_peephole2
315 [(match_scratch:DI 8 "r")
316 (set (match_operand:VP_2E 0 "register_operand" "")
317 (match_operand:VP_2E 1 "memory_operand" ""))
318 (set (match_operand:VP_2E 2 "register_operand" "")
319 (match_operand:VP_2E 3 "memory_operand" ""))
320 (set (match_operand:VP_2E 4 "register_operand" "")
321 (match_operand:VP_2E 5 "memory_operand" ""))
322 (set (match_operand:VP_2E 6 "register_operand" "")
323 (match_operand:VP_2E 7 "memory_operand" ""))
324 (match_dup 8)]
325 "TARGET_FLOAT
326 && aarch64_operands_adjust_ok_for_ldpstp (operands, true, <MODE>mode)"
327 [(const_int 0)]
328 {
329 if (aarch64_gen_adjusted_ldpstp (operands, true, <MODE>mode, UNKNOWN))
330 DONE;
331 else
332 FAIL;
333 })