Branch data Line data Source code
1 : : /* Convert tree expression to rtl instructions, for GNU compiler.
2 : : Copyright (C) 1988-2025 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 : : #include "internal-fn.h"
69 : :
70 : :
71 : : /* If this is nonzero, we do not bother generating VOLATILE
72 : : around volatile memory references, and we are willing to
73 : : output indirect addresses. If cse is to follow, we reject
74 : : indirect addresses so a useful potential cse is generated;
75 : : if it is used only once, instruction combination will produce
76 : : the same indirect address eventually. */
77 : : int cse_not_expected;
78 : :
79 : : static bool block_move_libcall_safe_for_call_parm (void);
80 : : static bool emit_block_move_via_pattern (rtx, rtx, rtx, unsigned, unsigned,
81 : : HOST_WIDE_INT, unsigned HOST_WIDE_INT,
82 : : unsigned HOST_WIDE_INT,
83 : : unsigned HOST_WIDE_INT, bool);
84 : : static void emit_block_move_via_loop (rtx, rtx, rtx, unsigned, int);
85 : : static void emit_block_move_via_sized_loop (rtx, rtx, rtx, unsigned, unsigned);
86 : : static void emit_block_move_via_oriented_loop (rtx, rtx, rtx, unsigned, unsigned);
87 : : static rtx emit_block_cmp_via_loop (rtx, rtx, rtx, tree, rtx, bool,
88 : : unsigned, unsigned);
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 (const_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 : 207778 : init_expr_target (void)
115 : : {
116 : 207778 : rtx pat;
117 : 207778 : int num_clobbers;
118 : 207778 : rtx mem, mem1;
119 : 207778 : 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 : 207778 : mem = gen_rtx_MEM (word_mode, stack_pointer_rtx);
125 : 207778 : 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 : 207778 : reg = gen_rtx_REG (word_mode, LAST_VIRTUAL_REGISTER + 1);
130 : :
131 : 207778 : rtx_insn *insn = as_a<rtx_insn *> (rtx_alloc (INSN));
132 : 207778 : pat = gen_rtx_SET (NULL_RTX, NULL_RTX);
133 : 207778 : PATTERN (insn) = pat;
134 : :
135 : 27218918 : for (machine_mode mode = VOIDmode; (int) mode < NUM_MACHINE_MODES;
136 : 27011140 : mode = (machine_mode) ((int) mode + 1))
137 : : {
138 : 27011140 : int regno;
139 : :
140 : 27011140 : direct_load[(int) mode] = direct_store[(int) mode] = 0;
141 : 27011140 : PUT_MODE (mem, mode);
142 : 27011140 : 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 : 27011140 : if (mode != VOIDmode && mode != BLKmode)
148 : 1851301766 : for (regno = 0; regno < FIRST_PSEUDO_REGISTER
149 : 1877897350 : && (direct_load[(int) mode] == 0 || direct_store[(int) mode] == 0);
150 : : regno++)
151 : : {
152 : 1851301766 : if (!targetm.hard_regno_mode_ok (regno, mode))
153 : 1737600536 : continue;
154 : :
155 : 113701230 : set_mode_and_regno (reg, mode, regno);
156 : :
157 : 113701230 : SET_SRC (pat) = mem;
158 : 113701230 : SET_DEST (pat) = reg;
159 : 113701230 : if (recog (pat, insn, &num_clobbers) >= 0)
160 : 6986894 : direct_load[(int) mode] = 1;
161 : :
162 : 113701230 : SET_SRC (pat) = mem1;
163 : 113701230 : SET_DEST (pat) = reg;
164 : 113701230 : if (recog (pat, insn, &num_clobbers) >= 0)
165 : 6986894 : direct_load[(int) mode] = 1;
166 : :
167 : 113701230 : SET_SRC (pat) = reg;
168 : 113701230 : SET_DEST (pat) = mem;
169 : 113701230 : if (recog (pat, insn, &num_clobbers) >= 0)
170 : 6986894 : direct_store[(int) mode] = 1;
171 : :
172 : 113701230 : SET_SRC (pat) = reg;
173 : 113701230 : SET_DEST (pat) = mem1;
174 : 113701230 : if (recog (pat, insn, &num_clobbers) >= 0)
175 : 6986894 : direct_store[(int) mode] = 1;
176 : : }
177 : : }
178 : :
179 : 207778 : mem = gen_rtx_MEM (VOIDmode, gen_raw_REG (Pmode, LAST_VIRTUAL_REGISTER + 1));
180 : :
181 : 207778 : opt_scalar_float_mode mode_iter;
182 : 1454446 : FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_FLOAT)
183 : : {
184 : 1246668 : scalar_float_mode mode = mode_iter.require ();
185 : 1246668 : scalar_float_mode srcmode;
186 : 4363338 : FOR_EACH_MODE_UNTIL (srcmode, mode)
187 : : {
188 : 3116670 : enum insn_code ic;
189 : :
190 : 3116670 : ic = can_extend_p (mode, srcmode, 0);
191 : 3116670 : if (ic == CODE_FOR_nothing)
192 : 2488863 : continue;
193 : :
194 : 627807 : PUT_MODE (mem, srcmode);
195 : :
196 : 627807 : if (insn_operand_matches (ic, 1, mem))
197 : 625732 : float_extend_from_mem[mode][srcmode] = true;
198 : : }
199 : : }
200 : 207778 : }
201 : :
202 : : /* This is run at the start of compiling a function. */
203 : :
204 : : void
205 : 1654947 : init_expr (void)
206 : : {
207 : 1654947 : memset (&crtl->expr, 0, sizeof (crtl->expr));
208 : 1654947 : }
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 : 1819357 : convert_move (rtx to, rtx from, int unsignedp)
218 : : {
219 : 1819357 : machine_mode to_mode = GET_MODE (to);
220 : 1819357 : machine_mode from_mode = GET_MODE (from);
221 : :
222 : 1819357 : gcc_assert (to_mode != BLKmode);
223 : 1819357 : gcc_assert (from_mode != BLKmode);
224 : :
225 : : /* If the source and destination are already the same, then there's
226 : : nothing to do. */
227 : 1819357 : if (to == from)
228 : 1819357 : 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 : 1819357 : scalar_int_mode to_int_mode;
235 : 1819357 : if (GET_CODE (from) == SUBREG
236 : 110120 : && SUBREG_PROMOTED_VAR_P (from)
237 : 1819357 : && is_a <scalar_int_mode> (to_mode, &to_int_mode)
238 : 1819357 : && (GET_MODE_PRECISION (subreg_promoted_mode (from))
239 : 0 : >= GET_MODE_PRECISION (to_int_mode))
240 : 1819357 : && 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 : 1819357 : gcc_assert (GET_CODE (to) != SUBREG || !SUBREG_PROMOTED_VAR_P (to));
266 : :
267 : 1819357 : if (to_mode == from_mode
268 : 1769900 : || (from_mode == VOIDmode && CONSTANT_P (from)))
269 : : {
270 : 49716 : emit_move_insn (to, from);
271 : 49716 : return;
272 : : }
273 : :
274 : 1769641 : if (VECTOR_MODE_P (to_mode) || VECTOR_MODE_P (from_mode))
275 : : {
276 : 28512 : if (GET_MODE_UNIT_PRECISION (to_mode)
277 : 14256 : > GET_MODE_UNIT_PRECISION (from_mode))
278 : : {
279 : 5636 : optab op = unsignedp ? zext_optab : sext_optab;
280 : 5636 : insn_code icode = convert_optab_handler (op, to_mode, from_mode);
281 : 5636 : if (icode != CODE_FOR_nothing)
282 : : {
283 : 852 : emit_unop_insn (icode, to, from,
284 : : unsignedp ? ZERO_EXTEND : SIGN_EXTEND);
285 : 852 : return;
286 : : }
287 : : }
288 : :
289 : 26808 : if (GET_MODE_UNIT_PRECISION (to_mode)
290 : 13404 : < GET_MODE_UNIT_PRECISION (from_mode))
291 : : {
292 : 1706 : insn_code icode = convert_optab_handler (trunc_optab,
293 : : to_mode, from_mode);
294 : 1706 : if (icode != CODE_FOR_nothing)
295 : : {
296 : 877 : emit_unop_insn (icode, to, from, TRUNCATE);
297 : 877 : return;
298 : : }
299 : : }
300 : :
301 : 37581 : gcc_assert (known_eq (GET_MODE_BITSIZE (from_mode),
302 : : GET_MODE_BITSIZE (to_mode)));
303 : :
304 : 12527 : if (VECTOR_MODE_P (to_mode))
305 : 12527 : from = force_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 : 12527 : emit_move_insn (to, from);
310 : 12527 : return;
311 : : }
312 : :
313 : 1755385 : 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 : 1755385 : convert_mode_scalar (to, from, unsignedp);
321 : : }
322 : :
323 : : /* Like convert_move, but deals only with scalar modes. */
324 : :
325 : : static void
326 : 1755429 : convert_mode_scalar (rtx to, rtx from, int unsignedp)
327 : : {
328 : : /* Both modes should be scalar types. */
329 : 1755434 : scalar_mode from_mode = as_a <scalar_mode> (GET_MODE (from));
330 : 1755434 : scalar_mode to_mode = as_a <scalar_mode> (GET_MODE (to));
331 : 1755434 : bool to_real = SCALAR_FLOAT_MODE_P (to_mode);
332 : 1755434 : bool from_real = SCALAR_FLOAT_MODE_P (from_mode);
333 : 1755434 : enum insn_code code;
334 : 1755434 : rtx libcall;
335 : :
336 : 1755434 : gcc_assert (to_real == from_real);
337 : :
338 : : /* rtx code for making an equivalent value. */
339 : 1755434 : enum rtx_code equiv_code = (unsignedp < 0 ? UNKNOWN
340 : 1755434 : : (unsignedp ? ZERO_EXTEND : SIGN_EXTEND));
341 : :
342 : 1755434 : auto acceptable_same_precision_modes
343 : 580 : = [] (scalar_mode from_mode, scalar_mode to_mode) -> bool
344 : : {
345 : 580 : if (DECIMAL_FLOAT_MODE_P (from_mode) != DECIMAL_FLOAT_MODE_P (to_mode))
346 : : return true;
347 : :
348 : : /* arm_bfloat_half_format <-> ieee_half_format */
349 : 2 : if ((REAL_MODE_FORMAT (from_mode) == &arm_bfloat_half_format
350 : 1 : && REAL_MODE_FORMAT (to_mode) == &ieee_half_format)
351 : 2 : || (REAL_MODE_FORMAT (to_mode) == &arm_bfloat_half_format
352 : 1 : && REAL_MODE_FORMAT (from_mode) == &ieee_half_format))
353 : : return true;
354 : :
355 : : /* ibm_extended_format <-> ieee_quad_format */
356 : 0 : if ((REAL_MODE_FORMAT (from_mode) == &ibm_extended_format
357 : 0 : && REAL_MODE_FORMAT (to_mode) == &ieee_quad_format)
358 : 0 : || (REAL_MODE_FORMAT (from_mode) == &ieee_quad_format
359 : 0 : && REAL_MODE_FORMAT (to_mode) == &ibm_extended_format))
360 : 0 : return true;
361 : :
362 : : return false;
363 : : };
364 : :
365 : 1755434 : if (to_real)
366 : : {
367 : 184871 : rtx value;
368 : 184871 : rtx_insn *insns;
369 : 184871 : convert_optab tab;
370 : :
371 : 184871 : gcc_assert ((GET_MODE_PRECISION (from_mode)
372 : : != GET_MODE_PRECISION (to_mode))
373 : : || acceptable_same_precision_modes (from_mode, to_mode));
374 : :
375 : 184871 : if (GET_MODE_PRECISION (from_mode) == GET_MODE_PRECISION (to_mode))
376 : : {
377 : 580 : if ((REAL_MODE_FORMAT (to_mode) == &arm_bfloat_half_format
378 : 1 : && REAL_MODE_FORMAT (from_mode) == &ieee_half_format)
379 : 580 : || (REAL_MODE_FORMAT (to_mode) == &ieee_quad_format
380 : 0 : && REAL_MODE_FORMAT (from_mode) == &ibm_extended_format))
381 : : /* libgcc implements just __trunchfbf2, not __extendhfbf2;
382 : : and __trunctfkf2, not __extendtfkf2. */
383 : : tab = trunc_optab;
384 : : else
385 : : /* Conversion between decimal float and binary float, same
386 : : size. */
387 : 579 : tab = DECIMAL_FLOAT_MODE_P (from_mode) ? trunc_optab : sext_optab;
388 : : }
389 : 184291 : else if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode))
390 : : tab = sext_optab;
391 : : else
392 : 19158 : tab = trunc_optab;
393 : :
394 : : /* Try converting directly if the insn is supported. */
395 : :
396 : 184871 : code = convert_optab_handler (tab, to_mode, from_mode);
397 : 184871 : if (code != CODE_FOR_nothing)
398 : : {
399 : 160713 : emit_unop_insn (code, to, from,
400 : : tab == sext_optab ? FLOAT_EXTEND : FLOAT_TRUNCATE);
401 : 160713 : return;
402 : : }
403 : :
404 : : #ifdef HAVE_SFmode
405 : 24158 : if (REAL_MODE_FORMAT (from_mode) == &arm_bfloat_half_format
406 : 24158 : && REAL_MODE_FORMAT (SFmode) == &ieee_single_format)
407 : : {
408 : 2640 : if (GET_MODE_PRECISION (to_mode) > GET_MODE_PRECISION (SFmode))
409 : : {
410 : : /* To cut down on libgcc size, implement
411 : : BFmode -> {DF,XF,TF}mode conversions by
412 : : BFmode -> SFmode -> {DF,XF,TF}mode conversions. */
413 : 4 : rtx temp = gen_reg_rtx (SFmode);
414 : 4 : convert_mode_scalar (temp, from, unsignedp);
415 : 4 : convert_mode_scalar (to, temp, unsignedp);
416 : 4 : return;
417 : : }
418 : 2636 : if (REAL_MODE_FORMAT (to_mode) == &ieee_half_format)
419 : : {
420 : : /* Similarly, implement BFmode -> HFmode as
421 : : BFmode -> SFmode -> HFmode conversion where SFmode
422 : : has superset of BFmode values. We don't need
423 : : to handle sNaNs by raising exception and turning
424 : : it into qNaN though, as that can be done in the
425 : : SFmode -> HFmode conversion too. */
426 : 1 : rtx temp = gen_reg_rtx (SFmode);
427 : 1 : int save_flag_finite_math_only = flag_finite_math_only;
428 : 1 : flag_finite_math_only = true;
429 : 1 : convert_mode_scalar (temp, from, unsignedp);
430 : 1 : flag_finite_math_only = save_flag_finite_math_only;
431 : 1 : convert_mode_scalar (to, temp, unsignedp);
432 : 1 : return;
433 : : }
434 : 2635 : if (to_mode == SFmode
435 : 2635 : && !HONOR_NANS (from_mode)
436 : 40 : && !HONOR_NANS (to_mode)
437 : 2675 : && optimize_insn_for_speed_p ())
438 : : {
439 : : /* If we don't expect sNaNs, for BFmode -> SFmode we can just
440 : : shift the bits up. */
441 : 39 : machine_mode fromi_mode, toi_mode;
442 : 78 : if (int_mode_for_size (GET_MODE_BITSIZE (from_mode),
443 : 39 : 0).exists (&fromi_mode)
444 : 39 : && int_mode_for_size (GET_MODE_BITSIZE (to_mode),
445 : 0 : 0).exists (&toi_mode))
446 : : {
447 : 39 : start_sequence ();
448 : 39 : rtx fromi = force_lowpart_subreg (fromi_mode, from,
449 : : from_mode);
450 : 39 : rtx tof = NULL_RTX;
451 : 39 : if (fromi)
452 : : {
453 : 39 : rtx toi;
454 : 39 : if (GET_MODE (fromi) == VOIDmode)
455 : 0 : toi = simplify_unary_operation (ZERO_EXTEND, toi_mode,
456 : : fromi, fromi_mode);
457 : : else
458 : : {
459 : 39 : toi = gen_reg_rtx (toi_mode);
460 : 39 : convert_mode_scalar (toi, fromi, 1);
461 : : }
462 : 39 : toi
463 : 78 : = maybe_expand_shift (LSHIFT_EXPR, toi_mode, toi,
464 : 39 : GET_MODE_PRECISION (to_mode)
465 : 39 : - GET_MODE_PRECISION (from_mode),
466 : : NULL_RTX, 1);
467 : 39 : if (toi)
468 : : {
469 : 39 : tof = force_lowpart_subreg (to_mode, toi, toi_mode);
470 : 39 : if (tof)
471 : 39 : emit_move_insn (to, tof);
472 : : }
473 : : }
474 : 39 : insns = get_insns ();
475 : 39 : end_sequence ();
476 : 39 : if (tof)
477 : : {
478 : 39 : emit_insn (insns);
479 : 39 : return;
480 : : }
481 : : }
482 : : }
483 : : }
484 : 24114 : if (REAL_MODE_FORMAT (from_mode) == &ieee_single_format
485 : 5013 : && REAL_MODE_FORMAT (to_mode) == &arm_bfloat_half_format
486 : 1816 : && !HONOR_NANS (from_mode)
487 : 0 : && !HONOR_NANS (to_mode)
488 : 0 : && !flag_rounding_math
489 : 24114 : && optimize_insn_for_speed_p ())
490 : : {
491 : : /* If we don't expect qNaNs nor sNaNs and can assume rounding
492 : : to nearest, we can expand the conversion inline as
493 : : (fromi + 0x7fff + ((fromi >> 16) & 1)) >> 16. */
494 : 0 : machine_mode fromi_mode, toi_mode;
495 : 0 : if (int_mode_for_size (GET_MODE_BITSIZE (from_mode),
496 : 0 : 0).exists (&fromi_mode)
497 : 0 : && int_mode_for_size (GET_MODE_BITSIZE (to_mode),
498 : 0 : 0).exists (&toi_mode))
499 : : {
500 : 0 : start_sequence ();
501 : 0 : rtx fromi = force_lowpart_subreg (fromi_mode, from, from_mode);
502 : 0 : rtx tof = NULL_RTX;
503 : 0 : do
504 : : {
505 : 0 : if (!fromi)
506 : : break;
507 : 0 : int shift = (GET_MODE_PRECISION (from_mode)
508 : 0 : - GET_MODE_PRECISION (to_mode));
509 : 0 : rtx temp1
510 : 0 : = maybe_expand_shift (RSHIFT_EXPR, fromi_mode, fromi,
511 : : shift, NULL_RTX, 1);
512 : 0 : if (!temp1)
513 : : break;
514 : 0 : rtx temp2
515 : 0 : = expand_binop (fromi_mode, and_optab, temp1, const1_rtx,
516 : : NULL_RTX, 1, OPTAB_DIRECT);
517 : 0 : if (!temp2)
518 : : break;
519 : 0 : rtx temp3
520 : 0 : = expand_binop (fromi_mode, add_optab, fromi,
521 : 0 : gen_int_mode ((HOST_WIDE_INT_1U
522 : 0 : << (shift - 1)) - 1,
523 : : fromi_mode), NULL_RTX,
524 : : 1, OPTAB_DIRECT);
525 : 0 : if (!temp3)
526 : : break;
527 : 0 : rtx temp4
528 : 0 : = expand_binop (fromi_mode, add_optab, temp3, temp2,
529 : : NULL_RTX, 1, OPTAB_DIRECT);
530 : 0 : if (!temp4)
531 : : break;
532 : 0 : rtx temp5 = maybe_expand_shift (RSHIFT_EXPR, fromi_mode,
533 : : temp4, shift, NULL_RTX, 1);
534 : 0 : if (!temp5)
535 : : break;
536 : 0 : rtx temp6 = force_lowpart_subreg (toi_mode, temp5,
537 : : fromi_mode);
538 : 0 : if (!temp6)
539 : : break;
540 : 0 : tof = force_lowpart_subreg (to_mode, temp6, toi_mode);
541 : 0 : if (tof)
542 : 0 : emit_move_insn (to, tof);
543 : : }
544 : : while (0);
545 : 0 : insns = get_insns ();
546 : 0 : end_sequence ();
547 : 0 : if (tof)
548 : : {
549 : 0 : emit_insn (insns);
550 : 0 : return;
551 : : }
552 : : }
553 : : }
554 : : #endif
555 : :
556 : : /* Otherwise use a libcall. */
557 : 24114 : libcall = convert_optab_libfunc (tab, to_mode, from_mode);
558 : :
559 : : /* Is this conversion implemented yet? */
560 : 24114 : gcc_assert (libcall);
561 : :
562 : 24114 : start_sequence ();
563 : 24114 : value = emit_library_call_value (libcall, NULL_RTX, LCT_CONST, to_mode,
564 : : from, from_mode);
565 : 24114 : insns = get_insns ();
566 : 24114 : end_sequence ();
567 : 24114 : emit_libcall_block (insns, to, value,
568 : 7443 : tab == trunc_optab ? gen_rtx_FLOAT_TRUNCATE (to_mode,
569 : : from)
570 : 16671 : : gen_rtx_FLOAT_EXTEND (to_mode, from));
571 : 24114 : return;
572 : : }
573 : :
574 : : /* Handle pointer conversion. */ /* SPEE 900220. */
575 : : /* If the target has a converter from FROM_MODE to TO_MODE, use it. */
576 : 1570563 : {
577 : 1570563 : convert_optab ctab;
578 : :
579 : 1570563 : if (GET_MODE_PRECISION (from_mode) > GET_MODE_PRECISION (to_mode))
580 : : ctab = trunc_optab;
581 : 1378196 : else if (unsignedp)
582 : : ctab = zext_optab;
583 : : else
584 : 731628 : ctab = sext_optab;
585 : :
586 : 1570563 : if (convert_optab_handler (ctab, to_mode, from_mode)
587 : : != CODE_FOR_nothing)
588 : : {
589 : 1372851 : emit_unop_insn (convert_optab_handler (ctab, to_mode, from_mode),
590 : : to, from, UNKNOWN);
591 : 1372851 : return;
592 : : }
593 : : }
594 : :
595 : : /* Targets are expected to provide conversion insns between PxImode and
596 : : xImode for all MODE_PARTIAL_INT modes they use, but no others. */
597 : 197712 : if (GET_MODE_CLASS (to_mode) == MODE_PARTIAL_INT)
598 : : {
599 : 0 : scalar_int_mode full_mode
600 : 0 : = smallest_int_mode_for_size (GET_MODE_BITSIZE (to_mode)).require ();
601 : :
602 : 0 : gcc_assert (convert_optab_handler (trunc_optab, to_mode, full_mode)
603 : : != CODE_FOR_nothing);
604 : :
605 : 0 : if (full_mode != from_mode)
606 : 0 : from = convert_to_mode (full_mode, from, unsignedp);
607 : 0 : emit_unop_insn (convert_optab_handler (trunc_optab, to_mode, full_mode),
608 : : to, from, UNKNOWN);
609 : 0 : return;
610 : : }
611 : 197712 : if (GET_MODE_CLASS (from_mode) == MODE_PARTIAL_INT)
612 : : {
613 : 0 : rtx new_from;
614 : 0 : scalar_int_mode full_mode
615 : 0 : = smallest_int_mode_for_size (GET_MODE_BITSIZE (from_mode)).require ();
616 : 0 : convert_optab ctab = unsignedp ? zext_optab : sext_optab;
617 : 0 : enum insn_code icode;
618 : :
619 : 0 : icode = convert_optab_handler (ctab, full_mode, from_mode);
620 : 0 : gcc_assert (icode != CODE_FOR_nothing);
621 : :
622 : 0 : if (to_mode == full_mode)
623 : : {
624 : 0 : emit_unop_insn (icode, to, from, UNKNOWN);
625 : 0 : return;
626 : : }
627 : :
628 : 0 : new_from = gen_reg_rtx (full_mode);
629 : 0 : emit_unop_insn (icode, new_from, from, UNKNOWN);
630 : :
631 : : /* else proceed to integer conversions below. */
632 : 0 : from_mode = full_mode;
633 : 0 : from = new_from;
634 : : }
635 : :
636 : : /* Make sure both are fixed-point modes or both are not. */
637 : 197712 : gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode) ==
638 : : ALL_SCALAR_FIXED_POINT_MODE_P (to_mode));
639 : 197712 : if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode))
640 : : {
641 : : /* If we widen from_mode to to_mode and they are in the same class,
642 : : we won't saturate the result.
643 : : Otherwise, always saturate the result to play safe. */
644 : 0 : if (GET_MODE_CLASS (from_mode) == GET_MODE_CLASS (to_mode)
645 : 0 : && GET_MODE_SIZE (from_mode) < GET_MODE_SIZE (to_mode))
646 : 0 : expand_fixed_convert (to, from, 0, 0);
647 : : else
648 : 0 : expand_fixed_convert (to, from, 0, 1);
649 : 0 : return;
650 : : }
651 : :
652 : : /* Now both modes are integers. */
653 : :
654 : : /* Handle expanding beyond a word. */
655 : 197712 : if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode)
656 : 200377 : && GET_MODE_PRECISION (to_mode) > BITS_PER_WORD)
657 : : {
658 : 5345 : rtx_insn *insns;
659 : 5345 : rtx lowpart;
660 : 5345 : rtx fill_value;
661 : 5345 : rtx lowfrom;
662 : 5345 : int i;
663 : 5345 : scalar_mode lowpart_mode;
664 : 10690 : int nwords = CEIL (GET_MODE_SIZE (to_mode), UNITS_PER_WORD);
665 : :
666 : : /* Try converting directly if the insn is supported. */
667 : 5345 : if ((code = can_extend_p (to_mode, from_mode, unsignedp))
668 : : != CODE_FOR_nothing)
669 : : {
670 : : /* If FROM is a SUBREG, put it into a register. Do this
671 : : so that we always generate the same set of insns for
672 : : better cse'ing; if an intermediate assignment occurred,
673 : : we won't be doing the operation directly on the SUBREG. */
674 : 0 : if (optimize > 0 && GET_CODE (from) == SUBREG)
675 : 0 : from = force_reg (from_mode, from);
676 : 0 : emit_unop_insn (code, to, from, equiv_code);
677 : 0 : return;
678 : : }
679 : : /* Next, try converting via full word. */
680 : 5345 : else if (GET_MODE_PRECISION (from_mode) < BITS_PER_WORD
681 : 5345 : && ((code = can_extend_p (to_mode, word_mode, unsignedp))
682 : : != CODE_FOR_nothing))
683 : : {
684 : 5345 : rtx word_to = gen_reg_rtx (word_mode);
685 : 5345 : if (REG_P (to))
686 : : {
687 : 5275 : if (reg_overlap_mentioned_p (to, from))
688 : 0 : from = force_reg (from_mode, from);
689 : 5275 : emit_clobber (to);
690 : : }
691 : 5345 : convert_move (word_to, from, unsignedp);
692 : 5345 : emit_unop_insn (code, to, word_to, equiv_code);
693 : 5345 : return;
694 : : }
695 : :
696 : : /* No special multiword conversion insn; do it by hand. */
697 : 0 : start_sequence ();
698 : :
699 : : /* Since we will turn this into a no conflict block, we must ensure
700 : : the source does not overlap the target so force it into an isolated
701 : : register when maybe so. Likewise for any MEM input, since the
702 : : conversion sequence might require several references to it and we
703 : : must ensure we're getting the same value every time. */
704 : :
705 : 0 : if (MEM_P (from) || reg_overlap_mentioned_p (to, from))
706 : 0 : from = force_reg (from_mode, from);
707 : :
708 : : /* Get a copy of FROM widened to a word, if necessary. */
709 : 0 : if (GET_MODE_PRECISION (from_mode) < BITS_PER_WORD)
710 : 0 : lowpart_mode = word_mode;
711 : : else
712 : : lowpart_mode = from_mode;
713 : :
714 : 0 : lowfrom = convert_to_mode (lowpart_mode, from, unsignedp);
715 : :
716 : 0 : lowpart = gen_lowpart (lowpart_mode, to);
717 : 0 : emit_move_insn (lowpart, lowfrom);
718 : :
719 : : /* Compute the value to put in each remaining word. */
720 : 0 : if (unsignedp)
721 : 0 : fill_value = const0_rtx;
722 : : else
723 : 0 : fill_value = emit_store_flag_force (gen_reg_rtx (word_mode),
724 : : LT, lowfrom, const0_rtx,
725 : : lowpart_mode, 0, -1);
726 : :
727 : : /* Fill the remaining words. */
728 : 0 : for (i = GET_MODE_SIZE (lowpart_mode) / UNITS_PER_WORD; i < nwords; i++)
729 : : {
730 : 0 : int index = (WORDS_BIG_ENDIAN ? nwords - i - 1 : i);
731 : 0 : rtx subword = operand_subword (to, index, 1, to_mode);
732 : :
733 : 0 : gcc_assert (subword);
734 : :
735 : 0 : if (fill_value != subword)
736 : 0 : emit_move_insn (subword, fill_value);
737 : : }
738 : :
739 : 0 : insns = get_insns ();
740 : 0 : end_sequence ();
741 : :
742 : 0 : emit_insn (insns);
743 : 0 : return;
744 : : }
745 : :
746 : : /* Truncating multi-word to a word or less. */
747 : 192367 : if (GET_MODE_PRECISION (from_mode) > BITS_PER_WORD
748 : 192367 : && GET_MODE_PRECISION (to_mode) <= BITS_PER_WORD)
749 : : {
750 : 72287 : if (!((MEM_P (from)
751 : 551 : && ! MEM_VOLATILE_P (from)
752 : 551 : && direct_load[(int) to_mode]
753 : 551 : && ! mode_dependent_address_p (XEXP (from, 0),
754 : 551 : MEM_ADDR_SPACE (from)))
755 : 40880 : || REG_P (from)
756 : : || GET_CODE (from) == SUBREG))
757 : 0 : from = force_reg (from_mode, from);
758 : 41431 : convert_move (to, gen_lowpart (word_mode, from), 0);
759 : 41431 : return;
760 : : }
761 : :
762 : : /* Now follow all the conversions between integers
763 : : no more than a word long. */
764 : :
765 : : /* For truncation, usually we can just refer to FROM in a narrower mode. */
766 : 301872 : if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode)
767 : 150936 : && TRULY_NOOP_TRUNCATION_MODES_P (to_mode, from_mode))
768 : : {
769 : 163716 : if (!((MEM_P (from)
770 : 13339 : && ! MEM_VOLATILE_P (from)
771 : 13280 : && direct_load[(int) to_mode]
772 : 13280 : && ! mode_dependent_address_p (XEXP (from, 0),
773 : 13280 : MEM_ADDR_SPACE (from)))
774 : 137656 : || REG_P (from)
775 : : || GET_CODE (from) == SUBREG))
776 : 917 : from = force_reg (from_mode, from);
777 : 125793 : if (REG_P (from) && REGNO (from) < FIRST_PSEUDO_REGISTER
778 : 150937 : && !targetm.hard_regno_mode_ok (REGNO (from), to_mode))
779 : 0 : from = copy_to_reg (from);
780 : 150936 : emit_move_insn (to, gen_lowpart (to_mode, from));
781 : 150936 : return;
782 : : }
783 : :
784 : : /* Handle extension. */
785 : 0 : if (GET_MODE_PRECISION (to_mode) > GET_MODE_PRECISION (from_mode))
786 : : {
787 : : /* Convert directly if that works. */
788 : 0 : if ((code = can_extend_p (to_mode, from_mode, unsignedp))
789 : : != CODE_FOR_nothing)
790 : : {
791 : 0 : emit_unop_insn (code, to, from, equiv_code);
792 : 0 : return;
793 : : }
794 : : else
795 : : {
796 : 0 : rtx tmp;
797 : 0 : int shift_amount;
798 : :
799 : : /* Search for a mode to convert via. */
800 : 0 : opt_scalar_mode intermediate_iter;
801 : 0 : FOR_EACH_MODE_FROM (intermediate_iter, from_mode)
802 : : {
803 : 0 : scalar_mode intermediate = intermediate_iter.require ();
804 : 0 : if (((can_extend_p (to_mode, intermediate, unsignedp)
805 : : != CODE_FOR_nothing)
806 : 0 : || (GET_MODE_SIZE (to_mode) < GET_MODE_SIZE (intermediate)
807 : 0 : && TRULY_NOOP_TRUNCATION_MODES_P (to_mode,
808 : : intermediate)))
809 : 0 : && (can_extend_p (intermediate, from_mode, unsignedp)
810 : : != CODE_FOR_nothing))
811 : : {
812 : 0 : convert_move (to, convert_to_mode (intermediate, from,
813 : : unsignedp), unsignedp);
814 : 0 : return;
815 : : }
816 : : }
817 : :
818 : : /* No suitable intermediate mode.
819 : : Generate what we need with shifts. */
820 : 0 : shift_amount = (GET_MODE_PRECISION (to_mode)
821 : 0 : - GET_MODE_PRECISION (from_mode));
822 : 0 : from = gen_lowpart (to_mode, force_reg (from_mode, from));
823 : 0 : tmp = expand_shift (LSHIFT_EXPR, to_mode, from, shift_amount,
824 : : to, unsignedp);
825 : 0 : tmp = expand_shift (RSHIFT_EXPR, to_mode, tmp, shift_amount,
826 : : to, unsignedp);
827 : 0 : if (tmp != to)
828 : 0 : emit_move_insn (to, tmp);
829 : 0 : return;
830 : : }
831 : : }
832 : :
833 : : /* Support special truncate insns for certain modes. */
834 : 0 : if (convert_optab_handler (trunc_optab, to_mode,
835 : : from_mode) != CODE_FOR_nothing)
836 : : {
837 : 0 : emit_unop_insn (convert_optab_handler (trunc_optab, to_mode, from_mode),
838 : : to, from, UNKNOWN);
839 : 0 : return;
840 : : }
841 : :
842 : : /* Handle truncation of volatile memrefs, and so on;
843 : : the things that couldn't be truncated directly,
844 : : and for which there was no special instruction.
845 : :
846 : : ??? Code above formerly short-circuited this, for most integer
847 : : mode pairs, with a force_reg in from_mode followed by a recursive
848 : : call to this routine. Appears always to have been wrong. */
849 : 0 : if (GET_MODE_PRECISION (to_mode) < GET_MODE_PRECISION (from_mode))
850 : : {
851 : 0 : rtx temp = force_reg (to_mode, gen_lowpart (to_mode, from));
852 : 0 : emit_move_insn (to, temp);
853 : 0 : return;
854 : : }
855 : :
856 : : /* Mode combination is not recognized. */
857 : 0 : gcc_unreachable ();
858 : : }
859 : :
860 : : /* Return an rtx for a value that would result
861 : : from converting X to mode MODE.
862 : : Both X and MODE may be floating, or both integer.
863 : : UNSIGNEDP is nonzero if X is an unsigned value.
864 : : This can be done by referring to a part of X in place
865 : : or by copying to a new temporary with conversion. */
866 : :
867 : : rtx
868 : 1664728 : convert_to_mode (machine_mode mode, rtx x, int unsignedp)
869 : : {
870 : 1664728 : return convert_modes (mode, VOIDmode, x, unsignedp);
871 : : }
872 : :
873 : : /* Return an rtx for a value that would result
874 : : from converting X from mode OLDMODE to mode MODE.
875 : : Both modes may be floating, or both integer.
876 : : UNSIGNEDP is nonzero if X is an unsigned value.
877 : :
878 : : This can be done by referring to a part of X in place
879 : : or by copying to a new temporary with conversion.
880 : :
881 : : You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
882 : :
883 : : rtx
884 : 4424577 : convert_modes (machine_mode mode, machine_mode oldmode, rtx x, int unsignedp)
885 : : {
886 : 4424577 : rtx temp;
887 : 4424577 : scalar_int_mode int_mode;
888 : :
889 : : /* If FROM is a SUBREG that indicates that we have already done at least
890 : : the required extension, strip it. */
891 : :
892 : 4424577 : if (GET_CODE (x) == SUBREG
893 : 75057 : && SUBREG_PROMOTED_VAR_P (x)
894 : 4424577 : && is_a <scalar_int_mode> (mode, &int_mode)
895 : 4424577 : && (GET_MODE_PRECISION (subreg_promoted_mode (x))
896 : 3 : >= GET_MODE_PRECISION (int_mode))
897 : 4424580 : && SUBREG_CHECK_PROMOTED_SIGN (x, unsignedp))
898 : : {
899 : 3 : scalar_int_mode int_orig_mode;
900 : 3 : scalar_int_mode int_inner_mode;
901 : 3 : machine_mode orig_mode = GET_MODE (x);
902 : 3 : x = gen_lowpart (int_mode, SUBREG_REG (x));
903 : :
904 : : /* Preserve SUBREG_PROMOTED_VAR_P if the new mode is wider than
905 : : the original mode, but narrower than the inner mode. */
906 : 3 : if (GET_CODE (x) == SUBREG
907 : 0 : && is_a <scalar_int_mode> (orig_mode, &int_orig_mode)
908 : 0 : && GET_MODE_PRECISION (int_mode)
909 : 0 : > GET_MODE_PRECISION (int_orig_mode)
910 : 0 : && is_a <scalar_int_mode> (GET_MODE (SUBREG_REG (x)),
911 : : &int_inner_mode)
912 : 3 : && GET_MODE_PRECISION (int_inner_mode)
913 : 0 : > GET_MODE_PRECISION (int_mode))
914 : : {
915 : 0 : SUBREG_PROMOTED_VAR_P (x) = 1;
916 : 0 : SUBREG_PROMOTED_SET (x, unsignedp);
917 : : }
918 : : }
919 : :
920 : 4424577 : if (GET_MODE (x) != VOIDmode)
921 : 2207516 : oldmode = GET_MODE (x);
922 : :
923 : 4424577 : if (mode == oldmode)
924 : : return x;
925 : :
926 : 3417382 : if (CONST_SCALAR_INT_P (x)
927 : 3417382 : && is_a <scalar_int_mode> (mode, &int_mode))
928 : : {
929 : : /* If the caller did not tell us the old mode, then there is not
930 : : much to do with respect to canonicalization. We have to
931 : : assume that all the bits are significant. */
932 : 1897592 : if (!is_a <scalar_int_mode> (oldmode))
933 : 1593610 : oldmode = MAX_MODE_INT;
934 : 1897592 : wide_int w = wide_int::from (rtx_mode_t (x, oldmode),
935 : 1897592 : GET_MODE_PRECISION (int_mode),
936 : 2741804 : unsignedp ? UNSIGNED : SIGNED);
937 : 1897592 : return immed_wide_int_const (w, int_mode);
938 : 1897592 : }
939 : :
940 : : /* We can do this with a gen_lowpart if both desired and current modes
941 : : are integer, and this is either a constant integer, a register, or a
942 : : non-volatile MEM. */
943 : 1519790 : scalar_int_mode int_oldmode;
944 : 1519790 : if (is_int_mode (mode, &int_mode)
945 : 1427734 : && is_int_mode (oldmode, &int_oldmode)
946 : 1427734 : && GET_MODE_PRECISION (int_mode) <= GET_MODE_PRECISION (int_oldmode)
947 : 451904 : && ((MEM_P (x) && !MEM_VOLATILE_P (x) && direct_load[(int) int_mode])
948 : 10970 : || CONST_POLY_INT_P (x)
949 : 440934 : || (REG_P (x)
950 : 403527 : && (!HARD_REGISTER_P (x)
951 : 1023 : || targetm.hard_regno_mode_ok (REGNO (x), int_mode))
952 : 403527 : && TRULY_NOOP_TRUNCATION_MODES_P (int_mode, GET_MODE (x)))))
953 : 414497 : return gen_lowpart (int_mode, x);
954 : :
955 : : /* Converting from integer constant into mode is always equivalent to an
956 : : subreg operation. */
957 : 1105293 : if (VECTOR_MODE_P (mode) && GET_MODE (x) == VOIDmode)
958 : : {
959 : 0 : gcc_assert (known_eq (GET_MODE_BITSIZE (mode),
960 : : GET_MODE_BITSIZE (oldmode)));
961 : 0 : return force_subreg (mode, x, oldmode, 0);
962 : : }
963 : :
964 : 1105293 : temp = gen_reg_rtx (mode);
965 : 1105293 : convert_move (temp, x, unsignedp);
966 : 1105293 : return temp;
967 : : }
968 : :
969 : : /* Variant of convert_modes for ABI parameter passing/return.
970 : : Return an rtx for a value that would result from converting X from
971 : : a floating point mode FMODE to wider integer mode MODE. */
972 : :
973 : : rtx
974 : 0 : convert_float_to_wider_int (machine_mode mode, machine_mode fmode, rtx x)
975 : : {
976 : 0 : gcc_assert (SCALAR_INT_MODE_P (mode) && SCALAR_FLOAT_MODE_P (fmode));
977 : 0 : scalar_int_mode tmp_mode = int_mode_for_mode (fmode).require ();
978 : 0 : rtx tmp = force_reg (tmp_mode, gen_lowpart (tmp_mode, x));
979 : 0 : return convert_modes (mode, tmp_mode, tmp, 1);
980 : : }
981 : :
982 : : /* Variant of convert_modes for ABI parameter passing/return.
983 : : Return an rtx for a value that would result from converting X from
984 : : an integer mode IMODE to a narrower floating point mode MODE. */
985 : :
986 : : rtx
987 : 0 : convert_wider_int_to_float (machine_mode mode, machine_mode imode, rtx x)
988 : : {
989 : 0 : gcc_assert (SCALAR_FLOAT_MODE_P (mode) && SCALAR_INT_MODE_P (imode));
990 : 0 : scalar_int_mode tmp_mode = int_mode_for_mode (mode).require ();
991 : 0 : rtx tmp = force_reg (tmp_mode, gen_lowpart (tmp_mode, x));
992 : 0 : return gen_lowpart_SUBREG (mode, tmp);
993 : : }
994 : :
995 : : /* Return the largest alignment we can use for doing a move (or store)
996 : : of MAX_PIECES. ALIGN is the largest alignment we could use. */
997 : :
998 : : static unsigned int
999 : 2530794 : alignment_for_piecewise_move (unsigned int max_pieces, unsigned int align)
1000 : : {
1001 : 2530794 : scalar_int_mode tmode
1002 : 2530794 : = int_mode_for_size (max_pieces * BITS_PER_UNIT, 0).require ();
1003 : :
1004 : 2530794 : if (align >= GET_MODE_ALIGNMENT (tmode))
1005 : 1980530 : align = GET_MODE_ALIGNMENT (tmode);
1006 : : else
1007 : : {
1008 : 550264 : scalar_int_mode xmode = NARROWEST_INT_MODE;
1009 : 550264 : opt_scalar_int_mode mode_iter;
1010 : 3310532 : FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_INT)
1011 : : {
1012 : 3306362 : tmode = mode_iter.require ();
1013 : 3306362 : if (GET_MODE_SIZE (tmode) > max_pieces
1014 : 3306362 : || targetm.slow_unaligned_access (tmode, align))
1015 : : break;
1016 : 2760268 : xmode = tmode;
1017 : : }
1018 : :
1019 : 550264 : align = MAX (align, GET_MODE_ALIGNMENT (xmode));
1020 : : }
1021 : :
1022 : 2530794 : return align;
1023 : : }
1024 : :
1025 : : /* Return true if we know how to implement OP using vectors of bytes. */
1026 : : static bool
1027 : 5412701 : can_use_qi_vectors (by_pieces_operation op)
1028 : : {
1029 : 5412701 : return (op == COMPARE_BY_PIECES
1030 : 5412701 : || op == SET_BY_PIECES
1031 : 5412701 : || op == CLEAR_BY_PIECES);
1032 : : }
1033 : :
1034 : : /* Return true if optabs exists for the mode and certain by pieces
1035 : : operations. */
1036 : : static bool
1037 : 23980229 : by_pieces_mode_supported_p (fixed_size_mode mode, by_pieces_operation op)
1038 : : {
1039 : 23980229 : if (optab_handler (mov_optab, mode) == CODE_FOR_nothing)
1040 : : return false;
1041 : :
1042 : 23123258 : if ((op == SET_BY_PIECES || op == CLEAR_BY_PIECES)
1043 : 499440 : && VECTOR_MODE_P (mode)
1044 : 23460382 : && optab_handler (vec_duplicate_optab, mode) == CODE_FOR_nothing)
1045 : : return false;
1046 : :
1047 : 23079408 : if (op == COMPARE_BY_PIECES
1048 : 23079408 : && !can_compare_p (EQ, mode, ccp_jump))
1049 : : return false;
1050 : :
1051 : : return true;
1052 : : }
1053 : :
1054 : : /* Return the widest mode that can be used to perform part of an
1055 : : operation OP on SIZE bytes. Try to use QI vector modes where
1056 : : possible. */
1057 : : static fixed_size_mode
1058 : 4934500 : widest_fixed_size_mode_for_size (unsigned int size, by_pieces_operation op)
1059 : : {
1060 : 4934500 : fixed_size_mode result = NARROWEST_INT_MODE;
1061 : :
1062 : 4934500 : gcc_checking_assert (size > 1);
1063 : :
1064 : : /* Use QI vector only if size is wider than a WORD. */
1065 : 4934500 : if (can_use_qi_vectors (op))
1066 : : {
1067 : 475369 : machine_mode mode;
1068 : 475369 : fixed_size_mode candidate;
1069 : 7623108 : FOR_EACH_MODE_IN_CLASS (mode, MODE_VECTOR_INT)
1070 : 7623108 : if (is_a<fixed_size_mode> (mode, &candidate)
1071 : 8651763 : && GET_MODE_SIZE (candidate) > UNITS_PER_WORD
1072 : 8152424 : && GET_MODE_INNER (candidate) == QImode)
1073 : : {
1074 : 3599334 : if (GET_MODE_SIZE (candidate) >= size)
1075 : : break;
1076 : 1324298 : if (by_pieces_mode_supported_p (candidate, op))
1077 : 7147739 : result = candidate;
1078 : : }
1079 : :
1080 : 475369 : if (result != NARROWEST_INT_MODE)
1081 : 281381 : return result;
1082 : : }
1083 : :
1084 : 4653119 : opt_scalar_int_mode tmode;
1085 : 4653119 : scalar_int_mode mode;
1086 : 37224952 : FOR_EACH_MODE_IN_CLASS (tmode, MODE_INT)
1087 : : {
1088 : 32571833 : mode = tmode.require ();
1089 : 32571833 : if (GET_MODE_SIZE (mode) < size
1090 : 32571833 : && by_pieces_mode_supported_p (mode, op))
1091 : 22618773 : result = mode;
1092 : : }
1093 : :
1094 : 4653119 : return result;
1095 : : }
1096 : :
1097 : : /* Determine whether an operation OP on LEN bytes with alignment ALIGN can
1098 : : and should be performed piecewise. */
1099 : :
1100 : : static bool
1101 : 925225 : can_do_by_pieces (unsigned HOST_WIDE_INT len, unsigned int align,
1102 : : enum by_pieces_operation op)
1103 : : {
1104 : 925225 : return targetm.use_by_pieces_infrastructure_p (len, align, op,
1105 : 925225 : optimize_insn_for_speed_p ());
1106 : : }
1107 : :
1108 : : /* Determine whether the LEN bytes can be moved by using several move
1109 : : instructions. Return nonzero if a call to move_by_pieces should
1110 : : succeed. */
1111 : :
1112 : : bool
1113 : 887964 : can_move_by_pieces (unsigned HOST_WIDE_INT len, unsigned int align)
1114 : : {
1115 : 887964 : return can_do_by_pieces (len, align, MOVE_BY_PIECES);
1116 : : }
1117 : :
1118 : : /* Return number of insns required to perform operation OP by pieces
1119 : : for L bytes. ALIGN (in bits) is maximum alignment we can assume. */
1120 : :
1121 : : unsigned HOST_WIDE_INT
1122 : 1792728 : by_pieces_ninsns (unsigned HOST_WIDE_INT l, unsigned int align,
1123 : : unsigned int max_size, by_pieces_operation op)
1124 : : {
1125 : 1792728 : unsigned HOST_WIDE_INT n_insns = 0;
1126 : 1792728 : fixed_size_mode mode;
1127 : :
1128 : 1792728 : if (targetm.overlap_op_by_pieces_p ())
1129 : : {
1130 : : /* NB: Round up L and ALIGN to the widest integer mode for
1131 : : MAX_SIZE. */
1132 : 1792728 : mode = widest_fixed_size_mode_for_size (max_size, op);
1133 : 1792728 : gcc_assert (optab_handler (mov_optab, mode) != CODE_FOR_nothing);
1134 : 3585456 : unsigned HOST_WIDE_INT up = ROUND_UP (l, GET_MODE_SIZE (mode));
1135 : 1792728 : if (up > l)
1136 : : l = up;
1137 : 1792728 : align = GET_MODE_ALIGNMENT (mode);
1138 : : }
1139 : :
1140 : 1792728 : align = alignment_for_piecewise_move (MOVE_MAX_PIECES, align);
1141 : :
1142 : 5396096 : while (max_size > 1 && l > 0)
1143 : : {
1144 : 1810640 : mode = widest_fixed_size_mode_for_size (max_size, op);
1145 : 1810640 : gcc_assert (optab_handler (mov_optab, mode) != CODE_FOR_nothing);
1146 : :
1147 : 1810640 : unsigned int modesize = GET_MODE_SIZE (mode);
1148 : :
1149 : 1810640 : if (align >= GET_MODE_ALIGNMENT (mode))
1150 : : {
1151 : 1810640 : unsigned HOST_WIDE_INT n_pieces = l / modesize;
1152 : 1810640 : l %= modesize;
1153 : 1810640 : switch (op)
1154 : : {
1155 : 1773379 : default:
1156 : 1773379 : n_insns += n_pieces;
1157 : 1773379 : break;
1158 : :
1159 : 37261 : case COMPARE_BY_PIECES:
1160 : 37261 : int batch = targetm.compare_by_pieces_branch_ratio (mode);
1161 : 37261 : int batch_ops = 4 * batch - 1;
1162 : 37261 : unsigned HOST_WIDE_INT full = n_pieces / batch;
1163 : 37261 : n_insns += full * batch_ops;
1164 : 37261 : if (n_pieces % batch != 0)
1165 : 0 : n_insns++;
1166 : : break;
1167 : :
1168 : : }
1169 : : }
1170 : : max_size = modesize;
1171 : : }
1172 : :
1173 : 1792728 : gcc_assert (!l);
1174 : 1792728 : return n_insns;
1175 : : }
1176 : :
1177 : : /* Used when performing piecewise block operations, holds information
1178 : : about one of the memory objects involved. The member functions
1179 : : can be used to generate code for loading from the object and
1180 : : updating the address when iterating. */
1181 : :
1182 : : class pieces_addr
1183 : : {
1184 : : /* The object being referenced, a MEM. Can be NULL_RTX to indicate
1185 : : stack pushes. */
1186 : : rtx m_obj;
1187 : : /* The address of the object. Can differ from that seen in the
1188 : : MEM rtx if we copied the address to a register. */
1189 : : rtx m_addr;
1190 : : /* Nonzero if the address on the object has an autoincrement already,
1191 : : signifies whether that was an increment or decrement. */
1192 : : signed char m_addr_inc;
1193 : : /* Nonzero if we intend to use autoinc without the address already
1194 : : having autoinc form. We will insert add insns around each memory
1195 : : reference, expecting later passes to form autoinc addressing modes.
1196 : : The only supported options are predecrement and postincrement. */
1197 : : signed char m_explicit_inc;
1198 : : /* True if we have either of the two possible cases of using
1199 : : autoincrement. */
1200 : : bool m_auto;
1201 : : /* True if this is an address to be used for load operations rather
1202 : : than stores. */
1203 : : bool m_is_load;
1204 : :
1205 : : /* Optionally, a function to obtain constants for any given offset into
1206 : : the objects, and data associated with it. */
1207 : : by_pieces_constfn m_constfn;
1208 : : void *m_cfndata;
1209 : : public:
1210 : : pieces_addr (rtx, bool, by_pieces_constfn, void *);
1211 : : rtx adjust (fixed_size_mode, HOST_WIDE_INT, by_pieces_prev * = nullptr);
1212 : : void increment_address (HOST_WIDE_INT);
1213 : : void maybe_predec (HOST_WIDE_INT);
1214 : : void maybe_postinc (HOST_WIDE_INT);
1215 : : void decide_autoinc (machine_mode, bool, HOST_WIDE_INT);
1216 : 688085 : int get_addr_inc ()
1217 : : {
1218 : 688085 : return m_addr_inc;
1219 : : }
1220 : : };
1221 : :
1222 : : /* Initialize a pieces_addr structure from an object OBJ. IS_LOAD is
1223 : : true if the operation to be performed on this object is a load
1224 : : rather than a store. For stores, OBJ can be NULL, in which case we
1225 : : assume the operation is a stack push. For loads, the optional
1226 : : CONSTFN and its associated CFNDATA can be used in place of the
1227 : : memory load. */
1228 : :
1229 : 1376170 : pieces_addr::pieces_addr (rtx obj, bool is_load, by_pieces_constfn constfn,
1230 : 1376170 : void *cfndata)
1231 : 1376170 : : m_obj (obj), m_is_load (is_load), m_constfn (constfn), m_cfndata (cfndata)
1232 : : {
1233 : 1376170 : m_addr_inc = 0;
1234 : 1376170 : m_auto = false;
1235 : 1376170 : if (obj)
1236 : : {
1237 : 1282673 : rtx addr = XEXP (obj, 0);
1238 : 1282673 : rtx_code code = GET_CODE (addr);
1239 : 1282673 : m_addr = addr;
1240 : 1282673 : bool dec = code == PRE_DEC || code == POST_DEC;
1241 : 1282673 : bool inc = code == PRE_INC || code == POST_INC;
1242 : 1282673 : m_auto = inc || dec;
1243 : 1282673 : if (m_auto)
1244 : 0 : m_addr_inc = dec ? -1 : 1;
1245 : :
1246 : : /* While we have always looked for these codes here, the code
1247 : : implementing the memory operation has never handled them.
1248 : : Support could be added later if necessary or beneficial. */
1249 : 1282673 : gcc_assert (code != PRE_INC && code != POST_DEC);
1250 : : }
1251 : : else
1252 : : {
1253 : 93497 : m_addr = NULL_RTX;
1254 : 93497 : if (!is_load)
1255 : : {
1256 : 45 : m_auto = true;
1257 : 45 : if (STACK_GROWS_DOWNWARD)
1258 : 45 : m_addr_inc = -1;
1259 : : else
1260 : : m_addr_inc = 1;
1261 : : }
1262 : : else
1263 : 93452 : gcc_assert (constfn != NULL);
1264 : : }
1265 : 1376170 : m_explicit_inc = 0;
1266 : 1376170 : if (constfn)
1267 : 115619 : gcc_assert (is_load);
1268 : 1376170 : }
1269 : :
1270 : : /* Decide whether to use autoinc for an address involved in a memory op.
1271 : : MODE is the mode of the accesses, REVERSE is true if we've decided to
1272 : : perform the operation starting from the end, and LEN is the length of
1273 : : the operation. Don't override an earlier decision to set m_auto. */
1274 : :
1275 : : void
1276 : 364068 : pieces_addr::decide_autoinc (machine_mode ARG_UNUSED (mode), bool reverse,
1277 : : HOST_WIDE_INT len)
1278 : : {
1279 : 364068 : if (m_auto || m_obj == NULL_RTX)
1280 : : return;
1281 : :
1282 : 341065 : bool use_predec = (m_is_load
1283 : : ? USE_LOAD_PRE_DECREMENT (mode)
1284 : : : USE_STORE_PRE_DECREMENT (mode));
1285 : 341065 : bool use_postinc = (m_is_load
1286 : : ? USE_LOAD_POST_INCREMENT (mode)
1287 : : : USE_STORE_POST_INCREMENT (mode));
1288 : 341065 : machine_mode addr_mode = get_address_mode (m_obj);
1289 : :
1290 : 341065 : if (use_predec && reverse)
1291 : : {
1292 : : m_addr = copy_to_mode_reg (addr_mode,
1293 : : plus_constant (addr_mode,
1294 : : m_addr, len));
1295 : : m_auto = true;
1296 : : m_explicit_inc = -1;
1297 : : }
1298 : 341065 : else if (use_postinc && !reverse)
1299 : : {
1300 : : m_addr = copy_to_mode_reg (addr_mode, m_addr);
1301 : : m_auto = true;
1302 : : m_explicit_inc = 1;
1303 : : }
1304 : 341065 : else if (CONSTANT_P (m_addr))
1305 : 70432 : m_addr = copy_to_mode_reg (addr_mode, m_addr);
1306 : : }
1307 : :
1308 : : /* Adjust the address to refer to the data at OFFSET in MODE. If we
1309 : : are using autoincrement for this address, we don't add the offset,
1310 : : but we still modify the MEM's properties. */
1311 : :
1312 : : rtx
1313 : 3884812 : pieces_addr::adjust (fixed_size_mode mode, HOST_WIDE_INT offset,
1314 : : by_pieces_prev *prev)
1315 : : {
1316 : 3884812 : if (m_constfn)
1317 : : /* Pass the previous data to m_constfn. */
1318 : 272246 : return m_constfn (m_cfndata, prev, offset, mode);
1319 : 3612566 : if (m_obj == NULL_RTX)
1320 : : return NULL_RTX;
1321 : 3612519 : if (m_auto)
1322 : 0 : return adjust_automodify_address (m_obj, mode, m_addr, offset);
1323 : : else
1324 : 3612519 : return adjust_address (m_obj, mode, offset);
1325 : : }
1326 : :
1327 : : /* Emit an add instruction to increment the address by SIZE. */
1328 : :
1329 : : void
1330 : 0 : pieces_addr::increment_address (HOST_WIDE_INT size)
1331 : : {
1332 : 0 : rtx amount = gen_int_mode (size, GET_MODE (m_addr));
1333 : 0 : emit_insn (gen_add2_insn (m_addr, amount));
1334 : 0 : }
1335 : :
1336 : : /* If we are supposed to decrement the address after each access, emit code
1337 : : to do so now. Increment by SIZE (which has should have the correct sign
1338 : : already). */
1339 : :
1340 : : void
1341 : 3884276 : pieces_addr::maybe_predec (HOST_WIDE_INT size)
1342 : : {
1343 : 3884276 : if (m_explicit_inc >= 0)
1344 : 3884276 : return;
1345 : 0 : gcc_assert (HAVE_PRE_DECREMENT);
1346 : : increment_address (size);
1347 : : }
1348 : :
1349 : : /* If we are supposed to decrement the address after each access, emit code
1350 : : to do so now. Increment by SIZE. */
1351 : :
1352 : : void
1353 : 3884299 : pieces_addr::maybe_postinc (HOST_WIDE_INT size)
1354 : : {
1355 : 3884299 : if (m_explicit_inc <= 0)
1356 : 3884299 : return;
1357 : 0 : gcc_assert (HAVE_POST_INCREMENT);
1358 : : increment_address (size);
1359 : : }
1360 : :
1361 : : /* This structure is used by do_op_by_pieces to describe the operation
1362 : : to be performed. */
1363 : :
1364 : : class op_by_pieces_d
1365 : : {
1366 : : private:
1367 : : fixed_size_mode get_usable_mode (fixed_size_mode, unsigned int);
1368 : : fixed_size_mode smallest_fixed_size_mode_for_size (unsigned int);
1369 : :
1370 : : protected:
1371 : : pieces_addr m_to, m_from;
1372 : : /* Make m_len read-only so that smallest_fixed_size_mode_for_size can
1373 : : use it to check the valid mode size. */
1374 : : const unsigned HOST_WIDE_INT m_len;
1375 : : HOST_WIDE_INT m_offset;
1376 : : unsigned int m_align;
1377 : : unsigned int m_max_size;
1378 : : bool m_reverse;
1379 : : /* True if this is a stack push. */
1380 : : bool m_push;
1381 : : /* True if targetm.overlap_op_by_pieces_p () returns true. */
1382 : : bool m_overlap_op_by_pieces;
1383 : : /* The type of operation that we're performing. */
1384 : : by_pieces_operation m_op;
1385 : :
1386 : : /* Virtual functions, overriden by derived classes for the specific
1387 : : operation. */
1388 : : virtual void generate (rtx, rtx, machine_mode) = 0;
1389 : : virtual bool prepare_mode (machine_mode, unsigned int) = 0;
1390 : 1105043 : virtual void finish_mode (machine_mode)
1391 : : {
1392 : 1105043 : }
1393 : :
1394 : : public:
1395 : : op_by_pieces_d (unsigned int, rtx, bool, rtx, bool, by_pieces_constfn,
1396 : : void *, unsigned HOST_WIDE_INT, unsigned int, bool,
1397 : : by_pieces_operation);
1398 : : void run ();
1399 : : };
1400 : :
1401 : : /* The constructor for an op_by_pieces_d structure. We require two
1402 : : objects named TO and FROM, which are identified as loads or stores
1403 : : by TO_LOAD and FROM_LOAD. If FROM is a load, the optional FROM_CFN
1404 : : and its associated FROM_CFN_DATA can be used to replace loads with
1405 : : constant values. MAX_PIECES describes the maximum number of bytes
1406 : : at a time which can be moved efficiently. LEN describes the length
1407 : : of the operation. */
1408 : :
1409 : 688085 : op_by_pieces_d::op_by_pieces_d (unsigned int max_pieces, rtx to,
1410 : : bool to_load, rtx from, bool from_load,
1411 : : by_pieces_constfn from_cfn,
1412 : : void *from_cfn_data,
1413 : : unsigned HOST_WIDE_INT len,
1414 : : unsigned int align, bool push,
1415 : 688085 : by_pieces_operation op)
1416 : 688085 : : m_to (to, to_load, NULL, NULL),
1417 : 688085 : m_from (from, from_load, from_cfn, from_cfn_data),
1418 : 688085 : m_len (len), m_max_size (max_pieces + 1),
1419 : 688085 : m_push (push), m_op (op)
1420 : : {
1421 : 688085 : int toi = m_to.get_addr_inc ();
1422 : 688085 : int fromi = m_from.get_addr_inc ();
1423 : 688085 : if (toi >= 0 && fromi >= 0)
1424 : 688040 : m_reverse = false;
1425 : 45 : else if (toi <= 0 && fromi <= 0)
1426 : 45 : m_reverse = true;
1427 : : else
1428 : 0 : gcc_unreachable ();
1429 : :
1430 : 688085 : m_offset = m_reverse ? len : 0;
1431 : 2565397 : align = MIN (to ? MEM_ALIGN (to) : align,
1432 : : from ? MEM_ALIGN (from) : align);
1433 : :
1434 : : /* If copying requires more than two move insns,
1435 : : copy addresses to registers (to make displacements shorter)
1436 : : and use post-increment if available. */
1437 : 688085 : if (by_pieces_ninsns (len, align, m_max_size, MOVE_BY_PIECES) > 2)
1438 : : {
1439 : : /* Find the mode of the largest comparison. */
1440 : 182034 : fixed_size_mode mode
1441 : 182034 : = widest_fixed_size_mode_for_size (m_max_size, m_op);
1442 : :
1443 : 182034 : m_from.decide_autoinc (mode, m_reverse, len);
1444 : 182034 : m_to.decide_autoinc (mode, m_reverse, len);
1445 : : }
1446 : :
1447 : 688085 : align = alignment_for_piecewise_move (MOVE_MAX_PIECES, align);
1448 : 688085 : m_align = align;
1449 : :
1450 : 688085 : m_overlap_op_by_pieces = targetm.overlap_op_by_pieces_p ();
1451 : 688085 : }
1452 : :
1453 : : /* This function returns the largest usable integer mode for LEN bytes
1454 : : whose size is no bigger than size of MODE. */
1455 : :
1456 : : fixed_size_mode
1457 : 1166286 : op_by_pieces_d::get_usable_mode (fixed_size_mode mode, unsigned int len)
1458 : : {
1459 : 1439067 : unsigned int size;
1460 : 1711848 : do
1461 : : {
1462 : 1439067 : size = GET_MODE_SIZE (mode);
1463 : 1439067 : if (len >= size && prepare_mode (mode, m_align))
1464 : : break;
1465 : : /* widest_fixed_size_mode_for_size checks SIZE > 1. */
1466 : 272781 : mode = widest_fixed_size_mode_for_size (size, m_op);
1467 : : }
1468 : : while (1);
1469 : 1166286 : return mode;
1470 : : }
1471 : :
1472 : : /* Return the smallest integer or QI vector mode that is not narrower
1473 : : than SIZE bytes. */
1474 : :
1475 : : fixed_size_mode
1476 : 478201 : op_by_pieces_d::smallest_fixed_size_mode_for_size (unsigned int size)
1477 : : {
1478 : : /* Use QI vector only for > size of WORD. */
1479 : 489621 : if (can_use_qi_vectors (m_op) && size > UNITS_PER_WORD)
1480 : : {
1481 : 6710 : machine_mode mode;
1482 : 6710 : fixed_size_mode candidate;
1483 : 91429 : FOR_EACH_MODE_IN_CLASS (mode, MODE_VECTOR_INT)
1484 : 91429 : if (is_a<fixed_size_mode> (mode, &candidate)
1485 : 182858 : && GET_MODE_INNER (candidate) == QImode)
1486 : : {
1487 : : /* Don't return a mode wider than M_LEN. */
1488 : 84626 : if (GET_MODE_SIZE (candidate) > m_len)
1489 : : break;
1490 : :
1491 : 40662 : if (GET_MODE_SIZE (candidate) >= size
1492 : 40662 : && by_pieces_mode_supported_p (candidate, m_op))
1493 : 5059 : return candidate;
1494 : : }
1495 : : }
1496 : :
1497 : 473142 : return smallest_int_mode_for_size (size * BITS_PER_UNIT).require ();
1498 : : }
1499 : :
1500 : : /* This function contains the main loop used for expanding a block
1501 : : operation. First move what we can in the largest integer mode,
1502 : : then go to successively smaller modes. For every access, call
1503 : : GENFUN with the two operands and the EXTRA_DATA. */
1504 : :
1505 : : void
1506 : 688085 : op_by_pieces_d::run ()
1507 : : {
1508 : 688085 : if (m_len == 0)
1509 : : return;
1510 : :
1511 : 688085 : unsigned HOST_WIDE_INT length = m_len;
1512 : :
1513 : : /* widest_fixed_size_mode_for_size checks M_MAX_SIZE > 1. */
1514 : 688085 : fixed_size_mode mode
1515 : 688085 : = widest_fixed_size_mode_for_size (m_max_size, m_op);
1516 : 688085 : mode = get_usable_mode (mode, length);
1517 : :
1518 : 688085 : by_pieces_prev to_prev = { nullptr, mode };
1519 : 688085 : by_pieces_prev from_prev = { nullptr, mode };
1520 : :
1521 : 1166286 : do
1522 : : {
1523 : 1166286 : unsigned int size = GET_MODE_SIZE (mode);
1524 : 1166286 : rtx to1 = NULL_RTX, from1;
1525 : :
1526 : 3108424 : while (length >= size)
1527 : : {
1528 : 1942138 : if (m_reverse)
1529 : 47 : m_offset -= size;
1530 : :
1531 : 1942138 : to1 = m_to.adjust (mode, m_offset, &to_prev);
1532 : 1942138 : to_prev.data = to1;
1533 : 1942138 : to_prev.mode = mode;
1534 : 1942138 : from1 = m_from.adjust (mode, m_offset, &from_prev);
1535 : 1942138 : from_prev.data = from1;
1536 : 1942138 : from_prev.mode = mode;
1537 : :
1538 : 1942138 : m_to.maybe_predec (-(HOST_WIDE_INT)size);
1539 : 1942138 : m_from.maybe_predec (-(HOST_WIDE_INT)size);
1540 : :
1541 : 1942138 : generate (to1, from1, mode);
1542 : :
1543 : 1942138 : m_to.maybe_postinc (size);
1544 : 1942138 : m_from.maybe_postinc (size);
1545 : :
1546 : 1942138 : if (!m_reverse)
1547 : 1942091 : m_offset += size;
1548 : :
1549 : 1942138 : length -= size;
1550 : : }
1551 : :
1552 : 1166286 : finish_mode (mode);
1553 : :
1554 : 1166286 : if (length == 0)
1555 : : return;
1556 : :
1557 : 478201 : if (!m_push && m_overlap_op_by_pieces)
1558 : : {
1559 : : /* NB: Generate overlapping operations if it is not a stack
1560 : : push since stack push must not overlap. Get the smallest
1561 : : fixed size mode for M_LEN bytes. */
1562 : 478201 : mode = smallest_fixed_size_mode_for_size (length);
1563 : 956402 : mode = get_usable_mode (mode, GET_MODE_SIZE (mode));
1564 : 478201 : int gap = GET_MODE_SIZE (mode) - length;
1565 : 478201 : if (gap > 0)
1566 : : {
1567 : : /* If size of MODE > M_LEN, generate the last operation
1568 : : in MODE for the remaining bytes with ovelapping memory
1569 : : from the previois operation. */
1570 : 43809 : if (m_reverse)
1571 : 0 : m_offset += gap;
1572 : : else
1573 : 43809 : m_offset -= gap;
1574 : 43809 : length += gap;
1575 : : }
1576 : : }
1577 : : else
1578 : : {
1579 : : /* widest_fixed_size_mode_for_size checks SIZE > 1. */
1580 : 0 : mode = widest_fixed_size_mode_for_size (size, m_op);
1581 : 0 : mode = get_usable_mode (mode, length);
1582 : : }
1583 : : }
1584 : : while (1);
1585 : : }
1586 : :
1587 : : /* Derived class from op_by_pieces_d, providing support for block move
1588 : : operations. */
1589 : :
1590 : : #ifdef PUSH_ROUNDING
1591 : : #define PUSHG_P(to) ((to) == nullptr)
1592 : : #else
1593 : : #define PUSHG_P(to) false
1594 : : #endif
1595 : :
1596 : : class move_by_pieces_d : public op_by_pieces_d
1597 : : {
1598 : : insn_gen_fn m_gen_fun;
1599 : : void generate (rtx, rtx, machine_mode) final override;
1600 : : bool prepare_mode (machine_mode, unsigned int) final override;
1601 : :
1602 : : public:
1603 : 560501 : move_by_pieces_d (rtx to, rtx from, unsigned HOST_WIDE_INT len,
1604 : : unsigned int align)
1605 : 560501 : : op_by_pieces_d (MOVE_MAX_PIECES, to, false, from, true, NULL,
1606 : 1121002 : NULL, len, align, PUSHG_P (to), MOVE_BY_PIECES)
1607 : : {
1608 : 560501 : }
1609 : : rtx finish_retmode (memop_ret);
1610 : : };
1611 : :
1612 : : /* Return true if MODE can be used for a set of copies, given an
1613 : : alignment ALIGN. Prepare whatever data is necessary for later
1614 : : calls to generate. */
1615 : :
1616 : : bool
1617 : 948633 : move_by_pieces_d::prepare_mode (machine_mode mode, unsigned int align)
1618 : : {
1619 : 948633 : insn_code icode = optab_handler (mov_optab, mode);
1620 : 948633 : m_gen_fun = GEN_FCN (icode);
1621 : 948633 : return icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode);
1622 : : }
1623 : :
1624 : : /* A callback used when iterating for a compare_by_pieces_operation.
1625 : : OP0 and OP1 are the values that have been loaded and should be
1626 : : compared in MODE. If OP0 is NULL, this means we should generate a
1627 : : push; otherwise EXTRA_DATA holds a pointer to a pointer to the insn
1628 : : gen function that should be used to generate the mode. */
1629 : :
1630 : : void
1631 : 1650186 : move_by_pieces_d::generate (rtx op0, rtx op1,
1632 : : machine_mode mode ATTRIBUTE_UNUSED)
1633 : : {
1634 : : #ifdef PUSH_ROUNDING
1635 : 1650186 : if (op0 == NULL_RTX)
1636 : : {
1637 : 47 : emit_single_push_insn (mode, op1, NULL);
1638 : 47 : return;
1639 : : }
1640 : : #endif
1641 : 1650139 : emit_insn (m_gen_fun (op0, op1));
1642 : : }
1643 : :
1644 : : /* Perform the final adjustment at the end of a string to obtain the
1645 : : correct return value for the block operation.
1646 : : Return value is based on RETMODE argument. */
1647 : :
1648 : : rtx
1649 : 0 : move_by_pieces_d::finish_retmode (memop_ret retmode)
1650 : : {
1651 : 0 : gcc_assert (!m_reverse);
1652 : 0 : if (retmode == RETURN_END_MINUS_ONE)
1653 : : {
1654 : 0 : m_to.maybe_postinc (-1);
1655 : 0 : --m_offset;
1656 : : }
1657 : 0 : return m_to.adjust (QImode, m_offset);
1658 : : }
1659 : :
1660 : : /* Generate several move instructions to copy LEN bytes from block FROM to
1661 : : block TO. (These are MEM rtx's with BLKmode).
1662 : :
1663 : : If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
1664 : : used to push FROM to the stack.
1665 : :
1666 : : ALIGN is maximum stack alignment we can assume.
1667 : :
1668 : : Return value is based on RETMODE argument. */
1669 : :
1670 : : rtx
1671 : 560501 : move_by_pieces (rtx to, rtx from, unsigned HOST_WIDE_INT len,
1672 : : unsigned int align, memop_ret retmode)
1673 : : {
1674 : : #ifndef PUSH_ROUNDING
1675 : : if (to == NULL)
1676 : : gcc_unreachable ();
1677 : : #endif
1678 : :
1679 : 560501 : move_by_pieces_d data (to, from, len, align);
1680 : :
1681 : 560501 : data.run ();
1682 : :
1683 : 560501 : if (retmode != RETURN_BEGIN)
1684 : 0 : return data.finish_retmode (retmode);
1685 : : else
1686 : : return to;
1687 : : }
1688 : :
1689 : : /* Derived class from op_by_pieces_d, providing support for block move
1690 : : operations. */
1691 : :
1692 : : class store_by_pieces_d : public op_by_pieces_d
1693 : : {
1694 : : insn_gen_fn m_gen_fun;
1695 : :
1696 : : void generate (rtx, rtx, machine_mode) final override;
1697 : : bool prepare_mode (machine_mode, unsigned int) final override;
1698 : :
1699 : : public:
1700 : 93452 : store_by_pieces_d (rtx to, by_pieces_constfn cfn, void *cfn_data,
1701 : : unsigned HOST_WIDE_INT len, unsigned int align,
1702 : : by_pieces_operation op)
1703 : 93452 : : op_by_pieces_d (STORE_MAX_PIECES, to, false, NULL_RTX, true, cfn,
1704 : 186904 : cfn_data, len, align, false, op)
1705 : : {
1706 : 93452 : }
1707 : : rtx finish_retmode (memop_ret);
1708 : : };
1709 : :
1710 : : /* Return true if MODE can be used for a set of stores, given an
1711 : : alignment ALIGN. Prepare whatever data is necessary for later
1712 : : calls to generate. */
1713 : :
1714 : : bool
1715 : 156410 : store_by_pieces_d::prepare_mode (machine_mode mode, unsigned int align)
1716 : : {
1717 : 156410 : insn_code icode = optab_handler (mov_optab, mode);
1718 : 156410 : m_gen_fun = GEN_FCN (icode);
1719 : 156410 : return icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode);
1720 : : }
1721 : :
1722 : : /* A callback used when iterating for a store_by_pieces_operation.
1723 : : OP0 and OP1 are the values that have been loaded and should be
1724 : : compared in MODE. If OP0 is NULL, this means we should generate a
1725 : : push; otherwise EXTRA_DATA holds a pointer to a pointer to the insn
1726 : : gen function that should be used to generate the mode. */
1727 : :
1728 : : void
1729 : 227840 : store_by_pieces_d::generate (rtx op0, rtx op1, machine_mode)
1730 : : {
1731 : 227840 : emit_insn (m_gen_fun (op0, op1));
1732 : 227840 : }
1733 : :
1734 : : /* Perform the final adjustment at the end of a string to obtain the
1735 : : correct return value for the block operation.
1736 : : Return value is based on RETMODE argument. */
1737 : :
1738 : : rtx
1739 : 536 : store_by_pieces_d::finish_retmode (memop_ret retmode)
1740 : : {
1741 : 536 : gcc_assert (!m_reverse);
1742 : 536 : if (retmode == RETURN_END_MINUS_ONE)
1743 : : {
1744 : 23 : m_to.maybe_postinc (-1);
1745 : 23 : --m_offset;
1746 : : }
1747 : 536 : return m_to.adjust (QImode, m_offset);
1748 : : }
1749 : :
1750 : : /* Determine whether the LEN bytes generated by CONSTFUN can be
1751 : : stored to memory using several move instructions. CONSTFUNDATA is
1752 : : a pointer which will be passed as argument in every CONSTFUN call.
1753 : : ALIGN is maximum alignment we can assume. MEMSETP is true if this is
1754 : : a memset operation and false if it's a copy of a constant string.
1755 : : Return true if a call to store_by_pieces should succeed. */
1756 : :
1757 : : bool
1758 : 66534 : can_store_by_pieces (unsigned HOST_WIDE_INT len,
1759 : : by_pieces_constfn constfun,
1760 : : void *constfundata, unsigned int align, bool memsetp)
1761 : : {
1762 : 66534 : unsigned HOST_WIDE_INT l;
1763 : 66534 : unsigned int max_size;
1764 : 66534 : HOST_WIDE_INT offset = 0;
1765 : 66534 : enum insn_code icode;
1766 : 66534 : int reverse;
1767 : : /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
1768 : 66534 : rtx cst ATTRIBUTE_UNUSED;
1769 : :
1770 : 66534 : if (len == 0)
1771 : : return true;
1772 : :
1773 : 110625 : if (!targetm.use_by_pieces_infrastructure_p (len, align,
1774 : : memsetp
1775 : : ? SET_BY_PIECES
1776 : : : STORE_BY_PIECES,
1777 : 66490 : optimize_insn_for_speed_p ()))
1778 : : return false;
1779 : :
1780 : 49981 : align = alignment_for_piecewise_move (STORE_MAX_PIECES, align);
1781 : :
1782 : : /* We would first store what we can in the largest integer mode, then go to
1783 : : successively smaller modes. */
1784 : :
1785 : 49981 : for (reverse = 0;
1786 : 99962 : reverse <= (HAVE_PRE_DECREMENT || HAVE_POST_DECREMENT);
1787 : : reverse++)
1788 : : {
1789 : 49981 : l = len;
1790 : 49981 : max_size = STORE_MAX_PIECES + 1;
1791 : 238213 : while (max_size > 1 && l > 0)
1792 : : {
1793 : 188232 : auto op = memsetp ? SET_BY_PIECES : STORE_BY_PIECES;
1794 : 188232 : auto mode = widest_fixed_size_mode_for_size (max_size, op);
1795 : :
1796 : 188232 : icode = optab_handler (mov_optab, mode);
1797 : 188232 : if (icode != CODE_FOR_nothing
1798 : 188232 : && align >= GET_MODE_ALIGNMENT (mode))
1799 : : {
1800 : 188232 : unsigned int size = GET_MODE_SIZE (mode);
1801 : :
1802 : 324657 : while (l >= size)
1803 : : {
1804 : 136425 : if (reverse)
1805 : : offset -= size;
1806 : :
1807 : 136425 : cst = (*constfun) (constfundata, nullptr, offset, mode);
1808 : : /* All CONST_VECTORs can be loaded for memset since
1809 : : vec_duplicate_optab is a precondition to pick a
1810 : : vector mode for the memset expander. */
1811 : 260229 : if (!((memsetp && VECTOR_MODE_P (mode))
1812 : 123804 : || targetm.legitimate_constant_p (mode, cst)))
1813 : 16509 : return false;
1814 : :
1815 : 136425 : if (!reverse)
1816 : 136425 : offset += size;
1817 : :
1818 : 136425 : l -= size;
1819 : : }
1820 : : }
1821 : :
1822 : 376464 : max_size = GET_MODE_SIZE (mode);
1823 : : }
1824 : :
1825 : : /* The code above should have handled everything. */
1826 : 49981 : gcc_assert (!l);
1827 : : }
1828 : :
1829 : : return true;
1830 : : }
1831 : :
1832 : : /* Generate several move instructions to store LEN bytes generated by
1833 : : CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
1834 : : pointer which will be passed as argument in every CONSTFUN call.
1835 : : ALIGN is maximum alignment we can assume. MEMSETP is true if this is
1836 : : a memset operation and false if it's a copy of a constant string.
1837 : : Return value is based on RETMODE argument. */
1838 : :
1839 : : rtx
1840 : 47478 : store_by_pieces (rtx to, unsigned HOST_WIDE_INT len,
1841 : : by_pieces_constfn constfun,
1842 : : void *constfundata, unsigned int align, bool memsetp,
1843 : : memop_ret retmode)
1844 : : {
1845 : 47478 : if (len == 0)
1846 : : {
1847 : 43 : gcc_assert (retmode != RETURN_END_MINUS_ONE);
1848 : : return to;
1849 : : }
1850 : :
1851 : 87771 : gcc_assert (targetm.use_by_pieces_infrastructure_p
1852 : : (len, align,
1853 : : memsetp ? SET_BY_PIECES : STORE_BY_PIECES,
1854 : : optimize_insn_for_speed_p ()));
1855 : :
1856 : 47435 : store_by_pieces_d data (to, constfun, constfundata, len, align,
1857 : 47435 : memsetp ? SET_BY_PIECES : STORE_BY_PIECES);
1858 : 47435 : data.run ();
1859 : :
1860 : 47435 : if (retmode != RETURN_BEGIN)
1861 : 536 : return data.finish_retmode (retmode);
1862 : : else
1863 : : return to;
1864 : : }
1865 : :
1866 : : void
1867 : 46017 : clear_by_pieces (rtx to, unsigned HOST_WIDE_INT len, unsigned int align)
1868 : : {
1869 : 46017 : if (len == 0)
1870 : 0 : return;
1871 : :
1872 : : /* Use builtin_memset_read_str to support vector mode broadcast. */
1873 : 46017 : char c = 0;
1874 : 46017 : store_by_pieces_d data (to, builtin_memset_read_str, &c, len, align,
1875 : 46017 : CLEAR_BY_PIECES);
1876 : 46017 : data.run ();
1877 : : }
1878 : :
1879 : : /* Context used by compare_by_pieces_genfn. It stores the fail label
1880 : : to jump to in case of miscomparison, and for branch ratios greater than 1,
1881 : : it stores an accumulator and the current and maximum counts before
1882 : : emitting another branch. */
1883 : :
1884 : : class compare_by_pieces_d : public op_by_pieces_d
1885 : : {
1886 : : rtx_code_label *m_fail_label;
1887 : : rtx m_accumulator;
1888 : : int m_count, m_batch;
1889 : :
1890 : : void generate (rtx, rtx, machine_mode) final override;
1891 : : bool prepare_mode (machine_mode, unsigned int) final override;
1892 : : void finish_mode (machine_mode) final override;
1893 : :
1894 : : public:
1895 : 34132 : compare_by_pieces_d (rtx op0, rtx op1, by_pieces_constfn op1_cfn,
1896 : : void *op1_cfn_data, HOST_WIDE_INT len, int align,
1897 : : rtx_code_label *fail_label)
1898 : 34132 : : op_by_pieces_d (COMPARE_MAX_PIECES, op0, true, op1, true, op1_cfn,
1899 : 68264 : op1_cfn_data, len, align, false, COMPARE_BY_PIECES)
1900 : : {
1901 : 34132 : m_fail_label = fail_label;
1902 : 34132 : }
1903 : : };
1904 : :
1905 : : /* A callback used when iterating for a compare_by_pieces_operation.
1906 : : OP0 and OP1 are the values that have been loaded and should be
1907 : : compared in MODE. DATA holds a pointer to the compare_by_pieces_data
1908 : : context structure. */
1909 : :
1910 : : void
1911 : 64112 : compare_by_pieces_d::generate (rtx op0, rtx op1, machine_mode mode)
1912 : : {
1913 : 64112 : if (m_batch > 1)
1914 : : {
1915 : 0 : rtx temp = expand_binop (mode, sub_optab, op0, op1, NULL_RTX,
1916 : : true, OPTAB_LIB_WIDEN);
1917 : 0 : if (m_count != 0)
1918 : 0 : temp = expand_binop (mode, ior_optab, m_accumulator, temp, temp,
1919 : : true, OPTAB_LIB_WIDEN);
1920 : 0 : m_accumulator = temp;
1921 : :
1922 : 0 : if (++m_count < m_batch)
1923 : : return;
1924 : :
1925 : 0 : m_count = 0;
1926 : 0 : op0 = m_accumulator;
1927 : 0 : op1 = const0_rtx;
1928 : 0 : m_accumulator = NULL_RTX;
1929 : : }
1930 : 64112 : do_compare_rtx_and_jump (op0, op1, NE, true, mode, NULL_RTX, NULL,
1931 : : m_fail_label, profile_probability::uninitialized ());
1932 : : }
1933 : :
1934 : : /* Return true if MODE can be used for a set of moves and comparisons,
1935 : : given an alignment ALIGN. Prepare whatever data is necessary for
1936 : : later calls to generate. */
1937 : :
1938 : : bool
1939 : 61243 : compare_by_pieces_d::prepare_mode (machine_mode mode, unsigned int align)
1940 : : {
1941 : 61243 : insn_code icode = optab_handler (mov_optab, mode);
1942 : 61243 : if (icode == CODE_FOR_nothing
1943 : 61243 : || align < GET_MODE_ALIGNMENT (mode)
1944 : 122486 : || !can_compare_p (EQ, mode, ccp_jump))
1945 : 0 : return false;
1946 : 61243 : m_batch = targetm.compare_by_pieces_branch_ratio (mode);
1947 : 61243 : if (m_batch < 0)
1948 : : return false;
1949 : 61243 : m_accumulator = NULL_RTX;
1950 : 61243 : m_count = 0;
1951 : 61243 : return true;
1952 : : }
1953 : :
1954 : : /* Called after expanding a series of comparisons in MODE. If we have
1955 : : accumulated results for which we haven't emitted a branch yet, do
1956 : : so now. */
1957 : :
1958 : : void
1959 : 61243 : compare_by_pieces_d::finish_mode (machine_mode mode)
1960 : : {
1961 : 61243 : if (m_accumulator != NULL_RTX)
1962 : 0 : do_compare_rtx_and_jump (m_accumulator, const0_rtx, NE, true, mode,
1963 : : NULL_RTX, NULL, m_fail_label,
1964 : : profile_probability::uninitialized ());
1965 : 61243 : }
1966 : :
1967 : : /* Generate several move instructions to compare LEN bytes from blocks
1968 : : ARG0 and ARG1. (These are MEM rtx's with BLKmode).
1969 : :
1970 : : If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
1971 : : used to push FROM to the stack.
1972 : :
1973 : : ALIGN is maximum stack alignment we can assume.
1974 : :
1975 : : Optionally, the caller can pass a constfn and associated data in A1_CFN
1976 : : and A1_CFN_DATA. describing that the second operand being compared is a
1977 : : known constant and how to obtain its data. */
1978 : :
1979 : : static rtx
1980 : 34132 : compare_by_pieces (rtx arg0, rtx arg1, unsigned HOST_WIDE_INT len,
1981 : : rtx target, unsigned int align,
1982 : : by_pieces_constfn a1_cfn, void *a1_cfn_data)
1983 : : {
1984 : 34132 : rtx_code_label *fail_label = gen_label_rtx ();
1985 : 34132 : rtx_code_label *end_label = gen_label_rtx ();
1986 : :
1987 : 34132 : if (target == NULL_RTX
1988 : 34132 : || !REG_P (target) || REGNO (target) < FIRST_PSEUDO_REGISTER)
1989 : 1 : target = gen_reg_rtx (TYPE_MODE (integer_type_node));
1990 : :
1991 : 34132 : compare_by_pieces_d data (arg0, arg1, a1_cfn, a1_cfn_data, len, align,
1992 : 34132 : fail_label);
1993 : :
1994 : 34132 : data.run ();
1995 : :
1996 : 34132 : emit_move_insn (target, const0_rtx);
1997 : 34132 : emit_jump (end_label);
1998 : 34132 : emit_barrier ();
1999 : 34132 : emit_label (fail_label);
2000 : 34132 : emit_move_insn (target, const1_rtx);
2001 : 34132 : emit_label (end_label);
2002 : :
2003 : 34132 : return target;
2004 : : }
2005 : :
2006 : : /* Emit code to move a block Y to a block X. This may be done with
2007 : : string-move instructions, with multiple scalar move instructions,
2008 : : or with a library call.
2009 : :
2010 : : Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
2011 : : SIZE is an rtx that says how long they are.
2012 : : ALIGN is the maximum alignment we can assume they have.
2013 : : METHOD describes what kind of copy this is, and what mechanisms may be used.
2014 : : MIN_SIZE is the minimal size of block to move
2015 : : MAX_SIZE is the maximal size of block to move, if it cannot be represented
2016 : : in unsigned HOST_WIDE_INT, than it is mask of all ones.
2017 : : CTZ_SIZE is the trailing-zeros count of SIZE; even a nonconstant SIZE is
2018 : : known to be a multiple of 1<<CTZ_SIZE.
2019 : :
2020 : : Return the address of the new block, if memcpy is called and returns it,
2021 : : 0 otherwise. */
2022 : :
2023 : : rtx
2024 : 648161 : emit_block_move_hints (rtx x, rtx y, rtx size, enum block_op_methods method,
2025 : : unsigned int expected_align, HOST_WIDE_INT expected_size,
2026 : : unsigned HOST_WIDE_INT min_size,
2027 : : unsigned HOST_WIDE_INT max_size,
2028 : : unsigned HOST_WIDE_INT probable_max_size,
2029 : : bool bail_out_libcall, bool *is_move_done,
2030 : : bool might_overlap, unsigned ctz_size)
2031 : : {
2032 : 648161 : int may_use_call;
2033 : 648161 : rtx retval = 0;
2034 : 648161 : unsigned int align;
2035 : :
2036 : 648161 : if (is_move_done)
2037 : 77706 : *is_move_done = true;
2038 : :
2039 : 648161 : gcc_assert (size);
2040 : 648161 : if (CONST_INT_P (size) && INTVAL (size) == 0)
2041 : : return 0;
2042 : :
2043 : 647884 : switch (method)
2044 : : {
2045 : : case BLOCK_OP_NORMAL:
2046 : : case BLOCK_OP_TAILCALL:
2047 : : may_use_call = 1;
2048 : : break;
2049 : :
2050 : 266484 : case BLOCK_OP_CALL_PARM:
2051 : 266484 : may_use_call = block_move_libcall_safe_for_call_parm ();
2052 : :
2053 : : /* Make inhibit_defer_pop nonzero around the library call
2054 : : to force it to pop the arguments right away. */
2055 : 266484 : NO_DEFER_POP;
2056 : 266484 : break;
2057 : :
2058 : 353 : case BLOCK_OP_NO_LIBCALL:
2059 : 353 : may_use_call = 0;
2060 : 353 : break;
2061 : :
2062 : 1061 : case BLOCK_OP_NO_LIBCALL_RET:
2063 : 1061 : may_use_call = -1;
2064 : 1061 : break;
2065 : :
2066 : 0 : default:
2067 : 0 : gcc_unreachable ();
2068 : : }
2069 : :
2070 : 647884 : gcc_assert (MEM_P (x) && MEM_P (y));
2071 : 647967 : align = MIN (MEM_ALIGN (x), MEM_ALIGN (y));
2072 : 647884 : gcc_assert (align >= BITS_PER_UNIT);
2073 : :
2074 : : /* Make sure we've got BLKmode addresses; store_one_arg can decide that
2075 : : block copy is more efficient for other large modes, e.g. DCmode. */
2076 : 647884 : x = adjust_address (x, BLKmode, 0);
2077 : 647884 : y = adjust_address (y, BLKmode, 0);
2078 : :
2079 : : /* If source and destination are the same, no need to copy anything. */
2080 : 647884 : if (rtx_equal_p (x, y)
2081 : 10 : && !MEM_VOLATILE_P (x)
2082 : 647894 : && !MEM_VOLATILE_P (y))
2083 : : return 0;
2084 : :
2085 : : /* Set MEM_SIZE as appropriate for this block copy. The main place this
2086 : : can be incorrect is coming from __builtin_memcpy. */
2087 : 647874 : poly_int64 const_size;
2088 : 647874 : if (poly_int_rtx_p (size, &const_size))
2089 : : {
2090 : 586403 : x = shallow_copy_rtx (x);
2091 : 586403 : y = shallow_copy_rtx (y);
2092 : 586403 : set_mem_size (x, const_size);
2093 : 586403 : set_mem_size (y, const_size);
2094 : : }
2095 : :
2096 : 647874 : bool pieces_ok = CONST_INT_P (size)
2097 : 647874 : && can_move_by_pieces (INTVAL (size), align);
2098 : 647874 : bool pattern_ok = false;
2099 : :
2100 : 647874 : if (!pieces_ok || might_overlap)
2101 : : {
2102 : 87418 : pattern_ok
2103 : 87418 : = emit_block_move_via_pattern (x, y, size, align,
2104 : : expected_align, expected_size,
2105 : : min_size, max_size, probable_max_size,
2106 : : might_overlap);
2107 : 87418 : if (!pattern_ok && might_overlap)
2108 : : {
2109 : : /* Do not try any of the other methods below as they are not safe
2110 : : for overlapping moves. */
2111 : 15521 : *is_move_done = false;
2112 : 15521 : return retval;
2113 : : }
2114 : : }
2115 : :
2116 : 71897 : bool dynamic_direction = false;
2117 : 71897 : if (!pattern_ok && !pieces_ok && may_use_call
2118 : 76560 : && (flag_inline_stringops & (might_overlap ? ILSOP_MEMMOVE : ILSOP_MEMCPY)))
2119 : : {
2120 : 632353 : may_use_call = 0;
2121 : 632353 : dynamic_direction = might_overlap;
2122 : : }
2123 : :
2124 : 632353 : if (pattern_ok)
2125 : : ;
2126 : 598736 : else if (pieces_ok)
2127 : 560456 : move_by_pieces (x, y, INTVAL (size), align, RETURN_BEGIN);
2128 : 38280 : else if (may_use_call && !might_overlap
2129 : 38232 : && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x))
2130 : 76512 : && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y)))
2131 : : {
2132 : 38232 : if (bail_out_libcall)
2133 : : {
2134 : 254 : if (is_move_done)
2135 : 254 : *is_move_done = false;
2136 : 254 : return retval;
2137 : : }
2138 : :
2139 : 37978 : if (may_use_call < 0)
2140 : 0 : return pc_rtx;
2141 : :
2142 : 37978 : retval = emit_block_copy_via_libcall (x, y, size,
2143 : : method == BLOCK_OP_TAILCALL);
2144 : : }
2145 : 48 : else if (dynamic_direction)
2146 : 0 : emit_block_move_via_oriented_loop (x, y, size, align, ctz_size);
2147 : 48 : else if (might_overlap)
2148 : 0 : *is_move_done = false;
2149 : : else
2150 : 48 : emit_block_move_via_sized_loop (x, y, size, align, ctz_size);
2151 : :
2152 : 632099 : if (method == BLOCK_OP_CALL_PARM)
2153 : 266476 : OK_DEFER_POP;
2154 : :
2155 : : return retval;
2156 : : }
2157 : :
2158 : : rtx
2159 : 570455 : emit_block_move (rtx x, rtx y, rtx size, enum block_op_methods method,
2160 : : unsigned int ctz_size)
2161 : : {
2162 : 570455 : unsigned HOST_WIDE_INT max, min = 0;
2163 : 570455 : if (GET_CODE (size) == CONST_INT)
2164 : 570235 : min = max = UINTVAL (size);
2165 : : else
2166 : 220 : max = GET_MODE_MASK (GET_MODE (size));
2167 : 570455 : return emit_block_move_hints (x, y, size, method, 0, -1,
2168 : : min, max, max,
2169 : 570455 : false, NULL, false, ctz_size);
2170 : : }
2171 : :
2172 : : /* A subroutine of emit_block_move. Returns true if calling the
2173 : : block move libcall will not clobber any parameters which may have
2174 : : already been placed on the stack. */
2175 : :
2176 : : static bool
2177 : 266484 : block_move_libcall_safe_for_call_parm (void)
2178 : : {
2179 : 266484 : tree fn;
2180 : :
2181 : : /* If arguments are pushed on the stack, then they're safe. */
2182 : 266484 : if (targetm.calls.push_argument (0))
2183 : : return true;
2184 : :
2185 : : /* If registers go on the stack anyway, any argument is sure to clobber
2186 : : an outgoing argument. */
2187 : : #if defined (REG_PARM_STACK_SPACE)
2188 : 3 : fn = builtin_decl_implicit (BUILT_IN_MEMCPY);
2189 : : /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
2190 : : depend on its argument. */
2191 : 3 : (void) fn;
2192 : 3 : if (OUTGOING_REG_PARM_STACK_SPACE ((!fn ? NULL_TREE : TREE_TYPE (fn)))
2193 : 3 : && REG_PARM_STACK_SPACE (fn) != 0)
2194 : : return false;
2195 : : #endif
2196 : :
2197 : : /* If any argument goes in memory, then it might clobber an outgoing
2198 : : argument. */
2199 : 3 : {
2200 : 3 : CUMULATIVE_ARGS args_so_far_v;
2201 : 3 : cumulative_args_t args_so_far;
2202 : 3 : tree arg;
2203 : :
2204 : 3 : fn = builtin_decl_implicit (BUILT_IN_MEMCPY);
2205 : 3 : INIT_CUMULATIVE_ARGS (args_so_far_v, TREE_TYPE (fn), NULL_RTX, 0, 3);
2206 : 3 : args_so_far = pack_cumulative_args (&args_so_far_v);
2207 : :
2208 : 3 : arg = TYPE_ARG_TYPES (TREE_TYPE (fn));
2209 : 12 : for ( ; arg != void_list_node ; arg = TREE_CHAIN (arg))
2210 : : {
2211 : 9 : machine_mode mode = TYPE_MODE (TREE_VALUE (arg));
2212 : 9 : function_arg_info arg_info (mode, /*named=*/true);
2213 : 9 : rtx tmp = targetm.calls.function_arg (args_so_far, arg_info);
2214 : 9 : if (!tmp || !REG_P (tmp))
2215 : 0 : return false;
2216 : 9 : if (targetm.calls.arg_partial_bytes (args_so_far, arg_info))
2217 : : return false;
2218 : 9 : targetm.calls.function_arg_advance (args_so_far, arg_info);
2219 : : }
2220 : : }
2221 : 3 : return true;
2222 : : }
2223 : :
2224 : : /* A subroutine of emit_block_move. Expand a cpymem or movmem pattern;
2225 : : return true if successful.
2226 : :
2227 : : X is the destination of the copy or move.
2228 : : Y is the source of the copy or move.
2229 : : SIZE is the size of the block to be moved.
2230 : :
2231 : : MIGHT_OVERLAP indicates this originated with expansion of a
2232 : : builtin_memmove() and the source and destination blocks may
2233 : : overlap.
2234 : : */
2235 : :
2236 : : static bool
2237 : 87418 : emit_block_move_via_pattern (rtx x, rtx y, rtx size, unsigned int align,
2238 : : unsigned int expected_align,
2239 : : HOST_WIDE_INT expected_size,
2240 : : unsigned HOST_WIDE_INT min_size,
2241 : : unsigned HOST_WIDE_INT max_size,
2242 : : unsigned HOST_WIDE_INT probable_max_size,
2243 : : bool might_overlap)
2244 : : {
2245 : 87418 : if (expected_align < align)
2246 : : expected_align = align;
2247 : 87418 : if (expected_size != -1)
2248 : : {
2249 : 12 : if ((unsigned HOST_WIDE_INT)expected_size > probable_max_size)
2250 : 0 : expected_size = probable_max_size;
2251 : 12 : if ((unsigned HOST_WIDE_INT)expected_size < min_size)
2252 : 0 : expected_size = min_size;
2253 : : }
2254 : :
2255 : : /* Since this is a move insn, we don't care about volatility. */
2256 : 87418 : temporary_volatile_ok v (true);
2257 : :
2258 : : /* Try the most limited insn first, because there's no point
2259 : : including more than one in the machine description unless
2260 : : the more limited one has some advantage. */
2261 : :
2262 : 87418 : opt_scalar_int_mode mode_iter;
2263 : 533351 : FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_INT)
2264 : : {
2265 : 479550 : scalar_int_mode mode = mode_iter.require ();
2266 : 479550 : enum insn_code code;
2267 : 479550 : if (might_overlap)
2268 : 108647 : code = direct_optab_handler (movmem_optab, mode);
2269 : : else
2270 : 370903 : code = direct_optab_handler (cpymem_optab, mode);
2271 : :
2272 : 479550 : if (code != CODE_FOR_nothing
2273 : : /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
2274 : : here because if SIZE is less than the mode mask, as it is
2275 : : returned by the macro, it will definitely be less than the
2276 : : actual mode mask. Since SIZE is within the Pmode address
2277 : : space, we limit MODE to Pmode. */
2278 : 479550 : && ((CONST_INT_P (size)
2279 : 24406 : && ((unsigned HOST_WIDE_INT) INTVAL (size)
2280 : 24406 : <= (GET_MODE_MASK (mode) >> 1)))
2281 : 86316 : || max_size <= (GET_MODE_MASK (mode) >> 1)
2282 : 118334 : || GET_MODE_BITSIZE (mode) >= GET_MODE_BITSIZE (Pmode)))
2283 : : {
2284 : 73700 : class expand_operand ops[9];
2285 : 73700 : unsigned int nops;
2286 : :
2287 : : /* ??? When called via emit_block_move_for_call, it'd be
2288 : : nice if there were some way to inform the backend, so
2289 : : that it doesn't fail the expansion because it thinks
2290 : : emitting the libcall would be more efficient. */
2291 : 73700 : nops = insn_data[(int) code].n_generator_args;
2292 : 73700 : gcc_assert (nops == 4 || nops == 6 || nops == 8 || nops == 9);
2293 : :
2294 : 73700 : create_fixed_operand (&ops[0], x);
2295 : 73700 : create_fixed_operand (&ops[1], y);
2296 : : /* The check above guarantees that this size conversion is valid. */
2297 : 73700 : create_convert_operand_to (&ops[2], size, mode, true);
2298 : 73700 : create_integer_operand (&ops[3], align / BITS_PER_UNIT);
2299 : 73700 : if (nops >= 6)
2300 : : {
2301 : 73700 : create_integer_operand (&ops[4], expected_align / BITS_PER_UNIT);
2302 : 73700 : create_integer_operand (&ops[5], expected_size);
2303 : : }
2304 : 73700 : if (nops >= 8)
2305 : : {
2306 : 73700 : create_integer_operand (&ops[6], min_size);
2307 : : /* If we cannot represent the maximal size,
2308 : : make parameter NULL. */
2309 : 73700 : if ((HOST_WIDE_INT) max_size != -1)
2310 : 54493 : create_integer_operand (&ops[7], max_size);
2311 : : else
2312 : 19207 : create_fixed_operand (&ops[7], NULL);
2313 : : }
2314 : 73700 : if (nops == 9)
2315 : : {
2316 : : /* If we cannot represent the maximal size,
2317 : : make parameter NULL. */
2318 : 73700 : if ((HOST_WIDE_INT) probable_max_size != -1)
2319 : 55866 : create_integer_operand (&ops[8], probable_max_size);
2320 : : else
2321 : 17834 : create_fixed_operand (&ops[8], NULL);
2322 : : }
2323 : 73700 : if (maybe_expand_insn (code, nops, ops))
2324 : 33617 : return true;
2325 : : }
2326 : : }
2327 : :
2328 : : return false;
2329 : 87418 : }
2330 : :
2331 : : /* Like emit_block_move_via_loop, but choose a suitable INCR based on
2332 : : ALIGN and CTZ_SIZE. */
2333 : :
2334 : : static void
2335 : 48 : emit_block_move_via_sized_loop (rtx x, rtx y, rtx size,
2336 : : unsigned int align,
2337 : : unsigned int ctz_size)
2338 : : {
2339 : 48 : int incr = align / BITS_PER_UNIT;
2340 : :
2341 : 48 : if (CONST_INT_P (size))
2342 : 0 : ctz_size = MAX (ctz_size, (unsigned) wi::ctz (UINTVAL (size)));
2343 : :
2344 : 48 : if (HOST_WIDE_INT_1U << ctz_size < (unsigned HOST_WIDE_INT) incr)
2345 : 0 : incr = HOST_WIDE_INT_1U << ctz_size;
2346 : :
2347 : 48 : while (incr > 1 && !can_move_by_pieces (incr, align))
2348 : 0 : incr >>= 1;
2349 : :
2350 : 48 : gcc_checking_assert (incr);
2351 : :
2352 : 48 : return emit_block_move_via_loop (x, y, size, align, incr);
2353 : : }
2354 : :
2355 : : /* Like emit_block_move_via_sized_loop, but besides choosing INCR so
2356 : : as to ensure safe moves even in case of overlap, output dynamic
2357 : : tests to choose between two loops, one moving downwards, another
2358 : : moving upwards. */
2359 : :
2360 : : static void
2361 : 0 : emit_block_move_via_oriented_loop (rtx x, rtx y, rtx size,
2362 : : unsigned int align,
2363 : : unsigned int ctz_size)
2364 : : {
2365 : 0 : int incr = align / BITS_PER_UNIT;
2366 : :
2367 : 0 : if (CONST_INT_P (size))
2368 : 0 : ctz_size = MAX (ctz_size, (unsigned) wi::ctz (UINTVAL (size)));
2369 : :
2370 : 0 : if (HOST_WIDE_INT_1U << ctz_size < (unsigned HOST_WIDE_INT) incr)
2371 : 0 : incr = HOST_WIDE_INT_1U << ctz_size;
2372 : :
2373 : 0 : while (incr > 1 && !int_mode_for_size (incr, 0).exists ())
2374 : 0 : incr >>= 1;
2375 : :
2376 : 0 : gcc_checking_assert (incr);
2377 : :
2378 : 0 : rtx_code_label *upw_label, *end_label;
2379 : 0 : upw_label = gen_label_rtx ();
2380 : 0 : end_label = gen_label_rtx ();
2381 : :
2382 : 0 : rtx x_addr = force_operand (XEXP (x, 0), NULL_RTX);
2383 : 0 : rtx y_addr = force_operand (XEXP (y, 0), NULL_RTX);
2384 : 0 : do_pending_stack_adjust ();
2385 : :
2386 : 0 : machine_mode mode = GET_MODE (x_addr);
2387 : 0 : if (mode != GET_MODE (y_addr))
2388 : : {
2389 : 0 : scalar_int_mode xmode
2390 : 0 : = smallest_int_mode_for_size (GET_MODE_BITSIZE (mode)).require ();
2391 : 0 : scalar_int_mode ymode
2392 : 0 : = smallest_int_mode_for_size (GET_MODE_BITSIZE
2393 : 0 : (GET_MODE (y_addr))).require ();
2394 : 0 : if (GET_MODE_BITSIZE (xmode) < GET_MODE_BITSIZE (ymode))
2395 : : mode = ymode;
2396 : : else
2397 : 0 : mode = xmode;
2398 : :
2399 : : #ifndef POINTERS_EXTEND_UNSIGNED
2400 : : const int POINTERS_EXTEND_UNSIGNED = 1;
2401 : : #endif
2402 : 0 : x_addr = convert_modes (mode, GET_MODE (x_addr), x_addr,
2403 : : POINTERS_EXTEND_UNSIGNED);
2404 : 0 : y_addr = convert_modes (mode, GET_MODE (y_addr), y_addr,
2405 : : POINTERS_EXTEND_UNSIGNED);
2406 : : }
2407 : :
2408 : : /* Test for overlap: if (x >= y || x + size <= y) goto upw_label. */
2409 : 0 : emit_cmp_and_jump_insns (x_addr, y_addr, GEU, NULL_RTX, mode,
2410 : : true, upw_label,
2411 : 0 : profile_probability::guessed_always ()
2412 : : .apply_scale (5, 10));
2413 : 0 : rtx tmp = convert_modes (GET_MODE (x_addr), GET_MODE (size), size, true);
2414 : 0 : tmp = simplify_gen_binary (PLUS, GET_MODE (x_addr), x_addr, tmp);
2415 : :
2416 : 0 : emit_cmp_and_jump_insns (tmp, y_addr, LEU, NULL_RTX, mode,
2417 : : true, upw_label,
2418 : 0 : profile_probability::guessed_always ()
2419 : : .apply_scale (8, 10));
2420 : :
2421 : 0 : emit_block_move_via_loop (x, y, size, align, -incr);
2422 : :
2423 : 0 : emit_jump (end_label);
2424 : 0 : emit_label (upw_label);
2425 : :
2426 : 0 : emit_block_move_via_loop (x, y, size, align, incr);
2427 : :
2428 : 0 : emit_label (end_label);
2429 : 0 : }
2430 : :
2431 : : /* A subroutine of emit_block_move. Copy the data via an explicit
2432 : : loop. This is used only when libcalls are forbidden, or when
2433 : : inlining is required. INCR is the block size to be copied in each
2434 : : loop iteration. If it is negative, the absolute value is used, and
2435 : : the block is copied backwards. INCR must be a power of two, an
2436 : : exact divisor for SIZE and ALIGN, and imply a mode that can be
2437 : : safely copied per iteration assuming no overlap. */
2438 : :
2439 : : static void
2440 : 48 : emit_block_move_via_loop (rtx x, rtx y, rtx size,
2441 : : unsigned int align, int incr)
2442 : : {
2443 : 48 : rtx_code_label *cmp_label, *top_label;
2444 : 48 : rtx iter, x_addr, y_addr, tmp;
2445 : 48 : machine_mode x_addr_mode = get_address_mode (x);
2446 : 48 : machine_mode y_addr_mode = get_address_mode (y);
2447 : 48 : machine_mode iter_mode;
2448 : :
2449 : 48 : iter_mode = GET_MODE (size);
2450 : 48 : if (iter_mode == VOIDmode)
2451 : 0 : iter_mode = word_mode;
2452 : :
2453 : 48 : top_label = gen_label_rtx ();
2454 : 48 : cmp_label = gen_label_rtx ();
2455 : 48 : iter = gen_reg_rtx (iter_mode);
2456 : :
2457 : 48 : bool downwards = incr < 0;
2458 : 48 : rtx iter_init;
2459 : 48 : rtx_code iter_cond;
2460 : 48 : rtx iter_limit;
2461 : 48 : rtx iter_incr;
2462 : 48 : machine_mode move_mode;
2463 : 48 : if (downwards)
2464 : : {
2465 : 0 : incr = -incr;
2466 : 0 : iter_init = size;
2467 : 0 : iter_cond = GEU;
2468 : 0 : iter_limit = const0_rtx;
2469 : 0 : iter_incr = GEN_INT (incr);
2470 : : }
2471 : : else
2472 : : {
2473 : 48 : iter_init = const0_rtx;
2474 : 48 : iter_cond = LTU;
2475 : 48 : iter_limit = size;
2476 : 48 : iter_incr = GEN_INT (incr);
2477 : : }
2478 : 48 : emit_move_insn (iter, iter_init);
2479 : :
2480 : 48 : opt_scalar_int_mode int_move_mode
2481 : 48 : = int_mode_for_size (incr * BITS_PER_UNIT, 1);
2482 : 48 : if (!int_move_mode.exists (&move_mode)
2483 : 96 : || GET_MODE_BITSIZE (int_move_mode.require ()) != incr * BITS_PER_UNIT)
2484 : : {
2485 : 0 : move_mode = BLKmode;
2486 : 0 : gcc_checking_assert (can_move_by_pieces (incr, align));
2487 : : }
2488 : :
2489 : 48 : x_addr = force_operand (XEXP (x, 0), NULL_RTX);
2490 : 48 : y_addr = force_operand (XEXP (y, 0), NULL_RTX);
2491 : 48 : do_pending_stack_adjust ();
2492 : :
2493 : 48 : emit_jump (cmp_label);
2494 : 48 : emit_label (top_label);
2495 : :
2496 : 48 : tmp = convert_modes (x_addr_mode, iter_mode, iter, true);
2497 : 48 : x_addr = simplify_gen_binary (PLUS, x_addr_mode, x_addr, tmp);
2498 : :
2499 : 48 : if (x_addr_mode != y_addr_mode)
2500 : 0 : tmp = convert_modes (y_addr_mode, iter_mode, iter, true);
2501 : 48 : y_addr = simplify_gen_binary (PLUS, y_addr_mode, y_addr, tmp);
2502 : :
2503 : 48 : x = change_address (x, move_mode, x_addr);
2504 : 48 : y = change_address (y, move_mode, y_addr);
2505 : :
2506 : 48 : if (move_mode == BLKmode)
2507 : : {
2508 : 0 : bool done;
2509 : 0 : emit_block_move_hints (x, y, iter_incr, BLOCK_OP_NO_LIBCALL,
2510 : : align, incr, incr, incr, incr,
2511 : : false, &done, false);
2512 : 0 : gcc_checking_assert (done);
2513 : : }
2514 : : else
2515 : 48 : emit_move_insn (x, y);
2516 : :
2517 : 48 : if (downwards)
2518 : 0 : emit_label (cmp_label);
2519 : :
2520 : 48 : tmp = expand_simple_binop (iter_mode, PLUS, iter, iter_incr, iter,
2521 : : true, OPTAB_LIB_WIDEN);
2522 : 48 : if (tmp != iter)
2523 : 0 : emit_move_insn (iter, tmp);
2524 : :
2525 : 48 : if (!downwards)
2526 : 48 : emit_label (cmp_label);
2527 : :
2528 : 48 : emit_cmp_and_jump_insns (iter, iter_limit, iter_cond, NULL_RTX, iter_mode,
2529 : : true, top_label,
2530 : 48 : profile_probability::guessed_always ()
2531 : : .apply_scale (9, 10));
2532 : 48 : }
2533 : :
2534 : : /* Expand a call to memcpy or memmove or memcmp, and return the result.
2535 : : TAILCALL is true if this is a tail call. */
2536 : :
2537 : : rtx
2538 : 37981 : emit_block_op_via_libcall (enum built_in_function fncode, rtx dst, rtx src,
2539 : : rtx size, bool tailcall)
2540 : : {
2541 : 37981 : rtx dst_addr, src_addr;
2542 : 37981 : tree call_expr, dst_tree, src_tree, size_tree;
2543 : 37981 : machine_mode size_mode;
2544 : :
2545 : : /* Since dst and src are passed to a libcall, mark the corresponding
2546 : : tree EXPR as addressable. */
2547 : 37981 : tree dst_expr = MEM_EXPR (dst);
2548 : 37981 : tree src_expr = MEM_EXPR (src);
2549 : 37981 : if (dst_expr)
2550 : 37676 : mark_addressable (dst_expr);
2551 : 37981 : if (src_expr)
2552 : 37943 : mark_addressable (src_expr);
2553 : :
2554 : 37981 : dst_addr = copy_addr_to_reg (XEXP (dst, 0));
2555 : 37981 : dst_addr = convert_memory_address (ptr_mode, dst_addr);
2556 : 37981 : dst_tree = make_tree (ptr_type_node, dst_addr);
2557 : :
2558 : 37981 : src_addr = copy_addr_to_reg (XEXP (src, 0));
2559 : 37981 : src_addr = convert_memory_address (ptr_mode, src_addr);
2560 : 37981 : src_tree = make_tree (ptr_type_node, src_addr);
2561 : :
2562 : 37981 : size_mode = TYPE_MODE (sizetype);
2563 : 37981 : size = convert_to_mode (size_mode, size, 1);
2564 : 37981 : size = copy_to_mode_reg (size_mode, size);
2565 : 37981 : size_tree = make_tree (sizetype, size);
2566 : :
2567 : : /* It is incorrect to use the libcall calling conventions for calls to
2568 : : memcpy/memmove/memcmp because they can be provided by the user. */
2569 : 37981 : tree fn = builtin_decl_implicit (fncode);
2570 : 37981 : call_expr = build_call_expr (fn, 3, dst_tree, src_tree, size_tree);
2571 : 37981 : CALL_EXPR_TAILCALL (call_expr) = tailcall;
2572 : :
2573 : 37981 : return expand_call (call_expr, NULL_RTX, false);
2574 : : }
2575 : :
2576 : : /* Try to expand cmpstrn or cmpmem operation ICODE with the given operands.
2577 : : ARG3_TYPE is the type of ARG3_RTX. Return the result rtx on success,
2578 : : otherwise return null. */
2579 : :
2580 : : rtx
2581 : 204602 : expand_cmpstrn_or_cmpmem (insn_code icode, rtx target, rtx arg1_rtx,
2582 : : rtx arg2_rtx, tree arg3_type, rtx arg3_rtx,
2583 : : HOST_WIDE_INT align)
2584 : : {
2585 : 204602 : machine_mode insn_mode = insn_data[icode].operand[0].mode;
2586 : :
2587 : 204602 : if (target && (!REG_P (target) || HARD_REGISTER_P (target)))
2588 : : target = NULL_RTX;
2589 : :
2590 : 204602 : class expand_operand ops[5];
2591 : 204602 : create_output_operand (&ops[0], target, insn_mode);
2592 : 204602 : create_fixed_operand (&ops[1], arg1_rtx);
2593 : 204602 : create_fixed_operand (&ops[2], arg2_rtx);
2594 : 204602 : create_convert_operand_from (&ops[3], arg3_rtx, TYPE_MODE (arg3_type),
2595 : 204602 : TYPE_UNSIGNED (arg3_type));
2596 : 204602 : create_integer_operand (&ops[4], align);
2597 : 204602 : if (maybe_expand_insn (icode, 5, ops))
2598 : 5772 : return ops[0].value;
2599 : : return NULL_RTX;
2600 : : }
2601 : :
2602 : : /* Expand a block compare between X and Y with length LEN using the
2603 : : cmpmem optab, placing the result in TARGET. LEN_TYPE is the type
2604 : : of the expression that was used to calculate the length. ALIGN
2605 : : gives the known minimum common alignment. */
2606 : :
2607 : : static rtx
2608 : 76672 : emit_block_cmp_via_cmpmem (rtx x, rtx y, rtx len, tree len_type, rtx target,
2609 : : unsigned align)
2610 : : {
2611 : : /* Note: The cmpstrnsi pattern, if it exists, is not suitable for
2612 : : implementing memcmp because it will stop if it encounters two
2613 : : zero bytes. */
2614 : 76672 : insn_code icode = direct_optab_handler (cmpmem_optab, SImode);
2615 : :
2616 : 76672 : if (icode == CODE_FOR_nothing)
2617 : : return NULL_RTX;
2618 : :
2619 : 76672 : return expand_cmpstrn_or_cmpmem (icode, target, x, y, len_type, len, align);
2620 : : }
2621 : :
2622 : : /* Emit code to compare a block Y to a block X. This may be done with
2623 : : string-compare instructions, with multiple scalar instructions,
2624 : : or with a library call.
2625 : :
2626 : : Both X and Y must be MEM rtx's. LEN is an rtx that says how long
2627 : : they are. LEN_TYPE is the type of the expression that was used to
2628 : : calculate it, and CTZ_LEN is the known trailing-zeros count of LEN,
2629 : : so LEN must be a multiple of 1<<CTZ_LEN even if it's not constant.
2630 : :
2631 : : If EQUALITY_ONLY is true, it means we don't have to return the tri-state
2632 : : value of a normal memcmp call, instead we can just compare for equality.
2633 : : If FORCE_LIBCALL is true, we should emit a call to memcmp rather than
2634 : : returning NULL_RTX.
2635 : :
2636 : : Optionally, the caller can pass a constfn and associated data in Y_CFN
2637 : : and Y_CFN_DATA. describing that the second operand being compared is a
2638 : : known constant and how to obtain its data.
2639 : : Return the result of the comparison, or NULL_RTX if we failed to
2640 : : perform the operation. */
2641 : :
2642 : : rtx
2643 : 110809 : emit_block_cmp_hints (rtx x, rtx y, rtx len, tree len_type, rtx target,
2644 : : bool equality_only, by_pieces_constfn y_cfn,
2645 : : void *y_cfndata, unsigned ctz_len)
2646 : : {
2647 : 110809 : rtx result = 0;
2648 : :
2649 : 110809 : if (CONST_INT_P (len) && INTVAL (len) == 0)
2650 : 6 : return const0_rtx;
2651 : :
2652 : 110803 : gcc_assert (MEM_P (x) && MEM_P (y));
2653 : 110803 : unsigned int align = MIN (MEM_ALIGN (x), MEM_ALIGN (y));
2654 : 110803 : gcc_assert (align >= BITS_PER_UNIT);
2655 : :
2656 : 110803 : x = adjust_address (x, BLKmode, 0);
2657 : 110803 : y = adjust_address (y, BLKmode, 0);
2658 : :
2659 : 110803 : if (equality_only
2660 : 57545 : && CONST_INT_P (len)
2661 : 148018 : && can_do_by_pieces (INTVAL (len), align, COMPARE_BY_PIECES))
2662 : 34131 : result = compare_by_pieces (x, y, INTVAL (len), target, align,
2663 : : y_cfn, y_cfndata);
2664 : : else
2665 : 76672 : result = emit_block_cmp_via_cmpmem (x, y, len, len_type, target, align);
2666 : :
2667 : 110803 : if (!result && (flag_inline_stringops & ILSOP_MEMCMP))
2668 : 361 : result = emit_block_cmp_via_loop (x, y, len, len_type,
2669 : : target, equality_only,
2670 : : align, ctz_len);
2671 : :
2672 : : return result;
2673 : : }
2674 : :
2675 : : /* Like emit_block_cmp_hints, but with known alignment and no support
2676 : : for constats. Always expand to a loop with iterations that compare
2677 : : blocks of the largest compare-by-pieces size that divides both len
2678 : : and align, and then, if !EQUALITY_ONLY, identify the word and then
2679 : : the unit that first differs to return the result. */
2680 : :
2681 : : rtx
2682 : 403 : emit_block_cmp_via_loop (rtx x, rtx y, rtx len, tree len_type, rtx target,
2683 : : bool equality_only, unsigned align, unsigned ctz_len)
2684 : : {
2685 : 403 : unsigned incr = align / BITS_PER_UNIT;
2686 : :
2687 : 403 : if (CONST_INT_P (len))
2688 : 319 : ctz_len = MAX (ctz_len, (unsigned) wi::ctz (UINTVAL (len)));
2689 : :
2690 : 403 : if (HOST_WIDE_INT_1U << ctz_len < (unsigned HOST_WIDE_INT) incr)
2691 : 148 : incr = HOST_WIDE_INT_1U << ctz_len;
2692 : :
2693 : : while (incr > 1
2694 : 407 : && !can_do_by_pieces (incr, align, COMPARE_BY_PIECES))
2695 : 4 : incr >>= 1;
2696 : :
2697 : 403 : rtx_code_label *cmp_label, *top_label, *ne_label, *res_label;
2698 : 403 : rtx iter, x_addr, y_addr, tmp;
2699 : 403 : machine_mode x_addr_mode = get_address_mode (x);
2700 : 403 : machine_mode y_addr_mode = get_address_mode (y);
2701 : 403 : machine_mode iter_mode;
2702 : :
2703 : 403 : iter_mode = GET_MODE (len);
2704 : 403 : if (iter_mode == VOIDmode)
2705 : 319 : iter_mode = word_mode;
2706 : :
2707 : 403 : rtx iter_init = const0_rtx;
2708 : 403 : rtx_code iter_cond = LTU;
2709 : 403 : rtx_code entry_cond = GEU;
2710 : 403 : rtx iter_limit = len;
2711 : 403 : rtx iter_incr = GEN_INT (incr);
2712 : 403 : machine_mode cmp_mode;
2713 : :
2714 : : /* We can drop the loop back edge if we know there's exactly one
2715 : : iteration. */
2716 : 403 : top_label = (!rtx_equal_p (len, iter_incr)
2717 : 403 : ? gen_label_rtx ()
2718 : : : NULL);
2719 : : /* We need not test before entering the loop if len is known
2720 : : nonzero. ??? This could be even stricter, testing whether a
2721 : : nonconstant LEN could possibly be zero. */
2722 : 319 : cmp_label = (!CONSTANT_P (len) || rtx_equal_p (len, iter_init)
2723 : 403 : ? gen_label_rtx ()
2724 : : : NULL);
2725 : 403 : ne_label = gen_label_rtx ();
2726 : 403 : res_label = gen_label_rtx ();
2727 : :
2728 : 403 : iter = gen_reg_rtx (iter_mode);
2729 : 403 : emit_move_insn (iter, iter_init);
2730 : :
2731 : 403 : opt_scalar_int_mode int_cmp_mode
2732 : 403 : = int_mode_for_size (incr * BITS_PER_UNIT, 1);
2733 : 403 : if (!int_cmp_mode.exists (&cmp_mode)
2734 : 1206 : || GET_MODE_BITSIZE (int_cmp_mode.require ()) != incr * BITS_PER_UNIT
2735 : 402 : || !can_compare_p (NE, cmp_mode, ccp_jump))
2736 : : {
2737 : 1 : cmp_mode = BLKmode;
2738 : 1 : gcc_checking_assert (incr != 1);
2739 : : }
2740 : :
2741 : : /* Save the base addresses. */
2742 : 403 : x_addr = force_operand (XEXP (x, 0), NULL_RTX);
2743 : 403 : y_addr = force_operand (XEXP (y, 0), NULL_RTX);
2744 : 403 : do_pending_stack_adjust ();
2745 : :
2746 : 403 : if (cmp_label)
2747 : : {
2748 : 84 : if (top_label)
2749 : 84 : emit_jump (cmp_label);
2750 : : else
2751 : 0 : emit_cmp_and_jump_insns (iter, iter_limit, entry_cond,
2752 : : NULL_RTX, iter_mode,
2753 : : true, cmp_label,
2754 : 0 : profile_probability::guessed_always ()
2755 : : .apply_scale (1, 10));
2756 : : }
2757 : 403 : if (top_label)
2758 : 386 : emit_label (top_label);
2759 : :
2760 : : /* Offset the base addresses by ITER. */
2761 : 403 : tmp = convert_modes (x_addr_mode, iter_mode, iter, true);
2762 : 403 : x_addr = simplify_gen_binary (PLUS, x_addr_mode, x_addr, tmp);
2763 : :
2764 : 403 : if (x_addr_mode != y_addr_mode)
2765 : 0 : tmp = convert_modes (y_addr_mode, iter_mode, iter, true);
2766 : 403 : y_addr = simplify_gen_binary (PLUS, y_addr_mode, y_addr, tmp);
2767 : :
2768 : 403 : x = change_address (x, cmp_mode, x_addr);
2769 : 403 : y = change_address (y, cmp_mode, y_addr);
2770 : :
2771 : : /* Compare one block. */
2772 : 403 : rtx part_res;
2773 : 403 : if (cmp_mode == BLKmode)
2774 : 1 : part_res = compare_by_pieces (x, y, incr, target, align, 0, 0);
2775 : : else
2776 : 402 : part_res = expand_binop (cmp_mode, sub_optab, x, y, NULL_RTX,
2777 : : true, OPTAB_LIB_WIDEN);
2778 : :
2779 : : /* Stop if we found a difference. */
2780 : 806 : emit_cmp_and_jump_insns (part_res, GEN_INT (0), NE, NULL_RTX,
2781 : 403 : GET_MODE (part_res), true, ne_label,
2782 : 403 : profile_probability::guessed_always ()
2783 : : .apply_scale (1, 10));
2784 : :
2785 : : /* Increment ITER. */
2786 : 403 : tmp = expand_simple_binop (iter_mode, PLUS, iter, iter_incr, iter,
2787 : : true, OPTAB_LIB_WIDEN);
2788 : 403 : if (tmp != iter)
2789 : 0 : emit_move_insn (iter, tmp);
2790 : :
2791 : 403 : if (cmp_label)
2792 : 84 : emit_label (cmp_label);
2793 : : /* Loop until we reach the limit. */
2794 : :
2795 : 403 : if (top_label)
2796 : 386 : emit_cmp_and_jump_insns (iter, iter_limit, iter_cond, NULL_RTX, iter_mode,
2797 : : true, top_label,
2798 : 772 : profile_probability::guessed_always ()
2799 : : .apply_scale (9, 10));
2800 : :
2801 : : /* We got to the end without differences, so the result is zero. */
2802 : 403 : if (target == NULL_RTX
2803 : 403 : || !REG_P (target) || REGNO (target) < FIRST_PSEUDO_REGISTER)
2804 : 49 : target = gen_reg_rtx (TYPE_MODE (integer_type_node));
2805 : :
2806 : 403 : emit_move_insn (target, const0_rtx);
2807 : 403 : emit_jump (res_label);
2808 : :
2809 : 403 : emit_label (ne_label);
2810 : :
2811 : : /* Return nonzero, or pinpoint the difference to return the expected
2812 : : result for non-equality tests. */
2813 : 403 : if (equality_only)
2814 : 0 : emit_move_insn (target, const1_rtx);
2815 : : else
2816 : : {
2817 : 403 : if (incr > UNITS_PER_WORD)
2818 : : /* ??? Re-compare the block found to be different one word at a
2819 : : time. */
2820 : 5 : part_res = emit_block_cmp_via_loop (x, y, GEN_INT (incr), len_type,
2821 : : target, equality_only,
2822 : : BITS_PER_WORD, 0);
2823 : 398 : else if (incr > 1)
2824 : : /* ??? Re-compare the block found to be different one byte at a
2825 : : time. We could do better using part_res, and being careful
2826 : : about endianness. */
2827 : 37 : part_res = emit_block_cmp_via_loop (x, y, GEN_INT (incr), len_type,
2828 : : target, equality_only,
2829 : : BITS_PER_UNIT, 0);
2830 : 1083 : else if (known_gt (GET_MODE_BITSIZE (GET_MODE (target)),
2831 : : GET_MODE_BITSIZE (cmp_mode)))
2832 : 361 : part_res = expand_binop (GET_MODE (target), sub_optab, x, y, target,
2833 : : true, OPTAB_LIB_WIDEN);
2834 : : else
2835 : : {
2836 : : /* In the odd chance target is QImode, we can't count on
2837 : : widening subtract to capture the result of the unsigned
2838 : : compares. */
2839 : 0 : rtx_code_label *ltu_label;
2840 : 0 : ltu_label = gen_label_rtx ();
2841 : 0 : emit_cmp_and_jump_insns (x, y, LTU, NULL_RTX,
2842 : : cmp_mode, true, ltu_label,
2843 : 0 : profile_probability::guessed_always ()
2844 : : .apply_scale (5, 10));
2845 : :
2846 : 0 : emit_move_insn (target, const1_rtx);
2847 : 0 : emit_jump (res_label);
2848 : :
2849 : 0 : emit_label (ltu_label);
2850 : 0 : emit_move_insn (target, constm1_rtx);
2851 : 0 : part_res = target;
2852 : : }
2853 : :
2854 : 403 : if (target != part_res)
2855 : 0 : convert_move (target, part_res, false);
2856 : : }
2857 : :
2858 : 403 : emit_label (res_label);
2859 : :
2860 : 403 : return target;
2861 : : }
2862 : :
2863 : :
2864 : : /* Copy all or part of a value X into registers starting at REGNO.
2865 : : The number of registers to be filled is NREGS. */
2866 : :
2867 : : void
2868 : 313 : move_block_to_reg (int regno, rtx x, int nregs, machine_mode mode)
2869 : : {
2870 : 313 : if (nregs == 0)
2871 : : return;
2872 : :
2873 : 299 : if (CONSTANT_P (x) && !targetm.legitimate_constant_p (mode, x))
2874 : 0 : x = validize_mem (force_const_mem (mode, x));
2875 : :
2876 : : /* See if the machine can do this with a load multiple insn. */
2877 : 299 : if (targetm.have_load_multiple ())
2878 : : {
2879 : 0 : rtx_insn *last = get_last_insn ();
2880 : 0 : rtx first = gen_rtx_REG (word_mode, regno);
2881 : 0 : if (rtx_insn *pat = targetm.gen_load_multiple (first, x,
2882 : : GEN_INT (nregs)))
2883 : : {
2884 : 0 : emit_insn (pat);
2885 : 0 : return;
2886 : : }
2887 : : else
2888 : 0 : delete_insns_since (last);
2889 : : }
2890 : :
2891 : 598 : for (int i = 0; i < nregs; i++)
2892 : 299 : emit_move_insn (gen_rtx_REG (word_mode, regno + i),
2893 : 299 : operand_subword_force (x, i, mode));
2894 : : }
2895 : :
2896 : : /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
2897 : : The number of registers to be filled is NREGS. */
2898 : :
2899 : : void
2900 : 1166 : move_block_from_reg (int regno, rtx x, int nregs)
2901 : : {
2902 : 1166 : if (nregs == 0)
2903 : : return;
2904 : :
2905 : : /* See if the machine can do this with a store multiple insn. */
2906 : 1166 : if (targetm.have_store_multiple ())
2907 : : {
2908 : 0 : rtx_insn *last = get_last_insn ();
2909 : 0 : rtx first = gen_rtx_REG (word_mode, regno);
2910 : 0 : if (rtx_insn *pat = targetm.gen_store_multiple (x, first,
2911 : : GEN_INT (nregs)))
2912 : : {
2913 : 0 : emit_insn (pat);
2914 : 0 : return;
2915 : : }
2916 : : else
2917 : 0 : delete_insns_since (last);
2918 : : }
2919 : :
2920 : 2332 : for (int i = 0; i < nregs; i++)
2921 : : {
2922 : 1166 : rtx tem = operand_subword (x, i, 1, BLKmode);
2923 : :
2924 : 1166 : gcc_assert (tem);
2925 : :
2926 : 1166 : emit_move_insn (tem, gen_rtx_REG (word_mode, regno + i));
2927 : : }
2928 : : }
2929 : :
2930 : : /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
2931 : : ORIG, where ORIG is a non-consecutive group of registers represented by
2932 : : a PARALLEL. The clone is identical to the original except in that the
2933 : : original set of registers is replaced by a new set of pseudo registers.
2934 : : The new set has the same modes as the original set. */
2935 : :
2936 : : rtx
2937 : 2989 : gen_group_rtx (rtx orig)
2938 : : {
2939 : 2989 : int i, length;
2940 : 2989 : rtx *tmps;
2941 : :
2942 : 2989 : gcc_assert (GET_CODE (orig) == PARALLEL);
2943 : :
2944 : 2989 : length = XVECLEN (orig, 0);
2945 : 2989 : tmps = XALLOCAVEC (rtx, length);
2946 : :
2947 : : /* Skip a NULL entry in first slot. */
2948 : 2989 : i = XEXP (XVECEXP (orig, 0, 0), 0) ? 0 : 1;
2949 : :
2950 : 2989 : if (i)
2951 : 0 : tmps[0] = 0;
2952 : :
2953 : 7303 : for (; i < length; i++)
2954 : : {
2955 : 4314 : machine_mode mode = GET_MODE (XEXP (XVECEXP (orig, 0, i), 0));
2956 : 4314 : rtx offset = XEXP (XVECEXP (orig, 0, i), 1);
2957 : :
2958 : 4314 : tmps[i] = gen_rtx_EXPR_LIST (VOIDmode, gen_reg_rtx (mode), offset);
2959 : : }
2960 : :
2961 : 2989 : return gen_rtx_PARALLEL (GET_MODE (orig), gen_rtvec_v (length, tmps));
2962 : : }
2963 : :
2964 : : /* A subroutine of emit_group_load. Arguments as for emit_group_load,
2965 : : except that values are placed in TMPS[i], and must later be moved
2966 : : into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
2967 : :
2968 : : static void
2969 : 297714 : emit_group_load_1 (rtx *tmps, rtx dst, rtx orig_src, tree type,
2970 : : poly_int64 ssize)
2971 : : {
2972 : 297717 : rtx src;
2973 : 297717 : int start, i;
2974 : 297717 : machine_mode m = GET_MODE (orig_src);
2975 : :
2976 : 297717 : gcc_assert (GET_CODE (dst) == PARALLEL);
2977 : :
2978 : 297717 : if (m != VOIDmode
2979 : 279073 : && !SCALAR_INT_MODE_P (m)
2980 : 17487 : && !MEM_P (orig_src)
2981 : 4406 : && GET_CODE (orig_src) != CONCAT)
2982 : : {
2983 : 3 : scalar_int_mode imode;
2984 : 3 : if (int_mode_for_mode (GET_MODE (orig_src)).exists (&imode))
2985 : : {
2986 : 3 : src = gen_reg_rtx (imode);
2987 : 3 : emit_move_insn (gen_lowpart (GET_MODE (orig_src), src), orig_src);
2988 : : }
2989 : : else
2990 : : {
2991 : 0 : src = assign_stack_temp (GET_MODE (orig_src), ssize);
2992 : 0 : emit_move_insn (src, orig_src);
2993 : : }
2994 : 3 : emit_group_load_1 (tmps, dst, src, type, ssize);
2995 : : return;
2996 : : }
2997 : :
2998 : : /* Check for a NULL entry, used to indicate that the parameter goes
2999 : : both on the stack and in registers. */
3000 : 297714 : if (XEXP (XVECEXP (dst, 0, 0), 0))
3001 : : start = 0;
3002 : : else
3003 : 0 : start = 1;
3004 : :
3005 : : /* Process the pieces. */
3006 : 882615 : for (i = start; i < XVECLEN (dst, 0); i++)
3007 : : {
3008 : 584901 : machine_mode mode = GET_MODE (XEXP (XVECEXP (dst, 0, i), 0));
3009 : 584901 : poly_int64 bytepos = rtx_to_poly_int64 (XEXP (XVECEXP (dst, 0, i), 1));
3010 : 1169802 : poly_int64 bytelen = GET_MODE_SIZE (mode);
3011 : 584901 : poly_int64 shift = 0;
3012 : :
3013 : : /* Handle trailing fragments that run over the size of the struct.
3014 : : It's the target's responsibility to make sure that the fragment
3015 : : cannot be strictly smaller in some cases and strictly larger
3016 : : in others. */
3017 : 584901 : gcc_checking_assert (ordered_p (bytepos + bytelen, ssize));
3018 : 584901 : if (known_size_p (ssize) && maybe_gt (bytepos + bytelen, ssize))
3019 : : {
3020 : : /* Arrange to shift the fragment to where it belongs.
3021 : : extract_bit_field loads to the lsb of the reg. */
3022 : : if (
3023 : : #ifdef BLOCK_REG_PADDING
3024 : : BLOCK_REG_PADDING (GET_MODE (orig_src), type, i == start)
3025 : : == (BYTES_BIG_ENDIAN ? PAD_UPWARD : PAD_DOWNWARD)
3026 : : #else
3027 : : BYTES_BIG_ENDIAN
3028 : : #endif
3029 : : )
3030 : : shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
3031 : 1776 : bytelen = ssize - bytepos;
3032 : 1776 : gcc_assert (maybe_gt (bytelen, 0));
3033 : : }
3034 : :
3035 : : /* If we won't be loading directly from memory, protect the real source
3036 : : from strange tricks we might play; but make sure that the source can
3037 : : be loaded directly into the destination. */
3038 : 584901 : src = orig_src;
3039 : 584901 : if (!MEM_P (orig_src)
3040 : 488575 : && (!REG_P (orig_src) || HARD_REGISTER_P (orig_src))
3041 : 628918 : && !CONSTANT_P (orig_src))
3042 : : {
3043 : 6729 : gcc_assert (GET_MODE (orig_src) != VOIDmode);
3044 : 6729 : src = force_reg (GET_MODE (orig_src), orig_src);
3045 : : }
3046 : :
3047 : : /* Optimize the access just a bit. */
3048 : 584901 : if (MEM_P (src)
3049 : 96326 : && (! targetm.slow_unaligned_access (mode, MEM_ALIGN (src))
3050 : 0 : || MEM_ALIGN (src) >= GET_MODE_ALIGNMENT (mode))
3051 : 192652 : && multiple_p (bytepos * BITS_PER_UNIT, GET_MODE_ALIGNMENT (mode))
3052 : 681227 : && known_eq (bytelen, GET_MODE_SIZE (mode)))
3053 : : {
3054 : 94569 : tmps[i] = gen_reg_rtx (mode);
3055 : 94569 : emit_move_insn (tmps[i], adjust_address (src, mode, bytepos));
3056 : : }
3057 : 490332 : else if (COMPLEX_MODE_P (mode)
3058 : 0 : && GET_MODE (src) == mode
3059 : 490332 : && known_eq (bytelen, GET_MODE_SIZE (mode)))
3060 : : /* Let emit_move_complex do the bulk of the work. */
3061 : 0 : tmps[i] = src;
3062 : 490332 : else if (GET_CODE (src) == CONCAT)
3063 : : {
3064 : 13458 : poly_int64 slen = GET_MODE_SIZE (GET_MODE (src));
3065 : 13458 : poly_int64 slen0 = GET_MODE_SIZE (GET_MODE (XEXP (src, 0)));
3066 : 6729 : unsigned int elt;
3067 : 6729 : poly_int64 subpos;
3068 : :
3069 : 6729 : if (can_div_trunc_p (bytepos, slen0, &elt, &subpos)
3070 : 6729 : && known_le (subpos + bytelen, slen0))
3071 : : {
3072 : : /* The following assumes that the concatenated objects all
3073 : : have the same size. In this case, a simple calculation
3074 : : can be used to determine the object and the bit field
3075 : : to be extracted. */
3076 : 4652 : tmps[i] = XEXP (src, elt);
3077 : 4652 : if (maybe_ne (subpos, 0)
3078 : 4652 : || maybe_ne (subpos + bytelen, slen0)
3079 : 9304 : || (!CONSTANT_P (tmps[i])
3080 : 4652 : && (!REG_P (tmps[i]) || GET_MODE (tmps[i]) != mode)))
3081 : 0 : tmps[i] = extract_bit_field (tmps[i], bytelen * BITS_PER_UNIT,
3082 : 0 : subpos * BITS_PER_UNIT,
3083 : : 1, NULL_RTX, mode, mode, false,
3084 : : NULL);
3085 : : }
3086 : : else
3087 : : {
3088 : 2077 : rtx mem;
3089 : :
3090 : 2077 : gcc_assert (known_eq (bytepos, 0));
3091 : 2077 : mem = assign_stack_temp (GET_MODE (src), slen);
3092 : 2077 : emit_move_insn (mem, src);
3093 : 2077 : tmps[i] = extract_bit_field (mem, bytelen * BITS_PER_UNIT,
3094 : 2077 : 0, 1, NULL_RTX, mode, mode, false,
3095 : : NULL);
3096 : : }
3097 : : }
3098 : 483603 : else if (CONSTANT_P (src) && GET_MODE (dst) != BLKmode
3099 : 37288 : && XVECLEN (dst, 0) > 1)
3100 : 37288 : tmps[i] = force_subreg (mode, src, GET_MODE (dst), bytepos);
3101 : 446315 : else if (CONSTANT_P (src))
3102 : : {
3103 : 0 : if (known_eq (bytelen, ssize))
3104 : 0 : tmps[i] = src;
3105 : : else
3106 : : {
3107 : : rtx first, second;
3108 : :
3109 : : /* TODO: const_wide_int can have sizes other than this... */
3110 : 0 : gcc_assert (known_eq (2 * bytelen, ssize));
3111 : 0 : split_double (src, &first, &second);
3112 : 0 : if (i)
3113 : 0 : tmps[i] = second;
3114 : : else
3115 : 0 : tmps[i] = first;
3116 : : }
3117 : : }
3118 : 446315 : else if (REG_P (src) && GET_MODE (src) == mode)
3119 : 0 : tmps[i] = src;
3120 : : else
3121 : 446315 : tmps[i] = extract_bit_field (src, bytelen * BITS_PER_UNIT,
3122 : 446315 : bytepos * BITS_PER_UNIT, 1, NULL_RTX,
3123 : : mode, mode, false, NULL);
3124 : :
3125 : 584901 : if (maybe_ne (shift, 0))
3126 : : tmps[i] = expand_shift (LSHIFT_EXPR, mode, tmps[i],
3127 : : shift, tmps[i], 0);
3128 : : }
3129 : : }
3130 : :
3131 : : /* Emit code to move a block SRC of type TYPE to a block DST,
3132 : : where DST is non-consecutive registers represented by a PARALLEL.
3133 : : SSIZE represents the total size of block ORIG_SRC in bytes, or -1
3134 : : if not known. */
3135 : :
3136 : : void
3137 : 10818 : emit_group_load (rtx dst, rtx src, tree type, poly_int64 ssize)
3138 : : {
3139 : 10818 : rtx *tmps;
3140 : 10818 : int i;
3141 : :
3142 : 10818 : tmps = XALLOCAVEC (rtx, XVECLEN (dst, 0));
3143 : 10818 : emit_group_load_1 (tmps, dst, src, type, ssize);
3144 : :
3145 : : /* Copy the extracted pieces into the proper (probable) hard regs. */
3146 : 30480 : for (i = 0; i < XVECLEN (dst, 0); i++)
3147 : : {
3148 : 19662 : rtx d = XEXP (XVECEXP (dst, 0, i), 0);
3149 : 19662 : if (d == NULL)
3150 : 0 : continue;
3151 : 19662 : emit_move_insn (d, tmps[i]);
3152 : : }
3153 : 10818 : }
3154 : :
3155 : : /* Similar, but load SRC into new pseudos in a format that looks like
3156 : : PARALLEL. This can later be fed to emit_group_move to get things
3157 : : in the right place. */
3158 : :
3159 : : rtx
3160 : 286896 : emit_group_load_into_temps (rtx parallel, rtx src, tree type, poly_int64 ssize)
3161 : : {
3162 : 286896 : rtvec vec;
3163 : 286896 : int i;
3164 : :
3165 : 286896 : vec = rtvec_alloc (XVECLEN (parallel, 0));
3166 : 286896 : emit_group_load_1 (&RTVEC_ELT (vec, 0), parallel, src, type, ssize);
3167 : :
3168 : : /* Convert the vector to look just like the original PARALLEL, except
3169 : : with the computed values. */
3170 : 852135 : for (i = 0; i < XVECLEN (parallel, 0); i++)
3171 : : {
3172 : 565239 : rtx e = XVECEXP (parallel, 0, i);
3173 : 565239 : rtx d = XEXP (e, 0);
3174 : :
3175 : 565239 : if (d)
3176 : : {
3177 : 565239 : d = force_reg (GET_MODE (d), RTVEC_ELT (vec, i));
3178 : 565239 : e = alloc_EXPR_LIST (REG_NOTE_KIND (e), d, XEXP (e, 1));
3179 : : }
3180 : 565239 : RTVEC_ELT (vec, i) = e;
3181 : : }
3182 : :
3183 : 286896 : return gen_rtx_PARALLEL (GET_MODE (parallel), vec);
3184 : : }
3185 : :
3186 : : /* Emit code to move a block SRC to block DST, where SRC and DST are
3187 : : non-consecutive groups of registers, each represented by a PARALLEL. */
3188 : :
3189 : : void
3190 : 289885 : emit_group_move (rtx dst, rtx src)
3191 : : {
3192 : 289885 : int i;
3193 : :
3194 : 289885 : gcc_assert (GET_CODE (src) == PARALLEL
3195 : : && GET_CODE (dst) == PARALLEL
3196 : : && XVECLEN (src, 0) == XVECLEN (dst, 0));
3197 : :
3198 : : /* Skip first entry if NULL. */
3199 : 859438 : for (i = XEXP (XVECEXP (src, 0, 0), 0) ? 0 : 1; i < XVECLEN (src, 0); i++)
3200 : 569553 : emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0),
3201 : 569553 : XEXP (XVECEXP (src, 0, i), 0));
3202 : 289885 : }
3203 : :
3204 : : /* Move a group of registers represented by a PARALLEL into pseudos. */
3205 : :
3206 : : rtx
3207 : 5705 : emit_group_move_into_temps (rtx src)
3208 : : {
3209 : 5705 : rtvec vec = rtvec_alloc (XVECLEN (src, 0));
3210 : 5705 : int i;
3211 : :
3212 : 13418 : for (i = 0; i < XVECLEN (src, 0); i++)
3213 : : {
3214 : 7713 : rtx e = XVECEXP (src, 0, i);
3215 : 7713 : rtx d = XEXP (e, 0);
3216 : :
3217 : 7713 : if (d)
3218 : 7713 : e = alloc_EXPR_LIST (REG_NOTE_KIND (e), copy_to_reg (d), XEXP (e, 1));
3219 : 7713 : RTVEC_ELT (vec, i) = e;
3220 : : }
3221 : :
3222 : 5705 : return gen_rtx_PARALLEL (GET_MODE (src), vec);
3223 : : }
3224 : :
3225 : : /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
3226 : : where SRC is non-consecutive registers represented by a PARALLEL.
3227 : : SSIZE represents the total size of block ORIG_DST, or -1 if not
3228 : : known. */
3229 : :
3230 : : void
3231 : 63544 : emit_group_store (rtx orig_dst, rtx src, tree type ATTRIBUTE_UNUSED,
3232 : : poly_int64 ssize)
3233 : : {
3234 : 63544 : rtx *tmps, dst;
3235 : 63544 : int start, finish, i;
3236 : 63544 : machine_mode m = GET_MODE (orig_dst);
3237 : :
3238 : 63544 : gcc_assert (GET_CODE (src) == PARALLEL);
3239 : :
3240 : 63544 : if (!SCALAR_INT_MODE_P (m)
3241 : 12877 : && !MEM_P (orig_dst) && GET_CODE (orig_dst) != CONCAT)
3242 : : {
3243 : 0 : scalar_int_mode imode;
3244 : 0 : if (int_mode_for_mode (GET_MODE (orig_dst)).exists (&imode))
3245 : : {
3246 : 0 : dst = gen_reg_rtx (imode);
3247 : 0 : emit_group_store (dst, src, type, ssize);
3248 : 0 : dst = gen_lowpart (GET_MODE (orig_dst), dst);
3249 : : }
3250 : : else
3251 : : {
3252 : 0 : dst = assign_stack_temp (GET_MODE (orig_dst), ssize);
3253 : 0 : emit_group_store (dst, src, type, ssize);
3254 : : }
3255 : 0 : emit_move_insn (orig_dst, dst);
3256 : 0 : return;
3257 : : }
3258 : :
3259 : : /* Check for a NULL entry, used to indicate that the parameter goes
3260 : : both on the stack and in registers. */
3261 : 63544 : if (XEXP (XVECEXP (src, 0, 0), 0))
3262 : : start = 0;
3263 : : else
3264 : 0 : start = 1;
3265 : 63544 : finish = XVECLEN (src, 0);
3266 : :
3267 : 63544 : tmps = XALLOCAVEC (rtx, finish);
3268 : :
3269 : : /* Copy the (probable) hard regs into pseudos. */
3270 : 183178 : for (i = start; i < finish; i++)
3271 : : {
3272 : 119634 : rtx reg = XEXP (XVECEXP (src, 0, i), 0);
3273 : 119634 : if (!REG_P (reg) || REGNO (reg) < FIRST_PSEUDO_REGISTER)
3274 : : {
3275 : 111921 : tmps[i] = gen_reg_rtx (GET_MODE (reg));
3276 : 111921 : emit_move_insn (tmps[i], reg);
3277 : : }
3278 : : else
3279 : 7713 : tmps[i] = reg;
3280 : : }
3281 : :
3282 : : /* If we won't be storing directly into memory, protect the real destination
3283 : : from strange tricks we might play. */
3284 : 63544 : dst = orig_dst;
3285 : 63544 : if (GET_CODE (dst) == PARALLEL)
3286 : : {
3287 : 0 : rtx temp;
3288 : :
3289 : : /* We can get a PARALLEL dst if there is a conditional expression in
3290 : : a return statement. In that case, the dst and src are the same,
3291 : : so no action is necessary. */
3292 : 0 : if (rtx_equal_p (dst, src))
3293 : : return;
3294 : :
3295 : : /* It is unclear if we can ever reach here, but we may as well handle
3296 : : it. Allocate a temporary, and split this into a store/load to/from
3297 : : the temporary. */
3298 : 0 : temp = assign_stack_temp (GET_MODE (dst), ssize);
3299 : 0 : emit_group_store (temp, src, type, ssize);
3300 : 0 : emit_group_load (dst, temp, type, ssize);
3301 : 0 : return;
3302 : : }
3303 : 63544 : else if (!MEM_P (dst) && GET_CODE (dst) != CONCAT)
3304 : : {
3305 : 50037 : machine_mode outer = GET_MODE (dst);
3306 : 50037 : machine_mode inner;
3307 : 50037 : poly_int64 bytepos;
3308 : 50037 : bool done = false;
3309 : 50037 : rtx temp;
3310 : :
3311 : 50037 : if (!REG_P (dst) || REGNO (dst) < FIRST_PSEUDO_REGISTER)
3312 : 0 : dst = gen_reg_rtx (outer);
3313 : :
3314 : : /* Make life a bit easier for combine: if the first element of the
3315 : : vector is the low part of the destination mode, use a paradoxical
3316 : : subreg to initialize the destination. */
3317 : 50037 : if (start < finish)
3318 : : {
3319 : 50037 : inner = GET_MODE (tmps[start]);
3320 : 50037 : bytepos = subreg_lowpart_offset (inner, outer);
3321 : 50037 : if (known_eq (rtx_to_poly_int64 (XEXP (XVECEXP (src, 0, start), 1)),
3322 : : bytepos))
3323 : : {
3324 : 50013 : temp = force_subreg (outer, tmps[start], inner, 0);
3325 : 50013 : if (temp)
3326 : : {
3327 : 49352 : emit_move_insn (dst, temp);
3328 : 49352 : done = true;
3329 : 49352 : start++;
3330 : : }
3331 : : }
3332 : : }
3333 : :
3334 : : /* If the first element wasn't the low part, try the last. */
3335 : 49352 : if (!done
3336 : 685 : && start < finish - 1)
3337 : : {
3338 : 618 : inner = GET_MODE (tmps[finish - 1]);
3339 : 618 : bytepos = subreg_lowpart_offset (inner, outer);
3340 : 618 : if (known_eq (rtx_to_poly_int64 (XEXP (XVECEXP (src, 0,
3341 : : finish - 1), 1)),
3342 : : bytepos))
3343 : : {
3344 : 0 : temp = force_subreg (outer, tmps[finish - 1], inner, 0);
3345 : 0 : if (temp)
3346 : : {
3347 : 0 : emit_move_insn (dst, temp);
3348 : 0 : done = true;
3349 : 0 : finish--;
3350 : : }
3351 : : }
3352 : : }
3353 : :
3354 : : /* Otherwise, simply initialize the result to zero. */
3355 : 49352 : if (!done)
3356 : 685 : emit_move_insn (dst, CONST0_RTX (outer));
3357 : : }
3358 : :
3359 : : /* Process the pieces. */
3360 : 131081 : for (i = start; i < finish; i++)
3361 : : {
3362 : 70282 : poly_int64 bytepos = rtx_to_poly_int64 (XEXP (XVECEXP (src, 0, i), 1));
3363 : 70282 : machine_mode mode = GET_MODE (tmps[i]);
3364 : 140564 : poly_int64 bytelen = GET_MODE_SIZE (mode);
3365 : 70282 : poly_uint64 adj_bytelen;
3366 : 70282 : rtx dest = dst;
3367 : :
3368 : : /* Handle trailing fragments that run over the size of the struct.
3369 : : It's the target's responsibility to make sure that the fragment
3370 : : cannot be strictly smaller in some cases and strictly larger
3371 : : in others. */
3372 : 70282 : gcc_checking_assert (ordered_p (bytepos + bytelen, ssize));
3373 : 139752 : if (known_size_p (ssize) && maybe_gt (bytepos + bytelen, ssize))
3374 : 812 : adj_bytelen = ssize - bytepos;
3375 : : else
3376 : 70282 : adj_bytelen = bytelen;
3377 : :
3378 : : /* Deal with destination CONCATs by either storing into one of the parts
3379 : : or doing a copy after storing into a register or stack temporary. */
3380 : 70282 : if (GET_CODE (dst) == CONCAT)
3381 : : {
3382 : 24282 : if (known_le (bytepos + adj_bytelen,
3383 : : GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)))))
3384 : : dest = XEXP (dst, 0);
3385 : :
3386 : 14886 : else if (known_ge (bytepos, GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)))))
3387 : : {
3388 : 9396 : bytepos -= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)));
3389 : 4698 : dest = XEXP (dst, 1);
3390 : : }
3391 : :
3392 : : else
3393 : : {
3394 : 2745 : machine_mode dest_mode = GET_MODE (dest);
3395 : 2745 : machine_mode tmp_mode = GET_MODE (tmps[i]);
3396 : 2745 : scalar_int_mode dest_imode;
3397 : :
3398 : 2745 : gcc_assert (known_eq (bytepos, 0) && XVECLEN (src, 0));
3399 : :
3400 : : /* If the source is a single scalar integer register, and the
3401 : : destination has a complex mode for which a same-sized integer
3402 : : mode exists, then we can take the left-justified part of the
3403 : : source in the complex mode. */
3404 : 2745 : if (finish == start + 1
3405 : 2745 : && REG_P (tmps[i])
3406 : 2745 : && SCALAR_INT_MODE_P (tmp_mode)
3407 : 2745 : && COMPLEX_MODE_P (dest_mode)
3408 : 5490 : && int_mode_for_mode (dest_mode).exists (&dest_imode))
3409 : : {
3410 : 2745 : const scalar_int_mode tmp_imode
3411 : 2745 : = as_a <scalar_int_mode> (tmp_mode);
3412 : :
3413 : 5490 : if (GET_MODE_BITSIZE (dest_imode)
3414 : 2745 : < GET_MODE_BITSIZE (tmp_imode))
3415 : : {
3416 : 59 : dest = gen_reg_rtx (dest_imode);
3417 : 59 : if (BYTES_BIG_ENDIAN)
3418 : : tmps[i] = expand_shift (RSHIFT_EXPR, tmp_mode, tmps[i],
3419 : : GET_MODE_BITSIZE (tmp_imode)
3420 : : - GET_MODE_BITSIZE (dest_imode),
3421 : : NULL_RTX, 1);
3422 : 59 : emit_move_insn (dest, gen_lowpart (dest_imode, tmps[i]));
3423 : 59 : dst = gen_lowpart (dest_mode, dest);
3424 : : }
3425 : : else
3426 : 2686 : dst = gen_lowpart (dest_mode, tmps[i]);
3427 : : }
3428 : :
3429 : : /* Otherwise spill the source onto the stack using the more
3430 : : aligned of the two modes. */
3431 : 0 : else if (GET_MODE_ALIGNMENT (dest_mode)
3432 : 0 : >= GET_MODE_ALIGNMENT (tmp_mode))
3433 : : {
3434 : 0 : dest = assign_stack_temp (dest_mode,
3435 : 0 : GET_MODE_SIZE (dest_mode));
3436 : 0 : emit_move_insn (adjust_address (dest, tmp_mode, bytepos),
3437 : : tmps[i]);
3438 : 0 : dst = dest;
3439 : : }
3440 : :
3441 : : else
3442 : : {
3443 : 0 : dest = assign_stack_temp (tmp_mode,
3444 : 0 : GET_MODE_SIZE (tmp_mode));
3445 : 0 : emit_move_insn (dest, tmps[i]);
3446 : 0 : dst = adjust_address (dest, dest_mode, bytepos);
3447 : : }
3448 : :
3449 : : break;
3450 : : }
3451 : : }
3452 : :
3453 : : /* Handle trailing fragments that run over the size of the struct. */
3454 : 67537 : if (known_size_p (ssize) && maybe_gt (bytepos + bytelen, ssize))
3455 : : {
3456 : : /* store_bit_field always takes its value from the lsb.
3457 : : Move the fragment to the lsb if it's not already there. */
3458 : 753 : if (
3459 : : #ifdef BLOCK_REG_PADDING
3460 : : BLOCK_REG_PADDING (GET_MODE (orig_dst), type, i == start)
3461 : : == (BYTES_BIG_ENDIAN ? PAD_UPWARD : PAD_DOWNWARD)
3462 : : #else
3463 : : BYTES_BIG_ENDIAN
3464 : : #endif
3465 : : )
3466 : : {
3467 : : poly_int64 shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
3468 : : tmps[i] = expand_shift (RSHIFT_EXPR, mode, tmps[i],
3469 : : shift, tmps[i], 0);
3470 : : }
3471 : :
3472 : : /* Make sure not to write past the end of the struct. */
3473 : 2259 : store_bit_field (dest,
3474 : 753 : adj_bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
3475 : 1506 : bytepos * BITS_PER_UNIT, ssize * BITS_PER_UNIT - 1,
3476 : : VOIDmode, tmps[i], false, false);
3477 : : }
3478 : :
3479 : : /* Optimize the access just a bit. */
3480 : 66784 : else if (MEM_P (dest)
3481 : 7566 : && (!targetm.slow_unaligned_access (mode, MEM_ALIGN (dest))
3482 : 0 : || MEM_ALIGN (dest) >= GET_MODE_ALIGNMENT (mode))
3483 : 15132 : && multiple_p (bytepos * BITS_PER_UNIT,
3484 : : GET_MODE_ALIGNMENT (mode))
3485 : 74350 : && known_eq (bytelen, GET_MODE_SIZE (mode)))
3486 : 7566 : emit_move_insn (adjust_address (dest, mode, bytepos), tmps[i]);
3487 : :
3488 : : else
3489 : 59218 : store_bit_field (dest, bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
3490 : 59218 : 0, 0, mode, tmps[i], false, false);
3491 : : }
3492 : :
3493 : : /* Copy from the pseudo into the (probable) hard reg. */
3494 : 63544 : if (orig_dst != dst)
3495 : 2745 : emit_move_insn (orig_dst, dst);
3496 : : }
3497 : :
3498 : : /* Return a form of X that does not use a PARALLEL. TYPE is the type
3499 : : of the value stored in X. */
3500 : :
3501 : : rtx
3502 : 344460 : maybe_emit_group_store (rtx x, tree type)
3503 : : {
3504 : 344460 : machine_mode mode = TYPE_MODE (type);
3505 : 344460 : gcc_checking_assert (GET_MODE (x) == VOIDmode || GET_MODE (x) == mode);
3506 : 344460 : if (GET_CODE (x) == PARALLEL)
3507 : : {
3508 : 0 : rtx result = gen_reg_rtx (mode);
3509 : 0 : emit_group_store (result, x, type, int_size_in_bytes (type));
3510 : 0 : return result;
3511 : : }
3512 : : return x;
3513 : : }
3514 : :
3515 : : /* Copy a BLKmode object of TYPE out of a register SRCREG into TARGET.
3516 : :
3517 : : This is used on targets that return BLKmode values in registers. */
3518 : :
3519 : : static void
3520 : 246 : copy_blkmode_from_reg (rtx target, rtx srcreg, tree type)
3521 : : {
3522 : 246 : unsigned HOST_WIDE_INT bytes = int_size_in_bytes (type);
3523 : 246 : rtx src = NULL, dst = NULL;
3524 : 246 : unsigned HOST_WIDE_INT bitsize = MIN (TYPE_ALIGN (type), BITS_PER_WORD);
3525 : 246 : unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0;
3526 : : /* No current ABI uses variable-sized modes to pass a BLKmnode type. */
3527 : 246 : fixed_size_mode mode = as_a <fixed_size_mode> (GET_MODE (srcreg));
3528 : 246 : fixed_size_mode tmode = as_a <fixed_size_mode> (GET_MODE (target));
3529 : 246 : fixed_size_mode copy_mode;
3530 : :
3531 : : /* BLKmode registers created in the back-end shouldn't have survived. */
3532 : 246 : gcc_assert (mode != BLKmode);
3533 : :
3534 : : /* If the structure doesn't take up a whole number of words, see whether
3535 : : SRCREG is padded on the left or on the right. If it's on the left,
3536 : : set PADDING_CORRECTION to the number of bits to skip.
3537 : :
3538 : : In most ABIs, the structure will be returned at the least end of
3539 : : the register, which translates to right padding on little-endian
3540 : : targets and left padding on big-endian targets. The opposite
3541 : : holds if the structure is returned at the most significant
3542 : : end of the register. */
3543 : 246 : if (bytes % UNITS_PER_WORD != 0
3544 : 246 : && (targetm.calls.return_in_msb (type)
3545 : 215 : ? !BYTES_BIG_ENDIAN
3546 : : : BYTES_BIG_ENDIAN))
3547 : 0 : padding_correction
3548 : 0 : = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD) * BITS_PER_UNIT));
3549 : :
3550 : : /* We can use a single move if we have an exact mode for the size. */
3551 : 246 : else if (MEM_P (target)
3552 : 246 : && (!targetm.slow_unaligned_access (mode, MEM_ALIGN (target))
3553 : 0 : || MEM_ALIGN (target) >= GET_MODE_ALIGNMENT (mode))
3554 : 492 : && bytes == GET_MODE_SIZE (mode))
3555 : : {
3556 : 38 : emit_move_insn (adjust_address (target, mode, 0), srcreg);
3557 : 38 : return;
3558 : : }
3559 : :
3560 : : /* And if we additionally have the same mode for a register. */
3561 : 208 : else if (REG_P (target)
3562 : 0 : && GET_MODE (target) == mode
3563 : 208 : && bytes == GET_MODE_SIZE (mode))
3564 : : {
3565 : 0 : emit_move_insn (target, srcreg);
3566 : 0 : return;
3567 : : }
3568 : :
3569 : : /* This code assumes srcreg is at least a full word. If it isn't, copy it
3570 : : into a new pseudo which is a full word. */
3571 : 416 : if (GET_MODE_SIZE (mode) < UNITS_PER_WORD)
3572 : : {
3573 : 76 : srcreg = convert_to_mode (word_mode, srcreg, TYPE_UNSIGNED (type));
3574 : 76 : mode = word_mode;
3575 : : }
3576 : :
3577 : : /* Copy the structure BITSIZE bits at a time. If the target lives in
3578 : : memory, take care of not reading/writing past its end by selecting
3579 : : a copy mode suited to BITSIZE. This should always be possible given
3580 : : how it is computed.
3581 : :
3582 : : If the target lives in register, make sure not to select a copy mode
3583 : : larger than the mode of the register.
3584 : :
3585 : : We could probably emit more efficient code for machines which do not use
3586 : : strict alignment, but it doesn't seem worth the effort at the current
3587 : : time. */
3588 : :
3589 : 208 : copy_mode = word_mode;
3590 : 208 : if (MEM_P (target))
3591 : : {
3592 : 208 : opt_scalar_int_mode mem_mode = int_mode_for_size (bitsize, 1);
3593 : 208 : if (mem_mode.exists ())
3594 : 208 : copy_mode = mem_mode.require ();
3595 : : }
3596 : 0 : else if (REG_P (target) && GET_MODE_BITSIZE (tmode) < BITS_PER_WORD)
3597 : : copy_mode = tmode;
3598 : :
3599 : 208 : for (bitpos = 0, xbitpos = padding_correction;
3600 : 1017 : bitpos < bytes * BITS_PER_UNIT;
3601 : 809 : bitpos += bitsize, xbitpos += bitsize)
3602 : : {
3603 : : /* We need a new source operand each time xbitpos is on a
3604 : : word boundary and when xbitpos == padding_correction
3605 : : (the first time through). */
3606 : 809 : if (xbitpos % BITS_PER_WORD == 0 || xbitpos == padding_correction)
3607 : 208 : src = operand_subword_force (srcreg, xbitpos / BITS_PER_WORD, mode);
3608 : :
3609 : : /* We need a new destination operand each time bitpos is on
3610 : : a word boundary. */
3611 : 809 : if (REG_P (target) && GET_MODE_BITSIZE (tmode) < BITS_PER_WORD)
3612 : : dst = target;
3613 : 809 : else if (bitpos % BITS_PER_WORD == 0)
3614 : 208 : dst = operand_subword (target, bitpos / BITS_PER_WORD, 1, tmode);
3615 : :
3616 : : /* Use xbitpos for the source extraction (right justified) and
3617 : : bitpos for the destination store (left justified). */
3618 : 809 : store_bit_field (dst, bitsize, bitpos % BITS_PER_WORD, 0, 0, copy_mode,
3619 : 809 : extract_bit_field (src, bitsize,
3620 : 809 : xbitpos % BITS_PER_WORD, 1,
3621 : : NULL_RTX, copy_mode, copy_mode,
3622 : : false, NULL),
3623 : : false, false);
3624 : : }
3625 : : }
3626 : :
3627 : : /* Copy BLKmode value SRC into a register of mode MODE_IN. Return the
3628 : : register if it contains any data, otherwise return null.
3629 : :
3630 : : This is used on targets that return BLKmode values in registers. */
3631 : :
3632 : : rtx
3633 : 3987 : copy_blkmode_to_reg (machine_mode mode_in, tree src)
3634 : : {
3635 : 3987 : int i, n_regs;
3636 : 3987 : unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0, bytes;
3637 : 3987 : unsigned int bitsize;
3638 : 3987 : rtx *dst_words, dst, x, src_word = NULL_RTX, dst_word = NULL_RTX;
3639 : : /* No current ABI uses variable-sized modes to pass a BLKmnode type. */
3640 : 3987 : fixed_size_mode mode = as_a <fixed_size_mode> (mode_in);
3641 : 3987 : fixed_size_mode dst_mode;
3642 : 3987 : scalar_int_mode min_mode;
3643 : :
3644 : 3987 : gcc_assert (TYPE_MODE (TREE_TYPE (src)) == BLKmode);
3645 : :
3646 : 3987 : x = expand_normal (src);
3647 : :
3648 : 3987 : bytes = arg_int_size_in_bytes (TREE_TYPE (src));
3649 : 3987 : if (bytes == 0)
3650 : : return NULL_RTX;
3651 : :
3652 : : /* If the structure doesn't take up a whole number of words, see
3653 : : whether the register value should be padded on the left or on
3654 : : the right. Set PADDING_CORRECTION to the number of padding
3655 : : bits needed on the left side.
3656 : :
3657 : : In most ABIs, the structure will be returned at the least end of
3658 : : the register, which translates to right padding on little-endian
3659 : : targets and left padding on big-endian targets. The opposite
3660 : : holds if the structure is returned at the most significant
3661 : : end of the register. */
3662 : 1220 : if (bytes % UNITS_PER_WORD != 0
3663 : 1220 : && (targetm.calls.return_in_msb (TREE_TYPE (src))
3664 : 1185 : ? !BYTES_BIG_ENDIAN
3665 : : : BYTES_BIG_ENDIAN))
3666 : 0 : padding_correction = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD)
3667 : 0 : * BITS_PER_UNIT));
3668 : :
3669 : 1220 : n_regs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3670 : 1220 : dst_words = XALLOCAVEC (rtx, n_regs);
3671 : 1220 : bitsize = MIN (TYPE_ALIGN (TREE_TYPE (src)), BITS_PER_WORD);
3672 : 1220 : min_mode = smallest_int_mode_for_size (bitsize).require ();
3673 : :
3674 : : /* Copy the structure BITSIZE bits at a time. */
3675 : 1220 : for (bitpos = 0, xbitpos = padding_correction;
3676 : 3963 : bitpos < bytes * BITS_PER_UNIT;
3677 : 2743 : bitpos += bitsize, xbitpos += bitsize)
3678 : : {
3679 : : /* We need a new destination pseudo each time xbitpos is
3680 : : on a word boundary and when xbitpos == padding_correction
3681 : : (the first time through). */
3682 : 2743 : if (xbitpos % BITS_PER_WORD == 0
3683 : 1520 : || xbitpos == padding_correction)
3684 : : {
3685 : : /* Generate an appropriate register. */
3686 : 1223 : dst_word = gen_reg_rtx (word_mode);
3687 : 1223 : dst_words[xbitpos / BITS_PER_WORD] = dst_word;
3688 : :
3689 : : /* Clear the destination before we move anything into it. */
3690 : 1223 : emit_move_insn (dst_word, CONST0_RTX (word_mode));
3691 : : }
3692 : :
3693 : : /* Find the largest integer mode that can be used to copy all or as
3694 : : many bits as possible of the structure if the target supports larger
3695 : : copies. There are too many corner cases here w.r.t to alignments on
3696 : : the read/writes. So if there is any padding just use single byte
3697 : : operations. */
3698 : 2743 : opt_scalar_int_mode mode_iter;
3699 : 2743 : if (padding_correction == 0 && !STRICT_ALIGNMENT)
3700 : : {
3701 : 7467 : FOR_EACH_MODE_FROM (mode_iter, min_mode)
3702 : : {
3703 : 7467 : unsigned int msize = GET_MODE_BITSIZE (mode_iter.require ());
3704 : 7467 : if (msize <= ((bytes * BITS_PER_UNIT) - bitpos)
3705 : 4727 : && msize <= BITS_PER_WORD)
3706 : 4724 : bitsize = msize;
3707 : : else
3708 : : break;
3709 : : }
3710 : : }
3711 : :
3712 : : /* We need a new source operand each time bitpos is on a word
3713 : : boundary. */
3714 : 2743 : if (bitpos % BITS_PER_WORD == 0)
3715 : 1223 : src_word = operand_subword_force (x, bitpos / BITS_PER_WORD, BLKmode);
3716 : :
3717 : : /* Use bitpos for the source extraction (left justified) and
3718 : : xbitpos for the destination store (right justified). */
3719 : 2743 : store_bit_field (dst_word, bitsize, xbitpos % BITS_PER_WORD,
3720 : 2743 : 0, 0, word_mode,
3721 : 2743 : extract_bit_field (src_word, bitsize,
3722 : 2743 : bitpos % BITS_PER_WORD, 1,
3723 : : NULL_RTX, word_mode, word_mode,
3724 : : false, NULL),
3725 : : false, false);
3726 : : }
3727 : :
3728 : 1220 : if (mode == BLKmode)
3729 : : {
3730 : : /* Find the smallest integer mode large enough to hold the
3731 : : entire structure. */
3732 : 0 : opt_scalar_int_mode mode_iter;
3733 : 0 : FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_INT)
3734 : 0 : if (GET_MODE_SIZE (mode_iter.require ()) >= bytes)
3735 : : break;
3736 : :
3737 : : /* A suitable mode should have been found. */
3738 : 0 : mode = mode_iter.require ();
3739 : : }
3740 : :
3741 : 3660 : if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
3742 : : dst_mode = word_mode;
3743 : : else
3744 : 494 : dst_mode = mode;
3745 : 1220 : dst = gen_reg_rtx (dst_mode);
3746 : :
3747 : 3663 : for (i = 0; i < n_regs; i++)
3748 : 1223 : emit_move_insn (operand_subword (dst, i, 0, dst_mode), dst_words[i]);
3749 : :
3750 : 1220 : if (mode != dst_mode)
3751 : 726 : dst = gen_lowpart (mode, dst);
3752 : :
3753 : : return dst;
3754 : : }
3755 : :
3756 : : /* Add a USE expression for REG to the (possibly empty) list pointed
3757 : : to by CALL_FUSAGE. REG must denote a hard register. */
3758 : :
3759 : : void
3760 : 11213411 : use_reg_mode (rtx *call_fusage, rtx reg, machine_mode mode)
3761 : : {
3762 : 11213411 : gcc_assert (REG_P (reg));
3763 : :
3764 : 11213411 : if (!HARD_REGISTER_P (reg))
3765 : : return;
3766 : :
3767 : 11213411 : *call_fusage
3768 : 11213411 : = gen_rtx_EXPR_LIST (mode, gen_rtx_USE (VOIDmode, reg), *call_fusage);
3769 : : }
3770 : :
3771 : : /* Add a CLOBBER expression for REG to the (possibly empty) list pointed
3772 : : to by CALL_FUSAGE. REG must denote a hard register. */
3773 : :
3774 : : void
3775 : 797494 : clobber_reg_mode (rtx *call_fusage, rtx reg, machine_mode mode)
3776 : : {
3777 : 797494 : gcc_assert (REG_P (reg) && REGNO (reg) < FIRST_PSEUDO_REGISTER);
3778 : :
3779 : 797494 : *call_fusage
3780 : 797494 : = gen_rtx_EXPR_LIST (mode, gen_rtx_CLOBBER (VOIDmode, reg), *call_fusage);
3781 : 797494 : }
3782 : :
3783 : : /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
3784 : : starting at REGNO. All of these registers must be hard registers. */
3785 : :
3786 : : void
3787 : 1562 : use_regs (rtx *call_fusage, int regno, int nregs)
3788 : : {
3789 : 1562 : int i;
3790 : :
3791 : 1562 : gcc_assert (regno + nregs <= FIRST_PSEUDO_REGISTER);
3792 : :
3793 : 3124 : for (i = 0; i < nregs; i++)
3794 : 1562 : use_reg (call_fusage, regno_reg_rtx[regno + i]);
3795 : 1562 : }
3796 : :
3797 : : /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
3798 : : PARALLEL REGS. This is for calls that pass values in multiple
3799 : : non-contiguous locations. The Irix 6 ABI has examples of this. */
3800 : :
3801 : : void
3802 : 294099 : use_group_regs (rtx *call_fusage, rtx regs)
3803 : : {
3804 : 294099 : int i;
3805 : :
3806 : 873744 : for (i = 0; i < XVECLEN (regs, 0); i++)
3807 : : {
3808 : 579645 : rtx reg = XEXP (XVECEXP (regs, 0, i), 0);
3809 : :
3810 : : /* A NULL entry means the parameter goes both on the stack and in
3811 : : registers. This can also be a MEM for targets that pass values
3812 : : partially on the stack and partially in registers. */
3813 : 579645 : if (reg != 0 && REG_P (reg))
3814 : 579645 : use_reg (call_fusage, reg);
3815 : : }
3816 : 294099 : }
3817 : :
3818 : : /* Return the defining gimple statement for SSA_NAME NAME if it is an
3819 : : assigment and the code of the expresion on the RHS is CODE. Return
3820 : : NULL otherwise. */
3821 : :
3822 : : static gimple *
3823 : 11375205 : get_def_for_expr (tree name, enum tree_code code)
3824 : : {
3825 : 11375205 : gimple *def_stmt;
3826 : :
3827 : 11375205 : if (TREE_CODE (name) != SSA_NAME)
3828 : : return NULL;
3829 : :
3830 : 8832519 : def_stmt = get_gimple_for_ssa_name (name);
3831 : 8832519 : if (!def_stmt
3832 : 1895624 : || !is_gimple_assign (def_stmt)
3833 : 10726815 : || gimple_assign_rhs_code (def_stmt) != code)
3834 : : return NULL;
3835 : :
3836 : : return def_stmt;
3837 : : }
3838 : :
3839 : : /* Return the defining gimple statement for SSA_NAME NAME if it is an
3840 : : assigment and the class of the expresion on the RHS is CLASS. Return
3841 : : NULL otherwise. */
3842 : :
3843 : : static gimple *
3844 : 15910 : get_def_for_expr_class (tree name, enum tree_code_class tclass)
3845 : : {
3846 : 15910 : gimple *def_stmt;
3847 : :
3848 : 15910 : if (TREE_CODE (name) != SSA_NAME)
3849 : : return NULL;
3850 : :
3851 : 15910 : def_stmt = get_gimple_for_ssa_name (name);
3852 : 15910 : if (!def_stmt
3853 : 13779 : || !is_gimple_assign (def_stmt)
3854 : 29689 : || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt)) != tclass)
3855 : : return NULL;
3856 : :
3857 : : return def_stmt;
3858 : : }
3859 : :
3860 : : /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
3861 : : its length in bytes. */
3862 : :
3863 : : rtx
3864 : 127472 : clear_storage_hints (rtx object, rtx size, enum block_op_methods method,
3865 : : unsigned int expected_align, HOST_WIDE_INT expected_size,
3866 : : unsigned HOST_WIDE_INT min_size,
3867 : : unsigned HOST_WIDE_INT max_size,
3868 : : unsigned HOST_WIDE_INT probable_max_size,
3869 : : unsigned ctz_size)
3870 : : {
3871 : 127472 : machine_mode mode = GET_MODE (object);
3872 : 127472 : unsigned int align;
3873 : :
3874 : 127472 : gcc_assert (method == BLOCK_OP_NORMAL || method == BLOCK_OP_TAILCALL);
3875 : :
3876 : : /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
3877 : : just move a zero. Otherwise, do this a piece at a time. */
3878 : 127472 : poly_int64 size_val;
3879 : 127472 : if (mode != BLKmode
3880 : 55212 : && poly_int_rtx_p (size, &size_val)
3881 : 182684 : && known_eq (size_val, GET_MODE_SIZE (mode)))
3882 : : {
3883 : 55212 : rtx zero = CONST0_RTX (mode);
3884 : 55212 : if (zero != NULL)
3885 : : {
3886 : 55212 : emit_move_insn (object, zero);
3887 : 55212 : return NULL;
3888 : : }
3889 : :
3890 : 0 : if (COMPLEX_MODE_P (mode))
3891 : : {
3892 : 0 : zero = CONST0_RTX (GET_MODE_INNER (mode));
3893 : 0 : if (zero != NULL)
3894 : : {
3895 : 0 : write_complex_part (object, zero, 0, true);
3896 : 0 : write_complex_part (object, zero, 1, false);
3897 : 0 : return NULL;
3898 : : }
3899 : : }
3900 : : }
3901 : :
3902 : 72260 : if (size == const0_rtx)
3903 : : return NULL;
3904 : :
3905 : 72260 : align = MEM_ALIGN (object);
3906 : :
3907 : 72260 : if (CONST_INT_P (size)
3908 : 137753 : && targetm.use_by_pieces_infrastructure_p (INTVAL (size), align,
3909 : : CLEAR_BY_PIECES,
3910 : 65493 : optimize_insn_for_speed_p ()))
3911 : 46017 : clear_by_pieces (object, INTVAL (size), align);
3912 : 26243 : else if (set_storage_via_setmem (object, size, const0_rtx, align,
3913 : : expected_align, expected_size,
3914 : : min_size, max_size, probable_max_size))
3915 : : ;
3916 : 5608 : else if (try_store_by_multiple_pieces (object, size, ctz_size,
3917 : : min_size, max_size,
3918 : : NULL_RTX, 0, align))
3919 : : ;
3920 : 5553 : else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object)))
3921 : 5553 : return set_storage_via_libcall (object, size, const0_rtx,
3922 : 5553 : method == BLOCK_OP_TAILCALL);
3923 : : else
3924 : 0 : gcc_unreachable ();
3925 : :
3926 : : return NULL;
3927 : : }
3928 : :
3929 : : rtx
3930 : 106547 : clear_storage (rtx object, rtx size, enum block_op_methods method)
3931 : : {
3932 : 106547 : unsigned HOST_WIDE_INT max, min = 0;
3933 : 106547 : if (GET_CODE (size) == CONST_INT)
3934 : 106547 : min = max = UINTVAL (size);
3935 : : else
3936 : 0 : max = GET_MODE_MASK (GET_MODE (size));
3937 : 106547 : return clear_storage_hints (object, size, method, 0, -1, min, max, max, 0);
3938 : : }
3939 : :
3940 : :
3941 : : /* A subroutine of clear_storage. Expand a call to memset.
3942 : : Return the return value of memset, 0 otherwise. */
3943 : :
3944 : : rtx
3945 : 5557 : set_storage_via_libcall (rtx object, rtx size, rtx val, bool tailcall)
3946 : : {
3947 : 5557 : tree call_expr, fn, object_tree, size_tree, val_tree;
3948 : 5557 : machine_mode size_mode;
3949 : :
3950 : 5557 : object = copy_addr_to_reg (XEXP (object, 0));
3951 : 5557 : object_tree = make_tree (ptr_type_node, object);
3952 : :
3953 : 5557 : if (!CONST_INT_P (val))
3954 : 3 : val = convert_to_mode (TYPE_MODE (integer_type_node), val, 1);
3955 : 5557 : val_tree = make_tree (integer_type_node, val);
3956 : :
3957 : 5557 : size_mode = TYPE_MODE (sizetype);
3958 : 5557 : size = convert_to_mode (size_mode, size, 1);
3959 : 5557 : size = copy_to_mode_reg (size_mode, size);
3960 : 5557 : size_tree = make_tree (sizetype, size);
3961 : :
3962 : : /* It is incorrect to use the libcall calling conventions for calls to
3963 : : memset because it can be provided by the user. */
3964 : 5557 : fn = builtin_decl_implicit (BUILT_IN_MEMSET);
3965 : 5557 : call_expr = build_call_expr (fn, 3, object_tree, val_tree, size_tree);
3966 : 5557 : CALL_EXPR_TAILCALL (call_expr) = tailcall;
3967 : :
3968 : 5557 : return expand_call (call_expr, NULL_RTX, false);
3969 : : }
3970 : :
3971 : : /* Expand a setmem pattern; return true if successful. */
3972 : :
3973 : : bool
3974 : 34464 : set_storage_via_setmem (rtx object, rtx size, rtx val, unsigned int align,
3975 : : unsigned int expected_align, HOST_WIDE_INT expected_size,
3976 : : unsigned HOST_WIDE_INT min_size,
3977 : : unsigned HOST_WIDE_INT max_size,
3978 : : unsigned HOST_WIDE_INT probable_max_size)
3979 : : {
3980 : : /* Try the most limited insn first, because there's no point
3981 : : including more than one in the machine description unless
3982 : : the more limited one has some advantage. */
3983 : :
3984 : 34464 : if (expected_align < align)
3985 : : expected_align = align;
3986 : 34464 : if (expected_size != -1)
3987 : : {
3988 : 5 : if ((unsigned HOST_WIDE_INT)expected_size > max_size)
3989 : 0 : expected_size = max_size;
3990 : 5 : if ((unsigned HOST_WIDE_INT)expected_size < min_size)
3991 : 0 : expected_size = min_size;
3992 : : }
3993 : :
3994 : 34464 : opt_scalar_int_mode mode_iter;
3995 : 163673 : FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_INT)
3996 : : {
3997 : 151755 : scalar_int_mode mode = mode_iter.require ();
3998 : 151755 : enum insn_code code = direct_optab_handler (setmem_optab, mode);
3999 : :
4000 : 151755 : if (code != CODE_FOR_nothing
4001 : : /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
4002 : : here because if SIZE is less than the mode mask, as it is
4003 : : returned by the macro, it will definitely be less than the
4004 : : actual mode mask. Since SIZE is within the Pmode address
4005 : : space, we limit MODE to Pmode. */
4006 : 151755 : && ((CONST_INT_P (size)
4007 : 20779 : && ((unsigned HOST_WIDE_INT) INTVAL (size)
4008 : 20779 : <= (GET_MODE_MASK (mode) >> 1)))
4009 : 25385 : || max_size <= (GET_MODE_MASK (mode) >> 1)
4010 : 32996 : || GET_MODE_BITSIZE (mode) >= GET_MODE_BITSIZE (Pmode)))
4011 : : {
4012 : 35687 : class expand_operand ops[9];
4013 : 35687 : unsigned int nops;
4014 : :
4015 : 35687 : nops = insn_data[(int) code].n_generator_args;
4016 : 35687 : gcc_assert (nops == 4 || nops == 6 || nops == 8 || nops == 9);
4017 : :
4018 : 35687 : create_fixed_operand (&ops[0], object);
4019 : : /* The check above guarantees that this size conversion is valid. */
4020 : 35687 : create_convert_operand_to (&ops[1], size, mode, true);
4021 : 35687 : create_convert_operand_from (&ops[2], val, byte_mode, true);
4022 : 35687 : create_integer_operand (&ops[3], align / BITS_PER_UNIT);
4023 : 35687 : if (nops >= 6)
4024 : : {
4025 : 35687 : create_integer_operand (&ops[4], expected_align / BITS_PER_UNIT);
4026 : 35687 : create_integer_operand (&ops[5], expected_size);
4027 : : }
4028 : 35687 : if (nops >= 8)
4029 : : {
4030 : 35687 : create_integer_operand (&ops[6], min_size);
4031 : : /* If we cannot represent the maximal size,
4032 : : make parameter NULL. */
4033 : 35687 : if ((HOST_WIDE_INT) max_size != -1)
4034 : 30686 : create_integer_operand (&ops[7], max_size);
4035 : : else
4036 : 5001 : create_fixed_operand (&ops[7], NULL);
4037 : : }
4038 : 35687 : if (nops == 9)
4039 : : {
4040 : : /* If we cannot represent the maximal size,
4041 : : make parameter NULL. */
4042 : 35687 : if ((HOST_WIDE_INT) probable_max_size != -1)
4043 : 30846 : create_integer_operand (&ops[8], probable_max_size);
4044 : : else
4045 : 4841 : create_fixed_operand (&ops[8], NULL);
4046 : : }
4047 : 35687 : if (maybe_expand_insn (code, nops, ops))
4048 : 22546 : return true;
4049 : : }
4050 : : }
4051 : :
4052 : : return false;
4053 : : }
4054 : :
4055 : :
4056 : : /* Write to one of the components of the complex value CPLX. Write VAL to
4057 : : the real part if IMAG_P is false, and the imaginary part if its true.
4058 : : If UNDEFINED_P then the value in CPLX is currently undefined. */
4059 : :
4060 : : void
4061 : 545822 : write_complex_part (rtx cplx, rtx val, bool imag_p, bool undefined_p)
4062 : : {
4063 : 545822 : machine_mode cmode;
4064 : 545822 : scalar_mode imode;
4065 : 545822 : unsigned ibitsize;
4066 : :
4067 : 545822 : if (GET_CODE (cplx) == CONCAT)
4068 : : {
4069 : 485638 : emit_move_insn (XEXP (cplx, imag_p), val);
4070 : 485638 : return;
4071 : : }
4072 : :
4073 : 60184 : cmode = GET_MODE (cplx);
4074 : 60184 : imode = GET_MODE_INNER (cmode);
4075 : 60184 : ibitsize = GET_MODE_BITSIZE (imode);
4076 : :
4077 : : /* For MEMs simplify_gen_subreg may generate an invalid new address
4078 : : because, e.g., the original address is considered mode-dependent
4079 : : by the target, which restricts simplify_subreg from invoking
4080 : : adjust_address_nv. Instead of preparing fallback support for an
4081 : : invalid address, we call adjust_address_nv directly. */
4082 : 60184 : if (MEM_P (cplx))
4083 : : {
4084 : 73524 : emit_move_insn (adjust_address_nv (cplx, imode,
4085 : : imag_p ? GET_MODE_SIZE (imode) : 0),
4086 : : val);
4087 : 49016 : return;
4088 : : }
4089 : :
4090 : : /* If the sub-object is at least word sized, then we know that subregging
4091 : : will work. This special case is important, since store_bit_field
4092 : : wants to operate on integer modes, and there's rarely an OImode to
4093 : : correspond to TCmode. */
4094 : 11168 : if (ibitsize >= BITS_PER_WORD
4095 : : /* For hard regs we have exact predicates. Assume we can split
4096 : : the original object if it spans an even number of hard regs.
4097 : : This special case is important for SCmode on 64-bit platforms
4098 : : where the natural size of floating-point regs is 32-bit. */
4099 : 11168 : || (REG_P (cplx)
4100 : 7304 : && REGNO (cplx) < FIRST_PSEUDO_REGISTER
4101 : 7120 : && REG_NREGS (cplx) % 2 == 0))
4102 : : {
4103 : 3880 : rtx part = simplify_gen_subreg (imode, cplx, cmode,
4104 : 5820 : imag_p ? GET_MODE_SIZE (imode) : 0);
4105 : 3880 : if (part)
4106 : : {
4107 : 3880 : emit_move_insn (part, val);
4108 : 3880 : return;
4109 : : }
4110 : : else
4111 : : /* simplify_gen_subreg may fail for sub-word MEMs. */
4112 : 0 : gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
4113 : : }
4114 : :
4115 : 10932 : store_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0, 0, 0, imode, val,
4116 : : false, undefined_p);
4117 : : }
4118 : :
4119 : : /* Extract one of the components of the complex value CPLX. Extract the
4120 : : real part if IMAG_P is false, and the imaginary part if it's true. */
4121 : :
4122 : : rtx
4123 : 493826 : read_complex_part (rtx cplx, bool imag_p)
4124 : : {
4125 : 493826 : machine_mode cmode;
4126 : 493826 : scalar_mode imode;
4127 : 493826 : unsigned ibitsize;
4128 : :
4129 : 493826 : if (GET_CODE (cplx) == CONCAT)
4130 : 317707 : return XEXP (cplx, imag_p);
4131 : :
4132 : 176119 : cmode = GET_MODE (cplx);
4133 : 176119 : imode = GET_MODE_INNER (cmode);
4134 : 176119 : ibitsize = GET_MODE_BITSIZE (imode);
4135 : :
4136 : : /* Special case reads from complex constants that got spilled to memory. */
4137 : 176119 : if (MEM_P (cplx) && GET_CODE (XEXP (cplx, 0)) == SYMBOL_REF)
4138 : : {
4139 : 37915 : tree decl = SYMBOL_REF_DECL (XEXP (cplx, 0));
4140 : 37915 : if (decl && TREE_CODE (decl) == COMPLEX_CST)
4141 : : {
4142 : 0 : tree part = imag_p ? TREE_IMAGPART (decl) : TREE_REALPART (decl);
4143 : 0 : if (CONSTANT_CLASS_P (part))
4144 : 0 : return expand_expr (part, NULL_RTX, imode, EXPAND_NORMAL);
4145 : : }
4146 : : }
4147 : :
4148 : : /* For MEMs simplify_gen_subreg may generate an invalid new address
4149 : : because, e.g., the original address is considered mode-dependent
4150 : : by the target, which restricts simplify_subreg from invoking
4151 : : adjust_address_nv. Instead of preparing fallback support for an
4152 : : invalid address, we call adjust_address_nv directly. */
4153 : 176119 : if (MEM_P (cplx))
4154 : 236429 : return adjust_address_nv (cplx, imode,
4155 : : imag_p ? GET_MODE_SIZE (imode) : 0);
4156 : :
4157 : : /* If the sub-object is at least word sized, then we know that subregging
4158 : : will work. This special case is important, since extract_bit_field
4159 : : wants to operate on integer modes, and there's rarely an OImode to
4160 : : correspond to TCmode. */
4161 : 18431 : if (ibitsize >= BITS_PER_WORD
4162 : : /* For hard regs we have exact predicates. Assume we can split
4163 : : the original object if it spans an even number of hard regs.
4164 : : This special case is important for SCmode on 64-bit platforms
4165 : : where the natural size of floating-point regs is 32-bit. */
4166 : 18431 : || (REG_P (cplx)
4167 : 338 : && REGNO (cplx) < FIRST_PSEUDO_REGISTER
4168 : 292 : && REG_NREGS (cplx) % 2 == 0))
4169 : : {
4170 : 9111 : rtx ret = simplify_gen_subreg (imode, cplx, cmode,
4171 : 13666 : imag_p ? GET_MODE_SIZE (imode) : 0);
4172 : 9111 : if (ret)
4173 : : return ret;
4174 : : else
4175 : : /* simplify_gen_subreg may fail for sub-word MEMs. */
4176 : 0 : gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
4177 : : }
4178 : :
4179 : 13980 : return extract_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0,
4180 : : true, NULL_RTX, imode, imode, false, NULL);
4181 : : }
4182 : :
4183 : : /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
4184 : : NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
4185 : : represented in NEW_MODE. If FORCE is true, this will never happen, as
4186 : : we'll force-create a SUBREG if needed. */
4187 : :
4188 : : static rtx
4189 : 243156 : emit_move_change_mode (machine_mode new_mode,
4190 : : machine_mode old_mode, rtx x, bool force)
4191 : : {
4192 : 243156 : rtx ret;
4193 : :
4194 : 243156 : if (push_operand (x, GET_MODE (x)))
4195 : : {
4196 : 1318 : ret = gen_rtx_MEM (new_mode, XEXP (x, 0));
4197 : 1318 : MEM_COPY_ATTRIBUTES (ret, x);
4198 : : }
4199 : 241838 : else if (MEM_P (x))
4200 : : {
4201 : : /* We don't have to worry about changing the address since the
4202 : : size in bytes is supposed to be the same. */
4203 : 53005 : if (reload_in_progress)
4204 : : {
4205 : : /* Copy the MEM to change the mode and move any
4206 : : substitutions from the old MEM to the new one. */
4207 : 0 : ret = adjust_address_nv (x, new_mode, 0);
4208 : 0 : copy_replacements (x, ret);
4209 : : }
4210 : : else
4211 : 53005 : ret = adjust_address (x, new_mode, 0);
4212 : : }
4213 : : else
4214 : : {
4215 : : /* Note that we do want simplify_subreg's behavior of validating
4216 : : that the new mode is ok for a hard register. If we were to use
4217 : : simplify_gen_subreg, we would create the subreg, but would
4218 : : probably run into the target not being able to implement it. */
4219 : : /* Except, of course, when FORCE is true, when this is exactly what
4220 : : we want. Which is needed for CCmodes on some targets. */
4221 : 188833 : if (force)
4222 : 188833 : ret = simplify_gen_subreg (new_mode, x, old_mode, 0);
4223 : : else
4224 : 0 : ret = simplify_subreg (new_mode, x, old_mode, 0);
4225 : : }
4226 : :
4227 : 243156 : return ret;
4228 : : }
4229 : :
4230 : : /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
4231 : : an integer mode of the same size as MODE. Returns the instruction
4232 : : emitted, or NULL if such a move could not be generated. */
4233 : :
4234 : : static rtx_insn *
4235 : 121578 : emit_move_via_integer (machine_mode mode, rtx x, rtx y, bool force)
4236 : : {
4237 : 121578 : scalar_int_mode imode;
4238 : 121578 : enum insn_code code;
4239 : :
4240 : : /* There must exist a mode of the exact size we require. */
4241 : 121578 : if (!int_mode_for_mode (mode).exists (&imode))
4242 : 0 : return NULL;
4243 : :
4244 : : /* The target must support moves in this mode. */
4245 : 121578 : code = optab_handler (mov_optab, imode);
4246 : 121578 : if (code == CODE_FOR_nothing)
4247 : : return NULL;
4248 : :
4249 : 121578 : x = emit_move_change_mode (imode, mode, x, force);
4250 : 121578 : if (x == NULL_RTX)
4251 : : return NULL;
4252 : 121578 : y = emit_move_change_mode (imode, mode, y, force);
4253 : 121578 : if (y == NULL_RTX)
4254 : : return NULL;
4255 : 121578 : return emit_insn (GEN_FCN (code) (x, y));
4256 : : }
4257 : :
4258 : : /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
4259 : : Return an equivalent MEM that does not use an auto-increment. */
4260 : :
4261 : : rtx
4262 : 3593 : emit_move_resolve_push (machine_mode mode, rtx x)
4263 : : {
4264 : 3593 : enum rtx_code code = GET_CODE (XEXP (x, 0));
4265 : 3593 : rtx temp;
4266 : :
4267 : 7186 : poly_int64 adjust = GET_MODE_SIZE (mode);
4268 : : #ifdef PUSH_ROUNDING
4269 : 3593 : adjust = PUSH_ROUNDING (adjust);
4270 : : #endif
4271 : 3593 : if (code == PRE_DEC || code == POST_DEC)
4272 : 3197 : adjust = -adjust;
4273 : 396 : else if (code == PRE_MODIFY || code == POST_MODIFY)
4274 : : {
4275 : 396 : rtx expr = XEXP (XEXP (x, 0), 1);
4276 : :
4277 : 396 : gcc_assert (GET_CODE (expr) == PLUS || GET_CODE (expr) == MINUS);
4278 : 396 : poly_int64 val = rtx_to_poly_int64 (XEXP (expr, 1));
4279 : 396 : if (GET_CODE (expr) == MINUS)
4280 : 0 : val = -val;
4281 : 396 : gcc_assert (known_eq (adjust, val) || known_eq (adjust, -val));
4282 : : adjust = val;
4283 : : }
4284 : :
4285 : : /* Do not use anti_adjust_stack, since we don't want to update
4286 : : stack_pointer_delta. */
4287 : 3593 : temp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
4288 : 3593 : gen_int_mode (adjust, Pmode), stack_pointer_rtx,
4289 : : 0, OPTAB_LIB_WIDEN);
4290 : 3593 : if (temp != stack_pointer_rtx)
4291 : 0 : emit_move_insn (stack_pointer_rtx, temp);
4292 : :
4293 : 3593 : switch (code)
4294 : : {
4295 : 3593 : case PRE_INC:
4296 : 3593 : case PRE_DEC:
4297 : 3593 : case PRE_MODIFY:
4298 : 3593 : temp = stack_pointer_rtx;
4299 : 3593 : break;
4300 : : case POST_INC:
4301 : : case POST_DEC:
4302 : : case POST_MODIFY:
4303 : 0 : temp = plus_constant (Pmode, stack_pointer_rtx, -adjust);
4304 : 0 : break;
4305 : 0 : default:
4306 : 0 : gcc_unreachable ();
4307 : : }
4308 : :
4309 : 3593 : return replace_equiv_address (x, temp);
4310 : : }
4311 : :
4312 : : /* A subroutine of emit_move_complex. Generate a move from Y into X.
4313 : : X is known to satisfy push_operand, and MODE is known to be complex.
4314 : : Returns the last instruction emitted. */
4315 : :
4316 : : rtx_insn *
4317 : 5225 : emit_move_complex_push (machine_mode mode, rtx x, rtx y)
4318 : : {
4319 : 5225 : scalar_mode submode = GET_MODE_INNER (mode);
4320 : 5225 : bool imag_first;
4321 : :
4322 : : #ifdef PUSH_ROUNDING
4323 : 10450 : poly_int64 submodesize = GET_MODE_SIZE (submode);
4324 : :
4325 : : /* In case we output to the stack, but the size is smaller than the
4326 : : machine can push exactly, we need to use move instructions. */
4327 : 5225 : if (maybe_ne (PUSH_ROUNDING (submodesize), submodesize))
4328 : : {
4329 : 718 : x = emit_move_resolve_push (mode, x);
4330 : 718 : return emit_move_insn (x, y);
4331 : : }
4332 : : #endif
4333 : :
4334 : : /* Note that the real part always precedes the imag part in memory
4335 : : regardless of machine's endianness. */
4336 : 4507 : switch (GET_CODE (XEXP (x, 0)))
4337 : : {
4338 : : case PRE_DEC:
4339 : : case POST_DEC:
4340 : : imag_first = true;
4341 : : break;
4342 : 0 : case PRE_INC:
4343 : 0 : case POST_INC:
4344 : 0 : imag_first = false;
4345 : 0 : break;
4346 : 0 : default:
4347 : 0 : gcc_unreachable ();
4348 : : }
4349 : :
4350 : 4507 : emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
4351 : : read_complex_part (y, imag_first));
4352 : 4507 : return emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
4353 : 9014 : read_complex_part (y, !imag_first));
4354 : : }
4355 : :
4356 : : /* A subroutine of emit_move_complex. Perform the move from Y to X
4357 : : via two moves of the parts. Returns the last instruction emitted. */
4358 : :
4359 : : rtx_insn *
4360 : 76756 : emit_move_complex_parts (rtx x, rtx y)
4361 : : {
4362 : : /* Show the output dies here. This is necessary for SUBREGs
4363 : : of pseudos since we cannot track their lifetimes correctly;
4364 : : hard regs shouldn't appear here except as return values. */
4365 : 76756 : if (!reload_completed && !reload_in_progress
4366 : 153512 : && REG_P (x) && !reg_overlap_mentioned_p (x, y))
4367 : 5577 : emit_clobber (x);
4368 : :
4369 : 76756 : write_complex_part (x, read_complex_part (y, false), false, true);
4370 : 76756 : write_complex_part (x, read_complex_part (y, true), true, false);
4371 : :
4372 : 76756 : return get_last_insn ();
4373 : : }
4374 : :
4375 : : /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
4376 : : MODE is known to be complex. Returns the last instruction emitted. */
4377 : :
4378 : : static rtx_insn *
4379 : 80978 : emit_move_complex (machine_mode mode, rtx x, rtx y)
4380 : : {
4381 : 80978 : bool try_int;
4382 : :
4383 : : /* Need to take special care for pushes, to maintain proper ordering
4384 : : of the data, and possibly extra padding. */
4385 : 80978 : if (push_operand (x, mode))
4386 : 4617 : return emit_move_complex_push (mode, x, y);
4387 : :
4388 : : /* See if we can coerce the target into moving both values at once, except
4389 : : for floating point where we favor moving as parts if this is easy. */
4390 : 76361 : if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
4391 : 68161 : && optab_handler (mov_optab, GET_MODE_INNER (mode)) != CODE_FOR_nothing
4392 : 68161 : && !(REG_P (x)
4393 : 1672 : && HARD_REGISTER_P (x)
4394 : 300 : && REG_NREGS (x) == 1)
4395 : 144522 : && !(REG_P (y)
4396 : 2748 : && HARD_REGISTER_P (y)
4397 : 1374 : && REG_NREGS (y) == 1))
4398 : : try_int = false;
4399 : : /* Not possible if the values are inherently not adjacent. */
4400 : 8200 : else if (GET_CODE (x) == CONCAT || GET_CODE (y) == CONCAT)
4401 : : try_int = false;
4402 : : /* Is possible if both are registers (or subregs of registers). */
4403 : 754 : else if (register_operand (x, mode) && register_operand (y, mode))
4404 : : try_int = true;
4405 : : /* If one of the operands is a memory, and alignment constraints
4406 : : are friendly enough, we may be able to do combined memory operations.
4407 : : We do not attempt this if Y is a constant because that combination is
4408 : : usually better with the by-parts thing below. */
4409 : 633 : else if ((MEM_P (x) ? !CONSTANT_P (y) : MEM_P (y))
4410 : : && (!STRICT_ALIGNMENT
4411 : : || get_mode_alignment (mode) == BIGGEST_ALIGNMENT))
4412 : : try_int = true;
4413 : : else
4414 : : try_int = false;
4415 : :
4416 : : if (try_int)
4417 : : {
4418 : 754 : rtx_insn *ret;
4419 : :
4420 : : /* For memory to memory moves, optimal behavior can be had with the
4421 : : existing block move logic. But use normal expansion if optimizing
4422 : : for size. */
4423 : 754 : if (MEM_P (x) && MEM_P (y))
4424 : : {
4425 : 724 : emit_block_move (x, y, gen_int_mode (GET_MODE_SIZE (mode), Pmode),
4426 : 359 : (optimize_insn_for_speed_p()
4427 : : ? BLOCK_OP_NO_LIBCALL : BLOCK_OP_NORMAL));
4428 : 359 : return get_last_insn ();
4429 : : }
4430 : :
4431 : 395 : ret = emit_move_via_integer (mode, x, y, true);
4432 : 395 : if (ret)
4433 : : return ret;
4434 : : }
4435 : :
4436 : 75607 : return emit_move_complex_parts (x, y);
4437 : : }
4438 : :
4439 : : /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
4440 : : MODE is known to be MODE_CC. Returns the last instruction emitted. */
4441 : :
4442 : : static rtx_insn *
4443 : 0 : emit_move_ccmode (machine_mode mode, rtx x, rtx y)
4444 : : {
4445 : 0 : rtx_insn *ret;
4446 : :
4447 : : /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
4448 : 0 : if (mode != CCmode)
4449 : : {
4450 : 0 : enum insn_code code = optab_handler (mov_optab, CCmode);
4451 : 0 : if (code != CODE_FOR_nothing)
4452 : : {
4453 : 0 : x = emit_move_change_mode (CCmode, mode, x, true);
4454 : 0 : y = emit_move_change_mode (CCmode, mode, y, true);
4455 : 0 : return emit_insn (GEN_FCN (code) (x, y));
4456 : : }
4457 : : }
4458 : :
4459 : : /* Otherwise, find the MODE_INT mode of the same width. */
4460 : 0 : ret = emit_move_via_integer (mode, x, y, false);
4461 : 0 : gcc_assert (ret != NULL);
4462 : : return ret;
4463 : : }
4464 : :
4465 : : /* Return true if word I of OP lies entirely in the
4466 : : undefined bits of a paradoxical subreg. */
4467 : :
4468 : : static bool
4469 : 0 : undefined_operand_subword_p (const_rtx op, int i)
4470 : : {
4471 : 0 : if (GET_CODE (op) != SUBREG)
4472 : : return false;
4473 : 0 : machine_mode innermostmode = GET_MODE (SUBREG_REG (op));
4474 : 0 : poly_int64 offset = i * UNITS_PER_WORD + subreg_memory_offset (op);
4475 : 0 : return (known_ge (offset, GET_MODE_SIZE (innermostmode))
4476 : 0 : || known_le (offset, -UNITS_PER_WORD));
4477 : : }
4478 : :
4479 : : /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
4480 : : MODE is any multi-word or full-word mode that lacks a move_insn
4481 : : pattern. Note that you will get better code if you define such
4482 : : patterns, even if they must turn into multiple assembler instructions. */
4483 : :
4484 : : static rtx_insn *
4485 : 0 : emit_move_multi_word (machine_mode mode, rtx x, rtx y)
4486 : : {
4487 : 0 : rtx_insn *last_insn = 0;
4488 : 0 : rtx_insn *seq;
4489 : 0 : rtx inner;
4490 : 0 : bool need_clobber;
4491 : 0 : int i, mode_size;
4492 : :
4493 : : /* This function can only handle cases where the number of words is
4494 : : known at compile time. */
4495 : 0 : mode_size = GET_MODE_SIZE (mode).to_constant ();
4496 : 0 : gcc_assert (mode_size >= UNITS_PER_WORD);
4497 : :
4498 : : /* If X is a push on the stack, do the push now and replace
4499 : : X with a reference to the stack pointer. */
4500 : 0 : if (push_operand (x, mode))
4501 : 0 : x = emit_move_resolve_push (mode, x);
4502 : :
4503 : : /* If we are in reload, see if either operand is a MEM whose address
4504 : : is scheduled for replacement. */
4505 : 0 : if (reload_in_progress && MEM_P (x)
4506 : 0 : && (inner = find_replacement (&XEXP (x, 0))) != XEXP (x, 0))
4507 : 0 : x = replace_equiv_address_nv (x, inner);
4508 : 0 : if (reload_in_progress && MEM_P (y)
4509 : 0 : && (inner = find_replacement (&XEXP (y, 0))) != XEXP (y, 0))
4510 : 0 : y = replace_equiv_address_nv (y, inner);
4511 : :
4512 : 0 : start_sequence ();
4513 : :
4514 : 0 : need_clobber = false;
4515 : 0 : for (i = 0; i < CEIL (mode_size, UNITS_PER_WORD); i++)
4516 : : {
4517 : : /* Do not generate code for a move if it would go entirely
4518 : : to the non-existing bits of a paradoxical subreg. */
4519 : 0 : if (undefined_operand_subword_p (x, i))
4520 : 0 : continue;
4521 : :
4522 : 0 : rtx xpart = operand_subword (x, i, 1, mode);
4523 : 0 : rtx ypart;
4524 : :
4525 : : /* Do not generate code for a move if it would come entirely
4526 : : from the undefined bits of a paradoxical subreg. */
4527 : 0 : if (undefined_operand_subword_p (y, i))
4528 : 0 : continue;
4529 : :
4530 : 0 : ypart = operand_subword (y, i, 1, mode);
4531 : :
4532 : : /* If we can't get a part of Y, put Y into memory if it is a
4533 : : constant. Otherwise, force it into a register. Then we must
4534 : : be able to get a part of Y. */
4535 : 0 : if (ypart == 0 && CONSTANT_P (y))
4536 : : {
4537 : 0 : y = use_anchored_address (force_const_mem (mode, y));
4538 : 0 : ypart = operand_subword (y, i, 1, mode);
4539 : : }
4540 : 0 : else if (ypart == 0)
4541 : 0 : ypart = operand_subword_force (y, i, mode);
4542 : :
4543 : 0 : gcc_assert (xpart && ypart);
4544 : :
4545 : 0 : need_clobber |= (GET_CODE (xpart) == SUBREG);
4546 : :
4547 : 0 : last_insn = emit_move_insn (xpart, ypart);
4548 : : }
4549 : :
4550 : 0 : seq = get_insns ();
4551 : 0 : end_sequence ();
4552 : :
4553 : : /* Show the output dies here. This is necessary for SUBREGs
4554 : : of pseudos since we cannot track their lifetimes correctly;
4555 : : hard regs shouldn't appear here except as return values.
4556 : : We never want to emit such a clobber after reload. */
4557 : 0 : if (x != y
4558 : 0 : && ! (reload_in_progress || reload_completed)
4559 : 0 : && need_clobber != 0)
4560 : 0 : emit_clobber (x);
4561 : :
4562 : 0 : emit_insn (seq);
4563 : :
4564 : 0 : return last_insn;
4565 : : }
4566 : :
4567 : : /* Low level part of emit_move_insn.
4568 : : Called just like emit_move_insn, but assumes X and Y
4569 : : are basically valid. */
4570 : :
4571 : : rtx_insn *
4572 : 75608750 : emit_move_insn_1 (rtx x, rtx y)
4573 : : {
4574 : 75608750 : machine_mode mode = GET_MODE (x);
4575 : 75608750 : enum insn_code code;
4576 : :
4577 : 75608750 : gcc_assert ((unsigned int) mode < (unsigned int) MAX_MACHINE_MODE);
4578 : :
4579 : 75608750 : code = optab_handler (mov_optab, mode);
4580 : 75608750 : if (code != CODE_FOR_nothing)
4581 : 75406589 : return emit_insn (GEN_FCN (code) (x, y));
4582 : :
4583 : : /* Expand complex moves by moving real part and imag part. */
4584 : 202161 : if (COMPLEX_MODE_P (mode))
4585 : 80978 : return emit_move_complex (mode, x, y);
4586 : :
4587 : : if (GET_MODE_CLASS (mode) == MODE_DECIMAL_FLOAT
4588 : : || ALL_FIXED_POINT_MODE_P (mode))
4589 : : {
4590 : 121183 : rtx_insn *result = emit_move_via_integer (mode, x, y, true);
4591 : :
4592 : : /* If we can't find an integer mode, use multi words. */
4593 : 121183 : if (result)
4594 : : return result;
4595 : : else
4596 : 0 : return emit_move_multi_word (mode, x, y);
4597 : : }
4598 : :
4599 : : if (GET_MODE_CLASS (mode) == MODE_CC)
4600 : 0 : return emit_move_ccmode (mode, x, y);
4601 : :
4602 : : /* Try using a move pattern for the corresponding integer mode. This is
4603 : : only safe when simplify_subreg can convert MODE constants into integer
4604 : : constants. At present, it can only do this reliably if the value
4605 : : fits within a HOST_WIDE_INT. */
4606 : 0 : if (!CONSTANT_P (y)
4607 : 0 : || known_le (GET_MODE_BITSIZE (mode), HOST_BITS_PER_WIDE_INT))
4608 : : {
4609 : 0 : rtx_insn *ret = emit_move_via_integer (mode, x, y, lra_in_progress);
4610 : :
4611 : 0 : if (ret)
4612 : : {
4613 : 0 : if (! lra_in_progress || recog (PATTERN (ret), ret, 0) >= 0)
4614 : 0 : return ret;
4615 : : }
4616 : : }
4617 : :
4618 : 0 : return emit_move_multi_word (mode, x, y);
4619 : : }
4620 : :
4621 : : /* Generate code to copy Y into X.
4622 : : Both Y and X must have the same mode, except that
4623 : : Y can be a constant with VOIDmode.
4624 : : This mode cannot be BLKmode; use emit_block_move for that.
4625 : :
4626 : : Return the last instruction emitted. */
4627 : :
4628 : : rtx_insn *
4629 : 68281706 : emit_move_insn (rtx x, rtx y)
4630 : : {
4631 : 68281706 : machine_mode mode = GET_MODE (x);
4632 : 68281706 : rtx y_cst = NULL_RTX;
4633 : 68281706 : rtx_insn *last_insn;
4634 : 68281706 : rtx set;
4635 : :
4636 : 68281706 : gcc_assert (mode != BLKmode
4637 : : && (GET_MODE (y) == mode || GET_MODE (y) == VOIDmode));
4638 : :
4639 : : /* If we have a copy that looks like one of the following patterns:
4640 : : (set (subreg:M1 (reg:M2 ...)) (subreg:M1 (reg:M2 ...)))
4641 : : (set (subreg:M1 (reg:M2 ...)) (mem:M1 ADDR))
4642 : : (set (mem:M1 ADDR) (subreg:M1 (reg:M2 ...)))
4643 : : (set (subreg:M1 (reg:M2 ...)) (constant C))
4644 : : where mode M1 is equal in size to M2, try to detect whether the
4645 : : mode change involves an implicit round trip through memory.
4646 : : If so, see if we can avoid that by removing the subregs and
4647 : : doing the move in mode M2 instead. */
4648 : :
4649 : 68281706 : rtx x_inner = NULL_RTX;
4650 : 68281706 : rtx y_inner = NULL_RTX;
4651 : :
4652 : 71049682 : auto candidate_subreg_p = [&](rtx subreg) {
4653 : 2767976 : return (REG_P (SUBREG_REG (subreg))
4654 : 8302209 : && known_eq (GET_MODE_SIZE (GET_MODE (SUBREG_REG (subreg))),
4655 : : GET_MODE_SIZE (GET_MODE (subreg)))
4656 : 3071064 : && optab_handler (mov_optab, GET_MODE (SUBREG_REG (subreg)))
4657 : 2767976 : != CODE_FOR_nothing);
4658 : : };
4659 : :
4660 : 68287628 : auto candidate_mem_p = [&](machine_mode innermode, rtx mem) {
4661 : 5922 : return (!targetm.can_change_mode_class (innermode, GET_MODE (mem), ALL_REGS)
4662 : 5922 : && !push_operand (mem, GET_MODE (mem))
4663 : : /* Not a candiate if innermode requires too much alignment. */
4664 : 11784 : && (MEM_ALIGN (mem) >= GET_MODE_ALIGNMENT (innermode)
4665 : 252 : || targetm.slow_unaligned_access (GET_MODE (mem),
4666 : 126 : MEM_ALIGN (mem))
4667 : 252 : || !targetm.slow_unaligned_access (innermode,
4668 : 126 : MEM_ALIGN (mem))));
4669 : : };
4670 : :
4671 : 68281706 : if (SUBREG_P (x) && candidate_subreg_p (x))
4672 : 9593 : x_inner = SUBREG_REG (x);
4673 : :
4674 : 68281706 : if (SUBREG_P (y) && candidate_subreg_p (y))
4675 : 292161 : y_inner = SUBREG_REG (y);
4676 : :
4677 : 68281706 : if (x_inner != NULL_RTX
4678 : 68281706 : && y_inner != NULL_RTX
4679 : 1098 : && GET_MODE (x_inner) == GET_MODE (y_inner)
4680 : 68282395 : && !targetm.can_change_mode_class (GET_MODE (x_inner), mode, ALL_REGS))
4681 : : {
4682 : 689 : x = x_inner;
4683 : 689 : y = y_inner;
4684 : 689 : mode = GET_MODE (x_inner);
4685 : : }
4686 : 68281017 : else if (x_inner != NULL_RTX
4687 : 8904 : && MEM_P (y)
4688 : 68281388 : && candidate_mem_p (GET_MODE (x_inner), y))
4689 : : {
4690 : 371 : x = x_inner;
4691 : 371 : y = adjust_address (y, GET_MODE (x_inner), 0);
4692 : 371 : mode = GET_MODE (x_inner);
4693 : : }
4694 : 68280646 : else if (y_inner != NULL_RTX
4695 : 291472 : && MEM_P (x)
4696 : 68286197 : && candidate_mem_p (GET_MODE (y_inner), x))
4697 : : {
4698 : 5491 : x = adjust_address (x, GET_MODE (y_inner), 0);
4699 : 5491 : y = y_inner;
4700 : 5491 : mode = GET_MODE (y_inner);
4701 : : }
4702 : 68275155 : else if (x_inner != NULL_RTX
4703 : 8533 : && CONSTANT_P (y)
4704 : 451 : && !targetm.can_change_mode_class (GET_MODE (x_inner),
4705 : : mode, ALL_REGS)
4706 : 68275606 : && (y_inner = simplify_subreg (GET_MODE (x_inner), y, mode, 0)))
4707 : : {
4708 : 451 : x = x_inner;
4709 : 451 : y = y_inner;
4710 : 451 : mode = GET_MODE (x_inner);
4711 : : }
4712 : :
4713 : 68281706 : if (CONSTANT_P (y))
4714 : : {
4715 : 16128123 : if (optimize
4716 : 12669750 : && SCALAR_FLOAT_MODE_P (GET_MODE (x))
4717 : 16891487 : && (last_insn = compress_float_constant (x, y)))
4718 : : return last_insn;
4719 : :
4720 : 16059091 : y_cst = y;
4721 : :
4722 : 16059091 : if (!targetm.legitimate_constant_p (mode, y))
4723 : : {
4724 : 485409 : y = force_const_mem (mode, y);
4725 : :
4726 : : /* If the target's cannot_force_const_mem prevented the spill,
4727 : : assume that the target's move expanders will also take care
4728 : : of the non-legitimate constant. */
4729 : 485409 : if (!y)
4730 : : y = y_cst;
4731 : : else
4732 : 465761 : y = use_anchored_address (y);
4733 : : }
4734 : : }
4735 : :
4736 : : /* If X or Y are memory references, verify that their addresses are valid
4737 : : for the machine. */
4738 : 68212674 : if (MEM_P (x)
4739 : 83597985 : && (! memory_address_addr_space_p (GET_MODE (x), XEXP (x, 0),
4740 : 13153508 : MEM_ADDR_SPACE (x))
4741 : 2231970 : && ! push_operand (x, GET_MODE (x))))
4742 : 167 : x = validize_mem (x);
4743 : :
4744 : 68212674 : if (MEM_P (y)
4745 : 85106460 : && ! memory_address_addr_space_p (GET_MODE (y), XEXP (y, 0),
4746 : 16893786 : MEM_ADDR_SPACE (y)))
4747 : 9251 : y = validize_mem (y);
4748 : :
4749 : 68212674 : gcc_assert (mode != BLKmode);
4750 : :
4751 : 68212674 : last_insn = emit_move_insn_1 (x, y);
4752 : :
4753 : 16059091 : if (y_cst && REG_P (x)
4754 : 11906209 : && (set = single_set (last_insn)) != NULL_RTX
4755 : 11906209 : && SET_DEST (set) == x
4756 : 80104431 : && ! rtx_equal_p (y_cst, SET_SRC (set)))
4757 : 1208835 : set_unique_reg_note (last_insn, REG_EQUAL, copy_rtx (y_cst));
4758 : :
4759 : : return last_insn;
4760 : : }
4761 : :
4762 : : /* Generate the body of an instruction to copy Y into X.
4763 : : It may be a list of insns, if one insn isn't enough. */
4764 : :
4765 : : rtx_insn *
4766 : 7395996 : gen_move_insn (rtx x, rtx y)
4767 : : {
4768 : 7395996 : rtx_insn *seq;
4769 : :
4770 : 7395996 : start_sequence ();
4771 : 7395996 : emit_move_insn_1 (x, y);
4772 : 7395996 : seq = get_insns ();
4773 : 7395996 : end_sequence ();
4774 : 7395996 : return seq;
4775 : : }
4776 : :
4777 : : /* If Y is representable exactly in a narrower mode, and the target can
4778 : : perform the extension directly from constant or memory, then emit the
4779 : : move as an extension. */
4780 : :
4781 : : static rtx_insn *
4782 : 763364 : compress_float_constant (rtx x, rtx y)
4783 : : {
4784 : 763364 : machine_mode dstmode = GET_MODE (x);
4785 : 763364 : machine_mode orig_srcmode = GET_MODE (y);
4786 : 763364 : machine_mode srcmode;
4787 : 763364 : const REAL_VALUE_TYPE *r;
4788 : 763364 : int oldcost, newcost;
4789 : 763364 : bool speed = optimize_insn_for_speed_p ();
4790 : :
4791 : 763364 : r = CONST_DOUBLE_REAL_VALUE (y);
4792 : :
4793 : 763364 : if (targetm.legitimate_constant_p (dstmode, y))
4794 : 761911 : oldcost = set_src_cost (y, orig_srcmode, speed);
4795 : : else
4796 : 1453 : oldcost = set_src_cost (force_const_mem (dstmode, y), dstmode, speed);
4797 : :
4798 : 2697829 : FOR_EACH_MODE_UNTIL (srcmode, orig_srcmode)
4799 : : {
4800 : 2003497 : enum insn_code ic;
4801 : 2003497 : rtx trunc_y;
4802 : 2003497 : rtx_insn *last_insn;
4803 : :
4804 : : /* Skip if the target can't extend this way. */
4805 : 2003497 : ic = can_extend_p (dstmode, srcmode, 0);
4806 : 2003497 : if (ic == CODE_FOR_nothing)
4807 : 1593931 : continue;
4808 : :
4809 : : /* Skip if the narrowed value isn't exact. */
4810 : 409566 : if (! exact_real_truncate (srcmode, r))
4811 : 51718 : continue;
4812 : :
4813 : 357848 : trunc_y = const_double_from_real_value (*r, srcmode);
4814 : :
4815 : 357848 : if (targetm.legitimate_constant_p (srcmode, trunc_y))
4816 : : {
4817 : : /* Skip if the target needs extra instructions to perform
4818 : : the extension. */
4819 : 353558 : if (!insn_operand_matches (ic, 1, trunc_y))
4820 : 3258 : continue;
4821 : : /* This is valid, but may not be cheaper than the original. */
4822 : 350300 : newcost = set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y),
4823 : : dstmode, speed);
4824 : 350300 : if (oldcost < newcost)
4825 : 281268 : continue;
4826 : : }
4827 : 4290 : else if (float_extend_from_mem[dstmode][srcmode])
4828 : : {
4829 : 0 : trunc_y = force_const_mem (srcmode, trunc_y);
4830 : : /* This is valid, but may not be cheaper than the original. */
4831 : 0 : newcost = set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y),
4832 : : dstmode, speed);
4833 : 0 : if (oldcost < newcost)
4834 : 0 : continue;
4835 : 0 : trunc_y = validize_mem (trunc_y);
4836 : : }
4837 : : else
4838 : 4290 : continue;
4839 : :
4840 : : /* For CSE's benefit, force the compressed constant pool entry
4841 : : into a new pseudo. This constant may be used in different modes,
4842 : : and if not, combine will put things back together for us. */
4843 : 69032 : trunc_y = force_reg (srcmode, trunc_y);
4844 : :
4845 : : /* If x is a hard register, perform the extension into a pseudo,
4846 : : so that e.g. stack realignment code is aware of it. */
4847 : 69032 : rtx target = x;
4848 : 69032 : if (REG_P (x) && HARD_REGISTER_P (x))
4849 : 1 : target = gen_reg_rtx (dstmode);
4850 : :
4851 : 69032 : emit_unop_insn (ic, target, trunc_y, UNKNOWN);
4852 : 69032 : last_insn = get_last_insn ();
4853 : :
4854 : 69032 : if (REG_P (target))
4855 : 58111 : set_unique_reg_note (last_insn, REG_EQUAL, y);
4856 : :
4857 : 69032 : if (target != x)
4858 : 1 : return emit_move_insn (x, target);
4859 : : return last_insn;
4860 : : }
4861 : :
4862 : : return NULL;
4863 : : }
4864 : :
4865 : : /* Pushing data onto the stack. */
4866 : :
4867 : : /* Push a block of length SIZE (perhaps variable)
4868 : : and return an rtx to address the beginning of the block.
4869 : : The value may be virtual_outgoing_args_rtx.
4870 : :
4871 : : EXTRA is the number of bytes of padding to push in addition to SIZE.
4872 : : BELOW nonzero means this padding comes at low addresses;
4873 : : otherwise, the padding comes at high addresses. */
4874 : :
4875 : : rtx
4876 : 266441 : push_block (rtx size, poly_int64 extra, int below)
4877 : : {
4878 : 266441 : rtx temp;
4879 : :
4880 : 266441 : size = convert_modes (Pmode, ptr_mode, size, 1);
4881 : 266441 : if (CONSTANT_P (size))
4882 : 266441 : anti_adjust_stack (plus_constant (Pmode, size, extra));
4883 : 0 : else if (REG_P (size) && known_eq (extra, 0))
4884 : 0 : anti_adjust_stack (size);
4885 : : else
4886 : : {
4887 : 0 : temp = copy_to_mode_reg (Pmode, size);
4888 : 0 : if (maybe_ne (extra, 0))
4889 : 0 : temp = expand_binop (Pmode, add_optab, temp,
4890 : 0 : gen_int_mode (extra, Pmode),
4891 : : temp, 0, OPTAB_LIB_WIDEN);
4892 : 0 : anti_adjust_stack (temp);
4893 : : }
4894 : :
4895 : 266441 : if (STACK_GROWS_DOWNWARD)
4896 : : {
4897 : 266441 : temp = virtual_outgoing_args_rtx;
4898 : 266441 : if (maybe_ne (extra, 0) && below)
4899 : 0 : temp = plus_constant (Pmode, temp, extra);
4900 : : }
4901 : : else
4902 : : {
4903 : : poly_int64 csize;
4904 : : if (poly_int_rtx_p (size, &csize))
4905 : : temp = plus_constant (Pmode, virtual_outgoing_args_rtx,
4906 : : -csize - (below ? 0 : extra));
4907 : : else if (maybe_ne (extra, 0) && !below)
4908 : : temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
4909 : : negate_rtx (Pmode, plus_constant (Pmode, size,
4910 : : extra)));
4911 : : else
4912 : : temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
4913 : : negate_rtx (Pmode, size));
4914 : : }
4915 : :
4916 : 266441 : return memory_address (NARROWEST_INT_MODE, temp);
4917 : : }
4918 : :
4919 : : /* A utility routine that returns the base of an auto-inc memory, or NULL. */
4920 : :
4921 : : static rtx
4922 : 2567132 : mem_autoinc_base (rtx mem)
4923 : : {
4924 : 0 : if (MEM_P (mem))
4925 : : {
4926 : 1557992 : rtx addr = XEXP (mem, 0);
4927 : 1557992 : if (GET_RTX_CLASS (GET_CODE (addr)) == RTX_AUTOINC)
4928 : 1025375 : return XEXP (addr, 0);
4929 : : }
4930 : : return NULL;
4931 : : }
4932 : :
4933 : : /* A utility routine used here, in reload, and in try_split. The insns
4934 : : after PREV up to and including LAST are known to adjust the stack,
4935 : : with a final value of END_ARGS_SIZE. Iterate backward from LAST
4936 : : placing notes as appropriate. PREV may be NULL, indicating the
4937 : : entire insn sequence prior to LAST should be scanned.
4938 : :
4939 : : The set of allowed stack pointer modifications is small:
4940 : : (1) One or more auto-inc style memory references (aka pushes),
4941 : : (2) One or more addition/subtraction with the SP as destination,
4942 : : (3) A single move insn with the SP as destination,
4943 : : (4) A call_pop insn,
4944 : : (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
4945 : :
4946 : : Insns in the sequence that do not modify the SP are ignored,
4947 : : except for noreturn calls.
4948 : :
4949 : : The return value is the amount of adjustment that can be trivially
4950 : : verified, via immediate operand or auto-inc. If the adjustment
4951 : : cannot be trivially extracted, the return value is HOST_WIDE_INT_MIN. */
4952 : :
4953 : : poly_int64
4954 : 4226069 : find_args_size_adjust (rtx_insn *insn)
4955 : : {
4956 : 4226069 : rtx dest, set, pat;
4957 : 4226069 : int i;
4958 : :
4959 : 4226069 : pat = PATTERN (insn);
4960 : 4226069 : set = NULL;
4961 : :
4962 : : /* Look for a call_pop pattern. */
4963 : 4226069 : if (CALL_P (insn))
4964 : : {
4965 : : /* We have to allow non-call_pop patterns for the case
4966 : : of emit_single_push_insn of a TLS address. */
4967 : 2596921 : if (GET_CODE (pat) != PARALLEL)
4968 : 2583396 : return 0;
4969 : :
4970 : : /* All call_pop have a stack pointer adjust in the parallel.
4971 : : The call itself is always first, and the stack adjust is
4972 : : usually last, so search from the end. */
4973 : 13525 : for (i = XVECLEN (pat, 0) - 1; i > 0; --i)
4974 : : {
4975 : 13525 : set = XVECEXP (pat, 0, i);
4976 : 13525 : if (GET_CODE (set) != SET)
4977 : 0 : continue;
4978 : 13525 : dest = SET_DEST (set);
4979 : 13525 : if (dest == stack_pointer_rtx)
4980 : : break;
4981 : : }
4982 : : /* We'd better have found the stack pointer adjust. */
4983 : 13525 : if (i == 0)
4984 : 0 : return 0;
4985 : : /* Fall through to process the extracted SET and DEST
4986 : : as if it was a standalone insn. */
4987 : : }
4988 : 1629148 : else if (GET_CODE (pat) == SET)
4989 : : set = pat;
4990 : 244034 : else if ((set = single_set (insn)) != NULL)
4991 : : ;
4992 : 47585 : else if (GET_CODE (pat) == PARALLEL)
4993 : : {
4994 : : /* ??? Some older ports use a parallel with a stack adjust
4995 : : and a store for a PUSH_ROUNDING pattern, rather than a
4996 : : PRE/POST_MODIFY rtx. Don't force them to update yet... */
4997 : : /* ??? See h8300 and m68k, pushqi1. */
4998 : 0 : for (i = XVECLEN (pat, 0) - 1; i >= 0; --i)
4999 : : {
5000 : 0 : set = XVECEXP (pat, 0, i);
5001 : 0 : if (GET_CODE (set) != SET)
5002 : 0 : continue;
5003 : 0 : dest = SET_DEST (set);
5004 : 0 : if (dest == stack_pointer_rtx)
5005 : : break;
5006 : :
5007 : : /* We do not expect an auto-inc of the sp in the parallel. */
5008 : 0 : gcc_checking_assert (mem_autoinc_base (dest) != stack_pointer_rtx);
5009 : 0 : gcc_checking_assert (mem_autoinc_base (SET_SRC (set))
5010 : : != stack_pointer_rtx);
5011 : : }
5012 : 0 : if (i < 0)
5013 : 0 : return 0;
5014 : : }
5015 : : else
5016 : 47585 : return 0;
5017 : :
5018 : 1595088 : dest = SET_DEST (set);
5019 : :
5020 : : /* Look for direct modifications of the stack pointer. */
5021 : 1595088 : if (REG_P (dest) && REGNO (dest) == STACK_POINTER_REGNUM)
5022 : : {
5023 : : /* Look for a trivial adjustment, otherwise assume nothing. */
5024 : : /* Note that the SPU restore_stack_block pattern refers to
5025 : : the stack pointer in V4SImode. Consider that non-trivial. */
5026 : 311522 : poly_int64 offset;
5027 : 311522 : if (SCALAR_INT_MODE_P (GET_MODE (dest))
5028 : 311522 : && strip_offset (SET_SRC (set), &offset) == stack_pointer_rtx)
5029 : 309157 : return offset;
5030 : : /* ??? Reload can generate no-op moves, which will be cleaned
5031 : : up later. Recognize it and continue searching. */
5032 : 2365 : else if (rtx_equal_p (dest, SET_SRC (set)))
5033 : 0 : return 0;
5034 : : else
5035 : 2365 : return HOST_WIDE_INT_MIN;
5036 : : }
5037 : : else
5038 : : {
5039 : 1283566 : rtx mem, addr;
5040 : :
5041 : : /* Otherwise only think about autoinc patterns. */
5042 : 2321087 : if (mem_autoinc_base (dest) == stack_pointer_rtx)
5043 : : {
5044 : 916265 : mem = dest;
5045 : 1259517 : gcc_checking_assert (mem_autoinc_base (SET_SRC (set))
5046 : : != stack_pointer_rtx);
5047 : : }
5048 : 544520 : else if (mem_autoinc_base (SET_SRC (set)) == stack_pointer_rtx)
5049 : : mem = SET_SRC (set);
5050 : : else
5051 : 258191 : return 0;
5052 : :
5053 : 1025375 : addr = XEXP (mem, 0);
5054 : 1025375 : switch (GET_CODE (addr))
5055 : : {
5056 : 109110 : case PRE_INC:
5057 : 109110 : case POST_INC:
5058 : 218220 : return GET_MODE_SIZE (GET_MODE (mem));
5059 : 898605 : case PRE_DEC:
5060 : 898605 : case POST_DEC:
5061 : 1797210 : return -GET_MODE_SIZE (GET_MODE (mem));
5062 : 17660 : case PRE_MODIFY:
5063 : 17660 : case POST_MODIFY:
5064 : 17660 : addr = XEXP (addr, 1);
5065 : 17660 : gcc_assert (GET_CODE (addr) == PLUS);
5066 : 17660 : gcc_assert (XEXP (addr, 0) == stack_pointer_rtx);
5067 : 17660 : return rtx_to_poly_int64 (XEXP (addr, 1));
5068 : 0 : default:
5069 : 0 : gcc_unreachable ();
5070 : : }
5071 : : }
5072 : : }
5073 : :
5074 : : poly_int64
5075 : 662189 : fixup_args_size_notes (rtx_insn *prev, rtx_insn *last,
5076 : : poly_int64 end_args_size)
5077 : : {
5078 : 662189 : poly_int64 args_size = end_args_size;
5079 : 662189 : bool saw_unknown = false;
5080 : 662189 : rtx_insn *insn;
5081 : :
5082 : 1893866 : for (insn = last; insn != prev; insn = PREV_INSN (insn))
5083 : : {
5084 : 1231677 : if (!NONDEBUG_INSN_P (insn))
5085 : 0 : continue;
5086 : :
5087 : : /* We might have existing REG_ARGS_SIZE notes, e.g. when pushing
5088 : : a call argument containing a TLS address that itself requires
5089 : : a call to __tls_get_addr. The handling of stack_pointer_delta
5090 : : in emit_single_push_insn is supposed to ensure that any such
5091 : : notes are already correct. */
5092 : 1231677 : rtx note = find_reg_note (insn, REG_ARGS_SIZE, NULL_RTX);
5093 : 1231677 : gcc_assert (!note || known_eq (args_size, get_args_size (note)));
5094 : :
5095 : 1231677 : poly_int64 this_delta = find_args_size_adjust (insn);
5096 : 1231677 : if (known_eq (this_delta, 0))
5097 : : {
5098 : 608089 : if (!CALL_P (insn)
5099 : 5 : || ACCUMULATE_OUTGOING_ARGS
5100 : 304052 : || find_reg_note (insn, REG_NORETURN, NULL_RTX) == NULL_RTX)
5101 : 304042 : continue;
5102 : : }
5103 : :
5104 : 927635 : gcc_assert (!saw_unknown);
5105 : 927635 : if (known_eq (this_delta, HOST_WIDE_INT_MIN))
5106 : 2342 : saw_unknown = true;
5107 : :
5108 : 927635 : if (!note)
5109 : 927635 : add_args_size_note (insn, args_size);
5110 : : if (STACK_GROWS_DOWNWARD)
5111 : 927635 : this_delta = -poly_uint64 (this_delta);
5112 : :
5113 : 927635 : if (saw_unknown)
5114 : : args_size = HOST_WIDE_INT_MIN;
5115 : : else
5116 : 1231677 : args_size -= this_delta;
5117 : : }
5118 : :
5119 : 662189 : return args_size;
5120 : : }
5121 : :
5122 : : #ifdef PUSH_ROUNDING
5123 : : /* Emit single push insn. */
5124 : :
5125 : : static void
5126 : 1818401 : emit_single_push_insn_1 (machine_mode mode, rtx x, tree type)
5127 : : {
5128 : 1818401 : rtx dest_addr;
5129 : 3636802 : poly_int64 rounded_size = PUSH_ROUNDING (GET_MODE_SIZE (mode));
5130 : 1818401 : rtx dest;
5131 : 1818401 : enum insn_code icode;
5132 : :
5133 : : /* If there is push pattern, use it. Otherwise try old way of throwing
5134 : : MEM representing push operation to move expander. */
5135 : 1818401 : icode = optab_handler (push_optab, mode);
5136 : 1818401 : if (icode != CODE_FOR_nothing)
5137 : : {
5138 : 0 : class expand_operand ops[1];
5139 : :
5140 : 0 : create_input_operand (&ops[0], x, mode);
5141 : 0 : if (maybe_expand_insn (icode, 1, ops))
5142 : 0 : return;
5143 : : }
5144 : 3636802 : if (known_eq (GET_MODE_SIZE (mode), rounded_size))
5145 : 1717120 : dest_addr = gen_rtx_fmt_e (STACK_PUSH_CODE, Pmode, stack_pointer_rtx);
5146 : : /* If we are to pad downward, adjust the stack pointer first and
5147 : : then store X into the stack location using an offset. This is
5148 : : because emit_move_insn does not know how to pad; it does not have
5149 : : access to type. */
5150 : 101281 : else if (targetm.calls.function_arg_padding (mode, type) == PAD_DOWNWARD)
5151 : : {
5152 : 0 : emit_move_insn (stack_pointer_rtx,
5153 : 0 : expand_binop (Pmode,
5154 : : STACK_GROWS_DOWNWARD ? sub_optab
5155 : : : add_optab,
5156 : : stack_pointer_rtx,
5157 : 0 : gen_int_mode (rounded_size, Pmode),
5158 : : NULL_RTX, 0, OPTAB_LIB_WIDEN));
5159 : :
5160 : 0 : poly_int64 offset = rounded_size - GET_MODE_SIZE (mode);
5161 : 0 : if (STACK_GROWS_DOWNWARD && STACK_PUSH_CODE == POST_DEC)
5162 : : /* We have already decremented the stack pointer, so get the
5163 : : previous value. */
5164 : : offset += rounded_size;
5165 : :
5166 : 0 : if (!STACK_GROWS_DOWNWARD && STACK_PUSH_CODE == POST_INC)
5167 : : /* We have already incremented the stack pointer, so get the
5168 : : previous value. */
5169 : : offset -= rounded_size;
5170 : :
5171 : 0 : dest_addr = plus_constant (Pmode, stack_pointer_rtx, offset);
5172 : : }
5173 : : else
5174 : : {
5175 : : if (STACK_GROWS_DOWNWARD)
5176 : : /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
5177 : 101281 : dest_addr = plus_constant (Pmode, stack_pointer_rtx, -rounded_size);
5178 : : else
5179 : : /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
5180 : : dest_addr = plus_constant (Pmode, stack_pointer_rtx, rounded_size);
5181 : :
5182 : 101281 : dest_addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, dest_addr);
5183 : : }
5184 : :
5185 : 1818401 : dest = gen_rtx_MEM (mode, dest_addr);
5186 : :
5187 : 1818401 : if (type != 0)
5188 : : {
5189 : 1818354 : set_mem_attributes (dest, type, 1);
5190 : :
5191 : 1818354 : if (cfun->tail_call_marked)
5192 : : /* Function incoming arguments may overlap with sibling call
5193 : : outgoing arguments and we cannot allow reordering of reads
5194 : : from function arguments with stores to outgoing arguments
5195 : : of sibling calls. */
5196 : 137723 : set_mem_alias_set (dest, 0);
5197 : : }
5198 : 1818401 : emit_move_insn (dest, x);
5199 : : }
5200 : :
5201 : : /* Emit and annotate a single push insn. */
5202 : :
5203 : : static void
5204 : 1818401 : emit_single_push_insn (machine_mode mode, rtx x, tree type)
5205 : : {
5206 : 1818401 : poly_int64 delta, old_delta = stack_pointer_delta;
5207 : 1818401 : rtx_insn *prev = get_last_insn ();
5208 : 1818401 : rtx_insn *last;
5209 : :
5210 : 1818401 : emit_single_push_insn_1 (mode, x, type);
5211 : :
5212 : : /* Adjust stack_pointer_delta to describe the situation after the push
5213 : : we just performed. Note that we must do this after the push rather
5214 : : than before the push in case calculating X needs pushes and pops of
5215 : : its own (e.g. if calling __tls_get_addr). The REG_ARGS_SIZE notes
5216 : : for such pushes and pops must not include the effect of the future
5217 : : push of X. */
5218 : 3636802 : stack_pointer_delta += PUSH_ROUNDING (GET_MODE_SIZE (mode));
5219 : :
5220 : 1818401 : last = get_last_insn ();
5221 : :
5222 : : /* Notice the common case where we emitted exactly one insn. */
5223 : 1818401 : if (PREV_INSN (last) == prev)
5224 : : {
5225 : 1709869 : add_args_size_note (last, stack_pointer_delta);
5226 : 1709869 : return;
5227 : : }
5228 : :
5229 : 108532 : delta = fixup_args_size_notes (prev, last, stack_pointer_delta);
5230 : 108532 : gcc_assert (known_eq (delta, HOST_WIDE_INT_MIN)
5231 : : || known_eq (delta, old_delta));
5232 : : }
5233 : : #endif
5234 : :
5235 : : /* If reading SIZE bytes from X will end up reading from
5236 : : Y return the number of bytes that overlap. Return -1
5237 : : if there is no overlap or -2 if we can't determine
5238 : : (for example when X and Y have different base registers). */
5239 : :
5240 : : static int
5241 : 0 : memory_load_overlap (rtx x, rtx y, HOST_WIDE_INT size)
5242 : : {
5243 : 0 : rtx tmp = plus_constant (Pmode, x, size);
5244 : 0 : rtx sub = simplify_gen_binary (MINUS, Pmode, tmp, y);
5245 : :
5246 : 0 : if (!CONST_INT_P (sub))
5247 : : return -2;
5248 : :
5249 : 0 : HOST_WIDE_INT val = INTVAL (sub);
5250 : :
5251 : 0 : return IN_RANGE (val, 1, size) ? val : -1;
5252 : : }
5253 : :
5254 : : /* Generate code to push X onto the stack, assuming it has mode MODE and
5255 : : type TYPE.
5256 : : MODE is redundant except when X is a CONST_INT (since they don't
5257 : : carry mode info).
5258 : : SIZE is an rtx for the size of data to be copied (in bytes),
5259 : : needed only if X is BLKmode.
5260 : : Return true if successful. May return false if asked to push a
5261 : : partial argument during a sibcall optimization (as specified by
5262 : : SIBCALL_P) and the incoming and outgoing pointers cannot be shown
5263 : : to not overlap.
5264 : :
5265 : : ALIGN (in bits) is maximum alignment we can assume.
5266 : :
5267 : : If PARTIAL and REG are both nonzero, then copy that many of the first
5268 : : bytes of X into registers starting with REG, and push the rest of X.
5269 : : The amount of space pushed is decreased by PARTIAL bytes.
5270 : : REG must be a hard register in this case.
5271 : : If REG is zero but PARTIAL is not, take any all others actions for an
5272 : : argument partially in registers, but do not actually load any
5273 : : registers.
5274 : :
5275 : : EXTRA is the amount in bytes of extra space to leave next to this arg.
5276 : : This is ignored if an argument block has already been allocated.
5277 : :
5278 : : On a machine that lacks real push insns, ARGS_ADDR is the address of
5279 : : the bottom of the argument block for this call. We use indexing off there
5280 : : to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
5281 : : argument block has not been preallocated.
5282 : :
5283 : : ARGS_SO_FAR is the size of args previously pushed for this call.
5284 : :
5285 : : REG_PARM_STACK_SPACE is nonzero if functions require stack space
5286 : : for arguments passed in registers. If nonzero, it will be the number
5287 : : of bytes required. */
5288 : :
5289 : : bool
5290 : 2139451 : emit_push_insn (rtx x, machine_mode mode, tree type, rtx size,
5291 : : unsigned int align, int partial, rtx reg, poly_int64 extra,
5292 : : rtx args_addr, rtx args_so_far, int reg_parm_stack_space,
5293 : : rtx alignment_pad, bool sibcall_p)
5294 : : {
5295 : 2139451 : rtx xinner;
5296 : 2139451 : pad_direction stack_direction
5297 : : = STACK_GROWS_DOWNWARD ? PAD_DOWNWARD : PAD_UPWARD;
5298 : :
5299 : : /* Decide where to pad the argument: PAD_DOWNWARD for below,
5300 : : PAD_UPWARD for above, or PAD_NONE for don't pad it.
5301 : : Default is below for small data on big-endian machines; else above. */
5302 : 2139451 : pad_direction where_pad = targetm.calls.function_arg_padding (mode, type);
5303 : :
5304 : : /* Invert direction if stack is post-decrement.
5305 : : FIXME: why? */
5306 : 2139451 : if (STACK_PUSH_CODE == POST_DEC)
5307 : : if (where_pad != PAD_NONE)
5308 : : where_pad = (where_pad == PAD_DOWNWARD ? PAD_UPWARD : PAD_DOWNWARD);
5309 : :
5310 : 2139451 : xinner = x;
5311 : :
5312 : 2139451 : int nregs = partial / UNITS_PER_WORD;
5313 : 2139451 : rtx *tmp_regs = NULL;
5314 : 2139451 : int overlapping = 0;
5315 : :
5316 : 2139451 : if (mode == BLKmode
5317 : : || (STRICT_ALIGNMENT && align < GET_MODE_ALIGNMENT (mode)))
5318 : : {
5319 : : /* Copy a block into the stack, entirely or partially. */
5320 : :
5321 : 266529 : rtx temp;
5322 : 266529 : int used;
5323 : 266529 : int offset;
5324 : 266529 : int skip;
5325 : :
5326 : 266529 : offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
5327 : 266529 : used = partial - offset;
5328 : :
5329 : 266529 : if (mode != BLKmode)
5330 : : {
5331 : : /* A value is to be stored in an insufficiently aligned
5332 : : stack slot; copy via a suitably aligned slot if
5333 : : necessary. */
5334 : : size = gen_int_mode (GET_MODE_SIZE (mode), Pmode);
5335 : : if (!MEM_P (xinner))
5336 : : {
5337 : : temp = assign_temp (type, 1, 1);
5338 : : emit_move_insn (temp, xinner);
5339 : : xinner = temp;
5340 : : }
5341 : : }
5342 : :
5343 : 266529 : gcc_assert (size);
5344 : :
5345 : : /* USED is now the # of bytes we need not copy to the stack
5346 : : because registers will take care of them. */
5347 : :
5348 : 266529 : if (partial != 0)
5349 : 0 : xinner = adjust_address (xinner, BLKmode, used);
5350 : :
5351 : : /* If the partial register-part of the arg counts in its stack size,
5352 : : skip the part of stack space corresponding to the registers.
5353 : : Otherwise, start copying to the beginning of the stack space,
5354 : : by setting SKIP to 0. */
5355 : 266529 : skip = (reg_parm_stack_space == 0) ? 0 : used;
5356 : :
5357 : : #ifdef PUSH_ROUNDING
5358 : : /* NB: Let the backend known the number of bytes to push and
5359 : : decide if push insns should be generated. */
5360 : 266529 : unsigned int push_size;
5361 : 266529 : if (CONST_INT_P (size))
5362 : 266529 : push_size = INTVAL (size);
5363 : : else
5364 : : push_size = 0;
5365 : :
5366 : : /* Do it with several push insns if that doesn't take lots of insns
5367 : : and if there is no difficulty with push insns that skip bytes
5368 : : on the stack for alignment purposes. */
5369 : 266529 : if (args_addr == 0
5370 : 266484 : && targetm.calls.push_argument (push_size)
5371 : 3786 : && CONST_INT_P (size)
5372 : 3786 : && skip == 0
5373 : 3786 : && MEM_ALIGN (xinner) >= align
5374 : 2880 : && can_move_by_pieces ((unsigned) INTVAL (size) - used, align)
5375 : : /* Here we avoid the case of a structure whose weak alignment
5376 : : forces many pushes of a small amount of data,
5377 : : and such small pushes do rounding that causes trouble. */
5378 : 2880 : && ((!targetm.slow_unaligned_access (word_mode, align))
5379 : 0 : || align >= BIGGEST_ALIGNMENT
5380 : 0 : || known_eq (PUSH_ROUNDING (align / BITS_PER_UNIT),
5381 : : align / BITS_PER_UNIT))
5382 : 269409 : && known_eq (PUSH_ROUNDING (INTVAL (size)), INTVAL (size)))
5383 : : {
5384 : : /* Push padding now if padding above and stack grows down,
5385 : : or if padding below and stack grows up.
5386 : : But if space already allocated, this has already been done. */
5387 : 45 : if (maybe_ne (extra, 0)
5388 : : && args_addr == 0
5389 : 0 : && where_pad != PAD_NONE
5390 : 45 : && where_pad != stack_direction)
5391 : 0 : anti_adjust_stack (gen_int_mode (extra, Pmode));
5392 : :
5393 : 45 : move_by_pieces (NULL, xinner, INTVAL (size) - used, align,
5394 : : RETURN_BEGIN);
5395 : : }
5396 : : else
5397 : : #endif /* PUSH_ROUNDING */
5398 : : {
5399 : 266484 : rtx target;
5400 : :
5401 : : /* Otherwise make space on the stack and copy the data
5402 : : to the address of that space. */
5403 : :
5404 : : /* Deduct words put into registers from the size we must copy. */
5405 : 266484 : if (partial != 0)
5406 : : {
5407 : 0 : if (CONST_INT_P (size))
5408 : 0 : size = GEN_INT (INTVAL (size) - used);
5409 : : else
5410 : 0 : size = expand_binop (GET_MODE (size), sub_optab, size,
5411 : 0 : gen_int_mode (used, GET_MODE (size)),
5412 : : NULL_RTX, 0, OPTAB_LIB_WIDEN);
5413 : : }
5414 : :
5415 : : /* Get the address of the stack space.
5416 : : In this case, we do not deal with EXTRA separately.
5417 : : A single stack adjust will do. */
5418 : 266484 : poly_int64 const_args_so_far;
5419 : 266484 : if (! args_addr)
5420 : : {
5421 : 266439 : temp = push_block (size, extra, where_pad == PAD_DOWNWARD);
5422 : 266439 : extra = 0;
5423 : : }
5424 : 45 : else if (poly_int_rtx_p (args_so_far, &const_args_so_far))
5425 : 45 : temp = memory_address (BLKmode,
5426 : : plus_constant (Pmode, args_addr,
5427 : : skip + const_args_so_far));
5428 : : else
5429 : 0 : temp = memory_address (BLKmode,
5430 : : plus_constant (Pmode,
5431 : : gen_rtx_PLUS (Pmode,
5432 : : args_addr,
5433 : : args_so_far),
5434 : : skip));
5435 : :
5436 : 266484 : if (!ACCUMULATE_OUTGOING_ARGS)
5437 : : {
5438 : : /* If the source is referenced relative to the stack pointer,
5439 : : copy it to another register to stabilize it. We do not need
5440 : : to do this if we know that we won't be changing sp. */
5441 : :
5442 : 266484 : if (reg_mentioned_p (virtual_stack_dynamic_rtx, temp)
5443 : 266484 : || reg_mentioned_p (virtual_outgoing_args_rtx, temp))
5444 : 266439 : temp = copy_to_reg (temp);
5445 : : }
5446 : :
5447 : 266484 : target = gen_rtx_MEM (BLKmode, temp);
5448 : :
5449 : : /* We do *not* set_mem_attributes here, because incoming arguments
5450 : : may overlap with sibling call outgoing arguments and we cannot
5451 : : allow reordering of reads from function arguments with stores
5452 : : to outgoing arguments of sibling calls. We do, however, want
5453 : : to record the alignment of the stack slot. */
5454 : : /* ALIGN may well be better aligned than TYPE, e.g. due to
5455 : : PARM_BOUNDARY. Assume the caller isn't lying. */
5456 : 266484 : set_mem_align (target, align);
5457 : :
5458 : : /* If part should go in registers and pushing to that part would
5459 : : overwrite some of the values that need to go into regs, load the
5460 : : overlapping values into temporary pseudos to be moved into the hard
5461 : : regs at the end after the stack pushing has completed.
5462 : : We cannot load them directly into the hard regs here because
5463 : : they can be clobbered by the block move expansions.
5464 : : See PR 65358. */
5465 : :
5466 : 266484 : if (partial > 0 && reg != 0 && mode == BLKmode
5467 : 0 : && GET_CODE (reg) != PARALLEL)
5468 : : {
5469 : 0 : overlapping = memory_load_overlap (XEXP (x, 0), temp, partial);
5470 : 0 : if (overlapping > 0)
5471 : : {
5472 : 0 : gcc_assert (overlapping % UNITS_PER_WORD == 0);
5473 : 0 : overlapping /= UNITS_PER_WORD;
5474 : :
5475 : 0 : tmp_regs = XALLOCAVEC (rtx, overlapping);
5476 : :
5477 : 0 : for (int i = 0; i < overlapping; i++)
5478 : 0 : tmp_regs[i] = gen_reg_rtx (word_mode);
5479 : :
5480 : 0 : for (int i = 0; i < overlapping; i++)
5481 : 0 : emit_move_insn (tmp_regs[i],
5482 : 0 : operand_subword_force (target, i, mode));
5483 : : }
5484 : 0 : else if (overlapping == -1)
5485 : : overlapping = 0;
5486 : : /* Could not determine whether there is overlap.
5487 : : Fail the sibcall. */
5488 : : else
5489 : : {
5490 : 0 : overlapping = 0;
5491 : 0 : if (sibcall_p)
5492 : 0 : return false;
5493 : : }
5494 : : }
5495 : :
5496 : : /* If source is a constant VAR_DECL with a simple constructor,
5497 : : store the constructor to the stack instead of moving it. */
5498 : 266484 : const_tree decl;
5499 : 266484 : HOST_WIDE_INT sz;
5500 : 266484 : if (partial == 0
5501 : 266484 : && MEM_P (xinner)
5502 : 266484 : && SYMBOL_REF_P (XEXP (xinner, 0))
5503 : 81590 : && (decl = SYMBOL_REF_DECL (XEXP (xinner, 0))) != NULL_TREE
5504 : 81590 : && VAR_P (decl)
5505 : 81590 : && TREE_READONLY (decl)
5506 : 4348 : && !TREE_SIDE_EFFECTS (decl)
5507 : 4348 : && immediate_const_ctor_p (DECL_INITIAL (decl), 2)
5508 : 6 : && (sz = int_expr_size (DECL_INITIAL (decl))) > 0
5509 : 6 : && CONST_INT_P (size)
5510 : 266490 : && INTVAL (size) == sz)
5511 : 0 : store_constructor (DECL_INITIAL (decl), target, 0, sz, false);
5512 : : else
5513 : 266484 : emit_block_move (target, xinner, size, BLOCK_OP_CALL_PARM);
5514 : : }
5515 : : }
5516 : 1872922 : else if (partial > 0)
5517 : : {
5518 : : /* Scalar partly in registers. This case is only supported
5519 : : for fixed-wdth modes. */
5520 : 0 : int num_words = GET_MODE_SIZE (mode).to_constant ();
5521 : 0 : num_words /= UNITS_PER_WORD;
5522 : 0 : int i;
5523 : 0 : int not_stack;
5524 : : /* # bytes of start of argument
5525 : : that we must make space for but need not store. */
5526 : 0 : int offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
5527 : 0 : int args_offset = INTVAL (args_so_far);
5528 : 0 : int skip;
5529 : :
5530 : : /* Push padding now if padding above and stack grows down,
5531 : : or if padding below and stack grows up.
5532 : : But if space already allocated, this has already been done. */
5533 : 0 : if (maybe_ne (extra, 0)
5534 : 0 : && args_addr == 0
5535 : 0 : && where_pad != PAD_NONE
5536 : 0 : && where_pad != stack_direction)
5537 : 0 : anti_adjust_stack (gen_int_mode (extra, Pmode));
5538 : :
5539 : : /* If we make space by pushing it, we might as well push
5540 : : the real data. Otherwise, we can leave OFFSET nonzero
5541 : : and leave the space uninitialized. */
5542 : 0 : if (args_addr == 0)
5543 : 0 : offset = 0;
5544 : :
5545 : : /* Now NOT_STACK gets the number of words that we don't need to
5546 : : allocate on the stack. Convert OFFSET to words too. */
5547 : 0 : not_stack = (partial - offset) / UNITS_PER_WORD;
5548 : 0 : offset /= UNITS_PER_WORD;
5549 : :
5550 : : /* If the partial register-part of the arg counts in its stack size,
5551 : : skip the part of stack space corresponding to the registers.
5552 : : Otherwise, start copying to the beginning of the stack space,
5553 : : by setting SKIP to 0. */
5554 : 0 : skip = (reg_parm_stack_space == 0) ? 0 : not_stack;
5555 : :
5556 : 0 : if (CONSTANT_P (x) && !targetm.legitimate_constant_p (mode, x))
5557 : 0 : x = validize_mem (force_const_mem (mode, x));
5558 : :
5559 : : /* If X is a hard register in a non-integer mode, copy it into a pseudo;
5560 : : SUBREGs of such registers are not allowed. */
5561 : 0 : if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER
5562 : 0 : && GET_MODE_CLASS (GET_MODE (x)) != MODE_INT))
5563 : 0 : x = copy_to_reg (x);
5564 : :
5565 : : /* Loop over all the words allocated on the stack for this arg. */
5566 : : /* We can do it by words, because any scalar bigger than a word
5567 : : has a size a multiple of a word. */
5568 : 0 : tree word_mode_type = lang_hooks.types.type_for_mode (word_mode, 1);
5569 : 0 : for (i = num_words - 1; i >= not_stack; i--)
5570 : 0 : if (i >= not_stack + offset)
5571 : 0 : if (!emit_push_insn (operand_subword_force (x, i, mode),
5572 : : word_mode, word_mode_type, NULL_RTX, align, 0,
5573 : 0 : NULL_RTX, 0, args_addr,
5574 : 0 : GEN_INT (args_offset + ((i - not_stack + skip)
5575 : : * UNITS_PER_WORD)),
5576 : : reg_parm_stack_space, alignment_pad, sibcall_p))
5577 : 0 : return false;
5578 : : }
5579 : : else
5580 : : {
5581 : 1872922 : rtx addr;
5582 : 1872922 : rtx dest;
5583 : :
5584 : : /* Push padding now if padding above and stack grows down,
5585 : : or if padding below and stack grows up.
5586 : : But if space already allocated, this has already been done. */
5587 : 1872922 : if (maybe_ne (extra, 0)
5588 : 0 : && args_addr == 0
5589 : 0 : && where_pad != PAD_NONE
5590 : 1872922 : && where_pad != stack_direction)
5591 : 0 : anti_adjust_stack (gen_int_mode (extra, Pmode));
5592 : :
5593 : : #ifdef PUSH_ROUNDING
5594 : 1872922 : if (args_addr == 0 && targetm.calls.push_argument (0))
5595 : 1818354 : emit_single_push_insn (mode, x, type);
5596 : : else
5597 : : #endif
5598 : : {
5599 : 54568 : addr = simplify_gen_binary (PLUS, Pmode, args_addr, args_so_far);
5600 : 54568 : dest = gen_rtx_MEM (mode, memory_address (mode, addr));
5601 : :
5602 : : /* We do *not* set_mem_attributes here, because incoming arguments
5603 : : may overlap with sibling call outgoing arguments and we cannot
5604 : : allow reordering of reads from function arguments with stores
5605 : : to outgoing arguments of sibling calls. We do, however, want
5606 : : to record the alignment of the stack slot. */
5607 : : /* ALIGN may well be better aligned than TYPE, e.g. due to
5608 : : PARM_BOUNDARY. Assume the caller isn't lying. */
5609 : 54568 : set_mem_align (dest, align);
5610 : :
5611 : 54568 : emit_move_insn (dest, x);
5612 : : }
5613 : : }
5614 : :
5615 : : /* Move the partial arguments into the registers and any overlapping
5616 : : values that we moved into the pseudos in tmp_regs. */
5617 : 2139451 : if (partial > 0 && reg != 0)
5618 : : {
5619 : : /* Handle calls that pass values in multiple non-contiguous locations.
5620 : : The Irix 6 ABI has examples of this. */
5621 : 0 : if (GET_CODE (reg) == PARALLEL)
5622 : 0 : emit_group_load (reg, x, type, -1);
5623 : : else
5624 : : {
5625 : 0 : gcc_assert (partial % UNITS_PER_WORD == 0);
5626 : 0 : move_block_to_reg (REGNO (reg), x, nregs - overlapping, mode);
5627 : :
5628 : 0 : for (int i = 0; i < overlapping; i++)
5629 : 0 : emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg)
5630 : 0 : + nregs - overlapping + i),
5631 : 0 : tmp_regs[i]);
5632 : :
5633 : : }
5634 : : }
5635 : :
5636 : 2139451 : if (maybe_ne (extra, 0) && args_addr == 0 && where_pad == stack_direction)
5637 : 0 : anti_adjust_stack (gen_int_mode (extra, Pmode));
5638 : :
5639 : 2139451 : if (alignment_pad && args_addr == 0)
5640 : 2084838 : anti_adjust_stack (alignment_pad);
5641 : :
5642 : : return true;
5643 : : }
5644 : :
5645 : : /* Return X if X can be used as a subtarget in a sequence of arithmetic
5646 : : operations. */
5647 : :
5648 : : static rtx
5649 : 195198036 : get_subtarget (rtx x)
5650 : : {
5651 : 195198036 : return (optimize
5652 : 50662315 : || x == 0
5653 : : /* Only registers can be subtargets. */
5654 : 16976352 : || !REG_P (x)
5655 : : /* Don't use hard regs to avoid extending their life. */
5656 : 11571004 : || REGNO (x) < FIRST_PSEUDO_REGISTER
5657 : 195198036 : ? 0 : x);
5658 : : }
5659 : :
5660 : : /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
5661 : : FIELD is a bitfield. Returns true if the optimization was successful,
5662 : : and there's nothing else to do. */
5663 : :
5664 : : static bool
5665 : 4492227 : optimize_bitfield_assignment_op (poly_uint64 pbitsize,
5666 : : poly_uint64 pbitpos,
5667 : : poly_uint64 pbitregion_start,
5668 : : poly_uint64 pbitregion_end,
5669 : : machine_mode mode1, rtx str_rtx,
5670 : : tree to, tree src, bool reverse)
5671 : : {
5672 : : /* str_mode is not guaranteed to be a scalar type. */
5673 : 4492227 : machine_mode str_mode = GET_MODE (str_rtx);
5674 : 4492227 : unsigned int str_bitsize;
5675 : 4492227 : tree op0, op1;
5676 : 4492227 : rtx value, result;
5677 : 4492227 : optab binop;
5678 : 4492227 : gimple *srcstmt;
5679 : 4492227 : enum tree_code code;
5680 : :
5681 : 4492227 : unsigned HOST_WIDE_INT bitsize, bitpos, bitregion_start, bitregion_end;
5682 : 4492227 : if (mode1 != VOIDmode
5683 : 68249 : || !pbitsize.is_constant (&bitsize)
5684 : 68249 : || !pbitpos.is_constant (&bitpos)
5685 : 68249 : || !pbitregion_start.is_constant (&bitregion_start)
5686 : 68249 : || !pbitregion_end.is_constant (&bitregion_end)
5687 : 68815 : || bitsize >= BITS_PER_WORD
5688 : 67980 : || !GET_MODE_BITSIZE (str_mode).is_constant (&str_bitsize)
5689 : 68546 : || str_bitsize > BITS_PER_WORD
5690 : 62343 : || TREE_SIDE_EFFECTS (to)
5691 : 4554455 : || TREE_THIS_VOLATILE (to))
5692 : : return false;
5693 : :
5694 : 62228 : STRIP_NOPS (src);
5695 : 62228 : if (TREE_CODE (src) != SSA_NAME)
5696 : : return false;
5697 : 20674 : if (TREE_CODE (TREE_TYPE (src)) != INTEGER_TYPE)
5698 : : return false;
5699 : :
5700 : 19519 : srcstmt = get_gimple_for_ssa_name (src);
5701 : 19519 : if (!srcstmt
5702 : 4229 : || !is_gimple_assign (srcstmt)
5703 : 23748 : || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt)) != tcc_binary)
5704 : : return false;
5705 : :
5706 : 447 : code = gimple_assign_rhs_code (srcstmt);
5707 : :
5708 : 447 : op0 = gimple_assign_rhs1 (srcstmt);
5709 : :
5710 : : /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
5711 : : to find its initialization. Hopefully the initialization will
5712 : : be from a bitfield load. */
5713 : 447 : if (TREE_CODE (op0) == SSA_NAME)
5714 : : {
5715 : 447 : gimple *op0stmt = get_gimple_for_ssa_name (op0);
5716 : :
5717 : : /* We want to eventually have OP0 be the same as TO, which
5718 : : should be a bitfield. */
5719 : 447 : if (!op0stmt
5720 : 417 : || !is_gimple_assign (op0stmt)
5721 : 864 : || gimple_assign_rhs_code (op0stmt) != TREE_CODE (to))
5722 : : return false;
5723 : 299 : op0 = gimple_assign_rhs1 (op0stmt);
5724 : : }
5725 : :
5726 : 299 : op1 = gimple_assign_rhs2 (srcstmt);
5727 : :
5728 : 299 : if (!operand_equal_p (to, op0, 0))
5729 : : return false;
5730 : :
5731 : 229 : if (MEM_P (str_rtx))
5732 : : {
5733 : 224 : unsigned HOST_WIDE_INT offset1;
5734 : :
5735 : 224 : if (str_bitsize == 0 || str_bitsize > BITS_PER_WORD)
5736 : 4 : str_bitsize = BITS_PER_WORD;
5737 : :
5738 : 224 : scalar_int_mode best_mode;
5739 : 224 : if (!get_best_mode (bitsize, bitpos, bitregion_start, bitregion_end,
5740 : 224 : MEM_ALIGN (str_rtx), str_bitsize, false, &best_mode))
5741 : 0 : return false;
5742 : 224 : str_mode = best_mode;
5743 : 224 : str_bitsize = GET_MODE_BITSIZE (best_mode);
5744 : :
5745 : 224 : offset1 = bitpos;
5746 : 224 : bitpos %= str_bitsize;
5747 : 224 : offset1 = (offset1 - bitpos) / BITS_PER_UNIT;
5748 : 224 : str_rtx = adjust_address (str_rtx, str_mode, offset1);
5749 : : }
5750 : 5 : else if (!REG_P (str_rtx) && GET_CODE (str_rtx) != SUBREG)
5751 : : return false;
5752 : :
5753 : : /* If the bit field covers the whole REG/MEM, store_field
5754 : : will likely generate better code. */
5755 : 229 : if (bitsize >= str_bitsize)
5756 : : return false;
5757 : :
5758 : : /* We can't handle fields split across multiple entities. */
5759 : 229 : if (bitpos + bitsize > str_bitsize)
5760 : : return false;
5761 : :
5762 : 229 : if (reverse ? !BYTES_BIG_ENDIAN : BYTES_BIG_ENDIAN)
5763 : 0 : bitpos = str_bitsize - bitpos - bitsize;
5764 : :
5765 : 229 : switch (code)
5766 : : {
5767 : 141 : case PLUS_EXPR:
5768 : 141 : case MINUS_EXPR:
5769 : : /* For now, just optimize the case of the topmost bitfield
5770 : : where we don't need to do any masking and also
5771 : : 1 bit bitfields where xor can be used.
5772 : : We might win by one instruction for the other bitfields
5773 : : too if insv/extv instructions aren't used, so that
5774 : : can be added later. */
5775 : 141 : if ((reverse || bitpos + bitsize != str_bitsize)
5776 : 97 : && (bitsize != 1 || TREE_CODE (op1) != INTEGER_CST))
5777 : : break;
5778 : :
5779 : 70 : value = expand_expr (op1, NULL_RTX, str_mode, EXPAND_NORMAL);
5780 : 70 : value = convert_modes (str_mode,
5781 : 70 : TYPE_MODE (TREE_TYPE (op1)), value,
5782 : 70 : TYPE_UNSIGNED (TREE_TYPE (op1)));
5783 : :
5784 : : /* We may be accessing data outside the field, which means
5785 : : we can alias adjacent data. */
5786 : 70 : if (MEM_P (str_rtx))
5787 : : {
5788 : 70 : str_rtx = shallow_copy_rtx (str_rtx);
5789 : 70 : set_mem_alias_set (str_rtx, 0);
5790 : 70 : set_mem_expr (str_rtx, 0);
5791 : : }
5792 : :
5793 : 70 : if (bitsize == 1 && (reverse || bitpos + bitsize != str_bitsize))
5794 : : {
5795 : 26 : value = expand_and (str_mode, value, const1_rtx, NULL);
5796 : 26 : binop = xor_optab;
5797 : : }
5798 : : else
5799 : 44 : binop = code == PLUS_EXPR ? add_optab : sub_optab;
5800 : :
5801 : 70 : value = expand_shift (LSHIFT_EXPR, str_mode, value, bitpos, NULL_RTX, 1);
5802 : 70 : if (reverse)
5803 : 0 : value = flip_storage_order (str_mode, value);
5804 : 70 : result = expand_binop (str_mode, binop, str_rtx,
5805 : : value, str_rtx, 1, OPTAB_WIDEN);
5806 : 70 : if (result != str_rtx)
5807 : 0 : emit_move_insn (str_rtx, result);
5808 : : return true;
5809 : :
5810 : 58 : case BIT_IOR_EXPR:
5811 : 58 : case BIT_XOR_EXPR:
5812 : 58 : if (TREE_CODE (op1) != INTEGER_CST)
5813 : : break;
5814 : 55 : value = expand_expr (op1, NULL_RTX, str_mode, EXPAND_NORMAL);
5815 : 55 : value = convert_modes (str_mode,
5816 : 55 : TYPE_MODE (TREE_TYPE (op1)), value,
5817 : 55 : TYPE_UNSIGNED (TREE_TYPE (op1)));
5818 : :
5819 : : /* We may be accessing data outside the field, which means
5820 : : we can alias adjacent data. */
5821 : 55 : if (MEM_P (str_rtx))
5822 : : {
5823 : 55 : str_rtx = shallow_copy_rtx (str_rtx);
5824 : 55 : set_mem_alias_set (str_rtx, 0);
5825 : 55 : set_mem_expr (str_rtx, 0);
5826 : : }
5827 : :
5828 : 55 : binop = code == BIT_IOR_EXPR ? ior_optab : xor_optab;
5829 : 55 : if (bitpos + bitsize != str_bitsize)
5830 : : {
5831 : 31 : rtx mask = gen_int_mode ((HOST_WIDE_INT_1U << bitsize) - 1,
5832 : : str_mode);
5833 : 31 : value = expand_and (str_mode, value, mask, NULL_RTX);
5834 : : }
5835 : 55 : value = expand_shift (LSHIFT_EXPR, str_mode, value, bitpos, NULL_RTX, 1);
5836 : 55 : if (reverse)
5837 : 0 : value = flip_storage_order (str_mode, value);
5838 : 55 : result = expand_binop (str_mode, binop, str_rtx,
5839 : : value, str_rtx, 1, OPTAB_WIDEN);
5840 : 55 : if (result != str_rtx)
5841 : 0 : emit_move_insn (str_rtx, result);
5842 : : return true;
5843 : :
5844 : : default:
5845 : : break;
5846 : : }
5847 : :
5848 : : return false;
5849 : : }
5850 : :
5851 : : /* In the C++ memory model, consecutive bit fields in a structure are
5852 : : considered one memory location.
5853 : :
5854 : : Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
5855 : : returns the bit range of consecutive bits in which this COMPONENT_REF
5856 : : belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
5857 : : and *OFFSET may be adjusted in the process.
5858 : :
5859 : : If the access does not need to be restricted, 0 is returned in both
5860 : : *BITSTART and *BITEND. */
5861 : :
5862 : : void
5863 : 818858 : get_bit_range (poly_uint64 *bitstart, poly_uint64 *bitend, tree exp,
5864 : : poly_int64 *bitpos, tree *offset)
5865 : : {
5866 : 818858 : poly_int64 bitoffset;
5867 : 818858 : tree field, repr;
5868 : :
5869 : 818858 : gcc_assert (TREE_CODE (exp) == COMPONENT_REF);
5870 : :
5871 : 818858 : field = TREE_OPERAND (exp, 1);
5872 : 818858 : repr = DECL_BIT_FIELD_REPRESENTATIVE (field);
5873 : : /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
5874 : : need to limit the range we can access. */
5875 : 818858 : if (!repr)
5876 : : {
5877 : 11617 : *bitstart = *bitend = 0;
5878 : 11617 : return;
5879 : : }
5880 : :
5881 : : /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
5882 : : part of a larger bit field, then the representative does not serve any
5883 : : useful purpose. This can occur in Ada. */
5884 : 807241 : if (handled_component_p (TREE_OPERAND (exp, 0)))
5885 : : {
5886 : 594692 : machine_mode rmode;
5887 : 594692 : poly_int64 rbitsize, rbitpos;
5888 : 594692 : tree roffset;
5889 : 594692 : int unsignedp, reversep, volatilep = 0;
5890 : 594692 : get_inner_reference (TREE_OPERAND (exp, 0), &rbitsize, &rbitpos,
5891 : : &roffset, &rmode, &unsignedp, &reversep,
5892 : : &volatilep);
5893 : 1189384 : if (!multiple_p (rbitpos, BITS_PER_UNIT))
5894 : : {
5895 : 0 : *bitstart = *bitend = 0;
5896 : 0 : return;
5897 : : }
5898 : : }
5899 : :
5900 : : /* Compute the adjustment to bitpos from the offset of the field
5901 : : relative to the representative. DECL_FIELD_OFFSET of field and
5902 : : repr are the same by construction if they are not constants,
5903 : : see finish_bitfield_layout. */
5904 : 807241 : poly_uint64 field_offset, repr_offset;
5905 : 807241 : if (poly_int_tree_p (DECL_FIELD_OFFSET (field), &field_offset)
5906 : 1614477 : && poly_int_tree_p (DECL_FIELD_OFFSET (repr), &repr_offset))
5907 : 807236 : bitoffset = (field_offset - repr_offset) * BITS_PER_UNIT;
5908 : : else
5909 : : bitoffset = 0;
5910 : 807241 : bitoffset += (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field))
5911 : 807241 : - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr)));
5912 : :
5913 : : /* If the adjustment is larger than bitpos, we would have a negative bit
5914 : : position for the lower bound and this may wreak havoc later. Adjust
5915 : : offset and bitpos to make the lower bound non-negative in that case. */
5916 : 807241 : if (maybe_gt (bitoffset, *bitpos))
5917 : : {
5918 : 11 : poly_int64 adjust_bits = upper_bound (bitoffset, *bitpos) - *bitpos;
5919 : 11 : poly_int64 adjust_bytes = exact_div (adjust_bits, BITS_PER_UNIT);
5920 : :
5921 : 11 : *bitpos += adjust_bits;
5922 : 11 : if (*offset == NULL_TREE)
5923 : 5 : *offset = size_int (-adjust_bytes);
5924 : : else
5925 : 6 : *offset = size_binop (MINUS_EXPR, *offset, size_int (adjust_bytes));
5926 : 11 : *bitstart = 0;
5927 : : }
5928 : : else
5929 : 807230 : *bitstart = *bitpos - bitoffset;
5930 : :
5931 : 807241 : *bitend = *bitstart + tree_to_poly_uint64 (DECL_SIZE (repr)) - 1;
5932 : : }
5933 : :
5934 : : /* Returns true if BASE is a DECL that does not reside in memory and
5935 : : has non-BLKmode. DECL_RTL must not be a MEM; if
5936 : : DECL_RTL was not set yet, return false. */
5937 : :
5938 : : bool
5939 : 5455224 : non_mem_decl_p (tree base)
5940 : : {
5941 : 5455224 : if (!DECL_P (base)
5942 : 5454924 : || TREE_ADDRESSABLE (base)
5943 : 8098904 : || DECL_MODE (base) == BLKmode)
5944 : : return false;
5945 : :
5946 : 1713953 : if (!DECL_RTL_SET_P (base))
5947 : : return false;
5948 : :
5949 : 1597455 : return (!MEM_P (DECL_RTL (base)));
5950 : : }
5951 : :
5952 : : /* Returns true if REF refers to an object that does not
5953 : : reside in memory and has non-BLKmode. */
5954 : :
5955 : : bool
5956 : 11565455 : mem_ref_refers_to_non_mem_p (tree ref)
5957 : : {
5958 : 11565455 : tree base;
5959 : :
5960 : 11565455 : if (TREE_CODE (ref) == MEM_REF
5961 : 11565455 : || TREE_CODE (ref) == TARGET_MEM_REF)
5962 : : {
5963 : 10073463 : tree addr = TREE_OPERAND (ref, 0);
5964 : :
5965 : 10073463 : if (TREE_CODE (addr) != ADDR_EXPR)
5966 : : return false;
5967 : :
5968 : 3963047 : base = TREE_OPERAND (addr, 0);
5969 : : }
5970 : : else
5971 : : base = ref;
5972 : :
5973 : 5455039 : return non_mem_decl_p (base);
5974 : : }
5975 : :
5976 : : /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
5977 : : is true, try generating a nontemporal store. */
5978 : :
5979 : : void
5980 : 17887818 : expand_assignment (tree to, tree from, bool nontemporal)
5981 : : {
5982 : 17887818 : rtx to_rtx = 0;
5983 : 17887818 : rtx result;
5984 : 17887818 : machine_mode mode;
5985 : 17887818 : unsigned int align;
5986 : 17887818 : enum insn_code icode;
5987 : :
5988 : : /* Don't crash if the lhs of the assignment was erroneous. */
5989 : 17887818 : if (TREE_CODE (to) == ERROR_MARK)
5990 : : {
5991 : 0 : expand_normal (from);
5992 : 0 : return;
5993 : : }
5994 : :
5995 : : /* Optimize away no-op moves without side-effects. */
5996 : 17887818 : if (operand_equal_p (to, from, 0))
5997 : : return;
5998 : :
5999 : : /* Handle misaligned stores. */
6000 : 17887745 : mode = TYPE_MODE (TREE_TYPE (to));
6001 : 17887745 : if ((TREE_CODE (to) == MEM_REF
6002 : 17887745 : || TREE_CODE (to) == TARGET_MEM_REF
6003 : 15723129 : || DECL_P (to))
6004 : 4011576 : && mode != BLKmode
6005 : 3543150 : && !mem_ref_refers_to_non_mem_p (to)
6006 : 6221064 : && ((align = get_object_alignment (to))
6007 : 3110532 : < GET_MODE_ALIGNMENT (mode))
6008 : 18329228 : && (((icode = optab_handler (movmisalign_optab, mode))
6009 : : != CODE_FOR_nothing)
6010 : 97435 : || targetm.slow_unaligned_access (mode, align)))
6011 : : {
6012 : 344048 : rtx reg, mem;
6013 : :
6014 : 344048 : reg = expand_expr (from, NULL_RTX, VOIDmode, EXPAND_NORMAL);
6015 : : /* Handle PARALLEL. */
6016 : 344048 : reg = maybe_emit_group_store (reg, TREE_TYPE (from));
6017 : 344048 : reg = force_not_mem (reg);
6018 : 344048 : mem = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
6019 : 344048 : if (TREE_CODE (to) == MEM_REF && REF_REVERSE_STORAGE_ORDER (to))
6020 : 0 : reg = flip_storage_order (mode, reg);
6021 : :
6022 : 344048 : if (icode != CODE_FOR_nothing)
6023 : : {
6024 : 344048 : class expand_operand ops[2];
6025 : :
6026 : 344048 : create_fixed_operand (&ops[0], mem);
6027 : 344048 : create_input_operand (&ops[1], reg, mode);
6028 : : /* The movmisalign<mode> pattern cannot fail, else the assignment
6029 : : would silently be omitted. */
6030 : 344048 : expand_insn (icode, 2, ops);
6031 : : }
6032 : : else
6033 : 0 : store_bit_field (mem, GET_MODE_BITSIZE (mode), 0, 0, 0, mode, reg,
6034 : : false, false);
6035 : 344048 : return;
6036 : : }
6037 : :
6038 : : /* Assignment of a structure component needs special treatment
6039 : : if the structure component's rtx is not simply a MEM.
6040 : : Assignment of an array element at a constant index, and assignment of
6041 : : an array element in an unaligned packed structure field, has the same
6042 : : problem. Same for (partially) storing into a non-memory object. */
6043 : 17543697 : if (handled_component_p (to)
6044 : 13321962 : || (TREE_CODE (to) == MEM_REF
6045 : 1595258 : && (REF_REVERSE_STORAGE_ORDER (to)
6046 : 1595242 : || mem_ref_refers_to_non_mem_p (to)))
6047 : 13173625 : || TREE_CODE (TREE_TYPE (to)) == ARRAY_TYPE)
6048 : : {
6049 : 4492375 : machine_mode mode1;
6050 : 4492375 : poly_int64 bitsize, bitpos;
6051 : 4492375 : poly_uint64 bitregion_start = 0;
6052 : 4492375 : poly_uint64 bitregion_end = 0;
6053 : 4492375 : tree offset;
6054 : 4492375 : int unsignedp, reversep, volatilep = 0;
6055 : 4492375 : tree tem;
6056 : :
6057 : 4492375 : push_temp_slots ();
6058 : 4492375 : tem = get_inner_reference (to, &bitsize, &bitpos, &offset, &mode1,
6059 : : &unsignedp, &reversep, &volatilep);
6060 : :
6061 : : /* Make sure bitpos is not negative, it can wreak havoc later. */
6062 : 4492375 : if (maybe_lt (bitpos, 0))
6063 : : {
6064 : 266 : gcc_assert (offset == NULL_TREE);
6065 : 266 : offset = size_int (bits_to_bytes_round_down (bitpos));
6066 : 266 : bitpos = num_trailing_bits (bitpos);
6067 : : }
6068 : :
6069 : 4492375 : if (TREE_CODE (to) == COMPONENT_REF
6070 : 4492375 : && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to, 1)))
6071 : 84966 : get_bit_range (&bitregion_start, &bitregion_end, to, &bitpos, &offset);
6072 : : /* The C++ memory model naturally applies to byte-aligned fields.
6073 : : However, if we do not have a DECL_BIT_FIELD_TYPE but BITPOS or
6074 : : BITSIZE are not byte-aligned, there is no need to limit the range
6075 : : we can access. This can occur with packed structures in Ada. */
6076 : 4407409 : else if (maybe_gt (bitsize, 0)
6077 : 4407394 : && multiple_p (bitsize, BITS_PER_UNIT)
6078 : 8814669 : && multiple_p (bitpos, BITS_PER_UNIT))
6079 : : {
6080 : 4407260 : bitregion_start = bitpos;
6081 : 4407260 : bitregion_end = bitpos + bitsize - 1;
6082 : : }
6083 : :
6084 : 4492375 : to_rtx = expand_expr (tem, NULL_RTX, VOIDmode, EXPAND_WRITE);
6085 : :
6086 : : /* If the field has a mode, we want to access it in the
6087 : : field's mode, not the computed mode.
6088 : : If a MEM has VOIDmode (external with incomplete type),
6089 : : use BLKmode for it instead. */
6090 : 4492375 : if (MEM_P (to_rtx))
6091 : : {
6092 : 3776179 : if (mode1 != VOIDmode)
6093 : 3708637 : to_rtx = adjust_address (to_rtx, mode1, 0);
6094 : 67542 : else if (GET_MODE (to_rtx) == VOIDmode)
6095 : 0 : to_rtx = adjust_address (to_rtx, BLKmode, 0);
6096 : : }
6097 : :
6098 : 4492375 : rtx stemp = NULL_RTX, old_to_rtx = NULL_RTX;
6099 : 4492375 : if (offset != 0)
6100 : : {
6101 : 171122 : machine_mode address_mode;
6102 : 171122 : rtx offset_rtx;
6103 : :
6104 : 171122 : if (!MEM_P (to_rtx))
6105 : : {
6106 : : /* We can get constant negative offsets into arrays with broken
6107 : : user code. Translate this to a trap instead of ICEing. */
6108 : 4 : if (TREE_CODE (offset) == INTEGER_CST)
6109 : : {
6110 : 1 : expand_builtin_trap ();
6111 : 1 : to_rtx = gen_rtx_MEM (BLKmode, const0_rtx);
6112 : : }
6113 : : /* Else spill for variable offset to the destination. We expect
6114 : : to run into this only for hard registers. */
6115 : : else
6116 : : {
6117 : 3 : gcc_assert (VAR_P (tem) && DECL_HARD_REGISTER (tem));
6118 : 3 : stemp = assign_stack_temp (GET_MODE (to_rtx),
6119 : 6 : GET_MODE_SIZE (GET_MODE (to_rtx)));
6120 : 3 : emit_move_insn (stemp, to_rtx);
6121 : 3 : old_to_rtx = to_rtx;
6122 : 3 : to_rtx = stemp;
6123 : : }
6124 : : }
6125 : :
6126 : 171122 : offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, EXPAND_SUM);
6127 : 171122 : address_mode = get_address_mode (to_rtx);
6128 : 171122 : if (GET_MODE (offset_rtx) != address_mode)
6129 : : {
6130 : : /* We cannot be sure that the RTL in offset_rtx is valid outside
6131 : : of a memory address context, so force it into a register
6132 : : before attempting to convert it to the desired mode. */
6133 : 290 : offset_rtx = force_operand (offset_rtx, NULL_RTX);
6134 : 290 : offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
6135 : : }
6136 : :
6137 : : /* If we have an expression in OFFSET_RTX and a non-zero
6138 : : byte offset in BITPOS, adding the byte offset before the
6139 : : OFFSET_RTX results in better intermediate code, which makes
6140 : : later rtl optimization passes perform better.
6141 : :
6142 : : We prefer intermediate code like this:
6143 : :
6144 : : r124:DI=r123:DI+0x18
6145 : : [r124:DI]=r121:DI
6146 : :
6147 : : ... instead of ...
6148 : :
6149 : : r124:DI=r123:DI+0x10
6150 : : [r124:DI+0x8]=r121:DI
6151 : :
6152 : : This is only done for aligned data values, as these can
6153 : : be expected to result in single move instructions. */
6154 : 171122 : poly_int64 bytepos;
6155 : 171122 : if (mode1 != VOIDmode
6156 : 171016 : && maybe_ne (bitpos, 0)
6157 : 45154 : && maybe_gt (bitsize, 0)
6158 : 216276 : && multiple_p (bitpos, BITS_PER_UNIT, &bytepos)
6159 : 216223 : && multiple_p (bitpos, bitsize)
6160 : 90202 : && multiple_p (bitsize, GET_MODE_ALIGNMENT (mode1))
6161 : 216223 : && MEM_ALIGN (to_rtx) >= GET_MODE_ALIGNMENT (mode1))
6162 : : {
6163 : 45086 : to_rtx = adjust_address (to_rtx, mode1, bytepos);
6164 : 45086 : bitregion_start = 0;
6165 : 45086 : if (known_ge (bitregion_end, poly_uint64 (bitpos)))
6166 : 45086 : bitregion_end -= bitpos;
6167 : 45086 : bitpos = 0;
6168 : : }
6169 : :
6170 : 171122 : to_rtx = offset_address (to_rtx, offset_rtx,
6171 : : highest_pow2_factor_for_target (to,
6172 : : offset));
6173 : : }
6174 : :
6175 : : /* No action is needed if the target is not a memory and the field
6176 : : lies completely outside that target. This can occur if the source
6177 : : code contains an out-of-bounds access to a small array. */
6178 : 4492375 : if (!MEM_P (to_rtx)
6179 : 716192 : && GET_MODE (to_rtx) != BLKmode
6180 : 5208567 : && known_ge (bitpos, GET_MODE_PRECISION (GET_MODE (to_rtx))))
6181 : : {
6182 : 3 : expand_normal (from);
6183 : 3 : result = NULL;
6184 : : }
6185 : : /* Handle expand_expr of a complex value returning a CONCAT. */
6186 : 4492372 : else if (GET_CODE (to_rtx) == CONCAT)
6187 : : {
6188 : 139 : machine_mode to_mode = GET_MODE (to_rtx);
6189 : 139 : gcc_checking_assert (COMPLEX_MODE_P (to_mode));
6190 : 278 : poly_int64 mode_bitsize = GET_MODE_BITSIZE (to_mode);
6191 : 139 : unsigned short inner_bitsize = GET_MODE_UNIT_BITSIZE (to_mode);
6192 : 139 : if (TYPE_MODE (TREE_TYPE (from)) == to_mode
6193 : 6 : && known_eq (bitpos, 0)
6194 : 145 : && known_eq (bitsize, mode_bitsize))
6195 : 6 : result = store_expr (from, to_rtx, false, nontemporal, reversep);
6196 : 133 : else if (TYPE_MODE (TREE_TYPE (from)) == GET_MODE_INNER (to_mode)
6197 : 86 : && known_eq (bitsize, inner_bitsize)
6198 : 219 : && (known_eq (bitpos, 0)
6199 : 33 : || known_eq (bitpos, inner_bitsize)))
6200 : 86 : result = store_expr (from, XEXP (to_rtx, maybe_ne (bitpos, 0)),
6201 : : false, nontemporal, reversep);
6202 : 47 : else if (known_le (bitpos + bitsize, inner_bitsize))
6203 : 5 : result = store_field (XEXP (to_rtx, 0), bitsize, bitpos,
6204 : : bitregion_start, bitregion_end,
6205 : : mode1, from, get_alias_set (to),
6206 : : nontemporal, reversep);
6207 : 42 : else if (known_ge (bitpos, inner_bitsize))
6208 : 3 : result = store_field (XEXP (to_rtx, 1), bitsize,
6209 : : bitpos - inner_bitsize,
6210 : : bitregion_start, bitregion_end,
6211 : : mode1, from, get_alias_set (to),
6212 : : nontemporal, reversep);
6213 : 39 : else if (known_eq (bitpos, 0) && known_eq (bitsize, mode_bitsize))
6214 : : {
6215 : 32 : result = expand_normal (from);
6216 : 32 : if (GET_CODE (result) == CONCAT)
6217 : : {
6218 : 0 : to_mode = GET_MODE_INNER (to_mode);
6219 : 0 : machine_mode from_mode = GET_MODE_INNER (GET_MODE (result));
6220 : 0 : rtx from_real
6221 : 0 : = force_subreg (to_mode, XEXP (result, 0), from_mode, 0);
6222 : 0 : rtx from_imag
6223 : 0 : = force_subreg (to_mode, XEXP (result, 1), from_mode, 0);
6224 : 0 : if (!from_real || !from_imag)
6225 : 0 : goto concat_store_slow;
6226 : 0 : emit_move_insn (XEXP (to_rtx, 0), from_real);
6227 : 0 : emit_move_insn (XEXP (to_rtx, 1), from_imag);
6228 : : }
6229 : : else
6230 : : {
6231 : 32 : machine_mode from_mode
6232 : 32 : = GET_MODE (result) == VOIDmode
6233 : 32 : ? TYPE_MODE (TREE_TYPE (from))
6234 : 32 : : GET_MODE (result);
6235 : 32 : rtx from_rtx;
6236 : 32 : if (MEM_P (result))
6237 : 1 : from_rtx = change_address (result, to_mode, NULL_RTX);
6238 : : else
6239 : 31 : from_rtx = force_subreg (to_mode, result, from_mode, 0);
6240 : 32 : if (from_rtx)
6241 : : {
6242 : 32 : emit_move_insn (XEXP (to_rtx, 0),
6243 : : read_complex_part (from_rtx, false));
6244 : 32 : emit_move_insn (XEXP (to_rtx, 1),
6245 : : read_complex_part (from_rtx, true));
6246 : : }
6247 : : else
6248 : : {
6249 : 0 : to_mode = GET_MODE_INNER (to_mode);
6250 : 0 : rtx from_real
6251 : 0 : = force_subreg (to_mode, result, from_mode, 0);
6252 : 0 : rtx from_imag
6253 : 0 : = force_subreg (to_mode, result, from_mode,
6254 : 0 : GET_MODE_SIZE (to_mode));
6255 : 0 : if (!from_real || !from_imag)
6256 : 0 : goto concat_store_slow;
6257 : 0 : emit_move_insn (XEXP (to_rtx, 0), from_real);
6258 : 0 : emit_move_insn (XEXP (to_rtx, 1), from_imag);
6259 : : }
6260 : : }
6261 : : }
6262 : : else
6263 : : {
6264 : 7 : concat_store_slow:;
6265 : 7 : rtx temp = assign_stack_temp (GET_MODE (to_rtx),
6266 : 14 : GET_MODE_SIZE (GET_MODE (to_rtx)));
6267 : 7 : write_complex_part (temp, XEXP (to_rtx, 0), false, true);
6268 : 7 : write_complex_part (temp, XEXP (to_rtx, 1), true, false);
6269 : 7 : result = store_field (temp, bitsize, bitpos,
6270 : : bitregion_start, bitregion_end,
6271 : : mode1, from, get_alias_set (to),
6272 : : nontemporal, reversep);
6273 : 7 : emit_move_insn (XEXP (to_rtx, 0), read_complex_part (temp, false));
6274 : 7 : emit_move_insn (XEXP (to_rtx, 1), read_complex_part (temp, true));
6275 : : }
6276 : : }
6277 : : /* For calls to functions returning variable length structures, if TO_RTX
6278 : : is not a MEM, go through a MEM because we must not create temporaries
6279 : : of the VLA type. */
6280 : 4492233 : else if (!MEM_P (to_rtx)
6281 : 716050 : && TREE_CODE (from) == CALL_EXPR
6282 : 970 : && COMPLETE_TYPE_P (TREE_TYPE (from))
6283 : 4493203 : && TREE_CODE (TYPE_SIZE (TREE_TYPE (from))) != INTEGER_CST)
6284 : : {
6285 : 6 : rtx temp = assign_stack_temp (GET_MODE (to_rtx),
6286 : 12 : GET_MODE_SIZE (GET_MODE (to_rtx)));
6287 : 6 : result = store_field (temp, bitsize, bitpos, bitregion_start,
6288 : : bitregion_end, mode1, from, get_alias_set (to),
6289 : : nontemporal, reversep);
6290 : 6 : emit_move_insn (to_rtx, temp);
6291 : : }
6292 : : else
6293 : : {
6294 : 4492227 : if (MEM_P (to_rtx))
6295 : : {
6296 : : /* If the field is at offset zero, we could have been given the
6297 : : DECL_RTX of the parent struct. Don't munge it. */
6298 : 3776183 : to_rtx = shallow_copy_rtx (to_rtx);
6299 : 3776183 : set_mem_attributes_minus_bitpos (to_rtx, to, 0, bitpos);
6300 : 3776183 : if (volatilep)
6301 : 8680 : MEM_VOLATILE_P (to_rtx) = 1;
6302 : : }
6303 : :
6304 : 4492227 : gcc_checking_assert (known_ge (bitpos, 0));
6305 : 4492227 : if (optimize_bitfield_assignment_op (bitsize, bitpos,
6306 : : bitregion_start, bitregion_end,
6307 : : mode1, to_rtx, to, from,
6308 : : reversep))
6309 : : result = NULL;
6310 : 4492102 : else if (SUBREG_P (to_rtx)
6311 : 4492102 : && SUBREG_PROMOTED_VAR_P (to_rtx))
6312 : : {
6313 : : /* If to_rtx is a promoted subreg, we need to zero or sign
6314 : : extend the value afterwards. */
6315 : 0 : if (TREE_CODE (to) == MEM_REF
6316 : 0 : && TYPE_MODE (TREE_TYPE (from)) != BLKmode
6317 : 0 : && !REF_REVERSE_STORAGE_ORDER (to)
6318 : 0 : && known_eq (bitpos, 0)
6319 : 0 : && known_eq (bitsize, GET_MODE_BITSIZE (GET_MODE (to_rtx))))
6320 : 0 : result = store_expr (from, to_rtx, 0, nontemporal, false);
6321 : : /* Check if the field overlaps the MSB, requiring extension. */
6322 : 0 : else if (maybe_eq (bitpos + bitsize,
6323 : 0 : GET_MODE_BITSIZE (GET_MODE (to_rtx))))
6324 : : {
6325 : 0 : scalar_int_mode imode = subreg_unpromoted_mode (to_rtx);
6326 : 0 : scalar_int_mode omode = subreg_promoted_mode (to_rtx);
6327 : 0 : rtx to_rtx1 = lowpart_subreg (imode, SUBREG_REG (to_rtx),
6328 : : omode);
6329 : 0 : result = store_field (to_rtx1, bitsize, bitpos,
6330 : : bitregion_start, bitregion_end,
6331 : : mode1, from, get_alias_set (to),
6332 : : nontemporal, reversep);
6333 : : /* If the target usually keeps IMODE appropriately
6334 : : extended in OMODE it's unsafe to refer to it using
6335 : : a SUBREG whilst this invariant doesn't hold. */
6336 : 0 : if (targetm.mode_rep_extended (imode, omode) != UNKNOWN)
6337 : 0 : to_rtx1 = simplify_gen_unary (TRUNCATE, imode,
6338 : : SUBREG_REG (to_rtx), omode);
6339 : 0 : convert_move (SUBREG_REG (to_rtx), to_rtx1,
6340 : 0 : SUBREG_PROMOTED_SIGN (to_rtx));
6341 : : }
6342 : : else
6343 : 0 : result = store_field (to_rtx, bitsize, bitpos,
6344 : : bitregion_start, bitregion_end,
6345 : : mode1, from, get_alias_set (to),
6346 : : nontemporal, reversep);
6347 : : }
6348 : : else
6349 : 4492102 : result = store_field (to_rtx, bitsize, bitpos,
6350 : : bitregion_start, bitregion_end,
6351 : : mode1, from, get_alias_set (to),
6352 : : nontemporal, reversep);
6353 : : /* Move the temporary storage back to the non-MEM_P. */
6354 : 4492227 : if (stemp)
6355 : 3 : emit_move_insn (old_to_rtx, stemp);
6356 : : }
6357 : :
6358 : 4492375 : if (result)
6359 : 859071 : preserve_temp_slots (result);
6360 : 4492375 : pop_temp_slots ();
6361 : 4492375 : return;
6362 : : }
6363 : :
6364 : : /* If the rhs is a function call and its value is not an aggregate,
6365 : : call the function before we start to compute the lhs.
6366 : : This is needed for correct code for cases such as
6367 : : val = setjmp (buf) on machines where reference to val
6368 : : requires loading up part of an address in a separate insn.
6369 : :
6370 : : Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
6371 : : since it might be a promoted variable where the zero- or sign- extension
6372 : : needs to be done. Handling this in the normal way is safe because no
6373 : : computation is done before the call. The same is true for SSA names. */
6374 : 2286360 : if (TREE_CODE (from) == CALL_EXPR && ! aggregate_value_p (from, from)
6375 : 2084760 : && COMPLETE_TYPE_P (TREE_TYPE (from))
6376 : 2084760 : && TREE_CODE (TYPE_SIZE (TREE_TYPE (from))) == INTEGER_CST
6377 : 15136082 : && ! (((VAR_P (to)
6378 : : || TREE_CODE (to) == PARM_DECL
6379 : : || TREE_CODE (to) == RESULT_DECL)
6380 : 140420 : && REG_P (DECL_RTL (to)))
6381 : 1951993 : || TREE_CODE (to) == SSA_NAME))
6382 : : {
6383 : 7879 : rtx value;
6384 : :
6385 : 7879 : push_temp_slots ();
6386 : 7879 : value = expand_normal (from);
6387 : :
6388 : 7879 : if (to_rtx == 0)
6389 : 7879 : to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
6390 : :
6391 : : /* Handle calls that return values in multiple non-contiguous locations.
6392 : : The Irix 6 ABI has examples of this. */
6393 : 7879 : if (GET_CODE (to_rtx) == PARALLEL)
6394 : : {
6395 : 0 : if (GET_CODE (value) == PARALLEL)
6396 : 0 : emit_group_move (to_rtx, value);
6397 : : else
6398 : 0 : emit_group_load (to_rtx, value, TREE_TYPE (from),
6399 : 0 : int_size_in_bytes (TREE_TYPE (from)));
6400 : : }
6401 : 7879 : else if (GET_CODE (value) == PARALLEL)
6402 : 1899 : emit_group_store (to_rtx, value, TREE_TYPE (from),
6403 : 1899 : int_size_in_bytes (TREE_TYPE (from)));
6404 : 5980 : else if (GET_MODE (to_rtx) == BLKmode)
6405 : : {
6406 : : /* Handle calls that return BLKmode values in registers. */
6407 : 244 : if (REG_P (value))
6408 : 244 : copy_blkmode_from_reg (to_rtx, value, TREE_TYPE (from));
6409 : : else
6410 : 0 : emit_block_move (to_rtx, value, expr_size (from), BLOCK_OP_NORMAL);
6411 : : }
6412 : : else
6413 : : {
6414 : 5736 : if (POINTER_TYPE_P (TREE_TYPE (to)))
6415 : 0 : value = convert_memory_address_addr_space
6416 : 0 : (as_a <scalar_int_mode> (GET_MODE (to_rtx)), value,
6417 : 0 : TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to))));
6418 : :
6419 : 5736 : emit_move_insn (to_rtx, value);
6420 : : }
6421 : :
6422 : 7879 : preserve_temp_slots (to_rtx);
6423 : 7879 : pop_temp_slots ();
6424 : 7879 : return;
6425 : : }
6426 : :
6427 : : /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
6428 : 13043443 : to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
6429 : :
6430 : : /* Don't move directly into a return register. */
6431 : 13043443 : if (TREE_CODE (to) == RESULT_DECL
6432 : 16159 : && (REG_P (to_rtx) || GET_CODE (to_rtx) == PARALLEL))
6433 : : {
6434 : 0 : rtx temp;
6435 : :
6436 : 0 : push_temp_slots ();
6437 : :
6438 : : /* If the source is itself a return value, it still is in a pseudo at
6439 : : this point so we can move it back to the return register directly. */
6440 : 0 : if (REG_P (to_rtx)
6441 : 0 : && TYPE_MODE (TREE_TYPE (from)) == BLKmode
6442 : 0 : && TREE_CODE (from) != CALL_EXPR)
6443 : 0 : temp = copy_blkmode_to_reg (GET_MODE (to_rtx), from);
6444 : : else
6445 : 0 : temp = expand_expr (from, NULL_RTX, GET_MODE (to_rtx), EXPAND_NORMAL);
6446 : :
6447 : : /* Handle calls that return values in multiple non-contiguous locations.
6448 : : The Irix 6 ABI has examples of this. */
6449 : 0 : if (GET_CODE (to_rtx) == PARALLEL)
6450 : : {
6451 : 0 : if (GET_CODE (temp) == PARALLEL)
6452 : 0 : emit_group_move (to_rtx, temp);
6453 : : else
6454 : 0 : emit_group_load (to_rtx, temp, TREE_TYPE (from),
6455 : 0 : int_size_in_bytes (TREE_TYPE (from)));
6456 : : }
6457 : 0 : else if (temp)
6458 : 0 : emit_move_insn (to_rtx, temp);
6459 : :
6460 : 0 : preserve_temp_slots (to_rtx);
6461 : 0 : pop_temp_slots ();
6462 : 0 : return;
6463 : : }
6464 : :
6465 : : /* In case we are returning the contents of an object which overlaps
6466 : : the place the value is being stored, use a safe function when copying
6467 : : a value through a pointer into a structure value return block. */
6468 : 13043443 : if (TREE_CODE (to) == RESULT_DECL
6469 : 16159 : && TREE_CODE (from) == INDIRECT_REF
6470 : 0 : && ADDR_SPACE_GENERIC_P
6471 : : (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from, 0)))))
6472 : 0 : && refs_may_alias_p (to, from)
6473 : 0 : && cfun->returns_struct
6474 : 13043443 : && !cfun->returns_pcc_struct)
6475 : : {
6476 : 0 : rtx from_rtx, size;
6477 : :
6478 : 0 : push_temp_slots ();
6479 : 0 : size = expr_size (from);
6480 : 0 : from_rtx = expand_normal (from);
6481 : :
6482 : 0 : emit_block_move_via_libcall (XEXP (to_rtx, 0), XEXP (from_rtx, 0), size);
6483 : :
6484 : 0 : preserve_temp_slots (to_rtx);
6485 : 0 : pop_temp_slots ();
6486 : 0 : return;
6487 : : }
6488 : :
6489 : : /* Compute FROM and store the value in the rtx we got. */
6490 : :
6491 : 13043443 : push_temp_slots ();
6492 : 13043443 : result = store_expr (from, to_rtx, 0, nontemporal, false);
6493 : 13043443 : preserve_temp_slots (result);
6494 : 13043443 : pop_temp_slots ();
6495 : 13043443 : return;
6496 : : }
6497 : :
6498 : : /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
6499 : : succeeded, false otherwise. */
6500 : :
6501 : : bool
6502 : 17 : emit_storent_insn (rtx to, rtx from)
6503 : : {
6504 : 17 : class expand_operand ops[2];
6505 : 17 : machine_mode mode = GET_MODE (to);
6506 : 17 : enum insn_code code = optab_handler (storent_optab, mode);
6507 : :
6508 : 17 : if (code == CODE_FOR_nothing)
6509 : : return false;
6510 : :
6511 : 17 : create_fixed_operand (&ops[0], to);
6512 : 17 : create_input_operand (&ops[1], from, mode);
6513 : 17 : return maybe_expand_insn (code, 2, ops);
6514 : : }
6515 : :
6516 : : /* Helper function for store_expr storing of STRING_CST. */
6517 : :
6518 : : static rtx
6519 : 91438 : string_cst_read_str (void *data, void *, HOST_WIDE_INT offset,
6520 : : fixed_size_mode mode)
6521 : : {
6522 : 91438 : tree str = (tree) data;
6523 : :
6524 : 91438 : gcc_assert (offset >= 0);
6525 : 91438 : if (offset >= TREE_STRING_LENGTH (str))
6526 : 3386 : return const0_rtx;
6527 : :
6528 : 88052 : if ((unsigned HOST_WIDE_INT) offset + GET_MODE_SIZE (mode)
6529 : 88052 : > (unsigned HOST_WIDE_INT) TREE_STRING_LENGTH (str))
6530 : : {
6531 : 2536 : char *p = XALLOCAVEC (char, GET_MODE_SIZE (mode));
6532 : 2536 : size_t l = TREE_STRING_LENGTH (str) - offset;
6533 : 2536 : memcpy (p, TREE_STRING_POINTER (str) + offset, l);
6534 : 2536 : memset (p + l, '\0', GET_MODE_SIZE (mode) - l);
6535 : 2536 : return c_readstr (p, mode, false);
6536 : : }
6537 : :
6538 : 85516 : return c_readstr (TREE_STRING_POINTER (str) + offset, mode, false);
6539 : : }
6540 : :
6541 : : /* Generate code for computing expression EXP,
6542 : : and storing the value into TARGET.
6543 : :
6544 : : If the mode is BLKmode then we may return TARGET itself.
6545 : : It turns out that in BLKmode it doesn't cause a problem.
6546 : : because C has no operators that could combine two different
6547 : : assignments into the same BLKmode object with different values
6548 : : with no sequence point. Will other languages need this to
6549 : : be more thorough?
6550 : :
6551 : : If CALL_PARAM_P is nonzero, this is a store into a call param on the
6552 : : stack, and block moves may need to be treated specially.
6553 : :
6554 : : If NONTEMPORAL is true, try using a nontemporal store instruction.
6555 : :
6556 : : If REVERSE is true, the store is to be done in reverse order. */
6557 : :
6558 : : rtx
6559 : 16713895 : store_expr (tree exp, rtx target, int call_param_p,
6560 : : bool nontemporal, bool reverse)
6561 : : {
6562 : 16713895 : rtx temp;
6563 : 16713895 : rtx alt_rtl = NULL_RTX;
6564 : 16713895 : location_t loc = curr_insn_location ();
6565 : 16713895 : bool shortened_string_cst = false;
6566 : :
6567 : 16713895 : if (VOID_TYPE_P (TREE_TYPE (exp)))
6568 : : {
6569 : : /* C++ can generate ?: expressions with a throw expression in one
6570 : : branch and an rvalue in the other. Here, we resolve attempts to
6571 : : store the throw expression's nonexistent result. */
6572 : 0 : gcc_assert (!call_param_p);
6573 : 0 : expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL);
6574 : 0 : return NULL_RTX;
6575 : : }
6576 : 16713895 : if (TREE_CODE (exp) == COMPOUND_EXPR)
6577 : : {
6578 : : /* Perform first part of compound expression, then assign from second
6579 : : part. */
6580 : 0 : expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
6581 : : call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
6582 : 0 : return store_expr (TREE_OPERAND (exp, 1), target,
6583 : 0 : call_param_p, nontemporal, reverse);
6584 : : }
6585 : 16713895 : else if (TREE_CODE (exp) == COND_EXPR && GET_MODE (target) == BLKmode)
6586 : : {
6587 : : /* For conditional expression, get safe form of the target. Then
6588 : : test the condition, doing the appropriate assignment on either
6589 : : side. This avoids the creation of unnecessary temporaries.
6590 : : For non-BLKmode, it is more efficient not to do this. */
6591 : :
6592 : 0 : rtx_code_label *lab1 = gen_label_rtx (), *lab2 = gen_label_rtx ();
6593 : :
6594 : 0 : do_pending_stack_adjust ();
6595 : 0 : NO_DEFER_POP;
6596 : 0 : jumpifnot (TREE_OPERAND (exp, 0), lab1,
6597 : : profile_probability::uninitialized ());
6598 : 0 : store_expr (TREE_OPERAND (exp, 1), target, call_param_p,
6599 : : nontemporal, reverse);
6600 : 0 : emit_jump_insn (targetm.gen_jump (lab2));
6601 : 0 : emit_barrier ();
6602 : 0 : emit_label (lab1);
6603 : 0 : store_expr (TREE_OPERAND (exp, 2), target, call_param_p,
6604 : : nontemporal, reverse);
6605 : 0 : emit_label (lab2);
6606 : 0 : OK_DEFER_POP;
6607 : :
6608 : 0 : return NULL_RTX;
6609 : : }
6610 : 16713895 : else if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target))
6611 : : /* If this is a scalar in a register that is stored in a wider mode
6612 : : than the declared mode, compute the result into its declared mode
6613 : : and then convert to the wider mode. Our value is the computed
6614 : : expression. */
6615 : : {
6616 : 7 : rtx inner_target = 0;
6617 : 7 : scalar_int_mode outer_mode = subreg_unpromoted_mode (target);
6618 : 7 : scalar_int_mode inner_mode = subreg_promoted_mode (target);
6619 : :
6620 : : /* We can do the conversion inside EXP, which will often result
6621 : : in some optimizations. Do the conversion in two steps: first
6622 : : change the signedness, if needed, then the extend. But don't
6623 : : do this if the type of EXP is a subtype of something else
6624 : : since then the conversion might involve more than just
6625 : : converting modes. */
6626 : 14 : if (INTEGRAL_TYPE_P (TREE_TYPE (exp))
6627 : 0 : && TREE_TYPE (TREE_TYPE (exp)) == 0
6628 : 7 : && GET_MODE_PRECISION (outer_mode)
6629 : 0 : == TYPE_PRECISION (TREE_TYPE (exp)))
6630 : : {
6631 : 0 : if (!SUBREG_CHECK_PROMOTED_SIGN (target,
6632 : : TYPE_UNSIGNED (TREE_TYPE (exp))))
6633 : : {
6634 : : /* Some types, e.g. Fortran's logical*4, won't have a signed
6635 : : version, so use the mode instead. */
6636 : 0 : tree ntype
6637 : : = (signed_or_unsigned_type_for
6638 : 0 : (SUBREG_PROMOTED_SIGN (target), TREE_TYPE (exp)));
6639 : 0 : if (ntype == NULL)
6640 : 0 : ntype = lang_hooks.types.type_for_mode
6641 : 0 : (TYPE_MODE (TREE_TYPE (exp)),
6642 : 0 : SUBREG_PROMOTED_SIGN (target));
6643 : :
6644 : 0 : exp = fold_convert_loc (loc, ntype, exp);
6645 : : }
6646 : :
6647 : 0 : exp = fold_convert_loc (loc, lang_hooks.types.type_for_mode
6648 : 0 : (inner_mode, SUBREG_PROMOTED_SIGN (target)),
6649 : : exp);
6650 : :
6651 : 0 : inner_target = SUBREG_REG (target);
6652 : : }
6653 : :
6654 : 7 : temp = expand_expr (exp, inner_target, VOIDmode,
6655 : : call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
6656 : :
6657 : :
6658 : : /* If TEMP is a VOIDmode constant, use convert_modes to make
6659 : : sure that we properly convert it. */
6660 : 7 : if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode)
6661 : : {
6662 : 0 : temp = convert_modes (outer_mode, TYPE_MODE (TREE_TYPE (exp)),
6663 : 0 : temp, SUBREG_PROMOTED_SIGN (target));
6664 : 0 : temp = convert_modes (inner_mode, outer_mode, temp,
6665 : 0 : SUBREG_PROMOTED_SIGN (target));
6666 : 0 : }
6667 : 7 : else if (!SCALAR_INT_MODE_P (GET_MODE (temp)))
6668 : 0 : temp = convert_modes (outer_mode, TYPE_MODE (TREE_TYPE (exp)),
6669 : 0 : temp, SUBREG_PROMOTED_SIGN (target));
6670 : :
6671 : 21 : convert_move (SUBREG_REG (target), temp,
6672 : 7 : SUBREG_PROMOTED_SIGN (target));
6673 : :
6674 : 7 : return NULL_RTX;
6675 : : }
6676 : 16713888 : else if ((TREE_CODE (exp) == STRING_CST
6677 : 16703826 : || (TREE_CODE (exp) == MEM_REF
6678 : 1305509 : && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
6679 : 454676 : && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
6680 : : == STRING_CST
6681 : 4348 : && integer_zerop (TREE_OPERAND (exp, 1))))
6682 : 14410 : && !nontemporal && !call_param_p
6683 : 16728298 : && MEM_P (target))
6684 : : {
6685 : : /* Optimize initialization of an array with a STRING_CST. */
6686 : 14404 : HOST_WIDE_INT exp_len, str_copy_len;
6687 : 14404 : rtx dest_mem;
6688 : 14404 : tree str = TREE_CODE (exp) == STRING_CST
6689 : 14404 : ? exp : TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6690 : :
6691 : 14404 : exp_len = int_expr_size (exp);
6692 : 14404 : if (exp_len <= 0)
6693 : 0 : goto normal_expr;
6694 : :
6695 : 14404 : if (TREE_STRING_LENGTH (str) <= 0)
6696 : 0 : goto normal_expr;
6697 : :
6698 : 28808 : if (can_store_by_pieces (exp_len, string_cst_read_str, (void *) str,
6699 : 14404 : MEM_ALIGN (target), false))
6700 : : {
6701 : 14229 : store_by_pieces (target, exp_len, string_cst_read_str, (void *) str,
6702 : 14229 : MEM_ALIGN (target), false, RETURN_BEGIN);
6703 : 14229 : return NULL_RTX;
6704 : : }
6705 : :
6706 : 175 : str_copy_len = TREE_STRING_LENGTH (str);
6707 : :
6708 : : /* Trailing NUL bytes in EXP will be handled by the call to
6709 : : clear_storage, which is more efficient than copying them from
6710 : : the STRING_CST, so trim those from STR_COPY_LEN. */
6711 : 297 : while (str_copy_len)
6712 : : {
6713 : 254 : if (TREE_STRING_POINTER (str)[str_copy_len - 1])
6714 : : break;
6715 : 122 : str_copy_len--;
6716 : : }
6717 : :
6718 : 175 : if ((STORE_MAX_PIECES & (STORE_MAX_PIECES - 1)) == 0)
6719 : : {
6720 : 175 : str_copy_len += STORE_MAX_PIECES - 1;
6721 : 175 : str_copy_len &= ~(STORE_MAX_PIECES - 1);
6722 : : }
6723 : 175 : if (str_copy_len >= exp_len)
6724 : 124 : goto normal_expr;
6725 : :
6726 : 102 : if (!can_store_by_pieces (str_copy_len, string_cst_read_str,
6727 : 51 : (void *) str, MEM_ALIGN (target), false))
6728 : 2 : goto normal_expr;
6729 : :
6730 : 49 : dest_mem = store_by_pieces (target, str_copy_len, string_cst_read_str,
6731 : 49 : (void *) str, MEM_ALIGN (target), false,
6732 : : RETURN_END);
6733 : 49 : clear_storage (adjust_address_1 (dest_mem, BLKmode, 0, 1, 1, 0,
6734 : 49 : exp_len - str_copy_len),
6735 : : GEN_INT (exp_len - str_copy_len), BLOCK_OP_NORMAL);
6736 : 49 : return NULL_RTX;
6737 : : }
6738 : : else
6739 : : {
6740 : 16699610 : rtx tmp_target;
6741 : :
6742 : 16699610 : normal_expr:
6743 : : /* If we want to use a nontemporal or a reverse order store, force the
6744 : : value into a register first. */
6745 : 16699610 : tmp_target = nontemporal || reverse ? NULL_RTX : target;
6746 : 16699610 : tree rexp = exp;
6747 : 16699610 : if (TREE_CODE (exp) == STRING_CST
6748 : 41 : && tmp_target == target
6749 : 41 : && GET_MODE (target) == BLKmode
6750 : 16699651 : && TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
6751 : : {
6752 : 41 : rtx size = expr_size (exp);
6753 : 41 : if (CONST_INT_P (size)
6754 : 41 : && size != const0_rtx
6755 : 82 : && (UINTVAL (size)
6756 : 41 : > ((unsigned HOST_WIDE_INT) TREE_STRING_LENGTH (exp) + 32)))
6757 : : {
6758 : : /* If the STRING_CST has much larger array type than
6759 : : TREE_STRING_LENGTH, only emit the TREE_STRING_LENGTH part of
6760 : : it into the rodata section as the code later on will use
6761 : : memset zero for the remainder anyway. See PR95052. */
6762 : 2 : tmp_target = NULL_RTX;
6763 : 2 : rexp = copy_node (exp);
6764 : 2 : tree index
6765 : 2 : = build_index_type (size_int (TREE_STRING_LENGTH (exp) - 1));
6766 : 2 : TREE_TYPE (rexp) = build_array_type (TREE_TYPE (TREE_TYPE (exp)),
6767 : : index);
6768 : 2 : shortened_string_cst = true;
6769 : : }
6770 : : }
6771 : 33399220 : temp = expand_expr_real (rexp, tmp_target, GET_MODE (target),
6772 : : (call_param_p
6773 : : ? EXPAND_STACK_PARM : EXPAND_NORMAL),
6774 : : &alt_rtl, false);
6775 : 16699610 : if (shortened_string_cst)
6776 : : {
6777 : 2 : gcc_assert (MEM_P (temp));
6778 : 2 : temp = change_address (temp, BLKmode, NULL_RTX);
6779 : : }
6780 : : }
6781 : :
6782 : : /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
6783 : : the same as that of TARGET, adjust the constant. This is needed, for
6784 : : example, in case it is a CONST_DOUBLE or CONST_WIDE_INT and we want
6785 : : only a word-sized value. */
6786 : 3335673 : if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode
6787 : 2386886 : && TREE_CODE (exp) != ERROR_MARK
6788 : 19086496 : && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
6789 : : {
6790 : 0 : gcc_assert (!shortened_string_cst);
6791 : 0 : if (GET_MODE_CLASS (GET_MODE (target))
6792 : 0 : != GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (exp)))
6793 : 0 : && known_eq (GET_MODE_BITSIZE (GET_MODE (target)),
6794 : : GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp)))))
6795 : : {
6796 : 0 : rtx t = simplify_gen_subreg (GET_MODE (target), temp,
6797 : 0 : TYPE_MODE (TREE_TYPE (exp)), 0);
6798 : 0 : if (t)
6799 : 0 : temp = t;
6800 : : }
6801 : 0 : if (GET_MODE (temp) == VOIDmode)
6802 : 0 : temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
6803 : 0 : temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
6804 : : }
6805 : :
6806 : : /* If value was not generated in the target, store it there.
6807 : : Convert the value to TARGET's type first if necessary and emit the
6808 : : pending incrementations that have been queued when expanding EXP.
6809 : : Note that we cannot emit the whole queue blindly because this will
6810 : : effectively disable the POST_INC optimization later.
6811 : :
6812 : : If TEMP and TARGET compare equal according to rtx_equal_p, but
6813 : : one or both of them are volatile memory refs, we have to distinguish
6814 : : two cases:
6815 : : - expand_expr has used TARGET. In this case, we must not generate
6816 : : another copy. This can be detected by TARGET being equal according
6817 : : to == .
6818 : : - expand_expr has not used TARGET - that means that the source just
6819 : : happens to have the same RTX form. Since temp will have been created
6820 : : by expand_expr, it will compare unequal according to == .
6821 : : We must generate a copy in this case, to reach the correct number
6822 : : of volatile memory references. */
6823 : :
6824 : 16699610 : if ((! rtx_equal_p (temp, target)
6825 : 2972711 : || (temp != target && (side_effects_p (temp)
6826 : 46687 : || side_effects_p (target)
6827 : 46687 : || (MEM_P (temp)
6828 : 46477 : && !mems_same_for_tbaa_p (temp, target)))))
6829 : 13726903 : && TREE_CODE (exp) != ERROR_MARK
6830 : : /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
6831 : : but TARGET is not valid memory reference, TEMP will differ
6832 : : from TARGET although it is really the same location. */
6833 : 13726903 : && !(alt_rtl
6834 : 2000045 : && rtx_equal_p (alt_rtl, target)
6835 : 1 : && !side_effects_p (alt_rtl)
6836 : 0 : && !side_effects_p (target))
6837 : : /* If there's nothing to copy, don't bother. Don't call
6838 : : expr_size unless necessary, because some front-ends (C++)
6839 : : expr_size-hook must not be given objects that are not
6840 : : supposed to be bit-copied or bit-initialized. */
6841 : 30426513 : && expr_size (exp) != const0_rtx)
6842 : : {
6843 : 13726903 : if (GET_MODE (temp) != GET_MODE (target) && GET_MODE (temp) != VOIDmode)
6844 : : {
6845 : 1327 : gcc_assert (!shortened_string_cst);
6846 : 1327 : if (GET_MODE (target) == BLKmode)
6847 : : {
6848 : : /* Handle calls that return BLKmode values in registers. */
6849 : 2 : if (REG_P (temp) && TREE_CODE (exp) == CALL_EXPR)
6850 : 2 : copy_blkmode_from_reg (target, temp, TREE_TYPE (exp));
6851 : : else
6852 : 0 : store_bit_field (target,
6853 : 0 : rtx_to_poly_int64 (expr_size (exp))
6854 : 0 : * BITS_PER_UNIT,
6855 : 0 : 0, 0, 0, GET_MODE (temp), temp, reverse,
6856 : : false);
6857 : : }
6858 : : else
6859 : 1325 : convert_move (target, temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
6860 : : }
6861 : :
6862 : 13725576 : else if (GET_MODE (temp) == BLKmode && TREE_CODE (exp) == STRING_CST)
6863 : : {
6864 : : /* Handle copying a string constant into an array. The string
6865 : : constant may be shorter than the array. So copy just the string's
6866 : : actual length, and clear the rest. First get the size of the data
6867 : : type of the string, which is actually the size of the target. */
6868 : 41 : rtx size = expr_size (exp);
6869 : :
6870 : 41 : if (CONST_INT_P (size)
6871 : 41 : && INTVAL (size) < TREE_STRING_LENGTH (exp))
6872 : 0 : emit_block_move (target, temp, size,
6873 : : (call_param_p
6874 : : ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
6875 : : else
6876 : : {
6877 : 41 : machine_mode pointer_mode
6878 : 41 : = targetm.addr_space.pointer_mode (MEM_ADDR_SPACE (target));
6879 : 41 : machine_mode address_mode = get_address_mode (target);
6880 : :
6881 : : /* Compute the size of the data to copy from the string. */
6882 : 41 : tree copy_size
6883 : 41 : = size_binop_loc (loc, MIN_EXPR,
6884 : : make_tree (sizetype, size),
6885 : 41 : size_int (TREE_STRING_LENGTH (exp)));
6886 : 41 : rtx copy_size_rtx
6887 : 41 : = expand_expr (copy_size, NULL_RTX, VOIDmode,
6888 : : (call_param_p
6889 : : ? EXPAND_STACK_PARM : EXPAND_NORMAL));
6890 : 41 : rtx_code_label *label = 0;
6891 : :
6892 : : /* Copy that much. */
6893 : 123 : copy_size_rtx = convert_to_mode (pointer_mode, copy_size_rtx,
6894 : 41 : TYPE_UNSIGNED (sizetype));
6895 : 82 : emit_block_move (target, temp, copy_size_rtx,
6896 : : (call_param_p
6897 : : ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
6898 : :
6899 : : /* Figure out how much is left in TARGET that we have to clear.
6900 : : Do all calculations in pointer_mode. */
6901 : 41 : poly_int64 const_copy_size;
6902 : 41 : if (poly_int_rtx_p (copy_size_rtx, &const_copy_size))
6903 : : {
6904 : 41 : size = plus_constant (address_mode, size, -const_copy_size);
6905 : 41 : target = adjust_address (target, BLKmode, const_copy_size);
6906 : : }
6907 : : else
6908 : : {
6909 : 0 : size = expand_binop (TYPE_MODE (sizetype), sub_optab, size,
6910 : : copy_size_rtx, NULL_RTX, 0,
6911 : : OPTAB_LIB_WIDEN);
6912 : :
6913 : 0 : if (GET_MODE (copy_size_rtx) != address_mode)
6914 : 0 : copy_size_rtx = convert_to_mode (address_mode,
6915 : : copy_size_rtx,
6916 : 0 : TYPE_UNSIGNED (sizetype));
6917 : :
6918 : 0 : target = offset_address (target, copy_size_rtx,
6919 : : highest_pow2_factor (copy_size));
6920 : 0 : label = gen_label_rtx ();
6921 : 0 : emit_cmp_and_jump_insns (size, const0_rtx, LT, NULL_RTX,
6922 : 0 : GET_MODE (size), 0, label);
6923 : : }
6924 : :
6925 : 41 : if (size != const0_rtx)
6926 : 2 : clear_storage (target, size, BLOCK_OP_NORMAL);
6927 : :
6928 : 41 : if (label)
6929 : 0 : emit_label (label);
6930 : : }
6931 : : }
6932 : 13725535 : else if (shortened_string_cst)
6933 : 0 : gcc_unreachable ();
6934 : : /* Handle calls that return values in multiple non-contiguous locations.
6935 : : The Irix 6 ABI has examples of this. */
6936 : 13725535 : else if (GET_CODE (target) == PARALLEL)
6937 : : {
6938 : 0 : if (GET_CODE (temp) == PARALLEL)
6939 : 0 : emit_group_move (target, temp);
6940 : : else
6941 : 0 : emit_group_load (target, temp, TREE_TYPE (exp),
6942 : 0 : int_size_in_bytes (TREE_TYPE (exp)));
6943 : : }
6944 : 13725535 : else if (GET_CODE (temp) == PARALLEL)
6945 : 0 : emit_group_store (target, temp, TREE_TYPE (exp),
6946 : 0 : int_size_in_bytes (TREE_TYPE (exp)));
6947 : 13725535 : else if (GET_MODE (temp) == BLKmode)
6948 : 604976 : emit_block_move (target, temp, expr_size (exp),
6949 : : (call_param_p
6950 : : ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
6951 : : /* If we emit a nontemporal store, there is nothing else to do. */
6952 : 13423047 : else if (nontemporal && emit_storent_insn (target, temp))
6953 : : ;
6954 : : else
6955 : : {
6956 : 13423030 : if (reverse)
6957 : 696 : temp = flip_storage_order (GET_MODE (target), temp);
6958 : 13423030 : temp = force_operand (temp, target);
6959 : 13423030 : if (temp != target)
6960 : 13421460 : emit_move_insn (target, temp);
6961 : : }
6962 : : }
6963 : : else
6964 : 2972707 : gcc_assert (!shortened_string_cst);
6965 : :
6966 : : return NULL_RTX;
6967 : : }
6968 : :
6969 : : /* Return true if field F of structure TYPE is a flexible array. */
6970 : :
6971 : : static bool
6972 : 3838766 : flexible_array_member_p (const_tree f, const_tree type)
6973 : : {
6974 : 3838766 : const_tree tf;
6975 : :
6976 : 3838766 : tf = TREE_TYPE (f);
6977 : 3838766 : return (DECL_CHAIN (f) == NULL
6978 : 1071486 : && TREE_CODE (tf) == ARRAY_TYPE
6979 : 2527 : && TYPE_DOMAIN (tf)
6980 : 2527 : && TYPE_MIN_VALUE (TYPE_DOMAIN (tf))
6981 : 2527 : && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf)))
6982 : 2527 : && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf))
6983 : 3838805 : && int_size_in_bytes (type) >= 0);
6984 : : }
6985 : :
6986 : : /* If FOR_CTOR_P, return the number of top-level elements that a constructor
6987 : : must have in order for it to completely initialize a value of type TYPE.
6988 : : Return -1 if the number isn't known.
6989 : :
6990 : : If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
6991 : :
6992 : : static HOST_WIDE_INT
6993 : 3493249 : count_type_elements (const_tree type, bool for_ctor_p)
6994 : : {
6995 : 3493249 : switch (TREE_CODE (type))
6996 : : {
6997 : 146463 : case ARRAY_TYPE:
6998 : 146463 : {
6999 : 146463 : tree nelts_minus_one;
7000 : :
7001 : 146463 : nelts_minus_one = array_type_nelts_minus_one (type);
7002 : 146463 : if (nelts_minus_one && tree_fits_uhwi_p (nelts_minus_one))
7003 : : {
7004 : 146454 : unsigned HOST_WIDE_INT n;
7005 : :
7006 : 146454 : n = tree_to_uhwi (nelts_minus_one) + 1;
7007 : 146454 : if (n == 0 || for_ctor_p)
7008 : 145719 : return n;
7009 : : else
7010 : 735 : return n * count_type_elements (TREE_TYPE (type), false);
7011 : : }
7012 : 9 : return for_ctor_p ? -1 : 1;
7013 : : }
7014 : :
7015 : 1709490 : case RECORD_TYPE:
7016 : 1709490 : {
7017 : 1709490 : unsigned HOST_WIDE_INT n;
7018 : 1709490 : tree f;
7019 : :
7020 : 1709490 : n = 0;
7021 : 15023164 : for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
7022 : 13313674 : if (TREE_CODE (f) == FIELD_DECL)
7023 : : {
7024 : 4293327 : if (!for_ctor_p)
7025 : 454561 : n += count_type_elements (TREE_TYPE (f), false);
7026 : 3838766 : else if (!flexible_array_member_p (f, type))
7027 : : /* Don't count flexible arrays, which are not supposed
7028 : : to be initialized. */
7029 : 3838727 : n += 1;
7030 : : }
7031 : :
7032 : 1709490 : return n;
7033 : : }
7034 : :
7035 : 3021 : case UNION_TYPE:
7036 : 3021 : case QUAL_UNION_TYPE:
7037 : 3021 : {
7038 : 3021 : tree f;
7039 : 3021 : HOST_WIDE_INT n, m;
7040 : :
7041 : 3021 : gcc_assert (!for_ctor_p);
7042 : : /* Estimate the number of scalars in each field and pick the
7043 : : maximum. Other estimates would do instead; the idea is simply
7044 : : to make sure that the estimate is not sensitive to the ordering
7045 : : of the fields. */
7046 : 3021 : n = 1;
7047 : 56976 : for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
7048 : 53955 : if (TREE_CODE (f) == FIELD_DECL)
7049 : : {
7050 : 49804 : m = count_type_elements (TREE_TYPE (f), false);
7051 : : /* If the field doesn't span the whole union, add an extra
7052 : : scalar for the rest. */
7053 : 49804 : if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f)),
7054 : 49804 : TYPE_SIZE (type)) != 1)
7055 : 32138 : m++;
7056 : 49804 : if (n < m)
7057 : 53955 : n = m;
7058 : : }
7059 : : return n;
7060 : : }
7061 : :
7062 : : case COMPLEX_TYPE:
7063 : : return 2;
7064 : :
7065 : 300 : case VECTOR_TYPE:
7066 : 300 : {
7067 : 300 : unsigned HOST_WIDE_INT nelts;
7068 : 300 : if (TYPE_VECTOR_SUBPARTS (type).is_constant (&nelts))
7069 : 300 : return nelts;
7070 : : else
7071 : : return -1;
7072 : : }
7073 : :
7074 : : case INTEGER_TYPE:
7075 : : case REAL_TYPE:
7076 : : case FIXED_POINT_TYPE:
7077 : : case ENUMERAL_TYPE:
7078 : : case BOOLEAN_TYPE:
7079 : : case POINTER_TYPE:
7080 : : case OFFSET_TYPE:
7081 : : case REFERENCE_TYPE:
7082 : : case NULLPTR_TYPE:
7083 : : case OPAQUE_TYPE:
7084 : : case BITINT_TYPE:
7085 : : return 1;
7086 : :
7087 : 0 : case ERROR_MARK:
7088 : 0 : return 0;
7089 : :
7090 : 0 : case VOID_TYPE:
7091 : 0 : case METHOD_TYPE:
7092 : 0 : case FUNCTION_TYPE:
7093 : 0 : case LANG_TYPE:
7094 : 0 : default:
7095 : 0 : gcc_unreachable ();
7096 : : }
7097 : : }
7098 : :
7099 : : /* Helper for categorize_ctor_elements. Identical interface. */
7100 : :
7101 : : static bool
7102 : 1461017 : categorize_ctor_elements_1 (const_tree ctor, HOST_WIDE_INT *p_nz_elts,
7103 : : HOST_WIDE_INT *p_unique_nz_elts,
7104 : : HOST_WIDE_INT *p_init_elts, int *p_complete)
7105 : : {
7106 : 1461017 : unsigned HOST_WIDE_INT idx;
7107 : 1461017 : HOST_WIDE_INT nz_elts, unique_nz_elts, init_elts, num_fields;
7108 : 1461017 : tree value, purpose, elt_type;
7109 : :
7110 : : /* Whether CTOR is a valid constant initializer, in accordance with what
7111 : : initializer_constant_valid_p does. If inferred from the constructor
7112 : : elements, true until proven otherwise. */
7113 : 1461017 : bool const_from_elts_p = constructor_static_from_elts_p (ctor);
7114 : 1461017 : bool const_p = const_from_elts_p ? true : TREE_STATIC (ctor);
7115 : :
7116 : 1461017 : nz_elts = 0;
7117 : 1461017 : unique_nz_elts = 0;
7118 : 1461017 : init_elts = 0;
7119 : 1461017 : num_fields = 0;
7120 : 1461017 : elt_type = NULL_TREE;
7121 : :
7122 : 5565441 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), idx, purpose, value)
7123 : : {
7124 : 4104424 : HOST_WIDE_INT mult = 1;
7125 : :
7126 : 4104424 : if (purpose && TREE_CODE (purpose) == RANGE_EXPR)
7127 : : {
7128 : 582 : tree lo_index = TREE_OPERAND (purpose, 0);
7129 : 582 : tree hi_index = TREE_OPERAND (purpose, 1);
7130 : :
7131 : 582 : if (tree_fits_uhwi_p (lo_index) && tree_fits_uhwi_p (hi_index))
7132 : 582 : mult = (tree_to_uhwi (hi_index)
7133 : 582 : - tree_to_uhwi (lo_index) + 1);
7134 : : }
7135 : 4104424 : num_fields += mult;
7136 : 4104424 : elt_type = TREE_TYPE (value);
7137 : :
7138 : 4104424 : switch (TREE_CODE (value))
7139 : : {
7140 : 508448 : case CONSTRUCTOR:
7141 : 508448 : {
7142 : 508448 : HOST_WIDE_INT nz = 0, unz = 0, ic = 0;
7143 : :
7144 : 508448 : bool const_elt_p = categorize_ctor_elements_1 (value, &nz, &unz,
7145 : : &ic, p_complete);
7146 : :
7147 : 508448 : nz_elts += mult * nz;
7148 : 508448 : unique_nz_elts += unz;
7149 : 508448 : init_elts += mult * ic;
7150 : :
7151 : 508448 : if (const_from_elts_p && const_p)
7152 : 295860 : const_p = const_elt_p;
7153 : : }
7154 : 508448 : break;
7155 : :
7156 : 2225788 : case INTEGER_CST:
7157 : 2225788 : case REAL_CST:
7158 : 2225788 : case FIXED_CST:
7159 : 2225788 : if (!initializer_zerop (value))
7160 : : {
7161 : 1624996 : nz_elts += mult;
7162 : 1624996 : unique_nz_elts++;
7163 : : }
7164 : 2225788 : init_elts += mult;
7165 : 2225788 : break;
7166 : :
7167 : 6297 : case STRING_CST:
7168 : 6297 : nz_elts += mult * TREE_STRING_LENGTH (value);
7169 : 6297 : unique_nz_elts += TREE_STRING_LENGTH (value);
7170 : 6297 : init_elts += mult * TREE_STRING_LENGTH (value);
7171 : 6297 : break;
7172 : :
7173 : 131 : case RAW_DATA_CST:
7174 : 131 : nz_elts += mult * RAW_DATA_LENGTH (value);
7175 : 131 : unique_nz_elts += RAW_DATA_LENGTH (value);
7176 : 131 : init_elts += mult * RAW_DATA_LENGTH (value);
7177 : 131 : num_fields += mult * (RAW_DATA_LENGTH (value) - 1);
7178 : 131 : break;
7179 : :
7180 : 2861 : case COMPLEX_CST:
7181 : 2861 : if (!initializer_zerop (TREE_REALPART (value)))
7182 : : {
7183 : 2434 : nz_elts += mult;
7184 : 2434 : unique_nz_elts++;
7185 : : }
7186 : 2861 : if (!initializer_zerop (TREE_IMAGPART (value)))
7187 : : {
7188 : 2300 : nz_elts += mult;
7189 : 2300 : unique_nz_elts++;
7190 : : }
7191 : 2861 : init_elts += 2 * mult;
7192 : 2861 : break;
7193 : :
7194 : 778 : case VECTOR_CST:
7195 : 778 : {
7196 : 778 : unsigned int nunits
7197 : : = constant_lower_bound
7198 : 778 : (TYPE_VECTOR_SUBPARTS (TREE_TYPE (value)));
7199 : 5269 : for (unsigned int i = 0; i < nunits; ++i)
7200 : : {
7201 : 4491 : tree v = VECTOR_CST_ELT (value, i);
7202 : 4491 : if (!initializer_zerop (v))
7203 : : {
7204 : 1993 : nz_elts += mult;
7205 : 1993 : unique_nz_elts++;
7206 : : }
7207 : 4491 : init_elts += mult;
7208 : : }
7209 : : }
7210 : : break;
7211 : :
7212 : 1360121 : default:
7213 : 1360121 : {
7214 : 1360121 : HOST_WIDE_INT tc = count_type_elements (elt_type, false);
7215 : 1360121 : nz_elts += mult * tc;
7216 : 1360121 : unique_nz_elts += tc;
7217 : 1360121 : init_elts += mult * tc;
7218 : :
7219 : 1360121 : if (const_from_elts_p && const_p)
7220 : 519681 : const_p
7221 : 519681 : = initializer_constant_valid_p (value,
7222 : : elt_type,
7223 : 519681 : TYPE_REVERSE_STORAGE_ORDER
7224 : : (TREE_TYPE (ctor)))
7225 : : != NULL_TREE;
7226 : : }
7227 : : break;
7228 : : }
7229 : : }
7230 : :
7231 : 1461017 : if (*p_complete && !complete_ctor_at_level_p (TREE_TYPE (ctor),
7232 : : num_fields, elt_type))
7233 : 163378 : *p_complete = 0;
7234 : 1297639 : else if (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
7235 : 1297639 : || TREE_CODE (TREE_TYPE (ctor)) == QUAL_UNION_TYPE)
7236 : : {
7237 : 10997 : if (*p_complete
7238 : 7094 : && CONSTRUCTOR_ZERO_PADDING_BITS (ctor)
7239 : 20128 : && (num_fields
7240 : 4567 : ? simple_cst_equal (TYPE_SIZE (TREE_TYPE (ctor)),
7241 : 4564 : TYPE_SIZE (elt_type)) != 1
7242 : 3 : : type_has_padding_at_level_p (TREE_TYPE (ctor))))
7243 : 3388 : *p_complete = 0;
7244 : 7609 : else if (*p_complete > 0
7245 : 10983 : && (num_fields
7246 : 3374 : ? simple_cst_equal (TYPE_SIZE (TREE_TYPE (ctor)),
7247 : 3374 : TYPE_SIZE (elt_type)) != 1
7248 : 0 : : type_has_padding_at_level_p (TREE_TYPE (ctor))))
7249 : 239 : *p_complete = -1;
7250 : : }
7251 : 1286642 : else if (*p_complete
7252 : 1210365 : && (CONSTRUCTOR_ZERO_PADDING_BITS (ctor)
7253 : 1197913 : || flag_zero_init_padding_bits == ZERO_INIT_PADDING_BITS_ALL)
7254 : 1299099 : && type_has_padding_at_level_p (TREE_TYPE (ctor)))
7255 : 2003 : *p_complete = 0;
7256 : 1284639 : else if (*p_complete > 0
7257 : 1284639 : && type_has_padding_at_level_p (TREE_TYPE (ctor)))
7258 : 15381 : *p_complete = -1;
7259 : :
7260 : 1461017 : *p_nz_elts += nz_elts;
7261 : 1461017 : *p_unique_nz_elts += unique_nz_elts;
7262 : 1461017 : *p_init_elts += init_elts;
7263 : :
7264 : 1461017 : return const_p;
7265 : : }
7266 : :
7267 : : /* Examine CTOR to discover:
7268 : : * how many scalar fields are set to nonzero values,
7269 : : and place it in *P_NZ_ELTS;
7270 : : * the same, but counting RANGE_EXPRs as multiplier of 1 instead of
7271 : : high - low + 1 (this can be useful for callers to determine ctors
7272 : : that could be cheaply initialized with - perhaps nested - loops
7273 : : compared to copied from huge read-only data),
7274 : : and place it in *P_UNIQUE_NZ_ELTS;
7275 : : * how many scalar fields in total are in CTOR,
7276 : : and place it in *P_ELT_COUNT.
7277 : : * whether the constructor is complete -- in the sense that every
7278 : : meaningful byte is explicitly given a value --
7279 : : and place it in *P_COMPLETE:
7280 : : - 0 if any field is missing
7281 : : - 1 if all fields are initialized, and there's no padding
7282 : : - -1 if all fields are initialized, but there's padding
7283 : :
7284 : : Return whether or not CTOR is a valid static constant initializer, the same
7285 : : as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
7286 : :
7287 : : bool
7288 : 952569 : categorize_ctor_elements (const_tree ctor, HOST_WIDE_INT *p_nz_elts,
7289 : : HOST_WIDE_INT *p_unique_nz_elts,
7290 : : HOST_WIDE_INT *p_init_elts, int *p_complete)
7291 : : {
7292 : 952569 : *p_nz_elts = 0;
7293 : 952569 : *p_unique_nz_elts = 0;
7294 : 952569 : *p_init_elts = 0;
7295 : 952569 : *p_complete = 1;
7296 : :
7297 : 952569 : return categorize_ctor_elements_1 (ctor, p_nz_elts, p_unique_nz_elts,
7298 : 952569 : p_init_elts, p_complete);
7299 : : }
7300 : :
7301 : : /* Return true if constructor CTOR is simple enough to be materialized
7302 : : in an integer mode register. Limit the size to WORDS words, which
7303 : : is 1 by default. */
7304 : :
7305 : : bool
7306 : 21571 : immediate_const_ctor_p (const_tree ctor, unsigned int words)
7307 : : {
7308 : : /* Allow function to be called with a VAR_DECL's DECL_INITIAL. */
7309 : 21571 : if (!ctor || TREE_CODE (ctor) != CONSTRUCTOR)
7310 : : return false;
7311 : :
7312 : 2059 : return TREE_CONSTANT (ctor)
7313 : 2059 : && !TREE_ADDRESSABLE (ctor)
7314 : 2059 : && CONSTRUCTOR_NELTS (ctor)
7315 : 2035 : && TREE_CODE (TREE_TYPE (ctor)) != ARRAY_TYPE
7316 : 637 : && int_expr_size (ctor) <= words * UNITS_PER_WORD
7317 : 2212 : && initializer_constant_valid_for_bitfield_p (ctor);
7318 : : }
7319 : :
7320 : : /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
7321 : : of which had type LAST_TYPE. Each element was itself a complete
7322 : : initializer, in the sense that every meaningful byte was explicitly
7323 : : given a value. Return true if the same is true for the constructor
7324 : : as a whole. */
7325 : :
7326 : : bool
7327 : 1636086 : complete_ctor_at_level_p (const_tree type, HOST_WIDE_INT num_elts,
7328 : : const_tree last_type)
7329 : : {
7330 : 1636086 : if (TREE_CODE (type) == UNION_TYPE || TREE_CODE (type) == QUAL_UNION_TYPE)
7331 : : {
7332 : 8058 : if (num_elts == 0)
7333 : : {
7334 : 24 : if (flag_zero_init_padding_bits >= ZERO_INIT_PADDING_BITS_UNIONS)
7335 : : return false;
7336 : :
7337 : : /* If the CONSTRUCTOR doesn't have any elts, it is
7338 : : incomplete if the union has at least one field. */
7339 : 27 : for (tree f = TYPE_FIELDS (type); f; f = DECL_CHAIN (f))
7340 : 24 : if (TREE_CODE (f) == FIELD_DECL)
7341 : : return false;
7342 : :
7343 : : return true;
7344 : : }
7345 : :
7346 : 8034 : gcc_assert (num_elts == 1 && last_type);
7347 : :
7348 : 8034 : if (flag_zero_init_padding_bits >= ZERO_INIT_PADDING_BITS_UNIONS)
7349 : : /* ??? We could look at each element of the union, and find the
7350 : : largest element. Which would avoid comparing the size of the
7351 : : initialized element against any tail padding in the union.
7352 : : Doesn't seem worth the effort... */
7353 : 6 : return simple_cst_equal (TYPE_SIZE (type), TYPE_SIZE (last_type)) == 1;
7354 : :
7355 : : return true;
7356 : : }
7357 : :
7358 : 1628028 : return count_type_elements (type, true) == num_elts;
7359 : : }
7360 : :
7361 : : /* Return true if EXP contains mostly (3/4) zeros. */
7362 : :
7363 : : static bool
7364 : 418349 : mostly_zeros_p (const_tree exp)
7365 : : {
7366 : 418349 : if (TREE_CODE (exp) == CONSTRUCTOR)
7367 : : {
7368 : 104 : HOST_WIDE_INT nz_elts, unz_elts, init_elts;
7369 : 104 : int complete_p;
7370 : :
7371 : 104 : categorize_ctor_elements (exp, &nz_elts, &unz_elts, &init_elts,
7372 : : &complete_p);
7373 : 104 : return !complete_p || nz_elts < init_elts / 4;
7374 : : }
7375 : :
7376 : 418245 : return initializer_zerop (exp);
7377 : : }
7378 : :
7379 : : /* Return true if EXP contains all zeros. */
7380 : :
7381 : : static bool
7382 : 2867 : all_zeros_p (const_tree exp)
7383 : : {
7384 : 2867 : if (TREE_CODE (exp) == CONSTRUCTOR)
7385 : : {
7386 : 2867 : HOST_WIDE_INT nz_elts, unz_elts, init_elts;
7387 : 2867 : int complete_p;
7388 : :
7389 : 2867 : categorize_ctor_elements (exp, &nz_elts, &unz_elts, &init_elts,
7390 : : &complete_p);
7391 : 2867 : return nz_elts == 0;
7392 : : }
7393 : :
7394 : 0 : return initializer_zerop (exp);
7395 : : }
7396 : :
7397 : : /* Helper function for store_constructor.
7398 : : TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
7399 : : CLEARED is as for store_constructor.
7400 : : ALIAS_SET is the alias set to use for any stores.
7401 : : If REVERSE is true, the store is to be done in reverse order.
7402 : :
7403 : : This provides a recursive shortcut back to store_constructor when it isn't
7404 : : necessary to go through store_field. This is so that we can pass through
7405 : : the cleared field to let store_constructor know that we may not have to
7406 : : clear a substructure if the outer structure has already been cleared. */
7407 : :
7408 : : static void
7409 : 33110 : store_constructor_field (rtx target, poly_uint64 bitsize, poly_int64 bitpos,
7410 : : poly_uint64 bitregion_start,
7411 : : poly_uint64 bitregion_end,
7412 : : machine_mode mode,
7413 : : tree exp, int cleared,
7414 : : alias_set_type alias_set, bool reverse)
7415 : : {
7416 : 33110 : poly_int64 bytepos;
7417 : 33110 : poly_uint64 bytesize;
7418 : 33110 : if (TREE_CODE (exp) == CONSTRUCTOR
7419 : : /* We can only call store_constructor recursively if the size and
7420 : : bit position are on a byte boundary. */
7421 : 60 : && multiple_p (bitpos, BITS_PER_UNIT, &bytepos)
7422 : 60 : && maybe_ne (bitsize, 0U)
7423 : 33110 : && multiple_p (bitsize, BITS_PER_UNIT, &bytesize)
7424 : : /* If we have a nonzero bitpos for a register target, then we just
7425 : : let store_field do the bitfield handling. This is unlikely to
7426 : : generate unnecessary clear instructions anyways. */
7427 : 33170 : && (known_eq (bitpos, 0) || MEM_P (target)))
7428 : : {
7429 : 60 : if (MEM_P (target))
7430 : : {
7431 : 18 : machine_mode target_mode = GET_MODE (target);
7432 : 18 : if (target_mode != BLKmode
7433 : 18 : && !multiple_p (bitpos, GET_MODE_ALIGNMENT (target_mode)))
7434 : : target_mode = BLKmode;
7435 : 18 : target = adjust_address (target, target_mode, bytepos);
7436 : : }
7437 : :
7438 : :
7439 : : /* Update the alias set, if required. */
7440 : 18 : if (MEM_P (target) && ! MEM_KEEP_ALIAS_SET_P (target)
7441 : 78 : && MEM_ALIAS_SET (target) != 0)
7442 : : {
7443 : 18 : target = copy_rtx (target);
7444 : 18 : set_mem_alias_set (target, alias_set);
7445 : : }
7446 : :
7447 : 60 : store_constructor (exp, target, cleared, bytesize, reverse);
7448 : : }
7449 : : else
7450 : 33050 : store_field (target, bitsize, bitpos, bitregion_start, bitregion_end, mode,
7451 : : exp, alias_set, false, reverse);
7452 : 33110 : }
7453 : :
7454 : :
7455 : : /* Returns the number of FIELD_DECLs in TYPE. */
7456 : :
7457 : : static int
7458 : 59061 : fields_length (const_tree type)
7459 : : {
7460 : 59061 : tree t = TYPE_FIELDS (type);
7461 : 59061 : int count = 0;
7462 : :
7463 : 521907 : for (; t; t = DECL_CHAIN (t))
7464 : 462846 : if (TREE_CODE (t) == FIELD_DECL)
7465 : 271687 : ++count;
7466 : :
7467 : 59061 : return count;
7468 : : }
7469 : :
7470 : :
7471 : : /* Store the value of constructor EXP into the rtx TARGET.
7472 : : TARGET is either a REG or a MEM; we know it cannot conflict, since
7473 : : safe_from_p has been called.
7474 : : CLEARED is true if TARGET is known to have been zero'd.
7475 : : SIZE is the number of bytes of TARGET we are allowed to modify: this
7476 : : may not be the same as the size of EXP if we are assigning to a field
7477 : : which has been packed to exclude padding bits.
7478 : : If REVERSE is true, the store is to be done in reverse order. */
7479 : :
7480 : : void
7481 : 281375 : store_constructor (tree exp, rtx target, int cleared, poly_int64 size,
7482 : : bool reverse)
7483 : : {
7484 : 281375 : tree type = TREE_TYPE (exp);
7485 : 281375 : HOST_WIDE_INT exp_size = int_size_in_bytes (type);
7486 : 281375 : poly_int64 bitregion_end = known_gt (size, 0) ? size * BITS_PER_UNIT - 1 : 0;
7487 : :
7488 : 281375 : switch (TREE_CODE (type))
7489 : : {
7490 : 60936 : case RECORD_TYPE:
7491 : 60936 : case UNION_TYPE:
7492 : 60936 : case QUAL_UNION_TYPE:
7493 : 60936 : {
7494 : 60936 : unsigned HOST_WIDE_INT idx;
7495 : 60936 : tree field, value;
7496 : :
7497 : : /* The storage order is specified for every aggregate type. */
7498 : 60936 : reverse = TYPE_REVERSE_STORAGE_ORDER (type);
7499 : :
7500 : : /* If size is zero or the target is already cleared, do nothing. */
7501 : 60936 : if (known_eq (size, 0) || cleared)
7502 : : cleared = 1;
7503 : : /* We either clear the aggregate or indicate the value is dead. */
7504 : 60936 : else if ((TREE_CODE (type) == UNION_TYPE
7505 : 60936 : || TREE_CODE (type) == QUAL_UNION_TYPE)
7506 : 62584 : && ! CONSTRUCTOR_ELTS (exp))
7507 : : /* If the constructor is empty, clear the union. */
7508 : : {
7509 : 1599 : clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
7510 : 1599 : cleared = 1;
7511 : : }
7512 : :
7513 : : /* If we are building a static constructor into a register,
7514 : : set the initial value as zero so we can fold the value into
7515 : : a constant. But if more than one register is involved,
7516 : : this probably loses. */
7517 : 3575 : else if (REG_P (target) && TREE_STATIC (exp)
7518 : 60035 : && known_le (GET_MODE_SIZE (GET_MODE (target)),
7519 : : REGMODE_NATURAL_SIZE (GET_MODE (target))))
7520 : : {
7521 : 276 : emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
7522 : 276 : cleared = 1;
7523 : : }
7524 : :
7525 : : /* If the constructor has fewer fields than the structure or
7526 : : if we are initializing the structure to mostly zeros, clear
7527 : : the whole structure first. Don't do this if TARGET is a
7528 : : register whose mode size isn't equal to SIZE since
7529 : : clear_storage can't handle this case. */
7530 : 59061 : else if (known_size_p (size)
7531 : 59137 : && (((int) CONSTRUCTOR_NELTS (exp) != fields_length (type))
7532 : 66 : || mostly_zeros_p (exp))
7533 : 118056 : && (!REG_P (target)
7534 : 6594 : || known_eq (GET_MODE_SIZE (GET_MODE (target)), size)))
7535 : : {
7536 : 58995 : clear_storage (target, gen_int_mode (size, Pmode),
7537 : : BLOCK_OP_NORMAL);
7538 : 58995 : cleared = 1;
7539 : : }
7540 : :
7541 : 60936 : if (REG_P (target) && !cleared)
7542 : 2 : emit_clobber (target);
7543 : :
7544 : : /* Store each element of the constructor into the
7545 : : corresponding field of TARGET. */
7546 : 61261 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, field, value)
7547 : : {
7548 : 325 : machine_mode mode;
7549 : 325 : HOST_WIDE_INT bitsize;
7550 : 325 : HOST_WIDE_INT bitpos = 0;
7551 : 325 : tree offset;
7552 : 325 : rtx to_rtx = target;
7553 : :
7554 : : /* Just ignore missing fields. We cleared the whole
7555 : : structure, above, if any fields are missing. */
7556 : 325 : if (field == 0)
7557 : 325 : continue;
7558 : :
7559 : 325 : if (cleared && initializer_zerop (value))
7560 : 78 : continue;
7561 : :
7562 : 247 : if (tree_fits_uhwi_p (DECL_SIZE (field)))
7563 : 247 : bitsize = tree_to_uhwi (DECL_SIZE (field));
7564 : : else
7565 : 0 : gcc_unreachable ();
7566 : :
7567 : 247 : mode = DECL_MODE (field);
7568 : 247 : if (DECL_BIT_FIELD (field))
7569 : 74 : mode = VOIDmode;
7570 : :
7571 : 247 : offset = DECL_FIELD_OFFSET (field);
7572 : 247 : if (tree_fits_shwi_p (offset)
7573 : 247 : && tree_fits_shwi_p (bit_position (field)))
7574 : : {
7575 : 247 : bitpos = int_bit_position (field);
7576 : 247 : offset = NULL_TREE;
7577 : : }
7578 : : else
7579 : 0 : gcc_unreachable ();
7580 : :
7581 : : /* If this initializes a field that is smaller than a
7582 : : word, at the start of a word, try to widen it to a full
7583 : : word. This special case allows us to output C++ member
7584 : : function initializations in a form that the optimizers
7585 : : can understand. */
7586 : 247 : if (WORD_REGISTER_OPERATIONS
7587 : : && REG_P (target)
7588 : : && bitsize < BITS_PER_WORD
7589 : : && bitpos % BITS_PER_WORD == 0
7590 : : && GET_MODE_CLASS (mode) == MODE_INT
7591 : : && TREE_CODE (value) == INTEGER_CST
7592 : : && exp_size >= 0
7593 : : && bitpos + BITS_PER_WORD <= exp_size * BITS_PER_UNIT)
7594 : : {
7595 : : type = TREE_TYPE (value);
7596 : :
7597 : : if (TYPE_PRECISION (type) < BITS_PER_WORD)
7598 : : {
7599 : : type = lang_hooks.types.type_for_mode
7600 : : (word_mode, TYPE_UNSIGNED (type));
7601 : : value = fold_convert (type, value);
7602 : : /* Make sure the bits beyond the original bitsize are zero
7603 : : so that we can correctly avoid extra zeroing stores in
7604 : : later constructor elements. */
7605 : : tree bitsize_mask
7606 : : = wide_int_to_tree (type, wi::mask (bitsize, false,
7607 : : BITS_PER_WORD));
7608 : : value = fold_build2 (BIT_AND_EXPR, type, value, bitsize_mask);
7609 : : }
7610 : :
7611 : : if (BYTES_BIG_ENDIAN)
7612 : : value
7613 : : = fold_build2 (LSHIFT_EXPR, type, value,
7614 : : build_int_cst (type,
7615 : : BITS_PER_WORD - bitsize));
7616 : : bitsize = BITS_PER_WORD;
7617 : : mode = word_mode;
7618 : : }
7619 : :
7620 : 82 : if (MEM_P (to_rtx) && !MEM_KEEP_ALIAS_SET_P (to_rtx)
7621 : 329 : && DECL_NONADDRESSABLE_P (field))
7622 : : {
7623 : 0 : to_rtx = copy_rtx (to_rtx);
7624 : 0 : MEM_KEEP_ALIAS_SET_P (to_rtx) = 1;
7625 : : }
7626 : :
7627 : 247 : store_constructor_field (to_rtx, bitsize, bitpos,
7628 : 247 : 0, bitregion_end, mode,
7629 : : value, cleared,
7630 : 247 : get_alias_set (TREE_TYPE (field)),
7631 : : reverse);
7632 : : }
7633 : : break;
7634 : : }
7635 : 42089 : case ARRAY_TYPE:
7636 : 42089 : {
7637 : 42089 : tree value, index;
7638 : 42089 : unsigned HOST_WIDE_INT i;
7639 : 42089 : bool need_to_clear;
7640 : 42089 : tree domain;
7641 : 42089 : tree elttype = TREE_TYPE (type);
7642 : 42089 : bool const_bounds_p;
7643 : 42089 : HOST_WIDE_INT minelt = 0;
7644 : 42089 : HOST_WIDE_INT maxelt = 0;
7645 : :
7646 : : /* The storage order is specified for every aggregate type. */
7647 : 42089 : reverse = TYPE_REVERSE_STORAGE_ORDER (type);
7648 : :
7649 : 42089 : domain = TYPE_DOMAIN (type);
7650 : 42089 : const_bounds_p = (TYPE_MIN_VALUE (domain)
7651 : 42089 : && TYPE_MAX_VALUE (domain)
7652 : 42089 : && tree_fits_shwi_p (TYPE_MIN_VALUE (domain))
7653 : 84178 : && tree_fits_shwi_p (TYPE_MAX_VALUE (domain)));
7654 : :
7655 : : /* If we have constant bounds for the range of the type, get them. */
7656 : 42089 : if (const_bounds_p)
7657 : : {
7658 : 42089 : minelt = tree_to_shwi (TYPE_MIN_VALUE (domain));
7659 : 42089 : maxelt = tree_to_shwi (TYPE_MAX_VALUE (domain));
7660 : : }
7661 : :
7662 : : /* If the constructor has fewer elements than the array, clear
7663 : : the whole array first. Similarly if this is static
7664 : : constructor of a non-BLKmode object. */
7665 : 42089 : if (cleared)
7666 : : need_to_clear = false;
7667 : 42047 : else if (REG_P (target) && TREE_STATIC (exp))
7668 : : need_to_clear = true;
7669 : : else
7670 : : {
7671 : 42040 : unsigned HOST_WIDE_INT idx;
7672 : 42040 : HOST_WIDE_INT count = 0, zero_count = 0;
7673 : 42040 : need_to_clear = ! const_bounds_p;
7674 : :
7675 : : /* This loop is a more accurate version of the loop in
7676 : : mostly_zeros_p (it handles RANGE_EXPR in an index). It
7677 : : is also needed to check for missing elements. */
7678 : 42096 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, index, value)
7679 : : {
7680 : 56 : HOST_WIDE_INT this_node_count;
7681 : :
7682 : 56 : if (need_to_clear)
7683 : : break;
7684 : :
7685 : 56 : if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
7686 : : {
7687 : 0 : tree lo_index = TREE_OPERAND (index, 0);
7688 : 0 : tree hi_index = TREE_OPERAND (index, 1);
7689 : :
7690 : 0 : if (! tree_fits_uhwi_p (lo_index)
7691 : 0 : || ! tree_fits_uhwi_p (hi_index))
7692 : : {
7693 : : need_to_clear = true;
7694 : : break;
7695 : : }
7696 : :
7697 : 0 : this_node_count = (tree_to_uhwi (hi_index)
7698 : 0 : - tree_to_uhwi (lo_index) + 1);
7699 : 0 : }
7700 : : else
7701 : : this_node_count = 1;
7702 : :
7703 : 56 : count += this_node_count;
7704 : 56 : if (mostly_zeros_p (value))
7705 : 0 : zero_count += this_node_count;
7706 : : }
7707 : :
7708 : : /* Clear the entire array first if there are any missing
7709 : : elements, or if the incidence of zero elements is >=
7710 : : 75%. */
7711 : 42040 : if (! need_to_clear
7712 : 42040 : && (count < maxelt - minelt + 1
7713 : 7 : || 4 * zero_count >= 3 * count))
7714 : : need_to_clear = true;
7715 : : }
7716 : :
7717 : 42040 : if (need_to_clear && maybe_gt (size, 0))
7718 : : {
7719 : 42040 : if (REG_P (target))
7720 : 1623 : emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
7721 : : else
7722 : 40417 : clear_storage (target, gen_int_mode (size, Pmode),
7723 : : BLOCK_OP_NORMAL);
7724 : : cleared = 1;
7725 : : }
7726 : :
7727 : 49 : if (!cleared && REG_P (target))
7728 : : /* Inform later passes that the old value is dead. */
7729 : 0 : emit_clobber (target);
7730 : :
7731 : : /* Store each element of the constructor into the
7732 : : corresponding element of TARGET, determined by counting the
7733 : : elements. */
7734 : 42481 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), i, index, value)
7735 : : {
7736 : 392 : machine_mode mode;
7737 : 392 : poly_int64 bitsize;
7738 : 392 : HOST_WIDE_INT bitpos;
7739 : 392 : rtx xtarget = target;
7740 : :
7741 : 392 : if (cleared && initializer_zerop (value))
7742 : 0 : continue;
7743 : :
7744 : 392 : mode = TYPE_MODE (elttype);
7745 : 392 : if (mode != BLKmode)
7746 : 784 : bitsize = GET_MODE_BITSIZE (mode);
7747 : 0 : else if (!poly_int_tree_p (TYPE_SIZE (elttype), &bitsize))
7748 : 0 : bitsize = -1;
7749 : :
7750 : 392 : if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
7751 : : {
7752 : 0 : tree lo_index = TREE_OPERAND (index, 0);
7753 : 0 : tree hi_index = TREE_OPERAND (index, 1);
7754 : 0 : rtx index_r, pos_rtx;
7755 : 0 : HOST_WIDE_INT lo, hi, count;
7756 : 0 : tree position;
7757 : :
7758 : : /* If the range is constant and "small", unroll the loop. */
7759 : 0 : if (const_bounds_p
7760 : 0 : && tree_fits_shwi_p (lo_index)
7761 : 0 : && tree_fits_shwi_p (hi_index)
7762 : 0 : && (lo = tree_to_shwi (lo_index),
7763 : 0 : hi = tree_to_shwi (hi_index),
7764 : 0 : count = hi - lo + 1,
7765 : 0 : (!MEM_P (target)
7766 : 0 : || count <= 2
7767 : 0 : || (tree_fits_uhwi_p (TYPE_SIZE (elttype))
7768 : 0 : && (tree_to_uhwi (TYPE_SIZE (elttype)) * count
7769 : : <= 40 * 8)))))
7770 : : {
7771 : 0 : lo -= minelt; hi -= minelt;
7772 : 0 : for (; lo <= hi; lo++)
7773 : : {
7774 : 0 : bitpos = lo * tree_to_shwi (TYPE_SIZE (elttype));
7775 : :
7776 : 0 : if (MEM_P (target)
7777 : 0 : && !MEM_KEEP_ALIAS_SET_P (target)
7778 : 0 : && TREE_CODE (type) == ARRAY_TYPE
7779 : 0 : && TYPE_NONALIASED_COMPONENT (type))
7780 : : {
7781 : 0 : target = copy_rtx (target);
7782 : 0 : MEM_KEEP_ALIAS_SET_P (target) = 1;
7783 : : }
7784 : :
7785 : 0 : store_constructor_field
7786 : 0 : (target, bitsize, bitpos, 0, bitregion_end,
7787 : : mode, value, cleared,
7788 : : get_alias_set (elttype), reverse);
7789 : : }
7790 : : }
7791 : : else
7792 : : {
7793 : 0 : rtx_code_label *loop_start = gen_label_rtx ();
7794 : 0 : rtx_code_label *loop_end = gen_label_rtx ();
7795 : 0 : tree exit_cond;
7796 : :
7797 : 0 : expand_normal (hi_index);
7798 : :
7799 : 0 : index = build_decl (EXPR_LOCATION (exp),
7800 : : VAR_DECL, NULL_TREE, domain);
7801 : 0 : index_r = gen_reg_rtx (promote_decl_mode (index, NULL));
7802 : 0 : SET_DECL_RTL (index, index_r);
7803 : 0 : store_expr (lo_index, index_r, 0, false, reverse);
7804 : :
7805 : : /* Build the head of the loop. */
7806 : 0 : do_pending_stack_adjust ();
7807 : 0 : emit_label (loop_start);
7808 : :
7809 : : /* Assign value to element index. */
7810 : 0 : position =
7811 : 0 : fold_convert (ssizetype,
7812 : : fold_build2 (MINUS_EXPR,
7813 : : TREE_TYPE (index),
7814 : : index,
7815 : : TYPE_MIN_VALUE (domain)));
7816 : :
7817 : 0 : position =
7818 : 0 : size_binop (MULT_EXPR, position,
7819 : : fold_convert (ssizetype,
7820 : : TYPE_SIZE_UNIT (elttype)));
7821 : :
7822 : 0 : pos_rtx = expand_normal (position);
7823 : 0 : xtarget = offset_address (target, pos_rtx,
7824 : : highest_pow2_factor (position));
7825 : 0 : xtarget = adjust_address (xtarget, mode, 0);
7826 : 0 : if (TREE_CODE (value) == CONSTRUCTOR)
7827 : 0 : store_constructor (value, xtarget, cleared,
7828 : : exact_div (bitsize, BITS_PER_UNIT),
7829 : : reverse);
7830 : : else
7831 : 0 : store_expr (value, xtarget, 0, false, reverse);
7832 : :
7833 : : /* Generate a conditional jump to exit the loop. */
7834 : 0 : exit_cond = build2 (LT_EXPR, integer_type_node,
7835 : : index, hi_index);
7836 : 0 : jumpif (exit_cond, loop_end,
7837 : : profile_probability::uninitialized ());
7838 : :
7839 : : /* Update the loop counter, and jump to the head of
7840 : : the loop. */
7841 : 0 : expand_assignment (index,
7842 : 0 : build2 (PLUS_EXPR, TREE_TYPE (index),
7843 : : index, integer_one_node),
7844 : : false);
7845 : :
7846 : 0 : emit_jump (loop_start);
7847 : :
7848 : : /* Build the end of the loop. */
7849 : 0 : emit_label (loop_end);
7850 : : }
7851 : : }
7852 : 392 : else if ((index != 0 && ! tree_fits_shwi_p (index))
7853 : 392 : || ! tree_fits_uhwi_p (TYPE_SIZE (elttype)))
7854 : : {
7855 : 0 : tree position;
7856 : :
7857 : 0 : if (index == 0)
7858 : 0 : index = ssize_int (1);
7859 : :
7860 : 0 : if (minelt)
7861 : 0 : index = fold_convert (ssizetype,
7862 : : fold_build2 (MINUS_EXPR,
7863 : : TREE_TYPE (index),
7864 : : index,
7865 : : TYPE_MIN_VALUE (domain)));
7866 : :
7867 : 0 : position =
7868 : 0 : size_binop (MULT_EXPR, index,
7869 : : fold_convert (ssizetype,
7870 : : TYPE_SIZE_UNIT (elttype)));
7871 : 0 : xtarget = offset_address (target,
7872 : : expand_normal (position),
7873 : : highest_pow2_factor (position));
7874 : 0 : xtarget = adjust_address (xtarget, mode, 0);
7875 : 0 : store_expr (value, xtarget, 0, false, reverse);
7876 : : }
7877 : : else
7878 : : {
7879 : 392 : if (index != 0)
7880 : 784 : bitpos = ((tree_to_shwi (index) - minelt)
7881 : 392 : * tree_to_uhwi (TYPE_SIZE (elttype)));
7882 : : else
7883 : 0 : bitpos = (i * tree_to_uhwi (TYPE_SIZE (elttype)));
7884 : :
7885 : 56 : if (MEM_P (target) && !MEM_KEEP_ALIAS_SET_P (target)
7886 : 56 : && TREE_CODE (type) == ARRAY_TYPE
7887 : 448 : && TYPE_NONALIASED_COMPONENT (type))
7888 : : {
7889 : 0 : target = copy_rtx (target);
7890 : 0 : MEM_KEEP_ALIAS_SET_P (target) = 1;
7891 : : }
7892 : 392 : store_constructor_field (target, bitsize, bitpos, 0,
7893 : : bitregion_end, mode, value,
7894 : : cleared, get_alias_set (elttype),
7895 : : reverse);
7896 : : }
7897 : : }
7898 : : break;
7899 : : }
7900 : :
7901 : 178350 : case VECTOR_TYPE:
7902 : 178350 : {
7903 : 178350 : unsigned HOST_WIDE_INT idx;
7904 : 178350 : constructor_elt *ce;
7905 : 178350 : bool need_to_clear;
7906 : 178350 : insn_code icode = CODE_FOR_nothing;
7907 : 178350 : tree elt;
7908 : 178350 : tree elttype = TREE_TYPE (type);
7909 : 178350 : int elt_size = vector_element_bits (type);
7910 : 178350 : machine_mode eltmode = TYPE_MODE (elttype);
7911 : 178350 : poly_int64 bitsize;
7912 : 178350 : poly_int64 bitpos;
7913 : 178350 : rtvec vector = NULL;
7914 : 178350 : poly_uint64 n_elts;
7915 : 178350 : unsigned HOST_WIDE_INT const_n_elts;
7916 : 178350 : alias_set_type alias;
7917 : 178350 : bool vec_vec_init_p = false;
7918 : 178350 : machine_mode mode = GET_MODE (target);
7919 : :
7920 : 178350 : gcc_assert (eltmode != BLKmode);
7921 : :
7922 : : /* Try using vec_duplicate_optab for uniform vectors. */
7923 : 178350 : icode = optab_handler (vec_duplicate_optab, mode);
7924 : 178350 : if (!TREE_SIDE_EFFECTS (exp)
7925 : 178350 : && VECTOR_MODE_P (mode)
7926 : 175171 : && icode != CODE_FOR_nothing
7927 : : /* If the vec_duplicate target pattern does not specify an element
7928 : : mode check that eltmode is the normal inner mode of the
7929 : : requested vector mode. But if the target allows eltmode
7930 : : explicitly go ahead and use it. */
7931 : 121531 : && (eltmode == GET_MODE_INNER (mode)
7932 : 0 : || insn_data[icode].operand[1].mode == eltmode)
7933 : 121531 : && (elt = uniform_vector_p (exp))
7934 : 205338 : && !VECTOR_TYPE_P (TREE_TYPE (elt)))
7935 : : {
7936 : 26988 : class expand_operand ops[2];
7937 : 26988 : create_output_operand (&ops[0], target, mode);
7938 : 26988 : create_input_operand (&ops[1], expand_normal (elt), eltmode);
7939 : 26988 : expand_insn (icode, 2, ops);
7940 : 26988 : if (!rtx_equal_p (target, ops[0].value))
7941 : 0 : emit_move_insn (target, ops[0].value);
7942 : 26988 : break;
7943 : : }
7944 : : /* Use sign-extension for uniform boolean vectors with
7945 : : integer modes and single-bit mask entries.
7946 : : Effectively "vec_duplicate" for bitmasks. */
7947 : 151362 : if (elt_size == 1
7948 : 184 : && !TREE_SIDE_EFFECTS (exp)
7949 : 184 : && VECTOR_BOOLEAN_TYPE_P (type)
7950 : 184 : && SCALAR_INT_MODE_P (TYPE_MODE (type))
7951 : 184 : && (elt = uniform_vector_p (exp))
7952 : 151545 : && !VECTOR_TYPE_P (TREE_TYPE (elt)))
7953 : : {
7954 : 183 : rtx op0 = force_reg (TYPE_MODE (TREE_TYPE (elt)),
7955 : : expand_normal (elt));
7956 : 183 : rtx tmp = gen_reg_rtx (mode);
7957 : 183 : convert_move (tmp, op0, 0);
7958 : :
7959 : : /* Ensure no excess bits are set.
7960 : : GCN needs this for nunits < 64.
7961 : : x86 needs this for nunits < 8. */
7962 : 183 : auto nunits = TYPE_VECTOR_SUBPARTS (type).to_constant ();
7963 : 183 : if (maybe_ne (GET_MODE_PRECISION (mode), nunits))
7964 : 2 : tmp = expand_binop (mode, and_optab, tmp,
7965 : 2 : GEN_INT ((HOST_WIDE_INT_1U << nunits) - 1),
7966 : : target, true, OPTAB_WIDEN);
7967 : 183 : if (tmp != target)
7968 : 181 : emit_move_insn (target, tmp);
7969 : : break;
7970 : : }
7971 : :
7972 : 151179 : n_elts = TYPE_VECTOR_SUBPARTS (type);
7973 : 151179 : if (REG_P (target)
7974 : 148354 : && VECTOR_MODE_P (mode))
7975 : : {
7976 : 148183 : const_n_elts = 0;
7977 : 148183 : if (CONSTRUCTOR_NELTS (exp)
7978 : 148183 : && (TREE_CODE (TREE_TYPE (CONSTRUCTOR_ELT (exp, 0)->value))
7979 : : == VECTOR_TYPE))
7980 : : {
7981 : 1079 : tree etype = TREE_TYPE (CONSTRUCTOR_ELT (exp, 0)->value);
7982 : 1079 : gcc_assert (known_eq (CONSTRUCTOR_NELTS (exp)
7983 : : * TYPE_VECTOR_SUBPARTS (etype),
7984 : : n_elts));
7985 : :
7986 : 3237 : icode = convert_optab_handler (vec_init_optab, mode,
7987 : 1079 : TYPE_MODE (etype));
7988 : 1079 : const_n_elts = CONSTRUCTOR_NELTS (exp);
7989 : 1079 : vec_vec_init_p = icode != CODE_FOR_nothing;
7990 : : }
7991 : 294208 : else if (exact_div (n_elts, GET_MODE_NUNITS (eltmode))
7992 : 147104 : .is_constant (&const_n_elts))
7993 : : {
7994 : : /* For a non-const type vector, we check it is made up of
7995 : : similarly non-const type vectors. */
7996 : 147104 : icode = convert_optab_handler (vec_init_optab, mode, eltmode);
7997 : : }
7998 : :
7999 : 148183 : if (const_n_elts && icode != CODE_FOR_nothing)
8000 : : {
8001 : 146811 : vector = rtvec_alloc (const_n_elts);
8002 : 526995 : for (unsigned int k = 0; k < const_n_elts; k++)
8003 : 380184 : RTVEC_ELT (vector, k) = CONST0_RTX (eltmode);
8004 : : }
8005 : : }
8006 : :
8007 : : /* Compute the size of the elements in the CTOR. It differs
8008 : : from the size of the vector type elements only when the
8009 : : CTOR elements are vectors themselves. */
8010 : 151179 : tree val_type = (CONSTRUCTOR_NELTS (exp) != 0
8011 : 151179 : ? TREE_TYPE (CONSTRUCTOR_ELT (exp, 0)->value)
8012 : 151179 : : elttype);
8013 : 151179 : if (VECTOR_TYPE_P (val_type))
8014 : 1370 : bitsize = tree_to_poly_uint64 (TYPE_SIZE (val_type));
8015 : : else
8016 : 149809 : bitsize = elt_size;
8017 : :
8018 : : /* If the constructor has fewer elements than the vector,
8019 : : clear the whole array first. Similarly if this is static
8020 : : constructor of a non-BLKmode object. */
8021 : 151179 : if (cleared)
8022 : : need_to_clear = false;
8023 : 151179 : else if (REG_P (target) && TREE_STATIC (exp))
8024 : : need_to_clear = true;
8025 : : else
8026 : : {
8027 : : poly_uint64 count = 0, zero_count = 0;
8028 : : tree value;
8029 : :
8030 : 569368 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
8031 : : {
8032 : 418189 : poly_int64 n_elts_here = exact_div (bitsize, elt_size);
8033 : 418189 : count += n_elts_here;
8034 : 418189 : if (mostly_zeros_p (value))
8035 : 418189 : zero_count += n_elts_here;
8036 : : }
8037 : :
8038 : : /* Clear the entire vector first if there are any missing elements,
8039 : : or if the incidence of zero elements is >= 75%. */
8040 : 151179 : need_to_clear = (maybe_lt (count, n_elts)
8041 : 151179 : || maybe_gt (4 * zero_count, 3 * count));
8042 : : }
8043 : :
8044 : 982 : if (need_to_clear && maybe_gt (size, 0) && !vector)
8045 : : {
8046 : 628 : if (REG_P (target))
8047 : 1 : emit_move_insn (target, CONST0_RTX (mode));
8048 : : else
8049 : 627 : clear_storage (target, gen_int_mode (size, Pmode),
8050 : : BLOCK_OP_NORMAL);
8051 : : cleared = 1;
8052 : : }
8053 : :
8054 : : /* Inform later passes that the old value is dead. */
8055 : 151179 : if (!cleared && !vector && REG_P (target) && maybe_gt (n_elts, 1u))
8056 : : {
8057 : 893 : emit_move_insn (target, CONST0_RTX (mode));
8058 : 893 : cleared = 1;
8059 : : }
8060 : :
8061 : 151179 : if (MEM_P (target))
8062 : 2825 : alias = MEM_ALIAS_SET (target);
8063 : : else
8064 : 148354 : alias = get_alias_set (elttype);
8065 : :
8066 : : /* Store each element of the constructor into the corresponding
8067 : : element of TARGET, determined by counting the elements. */
8068 : 151179 : HOST_WIDE_INT chunk_size = 0;
8069 : 151179 : bool chunk_multiple_p = constant_multiple_p (bitsize, elt_size,
8070 : : &chunk_size);
8071 : 151179 : gcc_assert (chunk_multiple_p || vec_vec_init_p);
8072 : :
8073 : 569368 : for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (exp), idx, &ce);
8074 : : idx++)
8075 : : {
8076 : 418189 : HOST_WIDE_INT eltpos;
8077 : 418189 : tree value = ce->value;
8078 : :
8079 : 418189 : if (cleared && initializer_zerop (value))
8080 : 6477 : continue;
8081 : :
8082 : 411712 : if (ce->index)
8083 : 42724 : eltpos = tree_to_uhwi (ce->index);
8084 : : else
8085 : 368988 : eltpos = idx * chunk_size;
8086 : :
8087 : 411712 : if (vector)
8088 : : {
8089 : 379241 : if (vec_vec_init_p)
8090 : : {
8091 : 2106 : gcc_assert (ce->index == NULL_TREE);
8092 : 2106 : gcc_assert (TREE_CODE (TREE_TYPE (value)) == VECTOR_TYPE);
8093 : 2106 : eltpos = idx;
8094 : : }
8095 : : else
8096 : 377135 : gcc_assert (TREE_CODE (TREE_TYPE (value)) != VECTOR_TYPE);
8097 : 379241 : RTVEC_ELT (vector, eltpos) = expand_normal (value);
8098 : : }
8099 : : else
8100 : : {
8101 : 32471 : machine_mode value_mode
8102 : 32471 : = (TREE_CODE (TREE_TYPE (value)) == VECTOR_TYPE
8103 : 32471 : ? TYPE_MODE (TREE_TYPE (value)) : eltmode);
8104 : 32471 : bitpos = eltpos * elt_size;
8105 : 32471 : store_constructor_field (target, bitsize, bitpos, 0,
8106 : : bitregion_end, value_mode,
8107 : : value, cleared, alias, reverse);
8108 : : }
8109 : : }
8110 : :
8111 : 151179 : if (vector)
8112 : 146811 : emit_insn (GEN_FCN (icode) (target,
8113 : : gen_rtx_PARALLEL (mode, vector)));
8114 : : break;
8115 : : }
8116 : :
8117 : 0 : default:
8118 : 0 : gcc_unreachable ();
8119 : : }
8120 : 281375 : }
8121 : :
8122 : : /* Store the value of EXP (an expression tree)
8123 : : into a subfield of TARGET which has mode MODE and occupies
8124 : : BITSIZE bits, starting BITPOS bits from the start of TARGET.
8125 : : If MODE is VOIDmode, it means that we are storing into a bit-field.
8126 : :
8127 : : BITREGION_START is bitpos of the first bitfield in this region.
8128 : : BITREGION_END is the bitpos of the ending bitfield in this region.
8129 : : These two fields are 0, if the C++ memory model does not apply,
8130 : : or we are not interested in keeping track of bitfield regions.
8131 : :
8132 : : Always return const0_rtx unless we have something particular to
8133 : : return.
8134 : :
8135 : : ALIAS_SET is the alias set for the destination. This value will
8136 : : (in general) be different from that for TARGET, since TARGET is a
8137 : : reference to the containing structure.
8138 : :
8139 : : If NONTEMPORAL is true, try generating a nontemporal store.
8140 : :
8141 : : If REVERSE is true, the store is to be done in reverse order. */
8142 : :
8143 : : static rtx
8144 : 4525173 : store_field (rtx target, poly_int64 bitsize, poly_int64 bitpos,
8145 : : poly_uint64 bitregion_start, poly_uint64 bitregion_end,
8146 : : machine_mode mode, tree exp,
8147 : : alias_set_type alias_set, bool nontemporal, bool reverse)
8148 : : {
8149 : 4525173 : if (TREE_CODE (exp) == ERROR_MARK)
8150 : 0 : return const0_rtx;
8151 : :
8152 : : /* If we have nothing to store, do nothing unless the expression has
8153 : : side-effects. Don't do that for zero sized addressable lhs of
8154 : : calls. */
8155 : 4525173 : if (known_eq (bitsize, 0)
8156 : 4525173 : && (!TREE_ADDRESSABLE (TREE_TYPE (exp))
8157 : 3 : || TREE_CODE (exp) != CALL_EXPR))
8158 : 0 : return expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL);
8159 : :
8160 : 4525173 : if (GET_CODE (target) == CONCAT)
8161 : : {
8162 : : /* We're storing into a struct containing a single __complex. */
8163 : :
8164 : 0 : gcc_assert (known_eq (bitpos, 0));
8165 : 0 : return store_expr (exp, target, 0, nontemporal, reverse);
8166 : : }
8167 : :
8168 : : /* If the structure is in a register or if the component
8169 : : is a bit field, we cannot use addressing to access it.
8170 : : Use bit-field techniques or SUBREG to store in it. */
8171 : :
8172 : 4525173 : poly_int64 decl_bitsize;
8173 : 4525173 : if (mode == VOIDmode
8174 : 4456975 : || (mode != BLKmode && ! direct_store[(int) mode]
8175 : 5443 : && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
8176 : 5441 : && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT)
8177 : 4451567 : || REG_P (target)
8178 : 3733308 : || GET_CODE (target) == SUBREG
8179 : : /* If the field isn't aligned enough to store as an ordinary memref,
8180 : : store it as a bit field. */
8181 : 3733308 : || (mode != BLKmode
8182 : 3617865 : && ((((MEM_ALIGN (target) < GET_MODE_ALIGNMENT (mode))
8183 : 7147728 : || !multiple_p (bitpos, GET_MODE_ALIGNMENT (mode)))
8184 : 46779 : && targetm.slow_unaligned_access (mode, MEM_ALIGN (target)))
8185 : 3617865 : || !multiple_p (bitpos, BITS_PER_UNIT)))
8186 : 3733308 : || (known_size_p (bitsize)
8187 : 3733296 : && mode != BLKmode
8188 : 3617865 : && maybe_gt (GET_MODE_BITSIZE (mode), bitsize))
8189 : : /* If the RHS and field are a constant size and the size of the
8190 : : RHS isn't the same size as the bitfield, we must use bitfield
8191 : : operations. */
8192 : 3733299 : || (known_size_p (bitsize)
8193 : 3733287 : && poly_int_tree_p (TYPE_SIZE (TREE_TYPE (exp)))
8194 : 3733287 : && maybe_ne (wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (exp))),
8195 : : bitsize)
8196 : : /* Except for initialization of full bytes from a CONSTRUCTOR, which
8197 : : we will handle specially below. */
8198 : 27 : && !(TREE_CODE (exp) == CONSTRUCTOR
8199 : 11 : && multiple_p (bitsize, BITS_PER_UNIT))
8200 : : /* And except for bitwise copying of TREE_ADDRESSABLE types,
8201 : : where the FIELD_DECL has the right bitsize, but TREE_TYPE (exp)
8202 : : includes some extra padding. store_expr / expand_expr will in
8203 : : that case call get_inner_reference that will have the bitsize
8204 : : we check here and thus the block move will not clobber the
8205 : : padding that shouldn't be clobbered. In the future we could
8206 : : replace the TREE_ADDRESSABLE check with a check that
8207 : : get_base_address needs to live in memory. */
8208 : 16 : && (!TREE_ADDRESSABLE (TREE_TYPE (exp))
8209 : 9 : || TREE_CODE (exp) != COMPONENT_REF
8210 : 6 : || !multiple_p (bitsize, BITS_PER_UNIT)
8211 : 6 : || !multiple_p (bitpos, BITS_PER_UNIT)
8212 : 6 : || !poly_int_tree_p (DECL_SIZE (TREE_OPERAND (exp, 1)),
8213 : : &decl_bitsize)
8214 : 6 : || maybe_ne (decl_bitsize, bitsize))
8215 : : /* A call with an addressable return type and return-slot
8216 : : optimization must not need bitfield operations but we must
8217 : : pass down the original target. */
8218 : 10 : && (TREE_CODE (exp) != CALL_EXPR
8219 : 6 : || !TREE_ADDRESSABLE (TREE_TYPE (exp))
8220 : 0 : || !CALL_EXPR_RETURN_SLOT_OPT (exp)))
8221 : : /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
8222 : : decl we must use bitfield operations. */
8223 : 8258462 : || (known_size_p (bitsize)
8224 : 3733277 : && TREE_CODE (exp) == MEM_REF
8225 : 29097 : && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
8226 : 23058 : && DECL_P (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
8227 : 18716 : && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
8228 : 5094 : && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) != BLKmode))
8229 : : {
8230 : 792077 : rtx temp;
8231 : 792077 : gimple *nop_def;
8232 : :
8233 : : /* If EXP is a NOP_EXPR of precision less than its mode, then that
8234 : : implies a mask operation. If the precision is the same size as
8235 : : the field we're storing into, that mask is redundant. This is
8236 : : particularly common with bit field assignments generated by the
8237 : : C front end. */
8238 : 792077 : nop_def = get_def_for_expr (exp, NOP_EXPR);
8239 : 792077 : if (nop_def)
8240 : : {
8241 : 7397 : tree type = TREE_TYPE (exp);
8242 : 7397 : if (INTEGRAL_TYPE_P (type)
8243 : 7153 : && maybe_ne (TYPE_PRECISION (type),
8244 : 14306 : GET_MODE_BITSIZE (TYPE_MODE (type)))
8245 : 11095 : && known_eq (bitsize, TYPE_PRECISION (type)))
8246 : : {
8247 : 3596 : tree op = gimple_assign_rhs1 (nop_def);
8248 : 3596 : type = TREE_TYPE (op);
8249 : 3596 : if (INTEGRAL_TYPE_P (type)
8250 : 3596 : && known_ge (TYPE_PRECISION (type), bitsize))
8251 : : exp = op;
8252 : : }
8253 : : }
8254 : :
8255 : 792077 : temp = expand_normal (exp);
8256 : :
8257 : : /* We don't support variable-sized BLKmode bitfields, since our
8258 : : handling of BLKmode is bound up with the ability to break
8259 : : things into words. */
8260 : 792077 : gcc_assert (mode != BLKmode || bitsize.is_constant ());
8261 : :
8262 : : /* Handle calls that return values in multiple non-contiguous locations.
8263 : : The Irix 6 ABI has examples of this. */
8264 : 792077 : if (GET_CODE (temp) == PARALLEL)
8265 : : {
8266 : 6 : HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
8267 : 6 : machine_mode temp_mode = GET_MODE (temp);
8268 : 6 : if (temp_mode == BLKmode || temp_mode == VOIDmode)
8269 : 6 : temp_mode
8270 : 6 : = smallest_int_mode_for_size (size * BITS_PER_UNIT).require ();
8271 : 6 : rtx temp_target = gen_reg_rtx (temp_mode);
8272 : 6 : emit_group_store (temp_target, temp, TREE_TYPE (exp), size);
8273 : 6 : temp = temp_target;
8274 : : }
8275 : :
8276 : : /* Handle calls that return BLKmode values in registers. */
8277 : 792071 : else if (mode == BLKmode && REG_P (temp) && TREE_CODE (exp) == CALL_EXPR)
8278 : : {
8279 : 0 : rtx temp_target = gen_reg_rtx (GET_MODE (temp));
8280 : 0 : copy_blkmode_from_reg (temp_target, temp, TREE_TYPE (exp));
8281 : 0 : temp = temp_target;
8282 : : }
8283 : :
8284 : : /* If the value has aggregate type and an integral mode then, if BITSIZE
8285 : : is narrower than this mode and this is for big-endian data, we first
8286 : : need to put the value into the low-order bits for store_bit_field,
8287 : : except when MODE is BLKmode and BITSIZE larger than the word size
8288 : : (see the handling of fields larger than a word in store_bit_field).
8289 : : Moreover, the field may be not aligned on a byte boundary; in this
8290 : : case, if it has reverse storage order, it needs to be accessed as a
8291 : : scalar field with reverse storage order and we must first put the
8292 : : value into target order. */
8293 : 792077 : scalar_int_mode temp_mode;
8294 : 1581922 : if (AGGREGATE_TYPE_P (TREE_TYPE (exp))
8295 : 793373 : && is_int_mode (GET_MODE (temp), &temp_mode))
8296 : : {
8297 : 3259 : HOST_WIDE_INT size = GET_MODE_BITSIZE (temp_mode);
8298 : :
8299 : 3259 : reverse = TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (exp));
8300 : :
8301 : 3259 : if (reverse)
8302 : 0 : temp = flip_storage_order (temp_mode, temp);
8303 : :
8304 : 3259 : gcc_checking_assert (known_le (bitsize, size));
8305 : 3259 : if (maybe_lt (bitsize, size)
8306 : 3259 : && reverse ? !BYTES_BIG_ENDIAN : BYTES_BIG_ENDIAN
8307 : : /* Use of to_constant for BLKmode was checked above. */
8308 : : && !(mode == BLKmode && bitsize.to_constant () > BITS_PER_WORD))
8309 : 0 : temp = expand_shift (RSHIFT_EXPR, temp_mode, temp,
8310 : : size - bitsize, NULL_RTX, 1);
8311 : : }
8312 : :
8313 : : /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
8314 : 723879 : if (mode != VOIDmode && mode != BLKmode
8315 : 1515698 : && mode != TYPE_MODE (TREE_TYPE (exp)))
8316 : 4 : temp = convert_modes (mode, TYPE_MODE (TREE_TYPE (exp)), temp, 1);
8317 : :
8318 : : /* If the mode of TEMP and TARGET is BLKmode, both must be in memory
8319 : : and BITPOS must be aligned on a byte boundary. If so, we simply do
8320 : : a block copy. Likewise for a BLKmode-like TARGET. */
8321 : 792077 : if (GET_MODE (temp) == BLKmode
8322 : 792077 : && (GET_MODE (target) == BLKmode
8323 : 176 : || (MEM_P (target)
8324 : 0 : && GET_MODE_CLASS (GET_MODE (target)) == MODE_INT
8325 : 0 : && multiple_p (bitpos, BITS_PER_UNIT)
8326 : 0 : && multiple_p (bitsize, BITS_PER_UNIT))))
8327 : : {
8328 : 76 : gcc_assert (MEM_P (target) && MEM_P (temp));
8329 : 76 : poly_int64 bytepos = exact_div (bitpos, BITS_PER_UNIT);
8330 : 76 : poly_int64 bytesize = bits_to_bytes_round_up (bitsize);
8331 : :
8332 : 76 : target = adjust_address (target, VOIDmode, bytepos);
8333 : 76 : emit_block_move (target, temp,
8334 : 76 : gen_int_mode (bytesize, Pmode),
8335 : : BLOCK_OP_NORMAL);
8336 : :
8337 : 76 : return const0_rtx;
8338 : : }
8339 : :
8340 : : /* If the mode of TEMP is still BLKmode and BITSIZE not larger than the
8341 : : word size, we need to load the value (see again store_bit_field). */
8342 : 792019 : if (GET_MODE (temp) == BLKmode && known_le (bitsize, BITS_PER_WORD))
8343 : : {
8344 : 61 : temp_mode = smallest_int_mode_for_size (bitsize).require ();
8345 : 61 : temp = extract_bit_field (temp, bitsize, 0, 1, NULL_RTX, temp_mode,
8346 : : temp_mode, false, NULL);
8347 : : }
8348 : :
8349 : : /* Store the value in the bitfield. */
8350 : 792001 : gcc_checking_assert (known_ge (bitpos, 0));
8351 : 792001 : store_bit_field (target, bitsize, bitpos,
8352 : : bitregion_start, bitregion_end,
8353 : : mode, temp, reverse, false);
8354 : :
8355 : 792001 : return const0_rtx;
8356 : : }
8357 : : else
8358 : : {
8359 : : /* Now build a reference to just the desired component. */
8360 : 3733096 : rtx to_rtx = adjust_address (target, mode,
8361 : : exact_div (bitpos, BITS_PER_UNIT));
8362 : :
8363 : 3733096 : if (to_rtx == target)
8364 : 1224544 : to_rtx = copy_rtx (to_rtx);
8365 : :
8366 : 7208132 : if (!MEM_KEEP_ALIAS_SET_P (to_rtx) && MEM_ALIAS_SET (to_rtx) != 0)
8367 : 3222638 : set_mem_alias_set (to_rtx, alias_set);
8368 : :
8369 : : /* Above we avoided using bitfield operations for storing a CONSTRUCTOR
8370 : : into a target smaller than its type; handle that case now. */
8371 : 3733096 : if (TREE_CODE (exp) == CONSTRUCTOR && known_size_p (bitsize))
8372 : : {
8373 : 70370 : poly_int64 bytesize = exact_div (bitsize, BITS_PER_UNIT);
8374 : 70370 : store_constructor (exp, to_rtx, 0, bytesize, reverse);
8375 : 70370 : return to_rtx;
8376 : : }
8377 : :
8378 : 3662726 : return store_expr (exp, to_rtx, 0, nontemporal, reverse);
8379 : : }
8380 : : }
8381 : :
8382 : : /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
8383 : : an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
8384 : : codes and find the ultimate containing object, which we return.
8385 : :
8386 : : We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
8387 : : bit position, *PUNSIGNEDP to the signedness and *PREVERSEP to the
8388 : : storage order of the field.
8389 : : If the position of the field is variable, we store a tree
8390 : : giving the variable offset (in units) in *POFFSET.
8391 : : This offset is in addition to the bit position.
8392 : : If the position is not variable, we store 0 in *POFFSET.
8393 : :
8394 : : If any of the extraction expressions is volatile,
8395 : : we store 1 in *PVOLATILEP. Otherwise we don't change that.
8396 : :
8397 : : If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
8398 : : Otherwise, it is a mode that can be used to access the field.
8399 : :
8400 : : If the field describes a variable-sized object, *PMODE is set to
8401 : : BLKmode and *PBITSIZE is set to -1. An access cannot be made in
8402 : : this case, but the address of the object can be found. */
8403 : :
8404 : : tree
8405 : 214200734 : get_inner_reference (tree exp, poly_int64 *pbitsize,
8406 : : poly_int64 *pbitpos, tree *poffset,
8407 : : machine_mode *pmode, int *punsignedp,
8408 : : int *preversep, int *pvolatilep)
8409 : : {
8410 : 214200734 : tree size_tree = 0;
8411 : 214200734 : machine_mode mode = VOIDmode;
8412 : 214200734 : bool blkmode_bitfield = false;
8413 : 214200734 : tree offset = size_zero_node;
8414 : 214200734 : poly_offset_int bit_offset = 0;
8415 : :
8416 : : /* First get the mode, signedness, storage order and size. We do this from
8417 : : just the outermost expression. */
8418 : 214200734 : *pbitsize = -1;
8419 : 214200734 : if (TREE_CODE (exp) == COMPONENT_REF)
8420 : : {
8421 : 82281980 : tree field = TREE_OPERAND (exp, 1);
8422 : 82281980 : size_tree = DECL_SIZE (field);
8423 : 82281980 : if (flag_strict_volatile_bitfields > 0
8424 : 58 : && TREE_THIS_VOLATILE (exp)
8425 : 40 : && DECL_BIT_FIELD_TYPE (field)
8426 : 82282002 : && DECL_MODE (field) != BLKmode)
8427 : : /* Volatile bitfields should be accessed in the mode of the
8428 : : field's type, not the mode computed based on the bit
8429 : : size. */
8430 : 22 : mode = TYPE_MODE (DECL_BIT_FIELD_TYPE (field));
8431 : 82281958 : else if (!DECL_BIT_FIELD (field))
8432 : : {
8433 : 80938337 : mode = DECL_MODE (field);
8434 : : /* For vector fields re-check the target flags, as DECL_MODE
8435 : : could have been set with different target flags than
8436 : : the current function has. */
8437 : 80938337 : if (VECTOR_TYPE_P (TREE_TYPE (field))
8438 : 80938337 : && VECTOR_MODE_P (TYPE_MODE_RAW (TREE_TYPE (field))))
8439 : 317065 : mode = TYPE_MODE (TREE_TYPE (field));
8440 : : }
8441 : 1343621 : else if (DECL_MODE (field) == BLKmode)
8442 : 148 : blkmode_bitfield = true;
8443 : :
8444 : 82281980 : *punsignedp = DECL_UNSIGNED (field);
8445 : : }
8446 : 131918754 : else if (TREE_CODE (exp) == BIT_FIELD_REF)
8447 : : {
8448 : 602640 : size_tree = TREE_OPERAND (exp, 1);
8449 : 1204893 : *punsignedp = (! INTEGRAL_TYPE_P (TREE_TYPE (exp))
8450 : 1041012 : || TYPE_UNSIGNED (TREE_TYPE (exp)));
8451 : :
8452 : : /* For vector element types with the correct size of access or for
8453 : : vector typed accesses use the mode of the access type. */
8454 : 602640 : if ((TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == VECTOR_TYPE
8455 : 415737 : && TREE_TYPE (exp) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)))
8456 : 376820 : && tree_int_cst_equal (size_tree, TYPE_SIZE (TREE_TYPE (exp))))
8457 : 641560 : || VECTOR_TYPE_P (TREE_TYPE (exp)))
8458 : 396873 : mode = TYPE_MODE (TREE_TYPE (exp));
8459 : : }
8460 : : else
8461 : : {
8462 : 131316114 : mode = TYPE_MODE (TREE_TYPE (exp));
8463 : 131316114 : *punsignedp = TYPE_UNSIGNED (TREE_TYPE (exp));
8464 : :
8465 : 131316114 : if (mode == BLKmode)
8466 : 53881076 : size_tree = TYPE_SIZE (TREE_TYPE (exp));
8467 : : else
8468 : 154870076 : *pbitsize = GET_MODE_BITSIZE (mode);
8469 : : }
8470 : :
8471 : 214200734 : if (size_tree != 0)
8472 : : {
8473 : 136102809 : if (!poly_int_tree_p (size_tree, pbitsize))
8474 : 340192 : mode = BLKmode, *pbitsize = -1;
8475 : : }
8476 : :
8477 : 214200734 : *preversep = reverse_storage_order_for_component_p (exp);
8478 : :
8479 : : /* Compute cumulative bit-offset for nested component-refs and array-refs,
8480 : : and find the ultimate containing object. */
8481 : 499327128 : while (1)
8482 : : {
8483 : 356763931 : switch (TREE_CODE (exp))
8484 : : {
8485 : 602640 : case BIT_FIELD_REF:
8486 : 602640 : bit_offset += wi::to_poly_offset (TREE_OPERAND (exp, 2));
8487 : 602640 : break;
8488 : :
8489 : 115133283 : case COMPONENT_REF:
8490 : 115133283 : {
8491 : 115133283 : tree field = TREE_OPERAND (exp, 1);
8492 : 115133283 : tree this_offset = component_ref_field_offset (exp);
8493 : :
8494 : : /* If this field hasn't been filled in yet, don't go past it.
8495 : : This should only happen when folding expressions made during
8496 : : type construction. */
8497 : 115133283 : if (this_offset == 0)
8498 : : break;
8499 : :
8500 : 115133283 : offset = size_binop (PLUS_EXPR, offset, this_offset);
8501 : 115133283 : bit_offset += wi::to_poly_offset (DECL_FIELD_BIT_OFFSET (field));
8502 : :
8503 : : /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
8504 : : }
8505 : 115133283 : break;
8506 : :
8507 : 24626448 : case ARRAY_REF:
8508 : 24626448 : case ARRAY_RANGE_REF:
8509 : 24626448 : {
8510 : 24626448 : tree index = TREE_OPERAND (exp, 1);
8511 : 24626448 : tree low_bound = array_ref_low_bound (exp);
8512 : 24626448 : tree unit_size = array_ref_element_size (exp);
8513 : :
8514 : : /* We assume all arrays have sizes that are a multiple of a byte.
8515 : : First subtract the lower bound, if any, in the type of the
8516 : : index, then convert to sizetype and multiply by the size of
8517 : : the array element. */
8518 : 24626448 : if (! integer_zerop (low_bound))
8519 : 766174 : index = fold_build2 (MINUS_EXPR, TREE_TYPE (index),
8520 : : index, low_bound);
8521 : :
8522 : 24626448 : offset = size_binop (PLUS_EXPR, offset,
8523 : : size_binop (MULT_EXPR,
8524 : : fold_convert (sizetype, index),
8525 : : unit_size));
8526 : : }
8527 : 24626448 : break;
8528 : :
8529 : : case REALPART_EXPR:
8530 : : break;
8531 : :
8532 : : case IMAGPART_EXPR:
8533 : 142563197 : bit_offset += *pbitsize;
8534 : : break;
8535 : :
8536 : : case VIEW_CONVERT_EXPR:
8537 : : break;
8538 : :
8539 : 82291115 : case MEM_REF:
8540 : : /* Hand back the decl for MEM[&decl, off]. */
8541 : 82291115 : if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR)
8542 : : {
8543 : 19276741 : tree off = TREE_OPERAND (exp, 1);
8544 : 19276741 : if (!integer_zerop (off))
8545 : : {
8546 : 10566774 : poly_offset_int boff = mem_ref_offset (exp);
8547 : 10566774 : boff <<= LOG2_BITS_PER_UNIT;
8548 : 10566774 : bit_offset += boff;
8549 : : }
8550 : 19276741 : exp = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
8551 : : }
8552 : 82291115 : goto done;
8553 : :
8554 : 131909619 : default:
8555 : 131909619 : goto done;
8556 : : }
8557 : :
8558 : : /* If any reference in the chain is volatile, the effect is volatile. */
8559 : 142563197 : if (TREE_THIS_VOLATILE (exp))
8560 : 448278 : *pvolatilep = 1;
8561 : :
8562 : 142563197 : exp = TREE_OPERAND (exp, 0);
8563 : 142563197 : }
8564 : 214200734 : done:
8565 : :
8566 : : /* If OFFSET is constant, see if we can return the whole thing as a
8567 : : constant bit position. Make sure to handle overflow during
8568 : : this conversion. */
8569 : 214200734 : if (poly_int_tree_p (offset))
8570 : : {
8571 : 203080740 : poly_offset_int tem = wi::sext (wi::to_poly_offset (offset),
8572 : 203080740 : TYPE_PRECISION (sizetype));
8573 : 203080740 : tem <<= LOG2_BITS_PER_UNIT;
8574 : 203080740 : tem += bit_offset;
8575 : 203080740 : if (tem.to_shwi (pbitpos))
8576 : 203079363 : *poffset = offset = NULL_TREE;
8577 : : }
8578 : :
8579 : : /* Otherwise, split it up. */
8580 : 203080740 : if (offset)
8581 : : {
8582 : : /* Avoid returning a negative bitpos as this may wreak havoc later. */
8583 : 11121371 : if (!bit_offset.to_shwi (pbitpos) || maybe_lt (*pbitpos, 0))
8584 : : {
8585 : 293 : *pbitpos = num_trailing_bits (bit_offset.force_shwi ());
8586 : 293 : poly_offset_int bytes = bits_to_bytes_round_down (bit_offset);
8587 : 293 : offset = size_binop (PLUS_EXPR, offset,
8588 : : build_int_cst (sizetype, bytes.force_shwi ()));
8589 : : }
8590 : :
8591 : 11121371 : *poffset = offset;
8592 : : }
8593 : :
8594 : : /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
8595 : 214200734 : if (mode == VOIDmode
8596 : 1764950 : && blkmode_bitfield
8597 : 148 : && multiple_p (*pbitpos, BITS_PER_UNIT)
8598 : 214200844 : && multiple_p (*pbitsize, BITS_PER_UNIT))
8599 : 0 : *pmode = BLKmode;
8600 : : else
8601 : 214200734 : *pmode = mode;
8602 : :
8603 : 214200734 : return exp;
8604 : : }
8605 : :
8606 : : /* Alignment in bits the TARGET of an assignment may be assumed to have. */
8607 : :
8608 : : static unsigned HOST_WIDE_INT
8609 : 486315 : target_align (const_tree target)
8610 : : {
8611 : : /* We might have a chain of nested references with intermediate misaligning
8612 : : bitfields components, so need to recurse to find out. */
8613 : :
8614 : 486315 : unsigned HOST_WIDE_INT this_align, outer_align;
8615 : :
8616 : 486315 : switch (TREE_CODE (target))
8617 : : {
8618 : : case BIT_FIELD_REF:
8619 : : return 1;
8620 : :
8621 : 129355 : case COMPONENT_REF:
8622 : 129355 : this_align = DECL_ALIGN (TREE_OPERAND (target, 1));
8623 : 129355 : outer_align = target_align (TREE_OPERAND (target, 0));
8624 : 129355 : return MIN (this_align, outer_align);
8625 : :
8626 : 181620 : case ARRAY_REF:
8627 : 181620 : case ARRAY_RANGE_REF:
8628 : 181620 : this_align = TYPE_ALIGN (TREE_TYPE (target));
8629 : 181620 : outer_align = target_align (TREE_OPERAND (target, 0));
8630 : 181620 : return MIN (this_align, outer_align);
8631 : :
8632 : 4218 : CASE_CONVERT:
8633 : 4218 : case NON_LVALUE_EXPR:
8634 : 4218 : case VIEW_CONVERT_EXPR:
8635 : 4218 : this_align = TYPE_ALIGN (TREE_TYPE (target));
8636 : 4218 : outer_align = target_align (TREE_OPERAND (target, 0));
8637 : 4218 : return MAX (this_align, outer_align);
8638 : :
8639 : 171118 : default:
8640 : 171118 : return TYPE_ALIGN (TREE_TYPE (target));
8641 : : }
8642 : : }
8643 : :
8644 : :
8645 : : /* Given an rtx VALUE that may contain additions and multiplications, return
8646 : : an equivalent value that just refers to a register, memory, or constant.
8647 : : This is done by generating instructions to perform the arithmetic and
8648 : : returning a pseudo-register containing the value.
8649 : :
8650 : : The returned value may be a REG, SUBREG, MEM or constant. */
8651 : :
8652 : : rtx
8653 : 30100549 : force_operand (rtx value, rtx target)
8654 : : {
8655 : 30100549 : rtx op1, op2;
8656 : : /* Use subtarget as the target for operand 0 of a binary operation. */
8657 : 30100549 : rtx subtarget = get_subtarget (target);
8658 : 30100549 : enum rtx_code code = GET_CODE (value);
8659 : :
8660 : : /* Check for subreg applied to an expression produced by loop optimizer. */
8661 : 30100549 : if (code == SUBREG
8662 : 272077 : && !REG_P (SUBREG_REG (value))
8663 : 123 : && !MEM_P (SUBREG_REG (value)))
8664 : : {
8665 : 123 : value
8666 : 123 : = simplify_gen_subreg (GET_MODE (value),
8667 : 123 : force_reg (GET_MODE (SUBREG_REG (value)),
8668 : : force_operand (SUBREG_REG (value),
8669 : : NULL_RTX)),
8670 : 123 : GET_MODE (SUBREG_REG (value)),
8671 : 123 : SUBREG_BYTE (value));
8672 : 123 : code = GET_CODE (value);
8673 : : }
8674 : :
8675 : : /* Check for a PIC address load. */
8676 : 30100549 : if ((code == PLUS || code == MINUS)
8677 : 3581950 : && XEXP (value, 0) == pic_offset_table_rtx
8678 : 1965 : && (GET_CODE (XEXP (value, 1)) == SYMBOL_REF
8679 : 1965 : || GET_CODE (XEXP (value, 1)) == LABEL_REF
8680 : 1965 : || GET_CODE (XEXP (value, 1)) == CONST))
8681 : : {
8682 : 221 : if (!subtarget)
8683 : 221 : subtarget = gen_reg_rtx (GET_MODE (value));
8684 : 221 : emit_move_insn (subtarget, value);
8685 : 221 : return subtarget;
8686 : : }
8687 : :
8688 : 30100328 : if (ARITHMETIC_P (value))
8689 : : {
8690 : 3691545 : op2 = XEXP (value, 1);
8691 : 3691545 : if (!CONSTANT_P (op2) && !(REG_P (op2) && op2 != subtarget))
8692 : 3691545 : subtarget = 0;
8693 : 3691545 : if (code == MINUS && CONST_INT_P (op2))
8694 : : {
8695 : 0 : code = PLUS;
8696 : 0 : op2 = negate_rtx (GET_MODE (value), op2);
8697 : : }
8698 : :
8699 : : /* Check for an addition with OP2 a constant integer and our first
8700 : : operand a PLUS of a virtual register and something else. In that
8701 : : case, we want to emit the sum of the virtual register and the
8702 : : constant first and then add the other value. This allows virtual
8703 : : register instantiation to simply modify the constant rather than
8704 : : creating another one around this addition. */
8705 : 3515332 : if (code == PLUS && CONST_INT_P (op2)
8706 : 3206552 : && GET_CODE (XEXP (value, 0)) == PLUS
8707 : 75380 : && REG_P (XEXP (XEXP (value, 0), 0))
8708 : 3717279 : && VIRTUAL_REGISTER_P (XEXP (XEXP (value, 0), 0)))
8709 : : {
8710 : 2068 : rtx temp = expand_simple_binop (GET_MODE (value), code,
8711 : : XEXP (XEXP (value, 0), 0), op2,
8712 : : subtarget, 0, OPTAB_LIB_WIDEN);
8713 : 2068 : return expand_simple_binop (GET_MODE (value), code, temp,
8714 : 2068 : force_operand (XEXP (XEXP (value,
8715 : : 0), 1), 0),
8716 : 2068 : target, 0, OPTAB_LIB_WIDEN);
8717 : : }
8718 : :
8719 : 3689477 : op1 = force_operand (XEXP (value, 0), subtarget);
8720 : 3689477 : op2 = force_operand (op2, NULL_RTX);
8721 : 3689477 : switch (code)
8722 : : {
8723 : 88157 : case MULT:
8724 : 88157 : return expand_mult (GET_MODE (value), op1, op2, target, 1);
8725 : 222 : case DIV:
8726 : 222 : if (!INTEGRAL_MODE_P (GET_MODE (value)))
8727 : 222 : return expand_simple_binop (GET_MODE (value), code, op1, op2,
8728 : 222 : target, 1, OPTAB_LIB_WIDEN);
8729 : : else
8730 : 0 : return expand_divmod (0,
8731 : : FLOAT_MODE_P (GET_MODE (value))
8732 : : ? RDIV_EXPR : TRUNC_DIV_EXPR,
8733 : 0 : GET_MODE (value), op1, op2, target, 0);
8734 : 0 : case MOD:
8735 : 0 : return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
8736 : 0 : target, 0);
8737 : 351 : case UDIV:
8738 : 351 : return expand_divmod (0, TRUNC_DIV_EXPR, GET_MODE (value), op1, op2,
8739 : 351 : target, 1);
8740 : 0 : case UMOD:
8741 : 0 : return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
8742 : 0 : target, 1);
8743 : 114 : case ASHIFTRT:
8744 : 114 : return expand_simple_binop (GET_MODE (value), code, op1, op2,
8745 : 114 : target, 0, OPTAB_LIB_WIDEN);
8746 : 3600633 : default:
8747 : 3600633 : return expand_simple_binop (GET_MODE (value), code, op1, op2,
8748 : 3600633 : target, 1, OPTAB_LIB_WIDEN);
8749 : : }
8750 : : }
8751 : 26408783 : if (UNARY_P (value))
8752 : : {
8753 : 16568 : if (!target)
8754 : 6464 : target = gen_reg_rtx (GET_MODE (value));
8755 : : /* FIX or UNSIGNED_FIX with integral mode has unspecified rounding,
8756 : : while FIX with floating point mode rounds toward zero. So, some
8757 : : targets use expressions like (fix:SI (fix:DF (reg:DF ...)))
8758 : : to express rounding toward zero during the conversion to int.
8759 : : expand_fix isn't able to handle that, it can only handle
8760 : : FIX/UNSIGNED_FIX from floating point mode to integral one. */
8761 : 16568 : if ((code == FIX || code == UNSIGNED_FIX)
8762 : 8 : && GET_CODE (XEXP (value, 0)) == FIX
8763 : 0 : && (GET_MODE (XEXP (value, 0))
8764 : 0 : == GET_MODE (XEXP (XEXP (value, 0), 0))))
8765 : 0 : op1 = force_operand (XEXP (XEXP (value, 0), 0), NULL_RTX);
8766 : : else
8767 : 16568 : op1 = force_operand (XEXP (value, 0), NULL_RTX);
8768 : 16568 : switch (code)
8769 : : {
8770 : 4975 : case ZERO_EXTEND:
8771 : 4975 : case SIGN_EXTEND:
8772 : 4975 : case TRUNCATE:
8773 : 4975 : case FLOAT_EXTEND:
8774 : 4975 : case FLOAT_TRUNCATE:
8775 : 4975 : convert_move (target, op1, code == ZERO_EXTEND);
8776 : 4975 : return target;
8777 : :
8778 : 8 : case FIX:
8779 : 8 : case UNSIGNED_FIX:
8780 : 8 : expand_fix (target, op1, code == UNSIGNED_FIX);
8781 : 8 : return target;
8782 : :
8783 : 168 : case FLOAT:
8784 : 168 : case UNSIGNED_FLOAT:
8785 : 168 : expand_float (target, op1, code == UNSIGNED_FLOAT);
8786 : 168 : return target;
8787 : :
8788 : 11417 : default:
8789 : 11417 : return expand_simple_unop (GET_MODE (value), code, op1, target, 0);
8790 : : }
8791 : : }
8792 : :
8793 : : #ifdef INSN_SCHEDULING
8794 : : /* On machines that have insn scheduling, we want all memory reference to be
8795 : : explicit, so we need to deal with such paradoxical SUBREGs. */
8796 : 26392215 : if (paradoxical_subreg_p (value) && MEM_P (SUBREG_REG (value)))
8797 : 0 : value
8798 : 0 : = simplify_gen_subreg (GET_MODE (value),
8799 : 0 : force_reg (GET_MODE (SUBREG_REG (value)),
8800 : : force_operand (SUBREG_REG (value),
8801 : : NULL_RTX)),
8802 : 0 : GET_MODE (SUBREG_REG (value)),
8803 : 0 : SUBREG_BYTE (value));
8804 : : #endif
8805 : :
8806 : : return value;
8807 : : }
8808 : :
8809 : : /* Subroutine of expand_expr: return true iff there is no way that
8810 : : EXP can reference X, which is being modified. TOP_P is nonzero if this
8811 : : call is going to be used to determine whether we need a temporary
8812 : : for EXP, as opposed to a recursive call to this function.
8813 : :
8814 : : It is always safe for this routine to return false since it merely
8815 : : searches for optimization opportunities. */
8816 : :
8817 : : bool
8818 : 8264482 : safe_from_p (const_rtx x, tree exp, int top_p)
8819 : : {
8820 : 8264498 : rtx exp_rtl = 0;
8821 : 8264498 : int i, nops;
8822 : :
8823 : 8264498 : if (x == 0
8824 : : /* If EXP has varying size, we MUST use a target since we currently
8825 : : have no way of allocating temporaries of variable size
8826 : : (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
8827 : : So we assume here that something at a higher level has prevented a
8828 : : clash. This is somewhat bogus, but the best we can do. Only
8829 : : do this when X is BLKmode and when we are at the top level. */
8830 : 1961111 : || (top_p && TREE_TYPE (exp) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp))
8831 : 1813386 : && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) != INTEGER_CST
8832 : 0 : && (TREE_CODE (TREE_TYPE (exp)) != ARRAY_TYPE
8833 : 0 : || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)) == NULL_TREE
8834 : 0 : || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)))
8835 : : != INTEGER_CST)
8836 : 0 : && GET_MODE (x) == BLKmode)
8837 : : /* If X is in the outgoing argument area, it is always safe. */
8838 : 10225609 : || (MEM_P (x)
8839 : 199852 : && (XEXP (x, 0) == virtual_outgoing_args_rtx
8840 : 199852 : || (GET_CODE (XEXP (x, 0)) == PLUS
8841 : 151375 : && XEXP (XEXP (x, 0), 0) == virtual_outgoing_args_rtx))))
8842 : : return true;
8843 : :
8844 : : /* If this is a subreg of a hard register, declare it unsafe, otherwise,
8845 : : find the underlying pseudo. */
8846 : 1961111 : if (GET_CODE (x) == SUBREG)
8847 : : {
8848 : 0 : x = SUBREG_REG (x);
8849 : 0 : if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
8850 : : return false;
8851 : : }
8852 : :
8853 : : /* Now look at our tree code and possibly recurse. */
8854 : 1961111 : switch (TREE_CODE_CLASS (TREE_CODE (exp)))
8855 : : {
8856 : 417 : case tcc_declaration:
8857 : 417 : exp_rtl = DECL_RTL_IF_SET (exp);
8858 : 247 : break;
8859 : :
8860 : : case tcc_constant:
8861 : : return true;
8862 : :
8863 : 878412 : case tcc_exceptional:
8864 : 878412 : if (TREE_CODE (exp) == TREE_LIST)
8865 : : {
8866 : 0 : while (1)
8867 : : {
8868 : 0 : if (TREE_VALUE (exp) && !safe_from_p (x, TREE_VALUE (exp), 0))
8869 : : return false;
8870 : 0 : exp = TREE_CHAIN (exp);
8871 : 0 : if (!exp)
8872 : : return true;
8873 : 0 : if (TREE_CODE (exp) != TREE_LIST)
8874 : : return safe_from_p (x, exp, 0);
8875 : : }
8876 : : }
8877 : 878412 : else if (TREE_CODE (exp) == CONSTRUCTOR)
8878 : : {
8879 : : constructor_elt *ce;
8880 : : unsigned HOST_WIDE_INT idx;
8881 : :
8882 : 7562567 : FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp), idx, ce)
8883 : 3910 : if ((ce->index != NULL_TREE && !safe_from_p (x, ce->index, 0))
8884 : 147552 : || !safe_from_p (x, ce->value, 0))
8885 : 121988 : return false;
8886 : : return true;
8887 : : }
8888 : 724654 : else if (TREE_CODE (exp) == ERROR_MARK)
8889 : : return true; /* An already-visited SAVE_EXPR? */
8890 : : else
8891 : : return false;
8892 : :
8893 : 0 : case tcc_statement:
8894 : : /* The only case we look at here is the DECL_INITIAL inside a
8895 : : DECL_EXPR. */
8896 : 0 : return (TREE_CODE (exp) != DECL_EXPR
8897 : 0 : || TREE_CODE (DECL_EXPR_DECL (exp)) != VAR_DECL
8898 : 0 : || !DECL_INITIAL (DECL_EXPR_DECL (exp))
8899 : 0 : || safe_from_p (x, DECL_INITIAL (DECL_EXPR_DECL (exp)), 0));
8900 : :
8901 : 0 : case tcc_binary:
8902 : 0 : case tcc_comparison:
8903 : 0 : if (!safe_from_p (x, TREE_OPERAND (exp, 1), 0))
8904 : : return false;
8905 : : /* Fall through. */
8906 : :
8907 : 16 : case tcc_unary:
8908 : 16 : return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
8909 : :
8910 : 264 : case tcc_expression:
8911 : 264 : case tcc_reference:
8912 : 264 : case tcc_vl_exp:
8913 : : /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
8914 : : the expression. If it is set, we conflict iff we are that rtx or
8915 : : both are in memory. Otherwise, we check all operands of the
8916 : : expression recursively. */
8917 : :
8918 : 264 : switch (TREE_CODE (exp))
8919 : : {
8920 : 241 : case ADDR_EXPR:
8921 : : /* If the operand is static or we are static, we can't conflict.
8922 : : Likewise if we don't conflict with the operand at all. */
8923 : 241 : if (staticp (TREE_OPERAND (exp, 0))
8924 : 111 : || TREE_STATIC (exp)
8925 : 352 : || safe_from_p (x, TREE_OPERAND (exp, 0), 0))
8926 : 241 : return true;
8927 : :
8928 : : /* Otherwise, the only way this can conflict is if we are taking
8929 : : the address of a DECL a that address if part of X, which is
8930 : : very rare. */
8931 : 0 : exp = TREE_OPERAND (exp, 0);
8932 : 0 : if (DECL_P (exp))
8933 : : {
8934 : 0 : if (!DECL_RTL_SET_P (exp)
8935 : 0 : || !MEM_P (DECL_RTL (exp)))
8936 : 0 : return false;
8937 : : else
8938 : 0 : exp_rtl = XEXP (DECL_RTL (exp), 0);
8939 : : }
8940 : : break;
8941 : :
8942 : 8 : case MEM_REF:
8943 : 8 : if (MEM_P (x)
8944 : 8 : && alias_sets_conflict_p (MEM_ALIAS_SET (x),
8945 : : get_alias_set (exp)))
8946 : : return false;
8947 : : break;
8948 : :
8949 : 0 : case CALL_EXPR:
8950 : : /* Assume that the call will clobber all hard registers and
8951 : : all of memory. */
8952 : 0 : if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
8953 : 0 : || MEM_P (x))
8954 : : return false;
8955 : : break;
8956 : :
8957 : 0 : case WITH_CLEANUP_EXPR:
8958 : 0 : case CLEANUP_POINT_EXPR:
8959 : : /* Lowered by gimplify.cc. */
8960 : 0 : gcc_unreachable ();
8961 : :
8962 : 0 : case SAVE_EXPR:
8963 : 0 : return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
8964 : :
8965 : : default:
8966 : : break;
8967 : : }
8968 : :
8969 : : /* If we have an rtx, we do not need to scan our operands. */
8970 : 0 : if (exp_rtl)
8971 : : break;
8972 : :
8973 : 23 : nops = TREE_OPERAND_LENGTH (exp);
8974 : 111 : for (i = 0; i < nops; i++)
8975 : 65 : if (TREE_OPERAND (exp, i) != 0
8976 : 65 : && ! safe_from_p (x, TREE_OPERAND (exp, i), 0))
8977 : : return false;
8978 : :
8979 : : break;
8980 : :
8981 : 0 : case tcc_type:
8982 : : /* Should never get a type here. */
8983 : 0 : gcc_unreachable ();
8984 : : }
8985 : :
8986 : : /* If we have an rtl, find any enclosed object. Then see if we conflict
8987 : : with it. */
8988 : 270 : if (exp_rtl)
8989 : : {
8990 : 247 : if (GET_CODE (exp_rtl) == SUBREG)
8991 : : {
8992 : 0 : exp_rtl = SUBREG_REG (exp_rtl);
8993 : 0 : if (REG_P (exp_rtl)
8994 : 0 : && REGNO (exp_rtl) < FIRST_PSEUDO_REGISTER)
8995 : : return false;
8996 : : }
8997 : :
8998 : : /* If the rtl is X, then it is not safe. Otherwise, it is unless both
8999 : : are memory and they conflict. */
9000 : 247 : return ! (rtx_equal_p (x, exp_rtl)
9001 : 247 : || (MEM_P (x) && MEM_P (exp_rtl)
9002 : 4 : && true_dependence (exp_rtl, VOIDmode, x)));
9003 : : }
9004 : :
9005 : : /* If we reach here, it is safe. */
9006 : : return true;
9007 : : }
9008 : :
9009 : :
9010 : : /* Return the highest power of two that EXP is known to be a multiple of.
9011 : : This is used in updating alignment of MEMs in array references. */
9012 : :
9013 : : unsigned HOST_WIDE_INT
9014 : 31630298 : highest_pow2_factor (const_tree exp)
9015 : : {
9016 : 31630298 : unsigned HOST_WIDE_INT ret;
9017 : 31630298 : int trailing_zeros = tree_ctz (exp);
9018 : 31630298 : if (trailing_zeros >= HOST_BITS_PER_WIDE_INT)
9019 : 43516369 : return BIGGEST_ALIGNMENT;
9020 : 9544071 : ret = HOST_WIDE_INT_1U << trailing_zeros;
9021 : 18638360 : if (ret > BIGGEST_ALIGNMENT)
9022 : 12735822 : return BIGGEST_ALIGNMENT;
9023 : : return ret;
9024 : : }
9025 : :
9026 : : /* Similar, except that the alignment requirements of TARGET are
9027 : : taken into account. Assume it is at least as aligned as its
9028 : : type, unless it is a COMPONENT_REF in which case the layout of
9029 : : the structure gives the alignment. */
9030 : :
9031 : : static unsigned HOST_WIDE_INT
9032 : 171122 : highest_pow2_factor_for_target (const_tree target, const_tree exp)
9033 : : {
9034 : 171122 : unsigned HOST_WIDE_INT talign = target_align (target) / BITS_PER_UNIT;
9035 : 171122 : unsigned HOST_WIDE_INT factor = highest_pow2_factor (exp);
9036 : :
9037 : 171122 : return MAX (factor, talign);
9038 : : }
9039 : :
9040 : : /* Convert the tree comparison code TCODE to the rtl one where the
9041 : : signedness is UNSIGNEDP. */
9042 : :
9043 : : static enum rtx_code
9044 : 13672 : convert_tree_comp_to_rtx (enum tree_code tcode, int unsignedp)
9045 : : {
9046 : 13672 : enum rtx_code code;
9047 : 13672 : switch (tcode)
9048 : : {
9049 : : case EQ_EXPR:
9050 : : code = EQ;
9051 : : break;
9052 : 767 : case NE_EXPR:
9053 : 767 : code = NE;
9054 : 767 : break;
9055 : 3203 : case LT_EXPR:
9056 : 3203 : code = unsignedp ? LTU : LT;
9057 : : break;
9058 : 1470 : case LE_EXPR:
9059 : 1470 : code = unsignedp ? LEU : LE;
9060 : : break;
9061 : 1890 : case GT_EXPR:
9062 : 1890 : code = unsignedp ? GTU : GT;
9063 : : break;
9064 : 3468 : case GE_EXPR:
9065 : 3468 : code = unsignedp ? GEU : GE;
9066 : : break;
9067 : 4 : case UNORDERED_EXPR:
9068 : 4 : code = UNORDERED;
9069 : 4 : break;
9070 : 0 : case ORDERED_EXPR:
9071 : 0 : code = ORDERED;
9072 : 0 : break;
9073 : 0 : case UNLT_EXPR:
9074 : 0 : code = UNLT;
9075 : 0 : break;
9076 : 0 : case UNLE_EXPR:
9077 : 0 : code = UNLE;
9078 : 0 : break;
9079 : 0 : case UNGT_EXPR:
9080 : 0 : code = UNGT;
9081 : 0 : break;
9082 : 0 : case UNGE_EXPR:
9083 : 0 : code = UNGE;
9084 : 0 : break;
9085 : 0 : case UNEQ_EXPR:
9086 : 0 : code = UNEQ;
9087 : 0 : break;
9088 : 0 : case LTGT_EXPR:
9089 : 0 : code = LTGT;
9090 : 0 : break;
9091 : :
9092 : 0 : default:
9093 : 0 : gcc_unreachable ();
9094 : : }
9095 : 13672 : return code;
9096 : : }
9097 : :
9098 : : /* Subroutine of expand_expr. Expand the two operands of a binary
9099 : : expression EXP0 and EXP1 placing the results in OP0 and OP1.
9100 : : The value may be stored in TARGET if TARGET is nonzero. The
9101 : : MODIFIER argument is as documented by expand_expr. */
9102 : :
9103 : : void
9104 : 7664309 : expand_operands (tree exp0, tree exp1, rtx target, rtx *op0, rtx *op1,
9105 : : enum expand_modifier modifier)
9106 : : {
9107 : 7664309 : if (! safe_from_p (target, exp1, 1))
9108 : 586080 : target = 0;
9109 : 7664309 : if (operand_equal_p (exp0, exp1, 0))
9110 : : {
9111 : 43207 : *op0 = expand_expr (exp0, target, VOIDmode, modifier);
9112 : 43207 : *op1 = copy_rtx (*op0);
9113 : : }
9114 : : else
9115 : : {
9116 : 7621102 : *op0 = expand_expr (exp0, target, VOIDmode, modifier);
9117 : 7621102 : *op1 = expand_expr (exp1, NULL_RTX, VOIDmode, modifier);
9118 : : }
9119 : 7664309 : }
9120 : :
9121 : :
9122 : : /* Return a MEM that contains constant EXP. DEFER is as for
9123 : : output_constant_def and MODIFIER is as for expand_expr. */
9124 : :
9125 : : static rtx
9126 : 2825286 : expand_expr_constant (tree exp, int defer, enum expand_modifier modifier)
9127 : : {
9128 : 2825286 : rtx mem;
9129 : :
9130 : 2825286 : mem = output_constant_def (exp, defer);
9131 : 2825286 : if (modifier != EXPAND_INITIALIZER)
9132 : 1809650 : mem = use_anchored_address (mem);
9133 : 2825286 : return mem;
9134 : : }
9135 : :
9136 : : /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
9137 : : The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
9138 : :
9139 : : static rtx
9140 : 14140503 : expand_expr_addr_expr_1 (tree exp, rtx target, scalar_int_mode tmode,
9141 : : enum expand_modifier modifier, addr_space_t as)
9142 : : {
9143 : 14140503 : rtx result, subtarget;
9144 : 14140503 : tree inner, offset;
9145 : 14140503 : poly_int64 bitsize, bitpos;
9146 : 14140503 : int unsignedp, reversep, volatilep = 0;
9147 : 14140503 : machine_mode mode1;
9148 : :
9149 : : /* If we are taking the address of a constant and are at the top level,
9150 : : we have to use output_constant_def since we can't call force_const_mem
9151 : : at top level. */
9152 : : /* ??? This should be considered a front-end bug. We should not be
9153 : : generating ADDR_EXPR of something that isn't an LVALUE. The only
9154 : : exception here is STRING_CST. */
9155 : 14140503 : if (CONSTANT_CLASS_P (exp))
9156 : : {
9157 : 2607128 : result = XEXP (expand_expr_constant (exp, 0, modifier), 0);
9158 : 2607128 : if (modifier < EXPAND_SUM)
9159 : 1720896 : result = force_operand (result, target);
9160 : 2607128 : return result;
9161 : : }
9162 : :
9163 : : /* Everything must be something allowed by is_gimple_addressable. */
9164 : 11533375 : switch (TREE_CODE (exp))
9165 : : {
9166 : 36 : case INDIRECT_REF:
9167 : : /* This case will happen via recursion for &a->b. */
9168 : 36 : return expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
9169 : :
9170 : 566200 : case MEM_REF:
9171 : 566200 : {
9172 : 566200 : tree tem = TREE_OPERAND (exp, 0);
9173 : 566200 : if (!integer_zerop (TREE_OPERAND (exp, 1)))
9174 : 303176 : tem = fold_build_pointer_plus (tem, TREE_OPERAND (exp, 1));
9175 : 566200 : return expand_expr (tem, target, tmode, modifier);
9176 : : }
9177 : :
9178 : 1223 : case TARGET_MEM_REF:
9179 : 1223 : return addr_for_mem_ref (exp, as, true);
9180 : :
9181 : 57932 : case CONST_DECL:
9182 : : /* Expand the initializer like constants above. */
9183 : 57932 : result = XEXP (expand_expr_constant (DECL_INITIAL (exp),
9184 : : 0, modifier), 0);
9185 : 57932 : if (modifier < EXPAND_SUM)
9186 : 57926 : result = force_operand (result, target);
9187 : : return result;
9188 : :
9189 : 140 : case REALPART_EXPR:
9190 : : /* The real part of the complex number is always first, therefore
9191 : : the address is the same as the address of the parent object. */
9192 : 140 : offset = 0;
9193 : 140 : bitpos = 0;
9194 : 140 : inner = TREE_OPERAND (exp, 0);
9195 : 140 : break;
9196 : :
9197 : 84 : case IMAGPART_EXPR:
9198 : : /* The imaginary part of the complex number is always second.
9199 : : The expression is therefore always offset by the size of the
9200 : : scalar type. */
9201 : 84 : offset = 0;
9202 : 168 : bitpos = GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (exp)));
9203 : 84 : inner = TREE_OPERAND (exp, 0);
9204 : 84 : break;
9205 : :
9206 : 13 : case COMPOUND_LITERAL_EXPR:
9207 : : /* Allow COMPOUND_LITERAL_EXPR in initializers or coming from
9208 : : initializers, if e.g. rtl_for_decl_init is called on DECL_INITIAL
9209 : : with COMPOUND_LITERAL_EXPRs in it, or ARRAY_REF on a const static
9210 : : array with address of COMPOUND_LITERAL_EXPR in DECL_INITIAL;
9211 : : the initializers aren't gimplified. */
9212 : 13 : if (COMPOUND_LITERAL_EXPR_DECL (exp)
9213 : 13 : && is_global_var (COMPOUND_LITERAL_EXPR_DECL (exp)))
9214 : 13 : return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp),
9215 : 13 : target, tmode, modifier, as);
9216 : : /* FALLTHRU */
9217 : 10907747 : default:
9218 : : /* If the object is a DECL, then expand it for its rtl. Don't bypass
9219 : : expand_expr, as that can have various side effects; LABEL_DECLs for
9220 : : example, may not have their DECL_RTL set yet. Expand the rtl of
9221 : : CONSTRUCTORs too, which should yield a memory reference for the
9222 : : constructor's contents. Assume language specific tree nodes can
9223 : : be expanded in some interesting way. */
9224 : 10907747 : gcc_assert (TREE_CODE (exp) < LAST_AND_UNUSED_TREE_CODE);
9225 : 10907747 : if (DECL_P (exp)
9226 : 1275834 : || TREE_CODE (exp) == CONSTRUCTOR
9227 : 1275834 : || TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
9228 : : {
9229 : 15774406 : result = expand_expr (exp, target, tmode,
9230 : : modifier == EXPAND_INITIALIZER
9231 : : ? EXPAND_INITIALIZER : EXPAND_CONST_ADDRESS);
9232 : :
9233 : : /* If the DECL isn't in memory, then the DECL wasn't properly
9234 : : marked TREE_ADDRESSABLE, which will be either a front-end
9235 : : or a tree optimizer bug. */
9236 : :
9237 : 9631913 : gcc_assert (MEM_P (result));
9238 : 9631913 : result = XEXP (result, 0);
9239 : :
9240 : : /* ??? Is this needed anymore? */
9241 : 9631913 : if (DECL_P (exp))
9242 : 9631913 : TREE_USED (exp) = 1;
9243 : :
9244 : 9631913 : if (modifier != EXPAND_INITIALIZER
9245 : : && modifier != EXPAND_CONST_ADDRESS
9246 : 9631913 : && modifier != EXPAND_SUM)
9247 : 4173712 : result = force_operand (result, target);
9248 : 9631913 : return result;
9249 : : }
9250 : :
9251 : : /* Pass FALSE as the last argument to get_inner_reference although
9252 : : we are expanding to RTL. The rationale is that we know how to
9253 : : handle "aligning nodes" here: we can just bypass them because
9254 : : they won't change the final object whose address will be returned
9255 : : (they actually exist only for that purpose). */
9256 : 1275834 : inner = get_inner_reference (exp, &bitsize, &bitpos, &offset, &mode1,
9257 : : &unsignedp, &reversep, &volatilep);
9258 : 1275834 : break;
9259 : : }
9260 : :
9261 : : /* We must have made progress. */
9262 : 1276058 : gcc_assert (inner != exp);
9263 : :
9264 : 1276058 : subtarget = offset || maybe_ne (bitpos, 0) ? NULL_RTX : target;
9265 : : /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
9266 : : inner alignment, force the inner to be sufficiently aligned. */
9267 : 1276058 : if (CONSTANT_CLASS_P (inner)
9268 : 1276058 : && TYPE_ALIGN (TREE_TYPE (inner)) < TYPE_ALIGN (TREE_TYPE (exp)))
9269 : : {
9270 : 0 : inner = copy_node (inner);
9271 : 0 : TREE_TYPE (inner) = copy_node (TREE_TYPE (inner));
9272 : 0 : SET_TYPE_ALIGN (TREE_TYPE (inner), TYPE_ALIGN (TREE_TYPE (exp)));
9273 : 0 : TYPE_USER_ALIGN (TREE_TYPE (inner)) = 1;
9274 : : }
9275 : 1276058 : result = expand_expr_addr_expr_1 (inner, subtarget, tmode, modifier, as);
9276 : :
9277 : 1276058 : if (offset)
9278 : : {
9279 : 44547 : rtx tmp;
9280 : :
9281 : 44547 : if (modifier != EXPAND_NORMAL)
9282 : 907 : result = force_operand (result, NULL);
9283 : 45454 : tmp = expand_expr (offset, NULL_RTX, tmode,
9284 : : modifier == EXPAND_INITIALIZER
9285 : : ? EXPAND_INITIALIZER : EXPAND_NORMAL);
9286 : :
9287 : : /* expand_expr is allowed to return an object in a mode other
9288 : : than TMODE. If it did, we need to convert. */
9289 : 44547 : if (GET_MODE (tmp) != VOIDmode && tmode != GET_MODE (tmp))
9290 : 0 : tmp = convert_modes (tmode, GET_MODE (tmp),
9291 : 0 : tmp, TYPE_UNSIGNED (TREE_TYPE (offset)));
9292 : 44547 : result = convert_memory_address_addr_space (tmode, result, as);
9293 : 44547 : tmp = convert_memory_address_addr_space (tmode, tmp, as);
9294 : :
9295 : 44547 : if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
9296 : 907 : result = simplify_gen_binary (PLUS, tmode, result, tmp);
9297 : : else
9298 : : {
9299 : 43640 : subtarget = maybe_ne (bitpos, 0) ? NULL_RTX : target;
9300 : 43640 : result = expand_simple_binop (tmode, PLUS, result, tmp, subtarget,
9301 : : 1, OPTAB_LIB_WIDEN);
9302 : : }
9303 : : }
9304 : :
9305 : 1276058 : if (maybe_ne (bitpos, 0))
9306 : : {
9307 : : /* Someone beforehand should have rejected taking the address
9308 : : of an object that isn't byte-aligned. */
9309 : 625750 : poly_int64 bytepos = exact_div (bitpos, BITS_PER_UNIT);
9310 : 625750 : result = convert_memory_address_addr_space (tmode, result, as);
9311 : 625750 : result = plus_constant (tmode, result, bytepos);
9312 : 625750 : if (modifier < EXPAND_SUM)
9313 : 591786 : result = force_operand (result, target);
9314 : : }
9315 : :
9316 : : return result;
9317 : : }
9318 : :
9319 : : /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
9320 : : The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
9321 : :
9322 : : static rtx
9323 : 12864430 : expand_expr_addr_expr (tree exp, rtx target, machine_mode tmode,
9324 : : enum expand_modifier modifier)
9325 : : {
9326 : 12864430 : addr_space_t as = ADDR_SPACE_GENERIC;
9327 : 12864430 : scalar_int_mode address_mode = Pmode;
9328 : 12864430 : scalar_int_mode pointer_mode = ptr_mode;
9329 : 12864430 : machine_mode rmode;
9330 : 12864430 : rtx result;
9331 : :
9332 : : /* Target mode of VOIDmode says "whatever's natural". */
9333 : 12864430 : if (tmode == VOIDmode)
9334 : 10987335 : tmode = TYPE_MODE (TREE_TYPE (exp));
9335 : :
9336 : 12864430 : if (POINTER_TYPE_P (TREE_TYPE (exp)))
9337 : : {
9338 : 12864430 : as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)));
9339 : 12864430 : address_mode = targetm.addr_space.address_mode (as);
9340 : 12864430 : pointer_mode = targetm.addr_space.pointer_mode (as);
9341 : : }
9342 : :
9343 : : /* We can get called with some Weird Things if the user does silliness
9344 : : like "(short) &a". In that case, convert_memory_address won't do
9345 : : the right thing, so ignore the given target mode. */
9346 : 12864430 : scalar_int_mode new_tmode = (tmode == pointer_mode
9347 : 12864430 : ? pointer_mode
9348 : 12864430 : : address_mode);
9349 : :
9350 : 12864430 : result = expand_expr_addr_expr_1 (TREE_OPERAND (exp, 0), target,
9351 : : new_tmode, modifier, as);
9352 : :
9353 : : /* Despite expand_expr claims concerning ignoring TMODE when not
9354 : : strictly convenient, stuff breaks if we don't honor it. Note
9355 : : that combined with the above, we only do this for pointer modes. */
9356 : 12864430 : rmode = GET_MODE (result);
9357 : 12864430 : if (rmode == VOIDmode)
9358 : 6 : rmode = new_tmode;
9359 : 12864430 : if (rmode != new_tmode)
9360 : 74 : result = convert_memory_address_addr_space (new_tmode, result, as);
9361 : :
9362 : 12864430 : return result;
9363 : : }
9364 : :
9365 : : /* Generate code for computing CONSTRUCTOR EXP.
9366 : : An rtx for the computed value is returned. If AVOID_TEMP_MEM
9367 : : is TRUE, instead of creating a temporary variable in memory
9368 : : NULL is returned and the caller needs to handle it differently. */
9369 : :
9370 : : static rtx
9371 : 213807 : expand_constructor (tree exp, rtx target, enum expand_modifier modifier,
9372 : : bool avoid_temp_mem)
9373 : : {
9374 : 213807 : tree type = TREE_TYPE (exp);
9375 : 213807 : machine_mode mode = TYPE_MODE (type);
9376 : :
9377 : : /* Try to avoid creating a temporary at all. This is possible
9378 : : if all of the initializer is zero.
9379 : : FIXME: try to handle all [0..255] initializers we can handle
9380 : : with memset. */
9381 : 213807 : if (TREE_STATIC (exp)
9382 : 213807 : && !TREE_ADDRESSABLE (exp)
9383 : 3803 : && target != 0 && mode == BLKmode
9384 : 216674 : && all_zeros_p (exp))
9385 : : {
9386 : 2862 : clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
9387 : 2862 : return target;
9388 : : }
9389 : :
9390 : : /* All elts simple constants => refer to a constant in memory. But
9391 : : if this is a non-BLKmode mode, let it store a field at a time
9392 : : since that should make a CONST_INT, CONST_WIDE_INT or
9393 : : CONST_DOUBLE when we fold. Likewise, if we have a target we can
9394 : : use, it is best to store directly into the target unless the type
9395 : : is large enough that memcpy will be used. If we are making an
9396 : : initializer and all operands are constant, put it in memory as
9397 : : well.
9398 : :
9399 : : FIXME: Avoid trying to fill vector constructors piece-meal.
9400 : : Output them with output_constant_def below unless we're sure
9401 : : they're zeros. This should go away when vector initializers
9402 : : are treated like VECTOR_CST instead of arrays. */
9403 : 210945 : if ((TREE_STATIC (exp)
9404 : 941 : && ((mode == BLKmode
9405 : 50 : && ! (target != 0 && safe_from_p (target, exp, 1)))
9406 : 896 : || TREE_ADDRESSABLE (exp)
9407 : 896 : || (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type))
9408 : 896 : && (! can_move_by_pieces
9409 : 896 : (tree_to_uhwi (TYPE_SIZE_UNIT (type)),
9410 : 896 : TYPE_ALIGN (type)))
9411 : 2 : && ! mostly_zeros_p (exp))))
9412 : 211839 : || ((modifier == EXPAND_INITIALIZER || modifier == EXPAND_CONST_ADDRESS)
9413 : 0 : && TREE_CONSTANT (exp)))
9414 : : {
9415 : 47 : rtx constructor;
9416 : :
9417 : 47 : if (avoid_temp_mem)
9418 : : return NULL_RTX;
9419 : :
9420 : 45 : constructor = expand_expr_constant (exp, 1, modifier);
9421 : :
9422 : 45 : if (modifier != EXPAND_CONST_ADDRESS
9423 : : && modifier != EXPAND_INITIALIZER
9424 : 45 : && modifier != EXPAND_SUM)
9425 : 45 : constructor = validize_mem (constructor);
9426 : :
9427 : 45 : return constructor;
9428 : : }
9429 : :
9430 : : /* If the CTOR is available in static storage and not mostly
9431 : : zeros and we can move it by pieces prefer to do so since
9432 : : that's usually more efficient than performing a series of
9433 : : stores from immediates. */
9434 : 210898 : if (avoid_temp_mem
9435 : 64 : && TREE_STATIC (exp)
9436 : 36 : && TREE_CONSTANT (exp)
9437 : 36 : && tree_fits_uhwi_p (TYPE_SIZE_UNIT (type))
9438 : 36 : && can_move_by_pieces (tree_to_uhwi (TYPE_SIZE_UNIT (type)),
9439 : 36 : TYPE_ALIGN (type))
9440 : 210934 : && ! mostly_zeros_p (exp))
9441 : : return NULL_RTX;
9442 : :
9443 : : /* Handle calls that pass values in multiple non-contiguous
9444 : : locations. The Irix 6 ABI has examples of this. */
9445 : 153735 : if (target == 0 || ! safe_from_p (target, exp, 1)
9446 : 31747 : || GET_CODE (target) == PARALLEL || modifier == EXPAND_STACK_PARM
9447 : : /* Also make a temporary if the store is to volatile memory, to
9448 : : avoid individual accesses to aggregate members. */
9449 : 242603 : || (GET_CODE (target) == MEM
9450 : 28317 : && MEM_VOLATILE_P (target)
9451 : 132 : && !TREE_ADDRESSABLE (TREE_TYPE (exp))))
9452 : : {
9453 : 179259 : if (avoid_temp_mem)
9454 : : return NULL_RTX;
9455 : :
9456 : 179248 : target = assign_temp (type, TREE_ADDRESSABLE (exp), 1);
9457 : : }
9458 : :
9459 : 210857 : store_constructor (exp, target, 0, int_expr_size (exp), false);
9460 : 210857 : return target;
9461 : : }
9462 : :
9463 : :
9464 : : /* expand_expr: generate code for computing expression EXP.
9465 : : An rtx for the computed value is returned. The value is never null.
9466 : : In the case of a void EXP, const0_rtx is returned.
9467 : :
9468 : : The value may be stored in TARGET if TARGET is nonzero.
9469 : : TARGET is just a suggestion; callers must assume that
9470 : : the rtx returned may not be the same as TARGET.
9471 : :
9472 : : If TARGET is CONST0_RTX, it means that the value will be ignored.
9473 : :
9474 : : If TMODE is not VOIDmode, it suggests generating the
9475 : : result in mode TMODE. But this is done only when convenient.
9476 : : Otherwise, TMODE is ignored and the value generated in its natural mode.
9477 : : TMODE is just a suggestion; callers must assume that
9478 : : the rtx returned may not have mode TMODE.
9479 : :
9480 : : Note that TARGET may have neither TMODE nor MODE. In that case, it
9481 : : probably will not be used.
9482 : :
9483 : : If MODIFIER is EXPAND_SUM then when EXP is an addition
9484 : : we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
9485 : : or a nest of (PLUS ...) and (MINUS ...) where the terms are
9486 : : products as above, or REG or MEM, or constant.
9487 : : Ordinarily in such cases we would output mul or add instructions
9488 : : and then return a pseudo reg containing the sum.
9489 : :
9490 : : EXPAND_INITIALIZER is much like EXPAND_SUM except that
9491 : : it also marks a label as absolutely required (it can't be dead).
9492 : : It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
9493 : : This is used for outputting expressions used in initializers.
9494 : :
9495 : : EXPAND_CONST_ADDRESS says that it is okay to return a MEM
9496 : : with a constant address even if that address is not normally legitimate.
9497 : : EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
9498 : :
9499 : : EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
9500 : : a call parameter. Such targets require special care as we haven't yet
9501 : : marked TARGET so that it's safe from being trashed by libcalls. We
9502 : : don't want to use TARGET for anything but the final result;
9503 : : Intermediate values must go elsewhere. Additionally, calls to
9504 : : emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
9505 : :
9506 : : If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
9507 : : address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
9508 : : DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
9509 : : COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
9510 : : recursively.
9511 : : If the result can be stored at TARGET, and ALT_RTL is non-NULL,
9512 : : then *ALT_RTL is set to TARGET (before legitimziation).
9513 : :
9514 : : If INNER_REFERENCE_P is true, we are expanding an inner reference.
9515 : : In this case, we don't adjust a returned MEM rtx that wouldn't be
9516 : : sufficiently aligned for its mode; instead, it's up to the caller
9517 : : to deal with it afterwards. This is used to make sure that unaligned
9518 : : base objects for which out-of-bounds accesses are supported, for
9519 : : example record types with trailing arrays, aren't realigned behind
9520 : : the back of the caller.
9521 : : The normal operating mode is to pass FALSE for this parameter. */
9522 : :
9523 : : rtx
9524 : 151841498 : expand_expr_real (tree exp, rtx target, machine_mode tmode,
9525 : : enum expand_modifier modifier, rtx *alt_rtl,
9526 : : bool inner_reference_p)
9527 : : {
9528 : 151841498 : rtx ret;
9529 : :
9530 : : /* Handle ERROR_MARK before anybody tries to access its type. */
9531 : 151841498 : if (TREE_CODE (exp) == ERROR_MARK
9532 : 151841498 : || (TREE_CODE (TREE_TYPE (exp)) == ERROR_MARK))
9533 : : {
9534 : 0 : ret = CONST0_RTX (tmode);
9535 : 0 : return ret ? ret : const0_rtx;
9536 : : }
9537 : :
9538 : 151841498 : ret = expand_expr_real_1 (exp, target, tmode, modifier, alt_rtl,
9539 : : inner_reference_p);
9540 : 151841498 : return ret;
9541 : : }
9542 : :
9543 : : /* Try to expand the conditional expression which is represented by
9544 : : TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If it succeeds
9545 : : return the rtl reg which represents the result. Otherwise return
9546 : : NULL_RTX. */
9547 : :
9548 : : static rtx
9549 : 17054 : expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED,
9550 : : tree treeop1 ATTRIBUTE_UNUSED,
9551 : : tree treeop2 ATTRIBUTE_UNUSED)
9552 : : {
9553 : 17054 : rtx insn;
9554 : 17054 : rtx op00, op01, op1, op2;
9555 : 17054 : enum rtx_code comparison_code;
9556 : 17054 : machine_mode comparison_mode;
9557 : 17054 : gimple *srcstmt;
9558 : 17054 : rtx temp;
9559 : 17054 : tree type = TREE_TYPE (treeop1);
9560 : 17054 : int unsignedp = TYPE_UNSIGNED (type);
9561 : 17054 : machine_mode mode = TYPE_MODE (type);
9562 : 17054 : machine_mode orig_mode = mode;
9563 : 17054 : static bool expanding_cond_expr_using_cmove = false;
9564 : :
9565 : : /* Conditional move expansion can end up TERing two operands which,
9566 : : when recursively hitting conditional expressions can result in
9567 : : exponential behavior if the cmove expansion ultimatively fails.
9568 : : It's hardly profitable to TER a cmove into a cmove so avoid doing
9569 : : that by failing early if we end up recursing. */
9570 : 17054 : if (expanding_cond_expr_using_cmove)
9571 : : return NULL_RTX;
9572 : :
9573 : : /* If we cannot do a conditional move on the mode, try doing it
9574 : : with the promoted mode. */
9575 : 16098 : if (!can_conditionally_move_p (mode))
9576 : : {
9577 : 145 : mode = promote_mode (type, mode, &unsignedp);
9578 : 145 : if (!can_conditionally_move_p (mode))
9579 : : return NULL_RTX;
9580 : 0 : temp = assign_temp (type, 0, 0); /* Use promoted mode for temp. */
9581 : : }
9582 : : else
9583 : 15953 : temp = assign_temp (type, 0, 1);
9584 : :
9585 : 15953 : expanding_cond_expr_using_cmove = true;
9586 : 15953 : start_sequence ();
9587 : 15953 : expand_operands (treeop1, treeop2,
9588 : : mode == orig_mode ? temp : NULL_RTX, &op1, &op2,
9589 : : EXPAND_NORMAL);
9590 : :
9591 : 15953 : if (TREE_CODE (treeop0) == SSA_NAME
9592 : 15910 : && (srcstmt = get_def_for_expr_class (treeop0, tcc_comparison))
9593 : 29585 : && !VECTOR_TYPE_P (TREE_TYPE (gimple_assign_rhs1 (srcstmt))))
9594 : : {
9595 : 13629 : type = TREE_TYPE (gimple_assign_rhs1 (srcstmt));
9596 : 13629 : enum tree_code cmpcode = gimple_assign_rhs_code (srcstmt);
9597 : 13629 : op00 = expand_normal (gimple_assign_rhs1 (srcstmt));
9598 : 13629 : op01 = expand_normal (gimple_assign_rhs2 (srcstmt));
9599 : 13629 : comparison_mode = TYPE_MODE (type);
9600 : 13629 : unsignedp = TYPE_UNSIGNED (type);
9601 : 13629 : comparison_code = convert_tree_comp_to_rtx (cmpcode, unsignedp);
9602 : : }
9603 : 2324 : else if (COMPARISON_CLASS_P (treeop0)
9604 : 2324 : && !VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (treeop0, 0))))
9605 : : {
9606 : 43 : type = TREE_TYPE (TREE_OPERAND (treeop0, 0));
9607 : 43 : enum tree_code cmpcode = TREE_CODE (treeop0);
9608 : 43 : op00 = expand_normal (TREE_OPERAND (treeop0, 0));
9609 : 43 : op01 = expand_normal (TREE_OPERAND (treeop0, 1));
9610 : 43 : unsignedp = TYPE_UNSIGNED (type);
9611 : 43 : comparison_mode = TYPE_MODE (type);
9612 : 43 : comparison_code = convert_tree_comp_to_rtx (cmpcode, unsignedp);
9613 : : }
9614 : : else
9615 : : {
9616 : 2281 : op00 = expand_normal (treeop0);
9617 : 2281 : op01 = const0_rtx;
9618 : 2281 : comparison_code = NE;
9619 : 2281 : comparison_mode = GET_MODE (op00);
9620 : 2281 : if (comparison_mode == VOIDmode)
9621 : 0 : comparison_mode = TYPE_MODE (TREE_TYPE (treeop0));
9622 : : }
9623 : 15953 : expanding_cond_expr_using_cmove = false;
9624 : :
9625 : 15953 : if (GET_MODE (op1) != mode)
9626 : 2043 : op1 = gen_lowpart (mode, op1);
9627 : :
9628 : 15953 : if (GET_MODE (op2) != mode)
9629 : 8777 : op2 = gen_lowpart (mode, op2);
9630 : :
9631 : : /* Try to emit the conditional move. */
9632 : 15953 : insn = emit_conditional_move (temp,
9633 : : { comparison_code, op00, op01,
9634 : : comparison_mode },
9635 : : op1, op2, mode,
9636 : : unsignedp);
9637 : :
9638 : : /* If we could do the conditional move, emit the sequence,
9639 : : and return. */
9640 : 15953 : if (insn)
9641 : : {
9642 : 13520 : rtx_insn *seq = get_insns ();
9643 : 13520 : end_sequence ();
9644 : 13520 : emit_insn (seq);
9645 : 13520 : return convert_modes (orig_mode, mode, temp, 0);
9646 : : }
9647 : :
9648 : : /* Otherwise discard the sequence and fall back to code with
9649 : : branches. */
9650 : 2433 : end_sequence ();
9651 : 2433 : return NULL_RTX;
9652 : : }
9653 : :
9654 : : /* A helper function for expand_expr_real_2 to be used with a
9655 : : misaligned mem_ref TEMP. Assume an unsigned type if UNSIGNEDP
9656 : : is nonzero, with alignment ALIGN in bits.
9657 : : Store the value at TARGET if possible (if TARGET is nonzero).
9658 : : Regardless of TARGET, we return the rtx for where the value is placed.
9659 : : If the result can be stored at TARGET, and ALT_RTL is non-NULL,
9660 : : then *ALT_RTL is set to TARGET (before legitimziation). */
9661 : :
9662 : : static rtx
9663 : 185858 : expand_misaligned_mem_ref (rtx temp, machine_mode mode, int unsignedp,
9664 : : unsigned int align, rtx target, rtx *alt_rtl)
9665 : : {
9666 : 185858 : enum insn_code icode;
9667 : :
9668 : 185858 : if ((icode = optab_handler (movmisalign_optab, mode))
9669 : : != CODE_FOR_nothing)
9670 : : {
9671 : 119418 : class expand_operand ops[2];
9672 : :
9673 : : /* We've already validated the memory, and we're creating a
9674 : : new pseudo destination. The predicates really can't fail,
9675 : : nor can the generator. */
9676 : 119418 : create_output_operand (&ops[0], NULL_RTX, mode);
9677 : 119418 : create_fixed_operand (&ops[1], temp);
9678 : 119418 : expand_insn (icode, 2, ops);
9679 : 119418 : temp = ops[0].value;
9680 : : }
9681 : 66440 : else if (targetm.slow_unaligned_access (mode, align))
9682 : 0 : temp = extract_bit_field (temp, GET_MODE_BITSIZE (mode),
9683 : 0 : 0, unsignedp, target,
9684 : : mode, mode, false, alt_rtl);
9685 : 185858 : return temp;
9686 : : }
9687 : :
9688 : : /* Helper function of expand_expr_2, expand a division or modulo.
9689 : : op0 and op1 should be already expanded treeop0 and treeop1, using
9690 : : expand_operands. */
9691 : :
9692 : : static rtx
9693 : 157369 : expand_expr_divmod (tree_code code, machine_mode mode, tree treeop0,
9694 : : tree treeop1, rtx op0, rtx op1, rtx target, int unsignedp)
9695 : : {
9696 : 314738 : bool mod_p = (code == TRUNC_MOD_EXPR || code == FLOOR_MOD_EXPR
9697 : 157369 : || code == CEIL_MOD_EXPR || code == ROUND_MOD_EXPR);
9698 : 157369 : if (SCALAR_INT_MODE_P (mode)
9699 : 157369 : && optimize >= 2
9700 : 130530 : && get_range_pos_neg (treeop0) == 1
9701 : 187572 : && get_range_pos_neg (treeop1) == 1)
9702 : : {
9703 : : /* If both arguments are known to be positive when interpreted
9704 : : as signed, we can expand it as both signed and unsigned
9705 : : division or modulo. Choose the cheaper sequence in that case. */
9706 : 17938 : bool speed_p = optimize_insn_for_speed_p ();
9707 : 17938 : do_pending_stack_adjust ();
9708 : 17938 : start_sequence ();
9709 : 17938 : rtx uns_ret = expand_divmod (mod_p, code, mode, op0, op1, target, 1);
9710 : 17938 : rtx_insn *uns_insns = get_insns ();
9711 : 17938 : end_sequence ();
9712 : 17938 : start_sequence ();
9713 : 17938 : rtx sgn_ret = expand_divmod (mod_p, code, mode, op0, op1, target, 0);
9714 : 17938 : rtx_insn *sgn_insns = get_insns ();
9715 : 17938 : end_sequence ();
9716 : 17938 : unsigned uns_cost = seq_cost (uns_insns, speed_p);
9717 : 17938 : unsigned sgn_cost = seq_cost (sgn_insns, speed_p);
9718 : 17938 : bool was_tie = false;
9719 : :
9720 : : /* If costs are the same then use as tie breaker the other other
9721 : : factor. */
9722 : 17938 : if (uns_cost == sgn_cost)
9723 : : {
9724 : 5887 : uns_cost = seq_cost (uns_insns, !speed_p);
9725 : 5887 : sgn_cost = seq_cost (sgn_insns, !speed_p);
9726 : 5887 : was_tie = true;
9727 : : }
9728 : :
9729 : 17938 : if (dump_file && (dump_flags & TDF_DETAILS))
9730 : 0 : fprintf (dump_file, ";; positive division:%s unsigned cost: %u; "
9731 : : "signed cost: %u\n",
9732 : : was_tie ? " (needed tie breaker)" : "", uns_cost, sgn_cost);
9733 : :
9734 : 17938 : if (uns_cost < sgn_cost || (uns_cost == sgn_cost && unsignedp))
9735 : : {
9736 : 12699 : emit_insn (uns_insns);
9737 : 12699 : return uns_ret;
9738 : : }
9739 : 5239 : emit_insn (sgn_insns);
9740 : 5239 : return sgn_ret;
9741 : : }
9742 : 139431 : return expand_divmod (mod_p, code, mode, op0, op1, target, unsignedp);
9743 : : }
9744 : :
9745 : : rtx
9746 : 12748571 : expand_expr_real_2 (const_sepops ops, rtx target, machine_mode tmode,
9747 : : enum expand_modifier modifier)
9748 : : {
9749 : 12748571 : rtx op0, op1, op2, temp;
9750 : 12748571 : rtx_code_label *lab;
9751 : 12748571 : tree type;
9752 : 12748571 : int unsignedp;
9753 : 12748571 : machine_mode mode;
9754 : 12748571 : scalar_int_mode int_mode;
9755 : 12748571 : enum tree_code code = ops->code;
9756 : 12748571 : optab this_optab;
9757 : 12748571 : rtx subtarget, original_target;
9758 : 12748571 : int ignore;
9759 : 12748571 : bool reduce_bit_field;
9760 : 12748571 : location_t loc = ops->location;
9761 : 12748571 : tree treeop0, treeop1, treeop2;
9762 : : #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
9763 : : ? reduce_to_bit_field_precision ((expr), \
9764 : : target, \
9765 : : type) \
9766 : : : (expr))
9767 : :
9768 : 12748571 : type = ops->type;
9769 : 12748571 : mode = TYPE_MODE (type);
9770 : 12748571 : unsignedp = TYPE_UNSIGNED (type);
9771 : :
9772 : 12748571 : treeop0 = ops->op0;
9773 : 12748571 : treeop1 = ops->op1;
9774 : 12748571 : treeop2 = ops->op2;
9775 : :
9776 : : /* We should be called only on simple (binary or unary) expressions,
9777 : : exactly those that are valid in gimple expressions that aren't
9778 : : GIMPLE_SINGLE_RHS (or invalid). */
9779 : 12748571 : gcc_assert (get_gimple_rhs_class (code) == GIMPLE_UNARY_RHS
9780 : : || get_gimple_rhs_class (code) == GIMPLE_BINARY_RHS
9781 : : || get_gimple_rhs_class (code) == GIMPLE_TERNARY_RHS);
9782 : :
9783 : 25497142 : ignore = (target == const0_rtx
9784 : 12748571 : || ((CONVERT_EXPR_CODE_P (code)
9785 : 9135315 : || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
9786 : 3630310 : && TREE_CODE (type) == VOID_TYPE));
9787 : :
9788 : : /* We should be called only if we need the result. */
9789 : 0 : gcc_assert (!ignore);
9790 : :
9791 : : /* An operation in what may be a bit-field type needs the
9792 : : result to be reduced to the precision of the bit-field type,
9793 : : which is narrower than that of the type's mode. */
9794 : 26181515 : reduce_bit_field = (INTEGRAL_TYPE_P (type)
9795 : 12748571 : && !type_has_mode_precision_p (type));
9796 : :
9797 : 684373 : if (reduce_bit_field
9798 : 684373 : && (modifier == EXPAND_STACK_PARM
9799 : 683852 : || (target && GET_MODE (target) != mode)))
9800 : 378748 : target = 0;
9801 : :
9802 : : /* Use subtarget as the target for operand 0 of a binary operation. */
9803 : 12748571 : subtarget = get_subtarget (target);
9804 : 12748571 : original_target = target;
9805 : :
9806 : 12748571 : switch (code)
9807 : : {
9808 : 3616444 : case NON_LVALUE_EXPR:
9809 : 3616444 : case PAREN_EXPR:
9810 : 3616444 : CASE_CONVERT:
9811 : 3616444 : if (treeop0 == error_mark_node)
9812 : 0 : return const0_rtx;
9813 : :
9814 : 3616444 : if (TREE_CODE (type) == UNION_TYPE)
9815 : : {
9816 : 0 : tree valtype = TREE_TYPE (treeop0);
9817 : :
9818 : : /* If both input and output are BLKmode, this conversion isn't doing
9819 : : anything except possibly changing memory attribute. */
9820 : 0 : if (mode == BLKmode && TYPE_MODE (valtype) == BLKmode)
9821 : : {
9822 : 0 : rtx result = expand_expr (treeop0, target, tmode,
9823 : : modifier);
9824 : :
9825 : 0 : result = copy_rtx (result);
9826 : 0 : set_mem_attributes (result, type, 0);
9827 : 0 : return result;
9828 : : }
9829 : :
9830 : 0 : if (target == 0)
9831 : : {
9832 : 0 : if (TYPE_MODE (type) != BLKmode)
9833 : 0 : target = gen_reg_rtx (TYPE_MODE (type));
9834 : : else
9835 : 0 : target = assign_temp (type, 1, 1);
9836 : : }
9837 : :
9838 : 0 : if (MEM_P (target))
9839 : : /* Store data into beginning of memory target. */
9840 : 0 : store_expr (treeop0,
9841 : 0 : adjust_address (target, TYPE_MODE (valtype), 0),
9842 : : modifier == EXPAND_STACK_PARM,
9843 : 0 : false, TYPE_REVERSE_STORAGE_ORDER (type));
9844 : :
9845 : : else
9846 : : {
9847 : 0 : gcc_assert (REG_P (target)
9848 : : && !TYPE_REVERSE_STORAGE_ORDER (type));
9849 : :
9850 : : /* Store this field into a union of the proper type. */
9851 : 0 : poly_uint64 op0_size
9852 : 0 : = tree_to_poly_uint64 (TYPE_SIZE (TREE_TYPE (treeop0)));
9853 : 0 : poly_uint64 union_size = GET_MODE_BITSIZE (mode);
9854 : 0 : store_field (target,
9855 : : /* The conversion must be constructed so that
9856 : : we know at compile time how many bits
9857 : : to preserve. */
9858 : 0 : ordered_min (op0_size, union_size),
9859 : 0 : 0, 0, 0, TYPE_MODE (valtype), treeop0, 0,
9860 : : false, false);
9861 : : }
9862 : :
9863 : : /* Return the entire union. */
9864 : 0 : return target;
9865 : : }
9866 : :
9867 : 3616444 : if (mode == TYPE_MODE (TREE_TYPE (treeop0)))
9868 : : {
9869 : 2152298 : op0 = expand_expr (treeop0, target, VOIDmode,
9870 : : modifier);
9871 : :
9872 : 2152298 : return REDUCE_BIT_FIELD (op0);
9873 : : }
9874 : :
9875 : 1818911 : op0 = expand_expr (treeop0, NULL_RTX, mode,
9876 : : modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier);
9877 : 1464146 : if (GET_MODE (op0) == mode)
9878 : : ;
9879 : :
9880 : : /* If OP0 is a constant, just convert it into the proper mode. */
9881 : 1424211 : else if (CONSTANT_P (op0))
9882 : : {
9883 : 896 : tree inner_type = TREE_TYPE (treeop0);
9884 : 896 : machine_mode inner_mode = GET_MODE (op0);
9885 : :
9886 : 896 : if (inner_mode == VOIDmode)
9887 : 11 : inner_mode = TYPE_MODE (inner_type);
9888 : :
9889 : 896 : if (modifier == EXPAND_INITIALIZER)
9890 : 0 : op0 = force_lowpart_subreg (mode, op0, inner_mode);
9891 : : else
9892 : 896 : op0 = convert_modes (mode, inner_mode, op0,
9893 : 896 : TYPE_UNSIGNED (inner_type));
9894 : : }
9895 : :
9896 : 1423315 : else if (modifier == EXPAND_INITIALIZER)
9897 : 24 : op0 = gen_rtx_fmt_e (TYPE_UNSIGNED (TREE_TYPE (treeop0))
9898 : : ? ZERO_EXTEND : SIGN_EXTEND, mode, op0);
9899 : :
9900 : 1423303 : else if (target == 0)
9901 : 907178 : op0 = convert_to_mode (mode, op0,
9902 : 907178 : TYPE_UNSIGNED (TREE_TYPE
9903 : : (treeop0)));
9904 : : else
9905 : : {
9906 : 1032250 : convert_move (target, op0,
9907 : 516125 : TYPE_UNSIGNED (TREE_TYPE (treeop0)));
9908 : 516125 : op0 = target;
9909 : : }
9910 : :
9911 : 1464146 : return REDUCE_BIT_FIELD (op0);
9912 : :
9913 : 0 : case ADDR_SPACE_CONVERT_EXPR:
9914 : 0 : {
9915 : 0 : tree treeop0_type = TREE_TYPE (treeop0);
9916 : :
9917 : 0 : gcc_assert (POINTER_TYPE_P (type));
9918 : 0 : gcc_assert (POINTER_TYPE_P (treeop0_type));
9919 : :
9920 : 0 : addr_space_t as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
9921 : 0 : addr_space_t as_from = TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type));
9922 : :
9923 : : /* Conversions between pointers to the same address space should
9924 : : have been implemented via CONVERT_EXPR / NOP_EXPR. */
9925 : 0 : gcc_assert (as_to != as_from);
9926 : :
9927 : 0 : op0 = expand_expr (treeop0, NULL_RTX, VOIDmode, modifier);
9928 : :
9929 : : /* Ask target code to handle conversion between pointers
9930 : : to overlapping address spaces. */
9931 : 0 : if (targetm.addr_space.subset_p (as_to, as_from)
9932 : 0 : || targetm.addr_space.subset_p (as_from, as_to))
9933 : : {
9934 : 0 : op0 = targetm.addr_space.convert (op0, treeop0_type, type);
9935 : : }
9936 : : else
9937 : : {
9938 : : /* For disjoint address spaces, converting anything but a null
9939 : : pointer invokes undefined behavior. We truncate or extend the
9940 : : value as if we'd converted via integers, which handles 0 as
9941 : : required, and all others as the programmer likely expects. */
9942 : : #ifndef POINTERS_EXTEND_UNSIGNED
9943 : : const int POINTERS_EXTEND_UNSIGNED = 1;
9944 : : #endif
9945 : 0 : op0 = convert_modes (mode, TYPE_MODE (treeop0_type),
9946 : : op0, POINTERS_EXTEND_UNSIGNED);
9947 : : }
9948 : 0 : gcc_assert (op0);
9949 : : return op0;
9950 : : }
9951 : :
9952 : 1339678 : case POINTER_PLUS_EXPR:
9953 : : /* Even though the sizetype mode and the pointer's mode can be different
9954 : : expand is able to handle this correctly and get the correct result out
9955 : : of the PLUS_EXPR code. */
9956 : : /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
9957 : : if sizetype precision is smaller than pointer precision. */
9958 : 1339678 : if (TYPE_PRECISION (sizetype) < TYPE_PRECISION (type))
9959 : 0 : treeop1 = fold_convert_loc (loc, type,
9960 : : fold_convert_loc (loc, ssizetype,
9961 : : treeop1));
9962 : : /* If sizetype precision is larger than pointer precision, truncate the
9963 : : offset to have matching modes. */
9964 : 1339678 : else if (TYPE_PRECISION (sizetype) > TYPE_PRECISION (type))
9965 : 0 : treeop1 = fold_convert_loc (loc, type, treeop1);
9966 : : /* FALLTHRU */
9967 : :
9968 : 5098572 : case PLUS_EXPR:
9969 : : /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
9970 : : something else, make sure we add the register to the constant and
9971 : : then to the other thing. This case can occur during strength
9972 : : reduction and doing it this way will produce better code if the
9973 : : frame pointer or argument pointer is eliminated.
9974 : :
9975 : : fold-const.cc will ensure that the constant is always in the inner
9976 : : PLUS_EXPR, so the only case we need to do anything about is if
9977 : : sp, ap, or fp is our second argument, in which case we must swap
9978 : : the innermost first argument and our second argument. */
9979 : :
9980 : 5098572 : if (TREE_CODE (treeop0) == PLUS_EXPR
9981 : 6872 : && TREE_CODE (TREE_OPERAND (treeop0, 1)) == INTEGER_CST
9982 : 0 : && VAR_P (treeop1)
9983 : 5098572 : && (DECL_RTL (treeop1) == frame_pointer_rtx
9984 : 0 : || DECL_RTL (treeop1) == stack_pointer_rtx
9985 : 0 : || DECL_RTL (treeop1) == arg_pointer_rtx))
9986 : : {
9987 : 0 : gcc_unreachable ();
9988 : : }
9989 : :
9990 : : /* If the result is to be ptr_mode and we are adding an integer to
9991 : : something, we might be forming a constant. So try to use
9992 : : plus_constant. If it produces a sum and we can't accept it,
9993 : : use force_operand. This allows P = &ARR[const] to generate
9994 : : efficient code on machines where a SYMBOL_REF is not a valid
9995 : : address.
9996 : :
9997 : : If this is an EXPAND_SUM call, always return the sum. */
9998 : 5098572 : if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER
9999 : 5098572 : || (mode == ptr_mode && (unsignedp || ! flag_trapv)))
10000 : : {
10001 : 3329142 : if (modifier == EXPAND_STACK_PARM)
10002 : 18618 : target = 0;
10003 : 3329142 : if (TREE_CODE (treeop0) == INTEGER_CST
10004 : 3330149 : && HWI_COMPUTABLE_MODE_P (mode)
10005 : 3330153 : && TREE_CONSTANT (treeop1))
10006 : : {
10007 : 4 : rtx constant_part;
10008 : 4 : HOST_WIDE_INT wc;
10009 : 4 : machine_mode wmode = TYPE_MODE (TREE_TYPE (treeop1));
10010 : :
10011 : 4 : op1 = expand_expr (treeop1, subtarget, VOIDmode,
10012 : : EXPAND_SUM);
10013 : : /* Use wi::shwi to ensure that the constant is
10014 : : truncated according to the mode of OP1, then sign extended
10015 : : to a HOST_WIDE_INT. Using the constant directly can result
10016 : : in non-canonical RTL in a 64x32 cross compile. */
10017 : 4 : wc = TREE_INT_CST_LOW (treeop0);
10018 : 4 : constant_part =
10019 : 4 : immed_wide_int_const (wi::shwi (wc, wmode), wmode);
10020 : 4 : op1 = plus_constant (mode, op1, INTVAL (constant_part));
10021 : 4 : if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
10022 : 1 : op1 = force_operand (op1, target);
10023 : 4 : return REDUCE_BIT_FIELD (op1);
10024 : : }
10025 : :
10026 : 3329138 : else if (TREE_CODE (treeop1) == INTEGER_CST
10027 : 7079683 : && HWI_COMPUTABLE_MODE_P (mode)
10028 : 5581870 : && TREE_CONSTANT (treeop0))
10029 : : {
10030 : 271617 : rtx constant_part;
10031 : 271617 : HOST_WIDE_INT wc;
10032 : 271617 : machine_mode wmode = TYPE_MODE (TREE_TYPE (treeop0));
10033 : :
10034 : 475048 : op0 = expand_expr (treeop0, subtarget, VOIDmode,
10035 : : (modifier == EXPAND_INITIALIZER
10036 : : ? EXPAND_INITIALIZER : EXPAND_SUM));
10037 : 271617 : if (! CONSTANT_P (op0))
10038 : : {
10039 : 6 : op1 = expand_expr (treeop1, NULL_RTX,
10040 : : VOIDmode, modifier);
10041 : : /* Return a PLUS if modifier says it's OK. */
10042 : 6 : if (modifier == EXPAND_SUM
10043 : : || modifier == EXPAND_INITIALIZER)
10044 : 6 : return simplify_gen_binary (PLUS, mode, op0, op1);
10045 : 0 : goto binop2;
10046 : : }
10047 : : /* Use wi::shwi to ensure that the constant is
10048 : : truncated according to the mode of OP1, then sign extended
10049 : : to a HOST_WIDE_INT. Using the constant directly can result
10050 : : in non-canonical RTL in a 64x32 cross compile. */
10051 : 271611 : wc = TREE_INT_CST_LOW (treeop1);
10052 : 271611 : constant_part
10053 : 271611 : = immed_wide_int_const (wi::shwi (wc, wmode), wmode);
10054 : 271611 : op0 = plus_constant (mode, op0, INTVAL (constant_part));
10055 : 271611 : if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
10056 : 202633 : op0 = force_operand (op0, target);
10057 : 271611 : return REDUCE_BIT_FIELD (op0);
10058 : : }
10059 : : }
10060 : :
10061 : : /* Use TER to expand pointer addition of a negated value
10062 : : as pointer subtraction. */
10063 : 8601909 : if ((POINTER_TYPE_P (TREE_TYPE (treeop0))
10064 : 3758881 : || (TREE_CODE (TREE_TYPE (treeop0)) == VECTOR_TYPE
10065 : 75544 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0)))))
10066 : 1068070 : && TREE_CODE (treeop1) == SSA_NAME
10067 : 5925623 : && TYPE_MODE (TREE_TYPE (treeop0))
10068 : 549336 : == TYPE_MODE (TREE_TYPE (treeop1)))
10069 : : {
10070 : 549336 : gimple *def = get_def_for_expr (treeop1, NEGATE_EXPR);
10071 : 549336 : if (def)
10072 : : {
10073 : 2910 : treeop1 = gimple_assign_rhs1 (def);
10074 : 2910 : code = MINUS_EXPR;
10075 : 2910 : goto do_minus;
10076 : : }
10077 : : }
10078 : :
10079 : : /* No sense saving up arithmetic to be done
10080 : : if it's all in the wrong mode to form part of an address.
10081 : : And force_operand won't know whether to sign-extend or
10082 : : zero-extend. */
10083 : 4824041 : if (modifier != EXPAND_INITIALIZER
10084 : 4824041 : && (modifier != EXPAND_SUM || mode != ptr_mode))
10085 : : {
10086 : 4281528 : expand_operands (treeop0, treeop1,
10087 : : subtarget, &op0, &op1, modifier);
10088 : 4281528 : if (op0 == const0_rtx)
10089 : 8680 : return op1;
10090 : 4272848 : if (op1 == const0_rtx)
10091 : : return op0;
10092 : 4272597 : goto binop2;
10093 : : }
10094 : :
10095 : 542513 : expand_operands (treeop0, treeop1,
10096 : : subtarget, &op0, &op1, modifier);
10097 : 542513 : return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
10098 : :
10099 : 500628 : case MINUS_EXPR:
10100 : 500628 : case POINTER_DIFF_EXPR:
10101 : 500628 : do_minus:
10102 : : /* For initializers, we are allowed to return a MINUS of two
10103 : : symbolic constants. Here we handle all cases when both operands
10104 : : are constant. */
10105 : : /* Handle difference of two symbolic constants,
10106 : : for the sake of an initializer. */
10107 : 500628 : if ((modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
10108 : 3011 : && really_constant_p (treeop0)
10109 : 501107 : && really_constant_p (treeop1))
10110 : : {
10111 : 68 : expand_operands (treeop0, treeop1,
10112 : : NULL_RTX, &op0, &op1, modifier);
10113 : 68 : return simplify_gen_binary (MINUS, mode, op0, op1);
10114 : : }
10115 : :
10116 : : /* No sense saving up arithmetic to be done
10117 : : if it's all in the wrong mode to form part of an address.
10118 : : And force_operand won't know whether to sign-extend or
10119 : : zero-extend. */
10120 : 500560 : if (modifier != EXPAND_INITIALIZER
10121 : 500560 : && (modifier != EXPAND_SUM || mode != ptr_mode))
10122 : 497617 : goto binop;
10123 : :
10124 : 2943 : expand_operands (treeop0, treeop1,
10125 : : subtarget, &op0, &op1, modifier);
10126 : :
10127 : : /* Convert A - const to A + (-const). */
10128 : 2943 : if (CONST_INT_P (op1))
10129 : : {
10130 : 0 : op1 = negate_rtx (mode, op1);
10131 : 0 : return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
10132 : : }
10133 : :
10134 : 2943 : goto binop2;
10135 : :
10136 : 0 : case WIDEN_MULT_PLUS_EXPR:
10137 : 0 : case WIDEN_MULT_MINUS_EXPR:
10138 : 0 : expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
10139 : 0 : op2 = expand_normal (treeop2);
10140 : 0 : target = expand_widen_pattern_expr (ops, op0, op1, op2,
10141 : : target, unsignedp);
10142 : 0 : return target;
10143 : :
10144 : 18657 : case WIDEN_MULT_EXPR:
10145 : : /* If first operand is constant, swap them.
10146 : : Thus the following special case checks need only
10147 : : check the second operand. */
10148 : 18657 : if (TREE_CODE (treeop0) == INTEGER_CST)
10149 : 368 : std::swap (treeop0, treeop1);
10150 : :
10151 : : /* First, check if we have a multiplication of one signed and one
10152 : : unsigned operand. */
10153 : 18657 : if (TREE_CODE (treeop1) != INTEGER_CST
10154 : 18657 : && (TYPE_UNSIGNED (TREE_TYPE (treeop0))
10155 : 14247 : != TYPE_UNSIGNED (TREE_TYPE (treeop1))))
10156 : : {
10157 : 0 : machine_mode innermode = TYPE_MODE (TREE_TYPE (treeop0));
10158 : 0 : this_optab = usmul_widen_optab;
10159 : 0 : if (find_widening_optab_handler (this_optab, mode, innermode)
10160 : : != CODE_FOR_nothing)
10161 : : {
10162 : 0 : if (TYPE_UNSIGNED (TREE_TYPE (treeop0)))
10163 : 0 : expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
10164 : : EXPAND_NORMAL);
10165 : : else
10166 : 0 : expand_operands (treeop0, treeop1, NULL_RTX, &op1, &op0,
10167 : : EXPAND_NORMAL);
10168 : : /* op0 and op1 might still be constant, despite the above
10169 : : != INTEGER_CST check. Handle it. */
10170 : 0 : if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
10171 : : {
10172 : 0 : op0 = convert_modes (mode, innermode, op0, true);
10173 : 0 : op1 = convert_modes (mode, innermode, op1, false);
10174 : 0 : return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1,
10175 : : target, unsignedp));
10176 : : }
10177 : 0 : goto binop3;
10178 : : }
10179 : : }
10180 : : /* Check for a multiplication with matching signedness. */
10181 : 18657 : else if ((TREE_CODE (treeop1) == INTEGER_CST
10182 : 4410 : && int_fits_type_p (treeop1, TREE_TYPE (treeop0)))
10183 : 18657 : || (TYPE_UNSIGNED (TREE_TYPE (treeop1))
10184 : 14247 : == TYPE_UNSIGNED (TREE_TYPE (treeop0))))
10185 : : {
10186 : 18657 : tree op0type = TREE_TYPE (treeop0);
10187 : 18657 : machine_mode innermode = TYPE_MODE (op0type);
10188 : 18657 : bool zextend_p = TYPE_UNSIGNED (op0type);
10189 : 18657 : optab other_optab = zextend_p ? smul_widen_optab : umul_widen_optab;
10190 : 2585 : this_optab = zextend_p ? umul_widen_optab : smul_widen_optab;
10191 : :
10192 : 18657 : if (TREE_CODE (treeop0) != INTEGER_CST)
10193 : : {
10194 : 18657 : if (find_widening_optab_handler (this_optab, mode, innermode)
10195 : : != CODE_FOR_nothing)
10196 : : {
10197 : 18657 : expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
10198 : : EXPAND_NORMAL);
10199 : : /* op0 and op1 might still be constant, despite the above
10200 : : != INTEGER_CST check. Handle it. */
10201 : 18657 : if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
10202 : : {
10203 : 0 : widen_mult_const:
10204 : 0 : op0 = convert_modes (mode, innermode, op0, zextend_p);
10205 : 0 : op1
10206 : 0 : = convert_modes (mode, innermode, op1,
10207 : 0 : TYPE_UNSIGNED (TREE_TYPE (treeop1)));
10208 : 0 : return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1,
10209 : : target,
10210 : : unsignedp));
10211 : : }
10212 : 18657 : temp = expand_widening_mult (mode, op0, op1, target,
10213 : : unsignedp, this_optab);
10214 : 18657 : return REDUCE_BIT_FIELD (temp);
10215 : : }
10216 : 0 : if (find_widening_optab_handler (other_optab, mode, innermode)
10217 : : != CODE_FOR_nothing
10218 : 0 : && innermode == word_mode)
10219 : : {
10220 : 0 : rtx htem, hipart;
10221 : 0 : op0 = expand_normal (treeop0);
10222 : 0 : op1 = expand_normal (treeop1);
10223 : : /* op0 and op1 might be constants, despite the above
10224 : : != INTEGER_CST check. Handle it. */
10225 : 0 : if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
10226 : 0 : goto widen_mult_const;
10227 : 0 : temp = expand_binop (mode, other_optab, op0, op1, target,
10228 : : unsignedp, OPTAB_LIB_WIDEN);
10229 : 0 : hipart = gen_highpart (word_mode, temp);
10230 : 0 : htem = expand_mult_highpart_adjust (word_mode, hipart,
10231 : : op0, op1, hipart,
10232 : : zextend_p);
10233 : 0 : if (htem != hipart)
10234 : 0 : emit_move_insn (hipart, htem);
10235 : 0 : return REDUCE_BIT_FIELD (temp);
10236 : : }
10237 : : }
10238 : : }
10239 : 0 : treeop0 = fold_build1 (CONVERT_EXPR, type, treeop0);
10240 : 0 : treeop1 = fold_build1 (CONVERT_EXPR, type, treeop1);
10241 : 0 : expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
10242 : 0 : return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
10243 : :
10244 : 1324802 : case MULT_EXPR:
10245 : : /* If this is a fixed-point operation, then we cannot use the code
10246 : : below because "expand_mult" doesn't support sat/no-sat fixed-point
10247 : : multiplications. */
10248 : 1324802 : if (ALL_FIXED_POINT_MODE_P (mode))
10249 : 0 : goto binop;
10250 : :
10251 : : /* If first operand is constant, swap them.
10252 : : Thus the following special case checks need only
10253 : : check the second operand. */
10254 : 1324802 : if (TREE_CODE (treeop0) == INTEGER_CST)
10255 : 686 : std::swap (treeop0, treeop1);
10256 : :
10257 : : /* Attempt to return something suitable for generating an
10258 : : indexed address, for machines that support that. */
10259 : :
10260 : 517682 : if (modifier == EXPAND_SUM && mode == ptr_mode
10261 : 1842484 : && tree_fits_shwi_p (treeop1))
10262 : : {
10263 : 511268 : tree exp1 = treeop1;
10264 : :
10265 : 511268 : op0 = expand_expr (treeop0, subtarget, VOIDmode,
10266 : : EXPAND_SUM);
10267 : :
10268 : 511268 : if (!REG_P (op0))
10269 : 241947 : op0 = force_operand (op0, NULL_RTX);
10270 : 511268 : if (!REG_P (op0))
10271 : 1708 : op0 = copy_to_mode_reg (mode, op0);
10272 : :
10273 : 511268 : op1 = gen_int_mode (tree_to_shwi (exp1),
10274 : 511268 : TYPE_MODE (TREE_TYPE (exp1)));
10275 : 511268 : return REDUCE_BIT_FIELD (gen_rtx_MULT (mode, op0, op1));
10276 : : }
10277 : :
10278 : 813534 : if (modifier == EXPAND_STACK_PARM)
10279 : 2932 : target = 0;
10280 : :
10281 : 813534 : if (SCALAR_INT_MODE_P (mode) && optimize >= 2)
10282 : : {
10283 : 479828 : gimple *def_stmt0 = get_def_for_expr (treeop0, TRUNC_DIV_EXPR);
10284 : 479828 : gimple *def_stmt1 = get_def_for_expr (treeop1, TRUNC_DIV_EXPR);
10285 : 479828 : if (def_stmt0
10286 : 479828 : && !operand_equal_p (treeop1, gimple_assign_rhs2 (def_stmt0), 0))
10287 : : def_stmt0 = NULL;
10288 : 479828 : if (def_stmt1
10289 : 479828 : && !operand_equal_p (treeop0, gimple_assign_rhs2 (def_stmt1), 0))
10290 : : def_stmt1 = NULL;
10291 : :
10292 : 479828 : if (def_stmt0 || def_stmt1)
10293 : : {
10294 : : /* X / Y * Y can be expanded as X - X % Y too.
10295 : : Choose the cheaper sequence of those two. */
10296 : 417 : if (def_stmt0)
10297 : 417 : treeop0 = gimple_assign_rhs1 (def_stmt0);
10298 : : else
10299 : : {
10300 : 0 : treeop1 = treeop0;
10301 : 0 : treeop0 = gimple_assign_rhs1 (def_stmt1);
10302 : : }
10303 : 417 : expand_operands (treeop0, treeop1, subtarget, &op0, &op1,
10304 : : EXPAND_NORMAL);
10305 : 417 : bool speed_p = optimize_insn_for_speed_p ();
10306 : 417 : do_pending_stack_adjust ();
10307 : 417 : start_sequence ();
10308 : 417 : rtx divmul_ret
10309 : 417 : = expand_expr_divmod (TRUNC_DIV_EXPR, mode, treeop0, treeop1,
10310 : : op0, op1, NULL_RTX, unsignedp);
10311 : 417 : divmul_ret = expand_mult (mode, divmul_ret, op1, target,
10312 : : unsignedp);
10313 : 417 : rtx_insn *divmul_insns = get_insns ();
10314 : 417 : end_sequence ();
10315 : 417 : start_sequence ();
10316 : 417 : rtx modsub_ret
10317 : 417 : = expand_expr_divmod (TRUNC_MOD_EXPR, mode, treeop0, treeop1,
10318 : : op0, op1, NULL_RTX, unsignedp);
10319 : 417 : this_optab = optab_for_tree_code (MINUS_EXPR, type,
10320 : : optab_default);
10321 : 417 : modsub_ret = expand_binop (mode, this_optab, op0, modsub_ret,
10322 : : target, unsignedp, OPTAB_LIB_WIDEN);
10323 : 417 : rtx_insn *modsub_insns = get_insns ();
10324 : 417 : end_sequence ();
10325 : 417 : unsigned divmul_cost = seq_cost (divmul_insns, speed_p);
10326 : 417 : unsigned modsub_cost = seq_cost (modsub_insns, speed_p);
10327 : : /* If costs are the same then use as tie breaker the other other
10328 : : factor. */
10329 : 417 : if (divmul_cost == modsub_cost)
10330 : : {
10331 : 20 : divmul_cost = seq_cost (divmul_insns, !speed_p);
10332 : 20 : modsub_cost = seq_cost (modsub_insns, !speed_p);
10333 : : }
10334 : :
10335 : 417 : if (divmul_cost <= modsub_cost)
10336 : : {
10337 : 349 : emit_insn (divmul_insns);
10338 : 349 : return REDUCE_BIT_FIELD (divmul_ret);
10339 : : }
10340 : 68 : emit_insn (modsub_insns);
10341 : 68 : return REDUCE_BIT_FIELD (modsub_ret);
10342 : : }
10343 : : }
10344 : :
10345 : 813117 : expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
10346 : :
10347 : : /* Expand X*Y as X&-Y when Y must be zero or one. */
10348 : 813117 : if (SCALAR_INT_MODE_P (mode))
10349 : : {
10350 : 682417 : bool gimple_zero_one_valued_p (tree, tree (*)(tree));
10351 : 682417 : bool bit0_p = gimple_zero_one_valued_p (treeop0, nullptr);
10352 : 682417 : bool bit1_p = gimple_zero_one_valued_p (treeop1, nullptr);
10353 : :
10354 : : /* Expand X*Y as X&Y when both X and Y must be zero or one. */
10355 : 682417 : if (bit0_p && bit1_p)
10356 : 2 : return REDUCE_BIT_FIELD (expand_and (mode, op0, op1, target));
10357 : :
10358 : 682415 : if (bit0_p || bit1_p)
10359 : : {
10360 : 4280 : bool speed = optimize_insn_for_speed_p ();
10361 : 4280 : int cost = add_cost (speed, mode) + neg_cost (speed, mode);
10362 : 4280 : struct algorithm algorithm;
10363 : 4280 : enum mult_variant variant;
10364 : 4280 : if (CONST_INT_P (op1)
10365 : 4280 : ? !choose_mult_variant (mode, INTVAL (op1),
10366 : : &algorithm, &variant, cost)
10367 : 672 : : cost < mul_cost (speed, mode))
10368 : : {
10369 : 2042 : temp = bit0_p ? expand_and (mode, negate_rtx (mode, op0),
10370 : : op1, target)
10371 : 257 : : expand_and (mode, op0,
10372 : : negate_rtx (mode, op1),
10373 : : target);
10374 : 2042 : return REDUCE_BIT_FIELD (temp);
10375 : : }
10376 : : }
10377 : : }
10378 : :
10379 : 811073 : return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
10380 : :
10381 : 156535 : case TRUNC_MOD_EXPR:
10382 : 156535 : case FLOOR_MOD_EXPR:
10383 : 156535 : case CEIL_MOD_EXPR:
10384 : 156535 : case ROUND_MOD_EXPR:
10385 : :
10386 : 156535 : case TRUNC_DIV_EXPR:
10387 : 156535 : case FLOOR_DIV_EXPR:
10388 : 156535 : case CEIL_DIV_EXPR:
10389 : 156535 : case ROUND_DIV_EXPR:
10390 : 156535 : case EXACT_DIV_EXPR:
10391 : : /* If this is a fixed-point operation, then we cannot use the code
10392 : : below because "expand_divmod" doesn't support sat/no-sat fixed-point
10393 : : divisions. */
10394 : 156535 : if (ALL_FIXED_POINT_MODE_P (mode))
10395 : 0 : goto binop;
10396 : :
10397 : 156535 : if (modifier == EXPAND_STACK_PARM)
10398 : 307 : target = 0;
10399 : : /* Possible optimization: compute the dividend with EXPAND_SUM
10400 : : then if the divisor is constant can optimize the case
10401 : : where some terms of the dividend have coeffs divisible by it. */
10402 : 156535 : expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
10403 : 156535 : return expand_expr_divmod (code, mode, treeop0, treeop1, op0, op1,
10404 : 156535 : target, unsignedp);
10405 : :
10406 : 30928 : case RDIV_EXPR:
10407 : 30928 : goto binop;
10408 : :
10409 : 1618 : case MULT_HIGHPART_EXPR:
10410 : 1618 : expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
10411 : 1618 : temp = expand_mult_highpart (mode, op0, op1, target, unsignedp);
10412 : 1618 : gcc_assert (temp);
10413 : : return temp;
10414 : :
10415 : 0 : case FIXED_CONVERT_EXPR:
10416 : 0 : op0 = expand_normal (treeop0);
10417 : 0 : if (target == 0 || modifier == EXPAND_STACK_PARM)
10418 : 0 : target = gen_reg_rtx (mode);
10419 : :
10420 : 0 : if ((TREE_CODE (TREE_TYPE (treeop0)) == INTEGER_TYPE
10421 : 0 : && TYPE_UNSIGNED (TREE_TYPE (treeop0)))
10422 : 0 : || (TREE_CODE (type) == INTEGER_TYPE && TYPE_UNSIGNED (type)))
10423 : 0 : expand_fixed_convert (target, op0, 1, TYPE_SATURATING (type));
10424 : : else
10425 : 0 : expand_fixed_convert (target, op0, 0, TYPE_SATURATING (type));
10426 : : return target;
10427 : :
10428 : 47574 : case FIX_TRUNC_EXPR:
10429 : 47574 : op0 = expand_normal (treeop0);
10430 : 47574 : if (target == 0 || modifier == EXPAND_STACK_PARM)
10431 : 3570 : target = gen_reg_rtx (mode);
10432 : 47574 : expand_fix (target, op0, unsignedp);
10433 : 47574 : return target;
10434 : :
10435 : 132789 : case FLOAT_EXPR:
10436 : 132789 : op0 = expand_normal (treeop0);
10437 : 132789 : if (target == 0 || modifier == EXPAND_STACK_PARM)
10438 : 62461 : target = gen_reg_rtx (mode);
10439 : : /* expand_float can't figure out what to do if FROM has VOIDmode.
10440 : : So give it the correct mode. With -O, cse will optimize this. */
10441 : 132789 : if (GET_MODE (op0) == VOIDmode)
10442 : 109 : op0 = copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0)),
10443 : : op0);
10444 : 265578 : expand_float (target, op0,
10445 : 132789 : TYPE_UNSIGNED (TREE_TYPE (treeop0)));
10446 : 132789 : return target;
10447 : :
10448 : 49038 : case NEGATE_EXPR:
10449 : 49038 : op0 = expand_expr (treeop0, subtarget,
10450 : : VOIDmode, EXPAND_NORMAL);
10451 : 49038 : if (modifier == EXPAND_STACK_PARM)
10452 : 241 : target = 0;
10453 : 49038 : temp = expand_unop (mode,
10454 : : optab_for_tree_code (NEGATE_EXPR, type,
10455 : : optab_default),
10456 : : op0, target, 0);
10457 : 49038 : gcc_assert (temp);
10458 : 49038 : return REDUCE_BIT_FIELD (temp);
10459 : :
10460 : 24580 : case ABS_EXPR:
10461 : 24580 : case ABSU_EXPR:
10462 : 24580 : op0 = expand_expr (treeop0, subtarget,
10463 : : VOIDmode, EXPAND_NORMAL);
10464 : 24580 : if (modifier == EXPAND_STACK_PARM)
10465 : 50 : target = 0;
10466 : :
10467 : : /* ABS_EXPR is not valid for complex arguments. */
10468 : 24580 : gcc_assert (GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
10469 : : && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT);
10470 : :
10471 : : /* Unsigned abs is simply the operand. Testing here means we don't
10472 : : risk generating incorrect code below. */
10473 : 24580 : if (TYPE_UNSIGNED (TREE_TYPE (treeop0)))
10474 : : return op0;
10475 : :
10476 : 24580 : return expand_abs (mode, op0, target, unsignedp,
10477 : 49160 : safe_from_p (target, treeop0, 1));
10478 : :
10479 : 99590 : case MAX_EXPR:
10480 : 99590 : case MIN_EXPR:
10481 : 99590 : target = original_target;
10482 : 99590 : if (target == 0
10483 : 99590 : || modifier == EXPAND_STACK_PARM
10484 : 56014 : || (MEM_P (target) && MEM_VOLATILE_P (target))
10485 : 56014 : || GET_MODE (target) != mode
10486 : 155604 : || (REG_P (target)
10487 : 49453 : && REGNO (target) < FIRST_PSEUDO_REGISTER))
10488 : 43576 : target = gen_reg_rtx (mode);
10489 : 99590 : expand_operands (treeop0, treeop1,
10490 : : target, &op0, &op1, EXPAND_NORMAL);
10491 : :
10492 : : /* First try to do it with a special MIN or MAX instruction.
10493 : : If that does not win, use a conditional jump to select the proper
10494 : : value. */
10495 : 99590 : this_optab = optab_for_tree_code (code, type, optab_default);
10496 : 99590 : temp = expand_binop (mode, this_optab, op0, op1, target, unsignedp,
10497 : : OPTAB_WIDEN);
10498 : 99590 : if (temp != 0)
10499 : : return temp;
10500 : :
10501 : 122 : if (VECTOR_TYPE_P (type))
10502 : 0 : gcc_unreachable ();
10503 : :
10504 : : /* At this point, a MEM target is no longer useful; we will get better
10505 : : code without it. */
10506 : :
10507 : 122 : if (! REG_P (target))
10508 : 1 : target = gen_reg_rtx (mode);
10509 : :
10510 : : /* If op1 was placed in target, swap op0 and op1. */
10511 : 122 : if (target != op0 && target == op1)
10512 : 0 : std::swap (op0, op1);
10513 : :
10514 : : /* We generate better code and avoid problems with op1 mentioning
10515 : : target by forcing op1 into a pseudo if it isn't a constant. */
10516 : 122 : if (! CONSTANT_P (op1))
10517 : 42 : op1 = force_reg (mode, op1);
10518 : :
10519 : 122 : {
10520 : 122 : enum rtx_code comparison_code;
10521 : 122 : rtx cmpop1 = op1;
10522 : :
10523 : 122 : if (code == MAX_EXPR)
10524 : 62 : comparison_code = unsignedp ? GEU : GE;
10525 : : else
10526 : 60 : comparison_code = unsignedp ? LEU : LE;
10527 : :
10528 : : /* Canonicalize to comparisons against 0. */
10529 : 122 : if (op1 == const1_rtx)
10530 : : {
10531 : : /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
10532 : : or (a != 0 ? a : 1) for unsigned.
10533 : : For MIN we are safe converting (a <= 1 ? a : 1)
10534 : : into (a <= 0 ? a : 1) */
10535 : 0 : cmpop1 = const0_rtx;
10536 : 0 : if (code == MAX_EXPR)
10537 : 0 : comparison_code = unsignedp ? NE : GT;
10538 : : }
10539 : 122 : if (op1 == constm1_rtx && !unsignedp)
10540 : : {
10541 : : /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
10542 : : and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
10543 : 0 : cmpop1 = const0_rtx;
10544 : 0 : if (code == MIN_EXPR)
10545 : 0 : comparison_code = LT;
10546 : : }
10547 : :
10548 : : /* Use a conditional move if possible. */
10549 : 122 : if (can_conditionally_move_p (mode))
10550 : : {
10551 : 75 : rtx insn;
10552 : :
10553 : 75 : start_sequence ();
10554 : :
10555 : : /* Try to emit the conditional move. */
10556 : 75 : insn = emit_conditional_move (target,
10557 : : { comparison_code,
10558 : : op0, cmpop1, mode },
10559 : : op0, op1, mode,
10560 : : unsignedp);
10561 : :
10562 : : /* If we could do the conditional move, emit the sequence,
10563 : : and return. */
10564 : 75 : if (insn)
10565 : : {
10566 : 41 : rtx_insn *seq = get_insns ();
10567 : 41 : end_sequence ();
10568 : 41 : emit_insn (seq);
10569 : 41 : return target;
10570 : : }
10571 : :
10572 : : /* Otherwise discard the sequence and fall back to code with
10573 : : branches. */
10574 : 34 : end_sequence ();
10575 : : }
10576 : :
10577 : 81 : if (target != op0)
10578 : 52 : emit_move_insn (target, op0);
10579 : :
10580 : 81 : lab = gen_label_rtx ();
10581 : 81 : do_compare_rtx_and_jump (target, cmpop1, comparison_code,
10582 : : unsignedp, mode, NULL_RTX, NULL, lab,
10583 : : profile_probability::uninitialized ());
10584 : : }
10585 : 81 : emit_move_insn (target, op1);
10586 : 81 : emit_label (lab);
10587 : 81 : return target;
10588 : :
10589 : 56082 : case BIT_NOT_EXPR:
10590 : 56082 : op0 = expand_expr (treeop0, subtarget,
10591 : : VOIDmode, EXPAND_NORMAL);
10592 : 56082 : if (modifier == EXPAND_STACK_PARM)
10593 : 88 : target = 0;
10594 : : /* In case we have to reduce the result to bitfield precision
10595 : : for unsigned bitfield expand this as XOR with a proper constant
10596 : : instead. */
10597 : 56082 : if (reduce_bit_field && TYPE_UNSIGNED (type))
10598 : : {
10599 : 20687 : int_mode = SCALAR_INT_TYPE_MODE (type);
10600 : 20687 : wide_int mask = wi::mask (TYPE_PRECISION (type),
10601 : 41374 : false, GET_MODE_PRECISION (int_mode));
10602 : :
10603 : 41374 : temp = expand_binop (int_mode, xor_optab, op0,
10604 : 41374 : immed_wide_int_const (mask, int_mode),
10605 : : target, 1, OPTAB_LIB_WIDEN);
10606 : 20687 : }
10607 : : else
10608 : 35395 : temp = expand_unop (mode, one_cmpl_optab, op0, target, 1);
10609 : 56082 : gcc_assert (temp);
10610 : : return temp;
10611 : :
10612 : : /* ??? Can optimize bitwise operations with one arg constant.
10613 : : Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
10614 : : and (a bitwise1 b) bitwise2 b (etc)
10615 : : but that is probably not worth while. */
10616 : :
10617 : 621625 : case BIT_AND_EXPR:
10618 : 621625 : case BIT_IOR_EXPR:
10619 : 621625 : case BIT_XOR_EXPR:
10620 : 621625 : goto binop;
10621 : :
10622 : 7393 : case LROTATE_EXPR:
10623 : 7393 : case RROTATE_EXPR:
10624 : 7393 : gcc_assert (VECTOR_MODE_P (TYPE_MODE (type))
10625 : : || type_has_mode_precision_p (type));
10626 : : /* fall through */
10627 : :
10628 : 272190 : case LSHIFT_EXPR:
10629 : 272190 : case RSHIFT_EXPR:
10630 : 272190 : {
10631 : : /* If this is a fixed-point operation, then we cannot use the code
10632 : : below because "expand_shift" doesn't support sat/no-sat fixed-point
10633 : : shifts. */
10634 : 272190 : if (ALL_FIXED_POINT_MODE_P (mode))
10635 : 0 : goto binop;
10636 : :
10637 : 272190 : if (! safe_from_p (subtarget, treeop1, 1))
10638 : 5238 : subtarget = 0;
10639 : 272190 : if (modifier == EXPAND_STACK_PARM)
10640 : 2574 : target = 0;
10641 : 272190 : op0 = expand_expr (treeop0, subtarget,
10642 : : VOIDmode, EXPAND_NORMAL);
10643 : :
10644 : : /* Left shift optimization when shifting across word_size boundary.
10645 : :
10646 : : If mode == GET_MODE_WIDER_MODE (word_mode), then normally
10647 : : there isn't native instruction to support this wide mode
10648 : : left shift. Given below scenario:
10649 : :
10650 : : Type A = (Type) B << C
10651 : :
10652 : : |< T >|
10653 : : | dest_high | dest_low |
10654 : :
10655 : : | word_size |
10656 : :
10657 : : If the shift amount C caused we shift B to across the word
10658 : : size boundary, i.e part of B shifted into high half of
10659 : : destination register, and part of B remains in the low
10660 : : half, then GCC will use the following left shift expand
10661 : : logic:
10662 : :
10663 : : 1. Initialize dest_low to B.
10664 : : 2. Initialize every bit of dest_high to the sign bit of B.
10665 : : 3. Logic left shift dest_low by C bit to finalize dest_low.
10666 : : The value of dest_low before this shift is kept in a temp D.
10667 : : 4. Logic left shift dest_high by C.
10668 : : 5. Logic right shift D by (word_size - C).
10669 : : 6. Or the result of 4 and 5 to finalize dest_high.
10670 : :
10671 : : While, by checking gimple statements, if operand B is
10672 : : coming from signed extension, then we can simplify above
10673 : : expand logic into:
10674 : :
10675 : : 1. dest_high = src_low >> (word_size - C).
10676 : : 2. dest_low = src_low << C.
10677 : :
10678 : : We can use one arithmetic right shift to finish all the
10679 : : purpose of steps 2, 4, 5, 6, thus we reduce the steps
10680 : : needed from 6 into 2.
10681 : :
10682 : : The case is similar for zero extension, except that we
10683 : : initialize dest_high to zero rather than copies of the sign
10684 : : bit from B. Furthermore, we need to use a logical right shift
10685 : : in this case.
10686 : :
10687 : : The choice of sign-extension versus zero-extension is
10688 : : determined entirely by whether or not B is signed and is
10689 : : independent of the current setting of unsignedp. */
10690 : :
10691 : 272190 : temp = NULL_RTX;
10692 : 272190 : if (code == LSHIFT_EXPR
10693 : 272190 : && target
10694 : 32347 : && REG_P (target)
10695 : 302027 : && GET_MODE_2XWIDER_MODE (word_mode).exists (&int_mode)
10696 : 29902 : && mode == int_mode
10697 : 1500 : && TREE_CONSTANT (treeop1)
10698 : 273020 : && TREE_CODE (treeop0) == SSA_NAME)
10699 : : {
10700 : 830 : gimple *def = SSA_NAME_DEF_STMT (treeop0);
10701 : 830 : if (is_gimple_assign (def)
10702 : 830 : && gimple_assign_rhs_code (def) == NOP_EXPR)
10703 : : {
10704 : 317 : scalar_int_mode rmode = SCALAR_INT_TYPE_MODE
10705 : : (TREE_TYPE (gimple_assign_rhs1 (def)));
10706 : :
10707 : 634 : if (GET_MODE_SIZE (rmode) < GET_MODE_SIZE (int_mode)
10708 : 588 : && TREE_INT_CST_LOW (treeop1) < GET_MODE_BITSIZE (word_mode)
10709 : 455 : && ((TREE_INT_CST_LOW (treeop1) + GET_MODE_BITSIZE (rmode))
10710 : 69 : >= GET_MODE_BITSIZE (word_mode)))
10711 : : {
10712 : 65 : rtx_insn *seq, *seq_old;
10713 : 65 : poly_uint64 high_off = subreg_highpart_offset (word_mode,
10714 : : int_mode);
10715 : 65 : bool extend_unsigned
10716 : 65 : = TYPE_UNSIGNED (TREE_TYPE (gimple_assign_rhs1 (def)));
10717 : 65 : rtx low = lowpart_subreg (word_mode, op0, int_mode);
10718 : 65 : rtx dest_low = lowpart_subreg (word_mode, target, int_mode);
10719 : 65 : rtx dest_high = simplify_gen_subreg (word_mode, target,
10720 : : int_mode, high_off);
10721 : 65 : HOST_WIDE_INT ramount = (BITS_PER_WORD
10722 : 65 : - TREE_INT_CST_LOW (treeop1));
10723 : 65 : tree rshift = build_int_cst (TREE_TYPE (treeop1), ramount);
10724 : :
10725 : 65 : start_sequence ();
10726 : : /* dest_high = src_low >> (word_size - C). */
10727 : 65 : temp = expand_variable_shift (RSHIFT_EXPR, word_mode, low,
10728 : : rshift, dest_high,
10729 : : extend_unsigned);
10730 : 65 : if (temp != dest_high)
10731 : 0 : emit_move_insn (dest_high, temp);
10732 : :
10733 : : /* dest_low = src_low << C. */
10734 : 65 : temp = expand_variable_shift (LSHIFT_EXPR, word_mode, low,
10735 : : treeop1, dest_low, unsignedp);
10736 : 65 : if (temp != dest_low)
10737 : 0 : emit_move_insn (dest_low, temp);
10738 : :
10739 : 65 : seq = get_insns ();
10740 : 65 : end_sequence ();
10741 : 65 : temp = target ;
10742 : :
10743 : 65 : if (have_insn_for (ASHIFT, int_mode))
10744 : : {
10745 : 65 : bool speed_p = optimize_insn_for_speed_p ();
10746 : 65 : start_sequence ();
10747 : 65 : rtx ret_old = expand_variable_shift (code, int_mode,
10748 : : op0, treeop1,
10749 : : target,
10750 : : unsignedp);
10751 : :
10752 : 65 : seq_old = get_insns ();
10753 : 65 : end_sequence ();
10754 : 130 : if (seq_cost (seq, speed_p)
10755 : 65 : >= seq_cost (seq_old, speed_p))
10756 : : {
10757 : 65 : seq = seq_old;
10758 : 65 : temp = ret_old;
10759 : : }
10760 : : }
10761 : 65 : emit_insn (seq);
10762 : : }
10763 : : }
10764 : : }
10765 : :
10766 : 65 : if (temp == NULL_RTX)
10767 : 272125 : temp = expand_variable_shift (code, mode, op0, treeop1, target,
10768 : : unsignedp);
10769 : 272190 : if (code == LSHIFT_EXPR)
10770 : 78558 : temp = REDUCE_BIT_FIELD (temp);
10771 : : return temp;
10772 : : }
10773 : :
10774 : : /* Could determine the answer when only additive constants differ. Also,
10775 : : the addition of one can be handled by changing the condition. */
10776 : 535735 : case LT_EXPR:
10777 : 535735 : case LE_EXPR:
10778 : 535735 : case GT_EXPR:
10779 : 535735 : case GE_EXPR:
10780 : 535735 : case EQ_EXPR:
10781 : 535735 : case NE_EXPR:
10782 : 535735 : case UNORDERED_EXPR:
10783 : 535735 : case ORDERED_EXPR:
10784 : 535735 : case UNLT_EXPR:
10785 : 535735 : case UNLE_EXPR:
10786 : 535735 : case UNGT_EXPR:
10787 : 535735 : case UNGE_EXPR:
10788 : 535735 : case UNEQ_EXPR:
10789 : 535735 : case LTGT_EXPR:
10790 : 535735 : {
10791 : 851532 : temp = do_store_flag (ops,
10792 : : modifier != EXPAND_STACK_PARM ? target : NULL_RTX,
10793 : : tmode != VOIDmode ? tmode : mode);
10794 : 535735 : if (temp)
10795 : : return temp;
10796 : :
10797 : : /* Use a compare and a jump for BLKmode comparisons, or for function
10798 : : type comparisons is have_canonicalize_funcptr_for_compare. */
10799 : :
10800 : 0 : if ((target == 0
10801 : 0 : || modifier == EXPAND_STACK_PARM
10802 : 0 : || ! safe_from_p (target, treeop0, 1)
10803 : 0 : || ! safe_from_p (target, treeop1, 1)
10804 : : /* Make sure we don't have a hard reg (such as function's return
10805 : : value) live across basic blocks, if not optimizing. */
10806 : 0 : || (!optimize && REG_P (target)
10807 : 0 : && REGNO (target) < FIRST_PSEUDO_REGISTER)))
10808 : 0 : target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
10809 : :
10810 : 0 : emit_move_insn (target, const0_rtx);
10811 : :
10812 : 0 : rtx_code_label *lab1 = gen_label_rtx ();
10813 : 0 : jumpifnot_1 (code, treeop0, treeop1, lab1,
10814 : : profile_probability::uninitialized ());
10815 : :
10816 : 0 : if (TYPE_PRECISION (type) == 1 && !TYPE_UNSIGNED (type))
10817 : 0 : emit_move_insn (target, constm1_rtx);
10818 : : else
10819 : 0 : emit_move_insn (target, const1_rtx);
10820 : :
10821 : 0 : emit_label (lab1);
10822 : 0 : return target;
10823 : : }
10824 : 54254 : case COMPLEX_EXPR:
10825 : : /* Get the rtx code of the operands. */
10826 : 54254 : op0 = expand_normal (treeop0);
10827 : 54254 : op1 = expand_normal (treeop1);
10828 : :
10829 : 54254 : if (!target)
10830 : 2693 : target = gen_reg_rtx (TYPE_MODE (type));
10831 : : else
10832 : : /* If target overlaps with op1, then either we need to force
10833 : : op1 into a pseudo (if target also overlaps with op0),
10834 : : or write the complex parts in reverse order. */
10835 : 51561 : switch (GET_CODE (target))
10836 : : {
10837 : 48884 : case CONCAT:
10838 : 48884 : if (reg_overlap_mentioned_p (XEXP (target, 0), op1))
10839 : : {
10840 : 0 : if (reg_overlap_mentioned_p (XEXP (target, 1), op0))
10841 : : {
10842 : 0 : complex_expr_force_op1:
10843 : 1718 : temp = gen_reg_rtx (GET_MODE_INNER (GET_MODE (target)));
10844 : 859 : emit_move_insn (temp, op1);
10845 : 859 : op1 = temp;
10846 : 859 : break;
10847 : : }
10848 : 0 : complex_expr_swap_order:
10849 : : /* Move the imaginary (op1) and real (op0) parts to their
10850 : : location. */
10851 : 1 : write_complex_part (target, op1, true, true);
10852 : 1 : write_complex_part (target, op0, false, false);
10853 : :
10854 : 1 : return target;
10855 : : }
10856 : : break;
10857 : 2677 : case MEM:
10858 : 5354 : temp = adjust_address_nv (target,
10859 : : GET_MODE_INNER (GET_MODE (target)), 0);
10860 : 2677 : if (reg_overlap_mentioned_p (temp, op1))
10861 : : {
10862 : 860 : scalar_mode imode = GET_MODE_INNER (GET_MODE (target));
10863 : 1720 : temp = adjust_address_nv (target, imode,
10864 : : GET_MODE_SIZE (imode));
10865 : 860 : if (reg_overlap_mentioned_p (temp, op0))
10866 : 859 : goto complex_expr_force_op1;
10867 : 1 : goto complex_expr_swap_order;
10868 : : }
10869 : : break;
10870 : 0 : default:
10871 : 0 : if (reg_overlap_mentioned_p (target, op1))
10872 : : {
10873 : 0 : if (reg_overlap_mentioned_p (target, op0))
10874 : 0 : goto complex_expr_force_op1;
10875 : 0 : goto complex_expr_swap_order;
10876 : : }
10877 : : break;
10878 : : }
10879 : :
10880 : : /* Move the real (op0) and imaginary (op1) parts to their location. */
10881 : 54253 : write_complex_part (target, op0, false, true);
10882 : 54253 : write_complex_part (target, op1, true, false);
10883 : :
10884 : 54253 : return target;
10885 : :
10886 : 0 : case WIDEN_SUM_EXPR:
10887 : 0 : {
10888 : 0 : tree oprnd0 = treeop0;
10889 : 0 : tree oprnd1 = treeop1;
10890 : :
10891 : 0 : expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
10892 : 0 : target = expand_widen_pattern_expr (ops, op0, NULL_RTX, op1,
10893 : : target, unsignedp);
10894 : 0 : return target;
10895 : : }
10896 : :
10897 : 15205 : case VEC_UNPACK_HI_EXPR:
10898 : 15205 : case VEC_UNPACK_LO_EXPR:
10899 : 15205 : case VEC_UNPACK_FIX_TRUNC_HI_EXPR:
10900 : 15205 : case VEC_UNPACK_FIX_TRUNC_LO_EXPR:
10901 : 15205 : {
10902 : 15205 : op0 = expand_normal (treeop0);
10903 : 15205 : temp = expand_widen_pattern_expr (ops, op0, NULL_RTX, NULL_RTX,
10904 : : target, unsignedp);
10905 : 15205 : gcc_assert (temp);
10906 : : return temp;
10907 : : }
10908 : :
10909 : 1746 : case VEC_UNPACK_FLOAT_HI_EXPR:
10910 : 1746 : case VEC_UNPACK_FLOAT_LO_EXPR:
10911 : 1746 : {
10912 : 1746 : op0 = expand_normal (treeop0);
10913 : : /* The signedness is determined from input operand. */
10914 : 1746 : temp = expand_widen_pattern_expr
10915 : 3492 : (ops, op0, NULL_RTX, NULL_RTX,
10916 : 1746 : target, TYPE_UNSIGNED (TREE_TYPE (treeop0)));
10917 : :
10918 : 1746 : gcc_assert (temp);
10919 : : return temp;
10920 : : }
10921 : :
10922 : 879 : case VEC_WIDEN_MULT_HI_EXPR:
10923 : 879 : case VEC_WIDEN_MULT_LO_EXPR:
10924 : 879 : case VEC_WIDEN_MULT_EVEN_EXPR:
10925 : 879 : case VEC_WIDEN_MULT_ODD_EXPR:
10926 : 879 : case VEC_WIDEN_LSHIFT_HI_EXPR:
10927 : 879 : case VEC_WIDEN_LSHIFT_LO_EXPR:
10928 : 879 : expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
10929 : 879 : target = expand_widen_pattern_expr (ops, op0, op1, NULL_RTX,
10930 : : target, unsignedp);
10931 : 879 : gcc_assert (target);
10932 : : return target;
10933 : :
10934 : 328 : case VEC_PACK_SAT_EXPR:
10935 : 328 : case VEC_PACK_FIX_TRUNC_EXPR:
10936 : 328 : mode = TYPE_MODE (TREE_TYPE (treeop0));
10937 : 328 : subtarget = NULL_RTX;
10938 : 328 : goto binop;
10939 : :
10940 : 9594 : case VEC_PACK_TRUNC_EXPR:
10941 : 9594 : if (VECTOR_BOOLEAN_TYPE_P (type)
10942 : 994 : && VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (treeop0))
10943 : 994 : && mode == TYPE_MODE (TREE_TYPE (treeop0))
10944 : 9794 : && SCALAR_INT_MODE_P (mode))
10945 : : {
10946 : 200 : class expand_operand eops[4];
10947 : 200 : machine_mode imode = TYPE_MODE (TREE_TYPE (treeop0));
10948 : 200 : expand_operands (treeop0, treeop1,
10949 : : subtarget, &op0, &op1, EXPAND_NORMAL);
10950 : 200 : this_optab = vec_pack_sbool_trunc_optab;
10951 : 200 : enum insn_code icode = optab_handler (this_optab, imode);
10952 : 200 : create_output_operand (&eops[0], target, mode);
10953 : 200 : create_convert_operand_from (&eops[1], op0, imode, false);
10954 : 200 : create_convert_operand_from (&eops[2], op1, imode, false);
10955 : 200 : temp = GEN_INT (TYPE_VECTOR_SUBPARTS (type).to_constant ());
10956 : 200 : create_input_operand (&eops[3], temp, imode);
10957 : 200 : expand_insn (icode, 4, eops);
10958 : 200 : return eops[0].value;
10959 : : }
10960 : 9394 : mode = TYPE_MODE (TREE_TYPE (treeop0));
10961 : 9394 : subtarget = NULL_RTX;
10962 : 9394 : goto binop;
10963 : :
10964 : 23 : case VEC_PACK_FLOAT_EXPR:
10965 : 23 : mode = TYPE_MODE (TREE_TYPE (treeop0));
10966 : 23 : expand_operands (treeop0, treeop1,
10967 : : subtarget, &op0, &op1, EXPAND_NORMAL);
10968 : 23 : this_optab = optab_for_tree_code (code, TREE_TYPE (treeop0),
10969 : : optab_default);
10970 : 69 : target = expand_binop (mode, this_optab, op0, op1, target,
10971 : 23 : TYPE_UNSIGNED (TREE_TYPE (treeop0)),
10972 : : OPTAB_LIB_WIDEN);
10973 : 23 : gcc_assert (target);
10974 : : return target;
10975 : :
10976 : 63690 : case VEC_PERM_EXPR:
10977 : 63690 : {
10978 : 63690 : expand_operands (treeop0, treeop1, target, &op0, &op1, EXPAND_NORMAL);
10979 : 63690 : vec_perm_builder sel;
10980 : 63690 : if (TREE_CODE (treeop2) == VECTOR_CST
10981 : 63690 : && tree_to_vec_perm_builder (&sel, treeop2))
10982 : : {
10983 : 63680 : machine_mode sel_mode = TYPE_MODE (TREE_TYPE (treeop2));
10984 : 63680 : temp = expand_vec_perm_const (mode, op0, op1, sel,
10985 : : sel_mode, target);
10986 : : }
10987 : : else
10988 : : {
10989 : 10 : op2 = expand_normal (treeop2);
10990 : 10 : temp = expand_vec_perm_var (mode, op0, op1, op2, target);
10991 : : }
10992 : 63690 : gcc_assert (temp);
10993 : 63690 : return temp;
10994 : 63690 : }
10995 : :
10996 : 230 : case DOT_PROD_EXPR:
10997 : 230 : {
10998 : 230 : tree oprnd0 = treeop0;
10999 : 230 : tree oprnd1 = treeop1;
11000 : 230 : tree oprnd2 = treeop2;
11001 : :
11002 : 230 : expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
11003 : 230 : op2 = expand_normal (oprnd2);
11004 : 230 : target = expand_widen_pattern_expr (ops, op0, op1, op2,
11005 : : target, unsignedp);
11006 : 230 : return target;
11007 : : }
11008 : :
11009 : 108 : case SAD_EXPR:
11010 : 108 : {
11011 : 108 : tree oprnd0 = treeop0;
11012 : 108 : tree oprnd1 = treeop1;
11013 : 108 : tree oprnd2 = treeop2;
11014 : :
11015 : 108 : expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
11016 : 108 : op2 = expand_normal (oprnd2);
11017 : 108 : target = expand_widen_pattern_expr (ops, op0, op1, op2,
11018 : : target, unsignedp);
11019 : 108 : return target;
11020 : : }
11021 : :
11022 : 0 : case REALIGN_LOAD_EXPR:
11023 : 0 : {
11024 : 0 : tree oprnd0 = treeop0;
11025 : 0 : tree oprnd1 = treeop1;
11026 : 0 : tree oprnd2 = treeop2;
11027 : :
11028 : 0 : this_optab = optab_for_tree_code (code, type, optab_default);
11029 : 0 : expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
11030 : 0 : op2 = expand_normal (oprnd2);
11031 : 0 : temp = expand_ternary_op (mode, this_optab, op0, op1, op2,
11032 : : target, unsignedp);
11033 : 0 : gcc_assert (temp);
11034 : : return temp;
11035 : : }
11036 : :
11037 : 17054 : case COND_EXPR:
11038 : 17054 : {
11039 : : /* A COND_EXPR with its type being VOID_TYPE represents a
11040 : : conditional jump and is handled in
11041 : : expand_gimple_cond_expr. */
11042 : 17054 : gcc_assert (!VOID_TYPE_P (type));
11043 : :
11044 : : /* Note that COND_EXPRs whose type is a structure or union
11045 : : are required to be constructed to contain assignments of
11046 : : a temporary variable, so that we can evaluate them here
11047 : : for side effect only. If type is void, we must do likewise. */
11048 : :
11049 : 17054 : gcc_assert (!TREE_ADDRESSABLE (type)
11050 : : && !ignore
11051 : : && TREE_TYPE (treeop1) != void_type_node
11052 : : && TREE_TYPE (treeop2) != void_type_node);
11053 : :
11054 : 17054 : temp = expand_cond_expr_using_cmove (treeop0, treeop1, treeop2);
11055 : 17054 : if (temp)
11056 : : return temp;
11057 : :
11058 : : /* If we are not to produce a result, we have no target. Otherwise,
11059 : : if a target was specified use it; it will not be used as an
11060 : : intermediate target unless it is safe. If no target, use a
11061 : : temporary. */
11062 : :
11063 : 3534 : if (modifier != EXPAND_STACK_PARM
11064 : 3534 : && original_target
11065 : 1954 : && safe_from_p (original_target, treeop0, 1)
11066 : 0 : && GET_MODE (original_target) == mode
11067 : 3534 : && !MEM_P (original_target))
11068 : : temp = original_target;
11069 : : else
11070 : 3534 : temp = assign_temp (type, 0, 1);
11071 : :
11072 : 3534 : do_pending_stack_adjust ();
11073 : 3534 : NO_DEFER_POP;
11074 : 3534 : rtx_code_label *lab0 = gen_label_rtx ();
11075 : 3534 : rtx_code_label *lab1 = gen_label_rtx ();
11076 : 3534 : jumpifnot (treeop0, lab0,
11077 : : profile_probability::uninitialized ());
11078 : 3534 : store_expr (treeop1, temp,
11079 : : modifier == EXPAND_STACK_PARM,
11080 : : false, false);
11081 : :
11082 : 3534 : emit_jump_insn (targetm.gen_jump (lab1));
11083 : 3534 : emit_barrier ();
11084 : 3534 : emit_label (lab0);
11085 : 3534 : store_expr (treeop2, temp,
11086 : : modifier == EXPAND_STACK_PARM,
11087 : : false, false);
11088 : :
11089 : 3534 : emit_label (lab1);
11090 : 3534 : OK_DEFER_POP;
11091 : 3534 : return temp;
11092 : : }
11093 : :
11094 : 0 : case VEC_DUPLICATE_EXPR:
11095 : 0 : op0 = expand_expr (treeop0, NULL_RTX, VOIDmode, modifier);
11096 : 0 : target = expand_vector_broadcast (mode, op0);
11097 : 0 : gcc_assert (target);
11098 : : return target;
11099 : :
11100 : 0 : case VEC_SERIES_EXPR:
11101 : 0 : expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, modifier);
11102 : 0 : return expand_vec_series_expr (mode, op0, op1, target);
11103 : :
11104 : 983 : case BIT_INSERT_EXPR:
11105 : 983 : {
11106 : 983 : unsigned bitpos = tree_to_uhwi (treeop2);
11107 : 983 : unsigned bitsize;
11108 : 983 : if (INTEGRAL_TYPE_P (TREE_TYPE (treeop1)))
11109 : 642 : bitsize = TYPE_PRECISION (TREE_TYPE (treeop1));
11110 : : else
11111 : 341 : bitsize = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (treeop1)));
11112 : 983 : op0 = expand_normal (treeop0);
11113 : 983 : op1 = expand_normal (treeop1);
11114 : 983 : rtx dst = gen_reg_rtx (mode);
11115 : 983 : emit_move_insn (dst, op0);
11116 : 983 : store_bit_field (dst, bitsize, bitpos, 0, 0,
11117 : 983 : TYPE_MODE (TREE_TYPE (treeop1)), op1, false, false);
11118 : 983 : return dst;
11119 : : }
11120 : :
11121 : 0 : default:
11122 : 0 : gcc_unreachable ();
11123 : : }
11124 : :
11125 : : /* Here to do an ordinary binary operator. */
11126 : 1159892 : binop:
11127 : 1159892 : expand_operands (treeop0, treeop1,
11128 : : subtarget, &op0, &op1, EXPAND_NORMAL);
11129 : 5435432 : binop2:
11130 : 5435432 : this_optab = optab_for_tree_code (code, type, optab_default);
11131 : 5435432 : binop3:
11132 : 5435432 : if (modifier == EXPAND_STACK_PARM)
11133 : 24843 : target = 0;
11134 : 5435432 : temp = expand_binop (mode, this_optab, op0, op1, target,
11135 : : unsignedp, OPTAB_LIB_WIDEN);
11136 : 5435432 : gcc_assert (temp);
11137 : : /* Bitwise operations do not need bitfield reduction as we expect their
11138 : : operands being properly truncated. */
11139 : 5435432 : if (code == BIT_XOR_EXPR
11140 : : || code == BIT_AND_EXPR
11141 : 5435432 : || code == BIT_IOR_EXPR)
11142 : : return temp;
11143 : 4813807 : return REDUCE_BIT_FIELD (temp);
11144 : : }
11145 : : #undef REDUCE_BIT_FIELD
11146 : :
11147 : :
11148 : : /* Return TRUE if expression STMT is suitable for replacement.
11149 : : Never consider memory loads as replaceable, because those don't ever lead
11150 : : into constant expressions. */
11151 : :
11152 : : static bool
11153 : 8 : stmt_is_replaceable_p (gimple *stmt)
11154 : : {
11155 : 8 : if (ssa_is_replaceable_p (stmt))
11156 : : {
11157 : : /* Don't move around loads. */
11158 : 7 : if (!gimple_assign_single_p (stmt)
11159 : 7 : || is_gimple_val (gimple_assign_rhs1 (stmt)))
11160 : 6 : return true;
11161 : : }
11162 : : return false;
11163 : : }
11164 : :
11165 : : /* A subroutine of expand_expr_real_1. Expand gimple assignment G,
11166 : : which is known to set an SSA_NAME result. The other arguments are
11167 : : as for expand_expr_real_1. */
11168 : :
11169 : : rtx
11170 : 14280541 : expand_expr_real_gassign (gassign *g, rtx target, machine_mode tmode,
11171 : : enum expand_modifier modifier, rtx *alt_rtl,
11172 : : bool inner_reference_p)
11173 : : {
11174 : 14280541 : separate_ops ops;
11175 : 14280541 : rtx r;
11176 : 14280541 : location_t saved_loc = curr_insn_location ();
11177 : 14280541 : auto loc = gimple_location (g);
11178 : 14280541 : if (loc != UNKNOWN_LOCATION)
11179 : 11402753 : set_curr_insn_location (loc);
11180 : 14280541 : tree lhs = gimple_assign_lhs (g);
11181 : 14280541 : ops.code = gimple_assign_rhs_code (g);
11182 : 14280541 : ops.type = TREE_TYPE (lhs);
11183 : 14280541 : switch (get_gimple_rhs_class (ops.code))
11184 : : {
11185 : 82022 : case GIMPLE_TERNARY_RHS:
11186 : 164044 : ops.op2 = gimple_assign_rhs3 (g);
11187 : : /* Fallthru */
11188 : 7573253 : case GIMPLE_BINARY_RHS:
11189 : 7573253 : ops.op1 = gimple_assign_rhs2 (g);
11190 : :
11191 : : /* Try to expand conditonal compare. */
11192 : 7573253 : if (targetm.have_ccmp ())
11193 : : {
11194 : 1016 : gcc_checking_assert (targetm.gen_ccmp_next != NULL);
11195 : 1016 : r = expand_ccmp_expr (g, TYPE_MODE (ops.type));
11196 : 1016 : if (r)
11197 : : break;
11198 : : }
11199 : : /* Fallthru */
11200 : 10932743 : case GIMPLE_UNARY_RHS:
11201 : 10932743 : ops.op0 = gimple_assign_rhs1 (g);
11202 : 10932743 : ops.location = loc;
11203 : 10932743 : r = expand_expr_real_2 (&ops, target, tmode, modifier);
11204 : 10932743 : break;
11205 : 3347780 : case GIMPLE_SINGLE_RHS:
11206 : 3347780 : {
11207 : 3347780 : r = expand_expr_real (gimple_assign_rhs1 (g), target,
11208 : : tmode, modifier, alt_rtl,
11209 : : inner_reference_p);
11210 : 3347780 : break;
11211 : : }
11212 : 0 : default:
11213 : 0 : gcc_unreachable ();
11214 : : }
11215 : 14280541 : set_curr_insn_location (saved_loc);
11216 : 14280541 : if (REG_P (r) && !REG_EXPR (r))
11217 : 3611579 : set_reg_attrs_for_decl_rtl (lhs, r);
11218 : 14280541 : return r;
11219 : : }
11220 : :
11221 : : rtx
11222 : 151842861 : expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
11223 : : enum expand_modifier modifier, rtx *alt_rtl,
11224 : : bool inner_reference_p)
11225 : : {
11226 : 151842861 : rtx op0, op1, temp, decl_rtl;
11227 : 151842861 : tree type;
11228 : 151842861 : int unsignedp;
11229 : 151842861 : machine_mode mode, dmode;
11230 : 151842861 : enum tree_code code = TREE_CODE (exp);
11231 : 151842861 : rtx subtarget, original_target;
11232 : 151842861 : int ignore;
11233 : 151842861 : bool reduce_bit_field;
11234 : 151842861 : location_t loc = EXPR_LOCATION (exp);
11235 : 151842861 : struct separate_ops ops;
11236 : 151842861 : tree treeop0, treeop1, treeop2;
11237 : 151842861 : tree ssa_name = NULL_TREE;
11238 : 151842861 : gimple *g;
11239 : :
11240 : : /* Some ABIs define padding bits in _BitInt uninitialized. Normally, RTL
11241 : : expansion sign/zero extends integral types with less than mode precision
11242 : : when reading from bit-fields and after arithmetic operations (see
11243 : : REDUCE_BIT_FIELD in expand_expr_real_2) and on subsequent loads relies
11244 : : on those extensions to have been already performed, but because of the
11245 : : above for _BitInt they need to be sign/zero extended when reading from
11246 : : locations that could be exposed to ABI boundaries (when loading from
11247 : : objects in memory, or function arguments, return value). Because we
11248 : : internally extend after arithmetic operations, we can avoid doing that
11249 : : when reading from SSA_NAMEs of vars. */
11250 : : #define EXTEND_BITINT(expr) \
11251 : : ((TREE_CODE (type) == BITINT_TYPE \
11252 : : && reduce_bit_field \
11253 : : && mode != BLKmode \
11254 : : && modifier != EXPAND_MEMORY \
11255 : : && modifier != EXPAND_WRITE \
11256 : : && modifier != EXPAND_INITIALIZER \
11257 : : && modifier != EXPAND_CONST_ADDRESS) \
11258 : : ? reduce_to_bit_field_precision ((expr), NULL_RTX, type) : (expr))
11259 : :
11260 : 151842861 : type = TREE_TYPE (exp);
11261 : 151842861 : mode = TYPE_MODE (type);
11262 : 151842861 : unsignedp = TYPE_UNSIGNED (type);
11263 : :
11264 : 151842861 : treeop0 = treeop1 = treeop2 = NULL_TREE;
11265 : 151842861 : if (!VL_EXP_CLASS_P (exp))
11266 : 145329800 : switch (TREE_CODE_LENGTH (code))
11267 : : {
11268 : 5426471 : default:
11269 : 5426471 : case 3: treeop2 = TREE_OPERAND (exp, 2); /* FALLTHRU */
11270 : 13109823 : case 2: treeop1 = TREE_OPERAND (exp, 1); /* FALLTHRU */
11271 : 27234948 : case 1: treeop0 = TREE_OPERAND (exp, 0); /* FALLTHRU */
11272 : : case 0: break;
11273 : : }
11274 : 151842861 : ops.code = code;
11275 : 151842861 : ops.type = type;
11276 : 151842861 : ops.op0 = treeop0;
11277 : 151842861 : ops.op1 = treeop1;
11278 : 151842861 : ops.op2 = treeop2;
11279 : 151842861 : ops.location = loc;
11280 : :
11281 : 303685722 : ignore = (target == const0_rtx
11282 : 151842861 : || ((CONVERT_EXPR_CODE_P (code)
11283 : 146987533 : || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
11284 : 927513 : && TREE_CODE (type) == VOID_TYPE));
11285 : :
11286 : : /* An operation in what may be a bit-field type needs the
11287 : : result to be reduced to the precision of the bit-field type,
11288 : : which is narrower than that of the type's mode. */
11289 : 303685504 : reduce_bit_field = (!ignore
11290 : 147570755 : && INTEGRAL_TYPE_P (type)
11291 : 77015455 : && !type_has_mode_precision_p (type));
11292 : :
11293 : : /* If we are going to ignore this result, we need only do something
11294 : : if there is a side-effect somewhere in the expression. If there
11295 : : is, short-circuit the most common cases here. Note that we must
11296 : : not call expand_expr with anything but const0_rtx in case this
11297 : : is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
11298 : :
11299 : 4272106 : if (ignore)
11300 : : {
11301 : 4272106 : if (! TREE_SIDE_EFFECTS (exp))
11302 : : return const0_rtx;
11303 : :
11304 : : /* Ensure we reference a volatile object even if value is ignored, but
11305 : : don't do this if all we are doing is taking its address. */
11306 : 4271888 : if (TREE_THIS_VOLATILE (exp)
11307 : 0 : && TREE_CODE (exp) != FUNCTION_DECL
11308 : 0 : && mode != VOIDmode && mode != BLKmode
11309 : 0 : && modifier != EXPAND_CONST_ADDRESS)
11310 : : {
11311 : 0 : temp = expand_expr (exp, NULL_RTX, VOIDmode, modifier);
11312 : 0 : if (MEM_P (temp))
11313 : 0 : copy_to_reg (temp);
11314 : 0 : return const0_rtx;
11315 : : }
11316 : :
11317 : 4271888 : if (TREE_CODE_CLASS (code) == tcc_unary
11318 : : || code == BIT_FIELD_REF
11319 : 4271888 : || code == COMPONENT_REF
11320 : 4271888 : || code == INDIRECT_REF)
11321 : 0 : return expand_expr (treeop0, const0_rtx, VOIDmode,
11322 : 0 : modifier);
11323 : :
11324 : 4271888 : else if (TREE_CODE_CLASS (code) == tcc_binary
11325 : 4271888 : || TREE_CODE_CLASS (code) == tcc_comparison
11326 : 4271888 : || code == ARRAY_REF || code == ARRAY_RANGE_REF)
11327 : : {
11328 : 0 : expand_expr (treeop0, const0_rtx, VOIDmode, modifier);
11329 : 0 : expand_expr (treeop1, const0_rtx, VOIDmode, modifier);
11330 : 0 : return const0_rtx;
11331 : : }
11332 : :
11333 : : target = 0;
11334 : : }
11335 : :
11336 : 151842643 : if (reduce_bit_field && modifier == EXPAND_STACK_PARM)
11337 : 37283 : target = 0;
11338 : :
11339 : : /* Use subtarget as the target for operand 0 of a binary operation. */
11340 : 151842643 : subtarget = get_subtarget (target);
11341 : 151842643 : original_target = target;
11342 : :
11343 : 151842643 : switch (code)
11344 : : {
11345 : 10811 : case LABEL_DECL:
11346 : 10811 : {
11347 : 10811 : tree function = decl_function_context (exp);
11348 : :
11349 : 10811 : temp = label_rtx (exp);
11350 : 10811 : temp = gen_rtx_LABEL_REF (Pmode, temp);
11351 : :
11352 : 10811 : if (function != current_function_decl
11353 : 1263 : && function != 0)
11354 : 1263 : LABEL_REF_NONLOCAL_P (temp) = 1;
11355 : :
11356 : 10811 : temp = gen_rtx_MEM (FUNCTION_MODE, temp);
11357 : 10811 : return temp;
11358 : : }
11359 : :
11360 : 54301153 : case SSA_NAME:
11361 : : /* ??? ivopts calls expander, without any preparation from
11362 : : out-of-ssa. So fake instructions as if this was an access to the
11363 : : base variable. This unnecessarily allocates a pseudo, see how we can
11364 : : reuse it, if partition base vars have it set already. */
11365 : 54301153 : if (!currently_expanding_to_rtl)
11366 : : {
11367 : 0 : tree var = SSA_NAME_VAR (exp);
11368 : 0 : if (var && DECL_RTL_SET_P (var))
11369 : 0 : return DECL_RTL (var);
11370 : 0 : return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp)),
11371 : 0 : LAST_VIRTUAL_REGISTER + 1);
11372 : : }
11373 : :
11374 : 54301153 : g = get_gimple_for_ssa_name (exp);
11375 : : /* For EXPAND_INITIALIZER try harder to get something simpler. */
11376 : 54301153 : if (g == NULL
11377 : 54301153 : && modifier == EXPAND_INITIALIZER
11378 : 26 : && !SSA_NAME_IS_DEFAULT_DEF (exp)
11379 : 11 : && (optimize || !SSA_NAME_VAR (exp)
11380 : 1 : || DECL_IGNORED_P (SSA_NAME_VAR (exp)))
11381 : 10 : && is_gimple_assign (SSA_NAME_DEF_STMT (exp))
11382 : 54301161 : && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp)))
11383 : 6 : g = SSA_NAME_DEF_STMT (exp);
11384 : 54301153 : if (safe_is_a <gassign *> (g))
11385 : 8565358 : return expand_expr_real_gassign (as_a<gassign *> (g), target, tmode,
11386 : 8565358 : modifier, alt_rtl, inner_reference_p);
11387 : 45735795 : else if (safe_is_a <gcall *> (g))
11388 : : {
11389 : : /* ??? internal call expansion doesn't follow the usual API
11390 : : of returning the destination RTX and being passed a desired
11391 : : target. */
11392 : 32812 : rtx dest = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
11393 : 32812 : tree tmplhs = make_tree (TREE_TYPE (exp), dest);
11394 : 32812 : gimple_call_set_lhs (g, tmplhs);
11395 : 32812 : expand_internal_call (as_a <gcall *> (g));
11396 : 32812 : gimple_call_set_lhs (g, exp);
11397 : 32812 : return dest;
11398 : : }
11399 : :
11400 : 45702983 : ssa_name = exp;
11401 : 45702983 : decl_rtl = get_rtx_for_ssa_name (ssa_name);
11402 : 45702983 : exp = SSA_NAME_VAR (ssa_name);
11403 : : /* Optimize and avoid to EXTEND_BITINIT doing anything if it is an
11404 : : SSA_NAME computed within the current function. In such case the
11405 : : value have been already extended before. While if it is a function
11406 : : parameter, result or some memory location, we need to be prepared
11407 : : for some other compiler leaving the bits uninitialized. */
11408 : 18007463 : if (!exp || VAR_P (exp))
11409 : : reduce_bit_field = false;
11410 : 45702983 : goto expand_decl_rtl;
11411 : :
11412 : 19383449 : case VAR_DECL:
11413 : : /* Allow accel compiler to handle variables that require special
11414 : : treatment, e.g. if they have been modified in some way earlier in
11415 : : compilation by the adjust_private_decl OpenACC hook. */
11416 : 19383449 : if (flag_openacc && targetm.goacc.expand_var_decl)
11417 : : {
11418 : 0 : temp = targetm.goacc.expand_var_decl (exp);
11419 : 0 : if (temp)
11420 : : return temp;
11421 : : }
11422 : : /* Expand const VAR_DECLs with CONSTRUCTOR initializers that
11423 : : have scalar integer modes to a reg via store_constructor. */
11424 : 19383449 : if (TREE_READONLY (exp)
11425 : 3349819 : && !TREE_SIDE_EFFECTS (exp)
11426 : 3327406 : && (modifier == EXPAND_NORMAL || modifier == EXPAND_STACK_PARM)
11427 : 17208 : && immediate_const_ctor_p (DECL_INITIAL (exp))
11428 : 131 : && SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (exp)))
11429 : 99 : && crtl->emit.regno_pointer_align_length
11430 : 19383548 : && !target)
11431 : : {
11432 : 73 : target = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
11433 : 73 : store_constructor (DECL_INITIAL (exp), target, 0,
11434 : 73 : int_expr_size (DECL_INITIAL (exp)), false);
11435 : 73 : return target;
11436 : : }
11437 : : /* ... fall through ... */
11438 : :
11439 : 19926064 : case PARM_DECL:
11440 : : /* If a static var's type was incomplete when the decl was written,
11441 : : but the type is complete now, lay out the decl now. */
11442 : 19926064 : if (DECL_SIZE (exp) == 0
11443 : 43527 : && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp))
11444 : 19969482 : && (TREE_STATIC (exp) || DECL_EXTERNAL (exp)))
11445 : 43418 : layout_decl (exp, 0);
11446 : :
11447 : : /* fall through */
11448 : :
11449 : 21338202 : case FUNCTION_DECL:
11450 : 21338202 : case RESULT_DECL:
11451 : 21338202 : decl_rtl = DECL_RTL (exp);
11452 : 67041185 : expand_decl_rtl:
11453 : 67041185 : gcc_assert (decl_rtl);
11454 : :
11455 : : /* DECL_MODE might change when TYPE_MODE depends on attribute target
11456 : : settings for VECTOR_TYPE_P that might switch for the function. */
11457 : 67041185 : if (currently_expanding_to_rtl
11458 : 63394451 : && code == VAR_DECL && MEM_P (decl_rtl)
11459 : 81428116 : && VECTOR_TYPE_P (type) && exp && DECL_MODE (exp) != mode)
11460 : 57 : decl_rtl = change_address (decl_rtl, TYPE_MODE (type), 0);
11461 : : else
11462 : 67041128 : decl_rtl = copy_rtx (decl_rtl);
11463 : :
11464 : : /* Record writes to register variables. */
11465 : 67041185 : if (modifier == EXPAND_WRITE
11466 : 21145063 : && REG_P (decl_rtl)
11467 : 82578870 : && HARD_REGISTER_P (decl_rtl))
11468 : 2028 : add_to_hard_reg_set (&crtl->asm_clobbers,
11469 : 2028 : GET_MODE (decl_rtl), REGNO (decl_rtl));
11470 : :
11471 : : /* Ensure variable marked as used even if it doesn't go through
11472 : : a parser. If it hasn't be used yet, write out an external
11473 : : definition. */
11474 : 67041185 : if (exp)
11475 : 39345665 : TREE_USED (exp) = 1;
11476 : :
11477 : : /* Show we haven't gotten RTL for this yet. */
11478 : 106386850 : temp = 0;
11479 : :
11480 : : /* Variables inherited from containing functions should have
11481 : : been lowered by this point. */
11482 : 39345665 : if (exp)
11483 : : {
11484 : 39345665 : tree context = decl_function_context (exp);
11485 : 39345665 : gcc_assert (SCOPE_FILE_SCOPE_P (context)
11486 : : || context == current_function_decl
11487 : : || TREE_STATIC (exp)
11488 : : || DECL_EXTERNAL (exp)
11489 : : /* ??? C++ creates functions that are not
11490 : : TREE_STATIC. */
11491 : : || TREE_CODE (exp) == FUNCTION_DECL);
11492 : : }
11493 : :
11494 : : /* This is the case of an array whose size is to be determined
11495 : : from its initializer, while the initializer is still being parsed.
11496 : : ??? We aren't parsing while expanding anymore. */
11497 : :
11498 : 67041185 : if (MEM_P (decl_rtl) && REG_P (XEXP (decl_rtl, 0)))
11499 : 382811 : temp = validize_mem (decl_rtl);
11500 : :
11501 : : /* If DECL_RTL is memory, we are in the normal case and the
11502 : : address is not valid, get the address into a register. */
11503 : :
11504 : 66658374 : else if (MEM_P (decl_rtl) && modifier != EXPAND_INITIALIZER)
11505 : : {
11506 : 18261655 : if (alt_rtl)
11507 : 2046439 : *alt_rtl = decl_rtl;
11508 : 18261655 : decl_rtl = use_anchored_address (decl_rtl);
11509 : 18261655 : if (modifier != EXPAND_CONST_ADDRESS
11510 : 18261655 : && modifier != EXPAND_SUM
11511 : 30257151 : && !memory_address_addr_space_p (exp ? DECL_MODE (exp)
11512 : 17012 : : GET_MODE (decl_rtl),
11513 : : XEXP (decl_rtl, 0),
11514 : 11995496 : MEM_ADDR_SPACE (decl_rtl)))
11515 : 133882 : temp = replace_equiv_address (decl_rtl,
11516 : : copy_rtx (XEXP (decl_rtl, 0)));
11517 : : }
11518 : :
11519 : : /* If we got something, return it. But first, set the alignment
11520 : : if the address is a register. */
11521 : 18644466 : if (temp != 0)
11522 : : {
11523 : 516693 : if (exp && MEM_P (temp) && REG_P (XEXP (temp, 0)))
11524 : 486875 : mark_reg_pointer (XEXP (temp, 0), DECL_ALIGN (exp));
11525 : : }
11526 : 66524492 : else if (MEM_P (decl_rtl))
11527 : : temp = decl_rtl;
11528 : :
11529 : 45394918 : if (temp != 0)
11530 : : {
11531 : 22133152 : if (MEM_P (temp)
11532 : : && modifier != EXPAND_WRITE
11533 : 22133152 : && modifier != EXPAND_MEMORY
11534 : : && modifier != EXPAND_INITIALIZER
11535 : 16442311 : && modifier != EXPAND_CONST_ADDRESS
11536 : 6821202 : && modifier != EXPAND_SUM
11537 : 6821202 : && !inner_reference_p
11538 : 4462074 : && mode != BLKmode
11539 : 26224654 : && MEM_ALIGN (temp) < GET_MODE_ALIGNMENT (mode))
11540 : 18496 : temp = expand_misaligned_mem_ref (temp, mode, unsignedp,
11541 : 18496 : MEM_ALIGN (temp), NULL_RTX, NULL);
11542 : :
11543 : 22133152 : return EXTEND_BITINT (temp);
11544 : : }
11545 : :
11546 : 44908033 : if (exp)
11547 : 17229535 : dmode = DECL_MODE (exp);
11548 : : else
11549 : 27678498 : dmode = TYPE_MODE (TREE_TYPE (ssa_name));
11550 : :
11551 : : /* If the mode of DECL_RTL does not match that of the decl,
11552 : : there are two cases: we are dealing with a BLKmode value
11553 : : that is returned in a register, or we are dealing with
11554 : : a promoted value. In the latter case, return a SUBREG
11555 : : of the wanted mode, but mark it so that we know that it
11556 : : was already extended. */
11557 : 44908033 : if (REG_P (decl_rtl)
11558 : 44432756 : && dmode != BLKmode
11559 : 44432756 : && GET_MODE (decl_rtl) != dmode)
11560 : : {
11561 : 70 : machine_mode pmode;
11562 : :
11563 : : /* Get the signedness to be used for this variable. Ensure we get
11564 : : the same mode we got when the variable was declared. */
11565 : 70 : if (code != SSA_NAME)
11566 : 0 : pmode = promote_decl_mode (exp, &unsignedp);
11567 : 70 : else if ((g = SSA_NAME_DEF_STMT (ssa_name))
11568 : 70 : && gimple_code (g) == GIMPLE_CALL
11569 : 72 : && !gimple_call_internal_p (g))
11570 : 2 : pmode = promote_function_mode (type, mode, &unsignedp,
11571 : 2 : gimple_call_fntype (g),
11572 : : 2);
11573 : : else
11574 : 68 : pmode = promote_ssa_mode (ssa_name, &unsignedp);
11575 : 70 : gcc_assert (GET_MODE (decl_rtl) == pmode);
11576 : :
11577 : : /* Some ABIs require scalar floating point modes to be passed
11578 : : in a wider scalar integer mode. We need to explicitly
11579 : : truncate to an integer mode of the correct precision before
11580 : : using a SUBREG to reinterpret as a floating point value. */
11581 : 70 : if (SCALAR_FLOAT_MODE_P (mode)
11582 : 0 : && SCALAR_INT_MODE_P (pmode)
11583 : 70 : && known_lt (GET_MODE_SIZE (mode), GET_MODE_SIZE (pmode)))
11584 : 0 : return convert_wider_int_to_float (mode, pmode, decl_rtl);
11585 : :
11586 : 70 : temp = gen_lowpart_SUBREG (mode, decl_rtl);
11587 : 70 : SUBREG_PROMOTED_VAR_P (temp) = 1;
11588 : 70 : SUBREG_PROMOTED_SET (temp, unsignedp);
11589 : 70 : return EXTEND_BITINT (temp);
11590 : : }
11591 : :
11592 : 44907963 : return EXTEND_BITINT (decl_rtl);
11593 : :
11594 : 40672159 : case INTEGER_CST:
11595 : 40672159 : {
11596 : 40672159 : if (TREE_CODE (type) == BITINT_TYPE)
11597 : : {
11598 : 10305 : unsigned int prec = TYPE_PRECISION (type);
11599 : 10305 : struct bitint_info info;
11600 : 10305 : bool ok = targetm.c.bitint_type_info (prec, &info);
11601 : 10305 : gcc_assert (ok);
11602 : 10305 : scalar_int_mode limb_mode
11603 : 10305 : = as_a <scalar_int_mode> (info.limb_mode);
11604 : 10305 : unsigned int limb_prec = GET_MODE_PRECISION (limb_mode);
11605 : 17025 : if (prec > limb_prec && prec > MAX_FIXED_MODE_SIZE)
11606 : : {
11607 : : /* Emit large/huge _BitInt INTEGER_CSTs into memory. */
11608 : 4277 : exp = tree_output_constant_def (exp);
11609 : 4277 : return expand_expr (exp, target, VOIDmode, modifier);
11610 : : }
11611 : : }
11612 : :
11613 : : /* Given that TYPE_PRECISION (type) is not always equal to
11614 : : GET_MODE_PRECISION (TYPE_MODE (type)), we need to extend from
11615 : : the former to the latter according to the signedness of the
11616 : : type. */
11617 : 40667882 : scalar_int_mode int_mode = SCALAR_INT_TYPE_MODE (type);
11618 : 40667882 : temp = immed_wide_int_const
11619 : 40667882 : (wi::to_wide (exp, GET_MODE_PRECISION (int_mode)), int_mode);
11620 : 40667882 : return temp;
11621 : : }
11622 : :
11623 : 534490 : case VECTOR_CST:
11624 : 534490 : {
11625 : 534490 : tree tmp = NULL_TREE;
11626 : 534490 : if (VECTOR_MODE_P (mode))
11627 : 532640 : return const_vector_from_tree (exp);
11628 : 1850 : scalar_int_mode int_mode;
11629 : 1850 : if (is_int_mode (mode, &int_mode))
11630 : : {
11631 : 183 : tree type_for_mode = lang_hooks.types.type_for_mode (int_mode, 1);
11632 : 183 : if (type_for_mode)
11633 : 183 : tmp = fold_unary_loc (loc, VIEW_CONVERT_EXPR,
11634 : : type_for_mode, exp);
11635 : : }
11636 : 183 : if (!tmp)
11637 : : {
11638 : 1667 : vec<constructor_elt, va_gc> *v;
11639 : : /* Constructors need to be fixed-length. FIXME. */
11640 : 1667 : unsigned int nunits = VECTOR_CST_NELTS (exp).to_constant ();
11641 : 1667 : vec_alloc (v, nunits);
11642 : 24044 : for (unsigned int i = 0; i < nunits; ++i)
11643 : 22377 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, VECTOR_CST_ELT (exp, i));
11644 : 1667 : tmp = build_constructor (type, v);
11645 : : }
11646 : 1850 : return expand_expr (tmp, ignore ? const0_rtx : target,
11647 : 1850 : tmode, modifier);
11648 : : }
11649 : :
11650 : 128 : case CONST_DECL:
11651 : 128 : if (modifier == EXPAND_WRITE)
11652 : : {
11653 : : /* Writing into CONST_DECL is always invalid, but handle it
11654 : : gracefully. */
11655 : 2 : addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (exp));
11656 : 2 : scalar_int_mode address_mode = targetm.addr_space.address_mode (as);
11657 : 2 : op0 = expand_expr_addr_expr_1 (exp, NULL_RTX, address_mode,
11658 : : EXPAND_NORMAL, as);
11659 : 2 : op0 = memory_address_addr_space (mode, op0, as);
11660 : 2 : temp = gen_rtx_MEM (mode, op0);
11661 : 2 : set_mem_addr_space (temp, as);
11662 : 2 : return temp;
11663 : : }
11664 : 126 : return expand_expr (DECL_INITIAL (exp), target, VOIDmode, modifier);
11665 : :
11666 : 863686 : case REAL_CST:
11667 : : /* If optimized, generate immediate CONST_DOUBLE
11668 : : which will be turned into memory by reload if necessary.
11669 : :
11670 : : We used to force a register so that loop.c could see it. But
11671 : : this does not allow gen_* patterns to perform optimizations with
11672 : : the constants. It also produces two insns in cases like "x = 1.0;".
11673 : : On most machines, floating-point constants are not permitted in
11674 : : many insns, so we'd end up copying it to a register in any case.
11675 : :
11676 : : Now, we do the copying in expand_binop, if appropriate. */
11677 : 863686 : return const_double_from_real_value (TREE_REAL_CST (exp),
11678 : 1727372 : TYPE_MODE (TREE_TYPE (exp)));
11679 : :
11680 : 0 : case FIXED_CST:
11681 : 0 : return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp),
11682 : : TYPE_MODE (TREE_TYPE (exp)));
11683 : :
11684 : 18349 : case COMPLEX_CST:
11685 : : /* Handle evaluating a complex constant in a CONCAT target. */
11686 : 18349 : if (original_target && GET_CODE (original_target) == CONCAT)
11687 : : {
11688 : 221 : rtx rtarg, itarg;
11689 : :
11690 : 221 : mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
11691 : 221 : rtarg = XEXP (original_target, 0);
11692 : 221 : itarg = XEXP (original_target, 1);
11693 : :
11694 : : /* Move the real and imaginary parts separately. */
11695 : 221 : op0 = expand_expr (TREE_REALPART (exp), rtarg, mode, EXPAND_NORMAL);
11696 : 221 : op1 = expand_expr (TREE_IMAGPART (exp), itarg, mode, EXPAND_NORMAL);
11697 : :
11698 : 221 : if (op0 != rtarg)
11699 : 221 : emit_move_insn (rtarg, op0);
11700 : 221 : if (op1 != itarg)
11701 : 221 : emit_move_insn (itarg, op1);
11702 : :
11703 : 221 : return original_target;
11704 : : }
11705 : :
11706 : : /* fall through */
11707 : :
11708 : 160181 : case STRING_CST:
11709 : 160181 : temp = expand_expr_constant (exp, 1, modifier);
11710 : :
11711 : : /* temp contains a constant address.
11712 : : On RISC machines where a constant address isn't valid,
11713 : : make some insns to get that address into a register. */
11714 : 160181 : if (modifier != EXPAND_CONST_ADDRESS
11715 : : && modifier != EXPAND_INITIALIZER
11716 : 160181 : && modifier != EXPAND_SUM
11717 : 178779 : && ! memory_address_addr_space_p (mode, XEXP (temp, 0),
11718 : 18598 : MEM_ADDR_SPACE (temp)))
11719 : 12 : return replace_equiv_address (temp,
11720 : 12 : copy_rtx (XEXP (temp, 0)));
11721 : : return temp;
11722 : :
11723 : 0 : case POLY_INT_CST:
11724 : 0 : return immed_wide_int_const (poly_int_cst_value (exp), mode);
11725 : :
11726 : 1363 : case SAVE_EXPR:
11727 : 1363 : {
11728 : 1363 : tree val = treeop0;
11729 : 1363 : rtx ret = expand_expr_real_1 (val, target, tmode, modifier, alt_rtl,
11730 : : inner_reference_p);
11731 : :
11732 : 1363 : if (!SAVE_EXPR_RESOLVED_P (exp))
11733 : : {
11734 : : /* We can indeed still hit this case, typically via builtin
11735 : : expanders calling save_expr immediately before expanding
11736 : : something. Assume this means that we only have to deal
11737 : : with non-BLKmode values. */
11738 : 1339 : gcc_assert (GET_MODE (ret) != BLKmode);
11739 : :
11740 : 1339 : val = build_decl (curr_insn_location (),
11741 : 1339 : VAR_DECL, NULL, TREE_TYPE (exp));
11742 : 1339 : DECL_ARTIFICIAL (val) = 1;
11743 : 1339 : DECL_IGNORED_P (val) = 1;
11744 : 1339 : treeop0 = val;
11745 : 1339 : TREE_OPERAND (exp, 0) = treeop0;
11746 : 1339 : SAVE_EXPR_RESOLVED_P (exp) = 1;
11747 : :
11748 : 1339 : if (!CONSTANT_P (ret))
11749 : 1339 : ret = copy_to_reg (ret);
11750 : 1339 : SET_DECL_RTL (val, ret);
11751 : : }
11752 : :
11753 : : return ret;
11754 : : }
11755 : :
11756 : :
11757 : 213740 : case CONSTRUCTOR:
11758 : : /* If we don't need the result, just ensure we evaluate any
11759 : : subexpressions. */
11760 : 213740 : if (ignore)
11761 : : {
11762 : : unsigned HOST_WIDE_INT idx;
11763 : : tree value;
11764 : :
11765 : 0 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
11766 : 0 : expand_expr (value, const0_rtx, VOIDmode, EXPAND_NORMAL);
11767 : :
11768 : 0 : return const0_rtx;
11769 : : }
11770 : :
11771 : 213740 : return expand_constructor (exp, target, modifier, false);
11772 : :
11773 : 810591 : case TARGET_MEM_REF:
11774 : 810591 : {
11775 : 810591 : addr_space_t as
11776 : 810591 : = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
11777 : 810591 : unsigned int align;
11778 : :
11779 : 810591 : op0 = addr_for_mem_ref (exp, as, true);
11780 : 810591 : op0 = memory_address_addr_space (mode, op0, as);
11781 : 810591 : temp = gen_rtx_MEM (mode, op0);
11782 : 810591 : set_mem_attributes (temp, exp, 0);
11783 : 810591 : set_mem_addr_space (temp, as);
11784 : 810591 : align = get_object_alignment (exp);
11785 : 810591 : if (modifier != EXPAND_WRITE
11786 : 810591 : && modifier != EXPAND_MEMORY
11787 : 559769 : && mode != BLKmode
11788 : 1365081 : && align < GET_MODE_ALIGNMENT (mode))
11789 : 46438 : temp = expand_misaligned_mem_ref (temp, mode, unsignedp,
11790 : : align, NULL_RTX, NULL);
11791 : 810591 : return EXTEND_BITINT (temp);
11792 : : }
11793 : :
11794 : 6426874 : case MEM_REF:
11795 : 6426874 : {
11796 : 6426874 : const bool reverse = REF_REVERSE_STORAGE_ORDER (exp);
11797 : 6426874 : addr_space_t as
11798 : 6426874 : = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
11799 : 6426874 : machine_mode address_mode;
11800 : 6426874 : tree base = TREE_OPERAND (exp, 0);
11801 : 6426874 : gimple *def_stmt;
11802 : 6426874 : unsigned align;
11803 : : /* Handle expansion of non-aliased memory with non-BLKmode. That
11804 : : might end up in a register. */
11805 : 6426874 : if (mem_ref_refers_to_non_mem_p (exp))
11806 : : {
11807 : 130012 : poly_int64 offset = mem_ref_offset (exp).force_shwi ();
11808 : 130012 : base = TREE_OPERAND (base, 0);
11809 : 130012 : poly_uint64 type_size;
11810 : 130012 : if (known_eq (offset, 0)
11811 : 77775 : && !reverse
11812 : 77775 : && poly_int_tree_p (TYPE_SIZE (type), &type_size)
11813 : 285562 : && known_eq (GET_MODE_BITSIZE (DECL_MODE (base)), type_size))
11814 : 33183 : return expand_expr (build1 (VIEW_CONVERT_EXPR, type, base),
11815 : 33183 : target, tmode, modifier);
11816 : 96829 : unsigned align;
11817 : 96829 : if (TYPE_MODE (type) == BLKmode || maybe_lt (offset, 0))
11818 : : {
11819 : 200 : temp = assign_stack_temp (DECL_MODE (base),
11820 : 400 : GET_MODE_SIZE (DECL_MODE (base)));
11821 : 200 : store_expr (base, temp, 0, false, false);
11822 : 200 : temp = adjust_address (temp, TYPE_MODE (type), offset);
11823 : 200 : if (TYPE_MODE (type) == BLKmode)
11824 : 185 : set_mem_size (temp, int_size_in_bytes (type));
11825 : : /* When the original ref was misaligned so will be the
11826 : : access to the stack temporary. Not all targets handle
11827 : : this correctly, some will ICE in sanity checking.
11828 : : Handle this by doing bitfield extraction when necessary. */
11829 : 30 : else if ((align = get_object_alignment (exp))
11830 : 15 : < GET_MODE_ALIGNMENT (TYPE_MODE (type)))
11831 : 3 : temp
11832 : 3 : = expand_misaligned_mem_ref (temp, TYPE_MODE (type),
11833 : : unsignedp, align,
11834 : : modifier == EXPAND_STACK_PARM
11835 : : ? NULL_RTX : target, NULL);
11836 : 200 : return temp;
11837 : : }
11838 : : /* When the access is fully outside of the underlying object
11839 : : expand the offset as zero. This avoids out-of-bound
11840 : : BIT_FIELD_REFs and generates smaller code for these cases
11841 : : with UB. */
11842 : 96629 : type_size = tree_to_poly_uint64 (TYPE_SIZE_UNIT (type));
11843 : 193258 : if (!ranges_maybe_overlap_p (offset, type_size, 0,
11844 : 193258 : GET_MODE_SIZE (DECL_MODE (base))))
11845 : 147 : offset = 0;
11846 : 96629 : exp = build3 (BIT_FIELD_REF, type, base, TYPE_SIZE (type),
11847 : 96629 : bitsize_int (offset * BITS_PER_UNIT));
11848 : 96629 : REF_REVERSE_STORAGE_ORDER (exp) = reverse;
11849 : 96629 : return expand_expr (exp, target, tmode, modifier);
11850 : : }
11851 : 6296862 : address_mode = targetm.addr_space.address_mode (as);
11852 : 6296862 : if ((def_stmt = get_def_for_expr (base, BIT_AND_EXPR)))
11853 : : {
11854 : 39 : tree mask = gimple_assign_rhs2 (def_stmt);
11855 : 39 : base = build2 (BIT_AND_EXPR, TREE_TYPE (base),
11856 : : gimple_assign_rhs1 (def_stmt), mask);
11857 : 39 : TREE_OPERAND (exp, 0) = base;
11858 : : }
11859 : 6296862 : align = get_object_alignment (exp);
11860 : 6296862 : op0 = expand_expr (base, NULL_RTX, VOIDmode, EXPAND_SUM);
11861 : 6296862 : op0 = memory_address_addr_space (mode, op0, as);
11862 : 6296862 : if (!integer_zerop (TREE_OPERAND (exp, 1)))
11863 : : {
11864 : 1941833 : rtx off = immed_wide_int_const (mem_ref_offset (exp), address_mode);
11865 : 1941833 : op0 = simplify_gen_binary (PLUS, address_mode, op0, off);
11866 : 1941833 : op0 = memory_address_addr_space (mode, op0, as);
11867 : : }
11868 : 6296862 : temp = gen_rtx_MEM (mode, op0);
11869 : 6296862 : set_mem_attributes (temp, exp, 0);
11870 : 6296862 : set_mem_addr_space (temp, as);
11871 : 6296862 : if (TREE_THIS_VOLATILE (exp))
11872 : 11434 : MEM_VOLATILE_P (temp) = 1;
11873 : 6296862 : if (modifier == EXPAND_WRITE || modifier == EXPAND_MEMORY)
11874 : : return temp;
11875 : 3774755 : if (!inner_reference_p
11876 : 1944641 : && mode != BLKmode
11877 : 5660328 : && align < GET_MODE_ALIGNMENT (mode))
11878 : 125693 : temp = expand_misaligned_mem_ref (temp, mode, unsignedp, align,
11879 : : modifier == EXPAND_STACK_PARM
11880 : : ? NULL_RTX : target, alt_rtl);
11881 : 3774755 : if (reverse)
11882 : 7 : temp = flip_storage_order (mode, temp);
11883 : 3774755 : return EXTEND_BITINT (temp);
11884 : : }
11885 : :
11886 : 600120 : case ARRAY_REF:
11887 : :
11888 : 600120 : {
11889 : 600120 : tree array = treeop0;
11890 : 600120 : tree index = treeop1;
11891 : 600120 : tree init;
11892 : :
11893 : : /* Fold an expression like: "foo"[2].
11894 : : This is not done in fold so it won't happen inside &.
11895 : : Don't fold if this is for wide characters since it's too
11896 : : difficult to do correctly and this is a very rare case. */
11897 : :
11898 : 600120 : if (modifier != EXPAND_CONST_ADDRESS
11899 : 600120 : && modifier != EXPAND_INITIALIZER
11900 : 600120 : && modifier != EXPAND_MEMORY)
11901 : : {
11902 : 600011 : tree t = fold_read_from_constant_string (exp);
11903 : :
11904 : 600011 : if (t)
11905 : 0 : return expand_expr (t, target, tmode, modifier);
11906 : : }
11907 : :
11908 : : /* If this is a constant index into a constant array,
11909 : : just get the value from the array. Handle both the cases when
11910 : : we have an explicit constructor and when our operand is a variable
11911 : : that was declared const. */
11912 : :
11913 : 600120 : if (modifier != EXPAND_CONST_ADDRESS
11914 : : && modifier != EXPAND_INITIALIZER
11915 : : && modifier != EXPAND_MEMORY
11916 : 600011 : && TREE_CODE (array) == CONSTRUCTOR
11917 : 0 : && ! TREE_SIDE_EFFECTS (array)
11918 : 600120 : && TREE_CODE (index) == INTEGER_CST)
11919 : : {
11920 : : unsigned HOST_WIDE_INT ix;
11921 : : tree field, value;
11922 : :
11923 : 0 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array), ix,
11924 : : field, value)
11925 : 0 : if (tree_int_cst_equal (field, index))
11926 : : {
11927 : 0 : if (!TREE_SIDE_EFFECTS (value)
11928 : 0 : && TREE_CODE (value) != RAW_DATA_CST)
11929 : 0 : return expand_expr (fold (value), target, tmode, modifier);
11930 : : break;
11931 : : }
11932 : : }
11933 : :
11934 : 600120 : else if (optimize >= 1
11935 : : && modifier != EXPAND_CONST_ADDRESS
11936 : 336480 : && modifier != EXPAND_INITIALIZER
11937 : 336480 : && modifier != EXPAND_MEMORY
11938 : 336375 : && TREE_READONLY (array) && ! TREE_SIDE_EFFECTS (array)
11939 : 10410 : && TREE_CODE (index) == INTEGER_CST
11940 : 1690 : && (VAR_P (array) || TREE_CODE (array) == CONST_DECL)
11941 : 600256 : && (init = ctor_for_folding (array)) != error_mark_node)
11942 : : {
11943 : 98 : if (init == NULL_TREE)
11944 : : {
11945 : 5 : tree value = build_zero_cst (type);
11946 : 5 : if (TREE_CODE (value) == CONSTRUCTOR)
11947 : : {
11948 : : /* If VALUE is a CONSTRUCTOR, this optimization is only
11949 : : useful if this doesn't store the CONSTRUCTOR into
11950 : : memory. If it does, it is more efficient to just
11951 : : load the data from the array directly. */
11952 : 5 : rtx ret = expand_constructor (value, target,
11953 : : modifier, true);
11954 : 5 : if (ret == NULL_RTX)
11955 : : value = NULL_TREE;
11956 : : }
11957 : :
11958 : : if (value)
11959 : 0 : return expand_expr (value, target, tmode, modifier);
11960 : : }
11961 : 93 : else if (TREE_CODE (init) == CONSTRUCTOR)
11962 : : {
11963 : : unsigned HOST_WIDE_INT ix;
11964 : : tree field, value;
11965 : :
11966 : 190 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), ix,
11967 : : field, value)
11968 : 165 : if (tree_int_cst_equal (field, index))
11969 : : {
11970 : 67 : if (TREE_SIDE_EFFECTS (value)
11971 : 67 : || TREE_CODE (value) == RAW_DATA_CST)
11972 : : break;
11973 : :
11974 : 67 : if (TREE_CODE (value) == CONSTRUCTOR)
11975 : : {
11976 : : /* If VALUE is a CONSTRUCTOR, this
11977 : : optimization is only useful if
11978 : : this doesn't store the CONSTRUCTOR
11979 : : into memory. If it does, it is more
11980 : : efficient to just load the data from
11981 : : the array directly. */
11982 : 62 : rtx ret = expand_constructor (value, target,
11983 : : modifier, true);
11984 : 62 : if (ret == NULL_RTX)
11985 : : break;
11986 : : }
11987 : :
11988 : 29 : return expand_expr (fold (value), target, tmode,
11989 : 29 : modifier);
11990 : : }
11991 : : }
11992 : 1 : else if (TREE_CODE (init) == STRING_CST)
11993 : : {
11994 : 1 : tree low_bound = array_ref_low_bound (exp);
11995 : 1 : tree index1 = fold_convert_loc (loc, sizetype, treeop1);
11996 : :
11997 : : /* Optimize the special case of a zero lower bound.
11998 : :
11999 : : We convert the lower bound to sizetype to avoid problems
12000 : : with constant folding. E.g. suppose the lower bound is
12001 : : 1 and its mode is QI. Without the conversion
12002 : : (ARRAY + (INDEX - (unsigned char)1))
12003 : : becomes
12004 : : (ARRAY + (-(unsigned char)1) + INDEX)
12005 : : which becomes
12006 : : (ARRAY + 255 + INDEX). Oops! */
12007 : 1 : if (!integer_zerop (low_bound))
12008 : 0 : index1 = size_diffop_loc (loc, index1,
12009 : : fold_convert_loc (loc, sizetype,
12010 : : low_bound));
12011 : :
12012 : 1 : if (tree_fits_uhwi_p (index1)
12013 : 2 : && compare_tree_int (index1, TREE_STRING_LENGTH (init)) < 0)
12014 : : {
12015 : 0 : tree char_type = TREE_TYPE (TREE_TYPE (init));
12016 : 0 : scalar_int_mode char_mode;
12017 : :
12018 : 600091 : if (is_int_mode (TYPE_MODE (char_type), &char_mode)
12019 : 0 : && GET_MODE_SIZE (char_mode) == 1)
12020 : 0 : return gen_int_mode (TREE_STRING_POINTER (init)
12021 : 0 : [TREE_INT_CST_LOW (index1)],
12022 : : char_mode);
12023 : : }
12024 : : }
12025 : : }
12026 : : }
12027 : 600091 : goto normal_inner_ref;
12028 : :
12029 : 3655299 : case COMPONENT_REF:
12030 : 3655299 : gcc_assert (TREE_CODE (treeop0) != CONSTRUCTOR);
12031 : : /* Fall through. */
12032 : 4550695 : case BIT_FIELD_REF:
12033 : 4550695 : case ARRAY_RANGE_REF:
12034 : 3655299 : normal_inner_ref:
12035 : 4550695 : {
12036 : 4550695 : machine_mode mode1, mode2;
12037 : 4550695 : poly_int64 bitsize, bitpos, bytepos;
12038 : 4550695 : tree offset;
12039 : 4550695 : int reversep, volatilep = 0;
12040 : 4550695 : tree tem
12041 : 4550695 : = get_inner_reference (exp, &bitsize, &bitpos, &offset, &mode1,
12042 : : &unsignedp, &reversep, &volatilep);
12043 : 4550695 : rtx orig_op0, memloc;
12044 : 4550695 : bool clear_mem_expr = false;
12045 : 4550695 : bool must_force_mem;
12046 : :
12047 : : /* If we got back the original object, something is wrong. Perhaps
12048 : : we are evaluating an expression too early. In any event, don't
12049 : : infinitely recurse. */
12050 : 4550695 : gcc_assert (tem != exp);
12051 : :
12052 : : /* Make sure bitpos is not negative, this can wreak havoc later. */
12053 : 4550695 : if (maybe_lt (bitpos, 0))
12054 : : {
12055 : 247 : gcc_checking_assert (offset == NULL_TREE);
12056 : 247 : offset = size_int (bits_to_bytes_round_down (bitpos));
12057 : 247 : bitpos = num_trailing_bits (bitpos);
12058 : : }
12059 : :
12060 : : /* If we have either an offset, a BLKmode result, or a reference
12061 : : outside the underlying object, we must force it to memory.
12062 : : Such a case can occur in Ada if we have unchecked conversion
12063 : : of an expression from a scalar type to an aggregate type or
12064 : : for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
12065 : : passed a partially uninitialized object or a view-conversion
12066 : : to a larger size. */
12067 : 9101390 : must_force_mem = offset != NULL_TREE
12068 : 4277825 : || mode1 == BLKmode
12069 : 8756969 : || (mode == BLKmode
12070 : 0 : && !int_mode_for_size (bitsize, 1).exists ());
12071 : :
12072 : 344421 : const enum expand_modifier tem_modifier
12073 : : = must_force_mem
12074 : : ? EXPAND_MEMORY
12075 : 4206274 : : modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier;
12076 : :
12077 : : /* If TEM's type is a union of variable size, pass TARGET to the inner
12078 : : computation, since it will need a temporary and TARGET is known
12079 : : to have to do. This occurs in unchecked conversion in Ada. */
12080 : 4550695 : const rtx tem_target
12081 : 4550695 : = TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
12082 : 36375 : && COMPLETE_TYPE_P (TREE_TYPE (tem))
12083 : 36370 : && TREE_CODE (TYPE_SIZE (TREE_TYPE (tem))) != INTEGER_CST
12084 : 0 : && modifier != EXPAND_STACK_PARM
12085 : 4550695 : ? target
12086 : 4550695 : : NULL_RTX;
12087 : :
12088 : 9101390 : orig_op0 = op0
12089 : 4550695 : = expand_expr_real (tem, tem_target, VOIDmode, tem_modifier, NULL,
12090 : : true);
12091 : :
12092 : : /* If the field has a mode, we want to access it in the
12093 : : field's mode, not the computed mode.
12094 : : If a MEM has VOIDmode (external with incomplete type),
12095 : : use BLKmode for it instead. */
12096 : 4550695 : if (MEM_P (op0))
12097 : : {
12098 : 4181529 : if (mode1 != VOIDmode)
12099 : 4005022 : op0 = adjust_address (op0, mode1, 0);
12100 : 176507 : else if (GET_MODE (op0) == VOIDmode)
12101 : 0 : op0 = adjust_address (op0, BLKmode, 0);
12102 : : }
12103 : :
12104 : 4550695 : mode2
12105 : 4550695 : = CONSTANT_P (op0) ? TYPE_MODE (TREE_TYPE (tem)) : GET_MODE (op0);
12106 : :
12107 : : /* See above for the rationale. */
12108 : 9101390 : if (maybe_gt (bitpos + bitsize, GET_MODE_BITSIZE (mode2)))
12109 : 2841540 : must_force_mem = true;
12110 : :
12111 : : /* Handle CONCAT first. */
12112 : 4550695 : if (GET_CODE (op0) == CONCAT && !must_force_mem)
12113 : : {
12114 : 120 : if (known_eq (bitpos, 0)
12115 : 218 : && known_eq (bitsize, GET_MODE_BITSIZE (GET_MODE (op0)))
12116 : 104 : && COMPLEX_MODE_P (mode1)
12117 : 99 : && COMPLEX_MODE_P (GET_MODE (op0))
12118 : 417 : && (GET_MODE_PRECISION (GET_MODE_INNER (mode1))
12119 : 198 : == GET_MODE_PRECISION (GET_MODE_INNER (GET_MODE (op0)))))
12120 : : {
12121 : 99 : if (reversep)
12122 : 0 : op0 = flip_storage_order (GET_MODE (op0), op0);
12123 : 99 : if (mode1 != GET_MODE (op0))
12124 : : {
12125 : : rtx parts[2];
12126 : 0 : for (int i = 0; i < 2; i++)
12127 : : {
12128 : 0 : rtx op = read_complex_part (op0, i != 0);
12129 : 0 : if (GET_CODE (op) == SUBREG)
12130 : 0 : op = force_reg (GET_MODE (op), op);
12131 : 0 : temp = gen_lowpart_common (GET_MODE_INNER (mode1), op);
12132 : 0 : if (temp)
12133 : : op = temp;
12134 : : else
12135 : : {
12136 : 0 : if (!REG_P (op) && !MEM_P (op))
12137 : 0 : op = force_reg (GET_MODE (op), op);
12138 : 0 : op = gen_lowpart (GET_MODE_INNER (mode1), op);
12139 : : }
12140 : 0 : parts[i] = op;
12141 : : }
12142 : 0 : op0 = gen_rtx_CONCAT (mode1, parts[0], parts[1]);
12143 : : }
12144 : 99 : return op0;
12145 : : }
12146 : 21 : if (known_eq (bitpos, 0)
12147 : 20 : && known_eq (bitsize,
12148 : : GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0))))
12149 : 23 : && maybe_ne (bitsize, 0))
12150 : : {
12151 : : op0 = XEXP (op0, 0);
12152 : : mode2 = GET_MODE (op0);
12153 : : }
12154 : 19 : else if (known_eq (bitpos,
12155 : : GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0))))
12156 : 4 : && known_eq (bitsize,
12157 : : GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 1))))
12158 : 0 : && maybe_ne (bitpos, 0)
12159 : 19 : && maybe_ne (bitsize, 0))
12160 : : {
12161 : 0 : op0 = XEXP (op0, 1);
12162 : 0 : bitpos = 0;
12163 : 0 : mode2 = GET_MODE (op0);
12164 : : }
12165 : : else
12166 : : /* Otherwise force into memory. */
12167 : : must_force_mem = true;
12168 : : }
12169 : :
12170 : : /* If this is a constant, put it in a register if it is a legitimate
12171 : : constant and we don't need a memory reference. */
12172 : 4550596 : if (CONSTANT_P (op0)
12173 : 45 : && mode2 != BLKmode
12174 : 45 : && targetm.legitimate_constant_p (mode2, op0)
12175 : 4550629 : && !must_force_mem)
12176 : 33 : op0 = force_reg (mode2, op0);
12177 : :
12178 : : /* Otherwise, if this is a constant, try to force it to the constant
12179 : : pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
12180 : : is a legitimate constant. */
12181 : 4550563 : else if (CONSTANT_P (op0) && (memloc = force_const_mem (mode2, op0)))
12182 : 12 : op0 = validize_mem (memloc);
12183 : :
12184 : : /* Otherwise, if this is a constant or the object is not in memory
12185 : : and need be, put it there. */
12186 : 4550551 : else if (CONSTANT_P (op0) || (!MEM_P (op0) && must_force_mem))
12187 : : {
12188 : 1277 : poly_int64 size;
12189 : 1277 : if (!poly_int_tree_p (TYPE_SIZE_UNIT (TREE_TYPE (tem)), &size))
12190 : 0 : size = max_int_size_in_bytes (TREE_TYPE (tem));
12191 : 1277 : memloc = assign_stack_local (TYPE_MODE (TREE_TYPE (tem)), size,
12192 : 1277 : TREE_CODE (tem) == SSA_NAME
12193 : 9 : ? TYPE_ALIGN (TREE_TYPE (tem))
12194 : 1268 : : get_object_alignment (tem));
12195 : 1277 : emit_move_insn (memloc, op0);
12196 : 1277 : op0 = memloc;
12197 : 1277 : clear_mem_expr = true;
12198 : : }
12199 : :
12200 : 4550596 : if (offset)
12201 : : {
12202 : 272870 : machine_mode address_mode;
12203 : 272870 : rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode,
12204 : : EXPAND_SUM);
12205 : :
12206 : 272870 : gcc_assert (MEM_P (op0));
12207 : :
12208 : 272870 : address_mode = get_address_mode (op0);
12209 : 272870 : if (GET_MODE (offset_rtx) != address_mode)
12210 : : {
12211 : : /* We cannot be sure that the RTL in offset_rtx is valid outside
12212 : : of a memory address context, so force it into a register
12213 : : before attempting to convert it to the desired mode. */
12214 : 414 : offset_rtx = force_operand (offset_rtx, NULL_RTX);
12215 : 414 : offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
12216 : : }
12217 : :
12218 : : /* See the comment in expand_assignment for the rationale. */
12219 : 272870 : if (mode1 != VOIDmode
12220 : 272636 : && maybe_ne (bitpos, 0)
12221 : 68392 : && maybe_gt (bitsize, 0)
12222 : 341262 : && multiple_p (bitpos, BITS_PER_UNIT, &bytepos)
12223 : 340725 : && multiple_p (bitpos, bitsize)
12224 : 135710 : && multiple_p (bitsize, GET_MODE_ALIGNMENT (mode1))
12225 : 340725 : && MEM_ALIGN (op0) >= GET_MODE_ALIGNMENT (mode1))
12226 : : {
12227 : 67828 : op0 = adjust_address (op0, mode1, bytepos);
12228 : 67828 : bitpos = 0;
12229 : : }
12230 : :
12231 : 272870 : op0 = offset_address (op0, offset_rtx,
12232 : : highest_pow2_factor (offset));
12233 : : }
12234 : :
12235 : : /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
12236 : : record its alignment as BIGGEST_ALIGNMENT. */
12237 : 4550596 : if (MEM_P (op0)
12238 : 4182818 : && known_eq (bitpos, 0)
12239 : 1437533 : && offset != 0
12240 : 4822736 : && is_aligning_offset (offset, tem))
12241 : 0 : set_mem_align (op0, BIGGEST_ALIGNMENT);
12242 : :
12243 : : /* Don't forget about volatility even if this is a bitfield. */
12244 : 4550596 : if (MEM_P (op0) && volatilep && ! MEM_VOLATILE_P (op0))
12245 : : {
12246 : 375 : if (op0 == orig_op0)
12247 : 123 : op0 = copy_rtx (op0);
12248 : :
12249 : 375 : MEM_VOLATILE_P (op0) = 1;
12250 : : }
12251 : :
12252 : 4550596 : if (MEM_P (op0) && TREE_CODE (tem) == FUNCTION_DECL)
12253 : : {
12254 : 6 : if (op0 == orig_op0)
12255 : 0 : op0 = copy_rtx (op0);
12256 : :
12257 : 6 : set_mem_align (op0, BITS_PER_UNIT);
12258 : : }
12259 : :
12260 : : /* In cases where an aligned union has an unaligned object
12261 : : as a field, we might be extracting a BLKmode value from
12262 : : an integer-mode (e.g., SImode) object. Handle this case
12263 : : by doing the extract into an object as wide as the field
12264 : : (which we know to be the width of a basic mode), then
12265 : : storing into memory, and changing the mode to BLKmode. */
12266 : 4550596 : if (mode1 == VOIDmode
12267 : 4262205 : || REG_P (op0) || GET_CODE (op0) == SUBREG
12268 : 4006199 : || (mode1 != BLKmode && ! direct_load[(int) mode1]
12269 : 26635 : && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
12270 : 22485 : && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT
12271 : : && modifier != EXPAND_CONST_ADDRESS
12272 : 15491 : && modifier != EXPAND_INITIALIZER
12273 : 15491 : && modifier != EXPAND_MEMORY)
12274 : : /* If the bitfield is volatile and the bitsize
12275 : : is narrower than the access size of the bitfield,
12276 : : we need to extract bitfields from the access. */
12277 : 3990708 : || (volatilep && TREE_CODE (exp) == COMPONENT_REF
12278 : 1301 : && DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1))
12279 : 10 : && mode1 != BLKmode
12280 : 20 : && maybe_lt (bitsize, GET_MODE_SIZE (mode1) * BITS_PER_UNIT))
12281 : : /* If the field isn't aligned enough to fetch as a memref,
12282 : : fetch it as a bit field. */
12283 : 3990699 : || (mode1 != BLKmode
12284 : 3918342 : && (((MEM_P (op0)
12285 : 3918342 : ? MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode1)
12286 : 7698133 : || !multiple_p (bitpos, GET_MODE_ALIGNMENT (mode1))
12287 : 0 : : TYPE_ALIGN (TREE_TYPE (tem)) < GET_MODE_ALIGNMENT (mode)
12288 : 0 : || !multiple_p (bitpos, GET_MODE_ALIGNMENT (mode)))
12289 : 71810 : && modifier != EXPAND_MEMORY
12290 : 71810 : && ((modifier == EXPAND_CONST_ADDRESS
12291 : 71810 : || modifier == EXPAND_INITIALIZER)
12292 : 71810 : ? STRICT_ALIGNMENT
12293 : 71810 : : targetm.slow_unaligned_access (mode1,
12294 : 71810 : MEM_ALIGN (op0))))
12295 : 3918342 : || !multiple_p (bitpos, BITS_PER_UNIT)))
12296 : : /* If the type and the field are a constant size and the
12297 : : size of the type isn't the same size as the bitfield,
12298 : : we must use bitfield operations. */
12299 : 12459637 : || (known_size_p (bitsize)
12300 : 3990699 : && TYPE_SIZE (TREE_TYPE (exp))
12301 : 3990699 : && poly_int_tree_p (TYPE_SIZE (TREE_TYPE (exp)))
12302 : 3990699 : && maybe_ne (wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (exp))),
12303 : : bitsize)))
12304 : : {
12305 : 559910 : machine_mode ext_mode = mode;
12306 : :
12307 : 559910 : if (ext_mode == BLKmode
12308 : 559910 : && ! (target != 0 && MEM_P (op0)
12309 : 6 : && MEM_P (target)
12310 : 6 : && multiple_p (bitpos, BITS_PER_UNIT)))
12311 : 3 : ext_mode = int_mode_for_size (bitsize, 1).else_blk ();
12312 : :
12313 : 559910 : if (ext_mode == BLKmode)
12314 : : {
12315 : 9 : if (target == 0)
12316 : 3 : target = assign_temp (type, 1, 1);
12317 : :
12318 : : /* ??? Unlike the similar test a few lines below, this one is
12319 : : very likely obsolete. */
12320 : 9 : if (known_eq (bitsize, 0))
12321 : : return target;
12322 : :
12323 : : /* In this case, BITPOS must start at a byte boundary and
12324 : : TARGET, if specified, must be a MEM. */
12325 : 9 : gcc_assert (MEM_P (op0)
12326 : : && (!target || MEM_P (target)));
12327 : :
12328 : 9 : bytepos = exact_div (bitpos, BITS_PER_UNIT);
12329 : 9 : poly_int64 bytesize = bits_to_bytes_round_up (bitsize);
12330 : 18 : emit_block_move (target,
12331 : 9 : adjust_address (op0, VOIDmode, bytepos),
12332 : 9 : gen_int_mode (bytesize, Pmode),
12333 : : (modifier == EXPAND_STACK_PARM
12334 : : ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
12335 : :
12336 : 9 : return target;
12337 : : }
12338 : :
12339 : : /* If we have nothing to extract, the result will be 0 for targets
12340 : : with SHIFT_COUNT_TRUNCATED == 0 and garbage otherwise. Always
12341 : : return 0 for the sake of consistency, as reading a zero-sized
12342 : : bitfield is valid in Ada and the value is fully specified. */
12343 : 559901 : if (known_eq (bitsize, 0))
12344 : 0 : return const0_rtx;
12345 : :
12346 : 559901 : op0 = validize_mem (op0);
12347 : :
12348 : 559901 : if (MEM_P (op0) && REG_P (XEXP (op0, 0)))
12349 : 62627 : mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
12350 : :
12351 : : /* If the result has aggregate type and the extraction is done in
12352 : : an integral mode, then the field may be not aligned on a byte
12353 : : boundary; in this case, if it has reverse storage order, it
12354 : : needs to be extracted as a scalar field with reverse storage
12355 : : order and put back into memory order afterwards. */
12356 : 559901 : if (AGGREGATE_TYPE_P (type)
12357 : 773 : && GET_MODE_CLASS (ext_mode) == MODE_INT)
12358 : 696 : reversep = TYPE_REVERSE_STORAGE_ORDER (type);
12359 : :
12360 : 559901 : gcc_checking_assert (known_ge (bitpos, 0));
12361 : 572525 : op0 = extract_bit_field (op0, bitsize, bitpos, unsignedp,
12362 : : (modifier == EXPAND_STACK_PARM
12363 : : ? NULL_RTX : target),
12364 : : ext_mode, ext_mode, reversep, alt_rtl);
12365 : :
12366 : : /* If the result has aggregate type and the mode of OP0 is an
12367 : : integral mode then, if BITSIZE is narrower than this mode
12368 : : and this is for big-endian data, we must put the field
12369 : : into the high-order bits. And we must also put it back
12370 : : into memory order if it has been previously reversed. */
12371 : 559901 : scalar_int_mode op0_mode;
12372 : 559901 : if (AGGREGATE_TYPE_P (type)
12373 : 559901 : && is_int_mode (GET_MODE (op0), &op0_mode))
12374 : : {
12375 : 696 : HOST_WIDE_INT size = GET_MODE_BITSIZE (op0_mode);
12376 : :
12377 : 696 : gcc_checking_assert (known_le (bitsize, size));
12378 : 696 : if (maybe_lt (bitsize, size)
12379 : 696 : && reversep ? !BYTES_BIG_ENDIAN : BYTES_BIG_ENDIAN)
12380 : 0 : op0 = expand_shift (LSHIFT_EXPR, op0_mode, op0,
12381 : : size - bitsize, op0, 1);
12382 : :
12383 : 696 : if (reversep)
12384 : 0 : op0 = flip_storage_order (op0_mode, op0);
12385 : : }
12386 : :
12387 : : /* If the result type is BLKmode, store the data into a temporary
12388 : : of the appropriate type, but with the mode corresponding to the
12389 : : mode for the data we have (op0's mode). */
12390 : 559901 : if (mode == BLKmode)
12391 : : {
12392 : 0 : rtx new_rtx
12393 : 0 : = assign_stack_temp_for_type (ext_mode,
12394 : 0 : GET_MODE_BITSIZE (ext_mode),
12395 : : type);
12396 : 0 : emit_move_insn (new_rtx, op0);
12397 : 0 : op0 = copy_rtx (new_rtx);
12398 : 0 : PUT_MODE (op0, BLKmode);
12399 : : }
12400 : :
12401 : 559901 : return op0;
12402 : : }
12403 : :
12404 : : /* If the result is BLKmode, use that to access the object
12405 : : now as well. */
12406 : 3990686 : if (mode == BLKmode)
12407 : 72348 : mode1 = BLKmode;
12408 : :
12409 : : /* Get a reference to just this component. */
12410 : 3990686 : bytepos = bits_to_bytes_round_down (bitpos);
12411 : 3990686 : if (modifier == EXPAND_CONST_ADDRESS
12412 : 3990686 : || modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
12413 : 173216 : op0 = adjust_address_nv (op0, mode1, bytepos);
12414 : : else
12415 : 3817470 : op0 = adjust_address (op0, mode1, bytepos);
12416 : :
12417 : 3990686 : if (op0 == orig_op0)
12418 : 125851 : op0 = copy_rtx (op0);
12419 : :
12420 : : /* Don't set memory attributes if the base expression is
12421 : : SSA_NAME that got expanded as a MEM or a CONSTANT. In that case,
12422 : : we should just honor its original memory attributes. */
12423 : 3990686 : if (!(TREE_CODE (tem) == SSA_NAME
12424 : 8547 : && (MEM_P (orig_op0) || CONSTANT_P (orig_op0))))
12425 : 3982139 : set_mem_attributes (op0, exp, 0);
12426 : :
12427 : 3990686 : if (REG_P (XEXP (op0, 0)))
12428 : 630965 : mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
12429 : :
12430 : : /* If op0 is a temporary because the original expressions was forced
12431 : : to memory, clear MEM_EXPR so that the original expression cannot
12432 : : be marked as addressable through MEM_EXPR of the temporary. */
12433 : 3990686 : if (clear_mem_expr)
12434 : 1165 : set_mem_expr (op0, NULL_TREE);
12435 : :
12436 : 3990686 : MEM_VOLATILE_P (op0) |= volatilep;
12437 : :
12438 : 3990686 : if (reversep
12439 : : && modifier != EXPAND_MEMORY
12440 : 483 : && modifier != EXPAND_WRITE)
12441 : 483 : op0 = flip_storage_order (mode1, op0);
12442 : :
12443 : 3990686 : op0 = EXTEND_BITINT (op0);
12444 : :
12445 : 3990686 : if (mode == mode1 || mode1 == BLKmode || mode1 == tmode
12446 : : || modifier == EXPAND_CONST_ADDRESS
12447 : 0 : || modifier == EXPAND_INITIALIZER)
12448 : : return op0;
12449 : :
12450 : 0 : if (target == 0)
12451 : 0 : target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
12452 : :
12453 : 0 : convert_move (target, op0, unsignedp);
12454 : 0 : return target;
12455 : : }
12456 : :
12457 : 65113 : case OBJ_TYPE_REF:
12458 : 65113 : return expand_expr (OBJ_TYPE_REF_EXPR (exp), target, tmode, modifier);
12459 : :
12460 : 6512851 : case CALL_EXPR:
12461 : : /* All valid uses of __builtin_va_arg_pack () are removed during
12462 : : inlining. */
12463 : 6512851 : if (CALL_EXPR_VA_ARG_PACK (exp))
12464 : 6 : error ("invalid use of %<__builtin_va_arg_pack ()%>");
12465 : 6512851 : {
12466 : 6512851 : tree fndecl = get_callee_fndecl (exp), attr;
12467 : :
12468 : 6512851 : if (fndecl
12469 : : /* Don't diagnose the error attribute in thunks, those are
12470 : : artificially created. */
12471 : 6328107 : && !CALL_FROM_THUNK_P (exp)
12472 : 12837075 : && (attr = lookup_attribute ("error",
12473 : 6324224 : DECL_ATTRIBUTES (fndecl))) != NULL)
12474 : : {
12475 : 5 : const char *ident = lang_hooks.decl_printable_name (fndecl, 1);
12476 : 10 : error ("call to %qs declared with attribute error: %s",
12477 : : identifier_to_locale (ident),
12478 : 5 : TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12479 : : }
12480 : 6512851 : if (fndecl
12481 : : /* Don't diagnose the warning attribute in thunks, those are
12482 : : artificially created. */
12483 : 6328107 : && !CALL_FROM_THUNK_P (exp)
12484 : 12837075 : && (attr = lookup_attribute ("warning",
12485 : 6324224 : DECL_ATTRIBUTES (fndecl))) != NULL)
12486 : : {
12487 : 17 : const char *ident = lang_hooks.decl_printable_name (fndecl, 1);
12488 : 34 : warning_at (EXPR_LOCATION (exp),
12489 : : OPT_Wattribute_warning,
12490 : : "call to %qs declared with attribute warning: %s",
12491 : : identifier_to_locale (ident),
12492 : 17 : TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12493 : : }
12494 : :
12495 : : /* Check for a built-in function. */
12496 : 6512851 : if (fndecl && fndecl_built_in_p (fndecl))
12497 : : {
12498 : 1936566 : gcc_assert (DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_FRONTEND);
12499 : 1936566 : return expand_builtin (exp, target, subtarget, tmode, ignore);
12500 : : }
12501 : : }
12502 : 4576285 : temp = expand_call (exp, target, ignore);
12503 : 4576285 : return EXTEND_BITINT (temp);
12504 : :
12505 : 344248 : case VIEW_CONVERT_EXPR:
12506 : 344248 : op0 = NULL_RTX;
12507 : :
12508 : : /* If we are converting to BLKmode, try to avoid an intermediate
12509 : : temporary by fetching an inner memory reference. */
12510 : 344248 : if (mode == BLKmode
12511 : 73507 : && poly_int_tree_p (TYPE_SIZE (type))
12512 : 73507 : && TYPE_MODE (TREE_TYPE (treeop0)) != BLKmode
12513 : 344248 : && handled_component_p (treeop0))
12514 : : {
12515 : 0 : machine_mode mode1;
12516 : 0 : poly_int64 bitsize, bitpos, bytepos;
12517 : 0 : tree offset;
12518 : 0 : int reversep, volatilep = 0;
12519 : 0 : tree tem
12520 : 0 : = get_inner_reference (treeop0, &bitsize, &bitpos, &offset, &mode1,
12521 : : &unsignedp, &reversep, &volatilep);
12522 : :
12523 : : /* ??? We should work harder and deal with non-zero offsets. */
12524 : 0 : if (!offset
12525 : 0 : && multiple_p (bitpos, BITS_PER_UNIT, &bytepos)
12526 : 0 : && !reversep
12527 : 0 : && known_size_p (bitsize)
12528 : 0 : && known_eq (wi::to_poly_offset (TYPE_SIZE (type)), bitsize))
12529 : : {
12530 : : /* See the normal_inner_ref case for the rationale. */
12531 : 0 : rtx orig_op0
12532 : 0 : = expand_expr_real (tem,
12533 : 0 : (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
12534 : 0 : && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
12535 : : != INTEGER_CST)
12536 : 0 : && modifier != EXPAND_STACK_PARM
12537 : : ? target : NULL_RTX),
12538 : : VOIDmode,
12539 : : modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier,
12540 : : NULL, true);
12541 : :
12542 : 0 : if (MEM_P (orig_op0))
12543 : : {
12544 : 0 : op0 = orig_op0;
12545 : :
12546 : : /* Get a reference to just this component. */
12547 : 0 : if (modifier == EXPAND_CONST_ADDRESS
12548 : : || modifier == EXPAND_SUM
12549 : 0 : || modifier == EXPAND_INITIALIZER)
12550 : 0 : op0 = adjust_address_nv (op0, mode, bytepos);
12551 : : else
12552 : 0 : op0 = adjust_address (op0, mode, bytepos);
12553 : :
12554 : 0 : if (op0 == orig_op0)
12555 : 0 : op0 = copy_rtx (op0);
12556 : :
12557 : 0 : set_mem_attributes (op0, treeop0, 0);
12558 : 0 : if (REG_P (XEXP (op0, 0)))
12559 : 0 : mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
12560 : :
12561 : 0 : MEM_VOLATILE_P (op0) |= volatilep;
12562 : : }
12563 : : }
12564 : : }
12565 : :
12566 : 0 : if (!op0)
12567 : 344248 : op0 = expand_expr_real (treeop0, NULL_RTX, VOIDmode, modifier,
12568 : 344248 : NULL, inner_reference_p || mode == BLKmode);
12569 : :
12570 : : /* If the input and output modes are both the same, we are done. */
12571 : 344248 : if (mode == GET_MODE (op0))
12572 : : ;
12573 : : /* Similarly if the output mode is BLKmode and input is a MEM,
12574 : : adjust_address done below is all we need. */
12575 : 146221 : else if (mode == BLKmode && MEM_P (op0))
12576 : : ;
12577 : : /* If neither mode is BLKmode, and both modes are the same size
12578 : : then we can use gen_lowpart. */
12579 : : else if (mode != BLKmode
12580 : 146194 : && GET_MODE (op0) != BLKmode
12581 : 144875 : && known_eq (GET_MODE_PRECISION (mode),
12582 : : GET_MODE_PRECISION (GET_MODE (op0)))
12583 : 140983 : && !COMPLEX_MODE_P (GET_MODE (op0)))
12584 : : {
12585 : 139582 : if (GET_CODE (op0) == SUBREG)
12586 : 124 : op0 = force_reg (GET_MODE (op0), op0);
12587 : 139582 : temp = gen_lowpart_common (mode, op0);
12588 : 139582 : if (temp)
12589 : : op0 = temp;
12590 : : else
12591 : : {
12592 : 27862 : if (!REG_P (op0) && !MEM_P (op0))
12593 : 18 : op0 = force_reg (GET_MODE (op0), op0);
12594 : 27862 : op0 = gen_lowpart (mode, op0);
12595 : : }
12596 : : }
12597 : : /* If both types are integral, convert from one mode to the other. */
12598 : 6637 : else if (INTEGRAL_TYPE_P (type)
12599 : 3140 : && INTEGRAL_TYPE_P (TREE_TYPE (treeop0))
12600 : 0 : && mode != BLKmode
12601 : 6637 : && GET_MODE (op0) != BLKmode)
12602 : 0 : op0 = convert_modes (mode, GET_MODE (op0), op0,
12603 : 0 : TYPE_UNSIGNED (TREE_TYPE (treeop0)));
12604 : : /* If the output type is a bit-field type, do an extraction. */
12605 : 6637 : else if (reduce_bit_field
12606 : 1 : && mode != BLKmode
12607 : 1 : && (MEM_P (op0) || !COMPLEX_MODE_P (GET_MODE (op0))))
12608 : 0 : return extract_bit_field (op0, TYPE_PRECISION (type), 0,
12609 : 0 : TYPE_UNSIGNED (type), NULL_RTX,
12610 : : mode, mode, false, NULL);
12611 : : /* As a last resort, spill op0 to memory, and reload it in a
12612 : : different mode. */
12613 : 6637 : else if (!MEM_P (op0))
12614 : : {
12615 : : /* If the operand is not a MEM, force it into memory. Since we
12616 : : are going to be changing the mode of the MEM, don't call
12617 : : force_const_mem for constants because we don't allow pool
12618 : : constants to change mode. */
12619 : 5313 : tree inner_type = TREE_TYPE (treeop0);
12620 : :
12621 : 5313 : gcc_assert (!TREE_ADDRESSABLE (exp));
12622 : :
12623 : 5313 : if (target == 0 || GET_MODE (target) != TYPE_MODE (inner_type))
12624 : 5307 : target
12625 : : = assign_stack_temp_for_type
12626 : 5307 : (TYPE_MODE (inner_type),
12627 : 10614 : GET_MODE_SIZE (TYPE_MODE (inner_type)), inner_type);
12628 : :
12629 : 5313 : emit_move_insn (target, op0);
12630 : 5313 : op0 = target;
12631 : :
12632 : 5313 : if (reduce_bit_field && mode != BLKmode)
12633 : 1 : return extract_bit_field (op0, TYPE_PRECISION (type), 0,
12634 : 1 : TYPE_UNSIGNED (type), NULL_RTX,
12635 : : mode, mode, false, NULL);
12636 : : }
12637 : :
12638 : : /* If OP0 is (now) a MEM, we need to deal with alignment issues. If the
12639 : : output type is such that the operand is known to be aligned, indicate
12640 : : that it is. Otherwise, we need only be concerned about alignment for
12641 : : non-BLKmode results. */
12642 : 344247 : if (MEM_P (op0))
12643 : : {
12644 : 124707 : enum insn_code icode;
12645 : :
12646 : 124707 : if (modifier != EXPAND_WRITE
12647 : 124707 : && modifier != EXPAND_MEMORY
12648 : 124707 : && !inner_reference_p
12649 : 124707 : && mode != BLKmode
12650 : 175907 : && MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode))
12651 : : {
12652 : : /* If the target does have special handling for unaligned
12653 : : loads of mode then use them. */
12654 : 14473 : if ((icode = optab_handler (movmisalign_optab, mode))
12655 : : != CODE_FOR_nothing)
12656 : : {
12657 : 2081 : rtx reg;
12658 : :
12659 : 2081 : op0 = adjust_address (op0, mode, 0);
12660 : : /* We've already validated the memory, and we're creating a
12661 : : new pseudo destination. The predicates really can't
12662 : : fail. */
12663 : 2081 : reg = gen_reg_rtx (mode);
12664 : :
12665 : : /* Nor can the insn generator. */
12666 : 2081 : rtx_insn *insn = GEN_FCN (icode) (reg, op0);
12667 : 2081 : emit_insn (insn);
12668 : 2081 : return reg;
12669 : : }
12670 : : else if (STRICT_ALIGNMENT)
12671 : : {
12672 : : poly_uint64 mode_size = GET_MODE_SIZE (mode);
12673 : : poly_uint64 temp_size = mode_size;
12674 : : if (GET_MODE (op0) != BLKmode)
12675 : : temp_size = upper_bound (temp_size,
12676 : : GET_MODE_SIZE (GET_MODE (op0)));
12677 : : rtx new_rtx
12678 : : = assign_stack_temp_for_type (mode, temp_size, type);
12679 : : rtx new_with_op0_mode
12680 : : = adjust_address (new_rtx, GET_MODE (op0), 0);
12681 : :
12682 : : gcc_assert (!TREE_ADDRESSABLE (exp));
12683 : :
12684 : : if (GET_MODE (op0) == BLKmode)
12685 : : {
12686 : : rtx size_rtx = gen_int_mode (mode_size, Pmode);
12687 : : emit_block_move (new_with_op0_mode, op0, size_rtx,
12688 : : (modifier == EXPAND_STACK_PARM
12689 : : ? BLOCK_OP_CALL_PARM
12690 : : : BLOCK_OP_NORMAL));
12691 : : }
12692 : : else
12693 : : emit_move_insn (new_with_op0_mode, op0);
12694 : :
12695 : : op0 = new_rtx;
12696 : : }
12697 : : }
12698 : :
12699 : 122626 : op0 = adjust_address (op0, mode, 0);
12700 : : }
12701 : :
12702 : : return op0;
12703 : :
12704 : 62614 : case MODIFY_EXPR:
12705 : 62614 : {
12706 : 62614 : tree lhs = treeop0;
12707 : 62614 : tree rhs = treeop1;
12708 : 62614 : gcc_assert (ignore);
12709 : :
12710 : : /* Check for |= or &= of a bitfield of size one into another bitfield
12711 : : of size 1. In this case, (unless we need the result of the
12712 : : assignment) we can do this more efficiently with a
12713 : : test followed by an assignment, if necessary.
12714 : :
12715 : : ??? At this point, we can't get a BIT_FIELD_REF here. But if
12716 : : things change so we do, this code should be enhanced to
12717 : : support it. */
12718 : 62614 : if (TREE_CODE (lhs) == COMPONENT_REF
12719 : 59720 : && (TREE_CODE (rhs) == BIT_IOR_EXPR
12720 : 59720 : || TREE_CODE (rhs) == BIT_AND_EXPR)
12721 : 0 : && TREE_OPERAND (rhs, 0) == lhs
12722 : 0 : && TREE_CODE (TREE_OPERAND (rhs, 1)) == COMPONENT_REF
12723 : 0 : && integer_onep (DECL_SIZE (TREE_OPERAND (lhs, 1)))
12724 : 62614 : && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs, 1), 1))))
12725 : : {
12726 : 0 : rtx_code_label *label = gen_label_rtx ();
12727 : 0 : int value = TREE_CODE (rhs) == BIT_IOR_EXPR;
12728 : 0 : profile_probability prob = profile_probability::uninitialized ();
12729 : 0 : if (value)
12730 : 0 : jumpifnot (TREE_OPERAND (rhs, 1), label, prob);
12731 : : else
12732 : 0 : jumpif (TREE_OPERAND (rhs, 1), label, prob);
12733 : 0 : expand_assignment (lhs, build_int_cst (TREE_TYPE (rhs), value),
12734 : : false);
12735 : 0 : do_pending_stack_adjust ();
12736 : 0 : emit_label (label);
12737 : 0 : return const0_rtx;
12738 : : }
12739 : :
12740 : 62614 : expand_assignment (lhs, rhs, false);
12741 : 62614 : return const0_rtx;
12742 : : }
12743 : :
12744 : 12864430 : case ADDR_EXPR:
12745 : 12864430 : return expand_expr_addr_expr (exp, target, tmode, modifier);
12746 : :
12747 : 153656 : case REALPART_EXPR:
12748 : 153656 : op0 = expand_normal (treeop0);
12749 : 153656 : return read_complex_part (op0, false);
12750 : :
12751 : 177478 : case IMAGPART_EXPR:
12752 : 177478 : op0 = expand_normal (treeop0);
12753 : 177478 : return read_complex_part (op0, true);
12754 : :
12755 : 0 : case RETURN_EXPR:
12756 : 0 : case LABEL_EXPR:
12757 : 0 : case GOTO_EXPR:
12758 : 0 : case SWITCH_EXPR:
12759 : 0 : case ASM_EXPR:
12760 : : /* Expanded in cfgexpand.cc. */
12761 : 0 : gcc_unreachable ();
12762 : :
12763 : 0 : case TRY_CATCH_EXPR:
12764 : 0 : case CATCH_EXPR:
12765 : 0 : case EH_FILTER_EXPR:
12766 : 0 : case TRY_FINALLY_EXPR:
12767 : 0 : case EH_ELSE_EXPR:
12768 : : /* Lowered by tree-eh.cc. */
12769 : 0 : gcc_unreachable ();
12770 : :
12771 : 0 : case WITH_CLEANUP_EXPR:
12772 : 0 : case CLEANUP_POINT_EXPR:
12773 : 0 : case TARGET_EXPR:
12774 : 0 : case CASE_LABEL_EXPR:
12775 : 0 : case VA_ARG_EXPR:
12776 : 0 : case BIND_EXPR:
12777 : 0 : case INIT_EXPR:
12778 : 0 : case CONJ_EXPR:
12779 : 0 : case COMPOUND_EXPR:
12780 : 0 : case PREINCREMENT_EXPR:
12781 : 0 : case PREDECREMENT_EXPR:
12782 : 0 : case POSTINCREMENT_EXPR:
12783 : 0 : case POSTDECREMENT_EXPR:
12784 : 0 : case LOOP_EXPR:
12785 : 0 : case EXIT_EXPR:
12786 : 0 : case COMPOUND_LITERAL_EXPR:
12787 : : /* Lowered by gimplify.cc. */
12788 : 0 : gcc_unreachable ();
12789 : :
12790 : 0 : case FDESC_EXPR:
12791 : : /* Function descriptors are not valid except for as
12792 : : initialization constants, and should not be expanded. */
12793 : 0 : gcc_unreachable ();
12794 : :
12795 : 256 : case WITH_SIZE_EXPR:
12796 : : /* WITH_SIZE_EXPR expands to its first argument. The caller should
12797 : : have pulled out the size to use in whatever context it needed. */
12798 : 256 : return expand_expr_real (treeop0, original_target, tmode,
12799 : 256 : modifier, alt_rtl, inner_reference_p);
12800 : :
12801 : 1777601 : default:
12802 : 1777601 : return expand_expr_real_2 (&ops, target, tmode, modifier);
12803 : : }
12804 : : }
12805 : : #undef EXTEND_BITINT
12806 : :
12807 : : /* Subroutine of above: reduce EXP to the precision of TYPE (in the
12808 : : signedness of TYPE), possibly returning the result in TARGET.
12809 : : TYPE is known to be a partial integer type. */
12810 : : static rtx
12811 : 84839 : reduce_to_bit_field_precision (rtx exp, rtx target, tree type)
12812 : : {
12813 : 84839 : scalar_int_mode mode = SCALAR_INT_TYPE_MODE (type);
12814 : 84839 : HOST_WIDE_INT prec = TYPE_PRECISION (type);
12815 : 84839 : gcc_assert ((GET_MODE (exp) == VOIDmode || GET_MODE (exp) == mode)
12816 : : && (!target || GET_MODE (target) == mode));
12817 : :
12818 : : /* For constant values, reduce using wide_int_to_tree. */
12819 : 84839 : if (poly_int_rtx_p (exp))
12820 : : {
12821 : 2 : auto value = wi::to_poly_wide (exp, mode);
12822 : 2 : tree t = wide_int_to_tree (type, value);
12823 : 2 : return expand_expr (t, target, VOIDmode, EXPAND_NORMAL);
12824 : : }
12825 : 84837 : else if (TYPE_UNSIGNED (type))
12826 : : {
12827 : 66830 : rtx mask = immed_wide_int_const
12828 : 66830 : (wi::mask (prec, false, GET_MODE_PRECISION (mode)), mode);
12829 : 66830 : return expand_and (mode, exp, mask, target);
12830 : : }
12831 : : else
12832 : : {
12833 : 18007 : int count = GET_MODE_PRECISION (mode) - prec;
12834 : 18007 : exp = expand_shift (LSHIFT_EXPR, mode, exp, count, target, 0);
12835 : 18007 : return expand_shift (RSHIFT_EXPR, mode, exp, count, target, 0);
12836 : : }
12837 : : }
12838 : :
12839 : : /* Subroutine of above: returns true if OFFSET corresponds to an offset that
12840 : : when applied to the address of EXP produces an address known to be
12841 : : aligned more than BIGGEST_ALIGNMENT. */
12842 : :
12843 : : static bool
12844 : 272140 : is_aligning_offset (const_tree offset, const_tree exp)
12845 : : {
12846 : : /* Strip off any conversions. */
12847 : 292847 : while (CONVERT_EXPR_P (offset))
12848 : 20707 : offset = TREE_OPERAND (offset, 0);
12849 : :
12850 : : /* We must now have a BIT_AND_EXPR with a constant that is one less than
12851 : : power of 2 and which is larger than BIGGEST_ALIGNMENT. */
12852 : 272140 : if (TREE_CODE (offset) != BIT_AND_EXPR
12853 : 0 : || !tree_fits_uhwi_p (TREE_OPERAND (offset, 1))
12854 : 0 : || compare_tree_int (TREE_OPERAND (offset, 1),
12855 : 0 : BIGGEST_ALIGNMENT / BITS_PER_UNIT) <= 0
12856 : 272140 : || !pow2p_hwi (tree_to_uhwi (TREE_OPERAND (offset, 1)) + 1))
12857 : 272140 : return false;
12858 : :
12859 : : /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
12860 : : It must be NEGATE_EXPR. Then strip any more conversions. */
12861 : 0 : offset = TREE_OPERAND (offset, 0);
12862 : 0 : while (CONVERT_EXPR_P (offset))
12863 : 0 : offset = TREE_OPERAND (offset, 0);
12864 : :
12865 : 0 : if (TREE_CODE (offset) != NEGATE_EXPR)
12866 : : return false;
12867 : :
12868 : 0 : offset = TREE_OPERAND (offset, 0);
12869 : 0 : while (CONVERT_EXPR_P (offset))
12870 : 0 : offset = TREE_OPERAND (offset, 0);
12871 : :
12872 : : /* This must now be the address of EXP. */
12873 : 0 : return TREE_CODE (offset) == ADDR_EXPR && TREE_OPERAND (offset, 0) == exp;
12874 : : }
12875 : :
12876 : : /* Return a STRING_CST corresponding to ARG's constant initializer either
12877 : : if it's a string constant, or, when VALREP is set, any other constant,
12878 : : or null otherwise.
12879 : : On success, set *PTR_OFFSET to the (possibly non-constant) byte offset
12880 : : within the byte string that ARG is references. If nonnull set *MEM_SIZE
12881 : : to the size of the byte string. If nonnull, set *DECL to the constant
12882 : : declaration ARG refers to. */
12883 : :
12884 : : static tree
12885 : 15661043 : constant_byte_string (tree arg, tree *ptr_offset, tree *mem_size, tree *decl,
12886 : : bool valrep = false)
12887 : : {
12888 : 15661043 : tree dummy = NULL_TREE;
12889 : 15661043 : if (!mem_size)
12890 : 10423 : mem_size = &dummy;
12891 : :
12892 : : /* Store the type of the original expression before conversions
12893 : : via NOP_EXPR or POINTER_PLUS_EXPR to other types have been
12894 : : removed. */
12895 : 15661043 : tree argtype = TREE_TYPE (arg);
12896 : :
12897 : 15661043 : tree array;
12898 : 15661043 : STRIP_NOPS (arg);
12899 : :
12900 : : /* Non-constant index into the character array in an ARRAY_REF
12901 : : expression or null. */
12902 : 15661043 : tree varidx = NULL_TREE;
12903 : :
12904 : 15661043 : poly_int64 base_off = 0;
12905 : :
12906 : 15661043 : if (TREE_CODE (arg) == ADDR_EXPR)
12907 : : {
12908 : 6527099 : arg = TREE_OPERAND (arg, 0);
12909 : 6527099 : tree ref = arg;
12910 : 6527099 : if (TREE_CODE (arg) == ARRAY_REF)
12911 : : {
12912 : 562801 : tree idx = TREE_OPERAND (arg, 1);
12913 : 562801 : if (TREE_CODE (idx) != INTEGER_CST)
12914 : : {
12915 : : /* From a pointer (but not array) argument extract the variable
12916 : : index to prevent get_addr_base_and_unit_offset() from failing
12917 : : due to it. Use it later to compute the non-constant offset
12918 : : into the string and return it to the caller. */
12919 : 167625 : varidx = idx;
12920 : 167625 : ref = TREE_OPERAND (arg, 0);
12921 : :
12922 : 167625 : if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE)
12923 : : return NULL_TREE;
12924 : :
12925 : 27986 : if (!integer_zerop (array_ref_low_bound (arg)))
12926 : : return NULL_TREE;
12927 : :
12928 : 27232 : if (!integer_onep (array_ref_element_size (arg)))
12929 : : return NULL_TREE;
12930 : : }
12931 : : }
12932 : 6385602 : array = get_addr_base_and_unit_offset (ref, &base_off);
12933 : 6385602 : if (!array
12934 : 6338889 : || (TREE_CODE (array) != VAR_DECL
12935 : 6338889 : && TREE_CODE (array) != CONST_DECL
12936 : 3851524 : && TREE_CODE (array) != STRING_CST))
12937 : : return NULL_TREE;
12938 : : }
12939 : 9133944 : else if (TREE_CODE (arg) == PLUS_EXPR || TREE_CODE (arg) == POINTER_PLUS_EXPR)
12940 : : {
12941 : 26456 : tree arg0 = TREE_OPERAND (arg, 0);
12942 : 26456 : tree arg1 = TREE_OPERAND (arg, 1);
12943 : :
12944 : 26456 : tree offset;
12945 : 26456 : tree str = string_constant (arg0, &offset, mem_size, decl);
12946 : 26456 : if (!str)
12947 : : {
12948 : 17131 : str = string_constant (arg1, &offset, mem_size, decl);
12949 : 17131 : arg1 = arg0;
12950 : : }
12951 : :
12952 : 17131 : if (str)
12953 : : {
12954 : : /* Avoid pointers to arrays (see bug 86622). */
12955 : 9325 : if (POINTER_TYPE_P (TREE_TYPE (arg))
12956 : 9325 : && TREE_CODE (TREE_TYPE (TREE_TYPE (arg))) == ARRAY_TYPE
12957 : 2100 : && !(decl && !*decl)
12958 : 12125 : && !(decl && tree_fits_uhwi_p (DECL_SIZE_UNIT (*decl))
12959 : 1400 : && tree_fits_uhwi_p (*mem_size)
12960 : 1400 : && tree_int_cst_equal (*mem_size, DECL_SIZE_UNIT (*decl))))
12961 : 2100 : return NULL_TREE;
12962 : :
12963 : 7225 : tree type = TREE_TYPE (offset);
12964 : 7225 : arg1 = fold_convert (type, arg1);
12965 : 7225 : *ptr_offset = fold_build2 (PLUS_EXPR, type, offset, arg1);
12966 : 7225 : return str;
12967 : : }
12968 : : return NULL_TREE;
12969 : : }
12970 : 9107488 : else if (TREE_CODE (arg) == SSA_NAME)
12971 : : {
12972 : 3924380 : gimple *stmt = SSA_NAME_DEF_STMT (arg);
12973 : 3924380 : if (!is_gimple_assign (stmt))
12974 : : return NULL_TREE;
12975 : :
12976 : 1012308 : tree rhs1 = gimple_assign_rhs1 (stmt);
12977 : 1012308 : tree_code code = gimple_assign_rhs_code (stmt);
12978 : 1012308 : if (code == ADDR_EXPR)
12979 : 224674 : return string_constant (rhs1, ptr_offset, mem_size, decl);
12980 : 787634 : else if (code != POINTER_PLUS_EXPR)
12981 : : return NULL_TREE;
12982 : :
12983 : 188920 : tree offset;
12984 : 188920 : if (tree str = string_constant (rhs1, &offset, mem_size, decl))
12985 : : {
12986 : : /* Avoid pointers to arrays (see bug 86622). */
12987 : 21700 : if (POINTER_TYPE_P (TREE_TYPE (rhs1))
12988 : 21700 : && TREE_CODE (TREE_TYPE (TREE_TYPE (rhs1))) == ARRAY_TYPE
12989 : 18919 : && !(decl && !*decl)
12990 : 37906 : && !(decl && tree_fits_uhwi_p (DECL_SIZE_UNIT (*decl))
12991 : 8103 : && tree_fits_uhwi_p (*mem_size)
12992 : 8103 : && tree_int_cst_equal (*mem_size, DECL_SIZE_UNIT (*decl))))
12993 : 14834 : return NULL_TREE;
12994 : :
12995 : 6866 : tree rhs2 = gimple_assign_rhs2 (stmt);
12996 : 6866 : tree type = TREE_TYPE (offset);
12997 : 6866 : rhs2 = fold_convert (type, rhs2);
12998 : 6866 : *ptr_offset = fold_build2 (PLUS_EXPR, type, offset, rhs2);
12999 : 6866 : return str;
13000 : : }
13001 : : return NULL_TREE;
13002 : : }
13003 : 5183108 : else if (DECL_P (arg))
13004 : : array = arg;
13005 : : else
13006 : : return NULL_TREE;
13007 : :
13008 : 8700873 : tree offset = wide_int_to_tree (sizetype, base_off);
13009 : 8700873 : if (varidx)
13010 : : {
13011 : 2143 : if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE)
13012 : : return NULL_TREE;
13013 : :
13014 : 1632 : gcc_assert (TREE_CODE (arg) == ARRAY_REF);
13015 : 1632 : tree chartype = TREE_TYPE (TREE_TYPE (TREE_OPERAND (arg, 0)));
13016 : 1632 : if (TREE_CODE (chartype) != INTEGER_TYPE)
13017 : : return NULL;
13018 : :
13019 : 1475 : offset = fold_convert (sizetype, varidx);
13020 : : }
13021 : :
13022 : 8700205 : if (TREE_CODE (array) == STRING_CST)
13023 : : {
13024 : 3474999 : *ptr_offset = fold_convert (sizetype, offset);
13025 : 3474999 : *mem_size = TYPE_SIZE_UNIT (TREE_TYPE (array));
13026 : 3474999 : if (decl)
13027 : 772800 : *decl = NULL_TREE;
13028 : 3474999 : gcc_checking_assert (tree_to_shwi (TYPE_SIZE_UNIT (TREE_TYPE (array)))
13029 : : >= TREE_STRING_LENGTH (array));
13030 : : return array;
13031 : : }
13032 : :
13033 : 5225206 : tree init = ctor_for_folding (array);
13034 : 5225206 : if (!init || init == error_mark_node)
13035 : : return NULL_TREE;
13036 : :
13037 : 157129 : if (valrep)
13038 : : {
13039 : 59339 : HOST_WIDE_INT cstoff;
13040 : 59339 : if (!base_off.is_constant (&cstoff))
13041 : : return NULL_TREE;
13042 : :
13043 : : /* Check that the host and target are sane. */
13044 : 59339 : if (CHAR_BIT != 8 || BITS_PER_UNIT != 8)
13045 : : return NULL_TREE;
13046 : :
13047 : 59339 : HOST_WIDE_INT typesz = int_size_in_bytes (TREE_TYPE (init));
13048 : 59339 : if (typesz <= 0 || (int) typesz != typesz)
13049 : : return NULL_TREE;
13050 : :
13051 : 59169 : HOST_WIDE_INT size = typesz;
13052 : 59169 : if (VAR_P (array)
13053 : 59157 : && DECL_SIZE_UNIT (array)
13054 : 118326 : && tree_fits_shwi_p (DECL_SIZE_UNIT (array)))
13055 : : {
13056 : 59157 : size = tree_to_shwi (DECL_SIZE_UNIT (array));
13057 : 59157 : gcc_checking_assert (size >= typesz);
13058 : : }
13059 : :
13060 : : /* If value representation was requested convert the initializer
13061 : : for the whole array or object into a string of bytes forming
13062 : : its value representation and return it. */
13063 : 59169 : unsigned char *bytes = XNEWVEC (unsigned char, size);
13064 : 59169 : int r = native_encode_initializer (init, bytes, size);
13065 : 59169 : if (r < typesz)
13066 : : {
13067 : 59 : XDELETEVEC (bytes);
13068 : 59 : return NULL_TREE;
13069 : : }
13070 : :
13071 : 59110 : if (r < size)
13072 : 0 : memset (bytes + r, '\0', size - r);
13073 : :
13074 : 59110 : const char *p = reinterpret_cast<const char *>(bytes);
13075 : 59110 : init = build_string_literal (size, p, char_type_node);
13076 : 59110 : init = TREE_OPERAND (init, 0);
13077 : 59110 : init = TREE_OPERAND (init, 0);
13078 : 59110 : XDELETE (bytes);
13079 : :
13080 : 59110 : *mem_size = size_int (TREE_STRING_LENGTH (init));
13081 : 59110 : *ptr_offset = wide_int_to_tree (ssizetype, base_off);
13082 : :
13083 : 59110 : if (decl)
13084 : 0 : *decl = array;
13085 : :
13086 : 59110 : return init;
13087 : : }
13088 : :
13089 : 97790 : if (TREE_CODE (init) == CONSTRUCTOR)
13090 : : {
13091 : : /* Convert the 64-bit constant offset to a wider type to avoid
13092 : : overflow and use it to obtain the initializer for the subobject
13093 : : it points into. */
13094 : 79570 : offset_int wioff;
13095 : 79570 : if (!base_off.is_constant (&wioff))
13096 : 158 : return NULL_TREE;
13097 : :
13098 : 79570 : wioff *= BITS_PER_UNIT;
13099 : 79570 : if (!wi::fits_uhwi_p (wioff))
13100 : : return NULL_TREE;
13101 : :
13102 : 79462 : base_off = wioff.to_uhwi ();
13103 : 79462 : unsigned HOST_WIDE_INT fieldoff = 0;
13104 : 79462 : init = fold_ctor_reference (TREE_TYPE (arg), init, base_off, 0, array,
13105 : : &fieldoff);
13106 : 79462 : if (!init || init == error_mark_node)
13107 : : return NULL_TREE;
13108 : :
13109 : 79412 : HOST_WIDE_INT cstoff;
13110 : 79412 : if (!base_off.is_constant (&cstoff))
13111 : : return NULL_TREE;
13112 : :
13113 : 79412 : cstoff = (cstoff - fieldoff) / BITS_PER_UNIT;
13114 : 79412 : tree off = build_int_cst (sizetype, cstoff);
13115 : 79412 : if (varidx)
13116 : 944 : offset = fold_build2 (PLUS_EXPR, TREE_TYPE (offset), offset, off);
13117 : : else
13118 : : offset = off;
13119 : : }
13120 : :
13121 : 97632 : *ptr_offset = offset;
13122 : :
13123 : 97632 : tree inittype = TREE_TYPE (init);
13124 : :
13125 : 97632 : if (TREE_CODE (init) == INTEGER_CST
13126 : 97632 : && (TREE_CODE (TREE_TYPE (array)) == INTEGER_TYPE
13127 : 1277 : || TYPE_MAIN_VARIANT (inittype) == char_type_node))
13128 : : {
13129 : : /* Check that the host and target are sane. */
13130 : 945 : if (CHAR_BIT != 8 || BITS_PER_UNIT != 8)
13131 : : return NULL_TREE;
13132 : :
13133 : : /* For a reference to (address of) a single constant character,
13134 : : store the native representation of the character in CHARBUF.
13135 : : If the reference is to an element of an array or a member
13136 : : of a struct, only consider narrow characters until ctors
13137 : : for wide character arrays are transformed to STRING_CSTs
13138 : : like those for narrow arrays. */
13139 : 945 : unsigned char charbuf[MAX_BITSIZE_MODE_ANY_MODE / BITS_PER_UNIT];
13140 : 945 : int len = native_encode_expr (init, charbuf, sizeof charbuf, 0);
13141 : 945 : if (len > 0)
13142 : : {
13143 : : /* Construct a string literal with elements of INITTYPE and
13144 : : the representation above. Then strip
13145 : : the ADDR_EXPR (ARRAY_REF (...)) around the STRING_CST. */
13146 : 945 : init = build_string_literal (len, (char *)charbuf, inittype);
13147 : 945 : init = TREE_OPERAND (TREE_OPERAND (init, 0), 0);
13148 : : }
13149 : : }
13150 : :
13151 : 97632 : tree initsize = TYPE_SIZE_UNIT (inittype);
13152 : :
13153 : 97632 : if (TREE_CODE (init) == CONSTRUCTOR && initializer_zerop (init))
13154 : : {
13155 : : /* Fold an empty/zero constructor for an implicitly initialized
13156 : : object or subobject into the empty string. */
13157 : :
13158 : : /* Determine the character type from that of the original
13159 : : expression. */
13160 : 9538 : tree chartype = argtype;
13161 : 9538 : if (POINTER_TYPE_P (chartype))
13162 : 9531 : chartype = TREE_TYPE (chartype);
13163 : 15372 : while (TREE_CODE (chartype) == ARRAY_TYPE)
13164 : 5834 : chartype = TREE_TYPE (chartype);
13165 : :
13166 : 9538 : if (INTEGRAL_TYPE_P (chartype)
13167 : 9538 : && TYPE_PRECISION (chartype) == TYPE_PRECISION (char_type_node))
13168 : : {
13169 : : /* Convert a char array to an empty STRING_CST having an array
13170 : : of the expected type and size. */
13171 : 9145 : if (!initsize)
13172 : 3090 : initsize = integer_zero_node;
13173 : :
13174 : 9145 : unsigned HOST_WIDE_INT size = tree_to_uhwi (initsize);
13175 : 9145 : if (size > (unsigned HOST_WIDE_INT) INT_MAX)
13176 : : return NULL_TREE;
13177 : :
13178 : 9145 : init = build_string_literal (size, NULL, chartype, size);
13179 : 9145 : init = TREE_OPERAND (init, 0);
13180 : 9145 : init = TREE_OPERAND (init, 0);
13181 : :
13182 : 9145 : *ptr_offset = integer_zero_node;
13183 : : }
13184 : : }
13185 : :
13186 : 97632 : if (decl)
13187 : 55479 : *decl = array;
13188 : :
13189 : 97632 : if (TREE_CODE (init) != STRING_CST)
13190 : : return NULL_TREE;
13191 : :
13192 : 67438 : *mem_size = initsize;
13193 : :
13194 : 67438 : gcc_checking_assert (tree_to_shwi (initsize) >= TREE_STRING_LENGTH (init));
13195 : :
13196 : : return init;
13197 : : }
13198 : :
13199 : : /* Return STRING_CST if an ARG corresponds to a string constant or zero
13200 : : if it doesn't. If we return nonzero, set *PTR_OFFSET to the (possibly
13201 : : non-constant) offset in bytes within the string that ARG is accessing.
13202 : : If MEM_SIZE is non-zero the storage size of the memory is returned.
13203 : : If DECL is non-zero the constant declaration is returned if available. */
13204 : :
13205 : : tree
13206 : 10808580 : string_constant (tree arg, tree *ptr_offset, tree *mem_size, tree *decl)
13207 : : {
13208 : 10808580 : return constant_byte_string (arg, ptr_offset, mem_size, decl, false);
13209 : : }
13210 : :
13211 : : /* Similar to string_constant, return a STRING_CST corresponding
13212 : : to the value representation of the first argument if it's
13213 : : a constant. */
13214 : :
13215 : : tree
13216 : 4852463 : byte_representation (tree arg, tree *ptr_offset, tree *mem_size, tree *decl)
13217 : : {
13218 : 4852463 : return constant_byte_string (arg, ptr_offset, mem_size, decl, true);
13219 : : }
13220 : :
13221 : : /* Optimize x % C1 == C2 for signed modulo if C1 is a power of two and C2
13222 : : is non-zero and C3 ((1<<(prec-1)) | (C1 - 1)):
13223 : : for C2 > 0 to x & C3 == C2
13224 : : for C2 < 0 to x & C3 == (C2 & C3). */
13225 : : enum tree_code
13226 : 35 : maybe_optimize_pow2p_mod_cmp (enum tree_code code, tree *arg0, tree *arg1)
13227 : : {
13228 : 35 : gimple *stmt = get_def_for_expr (*arg0, TRUNC_MOD_EXPR);
13229 : 35 : tree treeop0 = gimple_assign_rhs1 (stmt);
13230 : 35 : tree treeop1 = gimple_assign_rhs2 (stmt);
13231 : 35 : tree type = TREE_TYPE (*arg0);
13232 : 35 : scalar_int_mode mode;
13233 : 35 : if (!is_a <scalar_int_mode> (TYPE_MODE (type), &mode))
13234 : : return code;
13235 : 70 : if (GET_MODE_BITSIZE (mode) != TYPE_PRECISION (type)
13236 : 35 : || TYPE_PRECISION (type) <= 1
13237 : 35 : || TYPE_UNSIGNED (type)
13238 : : /* Signed x % c == 0 should have been optimized into unsigned modulo
13239 : : earlier. */
13240 : 35 : || integer_zerop (*arg1)
13241 : : /* If c is known to be non-negative, modulo will be expanded as unsigned
13242 : : modulo. */
13243 : 70 : || get_range_pos_neg (treeop0) == 1)
13244 : 0 : return code;
13245 : :
13246 : : /* x % c == d where d < 0 && d <= -c should be always false. */
13247 : 35 : if (tree_int_cst_sgn (*arg1) == -1
13248 : 51 : && -wi::to_widest (treeop1) >= wi::to_widest (*arg1))
13249 : : return code;
13250 : :
13251 : 35 : int prec = TYPE_PRECISION (type);
13252 : 35 : wide_int w = wi::to_wide (treeop1) - 1;
13253 : 35 : w |= wi::shifted_mask (0, prec - 1, true, prec);
13254 : 35 : tree c3 = wide_int_to_tree (type, w);
13255 : 35 : tree c4 = *arg1;
13256 : 35 : if (tree_int_cst_sgn (*arg1) == -1)
13257 : 16 : c4 = wide_int_to_tree (type, w & wi::to_wide (*arg1));
13258 : :
13259 : 35 : rtx op0 = expand_normal (treeop0);
13260 : 35 : treeop0 = make_tree (TREE_TYPE (treeop0), op0);
13261 : :
13262 : 35 : bool speed_p = optimize_insn_for_speed_p ();
13263 : :
13264 : 35 : do_pending_stack_adjust ();
13265 : :
13266 : 35 : location_t loc = gimple_location (stmt);
13267 : 35 : struct separate_ops ops;
13268 : 35 : ops.code = TRUNC_MOD_EXPR;
13269 : 35 : ops.location = loc;
13270 : 35 : ops.type = TREE_TYPE (treeop0);
13271 : 35 : ops.op0 = treeop0;
13272 : 35 : ops.op1 = treeop1;
13273 : 35 : ops.op2 = NULL_TREE;
13274 : 35 : start_sequence ();
13275 : 35 : rtx mor = expand_expr_real_2 (&ops, NULL_RTX, TYPE_MODE (ops.type),
13276 : : EXPAND_NORMAL);
13277 : 35 : rtx_insn *moinsns = get_insns ();
13278 : 35 : end_sequence ();
13279 : :
13280 : 35 : unsigned mocost = seq_cost (moinsns, speed_p);
13281 : 35 : mocost += rtx_cost (mor, mode, EQ, 0, speed_p);
13282 : 35 : mocost += rtx_cost (expand_normal (*arg1), mode, EQ, 1, speed_p);
13283 : :
13284 : 35 : ops.code = BIT_AND_EXPR;
13285 : 35 : ops.location = loc;
13286 : 35 : ops.type = TREE_TYPE (treeop0);
13287 : 35 : ops.op0 = treeop0;
13288 : 35 : ops.op1 = c3;
13289 : 35 : ops.op2 = NULL_TREE;
13290 : 35 : start_sequence ();
13291 : 35 : rtx mur = expand_expr_real_2 (&ops, NULL_RTX, TYPE_MODE (ops.type),
13292 : : EXPAND_NORMAL);
13293 : 35 : rtx_insn *muinsns = get_insns ();
13294 : 35 : end_sequence ();
13295 : :
13296 : 35 : unsigned mucost = seq_cost (muinsns, speed_p);
13297 : 35 : mucost += rtx_cost (mur, mode, EQ, 0, speed_p);
13298 : 35 : mucost += rtx_cost (expand_normal (c4), mode, EQ, 1, speed_p);
13299 : :
13300 : 35 : if (mocost <= mucost)
13301 : : {
13302 : 0 : emit_insn (moinsns);
13303 : 0 : *arg0 = make_tree (TREE_TYPE (*arg0), mor);
13304 : 0 : return code;
13305 : : }
13306 : :
13307 : 35 : emit_insn (muinsns);
13308 : 35 : *arg0 = make_tree (TREE_TYPE (*arg0), mur);
13309 : 35 : *arg1 = c4;
13310 : 35 : return code;
13311 : 35 : }
13312 : :
13313 : : /* Attempt to optimize unsigned (X % C1) == C2 (or (X % C1) != C2).
13314 : : If C1 is odd to:
13315 : : (X - C2) * C3 <= C4 (or >), where
13316 : : C3 is modular multiplicative inverse of C1 and 1<<prec and
13317 : : C4 is ((1<<prec) - 1) / C1 or ((1<<prec) - 1) / C1 - 1 (the latter
13318 : : if C2 > ((1<<prec) - 1) % C1).
13319 : : If C1 is even, S = ctz (C1) and C2 is 0, use
13320 : : ((X * C3) r>> S) <= C4, where C3 is modular multiplicative
13321 : : inverse of C1>>S and 1<<prec and C4 is (((1<<prec) - 1) / (C1>>S)) >> S.
13322 : :
13323 : : For signed (X % C1) == 0 if C1 is odd to (all operations in it
13324 : : unsigned):
13325 : : (X * C3) + C4 <= 2 * C4, where
13326 : : C3 is modular multiplicative inverse of (unsigned) C1 and 1<<prec and
13327 : : C4 is ((1<<(prec - 1) - 1) / C1).
13328 : : If C1 is even, S = ctz(C1), use
13329 : : ((X * C3) + C4) r>> S <= (C4 >> (S - 1))
13330 : : where C3 is modular multiplicative inverse of (unsigned)(C1>>S) and 1<<prec
13331 : : and C4 is ((1<<(prec - 1) - 1) / (C1>>S)) & (-1<<S).
13332 : :
13333 : : See the Hacker's Delight book, section 10-17. */
13334 : : enum tree_code
13335 : 3208388 : maybe_optimize_mod_cmp (enum tree_code code, tree *arg0, tree *arg1)
13336 : : {
13337 : 3208388 : gcc_checking_assert (code == EQ_EXPR || code == NE_EXPR);
13338 : 3208388 : gcc_checking_assert (TREE_CODE (*arg1) == INTEGER_CST);
13339 : :
13340 : 3208388 : if (optimize < 2)
13341 : : return code;
13342 : :
13343 : 2423075 : gimple *stmt = get_def_for_expr (*arg0, TRUNC_MOD_EXPR);
13344 : 2423075 : if (stmt == NULL)
13345 : : return code;
13346 : :
13347 : 2238 : tree treeop0 = gimple_assign_rhs1 (stmt);
13348 : 2238 : tree treeop1 = gimple_assign_rhs2 (stmt);
13349 : 2238 : if (TREE_CODE (treeop0) != SSA_NAME
13350 : 2153 : || TREE_CODE (treeop1) != INTEGER_CST
13351 : : /* Don't optimize the undefined behavior case x % 0;
13352 : : x % 1 should have been optimized into zero, punt if
13353 : : it makes it here for whatever reason;
13354 : : x % -c should have been optimized into x % c. */
13355 : 1798 : || compare_tree_int (treeop1, 2) <= 0
13356 : : /* Likewise x % c == d where d >= c should be always false. */
13357 : 3949 : || tree_int_cst_le (treeop1, *arg1))
13358 : 527 : return code;
13359 : :
13360 : : /* Unsigned x % pow2 is handled right already, for signed
13361 : : modulo handle it in maybe_optimize_pow2p_mod_cmp. */
13362 : 1711 : if (integer_pow2p (treeop1))
13363 : 35 : return maybe_optimize_pow2p_mod_cmp (code, arg0, arg1);
13364 : :
13365 : 1676 : tree type = TREE_TYPE (*arg0);
13366 : 1676 : scalar_int_mode mode;
13367 : 3208360 : if (!is_a <scalar_int_mode> (TYPE_MODE (type), &mode))
13368 : : return code;
13369 : 3352 : if (GET_MODE_BITSIZE (mode) != TYPE_PRECISION (type)
13370 : 1676 : || TYPE_PRECISION (type) <= 1)
13371 : : return code;
13372 : :
13373 : 1676 : signop sgn = UNSIGNED;
13374 : : /* If both operands are known to have the sign bit clear, handle
13375 : : even the signed modulo case as unsigned. treeop1 is always
13376 : : positive >= 2, checked above. */
13377 : 1676 : if (!TYPE_UNSIGNED (type) && get_range_pos_neg (treeop0) != 1)
13378 : : sgn = SIGNED;
13379 : :
13380 : 1676 : if (!TYPE_UNSIGNED (type))
13381 : : {
13382 : 1451 : if (tree_int_cst_sgn (*arg1) == -1)
13383 : : return code;
13384 : 1444 : type = unsigned_type_for (type);
13385 : 1444 : if (!type || TYPE_MODE (type) != TYPE_MODE (TREE_TYPE (*arg0)))
13386 : 0 : return code;
13387 : : }
13388 : :
13389 : 1669 : int prec = TYPE_PRECISION (type);
13390 : 1669 : wide_int w = wi::to_wide (treeop1);
13391 : 1669 : int shift = wi::ctz (w);
13392 : : /* Unsigned (X % C1) == C2 is equivalent to (X - C2) % C1 == 0 if
13393 : : C2 <= -1U % C1, because for any Z >= 0U - C2 in that case (Z % C1) != 0.
13394 : : If C1 is odd, we can handle all cases by subtracting
13395 : : C4 below. We could handle even the even C1 and C2 > -1U % C1 cases
13396 : : e.g. by testing for overflow on the subtraction, punt on that for now
13397 : : though. */
13398 : 1669 : if ((sgn == SIGNED || shift) && !integer_zerop (*arg1))
13399 : : {
13400 : 183 : if (sgn == SIGNED)
13401 : 168 : return code;
13402 : 26 : wide_int x = wi::umod_trunc (wi::mask (prec, false, prec), w);
13403 : 26 : if (wi::gtu_p (wi::to_wide (*arg1), x))
13404 : 11 : return code;
13405 : 26 : }
13406 : :
13407 : 1501 : imm_use_iterator imm_iter;
13408 : 1501 : use_operand_p use_p;
13409 : 10871 : FOR_EACH_IMM_USE_FAST (use_p, imm_iter, treeop0)
13410 : : {
13411 : 9371 : gimple *use_stmt = USE_STMT (use_p);
13412 : : /* Punt if treeop0 is used in the same bb in a division
13413 : : or another modulo with the same divisor. We should expect
13414 : : the division and modulo combined together. */
13415 : 18408 : if (use_stmt == stmt
13416 : 9371 : || gimple_bb (use_stmt) != gimple_bb (stmt))
13417 : 9037 : continue;
13418 : 334 : if (!is_gimple_assign (use_stmt)
13419 : 334 : || (gimple_assign_rhs_code (use_stmt) != TRUNC_DIV_EXPR
13420 : 327 : && gimple_assign_rhs_code (use_stmt) != TRUNC_MOD_EXPR))
13421 : 324 : continue;
13422 : 10 : if (gimple_assign_rhs1 (use_stmt) != treeop0
13423 : 10 : || !operand_equal_p (gimple_assign_rhs2 (use_stmt), treeop1, 0))
13424 : 9 : continue;
13425 : : return code;
13426 : : }
13427 : :
13428 : 1500 : w = wi::lrshift (w, shift);
13429 : 1500 : wide_int a = wide_int::from (w, prec + 1, UNSIGNED);
13430 : 1500 : wide_int b = wi::shifted_mask (prec, 1, false, prec + 1);
13431 : 1500 : wide_int m = wide_int::from (wi::mod_inv (a, b), prec, UNSIGNED);
13432 : 1500 : tree c3 = wide_int_to_tree (type, m);
13433 : 1500 : tree c5 = NULL_TREE;
13434 : 1500 : wide_int d, e;
13435 : 1500 : if (sgn == UNSIGNED)
13436 : : {
13437 : 758 : d = wi::divmod_trunc (wi::mask (prec, false, prec), w, UNSIGNED, &e);
13438 : : /* Use <= floor ((1<<prec) - 1) / C1 only if C2 <= ((1<<prec) - 1) % C1,
13439 : : otherwise use < or subtract one from C4. E.g. for
13440 : : x % 3U == 0 we transform this into x * 0xaaaaaaab <= 0x55555555, but
13441 : : x % 3U == 1 already needs to be
13442 : : (x - 1) * 0xaaaaaaabU <= 0x55555554. */
13443 : 758 : if (!shift && wi::gtu_p (wi::to_wide (*arg1), e))
13444 : 19 : d -= 1;
13445 : 758 : if (shift)
13446 : 278 : d = wi::lrshift (d, shift);
13447 : : }
13448 : : else
13449 : : {
13450 : 742 : e = wi::udiv_trunc (wi::mask (prec - 1, false, prec), w);
13451 : 742 : if (!shift)
13452 : 379 : d = wi::lshift (e, 1);
13453 : : else
13454 : : {
13455 : 363 : e = wi::bit_and (e, wi::mask (shift, true, prec));
13456 : 363 : d = wi::lrshift (e, shift - 1);
13457 : : }
13458 : 742 : c5 = wide_int_to_tree (type, e);
13459 : : }
13460 : 1500 : tree c4 = wide_int_to_tree (type, d);
13461 : :
13462 : 1500 : rtx op0 = expand_normal (treeop0);
13463 : 1500 : treeop0 = make_tree (TREE_TYPE (treeop0), op0);
13464 : :
13465 : 1500 : bool speed_p = optimize_insn_for_speed_p ();
13466 : :
13467 : 1500 : do_pending_stack_adjust ();
13468 : :
13469 : 1500 : location_t loc = gimple_location (stmt);
13470 : 1500 : struct separate_ops ops;
13471 : 1500 : ops.code = TRUNC_MOD_EXPR;
13472 : 1500 : ops.location = loc;
13473 : 1500 : ops.type = TREE_TYPE (treeop0);
13474 : 1500 : ops.op0 = treeop0;
13475 : 1500 : ops.op1 = treeop1;
13476 : 1500 : ops.op2 = NULL_TREE;
13477 : 1500 : start_sequence ();
13478 : 1500 : rtx mor = expand_expr_real_2 (&ops, NULL_RTX, TYPE_MODE (ops.type),
13479 : : EXPAND_NORMAL);
13480 : 1500 : rtx_insn *moinsns = get_insns ();
13481 : 1500 : end_sequence ();
13482 : :
13483 : 1500 : unsigned mocost = seq_cost (moinsns, speed_p);
13484 : 1500 : mocost += rtx_cost (mor, mode, EQ, 0, speed_p);
13485 : 1500 : mocost += rtx_cost (expand_normal (*arg1), mode, EQ, 1, speed_p);
13486 : :
13487 : 1500 : tree t = fold_convert_loc (loc, type, treeop0);
13488 : 1500 : if (!integer_zerop (*arg1))
13489 : 44 : t = fold_build2_loc (loc, MINUS_EXPR, type, t, fold_convert (type, *arg1));
13490 : 1500 : t = fold_build2_loc (loc, MULT_EXPR, type, t, c3);
13491 : 1500 : if (sgn == SIGNED)
13492 : 742 : t = fold_build2_loc (loc, PLUS_EXPR, type, t, c5);
13493 : 1500 : if (shift)
13494 : : {
13495 : 641 : tree s = build_int_cst (NULL_TREE, shift);
13496 : 641 : t = fold_build2_loc (loc, RROTATE_EXPR, type, t, s);
13497 : : }
13498 : :
13499 : 1500 : start_sequence ();
13500 : 1500 : rtx mur = expand_normal (t);
13501 : 1500 : rtx_insn *muinsns = get_insns ();
13502 : 1500 : end_sequence ();
13503 : :
13504 : 1500 : unsigned mucost = seq_cost (muinsns, speed_p);
13505 : 1500 : mucost += rtx_cost (mur, mode, LE, 0, speed_p);
13506 : 1500 : mucost += rtx_cost (expand_normal (c4), mode, LE, 1, speed_p);
13507 : :
13508 : 1500 : if (mocost <= mucost)
13509 : : {
13510 : 304 : emit_insn (moinsns);
13511 : 304 : *arg0 = make_tree (TREE_TYPE (*arg0), mor);
13512 : 304 : return code;
13513 : : }
13514 : :
13515 : 1196 : emit_insn (muinsns);
13516 : 1196 : *arg0 = make_tree (type, mur);
13517 : 1196 : *arg1 = c4;
13518 : 1196 : return code == EQ_EXPR ? LE_EXPR : GT_EXPR;
13519 : 3169 : }
13520 : :
13521 : : /* Optimize x - y < 0 into x < 0 if x - y has undefined overflow. */
13522 : :
13523 : : void
13524 : 233935 : maybe_optimize_sub_cmp_0 (enum tree_code code, tree *arg0, tree *arg1)
13525 : : {
13526 : 233935 : gcc_checking_assert (code == GT_EXPR || code == GE_EXPR
13527 : : || code == LT_EXPR || code == LE_EXPR);
13528 : 233935 : gcc_checking_assert (integer_zerop (*arg1));
13529 : :
13530 : 233935 : if (!optimize)
13531 : : return;
13532 : :
13533 : 201167 : gimple *stmt = get_def_for_expr (*arg0, MINUS_EXPR);
13534 : 201167 : if (stmt == NULL)
13535 : : return;
13536 : :
13537 : 1281 : tree treeop0 = gimple_assign_rhs1 (stmt);
13538 : 1281 : tree treeop1 = gimple_assign_rhs2 (stmt);
13539 : 1281 : if (!TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (treeop0)))
13540 : : return;
13541 : :
13542 : 1184 : if (issue_strict_overflow_warning (WARN_STRICT_OVERFLOW_COMPARISON))
13543 : 1 : warning_at (gimple_location (stmt), OPT_Wstrict_overflow,
13544 : : "assuming signed overflow does not occur when "
13545 : : "simplifying %<X - Y %s 0%> to %<X %s Y%>",
13546 : : op_symbol_code (code), op_symbol_code (code));
13547 : :
13548 : 1184 : *arg0 = treeop0;
13549 : 1184 : *arg1 = treeop1;
13550 : : }
13551 : :
13552 : :
13553 : : /* Expand CODE with arguments INNER & (1<<BITNUM) and 0 that represents
13554 : : a single bit equality/inequality test, returns where the result is located. */
13555 : :
13556 : : static rtx
13557 : 9459 : expand_single_bit_test (location_t loc, enum tree_code code,
13558 : : tree inner, int bitnum,
13559 : : tree result_type, rtx target,
13560 : : machine_mode mode)
13561 : : {
13562 : 9459 : gcc_assert (code == NE_EXPR || code == EQ_EXPR);
13563 : :
13564 : 9459 : tree type = TREE_TYPE (inner);
13565 : 9459 : scalar_int_mode operand_mode = SCALAR_INT_TYPE_MODE (type);
13566 : 9459 : int ops_unsigned;
13567 : 9459 : tree signed_type, unsigned_type, intermediate_type;
13568 : 9459 : gimple *inner_def;
13569 : :
13570 : : /* First, see if we can fold the single bit test into a sign-bit
13571 : : test. */
13572 : 9459 : if (bitnum == TYPE_PRECISION (type) - 1
13573 : 9459 : && type_has_mode_precision_p (type))
13574 : : {
13575 : 231 : tree stype = signed_type_for (type);
13576 : 428 : tree tmp = fold_build2_loc (loc, code == EQ_EXPR ? GE_EXPR : LT_EXPR,
13577 : : result_type,
13578 : : fold_convert_loc (loc, stype, inner),
13579 : 231 : build_int_cst (stype, 0));
13580 : 231 : return expand_expr (tmp, target, VOIDmode, EXPAND_NORMAL);
13581 : : }
13582 : :
13583 : : /* Otherwise we have (A & C) != 0 where C is a single bit,
13584 : : convert that into ((A >> C2) & 1). Where C2 = log2(C).
13585 : : Similarly for (A & C) == 0. */
13586 : :
13587 : : /* If INNER is a right shift of a constant and it plus BITNUM does
13588 : : not overflow, adjust BITNUM and INNER. */
13589 : 9228 : if ((inner_def = get_def_for_expr (inner, RSHIFT_EXPR))
13590 : 13 : && TREE_CODE (gimple_assign_rhs2 (inner_def)) == INTEGER_CST
13591 : 0 : && bitnum < TYPE_PRECISION (type)
13592 : 9228 : && wi::ltu_p (wi::to_wide (gimple_assign_rhs2 (inner_def)),
13593 : 9228 : TYPE_PRECISION (type) - bitnum))
13594 : : {
13595 : 0 : bitnum += tree_to_uhwi (gimple_assign_rhs2 (inner_def));
13596 : 0 : inner = gimple_assign_rhs1 (inner_def);
13597 : : }
13598 : :
13599 : : /* If we are going to be able to omit the AND below, we must do our
13600 : : operations as unsigned. If we must use the AND, we have a choice.
13601 : : Normally unsigned is faster, but for some machines signed is. */
13602 : 9228 : ops_unsigned = (load_extend_op (operand_mode) == SIGN_EXTEND
13603 : : && !flag_syntax_only) ? 0 : 1;
13604 : :
13605 : 9228 : signed_type = lang_hooks.types.type_for_mode (operand_mode, 0);
13606 : 9228 : unsigned_type = lang_hooks.types.type_for_mode (operand_mode, 1);
13607 : 9228 : intermediate_type = ops_unsigned ? unsigned_type : signed_type;
13608 : 9228 : inner = fold_convert_loc (loc, intermediate_type, inner);
13609 : :
13610 : 9228 : rtx inner0 = expand_expr (inner, NULL_RTX, VOIDmode, EXPAND_NORMAL);
13611 : :
13612 : 9228 : if (CONST_SCALAR_INT_P (inner0))
13613 : : {
13614 : 0 : wide_int t = rtx_mode_t (inner0, operand_mode);
13615 : 0 : bool setp = (wi::lrshift (t, bitnum) & 1) != 0;
13616 : 0 : return (setp ^ (code == EQ_EXPR)) ? const1_rtx : const0_rtx;
13617 : 0 : }
13618 : 9228 : int bitpos = bitnum;
13619 : :
13620 : 9228 : if (BYTES_BIG_ENDIAN)
13621 : : bitpos = GET_MODE_BITSIZE (operand_mode) - 1 - bitpos;
13622 : :
13623 : 9228 : inner0 = extract_bit_field (inner0, 1, bitpos, 1, target,
13624 : : operand_mode, mode, 0, NULL);
13625 : :
13626 : 9228 : if (code == EQ_EXPR)
13627 : 2557 : inner0 = expand_binop (GET_MODE (inner0), xor_optab, inner0, const1_rtx,
13628 : : NULL_RTX, 1, OPTAB_LIB_WIDEN);
13629 : 9228 : if (GET_MODE (inner0) != mode)
13630 : : {
13631 : 0 : rtx t = gen_reg_rtx (mode);
13632 : 0 : convert_move (t, inner0, 0);
13633 : 0 : return t;
13634 : : }
13635 : : return inner0;
13636 : : }
13637 : :
13638 : : /* Generate code to calculate OPS, and exploded expression
13639 : : using a store-flag instruction and return an rtx for the result.
13640 : : OPS reflects a comparison.
13641 : :
13642 : : If TARGET is nonzero, store the result there if convenient.
13643 : :
13644 : : Return zero if there is no suitable set-flag instruction
13645 : : available on this machine.
13646 : :
13647 : : Once expand_expr has been called on the arguments of the comparison,
13648 : : we are committed to doing the store flag, since it is not safe to
13649 : : re-evaluate the expression. We emit the store-flag insn by calling
13650 : : emit_store_flag, but only expand the arguments if we have a reason
13651 : : to believe that emit_store_flag will be successful. If we think that
13652 : : it will, but it isn't, we have to simulate the store-flag with a
13653 : : set/jump/set sequence. */
13654 : :
13655 : : static rtx
13656 : 535810 : do_store_flag (const_sepops ops, rtx target, machine_mode mode)
13657 : : {
13658 : 535810 : enum rtx_code code;
13659 : 535810 : tree arg0, arg1, type;
13660 : 535810 : machine_mode operand_mode;
13661 : 535810 : int unsignedp;
13662 : 535810 : rtx op0, op1;
13663 : 535810 : rtx subtarget = target;
13664 : 535810 : location_t loc = ops->location;
13665 : 535810 : unsigned HOST_WIDE_INT nunits;
13666 : :
13667 : 535810 : arg0 = ops->op0;
13668 : 535810 : arg1 = ops->op1;
13669 : :
13670 : : /* Don't crash if the comparison was erroneous. */
13671 : 535810 : if (arg0 == error_mark_node || arg1 == error_mark_node)
13672 : 0 : return const0_rtx;
13673 : :
13674 : 535810 : type = TREE_TYPE (arg0);
13675 : 535810 : operand_mode = TYPE_MODE (type);
13676 : 535810 : unsignedp = TYPE_UNSIGNED (type);
13677 : :
13678 : : /* We won't bother with BLKmode store-flag operations because it would mean
13679 : : passing a lot of information to emit_store_flag. */
13680 : 535810 : if (operand_mode == BLKmode)
13681 : : return 0;
13682 : :
13683 : : /* We won't bother with store-flag operations involving function pointers
13684 : : when function pointers must be canonicalized before comparisons. */
13685 : 535810 : if (targetm.have_canonicalize_funcptr_for_compare ()
13686 : 535810 : && ((POINTER_TYPE_P (TREE_TYPE (arg0))
13687 : 0 : && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (arg0))))
13688 : 0 : || (POINTER_TYPE_P (TREE_TYPE (arg1))
13689 : 0 : && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (arg1))))))
13690 : : return 0;
13691 : :
13692 : 535810 : STRIP_NOPS (arg0);
13693 : 535810 : STRIP_NOPS (arg1);
13694 : :
13695 : : /* For vector typed comparisons emit code to generate the desired
13696 : : all-ones or all-zeros mask. */
13697 : 535810 : if (VECTOR_TYPE_P (ops->type))
13698 : : {
13699 : 20003 : tree ifexp = build2 (ops->code, ops->type, arg0, arg1);
13700 : 20003 : if (VECTOR_BOOLEAN_TYPE_P (ops->type)
13701 : 40006 : && expand_vec_cmp_expr_p (TREE_TYPE (arg0), ops->type, ops->code))
13702 : 20003 : return expand_vec_cmp_expr (ops->type, ifexp, target);
13703 : : else
13704 : 0 : gcc_unreachable ();
13705 : : }
13706 : :
13707 : : /* Optimize (x % C1) == C2 or (x % C1) != C2 if it is beneficial
13708 : : into (x - C2) * C3 < C4. */
13709 : 515807 : if ((ops->code == EQ_EXPR || ops->code == NE_EXPR)
13710 : 317962 : && TREE_CODE (arg0) == SSA_NAME
13711 : 317480 : && TREE_CODE (arg1) == INTEGER_CST)
13712 : : {
13713 : 186033 : enum tree_code new_code = maybe_optimize_mod_cmp (ops->code,
13714 : : &arg0, &arg1);
13715 : 186033 : if (new_code != ops->code)
13716 : : {
13717 : 75 : struct separate_ops nops = *ops;
13718 : 75 : nops.code = new_code;
13719 : 75 : nops.op0 = arg0;
13720 : 75 : nops.op1 = arg1;
13721 : 75 : nops.type = TREE_TYPE (arg0);
13722 : 75 : return do_store_flag (&nops, target, mode);
13723 : : }
13724 : : }
13725 : :
13726 : : /* Optimize (x - y) < 0 into x < y if x - y has undefined overflow. */
13727 : 515732 : if (!unsignedp
13728 : 339579 : && (ops->code == LT_EXPR || ops->code == LE_EXPR
13729 : 339579 : || ops->code == GT_EXPR || ops->code == GE_EXPR)
13730 : 122377 : && integer_zerop (arg1)
13731 : 553696 : && TREE_CODE (arg0) == SSA_NAME)
13732 : 37960 : maybe_optimize_sub_cmp_0 (ops->code, &arg0, &arg1);
13733 : :
13734 : : /* Get the rtx comparison code to use. We know that EXP is a comparison
13735 : : operation of some type. Some comparisons against 1 and -1 can be
13736 : : converted to comparisons with zero. Do so here so that the tests
13737 : : below will be aware that we have a comparison with zero. These
13738 : : tests will not catch constants in the first operand, but constants
13739 : : are rarely passed as the first operand. */
13740 : :
13741 : 515732 : switch (ops->code)
13742 : : {
13743 : : case EQ_EXPR:
13744 : : code = EQ;
13745 : : break;
13746 : 192786 : case NE_EXPR:
13747 : 192786 : code = NE;
13748 : 192786 : break;
13749 : 41779 : case LT_EXPR:
13750 : 41779 : if (integer_onep (arg1))
13751 : 0 : arg1 = integer_zero_node, code = unsignedp ? LEU : LE;
13752 : : else
13753 : 41779 : code = unsignedp ? LTU : LT;
13754 : : break;
13755 : 33317 : case LE_EXPR:
13756 : 33317 : if (! unsignedp && integer_all_onesp (arg1))
13757 : 0 : arg1 = integer_zero_node, code = LT;
13758 : : else
13759 : 33317 : code = unsignedp ? LEU : LE;
13760 : : break;
13761 : 55890 : case GT_EXPR:
13762 : 55890 : if (! unsignedp && integer_all_onesp (arg1))
13763 : 0 : arg1 = integer_zero_node, code = GE;
13764 : : else
13765 : 55890 : code = unsignedp ? GTU : GT;
13766 : : break;
13767 : 42685 : case GE_EXPR:
13768 : 42685 : if (integer_onep (arg1))
13769 : 0 : arg1 = integer_zero_node, code = unsignedp ? GTU : GT;
13770 : : else
13771 : 42685 : code = unsignedp ? GEU : GE;
13772 : : break;
13773 : :
13774 : 674 : case UNORDERED_EXPR:
13775 : 674 : code = UNORDERED;
13776 : 674 : break;
13777 : 678 : case ORDERED_EXPR:
13778 : 678 : code = ORDERED;
13779 : 678 : break;
13780 : 482 : case UNLT_EXPR:
13781 : 482 : code = UNLT;
13782 : 482 : break;
13783 : 11129 : case UNLE_EXPR:
13784 : 11129 : code = UNLE;
13785 : 11129 : break;
13786 : 825 : case UNGT_EXPR:
13787 : 825 : code = UNGT;
13788 : 825 : break;
13789 : 10165 : case UNGE_EXPR:
13790 : 10165 : code = UNGE;
13791 : 10165 : break;
13792 : 141 : case UNEQ_EXPR:
13793 : 141 : code = UNEQ;
13794 : 141 : break;
13795 : 80 : case LTGT_EXPR:
13796 : 80 : code = LTGT;
13797 : 80 : break;
13798 : :
13799 : 0 : default:
13800 : 0 : gcc_unreachable ();
13801 : : }
13802 : :
13803 : : /* Put a constant second. */
13804 : 515732 : if (TREE_CODE (arg0) == REAL_CST || TREE_CODE (arg0) == INTEGER_CST
13805 : 514704 : || TREE_CODE (arg0) == FIXED_CST)
13806 : : {
13807 : 1028 : std::swap (arg0, arg1);
13808 : 1028 : code = swap_condition (code);
13809 : : }
13810 : :
13811 : : /* If this is an equality or inequality test of a single bit, we can
13812 : : do this by shifting the bit being tested to the low-order bit and
13813 : : masking the result with the constant 1. If the condition was EQ,
13814 : : we xor it with 1. This does not require an scc insn and is faster
13815 : : than an scc insn even if we have it. */
13816 : :
13817 : 515732 : if ((code == NE || code == EQ)
13818 : 317887 : && (integer_zerop (arg1)
13819 : 203806 : || integer_pow2p (arg1))
13820 : : /* vector types are not handled here. */
13821 : 143778 : && TREE_CODE (TREE_TYPE (arg1)) != VECTOR_TYPE
13822 : 659501 : && (TYPE_PRECISION (ops->type) != 1 || TYPE_UNSIGNED (ops->type)))
13823 : : {
13824 : 143769 : tree narg0 = arg0;
13825 : 143769 : wide_int nz = tree_nonzero_bits (narg0);
13826 : 143769 : gimple *srcstmt = get_def_for_expr (narg0, BIT_AND_EXPR);
13827 : : /* If the defining statement was (x & POW2), then use that instead of
13828 : : the non-zero bits. */
13829 : 143769 : if (srcstmt && integer_pow2p (gimple_assign_rhs2 (srcstmt)))
13830 : : {
13831 : 5193 : nz = wi::to_wide (gimple_assign_rhs2 (srcstmt));
13832 : 5193 : narg0 = gimple_assign_rhs1 (srcstmt);
13833 : : }
13834 : :
13835 : 143769 : if (wi::popcount (nz) == 1
13836 : 143769 : && (integer_zerop (arg1)
13837 : 134340 : || wi::to_wide (arg1) == nz))
13838 : : {
13839 : 9459 : int bitnum = wi::exact_log2 (nz);
13840 : 9459 : enum tree_code tcode = EQ_EXPR;
13841 : 9459 : if ((code == NE) ^ !integer_zerop (arg1))
13842 : 6868 : tcode = NE_EXPR;
13843 : :
13844 : 9459 : type = lang_hooks.types.type_for_mode (mode, unsignedp);
13845 : 9459 : return expand_single_bit_test (loc, tcode,
13846 : : narg0,
13847 : : bitnum, type, target, mode);
13848 : : }
13849 : 143769 : }
13850 : :
13851 : :
13852 : 506273 : if (! get_subtarget (target)
13853 : 506273 : || GET_MODE (subtarget) != operand_mode)
13854 : : subtarget = 0;
13855 : :
13856 : 506273 : expand_operands (arg0, arg1, subtarget, &op0, &op1, EXPAND_NORMAL);
13857 : :
13858 : : /* For boolean vectors with less than mode precision
13859 : : make sure to fill padding with consistent values. */
13860 : 9 : if (VECTOR_BOOLEAN_TYPE_P (type)
13861 : 0 : && SCALAR_INT_MODE_P (operand_mode)
13862 : 506273 : && TYPE_VECTOR_SUBPARTS (type).is_constant (&nunits)
13863 : 506273 : && maybe_ne (GET_MODE_PRECISION (operand_mode), nunits))
13864 : : {
13865 : 0 : gcc_assert (code == EQ || code == NE);
13866 : 0 : op0 = expand_binop (mode, and_optab, op0,
13867 : 0 : GEN_INT ((HOST_WIDE_INT_1U << nunits) - 1),
13868 : : NULL_RTX, true, OPTAB_WIDEN);
13869 : 0 : op1 = expand_binop (mode, and_optab, op1,
13870 : : GEN_INT ((HOST_WIDE_INT_1U << nunits) - 1),
13871 : : NULL_RTX, true, OPTAB_WIDEN);
13872 : : }
13873 : :
13874 : 506273 : if (target == 0)
13875 : 321836 : target = gen_reg_rtx (mode);
13876 : :
13877 : : /* Try a cstore if possible. */
13878 : 506273 : return emit_store_flag_force (target, code, op0, op1,
13879 : : operand_mode, unsignedp,
13880 : 506273 : (TYPE_PRECISION (ops->type) == 1
13881 : 1011969 : && !TYPE_UNSIGNED (ops->type)) ? -1 : 1);
13882 : : }
13883 : :
13884 : : /* Attempt to generate a casesi instruction. Returns true if successful,
13885 : : false otherwise (i.e. if there is no casesi instruction).
13886 : :
13887 : : DEFAULT_PROBABILITY is the probability of jumping to the default
13888 : : label. */
13889 : : bool
13890 : 7338 : try_casesi (tree index_type, tree index_expr, tree minval, tree range,
13891 : : rtx table_label, rtx default_label, rtx fallback_label,
13892 : : profile_probability default_probability)
13893 : : {
13894 : 7338 : class expand_operand ops[5];
13895 : 7338 : scalar_int_mode index_mode = SImode;
13896 : 7338 : rtx op1, op2, index;
13897 : :
13898 : 7338 : if (! targetm.have_casesi ())
13899 : : return false;
13900 : :
13901 : : /* The index must be some form of integer. Convert it to SImode. */
13902 : 0 : scalar_int_mode omode = SCALAR_INT_TYPE_MODE (index_type);
13903 : 0 : if (GET_MODE_BITSIZE (omode) > GET_MODE_BITSIZE (index_mode))
13904 : : {
13905 : 0 : rtx rangertx = expand_normal (range);
13906 : :
13907 : : /* We must handle the endpoints in the original mode. */
13908 : 0 : index_expr = build2 (MINUS_EXPR, index_type,
13909 : : index_expr, minval);
13910 : 0 : minval = integer_zero_node;
13911 : 0 : index = expand_normal (index_expr);
13912 : 0 : if (default_label)
13913 : 0 : emit_cmp_and_jump_insns (rangertx, index, LTU, NULL_RTX,
13914 : : omode, 1, default_label,
13915 : : default_probability);
13916 : : /* Now we can safely truncate. */
13917 : 0 : index = convert_to_mode (index_mode, index, 0);
13918 : : }
13919 : : else
13920 : : {
13921 : 0 : if (omode != index_mode)
13922 : : {
13923 : 0 : index_type = lang_hooks.types.type_for_mode (index_mode, 0);
13924 : 0 : index_expr = fold_convert (index_type, index_expr);
13925 : : }
13926 : :
13927 : 0 : index = expand_normal (index_expr);
13928 : : }
13929 : :
13930 : 0 : do_pending_stack_adjust ();
13931 : :
13932 : 0 : op1 = expand_normal (minval);
13933 : 0 : op2 = expand_normal (range);
13934 : :
13935 : 0 : create_input_operand (&ops[0], index, index_mode);
13936 : 0 : create_convert_operand_from_type (&ops[1], op1, TREE_TYPE (minval));
13937 : 0 : create_convert_operand_from_type (&ops[2], op2, TREE_TYPE (range));
13938 : 0 : create_fixed_operand (&ops[3], table_label);
13939 : 0 : create_fixed_operand (&ops[4], (default_label
13940 : : ? default_label
13941 : : : fallback_label));
13942 : 0 : expand_jump_insn (targetm.code_for_casesi, 5, ops);
13943 : 0 : return true;
13944 : : }
13945 : :
13946 : : /* Attempt to generate a tablejump instruction; same concept. */
13947 : : /* Subroutine of the next function.
13948 : :
13949 : : INDEX is the value being switched on, with the lowest value
13950 : : in the table already subtracted.
13951 : : MODE is its expected mode (needed if INDEX is constant).
13952 : : RANGE is the length of the jump table.
13953 : : TABLE_LABEL is a CODE_LABEL rtx for the table itself.
13954 : :
13955 : : DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
13956 : : index value is out of range.
13957 : : DEFAULT_PROBABILITY is the probability of jumping to
13958 : : the default label. */
13959 : :
13960 : : static void
13961 : 7338 : do_tablejump (rtx index, machine_mode mode, rtx range, rtx table_label,
13962 : : rtx default_label, profile_probability default_probability)
13963 : : {
13964 : 7338 : rtx temp, vector;
13965 : :
13966 : 7338 : if (INTVAL (range) > cfun->cfg->max_jumptable_ents)
13967 : 6046 : cfun->cfg->max_jumptable_ents = INTVAL (range);
13968 : :
13969 : : /* Do an unsigned comparison (in the proper mode) between the index
13970 : : expression and the value which represents the length of the range.
13971 : : Since we just finished subtracting the lower bound of the range
13972 : : from the index expression, this comparison allows us to simultaneously
13973 : : check that the original index expression value is both greater than
13974 : : or equal to the minimum value of the range and less than or equal to
13975 : : the maximum value of the range. */
13976 : :
13977 : 7338 : if (default_label)
13978 : 5935 : emit_cmp_and_jump_insns (index, range, GTU, NULL_RTX, mode, 1,
13979 : : default_label, default_probability);
13980 : :
13981 : : /* If index is in range, it must fit in Pmode.
13982 : : Convert to Pmode so we can index with it. */
13983 : 7338 : if (mode != Pmode)
13984 : : {
13985 : 6325 : unsigned int width;
13986 : :
13987 : : /* We know the value of INDEX is between 0 and RANGE. If we have a
13988 : : sign-extended subreg, and RANGE does not have the sign bit set, then
13989 : : we have a value that is valid for both sign and zero extension. In
13990 : : this case, we get better code if we sign extend. */
13991 : 6325 : if (GET_CODE (index) == SUBREG
13992 : 9 : && SUBREG_PROMOTED_VAR_P (index)
13993 : 0 : && SUBREG_PROMOTED_SIGNED_P (index)
13994 : 0 : && ((width = GET_MODE_PRECISION (as_a <scalar_int_mode> (mode)))
13995 : : <= HOST_BITS_PER_WIDE_INT)
13996 : 6325 : && ! (UINTVAL (range) & (HOST_WIDE_INT_1U << (width - 1))))
13997 : 0 : index = convert_to_mode (Pmode, index, 0);
13998 : : else
13999 : 6325 : index = convert_to_mode (Pmode, index, 1);
14000 : : }
14001 : :
14002 : : /* Don't let a MEM slip through, because then INDEX that comes
14003 : : out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
14004 : : and break_out_memory_refs will go to work on it and mess it up. */
14005 : : #ifdef PIC_CASE_VECTOR_ADDRESS
14006 : : if (flag_pic && !REG_P (index))
14007 : : index = copy_to_mode_reg (Pmode, index);
14008 : : #endif
14009 : :
14010 : : /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
14011 : : GET_MODE_SIZE, because this indicates how large insns are. The other
14012 : : uses should all be Pmode, because they are addresses. This code
14013 : : could fail if addresses and insns are not the same size. */
14014 : 7338 : index = simplify_gen_binary (MULT, Pmode, index,
14015 : 14676 : gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE),
14016 : 7338 : Pmode));
14017 : 7338 : index = simplify_gen_binary (PLUS, Pmode, index,
14018 : 7338 : gen_rtx_LABEL_REF (Pmode, table_label));
14019 : :
14020 : : #ifdef PIC_CASE_VECTOR_ADDRESS
14021 : : if (flag_pic)
14022 : : index = PIC_CASE_VECTOR_ADDRESS (index);
14023 : : else
14024 : : #endif
14025 : 8853 : index = memory_address (CASE_VECTOR_MODE, index);
14026 : 8853 : temp = gen_reg_rtx (CASE_VECTOR_MODE);
14027 : 8853 : vector = gen_const_mem (CASE_VECTOR_MODE, index);
14028 : 7338 : convert_move (temp, vector, 0);
14029 : :
14030 : 7338 : emit_jump_insn (targetm.gen_tablejump (temp, table_label));
14031 : :
14032 : : /* If we are generating PIC code or if the table is PC-relative, the
14033 : : table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
14034 : 7338 : if (! CASE_VECTOR_PC_RELATIVE && ! flag_pic)
14035 : 6331 : emit_barrier ();
14036 : 7338 : }
14037 : :
14038 : : bool
14039 : 7338 : try_tablejump (tree index_type, tree index_expr, tree minval, tree range,
14040 : : rtx table_label, rtx default_label,
14041 : : profile_probability default_probability)
14042 : : {
14043 : 7338 : rtx index;
14044 : :
14045 : 7338 : if (! targetm.have_tablejump ())
14046 : : return false;
14047 : :
14048 : 7338 : index_expr = fold_build2 (MINUS_EXPR, index_type,
14049 : : fold_convert (index_type, index_expr),
14050 : : fold_convert (index_type, minval));
14051 : 7338 : index = expand_normal (index_expr);
14052 : 7338 : do_pending_stack_adjust ();
14053 : :
14054 : 7338 : do_tablejump (index, TYPE_MODE (index_type),
14055 : 7338 : convert_modes (TYPE_MODE (index_type),
14056 : 7338 : TYPE_MODE (TREE_TYPE (range)),
14057 : : expand_normal (range),
14058 : 7338 : TYPE_UNSIGNED (TREE_TYPE (range))),
14059 : : table_label, default_label, default_probability);
14060 : 7338 : return true;
14061 : : }
14062 : :
14063 : : /* Return a CONST_VECTOR rtx representing vector mask for
14064 : : a VECTOR_CST of booleans. */
14065 : : static rtx
14066 : 34 : const_vector_mask_from_tree (tree exp)
14067 : : {
14068 : 34 : machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
14069 : 34 : machine_mode inner = GET_MODE_INNER (mode);
14070 : :
14071 : 34 : rtx_vector_builder builder (mode, VECTOR_CST_NPATTERNS (exp),
14072 : 34 : VECTOR_CST_NELTS_PER_PATTERN (exp));
14073 : 34 : unsigned int count = builder.encoded_nelts ();
14074 : 134 : for (unsigned int i = 0; i < count; ++i)
14075 : : {
14076 : 100 : tree elt = VECTOR_CST_ELT (exp, i);
14077 : 100 : gcc_assert (TREE_CODE (elt) == INTEGER_CST);
14078 : 100 : if (integer_zerop (elt))
14079 : 44 : builder.quick_push (CONST0_RTX (inner));
14080 : 56 : else if (integer_onep (elt)
14081 : 56 : || integer_minus_onep (elt))
14082 : 56 : builder.quick_push (CONSTM1_RTX (inner));
14083 : : else
14084 : 0 : gcc_unreachable ();
14085 : : }
14086 : 34 : return builder.build ();
14087 : 34 : }
14088 : :
14089 : : /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
14090 : : static rtx
14091 : 532640 : const_vector_from_tree (tree exp)
14092 : : {
14093 : 532640 : machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
14094 : :
14095 : 532640 : if (initializer_zerop (exp))
14096 : 157212 : return CONST0_RTX (mode);
14097 : :
14098 : 375428 : if (VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (exp)))
14099 : 34 : return const_vector_mask_from_tree (exp);
14100 : :
14101 : 375394 : machine_mode inner = GET_MODE_INNER (mode);
14102 : :
14103 : 375394 : rtx_vector_builder builder (mode, VECTOR_CST_NPATTERNS (exp),
14104 : 375394 : VECTOR_CST_NELTS_PER_PATTERN (exp));
14105 : 375394 : unsigned int count = builder.encoded_nelts ();
14106 : 1213507 : for (unsigned int i = 0; i < count; ++i)
14107 : : {
14108 : 838113 : tree elt = VECTOR_CST_ELT (exp, i);
14109 : 838113 : if (TREE_CODE (elt) == REAL_CST)
14110 : 132772 : builder.quick_push (const_double_from_real_value (TREE_REAL_CST (elt),
14111 : : inner));
14112 : 705341 : else if (TREE_CODE (elt) == FIXED_CST)
14113 : 0 : builder.quick_push (CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt),
14114 : : inner));
14115 : : else
14116 : 705341 : builder.quick_push (immed_wide_int_const (wi::to_poly_wide (elt),
14117 : : inner));
14118 : : }
14119 : 375394 : return builder.build ();
14120 : 375394 : }
14121 : :
14122 : : /* Build a decl for a personality function given a language prefix. */
14123 : :
14124 : : tree
14125 : 31200 : build_personality_function (const char *lang)
14126 : : {
14127 : 31200 : const char *unwind_and_version;
14128 : 31200 : tree decl, type;
14129 : 31200 : char *name;
14130 : :
14131 : 31200 : switch (targetm_common.except_unwind_info (&global_options))
14132 : : {
14133 : : case UI_NONE:
14134 : : return NULL;
14135 : : case UI_SJLJ:
14136 : : unwind_and_version = "_sj0";
14137 : : break;
14138 : 31200 : case UI_DWARF2:
14139 : 31200 : case UI_TARGET:
14140 : 31200 : unwind_and_version = "_v0";
14141 : 31200 : break;
14142 : 0 : case UI_SEH:
14143 : 0 : unwind_and_version = "_seh0";
14144 : 0 : break;
14145 : 0 : default:
14146 : 0 : gcc_unreachable ();
14147 : : }
14148 : :
14149 : 31200 : name = ACONCAT (("__", lang, "_personality", unwind_and_version, NULL));
14150 : :
14151 : 31200 : type = build_function_type_list (unsigned_type_node,
14152 : : integer_type_node, integer_type_node,
14153 : : long_long_unsigned_type_node,
14154 : : ptr_type_node, ptr_type_node, NULL_TREE);
14155 : 31200 : decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
14156 : : get_identifier (name), type);
14157 : 31200 : DECL_ARTIFICIAL (decl) = 1;
14158 : 31200 : DECL_EXTERNAL (decl) = 1;
14159 : 31200 : TREE_PUBLIC (decl) = 1;
14160 : :
14161 : : /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
14162 : : are the flags assigned by targetm.encode_section_info. */
14163 : 31200 : SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl), 0), NULL);
14164 : :
14165 : 31200 : return decl;
14166 : : }
14167 : :
14168 : : /* Extracts the personality function of DECL and returns the corresponding
14169 : : libfunc. */
14170 : :
14171 : : rtx
14172 : 1584802 : get_personality_function (tree decl)
14173 : : {
14174 : 1584802 : tree personality = DECL_FUNCTION_PERSONALITY (decl);
14175 : 1584802 : enum eh_personality_kind pk;
14176 : :
14177 : 1584802 : pk = function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl));
14178 : 1584802 : if (pk == eh_personality_none)
14179 : : return NULL;
14180 : :
14181 : 153802 : if (!personality
14182 : 153802 : && pk == eh_personality_any)
14183 : 72722 : personality = lang_hooks.eh_personality ();
14184 : :
14185 : 153802 : if (pk == eh_personality_lang)
14186 : 81080 : gcc_assert (personality != NULL_TREE);
14187 : :
14188 : 153802 : return XEXP (DECL_RTL (personality), 0);
14189 : : }
14190 : :
14191 : : /* Returns a tree for the size of EXP in bytes. */
14192 : :
14193 : : static tree
14194 : 14259416 : tree_expr_size (const_tree exp)
14195 : : {
14196 : 14259416 : if (DECL_P (exp)
14197 : 14259416 : && DECL_SIZE_UNIT (exp) != 0)
14198 : 1950212 : return DECL_SIZE_UNIT (exp);
14199 : : else
14200 : 12309204 : return size_in_bytes (TREE_TYPE (exp));
14201 : : }
14202 : :
14203 : : /* Return an rtx for the size in bytes of the value of EXP. */
14204 : :
14205 : : rtx
14206 : 14034199 : expr_size (tree exp)
14207 : : {
14208 : 14034199 : tree size;
14209 : :
14210 : 14034199 : if (TREE_CODE (exp) == WITH_SIZE_EXPR)
14211 : 767 : size = TREE_OPERAND (exp, 1);
14212 : : else
14213 : : {
14214 : 14033432 : size = tree_expr_size (exp);
14215 : 14033432 : gcc_assert (size);
14216 : 14033432 : gcc_assert (size == SUBSTITUTE_PLACEHOLDER_IN_EXPR (size, exp));
14217 : : }
14218 : :
14219 : 14034199 : return expand_expr (size, NULL_RTX, TYPE_MODE (sizetype), EXPAND_NORMAL);
14220 : : }
14221 : :
14222 : : /* Return a wide integer for the size in bytes of the value of EXP, or -1
14223 : : if the size can vary or is larger than an integer. */
14224 : :
14225 : : HOST_WIDE_INT
14226 : 225984 : int_expr_size (const_tree exp)
14227 : : {
14228 : 225984 : tree size;
14229 : :
14230 : 225984 : if (TREE_CODE (exp) == WITH_SIZE_EXPR)
14231 : 0 : size = TREE_OPERAND (exp, 1);
14232 : : else
14233 : : {
14234 : 225984 : size = tree_expr_size (exp);
14235 : 225984 : gcc_assert (size);
14236 : : }
14237 : :
14238 : 225984 : if (size == 0 || !tree_fits_shwi_p (size))
14239 : 0 : return -1;
14240 : :
14241 : 225984 : return tree_to_shwi (size);
14242 : : }
14243 : :
14244 : : /* Return the quotient of polynomial long division of x^2N by POLYNOMIAL
14245 : : in GF (2^N).
14246 : : Author: Richard Sandiford <richard.sandiford@arm.com> */
14247 : :
14248 : : unsigned HOST_WIDE_INT
14249 : 0 : gf2n_poly_long_div_quotient (unsigned HOST_WIDE_INT polynomial,
14250 : : unsigned short n)
14251 : : {
14252 : : /* The result has degree N, so needs N + 1 bits. */
14253 : 0 : gcc_assert (n < 64);
14254 : :
14255 : : /* Perform a division step for the x^2N coefficient. At this point the
14256 : : quotient and remainder have N implicit trailing zeros. */
14257 : : unsigned HOST_WIDE_INT quotient = 1;
14258 : : unsigned HOST_WIDE_INT remainder = polynomial;
14259 : :
14260 : : /* Process the coefficients for x^(2N-1) down to x^N, with each step
14261 : : reducing the number of implicit trailing zeros by one. */
14262 : 0 : for (unsigned int i = 0; i < n; ++i)
14263 : : {
14264 : 0 : bool coeff = remainder & (HOST_WIDE_INT_1U << (n - 1));
14265 : 0 : quotient = (quotient << 1) | coeff;
14266 : 0 : remainder = (remainder << 1) ^ (coeff ? polynomial : 0);
14267 : : }
14268 : 0 : return quotient;
14269 : : }
14270 : :
14271 : : /* Calculate CRC for the initial CRC and given POLYNOMIAL.
14272 : : CRC_BITS is CRC size. */
14273 : :
14274 : : static unsigned HOST_WIDE_INT
14275 : 66560 : calculate_crc (unsigned HOST_WIDE_INT crc,
14276 : : unsigned HOST_WIDE_INT polynomial,
14277 : : unsigned short crc_bits)
14278 : : {
14279 : 66560 : unsigned HOST_WIDE_INT msb = HOST_WIDE_INT_1U << (crc_bits - 1);
14280 : 66560 : crc = crc << (crc_bits - 8);
14281 : 599040 : for (short i = 8; i > 0; --i)
14282 : : {
14283 : 532480 : if (crc & msb)
14284 : 266240 : crc = (crc << 1) ^ polynomial;
14285 : : else
14286 : 266240 : crc <<= 1;
14287 : : }
14288 : : /* Zero out bits in crc beyond the specified number of crc_bits. */
14289 : 66560 : if (crc_bits < sizeof (crc) * CHAR_BIT)
14290 : 58112 : crc &= (HOST_WIDE_INT_1U << crc_bits) - 1;
14291 : 66560 : return crc;
14292 : : }
14293 : :
14294 : : /* Assemble CRC table with 256 elements for the given POLYNOM and CRC_BITS.
14295 : : POLYNOM is the polynomial used to calculate the CRC table's elements.
14296 : : CRC_BITS is the size of CRC, may be 8, 16, ... . */
14297 : :
14298 : : static rtx
14299 : 260 : assemble_crc_table (unsigned HOST_WIDE_INT polynom, unsigned short crc_bits)
14300 : : {
14301 : 260 : unsigned table_el_n = 0x100;
14302 : 260 : tree ar = build_array_type (make_unsigned_type (crc_bits),
14303 : 260 : build_index_type (size_int (table_el_n - 1)));
14304 : :
14305 : : /* Initialize the table. */
14306 : 260 : vec<tree, va_gc> *initial_values;
14307 : 260 : vec_alloc (initial_values, table_el_n);
14308 : 66820 : for (size_t i = 0; i < table_el_n; ++i)
14309 : : {
14310 : 66560 : unsigned HOST_WIDE_INT crc = calculate_crc (i, polynom, crc_bits);
14311 : 66560 : tree element = build_int_cstu (make_unsigned_type (crc_bits), crc);
14312 : 66560 : vec_safe_push (initial_values, element);
14313 : : }
14314 : 260 : tree ctor = build_constructor_from_vec (ar, initial_values);
14315 : 260 : rtx mem = output_constant_def (ctor, 1);
14316 : 260 : gcc_assert (MEM_P (mem));
14317 : 260 : if (dump_file && (dump_flags & TDF_DETAILS))
14318 : : {
14319 : 32 : fprintf (dump_file,
14320 : : ";; emitting crc table crc_%u_polynomial_"
14321 : : HOST_WIDE_INT_PRINT_HEX " ",
14322 : : crc_bits, polynom);
14323 : 32 : print_rtl_single (dump_file, XEXP (mem, 0));
14324 : 32 : fprintf (dump_file, "\n");
14325 : : }
14326 : :
14327 : 260 : return XEXP (mem, 0);
14328 : : }
14329 : :
14330 : : /* Generate CRC lookup table by calculating CRC for all possible
14331 : : 8-bit data values. The table is stored with a specific name in the read-only
14332 : : static data section.
14333 : : POLYNOM is the polynomial used to calculate the CRC table's elements.
14334 : : CRC_BITS is the size of CRC, may be 8, 16, ... . */
14335 : :
14336 : : static rtx
14337 : 260 : generate_crc_table (unsigned HOST_WIDE_INT polynom, unsigned short crc_bits)
14338 : : {
14339 : 260 : gcc_assert (crc_bits <= 64);
14340 : :
14341 : 260 : return assemble_crc_table (polynom, crc_bits);
14342 : : }
14343 : :
14344 : : /* Generate table-based CRC code for the given CRC, INPUT_DATA and the
14345 : : POLYNOMIAL (without leading 1).
14346 : :
14347 : : First, using POLYNOMIAL's value generates CRC table of 256 elements,
14348 : : then generates the assembly for the following code,
14349 : : where crc_bit_size and data_bit_size may be 8, 16, 32, 64, depending on CRC:
14350 : :
14351 : : for (int i = 0; i < data_bit_size / 8; i++)
14352 : : crc = (crc << 8) ^ crc_table[(crc >> (crc_bit_size - 8))
14353 : : ^ (data >> (data_bit_size - (i + 1) * 8)
14354 : : & 0xFF))];
14355 : :
14356 : : So to take values from the table, we need 8-bit data.
14357 : : If input data size is not 8, then first we extract upper 8 bits,
14358 : : then the other 8 bits, and so on. */
14359 : :
14360 : : static void
14361 : 260 : calculate_table_based_CRC (rtx *crc, const rtx &input_data,
14362 : : const rtx &polynomial,
14363 : : machine_mode data_mode)
14364 : : {
14365 : 260 : machine_mode mode = GET_MODE (*crc);
14366 : 260 : unsigned short crc_bit_size = GET_MODE_BITSIZE (mode).to_constant ();
14367 : 260 : unsigned short data_size = GET_MODE_SIZE (data_mode).to_constant ();
14368 : 260 : rtx tab = generate_crc_table (UINTVAL (polynomial), crc_bit_size);
14369 : :
14370 : 720 : for (unsigned short i = 0; i < data_size; i++)
14371 : : {
14372 : : /* crc >> (crc_bit_size - 8). */
14373 : 460 : *crc = force_reg (mode, *crc);
14374 : 460 : rtx op1 = expand_shift (RSHIFT_EXPR, mode, *crc, crc_bit_size - 8,
14375 : : NULL_RTX, 1);
14376 : :
14377 : : /* data >> (8 * (GET_MODE_SIZE (data_mode).to_constant () - i - 1)). */
14378 : 460 : unsigned range_8 = 8 * (data_size - i - 1);
14379 : : /* CRC's mode is always at least as wide as INPUT_DATA. Convert
14380 : : INPUT_DATA into CRC's mode. */
14381 : 460 : rtx data = gen_reg_rtx (mode);
14382 : 460 : convert_move (data, input_data, 1);
14383 : 460 : data = expand_shift (RSHIFT_EXPR, mode, data, range_8, NULL_RTX, 1);
14384 : :
14385 : : /* data >> (8 * (GET_MODE_SIZE (mode)
14386 : : .to_constant () - i - 1)) & 0xFF. */
14387 : 460 : rtx data_final = expand_and (mode, data,
14388 : 460 : gen_int_mode (255, mode), NULL_RTX);
14389 : :
14390 : : /* (crc >> (crc_bit_size - 8)) ^ data_8bit. */
14391 : 460 : rtx in = expand_binop (mode, xor_optab, op1, data_final,
14392 : : NULL_RTX, 1, OPTAB_WIDEN);
14393 : :
14394 : : /* ((crc >> (crc_bit_size - 8)) ^ data_8bit) & 0xFF. */
14395 : 460 : rtx index = expand_and (mode, in, gen_int_mode (255, mode),
14396 : : NULL_RTX);
14397 : 920 : int log_crc_size = exact_log2 (GET_MODE_SIZE (mode).to_constant ());
14398 : 460 : index = expand_shift (LSHIFT_EXPR, mode, index,
14399 : : log_crc_size, NULL_RTX, 0);
14400 : :
14401 : 460 : rtx addr = gen_reg_rtx (Pmode);
14402 : 460 : convert_move (addr, index, 1);
14403 : 460 : addr = expand_binop (Pmode, add_optab, addr, tab, NULL_RTX,
14404 : : 0, OPTAB_DIRECT);
14405 : :
14406 : : /* crc_table[(crc >> (crc_bit_size - 8)) ^ data_8bit] */
14407 : 460 : rtx tab_el = validize_mem (gen_rtx_MEM (mode, addr));
14408 : :
14409 : : /* (crc << 8) if CRC is larger than 8, otherwise crc = 0. */
14410 : 460 : rtx high = NULL_RTX;
14411 : 460 : if (crc_bit_size != 8)
14412 : 421 : high = expand_shift (LSHIFT_EXPR, mode, *crc, 8, NULL_RTX, 0);
14413 : : else
14414 : 39 : high = gen_int_mode (0, mode);
14415 : :
14416 : : /* crc = (crc << 8)
14417 : : ^ crc_table[(crc >> (crc_bit_size - 8)) ^ data_8bit]; */
14418 : 460 : *crc = expand_binop (mode, xor_optab, tab_el, high, NULL_RTX, 1,
14419 : : OPTAB_WIDEN);
14420 : : }
14421 : 260 : }
14422 : :
14423 : : /* Generate table-based CRC code for the given CRC, INPUT_DATA and the
14424 : : POLYNOMIAL (without leading 1).
14425 : :
14426 : : CRC is OP1, data is OP2 and the polynomial is OP3.
14427 : : This must generate a CRC table and an assembly for the following code,
14428 : : where crc_bit_size and data_bit_size may be 8, 16, 32, 64:
14429 : : uint_crc_bit_size_t
14430 : : crc_crc_bit_size (uint_crc_bit_size_t crc_init,
14431 : : uint_data_bit_size_t data, size_t size)
14432 : : {
14433 : : uint_crc_bit_size_t crc = crc_init;
14434 : : for (int i = 0; i < data_bit_size / 8; i++)
14435 : : crc = (crc << 8) ^ crc_table[(crc >> (crc_bit_size - 8))
14436 : : ^ (data >> (data_bit_size - (i + 1) * 8)
14437 : : & 0xFF))];
14438 : : return crc;
14439 : : } */
14440 : :
14441 : : void
14442 : 135 : expand_crc_table_based (rtx op0, rtx op1, rtx op2, rtx op3,
14443 : : machine_mode data_mode)
14444 : : {
14445 : 135 : gcc_assert (!CONST_INT_P (op0));
14446 : 135 : gcc_assert (CONST_INT_P (op3));
14447 : 135 : machine_mode crc_mode = GET_MODE (op0);
14448 : 135 : rtx crc = gen_reg_rtx (crc_mode);
14449 : 135 : convert_move (crc, op1, 0);
14450 : 135 : calculate_table_based_CRC (&crc, op2, op3, data_mode);
14451 : 135 : convert_move (op0, crc, 0);
14452 : 135 : }
14453 : :
14454 : : /* Generate the common operation for reflecting values:
14455 : : *OP = (*OP & AND1_VALUE) << SHIFT_VAL | (*OP & AND2_VALUE) >> SHIFT_VAL; */
14456 : :
14457 : : void
14458 : 1588 : gen_common_operation_to_reflect (rtx *op,
14459 : : unsigned HOST_WIDE_INT and1_value,
14460 : : unsigned HOST_WIDE_INT and2_value,
14461 : : unsigned shift_val)
14462 : : {
14463 : 1588 : rtx op1 = expand_and (GET_MODE (*op), *op,
14464 : 1588 : gen_int_mode (and1_value, GET_MODE (*op)), NULL_RTX);
14465 : 1588 : op1 = expand_shift (LSHIFT_EXPR, GET_MODE (*op), op1, shift_val, op1, 0);
14466 : 1588 : rtx op2 = expand_and (GET_MODE (*op), *op,
14467 : 1588 : gen_int_mode (and2_value, GET_MODE (*op)), NULL_RTX);
14468 : 1588 : op2 = expand_shift (RSHIFT_EXPR, GET_MODE (*op), op2, shift_val, op2, 1);
14469 : 1588 : *op = expand_binop (GET_MODE (*op), ior_optab, op1,
14470 : : op2, *op, 0, OPTAB_LIB_WIDEN);
14471 : 1588 : }
14472 : :
14473 : : /* Reflect 64-bit value for the 64-bit target. */
14474 : :
14475 : : void
14476 : 47 : reflect_64_bit_value (rtx *op)
14477 : : {
14478 : 47 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x00000000FFFFFFFF),
14479 : : HOST_WIDE_INT_C (0xFFFFFFFF00000000), 32);
14480 : 47 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x0000FFFF0000FFFF),
14481 : : HOST_WIDE_INT_C (0xFFFF0000FFFF0000), 16);
14482 : 47 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x00FF00FF00FF00FF),
14483 : : HOST_WIDE_INT_C (0xFF00FF00FF00FF00), 8);
14484 : 47 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x0F0F0F0F0F0F0F0F),
14485 : : HOST_WIDE_INT_C (0xF0F0F0F0F0F0F0F0), 4);
14486 : 47 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x3333333333333333),
14487 : : HOST_WIDE_INT_C (0xCCCCCCCCCCCCCCCC), 2);
14488 : 47 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x5555555555555555),
14489 : : HOST_WIDE_INT_C (0xAAAAAAAAAAAAAAAA), 1);
14490 : 47 : }
14491 : :
14492 : : /* Reflect 32-bit value for the 32-bit target. */
14493 : :
14494 : : void
14495 : 107 : reflect_32_bit_value (rtx *op)
14496 : : {
14497 : 107 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x0000FFFF),
14498 : : HOST_WIDE_INT_C (0xFFFF0000), 16);
14499 : 107 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x00FF00FF),
14500 : : HOST_WIDE_INT_C (0xFF00FF00), 8);
14501 : 107 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x0F0F0F0F),
14502 : : HOST_WIDE_INT_C (0xF0F0F0F0), 4);
14503 : 107 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x33333333),
14504 : : HOST_WIDE_INT_C (0xCCCCCCCC), 2);
14505 : 107 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x55555555),
14506 : : HOST_WIDE_INT_C (0xAAAAAAAA), 1);
14507 : 107 : }
14508 : :
14509 : : /* Reflect 16-bit value for the 16-bit target. */
14510 : :
14511 : : void
14512 : 108 : reflect_16_bit_value (rtx *op)
14513 : : {
14514 : 108 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x00FF),
14515 : : HOST_WIDE_INT_C (0xFF00), 8);
14516 : 108 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x0F0F),
14517 : : HOST_WIDE_INT_C (0xF0F0), 4);
14518 : 108 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x3333),
14519 : : HOST_WIDE_INT_C (0xCCCC), 2);
14520 : 108 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x5555),
14521 : : HOST_WIDE_INT_C (0xAAAA), 1);
14522 : 108 : }
14523 : :
14524 : : /* Reflect 8-bit value for the 8-bit target. */
14525 : :
14526 : : void
14527 : 113 : reflect_8_bit_value (rtx *op)
14528 : : {
14529 : 113 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x0F),
14530 : : HOST_WIDE_INT_C (0xF0), 4);
14531 : 113 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x33),
14532 : : HOST_WIDE_INT_C (0xCC), 2);
14533 : 113 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x55),
14534 : : HOST_WIDE_INT_C (0xAA), 1);
14535 : 113 : }
14536 : :
14537 : : /* Generate instruction sequence which reflects the value of the OP
14538 : : using shift, and, or operations. OP's mode may be less than word_mode. */
14539 : :
14540 : : void
14541 : 375 : generate_reflecting_code_standard (rtx *op)
14542 : : {
14543 : 1125 : gcc_assert (GET_MODE_BITSIZE (GET_MODE (*op)).to_constant () >= 8
14544 : : && GET_MODE_BITSIZE (GET_MODE (*op)).to_constant () <= 64);
14545 : :
14546 : 750 : if (GET_MODE_BITSIZE (GET_MODE (*op)).to_constant () == 64)
14547 : 47 : reflect_64_bit_value (op);
14548 : 656 : else if (GET_MODE_BITSIZE (GET_MODE (*op)).to_constant () == 32)
14549 : 107 : reflect_32_bit_value (op);
14550 : 442 : else if (GET_MODE_BITSIZE (GET_MODE (*op)).to_constant () == 16)
14551 : 108 : reflect_16_bit_value (op);
14552 : : else
14553 : 113 : reflect_8_bit_value (op);
14554 : 375 : }
14555 : :
14556 : : /* Generate table-based reversed CRC code for the given CRC, INPUT_DATA and
14557 : : the POLYNOMIAL (without leading 1).
14558 : :
14559 : : CRC is OP1, data is OP2 and the polynomial is OP3.
14560 : : This must generate CRC table and assembly for the following code,
14561 : : where crc_bit_size and data_bit_size may be 8, 16, 32, 64:
14562 : : uint_crc_bit_size_t
14563 : : crc_crc_bit_size (uint_crc_bit_size_t crc_init,
14564 : : uint_data_bit_size_t data, size_t size)
14565 : : {
14566 : : reflect (crc_init)
14567 : : uint_crc_bit_size_t crc = crc_init;
14568 : : reflect (data);
14569 : : for (int i = 0; i < data_bit_size / 8; i++)
14570 : : crc = (crc << 8) ^ crc_table[(crc >> (crc_bit_size - 8))
14571 : : ^ (data >> (data_bit_size - (i + 1) * 8) & 0xFF))];
14572 : : reflect (crc);
14573 : : return crc;
14574 : : } */
14575 : :
14576 : : void
14577 : 125 : expand_reversed_crc_table_based (rtx op0, rtx op1, rtx op2, rtx op3,
14578 : : machine_mode data_mode,
14579 : : void (*gen_reflecting_code) (rtx *op))
14580 : : {
14581 : 125 : gcc_assert (!CONST_INT_P (op0));
14582 : 125 : gcc_assert (CONST_INT_P (op3));
14583 : 125 : machine_mode crc_mode = GET_MODE (op0);
14584 : :
14585 : 125 : rtx crc = gen_reg_rtx (crc_mode);
14586 : 125 : convert_move (crc, op1, 0);
14587 : 125 : gen_reflecting_code (&crc);
14588 : :
14589 : 125 : rtx data = gen_reg_rtx (data_mode);
14590 : 125 : convert_move (data, op2, 0);
14591 : 125 : gen_reflecting_code (&data);
14592 : :
14593 : 125 : calculate_table_based_CRC (&crc, data, op3, data_mode);
14594 : :
14595 : 125 : gen_reflecting_code (&crc);
14596 : 125 : convert_move (op0, crc, 0);
14597 : 125 : }
|