Branch data Line data Source code
1 : : /* Convert tree expression to rtl instructions, for GNU compiler.
2 : : Copyright (C) 1988-2024 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 it under
7 : : the terms of the GNU General Public License as published by the Free
8 : : Software Foundation; either version 3, or (at your option) any later
9 : : version.
10 : :
11 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : : for more details.
15 : :
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/>. */
19 : :
20 : : #include "config.h"
21 : : #include "system.h"
22 : : #include "coretypes.h"
23 : : #include "backend.h"
24 : : #include "target.h"
25 : : #include "rtl.h"
26 : : #include "tree.h"
27 : : #include "gimple.h"
28 : : #include "predict.h"
29 : : #include "memmodel.h"
30 : : #include "tm_p.h"
31 : : #include "ssa.h"
32 : : #include "optabs.h"
33 : : #include "expmed.h"
34 : : #include "regs.h"
35 : : #include "emit-rtl.h"
36 : : #include "recog.h"
37 : : #include "cgraph.h"
38 : : #include "diagnostic.h"
39 : : #include "alias.h"
40 : : #include "fold-const.h"
41 : : #include "stor-layout.h"
42 : : #include "attribs.h"
43 : : #include "varasm.h"
44 : : #include "except.h"
45 : : #include "insn-attr.h"
46 : : #include "dojump.h"
47 : : #include "explow.h"
48 : : #include "calls.h"
49 : : #include "stmt.h"
50 : : /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
51 : : #include "expr.h"
52 : : #include "optabs-tree.h"
53 : : #include "libfuncs.h"
54 : : #include "reload.h"
55 : : #include "langhooks.h"
56 : : #include "common/common-target.h"
57 : : #include "tree-dfa.h"
58 : : #include "tree-ssa-live.h"
59 : : #include "tree-outof-ssa.h"
60 : : #include "tree-ssa-address.h"
61 : : #include "builtins.h"
62 : : #include "ccmp.h"
63 : : #include "gimple-iterator.h"
64 : : #include "gimple-fold.h"
65 : : #include "rtx-vector-builder.h"
66 : : #include "tree-pretty-print.h"
67 : : #include "flags.h"
68 : :
69 : :
70 : : /* If this is nonzero, we do not bother generating VOLATILE
71 : : around volatile memory references, and we are willing to
72 : : output indirect addresses. If cse is to follow, we reject
73 : : indirect addresses so a useful potential cse is generated;
74 : : if it is used only once, instruction combination will produce
75 : : the same indirect address eventually. */
76 : : int cse_not_expected;
77 : :
78 : : static bool block_move_libcall_safe_for_call_parm (void);
79 : : static bool emit_block_move_via_pattern (rtx, rtx, rtx, unsigned, unsigned,
80 : : HOST_WIDE_INT, unsigned HOST_WIDE_INT,
81 : : unsigned HOST_WIDE_INT,
82 : : unsigned HOST_WIDE_INT, bool);
83 : : static void emit_block_move_via_loop (rtx, rtx, rtx, unsigned, int);
84 : : static void emit_block_move_via_sized_loop (rtx, rtx, rtx, unsigned, unsigned);
85 : : static void emit_block_move_via_oriented_loop (rtx, rtx, rtx, unsigned, unsigned);
86 : : static rtx emit_block_cmp_via_loop (rtx, rtx, rtx, tree, rtx, bool,
87 : : unsigned, unsigned);
88 : : static void clear_by_pieces (rtx, unsigned HOST_WIDE_INT, unsigned int);
89 : : static rtx_insn *compress_float_constant (rtx, rtx);
90 : : static rtx get_subtarget (rtx);
91 : : static rtx store_field (rtx, poly_int64, poly_int64, poly_uint64, poly_uint64,
92 : : machine_mode, tree, alias_set_type, bool, bool);
93 : :
94 : : static unsigned HOST_WIDE_INT highest_pow2_factor_for_target (const_tree, const_tree);
95 : :
96 : : static bool is_aligning_offset (const_tree, const_tree);
97 : : static rtx reduce_to_bit_field_precision (rtx, rtx, tree);
98 : : static rtx do_store_flag (sepops, rtx, machine_mode);
99 : : #ifdef PUSH_ROUNDING
100 : : static void emit_single_push_insn (machine_mode, rtx, tree);
101 : : #endif
102 : : static void do_tablejump (rtx, machine_mode, rtx, rtx, rtx,
103 : : profile_probability);
104 : : static rtx const_vector_from_tree (tree);
105 : : static tree tree_expr_size (const_tree);
106 : : static void convert_mode_scalar (rtx, rtx, int);
107 : :
108 : :
109 : : /* This is run to set up which modes can be used
110 : : directly in memory and to initialize the block move optab. It is run
111 : : at the beginning of compilation and when the target is reinitialized. */
112 : :
113 : : void
114 : 209938 : init_expr_target (void)
115 : : {
116 : 209938 : rtx pat;
117 : 209938 : int num_clobbers;
118 : 209938 : rtx mem, mem1;
119 : 209938 : rtx reg;
120 : :
121 : : /* Try indexing by frame ptr and try by stack ptr.
122 : : It is known that on the Convex the stack ptr isn't a valid index.
123 : : With luck, one or the other is valid on any machine. */
124 : 209938 : mem = gen_rtx_MEM (word_mode, stack_pointer_rtx);
125 : 209938 : mem1 = gen_rtx_MEM (word_mode, frame_pointer_rtx);
126 : :
127 : : /* A scratch register we can modify in-place below to avoid
128 : : useless RTL allocations. */
129 : 209938 : reg = gen_rtx_REG (word_mode, LAST_VIRTUAL_REGISTER + 1);
130 : :
131 : 209938 : rtx_insn *insn = as_a<rtx_insn *> (rtx_alloc (INSN));
132 : 209938 : pat = gen_rtx_SET (NULL_RTX, NULL_RTX);
133 : 209938 : PATTERN (insn) = pat;
134 : :
135 : 27501878 : for (machine_mode mode = VOIDmode; (int) mode < NUM_MACHINE_MODES;
136 : 27291940 : mode = (machine_mode) ((int) mode + 1))
137 : : {
138 : 27291940 : int regno;
139 : :
140 : 27291940 : direct_load[(int) mode] = direct_store[(int) mode] = 0;
141 : 27291940 : PUT_MODE (mem, mode);
142 : 27291940 : PUT_MODE (mem1, mode);
143 : :
144 : : /* See if there is some register that can be used in this mode and
145 : : directly loaded or stored from memory. */
146 : :
147 : 27291940 : if (mode != VOIDmode && mode != BLKmode)
148 : 1870589184 : for (regno = 0; regno < FIRST_PSEUDO_REGISTER
149 : 1897461248 : && (direct_load[(int) mode] == 0 || direct_store[(int) mode] == 0);
150 : : regno++)
151 : : {
152 : 1870589184 : if (!targetm.hard_regno_mode_ok (regno, mode))
153 : 1755686441 : continue;
154 : :
155 : 114902743 : set_mode_and_regno (reg, mode, regno);
156 : :
157 : 114902743 : SET_SRC (pat) = mem;
158 : 114902743 : SET_DEST (pat) = reg;
159 : 114902743 : if (recog (pat, insn, &num_clobbers) >= 0)
160 : 7058708 : direct_load[(int) mode] = 1;
161 : :
162 : 114902743 : SET_SRC (pat) = mem1;
163 : 114902743 : SET_DEST (pat) = reg;
164 : 114902743 : if (recog (pat, insn, &num_clobbers) >= 0)
165 : 7058708 : direct_load[(int) mode] = 1;
166 : :
167 : 114902743 : SET_SRC (pat) = reg;
168 : 114902743 : SET_DEST (pat) = mem;
169 : 114902743 : if (recog (pat, insn, &num_clobbers) >= 0)
170 : 7058708 : direct_store[(int) mode] = 1;
171 : :
172 : 114902743 : SET_SRC (pat) = reg;
173 : 114902743 : SET_DEST (pat) = mem1;
174 : 114902743 : if (recog (pat, insn, &num_clobbers) >= 0)
175 : 7058708 : direct_store[(int) mode] = 1;
176 : : }
177 : : }
178 : :
179 : 209938 : mem = gen_rtx_MEM (VOIDmode, gen_raw_REG (Pmode, LAST_VIRTUAL_REGISTER + 1));
180 : :
181 : 209938 : opt_scalar_float_mode mode_iter;
182 : 1469566 : FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_FLOAT)
183 : : {
184 : 1259628 : scalar_float_mode mode = mode_iter.require ();
185 : 1259628 : scalar_float_mode srcmode;
186 : 4408698 : FOR_EACH_MODE_UNTIL (srcmode, mode)
187 : : {
188 : 3149070 : enum insn_code ic;
189 : :
190 : 3149070 : ic = can_extend_p (mode, srcmode, 0);
191 : 3149070 : if (ic == CODE_FOR_nothing)
192 : 2515043 : continue;
193 : :
194 : 634027 : PUT_MODE (mem, srcmode);
195 : :
196 : 634027 : if (insn_operand_matches (ic, 1, mem))
197 : 632073 : float_extend_from_mem[mode][srcmode] = true;
198 : : }
199 : : }
200 : 209938 : }
201 : :
202 : : /* This is run at the start of compiling a function. */
203 : :
204 : : void
205 : 1643414 : init_expr (void)
206 : : {
207 : 1643414 : memset (&crtl->expr, 0, sizeof (crtl->expr));
208 : 1643414 : }
209 : :
210 : : /* Copy data from FROM to TO, where the machine modes are not the same.
211 : : Both modes may be integer, or both may be floating, or both may be
212 : : fixed-point.
213 : : UNSIGNEDP should be nonzero if FROM is an unsigned type.
214 : : This causes zero-extension instead of sign-extension. */
215 : :
216 : : void
217 : 1771177 : convert_move (rtx to, rtx from, int unsignedp)
218 : : {
219 : 1771177 : machine_mode to_mode = GET_MODE (to);
220 : 1771177 : machine_mode from_mode = GET_MODE (from);
221 : :
222 : 1771177 : gcc_assert (to_mode != BLKmode);
223 : 1771177 : gcc_assert (from_mode != BLKmode);
224 : :
225 : : /* If the source and destination are already the same, then there's
226 : : nothing to do. */
227 : 1771177 : if (to == from)
228 : 1771177 : return;
229 : :
230 : : /* If FROM is a SUBREG that indicates that we have already done at least
231 : : the required extension, strip it. We don't handle such SUBREGs as
232 : : TO here. */
233 : :
234 : 1771177 : scalar_int_mode to_int_mode;
235 : 1771177 : if (GET_CODE (from) == SUBREG
236 : 112250 : && SUBREG_PROMOTED_VAR_P (from)
237 : 1771177 : && is_a <scalar_int_mode> (to_mode, &to_int_mode)
238 : 1771177 : && (GET_MODE_PRECISION (subreg_promoted_mode (from))
239 : 0 : >= GET_MODE_PRECISION (to_int_mode))
240 : 1771177 : && SUBREG_CHECK_PROMOTED_SIGN (from, unsignedp))
241 : : {
242 : 0 : scalar_int_mode int_orig_mode;
243 : 0 : scalar_int_mode int_inner_mode;
244 : 0 : machine_mode orig_mode = GET_MODE (from);
245 : :
246 : 0 : from = gen_lowpart (to_int_mode, SUBREG_REG (from));
247 : 0 : from_mode = to_int_mode;
248 : :
249 : : /* Preserve SUBREG_PROMOTED_VAR_P if the new mode is wider than
250 : : the original mode, but narrower than the inner mode. */
251 : 0 : if (GET_CODE (from) == SUBREG
252 : 0 : && is_a <scalar_int_mode> (orig_mode, &int_orig_mode)
253 : 0 : && GET_MODE_PRECISION (to_int_mode)
254 : 0 : > GET_MODE_PRECISION (int_orig_mode)
255 : 0 : && is_a <scalar_int_mode> (GET_MODE (SUBREG_REG (from)),
256 : : &int_inner_mode)
257 : 0 : && GET_MODE_PRECISION (int_inner_mode)
258 : 0 : > GET_MODE_PRECISION (to_int_mode))
259 : : {
260 : 0 : SUBREG_PROMOTED_VAR_P (from) = 1;
261 : 0 : SUBREG_PROMOTED_SET (from, unsignedp);
262 : : }
263 : : }
264 : :
265 : 1771177 : gcc_assert (GET_CODE (to) != SUBREG || !SUBREG_PROMOTED_VAR_P (to));
266 : :
267 : 1771177 : if (to_mode == from_mode
268 : 1712101 : || (from_mode == VOIDmode && CONSTANT_P (from)))
269 : : {
270 : 59082 : emit_move_insn (to, from);
271 : 59082 : return;
272 : : }
273 : :
274 : 1712095 : if (VECTOR_MODE_P (to_mode) || VECTOR_MODE_P (from_mode))
275 : : {
276 : 23800 : if (GET_MODE_UNIT_PRECISION (to_mode)
277 : 11900 : > GET_MODE_UNIT_PRECISION (from_mode))
278 : : {
279 : 4585 : optab op = unsignedp ? zext_optab : sext_optab;
280 : 4585 : insn_code icode = convert_optab_handler (op, to_mode, from_mode);
281 : 4585 : if (icode != CODE_FOR_nothing)
282 : : {
283 : 777 : emit_unop_insn (icode, to, from,
284 : : unsignedp ? ZERO_EXTEND : SIGN_EXTEND);
285 : 777 : return;
286 : : }
287 : : }
288 : :
289 : 22246 : if (GET_MODE_UNIT_PRECISION (to_mode)
290 : 11123 : < GET_MODE_UNIT_PRECISION (from_mode))
291 : : {
292 : 1023 : insn_code icode = convert_optab_handler (trunc_optab,
293 : : to_mode, from_mode);
294 : 1023 : if (icode != CODE_FOR_nothing)
295 : : {
296 : 72 : emit_unop_insn (icode, to, from, TRUNCATE);
297 : 72 : return;
298 : : }
299 : : }
300 : :
301 : 33153 : gcc_assert (known_eq (GET_MODE_BITSIZE (from_mode),
302 : : GET_MODE_BITSIZE (to_mode)));
303 : :
304 : 11051 : if (VECTOR_MODE_P (to_mode))
305 : 11051 : from = simplify_gen_subreg (to_mode, from, GET_MODE (from), 0);
306 : : else
307 : 0 : to = simplify_gen_subreg (from_mode, to, GET_MODE (to), 0);
308 : :
309 : 11051 : emit_move_insn (to, from);
310 : 11051 : return;
311 : : }
312 : :
313 : 1700195 : if (GET_CODE (to) == CONCAT && GET_CODE (from) == CONCAT)
314 : : {
315 : 0 : convert_move (XEXP (to, 0), XEXP (from, 0), unsignedp);
316 : 0 : convert_move (XEXP (to, 1), XEXP (from, 1), unsignedp);
317 : 0 : return;
318 : : }
319 : :
320 : 1700195 : convert_mode_scalar (to, from, unsignedp);
321 : : }
322 : :
323 : : /* Like convert_move, but deals only with scalar modes. */
324 : :
325 : : static void
326 : 1700247 : convert_mode_scalar (rtx to, rtx from, int unsignedp)
327 : : {
328 : : /* Both modes should be scalar types. */
329 : 1700251 : scalar_mode from_mode = as_a <scalar_mode> (GET_MODE (from));
330 : 1700251 : scalar_mode to_mode = as_a <scalar_mode> (GET_MODE (to));
331 : 1700251 : bool to_real = SCALAR_FLOAT_MODE_P (to_mode);
332 : 1700251 : bool from_real = SCALAR_FLOAT_MODE_P (from_mode);
333 : 1700251 : enum insn_code code;
334 : 1700251 : rtx libcall;
335 : :
336 : 1700251 : gcc_assert (to_real == from_real);
337 : :
338 : : /* rtx code for making an equivalent value. */
339 : 1700251 : enum rtx_code equiv_code = (unsignedp < 0 ? UNKNOWN
340 : 1700251 : : (unsignedp ? ZERO_EXTEND : SIGN_EXTEND));
341 : :
342 : 1700251 : if (to_real)
343 : : {
344 : 184183 : rtx value;
345 : 184183 : rtx_insn *insns;
346 : 184183 : convert_optab tab;
347 : :
348 : 184183 : gcc_assert ((GET_MODE_PRECISION (from_mode)
349 : : != GET_MODE_PRECISION (to_mode))
350 : : || (DECIMAL_FLOAT_MODE_P (from_mode)
351 : : != DECIMAL_FLOAT_MODE_P (to_mode))
352 : : || (REAL_MODE_FORMAT (from_mode) == &arm_bfloat_half_format
353 : : && REAL_MODE_FORMAT (to_mode) == &ieee_half_format)
354 : : || (REAL_MODE_FORMAT (to_mode) == &arm_bfloat_half_format
355 : : && REAL_MODE_FORMAT (from_mode) == &ieee_half_format));
356 : :
357 : 184183 : if (GET_MODE_PRECISION (from_mode) == GET_MODE_PRECISION (to_mode))
358 : : /* Conversion between decimal float and binary float, same size. */
359 : 717 : tab = DECIMAL_FLOAT_MODE_P (from_mode) ? trunc_optab : sext_optab;
360 : 183466 : else if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode))
361 : : tab = sext_optab;
362 : : else
363 : 19706 : tab = trunc_optab;
364 : :
365 : : /* Try converting directly if the insn is supported. */
366 : :
367 : 184183 : code = convert_optab_handler (tab, to_mode, from_mode);
368 : 184183 : if (code != CODE_FOR_nothing)
369 : : {
370 : 159976 : emit_unop_insn (code, to, from,
371 : : tab == sext_optab ? FLOAT_EXTEND : FLOAT_TRUNCATE);
372 : 159976 : return;
373 : : }
374 : :
375 : : #ifdef HAVE_SFmode
376 : 24207 : if (REAL_MODE_FORMAT (from_mode) == &arm_bfloat_half_format
377 : 24207 : && REAL_MODE_FORMAT (SFmode) == &ieee_single_format)
378 : : {
379 : 2586 : if (GET_MODE_PRECISION (to_mode) > GET_MODE_PRECISION (SFmode))
380 : : {
381 : : /* To cut down on libgcc size, implement
382 : : BFmode -> {DF,XF,TF}mode conversions by
383 : : BFmode -> SFmode -> {DF,XF,TF}mode conversions. */
384 : 4 : rtx temp = gen_reg_rtx (SFmode);
385 : 4 : convert_mode_scalar (temp, from, unsignedp);
386 : 4 : convert_mode_scalar (to, temp, unsignedp);
387 : 4 : return;
388 : : }
389 : 2582 : if (REAL_MODE_FORMAT (to_mode) == &ieee_half_format)
390 : : {
391 : : /* Similarly, implement BFmode -> HFmode as
392 : : BFmode -> SFmode -> HFmode conversion where SFmode
393 : : has superset of BFmode values. We don't need
394 : : to handle sNaNs by raising exception and turning
395 : : it into qNaN though, as that can be done in the
396 : : SFmode -> HFmode conversion too. */
397 : 0 : rtx temp = gen_reg_rtx (SFmode);
398 : 0 : int save_flag_finite_math_only = flag_finite_math_only;
399 : 0 : flag_finite_math_only = true;
400 : 0 : convert_mode_scalar (temp, from, unsignedp);
401 : 0 : flag_finite_math_only = save_flag_finite_math_only;
402 : 0 : convert_mode_scalar (to, temp, unsignedp);
403 : 0 : return;
404 : : }
405 : 2582 : if (to_mode == SFmode
406 : 2582 : && !HONOR_NANS (from_mode)
407 : 49 : && !HONOR_NANS (to_mode)
408 : 2631 : && optimize_insn_for_speed_p ())
409 : : {
410 : : /* If we don't expect sNaNs, for BFmode -> SFmode we can just
411 : : shift the bits up. */
412 : 48 : machine_mode fromi_mode, toi_mode;
413 : 96 : if (int_mode_for_size (GET_MODE_BITSIZE (from_mode),
414 : 48 : 0).exists (&fromi_mode)
415 : 144 : && int_mode_for_size (GET_MODE_BITSIZE (to_mode),
416 : 48 : 0).exists (&toi_mode))
417 : : {
418 : 48 : start_sequence ();
419 : 48 : rtx fromi = lowpart_subreg (fromi_mode, from, from_mode);
420 : 48 : rtx tof = NULL_RTX;
421 : 48 : if (fromi)
422 : : {
423 : 48 : rtx toi;
424 : 48 : if (GET_MODE (fromi) == VOIDmode)
425 : 0 : toi = simplify_unary_operation (ZERO_EXTEND, toi_mode,
426 : : fromi, fromi_mode);
427 : : else
428 : : {
429 : 48 : toi = gen_reg_rtx (toi_mode);
430 : 48 : convert_mode_scalar (toi, fromi, 1);
431 : : }
432 : 48 : toi
433 : 96 : = maybe_expand_shift (LSHIFT_EXPR, toi_mode, toi,
434 : 48 : GET_MODE_PRECISION (to_mode)
435 : 48 : - GET_MODE_PRECISION (from_mode),
436 : : NULL_RTX, 1);
437 : 48 : if (toi)
438 : : {
439 : 48 : tof = lowpart_subreg (to_mode, toi, toi_mode);
440 : 48 : if (tof)
441 : 48 : emit_move_insn (to, tof);
442 : : }
443 : : }
444 : 48 : insns = get_insns ();
445 : 48 : end_sequence ();
446 : 48 : if (tof)
447 : : {
448 : 48 : emit_insn (insns);
449 : 48 : return;
450 : : }
451 : : }
452 : : }
453 : : }
454 : 24155 : if (REAL_MODE_FORMAT (from_mode) == &ieee_single_format
455 : 4944 : && REAL_MODE_FORMAT (to_mode) == &arm_bfloat_half_format
456 : 1772 : && !HONOR_NANS (from_mode)
457 : 1 : && !HONOR_NANS (to_mode)
458 : 1 : && !flag_rounding_math
459 : 24156 : && optimize_insn_for_speed_p ())
460 : : {
461 : : /* If we don't expect qNaNs nor sNaNs and can assume rounding
462 : : to nearest, we can expand the conversion inline as
463 : : (fromi + 0x7fff + ((fromi >> 16) & 1)) >> 16. */
464 : 1 : machine_mode fromi_mode, toi_mode;
465 : 2 : if (int_mode_for_size (GET_MODE_BITSIZE (from_mode),
466 : 1 : 0).exists (&fromi_mode)
467 : 3 : && int_mode_for_size (GET_MODE_BITSIZE (to_mode),
468 : 1 : 0).exists (&toi_mode))
469 : : {
470 : 1 : start_sequence ();
471 : 1 : rtx fromi = lowpart_subreg (fromi_mode, from, from_mode);
472 : 1 : rtx tof = NULL_RTX;
473 : 2 : do
474 : : {
475 : 1 : if (!fromi)
476 : : break;
477 : 1 : int shift = (GET_MODE_PRECISION (from_mode)
478 : 1 : - GET_MODE_PRECISION (to_mode));
479 : 1 : rtx temp1
480 : 1 : = maybe_expand_shift (RSHIFT_EXPR, fromi_mode, fromi,
481 : : shift, NULL_RTX, 1);
482 : 1 : if (!temp1)
483 : : break;
484 : 1 : rtx temp2
485 : 1 : = expand_binop (fromi_mode, and_optab, temp1, const1_rtx,
486 : : NULL_RTX, 1, OPTAB_DIRECT);
487 : 1 : if (!temp2)
488 : : break;
489 : 1 : rtx temp3
490 : 1 : = expand_binop (fromi_mode, add_optab, fromi,
491 : : gen_int_mode ((HOST_WIDE_INT_1U
492 : 1 : << (shift - 1)) - 1,
493 : : fromi_mode), NULL_RTX,
494 : : 1, OPTAB_DIRECT);
495 : 1 : if (!temp3)
496 : : break;
497 : 1 : rtx temp4
498 : 1 : = expand_binop (fromi_mode, add_optab, temp3, temp2,
499 : : NULL_RTX, 1, OPTAB_DIRECT);
500 : 1 : if (!temp4)
501 : : break;
502 : 1 : rtx temp5 = maybe_expand_shift (RSHIFT_EXPR, fromi_mode,
503 : : temp4, shift, NULL_RTX, 1);
504 : 1 : if (!temp5)
505 : : break;
506 : 1 : rtx temp6 = lowpart_subreg (toi_mode, temp5, fromi_mode);
507 : 1 : if (!temp6)
508 : : break;
509 : 1 : tof = lowpart_subreg (to_mode, force_reg (toi_mode, temp6),
510 : : toi_mode);
511 : 1 : if (tof)
512 : 1 : emit_move_insn (to, tof);
513 : : }
514 : : while (0);
515 : 1 : insns = get_insns ();
516 : 1 : end_sequence ();
517 : 1 : if (tof)
518 : : {
519 : 1 : emit_insn (insns);
520 : 1 : return;
521 : : }
522 : : }
523 : : }
524 : : #endif
525 : :
526 : : /* Otherwise use a libcall. */
527 : 24154 : libcall = convert_optab_libfunc (tab, to_mode, from_mode);
528 : :
529 : : /* Is this conversion implemented yet? */
530 : 24154 : gcc_assert (libcall);
531 : :
532 : 24154 : start_sequence ();
533 : 24154 : value = emit_library_call_value (libcall, NULL_RTX, LCT_CONST, to_mode,
534 : : from, from_mode);
535 : 24154 : insns = get_insns ();
536 : 24154 : end_sequence ();
537 : 24154 : emit_libcall_block (insns, to, value,
538 : 7764 : tab == trunc_optab ? gen_rtx_FLOAT_TRUNCATE (to_mode,
539 : : from)
540 : 16390 : : gen_rtx_FLOAT_EXTEND (to_mode, from));
541 : 24154 : return;
542 : : }
543 : :
544 : : /* Handle pointer conversion. */ /* SPEE 900220. */
545 : : /* If the target has a converter from FROM_MODE to TO_MODE, use it. */
546 : 1516068 : {
547 : 1516068 : convert_optab ctab;
548 : :
549 : 1516068 : if (GET_MODE_PRECISION (from_mode) > GET_MODE_PRECISION (to_mode))
550 : : ctab = trunc_optab;
551 : 1323966 : else if (unsignedp)
552 : : ctab = zext_optab;
553 : : else
554 : 661057 : ctab = sext_optab;
555 : :
556 : 1516068 : if (convert_optab_handler (ctab, to_mode, from_mode)
557 : : != CODE_FOR_nothing)
558 : : {
559 : 1319016 : emit_unop_insn (convert_optab_handler (ctab, to_mode, from_mode),
560 : : to, from, UNKNOWN);
561 : 1319016 : return;
562 : : }
563 : : }
564 : :
565 : : /* Targets are expected to provide conversion insns between PxImode and
566 : : xImode for all MODE_PARTIAL_INT modes they use, but no others. */
567 : 197052 : if (GET_MODE_CLASS (to_mode) == MODE_PARTIAL_INT)
568 : : {
569 : 0 : scalar_int_mode full_mode
570 : 0 : = smallest_int_mode_for_size (GET_MODE_BITSIZE (to_mode));
571 : :
572 : 0 : gcc_assert (convert_optab_handler (trunc_optab, to_mode, full_mode)
573 : : != CODE_FOR_nothing);
574 : :
575 : 0 : if (full_mode != from_mode)
576 : 0 : from = convert_to_mode (full_mode, from, unsignedp);
577 : 0 : emit_unop_insn (convert_optab_handler (trunc_optab, to_mode, full_mode),
578 : : to, from, UNKNOWN);
579 : 0 : return;
580 : : }
581 : 197052 : if (GET_MODE_CLASS (from_mode) == MODE_PARTIAL_INT)
582 : : {
583 : 0 : rtx new_from;
584 : 0 : scalar_int_mode full_mode
585 : 0 : = smallest_int_mode_for_size (GET_MODE_BITSIZE (from_mode));
586 : 0 : convert_optab ctab = unsignedp ? zext_optab : sext_optab;
587 : 0 : enum insn_code icode;
588 : :
589 : 0 : icode = convert_optab_handler (ctab, full_mode, from_mode);
590 : 0 : gcc_assert (icode != CODE_FOR_nothing);
591 : :
592 : 0 : if (to_mode == full_mode)
593 : : {
594 : 0 : emit_unop_insn (icode, to, from, UNKNOWN);
595 : 0 : return;
596 : : }
597 : :
598 : 0 : new_from = gen_reg_rtx (full_mode);
599 : 0 : emit_unop_insn (icode, new_from, from, UNKNOWN);
600 : :
601 : : /* else proceed to integer conversions below. */
602 : 0 : from_mode = full_mode;
603 : 0 : from = new_from;
604 : : }
605 : :
606 : : /* Make sure both are fixed-point modes or both are not. */
607 : 197052 : gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode) ==
608 : : ALL_SCALAR_FIXED_POINT_MODE_P (to_mode));
609 : 197052 : if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode))
610 : : {
611 : : /* If we widen from_mode to to_mode and they are in the same class,
612 : : we won't saturate the result.
613 : : Otherwise, always saturate the result to play safe. */
614 : 0 : if (GET_MODE_CLASS (from_mode) == GET_MODE_CLASS (to_mode)
615 : 0 : && GET_MODE_SIZE (from_mode) < GET_MODE_SIZE (to_mode))
616 : 0 : expand_fixed_convert (to, from, 0, 0);
617 : : else
618 : 0 : expand_fixed_convert (to, from, 0, 1);
619 : 0 : return;
620 : : }
621 : :
622 : : /* Now both modes are integers. */
623 : :
624 : : /* Handle expanding beyond a word. */
625 : 197052 : if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode)
626 : 199609 : && GET_MODE_PRECISION (to_mode) > BITS_PER_WORD)
627 : : {
628 : 4950 : rtx_insn *insns;
629 : 4950 : rtx lowpart;
630 : 4950 : rtx fill_value;
631 : 4950 : rtx lowfrom;
632 : 4950 : int i;
633 : 4950 : scalar_mode lowpart_mode;
634 : 9900 : int nwords = CEIL (GET_MODE_SIZE (to_mode), UNITS_PER_WORD);
635 : :
636 : : /* Try converting directly if the insn is supported. */
637 : 4950 : if ((code = can_extend_p (to_mode, from_mode, unsignedp))
638 : : != CODE_FOR_nothing)
639 : : {
640 : : /* If FROM is a SUBREG, put it into a register. Do this
641 : : so that we always generate the same set of insns for
642 : : better cse'ing; if an intermediate assignment occurred,
643 : : we won't be doing the operation directly on the SUBREG. */
644 : 0 : if (optimize > 0 && GET_CODE (from) == SUBREG)
645 : 0 : from = force_reg (from_mode, from);
646 : 0 : emit_unop_insn (code, to, from, equiv_code);
647 : 0 : return;
648 : : }
649 : : /* Next, try converting via full word. */
650 : 4950 : else if (GET_MODE_PRECISION (from_mode) < BITS_PER_WORD
651 : 4950 : && ((code = can_extend_p (to_mode, word_mode, unsignedp))
652 : : != CODE_FOR_nothing))
653 : : {
654 : 4950 : rtx word_to = gen_reg_rtx (word_mode);
655 : 4950 : if (REG_P (to))
656 : : {
657 : 4882 : if (reg_overlap_mentioned_p (to, from))
658 : 0 : from = force_reg (from_mode, from);
659 : 4882 : emit_clobber (to);
660 : : }
661 : 4950 : convert_move (word_to, from, unsignedp);
662 : 4950 : emit_unop_insn (code, to, word_to, equiv_code);
663 : 4950 : return;
664 : : }
665 : :
666 : : /* No special multiword conversion insn; do it by hand. */
667 : 0 : start_sequence ();
668 : :
669 : : /* Since we will turn this into a no conflict block, we must ensure
670 : : the source does not overlap the target so force it into an isolated
671 : : register when maybe so. Likewise for any MEM input, since the
672 : : conversion sequence might require several references to it and we
673 : : must ensure we're getting the same value every time. */
674 : :
675 : 0 : if (MEM_P (from) || reg_overlap_mentioned_p (to, from))
676 : 0 : from = force_reg (from_mode, from);
677 : :
678 : : /* Get a copy of FROM widened to a word, if necessary. */
679 : 0 : if (GET_MODE_PRECISION (from_mode) < BITS_PER_WORD)
680 : 0 : lowpart_mode = word_mode;
681 : : else
682 : : lowpart_mode = from_mode;
683 : :
684 : 0 : lowfrom = convert_to_mode (lowpart_mode, from, unsignedp);
685 : :
686 : 0 : lowpart = gen_lowpart (lowpart_mode, to);
687 : 0 : emit_move_insn (lowpart, lowfrom);
688 : :
689 : : /* Compute the value to put in each remaining word. */
690 : 0 : if (unsignedp)
691 : 0 : fill_value = const0_rtx;
692 : : else
693 : 0 : fill_value = emit_store_flag_force (gen_reg_rtx (word_mode),
694 : : LT, lowfrom, const0_rtx,
695 : : lowpart_mode, 0, -1);
696 : :
697 : : /* Fill the remaining words. */
698 : 0 : for (i = GET_MODE_SIZE (lowpart_mode) / UNITS_PER_WORD; i < nwords; i++)
699 : : {
700 : 0 : int index = (WORDS_BIG_ENDIAN ? nwords - i - 1 : i);
701 : 0 : rtx subword = operand_subword (to, index, 1, to_mode);
702 : :
703 : 0 : gcc_assert (subword);
704 : :
705 : 0 : if (fill_value != subword)
706 : 0 : emit_move_insn (subword, fill_value);
707 : : }
708 : :
709 : 0 : insns = get_insns ();
710 : 0 : end_sequence ();
711 : :
712 : 0 : emit_insn (insns);
713 : 0 : return;
714 : : }
715 : :
716 : : /* Truncating multi-word to a word or less. */
717 : 192102 : if (GET_MODE_PRECISION (from_mode) > BITS_PER_WORD
718 : 192102 : && GET_MODE_PRECISION (to_mode) <= BITS_PER_WORD)
719 : : {
720 : 75126 : if (!((MEM_P (from)
721 : 537 : && ! MEM_VOLATILE_P (from)
722 : 537 : && direct_load[(int) to_mode]
723 : 537 : && ! mode_dependent_address_p (XEXP (from, 0),
724 : 537 : MEM_ADDR_SPACE (from)))
725 : 42082 : || REG_P (from)
726 : : || GET_CODE (from) == SUBREG))
727 : 0 : from = force_reg (from_mode, from);
728 : 42619 : convert_move (to, gen_lowpart (word_mode, from), 0);
729 : 42619 : return;
730 : : }
731 : :
732 : : /* Now follow all the conversions between integers
733 : : no more than a word long. */
734 : :
735 : : /* For truncation, usually we can just refer to FROM in a narrower mode. */
736 : 298966 : if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode)
737 : 149483 : && TRULY_NOOP_TRUNCATION_MODES_P (to_mode, from_mode))
738 : : {
739 : 161786 : if (!((MEM_P (from)
740 : 12811 : && ! MEM_VOLATILE_P (from)
741 : 12752 : && direct_load[(int) to_mode]
742 : 12752 : && ! mode_dependent_address_p (XEXP (from, 0),
743 : 12752 : MEM_ADDR_SPACE (from)))
744 : 136731 : || REG_P (from)
745 : : || GET_CODE (from) == SUBREG))
746 : 907 : from = force_reg (from_mode, from);
747 : 125335 : if (REG_P (from) && REGNO (from) < FIRST_PSEUDO_REGISTER
748 : 149484 : && !targetm.hard_regno_mode_ok (REGNO (from), to_mode))
749 : 0 : from = copy_to_reg (from);
750 : 149483 : emit_move_insn (to, gen_lowpart (to_mode, from));
751 : 149483 : return;
752 : : }
753 : :
754 : : /* Handle extension. */
755 : 0 : if (GET_MODE_PRECISION (to_mode) > GET_MODE_PRECISION (from_mode))
756 : : {
757 : : /* Convert directly if that works. */
758 : 0 : if ((code = can_extend_p (to_mode, from_mode, unsignedp))
759 : : != CODE_FOR_nothing)
760 : : {
761 : 0 : emit_unop_insn (code, to, from, equiv_code);
762 : 0 : return;
763 : : }
764 : : else
765 : : {
766 : 0 : rtx tmp;
767 : 0 : int shift_amount;
768 : :
769 : : /* Search for a mode to convert via. */
770 : 0 : opt_scalar_mode intermediate_iter;
771 : 0 : FOR_EACH_MODE_FROM (intermediate_iter, from_mode)
772 : : {
773 : 0 : scalar_mode intermediate = intermediate_iter.require ();
774 : 0 : if (((can_extend_p (to_mode, intermediate, unsignedp)
775 : : != CODE_FOR_nothing)
776 : 0 : || (GET_MODE_SIZE (to_mode) < GET_MODE_SIZE (intermediate)
777 : 0 : && TRULY_NOOP_TRUNCATION_MODES_P (to_mode,
778 : : intermediate)))
779 : 0 : && (can_extend_p (intermediate, from_mode, unsignedp)
780 : : != CODE_FOR_nothing))
781 : : {
782 : 0 : convert_move (to, convert_to_mode (intermediate, from,
783 : : unsignedp), unsignedp);
784 : 0 : return;
785 : : }
786 : : }
787 : :
788 : : /* No suitable intermediate mode.
789 : : Generate what we need with shifts. */
790 : 0 : shift_amount = (GET_MODE_PRECISION (to_mode)
791 : 0 : - GET_MODE_PRECISION (from_mode));
792 : 0 : from = gen_lowpart (to_mode, force_reg (from_mode, from));
793 : 0 : tmp = expand_shift (LSHIFT_EXPR, to_mode, from, shift_amount,
794 : : to, unsignedp);
795 : 0 : tmp = expand_shift (RSHIFT_EXPR, to_mode, tmp, shift_amount,
796 : : to, unsignedp);
797 : 0 : if (tmp != to)
798 : 0 : emit_move_insn (to, tmp);
799 : 0 : return;
800 : : }
801 : : }
802 : :
803 : : /* Support special truncate insns for certain modes. */
804 : 0 : if (convert_optab_handler (trunc_optab, to_mode,
805 : : from_mode) != CODE_FOR_nothing)
806 : : {
807 : 0 : emit_unop_insn (convert_optab_handler (trunc_optab, to_mode, from_mode),
808 : : to, from, UNKNOWN);
809 : 0 : return;
810 : : }
811 : :
812 : : /* Handle truncation of volatile memrefs, and so on;
813 : : the things that couldn't be truncated directly,
814 : : and for which there was no special instruction.
815 : :
816 : : ??? Code above formerly short-circuited this, for most integer
817 : : mode pairs, with a force_reg in from_mode followed by a recursive
818 : : call to this routine. Appears always to have been wrong. */
819 : 0 : if (GET_MODE_PRECISION (to_mode) < GET_MODE_PRECISION (from_mode))
820 : : {
821 : 0 : rtx temp = force_reg (to_mode, gen_lowpart (to_mode, from));
822 : 0 : emit_move_insn (to, temp);
823 : 0 : return;
824 : : }
825 : :
826 : : /* Mode combination is not recognized. */
827 : 0 : gcc_unreachable ();
828 : : }
829 : :
830 : : /* Return an rtx for a value that would result
831 : : from converting X to mode MODE.
832 : : Both X and MODE may be floating, or both integer.
833 : : UNSIGNEDP is nonzero if X is an unsigned value.
834 : : This can be done by referring to a part of X in place
835 : : or by copying to a new temporary with conversion. */
836 : :
837 : : rtx
838 : 1722167 : convert_to_mode (machine_mode mode, rtx x, int unsignedp)
839 : : {
840 : 1722167 : return convert_modes (mode, VOIDmode, x, unsignedp);
841 : : }
842 : :
843 : : /* Return an rtx for a value that would result
844 : : from converting X from mode OLDMODE to mode MODE.
845 : : Both modes may be floating, or both integer.
846 : : UNSIGNEDP is nonzero if X is an unsigned value.
847 : :
848 : : This can be done by referring to a part of X in place
849 : : or by copying to a new temporary with conversion.
850 : :
851 : : You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
852 : :
853 : : rtx
854 : 4049081 : convert_modes (machine_mode mode, machine_mode oldmode, rtx x, int unsignedp)
855 : : {
856 : 4049081 : rtx temp;
857 : 4049081 : scalar_int_mode int_mode;
858 : :
859 : : /* If FROM is a SUBREG that indicates that we have already done at least
860 : : the required extension, strip it. */
861 : :
862 : 4049081 : if (GET_CODE (x) == SUBREG
863 : 76736 : && SUBREG_PROMOTED_VAR_P (x)
864 : 4049081 : && is_a <scalar_int_mode> (mode, &int_mode)
865 : 4049081 : && (GET_MODE_PRECISION (subreg_promoted_mode (x))
866 : 3 : >= GET_MODE_PRECISION (int_mode))
867 : 4049084 : && SUBREG_CHECK_PROMOTED_SIGN (x, unsignedp))
868 : : {
869 : 3 : scalar_int_mode int_orig_mode;
870 : 3 : scalar_int_mode int_inner_mode;
871 : 3 : machine_mode orig_mode = GET_MODE (x);
872 : 3 : x = gen_lowpart (int_mode, SUBREG_REG (x));
873 : :
874 : : /* Preserve SUBREG_PROMOTED_VAR_P if the new mode is wider than
875 : : the original mode, but narrower than the inner mode. */
876 : 3 : if (GET_CODE (x) == SUBREG
877 : 0 : && is_a <scalar_int_mode> (orig_mode, &int_orig_mode)
878 : 0 : && GET_MODE_PRECISION (int_mode)
879 : 0 : > GET_MODE_PRECISION (int_orig_mode)
880 : 0 : && is_a <scalar_int_mode> (GET_MODE (SUBREG_REG (x)),
881 : : &int_inner_mode)
882 : 3 : && GET_MODE_PRECISION (int_inner_mode)
883 : 0 : > GET_MODE_PRECISION (int_mode))
884 : : {
885 : 0 : SUBREG_PROMOTED_VAR_P (x) = 1;
886 : 0 : SUBREG_PROMOTED_SET (x, unsignedp);
887 : : }
888 : : }
889 : :
890 : 4049081 : if (GET_MODE (x) != VOIDmode)
891 : 2201073 : oldmode = GET_MODE (x);
892 : :
893 : 4049081 : if (mode == oldmode)
894 : : return x;
895 : :
896 : 3061211 : if (CONST_SCALAR_INT_P (x)
897 : 3061211 : && is_a <scalar_int_mode> (mode, &int_mode))
898 : : {
899 : : /* If the caller did not tell us the old mode, then there is not
900 : : much to do with respect to canonicalization. We have to
901 : : assume that all the bits are significant. */
902 : 1532379 : if (!is_a <scalar_int_mode> (oldmode))
903 : 1469805 : oldmode = MAX_MODE_INT;
904 : 1532379 : wide_int w = wide_int::from (rtx_mode_t (x, oldmode),
905 : 1532379 : GET_MODE_PRECISION (int_mode),
906 : 2118115 : unsignedp ? UNSIGNED : SIGNED);
907 : 1532379 : return immed_wide_int_const (w, int_mode);
908 : 1532379 : }
909 : :
910 : : /* We can do this with a gen_lowpart if both desired and current modes
911 : : are integer, and this is either a constant integer, a register, or a
912 : : non-volatile MEM. */
913 : 1528832 : scalar_int_mode int_oldmode;
914 : 1528832 : if (is_int_mode (mode, &int_mode)
915 : 1439383 : && is_int_mode (oldmode, &int_oldmode)
916 : 1439383 : && GET_MODE_PRECISION (int_mode) <= GET_MODE_PRECISION (int_oldmode)
917 : 526062 : && ((MEM_P (x) && !MEM_VOLATILE_P (x) && direct_load[(int) int_mode])
918 : 10771 : || CONST_POLY_INT_P (x)
919 : 515291 : || (REG_P (x)
920 : 476493 : && (!HARD_REGISTER_P (x)
921 : 1053 : || targetm.hard_regno_mode_ok (REGNO (x), int_mode))
922 : 476493 : && TRULY_NOOP_TRUNCATION_MODES_P (int_mode, GET_MODE (x)))))
923 : 487264 : return gen_lowpart (int_mode, x);
924 : :
925 : : /* Converting from integer constant into mode is always equivalent to an
926 : : subreg operation. */
927 : 1041568 : if (VECTOR_MODE_P (mode) && GET_MODE (x) == VOIDmode)
928 : : {
929 : 0 : gcc_assert (known_eq (GET_MODE_BITSIZE (mode),
930 : : GET_MODE_BITSIZE (oldmode)));
931 : 0 : return simplify_gen_subreg (mode, x, oldmode, 0);
932 : : }
933 : :
934 : 1041568 : temp = gen_reg_rtx (mode);
935 : 1041568 : convert_move (temp, x, unsignedp);
936 : 1041568 : return temp;
937 : : }
938 : :
939 : : /* Variant of convert_modes for ABI parameter passing/return.
940 : : Return an rtx for a value that would result from converting X from
941 : : a floating point mode FMODE to wider integer mode MODE. */
942 : :
943 : : rtx
944 : 0 : convert_float_to_wider_int (machine_mode mode, machine_mode fmode, rtx x)
945 : : {
946 : 0 : gcc_assert (SCALAR_INT_MODE_P (mode) && SCALAR_FLOAT_MODE_P (fmode));
947 : 0 : scalar_int_mode tmp_mode = int_mode_for_mode (fmode).require ();
948 : 0 : rtx tmp = force_reg (tmp_mode, gen_lowpart (tmp_mode, x));
949 : 0 : return convert_modes (mode, tmp_mode, tmp, 1);
950 : : }
951 : :
952 : : /* Variant of convert_modes for ABI parameter passing/return.
953 : : Return an rtx for a value that would result from converting X from
954 : : an integer mode IMODE to a narrower floating point mode MODE. */
955 : :
956 : : rtx
957 : 0 : convert_wider_int_to_float (machine_mode mode, machine_mode imode, rtx x)
958 : : {
959 : 0 : gcc_assert (SCALAR_FLOAT_MODE_P (mode) && SCALAR_INT_MODE_P (imode));
960 : 0 : scalar_int_mode tmp_mode = int_mode_for_mode (mode).require ();
961 : 0 : rtx tmp = force_reg (tmp_mode, gen_lowpart (tmp_mode, x));
962 : 0 : return gen_lowpart_SUBREG (mode, tmp);
963 : : }
964 : :
965 : : /* Return the largest alignment we can use for doing a move (or store)
966 : : of MAX_PIECES. ALIGN is the largest alignment we could use. */
967 : :
968 : : static unsigned int
969 : 2583877 : alignment_for_piecewise_move (unsigned int max_pieces, unsigned int align)
970 : : {
971 : 2583877 : scalar_int_mode tmode
972 : 2583877 : = int_mode_for_size (max_pieces * BITS_PER_UNIT, 0).require ();
973 : :
974 : 2583877 : if (align >= GET_MODE_ALIGNMENT (tmode))
975 : 2003883 : align = GET_MODE_ALIGNMENT (tmode);
976 : : else
977 : : {
978 : 579994 : scalar_int_mode xmode = NARROWEST_INT_MODE;
979 : 579994 : opt_scalar_int_mode mode_iter;
980 : 3488479 : FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_INT)
981 : : {
982 : 3484300 : tmode = mode_iter.require ();
983 : 3484300 : if (GET_MODE_SIZE (tmode) > max_pieces
984 : 3484300 : || targetm.slow_unaligned_access (tmode, align))
985 : : break;
986 : 2908485 : xmode = tmode;
987 : : }
988 : :
989 : 579994 : align = MAX (align, GET_MODE_ALIGNMENT (xmode));
990 : : }
991 : :
992 : 2583877 : return align;
993 : : }
994 : :
995 : : /* Return true if we know how to implement OP using vectors of bytes. */
996 : : static bool
997 : 5532043 : can_use_qi_vectors (by_pieces_operation op)
998 : : {
999 : 5532043 : return (op == COMPARE_BY_PIECES
1000 : 5532043 : || op == SET_BY_PIECES
1001 : 5532043 : || op == CLEAR_BY_PIECES);
1002 : : }
1003 : :
1004 : : /* Return true if optabs exists for the mode and certain by pieces
1005 : : operations. */
1006 : : static bool
1007 : 25592775 : by_pieces_mode_supported_p (fixed_size_mode mode, by_pieces_operation op)
1008 : : {
1009 : 25592775 : if (optab_handler (mov_optab, mode) == CODE_FOR_nothing)
1010 : : return false;
1011 : :
1012 : 24787767 : if ((op == SET_BY_PIECES || op == CLEAR_BY_PIECES)
1013 : 1229197 : && VECTOR_MODE_P (mode)
1014 : 25866801 : && optab_handler (vec_duplicate_optab, mode) == CODE_FOR_nothing)
1015 : : return false;
1016 : :
1017 : 23976985 : if (op == COMPARE_BY_PIECES
1018 : 23976985 : && !can_compare_p (EQ, mode, ccp_jump))
1019 : : return false;
1020 : :
1021 : : return true;
1022 : : }
1023 : :
1024 : : /* Return the widest mode that can be used to perform part of an
1025 : : operation OP on SIZE bytes. Try to use QI vector modes where
1026 : : possible. */
1027 : : static fixed_size_mode
1028 : 5028599 : widest_fixed_size_mode_for_size (unsigned int size, by_pieces_operation op)
1029 : : {
1030 : 5028599 : fixed_size_mode result = NARROWEST_INT_MODE;
1031 : :
1032 : 5028599 : gcc_checking_assert (size > 1);
1033 : :
1034 : : /* Use QI vector only if size is wider than a WORD. */
1035 : 5090691 : if (can_use_qi_vectors (op) && size > UNITS_PER_WORD)
1036 : : {
1037 : 400406 : machine_mode mode;
1038 : 400406 : fixed_size_mode candidate;
1039 : 6730014 : FOR_EACH_MODE_IN_CLASS (mode, MODE_VECTOR_INT)
1040 : 6730014 : if (is_a<fixed_size_mode> (mode, &candidate)
1041 : 13460028 : && GET_MODE_INNER (candidate) == QImode)
1042 : : {
1043 : 5564706 : if (GET_MODE_SIZE (candidate) >= size)
1044 : : break;
1045 : 2381947 : if (by_pieces_mode_supported_p (candidate, op))
1046 : 6329608 : result = candidate;
1047 : : }
1048 : :
1049 : 400406 : if (result != NARROWEST_INT_MODE)
1050 : 258834 : return result;
1051 : : }
1052 : :
1053 : 4769765 : opt_scalar_int_mode tmode;
1054 : 4769765 : scalar_int_mode mode;
1055 : 38158120 : FOR_EACH_MODE_IN_CLASS (tmode, MODE_INT)
1056 : : {
1057 : 33388355 : mode = tmode.require ();
1058 : 33388355 : if (GET_MODE_SIZE (mode) < size
1059 : 33388355 : && by_pieces_mode_supported_p (mode, op))
1060 : 23174560 : result = mode;
1061 : : }
1062 : :
1063 : 4769765 : return result;
1064 : : }
1065 : :
1066 : : /* Determine whether an operation OP on LEN bytes with alignment ALIGN can
1067 : : and should be performed piecewise. */
1068 : :
1069 : : static bool
1070 : 936194 : can_do_by_pieces (unsigned HOST_WIDE_INT len, unsigned int align,
1071 : : enum by_pieces_operation op)
1072 : : {
1073 : 936194 : return targetm.use_by_pieces_infrastructure_p (len, align, op,
1074 : 936194 : optimize_insn_for_speed_p ());
1075 : : }
1076 : :
1077 : : /* Determine whether the LEN bytes can be moved by using several move
1078 : : instructions. Return nonzero if a call to move_by_pieces should
1079 : : succeed. */
1080 : :
1081 : : bool
1082 : 899654 : can_move_by_pieces (unsigned HOST_WIDE_INT len, unsigned int align)
1083 : : {
1084 : 899654 : return can_do_by_pieces (len, align, MOVE_BY_PIECES);
1085 : : }
1086 : :
1087 : : /* Return number of insns required to perform operation OP by pieces
1088 : : for L bytes. ALIGN (in bits) is maximum alignment we can assume. */
1089 : :
1090 : : unsigned HOST_WIDE_INT
1091 : 1821448 : by_pieces_ninsns (unsigned HOST_WIDE_INT l, unsigned int align,
1092 : : unsigned int max_size, by_pieces_operation op)
1093 : : {
1094 : 1821448 : unsigned HOST_WIDE_INT n_insns = 0;
1095 : 1821448 : fixed_size_mode mode;
1096 : :
1097 : 1821448 : if (targetm.overlap_op_by_pieces_p ())
1098 : : {
1099 : : /* NB: Round up L and ALIGN to the widest integer mode for
1100 : : MAX_SIZE. */
1101 : 1821448 : mode = widest_fixed_size_mode_for_size (max_size, op);
1102 : 1821448 : gcc_assert (optab_handler (mov_optab, mode) != CODE_FOR_nothing);
1103 : 3642896 : unsigned HOST_WIDE_INT up = ROUND_UP (l, GET_MODE_SIZE (mode));
1104 : 1821448 : if (up > l)
1105 : : l = up;
1106 : 1821448 : align = GET_MODE_ALIGNMENT (mode);
1107 : : }
1108 : :
1109 : 1821448 : align = alignment_for_piecewise_move (MOVE_MAX_PIECES, align);
1110 : :
1111 : 5481429 : while (max_size > 1 && l > 0)
1112 : : {
1113 : 1838533 : mode = widest_fixed_size_mode_for_size (max_size, op);
1114 : 1838533 : gcc_assert (optab_handler (mov_optab, mode) != CODE_FOR_nothing);
1115 : :
1116 : 1838533 : unsigned int modesize = GET_MODE_SIZE (mode);
1117 : :
1118 : 1838533 : if (align >= GET_MODE_ALIGNMENT (mode))
1119 : : {
1120 : 1838533 : unsigned HOST_WIDE_INT n_pieces = l / modesize;
1121 : 1838533 : l %= modesize;
1122 : 1838533 : switch (op)
1123 : : {
1124 : 1801993 : default:
1125 : 1801993 : n_insns += n_pieces;
1126 : 1801993 : break;
1127 : :
1128 : 36540 : case COMPARE_BY_PIECES:
1129 : 36540 : int batch = targetm.compare_by_pieces_branch_ratio (mode);
1130 : 36540 : int batch_ops = 4 * batch - 1;
1131 : 36540 : unsigned HOST_WIDE_INT full = n_pieces / batch;
1132 : 36540 : n_insns += full * batch_ops;
1133 : 36540 : if (n_pieces % batch != 0)
1134 : 0 : n_insns++;
1135 : : break;
1136 : :
1137 : : }
1138 : : }
1139 : : max_size = modesize;
1140 : : }
1141 : :
1142 : 1821448 : gcc_assert (!l);
1143 : 1821448 : return n_insns;
1144 : : }
1145 : :
1146 : : /* Used when performing piecewise block operations, holds information
1147 : : about one of the memory objects involved. The member functions
1148 : : can be used to generate code for loading from the object and
1149 : : updating the address when iterating. */
1150 : :
1151 : : class pieces_addr
1152 : : {
1153 : : /* The object being referenced, a MEM. Can be NULL_RTX to indicate
1154 : : stack pushes. */
1155 : : rtx m_obj;
1156 : : /* The address of the object. Can differ from that seen in the
1157 : : MEM rtx if we copied the address to a register. */
1158 : : rtx m_addr;
1159 : : /* Nonzero if the address on the object has an autoincrement already,
1160 : : signifies whether that was an increment or decrement. */
1161 : : signed char m_addr_inc;
1162 : : /* Nonzero if we intend to use autoinc without the address already
1163 : : having autoinc form. We will insert add insns around each memory
1164 : : reference, expecting later passes to form autoinc addressing modes.
1165 : : The only supported options are predecrement and postincrement. */
1166 : : signed char m_explicit_inc;
1167 : : /* True if we have either of the two possible cases of using
1168 : : autoincrement. */
1169 : : bool m_auto;
1170 : : /* True if this is an address to be used for load operations rather
1171 : : than stores. */
1172 : : bool m_is_load;
1173 : :
1174 : : /* Optionally, a function to obtain constants for any given offset into
1175 : : the objects, and data associated with it. */
1176 : : by_pieces_constfn m_constfn;
1177 : : void *m_cfndata;
1178 : : public:
1179 : : pieces_addr (rtx, bool, by_pieces_constfn, void *);
1180 : : rtx adjust (fixed_size_mode, HOST_WIDE_INT, by_pieces_prev * = nullptr);
1181 : : void increment_address (HOST_WIDE_INT);
1182 : : void maybe_predec (HOST_WIDE_INT);
1183 : : void maybe_postinc (HOST_WIDE_INT);
1184 : : void decide_autoinc (machine_mode, bool, HOST_WIDE_INT);
1185 : 711289 : int get_addr_inc ()
1186 : : {
1187 : 711289 : return m_addr_inc;
1188 : : }
1189 : : };
1190 : :
1191 : : /* Initialize a pieces_addr structure from an object OBJ. IS_LOAD is
1192 : : true if the operation to be performed on this object is a load
1193 : : rather than a store. For stores, OBJ can be NULL, in which case we
1194 : : assume the operation is a stack push. For loads, the optional
1195 : : CONSTFN and its associated CFNDATA can be used in place of the
1196 : : memory load. */
1197 : :
1198 : 1422578 : pieces_addr::pieces_addr (rtx obj, bool is_load, by_pieces_constfn constfn,
1199 : 1422578 : void *cfndata)
1200 : 1422578 : : m_obj (obj), m_is_load (is_load), m_constfn (constfn), m_cfndata (cfndata)
1201 : : {
1202 : 1422578 : m_addr_inc = 0;
1203 : 1422578 : m_auto = false;
1204 : 1422578 : if (obj)
1205 : : {
1206 : 1332531 : rtx addr = XEXP (obj, 0);
1207 : 1332531 : rtx_code code = GET_CODE (addr);
1208 : 1332531 : m_addr = addr;
1209 : 1332531 : bool dec = code == PRE_DEC || code == POST_DEC;
1210 : 1332531 : bool inc = code == PRE_INC || code == POST_INC;
1211 : 1332531 : m_auto = inc || dec;
1212 : 1332531 : if (m_auto)
1213 : 0 : m_addr_inc = dec ? -1 : 1;
1214 : :
1215 : : /* While we have always looked for these codes here, the code
1216 : : implementing the memory operation has never handled them.
1217 : : Support could be added later if necessary or beneficial. */
1218 : 1332531 : gcc_assert (code != PRE_INC && code != POST_DEC);
1219 : : }
1220 : : else
1221 : : {
1222 : 90047 : m_addr = NULL_RTX;
1223 : 90047 : if (!is_load)
1224 : : {
1225 : 46 : m_auto = true;
1226 : 46 : if (STACK_GROWS_DOWNWARD)
1227 : 46 : m_addr_inc = -1;
1228 : : else
1229 : : m_addr_inc = 1;
1230 : : }
1231 : : else
1232 : 90001 : gcc_assert (constfn != NULL);
1233 : : }
1234 : 1422578 : m_explicit_inc = 0;
1235 : 1422578 : if (constfn)
1236 : 112132 : gcc_assert (is_load);
1237 : 1422578 : }
1238 : :
1239 : : /* Decide whether to use autoinc for an address involved in a memory op.
1240 : : MODE is the mode of the accesses, REVERSE is true if we've decided to
1241 : : perform the operation starting from the end, and LEN is the length of
1242 : : the operation. Don't override an earlier decision to set m_auto. */
1243 : :
1244 : : void
1245 : 357104 : pieces_addr::decide_autoinc (machine_mode ARG_UNUSED (mode), bool reverse,
1246 : : HOST_WIDE_INT len)
1247 : : {
1248 : 357104 : if (m_auto || m_obj == NULL_RTX)
1249 : : return;
1250 : :
1251 : 335648 : bool use_predec = (m_is_load
1252 : : ? USE_LOAD_PRE_DECREMENT (mode)
1253 : : : USE_STORE_PRE_DECREMENT (mode));
1254 : 335648 : bool use_postinc = (m_is_load
1255 : : ? USE_LOAD_POST_INCREMENT (mode)
1256 : : : USE_STORE_POST_INCREMENT (mode));
1257 : 335648 : machine_mode addr_mode = get_address_mode (m_obj);
1258 : :
1259 : 335648 : if (use_predec && reverse)
1260 : : {
1261 : : m_addr = copy_to_mode_reg (addr_mode,
1262 : : plus_constant (addr_mode,
1263 : : m_addr, len));
1264 : : m_auto = true;
1265 : : m_explicit_inc = -1;
1266 : : }
1267 : 335648 : else if (use_postinc && !reverse)
1268 : : {
1269 : : m_addr = copy_to_mode_reg (addr_mode, m_addr);
1270 : : m_auto = true;
1271 : : m_explicit_inc = 1;
1272 : : }
1273 : 335648 : else if (CONSTANT_P (m_addr))
1274 : 70378 : m_addr = copy_to_mode_reg (addr_mode, m_addr);
1275 : : }
1276 : :
1277 : : /* Adjust the address to refer to the data at OFFSET in MODE. If we
1278 : : are using autoincrement for this address, we don't add the offset,
1279 : : but we still modify the MEM's properties. */
1280 : :
1281 : : rtx
1282 : 3951544 : pieces_addr::adjust (fixed_size_mode mode, HOST_WIDE_INT offset,
1283 : : by_pieces_prev *prev)
1284 : : {
1285 : 3951544 : if (m_constfn)
1286 : : /* Pass the previous data to m_constfn. */
1287 : 263496 : return m_constfn (m_cfndata, prev, offset, mode);
1288 : 3688048 : if (m_obj == NULL_RTX)
1289 : : return NULL_RTX;
1290 : 3688000 : if (m_auto)
1291 : 0 : return adjust_automodify_address (m_obj, mode, m_addr, offset);
1292 : : else
1293 : 3688000 : return adjust_address (m_obj, mode, offset);
1294 : : }
1295 : :
1296 : : /* Emit an add instruction to increment the address by SIZE. */
1297 : :
1298 : : void
1299 : 0 : pieces_addr::increment_address (HOST_WIDE_INT size)
1300 : : {
1301 : 0 : rtx amount = gen_int_mode (size, GET_MODE (m_addr));
1302 : 0 : emit_insn (gen_add2_insn (m_addr, amount));
1303 : 0 : }
1304 : :
1305 : : /* If we are supposed to decrement the address after each access, emit code
1306 : : to do so now. Increment by SIZE (which has should have the correct sign
1307 : : already). */
1308 : :
1309 : : void
1310 : 3951010 : pieces_addr::maybe_predec (HOST_WIDE_INT size)
1311 : : {
1312 : 3951010 : if (m_explicit_inc >= 0)
1313 : 3951010 : return;
1314 : 0 : gcc_assert (HAVE_PRE_DECREMENT);
1315 : : increment_address (size);
1316 : : }
1317 : :
1318 : : /* If we are supposed to decrement the address after each access, emit code
1319 : : to do so now. Increment by SIZE. */
1320 : :
1321 : : void
1322 : 3951033 : pieces_addr::maybe_postinc (HOST_WIDE_INT size)
1323 : : {
1324 : 3951033 : if (m_explicit_inc <= 0)
1325 : 3951033 : return;
1326 : 0 : gcc_assert (HAVE_POST_INCREMENT);
1327 : : increment_address (size);
1328 : : }
1329 : :
1330 : : /* This structure is used by do_op_by_pieces to describe the operation
1331 : : to be performed. */
1332 : :
1333 : : class op_by_pieces_d
1334 : : {
1335 : : private:
1336 : : fixed_size_mode get_usable_mode (fixed_size_mode, unsigned int);
1337 : : fixed_size_mode smallest_fixed_size_mode_for_size (unsigned int);
1338 : :
1339 : : protected:
1340 : : pieces_addr m_to, m_from;
1341 : : /* Make m_len read-only so that smallest_fixed_size_mode_for_size can
1342 : : use it to check the valid mode size. */
1343 : : const unsigned HOST_WIDE_INT m_len;
1344 : : HOST_WIDE_INT m_offset;
1345 : : unsigned int m_align;
1346 : : unsigned int m_max_size;
1347 : : bool m_reverse;
1348 : : /* True if this is a stack push. */
1349 : : bool m_push;
1350 : : /* True if targetm.overlap_op_by_pieces_p () returns true. */
1351 : : bool m_overlap_op_by_pieces;
1352 : : /* The type of operation that we're performing. */
1353 : : by_pieces_operation m_op;
1354 : :
1355 : : /* Virtual functions, overriden by derived classes for the specific
1356 : : operation. */
1357 : : virtual void generate (rtx, rtx, machine_mode) = 0;
1358 : : virtual bool prepare_mode (machine_mode, unsigned int) = 0;
1359 : 1154215 : virtual void finish_mode (machine_mode)
1360 : : {
1361 : 1154215 : }
1362 : :
1363 : : public:
1364 : : op_by_pieces_d (unsigned int, rtx, bool, rtx, bool, by_pieces_constfn,
1365 : : void *, unsigned HOST_WIDE_INT, unsigned int, bool,
1366 : : by_pieces_operation);
1367 : : void run ();
1368 : : };
1369 : :
1370 : : /* The constructor for an op_by_pieces_d structure. We require two
1371 : : objects named TO and FROM, which are identified as loads or stores
1372 : : by TO_LOAD and FROM_LOAD. If FROM is a load, the optional FROM_CFN
1373 : : and its associated FROM_CFN_DATA can be used to replace loads with
1374 : : constant values. MAX_PIECES describes the maximum number of bytes
1375 : : at a time which can be moved efficiently. LEN describes the length
1376 : : of the operation. */
1377 : :
1378 : 711289 : op_by_pieces_d::op_by_pieces_d (unsigned int max_pieces, rtx to,
1379 : : bool to_load, rtx from, bool from_load,
1380 : : by_pieces_constfn from_cfn,
1381 : : void *from_cfn_data,
1382 : : unsigned HOST_WIDE_INT len,
1383 : : unsigned int align, bool push,
1384 : 711289 : by_pieces_operation op)
1385 : 711289 : : m_to (to, to_load, NULL, NULL),
1386 : 711289 : m_from (from, from_load, from_cfn, from_cfn_data),
1387 : 711289 : m_len (len), m_max_size (max_pieces + 1),
1388 : 711289 : m_push (push), m_op (op)
1389 : : {
1390 : 711289 : int toi = m_to.get_addr_inc ();
1391 : 711289 : int fromi = m_from.get_addr_inc ();
1392 : 711289 : if (toi >= 0 && fromi >= 0)
1393 : 711243 : m_reverse = false;
1394 : 46 : else if (toi <= 0 && fromi <= 0)
1395 : 46 : m_reverse = true;
1396 : : else
1397 : 0 : gcc_unreachable ();
1398 : :
1399 : 711289 : m_offset = m_reverse ? len : 0;
1400 : 2665114 : align = MIN (to ? MEM_ALIGN (to) : align,
1401 : : from ? MEM_ALIGN (from) : align);
1402 : :
1403 : : /* If copying requires more than two move insns,
1404 : : copy addresses to registers (to make displacements shorter)
1405 : : and use post-increment if available. */
1406 : 711289 : if (by_pieces_ninsns (len, align, m_max_size, MOVE_BY_PIECES) > 2)
1407 : : {
1408 : : /* Find the mode of the largest comparison. */
1409 : 178552 : fixed_size_mode mode
1410 : 178552 : = widest_fixed_size_mode_for_size (m_max_size, m_op);
1411 : :
1412 : 178552 : m_from.decide_autoinc (mode, m_reverse, len);
1413 : 178552 : m_to.decide_autoinc (mode, m_reverse, len);
1414 : : }
1415 : :
1416 : 711289 : align = alignment_for_piecewise_move (MOVE_MAX_PIECES, align);
1417 : 711289 : m_align = align;
1418 : :
1419 : 711289 : m_overlap_op_by_pieces = targetm.overlap_op_by_pieces_p ();
1420 : 711289 : }
1421 : :
1422 : : /* This function returns the largest usable integer mode for LEN bytes
1423 : : whose size is no bigger than size of MODE. */
1424 : :
1425 : : fixed_size_mode
1426 : 1214733 : op_by_pieces_d::get_usable_mode (fixed_size_mode mode, unsigned int len)
1427 : : {
1428 : 1498123 : unsigned int size;
1429 : 1781513 : do
1430 : : {
1431 : 1498123 : size = GET_MODE_SIZE (mode);
1432 : 1498123 : if (len >= size && prepare_mode (mode, m_align))
1433 : : break;
1434 : : /* widest_fixed_size_mode_for_size checks SIZE > 1. */
1435 : 283390 : mode = widest_fixed_size_mode_for_size (size, m_op);
1436 : : }
1437 : : while (1);
1438 : 1214733 : return mode;
1439 : : }
1440 : :
1441 : : /* Return the smallest integer or QI vector mode that is not narrower
1442 : : than SIZE bytes. */
1443 : :
1444 : : fixed_size_mode
1445 : 503444 : op_by_pieces_d::smallest_fixed_size_mode_for_size (unsigned int size)
1446 : : {
1447 : : /* Use QI vector only for > size of WORD. */
1448 : 514593 : if (can_use_qi_vectors (m_op) && size > UNITS_PER_WORD)
1449 : : {
1450 : 6445 : machine_mode mode;
1451 : 6445 : fixed_size_mode candidate;
1452 : 87579 : FOR_EACH_MODE_IN_CLASS (mode, MODE_VECTOR_INT)
1453 : 168713 : if (is_a<fixed_size_mode> (mode, &candidate)
1454 : 175158 : && GET_MODE_INNER (candidate) == QImode)
1455 : : {
1456 : : /* Don't return a mode wider than M_LEN. */
1457 : 81178 : if (GET_MODE_SIZE (candidate) > m_len)
1458 : : break;
1459 : :
1460 : 39033 : if (GET_MODE_SIZE (candidate) >= size
1461 : 39033 : && by_pieces_mode_supported_p (candidate, m_op))
1462 : 4889 : return candidate;
1463 : : }
1464 : : }
1465 : :
1466 : 498555 : return smallest_int_mode_for_size (size * BITS_PER_UNIT);
1467 : : }
1468 : :
1469 : : /* This function contains the main loop used for expanding a block
1470 : : operation. First move what we can in the largest integer mode,
1471 : : then go to successively smaller modes. For every access, call
1472 : : GENFUN with the two operands and the EXTRA_DATA. */
1473 : :
1474 : : void
1475 : 711289 : op_by_pieces_d::run ()
1476 : : {
1477 : 711289 : if (m_len == 0)
1478 : : return;
1479 : :
1480 : 711289 : unsigned HOST_WIDE_INT length = m_len;
1481 : :
1482 : : /* widest_fixed_size_mode_for_size checks M_MAX_SIZE > 1. */
1483 : 711289 : fixed_size_mode mode
1484 : 711289 : = widest_fixed_size_mode_for_size (m_max_size, m_op);
1485 : 711289 : mode = get_usable_mode (mode, length);
1486 : :
1487 : 711289 : by_pieces_prev to_prev = { nullptr, mode };
1488 : 711289 : by_pieces_prev from_prev = { nullptr, mode };
1489 : :
1490 : 1214733 : do
1491 : : {
1492 : 1214733 : unsigned int size = GET_MODE_SIZE (mode);
1493 : 1214733 : rtx to1 = NULL_RTX, from1;
1494 : :
1495 : 3190238 : while (length >= size)
1496 : : {
1497 : 1975505 : if (m_reverse)
1498 : 48 : m_offset -= size;
1499 : :
1500 : 1975505 : to1 = m_to.adjust (mode, m_offset, &to_prev);
1501 : 1975505 : to_prev.data = to1;
1502 : 1975505 : to_prev.mode = mode;
1503 : 1975505 : from1 = m_from.adjust (mode, m_offset, &from_prev);
1504 : 1975505 : from_prev.data = from1;
1505 : 1975505 : from_prev.mode = mode;
1506 : :
1507 : 1975505 : m_to.maybe_predec (-(HOST_WIDE_INT)size);
1508 : 1975505 : m_from.maybe_predec (-(HOST_WIDE_INT)size);
1509 : :
1510 : 1975505 : generate (to1, from1, mode);
1511 : :
1512 : 1975505 : m_to.maybe_postinc (size);
1513 : 1975505 : m_from.maybe_postinc (size);
1514 : :
1515 : 1975505 : if (!m_reverse)
1516 : 1975457 : m_offset += size;
1517 : :
1518 : 1975505 : length -= size;
1519 : : }
1520 : :
1521 : 1214733 : finish_mode (mode);
1522 : :
1523 : 1214733 : if (length == 0)
1524 : : return;
1525 : :
1526 : 503444 : if (!m_push && m_overlap_op_by_pieces)
1527 : : {
1528 : : /* NB: Generate overlapping operations if it is not a stack
1529 : : push since stack push must not overlap. Get the smallest
1530 : : fixed size mode for M_LEN bytes. */
1531 : 503444 : mode = smallest_fixed_size_mode_for_size (length);
1532 : 1006888 : mode = get_usable_mode (mode, GET_MODE_SIZE (mode));
1533 : 503444 : int gap = GET_MODE_SIZE (mode) - length;
1534 : 503444 : if (gap > 0)
1535 : : {
1536 : : /* If size of MODE > M_LEN, generate the last operation
1537 : : in MODE for the remaining bytes with ovelapping memory
1538 : : from the previois operation. */
1539 : 45394 : if (m_reverse)
1540 : 0 : m_offset += gap;
1541 : : else
1542 : 45394 : m_offset -= gap;
1543 : 45394 : length += gap;
1544 : : }
1545 : : }
1546 : : else
1547 : : {
1548 : : /* widest_fixed_size_mode_for_size checks SIZE > 1. */
1549 : 0 : mode = widest_fixed_size_mode_for_size (size, m_op);
1550 : 0 : mode = get_usable_mode (mode, length);
1551 : : }
1552 : : }
1553 : : while (1);
1554 : : }
1555 : :
1556 : : /* Derived class from op_by_pieces_d, providing support for block move
1557 : : operations. */
1558 : :
1559 : : #ifdef PUSH_ROUNDING
1560 : : #define PUSHG_P(to) ((to) == nullptr)
1561 : : #else
1562 : : #define PUSHG_P(to) false
1563 : : #endif
1564 : :
1565 : : class move_by_pieces_d : public op_by_pieces_d
1566 : : {
1567 : : insn_gen_fn m_gen_fun;
1568 : : void generate (rtx, rtx, machine_mode) final override;
1569 : : bool prepare_mode (machine_mode, unsigned int) final override;
1570 : :
1571 : : public:
1572 : 587576 : move_by_pieces_d (rtx to, rtx from, unsigned HOST_WIDE_INT len,
1573 : : unsigned int align)
1574 : 587576 : : op_by_pieces_d (MOVE_MAX_PIECES, to, false, from, true, NULL,
1575 : 1175152 : NULL, len, align, PUSHG_P (to), MOVE_BY_PIECES)
1576 : : {
1577 : 587576 : }
1578 : : rtx finish_retmode (memop_ret);
1579 : : };
1580 : :
1581 : : /* Return true if MODE can be used for a set of copies, given an
1582 : : alignment ALIGN. Prepare whatever data is necessary for later
1583 : : calls to generate. */
1584 : :
1585 : : bool
1586 : 1001532 : move_by_pieces_d::prepare_mode (machine_mode mode, unsigned int align)
1587 : : {
1588 : 1001532 : insn_code icode = optab_handler (mov_optab, mode);
1589 : 1001532 : m_gen_fun = GEN_FCN (icode);
1590 : 1001532 : return icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode);
1591 : : }
1592 : :
1593 : : /* A callback used when iterating for a compare_by_pieces_operation.
1594 : : OP0 and OP1 are the values that have been loaded and should be
1595 : : compared in MODE. If OP0 is NULL, this means we should generate a
1596 : : push; otherwise EXTRA_DATA holds a pointer to a pointer to the insn
1597 : : gen function that should be used to generate the mode. */
1598 : :
1599 : : void
1600 : 1692601 : move_by_pieces_d::generate (rtx op0, rtx op1,
1601 : : machine_mode mode ATTRIBUTE_UNUSED)
1602 : : {
1603 : : #ifdef PUSH_ROUNDING
1604 : 1692601 : if (op0 == NULL_RTX)
1605 : : {
1606 : 48 : emit_single_push_insn (mode, op1, NULL);
1607 : 48 : return;
1608 : : }
1609 : : #endif
1610 : 1692553 : emit_insn (m_gen_fun (op0, op1));
1611 : : }
1612 : :
1613 : : /* Perform the final adjustment at the end of a string to obtain the
1614 : : correct return value for the block operation.
1615 : : Return value is based on RETMODE argument. */
1616 : :
1617 : : rtx
1618 : 0 : move_by_pieces_d::finish_retmode (memop_ret retmode)
1619 : : {
1620 : 0 : gcc_assert (!m_reverse);
1621 : 0 : if (retmode == RETURN_END_MINUS_ONE)
1622 : : {
1623 : 0 : m_to.maybe_postinc (-1);
1624 : 0 : --m_offset;
1625 : : }
1626 : 0 : return m_to.adjust (QImode, m_offset);
1627 : : }
1628 : :
1629 : : /* Generate several move instructions to copy LEN bytes from block FROM to
1630 : : block TO. (These are MEM rtx's with BLKmode).
1631 : :
1632 : : If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
1633 : : used to push FROM to the stack.
1634 : :
1635 : : ALIGN is maximum stack alignment we can assume.
1636 : :
1637 : : Return value is based on RETMODE argument. */
1638 : :
1639 : : rtx
1640 : 587576 : move_by_pieces (rtx to, rtx from, unsigned HOST_WIDE_INT len,
1641 : : unsigned int align, memop_ret retmode)
1642 : : {
1643 : : #ifndef PUSH_ROUNDING
1644 : : if (to == NULL)
1645 : : gcc_unreachable ();
1646 : : #endif
1647 : :
1648 : 587576 : move_by_pieces_d data (to, from, len, align);
1649 : :
1650 : 587576 : data.run ();
1651 : :
1652 : 587576 : if (retmode != RETURN_BEGIN)
1653 : 0 : return data.finish_retmode (retmode);
1654 : : else
1655 : : return to;
1656 : : }
1657 : :
1658 : : /* Derived class from op_by_pieces_d, providing support for block move
1659 : : operations. */
1660 : :
1661 : : class store_by_pieces_d : public op_by_pieces_d
1662 : : {
1663 : : insn_gen_fn m_gen_fun;
1664 : :
1665 : : void generate (rtx, rtx, machine_mode) final override;
1666 : : bool prepare_mode (machine_mode, unsigned int) final override;
1667 : :
1668 : : public:
1669 : 90001 : store_by_pieces_d (rtx to, by_pieces_constfn cfn, void *cfn_data,
1670 : : unsigned HOST_WIDE_INT len, unsigned int align,
1671 : : by_pieces_operation op)
1672 : 90001 : : op_by_pieces_d (STORE_MAX_PIECES, to, false, NULL_RTX, true, cfn,
1673 : 180002 : cfn_data, len, align, false, op)
1674 : : {
1675 : 90001 : }
1676 : : rtx finish_retmode (memop_ret);
1677 : : };
1678 : :
1679 : : /* Return true if MODE can be used for a set of stores, given an
1680 : : alignment ALIGN. Prepare whatever data is necessary for later
1681 : : calls to generate. */
1682 : :
1683 : : bool
1684 : 152683 : store_by_pieces_d::prepare_mode (machine_mode mode, unsigned int align)
1685 : : {
1686 : 152683 : insn_code icode = optab_handler (mov_optab, mode);
1687 : 152683 : m_gen_fun = GEN_FCN (icode);
1688 : 152683 : return icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode);
1689 : : }
1690 : :
1691 : : /* A callback used when iterating for a store_by_pieces_operation.
1692 : : OP0 and OP1 are the values that have been loaded and should be
1693 : : compared in MODE. If OP0 is NULL, this means we should generate a
1694 : : push; otherwise EXTRA_DATA holds a pointer to a pointer to the insn
1695 : : gen function that should be used to generate the mode. */
1696 : :
1697 : : void
1698 : 219162 : store_by_pieces_d::generate (rtx op0, rtx op1, machine_mode)
1699 : : {
1700 : 219162 : emit_insn (m_gen_fun (op0, op1));
1701 : 219162 : }
1702 : :
1703 : : /* Perform the final adjustment at the end of a string to obtain the
1704 : : correct return value for the block operation.
1705 : : Return value is based on RETMODE argument. */
1706 : :
1707 : : rtx
1708 : 534 : store_by_pieces_d::finish_retmode (memop_ret retmode)
1709 : : {
1710 : 534 : gcc_assert (!m_reverse);
1711 : 534 : if (retmode == RETURN_END_MINUS_ONE)
1712 : : {
1713 : 23 : m_to.maybe_postinc (-1);
1714 : 23 : --m_offset;
1715 : : }
1716 : 534 : return m_to.adjust (QImode, m_offset);
1717 : : }
1718 : :
1719 : : /* Determine whether the LEN bytes generated by CONSTFUN can be
1720 : : stored to memory using several move instructions. CONSTFUNDATA is
1721 : : a pointer which will be passed as argument in every CONSTFUN call.
1722 : : ALIGN is maximum alignment we can assume. MEMSETP is true if this is
1723 : : a memset operation and false if it's a copy of a constant string.
1724 : : Return true if a call to store_by_pieces should succeed. */
1725 : :
1726 : : bool
1727 : 66653 : can_store_by_pieces (unsigned HOST_WIDE_INT len,
1728 : : by_pieces_constfn constfun,
1729 : : void *constfundata, unsigned int align, bool memsetp)
1730 : : {
1731 : 66653 : unsigned HOST_WIDE_INT l;
1732 : 66653 : unsigned int max_size;
1733 : 66653 : HOST_WIDE_INT offset = 0;
1734 : 66653 : enum insn_code icode;
1735 : 66653 : int reverse;
1736 : : /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
1737 : 66653 : rtx cst ATTRIBUTE_UNUSED;
1738 : :
1739 : 66653 : if (len == 0)
1740 : : return true;
1741 : :
1742 : 112087 : if (!targetm.use_by_pieces_infrastructure_p (len, align,
1743 : : memsetp
1744 : : ? SET_BY_PIECES
1745 : : : STORE_BY_PIECES,
1746 : 66609 : optimize_insn_for_speed_p ()))
1747 : : return false;
1748 : :
1749 : 51140 : align = alignment_for_piecewise_move (STORE_MAX_PIECES, align);
1750 : :
1751 : : /* We would first store what we can in the largest integer mode, then go to
1752 : : successively smaller modes. */
1753 : :
1754 : 51140 : for (reverse = 0;
1755 : 102280 : reverse <= (HAVE_PRE_DECREMENT || HAVE_POST_DECREMENT);
1756 : : reverse++)
1757 : : {
1758 : 51140 : l = len;
1759 : 51140 : max_size = STORE_MAX_PIECES + 1;
1760 : 246527 : while (max_size > 1 && l > 0)
1761 : : {
1762 : 195387 : auto op = memsetp ? SET_BY_PIECES : STORE_BY_PIECES;
1763 : 195387 : auto mode = widest_fixed_size_mode_for_size (max_size, op);
1764 : :
1765 : 195387 : icode = optab_handler (mov_optab, mode);
1766 : 195387 : if (icode != CODE_FOR_nothing
1767 : 195387 : && align >= GET_MODE_ALIGNMENT (mode))
1768 : : {
1769 : 195387 : unsigned int size = GET_MODE_SIZE (mode);
1770 : :
1771 : 337290 : while (l >= size)
1772 : : {
1773 : 141903 : if (reverse)
1774 : : offset -= size;
1775 : :
1776 : 141903 : cst = (*constfun) (constfundata, nullptr, offset, mode);
1777 : : /* All CONST_VECTORs can be loaded for memset since
1778 : : vec_duplicate_optab is a precondition to pick a
1779 : : vector mode for the memset expander. */
1780 : 271539 : if (!((memsetp && VECTOR_MODE_P (mode))
1781 : 129636 : || targetm.legitimate_constant_p (mode, cst)))
1782 : 15469 : return false;
1783 : :
1784 : 141903 : if (!reverse)
1785 : 141903 : offset += size;
1786 : :
1787 : 141903 : l -= size;
1788 : : }
1789 : : }
1790 : :
1791 : 390774 : max_size = GET_MODE_SIZE (mode);
1792 : : }
1793 : :
1794 : : /* The code above should have handled everything. */
1795 : 51140 : gcc_assert (!l);
1796 : : }
1797 : :
1798 : : return true;
1799 : : }
1800 : :
1801 : : /* Generate several move instructions to store LEN bytes generated by
1802 : : CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
1803 : : pointer which will be passed as argument in every CONSTFUN call.
1804 : : ALIGN is maximum alignment we can assume. MEMSETP is true if this is
1805 : : a memset operation and false if it's a copy of a constant string.
1806 : : Return value is based on RETMODE argument. */
1807 : :
1808 : : rtx
1809 : 48509 : store_by_pieces (rtx to, unsigned HOST_WIDE_INT len,
1810 : : by_pieces_constfn constfun,
1811 : : void *constfundata, unsigned int align, bool memsetp,
1812 : : memop_ret retmode)
1813 : : {
1814 : 48509 : if (len == 0)
1815 : : {
1816 : 43 : gcc_assert (retmode != RETURN_END_MINUS_ONE);
1817 : : return to;
1818 : : }
1819 : :
1820 : 89992 : gcc_assert (targetm.use_by_pieces_infrastructure_p
1821 : : (len, align,
1822 : : memsetp ? SET_BY_PIECES : STORE_BY_PIECES,
1823 : : optimize_insn_for_speed_p ()));
1824 : :
1825 : 48466 : store_by_pieces_d data (to, constfun, constfundata, len, align,
1826 : 48466 : memsetp ? SET_BY_PIECES : STORE_BY_PIECES);
1827 : 48466 : data.run ();
1828 : :
1829 : 48466 : if (retmode != RETURN_BEGIN)
1830 : 534 : return data.finish_retmode (retmode);
1831 : : else
1832 : : return to;
1833 : : }
1834 : :
1835 : : /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
1836 : : rtx with BLKmode). ALIGN is maximum alignment we can assume. */
1837 : :
1838 : : static void
1839 : 41535 : clear_by_pieces (rtx to, unsigned HOST_WIDE_INT len, unsigned int align)
1840 : : {
1841 : 41535 : if (len == 0)
1842 : 0 : return;
1843 : :
1844 : : /* Use builtin_memset_read_str to support vector mode broadcast. */
1845 : 41535 : char c = 0;
1846 : 41535 : store_by_pieces_d data (to, builtin_memset_read_str, &c, len, align,
1847 : 41535 : CLEAR_BY_PIECES);
1848 : 41535 : data.run ();
1849 : : }
1850 : :
1851 : : /* Context used by compare_by_pieces_genfn. It stores the fail label
1852 : : to jump to in case of miscomparison, and for branch ratios greater than 1,
1853 : : it stores an accumulator and the current and maximum counts before
1854 : : emitting another branch. */
1855 : :
1856 : : class compare_by_pieces_d : public op_by_pieces_d
1857 : : {
1858 : : rtx_code_label *m_fail_label;
1859 : : rtx m_accumulator;
1860 : : int m_count, m_batch;
1861 : :
1862 : : void generate (rtx, rtx, machine_mode) final override;
1863 : : bool prepare_mode (machine_mode, unsigned int) final override;
1864 : : void finish_mode (machine_mode) final override;
1865 : :
1866 : : public:
1867 : 33712 : compare_by_pieces_d (rtx op0, rtx op1, by_pieces_constfn op1_cfn,
1868 : : void *op1_cfn_data, HOST_WIDE_INT len, int align,
1869 : : rtx_code_label *fail_label)
1870 : 33712 : : op_by_pieces_d (COMPARE_MAX_PIECES, op0, true, op1, true, op1_cfn,
1871 : 67424 : op1_cfn_data, len, align, false, COMPARE_BY_PIECES)
1872 : : {
1873 : 33712 : m_fail_label = fail_label;
1874 : 33712 : }
1875 : : };
1876 : :
1877 : : /* A callback used when iterating for a compare_by_pieces_operation.
1878 : : OP0 and OP1 are the values that have been loaded and should be
1879 : : compared in MODE. DATA holds a pointer to the compare_by_pieces_data
1880 : : context structure. */
1881 : :
1882 : : void
1883 : 63742 : compare_by_pieces_d::generate (rtx op0, rtx op1, machine_mode mode)
1884 : : {
1885 : 63742 : if (m_batch > 1)
1886 : : {
1887 : 0 : rtx temp = expand_binop (mode, sub_optab, op0, op1, NULL_RTX,
1888 : : true, OPTAB_LIB_WIDEN);
1889 : 0 : if (m_count != 0)
1890 : 0 : temp = expand_binop (mode, ior_optab, m_accumulator, temp, temp,
1891 : : true, OPTAB_LIB_WIDEN);
1892 : 0 : m_accumulator = temp;
1893 : :
1894 : 0 : if (++m_count < m_batch)
1895 : : return;
1896 : :
1897 : 0 : m_count = 0;
1898 : 0 : op0 = m_accumulator;
1899 : 0 : op1 = const0_rtx;
1900 : 0 : m_accumulator = NULL_RTX;
1901 : : }
1902 : 63742 : do_compare_rtx_and_jump (op0, op1, NE, true, mode, NULL_RTX, NULL,
1903 : : m_fail_label, profile_probability::uninitialized ());
1904 : : }
1905 : :
1906 : : /* Return true if MODE can be used for a set of moves and comparisons,
1907 : : given an alignment ALIGN. Prepare whatever data is necessary for
1908 : : later calls to generate. */
1909 : :
1910 : : bool
1911 : 60518 : compare_by_pieces_d::prepare_mode (machine_mode mode, unsigned int align)
1912 : : {
1913 : 60518 : insn_code icode = optab_handler (mov_optab, mode);
1914 : 60518 : if (icode == CODE_FOR_nothing
1915 : 60518 : || align < GET_MODE_ALIGNMENT (mode)
1916 : 121036 : || !can_compare_p (EQ, mode, ccp_jump))
1917 : 0 : return false;
1918 : 60518 : m_batch = targetm.compare_by_pieces_branch_ratio (mode);
1919 : 60518 : if (m_batch < 0)
1920 : : return false;
1921 : 60518 : m_accumulator = NULL_RTX;
1922 : 60518 : m_count = 0;
1923 : 60518 : return true;
1924 : : }
1925 : :
1926 : : /* Called after expanding a series of comparisons in MODE. If we have
1927 : : accumulated results for which we haven't emitted a branch yet, do
1928 : : so now. */
1929 : :
1930 : : void
1931 : 60518 : compare_by_pieces_d::finish_mode (machine_mode mode)
1932 : : {
1933 : 60518 : if (m_accumulator != NULL_RTX)
1934 : 0 : do_compare_rtx_and_jump (m_accumulator, const0_rtx, NE, true, mode,
1935 : : NULL_RTX, NULL, m_fail_label,
1936 : : profile_probability::uninitialized ());
1937 : 60518 : }
1938 : :
1939 : : /* Generate several move instructions to compare LEN bytes from blocks
1940 : : ARG0 and ARG1. (These are MEM rtx's with BLKmode).
1941 : :
1942 : : If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
1943 : : used to push FROM to the stack.
1944 : :
1945 : : ALIGN is maximum stack alignment we can assume.
1946 : :
1947 : : Optionally, the caller can pass a constfn and associated data in A1_CFN
1948 : : and A1_CFN_DATA. describing that the second operand being compared is a
1949 : : known constant and how to obtain its data. */
1950 : :
1951 : : static rtx
1952 : 33712 : compare_by_pieces (rtx arg0, rtx arg1, unsigned HOST_WIDE_INT len,
1953 : : rtx target, unsigned int align,
1954 : : by_pieces_constfn a1_cfn, void *a1_cfn_data)
1955 : : {
1956 : 33712 : rtx_code_label *fail_label = gen_label_rtx ();
1957 : 33712 : rtx_code_label *end_label = gen_label_rtx ();
1958 : :
1959 : 33712 : if (target == NULL_RTX
1960 : 33712 : || !REG_P (target) || REGNO (target) < FIRST_PSEUDO_REGISTER)
1961 : 1 : target = gen_reg_rtx (TYPE_MODE (integer_type_node));
1962 : :
1963 : 33712 : compare_by_pieces_d data (arg0, arg1, a1_cfn, a1_cfn_data, len, align,
1964 : 33712 : fail_label);
1965 : :
1966 : 33712 : data.run ();
1967 : :
1968 : 33712 : emit_move_insn (target, const0_rtx);
1969 : 33712 : emit_jump (end_label);
1970 : 33712 : emit_barrier ();
1971 : 33712 : emit_label (fail_label);
1972 : 33712 : emit_move_insn (target, const1_rtx);
1973 : 33712 : emit_label (end_label);
1974 : :
1975 : 33712 : return target;
1976 : : }
1977 : :
1978 : : /* Emit code to move a block Y to a block X. This may be done with
1979 : : string-move instructions, with multiple scalar move instructions,
1980 : : or with a library call.
1981 : :
1982 : : Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1983 : : SIZE is an rtx that says how long they are.
1984 : : ALIGN is the maximum alignment we can assume they have.
1985 : : METHOD describes what kind of copy this is, and what mechanisms may be used.
1986 : : MIN_SIZE is the minimal size of block to move
1987 : : MAX_SIZE is the maximal size of block to move, if it cannot be represented
1988 : : in unsigned HOST_WIDE_INT, than it is mask of all ones.
1989 : : CTZ_SIZE is the trailing-zeros count of SIZE; even a nonconstant SIZE is
1990 : : known to be a multiple of 1<<CTZ_SIZE.
1991 : :
1992 : : Return the address of the new block, if memcpy is called and returns it,
1993 : : 0 otherwise. */
1994 : :
1995 : : rtx
1996 : 668556 : emit_block_move_hints (rtx x, rtx y, rtx size, enum block_op_methods method,
1997 : : unsigned int expected_align, HOST_WIDE_INT expected_size,
1998 : : unsigned HOST_WIDE_INT min_size,
1999 : : unsigned HOST_WIDE_INT max_size,
2000 : : unsigned HOST_WIDE_INT probable_max_size,
2001 : : bool bail_out_libcall, bool *is_move_done,
2002 : : bool might_overlap, unsigned ctz_size)
2003 : : {
2004 : 668556 : int may_use_call;
2005 : 668556 : rtx retval = 0;
2006 : 668556 : unsigned int align;
2007 : :
2008 : 668556 : if (is_move_done)
2009 : 70650 : *is_move_done = true;
2010 : :
2011 : 668556 : gcc_assert (size);
2012 : 668556 : if (CONST_INT_P (size) && INTVAL (size) == 0)
2013 : : return 0;
2014 : :
2015 : 668278 : switch (method)
2016 : : {
2017 : : case BLOCK_OP_NORMAL:
2018 : : case BLOCK_OP_TAILCALL:
2019 : : may_use_call = 1;
2020 : : break;
2021 : :
2022 : 266153 : case BLOCK_OP_CALL_PARM:
2023 : 266153 : may_use_call = block_move_libcall_safe_for_call_parm ();
2024 : :
2025 : : /* Make inhibit_defer_pop nonzero around the library call
2026 : : to force it to pop the arguments right away. */
2027 : 266153 : NO_DEFER_POP;
2028 : 266153 : break;
2029 : :
2030 : 353 : case BLOCK_OP_NO_LIBCALL:
2031 : 353 : may_use_call = 0;
2032 : 353 : break;
2033 : :
2034 : 1060 : case BLOCK_OP_NO_LIBCALL_RET:
2035 : 1060 : may_use_call = -1;
2036 : 1060 : break;
2037 : :
2038 : 0 : default:
2039 : 0 : gcc_unreachable ();
2040 : : }
2041 : :
2042 : 668278 : gcc_assert (MEM_P (x) && MEM_P (y));
2043 : 668355 : align = MIN (MEM_ALIGN (x), MEM_ALIGN (y));
2044 : 668278 : gcc_assert (align >= BITS_PER_UNIT);
2045 : :
2046 : : /* Make sure we've got BLKmode addresses; store_one_arg can decide that
2047 : : block copy is more efficient for other large modes, e.g. DCmode. */
2048 : 668278 : x = adjust_address (x, BLKmode, 0);
2049 : 668278 : y = adjust_address (y, BLKmode, 0);
2050 : :
2051 : : /* If source and destination are the same, no need to copy anything. */
2052 : 668278 : if (rtx_equal_p (x, y)
2053 : 8 : && !MEM_VOLATILE_P (x)
2054 : 668286 : && !MEM_VOLATILE_P (y))
2055 : : return 0;
2056 : :
2057 : : /* Set MEM_SIZE as appropriate for this block copy. The main place this
2058 : : can be incorrect is coming from __builtin_memcpy. */
2059 : 668270 : poly_int64 const_size;
2060 : 668270 : if (poly_int_rtx_p (size, &const_size))
2061 : : {
2062 : 611865 : x = shallow_copy_rtx (x);
2063 : 611865 : y = shallow_copy_rtx (y);
2064 : 611865 : set_mem_size (x, const_size);
2065 : 611865 : set_mem_size (y, const_size);
2066 : : }
2067 : :
2068 : 668270 : bool pieces_ok = CONST_INT_P (size)
2069 : 668270 : && can_move_by_pieces (INTVAL (size), align);
2070 : 668270 : bool pattern_ok = false;
2071 : :
2072 : 668270 : if (!pieces_ok || might_overlap)
2073 : : {
2074 : 80740 : pattern_ok
2075 : 80740 : = emit_block_move_via_pattern (x, y, size, align,
2076 : : expected_align, expected_size,
2077 : : min_size, max_size, probable_max_size,
2078 : : might_overlap);
2079 : 80740 : if (!pattern_ok && might_overlap)
2080 : : {
2081 : : /* Do not try any of the other methods below as they are not safe
2082 : : for overlapping moves. */
2083 : 13894 : *is_move_done = false;
2084 : 13894 : return retval;
2085 : : }
2086 : : }
2087 : :
2088 : 654376 : bool dynamic_direction = false;
2089 : 654376 : if (!pattern_ok && !pieces_ok && may_use_call
2090 : 69056 : && (flag_inline_stringops & (might_overlap ? ILSOP_MEMMOVE : ILSOP_MEMCPY)))
2091 : : {
2092 : 654376 : may_use_call = 0;
2093 : 654376 : dynamic_direction = might_overlap;
2094 : : }
2095 : :
2096 : 654376 : if (pattern_ok)
2097 : : ;
2098 : 622058 : else if (pieces_ok)
2099 : 587530 : move_by_pieces (x, y, INTVAL (size), align, RETURN_BEGIN);
2100 : 34528 : else if (may_use_call && !might_overlap
2101 : 34480 : && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x))
2102 : 69008 : && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y)))
2103 : : {
2104 : 34480 : if (bail_out_libcall)
2105 : : {
2106 : 253 : if (is_move_done)
2107 : 253 : *is_move_done = false;
2108 : 253 : return retval;
2109 : : }
2110 : :
2111 : 34227 : if (may_use_call < 0)
2112 : 0 : return pc_rtx;
2113 : :
2114 : 34227 : retval = emit_block_copy_via_libcall (x, y, size,
2115 : : method == BLOCK_OP_TAILCALL);
2116 : : }
2117 : 48 : else if (dynamic_direction)
2118 : 0 : emit_block_move_via_oriented_loop (x, y, size, align, ctz_size);
2119 : 48 : else if (might_overlap)
2120 : 0 : *is_move_done = false;
2121 : : else
2122 : 48 : emit_block_move_via_sized_loop (x, y, size, align, ctz_size);
2123 : :
2124 : 654123 : if (method == BLOCK_OP_CALL_PARM)
2125 : 266147 : OK_DEFER_POP;
2126 : :
2127 : : return retval;
2128 : : }
2129 : :
2130 : : rtx
2131 : 597906 : emit_block_move (rtx x, rtx y, rtx size, enum block_op_methods method,
2132 : : unsigned int ctz_size)
2133 : : {
2134 : 597906 : unsigned HOST_WIDE_INT max, min = 0;
2135 : 597906 : if (GET_CODE (size) == CONST_INT)
2136 : 597686 : min = max = UINTVAL (size);
2137 : : else
2138 : 220 : max = GET_MODE_MASK (GET_MODE (size));
2139 : 597906 : return emit_block_move_hints (x, y, size, method, 0, -1,
2140 : : min, max, max,
2141 : 597906 : false, NULL, false, ctz_size);
2142 : : }
2143 : :
2144 : : /* A subroutine of emit_block_move. Returns true if calling the
2145 : : block move libcall will not clobber any parameters which may have
2146 : : already been placed on the stack. */
2147 : :
2148 : : static bool
2149 : 266153 : block_move_libcall_safe_for_call_parm (void)
2150 : : {
2151 : 266153 : tree fn;
2152 : :
2153 : : /* If arguments are pushed on the stack, then they're safe. */
2154 : 266153 : if (targetm.calls.push_argument (0))
2155 : : return true;
2156 : :
2157 : : /* If registers go on the stack anyway, any argument is sure to clobber
2158 : : an outgoing argument. */
2159 : : #if defined (REG_PARM_STACK_SPACE)
2160 : 1 : fn = builtin_decl_implicit (BUILT_IN_MEMCPY);
2161 : : /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
2162 : : depend on its argument. */
2163 : 1 : (void) fn;
2164 : 1 : if (OUTGOING_REG_PARM_STACK_SPACE ((!fn ? NULL_TREE : TREE_TYPE (fn)))
2165 : 1 : && REG_PARM_STACK_SPACE (fn) != 0)
2166 : : return false;
2167 : : #endif
2168 : :
2169 : : /* If any argument goes in memory, then it might clobber an outgoing
2170 : : argument. */
2171 : 1 : {
2172 : 1 : CUMULATIVE_ARGS args_so_far_v;
2173 : 1 : cumulative_args_t args_so_far;
2174 : 1 : tree arg;
2175 : :
2176 : 1 : fn = builtin_decl_implicit (BUILT_IN_MEMCPY);
2177 : 1 : INIT_CUMULATIVE_ARGS (args_so_far_v, TREE_TYPE (fn), NULL_RTX, 0, 3);
2178 : 1 : args_so_far = pack_cumulative_args (&args_so_far_v);
2179 : :
2180 : 1 : arg = TYPE_ARG_TYPES (TREE_TYPE (fn));
2181 : 4 : for ( ; arg != void_list_node ; arg = TREE_CHAIN (arg))
2182 : : {
2183 : 3 : machine_mode mode = TYPE_MODE (TREE_VALUE (arg));
2184 : 3 : function_arg_info arg_info (mode, /*named=*/true);
2185 : 3 : rtx tmp = targetm.calls.function_arg (args_so_far, arg_info);
2186 : 3 : if (!tmp || !REG_P (tmp))
2187 : 0 : return false;
2188 : 3 : if (targetm.calls.arg_partial_bytes (args_so_far, arg_info))
2189 : : return false;
2190 : 3 : targetm.calls.function_arg_advance (args_so_far, arg_info);
2191 : : }
2192 : : }
2193 : 1 : return true;
2194 : : }
2195 : :
2196 : : /* A subroutine of emit_block_move. Expand a cpymem or movmem pattern;
2197 : : return true if successful.
2198 : :
2199 : : X is the destination of the copy or move.
2200 : : Y is the source of the copy or move.
2201 : : SIZE is the size of the block to be moved.
2202 : :
2203 : : MIGHT_OVERLAP indicates this originated with expansion of a
2204 : : builtin_memmove() and the source and destination blocks may
2205 : : overlap.
2206 : : */
2207 : :
2208 : : static bool
2209 : 80740 : emit_block_move_via_pattern (rtx x, rtx y, rtx size, unsigned int align,
2210 : : unsigned int expected_align,
2211 : : HOST_WIDE_INT expected_size,
2212 : : unsigned HOST_WIDE_INT min_size,
2213 : : unsigned HOST_WIDE_INT max_size,
2214 : : unsigned HOST_WIDE_INT probable_max_size,
2215 : : bool might_overlap)
2216 : : {
2217 : 80740 : if (expected_align < align)
2218 : : expected_align = align;
2219 : 80740 : if (expected_size != -1)
2220 : : {
2221 : 12 : if ((unsigned HOST_WIDE_INT)expected_size > probable_max_size)
2222 : 0 : expected_size = probable_max_size;
2223 : 12 : if ((unsigned HOST_WIDE_INT)expected_size < min_size)
2224 : 0 : expected_size = min_size;
2225 : : }
2226 : :
2227 : : /* Since this is a move insn, we don't care about volatility. */
2228 : 80740 : temporary_volatile_ok v (true);
2229 : :
2230 : : /* Try the most limited insn first, because there's no point
2231 : : including more than one in the machine description unless
2232 : : the more limited one has some advantage. */
2233 : :
2234 : 80740 : opt_scalar_int_mode mode_iter;
2235 : 486251 : FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_INT)
2236 : : {
2237 : 437829 : scalar_int_mode mode = mode_iter.require ();
2238 : 437829 : enum insn_code code;
2239 : 437829 : if (might_overlap)
2240 : 97258 : code = direct_optab_handler (movmem_optab, mode);
2241 : : else
2242 : 340571 : code = direct_optab_handler (cpymem_optab, mode);
2243 : :
2244 : 437829 : if (code != CODE_FOR_nothing
2245 : : /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
2246 : : here because if SIZE is less than the mode mask, as it is
2247 : : returned by the macro, it will definitely be less than the
2248 : : actual mode mask. Since SIZE is within the Pmode address
2249 : : space, we limit MODE to Pmode. */
2250 : 437829 : && ((CONST_INT_P (size)
2251 : 23390 : && ((unsigned HOST_WIDE_INT) INTVAL (size)
2252 : 23390 : <= (GET_MODE_MASK (mode) >> 1)))
2253 : 78225 : || max_size <= (GET_MODE_MASK (mode) >> 1)
2254 : 112032 : || GET_MODE_BITSIZE (mode) >= GET_MODE_BITSIZE (Pmode)))
2255 : : {
2256 : 68707 : class expand_operand ops[9];
2257 : 68707 : unsigned int nops;
2258 : :
2259 : : /* ??? When called via emit_block_move_for_call, it'd be
2260 : : nice if there were some way to inform the backend, so
2261 : : that it doesn't fail the expansion because it thinks
2262 : : emitting the libcall would be more efficient. */
2263 : 68707 : nops = insn_data[(int) code].n_generator_args;
2264 : 68707 : gcc_assert (nops == 4 || nops == 6 || nops == 8 || nops == 9);
2265 : :
2266 : 68707 : create_fixed_operand (&ops[0], x);
2267 : 68707 : create_fixed_operand (&ops[1], y);
2268 : : /* The check above guarantees that this size conversion is valid. */
2269 : 68707 : create_convert_operand_to (&ops[2], size, mode, true);
2270 : 68707 : create_integer_operand (&ops[3], align / BITS_PER_UNIT);
2271 : 68707 : if (nops >= 6)
2272 : : {
2273 : 68707 : create_integer_operand (&ops[4], expected_align / BITS_PER_UNIT);
2274 : 68707 : create_integer_operand (&ops[5], expected_size);
2275 : : }
2276 : 68707 : if (nops >= 8)
2277 : : {
2278 : 68707 : create_integer_operand (&ops[6], min_size);
2279 : : /* If we cannot represent the maximal size,
2280 : : make parameter NULL. */
2281 : 68707 : if ((HOST_WIDE_INT) max_size != -1)
2282 : 48522 : create_integer_operand (&ops[7], max_size);
2283 : : else
2284 : 20185 : create_fixed_operand (&ops[7], NULL);
2285 : : }
2286 : 68707 : if (nops == 9)
2287 : : {
2288 : : /* If we cannot represent the maximal size,
2289 : : make parameter NULL. */
2290 : 68707 : if ((HOST_WIDE_INT) probable_max_size != -1)
2291 : 50172 : create_integer_operand (&ops[8], probable_max_size);
2292 : : else
2293 : 18535 : create_fixed_operand (&ops[8], NULL);
2294 : : }
2295 : 68707 : if (maybe_expand_insn (code, nops, ops))
2296 : 32318 : return true;
2297 : : }
2298 : : }
2299 : :
2300 : : return false;
2301 : 80740 : }
2302 : :
2303 : : /* Like emit_block_move_via_loop, but choose a suitable INCR based on
2304 : : ALIGN and CTZ_SIZE. */
2305 : :
2306 : : static void
2307 : 48 : emit_block_move_via_sized_loop (rtx x, rtx y, rtx size,
2308 : : unsigned int align,
2309 : : unsigned int ctz_size)
2310 : : {
2311 : 48 : int incr = align / BITS_PER_UNIT;
2312 : :
2313 : 48 : if (CONST_INT_P (size))
2314 : 0 : ctz_size = MAX (ctz_size, (unsigned) wi::ctz (UINTVAL (size)));
2315 : :
2316 : 48 : if (HOST_WIDE_INT_1U << ctz_size < (unsigned HOST_WIDE_INT) incr)
2317 : 0 : incr = HOST_WIDE_INT_1U << ctz_size;
2318 : :
2319 : 48 : while (incr > 1 && !can_move_by_pieces (incr, align))
2320 : 0 : incr >>= 1;
2321 : :
2322 : 48 : gcc_checking_assert (incr);
2323 : :
2324 : 48 : return emit_block_move_via_loop (x, y, size, align, incr);
2325 : : }
2326 : :
2327 : : /* Like emit_block_move_via_sized_loop, but besides choosing INCR so
2328 : : as to ensure safe moves even in case of overlap, output dynamic
2329 : : tests to choose between two loops, one moving downwards, another
2330 : : moving upwards. */
2331 : :
2332 : : static void
2333 : 0 : emit_block_move_via_oriented_loop (rtx x, rtx y, rtx size,
2334 : : unsigned int align,
2335 : : unsigned int ctz_size)
2336 : : {
2337 : 0 : int incr = align / BITS_PER_UNIT;
2338 : :
2339 : 0 : if (CONST_INT_P (size))
2340 : 0 : ctz_size = MAX (ctz_size, (unsigned) wi::ctz (UINTVAL (size)));
2341 : :
2342 : 0 : if (HOST_WIDE_INT_1U << ctz_size < (unsigned HOST_WIDE_INT) incr)
2343 : 0 : incr = HOST_WIDE_INT_1U << ctz_size;
2344 : :
2345 : 0 : while (incr > 1 && !int_mode_for_size (incr, 0).exists ())
2346 : 0 : incr >>= 1;
2347 : :
2348 : 0 : gcc_checking_assert (incr);
2349 : :
2350 : 0 : rtx_code_label *upw_label, *end_label;
2351 : 0 : upw_label = gen_label_rtx ();
2352 : 0 : end_label = gen_label_rtx ();
2353 : :
2354 : 0 : rtx x_addr = force_operand (XEXP (x, 0), NULL_RTX);
2355 : 0 : rtx y_addr = force_operand (XEXP (y, 0), NULL_RTX);
2356 : 0 : do_pending_stack_adjust ();
2357 : :
2358 : 0 : machine_mode mode = GET_MODE (x_addr);
2359 : 0 : if (mode != GET_MODE (y_addr))
2360 : : {
2361 : 0 : scalar_int_mode xmode
2362 : 0 : = smallest_int_mode_for_size (GET_MODE_BITSIZE (mode));
2363 : 0 : scalar_int_mode ymode
2364 : 0 : = smallest_int_mode_for_size (GET_MODE_BITSIZE
2365 : 0 : (GET_MODE (y_addr)));
2366 : 0 : if (GET_MODE_BITSIZE (xmode) < GET_MODE_BITSIZE (ymode))
2367 : : mode = ymode;
2368 : : else
2369 : 0 : mode = xmode;
2370 : :
2371 : : #ifndef POINTERS_EXTEND_UNSIGNED
2372 : : const int POINTERS_EXTEND_UNSIGNED = 1;
2373 : : #endif
2374 : 0 : x_addr = convert_modes (mode, GET_MODE (x_addr), x_addr,
2375 : : POINTERS_EXTEND_UNSIGNED);
2376 : 0 : y_addr = convert_modes (mode, GET_MODE (y_addr), y_addr,
2377 : : POINTERS_EXTEND_UNSIGNED);
2378 : : }
2379 : :
2380 : : /* Test for overlap: if (x >= y || x + size <= y) goto upw_label. */
2381 : 0 : emit_cmp_and_jump_insns (x_addr, y_addr, GEU, NULL_RTX, mode,
2382 : : true, upw_label,
2383 : 0 : profile_probability::guessed_always ()
2384 : : .apply_scale (5, 10));
2385 : 0 : rtx tmp = convert_modes (GET_MODE (x_addr), GET_MODE (size), size, true);
2386 : 0 : tmp = simplify_gen_binary (PLUS, GET_MODE (x_addr), x_addr, tmp);
2387 : :
2388 : 0 : emit_cmp_and_jump_insns (tmp, y_addr, LEU, NULL_RTX, mode,
2389 : : true, upw_label,
2390 : 0 : profile_probability::guessed_always ()
2391 : : .apply_scale (8, 10));
2392 : :
2393 : 0 : emit_block_move_via_loop (x, y, size, align, -incr);
2394 : :
2395 : 0 : emit_jump (end_label);
2396 : 0 : emit_label (upw_label);
2397 : :
2398 : 0 : emit_block_move_via_loop (x, y, size, align, incr);
2399 : :
2400 : 0 : emit_label (end_label);
2401 : 0 : }
2402 : :
2403 : : /* A subroutine of emit_block_move. Copy the data via an explicit
2404 : : loop. This is used only when libcalls are forbidden, or when
2405 : : inlining is required. INCR is the block size to be copied in each
2406 : : loop iteration. If it is negative, the absolute value is used, and
2407 : : the block is copied backwards. INCR must be a power of two, an
2408 : : exact divisor for SIZE and ALIGN, and imply a mode that can be
2409 : : safely copied per iteration assuming no overlap. */
2410 : :
2411 : : static void
2412 : 48 : emit_block_move_via_loop (rtx x, rtx y, rtx size,
2413 : : unsigned int align, int incr)
2414 : : {
2415 : 48 : rtx_code_label *cmp_label, *top_label;
2416 : 48 : rtx iter, x_addr, y_addr, tmp;
2417 : 48 : machine_mode x_addr_mode = get_address_mode (x);
2418 : 48 : machine_mode y_addr_mode = get_address_mode (y);
2419 : 48 : machine_mode iter_mode;
2420 : :
2421 : 48 : iter_mode = GET_MODE (size);
2422 : 48 : if (iter_mode == VOIDmode)
2423 : 0 : iter_mode = word_mode;
2424 : :
2425 : 48 : top_label = gen_label_rtx ();
2426 : 48 : cmp_label = gen_label_rtx ();
2427 : 48 : iter = gen_reg_rtx (iter_mode);
2428 : :
2429 : 48 : bool downwards = incr < 0;
2430 : 48 : rtx iter_init;
2431 : 48 : rtx_code iter_cond;
2432 : 48 : rtx iter_limit;
2433 : 48 : rtx iter_incr;
2434 : 48 : machine_mode move_mode;
2435 : 48 : if (downwards)
2436 : : {
2437 : 0 : incr = -incr;
2438 : 0 : iter_init = size;
2439 : 0 : iter_cond = GEU;
2440 : 0 : iter_limit = const0_rtx;
2441 : 0 : iter_incr = GEN_INT (incr);
2442 : : }
2443 : : else
2444 : : {
2445 : 48 : iter_init = const0_rtx;
2446 : 48 : iter_cond = LTU;
2447 : 48 : iter_limit = size;
2448 : 48 : iter_incr = GEN_INT (incr);
2449 : : }
2450 : 48 : emit_move_insn (iter, iter_init);
2451 : :
2452 : 48 : opt_scalar_int_mode int_move_mode
2453 : 48 : = int_mode_for_size (incr * BITS_PER_UNIT, 1);
2454 : 48 : if (!int_move_mode.exists (&move_mode)
2455 : 96 : || GET_MODE_BITSIZE (int_move_mode.require ()) != incr * BITS_PER_UNIT)
2456 : : {
2457 : 0 : move_mode = BLKmode;
2458 : 0 : gcc_checking_assert (can_move_by_pieces (incr, align));
2459 : : }
2460 : :
2461 : 48 : x_addr = force_operand (XEXP (x, 0), NULL_RTX);
2462 : 48 : y_addr = force_operand (XEXP (y, 0), NULL_RTX);
2463 : 48 : do_pending_stack_adjust ();
2464 : :
2465 : 48 : emit_jump (cmp_label);
2466 : 48 : emit_label (top_label);
2467 : :
2468 : 48 : tmp = convert_modes (x_addr_mode, iter_mode, iter, true);
2469 : 48 : x_addr = simplify_gen_binary (PLUS, x_addr_mode, x_addr, tmp);
2470 : :
2471 : 48 : if (x_addr_mode != y_addr_mode)
2472 : 0 : tmp = convert_modes (y_addr_mode, iter_mode, iter, true);
2473 : 48 : y_addr = simplify_gen_binary (PLUS, y_addr_mode, y_addr, tmp);
2474 : :
2475 : 48 : x = change_address (x, move_mode, x_addr);
2476 : 48 : y = change_address (y, move_mode, y_addr);
2477 : :
2478 : 48 : if (move_mode == BLKmode)
2479 : : {
2480 : 0 : bool done;
2481 : 0 : emit_block_move_hints (x, y, iter_incr, BLOCK_OP_NO_LIBCALL,
2482 : : align, incr, incr, incr, incr,
2483 : : false, &done, false);
2484 : 0 : gcc_checking_assert (done);
2485 : : }
2486 : : else
2487 : 48 : emit_move_insn (x, y);
2488 : :
2489 : 48 : if (downwards)
2490 : 0 : emit_label (cmp_label);
2491 : :
2492 : 48 : tmp = expand_simple_binop (iter_mode, PLUS, iter, iter_incr, iter,
2493 : : true, OPTAB_LIB_WIDEN);
2494 : 48 : if (tmp != iter)
2495 : 0 : emit_move_insn (iter, tmp);
2496 : :
2497 : 48 : if (!downwards)
2498 : 48 : emit_label (cmp_label);
2499 : :
2500 : 48 : emit_cmp_and_jump_insns (iter, iter_limit, iter_cond, NULL_RTX, iter_mode,
2501 : : true, top_label,
2502 : 48 : profile_probability::guessed_always ()
2503 : : .apply_scale (9, 10));
2504 : 48 : }
2505 : :
2506 : : /* Expand a call to memcpy or memmove or memcmp, and return the result.
2507 : : TAILCALL is true if this is a tail call. */
2508 : :
2509 : : rtx
2510 : 34230 : emit_block_op_via_libcall (enum built_in_function fncode, rtx dst, rtx src,
2511 : : rtx size, bool tailcall)
2512 : : {
2513 : 34230 : rtx dst_addr, src_addr;
2514 : 34230 : tree call_expr, dst_tree, src_tree, size_tree;
2515 : 34230 : machine_mode size_mode;
2516 : :
2517 : : /* Since dst and src are passed to a libcall, mark the corresponding
2518 : : tree EXPR as addressable. */
2519 : 34230 : tree dst_expr = MEM_EXPR (dst);
2520 : 34230 : tree src_expr = MEM_EXPR (src);
2521 : 34230 : if (dst_expr)
2522 : 33928 : mark_addressable (dst_expr);
2523 : 34230 : if (src_expr)
2524 : 34192 : mark_addressable (src_expr);
2525 : :
2526 : 34230 : dst_addr = copy_addr_to_reg (XEXP (dst, 0));
2527 : 34230 : dst_addr = convert_memory_address (ptr_mode, dst_addr);
2528 : 34230 : dst_tree = make_tree (ptr_type_node, dst_addr);
2529 : :
2530 : 34230 : src_addr = copy_addr_to_reg (XEXP (src, 0));
2531 : 34230 : src_addr = convert_memory_address (ptr_mode, src_addr);
2532 : 34230 : src_tree = make_tree (ptr_type_node, src_addr);
2533 : :
2534 : 34230 : size_mode = TYPE_MODE (sizetype);
2535 : 34230 : size = convert_to_mode (size_mode, size, 1);
2536 : 34230 : size = copy_to_mode_reg (size_mode, size);
2537 : 34230 : size_tree = make_tree (sizetype, size);
2538 : :
2539 : : /* It is incorrect to use the libcall calling conventions for calls to
2540 : : memcpy/memmove/memcmp because they can be provided by the user. */
2541 : 34230 : tree fn = builtin_decl_implicit (fncode);
2542 : 34230 : call_expr = build_call_expr (fn, 3, dst_tree, src_tree, size_tree);
2543 : 34230 : CALL_EXPR_TAILCALL (call_expr) = tailcall;
2544 : :
2545 : 34230 : return expand_call (call_expr, NULL_RTX, false);
2546 : : }
2547 : :
2548 : : /* Try to expand cmpstrn or cmpmem operation ICODE with the given operands.
2549 : : ARG3_TYPE is the type of ARG3_RTX. Return the result rtx on success,
2550 : : otherwise return null. */
2551 : :
2552 : : rtx
2553 : 208533 : expand_cmpstrn_or_cmpmem (insn_code icode, rtx target, rtx arg1_rtx,
2554 : : rtx arg2_rtx, tree arg3_type, rtx arg3_rtx,
2555 : : HOST_WIDE_INT align)
2556 : : {
2557 : 208533 : machine_mode insn_mode = insn_data[icode].operand[0].mode;
2558 : :
2559 : 208533 : if (target && (!REG_P (target) || HARD_REGISTER_P (target)))
2560 : : target = NULL_RTX;
2561 : :
2562 : 208533 : class expand_operand ops[5];
2563 : 208533 : create_output_operand (&ops[0], target, insn_mode);
2564 : 208533 : create_fixed_operand (&ops[1], arg1_rtx);
2565 : 208533 : create_fixed_operand (&ops[2], arg2_rtx);
2566 : 208533 : create_convert_operand_from (&ops[3], arg3_rtx, TYPE_MODE (arg3_type),
2567 : 208533 : TYPE_UNSIGNED (arg3_type));
2568 : 208533 : create_integer_operand (&ops[4], align);
2569 : 208533 : if (maybe_expand_insn (icode, 5, ops))
2570 : 5704 : return ops[0].value;
2571 : : return NULL_RTX;
2572 : : }
2573 : :
2574 : : /* Expand a block compare between X and Y with length LEN using the
2575 : : cmpmem optab, placing the result in TARGET. LEN_TYPE is the type
2576 : : of the expression that was used to calculate the length. ALIGN
2577 : : gives the known minimum common alignment. */
2578 : :
2579 : : static rtx
2580 : 77774 : emit_block_cmp_via_cmpmem (rtx x, rtx y, rtx len, tree len_type, rtx target,
2581 : : unsigned align)
2582 : : {
2583 : : /* Note: The cmpstrnsi pattern, if it exists, is not suitable for
2584 : : implementing memcmp because it will stop if it encounters two
2585 : : zero bytes. */
2586 : 77774 : insn_code icode = direct_optab_handler (cmpmem_optab, SImode);
2587 : :
2588 : 77774 : if (icode == CODE_FOR_nothing)
2589 : : return NULL_RTX;
2590 : :
2591 : 77774 : return expand_cmpstrn_or_cmpmem (icode, target, x, y, len_type, len, align);
2592 : : }
2593 : :
2594 : : /* Emit code to compare a block Y to a block X. This may be done with
2595 : : string-compare instructions, with multiple scalar instructions,
2596 : : or with a library call.
2597 : :
2598 : : Both X and Y must be MEM rtx's. LEN is an rtx that says how long
2599 : : they are. LEN_TYPE is the type of the expression that was used to
2600 : : calculate it, and CTZ_LEN is the known trailing-zeros count of LEN,
2601 : : so LEN must be a multiple of 1<<CTZ_LEN even if it's not constant.
2602 : :
2603 : : If EQUALITY_ONLY is true, it means we don't have to return the tri-state
2604 : : value of a normal memcmp call, instead we can just compare for equality.
2605 : : If FORCE_LIBCALL is true, we should emit a call to memcmp rather than
2606 : : returning NULL_RTX.
2607 : :
2608 : : Optionally, the caller can pass a constfn and associated data in Y_CFN
2609 : : and Y_CFN_DATA. describing that the second operand being compared is a
2610 : : known constant and how to obtain its data.
2611 : : Return the result of the comparison, or NULL_RTX if we failed to
2612 : : perform the operation. */
2613 : :
2614 : : rtx
2615 : 111491 : emit_block_cmp_hints (rtx x, rtx y, rtx len, tree len_type, rtx target,
2616 : : bool equality_only, by_pieces_constfn y_cfn,
2617 : : void *y_cfndata, unsigned ctz_len)
2618 : : {
2619 : 111491 : rtx result = 0;
2620 : :
2621 : 111491 : if (CONST_INT_P (len) && INTVAL (len) == 0)
2622 : 6 : return const0_rtx;
2623 : :
2624 : 111485 : gcc_assert (MEM_P (x) && MEM_P (y));
2625 : 111485 : unsigned int align = MIN (MEM_ALIGN (x), MEM_ALIGN (y));
2626 : 111485 : gcc_assert (align >= BITS_PER_UNIT);
2627 : :
2628 : 111485 : x = adjust_address (x, BLKmode, 0);
2629 : 111485 : y = adjust_address (y, BLKmode, 0);
2630 : :
2631 : 111485 : if (equality_only
2632 : 58201 : && CONST_INT_P (len)
2633 : 147979 : && can_do_by_pieces (INTVAL (len), align, COMPARE_BY_PIECES))
2634 : 33711 : result = compare_by_pieces (x, y, INTVAL (len), target, align,
2635 : : y_cfn, y_cfndata);
2636 : : else
2637 : 77774 : result = emit_block_cmp_via_cmpmem (x, y, len, len_type, target, align);
2638 : :
2639 : 111485 : if (!result && (flag_inline_stringops & ILSOP_MEMCMP))
2640 : 361 : result = emit_block_cmp_via_loop (x, y, len, len_type,
2641 : : target, equality_only,
2642 : : align, ctz_len);
2643 : :
2644 : : return result;
2645 : : }
2646 : :
2647 : : /* Like emit_block_cmp_hints, but with known alignment and no support
2648 : : for constats. Always expand to a loop with iterations that compare
2649 : : blocks of the largest compare-by-pieces size that divides both len
2650 : : and align, and then, if !EQUALITY_ONLY, identify the word and then
2651 : : the unit that first differs to return the result. */
2652 : :
2653 : : rtx
2654 : 403 : emit_block_cmp_via_loop (rtx x, rtx y, rtx len, tree len_type, rtx target,
2655 : : bool equality_only, unsigned align, unsigned ctz_len)
2656 : : {
2657 : 403 : unsigned incr = align / BITS_PER_UNIT;
2658 : :
2659 : 403 : if (CONST_INT_P (len))
2660 : 319 : ctz_len = MAX (ctz_len, (unsigned) wi::ctz (UINTVAL (len)));
2661 : :
2662 : 403 : if (HOST_WIDE_INT_1U << ctz_len < (unsigned HOST_WIDE_INT) incr)
2663 : 148 : incr = HOST_WIDE_INT_1U << ctz_len;
2664 : :
2665 : : while (incr > 1
2666 : 407 : && !can_do_by_pieces (incr, align, COMPARE_BY_PIECES))
2667 : 4 : incr >>= 1;
2668 : :
2669 : 403 : rtx_code_label *cmp_label, *top_label, *ne_label, *res_label;
2670 : 403 : rtx iter, x_addr, y_addr, tmp;
2671 : 403 : machine_mode x_addr_mode = get_address_mode (x);
2672 : 403 : machine_mode y_addr_mode = get_address_mode (y);
2673 : 403 : machine_mode iter_mode;
2674 : :
2675 : 403 : iter_mode = GET_MODE (len);
2676 : 403 : if (iter_mode == VOIDmode)
2677 : 319 : iter_mode = word_mode;
2678 : :
2679 : 403 : rtx iter_init = const0_rtx;
2680 : 403 : rtx_code iter_cond = LTU;
2681 : 403 : rtx_code entry_cond = GEU;
2682 : 403 : rtx iter_limit = len;
2683 : 403 : rtx iter_incr = GEN_INT (incr);
2684 : 403 : machine_mode cmp_mode;
2685 : :
2686 : : /* We can drop the loop back edge if we know there's exactly one
2687 : : iteration. */
2688 : 403 : top_label = (!rtx_equal_p (len, iter_incr)
2689 : 403 : ? gen_label_rtx ()
2690 : : : NULL);
2691 : : /* We need not test before entering the loop if len is known
2692 : : nonzero. ??? This could be even stricter, testing whether a
2693 : : nonconstant LEN could possibly be zero. */
2694 : 319 : cmp_label = (!CONSTANT_P (len) || rtx_equal_p (len, iter_init)
2695 : 403 : ? gen_label_rtx ()
2696 : : : NULL);
2697 : 403 : ne_label = gen_label_rtx ();
2698 : 403 : res_label = gen_label_rtx ();
2699 : :
2700 : 403 : iter = gen_reg_rtx (iter_mode);
2701 : 403 : emit_move_insn (iter, iter_init);
2702 : :
2703 : 403 : opt_scalar_int_mode int_cmp_mode
2704 : 403 : = int_mode_for_size (incr * BITS_PER_UNIT, 1);
2705 : 403 : if (!int_cmp_mode.exists (&cmp_mode)
2706 : 1206 : || GET_MODE_BITSIZE (int_cmp_mode.require ()) != incr * BITS_PER_UNIT
2707 : 805 : || !can_compare_p (NE, cmp_mode, ccp_jump))
2708 : : {
2709 : 1 : cmp_mode = BLKmode;
2710 : 1 : gcc_checking_assert (incr != 1);
2711 : : }
2712 : :
2713 : : /* Save the base addresses. */
2714 : 403 : x_addr = force_operand (XEXP (x, 0), NULL_RTX);
2715 : 403 : y_addr = force_operand (XEXP (y, 0), NULL_RTX);
2716 : 403 : do_pending_stack_adjust ();
2717 : :
2718 : 403 : if (cmp_label)
2719 : : {
2720 : 84 : if (top_label)
2721 : 84 : emit_jump (cmp_label);
2722 : : else
2723 : 0 : emit_cmp_and_jump_insns (iter, iter_limit, entry_cond,
2724 : : NULL_RTX, iter_mode,
2725 : : true, cmp_label,
2726 : 0 : profile_probability::guessed_always ()
2727 : : .apply_scale (1, 10));
2728 : : }
2729 : 403 : if (top_label)
2730 : 386 : emit_label (top_label);
2731 : :
2732 : : /* Offset the base addresses by ITER. */
2733 : 403 : tmp = convert_modes (x_addr_mode, iter_mode, iter, true);
2734 : 403 : x_addr = simplify_gen_binary (PLUS, x_addr_mode, x_addr, tmp);
2735 : :
2736 : 403 : if (x_addr_mode != y_addr_mode)
2737 : 0 : tmp = convert_modes (y_addr_mode, iter_mode, iter, true);
2738 : 403 : y_addr = simplify_gen_binary (PLUS, y_addr_mode, y_addr, tmp);
2739 : :
2740 : 403 : x = change_address (x, cmp_mode, x_addr);
2741 : 403 : y = change_address (y, cmp_mode, y_addr);
2742 : :
2743 : : /* Compare one block. */
2744 : 403 : rtx part_res;
2745 : 403 : if (cmp_mode == BLKmode)
2746 : 1 : part_res = compare_by_pieces (x, y, incr, target, align, 0, 0);
2747 : : else
2748 : 402 : part_res = expand_binop (cmp_mode, sub_optab, x, y, NULL_RTX,
2749 : : true, OPTAB_LIB_WIDEN);
2750 : :
2751 : : /* Stop if we found a difference. */
2752 : 403 : emit_cmp_and_jump_insns (part_res, GEN_INT (0), NE, NULL_RTX,
2753 : 403 : GET_MODE (part_res), true, ne_label,
2754 : 403 : profile_probability::guessed_always ()
2755 : : .apply_scale (1, 10));
2756 : :
2757 : : /* Increment ITER. */
2758 : 403 : tmp = expand_simple_binop (iter_mode, PLUS, iter, iter_incr, iter,
2759 : : true, OPTAB_LIB_WIDEN);
2760 : 403 : if (tmp != iter)
2761 : 0 : emit_move_insn (iter, tmp);
2762 : :
2763 : 403 : if (cmp_label)
2764 : 84 : emit_label (cmp_label);
2765 : : /* Loop until we reach the limit. */
2766 : :
2767 : 403 : if (top_label)
2768 : 386 : emit_cmp_and_jump_insns (iter, iter_limit, iter_cond, NULL_RTX, iter_mode,
2769 : : true, top_label,
2770 : 772 : profile_probability::guessed_always ()
2771 : : .apply_scale (9, 10));
2772 : :
2773 : : /* We got to the end without differences, so the result is zero. */
2774 : 403 : if (target == NULL_RTX
2775 : 403 : || !REG_P (target) || REGNO (target) < FIRST_PSEUDO_REGISTER)
2776 : 49 : target = gen_reg_rtx (TYPE_MODE (integer_type_node));
2777 : :
2778 : 403 : emit_move_insn (target, const0_rtx);
2779 : 403 : emit_jump (res_label);
2780 : :
2781 : 403 : emit_label (ne_label);
2782 : :
2783 : : /* Return nonzero, or pinpoint the difference to return the expected
2784 : : result for non-equality tests. */
2785 : 403 : if (equality_only)
2786 : 0 : emit_move_insn (target, const1_rtx);
2787 : : else
2788 : : {
2789 : 403 : if (incr > UNITS_PER_WORD)
2790 : : /* ??? Re-compare the block found to be different one word at a
2791 : : time. */
2792 : 5 : part_res = emit_block_cmp_via_loop (x, y, GEN_INT (incr), len_type,
2793 : : target, equality_only,
2794 : : BITS_PER_WORD, 0);
2795 : 398 : else if (incr > 1)
2796 : : /* ??? Re-compare the block found to be different one byte at a
2797 : : time. We could do better using part_res, and being careful
2798 : : about endianness. */
2799 : 37 : part_res = emit_block_cmp_via_loop (x, y, GEN_INT (incr), len_type,
2800 : : target, equality_only,
2801 : : BITS_PER_UNIT, 0);
2802 : 1083 : else if (known_gt (GET_MODE_BITSIZE (GET_MODE (target)),
2803 : : GET_MODE_BITSIZE (cmp_mode)))
2804 : 361 : part_res = expand_binop (GET_MODE (target), sub_optab, x, y, target,
2805 : : true, OPTAB_LIB_WIDEN);
2806 : : else
2807 : : {
2808 : : /* In the odd chance target is QImode, we can't count on
2809 : : widening subtract to capture the result of the unsigned
2810 : : compares. */
2811 : 0 : rtx_code_label *ltu_label;
2812 : 0 : ltu_label = gen_label_rtx ();
2813 : 0 : emit_cmp_and_jump_insns (x, y, LTU, NULL_RTX,
2814 : : cmp_mode, true, ltu_label,
2815 : 0 : profile_probability::guessed_always ()
2816 : : .apply_scale (5, 10));
2817 : :
2818 : 0 : emit_move_insn (target, const1_rtx);
2819 : 0 : emit_jump (res_label);
2820 : :
2821 : 0 : emit_label (ltu_label);
2822 : 0 : emit_move_insn (target, constm1_rtx);
2823 : 0 : part_res = target;
2824 : : }
2825 : :
2826 : 403 : if (target != part_res)
2827 : 0 : convert_move (target, part_res, false);
2828 : : }
2829 : :
2830 : 403 : emit_label (res_label);
2831 : :
2832 : 403 : return target;
2833 : : }
2834 : :
2835 : :
2836 : : /* Copy all or part of a value X into registers starting at REGNO.
2837 : : The number of registers to be filled is NREGS. */
2838 : :
2839 : : void
2840 : 318 : move_block_to_reg (int regno, rtx x, int nregs, machine_mode mode)
2841 : : {
2842 : 318 : if (nregs == 0)
2843 : : return;
2844 : :
2845 : 304 : if (CONSTANT_P (x) && !targetm.legitimate_constant_p (mode, x))
2846 : 0 : x = validize_mem (force_const_mem (mode, x));
2847 : :
2848 : : /* See if the machine can do this with a load multiple insn. */
2849 : 304 : if (targetm.have_load_multiple ())
2850 : : {
2851 : 0 : rtx_insn *last = get_last_insn ();
2852 : 0 : rtx first = gen_rtx_REG (word_mode, regno);
2853 : 0 : if (rtx_insn *pat = targetm.gen_load_multiple (first, x,
2854 : : GEN_INT (nregs)))
2855 : : {
2856 : 0 : emit_insn (pat);
2857 : 0 : return;
2858 : : }
2859 : : else
2860 : 0 : delete_insns_since (last);
2861 : : }
2862 : :
2863 : 608 : for (int i = 0; i < nregs; i++)
2864 : 304 : emit_move_insn (gen_rtx_REG (word_mode, regno + i),
2865 : 304 : operand_subword_force (x, i, mode));
2866 : : }
2867 : :
2868 : : /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
2869 : : The number of registers to be filled is NREGS. */
2870 : :
2871 : : void
2872 : 1166 : move_block_from_reg (int regno, rtx x, int nregs)
2873 : : {
2874 : 1166 : if (nregs == 0)
2875 : : return;
2876 : :
2877 : : /* See if the machine can do this with a store multiple insn. */
2878 : 1166 : if (targetm.have_store_multiple ())
2879 : : {
2880 : 0 : rtx_insn *last = get_last_insn ();
2881 : 0 : rtx first = gen_rtx_REG (word_mode, regno);
2882 : 0 : if (rtx_insn *pat = targetm.gen_store_multiple (x, first,
2883 : : GEN_INT (nregs)))
2884 : : {
2885 : 0 : emit_insn (pat);
2886 : 0 : return;
2887 : : }
2888 : : else
2889 : 0 : delete_insns_since (last);
2890 : : }
2891 : :
2892 : 2332 : for (int i = 0; i < nregs; i++)
2893 : : {
2894 : 1166 : rtx tem = operand_subword (x, i, 1, BLKmode);
2895 : :
2896 : 1166 : gcc_assert (tem);
2897 : :
2898 : 1166 : emit_move_insn (tem, gen_rtx_REG (word_mode, regno + i));
2899 : : }
2900 : : }
2901 : :
2902 : : /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
2903 : : ORIG, where ORIG is a non-consecutive group of registers represented by
2904 : : a PARALLEL. The clone is identical to the original except in that the
2905 : : original set of registers is replaced by a new set of pseudo registers.
2906 : : The new set has the same modes as the original set. */
2907 : :
2908 : : rtx
2909 : 2963 : gen_group_rtx (rtx orig)
2910 : : {
2911 : 2963 : int i, length;
2912 : 2963 : rtx *tmps;
2913 : :
2914 : 2963 : gcc_assert (GET_CODE (orig) == PARALLEL);
2915 : :
2916 : 2963 : length = XVECLEN (orig, 0);
2917 : 2963 : tmps = XALLOCAVEC (rtx, length);
2918 : :
2919 : : /* Skip a NULL entry in first slot. */
2920 : 2963 : i = XEXP (XVECEXP (orig, 0, 0), 0) ? 0 : 1;
2921 : :
2922 : 2963 : if (i)
2923 : 0 : tmps[0] = 0;
2924 : :
2925 : 7241 : for (; i < length; i++)
2926 : : {
2927 : 4278 : machine_mode mode = GET_MODE (XEXP (XVECEXP (orig, 0, i), 0));
2928 : 4278 : rtx offset = XEXP (XVECEXP (orig, 0, i), 1);
2929 : :
2930 : 4278 : tmps[i] = gen_rtx_EXPR_LIST (VOIDmode, gen_reg_rtx (mode), offset);
2931 : : }
2932 : :
2933 : 2963 : return gen_rtx_PARALLEL (GET_MODE (orig), gen_rtvec_v (length, tmps));
2934 : : }
2935 : :
2936 : : /* A subroutine of emit_group_load. Arguments as for emit_group_load,
2937 : : except that values are placed in TMPS[i], and must later be moved
2938 : : into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
2939 : :
2940 : : static void
2941 : 269180 : emit_group_load_1 (rtx *tmps, rtx dst, rtx orig_src, tree type,
2942 : : poly_int64 ssize)
2943 : : {
2944 : 269183 : rtx src;
2945 : 269183 : int start, i;
2946 : 269183 : machine_mode m = GET_MODE (orig_src);
2947 : :
2948 : 269183 : gcc_assert (GET_CODE (dst) == PARALLEL);
2949 : :
2950 : 269183 : if (m != VOIDmode
2951 : 256221 : && !SCALAR_INT_MODE_P (m)
2952 : 17160 : && !MEM_P (orig_src)
2953 : 4249 : && GET_CODE (orig_src) != CONCAT)
2954 : : {
2955 : 3 : scalar_int_mode imode;
2956 : 3 : if (int_mode_for_mode (GET_MODE (orig_src)).exists (&imode))
2957 : : {
2958 : 3 : src = gen_reg_rtx (imode);
2959 : 3 : emit_move_insn (gen_lowpart (GET_MODE (orig_src), src), orig_src);
2960 : : }
2961 : : else
2962 : : {
2963 : 0 : src = assign_stack_temp (GET_MODE (orig_src), ssize);
2964 : 0 : emit_move_insn (src, orig_src);
2965 : : }
2966 : 3 : emit_group_load_1 (tmps, dst, src, type, ssize);
2967 : : return;
2968 : : }
2969 : :
2970 : : /* Check for a NULL entry, used to indicate that the parameter goes
2971 : : both on the stack and in registers. */
2972 : 269180 : if (XEXP (XVECEXP (dst, 0, 0), 0))
2973 : : start = 0;
2974 : : else
2975 : 0 : start = 1;
2976 : :
2977 : : /* Process the pieces. */
2978 : 797101 : for (i = start; i < XVECLEN (dst, 0); i++)
2979 : : {
2980 : 527921 : machine_mode mode = GET_MODE (XEXP (XVECEXP (dst, 0, i), 0));
2981 : 527921 : poly_int64 bytepos = rtx_to_poly_int64 (XEXP (XVECEXP (dst, 0, i), 1));
2982 : 1055842 : poly_int64 bytelen = GET_MODE_SIZE (mode);
2983 : 527921 : poly_int64 shift = 0;
2984 : :
2985 : : /* Handle trailing fragments that run over the size of the struct.
2986 : : It's the target's responsibility to make sure that the fragment
2987 : : cannot be strictly smaller in some cases and strictly larger
2988 : : in others. */
2989 : 527921 : gcc_checking_assert (ordered_p (bytepos + bytelen, ssize));
2990 : 527921 : if (known_size_p (ssize) && maybe_gt (bytepos + bytelen, ssize))
2991 : : {
2992 : : /* Arrange to shift the fragment to where it belongs.
2993 : : extract_bit_field loads to the lsb of the reg. */
2994 : 1776 : if (
2995 : : #ifdef BLOCK_REG_PADDING
2996 : : BLOCK_REG_PADDING (GET_MODE (orig_src), type, i == start)
2997 : : == (BYTES_BIG_ENDIAN ? PAD_UPWARD : PAD_DOWNWARD)
2998 : : #else
2999 : : BYTES_BIG_ENDIAN
3000 : : #endif
3001 : : )
3002 : : shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
3003 : 1776 : bytelen = ssize - bytepos;
3004 : 1776 : gcc_assert (maybe_gt (bytelen, 0));
3005 : : }
3006 : :
3007 : : /* If we won't be loading directly from memory, protect the real source
3008 : : from strange tricks we might play; but make sure that the source can
3009 : : be loaded directly into the destination. */
3010 : 527921 : src = orig_src;
3011 : 527921 : if (!MEM_P (orig_src)
3012 : 441187 : && (!REG_P (orig_src) || HARD_REGISTER_P (orig_src))
3013 : 560323 : && !CONSTANT_P (orig_src))
3014 : : {
3015 : 6478 : gcc_assert (GET_MODE (orig_src) != VOIDmode);
3016 : 6478 : src = force_reg (GET_MODE (orig_src), orig_src);
3017 : : }
3018 : :
3019 : : /* Optimize the access just a bit. */
3020 : 527921 : if (MEM_P (src)
3021 : 86734 : && (! targetm.slow_unaligned_access (mode, MEM_ALIGN (src))
3022 : 0 : || MEM_ALIGN (src) >= GET_MODE_ALIGNMENT (mode))
3023 : 86734 : && multiple_p (bytepos * BITS_PER_UNIT, GET_MODE_ALIGNMENT (mode))
3024 : 614655 : && known_eq (bytelen, GET_MODE_SIZE (mode)))
3025 : : {
3026 : 84985 : tmps[i] = gen_reg_rtx (mode);
3027 : 84985 : emit_move_insn (tmps[i], adjust_address (src, mode, bytepos));
3028 : : }
3029 : 442936 : else if (COMPLEX_MODE_P (mode)
3030 : 0 : && GET_MODE (src) == mode
3031 : 442936 : && known_eq (bytelen, GET_MODE_SIZE (mode)))
3032 : : /* Let emit_move_complex do the bulk of the work. */
3033 : 0 : tmps[i] = src;
3034 : 442936 : else if (GET_CODE (src) == CONCAT)
3035 : : {
3036 : 12956 : poly_int64 slen = GET_MODE_SIZE (GET_MODE (src));
3037 : 12956 : poly_int64 slen0 = GET_MODE_SIZE (GET_MODE (XEXP (src, 0)));
3038 : 6478 : unsigned int elt;
3039 : 6478 : poly_int64 subpos;
3040 : :
3041 : 6478 : if (can_div_trunc_p (bytepos, slen0, &elt, &subpos)
3042 : 6478 : && known_le (subpos + bytelen, slen0))
3043 : : {
3044 : : /* The following assumes that the concatenated objects all
3045 : : have the same size. In this case, a simple calculation
3046 : : can be used to determine the object and the bit field
3047 : : to be extracted. */
3048 : 4464 : tmps[i] = XEXP (src, elt);
3049 : 8928 : if (maybe_ne (subpos, 0)
3050 : 8928 : || maybe_ne (subpos + bytelen, slen0)
3051 : 8928 : || (!CONSTANT_P (tmps[i])
3052 : 4464 : && (!REG_P (tmps[i]) || GET_MODE (tmps[i]) != mode)))
3053 : 0 : tmps[i] = extract_bit_field (tmps[i], bytelen * BITS_PER_UNIT,
3054 : 0 : subpos * BITS_PER_UNIT,
3055 : : 1, NULL_RTX, mode, mode, false,
3056 : : NULL);
3057 : : }
3058 : : else
3059 : : {
3060 : 2014 : rtx mem;
3061 : :
3062 : 2014 : gcc_assert (known_eq (bytepos, 0));
3063 : 2014 : mem = assign_stack_temp (GET_MODE (src), slen);
3064 : 2014 : emit_move_insn (mem, src);
3065 : 2014 : tmps[i] = extract_bit_field (mem, bytelen * BITS_PER_UNIT,
3066 : 4028 : 0, 1, NULL_RTX, mode, mode, false,
3067 : : NULL);
3068 : : }
3069 : : }
3070 : 436458 : else if (CONSTANT_P (src) && GET_MODE (dst) != BLKmode
3071 : 25924 : && XVECLEN (dst, 0) > 1)
3072 : 25924 : tmps[i] = simplify_gen_subreg (mode, src, GET_MODE (dst), bytepos);
3073 : 410534 : else if (CONSTANT_P (src))
3074 : : {
3075 : 0 : if (known_eq (bytelen, ssize))
3076 : 0 : tmps[i] = src;
3077 : : else
3078 : : {
3079 : 0 : rtx first, second;
3080 : :
3081 : : /* TODO: const_wide_int can have sizes other than this... */
3082 : 0 : gcc_assert (known_eq (2 * bytelen, ssize));
3083 : 0 : split_double (src, &first, &second);
3084 : 0 : if (i)
3085 : 0 : tmps[i] = second;
3086 : : else
3087 : 0 : tmps[i] = first;
3088 : : }
3089 : : }
3090 : 410534 : else if (REG_P (src) && GET_MODE (src) == mode)
3091 : 0 : tmps[i] = src;
3092 : : else
3093 : 410534 : tmps[i] = extract_bit_field (src, bytelen * BITS_PER_UNIT,
3094 : 821068 : bytepos * BITS_PER_UNIT, 1, NULL_RTX,
3095 : : mode, mode, false, NULL);
3096 : :
3097 : 527921 : if (maybe_ne (shift, 0))
3098 : 0 : tmps[i] = expand_shift (LSHIFT_EXPR, mode, tmps[i],
3099 : 0 : shift, tmps[i], 0);
3100 : : }
3101 : : }
3102 : :
3103 : : /* Emit code to move a block SRC of type TYPE to a block DST,
3104 : : where DST is non-consecutive registers represented by a PARALLEL.
3105 : : SSIZE represents the total size of block ORIG_SRC in bytes, or -1
3106 : : if not known. */
3107 : :
3108 : : void
3109 : 10533 : emit_group_load (rtx dst, rtx src, tree type, poly_int64 ssize)
3110 : : {
3111 : 10533 : rtx *tmps;
3112 : 10533 : int i;
3113 : :
3114 : 10533 : tmps = XALLOCAVEC (rtx, XVECLEN (dst, 0));
3115 : 10533 : emit_group_load_1 (tmps, dst, src, type, ssize);
3116 : :
3117 : : /* Copy the extracted pieces into the proper (probable) hard regs. */
3118 : 29644 : for (i = 0; i < XVECLEN (dst, 0); i++)
3119 : : {
3120 : 19111 : rtx d = XEXP (XVECEXP (dst, 0, i), 0);
3121 : 19111 : if (d == NULL)
3122 : 0 : continue;
3123 : 19111 : emit_move_insn (d, tmps[i]);
3124 : : }
3125 : 10533 : }
3126 : :
3127 : : /* Similar, but load SRC into new pseudos in a format that looks like
3128 : : PARALLEL. This can later be fed to emit_group_move to get things
3129 : : in the right place. */
3130 : :
3131 : : rtx
3132 : 258647 : emit_group_load_into_temps (rtx parallel, rtx src, tree type, poly_int64 ssize)
3133 : : {
3134 : 258647 : rtvec vec;
3135 : 258647 : int i;
3136 : :
3137 : 258647 : vec = rtvec_alloc (XVECLEN (parallel, 0));
3138 : 258647 : emit_group_load_1 (&RTVEC_ELT (vec, 0), parallel, src, type, ssize);
3139 : :
3140 : : /* Convert the vector to look just like the original PARALLEL, except
3141 : : with the computed values. */
3142 : 767457 : for (i = 0; i < XVECLEN (parallel, 0); i++)
3143 : : {
3144 : 508810 : rtx e = XVECEXP (parallel, 0, i);
3145 : 508810 : rtx d = XEXP (e, 0);
3146 : :
3147 : 508810 : if (d)
3148 : : {
3149 : 508810 : d = force_reg (GET_MODE (d), RTVEC_ELT (vec, i));
3150 : 508810 : e = alloc_EXPR_LIST (REG_NOTE_KIND (e), d, XEXP (e, 1));
3151 : : }
3152 : 508810 : RTVEC_ELT (vec, i) = e;
3153 : : }
3154 : :
3155 : 258647 : return gen_rtx_PARALLEL (GET_MODE (parallel), vec);
3156 : : }
3157 : :
3158 : : /* Emit code to move a block SRC to block DST, where SRC and DST are
3159 : : non-consecutive groups of registers, each represented by a PARALLEL. */
3160 : :
3161 : : void
3162 : 261610 : emit_group_move (rtx dst, rtx src)
3163 : : {
3164 : 261610 : int i;
3165 : :
3166 : 261610 : gcc_assert (GET_CODE (src) == PARALLEL
3167 : : && GET_CODE (dst) == PARALLEL
3168 : : && XVECLEN (src, 0) == XVECLEN (dst, 0));
3169 : :
3170 : : /* Skip first entry if NULL. */
3171 : 774698 : for (i = XEXP (XVECEXP (src, 0, 0), 0) ? 0 : 1; i < XVECLEN (src, 0); i++)
3172 : 513088 : emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0),
3173 : 513088 : XEXP (XVECEXP (src, 0, i), 0));
3174 : 261610 : }
3175 : :
3176 : : /* Move a group of registers represented by a PARALLEL into pseudos. */
3177 : :
3178 : : rtx
3179 : 5258 : emit_group_move_into_temps (rtx src)
3180 : : {
3181 : 5258 : rtvec vec = rtvec_alloc (XVECLEN (src, 0));
3182 : 5258 : int i;
3183 : :
3184 : 12465 : for (i = 0; i < XVECLEN (src, 0); i++)
3185 : : {
3186 : 7207 : rtx e = XVECEXP (src, 0, i);
3187 : 7207 : rtx d = XEXP (e, 0);
3188 : :
3189 : 7207 : if (d)
3190 : 7207 : e = alloc_EXPR_LIST (REG_NOTE_KIND (e), copy_to_reg (d), XEXP (e, 1));
3191 : 7207 : RTVEC_ELT (vec, i) = e;
3192 : : }
3193 : :
3194 : 5258 : return gen_rtx_PARALLEL (GET_MODE (src), vec);
3195 : : }
3196 : :
3197 : : /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
3198 : : where SRC is non-consecutive registers represented by a PARALLEL.
3199 : : SSIZE represents the total size of block ORIG_DST, or -1 if not
3200 : : known. */
3201 : :
3202 : : void
3203 : 60156 : emit_group_store (rtx orig_dst, rtx src, tree type ATTRIBUTE_UNUSED,
3204 : : poly_int64 ssize)
3205 : : {
3206 : 60156 : rtx *tmps, dst;
3207 : 60156 : int start, finish, i;
3208 : 60156 : machine_mode m = GET_MODE (orig_dst);
3209 : :
3210 : 60156 : gcc_assert (GET_CODE (src) == PARALLEL);
3211 : :
3212 : 60156 : if (!SCALAR_INT_MODE_P (m)
3213 : 12548 : && !MEM_P (orig_dst) && GET_CODE (orig_dst) != CONCAT)
3214 : : {
3215 : 0 : scalar_int_mode imode;
3216 : 0 : if (int_mode_for_mode (GET_MODE (orig_dst)).exists (&imode))
3217 : : {
3218 : 0 : dst = gen_reg_rtx (imode);
3219 : 0 : emit_group_store (dst, src, type, ssize);
3220 : 0 : dst = gen_lowpart (GET_MODE (orig_dst), dst);
3221 : : }
3222 : : else
3223 : : {
3224 : 0 : dst = assign_stack_temp (GET_MODE (orig_dst), ssize);
3225 : 0 : emit_group_store (dst, src, type, ssize);
3226 : : }
3227 : 0 : emit_move_insn (orig_dst, dst);
3228 : 0 : return;
3229 : : }
3230 : :
3231 : : /* Check for a NULL entry, used to indicate that the parameter goes
3232 : : both on the stack and in registers. */
3233 : 60156 : if (XEXP (XVECEXP (src, 0, 0), 0))
3234 : : start = 0;
3235 : : else
3236 : 0 : start = 1;
3237 : 60156 : finish = XVECLEN (src, 0);
3238 : :
3239 : 60156 : tmps = XALLOCAVEC (rtx, finish);
3240 : :
3241 : : /* Copy the (probable) hard regs into pseudos. */
3242 : 173483 : for (i = start; i < finish; i++)
3243 : : {
3244 : 113327 : rtx reg = XEXP (XVECEXP (src, 0, i), 0);
3245 : 113327 : if (!REG_P (reg) || REGNO (reg) < FIRST_PSEUDO_REGISTER)
3246 : : {
3247 : 106120 : tmps[i] = gen_reg_rtx (GET_MODE (reg));
3248 : 106120 : emit_move_insn (tmps[i], reg);
3249 : : }
3250 : : else
3251 : 7207 : tmps[i] = reg;
3252 : : }
3253 : :
3254 : : /* If we won't be storing directly into memory, protect the real destination
3255 : : from strange tricks we might play. */
3256 : 60156 : dst = orig_dst;
3257 : 60156 : if (GET_CODE (dst) == PARALLEL)
3258 : : {
3259 : 0 : rtx temp;
3260 : :
3261 : : /* We can get a PARALLEL dst if there is a conditional expression in
3262 : : a return statement. In that case, the dst and src are the same,
3263 : : so no action is necessary. */
3264 : 0 : if (rtx_equal_p (dst, src))
3265 : : return;
3266 : :
3267 : : /* It is unclear if we can ever reach here, but we may as well handle
3268 : : it. Allocate a temporary, and split this into a store/load to/from
3269 : : the temporary. */
3270 : 0 : temp = assign_stack_temp (GET_MODE (dst), ssize);
3271 : 0 : emit_group_store (temp, src, type, ssize);
3272 : 0 : emit_group_load (dst, temp, type, ssize);
3273 : 0 : return;
3274 : : }
3275 : 60156 : else if (!MEM_P (dst) && GET_CODE (dst) != CONCAT)
3276 : : {
3277 : 46995 : machine_mode outer = GET_MODE (dst);
3278 : 46995 : machine_mode inner;
3279 : 46995 : poly_int64 bytepos;
3280 : 46995 : bool done = false;
3281 : 46995 : rtx temp;
3282 : :
3283 : 46995 : if (!REG_P (dst) || REGNO (dst) < FIRST_PSEUDO_REGISTER)
3284 : 0 : dst = gen_reg_rtx (outer);
3285 : :
3286 : : /* Make life a bit easier for combine: if the first element of the
3287 : : vector is the low part of the destination mode, use a paradoxical
3288 : : subreg to initialize the destination. */
3289 : 46995 : if (start < finish)
3290 : : {
3291 : 46995 : inner = GET_MODE (tmps[start]);
3292 : 46995 : bytepos = subreg_lowpart_offset (inner, outer);
3293 : 46995 : if (known_eq (rtx_to_poly_int64 (XEXP (XVECEXP (src, 0, start), 1)),
3294 : : bytepos))
3295 : : {
3296 : 46969 : temp = simplify_gen_subreg (outer, tmps[start], inner, 0);
3297 : 46969 : if (temp)
3298 : : {
3299 : 46322 : emit_move_insn (dst, temp);
3300 : 46322 : done = true;
3301 : 46322 : start++;
3302 : : }
3303 : : }
3304 : : }
3305 : :
3306 : : /* If the first element wasn't the low part, try the last. */
3307 : 46995 : if (!done
3308 : 673 : && start < finish - 1)
3309 : : {
3310 : 604 : inner = GET_MODE (tmps[finish - 1]);
3311 : 604 : bytepos = subreg_lowpart_offset (inner, outer);
3312 : 604 : if (known_eq (rtx_to_poly_int64 (XEXP (XVECEXP (src, 0,
3313 : : finish - 1), 1)),
3314 : : bytepos))
3315 : : {
3316 : 0 : temp = simplify_gen_subreg (outer, tmps[finish - 1], inner, 0);
3317 : 0 : if (temp)
3318 : : {
3319 : 0 : emit_move_insn (dst, temp);
3320 : 0 : done = true;
3321 : 0 : finish--;
3322 : : }
3323 : : }
3324 : : }
3325 : :
3326 : : /* Otherwise, simply initialize the result to zero. */
3327 : 46995 : if (!done)
3328 : 673 : emit_move_insn (dst, CONST0_RTX (outer));
3329 : : }
3330 : :
3331 : : /* Process the pieces. */
3332 : 124495 : for (i = start; i < finish; i++)
3333 : : {
3334 : 67005 : poly_int64 bytepos = rtx_to_poly_int64 (XEXP (XVECEXP (src, 0, i), 1));
3335 : 67005 : machine_mode mode = GET_MODE (tmps[i]);
3336 : 134010 : poly_int64 bytelen = GET_MODE_SIZE (mode);
3337 : 67005 : poly_uint64 adj_bytelen;
3338 : 67005 : rtx dest = dst;
3339 : :
3340 : : /* Handle trailing fragments that run over the size of the struct.
3341 : : It's the target's responsibility to make sure that the fragment
3342 : : cannot be strictly smaller in some cases and strictly larger
3343 : : in others. */
3344 : 67005 : gcc_checking_assert (ordered_p (bytepos + bytelen, ssize));
3345 : 67005 : if (known_size_p (ssize) && maybe_gt (bytepos + bytelen, ssize))
3346 : 821 : adj_bytelen = ssize - bytepos;
3347 : : else
3348 : 66184 : adj_bytelen = bytelen;
3349 : :
3350 : : /* Deal with destination CONCATs by either storing into one of the parts
3351 : : or doing a copy after storing into a register or stack temporary. */
3352 : 67005 : if (GET_CODE (dst) == CONCAT)
3353 : : {
3354 : 24860 : if (known_le (bytepos + adj_bytelen,
3355 : : GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)))))
3356 : 4882 : dest = XEXP (dst, 0);
3357 : :
3358 : 15096 : else if (known_ge (bytepos, GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)))))
3359 : : {
3360 : 9764 : bytepos -= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)));
3361 : 4882 : dest = XEXP (dst, 1);
3362 : : }
3363 : :
3364 : : else
3365 : : {
3366 : 2666 : machine_mode dest_mode = GET_MODE (dest);
3367 : 2666 : machine_mode tmp_mode = GET_MODE (tmps[i]);
3368 : 2666 : scalar_int_mode dest_imode;
3369 : :
3370 : 2666 : gcc_assert (known_eq (bytepos, 0) && XVECLEN (src, 0));
3371 : :
3372 : : /* If the source is a single scalar integer register, and the
3373 : : destination has a complex mode for which a same-sized integer
3374 : : mode exists, then we can take the left-justified part of the
3375 : : source in the complex mode. */
3376 : 2666 : if (finish == start + 1
3377 : 2666 : && REG_P (tmps[i])
3378 : 2666 : && SCALAR_INT_MODE_P (tmp_mode)
3379 : 2666 : && COMPLEX_MODE_P (dest_mode)
3380 : 5332 : && int_mode_for_mode (dest_mode).exists (&dest_imode))
3381 : : {
3382 : 2666 : const scalar_int_mode tmp_imode
3383 : 2666 : = as_a <scalar_int_mode> (tmp_mode);
3384 : :
3385 : 5332 : if (GET_MODE_BITSIZE (dest_imode)
3386 : 2666 : < GET_MODE_BITSIZE (tmp_imode))
3387 : : {
3388 : 59 : dest = gen_reg_rtx (dest_imode);
3389 : 59 : if (BYTES_BIG_ENDIAN)
3390 : : tmps[i] = expand_shift (RSHIFT_EXPR, tmp_mode, tmps[i],
3391 : : GET_MODE_BITSIZE (tmp_imode)
3392 : : - GET_MODE_BITSIZE (dest_imode),
3393 : : NULL_RTX, 1);
3394 : 59 : emit_move_insn (dest, gen_lowpart (dest_imode, tmps[i]));
3395 : 59 : dst = gen_lowpart (dest_mode, dest);
3396 : : }
3397 : : else
3398 : 2607 : dst = gen_lowpart (dest_mode, tmps[i]);
3399 : : }
3400 : :
3401 : : /* Otherwise spill the source onto the stack using the more
3402 : : aligned of the two modes. */
3403 : 0 : else if (GET_MODE_ALIGNMENT (dest_mode)
3404 : 0 : >= GET_MODE_ALIGNMENT (tmp_mode))
3405 : : {
3406 : 0 : dest = assign_stack_temp (dest_mode,
3407 : 0 : GET_MODE_SIZE (dest_mode));
3408 : 0 : emit_move_insn (adjust_address (dest, tmp_mode, bytepos),
3409 : : tmps[i]);
3410 : 0 : dst = dest;
3411 : : }
3412 : :
3413 : : else
3414 : : {
3415 : 0 : dest = assign_stack_temp (tmp_mode,
3416 : 0 : GET_MODE_SIZE (tmp_mode));
3417 : 0 : emit_move_insn (dest, tmps[i]);
3418 : 0 : dst = adjust_address (dest, dest_mode, bytepos);
3419 : : }
3420 : :
3421 : 2666 : break;
3422 : : }
3423 : : }
3424 : :
3425 : : /* Handle trailing fragments that run over the size of the struct. */
3426 : 64339 : if (known_size_p (ssize) && maybe_gt (bytepos + bytelen, ssize))
3427 : : {
3428 : : /* store_bit_field always takes its value from the lsb.
3429 : : Move the fragment to the lsb if it's not already there. */
3430 : 762 : if (
3431 : : #ifdef BLOCK_REG_PADDING
3432 : : BLOCK_REG_PADDING (GET_MODE (orig_dst), type, i == start)
3433 : : == (BYTES_BIG_ENDIAN ? PAD_UPWARD : PAD_DOWNWARD)
3434 : : #else
3435 : : BYTES_BIG_ENDIAN
3436 : : #endif
3437 : : )
3438 : : {
3439 : : poly_int64 shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
3440 : : tmps[i] = expand_shift (RSHIFT_EXPR, mode, tmps[i],
3441 : : shift, tmps[i], 0);
3442 : : }
3443 : :
3444 : : /* Make sure not to write past the end of the struct. */
3445 : 3810 : store_bit_field (dest,
3446 : 762 : adj_bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
3447 : 1524 : bytepos * BITS_PER_UNIT, ssize * BITS_PER_UNIT - 1,
3448 : : VOIDmode, tmps[i], false, false);
3449 : : }
3450 : :
3451 : : /* Optimize the access just a bit. */
3452 : 63577 : else if (MEM_P (dest)
3453 : 7045 : && (!targetm.slow_unaligned_access (mode, MEM_ALIGN (dest))
3454 : 0 : || MEM_ALIGN (dest) >= GET_MODE_ALIGNMENT (mode))
3455 : 7045 : && multiple_p (bytepos * BITS_PER_UNIT,
3456 : : GET_MODE_ALIGNMENT (mode))
3457 : 70622 : && known_eq (bytelen, GET_MODE_SIZE (mode)))
3458 : 7045 : emit_move_insn (adjust_address (dest, mode, bytepos), tmps[i]);
3459 : :
3460 : : else
3461 : 56532 : store_bit_field (dest, bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
3462 : 113064 : 0, 0, mode, tmps[i], false, false);
3463 : : }
3464 : :
3465 : : /* Copy from the pseudo into the (probable) hard reg. */
3466 : 60156 : if (orig_dst != dst)
3467 : 2666 : emit_move_insn (orig_dst, dst);
3468 : : }
3469 : :
3470 : : /* Return a form of X that does not use a PARALLEL. TYPE is the type
3471 : : of the value stored in X. */
3472 : :
3473 : : rtx
3474 : 327193 : maybe_emit_group_store (rtx x, tree type)
3475 : : {
3476 : 327193 : machine_mode mode = TYPE_MODE (type);
3477 : 327193 : gcc_checking_assert (GET_MODE (x) == VOIDmode || GET_MODE (x) == mode);
3478 : 327193 : if (GET_CODE (x) == PARALLEL)
3479 : : {
3480 : 0 : rtx result = gen_reg_rtx (mode);
3481 : 0 : emit_group_store (result, x, type, int_size_in_bytes (type));
3482 : 0 : return result;
3483 : : }
3484 : : return x;
3485 : : }
3486 : :
3487 : : /* Copy a BLKmode object of TYPE out of a register SRCREG into TARGET.
3488 : :
3489 : : This is used on targets that return BLKmode values in registers. */
3490 : :
3491 : : static void
3492 : 278 : copy_blkmode_from_reg (rtx target, rtx srcreg, tree type)
3493 : : {
3494 : 278 : unsigned HOST_WIDE_INT bytes = int_size_in_bytes (type);
3495 : 278 : rtx src = NULL, dst = NULL;
3496 : 278 : unsigned HOST_WIDE_INT bitsize = MIN (TYPE_ALIGN (type), BITS_PER_WORD);
3497 : 278 : unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0;
3498 : : /* No current ABI uses variable-sized modes to pass a BLKmnode type. */
3499 : 278 : fixed_size_mode mode = as_a <fixed_size_mode> (GET_MODE (srcreg));
3500 : 278 : fixed_size_mode tmode = as_a <fixed_size_mode> (GET_MODE (target));
3501 : 278 : fixed_size_mode copy_mode;
3502 : :
3503 : : /* BLKmode registers created in the back-end shouldn't have survived. */
3504 : 278 : gcc_assert (mode != BLKmode);
3505 : :
3506 : : /* If the structure doesn't take up a whole number of words, see whether
3507 : : SRCREG is padded on the left or on the right. If it's on the left,
3508 : : set PADDING_CORRECTION to the number of bits to skip.
3509 : :
3510 : : In most ABIs, the structure will be returned at the least end of
3511 : : the register, which translates to right padding on little-endian
3512 : : targets and left padding on big-endian targets. The opposite
3513 : : holds if the structure is returned at the most significant
3514 : : end of the register. */
3515 : 278 : if (bytes % UNITS_PER_WORD != 0
3516 : 278 : && (targetm.calls.return_in_msb (type)
3517 : 206 : ? !BYTES_BIG_ENDIAN
3518 : : : BYTES_BIG_ENDIAN))
3519 : 0 : padding_correction
3520 : 0 : = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD) * BITS_PER_UNIT));
3521 : :
3522 : : /* We can use a single move if we have an exact mode for the size. */
3523 : 278 : else if (MEM_P (target)
3524 : 278 : && (!targetm.slow_unaligned_access (mode, MEM_ALIGN (target))
3525 : 0 : || MEM_ALIGN (target) >= GET_MODE_ALIGNMENT (mode))
3526 : 556 : && bytes == GET_MODE_SIZE (mode))
3527 : : {
3528 : 79 : emit_move_insn (adjust_address (target, mode, 0), srcreg);
3529 : 79 : return;
3530 : : }
3531 : :
3532 : : /* And if we additionally have the same mode for a register. */
3533 : 199 : else if (REG_P (target)
3534 : 0 : && GET_MODE (target) == mode
3535 : 199 : && bytes == GET_MODE_SIZE (mode))
3536 : : {
3537 : 0 : emit_move_insn (target, srcreg);
3538 : 0 : return;
3539 : : }
3540 : :
3541 : : /* This code assumes srcreg is at least a full word. If it isn't, copy it
3542 : : into a new pseudo which is a full word. */
3543 : 398 : if (GET_MODE_SIZE (mode) < UNITS_PER_WORD)
3544 : : {
3545 : 81 : srcreg = convert_to_mode (word_mode, srcreg, TYPE_UNSIGNED (type));
3546 : 81 : mode = word_mode;
3547 : : }
3548 : :
3549 : : /* Copy the structure BITSIZE bits at a time. If the target lives in
3550 : : memory, take care of not reading/writing past its end by selecting
3551 : : a copy mode suited to BITSIZE. This should always be possible given
3552 : : how it is computed.
3553 : :
3554 : : If the target lives in register, make sure not to select a copy mode
3555 : : larger than the mode of the register.
3556 : :
3557 : : We could probably emit more efficient code for machines which do not use
3558 : : strict alignment, but it doesn't seem worth the effort at the current
3559 : : time. */
3560 : :
3561 : 199 : copy_mode = word_mode;
3562 : 199 : if (MEM_P (target))
3563 : : {
3564 : 199 : opt_scalar_int_mode mem_mode = int_mode_for_size (bitsize, 1);
3565 : 199 : if (mem_mode.exists ())
3566 : 199 : copy_mode = mem_mode.require ();
3567 : : }
3568 : 0 : else if (REG_P (target) && GET_MODE_BITSIZE (tmode) < BITS_PER_WORD)
3569 : : copy_mode = tmode;
3570 : :
3571 : 199 : for (bitpos = 0, xbitpos = padding_correction;
3572 : 985 : bitpos < bytes * BITS_PER_UNIT;
3573 : 786 : bitpos += bitsize, xbitpos += bitsize)
3574 : : {
3575 : : /* We need a new source operand each time xbitpos is on a
3576 : : word boundary and when xbitpos == padding_correction
3577 : : (the first time through). */
3578 : 786 : if (xbitpos % BITS_PER_WORD == 0 || xbitpos == padding_correction)
3579 : 199 : src = operand_subword_force (srcreg, xbitpos / BITS_PER_WORD, mode);
3580 : :
3581 : : /* We need a new destination operand each time bitpos is on
3582 : : a word boundary. */
3583 : 786 : if (REG_P (target) && GET_MODE_BITSIZE (tmode) < BITS_PER_WORD)
3584 : : dst = target;
3585 : 786 : else if (bitpos % BITS_PER_WORD == 0)
3586 : 199 : dst = operand_subword (target, bitpos / BITS_PER_WORD, 1, tmode);
3587 : :
3588 : : /* Use xbitpos for the source extraction (right justified) and
3589 : : bitpos for the destination store (left justified). */
3590 : 786 : store_bit_field (dst, bitsize, bitpos % BITS_PER_WORD, 0, 0, copy_mode,
3591 : : extract_bit_field (src, bitsize,
3592 : 1572 : xbitpos % BITS_PER_WORD, 1,
3593 : : NULL_RTX, copy_mode, copy_mode,
3594 : : false, NULL),
3595 : : false, false);
3596 : : }
3597 : : }
3598 : :
3599 : : /* Copy BLKmode value SRC into a register of mode MODE_IN. Return the
3600 : : register if it contains any data, otherwise return null.
3601 : :
3602 : : This is used on targets that return BLKmode values in registers. */
3603 : :
3604 : : rtx
3605 : 3192 : copy_blkmode_to_reg (machine_mode mode_in, tree src)
3606 : : {
3607 : 3192 : int i, n_regs;
3608 : 3192 : unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0, bytes;
3609 : 3192 : unsigned int bitsize;
3610 : 3192 : rtx *dst_words, dst, x, src_word = NULL_RTX, dst_word = NULL_RTX;
3611 : : /* No current ABI uses variable-sized modes to pass a BLKmnode type. */
3612 : 3192 : fixed_size_mode mode = as_a <fixed_size_mode> (mode_in);
3613 : 3192 : fixed_size_mode dst_mode;
3614 : 3192 : scalar_int_mode min_mode;
3615 : :
3616 : 3192 : gcc_assert (TYPE_MODE (TREE_TYPE (src)) == BLKmode);
3617 : :
3618 : 3192 : x = expand_normal (src);
3619 : :
3620 : 3192 : bytes = arg_int_size_in_bytes (TREE_TYPE (src));
3621 : 3192 : if (bytes == 0)
3622 : : return NULL_RTX;
3623 : :
3624 : : /* If the structure doesn't take up a whole number of words, see
3625 : : whether the register value should be padded on the left or on
3626 : : the right. Set PADDING_CORRECTION to the number of padding
3627 : : bits needed on the left side.
3628 : :
3629 : : In most ABIs, the structure will be returned at the least end of
3630 : : the register, which translates to right padding on little-endian
3631 : : targets and left padding on big-endian targets. The opposite
3632 : : holds if the structure is returned at the most significant
3633 : : end of the register. */
3634 : 1208 : if (bytes % UNITS_PER_WORD != 0
3635 : 1208 : && (targetm.calls.return_in_msb (TREE_TYPE (src))
3636 : 1174 : ? !BYTES_BIG_ENDIAN
3637 : : : BYTES_BIG_ENDIAN))
3638 : 0 : padding_correction = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD)
3639 : 0 : * BITS_PER_UNIT));
3640 : :
3641 : 1208 : n_regs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3642 : 1208 : dst_words = XALLOCAVEC (rtx, n_regs);
3643 : 1208 : bitsize = MIN (TYPE_ALIGN (TREE_TYPE (src)), BITS_PER_WORD);
3644 : 1208 : min_mode = smallest_int_mode_for_size (bitsize);
3645 : :
3646 : : /* Copy the structure BITSIZE bits at a time. */
3647 : 1208 : for (bitpos = 0, xbitpos = padding_correction;
3648 : 3928 : bitpos < bytes * BITS_PER_UNIT;
3649 : 2720 : bitpos += bitsize, xbitpos += bitsize)
3650 : : {
3651 : : /* We need a new destination pseudo each time xbitpos is
3652 : : on a word boundary and when xbitpos == padding_correction
3653 : : (the first time through). */
3654 : 2720 : if (xbitpos % BITS_PER_WORD == 0
3655 : 1509 : || xbitpos == padding_correction)
3656 : : {
3657 : : /* Generate an appropriate register. */
3658 : 1211 : dst_word = gen_reg_rtx (word_mode);
3659 : 1211 : dst_words[xbitpos / BITS_PER_WORD] = dst_word;
3660 : :
3661 : : /* Clear the destination before we move anything into it. */
3662 : 1211 : emit_move_insn (dst_word, CONST0_RTX (word_mode));
3663 : : }
3664 : :
3665 : : /* Find the largest integer mode that can be used to copy all or as
3666 : : many bits as possible of the structure if the target supports larger
3667 : : copies. There are too many corner cases here w.r.t to alignments on
3668 : : the read/writes. So if there is any padding just use single byte
3669 : : operations. */
3670 : 2720 : opt_scalar_int_mode mode_iter;
3671 : 2720 : if (padding_correction == 0 && !STRICT_ALIGNMENT)
3672 : : {
3673 : 7409 : FOR_EACH_MODE_FROM (mode_iter, min_mode)
3674 : : {
3675 : 7409 : unsigned int msize = GET_MODE_BITSIZE (mode_iter.require ());
3676 : 7409 : if (msize <= ((bytes * BITS_PER_UNIT) - bitpos)
3677 : 4692 : && msize <= BITS_PER_WORD)
3678 : 4689 : bitsize = msize;
3679 : : else
3680 : : break;
3681 : : }
3682 : : }
3683 : :
3684 : : /* We need a new source operand each time bitpos is on a word
3685 : : boundary. */
3686 : 2720 : if (bitpos % BITS_PER_WORD == 0)
3687 : 1211 : src_word = operand_subword_force (x, bitpos / BITS_PER_WORD, BLKmode);
3688 : :
3689 : : /* Use bitpos for the source extraction (left justified) and
3690 : : xbitpos for the destination store (right justified). */
3691 : 8160 : store_bit_field (dst_word, bitsize, xbitpos % BITS_PER_WORD,
3692 : 2720 : 0, 0, word_mode,
3693 : : extract_bit_field (src_word, bitsize,
3694 : 5440 : bitpos % BITS_PER_WORD, 1,
3695 : : NULL_RTX, word_mode, word_mode,
3696 : : false, NULL),
3697 : : false, false);
3698 : : }
3699 : :
3700 : 1208 : if (mode == BLKmode)
3701 : : {
3702 : : /* Find the smallest integer mode large enough to hold the
3703 : : entire structure. */
3704 : 0 : opt_scalar_int_mode mode_iter;
3705 : 0 : FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_INT)
3706 : 0 : if (GET_MODE_SIZE (mode_iter.require ()) >= bytes)
3707 : : break;
3708 : :
3709 : : /* A suitable mode should have been found. */
3710 : 0 : mode = mode_iter.require ();
3711 : : }
3712 : :
3713 : 3624 : if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
3714 : : dst_mode = word_mode;
3715 : : else
3716 : 480 : dst_mode = mode;
3717 : 1208 : dst = gen_reg_rtx (dst_mode);
3718 : :
3719 : 2419 : for (i = 0; i < n_regs; i++)
3720 : 1211 : emit_move_insn (operand_subword (dst, i, 0, dst_mode), dst_words[i]);
3721 : :
3722 : 1208 : if (mode != dst_mode)
3723 : 728 : dst = gen_lowpart (mode, dst);
3724 : :
3725 : : return dst;
3726 : : }
3727 : :
3728 : : /* Add a USE expression for REG to the (possibly empty) list pointed
3729 : : to by CALL_FUSAGE. REG must denote a hard register. */
3730 : :
3731 : : void
3732 : 10767368 : use_reg_mode (rtx *call_fusage, rtx reg, machine_mode mode)
3733 : : {
3734 : 10767368 : gcc_assert (REG_P (reg));
3735 : :
3736 : 10767368 : if (!HARD_REGISTER_P (reg))
3737 : : return;
3738 : :
3739 : 10767368 : *call_fusage
3740 : 10767368 : = gen_rtx_EXPR_LIST (mode, gen_rtx_USE (VOIDmode, reg), *call_fusage);
3741 : : }
3742 : :
3743 : : /* Add a CLOBBER expression for REG to the (possibly empty) list pointed
3744 : : to by CALL_FUSAGE. REG must denote a hard register. */
3745 : :
3746 : : void
3747 : 797463 : clobber_reg_mode (rtx *call_fusage, rtx reg, machine_mode mode)
3748 : : {
3749 : 797463 : gcc_assert (REG_P (reg) && REGNO (reg) < FIRST_PSEUDO_REGISTER);
3750 : :
3751 : 797463 : *call_fusage
3752 : 797463 : = gen_rtx_EXPR_LIST (mode, gen_rtx_CLOBBER (VOIDmode, reg), *call_fusage);
3753 : 797463 : }
3754 : :
3755 : : /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
3756 : : starting at REGNO. All of these registers must be hard registers. */
3757 : :
3758 : : void
3759 : 1576 : use_regs (rtx *call_fusage, int regno, int nregs)
3760 : : {
3761 : 1576 : int i;
3762 : :
3763 : 1576 : gcc_assert (regno + nregs <= FIRST_PSEUDO_REGISTER);
3764 : :
3765 : 3152 : for (i = 0; i < nregs; i++)
3766 : 1576 : use_reg (call_fusage, regno_reg_rtx[regno + i]);
3767 : 1576 : }
3768 : :
3769 : : /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
3770 : : PARALLEL REGS. This is for calls that pass values in multiple
3771 : : non-contiguous locations. The Irix 6 ABI has examples of this. */
3772 : :
3773 : : void
3774 : 265595 : use_group_regs (rtx *call_fusage, rtx regs)
3775 : : {
3776 : 265595 : int i;
3777 : :
3778 : 788301 : for (i = 0; i < XVECLEN (regs, 0); i++)
3779 : : {
3780 : 522706 : rtx reg = XEXP (XVECEXP (regs, 0, i), 0);
3781 : :
3782 : : /* A NULL entry means the parameter goes both on the stack and in
3783 : : registers. This can also be a MEM for targets that pass values
3784 : : partially on the stack and partially in registers. */
3785 : 522706 : if (reg != 0 && REG_P (reg))
3786 : 522706 : use_reg (call_fusage, reg);
3787 : : }
3788 : 265595 : }
3789 : :
3790 : : /* Return the defining gimple statement for SSA_NAME NAME if it is an
3791 : : assigment and the code of the expresion on the RHS is CODE. Return
3792 : : NULL otherwise. */
3793 : :
3794 : : static gimple *
3795 : 10401287 : get_def_for_expr (tree name, enum tree_code code)
3796 : : {
3797 : 10401287 : gimple *def_stmt;
3798 : :
3799 : 10401287 : if (TREE_CODE (name) != SSA_NAME)
3800 : : return NULL;
3801 : :
3802 : 8327597 : def_stmt = get_gimple_for_ssa_name (name);
3803 : 8327597 : if (!def_stmt
3804 : 8327597 : || gimple_assign_rhs_code (def_stmt) != code)
3805 : : return NULL;
3806 : :
3807 : : return def_stmt;
3808 : : }
3809 : :
3810 : : /* Return the defining gimple statement for SSA_NAME NAME if it is an
3811 : : assigment and the class of the expresion on the RHS is CLASS. Return
3812 : : NULL otherwise. */
3813 : :
3814 : : static gimple *
3815 : 10543 : get_def_for_expr_class (tree name, enum tree_code_class tclass)
3816 : : {
3817 : 10543 : gimple *def_stmt;
3818 : :
3819 : 10543 : if (TREE_CODE (name) != SSA_NAME)
3820 : : return NULL;
3821 : :
3822 : 10543 : def_stmt = get_gimple_for_ssa_name (name);
3823 : 10543 : if (!def_stmt
3824 : 10543 : || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt)) != tclass)
3825 : : return NULL;
3826 : :
3827 : : return def_stmt;
3828 : : }
3829 : :
3830 : : /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
3831 : : its length in bytes. */
3832 : :
3833 : : rtx
3834 : 112097 : clear_storage_hints (rtx object, rtx size, enum block_op_methods method,
3835 : : unsigned int expected_align, HOST_WIDE_INT expected_size,
3836 : : unsigned HOST_WIDE_INT min_size,
3837 : : unsigned HOST_WIDE_INT max_size,
3838 : : unsigned HOST_WIDE_INT probable_max_size,
3839 : : unsigned ctz_size)
3840 : : {
3841 : 112097 : machine_mode mode = GET_MODE (object);
3842 : 112097 : unsigned int align;
3843 : :
3844 : 112097 : gcc_assert (method == BLOCK_OP_NORMAL || method == BLOCK_OP_TAILCALL);
3845 : :
3846 : : /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
3847 : : just move a zero. Otherwise, do this a piece at a time. */
3848 : 112097 : poly_int64 size_val;
3849 : 112097 : if (mode != BLKmode
3850 : 46558 : && poly_int_rtx_p (size, &size_val)
3851 : 158655 : && known_eq (size_val, GET_MODE_SIZE (mode)))
3852 : : {
3853 : 46558 : rtx zero = CONST0_RTX (mode);
3854 : 46558 : if (zero != NULL)
3855 : : {
3856 : 46558 : emit_move_insn (object, zero);
3857 : 46558 : return NULL;
3858 : : }
3859 : :
3860 : 0 : if (COMPLEX_MODE_P (mode))
3861 : : {
3862 : 0 : zero = CONST0_RTX (GET_MODE_INNER (mode));
3863 : 0 : if (zero != NULL)
3864 : : {
3865 : 0 : write_complex_part (object, zero, 0, true);
3866 : 0 : write_complex_part (object, zero, 1, false);
3867 : 0 : return NULL;
3868 : : }
3869 : : }
3870 : : }
3871 : :
3872 : 65539 : if (size == const0_rtx)
3873 : : return NULL;
3874 : :
3875 : 65539 : align = MEM_ALIGN (object);
3876 : :
3877 : 65539 : if (CONST_INT_P (size)
3878 : 124429 : && targetm.use_by_pieces_infrastructure_p (INTVAL (size), align,
3879 : : CLEAR_BY_PIECES,
3880 : 58890 : optimize_insn_for_speed_p ()))
3881 : 41535 : clear_by_pieces (object, INTVAL (size), align);
3882 : 24004 : else if (set_storage_via_setmem (object, size, const0_rtx, align,
3883 : : expected_align, expected_size,
3884 : : min_size, max_size, probable_max_size))
3885 : : ;
3886 : 5434 : else if (try_store_by_multiple_pieces (object, size, ctz_size,
3887 : : min_size, max_size,
3888 : : NULL_RTX, 0, align))
3889 : : ;
3890 : 5379 : else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object)))
3891 : 5379 : return set_storage_via_libcall (object, size, const0_rtx,
3892 : 5379 : method == BLOCK_OP_TAILCALL);
3893 : : else
3894 : 0 : gcc_unreachable ();
3895 : :
3896 : : return NULL;
3897 : : }
3898 : :
3899 : : rtx
3900 : 91556 : clear_storage (rtx object, rtx size, enum block_op_methods method)
3901 : : {
3902 : 91556 : unsigned HOST_WIDE_INT max, min = 0;
3903 : 91556 : if (GET_CODE (size) == CONST_INT)
3904 : 91556 : min = max = UINTVAL (size);
3905 : : else
3906 : 0 : max = GET_MODE_MASK (GET_MODE (size));
3907 : 91556 : return clear_storage_hints (object, size, method, 0, -1, min, max, max, 0);
3908 : : }
3909 : :
3910 : :
3911 : : /* A subroutine of clear_storage. Expand a call to memset.
3912 : : Return the return value of memset, 0 otherwise. */
3913 : :
3914 : : rtx
3915 : 5384 : set_storage_via_libcall (rtx object, rtx size, rtx val, bool tailcall)
3916 : : {
3917 : 5384 : tree call_expr, fn, object_tree, size_tree, val_tree;
3918 : 5384 : machine_mode size_mode;
3919 : :
3920 : 5384 : object = copy_addr_to_reg (XEXP (object, 0));
3921 : 5384 : object_tree = make_tree (ptr_type_node, object);
3922 : :
3923 : 5384 : if (!CONST_INT_P (val))
3924 : 4 : val = convert_to_mode (TYPE_MODE (integer_type_node), val, 1);
3925 : 5384 : val_tree = make_tree (integer_type_node, val);
3926 : :
3927 : 5384 : size_mode = TYPE_MODE (sizetype);
3928 : 5384 : size = convert_to_mode (size_mode, size, 1);
3929 : 5384 : size = copy_to_mode_reg (size_mode, size);
3930 : 5384 : size_tree = make_tree (sizetype, size);
3931 : :
3932 : : /* It is incorrect to use the libcall calling conventions for calls to
3933 : : memset because it can be provided by the user. */
3934 : 5384 : fn = builtin_decl_implicit (BUILT_IN_MEMSET);
3935 : 5384 : call_expr = build_call_expr (fn, 3, object_tree, val_tree, size_tree);
3936 : 5384 : CALL_EXPR_TAILCALL (call_expr) = tailcall;
3937 : :
3938 : 5384 : return expand_call (call_expr, NULL_RTX, false);
3939 : : }
3940 : :
3941 : : /* Expand a setmem pattern; return true if successful. */
3942 : :
3943 : : bool
3944 : 31357 : set_storage_via_setmem (rtx object, rtx size, rtx val, unsigned int align,
3945 : : unsigned int expected_align, HOST_WIDE_INT expected_size,
3946 : : unsigned HOST_WIDE_INT min_size,
3947 : : unsigned HOST_WIDE_INT max_size,
3948 : : unsigned HOST_WIDE_INT probable_max_size)
3949 : : {
3950 : : /* Try the most limited insn first, because there's no point
3951 : : including more than one in the machine description unless
3952 : : the more limited one has some advantage. */
3953 : :
3954 : 31357 : if (expected_align < align)
3955 : : expected_align = align;
3956 : 31357 : if (expected_size != -1)
3957 : : {
3958 : 5 : if ((unsigned HOST_WIDE_INT)expected_size > max_size)
3959 : 0 : expected_size = max_size;
3960 : 5 : if ((unsigned HOST_WIDE_INT)expected_size < min_size)
3961 : 0 : expected_size = min_size;
3962 : : }
3963 : :
3964 : 31357 : opt_scalar_int_mode mode_iter;
3965 : 149254 : FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_INT)
3966 : : {
3967 : 138334 : scalar_int_mode mode = mode_iter.require ();
3968 : 138334 : enum insn_code code = direct_optab_handler (setmem_optab, mode);
3969 : :
3970 : 138334 : if (code != CODE_FOR_nothing
3971 : : /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
3972 : : here because if SIZE is less than the mode mask, as it is
3973 : : returned by the macro, it will definitely be less than the
3974 : : actual mode mask. Since SIZE is within the Pmode address
3975 : : space, we limit MODE to Pmode. */
3976 : 138334 : && ((CONST_INT_P (size)
3977 : 18592 : && ((unsigned HOST_WIDE_INT) INTVAL (size)
3978 : 18592 : <= (GET_MODE_MASK (mode) >> 1)))
3979 : 23591 : || max_size <= (GET_MODE_MASK (mode) >> 1)
3980 : 32180 : || GET_MODE_BITSIZE (mode) >= GET_MODE_BITSIZE (Pmode)))
3981 : : {
3982 : 32386 : class expand_operand ops[9];
3983 : 32386 : unsigned int nops;
3984 : :
3985 : 32386 : nops = insn_data[(int) code].n_generator_args;
3986 : 32386 : gcc_assert (nops == 4 || nops == 6 || nops == 8 || nops == 9);
3987 : :
3988 : 32386 : create_fixed_operand (&ops[0], object);
3989 : : /* The check above guarantees that this size conversion is valid. */
3990 : 32386 : create_convert_operand_to (&ops[1], size, mode, true);
3991 : 32386 : create_convert_operand_from (&ops[2], val, byte_mode, true);
3992 : 32386 : create_integer_operand (&ops[3], align / BITS_PER_UNIT);
3993 : 32386 : if (nops >= 6)
3994 : : {
3995 : 32386 : create_integer_operand (&ops[4], expected_align / BITS_PER_UNIT);
3996 : 32386 : create_integer_operand (&ops[5], expected_size);
3997 : : }
3998 : 32386 : if (nops >= 8)
3999 : : {
4000 : 32386 : create_integer_operand (&ops[6], min_size);
4001 : : /* If we cannot represent the maximal size,
4002 : : make parameter NULL. */
4003 : 32386 : if ((HOST_WIDE_INT) max_size != -1)
4004 : 26878 : create_integer_operand (&ops[7], max_size);
4005 : : else
4006 : 5508 : create_fixed_operand (&ops[7], NULL);
4007 : : }
4008 : 32386 : if (nops == 9)
4009 : : {
4010 : : /* If we cannot represent the maximal size,
4011 : : make parameter NULL. */
4012 : 32386 : if ((HOST_WIDE_INT) probable_max_size != -1)
4013 : 27287 : create_integer_operand (&ops[8], probable_max_size);
4014 : : else
4015 : 5099 : create_fixed_operand (&ops[8], NULL);
4016 : : }
4017 : 32386 : if (maybe_expand_insn (code, nops, ops))
4018 : 20437 : return true;
4019 : : }
4020 : : }
4021 : :
4022 : : return false;
4023 : : }
4024 : :
4025 : :
4026 : : /* Write to one of the components of the complex value CPLX. Write VAL to
4027 : : the real part if IMAG_P is false, and the imaginary part if its true.
4028 : : If UNDEFINED_P then the value in CPLX is currently undefined. */
4029 : :
4030 : : void
4031 : 551720 : write_complex_part (rtx cplx, rtx val, bool imag_p, bool undefined_p)
4032 : : {
4033 : 551720 : machine_mode cmode;
4034 : 551720 : scalar_mode imode;
4035 : 551720 : unsigned ibitsize;
4036 : :
4037 : 551720 : if (GET_CODE (cplx) == CONCAT)
4038 : : {
4039 : 491088 : emit_move_insn (XEXP (cplx, imag_p), val);
4040 : 1035516 : return;
4041 : : }
4042 : :
4043 : 60632 : cmode = GET_MODE (cplx);
4044 : 60632 : imode = GET_MODE_INNER (cmode);
4045 : 60632 : ibitsize = GET_MODE_BITSIZE (imode);
4046 : :
4047 : : /* For MEMs simplify_gen_subreg may generate an invalid new address
4048 : : because, e.g., the original address is considered mode-dependent
4049 : : by the target, which restricts simplify_subreg from invoking
4050 : : adjust_address_nv. Instead of preparing fallback support for an
4051 : : invalid address, we call adjust_address_nv directly. */
4052 : 60632 : if (MEM_P (cplx))
4053 : : {
4054 : 74238 : emit_move_insn (adjust_address_nv (cplx, imode,
4055 : : imag_p ? GET_MODE_SIZE (imode) : 0),
4056 : : val);
4057 : 49492 : return;
4058 : : }
4059 : :
4060 : : /* If the sub-object is at least word sized, then we know that subregging
4061 : : will work. This special case is important, since store_bit_field
4062 : : wants to operate on integer modes, and there's rarely an OImode to
4063 : : correspond to TCmode. */
4064 : 11140 : if (ibitsize >= BITS_PER_WORD
4065 : : /* For hard regs we have exact predicates. Assume we can split
4066 : : the original object if it spans an even number of hard regs.
4067 : : This special case is important for SCmode on 64-bit platforms
4068 : : where the natural size of floating-point regs is 32-bit. */
4069 : 11140 : || (REG_P (cplx)
4070 : 7308 : && REGNO (cplx) < FIRST_PSEUDO_REGISTER
4071 : 7128 : && REG_NREGS (cplx) % 2 == 0))
4072 : : {
4073 : 3848 : rtx part = simplify_gen_subreg (imode, cplx, cmode,
4074 : 5772 : imag_p ? GET_MODE_SIZE (imode) : 0);
4075 : 3848 : if (part)
4076 : : {
4077 : 3848 : emit_move_insn (part, val);
4078 : 3848 : return;
4079 : : }
4080 : : else
4081 : : /* simplify_gen_subreg may fail for sub-word MEMs. */
4082 : 0 : gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
4083 : : }
4084 : :
4085 : 10938 : store_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0, 0, 0, imode, val,
4086 : : false, undefined_p);
4087 : : }
4088 : :
4089 : : /* Extract one of the components of the complex value CPLX. Extract the
4090 : : real part if IMAG_P is false, and the imaginary part if it's true. */
4091 : :
4092 : : rtx
4093 : 494474 : read_complex_part (rtx cplx, bool imag_p)
4094 : : {
4095 : 494474 : machine_mode cmode;
4096 : 494474 : scalar_mode imode;
4097 : 494474 : unsigned ibitsize;
4098 : :
4099 : 494474 : if (GET_CODE (cplx) == CONCAT)
4100 : 321291 : return XEXP (cplx, imag_p);
4101 : :
4102 : 173183 : cmode = GET_MODE (cplx);
4103 : 173183 : imode = GET_MODE_INNER (cmode);
4104 : 173183 : ibitsize = GET_MODE_BITSIZE (imode);
4105 : :
4106 : : /* Special case reads from complex constants that got spilled to memory. */
4107 : 173183 : if (MEM_P (cplx) && GET_CODE (XEXP (cplx, 0)) == SYMBOL_REF)
4108 : : {
4109 : 37076 : tree decl = SYMBOL_REF_DECL (XEXP (cplx, 0));
4110 : 37076 : if (decl && TREE_CODE (decl) == COMPLEX_CST)
4111 : : {
4112 : 0 : tree part = imag_p ? TREE_IMAGPART (decl) : TREE_REALPART (decl);
4113 : 0 : if (CONSTANT_CLASS_P (part))
4114 : 0 : return expand_expr (part, NULL_RTX, imode, EXPAND_NORMAL);
4115 : : }
4116 : : }
4117 : :
4118 : : /* For MEMs simplify_gen_subreg may generate an invalid new address
4119 : : because, e.g., the original address is considered mode-dependent
4120 : : by the target, which restricts simplify_subreg from invoking
4121 : : adjust_address_nv. Instead of preparing fallback support for an
4122 : : invalid address, we call adjust_address_nv directly. */
4123 : 173183 : if (MEM_P (cplx))
4124 : 232273 : return adjust_address_nv (cplx, imode,
4125 : : imag_p ? GET_MODE_SIZE (imode) : 0);
4126 : :
4127 : : /* If the sub-object is at least word sized, then we know that subregging
4128 : : will work. This special case is important, since extract_bit_field
4129 : : wants to operate on integer modes, and there's rarely an OImode to
4130 : : correspond to TCmode. */
4131 : 18207 : if (ibitsize >= BITS_PER_WORD
4132 : : /* For hard regs we have exact predicates. Assume we can split
4133 : : the original object if it spans an even number of hard regs.
4134 : : This special case is important for SCmode on 64-bit platforms
4135 : : where the natural size of floating-point regs is 32-bit. */
4136 : 18207 : || (REG_P (cplx)
4137 : 342 : && REGNO (cplx) < FIRST_PSEUDO_REGISTER
4138 : 296 : && REG_NREGS (cplx) % 2 == 0))
4139 : : {
4140 : 9045 : rtx ret = simplify_gen_subreg (imode, cplx, cmode,
4141 : 13567 : imag_p ? GET_MODE_SIZE (imode) : 0);
4142 : 9045 : if (ret)
4143 : : return ret;
4144 : : else
4145 : : /* simplify_gen_subreg may fail for sub-word MEMs. */
4146 : 0 : gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
4147 : : }
4148 : :
4149 : 13743 : return extract_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0,
4150 : : true, NULL_RTX, imode, imode, false, NULL);
4151 : : }
4152 : :
4153 : : /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
4154 : : NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
4155 : : represented in NEW_MODE. If FORCE is true, this will never happen, as
4156 : : we'll force-create a SUBREG if needed. */
4157 : :
4158 : : static rtx
4159 : 260522 : emit_move_change_mode (machine_mode new_mode,
4160 : : machine_mode old_mode, rtx x, bool force)
4161 : : {
4162 : 260522 : rtx ret;
4163 : :
4164 : 260522 : if (push_operand (x, GET_MODE (x)))
4165 : : {
4166 : 1316 : ret = gen_rtx_MEM (new_mode, XEXP (x, 0));
4167 : 1316 : MEM_COPY_ATTRIBUTES (ret, x);
4168 : : }
4169 : 259206 : else if (MEM_P (x))
4170 : : {
4171 : : /* We don't have to worry about changing the address since the
4172 : : size in bytes is supposed to be the same. */
4173 : 57383 : if (reload_in_progress)
4174 : : {
4175 : : /* Copy the MEM to change the mode and move any
4176 : : substitutions from the old MEM to the new one. */
4177 : 0 : ret = adjust_address_nv (x, new_mode, 0);
4178 : 0 : copy_replacements (x, ret);
4179 : : }
4180 : : else
4181 : 57383 : ret = adjust_address (x, new_mode, 0);
4182 : : }
4183 : : else
4184 : : {
4185 : : /* Note that we do want simplify_subreg's behavior of validating
4186 : : that the new mode is ok for a hard register. If we were to use
4187 : : simplify_gen_subreg, we would create the subreg, but would
4188 : : probably run into the target not being able to implement it. */
4189 : : /* Except, of course, when FORCE is true, when this is exactly what
4190 : : we want. Which is needed for CCmodes on some targets. */
4191 : 201823 : if (force)
4192 : 201823 : ret = simplify_gen_subreg (new_mode, x, old_mode, 0);
4193 : : else
4194 : 0 : ret = simplify_subreg (new_mode, x, old_mode, 0);
4195 : : }
4196 : :
4197 : 260522 : return ret;
4198 : : }
4199 : :
4200 : : /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
4201 : : an integer mode of the same size as MODE. Returns the instruction
4202 : : emitted, or NULL if such a move could not be generated. */
4203 : :
4204 : : static rtx_insn *
4205 : 130261 : emit_move_via_integer (machine_mode mode, rtx x, rtx y, bool force)
4206 : : {
4207 : 130261 : scalar_int_mode imode;
4208 : 130261 : enum insn_code code;
4209 : :
4210 : : /* There must exist a mode of the exact size we require. */
4211 : 130261 : if (!int_mode_for_mode (mode).exists (&imode))
4212 : 0 : return NULL;
4213 : :
4214 : : /* The target must support moves in this mode. */
4215 : 130261 : code = optab_handler (mov_optab, imode);
4216 : 130261 : if (code == CODE_FOR_nothing)
4217 : : return NULL;
4218 : :
4219 : 130261 : x = emit_move_change_mode (imode, mode, x, force);
4220 : 130261 : if (x == NULL_RTX)
4221 : : return NULL;
4222 : 130261 : y = emit_move_change_mode (imode, mode, y, force);
4223 : 130261 : if (y == NULL_RTX)
4224 : : return NULL;
4225 : 130261 : return emit_insn (GEN_FCN (code) (x, y));
4226 : : }
4227 : :
4228 : : /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
4229 : : Return an equivalent MEM that does not use an auto-increment. */
4230 : :
4231 : : rtx
4232 : 3593 : emit_move_resolve_push (machine_mode mode, rtx x)
4233 : : {
4234 : 3593 : enum rtx_code code = GET_CODE (XEXP (x, 0));
4235 : 3593 : rtx temp;
4236 : :
4237 : 7186 : poly_int64 adjust = GET_MODE_SIZE (mode);
4238 : : #ifdef PUSH_ROUNDING
4239 : 3593 : adjust = PUSH_ROUNDING (adjust);
4240 : : #endif
4241 : 3593 : if (code == PRE_DEC || code == POST_DEC)
4242 : 3197 : adjust = -adjust;
4243 : 396 : else if (code == PRE_MODIFY || code == POST_MODIFY)
4244 : : {
4245 : 396 : rtx expr = XEXP (XEXP (x, 0), 1);
4246 : :
4247 : 396 : gcc_assert (GET_CODE (expr) == PLUS || GET_CODE (expr) == MINUS);
4248 : 396 : poly_int64 val = rtx_to_poly_int64 (XEXP (expr, 1));
4249 : 396 : if (GET_CODE (expr) == MINUS)
4250 : 0 : val = -val;
4251 : 396 : gcc_assert (known_eq (adjust, val) || known_eq (adjust, -val));
4252 : : adjust = val;
4253 : : }
4254 : :
4255 : : /* Do not use anti_adjust_stack, since we don't want to update
4256 : : stack_pointer_delta. */
4257 : 3593 : temp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
4258 : 3593 : gen_int_mode (adjust, Pmode), stack_pointer_rtx,
4259 : : 0, OPTAB_LIB_WIDEN);
4260 : 3593 : if (temp != stack_pointer_rtx)
4261 : 0 : emit_move_insn (stack_pointer_rtx, temp);
4262 : :
4263 : 3593 : switch (code)
4264 : : {
4265 : 3593 : case PRE_INC:
4266 : 3593 : case PRE_DEC:
4267 : 3593 : case PRE_MODIFY:
4268 : 3593 : temp = stack_pointer_rtx;
4269 : 3593 : break;
4270 : : case POST_INC:
4271 : : case POST_DEC:
4272 : : case POST_MODIFY:
4273 : 0 : temp = plus_constant (Pmode, stack_pointer_rtx, -adjust);
4274 : 0 : break;
4275 : 0 : default:
4276 : 0 : gcc_unreachable ();
4277 : : }
4278 : :
4279 : 3593 : return replace_equiv_address (x, temp);
4280 : : }
4281 : :
4282 : : /* A subroutine of emit_move_complex. Generate a move from Y into X.
4283 : : X is known to satisfy push_operand, and MODE is known to be complex.
4284 : : Returns the last instruction emitted. */
4285 : :
4286 : : rtx_insn *
4287 : 5244 : emit_move_complex_push (machine_mode mode, rtx x, rtx y)
4288 : : {
4289 : 5244 : scalar_mode submode = GET_MODE_INNER (mode);
4290 : 5244 : bool imag_first;
4291 : :
4292 : : #ifdef PUSH_ROUNDING
4293 : 10488 : poly_int64 submodesize = GET_MODE_SIZE (submode);
4294 : :
4295 : : /* In case we output to the stack, but the size is smaller than the
4296 : : machine can push exactly, we need to use move instructions. */
4297 : 5244 : if (maybe_ne (PUSH_ROUNDING (submodesize), submodesize))
4298 : : {
4299 : 718 : x = emit_move_resolve_push (mode, x);
4300 : 718 : return emit_move_insn (x, y);
4301 : : }
4302 : : #endif
4303 : :
4304 : : /* Note that the real part always precedes the imag part in memory
4305 : : regardless of machine's endianness. */
4306 : 4526 : switch (GET_CODE (XEXP (x, 0)))
4307 : : {
4308 : : case PRE_DEC:
4309 : : case POST_DEC:
4310 : : imag_first = true;
4311 : : break;
4312 : 0 : case PRE_INC:
4313 : 0 : case POST_INC:
4314 : 0 : imag_first = false;
4315 : 0 : break;
4316 : 0 : default:
4317 : 0 : gcc_unreachable ();
4318 : : }
4319 : :
4320 : 4526 : emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
4321 : : read_complex_part (y, imag_first));
4322 : 4526 : return emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
4323 : 9052 : read_complex_part (y, !imag_first));
4324 : : }
4325 : :
4326 : : /* A subroutine of emit_move_complex. Perform the move from Y to X
4327 : : via two moves of the parts. Returns the last instruction emitted. */
4328 : :
4329 : : rtx_insn *
4330 : 76681 : emit_move_complex_parts (rtx x, rtx y)
4331 : : {
4332 : : /* Show the output dies here. This is necessary for SUBREGs
4333 : : of pseudos since we cannot track their lifetimes correctly;
4334 : : hard regs shouldn't appear here except as return values. */
4335 : 76681 : if (!reload_completed && !reload_in_progress
4336 : 153362 : && REG_P (x) && !reg_overlap_mentioned_p (x, y))
4337 : 5563 : emit_clobber (x);
4338 : :
4339 : 76681 : write_complex_part (x, read_complex_part (y, false), false, true);
4340 : 76681 : write_complex_part (x, read_complex_part (y, true), true, false);
4341 : :
4342 : 76681 : return get_last_insn ();
4343 : : }
4344 : :
4345 : : /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
4346 : : MODE is known to be complex. Returns the last instruction emitted. */
4347 : :
4348 : : static rtx_insn *
4349 : 80926 : emit_move_complex (machine_mode mode, rtx x, rtx y)
4350 : : {
4351 : 80926 : bool try_int;
4352 : :
4353 : : /* Need to take special care for pushes, to maintain proper ordering
4354 : : of the data, and possibly extra padding. */
4355 : 80926 : if (push_operand (x, mode))
4356 : 4636 : return emit_move_complex_push (mode, x, y);
4357 : :
4358 : : /* See if we can coerce the target into moving both values at once, except
4359 : : for floating point where we favor moving as parts if this is easy. */
4360 : 76290 : if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
4361 : 68081 : && optab_handler (mov_optab, GET_MODE_INNER (mode)) != CODE_FOR_nothing
4362 : 68081 : && !(REG_P (x)
4363 : 1656 : && HARD_REGISTER_P (x)
4364 : 302 : && REG_NREGS (x) == 1)
4365 : 144371 : && !(REG_P (y)
4366 : 2712 : && HARD_REGISTER_P (y)
4367 : 1356 : && REG_NREGS (y) == 1))
4368 : : try_int = false;
4369 : : /* Not possible if the values are inherently not adjacent. */
4370 : 8209 : else if (GET_CODE (x) == CONCAT || GET_CODE (y) == CONCAT)
4371 : : try_int = false;
4372 : : /* Is possible if both are registers (or subregs of registers). */
4373 : 756 : else if (register_operand (x, mode) && register_operand (y, mode))
4374 : : try_int = true;
4375 : : /* If one of the operands is a memory, and alignment constraints
4376 : : are friendly enough, we may be able to do combined memory operations.
4377 : : We do not attempt this if Y is a constant because that combination is
4378 : : usually better with the by-parts thing below. */
4379 : 637 : else if ((MEM_P (x) ? !CONSTANT_P (y) : MEM_P (y))
4380 : : && (!STRICT_ALIGNMENT
4381 : : || get_mode_alignment (mode) == BIGGEST_ALIGNMENT))
4382 : : try_int = true;
4383 : : else
4384 : : try_int = false;
4385 : :
4386 : : if (try_int)
4387 : : {
4388 : 756 : rtx_insn *ret;
4389 : :
4390 : : /* For memory to memory moves, optimal behavior can be had with the
4391 : : existing block move logic. But use normal expansion if optimizing
4392 : : for size. */
4393 : 756 : if (MEM_P (x) && MEM_P (y))
4394 : : {
4395 : 724 : emit_block_move (x, y, gen_int_mode (GET_MODE_SIZE (mode), Pmode),
4396 : 359 : (optimize_insn_for_speed_p()
4397 : : ? BLOCK_OP_NO_LIBCALL : BLOCK_OP_NORMAL));
4398 : 359 : return get_last_insn ();
4399 : : }
4400 : :
4401 : 397 : ret = emit_move_via_integer (mode, x, y, true);
4402 : 397 : if (ret)
4403 : : return ret;
4404 : : }
4405 : :
4406 : 75534 : return emit_move_complex_parts (x, y);
4407 : : }
4408 : :
4409 : : /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
4410 : : MODE is known to be MODE_CC. Returns the last instruction emitted. */
4411 : :
4412 : : static rtx_insn *
4413 : 0 : emit_move_ccmode (machine_mode mode, rtx x, rtx y)
4414 : : {
4415 : 0 : rtx_insn *ret;
4416 : :
4417 : : /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
4418 : 0 : if (mode != CCmode)
4419 : : {
4420 : 0 : enum insn_code code = optab_handler (mov_optab, CCmode);
4421 : 0 : if (code != CODE_FOR_nothing)
4422 : : {
4423 : 0 : x = emit_move_change_mode (CCmode, mode, x, true);
4424 : 0 : y = emit_move_change_mode (CCmode, mode, y, true);
4425 : 0 : return emit_insn (GEN_FCN (code) (x, y));
4426 : : }
4427 : : }
4428 : :
4429 : : /* Otherwise, find the MODE_INT mode of the same width. */
4430 : 0 : ret = emit_move_via_integer (mode, x, y, false);
4431 : 0 : gcc_assert (ret != NULL);
4432 : : return ret;
4433 : : }
4434 : :
4435 : : /* Return true if word I of OP lies entirely in the
4436 : : undefined bits of a paradoxical subreg. */
4437 : :
4438 : : static bool
4439 : 0 : undefined_operand_subword_p (const_rtx op, int i)
4440 : : {
4441 : 0 : if (GET_CODE (op) != SUBREG)
4442 : : return false;
4443 : 0 : machine_mode innermostmode = GET_MODE (SUBREG_REG (op));
4444 : 0 : poly_int64 offset = i * UNITS_PER_WORD + subreg_memory_offset (op);
4445 : 0 : return (known_ge (offset, GET_MODE_SIZE (innermostmode))
4446 : 0 : || known_le (offset, -UNITS_PER_WORD));
4447 : : }
4448 : :
4449 : : /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
4450 : : MODE is any multi-word or full-word mode that lacks a move_insn
4451 : : pattern. Note that you will get better code if you define such
4452 : : patterns, even if they must turn into multiple assembler instructions. */
4453 : :
4454 : : static rtx_insn *
4455 : 0 : emit_move_multi_word (machine_mode mode, rtx x, rtx y)
4456 : : {
4457 : 0 : rtx_insn *last_insn = 0;
4458 : 0 : rtx_insn *seq;
4459 : 0 : rtx inner;
4460 : 0 : bool need_clobber;
4461 : 0 : int i, mode_size;
4462 : :
4463 : : /* This function can only handle cases where the number of words is
4464 : : known at compile time. */
4465 : 0 : mode_size = GET_MODE_SIZE (mode).to_constant ();
4466 : 0 : gcc_assert (mode_size >= UNITS_PER_WORD);
4467 : :
4468 : : /* If X is a push on the stack, do the push now and replace
4469 : : X with a reference to the stack pointer. */
4470 : 0 : if (push_operand (x, mode))
4471 : 0 : x = emit_move_resolve_push (mode, x);
4472 : :
4473 : : /* If we are in reload, see if either operand is a MEM whose address
4474 : : is scheduled for replacement. */
4475 : 0 : if (reload_in_progress && MEM_P (x)
4476 : 0 : && (inner = find_replacement (&XEXP (x, 0))) != XEXP (x, 0))
4477 : 0 : x = replace_equiv_address_nv (x, inner);
4478 : 0 : if (reload_in_progress && MEM_P (y)
4479 : 0 : && (inner = find_replacement (&XEXP (y, 0))) != XEXP (y, 0))
4480 : 0 : y = replace_equiv_address_nv (y, inner);
4481 : :
4482 : 0 : start_sequence ();
4483 : :
4484 : 0 : need_clobber = false;
4485 : 0 : for (i = 0; i < CEIL (mode_size, UNITS_PER_WORD); i++)
4486 : : {
4487 : : /* Do not generate code for a move if it would go entirely
4488 : : to the non-existing bits of a paradoxical subreg. */
4489 : 0 : if (undefined_operand_subword_p (x, i))
4490 : 0 : continue;
4491 : :
4492 : 0 : rtx xpart = operand_subword (x, i, 1, mode);
4493 : 0 : rtx ypart;
4494 : :
4495 : : /* Do not generate code for a move if it would come entirely
4496 : : from the undefined bits of a paradoxical subreg. */
4497 : 0 : if (undefined_operand_subword_p (y, i))
4498 : 0 : continue;
4499 : :
4500 : 0 : ypart = operand_subword (y, i, 1, mode);
4501 : :
4502 : : /* If we can't get a part of Y, put Y into memory if it is a
4503 : : constant. Otherwise, force it into a register. Then we must
4504 : : be able to get a part of Y. */
4505 : 0 : if (ypart == 0 && CONSTANT_P (y))
4506 : : {
4507 : 0 : y = use_anchored_address (force_const_mem (mode, y));
4508 : 0 : ypart = operand_subword (y, i, 1, mode);
4509 : : }
4510 : 0 : else if (ypart == 0)
4511 : 0 : ypart = operand_subword_force (y, i, mode);
4512 : :
4513 : 0 : gcc_assert (xpart && ypart);
4514 : :
4515 : 0 : need_clobber |= (GET_CODE (xpart) == SUBREG);
4516 : :
4517 : 0 : last_insn = emit_move_insn (xpart, ypart);
4518 : : }
4519 : :
4520 : 0 : seq = get_insns ();
4521 : 0 : end_sequence ();
4522 : :
4523 : : /* Show the output dies here. This is necessary for SUBREGs
4524 : : of pseudos since we cannot track their lifetimes correctly;
4525 : : hard regs shouldn't appear here except as return values.
4526 : : We never want to emit such a clobber after reload. */
4527 : 0 : if (x != y
4528 : 0 : && ! (reload_in_progress || reload_completed)
4529 : 0 : && need_clobber != 0)
4530 : 0 : emit_clobber (x);
4531 : :
4532 : 0 : emit_insn (seq);
4533 : :
4534 : 0 : return last_insn;
4535 : : }
4536 : :
4537 : : /* Low level part of emit_move_insn.
4538 : : Called just like emit_move_insn, but assumes X and Y
4539 : : are basically valid. */
4540 : :
4541 : : rtx_insn *
4542 : 71550462 : emit_move_insn_1 (rtx x, rtx y)
4543 : : {
4544 : 71550462 : machine_mode mode = GET_MODE (x);
4545 : 71550462 : enum insn_code code;
4546 : :
4547 : 71550462 : gcc_assert ((unsigned int) mode < (unsigned int) MAX_MACHINE_MODE);
4548 : :
4549 : 71550462 : code = optab_handler (mov_optab, mode);
4550 : 71550462 : if (code != CODE_FOR_nothing)
4551 : 71339672 : return emit_insn (GEN_FCN (code) (x, y));
4552 : :
4553 : : /* Expand complex moves by moving real part and imag part. */
4554 : 210790 : if (COMPLEX_MODE_P (mode))
4555 : 80926 : return emit_move_complex (mode, x, y);
4556 : :
4557 : : if (GET_MODE_CLASS (mode) == MODE_DECIMAL_FLOAT
4558 : : || ALL_FIXED_POINT_MODE_P (mode))
4559 : : {
4560 : 129864 : rtx_insn *result = emit_move_via_integer (mode, x, y, true);
4561 : :
4562 : : /* If we can't find an integer mode, use multi words. */
4563 : 129864 : if (result)
4564 : : return result;
4565 : : else
4566 : 0 : return emit_move_multi_word (mode, x, y);
4567 : : }
4568 : :
4569 : : if (GET_MODE_CLASS (mode) == MODE_CC)
4570 : 0 : return emit_move_ccmode (mode, x, y);
4571 : :
4572 : : /* Try using a move pattern for the corresponding integer mode. This is
4573 : : only safe when simplify_subreg can convert MODE constants into integer
4574 : : constants. At present, it can only do this reliably if the value
4575 : : fits within a HOST_WIDE_INT. */
4576 : 0 : if (!CONSTANT_P (y)
4577 : 0 : || known_le (GET_MODE_BITSIZE (mode), HOST_BITS_PER_WIDE_INT))
4578 : : {
4579 : 0 : rtx_insn *ret = emit_move_via_integer (mode, x, y, lra_in_progress);
4580 : :
4581 : 0 : if (ret)
4582 : : {
4583 : 0 : if (! lra_in_progress || recog (PATTERN (ret), ret, 0) >= 0)
4584 : 0 : return ret;
4585 : : }
4586 : : }
4587 : :
4588 : 0 : return emit_move_multi_word (mode, x, y);
4589 : : }
4590 : :
4591 : : /* Generate code to copy Y into X.
4592 : : Both Y and X must have the same mode, except that
4593 : : Y can be a constant with VOIDmode.
4594 : : This mode cannot be BLKmode; use emit_block_move for that.
4595 : :
4596 : : Return the last instruction emitted. */
4597 : :
4598 : : rtx_insn *
4599 : 65299370 : emit_move_insn (rtx x, rtx y)
4600 : : {
4601 : 65299370 : machine_mode mode = GET_MODE (x);
4602 : 65299370 : rtx y_cst = NULL_RTX;
4603 : 65299370 : rtx_insn *last_insn;
4604 : 65299370 : rtx set;
4605 : :
4606 : 65299370 : gcc_assert (mode != BLKmode
4607 : : && (GET_MODE (y) == mode || GET_MODE (y) == VOIDmode));
4608 : :
4609 : : /* If we have a copy that looks like one of the following patterns:
4610 : : (set (subreg:M1 (reg:M2 ...)) (subreg:M1 (reg:M2 ...)))
4611 : : (set (subreg:M1 (reg:M2 ...)) (mem:M1 ADDR))
4612 : : (set (mem:M1 ADDR) (subreg:M1 (reg:M2 ...)))
4613 : : (set (subreg:M1 (reg:M2 ...)) (constant C))
4614 : : where mode M1 is equal in size to M2, try to detect whether the
4615 : : mode change involves an implicit round trip through memory.
4616 : : If so, see if we can avoid that by removing the subregs and
4617 : : doing the move in mode M2 instead. */
4618 : :
4619 : 65299370 : rtx x_inner = NULL_RTX;
4620 : 65299370 : rtx y_inner = NULL_RTX;
4621 : :
4622 : 68025666 : auto candidate_subreg_p = [&](rtx subreg) {
4623 : 2726296 : return (REG_P (SUBREG_REG (subreg))
4624 : 8176791 : && known_eq (GET_MODE_SIZE (GET_MODE (SUBREG_REG (subreg))),
4625 : : GET_MODE_SIZE (GET_MODE (subreg)))
4626 : 3037489 : && optab_handler (mov_optab, GET_MODE (SUBREG_REG (subreg)))
4627 : 2726296 : != CODE_FOR_nothing);
4628 : : };
4629 : :
4630 : 65307767 : auto candidate_mem_p = [&](machine_mode innermode, rtx mem) {
4631 : 8397 : return (!targetm.can_change_mode_class (innermode, GET_MODE (mem), ALL_REGS)
4632 : 8397 : && !push_operand (mem, GET_MODE (mem))
4633 : : /* Not a candiate if innermode requires too much alignment. */
4634 : 16740 : && (MEM_ALIGN (mem) >= GET_MODE_ALIGNMENT (innermode)
4635 : 264 : || targetm.slow_unaligned_access (GET_MODE (mem),
4636 : 132 : MEM_ALIGN (mem))
4637 : 264 : || !targetm.slow_unaligned_access (innermode,
4638 : 132 : MEM_ALIGN (mem))));
4639 : : };
4640 : :
4641 : 65299370 : if (SUBREG_P (x) && candidate_subreg_p (x))
4642 : 8800 : x_inner = SUBREG_REG (x);
4643 : :
4644 : 65299370 : if (SUBREG_P (y) && candidate_subreg_p (y))
4645 : 301319 : y_inner = SUBREG_REG (y);
4646 : :
4647 : 65299370 : if (x_inner != NULL_RTX
4648 : 65299370 : && y_inner != NULL_RTX
4649 : 1112 : && GET_MODE (x_inner) == GET_MODE (y_inner)
4650 : 65300056 : && !targetm.can_change_mode_class (GET_MODE (x_inner), mode, ALL_REGS))
4651 : : {
4652 : 686 : x = x_inner;
4653 : 686 : y = y_inner;
4654 : 686 : mode = GET_MODE (x_inner);
4655 : : }
4656 : 65298684 : else if (x_inner != NULL_RTX
4657 : 8114 : && MEM_P (y)
4658 : 65299043 : && candidate_mem_p (GET_MODE (x_inner), y))
4659 : : {
4660 : 359 : x = x_inner;
4661 : 359 : y = adjust_address (y, GET_MODE (x_inner), 0);
4662 : 359 : mode = GET_MODE (x_inner);
4663 : : }
4664 : 65298325 : else if (y_inner != NULL_RTX
4665 : 300633 : && MEM_P (x)
4666 : 65306363 : && candidate_mem_p (GET_MODE (y_inner), x))
4667 : : {
4668 : 7984 : x = adjust_address (x, GET_MODE (y_inner), 0);
4669 : 7984 : y = y_inner;
4670 : 7984 : mode = GET_MODE (y_inner);
4671 : : }
4672 : 65290341 : else if (x_inner != NULL_RTX
4673 : 7755 : && CONSTANT_P (y)
4674 : 442 : && !targetm.can_change_mode_class (GET_MODE (x_inner),
4675 : : mode, ALL_REGS)
4676 : 65290783 : && (y_inner = simplify_subreg (GET_MODE (x_inner), y, mode, 0)))
4677 : : {
4678 : 442 : x = x_inner;
4679 : 442 : y = y_inner;
4680 : 442 : mode = GET_MODE (x_inner);
4681 : : }
4682 : :
4683 : 65299370 : if (CONSTANT_P (y))
4684 : : {
4685 : 15274772 : if (optimize
4686 : 11854204 : && SCALAR_FLOAT_MODE_P (GET_MODE (x))
4687 : 16027872 : && (last_insn = compress_float_constant (x, y)))
4688 : : return last_insn;
4689 : :
4690 : 15206102 : y_cst = y;
4691 : :
4692 : 15206102 : if (!targetm.legitimate_constant_p (mode, y))
4693 : : {
4694 : 454229 : y = force_const_mem (mode, y);
4695 : :
4696 : : /* If the target's cannot_force_const_mem prevented the spill,
4697 : : assume that the target's move expanders will also take care
4698 : : of the non-legitimate constant. */
4699 : 454229 : if (!y)
4700 : : y = y_cst;
4701 : : else
4702 : 434699 : y = use_anchored_address (y);
4703 : : }
4704 : : }
4705 : :
4706 : : /* If X or Y are memory references, verify that their addresses are valid
4707 : : for the machine. */
4708 : 65230700 : if (MEM_P (x)
4709 : 80155980 : && (! memory_address_addr_space_p (GET_MODE (x), XEXP (x, 0),
4710 : 12712470 : MEM_ADDR_SPACE (x))
4711 : 2212978 : && ! push_operand (x, GET_MODE (x))))
4712 : 168 : x = validize_mem (x);
4713 : :
4714 : 65230700 : if (MEM_P (y)
4715 : 81738918 : && ! memory_address_addr_space_p (GET_MODE (y), XEXP (y, 0),
4716 : 16508218 : MEM_ADDR_SPACE (y)))
4717 : 9253 : y = validize_mem (y);
4718 : :
4719 : 65230700 : gcc_assert (mode != BLKmode);
4720 : :
4721 : 65230700 : last_insn = emit_move_insn_1 (x, y);
4722 : :
4723 : 15206102 : if (y_cst && REG_P (x)
4724 : 11301542 : && (set = single_set (last_insn)) != NULL_RTX
4725 : 11301542 : && SET_DEST (set) == x
4726 : 76516934 : && ! rtx_equal_p (y_cst, SET_SRC (set)))
4727 : 1263627 : set_unique_reg_note (last_insn, REG_EQUAL, copy_rtx (y_cst));
4728 : :
4729 : : return last_insn;
4730 : : }
4731 : :
4732 : : /* Generate the body of an instruction to copy Y into X.
4733 : : It may be a list of insns, if one insn isn't enough. */
4734 : :
4735 : : rtx_insn *
4736 : 6319682 : gen_move_insn (rtx x, rtx y)
4737 : : {
4738 : 6319682 : rtx_insn *seq;
4739 : :
4740 : 6319682 : start_sequence ();
4741 : 6319682 : emit_move_insn_1 (x, y);
4742 : 6319682 : seq = get_insns ();
4743 : 6319682 : end_sequence ();
4744 : 6319682 : return seq;
4745 : : }
4746 : :
4747 : : /* If Y is representable exactly in a narrower mode, and the target can
4748 : : perform the extension directly from constant or memory, then emit the
4749 : : move as an extension. */
4750 : :
4751 : : static rtx_insn *
4752 : 753100 : compress_float_constant (rtx x, rtx y)
4753 : : {
4754 : 753100 : machine_mode dstmode = GET_MODE (x);
4755 : 753100 : machine_mode orig_srcmode = GET_MODE (y);
4756 : 753100 : machine_mode srcmode;
4757 : 753100 : const REAL_VALUE_TYPE *r;
4758 : 753100 : int oldcost, newcost;
4759 : 753100 : bool speed = optimize_insn_for_speed_p ();
4760 : :
4761 : 753100 : r = CONST_DOUBLE_REAL_VALUE (y);
4762 : :
4763 : 753100 : if (targetm.legitimate_constant_p (dstmode, y))
4764 : 751771 : oldcost = set_src_cost (y, orig_srcmode, speed);
4765 : : else
4766 : 1329 : oldcost = set_src_cost (force_const_mem (dstmode, y), dstmode, speed);
4767 : :
4768 : 2658790 : FOR_EACH_MODE_UNTIL (srcmode, orig_srcmode)
4769 : : {
4770 : 1974360 : enum insn_code ic;
4771 : 1974360 : rtx trunc_y;
4772 : 1974360 : rtx_insn *last_insn;
4773 : :
4774 : : /* Skip if the target can't extend this way. */
4775 : 1974360 : ic = can_extend_p (dstmode, srcmode, 0);
4776 : 1974360 : if (ic == CODE_FOR_nothing)
4777 : 1571181 : continue;
4778 : :
4779 : : /* Skip if the narrowed value isn't exact. */
4780 : 403179 : if (! exact_real_truncate (srcmode, r))
4781 : 50051 : continue;
4782 : :
4783 : 353128 : trunc_y = const_double_from_real_value (*r, srcmode);
4784 : :
4785 : 353128 : if (targetm.legitimate_constant_p (srcmode, trunc_y))
4786 : : {
4787 : : /* Skip if the target needs extra instructions to perform
4788 : : the extension. */
4789 : 349469 : if (!insn_operand_matches (ic, 1, trunc_y))
4790 : 3335 : continue;
4791 : : /* This is valid, but may not be cheaper than the original. */
4792 : 346134 : newcost = set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y),
4793 : : dstmode, speed);
4794 : 346134 : if (oldcost < newcost)
4795 : 277464 : continue;
4796 : : }
4797 : 3659 : else if (float_extend_from_mem[dstmode][srcmode])
4798 : : {
4799 : 0 : trunc_y = force_const_mem (srcmode, trunc_y);
4800 : : /* This is valid, but may not be cheaper than the original. */
4801 : 0 : newcost = set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y),
4802 : : dstmode, speed);
4803 : 0 : if (oldcost < newcost)
4804 : 0 : continue;
4805 : 0 : trunc_y = validize_mem (trunc_y);
4806 : : }
4807 : : else
4808 : 3659 : continue;
4809 : :
4810 : : /* For CSE's benefit, force the compressed constant pool entry
4811 : : into a new pseudo. This constant may be used in different modes,
4812 : : and if not, combine will put things back together for us. */
4813 : 68670 : trunc_y = force_reg (srcmode, trunc_y);
4814 : :
4815 : : /* If x is a hard register, perform the extension into a pseudo,
4816 : : so that e.g. stack realignment code is aware of it. */
4817 : 68670 : rtx target = x;
4818 : 68670 : if (REG_P (x) && HARD_REGISTER_P (x))
4819 : 1 : target = gen_reg_rtx (dstmode);
4820 : :
4821 : 68670 : emit_unop_insn (ic, target, trunc_y, UNKNOWN);
4822 : 68670 : last_insn = get_last_insn ();
4823 : :
4824 : 68670 : if (REG_P (target))
4825 : 58049 : set_unique_reg_note (last_insn, REG_EQUAL, y);
4826 : :
4827 : 68670 : if (target != x)
4828 : 1 : return emit_move_insn (x, target);
4829 : : return last_insn;
4830 : : }
4831 : :
4832 : : return NULL;
4833 : : }
4834 : :
4835 : : /* Pushing data onto the stack. */
4836 : :
4837 : : /* Push a block of length SIZE (perhaps variable)
4838 : : and return an rtx to address the beginning of the block.
4839 : : The value may be virtual_outgoing_args_rtx.
4840 : :
4841 : : EXTRA is the number of bytes of padding to push in addition to SIZE.
4842 : : BELOW nonzero means this padding comes at low addresses;
4843 : : otherwise, the padding comes at high addresses. */
4844 : :
4845 : : rtx
4846 : 266113 : push_block (rtx size, poly_int64 extra, int below)
4847 : : {
4848 : 266113 : rtx temp;
4849 : :
4850 : 266113 : size = convert_modes (Pmode, ptr_mode, size, 1);
4851 : 266113 : if (CONSTANT_P (size))
4852 : 266113 : anti_adjust_stack (plus_constant (Pmode, size, extra));
4853 : 0 : else if (REG_P (size) && known_eq (extra, 0))
4854 : 0 : anti_adjust_stack (size);
4855 : : else
4856 : : {
4857 : 0 : temp = copy_to_mode_reg (Pmode, size);
4858 : 0 : if (maybe_ne (extra, 0))
4859 : 0 : temp = expand_binop (Pmode, add_optab, temp,
4860 : 0 : gen_int_mode (extra, Pmode),
4861 : : temp, 0, OPTAB_LIB_WIDEN);
4862 : 0 : anti_adjust_stack (temp);
4863 : : }
4864 : :
4865 : 266113 : if (STACK_GROWS_DOWNWARD)
4866 : : {
4867 : 266113 : temp = virtual_outgoing_args_rtx;
4868 : 266113 : if (maybe_ne (extra, 0) && below)
4869 : 0 : temp = plus_constant (Pmode, temp, extra);
4870 : : }
4871 : : else
4872 : : {
4873 : : poly_int64 csize;
4874 : : if (poly_int_rtx_p (size, &csize))
4875 : : temp = plus_constant (Pmode, virtual_outgoing_args_rtx,
4876 : : -csize - (below ? 0 : extra));
4877 : : else if (maybe_ne (extra, 0) && !below)
4878 : : temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
4879 : : negate_rtx (Pmode, plus_constant (Pmode, size,
4880 : : extra)));
4881 : : else
4882 : : temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
4883 : : negate_rtx (Pmode, size));
4884 : : }
4885 : :
4886 : 266113 : return memory_address (NARROWEST_INT_MODE, temp);
4887 : : }
4888 : :
4889 : : /* A utility routine that returns the base of an auto-inc memory, or NULL. */
4890 : :
4891 : : static rtx
4892 : 2548826 : mem_autoinc_base (rtx mem)
4893 : : {
4894 : 0 : if (MEM_P (mem))
4895 : : {
4896 : 1572302 : rtx addr = XEXP (mem, 0);
4897 : 1572302 : if (GET_RTX_CLASS (GET_CODE (addr)) == RTX_AUTOINC)
4898 : 1018501 : return XEXP (addr, 0);
4899 : : }
4900 : : return NULL;
4901 : : }
4902 : :
4903 : : /* A utility routine used here, in reload, and in try_split. The insns
4904 : : after PREV up to and including LAST are known to adjust the stack,
4905 : : with a final value of END_ARGS_SIZE. Iterate backward from LAST
4906 : : placing notes as appropriate. PREV may be NULL, indicating the
4907 : : entire insn sequence prior to LAST should be scanned.
4908 : :
4909 : : The set of allowed stack pointer modifications is small:
4910 : : (1) One or more auto-inc style memory references (aka pushes),
4911 : : (2) One or more addition/subtraction with the SP as destination,
4912 : : (3) A single move insn with the SP as destination,
4913 : : (4) A call_pop insn,
4914 : : (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
4915 : :
4916 : : Insns in the sequence that do not modify the SP are ignored,
4917 : : except for noreturn calls.
4918 : :
4919 : : The return value is the amount of adjustment that can be trivially
4920 : : verified, via immediate operand or auto-inc. If the adjustment
4921 : : cannot be trivially extracted, the return value is HOST_WIDE_INT_MIN. */
4922 : :
4923 : : poly_int64
4924 : 4232579 : find_args_size_adjust (rtx_insn *insn)
4925 : : {
4926 : 4232579 : rtx dest, set, pat;
4927 : 4232579 : int i;
4928 : :
4929 : 4232579 : pat = PATTERN (insn);
4930 : 4232579 : set = NULL;
4931 : :
4932 : : /* Look for a call_pop pattern. */
4933 : 4232579 : if (CALL_P (insn))
4934 : : {
4935 : : /* We have to allow non-call_pop patterns for the case
4936 : : of emit_single_push_insn of a TLS address. */
4937 : 2619968 : if (GET_CODE (pat) != PARALLEL)
4938 : 2607461 : return 0;
4939 : :
4940 : : /* All call_pop have a stack pointer adjust in the parallel.
4941 : : The call itself is always first, and the stack adjust is
4942 : : usually last, so search from the end. */
4943 : 12507 : for (i = XVECLEN (pat, 0) - 1; i > 0; --i)
4944 : : {
4945 : 12507 : set = XVECEXP (pat, 0, i);
4946 : 12507 : if (GET_CODE (set) != SET)
4947 : 0 : continue;
4948 : 12507 : dest = SET_DEST (set);
4949 : 12507 : if (dest == stack_pointer_rtx)
4950 : : break;
4951 : : }
4952 : : /* We'd better have found the stack pointer adjust. */
4953 : 12507 : if (i == 0)
4954 : 0 : return 0;
4955 : : /* Fall through to process the extracted SET and DEST
4956 : : as if it was a standalone insn. */
4957 : : }
4958 : 1612611 : else if (GET_CODE (pat) == SET)
4959 : : set = pat;
4960 : 234355 : else if ((set = single_set (insn)) != NULL)
4961 : : ;
4962 : 47647 : else if (GET_CODE (pat) == PARALLEL)
4963 : : {
4964 : : /* ??? Some older ports use a parallel with a stack adjust
4965 : : and a store for a PUSH_ROUNDING pattern, rather than a
4966 : : PRE/POST_MODIFY rtx. Don't force them to update yet... */
4967 : : /* ??? See h8300 and m68k, pushqi1. */
4968 : 0 : for (i = XVECLEN (pat, 0) - 1; i >= 0; --i)
4969 : : {
4970 : 0 : set = XVECEXP (pat, 0, i);
4971 : 0 : if (GET_CODE (set) != SET)
4972 : 0 : continue;
4973 : 0 : dest = SET_DEST (set);
4974 : 0 : if (dest == stack_pointer_rtx)
4975 : : break;
4976 : :
4977 : : /* We do not expect an auto-inc of the sp in the parallel. */
4978 : 0 : gcc_checking_assert (mem_autoinc_base (dest) != stack_pointer_rtx);
4979 : 0 : gcc_checking_assert (mem_autoinc_base (SET_SRC (set))
4980 : : != stack_pointer_rtx);
4981 : : }
4982 : 0 : if (i < 0)
4983 : 0 : return 0;
4984 : : }
4985 : : else
4986 : 47647 : return 0;
4987 : :
4988 : 1577471 : dest = SET_DEST (set);
4989 : :
4990 : : /* Look for direct modifications of the stack pointer. */
4991 : 1577471 : if (REG_P (dest) && REGNO (dest) == STACK_POINTER_REGNUM)
4992 : : {
4993 : : /* Look for a trivial adjustment, otherwise assume nothing. */
4994 : : /* Note that the SPU restore_stack_block pattern refers to
4995 : : the stack pointer in V4SImode. Consider that non-trivial. */
4996 : 303058 : poly_int64 offset;
4997 : 303058 : if (SCALAR_INT_MODE_P (GET_MODE (dest))
4998 : 303058 : && strip_offset (SET_SRC (set), &offset) == stack_pointer_rtx)
4999 : 300659 : return offset;
5000 : : /* ??? Reload can generate no-op moves, which will be cleaned
5001 : : up later. Recognize it and continue searching. */
5002 : 2399 : else if (rtx_equal_p (dest, SET_SRC (set)))
5003 : 0 : return 0;
5004 : : else
5005 : 2399 : return HOST_WIDE_INT_MIN;
5006 : : }
5007 : : else
5008 : : {
5009 : 1274413 : rtx mem, addr;
5010 : :
5011 : : /* Otherwise only think about autoinc patterns. */
5012 : 2310038 : if (mem_autoinc_base (dest) == stack_pointer_rtx)
5013 : : {
5014 : 911950 : mem = dest;
5015 : 1277466 : gcc_checking_assert (mem_autoinc_base (SET_SRC (set))
5016 : : != stack_pointer_rtx);
5017 : : }
5018 : 533624 : else if (mem_autoinc_base (SET_SRC (set)) == stack_pointer_rtx)
5019 : : mem = SET_SRC (set);
5020 : : else
5021 : 255912 : return 0;
5022 : :
5023 : 1018501 : addr = XEXP (mem, 0);
5024 : 1018501 : switch (GET_CODE (addr))
5025 : : {
5026 : 106551 : case PRE_INC:
5027 : 106551 : case POST_INC:
5028 : 213102 : return GET_MODE_SIZE (GET_MODE (mem));
5029 : 895905 : case PRE_DEC:
5030 : 895905 : case POST_DEC:
5031 : 1791810 : return -GET_MODE_SIZE (GET_MODE (mem));
5032 : 16045 : case PRE_MODIFY:
5033 : 16045 : case POST_MODIFY:
5034 : 16045 : addr = XEXP (addr, 1);
5035 : 16045 : gcc_assert (GET_CODE (addr) == PLUS);
5036 : 16045 : gcc_assert (XEXP (addr, 0) == stack_pointer_rtx);
5037 : 16045 : return rtx_to_poly_int64 (XEXP (addr, 1));
5038 : 0 : default:
5039 : 0 : gcc_unreachable ();
5040 : : }
5041 : : }
5042 : : }
5043 : :
5044 : : poly_int64
5045 : 655627 : fixup_args_size_notes (rtx_insn *prev, rtx_insn *last,
5046 : : poly_int64 end_args_size)
5047 : : {
5048 : 655627 : poly_int64 args_size = end_args_size;
5049 : 655627 : bool saw_unknown = false;
5050 : 655627 : rtx_insn *insn;
5051 : :
5052 : 1876727 : for (insn = last; insn != prev; insn = PREV_INSN (insn))
5053 : : {
5054 : 1221100 : if (!NONDEBUG_INSN_P (insn))
5055 : 0 : continue;
5056 : :
5057 : : /* We might have existing REG_ARGS_SIZE notes, e.g. when pushing
5058 : : a call argument containing a TLS address that itself requires
5059 : : a call to __tls_get_addr. The handling of stack_pointer_delta
5060 : : in emit_single_push_insn is supposed to ensure that any such
5061 : : notes are already correct. */
5062 : 1221100 : rtx note = find_reg_note (insn, REG_ARGS_SIZE, NULL_RTX);
5063 : 1221100 : gcc_assert (!note || known_eq (args_size, get_args_size (note)));
5064 : :
5065 : 1221100 : poly_int64 this_delta = find_args_size_adjust (insn);
5066 : 1221100 : if (known_eq (this_delta, 0))
5067 : : {
5068 : 602955 : if (!CALL_P (insn)
5069 : 5 : || ACCUMULATE_OUTGOING_ARGS
5070 : 301485 : || find_reg_note (insn, REG_NORETURN, NULL_RTX) == NULL_RTX)
5071 : 301475 : continue;
5072 : : }
5073 : :
5074 : 919625 : gcc_assert (!saw_unknown);
5075 : 919625 : if (known_eq (this_delta, HOST_WIDE_INT_MIN))
5076 : 2342 : saw_unknown = true;
5077 : :
5078 : 919625 : if (!note)
5079 : 919625 : add_args_size_note (insn, args_size);
5080 : : if (STACK_GROWS_DOWNWARD)
5081 : 919625 : this_delta = -poly_uint64 (this_delta);
5082 : :
5083 : 919625 : if (saw_unknown)
5084 : : args_size = HOST_WIDE_INT_MIN;
5085 : : else
5086 : 1221100 : args_size -= this_delta;
5087 : : }
5088 : :
5089 : 655627 : return args_size;
5090 : : }
5091 : :
5092 : : #ifdef PUSH_ROUNDING
5093 : : /* Emit single push insn. */
5094 : :
5095 : : static void
5096 : 1800492 : emit_single_push_insn_1 (machine_mode mode, rtx x, tree type)
5097 : : {
5098 : 1800492 : rtx dest_addr;
5099 : 3600984 : poly_int64 rounded_size = PUSH_ROUNDING (GET_MODE_SIZE (mode));
5100 : 1800492 : rtx dest;
5101 : 1800492 : enum insn_code icode;
5102 : :
5103 : : /* If there is push pattern, use it. Otherwise try old way of throwing
5104 : : MEM representing push operation to move expander. */
5105 : 1800492 : icode = optab_handler (push_optab, mode);
5106 : 1800492 : if (icode != CODE_FOR_nothing)
5107 : : {
5108 : 0 : class expand_operand ops[1];
5109 : :
5110 : 0 : create_input_operand (&ops[0], x, mode);
5111 : 0 : if (maybe_expand_insn (icode, 1, ops))
5112 : 0 : return;
5113 : : }
5114 : 3600984 : if (known_eq (GET_MODE_SIZE (mode), rounded_size))
5115 : 1689619 : dest_addr = gen_rtx_fmt_e (STACK_PUSH_CODE, Pmode, stack_pointer_rtx);
5116 : : /* If we are to pad downward, adjust the stack pointer first and
5117 : : then store X into the stack location using an offset. This is
5118 : : because emit_move_insn does not know how to pad; it does not have
5119 : : access to type. */
5120 : 110873 : else if (targetm.calls.function_arg_padding (mode, type) == PAD_DOWNWARD)
5121 : : {
5122 : 0 : emit_move_insn (stack_pointer_rtx,
5123 : 0 : expand_binop (Pmode,
5124 : : STACK_GROWS_DOWNWARD ? sub_optab
5125 : : : add_optab,
5126 : : stack_pointer_rtx,
5127 : 0 : gen_int_mode (rounded_size, Pmode),
5128 : : NULL_RTX, 0, OPTAB_LIB_WIDEN));
5129 : :
5130 : 0 : poly_int64 offset = rounded_size - GET_MODE_SIZE (mode);
5131 : 0 : if (STACK_GROWS_DOWNWARD && STACK_PUSH_CODE == POST_DEC)
5132 : : /* We have already decremented the stack pointer, so get the
5133 : : previous value. */
5134 : : offset += rounded_size;
5135 : :
5136 : 0 : if (!STACK_GROWS_DOWNWARD && STACK_PUSH_CODE == POST_INC)
5137 : : /* We have already incremented the stack pointer, so get the
5138 : : previous value. */
5139 : : offset -= rounded_size;
5140 : :
5141 : 0 : dest_addr = plus_constant (Pmode, stack_pointer_rtx, offset);
5142 : : }
5143 : : else
5144 : : {
5145 : 110873 : if (STACK_GROWS_DOWNWARD)
5146 : : /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
5147 : 110873 : dest_addr = plus_constant (Pmode, stack_pointer_rtx, -rounded_size);
5148 : : else
5149 : : /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
5150 : : dest_addr = plus_constant (Pmode, stack_pointer_rtx, rounded_size);
5151 : :
5152 : 110873 : dest_addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, dest_addr);
5153 : : }
5154 : :
5155 : 1800492 : dest = gen_rtx_MEM (mode, dest_addr);
5156 : :
5157 : 1800492 : if (type != 0)
5158 : : {
5159 : 1800444 : set_mem_attributes (dest, type, 1);
5160 : :
5161 : 1800444 : if (cfun->tail_call_marked)
5162 : : /* Function incoming arguments may overlap with sibling call
5163 : : outgoing arguments and we cannot allow reordering of reads
5164 : : from function arguments with stores to outgoing arguments
5165 : : of sibling calls. */
5166 : 135086 : set_mem_alias_set (dest, 0);
5167 : : }
5168 : 1800492 : emit_move_insn (dest, x);
5169 : : }
5170 : :
5171 : : /* Emit and annotate a single push insn. */
5172 : :
5173 : : static void
5174 : 1800492 : emit_single_push_insn (machine_mode mode, rtx x, tree type)
5175 : : {
5176 : 1800492 : poly_int64 delta, old_delta = stack_pointer_delta;
5177 : 1800492 : rtx_insn *prev = get_last_insn ();
5178 : 1800492 : rtx_insn *last;
5179 : :
5180 : 1800492 : emit_single_push_insn_1 (mode, x, type);
5181 : :
5182 : : /* Adjust stack_pointer_delta to describe the situation after the push
5183 : : we just performed. Note that we must do this after the push rather
5184 : : than before the push in case calculating X needs pushes and pops of
5185 : : its own (e.g. if calling __tls_get_addr). The REG_ARGS_SIZE notes
5186 : : for such pushes and pops must not include the effect of the future
5187 : : push of X. */
5188 : 3600984 : stack_pointer_delta += PUSH_ROUNDING (GET_MODE_SIZE (mode));
5189 : :
5190 : 1800492 : last = get_last_insn ();
5191 : :
5192 : : /* Notice the common case where we emitted exactly one insn. */
5193 : 1800492 : if (PREV_INSN (last) == prev)
5194 : : {
5195 : 1694412 : add_args_size_note (last, stack_pointer_delta);
5196 : 1694412 : return;
5197 : : }
5198 : :
5199 : 106080 : delta = fixup_args_size_notes (prev, last, stack_pointer_delta);
5200 : 106080 : gcc_assert (known_eq (delta, HOST_WIDE_INT_MIN)
5201 : : || known_eq (delta, old_delta));
5202 : : }
5203 : : #endif
5204 : :
5205 : : /* If reading SIZE bytes from X will end up reading from
5206 : : Y return the number of bytes that overlap. Return -1
5207 : : if there is no overlap or -2 if we can't determine
5208 : : (for example when X and Y have different base registers). */
5209 : :
5210 : : static int
5211 : 0 : memory_load_overlap (rtx x, rtx y, HOST_WIDE_INT size)
5212 : : {
5213 : 0 : rtx tmp = plus_constant (Pmode, x, size);
5214 : 0 : rtx sub = simplify_gen_binary (MINUS, Pmode, tmp, y);
5215 : :
5216 : 0 : if (!CONST_INT_P (sub))
5217 : : return -2;
5218 : :
5219 : 0 : HOST_WIDE_INT val = INTVAL (sub);
5220 : :
5221 : 0 : return IN_RANGE (val, 1, size) ? val : -1;
5222 : : }
5223 : :
5224 : : /* Generate code to push X onto the stack, assuming it has mode MODE and
5225 : : type TYPE.
5226 : : MODE is redundant except when X is a CONST_INT (since they don't
5227 : : carry mode info).
5228 : : SIZE is an rtx for the size of data to be copied (in bytes),
5229 : : needed only if X is BLKmode.
5230 : : Return true if successful. May return false if asked to push a
5231 : : partial argument during a sibcall optimization (as specified by
5232 : : SIBCALL_P) and the incoming and outgoing pointers cannot be shown
5233 : : to not overlap.
5234 : :
5235 : : ALIGN (in bits) is maximum alignment we can assume.
5236 : :
5237 : : If PARTIAL and REG are both nonzero, then copy that many of the first
5238 : : bytes of X into registers starting with REG, and push the rest of X.
5239 : : The amount of space pushed is decreased by PARTIAL bytes.
5240 : : REG must be a hard register in this case.
5241 : : If REG is zero but PARTIAL is not, take any all others actions for an
5242 : : argument partially in registers, but do not actually load any
5243 : : registers.
5244 : :
5245 : : EXTRA is the amount in bytes of extra space to leave next to this arg.
5246 : : This is ignored if an argument block has already been allocated.
5247 : :
5248 : : On a machine that lacks real push insns, ARGS_ADDR is the address of
5249 : : the bottom of the argument block for this call. We use indexing off there
5250 : : to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
5251 : : argument block has not been preallocated.
5252 : :
5253 : : ARGS_SO_FAR is the size of args previously pushed for this call.
5254 : :
5255 : : REG_PARM_STACK_SPACE is nonzero if functions require stack space
5256 : : for arguments passed in registers. If nonzero, it will be the number
5257 : : of bytes required. */
5258 : :
5259 : : bool
5260 : 2121089 : emit_push_insn (rtx x, machine_mode mode, tree type, rtx size,
5261 : : unsigned int align, int partial, rtx reg, poly_int64 extra,
5262 : : rtx args_addr, rtx args_so_far, int reg_parm_stack_space,
5263 : : rtx alignment_pad, bool sibcall_p)
5264 : : {
5265 : 2121089 : rtx xinner;
5266 : 2121089 : pad_direction stack_direction
5267 : : = STACK_GROWS_DOWNWARD ? PAD_DOWNWARD : PAD_UPWARD;
5268 : :
5269 : : /* Decide where to pad the argument: PAD_DOWNWARD for below,
5270 : : PAD_UPWARD for above, or PAD_NONE for don't pad it.
5271 : : Default is below for small data on big-endian machines; else above. */
5272 : 2121089 : pad_direction where_pad = targetm.calls.function_arg_padding (mode, type);
5273 : :
5274 : : /* Invert direction if stack is post-decrement.
5275 : : FIXME: why? */
5276 : 2121089 : if (STACK_PUSH_CODE == POST_DEC)
5277 : : if (where_pad != PAD_NONE)
5278 : : where_pad = (where_pad == PAD_DOWNWARD ? PAD_UPWARD : PAD_DOWNWARD);
5279 : :
5280 : 2121089 : xinner = x;
5281 : :
5282 : 2121089 : int nregs = partial / UNITS_PER_WORD;
5283 : 2121089 : rtx *tmp_regs = NULL;
5284 : 2121089 : int overlapping = 0;
5285 : :
5286 : 2121089 : if (mode == BLKmode
5287 : : || (STRICT_ALIGNMENT && align < GET_MODE_ALIGNMENT (mode)))
5288 : : {
5289 : : /* Copy a block into the stack, entirely or partially. */
5290 : :
5291 : 266199 : rtx temp;
5292 : 266199 : int used;
5293 : 266199 : int offset;
5294 : 266199 : int skip;
5295 : :
5296 : 266199 : offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
5297 : 266199 : used = partial - offset;
5298 : :
5299 : 266199 : if (mode != BLKmode)
5300 : : {
5301 : : /* A value is to be stored in an insufficiently aligned
5302 : : stack slot; copy via a suitably aligned slot if
5303 : : necessary. */
5304 : : size = gen_int_mode (GET_MODE_SIZE (mode), Pmode);
5305 : : if (!MEM_P (xinner))
5306 : : {
5307 : : temp = assign_temp (type, 1, 1);
5308 : : emit_move_insn (temp, xinner);
5309 : : xinner = temp;
5310 : : }
5311 : : }
5312 : :
5313 : 266199 : gcc_assert (size);
5314 : :
5315 : : /* USED is now the # of bytes we need not copy to the stack
5316 : : because registers will take care of them. */
5317 : :
5318 : 266199 : if (partial != 0)
5319 : 0 : xinner = adjust_address (xinner, BLKmode, used);
5320 : :
5321 : : /* If the partial register-part of the arg counts in its stack size,
5322 : : skip the part of stack space corresponding to the registers.
5323 : : Otherwise, start copying to the beginning of the stack space,
5324 : : by setting SKIP to 0. */
5325 : 266199 : skip = (reg_parm_stack_space == 0) ? 0 : used;
5326 : :
5327 : : #ifdef PUSH_ROUNDING
5328 : : /* NB: Let the backend known the number of bytes to push and
5329 : : decide if push insns should be generated. */
5330 : 266199 : unsigned int push_size;
5331 : 266199 : if (CONST_INT_P (size))
5332 : 266199 : push_size = INTVAL (size);
5333 : : else
5334 : : push_size = 0;
5335 : :
5336 : : /* Do it with several push insns if that doesn't take lots of insns
5337 : : and if there is no difficulty with push insns that skip bytes
5338 : : on the stack for alignment purposes. */
5339 : 266199 : if (args_addr == 0
5340 : 266158 : && targetm.calls.push_argument (push_size)
5341 : 3756 : && CONST_INT_P (size)
5342 : 3756 : && skip == 0
5343 : 3756 : && MEM_ALIGN (xinner) >= align
5344 : 2853 : && can_move_by_pieces ((unsigned) INTVAL (size) - used, align)
5345 : : /* Here we avoid the case of a structure whose weak alignment
5346 : : forces many pushes of a small amount of data,
5347 : : and such small pushes do rounding that causes trouble. */
5348 : 2853 : && ((!targetm.slow_unaligned_access (word_mode, align))
5349 : 0 : || align >= BIGGEST_ALIGNMENT
5350 : 0 : || known_eq (PUSH_ROUNDING (align / BITS_PER_UNIT),
5351 : : align / BITS_PER_UNIT))
5352 : 269052 : && known_eq (PUSH_ROUNDING (INTVAL (size)), INTVAL (size)))
5353 : : {
5354 : : /* Push padding now if padding above and stack grows down,
5355 : : or if padding below and stack grows up.
5356 : : But if space already allocated, this has already been done. */
5357 : 46 : if (maybe_ne (extra, 0)
5358 : : && args_addr == 0
5359 : 0 : && where_pad != PAD_NONE
5360 : 46 : && where_pad != stack_direction)
5361 : 0 : anti_adjust_stack (gen_int_mode (extra, Pmode));
5362 : :
5363 : 46 : move_by_pieces (NULL, xinner, INTVAL (size) - used, align,
5364 : : RETURN_BEGIN);
5365 : : }
5366 : : else
5367 : : #endif /* PUSH_ROUNDING */
5368 : : {
5369 : 266153 : rtx target;
5370 : :
5371 : : /* Otherwise make space on the stack and copy the data
5372 : : to the address of that space. */
5373 : :
5374 : : /* Deduct words put into registers from the size we must copy. */
5375 : 266153 : if (partial != 0)
5376 : : {
5377 : 0 : if (CONST_INT_P (size))
5378 : 0 : size = GEN_INT (INTVAL (size) - used);
5379 : : else
5380 : 0 : size = expand_binop (GET_MODE (size), sub_optab, size,
5381 : 0 : gen_int_mode (used, GET_MODE (size)),
5382 : : NULL_RTX, 0, OPTAB_LIB_WIDEN);
5383 : : }
5384 : :
5385 : : /* Get the address of the stack space.
5386 : : In this case, we do not deal with EXTRA separately.
5387 : : A single stack adjust will do. */
5388 : 266153 : poly_int64 const_args_so_far;
5389 : 266153 : if (! args_addr)
5390 : : {
5391 : 266112 : temp = push_block (size, extra, where_pad == PAD_DOWNWARD);
5392 : 266112 : extra = 0;
5393 : : }
5394 : 41 : else if (poly_int_rtx_p (args_so_far, &const_args_so_far))
5395 : 41 : temp = memory_address (BLKmode,
5396 : : plus_constant (Pmode, args_addr,
5397 : : skip + const_args_so_far));
5398 : : else
5399 : 0 : temp = memory_address (BLKmode,
5400 : : plus_constant (Pmode,
5401 : : gen_rtx_PLUS (Pmode,
5402 : : args_addr,
5403 : : args_so_far),
5404 : : skip));
5405 : :
5406 : 266153 : if (!ACCUMULATE_OUTGOING_ARGS)
5407 : : {
5408 : : /* If the source is referenced relative to the stack pointer,
5409 : : copy it to another register to stabilize it. We do not need
5410 : : to do this if we know that we won't be changing sp. */
5411 : :
5412 : 266153 : if (reg_mentioned_p (virtual_stack_dynamic_rtx, temp)
5413 : 266153 : || reg_mentioned_p (virtual_outgoing_args_rtx, temp))
5414 : 266112 : temp = copy_to_reg (temp);
5415 : : }
5416 : :
5417 : 266153 : target = gen_rtx_MEM (BLKmode, temp);
5418 : :
5419 : : /* We do *not* set_mem_attributes here, because incoming arguments
5420 : : may overlap with sibling call outgoing arguments and we cannot
5421 : : allow reordering of reads from function arguments with stores
5422 : : to outgoing arguments of sibling calls. We do, however, want
5423 : : to record the alignment of the stack slot. */
5424 : : /* ALIGN may well be better aligned than TYPE, e.g. due to
5425 : : PARM_BOUNDARY. Assume the caller isn't lying. */
5426 : 266153 : set_mem_align (target, align);
5427 : :
5428 : : /* If part should go in registers and pushing to that part would
5429 : : overwrite some of the values that need to go into regs, load the
5430 : : overlapping values into temporary pseudos to be moved into the hard
5431 : : regs at the end after the stack pushing has completed.
5432 : : We cannot load them directly into the hard regs here because
5433 : : they can be clobbered by the block move expansions.
5434 : : See PR 65358. */
5435 : :
5436 : 266153 : if (partial > 0 && reg != 0 && mode == BLKmode
5437 : 0 : && GET_CODE (reg) != PARALLEL)
5438 : : {
5439 : 0 : overlapping = memory_load_overlap (XEXP (x, 0), temp, partial);
5440 : 0 : if (overlapping > 0)
5441 : : {
5442 : 0 : gcc_assert (overlapping % UNITS_PER_WORD == 0);
5443 : 0 : overlapping /= UNITS_PER_WORD;
5444 : :
5445 : 0 : tmp_regs = XALLOCAVEC (rtx, overlapping);
5446 : :
5447 : 0 : for (int i = 0; i < overlapping; i++)
5448 : 0 : tmp_regs[i] = gen_reg_rtx (word_mode);
5449 : :
5450 : 0 : for (int i = 0; i < overlapping; i++)
5451 : 0 : emit_move_insn (tmp_regs[i],
5452 : 0 : operand_subword_force (target, i, mode));
5453 : : }
5454 : 0 : else if (overlapping == -1)
5455 : : overlapping = 0;
5456 : : /* Could not determine whether there is overlap.
5457 : : Fail the sibcall. */
5458 : : else
5459 : : {
5460 : 0 : overlapping = 0;
5461 : 0 : if (sibcall_p)
5462 : 0 : return false;
5463 : : }
5464 : : }
5465 : :
5466 : : /* If source is a constant VAR_DECL with a simple constructor,
5467 : : store the constructor to the stack instead of moving it. */
5468 : 266153 : const_tree decl;
5469 : 266153 : HOST_WIDE_INT sz;
5470 : 266153 : if (partial == 0
5471 : 266153 : && MEM_P (xinner)
5472 : 266153 : && SYMBOL_REF_P (XEXP (xinner, 0))
5473 : 81547 : && (decl = SYMBOL_REF_DECL (XEXP (xinner, 0))) != NULL_TREE
5474 : 81547 : && VAR_P (decl)
5475 : 81547 : && TREE_READONLY (decl)
5476 : 4325 : && !TREE_SIDE_EFFECTS (decl)
5477 : 4325 : && immediate_const_ctor_p (DECL_INITIAL (decl), 2)
5478 : 6 : && (sz = int_expr_size (DECL_INITIAL (decl))) > 0
5479 : 6 : && CONST_INT_P (size)
5480 : 266159 : && INTVAL (size) == sz)
5481 : 0 : store_constructor (DECL_INITIAL (decl), target, 0, sz, false);
5482 : : else
5483 : 266153 : emit_block_move (target, xinner, size, BLOCK_OP_CALL_PARM);
5484 : : }
5485 : : }
5486 : 1854890 : else if (partial > 0)
5487 : : {
5488 : : /* Scalar partly in registers. This case is only supported
5489 : : for fixed-wdth modes. */
5490 : 0 : int num_words = GET_MODE_SIZE (mode).to_constant ();
5491 : 0 : num_words /= UNITS_PER_WORD;
5492 : 0 : int i;
5493 : 0 : int not_stack;
5494 : : /* # bytes of start of argument
5495 : : that we must make space for but need not store. */
5496 : 0 : int offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
5497 : 0 : int args_offset = INTVAL (args_so_far);
5498 : 0 : int skip;
5499 : :
5500 : : /* Push padding now if padding above and stack grows down,
5501 : : or if padding below and stack grows up.
5502 : : But if space already allocated, this has already been done. */
5503 : 0 : if (maybe_ne (extra, 0)
5504 : 0 : && args_addr == 0
5505 : 0 : && where_pad != PAD_NONE
5506 : 0 : && where_pad != stack_direction)
5507 : 0 : anti_adjust_stack (gen_int_mode (extra, Pmode));
5508 : :
5509 : : /* If we make space by pushing it, we might as well push
5510 : : the real data. Otherwise, we can leave OFFSET nonzero
5511 : : and leave the space uninitialized. */
5512 : 0 : if (args_addr == 0)
5513 : 0 : offset = 0;
5514 : :
5515 : : /* Now NOT_STACK gets the number of words that we don't need to
5516 : : allocate on the stack. Convert OFFSET to words too. */
5517 : 0 : not_stack = (partial - offset) / UNITS_PER_WORD;
5518 : 0 : offset /= UNITS_PER_WORD;
5519 : :
5520 : : /* If the partial register-part of the arg counts in its stack size,
5521 : : skip the part of stack space corresponding to the registers.
5522 : : Otherwise, start copying to the beginning of the stack space,
5523 : : by setting SKIP to 0. */
5524 : 0 : skip = (reg_parm_stack_space == 0) ? 0 : not_stack;
5525 : :
5526 : 0 : if (CONSTANT_P (x) && !targetm.legitimate_constant_p (mode, x))
5527 : 0 : x = validize_mem (force_const_mem (mode, x));
5528 : :
5529 : : /* If X is a hard register in a non-integer mode, copy it into a pseudo;
5530 : : SUBREGs of such registers are not allowed. */
5531 : 0 : if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER
5532 : 0 : && GET_MODE_CLASS (GET_MODE (x)) != MODE_INT))
5533 : 0 : x = copy_to_reg (x);
5534 : :
5535 : : /* Loop over all the words allocated on the stack for this arg. */
5536 : : /* We can do it by words, because any scalar bigger than a word
5537 : : has a size a multiple of a word. */
5538 : 0 : tree word_mode_type = lang_hooks.types.type_for_mode (word_mode, 1);
5539 : 0 : for (i = num_words - 1; i >= not_stack; i--)
5540 : 0 : if (i >= not_stack + offset)
5541 : 0 : if (!emit_push_insn (operand_subword_force (x, i, mode),
5542 : : word_mode, word_mode_type, NULL_RTX, align, 0,
5543 : 0 : NULL_RTX, 0, args_addr,
5544 : 0 : GEN_INT (args_offset + ((i - not_stack + skip)
5545 : : * UNITS_PER_WORD)),
5546 : : reg_parm_stack_space, alignment_pad, sibcall_p))
5547 : 0 : return false;
5548 : : }
5549 : : else
5550 : : {
5551 : 1854890 : rtx addr;
5552 : 1854890 : rtx dest;
5553 : :
5554 : : /* Push padding now if padding above and stack grows down,
5555 : : or if padding below and stack grows up.
5556 : : But if space already allocated, this has already been done. */
5557 : 1854890 : if (maybe_ne (extra, 0)
5558 : 0 : && args_addr == 0
5559 : 0 : && where_pad != PAD_NONE
5560 : 1854890 : && where_pad != stack_direction)
5561 : 0 : anti_adjust_stack (gen_int_mode (extra, Pmode));
5562 : :
5563 : : #ifdef PUSH_ROUNDING
5564 : 1854890 : if (args_addr == 0 && targetm.calls.push_argument (0))
5565 : 1800444 : emit_single_push_insn (mode, x, type);
5566 : : else
5567 : : #endif
5568 : : {
5569 : 54446 : addr = simplify_gen_binary (PLUS, Pmode, args_addr, args_so_far);
5570 : 54446 : dest = gen_rtx_MEM (mode, memory_address (mode, addr));
5571 : :
5572 : : /* We do *not* set_mem_attributes here, because incoming arguments
5573 : : may overlap with sibling call outgoing arguments and we cannot
5574 : : allow reordering of reads from function arguments with stores
5575 : : to outgoing arguments of sibling calls. We do, however, want
5576 : : to record the alignment of the stack slot. */
5577 : : /* ALIGN may well be better aligned than TYPE, e.g. due to
5578 : : PARM_BOUNDARY. Assume the caller isn't lying. */
5579 : 54446 : set_mem_align (dest, align);
5580 : :
5581 : 54446 : emit_move_insn (dest, x);
5582 : : }
5583 : : }
5584 : :
5585 : : /* Move the partial arguments into the registers and any overlapping
5586 : : values that we moved into the pseudos in tmp_regs. */
5587 : 2121089 : if (partial > 0 && reg != 0)
5588 : : {
5589 : : /* Handle calls that pass values in multiple non-contiguous locations.
5590 : : The Irix 6 ABI has examples of this. */
5591 : 0 : if (GET_CODE (reg) == PARALLEL)
5592 : 0 : emit_group_load (reg, x, type, -1);
5593 : : else
5594 : : {
5595 : 0 : gcc_assert (partial % UNITS_PER_WORD == 0);
5596 : 0 : move_block_to_reg (REGNO (reg), x, nregs - overlapping, mode);
5597 : :
5598 : 0 : for (int i = 0; i < overlapping; i++)
5599 : 0 : emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg)
5600 : 0 : + nregs - overlapping + i),
5601 : 0 : tmp_regs[i]);
5602 : :
5603 : : }
5604 : : }
5605 : :
5606 : 2121089 : if (maybe_ne (extra, 0) && args_addr == 0 && where_pad == stack_direction)
5607 : 0 : anti_adjust_stack (gen_int_mode (extra, Pmode));
5608 : :
5609 : 2121089 : if (alignment_pad && args_addr == 0)
5610 : 2066602 : anti_adjust_stack (alignment_pad);
5611 : :
5612 : : return true;
5613 : : }
5614 : :
5615 : : /* Return X if X can be used as a subtarget in a sequence of arithmetic
5616 : : operations. */
5617 : :
5618 : : static rtx
5619 : 184972197 : get_subtarget (rtx x)
5620 : : {
5621 : 184972197 : return (optimize
5622 : 50363542 : || x == 0
5623 : : /* Only registers can be subtargets. */
5624 : 16917756 : || !REG_P (x)
5625 : : /* Don't use hard regs to avoid extending their life. */
5626 : 11674269 : || REGNO (x) < FIRST_PSEUDO_REGISTER
5627 : 184972197 : ? 0 : x);
5628 : : }
5629 : :
5630 : : /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
5631 : : FIELD is a bitfield. Returns true if the optimization was successful,
5632 : : and there's nothing else to do. */
5633 : :
5634 : : static bool
5635 : 4404926 : optimize_bitfield_assignment_op (poly_uint64 pbitsize,
5636 : : poly_uint64 pbitpos,
5637 : : poly_uint64 pbitregion_start,
5638 : : poly_uint64 pbitregion_end,
5639 : : machine_mode mode1, rtx str_rtx,
5640 : : tree to, tree src, bool reverse)
5641 : : {
5642 : : /* str_mode is not guaranteed to be a scalar type. */
5643 : 4404926 : machine_mode str_mode = GET_MODE (str_rtx);
5644 : 4404926 : unsigned int str_bitsize;
5645 : 4404926 : tree op0, op1;
5646 : 4404926 : rtx value, result;
5647 : 4404926 : optab binop;
5648 : 4404926 : gimple *srcstmt;
5649 : 4404926 : enum tree_code code;
5650 : :
5651 : 4404926 : unsigned HOST_WIDE_INT bitsize, bitpos, bitregion_start, bitregion_end;
5652 : 4404926 : if (mode1 != VOIDmode
5653 : 65154 : || !pbitsize.is_constant (&bitsize)
5654 : 65154 : || !pbitpos.is_constant (&bitpos)
5655 : 65154 : || !pbitregion_start.is_constant (&bitregion_start)
5656 : 65154 : || !pbitregion_end.is_constant (&bitregion_end)
5657 : 65715 : || bitsize >= BITS_PER_WORD
5658 : 65029 : || !GET_MODE_BITSIZE (str_mode).is_constant (&str_bitsize)
5659 : 65590 : || str_bitsize > BITS_PER_WORD
5660 : 59260 : || TREE_SIDE_EFFECTS (to)
5661 : 4464091 : || TREE_THIS_VOLATILE (to))
5662 : : return false;
5663 : :
5664 : 59165 : STRIP_NOPS (src);
5665 : 59165 : if (TREE_CODE (src) != SSA_NAME)
5666 : : return false;
5667 : 16668 : if (TREE_CODE (TREE_TYPE (src)) != INTEGER_TYPE)
5668 : : return false;
5669 : :
5670 : 15615 : srcstmt = get_gimple_for_ssa_name (src);
5671 : 15615 : if (!srcstmt
5672 : 15615 : || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt)) != tcc_binary)
5673 : : return false;
5674 : :
5675 : 894 : code = gimple_assign_rhs_code (srcstmt);
5676 : :
5677 : 894 : op0 = gimple_assign_rhs1 (srcstmt);
5678 : :
5679 : : /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
5680 : : to find its initialization. Hopefully the initialization will
5681 : : be from a bitfield load. */
5682 : 894 : if (TREE_CODE (op0) == SSA_NAME)
5683 : : {
5684 : 894 : gimple *op0stmt = get_gimple_for_ssa_name (op0);
5685 : :
5686 : : /* We want to eventually have OP0 be the same as TO, which
5687 : : should be a bitfield. */
5688 : 894 : if (!op0stmt
5689 : 864 : || !is_gimple_assign (op0stmt)
5690 : 1758 : || gimple_assign_rhs_code (op0stmt) != TREE_CODE (to))
5691 : : return false;
5692 : 298 : op0 = gimple_assign_rhs1 (op0stmt);
5693 : : }
5694 : :
5695 : 298 : op1 = gimple_assign_rhs2 (srcstmt);
5696 : :
5697 : 298 : if (!operand_equal_p (to, op0, 0))
5698 : : return false;
5699 : :
5700 : 228 : if (MEM_P (str_rtx))
5701 : : {
5702 : 223 : unsigned HOST_WIDE_INT offset1;
5703 : :
5704 : 223 : if (str_bitsize == 0 || str_bitsize > BITS_PER_WORD)
5705 : 4 : str_bitsize = BITS_PER_WORD;
5706 : :
5707 : 223 : scalar_int_mode best_mode;
5708 : 223 : if (!get_best_mode (bitsize, bitpos, bitregion_start, bitregion_end,
5709 : 223 : MEM_ALIGN (str_rtx), str_bitsize, false, &best_mode))
5710 : 0 : return false;
5711 : 223 : str_mode = best_mode;
5712 : 223 : str_bitsize = GET_MODE_BITSIZE (best_mode);
5713 : :
5714 : 223 : offset1 = bitpos;
5715 : 223 : bitpos %= str_bitsize;
5716 : 223 : offset1 = (offset1 - bitpos) / BITS_PER_UNIT;
5717 : 223 : str_rtx = adjust_address (str_rtx, str_mode, offset1);
5718 : : }
5719 : 5 : else if (!REG_P (str_rtx) && GET_CODE (str_rtx) != SUBREG)
5720 : : return false;
5721 : :
5722 : : /* If the bit field covers the whole REG/MEM, store_field
5723 : : will likely generate better code. */
5724 : 228 : if (bitsize >= str_bitsize)
5725 : : return false;
5726 : :
5727 : : /* We can't handle fields split across multiple entities. */
5728 : 228 : if (bitpos + bitsize > str_bitsize)
5729 : : return false;
5730 : :
5731 : 228 : if (reverse ? !BYTES_BIG_ENDIAN : BYTES_BIG_ENDIAN)
5732 : 0 : bitpos = str_bitsize - bitpos - bitsize;
5733 : :
5734 : 228 : switch (code)
5735 : : {
5736 : 141 : case PLUS_EXPR:
5737 : 141 : case MINUS_EXPR:
5738 : : /* For now, just optimize the case of the topmost bitfield
5739 : : where we don't need to do any masking and also
5740 : : 1 bit bitfields where xor can be used.
5741 : : We might win by one instruction for the other bitfields
5742 : : too if insv/extv instructions aren't used, so that
5743 : : can be added later. */
5744 : 141 : if ((reverse || bitpos + bitsize != str_bitsize)
5745 : 97 : && (bitsize != 1 || TREE_CODE (op1) != INTEGER_CST))
5746 : : break;
5747 : :
5748 : 70 : value = expand_expr (op1, NULL_RTX, str_mode, EXPAND_NORMAL);
5749 : 70 : value = convert_modes (str_mode,
5750 : 70 : TYPE_MODE (TREE_TYPE (op1)), value,
5751 : 70 : TYPE_UNSIGNED (TREE_TYPE (op1)));
5752 : :
5753 : : /* We may be accessing data outside the field, which means
5754 : : we can alias adjacent data. */
5755 : 70 : if (MEM_P (str_rtx))
5756 : : {
5757 : 70 : str_rtx = shallow_copy_rtx (str_rtx);
5758 : 70 : set_mem_alias_set (str_rtx, 0);
5759 : 70 : set_mem_expr (str_rtx, 0);
5760 : : }
5761 : :
5762 : 70 : if (bitsize == 1 && (reverse || bitpos + bitsize != str_bitsize))
5763 : : {
5764 : 26 : value = expand_and (str_mode, value, const1_rtx, NULL);
5765 : 26 : binop = xor_optab;
5766 : : }
5767 : : else
5768 : 44 : binop = code == PLUS_EXPR ? add_optab : sub_optab;
5769 : :
5770 : 70 : value = expand_shift (LSHIFT_EXPR, str_mode, value, bitpos, NULL_RTX, 1);
5771 : 70 : if (reverse)
5772 : 0 : value = flip_storage_order (str_mode, value);
5773 : 70 : result = expand_binop (str_mode, binop, str_rtx,
5774 : : value, str_rtx, 1, OPTAB_WIDEN);
5775 : 70 : if (result != str_rtx)
5776 : 0 : emit_move_insn (str_rtx, result);
5777 : : return true;
5778 : :
5779 : 57 : case BIT_IOR_EXPR:
5780 : 57 : case BIT_XOR_EXPR:
5781 : 57 : if (TREE_CODE (op1) != INTEGER_CST)
5782 : : break;
5783 : 55 : value = expand_expr (op1, NULL_RTX, str_mode, EXPAND_NORMAL);
5784 : 55 : value = convert_modes (str_mode,
5785 : 55 : TYPE_MODE (TREE_TYPE (op1)), value,
5786 : 55 : TYPE_UNSIGNED (TREE_TYPE (op1)));
5787 : :
5788 : : /* We may be accessing data outside the field, which means
5789 : : we can alias adjacent data. */
5790 : 55 : if (MEM_P (str_rtx))
5791 : : {
5792 : 55 : str_rtx = shallow_copy_rtx (str_rtx);
5793 : 55 : set_mem_alias_set (str_rtx, 0);
5794 : 55 : set_mem_expr (str_rtx, 0);
5795 : : }
5796 : :
5797 : 55 : binop = code == BIT_IOR_EXPR ? ior_optab : xor_optab;
5798 : 55 : if (bitpos + bitsize != str_bitsize)
5799 : : {
5800 : 31 : rtx mask = gen_int_mode ((HOST_WIDE_INT_1U << bitsize) - 1,
5801 : : str_mode);
5802 : 31 : value = expand_and (str_mode, value, mask, NULL_RTX);
5803 : : }
5804 : 55 : value = expand_shift (LSHIFT_EXPR, str_mode, value, bitpos, NULL_RTX, 1);
5805 : 55 : if (reverse)
5806 : 0 : value = flip_storage_order (str_mode, value);
5807 : 55 : result = expand_binop (str_mode, binop, str_rtx,
5808 : : value, str_rtx, 1, OPTAB_WIDEN);
5809 : 55 : if (result != str_rtx)
5810 : 0 : emit_move_insn (str_rtx, result);
5811 : : return true;
5812 : :
5813 : : default:
5814 : : break;
5815 : : }
5816 : :
5817 : : return false;
5818 : : }
5819 : :
5820 : : /* In the C++ memory model, consecutive bit fields in a structure are
5821 : : considered one memory location.
5822 : :
5823 : : Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
5824 : : returns the bit range of consecutive bits in which this COMPONENT_REF
5825 : : belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
5826 : : and *OFFSET may be adjusted in the process.
5827 : :
5828 : : If the access does not need to be restricted, 0 is returned in both
5829 : : *BITSTART and *BITEND. */
5830 : :
5831 : : void
5832 : 664091 : get_bit_range (poly_uint64 *bitstart, poly_uint64 *bitend, tree exp,
5833 : : poly_int64 *bitpos, tree *offset)
5834 : : {
5835 : 664091 : poly_int64 bitoffset;
5836 : 664091 : tree field, repr;
5837 : :
5838 : 664091 : gcc_assert (TREE_CODE (exp) == COMPONENT_REF);
5839 : :
5840 : 664091 : field = TREE_OPERAND (exp, 1);
5841 : 664091 : repr = DECL_BIT_FIELD_REPRESENTATIVE (field);
5842 : : /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
5843 : : need to limit the range we can access. */
5844 : 664091 : if (!repr)
5845 : : {
5846 : 11617 : *bitstart = *bitend = 0;
5847 : 11617 : return;
5848 : : }
5849 : :
5850 : : /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
5851 : : part of a larger bit field, then the representative does not serve any
5852 : : useful purpose. This can occur in Ada. */
5853 : 652474 : if (handled_component_p (TREE_OPERAND (exp, 0)))
5854 : : {
5855 : 477402 : machine_mode rmode;
5856 : 477402 : poly_int64 rbitsize, rbitpos;
5857 : 477402 : tree roffset;
5858 : 477402 : int unsignedp, reversep, volatilep = 0;
5859 : 477402 : get_inner_reference (TREE_OPERAND (exp, 0), &rbitsize, &rbitpos,
5860 : : &roffset, &rmode, &unsignedp, &reversep,
5861 : : &volatilep);
5862 : 954804 : if (!multiple_p (rbitpos, BITS_PER_UNIT))
5863 : : {
5864 : 0 : *bitstart = *bitend = 0;
5865 : 0 : return;
5866 : : }
5867 : : }
5868 : :
5869 : : /* Compute the adjustment to bitpos from the offset of the field
5870 : : relative to the representative. DECL_FIELD_OFFSET of field and
5871 : : repr are the same by construction if they are not constants,
5872 : : see finish_bitfield_layout. */
5873 : 652474 : poly_uint64 field_offset, repr_offset;
5874 : 652474 : if (poly_int_tree_p (DECL_FIELD_OFFSET (field), &field_offset)
5875 : 1304943 : && poly_int_tree_p (DECL_FIELD_OFFSET (repr), &repr_offset))
5876 : 652469 : bitoffset = (field_offset - repr_offset) * BITS_PER_UNIT;
5877 : : else
5878 : : bitoffset = 0;
5879 : 652474 : bitoffset += (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field))
5880 : 652474 : - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr)));
5881 : :
5882 : : /* If the adjustment is larger than bitpos, we would have a negative bit
5883 : : position for the lower bound and this may wreak havoc later. Adjust
5884 : : offset and bitpos to make the lower bound non-negative in that case. */
5885 : 652474 : if (maybe_gt (bitoffset, *bitpos))
5886 : : {
5887 : 11 : poly_int64 adjust_bits = upper_bound (bitoffset, *bitpos) - *bitpos;
5888 : 11 : poly_int64 adjust_bytes = exact_div (adjust_bits, BITS_PER_UNIT);
5889 : :
5890 : 11 : *bitpos += adjust_bits;
5891 : 11 : if (*offset == NULL_TREE)
5892 : 5 : *offset = size_int (-adjust_bytes);
5893 : : else
5894 : 6 : *offset = size_binop (MINUS_EXPR, *offset, size_int (adjust_bytes));
5895 : 11 : *bitstart = 0;
5896 : : }
5897 : : else
5898 : 652463 : *bitstart = *bitpos - bitoffset;
5899 : :
5900 : 652474 : *bitend = *bitstart + tree_to_poly_uint64 (DECL_SIZE (repr)) - 1;
5901 : : }
5902 : :
5903 : : /* Returns true if BASE is a DECL that does not reside in memory and
5904 : : has non-BLKmode. DECL_RTL must not be a MEM; if
5905 : : DECL_RTL was not set yet, return false. */
5906 : :
5907 : : bool
5908 : 4511743 : non_mem_decl_p (tree base)
5909 : : {
5910 : 4511743 : if (!DECL_P (base)
5911 : 4511436 : || TREE_ADDRESSABLE (base)
5912 : 6825207 : || DECL_MODE (base) == BLKmode)
5913 : : return false;
5914 : :
5915 : 1580363 : if (!DECL_RTL_SET_P (base))
5916 : : return false;
5917 : :
5918 : 1465842 : return (!MEM_P (DECL_RTL (base)));
5919 : : }
5920 : :
5921 : : /* Returns true if REF refers to an object that does not
5922 : : reside in memory and has non-BLKmode. */
5923 : :
5924 : : bool
5925 : 10287395 : mem_ref_refers_to_non_mem_p (tree ref)
5926 : : {
5927 : 10287395 : tree base;
5928 : :
5929 : 10287395 : if (TREE_CODE (ref) == MEM_REF
5930 : 10287395 : || TREE_CODE (ref) == TARGET_MEM_REF)
5931 : : {
5932 : 8702702 : tree addr = TREE_OPERAND (ref, 0);
5933 : :
5934 : 8702702 : if (TREE_CODE (addr) != ADDR_EXPR)
5935 : : return false;
5936 : :
5937 : 2926833 : base = TREE_OPERAND (addr, 0);
5938 : : }
5939 : : else
5940 : : base = ref;
5941 : :
5942 : 4511526 : return non_mem_decl_p (base);
5943 : : }
5944 : :
5945 : : /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
5946 : : is true, try generating a nontemporal store. */
5947 : :
5948 : : void
5949 : 17298996 : expand_assignment (tree to, tree from, bool nontemporal)
5950 : : {
5951 : 17298996 : rtx to_rtx = 0;
5952 : 17298996 : rtx result;
5953 : 17298996 : machine_mode mode;
5954 : 17298996 : unsigned int align;
5955 : 17298996 : enum insn_code icode;
5956 : :
5957 : : /* Don't crash if the lhs of the assignment was erroneous. */
5958 : 17298996 : if (TREE_CODE (to) == ERROR_MARK)
5959 : : {
5960 : 0 : expand_normal (from);
5961 : 0 : return;
5962 : : }
5963 : :
5964 : : /* Optimize away no-op moves without side-effects. */
5965 : 17298996 : if (operand_equal_p (to, from, 0))
5966 : : return;
5967 : :
5968 : : /* Handle misaligned stores. */
5969 : 17298904 : mode = TYPE_MODE (TREE_TYPE (to));
5970 : 17298904 : if ((TREE_CODE (to) == MEM_REF
5971 : 17298904 : || TREE_CODE (to) == TARGET_MEM_REF
5972 : 15538741 : || DECL_P (to))
5973 : 3722522 : && mode != BLKmode
5974 : 3231543 : && !mem_ref_refers_to_non_mem_p (to)
5975 : 5546716 : && ((align = get_object_alignment (to))
5976 : 2773358 : < GET_MODE_ALIGNMENT (mode))
5977 : 17720671 : && (((icode = optab_handler (movmisalign_optab, mode))
5978 : : != CODE_FOR_nothing)
5979 : 94823 : || targetm.slow_unaligned_access (mode, align)))
5980 : : {
5981 : 326944 : rtx reg, mem;
5982 : :
5983 : 326944 : reg = expand_expr (from, NULL_RTX, VOIDmode, EXPAND_NORMAL);
5984 : : /* Handle PARALLEL. */
5985 : 326944 : reg = maybe_emit_group_store (reg, TREE_TYPE (from));
5986 : 326944 : reg = force_not_mem (reg);
5987 : 326944 : mem = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
5988 : 326944 : if (TREE_CODE (to) == MEM_REF && REF_REVERSE_STORAGE_ORDER (to))
5989 : 0 : reg = flip_storage_order (mode, reg);
5990 : :
5991 : 326944 : if (icode != CODE_FOR_nothing)
5992 : : {
5993 : 326944 : class expand_operand ops[2];
5994 : :
5995 : 326944 : create_fixed_operand (&ops[0], mem);
5996 : 326944 : create_input_operand (&ops[1], reg, mode);
5997 : : /* The movmisalign<mode> pattern cannot fail, else the assignment
5998 : : would silently be omitted. */
5999 : 326944 : expand_insn (icode, 2, ops);
6000 : : }
6001 : : else
6002 : 0 : store_bit_field (mem, GET_MODE_BITSIZE (mode), 0, 0, 0, mode, reg,
6003 : : false, false);
6004 : 326944 : return;
6005 : : }
6006 : :
6007 : : /* Assignment of a structure component needs special treatment
6008 : : if the structure component's rtx is not simply a MEM.
6009 : : Assignment of an array element at a constant index, and assignment of
6010 : : an array element in an unaligned packed structure field, has the same
6011 : : problem. Same for (partially) storing into a non-memory object. */
6012 : 16971960 : if (handled_component_p (to)
6013 : 12763321 : || (TREE_CODE (to) == MEM_REF
6014 : 1234053 : && (REF_REVERSE_STORAGE_ORDER (to)
6015 : 1234053 : || mem_ref_refers_to_non_mem_p (to)))
6016 : 29657018 : || TREE_CODE (TREE_TYPE (to)) == ARRAY_TYPE)
6017 : : {
6018 : 4405061 : machine_mode mode1;
6019 : 4405061 : poly_int64 bitsize, bitpos;
6020 : 4405061 : poly_uint64 bitregion_start = 0;
6021 : 4405061 : poly_uint64 bitregion_end = 0;
6022 : 4405061 : tree offset;
6023 : 4405061 : int unsignedp, reversep, volatilep = 0;
6024 : 4405061 : tree tem;
6025 : :
6026 : 4405061 : push_temp_slots ();
6027 : 4405061 : tem = get_inner_reference (to, &bitsize, &bitpos, &offset, &mode1,
6028 : : &unsignedp, &reversep, &volatilep);
6029 : :
6030 : : /* Make sure bitpos is not negative, it can wreak havoc later. */
6031 : 4405061 : if (maybe_lt (bitpos, 0))
6032 : : {
6033 : 334 : gcc_assert (offset == NULL_TREE);
6034 : 334 : offset = size_int (bits_to_bytes_round_down (bitpos));
6035 : 334 : bitpos = num_trailing_bits (bitpos);
6036 : : }
6037 : :
6038 : 4405061 : if (TREE_CODE (to) == COMPONENT_REF
6039 : 4405061 : && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to, 1)))
6040 : 83647 : get_bit_range (&bitregion_start, &bitregion_end, to, &bitpos, &offset);
6041 : : /* The C++ memory model naturally applies to byte-aligned fields.
6042 : : However, if we do not have a DECL_BIT_FIELD_TYPE but BITPOS or
6043 : : BITSIZE are not byte-aligned, there is no need to limit the range
6044 : : we can access. This can occur with packed structures in Ada. */
6045 : 164 : else if (maybe_gt (bitsize, 0)
6046 : 4321398 : && multiple_p (bitsize, BITS_PER_UNIT)
6047 : 8642664 : && multiple_p (bitpos, BITS_PER_UNIT))
6048 : : {
6049 : 4321250 : bitregion_start = bitpos;
6050 : 4321250 : bitregion_end = bitpos + bitsize - 1;
6051 : : }
6052 : :
6053 : 4405061 : to_rtx = expand_expr (tem, NULL_RTX, VOIDmode, EXPAND_WRITE);
6054 : :
6055 : : /* If the field has a mode, we want to access it in the
6056 : : field's mode, not the computed mode.
6057 : : If a MEM has VOIDmode (external with incomplete type),
6058 : : use BLKmode for it instead. */
6059 : 4405061 : if (MEM_P (to_rtx))
6060 : : {
6061 : 3770782 : if (mode1 != VOIDmode)
6062 : 3706330 : to_rtx = adjust_address (to_rtx, mode1, 0);
6063 : 64452 : else if (GET_MODE (to_rtx) == VOIDmode)
6064 : 0 : to_rtx = adjust_address (to_rtx, BLKmode, 0);
6065 : : }
6066 : :
6067 : 4405061 : rtx stemp = NULL_RTX, old_to_rtx = NULL_RTX;
6068 : 4405061 : if (offset != 0)
6069 : : {
6070 : 173957 : machine_mode address_mode;
6071 : 173957 : rtx offset_rtx;
6072 : :
6073 : 173957 : if (!MEM_P (to_rtx))
6074 : : {
6075 : : /* We can get constant negative offsets into arrays with broken
6076 : : user code. Translate this to a trap instead of ICEing. */
6077 : 8 : if (TREE_CODE (offset) == INTEGER_CST)
6078 : : {
6079 : 5 : expand_builtin_trap ();
6080 : 5 : to_rtx = gen_rtx_MEM (BLKmode, const0_rtx);
6081 : : }
6082 : : /* Else spill for variable offset to the destination. We expect
6083 : : to run into this only for hard registers. */
6084 : : else
6085 : : {
6086 : 3 : gcc_assert (VAR_P (tem) && DECL_HARD_REGISTER (tem));
6087 : 3 : stemp = assign_stack_temp (GET_MODE (to_rtx),
6088 : 6 : GET_MODE_SIZE (GET_MODE (to_rtx)));
6089 : 3 : emit_move_insn (stemp, to_rtx);
6090 : 3 : old_to_rtx = to_rtx;
6091 : 3 : to_rtx = stemp;
6092 : : }
6093 : : }
6094 : :
6095 : 173957 : offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, EXPAND_SUM);
6096 : 173957 : address_mode = get_address_mode (to_rtx);
6097 : 173957 : if (GET_MODE (offset_rtx) != address_mode)
6098 : : {
6099 : : /* We cannot be sure that the RTL in offset_rtx is valid outside
6100 : : of a memory address context, so force it into a register
6101 : : before attempting to convert it to the desired mode. */
6102 : 358 : offset_rtx = force_operand (offset_rtx, NULL_RTX);
6103 : 358 : offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
6104 : : }
6105 : :
6106 : : /* If we have an expression in OFFSET_RTX and a non-zero
6107 : : byte offset in BITPOS, adding the byte offset before the
6108 : : OFFSET_RTX results in better intermediate code, which makes
6109 : : later rtl optimization passes perform better.
6110 : :
6111 : : We prefer intermediate code like this:
6112 : :
6113 : : r124:DI=r123:DI+0x18
6114 : : [r124:DI]=r121:DI
6115 : :
6116 : : ... instead of ...
6117 : :
6118 : : r124:DI=r123:DI+0x10
6119 : : [r124:DI+0x8]=r121:DI
6120 : :
6121 : : This is only done for aligned data values, as these can
6122 : : be expected to result in single move instructions. */
6123 : 173957 : poly_int64 bytepos;
6124 : 173957 : if (mode1 != VOIDmode
6125 : 173834 : && maybe_ne (bitpos, 0)
6126 : 174023 : && maybe_gt (bitsize, 0)
6127 : 48714 : && multiple_p (bitpos, BITS_PER_UNIT, &bytepos)
6128 : 48714 : && multiple_p (bitpos, bitsize)
6129 : 48663 : && multiple_p (bitsize, GET_MODE_ALIGNMENT (mode1))
6130 : 222620 : && MEM_ALIGN (to_rtx) >= GET_MODE_ALIGNMENT (mode1))
6131 : : {
6132 : 48648 : to_rtx = adjust_address (to_rtx, mode1, bytepos);
6133 : 48648 : bitregion_start = 0;
6134 : 48648 : if (known_ge (bitregion_end, poly_uint64 (bitpos)))
6135 : 48648 : bitregion_end -= bitpos;
6136 : 48648 : bitpos = 0;
6137 : : }
6138 : :
6139 : 173957 : to_rtx = offset_address (to_rtx, offset_rtx,
6140 : : highest_pow2_factor_for_target (to,
6141 : : offset));
6142 : : }
6143 : :
6144 : : /* No action is needed if the target is not a memory and the field
6145 : : lies completely outside that target. This can occur if the source
6146 : : code contains an out-of-bounds access to a small array. */
6147 : 4405061 : if (!MEM_P (to_rtx)
6148 : 634271 : && GET_MODE (to_rtx) != BLKmode
6149 : 5039332 : && known_ge (bitpos, GET_MODE_PRECISION (GET_MODE (to_rtx))))
6150 : : {
6151 : 3 : expand_normal (from);
6152 : 3 : result = NULL;
6153 : : }
6154 : : /* Handle expand_expr of a complex value returning a CONCAT. */
6155 : 4405058 : else if (GET_CODE (to_rtx) == CONCAT)
6156 : : {
6157 : 120 : machine_mode to_mode = GET_MODE (to_rtx);
6158 : 120 : gcc_checking_assert (COMPLEX_MODE_P (to_mode));
6159 : 240 : poly_int64 mode_bitsize = GET_MODE_BITSIZE (to_mode);
6160 : 120 : unsigned short inner_bitsize = GET_MODE_UNIT_BITSIZE (to_mode);
6161 : 120 : if (TYPE_MODE (TREE_TYPE (from)) == to_mode
6162 : 6 : && known_eq (bitpos, 0)
6163 : 126 : && known_eq (bitsize, mode_bitsize))
6164 : 6 : result = store_expr (from, to_rtx, false, nontemporal, reversep);
6165 : 114 : else if (TYPE_MODE (TREE_TYPE (from)) == GET_MODE_INNER (to_mode)
6166 : 64 : && known_eq (bitsize, inner_bitsize)
6167 : 178 : && (known_eq (bitpos, 0)
6168 : 28 : || known_eq (bitpos, inner_bitsize)))
6169 : 64 : result = store_expr (from, XEXP (to_rtx, maybe_ne (bitpos, 0)),
6170 : : false, nontemporal, reversep);
6171 : 50 : else if (known_le (bitpos + bitsize, inner_bitsize))
6172 : 5 : result = store_field (XEXP (to_rtx, 0), bitsize, bitpos,
6173 : : bitregion_start, bitregion_end,
6174 : : mode1, from, get_alias_set (to),
6175 : : nontemporal, reversep);
6176 : 45 : else if (known_ge (bitpos, inner_bitsize))
6177 : 3 : result = store_field (XEXP (to_rtx, 1), bitsize,
6178 : : bitpos - inner_bitsize,
6179 : : bitregion_start, bitregion_end,
6180 : : mode1, from, get_alias_set (to),
6181 : : nontemporal, reversep);
6182 : 42 : else if (known_eq (bitpos, 0) && known_eq (bitsize, mode_bitsize))
6183 : : {
6184 : 35 : result = expand_normal (from);
6185 : 35 : if (GET_CODE (result) == CONCAT)
6186 : : {
6187 : 0 : to_mode = GET_MODE_INNER (to_mode);
6188 : 0 : machine_mode from_mode = GET_MODE_INNER (GET_MODE (result));
6189 : 0 : rtx from_real
6190 : 0 : = simplify_gen_subreg (to_mode, XEXP (result, 0),
6191 : 0 : from_mode, 0);
6192 : 0 : rtx from_imag
6193 : 0 : = simplify_gen_subreg (to_mode, XEXP (result, 1),
6194 : 0 : from_mode, 0);
6195 : 0 : if (!from_real || !from_imag)
6196 : 0 : goto concat_store_slow;
6197 : 0 : emit_move_insn (XEXP (to_rtx, 0), from_real);
6198 : 0 : emit_move_insn (XEXP (to_rtx, 1), from_imag);
6199 : : }
6200 : : else
6201 : : {
6202 : 35 : machine_mode from_mode
6203 : 35 : = GET_MODE (result) == VOIDmode
6204 : 35 : ? TYPE_MODE (TREE_TYPE (from))
6205 : 35 : : GET_MODE (result);
6206 : 35 : rtx from_rtx;
6207 : 35 : if (MEM_P (result))
6208 : 1 : from_rtx = change_address (result, to_mode, NULL_RTX);
6209 : : else
6210 : 34 : from_rtx
6211 : 34 : = simplify_gen_subreg (to_mode, result, from_mode, 0);
6212 : 35 : if (from_rtx)
6213 : : {
6214 : 33 : emit_move_insn (XEXP (to_rtx, 0),
6215 : : read_complex_part (from_rtx, false));
6216 : 33 : emit_move_insn (XEXP (to_rtx, 1),
6217 : : read_complex_part (from_rtx, true));
6218 : : }
6219 : : else
6220 : : {
6221 : 2 : to_mode = GET_MODE_INNER (to_mode);
6222 : 2 : rtx from_real
6223 : 2 : = simplify_gen_subreg (to_mode, result, from_mode, 0);
6224 : 2 : rtx from_imag
6225 : 2 : = simplify_gen_subreg (to_mode, result, from_mode,
6226 : 2 : GET_MODE_SIZE (to_mode));
6227 : 2 : if (!from_real || !from_imag)
6228 : 0 : goto concat_store_slow;
6229 : 2 : emit_move_insn (XEXP (to_rtx, 0), from_real);
6230 : 2 : emit_move_insn (XEXP (to_rtx, 1), from_imag);
6231 : : }
6232 : : }
6233 : : }
6234 : : else
6235 : : {
6236 : 7 : concat_store_slow:;
6237 : 7 : rtx temp = assign_stack_temp (GET_MODE (to_rtx),
6238 : 14 : GET_MODE_SIZE (GET_MODE (to_rtx)));
6239 : 7 : write_complex_part (temp, XEXP (to_rtx, 0), false, true);
6240 : 7 : write_complex_part (temp, XEXP (to_rtx, 1), true, false);
6241 : 7 : result = store_field (temp, bitsize, bitpos,
6242 : : bitregion_start, bitregion_end,
6243 : : mode1, from, get_alias_set (to),
6244 : : nontemporal, reversep);
6245 : 7 : emit_move_insn (XEXP (to_rtx, 0), read_complex_part (temp, false));
6246 : 7 : emit_move_insn (XEXP (to_rtx, 1), read_complex_part (temp, true));
6247 : : }
6248 : : }
6249 : : /* For calls to functions returning variable length structures, if TO_RTX
6250 : : is not a MEM, go through a MEM because we must not create temporaries
6251 : : of the VLA type. */
6252 : 4404938 : else if (!MEM_P (to_rtx)
6253 : 634148 : && TREE_CODE (from) == CALL_EXPR
6254 : 633 : && COMPLETE_TYPE_P (TREE_TYPE (from))
6255 : 4405571 : && TREE_CODE (TYPE_SIZE (TREE_TYPE (from))) != INTEGER_CST)
6256 : : {
6257 : 12 : rtx temp = assign_stack_temp (GET_MODE (to_rtx),
6258 : 24 : GET_MODE_SIZE (GET_MODE (to_rtx)));
6259 : 12 : result = store_field (temp, bitsize, bitpos, bitregion_start,
6260 : : bitregion_end, mode1, from, get_alias_set (to),
6261 : : nontemporal, reversep);
6262 : 12 : emit_move_insn (to_rtx, temp);
6263 : : }
6264 : : else
6265 : : {
6266 : 4404926 : if (MEM_P (to_rtx))
6267 : : {
6268 : : /* If the field is at offset zero, we could have been given the
6269 : : DECL_RTX of the parent struct. Don't munge it. */
6270 : 3770790 : to_rtx = shallow_copy_rtx (to_rtx);
6271 : 3770790 : set_mem_attributes_minus_bitpos (to_rtx, to, 0, bitpos);
6272 : 3770790 : if (volatilep)
6273 : 9310 : MEM_VOLATILE_P (to_rtx) = 1;
6274 : : }
6275 : :
6276 : 4404926 : gcc_checking_assert (known_ge (bitpos, 0));
6277 : 4404926 : if (optimize_bitfield_assignment_op (bitsize, bitpos,
6278 : : bitregion_start, bitregion_end,
6279 : : mode1, to_rtx, to, from,
6280 : : reversep))
6281 : : result = NULL;
6282 : 4404801 : else if (SUBREG_P (to_rtx)
6283 : 4404801 : && SUBREG_PROMOTED_VAR_P (to_rtx))
6284 : : {
6285 : : /* If to_rtx is a promoted subreg, we need to zero or sign
6286 : : extend the value afterwards. */
6287 : 0 : if (TREE_CODE (to) == MEM_REF
6288 : 0 : && TYPE_MODE (TREE_TYPE (from)) != BLKmode
6289 : 0 : && !REF_REVERSE_STORAGE_ORDER (to)
6290 : 0 : && known_eq (bitpos, 0)
6291 : 0 : && known_eq (bitsize, GET_MODE_BITSIZE (GET_MODE (to_rtx))))
6292 : 0 : result = store_expr (from, to_rtx, 0, nontemporal, false);
6293 : : /* Check if the field overlaps the MSB, requiring extension. */
6294 : 0 : else if (maybe_eq (bitpos + bitsize,
6295 : 0 : GET_MODE_BITSIZE (GET_MODE (to_rtx))))
6296 : : {
6297 : 0 : scalar_int_mode imode = subreg_unpromoted_mode (to_rtx);
6298 : 0 : scalar_int_mode omode = subreg_promoted_mode (to_rtx);
6299 : 0 : rtx to_rtx1 = lowpart_subreg (imode, SUBREG_REG (to_rtx),
6300 : : omode);
6301 : 0 : result = store_field (to_rtx1, bitsize, bitpos,
6302 : : bitregion_start, bitregion_end,
6303 : : mode1, from, get_alias_set (to),
6304 : : nontemporal, reversep);
6305 : : /* If the target usually keeps IMODE appropriately
6306 : : extended in OMODE it's unsafe to refer to it using
6307 : : a SUBREG whilst this invariant doesn't hold. */
6308 : 0 : if (targetm.mode_rep_extended (imode, omode) != UNKNOWN)
6309 : 0 : to_rtx1 = simplify_gen_unary (TRUNCATE, imode,
6310 : : SUBREG_REG (to_rtx), omode);
6311 : 0 : convert_move (SUBREG_REG (to_rtx), to_rtx1,
6312 : 0 : SUBREG_PROMOTED_SIGN (to_rtx));
6313 : : }
6314 : : else
6315 : 0 : result = store_field (to_rtx, bitsize, bitpos,
6316 : : bitregion_start, bitregion_end,
6317 : : mode1, from, get_alias_set (to),
6318 : : nontemporal, reversep);
6319 : : }
6320 : : else
6321 : 4404801 : result = store_field (to_rtx, bitsize, bitpos,
6322 : : bitregion_start, bitregion_end,
6323 : : mode1, from, get_alias_set (to),
6324 : : nontemporal, reversep);
6325 : : /* Move the temporary storage back to the non-MEM_P. */
6326 : 4404926 : if (stemp)
6327 : 3 : emit_move_insn (old_to_rtx, stemp);
6328 : : }
6329 : :
6330 : 4405061 : if (result)
6331 : 763355 : preserve_temp_slots (result);
6332 : 4405061 : pop_temp_slots ();
6333 : 4405061 : return;
6334 : : }
6335 : :
6336 : : /* If the rhs is a function call and its value is not an aggregate,
6337 : : call the function before we start to compute the lhs.
6338 : : This is needed for correct code for cases such as
6339 : : val = setjmp (buf) on machines where reference to val
6340 : : requires loading up part of an address in a separate insn.
6341 : :
6342 : : Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
6343 : : since it might be a promoted variable where the zero- or sign- extension
6344 : : needs to be done. Handling this in the normal way is safe because no
6345 : : computation is done before the call. The same is true for SSA names. */
6346 : 2212768 : if (TREE_CODE (from) == CALL_EXPR && ! aggregate_value_p (from, from)
6347 : 2011758 : && COMPLETE_TYPE_P (TREE_TYPE (from))
6348 : 2011758 : && TREE_CODE (TYPE_SIZE (TREE_TYPE (from))) == INTEGER_CST
6349 : 14578657 : && ! (((VAR_P (to)
6350 : : || TREE_CODE (to) == PARM_DECL
6351 : : || TREE_CODE (to) == RESULT_DECL)
6352 : 123211 : && REG_P (DECL_RTL (to)))
6353 : 1895827 : || TREE_CODE (to) == SSA_NAME))
6354 : : {
6355 : 7566 : rtx value;
6356 : :
6357 : 7566 : push_temp_slots ();
6358 : 7566 : value = expand_normal (from);
6359 : :
6360 : 7566 : if (to_rtx == 0)
6361 : 7566 : to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
6362 : :
6363 : : /* Handle calls that return values in multiple non-contiguous locations.
6364 : : The Irix 6 ABI has examples of this. */
6365 : 7566 : if (GET_CODE (to_rtx) == PARALLEL)
6366 : : {
6367 : 0 : if (GET_CODE (value) == PARALLEL)
6368 : 0 : emit_group_move (to_rtx, value);
6369 : : else
6370 : 0 : emit_group_load (to_rtx, value, TREE_TYPE (from),
6371 : 0 : int_size_in_bytes (TREE_TYPE (from)));
6372 : : }
6373 : 7566 : else if (GET_CODE (value) == PARALLEL)
6374 : 1420 : emit_group_store (to_rtx, value, TREE_TYPE (from),
6375 : 2840 : int_size_in_bytes (TREE_TYPE (from)));
6376 : 6146 : else if (GET_MODE (to_rtx) == BLKmode)
6377 : : {
6378 : : /* Handle calls that return BLKmode values in registers. */
6379 : 276 : if (REG_P (value))
6380 : 276 : copy_blkmode_from_reg (to_rtx, value, TREE_TYPE (from));
6381 : : else
6382 : 0 : emit_block_move (to_rtx, value, expr_size (from), BLOCK_OP_NORMAL);
6383 : : }
6384 : : else
6385 : : {
6386 : 5870 : if (POINTER_TYPE_P (TREE_TYPE (to)))
6387 : 0 : value = convert_memory_address_addr_space
6388 : 0 : (as_a <scalar_int_mode> (GET_MODE (to_rtx)), value,
6389 : 0 : TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to))));
6390 : :
6391 : 5870 : emit_move_insn (to_rtx, value);
6392 : : }
6393 : :
6394 : 7566 : preserve_temp_slots (to_rtx);
6395 : 7566 : pop_temp_slots ();
6396 : 7566 : return;
6397 : : }
6398 : :
6399 : : /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
6400 : 12559333 : to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
6401 : :
6402 : : /* Don't move directly into a return register. */
6403 : 12559333 : if (TREE_CODE (to) == RESULT_DECL
6404 : 15694 : && (REG_P (to_rtx) || GET_CODE (to_rtx) == PARALLEL))
6405 : : {
6406 : 32 : rtx temp;
6407 : :
6408 : 32 : push_temp_slots ();
6409 : :
6410 : : /* If the source is itself a return value, it still is in a pseudo at
6411 : : this point so we can move it back to the return register directly. */
6412 : 32 : if (REG_P (to_rtx)
6413 : 32 : && TYPE_MODE (TREE_TYPE (from)) == BLKmode
6414 : 32 : && TREE_CODE (from) != CALL_EXPR)
6415 : 0 : temp = copy_blkmode_to_reg (GET_MODE (to_rtx), from);
6416 : : else
6417 : 32 : temp = expand_expr (from, NULL_RTX, GET_MODE (to_rtx), EXPAND_NORMAL);
6418 : :
6419 : : /* Handle calls that return values in multiple non-contiguous locations.
6420 : : The Irix 6 ABI has examples of this. */
6421 : 32 : if (GET_CODE (to_rtx) == PARALLEL)
6422 : : {
6423 : 0 : if (GET_CODE (temp) == PARALLEL)
6424 : 0 : emit_group_move (to_rtx, temp);
6425 : : else
6426 : 0 : emit_group_load (to_rtx, temp, TREE_TYPE (from),
6427 : 0 : int_size_in_bytes (TREE_TYPE (from)));
6428 : : }
6429 : 32 : else if (temp)
6430 : 32 : emit_move_insn (to_rtx, temp);
6431 : :
6432 : 32 : preserve_temp_slots (to_rtx);
6433 : 32 : pop_temp_slots ();
6434 : 32 : return;
6435 : : }
6436 : :
6437 : : /* In case we are returning the contents of an object which overlaps
6438 : : the place the value is being stored, use a safe function when copying
6439 : : a value through a pointer into a structure value return block. */
6440 : 12559301 : if (TREE_CODE (to) == RESULT_DECL
6441 : 15662 : && TREE_CODE (from) == INDIRECT_REF
6442 : 0 : && ADDR_SPACE_GENERIC_P
6443 : : (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from, 0)))))
6444 : 0 : && refs_may_alias_p (to, from)
6445 : 0 : && cfun->returns_struct
6446 : 12559301 : && !cfun->returns_pcc_struct)
6447 : : {
6448 : 0 : rtx from_rtx, size;
6449 : :
6450 : 0 : push_temp_slots ();
6451 : 0 : size = expr_size (from);
6452 : 0 : from_rtx = expand_normal (from);
6453 : :
6454 : 0 : emit_block_move_via_libcall (XEXP (to_rtx, 0), XEXP (from_rtx, 0), size);
6455 : :
6456 : 0 : preserve_temp_slots (to_rtx);
6457 : 0 : pop_temp_slots ();
6458 : 0 : return;
6459 : : }
6460 : :
6461 : : /* Compute FROM and store the value in the rtx we got. */
6462 : :
6463 : 12559301 : push_temp_slots ();
6464 : 12559301 : result = store_expr (from, to_rtx, 0, nontemporal, false);
6465 : 12559301 : preserve_temp_slots (result);
6466 : 12559301 : pop_temp_slots ();
6467 : 12559301 : return;
6468 : : }
6469 : :
6470 : : /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
6471 : : succeeded, false otherwise. */
6472 : :
6473 : : bool
6474 : 17 : emit_storent_insn (rtx to, rtx from)
6475 : : {
6476 : 17 : class expand_operand ops[2];
6477 : 17 : machine_mode mode = GET_MODE (to);
6478 : 17 : enum insn_code code = optab_handler (storent_optab, mode);
6479 : :
6480 : 17 : if (code == CODE_FOR_nothing)
6481 : : return false;
6482 : :
6483 : 17 : create_fixed_operand (&ops[0], to);
6484 : 17 : create_input_operand (&ops[1], from, mode);
6485 : 17 : return maybe_expand_insn (code, 2, ops);
6486 : : }
6487 : :
6488 : : /* Helper function for store_expr storing of STRING_CST. */
6489 : :
6490 : : static rtx
6491 : 87743 : string_cst_read_str (void *data, void *, HOST_WIDE_INT offset,
6492 : : fixed_size_mode mode)
6493 : : {
6494 : 87743 : tree str = (tree) data;
6495 : :
6496 : 87743 : gcc_assert (offset >= 0);
6497 : 87743 : if (offset >= TREE_STRING_LENGTH (str))
6498 : 3724 : return const0_rtx;
6499 : :
6500 : 84019 : if ((unsigned HOST_WIDE_INT) offset + GET_MODE_SIZE (mode)
6501 : 84019 : > (unsigned HOST_WIDE_INT) TREE_STRING_LENGTH (str))
6502 : : {
6503 : 2709 : char *p = XALLOCAVEC (char, GET_MODE_SIZE (mode));
6504 : 2709 : size_t l = TREE_STRING_LENGTH (str) - offset;
6505 : 2709 : memcpy (p, TREE_STRING_POINTER (str) + offset, l);
6506 : 2709 : memset (p + l, '\0', GET_MODE_SIZE (mode) - l);
6507 : 2709 : return c_readstr (p, mode, false);
6508 : : }
6509 : :
6510 : 81310 : return c_readstr (TREE_STRING_POINTER (str) + offset, mode, false);
6511 : : }
6512 : :
6513 : : /* Generate code for computing expression EXP,
6514 : : and storing the value into TARGET.
6515 : :
6516 : : If the mode is BLKmode then we may return TARGET itself.
6517 : : It turns out that in BLKmode it doesn't cause a problem.
6518 : : because C has no operators that could combine two different
6519 : : assignments into the same BLKmode object with different values
6520 : : with no sequence point. Will other languages need this to
6521 : : be more thorough?
6522 : :
6523 : : If CALL_PARAM_P is nonzero, this is a store into a call param on the
6524 : : stack, and block moves may need to be treated specially.
6525 : :
6526 : : If NONTEMPORAL is true, try using a nontemporal store instruction.
6527 : :
6528 : : If REVERSE is true, the store is to be done in reverse order. */
6529 : :
6530 : : rtx
6531 : 16231570 : store_expr (tree exp, rtx target, int call_param_p,
6532 : : bool nontemporal, bool reverse)
6533 : : {
6534 : 16231570 : rtx temp;
6535 : 16231570 : rtx alt_rtl = NULL_RTX;
6536 : 16231570 : location_t loc = curr_insn_location ();
6537 : 16231570 : bool shortened_string_cst = false;
6538 : :
6539 : 16231570 : if (VOID_TYPE_P (TREE_TYPE (exp)))
6540 : : {
6541 : : /* C++ can generate ?: expressions with a throw expression in one
6542 : : branch and an rvalue in the other. Here, we resolve attempts to
6543 : : store the throw expression's nonexistent result. */
6544 : 0 : gcc_assert (!call_param_p);
6545 : 0 : expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL);
6546 : 0 : return NULL_RTX;
6547 : : }
6548 : 16231570 : if (TREE_CODE (exp) == COMPOUND_EXPR)
6549 : : {
6550 : : /* Perform first part of compound expression, then assign from second
6551 : : part. */
6552 : 0 : expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
6553 : : call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
6554 : 0 : return store_expr (TREE_OPERAND (exp, 1), target,
6555 : 0 : call_param_p, nontemporal, reverse);
6556 : : }
6557 : 16231570 : else if (TREE_CODE (exp) == COND_EXPR && GET_MODE (target) == BLKmode)
6558 : : {
6559 : : /* For conditional expression, get safe form of the target. Then
6560 : : test the condition, doing the appropriate assignment on either
6561 : : side. This avoids the creation of unnecessary temporaries.
6562 : : For non-BLKmode, it is more efficient not to do this. */
6563 : :
6564 : 0 : rtx_code_label *lab1 = gen_label_rtx (), *lab2 = gen_label_rtx ();
6565 : :
6566 : 0 : do_pending_stack_adjust ();
6567 : 0 : NO_DEFER_POP;
6568 : 0 : jumpifnot (TREE_OPERAND (exp, 0), lab1,
6569 : : profile_probability::uninitialized ());
6570 : 0 : store_expr (TREE_OPERAND (exp, 1), target, call_param_p,
6571 : : nontemporal, reverse);
6572 : 0 : emit_jump_insn (targetm.gen_jump (lab2));
6573 : 0 : emit_barrier ();
6574 : 0 : emit_label (lab1);
6575 : 0 : store_expr (TREE_OPERAND (exp, 2), target, call_param_p,
6576 : : nontemporal, reverse);
6577 : 0 : emit_label (lab2);
6578 : 0 : OK_DEFER_POP;
6579 : :
6580 : 0 : return NULL_RTX;
6581 : : }
6582 : 16231570 : else if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target))
6583 : : /* If this is a scalar in a register that is stored in a wider mode
6584 : : than the declared mode, compute the result into its declared mode
6585 : : and then convert to the wider mode. Our value is the computed
6586 : : expression. */
6587 : : {
6588 : 7 : rtx inner_target = 0;
6589 : 7 : scalar_int_mode outer_mode = subreg_unpromoted_mode (target);
6590 : 7 : scalar_int_mode inner_mode = subreg_promoted_mode (target);
6591 : :
6592 : : /* We can do the conversion inside EXP, which will often result
6593 : : in some optimizations. Do the conversion in two steps: first
6594 : : change the signedness, if needed, then the extend. But don't
6595 : : do this if the type of EXP is a subtype of something else
6596 : : since then the conversion might involve more than just
6597 : : converting modes. */
6598 : 14 : if (INTEGRAL_TYPE_P (TREE_TYPE (exp))
6599 : 0 : && TREE_TYPE (TREE_TYPE (exp)) == 0
6600 : 7 : && GET_MODE_PRECISION (outer_mode)
6601 : 0 : == TYPE_PRECISION (TREE_TYPE (exp)))
6602 : : {
6603 : 0 : if (!SUBREG_CHECK_PROMOTED_SIGN (target,
6604 : : TYPE_UNSIGNED (TREE_TYPE (exp))))
6605 : : {
6606 : : /* Some types, e.g. Fortran's logical*4, won't have a signed
6607 : : version, so use the mode instead. */
6608 : 0 : tree ntype
6609 : : = (signed_or_unsigned_type_for
6610 : 0 : (SUBREG_PROMOTED_SIGN (target), TREE_TYPE (exp)));
6611 : 0 : if (ntype == NULL)
6612 : 0 : ntype = lang_hooks.types.type_for_mode
6613 : 0 : (TYPE_MODE (TREE_TYPE (exp)),
6614 : 0 : SUBREG_PROMOTED_SIGN (target));
6615 : :
6616 : 0 : exp = fold_convert_loc (loc, ntype, exp);
6617 : : }
6618 : :
6619 : 0 : exp = fold_convert_loc (loc, lang_hooks.types.type_for_mode
6620 : 0 : (inner_mode, SUBREG_PROMOTED_SIGN (target)),
6621 : : exp);
6622 : :
6623 : 0 : inner_target = SUBREG_REG (target);
6624 : : }
6625 : :
6626 : 7 : temp = expand_expr (exp, inner_target, VOIDmode,
6627 : : call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
6628 : :
6629 : :
6630 : : /* If TEMP is a VOIDmode constant, use convert_modes to make
6631 : : sure that we properly convert it. */
6632 : 7 : if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode)
6633 : : {
6634 : 0 : temp = convert_modes (outer_mode, TYPE_MODE (TREE_TYPE (exp)),
6635 : 0 : temp, SUBREG_PROMOTED_SIGN (target));
6636 : 0 : temp = convert_modes (inner_mode, outer_mode, temp,
6637 : 0 : SUBREG_PROMOTED_SIGN (target));
6638 : 0 : }
6639 : 7 : else if (!SCALAR_INT_MODE_P (GET_MODE (temp)))
6640 : 0 : temp = convert_modes (outer_mode, TYPE_MODE (TREE_TYPE (exp)),
6641 : 0 : temp, SUBREG_PROMOTED_SIGN (target));
6642 : :
6643 : 21 : convert_move (SUBREG_REG (target), temp,
6644 : 7 : SUBREG_PROMOTED_SIGN (target));
6645 : :
6646 : 7 : return NULL_RTX;
6647 : : }
6648 : 16231563 : else if ((TREE_CODE (exp) == STRING_CST
6649 : 16222434 : || (TREE_CODE (exp) == MEM_REF
6650 : 1122954 : && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
6651 : 317933 : && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
6652 : : == STRING_CST
6653 : 4699 : && integer_zerop (TREE_OPERAND (exp, 1))))
6654 : 13828 : && !nontemporal && !call_param_p
6655 : 16245391 : && MEM_P (target))
6656 : : {
6657 : : /* Optimize initialization of an array with a STRING_CST. */
6658 : 13822 : HOST_WIDE_INT exp_len, str_copy_len;
6659 : 13822 : rtx dest_mem;
6660 : 13822 : tree str = TREE_CODE (exp) == STRING_CST
6661 : 13822 : ? exp : TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6662 : :
6663 : 13822 : exp_len = int_expr_size (exp);
6664 : 13822 : if (exp_len <= 0)
6665 : 0 : goto normal_expr;
6666 : :
6667 : 13822 : if (TREE_STRING_LENGTH (str) <= 0)
6668 : 0 : goto normal_expr;
6669 : :
6670 : 27644 : if (can_store_by_pieces (exp_len, string_cst_read_str, (void *) str,
6671 : 13822 : MEM_ALIGN (target), false))
6672 : : {
6673 : 13626 : store_by_pieces (target, exp_len, string_cst_read_str, (void *) str,
6674 : 13626 : MEM_ALIGN (target), false, RETURN_BEGIN);
6675 : 13626 : return NULL_RTX;
6676 : : }
6677 : :
6678 : 196 : str_copy_len = TREE_STRING_LENGTH (str);
6679 : :
6680 : : /* Trailing NUL bytes in EXP will be handled by the call to
6681 : : clear_storage, which is more efficient than copying them from
6682 : : the STRING_CST, so trim those from STR_COPY_LEN. */
6683 : 478 : while (str_copy_len)
6684 : : {
6685 : 435 : if (TREE_STRING_POINTER (str)[str_copy_len - 1])
6686 : : break;
6687 : 282 : str_copy_len--;
6688 : : }
6689 : :
6690 : 196 : if ((STORE_MAX_PIECES & (STORE_MAX_PIECES - 1)) == 0)
6691 : : {
6692 : 196 : str_copy_len += STORE_MAX_PIECES - 1;
6693 : 196 : str_copy_len &= ~(STORE_MAX_PIECES - 1);
6694 : : }
6695 : 196 : if (str_copy_len >= exp_len)
6696 : 139 : goto normal_expr;
6697 : :
6698 : 114 : if (!can_store_by_pieces (str_copy_len, string_cst_read_str,
6699 : 57 : (void *) str, MEM_ALIGN (target), false))
6700 : 11 : goto normal_expr;
6701 : :
6702 : 46 : dest_mem = store_by_pieces (target, str_copy_len, string_cst_read_str,
6703 : 46 : (void *) str, MEM_ALIGN (target), false,
6704 : : RETURN_END);
6705 : 46 : clear_storage (adjust_address_1 (dest_mem, BLKmode, 0, 1, 1, 0,
6706 : 46 : exp_len - str_copy_len),
6707 : : GEN_INT (exp_len - str_copy_len), BLOCK_OP_NORMAL);
6708 : 46 : return NULL_RTX;
6709 : : }
6710 : : else
6711 : : {
6712 : 16217891 : rtx tmp_target;
6713 : :
6714 : 16217891 : normal_expr:
6715 : : /* If we want to use a nontemporal or a reverse order store, force the
6716 : : value into a register first. */
6717 : 16217891 : tmp_target = nontemporal || reverse ? NULL_RTX : target;
6718 : 16217891 : tree rexp = exp;
6719 : 16217891 : if (TREE_CODE (exp) == STRING_CST
6720 : 64 : && tmp_target == target
6721 : 64 : && GET_MODE (target) == BLKmode
6722 : 16217955 : && TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
6723 : : {
6724 : 64 : rtx size = expr_size (exp);
6725 : 64 : if (CONST_INT_P (size)
6726 : 64 : && size != const0_rtx
6727 : 128 : && (UINTVAL (size)
6728 : 64 : > ((unsigned HOST_WIDE_INT) TREE_STRING_LENGTH (exp) + 32)))
6729 : : {
6730 : : /* If the STRING_CST has much larger array type than
6731 : : TREE_STRING_LENGTH, only emit the TREE_STRING_LENGTH part of
6732 : : it into the rodata section as the code later on will use
6733 : : memset zero for the remainder anyway. See PR95052. */
6734 : 2 : tmp_target = NULL_RTX;
6735 : 2 : rexp = copy_node (exp);
6736 : 2 : tree index
6737 : 2 : = build_index_type (size_int (TREE_STRING_LENGTH (exp) - 1));
6738 : 2 : TREE_TYPE (rexp) = build_array_type (TREE_TYPE (TREE_TYPE (exp)),
6739 : : index);
6740 : 2 : shortened_string_cst = true;
6741 : : }
6742 : : }
6743 : 32435782 : temp = expand_expr_real (rexp, tmp_target, GET_MODE (target),
6744 : : (call_param_p
6745 : : ? EXPAND_STACK_PARM : EXPAND_NORMAL),
6746 : : &alt_rtl, false);
6747 : 16217891 : if (shortened_string_cst)
6748 : : {
6749 : 2 : gcc_assert (MEM_P (temp));
6750 : 2 : temp = change_address (temp, BLKmode, NULL_RTX);
6751 : : }
6752 : : }
6753 : :
6754 : : /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
6755 : : the same as that of TARGET, adjust the constant. This is needed, for
6756 : : example, in case it is a CONST_DOUBLE or CONST_WIDE_INT and we want
6757 : : only a word-sized value. */
6758 : 3200613 : if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode
6759 : 2256987 : && TREE_CODE (exp) != ERROR_MARK
6760 : 18474878 : && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
6761 : : {
6762 : 0 : gcc_assert (!shortened_string_cst);
6763 : 0 : if (GET_MODE_CLASS (GET_MODE (target))
6764 : 0 : != GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (exp)))
6765 : 0 : && known_eq (GET_MODE_BITSIZE (GET_MODE (target)),
6766 : : GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp)))))
6767 : : {
6768 : 0 : rtx t = simplify_gen_subreg (GET_MODE (target), temp,
6769 : 0 : TYPE_MODE (TREE_TYPE (exp)), 0);
6770 : 0 : if (t)
6771 : 0 : temp = t;
6772 : : }
6773 : 0 : if (GET_MODE (temp) == VOIDmode)
6774 : 0 : temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
6775 : 0 : temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
6776 : : }
6777 : :
6778 : : /* If value was not generated in the target, store it there.
6779 : : Convert the value to TARGET's type first if necessary and emit the
6780 : : pending incrementations that have been queued when expanding EXP.
6781 : : Note that we cannot emit the whole queue blindly because this will
6782 : : effectively disable the POST_INC optimization later.
6783 : :
6784 : : If TEMP and TARGET compare equal according to rtx_equal_p, but
6785 : : one or both of them are volatile memory refs, we have to distinguish
6786 : : two cases:
6787 : : - expand_expr has used TARGET. In this case, we must not generate
6788 : : another copy. This can be detected by TARGET being equal according
6789 : : to == .
6790 : : - expand_expr has not used TARGET - that means that the source just
6791 : : happens to have the same RTX form. Since temp will have been created
6792 : : by expand_expr, it will compare unequal according to == .
6793 : : We must generate a copy in this case, to reach the correct number
6794 : : of volatile memory references. */
6795 : :
6796 : 16217891 : if ((! rtx_equal_p (temp, target)
6797 : 2889981 : || (temp != target && (side_effects_p (temp)
6798 : 43644 : || side_effects_p (target)
6799 : 43644 : || (MEM_P (temp)
6800 : 43428 : && !mems_same_for_tbaa_p (temp, target)))))
6801 : 13327914 : && TREE_CODE (exp) != ERROR_MARK
6802 : : /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
6803 : : but TARGET is not valid memory reference, TEMP will differ
6804 : : from TARGET although it is really the same location. */
6805 : 13327914 : && !(alt_rtl
6806 : 1980981 : && rtx_equal_p (alt_rtl, target)
6807 : 1 : && !side_effects_p (alt_rtl)
6808 : 0 : && !side_effects_p (target))
6809 : : /* If there's nothing to copy, don't bother. Don't call
6810 : : expr_size unless necessary, because some front-ends (C++)
6811 : : expr_size-hook must not be given objects that are not
6812 : : supposed to be bit-copied or bit-initialized. */
6813 : 29545805 : && expr_size (exp) != const0_rtx)
6814 : : {
6815 : 13327914 : if (GET_MODE (temp) != GET_MODE (target) && GET_MODE (temp) != VOIDmode)
6816 : : {
6817 : 1398 : gcc_assert (!shortened_string_cst);
6818 : 1398 : if (GET_MODE (target) == BLKmode)
6819 : : {
6820 : : /* Handle calls that return BLKmode values in registers. */
6821 : 2 : if (REG_P (temp) && TREE_CODE (exp) == CALL_EXPR)
6822 : 2 : copy_blkmode_from_reg (target, temp, TREE_TYPE (exp));
6823 : : else
6824 : 0 : store_bit_field (target,
6825 : 0 : rtx_to_poly_int64 (expr_size (exp))
6826 : 0 : * BITS_PER_UNIT,
6827 : 0 : 0, 0, 0, GET_MODE (temp), temp, reverse,
6828 : : false);
6829 : : }
6830 : : else
6831 : 1396 : convert_move (target, temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
6832 : : }
6833 : :
6834 : 13326516 : else if (GET_MODE (temp) == BLKmode && TREE_CODE (exp) == STRING_CST)
6835 : : {
6836 : : /* Handle copying a string constant into an array. The string
6837 : : constant may be shorter than the array. So copy just the string's
6838 : : actual length, and clear the rest. First get the size of the data
6839 : : type of the string, which is actually the size of the target. */
6840 : 64 : rtx size = expr_size (exp);
6841 : :
6842 : 64 : if (CONST_INT_P (size)
6843 : 64 : && INTVAL (size) < TREE_STRING_LENGTH (exp))
6844 : 0 : emit_block_move (target, temp, size,
6845 : : (call_param_p
6846 : : ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
6847 : : else
6848 : : {
6849 : 64 : machine_mode pointer_mode
6850 : 64 : = targetm.addr_space.pointer_mode (MEM_ADDR_SPACE (target));
6851 : 64 : machine_mode address_mode = get_address_mode (target);
6852 : :
6853 : : /* Compute the size of the data to copy from the string. */
6854 : 64 : tree copy_size
6855 : 64 : = size_binop_loc (loc, MIN_EXPR,
6856 : : make_tree (sizetype, size),
6857 : 64 : size_int (TREE_STRING_LENGTH (exp)));
6858 : 64 : rtx copy_size_rtx
6859 : 64 : = expand_expr (copy_size, NULL_RTX, VOIDmode,
6860 : : (call_param_p
6861 : : ? EXPAND_STACK_PARM : EXPAND_NORMAL));
6862 : 64 : rtx_code_label *label = 0;
6863 : :
6864 : : /* Copy that much. */
6865 : 192 : copy_size_rtx = convert_to_mode (pointer_mode, copy_size_rtx,
6866 : 64 : TYPE_UNSIGNED (sizetype));
6867 : 128 : emit_block_move (target, temp, copy_size_rtx,
6868 : : (call_param_p
6869 : : ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
6870 : :
6871 : : /* Figure out how much is left in TARGET that we have to clear.
6872 : : Do all calculations in pointer_mode. */
6873 : 64 : poly_int64 const_copy_size;
6874 : 64 : if (poly_int_rtx_p (copy_size_rtx, &const_copy_size))
6875 : : {
6876 : 64 : size = plus_constant (address_mode, size, -const_copy_size);
6877 : 64 : target = adjust_address (target, BLKmode, const_copy_size);
6878 : : }
6879 : : else
6880 : : {
6881 : 0 : size = expand_binop (TYPE_MODE (sizetype), sub_optab, size,
6882 : : copy_size_rtx, NULL_RTX, 0,
6883 : : OPTAB_LIB_WIDEN);
6884 : :
6885 : 0 : if (GET_MODE (copy_size_rtx) != address_mode)
6886 : 0 : copy_size_rtx = convert_to_mode (address_mode,
6887 : : copy_size_rtx,
6888 : 0 : TYPE_UNSIGNED (sizetype));
6889 : :
6890 : 0 : target = offset_address (target, copy_size_rtx,
6891 : : highest_pow2_factor (copy_size));
6892 : 0 : label = gen_label_rtx ();
6893 : 0 : emit_cmp_and_jump_insns (size, const0_rtx, LT, NULL_RTX,
6894 : 0 : GET_MODE (size), 0, label);
6895 : : }
6896 : :
6897 : 64 : if (size != const0_rtx)
6898 : 2 : clear_storage (target, size, BLOCK_OP_NORMAL);
6899 : :
6900 : 64 : if (label)
6901 : 0 : emit_label (label);
6902 : : }
6903 : : }
6904 : 13326452 : else if (shortened_string_cst)
6905 : 0 : gcc_unreachable ();
6906 : : /* Handle calls that return values in multiple non-contiguous locations.
6907 : : The Irix 6 ABI has examples of this. */
6908 : 13326452 : else if (GET_CODE (target) == PARALLEL)
6909 : : {
6910 : 0 : if (GET_CODE (temp) == PARALLEL)
6911 : 0 : emit_group_move (target, temp);
6912 : : else
6913 : 0 : emit_group_load (target, temp, TREE_TYPE (exp),
6914 : 0 : int_size_in_bytes (TREE_TYPE (exp)));
6915 : : }
6916 : 13326452 : else if (GET_CODE (temp) == PARALLEL)
6917 : 0 : emit_group_store (target, temp, TREE_TYPE (exp),
6918 : 0 : int_size_in_bytes (TREE_TYPE (exp)));
6919 : 13326452 : else if (GET_MODE (temp) == BLKmode)
6920 : 659894 : emit_block_move (target, temp, expr_size (exp),
6921 : : (call_param_p
6922 : : ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
6923 : : /* If we emit a nontemporal store, there is nothing else to do. */
6924 : 12996505 : else if (nontemporal && emit_storent_insn (target, temp))
6925 : : ;
6926 : : else
6927 : : {
6928 : 12996488 : if (reverse)
6929 : 712 : temp = flip_storage_order (GET_MODE (target), temp);
6930 : 12996488 : temp = force_operand (temp, target);
6931 : 12996488 : if (temp != target)
6932 : 12994977 : emit_move_insn (target, temp);
6933 : : }
6934 : : }
6935 : : else
6936 : 2889977 : gcc_assert (!shortened_string_cst);
6937 : :
6938 : : return NULL_RTX;
6939 : : }
6940 : :
6941 : : /* Return true if field F of structure TYPE is a flexible array. */
6942 : :
6943 : : static bool
6944 : 3490434 : flexible_array_member_p (const_tree f, const_tree type)
6945 : : {
6946 : 3490434 : const_tree tf;
6947 : :
6948 : 3490434 : tf = TREE_TYPE (f);
6949 : 3490434 : return (DECL_CHAIN (f) == NULL
6950 : 1052308 : && TREE_CODE (tf) == ARRAY_TYPE
6951 : 2431 : && TYPE_DOMAIN (tf)
6952 : 2431 : && TYPE_MIN_VALUE (TYPE_DOMAIN (tf))
6953 : 2431 : && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf)))
6954 : 2431 : && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf))
6955 : 3490461 : && int_size_in_bytes (type) >= 0);
6956 : : }
6957 : :
6958 : : /* If FOR_CTOR_P, return the number of top-level elements that a constructor
6959 : : must have in order for it to completely initialize a value of type TYPE.
6960 : : Return -1 if the number isn't known.
6961 : :
6962 : : If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
6963 : :
6964 : : static HOST_WIDE_INT
6965 : 3310625 : count_type_elements (const_tree type, bool for_ctor_p)
6966 : : {
6967 : 3310625 : switch (TREE_CODE (type))
6968 : : {
6969 : 140057 : case ARRAY_TYPE:
6970 : 140057 : {
6971 : 140057 : tree nelts;
6972 : :
6973 : 140057 : nelts = array_type_nelts (type);
6974 : 140057 : if (nelts && tree_fits_uhwi_p (nelts))
6975 : : {
6976 : 140045 : unsigned HOST_WIDE_INT n;
6977 : :
6978 : 140045 : n = tree_to_uhwi (nelts) + 1;
6979 : 140045 : if (n == 0 || for_ctor_p)
6980 : 139290 : return n;
6981 : : else
6982 : 755 : return n * count_type_elements (TREE_TYPE (type), false);
6983 : : }
6984 : 12 : return for_ctor_p ? -1 : 1;
6985 : : }
6986 : :
6987 : 1584576 : case RECORD_TYPE:
6988 : 1584576 : {
6989 : 1584576 : unsigned HOST_WIDE_INT n;
6990 : 1584576 : tree f;
6991 : :
6992 : 1584576 : n = 0;
6993 : 10815490 : for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
6994 : 9230914 : if (TREE_CODE (f) == FIELD_DECL)
6995 : : {
6996 : 3935631 : if (!for_ctor_p)
6997 : 445197 : n += count_type_elements (TREE_TYPE (f), false);
6998 : 3490434 : else if (!flexible_array_member_p (f, type))
6999 : : /* Don't count flexible arrays, which are not supposed
7000 : : to be initialized. */
7001 : 3490407 : n += 1;
7002 : : }
7003 : :
7004 : 1584576 : return n;
7005 : : }
7006 : :
7007 : 1505 : case UNION_TYPE:
7008 : 1505 : case QUAL_UNION_TYPE:
7009 : 1505 : {
7010 : 1505 : tree f;
7011 : 1505 : HOST_WIDE_INT n, m;
7012 : :
7013 : 1505 : gcc_assert (!for_ctor_p);
7014 : : /* Estimate the number of scalars in each field and pick the
7015 : : maximum. Other estimates would do instead; the idea is simply
7016 : : to make sure that the estimate is not sensitive to the ordering
7017 : : of the fields. */
7018 : 1505 : n = 1;
7019 : 28188 : for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
7020 : 26683 : if (TREE_CODE (f) == FIELD_DECL)
7021 : : {
7022 : 24092 : m = count_type_elements (TREE_TYPE (f), false);
7023 : : /* If the field doesn't span the whole union, add an extra
7024 : : scalar for the rest. */
7025 : 24092 : if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f)),
7026 : 24092 : TYPE_SIZE (type)) != 1)
7027 : 15502 : m++;
7028 : 24092 : if (n < m)
7029 : 26683 : n = m;
7030 : : }
7031 : : return n;
7032 : : }
7033 : :
7034 : : case COMPLEX_TYPE:
7035 : : return 2;
7036 : :
7037 : 301 : case VECTOR_TYPE:
7038 : 301 : {
7039 : 301 : unsigned HOST_WIDE_INT nelts;
7040 : 301 : if (TYPE_VECTOR_SUBPARTS (type).is_constant (&nelts))
7041 : 301 : return nelts;
7042 : : else
7043 : : return -1;
7044 : : }
7045 : :
7046 : : case INTEGER_TYPE:
7047 : : case REAL_TYPE:
7048 : : case FIXED_POINT_TYPE:
7049 : : case ENUMERAL_TYPE:
7050 : : case BOOLEAN_TYPE:
7051 : : case POINTER_TYPE:
7052 : : case OFFSET_TYPE:
7053 : : case REFERENCE_TYPE:
7054 : : case NULLPTR_TYPE:
7055 : : case OPAQUE_TYPE:
7056 : : case BITINT_TYPE:
7057 : : return 1;
7058 : :
7059 : 0 : case ERROR_MARK:
7060 : 0 : return 0;
7061 : :
7062 : 0 : case VOID_TYPE:
7063 : 0 : case METHOD_TYPE:
7064 : 0 : case FUNCTION_TYPE:
7065 : 0 : case LANG_TYPE:
7066 : 0 : default:
7067 : 0 : gcc_unreachable ();
7068 : : }
7069 : : }
7070 : :
7071 : : /* Helper for categorize_ctor_elements. Identical interface. */
7072 : :
7073 : : static bool
7074 : 1366885 : categorize_ctor_elements_1 (const_tree ctor, HOST_WIDE_INT *p_nz_elts,
7075 : : HOST_WIDE_INT *p_unique_nz_elts,
7076 : : HOST_WIDE_INT *p_init_elts, bool *p_complete)
7077 : : {
7078 : 1366885 : unsigned HOST_WIDE_INT idx;
7079 : 1366885 : HOST_WIDE_INT nz_elts, unique_nz_elts, init_elts, num_fields;
7080 : 1366885 : tree value, purpose, elt_type;
7081 : :
7082 : : /* Whether CTOR is a valid constant initializer, in accordance with what
7083 : : initializer_constant_valid_p does. If inferred from the constructor
7084 : : elements, true until proven otherwise. */
7085 : 1366885 : bool const_from_elts_p = constructor_static_from_elts_p (ctor);
7086 : 1366885 : bool const_p = const_from_elts_p ? true : TREE_STATIC (ctor);
7087 : :
7088 : 1366885 : nz_elts = 0;
7089 : 1366885 : unique_nz_elts = 0;
7090 : 1366885 : init_elts = 0;
7091 : 1366885 : num_fields = 0;
7092 : 1366885 : elt_type = NULL_TREE;
7093 : :
7094 : 5177073 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), idx, purpose, value)
7095 : : {
7096 : 3810188 : HOST_WIDE_INT mult = 1;
7097 : :
7098 : 3810188 : if (purpose && TREE_CODE (purpose) == RANGE_EXPR)
7099 : : {
7100 : 615 : tree lo_index = TREE_OPERAND (purpose, 0);
7101 : 615 : tree hi_index = TREE_OPERAND (purpose, 1);
7102 : :
7103 : 615 : if (tree_fits_uhwi_p (lo_index) && tree_fits_uhwi_p (hi_index))
7104 : 615 : mult = (tree_to_uhwi (hi_index)
7105 : 615 : - tree_to_uhwi (lo_index) + 1);
7106 : : }
7107 : 3810188 : num_fields += mult;
7108 : 3810188 : elt_type = TREE_TYPE (value);
7109 : :
7110 : 3810188 : switch (TREE_CODE (value))
7111 : : {
7112 : 465355 : case CONSTRUCTOR:
7113 : 465355 : {
7114 : 465355 : HOST_WIDE_INT nz = 0, unz = 0, ic = 0;
7115 : :
7116 : 465355 : bool const_elt_p = categorize_ctor_elements_1 (value, &nz, &unz,
7117 : : &ic, p_complete);
7118 : :
7119 : 465355 : nz_elts += mult * nz;
7120 : 465355 : unique_nz_elts += unz;
7121 : 465355 : init_elts += mult * ic;
7122 : :
7123 : 465355 : if (const_from_elts_p && const_p)
7124 : 253309 : const_p = const_elt_p;
7125 : : }
7126 : 465355 : break;
7127 : :
7128 : 1999312 : case INTEGER_CST:
7129 : 1999312 : case REAL_CST:
7130 : 1999312 : case FIXED_CST:
7131 : 1999312 : if (!initializer_zerop (value))
7132 : : {
7133 : 1490552 : nz_elts += mult;
7134 : 1490552 : unique_nz_elts++;
7135 : : }
7136 : 1999312 : init_elts += mult;
7137 : 1999312 : break;
7138 : :
7139 : 6334 : case STRING_CST:
7140 : 6334 : nz_elts += mult * TREE_STRING_LENGTH (value);
7141 : 6334 : unique_nz_elts += TREE_STRING_LENGTH (value);
7142 : 6334 : init_elts += mult * TREE_STRING_LENGTH (value);
7143 : 6334 : break;
7144 : :
7145 : 2480 : case COMPLEX_CST:
7146 : 2480 : if (!initializer_zerop (TREE_REALPART (value)))
7147 : : {
7148 : 2066 : nz_elts += mult;
7149 : 2066 : unique_nz_elts++;
7150 : : }
7151 : 2480 : if (!initializer_zerop (TREE_IMAGPART (value)))
7152 : : {
7153 : 1988 : nz_elts += mult;
7154 : 1988 : unique_nz_elts++;
7155 : : }
7156 : 2480 : init_elts += 2 * mult;
7157 : 2480 : break;
7158 : :
7159 : 766 : case VECTOR_CST:
7160 : 766 : {
7161 : : /* We can only construct constant-length vectors using
7162 : : CONSTRUCTOR. */
7163 : 766 : unsigned int nunits = VECTOR_CST_NELTS (value).to_constant ();
7164 : 5197 : for (unsigned int i = 0; i < nunits; ++i)
7165 : : {
7166 : 4431 : tree v = VECTOR_CST_ELT (value, i);
7167 : 4431 : if (!initializer_zerop (v))
7168 : : {
7169 : 2019 : nz_elts += mult;
7170 : 2019 : unique_nz_elts++;
7171 : : }
7172 : 4431 : init_elts += mult;
7173 : : }
7174 : : }
7175 : : break;
7176 : :
7177 : 1335941 : default:
7178 : 1335941 : {
7179 : 1335941 : HOST_WIDE_INT tc = count_type_elements (elt_type, false);
7180 : 1335941 : nz_elts += mult * tc;
7181 : 1335941 : unique_nz_elts += tc;
7182 : 1335941 : init_elts += mult * tc;
7183 : :
7184 : 1335941 : if (const_from_elts_p && const_p)
7185 : 504792 : const_p
7186 : 504792 : = initializer_constant_valid_p (value,
7187 : : elt_type,
7188 : 504792 : TYPE_REVERSE_STORAGE_ORDER
7189 : : (TREE_TYPE (ctor)))
7190 : : != NULL_TREE;
7191 : : }
7192 : : break;
7193 : : }
7194 : : }
7195 : :
7196 : 1366885 : if (*p_complete && !complete_ctor_at_level_p (TREE_TYPE (ctor),
7197 : : num_fields, elt_type))
7198 : 145693 : *p_complete = false;
7199 : :
7200 : 1366885 : *p_nz_elts += nz_elts;
7201 : 1366885 : *p_unique_nz_elts += unique_nz_elts;
7202 : 1366885 : *p_init_elts += init_elts;
7203 : :
7204 : 1366885 : return const_p;
7205 : : }
7206 : :
7207 : : /* Examine CTOR to discover:
7208 : : * how many scalar fields are set to nonzero values,
7209 : : and place it in *P_NZ_ELTS;
7210 : : * the same, but counting RANGE_EXPRs as multiplier of 1 instead of
7211 : : high - low + 1 (this can be useful for callers to determine ctors
7212 : : that could be cheaply initialized with - perhaps nested - loops
7213 : : compared to copied from huge read-only data),
7214 : : and place it in *P_UNIQUE_NZ_ELTS;
7215 : : * how many scalar fields in total are in CTOR,
7216 : : and place it in *P_ELT_COUNT.
7217 : : * whether the constructor is complete -- in the sense that every
7218 : : meaningful byte is explicitly given a value --
7219 : : and place it in *P_COMPLETE.
7220 : :
7221 : : Return whether or not CTOR is a valid static constant initializer, the same
7222 : : as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
7223 : :
7224 : : bool
7225 : 901530 : categorize_ctor_elements (const_tree ctor, HOST_WIDE_INT *p_nz_elts,
7226 : : HOST_WIDE_INT *p_unique_nz_elts,
7227 : : HOST_WIDE_INT *p_init_elts, bool *p_complete)
7228 : : {
7229 : 901530 : *p_nz_elts = 0;
7230 : 901530 : *p_unique_nz_elts = 0;
7231 : 901530 : *p_init_elts = 0;
7232 : 901530 : *p_complete = true;
7233 : :
7234 : 901530 : return categorize_ctor_elements_1 (ctor, p_nz_elts, p_unique_nz_elts,
7235 : 901530 : p_init_elts, p_complete);
7236 : : }
7237 : :
7238 : : /* Return true if constructor CTOR is simple enough to be materialized
7239 : : in an integer mode register. Limit the size to WORDS words, which
7240 : : is 1 by default. */
7241 : :
7242 : : bool
7243 : 19496 : immediate_const_ctor_p (const_tree ctor, unsigned int words)
7244 : : {
7245 : : /* Allow function to be called with a VAR_DECL's DECL_INITIAL. */
7246 : 19496 : if (!ctor || TREE_CODE (ctor) != CONSTRUCTOR)
7247 : : return false;
7248 : :
7249 : 2065 : return TREE_CONSTANT (ctor)
7250 : 2065 : && !TREE_ADDRESSABLE (ctor)
7251 : 2065 : && CONSTRUCTOR_NELTS (ctor)
7252 : 2050 : && TREE_CODE (TREE_TYPE (ctor)) != ARRAY_TYPE
7253 : 732 : && int_expr_size (ctor) <= words * UNITS_PER_WORD
7254 : 2176 : && initializer_constant_valid_for_bitfield_p (ctor);
7255 : : }
7256 : :
7257 : : /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
7258 : : of which had type LAST_TYPE. Each element was itself a complete
7259 : : initializer, in the sense that every meaningful byte was explicitly
7260 : : given a value. Return true if the same is true for the constructor
7261 : : as a whole. */
7262 : :
7263 : : bool
7264 : 1512656 : complete_ctor_at_level_p (const_tree type, HOST_WIDE_INT num_elts,
7265 : : const_tree last_type)
7266 : : {
7267 : 1512656 : if (TREE_CODE (type) == UNION_TYPE
7268 : 1512656 : || TREE_CODE (type) == QUAL_UNION_TYPE)
7269 : : {
7270 : 8016 : if (num_elts == 0)
7271 : : return false;
7272 : :
7273 : 7994 : gcc_assert (num_elts == 1 && last_type);
7274 : :
7275 : : /* ??? We could look at each element of the union, and find the
7276 : : largest element. Which would avoid comparing the size of the
7277 : : initialized element against any tail padding in the union.
7278 : : Doesn't seem worth the effort... */
7279 : 7994 : return simple_cst_equal (TYPE_SIZE (type), TYPE_SIZE (last_type)) == 1;
7280 : : }
7281 : :
7282 : 1504640 : return count_type_elements (type, true) == num_elts;
7283 : : }
7284 : :
7285 : : /* Return true if EXP contains mostly (3/4) zeros. */
7286 : :
7287 : : static bool
7288 : 398447 : mostly_zeros_p (const_tree exp)
7289 : : {
7290 : 398447 : if (TREE_CODE (exp) == CONSTRUCTOR)
7291 : : {
7292 : 92 : HOST_WIDE_INT nz_elts, unz_elts, init_elts;
7293 : 92 : bool complete_p;
7294 : :
7295 : 92 : categorize_ctor_elements (exp, &nz_elts, &unz_elts, &init_elts,
7296 : : &complete_p);
7297 : 92 : return !complete_p || nz_elts < init_elts / 4;
7298 : : }
7299 : :
7300 : 398355 : return initializer_zerop (exp);
7301 : : }
7302 : :
7303 : : /* Return true if EXP contains all zeros. */
7304 : :
7305 : : static bool
7306 : 2395 : all_zeros_p (const_tree exp)
7307 : : {
7308 : 2395 : if (TREE_CODE (exp) == CONSTRUCTOR)
7309 : : {
7310 : 2395 : HOST_WIDE_INT nz_elts, unz_elts, init_elts;
7311 : 2395 : bool complete_p;
7312 : :
7313 : 2395 : categorize_ctor_elements (exp, &nz_elts, &unz_elts, &init_elts,
7314 : : &complete_p);
7315 : 2395 : return nz_elts == 0;
7316 : : }
7317 : :
7318 : 0 : return initializer_zerop (exp);
7319 : : }
7320 : :
7321 : : /* Helper function for store_constructor.
7322 : : TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
7323 : : CLEARED is as for store_constructor.
7324 : : ALIAS_SET is the alias set to use for any stores.
7325 : : If REVERSE is true, the store is to be done in reverse order.
7326 : :
7327 : : This provides a recursive shortcut back to store_constructor when it isn't
7328 : : necessary to go through store_field. This is so that we can pass through
7329 : : the cleared field to let store_constructor know that we may not have to
7330 : : clear a substructure if the outer structure has already been cleared. */
7331 : :
7332 : : static void
7333 : 27064 : store_constructor_field (rtx target, poly_uint64 bitsize, poly_int64 bitpos,
7334 : : poly_uint64 bitregion_start,
7335 : : poly_uint64 bitregion_end,
7336 : : machine_mode mode,
7337 : : tree exp, int cleared,
7338 : : alias_set_type alias_set, bool reverse)
7339 : : {
7340 : 27064 : poly_int64 bytepos;
7341 : 27064 : poly_uint64 bytesize;
7342 : 27064 : if (TREE_CODE (exp) == CONSTRUCTOR
7343 : : /* We can only call store_constructor recursively if the size and
7344 : : bit position are on a byte boundary. */
7345 : 14 : && multiple_p (bitpos, BITS_PER_UNIT, &bytepos)
7346 : 14 : && maybe_ne (bitsize, 0U)
7347 : 27064 : && multiple_p (bitsize, BITS_PER_UNIT, &bytesize)
7348 : : /* If we have a nonzero bitpos for a register target, then we just
7349 : : let store_field do the bitfield handling. This is unlikely to
7350 : : generate unnecessary clear instructions anyways. */
7351 : 27078 : && (known_eq (bitpos, 0) || MEM_P (target)))
7352 : : {
7353 : 14 : if (MEM_P (target))
7354 : : {
7355 : 14 : machine_mode target_mode = GET_MODE (target);
7356 : 14 : if (target_mode != BLKmode
7357 : 14 : && !multiple_p (bitpos, GET_MODE_ALIGNMENT (target_mode)))
7358 : : target_mode = BLKmode;
7359 : 14 : target = adjust_address (target, target_mode, bytepos);
7360 : : }
7361 : :
7362 : :
7363 : : /* Update the alias set, if required. */
7364 : 14 : if (MEM_P (target) && ! MEM_KEEP_ALIAS_SET_P (target)
7365 : 28 : && MEM_ALIAS_SET (target) != 0)
7366 : : {
7367 : 14 : target = copy_rtx (target);
7368 : 14 : set_mem_alias_set (target, alias_set);
7369 : : }
7370 : :
7371 : 14 : store_constructor (exp, target, cleared, bytesize, reverse);
7372 : : }
7373 : : else
7374 : 27050 : store_field (target, bitsize, bitpos, bitregion_start, bitregion_end, mode,
7375 : : exp, alias_set, false, reverse);
7376 : 27064 : }
7377 : :
7378 : :
7379 : : /* Returns the number of FIELD_DECLs in TYPE. */
7380 : :
7381 : : static int
7382 : 51295 : fields_length (const_tree type)
7383 : : {
7384 : 51295 : tree t = TYPE_FIELDS (type);
7385 : 51295 : int count = 0;
7386 : :
7387 : 388947 : for (; t; t = DECL_CHAIN (t))
7388 : 337652 : if (TREE_CODE (t) == FIELD_DECL)
7389 : 240830 : ++count;
7390 : :
7391 : 51295 : return count;
7392 : : }
7393 : :
7394 : :
7395 : : /* Store the value of constructor EXP into the rtx TARGET.
7396 : : TARGET is either a REG or a MEM; we know it cannot conflict, since
7397 : : safe_from_p has been called.
7398 : : CLEARED is true if TARGET is known to have been zero'd.
7399 : : SIZE is the number of bytes of TARGET we are allowed to modify: this
7400 : : may not be the same as the size of EXP if we are assigning to a field
7401 : : which has been packed to exclude padding bits.
7402 : : If REVERSE is true, the store is to be done in reverse order. */
7403 : :
7404 : : void
7405 : 251783 : store_constructor (tree exp, rtx target, int cleared, poly_int64 size,
7406 : : bool reverse)
7407 : : {
7408 : 251783 : tree type = TREE_TYPE (exp);
7409 : 251783 : HOST_WIDE_INT exp_size = int_size_in_bytes (type);
7410 : 251783 : poly_int64 bitregion_end = known_gt (size, 0) ? size * BITS_PER_UNIT - 1 : 0;
7411 : :
7412 : 251783 : switch (TREE_CODE (type))
7413 : : {
7414 : 52925 : case RECORD_TYPE:
7415 : 52925 : case UNION_TYPE:
7416 : 52925 : case QUAL_UNION_TYPE:
7417 : 52925 : {
7418 : 52925 : unsigned HOST_WIDE_INT idx;
7419 : 52925 : tree field, value;
7420 : :
7421 : : /* The storage order is specified for every aggregate type. */
7422 : 52925 : reverse = TYPE_REVERSE_STORAGE_ORDER (type);
7423 : :
7424 : : /* If size is zero or the target is already cleared, do nothing. */
7425 : 52925 : if (known_eq (size, 0) || cleared)
7426 : : cleared = 1;
7427 : : /* We either clear the aggregate or indicate the value is dead. */
7428 : 52925 : else if ((TREE_CODE (type) == UNION_TYPE
7429 : 52925 : || TREE_CODE (type) == QUAL_UNION_TYPE)
7430 : 52925 : && ! CONSTRUCTOR_ELTS (exp))
7431 : : /* If the constructor is empty, clear the union. */
7432 : : {
7433 : 1426 : clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
7434 : 1426 : cleared = 1;
7435 : : }
7436 : :
7437 : : /* If we are building a static constructor into a register,
7438 : : set the initial value as zero so we can fold the value into
7439 : : a constant. But if more than one register is involved,
7440 : : this probably loses. */
7441 : 2187 : else if (REG_P (target) && TREE_STATIC (exp)
7442 : 52019 : && known_le (GET_MODE_SIZE (GET_MODE (target)),
7443 : : REGMODE_NATURAL_SIZE (GET_MODE (target))))
7444 : : {
7445 : 204 : emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
7446 : 204 : cleared = 1;
7447 : : }
7448 : :
7449 : : /* If the constructor has fewer fields than the structure or
7450 : : if we are initializing the structure to mostly zeros, clear
7451 : : the whole structure first. Don't do this if TARGET is a
7452 : : register whose mode size isn't equal to SIZE since
7453 : : clear_storage can't handle this case. */
7454 : 51295 : else if (known_size_p (size)
7455 : 51295 : && (((int) CONSTRUCTOR_NELTS (exp) != fields_length (type))
7456 : 54 : || mostly_zeros_p (exp))
7457 : 102536 : && (!REG_P (target)
7458 : 4016 : || known_eq (GET_MODE_SIZE (GET_MODE (target)), size)))
7459 : : {
7460 : 51241 : clear_storage (target, gen_int_mode (size, Pmode),
7461 : : BLOCK_OP_NORMAL);
7462 : 51241 : cleared = 1;
7463 : : }
7464 : :
7465 : 52925 : if (REG_P (target) && !cleared)
7466 : 2 : emit_clobber (target);
7467 : :
7468 : : /* Store each element of the constructor into the
7469 : : corresponding field of TARGET. */
7470 : 53192 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, field, value)
7471 : : {
7472 : 267 : machine_mode mode;
7473 : 267 : HOST_WIDE_INT bitsize;
7474 : 267 : HOST_WIDE_INT bitpos = 0;
7475 : 267 : tree offset;
7476 : 267 : rtx to_rtx = target;
7477 : :
7478 : : /* Just ignore missing fields. We cleared the whole
7479 : : structure, above, if any fields are missing. */
7480 : 267 : if (field == 0)
7481 : 78 : continue;
7482 : :
7483 : 267 : if (cleared && initializer_zerop (value))
7484 : 78 : continue;
7485 : :
7486 : 189 : if (tree_fits_uhwi_p (DECL_SIZE (field)))
7487 : 189 : bitsize = tree_to_uhwi (DECL_SIZE (field));
7488 : : else
7489 : 0 : gcc_unreachable ();
7490 : :
7491 : 189 : mode = DECL_MODE (field);
7492 : 189 : if (DECL_BIT_FIELD (field))
7493 : 74 : mode = VOIDmode;
7494 : :
7495 : 189 : offset = DECL_FIELD_OFFSET (field);
7496 : 189 : if (tree_fits_shwi_p (offset)
7497 : 189 : && tree_fits_shwi_p (bit_position (field)))
7498 : : {
7499 : 189 : bitpos = int_bit_position (field);
7500 : 189 : offset = NULL_TREE;
7501 : : }
7502 : : else
7503 : 0 : gcc_unreachable ();
7504 : :
7505 : : /* If this initializes a field that is smaller than a
7506 : : word, at the start of a word, try to widen it to a full
7507 : : word. This special case allows us to output C++ member
7508 : : function initializations in a form that the optimizers
7509 : : can understand. */
7510 : 189 : if (WORD_REGISTER_OPERATIONS
7511 : : && REG_P (target)
7512 : : && bitsize < BITS_PER_WORD
7513 : : && bitpos % BITS_PER_WORD == 0
7514 : : && GET_MODE_CLASS (mode) == MODE_INT
7515 : : && TREE_CODE (value) == INTEGER_CST
7516 : : && exp_size >= 0
7517 : : && bitpos + BITS_PER_WORD <= exp_size * BITS_PER_UNIT)
7518 : : {
7519 : : type = TREE_TYPE (value);
7520 : :
7521 : : if (TYPE_PRECISION (type) < BITS_PER_WORD)
7522 : : {
7523 : : type = lang_hooks.types.type_for_mode
7524 : : (word_mode, TYPE_UNSIGNED (type));
7525 : : value = fold_convert (type, value);
7526 : : /* Make sure the bits beyond the original bitsize are zero
7527 : : so that we can correctly avoid extra zeroing stores in
7528 : : later constructor elements. */
7529 : : tree bitsize_mask
7530 : : = wide_int_to_tree (type, wi::mask (bitsize, false,
7531 : : BITS_PER_WORD));
7532 : : value = fold_build2 (BIT_AND_EXPR, type, value, bitsize_mask);
7533 : : }
7534 : :
7535 : : if (BYTES_BIG_ENDIAN)
7536 : : value
7537 : : = fold_build2 (LSHIFT_EXPR, type, value,
7538 : : build_int_cst (type,
7539 : : BITS_PER_WORD - bitsize));
7540 : : bitsize = BITS_PER_WORD;
7541 : : mode = word_mode;
7542 : : }
7543 : :
7544 : 66 : if (MEM_P (to_rtx) && !MEM_KEEP_ALIAS_SET_P (to_rtx)
7545 : 255 : && DECL_NONADDRESSABLE_P (field))
7546 : : {
7547 : 0 : to_rtx = copy_rtx (to_rtx);
7548 : 0 : MEM_KEEP_ALIAS_SET_P (to_rtx) = 1;
7549 : : }
7550 : :
7551 : 378 : store_constructor_field (to_rtx, bitsize, bitpos,
7552 : 378 : 0, bitregion_end, mode,
7553 : : value, cleared,
7554 : 189 : get_alias_set (TREE_TYPE (field)),
7555 : : reverse);
7556 : : }
7557 : : break;
7558 : : }
7559 : 34803 : case ARRAY_TYPE:
7560 : 34803 : {
7561 : 34803 : tree value, index;
7562 : 34803 : unsigned HOST_WIDE_INT i;
7563 : 34803 : bool need_to_clear;
7564 : 34803 : tree domain;
7565 : 34803 : tree elttype = TREE_TYPE (type);
7566 : 34803 : bool const_bounds_p;
7567 : 34803 : HOST_WIDE_INT minelt = 0;
7568 : 34803 : HOST_WIDE_INT maxelt = 0;
7569 : :
7570 : : /* The storage order is specified for every aggregate type. */
7571 : 34803 : reverse = TYPE_REVERSE_STORAGE_ORDER (type);
7572 : :
7573 : 34803 : domain = TYPE_DOMAIN (type);
7574 : 34803 : const_bounds_p = (TYPE_MIN_VALUE (domain)
7575 : 34803 : && TYPE_MAX_VALUE (domain)
7576 : 34803 : && tree_fits_shwi_p (TYPE_MIN_VALUE (domain))
7577 : 69606 : && tree_fits_shwi_p (TYPE_MAX_VALUE (domain)));
7578 : :
7579 : : /* If we have constant bounds for the range of the type, get them. */
7580 : 34803 : if (const_bounds_p)
7581 : : {
7582 : 34803 : minelt = tree_to_shwi (TYPE_MIN_VALUE (domain));
7583 : 34803 : maxelt = tree_to_shwi (TYPE_MAX_VALUE (domain));
7584 : : }
7585 : :
7586 : : /* If the constructor has fewer elements than the array, clear
7587 : : the whole array first. Similarly if this is static
7588 : : constructor of a non-BLKmode object. */
7589 : 34803 : if (cleared)
7590 : : need_to_clear = false;
7591 : 34803 : else if (REG_P (target) && TREE_STATIC (exp))
7592 : : need_to_clear = true;
7593 : : else
7594 : : {
7595 : 34797 : unsigned HOST_WIDE_INT idx;
7596 : 34797 : HOST_WIDE_INT count = 0, zero_count = 0;
7597 : 34797 : need_to_clear = ! const_bounds_p;
7598 : :
7599 : : /* This loop is a more accurate version of the loop in
7600 : : mostly_zeros_p (it handles RANGE_EXPR in an index). It
7601 : : is also needed to check for missing elements. */
7602 : 34845 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, index, value)
7603 : : {
7604 : 48 : HOST_WIDE_INT this_node_count;
7605 : :
7606 : 48 : if (need_to_clear)
7607 : : break;
7608 : :
7609 : 48 : if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
7610 : : {
7611 : 0 : tree lo_index = TREE_OPERAND (index, 0);
7612 : 0 : tree hi_index = TREE_OPERAND (index, 1);
7613 : :
7614 : 0 : if (! tree_fits_uhwi_p (lo_index)
7615 : 0 : || ! tree_fits_uhwi_p (hi_index))
7616 : : {
7617 : : need_to_clear = true;
7618 : : break;
7619 : : }
7620 : :
7621 : 0 : this_node_count = (tree_to_uhwi (hi_index)
7622 : 0 : - tree_to_uhwi (lo_index) + 1);
7623 : 0 : }
7624 : : else
7625 : : this_node_count = 1;
7626 : :
7627 : 48 : count += this_node_count;
7628 : 48 : if (mostly_zeros_p (value))
7629 : 0 : zero_count += this_node_count;
7630 : : }
7631 : :
7632 : : /* Clear the entire array first if there are any missing
7633 : : elements, or if the incidence of zero elements is >=
7634 : : 75%. */
7635 : 34797 : if (! need_to_clear
7636 : 34797 : && (count < maxelt - minelt + 1
7637 : 6 : || 4 * zero_count >= 3 * count))
7638 : 34791 : need_to_clear = true;
7639 : : }
7640 : :
7641 : 34803 : if (need_to_clear && maybe_gt (size, 0))
7642 : : {
7643 : 34797 : if (REG_P (target))
7644 : 971 : emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
7645 : : else
7646 : 33826 : clear_storage (target, gen_int_mode (size, Pmode),
7647 : : BLOCK_OP_NORMAL);
7648 : : cleared = 1;
7649 : : }
7650 : :
7651 : 6 : if (!cleared && REG_P (target))
7652 : : /* Inform later passes that the old value is dead. */
7653 : 0 : emit_clobber (target);
7654 : :
7655 : : /* Store each element of the constructor into the
7656 : : corresponding element of TARGET, determined by counting the
7657 : : elements. */
7658 : 34851 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), i, index, value)
7659 : : {
7660 : 48 : machine_mode mode;
7661 : 48 : poly_int64 bitsize;
7662 : 48 : HOST_WIDE_INT bitpos;
7663 : 48 : rtx xtarget = target;
7664 : :
7665 : 48 : if (cleared && initializer_zerop (value))
7666 : 0 : continue;
7667 : :
7668 : 48 : mode = TYPE_MODE (elttype);
7669 : 48 : if (mode != BLKmode)
7670 : 96 : bitsize = GET_MODE_BITSIZE (mode);
7671 : 0 : else if (!poly_int_tree_p (TYPE_SIZE (elttype), &bitsize))
7672 : 0 : bitsize = -1;
7673 : :
7674 : 48 : if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
7675 : : {
7676 : 0 : tree lo_index = TREE_OPERAND (index, 0);
7677 : 0 : tree hi_index = TREE_OPERAND (index, 1);
7678 : 0 : rtx index_r, pos_rtx;
7679 : 0 : HOST_WIDE_INT lo, hi, count;
7680 : 0 : tree position;
7681 : :
7682 : : /* If the range is constant and "small", unroll the loop. */
7683 : 0 : if (const_bounds_p
7684 : 0 : && tree_fits_shwi_p (lo_index)
7685 : 0 : && tree_fits_shwi_p (hi_index)
7686 : 0 : && (lo = tree_to_shwi (lo_index),
7687 : 0 : hi = tree_to_shwi (hi_index),
7688 : 0 : count = hi - lo + 1,
7689 : 0 : (!MEM_P (target)
7690 : 0 : || count <= 2
7691 : 0 : || (tree_fits_uhwi_p (TYPE_SIZE (elttype))
7692 : 0 : && (tree_to_uhwi (TYPE_SIZE (elttype)) * count
7693 : : <= 40 * 8)))))
7694 : : {
7695 : 0 : lo -= minelt; hi -= minelt;
7696 : 0 : for (; lo <= hi; lo++)
7697 : : {
7698 : 0 : bitpos = lo * tree_to_shwi (TYPE_SIZE (elttype));
7699 : :
7700 : 0 : if (MEM_P (target)
7701 : 0 : && !MEM_KEEP_ALIAS_SET_P (target)
7702 : 0 : && TREE_CODE (type) == ARRAY_TYPE
7703 : 0 : && TYPE_NONALIASED_COMPONENT (type))
7704 : : {
7705 : 0 : target = copy_rtx (target);
7706 : 0 : MEM_KEEP_ALIAS_SET_P (target) = 1;
7707 : : }
7708 : :
7709 : 0 : store_constructor_field
7710 : 0 : (target, bitsize, bitpos, 0, bitregion_end,
7711 : : mode, value, cleared,
7712 : : get_alias_set (elttype), reverse);
7713 : : }
7714 : : }
7715 : : else
7716 : : {
7717 : 0 : rtx_code_label *loop_start = gen_label_rtx ();
7718 : 0 : rtx_code_label *loop_end = gen_label_rtx ();
7719 : 0 : tree exit_cond;
7720 : :
7721 : 0 : expand_normal (hi_index);
7722 : :
7723 : 0 : index = build_decl (EXPR_LOCATION (exp),
7724 : : VAR_DECL, NULL_TREE, domain);
7725 : 0 : index_r = gen_reg_rtx (promote_decl_mode (index, NULL));
7726 : 0 : SET_DECL_RTL (index, index_r);
7727 : 0 : store_expr (lo_index, index_r, 0, false, reverse);
7728 : :
7729 : : /* Build the head of the loop. */
7730 : 0 : do_pending_stack_adjust ();
7731 : 0 : emit_label (loop_start);
7732 : :
7733 : : /* Assign value to element index. */
7734 : 0 : position =
7735 : 0 : fold_convert (ssizetype,
7736 : : fold_build2 (MINUS_EXPR,
7737 : : TREE_TYPE (index),
7738 : : index,
7739 : : TYPE_MIN_VALUE (domain)));
7740 : :
7741 : 0 : position =
7742 : 0 : size_binop (MULT_EXPR, position,
7743 : : fold_convert (ssizetype,
7744 : : TYPE_SIZE_UNIT (elttype)));
7745 : :
7746 : 0 : pos_rtx = expand_normal (position);
7747 : 0 : xtarget = offset_address (target, pos_rtx,
7748 : : highest_pow2_factor (position));
7749 : 0 : xtarget = adjust_address (xtarget, mode, 0);
7750 : 0 : if (TREE_CODE (value) == CONSTRUCTOR)
7751 : 0 : store_constructor (value, xtarget, cleared,
7752 : : exact_div (bitsize, BITS_PER_UNIT),
7753 : : reverse);
7754 : : else
7755 : 0 : store_expr (value, xtarget, 0, false, reverse);
7756 : :
7757 : : /* Generate a conditional jump to exit the loop. */
7758 : 0 : exit_cond = build2 (LT_EXPR, integer_type_node,
7759 : : index, hi_index);
7760 : 0 : jumpif (exit_cond, loop_end,
7761 : : profile_probability::uninitialized ());
7762 : :
7763 : : /* Update the loop counter, and jump to the head of
7764 : : the loop. */
7765 : 0 : expand_assignment (index,
7766 : 0 : build2 (PLUS_EXPR, TREE_TYPE (index),
7767 : : index, integer_one_node),
7768 : : false);
7769 : :
7770 : 0 : emit_jump (loop_start);
7771 : :
7772 : : /* Build the end of the loop. */
7773 : 0 : emit_label (loop_end);
7774 : : }
7775 : : }
7776 : 48 : else if ((index != 0 && ! tree_fits_shwi_p (index))
7777 : 48 : || ! tree_fits_uhwi_p (TYPE_SIZE (elttype)))
7778 : : {
7779 : 0 : tree position;
7780 : :
7781 : 0 : if (index == 0)
7782 : 0 : index = ssize_int (1);
7783 : :
7784 : 0 : if (minelt)
7785 : 0 : index = fold_convert (ssizetype,
7786 : : fold_build2 (MINUS_EXPR,
7787 : : TREE_TYPE (index),
7788 : : index,
7789 : : TYPE_MIN_VALUE (domain)));
7790 : :
7791 : 0 : position =
7792 : 0 : size_binop (MULT_EXPR, index,
7793 : : fold_convert (ssizetype,
7794 : : TYPE_SIZE_UNIT (elttype)));
7795 : 0 : xtarget = offset_address (target,
7796 : : expand_normal (position),
7797 : : highest_pow2_factor (position));
7798 : 0 : xtarget = adjust_address (xtarget, mode, 0);
7799 : 0 : store_expr (value, xtarget, 0, false, reverse);
7800 : : }
7801 : : else
7802 : : {
7803 : 48 : if (index != 0)
7804 : 96 : bitpos = ((tree_to_shwi (index) - minelt)
7805 : 48 : * tree_to_uhwi (TYPE_SIZE (elttype)));
7806 : : else
7807 : 0 : bitpos = (i * tree_to_uhwi (TYPE_SIZE (elttype)));
7808 : :
7809 : 48 : if (MEM_P (target) && !MEM_KEEP_ALIAS_SET_P (target)
7810 : 48 : && TREE_CODE (type) == ARRAY_TYPE
7811 : 96 : && TYPE_NONALIASED_COMPONENT (type))
7812 : : {
7813 : 0 : target = copy_rtx (target);
7814 : 0 : MEM_KEEP_ALIAS_SET_P (target) = 1;
7815 : : }
7816 : 48 : store_constructor_field (target, bitsize, bitpos, 0,
7817 : : bitregion_end, mode, value,
7818 : : cleared, get_alias_set (elttype),
7819 : : reverse);
7820 : : }
7821 : : }
7822 : : break;
7823 : : }
7824 : :
7825 : 164055 : case VECTOR_TYPE:
7826 : 164055 : {
7827 : 164055 : unsigned HOST_WIDE_INT idx;
7828 : 164055 : constructor_elt *ce;
7829 : 164055 : int i;
7830 : 164055 : bool need_to_clear;
7831 : 164055 : insn_code icode = CODE_FOR_nothing;
7832 : 164055 : tree elt;
7833 : 164055 : tree elttype = TREE_TYPE (type);
7834 : 164055 : int elt_size = vector_element_bits (type);
7835 : 164055 : machine_mode eltmode = TYPE_MODE (elttype);
7836 : 164055 : HOST_WIDE_INT bitsize;
7837 : 164055 : HOST_WIDE_INT bitpos;
7838 : 164055 : rtvec vector = NULL;
7839 : 164055 : poly_uint64 n_elts;
7840 : 164055 : unsigned HOST_WIDE_INT const_n_elts;
7841 : 164055 : alias_set_type alias;
7842 : 164055 : bool vec_vec_init_p = false;
7843 : 164055 : machine_mode mode = GET_MODE (target);
7844 : :
7845 : 164055 : gcc_assert (eltmode != BLKmode);
7846 : :
7847 : : /* Try using vec_duplicate_optab for uniform vectors. */
7848 : 328110 : if (!TREE_SIDE_EFFECTS (exp)
7849 : 164055 : && VECTOR_MODE_P (mode)
7850 : 160970 : && eltmode == GET_MODE_INNER (mode)
7851 : 160970 : && ((icode = optab_handler (vec_duplicate_optab, mode))
7852 : : != CODE_FOR_nothing)
7853 : 102370 : && (elt = uniform_vector_p (exp))
7854 : 184752 : && !VECTOR_TYPE_P (TREE_TYPE (elt)))
7855 : : {
7856 : 20697 : class expand_operand ops[2];
7857 : 20697 : create_output_operand (&ops[0], target, mode);
7858 : 20697 : create_input_operand (&ops[1], expand_normal (elt), eltmode);
7859 : 20697 : expand_insn (icode, 2, ops);
7860 : 20697 : if (!rtx_equal_p (target, ops[0].value))
7861 : 0 : emit_move_insn (target, ops[0].value);
7862 : 20697 : break;
7863 : : }
7864 : : /* Use sign-extension for uniform boolean vectors with
7865 : : integer modes and single-bit mask entries.
7866 : : Effectively "vec_duplicate" for bitmasks. */
7867 : 143358 : if (elt_size == 1
7868 : 202 : && !TREE_SIDE_EFFECTS (exp)
7869 : 202 : && VECTOR_BOOLEAN_TYPE_P (type)
7870 : 202 : && SCALAR_INT_MODE_P (TYPE_MODE (type))
7871 : 202 : && (elt = uniform_vector_p (exp))
7872 : 143559 : && !VECTOR_TYPE_P (TREE_TYPE (elt)))
7873 : : {
7874 : 201 : rtx op0 = force_reg (TYPE_MODE (TREE_TYPE (elt)),
7875 : : expand_normal (elt));
7876 : 201 : rtx tmp = gen_reg_rtx (mode);
7877 : 201 : convert_move (tmp, op0, 0);
7878 : :
7879 : : /* Ensure no excess bits are set.
7880 : : GCN needs this for nunits < 64.
7881 : : x86 needs this for nunits < 8. */
7882 : 201 : auto nunits = TYPE_VECTOR_SUBPARTS (type).to_constant ();
7883 : 201 : if (maybe_ne (GET_MODE_PRECISION (mode), nunits))
7884 : 13 : tmp = expand_binop (mode, and_optab, tmp,
7885 : 13 : GEN_INT ((HOST_WIDE_INT_1U << nunits) - 1),
7886 : : target, true, OPTAB_WIDEN);
7887 : 201 : if (tmp != target)
7888 : 188 : emit_move_insn (target, tmp);
7889 : 201 : break;
7890 : : }
7891 : :
7892 : 143157 : n_elts = TYPE_VECTOR_SUBPARTS (type);
7893 : 143157 : if (REG_P (target)
7894 : 140439 : && VECTOR_MODE_P (mode)
7895 : 283430 : && n_elts.is_constant (&const_n_elts))
7896 : : {
7897 : 140273 : machine_mode emode = eltmode;
7898 : 140273 : bool vector_typed_elts_p = false;
7899 : :
7900 : 140273 : if (CONSTRUCTOR_NELTS (exp)
7901 : 140273 : && (TREE_CODE (TREE_TYPE (CONSTRUCTOR_ELT (exp, 0)->value))
7902 : : == VECTOR_TYPE))
7903 : : {
7904 : 443 : tree etype = TREE_TYPE (CONSTRUCTOR_ELT (exp, 0)->value);
7905 : 443 : gcc_assert (known_eq (CONSTRUCTOR_NELTS (exp)
7906 : : * TYPE_VECTOR_SUBPARTS (etype),
7907 : : n_elts));
7908 : 443 : emode = TYPE_MODE (etype);
7909 : : vector_typed_elts_p = true;
7910 : : }
7911 : 140273 : icode = convert_optab_handler (vec_init_optab, mode, emode);
7912 : 140273 : if (icode != CODE_FOR_nothing)
7913 : : {
7914 : 139024 : unsigned int n = const_n_elts;
7915 : :
7916 : 139024 : if (vector_typed_elts_p)
7917 : : {
7918 : 412 : n = CONSTRUCTOR_NELTS (exp);
7919 : 412 : vec_vec_init_p = true;
7920 : : }
7921 : 139024 : vector = rtvec_alloc (n);
7922 : 503826 : for (unsigned int k = 0; k < n; k++)
7923 : 364802 : RTVEC_ELT (vector, k) = CONST0_RTX (emode);
7924 : : }
7925 : : }
7926 : :
7927 : : /* Compute the size of the elements in the CTOR. It differs
7928 : : from the size of the vector type elements only when the
7929 : : CTOR elements are vectors themselves. */
7930 : 143157 : tree val_type = (CONSTRUCTOR_NELTS (exp) != 0
7931 : 143157 : ? TREE_TYPE (CONSTRUCTOR_ELT (exp, 0)->value)
7932 : 143157 : : elttype);
7933 : 143157 : if (VECTOR_TYPE_P (val_type))
7934 : 755 : bitsize = tree_to_uhwi (TYPE_SIZE (val_type));
7935 : : else
7936 : 142402 : bitsize = elt_size;
7937 : :
7938 : : /* If the constructor has fewer elements than the vector,
7939 : : clear the whole array first. Similarly if this is static
7940 : : constructor of a non-BLKmode object. */
7941 : 143157 : if (cleared)
7942 : : need_to_clear = false;
7943 : 143157 : else if (REG_P (target) && TREE_STATIC (exp))
7944 : : need_to_clear = true;
7945 : : else
7946 : : {
7947 : 143157 : unsigned HOST_WIDE_INT count = 0, zero_count = 0;
7948 : 143157 : tree value;
7949 : :
7950 : 541464 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
7951 : : {
7952 : 398307 : int n_elts_here = bitsize / elt_size;
7953 : 398307 : count += n_elts_here;
7954 : 398307 : if (mostly_zeros_p (value))
7955 : 14273 : zero_count += n_elts_here;
7956 : : }
7957 : :
7958 : : /* Clear the entire vector first if there are any missing elements,
7959 : : or if the incidence of zero elements is >= 75%. */
7960 : 286314 : need_to_clear = (maybe_lt (count, n_elts)
7961 : 143157 : || 4 * zero_count >= 3 * count);
7962 : : }
7963 : :
7964 : 143157 : if (need_to_clear && maybe_gt (size, 0) && !vector)
7965 : : {
7966 : 749 : if (REG_P (target))
7967 : 4 : emit_move_insn (target, CONST0_RTX (mode));
7968 : : else
7969 : 745 : clear_storage (target, gen_int_mode (size, Pmode),
7970 : : BLOCK_OP_NORMAL);
7971 : : cleared = 1;
7972 : : }
7973 : :
7974 : : /* Inform later passes that the old value is dead. */
7975 : 143157 : if (!cleared && !vector && REG_P (target) && maybe_gt (n_elts, 1u))
7976 : : {
7977 : 826 : emit_move_insn (target, CONST0_RTX (mode));
7978 : 826 : cleared = 1;
7979 : : }
7980 : :
7981 : 143157 : if (MEM_P (target))
7982 : 2718 : alias = MEM_ALIAS_SET (target);
7983 : : else
7984 : 140439 : alias = get_alias_set (elttype);
7985 : :
7986 : : /* Store each element of the constructor into the corresponding
7987 : : element of TARGET, determined by counting the elements. */
7988 : 143157 : for (idx = 0, i = 0;
7989 : 541464 : vec_safe_iterate (CONSTRUCTOR_ELTS (exp), idx, &ce);
7990 : 398307 : idx++, i += bitsize / elt_size)
7991 : : {
7992 : 398307 : HOST_WIDE_INT eltpos;
7993 : 398307 : tree value = ce->value;
7994 : :
7995 : 398307 : if (cleared && initializer_zerop (value))
7996 : 7625 : continue;
7997 : :
7998 : 390682 : if (ce->index)
7999 : 41118 : eltpos = tree_to_uhwi (ce->index);
8000 : : else
8001 : 349564 : eltpos = i;
8002 : :
8003 : 390682 : if (vector)
8004 : : {
8005 : 363855 : if (vec_vec_init_p)
8006 : : {
8007 : 834 : gcc_assert (ce->index == NULL_TREE);
8008 : 834 : gcc_assert (TREE_CODE (TREE_TYPE (value)) == VECTOR_TYPE);
8009 : 834 : eltpos = idx;
8010 : : }
8011 : : else
8012 : 363021 : gcc_assert (TREE_CODE (TREE_TYPE (value)) != VECTOR_TYPE);
8013 : 363855 : RTVEC_ELT (vector, eltpos) = expand_normal (value);
8014 : : }
8015 : : else
8016 : : {
8017 : 26827 : machine_mode value_mode
8018 : 26827 : = (TREE_CODE (TREE_TYPE (value)) == VECTOR_TYPE
8019 : 26827 : ? TYPE_MODE (TREE_TYPE (value)) : eltmode);
8020 : 26827 : bitpos = eltpos * elt_size;
8021 : 26827 : store_constructor_field (target, bitsize, bitpos, 0,
8022 : : bitregion_end, value_mode,
8023 : : value, cleared, alias, reverse);
8024 : : }
8025 : : }
8026 : :
8027 : 143157 : if (vector)
8028 : 139024 : emit_insn (GEN_FCN (icode) (target,
8029 : : gen_rtx_PARALLEL (mode, vector)));
8030 : : break;
8031 : : }
8032 : :
8033 : 0 : default:
8034 : 0 : gcc_unreachable ();
8035 : : }
8036 : 251783 : }
8037 : :
8038 : : /* Store the value of EXP (an expression tree)
8039 : : into a subfield of TARGET which has mode MODE and occupies
8040 : : BITSIZE bits, starting BITPOS bits from the start of TARGET.
8041 : : If MODE is VOIDmode, it means that we are storing into a bit-field.
8042 : :
8043 : : BITREGION_START is bitpos of the first bitfield in this region.
8044 : : BITREGION_END is the bitpos of the ending bitfield in this region.
8045 : : These two fields are 0, if the C++ memory model does not apply,
8046 : : or we are not interested in keeping track of bitfield regions.
8047 : :
8048 : : Always return const0_rtx unless we have something particular to
8049 : : return.
8050 : :
8051 : : ALIAS_SET is the alias set for the destination. This value will
8052 : : (in general) be different from that for TARGET, since TARGET is a
8053 : : reference to the containing structure.
8054 : :
8055 : : If NONTEMPORAL is true, try generating a nontemporal store.
8056 : :
8057 : : If REVERSE is true, the store is to be done in reverse order. */
8058 : :
8059 : : static rtx
8060 : 4431878 : store_field (rtx target, poly_int64 bitsize, poly_int64 bitpos,
8061 : : poly_uint64 bitregion_start, poly_uint64 bitregion_end,
8062 : : machine_mode mode, tree exp,
8063 : : alias_set_type alias_set, bool nontemporal, bool reverse)
8064 : : {
8065 : 4431878 : if (TREE_CODE (exp) == ERROR_MARK)
8066 : 0 : return const0_rtx;
8067 : :
8068 : : /* If we have nothing to store, do nothing unless the expression has
8069 : : side-effects. Don't do that for zero sized addressable lhs of
8070 : : calls. */
8071 : 0 : if (known_eq (bitsize, 0)
8072 : 4431878 : && (!TREE_ADDRESSABLE (TREE_TYPE (exp))
8073 : 4 : || TREE_CODE (exp) != CALL_EXPR))
8074 : 0 : return expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL);
8075 : :
8076 : 4431878 : if (GET_CODE (target) == CONCAT)
8077 : : {
8078 : : /* We're storing into a struct containing a single __complex. */
8079 : :
8080 : 0 : gcc_assert (known_eq (bitpos, 0));
8081 : 0 : return store_expr (exp, target, 0, nontemporal, reverse);
8082 : : }
8083 : :
8084 : : /* If the structure is in a register or if the component
8085 : : is a bit field, we cannot use addressing to access it.
8086 : : Use bit-field techniques or SUBREG to store in it. */
8087 : :
8088 : 4431878 : poly_int64 decl_bitsize;
8089 : 4431878 : if (mode == VOIDmode
8090 : 4366775 : || (mode != BLKmode && ! direct_store[(int) mode]
8091 : 5364 : && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
8092 : 5362 : && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT)
8093 : 4361454 : || REG_P (target)
8094 : 3725602 : || GET_CODE (target) == SUBREG
8095 : : /* If the field isn't aligned enough to store as an ordinary memref,
8096 : : store it as a bit field. */
8097 : 3725602 : || (mode != BLKmode
8098 : 3614678 : && ((((MEM_ALIGN (target) < GET_MODE_ALIGNMENT (mode))
8099 : 3572412 : || !multiple_p (bitpos, GET_MODE_ALIGNMENT (mode)))
8100 : 47730 : && targetm.slow_unaligned_access (mode, MEM_ALIGN (target)))
8101 : 3614678 : || !multiple_p (bitpos, BITS_PER_UNIT)))
8102 : 3725602 : || (known_size_p (bitsize)
8103 : 3725590 : && mode != BLKmode
8104 : 3614678 : && maybe_gt (GET_MODE_BITSIZE (mode), bitsize))
8105 : : /* If the RHS and field are a constant size and the size of the
8106 : : RHS isn't the same size as the bitfield, we must use bitfield
8107 : : operations. */
8108 : 3725592 : || (known_size_p (bitsize)
8109 : 3725580 : && poly_int_tree_p (TYPE_SIZE (TREE_TYPE (exp)))
8110 : 3725580 : && maybe_ne (wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (exp))),
8111 : : bitsize)
8112 : : /* Except for initialization of full bytes from a CONSTRUCTOR, which
8113 : : we will handle specially below. */
8114 : 31 : && !(TREE_CODE (exp) == CONSTRUCTOR
8115 : 12 : && multiple_p (bitsize, BITS_PER_UNIT))
8116 : : /* And except for bitwise copying of TREE_ADDRESSABLE types,
8117 : : where the FIELD_DECL has the right bitsize, but TREE_TYPE (exp)
8118 : : includes some extra padding. store_expr / expand_expr will in
8119 : : that case call get_inner_reference that will have the bitsize
8120 : : we check here and thus the block move will not clobber the
8121 : : padding that shouldn't be clobbered. In the future we could
8122 : : replace the TREE_ADDRESSABLE check with a check that
8123 : : get_base_address needs to live in memory. */
8124 : 19 : && (!TREE_ADDRESSABLE (TREE_TYPE (exp))
8125 : 10 : || TREE_CODE (exp) != COMPONENT_REF
8126 : 6 : || !multiple_p (bitsize, BITS_PER_UNIT)
8127 : 6 : || !multiple_p (bitpos, BITS_PER_UNIT)
8128 : 6 : || !poly_int_tree_p (DECL_SIZE (TREE_OPERAND (exp, 1)),
8129 : : &decl_bitsize)
8130 : 6 : || maybe_ne (decl_bitsize, bitsize))
8131 : : /* A call with an addressable return type and return-slot
8132 : : optimization must not need bitfield operations but we must
8133 : : pass down the original target. */
8134 : 13 : && (TREE_CODE (exp) != CALL_EXPR
8135 : 8 : || !TREE_ADDRESSABLE (TREE_TYPE (exp))
8136 : 0 : || !CALL_EXPR_RETURN_SLOT_OPT (exp)))
8137 : : /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
8138 : : decl we must use bitfield operations. */
8139 : 8157457 : || (known_size_p (bitsize)
8140 : 3725567 : && TREE_CODE (exp) == MEM_REF
8141 : 30471 : && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
8142 : 25136 : && DECL_P (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
8143 : 20443 : && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
8144 : 4029 : && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) != BLKmode))
8145 : : {
8146 : 706753 : rtx temp;
8147 : 706753 : gimple *nop_def;
8148 : :
8149 : : /* If EXP is a NOP_EXPR of precision less than its mode, then that
8150 : : implies a mask operation. If the precision is the same size as
8151 : : the field we're storing into, that mask is redundant. This is
8152 : : particularly common with bit field assignments generated by the
8153 : : C front end. */
8154 : 706753 : nop_def = get_def_for_expr (exp, NOP_EXPR);
8155 : 706753 : if (nop_def)
8156 : : {
8157 : 7046 : tree type = TREE_TYPE (exp);
8158 : 7046 : if (INTEGRAL_TYPE_P (type)
8159 : 6898 : && maybe_ne (TYPE_PRECISION (type),
8160 : 13796 : GET_MODE_BITSIZE (TYPE_MODE (type)))
8161 : 13944 : && known_eq (bitsize, TYPE_PRECISION (type)))
8162 : : {
8163 : 3255 : tree op = gimple_assign_rhs1 (nop_def);
8164 : 3255 : type = TREE_TYPE (op);
8165 : 3255 : if (INTEGRAL_TYPE_P (type)
8166 : 3255 : && known_ge (TYPE_PRECISION (type), bitsize))
8167 : 3221 : exp = op;
8168 : : }
8169 : : }
8170 : :
8171 : 706753 : temp = expand_normal (exp);
8172 : :
8173 : : /* We don't support variable-sized BLKmode bitfields, since our
8174 : : handling of BLKmode is bound up with the ability to break
8175 : : things into words. */
8176 : 706753 : gcc_assert (mode != BLKmode || bitsize.is_constant ());
8177 : :
8178 : : /* Handle calls that return values in multiple non-contiguous locations.
8179 : : The Irix 6 ABI has examples of this. */
8180 : 706753 : if (GET_CODE (temp) == PARALLEL)
8181 : : {
8182 : 8 : HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
8183 : 8 : machine_mode temp_mode = GET_MODE (temp);
8184 : 8 : if (temp_mode == BLKmode || temp_mode == VOIDmode)
8185 : 8 : temp_mode = smallest_int_mode_for_size (size * BITS_PER_UNIT);
8186 : 8 : rtx temp_target = gen_reg_rtx (temp_mode);
8187 : 8 : emit_group_store (temp_target, temp, TREE_TYPE (exp), size);
8188 : 8 : temp = temp_target;
8189 : : }
8190 : :
8191 : : /* Handle calls that return BLKmode values in registers. */
8192 : 706745 : else if (mode == BLKmode && REG_P (temp) && TREE_CODE (exp) == CALL_EXPR)
8193 : : {
8194 : 0 : rtx temp_target = gen_reg_rtx (GET_MODE (temp));
8195 : 0 : copy_blkmode_from_reg (temp_target, temp, TREE_TYPE (exp));
8196 : 0 : temp = temp_target;
8197 : : }
8198 : :
8199 : : /* If the value has aggregate type and an integral mode then, if BITSIZE
8200 : : is narrower than this mode and this is for big-endian data, we first
8201 : : need to put the value into the low-order bits for store_bit_field,
8202 : : except when MODE is BLKmode and BITSIZE larger than the word size
8203 : : (see the handling of fields larger than a word in store_bit_field).
8204 : : Moreover, the field may be not aligned on a byte boundary; in this
8205 : : case, if it has reverse storage order, it needs to be accessed as a
8206 : : scalar field with reverse storage order and we must first put the
8207 : : value into target order. */
8208 : 706753 : scalar_int_mode temp_mode;
8209 : 1411530 : if (AGGREGATE_TYPE_P (TREE_TYPE (exp))
8210 : 707612 : && is_int_mode (GET_MODE (temp), &temp_mode))
8211 : : {
8212 : 2251 : HOST_WIDE_INT size = GET_MODE_BITSIZE (temp_mode);
8213 : :
8214 : 2251 : reverse = TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (exp));
8215 : :
8216 : 2251 : if (reverse)
8217 : 0 : temp = flip_storage_order (temp_mode, temp);
8218 : :
8219 : 2251 : gcc_checking_assert (known_le (bitsize, size));
8220 : 2251 : if (maybe_lt (bitsize, size)
8221 : 2251 : && reverse ? !BYTES_BIG_ENDIAN : BYTES_BIG_ENDIAN
8222 : : /* Use of to_constant for BLKmode was checked above. */
8223 : : && !(mode == BLKmode && bitsize.to_constant () > BITS_PER_WORD))
8224 : 0 : temp = expand_shift (RSHIFT_EXPR, temp_mode, temp,
8225 : : size - bitsize, NULL_RTX, 1);
8226 : : }
8227 : :
8228 : : /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
8229 : 641650 : if (mode != VOIDmode && mode != BLKmode
8230 : 1347826 : && mode != TYPE_MODE (TREE_TYPE (exp)))
8231 : 4 : temp = convert_modes (mode, TYPE_MODE (TREE_TYPE (exp)), temp, 1);
8232 : :
8233 : : /* If the mode of TEMP and TARGET is BLKmode, both must be in memory
8234 : : and BITPOS must be aligned on a byte boundary. If so, we simply do
8235 : : a block copy. Likewise for a BLKmode-like TARGET. */
8236 : 706753 : if (GET_MODE (temp) == BLKmode
8237 : 706753 : && (GET_MODE (target) == BLKmode
8238 : 173 : || (MEM_P (target)
8239 : 0 : && GET_MODE_CLASS (GET_MODE (target)) == MODE_INT
8240 : 0 : && multiple_p (bitpos, BITS_PER_UNIT)
8241 : 0 : && multiple_p (bitsize, BITS_PER_UNIT))))
8242 : : {
8243 : 396 : gcc_assert (MEM_P (target) && MEM_P (temp));
8244 : 396 : poly_int64 bytepos = exact_div (bitpos, BITS_PER_UNIT);
8245 : 396 : poly_int64 bytesize = bits_to_bytes_round_up (bitsize);
8246 : :
8247 : 396 : target = adjust_address (target, VOIDmode, bytepos);
8248 : 396 : emit_block_move (target, temp,
8249 : 396 : gen_int_mode (bytesize, Pmode),
8250 : : BLOCK_OP_NORMAL);
8251 : :
8252 : 396 : return const0_rtx;
8253 : : }
8254 : :
8255 : : /* If the mode of TEMP is still BLKmode and BITSIZE not larger than the
8256 : : word size, we need to load the value (see again store_bit_field). */
8257 : 706377 : if (GET_MODE (temp) == BLKmode && known_le (bitsize, BITS_PER_WORD))
8258 : : {
8259 : 11 : temp_mode = smallest_int_mode_for_size (bitsize);
8260 : 11 : temp = extract_bit_field (temp, bitsize, 0, 1, NULL_RTX, temp_mode,
8261 : : temp_mode, false, NULL);
8262 : : }
8263 : :
8264 : : /* Store the value in the bitfield. */
8265 : 706357 : gcc_checking_assert (known_ge (bitpos, 0));
8266 : 706357 : store_bit_field (target, bitsize, bitpos,
8267 : : bitregion_start, bitregion_end,
8268 : : mode, temp, reverse, false);
8269 : :
8270 : 706357 : return const0_rtx;
8271 : : }
8272 : : else
8273 : : {
8274 : : /* Now build a reference to just the desired component. */
8275 : 3725125 : rtx to_rtx = adjust_address (target, mode,
8276 : : exact_div (bitpos, BITS_PER_UNIT));
8277 : :
8278 : 3725125 : if (to_rtx == target)
8279 : 1246659 : to_rtx = copy_rtx (to_rtx);
8280 : :
8281 : 3725125 : if (!MEM_KEEP_ALIAS_SET_P (to_rtx) && MEM_ALIAS_SET (to_rtx) != 0)
8282 : 3214535 : set_mem_alias_set (to_rtx, alias_set);
8283 : :
8284 : : /* Above we avoided using bitfield operations for storing a CONSTRUCTOR
8285 : : into a target smaller than its type; handle that case now. */
8286 : 3725125 : if (TREE_CODE (exp) == CONSTRUCTOR && known_size_p (bitsize))
8287 : : {
8288 : 59224 : poly_int64 bytesize = exact_div (bitsize, BITS_PER_UNIT);
8289 : 59224 : store_constructor (exp, to_rtx, 0, bytesize, reverse);
8290 : 59224 : return to_rtx;
8291 : : }
8292 : :
8293 : 3665901 : return store_expr (exp, to_rtx, 0, nontemporal, reverse);
8294 : : }
8295 : : }
8296 : :
8297 : : /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
8298 : : an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
8299 : : codes and find the ultimate containing object, which we return.
8300 : :
8301 : : We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
8302 : : bit position, *PUNSIGNEDP to the signedness and *PREVERSEP to the
8303 : : storage order of the field.
8304 : : If the position of the field is variable, we store a tree
8305 : : giving the variable offset (in units) in *POFFSET.
8306 : : This offset is in addition to the bit position.
8307 : : If the position is not variable, we store 0 in *POFFSET.
8308 : :
8309 : : If any of the extraction expressions is volatile,
8310 : : we store 1 in *PVOLATILEP. Otherwise we don't change that.
8311 : :
8312 : : If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
8313 : : Otherwise, it is a mode that can be used to access the field.
8314 : :
8315 : : If the field describes a variable-sized object, *PMODE is set to
8316 : : BLKmode and *PBITSIZE is set to -1. An access cannot be made in
8317 : : this case, but the address of the object can be found. */
8318 : :
8319 : : tree
8320 : 211518401 : get_inner_reference (tree exp, poly_int64 *pbitsize,
8321 : : poly_int64 *pbitpos, tree *poffset,
8322 : : machine_mode *pmode, int *punsignedp,
8323 : : int *preversep, int *pvolatilep)
8324 : : {
8325 : 211518401 : tree size_tree = 0;
8326 : 211518401 : machine_mode mode = VOIDmode;
8327 : 211518401 : bool blkmode_bitfield = false;
8328 : 211518401 : tree offset = size_zero_node;
8329 : 211518401 : poly_offset_int bit_offset = 0;
8330 : :
8331 : : /* First get the mode, signedness, storage order and size. We do this from
8332 : : just the outermost expression. */
8333 : 211518401 : *pbitsize = -1;
8334 : 211518401 : if (TREE_CODE (exp) == COMPONENT_REF)
8335 : : {
8336 : 87349026 : tree field = TREE_OPERAND (exp, 1);
8337 : 87349026 : size_tree = DECL_SIZE (field);
8338 : 87349026 : if (flag_strict_volatile_bitfields > 0
8339 : 58 : && TREE_THIS_VOLATILE (exp)
8340 : 40 : && DECL_BIT_FIELD_TYPE (field)
8341 : 87349048 : && DECL_MODE (field) != BLKmode)
8342 : : /* Volatile bitfields should be accessed in the mode of the
8343 : : field's type, not the mode computed based on the bit
8344 : : size. */
8345 : 22 : mode = TYPE_MODE (DECL_BIT_FIELD_TYPE (field));
8346 : 87349004 : else if (!DECL_BIT_FIELD (field))
8347 : : {
8348 : 86364962 : mode = DECL_MODE (field);
8349 : : /* For vector fields re-check the target flags, as DECL_MODE
8350 : : could have been set with different target flags than
8351 : : the current function has. */
8352 : 86364962 : if (VECTOR_TYPE_P (TREE_TYPE (field))
8353 : 86364962 : && VECTOR_MODE_P (TYPE_MODE_RAW (TREE_TYPE (field))))
8354 : 314227 : mode = TYPE_MODE (TREE_TYPE (field));
8355 : : }
8356 : 984042 : else if (DECL_MODE (field) == BLKmode)
8357 : 57 : blkmode_bitfield = true;
8358 : :
8359 : 87349026 : *punsignedp = DECL_UNSIGNED (field);
8360 : : }
8361 : 124169375 : else if (TREE_CODE (exp) == BIT_FIELD_REF)
8362 : : {
8363 : 626977 : size_tree = TREE_OPERAND (exp, 1);
8364 : 1253579 : *punsignedp = (! INTEGRAL_TYPE_P (TREE_TYPE (exp))
8365 : 1135388 : || TYPE_UNSIGNED (TREE_TYPE (exp)));
8366 : :
8367 : : /* For vector element types with the correct size of access or for
8368 : : vector typed accesses use the mode of the access type. */
8369 : 626977 : if ((TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == VECTOR_TYPE
8370 : 403551 : && TREE_TYPE (exp) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)))
8371 : 371230 : && tree_int_cst_equal (size_tree, TYPE_SIZE (TREE_TYPE (exp))))
8372 : 659302 : || VECTOR_TYPE_P (TREE_TYPE (exp)))
8373 : 393797 : mode = TYPE_MODE (TREE_TYPE (exp));
8374 : : }
8375 : : else
8376 : : {
8377 : 123542398 : mode = TYPE_MODE (TREE_TYPE (exp));
8378 : 123542398 : *punsignedp = TYPE_UNSIGNED (TREE_TYPE (exp));
8379 : :
8380 : 123542398 : if (mode == BLKmode)
8381 : 49222876 : size_tree = TYPE_SIZE (TREE_TYPE (exp));
8382 : : else
8383 : 148639044 : *pbitsize = GET_MODE_BITSIZE (mode);
8384 : : }
8385 : :
8386 : 211518401 : if (size_tree != 0)
8387 : : {
8388 : 136599600 : if (! tree_fits_uhwi_p (size_tree))
8389 : 303474 : mode = BLKmode, *pbitsize = -1;
8390 : : else
8391 : 136296126 : *pbitsize = tree_to_uhwi (size_tree);
8392 : : }
8393 : :
8394 : 211518401 : *preversep = reverse_storage_order_for_component_p (exp);
8395 : :
8396 : : /* Compute cumulative bit-offset for nested component-refs and array-refs,
8397 : : and find the ultimate containing object. */
8398 : 514521319 : while (1)
8399 : : {
8400 : 363019860 : switch (TREE_CODE (exp))
8401 : : {
8402 : 626977 : case BIT_FIELD_REF:
8403 : 626977 : bit_offset += wi::to_poly_offset (TREE_OPERAND (exp, 2));
8404 : 626977 : break;
8405 : :
8406 : 126685710 : case COMPONENT_REF:
8407 : 126685710 : {
8408 : 126685710 : tree field = TREE_OPERAND (exp, 1);
8409 : 126685710 : tree this_offset = component_ref_field_offset (exp);
8410 : :
8411 : : /* If this field hasn't been filled in yet, don't go past it.
8412 : : This should only happen when folding expressions made during
8413 : : type construction. */
8414 : 126685710 : if (this_offset == 0)
8415 : : break;
8416 : :
8417 : 126685679 : offset = size_binop (PLUS_EXPR, offset, this_offset);
8418 : 126685679 : bit_offset += wi::to_poly_offset (DECL_FIELD_BIT_OFFSET (field));
8419 : :
8420 : : /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
8421 : : }
8422 : 126685679 : break;
8423 : :
8424 : 22054979 : case ARRAY_REF:
8425 : 22054979 : case ARRAY_RANGE_REF:
8426 : 22054979 : {
8427 : 22054979 : tree index = TREE_OPERAND (exp, 1);
8428 : 22054979 : tree low_bound = array_ref_low_bound (exp);
8429 : 22054979 : tree unit_size = array_ref_element_size (exp);
8430 : :
8431 : : /* We assume all arrays have sizes that are a multiple of a byte.
8432 : : First subtract the lower bound, if any, in the type of the
8433 : : index, then convert to sizetype and multiply by the size of
8434 : : the array element. */
8435 : 22054979 : if (! integer_zerop (low_bound))
8436 : 750422 : index = fold_build2 (MINUS_EXPR, TREE_TYPE (index),
8437 : : index, low_bound);
8438 : :
8439 : 22054979 : offset = size_binop (PLUS_EXPR, offset,
8440 : : size_binop (MULT_EXPR,
8441 : : fold_convert (sizetype, index),
8442 : : unit_size));
8443 : : }
8444 : 22054979 : break;
8445 : :
8446 : : case REALPART_EXPR:
8447 : : break;
8448 : :
8449 : : case IMAGPART_EXPR:
8450 : 151501459 : bit_offset += *pbitsize;
8451 : : break;
8452 : :
8453 : : case VIEW_CONVERT_EXPR:
8454 : : break;
8455 : :
8456 : 73444944 : case MEM_REF:
8457 : : /* Hand back the decl for MEM[&decl, off]. */
8458 : 73444944 : if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR)
8459 : : {
8460 : 14962102 : tree off = TREE_OPERAND (exp, 1);
8461 : 14962102 : if (!integer_zerop (off))
8462 : : {
8463 : 8048842 : poly_offset_int boff = mem_ref_offset (exp);
8464 : 8048842 : boff <<= LOG2_BITS_PER_UNIT;
8465 : 8048842 : bit_offset += boff;
8466 : : }
8467 : 14962102 : exp = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
8468 : : }
8469 : 73444944 : goto done;
8470 : :
8471 : 138073457 : default:
8472 : 138073457 : goto done;
8473 : : }
8474 : :
8475 : : /* If any reference in the chain is volatile, the effect is volatile. */
8476 : 151501459 : if (TREE_THIS_VOLATILE (exp))
8477 : 449932 : *pvolatilep = 1;
8478 : :
8479 : 151501459 : exp = TREE_OPERAND (exp, 0);
8480 : 151501459 : }
8481 : 211518401 : done:
8482 : :
8483 : : /* If OFFSET is constant, see if we can return the whole thing as a
8484 : : constant bit position. Make sure to handle overflow during
8485 : : this conversion. */
8486 : 211518401 : if (poly_int_tree_p (offset))
8487 : : {
8488 : 202398563 : poly_offset_int tem = wi::sext (wi::to_poly_offset (offset),
8489 : 202398563 : TYPE_PRECISION (sizetype));
8490 : 202398563 : tem <<= LOG2_BITS_PER_UNIT;
8491 : 202398563 : tem += bit_offset;
8492 : 202398563 : if (tem.to_shwi (pbitpos))
8493 : 202397003 : *poffset = offset = NULL_TREE;
8494 : : }
8495 : :
8496 : : /* Otherwise, split it up. */
8497 : 202398563 : if (offset)
8498 : : {
8499 : : /* Avoid returning a negative bitpos as this may wreak havoc later. */
8500 : 9121398 : if (!bit_offset.to_shwi (pbitpos) || maybe_lt (*pbitpos, 0))
8501 : : {
8502 : 313 : *pbitpos = num_trailing_bits (bit_offset.force_shwi ());
8503 : 313 : poly_offset_int bytes = bits_to_bytes_round_down (bit_offset);
8504 : 313 : offset = size_binop (PLUS_EXPR, offset,
8505 : : build_int_cst (sizetype, bytes.force_shwi ()));
8506 : : }
8507 : :
8508 : 9121398 : *poffset = offset;
8509 : : }
8510 : :
8511 : : /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
8512 : 211518401 : if (mode == VOIDmode
8513 : 1819682 : && blkmode_bitfield
8514 : 57 : && multiple_p (*pbitpos, BITS_PER_UNIT)
8515 : 211518420 : && multiple_p (*pbitsize, BITS_PER_UNIT))
8516 : 0 : *pmode = BLKmode;
8517 : : else
8518 : 211518401 : *pmode = mode;
8519 : :
8520 : 211518401 : return exp;
8521 : : }
8522 : :
8523 : : /* Alignment in bits the TARGET of an assignment may be assumed to have. */
8524 : :
8525 : : static unsigned HOST_WIDE_INT
8526 : 509444 : target_align (const_tree target)
8527 : : {
8528 : : /* We might have a chain of nested references with intermediate misaligning
8529 : : bitfields components, so need to recurse to find out. */
8530 : :
8531 : 509444 : unsigned HOST_WIDE_INT this_align, outer_align;
8532 : :
8533 : 509444 : switch (TREE_CODE (target))
8534 : : {
8535 : : case BIT_FIELD_REF:
8536 : : return 1;
8537 : :
8538 : 146385 : case COMPONENT_REF:
8539 : 146385 : this_align = DECL_ALIGN (TREE_OPERAND (target, 1));
8540 : 146385 : outer_align = target_align (TREE_OPERAND (target, 0));
8541 : 146385 : return MIN (this_align, outer_align);
8542 : :
8543 : 184864 : case ARRAY_REF:
8544 : 184864 : case ARRAY_RANGE_REF:
8545 : 184864 : this_align = TYPE_ALIGN (TREE_TYPE (target));
8546 : 184864 : outer_align = target_align (TREE_OPERAND (target, 0));
8547 : 184864 : return MIN (this_align, outer_align);
8548 : :
8549 : 4238 : CASE_CONVERT:
8550 : 4238 : case NON_LVALUE_EXPR:
8551 : 4238 : case VIEW_CONVERT_EXPR:
8552 : 4238 : this_align = TYPE_ALIGN (TREE_TYPE (target));
8553 : 4238 : outer_align = target_align (TREE_OPERAND (target, 0));
8554 : 4238 : return MAX (this_align, outer_align);
8555 : :
8556 : 173953 : default:
8557 : 173953 : return TYPE_ALIGN (TREE_TYPE (target));
8558 : : }
8559 : : }
8560 : :
8561 : :
8562 : : /* Given an rtx VALUE that may contain additions and multiplications, return
8563 : : an equivalent value that just refers to a register, memory, or constant.
8564 : : This is done by generating instructions to perform the arithmetic and
8565 : : returning a pseudo-register containing the value.
8566 : :
8567 : : The returned value may be a REG, SUBREG, MEM or constant. */
8568 : :
8569 : : rtx
8570 : 28785679 : force_operand (rtx value, rtx target)
8571 : : {
8572 : 28785679 : rtx op1, op2;
8573 : : /* Use subtarget as the target for operand 0 of a binary operation. */
8574 : 28785679 : rtx subtarget = get_subtarget (target);
8575 : 28785679 : enum rtx_code code = GET_CODE (value);
8576 : :
8577 : : /* Check for subreg applied to an expression produced by loop optimizer. */
8578 : 28785679 : if (code == SUBREG
8579 : 307044 : && !REG_P (SUBREG_REG (value))
8580 : 94 : && !MEM_P (SUBREG_REG (value)))
8581 : : {
8582 : 94 : value
8583 : 94 : = simplify_gen_subreg (GET_MODE (value),
8584 : 94 : force_reg (GET_MODE (SUBREG_REG (value)),
8585 : : force_operand (SUBREG_REG (value),
8586 : : NULL_RTX)),
8587 : 94 : GET_MODE (SUBREG_REG (value)),
8588 : 94 : SUBREG_BYTE (value));
8589 : 94 : code = GET_CODE (value);
8590 : : }
8591 : :
8592 : : /* Check for a PIC address load. */
8593 : 28785679 : if ((code == PLUS || code == MINUS)
8594 : 3370519 : && XEXP (value, 0) == pic_offset_table_rtx
8595 : 1984 : && (GET_CODE (XEXP (value, 1)) == SYMBOL_REF
8596 : 1984 : || GET_CODE (XEXP (value, 1)) == LABEL_REF
8597 : 1984 : || GET_CODE (XEXP (value, 1)) == CONST))
8598 : : {
8599 : 228 : if (!subtarget)
8600 : 228 : subtarget = gen_reg_rtx (GET_MODE (value));
8601 : 228 : emit_move_insn (subtarget, value);
8602 : 228 : return subtarget;
8603 : : }
8604 : :
8605 : 28785451 : if (ARITHMETIC_P (value))
8606 : : {
8607 : 3467386 : op2 = XEXP (value, 1);
8608 : 3467386 : if (!CONSTANT_P (op2) && !(REG_P (op2) && op2 != subtarget))
8609 : 3467386 : subtarget = 0;
8610 : 3467386 : if (code == MINUS && CONST_INT_P (op2))
8611 : : {
8612 : 0 : code = PLUS;
8613 : 0 : op2 = negate_rtx (GET_MODE (value), op2);
8614 : : }
8615 : :
8616 : : /* Check for an addition with OP2 a constant integer and our first
8617 : : operand a PLUS of a virtual register and something else. In that
8618 : : case, we want to emit the sum of the virtual register and the
8619 : : constant first and then add the other value. This allows virtual
8620 : : register instantiation to simply modify the constant rather than
8621 : : creating another one around this addition. */
8622 : 3296834 : if (code == PLUS && CONST_INT_P (op2)
8623 : 2999014 : && GET_CODE (XEXP (value, 0)) == PLUS
8624 : 75318 : && REG_P (XEXP (XEXP (value, 0), 0))
8625 : 3491790 : && VIRTUAL_REGISTER_P (XEXP (XEXP (value, 0), 0)))
8626 : : {
8627 : 1861 : rtx temp = expand_simple_binop (GET_MODE (value), code,
8628 : : XEXP (XEXP (value, 0), 0), op2,
8629 : : subtarget, 0, OPTAB_LIB_WIDEN);
8630 : 1861 : return expand_simple_binop (GET_MODE (value), code, temp,
8631 : 1861 : force_operand (XEXP (XEXP (value,
8632 : : 0), 1), 0),
8633 : 1861 : target, 0, OPTAB_LIB_WIDEN);
8634 : : }
8635 : :
8636 : 3465525 : op1 = force_operand (XEXP (value, 0), subtarget);
8637 : 3465525 : op2 = force_operand (op2, NULL_RTX);
8638 : 3465525 : switch (code)
8639 : : {
8640 : 89375 : case MULT:
8641 : 89375 : return expand_mult (GET_MODE (value), op1, op2, target, 1);
8642 : 0 : case DIV:
8643 : 0 : if (!INTEGRAL_MODE_P (GET_MODE (value)))
8644 : 0 : return expand_simple_binop (GET_MODE (value), code, op1, op2,
8645 : 0 : target, 1, OPTAB_LIB_WIDEN);
8646 : : else
8647 : 0 : return expand_divmod (0,
8648 : : FLOAT_MODE_P (GET_MODE (value))
8649 : : ? RDIV_EXPR : TRUNC_DIV_EXPR,
8650 : 0 : GET_MODE (value), op1, op2, target, 0);
8651 : 0 : case MOD:
8652 : 0 : return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
8653 : 0 : target, 0);
8654 : 349 : case UDIV:
8655 : 349 : return expand_divmod (0, TRUNC_DIV_EXPR, GET_MODE (value), op1, op2,
8656 : 349 : target, 1);
8657 : 0 : case UMOD:
8658 : 0 : return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
8659 : 0 : target, 1);
8660 : 0 : case ASHIFTRT:
8661 : 0 : return expand_simple_binop (GET_MODE (value), code, op1, op2,
8662 : 0 : target, 0, OPTAB_LIB_WIDEN);
8663 : 3375801 : default:
8664 : 3375801 : return expand_simple_binop (GET_MODE (value), code, op1, op2,
8665 : 3375801 : target, 1, OPTAB_LIB_WIDEN);
8666 : : }
8667 : : }
8668 : 25318065 : if (UNARY_P (value))
8669 : : {
8670 : 9428 : if (!target)
8671 : 5690 : target = gen_reg_rtx (GET_MODE (value));
8672 : 9428 : op1 = force_operand (XEXP (value, 0), NULL_RTX);
8673 : 9428 : switch (code)
8674 : : {
8675 : 29 : case ZERO_EXTEND:
8676 : 29 : case SIGN_EXTEND:
8677 : 29 : case TRUNCATE:
8678 : 29 : case FLOAT_EXTEND:
8679 : 29 : case FLOAT_TRUNCATE:
8680 : 29 : convert_move (target, op1, code == ZERO_EXTEND);
8681 : 29 : return target;
8682 : :
8683 : 0 : case FIX:
8684 : 0 : case UNSIGNED_FIX:
8685 : 0 : expand_fix (target, op1, code == UNSIGNED_FIX);
8686 : 0 : return target;
8687 : :
8688 : 0 : case FLOAT:
8689 : 0 : case UNSIGNED_FLOAT:
8690 : 0 : expand_float (target, op1, code == UNSIGNED_FLOAT);
8691 : 0 : return target;
8692 : :
8693 : 9399 : default:
8694 : 9399 : return expand_simple_unop (GET_MODE (value), code, op1, target, 0);
8695 : : }
8696 : : }
8697 : :
8698 : : #ifdef INSN_SCHEDULING
8699 : : /* On machines that have insn scheduling, we want all memory reference to be
8700 : : explicit, so we need to deal with such paradoxical SUBREGs. */
8701 : 25308637 : if (paradoxical_subreg_p (value) && MEM_P (SUBREG_REG (value)))
8702 : 0 : value
8703 : 0 : = simplify_gen_subreg (GET_MODE (value),
8704 : 0 : force_reg (GET_MODE (SUBREG_REG (value)),
8705 : : force_operand (SUBREG_REG (value),
8706 : : NULL_RTX)),
8707 : 0 : GET_MODE (SUBREG_REG (value)),
8708 : 0 : SUBREG_BYTE (value));
8709 : : #endif
8710 : :
8711 : : return value;
8712 : : }
8713 : :
8714 : : /* Subroutine of expand_expr: return true iff there is no way that
8715 : : EXP can reference X, which is being modified. TOP_P is nonzero if this
8716 : : call is going to be used to determine whether we need a temporary
8717 : : for EXP, as opposed to a recursive call to this function.
8718 : :
8719 : : It is always safe for this routine to return false since it merely
8720 : : searches for optimization opportunities. */
8721 : :
8722 : : bool
8723 : 7540084 : safe_from_p (const_rtx x, tree exp, int top_p)
8724 : : {
8725 : 7540086 : rtx exp_rtl = 0;
8726 : 7540086 : int i, nops;
8727 : :
8728 : 7540086 : if (x == 0
8729 : : /* If EXP has varying size, we MUST use a target since we currently
8730 : : have no way of allocating temporaries of variable size
8731 : : (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
8732 : : So we assume here that something at a higher level has prevented a
8733 : : clash. This is somewhat bogus, but the best we can do. Only
8734 : : do this when X is BLKmode and when we are at the top level. */
8735 : 1860337 : || (top_p && TREE_TYPE (exp) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp))
8736 : 1735907 : && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) != INTEGER_CST
8737 : 0 : && (TREE_CODE (TREE_TYPE (exp)) != ARRAY_TYPE
8738 : 0 : || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)) == NULL_TREE
8739 : 0 : || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)))
8740 : : != INTEGER_CST)
8741 : 0 : && GET_MODE (x) == BLKmode)
8742 : : /* If X is in the outgoing argument area, it is always safe. */
8743 : 9400423 : || (MEM_P (x)
8744 : 173395 : && (XEXP (x, 0) == virtual_outgoing_args_rtx
8745 : 173395 : || (GET_CODE (XEXP (x, 0)) == PLUS
8746 : 127882 : && XEXP (XEXP (x, 0), 0) == virtual_outgoing_args_rtx))))
8747 : : return true;
8748 : :
8749 : : /* If this is a subreg of a hard register, declare it unsafe, otherwise,
8750 : : find the underlying pseudo. */
8751 : 1860337 : if (GET_CODE (x) == SUBREG)
8752 : : {
8753 : 0 : x = SUBREG_REG (x);
8754 : 0 : if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
8755 : : return false;
8756 : : }
8757 : :
8758 : : /* Now look at our tree code and possibly recurse. */
8759 : 1860337 : switch (TREE_CODE_CLASS (TREE_CODE (exp)))
8760 : : {
8761 : 381 : case tcc_declaration:
8762 : 381 : exp_rtl = DECL_RTL_IF_SET (exp);
8763 : 227 : break;
8764 : :
8765 : : case tcc_constant:
8766 : : return true;
8767 : :
8768 : 798910 : case tcc_exceptional:
8769 : 798910 : if (TREE_CODE (exp) == TREE_LIST)
8770 : : {
8771 : 0 : while (1)
8772 : : {
8773 : 0 : if (TREE_VALUE (exp) && !safe_from_p (x, TREE_VALUE (exp), 0))
8774 : : return false;
8775 : 0 : exp = TREE_CHAIN (exp);
8776 : 0 : if (!exp)
8777 : : return true;
8778 : 0 : if (TREE_CODE (exp) != TREE_LIST)
8779 : 0 : return safe_from_p (x, exp, 0);
8780 : : }
8781 : : }
8782 : 798910 : else if (TREE_CODE (exp) == CONSTRUCTOR)
8783 : : {
8784 : : constructor_elt *ce;
8785 : : unsigned HOST_WIDE_INT idx;
8786 : :
8787 : 6891341 : FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp), idx, ce)
8788 : 3752 : if ((ce->index != NULL_TREE && !safe_from_p (x, ce->index, 0))
8789 : 124359 : || !safe_from_p (x, ce->value, 0))
8790 : 106790 : return false;
8791 : : return true;
8792 : : }
8793 : 663674 : else if (TREE_CODE (exp) == ERROR_MARK)
8794 : : return true; /* An already-visited SAVE_EXPR? */
8795 : : else
8796 : : return false;
8797 : :
8798 : 0 : case tcc_statement:
8799 : : /* The only case we look at here is the DECL_INITIAL inside a
8800 : : DECL_EXPR. */
8801 : 0 : return (TREE_CODE (exp) != DECL_EXPR
8802 : 0 : || TREE_CODE (DECL_EXPR_DECL (exp)) != VAR_DECL
8803 : 0 : || !DECL_INITIAL (DECL_EXPR_DECL (exp))
8804 : 0 : || safe_from_p (x, DECL_INITIAL (DECL_EXPR_DECL (exp)), 0));
8805 : :
8806 : 0 : case tcc_binary:
8807 : 0 : case tcc_comparison:
8808 : 0 : if (!safe_from_p (x, TREE_OPERAND (exp, 1), 0))
8809 : : return false;
8810 : : /* Fall through. */
8811 : :
8812 : 2 : case tcc_unary:
8813 : 2 : return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
8814 : :
8815 : 202 : case tcc_expression:
8816 : 202 : case tcc_reference:
8817 : 202 : case tcc_vl_exp:
8818 : : /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
8819 : : the expression. If it is set, we conflict iff we are that rtx or
8820 : : both are in memory. Otherwise, we check all operands of the
8821 : : expression recursively. */
8822 : :
8823 : 202 : switch (TREE_CODE (exp))
8824 : : {
8825 : 191 : case ADDR_EXPR:
8826 : : /* If the operand is static or we are static, we can't conflict.
8827 : : Likewise if we don't conflict with the operand at all. */
8828 : 191 : if (staticp (TREE_OPERAND (exp, 0))
8829 : 47 : || TREE_STATIC (exp)
8830 : 238 : || safe_from_p (x, TREE_OPERAND (exp, 0), 0))
8831 : 191 : return true;
8832 : :
8833 : : /* Otherwise, the only way this can conflict is if we are taking
8834 : : the address of a DECL a that address if part of X, which is
8835 : : very rare. */
8836 : 0 : exp = TREE_OPERAND (exp, 0);
8837 : 0 : if (DECL_P (exp))
8838 : : {
8839 : 0 : if (!DECL_RTL_SET_P (exp)
8840 : 0 : || !MEM_P (DECL_RTL (exp)))
8841 : 0 : return false;
8842 : : else
8843 : 0 : exp_rtl = XEXP (DECL_RTL (exp), 0);
8844 : : }
8845 : : break;
8846 : :
8847 : 0 : case MEM_REF:
8848 : 0 : if (MEM_P (x)
8849 : 0 : && alias_sets_conflict_p (MEM_ALIAS_SET (x),
8850 : : get_alias_set (exp)))
8851 : : return false;
8852 : : break;
8853 : :
8854 : 0 : case CALL_EXPR:
8855 : : /* Assume that the call will clobber all hard registers and
8856 : : all of memory. */
8857 : 0 : if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
8858 : 0 : || MEM_P (x))
8859 : : return false;
8860 : : break;
8861 : :
8862 : 0 : case WITH_CLEANUP_EXPR:
8863 : 0 : case CLEANUP_POINT_EXPR:
8864 : : /* Lowered by gimplify.cc. */
8865 : 0 : gcc_unreachable ();
8866 : :
8867 : 0 : case SAVE_EXPR:
8868 : 0 : return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
8869 : :
8870 : : default:
8871 : : break;
8872 : : }
8873 : :
8874 : : /* If we have an rtx, we do not need to scan our operands. */
8875 : 0 : if (exp_rtl)
8876 : : break;
8877 : :
8878 : 11 : nops = TREE_OPERAND_LENGTH (exp);
8879 : 55 : for (i = 0; i < nops; i++)
8880 : 33 : if (TREE_OPERAND (exp, i) != 0
8881 : 33 : && ! safe_from_p (x, TREE_OPERAND (exp, i), 0))
8882 : : return false;
8883 : :
8884 : : break;
8885 : :
8886 : 0 : case tcc_type:
8887 : : /* Should never get a type here. */
8888 : 0 : gcc_unreachable ();
8889 : : }
8890 : :
8891 : : /* If we have an rtl, find any enclosed object. Then see if we conflict
8892 : : with it. */
8893 : 238 : if (exp_rtl)
8894 : : {
8895 : 227 : if (GET_CODE (exp_rtl) == SUBREG)
8896 : : {
8897 : 0 : exp_rtl = SUBREG_REG (exp_rtl);
8898 : 0 : if (REG_P (exp_rtl)
8899 : 0 : && REGNO (exp_rtl) < FIRST_PSEUDO_REGISTER)
8900 : : return false;
8901 : : }
8902 : :
8903 : : /* If the rtl is X, then it is not safe. Otherwise, it is unless both
8904 : : are memory and they conflict. */
8905 : 227 : return ! (rtx_equal_p (x, exp_rtl)
8906 : 227 : || (MEM_P (x) && MEM_P (exp_rtl)
8907 : 0 : && true_dependence (exp_rtl, VOIDmode, x)));
8908 : : }
8909 : :
8910 : : /* If we reach here, it is safe. */
8911 : : return true;
8912 : : }
8913 : :
8914 : :
8915 : : /* Return the highest power of two that EXP is known to be a multiple of.
8916 : : This is used in updating alignment of MEMs in array references. */
8917 : :
8918 : : unsigned HOST_WIDE_INT
8919 : 29349115 : highest_pow2_factor (const_tree exp)
8920 : : {
8921 : 29349115 : unsigned HOST_WIDE_INT ret;
8922 : 29349115 : int trailing_zeros = tree_ctz (exp);
8923 : 29349115 : if (trailing_zeros >= HOST_BITS_PER_WIDE_INT)
8924 : 39533970 : return BIGGEST_ALIGNMENT;
8925 : 9262181 : ret = HOST_WIDE_INT_1U << trailing_zeros;
8926 : 18075563 : if (ret > BIGGEST_ALIGNMENT)
8927 : 12846721 : return BIGGEST_ALIGNMENT;
8928 : : return ret;
8929 : : }
8930 : :
8931 : : /* Similar, except that the alignment requirements of TARGET are
8932 : : taken into account. Assume it is at least as aligned as its
8933 : : type, unless it is a COMPONENT_REF in which case the layout of
8934 : : the structure gives the alignment. */
8935 : :
8936 : : static unsigned HOST_WIDE_INT
8937 : 173957 : highest_pow2_factor_for_target (const_tree target, const_tree exp)
8938 : : {
8939 : 173957 : unsigned HOST_WIDE_INT talign = target_align (target) / BITS_PER_UNIT;
8940 : 173957 : unsigned HOST_WIDE_INT factor = highest_pow2_factor (exp);
8941 : :
8942 : 173957 : return MAX (factor, talign);
8943 : : }
8944 : :
8945 : : /* Convert the tree comparison code TCODE to the rtl one where the
8946 : : signedness is UNSIGNEDP. */
8947 : :
8948 : : static enum rtx_code
8949 : 8337 : convert_tree_comp_to_rtx (enum tree_code tcode, int unsignedp)
8950 : : {
8951 : 8337 : enum rtx_code code;
8952 : 8337 : switch (tcode)
8953 : : {
8954 : : case EQ_EXPR:
8955 : : code = EQ;
8956 : : break;
8957 : 769 : case NE_EXPR:
8958 : 769 : code = NE;
8959 : 769 : break;
8960 : 2091 : case LT_EXPR:
8961 : 2091 : code = unsignedp ? LTU : LT;
8962 : : break;
8963 : 570 : case LE_EXPR:
8964 : 570 : code = unsignedp ? LEU : LE;
8965 : : break;
8966 : 1314 : case GT_EXPR:
8967 : 1314 : code = unsignedp ? GTU : GT;
8968 : : break;
8969 : 746 : case GE_EXPR:
8970 : 746 : code = unsignedp ? GEU : GE;
8971 : : break;
8972 : 4 : case UNORDERED_EXPR:
8973 : 4 : code = UNORDERED;
8974 : 4 : break;
8975 : 0 : case ORDERED_EXPR:
8976 : 0 : code = ORDERED;
8977 : 0 : break;
8978 : 0 : case UNLT_EXPR:
8979 : 0 : code = UNLT;
8980 : 0 : break;
8981 : 0 : case UNLE_EXPR:
8982 : 0 : code = UNLE;
8983 : 0 : break;
8984 : 0 : case UNGT_EXPR:
8985 : 0 : code = UNGT;
8986 : 0 : break;
8987 : 0 : case UNGE_EXPR:
8988 : 0 : code = UNGE;
8989 : 0 : break;
8990 : 0 : case UNEQ_EXPR:
8991 : 0 : code = UNEQ;
8992 : 0 : break;
8993 : 0 : case LTGT_EXPR:
8994 : 0 : code = LTGT;
8995 : 0 : break;
8996 : :
8997 : 0 : default:
8998 : 0 : gcc_unreachable ();
8999 : : }
9000 : 8337 : return code;
9001 : : }
9002 : :
9003 : : /* Subroutine of expand_expr. Expand the two operands of a binary
9004 : : expression EXP0 and EXP1 placing the results in OP0 and OP1.
9005 : : The value may be stored in TARGET if TARGET is nonzero. The
9006 : : MODIFIER argument is as documented by expand_expr. */
9007 : :
9008 : : void
9009 : 7020328 : expand_operands (tree exp0, tree exp1, rtx target, rtx *op0, rtx *op1,
9010 : : enum expand_modifier modifier)
9011 : : {
9012 : 7020328 : if (! safe_from_p (target, exp1, 1))
9013 : 540714 : target = 0;
9014 : 7020328 : if (operand_equal_p (exp0, exp1, 0))
9015 : : {
9016 : 32654 : *op0 = expand_expr (exp0, target, VOIDmode, modifier);
9017 : 32654 : *op1 = copy_rtx (*op0);
9018 : : }
9019 : : else
9020 : : {
9021 : 6987674 : *op0 = expand_expr (exp0, target, VOIDmode, modifier);
9022 : 6987674 : *op1 = expand_expr (exp1, NULL_RTX, VOIDmode, modifier);
9023 : : }
9024 : 7020328 : }
9025 : :
9026 : :
9027 : : /* Return a MEM that contains constant EXP. DEFER is as for
9028 : : output_constant_def and MODIFIER is as for expand_expr. */
9029 : :
9030 : : static rtx
9031 : 2720660 : expand_expr_constant (tree exp, int defer, enum expand_modifier modifier)
9032 : : {
9033 : 2720660 : rtx mem;
9034 : :
9035 : 2720660 : mem = output_constant_def (exp, defer);
9036 : 2720660 : if (modifier != EXPAND_INITIALIZER)
9037 : 1714343 : mem = use_anchored_address (mem);
9038 : 2720660 : return mem;
9039 : : }
9040 : :
9041 : : /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
9042 : : The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
9043 : :
9044 : : static rtx
9045 : 13525112 : expand_expr_addr_expr_1 (tree exp, rtx target, scalar_int_mode tmode,
9046 : : enum expand_modifier modifier, addr_space_t as)
9047 : : {
9048 : 13525112 : rtx result, subtarget;
9049 : 13525112 : tree inner, offset;
9050 : 13525112 : poly_int64 bitsize, bitpos;
9051 : 13525112 : int unsignedp, reversep, volatilep = 0;
9052 : 13525112 : machine_mode mode1;
9053 : :
9054 : : /* If we are taking the address of a constant and are at the top level,
9055 : : we have to use output_constant_def since we can't call force_const_mem
9056 : : at top level. */
9057 : : /* ??? This should be considered a front-end bug. We should not be
9058 : : generating ADDR_EXPR of something that isn't an LVALUE. The only
9059 : : exception here is STRING_CST. */
9060 : 13525112 : if (CONSTANT_CLASS_P (exp))
9061 : : {
9062 : 2512450 : result = XEXP (expand_expr_constant (exp, 0, modifier), 0);
9063 : 2512450 : if (modifier < EXPAND_SUM)
9064 : 1630073 : result = force_operand (result, target);
9065 : 2512450 : return result;
9066 : : }
9067 : :
9068 : : /* Everything must be something allowed by is_gimple_addressable. */
9069 : 11012662 : switch (TREE_CODE (exp))
9070 : : {
9071 : 38 : case INDIRECT_REF:
9072 : : /* This case will happen via recursion for &a->b. */
9073 : 38 : return expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
9074 : :
9075 : 573481 : case MEM_REF:
9076 : 573481 : {
9077 : 573481 : tree tem = TREE_OPERAND (exp, 0);
9078 : 573481 : if (!integer_zerop (TREE_OPERAND (exp, 1)))
9079 : 302286 : tem = fold_build_pointer_plus (tem, TREE_OPERAND (exp, 1));
9080 : 573481 : return expand_expr (tem, target, tmode, modifier);
9081 : : }
9082 : :
9083 : 1055 : case TARGET_MEM_REF:
9084 : 1055 : return addr_for_mem_ref (exp, as, true);
9085 : :
9086 : 57084 : case CONST_DECL:
9087 : : /* Expand the initializer like constants above. */
9088 : 57084 : result = XEXP (expand_expr_constant (DECL_INITIAL (exp),
9089 : : 0, modifier), 0);
9090 : 57084 : if (modifier < EXPAND_SUM)
9091 : 57078 : result = force_operand (result, target);
9092 : : return result;
9093 : :
9094 : 114 : case REALPART_EXPR:
9095 : : /* The real part of the complex number is always first, therefore
9096 : : the address is the same as the address of the parent object. */
9097 : 114 : offset = 0;
9098 : 114 : bitpos = 0;
9099 : 114 : inner = TREE_OPERAND (exp, 0);
9100 : 114 : break;
9101 : :
9102 : 52 : case IMAGPART_EXPR:
9103 : : /* The imaginary part of the complex number is always second.
9104 : : The expression is therefore always offset by the size of the
9105 : : scalar type. */
9106 : 52 : offset = 0;
9107 : 104 : bitpos = GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (exp)));
9108 : 52 : inner = TREE_OPERAND (exp, 0);
9109 : 52 : break;
9110 : :
9111 : 13 : case COMPOUND_LITERAL_EXPR:
9112 : : /* Allow COMPOUND_LITERAL_EXPR in initializers or coming from
9113 : : initializers, if e.g. rtl_for_decl_init is called on DECL_INITIAL
9114 : : with COMPOUND_LITERAL_EXPRs in it, or ARRAY_REF on a const static
9115 : : array with address of COMPOUND_LITERAL_EXPR in DECL_INITIAL;
9116 : : the initializers aren't gimplified. */
9117 : 13 : if (COMPOUND_LITERAL_EXPR_DECL (exp)
9118 : 13 : && is_global_var (COMPOUND_LITERAL_EXPR_DECL (exp)))
9119 : 13 : return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp),
9120 : 13 : target, tmode, modifier, as);
9121 : : /* FALLTHRU */
9122 : 10380825 : default:
9123 : : /* If the object is a DECL, then expand it for its rtl. Don't bypass
9124 : : expand_expr, as that can have various side effects; LABEL_DECLs for
9125 : : example, may not have their DECL_RTL set yet. Expand the rtl of
9126 : : CONSTRUCTORs too, which should yield a memory reference for the
9127 : : constructor's contents. Assume language specific tree nodes can
9128 : : be expanded in some interesting way. */
9129 : 10380825 : gcc_assert (TREE_CODE (exp) < LAST_AND_UNUSED_TREE_CODE);
9130 : 10380825 : if (DECL_P (exp)
9131 : 1246303 : || TREE_CODE (exp) == CONSTRUCTOR
9132 : 1246303 : || TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
9133 : : {
9134 : 14764289 : result = expand_expr (exp, target, tmode,
9135 : : modifier == EXPAND_INITIALIZER
9136 : : ? EXPAND_INITIALIZER : EXPAND_CONST_ADDRESS);
9137 : :
9138 : : /* If the DECL isn't in memory, then the DECL wasn't properly
9139 : : marked TREE_ADDRESSABLE, which will be either a front-end
9140 : : or a tree optimizer bug. */
9141 : :
9142 : 9134522 : gcc_assert (MEM_P (result));
9143 : 9134522 : result = XEXP (result, 0);
9144 : :
9145 : : /* ??? Is this needed anymore? */
9146 : 9134522 : if (DECL_P (exp))
9147 : 9134522 : TREE_USED (exp) = 1;
9148 : :
9149 : 9134522 : if (modifier != EXPAND_INITIALIZER
9150 : : && modifier != EXPAND_CONST_ADDRESS
9151 : 9134522 : && modifier != EXPAND_SUM)
9152 : 4009889 : result = force_operand (result, target);
9153 : 9134522 : return result;
9154 : : }
9155 : :
9156 : : /* Pass FALSE as the last argument to get_inner_reference although
9157 : : we are expanding to RTL. The rationale is that we know how to
9158 : : handle "aligning nodes" here: we can just bypass them because
9159 : : they won't change the final object whose address will be returned
9160 : : (they actually exist only for that purpose). */
9161 : 1246303 : inner = get_inner_reference (exp, &bitsize, &bitpos, &offset, &mode1,
9162 : : &unsignedp, &reversep, &volatilep);
9163 : 1246303 : break;
9164 : : }
9165 : :
9166 : : /* We must have made progress. */
9167 : 1246469 : gcc_assert (inner != exp);
9168 : :
9169 : 1246469 : subtarget = offset || maybe_ne (bitpos, 0) ? NULL_RTX : target;
9170 : : /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
9171 : : inner alignment, force the inner to be sufficiently aligned. */
9172 : 1246469 : if (CONSTANT_CLASS_P (inner)
9173 : 1246469 : && TYPE_ALIGN (TREE_TYPE (inner)) < TYPE_ALIGN (TREE_TYPE (exp)))
9174 : : {
9175 : 0 : inner = copy_node (inner);
9176 : 0 : TREE_TYPE (inner) = copy_node (TREE_TYPE (inner));
9177 : 0 : SET_TYPE_ALIGN (TREE_TYPE (inner), TYPE_ALIGN (TREE_TYPE (exp)));
9178 : 0 : TYPE_USER_ALIGN (TREE_TYPE (inner)) = 1;
9179 : : }
9180 : 1246469 : result = expand_expr_addr_expr_1 (inner, subtarget, tmode, modifier, as);
9181 : :
9182 : 1246469 : if (offset)
9183 : : {
9184 : 48482 : rtx tmp;
9185 : :
9186 : 48482 : if (modifier != EXPAND_NORMAL)
9187 : 1829 : result = force_operand (result, NULL);
9188 : 50311 : tmp = expand_expr (offset, NULL_RTX, tmode,
9189 : : modifier == EXPAND_INITIALIZER
9190 : : ? EXPAND_INITIALIZER : EXPAND_NORMAL);
9191 : :
9192 : : /* expand_expr is allowed to return an object in a mode other
9193 : : than TMODE. If it did, we need to convert. */
9194 : 48482 : if (GET_MODE (tmp) != VOIDmode && tmode != GET_MODE (tmp))
9195 : 0 : tmp = convert_modes (tmode, GET_MODE (tmp),
9196 : 0 : tmp, TYPE_UNSIGNED (TREE_TYPE (offset)));
9197 : 48482 : result = convert_memory_address_addr_space (tmode, result, as);
9198 : 48482 : tmp = convert_memory_address_addr_space (tmode, tmp, as);
9199 : :
9200 : 48482 : if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
9201 : 1829 : result = simplify_gen_binary (PLUS, tmode, result, tmp);
9202 : : else
9203 : : {
9204 : 46653 : subtarget = maybe_ne (bitpos, 0) ? NULL_RTX : target;
9205 : 46653 : result = expand_simple_binop (tmode, PLUS, result, tmp, subtarget,
9206 : : 1, OPTAB_LIB_WIDEN);
9207 : : }
9208 : : }
9209 : :
9210 : 1246469 : if (maybe_ne (bitpos, 0))
9211 : : {
9212 : : /* Someone beforehand should have rejected taking the address
9213 : : of an object that isn't byte-aligned. */
9214 : 640343 : poly_int64 bytepos = exact_div (bitpos, BITS_PER_UNIT);
9215 : 640343 : result = convert_memory_address_addr_space (tmode, result, as);
9216 : 640343 : result = plus_constant (tmode, result, bytepos);
9217 : 640343 : if (modifier < EXPAND_SUM)
9218 : 606468 : result = force_operand (result, target);
9219 : : }
9220 : :
9221 : : return result;
9222 : : }
9223 : :
9224 : : /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
9225 : : The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
9226 : :
9227 : : static rtx
9228 : 12278628 : expand_expr_addr_expr (tree exp, rtx target, machine_mode tmode,
9229 : : enum expand_modifier modifier)
9230 : : {
9231 : 12278628 : addr_space_t as = ADDR_SPACE_GENERIC;
9232 : 12278628 : scalar_int_mode address_mode = Pmode;
9233 : 12278628 : scalar_int_mode pointer_mode = ptr_mode;
9234 : 12278628 : machine_mode rmode;
9235 : 12278628 : rtx result;
9236 : :
9237 : : /* Target mode of VOIDmode says "whatever's natural". */
9238 : 12278628 : if (tmode == VOIDmode)
9239 : 10387488 : tmode = TYPE_MODE (TREE_TYPE (exp));
9240 : :
9241 : 12278628 : if (POINTER_TYPE_P (TREE_TYPE (exp)))
9242 : : {
9243 : 12278628 : as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)));
9244 : 12278628 : address_mode = targetm.addr_space.address_mode (as);
9245 : 12278628 : pointer_mode = targetm.addr_space.pointer_mode (as);
9246 : : }
9247 : :
9248 : : /* We can get called with some Weird Things if the user does silliness
9249 : : like "(short) &a". In that case, convert_memory_address won't do
9250 : : the right thing, so ignore the given target mode. */
9251 : 12278628 : scalar_int_mode new_tmode = (tmode == pointer_mode
9252 : 12278628 : ? pointer_mode
9253 : 12278628 : : address_mode);
9254 : :
9255 : 12278628 : result = expand_expr_addr_expr_1 (TREE_OPERAND (exp, 0), target,
9256 : : new_tmode, modifier, as);
9257 : :
9258 : : /* Despite expand_expr claims concerning ignoring TMODE when not
9259 : : strictly convenient, stuff breaks if we don't honor it. Note
9260 : : that combined with the above, we only do this for pointer modes. */
9261 : 12278628 : rmode = GET_MODE (result);
9262 : 12278628 : if (rmode == VOIDmode)
9263 : 6 : rmode = new_tmode;
9264 : 12278628 : if (rmode != new_tmode)
9265 : 65 : result = convert_memory_address_addr_space (new_tmode, result, as);
9266 : :
9267 : 12278628 : return result;
9268 : : }
9269 : :
9270 : : /* Generate code for computing CONSTRUCTOR EXP.
9271 : : An rtx for the computed value is returned. If AVOID_TEMP_MEM
9272 : : is TRUE, instead of creating a temporary variable in memory
9273 : : NULL is returned and the caller needs to handle it differently. */
9274 : :
9275 : : static rtx
9276 : 194977 : expand_constructor (tree exp, rtx target, enum expand_modifier modifier,
9277 : : bool avoid_temp_mem)
9278 : : {
9279 : 194977 : tree type = TREE_TYPE (exp);
9280 : 194977 : machine_mode mode = TYPE_MODE (type);
9281 : :
9282 : : /* Try to avoid creating a temporary at all. This is possible
9283 : : if all of the initializer is zero.
9284 : : FIXME: try to handle all [0..255] initializers we can handle
9285 : : with memset. */
9286 : 194977 : if (TREE_STATIC (exp)
9287 : 194977 : && !TREE_ADDRESSABLE (exp)
9288 : 3198 : && target != 0 && mode == BLKmode
9289 : 197372 : && all_zeros_p (exp))
9290 : : {
9291 : 2390 : clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
9292 : 2390 : return target;
9293 : : }
9294 : :
9295 : : /* All elts simple constants => refer to a constant in memory. But
9296 : : if this is a non-BLKmode mode, let it store a field at a time
9297 : : since that should make a CONST_INT, CONST_WIDE_INT or
9298 : : CONST_DOUBLE when we fold. Likewise, if we have a target we can
9299 : : use, it is best to store directly into the target unless the type
9300 : : is large enough that memcpy will be used. If we are making an
9301 : : initializer and all operands are constant, put it in memory as
9302 : : well.
9303 : :
9304 : : FIXME: Avoid trying to fill vector constructors piece-meal.
9305 : : Output them with output_constant_def below unless we're sure
9306 : : they're zeros. This should go away when vector initializers
9307 : : are treated like VECTOR_CST instead of arrays. */
9308 : 192587 : if ((TREE_STATIC (exp)
9309 : 808 : && ((mode == BLKmode
9310 : 50 : && ! (target != 0 && safe_from_p (target, exp, 1)))
9311 : 763 : || TREE_ADDRESSABLE (exp)
9312 : 763 : || (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type))
9313 : 763 : && (! can_move_by_pieces
9314 : 763 : (tree_to_uhwi (TYPE_SIZE_UNIT (type)),
9315 : 763 : TYPE_ALIGN (type)))
9316 : 2 : && ! mostly_zeros_p (exp))))
9317 : 193348 : || ((modifier == EXPAND_INITIALIZER || modifier == EXPAND_CONST_ADDRESS)
9318 : 0 : && TREE_CONSTANT (exp)))
9319 : : {
9320 : 47 : rtx constructor;
9321 : :
9322 : 47 : if (avoid_temp_mem)
9323 : : return NULL_RTX;
9324 : :
9325 : 45 : constructor = expand_expr_constant (exp, 1, modifier);
9326 : :
9327 : 45 : if (modifier != EXPAND_CONST_ADDRESS
9328 : : && modifier != EXPAND_INITIALIZER
9329 : 45 : && modifier != EXPAND_SUM)
9330 : 45 : constructor = validize_mem (constructor);
9331 : :
9332 : 45 : return constructor;
9333 : : }
9334 : :
9335 : : /* If the CTOR is available in static storage and not mostly
9336 : : zeros and we can move it by pieces prefer to do so since
9337 : : that's usually more efficient than performing a series of
9338 : : stores from immediates. */
9339 : 192540 : if (avoid_temp_mem
9340 : 60 : && TREE_STATIC (exp)
9341 : 36 : && TREE_CONSTANT (exp)
9342 : 36 : && tree_fits_uhwi_p (TYPE_SIZE_UNIT (type))
9343 : 36 : && can_move_by_pieces (tree_to_uhwi (TYPE_SIZE_UNIT (type)),
9344 : 36 : TYPE_ALIGN (type))
9345 : 192576 : && ! mostly_zeros_p (exp))
9346 : : return NULL_RTX;
9347 : :
9348 : : /* Handle calls that pass values in multiple non-contiguous
9349 : : locations. The Irix 6 ABI has examples of this. */
9350 : 135217 : if (target == 0 || ! safe_from_p (target, exp, 1)
9351 : 28427 : || GET_CODE (target) == PARALLEL || modifier == EXPAND_STACK_PARM
9352 : : /* Also make a temporary if the store is to volatile memory, to
9353 : : avoid individual accesses to aggregate members. */
9354 : 220927 : || (GET_CODE (target) == MEM
9355 : 26322 : && MEM_VOLATILE_P (target)
9356 : 144 : && !TREE_ADDRESSABLE (TREE_TYPE (exp))))
9357 : : {
9358 : 164229 : if (avoid_temp_mem)
9359 : : return NULL_RTX;
9360 : :
9361 : 164218 : target = assign_temp (type, TREE_ADDRESSABLE (exp), 1);
9362 : : }
9363 : :
9364 : 192499 : store_constructor (exp, target, 0, int_expr_size (exp), false);
9365 : 192499 : return target;
9366 : : }
9367 : :
9368 : :
9369 : : /* expand_expr: generate code for computing expression EXP.
9370 : : An rtx for the computed value is returned. The value is never null.
9371 : : In the case of a void EXP, const0_rtx is returned.
9372 : :
9373 : : The value may be stored in TARGET if TARGET is nonzero.
9374 : : TARGET is just a suggestion; callers must assume that
9375 : : the rtx returned may not be the same as TARGET.
9376 : :
9377 : : If TARGET is CONST0_RTX, it means that the value will be ignored.
9378 : :
9379 : : If TMODE is not VOIDmode, it suggests generating the
9380 : : result in mode TMODE. But this is done only when convenient.
9381 : : Otherwise, TMODE is ignored and the value generated in its natural mode.
9382 : : TMODE is just a suggestion; callers must assume that
9383 : : the rtx returned may not have mode TMODE.
9384 : :
9385 : : Note that TARGET may have neither TMODE nor MODE. In that case, it
9386 : : probably will not be used.
9387 : :
9388 : : If MODIFIER is EXPAND_SUM then when EXP is an addition
9389 : : we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
9390 : : or a nest of (PLUS ...) and (MINUS ...) where the terms are
9391 : : products as above, or REG or MEM, or constant.
9392 : : Ordinarily in such cases we would output mul or add instructions
9393 : : and then return a pseudo reg containing the sum.
9394 : :
9395 : : EXPAND_INITIALIZER is much like EXPAND_SUM except that
9396 : : it also marks a label as absolutely required (it can't be dead).
9397 : : It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
9398 : : This is used for outputting expressions used in initializers.
9399 : :
9400 : : EXPAND_CONST_ADDRESS says that it is okay to return a MEM
9401 : : with a constant address even if that address is not normally legitimate.
9402 : : EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
9403 : :
9404 : : EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
9405 : : a call parameter. Such targets require special care as we haven't yet
9406 : : marked TARGET so that it's safe from being trashed by libcalls. We
9407 : : don't want to use TARGET for anything but the final result;
9408 : : Intermediate values must go elsewhere. Additionally, calls to
9409 : : emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
9410 : :
9411 : : If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
9412 : : address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
9413 : : DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
9414 : : COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
9415 : : recursively.
9416 : : If the result can be stored at TARGET, and ALT_RTL is non-NULL,
9417 : : then *ALT_RTL is set to TARGET (before legitimziation).
9418 : :
9419 : : If INNER_REFERENCE_P is true, we are expanding an inner reference.
9420 : : In this case, we don't adjust a returned MEM rtx that wouldn't be
9421 : : sufficiently aligned for its mode; instead, it's up to the caller
9422 : : to deal with it afterwards. This is used to make sure that unaligned
9423 : : base objects for which out-of-bounds accesses are supported, for
9424 : : example record types with trailing arrays, aren't realigned behind
9425 : : the back of the caller.
9426 : : The normal operating mode is to pass FALSE for this parameter. */
9427 : :
9428 : : rtx
9429 : 143853940 : expand_expr_real (tree exp, rtx target, machine_mode tmode,
9430 : : enum expand_modifier modifier, rtx *alt_rtl,
9431 : : bool inner_reference_p)
9432 : : {
9433 : 143853940 : rtx ret;
9434 : :
9435 : : /* Handle ERROR_MARK before anybody tries to access its type. */
9436 : 143853940 : if (TREE_CODE (exp) == ERROR_MARK
9437 : 143853940 : || (TREE_CODE (TREE_TYPE (exp)) == ERROR_MARK))
9438 : : {
9439 : 0 : ret = CONST0_RTX (tmode);
9440 : 0 : return ret ? ret : const0_rtx;
9441 : : }
9442 : :
9443 : 143853940 : ret = expand_expr_real_1 (exp, target, tmode, modifier, alt_rtl,
9444 : : inner_reference_p);
9445 : 143853940 : return ret;
9446 : : }
9447 : :
9448 : : /* Try to expand the conditional expression which is represented by
9449 : : TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If it succeeds
9450 : : return the rtl reg which represents the result. Otherwise return
9451 : : NULL_RTX. */
9452 : :
9453 : : static rtx
9454 : 11646 : expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED,
9455 : : tree treeop1 ATTRIBUTE_UNUSED,
9456 : : tree treeop2 ATTRIBUTE_UNUSED)
9457 : : {
9458 : 11646 : rtx insn;
9459 : 11646 : rtx op00, op01, op1, op2;
9460 : 11646 : enum rtx_code comparison_code;
9461 : 11646 : machine_mode comparison_mode;
9462 : 11646 : gimple *srcstmt;
9463 : 11646 : rtx temp;
9464 : 11646 : tree type = TREE_TYPE (treeop1);
9465 : 11646 : int unsignedp = TYPE_UNSIGNED (type);
9466 : 11646 : machine_mode mode = TYPE_MODE (type);
9467 : 11646 : machine_mode orig_mode = mode;
9468 : 11646 : static bool expanding_cond_expr_using_cmove = false;
9469 : :
9470 : : /* Conditional move expansion can end up TERing two operands which,
9471 : : when recursively hitting conditional expressions can result in
9472 : : exponential behavior if the cmove expansion ultimatively fails.
9473 : : It's hardly profitable to TER a cmove into a cmove so avoid doing
9474 : : that by failing early if we end up recursing. */
9475 : 11646 : if (expanding_cond_expr_using_cmove)
9476 : : return NULL_RTX;
9477 : :
9478 : : /* If we cannot do a conditional move on the mode, try doing it
9479 : : with the promoted mode. */
9480 : 10719 : if (!can_conditionally_move_p (mode))
9481 : : {
9482 : 147 : mode = promote_mode (type, mode, &unsignedp);
9483 : 147 : if (!can_conditionally_move_p (mode))
9484 : : return NULL_RTX;
9485 : 0 : temp = assign_temp (type, 0, 0); /* Use promoted mode for temp. */
9486 : : }
9487 : : else
9488 : 10572 : temp = assign_temp (type, 0, 1);
9489 : :
9490 : 10572 : expanding_cond_expr_using_cmove = true;
9491 : 10572 : start_sequence ();
9492 : 10572 : expand_operands (treeop1, treeop2,
9493 : : mode == orig_mode ? temp : NULL_RTX, &op1, &op2,
9494 : : EXPAND_NORMAL);
9495 : :
9496 : 10572 : if (TREE_CODE (treeop0) == SSA_NAME
9497 : 10572 : && (srcstmt = get_def_for_expr_class (treeop0, tcc_comparison)))
9498 : : {
9499 : 8308 : type = TREE_TYPE (gimple_assign_rhs1 (srcstmt));
9500 : 8308 : enum tree_code cmpcode = gimple_assign_rhs_code (srcstmt);
9501 : 8308 : op00 = expand_normal (gimple_assign_rhs1 (srcstmt));
9502 : 8308 : op01 = expand_normal (gimple_assign_rhs2 (srcstmt));
9503 : 8308 : comparison_mode = TYPE_MODE (type);
9504 : 8308 : unsignedp = TYPE_UNSIGNED (type);
9505 : 8308 : comparison_code = convert_tree_comp_to_rtx (cmpcode, unsignedp);
9506 : : }
9507 : 2264 : else if (COMPARISON_CLASS_P (treeop0))
9508 : : {
9509 : 29 : type = TREE_TYPE (TREE_OPERAND (treeop0, 0));
9510 : 29 : enum tree_code cmpcode = TREE_CODE (treeop0);
9511 : 29 : op00 = expand_normal (TREE_OPERAND (treeop0, 0));
9512 : 29 : op01 = expand_normal (TREE_OPERAND (treeop0, 1));
9513 : 29 : unsignedp = TYPE_UNSIGNED (type);
9514 : 29 : comparison_mode = TYPE_MODE (type);
9515 : 29 : comparison_code = convert_tree_comp_to_rtx (cmpcode, unsignedp);
9516 : : }
9517 : : else
9518 : : {
9519 : 2235 : op00 = expand_normal (treeop0);
9520 : 2235 : op01 = const0_rtx;
9521 : 2235 : comparison_code = NE;
9522 : 2235 : comparison_mode = GET_MODE (op00);
9523 : 2235 : if (comparison_mode == VOIDmode)
9524 : 0 : comparison_mode = TYPE_MODE (TREE_TYPE (treeop0));
9525 : : }
9526 : 10572 : expanding_cond_expr_using_cmove = false;
9527 : :
9528 : 10572 : if (GET_MODE (op1) != mode)
9529 : 2030 : op1 = gen_lowpart (mode, op1);
9530 : :
9531 : 10572 : if (GET_MODE (op2) != mode)
9532 : 4866 : op2 = gen_lowpart (mode, op2);
9533 : :
9534 : : /* Try to emit the conditional move. */
9535 : 10572 : insn = emit_conditional_move (temp,
9536 : : { comparison_code, op00, op01,
9537 : : comparison_mode },
9538 : : op1, op2, mode,
9539 : : unsignedp);
9540 : :
9541 : : /* If we could do the conditional move, emit the sequence,
9542 : : and return. */
9543 : 10572 : if (insn)
9544 : : {
9545 : 8962 : rtx_insn *seq = get_insns ();
9546 : 8962 : end_sequence ();
9547 : 8962 : emit_insn (seq);
9548 : 8962 : return convert_modes (orig_mode, mode, temp, 0);
9549 : : }
9550 : :
9551 : : /* Otherwise discard the sequence and fall back to code with
9552 : : branches. */
9553 : 1610 : end_sequence ();
9554 : 1610 : return NULL_RTX;
9555 : : }
9556 : :
9557 : : /* A helper function for expand_expr_real_2 to be used with a
9558 : : misaligned mem_ref TEMP. Assume an unsigned type if UNSIGNEDP
9559 : : is nonzero, with alignment ALIGN in bits.
9560 : : Store the value at TARGET if possible (if TARGET is nonzero).
9561 : : Regardless of TARGET, we return the rtx for where the value is placed.
9562 : : If the result can be stored at TARGET, and ALT_RTL is non-NULL,
9563 : : then *ALT_RTL is set to TARGET (before legitimziation). */
9564 : :
9565 : : static rtx
9566 : 194918 : expand_misaligned_mem_ref (rtx temp, machine_mode mode, int unsignedp,
9567 : : unsigned int align, rtx target, rtx *alt_rtl)
9568 : : {
9569 : 194918 : enum insn_code icode;
9570 : :
9571 : 194918 : if ((icode = optab_handler (movmisalign_optab, mode))
9572 : : != CODE_FOR_nothing)
9573 : : {
9574 : 111431 : class expand_operand ops[2];
9575 : :
9576 : : /* We've already validated the memory, and we're creating a
9577 : : new pseudo destination. The predicates really can't fail,
9578 : : nor can the generator. */
9579 : 111431 : create_output_operand (&ops[0], NULL_RTX, mode);
9580 : 111431 : create_fixed_operand (&ops[1], temp);
9581 : 111431 : expand_insn (icode, 2, ops);
9582 : 111431 : temp = ops[0].value;
9583 : : }
9584 : 83487 : else if (targetm.slow_unaligned_access (mode, align))
9585 : 0 : temp = extract_bit_field (temp, GET_MODE_BITSIZE (mode),
9586 : 0 : 0, unsignedp, target,
9587 : : mode, mode, false, alt_rtl);
9588 : 194918 : return temp;
9589 : : }
9590 : :
9591 : : /* Helper function of expand_expr_2, expand a division or modulo.
9592 : : op0 and op1 should be already expanded treeop0 and treeop1, using
9593 : : expand_operands. */
9594 : :
9595 : : static rtx
9596 : 138566 : expand_expr_divmod (tree_code code, machine_mode mode, tree treeop0,
9597 : : tree treeop1, rtx op0, rtx op1, rtx target, int unsignedp)
9598 : : {
9599 : 277132 : bool mod_p = (code == TRUNC_MOD_EXPR || code == FLOOR_MOD_EXPR
9600 : 138566 : || code == CEIL_MOD_EXPR || code == ROUND_MOD_EXPR);
9601 : 138566 : if (SCALAR_INT_MODE_P (mode)
9602 : 138566 : && optimize >= 2
9603 : 110408 : && get_range_pos_neg (treeop0) == 1
9604 : 162729 : && get_range_pos_neg (treeop1) == 1)
9605 : : {
9606 : : /* If both arguments are known to be positive when interpreted
9607 : : as signed, we can expand it as both signed and unsigned
9608 : : division or modulo. Choose the cheaper sequence in that case. */
9609 : 12923 : bool speed_p = optimize_insn_for_speed_p ();
9610 : 12923 : do_pending_stack_adjust ();
9611 : 12923 : start_sequence ();
9612 : 12923 : rtx uns_ret = expand_divmod (mod_p, code, mode, op0, op1, target, 1);
9613 : 12923 : rtx_insn *uns_insns = get_insns ();
9614 : 12923 : end_sequence ();
9615 : 12923 : start_sequence ();
9616 : 12923 : rtx sgn_ret = expand_divmod (mod_p, code, mode, op0, op1, target, 0);
9617 : 12923 : rtx_insn *sgn_insns = get_insns ();
9618 : 12923 : end_sequence ();
9619 : 12923 : unsigned uns_cost = seq_cost (uns_insns, speed_p);
9620 : 12923 : unsigned sgn_cost = seq_cost (sgn_insns, speed_p);
9621 : :
9622 : : /* If costs are the same then use as tie breaker the other other
9623 : : factor. */
9624 : 12923 : if (uns_cost == sgn_cost)
9625 : : {
9626 : 2078 : uns_cost = seq_cost (uns_insns, !speed_p);
9627 : 2078 : sgn_cost = seq_cost (sgn_insns, !speed_p);
9628 : : }
9629 : :
9630 : 12923 : if (uns_cost < sgn_cost || (uns_cost == sgn_cost && unsignedp))
9631 : : {
9632 : 11517 : emit_insn (uns_insns);
9633 : 11517 : return uns_ret;
9634 : : }
9635 : 1406 : emit_insn (sgn_insns);
9636 : 1406 : return sgn_ret;
9637 : : }
9638 : 125643 : return expand_divmod (mod_p, code, mode, op0, op1, target, unsignedp);
9639 : : }
9640 : :
9641 : : rtx
9642 : 11872780 : expand_expr_real_2 (sepops ops, rtx target, machine_mode tmode,
9643 : : enum expand_modifier modifier)
9644 : : {
9645 : 11872780 : rtx op0, op1, op2, temp;
9646 : 11872780 : rtx_code_label *lab;
9647 : 11872780 : tree type;
9648 : 11872780 : int unsignedp;
9649 : 11872780 : machine_mode mode;
9650 : 11872780 : scalar_int_mode int_mode;
9651 : 11872780 : enum tree_code code = ops->code;
9652 : 11872780 : optab this_optab;
9653 : 11872780 : rtx subtarget, original_target;
9654 : 11872780 : int ignore;
9655 : 11872780 : bool reduce_bit_field;
9656 : 11872780 : location_t loc = ops->location;
9657 : 11872780 : tree treeop0, treeop1, treeop2;
9658 : : #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
9659 : : ? reduce_to_bit_field_precision ((expr), \
9660 : : target, \
9661 : : type) \
9662 : : : (expr))
9663 : :
9664 : 11872780 : type = ops->type;
9665 : 11872780 : mode = TYPE_MODE (type);
9666 : 11872780 : unsignedp = TYPE_UNSIGNED (type);
9667 : :
9668 : 11872780 : treeop0 = ops->op0;
9669 : 11872780 : treeop1 = ops->op1;
9670 : 11872780 : treeop2 = ops->op2;
9671 : :
9672 : : /* We should be called only on simple (binary or unary) expressions,
9673 : : exactly those that are valid in gimple expressions that aren't
9674 : : GIMPLE_SINGLE_RHS (or invalid). */
9675 : 11872780 : gcc_assert (get_gimple_rhs_class (code) == GIMPLE_UNARY_RHS
9676 : : || get_gimple_rhs_class (code) == GIMPLE_BINARY_RHS
9677 : : || get_gimple_rhs_class (code) == GIMPLE_TERNARY_RHS);
9678 : :
9679 : 23745560 : ignore = (target == const0_rtx
9680 : 11872780 : || ((CONVERT_EXPR_CODE_P (code)
9681 : 8401412 : || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
9682 : 3483014 : && TREE_CODE (type) == VOID_TYPE));
9683 : :
9684 : : /* We should be called only if we need the result. */
9685 : 0 : gcc_assert (!ignore);
9686 : :
9687 : : /* An operation in what may be a bit-field type needs the
9688 : : result to be reduced to the precision of the bit-field type,
9689 : : which is narrower than that of the type's mode. */
9690 : 24371437 : reduce_bit_field = (INTEGRAL_TYPE_P (type)
9691 : 11872780 : && !type_has_mode_precision_p (type));
9692 : :
9693 : 625877 : if (reduce_bit_field
9694 : 625877 : && (modifier == EXPAND_STACK_PARM
9695 : 625368 : || (target && GET_MODE (target) != mode)))
9696 : 339564 : target = 0;
9697 : :
9698 : : /* Use subtarget as the target for operand 0 of a binary operation. */
9699 : 11872780 : subtarget = get_subtarget (target);
9700 : 11872780 : original_target = target;
9701 : :
9702 : 11872780 : switch (code)
9703 : : {
9704 : 3474275 : case NON_LVALUE_EXPR:
9705 : 3474275 : case PAREN_EXPR:
9706 : 3474275 : CASE_CONVERT:
9707 : 3474275 : if (treeop0 == error_mark_node)
9708 : 0 : return const0_rtx;
9709 : :
9710 : 3474275 : if (TREE_CODE (type) == UNION_TYPE)
9711 : : {
9712 : 0 : tree valtype = TREE_TYPE (treeop0);
9713 : :
9714 : : /* If both input and output are BLKmode, this conversion isn't doing
9715 : : anything except possibly changing memory attribute. */
9716 : 0 : if (mode == BLKmode && TYPE_MODE (valtype) == BLKmode)
9717 : : {
9718 : 0 : rtx result = expand_expr (treeop0, target, tmode,
9719 : : modifier);
9720 : :
9721 : 0 : result = copy_rtx (result);
9722 : 0 : set_mem_attributes (result, type, 0);
9723 : 0 : return result;
9724 : : }
9725 : :
9726 : 0 : if (target == 0)
9727 : : {
9728 : 0 : if (TYPE_MODE (type) != BLKmode)
9729 : 0 : target = gen_reg_rtx (TYPE_MODE (type));
9730 : : else
9731 : 0 : target = assign_temp (type, 1, 1);
9732 : : }
9733 : :
9734 : 0 : if (MEM_P (target))
9735 : : /* Store data into beginning of memory target. */
9736 : 0 : store_expr (treeop0,
9737 : 0 : adjust_address (target, TYPE_MODE (valtype), 0),
9738 : : modifier == EXPAND_STACK_PARM,
9739 : 0 : false, TYPE_REVERSE_STORAGE_ORDER (type));
9740 : :
9741 : : else
9742 : : {
9743 : 0 : gcc_assert (REG_P (target)
9744 : : && !TYPE_REVERSE_STORAGE_ORDER (type));
9745 : :
9746 : : /* Store this field into a union of the proper type. */
9747 : 0 : poly_uint64 op0_size
9748 : 0 : = tree_to_poly_uint64 (TYPE_SIZE (TREE_TYPE (treeop0)));
9749 : 0 : poly_uint64 union_size = GET_MODE_BITSIZE (mode);
9750 : 0 : store_field (target,
9751 : : /* The conversion must be constructed so that
9752 : : we know at compile time how many bits
9753 : : to preserve. */
9754 : 0 : ordered_min (op0_size, union_size),
9755 : 0 : 0, 0, 0, TYPE_MODE (valtype), treeop0, 0,
9756 : : false, false);
9757 : : }
9758 : :
9759 : : /* Return the entire union. */
9760 : 0 : return target;
9761 : : }
9762 : :
9763 : 3474275 : if (mode == TYPE_MODE (TREE_TYPE (treeop0)))
9764 : : {
9765 : 1992765 : op0 = expand_expr (treeop0, target, VOIDmode,
9766 : : modifier);
9767 : :
9768 : 1992765 : return REDUCE_BIT_FIELD (op0);
9769 : : }
9770 : :
9771 : 1828772 : op0 = expand_expr (treeop0, NULL_RTX, mode,
9772 : : modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier);
9773 : 1481510 : if (GET_MODE (op0) == mode)
9774 : : ;
9775 : :
9776 : : /* If OP0 is a constant, just convert it into the proper mode. */
9777 : 1444448 : else if (CONSTANT_P (op0))
9778 : : {
9779 : 887 : tree inner_type = TREE_TYPE (treeop0);
9780 : 887 : machine_mode inner_mode = GET_MODE (op0);
9781 : :
9782 : 887 : if (inner_mode == VOIDmode)
9783 : 12 : inner_mode = TYPE_MODE (inner_type);
9784 : :
9785 : 887 : if (modifier == EXPAND_INITIALIZER)
9786 : 0 : op0 = lowpart_subreg (mode, op0, inner_mode);
9787 : : else
9788 : 887 : op0= convert_modes (mode, inner_mode, op0,
9789 : 887 : TYPE_UNSIGNED (inner_type));
9790 : : }
9791 : :
9792 : 1443561 : else if (modifier == EXPAND_INITIALIZER)
9793 : 18 : op0 = gen_rtx_fmt_e (TYPE_UNSIGNED (TREE_TYPE (treeop0))
9794 : : ? ZERO_EXTEND : SIGN_EXTEND, mode, op0);
9795 : :
9796 : 1443549 : else if (target == 0)
9797 : 898331 : op0 = convert_to_mode (mode, op0,
9798 : 898331 : TYPE_UNSIGNED (TREE_TYPE
9799 : : (treeop0)));
9800 : : else
9801 : : {
9802 : 1090436 : convert_move (target, op0,
9803 : 545218 : TYPE_UNSIGNED (TREE_TYPE (treeop0)));
9804 : 545218 : op0 = target;
9805 : : }
9806 : :
9807 : 1481510 : return REDUCE_BIT_FIELD (op0);
9808 : :
9809 : 0 : case ADDR_SPACE_CONVERT_EXPR:
9810 : 0 : {
9811 : 0 : tree treeop0_type = TREE_TYPE (treeop0);
9812 : :
9813 : 0 : gcc_assert (POINTER_TYPE_P (type));
9814 : 0 : gcc_assert (POINTER_TYPE_P (treeop0_type));
9815 : :
9816 : 0 : addr_space_t as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
9817 : 0 : addr_space_t as_from = TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type));
9818 : :
9819 : : /* Conversions between pointers to the same address space should
9820 : : have been implemented via CONVERT_EXPR / NOP_EXPR. */
9821 : 0 : gcc_assert (as_to != as_from);
9822 : :
9823 : 0 : op0 = expand_expr (treeop0, NULL_RTX, VOIDmode, modifier);
9824 : :
9825 : : /* Ask target code to handle conversion between pointers
9826 : : to overlapping address spaces. */
9827 : 0 : if (targetm.addr_space.subset_p (as_to, as_from)
9828 : 0 : || targetm.addr_space.subset_p (as_from, as_to))
9829 : : {
9830 : 0 : op0 = targetm.addr_space.convert (op0, treeop0_type, type);
9831 : : }
9832 : : else
9833 : : {
9834 : : /* For disjoint address spaces, converting anything but a null
9835 : : pointer invokes undefined behavior. We truncate or extend the
9836 : : value as if we'd converted via integers, which handles 0 as
9837 : : required, and all others as the programmer likely expects. */
9838 : : #ifndef POINTERS_EXTEND_UNSIGNED
9839 : : const int POINTERS_EXTEND_UNSIGNED = 1;
9840 : : #endif
9841 : 0 : op0 = convert_modes (mode, TYPE_MODE (treeop0_type),
9842 : : op0, POINTERS_EXTEND_UNSIGNED);
9843 : : }
9844 : 0 : gcc_assert (op0);
9845 : : return op0;
9846 : : }
9847 : :
9848 : 1291297 : case POINTER_PLUS_EXPR:
9849 : : /* Even though the sizetype mode and the pointer's mode can be different
9850 : : expand is able to handle this correctly and get the correct result out
9851 : : of the PLUS_EXPR code. */
9852 : : /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
9853 : : if sizetype precision is smaller than pointer precision. */
9854 : 1291297 : if (TYPE_PRECISION (sizetype) < TYPE_PRECISION (type))
9855 : 0 : treeop1 = fold_convert_loc (loc, type,
9856 : : fold_convert_loc (loc, ssizetype,
9857 : : treeop1));
9858 : : /* If sizetype precision is larger than pointer precision, truncate the
9859 : : offset to have matching modes. */
9860 : 1291297 : else if (TYPE_PRECISION (sizetype) > TYPE_PRECISION (type))
9861 : 0 : treeop1 = fold_convert_loc (loc, type, treeop1);
9862 : : /* FALLTHRU */
9863 : :
9864 : 4780762 : case PLUS_EXPR:
9865 : : /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
9866 : : something else, make sure we add the register to the constant and
9867 : : then to the other thing. This case can occur during strength
9868 : : reduction and doing it this way will produce better code if the
9869 : : frame pointer or argument pointer is eliminated.
9870 : :
9871 : : fold-const.cc will ensure that the constant is always in the inner
9872 : : PLUS_EXPR, so the only case we need to do anything about is if
9873 : : sp, ap, or fp is our second argument, in which case we must swap
9874 : : the innermost first argument and our second argument. */
9875 : :
9876 : 4780762 : if (TREE_CODE (treeop0) == PLUS_EXPR
9877 : 6576 : && TREE_CODE (TREE_OPERAND (treeop0, 1)) == INTEGER_CST
9878 : 0 : && VAR_P (treeop1)
9879 : 4780762 : && (DECL_RTL (treeop1) == frame_pointer_rtx
9880 : 0 : || DECL_RTL (treeop1) == stack_pointer_rtx
9881 : 0 : || DECL_RTL (treeop1) == arg_pointer_rtx))
9882 : : {
9883 : 0 : gcc_unreachable ();
9884 : : }
9885 : :
9886 : : /* If the result is to be ptr_mode and we are adding an integer to
9887 : : something, we might be forming a constant. So try to use
9888 : : plus_constant. If it produces a sum and we can't accept it,
9889 : : use force_operand. This allows P = &ARR[const] to generate
9890 : : efficient code on machines where a SYMBOL_REF is not a valid
9891 : : address.
9892 : :
9893 : : If this is an EXPAND_SUM call, always return the sum. */
9894 : 4780762 : if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER
9895 : 4780762 : || (mode == ptr_mode && (unsignedp || ! flag_trapv)))
9896 : : {
9897 : 3042028 : if (modifier == EXPAND_STACK_PARM)
9898 : 18582 : target = 0;
9899 : 3042028 : if (TREE_CODE (treeop0) == INTEGER_CST
9900 : 1007 : && HWI_COMPUTABLE_MODE_P (mode)
9901 : 3043035 : && TREE_CONSTANT (treeop1))
9902 : : {
9903 : 4 : rtx constant_part;
9904 : 4 : HOST_WIDE_INT wc;
9905 : 4 : machine_mode wmode = TYPE_MODE (TREE_TYPE (treeop1));
9906 : :
9907 : 4 : op1 = expand_expr (treeop1, subtarget, VOIDmode,
9908 : : EXPAND_SUM);
9909 : : /* Use wi::shwi to ensure that the constant is
9910 : : truncated according to the mode of OP1, then sign extended
9911 : : to a HOST_WIDE_INT. Using the constant directly can result
9912 : : in non-canonical RTL in a 64x32 cross compile. */
9913 : 4 : wc = TREE_INT_CST_LOW (treeop0);
9914 : 4 : constant_part =
9915 : 4 : immed_wide_int_const (wi::shwi (wc, wmode), wmode);
9916 : 4 : op1 = plus_constant (mode, op1, INTVAL (constant_part));
9917 : 4 : if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
9918 : 1 : op1 = force_operand (op1, target);
9919 : 4 : return REDUCE_BIT_FIELD (op1);
9920 : : }
9921 : :
9922 : 3042024 : else if (TREE_CODE (treeop1) == INTEGER_CST
9923 : 2061405 : && HWI_COMPUTABLE_MODE_P (mode)
9924 : 5103429 : && TREE_CONSTANT (treeop0))
9925 : : {
9926 : 278863 : rtx constant_part;
9927 : 278863 : HOST_WIDE_INT wc;
9928 : 278863 : machine_mode wmode = TYPE_MODE (TREE_TYPE (treeop0));
9929 : :
9930 : 484551 : op0 = expand_expr (treeop0, subtarget, VOIDmode,
9931 : : (modifier == EXPAND_INITIALIZER
9932 : : ? EXPAND_INITIALIZER : EXPAND_SUM));
9933 : 278863 : if (! CONSTANT_P (op0))
9934 : : {
9935 : 6 : op1 = expand_expr (treeop1, NULL_RTX,
9936 : : VOIDmode, modifier);
9937 : : /* Return a PLUS if modifier says it's OK. */
9938 : 6 : if (modifier == EXPAND_SUM
9939 : : || modifier == EXPAND_INITIALIZER)
9940 : 6 : return simplify_gen_binary (PLUS, mode, op0, op1);
9941 : 0 : goto binop2;
9942 : : }
9943 : : /* Use wi::shwi to ensure that the constant is
9944 : : truncated according to the mode of OP1, then sign extended
9945 : : to a HOST_WIDE_INT. Using the constant directly can result
9946 : : in non-canonical RTL in a 64x32 cross compile. */
9947 : 278857 : wc = TREE_INT_CST_LOW (treeop1);
9948 : 278857 : constant_part
9949 : 278857 : = immed_wide_int_const (wi::shwi (wc, wmode), wmode);
9950 : 278857 : op0 = plus_constant (mode, op0, INTVAL (constant_part));
9951 : 278857 : if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
9952 : 204955 : op0 = force_operand (op0, target);
9953 : 278857 : return REDUCE_BIT_FIELD (op0);
9954 : : }
9955 : : }
9956 : :
9957 : : /* Use TER to expand pointer addition of a negated value
9958 : : as pointer subtraction. */
9959 : 8011144 : if ((POINTER_TYPE_P (TREE_TYPE (treeop0))
9960 : 3489452 : || (TREE_CODE (TREE_TYPE (treeop0)) == VECTOR_TYPE
9961 : 66189 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0)))))
9962 : 1012443 : && TREE_CODE (treeop1) == SSA_NAME
9963 : 5541131 : && TYPE_MODE (TREE_TYPE (treeop0))
9964 : 519618 : == TYPE_MODE (TREE_TYPE (treeop1)))
9965 : : {
9966 : 519618 : gimple *def = get_def_for_expr (treeop1, NEGATE_EXPR);
9967 : 519618 : if (def)
9968 : : {
9969 : 3232 : treeop1 = gimple_assign_rhs1 (def);
9970 : 3232 : code = MINUS_EXPR;
9971 : 3232 : goto do_minus;
9972 : : }
9973 : : }
9974 : :
9975 : : /* No sense saving up arithmetic to be done
9976 : : if it's all in the wrong mode to form part of an address.
9977 : : And force_operand won't know whether to sign-extend or
9978 : : zero-extend. */
9979 : 4498663 : if (modifier != EXPAND_INITIALIZER
9980 : 4498663 : && (modifier != EXPAND_SUM || mode != ptr_mode))
9981 : : {
9982 : 3982446 : expand_operands (treeop0, treeop1,
9983 : : subtarget, &op0, &op1, modifier);
9984 : 3982446 : if (op0 == const0_rtx)
9985 : 8050 : return op1;
9986 : 3974396 : if (op1 == const0_rtx)
9987 : : return op0;
9988 : 3974135 : goto binop2;
9989 : : }
9990 : :
9991 : 516217 : expand_operands (treeop0, treeop1,
9992 : : subtarget, &op0, &op1, modifier);
9993 : 516217 : return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
9994 : :
9995 : 438465 : case MINUS_EXPR:
9996 : 438465 : case POINTER_DIFF_EXPR:
9997 : 438465 : do_minus:
9998 : : /* For initializers, we are allowed to return a MINUS of two
9999 : : symbolic constants. Here we handle all cases when both operands
10000 : : are constant. */
10001 : : /* Handle difference of two symbolic constants,
10002 : : for the sake of an initializer. */
10003 : 438465 : if ((modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
10004 : 2843 : && really_constant_p (treeop0)
10005 : 438929 : && really_constant_p (treeop1))
10006 : : {
10007 : 68 : expand_operands (treeop0, treeop1,
10008 : : NULL_RTX, &op0, &op1, modifier);
10009 : 68 : return simplify_gen_binary (MINUS, mode, op0, op1);
10010 : : }
10011 : :
10012 : : /* No sense saving up arithmetic to be done
10013 : : if it's all in the wrong mode to form part of an address.
10014 : : And force_operand won't know whether to sign-extend or
10015 : : zero-extend. */
10016 : 438397 : if (modifier != EXPAND_INITIALIZER
10017 : 438397 : && (modifier != EXPAND_SUM || mode != ptr_mode))
10018 : 435622 : goto binop;
10019 : :
10020 : 2775 : expand_operands (treeop0, treeop1,
10021 : : subtarget, &op0, &op1, modifier);
10022 : :
10023 : : /* Convert A - const to A + (-const). */
10024 : 2775 : if (CONST_INT_P (op1))
10025 : : {
10026 : 0 : op1 = negate_rtx (mode, op1);
10027 : 0 : return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
10028 : : }
10029 : :
10030 : 2775 : goto binop2;
10031 : :
10032 : 0 : case WIDEN_MULT_PLUS_EXPR:
10033 : 0 : case WIDEN_MULT_MINUS_EXPR:
10034 : 0 : expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
10035 : 0 : op2 = expand_normal (treeop2);
10036 : 0 : target = expand_widen_pattern_expr (ops, op0, op1, op2,
10037 : : target, unsignedp);
10038 : 0 : return target;
10039 : :
10040 : 18776 : case WIDEN_MULT_EXPR:
10041 : : /* If first operand is constant, swap them.
10042 : : Thus the following special case checks need only
10043 : : check the second operand. */
10044 : 18776 : if (TREE_CODE (treeop0) == INTEGER_CST)
10045 : 368 : std::swap (treeop0, treeop1);
10046 : :
10047 : : /* First, check if we have a multiplication of one signed and one
10048 : : unsigned operand. */
10049 : 18776 : if (TREE_CODE (treeop1) != INTEGER_CST
10050 : 18776 : && (TYPE_UNSIGNED (TREE_TYPE (treeop0))
10051 : 14307 : != TYPE_UNSIGNED (TREE_TYPE (treeop1))))
10052 : : {
10053 : 0 : machine_mode innermode = TYPE_MODE (TREE_TYPE (treeop0));
10054 : 0 : this_optab = usmul_widen_optab;
10055 : 0 : if (find_widening_optab_handler (this_optab, mode, innermode)
10056 : : != CODE_FOR_nothing)
10057 : : {
10058 : 0 : if (TYPE_UNSIGNED (TREE_TYPE (treeop0)))
10059 : 0 : expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
10060 : : EXPAND_NORMAL);
10061 : : else
10062 : 0 : expand_operands (treeop0, treeop1, NULL_RTX, &op1, &op0,
10063 : : EXPAND_NORMAL);
10064 : : /* op0 and op1 might still be constant, despite the above
10065 : : != INTEGER_CST check. Handle it. */
10066 : 0 : if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
10067 : : {
10068 : 0 : op0 = convert_modes (mode, innermode, op0, true);
10069 : 0 : op1 = convert_modes (mode, innermode, op1, false);
10070 : 0 : return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1,
10071 : : target, unsignedp));
10072 : : }
10073 : 0 : goto binop3;
10074 : : }
10075 : : }
10076 : : /* Check for a multiplication with matching signedness. */
10077 : 18776 : else if ((TREE_CODE (treeop1) == INTEGER_CST
10078 : 4469 : && int_fits_type_p (treeop1, TREE_TYPE (treeop0)))
10079 : 18776 : || (TYPE_UNSIGNED (TREE_TYPE (treeop1))
10080 : 14307 : == TYPE_UNSIGNED (TREE_TYPE (treeop0))))
10081 : : {
10082 : 18776 : tree op0type = TREE_TYPE (treeop0);
10083 : 18776 : machine_mode innermode = TYPE_MODE (op0type);
10084 : 18776 : bool zextend_p = TYPE_UNSIGNED (op0type);
10085 : 18776 : optab other_optab = zextend_p ? smul_widen_optab : umul_widen_optab;
10086 : 2607 : this_optab = zextend_p ? umul_widen_optab : smul_widen_optab;
10087 : :
10088 : 18776 : if (TREE_CODE (treeop0) != INTEGER_CST)
10089 : : {
10090 : 18776 : if (find_widening_optab_handler (this_optab, mode, innermode)
10091 : : != CODE_FOR_nothing)
10092 : : {
10093 : 18776 : expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
10094 : : EXPAND_NORMAL);
10095 : : /* op0 and op1 might still be constant, despite the above
10096 : : != INTEGER_CST check. Handle it. */
10097 : 18776 : if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
10098 : : {
10099 : 0 : widen_mult_const:
10100 : 0 : op0 = convert_modes (mode, innermode, op0, zextend_p);
10101 : 0 : op1
10102 : 0 : = convert_modes (mode, innermode, op1,
10103 : 0 : TYPE_UNSIGNED (TREE_TYPE (treeop1)));
10104 : 0 : return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1,
10105 : : target,
10106 : : unsignedp));
10107 : : }
10108 : 18776 : temp = expand_widening_mult (mode, op0, op1, target,
10109 : : unsignedp, this_optab);
10110 : 18776 : return REDUCE_BIT_FIELD (temp);
10111 : : }
10112 : 0 : if (find_widening_optab_handler (other_optab, mode, innermode)
10113 : : != CODE_FOR_nothing
10114 : 0 : && innermode == word_mode)
10115 : : {
10116 : 0 : rtx htem, hipart;
10117 : 0 : op0 = expand_normal (treeop0);
10118 : 0 : op1 = expand_normal (treeop1);
10119 : : /* op0 and op1 might be constants, despite the above
10120 : : != INTEGER_CST check. Handle it. */
10121 : 0 : if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
10122 : 0 : goto widen_mult_const;
10123 : 0 : temp = expand_binop (mode, other_optab, op0, op1, target,
10124 : : unsignedp, OPTAB_LIB_WIDEN);
10125 : 0 : hipart = gen_highpart (word_mode, temp);
10126 : 0 : htem = expand_mult_highpart_adjust (word_mode, hipart,
10127 : : op0, op1, hipart,
10128 : : zextend_p);
10129 : 0 : if (htem != hipart)
10130 : 0 : emit_move_insn (hipart, htem);
10131 : 0 : return REDUCE_BIT_FIELD (temp);
10132 : : }
10133 : : }
10134 : : }
10135 : 0 : treeop0 = fold_build1 (CONVERT_EXPR, type, treeop0);
10136 : 0 : treeop1 = fold_build1 (CONVERT_EXPR, type, treeop1);
10137 : 0 : expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
10138 : 0 : return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
10139 : :
10140 : 1209490 : case MULT_EXPR:
10141 : : /* If this is a fixed-point operation, then we cannot use the code
10142 : : below because "expand_mult" doesn't support sat/no-sat fixed-point
10143 : : multiplications. */
10144 : 1209490 : if (ALL_FIXED_POINT_MODE_P (mode))
10145 : 0 : goto binop;
10146 : :
10147 : : /* If first operand is constant, swap them.
10148 : : Thus the following special case checks need only
10149 : : check the second operand. */
10150 : 1209490 : if (TREE_CODE (treeop0) == INTEGER_CST)
10151 : 686 : std::swap (treeop0, treeop1);
10152 : :
10153 : : /* Attempt to return something suitable for generating an
10154 : : indexed address, for machines that support that. */
10155 : :
10156 : 489107 : if (modifier == EXPAND_SUM && mode == ptr_mode
10157 : 1698597 : && tree_fits_shwi_p (treeop1))
10158 : : {
10159 : 483862 : tree exp1 = treeop1;
10160 : :
10161 : 483862 : op0 = expand_expr (treeop0, subtarget, VOIDmode,
10162 : : EXPAND_SUM);
10163 : :
10164 : 483862 : if (!REG_P (op0))
10165 : 234022 : op0 = force_operand (op0, NULL_RTX);
10166 : 483862 : if (!REG_P (op0))
10167 : 1576 : op0 = copy_to_mode_reg (mode, op0);
10168 : :
10169 : 483862 : op1 = gen_int_mode (tree_to_shwi (exp1),
10170 : 483862 : TYPE_MODE (TREE_TYPE (exp1)));
10171 : 483862 : return REDUCE_BIT_FIELD (gen_rtx_MULT (mode, op0, op1));
10172 : : }
10173 : :
10174 : 725628 : if (modifier == EXPAND_STACK_PARM)
10175 : 2956 : target = 0;
10176 : :
10177 : 725628 : if (SCALAR_INT_MODE_P (mode) && optimize >= 2)
10178 : : {
10179 : 417728 : gimple *def_stmt0 = get_def_for_expr (treeop0, TRUNC_DIV_EXPR);
10180 : 417728 : gimple *def_stmt1 = get_def_for_expr (treeop1, TRUNC_DIV_EXPR);
10181 : 417728 : if (def_stmt0
10182 : 417728 : && !operand_equal_p (treeop1, gimple_assign_rhs2 (def_stmt0), 0))
10183 : : def_stmt0 = NULL;
10184 : 417728 : if (def_stmt1
10185 : 417728 : && !operand_equal_p (treeop0, gimple_assign_rhs2 (def_stmt1), 0))
10186 : : def_stmt1 = NULL;
10187 : :
10188 : 417728 : if (def_stmt0 || def_stmt1)
10189 : : {
10190 : : /* X / Y * Y can be expanded as X - X % Y too.
10191 : : Choose the cheaper sequence of those two. */
10192 : 421 : if (def_stmt0)
10193 : 421 : treeop0 = gimple_assign_rhs1 (def_stmt0);
10194 : : else
10195 : : {
10196 : 0 : treeop1 = treeop0;
10197 : 0 : treeop0 = gimple_assign_rhs1 (def_stmt1);
10198 : : }
10199 : 421 : expand_operands (treeop0, treeop1, subtarget, &op0, &op1,
10200 : : EXPAND_NORMAL);
10201 : 421 : bool speed_p = optimize_insn_for_speed_p ();
10202 : 421 : do_pending_stack_adjust ();
10203 : 421 : start_sequence ();
10204 : 421 : rtx divmul_ret
10205 : 421 : = expand_expr_divmod (TRUNC_DIV_EXPR, mode, treeop0, treeop1,
10206 : : op0, op1, NULL_RTX, unsignedp);
10207 : 421 : divmul_ret = expand_mult (mode, divmul_ret, op1, target,
10208 : : unsignedp);
10209 : 421 : rtx_insn *divmul_insns = get_insns ();
10210 : 421 : end_sequence ();
10211 : 421 : start_sequence ();
10212 : 421 : rtx modsub_ret
10213 : 421 : = expand_expr_divmod (TRUNC_MOD_EXPR, mode, treeop0, treeop1,
10214 : : op0, op1, NULL_RTX, unsignedp);
10215 : 421 : this_optab = optab_for_tree_code (MINUS_EXPR, type,
10216 : : optab_default);
10217 : 421 : modsub_ret = expand_binop (mode, this_optab, op0, modsub_ret,
10218 : : target, unsignedp, OPTAB_LIB_WIDEN);
10219 : 421 : rtx_insn *modsub_insns = get_insns ();
10220 : 421 : end_sequence ();
10221 : 421 : unsigned divmul_cost = seq_cost (divmul_insns, speed_p);
10222 : 421 : unsigned modsub_cost = seq_cost (modsub_insns, speed_p);
10223 : : /* If costs are the same then use as tie breaker the other other
10224 : : factor. */
10225 : 421 : if (divmul_cost == modsub_cost)
10226 : : {
10227 : 0 : divmul_cost = seq_cost (divmul_insns, !speed_p);
10228 : 0 : modsub_cost = seq_cost (modsub_insns, !speed_p);
10229 : : }
10230 : :
10231 : 421 : if (divmul_cost <= modsub_cost)
10232 : : {
10233 : 341 : emit_insn (divmul_insns);
10234 : 341 : return REDUCE_BIT_FIELD (divmul_ret);
10235 : : }
10236 : 80 : emit_insn (modsub_insns);
10237 : 80 : return REDUCE_BIT_FIELD (modsub_ret);
10238 : : }
10239 : : }
10240 : :
10241 : 725207 : expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
10242 : :
10243 : : /* Expand X*Y as X&-Y when Y must be zero or one. */
10244 : 725207 : if (SCALAR_INT_MODE_P (mode))
10245 : : {
10246 : 597430 : bool gimple_zero_one_valued_p (tree, tree (*)(tree));
10247 : 597430 : bool bit0_p = gimple_zero_one_valued_p (treeop0, nullptr);
10248 : 597430 : bool bit1_p = gimple_zero_one_valued_p (treeop1, nullptr);
10249 : :
10250 : : /* Expand X*Y as X&Y when both X and Y must be zero or one. */
10251 : 597430 : if (bit0_p && bit1_p)
10252 : 2 : return REDUCE_BIT_FIELD (expand_and (mode, op0, op1, target));
10253 : :
10254 : 597428 : if (bit0_p || bit1_p)
10255 : : {
10256 : 3670 : bool speed = optimize_insn_for_speed_p ();
10257 : 3670 : int cost = add_cost (speed, mode) + neg_cost (speed, mode);
10258 : 3670 : struct algorithm algorithm;
10259 : 3670 : enum mult_variant variant;
10260 : 3670 : if (CONST_INT_P (op1)
10261 : 4075 : ? !choose_mult_variant (mode, INTVAL (op1),
10262 : : &algorithm, &variant, cost)
10263 : 405 : : cost < mul_cost (speed, mode))
10264 : : {
10265 : 1589 : temp = bit0_p ? expand_and (mode, negate_rtx (mode, op0),
10266 : : op1, target)
10267 : 120 : : expand_and (mode, op0,
10268 : : negate_rtx (mode, op1),
10269 : : target);
10270 : 1589 : return REDUCE_BIT_FIELD (temp);
10271 : : }
10272 : : }
10273 : : }
10274 : :
10275 : 723616 : return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
10276 : :
10277 : 137724 : case TRUNC_MOD_EXPR:
10278 : 137724 : case FLOOR_MOD_EXPR:
10279 : 137724 : case CEIL_MOD_EXPR:
10280 : 137724 : case ROUND_MOD_EXPR:
10281 : :
10282 : 137724 : case TRUNC_DIV_EXPR:
10283 : 137724 : case FLOOR_DIV_EXPR:
10284 : 137724 : case CEIL_DIV_EXPR:
10285 : 137724 : case ROUND_DIV_EXPR:
10286 : 137724 : case EXACT_DIV_EXPR:
10287 : : /* If this is a fixed-point operation, then we cannot use the code
10288 : : below because "expand_divmod" doesn't support sat/no-sat fixed-point
10289 : : divisions. */
10290 : 137724 : if (ALL_FIXED_POINT_MODE_P (mode))
10291 : 0 : goto binop;
10292 : :
10293 : 137724 : if (modifier == EXPAND_STACK_PARM)
10294 : 279 : target = 0;
10295 : : /* Possible optimization: compute the dividend with EXPAND_SUM
10296 : : then if the divisor is constant can optimize the case
10297 : : where some terms of the dividend have coeffs divisible by it. */
10298 : 137724 : expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
10299 : 137724 : return expand_expr_divmod (code, mode, treeop0, treeop1, op0, op1,
10300 : 137724 : target, unsignedp);
10301 : :
10302 : 28825 : case RDIV_EXPR:
10303 : 28825 : goto binop;
10304 : :
10305 : 1593 : case MULT_HIGHPART_EXPR:
10306 : 1593 : expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
10307 : 1593 : temp = expand_mult_highpart (mode, op0, op1, target, unsignedp);
10308 : 1593 : gcc_assert (temp);
10309 : : return temp;
10310 : :
10311 : 0 : case FIXED_CONVERT_EXPR:
10312 : 0 : op0 = expand_normal (treeop0);
10313 : 0 : if (target == 0 || modifier == EXPAND_STACK_PARM)
10314 : 0 : target = gen_reg_rtx (mode);
10315 : :
10316 : 0 : if ((TREE_CODE (TREE_TYPE (treeop0)) == INTEGER_TYPE
10317 : 0 : && TYPE_UNSIGNED (TREE_TYPE (treeop0)))
10318 : 0 : || (TREE_CODE (type) == INTEGER_TYPE && TYPE_UNSIGNED (type)))
10319 : 0 : expand_fixed_convert (target, op0, 1, TYPE_SATURATING (type));
10320 : : else
10321 : 0 : expand_fixed_convert (target, op0, 0, TYPE_SATURATING (type));
10322 : : return target;
10323 : :
10324 : 46422 : case FIX_TRUNC_EXPR:
10325 : 46422 : op0 = expand_normal (treeop0);
10326 : 46422 : if (target == 0 || modifier == EXPAND_STACK_PARM)
10327 : 3481 : target = gen_reg_rtx (mode);
10328 : 46422 : expand_fix (target, op0, unsignedp);
10329 : 46422 : return target;
10330 : :
10331 : 127959 : case FLOAT_EXPR:
10332 : 127959 : op0 = expand_normal (treeop0);
10333 : 127959 : if (target == 0 || modifier == EXPAND_STACK_PARM)
10334 : 61209 : target = gen_reg_rtx (mode);
10335 : : /* expand_float can't figure out what to do if FROM has VOIDmode.
10336 : : So give it the correct mode. With -O, cse will optimize this. */
10337 : 127959 : if (GET_MODE (op0) == VOIDmode)
10338 : 77 : op0 = copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0)),
10339 : : op0);
10340 : 255918 : expand_float (target, op0,
10341 : 127959 : TYPE_UNSIGNED (TREE_TYPE (treeop0)));
10342 : 127959 : return target;
10343 : :
10344 : 46130 : case NEGATE_EXPR:
10345 : 46130 : op0 = expand_expr (treeop0, subtarget,
10346 : : VOIDmode, EXPAND_NORMAL);
10347 : 46130 : if (modifier == EXPAND_STACK_PARM)
10348 : 235 : target = 0;
10349 : 46130 : temp = expand_unop (mode,
10350 : : optab_for_tree_code (NEGATE_EXPR, type,
10351 : : optab_default),
10352 : : op0, target, 0);
10353 : 46130 : gcc_assert (temp);
10354 : 46130 : return REDUCE_BIT_FIELD (temp);
10355 : :
10356 : 21623 : case ABS_EXPR:
10357 : 21623 : case ABSU_EXPR:
10358 : 21623 : op0 = expand_expr (treeop0, subtarget,
10359 : : VOIDmode, EXPAND_NORMAL);
10360 : 21623 : if (modifier == EXPAND_STACK_PARM)
10361 : 39 : target = 0;
10362 : :
10363 : : /* ABS_EXPR is not valid for complex arguments. */
10364 : 21623 : gcc_assert (GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
10365 : : && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT);
10366 : :
10367 : : /* Unsigned abs is simply the operand. Testing here means we don't
10368 : : risk generating incorrect code below. */
10369 : 21623 : if (TYPE_UNSIGNED (TREE_TYPE (treeop0)))
10370 : : return op0;
10371 : :
10372 : 21623 : return expand_abs (mode, op0, target, unsignedp,
10373 : 43246 : safe_from_p (target, treeop0, 1));
10374 : :
10375 : 86681 : case MAX_EXPR:
10376 : 86681 : case MIN_EXPR:
10377 : 86681 : target = original_target;
10378 : 86681 : if (target == 0
10379 : 86681 : || modifier == EXPAND_STACK_PARM
10380 : 51217 : || (MEM_P (target) && MEM_VOLATILE_P (target))
10381 : 51217 : || GET_MODE (target) != mode
10382 : 137898 : || (REG_P (target)
10383 : 46049 : && REGNO (target) < FIRST_PSEUDO_REGISTER))
10384 : 35464 : target = gen_reg_rtx (mode);
10385 : 86681 : expand_operands (treeop0, treeop1,
10386 : : target, &op0, &op1, EXPAND_NORMAL);
10387 : :
10388 : : /* First try to do it with a special MIN or MAX instruction.
10389 : : If that does not win, use a conditional jump to select the proper
10390 : : value. */
10391 : 86681 : this_optab = optab_for_tree_code (code, type, optab_default);
10392 : 86681 : temp = expand_binop (mode, this_optab, op0, op1, target, unsignedp,
10393 : : OPTAB_WIDEN);
10394 : 86681 : if (temp != 0)
10395 : : return temp;
10396 : :
10397 : 128 : if (VECTOR_TYPE_P (type))
10398 : 0 : gcc_unreachable ();
10399 : :
10400 : : /* At this point, a MEM target is no longer useful; we will get better
10401 : : code without it. */
10402 : :
10403 : 128 : if (! REG_P (target))
10404 : 1 : target = gen_reg_rtx (mode);
10405 : :
10406 : : /* If op1 was placed in target, swap op0 and op1. */
10407 : 128 : if (target != op0 && target == op1)
10408 : 0 : std::swap (op0, op1);
10409 : :
10410 : : /* We generate better code and avoid problems with op1 mentioning
10411 : : target by forcing op1 into a pseudo if it isn't a constant. */
10412 : 128 : if (! CONSTANT_P (op1))
10413 : 48 : op1 = force_reg (mode, op1);
10414 : :
10415 : 128 : {
10416 : 128 : enum rtx_code comparison_code;
10417 : 128 : rtx cmpop1 = op1;
10418 : :
10419 : 128 : if (code == MAX_EXPR)
10420 : 65 : comparison_code = unsignedp ? GEU : GE;
10421 : : else
10422 : 63 : comparison_code = unsignedp ? LEU : LE;
10423 : :
10424 : : /* Canonicalize to comparisons against 0. */
10425 : 128 : if (op1 == const1_rtx)
10426 : : {
10427 : : /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
10428 : : or (a != 0 ? a : 1) for unsigned.
10429 : : For MIN we are safe converting (a <= 1 ? a : 1)
10430 : : into (a <= 0 ? a : 1) */
10431 : 0 : cmpop1 = const0_rtx;
10432 : 0 : if (code == MAX_EXPR)
10433 : 0 : comparison_code = unsignedp ? NE : GT;
10434 : : }
10435 : 128 : if (op1 == constm1_rtx && !unsignedp)
10436 : : {
10437 : : /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
10438 : : and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
10439 : 0 : cmpop1 = const0_rtx;
10440 : 0 : if (code == MIN_EXPR)
10441 : 0 : comparison_code = LT;
10442 : : }
10443 : :
10444 : : /* Use a conditional move if possible. */
10445 : 128 : if (can_conditionally_move_p (mode))
10446 : : {
10447 : 81 : rtx insn;
10448 : :
10449 : 81 : start_sequence ();
10450 : :
10451 : : /* Try to emit the conditional move. */
10452 : 81 : insn = emit_conditional_move (target,
10453 : : { comparison_code,
10454 : : op0, cmpop1, mode },
10455 : : op0, op1, mode,
10456 : : unsignedp);
10457 : :
10458 : : /* If we could do the conditional move, emit the sequence,
10459 : : and return. */
10460 : 81 : if (insn)
10461 : : {
10462 : 44 : rtx_insn *seq = get_insns ();
10463 : 44 : end_sequence ();
10464 : 44 : emit_insn (seq);
10465 : 44 : return target;
10466 : : }
10467 : :
10468 : : /* Otherwise discard the sequence and fall back to code with
10469 : : branches. */
10470 : 37 : end_sequence ();
10471 : : }
10472 : :
10473 : 84 : if (target != op0)
10474 : 55 : emit_move_insn (target, op0);
10475 : :
10476 : 84 : lab = gen_label_rtx ();
10477 : 84 : do_compare_rtx_and_jump (target, cmpop1, comparison_code,
10478 : : unsignedp, mode, NULL_RTX, NULL, lab,
10479 : : profile_probability::uninitialized ());
10480 : : }
10481 : 84 : emit_move_insn (target, op1);
10482 : 84 : emit_label (lab);
10483 : 84 : return target;
10484 : :
10485 : 50465 : case BIT_NOT_EXPR:
10486 : 50465 : op0 = expand_expr (treeop0, subtarget,
10487 : : VOIDmode, EXPAND_NORMAL);
10488 : 50465 : if (modifier == EXPAND_STACK_PARM)
10489 : 92 : target = 0;
10490 : : /* In case we have to reduce the result to bitfield precision
10491 : : for unsigned bitfield expand this as XOR with a proper constant
10492 : : instead. */
10493 : 50465 : if (reduce_bit_field && TYPE_UNSIGNED (type))
10494 : : {
10495 : 22565 : int_mode = SCALAR_INT_TYPE_MODE (type);
10496 : 22565 : wide_int mask = wi::mask (TYPE_PRECISION (type),
10497 : 45130 : false, GET_MODE_PRECISION (int_mode));
10498 : :
10499 : 22565 : temp = expand_binop (int_mode, xor_optab, op0,
10500 : : immed_wide_int_const (mask, int_mode),
10501 : : target, 1, OPTAB_LIB_WIDEN);
10502 : 22565 : }
10503 : : else
10504 : 27900 : temp = expand_unop (mode, one_cmpl_optab, op0, target, 1);
10505 : 50465 : gcc_assert (temp);
10506 : : return temp;
10507 : :
10508 : : /* ??? Can optimize bitwise operations with one arg constant.
10509 : : Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
10510 : : and (a bitwise1 b) bitwise2 b (etc)
10511 : : but that is probably not worth while. */
10512 : :
10513 : 547885 : case BIT_AND_EXPR:
10514 : 547885 : case BIT_IOR_EXPR:
10515 : 547885 : case BIT_XOR_EXPR:
10516 : 547885 : goto binop;
10517 : :
10518 : 7780 : case LROTATE_EXPR:
10519 : 7780 : case RROTATE_EXPR:
10520 : 7780 : gcc_assert (VECTOR_MODE_P (TYPE_MODE (type))
10521 : : || type_has_mode_precision_p (type));
10522 : : /* fall through */
10523 : :
10524 : 237180 : case LSHIFT_EXPR:
10525 : 237180 : case RSHIFT_EXPR:
10526 : 237180 : {
10527 : : /* If this is a fixed-point operation, then we cannot use the code
10528 : : below because "expand_shift" doesn't support sat/no-sat fixed-point
10529 : : shifts. */
10530 : 237180 : if (ALL_FIXED_POINT_MODE_P (mode))
10531 : 0 : goto binop;
10532 : :
10533 : 237180 : if (! safe_from_p (subtarget, treeop1, 1))
10534 : 5716 : subtarget = 0;
10535 : 237180 : if (modifier == EXPAND_STACK_PARM)
10536 : 2519 : target = 0;
10537 : 237180 : op0 = expand_expr (treeop0, subtarget,
10538 : : VOIDmode, EXPAND_NORMAL);
10539 : :
10540 : : /* Left shift optimization when shifting across word_size boundary.
10541 : :
10542 : : If mode == GET_MODE_WIDER_MODE (word_mode), then normally
10543 : : there isn't native instruction to support this wide mode
10544 : : left shift. Given below scenario:
10545 : :
10546 : : Type A = (Type) B << C
10547 : :
10548 : : |< T >|
10549 : : | dest_high | dest_low |
10550 : :
10551 : : | word_size |
10552 : :
10553 : : If the shift amount C caused we shift B to across the word
10554 : : size boundary, i.e part of B shifted into high half of
10555 : : destination register, and part of B remains in the low
10556 : : half, then GCC will use the following left shift expand
10557 : : logic:
10558 : :
10559 : : 1. Initialize dest_low to B.
10560 : : 2. Initialize every bit of dest_high to the sign bit of B.
10561 : : 3. Logic left shift dest_low by C bit to finalize dest_low.
10562 : : The value of dest_low before this shift is kept in a temp D.
10563 : : 4. Logic left shift dest_high by C.
10564 : : 5. Logic right shift D by (word_size - C).
10565 : : 6. Or the result of 4 and 5 to finalize dest_high.
10566 : :
10567 : : While, by checking gimple statements, if operand B is
10568 : : coming from signed extension, then we can simplify above
10569 : : expand logic into:
10570 : :
10571 : : 1. dest_high = src_low >> (word_size - C).
10572 : : 2. dest_low = src_low << C.
10573 : :
10574 : : We can use one arithmetic right shift to finish all the
10575 : : purpose of steps 2, 4, 5, 6, thus we reduce the steps
10576 : : needed from 6 into 2.
10577 : :
10578 : : The case is similar for zero extension, except that we
10579 : : initialize dest_high to zero rather than copies of the sign
10580 : : bit from B. Furthermore, we need to use a logical right shift
10581 : : in this case.
10582 : :
10583 : : The choice of sign-extension versus zero-extension is
10584 : : determined entirely by whether or not B is signed and is
10585 : : independent of the current setting of unsignedp. */
10586 : :
10587 : 237180 : temp = NULL_RTX;
10588 : 237180 : if (code == LSHIFT_EXPR
10589 : 237180 : && target
10590 : 30236 : && REG_P (target)
10591 : 28453 : && GET_MODE_2XWIDER_MODE (word_mode).exists (&int_mode)
10592 : 28453 : && mode == int_mode
10593 : 1462 : && TREE_CONSTANT (treeop1)
10594 : 238006 : && TREE_CODE (treeop0) == SSA_NAME)
10595 : : {
10596 : 826 : gimple *def = SSA_NAME_DEF_STMT (treeop0);
10597 : 826 : if (is_gimple_assign (def)
10598 : 826 : && gimple_assign_rhs_code (def) == NOP_EXPR)
10599 : : {
10600 : 325 : scalar_int_mode rmode = SCALAR_INT_TYPE_MODE
10601 : : (TREE_TYPE (gimple_assign_rhs1 (def)));
10602 : :
10603 : 650 : if (GET_MODE_SIZE (rmode) < GET_MODE_SIZE (int_mode)
10604 : 608 : && TREE_INT_CST_LOW (treeop1) < GET_MODE_BITSIZE (word_mode)
10605 : 471 : && ((TREE_INT_CST_LOW (treeop1) + GET_MODE_BITSIZE (rmode))
10606 : 73 : >= GET_MODE_BITSIZE (word_mode)))
10607 : : {
10608 : 68 : rtx_insn *seq, *seq_old;
10609 : 68 : poly_uint64 high_off = subreg_highpart_offset (word_mode,
10610 : : int_mode);
10611 : 68 : bool extend_unsigned
10612 : 68 : = TYPE_UNSIGNED (TREE_TYPE (gimple_assign_rhs1 (def)));
10613 : 68 : rtx low = lowpart_subreg (word_mode, op0, int_mode);
10614 : 68 : rtx dest_low = lowpart_subreg (word_mode, target, int_mode);
10615 : 68 : rtx dest_high = simplify_gen_subreg (word_mode, target,
10616 : : int_mode, high_off);
10617 : 68 : HOST_WIDE_INT ramount = (BITS_PER_WORD
10618 : 68 : - TREE_INT_CST_LOW (treeop1));
10619 : 68 : tree rshift = build_int_cst (TREE_TYPE (treeop1), ramount);
10620 : :
10621 : 68 : start_sequence ();
10622 : : /* dest_high = src_low >> (word_size - C). */
10623 : 68 : temp = expand_variable_shift (RSHIFT_EXPR, word_mode, low,
10624 : : rshift, dest_high,
10625 : : extend_unsigned);
10626 : 68 : if (temp != dest_high)
10627 : 0 : emit_move_insn (dest_high, temp);
10628 : :
10629 : : /* dest_low = src_low << C. */
10630 : 68 : temp = expand_variable_shift (LSHIFT_EXPR, word_mode, low,
10631 : : treeop1, dest_low, unsignedp);
10632 : 68 : if (temp != dest_low)
10633 : 1 : emit_move_insn (dest_low, temp);
10634 : :
10635 : 68 : seq = get_insns ();
10636 : 68 : end_sequence ();
10637 : 68 : temp = target ;
10638 : :
10639 : 68 : if (have_insn_for (ASHIFT, int_mode))
10640 : : {
10641 : 68 : bool speed_p = optimize_insn_for_speed_p ();
10642 : 68 : start_sequence ();
10643 : 68 : rtx ret_old = expand_variable_shift (code, int_mode,
10644 : : op0, treeop1,
10645 : : target,
10646 : : unsignedp);
10647 : :
10648 : 68 : seq_old = get_insns ();
10649 : 68 : end_sequence ();
10650 : 136 : if (seq_cost (seq, speed_p)
10651 : 68 : >= seq_cost (seq_old, speed_p))
10652 : : {
10653 : 68 : seq = seq_old;
10654 : 68 : temp = ret_old;
10655 : : }
10656 : : }
10657 : 68 : emit_insn (seq);
10658 : : }
10659 : : }
10660 : : }
10661 : :
10662 : 236422 : if (temp == NULL_RTX)
10663 : 237112 : temp = expand_variable_shift (code, mode, op0, treeop1, target,
10664 : : unsignedp);
10665 : 237180 : if (code == LSHIFT_EXPR)
10666 : 68257 : temp = REDUCE_BIT_FIELD (temp);
10667 : : return temp;
10668 : : }
10669 : :
10670 : : /* Could determine the answer when only additive constants differ. Also,
10671 : : the addition of one can be handled by changing the condition. */
10672 : 474466 : case LT_EXPR:
10673 : 474466 : case LE_EXPR:
10674 : 474466 : case GT_EXPR:
10675 : 474466 : case GE_EXPR:
10676 : 474466 : case EQ_EXPR:
10677 : 474466 : case NE_EXPR:
10678 : 474466 : case UNORDERED_EXPR:
10679 : 474466 : case ORDERED_EXPR:
10680 : 474466 : case UNLT_EXPR:
10681 : 474466 : case UNLE_EXPR:
10682 : 474466 : case UNGT_EXPR:
10683 : 474466 : case UNGE_EXPR:
10684 : 474466 : case UNEQ_EXPR:
10685 : 474466 : case LTGT_EXPR:
10686 : 474466 : {
10687 : 743502 : temp = do_store_flag (ops,
10688 : : modifier != EXPAND_STACK_PARM ? target : NULL_RTX,
10689 : : tmode != VOIDmode ? tmode : mode);
10690 : 474466 : if (temp)
10691 : : return temp;
10692 : :
10693 : : /* Use a compare and a jump for BLKmode comparisons, or for function
10694 : : type comparisons is have_canonicalize_funcptr_for_compare. */
10695 : :
10696 : 0 : if ((target == 0
10697 : 0 : || modifier == EXPAND_STACK_PARM
10698 : 0 : || ! safe_from_p (target, treeop0, 1)
10699 : 0 : || ! safe_from_p (target, treeop1, 1)
10700 : : /* Make sure we don't have a hard reg (such as function's return
10701 : : value) live across basic blocks, if not optimizing. */
10702 : 0 : || (!optimize && REG_P (target)
10703 : 0 : && REGNO (target) < FIRST_PSEUDO_REGISTER)))
10704 : 0 : target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
10705 : :
10706 : 0 : emit_move_insn (target, const0_rtx);
10707 : :
10708 : 0 : rtx_code_label *lab1 = gen_label_rtx ();
10709 : 0 : jumpifnot_1 (code, treeop0, treeop1, lab1,
10710 : : profile_probability::uninitialized ());
10711 : :
10712 : 0 : if (TYPE_PRECISION (type) == 1 && !TYPE_UNSIGNED (type))
10713 : 0 : emit_move_insn (target, constm1_rtx);
10714 : : else
10715 : 0 : emit_move_insn (target, const1_rtx);
10716 : :
10717 : 0 : emit_label (lab1);
10718 : 0 : return target;
10719 : : }
10720 : 54340 : case COMPLEX_EXPR:
10721 : : /* Get the rtx code of the operands. */
10722 : 54340 : op0 = expand_normal (treeop0);
10723 : 54340 : op1 = expand_normal (treeop1);
10724 : :
10725 : 54340 : if (!target)
10726 : 2530 : target = gen_reg_rtx (TYPE_MODE (type));
10727 : : else
10728 : : /* If target overlaps with op1, then either we need to force
10729 : : op1 into a pseudo (if target also overlaps with op0),
10730 : : or write the complex parts in reverse order. */
10731 : 51810 : switch (GET_CODE (target))
10732 : : {
10733 : 48859 : case CONCAT:
10734 : 48859 : if (reg_overlap_mentioned_p (XEXP (target, 0), op1))
10735 : : {
10736 : 0 : if (reg_overlap_mentioned_p (XEXP (target, 1), op0))
10737 : : {
10738 : 0 : complex_expr_force_op1:
10739 : 1852 : temp = gen_reg_rtx (GET_MODE_INNER (GET_MODE (target)));
10740 : 926 : emit_move_insn (temp, op1);
10741 : 926 : op1 = temp;
10742 : 926 : break;
10743 : : }
10744 : 0 : complex_expr_swap_order:
10745 : : /* Move the imaginary (op1) and real (op0) parts to their
10746 : : location. */
10747 : 80 : write_complex_part (target, op1, true, true);
10748 : 80 : write_complex_part (target, op0, false, false);
10749 : :
10750 : 80 : return target;
10751 : : }
10752 : : break;
10753 : 2951 : case MEM:
10754 : 5902 : temp = adjust_address_nv (target,
10755 : : GET_MODE_INNER (GET_MODE (target)), 0);
10756 : 2951 : if (reg_overlap_mentioned_p (temp, op1))
10757 : : {
10758 : 1006 : scalar_mode imode = GET_MODE_INNER (GET_MODE (target));
10759 : 2012 : temp = adjust_address_nv (target, imode,
10760 : : GET_MODE_SIZE (imode));
10761 : 1006 : if (reg_overlap_mentioned_p (temp, op0))
10762 : 926 : goto complex_expr_force_op1;
10763 : 80 : goto complex_expr_swap_order;
10764 : : }
10765 : : break;
10766 : 0 : default:
10767 : 0 : if (reg_overlap_mentioned_p (target, op1))
10768 : : {
10769 : 0 : if (reg_overlap_mentioned_p (target, op0))
10770 : 0 : goto complex_expr_force_op1;
10771 : 0 : goto complex_expr_swap_order;
10772 : : }
10773 : : break;
10774 : : }
10775 : :
10776 : : /* Move the real (op0) and imaginary (op1) parts to their location. */
10777 : 54260 : write_complex_part (target, op0, false, true);
10778 : 54260 : write_complex_part (target, op1, true, false);
10779 : :
10780 : 54260 : return target;
10781 : :
10782 : 0 : case WIDEN_SUM_EXPR:
10783 : 0 : {
10784 : 0 : tree oprnd0 = treeop0;
10785 : 0 : tree oprnd1 = treeop1;
10786 : :
10787 : 0 : expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
10788 : 0 : target = expand_widen_pattern_expr (ops, op0, NULL_RTX, op1,
10789 : : target, unsignedp);
10790 : 0 : return target;
10791 : : }
10792 : :
10793 : 11989 : case VEC_UNPACK_HI_EXPR:
10794 : 11989 : case VEC_UNPACK_LO_EXPR:
10795 : 11989 : case VEC_UNPACK_FIX_TRUNC_HI_EXPR:
10796 : 11989 : case VEC_UNPACK_FIX_TRUNC_LO_EXPR:
10797 : 11989 : {
10798 : 11989 : op0 = expand_normal (treeop0);
10799 : 11989 : temp = expand_widen_pattern_expr (ops, op0, NULL_RTX, NULL_RTX,
10800 : : target, unsignedp);
10801 : 11989 : gcc_assert (temp);
10802 : : return temp;
10803 : : }
10804 : :
10805 : 1466 : case VEC_UNPACK_FLOAT_HI_EXPR:
10806 : 1466 : case VEC_UNPACK_FLOAT_LO_EXPR:
10807 : 1466 : {
10808 : 1466 : op0 = expand_normal (treeop0);
10809 : : /* The signedness is determined from input operand. */
10810 : 1466 : temp = expand_widen_pattern_expr
10811 : 2932 : (ops, op0, NULL_RTX, NULL_RTX,
10812 : 1466 : target, TYPE_UNSIGNED (TREE_TYPE (treeop0)));
10813 : :
10814 : 1466 : gcc_assert (temp);
10815 : : return temp;
10816 : : }
10817 : :
10818 : 904 : case VEC_WIDEN_MULT_HI_EXPR:
10819 : 904 : case VEC_WIDEN_MULT_LO_EXPR:
10820 : 904 : case VEC_WIDEN_MULT_EVEN_EXPR:
10821 : 904 : case VEC_WIDEN_MULT_ODD_EXPR:
10822 : 904 : case VEC_WIDEN_LSHIFT_HI_EXPR:
10823 : 904 : case VEC_WIDEN_LSHIFT_LO_EXPR:
10824 : 904 : expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
10825 : 904 : target = expand_widen_pattern_expr (ops, op0, op1, NULL_RTX,
10826 : : target, unsignedp);
10827 : 904 : gcc_assert (target);
10828 : : return target;
10829 : :
10830 : 215 : case VEC_PACK_SAT_EXPR:
10831 : 215 : case VEC_PACK_FIX_TRUNC_EXPR:
10832 : 215 : mode = TYPE_MODE (TREE_TYPE (treeop0));
10833 : 215 : subtarget = NULL_RTX;
10834 : 215 : goto binop;
10835 : :
10836 : 7688 : case VEC_PACK_TRUNC_EXPR:
10837 : 7688 : if (VECTOR_BOOLEAN_TYPE_P (type)
10838 : 913 : && VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (treeop0))
10839 : 913 : && mode == TYPE_MODE (TREE_TYPE (treeop0))
10840 : 7889 : && SCALAR_INT_MODE_P (mode))
10841 : : {
10842 : 201 : class expand_operand eops[4];
10843 : 201 : machine_mode imode = TYPE_MODE (TREE_TYPE (treeop0));
10844 : 201 : expand_operands (treeop0, treeop1,
10845 : : subtarget, &op0, &op1, EXPAND_NORMAL);
10846 : 201 : this_optab = vec_pack_sbool_trunc_optab;
10847 : 201 : enum insn_code icode = optab_handler (this_optab, imode);
10848 : 201 : create_output_operand (&eops[0], target, mode);
10849 : 201 : create_convert_operand_from (&eops[1], op0, imode, false);
10850 : 201 : create_convert_operand_from (&eops[2], op1, imode, false);
10851 : 201 : temp = GEN_INT (TYPE_VECTOR_SUBPARTS (type).to_constant ());
10852 : 201 : create_input_operand (&eops[3], temp, imode);
10853 : 201 : expand_insn (icode, 4, eops);
10854 : 201 : return eops[0].value;
10855 : : }
10856 : 7487 : mode = TYPE_MODE (TREE_TYPE (treeop0));
10857 : 7487 : subtarget = NULL_RTX;
10858 : 7487 : goto binop;
10859 : :
10860 : 20 : case VEC_PACK_FLOAT_EXPR:
10861 : 20 : mode = TYPE_MODE (TREE_TYPE (treeop0));
10862 : 20 : expand_operands (treeop0, treeop1,
10863 : : subtarget, &op0, &op1, EXPAND_NORMAL);
10864 : 20 : this_optab = optab_for_tree_code (code, TREE_TYPE (treeop0),
10865 : : optab_default);
10866 : 60 : target = expand_binop (mode, this_optab, op0, op1, target,
10867 : 20 : TYPE_UNSIGNED (TREE_TYPE (treeop0)),
10868 : : OPTAB_LIB_WIDEN);
10869 : 20 : gcc_assert (target);
10870 : : return target;
10871 : :
10872 : 57796 : case VEC_PERM_EXPR:
10873 : 57796 : {
10874 : 57796 : expand_operands (treeop0, treeop1, target, &op0, &op1, EXPAND_NORMAL);
10875 : 57796 : vec_perm_builder sel;
10876 : 57796 : if (TREE_CODE (treeop2) == VECTOR_CST
10877 : 57796 : && tree_to_vec_perm_builder (&sel, treeop2))
10878 : : {
10879 : 57786 : machine_mode sel_mode = TYPE_MODE (TREE_TYPE (treeop2));
10880 : 57786 : temp = expand_vec_perm_const (mode, op0, op1, sel,
10881 : : sel_mode, target);
10882 : : }
10883 : : else
10884 : : {
10885 : 10 : op2 = expand_normal (treeop2);
10886 : 10 : temp = expand_vec_perm_var (mode, op0, op1, op2, target);
10887 : : }
10888 : 57796 : gcc_assert (temp);
10889 : 57796 : return temp;
10890 : 57796 : }
10891 : :
10892 : 137 : case DOT_PROD_EXPR:
10893 : 137 : {
10894 : 137 : tree oprnd0 = treeop0;
10895 : 137 : tree oprnd1 = treeop1;
10896 : 137 : tree oprnd2 = treeop2;
10897 : :
10898 : 137 : expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
10899 : 137 : op2 = expand_normal (oprnd2);
10900 : 137 : target = expand_widen_pattern_expr (ops, op0, op1, op2,
10901 : : target, unsignedp);
10902 : 137 : return target;
10903 : : }
10904 : :
10905 : 99 : case SAD_EXPR:
10906 : 99 : {
10907 : 99 : tree oprnd0 = treeop0;
10908 : 99 : tree oprnd1 = treeop1;
10909 : 99 : tree oprnd2 = treeop2;
10910 : :
10911 : 99 : expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
10912 : 99 : op2 = expand_normal (oprnd2);
10913 : 99 : target = expand_widen_pattern_expr (ops, op0, op1, op2,
10914 : : target, unsignedp);
10915 : 99 : return target;
10916 : : }
10917 : :
10918 : 0 : case REALIGN_LOAD_EXPR:
10919 : 0 : {
10920 : 0 : tree oprnd0 = treeop0;
10921 : 0 : tree oprnd1 = treeop1;
10922 : 0 : tree oprnd2 = treeop2;
10923 : :
10924 : 0 : this_optab = optab_for_tree_code (code, type, optab_default);
10925 : 0 : expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
10926 : 0 : op2 = expand_normal (oprnd2);
10927 : 0 : temp = expand_ternary_op (mode, this_optab, op0, op1, op2,
10928 : : target, unsignedp);
10929 : 0 : gcc_assert (temp);
10930 : : return temp;
10931 : : }
10932 : :
10933 : 11646 : case COND_EXPR:
10934 : 11646 : {
10935 : : /* A COND_EXPR with its type being VOID_TYPE represents a
10936 : : conditional jump and is handled in
10937 : : expand_gimple_cond_expr. */
10938 : 11646 : gcc_assert (!VOID_TYPE_P (type));
10939 : :
10940 : : /* Note that COND_EXPRs whose type is a structure or union
10941 : : are required to be constructed to contain assignments of
10942 : : a temporary variable, so that we can evaluate them here
10943 : : for side effect only. If type is void, we must do likewise. */
10944 : :
10945 : 11646 : gcc_assert (!TREE_ADDRESSABLE (type)
10946 : : && !ignore
10947 : : && TREE_TYPE (treeop1) != void_type_node
10948 : : && TREE_TYPE (treeop2) != void_type_node);
10949 : :
10950 : 11646 : temp = expand_cond_expr_using_cmove (treeop0, treeop1, treeop2);
10951 : 11646 : if (temp)
10952 : : return temp;
10953 : :
10954 : : /* If we are not to produce a result, we have no target. Otherwise,
10955 : : if a target was specified use it; it will not be used as an
10956 : : intermediate target unless it is safe. If no target, use a
10957 : : temporary. */
10958 : :
10959 : 2684 : if (modifier != EXPAND_STACK_PARM
10960 : 2684 : && original_target
10961 : 1303 : && safe_from_p (original_target, treeop0, 1)
10962 : 0 : && GET_MODE (original_target) == mode
10963 : 2684 : && !MEM_P (original_target))
10964 : : temp = original_target;
10965 : : else
10966 : 2684 : temp = assign_temp (type, 0, 1);
10967 : :
10968 : 2684 : do_pending_stack_adjust ();
10969 : 2684 : NO_DEFER_POP;
10970 : 2684 : rtx_code_label *lab0 = gen_label_rtx ();
10971 : 2684 : rtx_code_label *lab1 = gen_label_rtx ();
10972 : 2684 : jumpifnot (treeop0, lab0,
10973 : : profile_probability::uninitialized ());
10974 : 2684 : store_expr (treeop1, temp,
10975 : : modifier == EXPAND_STACK_PARM,
10976 : : false, false);
10977 : :
10978 : 2684 : emit_jump_insn (targetm.gen_jump (lab1));
10979 : 2684 : emit_barrier ();
10980 : 2684 : emit_label (lab0);
10981 : 2684 : store_expr (treeop2, temp,
10982 : : modifier == EXPAND_STACK_PARM,
10983 : : false, false);
10984 : :
10985 : 2684 : emit_label (lab1);
10986 : 2684 : OK_DEFER_POP;
10987 : 2684 : return temp;
10988 : : }
10989 : :
10990 : 0 : case VEC_DUPLICATE_EXPR:
10991 : 0 : op0 = expand_expr (treeop0, NULL_RTX, VOIDmode, modifier);
10992 : 0 : target = expand_vector_broadcast (mode, op0);
10993 : 0 : gcc_assert (target);
10994 : : return target;
10995 : :
10996 : 0 : case VEC_SERIES_EXPR:
10997 : 0 : expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, modifier);
10998 : 0 : return expand_vec_series_expr (mode, op0, op1, target);
10999 : :
11000 : 991 : case BIT_INSERT_EXPR:
11001 : 991 : {
11002 : 991 : unsigned bitpos = tree_to_uhwi (treeop2);
11003 : 991 : unsigned bitsize;
11004 : 991 : if (INTEGRAL_TYPE_P (TREE_TYPE (treeop1)))
11005 : 686 : bitsize = TYPE_PRECISION (TREE_TYPE (treeop1));
11006 : : else
11007 : 305 : bitsize = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (treeop1)));
11008 : 991 : op0 = expand_normal (treeop0);
11009 : 991 : op1 = expand_normal (treeop1);
11010 : 991 : rtx dst = gen_reg_rtx (mode);
11011 : 991 : emit_move_insn (dst, op0);
11012 : 991 : store_bit_field (dst, bitsize, bitpos, 0, 0,
11013 : 991 : TYPE_MODE (TREE_TYPE (treeop1)), op1, false, false);
11014 : 991 : return dst;
11015 : : }
11016 : :
11017 : 0 : default:
11018 : 0 : gcc_unreachable ();
11019 : : }
11020 : :
11021 : : /* Here to do an ordinary binary operator. */
11022 : 1020034 : binop:
11023 : 1020034 : expand_operands (treeop0, treeop1,
11024 : : subtarget, &op0, &op1, EXPAND_NORMAL);
11025 : 4996944 : binop2:
11026 : 4996944 : this_optab = optab_for_tree_code (code, type, optab_default);
11027 : 4996944 : binop3:
11028 : 4996944 : if (modifier == EXPAND_STACK_PARM)
11029 : 24238 : target = 0;
11030 : 4996944 : temp = expand_binop (mode, this_optab, op0, op1, target,
11031 : : unsignedp, OPTAB_LIB_WIDEN);
11032 : 4996944 : gcc_assert (temp);
11033 : : /* Bitwise operations do not need bitfield reduction as we expect their
11034 : : operands being properly truncated. */
11035 : 4996944 : if (code == BIT_XOR_EXPR
11036 : : || code == BIT_AND_EXPR
11037 : 4996944 : || code == BIT_IOR_EXPR)
11038 : : return temp;
11039 : 4449059 : return REDUCE_BIT_FIELD (temp);
11040 : : }
11041 : : #undef REDUCE_BIT_FIELD
11042 : :
11043 : :
11044 : : /* Return TRUE if expression STMT is suitable for replacement.
11045 : : Never consider memory loads as replaceable, because those don't ever lead
11046 : : into constant expressions. */
11047 : :
11048 : : static bool
11049 : 10 : stmt_is_replaceable_p (gimple *stmt)
11050 : : {
11051 : 10 : if (ssa_is_replaceable_p (stmt))
11052 : : {
11053 : : /* Don't move around loads. */
11054 : 7 : if (!gimple_assign_single_p (stmt)
11055 : 7 : || is_gimple_val (gimple_assign_rhs1 (stmt)))
11056 : 6 : return true;
11057 : : }
11058 : : return false;
11059 : : }
11060 : :
11061 : : /* A subroutine of expand_expr_real_1. Expand gimple assignment G,
11062 : : which is known to set an SSA_NAME result. The other arguments are
11063 : : as for expand_expr_real_1. */
11064 : :
11065 : : rtx
11066 : 13205260 : expand_expr_real_gassign (gassign *g, rtx target, machine_mode tmode,
11067 : : enum expand_modifier modifier, rtx *alt_rtl,
11068 : : bool inner_reference_p)
11069 : : {
11070 : 13205260 : separate_ops ops;
11071 : 13205260 : rtx r;
11072 : 13205260 : location_t saved_loc = curr_insn_location ();
11073 : 13205260 : auto loc = gimple_location (g);
11074 : 13205260 : if (loc != UNKNOWN_LOCATION)
11075 : 10619168 : set_curr_insn_location (loc);
11076 : 13205260 : tree lhs = gimple_assign_lhs (g);
11077 : 13205260 : ops.code = gimple_assign_rhs_code (g);
11078 : 13205260 : ops.type = TREE_TYPE (lhs);
11079 : 13205260 : switch (get_gimple_rhs_class (ops.code))
11080 : : {
11081 : 70640 : case GIMPLE_TERNARY_RHS:
11082 : 141280 : ops.op2 = gimple_assign_rhs3 (g);
11083 : : /* Fallthru */
11084 : 6863814 : case GIMPLE_BINARY_RHS:
11085 : 6863814 : ops.op1 = gimple_assign_rhs2 (g);
11086 : :
11087 : : /* Try to expand conditonal compare. */
11088 : 6863814 : if (targetm.gen_ccmp_first)
11089 : : {
11090 : 0 : gcc_checking_assert (targetm.gen_ccmp_next != NULL);
11091 : 0 : r = expand_ccmp_expr (g, TYPE_MODE (ops.type));
11092 : 0 : if (r)
11093 : : break;
11094 : : }
11095 : : /* Fallthru */
11096 : 10077103 : case GIMPLE_UNARY_RHS:
11097 : 10077103 : ops.op0 = gimple_assign_rhs1 (g);
11098 : 10077103 : ops.location = loc;
11099 : 10077103 : r = expand_expr_real_2 (&ops, target, tmode, modifier);
11100 : 10077103 : break;
11101 : 3128157 : case GIMPLE_SINGLE_RHS:
11102 : 3128157 : {
11103 : 3128157 : r = expand_expr_real (gimple_assign_rhs1 (g), target,
11104 : : tmode, modifier, alt_rtl,
11105 : : inner_reference_p);
11106 : 3128157 : break;
11107 : : }
11108 : 0 : default:
11109 : 0 : gcc_unreachable ();
11110 : : }
11111 : 13205260 : set_curr_insn_location (saved_loc);
11112 : 13205260 : if (REG_P (r) && !REG_EXPR (r))
11113 : 3300471 : set_reg_attrs_for_decl_rtl (lhs, r);
11114 : 13205260 : return r;
11115 : : }
11116 : :
11117 : : rtx
11118 : 143855350 : expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
11119 : : enum expand_modifier modifier, rtx *alt_rtl,
11120 : : bool inner_reference_p)
11121 : : {
11122 : 143855350 : rtx op0, op1, temp, decl_rtl;
11123 : 143855350 : tree type;
11124 : 143855350 : int unsignedp;
11125 : 143855350 : machine_mode mode, dmode;
11126 : 143855350 : enum tree_code code = TREE_CODE (exp);
11127 : 143855350 : rtx subtarget, original_target;
11128 : 143855350 : int ignore;
11129 : 143855350 : bool reduce_bit_field;
11130 : 143855350 : location_t loc = EXPR_LOCATION (exp);
11131 : 143855350 : struct separate_ops ops;
11132 : 143855350 : tree treeop0, treeop1, treeop2;
11133 : 143855350 : tree ssa_name = NULL_TREE;
11134 : 143855350 : gimple *g;
11135 : :
11136 : : /* Some ABIs define padding bits in _BitInt uninitialized. Normally, RTL
11137 : : expansion sign/zero extends integral types with less than mode precision
11138 : : when reading from bit-fields and after arithmetic operations (see
11139 : : REDUCE_BIT_FIELD in expand_expr_real_2) and on subsequent loads relies
11140 : : on those extensions to have been already performed, but because of the
11141 : : above for _BitInt they need to be sign/zero extended when reading from
11142 : : locations that could be exposed to ABI boundaries (when loading from
11143 : : objects in memory, or function arguments, return value). Because we
11144 : : internally extend after arithmetic operations, we can avoid doing that
11145 : : when reading from SSA_NAMEs of vars. */
11146 : : #define EXTEND_BITINT(expr) \
11147 : : ((TREE_CODE (type) == BITINT_TYPE \
11148 : : && reduce_bit_field \
11149 : : && mode != BLKmode \
11150 : : && modifier != EXPAND_MEMORY \
11151 : : && modifier != EXPAND_WRITE \
11152 : : && modifier != EXPAND_INITIALIZER \
11153 : : && modifier != EXPAND_CONST_ADDRESS) \
11154 : : ? reduce_to_bit_field_precision ((expr), NULL_RTX, type) : (expr))
11155 : :
11156 : 143855350 : type = TREE_TYPE (exp);
11157 : 143855350 : mode = TYPE_MODE (type);
11158 : 143855350 : unsignedp = TYPE_UNSIGNED (type);
11159 : :
11160 : 143855350 : treeop0 = treeop1 = treeop2 = NULL_TREE;
11161 : 143855350 : if (!VL_EXP_CLASS_P (exp))
11162 : 137497782 : switch (TREE_CODE_LENGTH (code))
11163 : : {
11164 : 5238978 : default:
11165 : 5238978 : case 3: treeop2 = TREE_OPERAND (exp, 2); /* FALLTHRU */
11166 : 12312757 : case 2: treeop1 = TREE_OPERAND (exp, 1); /* FALLTHRU */
11167 : 25816786 : case 1: treeop0 = TREE_OPERAND (exp, 0); /* FALLTHRU */
11168 : : case 0: break;
11169 : : }
11170 : 143855350 : ops.code = code;
11171 : 143855350 : ops.type = type;
11172 : 143855350 : ops.op0 = treeop0;
11173 : 143855350 : ops.op1 = treeop1;
11174 : 143855350 : ops.op2 = treeop2;
11175 : 143855350 : ops.location = loc;
11176 : :
11177 : 287710700 : ignore = (target == const0_rtx
11178 : 143855350 : || ((CONVERT_EXPR_CODE_P (code)
11179 : 139098715 : || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
11180 : 891341 : && TREE_CODE (type) == VOID_TYPE));
11181 : :
11182 : : /* An operation in what may be a bit-field type needs the
11183 : : result to be reduced to the precision of the bit-field type,
11184 : : which is narrower than that of the type's mode. */
11185 : 287710431 : reduce_bit_field = (!ignore
11186 : 139664972 : && INTEGRAL_TYPE_P (type)
11187 : 72574646 : && !type_has_mode_precision_p (type));
11188 : :
11189 : : /* If we are going to ignore this result, we need only do something
11190 : : if there is a side-effect somewhere in the expression. If there
11191 : : is, short-circuit the most common cases here. Note that we must
11192 : : not call expand_expr with anything but const0_rtx in case this
11193 : : is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
11194 : :
11195 : 4190378 : if (ignore)
11196 : : {
11197 : 4190378 : if (! TREE_SIDE_EFFECTS (exp))
11198 : : return const0_rtx;
11199 : :
11200 : : /* Ensure we reference a volatile object even if value is ignored, but
11201 : : don't do this if all we are doing is taking its address. */
11202 : 4190109 : if (TREE_THIS_VOLATILE (exp)
11203 : 0 : && TREE_CODE (exp) != FUNCTION_DECL
11204 : 0 : && mode != VOIDmode && mode != BLKmode
11205 : 0 : && modifier != EXPAND_CONST_ADDRESS)
11206 : : {
11207 : 0 : temp = expand_expr (exp, NULL_RTX, VOIDmode, modifier);
11208 : 0 : if (MEM_P (temp))
11209 : 0 : copy_to_reg (temp);
11210 : 0 : return const0_rtx;
11211 : : }
11212 : :
11213 : 4190109 : if (TREE_CODE_CLASS (code) == tcc_unary
11214 : : || code == BIT_FIELD_REF
11215 : 4190109 : || code == COMPONENT_REF
11216 : 4190109 : || code == INDIRECT_REF)
11217 : 0 : return expand_expr (treeop0, const0_rtx, VOIDmode,
11218 : 0 : modifier);
11219 : :
11220 : 4190109 : else if (TREE_CODE_CLASS (code) == tcc_binary
11221 : 4190109 : || TREE_CODE_CLASS (code) == tcc_comparison
11222 : 4190109 : || code == ARRAY_REF || code == ARRAY_RANGE_REF)
11223 : : {
11224 : 0 : expand_expr (treeop0, const0_rtx, VOIDmode, modifier);
11225 : 0 : expand_expr (treeop1, const0_rtx, VOIDmode, modifier);
11226 : 0 : return const0_rtx;
11227 : : }
11228 : :
11229 : : target = 0;
11230 : : }
11231 : :
11232 : 143855081 : if (reduce_bit_field && modifier == EXPAND_STACK_PARM)
11233 : 29703 : target = 0;
11234 : :
11235 : : /* Use subtarget as the target for operand 0 of a binary operation. */
11236 : 143855081 : subtarget = get_subtarget (target);
11237 : 143855081 : original_target = target;
11238 : :
11239 : 143855081 : switch (code)
11240 : : {
11241 : 10831 : case LABEL_DECL:
11242 : 10831 : {
11243 : 10831 : tree function = decl_function_context (exp);
11244 : :
11245 : 10831 : temp = label_rtx (exp);
11246 : 10831 : temp = gen_rtx_LABEL_REF (Pmode, temp);
11247 : :
11248 : 10831 : if (function != current_function_decl
11249 : 1271 : && function != 0)
11250 : 1271 : LABEL_REF_NONLOCAL_P (temp) = 1;
11251 : :
11252 : 10831 : temp = gen_rtx_MEM (FUNCTION_MODE, temp);
11253 : 10831 : return temp;
11254 : : }
11255 : :
11256 : 51256500 : case SSA_NAME:
11257 : : /* ??? ivopts calls expander, without any preparation from
11258 : : out-of-ssa. So fake instructions as if this was an access to the
11259 : : base variable. This unnecessarily allocates a pseudo, see how we can
11260 : : reuse it, if partition base vars have it set already. */
11261 : 51256500 : if (!currently_expanding_to_rtl)
11262 : : {
11263 : 0 : tree var = SSA_NAME_VAR (exp);
11264 : 0 : if (var && DECL_RTL_SET_P (var))
11265 : 0 : return DECL_RTL (var);
11266 : 0 : return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp)),
11267 : 0 : LAST_VIRTUAL_REGISTER + 1);
11268 : : }
11269 : :
11270 : 51256500 : g = get_gimple_for_ssa_name (exp);
11271 : : /* For EXPAND_INITIALIZER try harder to get something simpler. */
11272 : 51256500 : if (g == NULL
11273 : 51256500 : && modifier == EXPAND_INITIALIZER
11274 : 26 : && !SSA_NAME_IS_DEFAULT_DEF (exp)
11275 : 11 : && (optimize || !SSA_NAME_VAR (exp)
11276 : 1 : || DECL_IGNORED_P (SSA_NAME_VAR (exp)))
11277 : 51256510 : && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp)))
11278 : 6 : g = SSA_NAME_DEF_STMT (exp);
11279 : 51256500 : if (g)
11280 : 7886483 : return expand_expr_real_gassign (as_a<gassign *> (g), target, tmode,
11281 : 7886483 : modifier, alt_rtl, inner_reference_p);
11282 : :
11283 : 43370017 : ssa_name = exp;
11284 : 43370017 : decl_rtl = get_rtx_for_ssa_name (ssa_name);
11285 : 43370017 : exp = SSA_NAME_VAR (ssa_name);
11286 : : /* Optimize and avoid to EXTEND_BITINIT doing anything if it is an
11287 : : SSA_NAME computed within the current function. In such case the
11288 : : value have been already extended before. While if it is a function
11289 : : parameter, result or some memory location, we need to be prepared
11290 : : for some other compiler leaving the bits uninitialized. */
11291 : 16672830 : if (!exp || VAR_P (exp))
11292 : : reduce_bit_field = false;
11293 : 43370017 : goto expand_decl_rtl;
11294 : :
11295 : 18764940 : case VAR_DECL:
11296 : : /* Allow accel compiler to handle variables that require special
11297 : : treatment, e.g. if they have been modified in some way earlier in
11298 : : compilation by the adjust_private_decl OpenACC hook. */
11299 : 18764940 : if (flag_openacc && targetm.goacc.expand_var_decl)
11300 : : {
11301 : 0 : temp = targetm.goacc.expand_var_decl (exp);
11302 : 0 : if (temp)
11303 : : return temp;
11304 : : }
11305 : : /* Expand const VAR_DECLs with CONSTRUCTOR initializers that
11306 : : have scalar integer modes to a reg via store_constructor. */
11307 : 18764940 : if (TREE_READONLY (exp)
11308 : 3347087 : && !TREE_SIDE_EFFECTS (exp)
11309 : 3324681 : && (modifier == EXPAND_NORMAL || modifier == EXPAND_STACK_PARM)
11310 : 15156 : && immediate_const_ctor_p (DECL_INITIAL (exp))
11311 : 89 : && SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (exp)))
11312 : 58 : && crtl->emit.regno_pointer_align_length
11313 : 18764998 : && !target)
11314 : : {
11315 : 31 : target = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
11316 : 31 : store_constructor (DECL_INITIAL (exp), target, 0,
11317 : 31 : int_expr_size (DECL_INITIAL (exp)), false);
11318 : 31 : return target;
11319 : : }
11320 : : /* ... fall through ... */
11321 : :
11322 : 19343061 : case PARM_DECL:
11323 : : /* If a static var's type was incomplete when the decl was written,
11324 : : but the type is complete now, lay out the decl now. */
11325 : 19343061 : if (DECL_SIZE (exp) == 0
11326 : 45621 : && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp))
11327 : 19388570 : && (TREE_STATIC (exp) || DECL_EXTERNAL (exp)))
11328 : 45509 : layout_decl (exp, 0);
11329 : :
11330 : : /* fall through */
11331 : :
11332 : 20752973 : case FUNCTION_DECL:
11333 : 20752973 : case RESULT_DECL:
11334 : 20752973 : decl_rtl = DECL_RTL (exp);
11335 : 64122990 : expand_decl_rtl:
11336 : 64122990 : gcc_assert (decl_rtl);
11337 : :
11338 : : /* DECL_MODE might change when TYPE_MODE depends on attribute target
11339 : : settings for VECTOR_TYPE_P that might switch for the function. */
11340 : 64122990 : if (currently_expanding_to_rtl
11341 : 60467510 : && code == VAR_DECL && MEM_P (decl_rtl)
11342 : 77955971 : && VECTOR_TYPE_P (type) && exp && DECL_MODE (exp) != mode)
11343 : 57 : decl_rtl = change_address (decl_rtl, TYPE_MODE (type), 0);
11344 : : else
11345 : 64122933 : decl_rtl = copy_rtx (decl_rtl);
11346 : :
11347 : : /* Record writes to register variables. */
11348 : 64122990 : if (modifier == EXPAND_WRITE
11349 : 20503358 : && REG_P (decl_rtl)
11350 : 79025856 : && HARD_REGISTER_P (decl_rtl))
11351 : 2014 : add_to_hard_reg_set (&crtl->asm_clobbers,
11352 : 2014 : GET_MODE (decl_rtl), REGNO (decl_rtl));
11353 : :
11354 : : /* Ensure variable marked as used even if it doesn't go through
11355 : : a parser. If it hasn't be used yet, write out an external
11356 : : definition. */
11357 : 64122990 : if (exp)
11358 : 37425803 : TREE_USED (exp) = 1;
11359 : :
11360 : : /* Show we haven't gotten RTL for this yet. */
11361 : 101548793 : temp = 0;
11362 : :
11363 : : /* Variables inherited from containing functions should have
11364 : : been lowered by this point. */
11365 : 37425803 : if (exp)
11366 : : {
11367 : 37425803 : tree context = decl_function_context (exp);
11368 : 37425803 : gcc_assert (SCOPE_FILE_SCOPE_P (context)
11369 : : || context == current_function_decl
11370 : : || TREE_STATIC (exp)
11371 : : || DECL_EXTERNAL (exp)
11372 : : /* ??? C++ creates functions that are not
11373 : : TREE_STATIC. */
11374 : : || TREE_CODE (exp) == FUNCTION_DECL);
11375 : : }
11376 : :
11377 : : /* This is the case of an array whose size is to be determined
11378 : : from its initializer, while the initializer is still being parsed.
11379 : : ??? We aren't parsing while expanding anymore. */
11380 : :
11381 : 64122990 : if (MEM_P (decl_rtl) && REG_P (XEXP (decl_rtl, 0)))
11382 : 372459 : temp = validize_mem (decl_rtl);
11383 : :
11384 : : /* If DECL_RTL is memory, we are in the normal case and the
11385 : : address is not valid, get the address into a register. */
11386 : :
11387 : 63750531 : else if (MEM_P (decl_rtl) && modifier != EXPAND_INITIALIZER)
11388 : : {
11389 : 17638549 : if (alt_rtl)
11390 : 2024332 : *alt_rtl = decl_rtl;
11391 : 17638549 : decl_rtl = use_anchored_address (decl_rtl);
11392 : 17638549 : if (modifier != EXPAND_CONST_ADDRESS
11393 : 17638549 : && modifier != EXPAND_SUM
11394 : 29496568 : && !memory_address_addr_space_p (exp ? DECL_MODE (exp)
11395 : 16597 : : GET_MODE (decl_rtl),
11396 : : XEXP (decl_rtl, 0),
11397 : 11858019 : MEM_ADDR_SPACE (decl_rtl)))
11398 : 136372 : temp = replace_equiv_address (decl_rtl,
11399 : : copy_rtx (XEXP (decl_rtl, 0)));
11400 : : }
11401 : :
11402 : : /* If we got something, return it. But first, set the alignment
11403 : : if the address is a register. */
11404 : 18011008 : if (temp != 0)
11405 : : {
11406 : 508831 : if (exp && MEM_P (temp) && REG_P (XEXP (temp, 0)))
11407 : 479144 : mark_reg_pointer (XEXP (temp, 0), DECL_ALIGN (exp));
11408 : : }
11409 : 63614159 : else if (MEM_P (decl_rtl))
11410 : : temp = decl_rtl;
11411 : :
11412 : 43087124 : if (temp != 0)
11413 : : {
11414 : 21515020 : if (MEM_P (temp)
11415 : : && modifier != EXPAND_WRITE
11416 : 21515020 : && modifier != EXPAND_MEMORY
11417 : : && modifier != EXPAND_INITIALIZER
11418 : 15846284 : && modifier != EXPAND_CONST_ADDRESS
11419 : 6722586 : && modifier != EXPAND_SUM
11420 : 6722586 : && !inner_reference_p
11421 : 4483190 : && mode != BLKmode
11422 : 25557319 : && MEM_ALIGN (temp) < GET_MODE_ALIGNMENT (mode))
11423 : 18703 : temp = expand_misaligned_mem_ref (temp, mode, unsignedp,
11424 : 18703 : MEM_ALIGN (temp), NULL_RTX, NULL);
11425 : :
11426 : 21515020 : return EXTEND_BITINT (temp);
11427 : : }
11428 : :
11429 : 42607970 : if (exp)
11430 : 15927390 : dmode = DECL_MODE (exp);
11431 : : else
11432 : 26680580 : dmode = TYPE_MODE (TREE_TYPE (ssa_name));
11433 : :
11434 : : /* If the mode of DECL_RTL does not match that of the decl,
11435 : : there are two cases: we are dealing with a BLKmode value
11436 : : that is returned in a register, or we are dealing with
11437 : : a promoted value. In the latter case, return a SUBREG
11438 : : of the wanted mode, but mark it so that we know that it
11439 : : was already extended. */
11440 : 42607970 : if (REG_P (decl_rtl)
11441 : 42061300 : && dmode != BLKmode
11442 : 42061300 : && GET_MODE (decl_rtl) != dmode)
11443 : : {
11444 : 69 : machine_mode pmode;
11445 : :
11446 : : /* Get the signedness to be used for this variable. Ensure we get
11447 : : the same mode we got when the variable was declared. */
11448 : 69 : if (code != SSA_NAME)
11449 : 0 : pmode = promote_decl_mode (exp, &unsignedp);
11450 : 69 : else if ((g = SSA_NAME_DEF_STMT (ssa_name))
11451 : 69 : && gimple_code (g) == GIMPLE_CALL
11452 : 71 : && !gimple_call_internal_p (g))
11453 : 2 : pmode = promote_function_mode (type, mode, &unsignedp,
11454 : 2 : gimple_call_fntype (g),
11455 : : 2);
11456 : : else
11457 : 67 : pmode = promote_ssa_mode (ssa_name, &unsignedp);
11458 : 69 : gcc_assert (GET_MODE (decl_rtl) == pmode);
11459 : :
11460 : : /* Some ABIs require scalar floating point modes to be passed
11461 : : in a wider scalar integer mode. We need to explicitly
11462 : : truncate to an integer mode of the correct precision before
11463 : : using a SUBREG to reinterpret as a floating point value. */
11464 : 69 : if (SCALAR_FLOAT_MODE_P (mode)
11465 : 0 : && SCALAR_INT_MODE_P (pmode)
11466 : 69 : && known_lt (GET_MODE_SIZE (mode), GET_MODE_SIZE (pmode)))
11467 : 0 : return convert_wider_int_to_float (mode, pmode, decl_rtl);
11468 : :
11469 : 69 : temp = gen_lowpart_SUBREG (mode, decl_rtl);
11470 : 69 : SUBREG_PROMOTED_VAR_P (temp) = 1;
11471 : 69 : SUBREG_PROMOTED_SET (temp, unsignedp);
11472 : 69 : return EXTEND_BITINT (temp);
11473 : : }
11474 : :
11475 : 42607901 : return EXTEND_BITINT (decl_rtl);
11476 : :
11477 : 37961818 : case INTEGER_CST:
11478 : 37961818 : {
11479 : 37961818 : if (TREE_CODE (type) == BITINT_TYPE)
11480 : : {
11481 : 10251 : unsigned int prec = TYPE_PRECISION (type);
11482 : 10251 : struct bitint_info info;
11483 : 10251 : bool ok = targetm.c.bitint_type_info (prec, &info);
11484 : 10251 : gcc_assert (ok);
11485 : 10251 : scalar_int_mode limb_mode
11486 : 10251 : = as_a <scalar_int_mode> (info.limb_mode);
11487 : 10251 : unsigned int limb_prec = GET_MODE_PRECISION (limb_mode);
11488 : 16941 : if (prec > limb_prec && prec > MAX_FIXED_MODE_SIZE)
11489 : : {
11490 : : /* Emit large/huge _BitInt INTEGER_CSTs into memory. */
11491 : 4258 : exp = tree_output_constant_def (exp);
11492 : 4258 : return expand_expr (exp, target, VOIDmode, modifier);
11493 : : }
11494 : : }
11495 : :
11496 : : /* Given that TYPE_PRECISION (type) is not always equal to
11497 : : GET_MODE_PRECISION (TYPE_MODE (type)), we need to extend from
11498 : : the former to the latter according to the signedness of the
11499 : : type. */
11500 : 37957560 : scalar_int_mode int_mode = SCALAR_INT_TYPE_MODE (type);
11501 : 37957560 : temp = immed_wide_int_const
11502 : 37957560 : (wi::to_wide (exp, GET_MODE_PRECISION (int_mode)), int_mode);
11503 : 37957560 : return temp;
11504 : : }
11505 : :
11506 : 496928 : case VECTOR_CST:
11507 : 496928 : {
11508 : 496928 : tree tmp = NULL_TREE;
11509 : 496928 : if (VECTOR_MODE_P (mode))
11510 : 495083 : return const_vector_from_tree (exp);
11511 : 1845 : scalar_int_mode int_mode;
11512 : 1845 : if (is_int_mode (mode, &int_mode))
11513 : : {
11514 : 155 : tree type_for_mode = lang_hooks.types.type_for_mode (int_mode, 1);
11515 : 155 : if (type_for_mode)
11516 : 155 : tmp = fold_unary_loc (loc, VIEW_CONVERT_EXPR,
11517 : : type_for_mode, exp);
11518 : : }
11519 : 155 : if (!tmp)
11520 : : {
11521 : 1690 : vec<constructor_elt, va_gc> *v;
11522 : : /* Constructors need to be fixed-length. FIXME. */
11523 : 1690 : unsigned int nunits = VECTOR_CST_NELTS (exp).to_constant ();
11524 : 1690 : vec_alloc (v, nunits);
11525 : 21799 : for (unsigned int i = 0; i < nunits; ++i)
11526 : 20109 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, VECTOR_CST_ELT (exp, i));
11527 : 1690 : tmp = build_constructor (type, v);
11528 : : }
11529 : 1845 : return expand_expr (tmp, ignore ? const0_rtx : target,
11530 : 1845 : tmode, modifier);
11531 : : }
11532 : :
11533 : 127 : case CONST_DECL:
11534 : 127 : if (modifier == EXPAND_WRITE)
11535 : : {
11536 : : /* Writing into CONST_DECL is always invalid, but handle it
11537 : : gracefully. */
11538 : 2 : addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (exp));
11539 : 2 : scalar_int_mode address_mode = targetm.addr_space.address_mode (as);
11540 : 2 : op0 = expand_expr_addr_expr_1 (exp, NULL_RTX, address_mode,
11541 : : EXPAND_NORMAL, as);
11542 : 2 : op0 = memory_address_addr_space (mode, op0, as);
11543 : 2 : temp = gen_rtx_MEM (mode, op0);
11544 : 2 : set_mem_addr_space (temp, as);
11545 : 2 : return temp;
11546 : : }
11547 : 125 : return expand_expr (DECL_INITIAL (exp), target, VOIDmode, modifier);
11548 : :
11549 : 855504 : case REAL_CST:
11550 : : /* If optimized, generate immediate CONST_DOUBLE
11551 : : which will be turned into memory by reload if necessary.
11552 : :
11553 : : We used to force a register so that loop.c could see it. But
11554 : : this does not allow gen_* patterns to perform optimizations with
11555 : : the constants. It also produces two insns in cases like "x = 1.0;".
11556 : : On most machines, floating-point constants are not permitted in
11557 : : many insns, so we'd end up copying it to a register in any case.
11558 : :
11559 : : Now, we do the copying in expand_binop, if appropriate. */
11560 : 855504 : return const_double_from_real_value (TREE_REAL_CST (exp),
11561 : 1711008 : TYPE_MODE (TREE_TYPE (exp)));
11562 : :
11563 : 0 : case FIXED_CST:
11564 : 0 : return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp),
11565 : : TYPE_MODE (TREE_TYPE (exp)));
11566 : :
11567 : 18336 : case COMPLEX_CST:
11568 : : /* Handle evaluating a complex constant in a CONCAT target. */
11569 : 18336 : if (original_target && GET_CODE (original_target) == CONCAT)
11570 : : {
11571 : 203 : rtx rtarg, itarg;
11572 : :
11573 : 203 : mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
11574 : 203 : rtarg = XEXP (original_target, 0);
11575 : 203 : itarg = XEXP (original_target, 1);
11576 : :
11577 : : /* Move the real and imaginary parts separately. */
11578 : 203 : op0 = expand_expr (TREE_REALPART (exp), rtarg, mode, EXPAND_NORMAL);
11579 : 203 : op1 = expand_expr (TREE_IMAGPART (exp), itarg, mode, EXPAND_NORMAL);
11580 : :
11581 : 203 : if (op0 != rtarg)
11582 : 203 : emit_move_insn (rtarg, op0);
11583 : 203 : if (op1 != itarg)
11584 : 203 : emit_move_insn (itarg, op1);
11585 : :
11586 : 203 : return original_target;
11587 : : }
11588 : :
11589 : : /* fall through */
11590 : :
11591 : 151081 : case STRING_CST:
11592 : 151081 : temp = expand_expr_constant (exp, 1, modifier);
11593 : :
11594 : : /* temp contains a constant address.
11595 : : On RISC machines where a constant address isn't valid,
11596 : : make some insns to get that address into a register. */
11597 : 151081 : if (modifier != EXPAND_CONST_ADDRESS
11598 : : && modifier != EXPAND_INITIALIZER
11599 : 151081 : && modifier != EXPAND_SUM
11600 : 169646 : && ! memory_address_addr_space_p (mode, XEXP (temp, 0),
11601 : 18565 : MEM_ADDR_SPACE (temp)))
11602 : 12 : return replace_equiv_address (temp,
11603 : 12 : copy_rtx (XEXP (temp, 0)));
11604 : : return temp;
11605 : :
11606 : 0 : case POLY_INT_CST:
11607 : 0 : return immed_wide_int_const (poly_int_cst_value (exp), mode);
11608 : :
11609 : 1410 : case SAVE_EXPR:
11610 : 1410 : {
11611 : 1410 : tree val = treeop0;
11612 : 1410 : rtx ret = expand_expr_real_1 (val, target, tmode, modifier, alt_rtl,
11613 : : inner_reference_p);
11614 : :
11615 : 1410 : if (!SAVE_EXPR_RESOLVED_P (exp))
11616 : : {
11617 : : /* We can indeed still hit this case, typically via builtin
11618 : : expanders calling save_expr immediately before expanding
11619 : : something. Assume this means that we only have to deal
11620 : : with non-BLKmode values. */
11621 : 1390 : gcc_assert (GET_MODE (ret) != BLKmode);
11622 : :
11623 : 1390 : val = build_decl (curr_insn_location (),
11624 : 1390 : VAR_DECL, NULL, TREE_TYPE (exp));
11625 : 1390 : DECL_ARTIFICIAL (val) = 1;
11626 : 1390 : DECL_IGNORED_P (val) = 1;
11627 : 1390 : treeop0 = val;
11628 : 1390 : TREE_OPERAND (exp, 0) = treeop0;
11629 : 1390 : SAVE_EXPR_RESOLVED_P (exp) = 1;
11630 : :
11631 : 1390 : if (!CONSTANT_P (ret))
11632 : 1390 : ret = copy_to_reg (ret);
11633 : 1390 : SET_DECL_RTL (val, ret);
11634 : : }
11635 : :
11636 : : return ret;
11637 : : }
11638 : :
11639 : :
11640 : 194914 : case CONSTRUCTOR:
11641 : : /* If we don't need the result, just ensure we evaluate any
11642 : : subexpressions. */
11643 : 194914 : if (ignore)
11644 : : {
11645 : : unsigned HOST_WIDE_INT idx;
11646 : : tree value;
11647 : :
11648 : 0 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
11649 : 0 : expand_expr (value, const0_rtx, VOIDmode, EXPAND_NORMAL);
11650 : :
11651 : 0 : return const0_rtx;
11652 : : }
11653 : :
11654 : 194914 : return expand_constructor (exp, target, modifier, false);
11655 : :
11656 : 741537 : case TARGET_MEM_REF:
11657 : 741537 : {
11658 : 741537 : addr_space_t as
11659 : 741537 : = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
11660 : 741537 : unsigned int align;
11661 : :
11662 : 741537 : op0 = addr_for_mem_ref (exp, as, true);
11663 : 741537 : op0 = memory_address_addr_space (mode, op0, as);
11664 : 741537 : temp = gen_rtx_MEM (mode, op0);
11665 : 741537 : set_mem_attributes (temp, exp, 0);
11666 : 741537 : set_mem_addr_space (temp, as);
11667 : 741537 : align = get_object_alignment (exp);
11668 : 741537 : if (modifier != EXPAND_WRITE
11669 : 741537 : && modifier != EXPAND_MEMORY
11670 : 519832 : && mode != BLKmode
11671 : 1249052 : && align < GET_MODE_ALIGNMENT (mode))
11672 : 48592 : temp = expand_misaligned_mem_ref (temp, mode, unsignedp,
11673 : : align, NULL_RTX, NULL);
11674 : 741537 : return EXTEND_BITINT (temp);
11675 : : }
11676 : :
11677 : 5821577 : case MEM_REF:
11678 : 5821577 : {
11679 : 5821577 : const bool reverse = REF_REVERSE_STORAGE_ORDER (exp);
11680 : 5821577 : addr_space_t as
11681 : 5821577 : = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
11682 : 5821577 : machine_mode address_mode;
11683 : 5821577 : tree base = TREE_OPERAND (exp, 0);
11684 : 5821577 : gimple *def_stmt;
11685 : 5821577 : unsigned align;
11686 : : /* Handle expansion of non-aliased memory with non-BLKmode. That
11687 : : might end up in a register. */
11688 : 5821577 : if (mem_ref_refers_to_non_mem_p (exp))
11689 : : {
11690 : 65046 : poly_int64 offset = mem_ref_offset (exp).force_shwi ();
11691 : 65046 : base = TREE_OPERAND (base, 0);
11692 : 65046 : poly_uint64 type_size;
11693 : 130092 : if (known_eq (offset, 0)
11694 : 42030 : && !reverse
11695 : 42030 : && poly_int_tree_p (TYPE_SIZE (type), &type_size)
11696 : 149106 : && known_eq (GET_MODE_BITSIZE (DECL_MODE (base)), type_size))
11697 : 25169 : return expand_expr (build1 (VIEW_CONVERT_EXPR, type, base),
11698 : 25169 : target, tmode, modifier);
11699 : 39877 : if (TYPE_MODE (type) == BLKmode)
11700 : : {
11701 : 558 : temp = assign_stack_temp (DECL_MODE (base),
11702 : 1116 : GET_MODE_SIZE (DECL_MODE (base)));
11703 : 558 : store_expr (base, temp, 0, false, false);
11704 : 558 : temp = adjust_address (temp, BLKmode, offset);
11705 : 558 : set_mem_size (temp, int_size_in_bytes (type));
11706 : 558 : return temp;
11707 : : }
11708 : 39319 : exp = build3 (BIT_FIELD_REF, type, base, TYPE_SIZE (type),
11709 : 39319 : bitsize_int (offset * BITS_PER_UNIT));
11710 : 39319 : REF_REVERSE_STORAGE_ORDER (exp) = reverse;
11711 : 39319 : return expand_expr (exp, target, tmode, modifier);
11712 : : }
11713 : 5756531 : address_mode = targetm.addr_space.address_mode (as);
11714 : 5756531 : if ((def_stmt = get_def_for_expr (base, BIT_AND_EXPR)))
11715 : : {
11716 : 39 : tree mask = gimple_assign_rhs2 (def_stmt);
11717 : 39 : base = build2 (BIT_AND_EXPR, TREE_TYPE (base),
11718 : : gimple_assign_rhs1 (def_stmt), mask);
11719 : 39 : TREE_OPERAND (exp, 0) = base;
11720 : : }
11721 : 5756531 : align = get_object_alignment (exp);
11722 : 5756531 : op0 = expand_expr (base, NULL_RTX, VOIDmode, EXPAND_SUM);
11723 : 5756531 : op0 = memory_address_addr_space (mode, op0, as);
11724 : 5756531 : if (!integer_zerop (TREE_OPERAND (exp, 1)))
11725 : : {
11726 : 1617975 : rtx off = immed_wide_int_const (mem_ref_offset (exp), address_mode);
11727 : 1617975 : op0 = simplify_gen_binary (PLUS, address_mode, op0, off);
11728 : 1617975 : op0 = memory_address_addr_space (mode, op0, as);
11729 : : }
11730 : 5756531 : temp = gen_rtx_MEM (mode, op0);
11731 : 5756531 : set_mem_attributes (temp, exp, 0);
11732 : 5756531 : set_mem_addr_space (temp, as);
11733 : 5756531 : if (TREE_THIS_VOLATILE (exp))
11734 : 19227 : MEM_VOLATILE_P (temp) = 1;
11735 : 5756531 : if (modifier == EXPAND_WRITE || modifier == EXPAND_MEMORY)
11736 : : return temp;
11737 : 3543939 : if (!inner_reference_p
11738 : 1757572 : && mode != BLKmode
11739 : 5236578 : && align < GET_MODE_ALIGNMENT (mode))
11740 : 132230 : temp = expand_misaligned_mem_ref (temp, mode, unsignedp, align,
11741 : : modifier == EXPAND_STACK_PARM
11742 : : ? NULL_RTX : target, alt_rtl);
11743 : 3543939 : if (reverse)
11744 : 7 : temp = flip_storage_order (mode, temp);
11745 : 3543939 : return EXTEND_BITINT (temp);
11746 : : }
11747 : :
11748 : 562582 : case ARRAY_REF:
11749 : :
11750 : 562582 : {
11751 : 562582 : tree array = treeop0;
11752 : 562582 : tree index = treeop1;
11753 : 562582 : tree init;
11754 : :
11755 : : /* Fold an expression like: "foo"[2].
11756 : : This is not done in fold so it won't happen inside &.
11757 : : Don't fold if this is for wide characters since it's too
11758 : : difficult to do correctly and this is a very rare case. */
11759 : :
11760 : 562582 : if (modifier != EXPAND_CONST_ADDRESS
11761 : 562582 : && modifier != EXPAND_INITIALIZER
11762 : 562582 : && modifier != EXPAND_MEMORY)
11763 : : {
11764 : 562473 : tree t = fold_read_from_constant_string (exp);
11765 : :
11766 : 562473 : if (t)
11767 : 0 : return expand_expr (t, target, tmode, modifier);
11768 : : }
11769 : :
11770 : : /* If this is a constant index into a constant array,
11771 : : just get the value from the array. Handle both the cases when
11772 : : we have an explicit constructor and when our operand is a variable
11773 : : that was declared const. */
11774 : :
11775 : 562582 : if (modifier != EXPAND_CONST_ADDRESS
11776 : : && modifier != EXPAND_INITIALIZER
11777 : : && modifier != EXPAND_MEMORY
11778 : 562473 : && TREE_CODE (array) == CONSTRUCTOR
11779 : 0 : && ! TREE_SIDE_EFFECTS (array)
11780 : 562582 : && TREE_CODE (index) == INTEGER_CST)
11781 : : {
11782 : : unsigned HOST_WIDE_INT ix;
11783 : : tree field, value;
11784 : :
11785 : 0 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array), ix,
11786 : : field, value)
11787 : 0 : if (tree_int_cst_equal (field, index))
11788 : : {
11789 : 0 : if (!TREE_SIDE_EFFECTS (value))
11790 : 0 : return expand_expr (fold (value), target, tmode, modifier);
11791 : : break;
11792 : : }
11793 : : }
11794 : :
11795 : 562582 : else if (optimize >= 1
11796 : : && modifier != EXPAND_CONST_ADDRESS
11797 : 301849 : && modifier != EXPAND_INITIALIZER
11798 : 301849 : && modifier != EXPAND_MEMORY
11799 : 301744 : && TREE_READONLY (array) && ! TREE_SIDE_EFFECTS (array)
11800 : 7677 : && TREE_CODE (index) == INTEGER_CST
11801 : 1559 : && (VAR_P (array) || TREE_CODE (array) == CONST_DECL)
11802 : 562696 : && (init = ctor_for_folding (array)) != error_mark_node)
11803 : : {
11804 : 90 : if (init == NULL_TREE)
11805 : : {
11806 : 5 : tree value = build_zero_cst (type);
11807 : 5 : if (TREE_CODE (value) == CONSTRUCTOR)
11808 : : {
11809 : : /* If VALUE is a CONSTRUCTOR, this optimization is only
11810 : : useful if this doesn't store the CONSTRUCTOR into
11811 : : memory. If it does, it is more efficient to just
11812 : : load the data from the array directly. */
11813 : 5 : rtx ret = expand_constructor (value, target,
11814 : : modifier, true);
11815 : 5 : if (ret == NULL_RTX)
11816 : : value = NULL_TREE;
11817 : : }
11818 : :
11819 : : if (value)
11820 : 0 : return expand_expr (value, target, tmode, modifier);
11821 : : }
11822 : 85 : else if (TREE_CODE (init) == CONSTRUCTOR)
11823 : : {
11824 : : unsigned HOST_WIDE_INT ix;
11825 : : tree field, value;
11826 : :
11827 : 170 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), ix,
11828 : : field, value)
11829 : 149 : if (tree_int_cst_equal (field, index))
11830 : : {
11831 : 63 : if (TREE_SIDE_EFFECTS (value))
11832 : : break;
11833 : :
11834 : 63 : if (TREE_CODE (value) == CONSTRUCTOR)
11835 : : {
11836 : : /* If VALUE is a CONSTRUCTOR, this
11837 : : optimization is only useful if
11838 : : this doesn't store the CONSTRUCTOR
11839 : : into memory. If it does, it is more
11840 : : efficient to just load the data from
11841 : : the array directly. */
11842 : 58 : rtx ret = expand_constructor (value, target,
11843 : : modifier, true);
11844 : 58 : if (ret == NULL_RTX)
11845 : : break;
11846 : : }
11847 : :
11848 : 25 : return
11849 : 25 : expand_expr (fold (value), target, tmode, modifier);
11850 : : }
11851 : : }
11852 : 1 : else if (TREE_CODE (init) == STRING_CST)
11853 : : {
11854 : 1 : tree low_bound = array_ref_low_bound (exp);
11855 : 1 : tree index1 = fold_convert_loc (loc, sizetype, treeop1);
11856 : :
11857 : : /* Optimize the special case of a zero lower bound.
11858 : :
11859 : : We convert the lower bound to sizetype to avoid problems
11860 : : with constant folding. E.g. suppose the lower bound is
11861 : : 1 and its mode is QI. Without the conversion
11862 : : (ARRAY + (INDEX - (unsigned char)1))
11863 : : becomes
11864 : : (ARRAY + (-(unsigned char)1) + INDEX)
11865 : : which becomes
11866 : : (ARRAY + 255 + INDEX). Oops! */
11867 : 1 : if (!integer_zerop (low_bound))
11868 : 0 : index1 = size_diffop_loc (loc, index1,
11869 : : fold_convert_loc (loc, sizetype,
11870 : : low_bound));
11871 : :
11872 : 1 : if (tree_fits_uhwi_p (index1)
11873 : 1 : && compare_tree_int (index1, TREE_STRING_LENGTH (init)) < 0)
11874 : : {
11875 : 0 : tree char_type = TREE_TYPE (TREE_TYPE (init));
11876 : 0 : scalar_int_mode char_mode;
11877 : :
11878 : 0 : if (is_int_mode (TYPE_MODE (char_type), &char_mode)
11879 : 0 : && GET_MODE_SIZE (char_mode) == 1)
11880 : 0 : return gen_int_mode (TREE_STRING_POINTER (init)
11881 : 0 : [TREE_INT_CST_LOW (index1)],
11882 : : char_mode);
11883 : : }
11884 : : }
11885 : : }
11886 : : }
11887 : 562557 : goto normal_inner_ref;
11888 : :
11889 : 3645541 : case COMPONENT_REF:
11890 : 3645541 : gcc_assert (TREE_CODE (treeop0) != CONSTRUCTOR);
11891 : : /* Fall through. */
11892 : 4431652 : case BIT_FIELD_REF:
11893 : 4431652 : case ARRAY_RANGE_REF:
11894 : 3645541 : normal_inner_ref:
11895 : 4431652 : {
11896 : 4431652 : machine_mode mode1, mode2;
11897 : 4431652 : poly_int64 bitsize, bitpos, bytepos;
11898 : 4431652 : tree offset;
11899 : 4431652 : int reversep, volatilep = 0;
11900 : 4431652 : tree tem
11901 : 4431652 : = get_inner_reference (exp, &bitsize, &bitpos, &offset, &mode1,
11902 : : &unsignedp, &reversep, &volatilep);
11903 : 4431652 : rtx orig_op0, memloc;
11904 : 4431652 : bool clear_mem_expr = false;
11905 : 4431652 : bool must_force_mem;
11906 : :
11907 : : /* If we got back the original object, something is wrong. Perhaps
11908 : : we are evaluating an expression too early. In any event, don't
11909 : : infinitely recurse. */
11910 : 4431652 : gcc_assert (tem != exp);
11911 : :
11912 : : /* Make sure bitpos is not negative, this can wreak havoc later. */
11913 : 4431652 : if (maybe_lt (bitpos, 0))
11914 : : {
11915 : 288 : gcc_checking_assert (offset == NULL_TREE);
11916 : 288 : offset = size_int (bits_to_bytes_round_down (bitpos));
11917 : 288 : bitpos = num_trailing_bits (bitpos);
11918 : : }
11919 : :
11920 : : /* If we have either an offset, a BLKmode result, or a reference
11921 : : outside the underlying object, we must force it to memory.
11922 : : Such a case can occur in Ada if we have unchecked conversion
11923 : : of an expression from a scalar type to an aggregate type or
11924 : : for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
11925 : : passed a partially uninitialized object or a view-conversion
11926 : : to a larger size. */
11927 : 8863304 : must_force_mem = offset != NULL_TREE
11928 : 4182327 : || mode1 == BLKmode
11929 : 8525773 : || (mode == BLKmode
11930 : 0 : && !int_mode_for_size (bitsize, 1).exists ());
11931 : :
11932 : 337531 : const enum expand_modifier tem_modifier
11933 : : = must_force_mem
11934 : : ? EXPAND_MEMORY
11935 : 4094121 : : modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier;
11936 : :
11937 : : /* If TEM's type is a union of variable size, pass TARGET to the inner
11938 : : computation, since it will need a temporary and TARGET is known
11939 : : to have to do. This occurs in unchecked conversion in Ada. */
11940 : 4431652 : const rtx tem_target
11941 : 4431652 : = TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
11942 : 31615 : && COMPLETE_TYPE_P (TREE_TYPE (tem))
11943 : 31610 : && TREE_CODE (TYPE_SIZE (TREE_TYPE (tem))) != INTEGER_CST
11944 : 0 : && modifier != EXPAND_STACK_PARM
11945 : 4431652 : ? target
11946 : 4431652 : : NULL_RTX;
11947 : :
11948 : 8863304 : orig_op0 = op0
11949 : 4431652 : = expand_expr_real (tem, tem_target, VOIDmode, tem_modifier, NULL,
11950 : : true);
11951 : :
11952 : : /* If the field has a mode, we want to access it in the
11953 : : field's mode, not the computed mode.
11954 : : If a MEM has VOIDmode (external with incomplete type),
11955 : : use BLKmode for it instead. */
11956 : 4431652 : if (MEM_P (op0))
11957 : : {
11958 : 4084608 : if (mode1 != VOIDmode)
11959 : 3921371 : op0 = adjust_address (op0, mode1, 0);
11960 : 163237 : else if (GET_MODE (op0) == VOIDmode)
11961 : 0 : op0 = adjust_address (op0, BLKmode, 0);
11962 : : }
11963 : :
11964 : 4431652 : mode2
11965 : 4431652 : = CONSTANT_P (op0) ? TYPE_MODE (TREE_TYPE (tem)) : GET_MODE (op0);
11966 : :
11967 : : /* See above for the rationale. */
11968 : 8863304 : if (maybe_gt (bitpos + bitsize, GET_MODE_BITSIZE (mode2)))
11969 : 2778085 : must_force_mem = true;
11970 : :
11971 : : /* Handle CONCAT first. */
11972 : 4431652 : if (GET_CODE (op0) == CONCAT && !must_force_mem)
11973 : : {
11974 : 256 : if (known_eq (bitpos, 0)
11975 : 234 : && known_eq (bitsize, GET_MODE_BITSIZE (GET_MODE (op0)))
11976 : 114 : && COMPLEX_MODE_P (mode1)
11977 : 109 : && COMPLEX_MODE_P (GET_MODE (op0))
11978 : 455 : && (GET_MODE_PRECISION (GET_MODE_INNER (mode1))
11979 : 218 : == GET_MODE_PRECISION (GET_MODE_INNER (GET_MODE (op0)))))
11980 : : {
11981 : 109 : if (reversep)
11982 : 0 : op0 = flip_storage_order (GET_MODE (op0), op0);
11983 : 109 : if (mode1 != GET_MODE (op0))
11984 : : {
11985 : : rtx parts[2];
11986 : 0 : for (int i = 0; i < 2; i++)
11987 : : {
11988 : 0 : rtx op = read_complex_part (op0, i != 0);
11989 : 0 : if (GET_CODE (op) == SUBREG)
11990 : 0 : op = force_reg (GET_MODE (op), op);
11991 : 0 : temp = gen_lowpart_common (GET_MODE_INNER (mode1), op);
11992 : 0 : if (temp)
11993 : : op = temp;
11994 : : else
11995 : : {
11996 : 0 : if (!REG_P (op) && !MEM_P (op))
11997 : 0 : op = force_reg (GET_MODE (op), op);
11998 : 0 : op = gen_lowpart (GET_MODE_INNER (mode1), op);
11999 : : }
12000 : 0 : parts[i] = op;
12001 : : }
12002 : 0 : op0 = gen_rtx_CONCAT (mode1, parts[0], parts[1]);
12003 : : }
12004 : 109 : return op0;
12005 : : }
12006 : 38 : if (known_eq (bitpos, 0)
12007 : 16 : && known_eq (bitsize,
12008 : : GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0))))
12009 : 19 : && maybe_ne (bitsize, 0))
12010 : : {
12011 : 0 : op0 = XEXP (op0, 0);
12012 : 0 : mode2 = GET_MODE (op0);
12013 : : }
12014 : 19 : else if (known_eq (bitpos,
12015 : : GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0))))
12016 : 4 : && known_eq (bitsize,
12017 : : GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 1))))
12018 : 0 : && maybe_ne (bitpos, 0)
12019 : 21 : && maybe_ne (bitsize, 0))
12020 : : {
12021 : 0 : op0 = XEXP (op0, 1);
12022 : 0 : bitpos = 0;
12023 : 0 : mode2 = GET_MODE (op0);
12024 : : }
12025 : : else
12026 : : /* Otherwise force into memory. */
12027 : : must_force_mem = true;
12028 : : }
12029 : :
12030 : : /* If this is a constant, put it in a register if it is a legitimate
12031 : : constant and we don't need a memory reference. */
12032 : 4431543 : if (CONSTANT_P (op0)
12033 : 45 : && mode2 != BLKmode
12034 : 45 : && targetm.legitimate_constant_p (mode2, op0)
12035 : 4431576 : && !must_force_mem)
12036 : 33 : op0 = force_reg (mode2, op0);
12037 : :
12038 : : /* Otherwise, if this is a constant, try to force it to the constant
12039 : : pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
12040 : : is a legitimate constant. */
12041 : 4431510 : else if (CONSTANT_P (op0) && (memloc = force_const_mem (mode2, op0)))
12042 : 12 : op0 = validize_mem (memloc);
12043 : :
12044 : : /* Otherwise, if this is a constant or the object is not in memory
12045 : : and need be, put it there. */
12046 : 4431498 : else if (CONSTANT_P (op0) || (!MEM_P (op0) && must_force_mem))
12047 : : {
12048 : 1247 : memloc = assign_temp (TREE_TYPE (tem), 1, 1);
12049 : 1247 : emit_move_insn (memloc, op0);
12050 : 1247 : op0 = memloc;
12051 : 1247 : clear_mem_expr = true;
12052 : : }
12053 : :
12054 : 4431543 : if (offset)
12055 : : {
12056 : 249325 : machine_mode address_mode;
12057 : 249325 : rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode,
12058 : : EXPAND_SUM);
12059 : :
12060 : 249325 : gcc_assert (MEM_P (op0));
12061 : :
12062 : 249325 : address_mode = get_address_mode (op0);
12063 : 249325 : if (GET_MODE (offset_rtx) != address_mode)
12064 : : {
12065 : : /* We cannot be sure that the RTL in offset_rtx is valid outside
12066 : : of a memory address context, so force it into a register
12067 : : before attempting to convert it to the desired mode. */
12068 : 489 : offset_rtx = force_operand (offset_rtx, NULL_RTX);
12069 : 489 : offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
12070 : : }
12071 : :
12072 : : /* See the comment in expand_assignment for the rationale. */
12073 : 249325 : if (mode1 != VOIDmode
12074 : 249060 : && maybe_ne (bitpos, 0)
12075 : 249902 : && maybe_gt (bitsize, 0)
12076 : 66066 : && multiple_p (bitpos, BITS_PER_UNIT, &bytepos)
12077 : 66066 : && multiple_p (bitpos, bitsize)
12078 : 65516 : && multiple_p (bitsize, GET_MODE_ALIGNMENT (mode1))
12079 : 314841 : && MEM_ALIGN (op0) >= GET_MODE_ALIGNMENT (mode1))
12080 : : {
12081 : 65489 : op0 = adjust_address (op0, mode1, bytepos);
12082 : 65489 : bitpos = 0;
12083 : : }
12084 : :
12085 : 249325 : op0 = offset_address (op0, offset_rtx,
12086 : : highest_pow2_factor (offset));
12087 : : }
12088 : :
12089 : : /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
12090 : : record its alignment as BIGGEST_ALIGNMENT. */
12091 : 4431543 : if (MEM_P (op0)
12092 : 5828945 : && known_eq (bitpos, 0)
12093 : 1397402 : && offset != 0
12094 : 4680125 : && is_aligning_offset (offset, tem))
12095 : 0 : set_mem_align (op0, BIGGEST_ALIGNMENT);
12096 : :
12097 : : /* Don't forget about volatility even if this is a bitfield. */
12098 : 4431543 : if (MEM_P (op0) && volatilep && ! MEM_VOLATILE_P (op0))
12099 : : {
12100 : 3585 : if (op0 == orig_op0)
12101 : 2637 : op0 = copy_rtx (op0);
12102 : :
12103 : 3585 : MEM_VOLATILE_P (op0) = 1;
12104 : : }
12105 : :
12106 : 4431543 : if (MEM_P (op0) && TREE_CODE (tem) == FUNCTION_DECL)
12107 : : {
12108 : 6 : if (op0 == orig_op0)
12109 : 0 : op0 = copy_rtx (op0);
12110 : :
12111 : 6 : set_mem_align (op0, BITS_PER_UNIT);
12112 : : }
12113 : :
12114 : : /* In cases where an aligned union has an unaligned object
12115 : : as a field, we might be extracting a BLKmode value from
12116 : : an integer-mode (e.g., SImode) object. Handle this case
12117 : : by doing the extract into an object as wide as the field
12118 : : (which we know to be the width of a basic mode), then
12119 : : storing into memory, and changing the mode to BLKmode. */
12120 : 4431543 : if (mode1 == VOIDmode
12121 : 4217462 : || REG_P (op0) || GET_CODE (op0) == SUBREG
12122 : 3922508 : || (mode1 != BLKmode && ! direct_load[(int) mode1]
12123 : 26534 : && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
12124 : 22383 : && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT
12125 : : && modifier != EXPAND_CONST_ADDRESS
12126 : 15398 : && modifier != EXPAND_INITIALIZER
12127 : 15398 : && modifier != EXPAND_MEMORY)
12128 : : /* If the bitfield is volatile and the bitsize
12129 : : is narrower than the access size of the bitfield,
12130 : : we need to extract bitfields from the access. */
12131 : 3907110 : || (volatilep && TREE_CODE (exp) == COMPONENT_REF
12132 : 10403 : && DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1))
12133 : 10 : && mode1 != BLKmode
12134 : 20 : && maybe_lt (bitsize, GET_MODE_SIZE (mode1) * BITS_PER_UNIT))
12135 : : /* If the field isn't aligned enough to fetch as a memref,
12136 : : fetch it as a bit field. */
12137 : 3907101 : || (mode1 != BLKmode
12138 : 3818075 : && (((MEM_P (op0)
12139 : 3818075 : ? MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode1)
12140 : 3719456 : || !multiple_p (bitpos, GET_MODE_ALIGNMENT (mode1))
12141 : 0 : : TYPE_ALIGN (TREE_TYPE (tem)) < GET_MODE_ALIGNMENT (mode)
12142 : 0 : || !multiple_p (bitpos, GET_MODE_ALIGNMENT (mode)))
12143 : 103710 : && modifier != EXPAND_MEMORY
12144 : 103710 : && ((modifier == EXPAND_CONST_ADDRESS
12145 : 103710 : || modifier == EXPAND_INITIALIZER)
12146 : 103710 : ? STRICT_ALIGNMENT
12147 : 103710 : : targetm.slow_unaligned_access (mode1,
12148 : 103710 : MEM_ALIGN (op0))))
12149 : 3818075 : || !multiple_p (bitpos, BITS_PER_UNIT)))
12150 : : /* If the type and the field are a constant size and the
12151 : : size of the type isn't the same size as the bitfield,
12152 : : we must use bitfield operations. */
12153 : 12156719 : || (known_size_p (bitsize)
12154 : 3907101 : && TYPE_SIZE (TREE_TYPE (exp))
12155 : 3907101 : && poly_int_tree_p (TYPE_SIZE (TREE_TYPE (exp)))
12156 : 3907101 : && maybe_ne (wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (exp))),
12157 : : bitsize)))
12158 : : {
12159 : 524457 : machine_mode ext_mode = mode;
12160 : :
12161 : 524457 : if (ext_mode == BLKmode
12162 : 524457 : && ! (target != 0 && MEM_P (op0)
12163 : 6 : && MEM_P (target)
12164 : 6 : && multiple_p (bitpos, BITS_PER_UNIT)))
12165 : 4 : ext_mode = int_mode_for_size (bitsize, 1).else_blk ();
12166 : :
12167 : 524457 : if (ext_mode == BLKmode)
12168 : : {
12169 : 10 : if (target == 0)
12170 : 4 : target = assign_temp (type, 1, 1);
12171 : :
12172 : : /* ??? Unlike the similar test a few lines below, this one is
12173 : : very likely obsolete. */
12174 : 10 : if (known_eq (bitsize, 0))
12175 : : return target;
12176 : :
12177 : : /* In this case, BITPOS must start at a byte boundary and
12178 : : TARGET, if specified, must be a MEM. */
12179 : 10 : gcc_assert (MEM_P (op0)
12180 : : && (!target || MEM_P (target)));
12181 : :
12182 : 10 : bytepos = exact_div (bitpos, BITS_PER_UNIT);
12183 : 10 : poly_int64 bytesize = bits_to_bytes_round_up (bitsize);
12184 : 30 : emit_block_move (target,
12185 : 10 : adjust_address (op0, VOIDmode, bytepos),
12186 : 10 : gen_int_mode (bytesize, Pmode),
12187 : : (modifier == EXPAND_STACK_PARM
12188 : : ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
12189 : :
12190 : 10 : return target;
12191 : : }
12192 : :
12193 : : /* If we have nothing to extract, the result will be 0 for targets
12194 : : with SHIFT_COUNT_TRUNCATED == 0 and garbage otherwise. Always
12195 : : return 0 for the sake of consistency, as reading a zero-sized
12196 : : bitfield is valid in Ada and the value is fully specified. */
12197 : 524447 : if (known_eq (bitsize, 0))
12198 : 0 : return const0_rtx;
12199 : :
12200 : 524447 : op0 = validize_mem (op0);
12201 : :
12202 : 524447 : if (MEM_P (op0) && REG_P (XEXP (op0, 0)))
12203 : 51869 : mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
12204 : :
12205 : : /* If the result has aggregate type and the extraction is done in
12206 : : an integral mode, then the field may be not aligned on a byte
12207 : : boundary; in this case, if it has reverse storage order, it
12208 : : needs to be extracted as a scalar field with reverse storage
12209 : : order and put back into memory order afterwards. */
12210 : 524447 : if (AGGREGATE_TYPE_P (type)
12211 : 771 : && GET_MODE_CLASS (ext_mode) == MODE_INT)
12212 : 695 : reversep = TYPE_REVERSE_STORAGE_ORDER (type);
12213 : :
12214 : 524447 : gcc_checking_assert (known_ge (bitpos, 0));
12215 : 537214 : op0 = extract_bit_field (op0, bitsize, bitpos, unsignedp,
12216 : : (modifier == EXPAND_STACK_PARM
12217 : : ? NULL_RTX : target),
12218 : : ext_mode, ext_mode, reversep, alt_rtl);
12219 : :
12220 : : /* If the result has aggregate type and the mode of OP0 is an
12221 : : integral mode then, if BITSIZE is narrower than this mode
12222 : : and this is for big-endian data, we must put the field
12223 : : into the high-order bits. And we must also put it back
12224 : : into memory order if it has been previously reversed. */
12225 : 524447 : scalar_int_mode op0_mode;
12226 : 524447 : if (AGGREGATE_TYPE_P (type)
12227 : 524447 : && is_int_mode (GET_MODE (op0), &op0_mode))
12228 : : {
12229 : 695 : HOST_WIDE_INT size = GET_MODE_BITSIZE (op0_mode);
12230 : :
12231 : 695 : gcc_checking_assert (known_le (bitsize, size));
12232 : 695 : if (maybe_lt (bitsize, size)
12233 : 695 : && reversep ? !BYTES_BIG_ENDIAN : BYTES_BIG_ENDIAN)
12234 : 0 : op0 = expand_shift (LSHIFT_EXPR, op0_mode, op0,
12235 : : size - bitsize, op0, 1);
12236 : :
12237 : 695 : if (reversep)
12238 : 0 : op0 = flip_storage_order (op0_mode, op0);
12239 : : }
12240 : :
12241 : : /* If the result type is BLKmode, store the data into a temporary
12242 : : of the appropriate type, but with the mode corresponding to the
12243 : : mode for the data we have (op0's mode). */
12244 : 524447 : if (mode == BLKmode)
12245 : : {
12246 : 0 : rtx new_rtx
12247 : 0 : = assign_stack_temp_for_type (ext_mode,
12248 : 0 : GET_MODE_BITSIZE (ext_mode),
12249 : : type);
12250 : 0 : emit_move_insn (new_rtx, op0);
12251 : 0 : op0 = copy_rtx (new_rtx);
12252 : 0 : PUT_MODE (op0, BLKmode);
12253 : : }
12254 : :
12255 : 524447 : return op0;
12256 : : }
12257 : :
12258 : : /* If the result is BLKmode, use that to access the object
12259 : : now as well. */
12260 : 3907086 : if (mode == BLKmode)
12261 : 89016 : mode1 = BLKmode;
12262 : :
12263 : : /* Get a reference to just this component. */
12264 : 3907086 : bytepos = bits_to_bytes_round_down (bitpos);
12265 : 3907086 : if (modifier == EXPAND_CONST_ADDRESS
12266 : 3907086 : || modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
12267 : 159544 : op0 = adjust_address_nv (op0, mode1, bytepos);
12268 : : else
12269 : 3747542 : op0 = adjust_address (op0, mode1, bytepos);
12270 : :
12271 : 3907086 : if (op0 == orig_op0)
12272 : 125138 : op0 = copy_rtx (op0);
12273 : :
12274 : : /* Don't set memory attributes if the base expression is
12275 : : SSA_NAME that got expanded as a MEM or a CONSTANT. In that case,
12276 : : we should just honor its original memory attributes. */
12277 : 3907086 : if (!(TREE_CODE (tem) == SSA_NAME
12278 : 7987 : && (MEM_P (orig_op0) || CONSTANT_P (orig_op0))))
12279 : 3899099 : set_mem_attributes (op0, exp, 0);
12280 : :
12281 : 3907086 : if (REG_P (XEXP (op0, 0)))
12282 : 628739 : mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
12283 : :
12284 : : /* If op0 is a temporary because the original expressions was forced
12285 : : to memory, clear MEM_EXPR so that the original expression cannot
12286 : : be marked as addressable through MEM_EXPR of the temporary. */
12287 : 3907086 : if (clear_mem_expr)
12288 : 1125 : set_mem_expr (op0, NULL_TREE);
12289 : :
12290 : 3907086 : MEM_VOLATILE_P (op0) |= volatilep;
12291 : :
12292 : 3907086 : if (reversep
12293 : : && modifier != EXPAND_MEMORY
12294 : 439 : && modifier != EXPAND_WRITE)
12295 : 439 : op0 = flip_storage_order (mode1, op0);
12296 : :
12297 : 3907086 : op0 = EXTEND_BITINT (op0);
12298 : :
12299 : 3907086 : if (mode == mode1 || mode1 == BLKmode || mode1 == tmode
12300 : : || modifier == EXPAND_CONST_ADDRESS
12301 : 0 : || modifier == EXPAND_INITIALIZER)
12302 : : return op0;
12303 : :
12304 : 0 : if (target == 0)
12305 : 0 : target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
12306 : :
12307 : 0 : convert_move (target, op0, unsignedp);
12308 : 0 : return target;
12309 : : }
12310 : :
12311 : 65735 : case OBJ_TYPE_REF:
12312 : 65735 : return expand_expr (OBJ_TYPE_REF_EXPR (exp), target, tmode, modifier);
12313 : :
12314 : 6357385 : case CALL_EXPR:
12315 : : /* All valid uses of __builtin_va_arg_pack () are removed during
12316 : : inlining. */
12317 : 6357385 : if (CALL_EXPR_VA_ARG_PACK (exp))
12318 : 6 : error ("invalid use of %<__builtin_va_arg_pack ()%>");
12319 : 6357385 : {
12320 : 6357385 : tree fndecl = get_callee_fndecl (exp), attr;
12321 : :
12322 : 6357385 : if (fndecl
12323 : : /* Don't diagnose the error attribute in thunks, those are
12324 : : artificially created. */
12325 : 6176086 : && !CALL_FROM_THUNK_P (exp)
12326 : 12528974 : && (attr = lookup_attribute ("error",
12327 : 6171589 : DECL_ATTRIBUTES (fndecl))) != NULL)
12328 : : {
12329 : 6 : const char *ident = lang_hooks.decl_printable_name (fndecl, 1);
12330 : 6 : error ("call to %qs declared with attribute error: %s",
12331 : : identifier_to_locale (ident),
12332 : 6 : TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12333 : : }
12334 : 6357385 : if (fndecl
12335 : : /* Don't diagnose the warning attribute in thunks, those are
12336 : : artificially created. */
12337 : 6176086 : && !CALL_FROM_THUNK_P (exp)
12338 : 12528974 : && (attr = lookup_attribute ("warning",
12339 : 6171589 : DECL_ATTRIBUTES (fndecl))) != NULL)
12340 : : {
12341 : 20 : const char *ident = lang_hooks.decl_printable_name (fndecl, 1);
12342 : 20 : warning_at (EXPR_LOCATION (exp),
12343 : : OPT_Wattribute_warning,
12344 : : "call to %qs declared with attribute warning: %s",
12345 : : identifier_to_locale (ident),
12346 : 20 : TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12347 : : }
12348 : :
12349 : : /* Check for a built-in function. */
12350 : 6357385 : if (fndecl && fndecl_built_in_p (fndecl))
12351 : : {
12352 : 1861614 : gcc_assert (DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_FRONTEND);
12353 : 1861614 : return expand_builtin (exp, target, subtarget, tmode, ignore);
12354 : : }
12355 : : }
12356 : 4495771 : temp = expand_call (exp, target, ignore);
12357 : 4495771 : return EXTEND_BITINT (temp);
12358 : :
12359 : 325055 : case VIEW_CONVERT_EXPR:
12360 : 325055 : op0 = NULL_RTX;
12361 : :
12362 : : /* If we are converting to BLKmode, try to avoid an intermediate
12363 : : temporary by fetching an inner memory reference. */
12364 : 325055 : if (mode == BLKmode
12365 : 73451 : && poly_int_tree_p (TYPE_SIZE (type))
12366 : 73451 : && TYPE_MODE (TREE_TYPE (treeop0)) != BLKmode
12367 : 325086 : && handled_component_p (treeop0))
12368 : : {
12369 : 0 : machine_mode mode1;
12370 : 0 : poly_int64 bitsize, bitpos, bytepos;
12371 : 0 : tree offset;
12372 : 0 : int reversep, volatilep = 0;
12373 : 0 : tree tem
12374 : 0 : = get_inner_reference (treeop0, &bitsize, &bitpos, &offset, &mode1,
12375 : : &unsignedp, &reversep, &volatilep);
12376 : :
12377 : : /* ??? We should work harder and deal with non-zero offsets. */
12378 : 0 : if (!offset
12379 : 0 : && multiple_p (bitpos, BITS_PER_UNIT, &bytepos)
12380 : 0 : && !reversep
12381 : 0 : && known_size_p (bitsize)
12382 : 0 : && known_eq (wi::to_poly_offset (TYPE_SIZE (type)), bitsize))
12383 : : {
12384 : : /* See the normal_inner_ref case for the rationale. */
12385 : 0 : rtx orig_op0
12386 : 0 : = expand_expr_real (tem,
12387 : 0 : (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
12388 : 0 : && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
12389 : : != INTEGER_CST)
12390 : 0 : && modifier != EXPAND_STACK_PARM
12391 : : ? target : NULL_RTX),
12392 : : VOIDmode,
12393 : : modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier,
12394 : : NULL, true);
12395 : :
12396 : 0 : if (MEM_P (orig_op0))
12397 : : {
12398 : 0 : op0 = orig_op0;
12399 : :
12400 : : /* Get a reference to just this component. */
12401 : 0 : if (modifier == EXPAND_CONST_ADDRESS
12402 : : || modifier == EXPAND_SUM
12403 : 0 : || modifier == EXPAND_INITIALIZER)
12404 : 0 : op0 = adjust_address_nv (op0, mode, bytepos);
12405 : : else
12406 : 0 : op0 = adjust_address (op0, mode, bytepos);
12407 : :
12408 : 0 : if (op0 == orig_op0)
12409 : 0 : op0 = copy_rtx (op0);
12410 : :
12411 : 0 : set_mem_attributes (op0, treeop0, 0);
12412 : 0 : if (REG_P (XEXP (op0, 0)))
12413 : 0 : mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
12414 : :
12415 : 0 : MEM_VOLATILE_P (op0) |= volatilep;
12416 : : }
12417 : : }
12418 : : }
12419 : :
12420 : 0 : if (!op0)
12421 : 325055 : op0 = expand_expr_real (treeop0, NULL_RTX, VOIDmode, modifier,
12422 : : NULL, inner_reference_p);
12423 : :
12424 : : /* If the input and output modes are both the same, we are done. */
12425 : 325055 : if (mode == GET_MODE (op0))
12426 : : ;
12427 : : /* Similarly if the output mode is BLKmode and input is a MEM,
12428 : : adjust_address done below is all we need. */
12429 : 147526 : else if (mode == BLKmode && MEM_P (op0))
12430 : : ;
12431 : : /* If neither mode is BLKmode, and both modes are the same size
12432 : : then we can use gen_lowpart. */
12433 : 147495 : else if (mode != BLKmode
12434 : 147495 : && GET_MODE (op0) != BLKmode
12435 : 145924 : && known_eq (GET_MODE_PRECISION (mode),
12436 : : GET_MODE_PRECISION (GET_MODE (op0)))
12437 : 142028 : && !COMPLEX_MODE_P (GET_MODE (op0)))
12438 : : {
12439 : 140638 : if (GET_CODE (op0) == SUBREG)
12440 : 134 : op0 = force_reg (GET_MODE (op0), op0);
12441 : 140638 : temp = gen_lowpart_common (mode, op0);
12442 : 140638 : if (temp)
12443 : : op0 = temp;
12444 : : else
12445 : : {
12446 : 27197 : if (!REG_P (op0) && !MEM_P (op0))
12447 : 21 : op0 = force_reg (GET_MODE (op0), op0);
12448 : 27197 : op0 = gen_lowpart (mode, op0);
12449 : : }
12450 : : }
12451 : : /* If both types are integral, convert from one mode to the other. */
12452 : 6888 : else if (INTEGRAL_TYPE_P (type)
12453 : 3139 : && INTEGRAL_TYPE_P (TREE_TYPE (treeop0))
12454 : 0 : && mode != BLKmode
12455 : 6888 : && GET_MODE (op0) != BLKmode)
12456 : 0 : op0 = convert_modes (mode, GET_MODE (op0), op0,
12457 : 0 : TYPE_UNSIGNED (TREE_TYPE (treeop0)));
12458 : : /* If the output type is a bit-field type, do an extraction. */
12459 : 6888 : else if (reduce_bit_field)
12460 : 0 : return extract_bit_field (op0, TYPE_PRECISION (type), 0,
12461 : 0 : TYPE_UNSIGNED (type), NULL_RTX,
12462 : : mode, mode, false, NULL);
12463 : : /* As a last resort, spill op0 to memory, and reload it in a
12464 : : different mode. */
12465 : 6888 : else if (!MEM_P (op0))
12466 : : {
12467 : : /* If the operand is not a MEM, force it into memory. Since we
12468 : : are going to be changing the mode of the MEM, don't call
12469 : : force_const_mem for constants because we don't allow pool
12470 : : constants to change mode. */
12471 : 5317 : tree inner_type = TREE_TYPE (treeop0);
12472 : :
12473 : 5317 : gcc_assert (!TREE_ADDRESSABLE (exp));
12474 : :
12475 : 5317 : if (target == 0 || GET_MODE (target) != TYPE_MODE (inner_type))
12476 : 5311 : target
12477 : : = assign_stack_temp_for_type
12478 : 5311 : (TYPE_MODE (inner_type),
12479 : 15933 : GET_MODE_SIZE (TYPE_MODE (inner_type)), inner_type);
12480 : :
12481 : 5317 : emit_move_insn (target, op0);
12482 : 5317 : op0 = target;
12483 : : }
12484 : :
12485 : : /* If OP0 is (now) a MEM, we need to deal with alignment issues. If the
12486 : : output type is such that the operand is known to be aligned, indicate
12487 : : that it is. Otherwise, we need only be concerned about alignment for
12488 : : non-BLKmode results. */
12489 : 325055 : if (MEM_P (op0))
12490 : : {
12491 : 124947 : enum insn_code icode;
12492 : :
12493 : 124947 : if (modifier != EXPAND_WRITE
12494 : 124947 : && modifier != EXPAND_MEMORY
12495 : 124947 : && !inner_reference_p
12496 : 124947 : && mode != BLKmode
12497 : 176443 : && MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode))
12498 : : {
12499 : : /* If the target does have special handling for unaligned
12500 : : loads of mode then use them. */
12501 : 15196 : if ((icode = optab_handler (movmisalign_optab, mode))
12502 : : != CODE_FOR_nothing)
12503 : : {
12504 : 2806 : rtx reg;
12505 : :
12506 : 2806 : op0 = adjust_address (op0, mode, 0);
12507 : : /* We've already validated the memory, and we're creating a
12508 : : new pseudo destination. The predicates really can't
12509 : : fail. */
12510 : 2806 : reg = gen_reg_rtx (mode);
12511 : :
12512 : : /* Nor can the insn generator. */
12513 : 2806 : rtx_insn *insn = GEN_FCN (icode) (reg, op0);
12514 : 2806 : emit_insn (insn);
12515 : 2806 : return reg;
12516 : : }
12517 : : else if (STRICT_ALIGNMENT)
12518 : : {
12519 : : poly_uint64 mode_size = GET_MODE_SIZE (mode);
12520 : : poly_uint64 temp_size = mode_size;
12521 : : if (GET_MODE (op0) != BLKmode)
12522 : : temp_size = upper_bound (temp_size,
12523 : : GET_MODE_SIZE (GET_MODE (op0)));
12524 : : rtx new_rtx
12525 : : = assign_stack_temp_for_type (mode, temp_size, type);
12526 : : rtx new_with_op0_mode
12527 : : = adjust_address (new_rtx, GET_MODE (op0), 0);
12528 : :
12529 : : gcc_assert (!TREE_ADDRESSABLE (exp));
12530 : :
12531 : : if (GET_MODE (op0) == BLKmode)
12532 : : {
12533 : : rtx size_rtx = gen_int_mode (mode_size, Pmode);
12534 : : emit_block_move (new_with_op0_mode, op0, size_rtx,
12535 : : (modifier == EXPAND_STACK_PARM
12536 : : ? BLOCK_OP_CALL_PARM
12537 : : : BLOCK_OP_NORMAL));
12538 : : }
12539 : : else
12540 : : emit_move_insn (new_with_op0_mode, op0);
12541 : :
12542 : : op0 = new_rtx;
12543 : : }
12544 : : }
12545 : :
12546 : 122141 : op0 = adjust_address (op0, mode, 0);
12547 : : }
12548 : :
12549 : : return op0;
12550 : :
12551 : 62023 : case MODIFY_EXPR:
12552 : 62023 : {
12553 : 62023 : tree lhs = treeop0;
12554 : 62023 : tree rhs = treeop1;
12555 : 62023 : gcc_assert (ignore);
12556 : :
12557 : : /* Check for |= or &= of a bitfield of size one into another bitfield
12558 : : of size 1. In this case, (unless we need the result of the
12559 : : assignment) we can do this more efficiently with a
12560 : : test followed by an assignment, if necessary.
12561 : :
12562 : : ??? At this point, we can't get a BIT_FIELD_REF here. But if
12563 : : things change so we do, this code should be enhanced to
12564 : : support it. */
12565 : 62023 : if (TREE_CODE (lhs) == COMPONENT_REF
12566 : 59278 : && (TREE_CODE (rhs) == BIT_IOR_EXPR
12567 : 59278 : || TREE_CODE (rhs) == BIT_AND_EXPR)
12568 : 0 : && TREE_OPERAND (rhs, 0) == lhs
12569 : 0 : && TREE_CODE (TREE_OPERAND (rhs, 1)) == COMPONENT_REF
12570 : 0 : && integer_onep (DECL_SIZE (TREE_OPERAND (lhs, 1)))
12571 : 62023 : && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs, 1), 1))))
12572 : : {
12573 : 0 : rtx_code_label *label = gen_label_rtx ();
12574 : 0 : int value = TREE_CODE (rhs) == BIT_IOR_EXPR;
12575 : 0 : profile_probability prob = profile_probability::uninitialized ();
12576 : 0 : if (value)
12577 : 0 : jumpifnot (TREE_OPERAND (rhs, 1), label, prob);
12578 : : else
12579 : 0 : jumpif (TREE_OPERAND (rhs, 1), label, prob);
12580 : 0 : expand_assignment (lhs, build_int_cst (TREE_TYPE (rhs), value),
12581 : : false);
12582 : 0 : do_pending_stack_adjust ();
12583 : 0 : emit_label (label);
12584 : 0 : return const0_rtx;
12585 : : }
12586 : :
12587 : 62023 : expand_assignment (lhs, rhs, false);
12588 : 62023 : return const0_rtx;
12589 : : }
12590 : :
12591 : 12278628 : case ADDR_EXPR:
12592 : 12278628 : return expand_expr_addr_expr (exp, target, tmode, modifier);
12593 : :
12594 : 154058 : case REALPART_EXPR:
12595 : 154058 : op0 = expand_normal (treeop0);
12596 : 154058 : return read_complex_part (op0, false);
12597 : :
12598 : 177838 : case IMAGPART_EXPR:
12599 : 177838 : op0 = expand_normal (treeop0);
12600 : 177838 : return read_complex_part (op0, true);
12601 : :
12602 : 0 : case RETURN_EXPR:
12603 : 0 : case LABEL_EXPR:
12604 : 0 : case GOTO_EXPR:
12605 : 0 : case SWITCH_EXPR:
12606 : 0 : case ASM_EXPR:
12607 : : /* Expanded in cfgexpand.cc. */
12608 : 0 : gcc_unreachable ();
12609 : :
12610 : 0 : case TRY_CATCH_EXPR:
12611 : 0 : case CATCH_EXPR:
12612 : 0 : case EH_FILTER_EXPR:
12613 : 0 : case TRY_FINALLY_EXPR:
12614 : 0 : case EH_ELSE_EXPR:
12615 : : /* Lowered by tree-eh.cc. */
12616 : 0 : gcc_unreachable ();
12617 : :
12618 : 0 : case WITH_CLEANUP_EXPR:
12619 : 0 : case CLEANUP_POINT_EXPR:
12620 : 0 : case TARGET_EXPR:
12621 : 0 : case CASE_LABEL_EXPR:
12622 : 0 : case VA_ARG_EXPR:
12623 : 0 : case BIND_EXPR:
12624 : 0 : case INIT_EXPR:
12625 : 0 : case CONJ_EXPR:
12626 : 0 : case COMPOUND_EXPR:
12627 : 0 : case PREINCREMENT_EXPR:
12628 : 0 : case PREDECREMENT_EXPR:
12629 : 0 : case POSTINCREMENT_EXPR:
12630 : 0 : case POSTDECREMENT_EXPR:
12631 : 0 : case LOOP_EXPR:
12632 : 0 : case EXIT_EXPR:
12633 : 0 : case COMPOUND_LITERAL_EXPR:
12634 : : /* Lowered by gimplify.cc. */
12635 : 0 : gcc_unreachable ();
12636 : :
12637 : 0 : case FDESC_EXPR:
12638 : : /* Function descriptors are not valid except for as
12639 : : initialization constants, and should not be expanded. */
12640 : 0 : gcc_unreachable ();
12641 : :
12642 : 256 : case WITH_SIZE_EXPR:
12643 : : /* WITH_SIZE_EXPR expands to its first argument. The caller should
12644 : : have pulled out the size to use in whatever context it needed. */
12645 : 256 : return expand_expr_real (treeop0, original_target, tmode,
12646 : 256 : modifier, alt_rtl, inner_reference_p);
12647 : :
12648 : 1756992 : default:
12649 : 1756992 : return expand_expr_real_2 (&ops, target, tmode, modifier);
12650 : : }
12651 : : }
12652 : : #undef EXTEND_BITINT
12653 : :
12654 : : /* Subroutine of above: reduce EXP to the precision of TYPE (in the
12655 : : signedness of TYPE), possibly returning the result in TARGET.
12656 : : TYPE is known to be a partial integer type. */
12657 : : static rtx
12658 : 83870 : reduce_to_bit_field_precision (rtx exp, rtx target, tree type)
12659 : : {
12660 : 83870 : scalar_int_mode mode = SCALAR_INT_TYPE_MODE (type);
12661 : 83870 : HOST_WIDE_INT prec = TYPE_PRECISION (type);
12662 : 83870 : gcc_assert ((GET_MODE (exp) == VOIDmode || GET_MODE (exp) == mode)
12663 : : && (!target || GET_MODE (target) == mode));
12664 : :
12665 : : /* For constant values, reduce using wide_int_to_tree. */
12666 : 83870 : if (poly_int_rtx_p (exp))
12667 : : {
12668 : 2 : auto value = wi::to_poly_wide (exp, mode);
12669 : 2 : tree t = wide_int_to_tree (type, value);
12670 : 2 : return expand_expr (t, target, VOIDmode, EXPAND_NORMAL);
12671 : : }
12672 : 83868 : else if (TYPE_UNSIGNED (type))
12673 : : {
12674 : 65910 : rtx mask = immed_wide_int_const
12675 : 65910 : (wi::mask (prec, false, GET_MODE_PRECISION (mode)), mode);
12676 : 65910 : return expand_and (mode, exp, mask, target);
12677 : : }
12678 : : else
12679 : : {
12680 : 17958 : int count = GET_MODE_PRECISION (mode) - prec;
12681 : 17958 : exp = expand_shift (LSHIFT_EXPR, mode, exp, count, target, 0);
12682 : 17958 : return expand_shift (RSHIFT_EXPR, mode, exp, count, target, 0);
12683 : : }
12684 : : }
12685 : :
12686 : : /* Subroutine of above: returns true if OFFSET corresponds to an offset that
12687 : : when applied to the address of EXP produces an address known to be
12688 : : aligned more than BIGGEST_ALIGNMENT. */
12689 : :
12690 : : static bool
12691 : 248582 : is_aligning_offset (const_tree offset, const_tree exp)
12692 : : {
12693 : : /* Strip off any conversions. */
12694 : 265450 : while (CONVERT_EXPR_P (offset))
12695 : 16868 : offset = TREE_OPERAND (offset, 0);
12696 : :
12697 : : /* We must now have a BIT_AND_EXPR with a constant that is one less than
12698 : : power of 2 and which is larger than BIGGEST_ALIGNMENT. */
12699 : 248582 : if (TREE_CODE (offset) != BIT_AND_EXPR
12700 : 0 : || !tree_fits_uhwi_p (TREE_OPERAND (offset, 1))
12701 : 0 : || compare_tree_int (TREE_OPERAND (offset, 1),
12702 : 0 : BIGGEST_ALIGNMENT / BITS_PER_UNIT) <= 0
12703 : 248582 : || !pow2p_hwi (tree_to_uhwi (TREE_OPERAND (offset, 1)) + 1))
12704 : 248582 : return false;
12705 : :
12706 : : /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
12707 : : It must be NEGATE_EXPR. Then strip any more conversions. */
12708 : 0 : offset = TREE_OPERAND (offset, 0);
12709 : 0 : while (CONVERT_EXPR_P (offset))
12710 : 0 : offset = TREE_OPERAND (offset, 0);
12711 : :
12712 : 0 : if (TREE_CODE (offset) != NEGATE_EXPR)
12713 : : return false;
12714 : :
12715 : 0 : offset = TREE_OPERAND (offset, 0);
12716 : 0 : while (CONVERT_EXPR_P (offset))
12717 : 0 : offset = TREE_OPERAND (offset, 0);
12718 : :
12719 : : /* This must now be the address of EXP. */
12720 : 0 : return TREE_CODE (offset) == ADDR_EXPR && TREE_OPERAND (offset, 0) == exp;
12721 : : }
12722 : :
12723 : : /* Return a STRING_CST corresponding to ARG's constant initializer either
12724 : : if it's a string constant, or, when VALREP is set, any other constant,
12725 : : or null otherwise.
12726 : : On success, set *PTR_OFFSET to the (possibly non-constant) byte offset
12727 : : within the byte string that ARG is references. If nonnull set *MEM_SIZE
12728 : : to the size of the byte string. If nonnull, set *DECL to the constant
12729 : : declaration ARG refers to. */
12730 : :
12731 : : static tree
12732 : 15340289 : constant_byte_string (tree arg, tree *ptr_offset, tree *mem_size, tree *decl,
12733 : : bool valrep = false)
12734 : : {
12735 : 15340289 : tree dummy = NULL_TREE;
12736 : 15340289 : if (!mem_size)
12737 : 10481 : mem_size = &dummy;
12738 : :
12739 : : /* Store the type of the original expression before conversions
12740 : : via NOP_EXPR or POINTER_PLUS_EXPR to other types have been
12741 : : removed. */
12742 : 15340289 : tree argtype = TREE_TYPE (arg);
12743 : :
12744 : 15340289 : tree array;
12745 : 15340289 : STRIP_NOPS (arg);
12746 : :
12747 : : /* Non-constant index into the character array in an ARRAY_REF
12748 : : expression or null. */
12749 : 15340289 : tree varidx = NULL_TREE;
12750 : :
12751 : 15340289 : poly_int64 base_off = 0;
12752 : :
12753 : 15340289 : if (TREE_CODE (arg) == ADDR_EXPR)
12754 : : {
12755 : 6391171 : arg = TREE_OPERAND (arg, 0);
12756 : 6391171 : tree ref = arg;
12757 : 6391171 : if (TREE_CODE (arg) == ARRAY_REF)
12758 : : {
12759 : 540100 : tree idx = TREE_OPERAND (arg, 1);
12760 : 540100 : if (TREE_CODE (idx) != INTEGER_CST)
12761 : : {
12762 : : /* From a pointer (but not array) argument extract the variable
12763 : : index to prevent get_addr_base_and_unit_offset() from failing
12764 : : due to it. Use it later to compute the non-constant offset
12765 : : into the string and return it to the caller. */
12766 : 162885 : varidx = idx;
12767 : 162885 : ref = TREE_OPERAND (arg, 0);
12768 : :
12769 : 162885 : if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE)
12770 : : return NULL_TREE;
12771 : :
12772 : 27831 : if (!integer_zerop (array_ref_low_bound (arg)))
12773 : : return NULL_TREE;
12774 : :
12775 : 27091 : if (!integer_onep (array_ref_element_size (arg)))
12776 : : return NULL_TREE;
12777 : : }
12778 : : }
12779 : 6254402 : array = get_addr_base_and_unit_offset (ref, &base_off);
12780 : 6254402 : if (!array
12781 : 6207306 : || (TREE_CODE (array) != VAR_DECL
12782 : 6207306 : && TREE_CODE (array) != CONST_DECL
12783 : 3804847 : && TREE_CODE (array) != STRING_CST))
12784 : : return NULL_TREE;
12785 : : }
12786 : 8949118 : else if (TREE_CODE (arg) == PLUS_EXPR || TREE_CODE (arg) == POINTER_PLUS_EXPR)
12787 : : {
12788 : 26586 : tree arg0 = TREE_OPERAND (arg, 0);
12789 : 26586 : tree arg1 = TREE_OPERAND (arg, 1);
12790 : :
12791 : 26586 : tree offset;
12792 : 26586 : tree str = string_constant (arg0, &offset, mem_size, decl);
12793 : 26586 : if (!str)
12794 : : {
12795 : 16766 : str = string_constant (arg1, &offset, mem_size, decl);
12796 : 16766 : arg1 = arg0;
12797 : : }
12798 : :
12799 : 16766 : if (str)
12800 : : {
12801 : : /* Avoid pointers to arrays (see bug 86622). */
12802 : 9820 : if (POINTER_TYPE_P (TREE_TYPE (arg))
12803 : 9820 : && TREE_CODE (TREE_TYPE (TREE_TYPE (arg))) == ARRAY_TYPE
12804 : 2100 : && !(decl && !*decl)
12805 : 12620 : && !(decl && tree_fits_uhwi_p (DECL_SIZE_UNIT (*decl))
12806 : 1400 : && tree_fits_uhwi_p (*mem_size)
12807 : 1400 : && tree_int_cst_equal (*mem_size, DECL_SIZE_UNIT (*decl))))
12808 : 2100 : return NULL_TREE;
12809 : :
12810 : 7720 : tree type = TREE_TYPE (offset);
12811 : 7720 : arg1 = fold_convert (type, arg1);
12812 : 7720 : *ptr_offset = fold_build2 (PLUS_EXPR, type, offset, arg1);
12813 : 7720 : return str;
12814 : : }
12815 : : return NULL_TREE;
12816 : : }
12817 : 8922532 : else if (TREE_CODE (arg) == SSA_NAME)
12818 : : {
12819 : 3957323 : gimple *stmt = SSA_NAME_DEF_STMT (arg);
12820 : 3957323 : if (!is_gimple_assign (stmt))
12821 : : return NULL_TREE;
12822 : :
12823 : 966729 : tree rhs1 = gimple_assign_rhs1 (stmt);
12824 : 966729 : tree_code code = gimple_assign_rhs_code (stmt);
12825 : 966729 : if (code == ADDR_EXPR)
12826 : 218608 : return string_constant (rhs1, ptr_offset, mem_size, decl);
12827 : 748121 : else if (code != POINTER_PLUS_EXPR)
12828 : : return NULL_TREE;
12829 : :
12830 : 186302 : tree offset;
12831 : 186302 : if (tree str = string_constant (rhs1, &offset, mem_size, decl))
12832 : : {
12833 : : /* Avoid pointers to arrays (see bug 86622). */
12834 : 22119 : if (POINTER_TYPE_P (TREE_TYPE (rhs1))
12835 : 22119 : && TREE_CODE (TREE_TYPE (TREE_TYPE (rhs1))) == ARRAY_TYPE
12836 : 19333 : && !(decl && !*decl)
12837 : 39735 : && !(decl && tree_fits_uhwi_p (DECL_SIZE_UNIT (*decl))
12838 : 8808 : && tree_fits_uhwi_p (*mem_size)
12839 : 8808 : && tree_int_cst_equal (*mem_size, DECL_SIZE_UNIT (*decl))))
12840 : 15068 : return NULL_TREE;
12841 : :
12842 : 7051 : tree rhs2 = gimple_assign_rhs2 (stmt);
12843 : 7051 : tree type = TREE_TYPE (offset);
12844 : 7051 : rhs2 = fold_convert (type, rhs2);
12845 : 7051 : *ptr_offset = fold_build2 (PLUS_EXPR, type, offset, rhs2);
12846 : 7051 : return str;
12847 : : }
12848 : : return NULL_TREE;
12849 : : }
12850 : 4965209 : else if (DECL_P (arg))
12851 : : array = arg;
12852 : : else
12853 : : return NULL_TREE;
12854 : :
12855 : 8533106 : tree offset = wide_int_to_tree (sizetype, base_off);
12856 : 8533106 : if (varidx)
12857 : : {
12858 : 2131 : if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE)
12859 : : return NULL_TREE;
12860 : :
12861 : 1620 : gcc_assert (TREE_CODE (arg) == ARRAY_REF);
12862 : 1620 : tree chartype = TREE_TYPE (TREE_TYPE (TREE_OPERAND (arg, 0)));
12863 : 1620 : if (TREE_CODE (chartype) != INTEGER_TYPE)
12864 : : return NULL;
12865 : :
12866 : 1463 : offset = fold_convert (sizetype, varidx);
12867 : : }
12868 : :
12869 : 8532438 : if (TREE_CODE (array) == STRING_CST)
12870 : : {
12871 : 3416266 : *ptr_offset = fold_convert (sizetype, offset);
12872 : 3416266 : *mem_size = TYPE_SIZE_UNIT (TREE_TYPE (array));
12873 : 3416266 : if (decl)
12874 : 789630 : *decl = NULL_TREE;
12875 : 3416266 : gcc_checking_assert (tree_to_shwi (TYPE_SIZE_UNIT (TREE_TYPE (array)))
12876 : : >= TREE_STRING_LENGTH (array));
12877 : : return array;
12878 : : }
12879 : :
12880 : 5116172 : tree init = ctor_for_folding (array);
12881 : 5116172 : if (!init || init == error_mark_node)
12882 : : return NULL_TREE;
12883 : :
12884 : 155188 : if (valrep)
12885 : : {
12886 : 57875 : HOST_WIDE_INT cstoff;
12887 : 57875 : if (!base_off.is_constant (&cstoff))
12888 : : return NULL_TREE;
12889 : :
12890 : : /* Check that the host and target are sane. */
12891 : 57875 : if (CHAR_BIT != 8 || BITS_PER_UNIT != 8)
12892 : : return NULL_TREE;
12893 : :
12894 : 57875 : HOST_WIDE_INT typesz = int_size_in_bytes (TREE_TYPE (init));
12895 : 57875 : if (typesz <= 0 || (int) typesz != typesz)
12896 : : return NULL_TREE;
12897 : :
12898 : 57705 : HOST_WIDE_INT size = typesz;
12899 : 57705 : if (VAR_P (array)
12900 : 57703 : && DECL_SIZE_UNIT (array)
12901 : 115408 : && tree_fits_shwi_p (DECL_SIZE_UNIT (array)))
12902 : : {
12903 : 57703 : size = tree_to_shwi (DECL_SIZE_UNIT (array));
12904 : 57703 : gcc_checking_assert (size >= typesz);
12905 : : }
12906 : :
12907 : : /* If value representation was requested convert the initializer
12908 : : for the whole array or object into a string of bytes forming
12909 : : its value representation and return it. */
12910 : 57705 : unsigned char *bytes = XNEWVEC (unsigned char, size);
12911 : 57705 : int r = native_encode_initializer (init, bytes, size);
12912 : 57705 : if (r < typesz)
12913 : : {
12914 : 59 : XDELETEVEC (bytes);
12915 : 59 : return NULL_TREE;
12916 : : }
12917 : :
12918 : 57646 : if (r < size)
12919 : 0 : memset (bytes + r, '\0', size - r);
12920 : :
12921 : 57646 : const char *p = reinterpret_cast<const char *>(bytes);
12922 : 57646 : init = build_string_literal (size, p, char_type_node);
12923 : 57646 : init = TREE_OPERAND (init, 0);
12924 : 57646 : init = TREE_OPERAND (init, 0);
12925 : 57646 : XDELETE (bytes);
12926 : :
12927 : 57646 : *mem_size = size_int (TREE_STRING_LENGTH (init));
12928 : 57646 : *ptr_offset = wide_int_to_tree (ssizetype, base_off);
12929 : :
12930 : 57646 : if (decl)
12931 : 0 : *decl = array;
12932 : :
12933 : 57646 : return init;
12934 : : }
12935 : :
12936 : 97313 : if (TREE_CODE (init) == CONSTRUCTOR)
12937 : : {
12938 : : /* Convert the 64-bit constant offset to a wider type to avoid
12939 : : overflow and use it to obtain the initializer for the subobject
12940 : : it points into. */
12941 : 79146 : offset_int wioff;
12942 : 79146 : if (!base_off.is_constant (&wioff))
12943 : 178 : return NULL_TREE;
12944 : :
12945 : 79146 : wioff *= BITS_PER_UNIT;
12946 : 79146 : if (!wi::fits_uhwi_p (wioff))
12947 : : return NULL_TREE;
12948 : :
12949 : 79011 : base_off = wioff.to_uhwi ();
12950 : 79011 : unsigned HOST_WIDE_INT fieldoff = 0;
12951 : 79011 : init = fold_ctor_reference (TREE_TYPE (arg), init, base_off, 0, array,
12952 : : &fieldoff);
12953 : 79011 : if (!init || init == error_mark_node)
12954 : : return NULL_TREE;
12955 : :
12956 : 78968 : HOST_WIDE_INT cstoff;
12957 : 78968 : if (!base_off.is_constant (&cstoff))
12958 : : return NULL_TREE;
12959 : :
12960 : 78968 : cstoff = (cstoff - fieldoff) / BITS_PER_UNIT;
12961 : 78968 : tree off = build_int_cst (sizetype, cstoff);
12962 : 78968 : if (varidx)
12963 : 944 : offset = fold_build2 (PLUS_EXPR, TREE_TYPE (offset), offset, off);
12964 : : else
12965 : : offset = off;
12966 : : }
12967 : :
12968 : 97135 : *ptr_offset = offset;
12969 : :
12970 : 97135 : tree inittype = TREE_TYPE (init);
12971 : :
12972 : 97135 : if (TREE_CODE (init) == INTEGER_CST
12973 : 97135 : && (TREE_CODE (TREE_TYPE (array)) == INTEGER_TYPE
12974 : 1348 : || TYPE_MAIN_VARIANT (inittype) == char_type_node))
12975 : : {
12976 : : /* Check that the host and target are sane. */
12977 : 959 : if (CHAR_BIT != 8 || BITS_PER_UNIT != 8)
12978 : : return NULL_TREE;
12979 : :
12980 : : /* For a reference to (address of) a single constant character,
12981 : : store the native representation of the character in CHARBUF.
12982 : : If the reference is to an element of an array or a member
12983 : : of a struct, only consider narrow characters until ctors
12984 : : for wide character arrays are transformed to STRING_CSTs
12985 : : like those for narrow arrays. */
12986 : 959 : unsigned char charbuf[MAX_BITSIZE_MODE_ANY_MODE / BITS_PER_UNIT];
12987 : 959 : int len = native_encode_expr (init, charbuf, sizeof charbuf, 0);
12988 : 959 : if (len > 0)
12989 : : {
12990 : : /* Construct a string literal with elements of INITTYPE and
12991 : : the representation above. Then strip
12992 : : the ADDR_EXPR (ARRAY_REF (...)) around the STRING_CST. */
12993 : 959 : init = build_string_literal (len, (char *)charbuf, inittype);
12994 : 959 : init = TREE_OPERAND (TREE_OPERAND (init, 0), 0);
12995 : : }
12996 : : }
12997 : :
12998 : 97135 : tree initsize = TYPE_SIZE_UNIT (inittype);
12999 : :
13000 : 97135 : if (TREE_CODE (init) == CONSTRUCTOR && initializer_zerop (init))
13001 : : {
13002 : : /* Fold an empty/zero constructor for an implicitly initialized
13003 : : object or subobject into the empty string. */
13004 : :
13005 : : /* Determine the character type from that of the original
13006 : : expression. */
13007 : 11698 : tree chartype = argtype;
13008 : 11698 : if (POINTER_TYPE_P (chartype))
13009 : 11691 : chartype = TREE_TYPE (chartype);
13010 : 18516 : while (TREE_CODE (chartype) == ARRAY_TYPE)
13011 : 6818 : chartype = TREE_TYPE (chartype);
13012 : :
13013 : 11698 : if (INTEGRAL_TYPE_P (chartype)
13014 : 11698 : && TYPE_PRECISION (chartype) == TYPE_PRECISION (char_type_node))
13015 : : {
13016 : : /* Convert a char array to an empty STRING_CST having an array
13017 : : of the expected type and size. */
13018 : 11614 : if (!initsize)
13019 : 3957 : initsize = integer_zero_node;
13020 : :
13021 : 11614 : unsigned HOST_WIDE_INT size = tree_to_uhwi (initsize);
13022 : 11614 : if (size > (unsigned HOST_WIDE_INT) INT_MAX)
13023 : : return NULL_TREE;
13024 : :
13025 : 11614 : init = build_string_literal (size, NULL, chartype, size);
13026 : 11614 : init = TREE_OPERAND (init, 0);
13027 : 11614 : init = TREE_OPERAND (init, 0);
13028 : :
13029 : 11614 : *ptr_offset = integer_zero_node;
13030 : : }
13031 : : }
13032 : :
13033 : 97135 : if (decl)
13034 : 56428 : *decl = array;
13035 : :
13036 : 97135 : if (TREE_CODE (init) != STRING_CST)
13037 : : return NULL_TREE;
13038 : :
13039 : 69777 : *mem_size = initsize;
13040 : :
13041 : 69777 : gcc_checking_assert (tree_to_shwi (initsize) >= TREE_STRING_LENGTH (init));
13042 : :
13043 : : return init;
13044 : : }
13045 : :
13046 : : /* Return STRING_CST if an ARG corresponds to a string constant or zero
13047 : : if it doesn't. If we return nonzero, set *PTR_OFFSET to the (possibly
13048 : : non-constant) offset in bytes within the string that ARG is accessing.
13049 : : If MEM_SIZE is non-zero the storage size of the memory is returned.
13050 : : If DECL is non-zero the constant declaration is returned if available. */
13051 : :
13052 : : tree
13053 : 10454061 : string_constant (tree arg, tree *ptr_offset, tree *mem_size, tree *decl)
13054 : : {
13055 : 10454061 : return constant_byte_string (arg, ptr_offset, mem_size, decl, false);
13056 : : }
13057 : :
13058 : : /* Similar to string_constant, return a STRING_CST corresponding
13059 : : to the value representation of the first argument if it's
13060 : : a constant. */
13061 : :
13062 : : tree
13063 : 4886228 : byte_representation (tree arg, tree *ptr_offset, tree *mem_size, tree *decl)
13064 : : {
13065 : 4886228 : return constant_byte_string (arg, ptr_offset, mem_size, decl, true);
13066 : : }
13067 : :
13068 : : /* Optimize x % C1 == C2 for signed modulo if C1 is a power of two and C2
13069 : : is non-zero and C3 ((1<<(prec-1)) | (C1 - 1)):
13070 : : for C2 > 0 to x & C3 == C2
13071 : : for C2 < 0 to x & C3 == (C2 & C3). */
13072 : : enum tree_code
13073 : 35 : maybe_optimize_pow2p_mod_cmp (enum tree_code code, tree *arg0, tree *arg1)
13074 : : {
13075 : 35 : gimple *stmt = get_def_for_expr (*arg0, TRUNC_MOD_EXPR);
13076 : 35 : tree treeop0 = gimple_assign_rhs1 (stmt);
13077 : 35 : tree treeop1 = gimple_assign_rhs2 (stmt);
13078 : 35 : tree type = TREE_TYPE (*arg0);
13079 : 35 : scalar_int_mode mode;
13080 : 35 : if (!is_a <scalar_int_mode> (TYPE_MODE (type), &mode))
13081 : : return code;
13082 : 70 : if (GET_MODE_BITSIZE (mode) != TYPE_PRECISION (type)
13083 : 35 : || TYPE_PRECISION (type) <= 1
13084 : 35 : || TYPE_UNSIGNED (type)
13085 : : /* Signed x % c == 0 should have been optimized into unsigned modulo
13086 : : earlier. */
13087 : 35 : || integer_zerop (*arg1)
13088 : : /* If c is known to be non-negative, modulo will be expanded as unsigned
13089 : : modulo. */
13090 : 70 : || get_range_pos_neg (treeop0) == 1)
13091 : 0 : return code;
13092 : :
13093 : : /* x % c == d where d < 0 && d <= -c should be always false. */
13094 : 35 : if (tree_int_cst_sgn (*arg1) == -1
13095 : 51 : && -wi::to_widest (treeop1) >= wi::to_widest (*arg1))
13096 : : return code;
13097 : :
13098 : 35 : int prec = TYPE_PRECISION (type);
13099 : 35 : wide_int w = wi::to_wide (treeop1) - 1;
13100 : 35 : w |= wi::shifted_mask (0, prec - 1, true, prec);
13101 : 35 : tree c3 = wide_int_to_tree (type, w);
13102 : 35 : tree c4 = *arg1;
13103 : 35 : if (tree_int_cst_sgn (*arg1) == -1)
13104 : 16 : c4 = wide_int_to_tree (type, w & wi::to_wide (*arg1));
13105 : :
13106 : 35 : rtx op0 = expand_normal (treeop0);
13107 : 35 : treeop0 = make_tree (TREE_TYPE (treeop0), op0);
13108 : :
13109 : 35 : bool speed_p = optimize_insn_for_speed_p ();
13110 : :
13111 : 35 : do_pending_stack_adjust ();
13112 : :
13113 : 35 : location_t loc = gimple_location (stmt);
13114 : 35 : struct separate_ops ops;
13115 : 35 : ops.code = TRUNC_MOD_EXPR;
13116 : 35 : ops.location = loc;
13117 : 35 : ops.type = TREE_TYPE (treeop0);
13118 : 35 : ops.op0 = treeop0;
13119 : 35 : ops.op1 = treeop1;
13120 : 35 : ops.op2 = NULL_TREE;
13121 : 35 : start_sequence ();
13122 : 35 : rtx mor = expand_expr_real_2 (&ops, NULL_RTX, TYPE_MODE (ops.type),
13123 : : EXPAND_NORMAL);
13124 : 35 : rtx_insn *moinsns = get_insns ();
13125 : 35 : end_sequence ();
13126 : :
13127 : 35 : unsigned mocost = seq_cost (moinsns, speed_p);
13128 : 35 : mocost += rtx_cost (mor, mode, EQ, 0, speed_p);
13129 : 35 : mocost += rtx_cost (expand_normal (*arg1), mode, EQ, 1, speed_p);
13130 : :
13131 : 35 : ops.code = BIT_AND_EXPR;
13132 : 35 : ops.location = loc;
13133 : 35 : ops.type = TREE_TYPE (treeop0);
13134 : 35 : ops.op0 = treeop0;
13135 : 35 : ops.op1 = c3;
13136 : 35 : ops.op2 = NULL_TREE;
13137 : 35 : start_sequence ();
13138 : 35 : rtx mur = expand_expr_real_2 (&ops, NULL_RTX, TYPE_MODE (ops.type),
13139 : : EXPAND_NORMAL);
13140 : 35 : rtx_insn *muinsns = get_insns ();
13141 : 35 : end_sequence ();
13142 : :
13143 : 35 : unsigned mucost = seq_cost (muinsns, speed_p);
13144 : 35 : mucost += rtx_cost (mur, mode, EQ, 0, speed_p);
13145 : 35 : mucost += rtx_cost (expand_normal (c4), mode, EQ, 1, speed_p);
13146 : :
13147 : 35 : if (mocost <= mucost)
13148 : : {
13149 : 0 : emit_insn (moinsns);
13150 : 0 : *arg0 = make_tree (TREE_TYPE (*arg0), mor);
13151 : 0 : return code;
13152 : : }
13153 : :
13154 : 35 : emit_insn (muinsns);
13155 : 35 : *arg0 = make_tree (TREE_TYPE (*arg0), mur);
13156 : 35 : *arg1 = c4;
13157 : 35 : return code;
13158 : 35 : }
13159 : :
13160 : : /* Attempt to optimize unsigned (X % C1) == C2 (or (X % C1) != C2).
13161 : : If C1 is odd to:
13162 : : (X - C2) * C3 <= C4 (or >), where
13163 : : C3 is modular multiplicative inverse of C1 and 1<<prec and
13164 : : C4 is ((1<<prec) - 1) / C1 or ((1<<prec) - 1) / C1 - 1 (the latter
13165 : : if C2 > ((1<<prec) - 1) % C1).
13166 : : If C1 is even, S = ctz (C1) and C2 is 0, use
13167 : : ((X * C3) r>> S) <= C4, where C3 is modular multiplicative
13168 : : inverse of C1>>S and 1<<prec and C4 is (((1<<prec) - 1) / (C1>>S)) >> S.
13169 : :
13170 : : For signed (X % C1) == 0 if C1 is odd to (all operations in it
13171 : : unsigned):
13172 : : (X * C3) + C4 <= 2 * C4, where
13173 : : C3 is modular multiplicative inverse of (unsigned) C1 and 1<<prec and
13174 : : C4 is ((1<<(prec - 1) - 1) / C1).
13175 : : If C1 is even, S = ctz(C1), use
13176 : : ((X * C3) + C4) r>> S <= (C4 >> (S - 1))
13177 : : where C3 is modular multiplicative inverse of (unsigned)(C1>>S) and 1<<prec
13178 : : and C4 is ((1<<(prec - 1) - 1) / (C1>>S)) & (-1<<S).
13179 : :
13180 : : See the Hacker's Delight book, section 10-17. */
13181 : : enum tree_code
13182 : 2953214 : maybe_optimize_mod_cmp (enum tree_code code, tree *arg0, tree *arg1)
13183 : : {
13184 : 2953214 : gcc_checking_assert (code == EQ_EXPR || code == NE_EXPR);
13185 : 2953214 : gcc_checking_assert (TREE_CODE (*arg1) == INTEGER_CST);
13186 : :
13187 : 2953214 : if (optimize < 2)
13188 : : return code;
13189 : :
13190 : 2250175 : gimple *stmt = get_def_for_expr (*arg0, TRUNC_MOD_EXPR);
13191 : 2250175 : if (stmt == NULL)
13192 : : return code;
13193 : :
13194 : 2186 : tree treeop0 = gimple_assign_rhs1 (stmt);
13195 : 2186 : tree treeop1 = gimple_assign_rhs2 (stmt);
13196 : 2186 : if (TREE_CODE (treeop0) != SSA_NAME
13197 : 2108 : || TREE_CODE (treeop1) != INTEGER_CST
13198 : : /* Don't optimize the undefined behavior case x % 0;
13199 : : x % 1 should have been optimized into zero, punt if
13200 : : it makes it here for whatever reason;
13201 : : x % -c should have been optimized into x % c. */
13202 : 1791 : || compare_tree_int (treeop1, 2) <= 0
13203 : : /* Likewise x % c == d where d >= c should be always false. */
13204 : 3878 : || tree_int_cst_le (treeop1, *arg1))
13205 : 494 : return code;
13206 : :
13207 : : /* Unsigned x % pow2 is handled right already, for signed
13208 : : modulo handle it in maybe_optimize_pow2p_mod_cmp. */
13209 : 1692 : if (integer_pow2p (treeop1))
13210 : 35 : return maybe_optimize_pow2p_mod_cmp (code, arg0, arg1);
13211 : :
13212 : 1657 : tree type = TREE_TYPE (*arg0);
13213 : 1657 : scalar_int_mode mode;
13214 : 2953186 : if (!is_a <scalar_int_mode> (TYPE_MODE (type), &mode))
13215 : : return code;
13216 : 3314 : if (GET_MODE_BITSIZE (mode) != TYPE_PRECISION (type)
13217 : 1657 : || TYPE_PRECISION (type) <= 1)
13218 : : return code;
13219 : :
13220 : 1657 : signop sgn = UNSIGNED;
13221 : : /* If both operands are known to have the sign bit clear, handle
13222 : : even the signed modulo case as unsigned. treeop1 is always
13223 : : positive >= 2, checked above. */
13224 : 1657 : if (!TYPE_UNSIGNED (type) && get_range_pos_neg (treeop0) != 1)
13225 : : sgn = SIGNED;
13226 : :
13227 : 1657 : if (!TYPE_UNSIGNED (type))
13228 : : {
13229 : 1437 : if (tree_int_cst_sgn (*arg1) == -1)
13230 : : return code;
13231 : 1430 : type = unsigned_type_for (type);
13232 : 1430 : if (!type || TYPE_MODE (type) != TYPE_MODE (TREE_TYPE (*arg0)))
13233 : 0 : return code;
13234 : : }
13235 : :
13236 : 1650 : int prec = TYPE_PRECISION (type);
13237 : 1650 : wide_int w = wi::to_wide (treeop1);
13238 : 1650 : int shift = wi::ctz (w);
13239 : : /* Unsigned (X % C1) == C2 is equivalent to (X - C2) % C1 == 0 if
13240 : : C2 <= -1U % C1, because for any Z >= 0U - C2 in that case (Z % C1) != 0.
13241 : : If C1 is odd, we can handle all cases by subtracting
13242 : : C4 below. We could handle even the even C1 and C2 > -1U % C1 cases
13243 : : e.g. by testing for overflow on the subtraction, punt on that for now
13244 : : though. */
13245 : 1650 : if ((sgn == SIGNED || shift) && !integer_zerop (*arg1))
13246 : : {
13247 : 178 : if (sgn == SIGNED)
13248 : 163 : return code;
13249 : 26 : wide_int x = wi::umod_trunc (wi::mask (prec, false, prec), w);
13250 : 26 : if (wi::gtu_p (wi::to_wide (*arg1), x))
13251 : 11 : return code;
13252 : 26 : }
13253 : :
13254 : 1487 : imm_use_iterator imm_iter;
13255 : 1487 : use_operand_p use_p;
13256 : 10588 : FOR_EACH_IMM_USE_FAST (use_p, imm_iter, treeop0)
13257 : : {
13258 : 9102 : gimple *use_stmt = USE_STMT (use_p);
13259 : : /* Punt if treeop0 is used in the same bb in a division
13260 : : or another modulo with the same divisor. We should expect
13261 : : the division and modulo combined together. */
13262 : 17871 : if (use_stmt == stmt
13263 : 9102 : || gimple_bb (use_stmt) != gimple_bb (stmt))
13264 : 8769 : continue;
13265 : 333 : if (!is_gimple_assign (use_stmt)
13266 : 333 : || (gimple_assign_rhs_code (use_stmt) != TRUNC_DIV_EXPR
13267 : 326 : && gimple_assign_rhs_code (use_stmt) != TRUNC_MOD_EXPR))
13268 : 318 : continue;
13269 : 15 : if (gimple_assign_rhs1 (use_stmt) != treeop0
13270 : 15 : || !operand_equal_p (gimple_assign_rhs2 (use_stmt), treeop1, 0))
13271 : 14 : continue;
13272 : : return code;
13273 : : }
13274 : :
13275 : 1486 : w = wi::lrshift (w, shift);
13276 : 1486 : wide_int a = wide_int::from (w, prec + 1, UNSIGNED);
13277 : 1486 : wide_int b = wi::shifted_mask (prec, 1, false, prec + 1);
13278 : 1486 : wide_int m = wide_int::from (wi::mod_inv (a, b), prec, UNSIGNED);
13279 : 1486 : tree c3 = wide_int_to_tree (type, m);
13280 : 1486 : tree c5 = NULL_TREE;
13281 : 1486 : wide_int d, e;
13282 : 1486 : if (sgn == UNSIGNED)
13283 : : {
13284 : 755 : d = wi::divmod_trunc (wi::mask (prec, false, prec), w, UNSIGNED, &e);
13285 : : /* Use <= floor ((1<<prec) - 1) / C1 only if C2 <= ((1<<prec) - 1) % C1,
13286 : : otherwise use < or subtract one from C4. E.g. for
13287 : : x % 3U == 0 we transform this into x * 0xaaaaaaab <= 0x55555555, but
13288 : : x % 3U == 1 already needs to be
13289 : : (x - 1) * 0xaaaaaaabU <= 0x55555554. */
13290 : 755 : if (!shift && wi::gtu_p (wi::to_wide (*arg1), e))
13291 : 18 : d -= 1;
13292 : 755 : if (shift)
13293 : 277 : d = wi::lrshift (d, shift);
13294 : : }
13295 : : else
13296 : : {
13297 : 731 : e = wi::udiv_trunc (wi::mask (prec - 1, false, prec), w);
13298 : 731 : if (!shift)
13299 : 373 : d = wi::lshift (e, 1);
13300 : : else
13301 : : {
13302 : 358 : e = wi::bit_and (e, wi::mask (shift, true, prec));
13303 : 358 : d = wi::lrshift (e, shift - 1);
13304 : : }
13305 : 731 : c5 = wide_int_to_tree (type, e);
13306 : : }
13307 : 1486 : tree c4 = wide_int_to_tree (type, d);
13308 : :
13309 : 1486 : rtx op0 = expand_normal (treeop0);
13310 : 1486 : treeop0 = make_tree (TREE_TYPE (treeop0), op0);
13311 : :
13312 : 1486 : bool speed_p = optimize_insn_for_speed_p ();
13313 : :
13314 : 1486 : do_pending_stack_adjust ();
13315 : :
13316 : 1486 : location_t loc = gimple_location (stmt);
13317 : 1486 : struct separate_ops ops;
13318 : 1486 : ops.code = TRUNC_MOD_EXPR;
13319 : 1486 : ops.location = loc;
13320 : 1486 : ops.type = TREE_TYPE (treeop0);
13321 : 1486 : ops.op0 = treeop0;
13322 : 1486 : ops.op1 = treeop1;
13323 : 1486 : ops.op2 = NULL_TREE;
13324 : 1486 : start_sequence ();
13325 : 1486 : rtx mor = expand_expr_real_2 (&ops, NULL_RTX, TYPE_MODE (ops.type),
13326 : : EXPAND_NORMAL);
13327 : 1486 : rtx_insn *moinsns = get_insns ();
13328 : 1486 : end_sequence ();
13329 : :
13330 : 1486 : unsigned mocost = seq_cost (moinsns, speed_p);
13331 : 1486 : mocost += rtx_cost (mor, mode, EQ, 0, speed_p);
13332 : 1486 : mocost += rtx_cost (expand_normal (*arg1), mode, EQ, 1, speed_p);
13333 : :
13334 : 1486 : tree t = fold_convert_loc (loc, type, treeop0);
13335 : 1486 : if (!integer_zerop (*arg1))
13336 : 47 : t = fold_build2_loc (loc, MINUS_EXPR, type, t, fold_convert (type, *arg1));
13337 : 1486 : t = fold_build2_loc (loc, MULT_EXPR, type, t, c3);
13338 : 1486 : if (sgn == SIGNED)
13339 : 731 : t = fold_build2_loc (loc, PLUS_EXPR, type, t, c5);
13340 : 1486 : if (shift)
13341 : : {
13342 : 635 : tree s = build_int_cst (NULL_TREE, shift);
13343 : 635 : t = fold_build2_loc (loc, RROTATE_EXPR, type, t, s);
13344 : : }
13345 : :
13346 : 1486 : start_sequence ();
13347 : 1486 : rtx mur = expand_normal (t);
13348 : 1486 : rtx_insn *muinsns = get_insns ();
13349 : 1486 : end_sequence ();
13350 : :
13351 : 1486 : unsigned mucost = seq_cost (muinsns, speed_p);
13352 : 1486 : mucost += rtx_cost (mur, mode, LE, 0, speed_p);
13353 : 1486 : mucost += rtx_cost (expand_normal (c4), mode, LE, 1, speed_p);
13354 : :
13355 : 1486 : if (mocost <= mucost)
13356 : : {
13357 : 295 : emit_insn (moinsns);
13358 : 295 : *arg0 = make_tree (TREE_TYPE (*arg0), mor);
13359 : 295 : return code;
13360 : : }
13361 : :
13362 : 1191 : emit_insn (muinsns);
13363 : 1191 : *arg0 = make_tree (type, mur);
13364 : 1191 : *arg1 = c4;
13365 : 1191 : return code == EQ_EXPR ? LE_EXPR : GT_EXPR;
13366 : 3136 : }
13367 : :
13368 : : /* Optimize x - y < 0 into x < 0 if x - y has undefined overflow. */
13369 : :
13370 : : void
13371 : 227733 : maybe_optimize_sub_cmp_0 (enum tree_code code, tree *arg0, tree *arg1)
13372 : : {
13373 : 227733 : gcc_checking_assert (code == GT_EXPR || code == GE_EXPR
13374 : : || code == LT_EXPR || code == LE_EXPR);
13375 : 227733 : gcc_checking_assert (integer_zerop (*arg1));
13376 : :
13377 : 227733 : if (!optimize)
13378 : : return;
13379 : :
13380 : 196015 : gimple *stmt = get_def_for_expr (*arg0, MINUS_EXPR);
13381 : 196015 : if (stmt == NULL)
13382 : : return;
13383 : :
13384 : 1377 : tree treeop0 = gimple_assign_rhs1 (stmt);
13385 : 1377 : tree treeop1 = gimple_assign_rhs2 (stmt);
13386 : 1377 : if (!TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (treeop0)))
13387 : : return;
13388 : :
13389 : 1282 : if (issue_strict_overflow_warning (WARN_STRICT_OVERFLOW_COMPARISON))
13390 : 1 : warning_at (gimple_location (stmt), OPT_Wstrict_overflow,
13391 : : "assuming signed overflow does not occur when "
13392 : : "simplifying %<X - Y %s 0%> to %<X %s Y%>",
13393 : : op_symbol_code (code), op_symbol_code (code));
13394 : :
13395 : 1282 : *arg0 = treeop0;
13396 : 1282 : *arg1 = treeop1;
13397 : : }
13398 : :
13399 : :
13400 : : /* Expand CODE with arguments INNER & (1<<BITNUM) and 0 that represents
13401 : : a single bit equality/inequality test, returns where the result is located. */
13402 : :
13403 : : static rtx
13404 : 6469 : expand_single_bit_test (location_t loc, enum tree_code code,
13405 : : tree inner, int bitnum,
13406 : : tree result_type, rtx target,
13407 : : machine_mode mode)
13408 : : {
13409 : 6469 : gcc_assert (code == NE_EXPR || code == EQ_EXPR);
13410 : :
13411 : 6469 : tree type = TREE_TYPE (inner);
13412 : 6469 : scalar_int_mode operand_mode = SCALAR_INT_TYPE_MODE (type);
13413 : 6469 : int ops_unsigned;
13414 : 6469 : tree signed_type, unsigned_type, intermediate_type;
13415 : 6469 : gimple *inner_def;
13416 : :
13417 : : /* First, see if we can fold the single bit test into a sign-bit
13418 : : test. */
13419 : 6469 : if (bitnum == TYPE_PRECISION (type) - 1
13420 : 6469 : && type_has_mode_precision_p (type))
13421 : : {
13422 : 89 : tree stype = signed_type_for (type);
13423 : 145 : tree tmp = fold_build2_loc (loc, code == EQ_EXPR ? GE_EXPR : LT_EXPR,
13424 : : result_type,
13425 : : fold_convert_loc (loc, stype, inner),
13426 : 89 : build_int_cst (stype, 0));
13427 : 89 : return expand_expr (tmp, target, VOIDmode, EXPAND_NORMAL);
13428 : : }
13429 : :
13430 : : /* Otherwise we have (A & C) != 0 where C is a single bit,
13431 : : convert that into ((A >> C2) & 1). Where C2 = log2(C).
13432 : : Similarly for (A & C) == 0. */
13433 : :
13434 : : /* If INNER is a right shift of a constant and it plus BITNUM does
13435 : : not overflow, adjust BITNUM and INNER. */
13436 : 6380 : if ((inner_def = get_def_for_expr (inner, RSHIFT_EXPR))
13437 : 14 : && TREE_CODE (gimple_assign_rhs2 (inner_def)) == INTEGER_CST
13438 : 0 : && bitnum < TYPE_PRECISION (type)
13439 : 6380 : && wi::ltu_p (wi::to_wide (gimple_assign_rhs2 (inner_def)),
13440 : 6380 : TYPE_PRECISION (type) - bitnum))
13441 : : {
13442 : 0 : bitnum += tree_to_uhwi (gimple_assign_rhs2 (inner_def));
13443 : 0 : inner = gimple_assign_rhs1 (inner_def);
13444 : : }
13445 : :
13446 : : /* If we are going to be able to omit the AND below, we must do our
13447 : : operations as unsigned. If we must use the AND, we have a choice.
13448 : : Normally unsigned is faster, but for some machines signed is. */
13449 : 6380 : ops_unsigned = (load_extend_op (operand_mode) == SIGN_EXTEND
13450 : : && !flag_syntax_only) ? 0 : 1;
13451 : :
13452 : 6380 : signed_type = lang_hooks.types.type_for_mode (operand_mode, 0);
13453 : 6380 : unsigned_type = lang_hooks.types.type_for_mode (operand_mode, 1);
13454 : 6380 : intermediate_type = ops_unsigned ? unsigned_type : signed_type;
13455 : 6380 : inner = fold_convert_loc (loc, intermediate_type, inner);
13456 : :
13457 : 6380 : rtx inner0 = expand_expr (inner, NULL_RTX, VOIDmode, EXPAND_NORMAL);
13458 : :
13459 : 6380 : if (CONST_SCALAR_INT_P (inner0))
13460 : : {
13461 : 0 : wide_int t = rtx_mode_t (inner0, operand_mode);
13462 : 0 : bool setp = (wi::lrshift (t, bitnum) & 1) != 0;
13463 : 0 : return (setp ^ (code == EQ_EXPR)) ? const1_rtx : const0_rtx;
13464 : 0 : }
13465 : 6380 : int bitpos = bitnum;
13466 : :
13467 : 6380 : if (BYTES_BIG_ENDIAN)
13468 : : bitpos = GET_MODE_BITSIZE (operand_mode) - 1 - bitpos;
13469 : :
13470 : 6380 : inner0 = extract_bit_field (inner0, 1, bitpos, 1, target,
13471 : : operand_mode, mode, 0, NULL);
13472 : :
13473 : 6380 : if (code == EQ_EXPR)
13474 : 1968 : inner0 = expand_binop (GET_MODE (inner0), xor_optab, inner0, const1_rtx,
13475 : : NULL_RTX, 1, OPTAB_LIB_WIDEN);
13476 : 6380 : if (GET_MODE (inner0) != mode)
13477 : : {
13478 : 0 : rtx t = gen_reg_rtx (mode);
13479 : 0 : convert_move (t, inner0, 0);
13480 : 0 : return t;
13481 : : }
13482 : : return inner0;
13483 : : }
13484 : :
13485 : : /* Generate code to calculate OPS, and exploded expression
13486 : : using a store-flag instruction and return an rtx for the result.
13487 : : OPS reflects a comparison.
13488 : :
13489 : : If TARGET is nonzero, store the result there if convenient.
13490 : :
13491 : : Return zero if there is no suitable set-flag instruction
13492 : : available on this machine.
13493 : :
13494 : : Once expand_expr has been called on the arguments of the comparison,
13495 : : we are committed to doing the store flag, since it is not safe to
13496 : : re-evaluate the expression. We emit the store-flag insn by calling
13497 : : emit_store_flag, but only expand the arguments if we have a reason
13498 : : to believe that emit_store_flag will be successful. If we think that
13499 : : it will, but it isn't, we have to simulate the store-flag with a
13500 : : set/jump/set sequence. */
13501 : :
13502 : : static rtx
13503 : 474544 : do_store_flag (sepops ops, rtx target, machine_mode mode)
13504 : : {
13505 : 474544 : enum rtx_code code;
13506 : 474544 : tree arg0, arg1, type;
13507 : 474544 : machine_mode operand_mode;
13508 : 474544 : int unsignedp;
13509 : 474544 : rtx op0, op1;
13510 : 474544 : rtx subtarget = target;
13511 : 474544 : location_t loc = ops->location;
13512 : 474544 : unsigned HOST_WIDE_INT nunits;
13513 : :
13514 : 474544 : arg0 = ops->op0;
13515 : 474544 : arg1 = ops->op1;
13516 : :
13517 : : /* Don't crash if the comparison was erroneous. */
13518 : 474544 : if (arg0 == error_mark_node || arg1 == error_mark_node)
13519 : 0 : return const0_rtx;
13520 : :
13521 : 474544 : type = TREE_TYPE (arg0);
13522 : 474544 : operand_mode = TYPE_MODE (type);
13523 : 474544 : unsignedp = TYPE_UNSIGNED (type);
13524 : :
13525 : : /* We won't bother with BLKmode store-flag operations because it would mean
13526 : : passing a lot of information to emit_store_flag. */
13527 : 474544 : if (operand_mode == BLKmode)
13528 : : return 0;
13529 : :
13530 : : /* We won't bother with store-flag operations involving function pointers
13531 : : when function pointers must be canonicalized before comparisons. */
13532 : 474544 : if (targetm.have_canonicalize_funcptr_for_compare ()
13533 : 474544 : && ((POINTER_TYPE_P (TREE_TYPE (arg0))
13534 : 0 : && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (arg0))))
13535 : 0 : || (POINTER_TYPE_P (TREE_TYPE (arg1))
13536 : 0 : && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (arg1))))))
13537 : : return 0;
13538 : :
13539 : 474544 : STRIP_NOPS (arg0);
13540 : 474544 : STRIP_NOPS (arg1);
13541 : :
13542 : : /* For vector typed comparisons emit code to generate the desired
13543 : : all-ones or all-zeros mask. */
13544 : 474544 : if (VECTOR_TYPE_P (ops->type))
13545 : : {
13546 : 9340 : tree ifexp = build2 (ops->code, ops->type, arg0, arg1);
13547 : 9340 : if (VECTOR_BOOLEAN_TYPE_P (ops->type)
13548 : 18680 : && expand_vec_cmp_expr_p (TREE_TYPE (arg0), ops->type, ops->code))
13549 : 9340 : return expand_vec_cmp_expr (ops->type, ifexp, target);
13550 : : else
13551 : 0 : gcc_unreachable ();
13552 : : }
13553 : :
13554 : : /* Optimize (x % C1) == C2 or (x % C1) != C2 if it is beneficial
13555 : : into (x - C2) * C3 < C4. */
13556 : 465204 : if ((ops->code == EQ_EXPR || ops->code == NE_EXPR)
13557 : 285818 : && TREE_CODE (arg0) == SSA_NAME
13558 : 283124 : && TREE_CODE (arg1) == INTEGER_CST)
13559 : : {
13560 : 166665 : enum tree_code new_code = maybe_optimize_mod_cmp (ops->code,
13561 : : &arg0, &arg1);
13562 : 166665 : if (new_code != ops->code)
13563 : : {
13564 : 78 : struct separate_ops nops = *ops;
13565 : 78 : nops.code = ops->code = new_code;
13566 : 78 : nops.op0 = arg0;
13567 : 78 : nops.op1 = arg1;
13568 : 78 : nops.type = TREE_TYPE (arg0);
13569 : 78 : return do_store_flag (&nops, target, mode);
13570 : : }
13571 : : }
13572 : :
13573 : : /* Optimize (x - y) < 0 into x < y if x - y has undefined overflow. */
13574 : 465126 : if (!unsignedp
13575 : 326865 : && (ops->code == LT_EXPR || ops->code == LE_EXPR
13576 : 326865 : || ops->code == GT_EXPR || ops->code == GE_EXPR)
13577 : 115619 : && integer_zerop (arg1)
13578 : 500853 : && TREE_CODE (arg0) == SSA_NAME)
13579 : 35722 : maybe_optimize_sub_cmp_0 (ops->code, &arg0, &arg1);
13580 : :
13581 : : /* Get the rtx comparison code to use. We know that EXP is a comparison
13582 : : operation of some type. Some comparisons against 1 and -1 can be
13583 : : converted to comparisons with zero. Do so here so that the tests
13584 : : below will be aware that we have a comparison with zero. These
13585 : : tests will not catch constants in the first operand, but constants
13586 : : are rarely passed as the first operand. */
13587 : :
13588 : 465126 : switch (ops->code)
13589 : : {
13590 : : case EQ_EXPR:
13591 : : code = EQ;
13592 : : break;
13593 : 172267 : case NE_EXPR:
13594 : 172267 : code = NE;
13595 : 172267 : break;
13596 : 35138 : case LT_EXPR:
13597 : 35138 : if (integer_onep (arg1))
13598 : 0 : arg1 = integer_zero_node, code = unsignedp ? LEU : LE;
13599 : : else
13600 : 35138 : code = unsignedp ? LTU : LT;
13601 : : break;
13602 : 27239 : case LE_EXPR:
13603 : 27239 : if (! unsignedp && integer_all_onesp (arg1))
13604 : 0 : arg1 = integer_zero_node, code = LT;
13605 : : else
13606 : 27239 : code = unsignedp ? LEU : LE;
13607 : : break;
13608 : 50530 : case GT_EXPR:
13609 : 50530 : if (! unsignedp && integer_all_onesp (arg1))
13610 : 0 : arg1 = integer_zero_node, code = GE;
13611 : : else
13612 : 50530 : code = unsignedp ? GTU : GT;
13613 : : break;
13614 : 40797 : case GE_EXPR:
13615 : 40797 : if (integer_onep (arg1))
13616 : 0 : arg1 = integer_zero_node, code = unsignedp ? GTU : GT;
13617 : : else
13618 : 40797 : code = unsignedp ? GEU : GE;
13619 : : break;
13620 : :
13621 : 671 : case UNORDERED_EXPR:
13622 : 671 : code = UNORDERED;
13623 : 671 : break;
13624 : 716 : case ORDERED_EXPR:
13625 : 716 : code = ORDERED;
13626 : 716 : break;
13627 : 483 : case UNLT_EXPR:
13628 : 483 : code = UNLT;
13629 : 483 : break;
13630 : 11939 : case UNLE_EXPR:
13631 : 11939 : code = UNLE;
13632 : 11939 : break;
13633 : 765 : case UNGT_EXPR:
13634 : 765 : code = UNGT;
13635 : 765 : break;
13636 : 10937 : case UNGE_EXPR:
13637 : 10937 : code = UNGE;
13638 : 10937 : break;
13639 : 152 : case UNEQ_EXPR:
13640 : 152 : code = UNEQ;
13641 : 152 : break;
13642 : 19 : case LTGT_EXPR:
13643 : 19 : code = LTGT;
13644 : 19 : break;
13645 : :
13646 : 0 : default:
13647 : 0 : gcc_unreachable ();
13648 : : }
13649 : :
13650 : : /* Put a constant second. */
13651 : 465126 : if (TREE_CODE (arg0) == REAL_CST || TREE_CODE (arg0) == INTEGER_CST
13652 : 464287 : || TREE_CODE (arg0) == FIXED_CST)
13653 : : {
13654 : 839 : std::swap (arg0, arg1);
13655 : 839 : code = swap_condition (code);
13656 : : }
13657 : :
13658 : : /* If this is an equality or inequality test of a single bit, we can
13659 : : do this by shifting the bit being tested to the low-order bit and
13660 : : masking the result with the constant 1. If the condition was EQ,
13661 : : we xor it with 1. This does not require an scc insn and is faster
13662 : : than an scc insn even if we have it. */
13663 : :
13664 : 465126 : if ((code == NE || code == EQ)
13665 : 285740 : && (integer_zerop (arg1)
13666 : 183114 : || integer_pow2p (arg1))
13667 : : /* vector types are not handled here. */
13668 : 130325 : && TREE_CODE (TREE_TYPE (arg1)) != VECTOR_TYPE
13669 : 595450 : && (TYPE_PRECISION (ops->type) != 1 || TYPE_UNSIGNED (ops->type)))
13670 : : {
13671 : 130324 : tree narg0 = arg0;
13672 : 130324 : wide_int nz = tree_nonzero_bits (narg0);
13673 : 130324 : gimple *srcstmt = get_def_for_expr (narg0, BIT_AND_EXPR);
13674 : : /* If the defining statement was (x & POW2), then use that instead of
13675 : : the non-zero bits. */
13676 : 130324 : if (srcstmt && integer_pow2p (gimple_assign_rhs2 (srcstmt)))
13677 : : {
13678 : 4362 : nz = wi::to_wide (gimple_assign_rhs2 (srcstmt));
13679 : 4362 : narg0 = gimple_assign_rhs1 (srcstmt);
13680 : : }
13681 : :
13682 : 130324 : if (wi::popcount (nz) == 1
13683 : 130324 : && (integer_zerop (arg1)
13684 : 123888 : || wi::to_wide (arg1) == nz))
13685 : : {
13686 : 6469 : int bitnum = wi::exact_log2 (nz);
13687 : 6469 : enum tree_code tcode = EQ_EXPR;
13688 : 6469 : if ((code == NE) ^ !integer_zerop (arg1))
13689 : 4468 : tcode = NE_EXPR;
13690 : :
13691 : 6469 : type = lang_hooks.types.type_for_mode (mode, unsignedp);
13692 : 6469 : return expand_single_bit_test (loc, tcode,
13693 : : narg0,
13694 : : bitnum, type, target, mode);
13695 : : }
13696 : 130324 : }
13697 : :
13698 : :
13699 : 458657 : if (! get_subtarget (target)
13700 : 458657 : || GET_MODE (subtarget) != operand_mode)
13701 : : subtarget = 0;
13702 : :
13703 : 458657 : expand_operands (arg0, arg1, subtarget, &op0, &op1, EXPAND_NORMAL);
13704 : :
13705 : : /* For boolean vectors with less than mode precision
13706 : : make sure to fill padding with consistent values. */
13707 : 1 : if (VECTOR_BOOLEAN_TYPE_P (type)
13708 : 1 : && SCALAR_INT_MODE_P (operand_mode)
13709 : 458657 : && TYPE_VECTOR_SUBPARTS (type).is_constant (&nunits)
13710 : 458658 : && maybe_ne (GET_MODE_PRECISION (operand_mode), nunits))
13711 : : {
13712 : 1 : gcc_assert (code == EQ || code == NE);
13713 : 1 : op0 = expand_binop (mode, and_optab, op0,
13714 : 1 : GEN_INT ((HOST_WIDE_INT_1U << nunits) - 1),
13715 : : NULL_RTX, true, OPTAB_WIDEN);
13716 : 1 : op1 = expand_binop (mode, and_optab, op1,
13717 : : GEN_INT ((HOST_WIDE_INT_1U << nunits) - 1),
13718 : : NULL_RTX, true, OPTAB_WIDEN);
13719 : : }
13720 : :
13721 : 458657 : if (target == 0)
13722 : 283998 : target = gen_reg_rtx (mode);
13723 : :
13724 : : /* Try a cstore if possible. */
13725 : 458657 : return emit_store_flag_force (target, code, op0, op1,
13726 : : operand_mode, unsignedp,
13727 : 458657 : (TYPE_PRECISION (ops->type) == 1
13728 : 916844 : && !TYPE_UNSIGNED (ops->type)) ? -1 : 1);
13729 : : }
13730 : :
13731 : : /* Attempt to generate a casesi instruction. Returns true if successful,
13732 : : false otherwise (i.e. if there is no casesi instruction).
13733 : :
13734 : : DEFAULT_PROBABILITY is the probability of jumping to the default
13735 : : label. */
13736 : : bool
13737 : 16432 : try_casesi (tree index_type, tree index_expr, tree minval, tree range,
13738 : : rtx table_label, rtx default_label, rtx fallback_label,
13739 : : profile_probability default_probability)
13740 : : {
13741 : 16432 : class expand_operand ops[5];
13742 : 16432 : scalar_int_mode index_mode = SImode;
13743 : 16432 : rtx op1, op2, index;
13744 : :
13745 : 16432 : if (! targetm.have_casesi ())
13746 : : return false;
13747 : :
13748 : : /* The index must be some form of integer. Convert it to SImode. */
13749 : 0 : scalar_int_mode omode = SCALAR_INT_TYPE_MODE (index_type);
13750 : 0 : if (GET_MODE_BITSIZE (omode) > GET_MODE_BITSIZE (index_mode))
13751 : : {
13752 : 0 : rtx rangertx = expand_normal (range);
13753 : :
13754 : : /* We must handle the endpoints in the original mode. */
13755 : 0 : index_expr = build2 (MINUS_EXPR, index_type,
13756 : : index_expr, minval);
13757 : 0 : minval = integer_zero_node;
13758 : 0 : index = expand_normal (index_expr);
13759 : 0 : if (default_label)
13760 : 0 : emit_cmp_and_jump_insns (rangertx, index, LTU, NULL_RTX,
13761 : : omode, 1, default_label,
13762 : : default_probability);
13763 : : /* Now we can safely truncate. */
13764 : 0 : index = convert_to_mode (index_mode, index, 0);
13765 : : }
13766 : : else
13767 : : {
13768 : 0 : if (omode != index_mode)
13769 : : {
13770 : 0 : index_type = lang_hooks.types.type_for_mode (index_mode, 0);
13771 : 0 : index_expr = fold_convert (index_type, index_expr);
13772 : : }
13773 : :
13774 : 0 : index = expand_normal (index_expr);
13775 : : }
13776 : :
13777 : 0 : do_pending_stack_adjust ();
13778 : :
13779 : 0 : op1 = expand_normal (minval);
13780 : 0 : op2 = expand_normal (range);
13781 : :
13782 : 0 : create_input_operand (&ops[0], index, index_mode);
13783 : 0 : create_convert_operand_from_type (&ops[1], op1, TREE_TYPE (minval));
13784 : 0 : create_convert_operand_from_type (&ops[2], op2, TREE_TYPE (range));
13785 : 0 : create_fixed_operand (&ops[3], table_label);
13786 : 0 : create_fixed_operand (&ops[4], (default_label
13787 : : ? default_label
13788 : : : fallback_label));
13789 : 0 : expand_jump_insn (targetm.code_for_casesi, 5, ops);
13790 : 0 : return true;
13791 : : }
13792 : :
13793 : : /* Attempt to generate a tablejump instruction; same concept. */
13794 : : /* Subroutine of the next function.
13795 : :
13796 : : INDEX is the value being switched on, with the lowest value
13797 : : in the table already subtracted.
13798 : : MODE is its expected mode (needed if INDEX is constant).
13799 : : RANGE is the length of the jump table.
13800 : : TABLE_LABEL is a CODE_LABEL rtx for the table itself.
13801 : :
13802 : : DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
13803 : : index value is out of range.
13804 : : DEFAULT_PROBABILITY is the probability of jumping to
13805 : : the default label. */
13806 : :
13807 : : static void
13808 : 16432 : do_tablejump (rtx index, machine_mode mode, rtx range, rtx table_label,
13809 : : rtx default_label, profile_probability default_probability)
13810 : : {
13811 : 16432 : rtx temp, vector;
13812 : :
13813 : 16432 : if (INTVAL (range) > cfun->cfg->max_jumptable_ents)
13814 : 15160 : cfun->cfg->max_jumptable_ents = INTVAL (range);
13815 : :
13816 : : /* Do an unsigned comparison (in the proper mode) between the index
13817 : : expression and the value which represents the length of the range.
13818 : : Since we just finished subtracting the lower bound of the range
13819 : : from the index expression, this comparison allows us to simultaneously
13820 : : check that the original index expression value is both greater than
13821 : : or equal to the minimum value of the range and less than or equal to
13822 : : the maximum value of the range. */
13823 : :
13824 : 16432 : if (default_label)
13825 : 14993 : emit_cmp_and_jump_insns (index, range, GTU, NULL_RTX, mode, 1,
13826 : : default_label, default_probability);
13827 : :
13828 : : /* If index is in range, it must fit in Pmode.
13829 : : Convert to Pmode so we can index with it. */
13830 : 16432 : if (mode != Pmode)
13831 : : {
13832 : 14914 : unsigned int width;
13833 : :
13834 : : /* We know the value of INDEX is between 0 and RANGE. If we have a
13835 : : sign-extended subreg, and RANGE does not have the sign bit set, then
13836 : : we have a value that is valid for both sign and zero extension. In
13837 : : this case, we get better code if we sign extend. */
13838 : 14914 : if (GET_CODE (index) == SUBREG
13839 : 10 : && SUBREG_PROMOTED_VAR_P (index)
13840 : 0 : && SUBREG_PROMOTED_SIGNED_P (index)
13841 : 0 : && ((width = GET_MODE_PRECISION (as_a <scalar_int_mode> (mode)))
13842 : : <= HOST_BITS_PER_WIDE_INT)
13843 : 14914 : && ! (UINTVAL (range) & (HOST_WIDE_INT_1U << (width - 1))))
13844 : 0 : index = convert_to_mode (Pmode, index, 0);
13845 : : else
13846 : 14914 : index = convert_to_mode (Pmode, index, 1);
13847 : : }
13848 : :
13849 : : /* Don't let a MEM slip through, because then INDEX that comes
13850 : : out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
13851 : : and break_out_memory_refs will go to work on it and mess it up. */
13852 : : #ifdef PIC_CASE_VECTOR_ADDRESS
13853 : : if (flag_pic && !REG_P (index))
13854 : : index = copy_to_mode_reg (Pmode, index);
13855 : : #endif
13856 : :
13857 : : /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
13858 : : GET_MODE_SIZE, because this indicates how large insns are. The other
13859 : : uses should all be Pmode, because they are addresses. This code
13860 : : could fail if addresses and insns are not the same size. */
13861 : 16432 : index = simplify_gen_binary (MULT, Pmode, index,
13862 : 32864 : gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE),
13863 : 16432 : Pmode));
13864 : 16432 : index = simplify_gen_binary (PLUS, Pmode, index,
13865 : 16432 : gen_rtx_LABEL_REF (Pmode, table_label));
13866 : :
13867 : : #ifdef PIC_CASE_VECTOR_ADDRESS
13868 : : if (flag_pic)
13869 : : index = PIC_CASE_VECTOR_ADDRESS (index);
13870 : : else
13871 : : #endif
13872 : 18044 : index = memory_address (CASE_VECTOR_MODE, index);
13873 : 18044 : temp = gen_reg_rtx (CASE_VECTOR_MODE);
13874 : 18044 : vector = gen_const_mem (CASE_VECTOR_MODE, index);
13875 : 16432 : convert_move (temp, vector, 0);
13876 : :
13877 : 16432 : emit_jump_insn (targetm.gen_tablejump (temp, table_label));
13878 : :
13879 : : /* If we are generating PIC code or if the table is PC-relative, the
13880 : : table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
13881 : 16432 : if (! CASE_VECTOR_PC_RELATIVE && ! flag_pic)
13882 : 15357 : emit_barrier ();
13883 : 16432 : }
13884 : :
13885 : : bool
13886 : 16432 : try_tablejump (tree index_type, tree index_expr, tree minval, tree range,
13887 : : rtx table_label, rtx default_label,
13888 : : profile_probability default_probability)
13889 : : {
13890 : 16432 : rtx index;
13891 : :
13892 : 16432 : if (! targetm.have_tablejump ())
13893 : : return false;
13894 : :
13895 : 16432 : index_expr = fold_build2 (MINUS_EXPR, index_type,
13896 : : fold_convert (index_type, index_expr),
13897 : : fold_convert (index_type, minval));
13898 : 16432 : index = expand_normal (index_expr);
13899 : 16432 : do_pending_stack_adjust ();
13900 : :
13901 : 16432 : do_tablejump (index, TYPE_MODE (index_type),
13902 : 16432 : convert_modes (TYPE_MODE (index_type),
13903 : 16432 : TYPE_MODE (TREE_TYPE (range)),
13904 : : expand_normal (range),
13905 : 16432 : TYPE_UNSIGNED (TREE_TYPE (range))),
13906 : : table_label, default_label, default_probability);
13907 : 16432 : return true;
13908 : : }
13909 : :
13910 : : /* Return a CONST_VECTOR rtx representing vector mask for
13911 : : a VECTOR_CST of booleans. */
13912 : : static rtx
13913 : 99 : const_vector_mask_from_tree (tree exp)
13914 : : {
13915 : 99 : machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
13916 : 99 : machine_mode inner = GET_MODE_INNER (mode);
13917 : :
13918 : 99 : rtx_vector_builder builder (mode, VECTOR_CST_NPATTERNS (exp),
13919 : 99 : VECTOR_CST_NELTS_PER_PATTERN (exp));
13920 : 99 : unsigned int count = builder.encoded_nelts ();
13921 : 263 : for (unsigned int i = 0; i < count; ++i)
13922 : : {
13923 : 164 : tree elt = VECTOR_CST_ELT (exp, i);
13924 : 164 : gcc_assert (TREE_CODE (elt) == INTEGER_CST);
13925 : 164 : if (integer_zerop (elt))
13926 : 43 : builder.quick_push (CONST0_RTX (inner));
13927 : 121 : else if (integer_onep (elt)
13928 : 121 : || integer_minus_onep (elt))
13929 : 121 : builder.quick_push (CONSTM1_RTX (inner));
13930 : : else
13931 : 0 : gcc_unreachable ();
13932 : : }
13933 : 99 : return builder.build ();
13934 : 99 : }
13935 : :
13936 : : /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
13937 : : static rtx
13938 : 495083 : const_vector_from_tree (tree exp)
13939 : : {
13940 : 495083 : machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
13941 : :
13942 : 495083 : if (initializer_zerop (exp))
13943 : 149388 : return CONST0_RTX (mode);
13944 : :
13945 : 345695 : if (VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (exp)))
13946 : 99 : return const_vector_mask_from_tree (exp);
13947 : :
13948 : 345596 : machine_mode inner = GET_MODE_INNER (mode);
13949 : :
13950 : 345596 : rtx_vector_builder builder (mode, VECTOR_CST_NPATTERNS (exp),
13951 : 345596 : VECTOR_CST_NELTS_PER_PATTERN (exp));
13952 : 345596 : unsigned int count = builder.encoded_nelts ();
13953 : 1116868 : for (unsigned int i = 0; i < count; ++i)
13954 : : {
13955 : 771272 : tree elt = VECTOR_CST_ELT (exp, i);
13956 : 771272 : if (TREE_CODE (elt) == REAL_CST)
13957 : 115034 : builder.quick_push (const_double_from_real_value (TREE_REAL_CST (elt),
13958 : : inner));
13959 : 656238 : else if (TREE_CODE (elt) == FIXED_CST)
13960 : 0 : builder.quick_push (CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt),
13961 : : inner));
13962 : : else
13963 : 656238 : builder.quick_push (immed_wide_int_const (wi::to_poly_wide (elt),
13964 : : inner));
13965 : : }
13966 : 345596 : return builder.build ();
13967 : 345596 : }
13968 : :
13969 : : /* Build a decl for a personality function given a language prefix. */
13970 : :
13971 : : tree
13972 : 32347 : build_personality_function (const char *lang)
13973 : : {
13974 : 32347 : const char *unwind_and_version;
13975 : 32347 : tree decl, type;
13976 : 32347 : char *name;
13977 : :
13978 : 32347 : switch (targetm_common.except_unwind_info (&global_options))
13979 : : {
13980 : : case UI_NONE:
13981 : : return NULL;
13982 : : case UI_SJLJ:
13983 : : unwind_and_version = "_sj0";
13984 : : break;
13985 : 32347 : case UI_DWARF2:
13986 : 32347 : case UI_TARGET:
13987 : 32347 : unwind_and_version = "_v0";
13988 : 32347 : break;
13989 : 0 : case UI_SEH:
13990 : 0 : unwind_and_version = "_seh0";
13991 : 0 : break;
13992 : 0 : default:
13993 : 0 : gcc_unreachable ();
13994 : : }
13995 : :
13996 : 32347 : name = ACONCAT (("__", lang, "_personality", unwind_and_version, NULL));
13997 : :
13998 : 32347 : type = build_function_type_list (unsigned_type_node,
13999 : : integer_type_node, integer_type_node,
14000 : : long_long_unsigned_type_node,
14001 : : ptr_type_node, ptr_type_node, NULL_TREE);
14002 : 32347 : decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
14003 : : get_identifier (name), type);
14004 : 32347 : DECL_ARTIFICIAL (decl) = 1;
14005 : 32347 : DECL_EXTERNAL (decl) = 1;
14006 : 32347 : TREE_PUBLIC (decl) = 1;
14007 : :
14008 : : /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
14009 : : are the flags assigned by targetm.encode_section_info. */
14010 : 32347 : SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl), 0), NULL);
14011 : :
14012 : 32347 : return decl;
14013 : : }
14014 : :
14015 : : /* Extracts the personality function of DECL and returns the corresponding
14016 : : libfunc. */
14017 : :
14018 : : rtx
14019 : 2981903 : get_personality_function (tree decl)
14020 : : {
14021 : 2981903 : tree personality = DECL_FUNCTION_PERSONALITY (decl);
14022 : 2981903 : enum eh_personality_kind pk;
14023 : :
14024 : 2981903 : pk = function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl));
14025 : 2981903 : if (pk == eh_personality_none)
14026 : : return NULL;
14027 : :
14028 : 143916 : if (!personality
14029 : 143916 : && pk == eh_personality_any)
14030 : 62636 : personality = lang_hooks.eh_personality ();
14031 : :
14032 : 143916 : if (pk == eh_personality_lang)
14033 : 81280 : gcc_assert (personality != NULL_TREE);
14034 : :
14035 : 143916 : return XEXP (DECL_RTL (personality), 0);
14036 : : }
14037 : :
14038 : : /* Returns a tree for the size of EXP in bytes. */
14039 : :
14040 : : static tree
14041 : 13868401 : tree_expr_size (const_tree exp)
14042 : : {
14043 : 13868401 : if (DECL_P (exp)
14044 : 13868401 : && DECL_SIZE_UNIT (exp) != 0)
14045 : 2037956 : return DECL_SIZE_UNIT (exp);
14046 : : else
14047 : 11830445 : return size_in_bytes (TREE_TYPE (exp));
14048 : : }
14049 : :
14050 : : /* Return an rtx for the size in bytes of the value of EXP. */
14051 : :
14052 : : rtx
14053 : 13662071 : expr_size (tree exp)
14054 : : {
14055 : 13662071 : tree size;
14056 : :
14057 : 13662071 : if (TREE_CODE (exp) == WITH_SIZE_EXPR)
14058 : 767 : size = TREE_OPERAND (exp, 1);
14059 : : else
14060 : : {
14061 : 13661304 : size = tree_expr_size (exp);
14062 : 13661304 : gcc_assert (size);
14063 : 13661304 : gcc_assert (size == SUBSTITUTE_PLACEHOLDER_IN_EXPR (size, exp));
14064 : : }
14065 : :
14066 : 13662071 : return expand_expr (size, NULL_RTX, TYPE_MODE (sizetype), EXPAND_NORMAL);
14067 : : }
14068 : :
14069 : : /* Return a wide integer for the size in bytes of the value of EXP, or -1
14070 : : if the size can vary or is larger than an integer. */
14071 : :
14072 : : HOST_WIDE_INT
14073 : 207097 : int_expr_size (const_tree exp)
14074 : : {
14075 : 207097 : tree size;
14076 : :
14077 : 207097 : if (TREE_CODE (exp) == WITH_SIZE_EXPR)
14078 : 0 : size = TREE_OPERAND (exp, 1);
14079 : : else
14080 : : {
14081 : 207097 : size = tree_expr_size (exp);
14082 : 207097 : gcc_assert (size);
14083 : : }
14084 : :
14085 : 207097 : if (size == 0 || !tree_fits_shwi_p (size))
14086 : 0 : return -1;
14087 : :
14088 : 207097 : return tree_to_shwi (size);
14089 : : }
|