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 : : /* Cache of the "extended" flag in the target's _BitInt description
80 : : for use during expand. */
81 : : int bitint_extended = -1;
82 : :
83 : : static bool block_move_libcall_safe_for_call_parm (void);
84 : : static bool emit_block_move_via_pattern (rtx, rtx, rtx, unsigned, unsigned,
85 : : HOST_WIDE_INT, unsigned HOST_WIDE_INT,
86 : : unsigned HOST_WIDE_INT,
87 : : unsigned HOST_WIDE_INT, bool);
88 : : static void emit_block_move_via_loop (rtx, rtx, rtx, unsigned, int);
89 : : static void emit_block_move_via_sized_loop (rtx, rtx, rtx, unsigned, unsigned);
90 : : static void emit_block_move_via_oriented_loop (rtx, rtx, rtx, unsigned, unsigned);
91 : : static rtx emit_block_cmp_via_loop (rtx, rtx, rtx, tree, rtx, bool,
92 : : unsigned, unsigned);
93 : : static rtx_insn *compress_float_constant (rtx, rtx);
94 : : static rtx get_subtarget (rtx);
95 : : static rtx store_field (rtx, poly_int64, poly_int64, poly_uint64, poly_uint64,
96 : : machine_mode, tree, alias_set_type, bool, bool);
97 : :
98 : : static unsigned HOST_WIDE_INT highest_pow2_factor_for_target (const_tree, const_tree);
99 : :
100 : : static bool is_aligning_offset (const_tree, const_tree);
101 : : static rtx reduce_to_bit_field_precision (rtx, rtx, tree);
102 : : static rtx do_store_flag (const_sepops, rtx, machine_mode);
103 : : #ifdef PUSH_ROUNDING
104 : : static void emit_single_push_insn (machine_mode, rtx, tree);
105 : : #endif
106 : : static void do_tablejump (rtx, machine_mode, rtx, rtx, rtx,
107 : : profile_probability);
108 : : static rtx const_vector_from_tree (tree);
109 : : static tree tree_expr_size (const_tree);
110 : : static void convert_mode_scalar (rtx, rtx, int);
111 : :
112 : :
113 : : /* This is run to set up which modes can be used
114 : : directly in memory and to initialize the block move optab. It is run
115 : : at the beginning of compilation and when the target is reinitialized. */
116 : :
117 : : void
118 : 214285 : init_expr_target (void)
119 : : {
120 : 214285 : rtx pat;
121 : 214285 : int num_clobbers;
122 : 214285 : rtx mem, mem1;
123 : 214285 : rtx reg;
124 : :
125 : : /* Try indexing by frame ptr and try by stack ptr.
126 : : It is known that on the Convex the stack ptr isn't a valid index.
127 : : With luck, one or the other is valid on any machine. */
128 : 214285 : mem = gen_rtx_MEM (word_mode, stack_pointer_rtx);
129 : 214285 : mem1 = gen_rtx_MEM (word_mode, frame_pointer_rtx);
130 : :
131 : : /* A scratch register we can modify in-place below to avoid
132 : : useless RTL allocations. */
133 : 214285 : reg = gen_rtx_REG (word_mode, LAST_VIRTUAL_REGISTER + 1);
134 : :
135 : 214285 : rtx_insn *insn = as_a<rtx_insn *> (rtx_alloc (INSN));
136 : 214285 : pat = gen_rtx_SET (NULL_RTX, NULL_RTX);
137 : 214285 : PATTERN (insn) = pat;
138 : :
139 : 26785625 : for (machine_mode mode = VOIDmode; (int) mode < NUM_MACHINE_MODES;
140 : 26571340 : mode = (machine_mode) ((int) mode + 1))
141 : : {
142 : 26571340 : int regno;
143 : :
144 : 26571340 : direct_load[(int) mode] = direct_store[(int) mode] = 0;
145 : 26571340 : PUT_MODE (mem, mode);
146 : 26571340 : PUT_MODE (mem1, mode);
147 : :
148 : : /* See if there is some register that can be used in this mode and
149 : : directly loaded or stored from memory. */
150 : :
151 : 26571340 : if (mode != VOIDmode && mode != BLKmode)
152 : 1790702105 : for (regno = 0; regno < FIRST_PSEUDO_REGISTER
153 : 1816844875 : && (direct_load[(int) mode] == 0 || direct_store[(int) mode] == 0);
154 : : regno++)
155 : : {
156 : 1790702105 : if (!targetm.hard_regno_mode_ok (regno, mode))
157 : 1673422349 : continue;
158 : :
159 : 117279756 : set_mode_and_regno (reg, mode, regno);
160 : :
161 : 117279756 : SET_SRC (pat) = mem;
162 : 117279756 : SET_DEST (pat) = reg;
163 : 117279756 : if (recog (pat, insn, &num_clobbers) >= 0)
164 : 7209577 : direct_load[(int) mode] = 1;
165 : :
166 : 117279756 : SET_SRC (pat) = mem1;
167 : 117279756 : SET_DEST (pat) = reg;
168 : 117279756 : if (recog (pat, insn, &num_clobbers) >= 0)
169 : 7209577 : direct_load[(int) mode] = 1;
170 : :
171 : 117279756 : SET_SRC (pat) = reg;
172 : 117279756 : SET_DEST (pat) = mem;
173 : 117279756 : if (recog (pat, insn, &num_clobbers) >= 0)
174 : 7209577 : direct_store[(int) mode] = 1;
175 : :
176 : 117279756 : SET_SRC (pat) = reg;
177 : 117279756 : SET_DEST (pat) = mem1;
178 : 117279756 : if (recog (pat, insn, &num_clobbers) >= 0)
179 : 7209577 : direct_store[(int) mode] = 1;
180 : : }
181 : : }
182 : :
183 : 219963 : mem = gen_rtx_MEM (VOIDmode, gen_raw_REG (Pmode, LAST_VIRTUAL_REGISTER + 1));
184 : :
185 : 214285 : opt_scalar_float_mode mode_iter;
186 : 1499995 : FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_FLOAT)
187 : : {
188 : 1285710 : scalar_float_mode mode = mode_iter.require ();
189 : 1285710 : scalar_float_mode srcmode;
190 : 4499985 : FOR_EACH_MODE_UNTIL (srcmode, mode)
191 : : {
192 : 3214275 : enum insn_code ic;
193 : :
194 : 3214275 : ic = can_extend_p (mode, srcmode, 0);
195 : 3214275 : if (ic == CODE_FOR_nothing)
196 : 2566754 : continue;
197 : :
198 : 647521 : PUT_MODE (mem, srcmode);
199 : :
200 : 647521 : if (insn_operand_matches (ic, 1, mem))
201 : 645425 : float_extend_from_mem[mode][srcmode] = true;
202 : : }
203 : : }
204 : 214285 : }
205 : :
206 : : /* This is run at the start of compiling a function. */
207 : :
208 : : void
209 : 1692682 : init_expr (void)
210 : : {
211 : 1692682 : memset (&crtl->expr, 0, sizeof (crtl->expr));
212 : 1692682 : }
213 : :
214 : : /* Copy data from FROM to TO, where the machine modes are not the same.
215 : : Both modes may be integer, or both may be floating, or both may be
216 : : fixed-point.
217 : : UNSIGNEDP should be nonzero if FROM is an unsigned type.
218 : : This causes zero-extension instead of sign-extension. */
219 : :
220 : : void
221 : 2082304 : convert_move (rtx to, rtx from, int unsignedp)
222 : : {
223 : 2082304 : machine_mode to_mode = GET_MODE (to);
224 : 2082304 : machine_mode from_mode = GET_MODE (from);
225 : :
226 : 2082304 : gcc_assert (to_mode != BLKmode);
227 : 2082304 : gcc_assert (from_mode != BLKmode);
228 : :
229 : : /* If the source and destination are already the same, then there's
230 : : nothing to do. */
231 : 2082304 : if (to == from)
232 : 2082304 : return;
233 : :
234 : : /* If FROM is a SUBREG that indicates that we have already done at least
235 : : the required extension, strip it. We don't handle such SUBREGs as
236 : : TO here. */
237 : :
238 : 2082304 : scalar_int_mode to_int_mode;
239 : 2082304 : if (GET_CODE (from) == SUBREG
240 : 116590 : && SUBREG_PROMOTED_VAR_P (from)
241 : 2082304 : && is_a <scalar_int_mode> (to_mode, &to_int_mode)
242 : 2082304 : && (GET_MODE_PRECISION (subreg_promoted_mode (from))
243 : 0 : >= GET_MODE_PRECISION (to_int_mode))
244 : 2082304 : && SUBREG_CHECK_PROMOTED_SIGN (from, unsignedp))
245 : : {
246 : 0 : scalar_int_mode int_orig_mode;
247 : 0 : scalar_int_mode int_inner_mode;
248 : 0 : machine_mode orig_mode = GET_MODE (from);
249 : :
250 : 0 : from = gen_lowpart (to_int_mode, SUBREG_REG (from));
251 : 0 : from_mode = to_int_mode;
252 : :
253 : : /* Preserve SUBREG_PROMOTED_VAR_P if the new mode is wider than
254 : : the original mode, but narrower than the inner mode. */
255 : 0 : if (GET_CODE (from) == SUBREG
256 : 0 : && is_a <scalar_int_mode> (orig_mode, &int_orig_mode)
257 : 0 : && GET_MODE_PRECISION (to_int_mode)
258 : 0 : > GET_MODE_PRECISION (int_orig_mode)
259 : 0 : && is_a <scalar_int_mode> (GET_MODE (SUBREG_REG (from)),
260 : : &int_inner_mode)
261 : 0 : && GET_MODE_PRECISION (int_inner_mode)
262 : 0 : > GET_MODE_PRECISION (to_int_mode))
263 : : {
264 : 0 : SUBREG_PROMOTED_VAR_P (from) = 1;
265 : 0 : SUBREG_PROMOTED_SET (from, unsignedp);
266 : : }
267 : : }
268 : :
269 : 2082304 : gcc_assert (GET_CODE (to) != SUBREG || !SUBREG_PROMOTED_VAR_P (to));
270 : :
271 : 2082304 : if (to_mode == from_mode
272 : 2030564 : || (from_mode == VOIDmode && CONSTANT_P (from)))
273 : : {
274 : 52003 : emit_move_insn (to, from);
275 : 52003 : return;
276 : : }
277 : :
278 : 2030301 : if (VECTOR_MODE_P (to_mode) || VECTOR_MODE_P (from_mode))
279 : : {
280 : 28578 : if (GET_MODE_UNIT_PRECISION (to_mode)
281 : 14289 : > GET_MODE_UNIT_PRECISION (from_mode))
282 : : {
283 : 5318 : optab op = unsignedp ? zext_optab : sext_optab;
284 : 5318 : insn_code icode = convert_optab_handler (op, to_mode, from_mode);
285 : 5318 : if (icode != CODE_FOR_nothing)
286 : : {
287 : 480 : emit_unop_insn (icode, to, from,
288 : : unsignedp ? ZERO_EXTEND : SIGN_EXTEND);
289 : 480 : return;
290 : : }
291 : : }
292 : :
293 : 27618 : if (GET_MODE_UNIT_PRECISION (to_mode)
294 : 13809 : < GET_MODE_UNIT_PRECISION (from_mode))
295 : : {
296 : 1849 : insn_code icode = convert_optab_handler (trunc_optab,
297 : : to_mode, from_mode);
298 : 1849 : if (icode != CODE_FOR_nothing)
299 : : {
300 : 808 : emit_unop_insn (icode, to, from, TRUNCATE);
301 : 808 : return;
302 : : }
303 : : }
304 : :
305 : 39003 : gcc_assert (known_eq (GET_MODE_BITSIZE (from_mode),
306 : : GET_MODE_BITSIZE (to_mode)));
307 : :
308 : 13001 : if (VECTOR_MODE_P (to_mode))
309 : 13001 : from = force_subreg (to_mode, from, GET_MODE (from), 0);
310 : : else
311 : 0 : to = simplify_gen_subreg (from_mode, to, GET_MODE (to), 0);
312 : :
313 : 13001 : emit_move_insn (to, from);
314 : 13001 : return;
315 : : }
316 : :
317 : 2016012 : if (GET_CODE (to) == CONCAT && GET_CODE (from) == CONCAT)
318 : : {
319 : 0 : convert_move (XEXP (to, 0), XEXP (from, 0), unsignedp);
320 : 0 : convert_move (XEXP (to, 1), XEXP (from, 1), unsignedp);
321 : 0 : return;
322 : : }
323 : :
324 : 2016012 : convert_mode_scalar (to, from, unsignedp);
325 : : }
326 : :
327 : : /* Like convert_move, but deals only with scalar modes. */
328 : :
329 : : static void
330 : 2016062 : convert_mode_scalar (rtx to, rtx from, int unsignedp)
331 : : {
332 : : /* Both modes should be scalar types. */
333 : 2016067 : scalar_mode from_mode = as_a <scalar_mode> (GET_MODE (from));
334 : 2016067 : scalar_mode to_mode = as_a <scalar_mode> (GET_MODE (to));
335 : 2016067 : bool to_real = SCALAR_FLOAT_MODE_P (to_mode);
336 : 2016067 : bool from_real = SCALAR_FLOAT_MODE_P (from_mode);
337 : 2016067 : enum insn_code code;
338 : 2016067 : rtx libcall;
339 : :
340 : 2016067 : gcc_assert (to_real == from_real);
341 : :
342 : : /* rtx code for making an equivalent value. */
343 : 3118193 : enum rtx_code equiv_code = (unsignedp < 0 ? UNKNOWN
344 : 2016067 : : (unsignedp ? ZERO_EXTEND : SIGN_EXTEND));
345 : :
346 : 2016067 : auto acceptable_same_precision_modes
347 : 580 : = [] (scalar_mode from_mode, scalar_mode to_mode) -> bool
348 : : {
349 : 580 : if (DECIMAL_FLOAT_MODE_P (from_mode) != DECIMAL_FLOAT_MODE_P (to_mode))
350 : : return true;
351 : :
352 : : /* arm_bfloat_half_format <-> ieee_half_format */
353 : 2 : if ((REAL_MODE_FORMAT (from_mode) == &arm_bfloat_half_format
354 : 1 : && REAL_MODE_FORMAT (to_mode) == &ieee_half_format)
355 : 2 : || (REAL_MODE_FORMAT (to_mode) == &arm_bfloat_half_format
356 : 1 : && REAL_MODE_FORMAT (from_mode) == &ieee_half_format))
357 : : return true;
358 : :
359 : : /* ibm_extended_format <-> ieee_quad_format */
360 : 0 : if ((REAL_MODE_FORMAT (from_mode) == &ibm_extended_format
361 : 0 : && REAL_MODE_FORMAT (to_mode) == &ieee_quad_format)
362 : 0 : || (REAL_MODE_FORMAT (from_mode) == &ieee_quad_format
363 : 0 : && REAL_MODE_FORMAT (to_mode) == &ibm_extended_format))
364 : 0 : return true;
365 : :
366 : : return false;
367 : : };
368 : :
369 : 2016067 : if (to_real)
370 : : {
371 : 185389 : rtx value;
372 : 185389 : rtx_insn *insns;
373 : 185389 : convert_optab tab;
374 : :
375 : 185389 : gcc_assert ((GET_MODE_PRECISION (from_mode)
376 : : != GET_MODE_PRECISION (to_mode))
377 : : || acceptable_same_precision_modes (from_mode, to_mode));
378 : :
379 : 185389 : if (GET_MODE_PRECISION (from_mode) == GET_MODE_PRECISION (to_mode))
380 : : {
381 : 580 : if ((REAL_MODE_FORMAT (to_mode) == &arm_bfloat_half_format
382 : 1 : && REAL_MODE_FORMAT (from_mode) == &ieee_half_format)
383 : 580 : || (REAL_MODE_FORMAT (to_mode) == &ieee_quad_format
384 : 0 : && REAL_MODE_FORMAT (from_mode) == &ibm_extended_format))
385 : : /* libgcc implements just __trunchfbf2, not __extendhfbf2;
386 : : and __trunctfkf2, not __extendtfkf2. */
387 : : tab = trunc_optab;
388 : : else
389 : : /* Conversion between decimal float and binary float, same
390 : : size. */
391 : 579 : tab = DECIMAL_FLOAT_MODE_P (from_mode) ? trunc_optab : sext_optab;
392 : : }
393 : 184809 : else if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode))
394 : : tab = sext_optab;
395 : : else
396 : 19441 : tab = trunc_optab;
397 : :
398 : : /* Try converting directly if the insn is supported. */
399 : :
400 : 185389 : code = convert_optab_handler (tab, to_mode, from_mode);
401 : 185389 : if (code != CODE_FOR_nothing)
402 : : {
403 : 160989 : emit_unop_insn (code, to, from,
404 : : tab == sext_optab ? FLOAT_EXTEND : FLOAT_TRUNCATE);
405 : 160989 : return;
406 : : }
407 : :
408 : : #ifdef HAVE_SFmode
409 : 24400 : if (REAL_MODE_FORMAT (from_mode) == &arm_bfloat_half_format
410 : 24400 : && REAL_MODE_FORMAT (SFmode) == &ieee_single_format)
411 : : {
412 : 2812 : if (GET_MODE_PRECISION (to_mode) > GET_MODE_PRECISION (SFmode))
413 : : {
414 : : /* To cut down on libgcc size, implement
415 : : BFmode -> {DF,XF,TF}mode conversions by
416 : : BFmode -> SFmode -> {DF,XF,TF}mode conversions. */
417 : 4 : rtx temp = gen_reg_rtx (SFmode);
418 : 4 : convert_mode_scalar (temp, from, unsignedp);
419 : 4 : convert_mode_scalar (to, temp, unsignedp);
420 : 4 : return;
421 : : }
422 : 2808 : if (REAL_MODE_FORMAT (to_mode) == &ieee_half_format)
423 : : {
424 : : /* Similarly, implement BFmode -> HFmode as
425 : : BFmode -> SFmode -> HFmode conversion where SFmode
426 : : has superset of BFmode values. We don't need
427 : : to handle sNaNs by raising exception and turning
428 : : it into qNaN though, as that can be done in the
429 : : SFmode -> HFmode conversion too. */
430 : 1 : rtx temp = gen_reg_rtx (SFmode);
431 : 1 : int save_flag_finite_math_only = flag_finite_math_only;
432 : 1 : flag_finite_math_only = true;
433 : 1 : convert_mode_scalar (temp, from, unsignedp);
434 : 1 : flag_finite_math_only = save_flag_finite_math_only;
435 : 1 : convert_mode_scalar (to, temp, unsignedp);
436 : 1 : return;
437 : : }
438 : 2807 : if (to_mode == SFmode
439 : 2807 : && !HONOR_NANS (from_mode)
440 : 46 : && !HONOR_NANS (to_mode)
441 : 2853 : && optimize_insn_for_speed_p ())
442 : : {
443 : : /* If we don't expect sNaNs, for BFmode -> SFmode we can just
444 : : shift the bits up. */
445 : 45 : machine_mode fromi_mode, toi_mode;
446 : 90 : if (int_mode_for_size (GET_MODE_BITSIZE (from_mode),
447 : 45 : 0).exists (&fromi_mode)
448 : 45 : && int_mode_for_size (GET_MODE_BITSIZE (to_mode),
449 : 0 : 0).exists (&toi_mode))
450 : : {
451 : 45 : start_sequence ();
452 : 45 : rtx fromi = force_lowpart_subreg (fromi_mode, from,
453 : : from_mode);
454 : 45 : rtx tof = NULL_RTX;
455 : 45 : if (fromi)
456 : : {
457 : 45 : rtx toi;
458 : 45 : if (GET_MODE (fromi) == VOIDmode)
459 : 0 : toi = simplify_unary_operation (ZERO_EXTEND, toi_mode,
460 : : fromi, fromi_mode);
461 : : else
462 : : {
463 : 45 : toi = gen_reg_rtx (toi_mode);
464 : 45 : convert_mode_scalar (toi, fromi, 1);
465 : : }
466 : 45 : toi
467 : 90 : = maybe_expand_shift (LSHIFT_EXPR, toi_mode, toi,
468 : 45 : GET_MODE_PRECISION (to_mode)
469 : 45 : - GET_MODE_PRECISION (from_mode),
470 : : NULL_RTX, 1);
471 : 45 : if (toi)
472 : : {
473 : 45 : tof = force_lowpart_subreg (to_mode, toi, toi_mode);
474 : 45 : if (tof)
475 : 45 : emit_move_insn (to, tof);
476 : : }
477 : : }
478 : 45 : insns = end_sequence ();
479 : 45 : if (tof)
480 : : {
481 : 45 : emit_insn (insns);
482 : 45 : return;
483 : : }
484 : : }
485 : : }
486 : : }
487 : 24350 : if (REAL_MODE_FORMAT (from_mode) == &ieee_single_format
488 : 5077 : && REAL_MODE_FORMAT (to_mode) == &arm_bfloat_half_format
489 : 1872 : && !HONOR_NANS (from_mode)
490 : 0 : && !HONOR_NANS (to_mode)
491 : 0 : && !flag_rounding_math
492 : 24350 : && optimize_insn_for_speed_p ())
493 : : {
494 : : /* If we don't expect qNaNs nor sNaNs and can assume rounding
495 : : to nearest, we can expand the conversion inline as
496 : : (fromi + 0x7fff + ((fromi >> 16) & 1)) >> 16. */
497 : 0 : machine_mode fromi_mode, toi_mode;
498 : 0 : if (int_mode_for_size (GET_MODE_BITSIZE (from_mode),
499 : 0 : 0).exists (&fromi_mode)
500 : 0 : && int_mode_for_size (GET_MODE_BITSIZE (to_mode),
501 : 0 : 0).exists (&toi_mode))
502 : : {
503 : 0 : start_sequence ();
504 : 0 : rtx fromi = force_lowpart_subreg (fromi_mode, from, from_mode);
505 : 0 : rtx tof = NULL_RTX;
506 : 0 : do
507 : : {
508 : 0 : if (!fromi)
509 : : break;
510 : 0 : int shift = (GET_MODE_PRECISION (from_mode)
511 : 0 : - GET_MODE_PRECISION (to_mode));
512 : 0 : rtx temp1
513 : 0 : = maybe_expand_shift (RSHIFT_EXPR, fromi_mode, fromi,
514 : : shift, NULL_RTX, 1);
515 : 0 : if (!temp1)
516 : : break;
517 : 0 : rtx temp2
518 : 0 : = expand_binop (fromi_mode, and_optab, temp1, const1_rtx,
519 : : NULL_RTX, 1, OPTAB_DIRECT);
520 : 0 : if (!temp2)
521 : : break;
522 : 0 : rtx temp3
523 : 0 : = expand_binop (fromi_mode, add_optab, fromi,
524 : : gen_int_mode ((HOST_WIDE_INT_1U
525 : 0 : << (shift - 1)) - 1,
526 : : fromi_mode), NULL_RTX,
527 : : 1, OPTAB_DIRECT);
528 : 0 : if (!temp3)
529 : : break;
530 : 0 : rtx temp4
531 : 0 : = expand_binop (fromi_mode, add_optab, temp3, temp2,
532 : : NULL_RTX, 1, OPTAB_DIRECT);
533 : 0 : if (!temp4)
534 : : break;
535 : 0 : rtx temp5 = maybe_expand_shift (RSHIFT_EXPR, fromi_mode,
536 : : temp4, shift, NULL_RTX, 1);
537 : 0 : if (!temp5)
538 : : break;
539 : 0 : rtx temp6 = force_lowpart_subreg (toi_mode, temp5,
540 : : fromi_mode);
541 : 0 : if (!temp6)
542 : : break;
543 : 0 : tof = force_lowpart_subreg (to_mode, temp6, toi_mode);
544 : 0 : if (tof)
545 : 0 : emit_move_insn (to, tof);
546 : : }
547 : : while (0);
548 : 0 : insns = end_sequence ();
549 : 0 : if (tof)
550 : : {
551 : 0 : emit_insn (insns);
552 : 0 : return;
553 : : }
554 : : }
555 : : }
556 : : #endif
557 : :
558 : : /* Otherwise use a libcall. */
559 : 24350 : libcall = convert_optab_libfunc (tab, to_mode, from_mode);
560 : :
561 : : /* Is this conversion implemented yet? */
562 : 24350 : gcc_assert (libcall);
563 : :
564 : 24350 : start_sequence ();
565 : 24350 : value = emit_library_call_value (libcall, NULL_RTX, LCT_CONST, to_mode,
566 : : from, from_mode);
567 : 24350 : insns = end_sequence ();
568 : 24350 : emit_libcall_block (insns, to, value,
569 : 7558 : tab == trunc_optab ? gen_rtx_FLOAT_TRUNCATE (to_mode,
570 : : from)
571 : 16792 : : gen_rtx_FLOAT_EXTEND (to_mode, from));
572 : 24350 : return;
573 : : }
574 : :
575 : : /* Handle pointer conversion. */ /* SPEE 900220. */
576 : : /* If the target has a converter from FROM_MODE to TO_MODE, use it. */
577 : 1830678 : {
578 : 1830678 : convert_optab ctab;
579 : :
580 : 1830678 : if (GET_MODE_PRECISION (from_mode) > GET_MODE_PRECISION (to_mode))
581 : : ctab = trunc_optab;
582 : 1636031 : else if (unsignedp)
583 : : ctab = zext_optab;
584 : : else
585 : 831330 : ctab = sext_optab;
586 : :
587 : 1830678 : if (convert_optab_handler (ctab, to_mode, from_mode)
588 : : != CODE_FOR_nothing)
589 : : {
590 : 1630589 : emit_unop_insn (convert_optab_handler (ctab, to_mode, from_mode),
591 : : to, from, UNKNOWN);
592 : 1630589 : return;
593 : : }
594 : : }
595 : :
596 : : /* Targets are expected to provide conversion insns between PxImode and
597 : : xImode for all MODE_PARTIAL_INT modes they use, but no others. */
598 : 200089 : if (GET_MODE_CLASS (to_mode) == MODE_PARTIAL_INT)
599 : : {
600 : 0 : scalar_int_mode full_mode
601 : 0 : = smallest_int_mode_for_size (GET_MODE_BITSIZE (to_mode)).require ();
602 : :
603 : 0 : gcc_assert (convert_optab_handler (trunc_optab, to_mode, full_mode)
604 : : != CODE_FOR_nothing);
605 : :
606 : 0 : if (full_mode != from_mode)
607 : 0 : from = convert_to_mode (full_mode, from, unsignedp);
608 : 0 : emit_unop_insn (convert_optab_handler (trunc_optab, to_mode, full_mode),
609 : : to, from, UNKNOWN);
610 : 0 : return;
611 : : }
612 : 200089 : if (GET_MODE_CLASS (from_mode) == MODE_PARTIAL_INT)
613 : : {
614 : 0 : rtx new_from;
615 : 0 : scalar_int_mode full_mode
616 : 0 : = smallest_int_mode_for_size (GET_MODE_BITSIZE (from_mode)).require ();
617 : 0 : convert_optab ctab = unsignedp ? zext_optab : sext_optab;
618 : 0 : enum insn_code icode;
619 : :
620 : 0 : icode = convert_optab_handler (ctab, full_mode, from_mode);
621 : 0 : gcc_assert (icode != CODE_FOR_nothing);
622 : :
623 : 0 : if (to_mode == full_mode)
624 : : {
625 : 0 : emit_unop_insn (icode, to, from, UNKNOWN);
626 : 0 : return;
627 : : }
628 : :
629 : 0 : new_from = gen_reg_rtx (full_mode);
630 : 0 : emit_unop_insn (icode, new_from, from, UNKNOWN);
631 : :
632 : : /* else proceed to integer conversions below. */
633 : 0 : from_mode = full_mode;
634 : 0 : from = new_from;
635 : : }
636 : :
637 : : /* Make sure both are fixed-point modes or both are not. */
638 : 200089 : gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode) ==
639 : : ALL_SCALAR_FIXED_POINT_MODE_P (to_mode));
640 : 200089 : if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode))
641 : : {
642 : : /* If we widen from_mode to to_mode and they are in the same class,
643 : : we won't saturate the result.
644 : : Otherwise, always saturate the result to play safe. */
645 : 0 : if (GET_MODE_CLASS (from_mode) == GET_MODE_CLASS (to_mode)
646 : 0 : && GET_MODE_SIZE (from_mode) < GET_MODE_SIZE (to_mode))
647 : 0 : expand_fixed_convert (to, from, 0, 0);
648 : : else
649 : 0 : expand_fixed_convert (to, from, 0, 1);
650 : 0 : return;
651 : : }
652 : :
653 : : /* Now both modes are integers. */
654 : :
655 : : /* Handle expanding beyond a word. */
656 : 200089 : if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode)
657 : 202828 : && GET_MODE_PRECISION (to_mode) > BITS_PER_WORD)
658 : : {
659 : 5442 : rtx_insn *insns;
660 : 5442 : rtx lowpart;
661 : 5442 : rtx fill_value;
662 : 5442 : rtx lowfrom;
663 : 5442 : int i;
664 : 5442 : scalar_mode lowpart_mode;
665 : 10884 : int nwords = CEIL (GET_MODE_SIZE (to_mode), UNITS_PER_WORD);
666 : :
667 : : /* Try converting directly if the insn is supported. */
668 : 5442 : if ((code = can_extend_p (to_mode, from_mode, unsignedp))
669 : : != CODE_FOR_nothing)
670 : : {
671 : : /* If FROM is a SUBREG, put it into a register. Do this
672 : : so that we always generate the same set of insns for
673 : : better cse'ing; if an intermediate assignment occurred,
674 : : we won't be doing the operation directly on the SUBREG. */
675 : 0 : if (optimize > 0 && GET_CODE (from) == SUBREG)
676 : 0 : from = force_reg (from_mode, from);
677 : 0 : emit_unop_insn (code, to, from, equiv_code);
678 : 0 : return;
679 : : }
680 : : /* Next, try converting via full word. */
681 : 5442 : else if (GET_MODE_PRECISION (from_mode) < BITS_PER_WORD
682 : 5442 : && ((code = can_extend_p (to_mode, word_mode, unsignedp))
683 : : != CODE_FOR_nothing))
684 : : {
685 : 5442 : rtx word_to = gen_reg_rtx (word_mode);
686 : 5442 : if (REG_P (to))
687 : : {
688 : 5371 : if (reg_overlap_mentioned_p (to, from))
689 : 0 : from = force_reg (from_mode, from);
690 : 5371 : emit_clobber (to);
691 : : }
692 : 5442 : convert_move (word_to, from, unsignedp);
693 : 5442 : emit_unop_insn (code, to, word_to, equiv_code);
694 : 5442 : return;
695 : : }
696 : :
697 : : /* No special multiword conversion insn; do it by hand. */
698 : 0 : start_sequence ();
699 : :
700 : : /* Since we will turn this into a no conflict block, we must ensure
701 : : the source does not overlap the target so force it into an isolated
702 : : register when maybe so. Likewise for any MEM input, since the
703 : : conversion sequence might require several references to it and we
704 : : must ensure we're getting the same value every time. */
705 : :
706 : 0 : if (MEM_P (from) || reg_overlap_mentioned_p (to, from))
707 : 0 : from = force_reg (from_mode, from);
708 : :
709 : : /* Get a copy of FROM widened to a word, if necessary. */
710 : 0 : if (GET_MODE_PRECISION (from_mode) < BITS_PER_WORD)
711 : 0 : lowpart_mode = word_mode;
712 : : else
713 : : lowpart_mode = from_mode;
714 : :
715 : 0 : lowfrom = convert_to_mode (lowpart_mode, from, unsignedp);
716 : :
717 : 0 : lowpart = gen_lowpart (lowpart_mode, to);
718 : 0 : emit_move_insn (lowpart, lowfrom);
719 : :
720 : : /* Compute the value to put in each remaining word. */
721 : 0 : if (unsignedp)
722 : 0 : fill_value = const0_rtx;
723 : : else
724 : 0 : fill_value = emit_store_flag_force (gen_reg_rtx (word_mode),
725 : : LT, lowfrom, const0_rtx,
726 : : lowpart_mode, 0, -1);
727 : :
728 : : /* Fill the remaining words. */
729 : 0 : for (i = GET_MODE_SIZE (lowpart_mode) / UNITS_PER_WORD; i < nwords; i++)
730 : : {
731 : 0 : int index = (WORDS_BIG_ENDIAN ? nwords - i - 1 : i);
732 : 0 : rtx subword = operand_subword (to, index, 1, to_mode);
733 : :
734 : 0 : gcc_assert (subword);
735 : :
736 : 0 : if (fill_value != subword)
737 : 0 : emit_move_insn (subword, fill_value);
738 : : }
739 : :
740 : 0 : insns = end_sequence ();
741 : :
742 : 0 : emit_insn (insns);
743 : 0 : return;
744 : : }
745 : :
746 : : /* Truncating multi-word to a word or less. */
747 : 194647 : if (GET_MODE_PRECISION (from_mode) > BITS_PER_WORD
748 : 194647 : && GET_MODE_PRECISION (to_mode) <= BITS_PER_WORD)
749 : : {
750 : 71509 : if (!((MEM_P (from)
751 : 540 : && ! MEM_VOLATILE_P (from)
752 : 540 : && direct_load[(int) to_mode]
753 : 540 : && ! mode_dependent_address_p (XEXP (from, 0),
754 : 540 : MEM_ADDR_SPACE (from)))
755 : 40467 : || REG_P (from)
756 : : || GET_CODE (from) == SUBREG))
757 : 0 : from = force_reg (from_mode, from);
758 : 41007 : convert_move (to, gen_lowpart (word_mode, from), 0);
759 : 41007 : 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 : 307280 : if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode)
767 : 153640 : && TRULY_NOOP_TRUNCATION_MODES_P (to_mode, from_mode))
768 : : {
769 : 165904 : if (!((MEM_P (from)
770 : 13823 : && ! MEM_VOLATILE_P (from)
771 : 13764 : && direct_load[(int) to_mode]
772 : 13764 : && ! mode_dependent_address_p (XEXP (from, 0),
773 : 13764 : MEM_ADDR_SPACE (from)))
774 : 139876 : || REG_P (from)
775 : : || GET_CODE (from) == SUBREG))
776 : 918 : from = force_reg (from_mode, from);
777 : 128530 : if (REG_P (from) && REGNO (from) < FIRST_PSEUDO_REGISTER
778 : 153641 : && !targetm.hard_regno_mode_ok (REGNO (from), to_mode))
779 : 0 : from = copy_to_reg (from);
780 : 153640 : emit_move_insn (to, gen_lowpart (to_mode, from));
781 : 153640 : 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 : 1895592 : convert_to_mode (machine_mode mode, rtx x, int unsignedp)
869 : : {
870 : 1895592 : 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 : 4764925 : convert_modes (machine_mode mode, machine_mode oldmode, rtx x, int unsignedp)
885 : : {
886 : 4764925 : rtx temp;
887 : 4764925 : 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 : 4764925 : if (GET_CODE (x) == SUBREG
893 : 82770 : && SUBREG_PROMOTED_VAR_P (x)
894 : 4764925 : && is_a <scalar_int_mode> (mode, &int_mode)
895 : 4764925 : && (GET_MODE_PRECISION (subreg_promoted_mode (x))
896 : 7 : >= GET_MODE_PRECISION (int_mode))
897 : 4764932 : && SUBREG_CHECK_PROMOTED_SIGN (x, unsignedp))
898 : : {
899 : 7 : scalar_int_mode int_orig_mode;
900 : 7 : scalar_int_mode int_inner_mode;
901 : 7 : machine_mode orig_mode = GET_MODE (x);
902 : 7 : 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 : 7 : 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 : 7 : && 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 : 4764925 : if (GET_MODE (x) != VOIDmode)
921 : 2452938 : oldmode = GET_MODE (x);
922 : :
923 : 4764925 : if (mode == oldmode)
924 : : return x;
925 : :
926 : 3721523 : if (CONST_SCALAR_INT_P (x)
927 : 3721523 : && 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 : 1987153 : if (!is_a <scalar_int_mode> (oldmode))
933 : 1672707 : oldmode = MAX_MODE_INT;
934 : 1987153 : wide_int w = wide_int::from (rtx_mode_t (x, oldmode),
935 : 1987153 : GET_MODE_PRECISION (int_mode),
936 : 2845358 : unsignedp ? UNSIGNED : SIGNED);
937 : 1987153 : return immed_wide_int_const (w, int_mode);
938 : 1987153 : }
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 : 1734370 : scalar_int_mode int_oldmode;
944 : 1734370 : if (is_int_mode (mode, &int_mode)
945 : 1642221 : && is_int_mode (oldmode, &int_oldmode)
946 : 1642221 : && GET_MODE_PRECISION (int_mode) <= GET_MODE_PRECISION (int_oldmode)
947 : 454192 : && ((MEM_P (x) && !MEM_VOLATILE_P (x) && direct_load[(int) int_mode])
948 : 11850 : || CONST_POLY_INT_P (x)
949 : 442342 : || (REG_P (x)
950 : 405617 : && (!HARD_REGISTER_P (x)
951 : 977 : || targetm.hard_regno_mode_ok (REGNO (x), int_mode))
952 : 405617 : && TRULY_NOOP_TRUNCATION_MODES_P (int_mode, GET_MODE (x)))))
953 : 417467 : return gen_lowpart (int_mode, x);
954 : :
955 : : /* Converting from integer constant into mode is always equivalent to an
956 : : subreg operation. */
957 : 1316903 : 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 : 1316903 : temp = gen_reg_rtx (mode);
965 : 1316903 : convert_move (temp, x, unsignedp);
966 : 1316903 : 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 : 2779586 : alignment_for_piecewise_move (unsigned int max_pieces, unsigned int align)
1000 : : {
1001 : 2779586 : scalar_int_mode tmode
1002 : 2779586 : = int_mode_for_size (max_pieces * BITS_PER_UNIT, 0).require ();
1003 : :
1004 : 2779586 : if (align >= GET_MODE_ALIGNMENT (tmode))
1005 : 2210509 : align = GET_MODE_ALIGNMENT (tmode);
1006 : : else
1007 : : {
1008 : 569077 : scalar_int_mode xmode = NARROWEST_INT_MODE;
1009 : 569077 : opt_scalar_int_mode mode_iter;
1010 : 3430523 : FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_INT)
1011 : : {
1012 : 3424864 : tmode = mode_iter.require ();
1013 : 3424864 : if (GET_MODE_SIZE (tmode) > max_pieces
1014 : 3424864 : || targetm.slow_unaligned_access (tmode, align))
1015 : : break;
1016 : 2861446 : xmode = tmode;
1017 : : }
1018 : :
1019 : 569077 : align = MAX (align, GET_MODE_ALIGNMENT (xmode));
1020 : : }
1021 : :
1022 : 2779586 : return align;
1023 : : }
1024 : :
1025 : : /* Return true if we know how to implement OP using vectors of bytes. */
1026 : : static bool
1027 : 5863082 : can_use_qi_vectors (by_pieces_operation op)
1028 : : {
1029 : 5863082 : return (op == COMPARE_BY_PIECES
1030 : 0 : || op == SET_BY_PIECES
1031 : 0 : || 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 : 25954763 : by_pieces_mode_supported_p (fixed_size_mode mode, by_pieces_operation op)
1038 : : {
1039 : 25954763 : if (optab_handler (mov_optab, mode) == CODE_FOR_nothing)
1040 : : return false;
1041 : :
1042 : 24582677 : if ((op == SET_BY_PIECES || op == CLEAR_BY_PIECES)
1043 : 706288 : && VECTOR_MODE_P (mode)
1044 : 25087780 : && optab_handler (vec_duplicate_optab, mode) == CODE_FOR_nothing)
1045 : : return false;
1046 : :
1047 : 24534745 : if (op == COMPARE_BY_PIECES
1048 : 24534745 : && !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 : 5372823 : widest_fixed_size_mode_for_size (unsigned int size, by_pieces_operation op)
1059 : : {
1060 : 5372823 : fixed_size_mode result = NARROWEST_INT_MODE;
1061 : :
1062 : 5372823 : gcc_checking_assert (size > 1);
1063 : :
1064 : : /* Use QI vector only if size is wider than a WORD. */
1065 : 5372823 : if (can_use_qi_vectors (op))
1066 : : {
1067 : 732138 : machine_mode mode;
1068 : 732138 : fixed_size_mode candidate;
1069 : 12106728 : FOR_EACH_MODE_IN_CLASS (mode, MODE_VECTOR_INT)
1070 : 12106728 : if (is_a<fixed_size_mode> (mode, &candidate)
1071 : 13201263 : && GET_MODE_SIZE (candidate) > UNITS_PER_WORD
1072 : 13042512 : && GET_MODE_INNER (candidate) == QImode)
1073 : : {
1074 : 5708354 : if (GET_MODE_SIZE (candidate) >= size)
1075 : : break;
1076 : 2122039 : if (by_pieces_mode_supported_p (candidate, op))
1077 : 11374590 : result = candidate;
1078 : : }
1079 : :
1080 : 732138 : if (result != NARROWEST_INT_MODE)
1081 : 485509 : return result;
1082 : : }
1083 : :
1084 : 4887314 : opt_scalar_int_mode tmode;
1085 : 4887314 : scalar_int_mode mode;
1086 : 39098512 : FOR_EACH_MODE_IN_CLASS (tmode, MODE_INT)
1087 : : {
1088 : 34211198 : mode = tmode.require ();
1089 : 34211198 : if (GET_MODE_SIZE (mode) < size
1090 : 34211198 : && by_pieces_mode_supported_p (mode, op))
1091 : 23792495 : result = mode;
1092 : : }
1093 : :
1094 : 4887314 : 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 : 963362 : can_do_by_pieces (unsigned HOST_WIDE_INT len, unsigned int align,
1102 : : enum by_pieces_operation op)
1103 : : {
1104 : 963362 : return targetm.use_by_pieces_infrastructure_p (len, align, op,
1105 : 963362 : 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 : 896482 : can_move_by_pieces (unsigned HOST_WIDE_INT len, unsigned int align)
1114 : : {
1115 : 896482 : 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 : 1964482 : by_pieces_ninsns (unsigned HOST_WIDE_INT l, unsigned int align,
1123 : : unsigned int max_size, by_pieces_operation op)
1124 : : {
1125 : 1964482 : unsigned HOST_WIDE_INT n_insns = 0;
1126 : 1964482 : fixed_size_mode mode;
1127 : :
1128 : 1964482 : 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 : 1964482 : mode = widest_fixed_size_mode_for_size (max_size, op);
1133 : 1964482 : gcc_assert (optab_handler (mov_optab, mode) != CODE_FOR_nothing);
1134 : 3928964 : unsigned HOST_WIDE_INT up = ROUND_UP (l, GET_MODE_SIZE (mode));
1135 : 1964482 : if (up > l)
1136 : : l = up;
1137 : 1964482 : align = GET_MODE_ALIGNMENT (mode);
1138 : : }
1139 : :
1140 : 1964482 : align = alignment_for_piecewise_move (MOVE_MAX_PIECES, align);
1141 : :
1142 : 5900131 : while (max_size > 1 && l > 0)
1143 : : {
1144 : 1971167 : mode = widest_fixed_size_mode_for_size (max_size, op);
1145 : 1971167 : gcc_assert (optab_handler (mov_optab, mode) != CODE_FOR_nothing);
1146 : :
1147 : 1971167 : unsigned int modesize = GET_MODE_SIZE (mode);
1148 : :
1149 : 1971167 : if (align >= GET_MODE_ALIGNMENT (mode))
1150 : : {
1151 : 1971167 : unsigned HOST_WIDE_INT n_pieces = l / modesize;
1152 : 1971167 : l %= modesize;
1153 : 1971167 : switch (op)
1154 : : {
1155 : 1904287 : default:
1156 : 1904287 : n_insns += n_pieces;
1157 : 1904287 : break;
1158 : :
1159 : 66880 : case COMPARE_BY_PIECES:
1160 : 66880 : int batch = targetm.compare_by_pieces_branch_ratio (mode);
1161 : 66880 : int batch_ops = 4 * batch - 1;
1162 : 66880 : unsigned HOST_WIDE_INT full = n_pieces / batch;
1163 : 66880 : n_insns += full * batch_ops;
1164 : 66880 : if (n_pieces % batch != 0)
1165 : 0 : n_insns++;
1166 : : break;
1167 : :
1168 : : }
1169 : : }
1170 : : max_size = modesize;
1171 : : }
1172 : :
1173 : 1964482 : gcc_assert (!l);
1174 : 1964482 : 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 : 762355 : int get_addr_inc ()
1217 : : {
1218 : 762355 : 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 : 1524710 : pieces_addr::pieces_addr (rtx obj, bool is_load, by_pieces_constfn constfn,
1230 : 1524710 : void *cfndata)
1231 : 1524710 : : m_obj (obj), m_is_load (is_load), m_constfn (constfn), m_cfndata (cfndata)
1232 : : {
1233 : 1524710 : m_addr_inc = 0;
1234 : 1524710 : m_auto = false;
1235 : 1524710 : if (obj)
1236 : : {
1237 : 1393762 : rtx addr = XEXP (obj, 0);
1238 : 1393762 : rtx_code code = GET_CODE (addr);
1239 : 1393762 : m_addr = addr;
1240 : 1393762 : bool dec = code == PRE_DEC || code == POST_DEC;
1241 : 1393762 : bool inc = code == PRE_INC || code == POST_INC;
1242 : 1393762 : m_auto = inc || dec;
1243 : 1393762 : 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 : 1393762 : gcc_assert (code != PRE_INC && code != POST_DEC);
1250 : : }
1251 : : else
1252 : : {
1253 : 130948 : m_addr = NULL_RTX;
1254 : 130948 : 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 : 130903 : gcc_assert (constfn != NULL);
1264 : : }
1265 : 1524710 : m_explicit_inc = 0;
1266 : 1524710 : if (constfn)
1267 : 154700 : gcc_assert (is_load);
1268 : 1524710 : }
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 : 373546 : pieces_addr::decide_autoinc (machine_mode ARG_UNUSED (mode), bool reverse,
1277 : : HOST_WIDE_INT len)
1278 : : {
1279 : 373546 : if (m_auto || m_obj == NULL_RTX)
1280 : : return;
1281 : :
1282 : 342254 : bool use_predec = (m_is_load
1283 : : ? USE_LOAD_PRE_DECREMENT (mode)
1284 : : : USE_STORE_PRE_DECREMENT (mode));
1285 : 342254 : bool use_postinc = (m_is_load
1286 : : ? USE_LOAD_POST_INCREMENT (mode)
1287 : : : USE_STORE_POST_INCREMENT (mode));
1288 : 342254 : machine_mode addr_mode = get_address_mode (m_obj);
1289 : :
1290 : 342254 : 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 : 342254 : 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 : 342254 : else if (CONSTANT_P (m_addr))
1305 : 70714 : 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 : 4151972 : pieces_addr::adjust (fixed_size_mode mode, HOST_WIDE_INT offset,
1314 : : by_pieces_prev *prev)
1315 : : {
1316 : 4151972 : if (m_constfn)
1317 : : /* Pass the previous data to m_constfn. */
1318 : 383890 : return m_constfn (m_cfndata, prev, offset, mode);
1319 : 3768082 : if (m_obj == NULL_RTX)
1320 : : return NULL_RTX;
1321 : 3768035 : if (m_auto)
1322 : 0 : return adjust_automodify_address (m_obj, mode, m_addr, offset);
1323 : : else
1324 : 3768035 : 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 : 4151308 : pieces_addr::maybe_predec (HOST_WIDE_INT size)
1342 : : {
1343 : 4151308 : if (m_explicit_inc >= 0)
1344 : 4151308 : 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 : 4151331 : pieces_addr::maybe_postinc (HOST_WIDE_INT size)
1354 : : {
1355 : 4151331 : if (m_explicit_inc <= 0)
1356 : 4151331 : 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 : 1157970 : virtual void finish_mode (machine_mode)
1391 : : {
1392 : 1157970 : }
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 : 762355 : 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 : 762355 : by_pieces_operation op)
1416 : 762355 : : m_to (to, to_load, NULL, NULL),
1417 : 762355 : m_from (from, from_load, from_cfn, from_cfn_data),
1418 : 762355 : m_len (len), m_max_size (max_pieces + 1),
1419 : 762355 : m_push (push), m_op (op)
1420 : : {
1421 : 762355 : int toi = m_to.get_addr_inc ();
1422 : 762355 : int fromi = m_from.get_addr_inc ();
1423 : 762355 : if (toi >= 0 && fromi >= 0)
1424 : 762310 : m_reverse = false;
1425 : 45 : else if (toi <= 0 && fromi <= 0)
1426 : 45 : m_reverse = true;
1427 : : else
1428 : 0 : gcc_unreachable ();
1429 : :
1430 : 762355 : m_offset = m_reverse ? len : 0;
1431 : 2787579 : 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 : 762355 : if (by_pieces_ninsns (len, align, m_max_size, MOVE_BY_PIECES) > 2)
1438 : : {
1439 : : /* Find the mode of the largest comparison. */
1440 : 186773 : fixed_size_mode mode
1441 : 186773 : = widest_fixed_size_mode_for_size (m_max_size, m_op);
1442 : :
1443 : 186773 : m_from.decide_autoinc (mode, m_reverse, len);
1444 : 186773 : m_to.decide_autoinc (mode, m_reverse, len);
1445 : : }
1446 : :
1447 : 762365 : align = alignment_for_piecewise_move (MOVE_MAX_PIECES, align);
1448 : 762355 : m_align = align;
1449 : :
1450 : 762355 : m_overlap_op_by_pieces = targetm.overlap_op_by_pieces_p ();
1451 : 762355 : }
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 : 1247627 : op_by_pieces_d::get_usable_mode (fixed_size_mode mode, unsigned int len)
1458 : : {
1459 : 1544571 : unsigned int size;
1460 : 1841515 : do
1461 : : {
1462 : 1544571 : size = GET_MODE_SIZE (mode);
1463 : 1544571 : if (len >= size && prepare_mode (mode, m_align))
1464 : : break;
1465 : : /* widest_fixed_size_mode_for_size checks SIZE > 1. */
1466 : 296944 : mode = widest_fixed_size_mode_for_size (size, m_op);
1467 : : }
1468 : : while (1);
1469 : 1247627 : 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 : 490259 : op_by_pieces_d::smallest_fixed_size_mode_for_size (unsigned int size)
1477 : : {
1478 : : /* Use QI vector only for > size of WORD. */
1479 : 502405 : if (can_use_qi_vectors (m_op) && size > UNITS_PER_WORD)
1480 : : {
1481 : 7694 : machine_mode mode;
1482 : 7694 : fixed_size_mode candidate;
1483 : 103937 : FOR_EACH_MODE_IN_CLASS (mode, MODE_VECTOR_INT)
1484 : 103937 : if (is_a<fixed_size_mode> (mode, &candidate)
1485 : 207874 : && GET_MODE_INNER (candidate) == QImode)
1486 : : {
1487 : : /* Don't return a mode wider than M_LEN. */
1488 : 96714 : if (GET_MODE_SIZE (candidate) > m_len)
1489 : : break;
1490 : :
1491 : 46623 : if (GET_MODE_SIZE (candidate) >= size
1492 : 46623 : && by_pieces_mode_supported_p (candidate, m_op))
1493 : 5960 : return candidate;
1494 : : }
1495 : : }
1496 : :
1497 : 484299 : 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 : 762355 : op_by_pieces_d::run ()
1507 : : {
1508 : 762355 : if (m_len == 0)
1509 : : return;
1510 : :
1511 : 757368 : unsigned HOST_WIDE_INT length = m_len;
1512 : :
1513 : : /* widest_fixed_size_mode_for_size checks M_MAX_SIZE > 1. */
1514 : 757368 : fixed_size_mode mode
1515 : 757368 : = widest_fixed_size_mode_for_size (m_max_size, m_op);
1516 : 757368 : mode = get_usable_mode (mode, length);
1517 : :
1518 : 757368 : by_pieces_prev to_prev = { nullptr, mode };
1519 : 757368 : by_pieces_prev from_prev = { nullptr, mode };
1520 : :
1521 : 1247627 : do
1522 : : {
1523 : 1247627 : unsigned int size = GET_MODE_SIZE (mode);
1524 : 1247627 : rtx to1 = NULL_RTX, from1;
1525 : :
1526 : 3323281 : while (length >= size)
1527 : : {
1528 : 2075654 : if (m_reverse)
1529 : 47 : m_offset -= size;
1530 : :
1531 : 2075654 : to1 = m_to.adjust (mode, m_offset, &to_prev);
1532 : 2075654 : to_prev.data = to1;
1533 : 2075654 : to_prev.mode = mode;
1534 : 2075654 : from1 = m_from.adjust (mode, m_offset, &from_prev);
1535 : 2075654 : from_prev.data = from1;
1536 : 2075654 : from_prev.mode = mode;
1537 : :
1538 : 2075654 : m_to.maybe_predec (-(HOST_WIDE_INT)size);
1539 : 2075654 : m_from.maybe_predec (-(HOST_WIDE_INT)size);
1540 : :
1541 : 2075654 : generate (to1, from1, mode);
1542 : :
1543 : 2075654 : m_to.maybe_postinc (size);
1544 : 2075654 : m_from.maybe_postinc (size);
1545 : :
1546 : 2075654 : if (!m_reverse)
1547 : 2075607 : m_offset += size;
1548 : :
1549 : 2075654 : length -= size;
1550 : : }
1551 : :
1552 : 1247627 : finish_mode (mode);
1553 : :
1554 : 1247627 : if (length == 0)
1555 : : return;
1556 : :
1557 : 490259 : 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 : 490259 : mode = smallest_fixed_size_mode_for_size (length);
1563 : 980518 : mode = get_usable_mode (mode, GET_MODE_SIZE (mode));
1564 : 490259 : int gap = GET_MODE_SIZE (mode) - length;
1565 : 490259 : 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 : 47261 : if (m_reverse)
1571 : 0 : m_offset += gap;
1572 : : else
1573 : 47261 : m_offset -= gap;
1574 : 47261 : 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 : 571229 : move_by_pieces_d (rtx to, rtx from, unsigned HOST_WIDE_INT len,
1604 : : unsigned int align)
1605 : 571229 : : op_by_pieces_d (MOVE_MAX_PIECES, to, false, from, true, NULL,
1606 : 1142458 : NULL, len, align, PUSHG_P (to), MOVE_BY_PIECES)
1607 : : {
1608 : 571229 : }
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 : 951211 : move_by_pieces_d::prepare_mode (machine_mode mode, unsigned int align)
1618 : : {
1619 : 951211 : insn_code icode = optab_handler (mov_optab, mode);
1620 : 951211 : m_gen_fun = GEN_FCN (icode);
1621 : 951211 : 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 : 1646734 : move_by_pieces_d::generate (rtx op0, rtx op1,
1632 : : machine_mode mode ATTRIBUTE_UNUSED)
1633 : : {
1634 : : #ifdef PUSH_ROUNDING
1635 : 1646734 : if (op0 == NULL_RTX)
1636 : : {
1637 : 47 : emit_single_push_insn (mode, op1, NULL);
1638 : 47 : return;
1639 : : }
1640 : : #endif
1641 : 1646687 : 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 : 571229 : 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 : 571229 : move_by_pieces_d data (to, from, len, align);
1680 : :
1681 : 571229 : data.run ();
1682 : :
1683 : 571229 : 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 : 130903 : 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 : 130903 : : op_by_pieces_d (STORE_MAX_PIECES, to, false, NULL_RTX, true, cfn,
1704 : 261806 : cfn_data, len, align, false, op)
1705 : : {
1706 : 130903 : }
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 : 206759 : store_by_pieces_d::prepare_mode (machine_mode mode, unsigned int align)
1716 : : {
1717 : 206759 : insn_code icode = optab_handler (mov_optab, mode);
1718 : 206759 : m_gen_fun = GEN_FCN (icode);
1719 : 206759 : 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 : 336201 : store_by_pieces_d::generate (rtx op0, rtx op1, machine_mode)
1730 : : {
1731 : 336201 : emit_insn (m_gen_fun (op0, op1));
1732 : 336201 : }
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 : 664 : store_by_pieces_d::finish_retmode (memop_ret retmode)
1740 : : {
1741 : 664 : gcc_assert (!m_reverse);
1742 : 664 : if (retmode == RETURN_END_MINUS_ONE)
1743 : : {
1744 : 23 : m_to.maybe_postinc (-1);
1745 : 23 : --m_offset;
1746 : : }
1747 : 664 : 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 : 90799 : can_store_by_pieces (unsigned HOST_WIDE_INT len,
1759 : : by_pieces_constfn constfun,
1760 : : void *constfundata, unsigned int align, bool memsetp)
1761 : : {
1762 : 90799 : unsigned HOST_WIDE_INT l;
1763 : 90799 : unsigned int max_size;
1764 : 90799 : HOST_WIDE_INT offset = 0;
1765 : 90799 : enum insn_code icode;
1766 : 90799 : int reverse;
1767 : : /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
1768 : 90799 : rtx cst ATTRIBUTE_UNUSED;
1769 : :
1770 : 90799 : if (len == 0)
1771 : : return true;
1772 : :
1773 : 137068 : if (!targetm.use_by_pieces_infrastructure_p (len, align,
1774 : : memsetp
1775 : : ? SET_BY_PIECES
1776 : : : STORE_BY_PIECES,
1777 : 90755 : optimize_insn_for_speed_p ()))
1778 : : return false;
1779 : :
1780 : 52749 : 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 : 52749 : for (reverse = 0;
1786 : 105498 : reverse <= (HAVE_PRE_DECREMENT || HAVE_POST_DECREMENT);
1787 : : reverse++)
1788 : : {
1789 : 52749 : l = len;
1790 : 52749 : max_size = STORE_MAX_PIECES + 1;
1791 : 248838 : while (max_size > 1 && l > 0)
1792 : : {
1793 : 196089 : auto op = memsetp ? SET_BY_PIECES : STORE_BY_PIECES;
1794 : 196089 : auto mode = widest_fixed_size_mode_for_size (max_size, op);
1795 : :
1796 : 196089 : icode = optab_handler (mov_optab, mode);
1797 : 196089 : if (icode != CODE_FOR_nothing
1798 : 196089 : && align >= GET_MODE_ALIGNMENT (mode))
1799 : : {
1800 : 196089 : unsigned int size = GET_MODE_SIZE (mode);
1801 : :
1802 : 342306 : while (l >= size)
1803 : : {
1804 : 146217 : if (reverse)
1805 : : offset -= size;
1806 : :
1807 : 146217 : 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 : 276298 : if (!((memsetp && VECTOR_MODE_P (mode))
1812 : 130081 : || targetm.legitimate_constant_p (mode, cst)))
1813 : 38006 : return false;
1814 : :
1815 : 146217 : if (!reverse)
1816 : 146217 : offset += size;
1817 : :
1818 : 146217 : l -= size;
1819 : : }
1820 : : }
1821 : :
1822 : 392178 : max_size = GET_MODE_SIZE (mode);
1823 : : }
1824 : :
1825 : : /* The code above should have handled everything. */
1826 : 52749 : 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 : 57289 : 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 : 57289 : if (len == 0)
1846 : : {
1847 : 5029 : gcc_assert (retmode != RETURN_END_MINUS_ONE);
1848 : : return to;
1849 : : }
1850 : :
1851 : 94712 : 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 : 52260 : store_by_pieces_d data (to, constfun, constfundata, len, align,
1857 : 52260 : memsetp ? SET_BY_PIECES : STORE_BY_PIECES);
1858 : 52260 : data.run ();
1859 : :
1860 : 52260 : if (retmode != RETURN_BEGIN)
1861 : 664 : return data.finish_retmode (retmode);
1862 : : else
1863 : : return to;
1864 : : }
1865 : :
1866 : : void
1867 : 78643 : clear_by_pieces (rtx to, unsigned HOST_WIDE_INT len, unsigned int align)
1868 : : {
1869 : 78643 : if (len == 0)
1870 : 0 : return;
1871 : :
1872 : : /* Use builtin_memset_read_str to support vector mode broadcast. */
1873 : 78643 : char c = 0;
1874 : 78643 : store_by_pieces_d data (to, builtin_memset_read_str, &c, len, align,
1875 : 78643 : CLEAR_BY_PIECES);
1876 : 78643 : 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 : 60223 : 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 : 60223 : : op_by_pieces_d (COMPARE_MAX_PIECES, op0, true, op1, true, op1_cfn,
1899 : 120446 : op1_cfn_data, len, align, false, COMPARE_BY_PIECES)
1900 : : {
1901 : 60223 : m_fail_label = fail_label;
1902 : 60223 : }
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 : 92719 : compare_by_pieces_d::generate (rtx op0, rtx op1, machine_mode mode)
1912 : : {
1913 : 92719 : 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 : 92719 : 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 : 89657 : compare_by_pieces_d::prepare_mode (machine_mode mode, unsigned int align)
1940 : : {
1941 : 89657 : insn_code icode = optab_handler (mov_optab, mode);
1942 : 89657 : if (icode == CODE_FOR_nothing
1943 : 89657 : || align < GET_MODE_ALIGNMENT (mode)
1944 : 179314 : || !can_compare_p (EQ, mode, ccp_jump))
1945 : 0 : return false;
1946 : 89657 : m_batch = targetm.compare_by_pieces_branch_ratio (mode);
1947 : 89657 : if (m_batch < 0)
1948 : : return false;
1949 : 89657 : m_accumulator = NULL_RTX;
1950 : 89657 : m_count = 0;
1951 : 89657 : 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 : 89657 : compare_by_pieces_d::finish_mode (machine_mode mode)
1960 : : {
1961 : 89657 : 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 : 89657 : }
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 : 60223 : 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 : 60223 : rtx_code_label *fail_label = gen_label_rtx ();
1985 : 60223 : rtx_code_label *end_label = gen_label_rtx ();
1986 : :
1987 : 60223 : if (target == NULL_RTX
1988 : 60223 : || !REG_P (target) || REGNO (target) < FIRST_PSEUDO_REGISTER)
1989 : 2 : target = gen_reg_rtx (TYPE_MODE (integer_type_node));
1990 : :
1991 : 60223 : compare_by_pieces_d data (arg0, arg1, a1_cfn, a1_cfn_data, len, align,
1992 : 60223 : fail_label);
1993 : :
1994 : 60223 : data.run ();
1995 : :
1996 : 60223 : emit_move_insn (target, const0_rtx);
1997 : 60223 : emit_jump (end_label);
1998 : 60223 : emit_barrier ();
1999 : 60223 : emit_label (fail_label);
2000 : 60223 : emit_move_insn (target, const1_rtx);
2001 : 60223 : emit_label (end_label);
2002 : :
2003 : 60223 : 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 : 658793 : 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 : 658793 : int may_use_call;
2033 : 658793 : rtx retval = 0;
2034 : 658793 : unsigned int align;
2035 : :
2036 : 658793 : if (is_move_done)
2037 : 83866 : *is_move_done = true;
2038 : :
2039 : 658793 : gcc_assert (size);
2040 : 658793 : if (CONST_INT_P (size) && INTVAL (size) == 0)
2041 : : return 0;
2042 : :
2043 : 658516 : switch (method)
2044 : : {
2045 : : case BLOCK_OP_NORMAL:
2046 : : case BLOCK_OP_TAILCALL:
2047 : : may_use_call = 1;
2048 : : break;
2049 : :
2050 : 268756 : case BLOCK_OP_CALL_PARM:
2051 : 268756 : 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 : 268756 : NO_DEFER_POP;
2056 : 268756 : break;
2057 : :
2058 : 354 : case BLOCK_OP_NO_LIBCALL:
2059 : 354 : may_use_call = 0;
2060 : 354 : 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 : 658516 : gcc_assert (MEM_P (x) && MEM_P (y));
2071 : 658601 : align = MIN (MEM_ALIGN (x), MEM_ALIGN (y));
2072 : 658516 : 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 : 658516 : x = adjust_address (x, BLKmode, 0);
2077 : 658516 : y = adjust_address (y, BLKmode, 0);
2078 : :
2079 : : /* If source and destination are the same, no need to copy anything. */
2080 : 658516 : if (rtx_equal_p (x, y)
2081 : 16 : && !MEM_VOLATILE_P (x)
2082 : 658532 : && !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 : 658500 : poly_int64 const_size;
2088 : 658500 : if (poly_int_rtx_p (size, &const_size))
2089 : : {
2090 : 590957 : x = shallow_copy_rtx (x);
2091 : 590957 : y = shallow_copy_rtx (y);
2092 : 590957 : set_mem_size (x, const_size);
2093 : 590957 : set_mem_size (y, const_size);
2094 : : }
2095 : :
2096 : 658500 : bool pieces_ok = CONST_INT_P (size)
2097 : 658500 : && can_move_by_pieces (INTVAL (size), align);
2098 : 658500 : bool pattern_ok = false;
2099 : :
2100 : 658500 : if (!pieces_ok || might_overlap)
2101 : : {
2102 : 92812 : pattern_ok
2103 : 92812 : = 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 : 92812 : 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 : 9877 : *is_move_done = false;
2112 : 9877 : return retval;
2113 : : }
2114 : : }
2115 : :
2116 : 82935 : bool dynamic_direction = false;
2117 : 82935 : if (!pattern_ok && !pieces_ok && may_use_call
2118 : 113540 : && (flag_inline_stringops & (might_overlap ? ILSOP_MEMMOVE : ILSOP_MEMCPY)))
2119 : : {
2120 : 648623 : may_use_call = 0;
2121 : 648623 : dynamic_direction = might_overlap;
2122 : : }
2123 : :
2124 : 648623 : if (pattern_ok)
2125 : : ;
2126 : 622458 : else if (pieces_ok)
2127 : 565688 : move_by_pieces (x, y, INTVAL (size), align, RETURN_BEGIN);
2128 : 56770 : else if (may_use_call && !might_overlap
2129 : 56722 : && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x))
2130 : 113492 : && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y)))
2131 : : {
2132 : 56722 : if (bail_out_libcall)
2133 : : {
2134 : 251 : if (is_move_done)
2135 : 251 : *is_move_done = false;
2136 : 251 : return retval;
2137 : : }
2138 : :
2139 : 56471 : if (may_use_call < 0)
2140 : 0 : return pc_rtx;
2141 : :
2142 : 56471 : 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 : 648372 : if (method == BLOCK_OP_CALL_PARM)
2153 : 268742 : OK_DEFER_POP;
2154 : :
2155 : : return retval;
2156 : : }
2157 : :
2158 : : rtx
2159 : 574927 : emit_block_move (rtx x, rtx y, rtx size, enum block_op_methods method,
2160 : : unsigned int ctz_size)
2161 : : {
2162 : 574927 : unsigned HOST_WIDE_INT max, min = 0;
2163 : 574927 : if (GET_CODE (size) == CONST_INT)
2164 : 574707 : min = max = UINTVAL (size);
2165 : : else
2166 : 220 : max = GET_MODE_MASK (GET_MODE (size));
2167 : 574927 : return emit_block_move_hints (x, y, size, method, 0, -1,
2168 : : min, max, max,
2169 : 574927 : 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 : 268756 : block_move_libcall_safe_for_call_parm (void)
2178 : : {
2179 : 268756 : tree fn;
2180 : :
2181 : : /* If arguments are pushed on the stack, then they're safe. */
2182 : 268756 : 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 : 92812 : 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 : 92812 : if (expected_align < align)
2246 : : expected_align = align;
2247 : 92812 : if (expected_size != -1)
2248 : : {
2249 : 13 : if ((unsigned HOST_WIDE_INT)expected_size > probable_max_size)
2250 : 0 : expected_size = probable_max_size;
2251 : 13 : 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 : 92812 : 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 : 92812 : opt_scalar_int_mode mode_iter;
2263 : 615952 : FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_INT)
2264 : : {
2265 : 549305 : scalar_int_mode mode = mode_iter.require ();
2266 : 549305 : enum insn_code code;
2267 : 549305 : if (might_overlap)
2268 : 88571 : code = direct_optab_handler (movmem_optab, mode);
2269 : : else
2270 : 460734 : code = direct_optab_handler (cpymem_optab, mode);
2271 : :
2272 : 549305 : 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 : 549305 : && ((CONST_INT_P (size)
2279 : 39680 : && ((unsigned HOST_WIDE_INT) INTVAL (size)
2280 : 39680 : <= (GET_MODE_MASK (mode) >> 1)))
2281 : 119199 : || max_size <= (GET_MODE_MASK (mode) >> 1)
2282 : 154956 : || GET_MODE_BITSIZE (mode) >= GET_MODE_BITSIZE (Pmode)))
2283 : : {
2284 : 108924 : class expand_operand ops[9];
2285 : 108924 : 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 : 108924 : nops = insn_data[(int) code].n_generator_args;
2292 : 108924 : gcc_assert (nops == 4 || nops == 6 || nops == 8 || nops == 9);
2293 : :
2294 : 108924 : create_fixed_operand (&ops[0], x);
2295 : 108924 : create_fixed_operand (&ops[1], y);
2296 : : /* The check above guarantees that this size conversion is valid. */
2297 : 108924 : create_convert_operand_to (&ops[2], size, mode, true);
2298 : 108924 : create_integer_operand (&ops[3], align / BITS_PER_UNIT);
2299 : 108924 : if (nops >= 6)
2300 : : {
2301 : 108924 : create_integer_operand (&ops[4], expected_align / BITS_PER_UNIT);
2302 : 108924 : create_integer_operand (&ops[5], expected_size);
2303 : : }
2304 : 108924 : if (nops >= 8)
2305 : : {
2306 : 108924 : create_integer_operand (&ops[6], min_size);
2307 : : /* If we cannot represent the maximal size,
2308 : : make parameter NULL. */
2309 : 108924 : if ((HOST_WIDE_INT) max_size != -1)
2310 : 92050 : create_integer_operand (&ops[7], max_size);
2311 : : else
2312 : 16874 : create_fixed_operand (&ops[7], NULL);
2313 : : }
2314 : 108924 : if (nops == 9)
2315 : : {
2316 : : /* If we cannot represent the maximal size,
2317 : : make parameter NULL. */
2318 : 108924 : if ((HOST_WIDE_INT) probable_max_size != -1)
2319 : 94486 : create_integer_operand (&ops[8], probable_max_size);
2320 : : else
2321 : 14438 : create_fixed_operand (&ops[8], NULL);
2322 : : }
2323 : 108924 : if (maybe_expand_insn (code, nops, ops))
2324 : 26165 : return true;
2325 : : }
2326 : : }
2327 : :
2328 : : return false;
2329 : 92812 : }
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 : 56474 : emit_block_op_via_libcall (enum built_in_function fncode, rtx dst, rtx src,
2539 : : rtx size, bool tailcall)
2540 : : {
2541 : 56474 : rtx dst_addr, src_addr;
2542 : 56474 : tree call_expr, dst_tree, src_tree, size_tree;
2543 : 56474 : machine_mode size_mode;
2544 : :
2545 : : /* Since dst and src are passed to a libcall, mark the corresponding
2546 : : tree EXPR as addressable. */
2547 : 56474 : tree dst_expr = MEM_EXPR (dst);
2548 : 56474 : tree src_expr = MEM_EXPR (src);
2549 : 56474 : if (dst_expr)
2550 : 49762 : mark_addressable (dst_expr);
2551 : 56474 : if (src_expr)
2552 : 55073 : mark_addressable (src_expr);
2553 : :
2554 : 56474 : dst_addr = copy_addr_to_reg (XEXP (dst, 0));
2555 : 56474 : dst_addr = convert_memory_address (ptr_mode, dst_addr);
2556 : 56474 : dst_tree = make_tree (ptr_type_node, dst_addr);
2557 : :
2558 : 56474 : src_addr = copy_addr_to_reg (XEXP (src, 0));
2559 : 56474 : src_addr = convert_memory_address (ptr_mode, src_addr);
2560 : 56474 : src_tree = make_tree (ptr_type_node, src_addr);
2561 : :
2562 : 56474 : size_mode = TYPE_MODE (sizetype);
2563 : 56474 : size = convert_to_mode (size_mode, size, 1);
2564 : 56474 : size = copy_to_mode_reg (size_mode, size);
2565 : 56474 : 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 : 56474 : tree fn = builtin_decl_implicit (fncode);
2570 : 56474 : call_expr = build_call_expr (fn, 3, dst_tree, src_tree, size_tree);
2571 : 56474 : CALL_EXPR_TAILCALL (call_expr) = tailcall;
2572 : :
2573 : 56474 : 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 : 170283 : 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 : 170283 : machine_mode insn_mode = insn_data[icode].operand[0].mode;
2586 : :
2587 : 170283 : if (target && (!REG_P (target) || HARD_REGISTER_P (target)))
2588 : : target = NULL_RTX;
2589 : :
2590 : 170283 : class expand_operand ops[5];
2591 : 170283 : create_output_operand (&ops[0], target, insn_mode);
2592 : 170283 : create_fixed_operand (&ops[1], arg1_rtx);
2593 : 170283 : create_fixed_operand (&ops[2], arg2_rtx);
2594 : 170283 : create_convert_operand_from (&ops[3], arg3_rtx, TYPE_MODE (arg3_type),
2595 : 170283 : TYPE_UNSIGNED (arg3_type));
2596 : 170283 : create_integer_operand (&ops[4], align);
2597 : 170283 : if (maybe_expand_insn (icode, 5, ops))
2598 : 5771 : 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 : 42334 : 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 : 42334 : insn_code icode = direct_optab_handler (cmpmem_optab, SImode);
2615 : :
2616 : 42334 : if (icode == CODE_FOR_nothing)
2617 : : return NULL_RTX;
2618 : :
2619 : 42334 : 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 : 102556 : 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 : 102556 : rtx result = 0;
2648 : :
2649 : 102556 : if (CONST_INT_P (len) && INTVAL (len) == 0)
2650 : 0 : return const0_rtx;
2651 : :
2652 : 102556 : gcc_assert (MEM_P (x) && MEM_P (y));
2653 : 102556 : unsigned int align = MIN (MEM_ALIGN (x), MEM_ALIGN (y));
2654 : 102556 : gcc_assert (align >= BITS_PER_UNIT);
2655 : :
2656 : 102556 : x = adjust_address (x, BLKmode, 0);
2657 : 102556 : y = adjust_address (y, BLKmode, 0);
2658 : :
2659 : 102556 : if (equality_only
2660 : 88255 : && CONST_INT_P (len)
2661 : 169390 : && can_do_by_pieces (INTVAL (len), align, COMPARE_BY_PIECES))
2662 : 60222 : result = compare_by_pieces (x, y, INTVAL (len), target, align,
2663 : : y_cfn, y_cfndata);
2664 : : else
2665 : 42334 : result = emit_block_cmp_via_cmpmem (x, y, len, len_type, target, align);
2666 : :
2667 : 102556 : 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 : 403 : 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 : 430 : move_block_to_reg (int regno, rtx x, int nregs, machine_mode mode)
2869 : : {
2870 : 430 : if (nregs == 0)
2871 : : return;
2872 : :
2873 : 416 : 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 : 416 : 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 : 832 : for (int i = 0; i < nregs; i++)
2892 : 416 : emit_move_insn (gen_rtx_REG (word_mode, regno + i),
2893 : 416 : 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 : 1214 : move_block_from_reg (int regno, rtx x, int nregs)
2901 : : {
2902 : 1214 : if (nregs == 0)
2903 : : return;
2904 : :
2905 : : /* See if the machine can do this with a store multiple insn. */
2906 : 1214 : 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 : 2428 : for (int i = 0; i < nregs; i++)
2921 : : {
2922 : 1214 : rtx tem = operand_subword (x, i, 1, BLKmode);
2923 : :
2924 : 1214 : gcc_assert (tem);
2925 : :
2926 : 1214 : 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 : 3023 : gen_group_rtx (rtx orig)
2938 : : {
2939 : 3023 : int i, length;
2940 : 3023 : rtx *tmps;
2941 : :
2942 : 3023 : gcc_assert (GET_CODE (orig) == PARALLEL);
2943 : :
2944 : 3023 : length = XVECLEN (orig, 0);
2945 : 3023 : tmps = XALLOCAVEC (rtx, length);
2946 : :
2947 : : /* Skip a NULL entry in first slot. */
2948 : 3023 : i = XEXP (XVECEXP (orig, 0, 0), 0) ? 0 : 1;
2949 : :
2950 : 3023 : if (i)
2951 : 0 : tmps[0] = 0;
2952 : :
2953 : 7355 : for (; i < length; i++)
2954 : : {
2955 : 4332 : machine_mode mode = GET_MODE (XEXP (XVECEXP (orig, 0, i), 0));
2956 : 4332 : rtx offset = XEXP (XVECEXP (orig, 0, i), 1);
2957 : :
2958 : 4332 : tmps[i] = gen_rtx_EXPR_LIST (VOIDmode, gen_reg_rtx (mode), offset);
2959 : : }
2960 : :
2961 : 3023 : 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 : 305972 : emit_group_load_1 (rtx *tmps, rtx dst, rtx orig_src, tree type,
2970 : : poly_int64 ssize)
2971 : : {
2972 : 305975 : rtx src;
2973 : 305975 : int start, i;
2974 : 305975 : machine_mode m = GET_MODE (orig_src);
2975 : :
2976 : 305975 : gcc_assert (GET_CODE (dst) == PARALLEL);
2977 : :
2978 : 305975 : if (m != VOIDmode
2979 : 287302 : && !SCALAR_INT_MODE_P (m)
2980 : 18762 : && !MEM_P (orig_src)
2981 : 5463 : && 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 : 305972 : if (XEXP (XVECEXP (dst, 0, 0), 0))
3001 : : start = 0;
3002 : : else
3003 : 0 : start = 1;
3004 : :
3005 : : /* Process the pieces. */
3006 : 906687 : for (i = start; i < XVECLEN (dst, 0); i++)
3007 : : {
3008 : 600715 : machine_mode mode = GET_MODE (XEXP (XVECEXP (dst, 0, i), 0));
3009 : 600715 : poly_int64 bytepos = rtx_to_poly_int64 (XEXP (XVECEXP (dst, 0, i), 1));
3010 : 1201430 : poly_int64 bytelen = GET_MODE_SIZE (mode);
3011 : 600715 : 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 : 600715 : gcc_checking_assert (ordered_p (bytepos + bytelen, ssize));
3018 : 600715 : 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 : 1789 : bytelen = ssize - bytepos;
3032 : 1789 : 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 : 600715 : src = orig_src;
3039 : 600715 : if (!MEM_P (orig_src)
3040 : 498464 : && (!REG_P (orig_src) || HARD_REGISTER_P (orig_src))
3041 : 646373 : && !CONSTANT_P (orig_src))
3042 : : {
3043 : 8312 : gcc_assert (GET_MODE (orig_src) != VOIDmode);
3044 : 8312 : src = force_reg (GET_MODE (orig_src), orig_src);
3045 : : }
3046 : :
3047 : : /* Optimize the access just a bit. */
3048 : 600715 : if (MEM_P (src)
3049 : 102251 : && (! targetm.slow_unaligned_access (mode, MEM_ALIGN (src))
3050 : 0 : || MEM_ALIGN (src) >= GET_MODE_ALIGNMENT (mode))
3051 : 204502 : && multiple_p (bytepos * BITS_PER_UNIT, GET_MODE_ALIGNMENT (mode))
3052 : 702966 : && known_eq (bytelen, GET_MODE_SIZE (mode)))
3053 : : {
3054 : 100481 : tmps[i] = gen_reg_rtx (mode);
3055 : 100481 : emit_move_insn (tmps[i], adjust_address (src, mode, bytepos));
3056 : : }
3057 : 500234 : else if (COMPLEX_MODE_P (mode)
3058 : 0 : && GET_MODE (src) == mode
3059 : 500234 : && known_eq (bytelen, GET_MODE_SIZE (mode)))
3060 : : /* Let emit_move_complex do the bulk of the work. */
3061 : 0 : tmps[i] = src;
3062 : 500234 : else if (GET_CODE (src) == CONCAT)
3063 : : {
3064 : 16624 : poly_int64 slen = GET_MODE_SIZE (GET_MODE (src));
3065 : 16624 : poly_int64 slen0 = GET_MODE_SIZE (GET_MODE (XEXP (src, 0)));
3066 : 8312 : unsigned int elt;
3067 : 8312 : poly_int64 subpos;
3068 : :
3069 : 8312 : if (can_div_trunc_p (bytepos, slen0, &elt, &subpos)
3070 : 8312 : && 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 : 5704 : tmps[i] = XEXP (src, elt);
3077 : 5704 : if (maybe_ne (subpos, 0)
3078 : 5704 : || maybe_ne (subpos + bytelen, slen0)
3079 : 11408 : || (!CONSTANT_P (tmps[i])
3080 : 5704 : && (!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 : 2608 : rtx mem;
3089 : :
3090 : 2608 : gcc_assert (known_eq (bytepos, 0));
3091 : 2608 : mem = assign_stack_temp (GET_MODE (src), slen);
3092 : 2608 : emit_move_insn (mem, src);
3093 : 2608 : tmps[i] = extract_bit_field (mem, bytelen * BITS_PER_UNIT,
3094 : : 0, 1, NULL_RTX, mode, mode, false,
3095 : : NULL);
3096 : : }
3097 : : }
3098 : 491922 : else if (CONSTANT_P (src) && GET_MODE (dst) != BLKmode
3099 : 37346 : && XVECLEN (dst, 0) > 1)
3100 : 37346 : tmps[i] = force_subreg (mode, src, GET_MODE (dst), bytepos);
3101 : 454576 : 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 : 454576 : else if (REG_P (src) && GET_MODE (src) == mode)
3119 : 0 : tmps[i] = src;
3120 : : else
3121 : 454576 : tmps[i] = extract_bit_field (src, bytelen * BITS_PER_UNIT,
3122 : 909152 : bytepos * BITS_PER_UNIT, 1, NULL_RTX,
3123 : : mode, mode, false, NULL);
3124 : :
3125 : 600715 : 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 : 11324 : emit_group_load (rtx dst, rtx src, tree type, poly_int64 ssize)
3138 : : {
3139 : 11324 : rtx *tmps;
3140 : 11324 : int i;
3141 : :
3142 : 11324 : tmps = XALLOCAVEC (rtx, XVECLEN (dst, 0));
3143 : 11324 : emit_group_load_1 (tmps, dst, src, type, ssize);
3144 : :
3145 : : /* Copy the extracted pieces into the proper (probable) hard regs. */
3146 : 31724 : for (i = 0; i < XVECLEN (dst, 0); i++)
3147 : : {
3148 : 20400 : rtx d = XEXP (XVECEXP (dst, 0, i), 0);
3149 : 20400 : if (d == NULL)
3150 : 0 : continue;
3151 : 20400 : emit_move_insn (d, tmps[i]);
3152 : : }
3153 : 11324 : }
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 : 294648 : emit_group_load_into_temps (rtx parallel, rtx src, tree type, poly_int64 ssize)
3161 : : {
3162 : 294648 : rtvec vec;
3163 : 294648 : int i;
3164 : :
3165 : 294648 : vec = rtvec_alloc (XVECLEN (parallel, 0));
3166 : 294648 : 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 : 874963 : for (i = 0; i < XVECLEN (parallel, 0); i++)
3171 : : {
3172 : 580315 : rtx e = XVECEXP (parallel, 0, i);
3173 : 580315 : rtx d = XEXP (e, 0);
3174 : :
3175 : 580315 : if (d)
3176 : : {
3177 : 580315 : d = force_reg (GET_MODE (d), RTVEC_ELT (vec, i));
3178 : 580315 : e = alloc_EXPR_LIST (REG_NOTE_KIND (e), d, XEXP (e, 1));
3179 : : }
3180 : 580315 : RTVEC_ELT (vec, i) = e;
3181 : : }
3182 : :
3183 : 294648 : 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 : 297671 : emit_group_move (rtx dst, rtx src)
3191 : : {
3192 : 297671 : int i;
3193 : :
3194 : 297671 : 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 : 882318 : for (i = XEXP (XVECEXP (src, 0, 0), 0) ? 0 : 1; i < XVECLEN (src, 0); i++)
3200 : 584647 : emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0),
3201 : 584647 : XEXP (XVECEXP (src, 0, i), 0));
3202 : 297671 : }
3203 : :
3204 : : /* Move a group of registers represented by a PARALLEL into pseudos. */
3205 : :
3206 : : rtx
3207 : 5642 : emit_group_move_into_temps (rtx src)
3208 : : {
3209 : 5642 : rtvec vec = rtvec_alloc (XVECLEN (src, 0));
3210 : 5642 : int i;
3211 : :
3212 : 13286 : for (i = 0; i < XVECLEN (src, 0); i++)
3213 : : {
3214 : 7644 : rtx e = XVECEXP (src, 0, i);
3215 : 7644 : rtx d = XEXP (e, 0);
3216 : :
3217 : 7644 : if (d)
3218 : 7644 : e = alloc_EXPR_LIST (REG_NOTE_KIND (e), copy_to_reg (d), XEXP (e, 1));
3219 : 7644 : RTVEC_ELT (vec, i) = e;
3220 : : }
3221 : :
3222 : 5642 : 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 : 65851 : emit_group_store (rtx orig_dst, rtx src, tree type ATTRIBUTE_UNUSED,
3232 : : poly_int64 ssize)
3233 : : {
3234 : 65851 : rtx *tmps, dst;
3235 : 65851 : int start, finish, i;
3236 : 65851 : machine_mode m = GET_MODE (orig_dst);
3237 : :
3238 : 65851 : gcc_assert (GET_CODE (src) == PARALLEL);
3239 : :
3240 : 65851 : if (!SCALAR_INT_MODE_P (m)
3241 : 14023 : && !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 : 65851 : if (XEXP (XVECEXP (src, 0, 0), 0))
3262 : : start = 0;
3263 : : else
3264 : 0 : start = 1;
3265 : 65851 : finish = XVECLEN (src, 0);
3266 : :
3267 : 65851 : tmps = XALLOCAVEC (rtx, finish);
3268 : :
3269 : : /* Copy the (probable) hard regs into pseudos. */
3270 : 189568 : for (i = start; i < finish; i++)
3271 : : {
3272 : 123717 : rtx reg = XEXP (XVECEXP (src, 0, i), 0);
3273 : 123717 : if (!REG_P (reg) || REGNO (reg) < FIRST_PSEUDO_REGISTER)
3274 : : {
3275 : 116073 : tmps[i] = gen_reg_rtx (GET_MODE (reg));
3276 : 116073 : emit_move_insn (tmps[i], reg);
3277 : : }
3278 : : else
3279 : 7644 : 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 : 65851 : dst = orig_dst;
3285 : 65851 : 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 : 65851 : else if (!MEM_P (dst) && GET_CODE (dst) != CONCAT)
3304 : : {
3305 : 51211 : machine_mode outer = GET_MODE (dst);
3306 : 51211 : machine_mode inner;
3307 : 51211 : poly_int64 bytepos;
3308 : 51211 : bool done = false;
3309 : 51211 : rtx temp;
3310 : :
3311 : 51211 : 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 : 51211 : if (start < finish)
3318 : : {
3319 : 51211 : inner = GET_MODE (tmps[start]);
3320 : 51211 : bytepos = subreg_lowpart_offset (inner, outer);
3321 : 51211 : if (known_eq (rtx_to_poly_int64 (XEXP (XVECEXP (src, 0, start), 1)),
3322 : : bytepos))
3323 : : {
3324 : 51187 : temp = force_subreg (outer, tmps[start], inner, 0);
3325 : 51187 : if (temp)
3326 : : {
3327 : 50534 : emit_move_insn (dst, temp);
3328 : 50534 : done = true;
3329 : 50534 : start++;
3330 : : }
3331 : : }
3332 : : }
3333 : :
3334 : : /* If the first element wasn't the low part, try the last. */
3335 : 50534 : if (!done
3336 : 677 : && start < finish - 1)
3337 : : {
3338 : 610 : inner = GET_MODE (tmps[finish - 1]);
3339 : 610 : bytepos = subreg_lowpart_offset (inner, outer);
3340 : 610 : 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 : 50534 : if (!done)
3356 : 677 : emit_move_insn (dst, CONST0_RTX (outer));
3357 : : }
3358 : :
3359 : : /* Process the pieces. */
3360 : 135701 : for (i = start; i < finish; i++)
3361 : : {
3362 : 73183 : poly_int64 bytepos = rtx_to_poly_int64 (XEXP (XVECEXP (src, 0, i), 1));
3363 : 73183 : machine_mode mode = GET_MODE (tmps[i]);
3364 : 146366 : poly_int64 bytelen = GET_MODE_SIZE (mode);
3365 : 73183 : poly_uint64 adj_bytelen;
3366 : 73183 : 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 : 73183 : gcc_checking_assert (ordered_p (bytepos + bytelen, ssize));
3373 : 145547 : if (known_size_p (ssize) && maybe_gt (bytepos + bytelen, ssize))
3374 : 819 : adj_bytelen = ssize - bytepos;
3375 : : else
3376 : 73183 : 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 : 73183 : if (GET_CODE (dst) == CONCAT)
3381 : : {
3382 : 27890 : if (known_le (bytepos + adj_bytelen,
3383 : : GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)))))
3384 : : dest = XEXP (dst, 0);
3385 : :
3386 : 17278 : else if (known_ge (bytepos, GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)))))
3387 : : {
3388 : 10612 : bytepos -= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)));
3389 : 5306 : dest = XEXP (dst, 1);
3390 : : }
3391 : :
3392 : : else
3393 : : {
3394 : 3333 : machine_mode dest_mode = GET_MODE (dest);
3395 : 3333 : machine_mode tmp_mode = GET_MODE (tmps[i]);
3396 : 3333 : scalar_int_mode dest_imode;
3397 : :
3398 : 3333 : 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 : 3333 : if (finish == start + 1
3405 : 3333 : && REG_P (tmps[i])
3406 : 3333 : && SCALAR_INT_MODE_P (tmp_mode)
3407 : 3333 : && COMPLEX_MODE_P (dest_mode)
3408 : 6666 : && int_mode_for_mode (dest_mode).exists (&dest_imode))
3409 : : {
3410 : 3333 : const scalar_int_mode tmp_imode
3411 : 3333 : = as_a <scalar_int_mode> (tmp_mode);
3412 : :
3413 : 6666 : if (GET_MODE_BITSIZE (dest_imode)
3414 : 3333 : < 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 : 3274 : 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 : 69850 : 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 : 760 : 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 : 760 : store_bit_field (dest,
3474 : 760 : adj_bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
3475 : 2280 : 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 : 69090 : else if (MEM_P (dest)
3481 : 7490 : && (!targetm.slow_unaligned_access (mode, MEM_ALIGN (dest))
3482 : 0 : || MEM_ALIGN (dest) >= GET_MODE_ALIGNMENT (mode))
3483 : 14980 : && multiple_p (bytepos * BITS_PER_UNIT,
3484 : : GET_MODE_ALIGNMENT (mode))
3485 : 76580 : && known_eq (bytelen, GET_MODE_SIZE (mode)))
3486 : 7490 : emit_move_insn (adjust_address (dest, mode, bytepos), tmps[i]);
3487 : :
3488 : : else
3489 : 123200 : store_bit_field (dest, bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
3490 : : 0, 0, mode, tmps[i], false, false);
3491 : : }
3492 : :
3493 : : /* Copy from the pseudo into the (probable) hard reg. */
3494 : 65851 : if (orig_dst != dst)
3495 : 3333 : 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 : 330300 : maybe_emit_group_store (rtx x, tree type)
3503 : : {
3504 : 330300 : machine_mode mode = TYPE_MODE (type);
3505 : 330300 : gcc_checking_assert (GET_MODE (x) == VOIDmode || GET_MODE (x) == mode);
3506 : 330300 : 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 : 249 : copy_blkmode_from_reg (rtx target, rtx srcreg, tree type)
3521 : : {
3522 : 249 : unsigned HOST_WIDE_INT bytes = int_size_in_bytes (type);
3523 : 249 : rtx src = NULL, dst = NULL;
3524 : 249 : unsigned HOST_WIDE_INT bitsize = MIN (TYPE_ALIGN (type), BITS_PER_WORD);
3525 : 249 : unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0;
3526 : : /* No current ABI uses variable-sized modes to pass a BLKmnode type. */
3527 : 249 : fixed_size_mode mode = as_a <fixed_size_mode> (GET_MODE (srcreg));
3528 : 249 : fixed_size_mode tmode = as_a <fixed_size_mode> (GET_MODE (target));
3529 : 249 : fixed_size_mode copy_mode;
3530 : :
3531 : : /* BLKmode registers created in the back-end shouldn't have survived. */
3532 : 249 : 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 : 249 : if (bytes % UNITS_PER_WORD != 0
3544 : 249 : && (targetm.calls.return_in_msb (type)
3545 : 218 : ? !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 : 249 : else if (MEM_P (target)
3552 : 249 : && (!targetm.slow_unaligned_access (mode, MEM_ALIGN (target))
3553 : 0 : || MEM_ALIGN (target) >= GET_MODE_ALIGNMENT (mode))
3554 : 498 : && 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 : 211 : else if (REG_P (target)
3562 : 0 : && GET_MODE (target) == mode
3563 : 211 : && 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 : 422 : 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 : 211 : copy_mode = word_mode;
3590 : 211 : if (MEM_P (target))
3591 : : {
3592 : 211 : opt_scalar_int_mode mem_mode = int_mode_for_size (bitsize, 1);
3593 : 211 : if (mem_mode.exists ())
3594 : 211 : 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 : 211 : for (bitpos = 0, xbitpos = padding_correction;
3600 : 1035 : bitpos < bytes * BITS_PER_UNIT;
3601 : 824 : 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 : 824 : if (xbitpos % BITS_PER_WORD == 0 || xbitpos == padding_correction)
3607 : 211 : 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 : 824 : if (REG_P (target) && GET_MODE_BITSIZE (tmode) < BITS_PER_WORD)
3612 : : dst = target;
3613 : 824 : else if (bitpos % BITS_PER_WORD == 0)
3614 : 211 : 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 : 824 : store_bit_field (dst, bitsize, bitpos % BITS_PER_WORD, 0, 0, copy_mode,
3619 : 824 : extract_bit_field (src, bitsize,
3620 : 824 : 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 : 3435 : copy_blkmode_to_reg (machine_mode mode_in, tree src)
3634 : : {
3635 : 3435 : int i, n_regs;
3636 : 3435 : unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0, bytes;
3637 : 3435 : unsigned int bitsize;
3638 : 3435 : 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 : 3435 : fixed_size_mode mode = as_a <fixed_size_mode> (mode_in);
3641 : 3435 : fixed_size_mode dst_mode;
3642 : 3435 : scalar_int_mode min_mode;
3643 : :
3644 : 3435 : gcc_assert (TYPE_MODE (TREE_TYPE (src)) == BLKmode);
3645 : :
3646 : 3435 : x = expand_normal (src);
3647 : :
3648 : 3435 : bytes = arg_int_size_in_bytes (TREE_TYPE (src));
3649 : 3435 : 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 : 1224 : if (bytes % UNITS_PER_WORD != 0
3663 : 1224 : && (targetm.calls.return_in_msb (TREE_TYPE (src))
3664 : 1188 : ? !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 : 1224 : n_regs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3670 : 1224 : dst_words = XALLOCAVEC (rtx, n_regs);
3671 : 1224 : bitsize = MIN (TYPE_ALIGN (TREE_TYPE (src)), BITS_PER_WORD);
3672 : 1224 : min_mode = smallest_int_mode_for_size (bitsize).require ();
3673 : :
3674 : : /* Copy the structure BITSIZE bits at a time. */
3675 : 1224 : for (bitpos = 0, xbitpos = padding_correction;
3676 : 3974 : bitpos < bytes * BITS_PER_UNIT;
3677 : 2750 : 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 : 2750 : if (xbitpos % BITS_PER_WORD == 0
3683 : 1523 : || xbitpos == padding_correction)
3684 : : {
3685 : : /* Generate an appropriate register. */
3686 : 1227 : dst_word = gen_reg_rtx (word_mode);
3687 : 1227 : dst_words[xbitpos / BITS_PER_WORD] = dst_word;
3688 : :
3689 : : /* Clear the destination before we move anything into it. */
3690 : 1227 : 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 : 2750 : opt_scalar_int_mode mode_iter;
3699 : 2750 : if (padding_correction == 0 && !STRICT_ALIGNMENT)
3700 : : {
3701 : 7488 : FOR_EACH_MODE_FROM (mode_iter, min_mode)
3702 : : {
3703 : 7488 : unsigned int msize = GET_MODE_BITSIZE (mode_iter.require ());
3704 : 7488 : if (msize <= ((bytes * BITS_PER_UNIT) - bitpos)
3705 : 4741 : && msize <= BITS_PER_WORD)
3706 : 4738 : 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 : 2750 : if (bitpos % BITS_PER_WORD == 0)
3715 : 1227 : 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 : 5500 : store_bit_field (dst_word, bitsize, xbitpos % BITS_PER_WORD,
3720 : : 0, 0, word_mode,
3721 : 2750 : extract_bit_field (src_word, bitsize,
3722 : 2750 : bitpos % BITS_PER_WORD, 1,
3723 : : NULL_RTX, word_mode, word_mode,
3724 : : false, NULL),
3725 : : false, false);
3726 : : }
3727 : :
3728 : 1224 : 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 : 3672 : if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
3742 : : dst_mode = word_mode;
3743 : : else
3744 : 498 : dst_mode = mode;
3745 : 1224 : dst = gen_reg_rtx (dst_mode);
3746 : :
3747 : 3675 : for (i = 0; i < n_regs; i++)
3748 : 1227 : emit_move_insn (operand_subword (dst, i, 0, dst_mode), dst_words[i]);
3749 : :
3750 : 1224 : 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 : 11395128 : use_reg_mode (rtx *call_fusage, rtx reg, machine_mode mode)
3761 : : {
3762 : 11395128 : gcc_assert (REG_P (reg));
3763 : :
3764 : 11395128 : if (!HARD_REGISTER_P (reg))
3765 : : return;
3766 : :
3767 : 11395128 : *call_fusage
3768 : 11395128 : = 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 : 797877 : clobber_reg_mode (rtx *call_fusage, rtx reg, machine_mode mode)
3776 : : {
3777 : 797877 : gcc_assert (REG_P (reg) && REGNO (reg) < FIRST_PSEUDO_REGISTER);
3778 : :
3779 : 797877 : *call_fusage
3780 : 797877 : = gen_rtx_EXPR_LIST (mode, gen_rtx_CLOBBER (VOIDmode, reg), *call_fusage);
3781 : 797877 : }
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 : 1581 : use_regs (rtx *call_fusage, int regno, int nregs)
3788 : : {
3789 : 1581 : int i;
3790 : :
3791 : 1581 : gcc_assert (regno + nregs <= FIRST_PSEUDO_REGISTER);
3792 : :
3793 : 3162 : for (i = 0; i < nregs; i++)
3794 : 1581 : use_reg (call_fusage, regno_reg_rtx[regno + i]);
3795 : 1581 : }
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 : 301876 : use_group_regs (rtx *call_fusage, rtx regs)
3803 : : {
3804 : 301876 : int i;
3805 : :
3806 : 896647 : for (i = 0; i < XVECLEN (regs, 0); i++)
3807 : : {
3808 : 594771 : 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 : 594771 : if (reg != 0 && REG_P (reg))
3814 : 594771 : use_reg (call_fusage, reg);
3815 : : }
3816 : 301876 : }
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 : 11748048 : get_def_for_expr (tree name, enum tree_code code)
3824 : : {
3825 : 11748048 : gimple *def_stmt;
3826 : :
3827 : 11748048 : if (TREE_CODE (name) != SSA_NAME)
3828 : : return NULL;
3829 : :
3830 : 9168238 : def_stmt = get_gimple_for_ssa_name (name);
3831 : 9168238 : if (!def_stmt
3832 : 1931204 : || !is_gimple_assign (def_stmt)
3833 : 11098066 : || 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 : 16419 : get_def_for_expr_class (tree name, enum tree_code_class tclass)
3845 : : {
3846 : 16419 : gimple *def_stmt;
3847 : :
3848 : 16419 : if (TREE_CODE (name) != SSA_NAME)
3849 : : return NULL;
3850 : :
3851 : 16419 : def_stmt = get_gimple_for_ssa_name (name);
3852 : 16419 : if (!def_stmt
3853 : 14278 : || !is_gimple_assign (def_stmt)
3854 : 30697 : || 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 : 159790 : 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 : 159790 : machine_mode mode = GET_MODE (object);
3872 : 159790 : unsigned int align;
3873 : :
3874 : 159790 : 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 : 159790 : poly_int64 size_val;
3879 : 159790 : if (mode != BLKmode
3880 : 54658 : && poly_int_rtx_p (size, &size_val)
3881 : 214448 : && known_eq (size_val, GET_MODE_SIZE (mode)))
3882 : : {
3883 : 54658 : rtx zero = CONST0_RTX (mode);
3884 : 54658 : if (zero != NULL)
3885 : : {
3886 : 54658 : emit_move_insn (object, zero);
3887 : 54658 : 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 : 105132 : if (size == const0_rtx)
3903 : : return NULL;
3904 : :
3905 : 105132 : align = MEM_ALIGN (object);
3906 : :
3907 : 105132 : if (CONST_INT_P (size)
3908 : 203029 : && targetm.use_by_pieces_infrastructure_p (INTVAL (size), align,
3909 : : CLEAR_BY_PIECES,
3910 : 97897 : optimize_insn_for_speed_p ()))
3911 : 78643 : clear_by_pieces (object, INTVAL (size), align);
3912 : 26489 : 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 : 16768 : else if (try_store_by_multiple_pieces (object, size, ctz_size,
3917 : : min_size, max_size,
3918 : : NULL_RTX, 0, align))
3919 : : ;
3920 : 16506 : else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object)))
3921 : 16506 : return set_storage_via_libcall (object, size, const0_rtx,
3922 : 16506 : method == BLOCK_OP_TAILCALL);
3923 : : else
3924 : 0 : gcc_unreachable ();
3925 : :
3926 : : return NULL;
3927 : : }
3928 : :
3929 : : rtx
3930 : 109561 : clear_storage (rtx object, rtx size, enum block_op_methods method)
3931 : : {
3932 : 109561 : unsigned HOST_WIDE_INT max, min = 0;
3933 : 109561 : if (GET_CODE (size) == CONST_INT)
3934 : 109561 : min = max = UINTVAL (size);
3935 : : else
3936 : 0 : max = GET_MODE_MASK (GET_MODE (size));
3937 : 109561 : 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 : 16510 : set_storage_via_libcall (rtx object, rtx size, rtx val, bool tailcall)
3946 : : {
3947 : 16510 : tree call_expr, fn, object_tree, size_tree, val_tree;
3948 : 16510 : machine_mode size_mode;
3949 : :
3950 : 16510 : object = copy_addr_to_reg (XEXP (object, 0));
3951 : 16510 : object_tree = make_tree (ptr_type_node, object);
3952 : :
3953 : 16510 : if (!CONST_INT_P (val))
3954 : 3 : val = convert_to_mode (TYPE_MODE (integer_type_node), val, 1);
3955 : 16510 : val_tree = make_tree (integer_type_node, val);
3956 : :
3957 : 16510 : size_mode = TYPE_MODE (sizetype);
3958 : 16510 : size = convert_to_mode (size_mode, size, 1);
3959 : 16510 : size = copy_to_mode_reg (size_mode, size);
3960 : 16510 : 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 : 16510 : fn = builtin_decl_implicit (BUILT_IN_MEMSET);
3965 : 16510 : call_expr = build_call_expr (fn, 3, object_tree, val_tree, size_tree);
3966 : 16510 : CALL_EXPR_TAILCALL (call_expr) = tailcall;
3967 : :
3968 : 16510 : return expand_call (call_expr, NULL_RTX, false);
3969 : : }
3970 : :
3971 : : /* Expand a setmem pattern; return true if successful. */
3972 : :
3973 : : bool
3974 : 35565 : 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 : 35565 : if (expected_align < align)
3985 : : expected_align = align;
3986 : 35565 : 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 : 35565 : opt_scalar_int_mode mode_iter;
3995 : 225594 : FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_INT)
3996 : : {
3997 : 201958 : scalar_int_mode mode = mode_iter.require ();
3998 : 201958 : enum insn_code code = direct_optab_handler (setmem_optab, mode);
3999 : :
4000 : 201958 : 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 : 201958 : && ((CONST_INT_P (size)
4007 : 30477 : && ((unsigned HOST_WIDE_INT) INTVAL (size)
4008 : 30477 : <= (GET_MODE_MASK (mode) >> 1)))
4009 : 27879 : || max_size <= (GET_MODE_MASK (mode) >> 1)
4010 : 30796 : || GET_MODE_BITSIZE (mode) >= GET_MODE_BITSIZE (Pmode)))
4011 : : {
4012 : 47414 : class expand_operand ops[9];
4013 : 47414 : unsigned int nops;
4014 : :
4015 : 47414 : nops = insn_data[(int) code].n_generator_args;
4016 : 47414 : gcc_assert (nops == 4 || nops == 6 || nops == 8 || nops == 9);
4017 : :
4018 : 47414 : create_fixed_operand (&ops[0], object);
4019 : : /* The check above guarantees that this size conversion is valid. */
4020 : 47414 : create_convert_operand_to (&ops[1], size, mode, true);
4021 : 47414 : create_convert_operand_from (&ops[2], val, byte_mode, true);
4022 : 47414 : create_integer_operand (&ops[3], align / BITS_PER_UNIT);
4023 : 47414 : if (nops >= 6)
4024 : : {
4025 : 47414 : create_integer_operand (&ops[4], expected_align / BITS_PER_UNIT);
4026 : 47414 : create_integer_operand (&ops[5], expected_size);
4027 : : }
4028 : 47414 : if (nops >= 8)
4029 : : {
4030 : 47414 : create_integer_operand (&ops[6], min_size);
4031 : : /* If we cannot represent the maximal size,
4032 : : make parameter NULL. */
4033 : 47414 : if ((HOST_WIDE_INT) max_size != -1)
4034 : 45037 : create_integer_operand (&ops[7], max_size);
4035 : : else
4036 : 2377 : create_fixed_operand (&ops[7], NULL);
4037 : : }
4038 : 47414 : if (nops == 9)
4039 : : {
4040 : : /* If we cannot represent the maximal size,
4041 : : make parameter NULL. */
4042 : 47414 : if ((HOST_WIDE_INT) probable_max_size != -1)
4043 : 45560 : create_integer_operand (&ops[8], probable_max_size);
4044 : : else
4045 : 1854 : create_fixed_operand (&ops[8], NULL);
4046 : : }
4047 : 47414 : if (maybe_expand_insn (code, nops, ops))
4048 : 11929 : 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 : 557963 : write_complex_part (rtx cplx, rtx val, bool imag_p, bool undefined_p)
4062 : : {
4063 : 557963 : machine_mode cmode;
4064 : 557963 : scalar_mode imode;
4065 : 557963 : unsigned ibitsize;
4066 : :
4067 : 557963 : if (GET_CODE (cplx) == CONCAT)
4068 : : {
4069 : 494995 : emit_move_insn (XEXP (cplx, imag_p), val);
4070 : 494995 : return;
4071 : : }
4072 : :
4073 : 62968 : cmode = GET_MODE (cplx);
4074 : 62968 : imode = GET_MODE_INNER (cmode);
4075 : 62968 : 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 : 62968 : if (MEM_P (cplx))
4083 : : {
4084 : 76071 : emit_move_insn (adjust_address_nv (cplx, imode,
4085 : : imag_p ? GET_MODE_SIZE (imode) : 0),
4086 : : val);
4087 : 50714 : 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 : 12254 : 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 : 12254 : || (REG_P (cplx)
4100 : 7306 : && REGNO (cplx) < FIRST_PSEUDO_REGISTER
4101 : 7120 : && REG_NREGS (cplx) % 2 == 0))
4102 : : {
4103 : 4964 : rtx part = simplify_gen_subreg (imode, cplx, cmode,
4104 : 7446 : imag_p ? GET_MODE_SIZE (imode) : 0);
4105 : 4964 : if (part)
4106 : : {
4107 : 4964 : emit_move_insn (part, val);
4108 : 4964 : 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 : 10935 : 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 : 505633 : read_complex_part (rtx cplx, bool imag_p)
4124 : : {
4125 : 505633 : machine_mode cmode;
4126 : 505633 : scalar_mode imode;
4127 : 505633 : unsigned ibitsize;
4128 : :
4129 : 505633 : if (GET_CODE (cplx) == CONCAT)
4130 : 327811 : return XEXP (cplx, imag_p);
4131 : :
4132 : 177822 : cmode = GET_MODE (cplx);
4133 : 177822 : imode = GET_MODE_INNER (cmode);
4134 : 177822 : ibitsize = GET_MODE_BITSIZE (imode);
4135 : :
4136 : : /* Special case reads from complex constants that got spilled to memory. */
4137 : 177822 : if (MEM_P (cplx) && GET_CODE (XEXP (cplx, 0)) == SYMBOL_REF)
4138 : : {
4139 : 37929 : tree decl = SYMBOL_REF_DECL (XEXP (cplx, 0));
4140 : 37929 : 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 : 177822 : if (MEM_P (cplx))
4154 : 235490 : 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 : 20721 : 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 : 20721 : || (REG_P (cplx)
4167 : 338 : && REGNO (cplx) < FIRST_PSEUDO_REGISTER
4168 : 292 : && REG_NREGS (cplx) % 2 == 0))
4169 : : {
4170 : 10225 : rtx ret = simplify_gen_subreg (imode, cplx, cmode,
4171 : 15337 : imag_p ? GET_MODE_SIZE (imode) : 0);
4172 : 10225 : 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 : 15744 : 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 : 244318 : emit_move_change_mode (machine_mode new_mode,
4190 : : machine_mode old_mode, rtx x, bool force)
4191 : : {
4192 : 244318 : rtx ret;
4193 : :
4194 : 244318 : 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 : 243000 : 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 : 53029 : 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 : 53029 : 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 : 189971 : if (force)
4222 : 189971 : 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 : 244318 : 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 : 122159 : emit_move_via_integer (machine_mode mode, rtx x, rtx y, bool force)
4236 : : {
4237 : 122159 : scalar_int_mode imode;
4238 : 122159 : enum insn_code code;
4239 : :
4240 : : /* There must exist a mode of the exact size we require. */
4241 : 122159 : if (!int_mode_for_mode (mode).exists (&imode))
4242 : 0 : return NULL;
4243 : :
4244 : : /* The target must support moves in this mode. */
4245 : 122159 : code = optab_handler (mov_optab, imode);
4246 : 122159 : if (code == CODE_FOR_nothing)
4247 : : return NULL;
4248 : :
4249 : 122159 : x = emit_move_change_mode (imode, mode, x, force);
4250 : 122159 : if (x == NULL_RTX)
4251 : : return NULL;
4252 : 122159 : y = emit_move_change_mode (imode, mode, y, force);
4253 : 122159 : if (y == NULL_RTX)
4254 : : return NULL;
4255 : 122159 : 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 : 3597 : 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 : 5381 : emit_move_complex_push (machine_mode mode, rtx x, rtx y)
4318 : : {
4319 : 5381 : scalar_mode submode = GET_MODE_INNER (mode);
4320 : 5381 : bool imag_first;
4321 : :
4322 : : #ifdef PUSH_ROUNDING
4323 : 10762 : 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 : 5381 : 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 : 4663 : 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 : 4663 : emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
4351 : : read_complex_part (y, imag_first));
4352 : 4663 : return emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
4353 : 9326 : 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 : 81476 : 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 : 81476 : if (!reload_completed && !reload_in_progress
4366 : 162952 : && REG_P (x) && !reg_overlap_mentioned_p (x, y))
4367 : 6120 : emit_clobber (x);
4368 : :
4369 : 81476 : write_complex_part (x, read_complex_part (y, false), false, true);
4370 : 81476 : write_complex_part (x, read_complex_part (y, true), true, false);
4371 : :
4372 : 81476 : 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 : 85856 : emit_move_complex (machine_mode mode, rtx x, rtx y)
4380 : : {
4381 : 85856 : 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 : 85856 : if (push_operand (x, mode))
4386 : 4773 : 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 : 81083 : if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
4391 : 72878 : && optab_handler (mov_optab, GET_MODE_INNER (mode)) != CODE_FOR_nothing
4392 : 72878 : && !(REG_P (x)
4393 : 2214 : && HARD_REGISTER_P (x)
4394 : 564 : && REG_NREGS (x) == 1)
4395 : 153961 : && !(REG_P (y)
4396 : 3304 : && HARD_REGISTER_P (y)
4397 : 1652 : && REG_NREGS (y) == 1))
4398 : : try_int = false;
4399 : : /* Not possible if the values are inherently not adjacent. */
4400 : 8205 : 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 : 756 : 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 : 634 : 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 : 756 : 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 : 756 : if (MEM_P (x) && MEM_P (y))
4424 : : {
4425 : 726 : emit_block_move (x, y, gen_int_mode (GET_MODE_SIZE (mode), Pmode),
4426 : 360 : (optimize_insn_for_speed_p()
4427 : : ? BLOCK_OP_NO_LIBCALL : BLOCK_OP_NORMAL));
4428 : 360 : return get_last_insn ();
4429 : : }
4430 : :
4431 : 396 : ret = emit_move_via_integer (mode, x, y, true);
4432 : 396 : if (ret)
4433 : : return ret;
4434 : : }
4435 : :
4436 : 80327 : 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 = end_sequence ();
4551 : :
4552 : : /* Show the output dies here. This is necessary for SUBREGs
4553 : : of pseudos since we cannot track their lifetimes correctly;
4554 : : hard regs shouldn't appear here except as return values.
4555 : : We never want to emit such a clobber after reload. */
4556 : 0 : if (x != y
4557 : 0 : && ! (reload_in_progress || reload_completed)
4558 : 0 : && need_clobber != 0)
4559 : 0 : emit_clobber (x);
4560 : :
4561 : 0 : emit_insn (seq);
4562 : :
4563 : 0 : return last_insn;
4564 : : }
4565 : :
4566 : : /* Low level part of emit_move_insn.
4567 : : Called just like emit_move_insn, but assumes X and Y
4568 : : are basically valid. */
4569 : :
4570 : : rtx_insn *
4571 : 76544811 : emit_move_insn_1 (rtx x, rtx y)
4572 : : {
4573 : 76544811 : machine_mode mode = GET_MODE (x);
4574 : 76544811 : enum insn_code code;
4575 : :
4576 : 76544811 : gcc_assert ((unsigned int) mode < (unsigned int) MAX_MACHINE_MODE);
4577 : :
4578 : 76544811 : code = optab_handler (mov_optab, mode);
4579 : 76544811 : if (code != CODE_FOR_nothing)
4580 : 76337192 : return emit_insn (GEN_FCN (code) (x, y));
4581 : :
4582 : : /* Expand complex moves by moving real part and imag part. */
4583 : 207619 : if (COMPLEX_MODE_P (mode))
4584 : 85856 : return emit_move_complex (mode, x, y);
4585 : :
4586 : : if (GET_MODE_CLASS (mode) == MODE_DECIMAL_FLOAT
4587 : : || ALL_FIXED_POINT_MODE_P (mode))
4588 : : {
4589 : 121763 : rtx_insn *result = emit_move_via_integer (mode, x, y, true);
4590 : :
4591 : : /* If we can't find an integer mode, use multi words. */
4592 : 121763 : if (result)
4593 : : return result;
4594 : : else
4595 : 0 : return emit_move_multi_word (mode, x, y);
4596 : : }
4597 : :
4598 : : if (GET_MODE_CLASS (mode) == MODE_CC)
4599 : 0 : return emit_move_ccmode (mode, x, y);
4600 : :
4601 : : /* Try using a move pattern for the corresponding integer mode. This is
4602 : : only safe when simplify_subreg can convert MODE constants into integer
4603 : : constants. At present, it can only do this reliably if the value
4604 : : fits within a HOST_WIDE_INT. */
4605 : 0 : if (!CONSTANT_P (y)
4606 : 0 : || known_le (GET_MODE_BITSIZE (mode), HOST_BITS_PER_WIDE_INT))
4607 : : {
4608 : 0 : rtx_insn *ret = emit_move_via_integer (mode, x, y, lra_in_progress);
4609 : :
4610 : 0 : if (ret)
4611 : : {
4612 : 0 : if (! lra_in_progress || recog (PATTERN (ret), ret, 0) >= 0)
4613 : 0 : return ret;
4614 : : }
4615 : : }
4616 : :
4617 : 0 : return emit_move_multi_word (mode, x, y);
4618 : : }
4619 : :
4620 : : /* Generate code to copy Y into X.
4621 : : Both Y and X must have the same mode, except that
4622 : : Y can be a constant with VOIDmode.
4623 : : This mode cannot be BLKmode; use emit_block_move for that.
4624 : :
4625 : : Return the last instruction emitted. */
4626 : :
4627 : : rtx_insn *
4628 : 70652197 : emit_move_insn (rtx x, rtx y)
4629 : : {
4630 : 70652197 : machine_mode mode = GET_MODE (x);
4631 : 70652197 : rtx y_cst = NULL_RTX;
4632 : 70652197 : rtx_insn *last_insn;
4633 : 70652197 : rtx set;
4634 : :
4635 : 70652197 : gcc_assert (mode != BLKmode
4636 : : && (GET_MODE (y) == mode || GET_MODE (y) == VOIDmode));
4637 : :
4638 : : /* If we have a copy that looks like one of the following patterns:
4639 : : (set (subreg:M1 (reg:M2 ...)) (subreg:M1 (reg:M2 ...)))
4640 : : (set (subreg:M1 (reg:M2 ...)) (mem:M1 ADDR))
4641 : : (set (mem:M1 ADDR) (subreg:M1 (reg:M2 ...)))
4642 : : (set (subreg:M1 (reg:M2 ...)) (constant C))
4643 : : where mode M1 is equal in size to M2, try to detect whether the
4644 : : mode change involves an implicit round trip through memory.
4645 : : If so, see if we can avoid that by removing the subregs and
4646 : : doing the move in mode M2 instead. */
4647 : :
4648 : 70652197 : rtx x_inner = NULL_RTX;
4649 : 70652197 : rtx y_inner = NULL_RTX;
4650 : :
4651 : 73377063 : auto candidate_subreg_p = [&](rtx subreg) {
4652 : 2724866 : return (REG_P (SUBREG_REG (subreg))
4653 : 8172861 : && known_eq (GET_MODE_SIZE (GET_MODE (SUBREG_REG (subreg))),
4654 : : GET_MODE_SIZE (GET_MODE (subreg)))
4655 : 3038326 : && optab_handler (mov_optab, GET_MODE (SUBREG_REG (subreg)))
4656 : 2724866 : != CODE_FOR_nothing);
4657 : : };
4658 : :
4659 : 70658312 : auto candidate_mem_p = [&](machine_mode innermode, rtx mem) {
4660 : 6115 : return (!targetm.can_change_mode_class (innermode, GET_MODE (mem), ALL_REGS)
4661 : 6115 : && !push_operand (mem, GET_MODE (mem))
4662 : : /* Not a candiate if innermode requires too much alignment. */
4663 : 12170 : && (MEM_ALIGN (mem) >= GET_MODE_ALIGNMENT (innermode)
4664 : 226 : || targetm.slow_unaligned_access (GET_MODE (mem),
4665 : 113 : MEM_ALIGN (mem))
4666 : 226 : || !targetm.slow_unaligned_access (innermode,
4667 : 113 : MEM_ALIGN (mem))));
4668 : : };
4669 : :
4670 : 70652197 : if (SUBREG_P (x) && candidate_subreg_p (x))
4671 : 10230 : x_inner = SUBREG_REG (x);
4672 : :
4673 : 70652197 : if (SUBREG_P (y) && candidate_subreg_p (y))
4674 : 301901 : y_inner = SUBREG_REG (y);
4675 : :
4676 : 70652197 : if (x_inner != NULL_RTX
4677 : 70652197 : && y_inner != NULL_RTX
4678 : 1081 : && GET_MODE (x_inner) == GET_MODE (y_inner)
4679 : 70652885 : && !targetm.can_change_mode_class (GET_MODE (x_inner), mode, ALL_REGS))
4680 : : {
4681 : 688 : x = x_inner;
4682 : 688 : y = y_inner;
4683 : 688 : mode = GET_MODE (x_inner);
4684 : : }
4685 : 70651509 : else if (x_inner != NULL_RTX
4686 : 9542 : && MEM_P (y)
4687 : 70651823 : && candidate_mem_p (GET_MODE (x_inner), y))
4688 : : {
4689 : 314 : x = x_inner;
4690 : 314 : y = adjust_address (y, GET_MODE (x_inner), 0);
4691 : 314 : mode = GET_MODE (x_inner);
4692 : : }
4693 : 70651195 : else if (y_inner != NULL_RTX
4694 : 301213 : && MEM_P (x)
4695 : 70656996 : && candidate_mem_p (GET_MODE (y_inner), x))
4696 : : {
4697 : 5741 : x = adjust_address (x, GET_MODE (y_inner), 0);
4698 : 5741 : y = y_inner;
4699 : 5741 : mode = GET_MODE (y_inner);
4700 : : }
4701 : 70645454 : else if (x_inner != NULL_RTX
4702 : 9228 : && CONSTANT_P (y)
4703 : 468 : && !targetm.can_change_mode_class (GET_MODE (x_inner),
4704 : : mode, ALL_REGS)
4705 : 70645922 : && (y_inner = simplify_subreg (GET_MODE (x_inner), y, mode, 0)))
4706 : : {
4707 : 468 : x = x_inner;
4708 : 468 : y = y_inner;
4709 : 468 : mode = GET_MODE (x_inner);
4710 : : }
4711 : :
4712 : 70652197 : if (CONSTANT_P (y))
4713 : : {
4714 : 16690615 : if (optimize
4715 : 13108254 : && SCALAR_FLOAT_MODE_P (GET_MODE (x))
4716 : 17475496 : && (last_insn = compress_float_constant (x, y)))
4717 : : return last_insn;
4718 : :
4719 : 16621687 : y_cst = y;
4720 : :
4721 : 16621687 : if (!targetm.legitimate_constant_p (mode, y))
4722 : : {
4723 : 502945 : y = force_const_mem (mode, y);
4724 : :
4725 : : /* If the target's cannot_force_const_mem prevented the spill,
4726 : : assume that the target's move expanders will also take care
4727 : : of the non-legitimate constant. */
4728 : 502945 : if (!y)
4729 : : y = y_cst;
4730 : : else
4731 : 482982 : y = use_anchored_address (y);
4732 : : }
4733 : : }
4734 : :
4735 : : /* If X or Y are memory references, verify that their addresses are valid
4736 : : for the machine. */
4737 : 70583269 : if (MEM_P (x)
4738 : 86620700 : && (! memory_address_addr_space_p (GET_MODE (x), XEXP (x, 0),
4739 : 13793910 : MEM_ADDR_SPACE (x))
4740 : 2243688 : && ! push_operand (x, GET_MODE (x))))
4741 : 167 : x = validize_mem (x);
4742 : :
4743 : 70583269 : if (MEM_P (y)
4744 : 88368916 : && ! memory_address_addr_space_p (GET_MODE (y), XEXP (y, 0),
4745 : 17785647 : MEM_ADDR_SPACE (y)))
4746 : 9279 : y = validize_mem (y);
4747 : :
4748 : 70583269 : gcc_assert (mode != BLKmode);
4749 : :
4750 : 70583269 : last_insn = emit_move_insn_1 (x, y);
4751 : :
4752 : 16621687 : if (y_cst && REG_P (x)
4753 : 12273843 : && (set = single_set (last_insn)) != NULL_RTX
4754 : 12273843 : && SET_DEST (set) == x
4755 : 82842651 : && ! rtx_equal_p (y_cst, SET_SRC (set)))
4756 : 1249237 : set_unique_reg_note (last_insn, REG_EQUAL, copy_rtx (y_cst));
4757 : :
4758 : : return last_insn;
4759 : : }
4760 : :
4761 : : /* Generate the body of an instruction to copy Y into X.
4762 : : It may be a list of insns, if one insn isn't enough. */
4763 : :
4764 : : rtx_insn *
4765 : 5961462 : gen_move_insn (rtx x, rtx y)
4766 : : {
4767 : 5961462 : start_sequence ();
4768 : 5961462 : emit_move_insn_1 (x, y);
4769 : 5961462 : return end_sequence ();
4770 : : }
4771 : :
4772 : : /* If Y is representable exactly in a narrower mode, and the target can
4773 : : perform the extension directly from constant or memory, then emit the
4774 : : move as an extension. */
4775 : :
4776 : : static rtx_insn *
4777 : 784881 : compress_float_constant (rtx x, rtx y)
4778 : : {
4779 : 784881 : machine_mode dstmode = GET_MODE (x);
4780 : 784881 : machine_mode orig_srcmode = GET_MODE (y);
4781 : 784881 : machine_mode srcmode;
4782 : 784881 : const REAL_VALUE_TYPE *r;
4783 : 784881 : int oldcost, newcost;
4784 : 784881 : bool speed = optimize_insn_for_speed_p ();
4785 : :
4786 : 784881 : r = CONST_DOUBLE_REAL_VALUE (y);
4787 : :
4788 : 784881 : if (targetm.legitimate_constant_p (dstmode, y))
4789 : 783212 : oldcost = set_src_cost (y, orig_srcmode, speed);
4790 : : else
4791 : 1669 : oldcost = set_src_cost (force_const_mem (dstmode, y), dstmode, speed);
4792 : :
4793 : 2774295 : FOR_EACH_MODE_UNTIL (srcmode, orig_srcmode)
4794 : : {
4795 : 2058342 : enum insn_code ic;
4796 : 2058342 : rtx trunc_y;
4797 : 2058342 : rtx_insn *last_insn;
4798 : :
4799 : : /* Skip if the target can't extend this way. */
4800 : 2058342 : ic = can_extend_p (dstmode, srcmode, 0);
4801 : 2058342 : if (ic == CODE_FOR_nothing)
4802 : 1637390 : continue;
4803 : :
4804 : : /* Skip if the narrowed value isn't exact. */
4805 : 420952 : if (! exact_real_truncate (srcmode, r))
4806 : 52545 : continue;
4807 : :
4808 : 368407 : trunc_y = const_double_from_real_value (*r, srcmode);
4809 : :
4810 : 368407 : if (targetm.legitimate_constant_p (srcmode, trunc_y))
4811 : : {
4812 : : /* Skip if the target needs extra instructions to perform
4813 : : the extension. */
4814 : 364331 : if (!insn_operand_matches (ic, 1, trunc_y))
4815 : 4163 : continue;
4816 : : /* This is valid, but may not be cheaper than the original. */
4817 : 360168 : newcost = set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y),
4818 : : dstmode, speed);
4819 : 360168 : if (oldcost < newcost)
4820 : 291240 : continue;
4821 : : }
4822 : 4076 : else if (float_extend_from_mem[dstmode][srcmode])
4823 : : {
4824 : 0 : trunc_y = force_const_mem (srcmode, trunc_y);
4825 : : /* This is valid, but may not be cheaper than the original. */
4826 : 0 : newcost = set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y),
4827 : : dstmode, speed);
4828 : 0 : if (oldcost < newcost)
4829 : 0 : continue;
4830 : 0 : trunc_y = validize_mem (trunc_y);
4831 : : }
4832 : : else
4833 : 4076 : continue;
4834 : :
4835 : : /* For CSE's benefit, force the compressed constant pool entry
4836 : : into a new pseudo. This constant may be used in different modes,
4837 : : and if not, combine will put things back together for us. */
4838 : 68928 : trunc_y = force_reg (srcmode, trunc_y);
4839 : :
4840 : : /* If x is a hard register, perform the extension into a pseudo,
4841 : : so that e.g. stack realignment code is aware of it. */
4842 : 68928 : rtx target = x;
4843 : 68928 : if (REG_P (x) && HARD_REGISTER_P (x))
4844 : 1 : target = gen_reg_rtx (dstmode);
4845 : :
4846 : 68928 : emit_unop_insn (ic, target, trunc_y, UNKNOWN);
4847 : 68928 : last_insn = get_last_insn ();
4848 : :
4849 : 68928 : if (REG_P (target))
4850 : 57917 : set_unique_reg_note (last_insn, REG_EQUAL, y);
4851 : :
4852 : 68928 : if (target != x)
4853 : 1 : return emit_move_insn (x, target);
4854 : : return last_insn;
4855 : : }
4856 : :
4857 : : return NULL;
4858 : : }
4859 : :
4860 : : /* Pushing data onto the stack. */
4861 : :
4862 : : /* Push a block of length SIZE (perhaps variable)
4863 : : and return an rtx to address the beginning of the block.
4864 : : The value may be virtual_outgoing_args_rtx.
4865 : :
4866 : : EXTRA is the number of bytes of padding to push in addition to SIZE.
4867 : : BELOW nonzero means this padding comes at low addresses;
4868 : : otherwise, the padding comes at high addresses. */
4869 : :
4870 : : rtx
4871 : 268695 : push_block (rtx size, poly_int64 extra, int below)
4872 : : {
4873 : 268695 : rtx temp;
4874 : :
4875 : 333861 : size = convert_modes (Pmode, ptr_mode, size, 1);
4876 : 268695 : if (CONSTANT_P (size))
4877 : 333861 : anti_adjust_stack (plus_constant (Pmode, size, extra));
4878 : 0 : else if (REG_P (size) && known_eq (extra, 0))
4879 : 0 : anti_adjust_stack (size);
4880 : : else
4881 : : {
4882 : 0 : temp = copy_to_mode_reg (Pmode, size);
4883 : 0 : if (maybe_ne (extra, 0))
4884 : 0 : temp = expand_binop (Pmode, add_optab, temp,
4885 : 0 : gen_int_mode (extra, Pmode),
4886 : : temp, 0, OPTAB_LIB_WIDEN);
4887 : 0 : anti_adjust_stack (temp);
4888 : : }
4889 : :
4890 : 268695 : if (STACK_GROWS_DOWNWARD)
4891 : : {
4892 : 268695 : temp = virtual_outgoing_args_rtx;
4893 : 268695 : if (maybe_ne (extra, 0) && below)
4894 : 0 : temp = plus_constant (Pmode, temp, extra);
4895 : : }
4896 : : else
4897 : : {
4898 : : poly_int64 csize;
4899 : : if (poly_int_rtx_p (size, &csize))
4900 : : temp = plus_constant (Pmode, virtual_outgoing_args_rtx,
4901 : : -csize - (below ? 0 : extra));
4902 : : else if (maybe_ne (extra, 0) && !below)
4903 : : temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
4904 : : negate_rtx (Pmode, plus_constant (Pmode, size,
4905 : : extra)));
4906 : : else
4907 : : temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
4908 : : negate_rtx (Pmode, size));
4909 : : }
4910 : :
4911 : 268695 : return memory_address (NARROWEST_INT_MODE, temp);
4912 : : }
4913 : :
4914 : : /* A utility routine that returns the base of an auto-inc memory, or NULL. */
4915 : :
4916 : : static rtx
4917 : 2567282 : mem_autoinc_base (rtx mem)
4918 : : {
4919 : 0 : if (MEM_P (mem))
4920 : : {
4921 : 1570164 : rtx addr = XEXP (mem, 0);
4922 : 1570164 : if (GET_RTX_CLASS (GET_CODE (addr)) == RTX_AUTOINC)
4923 : 1024784 : return XEXP (addr, 0);
4924 : : }
4925 : : return NULL;
4926 : : }
4927 : :
4928 : : /* A utility routine used here, in reload, and in try_split. The insns
4929 : : after PREV up to and including LAST are known to adjust the stack,
4930 : : with a final value of END_ARGS_SIZE. Iterate backward from LAST
4931 : : placing notes as appropriate. PREV may be NULL, indicating the
4932 : : entire insn sequence prior to LAST should be scanned.
4933 : :
4934 : : The set of allowed stack pointer modifications is small:
4935 : : (1) One or more auto-inc style memory references (aka pushes),
4936 : : (2) One or more addition/subtraction with the SP as destination,
4937 : : (3) A single move insn with the SP as destination,
4938 : : (4) A call_pop insn,
4939 : : (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
4940 : :
4941 : : Insns in the sequence that do not modify the SP are ignored,
4942 : : except for noreturn calls.
4943 : :
4944 : : The return value is the amount of adjustment that can be trivially
4945 : : verified, via immediate operand or auto-inc. If the adjustment
4946 : : cannot be trivially extracted, the return value is HOST_WIDE_INT_MIN. */
4947 : :
4948 : : poly_int64
4949 : 4402368 : find_args_size_adjust (rtx_insn *insn)
4950 : : {
4951 : 4402368 : rtx dest, set, pat;
4952 : 4402368 : int i;
4953 : :
4954 : 4402368 : pat = PATTERN (insn);
4955 : 4402368 : set = NULL;
4956 : :
4957 : : /* Look for a call_pop pattern. */
4958 : 4402368 : if (CALL_P (insn))
4959 : : {
4960 : : /* We have to allow non-call_pop patterns for the case
4961 : : of emit_single_push_insn of a TLS address. */
4962 : 2757920 : if (GET_CODE (pat) != PARALLEL)
4963 : 2743452 : return 0;
4964 : :
4965 : : /* All call_pop have a stack pointer adjust in the parallel.
4966 : : The call itself is always first, and the stack adjust is
4967 : : usually last, so search from the end. */
4968 : 14468 : for (i = XVECLEN (pat, 0) - 1; i > 0; --i)
4969 : : {
4970 : 14468 : set = XVECEXP (pat, 0, i);
4971 : 14468 : if (GET_CODE (set) != SET)
4972 : 0 : continue;
4973 : 14468 : dest = SET_DEST (set);
4974 : 14468 : if (dest == stack_pointer_rtx)
4975 : : break;
4976 : : }
4977 : : /* We'd better have found the stack pointer adjust. */
4978 : 14468 : if (i == 0)
4979 : 0 : return 0;
4980 : : /* Fall through to process the extracted SET and DEST
4981 : : as if it was a standalone insn. */
4982 : : }
4983 : 1644448 : else if (GET_CODE (pat) == SET)
4984 : : set = pat;
4985 : 257963 : else if ((set = single_set (insn)) != NULL)
4986 : : ;
4987 : 46861 : else if (GET_CODE (pat) == PARALLEL)
4988 : : {
4989 : : /* ??? Some older ports use a parallel with a stack adjust
4990 : : and a store for a PUSH_ROUNDING pattern, rather than a
4991 : : PRE/POST_MODIFY rtx. Don't force them to update yet... */
4992 : : /* ??? See h8300 and m68k, pushqi1. */
4993 : 0 : for (i = XVECLEN (pat, 0) - 1; i >= 0; --i)
4994 : : {
4995 : 0 : set = XVECEXP (pat, 0, i);
4996 : 0 : if (GET_CODE (set) != SET)
4997 : 0 : continue;
4998 : 0 : dest = SET_DEST (set);
4999 : 0 : if (dest == stack_pointer_rtx)
5000 : : break;
5001 : :
5002 : : /* We do not expect an auto-inc of the sp in the parallel. */
5003 : 0 : gcc_checking_assert (mem_autoinc_base (dest) != stack_pointer_rtx);
5004 : 0 : gcc_checking_assert (mem_autoinc_base (SET_SRC (set))
5005 : : != stack_pointer_rtx);
5006 : : }
5007 : 0 : if (i < 0)
5008 : 0 : return 0;
5009 : : }
5010 : : else
5011 : 46861 : return 0;
5012 : :
5013 : 1612055 : dest = SET_DEST (set);
5014 : :
5015 : : /* Look for direct modifications of the stack pointer. */
5016 : 1612055 : if (REG_P (dest) && REGNO (dest) == STACK_POINTER_REGNUM)
5017 : : {
5018 : : /* Look for a trivial adjustment, otherwise assume nothing. */
5019 : : /* Note that the SPU restore_stack_block pattern refers to
5020 : : the stack pointer in V4SImode. Consider that non-trivial. */
5021 : 328414 : poly_int64 offset;
5022 : 328414 : if (SCALAR_INT_MODE_P (GET_MODE (dest))
5023 : 328414 : && strip_offset (SET_SRC (set), &offset) == stack_pointer_rtx)
5024 : 326012 : return offset;
5025 : : /* ??? Reload can generate no-op moves, which will be cleaned
5026 : : up later. Recognize it and continue searching. */
5027 : 2402 : else if (rtx_equal_p (dest, SET_SRC (set)))
5028 : 0 : return 0;
5029 : : else
5030 : 2402 : return HOST_WIDE_INT_MIN;
5031 : : }
5032 : : else
5033 : : {
5034 : 1283641 : rtx mem, addr;
5035 : :
5036 : : /* Otherwise only think about autoinc patterns. */
5037 : 2322448 : if (mem_autoinc_base (dest) == stack_pointer_rtx)
5038 : : {
5039 : 916053 : mem = dest;
5040 : 1270324 : gcc_checking_assert (mem_autoinc_base (SET_SRC (set))
5041 : : != stack_pointer_rtx);
5042 : : }
5043 : 544674 : else if (mem_autoinc_base (SET_SRC (set)) == stack_pointer_rtx)
5044 : : mem = SET_SRC (set);
5045 : : else
5046 : 258857 : return 0;
5047 : :
5048 : 1024784 : addr = XEXP (mem, 0);
5049 : 1024784 : switch (GET_CODE (addr))
5050 : : {
5051 : 108731 : case PRE_INC:
5052 : 108731 : case POST_INC:
5053 : 217462 : return GET_MODE_SIZE (GET_MODE (mem));
5054 : 898132 : case PRE_DEC:
5055 : 898132 : case POST_DEC:
5056 : 1796264 : return -GET_MODE_SIZE (GET_MODE (mem));
5057 : 17921 : case PRE_MODIFY:
5058 : 17921 : case POST_MODIFY:
5059 : 17921 : addr = XEXP (addr, 1);
5060 : 17921 : gcc_assert (GET_CODE (addr) == PLUS);
5061 : 17921 : gcc_assert (XEXP (addr, 0) == stack_pointer_rtx);
5062 : 17921 : return rtx_to_poly_int64 (XEXP (addr, 1));
5063 : 0 : default:
5064 : 0 : gcc_unreachable ();
5065 : : }
5066 : : }
5067 : : }
5068 : :
5069 : : poly_int64
5070 : 663270 : fixup_args_size_notes (rtx_insn *prev, rtx_insn *last,
5071 : : poly_int64 end_args_size)
5072 : : {
5073 : 663270 : poly_int64 args_size = end_args_size;
5074 : 663270 : bool saw_unknown = false;
5075 : 663270 : rtx_insn *insn;
5076 : :
5077 : 1894640 : for (insn = last; insn != prev; insn = PREV_INSN (insn))
5078 : : {
5079 : 1231370 : if (!NONDEBUG_INSN_P (insn))
5080 : 0 : continue;
5081 : :
5082 : : /* We might have existing REG_ARGS_SIZE notes, e.g. when pushing
5083 : : a call argument containing a TLS address that itself requires
5084 : : a call to __tls_get_addr. The handling of stack_pointer_delta
5085 : : in emit_single_push_insn is supposed to ensure that any such
5086 : : notes are already correct. */
5087 : 1231370 : rtx note = find_reg_note (insn, REG_ARGS_SIZE, NULL_RTX);
5088 : 1231370 : gcc_assert (!note || known_eq (args_size, get_args_size (note)));
5089 : :
5090 : 1231370 : poly_int64 this_delta = find_args_size_adjust (insn);
5091 : 1231370 : if (known_eq (this_delta, 0))
5092 : : {
5093 : 607869 : if (!CALL_P (insn)
5094 : 5 : || ACCUMULATE_OUTGOING_ARGS
5095 : 303942 : || find_reg_note (insn, REG_NORETURN, NULL_RTX) == NULL_RTX)
5096 : 303932 : continue;
5097 : : }
5098 : :
5099 : 927438 : gcc_assert (!saw_unknown);
5100 : 927438 : if (known_eq (this_delta, HOST_WIDE_INT_MIN))
5101 : 2379 : saw_unknown = true;
5102 : :
5103 : 927438 : if (!note)
5104 : 927438 : add_args_size_note (insn, args_size);
5105 : : if (STACK_GROWS_DOWNWARD)
5106 : 927438 : this_delta = -poly_uint64 (this_delta);
5107 : :
5108 : 927438 : if (saw_unknown)
5109 : : args_size = HOST_WIDE_INT_MIN;
5110 : : else
5111 : 1231370 : args_size -= this_delta;
5112 : : }
5113 : :
5114 : 663270 : return args_size;
5115 : : }
5116 : :
5117 : : #ifdef PUSH_ROUNDING
5118 : : /* Emit single push insn. */
5119 : :
5120 : : static void
5121 : 1831332 : emit_single_push_insn_1 (machine_mode mode, rtx x, tree type)
5122 : : {
5123 : 1831332 : rtx dest_addr;
5124 : 3662664 : poly_int64 rounded_size = PUSH_ROUNDING (GET_MODE_SIZE (mode));
5125 : 1831332 : rtx dest;
5126 : 1831332 : enum insn_code icode;
5127 : :
5128 : : /* If there is push pattern, use it. Otherwise try old way of throwing
5129 : : MEM representing push operation to move expander. */
5130 : 1831332 : icode = optab_handler (push_optab, mode);
5131 : 1831332 : if (icode != CODE_FOR_nothing)
5132 : : {
5133 : 0 : class expand_operand ops[1];
5134 : :
5135 : 0 : create_input_operand (&ops[0], x, mode);
5136 : 0 : if (maybe_expand_insn (icode, 1, ops))
5137 : 0 : return;
5138 : : }
5139 : 3662664 : if (known_eq (GET_MODE_SIZE (mode), rounded_size))
5140 : 3165652 : dest_addr = gen_rtx_fmt_e (STACK_PUSH_CODE, Pmode, stack_pointer_rtx);
5141 : : /* If we are to pad downward, adjust the stack pointer first and
5142 : : then store X into the stack location using an offset. This is
5143 : : because emit_move_insn does not know how to pad; it does not have
5144 : : access to type. */
5145 : 102527 : else if (targetm.calls.function_arg_padding (mode, type) == PAD_DOWNWARD)
5146 : : {
5147 : 0 : emit_move_insn (stack_pointer_rtx,
5148 : 0 : expand_binop (Pmode,
5149 : : STACK_GROWS_DOWNWARD ? sub_optab
5150 : : : add_optab,
5151 : : stack_pointer_rtx,
5152 : 0 : gen_int_mode (rounded_size, Pmode),
5153 : : NULL_RTX, 0, OPTAB_LIB_WIDEN));
5154 : :
5155 : 0 : poly_int64 offset = rounded_size - GET_MODE_SIZE (mode);
5156 : 0 : if (STACK_GROWS_DOWNWARD && STACK_PUSH_CODE == POST_DEC)
5157 : : /* We have already decremented the stack pointer, so get the
5158 : : previous value. */
5159 : : offset += rounded_size;
5160 : :
5161 : 0 : if (!STACK_GROWS_DOWNWARD && STACK_PUSH_CODE == POST_INC)
5162 : : /* We have already incremented the stack pointer, so get the
5163 : : previous value. */
5164 : : offset -= rounded_size;
5165 : :
5166 : 0 : dest_addr = plus_constant (Pmode, stack_pointer_rtx, offset);
5167 : : }
5168 : : else
5169 : : {
5170 : : if (STACK_GROWS_DOWNWARD)
5171 : : /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
5172 : 103129 : dest_addr = plus_constant (Pmode, stack_pointer_rtx, -rounded_size);
5173 : : else
5174 : : /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
5175 : : dest_addr = plus_constant (Pmode, stack_pointer_rtx, rounded_size);
5176 : :
5177 : 103129 : dest_addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, dest_addr);
5178 : : }
5179 : :
5180 : 1831332 : dest = gen_rtx_MEM (mode, dest_addr);
5181 : :
5182 : 1831332 : if (type != 0)
5183 : : {
5184 : 1831285 : set_mem_attributes (dest, type, 1);
5185 : :
5186 : 1831285 : if (cfun->tail_call_marked)
5187 : : /* Function incoming arguments may overlap with sibling call
5188 : : outgoing arguments and we cannot allow reordering of reads
5189 : : from function arguments with stores to outgoing arguments
5190 : : of sibling calls. */
5191 : 138659 : set_mem_alias_set (dest, 0);
5192 : : }
5193 : 1831332 : emit_move_insn (dest, x);
5194 : : }
5195 : :
5196 : : /* Emit and annotate a single push insn. */
5197 : :
5198 : : static void
5199 : 1831332 : emit_single_push_insn (machine_mode mode, rtx x, tree type)
5200 : : {
5201 : 1831332 : poly_int64 delta, old_delta = stack_pointer_delta;
5202 : 1831332 : rtx_insn *prev = get_last_insn ();
5203 : 1831332 : rtx_insn *last;
5204 : :
5205 : 1831332 : emit_single_push_insn_1 (mode, x, type);
5206 : :
5207 : : /* Adjust stack_pointer_delta to describe the situation after the push
5208 : : we just performed. Note that we must do this after the push rather
5209 : : than before the push in case calculating X needs pushes and pops of
5210 : : its own (e.g. if calling __tls_get_addr). The REG_ARGS_SIZE notes
5211 : : for such pushes and pops must not include the effect of the future
5212 : : push of X. */
5213 : 3662664 : stack_pointer_delta += PUSH_ROUNDING (GET_MODE_SIZE (mode));
5214 : :
5215 : 1831332 : last = get_last_insn ();
5216 : :
5217 : : /* Notice the common case where we emitted exactly one insn. */
5218 : 1831332 : if (PREV_INSN (last) == prev)
5219 : : {
5220 : 1722027 : add_args_size_note (last, stack_pointer_delta);
5221 : 1722027 : return;
5222 : : }
5223 : :
5224 : 109305 : delta = fixup_args_size_notes (prev, last, stack_pointer_delta);
5225 : 109305 : gcc_assert (known_eq (delta, HOST_WIDE_INT_MIN)
5226 : : || known_eq (delta, old_delta));
5227 : : }
5228 : : #endif
5229 : :
5230 : : /* If reading SIZE bytes from X will end up reading from
5231 : : Y return the number of bytes that overlap. Return -1
5232 : : if there is no overlap or -2 if we can't determine
5233 : : (for example when X and Y have different base registers). */
5234 : :
5235 : : static int
5236 : 0 : memory_load_overlap (rtx x, rtx y, HOST_WIDE_INT size)
5237 : : {
5238 : 0 : rtx tmp = plus_constant (Pmode, x, size);
5239 : 0 : rtx sub = simplify_gen_binary (MINUS, Pmode, tmp, y);
5240 : :
5241 : 0 : if (!CONST_INT_P (sub))
5242 : : return -2;
5243 : :
5244 : 0 : HOST_WIDE_INT val = INTVAL (sub);
5245 : :
5246 : 0 : return IN_RANGE (val, 1, size) ? val : -1;
5247 : : }
5248 : :
5249 : : /* Generate code to push X onto the stack, assuming it has mode MODE and
5250 : : type TYPE.
5251 : : MODE is redundant except when X is a CONST_INT (since they don't
5252 : : carry mode info).
5253 : : SIZE is an rtx for the size of data to be copied (in bytes),
5254 : : needed only if X is BLKmode.
5255 : : Return true if successful. May return false if asked to push a
5256 : : partial argument during a sibcall optimization (as specified by
5257 : : SIBCALL_P) and the incoming and outgoing pointers cannot be shown
5258 : : to not overlap.
5259 : :
5260 : : ALIGN (in bits) is maximum alignment we can assume.
5261 : :
5262 : : If PARTIAL and REG are both nonzero, then copy that many of the first
5263 : : bytes of X into registers starting with REG, and push the rest of X.
5264 : : The amount of space pushed is decreased by PARTIAL bytes.
5265 : : REG must be a hard register in this case.
5266 : : If REG is zero but PARTIAL is not, take any all others actions for an
5267 : : argument partially in registers, but do not actually load any
5268 : : registers.
5269 : :
5270 : : EXTRA is the amount in bytes of extra space to leave next to this arg.
5271 : : This is ignored if an argument block has already been allocated.
5272 : :
5273 : : On a machine that lacks real push insns, ARGS_ADDR is the address of
5274 : : the bottom of the argument block for this call. We use indexing off there
5275 : : to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
5276 : : argument block has not been preallocated.
5277 : :
5278 : : ARGS_SO_FAR is the size of args previously pushed for this call.
5279 : :
5280 : : REG_PARM_STACK_SPACE is nonzero if functions require stack space
5281 : : for arguments passed in registers. If nonzero, it will be the number
5282 : : of bytes required. */
5283 : :
5284 : : bool
5285 : 2155160 : emit_push_insn (rtx x, machine_mode mode, tree type, rtx size,
5286 : : unsigned int align, int partial, rtx reg, poly_int64 extra,
5287 : : rtx args_addr, rtx args_so_far, int reg_parm_stack_space,
5288 : : rtx alignment_pad, bool sibcall_p)
5289 : : {
5290 : 2155160 : rtx xinner;
5291 : 2155160 : pad_direction stack_direction
5292 : : = STACK_GROWS_DOWNWARD ? PAD_DOWNWARD : PAD_UPWARD;
5293 : :
5294 : : /* Decide where to pad the argument: PAD_DOWNWARD for below,
5295 : : PAD_UPWARD for above, or PAD_NONE for don't pad it.
5296 : : Default is below for small data on big-endian machines; else above. */
5297 : 2155160 : pad_direction where_pad = targetm.calls.function_arg_padding (mode, type);
5298 : :
5299 : : /* Invert direction if stack is post-decrement.
5300 : : FIXME: why? */
5301 : 2155160 : if (STACK_PUSH_CODE == POST_DEC)
5302 : : if (where_pad != PAD_NONE)
5303 : : where_pad = (where_pad == PAD_DOWNWARD ? PAD_UPWARD : PAD_DOWNWARD);
5304 : :
5305 : 2155160 : xinner = x;
5306 : :
5307 : 2155160 : int nregs = partial / UNITS_PER_WORD;
5308 : 2155160 : rtx *tmp_regs = NULL;
5309 : 2155160 : int overlapping = 0;
5310 : :
5311 : 2155160 : if (mode == BLKmode
5312 : : || (STRICT_ALIGNMENT && align < GET_MODE_ALIGNMENT (mode)))
5313 : : {
5314 : : /* Copy a block into the stack, entirely or partially. */
5315 : :
5316 : 268801 : rtx temp;
5317 : 268801 : int used;
5318 : 268801 : int offset;
5319 : 268801 : int skip;
5320 : :
5321 : 268801 : offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
5322 : 268801 : used = partial - offset;
5323 : :
5324 : 268801 : if (mode != BLKmode)
5325 : : {
5326 : : /* A value is to be stored in an insufficiently aligned
5327 : : stack slot; copy via a suitably aligned slot if
5328 : : necessary. */
5329 : : size = gen_int_mode (GET_MODE_SIZE (mode), Pmode);
5330 : : if (!MEM_P (xinner))
5331 : : {
5332 : : temp = assign_temp (type, 1, 1);
5333 : : emit_move_insn (temp, xinner);
5334 : : xinner = temp;
5335 : : }
5336 : : }
5337 : :
5338 : 268801 : gcc_assert (size);
5339 : :
5340 : : /* USED is now the # of bytes we need not copy to the stack
5341 : : because registers will take care of them. */
5342 : :
5343 : 268801 : if (partial != 0)
5344 : 0 : xinner = adjust_address (xinner, BLKmode, used);
5345 : :
5346 : : /* If the partial register-part of the arg counts in its stack size,
5347 : : skip the part of stack space corresponding to the registers.
5348 : : Otherwise, start copying to the beginning of the stack space,
5349 : : by setting SKIP to 0. */
5350 : 268801 : skip = (reg_parm_stack_space == 0) ? 0 : used;
5351 : :
5352 : : #ifdef PUSH_ROUNDING
5353 : : /* NB: Let the backend known the number of bytes to push and
5354 : : decide if push insns should be generated. */
5355 : 268801 : unsigned int push_size;
5356 : 268801 : if (CONST_INT_P (size))
5357 : 268801 : push_size = INTVAL (size);
5358 : : else
5359 : : push_size = 0;
5360 : :
5361 : : /* Do it with several push insns if that doesn't take lots of insns
5362 : : and if there is no difficulty with push insns that skip bytes
5363 : : on the stack for alignment purposes. */
5364 : 268801 : if (args_addr == 0
5365 : 268738 : && targetm.calls.push_argument (push_size)
5366 : 3786 : && CONST_INT_P (size)
5367 : 3786 : && skip == 0
5368 : 3786 : && MEM_ALIGN (xinner) >= align
5369 : 2947 : && can_move_by_pieces ((unsigned) INTVAL (size) - used, align)
5370 : : /* Here we avoid the case of a structure whose weak alignment
5371 : : forces many pushes of a small amount of data,
5372 : : and such small pushes do rounding that causes trouble. */
5373 : 2947 : && ((!targetm.slow_unaligned_access (word_mode, align))
5374 : 0 : || align >= BIGGEST_ALIGNMENT
5375 : 0 : || known_eq (PUSH_ROUNDING (align / BITS_PER_UNIT),
5376 : : align / BITS_PER_UNIT))
5377 : 271748 : && known_eq (PUSH_ROUNDING (INTVAL (size)), INTVAL (size)))
5378 : : {
5379 : : /* Push padding now if padding above and stack grows down,
5380 : : or if padding below and stack grows up.
5381 : : But if space already allocated, this has already been done. */
5382 : 45 : if (maybe_ne (extra, 0)
5383 : : && args_addr == 0
5384 : 0 : && where_pad != PAD_NONE
5385 : 45 : && where_pad != stack_direction)
5386 : 0 : anti_adjust_stack (gen_int_mode (extra, Pmode));
5387 : :
5388 : 45 : move_by_pieces (NULL, xinner, INTVAL (size) - used, align,
5389 : : RETURN_BEGIN);
5390 : : }
5391 : : else
5392 : : #endif /* PUSH_ROUNDING */
5393 : : {
5394 : 268756 : rtx target;
5395 : :
5396 : : /* Otherwise make space on the stack and copy the data
5397 : : to the address of that space. */
5398 : :
5399 : : /* Deduct words put into registers from the size we must copy. */
5400 : 268756 : if (partial != 0)
5401 : : {
5402 : 0 : if (CONST_INT_P (size))
5403 : 0 : size = GEN_INT (INTVAL (size) - used);
5404 : : else
5405 : 0 : size = expand_binop (GET_MODE (size), sub_optab, size,
5406 : 0 : gen_int_mode (used, GET_MODE (size)),
5407 : : NULL_RTX, 0, OPTAB_LIB_WIDEN);
5408 : : }
5409 : :
5410 : : /* Get the address of the stack space.
5411 : : In this case, we do not deal with EXTRA separately.
5412 : : A single stack adjust will do. */
5413 : 268756 : poly_int64 const_args_so_far;
5414 : 268756 : if (! args_addr)
5415 : : {
5416 : 268693 : temp = push_block (size, extra, where_pad == PAD_DOWNWARD);
5417 : 268693 : extra = 0;
5418 : : }
5419 : 63 : else if (poly_int_rtx_p (args_so_far, &const_args_so_far))
5420 : 81 : temp = memory_address (BLKmode,
5421 : : plus_constant (Pmode, args_addr,
5422 : : skip + const_args_so_far));
5423 : : else
5424 : 0 : temp = memory_address (BLKmode,
5425 : : plus_constant (Pmode,
5426 : : gen_rtx_PLUS (Pmode,
5427 : : args_addr,
5428 : : args_so_far),
5429 : : skip));
5430 : :
5431 : 268756 : if (!ACCUMULATE_OUTGOING_ARGS)
5432 : : {
5433 : : /* If the source is referenced relative to the stack pointer,
5434 : : copy it to another register to stabilize it. We do not need
5435 : : to do this if we know that we won't be changing sp. */
5436 : :
5437 : 268756 : if (reg_mentioned_p (virtual_stack_dynamic_rtx, temp)
5438 : 268756 : || reg_mentioned_p (virtual_outgoing_args_rtx, temp))
5439 : 268693 : temp = copy_to_reg (temp);
5440 : : }
5441 : :
5442 : 268756 : target = gen_rtx_MEM (BLKmode, temp);
5443 : :
5444 : : /* We do *not* set_mem_attributes here, because incoming arguments
5445 : : may overlap with sibling call outgoing arguments and we cannot
5446 : : allow reordering of reads from function arguments with stores
5447 : : to outgoing arguments of sibling calls. We do, however, want
5448 : : to record the alignment of the stack slot. */
5449 : : /* ALIGN may well be better aligned than TYPE, e.g. due to
5450 : : PARM_BOUNDARY. Assume the caller isn't lying. */
5451 : 268756 : set_mem_align (target, align);
5452 : :
5453 : : /* If part should go in registers and pushing to that part would
5454 : : overwrite some of the values that need to go into regs, load the
5455 : : overlapping values into temporary pseudos to be moved into the hard
5456 : : regs at the end after the stack pushing has completed.
5457 : : We cannot load them directly into the hard regs here because
5458 : : they can be clobbered by the block move expansions.
5459 : : See PR 65358. */
5460 : :
5461 : 268756 : if (partial > 0 && reg != 0 && mode == BLKmode
5462 : 0 : && GET_CODE (reg) != PARALLEL)
5463 : : {
5464 : 0 : overlapping = memory_load_overlap (XEXP (x, 0), temp, partial);
5465 : 0 : if (overlapping > 0)
5466 : : {
5467 : 0 : gcc_assert (overlapping % UNITS_PER_WORD == 0);
5468 : 0 : overlapping /= UNITS_PER_WORD;
5469 : :
5470 : 0 : tmp_regs = XALLOCAVEC (rtx, overlapping);
5471 : :
5472 : 0 : for (int i = 0; i < overlapping; i++)
5473 : 0 : tmp_regs[i] = gen_reg_rtx (word_mode);
5474 : :
5475 : 0 : for (int i = 0; i < overlapping; i++)
5476 : 0 : emit_move_insn (tmp_regs[i],
5477 : 0 : operand_subword_force (target, i, mode));
5478 : : }
5479 : 0 : else if (overlapping == -1)
5480 : : overlapping = 0;
5481 : : /* Could not determine whether there is overlap.
5482 : : Fail the sibcall. */
5483 : : else
5484 : : {
5485 : 0 : overlapping = 0;
5486 : 0 : if (sibcall_p)
5487 : 0 : return false;
5488 : : }
5489 : : }
5490 : :
5491 : : /* If source is a constant VAR_DECL with a simple constructor,
5492 : : store the constructor to the stack instead of moving it. */
5493 : 268756 : const_tree decl;
5494 : 268756 : HOST_WIDE_INT sz;
5495 : 268756 : if (partial == 0
5496 : 268756 : && MEM_P (xinner)
5497 : 268756 : && SYMBOL_REF_P (XEXP (xinner, 0))
5498 : 81877 : && (decl = SYMBOL_REF_DECL (XEXP (xinner, 0))) != NULL_TREE
5499 : 81877 : && VAR_P (decl)
5500 : 81877 : && TREE_READONLY (decl)
5501 : 4500 : && !TREE_SIDE_EFFECTS (decl)
5502 : 4500 : && immediate_const_ctor_p (DECL_INITIAL (decl), 2)
5503 : 6 : && (sz = int_expr_size (DECL_INITIAL (decl))) > 0
5504 : 6 : && CONST_INT_P (size)
5505 : 268762 : && INTVAL (size) == sz)
5506 : 0 : store_constructor (DECL_INITIAL (decl), target, 0, sz, false);
5507 : : else
5508 : 268756 : emit_block_move (target, xinner, size, BLOCK_OP_CALL_PARM);
5509 : : }
5510 : : }
5511 : 1886359 : else if (partial > 0)
5512 : : {
5513 : : /* Scalar partly in registers. This case is only supported
5514 : : for fixed-wdth modes. */
5515 : 0 : int num_words = GET_MODE_SIZE (mode).to_constant ();
5516 : 0 : num_words /= UNITS_PER_WORD;
5517 : 0 : int i;
5518 : 0 : int not_stack;
5519 : : /* # bytes of start of argument
5520 : : that we must make space for but need not store. */
5521 : 0 : int offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
5522 : 0 : int args_offset = INTVAL (args_so_far);
5523 : 0 : int skip;
5524 : :
5525 : : /* Push padding now if padding above and stack grows down,
5526 : : or if padding below and stack grows up.
5527 : : But if space already allocated, this has already been done. */
5528 : 0 : if (maybe_ne (extra, 0)
5529 : 0 : && args_addr == 0
5530 : 0 : && where_pad != PAD_NONE
5531 : 0 : && where_pad != stack_direction)
5532 : 0 : anti_adjust_stack (gen_int_mode (extra, Pmode));
5533 : :
5534 : : /* If we make space by pushing it, we might as well push
5535 : : the real data. Otherwise, we can leave OFFSET nonzero
5536 : : and leave the space uninitialized. */
5537 : 0 : if (args_addr == 0)
5538 : 0 : offset = 0;
5539 : :
5540 : : /* Now NOT_STACK gets the number of words that we don't need to
5541 : : allocate on the stack. Convert OFFSET to words too. */
5542 : 0 : not_stack = (partial - offset) / UNITS_PER_WORD;
5543 : 0 : offset /= UNITS_PER_WORD;
5544 : :
5545 : : /* If the partial register-part of the arg counts in its stack size,
5546 : : skip the part of stack space corresponding to the registers.
5547 : : Otherwise, start copying to the beginning of the stack space,
5548 : : by setting SKIP to 0. */
5549 : 0 : skip = (reg_parm_stack_space == 0) ? 0 : not_stack;
5550 : :
5551 : 0 : if (CONSTANT_P (x) && !targetm.legitimate_constant_p (mode, x))
5552 : 0 : x = validize_mem (force_const_mem (mode, x));
5553 : :
5554 : : /* If X is a hard register in a non-integer mode, copy it into a pseudo;
5555 : : SUBREGs of such registers are not allowed. */
5556 : 0 : if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER
5557 : 0 : && GET_MODE_CLASS (GET_MODE (x)) != MODE_INT))
5558 : 0 : x = copy_to_reg (x);
5559 : :
5560 : : /* Loop over all the words allocated on the stack for this arg. */
5561 : : /* We can do it by words, because any scalar bigger than a word
5562 : : has a size a multiple of a word. */
5563 : 0 : tree word_mode_type = lang_hooks.types.type_for_mode (word_mode, 1);
5564 : 0 : for (i = num_words - 1; i >= not_stack; i--)
5565 : 0 : if (i >= not_stack + offset)
5566 : 0 : if (!emit_push_insn (operand_subword_force (x, i, mode),
5567 : : word_mode, word_mode_type, NULL_RTX, align, 0,
5568 : : NULL_RTX, 0, args_addr,
5569 : 0 : GEN_INT (args_offset + ((i - not_stack + skip)
5570 : : * UNITS_PER_WORD)),
5571 : : reg_parm_stack_space, alignment_pad, sibcall_p))
5572 : 0 : return false;
5573 : : }
5574 : : else
5575 : : {
5576 : 1886359 : rtx addr;
5577 : 1886359 : rtx dest;
5578 : :
5579 : : /* Push padding now if padding above and stack grows down,
5580 : : or if padding below and stack grows up.
5581 : : But if space already allocated, this has already been done. */
5582 : 1886359 : if (maybe_ne (extra, 0)
5583 : 0 : && args_addr == 0
5584 : 0 : && where_pad != PAD_NONE
5585 : 1886359 : && where_pad != stack_direction)
5586 : 0 : anti_adjust_stack (gen_int_mode (extra, Pmode));
5587 : :
5588 : : #ifdef PUSH_ROUNDING
5589 : 1886359 : if (args_addr == 0 && targetm.calls.push_argument (0))
5590 : 1831285 : emit_single_push_insn (mode, x, type);
5591 : : else
5592 : : #endif
5593 : : {
5594 : 63055 : addr = simplify_gen_binary (PLUS, Pmode, args_addr, args_so_far);
5595 : 55074 : dest = gen_rtx_MEM (mode, memory_address (mode, addr));
5596 : :
5597 : : /* We do *not* set_mem_attributes here, because incoming arguments
5598 : : may overlap with sibling call outgoing arguments and we cannot
5599 : : allow reordering of reads from function arguments with stores
5600 : : to outgoing arguments of sibling calls. We do, however, want
5601 : : to record the alignment of the stack slot. */
5602 : : /* ALIGN may well be better aligned than TYPE, e.g. due to
5603 : : PARM_BOUNDARY. Assume the caller isn't lying. */
5604 : 55074 : set_mem_align (dest, align);
5605 : :
5606 : 55074 : emit_move_insn (dest, x);
5607 : : }
5608 : : }
5609 : :
5610 : : /* Move the partial arguments into the registers and any overlapping
5611 : : values that we moved into the pseudos in tmp_regs. */
5612 : 2155160 : if (partial > 0 && reg != 0)
5613 : : {
5614 : : /* Handle calls that pass values in multiple non-contiguous locations.
5615 : : The Irix 6 ABI has examples of this. */
5616 : 0 : if (GET_CODE (reg) == PARALLEL)
5617 : 0 : emit_group_load (reg, x, type, -1);
5618 : : else
5619 : : {
5620 : 0 : gcc_assert (partial % UNITS_PER_WORD == 0);
5621 : 0 : move_block_to_reg (REGNO (reg), x, nregs - overlapping, mode);
5622 : :
5623 : 0 : for (int i = 0; i < overlapping; i++)
5624 : 0 : emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg)
5625 : 0 : + nregs - overlapping + i),
5626 : 0 : tmp_regs[i]);
5627 : :
5628 : : }
5629 : : }
5630 : :
5631 : 2155160 : if (maybe_ne (extra, 0) && args_addr == 0 && where_pad == stack_direction)
5632 : 0 : anti_adjust_stack (gen_int_mode (extra, Pmode));
5633 : :
5634 : 2155160 : if (alignment_pad && args_addr == 0)
5635 : 2100023 : anti_adjust_stack (alignment_pad);
5636 : :
5637 : : return true;
5638 : : }
5639 : :
5640 : : /* Return X if X can be used as a subtarget in a sequence of arithmetic
5641 : : operations. */
5642 : :
5643 : : static rtx
5644 : 200355000 : get_subtarget (rtx x)
5645 : : {
5646 : 200355000 : return (optimize
5647 : 51612037 : || x == 0
5648 : : /* Only registers can be subtargets. */
5649 : 17305516 : || !REG_P (x)
5650 : : /* Don't use hard regs to avoid extending their life. */
5651 : 11729490 : || REGNO (x) < FIRST_PSEUDO_REGISTER
5652 : 200355000 : ? 0 : x);
5653 : : }
5654 : :
5655 : : /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
5656 : : FIELD is a bitfield. Returns true if the optimization was successful,
5657 : : and there's nothing else to do. */
5658 : :
5659 : : static bool
5660 : 4736851 : optimize_bitfield_assignment_op (poly_uint64 pbitsize,
5661 : : poly_uint64 pbitpos,
5662 : : poly_uint64 pbitregion_start,
5663 : : poly_uint64 pbitregion_end,
5664 : : machine_mode mode1, rtx str_rtx,
5665 : : tree to, tree src, bool reverse)
5666 : : {
5667 : : /* str_mode is not guaranteed to be a scalar type. */
5668 : 4736851 : machine_mode str_mode = GET_MODE (str_rtx);
5669 : 4736851 : unsigned int str_bitsize;
5670 : 4736851 : tree op0, op1;
5671 : 4736851 : rtx value, result;
5672 : 4736851 : optab binop;
5673 : 4736851 : gimple *srcstmt;
5674 : 4736851 : enum tree_code code;
5675 : :
5676 : 4736851 : unsigned HOST_WIDE_INT bitsize, bitpos, bitregion_start, bitregion_end;
5677 : 4736851 : if (mode1 != VOIDmode
5678 : 71339 : || !pbitsize.is_constant (&bitsize)
5679 : 71339 : || !pbitpos.is_constant (&bitpos)
5680 : 71339 : || !pbitregion_start.is_constant (&bitregion_start)
5681 : 71339 : || !pbitregion_end.is_constant (&bitregion_end)
5682 : 71917 : || bitsize >= BITS_PER_WORD
5683 : 71070 : || !GET_MODE_BITSIZE (str_mode).is_constant (&str_bitsize)
5684 : 71648 : || str_bitsize > BITS_PER_WORD
5685 : 65677 : || TREE_SIDE_EFFECTS (to)
5686 : 4802399 : || TREE_THIS_VOLATILE (to))
5687 : : return false;
5688 : :
5689 : 65548 : STRIP_NOPS (src);
5690 : 65548 : if (TREE_CODE (src) != SSA_NAME)
5691 : : return false;
5692 : 23427 : if (TREE_CODE (TREE_TYPE (src)) != INTEGER_TYPE)
5693 : : return false;
5694 : :
5695 : 21276 : srcstmt = get_gimple_for_ssa_name (src);
5696 : 21276 : if (!srcstmt
5697 : 4614 : || !is_gimple_assign (srcstmt)
5698 : 25890 : || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt)) != tcc_binary)
5699 : : return false;
5700 : :
5701 : 788 : code = gimple_assign_rhs_code (srcstmt);
5702 : :
5703 : 788 : op0 = gimple_assign_rhs1 (srcstmt);
5704 : :
5705 : : /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
5706 : : to find its initialization. Hopefully the initialization will
5707 : : be from a bitfield load. */
5708 : 788 : if (TREE_CODE (op0) == SSA_NAME)
5709 : : {
5710 : 788 : gimple *op0stmt = get_gimple_for_ssa_name (op0);
5711 : :
5712 : : /* We want to eventually have OP0 be the same as TO, which
5713 : : should be a bitfield. */
5714 : 788 : if (!op0stmt
5715 : 729 : || !is_gimple_assign (op0stmt)
5716 : 1517 : || gimple_assign_rhs_code (op0stmt) != TREE_CODE (to))
5717 : : return false;
5718 : 407 : op0 = gimple_assign_rhs1 (op0stmt);
5719 : : }
5720 : :
5721 : 407 : op1 = gimple_assign_rhs2 (srcstmt);
5722 : :
5723 : 407 : if (!operand_equal_p (to, op0, 0))
5724 : : return false;
5725 : :
5726 : 347 : if (MEM_P (str_rtx))
5727 : : {
5728 : 342 : unsigned HOST_WIDE_INT offset1;
5729 : :
5730 : 342 : if (str_bitsize == 0 || str_bitsize > BITS_PER_WORD)
5731 : 122 : str_bitsize = BITS_PER_WORD;
5732 : :
5733 : 342 : scalar_int_mode best_mode;
5734 : 342 : if (!get_best_mode (bitsize, bitpos, bitregion_start, bitregion_end,
5735 : 342 : MEM_ALIGN (str_rtx), str_bitsize, false, &best_mode))
5736 : 0 : return false;
5737 : 342 : str_mode = best_mode;
5738 : 342 : str_bitsize = GET_MODE_BITSIZE (best_mode);
5739 : :
5740 : 342 : offset1 = bitpos;
5741 : 342 : bitpos %= str_bitsize;
5742 : 342 : offset1 = (offset1 - bitpos) / BITS_PER_UNIT;
5743 : 342 : str_rtx = adjust_address (str_rtx, str_mode, offset1);
5744 : : }
5745 : 5 : else if (!REG_P (str_rtx) && GET_CODE (str_rtx) != SUBREG)
5746 : : return false;
5747 : :
5748 : : /* If the bit field covers the whole REG/MEM, store_field
5749 : : will likely generate better code. */
5750 : 347 : if (bitsize >= str_bitsize)
5751 : : return false;
5752 : :
5753 : : /* We can't handle fields split across multiple entities. */
5754 : 347 : if (bitpos + bitsize > str_bitsize)
5755 : : return false;
5756 : :
5757 : 347 : if (reverse ? !BYTES_BIG_ENDIAN : BYTES_BIG_ENDIAN)
5758 : 0 : bitpos = str_bitsize - bitpos - bitsize;
5759 : :
5760 : 347 : switch (code)
5761 : : {
5762 : 141 : case PLUS_EXPR:
5763 : 141 : case MINUS_EXPR:
5764 : : /* For now, just optimize the case of the topmost bitfield
5765 : : where we don't need to do any masking and also
5766 : : 1 bit bitfields where xor can be used.
5767 : : We might win by one instruction for the other bitfields
5768 : : too if insv/extv instructions aren't used, so that
5769 : : can be added later. */
5770 : 141 : if ((reverse || bitpos + bitsize != str_bitsize)
5771 : 97 : && (bitsize != 1 || TREE_CODE (op1) != INTEGER_CST))
5772 : : break;
5773 : :
5774 : 70 : value = expand_expr (op1, NULL_RTX, str_mode, EXPAND_NORMAL);
5775 : 70 : value = convert_modes (str_mode,
5776 : 70 : TYPE_MODE (TREE_TYPE (op1)), value,
5777 : 70 : TYPE_UNSIGNED (TREE_TYPE (op1)));
5778 : :
5779 : : /* We may be accessing data outside the field, which means
5780 : : we can alias adjacent data. */
5781 : 70 : if (MEM_P (str_rtx))
5782 : : {
5783 : 70 : str_rtx = shallow_copy_rtx (str_rtx);
5784 : 70 : set_mem_alias_set (str_rtx, 0);
5785 : 70 : set_mem_expr (str_rtx, 0);
5786 : : }
5787 : :
5788 : 70 : if (bitsize == 1 && (reverse || bitpos + bitsize != str_bitsize))
5789 : : {
5790 : 26 : value = expand_and (str_mode, value, const1_rtx, NULL);
5791 : 26 : binop = xor_optab;
5792 : : }
5793 : : else
5794 : 44 : binop = code == PLUS_EXPR ? add_optab : sub_optab;
5795 : :
5796 : 70 : value = expand_shift (LSHIFT_EXPR, str_mode, value, bitpos, NULL_RTX, 1);
5797 : 70 : if (reverse)
5798 : 0 : value = flip_storage_order (str_mode, value);
5799 : 70 : result = expand_binop (str_mode, binop, str_rtx,
5800 : : value, str_rtx, 1, OPTAB_WIDEN);
5801 : 70 : if (result != str_rtx)
5802 : 0 : emit_move_insn (str_rtx, result);
5803 : : return true;
5804 : :
5805 : 176 : case BIT_IOR_EXPR:
5806 : 176 : case BIT_XOR_EXPR:
5807 : 176 : if (TREE_CODE (op1) != INTEGER_CST)
5808 : : break;
5809 : 55 : value = expand_expr (op1, NULL_RTX, str_mode, EXPAND_NORMAL);
5810 : 55 : value = convert_modes (str_mode,
5811 : 55 : TYPE_MODE (TREE_TYPE (op1)), value,
5812 : 55 : TYPE_UNSIGNED (TREE_TYPE (op1)));
5813 : :
5814 : : /* We may be accessing data outside the field, which means
5815 : : we can alias adjacent data. */
5816 : 55 : if (MEM_P (str_rtx))
5817 : : {
5818 : 55 : str_rtx = shallow_copy_rtx (str_rtx);
5819 : 55 : set_mem_alias_set (str_rtx, 0);
5820 : 55 : set_mem_expr (str_rtx, 0);
5821 : : }
5822 : :
5823 : 55 : binop = code == BIT_IOR_EXPR ? ior_optab : xor_optab;
5824 : 55 : if (bitpos + bitsize != str_bitsize)
5825 : : {
5826 : 31 : rtx mask = gen_int_mode ((HOST_WIDE_INT_1U << bitsize) - 1,
5827 : : str_mode);
5828 : 31 : value = expand_and (str_mode, value, mask, NULL_RTX);
5829 : : }
5830 : 55 : value = expand_shift (LSHIFT_EXPR, str_mode, value, bitpos, NULL_RTX, 1);
5831 : 55 : if (reverse)
5832 : 0 : value = flip_storage_order (str_mode, value);
5833 : 55 : result = expand_binop (str_mode, binop, str_rtx,
5834 : : value, str_rtx, 1, OPTAB_WIDEN);
5835 : 55 : if (result != str_rtx)
5836 : 0 : emit_move_insn (str_rtx, result);
5837 : : return true;
5838 : :
5839 : : default:
5840 : : break;
5841 : : }
5842 : :
5843 : : return false;
5844 : : }
5845 : :
5846 : : /* In the C++ memory model, consecutive bit fields in a structure are
5847 : : considered one memory location.
5848 : :
5849 : : Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
5850 : : returns the bit range of consecutive bits in which this COMPONENT_REF
5851 : : belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
5852 : : and *OFFSET may be adjusted in the process.
5853 : :
5854 : : If the access does not need to be restricted, 0 is returned in both
5855 : : *BITSTART and *BITEND. */
5856 : :
5857 : : void
5858 : 932132 : get_bit_range (poly_uint64 *bitstart, poly_uint64 *bitend, tree exp,
5859 : : poly_int64 *bitpos, tree *offset)
5860 : : {
5861 : 932132 : poly_int64 bitoffset;
5862 : 932132 : tree field, repr;
5863 : :
5864 : 932132 : gcc_assert (TREE_CODE (exp) == COMPONENT_REF);
5865 : :
5866 : 932132 : field = TREE_OPERAND (exp, 1);
5867 : 932132 : repr = DECL_BIT_FIELD_REPRESENTATIVE (field);
5868 : : /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
5869 : : need to limit the range we can access. */
5870 : 932132 : if (!repr)
5871 : : {
5872 : 65 : *bitstart = *bitend = 0;
5873 : 65 : return;
5874 : : }
5875 : :
5876 : : /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
5877 : : part of a larger bit field, then the representative does not serve any
5878 : : useful purpose. This can occur in Ada. */
5879 : 932067 : if (handled_component_p (TREE_OPERAND (exp, 0)))
5880 : : {
5881 : 695505 : machine_mode rmode;
5882 : 695505 : poly_int64 rbitsize, rbitpos;
5883 : 695505 : tree roffset;
5884 : 695505 : int unsignedp, reversep, volatilep = 0;
5885 : 695505 : get_inner_reference (TREE_OPERAND (exp, 0), &rbitsize, &rbitpos,
5886 : : &roffset, &rmode, &unsignedp, &reversep,
5887 : : &volatilep);
5888 : 1391010 : if (!multiple_p (rbitpos, BITS_PER_UNIT))
5889 : : {
5890 : 0 : *bitstart = *bitend = 0;
5891 : 0 : return;
5892 : : }
5893 : : }
5894 : :
5895 : : /* Compute the adjustment to bitpos from the offset of the field
5896 : : relative to the representative. DECL_FIELD_OFFSET of field and
5897 : : repr are the same by construction if they are not constants,
5898 : : see finish_bitfield_layout. */
5899 : 932067 : poly_uint64 field_offset, repr_offset;
5900 : 932067 : if (poly_int_tree_p (DECL_FIELD_OFFSET (field), &field_offset)
5901 : 1864129 : && poly_int_tree_p (DECL_FIELD_OFFSET (repr), &repr_offset))
5902 : 932062 : bitoffset = (field_offset - repr_offset) * BITS_PER_UNIT;
5903 : : else
5904 : : bitoffset = 0;
5905 : 932067 : bitoffset += (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field))
5906 : 932067 : - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr)));
5907 : :
5908 : : /* If the adjustment is larger than bitpos, we would have a negative bit
5909 : : position for the lower bound and this may wreak havoc later. Adjust
5910 : : offset and bitpos to make the lower bound non-negative in that case. */
5911 : 932067 : if (maybe_gt (bitoffset, *bitpos))
5912 : : {
5913 : 9 : poly_int64 adjust_bits = upper_bound (bitoffset, *bitpos) - *bitpos;
5914 : 9 : poly_int64 adjust_bytes = exact_div (adjust_bits, BITS_PER_UNIT);
5915 : :
5916 : 9 : *bitpos += adjust_bits;
5917 : 9 : if (*offset == NULL_TREE)
5918 : 5 : *offset = size_int (-adjust_bytes);
5919 : : else
5920 : 4 : *offset = size_binop (MINUS_EXPR, *offset, size_int (adjust_bytes));
5921 : 9 : *bitstart = 0;
5922 : : }
5923 : : else
5924 : 932058 : *bitstart = *bitpos - bitoffset;
5925 : :
5926 : 932067 : *bitend = *bitstart + tree_to_poly_uint64 (DECL_SIZE (repr)) - 1;
5927 : : }
5928 : :
5929 : : /* Returns true if BASE is a DECL that does not reside in memory and
5930 : : has non-BLKmode. DECL_RTL must not be a MEM; if
5931 : : DECL_RTL was not set yet, return false. */
5932 : :
5933 : : bool
5934 : 5425536 : non_mem_decl_p (tree base)
5935 : : {
5936 : 5425536 : if (!DECL_P (base)
5937 : 5425182 : || TREE_ADDRESSABLE (base)
5938 : 7920954 : || DECL_MODE (base) == BLKmode)
5939 : : return false;
5940 : :
5941 : 1608864 : if (!DECL_RTL_SET_P (base))
5942 : : return false;
5943 : :
5944 : 1491151 : return (!MEM_P (DECL_RTL (base)));
5945 : : }
5946 : :
5947 : : /* Returns true if REF refers to an object that does not
5948 : : reside in memory and has non-BLKmode. */
5949 : :
5950 : : bool
5951 : 11807872 : mem_ref_refers_to_non_mem_p (tree ref)
5952 : : {
5953 : 11807872 : tree base;
5954 : :
5955 : 11807872 : if (TREE_CODE (ref) == MEM_REF
5956 : 11807872 : || TREE_CODE (ref) == TARGET_MEM_REF)
5957 : : {
5958 : 10266623 : tree addr = TREE_OPERAND (ref, 0);
5959 : :
5960 : 10266623 : if (TREE_CODE (addr) != ADDR_EXPR)
5961 : : return false;
5962 : :
5963 : 3855459 : base = TREE_OPERAND (addr, 0);
5964 : : }
5965 : : else
5966 : : base = ref;
5967 : :
5968 : 5396708 : return non_mem_decl_p (base);
5969 : : }
5970 : :
5971 : : /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
5972 : : is true, try generating a nontemporal store. */
5973 : :
5974 : : void
5975 : 18366099 : expand_assignment (tree to, tree from, bool nontemporal)
5976 : : {
5977 : 18366099 : rtx to_rtx = 0;
5978 : 18366099 : rtx result;
5979 : 18366099 : machine_mode mode;
5980 : 18366099 : unsigned int align;
5981 : 18366099 : enum insn_code icode;
5982 : :
5983 : : /* Don't crash if the lhs of the assignment was erroneous. */
5984 : 18366099 : if (TREE_CODE (to) == ERROR_MARK)
5985 : : {
5986 : 0 : expand_normal (from);
5987 : 0 : return;
5988 : : }
5989 : :
5990 : : /* Optimize away no-op moves without side-effects. */
5991 : 18366099 : if (operand_equal_p (to, from, 0))
5992 : : return;
5993 : :
5994 : : /* Handle misaligned stores. */
5995 : 18365951 : mode = TYPE_MODE (TREE_TYPE (to));
5996 : 18365951 : if ((TREE_CODE (to) == MEM_REF
5997 : 18365951 : || TREE_CODE (to) == TARGET_MEM_REF
5998 : 16199469 : || DECL_P (to))
5999 : 4036524 : && mode != BLKmode
6000 : 3567220 : && !mem_ref_refers_to_non_mem_p (to)
6001 : 6348676 : && ((align = get_object_alignment (to))
6002 : 3174338 : < GET_MODE_ALIGNMENT (mode))
6003 : 18792241 : && (((icode = optab_handler (movmisalign_optab, mode))
6004 : : != CODE_FOR_nothing)
6005 : 96403 : || targetm.slow_unaligned_access (mode, align)))
6006 : : {
6007 : 329887 : rtx reg, mem;
6008 : :
6009 : 329887 : reg = expand_expr (from, NULL_RTX, VOIDmode, EXPAND_NORMAL);
6010 : : /* Handle PARALLEL. */
6011 : 329887 : reg = maybe_emit_group_store (reg, TREE_TYPE (from));
6012 : 329887 : reg = force_not_mem (reg);
6013 : 329887 : mem = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
6014 : 329887 : if (TREE_CODE (to) == MEM_REF && REF_REVERSE_STORAGE_ORDER (to))
6015 : 0 : reg = flip_storage_order (mode, reg);
6016 : :
6017 : 329887 : if (icode != CODE_FOR_nothing)
6018 : : {
6019 : 329887 : class expand_operand ops[2];
6020 : :
6021 : 329887 : create_fixed_operand (&ops[0], mem);
6022 : 329887 : create_input_operand (&ops[1], reg, mode);
6023 : : /* The movmisalign<mode> pattern cannot fail, else the assignment
6024 : : would silently be omitted. */
6025 : 329887 : expand_insn (icode, 2, ops);
6026 : : }
6027 : : else
6028 : 0 : store_bit_field (mem, GET_MODE_BITSIZE (mode), 0, 0, 0, mode, reg,
6029 : : false, false);
6030 : 329887 : return;
6031 : : }
6032 : :
6033 : : /* Assignment of a structure component needs special treatment
6034 : : if the structure component's rtx is not simply a MEM.
6035 : : Assignment of an array element at a constant index, and assignment of
6036 : : an array element in an unaligned packed structure field, has the same
6037 : : problem. Same for (partially) storing into a non-memory object. */
6038 : 18036064 : if (handled_component_p (to)
6039 : 13534718 : || (TREE_CODE (to) == MEM_REF
6040 : 1600327 : && (REF_REVERSE_STORAGE_ORDER (to)
6041 : 1600311 : || mem_ref_refers_to_non_mem_p (to)))
6042 : 13420371 : || TREE_CODE (TREE_TYPE (to)) == ARRAY_TYPE)
6043 : : {
6044 : 4737013 : machine_mode mode1;
6045 : 4737013 : poly_int64 bitsize, bitpos;
6046 : 4737013 : poly_uint64 bitregion_start = 0;
6047 : 4737013 : poly_uint64 bitregion_end = 0;
6048 : 4737013 : tree offset;
6049 : 4737013 : int unsignedp, reversep, volatilep = 0;
6050 : 4737013 : tree tem;
6051 : :
6052 : 4737013 : push_temp_slots ();
6053 : 4737013 : tem = get_inner_reference (to, &bitsize, &bitpos, &offset, &mode1,
6054 : : &unsignedp, &reversep, &volatilep);
6055 : :
6056 : : /* Make sure bitpos is not negative, it can wreak havoc later. */
6057 : 4737013 : if (maybe_lt (bitpos, 0))
6058 : : {
6059 : 222 : gcc_assert (offset == NULL_TREE);
6060 : 222 : offset = size_int (bits_to_bytes_round_down (bitpos));
6061 : 222 : bitpos = num_trailing_bits (bitpos);
6062 : : }
6063 : :
6064 : 4737013 : if (TREE_CODE (to) == COMPONENT_REF
6065 : 4737013 : && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to, 1)))
6066 : 89892 : get_bit_range (&bitregion_start, &bitregion_end, to, &bitpos, &offset);
6067 : : /* The C++ memory model naturally applies to byte-aligned fields.
6068 : : However, if we do not have a DECL_BIT_FIELD_TYPE but BITPOS or
6069 : : BITSIZE are not byte-aligned, there is no need to limit the range
6070 : : we can access. This can occur with packed structures in Ada. */
6071 : 4647121 : else if (maybe_gt (bitsize, 0)
6072 : 4647106 : && multiple_p (bitsize, BITS_PER_UNIT)
6073 : 9293968 : && multiple_p (bitpos, BITS_PER_UNIT))
6074 : : {
6075 : 4646847 : bitregion_start = bitpos;
6076 : 4646847 : bitregion_end = bitpos + bitsize - 1;
6077 : : }
6078 : :
6079 : 4737013 : to_rtx = expand_expr (tem, NULL_RTX, VOIDmode, EXPAND_WRITE);
6080 : :
6081 : : /* If the field has a mode, we want to access it in the
6082 : : field's mode, not the computed mode.
6083 : : If a MEM has VOIDmode (external with incomplete type),
6084 : : use BLKmode for it instead. */
6085 : 4737013 : if (MEM_P (to_rtx))
6086 : : {
6087 : 4040763 : if (mode1 != VOIDmode)
6088 : 3970170 : to_rtx = adjust_address (to_rtx, mode1, 0);
6089 : 70593 : else if (GET_MODE (to_rtx) == VOIDmode)
6090 : 0 : to_rtx = adjust_address (to_rtx, BLKmode, 0);
6091 : : }
6092 : :
6093 : 4737013 : rtx stemp = NULL_RTX, old_to_rtx = NULL_RTX;
6094 : 4737013 : if (offset != 0)
6095 : : {
6096 : 173782 : machine_mode address_mode;
6097 : 173782 : rtx offset_rtx;
6098 : :
6099 : 173782 : if (!MEM_P (to_rtx))
6100 : : {
6101 : : /* We can get constant negative offsets into arrays with broken
6102 : : user code. Translate this to a trap instead of ICEing. */
6103 : 4 : if (TREE_CODE (offset) == INTEGER_CST)
6104 : : {
6105 : 1 : expand_builtin_trap ();
6106 : 1 : to_rtx = gen_rtx_MEM (BLKmode, const0_rtx);
6107 : : }
6108 : : /* Else spill for variable offset to the destination. We expect
6109 : : to run into this only for hard registers. */
6110 : : else
6111 : : {
6112 : 3 : gcc_assert (VAR_P (tem) && DECL_HARD_REGISTER (tem));
6113 : 3 : stemp = assign_stack_temp (GET_MODE (to_rtx),
6114 : 6 : GET_MODE_SIZE (GET_MODE (to_rtx)));
6115 : 3 : emit_move_insn (stemp, to_rtx);
6116 : 3 : old_to_rtx = to_rtx;
6117 : 3 : to_rtx = stemp;
6118 : : }
6119 : : }
6120 : :
6121 : 173782 : offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, EXPAND_SUM);
6122 : 173782 : address_mode = get_address_mode (to_rtx);
6123 : 173782 : if (GET_MODE (offset_rtx) != address_mode)
6124 : : {
6125 : : /* We cannot be sure that the RTL in offset_rtx is valid outside
6126 : : of a memory address context, so force it into a register
6127 : : before attempting to convert it to the desired mode. */
6128 : 246 : offset_rtx = force_operand (offset_rtx, NULL_RTX);
6129 : 246 : offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
6130 : : }
6131 : :
6132 : : /* If we have an expression in OFFSET_RTX and a non-zero
6133 : : byte offset in BITPOS, adding the byte offset before the
6134 : : OFFSET_RTX results in better intermediate code, which makes
6135 : : later rtl optimization passes perform better.
6136 : :
6137 : : We prefer intermediate code like this:
6138 : :
6139 : : r124:DI=r123:DI+0x18
6140 : : [r124:DI]=r121:DI
6141 : :
6142 : : ... instead of ...
6143 : :
6144 : : r124:DI=r123:DI+0x10
6145 : : [r124:DI+0x8]=r121:DI
6146 : :
6147 : : This is only done for aligned data values, as these can
6148 : : be expected to result in single move instructions. */
6149 : 173782 : poly_int64 bytepos;
6150 : 173782 : if (mode1 != VOIDmode
6151 : 173674 : && maybe_ne (bitpos, 0)
6152 : 46368 : && maybe_gt (bitsize, 0)
6153 : 220150 : && multiple_p (bitpos, BITS_PER_UNIT, &bytepos)
6154 : 220093 : && multiple_p (bitpos, bitsize)
6155 : 92622 : && multiple_p (bitsize, GET_MODE_ALIGNMENT (mode1))
6156 : 220093 : && MEM_ALIGN (to_rtx) >= GET_MODE_ALIGNMENT (mode1))
6157 : : {
6158 : 46103 : to_rtx = adjust_address (to_rtx, mode1, bytepos);
6159 : 46103 : bitregion_start = 0;
6160 : 46103 : if (known_ge (bitregion_end, poly_uint64 (bitpos)))
6161 : 46103 : bitregion_end -= bitpos;
6162 : 46103 : bitpos = 0;
6163 : : }
6164 : :
6165 : 173782 : to_rtx = offset_address (to_rtx, offset_rtx,
6166 : : highest_pow2_factor_for_target (to,
6167 : : offset));
6168 : : }
6169 : :
6170 : : /* No action is needed if the target is not a memory and the field
6171 : : lies completely outside that target. This can occur if the source
6172 : : code contains an out-of-bounds access to a small array. */
6173 : 4737013 : if (!MEM_P (to_rtx)
6174 : 696246 : && GET_MODE (to_rtx) != BLKmode
6175 : 5433259 : && known_ge (bitpos, GET_MODE_PRECISION (GET_MODE (to_rtx))))
6176 : : {
6177 : 3 : expand_normal (from);
6178 : 3 : result = NULL;
6179 : : }
6180 : : /* Handle expand_expr of a complex value returning a CONCAT. */
6181 : 4737010 : else if (GET_CODE (to_rtx) == CONCAT)
6182 : : {
6183 : 153 : machine_mode to_mode = GET_MODE (to_rtx);
6184 : 153 : gcc_checking_assert (COMPLEX_MODE_P (to_mode));
6185 : 306 : poly_int64 mode_bitsize = GET_MODE_BITSIZE (to_mode);
6186 : 153 : unsigned short inner_bitsize = GET_MODE_UNIT_BITSIZE (to_mode);
6187 : 153 : if (TYPE_MODE (TREE_TYPE (from)) == to_mode
6188 : 0 : && known_eq (bitpos, 0)
6189 : 153 : && known_eq (bitsize, mode_bitsize))
6190 : 0 : result = store_expr (from, to_rtx, false, nontemporal, reversep);
6191 : 153 : else if (TYPE_MODE (TREE_TYPE (from)) == GET_MODE_INNER (to_mode)
6192 : 106 : && known_eq (bitsize, inner_bitsize)
6193 : 259 : && (known_eq (bitpos, 0)
6194 : 33 : || known_eq (bitpos, inner_bitsize)))
6195 : 106 : result = store_expr (from, XEXP (to_rtx, maybe_ne (bitpos, 0)),
6196 : : false, nontemporal, reversep);
6197 : 47 : else if (known_le (bitpos + bitsize, inner_bitsize))
6198 : 5 : result = store_field (XEXP (to_rtx, 0), bitsize, bitpos,
6199 : : bitregion_start, bitregion_end,
6200 : : mode1, from, get_alias_set (to),
6201 : : nontemporal, reversep);
6202 : 42 : else if (known_ge (bitpos, inner_bitsize))
6203 : 3 : result = store_field (XEXP (to_rtx, 1), bitsize,
6204 : : bitpos - inner_bitsize,
6205 : : bitregion_start, bitregion_end,
6206 : : mode1, from, get_alias_set (to),
6207 : : nontemporal, reversep);
6208 : 39 : else if (known_eq (bitpos, 0) && known_eq (bitsize, mode_bitsize))
6209 : : {
6210 : 32 : result = expand_normal (from);
6211 : 32 : if (GET_CODE (result) == CONCAT)
6212 : : {
6213 : 0 : to_mode = GET_MODE_INNER (to_mode);
6214 : 0 : machine_mode from_mode = GET_MODE_INNER (GET_MODE (result));
6215 : 0 : rtx from_real
6216 : 0 : = force_subreg (to_mode, XEXP (result, 0), from_mode, 0);
6217 : 0 : rtx from_imag
6218 : 0 : = force_subreg (to_mode, XEXP (result, 1), from_mode, 0);
6219 : 0 : if (!from_real || !from_imag)
6220 : 0 : goto concat_store_slow;
6221 : 0 : emit_move_insn (XEXP (to_rtx, 0), from_real);
6222 : 0 : emit_move_insn (XEXP (to_rtx, 1), from_imag);
6223 : : }
6224 : : else
6225 : : {
6226 : 32 : machine_mode from_mode
6227 : 32 : = GET_MODE (result) == VOIDmode
6228 : 32 : ? TYPE_MODE (TREE_TYPE (from))
6229 : 32 : : GET_MODE (result);
6230 : 32 : rtx from_rtx;
6231 : 32 : if (MEM_P (result))
6232 : 1 : from_rtx = change_address (result, to_mode, NULL_RTX);
6233 : : else
6234 : 31 : from_rtx = force_subreg (to_mode, result, from_mode, 0);
6235 : 32 : if (from_rtx)
6236 : : {
6237 : 32 : emit_move_insn (XEXP (to_rtx, 0),
6238 : : read_complex_part (from_rtx, false));
6239 : 32 : emit_move_insn (XEXP (to_rtx, 1),
6240 : : read_complex_part (from_rtx, true));
6241 : : }
6242 : : else
6243 : : {
6244 : 0 : to_mode = GET_MODE_INNER (to_mode);
6245 : 0 : rtx from_real
6246 : 0 : = force_subreg (to_mode, result, from_mode, 0);
6247 : 0 : rtx from_imag
6248 : 0 : = force_subreg (to_mode, result, from_mode,
6249 : 0 : GET_MODE_SIZE (to_mode));
6250 : 0 : if (!from_real || !from_imag)
6251 : 0 : goto concat_store_slow;
6252 : 0 : emit_move_insn (XEXP (to_rtx, 0), from_real);
6253 : 0 : emit_move_insn (XEXP (to_rtx, 1), from_imag);
6254 : : }
6255 : : }
6256 : : }
6257 : : else
6258 : : {
6259 : 7 : concat_store_slow:;
6260 : 7 : rtx temp = assign_stack_temp (GET_MODE (to_rtx),
6261 : 14 : GET_MODE_SIZE (GET_MODE (to_rtx)));
6262 : 7 : write_complex_part (temp, XEXP (to_rtx, 0), false, true);
6263 : 7 : write_complex_part (temp, XEXP (to_rtx, 1), true, false);
6264 : 7 : result = store_field (temp, bitsize, bitpos,
6265 : : bitregion_start, bitregion_end,
6266 : : mode1, from, get_alias_set (to),
6267 : : nontemporal, reversep);
6268 : 7 : emit_move_insn (XEXP (to_rtx, 0), read_complex_part (temp, false));
6269 : 7 : emit_move_insn (XEXP (to_rtx, 1), read_complex_part (temp, true));
6270 : : }
6271 : : }
6272 : : /* For calls to functions returning variable length structures, if TO_RTX
6273 : : is not a MEM, go through a MEM because we must not create temporaries
6274 : : of the VLA type. */
6275 : 4736857 : else if (!MEM_P (to_rtx)
6276 : 696090 : && TREE_CODE (from) == CALL_EXPR
6277 : 350 : && COMPLETE_TYPE_P (TREE_TYPE (from))
6278 : 4737207 : && TREE_CODE (TYPE_SIZE (TREE_TYPE (from))) != INTEGER_CST)
6279 : : {
6280 : 6 : rtx temp = assign_stack_temp (GET_MODE (to_rtx),
6281 : 12 : GET_MODE_SIZE (GET_MODE (to_rtx)));
6282 : 6 : result = store_field (temp, bitsize, bitpos, bitregion_start,
6283 : : bitregion_end, mode1, from, get_alias_set (to),
6284 : : nontemporal, reversep);
6285 : 6 : emit_move_insn (to_rtx, temp);
6286 : : }
6287 : : else
6288 : : {
6289 : 4736851 : if (MEM_P (to_rtx))
6290 : : {
6291 : : /* If the field is at offset zero, we could have been given the
6292 : : DECL_RTX of the parent struct. Don't munge it. */
6293 : 4040767 : to_rtx = shallow_copy_rtx (to_rtx);
6294 : 4040767 : set_mem_attributes_minus_bitpos (to_rtx, to, 0, bitpos);
6295 : 4040767 : if (volatilep)
6296 : 8654 : MEM_VOLATILE_P (to_rtx) = 1;
6297 : : }
6298 : :
6299 : 4736851 : gcc_checking_assert (known_ge (bitpos, 0));
6300 : 4736851 : if (optimize_bitfield_assignment_op (bitsize, bitpos,
6301 : : bitregion_start, bitregion_end,
6302 : : mode1, to_rtx, to, from,
6303 : : reversep))
6304 : : result = NULL;
6305 : 4736726 : else if (SUBREG_P (to_rtx)
6306 : 4736726 : && SUBREG_PROMOTED_VAR_P (to_rtx))
6307 : : {
6308 : : /* If to_rtx is a promoted subreg, we need to zero or sign
6309 : : extend the value afterwards. */
6310 : 0 : if (TREE_CODE (to) == MEM_REF
6311 : 0 : && TYPE_MODE (TREE_TYPE (from)) != BLKmode
6312 : 0 : && !REF_REVERSE_STORAGE_ORDER (to)
6313 : 0 : && known_eq (bitpos, 0)
6314 : 0 : && known_eq (bitsize, GET_MODE_BITSIZE (GET_MODE (to_rtx))))
6315 : 0 : result = store_expr (from, to_rtx, 0, nontemporal, false);
6316 : : /* Check if the field overlaps the MSB, requiring extension. */
6317 : 0 : else if (maybe_eq (bitpos + bitsize,
6318 : 0 : GET_MODE_BITSIZE (GET_MODE (to_rtx))))
6319 : : {
6320 : 0 : scalar_int_mode imode = subreg_unpromoted_mode (to_rtx);
6321 : 0 : scalar_int_mode omode = subreg_promoted_mode (to_rtx);
6322 : 0 : rtx to_rtx1 = lowpart_subreg (imode, SUBREG_REG (to_rtx),
6323 : : omode);
6324 : 0 : result = store_field (to_rtx1, bitsize, bitpos,
6325 : : bitregion_start, bitregion_end,
6326 : : mode1, from, get_alias_set (to),
6327 : : nontemporal, reversep);
6328 : : /* If the target usually keeps IMODE appropriately
6329 : : extended in OMODE it's unsafe to refer to it using
6330 : : a SUBREG whilst this invariant doesn't hold. */
6331 : 0 : if (targetm.mode_rep_extended (imode, omode) != UNKNOWN)
6332 : 0 : to_rtx1 = simplify_gen_unary (TRUNCATE, imode,
6333 : : SUBREG_REG (to_rtx), omode);
6334 : 0 : convert_move (SUBREG_REG (to_rtx), to_rtx1,
6335 : 0 : SUBREG_PROMOTED_SIGN (to_rtx));
6336 : : }
6337 : : else
6338 : 0 : result = store_field (to_rtx, bitsize, bitpos,
6339 : : bitregion_start, bitregion_end,
6340 : : mode1, from, get_alias_set (to),
6341 : : nontemporal, reversep);
6342 : : }
6343 : : else
6344 : 4736726 : result = store_field (to_rtx, bitsize, bitpos,
6345 : : bitregion_start, bitregion_end,
6346 : : mode1, from, get_alias_set (to),
6347 : : nontemporal, reversep);
6348 : : /* Move the temporary storage back to the non-MEM_P. */
6349 : 4736851 : if (stemp)
6350 : 3 : emit_move_insn (old_to_rtx, stemp);
6351 : : }
6352 : :
6353 : 4737013 : if (result)
6354 : 839752 : preserve_temp_slots (result);
6355 : 4737013 : pop_temp_slots ();
6356 : 4737013 : return;
6357 : : }
6358 : :
6359 : : /* If the rhs is a function call and its value is not an aggregate,
6360 : : call the function before we start to compute the lhs.
6361 : : This is needed for correct code for cases such as
6362 : : val = setjmp (buf) on machines where reference to val
6363 : : requires loading up part of an address in a separate insn.
6364 : :
6365 : : Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
6366 : : since it might be a promoted variable where the zero- or sign- extension
6367 : : needs to be done. Handling this in the normal way is safe because no
6368 : : computation is done before the call. The same is true for SSA names. */
6369 : 2314213 : if (TREE_CODE (from) == CALL_EXPR && ! aggregate_value_p (from, from)
6370 : 2114440 : && COMPLETE_TYPE_P (TREE_TYPE (from))
6371 : 2114440 : && TREE_CODE (TYPE_SIZE (TREE_TYPE (from))) == INTEGER_CST
6372 : 15413491 : && ! (((VAR_P (to)
6373 : : || TREE_CODE (to) == PARM_DECL
6374 : : || TREE_CODE (to) == RESULT_DECL)
6375 : 130351 : && REG_P (DECL_RTL (to)))
6376 : 1992029 : || TREE_CODE (to) == SSA_NAME))
6377 : : {
6378 : 8165 : rtx value;
6379 : :
6380 : 8165 : push_temp_slots ();
6381 : 8165 : value = expand_normal (from);
6382 : :
6383 : 8165 : if (to_rtx == 0)
6384 : 8165 : to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
6385 : :
6386 : : /* Handle calls that return values in multiple non-contiguous locations.
6387 : : The Irix 6 ABI has examples of this. */
6388 : 8165 : if (GET_CODE (to_rtx) == PARALLEL)
6389 : : {
6390 : 0 : if (GET_CODE (value) == PARALLEL)
6391 : 0 : emit_group_move (to_rtx, value);
6392 : : else
6393 : 0 : emit_group_load (to_rtx, value, TREE_TYPE (from),
6394 : 0 : int_size_in_bytes (TREE_TYPE (from)));
6395 : : }
6396 : 8165 : else if (GET_CODE (value) == PARALLEL)
6397 : 1827 : emit_group_store (to_rtx, value, TREE_TYPE (from),
6398 : 1827 : int_size_in_bytes (TREE_TYPE (from)));
6399 : 6338 : else if (GET_MODE (to_rtx) == BLKmode)
6400 : : {
6401 : : /* Handle calls that return BLKmode values in registers. */
6402 : 247 : if (REG_P (value))
6403 : 247 : copy_blkmode_from_reg (to_rtx, value, TREE_TYPE (from));
6404 : : else
6405 : 0 : emit_block_move (to_rtx, value, expr_size (from), BLOCK_OP_NORMAL);
6406 : : }
6407 : : else
6408 : : {
6409 : 6091 : if (POINTER_TYPE_P (TREE_TYPE (to)))
6410 : 0 : value = convert_memory_address_addr_space
6411 : 0 : (as_a <scalar_int_mode> (GET_MODE (to_rtx)), value,
6412 : 0 : TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to))));
6413 : :
6414 : 6091 : emit_move_insn (to_rtx, value);
6415 : : }
6416 : :
6417 : 8165 : preserve_temp_slots (to_rtx);
6418 : 8165 : pop_temp_slots ();
6419 : 8165 : return;
6420 : : }
6421 : :
6422 : : /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
6423 : 13290886 : to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
6424 : :
6425 : : /* Don't move directly into a return register. */
6426 : 13290886 : if (TREE_CODE (to) == RESULT_DECL
6427 : 28785 : && (REG_P (to_rtx) || GET_CODE (to_rtx) == PARALLEL))
6428 : : {
6429 : 0 : rtx temp;
6430 : :
6431 : 0 : push_temp_slots ();
6432 : :
6433 : : /* If the source is itself a return value, it still is in a pseudo at
6434 : : this point so we can move it back to the return register directly. */
6435 : 0 : if (REG_P (to_rtx)
6436 : 0 : && TYPE_MODE (TREE_TYPE (from)) == BLKmode
6437 : 0 : && TREE_CODE (from) != CALL_EXPR)
6438 : 0 : temp = copy_blkmode_to_reg (GET_MODE (to_rtx), from);
6439 : : else
6440 : 0 : temp = expand_expr (from, NULL_RTX, GET_MODE (to_rtx), EXPAND_NORMAL);
6441 : :
6442 : : /* Handle calls that return values in multiple non-contiguous locations.
6443 : : The Irix 6 ABI has examples of this. */
6444 : 0 : if (GET_CODE (to_rtx) == PARALLEL)
6445 : : {
6446 : 0 : if (GET_CODE (temp) == PARALLEL)
6447 : 0 : emit_group_move (to_rtx, temp);
6448 : : else
6449 : 0 : emit_group_load (to_rtx, temp, TREE_TYPE (from),
6450 : 0 : int_size_in_bytes (TREE_TYPE (from)));
6451 : : }
6452 : 0 : else if (temp)
6453 : 0 : emit_move_insn (to_rtx, temp);
6454 : :
6455 : 0 : preserve_temp_slots (to_rtx);
6456 : 0 : pop_temp_slots ();
6457 : 0 : return;
6458 : : }
6459 : :
6460 : : /* In case we are returning the contents of an object which overlaps
6461 : : the place the value is being stored, use a safe function when copying
6462 : : a value through a pointer into a structure value return block. */
6463 : 13290886 : if (TREE_CODE (to) == RESULT_DECL
6464 : 28785 : && TREE_CODE (from) == INDIRECT_REF
6465 : 0 : && ADDR_SPACE_GENERIC_P
6466 : : (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from, 0)))))
6467 : 0 : && refs_may_alias_p (to, from)
6468 : 0 : && cfun->returns_struct
6469 : 13290886 : && !cfun->returns_pcc_struct)
6470 : : {
6471 : 0 : rtx from_rtx, size;
6472 : :
6473 : 0 : push_temp_slots ();
6474 : 0 : size = expr_size (from);
6475 : 0 : from_rtx = expand_normal (from);
6476 : :
6477 : 0 : emit_block_move_via_libcall (XEXP (to_rtx, 0), XEXP (from_rtx, 0), size);
6478 : :
6479 : 0 : preserve_temp_slots (to_rtx);
6480 : 0 : pop_temp_slots ();
6481 : 0 : return;
6482 : : }
6483 : :
6484 : : /* Compute FROM and store the value in the rtx we got. */
6485 : :
6486 : 13290886 : push_temp_slots ();
6487 : 13290886 : result = store_expr (from, to_rtx, 0, nontemporal, false);
6488 : 13290886 : preserve_temp_slots (result);
6489 : 13290886 : pop_temp_slots ();
6490 : 13290886 : return;
6491 : : }
6492 : :
6493 : : /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
6494 : : succeeded, false otherwise. */
6495 : :
6496 : : bool
6497 : 17 : emit_storent_insn (rtx to, rtx from)
6498 : : {
6499 : 17 : class expand_operand ops[2];
6500 : 17 : machine_mode mode = GET_MODE (to);
6501 : 17 : enum insn_code code = optab_handler (storent_optab, mode);
6502 : :
6503 : 17 : if (code == CODE_FOR_nothing)
6504 : : return false;
6505 : :
6506 : 17 : create_fixed_operand (&ops[0], to);
6507 : 17 : create_input_operand (&ops[1], from, mode);
6508 : 17 : return maybe_expand_insn (code, 2, ops);
6509 : : }
6510 : :
6511 : : /* Helper function for store_expr storing of STRING_CST. */
6512 : :
6513 : : static rtx
6514 : 95011 : string_cst_read_str (void *data, void *, HOST_WIDE_INT offset,
6515 : : fixed_size_mode mode)
6516 : : {
6517 : 95011 : tree str = (tree) data;
6518 : :
6519 : 95011 : gcc_assert (offset >= 0);
6520 : 95011 : if (offset >= TREE_STRING_LENGTH (str))
6521 : 3614 : return const0_rtx;
6522 : :
6523 : 91397 : if ((unsigned HOST_WIDE_INT) offset + GET_MODE_SIZE (mode)
6524 : 91397 : > (unsigned HOST_WIDE_INT) TREE_STRING_LENGTH (str))
6525 : : {
6526 : 2728 : char *p = XALLOCAVEC (char, GET_MODE_SIZE (mode));
6527 : 2728 : size_t l = TREE_STRING_LENGTH (str) - offset;
6528 : 2728 : memcpy (p, TREE_STRING_POINTER (str) + offset, l);
6529 : 2728 : memset (p + l, '\0', GET_MODE_SIZE (mode) - l);
6530 : 2728 : return c_readstr (p, mode, false);
6531 : : }
6532 : :
6533 : 88669 : return c_readstr (TREE_STRING_POINTER (str) + offset, mode, false);
6534 : : }
6535 : :
6536 : : /* Helper function for store_expr storing of RAW_DATA_CST. */
6537 : :
6538 : : static rtx
6539 : 36 : raw_data_cst_read_str (void *data, void *, HOST_WIDE_INT offset,
6540 : : fixed_size_mode mode)
6541 : : {
6542 : 36 : tree cst = (tree) data;
6543 : :
6544 : 36 : gcc_assert (offset >= 0);
6545 : 36 : if (offset >= RAW_DATA_LENGTH (cst))
6546 : 0 : return const0_rtx;
6547 : :
6548 : 36 : if ((unsigned HOST_WIDE_INT) offset + GET_MODE_SIZE (mode)
6549 : 36 : > (unsigned HOST_WIDE_INT) RAW_DATA_LENGTH (cst))
6550 : : {
6551 : 0 : char *p = XALLOCAVEC (char, GET_MODE_SIZE (mode));
6552 : 0 : size_t l = RAW_DATA_LENGTH (cst) - offset;
6553 : 0 : memcpy (p, RAW_DATA_POINTER (cst) + offset, l);
6554 : 0 : memset (p + l, '\0', GET_MODE_SIZE (mode) - l);
6555 : 0 : return c_readstr (p, mode, false);
6556 : : }
6557 : :
6558 : 36 : return c_readstr (RAW_DATA_POINTER (cst) + offset, mode, false);
6559 : : }
6560 : :
6561 : : /* Generate code for computing expression EXP,
6562 : : and storing the value into TARGET.
6563 : :
6564 : : If the mode is BLKmode then we may return TARGET itself.
6565 : : It turns out that in BLKmode it doesn't cause a problem.
6566 : : because C has no operators that could combine two different
6567 : : assignments into the same BLKmode object with different values
6568 : : with no sequence point. Will other languages need this to
6569 : : be more thorough?
6570 : :
6571 : : If CALL_PARAM_P is nonzero, this is a store into a call param on the
6572 : : stack, and block moves may need to be treated specially.
6573 : :
6574 : : If NONTEMPORAL is true, try using a nontemporal store instruction.
6575 : :
6576 : : If REVERSE is true, the store is to be done in reverse order. */
6577 : :
6578 : : rtx
6579 : 17226123 : store_expr (tree exp, rtx target, int call_param_p,
6580 : : bool nontemporal, bool reverse)
6581 : : {
6582 : 17226123 : rtx temp;
6583 : 17226123 : rtx alt_rtl = NULL_RTX;
6584 : 17226123 : location_t loc = curr_insn_location ();
6585 : 17226123 : bool shortened_string_cst = false;
6586 : :
6587 : 17226123 : if (VOID_TYPE_P (TREE_TYPE (exp)))
6588 : : {
6589 : : /* C++ can generate ?: expressions with a throw expression in one
6590 : : branch and an rvalue in the other. Here, we resolve attempts to
6591 : : store the throw expression's nonexistent result. */
6592 : 0 : gcc_assert (!call_param_p);
6593 : 0 : expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL);
6594 : 0 : return NULL_RTX;
6595 : : }
6596 : 17226123 : if (TREE_CODE (exp) == COMPOUND_EXPR)
6597 : : {
6598 : : /* Perform first part of compound expression, then assign from second
6599 : : part. */
6600 : 0 : expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
6601 : : call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
6602 : 0 : return store_expr (TREE_OPERAND (exp, 1), target,
6603 : 0 : call_param_p, nontemporal, reverse);
6604 : : }
6605 : 17226123 : else if (TREE_CODE (exp) == COND_EXPR && GET_MODE (target) == BLKmode)
6606 : : {
6607 : : /* For conditional expression, get safe form of the target. Then
6608 : : test the condition, doing the appropriate assignment on either
6609 : : side. This avoids the creation of unnecessary temporaries.
6610 : : For non-BLKmode, it is more efficient not to do this. */
6611 : :
6612 : 0 : rtx_code_label *lab1 = gen_label_rtx (), *lab2 = gen_label_rtx ();
6613 : :
6614 : 0 : do_pending_stack_adjust ();
6615 : 0 : NO_DEFER_POP;
6616 : 0 : jumpifnot (TREE_OPERAND (exp, 0), lab1,
6617 : : profile_probability::uninitialized ());
6618 : 0 : store_expr (TREE_OPERAND (exp, 1), target, call_param_p,
6619 : : nontemporal, reverse);
6620 : 0 : emit_jump_insn (targetm.gen_jump (lab2));
6621 : 0 : emit_barrier ();
6622 : 0 : emit_label (lab1);
6623 : 0 : store_expr (TREE_OPERAND (exp, 2), target, call_param_p,
6624 : : nontemporal, reverse);
6625 : 0 : emit_label (lab2);
6626 : 0 : OK_DEFER_POP;
6627 : :
6628 : 0 : return NULL_RTX;
6629 : : }
6630 : 17226123 : else if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target))
6631 : : /* If this is a scalar in a register that is stored in a wider mode
6632 : : than the declared mode, compute the result into its declared mode
6633 : : and then convert to the wider mode. Our value is the computed
6634 : : expression. */
6635 : : {
6636 : 7 : rtx inner_target = 0;
6637 : 7 : scalar_int_mode outer_mode = subreg_unpromoted_mode (target);
6638 : 7 : scalar_int_mode inner_mode = subreg_promoted_mode (target);
6639 : :
6640 : : /* We can do the conversion inside EXP, which will often result
6641 : : in some optimizations. Do the conversion in two steps: first
6642 : : change the signedness, if needed, then the extend. But don't
6643 : : do this if the type of EXP is a subtype of something else
6644 : : since then the conversion might involve more than just
6645 : : converting modes. */
6646 : 14 : if (INTEGRAL_TYPE_P (TREE_TYPE (exp))
6647 : 0 : && TREE_TYPE (TREE_TYPE (exp)) == 0
6648 : 7 : && GET_MODE_PRECISION (outer_mode)
6649 : 0 : == TYPE_PRECISION (TREE_TYPE (exp)))
6650 : : {
6651 : 0 : if (!SUBREG_CHECK_PROMOTED_SIGN (target,
6652 : : TYPE_UNSIGNED (TREE_TYPE (exp))))
6653 : : {
6654 : : /* Some types, e.g. Fortran's logical*4, won't have a signed
6655 : : version, so use the mode instead. */
6656 : 0 : tree ntype
6657 : : = (signed_or_unsigned_type_for
6658 : 0 : (SUBREG_PROMOTED_SIGN (target), TREE_TYPE (exp)));
6659 : 0 : if (ntype == NULL)
6660 : 0 : ntype = lang_hooks.types.type_for_mode
6661 : 0 : (TYPE_MODE (TREE_TYPE (exp)),
6662 : 0 : SUBREG_PROMOTED_SIGN (target));
6663 : :
6664 : 0 : exp = fold_convert_loc (loc, ntype, exp);
6665 : : }
6666 : :
6667 : 0 : exp = fold_convert_loc (loc, lang_hooks.types.type_for_mode
6668 : 0 : (inner_mode, SUBREG_PROMOTED_SIGN (target)),
6669 : : exp);
6670 : :
6671 : 0 : inner_target = SUBREG_REG (target);
6672 : : }
6673 : :
6674 : 7 : temp = expand_expr (exp, inner_target, VOIDmode,
6675 : : call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
6676 : :
6677 : :
6678 : : /* If TEMP is a VOIDmode constant, use convert_modes to make
6679 : : sure that we properly convert it. */
6680 : 7 : if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode)
6681 : : {
6682 : 0 : temp = convert_modes (outer_mode, TYPE_MODE (TREE_TYPE (exp)),
6683 : 0 : temp, SUBREG_PROMOTED_SIGN (target));
6684 : 0 : temp = convert_modes (inner_mode, outer_mode, temp,
6685 : 0 : SUBREG_PROMOTED_SIGN (target));
6686 : 0 : }
6687 : 7 : else if (!SCALAR_INT_MODE_P (GET_MODE (temp)))
6688 : 0 : temp = convert_modes (outer_mode, TYPE_MODE (TREE_TYPE (exp)),
6689 : 0 : temp, SUBREG_PROMOTED_SIGN (target));
6690 : :
6691 : 21 : convert_move (SUBREG_REG (target), temp,
6692 : 7 : SUBREG_PROMOTED_SIGN (target));
6693 : :
6694 : 7 : return NULL_RTX;
6695 : : }
6696 : 17226116 : else if ((TREE_CODE (exp) == STRING_CST
6697 : 17215229 : || (TREE_CODE (exp) == MEM_REF
6698 : 1299251 : && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
6699 : 415509 : && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
6700 : : == STRING_CST
6701 : 4372 : && integer_zerop (TREE_OPERAND (exp, 1))))
6702 : 15259 : && !nontemporal && !call_param_p
6703 : 17241375 : && MEM_P (target))
6704 : : {
6705 : : /* Optimize initialization of an array with a STRING_CST. */
6706 : 15241 : HOST_WIDE_INT exp_len, str_copy_len;
6707 : 15241 : rtx dest_mem;
6708 : 15241 : tree str = TREE_CODE (exp) == STRING_CST
6709 : 15241 : ? exp : TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6710 : :
6711 : 15241 : exp_len = int_expr_size (exp);
6712 : 15241 : if (exp_len <= 0)
6713 : 0 : goto normal_expr;
6714 : :
6715 : 15241 : if (TREE_STRING_LENGTH (str) <= 0)
6716 : 0 : goto normal_expr;
6717 : :
6718 : 30482 : if (can_store_by_pieces (exp_len, string_cst_read_str, (void *) str,
6719 : 15241 : MEM_ALIGN (target), false))
6720 : : {
6721 : 15065 : store_by_pieces (target, exp_len, string_cst_read_str, (void *) str,
6722 : 15065 : MEM_ALIGN (target), false, RETURN_BEGIN);
6723 : 15065 : return NULL_RTX;
6724 : : }
6725 : :
6726 : 176 : str_copy_len = TREE_STRING_LENGTH (str);
6727 : :
6728 : : /* Trailing NUL bytes in EXP will be handled by the call to
6729 : : clear_storage, which is more efficient than copying them from
6730 : : the STRING_CST, so trim those from STR_COPY_LEN. */
6731 : 299 : while (str_copy_len)
6732 : : {
6733 : 256 : if (TREE_STRING_POINTER (str)[str_copy_len - 1])
6734 : : break;
6735 : 123 : str_copy_len--;
6736 : : }
6737 : :
6738 : 176 : if ((STORE_MAX_PIECES & (STORE_MAX_PIECES - 1)) == 0)
6739 : : {
6740 : 176 : str_copy_len += STORE_MAX_PIECES - 1;
6741 : 176 : str_copy_len &= ~(STORE_MAX_PIECES - 1);
6742 : : }
6743 : 176 : if (str_copy_len >= exp_len)
6744 : 125 : goto normal_expr;
6745 : :
6746 : 102 : if (!can_store_by_pieces (str_copy_len, string_cst_read_str,
6747 : 51 : (void *) str, MEM_ALIGN (target), false))
6748 : 2 : goto normal_expr;
6749 : :
6750 : 49 : dest_mem = store_by_pieces (target, str_copy_len, string_cst_read_str,
6751 : 49 : (void *) str, MEM_ALIGN (target), false,
6752 : : RETURN_END);
6753 : 49 : clear_storage (adjust_address_1 (dest_mem, BLKmode, 0, 1, 1, 0,
6754 : 49 : exp_len - str_copy_len),
6755 : : GEN_INT (exp_len - str_copy_len), BLOCK_OP_NORMAL);
6756 : 49 : return NULL_RTX;
6757 : : }
6758 : : else
6759 : : {
6760 : 17211002 : rtx tmp_target;
6761 : :
6762 : 17211002 : normal_expr:
6763 : : /* If we want to use a nontemporal or a reverse order store, force the
6764 : : value into a register first. */
6765 : 17211002 : tmp_target = nontemporal || reverse ? NULL_RTX : target;
6766 : 17211002 : tree rexp = exp;
6767 : 17211002 : if (TREE_CODE (exp) == STRING_CST
6768 : 42 : && tmp_target == target
6769 : 42 : && GET_MODE (target) == BLKmode
6770 : 17211044 : && TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
6771 : : {
6772 : 42 : rtx size = expr_size (exp);
6773 : 42 : if (CONST_INT_P (size)
6774 : 42 : && size != const0_rtx
6775 : 84 : && (UINTVAL (size)
6776 : 42 : > ((unsigned HOST_WIDE_INT) TREE_STRING_LENGTH (exp) + 32)))
6777 : : {
6778 : : /* If the STRING_CST has much larger array type than
6779 : : TREE_STRING_LENGTH, only emit the TREE_STRING_LENGTH part of
6780 : : it into the rodata section as the code later on will use
6781 : : memset zero for the remainder anyway. See PR95052. */
6782 : 2 : tmp_target = NULL_RTX;
6783 : 2 : rexp = copy_node (exp);
6784 : 2 : tree index
6785 : 2 : = build_index_type (size_int (TREE_STRING_LENGTH (exp) - 1));
6786 : 2 : TREE_TYPE (rexp) = build_array_type (TREE_TYPE (TREE_TYPE (exp)),
6787 : : index);
6788 : 2 : shortened_string_cst = true;
6789 : : }
6790 : : }
6791 : 34422004 : temp = expand_expr_real (rexp, tmp_target, GET_MODE (target),
6792 : : (call_param_p
6793 : : ? EXPAND_STACK_PARM : EXPAND_NORMAL),
6794 : : &alt_rtl, false);
6795 : 17211002 : if (shortened_string_cst)
6796 : : {
6797 : 2 : gcc_assert (MEM_P (temp));
6798 : 2 : temp = change_address (temp, BLKmode, NULL_RTX);
6799 : : }
6800 : : }
6801 : :
6802 : : /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
6803 : : the same as that of TARGET, adjust the constant. This is needed, for
6804 : : example, in case it is a CONST_DOUBLE or CONST_WIDE_INT and we want
6805 : : only a word-sized value. */
6806 : 3551575 : if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode
6807 : 2566295 : && TREE_CODE (exp) != ERROR_MARK
6808 : 19777297 : && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
6809 : : {
6810 : 0 : gcc_assert (!shortened_string_cst);
6811 : 0 : if (GET_MODE_CLASS (GET_MODE (target))
6812 : 0 : != GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (exp)))
6813 : 0 : && known_eq (GET_MODE_BITSIZE (GET_MODE (target)),
6814 : : GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp)))))
6815 : : {
6816 : 0 : rtx t = simplify_gen_subreg (GET_MODE (target), temp,
6817 : 0 : TYPE_MODE (TREE_TYPE (exp)), 0);
6818 : 0 : if (t)
6819 : 0 : temp = t;
6820 : : }
6821 : 0 : if (GET_MODE (temp) == VOIDmode)
6822 : 0 : temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
6823 : 0 : temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
6824 : : }
6825 : :
6826 : : /* If value was not generated in the target, store it there.
6827 : : Convert the value to TARGET's type first if necessary and emit the
6828 : : pending incrementations that have been queued when expanding EXP.
6829 : : Note that we cannot emit the whole queue blindly because this will
6830 : : effectively disable the POST_INC optimization later.
6831 : :
6832 : : If TEMP and TARGET compare equal according to rtx_equal_p, but
6833 : : one or both of them are volatile memory refs, we have to distinguish
6834 : : two cases:
6835 : : - expand_expr has used TARGET. In this case, we must not generate
6836 : : another copy. This can be detected by TARGET being equal according
6837 : : to == .
6838 : : - expand_expr has not used TARGET - that means that the source just
6839 : : happens to have the same RTX form. Since temp will have been created
6840 : : by expand_expr, it will compare unequal according to == .
6841 : : We must generate a copy in this case, to reach the correct number
6842 : : of volatile memory references. */
6843 : :
6844 : 17211002 : if ((! rtx_equal_p (temp, target)
6845 : 3091501 : || (temp != target && (side_effects_p (temp)
6846 : 46725 : || side_effects_p (target)
6847 : 46725 : || (MEM_P (temp)
6848 : 46248 : && !mems_same_for_tbaa_p (temp, target)))))
6849 : 14119505 : && TREE_CODE (exp) != ERROR_MARK
6850 : : /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
6851 : : but TARGET is not valid memory reference, TEMP will differ
6852 : : from TARGET although it is really the same location. */
6853 : 14119505 : && !(alt_rtl
6854 : 1984667 : && rtx_equal_p (alt_rtl, target)
6855 : 1 : && !side_effects_p (alt_rtl)
6856 : 0 : && !side_effects_p (target))
6857 : : /* If there's nothing to copy, don't bother. Don't call
6858 : : expr_size unless necessary, because some front-ends (C++)
6859 : : expr_size-hook must not be given objects that are not
6860 : : supposed to be bit-copied or bit-initialized. */
6861 : 31330507 : && expr_size (exp) != const0_rtx)
6862 : : {
6863 : 14119505 : if (GET_MODE (temp) != GET_MODE (target) && GET_MODE (temp) != VOIDmode)
6864 : : {
6865 : 1540 : gcc_assert (!shortened_string_cst);
6866 : 1540 : if (GET_MODE (target) == BLKmode)
6867 : : {
6868 : : /* Handle calls that return BLKmode values in registers. */
6869 : 2 : if (REG_P (temp) && TREE_CODE (exp) == CALL_EXPR)
6870 : 2 : copy_blkmode_from_reg (target, temp, TREE_TYPE (exp));
6871 : : else
6872 : 0 : store_bit_field (target,
6873 : 0 : rtx_to_poly_int64 (expr_size (exp))
6874 : 0 : * BITS_PER_UNIT,
6875 : : 0, 0, 0, GET_MODE (temp), temp, reverse,
6876 : : false);
6877 : : }
6878 : : else
6879 : 1538 : convert_move (target, temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
6880 : : }
6881 : :
6882 : 14117965 : else if (GET_MODE (temp) == BLKmode && TREE_CODE (exp) == STRING_CST)
6883 : : {
6884 : : /* Handle copying a string constant into an array. The string
6885 : : constant may be shorter than the array. So copy just the string's
6886 : : actual length, and clear the rest. First get the size of the data
6887 : : type of the string, which is actually the size of the target. */
6888 : 42 : rtx size = expr_size (exp);
6889 : :
6890 : 42 : if (CONST_INT_P (size)
6891 : 42 : && INTVAL (size) < TREE_STRING_LENGTH (exp))
6892 : 0 : emit_block_move (target, temp, size,
6893 : : (call_param_p
6894 : : ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
6895 : : else
6896 : : {
6897 : 42 : machine_mode pointer_mode
6898 : 42 : = targetm.addr_space.pointer_mode (MEM_ADDR_SPACE (target));
6899 : 42 : machine_mode address_mode = get_address_mode (target);
6900 : :
6901 : : /* Compute the size of the data to copy from the string. */
6902 : 42 : tree copy_size
6903 : 42 : = size_binop_loc (loc, MIN_EXPR,
6904 : : make_tree (sizetype, size),
6905 : 42 : size_int (TREE_STRING_LENGTH (exp)));
6906 : 42 : rtx copy_size_rtx
6907 : 42 : = expand_expr (copy_size, NULL_RTX, VOIDmode,
6908 : : (call_param_p
6909 : : ? EXPAND_STACK_PARM : EXPAND_NORMAL));
6910 : 42 : rtx_code_label *label = 0;
6911 : :
6912 : : /* Copy that much. */
6913 : 126 : copy_size_rtx = convert_to_mode (pointer_mode, copy_size_rtx,
6914 : 42 : TYPE_UNSIGNED (sizetype));
6915 : 84 : emit_block_move (target, temp, copy_size_rtx,
6916 : : (call_param_p
6917 : : ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
6918 : :
6919 : : /* Figure out how much is left in TARGET that we have to clear.
6920 : : Do all calculations in pointer_mode. */
6921 : 42 : poly_int64 const_copy_size;
6922 : 42 : if (poly_int_rtx_p (copy_size_rtx, &const_copy_size))
6923 : : {
6924 : 42 : size = plus_constant (address_mode, size, -const_copy_size);
6925 : 42 : target = adjust_address (target, BLKmode, const_copy_size);
6926 : : }
6927 : : else
6928 : : {
6929 : 0 : size = expand_binop (TYPE_MODE (sizetype), sub_optab, size,
6930 : : copy_size_rtx, NULL_RTX, 0,
6931 : : OPTAB_LIB_WIDEN);
6932 : :
6933 : 0 : if (GET_MODE (copy_size_rtx) != address_mode)
6934 : 0 : copy_size_rtx = convert_to_mode (address_mode,
6935 : : copy_size_rtx,
6936 : 0 : TYPE_UNSIGNED (sizetype));
6937 : :
6938 : 0 : target = offset_address (target, copy_size_rtx,
6939 : : highest_pow2_factor (copy_size));
6940 : 0 : label = gen_label_rtx ();
6941 : 0 : emit_cmp_and_jump_insns (size, const0_rtx, LT, NULL_RTX,
6942 : 0 : GET_MODE (size), 0, label);
6943 : : }
6944 : :
6945 : 42 : if (size != const0_rtx)
6946 : 2 : clear_storage (target, size, BLOCK_OP_NORMAL);
6947 : :
6948 : 42 : if (label)
6949 : 0 : emit_label (label);
6950 : : }
6951 : : }
6952 : 14117923 : else if (shortened_string_cst)
6953 : 0 : gcc_unreachable ();
6954 : : /* Handle calls that return values in multiple non-contiguous locations.
6955 : : The Irix 6 ABI has examples of this. */
6956 : 14117923 : else if (GET_CODE (target) == PARALLEL)
6957 : : {
6958 : 0 : if (GET_CODE (temp) == PARALLEL)
6959 : 0 : emit_group_move (target, temp);
6960 : : else
6961 : 0 : emit_group_load (target, temp, TREE_TYPE (exp),
6962 : 0 : int_size_in_bytes (TREE_TYPE (exp)));
6963 : : }
6964 : 14117923 : else if (GET_CODE (temp) == PARALLEL)
6965 : 0 : emit_group_store (target, temp, TREE_TYPE (exp),
6966 : 0 : int_size_in_bytes (TREE_TYPE (exp)));
6967 : 14117923 : else if (GET_MODE (temp) == BLKmode)
6968 : 609322 : emit_block_move (target, temp, expr_size (exp),
6969 : : (call_param_p
6970 : : ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
6971 : : /* If we emit a nontemporal store, there is nothing else to do. */
6972 : 13813262 : else if (nontemporal && emit_storent_insn (target, temp))
6973 : : ;
6974 : : else
6975 : : {
6976 : 13813245 : if (reverse)
6977 : 696 : temp = flip_storage_order (GET_MODE (target), temp);
6978 : 13813245 : temp = force_operand (temp, target);
6979 : 13813245 : if (temp != target)
6980 : 13811787 : emit_move_insn (target, temp);
6981 : : }
6982 : : }
6983 : : else
6984 : 3091497 : gcc_assert (!shortened_string_cst);
6985 : :
6986 : : return NULL_RTX;
6987 : : }
6988 : :
6989 : : /* Return true if field F of structure TYPE is a flexible array. */
6990 : :
6991 : : static bool
6992 : 3911493 : flexible_array_member_p (const_tree f, const_tree type)
6993 : : {
6994 : 3911493 : const_tree tf;
6995 : :
6996 : 3911493 : tf = TREE_TYPE (f);
6997 : 3911493 : return (DECL_CHAIN (f) == NULL
6998 : 1075682 : && TREE_CODE (tf) == ARRAY_TYPE
6999 : 2541 : && TYPE_DOMAIN (tf)
7000 : 2541 : && TYPE_MIN_VALUE (TYPE_DOMAIN (tf))
7001 : 2541 : && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf)))
7002 : 2541 : && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf))
7003 : 3911532 : && int_size_in_bytes (type) >= 0);
7004 : : }
7005 : :
7006 : : /* If FOR_CTOR_P, return the number of top-level elements that a constructor
7007 : : must have in order for it to completely initialize a value of type TYPE.
7008 : : Return -1 if the number isn't known.
7009 : :
7010 : : If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
7011 : :
7012 : : static HOST_WIDE_INT
7013 : 3671356 : count_type_elements (const_tree type, bool for_ctor_p)
7014 : : {
7015 : 3671356 : switch (TREE_CODE (type))
7016 : : {
7017 : 150904 : case ARRAY_TYPE:
7018 : 150904 : {
7019 : 150904 : tree nelts_minus_one;
7020 : :
7021 : 150904 : nelts_minus_one = array_type_nelts_minus_one (type);
7022 : 150904 : if (nelts_minus_one && tree_fits_uhwi_p (nelts_minus_one))
7023 : : {
7024 : 150893 : unsigned HOST_WIDE_INT n;
7025 : :
7026 : 150893 : n = tree_to_uhwi (nelts_minus_one) + 1;
7027 : 150893 : if (n == 0 || for_ctor_p)
7028 : 150136 : return n;
7029 : : else
7030 : 757 : return n * count_type_elements (TREE_TYPE (type), false);
7031 : : }
7032 : 11 : return for_ctor_p ? -1 : 1;
7033 : : }
7034 : :
7035 : 1749739 : case RECORD_TYPE:
7036 : 1749739 : {
7037 : 1749739 : unsigned HOST_WIDE_INT n;
7038 : 1749739 : tree f;
7039 : :
7040 : 1749739 : n = 0;
7041 : 16051206 : for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
7042 : 14301467 : if (TREE_CODE (f) == FIELD_DECL)
7043 : : {
7044 : 4378853 : if (!for_ctor_p)
7045 : 467360 : n += count_type_elements (TREE_TYPE (f), false);
7046 : 3911493 : else if (!flexible_array_member_p (f, type))
7047 : : /* Don't count flexible arrays, which are not supposed
7048 : : to be initialized. */
7049 : 3911454 : n += 1;
7050 : : }
7051 : :
7052 : 1749739 : return n;
7053 : : }
7054 : :
7055 : 4977 : case UNION_TYPE:
7056 : 4977 : case QUAL_UNION_TYPE:
7057 : 4977 : {
7058 : 4977 : tree f;
7059 : 4977 : HOST_WIDE_INT n, m;
7060 : :
7061 : 4977 : gcc_assert (!for_ctor_p);
7062 : : /* Estimate the number of scalars in each field and pick the
7063 : : maximum. Other estimates would do instead; the idea is simply
7064 : : to make sure that the estimate is not sensitive to the ordering
7065 : : of the fields. */
7066 : 4977 : n = 1;
7067 : 113584 : for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
7068 : 108607 : if (TREE_CODE (f) == FIELD_DECL)
7069 : : {
7070 : 102502 : m = count_type_elements (TREE_TYPE (f), false);
7071 : : /* If the field doesn't span the whole union, add an extra
7072 : : scalar for the rest. */
7073 : 102502 : if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f)),
7074 : 102502 : TYPE_SIZE (type)) != 1)
7075 : 73110 : m++;
7076 : 102502 : if (n < m)
7077 : 108607 : n = m;
7078 : : }
7079 : : return n;
7080 : : }
7081 : :
7082 : : case COMPLEX_TYPE:
7083 : : return 2;
7084 : :
7085 : 306 : case VECTOR_TYPE:
7086 : 306 : {
7087 : 306 : unsigned HOST_WIDE_INT nelts;
7088 : 306 : if (TYPE_VECTOR_SUBPARTS (type).is_constant (&nelts))
7089 : 306 : return nelts;
7090 : : else
7091 : : return -1;
7092 : : }
7093 : :
7094 : : case INTEGER_TYPE:
7095 : : case REAL_TYPE:
7096 : : case FIXED_POINT_TYPE:
7097 : : case ENUMERAL_TYPE:
7098 : : case BOOLEAN_TYPE:
7099 : : case POINTER_TYPE:
7100 : : case OFFSET_TYPE:
7101 : : case REFERENCE_TYPE:
7102 : : case NULLPTR_TYPE:
7103 : : case OPAQUE_TYPE:
7104 : : case BITINT_TYPE:
7105 : : return 1;
7106 : :
7107 : 0 : case ERROR_MARK:
7108 : 0 : return 0;
7109 : :
7110 : 0 : case VOID_TYPE:
7111 : 0 : case METHOD_TYPE:
7112 : 0 : case FUNCTION_TYPE:
7113 : 0 : case LANG_TYPE:
7114 : 0 : default:
7115 : 0 : gcc_unreachable ();
7116 : : }
7117 : : }
7118 : :
7119 : : /* Helper for categorize_ctor_elements. Identical interface. */
7120 : :
7121 : : static bool
7122 : 1511667 : categorize_ctor_elements_1 (const_tree ctor, HOST_WIDE_INT *p_nz_elts,
7123 : : HOST_WIDE_INT *p_unique_nz_elts,
7124 : : HOST_WIDE_INT *p_init_elts, int *p_complete)
7125 : : {
7126 : 1511667 : unsigned HOST_WIDE_INT idx;
7127 : 1511667 : HOST_WIDE_INT nz_elts, unique_nz_elts, init_elts, num_fields;
7128 : 1511667 : tree value, purpose, elt_type;
7129 : :
7130 : : /* Whether CTOR is a valid constant initializer, in accordance with what
7131 : : initializer_constant_valid_p does. If inferred from the constructor
7132 : : elements, true until proven otherwise. */
7133 : 1511667 : bool const_from_elts_p = constructor_static_from_elts_p (ctor);
7134 : 1511667 : bool const_p = const_from_elts_p ? true : TREE_STATIC (ctor);
7135 : :
7136 : 1511667 : nz_elts = 0;
7137 : 1511667 : unique_nz_elts = 0;
7138 : 1511667 : init_elts = 0;
7139 : 1511667 : num_fields = 0;
7140 : 1511667 : elt_type = NULL_TREE;
7141 : :
7142 : 5818306 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), idx, purpose, value)
7143 : : {
7144 : 4306639 : HOST_WIDE_INT mult = 1;
7145 : :
7146 : 4306639 : if (purpose && TREE_CODE (purpose) == RANGE_EXPR)
7147 : : {
7148 : 681 : tree lo_index = TREE_OPERAND (purpose, 0);
7149 : 681 : tree hi_index = TREE_OPERAND (purpose, 1);
7150 : :
7151 : 681 : if (tree_fits_uhwi_p (lo_index) && tree_fits_uhwi_p (hi_index))
7152 : 681 : mult = (tree_to_uhwi (hi_index)
7153 : 681 : - tree_to_uhwi (lo_index) + 1);
7154 : : }
7155 : 4306639 : num_fields += mult;
7156 : 4306639 : elt_type = TREE_TYPE (value);
7157 : :
7158 : 4306639 : switch (TREE_CODE (value))
7159 : : {
7160 : 535854 : case CONSTRUCTOR:
7161 : 535854 : {
7162 : 535854 : HOST_WIDE_INT nz = 0, unz = 0, ic = 0;
7163 : :
7164 : 535854 : bool const_elt_p = categorize_ctor_elements_1 (value, &nz, &unz,
7165 : : &ic, p_complete);
7166 : :
7167 : 535854 : nz_elts += mult * nz;
7168 : 535854 : unique_nz_elts += unz;
7169 : 535854 : init_elts += mult * ic;
7170 : :
7171 : 535854 : if (const_from_elts_p && const_p)
7172 : 323024 : const_p = const_elt_p;
7173 : : }
7174 : 535854 : break;
7175 : :
7176 : 2322450 : case INTEGER_CST:
7177 : 2322450 : case REAL_CST:
7178 : 2322450 : case FIXED_CST:
7179 : 2322450 : if (!initializer_zerop (value))
7180 : : {
7181 : 1663537 : nz_elts += mult;
7182 : 1663537 : unique_nz_elts++;
7183 : : }
7184 : 2322450 : init_elts += mult;
7185 : 2322450 : break;
7186 : :
7187 : 6302 : case STRING_CST:
7188 : 6302 : nz_elts += mult * TREE_STRING_LENGTH (value);
7189 : 6302 : unique_nz_elts += TREE_STRING_LENGTH (value);
7190 : 6302 : init_elts += mult * TREE_STRING_LENGTH (value);
7191 : 6302 : break;
7192 : :
7193 : 160 : case RAW_DATA_CST:
7194 : 160 : nz_elts += mult * RAW_DATA_LENGTH (value);
7195 : 160 : unique_nz_elts += RAW_DATA_LENGTH (value);
7196 : 160 : init_elts += mult * RAW_DATA_LENGTH (value);
7197 : 160 : num_fields += mult * (RAW_DATA_LENGTH (value) - 1);
7198 : 160 : break;
7199 : :
7200 : 2784 : case COMPLEX_CST:
7201 : 2784 : if (!initializer_zerop (TREE_REALPART (value)))
7202 : : {
7203 : 2349 : nz_elts += mult;
7204 : 2349 : unique_nz_elts++;
7205 : : }
7206 : 2784 : if (!initializer_zerop (TREE_IMAGPART (value)))
7207 : : {
7208 : 2269 : nz_elts += mult;
7209 : 2269 : unique_nz_elts++;
7210 : : }
7211 : 2784 : init_elts += 2 * mult;
7212 : 2784 : break;
7213 : :
7214 : 778 : case VECTOR_CST:
7215 : 778 : {
7216 : 778 : unsigned int nunits
7217 : : = constant_lower_bound
7218 : 778 : (TYPE_VECTOR_SUBPARTS (TREE_TYPE (value)));
7219 : 5269 : for (unsigned int i = 0; i < nunits; ++i)
7220 : : {
7221 : 4491 : tree v = VECTOR_CST_ELT (value, i);
7222 : 4491 : if (!initializer_zerop (v))
7223 : : {
7224 : 1993 : nz_elts += mult;
7225 : 1993 : unique_nz_elts++;
7226 : : }
7227 : 4491 : init_elts += mult;
7228 : : }
7229 : : }
7230 : : break;
7231 : :
7232 : 1438311 : default:
7233 : 1438311 : {
7234 : 1438311 : HOST_WIDE_INT tc = count_type_elements (elt_type, false);
7235 : 1438311 : nz_elts += mult * tc;
7236 : 1438311 : unique_nz_elts += tc;
7237 : 1438311 : init_elts += mult * tc;
7238 : :
7239 : 1438311 : if (const_from_elts_p && const_p)
7240 : 592871 : const_p
7241 : 592871 : = initializer_constant_valid_p (value,
7242 : : elt_type,
7243 : 592871 : TYPE_REVERSE_STORAGE_ORDER
7244 : : (TREE_TYPE (ctor)))
7245 : : != NULL_TREE;
7246 : : }
7247 : : break;
7248 : : }
7249 : : }
7250 : :
7251 : 1511667 : if (*p_complete && !complete_ctor_at_level_p (TREE_TYPE (ctor),
7252 : : num_fields, elt_type))
7253 : 177258 : *p_complete = 0;
7254 : 1334409 : else if (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
7255 : 1334409 : || TREE_CODE (TREE_TYPE (ctor)) == QUAL_UNION_TYPE)
7256 : : {
7257 : 12085 : if (*p_complete
7258 : 7840 : && CONSTRUCTOR_ZERO_PADDING_BITS (ctor)
7259 : 22414 : && (num_fields
7260 : 5166 : ? simple_cst_equal (TYPE_SIZE (TREE_TYPE (ctor)),
7261 : 5163 : TYPE_SIZE (elt_type)) != 1
7262 : 3 : : type_has_padding_at_level_p (TREE_TYPE (ctor))))
7263 : 3407 : *p_complete = 0;
7264 : 8678 : else if (*p_complete > 0
7265 : 12770 : && (num_fields
7266 : 4092 : ? simple_cst_equal (TYPE_SIZE (TREE_TYPE (ctor)),
7267 : 4092 : TYPE_SIZE (elt_type)) != 1
7268 : 0 : : type_has_padding_at_level_p (TREE_TYPE (ctor))))
7269 : 234 : *p_complete = -1;
7270 : : }
7271 : 1322324 : else if (*p_complete
7272 : 1212774 : && (CONSTRUCTOR_ZERO_PADDING_BITS (ctor)
7273 : 1189233 : || flag_zero_init_padding_bits == ZERO_INIT_PADDING_BITS_ALL)
7274 : 1345870 : && type_has_padding_at_level_p (TREE_TYPE (ctor)))
7275 : 2742 : *p_complete = 0;
7276 : 1319582 : else if (*p_complete > 0
7277 : 1319582 : && type_has_padding_at_level_p (TREE_TYPE (ctor)))
7278 : 14906 : *p_complete = -1;
7279 : :
7280 : 1511667 : *p_nz_elts += nz_elts;
7281 : 1511667 : *p_unique_nz_elts += unique_nz_elts;
7282 : 1511667 : *p_init_elts += init_elts;
7283 : :
7284 : 1511667 : return const_p;
7285 : : }
7286 : :
7287 : : /* Examine CTOR to discover:
7288 : : * how many scalar fields are set to nonzero values,
7289 : : and place it in *P_NZ_ELTS;
7290 : : * the same, but counting RANGE_EXPRs as multiplier of 1 instead of
7291 : : high - low + 1 (this can be useful for callers to determine ctors
7292 : : that could be cheaply initialized with - perhaps nested - loops
7293 : : compared to copied from huge read-only data),
7294 : : and place it in *P_UNIQUE_NZ_ELTS;
7295 : : * how many scalar fields in total are in CTOR,
7296 : : and place it in *P_ELT_COUNT.
7297 : : * whether the constructor is complete -- in the sense that every
7298 : : meaningful byte is explicitly given a value --
7299 : : and place it in *P_COMPLETE:
7300 : : - 0 if any field is missing
7301 : : - 1 if all fields are initialized, and there's no padding
7302 : : - -1 if all fields are initialized, but there's padding
7303 : :
7304 : : Return whether or not CTOR is a valid static constant initializer, the same
7305 : : as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
7306 : :
7307 : : bool
7308 : 975813 : categorize_ctor_elements (const_tree ctor, HOST_WIDE_INT *p_nz_elts,
7309 : : HOST_WIDE_INT *p_unique_nz_elts,
7310 : : HOST_WIDE_INT *p_init_elts, int *p_complete)
7311 : : {
7312 : 975813 : *p_nz_elts = 0;
7313 : 975813 : *p_unique_nz_elts = 0;
7314 : 975813 : *p_init_elts = 0;
7315 : 975813 : *p_complete = 1;
7316 : :
7317 : 975813 : return categorize_ctor_elements_1 (ctor, p_nz_elts, p_unique_nz_elts,
7318 : 975813 : p_init_elts, p_complete);
7319 : : }
7320 : :
7321 : : /* Return true if constructor CTOR is simple enough to be materialized
7322 : : in an integer mode register. Limit the size to WORDS words, which
7323 : : is 1 by default. */
7324 : :
7325 : : bool
7326 : 21729 : immediate_const_ctor_p (const_tree ctor, unsigned int words)
7327 : : {
7328 : : /* Allow function to be called with a VAR_DECL's DECL_INITIAL. */
7329 : 21729 : if (!ctor || TREE_CODE (ctor) != CONSTRUCTOR)
7330 : : return false;
7331 : :
7332 : 2743 : return TREE_CONSTANT (ctor)
7333 : 2743 : && !TREE_ADDRESSABLE (ctor)
7334 : 2732 : && CONSTRUCTOR_NELTS (ctor)
7335 : 2708 : && TREE_CODE (TREE_TYPE (ctor)) != ARRAY_TYPE
7336 : 629 : && int_expr_size (ctor) <= words * UNITS_PER_WORD
7337 : 2921 : && initializer_constant_valid_for_bitfield_p (ctor);
7338 : : }
7339 : :
7340 : : /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
7341 : : of which had type LAST_TYPE. Each element was itself a complete
7342 : : initializer, in the sense that every meaningful byte was explicitly
7343 : : given a value. Return true if the same is true for the constructor
7344 : : as a whole. */
7345 : :
7346 : : bool
7347 : 1671411 : complete_ctor_at_level_p (const_tree type, HOST_WIDE_INT num_elts,
7348 : : const_tree last_type)
7349 : : {
7350 : 1671411 : if (TREE_CODE (type) == UNION_TYPE || TREE_CODE (type) == QUAL_UNION_TYPE)
7351 : : {
7352 : 8985 : if (num_elts == 0)
7353 : : {
7354 : 13 : if (flag_zero_init_padding_bits >= ZERO_INIT_PADDING_BITS_UNIONS)
7355 : : return false;
7356 : :
7357 : : /* If the CONSTRUCTOR doesn't have any elts, it is
7358 : : incomplete if the union has at least one field. */
7359 : 16 : for (tree f = TYPE_FIELDS (type); f; f = DECL_CHAIN (f))
7360 : 13 : if (TREE_CODE (f) == FIELD_DECL)
7361 : : return false;
7362 : :
7363 : : return true;
7364 : : }
7365 : :
7366 : 8972 : gcc_assert (num_elts == 1 && last_type);
7367 : :
7368 : 8972 : if (flag_zero_init_padding_bits >= ZERO_INIT_PADDING_BITS_UNIONS)
7369 : : /* ??? We could look at each element of the union, and find the
7370 : : largest element. Which would avoid comparing the size of the
7371 : : initialized element against any tail padding in the union.
7372 : : Doesn't seem worth the effort... */
7373 : 6 : return simple_cst_equal (TYPE_SIZE (type), TYPE_SIZE (last_type)) == 1;
7374 : :
7375 : : return true;
7376 : : }
7377 : :
7378 : 1662426 : return count_type_elements (type, true) == num_elts;
7379 : : }
7380 : :
7381 : : /* Return true if EXP contains mostly (3/4) zeros. */
7382 : :
7383 : : static bool
7384 : 356103 : mostly_zeros_p (const_tree exp)
7385 : : {
7386 : 356103 : if (TREE_CODE (exp) == CONSTRUCTOR)
7387 : : {
7388 : 127 : HOST_WIDE_INT nz_elts, unz_elts, init_elts;
7389 : 127 : int complete_p;
7390 : :
7391 : 127 : categorize_ctor_elements (exp, &nz_elts, &unz_elts, &init_elts,
7392 : : &complete_p);
7393 : 127 : return !complete_p || nz_elts < init_elts / 4;
7394 : : }
7395 : :
7396 : 355976 : return initializer_zerop (exp);
7397 : : }
7398 : :
7399 : : /* Return true if EXP contains all zeros. */
7400 : :
7401 : : static bool
7402 : 1276 : all_zeros_p (const_tree exp)
7403 : : {
7404 : 1276 : if (TREE_CODE (exp) == CONSTRUCTOR)
7405 : : {
7406 : 1276 : HOST_WIDE_INT nz_elts, unz_elts, init_elts;
7407 : 1276 : int complete_p;
7408 : :
7409 : 1276 : categorize_ctor_elements (exp, &nz_elts, &unz_elts, &init_elts,
7410 : : &complete_p);
7411 : 1276 : return nz_elts == 0;
7412 : : }
7413 : :
7414 : 0 : return initializer_zerop (exp);
7415 : : }
7416 : :
7417 : : /* Helper function for store_constructor.
7418 : : TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
7419 : : CLEARED is as for store_constructor.
7420 : : ALIAS_SET is the alias set to use for any stores.
7421 : : If REVERSE is true, the store is to be done in reverse order.
7422 : :
7423 : : This provides a recursive shortcut back to store_constructor when it isn't
7424 : : necessary to go through store_field. This is so that we can pass through
7425 : : the cleared field to let store_constructor know that we may not have to
7426 : : clear a substructure if the outer structure has already been cleared. */
7427 : :
7428 : : static void
7429 : 32408 : store_constructor_field (rtx target, poly_uint64 bitsize, poly_int64 bitpos,
7430 : : poly_uint64 bitregion_start,
7431 : : poly_uint64 bitregion_end,
7432 : : machine_mode mode,
7433 : : tree exp, int cleared,
7434 : : alias_set_type alias_set, bool reverse)
7435 : : {
7436 : 32408 : poly_int64 bytepos;
7437 : 32408 : poly_uint64 bytesize;
7438 : 32408 : if (TREE_CODE (exp) == CONSTRUCTOR
7439 : : /* We can only call store_constructor recursively if the size and
7440 : : bit position are on a byte boundary. */
7441 : 64 : && multiple_p (bitpos, BITS_PER_UNIT, &bytepos)
7442 : 64 : && maybe_ne (bitsize, 0U)
7443 : 32408 : && multiple_p (bitsize, BITS_PER_UNIT, &bytesize)
7444 : : /* If we have a nonzero bitpos for a register target, then we just
7445 : : let store_field do the bitfield handling. This is unlikely to
7446 : : generate unnecessary clear instructions anyways. */
7447 : 32472 : && (known_eq (bitpos, 0) || MEM_P (target)))
7448 : : {
7449 : 64 : if (MEM_P (target))
7450 : : {
7451 : 22 : machine_mode target_mode = GET_MODE (target);
7452 : 22 : if (target_mode != BLKmode
7453 : 22 : && !multiple_p (bitpos, GET_MODE_ALIGNMENT (target_mode)))
7454 : : target_mode = BLKmode;
7455 : 22 : target = adjust_address (target, target_mode, bytepos);
7456 : : }
7457 : :
7458 : :
7459 : : /* Update the alias set, if required. */
7460 : 22 : if (MEM_P (target) && ! MEM_KEEP_ALIAS_SET_P (target)
7461 : 86 : && MEM_ALIAS_SET (target) != 0)
7462 : : {
7463 : 18 : target = copy_rtx (target);
7464 : 18 : set_mem_alias_set (target, alias_set);
7465 : : }
7466 : :
7467 : 64 : store_constructor (exp, target, cleared, bytesize, reverse);
7468 : : }
7469 : : else
7470 : 32344 : store_field (target, bitsize, bitpos, bitregion_start, bitregion_end, mode,
7471 : : exp, alias_set, false, reverse);
7472 : 32408 : }
7473 : :
7474 : :
7475 : : /* Returns the number of FIELD_DECLs in TYPE. */
7476 : :
7477 : : static int
7478 : 68255 : fields_length (const_tree type)
7479 : : {
7480 : 68255 : tree t = TYPE_FIELDS (type);
7481 : 68255 : int count = 0;
7482 : :
7483 : 798081 : for (; t; t = DECL_CHAIN (t))
7484 : 729826 : if (TREE_CODE (t) == FIELD_DECL)
7485 : 300135 : ++count;
7486 : :
7487 : 68255 : return count;
7488 : : }
7489 : :
7490 : :
7491 : : /* Store the value of constructor EXP into the rtx TARGET.
7492 : : TARGET is either a REG or a MEM; we know it cannot conflict, since
7493 : : safe_from_p has been called.
7494 : : CLEARED is true if TARGET is known to have been zero'd.
7495 : : SIZE is the number of bytes of TARGET we are allowed to modify: this
7496 : : may not be the same as the size of EXP if we are assigning to a field
7497 : : which has been packed to exclude padding bits.
7498 : : If REVERSE is true, the store is to be done in reverse order. */
7499 : :
7500 : : void
7501 : 246808 : store_constructor (tree exp, rtx target, int cleared, poly_int64 size,
7502 : : bool reverse)
7503 : : {
7504 : 246808 : tree type = TREE_TYPE (exp);
7505 : 246808 : HOST_WIDE_INT exp_size = int_size_in_bytes (type);
7506 : 246808 : poly_int64 bitregion_end = known_gt (size, 0) ? size * BITS_PER_UNIT - 1 : 0;
7507 : :
7508 : 246808 : switch (TREE_CODE (type))
7509 : : {
7510 : 68655 : case RECORD_TYPE:
7511 : 68655 : case UNION_TYPE:
7512 : 68655 : case QUAL_UNION_TYPE:
7513 : 68655 : {
7514 : 68655 : unsigned HOST_WIDE_INT idx;
7515 : 68655 : tree field, value;
7516 : :
7517 : : /* The storage order is specified for every aggregate type. */
7518 : 68655 : reverse = TYPE_REVERSE_STORAGE_ORDER (type);
7519 : :
7520 : : /* If size is zero or the target is already cleared, do nothing. */
7521 : 68655 : if (known_eq (size, 0) || cleared)
7522 : : cleared = 1;
7523 : : /* We either clear the aggregate or indicate the value is dead. */
7524 : 68655 : else if ((TREE_CODE (type) == UNION_TYPE
7525 : 68655 : || TREE_CODE (type) == QUAL_UNION_TYPE)
7526 : 68898 : && ! CONSTRUCTOR_ELTS (exp))
7527 : : /* If the constructor is empty, clear the union. */
7528 : : {
7529 : 194 : clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
7530 : 194 : cleared = 1;
7531 : : }
7532 : :
7533 : : /* If we are building a static constructor into a register,
7534 : : set the initial value as zero so we can fold the value into
7535 : : a constant. But if more than one register is involved,
7536 : : this probably loses. */
7537 : 4178 : else if (REG_P (target) && TREE_STATIC (exp)
7538 : 69019 : && known_le (GET_MODE_SIZE (GET_MODE (target)),
7539 : : REGMODE_NATURAL_SIZE (GET_MODE (target))))
7540 : : {
7541 : 206 : emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
7542 : 206 : cleared = 1;
7543 : : }
7544 : :
7545 : : /* If the constructor has fewer fields than the structure or
7546 : : if we are initializing the structure to mostly zeros, clear
7547 : : the whole structure first. Don't do this if TARGET is a
7548 : : register whose mode size isn't equal to SIZE since
7549 : : clear_storage can't handle this case. */
7550 : 68255 : else if (known_size_p (size)
7551 : 68354 : && (((int) CONSTRUCTOR_NELTS (exp) != fields_length (type))
7552 : 86 : || mostly_zeros_p (exp))
7553 : 136428 : && (!REG_P (target)
7554 : 7940 : || known_eq (GET_MODE_SIZE (GET_MODE (target)), size)))
7555 : : {
7556 : 78874 : clear_storage (target, gen_int_mode (size, Pmode),
7557 : : BLOCK_OP_NORMAL);
7558 : 68173 : cleared = 1;
7559 : : }
7560 : :
7561 : 68655 : if (REG_P (target) && !cleared)
7562 : 2 : emit_clobber (target);
7563 : :
7564 : : /* Store each element of the constructor into the
7565 : : corresponding field of TARGET. */
7566 : 68892 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, field, value)
7567 : : {
7568 : 237 : machine_mode mode;
7569 : 237 : HOST_WIDE_INT bitsize;
7570 : 237 : HOST_WIDE_INT bitpos = 0;
7571 : 237 : tree offset;
7572 : 237 : rtx to_rtx = target;
7573 : :
7574 : : /* Just ignore missing fields. We cleared the whole
7575 : : structure, above, if any fields are missing. */
7576 : 237 : if (field == 0)
7577 : 237 : continue;
7578 : :
7579 : 237 : if (cleared && initializer_zerop (value))
7580 : 4 : continue;
7581 : :
7582 : 233 : if (tree_fits_uhwi_p (DECL_SIZE (field)))
7583 : 233 : bitsize = tree_to_uhwi (DECL_SIZE (field));
7584 : : else
7585 : 0 : gcc_unreachable ();
7586 : :
7587 : 233 : mode = DECL_MODE (field);
7588 : 233 : if (DECL_BIT_FIELD (field))
7589 : 24 : mode = VOIDmode;
7590 : :
7591 : 233 : offset = DECL_FIELD_OFFSET (field);
7592 : 233 : if (tree_fits_shwi_p (offset)
7593 : 233 : && tree_fits_shwi_p (bit_position (field)))
7594 : : {
7595 : 233 : bitpos = int_bit_position (field);
7596 : 233 : offset = NULL_TREE;
7597 : : }
7598 : : else
7599 : 0 : gcc_unreachable ();
7600 : :
7601 : : /* If this initializes a field that is smaller than a
7602 : : word, at the start of a word, try to widen it to a full
7603 : : word. This special case allows us to output C++ member
7604 : : function initializations in a form that the optimizers
7605 : : can understand. */
7606 : 233 : if (WORD_REGISTER_OPERATIONS
7607 : : && REG_P (target)
7608 : : && bitsize < BITS_PER_WORD
7609 : : && bitpos % BITS_PER_WORD == 0
7610 : : && GET_MODE_CLASS (mode) == MODE_INT
7611 : : && TREE_CODE (value) == INTEGER_CST
7612 : : && exp_size >= 0
7613 : : && bitpos + BITS_PER_WORD <= exp_size * BITS_PER_UNIT)
7614 : : {
7615 : : type = TREE_TYPE (value);
7616 : :
7617 : : if (TYPE_PRECISION (type) < BITS_PER_WORD)
7618 : : {
7619 : : type = lang_hooks.types.type_for_mode
7620 : : (word_mode, TYPE_UNSIGNED (type));
7621 : : value = fold_convert (type, value);
7622 : : /* Make sure the bits beyond the original bitsize are zero
7623 : : so that we can correctly avoid extra zeroing stores in
7624 : : later constructor elements. */
7625 : : tree bitsize_mask
7626 : : = wide_int_to_tree (type, wi::mask (bitsize, false,
7627 : : BITS_PER_WORD));
7628 : : value = fold_build2 (BIT_AND_EXPR, type, value, bitsize_mask);
7629 : : }
7630 : :
7631 : : if (BYTES_BIG_ENDIAN)
7632 : : value
7633 : : = fold_build2 (LSHIFT_EXPR, type, value,
7634 : : build_int_cst (type,
7635 : : BITS_PER_WORD - bitsize));
7636 : : bitsize = BITS_PER_WORD;
7637 : : mode = word_mode;
7638 : : }
7639 : :
7640 : 118 : if (MEM_P (to_rtx) && !MEM_KEEP_ALIAS_SET_P (to_rtx)
7641 : 351 : && DECL_NONADDRESSABLE_P (field))
7642 : : {
7643 : 0 : to_rtx = copy_rtx (to_rtx);
7644 : 0 : MEM_KEEP_ALIAS_SET_P (to_rtx) = 1;
7645 : : }
7646 : :
7647 : 233 : store_constructor_field (to_rtx, bitsize, bitpos,
7648 : 233 : 0, bitregion_end, mode,
7649 : : value, cleared,
7650 : 233 : get_alias_set (TREE_TYPE (field)),
7651 : : reverse);
7652 : : }
7653 : : break;
7654 : : }
7655 : 38735 : case ARRAY_TYPE:
7656 : 38735 : {
7657 : 38735 : tree value, index;
7658 : 38735 : unsigned HOST_WIDE_INT i, j = 0;
7659 : 38735 : bool need_to_clear;
7660 : 38735 : tree domain;
7661 : 38735 : tree elttype = TREE_TYPE (type);
7662 : 38735 : bool const_bounds_p;
7663 : 38735 : unsigned HOST_WIDE_INT minelt = 0;
7664 : 38735 : unsigned HOST_WIDE_INT maxelt = 0;
7665 : :
7666 : : /* The storage order is specified for every aggregate type. */
7667 : 38735 : reverse = TYPE_REVERSE_STORAGE_ORDER (type);
7668 : :
7669 : 38735 : domain = TYPE_DOMAIN (type);
7670 : 38735 : const_bounds_p = (TYPE_MIN_VALUE (domain)
7671 : 38735 : && TYPE_MAX_VALUE (domain)
7672 : 38735 : && tree_fits_uhwi_p (TYPE_MIN_VALUE (domain))
7673 : 77470 : && tree_fits_uhwi_p (TYPE_MAX_VALUE (domain)));
7674 : :
7675 : : /* If we have constant bounds for the range of the type, get them. */
7676 : 38735 : if (const_bounds_p)
7677 : : {
7678 : 38735 : minelt = tree_to_uhwi (TYPE_MIN_VALUE (domain));
7679 : 38735 : maxelt = tree_to_uhwi (TYPE_MAX_VALUE (domain));
7680 : : }
7681 : :
7682 : : /* If the constructor has fewer elements than the array, clear
7683 : : the whole array first. Similarly if this is static
7684 : : constructor of a non-BLKmode object. */
7685 : 38735 : if (cleared)
7686 : : need_to_clear = false;
7687 : 38689 : else if (REG_P (target) && TREE_STATIC (exp))
7688 : : need_to_clear = true;
7689 : : else
7690 : : {
7691 : 38586 : unsigned HOST_WIDE_INT idx;
7692 : 38586 : unsigned HOST_WIDE_INT count = 0, zero_count = 0;
7693 : 38586 : need_to_clear = ! const_bounds_p;
7694 : :
7695 : : /* This loop is a more accurate version of the loop in
7696 : : mostly_zeros_p (it handles RANGE_EXPR in an index). It
7697 : : is also needed to check for missing elements. */
7698 : 38634 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, index, value)
7699 : : {
7700 : 48 : unsigned HOST_WIDE_INT this_node_count;
7701 : :
7702 : 48 : if (need_to_clear)
7703 : : break;
7704 : :
7705 : 48 : if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
7706 : : {
7707 : 0 : tree lo_index = TREE_OPERAND (index, 0);
7708 : 0 : tree hi_index = TREE_OPERAND (index, 1);
7709 : :
7710 : 0 : if (! tree_fits_uhwi_p (lo_index)
7711 : 0 : || ! tree_fits_uhwi_p (hi_index))
7712 : : {
7713 : : need_to_clear = true;
7714 : : break;
7715 : : }
7716 : :
7717 : 0 : this_node_count = (tree_to_uhwi (hi_index)
7718 : 0 : - tree_to_uhwi (lo_index) + 1);
7719 : 0 : }
7720 : 48 : else if (TREE_CODE (value) == RAW_DATA_CST)
7721 : 0 : this_node_count = RAW_DATA_LENGTH (value);
7722 : : else
7723 : : this_node_count = 1;
7724 : :
7725 : 48 : count += this_node_count;
7726 : 48 : if (mostly_zeros_p (value))
7727 : 0 : zero_count += this_node_count;
7728 : : }
7729 : :
7730 : : /* Clear the entire array first if there are any missing
7731 : : elements, or if the incidence of zero elements is >=
7732 : : 75%. */
7733 : 38586 : if (! need_to_clear
7734 : 38586 : && (count < maxelt - minelt + 1
7735 : 6 : || 4 * zero_count >= 3 * count))
7736 : : need_to_clear = true;
7737 : : }
7738 : :
7739 : 38683 : if (need_to_clear && maybe_gt (size, 0))
7740 : : {
7741 : 38683 : if (REG_P (target))
7742 : 1628 : emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
7743 : : else
7744 : 41812 : clear_storage (target, gen_int_mode (size, Pmode),
7745 : : BLOCK_OP_NORMAL);
7746 : : cleared = 1;
7747 : : }
7748 : :
7749 : 52 : if (!cleared && REG_P (target))
7750 : : /* Inform later passes that the old value is dead. */
7751 : 0 : emit_clobber (target);
7752 : :
7753 : : /* Store each element of the constructor into the
7754 : : corresponding element of TARGET, determined by counting the
7755 : : elements. */
7756 : 39891 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), i, index, value)
7757 : : {
7758 : 1156 : machine_mode mode;
7759 : 1156 : poly_int64 bitsize;
7760 : 1156 : HOST_WIDE_INT bitpos;
7761 : 1156 : rtx xtarget = target;
7762 : :
7763 : 1156 : if (cleared && initializer_zerop (value))
7764 : : {
7765 : 672 : if (TREE_CODE (value) == RAW_DATA_CST)
7766 : 0 : j += RAW_DATA_LENGTH (value) - 1;
7767 : 674 : continue;
7768 : : }
7769 : :
7770 : 484 : mode = TYPE_MODE (elttype);
7771 : 484 : if (mode != BLKmode)
7772 : 968 : bitsize = GET_MODE_BITSIZE (mode);
7773 : 0 : else if (!poly_int_tree_p (TYPE_SIZE (elttype), &bitsize))
7774 : 0 : bitsize = -1;
7775 : :
7776 : 484 : if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
7777 : : {
7778 : 0 : tree lo_index = TREE_OPERAND (index, 0);
7779 : 0 : tree hi_index = TREE_OPERAND (index, 1);
7780 : 0 : rtx index_r;
7781 : 0 : unsigned HOST_WIDE_INT lo, hi, count;
7782 : 0 : tree offset;
7783 : :
7784 : 0 : gcc_assert (TREE_CODE (value) != RAW_DATA_CST);
7785 : :
7786 : : /* If the range is constant and "small", unroll the loop. */
7787 : 0 : if (const_bounds_p
7788 : 0 : && tree_fits_uhwi_p (lo_index)
7789 : 0 : && tree_fits_uhwi_p (hi_index)
7790 : 0 : && (lo = tree_to_uhwi (lo_index),
7791 : 0 : hi = tree_to_uhwi (hi_index),
7792 : 0 : count = hi - lo + 1,
7793 : 0 : (!MEM_P (target)
7794 : 0 : || count <= 2
7795 : 0 : || (tree_fits_uhwi_p (TYPE_SIZE (elttype))
7796 : 0 : && (tree_to_uhwi (TYPE_SIZE (elttype)) * count
7797 : : <= 40 * 8)))))
7798 : : {
7799 : 0 : lo -= minelt; hi -= minelt;
7800 : 0 : for (; lo <= hi; lo++)
7801 : : {
7802 : 0 : bitpos = lo * tree_to_uhwi (TYPE_SIZE (elttype));
7803 : :
7804 : 0 : if (MEM_P (target)
7805 : 0 : && !MEM_KEEP_ALIAS_SET_P (target)
7806 : 0 : && TREE_CODE (type) == ARRAY_TYPE
7807 : 0 : && TYPE_NONALIASED_COMPONENT (type))
7808 : : {
7809 : 0 : target = copy_rtx (target);
7810 : 0 : MEM_KEEP_ALIAS_SET_P (target) = 1;
7811 : : }
7812 : :
7813 : 0 : store_constructor_field
7814 : 0 : (target, bitsize, bitpos, 0, bitregion_end,
7815 : : mode, value, cleared,
7816 : : get_alias_set (elttype), reverse);
7817 : : }
7818 : : }
7819 : : else
7820 : : {
7821 : 0 : rtx_code_label *loop_start = gen_label_rtx ();
7822 : 0 : rtx_code_label *loop_end = gen_label_rtx ();
7823 : 0 : tree exit_cond;
7824 : :
7825 : 0 : expand_normal (hi_index);
7826 : :
7827 : 0 : index = build_decl (EXPR_LOCATION (exp),
7828 : : VAR_DECL, NULL_TREE, domain);
7829 : 0 : index_r = gen_reg_rtx (promote_decl_mode (index, NULL));
7830 : 0 : SET_DECL_RTL (index, index_r);
7831 : 0 : store_expr (lo_index, index_r, 0, false, reverse);
7832 : :
7833 : : /* Build the head of the loop. */
7834 : 0 : do_pending_stack_adjust ();
7835 : 0 : emit_label (loop_start);
7836 : :
7837 : : /* Assign value to element index. */
7838 : 0 : offset = fold_build2 (MINUS_EXPR,
7839 : : TREE_TYPE (index),
7840 : : index,
7841 : : TYPE_MIN_VALUE (domain));
7842 : :
7843 : 0 : offset = size_binop (MULT_EXPR,
7844 : : fold_convert (sizetype, offset),
7845 : : TYPE_SIZE_UNIT (elttype));
7846 : :
7847 : 0 : xtarget = offset_address (target,
7848 : : expand_normal (offset),
7849 : : highest_pow2_factor (offset));
7850 : 0 : xtarget = adjust_address (xtarget, mode, 0);
7851 : 0 : if (TREE_CODE (value) == CONSTRUCTOR)
7852 : 0 : store_constructor (value, xtarget, cleared,
7853 : : exact_div (bitsize, BITS_PER_UNIT),
7854 : : reverse);
7855 : : else
7856 : 0 : store_expr (value, xtarget, 0, false, reverse);
7857 : :
7858 : : /* Generate a conditional jump to exit the loop. */
7859 : 0 : exit_cond = build2 (LT_EXPR, integer_type_node,
7860 : : index, hi_index);
7861 : 0 : jumpif (exit_cond, loop_end,
7862 : : profile_probability::uninitialized ());
7863 : :
7864 : : /* Update the loop counter, and jump to the head of
7865 : : the loop. */
7866 : 0 : expand_assignment (index,
7867 : 0 : build2 (PLUS_EXPR, TREE_TYPE (index),
7868 : : index, integer_one_node),
7869 : : false);
7870 : :
7871 : 0 : emit_jump (loop_start);
7872 : :
7873 : : /* Build the end of the loop. */
7874 : 0 : emit_label (loop_end);
7875 : : }
7876 : : }
7877 : 484 : else if ((index && !tree_fits_uhwi_p (index))
7878 : 484 : || !tree_fits_uhwi_p (TYPE_SIZE (elttype)))
7879 : : {
7880 : 0 : tree offset;
7881 : :
7882 : 0 : gcc_assert (TREE_CODE (value) != RAW_DATA_CST);
7883 : 0 : if (index)
7884 : 0 : offset = fold_build2 (MINUS_EXPR,
7885 : : TREE_TYPE (index),
7886 : : index,
7887 : : TYPE_MIN_VALUE (domain));
7888 : : else
7889 : 0 : offset = size_int (i + j);
7890 : :
7891 : 0 : offset = size_binop (MULT_EXPR,
7892 : : fold_convert (sizetype, offset),
7893 : : TYPE_SIZE_UNIT (elttype));
7894 : 0 : xtarget = offset_address (target,
7895 : : expand_normal (offset),
7896 : : highest_pow2_factor (offset));
7897 : 0 : xtarget = adjust_address (xtarget, mode, 0);
7898 : 0 : store_expr (value, xtarget, 0, false, reverse);
7899 : : }
7900 : : else
7901 : : {
7902 : 484 : if (index)
7903 : 968 : bitpos = ((tree_to_uhwi (index) - minelt)
7904 : 484 : * tree_to_uhwi (TYPE_SIZE (elttype)));
7905 : : else
7906 : 0 : bitpos = ((i + j) * tree_to_uhwi (TYPE_SIZE (elttype)));
7907 : :
7908 : 52 : if (MEM_P (target) && !MEM_KEEP_ALIAS_SET_P (target)
7909 : 52 : && TREE_CODE (type) == ARRAY_TYPE
7910 : 536 : && TYPE_NONALIASED_COMPONENT (type))
7911 : : {
7912 : 0 : target = copy_rtx (target);
7913 : 0 : MEM_KEEP_ALIAS_SET_P (target) = 1;
7914 : : }
7915 : 484 : if (TREE_CODE (value) != RAW_DATA_CST)
7916 : 480 : store_constructor_field (target, bitsize, bitpos, 0,
7917 : 480 : bitregion_end, mode, value,
7918 : : cleared, get_alias_set (elttype),
7919 : : reverse);
7920 : : else
7921 : : {
7922 : 4 : j += RAW_DATA_LENGTH (value) - 1;
7923 : 4 : gcc_assert (known_eq (bitsize, BITS_PER_UNIT));
7924 : 4 : rtx to_rtx = adjust_address (target, mode,
7925 : : bitpos / BITS_PER_UNIT);
7926 : :
7927 : 4 : if (to_rtx == target)
7928 : 0 : to_rtx = copy_rtx (to_rtx);
7929 : :
7930 : 4 : if (!MEM_KEEP_ALIAS_SET_P (to_rtx)
7931 : 8 : && MEM_ALIAS_SET (to_rtx) != 0)
7932 : 0 : set_mem_alias_set (to_rtx, get_alias_set (elttype));
7933 : :
7934 : 8 : if (can_store_by_pieces (RAW_DATA_LENGTH (value),
7935 : : raw_data_cst_read_str,
7936 : : (void *) value,
7937 : 4 : MEM_ALIGN (target), false))
7938 : : {
7939 : 4 : store_by_pieces (target, RAW_DATA_LENGTH (value),
7940 : : raw_data_cst_read_str, (void *) value,
7941 : 2 : MEM_ALIGN (target), false,
7942 : : RETURN_BEGIN);
7943 : 2 : continue;
7944 : : }
7945 : :
7946 : 2 : elttype
7947 : 2 : = build_array_type_nelts (TREE_TYPE (value),
7948 : 2 : RAW_DATA_LENGTH (value));
7949 : 2 : tree ctor = build_constructor_single (elttype, NULL_TREE,
7950 : : value);
7951 : 2 : ctor = tree_output_constant_def (ctor);
7952 : 2 : mode = TYPE_MODE (type);
7953 : 2 : store_constructor_field (target,
7954 : 2 : bitsize * RAW_DATA_LENGTH (value),
7955 : 2 : bitpos, 0, bitregion_end, mode,
7956 : : ctor, cleared,
7957 : : get_alias_set (elttype), reverse);
7958 : : }
7959 : : }
7960 : : }
7961 : : break;
7962 : : }
7963 : :
7964 : 139418 : case VECTOR_TYPE:
7965 : 139418 : {
7966 : 139418 : unsigned HOST_WIDE_INT idx;
7967 : 139418 : constructor_elt *ce;
7968 : 139418 : bool need_to_clear;
7969 : 139418 : insn_code icode = CODE_FOR_nothing;
7970 : 139418 : tree elt;
7971 : 139418 : tree elttype = TREE_TYPE (type);
7972 : 139418 : int elt_size = vector_element_bits (type);
7973 : 139418 : machine_mode eltmode = TYPE_MODE (elttype);
7974 : 139418 : poly_int64 bitsize;
7975 : 139418 : poly_int64 bitpos;
7976 : 139418 : rtvec vector = NULL;
7977 : 139418 : poly_uint64 n_elts;
7978 : 139418 : unsigned HOST_WIDE_INT const_n_elts;
7979 : 139418 : alias_set_type alias;
7980 : 139418 : bool vec_vec_init_p = false;
7981 : 139418 : machine_mode mode = GET_MODE (target);
7982 : :
7983 : 139418 : gcc_assert (eltmode != BLKmode);
7984 : :
7985 : : /* Try using vec_duplicate_optab for uniform vectors. */
7986 : 139418 : icode = optab_handler (vec_duplicate_optab, mode);
7987 : 139418 : if (!TREE_SIDE_EFFECTS (exp)
7988 : 139418 : && VECTOR_MODE_P (mode)
7989 : 136233 : && icode != CODE_FOR_nothing
7990 : : /* If the vec_duplicate target pattern does not specify an element
7991 : : mode check that eltmode is the normal inner mode of the
7992 : : requested vector mode. But if the target allows eltmode
7993 : : explicitly go ahead and use it. */
7994 : 94878 : && (eltmode == GET_MODE_INNER (mode)
7995 : 0 : || insn_data[icode].operand[1].mode == eltmode)
7996 : 94878 : && (elt = uniform_vector_p (exp))
7997 : 157150 : && !VECTOR_TYPE_P (TREE_TYPE (elt)))
7998 : : {
7999 : 17732 : class expand_operand ops[2];
8000 : 17732 : create_output_operand (&ops[0], target, mode);
8001 : 17732 : create_input_operand (&ops[1], expand_normal (elt), eltmode);
8002 : 17732 : expand_insn (icode, 2, ops);
8003 : 17732 : if (!rtx_equal_p (target, ops[0].value))
8004 : 0 : emit_move_insn (target, ops[0].value);
8005 : 17732 : break;
8006 : : }
8007 : : /* Use sign-extension for uniform boolean vectors with
8008 : : integer modes and single-bit mask entries.
8009 : : Effectively "vec_duplicate" for bitmasks. */
8010 : 121686 : if (elt_size == 1
8011 : 146 : && !TREE_SIDE_EFFECTS (exp)
8012 : 146 : && VECTOR_BOOLEAN_TYPE_P (type)
8013 : 146 : && SCALAR_INT_MODE_P (TYPE_MODE (type))
8014 : 146 : && (elt = uniform_vector_p (exp))
8015 : 121829 : && !VECTOR_TYPE_P (TREE_TYPE (elt)))
8016 : : {
8017 : 143 : rtx op0 = force_reg (TYPE_MODE (TREE_TYPE (elt)),
8018 : : expand_normal (elt));
8019 : 143 : rtx tmp = gen_reg_rtx (mode);
8020 : 143 : convert_move (tmp, op0, 0);
8021 : :
8022 : : /* Ensure no excess bits are set.
8023 : : GCN needs this for nunits < 64.
8024 : : x86 needs this for nunits < 8. */
8025 : 143 : auto nunits = TYPE_VECTOR_SUBPARTS (type).to_constant ();
8026 : 143 : if (maybe_ne (GET_MODE_PRECISION (mode), nunits))
8027 : 2 : tmp = expand_binop (mode, and_optab, tmp,
8028 : 2 : GEN_INT ((HOST_WIDE_INT_1U << nunits) - 1),
8029 : : target, true, OPTAB_WIDEN);
8030 : 143 : if (tmp != target)
8031 : 141 : emit_move_insn (target, tmp);
8032 : : break;
8033 : : }
8034 : :
8035 : 121543 : n_elts = TYPE_VECTOR_SUBPARTS (type);
8036 : 121543 : if (REG_P (target)
8037 : 118662 : && VECTOR_MODE_P (mode))
8038 : : {
8039 : 118501 : const_n_elts = 0;
8040 : 118501 : if (CONSTRUCTOR_NELTS (exp)
8041 : 118501 : && (TREE_CODE (TREE_TYPE (CONSTRUCTOR_ELT (exp, 0)->value))
8042 : : == VECTOR_TYPE))
8043 : : {
8044 : 1094 : tree etype = TREE_TYPE (CONSTRUCTOR_ELT (exp, 0)->value);
8045 : 1094 : gcc_assert (known_eq (CONSTRUCTOR_NELTS (exp)
8046 : : * TYPE_VECTOR_SUBPARTS (etype),
8047 : : n_elts));
8048 : :
8049 : 3282 : icode = convert_optab_handler (vec_init_optab, mode,
8050 : 1094 : TYPE_MODE (etype));
8051 : 1094 : const_n_elts = CONSTRUCTOR_NELTS (exp);
8052 : 1094 : vec_vec_init_p = icode != CODE_FOR_nothing;
8053 : : }
8054 : 234814 : else if (exact_div (n_elts, GET_MODE_NUNITS (eltmode))
8055 : 117407 : .is_constant (&const_n_elts))
8056 : : {
8057 : : /* For a non-const type vector, we check it is made up of
8058 : : similarly non-const type vectors. */
8059 : 117407 : icode = convert_optab_handler (vec_init_optab, mode, eltmode);
8060 : : }
8061 : :
8062 : 118501 : if (const_n_elts && icode != CODE_FOR_nothing)
8063 : : {
8064 : 117860 : vector = rtvec_alloc (const_n_elts);
8065 : 436382 : for (unsigned int k = 0; k < const_n_elts; k++)
8066 : 318522 : RTVEC_ELT (vector, k) = CONST0_RTX (eltmode);
8067 : : }
8068 : : }
8069 : :
8070 : : /* Compute the size of the elements in the CTOR. It differs
8071 : : from the size of the vector type elements only when the
8072 : : CTOR elements are vectors themselves. */
8073 : 121543 : tree val_type = (CONSTRUCTOR_NELTS (exp) != 0
8074 : 121543 : ? TREE_TYPE (CONSTRUCTOR_ELT (exp, 0)->value)
8075 : 121543 : : elttype);
8076 : 121543 : if (VECTOR_TYPE_P (val_type))
8077 : 1397 : bitsize = tree_to_poly_uint64 (TYPE_SIZE (val_type));
8078 : : else
8079 : 120146 : bitsize = elt_size;
8080 : :
8081 : : /* If the constructor has fewer elements than the vector,
8082 : : clear the whole array first. Similarly if this is static
8083 : : constructor of a non-BLKmode object. */
8084 : 121543 : if (cleared)
8085 : : need_to_clear = false;
8086 : 121543 : else if (REG_P (target) && TREE_STATIC (exp))
8087 : : need_to_clear = true;
8088 : : else
8089 : : {
8090 : : poly_uint64 count = 0, zero_count = 0;
8091 : : tree value;
8092 : :
8093 : 477471 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
8094 : : {
8095 : 355928 : poly_int64 n_elts_here = exact_div (bitsize, elt_size);
8096 : 355928 : count += n_elts_here;
8097 : 355928 : if (mostly_zeros_p (value))
8098 : 355928 : zero_count += n_elts_here;
8099 : : }
8100 : :
8101 : : /* Clear the entire vector first if there are any missing elements,
8102 : : or if the incidence of zero elements is >= 75%. */
8103 : 121543 : need_to_clear = (maybe_lt (count, n_elts)
8104 : 121543 : || maybe_gt (4 * zero_count, 3 * count));
8105 : : }
8106 : :
8107 : 1020 : if (need_to_clear && maybe_gt (size, 0) && !vector)
8108 : : {
8109 : 660 : if (REG_P (target))
8110 : 1 : emit_move_insn (target, CONST0_RTX (mode));
8111 : : else
8112 : 659 : clear_storage (target, gen_int_mode (size, Pmode),
8113 : : BLOCK_OP_NORMAL);
8114 : : cleared = 1;
8115 : : }
8116 : :
8117 : : /* Inform later passes that the old value is dead. */
8118 : 121543 : if (!cleared && !vector && REG_P (target) && maybe_gt (n_elts, 1u))
8119 : : {
8120 : 484 : emit_move_insn (target, CONST0_RTX (mode));
8121 : 484 : cleared = 1;
8122 : : }
8123 : :
8124 : 121543 : if (MEM_P (target))
8125 : 2881 : alias = MEM_ALIAS_SET (target);
8126 : : else
8127 : 118662 : alias = get_alias_set (elttype);
8128 : :
8129 : : /* Store each element of the constructor into the corresponding
8130 : : element of TARGET, determined by counting the elements. */
8131 : 121543 : HOST_WIDE_INT chunk_size = 0;
8132 : 121543 : bool chunk_multiple_p = constant_multiple_p (bitsize, elt_size,
8133 : : &chunk_size);
8134 : 121543 : gcc_assert (chunk_multiple_p || vec_vec_init_p);
8135 : :
8136 : 477471 : for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (exp), idx, &ce);
8137 : : idx++)
8138 : : {
8139 : 355928 : HOST_WIDE_INT eltpos;
8140 : 355928 : tree value = ce->value;
8141 : :
8142 : 355928 : if (cleared && initializer_zerop (value))
8143 : 6657 : continue;
8144 : :
8145 : 349271 : if (ce->index)
8146 : 44483 : eltpos = tree_to_uhwi (ce->index);
8147 : : else
8148 : 304788 : eltpos = idx * chunk_size;
8149 : :
8150 : 349271 : if (vector)
8151 : : {
8152 : 317578 : if (vec_vec_init_p)
8153 : : {
8154 : 2172 : gcc_assert (ce->index == NULL_TREE);
8155 : 2172 : gcc_assert (TREE_CODE (TREE_TYPE (value)) == VECTOR_TYPE);
8156 : 2172 : eltpos = idx;
8157 : : }
8158 : : else
8159 : 315406 : gcc_assert (TREE_CODE (TREE_TYPE (value)) != VECTOR_TYPE);
8160 : 317578 : RTVEC_ELT (vector, eltpos) = expand_normal (value);
8161 : : }
8162 : : else
8163 : : {
8164 : 31693 : machine_mode value_mode
8165 : 31693 : = (TREE_CODE (TREE_TYPE (value)) == VECTOR_TYPE
8166 : 31693 : ? TYPE_MODE (TREE_TYPE (value)) : eltmode);
8167 : 31693 : bitpos = eltpos * elt_size;
8168 : 31693 : store_constructor_field (target, bitsize, bitpos, 0,
8169 : 31693 : bitregion_end, value_mode,
8170 : : value, cleared, alias, reverse);
8171 : : }
8172 : : }
8173 : :
8174 : 121543 : if (vector)
8175 : 117860 : emit_insn (GEN_FCN (icode) (target,
8176 : : gen_rtx_PARALLEL (mode, vector)));
8177 : : break;
8178 : : }
8179 : :
8180 : 0 : default:
8181 : 0 : gcc_unreachable ();
8182 : : }
8183 : 246808 : }
8184 : :
8185 : : /* Store the value of EXP (an expression tree)
8186 : : into a subfield of TARGET which has mode MODE and occupies
8187 : : BITSIZE bits, starting BITPOS bits from the start of TARGET.
8188 : : If MODE is VOIDmode, it means that we are storing into a bit-field.
8189 : :
8190 : : BITREGION_START is bitpos of the first bitfield in this region.
8191 : : BITREGION_END is the bitpos of the ending bitfield in this region.
8192 : : These two fields are 0, if the C++ memory model does not apply,
8193 : : or we are not interested in keeping track of bitfield regions.
8194 : :
8195 : : Always return const0_rtx unless we have something particular to
8196 : : return.
8197 : :
8198 : : ALIAS_SET is the alias set for the destination. This value will
8199 : : (in general) be different from that for TARGET, since TARGET is a
8200 : : reference to the containing structure.
8201 : :
8202 : : If NONTEMPORAL is true, try generating a nontemporal store.
8203 : :
8204 : : If REVERSE is true, the store is to be done in reverse order. */
8205 : :
8206 : : static rtx
8207 : 4769091 : store_field (rtx target, poly_int64 bitsize, poly_int64 bitpos,
8208 : : poly_uint64 bitregion_start, poly_uint64 bitregion_end,
8209 : : machine_mode mode, tree exp,
8210 : : alias_set_type alias_set, bool nontemporal, bool reverse)
8211 : : {
8212 : 4769091 : if (TREE_CODE (exp) == ERROR_MARK)
8213 : 0 : return const0_rtx;
8214 : :
8215 : : /* If we have nothing to store, do nothing unless the expression has
8216 : : side-effects. Don't do that for zero sized addressable lhs of
8217 : : calls. */
8218 : 4769091 : if (known_eq (bitsize, 0)
8219 : 4769091 : && (!TREE_ADDRESSABLE (TREE_TYPE (exp))
8220 : 3 : || TREE_CODE (exp) != CALL_EXPR))
8221 : 0 : return expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL);
8222 : :
8223 : 4769091 : if (GET_CODE (target) == CONCAT)
8224 : : {
8225 : : /* We're storing into a struct containing a single __complex. */
8226 : :
8227 : 0 : gcc_assert (known_eq (bitpos, 0));
8228 : 0 : return store_expr (exp, target, 0, nontemporal, reverse);
8229 : : }
8230 : :
8231 : : /* If the structure is in a register or if the component
8232 : : is a bit field, we cannot use addressing to access it.
8233 : : Use bit-field techniques or SUBREG to store in it. */
8234 : :
8235 : 4769091 : poly_int64 decl_bitsize;
8236 : 4769091 : if (mode == VOIDmode
8237 : 4697853 : || (mode != BLKmode && ! direct_store[(int) mode]
8238 : 5330 : && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
8239 : 5328 : && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT)
8240 : 4692558 : || REG_P (target)
8241 : 3995209 : || GET_CODE (target) == SUBREG
8242 : : /* If the field isn't aligned enough to store as an ordinary memref,
8243 : : store it as a bit field. */
8244 : 3995209 : || (mode != BLKmode
8245 : 3875794 : && ((((MEM_ALIGN (target) < GET_MODE_ALIGNMENT (mode))
8246 : 7664670 : || !multiple_p (bitpos, GET_MODE_ALIGNMENT (mode)))
8247 : 46257 : && targetm.slow_unaligned_access (mode, MEM_ALIGN (target)))
8248 : 3875794 : || !multiple_p (bitpos, BITS_PER_UNIT)))
8249 : 3995209 : || (known_size_p (bitsize)
8250 : 3995197 : && mode != BLKmode
8251 : 3875794 : && maybe_gt (GET_MODE_BITSIZE (mode), bitsize))
8252 : : /* If the RHS and field are a constant size and the size of the
8253 : : RHS isn't the same size as the bitfield, we must use bitfield
8254 : : operations. */
8255 : 3995200 : || (known_size_p (bitsize)
8256 : 3995188 : && poly_int_tree_p (TYPE_SIZE (TREE_TYPE (exp)))
8257 : 3995188 : && maybe_ne (wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (exp))),
8258 : : bitsize)
8259 : : /* Except for initialization of full bytes from a CONSTRUCTOR, which
8260 : : we will handle specially below. */
8261 : 33 : && !(TREE_CODE (exp) == CONSTRUCTOR
8262 : 11 : && multiple_p (bitsize, BITS_PER_UNIT))
8263 : : /* And except for bitwise copying of TREE_ADDRESSABLE types,
8264 : : where the FIELD_DECL has the right bitsize, but TREE_TYPE (exp)
8265 : : includes some extra padding. store_expr / expand_expr will in
8266 : : that case call get_inner_reference that will have the bitsize
8267 : : we check here and thus the block move will not clobber the
8268 : : padding that shouldn't be clobbered. In the future we could
8269 : : replace the TREE_ADDRESSABLE check with a check that
8270 : : get_base_address needs to live in memory. */
8271 : 22 : && (!TREE_ADDRESSABLE (TREE_TYPE (exp))
8272 : 9 : || TREE_CODE (exp) != COMPONENT_REF
8273 : 6 : || !multiple_p (bitsize, BITS_PER_UNIT)
8274 : 6 : || !multiple_p (bitpos, BITS_PER_UNIT)
8275 : 6 : || !poly_int_tree_p (DECL_SIZE (TREE_OPERAND (exp, 1)),
8276 : : &decl_bitsize)
8277 : 6 : || maybe_ne (decl_bitsize, bitsize))
8278 : : /* A call with an addressable return type and return-slot
8279 : : optimization must not need bitfield operations but we must
8280 : : pass down the original target. */
8281 : 16 : && (TREE_CODE (exp) != CALL_EXPR
8282 : 6 : || !TREE_ADDRESSABLE (TREE_TYPE (exp))
8283 : 0 : || !CALL_EXPR_RETURN_SLOT_OPT (exp)))
8284 : : /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
8285 : : decl we must use bitfield operations. */
8286 : 8764275 : || (known_size_p (bitsize)
8287 : 3995172 : && TREE_CODE (exp) == MEM_REF
8288 : 30989 : && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
8289 : 24163 : && DECL_P (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
8290 : 19818 : && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
8291 : 5527 : && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) != BLKmode))
8292 : : {
8293 : 774172 : rtx temp;
8294 : 774172 : gimple *nop_def;
8295 : :
8296 : : /* If EXP is a NOP_EXPR of precision less than its mode, then that
8297 : : implies a mask operation. If the precision is the same size as
8298 : : the field we're storing into, that mask is redundant. This is
8299 : : particularly common with bit field assignments generated by the
8300 : : C front end. */
8301 : 774172 : nop_def = get_def_for_expr (exp, NOP_EXPR);
8302 : 774172 : if (nop_def)
8303 : : {
8304 : 7000 : tree type = TREE_TYPE (exp);
8305 : 7000 : if (INTEGRAL_TYPE_P (type)
8306 : 6792 : && maybe_ne (TYPE_PRECISION (type),
8307 : 13584 : GET_MODE_BITSIZE (TYPE_MODE (type)))
8308 : 10761 : && known_eq (bitsize, TYPE_PRECISION (type)))
8309 : : {
8310 : 3659 : tree op = gimple_assign_rhs1 (nop_def);
8311 : 3659 : type = TREE_TYPE (op);
8312 : 3659 : if (INTEGRAL_TYPE_P (type)
8313 : 3659 : && known_ge (TYPE_PRECISION (type), bitsize))
8314 : : exp = op;
8315 : : }
8316 : : }
8317 : :
8318 : 774172 : temp = expand_normal (exp);
8319 : :
8320 : : /* We don't support variable-sized BLKmode bitfields, since our
8321 : : handling of BLKmode is bound up with the ability to break
8322 : : things into words. */
8323 : 774172 : gcc_assert (mode != BLKmode || bitsize.is_constant ());
8324 : :
8325 : : /* Handle calls that return values in multiple non-contiguous locations.
8326 : : The Irix 6 ABI has examples of this. */
8327 : 774172 : if (GET_CODE (temp) == PARALLEL)
8328 : : {
8329 : 6 : HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
8330 : 6 : machine_mode temp_mode = GET_MODE (temp);
8331 : 6 : if (temp_mode == BLKmode || temp_mode == VOIDmode)
8332 : 6 : temp_mode
8333 : 6 : = smallest_int_mode_for_size (size * BITS_PER_UNIT).require ();
8334 : 6 : rtx temp_target = gen_reg_rtx (temp_mode);
8335 : 6 : emit_group_store (temp_target, temp, TREE_TYPE (exp), size);
8336 : 6 : temp = temp_target;
8337 : : }
8338 : :
8339 : : /* Handle calls that return BLKmode values in registers. */
8340 : 774166 : else if (mode == BLKmode && REG_P (temp) && TREE_CODE (exp) == CALL_EXPR)
8341 : : {
8342 : 0 : rtx temp_target = gen_reg_rtx (GET_MODE (temp));
8343 : 0 : copy_blkmode_from_reg (temp_target, temp, TREE_TYPE (exp));
8344 : 0 : temp = temp_target;
8345 : : }
8346 : :
8347 : : /* If the value has aggregate type and an integral mode then, if BITSIZE
8348 : : is narrower than this mode and this is for big-endian data, we first
8349 : : need to put the value into the low-order bits for store_bit_field,
8350 : : except when MODE is BLKmode and BITSIZE larger than the word size
8351 : : (see the handling of fields larger than a word in store_bit_field).
8352 : : Moreover, the field may be not aligned on a byte boundary; in this
8353 : : case, if it has reverse storage order, it needs to be accessed as a
8354 : : scalar field with reverse storage order and we must first put the
8355 : : value into target order. */
8356 : 774172 : scalar_int_mode temp_mode;
8357 : 1546293 : if (AGGREGATE_TYPE_P (TREE_TYPE (exp))
8358 : 774999 : && is_int_mode (GET_MODE (temp), &temp_mode))
8359 : : {
8360 : 2598 : HOST_WIDE_INT size = GET_MODE_BITSIZE (temp_mode);
8361 : :
8362 : 2598 : reverse = TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (exp));
8363 : :
8364 : 2598 : if (reverse)
8365 : 0 : temp = flip_storage_order (temp_mode, temp);
8366 : :
8367 : 2598 : gcc_checking_assert (known_le (bitsize, size));
8368 : 2598 : if (maybe_lt (bitsize, size)
8369 : 2598 : && reverse ? !BYTES_BIG_ENDIAN : BYTES_BIG_ENDIAN
8370 : : /* Use of to_constant for BLKmode was checked above. */
8371 : : && !(mode == BLKmode && bitsize.to_constant () > BITS_PER_WORD))
8372 : 0 : temp = expand_shift (RSHIFT_EXPR, temp_mode, temp,
8373 : : size - bitsize, NULL_RTX, 1);
8374 : : }
8375 : :
8376 : : /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
8377 : 702934 : if (mode != VOIDmode && mode != BLKmode
8378 : 1476836 : && mode != TYPE_MODE (TREE_TYPE (exp)))
8379 : 4 : temp = convert_modes (mode, TYPE_MODE (TREE_TYPE (exp)), temp, 1);
8380 : :
8381 : : /* If the mode of TEMP and TARGET is BLKmode, both must be in memory
8382 : : and BITPOS must be aligned on a byte boundary. If so, we simply do
8383 : : a block copy. Likewise for a BLKmode-like TARGET. */
8384 : 774172 : if (GET_MODE (temp) == BLKmode
8385 : 774172 : && (GET_MODE (target) == BLKmode
8386 : 179 : || (MEM_P (target)
8387 : 0 : && GET_MODE_CLASS (GET_MODE (target)) == MODE_INT
8388 : 0 : && multiple_p (bitpos, BITS_PER_UNIT)
8389 : 0 : && multiple_p (bitsize, BITS_PER_UNIT))))
8390 : : {
8391 : 85 : gcc_assert (MEM_P (target) && MEM_P (temp));
8392 : 85 : poly_int64 bytepos = exact_div (bitpos, BITS_PER_UNIT);
8393 : 85 : poly_int64 bytesize = bits_to_bytes_round_up (bitsize);
8394 : :
8395 : 85 : target = adjust_address (target, VOIDmode, bytepos);
8396 : 85 : emit_block_move (target, temp,
8397 : 85 : gen_int_mode (bytesize, Pmode),
8398 : : BLOCK_OP_NORMAL);
8399 : :
8400 : 85 : return const0_rtx;
8401 : : }
8402 : :
8403 : : /* If the mode of TEMP is still BLKmode and BITSIZE not larger than the
8404 : : word size, we need to load the value (see again store_bit_field). */
8405 : 774105 : if (GET_MODE (temp) == BLKmode && known_le (bitsize, BITS_PER_WORD))
8406 : : {
8407 : 61 : temp_mode = smallest_int_mode_for_size (bitsize).require ();
8408 : 61 : temp = extract_bit_field (temp, bitsize, 0, 1, NULL_RTX, temp_mode,
8409 : : temp_mode, false, NULL);
8410 : : }
8411 : :
8412 : : /* Store the value in the bitfield. */
8413 : 774087 : gcc_checking_assert (known_ge (bitpos, 0));
8414 : 774087 : store_bit_field (target, bitsize, bitpos,
8415 : : bitregion_start, bitregion_end,
8416 : : mode, temp, reverse, false);
8417 : :
8418 : 774087 : return const0_rtx;
8419 : : }
8420 : : else
8421 : : {
8422 : : /* Now build a reference to just the desired component. */
8423 : 3994919 : rtx to_rtx = adjust_address (target, mode,
8424 : : exact_div (bitpos, BITS_PER_UNIT));
8425 : :
8426 : 3994919 : if (to_rtx == target)
8427 : 1283522 : to_rtx = copy_rtx (to_rtx);
8428 : :
8429 : 7727234 : if (!MEM_KEEP_ALIAS_SET_P (to_rtx) && MEM_ALIAS_SET (to_rtx) != 0)
8430 : 3473325 : set_mem_alias_set (to_rtx, alias_set);
8431 : :
8432 : : /* Above we avoided using bitfield operations for storing a CONSTRUCTOR
8433 : : into a target smaller than its type; handle that case now. */
8434 : 3994919 : if (TREE_CODE (exp) == CONSTRUCTOR && known_size_p (bitsize))
8435 : : {
8436 : 67892 : poly_int64 bytesize = exact_div (bitsize, BITS_PER_UNIT);
8437 : 67892 : store_constructor (exp, to_rtx, 0, bytesize, reverse);
8438 : 67892 : return to_rtx;
8439 : : }
8440 : :
8441 : 3927027 : return store_expr (exp, to_rtx, 0, nontemporal, reverse);
8442 : : }
8443 : : }
8444 : :
8445 : : /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
8446 : : an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
8447 : : codes and find the ultimate containing object, which we return.
8448 : :
8449 : : We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
8450 : : bit position, *PUNSIGNEDP to the signedness and *PREVERSEP to the
8451 : : storage order of the field.
8452 : : If the position of the field is variable, we store a tree
8453 : : giving the variable offset (in units) in *POFFSET.
8454 : : This offset is in addition to the bit position.
8455 : : If the position is not variable, we store 0 in *POFFSET.
8456 : :
8457 : : If any of the extraction expressions is volatile,
8458 : : we store 1 in *PVOLATILEP. Otherwise we don't change that.
8459 : :
8460 : : If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
8461 : : Otherwise, it is a mode that can be used to access the field.
8462 : :
8463 : : If the field describes a variable-sized object, *PMODE is set to
8464 : : BLKmode and *PBITSIZE is set to -1. An access cannot be made in
8465 : : this case, but the address of the object can be found. */
8466 : :
8467 : : tree
8468 : 234023344 : get_inner_reference (tree exp, poly_int64 *pbitsize,
8469 : : poly_int64 *pbitpos, tree *poffset,
8470 : : machine_mode *pmode, int *punsignedp,
8471 : : int *preversep, int *pvolatilep)
8472 : : {
8473 : 234023344 : tree size_tree = 0;
8474 : 234023344 : machine_mode mode = VOIDmode;
8475 : 234023344 : bool blkmode_bitfield = false;
8476 : 234023344 : tree offset = size_zero_node;
8477 : 234023344 : poly_offset_int bit_offset = 0;
8478 : :
8479 : : /* First get the mode, signedness, storage order and size. We do this from
8480 : : just the outermost expression. */
8481 : 234023344 : *pbitsize = -1;
8482 : 234023344 : if (TREE_CODE (exp) == COMPONENT_REF)
8483 : : {
8484 : 91921996 : tree field = TREE_OPERAND (exp, 1);
8485 : 91921996 : size_tree = DECL_SIZE (field);
8486 : 91921996 : if (flag_strict_volatile_bitfields > 0
8487 : 58 : && TREE_THIS_VOLATILE (exp)
8488 : 40 : && DECL_BIT_FIELD_TYPE (field)
8489 : 91922018 : && DECL_MODE (field) != BLKmode)
8490 : : /* Volatile bitfields should be accessed in the mode of the
8491 : : field's type, not the mode computed based on the bit
8492 : : size. */
8493 : 22 : mode = TYPE_MODE (DECL_BIT_FIELD_TYPE (field));
8494 : 91921974 : else if (!DECL_BIT_FIELD (field))
8495 : : {
8496 : 90485807 : mode = DECL_MODE (field);
8497 : : /* For vector fields re-check the target flags, as DECL_MODE
8498 : : could have been set with different target flags than
8499 : : the current function has. */
8500 : 90485807 : if (VECTOR_TYPE_P (TREE_TYPE (field))
8501 : 90485807 : && VECTOR_MODE_P (TYPE_MODE_RAW (TREE_TYPE (field))))
8502 : 321719 : mode = TYPE_MODE (TREE_TYPE (field));
8503 : : }
8504 : 1436167 : else if (DECL_MODE (field) == BLKmode)
8505 : 620 : blkmode_bitfield = true;
8506 : :
8507 : 91921996 : *punsignedp = DECL_UNSIGNED (field);
8508 : : }
8509 : 142101348 : else if (TREE_CODE (exp) == BIT_FIELD_REF)
8510 : : {
8511 : 613702 : size_tree = TREE_OPERAND (exp, 1);
8512 : 1227017 : *punsignedp = (! INTEGRAL_TYPE_P (TREE_TYPE (exp))
8513 : 1081288 : || TYPE_UNSIGNED (TREE_TYPE (exp)));
8514 : :
8515 : : /* For vector element types with the correct size of access or for
8516 : : vector typed accesses use the mode of the access type. */
8517 : 613702 : if ((TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == VECTOR_TYPE
8518 : 428277 : && TREE_TYPE (exp) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)))
8519 : 390497 : && tree_int_cst_equal (size_tree, TYPE_SIZE (TREE_TYPE (exp))))
8520 : 651517 : || VECTOR_TYPE_P (TREE_TYPE (exp)))
8521 : 412302 : mode = TYPE_MODE (TREE_TYPE (exp));
8522 : : }
8523 : : else
8524 : : {
8525 : 141487646 : mode = TYPE_MODE (TREE_TYPE (exp));
8526 : 141487646 : *punsignedp = TYPE_UNSIGNED (TREE_TYPE (exp));
8527 : :
8528 : 141487646 : if (mode == BLKmode)
8529 : 57725992 : size_tree = TYPE_SIZE (TREE_TYPE (exp));
8530 : : else
8531 : 167523308 : *pbitsize = GET_MODE_BITSIZE (mode);
8532 : : }
8533 : :
8534 : 234023344 : if (size_tree != 0)
8535 : : {
8536 : 149585563 : if (!poly_int_tree_p (size_tree, pbitsize))
8537 : 340336 : mode = BLKmode, *pbitsize = -1;
8538 : : }
8539 : :
8540 : 234023344 : *preversep = reverse_storage_order_for_component_p (exp);
8541 : :
8542 : : /* Compute cumulative bit-offset for nested component-refs and array-refs,
8543 : : and find the ultimate containing object. */
8544 : 556206766 : while (1)
8545 : : {
8546 : 395115055 : switch (TREE_CODE (exp))
8547 : : {
8548 : 613702 : case BIT_FIELD_REF:
8549 : 613702 : bit_offset += wi::to_poly_offset (TREE_OPERAND (exp, 2));
8550 : 613702 : break;
8551 : :
8552 : 129903505 : case COMPONENT_REF:
8553 : 129903505 : {
8554 : 129903505 : tree field = TREE_OPERAND (exp, 1);
8555 : 129903505 : tree this_offset = component_ref_field_offset (exp);
8556 : :
8557 : : /* If this field hasn't been filled in yet, don't go past it.
8558 : : This should only happen when folding expressions made during
8559 : : type construction. */
8560 : 129903505 : if (this_offset == 0)
8561 : : break;
8562 : :
8563 : 129903505 : offset = size_binop (PLUS_EXPR, offset, this_offset);
8564 : 129903505 : bit_offset += wi::to_poly_offset (DECL_FIELD_BIT_OFFSET (field));
8565 : :
8566 : : /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
8567 : : }
8568 : 129903505 : break;
8569 : :
8570 : 27776483 : case ARRAY_REF:
8571 : 27776483 : case ARRAY_RANGE_REF:
8572 : 27776483 : {
8573 : 27776483 : tree index = TREE_OPERAND (exp, 1);
8574 : 27776483 : tree low_bound = array_ref_low_bound (exp);
8575 : 27776483 : tree unit_size = array_ref_element_size (exp);
8576 : :
8577 : : /* We assume all arrays have sizes that are a multiple of a byte.
8578 : : First subtract the lower bound, if any, in the type of the
8579 : : index, then convert to sizetype and multiply by the size of
8580 : : the array element. */
8581 : 27776483 : if (! integer_zerop (low_bound))
8582 : 777861 : index = fold_build2 (MINUS_EXPR, TREE_TYPE (index),
8583 : : index, low_bound);
8584 : :
8585 : 27776483 : offset = size_binop (PLUS_EXPR, offset,
8586 : : size_binop (MULT_EXPR,
8587 : : fold_convert (sizetype, index),
8588 : : unit_size));
8589 : : }
8590 : 27776483 : break;
8591 : :
8592 : : case REALPART_EXPR:
8593 : : break;
8594 : :
8595 : : case IMAGPART_EXPR:
8596 : 161091711 : bit_offset += *pbitsize;
8597 : : break;
8598 : :
8599 : : case VIEW_CONVERT_EXPR:
8600 : : break;
8601 : :
8602 : 87722887 : case MEM_REF:
8603 : : /* Hand back the decl for MEM[&decl, off]. */
8604 : 87722887 : if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR)
8605 : : {
8606 : 19676966 : tree off = TREE_OPERAND (exp, 1);
8607 : 19676966 : if (!integer_zerop (off))
8608 : : {
8609 : 10990127 : poly_offset_int boff = mem_ref_offset (exp);
8610 : 10990127 : boff <<= LOG2_BITS_PER_UNIT;
8611 : 10990127 : bit_offset += boff;
8612 : : }
8613 : 19676966 : exp = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
8614 : : }
8615 : 87722887 : goto done;
8616 : :
8617 : 146300457 : default:
8618 : 146300457 : goto done;
8619 : : }
8620 : :
8621 : : /* If any reference in the chain is volatile, the effect is volatile. */
8622 : 161091711 : if (TREE_THIS_VOLATILE (exp))
8623 : 458584 : *pvolatilep = 1;
8624 : :
8625 : 161091711 : exp = TREE_OPERAND (exp, 0);
8626 : 161091711 : }
8627 : 234023344 : done:
8628 : :
8629 : : /* If OFFSET is constant, see if we can return the whole thing as a
8630 : : constant bit position. Make sure to handle overflow during
8631 : : this conversion. */
8632 : 234023344 : if (poly_int_tree_p (offset))
8633 : : {
8634 : 220640654 : poly_offset_int tem = wi::sext (wi::to_poly_offset (offset),
8635 : 220640654 : TYPE_PRECISION (sizetype));
8636 : 220640654 : tem <<= LOG2_BITS_PER_UNIT;
8637 : 220640654 : tem += bit_offset;
8638 : 220640654 : if (tem.to_shwi (pbitpos))
8639 : 220639280 : *poffset = offset = NULL_TREE;
8640 : : }
8641 : :
8642 : : /* Otherwise, split it up. */
8643 : 220640654 : if (offset)
8644 : : {
8645 : : /* Avoid returning a negative bitpos as this may wreak havoc later. */
8646 : 13384064 : if (!bit_offset.to_shwi (pbitpos) || maybe_lt (*pbitpos, 0))
8647 : : {
8648 : 288 : *pbitpos = num_trailing_bits (bit_offset.force_shwi ());
8649 : 288 : poly_offset_int bytes = bits_to_bytes_round_down (bit_offset);
8650 : 288 : offset = size_binop (PLUS_EXPR, offset,
8651 : : build_int_cst (sizetype, bytes.force_shwi ()));
8652 : : }
8653 : :
8654 : 13384064 : *poffset = offset;
8655 : : }
8656 : :
8657 : : /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
8658 : 234023344 : if (mode == VOIDmode
8659 : 2056676 : && blkmode_bitfield
8660 : 620 : && multiple_p (*pbitpos, BITS_PER_UNIT)
8661 : 234023832 : && multiple_p (*pbitsize, BITS_PER_UNIT))
8662 : 5 : *pmode = BLKmode;
8663 : : else
8664 : 234023339 : *pmode = mode;
8665 : :
8666 : 234023344 : return exp;
8667 : : }
8668 : :
8669 : : /* Alignment in bits the TARGET of an assignment may be assumed to have. */
8670 : :
8671 : : static unsigned HOST_WIDE_INT
8672 : 498499 : target_align (const_tree target)
8673 : : {
8674 : : /* We might have a chain of nested references with intermediate misaligning
8675 : : bitfields components, so need to recurse to find out. */
8676 : :
8677 : 498499 : unsigned HOST_WIDE_INT this_align, outer_align;
8678 : :
8679 : 498499 : switch (TREE_CODE (target))
8680 : : {
8681 : : case BIT_FIELD_REF:
8682 : : return 1;
8683 : :
8684 : 135994 : case COMPONENT_REF:
8685 : 135994 : this_align = DECL_ALIGN (TREE_OPERAND (target, 1));
8686 : 135994 : outer_align = target_align (TREE_OPERAND (target, 0));
8687 : 135994 : return MIN (this_align, outer_align);
8688 : :
8689 : 184387 : case ARRAY_REF:
8690 : 184387 : case ARRAY_RANGE_REF:
8691 : 184387 : this_align = TYPE_ALIGN (TREE_TYPE (target));
8692 : 184387 : outer_align = target_align (TREE_OPERAND (target, 0));
8693 : 184387 : return MIN (this_align, outer_align);
8694 : :
8695 : 4336 : CASE_CONVERT:
8696 : 4336 : case NON_LVALUE_EXPR:
8697 : 4336 : case VIEW_CONVERT_EXPR:
8698 : 4336 : this_align = TYPE_ALIGN (TREE_TYPE (target));
8699 : 4336 : outer_align = target_align (TREE_OPERAND (target, 0));
8700 : 4336 : return MAX (this_align, outer_align);
8701 : :
8702 : 173777 : default:
8703 : 173777 : return TYPE_ALIGN (TREE_TYPE (target));
8704 : : }
8705 : : }
8706 : :
8707 : :
8708 : : /* Given an rtx VALUE that may contain additions and multiplications, return
8709 : : an equivalent value that just refers to a register, memory, or constant.
8710 : : This is done by generating instructions to perform the arithmetic and
8711 : : returning a pseudo-register containing the value.
8712 : :
8713 : : The returned value may be a REG, SUBREG, MEM or constant. */
8714 : :
8715 : : rtx
8716 : 31088966 : force_operand (rtx value, rtx target)
8717 : : {
8718 : 31088966 : rtx op1, op2;
8719 : : /* Use subtarget as the target for operand 0 of a binary operation. */
8720 : 31088966 : rtx subtarget = get_subtarget (target);
8721 : 31088966 : enum rtx_code code = GET_CODE (value);
8722 : :
8723 : : /* Check for subreg applied to an expression produced by loop optimizer. */
8724 : 31088966 : if (code == SUBREG
8725 : 253177 : && !REG_P (SUBREG_REG (value))
8726 : 183 : && !MEM_P (SUBREG_REG (value)))
8727 : : {
8728 : 183 : value
8729 : 183 : = simplify_gen_subreg (GET_MODE (value),
8730 : 183 : force_reg (GET_MODE (SUBREG_REG (value)),
8731 : : force_operand (SUBREG_REG (value),
8732 : : NULL_RTX)),
8733 : 183 : GET_MODE (SUBREG_REG (value)),
8734 : 183 : SUBREG_BYTE (value));
8735 : 183 : code = GET_CODE (value);
8736 : : }
8737 : :
8738 : : /* Check for a PIC address load. */
8739 : 31088966 : if ((code == PLUS || code == MINUS)
8740 : 3747436 : && XEXP (value, 0) == pic_offset_table_rtx
8741 : 1974 : && (GET_CODE (XEXP (value, 1)) == SYMBOL_REF
8742 : 1974 : || GET_CODE (XEXP (value, 1)) == LABEL_REF
8743 : 1974 : || GET_CODE (XEXP (value, 1)) == CONST))
8744 : : {
8745 : 219 : if (!subtarget)
8746 : 219 : subtarget = gen_reg_rtx (GET_MODE (value));
8747 : 219 : emit_move_insn (subtarget, value);
8748 : 219 : return subtarget;
8749 : : }
8750 : :
8751 : 31088747 : if (ARITHMETIC_P (value))
8752 : : {
8753 : 3858105 : op2 = XEXP (value, 1);
8754 : 3858105 : if (!CONSTANT_P (op2) && !(REG_P (op2) && op2 != subtarget))
8755 : 3858105 : subtarget = 0;
8756 : 3858105 : if (code == MINUS && CONST_INT_P (op2))
8757 : : {
8758 : 0 : code = PLUS;
8759 : 0 : op2 = negate_rtx (GET_MODE (value), op2);
8760 : : }
8761 : :
8762 : : /* Check for an addition with OP2 a constant integer and our first
8763 : : operand a PLUS of a virtual register and something else. In that
8764 : : case, we want to emit the sum of the virtual register and the
8765 : : constant first and then add the other value. This allows virtual
8766 : : register instantiation to simply modify the constant rather than
8767 : : creating another one around this addition. */
8768 : 3683665 : if (code == PLUS && CONST_INT_P (op2)
8769 : 3317417 : && GET_CODE (XEXP (value, 0)) == PLUS
8770 : 103631 : && REG_P (XEXP (XEXP (value, 0), 0))
8771 : 3910345 : && VIRTUAL_REGISTER_P (XEXP (XEXP (value, 0), 0)))
8772 : : {
8773 : 2732 : rtx temp = expand_simple_binop (GET_MODE (value), code,
8774 : : XEXP (XEXP (value, 0), 0), op2,
8775 : : subtarget, 0, OPTAB_LIB_WIDEN);
8776 : 2732 : return expand_simple_binop (GET_MODE (value), code, temp,
8777 : 2732 : force_operand (XEXP (XEXP (value,
8778 : : 0), 1), 0),
8779 : 2732 : target, 0, OPTAB_LIB_WIDEN);
8780 : : }
8781 : :
8782 : 3855373 : op1 = force_operand (XEXP (value, 0), subtarget);
8783 : 3855373 : op2 = force_operand (op2, NULL_RTX);
8784 : 3855373 : switch (code)
8785 : : {
8786 : 91285 : case MULT:
8787 : 91285 : return expand_mult (GET_MODE (value), op1, op2, target, 1);
8788 : 240 : case DIV:
8789 : 240 : if (!INTEGRAL_MODE_P (GET_MODE (value)))
8790 : 240 : return expand_simple_binop (GET_MODE (value), code, op1, op2,
8791 : 240 : target, 1, OPTAB_LIB_WIDEN);
8792 : : else
8793 : 0 : return expand_divmod (0,
8794 : : FLOAT_MODE_P (GET_MODE (value))
8795 : : ? RDIV_EXPR : TRUNC_DIV_EXPR,
8796 : 0 : GET_MODE (value), op1, op2, target, 0);
8797 : 0 : case MOD:
8798 : 0 : return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
8799 : 0 : target, 0);
8800 : 379 : case UDIV:
8801 : 379 : return expand_divmod (0, TRUNC_DIV_EXPR, GET_MODE (value), op1, op2,
8802 : 379 : target, 1);
8803 : 0 : case UMOD:
8804 : 0 : return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
8805 : 0 : target, 1);
8806 : 94 : case ASHIFTRT:
8807 : 94 : return expand_simple_binop (GET_MODE (value), code, op1, op2,
8808 : 94 : target, 0, OPTAB_LIB_WIDEN);
8809 : 3763375 : default:
8810 : 3763375 : return expand_simple_binop (GET_MODE (value), code, op1, op2,
8811 : 3763375 : target, 1, OPTAB_LIB_WIDEN);
8812 : : }
8813 : : }
8814 : 27230642 : if (UNARY_P (value))
8815 : : {
8816 : 16951 : if (!target)
8817 : 6732 : target = gen_reg_rtx (GET_MODE (value));
8818 : : /* FIX or UNSIGNED_FIX with integral mode has unspecified rounding,
8819 : : while FIX with floating point mode rounds toward zero. So, some
8820 : : targets use expressions like (fix:SI (fix:DF (reg:DF ...)))
8821 : : to express rounding toward zero during the conversion to int.
8822 : : expand_fix isn't able to handle that, it can only handle
8823 : : FIX/UNSIGNED_FIX from floating point mode to integral one. */
8824 : 16951 : if ((code == FIX || code == UNSIGNED_FIX)
8825 : 4 : && GET_CODE (XEXP (value, 0)) == FIX
8826 : 0 : && (GET_MODE (XEXP (value, 0))
8827 : 0 : == GET_MODE (XEXP (XEXP (value, 0), 0))))
8828 : 0 : op1 = force_operand (XEXP (XEXP (value, 0), 0), NULL_RTX);
8829 : : else
8830 : 16951 : op1 = force_operand (XEXP (value, 0), NULL_RTX);
8831 : 16951 : switch (code)
8832 : : {
8833 : 4773 : case ZERO_EXTEND:
8834 : 4773 : case SIGN_EXTEND:
8835 : 4773 : case TRUNCATE:
8836 : 4773 : case FLOAT_EXTEND:
8837 : 4773 : case FLOAT_TRUNCATE:
8838 : 4773 : convert_move (target, op1, code == ZERO_EXTEND);
8839 : 4773 : return target;
8840 : :
8841 : 4 : case FIX:
8842 : 4 : case UNSIGNED_FIX:
8843 : 4 : expand_fix (target, op1, code == UNSIGNED_FIX);
8844 : 4 : return target;
8845 : :
8846 : 120 : case FLOAT:
8847 : 120 : case UNSIGNED_FLOAT:
8848 : 120 : expand_float (target, op1, code == UNSIGNED_FLOAT);
8849 : 120 : return target;
8850 : :
8851 : 12054 : default:
8852 : 12054 : return expand_simple_unop (GET_MODE (value), code, op1, target, 0);
8853 : : }
8854 : : }
8855 : :
8856 : : #ifdef INSN_SCHEDULING
8857 : : /* On machines that have insn scheduling, we want all memory reference to be
8858 : : explicit, so we need to deal with such paradoxical SUBREGs. */
8859 : 27213691 : if (paradoxical_subreg_p (value) && MEM_P (SUBREG_REG (value)))
8860 : 0 : value
8861 : 0 : = simplify_gen_subreg (GET_MODE (value),
8862 : 0 : force_reg (GET_MODE (SUBREG_REG (value)),
8863 : : force_operand (SUBREG_REG (value),
8864 : : NULL_RTX)),
8865 : : GET_MODE (SUBREG_REG (value)),
8866 : 0 : SUBREG_BYTE (value));
8867 : : #endif
8868 : :
8869 : : return value;
8870 : : }
8871 : :
8872 : : /* Subroutine of expand_expr: return true iff there is no way that
8873 : : EXP can reference X, which is being modified. TOP_P is nonzero if this
8874 : : call is going to be used to determine whether we need a temporary
8875 : : for EXP, as opposed to a recursive call to this function.
8876 : :
8877 : : It is always safe for this routine to return false since it merely
8878 : : searches for optimization opportunities. */
8879 : :
8880 : : bool
8881 : 8475792 : safe_from_p (const_rtx x, tree exp, int top_p)
8882 : : {
8883 : 8475808 : rtx exp_rtl = 0;
8884 : 8475808 : int i, nops;
8885 : :
8886 : 8475808 : if (x == 0
8887 : : /* If EXP has varying size, we MUST use a target since we currently
8888 : : have no way of allocating temporaries of variable size
8889 : : (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
8890 : : So we assume here that something at a higher level has prevented a
8891 : : clash. This is somewhat bogus, but the best we can do. Only
8892 : : do this when X is BLKmode and when we are at the top level. */
8893 : 1947613 : || (top_p && TREE_TYPE (exp) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp))
8894 : 1817163 : && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) != INTEGER_CST
8895 : 0 : && (TREE_CODE (TREE_TYPE (exp)) != ARRAY_TYPE
8896 : 0 : || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)) == NULL_TREE
8897 : 0 : || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)))
8898 : : != INTEGER_CST)
8899 : 0 : && GET_MODE (x) == BLKmode)
8900 : : /* If X is in the outgoing argument area, it is always safe. */
8901 : 10423421 : || (MEM_P (x)
8902 : 181058 : && (XEXP (x, 0) == virtual_outgoing_args_rtx
8903 : 181058 : || (GET_CODE (XEXP (x, 0)) == PLUS
8904 : 133465 : && XEXP (XEXP (x, 0), 0) == virtual_outgoing_args_rtx))))
8905 : : return true;
8906 : :
8907 : : /* If this is a subreg of a hard register, declare it unsafe, otherwise,
8908 : : find the underlying pseudo. */
8909 : 1947613 : if (GET_CODE (x) == SUBREG)
8910 : : {
8911 : 0 : x = SUBREG_REG (x);
8912 : 0 : if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
8913 : : return false;
8914 : : }
8915 : :
8916 : : /* Now look at our tree code and possibly recurse. */
8917 : 1947613 : switch (TREE_CODE_CLASS (TREE_CODE (exp)))
8918 : : {
8919 : 457 : case tcc_declaration:
8920 : 457 : exp_rtl = DECL_RTL_IF_SET (exp);
8921 : : break;
8922 : :
8923 : : case tcc_constant:
8924 : : return true;
8925 : :
8926 : 855426 : case tcc_exceptional:
8927 : 855426 : if (TREE_CODE (exp) == TREE_LIST)
8928 : : {
8929 : 0 : while (1)
8930 : : {
8931 : 0 : if (TREE_VALUE (exp) && !safe_from_p (x, TREE_VALUE (exp), 0))
8932 : : return false;
8933 : 0 : exp = TREE_CHAIN (exp);
8934 : 0 : if (!exp)
8935 : : return true;
8936 : 0 : if (TREE_CODE (exp) != TREE_LIST)
8937 : : return safe_from_p (x, exp, 0);
8938 : : }
8939 : : }
8940 : 855426 : else if (TREE_CODE (exp) == CONSTRUCTOR)
8941 : : {
8942 : : constructor_elt *ce;
8943 : : unsigned HOST_WIDE_INT idx;
8944 : :
8945 : 7786500 : FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp), idx, ce)
8946 : 3987 : if ((ce->index != NULL_TREE && !safe_from_p (x, ce->index, 0))
8947 : 130277 : || !safe_from_p (x, ce->value, 0))
8948 : 104838 : return false;
8949 : : return true;
8950 : : }
8951 : 711910 : else if (TREE_CODE (exp) == ERROR_MARK)
8952 : : return true; /* An already-visited SAVE_EXPR? */
8953 : : else
8954 : : return false;
8955 : :
8956 : 0 : case tcc_statement:
8957 : : /* The only case we look at here is the DECL_INITIAL inside a
8958 : : DECL_EXPR. */
8959 : 0 : return (TREE_CODE (exp) != DECL_EXPR
8960 : 0 : || TREE_CODE (DECL_EXPR_DECL (exp)) != VAR_DECL
8961 : 0 : || !DECL_INITIAL (DECL_EXPR_DECL (exp))
8962 : 0 : || safe_from_p (x, DECL_INITIAL (DECL_EXPR_DECL (exp)), 0));
8963 : :
8964 : 0 : case tcc_binary:
8965 : 0 : case tcc_comparison:
8966 : 0 : if (!safe_from_p (x, TREE_OPERAND (exp, 1), 0))
8967 : : return false;
8968 : : /* Fall through. */
8969 : :
8970 : 16 : case tcc_unary:
8971 : 16 : return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
8972 : :
8973 : 264 : case tcc_expression:
8974 : 264 : case tcc_reference:
8975 : 264 : case tcc_vl_exp:
8976 : : /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
8977 : : the expression. If it is set, we conflict iff we are that rtx or
8978 : : both are in memory. Otherwise, we check all operands of the
8979 : : expression recursively. */
8980 : :
8981 : 264 : switch (TREE_CODE (exp))
8982 : : {
8983 : 241 : case ADDR_EXPR:
8984 : : /* If the operand is static or we are static, we can't conflict.
8985 : : Likewise if we don't conflict with the operand at all. */
8986 : 241 : if (staticp (TREE_OPERAND (exp, 0))
8987 : 111 : || TREE_STATIC (exp)
8988 : 352 : || safe_from_p (x, TREE_OPERAND (exp, 0), 0))
8989 : 241 : return true;
8990 : :
8991 : : /* Otherwise, the only way this can conflict is if we are taking
8992 : : the address of a DECL a that address if part of X, which is
8993 : : very rare. */
8994 : 0 : exp = TREE_OPERAND (exp, 0);
8995 : 0 : if (DECL_P (exp))
8996 : : {
8997 : 0 : if (!DECL_RTL_SET_P (exp)
8998 : 0 : || !MEM_P (DECL_RTL (exp)))
8999 : 0 : return false;
9000 : : else
9001 : 0 : exp_rtl = XEXP (DECL_RTL (exp), 0);
9002 : : }
9003 : : break;
9004 : :
9005 : 8 : case MEM_REF:
9006 : 8 : if (MEM_P (x)
9007 : 8 : && alias_sets_conflict_p (MEM_ALIAS_SET (x),
9008 : : get_alias_set (exp)))
9009 : : return false;
9010 : : break;
9011 : :
9012 : 0 : case CALL_EXPR:
9013 : : /* Assume that the call will clobber all hard registers and
9014 : : all of memory. */
9015 : 0 : if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
9016 : 0 : || MEM_P (x))
9017 : : return false;
9018 : : break;
9019 : :
9020 : 0 : case WITH_CLEANUP_EXPR:
9021 : 0 : case CLEANUP_POINT_EXPR:
9022 : : /* Lowered by gimplify.cc. */
9023 : 0 : gcc_unreachable ();
9024 : :
9025 : 0 : case SAVE_EXPR:
9026 : 0 : return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
9027 : :
9028 : : default:
9029 : : break;
9030 : : }
9031 : :
9032 : : /* If we have an rtx, we do not need to scan our operands. */
9033 : 0 : if (exp_rtl)
9034 : : break;
9035 : :
9036 : 23 : nops = TREE_OPERAND_LENGTH (exp);
9037 : 111 : for (i = 0; i < nops; i++)
9038 : 65 : if (TREE_OPERAND (exp, i) != 0
9039 : 65 : && ! safe_from_p (x, TREE_OPERAND (exp, i), 0))
9040 : : return false;
9041 : :
9042 : : break;
9043 : :
9044 : 0 : case tcc_type:
9045 : : /* Should never get a type here. */
9046 : 0 : gcc_unreachable ();
9047 : : }
9048 : :
9049 : : /* If we have an rtl, find any enclosed object. Then see if we conflict
9050 : : with it. */
9051 : 270 : if (exp_rtl)
9052 : : {
9053 : 247 : if (GET_CODE (exp_rtl) == SUBREG)
9054 : : {
9055 : 0 : exp_rtl = SUBREG_REG (exp_rtl);
9056 : 0 : if (REG_P (exp_rtl)
9057 : 0 : && REGNO (exp_rtl) < FIRST_PSEUDO_REGISTER)
9058 : : return false;
9059 : : }
9060 : :
9061 : : /* If the rtl is X, then it is not safe. Otherwise, it is unless both
9062 : : are memory and they conflict. */
9063 : 247 : return ! (rtx_equal_p (x, exp_rtl)
9064 : 247 : || (MEM_P (x) && MEM_P (exp_rtl)
9065 : 4 : && true_dependence (exp_rtl, VOIDmode, x)));
9066 : : }
9067 : :
9068 : : /* If we reach here, it is safe. */
9069 : : return true;
9070 : : }
9071 : :
9072 : :
9073 : : /* Return the highest power of two that EXP is known to be a multiple of.
9074 : : This is used in updating alignment of MEMs in array references. */
9075 : :
9076 : : unsigned HOST_WIDE_INT
9077 : 32896314 : highest_pow2_factor (const_tree exp)
9078 : : {
9079 : 32896314 : unsigned HOST_WIDE_INT ret;
9080 : 32896314 : int trailing_zeros = tree_ctz (exp);
9081 : 32896314 : if (trailing_zeros >= HOST_BITS_PER_WIDE_INT)
9082 : 45574408 : return BIGGEST_ALIGNMENT;
9083 : 9764816 : ret = HOST_WIDE_INT_1U << trailing_zeros;
9084 : 19061095 : if (ret > BIGGEST_ALIGNMENT)
9085 : 12956180 : return BIGGEST_ALIGNMENT;
9086 : : return ret;
9087 : : }
9088 : :
9089 : : /* Similar, except that the alignment requirements of TARGET are
9090 : : taken into account. Assume it is at least as aligned as its
9091 : : type, unless it is a COMPONENT_REF in which case the layout of
9092 : : the structure gives the alignment. */
9093 : :
9094 : : static unsigned HOST_WIDE_INT
9095 : 173782 : highest_pow2_factor_for_target (const_tree target, const_tree exp)
9096 : : {
9097 : 173782 : unsigned HOST_WIDE_INT talign = target_align (target) / BITS_PER_UNIT;
9098 : 173782 : unsigned HOST_WIDE_INT factor = highest_pow2_factor (exp);
9099 : :
9100 : 173782 : return MAX (factor, talign);
9101 : : }
9102 : :
9103 : : /* Convert the tree comparison code TCODE to the rtl one where the
9104 : : signedness is UNSIGNEDP. */
9105 : :
9106 : : static enum rtx_code
9107 : 14326 : convert_tree_comp_to_rtx (enum tree_code tcode, int unsignedp)
9108 : : {
9109 : 14326 : enum rtx_code code;
9110 : 14326 : switch (tcode)
9111 : : {
9112 : : case EQ_EXPR:
9113 : : code = EQ;
9114 : : break;
9115 : 935 : case NE_EXPR:
9116 : 935 : code = NE;
9117 : 935 : break;
9118 : 3174 : case LT_EXPR:
9119 : 3174 : code = unsignedp ? LTU : LT;
9120 : : break;
9121 : 1911 : case LE_EXPR:
9122 : 1911 : code = unsignedp ? LEU : LE;
9123 : : break;
9124 : 1995 : case GT_EXPR:
9125 : 1995 : code = unsignedp ? GTU : GT;
9126 : : break;
9127 : 3484 : case GE_EXPR:
9128 : 3484 : code = unsignedp ? GEU : GE;
9129 : : break;
9130 : 4 : case UNORDERED_EXPR:
9131 : 4 : code = UNORDERED;
9132 : 4 : break;
9133 : 0 : case ORDERED_EXPR:
9134 : 0 : code = ORDERED;
9135 : 0 : break;
9136 : 0 : case UNLT_EXPR:
9137 : 0 : code = UNLT;
9138 : 0 : break;
9139 : 0 : case UNLE_EXPR:
9140 : 0 : code = UNLE;
9141 : 0 : break;
9142 : 0 : case UNGT_EXPR:
9143 : 0 : code = UNGT;
9144 : 0 : break;
9145 : 0 : case UNGE_EXPR:
9146 : 0 : code = UNGE;
9147 : 0 : break;
9148 : 0 : case UNEQ_EXPR:
9149 : 0 : code = UNEQ;
9150 : 0 : break;
9151 : 0 : case LTGT_EXPR:
9152 : 0 : code = LTGT;
9153 : 0 : break;
9154 : :
9155 : 0 : default:
9156 : 0 : gcc_unreachable ();
9157 : : }
9158 : 14326 : return code;
9159 : : }
9160 : :
9161 : : /* Subroutine of expand_expr. Expand the two operands of a binary
9162 : : expression EXP0 and EXP1 placing the results in OP0 and OP1.
9163 : : The value may be stored in TARGET if TARGET is nonzero. The
9164 : : MODIFIER argument is as documented by expand_expr. */
9165 : :
9166 : : void
9167 : 7885302 : expand_operands (tree exp0, tree exp1, rtx target, rtx *op0, rtx *op1,
9168 : : enum expand_modifier modifier)
9169 : : {
9170 : 7885302 : if (! safe_from_p (target, exp1, 1))
9171 : 590191 : target = 0;
9172 : 7885302 : if (operand_equal_p (exp0, exp1, 0))
9173 : : {
9174 : 46035 : *op0 = expand_expr (exp0, target, VOIDmode, modifier);
9175 : 46035 : *op1 = copy_rtx (*op0);
9176 : : }
9177 : : else
9178 : : {
9179 : 7839267 : *op0 = expand_expr (exp0, target, VOIDmode, modifier);
9180 : 7839267 : *op1 = expand_expr (exp1, NULL_RTX, VOIDmode, modifier);
9181 : : }
9182 : 7885302 : }
9183 : :
9184 : :
9185 : : /* Return a MEM that contains constant EXP. DEFER is as for
9186 : : output_constant_def and MODIFIER is as for expand_expr. */
9187 : :
9188 : : static rtx
9189 : 2897992 : expand_expr_constant (tree exp, int defer, enum expand_modifier modifier)
9190 : : {
9191 : 2897992 : rtx mem;
9192 : :
9193 : 2897992 : mem = output_constant_def (exp, defer);
9194 : 2897992 : if (modifier != EXPAND_INITIALIZER)
9195 : 1865361 : mem = use_anchored_address (mem);
9196 : 2897992 : return mem;
9197 : : }
9198 : :
9199 : : /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
9200 : : The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
9201 : :
9202 : : static rtx
9203 : 14334298 : expand_expr_addr_expr_1 (tree exp, rtx target, scalar_int_mode tmode,
9204 : : enum expand_modifier modifier, addr_space_t as)
9205 : : {
9206 : 14334298 : rtx result, subtarget;
9207 : 14334298 : tree inner, offset;
9208 : 14334298 : poly_int64 bitsize, bitpos;
9209 : 14334298 : int unsignedp, reversep, volatilep = 0;
9210 : 14334298 : machine_mode mode1;
9211 : :
9212 : : /* If we are taking the address of a constant and are at the top level,
9213 : : we have to use output_constant_def since we can't call force_const_mem
9214 : : at top level. */
9215 : : /* ??? This should be considered a front-end bug. We should not be
9216 : : generating ADDR_EXPR of something that isn't an LVALUE. The only
9217 : : exception here is STRING_CST. */
9218 : 14334298 : if (CONSTANT_CLASS_P (exp))
9219 : : {
9220 : 2666785 : result = XEXP (expand_expr_constant (exp, 0, modifier), 0);
9221 : 2666785 : if (modifier < EXPAND_SUM)
9222 : 1771351 : result = force_operand (result, target);
9223 : 2666785 : return result;
9224 : : }
9225 : :
9226 : : /* Everything must be something allowed by is_gimple_addressable. */
9227 : 11667513 : switch (TREE_CODE (exp))
9228 : : {
9229 : 36 : case INDIRECT_REF:
9230 : : /* This case will happen via recursion for &a->b. */
9231 : 36 : return expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
9232 : :
9233 : 591632 : case MEM_REF:
9234 : 591632 : {
9235 : 591632 : tree tem = TREE_OPERAND (exp, 0);
9236 : 591632 : if (!integer_zerop (TREE_OPERAND (exp, 1)))
9237 : 320361 : tem = fold_build_pointer_plus (tem, TREE_OPERAND (exp, 1));
9238 : 591632 : return expand_expr (tem, target, tmode, modifier);
9239 : : }
9240 : :
9241 : 1111 : case TARGET_MEM_REF:
9242 : 1111 : return addr_for_mem_ref (exp, as, true);
9243 : :
9244 : 58719 : case CONST_DECL:
9245 : : /* Expand the initializer like constants above. */
9246 : 58719 : result = XEXP (expand_expr_constant (DECL_INITIAL (exp),
9247 : : 0, modifier), 0);
9248 : 58719 : if (modifier < EXPAND_SUM)
9249 : 58713 : result = force_operand (result, target);
9250 : : return result;
9251 : :
9252 : 167 : case REALPART_EXPR:
9253 : : /* The real part of the complex number is always first, therefore
9254 : : the address is the same as the address of the parent object. */
9255 : 167 : offset = 0;
9256 : 167 : bitpos = 0;
9257 : 167 : inner = TREE_OPERAND (exp, 0);
9258 : 167 : break;
9259 : :
9260 : 84 : case IMAGPART_EXPR:
9261 : : /* The imaginary part of the complex number is always second.
9262 : : The expression is therefore always offset by the size of the
9263 : : scalar type. */
9264 : 84 : offset = 0;
9265 : 168 : bitpos = GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (exp)));
9266 : 84 : inner = TREE_OPERAND (exp, 0);
9267 : 84 : break;
9268 : :
9269 : 13 : case COMPOUND_LITERAL_EXPR:
9270 : : /* Allow COMPOUND_LITERAL_EXPR in initializers or coming from
9271 : : initializers, if e.g. rtl_for_decl_init is called on DECL_INITIAL
9272 : : with COMPOUND_LITERAL_EXPRs in it, or ARRAY_REF on a const static
9273 : : array with address of COMPOUND_LITERAL_EXPR in DECL_INITIAL;
9274 : : the initializers aren't gimplified. */
9275 : 13 : if (COMPOUND_LITERAL_EXPR_DECL (exp)
9276 : 13 : && is_global_var (COMPOUND_LITERAL_EXPR_DECL (exp)))
9277 : 13 : return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp),
9278 : 13 : target, tmode, modifier, as);
9279 : : /* FALLTHRU */
9280 : 11015751 : default:
9281 : : /* If the object is a DECL, then expand it for its rtl. Don't bypass
9282 : : expand_expr, as that can have various side effects; LABEL_DECLs for
9283 : : example, may not have their DECL_RTL set yet. Expand the rtl of
9284 : : CONSTRUCTORs too, which should yield a memory reference for the
9285 : : constructor's contents. Assume language specific tree nodes can
9286 : : be expanded in some interesting way. */
9287 : 11015751 : gcc_assert (TREE_CODE (exp) < LAST_AND_UNUSED_TREE_CODE);
9288 : 11015751 : if (DECL_P (exp)
9289 : 1314350 : || TREE_CODE (exp) == CONSTRUCTOR
9290 : 1314350 : || TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
9291 : : {
9292 : 15902713 : result = expand_expr (exp, target, tmode,
9293 : : modifier == EXPAND_INITIALIZER
9294 : : ? EXPAND_INITIALIZER : EXPAND_CONST_ADDRESS);
9295 : :
9296 : : /* If the DECL isn't in memory, then the DECL wasn't properly
9297 : : marked TREE_ADDRESSABLE, which will be either a front-end
9298 : : or a tree optimizer bug. */
9299 : :
9300 : 9701401 : gcc_assert (MEM_P (result));
9301 : 9701401 : result = XEXP (result, 0);
9302 : :
9303 : : /* ??? Is this needed anymore? */
9304 : 9701401 : if (DECL_P (exp))
9305 : 9701401 : TREE_USED (exp) = 1;
9306 : :
9307 : 9701401 : if (modifier != EXPAND_INITIALIZER
9308 : : && modifier != EXPAND_CONST_ADDRESS
9309 : 9701401 : && modifier != EXPAND_SUM)
9310 : 4223049 : result = force_operand (result, target);
9311 : 9701401 : return result;
9312 : : }
9313 : :
9314 : : /* Pass FALSE as the last argument to get_inner_reference although
9315 : : we are expanding to RTL. The rationale is that we know how to
9316 : : handle "aligning nodes" here: we can just bypass them because
9317 : : they won't change the final object whose address will be returned
9318 : : (they actually exist only for that purpose). */
9319 : 1314350 : inner = get_inner_reference (exp, &bitsize, &bitpos, &offset, &mode1,
9320 : : &unsignedp, &reversep, &volatilep);
9321 : 1314350 : break;
9322 : : }
9323 : :
9324 : : /* We must have made progress. */
9325 : 1314601 : gcc_assert (inner != exp);
9326 : :
9327 : 1314601 : subtarget = offset || maybe_ne (bitpos, 0) ? NULL_RTX : target;
9328 : : /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
9329 : : inner alignment, force the inner to be sufficiently aligned. */
9330 : 1314601 : if (CONSTANT_CLASS_P (inner)
9331 : 1314601 : && TYPE_ALIGN (TREE_TYPE (inner)) < TYPE_ALIGN (TREE_TYPE (exp)))
9332 : : {
9333 : 0 : inner = copy_node (inner);
9334 : 0 : TREE_TYPE (inner) = copy_node (TREE_TYPE (inner));
9335 : 0 : SET_TYPE_ALIGN (TREE_TYPE (inner), TYPE_ALIGN (TREE_TYPE (exp)));
9336 : 0 : TYPE_USER_ALIGN (TREE_TYPE (inner)) = 1;
9337 : : }
9338 : 1314601 : result = expand_expr_addr_expr_1 (inner, subtarget, tmode, modifier, as);
9339 : :
9340 : 1314601 : if (offset)
9341 : : {
9342 : 51236 : rtx tmp;
9343 : :
9344 : 51236 : if (modifier != EXPAND_NORMAL)
9345 : 1516 : result = force_operand (result, NULL);
9346 : 52752 : tmp = expand_expr (offset, NULL_RTX, tmode,
9347 : : modifier == EXPAND_INITIALIZER
9348 : : ? EXPAND_INITIALIZER : EXPAND_NORMAL);
9349 : :
9350 : : /* expand_expr is allowed to return an object in a mode other
9351 : : than TMODE. If it did, we need to convert. */
9352 : 51236 : if (GET_MODE (tmp) != VOIDmode && tmode != GET_MODE (tmp))
9353 : 0 : tmp = convert_modes (tmode, GET_MODE (tmp),
9354 : 0 : tmp, TYPE_UNSIGNED (TREE_TYPE (offset)));
9355 : 51236 : result = convert_memory_address_addr_space (tmode, result, as);
9356 : 51236 : tmp = convert_memory_address_addr_space (tmode, tmp, as);
9357 : :
9358 : 51236 : if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
9359 : 1516 : result = simplify_gen_binary (PLUS, tmode, result, tmp);
9360 : : else
9361 : : {
9362 : 49720 : subtarget = maybe_ne (bitpos, 0) ? NULL_RTX : target;
9363 : 49720 : result = expand_simple_binop (tmode, PLUS, result, tmp, subtarget,
9364 : : 1, OPTAB_LIB_WIDEN);
9365 : : }
9366 : : }
9367 : :
9368 : 1314601 : if (maybe_ne (bitpos, 0))
9369 : : {
9370 : : /* Someone beforehand should have rejected taking the address
9371 : : of an object that isn't byte-aligned. */
9372 : 641797 : poly_int64 bytepos = exact_div (bitpos, BITS_PER_UNIT);
9373 : 641797 : result = convert_memory_address_addr_space (tmode, result, as);
9374 : 641797 : result = plus_constant (tmode, result, bytepos);
9375 : 641797 : if (modifier < EXPAND_SUM)
9376 : 606510 : result = force_operand (result, target);
9377 : : }
9378 : :
9379 : : return result;
9380 : : }
9381 : :
9382 : : /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
9383 : : The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
9384 : :
9385 : : static rtx
9386 : 13019682 : expand_expr_addr_expr (tree exp, rtx target, machine_mode tmode,
9387 : : enum expand_modifier modifier)
9388 : : {
9389 : 13019682 : addr_space_t as = ADDR_SPACE_GENERIC;
9390 : 13019682 : scalar_int_mode address_mode = Pmode;
9391 : 13019682 : scalar_int_mode pointer_mode = ptr_mode;
9392 : 13019682 : machine_mode rmode;
9393 : 13019682 : rtx result;
9394 : :
9395 : : /* Target mode of VOIDmode says "whatever's natural". */
9396 : 13019682 : if (tmode == VOIDmode)
9397 : 11055756 : tmode = TYPE_MODE (TREE_TYPE (exp));
9398 : :
9399 : 13019682 : if (POINTER_TYPE_P (TREE_TYPE (exp)))
9400 : : {
9401 : 13019682 : as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)));
9402 : 13019682 : address_mode = targetm.addr_space.address_mode (as);
9403 : 13019682 : pointer_mode = targetm.addr_space.pointer_mode (as);
9404 : : }
9405 : :
9406 : : /* We can get called with some Weird Things if the user does silliness
9407 : : like "(short) &a". In that case, convert_memory_address won't do
9408 : : the right thing, so ignore the given target mode. */
9409 : 13019682 : scalar_int_mode new_tmode = (tmode == pointer_mode
9410 : 13019682 : ? pointer_mode
9411 : 13019682 : : address_mode);
9412 : :
9413 : 13019682 : result = expand_expr_addr_expr_1 (TREE_OPERAND (exp, 0), target,
9414 : : new_tmode, modifier, as);
9415 : :
9416 : : /* Despite expand_expr claims concerning ignoring TMODE when not
9417 : : strictly convenient, stuff breaks if we don't honor it. Note
9418 : : that combined with the above, we only do this for pointer modes. */
9419 : 13019682 : rmode = GET_MODE (result);
9420 : 13019682 : if (rmode == VOIDmode)
9421 : 6 : rmode = new_tmode;
9422 : 13019682 : if (rmode != new_tmode)
9423 : 74 : result = convert_memory_address_addr_space (new_tmode, result, as);
9424 : :
9425 : 13019682 : return result;
9426 : : }
9427 : :
9428 : : /* Generate code for computing CONSTRUCTOR EXP.
9429 : : An rtx for the computed value is returned. If AVOID_TEMP_MEM
9430 : : is TRUE, instead of creating a temporary variable in memory
9431 : : NULL is returned and the caller needs to handle it differently. */
9432 : :
9433 : : static rtx
9434 : 180099 : expand_constructor (tree exp, rtx target, enum expand_modifier modifier,
9435 : : bool avoid_temp_mem)
9436 : : {
9437 : 180099 : tree type = TREE_TYPE (exp);
9438 : 180099 : machine_mode mode = TYPE_MODE (type);
9439 : :
9440 : : /* Try to avoid creating a temporary at all. This is possible
9441 : : if all of the initializer is zero.
9442 : : FIXME: try to handle all [0..255] initializers we can handle
9443 : : with memset. */
9444 : 180099 : if (TREE_STATIC (exp)
9445 : 2210 : && !TREE_ADDRESSABLE (exp)
9446 : 2210 : && target != 0 && mode == BLKmode
9447 : 181375 : && all_zeros_p (exp))
9448 : : {
9449 : 1267 : clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
9450 : 1267 : return target;
9451 : : }
9452 : :
9453 : : /* All elts simple constants => refer to a constant in memory. But
9454 : : if this is a non-BLKmode mode, let it store a field at a time
9455 : : since that should make a CONST_INT, CONST_WIDE_INT or
9456 : : CONST_DOUBLE when we fold. Likewise, if we have a target we can
9457 : : use, it is best to store directly into the target unless the type
9458 : : is large enough that memcpy will be used. If we are making an
9459 : : initializer and all operands are constant, put it in memory as
9460 : : well.
9461 : :
9462 : : FIXME: Avoid trying to fill vector constructors piece-meal.
9463 : : Output them with output_constant_def below unless we're sure
9464 : : they're zeros. This should go away when vector initializers
9465 : : are treated like VECTOR_CST instead of arrays. */
9466 : 178832 : if ((TREE_STATIC (exp)
9467 : 943 : && ((mode == BLKmode
9468 : 46 : && ! (target != 0 && safe_from_p (target, exp, 1)))
9469 : 906 : || TREE_ADDRESSABLE (exp)
9470 : 906 : || (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type))
9471 : 906 : && (! can_move_by_pieces
9472 : 906 : (tree_to_uhwi (TYPE_SIZE_UNIT (type)),
9473 : 906 : TYPE_ALIGN (type)))
9474 : 4 : && ! mostly_zeros_p (exp))))
9475 : 179736 : || ((modifier == EXPAND_INITIALIZER || modifier == EXPAND_CONST_ADDRESS)
9476 : 0 : && TREE_CONSTANT (exp)))
9477 : : {
9478 : 39 : rtx constructor;
9479 : :
9480 : 39 : if (avoid_temp_mem)
9481 : : return NULL_RTX;
9482 : :
9483 : 37 : constructor = expand_expr_constant (exp, 1, modifier);
9484 : :
9485 : 37 : if (modifier != EXPAND_CONST_ADDRESS
9486 : : && modifier != EXPAND_INITIALIZER
9487 : 37 : && modifier != EXPAND_SUM)
9488 : 37 : constructor = validize_mem (constructor);
9489 : :
9490 : 37 : return constructor;
9491 : : }
9492 : :
9493 : : /* If the CTOR is available in static storage and not mostly
9494 : : zeros and we can move it by pieces prefer to do so since
9495 : : that's usually more efficient than performing a series of
9496 : : stores from immediates. */
9497 : 178793 : if (avoid_temp_mem
9498 : 74 : && TREE_STATIC (exp)
9499 : 38 : && TREE_CONSTANT (exp)
9500 : 38 : && tree_fits_uhwi_p (TYPE_SIZE_UNIT (type))
9501 : 38 : && can_move_by_pieces (tree_to_uhwi (TYPE_SIZE_UNIT (type)),
9502 : 38 : TYPE_ALIGN (type))
9503 : 178830 : && ! mostly_zeros_p (exp))
9504 : : return NULL_RTX;
9505 : :
9506 : : /* Handle calls that pass values in multiple non-contiguous
9507 : : locations. The Irix 6 ABI has examples of this. */
9508 : 143481 : if (target == 0 || ! safe_from_p (target, exp, 1)
9509 : 38643 : || GET_CODE (target) == PARALLEL || modifier == EXPAND_STACK_PARM
9510 : : /* Also make a temporary if the store is to volatile memory, to
9511 : : avoid individual accesses to aggregate members. */
9512 : 217394 : || (GET_CODE (target) == MEM
9513 : 34593 : && MEM_VOLATILE_P (target)
9514 : 134 : && !TREE_ADDRESSABLE (TREE_TYPE (exp))))
9515 : : {
9516 : 140260 : if (avoid_temp_mem)
9517 : : return NULL_RTX;
9518 : :
9519 : 140249 : target = assign_temp (type, TREE_ADDRESSABLE (exp), 1);
9520 : : }
9521 : :
9522 : 178752 : store_constructor (exp, target, 0, int_expr_size (exp), false);
9523 : 178752 : return target;
9524 : : }
9525 : :
9526 : :
9527 : : /* expand_expr: generate code for computing expression EXP.
9528 : : An rtx for the computed value is returned. The value is never null.
9529 : : In the case of a void EXP, const0_rtx is returned.
9530 : :
9531 : : The value may be stored in TARGET if TARGET is nonzero.
9532 : : TARGET is just a suggestion; callers must assume that
9533 : : the rtx returned may not be the same as TARGET.
9534 : :
9535 : : If TARGET is CONST0_RTX, it means that the value will be ignored.
9536 : :
9537 : : If TMODE is not VOIDmode, it suggests generating the
9538 : : result in mode TMODE. But this is done only when convenient.
9539 : : Otherwise, TMODE is ignored and the value generated in its natural mode.
9540 : : TMODE is just a suggestion; callers must assume that
9541 : : the rtx returned may not have mode TMODE.
9542 : :
9543 : : Note that TARGET may have neither TMODE nor MODE. In that case, it
9544 : : probably will not be used.
9545 : :
9546 : : If MODIFIER is EXPAND_SUM then when EXP is an addition
9547 : : we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
9548 : : or a nest of (PLUS ...) and (MINUS ...) where the terms are
9549 : : products as above, or REG or MEM, or constant.
9550 : : Ordinarily in such cases we would output mul or add instructions
9551 : : and then return a pseudo reg containing the sum.
9552 : :
9553 : : EXPAND_INITIALIZER is much like EXPAND_SUM except that
9554 : : it also marks a label as absolutely required (it can't be dead).
9555 : : It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
9556 : : This is used for outputting expressions used in initializers.
9557 : :
9558 : : EXPAND_CONST_ADDRESS says that it is okay to return a MEM
9559 : : with a constant address even if that address is not normally legitimate.
9560 : : EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
9561 : :
9562 : : EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
9563 : : a call parameter. Such targets require special care as we haven't yet
9564 : : marked TARGET so that it's safe from being trashed by libcalls. We
9565 : : don't want to use TARGET for anything but the final result;
9566 : : Intermediate values must go elsewhere. Additionally, calls to
9567 : : emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
9568 : :
9569 : : If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
9570 : : address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
9571 : : DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
9572 : : COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
9573 : : recursively.
9574 : : If the result can be stored at TARGET, and ALT_RTL is non-NULL,
9575 : : then *ALT_RTL is set to TARGET (before legitimziation).
9576 : :
9577 : : If INNER_REFERENCE_P is true, we are expanding an inner reference.
9578 : : In this case, we don't adjust a returned MEM rtx that wouldn't be
9579 : : sufficiently aligned for its mode; instead, it's up to the caller
9580 : : to deal with it afterwards. This is used to make sure that unaligned
9581 : : base objects for which out-of-bounds accesses are supported, for
9582 : : example record types with trailing arrays, aren't realigned behind
9583 : : the back of the caller.
9584 : : The normal operating mode is to pass FALSE for this parameter. */
9585 : :
9586 : : rtx
9587 : 155661849 : expand_expr_real (tree exp, rtx target, machine_mode tmode,
9588 : : enum expand_modifier modifier, rtx *alt_rtl,
9589 : : bool inner_reference_p)
9590 : : {
9591 : 155661849 : rtx ret;
9592 : :
9593 : : /* Handle ERROR_MARK before anybody tries to access its type. */
9594 : 155661849 : if (TREE_CODE (exp) == ERROR_MARK
9595 : 155661849 : || (TREE_CODE (TREE_TYPE (exp)) == ERROR_MARK))
9596 : : {
9597 : 0 : ret = CONST0_RTX (tmode);
9598 : 0 : return ret ? ret : const0_rtx;
9599 : : }
9600 : :
9601 : 155661849 : ret = expand_expr_real_1 (exp, target, tmode, modifier, alt_rtl,
9602 : : inner_reference_p);
9603 : 155661849 : return ret;
9604 : : }
9605 : :
9606 : : /* Try to expand the conditional expression which is represented by
9607 : : TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If it succeeds
9608 : : return the rtl reg which represents the result. Otherwise return
9609 : : NULL_RTX. */
9610 : :
9611 : : static rtx
9612 : 17829 : expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED,
9613 : : tree treeop1 ATTRIBUTE_UNUSED,
9614 : : tree treeop2 ATTRIBUTE_UNUSED)
9615 : : {
9616 : 17829 : rtx insn;
9617 : 17829 : rtx op00, op01, op1, op2;
9618 : 17829 : enum rtx_code comparison_code;
9619 : 17829 : machine_mode comparison_mode;
9620 : 17829 : gimple *srcstmt;
9621 : 17829 : rtx temp;
9622 : 17829 : tree type = TREE_TYPE (treeop1);
9623 : 17829 : int unsignedp = TYPE_UNSIGNED (type);
9624 : 17829 : machine_mode mode = TYPE_MODE (type);
9625 : 17829 : machine_mode orig_mode = mode;
9626 : 17829 : static bool expanding_cond_expr_using_cmove = false;
9627 : :
9628 : : /* Conditional move expansion can end up TERing two operands which,
9629 : : when recursively hitting conditional expressions can result in
9630 : : exponential behavior if the cmove expansion ultimatively fails.
9631 : : It's hardly profitable to TER a cmove into a cmove so avoid doing
9632 : : that by failing early if we end up recursing. */
9633 : 17829 : if (expanding_cond_expr_using_cmove)
9634 : : return NULL_RTX;
9635 : :
9636 : : /* If we cannot do a conditional move on the mode, try doing it
9637 : : with the promoted mode. */
9638 : 16869 : if (!can_conditionally_move_p (mode))
9639 : : {
9640 : 251 : mode = promote_mode (type, mode, &unsignedp);
9641 : 251 : if (!can_conditionally_move_p (mode))
9642 : : return NULL_RTX;
9643 : 0 : temp = assign_temp (type, 0, 0); /* Use promoted mode for temp. */
9644 : : }
9645 : : else
9646 : 16618 : temp = assign_temp (type, 0, 1);
9647 : :
9648 : 16618 : expanding_cond_expr_using_cmove = true;
9649 : 16618 : start_sequence ();
9650 : 16618 : expand_operands (treeop1, treeop2,
9651 : : mode == orig_mode ? temp : NULL_RTX, &op1, &op2,
9652 : : EXPAND_NORMAL);
9653 : :
9654 : 16618 : if (TREE_CODE (treeop0) == SSA_NAME
9655 : 16419 : && (srcstmt = get_def_for_expr_class (treeop0, tcc_comparison))
9656 : 30748 : && !VECTOR_TYPE_P (TREE_TYPE (gimple_assign_rhs1 (srcstmt))))
9657 : : {
9658 : 14127 : type = TREE_TYPE (gimple_assign_rhs1 (srcstmt));
9659 : 14127 : enum tree_code cmpcode = gimple_assign_rhs_code (srcstmt);
9660 : 14127 : op00 = expand_normal (gimple_assign_rhs1 (srcstmt));
9661 : 14127 : op01 = expand_normal (gimple_assign_rhs2 (srcstmt));
9662 : 14127 : comparison_mode = TYPE_MODE (type);
9663 : 14127 : unsignedp = TYPE_UNSIGNED (type);
9664 : 14127 : comparison_code = convert_tree_comp_to_rtx (cmpcode, unsignedp);
9665 : : }
9666 : 2491 : else if (COMPARISON_CLASS_P (treeop0)
9667 : 2491 : && !VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (treeop0, 0))))
9668 : : {
9669 : 199 : type = TREE_TYPE (TREE_OPERAND (treeop0, 0));
9670 : 199 : enum tree_code cmpcode = TREE_CODE (treeop0);
9671 : 199 : op00 = expand_normal (TREE_OPERAND (treeop0, 0));
9672 : 199 : op01 = expand_normal (TREE_OPERAND (treeop0, 1));
9673 : 199 : unsignedp = TYPE_UNSIGNED (type);
9674 : 199 : comparison_mode = TYPE_MODE (type);
9675 : 199 : comparison_code = convert_tree_comp_to_rtx (cmpcode, unsignedp);
9676 : : }
9677 : : else
9678 : : {
9679 : 2292 : op00 = expand_normal (treeop0);
9680 : 2292 : op01 = const0_rtx;
9681 : 2292 : comparison_code = NE;
9682 : 2292 : comparison_mode = GET_MODE (op00);
9683 : 2292 : if (comparison_mode == VOIDmode)
9684 : 0 : comparison_mode = TYPE_MODE (TREE_TYPE (treeop0));
9685 : : }
9686 : 16618 : expanding_cond_expr_using_cmove = false;
9687 : :
9688 : 16618 : if (GET_MODE (op1) != mode)
9689 : 2062 : op1 = gen_lowpart (mode, op1);
9690 : :
9691 : 16618 : if (GET_MODE (op2) != mode)
9692 : 9206 : op2 = gen_lowpart (mode, op2);
9693 : :
9694 : : /* Try to emit the conditional move. */
9695 : 16618 : insn = emit_conditional_move (temp,
9696 : : { comparison_code, op00, op01,
9697 : : comparison_mode },
9698 : : op1, op2, mode,
9699 : : unsignedp);
9700 : :
9701 : : /* If we could do the conditional move, emit the sequence,
9702 : : and return. */
9703 : 16618 : if (insn)
9704 : : {
9705 : 14064 : rtx_insn *seq = end_sequence ();
9706 : 14064 : emit_insn (seq);
9707 : 14064 : return convert_modes (orig_mode, mode, temp, 0);
9708 : : }
9709 : :
9710 : : /* Otherwise discard the sequence and fall back to code with
9711 : : branches. */
9712 : 2554 : end_sequence ();
9713 : 2554 : return NULL_RTX;
9714 : : }
9715 : :
9716 : : /* A helper function for expand_expr_real_2 to be used with a
9717 : : misaligned mem_ref TEMP. Assume an unsigned type if UNSIGNEDP
9718 : : is nonzero, with alignment ALIGN in bits.
9719 : : Store the value at TARGET if possible (if TARGET is nonzero).
9720 : : Regardless of TARGET, we return the rtx for where the value is placed.
9721 : : If the result can be stored at TARGET, and ALT_RTL is non-NULL,
9722 : : then *ALT_RTL is set to TARGET (before legitimziation). */
9723 : :
9724 : : static rtx
9725 : 201297 : expand_misaligned_mem_ref (rtx temp, machine_mode mode, int unsignedp,
9726 : : unsigned int align, rtx target, rtx *alt_rtl)
9727 : : {
9728 : 201297 : enum insn_code icode;
9729 : :
9730 : 201297 : if ((icode = optab_handler (movmisalign_optab, mode))
9731 : : != CODE_FOR_nothing)
9732 : : {
9733 : 125630 : class expand_operand ops[2];
9734 : :
9735 : : /* We've already validated the memory, and we're creating a
9736 : : new pseudo destination. The predicates really can't fail,
9737 : : nor can the generator. */
9738 : 125630 : create_output_operand (&ops[0], NULL_RTX, mode);
9739 : 125630 : create_fixed_operand (&ops[1], temp);
9740 : 125630 : expand_insn (icode, 2, ops);
9741 : 125630 : temp = ops[0].value;
9742 : : }
9743 : 75667 : else if (targetm.slow_unaligned_access (mode, align))
9744 : 0 : temp = extract_bit_field (temp, GET_MODE_BITSIZE (mode),
9745 : : 0, unsignedp, target,
9746 : : mode, mode, false, alt_rtl);
9747 : 201297 : return temp;
9748 : : }
9749 : :
9750 : : /* Helper function of expand_expr_2, expand a division or modulo.
9751 : : op0 and op1 should be already expanded treeop0 and treeop1, using
9752 : : expand_operands. */
9753 : :
9754 : : static rtx
9755 : 160579 : expand_expr_divmod (tree_code code, machine_mode mode, tree treeop0,
9756 : : tree treeop1, rtx op0, rtx op1, rtx target, int unsignedp)
9757 : : {
9758 : 321158 : bool mod_p = (code == TRUNC_MOD_EXPR || code == FLOOR_MOD_EXPR
9759 : 160579 : || code == CEIL_MOD_EXPR || code == ROUND_MOD_EXPR);
9760 : 160579 : if (SCALAR_INT_MODE_P (mode)
9761 : 160579 : && optimize >= 2
9762 : 134651 : && get_range_pos_neg (treeop0, currently_expanding_gimple_stmt) == 1
9763 : 199245 : && get_range_pos_neg (treeop1, currently_expanding_gimple_stmt) == 1)
9764 : : {
9765 : : /* If both arguments are known to be positive when interpreted
9766 : : as signed, we can expand it as both signed and unsigned
9767 : : division or modulo. Choose the cheaper sequence in that case. */
9768 : 26058 : bool speed_p = optimize_insn_for_speed_p ();
9769 : 26058 : do_pending_stack_adjust ();
9770 : 26058 : start_sequence ();
9771 : 26058 : rtx uns_ret = expand_divmod (mod_p, code, mode, op0, op1, target, 1);
9772 : 26058 : rtx_insn *uns_insns = end_sequence ();
9773 : 26058 : start_sequence ();
9774 : 26058 : rtx sgn_ret = expand_divmod (mod_p, code, mode, op0, op1, target, 0);
9775 : 26058 : rtx_insn *sgn_insns = end_sequence ();
9776 : 26058 : unsigned uns_cost = seq_cost (uns_insns, speed_p);
9777 : 26058 : unsigned sgn_cost = seq_cost (sgn_insns, speed_p);
9778 : 26058 : bool was_tie = false;
9779 : :
9780 : : /* If costs are the same then use as tie breaker the other other
9781 : : factor. */
9782 : 26058 : if (uns_cost == sgn_cost)
9783 : : {
9784 : 12364 : uns_cost = seq_cost (uns_insns, !speed_p);
9785 : 12364 : sgn_cost = seq_cost (sgn_insns, !speed_p);
9786 : 12364 : was_tie = true;
9787 : : }
9788 : :
9789 : 26058 : if (dump_file && (dump_flags & TDF_DETAILS))
9790 : 0 : fprintf (dump_file, ";; positive division:%s unsigned cost: %u; "
9791 : : "signed cost: %u\n",
9792 : : was_tie ? " (needed tie breaker)" : "", uns_cost, sgn_cost);
9793 : :
9794 : 26058 : if (uns_cost < sgn_cost || (uns_cost == sgn_cost && unsignedp))
9795 : : {
9796 : 14612 : emit_insn (uns_insns);
9797 : 14612 : return uns_ret;
9798 : : }
9799 : 11446 : emit_insn (sgn_insns);
9800 : 11446 : return sgn_ret;
9801 : : }
9802 : 134521 : return expand_divmod (mod_p, code, mode, op0, op1, target, unsignedp);
9803 : : }
9804 : :
9805 : : /* Return true if EXP has a range of values [0..1], false
9806 : : otherwise. This works for constants and ssa names, calling back into the ranger. */
9807 : : static bool
9808 : 1425374 : expr_has_boolean_range (tree exp, gimple *stmt)
9809 : : {
9810 : : /* An integral type with a single bit of precision. */
9811 : 2850735 : if (INTEGRAL_TYPE_P (TREE_TYPE (exp))
9812 : 1425374 : && TYPE_UNSIGNED (TREE_TYPE (exp))
9813 : 2400838 : && TYPE_PRECISION (TREE_TYPE (exp)) == 1)
9814 : : return true;
9815 : :
9816 : : /* Signed 1 bit integers are not boolean ranges. */
9817 : 2850735 : if (!INTEGRAL_TYPE_P (TREE_TYPE (exp))
9818 : 2850735 : || TYPE_PRECISION (TREE_TYPE (exp)) <= 1)
9819 : : return false;
9820 : :
9821 : 1425374 : if (TREE_CODE (exp) == SSA_NAME)
9822 : 830719 : return ssa_name_has_boolean_range (exp, stmt);
9823 : 594655 : if (TREE_CODE (exp) == INTEGER_CST)
9824 : 523683 : return wi::leu_p (wi::to_wide (exp), 1);
9825 : : return false;
9826 : : }
9827 : :
9828 : : rtx
9829 : 13090514 : expand_expr_real_2 (const_sepops ops, rtx target, machine_mode tmode,
9830 : : enum expand_modifier modifier)
9831 : : {
9832 : 13090514 : rtx op0, op1, op2, temp;
9833 : 13090514 : rtx_code_label *lab;
9834 : 13090514 : tree type;
9835 : 13090514 : int unsignedp;
9836 : 13090514 : machine_mode mode;
9837 : 13090514 : scalar_int_mode int_mode;
9838 : 13090514 : enum tree_code code = ops->code;
9839 : 13090514 : optab this_optab;
9840 : 13090514 : rtx subtarget, original_target;
9841 : 13090514 : int ignore;
9842 : 13090514 : bool reduce_bit_field;
9843 : 13090514 : location_t loc = ops->location;
9844 : 13090514 : tree treeop0, treeop1, treeop2;
9845 : : #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
9846 : : ? reduce_to_bit_field_precision ((expr), \
9847 : : target, \
9848 : : type) \
9849 : : : (expr))
9850 : :
9851 : 13090514 : type = ops->type;
9852 : 13090514 : mode = TYPE_MODE (type);
9853 : 13090514 : unsignedp = TYPE_UNSIGNED (type);
9854 : :
9855 : 13090514 : treeop0 = ops->op0;
9856 : 13090514 : treeop1 = ops->op1;
9857 : 13090514 : treeop2 = ops->op2;
9858 : :
9859 : : /* We should be called only on simple (binary or unary) expressions,
9860 : : exactly those that are valid in gimple expressions that aren't
9861 : : GIMPLE_SINGLE_RHS (or invalid). */
9862 : 13090514 : gcc_assert (get_gimple_rhs_class (code) == GIMPLE_UNARY_RHS
9863 : : || get_gimple_rhs_class (code) == GIMPLE_BINARY_RHS
9864 : : || get_gimple_rhs_class (code) == GIMPLE_TERNARY_RHS);
9865 : :
9866 : 26181028 : ignore = (target == const0_rtx
9867 : 13090514 : || ((CONVERT_EXPR_CODE_P (code)
9868 : 9403442 : || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
9869 : 3704901 : && TREE_CODE (type) == VOID_TYPE));
9870 : :
9871 : : /* We should be called only if we need the result. */
9872 : 0 : gcc_assert (!ignore);
9873 : :
9874 : : /* An operation in what may be a bit-field type needs the
9875 : : result to be reduced to the precision of the bit-field type,
9876 : : which is narrower than that of the type's mode. */
9877 : 26879711 : reduce_bit_field = (INTEGRAL_TYPE_P (type)
9878 : 13090514 : && !type_has_mode_precision_p (type));
9879 : :
9880 : 698683 : if (reduce_bit_field
9881 : 698683 : && (modifier == EXPAND_STACK_PARM
9882 : 698162 : || (target && GET_MODE (target) != mode)))
9883 : 386414 : target = 0;
9884 : :
9885 : : /* Use subtarget as the target for operand 0 of a binary operation. */
9886 : 13090514 : subtarget = get_subtarget (target);
9887 : 13090514 : original_target = target;
9888 : :
9889 : 13090514 : switch (code)
9890 : : {
9891 : 3690253 : case NON_LVALUE_EXPR:
9892 : 3690253 : case PAREN_EXPR:
9893 : 3690253 : CASE_CONVERT:
9894 : 3690253 : if (treeop0 == error_mark_node)
9895 : 0 : return const0_rtx;
9896 : :
9897 : 3690253 : if (TREE_CODE (type) == UNION_TYPE)
9898 : : {
9899 : 0 : tree valtype = TREE_TYPE (treeop0);
9900 : :
9901 : : /* If both input and output are BLKmode, this conversion isn't doing
9902 : : anything except possibly changing memory attribute. */
9903 : 0 : if (mode == BLKmode && TYPE_MODE (valtype) == BLKmode)
9904 : : {
9905 : 0 : rtx result = expand_expr (treeop0, target, tmode,
9906 : : modifier);
9907 : :
9908 : 0 : result = copy_rtx (result);
9909 : 0 : set_mem_attributes (result, type, 0);
9910 : 0 : return result;
9911 : : }
9912 : :
9913 : 0 : if (target == 0)
9914 : : {
9915 : 0 : if (TYPE_MODE (type) != BLKmode)
9916 : 0 : target = gen_reg_rtx (TYPE_MODE (type));
9917 : : else
9918 : 0 : target = assign_temp (type, 1, 1);
9919 : : }
9920 : :
9921 : 0 : if (MEM_P (target))
9922 : : /* Store data into beginning of memory target. */
9923 : 0 : store_expr (treeop0,
9924 : 0 : adjust_address (target, TYPE_MODE (valtype), 0),
9925 : : modifier == EXPAND_STACK_PARM,
9926 : 0 : false, TYPE_REVERSE_STORAGE_ORDER (type));
9927 : :
9928 : : else
9929 : : {
9930 : 0 : gcc_assert (REG_P (target)
9931 : : && !TYPE_REVERSE_STORAGE_ORDER (type));
9932 : :
9933 : : /* Store this field into a union of the proper type. */
9934 : 0 : poly_uint64 op0_size
9935 : 0 : = tree_to_poly_uint64 (TYPE_SIZE (TREE_TYPE (treeop0)));
9936 : 0 : poly_uint64 union_size = GET_MODE_BITSIZE (mode);
9937 : 0 : store_field (target,
9938 : : /* The conversion must be constructed so that
9939 : : we know at compile time how many bits
9940 : : to preserve. */
9941 : 0 : ordered_min (op0_size, union_size),
9942 : 0 : 0, 0, 0, TYPE_MODE (valtype), treeop0, 0,
9943 : : false, false);
9944 : : }
9945 : :
9946 : : /* Return the entire union. */
9947 : 0 : return target;
9948 : : }
9949 : :
9950 : 3690253 : if (mode == TYPE_MODE (TREE_TYPE (treeop0)))
9951 : : {
9952 : 2194405 : op0 = expand_expr (treeop0, target, VOIDmode,
9953 : : modifier);
9954 : :
9955 : 2194405 : return REDUCE_BIT_FIELD (op0);
9956 : : }
9957 : :
9958 : 1860833 : op0 = expand_expr (treeop0, NULL_RTX, mode,
9959 : : modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier);
9960 : 1495848 : if (GET_MODE (op0) == mode)
9961 : : ;
9962 : :
9963 : : /* If OP0 is a constant, just convert it into the proper mode. */
9964 : 1454975 : else if (CONSTANT_P (op0))
9965 : : {
9966 : 901 : tree inner_type = TREE_TYPE (treeop0);
9967 : 901 : machine_mode inner_mode = GET_MODE (op0);
9968 : :
9969 : 901 : if (inner_mode == VOIDmode)
9970 : 15 : inner_mode = TYPE_MODE (inner_type);
9971 : :
9972 : 901 : if (modifier == EXPAND_INITIALIZER)
9973 : 0 : op0 = force_lowpart_subreg (mode, op0, inner_mode);
9974 : : else
9975 : 901 : op0 = convert_modes (mode, inner_mode, op0,
9976 : 901 : TYPE_UNSIGNED (inner_type));
9977 : : }
9978 : :
9979 : 1454074 : else if (modifier == EXPAND_INITIALIZER)
9980 : 24 : op0 = gen_rtx_fmt_e (TYPE_UNSIGNED (TREE_TYPE (treeop0))
9981 : : ? ZERO_EXTEND : SIGN_EXTEND, mode, op0);
9982 : :
9983 : 1454062 : else if (SCALAR_INT_MODE_P (GET_MODE (op0))
9984 : 1281546 : && optimize >= 2
9985 : 751211 : && SCALAR_INT_MODE_P (mode)
9986 : 751211 : && INTEGRAL_TYPE_P (TREE_TYPE (treeop0))
9987 : 751006 : && (GET_MODE_SIZE (as_a <scalar_int_mode> (mode))
9988 : 1502012 : > GET_MODE_SIZE (as_a <scalar_int_mode> (GET_MODE (op0))))
9989 : 1964310 : && get_range_pos_neg (treeop0,
9990 : : currently_expanding_gimple_stmt) == 1)
9991 : : {
9992 : : /* If argument is known to be positive when interpreted
9993 : : as signed, we can expand it as both sign and zero
9994 : : extension. Choose the cheaper sequence in that case. */
9995 : 153662 : bool speed_p = optimize_insn_for_speed_p ();
9996 : 153662 : rtx uns_ret = NULL_RTX, sgn_ret = NULL_RTX;
9997 : 153662 : do_pending_stack_adjust ();
9998 : 153662 : start_sequence ();
9999 : 153662 : if (target == NULL_RTX)
10000 : 124858 : uns_ret = convert_to_mode (mode, op0, 1);
10001 : : else
10002 : 28804 : convert_move (target, op0, 1);
10003 : 153662 : rtx_insn *uns_insns = end_sequence ();
10004 : 153662 : start_sequence ();
10005 : 153662 : if (target == NULL_RTX)
10006 : 124858 : sgn_ret = convert_to_mode (mode, op0, 0);
10007 : : else
10008 : 28804 : convert_move (target, op0, 0);
10009 : 153662 : rtx_insn *sgn_insns = end_sequence ();
10010 : 153662 : unsigned uns_cost = seq_cost (uns_insns, speed_p);
10011 : 153662 : unsigned sgn_cost = seq_cost (sgn_insns, speed_p);
10012 : 153662 : bool was_tie = false;
10013 : :
10014 : : /* If costs are the same then use as tie breaker the other other
10015 : : factor. */
10016 : 153662 : if (uns_cost == sgn_cost)
10017 : : {
10018 : 43112 : uns_cost = seq_cost (uns_insns, !speed_p);
10019 : 43112 : sgn_cost = seq_cost (sgn_insns, !speed_p);
10020 : 43112 : was_tie = true;
10021 : : }
10022 : :
10023 : 153662 : if (dump_file && (dump_flags & TDF_DETAILS))
10024 : 0 : fprintf (dump_file, ";; positive extension:%s unsigned cost: %u; "
10025 : : "signed cost: %u\n",
10026 : : was_tie ? " (needed tie breaker)" : "",
10027 : : uns_cost, sgn_cost);
10028 : 153662 : if (uns_cost < sgn_cost
10029 : 153662 : || (uns_cost == sgn_cost && TYPE_UNSIGNED (TREE_TYPE (treeop0))))
10030 : : {
10031 : 138045 : emit_insn (uns_insns);
10032 : 138045 : sgn_ret = uns_ret;
10033 : : }
10034 : : else
10035 : 15617 : emit_insn (sgn_insns);
10036 : 153662 : if (target == NULL_RTX)
10037 : 124858 : op0 = sgn_ret;
10038 : : else
10039 : 28804 : op0 = target;
10040 : : }
10041 : 1300400 : else if (target == 0)
10042 : 801962 : op0 = convert_to_mode (mode, op0, TYPE_UNSIGNED (TREE_TYPE (treeop0)));
10043 : : else
10044 : : {
10045 : 498438 : convert_move (target, op0, TYPE_UNSIGNED (TREE_TYPE (treeop0)));
10046 : 498438 : op0 = target;
10047 : : }
10048 : :
10049 : 1495848 : return REDUCE_BIT_FIELD (op0);
10050 : :
10051 : 0 : case ADDR_SPACE_CONVERT_EXPR:
10052 : 0 : {
10053 : 0 : tree treeop0_type = TREE_TYPE (treeop0);
10054 : :
10055 : 0 : gcc_assert (POINTER_TYPE_P (type));
10056 : 0 : gcc_assert (POINTER_TYPE_P (treeop0_type));
10057 : :
10058 : 0 : addr_space_t as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
10059 : 0 : addr_space_t as_from = TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type));
10060 : :
10061 : : /* Conversions between pointers to the same address space should
10062 : : have been implemented via CONVERT_EXPR / NOP_EXPR. */
10063 : 0 : gcc_assert (as_to != as_from);
10064 : :
10065 : 0 : op0 = expand_expr (treeop0, NULL_RTX, VOIDmode, modifier);
10066 : :
10067 : : /* Ask target code to handle conversion between pointers
10068 : : to overlapping address spaces. */
10069 : 0 : if (targetm.addr_space.subset_p (as_to, as_from)
10070 : 0 : || targetm.addr_space.subset_p (as_from, as_to))
10071 : : {
10072 : 0 : op0 = targetm.addr_space.convert (op0, treeop0_type, type);
10073 : : }
10074 : : else
10075 : : {
10076 : : /* For disjoint address spaces, converting anything but a null
10077 : : pointer invokes undefined behavior. We truncate or extend the
10078 : : value as if we'd converted via integers, which handles 0 as
10079 : : required, and all others as the programmer likely expects. */
10080 : : #ifndef POINTERS_EXTEND_UNSIGNED
10081 : : const int POINTERS_EXTEND_UNSIGNED = 1;
10082 : : #endif
10083 : 0 : op0 = convert_modes (mode, TYPE_MODE (treeop0_type),
10084 : : op0, POINTERS_EXTEND_UNSIGNED);
10085 : : }
10086 : 0 : gcc_assert (op0);
10087 : : return op0;
10088 : : }
10089 : :
10090 : 1390451 : case POINTER_PLUS_EXPR:
10091 : : /* Even though the sizetype mode and the pointer's mode can be different
10092 : : expand is able to handle this correctly and get the correct result out
10093 : : of the PLUS_EXPR code. */
10094 : : /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
10095 : : if sizetype precision is smaller than pointer precision. */
10096 : 1390451 : if (TYPE_PRECISION (sizetype) < TYPE_PRECISION (type))
10097 : 0 : treeop1 = fold_convert_loc (loc, type,
10098 : : fold_convert_loc (loc, ssizetype,
10099 : : treeop1));
10100 : : /* If sizetype precision is larger than pointer precision, truncate the
10101 : : offset to have matching modes. */
10102 : 1390451 : else if (TYPE_PRECISION (sizetype) > TYPE_PRECISION (type))
10103 : 0 : treeop1 = fold_convert_loc (loc, type, treeop1);
10104 : : /* FALLTHRU */
10105 : :
10106 : 5243807 : case PLUS_EXPR:
10107 : : /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
10108 : : something else, make sure we add the register to the constant and
10109 : : then to the other thing. This case can occur during strength
10110 : : reduction and doing it this way will produce better code if the
10111 : : frame pointer or argument pointer is eliminated.
10112 : :
10113 : : fold-const.cc will ensure that the constant is always in the inner
10114 : : PLUS_EXPR, so the only case we need to do anything about is if
10115 : : sp, ap, or fp is our second argument, in which case we must swap
10116 : : the innermost first argument and our second argument. */
10117 : :
10118 : 5243807 : if (TREE_CODE (treeop0) == PLUS_EXPR
10119 : 6900 : && TREE_CODE (TREE_OPERAND (treeop0, 1)) == INTEGER_CST
10120 : 0 : && VAR_P (treeop1)
10121 : 5243807 : && (DECL_RTL (treeop1) == frame_pointer_rtx
10122 : 0 : || DECL_RTL (treeop1) == stack_pointer_rtx
10123 : 0 : || DECL_RTL (treeop1) == arg_pointer_rtx))
10124 : : {
10125 : 0 : gcc_unreachable ();
10126 : : }
10127 : :
10128 : : /* If the result is to be ptr_mode and we are adding an integer to
10129 : : something, we might be forming a constant. So try to use
10130 : : plus_constant. If it produces a sum and we can't accept it,
10131 : : use force_operand. This allows P = &ARR[const] to generate
10132 : : efficient code on machines where a SYMBOL_REF is not a valid
10133 : : address.
10134 : :
10135 : : If this is an EXPAND_SUM call, always return the sum. */
10136 : 5243807 : if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER
10137 : 5243807 : || (mode == ptr_mode && (unsignedp || ! flag_trapv)))
10138 : : {
10139 : 3436846 : if (modifier == EXPAND_STACK_PARM)
10140 : 18747 : target = 0;
10141 : 3436846 : if (TREE_CODE (treeop0) == INTEGER_CST
10142 : 3437853 : && HWI_COMPUTABLE_MODE_P (mode)
10143 : 3437857 : && TREE_CONSTANT (treeop1))
10144 : : {
10145 : 4 : rtx constant_part;
10146 : 4 : HOST_WIDE_INT wc;
10147 : 4 : machine_mode wmode = TYPE_MODE (TREE_TYPE (treeop1));
10148 : :
10149 : 4 : op1 = expand_expr (treeop1, subtarget, VOIDmode,
10150 : : EXPAND_SUM);
10151 : : /* Use wi::shwi to ensure that the constant is
10152 : : truncated according to the mode of OP1, then sign extended
10153 : : to a HOST_WIDE_INT. Using the constant directly can result
10154 : : in non-canonical RTL in a 64x32 cross compile. */
10155 : 4 : wc = TREE_INT_CST_LOW (treeop0);
10156 : 4 : constant_part =
10157 : 4 : immed_wide_int_const (wi::shwi (wc, wmode), wmode);
10158 : 4 : op1 = plus_constant (mode, op1, INTVAL (constant_part));
10159 : 4 : if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
10160 : 1 : op1 = force_operand (op1, target);
10161 : 4 : return REDUCE_BIT_FIELD (op1);
10162 : : }
10163 : :
10164 : 3436842 : else if (TREE_CODE (treeop1) == INTEGER_CST
10165 : 7282306 : && HWI_COMPUTABLE_MODE_P (mode)
10166 : 5755066 : && TREE_CONSTANT (treeop0))
10167 : : {
10168 : 279721 : rtx constant_part;
10169 : 279721 : HOST_WIDE_INT wc;
10170 : 279721 : machine_mode wmode = TYPE_MODE (TREE_TYPE (treeop0));
10171 : :
10172 : 488792 : op0 = expand_expr (treeop0, subtarget, VOIDmode,
10173 : : (modifier == EXPAND_INITIALIZER
10174 : : ? EXPAND_INITIALIZER : EXPAND_SUM));
10175 : 279721 : if (! CONSTANT_P (op0))
10176 : : {
10177 : 6 : op1 = expand_expr (treeop1, NULL_RTX,
10178 : : VOIDmode, modifier);
10179 : : /* Return a PLUS if modifier says it's OK. */
10180 : 6 : if (modifier == EXPAND_SUM
10181 : : || modifier == EXPAND_INITIALIZER)
10182 : 6 : return simplify_gen_binary (PLUS, mode, op0, op1);
10183 : 0 : goto binop2;
10184 : : }
10185 : : /* Use wi::shwi to ensure that the constant is
10186 : : truncated according to the mode of OP1, then sign extended
10187 : : to a HOST_WIDE_INT. Using the constant directly can result
10188 : : in non-canonical RTL in a 64x32 cross compile. */
10189 : 279715 : wc = TREE_INT_CST_LOW (treeop1);
10190 : 279715 : constant_part
10191 : 279715 : = immed_wide_int_const (wi::shwi (wc, wmode), wmode);
10192 : 279715 : op0 = plus_constant (mode, op0, INTVAL (constant_part));
10193 : 279715 : if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
10194 : 208273 : op0 = force_operand (op0, target);
10195 : 279715 : return REDUCE_BIT_FIELD (op0);
10196 : : }
10197 : : }
10198 : :
10199 : : /* Use TER to expand pointer addition of a negated value
10200 : : as pointer subtraction. */
10201 : 8834648 : if ((POINTER_TYPE_P (TREE_TYPE (treeop0))
10202 : 3853343 : || (TREE_CODE (TREE_TYPE (treeop0)) == VECTOR_TYPE
10203 : 79573 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0)))))
10204 : 1110739 : && TREE_CODE (treeop1) == SSA_NAME
10205 : 6109032 : && TYPE_MODE (TREE_TYPE (treeop0))
10206 : 572475 : == TYPE_MODE (TREE_TYPE (treeop1)))
10207 : : {
10208 : 572475 : gimple *def = get_def_for_expr (treeop1, NEGATE_EXPR);
10209 : 572475 : if (def)
10210 : : {
10211 : 2491 : treeop1 = gimple_assign_rhs1 (def);
10212 : 2491 : code = MINUS_EXPR;
10213 : 2491 : goto do_minus;
10214 : : }
10215 : : }
10216 : :
10217 : : /* No sense saving up arithmetic to be done
10218 : : if it's all in the wrong mode to form part of an address.
10219 : : And force_operand won't know whether to sign-extend or
10220 : : zero-extend. */
10221 : 4961591 : if (modifier != EXPAND_INITIALIZER
10222 : 4961591 : && (modifier != EXPAND_SUM || mode != ptr_mode))
10223 : : {
10224 : 4395528 : expand_operands (treeop0, treeop1,
10225 : : subtarget, &op0, &op1, modifier);
10226 : 4395528 : if (op0 == const0_rtx)
10227 : 8670 : return op1;
10228 : 4386858 : if (op1 == const0_rtx)
10229 : : return op0;
10230 : 4386606 : goto binop2;
10231 : : }
10232 : :
10233 : 566063 : expand_operands (treeop0, treeop1,
10234 : : subtarget, &op0, &op1, modifier);
10235 : 566063 : return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
10236 : :
10237 : 531253 : case MINUS_EXPR:
10238 : 531253 : case POINTER_DIFF_EXPR:
10239 : 531253 : do_minus:
10240 : : /* For initializers, we are allowed to return a MINUS of two
10241 : : symbolic constants. Here we handle all cases when both operands
10242 : : are constant. */
10243 : : /* Handle difference of two symbolic constants,
10244 : : for the sake of an initializer. */
10245 : 531253 : if ((modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
10246 : 3177 : && really_constant_p (treeop0)
10247 : 531753 : && really_constant_p (treeop1))
10248 : : {
10249 : 68 : expand_operands (treeop0, treeop1,
10250 : : NULL_RTX, &op0, &op1, modifier);
10251 : 68 : return simplify_gen_binary (MINUS, mode, op0, op1);
10252 : : }
10253 : :
10254 : : /* No sense saving up arithmetic to be done
10255 : : if it's all in the wrong mode to form part of an address.
10256 : : And force_operand won't know whether to sign-extend or
10257 : : zero-extend. */
10258 : 531185 : if (modifier != EXPAND_INITIALIZER
10259 : 531185 : && (modifier != EXPAND_SUM || mode != ptr_mode))
10260 : 528076 : goto binop;
10261 : :
10262 : 3109 : expand_operands (treeop0, treeop1,
10263 : : subtarget, &op0, &op1, modifier);
10264 : :
10265 : : /* Convert A - const to A + (-const). */
10266 : 3109 : if (CONST_INT_P (op1))
10267 : : {
10268 : 0 : op1 = negate_rtx (mode, op1);
10269 : 0 : return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
10270 : : }
10271 : :
10272 : 3109 : goto binop2;
10273 : :
10274 : 0 : case WIDEN_MULT_PLUS_EXPR:
10275 : 0 : case WIDEN_MULT_MINUS_EXPR:
10276 : 0 : expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
10277 : 0 : op2 = expand_normal (treeop2);
10278 : 0 : target = expand_widen_pattern_expr (ops, op0, op1, op2,
10279 : : target, unsignedp);
10280 : 0 : return target;
10281 : :
10282 : 18200 : case WIDEN_MULT_EXPR:
10283 : : /* If first operand is constant, swap them.
10284 : : Thus the following special case checks need only
10285 : : check the second operand. */
10286 : 18200 : if (TREE_CODE (treeop0) == INTEGER_CST)
10287 : 368 : std::swap (treeop0, treeop1);
10288 : :
10289 : : /* First, check if we have a multiplication of one signed and one
10290 : : unsigned operand. */
10291 : 18200 : if (TREE_CODE (treeop1) != INTEGER_CST
10292 : 18200 : && (TYPE_UNSIGNED (TREE_TYPE (treeop0))
10293 : 13760 : != TYPE_UNSIGNED (TREE_TYPE (treeop1))))
10294 : : {
10295 : 0 : machine_mode innermode = TYPE_MODE (TREE_TYPE (treeop0));
10296 : 0 : this_optab = usmul_widen_optab;
10297 : 0 : if (find_widening_optab_handler (this_optab, mode, innermode)
10298 : : != CODE_FOR_nothing)
10299 : : {
10300 : 0 : if (TYPE_UNSIGNED (TREE_TYPE (treeop0)))
10301 : 0 : expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
10302 : : EXPAND_NORMAL);
10303 : : else
10304 : 0 : expand_operands (treeop0, treeop1, NULL_RTX, &op1, &op0,
10305 : : EXPAND_NORMAL);
10306 : : /* op0 and op1 might still be constant, despite the above
10307 : : != INTEGER_CST check. Handle it. */
10308 : 0 : if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
10309 : : {
10310 : 0 : op0 = convert_modes (mode, innermode, op0, true);
10311 : 0 : op1 = convert_modes (mode, innermode, op1, false);
10312 : 0 : return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1,
10313 : : target, unsignedp));
10314 : : }
10315 : 0 : goto binop3;
10316 : : }
10317 : : }
10318 : : /* Check for a multiplication with matching signedness. */
10319 : 18200 : else if ((TREE_CODE (treeop1) == INTEGER_CST
10320 : 4440 : && int_fits_type_p (treeop1, TREE_TYPE (treeop0)))
10321 : 18204 : || (TYPE_UNSIGNED (TREE_TYPE (treeop1))
10322 : 13764 : == TYPE_UNSIGNED (TREE_TYPE (treeop0))))
10323 : : {
10324 : 18200 : tree op0type = TREE_TYPE (treeop0);
10325 : 18200 : machine_mode innermode = TYPE_MODE (op0type);
10326 : 18200 : bool zextend_p = TYPE_UNSIGNED (op0type);
10327 : 18200 : optab other_optab = zextend_p ? smul_widen_optab : umul_widen_optab;
10328 : 2549 : this_optab = zextend_p ? umul_widen_optab : smul_widen_optab;
10329 : :
10330 : 18200 : if (TREE_CODE (treeop0) != INTEGER_CST)
10331 : : {
10332 : 18200 : if (find_widening_optab_handler (this_optab, mode, innermode)
10333 : : != CODE_FOR_nothing)
10334 : : {
10335 : 18200 : expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
10336 : : EXPAND_NORMAL);
10337 : : /* op0 and op1 might still be constant, despite the above
10338 : : != INTEGER_CST check. Handle it. */
10339 : 18200 : if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
10340 : : {
10341 : 0 : widen_mult_const:
10342 : 0 : op0 = convert_modes (mode, innermode, op0, zextend_p);
10343 : 0 : op1
10344 : 0 : = convert_modes (mode, innermode, op1,
10345 : 0 : TYPE_UNSIGNED (TREE_TYPE (treeop1)));
10346 : 0 : return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1,
10347 : : target,
10348 : : unsignedp));
10349 : : }
10350 : 18200 : temp = expand_widening_mult (mode, op0, op1, target,
10351 : : unsignedp, this_optab);
10352 : 18200 : return REDUCE_BIT_FIELD (temp);
10353 : : }
10354 : 0 : if (find_widening_optab_handler (other_optab, mode, innermode)
10355 : : != CODE_FOR_nothing
10356 : 0 : && innermode == word_mode)
10357 : : {
10358 : 0 : rtx htem, hipart;
10359 : 0 : op0 = expand_normal (treeop0);
10360 : 0 : op1 = expand_normal (treeop1);
10361 : : /* op0 and op1 might be constants, despite the above
10362 : : != INTEGER_CST check. Handle it. */
10363 : 0 : if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
10364 : 0 : goto widen_mult_const;
10365 : 0 : temp = expand_binop (mode, other_optab, op0, op1, target,
10366 : : unsignedp, OPTAB_LIB_WIDEN);
10367 : 0 : hipart = gen_highpart (word_mode, temp);
10368 : 0 : htem = expand_mult_highpart_adjust (word_mode, hipart,
10369 : : op0, op1, hipart,
10370 : : zextend_p);
10371 : 0 : if (htem != hipart)
10372 : 0 : emit_move_insn (hipart, htem);
10373 : 0 : return REDUCE_BIT_FIELD (temp);
10374 : : }
10375 : : }
10376 : : }
10377 : 0 : treeop0 = fold_build1 (CONVERT_EXPR, type, treeop0);
10378 : 0 : treeop1 = fold_build1 (CONVERT_EXPR, type, treeop1);
10379 : 0 : expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
10380 : 0 : return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
10381 : :
10382 : 1365862 : case MULT_EXPR:
10383 : : /* If this is a fixed-point operation, then we cannot use the code
10384 : : below because "expand_mult" doesn't support sat/no-sat fixed-point
10385 : : multiplications. */
10386 : 1365862 : if (ALL_FIXED_POINT_MODE_P (mode))
10387 : 0 : goto binop;
10388 : :
10389 : : /* If first operand is constant, swap them.
10390 : : Thus the following special case checks need only
10391 : : check the second operand. */
10392 : 1365862 : if (TREE_CODE (treeop0) == INTEGER_CST)
10393 : 686 : std::swap (treeop0, treeop1);
10394 : :
10395 : : /* Attempt to return something suitable for generating an
10396 : : indexed address, for machines that support that. */
10397 : :
10398 : 527620 : if (modifier == EXPAND_SUM && mode == ptr_mode
10399 : 1893482 : && tree_fits_shwi_p (treeop1))
10400 : : {
10401 : 521217 : tree exp1 = treeop1;
10402 : :
10403 : 521217 : op0 = expand_expr (treeop0, subtarget, VOIDmode,
10404 : : EXPAND_SUM);
10405 : :
10406 : 521217 : if (!REG_P (op0))
10407 : 245551 : op0 = force_operand (op0, NULL_RTX);
10408 : 521217 : if (!REG_P (op0))
10409 : 2416 : op0 = copy_to_mode_reg (mode, op0);
10410 : :
10411 : 521217 : op1 = gen_int_mode (tree_to_shwi (exp1),
10412 : 521217 : TYPE_MODE (TREE_TYPE (exp1)));
10413 : 521217 : return REDUCE_BIT_FIELD (gen_rtx_MULT (mode, op0, op1));
10414 : : }
10415 : :
10416 : 844645 : if (modifier == EXPAND_STACK_PARM)
10417 : 2912 : target = 0;
10418 : :
10419 : 844645 : if (SCALAR_INT_MODE_P (mode) && optimize >= 2)
10420 : : {
10421 : 502576 : gimple *def_stmt0 = get_def_for_expr (treeop0, TRUNC_DIV_EXPR);
10422 : 502576 : gimple *def_stmt1 = get_def_for_expr (treeop1, TRUNC_DIV_EXPR);
10423 : 502576 : if (def_stmt0
10424 : 502576 : && !operand_equal_p (treeop1, gimple_assign_rhs2 (def_stmt0), 0))
10425 : : def_stmt0 = NULL;
10426 : 502576 : if (def_stmt1
10427 : 502576 : && !operand_equal_p (treeop0, gimple_assign_rhs2 (def_stmt1), 0))
10428 : : def_stmt1 = NULL;
10429 : :
10430 : 502576 : if (def_stmt0 || def_stmt1)
10431 : : {
10432 : : /* X / Y * Y can be expanded as X - X % Y too.
10433 : : Choose the cheaper sequence of those two. */
10434 : 235 : if (def_stmt0)
10435 : 235 : treeop0 = gimple_assign_rhs1 (def_stmt0);
10436 : : else
10437 : : {
10438 : 0 : treeop1 = treeop0;
10439 : 0 : treeop0 = gimple_assign_rhs1 (def_stmt1);
10440 : : }
10441 : 235 : expand_operands (treeop0, treeop1, subtarget, &op0, &op1,
10442 : : EXPAND_NORMAL);
10443 : 235 : bool speed_p = optimize_insn_for_speed_p ();
10444 : 235 : do_pending_stack_adjust ();
10445 : 235 : start_sequence ();
10446 : 235 : rtx divmul_ret
10447 : 235 : = expand_expr_divmod (TRUNC_DIV_EXPR, mode, treeop0, treeop1,
10448 : : op0, op1, NULL_RTX, unsignedp);
10449 : 235 : divmul_ret = expand_mult (mode, divmul_ret, op1, target,
10450 : : unsignedp);
10451 : 235 : rtx_insn *divmul_insns = end_sequence ();
10452 : 235 : start_sequence ();
10453 : 235 : rtx modsub_ret
10454 : 235 : = expand_expr_divmod (TRUNC_MOD_EXPR, mode, treeop0, treeop1,
10455 : : op0, op1, NULL_RTX, unsignedp);
10456 : 235 : this_optab = optab_for_tree_code (MINUS_EXPR, type,
10457 : : optab_default);
10458 : 235 : modsub_ret = expand_binop (mode, this_optab, op0, modsub_ret,
10459 : : target, unsignedp, OPTAB_LIB_WIDEN);
10460 : 235 : rtx_insn *modsub_insns = end_sequence ();
10461 : 235 : unsigned divmul_cost = seq_cost (divmul_insns, speed_p);
10462 : 235 : unsigned modsub_cost = seq_cost (modsub_insns, speed_p);
10463 : : /* If costs are the same then use as tie breaker the other other
10464 : : factor. */
10465 : 235 : if (divmul_cost == modsub_cost)
10466 : : {
10467 : 20 : divmul_cost = seq_cost (divmul_insns, !speed_p);
10468 : 20 : modsub_cost = seq_cost (modsub_insns, !speed_p);
10469 : : }
10470 : :
10471 : 235 : if (divmul_cost <= modsub_cost)
10472 : : {
10473 : 167 : emit_insn (divmul_insns);
10474 : 167 : return REDUCE_BIT_FIELD (divmul_ret);
10475 : : }
10476 : 68 : emit_insn (modsub_insns);
10477 : 68 : return REDUCE_BIT_FIELD (modsub_ret);
10478 : : }
10479 : : }
10480 : :
10481 : 844410 : expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
10482 : :
10483 : : /* Expand X*Y as X&-Y when Y must be zero or one. */
10484 : 844410 : if (SCALAR_INT_MODE_P (mode))
10485 : : {
10486 : 712687 : bool bit0_p = expr_has_boolean_range (treeop0, currently_expanding_gimple_stmt);
10487 : 712687 : bool bit1_p = expr_has_boolean_range (treeop1, currently_expanding_gimple_stmt);
10488 : :
10489 : : /* Expand X*Y as X&Y when both X and Y must be zero or one. */
10490 : 712687 : if (bit0_p && bit1_p)
10491 : 4 : return REDUCE_BIT_FIELD (expand_and (mode, op0, op1, target));
10492 : :
10493 : 712683 : if (bit0_p || bit1_p)
10494 : : {
10495 : 4719 : bool speed = optimize_insn_for_speed_p ();
10496 : 4719 : int cost = add_cost (speed, mode) + neg_cost (speed, mode);
10497 : 4719 : struct algorithm algorithm;
10498 : 4719 : enum mult_variant variant;
10499 : 4719 : if (CONST_INT_P (op1)
10500 : 4719 : ? !choose_mult_variant (mode, INTVAL (op1),
10501 : : &algorithm, &variant, cost)
10502 : 740 : : cost < mul_cost (speed, mode))
10503 : : {
10504 : 2125 : temp = bit0_p ? expand_and (mode, negate_rtx (mode, op0),
10505 : : op1, target)
10506 : 293 : : expand_and (mode, op0,
10507 : : negate_rtx (mode, op1),
10508 : : target);
10509 : 2125 : return REDUCE_BIT_FIELD (temp);
10510 : : }
10511 : : }
10512 : : }
10513 : :
10514 : 842281 : return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
10515 : :
10516 : 160109 : case TRUNC_MOD_EXPR:
10517 : 160109 : case FLOOR_MOD_EXPR:
10518 : 160109 : case CEIL_MOD_EXPR:
10519 : 160109 : case ROUND_MOD_EXPR:
10520 : :
10521 : 160109 : case TRUNC_DIV_EXPR:
10522 : 160109 : case FLOOR_DIV_EXPR:
10523 : 160109 : case CEIL_DIV_EXPR:
10524 : 160109 : case ROUND_DIV_EXPR:
10525 : 160109 : case EXACT_DIV_EXPR:
10526 : : /* If this is a fixed-point operation, then we cannot use the code
10527 : : below because "expand_divmod" doesn't support sat/no-sat fixed-point
10528 : : divisions. */
10529 : 160109 : if (ALL_FIXED_POINT_MODE_P (mode))
10530 : 0 : goto binop;
10531 : :
10532 : 160109 : if (modifier == EXPAND_STACK_PARM)
10533 : 318 : target = 0;
10534 : : /* Possible optimization: compute the dividend with EXPAND_SUM
10535 : : then if the divisor is constant can optimize the case
10536 : : where some terms of the dividend have coeffs divisible by it. */
10537 : 160109 : expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
10538 : 160109 : return expand_expr_divmod (code, mode, treeop0, treeop1, op0, op1,
10539 : 160109 : target, unsignedp);
10540 : :
10541 : 30934 : case RDIV_EXPR:
10542 : 30934 : goto binop;
10543 : :
10544 : 1665 : case MULT_HIGHPART_EXPR:
10545 : 1665 : expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
10546 : 1665 : temp = expand_mult_highpart (mode, op0, op1, target, unsignedp);
10547 : 1665 : gcc_assert (temp);
10548 : : return temp;
10549 : :
10550 : 0 : case FIXED_CONVERT_EXPR:
10551 : 0 : op0 = expand_normal (treeop0);
10552 : 0 : if (target == 0 || modifier == EXPAND_STACK_PARM)
10553 : 0 : target = gen_reg_rtx (mode);
10554 : :
10555 : 0 : if ((TREE_CODE (TREE_TYPE (treeop0)) == INTEGER_TYPE
10556 : 0 : && TYPE_UNSIGNED (TREE_TYPE (treeop0)))
10557 : 0 : || (TREE_CODE (type) == INTEGER_TYPE && TYPE_UNSIGNED (type)))
10558 : 0 : expand_fixed_convert (target, op0, 1, TYPE_SATURATING (type));
10559 : : else
10560 : 0 : expand_fixed_convert (target, op0, 0, TYPE_SATURATING (type));
10561 : : return target;
10562 : :
10563 : 47759 : case FIX_TRUNC_EXPR:
10564 : 47759 : op0 = expand_normal (treeop0);
10565 : 47759 : if (target == 0 || modifier == EXPAND_STACK_PARM)
10566 : 3135 : target = gen_reg_rtx (mode);
10567 : 47759 : expand_fix (target, op0, unsignedp);
10568 : 47759 : return target;
10569 : :
10570 : 133568 : case FLOAT_EXPR:
10571 : 133568 : op0 = expand_normal (treeop0);
10572 : 133568 : if (target == 0 || modifier == EXPAND_STACK_PARM)
10573 : 63048 : target = gen_reg_rtx (mode);
10574 : : /* expand_float can't figure out what to do if FROM has VOIDmode.
10575 : : So give it the correct mode. With -O, cse will optimize this. */
10576 : 133568 : if (GET_MODE (op0) == VOIDmode)
10577 : 108 : op0 = copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0)),
10578 : : op0);
10579 : 267136 : expand_float (target, op0,
10580 : 133568 : TYPE_UNSIGNED (TREE_TYPE (treeop0)));
10581 : 133568 : return target;
10582 : :
10583 : 50488 : case NEGATE_EXPR:
10584 : 50488 : op0 = expand_expr (treeop0, subtarget,
10585 : : VOIDmode, EXPAND_NORMAL);
10586 : 50488 : if (modifier == EXPAND_STACK_PARM)
10587 : 243 : target = 0;
10588 : 50488 : temp = expand_unop (mode,
10589 : : optab_for_tree_code (NEGATE_EXPR, type,
10590 : : optab_default),
10591 : : op0, target, 0);
10592 : 50488 : gcc_assert (temp);
10593 : 50488 : return REDUCE_BIT_FIELD (temp);
10594 : :
10595 : 25371 : case ABS_EXPR:
10596 : 25371 : case ABSU_EXPR:
10597 : 25371 : op0 = expand_expr (treeop0, subtarget,
10598 : : VOIDmode, EXPAND_NORMAL);
10599 : 25371 : if (modifier == EXPAND_STACK_PARM)
10600 : 66 : target = 0;
10601 : :
10602 : : /* ABS_EXPR is not valid for complex arguments. */
10603 : 25371 : gcc_assert (GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
10604 : : && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT);
10605 : :
10606 : : /* Unsigned abs is simply the operand. Testing here means we don't
10607 : : risk generating incorrect code below. */
10608 : 25371 : if (TYPE_UNSIGNED (TREE_TYPE (treeop0)))
10609 : : return op0;
10610 : :
10611 : 25371 : return expand_abs (mode, op0, target, unsignedp,
10612 : 50742 : safe_from_p (target, treeop0, 1));
10613 : :
10614 : 101904 : case MAX_EXPR:
10615 : 101904 : case MIN_EXPR:
10616 : 101904 : target = original_target;
10617 : 101904 : if (target == 0
10618 : 101904 : || modifier == EXPAND_STACK_PARM
10619 : 57073 : || (MEM_P (target) && MEM_VOLATILE_P (target))
10620 : 57073 : || GET_MODE (target) != mode
10621 : 158977 : || (REG_P (target)
10622 : 50462 : && REGNO (target) < FIRST_PSEUDO_REGISTER))
10623 : 44831 : target = gen_reg_rtx (mode);
10624 : 101904 : expand_operands (treeop0, treeop1,
10625 : : target, &op0, &op1, EXPAND_NORMAL);
10626 : :
10627 : : /* First try to do it with a special MIN or MAX instruction.
10628 : : If that does not win, use a conditional jump to select the proper
10629 : : value. */
10630 : 101904 : this_optab = optab_for_tree_code (code, type, optab_default);
10631 : 101904 : temp = expand_binop (mode, this_optab, op0, op1, target, unsignedp,
10632 : : OPTAB_WIDEN);
10633 : 101904 : if (temp != 0)
10634 : : return temp;
10635 : :
10636 : 122 : if (VECTOR_TYPE_P (type))
10637 : 0 : gcc_unreachable ();
10638 : :
10639 : : /* At this point, a MEM target is no longer useful; we will get better
10640 : : code without it. */
10641 : :
10642 : 122 : if (! REG_P (target))
10643 : 1 : target = gen_reg_rtx (mode);
10644 : :
10645 : : /* If op1 was placed in target, swap op0 and op1. */
10646 : 122 : if (target != op0 && target == op1)
10647 : 0 : std::swap (op0, op1);
10648 : :
10649 : : /* We generate better code and avoid problems with op1 mentioning
10650 : : target by forcing op1 into a pseudo if it isn't a constant. */
10651 : 122 : if (! CONSTANT_P (op1))
10652 : 42 : op1 = force_reg (mode, op1);
10653 : :
10654 : 122 : {
10655 : 122 : enum rtx_code comparison_code;
10656 : 122 : rtx cmpop1 = op1;
10657 : :
10658 : 122 : if (code == MAX_EXPR)
10659 : 62 : comparison_code = unsignedp ? GEU : GE;
10660 : : else
10661 : 60 : comparison_code = unsignedp ? LEU : LE;
10662 : :
10663 : : /* Canonicalize to comparisons against 0. */
10664 : 122 : if (op1 == const1_rtx)
10665 : : {
10666 : : /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
10667 : : or (a != 0 ? a : 1) for unsigned.
10668 : : For MIN we are safe converting (a <= 1 ? a : 1)
10669 : : into (a <= 0 ? a : 1) */
10670 : 0 : cmpop1 = const0_rtx;
10671 : 0 : if (code == MAX_EXPR)
10672 : 0 : comparison_code = unsignedp ? NE : GT;
10673 : : }
10674 : 122 : if (op1 == constm1_rtx && !unsignedp)
10675 : : {
10676 : : /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
10677 : : and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
10678 : 0 : cmpop1 = const0_rtx;
10679 : 0 : if (code == MIN_EXPR)
10680 : 0 : comparison_code = LT;
10681 : : }
10682 : :
10683 : : /* Use a conditional move if possible. */
10684 : 122 : if (can_conditionally_move_p (mode))
10685 : : {
10686 : 75 : rtx insn;
10687 : :
10688 : 75 : start_sequence ();
10689 : :
10690 : : /* Try to emit the conditional move. */
10691 : 75 : insn = emit_conditional_move (target,
10692 : : { comparison_code,
10693 : : op0, cmpop1, mode },
10694 : : op0, op1, mode,
10695 : : unsignedp);
10696 : :
10697 : : /* If we could do the conditional move, emit the sequence,
10698 : : and return. */
10699 : 75 : if (insn)
10700 : : {
10701 : 41 : rtx_insn *seq = end_sequence ();
10702 : 41 : emit_insn (seq);
10703 : 41 : return target;
10704 : : }
10705 : :
10706 : : /* Otherwise discard the sequence and fall back to code with
10707 : : branches. */
10708 : 34 : end_sequence ();
10709 : : }
10710 : :
10711 : 81 : if (target != op0)
10712 : 52 : emit_move_insn (target, op0);
10713 : :
10714 : 81 : lab = gen_label_rtx ();
10715 : 81 : do_compare_rtx_and_jump (target, cmpop1, comparison_code,
10716 : : unsignedp, mode, NULL_RTX, NULL, lab,
10717 : : profile_probability::uninitialized ());
10718 : : }
10719 : 81 : emit_move_insn (target, op1);
10720 : 81 : emit_label (lab);
10721 : 81 : return target;
10722 : :
10723 : 57508 : case BIT_NOT_EXPR:
10724 : 57508 : op0 = expand_expr (treeop0, subtarget,
10725 : : VOIDmode, EXPAND_NORMAL);
10726 : 57508 : if (modifier == EXPAND_STACK_PARM)
10727 : 87 : target = 0;
10728 : : /* In case we have to reduce the result to bitfield precision
10729 : : for unsigned bitfield expand this as XOR with a proper constant
10730 : : instead. */
10731 : 57508 : if (reduce_bit_field && TYPE_UNSIGNED (type))
10732 : : {
10733 : 20878 : int_mode = SCALAR_INT_TYPE_MODE (type);
10734 : 20878 : wide_int mask = wi::mask (TYPE_PRECISION (type),
10735 : 41756 : false, GET_MODE_PRECISION (int_mode));
10736 : :
10737 : 41756 : temp = expand_binop (int_mode, xor_optab, op0,
10738 : 41756 : immed_wide_int_const (mask, int_mode),
10739 : : target, 1, OPTAB_LIB_WIDEN);
10740 : 20878 : }
10741 : : else
10742 : 36630 : temp = expand_unop (mode, one_cmpl_optab, op0, target, 1);
10743 : 57508 : gcc_assert (temp);
10744 : : return temp;
10745 : :
10746 : : /* ??? Can optimize bitwise operations with one arg constant.
10747 : : Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
10748 : : and (a bitwise1 b) bitwise2 b (etc)
10749 : : but that is probably not worth while. */
10750 : :
10751 : 621374 : case BIT_AND_EXPR:
10752 : 621374 : case BIT_IOR_EXPR:
10753 : 621374 : case BIT_XOR_EXPR:
10754 : 621374 : goto binop;
10755 : :
10756 : 7828 : case LROTATE_EXPR:
10757 : 7828 : case RROTATE_EXPR:
10758 : 7828 : gcc_assert (VECTOR_MODE_P (TYPE_MODE (type))
10759 : : || type_has_mode_precision_p (type));
10760 : : /* fall through */
10761 : :
10762 : 289029 : case LSHIFT_EXPR:
10763 : 289029 : case RSHIFT_EXPR:
10764 : 289029 : {
10765 : : /* If this is a fixed-point operation, then we cannot use the code
10766 : : below because "expand_shift" doesn't support sat/no-sat fixed-point
10767 : : shifts. */
10768 : 289029 : if (ALL_FIXED_POINT_MODE_P (mode))
10769 : 0 : goto binop;
10770 : :
10771 : 289029 : if (! safe_from_p (subtarget, treeop1, 1))
10772 : 4714 : subtarget = 0;
10773 : 289029 : if (modifier == EXPAND_STACK_PARM)
10774 : 2569 : target = 0;
10775 : 289029 : op0 = expand_expr (treeop0, subtarget,
10776 : : VOIDmode, EXPAND_NORMAL);
10777 : :
10778 : : /* Left shift optimization when shifting across word_size boundary.
10779 : :
10780 : : If mode == GET_MODE_WIDER_MODE (word_mode), then normally
10781 : : there isn't native instruction to support this wide mode
10782 : : left shift. Given below scenario:
10783 : :
10784 : : Type A = (Type) B << C
10785 : :
10786 : : |< T >|
10787 : : | dest_high | dest_low |
10788 : :
10789 : : | word_size |
10790 : :
10791 : : If the shift amount C caused we shift B to across the word
10792 : : size boundary, i.e part of B shifted into high half of
10793 : : destination register, and part of B remains in the low
10794 : : half, then GCC will use the following left shift expand
10795 : : logic:
10796 : :
10797 : : 1. Initialize dest_low to B.
10798 : : 2. Initialize every bit of dest_high to the sign bit of B.
10799 : : 3. Logic left shift dest_low by C bit to finalize dest_low.
10800 : : The value of dest_low before this shift is kept in a temp D.
10801 : : 4. Logic left shift dest_high by C.
10802 : : 5. Logic right shift D by (word_size - C).
10803 : : 6. Or the result of 4 and 5 to finalize dest_high.
10804 : :
10805 : : While, by checking gimple statements, if operand B is
10806 : : coming from signed extension, then we can simplify above
10807 : : expand logic into:
10808 : :
10809 : : 1. dest_high = src_low >> (word_size - C).
10810 : : 2. dest_low = src_low << C.
10811 : :
10812 : : We can use one arithmetic right shift to finish all the
10813 : : purpose of steps 2, 4, 5, 6, thus we reduce the steps
10814 : : needed from 6 into 2.
10815 : :
10816 : : The case is similar for zero extension, except that we
10817 : : initialize dest_high to zero rather than copies of the sign
10818 : : bit from B. Furthermore, we need to use a logical right shift
10819 : : in this case.
10820 : :
10821 : : The choice of sign-extension versus zero-extension is
10822 : : determined entirely by whether or not B is signed and is
10823 : : independent of the current setting of unsignedp. */
10824 : :
10825 : 289029 : temp = NULL_RTX;
10826 : 289029 : if (code == LSHIFT_EXPR
10827 : 289029 : && target
10828 : 32604 : && REG_P (target)
10829 : 318791 : && GET_MODE_2XWIDER_MODE (word_mode).exists (&int_mode)
10830 : 29829 : && mode == int_mode
10831 : 1524 : && TREE_CONSTANT (treeop1)
10832 : 289873 : && TREE_CODE (treeop0) == SSA_NAME)
10833 : : {
10834 : 844 : gimple *def = SSA_NAME_DEF_STMT (treeop0);
10835 : 844 : if (is_gimple_assign (def)
10836 : 844 : && gimple_assign_rhs_code (def) == NOP_EXPR)
10837 : : {
10838 : 322 : scalar_int_mode rmode = SCALAR_INT_TYPE_MODE
10839 : : (TREE_TYPE (gimple_assign_rhs1 (def)));
10840 : :
10841 : 644 : if (GET_MODE_SIZE (rmode) < GET_MODE_SIZE (int_mode)
10842 : 598 : && TREE_INT_CST_LOW (treeop1) < GET_MODE_BITSIZE (word_mode)
10843 : 464 : && ((TREE_INT_CST_LOW (treeop1) + GET_MODE_BITSIZE (rmode))
10844 : 71 : >= GET_MODE_BITSIZE (word_mode)))
10845 : : {
10846 : 67 : rtx_insn *seq, *seq_old;
10847 : 67 : poly_uint64 high_off = subreg_highpart_offset (word_mode,
10848 : : int_mode);
10849 : 67 : bool extend_unsigned
10850 : 67 : = TYPE_UNSIGNED (TREE_TYPE (gimple_assign_rhs1 (def)));
10851 : 67 : rtx low = lowpart_subreg (word_mode, op0, int_mode);
10852 : 67 : rtx dest_low = lowpart_subreg (word_mode, target, int_mode);
10853 : 67 : rtx dest_high = simplify_gen_subreg (word_mode, target,
10854 : : int_mode, high_off);
10855 : 67 : HOST_WIDE_INT ramount = (BITS_PER_WORD
10856 : 67 : - TREE_INT_CST_LOW (treeop1));
10857 : 67 : tree rshift = build_int_cst (TREE_TYPE (treeop1), ramount);
10858 : :
10859 : 67 : start_sequence ();
10860 : : /* dest_high = src_low >> (word_size - C). */
10861 : 67 : temp = expand_variable_shift (RSHIFT_EXPR, word_mode, low,
10862 : : rshift, dest_high,
10863 : : extend_unsigned);
10864 : 67 : if (temp != dest_high)
10865 : 0 : emit_move_insn (dest_high, temp);
10866 : :
10867 : : /* dest_low = src_low << C. */
10868 : 67 : temp = expand_variable_shift (LSHIFT_EXPR, word_mode, low,
10869 : : treeop1, dest_low, unsignedp);
10870 : 67 : if (temp != dest_low)
10871 : 2 : emit_move_insn (dest_low, temp);
10872 : :
10873 : 67 : seq = end_sequence ();
10874 : 67 : temp = target ;
10875 : :
10876 : 67 : if (have_insn_for (ASHIFT, int_mode))
10877 : : {
10878 : 67 : bool speed_p = optimize_insn_for_speed_p ();
10879 : 67 : start_sequence ();
10880 : 67 : rtx ret_old = expand_variable_shift (code, int_mode,
10881 : : op0, treeop1,
10882 : : target,
10883 : : unsignedp);
10884 : :
10885 : 67 : seq_old = end_sequence ();
10886 : 134 : if (seq_cost (seq, speed_p)
10887 : 67 : >= seq_cost (seq_old, speed_p))
10888 : : {
10889 : 67 : seq = seq_old;
10890 : 67 : temp = ret_old;
10891 : : }
10892 : : }
10893 : 67 : emit_insn (seq);
10894 : : }
10895 : : }
10896 : : }
10897 : :
10898 : 67 : if (temp == NULL_RTX)
10899 : 288962 : temp = expand_variable_shift (code, mode, op0, treeop1, target,
10900 : : unsignedp);
10901 : 289029 : if (code == LSHIFT_EXPR)
10902 : 81853 : temp = REDUCE_BIT_FIELD (temp);
10903 : : return temp;
10904 : : }
10905 : :
10906 : : /* Could determine the answer when only additive constants differ. Also,
10907 : : the addition of one can be handled by changing the condition. */
10908 : 546390 : case LT_EXPR:
10909 : 546390 : case LE_EXPR:
10910 : 546390 : case GT_EXPR:
10911 : 546390 : case GE_EXPR:
10912 : 546390 : case EQ_EXPR:
10913 : 546390 : case NE_EXPR:
10914 : 546390 : case UNORDERED_EXPR:
10915 : 546390 : case ORDERED_EXPR:
10916 : 546390 : case UNLT_EXPR:
10917 : 546390 : case UNLE_EXPR:
10918 : 546390 : case UNGT_EXPR:
10919 : 546390 : case UNGE_EXPR:
10920 : 546390 : case UNEQ_EXPR:
10921 : 546390 : case LTGT_EXPR:
10922 : 546390 : {
10923 : 869457 : temp = do_store_flag (ops,
10924 : : modifier != EXPAND_STACK_PARM ? target : NULL_RTX,
10925 : : tmode != VOIDmode ? tmode : mode);
10926 : 546390 : if (temp)
10927 : : return temp;
10928 : :
10929 : : /* Use a compare and a jump for BLKmode comparisons, or for function
10930 : : type comparisons is have_canonicalize_funcptr_for_compare. */
10931 : :
10932 : 0 : if ((target == 0
10933 : 0 : || modifier == EXPAND_STACK_PARM
10934 : 0 : || ! safe_from_p (target, treeop0, 1)
10935 : 0 : || ! safe_from_p (target, treeop1, 1)
10936 : : /* Make sure we don't have a hard reg (such as function's return
10937 : : value) live across basic blocks, if not optimizing. */
10938 : 0 : || (!optimize && REG_P (target)
10939 : 0 : && REGNO (target) < FIRST_PSEUDO_REGISTER)))
10940 : 0 : target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
10941 : :
10942 : 0 : emit_move_insn (target, const0_rtx);
10943 : :
10944 : 0 : rtx_code_label *lab1 = gen_label_rtx ();
10945 : 0 : jumpifnot_1 (code, treeop0, treeop1, lab1,
10946 : : profile_probability::uninitialized ());
10947 : :
10948 : 0 : if (TYPE_PRECISION (type) == 1 && !TYPE_UNSIGNED (type))
10949 : 0 : emit_move_insn (target, constm1_rtx);
10950 : : else
10951 : 0 : emit_move_insn (target, const1_rtx);
10952 : :
10953 : 0 : emit_label (lab1);
10954 : 0 : return target;
10955 : : }
10956 : 54840 : case COMPLEX_EXPR:
10957 : : /* Get the rtx code of the operands. */
10958 : 54840 : op0 = expand_normal (treeop0);
10959 : 54840 : op1 = expand_normal (treeop1);
10960 : :
10961 : 54840 : if (!target)
10962 : 2693 : target = gen_reg_rtx (TYPE_MODE (type));
10963 : : else
10964 : : /* If target overlaps with op1, then either we need to force
10965 : : op1 into a pseudo (if target also overlaps with op0),
10966 : : or write the complex parts in reverse order. */
10967 : 52147 : switch (GET_CODE (target))
10968 : : {
10969 : 49417 : case CONCAT:
10970 : 49417 : if (reg_overlap_mentioned_p (XEXP (target, 0), op1))
10971 : : {
10972 : 0 : if (reg_overlap_mentioned_p (XEXP (target, 1), op0))
10973 : : {
10974 : 0 : complex_expr_force_op1:
10975 : 1718 : temp = gen_reg_rtx (GET_MODE_INNER (GET_MODE (target)));
10976 : 859 : emit_move_insn (temp, op1);
10977 : 859 : op1 = temp;
10978 : 859 : break;
10979 : : }
10980 : 0 : complex_expr_swap_order:
10981 : : /* Move the imaginary (op1) and real (op0) parts to their
10982 : : location. */
10983 : 1 : write_complex_part (target, op1, true, true);
10984 : 1 : write_complex_part (target, op0, false, false);
10985 : :
10986 : 1 : return target;
10987 : : }
10988 : : break;
10989 : 2730 : case MEM:
10990 : 5460 : temp = adjust_address_nv (target,
10991 : : GET_MODE_INNER (GET_MODE (target)), 0);
10992 : 2730 : if (reg_overlap_mentioned_p (temp, op1))
10993 : : {
10994 : 860 : scalar_mode imode = GET_MODE_INNER (GET_MODE (target));
10995 : 1720 : temp = adjust_address_nv (target, imode,
10996 : : GET_MODE_SIZE (imode));
10997 : 860 : if (reg_overlap_mentioned_p (temp, op0))
10998 : 859 : goto complex_expr_force_op1;
10999 : 1 : goto complex_expr_swap_order;
11000 : : }
11001 : : break;
11002 : 0 : default:
11003 : 0 : if (reg_overlap_mentioned_p (target, op1))
11004 : : {
11005 : 0 : if (reg_overlap_mentioned_p (target, op0))
11006 : 0 : goto complex_expr_force_op1;
11007 : 0 : goto complex_expr_swap_order;
11008 : : }
11009 : : break;
11010 : : }
11011 : :
11012 : : /* Move the real (op0) and imaginary (op1) parts to their location. */
11013 : 54839 : write_complex_part (target, op0, false, true);
11014 : 54839 : write_complex_part (target, op1, true, false);
11015 : :
11016 : 54839 : return target;
11017 : :
11018 : 0 : case WIDEN_SUM_EXPR:
11019 : 0 : {
11020 : 0 : tree oprnd0 = treeop0;
11021 : 0 : tree oprnd1 = treeop1;
11022 : :
11023 : 0 : expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
11024 : 0 : target = expand_widen_pattern_expr (ops, op0, NULL_RTX, op1,
11025 : : target, unsignedp);
11026 : 0 : return target;
11027 : : }
11028 : :
11029 : 17649 : case VEC_UNPACK_HI_EXPR:
11030 : 17649 : case VEC_UNPACK_LO_EXPR:
11031 : 17649 : case VEC_UNPACK_FIX_TRUNC_HI_EXPR:
11032 : 17649 : case VEC_UNPACK_FIX_TRUNC_LO_EXPR:
11033 : 17649 : {
11034 : 17649 : op0 = expand_normal (treeop0);
11035 : 17649 : temp = expand_widen_pattern_expr (ops, op0, NULL_RTX, NULL_RTX,
11036 : : target, unsignedp);
11037 : 17649 : gcc_assert (temp);
11038 : : return temp;
11039 : : }
11040 : :
11041 : 1780 : case VEC_UNPACK_FLOAT_HI_EXPR:
11042 : 1780 : case VEC_UNPACK_FLOAT_LO_EXPR:
11043 : 1780 : {
11044 : 1780 : op0 = expand_normal (treeop0);
11045 : : /* The signedness is determined from input operand. */
11046 : 1780 : temp = expand_widen_pattern_expr
11047 : 3560 : (ops, op0, NULL_RTX, NULL_RTX,
11048 : 1780 : target, TYPE_UNSIGNED (TREE_TYPE (treeop0)));
11049 : :
11050 : 1780 : gcc_assert (temp);
11051 : : return temp;
11052 : : }
11053 : :
11054 : 975 : case VEC_WIDEN_MULT_HI_EXPR:
11055 : 975 : case VEC_WIDEN_MULT_LO_EXPR:
11056 : 975 : case VEC_WIDEN_MULT_EVEN_EXPR:
11057 : 975 : case VEC_WIDEN_MULT_ODD_EXPR:
11058 : 975 : case VEC_WIDEN_LSHIFT_HI_EXPR:
11059 : 975 : case VEC_WIDEN_LSHIFT_LO_EXPR:
11060 : 975 : expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
11061 : 975 : target = expand_widen_pattern_expr (ops, op0, op1, NULL_RTX,
11062 : : target, unsignedp);
11063 : 975 : gcc_assert (target);
11064 : : return target;
11065 : :
11066 : 341 : case VEC_PACK_SAT_EXPR:
11067 : 341 : case VEC_PACK_FIX_TRUNC_EXPR:
11068 : 341 : mode = TYPE_MODE (TREE_TYPE (treeop0));
11069 : 341 : subtarget = NULL_RTX;
11070 : 341 : goto binop;
11071 : :
11072 : 10934 : case VEC_PACK_TRUNC_EXPR:
11073 : 10934 : if (VECTOR_BOOLEAN_TYPE_P (type)
11074 : 2525 : && VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (treeop0))
11075 : 2525 : && mode == TYPE_MODE (TREE_TYPE (treeop0))
11076 : 11640 : && SCALAR_INT_MODE_P (mode))
11077 : : {
11078 : 706 : class expand_operand eops[4];
11079 : 706 : machine_mode imode = TYPE_MODE (TREE_TYPE (treeop0));
11080 : 706 : expand_operands (treeop0, treeop1,
11081 : : subtarget, &op0, &op1, EXPAND_NORMAL);
11082 : 706 : this_optab = vec_pack_sbool_trunc_optab;
11083 : 706 : enum insn_code icode = optab_handler (this_optab, imode);
11084 : 706 : create_output_operand (&eops[0], target, mode);
11085 : 706 : create_convert_operand_from (&eops[1], op0, imode, false);
11086 : 706 : create_convert_operand_from (&eops[2], op1, imode, false);
11087 : 706 : temp = GEN_INT (TYPE_VECTOR_SUBPARTS (type).to_constant ());
11088 : 706 : create_input_operand (&eops[3], temp, imode);
11089 : 706 : expand_insn (icode, 4, eops);
11090 : 706 : return eops[0].value;
11091 : : }
11092 : 10228 : mode = TYPE_MODE (TREE_TYPE (treeop0));
11093 : 10228 : subtarget = NULL_RTX;
11094 : 10228 : goto binop;
11095 : :
11096 : 27 : case VEC_PACK_FLOAT_EXPR:
11097 : 27 : mode = TYPE_MODE (TREE_TYPE (treeop0));
11098 : 27 : expand_operands (treeop0, treeop1,
11099 : : subtarget, &op0, &op1, EXPAND_NORMAL);
11100 : 27 : this_optab = optab_for_tree_code (code, TREE_TYPE (treeop0),
11101 : : optab_default);
11102 : 81 : target = expand_binop (mode, this_optab, op0, op1, target,
11103 : 27 : TYPE_UNSIGNED (TREE_TYPE (treeop0)),
11104 : : OPTAB_LIB_WIDEN);
11105 : 27 : gcc_assert (target);
11106 : : return target;
11107 : :
11108 : 71700 : case VEC_PERM_EXPR:
11109 : 71700 : {
11110 : 71700 : expand_operands (treeop0, treeop1, target, &op0, &op1, EXPAND_NORMAL);
11111 : 71700 : vec_perm_builder sel;
11112 : 71700 : if (TREE_CODE (treeop2) == VECTOR_CST
11113 : 71700 : && tree_to_vec_perm_builder (&sel, treeop2))
11114 : : {
11115 : 71690 : machine_mode sel_mode = TYPE_MODE (TREE_TYPE (treeop2));
11116 : 71690 : temp = expand_vec_perm_const (mode, op0, op1, sel,
11117 : : sel_mode, target);
11118 : : }
11119 : : else
11120 : : {
11121 : 10 : op2 = expand_normal (treeop2);
11122 : 10 : temp = expand_vec_perm_var (mode, op0, op1, op2, target);
11123 : : }
11124 : 71700 : gcc_assert (temp);
11125 : 71700 : return temp;
11126 : 71700 : }
11127 : :
11128 : 401 : case DOT_PROD_EXPR:
11129 : 401 : {
11130 : 401 : tree oprnd0 = treeop0;
11131 : 401 : tree oprnd1 = treeop1;
11132 : 401 : tree oprnd2 = treeop2;
11133 : :
11134 : 401 : expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
11135 : 401 : op2 = expand_normal (oprnd2);
11136 : 401 : target = expand_widen_pattern_expr (ops, op0, op1, op2,
11137 : : target, unsignedp);
11138 : 401 : return target;
11139 : : }
11140 : :
11141 : 114 : case SAD_EXPR:
11142 : 114 : {
11143 : 114 : tree oprnd0 = treeop0;
11144 : 114 : tree oprnd1 = treeop1;
11145 : 114 : tree oprnd2 = treeop2;
11146 : :
11147 : 114 : expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
11148 : 114 : op2 = expand_normal (oprnd2);
11149 : 114 : target = expand_widen_pattern_expr (ops, op0, op1, op2,
11150 : : target, unsignedp);
11151 : 114 : return target;
11152 : : }
11153 : :
11154 : 0 : case REALIGN_LOAD_EXPR:
11155 : 0 : {
11156 : 0 : tree oprnd0 = treeop0;
11157 : 0 : tree oprnd1 = treeop1;
11158 : 0 : tree oprnd2 = treeop2;
11159 : :
11160 : 0 : this_optab = optab_for_tree_code (code, type, optab_default);
11161 : 0 : expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
11162 : 0 : op2 = expand_normal (oprnd2);
11163 : 0 : temp = expand_ternary_op (mode, this_optab, op0, op1, op2,
11164 : : target, unsignedp);
11165 : 0 : gcc_assert (temp);
11166 : : return temp;
11167 : : }
11168 : :
11169 : 17829 : case COND_EXPR:
11170 : 17829 : {
11171 : : /* A COND_EXPR with its type being VOID_TYPE represents a
11172 : : conditional jump and is handled in
11173 : : expand_gimple_cond_expr. */
11174 : 17829 : gcc_assert (!VOID_TYPE_P (type));
11175 : :
11176 : : /* Note that COND_EXPRs whose type is a structure or union
11177 : : are required to be constructed to contain assignments of
11178 : : a temporary variable, so that we can evaluate them here
11179 : : for side effect only. If type is void, we must do likewise. */
11180 : :
11181 : 17829 : gcc_assert (!TREE_ADDRESSABLE (type)
11182 : : && !ignore
11183 : : && TREE_TYPE (treeop1) != void_type_node
11184 : : && TREE_TYPE (treeop2) != void_type_node);
11185 : :
11186 : 17829 : temp = expand_cond_expr_using_cmove (treeop0, treeop1, treeop2);
11187 : 17829 : if (temp)
11188 : : return temp;
11189 : :
11190 : : /* If we are not to produce a result, we have no target. Otherwise,
11191 : : if a target was specified use it; it will not be used as an
11192 : : intermediate target unless it is safe. If no target, use a
11193 : : temporary. */
11194 : :
11195 : 3765 : if (modifier != EXPAND_STACK_PARM
11196 : 3765 : && original_target
11197 : 2166 : && safe_from_p (original_target, treeop0, 1)
11198 : 0 : && GET_MODE (original_target) == mode
11199 : 3765 : && !MEM_P (original_target))
11200 : : temp = original_target;
11201 : : else
11202 : 3765 : temp = assign_temp (type, 0, 1);
11203 : :
11204 : 3765 : do_pending_stack_adjust ();
11205 : 3765 : NO_DEFER_POP;
11206 : 3765 : rtx_code_label *lab0 = gen_label_rtx ();
11207 : 3765 : rtx_code_label *lab1 = gen_label_rtx ();
11208 : 3765 : jumpifnot (treeop0, lab0,
11209 : : profile_probability::uninitialized ());
11210 : 3765 : store_expr (treeop1, temp,
11211 : : modifier == EXPAND_STACK_PARM,
11212 : : false, false);
11213 : :
11214 : 3765 : emit_jump_insn (targetm.gen_jump (lab1));
11215 : 3765 : emit_barrier ();
11216 : 3765 : emit_label (lab0);
11217 : 3765 : store_expr (treeop2, temp,
11218 : : modifier == EXPAND_STACK_PARM,
11219 : : false, false);
11220 : :
11221 : 3765 : emit_label (lab1);
11222 : 3765 : OK_DEFER_POP;
11223 : 3765 : return temp;
11224 : : }
11225 : :
11226 : 0 : case VEC_DUPLICATE_EXPR:
11227 : 0 : op0 = expand_expr (treeop0, NULL_RTX, VOIDmode, modifier);
11228 : 0 : target = expand_vector_broadcast (mode, op0);
11229 : 0 : gcc_assert (target);
11230 : : return target;
11231 : :
11232 : 0 : case VEC_SERIES_EXPR:
11233 : 0 : expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, modifier);
11234 : 0 : return expand_vec_series_expr (mode, op0, op1, target);
11235 : :
11236 : 941 : case BIT_INSERT_EXPR:
11237 : 941 : {
11238 : 941 : unsigned bitpos = tree_to_uhwi (treeop2);
11239 : 941 : unsigned bitsize;
11240 : 941 : if (INTEGRAL_TYPE_P (TREE_TYPE (treeop1)))
11241 : 600 : bitsize = TYPE_PRECISION (TREE_TYPE (treeop1));
11242 : : else
11243 : 341 : bitsize = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (treeop1)));
11244 : 941 : op0 = expand_normal (treeop0);
11245 : 941 : op1 = expand_normal (treeop1);
11246 : 941 : rtx dst = gen_reg_rtx (mode);
11247 : 941 : emit_move_insn (dst, op0);
11248 : 941 : store_bit_field (dst, bitsize, bitpos, 0, 0,
11249 : 941 : TYPE_MODE (TREE_TYPE (treeop1)), op1, false, false);
11250 : 941 : return dst;
11251 : : }
11252 : :
11253 : 0 : default:
11254 : 0 : gcc_unreachable ();
11255 : : }
11256 : :
11257 : : /* Here to do an ordinary binary operator. */
11258 : 1190953 : binop:
11259 : 1190953 : expand_operands (treeop0, treeop1,
11260 : : subtarget, &op0, &op1, EXPAND_NORMAL);
11261 : 5580668 : binop2:
11262 : 5580668 : this_optab = optab_for_tree_code (code, type, optab_default);
11263 : 5580668 : binop3:
11264 : 5580668 : if (modifier == EXPAND_STACK_PARM)
11265 : 26629 : target = 0;
11266 : 5580668 : temp = expand_binop (mode, this_optab, op0, op1, target,
11267 : : unsignedp, OPTAB_LIB_WIDEN);
11268 : 5580668 : gcc_assert (temp);
11269 : : /* Bitwise operations do not need bitfield reduction as we expect their
11270 : : operands being properly truncated. */
11271 : 5580668 : if (code == BIT_XOR_EXPR
11272 : : || code == BIT_AND_EXPR
11273 : 5580668 : || code == BIT_IOR_EXPR)
11274 : : return temp;
11275 : 4959294 : return REDUCE_BIT_FIELD (temp);
11276 : : }
11277 : : #undef REDUCE_BIT_FIELD
11278 : :
11279 : :
11280 : : /* Return TRUE if expression STMT is suitable for replacement.
11281 : : Never consider memory loads as replaceable, because those don't ever lead
11282 : : into constant expressions. */
11283 : :
11284 : : static bool
11285 : 8 : stmt_is_replaceable_p (gimple *stmt)
11286 : : {
11287 : 8 : if (ssa_is_replaceable_p (stmt))
11288 : : {
11289 : : /* Don't move around loads. */
11290 : 7 : if (!gimple_assign_single_p (stmt)
11291 : 7 : || is_gimple_val (gimple_assign_rhs1 (stmt)))
11292 : 6 : return true;
11293 : : }
11294 : : return false;
11295 : : }
11296 : :
11297 : : /* A subroutine of expand_expr_real_1. Expand gimple assignment G,
11298 : : which is known to set an SSA_NAME result. The other arguments are
11299 : : as for expand_expr_real_1. */
11300 : :
11301 : : rtx
11302 : 14653838 : expand_expr_real_gassign (gassign *g, rtx target, machine_mode tmode,
11303 : : enum expand_modifier modifier, rtx *alt_rtl,
11304 : : bool inner_reference_p)
11305 : : {
11306 : 14653838 : separate_ops ops;
11307 : 14653838 : rtx r;
11308 : 14653838 : location_t saved_loc = curr_insn_location ();
11309 : 14653838 : auto loc = gimple_location (g);
11310 : 14653838 : if (loc != UNKNOWN_LOCATION)
11311 : 11765936 : set_curr_insn_location (loc);
11312 : 14653838 : tree lhs = gimple_assign_lhs (g);
11313 : 14653838 : ops.code = gimple_assign_rhs_code (g);
11314 : 14653838 : ops.type = TREE_TYPE (lhs);
11315 : 14653838 : switch (get_gimple_rhs_class (ops.code))
11316 : : {
11317 : 90786 : case GIMPLE_TERNARY_RHS:
11318 : 181572 : ops.op2 = gimple_assign_rhs3 (g);
11319 : : /* Fallthru */
11320 : 7791882 : case GIMPLE_BINARY_RHS:
11321 : 7791882 : ops.op1 = gimple_assign_rhs2 (g);
11322 : :
11323 : : /* Try to expand conditonal compare. */
11324 : 7791882 : if (targetm.have_ccmp ())
11325 : : {
11326 : 1106 : gcc_checking_assert (targetm.gen_ccmp_next != NULL);
11327 : 1106 : r = expand_ccmp_expr (g, TYPE_MODE (ops.type));
11328 : 1106 : if (r)
11329 : : break;
11330 : : }
11331 : : /* Fallthru */
11332 : 11212690 : case GIMPLE_UNARY_RHS:
11333 : 11212690 : ops.op0 = gimple_assign_rhs1 (g);
11334 : 11212690 : ops.location = loc;
11335 : 11212690 : r = expand_expr_real_2 (&ops, target, tmode, modifier);
11336 : 11212690 : break;
11337 : 3441130 : case GIMPLE_SINGLE_RHS:
11338 : 3441130 : {
11339 : 3441130 : r = expand_expr_real (gimple_assign_rhs1 (g), target,
11340 : : tmode, modifier, alt_rtl,
11341 : : inner_reference_p);
11342 : 3441130 : break;
11343 : : }
11344 : 0 : default:
11345 : 0 : gcc_unreachable ();
11346 : : }
11347 : 14653838 : set_curr_insn_location (saved_loc);
11348 : 14653838 : if (REG_P (r) && !REG_EXPR (r))
11349 : 3655541 : set_reg_attrs_for_decl_rtl (lhs, r);
11350 : 14653838 : return r;
11351 : : }
11352 : :
11353 : : rtx
11354 : 155663301 : expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
11355 : : enum expand_modifier modifier, rtx *alt_rtl,
11356 : : bool inner_reference_p)
11357 : : {
11358 : 155663301 : rtx op0, op1, temp, decl_rtl;
11359 : 155663301 : tree type;
11360 : 155663301 : int unsignedp;
11361 : 155663301 : machine_mode mode, dmode;
11362 : 155663301 : enum tree_code code = TREE_CODE (exp);
11363 : 155663301 : rtx subtarget, original_target;
11364 : 155663301 : int ignore;
11365 : 155663301 : bool reduce_bit_field;
11366 : 155663301 : location_t loc = EXPR_LOCATION (exp);
11367 : 155663301 : struct separate_ops ops;
11368 : 155663301 : tree treeop0, treeop1, treeop2;
11369 : 155663301 : tree ssa_name = NULL_TREE;
11370 : 155663301 : gimple *g;
11371 : :
11372 : : /* Some ABIs define padding bits in _BitInt uninitialized. Normally, RTL
11373 : : expansion sign/zero extends integral types with less than mode precision
11374 : : when reading from bit-fields and after arithmetic operations (see
11375 : : REDUCE_BIT_FIELD in expand_expr_real_2) and on subsequent loads relies
11376 : : on those extensions to have been already performed, but because of the
11377 : : above for _BitInt they need to be sign/zero extended when reading from
11378 : : locations that could be exposed to ABI boundaries (when loading from
11379 : : objects in memory, or function arguments, return value). Because we
11380 : : internally extend after arithmetic operations, we can avoid doing that
11381 : : when reading from SSA_NAMEs of vars. */
11382 : : #define EXTEND_BITINT(expr) \
11383 : : ((TREE_CODE (type) == BITINT_TYPE \
11384 : : && !bitint_extended \
11385 : : && reduce_bit_field \
11386 : : && mode != BLKmode \
11387 : : && modifier != EXPAND_MEMORY \
11388 : : && modifier != EXPAND_WRITE \
11389 : : && modifier != EXPAND_INITIALIZER \
11390 : : && modifier != EXPAND_CONST_ADDRESS) \
11391 : : ? reduce_to_bit_field_precision ((expr), NULL_RTX, type) : (expr))
11392 : :
11393 : 155663301 : type = TREE_TYPE (exp);
11394 : 155663301 : mode = TYPE_MODE (type);
11395 : 155663301 : unsignedp = TYPE_UNSIGNED (type);
11396 : 155663301 : if (TREE_CODE (type) == BITINT_TYPE && bitint_extended == -1)
11397 : : {
11398 : 8556 : struct bitint_info info;
11399 : 8556 : bool ok = targetm.c.bitint_type_info (TYPE_PRECISION (type), &info);
11400 : 8556 : gcc_assert (ok);
11401 : 8556 : bitint_extended = info.extended;
11402 : : }
11403 : :
11404 : 155663301 : treeop0 = treeop1 = treeop2 = NULL_TREE;
11405 : 155663301 : if (!VL_EXP_CLASS_P (exp))
11406 : 149024883 : switch (TREE_CODE_LENGTH (code))
11407 : : {
11408 : 5584483 : default:
11409 : 5584483 : case 3: treeop2 = TREE_OPERAND (exp, 2); /* FALLTHRU */
11410 : 13492314 : case 2: treeop1 = TREE_OPERAND (exp, 1); /* FALLTHRU */
11411 : 27787432 : case 1: treeop0 = TREE_OPERAND (exp, 0); /* FALLTHRU */
11412 : : case 0: break;
11413 : : }
11414 : 155663301 : ops.code = code;
11415 : 155663301 : ops.type = type;
11416 : 155663301 : ops.op0 = treeop0;
11417 : 155663301 : ops.op1 = treeop1;
11418 : 155663301 : ops.op2 = treeop2;
11419 : 155663301 : ops.location = loc;
11420 : :
11421 : 311326602 : ignore = (target == const0_rtx
11422 : 155663301 : || ((CONVERT_EXPR_CODE_P (code)
11423 : 150688627 : || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
11424 : 940136 : && TREE_CODE (type) == VOID_TYPE));
11425 : :
11426 : : /* An operation in what may be a bit-field type needs the
11427 : : result to be reduced to the precision of the bit-field type,
11428 : : which is narrower than that of the type's mode. */
11429 : 311326379 : reduce_bit_field = (!ignore
11430 : 151291319 : && INTEGRAL_TYPE_P (type)
11431 : 79232078 : && !type_has_mode_precision_p (type));
11432 : :
11433 : : /* If we are going to ignore this result, we need only do something
11434 : : if there is a side-effect somewhere in the expression. If there
11435 : : is, short-circuit the most common cases here. Note that we must
11436 : : not call expand_expr with anything but const0_rtx in case this
11437 : : is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
11438 : :
11439 : 4371982 : if (ignore)
11440 : : {
11441 : 4371982 : if (! TREE_SIDE_EFFECTS (exp))
11442 : : return const0_rtx;
11443 : :
11444 : : /* Ensure we reference a volatile object even if value is ignored, but
11445 : : don't do this if all we are doing is taking its address. */
11446 : 4371759 : if (TREE_THIS_VOLATILE (exp)
11447 : 0 : && TREE_CODE (exp) != FUNCTION_DECL
11448 : 0 : && mode != VOIDmode && mode != BLKmode
11449 : 0 : && modifier != EXPAND_CONST_ADDRESS)
11450 : : {
11451 : 0 : temp = expand_expr (exp, NULL_RTX, VOIDmode, modifier);
11452 : 0 : if (MEM_P (temp))
11453 : 0 : copy_to_reg (temp);
11454 : 0 : return const0_rtx;
11455 : : }
11456 : :
11457 : 4371759 : if (TREE_CODE_CLASS (code) == tcc_unary
11458 : : || code == BIT_FIELD_REF
11459 : 4371759 : || code == COMPONENT_REF
11460 : 4371759 : || code == INDIRECT_REF)
11461 : 0 : return expand_expr (treeop0, const0_rtx, VOIDmode,
11462 : 0 : modifier);
11463 : :
11464 : 4371759 : else if (TREE_CODE_CLASS (code) == tcc_binary
11465 : 4371759 : || TREE_CODE_CLASS (code) == tcc_comparison
11466 : 4371759 : || code == ARRAY_REF || code == ARRAY_RANGE_REF)
11467 : : {
11468 : 0 : expand_expr (treeop0, const0_rtx, VOIDmode, modifier);
11469 : 0 : expand_expr (treeop1, const0_rtx, VOIDmode, modifier);
11470 : 0 : return const0_rtx;
11471 : : }
11472 : :
11473 : : target = 0;
11474 : : }
11475 : :
11476 : 155663078 : if (reduce_bit_field && modifier == EXPAND_STACK_PARM)
11477 : 37736 : target = 0;
11478 : :
11479 : : /* Use subtarget as the target for operand 0 of a binary operation. */
11480 : 155663078 : subtarget = get_subtarget (target);
11481 : 155663078 : original_target = target;
11482 : :
11483 : 155663078 : switch (code)
11484 : : {
11485 : 10818 : case LABEL_DECL:
11486 : 10818 : {
11487 : 10818 : tree function = decl_function_context (exp);
11488 : :
11489 : 10818 : temp = label_rtx (exp);
11490 : 14762 : temp = gen_rtx_LABEL_REF (Pmode, temp);
11491 : :
11492 : 10818 : if (function != current_function_decl
11493 : 1270 : && function != 0)
11494 : 1270 : LABEL_REF_NONLOCAL_P (temp) = 1;
11495 : :
11496 : 10818 : temp = gen_rtx_MEM (FUNCTION_MODE, temp);
11497 : 10818 : return temp;
11498 : : }
11499 : :
11500 : 55821493 : case SSA_NAME:
11501 : : /* ??? ivopts calls expander, without any preparation from
11502 : : out-of-ssa. So fake instructions as if this was an access to the
11503 : : base variable. This unnecessarily allocates a pseudo, see how we can
11504 : : reuse it, if partition base vars have it set already. */
11505 : 55821493 : if (!currently_expanding_to_rtl)
11506 : : {
11507 : 0 : tree var = SSA_NAME_VAR (exp);
11508 : 0 : if (var && DECL_RTL_SET_P (var))
11509 : 0 : return DECL_RTL (var);
11510 : 0 : return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp)),
11511 : 0 : LAST_VIRTUAL_REGISTER + 1);
11512 : : }
11513 : :
11514 : 55821493 : g = get_gimple_for_ssa_name (exp);
11515 : : /* For EXPAND_INITIALIZER try harder to get something simpler. */
11516 : 55821493 : if (g == NULL
11517 : 55821493 : && modifier == EXPAND_INITIALIZER
11518 : 26 : && !SSA_NAME_IS_DEFAULT_DEF (exp)
11519 : 11 : && (optimize || !SSA_NAME_VAR (exp)
11520 : 1 : || DECL_IGNORED_P (SSA_NAME_VAR (exp)))
11521 : 10 : && is_gimple_assign (SSA_NAME_DEF_STMT (exp))
11522 : 55821501 : && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp)))
11523 : 6 : g = SSA_NAME_DEF_STMT (exp);
11524 : 55821493 : if (safe_is_a <gassign *> (g))
11525 : 8772328 : return expand_expr_real_gassign (as_a<gassign *> (g), target, tmode,
11526 : 8772328 : modifier, alt_rtl, inner_reference_p);
11527 : 47049165 : else if (safe_is_a <gcall *> (g))
11528 : : {
11529 : : /* ??? internal call expansion doesn't follow the usual API
11530 : : of returning the destination RTX and being passed a desired
11531 : : target. */
11532 : 73048 : if (modifier == EXPAND_WRITE)
11533 : 36528 : return DECL_RTL (SSA_NAME_VAR (exp));
11534 : 36520 : rtx dest = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
11535 : 36520 : tree tmplhs = make_tree (TREE_TYPE (exp), dest);
11536 : 36520 : tree var_or_id = SSA_NAME_VAR (exp);
11537 : : if (!var_or_id)
11538 : 26669 : var_or_id = SSA_NAME_IDENTIFIER (exp);
11539 : 36520 : SET_SSA_NAME_VAR_OR_IDENTIFIER (exp, tmplhs);
11540 : 36520 : expand_internal_call (as_a <gcall *> (g));
11541 : 36520 : SET_SSA_NAME_VAR_OR_IDENTIFIER (exp, var_or_id);
11542 : 36520 : return dest;
11543 : : }
11544 : :
11545 : 46976117 : ssa_name = exp;
11546 : 46976117 : decl_rtl = get_rtx_for_ssa_name (ssa_name);
11547 : 46976117 : exp = SSA_NAME_VAR (ssa_name);
11548 : : /* Optimize and avoid to EXTEND_BITINIT doing anything if it is an
11549 : : SSA_NAME computed within the current function. In such case the
11550 : : value have been already extended before. While if it is a function
11551 : : parameter, result or some memory location, we need to be prepared
11552 : : for some other compiler leaving the bits uninitialized. */
11553 : 18558404 : if (!exp || VAR_P (exp))
11554 : : reduce_bit_field = false;
11555 : 46976117 : goto expand_decl_rtl;
11556 : :
11557 : 19672583 : case VAR_DECL:
11558 : : /* Allow accel compiler to handle variables that require special
11559 : : treatment, e.g. if they have been modified in some way earlier in
11560 : : compilation by the adjust_private_decl OpenACC hook. */
11561 : 19672583 : if (flag_openacc && targetm.goacc.expand_var_decl)
11562 : : {
11563 : 0 : temp = targetm.goacc.expand_var_decl (exp);
11564 : 0 : if (temp)
11565 : : return temp;
11566 : : }
11567 : : /* Expand const VAR_DECLs with CONSTRUCTOR initializers that
11568 : : have scalar integer modes to a reg via store_constructor. */
11569 : 19672583 : if (TREE_READONLY (exp)
11570 : 3367871 : && !TREE_SIDE_EFFECTS (exp)
11571 : 3345455 : && (modifier == EXPAND_NORMAL || modifier == EXPAND_STACK_PARM)
11572 : 17214 : && immediate_const_ctor_p (DECL_INITIAL (exp))
11573 : 156 : && SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (exp)))
11574 : 124 : && crtl->emit.regno_pointer_align_length
11575 : 19672707 : && !target)
11576 : : {
11577 : 85 : target = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
11578 : 85 : store_constructor (DECL_INITIAL (exp), target, 0,
11579 : 85 : int_expr_size (DECL_INITIAL (exp)), false);
11580 : 85 : return target;
11581 : : }
11582 : : /* ... fall through ... */
11583 : :
11584 : 20214170 : case PARM_DECL:
11585 : : /* If a static var's type was incomplete when the decl was written,
11586 : : but the type is complete now, lay out the decl now. */
11587 : 20214170 : if (DECL_SIZE (exp) == 0
11588 : 44815 : && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp))
11589 : 20258873 : && (TREE_STATIC (exp) || DECL_EXTERNAL (exp)))
11590 : 44703 : layout_decl (exp, 0);
11591 : :
11592 : : /* fall through */
11593 : :
11594 : 21665938 : case FUNCTION_DECL:
11595 : 21665938 : case RESULT_DECL:
11596 : 21665938 : decl_rtl = DECL_RTL (exp);
11597 : 68642055 : expand_decl_rtl:
11598 : 68642055 : gcc_assert (decl_rtl);
11599 : :
11600 : : /* DECL_MODE might change when TYPE_MODE depends on attribute target
11601 : : settings for VECTOR_TYPE_P that might switch for the function. */
11602 : 68642055 : if (currently_expanding_to_rtl
11603 : 64980745 : && code == VAR_DECL && MEM_P (decl_rtl)
11604 : 83309329 : && VECTOR_TYPE_P (type) && exp && DECL_MODE (exp) != mode)
11605 : 57 : decl_rtl = change_address (decl_rtl, TYPE_MODE (type), 0);
11606 : : else
11607 : 68641998 : decl_rtl = copy_rtx (decl_rtl);
11608 : :
11609 : : /* Record writes to register variables. */
11610 : 68642055 : if (modifier == EXPAND_WRITE
11611 : 21651512 : && REG_P (decl_rtl)
11612 : 84450311 : && HARD_REGISTER_P (decl_rtl))
11613 : 2026 : add_to_hard_reg_set (&crtl->asm_clobbers,
11614 : 2026 : GET_MODE (decl_rtl), REGNO (decl_rtl));
11615 : :
11616 : : /* Ensure variable marked as used even if it doesn't go through
11617 : : a parser. If it hasn't be used yet, write out an external
11618 : : definition. */
11619 : 68642055 : if (exp)
11620 : 40224342 : TREE_USED (exp) = 1;
11621 : :
11622 : : /* Show we haven't gotten RTL for this yet. */
11623 : 108866397 : temp = 0;
11624 : :
11625 : : /* Variables inherited from containing functions should have
11626 : : been lowered by this point. */
11627 : 40224342 : if (exp)
11628 : : {
11629 : 40224342 : tree context = decl_function_context (exp);
11630 : 40224342 : gcc_assert (SCOPE_FILE_SCOPE_P (context)
11631 : : || context == current_function_decl
11632 : : || TREE_STATIC (exp)
11633 : : || DECL_EXTERNAL (exp)
11634 : : /* ??? C++ creates functions that are not
11635 : : TREE_STATIC. */
11636 : : || TREE_CODE (exp) == FUNCTION_DECL);
11637 : : }
11638 : :
11639 : : /* This is the case of an array whose size is to be determined
11640 : : from its initializer, while the initializer is still being parsed.
11641 : : ??? We aren't parsing while expanding anymore. */
11642 : :
11643 : 68642055 : if (MEM_P (decl_rtl) && REG_P (XEXP (decl_rtl, 0)))
11644 : 390446 : temp = validize_mem (decl_rtl);
11645 : :
11646 : : /* If DECL_RTL is memory, we are in the normal case and the
11647 : : address is not valid, get the address into a register. */
11648 : :
11649 : 68251609 : else if (MEM_P (decl_rtl) && modifier != EXPAND_INITIALIZER)
11650 : : {
11651 : 18612266 : if (alt_rtl)
11652 : 2030845 : *alt_rtl = decl_rtl;
11653 : 18612266 : decl_rtl = use_anchored_address (decl_rtl);
11654 : 18612266 : if (modifier != EXPAND_CONST_ADDRESS
11655 : 18612266 : && modifier != EXPAND_SUM
11656 : 30878661 : && !memory_address_addr_space_p (exp ? DECL_MODE (exp)
11657 : 17148 : : GET_MODE (decl_rtl),
11658 : : XEXP (decl_rtl, 0),
11659 : 12266395 : MEM_ADDR_SPACE (decl_rtl)))
11660 : 136034 : temp = replace_equiv_address (decl_rtl,
11661 : : copy_rtx (XEXP (decl_rtl, 0)));
11662 : : }
11663 : :
11664 : : /* If we got something, return it. But first, set the alignment
11665 : : if the address is a register. */
11666 : 19002712 : if (temp != 0)
11667 : : {
11668 : 526480 : if (exp && MEM_P (temp) && REG_P (XEXP (temp, 0)))
11669 : 494703 : mark_reg_pointer (XEXP (temp, 0), DECL_ALIGN (exp));
11670 : : }
11671 : 68115575 : else if (MEM_P (decl_rtl))
11672 : : temp = decl_rtl;
11673 : :
11674 : 46634706 : if (temp != 0)
11675 : : {
11676 : 22502062 : if (MEM_P (temp)
11677 : : && modifier != EXPAND_WRITE
11678 : 22502062 : && modifier != EXPAND_MEMORY
11679 : : && modifier != EXPAND_INITIALIZER
11680 : 16568666 : && modifier != EXPAND_CONST_ADDRESS
11681 : 6878076 : && modifier != EXPAND_SUM
11682 : 6878076 : && !inner_reference_p
11683 : 4474031 : && mode != BLKmode
11684 : 26608563 : && MEM_ALIGN (temp) < GET_MODE_ALIGNMENT (mode))
11685 : 19821 : temp = expand_misaligned_mem_ref (temp, mode, unsignedp,
11686 : 19821 : MEM_ALIGN (temp), NULL_RTX, NULL);
11687 : :
11688 : 22502062 : return EXTEND_BITINT (temp);
11689 : : }
11690 : :
11691 : 46139993 : if (exp)
11692 : 17739438 : dmode = DECL_MODE (exp);
11693 : : else
11694 : 28400555 : dmode = TYPE_MODE (TREE_TYPE (ssa_name));
11695 : :
11696 : : /* If the mode of DECL_RTL does not match that of the decl,
11697 : : there are two cases: we are dealing with a BLKmode value
11698 : : that is returned in a register, or we are dealing with
11699 : : a promoted value. In the latter case, return a SUBREG
11700 : : of the wanted mode, but mark it so that we know that it
11701 : : was already extended. */
11702 : 46139993 : if (REG_P (decl_rtl)
11703 : 45657567 : && dmode != BLKmode
11704 : 45657567 : && GET_MODE (decl_rtl) != dmode)
11705 : : {
11706 : 82 : machine_mode pmode;
11707 : :
11708 : : /* Get the signedness to be used for this variable. Ensure we get
11709 : : the same mode we got when the variable was declared. */
11710 : 82 : if (code != SSA_NAME)
11711 : 0 : pmode = promote_decl_mode (exp, &unsignedp);
11712 : 82 : else if ((g = SSA_NAME_DEF_STMT (ssa_name))
11713 : 82 : && gimple_code (g) == GIMPLE_CALL
11714 : 84 : && !gimple_call_internal_p (g))
11715 : 2 : pmode = promote_function_mode (type, mode, &unsignedp,
11716 : 2 : gimple_call_fntype (g),
11717 : : 2);
11718 : : else
11719 : 80 : pmode = promote_ssa_mode (ssa_name, &unsignedp);
11720 : 82 : gcc_assert (GET_MODE (decl_rtl) == pmode);
11721 : :
11722 : : /* Some ABIs require scalar floating point modes to be passed
11723 : : in a wider scalar integer mode. We need to explicitly
11724 : : truncate to an integer mode of the correct precision before
11725 : : using a SUBREG to reinterpret as a floating point value. */
11726 : 82 : if (SCALAR_FLOAT_MODE_P (mode)
11727 : 0 : && SCALAR_INT_MODE_P (pmode)
11728 : 82 : && known_lt (GET_MODE_SIZE (mode), GET_MODE_SIZE (pmode)))
11729 : 0 : return convert_wider_int_to_float (mode, pmode, decl_rtl);
11730 : :
11731 : 82 : temp = gen_lowpart_SUBREG (mode, decl_rtl);
11732 : 82 : SUBREG_PROMOTED_VAR_P (temp) = 1;
11733 : 82 : SUBREG_PROMOTED_SET (temp, unsignedp);
11734 : 82 : return EXTEND_BITINT (temp);
11735 : : }
11736 : :
11737 : 46139911 : return EXTEND_BITINT (decl_rtl);
11738 : :
11739 : 41959531 : case INTEGER_CST:
11740 : 41959531 : {
11741 : 41959531 : if (TREE_CODE (type) == BITINT_TYPE)
11742 : : {
11743 : 10624 : unsigned int prec = TYPE_PRECISION (type);
11744 : 10624 : struct bitint_info info;
11745 : 10624 : bool ok = targetm.c.bitint_type_info (prec, &info);
11746 : 10624 : gcc_assert (ok);
11747 : 10624 : scalar_int_mode limb_mode
11748 : 10624 : = as_a <scalar_int_mode> (info.limb_mode);
11749 : 10624 : unsigned int limb_prec = GET_MODE_PRECISION (limb_mode);
11750 : 17510 : if (prec > limb_prec && prec > MAX_FIXED_MODE_SIZE)
11751 : : {
11752 : : /* Emit large/huge _BitInt INTEGER_CSTs into memory. */
11753 : 4433 : exp = tree_output_constant_def (exp);
11754 : 4433 : return expand_expr (exp, target, VOIDmode, modifier);
11755 : : }
11756 : : }
11757 : :
11758 : : /* Given that TYPE_PRECISION (type) is not always equal to
11759 : : GET_MODE_PRECISION (TYPE_MODE (type)), we need to extend from
11760 : : the former to the latter according to the signedness of the
11761 : : type. */
11762 : 41955098 : scalar_int_mode int_mode = SCALAR_INT_TYPE_MODE (type);
11763 : 41955098 : temp = immed_wide_int_const
11764 : 41955098 : (wi::to_wide (exp, GET_MODE_PRECISION (int_mode)), int_mode);
11765 : 41955098 : return temp;
11766 : : }
11767 : :
11768 : 559060 : case VECTOR_CST:
11769 : 559060 : {
11770 : 559060 : tree tmp = NULL_TREE;
11771 : 559060 : if (VECTOR_MODE_P (mode))
11772 : 556456 : return const_vector_from_tree (exp);
11773 : 2604 : scalar_int_mode int_mode;
11774 : 2604 : if (is_int_mode (mode, &int_mode))
11775 : : {
11776 : 891 : tree type_for_mode = lang_hooks.types.type_for_mode (int_mode, 1);
11777 : 891 : if (type_for_mode)
11778 : 891 : tmp = fold_unary_loc (loc, VIEW_CONVERT_EXPR,
11779 : : type_for_mode, exp);
11780 : : }
11781 : 891 : if (!tmp)
11782 : : {
11783 : 1713 : vec<constructor_elt, va_gc> *v;
11784 : : /* Constructors need to be fixed-length. FIXME. */
11785 : 1713 : unsigned int nunits = VECTOR_CST_NELTS (exp).to_constant ();
11786 : 1713 : vec_alloc (v, nunits);
11787 : 24552 : for (unsigned int i = 0; i < nunits; ++i)
11788 : 22839 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, VECTOR_CST_ELT (exp, i));
11789 : 1713 : tmp = build_constructor (type, v);
11790 : : }
11791 : 2604 : return expand_expr (tmp, ignore ? const0_rtx : target,
11792 : 2604 : tmode, modifier);
11793 : : }
11794 : :
11795 : 141 : case CONST_DECL:
11796 : 141 : if (modifier == EXPAND_WRITE)
11797 : : {
11798 : : /* Writing into CONST_DECL is always invalid, but handle it
11799 : : gracefully. */
11800 : 2 : addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (exp));
11801 : 2 : scalar_int_mode address_mode = targetm.addr_space.address_mode (as);
11802 : 2 : op0 = expand_expr_addr_expr_1 (exp, NULL_RTX, address_mode,
11803 : : EXPAND_NORMAL, as);
11804 : 2 : op0 = memory_address_addr_space (mode, op0, as);
11805 : 2 : temp = gen_rtx_MEM (mode, op0);
11806 : 2 : set_mem_addr_space (temp, as);
11807 : 2 : return temp;
11808 : : }
11809 : 139 : return expand_expr (DECL_INITIAL (exp), target, VOIDmode, modifier);
11810 : :
11811 : 867643 : case REAL_CST:
11812 : : /* If optimized, generate immediate CONST_DOUBLE
11813 : : which will be turned into memory by reload if necessary.
11814 : :
11815 : : We used to force a register so that loop.c could see it. But
11816 : : this does not allow gen_* patterns to perform optimizations with
11817 : : the constants. It also produces two insns in cases like "x = 1.0;".
11818 : : On most machines, floating-point constants are not permitted in
11819 : : many insns, so we'd end up copying it to a register in any case.
11820 : :
11821 : : Now, we do the copying in expand_binop, if appropriate. */
11822 : 867643 : return const_double_from_real_value (TREE_REAL_CST (exp),
11823 : 1735286 : TYPE_MODE (TREE_TYPE (exp)));
11824 : :
11825 : 0 : case FIXED_CST:
11826 : 0 : return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp),
11827 : : TYPE_MODE (TREE_TYPE (exp)));
11828 : :
11829 : 18398 : case COMPLEX_CST:
11830 : : /* Handle evaluating a complex constant in a CONCAT target. */
11831 : 18398 : if (original_target && GET_CODE (original_target) == CONCAT)
11832 : : {
11833 : 261 : rtx rtarg, itarg;
11834 : :
11835 : 261 : mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
11836 : 261 : rtarg = XEXP (original_target, 0);
11837 : 261 : itarg = XEXP (original_target, 1);
11838 : :
11839 : : /* Move the real and imaginary parts separately. */
11840 : 261 : op0 = expand_expr (TREE_REALPART (exp), rtarg, mode, EXPAND_NORMAL);
11841 : 261 : op1 = expand_expr (TREE_IMAGPART (exp), itarg, mode, EXPAND_NORMAL);
11842 : :
11843 : 261 : if (op0 != rtarg)
11844 : 261 : emit_move_insn (rtarg, op0);
11845 : 261 : if (op1 != itarg)
11846 : 261 : emit_move_insn (itarg, op1);
11847 : :
11848 : 261 : return original_target;
11849 : : }
11850 : :
11851 : : /* fall through */
11852 : :
11853 : 172451 : case STRING_CST:
11854 : 172451 : temp = expand_expr_constant (exp, 1, modifier);
11855 : :
11856 : : /* temp contains a constant address.
11857 : : On RISC machines where a constant address isn't valid,
11858 : : make some insns to get that address into a register. */
11859 : 172451 : if (modifier != EXPAND_CONST_ADDRESS
11860 : : && modifier != EXPAND_INITIALIZER
11861 : 172451 : && modifier != EXPAND_SUM
11862 : 191050 : && ! memory_address_addr_space_p (mode, XEXP (temp, 0),
11863 : 18599 : MEM_ADDR_SPACE (temp)))
11864 : 12 : return replace_equiv_address (temp,
11865 : 12 : copy_rtx (XEXP (temp, 0)));
11866 : : return temp;
11867 : :
11868 : 0 : case POLY_INT_CST:
11869 : 0 : return immed_wide_int_const (poly_int_cst_value (exp), mode);
11870 : :
11871 : 1452 : case SAVE_EXPR:
11872 : 1452 : {
11873 : 1452 : tree val = treeop0;
11874 : 1452 : rtx ret = expand_expr_real_1 (val, target, tmode, modifier, alt_rtl,
11875 : : inner_reference_p);
11876 : :
11877 : 1452 : if (!SAVE_EXPR_RESOLVED_P (exp))
11878 : : {
11879 : : /* We can indeed still hit this case, typically via builtin
11880 : : expanders calling save_expr immediately before expanding
11881 : : something. Assume this means that we only have to deal
11882 : : with non-BLKmode values. */
11883 : 1409 : gcc_assert (GET_MODE (ret) != BLKmode);
11884 : :
11885 : 1409 : val = build_decl (curr_insn_location (),
11886 : 1409 : VAR_DECL, NULL, TREE_TYPE (exp));
11887 : 1409 : DECL_ARTIFICIAL (val) = 1;
11888 : 1409 : DECL_IGNORED_P (val) = 1;
11889 : 1409 : treeop0 = val;
11890 : 1409 : TREE_OPERAND (exp, 0) = treeop0;
11891 : 1409 : SAVE_EXPR_RESOLVED_P (exp) = 1;
11892 : :
11893 : 1409 : if (!CONSTANT_P (ret))
11894 : 1409 : ret = copy_to_reg (ret);
11895 : 1409 : SET_DECL_RTL (val, ret);
11896 : : }
11897 : :
11898 : : return ret;
11899 : : }
11900 : :
11901 : :
11902 : 180022 : case CONSTRUCTOR:
11903 : : /* If we don't need the result, just ensure we evaluate any
11904 : : subexpressions. */
11905 : 180022 : if (ignore)
11906 : : {
11907 : : unsigned HOST_WIDE_INT idx;
11908 : : tree value;
11909 : :
11910 : 0 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
11911 : 0 : expand_expr (value, const0_rtx, VOIDmode, EXPAND_NORMAL);
11912 : :
11913 : 0 : return const0_rtx;
11914 : : }
11915 : :
11916 : 180022 : return expand_constructor (exp, target, modifier, false);
11917 : :
11918 : 840846 : case TARGET_MEM_REF:
11919 : 840846 : {
11920 : 840846 : addr_space_t as
11921 : 840846 : = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
11922 : 840846 : unsigned int align;
11923 : :
11924 : 840846 : op0 = addr_for_mem_ref (exp, as, true);
11925 : 840846 : op0 = memory_address_addr_space (mode, op0, as);
11926 : 840846 : temp = gen_rtx_MEM (mode, op0);
11927 : 840846 : set_mem_attributes (temp, exp, 0);
11928 : 840846 : set_mem_addr_space (temp, as);
11929 : 840846 : align = get_object_alignment (exp);
11930 : 840846 : if (modifier != EXPAND_WRITE
11931 : 840846 : && modifier != EXPAND_MEMORY
11932 : 574815 : && mode != BLKmode
11933 : 1410175 : && align < GET_MODE_ALIGNMENT (mode))
11934 : 50872 : temp = expand_misaligned_mem_ref (temp, mode, unsignedp,
11935 : : align, NULL_RTX, NULL);
11936 : 840846 : return EXTEND_BITINT (temp);
11937 : : }
11938 : :
11939 : 6608369 : case MEM_REF:
11940 : 6608369 : {
11941 : 6608369 : const bool reverse = REF_REVERSE_STORAGE_ORDER (exp);
11942 : 6608369 : addr_space_t as
11943 : 6608369 : = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
11944 : 6608369 : machine_mode address_mode;
11945 : 6608369 : tree base = TREE_OPERAND (exp, 0);
11946 : 6608369 : gimple *def_stmt;
11947 : 6608369 : unsigned align;
11948 : : /* Handle expansion of non-aliased memory with non-BLKmode. That
11949 : : might end up in a register. */
11950 : 6608369 : if (mem_ref_refers_to_non_mem_p (exp))
11951 : : {
11952 : 85054 : poly_int64 offset = mem_ref_offset (exp).force_shwi ();
11953 : 85054 : base = TREE_OPERAND (base, 0);
11954 : 85054 : poly_uint64 type_size;
11955 : 85054 : if (known_eq (offset, 0)
11956 : 47578 : && !reverse
11957 : 47578 : && poly_int_tree_p (TYPE_SIZE (type), &type_size)
11958 : 180210 : && known_eq (GET_MODE_BITSIZE (DECL_MODE (base)), type_size))
11959 : 19821 : return expand_expr (build1 (VIEW_CONVERT_EXPR, type, base),
11960 : 19821 : target, tmode, modifier);
11961 : 65233 : unsigned align;
11962 : 65233 : if (TYPE_MODE (type) == BLKmode || maybe_lt (offset, 0))
11963 : : {
11964 : 206 : temp = assign_stack_temp (DECL_MODE (base),
11965 : 412 : GET_MODE_SIZE (DECL_MODE (base)));
11966 : 206 : store_expr (base, temp, 0, false, false);
11967 : 206 : temp = adjust_address (temp, TYPE_MODE (type), offset);
11968 : 206 : if (TYPE_MODE (type) == BLKmode)
11969 : 191 : set_mem_size (temp, int_size_in_bytes (type));
11970 : : /* When the original ref was misaligned so will be the
11971 : : access to the stack temporary. Not all targets handle
11972 : : this correctly, some will ICE in sanity checking.
11973 : : Handle this by doing bitfield extraction when necessary. */
11974 : 30 : else if ((align = get_object_alignment (exp))
11975 : 15 : < GET_MODE_ALIGNMENT (TYPE_MODE (type)))
11976 : 3 : temp
11977 : 3 : = expand_misaligned_mem_ref (temp, TYPE_MODE (type),
11978 : : unsignedp, align,
11979 : : modifier == EXPAND_STACK_PARM
11980 : : ? NULL_RTX : target, NULL);
11981 : 206 : return temp;
11982 : : }
11983 : : /* When the access is fully outside of the underlying object
11984 : : expand the offset as zero. This avoids out-of-bound
11985 : : BIT_FIELD_REFs and generates smaller code for these cases
11986 : : with UB. */
11987 : 65027 : type_size = tree_to_poly_uint64 (TYPE_SIZE_UNIT (type));
11988 : 130054 : if (!ranges_maybe_overlap_p (offset, type_size, 0,
11989 : 130054 : GET_MODE_SIZE (DECL_MODE (base))))
11990 : 149 : offset = 0;
11991 : 65027 : exp = build3 (BIT_FIELD_REF, type, base, TYPE_SIZE (type),
11992 : 65027 : bitsize_int (offset * BITS_PER_UNIT));
11993 : 65027 : REF_REVERSE_STORAGE_ORDER (exp) = reverse;
11994 : 65027 : return expand_expr (exp, target, tmode, modifier);
11995 : : }
11996 : 6523315 : address_mode = targetm.addr_space.address_mode (as);
11997 : 6523315 : if ((def_stmt = get_def_for_expr (base, BIT_AND_EXPR)))
11998 : : {
11999 : 38 : tree mask = gimple_assign_rhs2 (def_stmt);
12000 : 38 : base = build2 (BIT_AND_EXPR, TREE_TYPE (base),
12001 : : gimple_assign_rhs1 (def_stmt), mask);
12002 : 38 : TREE_OPERAND (exp, 0) = base;
12003 : : }
12004 : 6523315 : align = get_object_alignment (exp);
12005 : 6523315 : op0 = expand_expr (base, NULL_RTX, VOIDmode, EXPAND_SUM);
12006 : 6523315 : op0 = memory_address_addr_space (mode, op0, as);
12007 : 6523315 : if (!integer_zerop (TREE_OPERAND (exp, 1)))
12008 : : {
12009 : 2028448 : rtx off = immed_wide_int_const (mem_ref_offset (exp), address_mode);
12010 : 2028448 : op0 = simplify_gen_binary (PLUS, address_mode, op0, off);
12011 : 2028448 : op0 = memory_address_addr_space (mode, op0, as);
12012 : : }
12013 : 6523315 : temp = gen_rtx_MEM (mode, op0);
12014 : 6523315 : set_mem_attributes (temp, exp, 0);
12015 : 6523315 : set_mem_addr_space (temp, as);
12016 : 6523315 : if (TREE_THIS_VOLATILE (exp))
12017 : 12220 : MEM_VOLATILE_P (temp) = 1;
12018 : 6523315 : if (modifier == EXPAND_WRITE || modifier == EXPAND_MEMORY)
12019 : : return temp;
12020 : 3903689 : if (!inner_reference_p
12021 : 1997921 : && mode != BLKmode
12022 : 5840832 : && align < GET_MODE_ALIGNMENT (mode))
12023 : 135867 : temp = expand_misaligned_mem_ref (temp, mode, unsignedp, align,
12024 : : modifier == EXPAND_STACK_PARM
12025 : : ? NULL_RTX : target, alt_rtl);
12026 : 3903689 : if (reverse)
12027 : 7 : temp = flip_storage_order (mode, temp);
12028 : 3903689 : return EXTEND_BITINT (temp);
12029 : : }
12030 : :
12031 : 612427 : case ARRAY_REF:
12032 : :
12033 : 612427 : {
12034 : 612427 : tree array = treeop0;
12035 : 612427 : tree index = treeop1;
12036 : 612427 : tree init;
12037 : :
12038 : : /* Fold an expression like: "foo"[2].
12039 : : This is not done in fold so it won't happen inside &.
12040 : : Don't fold if this is for wide characters since it's too
12041 : : difficult to do correctly and this is a very rare case. */
12042 : :
12043 : 612427 : if (modifier != EXPAND_CONST_ADDRESS
12044 : 612427 : && modifier != EXPAND_INITIALIZER
12045 : 612427 : && modifier != EXPAND_MEMORY)
12046 : : {
12047 : 612318 : tree t = fold_read_from_constant_string (exp);
12048 : :
12049 : 612318 : if (t)
12050 : 0 : return expand_expr (t, target, tmode, modifier);
12051 : : }
12052 : :
12053 : : /* If this is a constant index into a constant array,
12054 : : just get the value from the array. Handle both the cases when
12055 : : we have an explicit constructor and when our operand is a variable
12056 : : that was declared const. */
12057 : :
12058 : 612427 : if (modifier != EXPAND_CONST_ADDRESS
12059 : : && modifier != EXPAND_INITIALIZER
12060 : : && modifier != EXPAND_MEMORY
12061 : 612318 : && TREE_CODE (array) == CONSTRUCTOR
12062 : 0 : && ! TREE_SIDE_EFFECTS (array)
12063 : 612427 : && TREE_CODE (index) == INTEGER_CST)
12064 : : {
12065 : : unsigned HOST_WIDE_INT ix;
12066 : : tree field, value;
12067 : :
12068 : 0 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array), ix,
12069 : : field, value)
12070 : 0 : if (tree_int_cst_equal (field, index))
12071 : : {
12072 : 0 : if (!TREE_SIDE_EFFECTS (value)
12073 : 0 : && TREE_CODE (value) != RAW_DATA_CST)
12074 : 0 : return expand_expr (fold (value), target, tmode, modifier);
12075 : : break;
12076 : : }
12077 : : }
12078 : :
12079 : 612427 : else if (optimize >= 1
12080 : : && modifier != EXPAND_CONST_ADDRESS
12081 : 345772 : && modifier != EXPAND_INITIALIZER
12082 : 345772 : && modifier != EXPAND_MEMORY
12083 : 345667 : && TREE_READONLY (array) && ! TREE_SIDE_EFFECTS (array)
12084 : 11767 : && TREE_CODE (index) == INTEGER_CST
12085 : 1794 : && (VAR_P (array) || TREE_CODE (array) == CONST_DECL)
12086 : 612567 : && (init = ctor_for_folding (array)) != error_mark_node)
12087 : : {
12088 : 102 : if (init == NULL_TREE)
12089 : : {
12090 : 5 : tree value = build_zero_cst (type);
12091 : 5 : if (TREE_CODE (value) == CONSTRUCTOR)
12092 : : {
12093 : : /* If VALUE is a CONSTRUCTOR, this optimization is only
12094 : : useful if this doesn't store the CONSTRUCTOR into
12095 : : memory. If it does, it is more efficient to just
12096 : : load the data from the array directly. */
12097 : 5 : rtx ret = expand_constructor (value, target,
12098 : : modifier, true);
12099 : 5 : if (ret == NULL_RTX)
12100 : : value = NULL_TREE;
12101 : : }
12102 : :
12103 : : if (value)
12104 : 0 : return expand_expr (value, target, tmode, modifier);
12105 : : }
12106 : 97 : else if (TREE_CODE (init) == CONSTRUCTOR)
12107 : : {
12108 : : unsigned HOST_WIDE_INT ix;
12109 : : tree field, value;
12110 : :
12111 : 198 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), ix,
12112 : : field, value)
12113 : 179 : if (tree_int_cst_equal (field, index))
12114 : : {
12115 : 77 : if (TREE_SIDE_EFFECTS (value)
12116 : 77 : || TREE_CODE (value) == RAW_DATA_CST)
12117 : : break;
12118 : :
12119 : 77 : if (TREE_CODE (value) == CONSTRUCTOR)
12120 : : {
12121 : : /* If VALUE is a CONSTRUCTOR, this
12122 : : optimization is only useful if
12123 : : this doesn't store the CONSTRUCTOR
12124 : : into memory. If it does, it is more
12125 : : efficient to just load the data from
12126 : : the array directly. */
12127 : 72 : rtx ret = expand_constructor (value, target,
12128 : : modifier, true);
12129 : 72 : if (ret == NULL_RTX)
12130 : : break;
12131 : : }
12132 : :
12133 : 39 : return expand_expr (fold (value), target, tmode,
12134 : 39 : modifier);
12135 : : }
12136 : : }
12137 : 1 : else if (TREE_CODE (init) == STRING_CST)
12138 : : {
12139 : 1 : tree low_bound = array_ref_low_bound (exp);
12140 : 1 : tree index1 = fold_convert_loc (loc, sizetype, treeop1);
12141 : :
12142 : : /* Optimize the special case of a zero lower bound.
12143 : :
12144 : : We convert the lower bound to sizetype to avoid problems
12145 : : with constant folding. E.g. suppose the lower bound is
12146 : : 1 and its mode is QI. Without the conversion
12147 : : (ARRAY + (INDEX - (unsigned char)1))
12148 : : becomes
12149 : : (ARRAY + (-(unsigned char)1) + INDEX)
12150 : : which becomes
12151 : : (ARRAY + 255 + INDEX). Oops! */
12152 : 1 : if (!integer_zerop (low_bound))
12153 : 0 : index1 = size_diffop_loc (loc, index1,
12154 : : fold_convert_loc (loc, sizetype,
12155 : : low_bound));
12156 : :
12157 : 1 : if (tree_fits_uhwi_p (index1)
12158 : 2 : && compare_tree_int (index1, TREE_STRING_LENGTH (init)) < 0)
12159 : : {
12160 : 0 : tree char_type = TREE_TYPE (TREE_TYPE (init));
12161 : 0 : scalar_int_mode char_mode;
12162 : :
12163 : 612388 : if (is_int_mode (TYPE_MODE (char_type), &char_mode)
12164 : 0 : && GET_MODE_SIZE (char_mode) == 1)
12165 : 0 : return gen_int_mode (TREE_STRING_POINTER (init)
12166 : 0 : [TREE_INT_CST_LOW (index1)],
12167 : : char_mode);
12168 : : }
12169 : : }
12170 : : }
12171 : : }
12172 : 612388 : goto normal_inner_ref;
12173 : :
12174 : 3771830 : case COMPONENT_REF:
12175 : 3771830 : gcc_assert (TREE_CODE (treeop0) != CONSTRUCTOR);
12176 : : /* Fall through. */
12177 : 4650865 : case BIT_FIELD_REF:
12178 : 4650865 : case ARRAY_RANGE_REF:
12179 : 3771830 : normal_inner_ref:
12180 : 4650865 : {
12181 : 4650865 : machine_mode mode1, mode2;
12182 : 4650865 : poly_int64 bitsize, bitpos, bytepos;
12183 : 4650865 : tree offset;
12184 : 4650865 : int reversep, volatilep = 0;
12185 : 4650865 : tree tem
12186 : 4650865 : = get_inner_reference (exp, &bitsize, &bitpos, &offset, &mode1,
12187 : : &unsignedp, &reversep, &volatilep);
12188 : 4650865 : rtx orig_op0, memloc;
12189 : 4650865 : bool clear_mem_expr = false;
12190 : 4650865 : bool must_force_mem;
12191 : :
12192 : : /* If we got back the original object, something is wrong. Perhaps
12193 : : we are evaluating an expression too early. In any event, don't
12194 : : infinitely recurse. */
12195 : 4650865 : gcc_assert (tem != exp);
12196 : :
12197 : : /* Make sure bitpos is not negative, this can wreak havoc later. */
12198 : 4650865 : if (maybe_lt (bitpos, 0))
12199 : : {
12200 : 247 : gcc_checking_assert (offset == NULL_TREE);
12201 : 247 : offset = size_int (bits_to_bytes_round_down (bitpos));
12202 : 247 : bitpos = num_trailing_bits (bitpos);
12203 : : }
12204 : :
12205 : : /* If we have either an offset, a BLKmode result, or a reference
12206 : : outside the underlying object, we must force it to memory.
12207 : : Such a case can occur in Ada if we have unchecked conversion
12208 : : of an expression from a scalar type to an aggregate type or
12209 : : for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
12210 : : passed a partially uninitialized object or a view-conversion
12211 : : to a larger size. */
12212 : 9301730 : must_force_mem = offset != NULL_TREE
12213 : 4369780 : || mode1 == BLKmode
12214 : 8944562 : || (mode == BLKmode
12215 : 0 : && !int_mode_for_size (bitsize, 1).exists ());
12216 : :
12217 : 548142 : const enum expand_modifier tem_modifier
12218 : : = must_force_mem
12219 : : ? EXPAND_MEMORY
12220 : 4293697 : : modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier;
12221 : :
12222 : : /* If TEM's type is a union of variable size, pass TARGET to the inner
12223 : : computation, since it will need a temporary and TARGET is known
12224 : : to have to do. This occurs in unchecked conversion in Ada. */
12225 : 4650865 : const rtx tem_target
12226 : 4650865 : = TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
12227 : 36830 : && COMPLETE_TYPE_P (TREE_TYPE (tem))
12228 : 36825 : && TREE_CODE (TYPE_SIZE (TREE_TYPE (tem))) != INTEGER_CST
12229 : 0 : && modifier != EXPAND_STACK_PARM
12230 : 4650865 : ? target
12231 : : : NULL_RTX;
12232 : :
12233 : 9301730 : orig_op0 = op0
12234 : 4650865 : = expand_expr_real (tem, tem_target, VOIDmode, tem_modifier, NULL,
12235 : : true);
12236 : :
12237 : : /* If the field has a mode, we want to access it in the
12238 : : field's mode, not the computed mode.
12239 : : If a MEM has VOIDmode (external with incomplete type),
12240 : : use BLKmode for it instead. */
12241 : 4650865 : if (MEM_P (op0))
12242 : : {
12243 : 4304622 : if (mode1 != VOIDmode)
12244 : 4130710 : op0 = adjust_address (op0, mode1, 0);
12245 : 173912 : else if (GET_MODE (op0) == VOIDmode)
12246 : 0 : op0 = adjust_address (op0, BLKmode, 0);
12247 : : }
12248 : :
12249 : 4650865 : mode2
12250 : 4650865 : = CONSTANT_P (op0) ? TYPE_MODE (TREE_TYPE (tem)) : GET_MODE (op0);
12251 : :
12252 : : /* See above for the rationale. */
12253 : 9301730 : if (maybe_gt (bitpos + bitsize, GET_MODE_BITSIZE (mode2)))
12254 : 2911790 : must_force_mem = true;
12255 : :
12256 : : /* Handle CONCAT first. */
12257 : 4650865 : if (GET_CODE (op0) == CONCAT && !must_force_mem)
12258 : : {
12259 : 134 : if (known_eq (bitpos, 0)
12260 : 246 : && known_eq (bitsize, GET_MODE_BITSIZE (GET_MODE (op0)))
12261 : 118 : && COMPLEX_MODE_P (mode1)
12262 : 113 : && COMPLEX_MODE_P (GET_MODE (op0))
12263 : 473 : && (GET_MODE_PRECISION (GET_MODE_INNER (mode1))
12264 : 226 : == GET_MODE_PRECISION (GET_MODE_INNER (GET_MODE (op0)))))
12265 : : {
12266 : 113 : if (reversep)
12267 : 0 : op0 = flip_storage_order (GET_MODE (op0), op0);
12268 : 113 : if (mode1 != GET_MODE (op0))
12269 : : {
12270 : : rtx parts[2];
12271 : 0 : for (int i = 0; i < 2; i++)
12272 : : {
12273 : 0 : rtx op = read_complex_part (op0, i != 0);
12274 : 0 : if (GET_CODE (op) == SUBREG)
12275 : 0 : op = force_reg (GET_MODE (op), op);
12276 : 0 : temp = gen_lowpart_common (GET_MODE_INNER (mode1), op);
12277 : 0 : if (temp)
12278 : : op = temp;
12279 : : else
12280 : : {
12281 : 0 : if (!REG_P (op) && !MEM_P (op))
12282 : 0 : op = force_reg (GET_MODE (op), op);
12283 : 0 : op = gen_lowpart (GET_MODE_INNER (mode1), op);
12284 : : }
12285 : 0 : parts[i] = op;
12286 : : }
12287 : 0 : op0 = gen_rtx_CONCAT (mode1, parts[0], parts[1]);
12288 : : }
12289 : 113 : return op0;
12290 : : }
12291 : 21 : if (known_eq (bitpos, 0)
12292 : 20 : && known_eq (bitsize,
12293 : : GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0))))
12294 : 23 : && maybe_ne (bitsize, 0))
12295 : : {
12296 : : op0 = XEXP (op0, 0);
12297 : : mode2 = GET_MODE (op0);
12298 : : }
12299 : 19 : else if (known_eq (bitpos,
12300 : : GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0))))
12301 : 4 : && known_eq (bitsize,
12302 : : GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 1))))
12303 : 0 : && maybe_ne (bitpos, 0)
12304 : 19 : && maybe_ne (bitsize, 0))
12305 : : {
12306 : 0 : op0 = XEXP (op0, 1);
12307 : 0 : bitpos = 0;
12308 : 0 : mode2 = GET_MODE (op0);
12309 : : }
12310 : : else
12311 : : /* Otherwise force into memory. */
12312 : : must_force_mem = true;
12313 : : }
12314 : :
12315 : : /* If this is a constant, put it in a register if it is a legitimate
12316 : : constant and we don't need a memory reference. */
12317 : 4650752 : if (CONSTANT_P (op0)
12318 : 25 : && mode2 != BLKmode
12319 : 25 : && targetm.legitimate_constant_p (mode2, op0)
12320 : 4650765 : && !must_force_mem)
12321 : 13 : op0 = force_reg (mode2, op0);
12322 : :
12323 : : /* Otherwise, if this is a constant, try to force it to the constant
12324 : : pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
12325 : : is a legitimate constant. */
12326 : 4650739 : else if (CONSTANT_P (op0) && (memloc = force_const_mem (mode2, op0)))
12327 : 12 : op0 = validize_mem (memloc);
12328 : :
12329 : : /* Otherwise, if this is a constant or the object is not in memory
12330 : : and need be, put it there. */
12331 : 4650727 : else if (CONSTANT_P (op0) || (!MEM_P (op0) && must_force_mem))
12332 : : {
12333 : 1216 : poly_int64 size;
12334 : 1216 : if (!poly_int_tree_p (TYPE_SIZE_UNIT (TREE_TYPE (tem)), &size))
12335 : 0 : size = max_int_size_in_bytes (TREE_TYPE (tem));
12336 : 1216 : memloc = assign_stack_local (TYPE_MODE (TREE_TYPE (tem)), size,
12337 : 1216 : TREE_CODE (tem) == SSA_NAME
12338 : 9 : ? TYPE_ALIGN (TREE_TYPE (tem))
12339 : 1207 : : get_object_alignment (tem));
12340 : 1216 : emit_move_insn (memloc, op0);
12341 : 1216 : op0 = memloc;
12342 : 1216 : clear_mem_expr = true;
12343 : : }
12344 : :
12345 : 4650752 : if (offset)
12346 : : {
12347 : 281085 : machine_mode address_mode;
12348 : 281085 : rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode,
12349 : : EXPAND_SUM);
12350 : :
12351 : 281085 : gcc_assert (MEM_P (op0));
12352 : :
12353 : 281085 : address_mode = get_address_mode (op0);
12354 : 281085 : if (GET_MODE (offset_rtx) != address_mode)
12355 : : {
12356 : : /* We cannot be sure that the RTL in offset_rtx is valid outside
12357 : : of a memory address context, so force it into a register
12358 : : before attempting to convert it to the desired mode. */
12359 : 414 : offset_rtx = force_operand (offset_rtx, NULL_RTX);
12360 : 414 : offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
12361 : : }
12362 : :
12363 : : /* See the comment in expand_assignment for the rationale. */
12364 : 281085 : if (mode1 != VOIDmode
12365 : 280851 : && maybe_ne (bitpos, 0)
12366 : 72132 : && maybe_gt (bitsize, 0)
12367 : 353217 : && multiple_p (bitpos, BITS_PER_UNIT, &bytepos)
12368 : 352678 : && multiple_p (bitpos, bitsize)
12369 : 143186 : && multiple_p (bitsize, GET_MODE_ALIGNMENT (mode1))
12370 : 352678 : && MEM_ALIGN (op0) >= GET_MODE_ALIGNMENT (mode1))
12371 : : {
12372 : 71287 : op0 = adjust_address (op0, mode1, bytepos);
12373 : 71287 : bitpos = 0;
12374 : : }
12375 : :
12376 : 281085 : op0 = offset_address (op0, offset_rtx,
12377 : : highest_pow2_factor (offset));
12378 : : }
12379 : :
12380 : : /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
12381 : : record its alignment as BIGGEST_ALIGNMENT. */
12382 : 4650752 : if (MEM_P (op0)
12383 : 4305850 : && known_eq (bitpos, 0)
12384 : 1480016 : && offset != 0
12385 : 4930826 : && is_aligning_offset (offset, tem))
12386 : 0 : set_mem_align (op0, BIGGEST_ALIGNMENT);
12387 : :
12388 : : /* Don't forget about volatility even if this is a bitfield. */
12389 : 4650752 : if (MEM_P (op0) && volatilep && ! MEM_VOLATILE_P (op0))
12390 : : {
12391 : 410 : if (op0 == orig_op0)
12392 : 158 : op0 = copy_rtx (op0);
12393 : :
12394 : 410 : MEM_VOLATILE_P (op0) = 1;
12395 : : }
12396 : :
12397 : 4650752 : if (MEM_P (op0) && TREE_CODE (tem) == FUNCTION_DECL)
12398 : : {
12399 : 6 : if (op0 == orig_op0)
12400 : 0 : op0 = copy_rtx (op0);
12401 : :
12402 : 6 : set_mem_align (op0, BITS_PER_UNIT);
12403 : : }
12404 : :
12405 : : /* In cases where an aligned union has an unaligned object
12406 : : as a field, we might be extracting a BLKmode value from
12407 : : an integer-mode (e.g., SImode) object. Handle this case
12408 : : by doing the extract into an object as wide as the field
12409 : : (which we know to be the width of a basic mode), then
12410 : : storing into memory, and changing the mode to BLKmode. */
12411 : 4650752 : if (mode1 == VOIDmode
12412 : 4399765 : || REG_P (op0) || GET_CODE (op0) == SUBREG
12413 : 4131904 : || (mode1 != BLKmode && ! direct_load[(int) mode1]
12414 : 26598 : && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
12415 : 22448 : && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT
12416 : : && modifier != EXPAND_CONST_ADDRESS
12417 : 15371 : && modifier != EXPAND_INITIALIZER
12418 : 15371 : && modifier != EXPAND_MEMORY)
12419 : : /* If the bitfield is volatile and the bitsize
12420 : : is narrower than the access size of the bitfield,
12421 : : we need to extract bitfields from the access. */
12422 : 4116533 : || (volatilep && TREE_CODE (exp) == COMPONENT_REF
12423 : 1277 : && DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1))
12424 : 10 : && mode1 != BLKmode
12425 : 20 : && maybe_lt (bitsize, GET_MODE_SIZE (mode1) * BITS_PER_UNIT))
12426 : : /* If the field isn't aligned enough to fetch as a memref,
12427 : : fetch it as a bit field. */
12428 : 4116524 : || (mode1 != BLKmode
12429 : 4039619 : && (((MEM_P (op0)
12430 : 4039619 : ? MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode1)
12431 : 7934422 : || !multiple_p (bitpos, GET_MODE_ALIGNMENT (mode1))
12432 : 0 : : TYPE_ALIGN (TREE_TYPE (tem)) < GET_MODE_ALIGNMENT (mode)
12433 : 0 : || !multiple_p (bitpos, GET_MODE_ALIGNMENT (mode)))
12434 : 75722 : && modifier != EXPAND_MEMORY
12435 : 75722 : && ((modifier == EXPAND_CONST_ADDRESS
12436 : 75722 : || modifier == EXPAND_INITIALIZER)
12437 : 75722 : ? STRICT_ALIGNMENT
12438 : 75722 : : targetm.slow_unaligned_access (mode1,
12439 : 75722 : MEM_ALIGN (op0))))
12440 : 4039619 : || !multiple_p (bitpos, BITS_PER_UNIT)))
12441 : : /* If the type and the field are a constant size and the
12442 : : size of the type isn't the same size as the bitfield,
12443 : : we must use bitfield operations. */
12444 : 12806895 : || (known_size_p (bitsize)
12445 : 4116524 : && TYPE_SIZE (TREE_TYPE (exp))
12446 : 4116524 : && poly_int_tree_p (TYPE_SIZE (TREE_TYPE (exp)))
12447 : 4116524 : && maybe_ne (wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (exp))),
12448 : : bitsize)))
12449 : : {
12450 : 534257 : machine_mode ext_mode = mode;
12451 : :
12452 : 534257 : if (ext_mode == BLKmode
12453 : 534257 : && ! (target != 0 && MEM_P (op0)
12454 : 22 : && MEM_P (target)
12455 : 22 : && multiple_p (bitpos, BITS_PER_UNIT)))
12456 : 3 : ext_mode = int_mode_for_size (bitsize, 1).else_blk ();
12457 : :
12458 : 534257 : if (ext_mode == BLKmode)
12459 : : {
12460 : 25 : if (target == 0)
12461 : 3 : target = assign_temp (type, 1, 1);
12462 : :
12463 : : /* ??? Unlike the similar test a few lines below, this one is
12464 : : very likely obsolete. */
12465 : 25 : if (known_eq (bitsize, 0))
12466 : : return target;
12467 : :
12468 : : /* In this case, BITPOS must start at a byte boundary and
12469 : : TARGET, if specified, must be a MEM. */
12470 : 25 : gcc_assert (MEM_P (op0)
12471 : : && (!target || MEM_P (target)));
12472 : :
12473 : 25 : bytepos = exact_div (bitpos, BITS_PER_UNIT);
12474 : 25 : poly_int64 bytesize = bits_to_bytes_round_up (bitsize);
12475 : 50 : emit_block_move (target,
12476 : : adjust_address (op0, VOIDmode, bytepos),
12477 : 25 : gen_int_mode (bytesize, Pmode),
12478 : : (modifier == EXPAND_STACK_PARM
12479 : : ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
12480 : :
12481 : 25 : return target;
12482 : : }
12483 : :
12484 : : /* If we have nothing to extract, the result will be 0 for targets
12485 : : with SHIFT_COUNT_TRUNCATED == 0 and garbage otherwise. Always
12486 : : return 0 for the sake of consistency, as reading a zero-sized
12487 : : bitfield is valid in Ada and the value is fully specified. */
12488 : 534232 : if (known_eq (bitsize, 0))
12489 : 0 : return const0_rtx;
12490 : :
12491 : 534232 : op0 = validize_mem (op0);
12492 : :
12493 : 534232 : if (MEM_P (op0) && REG_P (XEXP (op0, 0)))
12494 : 65438 : mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
12495 : :
12496 : : /* If the result has aggregate type and the extraction is done in
12497 : : an integral mode, then the field may be not aligned on a byte
12498 : : boundary; in this case, if it has reverse storage order, it
12499 : : needs to be extracted as a scalar field with reverse storage
12500 : : order and put back into memory order afterwards. */
12501 : 534232 : if (AGGREGATE_TYPE_P (type)
12502 : 5658 : && GET_MODE_CLASS (ext_mode) == MODE_INT)
12503 : 5576 : reversep = TYPE_REVERSE_STORAGE_ORDER (type);
12504 : :
12505 : 534232 : gcc_checking_assert (known_ge (bitpos, 0));
12506 : 547030 : op0 = extract_bit_field (op0, bitsize, bitpos, unsignedp,
12507 : : (modifier == EXPAND_STACK_PARM
12508 : : ? NULL_RTX : target),
12509 : : ext_mode, ext_mode, reversep, alt_rtl);
12510 : :
12511 : : /* If the result has aggregate type and the mode of OP0 is an
12512 : : integral mode then, if BITSIZE is narrower than this mode
12513 : : and this is for big-endian data, we must put the field
12514 : : into the high-order bits. And we must also put it back
12515 : : into memory order if it has been previously reversed. */
12516 : 534232 : scalar_int_mode op0_mode;
12517 : 534232 : if (AGGREGATE_TYPE_P (type)
12518 : 534232 : && is_int_mode (GET_MODE (op0), &op0_mode))
12519 : : {
12520 : 5576 : HOST_WIDE_INT size = GET_MODE_BITSIZE (op0_mode);
12521 : :
12522 : 5576 : gcc_checking_assert (known_le (bitsize, size));
12523 : 5576 : if (maybe_lt (bitsize, size)
12524 : 5576 : && reversep ? !BYTES_BIG_ENDIAN : BYTES_BIG_ENDIAN)
12525 : 0 : op0 = expand_shift (LSHIFT_EXPR, op0_mode, op0,
12526 : : size - bitsize, op0, 1);
12527 : :
12528 : 5576 : if (reversep)
12529 : 0 : op0 = flip_storage_order (op0_mode, op0);
12530 : : }
12531 : :
12532 : : /* If the result type is BLKmode, store the data into a temporary
12533 : : of the appropriate type, but with the mode corresponding to the
12534 : : mode for the data we have (op0's mode). */
12535 : 534232 : if (mode == BLKmode)
12536 : : {
12537 : 0 : rtx new_rtx
12538 : 0 : = assign_stack_temp_for_type (ext_mode,
12539 : 0 : GET_MODE_BITSIZE (ext_mode),
12540 : : type);
12541 : 0 : emit_move_insn (new_rtx, op0);
12542 : 0 : op0 = copy_rtx (new_rtx);
12543 : 0 : PUT_MODE (op0, BLKmode);
12544 : : }
12545 : :
12546 : 534232 : return op0;
12547 : : }
12548 : :
12549 : : /* If the result is BLKmode, use that to access the object
12550 : : now as well. */
12551 : 4116495 : if (mode == BLKmode)
12552 : 76880 : mode1 = BLKmode;
12553 : :
12554 : : /* Get a reference to just this component. */
12555 : 4116495 : bytepos = bits_to_bytes_round_down (bitpos);
12556 : 4116495 : if (modifier == EXPAND_CONST_ADDRESS
12557 : 4116495 : || modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
12558 : 181250 : op0 = adjust_address_nv (op0, mode1, bytepos);
12559 : : else
12560 : 3935245 : op0 = adjust_address (op0, mode1, bytepos);
12561 : :
12562 : 4116495 : if (op0 == orig_op0)
12563 : 147151 : op0 = copy_rtx (op0);
12564 : :
12565 : : /* Don't set memory attributes if the base expression is
12566 : : SSA_NAME that got expanded as a MEM or a CONSTANT. In that case,
12567 : : we should just honor its original memory attributes. */
12568 : 4116495 : if (!(TREE_CODE (tem) == SSA_NAME
12569 : 8619 : && (MEM_P (orig_op0) || CONSTANT_P (orig_op0))))
12570 : 4107876 : set_mem_attributes (op0, exp, 0);
12571 : :
12572 : 4116495 : if (REG_P (XEXP (op0, 0)))
12573 : 651973 : mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
12574 : :
12575 : : /* If op0 is a temporary because the original expressions was forced
12576 : : to memory, clear MEM_EXPR so that the original expression cannot
12577 : : be marked as addressable through MEM_EXPR of the temporary. */
12578 : 4116495 : if (clear_mem_expr)
12579 : 1182 : set_mem_expr (op0, NULL_TREE);
12580 : :
12581 : 4116495 : MEM_VOLATILE_P (op0) |= volatilep;
12582 : :
12583 : 4116495 : if (reversep
12584 : : && modifier != EXPAND_MEMORY
12585 : 483 : && modifier != EXPAND_WRITE)
12586 : 483 : op0 = flip_storage_order (mode1, op0);
12587 : :
12588 : 4116495 : op0 = EXTEND_BITINT (op0);
12589 : :
12590 : 4116495 : if (mode == mode1 || mode1 == BLKmode || mode1 == tmode
12591 : : || modifier == EXPAND_CONST_ADDRESS
12592 : 0 : || modifier == EXPAND_INITIALIZER)
12593 : : return op0;
12594 : :
12595 : 0 : if (target == 0)
12596 : 0 : target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
12597 : :
12598 : 0 : convert_move (target, op0, unsignedp);
12599 : 0 : return target;
12600 : : }
12601 : :
12602 : 92534 : case OBJ_TYPE_REF:
12603 : 92534 : return expand_expr (OBJ_TYPE_REF_EXPR (exp), target, tmode, modifier);
12604 : :
12605 : 6638203 : case CALL_EXPR:
12606 : : /* All valid uses of __builtin_va_arg_pack () are removed during
12607 : : inlining. */
12608 : 6638203 : if (CALL_EXPR_VA_ARG_PACK (exp))
12609 : 6 : error ("invalid use of %<__builtin_va_arg_pack ()%>");
12610 : 6638203 : {
12611 : 6638203 : tree fndecl = get_callee_fndecl (exp), attr;
12612 : :
12613 : 6638203 : if (fndecl
12614 : : /* Don't diagnose the error attribute in thunks, those are
12615 : : artificially created. */
12616 : 6443259 : && !CALL_FROM_THUNK_P (exp)
12617 : 13077703 : && (attr = lookup_attribute ("error",
12618 : 6439500 : DECL_ATTRIBUTES (fndecl))) != NULL)
12619 : : {
12620 : 5 : const char *ident = lang_hooks.decl_printable_name (fndecl, 1);
12621 : 10 : error ("call to %qs declared with attribute error: %s",
12622 : : identifier_to_locale (ident),
12623 : 5 : TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12624 : : }
12625 : 6638203 : if (fndecl
12626 : : /* Don't diagnose the warning attribute in thunks, those are
12627 : : artificially created. */
12628 : 6443259 : && !CALL_FROM_THUNK_P (exp)
12629 : 13077703 : && (attr = lookup_attribute ("warning",
12630 : 6439500 : DECL_ATTRIBUTES (fndecl))) != NULL)
12631 : : {
12632 : 17 : const char *ident = lang_hooks.decl_printable_name (fndecl, 1);
12633 : 34 : warning_at (EXPR_LOCATION (exp),
12634 : 17 : OPT_Wattribute_warning,
12635 : : "call to %qs declared with attribute warning: %s",
12636 : : identifier_to_locale (ident),
12637 : 17 : TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12638 : : }
12639 : :
12640 : : /* Check for a built-in function. */
12641 : 6638203 : if (fndecl && fndecl_built_in_p (fndecl))
12642 : : {
12643 : 1973491 : gcc_assert (DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_FRONTEND);
12644 : 1973491 : return expand_builtin (exp, target, subtarget, tmode, ignore);
12645 : : }
12646 : : }
12647 : 4664712 : temp = expand_call (exp, target, ignore);
12648 : 4664712 : return EXTEND_BITINT (temp);
12649 : :
12650 : 337245 : case VIEW_CONVERT_EXPR:
12651 : 337245 : op0 = NULL_RTX;
12652 : :
12653 : : /* If we are converting to BLKmode, try to avoid an intermediate
12654 : : temporary by fetching an inner memory reference. */
12655 : 337245 : if (mode == BLKmode
12656 : 74220 : && poly_int_tree_p (TYPE_SIZE (type))
12657 : 74220 : && TYPE_MODE (TREE_TYPE (treeop0)) != BLKmode
12658 : 337245 : && handled_component_p (treeop0))
12659 : : {
12660 : 0 : machine_mode mode1;
12661 : 0 : poly_int64 bitsize, bitpos, bytepos;
12662 : 0 : tree offset;
12663 : 0 : int reversep, volatilep = 0;
12664 : 0 : tree tem
12665 : 0 : = get_inner_reference (treeop0, &bitsize, &bitpos, &offset, &mode1,
12666 : : &unsignedp, &reversep, &volatilep);
12667 : :
12668 : : /* ??? We should work harder and deal with non-zero offsets. */
12669 : 0 : if (!offset
12670 : 0 : && multiple_p (bitpos, BITS_PER_UNIT, &bytepos)
12671 : 0 : && !reversep
12672 : 0 : && known_size_p (bitsize)
12673 : 0 : && known_eq (wi::to_poly_offset (TYPE_SIZE (type)), bitsize))
12674 : : {
12675 : : /* See the normal_inner_ref case for the rationale. */
12676 : 0 : rtx orig_op0
12677 : 0 : = expand_expr_real (tem,
12678 : 0 : (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
12679 : 0 : && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
12680 : : != INTEGER_CST)
12681 : 0 : && modifier != EXPAND_STACK_PARM
12682 : : ? target : NULL_RTX),
12683 : : VOIDmode,
12684 : : modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier,
12685 : : NULL, true);
12686 : :
12687 : 0 : if (MEM_P (orig_op0))
12688 : : {
12689 : 0 : op0 = orig_op0;
12690 : :
12691 : : /* Get a reference to just this component. */
12692 : 0 : if (modifier == EXPAND_CONST_ADDRESS
12693 : : || modifier == EXPAND_SUM
12694 : 0 : || modifier == EXPAND_INITIALIZER)
12695 : 0 : op0 = adjust_address_nv (op0, mode, bytepos);
12696 : : else
12697 : 0 : op0 = adjust_address (op0, mode, bytepos);
12698 : :
12699 : 0 : if (op0 == orig_op0)
12700 : 0 : op0 = copy_rtx (op0);
12701 : :
12702 : 0 : set_mem_attributes (op0, treeop0, 0);
12703 : 0 : if (REG_P (XEXP (op0, 0)))
12704 : 0 : mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
12705 : :
12706 : 0 : MEM_VOLATILE_P (op0) |= volatilep;
12707 : : }
12708 : : }
12709 : : }
12710 : :
12711 : 0 : if (!op0)
12712 : 337245 : op0 = expand_expr_real (treeop0, NULL_RTX, VOIDmode, modifier,
12713 : 337245 : NULL, inner_reference_p || mode == BLKmode);
12714 : :
12715 : : /* If the input and output modes are both the same, we are done. */
12716 : 337245 : if (mode == GET_MODE (op0))
12717 : : ;
12718 : : /* Similarly if the output mode is BLKmode and input is a MEM,
12719 : : adjust_address done below is all we need. */
12720 : 144119 : else if (mode == BLKmode && MEM_P (op0))
12721 : : ;
12722 : : /* If neither mode is BLKmode, and both modes are the same size
12723 : : then we can use gen_lowpart. */
12724 : : else if (mode != BLKmode
12725 : 144086 : && GET_MODE (op0) != BLKmode
12726 : 142760 : && known_eq (GET_MODE_PRECISION (mode),
12727 : : GET_MODE_PRECISION (GET_MODE (op0)))
12728 : 138866 : && !COMPLEX_MODE_P (GET_MODE (op0)))
12729 : : {
12730 : 137469 : if (GET_CODE (op0) == SUBREG)
12731 : 99 : op0 = force_reg (GET_MODE (op0), op0);
12732 : 137469 : temp = gen_lowpart_common (mode, op0);
12733 : 137469 : if (temp)
12734 : : op0 = temp;
12735 : : else
12736 : : {
12737 : 27302 : if (!REG_P (op0) && !MEM_P (op0))
12738 : 18 : op0 = force_reg (GET_MODE (op0), op0);
12739 : 27302 : op0 = gen_lowpart (mode, op0);
12740 : : }
12741 : : }
12742 : : /* If both types are integral, convert from one mode to the other. */
12743 : 6648 : else if (INTEGRAL_TYPE_P (type)
12744 : 3140 : && INTEGRAL_TYPE_P (TREE_TYPE (treeop0))
12745 : 0 : && mode != BLKmode
12746 : 6648 : && GET_MODE (op0) != BLKmode)
12747 : 0 : op0 = convert_modes (mode, GET_MODE (op0), op0,
12748 : 0 : TYPE_UNSIGNED (TREE_TYPE (treeop0)));
12749 : : /* If the output type is a bit-field type, do an extraction. */
12750 : 6648 : else if (reduce_bit_field
12751 : 1 : && mode != BLKmode
12752 : 1 : && (MEM_P (op0) || !COMPLEX_MODE_P (GET_MODE (op0))))
12753 : 0 : return extract_bit_field (op0, TYPE_PRECISION (type), 0,
12754 : 0 : TYPE_UNSIGNED (type), NULL_RTX,
12755 : : mode, mode, false, NULL);
12756 : : /* As a last resort, spill op0 to memory, and reload it in a
12757 : : different mode. */
12758 : 6648 : else if (!MEM_P (op0))
12759 : : {
12760 : : /* If the operand is not a MEM, force it into memory. Since we
12761 : : are going to be changing the mode of the MEM, don't call
12762 : : force_const_mem for constants because we don't allow pool
12763 : : constants to change mode. */
12764 : 5317 : tree inner_type = TREE_TYPE (treeop0);
12765 : :
12766 : 5317 : gcc_assert (!TREE_ADDRESSABLE (exp));
12767 : :
12768 : 5317 : if (target == 0 || GET_MODE (target) != TYPE_MODE (inner_type))
12769 : 5313 : target
12770 : : = assign_stack_temp_for_type
12771 : 5313 : (TYPE_MODE (inner_type),
12772 : 10626 : GET_MODE_SIZE (TYPE_MODE (inner_type)), inner_type);
12773 : :
12774 : 5317 : emit_move_insn (target, op0);
12775 : 5317 : op0 = target;
12776 : :
12777 : 5317 : if (reduce_bit_field && mode != BLKmode)
12778 : 1 : return extract_bit_field (op0, TYPE_PRECISION (type), 0,
12779 : 1 : TYPE_UNSIGNED (type), NULL_RTX,
12780 : : mode, mode, false, NULL);
12781 : : }
12782 : :
12783 : : /* If OP0 is (now) a MEM, we need to deal with alignment issues. If the
12784 : : output type is such that the operand is known to be aligned, indicate
12785 : : that it is. Otherwise, we need only be concerned about alignment for
12786 : : non-BLKmode results. */
12787 : 337244 : if (MEM_P (op0))
12788 : : {
12789 : 127452 : enum insn_code icode;
12790 : :
12791 : 127452 : if (modifier != EXPAND_WRITE
12792 : 127452 : && modifier != EXPAND_MEMORY
12793 : 127452 : && !inner_reference_p
12794 : 127451 : && mode != BLKmode
12795 : 180683 : && MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode))
12796 : : {
12797 : : /* If the target does have special handling for unaligned
12798 : : loads of mode then use them. */
12799 : 15755 : if ((icode = optab_handler (movmisalign_optab, mode))
12800 : : != CODE_FOR_nothing)
12801 : : {
12802 : 1870 : rtx reg;
12803 : :
12804 : 1870 : op0 = adjust_address (op0, mode, 0);
12805 : : /* We've already validated the memory, and we're creating a
12806 : : new pseudo destination. The predicates really can't
12807 : : fail. */
12808 : 1870 : reg = gen_reg_rtx (mode);
12809 : :
12810 : : /* Nor can the insn generator. */
12811 : 1870 : rtx_insn *insn = GEN_FCN (icode) (reg, op0);
12812 : 1870 : emit_insn (insn);
12813 : 1870 : return reg;
12814 : : }
12815 : : else if (STRICT_ALIGNMENT)
12816 : : {
12817 : : poly_uint64 mode_size = GET_MODE_SIZE (mode);
12818 : : poly_uint64 temp_size = mode_size;
12819 : : if (GET_MODE (op0) != BLKmode)
12820 : : temp_size = upper_bound (temp_size,
12821 : : GET_MODE_SIZE (GET_MODE (op0)));
12822 : : rtx new_rtx
12823 : : = assign_stack_temp_for_type (mode, temp_size, type);
12824 : : rtx new_with_op0_mode
12825 : : = adjust_address (new_rtx, GET_MODE (op0), 0);
12826 : :
12827 : : gcc_assert (!TREE_ADDRESSABLE (exp));
12828 : :
12829 : : if (GET_MODE (op0) == BLKmode)
12830 : : {
12831 : : rtx size_rtx = gen_int_mode (mode_size, Pmode);
12832 : : emit_block_move (new_with_op0_mode, op0, size_rtx,
12833 : : (modifier == EXPAND_STACK_PARM
12834 : : ? BLOCK_OP_CALL_PARM
12835 : : : BLOCK_OP_NORMAL));
12836 : : }
12837 : : else
12838 : : emit_move_insn (new_with_op0_mode, op0);
12839 : :
12840 : : op0 = new_rtx;
12841 : : }
12842 : : }
12843 : :
12844 : 125582 : op0 = adjust_address (op0, mode, 0);
12845 : : }
12846 : :
12847 : : return op0;
12848 : :
12849 : 63117 : case MODIFY_EXPR:
12850 : 63117 : {
12851 : 63117 : tree lhs = treeop0;
12852 : 63117 : tree rhs = treeop1;
12853 : 63117 : gcc_assert (ignore);
12854 : :
12855 : : /* Check for |= or &= of a bitfield of size one into another bitfield
12856 : : of size 1. In this case, (unless we need the result of the
12857 : : assignment) we can do this more efficiently with a
12858 : : test followed by an assignment, if necessary.
12859 : :
12860 : : ??? At this point, we can't get a BIT_FIELD_REF here. But if
12861 : : things change so we do, this code should be enhanced to
12862 : : support it. */
12863 : 63117 : if (TREE_CODE (lhs) == COMPONENT_REF
12864 : 60141 : && (TREE_CODE (rhs) == BIT_IOR_EXPR
12865 : 60141 : || TREE_CODE (rhs) == BIT_AND_EXPR)
12866 : 0 : && TREE_OPERAND (rhs, 0) == lhs
12867 : 0 : && TREE_CODE (TREE_OPERAND (rhs, 1)) == COMPONENT_REF
12868 : 0 : && integer_onep (DECL_SIZE (TREE_OPERAND (lhs, 1)))
12869 : 63117 : && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs, 1), 1))))
12870 : : {
12871 : 0 : rtx_code_label *label = gen_label_rtx ();
12872 : 0 : int value = TREE_CODE (rhs) == BIT_IOR_EXPR;
12873 : 0 : profile_probability prob = profile_probability::uninitialized ();
12874 : 0 : if (value)
12875 : 0 : jumpifnot (TREE_OPERAND (rhs, 1), label, prob);
12876 : : else
12877 : 0 : jumpif (TREE_OPERAND (rhs, 1), label, prob);
12878 : 0 : expand_assignment (lhs, build_int_cst (TREE_TYPE (rhs), value),
12879 : : false);
12880 : 0 : do_pending_stack_adjust ();
12881 : 0 : emit_label (label);
12882 : 0 : return const0_rtx;
12883 : : }
12884 : :
12885 : 63117 : expand_assignment (lhs, rhs, false);
12886 : 63117 : return const0_rtx;
12887 : : }
12888 : :
12889 : 13019682 : case ADDR_EXPR:
12890 : 13019682 : return expand_expr_addr_expr (exp, target, tmode, modifier);
12891 : :
12892 : 154636 : case REALPART_EXPR:
12893 : 154636 : op0 = expand_normal (treeop0);
12894 : 154636 : return read_complex_part (op0, false);
12895 : :
12896 : 178553 : case IMAGPART_EXPR:
12897 : 178553 : op0 = expand_normal (treeop0);
12898 : 178553 : return read_complex_part (op0, true);
12899 : :
12900 : 0 : case RETURN_EXPR:
12901 : 0 : case LABEL_EXPR:
12902 : 0 : case GOTO_EXPR:
12903 : 0 : case SWITCH_EXPR:
12904 : 0 : case ASM_EXPR:
12905 : : /* Expanded in cfgexpand.cc. */
12906 : 0 : gcc_unreachable ();
12907 : :
12908 : 0 : case TRY_CATCH_EXPR:
12909 : 0 : case CATCH_EXPR:
12910 : 0 : case EH_FILTER_EXPR:
12911 : 0 : case TRY_FINALLY_EXPR:
12912 : 0 : case EH_ELSE_EXPR:
12913 : : /* Lowered by tree-eh.cc. */
12914 : 0 : gcc_unreachable ();
12915 : :
12916 : 0 : case WITH_CLEANUP_EXPR:
12917 : 0 : case CLEANUP_POINT_EXPR:
12918 : 0 : case TARGET_EXPR:
12919 : 0 : case CASE_LABEL_EXPR:
12920 : 0 : case VA_ARG_EXPR:
12921 : 0 : case BIND_EXPR:
12922 : 0 : case INIT_EXPR:
12923 : 0 : case CONJ_EXPR:
12924 : 0 : case COMPOUND_EXPR:
12925 : 0 : case PREINCREMENT_EXPR:
12926 : 0 : case PREDECREMENT_EXPR:
12927 : 0 : case POSTINCREMENT_EXPR:
12928 : 0 : case POSTDECREMENT_EXPR:
12929 : 0 : case LOOP_EXPR:
12930 : 0 : case EXIT_EXPR:
12931 : 0 : case COMPOUND_LITERAL_EXPR:
12932 : : /* Lowered by gimplify.cc. */
12933 : 0 : gcc_unreachable ();
12934 : :
12935 : 0 : case FDESC_EXPR:
12936 : : /* Function descriptors are not valid except for as
12937 : : initialization constants, and should not be expanded. */
12938 : 0 : gcc_unreachable ();
12939 : :
12940 : 258 : case WITH_SIZE_EXPR:
12941 : : /* WITH_SIZE_EXPR expands to its first argument. The caller should
12942 : : have pulled out the size to use in whatever context it needed. */
12943 : 258 : return expand_expr_real (treeop0, original_target, tmode,
12944 : 258 : modifier, alt_rtl, inner_reference_p);
12945 : :
12946 : 1839836 : default:
12947 : 1839836 : return expand_expr_real_2 (&ops, target, tmode, modifier);
12948 : : }
12949 : : }
12950 : : #undef EXTEND_BITINT
12951 : :
12952 : : /* Subroutine of above: reduce EXP to the precision of TYPE (in the
12953 : : signedness of TYPE), possibly returning the result in TARGET.
12954 : : TYPE is known to be a partial integer type. */
12955 : : static rtx
12956 : 86835 : reduce_to_bit_field_precision (rtx exp, rtx target, tree type)
12957 : : {
12958 : 86835 : scalar_int_mode mode = SCALAR_INT_TYPE_MODE (type);
12959 : 86835 : HOST_WIDE_INT prec = TYPE_PRECISION (type);
12960 : 86835 : gcc_assert ((GET_MODE (exp) == VOIDmode || GET_MODE (exp) == mode)
12961 : : && (!target || GET_MODE (target) == mode));
12962 : :
12963 : : /* For constant values, reduce using wide_int_to_tree. */
12964 : 86835 : if (poly_int_rtx_p (exp))
12965 : : {
12966 : 0 : auto value = wi::to_poly_wide (exp, mode);
12967 : 0 : tree t = wide_int_to_tree (type, value);
12968 : 0 : return expand_expr (t, target, VOIDmode, EXPAND_NORMAL);
12969 : : }
12970 : 86835 : else if (TYPE_UNSIGNED (type))
12971 : : {
12972 : 68731 : rtx mask = immed_wide_int_const
12973 : 68731 : (wi::mask (prec, false, GET_MODE_PRECISION (mode)), mode);
12974 : 68731 : return expand_and (mode, exp, mask, target);
12975 : : }
12976 : : else
12977 : : {
12978 : 18104 : int count = GET_MODE_PRECISION (mode) - prec;
12979 : 18104 : exp = expand_shift (LSHIFT_EXPR, mode, exp, count, target, 0);
12980 : 18104 : return expand_shift (RSHIFT_EXPR, mode, exp, count, target, 0);
12981 : : }
12982 : : }
12983 : :
12984 : : /* Subroutine of above: returns true if OFFSET corresponds to an offset that
12985 : : when applied to the address of EXP produces an address known to be
12986 : : aligned more than BIGGEST_ALIGNMENT. */
12987 : :
12988 : : static bool
12989 : 280074 : is_aligning_offset (const_tree offset, const_tree exp)
12990 : : {
12991 : : /* Strip off any conversions. */
12992 : 304522 : while (CONVERT_EXPR_P (offset))
12993 : 24448 : offset = TREE_OPERAND (offset, 0);
12994 : :
12995 : : /* We must now have a BIT_AND_EXPR with a constant that is one less than
12996 : : power of 2 and which is larger than BIGGEST_ALIGNMENT. */
12997 : 280074 : if (TREE_CODE (offset) != BIT_AND_EXPR
12998 : 0 : || !tree_fits_uhwi_p (TREE_OPERAND (offset, 1))
12999 : 0 : || compare_tree_int (TREE_OPERAND (offset, 1),
13000 : 0 : BIGGEST_ALIGNMENT / BITS_PER_UNIT) <= 0
13001 : 280074 : || !pow2p_hwi (tree_to_uhwi (TREE_OPERAND (offset, 1)) + 1))
13002 : 280074 : return false;
13003 : :
13004 : : /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
13005 : : It must be NEGATE_EXPR. Then strip any more conversions. */
13006 : 0 : offset = TREE_OPERAND (offset, 0);
13007 : 0 : while (CONVERT_EXPR_P (offset))
13008 : 0 : offset = TREE_OPERAND (offset, 0);
13009 : :
13010 : 0 : if (TREE_CODE (offset) != NEGATE_EXPR)
13011 : : return false;
13012 : :
13013 : 0 : offset = TREE_OPERAND (offset, 0);
13014 : 0 : while (CONVERT_EXPR_P (offset))
13015 : 0 : offset = TREE_OPERAND (offset, 0);
13016 : :
13017 : : /* This must now be the address of EXP. */
13018 : 0 : return TREE_CODE (offset) == ADDR_EXPR && TREE_OPERAND (offset, 0) == exp;
13019 : : }
13020 : :
13021 : : /* Return a STRING_CST corresponding to ARG's constant initializer either
13022 : : if it's a string constant, or, when VALREP is set, any other constant,
13023 : : or null otherwise.
13024 : : On success, set *PTR_OFFSET to the (possibly non-constant) byte offset
13025 : : within the byte string that ARG is references. If nonnull set *MEM_SIZE
13026 : : to the size of the byte string. If nonnull, set *DECL to the constant
13027 : : declaration ARG refers to. */
13028 : :
13029 : : static tree
13030 : 15239747 : constant_byte_string (tree arg, tree *ptr_offset, tree *mem_size, tree *decl,
13031 : : bool valrep = false)
13032 : : {
13033 : 15239747 : tree dummy = NULL_TREE;
13034 : 15239747 : if (!mem_size)
13035 : 10858 : mem_size = &dummy;
13036 : :
13037 : : /* Store the type of the original expression before conversions
13038 : : via NOP_EXPR or POINTER_PLUS_EXPR to other types have been
13039 : : removed. */
13040 : 15239747 : tree argtype = TREE_TYPE (arg);
13041 : :
13042 : 15239747 : tree array;
13043 : 15239747 : STRIP_NOPS (arg);
13044 : :
13045 : : /* Non-constant index into the character array in an ARRAY_REF
13046 : : expression or null. */
13047 : 15239747 : tree varidx = NULL_TREE;
13048 : :
13049 : 15239747 : poly_int64 base_off = 0;
13050 : :
13051 : 15239747 : if (TREE_CODE (arg) == ADDR_EXPR)
13052 : : {
13053 : 6209438 : arg = TREE_OPERAND (arg, 0);
13054 : 6209438 : tree ref = arg;
13055 : 6209438 : if (TREE_CODE (arg) == ARRAY_REF)
13056 : : {
13057 : 533764 : tree idx = TREE_OPERAND (arg, 1);
13058 : 533764 : if (TREE_CODE (idx) != INTEGER_CST)
13059 : : {
13060 : : /* From a pointer (but not array) argument extract the variable
13061 : : index to prevent get_addr_base_and_unit_offset() from failing
13062 : : due to it. Use it later to compute the non-constant offset
13063 : : into the string and return it to the caller. */
13064 : 166565 : varidx = idx;
13065 : 166565 : ref = TREE_OPERAND (arg, 0);
13066 : :
13067 : 166565 : if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE)
13068 : : return NULL_TREE;
13069 : :
13070 : 27993 : if (!integer_zerop (array_ref_low_bound (arg)))
13071 : : return NULL_TREE;
13072 : :
13073 : 27245 : if (!integer_onep (array_ref_element_size (arg)))
13074 : : return NULL_TREE;
13075 : : }
13076 : : }
13077 : 6069125 : array = get_addr_base_and_unit_offset (ref, &base_off);
13078 : 6069125 : if (!array
13079 : 6021834 : || (TREE_CODE (array) != VAR_DECL
13080 : 6021834 : && TREE_CODE (array) != CONST_DECL
13081 : 3765698 : && TREE_CODE (array) != STRING_CST))
13082 : : return NULL_TREE;
13083 : : }
13084 : 9030309 : else if (TREE_CODE (arg) == PLUS_EXPR || TREE_CODE (arg) == POINTER_PLUS_EXPR)
13085 : : {
13086 : 26481 : tree arg0 = TREE_OPERAND (arg, 0);
13087 : 26481 : tree arg1 = TREE_OPERAND (arg, 1);
13088 : :
13089 : 26481 : tree offset;
13090 : 26481 : tree str = string_constant (arg0, &offset, mem_size, decl);
13091 : 26481 : if (!str)
13092 : : {
13093 : 17141 : str = string_constant (arg1, &offset, mem_size, decl);
13094 : 17141 : arg1 = arg0;
13095 : : }
13096 : :
13097 : 17141 : if (str)
13098 : : {
13099 : : /* Avoid pointers to arrays (see bug 86622). */
13100 : 9340 : if (POINTER_TYPE_P (TREE_TYPE (arg))
13101 : 9340 : && TREE_CODE (TREE_TYPE (TREE_TYPE (arg))) == ARRAY_TYPE
13102 : 2100 : && !(decl && !*decl)
13103 : 12140 : && !(decl && tree_fits_uhwi_p (DECL_SIZE_UNIT (*decl))
13104 : 1400 : && tree_fits_uhwi_p (*mem_size)
13105 : 1400 : && tree_int_cst_equal (*mem_size, DECL_SIZE_UNIT (*decl))))
13106 : 2100 : return NULL_TREE;
13107 : :
13108 : 7240 : tree type = TREE_TYPE (offset);
13109 : 7240 : arg1 = fold_convert (type, arg1);
13110 : 7240 : *ptr_offset = fold_build2 (PLUS_EXPR, type, offset, arg1);
13111 : 7240 : return str;
13112 : : }
13113 : : return NULL_TREE;
13114 : : }
13115 : 9003828 : else if (TREE_CODE (arg) == SSA_NAME)
13116 : : {
13117 : 3809650 : gimple *stmt = SSA_NAME_DEF_STMT (arg);
13118 : 3809650 : if (!is_gimple_assign (stmt))
13119 : : return NULL_TREE;
13120 : :
13121 : 1005937 : tree rhs1 = gimple_assign_rhs1 (stmt);
13122 : 1005937 : tree_code code = gimple_assign_rhs_code (stmt);
13123 : 1005937 : if (code == ADDR_EXPR)
13124 : 222978 : return string_constant (rhs1, ptr_offset, mem_size, decl);
13125 : 782959 : else if (code != POINTER_PLUS_EXPR)
13126 : : return NULL_TREE;
13127 : :
13128 : 192125 : tree offset;
13129 : 192125 : if (tree str = string_constant (rhs1, &offset, mem_size, decl))
13130 : : {
13131 : : /* Avoid pointers to arrays (see bug 86622). */
13132 : 22647 : if (POINTER_TYPE_P (TREE_TYPE (rhs1))
13133 : 22647 : && TREE_CODE (TREE_TYPE (TREE_TYPE (rhs1))) == ARRAY_TYPE
13134 : 19950 : && !(decl && !*decl)
13135 : 38943 : && !(decl && tree_fits_uhwi_p (DECL_SIZE_UNIT (*decl))
13136 : 8148 : && tree_fits_uhwi_p (*mem_size)
13137 : 8148 : && tree_int_cst_equal (*mem_size, DECL_SIZE_UNIT (*decl))))
13138 : 16448 : return NULL_TREE;
13139 : :
13140 : 6199 : tree rhs2 = gimple_assign_rhs2 (stmt);
13141 : 6199 : tree type = TREE_TYPE (offset);
13142 : 6199 : rhs2 = fold_convert (type, rhs2);
13143 : 6199 : *ptr_offset = fold_build2 (PLUS_EXPR, type, offset, rhs2);
13144 : 6199 : return str;
13145 : : }
13146 : : return NULL_TREE;
13147 : : }
13148 : 5194178 : else if (DECL_P (arg))
13149 : : array = arg;
13150 : : else
13151 : : return NULL_TREE;
13152 : :
13153 : 8365047 : tree offset = wide_int_to_tree (sizetype, base_off);
13154 : 8365047 : if (varidx)
13155 : : {
13156 : 2258 : if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE)
13157 : : return NULL_TREE;
13158 : :
13159 : 1747 : gcc_assert (TREE_CODE (arg) == ARRAY_REF);
13160 : 1747 : tree chartype = TREE_TYPE (TREE_TYPE (TREE_OPERAND (arg, 0)));
13161 : 1747 : if (TREE_CODE (chartype) != INTEGER_TYPE)
13162 : : return NULL;
13163 : :
13164 : 1591 : offset = fold_convert (sizetype, varidx);
13165 : : }
13166 : :
13167 : 8364380 : if (TREE_CODE (array) == STRING_CST)
13168 : : {
13169 : 3384457 : *ptr_offset = fold_convert (sizetype, offset);
13170 : 3384457 : *mem_size = TYPE_SIZE_UNIT (TREE_TYPE (array));
13171 : 3384457 : if (decl)
13172 : 751392 : *decl = NULL_TREE;
13173 : 3384457 : gcc_checking_assert (tree_to_shwi (TYPE_SIZE_UNIT (TREE_TYPE (array)))
13174 : : >= TREE_STRING_LENGTH (array));
13175 : : return array;
13176 : : }
13177 : :
13178 : 4979923 : tree init = ctor_for_folding (array);
13179 : 4979923 : if (!init || init == error_mark_node)
13180 : : return NULL_TREE;
13181 : :
13182 : 153007 : if (valrep)
13183 : : {
13184 : 56385 : HOST_WIDE_INT cstoff;
13185 : 56385 : if (!base_off.is_constant (&cstoff))
13186 : : return NULL_TREE;
13187 : :
13188 : : /* Check that the host and target are sane. */
13189 : 56385 : if (CHAR_BIT != 8 || BITS_PER_UNIT != 8)
13190 : : return NULL_TREE;
13191 : :
13192 : 56385 : HOST_WIDE_INT typesz = int_size_in_bytes (TREE_TYPE (init));
13193 : 56385 : if (typesz <= 0 || (int) typesz != typesz)
13194 : : return NULL_TREE;
13195 : :
13196 : 56232 : HOST_WIDE_INT size = typesz;
13197 : 56232 : if (VAR_P (array)
13198 : 56220 : && DECL_SIZE_UNIT (array)
13199 : 112452 : && tree_fits_shwi_p (DECL_SIZE_UNIT (array)))
13200 : : {
13201 : 56220 : size = tree_to_shwi (DECL_SIZE_UNIT (array));
13202 : 56220 : gcc_checking_assert (size >= typesz);
13203 : : }
13204 : :
13205 : : /* If value representation was requested convert the initializer
13206 : : for the whole array or object into a string of bytes forming
13207 : : its value representation and return it. */
13208 : 56232 : unsigned char *bytes = XNEWVEC (unsigned char, size);
13209 : 56232 : int r = native_encode_initializer (init, bytes, size);
13210 : 56232 : if (r < typesz)
13211 : : {
13212 : 58 : XDELETEVEC (bytes);
13213 : 58 : return NULL_TREE;
13214 : : }
13215 : :
13216 : 56174 : if (r < size)
13217 : 0 : memset (bytes + r, '\0', size - r);
13218 : :
13219 : 56174 : const char *p = reinterpret_cast<const char *>(bytes);
13220 : 56174 : init = build_string_literal (size, p, char_type_node);
13221 : 56174 : init = TREE_OPERAND (init, 0);
13222 : 56174 : init = TREE_OPERAND (init, 0);
13223 : 56174 : XDELETE (bytes);
13224 : :
13225 : 56174 : *mem_size = size_int (TREE_STRING_LENGTH (init));
13226 : 56174 : *ptr_offset = wide_int_to_tree (ssizetype, base_off);
13227 : :
13228 : 56174 : if (decl)
13229 : 0 : *decl = array;
13230 : :
13231 : 56174 : return init;
13232 : : }
13233 : :
13234 : 96622 : if (TREE_CODE (init) == CONSTRUCTOR)
13235 : : {
13236 : : /* Convert the 64-bit constant offset to a wider type to avoid
13237 : : overflow and use it to obtain the initializer for the subobject
13238 : : it points into. */
13239 : 78502 : offset_int wioff;
13240 : 78502 : if (!base_off.is_constant (&wioff))
13241 : 155 : return NULL_TREE;
13242 : :
13243 : 78502 : wioff *= BITS_PER_UNIT;
13244 : 78502 : if (!wi::fits_uhwi_p (wioff))
13245 : : return NULL_TREE;
13246 : :
13247 : 78394 : base_off = wioff.to_uhwi ();
13248 : 78394 : unsigned HOST_WIDE_INT fieldoff = 0;
13249 : 78394 : init = fold_ctor_reference (TREE_TYPE (arg), init, base_off, 0, array,
13250 : : &fieldoff);
13251 : 78394 : if (!init || init == error_mark_node)
13252 : : return NULL_TREE;
13253 : :
13254 : 78347 : HOST_WIDE_INT cstoff;
13255 : 78347 : if (!base_off.is_constant (&cstoff))
13256 : : return NULL_TREE;
13257 : :
13258 : 78347 : cstoff = (cstoff - fieldoff) / BITS_PER_UNIT;
13259 : 78347 : tree off = build_int_cst (sizetype, cstoff);
13260 : 78347 : if (varidx)
13261 : 944 : offset = fold_build2 (PLUS_EXPR, TREE_TYPE (offset), offset, off);
13262 : : else
13263 : : offset = off;
13264 : : }
13265 : :
13266 : 96467 : *ptr_offset = offset;
13267 : :
13268 : 96467 : tree inittype = TREE_TYPE (init);
13269 : :
13270 : 96467 : if (TREE_CODE (init) == INTEGER_CST
13271 : 96467 : && (TREE_CODE (TREE_TYPE (array)) == INTEGER_TYPE
13272 : 880 : || TYPE_MAIN_VARIANT (inittype) == char_type_node))
13273 : : {
13274 : : /* Check that the host and target are sane. */
13275 : 901 : if (CHAR_BIT != 8 || BITS_PER_UNIT != 8)
13276 : : return NULL_TREE;
13277 : :
13278 : : /* For a reference to (address of) a single constant character,
13279 : : store the native representation of the character in CHARBUF.
13280 : : If the reference is to an element of an array or a member
13281 : : of a struct, only consider narrow characters until ctors
13282 : : for wide character arrays are transformed to STRING_CSTs
13283 : : like those for narrow arrays. */
13284 : 901 : unsigned char charbuf[MAX_BITSIZE_MODE_ANY_MODE / BITS_PER_UNIT];
13285 : 901 : int len = native_encode_expr (init, charbuf, sizeof charbuf, 0);
13286 : 901 : if (len > 0)
13287 : : {
13288 : : /* Construct a string literal with elements of INITTYPE and
13289 : : the representation above. Then strip
13290 : : the ADDR_EXPR (ARRAY_REF (...)) around the STRING_CST. */
13291 : 901 : init = build_string_literal (len, (char *)charbuf, inittype);
13292 : 901 : init = TREE_OPERAND (TREE_OPERAND (init, 0), 0);
13293 : : }
13294 : : }
13295 : :
13296 : 96467 : tree initsize = TYPE_SIZE_UNIT (inittype);
13297 : :
13298 : 96467 : if (TREE_CODE (init) == CONSTRUCTOR && initializer_zerop (init))
13299 : : {
13300 : : /* Fold an empty/zero constructor for an implicitly initialized
13301 : : object or subobject into the empty string. */
13302 : :
13303 : : /* Determine the character type from that of the original
13304 : : expression. */
13305 : 9342 : tree chartype = argtype;
13306 : 9342 : if (POINTER_TYPE_P (chartype))
13307 : 9335 : chartype = TREE_TYPE (chartype);
13308 : 14968 : while (TREE_CODE (chartype) == ARRAY_TYPE)
13309 : 5626 : chartype = TREE_TYPE (chartype);
13310 : :
13311 : 9342 : if (INTEGRAL_TYPE_P (chartype)
13312 : 9342 : && TYPE_PRECISION (chartype) == TYPE_PRECISION (char_type_node))
13313 : : {
13314 : : /* Convert a char array to an empty STRING_CST having an array
13315 : : of the expected type and size. */
13316 : 9129 : if (!initsize)
13317 : 3090 : initsize = integer_zero_node;
13318 : 6039 : else if (!tree_fits_uhwi_p (initsize))
13319 : : return NULL_TREE;
13320 : :
13321 : 9123 : unsigned HOST_WIDE_INT size = tree_to_uhwi (initsize);
13322 : 9123 : if (size > (unsigned HOST_WIDE_INT) INT_MAX)
13323 : : return NULL_TREE;
13324 : :
13325 : 9123 : init = build_string_literal (size, NULL, chartype, size);
13326 : 9123 : init = TREE_OPERAND (init, 0);
13327 : 9123 : init = TREE_OPERAND (init, 0);
13328 : :
13329 : 9123 : *ptr_offset = integer_zero_node;
13330 : : }
13331 : : }
13332 : :
13333 : 96461 : if (decl)
13334 : 54026 : *decl = array;
13335 : :
13336 : 96461 : if (TREE_CODE (init) != STRING_CST)
13337 : : return NULL_TREE;
13338 : :
13339 : 66882 : *mem_size = initsize;
13340 : :
13341 : 66882 : gcc_checking_assert (tree_to_shwi (initsize) >= TREE_STRING_LENGTH (init));
13342 : :
13343 : : return init;
13344 : : }
13345 : :
13346 : : /* Return STRING_CST if an ARG corresponds to a string constant or zero
13347 : : if it doesn't. If we return nonzero, set *PTR_OFFSET to the (possibly
13348 : : non-constant) offset in bytes within the string that ARG is accessing.
13349 : : If MEM_SIZE is non-zero the storage size of the memory is returned.
13350 : : If DECL is non-zero the constant declaration is returned if available. */
13351 : :
13352 : : tree
13353 : 10706152 : string_constant (tree arg, tree *ptr_offset, tree *mem_size, tree *decl)
13354 : : {
13355 : 10706152 : return constant_byte_string (arg, ptr_offset, mem_size, decl, false);
13356 : : }
13357 : :
13358 : : /* Similar to string_constant, return a STRING_CST corresponding
13359 : : to the value representation of the first argument if it's
13360 : : a constant. */
13361 : :
13362 : : tree
13363 : 4533595 : byte_representation (tree arg, tree *ptr_offset, tree *mem_size, tree *decl)
13364 : : {
13365 : 4533595 : return constant_byte_string (arg, ptr_offset, mem_size, decl, true);
13366 : : }
13367 : :
13368 : : /* Optimize x % C1 == C2 for signed modulo if C1 is a power of two and C2
13369 : : is non-zero and C3 ((1<<(prec-1)) | (C1 - 1)):
13370 : : for C2 > 0 to x & C3 == C2
13371 : : for C2 < 0 to x & C3 == (C2 & C3). */
13372 : : enum tree_code
13373 : 35 : maybe_optimize_pow2p_mod_cmp (enum tree_code code, tree *arg0, tree *arg1)
13374 : : {
13375 : 35 : gimple *stmt = get_def_for_expr (*arg0, TRUNC_MOD_EXPR);
13376 : 35 : tree treeop0 = gimple_assign_rhs1 (stmt);
13377 : 35 : tree treeop1 = gimple_assign_rhs2 (stmt);
13378 : 35 : tree type = TREE_TYPE (*arg0);
13379 : 35 : scalar_int_mode mode;
13380 : 35 : if (!is_a <scalar_int_mode> (TYPE_MODE (type), &mode))
13381 : : return code;
13382 : 70 : if (GET_MODE_BITSIZE (mode) != TYPE_PRECISION (type)
13383 : 35 : || TYPE_PRECISION (type) <= 1
13384 : 35 : || TYPE_UNSIGNED (type)
13385 : : /* Signed x % c == 0 should have been optimized into unsigned modulo
13386 : : earlier. */
13387 : 35 : || integer_zerop (*arg1)
13388 : : /* If c is known to be non-negative, modulo will be expanded as unsigned
13389 : : modulo. */
13390 : 70 : || get_range_pos_neg (treeop0, currently_expanding_gimple_stmt) == 1)
13391 : 0 : return code;
13392 : :
13393 : : /* x % c == d where d < 0 && d <= -c should be always false. */
13394 : 35 : if (tree_int_cst_sgn (*arg1) == -1
13395 : 51 : && -wi::to_widest (treeop1) >= wi::to_widest (*arg1))
13396 : : return code;
13397 : :
13398 : 35 : int prec = TYPE_PRECISION (type);
13399 : 35 : wide_int w = wi::to_wide (treeop1) - 1;
13400 : 35 : w |= wi::shifted_mask (0, prec - 1, true, prec);
13401 : 35 : tree c3 = wide_int_to_tree (type, w);
13402 : 35 : tree c4 = *arg1;
13403 : 35 : if (tree_int_cst_sgn (*arg1) == -1)
13404 : 16 : c4 = wide_int_to_tree (type, w & wi::to_wide (*arg1));
13405 : :
13406 : 35 : rtx op0 = expand_normal (treeop0);
13407 : 35 : treeop0 = make_tree (TREE_TYPE (treeop0), op0);
13408 : :
13409 : 35 : bool speed_p = optimize_insn_for_speed_p ();
13410 : :
13411 : 35 : do_pending_stack_adjust ();
13412 : :
13413 : 35 : location_t loc = gimple_location (stmt);
13414 : 35 : struct separate_ops ops;
13415 : 35 : ops.code = TRUNC_MOD_EXPR;
13416 : 35 : ops.location = loc;
13417 : 35 : ops.type = TREE_TYPE (treeop0);
13418 : 35 : ops.op0 = treeop0;
13419 : 35 : ops.op1 = treeop1;
13420 : 35 : ops.op2 = NULL_TREE;
13421 : 35 : start_sequence ();
13422 : 35 : rtx mor = expand_expr_real_2 (&ops, NULL_RTX, TYPE_MODE (ops.type),
13423 : : EXPAND_NORMAL);
13424 : 35 : rtx_insn *moinsns = end_sequence ();
13425 : :
13426 : 35 : unsigned mocost = seq_cost (moinsns, speed_p);
13427 : 35 : mocost += rtx_cost (mor, mode, EQ, 0, speed_p);
13428 : 35 : mocost += rtx_cost (expand_normal (*arg1), mode, EQ, 1, speed_p);
13429 : :
13430 : 35 : ops.code = BIT_AND_EXPR;
13431 : 35 : ops.location = loc;
13432 : 35 : ops.type = TREE_TYPE (treeop0);
13433 : 35 : ops.op0 = treeop0;
13434 : 35 : ops.op1 = c3;
13435 : 35 : ops.op2 = NULL_TREE;
13436 : 35 : start_sequence ();
13437 : 35 : rtx mur = expand_expr_real_2 (&ops, NULL_RTX, TYPE_MODE (ops.type),
13438 : : EXPAND_NORMAL);
13439 : 35 : rtx_insn *muinsns = end_sequence ();
13440 : :
13441 : 35 : unsigned mucost = seq_cost (muinsns, speed_p);
13442 : 35 : mucost += rtx_cost (mur, mode, EQ, 0, speed_p);
13443 : 35 : mucost += rtx_cost (expand_normal (c4), mode, EQ, 1, speed_p);
13444 : :
13445 : 35 : if (mocost <= mucost)
13446 : : {
13447 : 0 : emit_insn (moinsns);
13448 : 0 : *arg0 = make_tree (TREE_TYPE (*arg0), mor);
13449 : 0 : return code;
13450 : : }
13451 : :
13452 : 35 : emit_insn (muinsns);
13453 : 35 : *arg0 = make_tree (TREE_TYPE (*arg0), mur);
13454 : 35 : *arg1 = c4;
13455 : 35 : return code;
13456 : 35 : }
13457 : :
13458 : : /* Attempt to optimize unsigned (X % C1) == C2 (or (X % C1) != C2).
13459 : : If C1 is odd to:
13460 : : (X - C2) * C3 <= C4 (or >), where
13461 : : C3 is modular multiplicative inverse of C1 and 1<<prec and
13462 : : C4 is ((1<<prec) - 1) / C1 or ((1<<prec) - 1) / C1 - 1 (the latter
13463 : : if C2 > ((1<<prec) - 1) % C1).
13464 : : If C1 is even, S = ctz (C1) and C2 is 0, use
13465 : : ((X * C3) r>> S) <= C4, where C3 is modular multiplicative
13466 : : inverse of C1>>S and 1<<prec and C4 is (((1<<prec) - 1) / (C1>>S)) >> S.
13467 : :
13468 : : For signed (X % C1) == 0 if C1 is odd to (all operations in it
13469 : : unsigned):
13470 : : (X * C3) + C4 <= 2 * C4, where
13471 : : C3 is modular multiplicative inverse of (unsigned) C1 and 1<<prec and
13472 : : C4 is ((1<<(prec - 1) - 1) / C1).
13473 : : If C1 is even, S = ctz(C1), use
13474 : : ((X * C3) + C4) r>> S <= (C4 >> (S - 1))
13475 : : where C3 is modular multiplicative inverse of (unsigned)(C1>>S) and 1<<prec
13476 : : and C4 is ((1<<(prec - 1) - 1) / (C1>>S)) & (-1<<S).
13477 : :
13478 : : See the Hacker's Delight book, section 10-17. */
13479 : : enum tree_code
13480 : 3300570 : maybe_optimize_mod_cmp (enum tree_code code, tree *arg0, tree *arg1)
13481 : : {
13482 : 3300570 : gcc_checking_assert (code == EQ_EXPR || code == NE_EXPR);
13483 : 3300570 : gcc_checking_assert (TREE_CODE (*arg1) == INTEGER_CST);
13484 : :
13485 : 3300570 : if (optimize < 2)
13486 : : return code;
13487 : :
13488 : 2508068 : gimple *stmt = get_def_for_expr (*arg0, TRUNC_MOD_EXPR);
13489 : 2508068 : if (stmt == NULL)
13490 : : return code;
13491 : :
13492 : 2630 : tree treeop0 = gimple_assign_rhs1 (stmt);
13493 : 2630 : tree treeop1 = gimple_assign_rhs2 (stmt);
13494 : 2630 : if (TREE_CODE (treeop0) != SSA_NAME
13495 : 2542 : || TREE_CODE (treeop1) != INTEGER_CST
13496 : : /* Don't optimize the undefined behavior case x % 0;
13497 : : x % 1 should have been optimized into zero, punt if
13498 : : it makes it here for whatever reason;
13499 : : x % -c should have been optimized into x % c. */
13500 : 2177 : || compare_tree_int (treeop1, 2) <= 0
13501 : : /* Likewise x % c == d where d >= c should be always false. */
13502 : 4726 : || tree_int_cst_le (treeop1, *arg1))
13503 : 534 : return code;
13504 : :
13505 : : /* Unsigned x % pow2 is handled right already, for signed
13506 : : modulo handle it in maybe_optimize_pow2p_mod_cmp. */
13507 : 2096 : if (integer_pow2p (treeop1))
13508 : 35 : return maybe_optimize_pow2p_mod_cmp (code, arg0, arg1);
13509 : :
13510 : 2061 : tree type = TREE_TYPE (*arg0);
13511 : 2061 : scalar_int_mode mode;
13512 : 3300542 : if (!is_a <scalar_int_mode> (TYPE_MODE (type), &mode))
13513 : : return code;
13514 : 4122 : if (GET_MODE_BITSIZE (mode) != TYPE_PRECISION (type)
13515 : 2061 : || TYPE_PRECISION (type) <= 1)
13516 : : return code;
13517 : :
13518 : 2061 : signop sgn = UNSIGNED;
13519 : : /* If both operands are known to have the sign bit clear, handle
13520 : : even the signed modulo case as unsigned. treeop1 is always
13521 : : positive >= 2, checked above. */
13522 : 2061 : if (!TYPE_UNSIGNED (type)
13523 : 2061 : && get_range_pos_neg (treeop0, currently_expanding_gimple_stmt) != 1)
13524 : : sgn = SIGNED;
13525 : :
13526 : 2061 : if (!TYPE_UNSIGNED (type))
13527 : : {
13528 : 1833 : if (tree_int_cst_sgn (*arg1) == -1)
13529 : : return code;
13530 : 1826 : type = unsigned_type_for (type);
13531 : 1826 : if (!type || TYPE_MODE (type) != TYPE_MODE (TREE_TYPE (*arg0)))
13532 : 0 : return code;
13533 : : }
13534 : :
13535 : 2054 : int prec = TYPE_PRECISION (type);
13536 : 2054 : wide_int w = wi::to_wide (treeop1);
13537 : 2054 : int shift = wi::ctz (w);
13538 : : /* Unsigned (X % C1) == C2 is equivalent to (X - C2) % C1 == 0 if
13539 : : C2 <= -1U % C1, because for any Z >= 0U - C2 in that case (Z % C1) != 0.
13540 : : If C1 is odd, we can handle all cases by subtracting
13541 : : C4 below. We could handle even the even C1 and C2 > -1U % C1 cases
13542 : : e.g. by testing for overflow on the subtraction, punt on that for now
13543 : : though. */
13544 : 2054 : if ((sgn == SIGNED || shift) && !integer_zerop (*arg1))
13545 : : {
13546 : 191 : if (sgn == SIGNED)
13547 : 176 : return code;
13548 : 26 : wide_int x = wi::umod_trunc (wi::mask (prec, false, prec), w);
13549 : 26 : if (wi::gtu_p (wi::to_wide (*arg1), x))
13550 : 11 : return code;
13551 : 26 : }
13552 : :
13553 : 1878 : imm_use_iterator imm_iter;
13554 : 1878 : use_operand_p use_p;
13555 : 15552 : FOR_EACH_IMM_USE_FAST (use_p, imm_iter, treeop0)
13556 : : {
13557 : 11806 : gimple *use_stmt = USE_STMT (use_p);
13558 : : /* Punt if treeop0 is used in the same bb in a division
13559 : : or another modulo with the same divisor. We should expect
13560 : : the division and modulo combined together. */
13561 : 22956 : if (use_stmt == stmt
13562 : 11806 : || gimple_bb (use_stmt) != gimple_bb (stmt))
13563 : 11150 : continue;
13564 : 656 : if (!is_gimple_assign (use_stmt)
13565 : 656 : || (gimple_assign_rhs_code (use_stmt) != TRUNC_DIV_EXPR
13566 : 640 : && gimple_assign_rhs_code (use_stmt) != TRUNC_MOD_EXPR))
13567 : 637 : continue;
13568 : 19 : if (gimple_assign_rhs1 (use_stmt) != treeop0
13569 : 19 : || !operand_equal_p (gimple_assign_rhs2 (use_stmt), treeop1, 0))
13570 : 9 : continue;
13571 : 10 : return code;
13572 : 10 : }
13573 : :
13574 : 1868 : w = wi::lrshift (w, shift);
13575 : 1868 : wide_int a = wide_int::from (w, prec + 1, UNSIGNED);
13576 : 1868 : wide_int b = wi::shifted_mask (prec, 1, false, prec + 1);
13577 : 1868 : wide_int m = wide_int::from (wi::mod_inv (a, b), prec, UNSIGNED);
13578 : 1868 : tree c3 = wide_int_to_tree (type, m);
13579 : 1868 : tree c5 = NULL_TREE;
13580 : 1868 : wide_int d, e;
13581 : 1868 : if (sgn == UNSIGNED)
13582 : : {
13583 : 1037 : d = wi::divmod_trunc (wi::mask (prec, false, prec), w, UNSIGNED, &e);
13584 : : /* Use <= floor ((1<<prec) - 1) / C1 only if C2 <= ((1<<prec) - 1) % C1,
13585 : : otherwise use < or subtract one from C4. E.g. for
13586 : : x % 3U == 0 we transform this into x * 0xaaaaaaab <= 0x55555555, but
13587 : : x % 3U == 1 already needs to be
13588 : : (x - 1) * 0xaaaaaaabU <= 0x55555554. */
13589 : 1037 : if (!shift && wi::gtu_p (wi::to_wide (*arg1), e))
13590 : 15 : d -= 1;
13591 : 1037 : if (shift)
13592 : 442 : d = wi::lrshift (d, shift);
13593 : : }
13594 : : else
13595 : : {
13596 : 831 : e = wi::udiv_trunc (wi::mask (prec - 1, false, prec), w);
13597 : 831 : if (!shift)
13598 : 638 : d = wi::lshift (e, 1);
13599 : : else
13600 : : {
13601 : 193 : e = wi::bit_and (e, wi::mask (shift, true, prec));
13602 : 193 : d = wi::lrshift (e, shift - 1);
13603 : : }
13604 : 831 : c5 = wide_int_to_tree (type, e);
13605 : : }
13606 : 1868 : tree c4 = wide_int_to_tree (type, d);
13607 : :
13608 : 1868 : rtx op0 = expand_normal (treeop0);
13609 : 1868 : treeop0 = make_tree (TREE_TYPE (treeop0), op0);
13610 : :
13611 : 1868 : bool speed_p = optimize_insn_for_speed_p ();
13612 : :
13613 : 1868 : do_pending_stack_adjust ();
13614 : :
13615 : 1868 : location_t loc = gimple_location (stmt);
13616 : 1868 : struct separate_ops ops;
13617 : 1868 : ops.code = TRUNC_MOD_EXPR;
13618 : 1868 : ops.location = loc;
13619 : 1868 : ops.type = TREE_TYPE (treeop0);
13620 : 1868 : ops.op0 = treeop0;
13621 : 1868 : ops.op1 = treeop1;
13622 : 1868 : ops.op2 = NULL_TREE;
13623 : 1868 : start_sequence ();
13624 : 1868 : rtx mor = expand_expr_real_2 (&ops, NULL_RTX, TYPE_MODE (ops.type),
13625 : : EXPAND_NORMAL);
13626 : 1868 : rtx_insn *moinsns = end_sequence ();
13627 : :
13628 : 1868 : unsigned mocost = seq_cost (moinsns, speed_p);
13629 : 1868 : mocost += rtx_cost (mor, mode, EQ, 0, speed_p);
13630 : 1868 : mocost += rtx_cost (expand_normal (*arg1), mode, EQ, 1, speed_p);
13631 : :
13632 : 1868 : tree t = fold_convert_loc (loc, type, treeop0);
13633 : 1868 : if (!integer_zerop (*arg1))
13634 : 36 : t = fold_build2_loc (loc, MINUS_EXPR, type, t, fold_convert (type, *arg1));
13635 : 1868 : t = fold_build2_loc (loc, MULT_EXPR, type, t, c3);
13636 : 1868 : if (sgn == SIGNED)
13637 : 831 : t = fold_build2_loc (loc, PLUS_EXPR, type, t, c5);
13638 : 1868 : if (shift)
13639 : : {
13640 : 635 : tree s = build_int_cst (NULL_TREE, shift);
13641 : 635 : t = fold_build2_loc (loc, RROTATE_EXPR, type, t, s);
13642 : : }
13643 : :
13644 : 1868 : start_sequence ();
13645 : 1868 : rtx mur = expand_normal (t);
13646 : 1868 : rtx_insn *muinsns = end_sequence ();
13647 : :
13648 : 1868 : unsigned mucost = seq_cost (muinsns, speed_p);
13649 : 1868 : mucost += rtx_cost (mur, mode, LE, 0, speed_p);
13650 : 1868 : mucost += rtx_cost (expand_normal (c4), mode, LE, 1, speed_p);
13651 : :
13652 : 1868 : if (mocost <= mucost)
13653 : : {
13654 : 308 : emit_insn (moinsns);
13655 : 308 : *arg0 = make_tree (TREE_TYPE (*arg0), mor);
13656 : 308 : return code;
13657 : : }
13658 : :
13659 : 1560 : emit_insn (muinsns);
13660 : 1560 : *arg0 = make_tree (type, mur);
13661 : 1560 : *arg1 = c4;
13662 : 1560 : return code == EQ_EXPR ? LE_EXPR : GT_EXPR;
13663 : 3922 : }
13664 : :
13665 : : /* Optimize x - y < 0 into x < 0 if x - y has undefined overflow. */
13666 : :
13667 : : void
13668 : 238100 : maybe_optimize_sub_cmp_0 (enum tree_code code, tree *arg0, tree *arg1)
13669 : : {
13670 : 238100 : gcc_checking_assert (code == GT_EXPR || code == GE_EXPR
13671 : : || code == LT_EXPR || code == LE_EXPR);
13672 : 238100 : gcc_checking_assert (integer_zerop (*arg1));
13673 : :
13674 : 238100 : if (!optimize)
13675 : : return;
13676 : :
13677 : 204885 : gimple *stmt = get_def_for_expr (*arg0, MINUS_EXPR);
13678 : 204885 : if (stmt == NULL)
13679 : : return;
13680 : :
13681 : 1326 : tree treeop0 = gimple_assign_rhs1 (stmt);
13682 : 1326 : tree treeop1 = gimple_assign_rhs2 (stmt);
13683 : 1326 : if (!TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (treeop0)))
13684 : : return;
13685 : :
13686 : 1229 : if (issue_strict_overflow_warning (WARN_STRICT_OVERFLOW_COMPARISON))
13687 : 1 : warning_at (gimple_location (stmt), OPT_Wstrict_overflow,
13688 : : "assuming signed overflow does not occur when "
13689 : : "simplifying %<X - Y %s 0%> to %<X %s Y%>",
13690 : : op_symbol_code (code), op_symbol_code (code));
13691 : :
13692 : 1229 : *arg0 = treeop0;
13693 : 1229 : *arg1 = treeop1;
13694 : : }
13695 : :
13696 : :
13697 : : /* Expand CODE with arguments INNER & (1<<BITNUM) and 0 that represents
13698 : : a single bit equality/inequality test, returns where the result is located. */
13699 : :
13700 : : static rtx
13701 : 11010 : expand_single_bit_test (location_t loc, enum tree_code code,
13702 : : tree inner, int bitnum,
13703 : : tree result_type, rtx target,
13704 : : machine_mode mode)
13705 : : {
13706 : 11010 : gcc_assert (code == NE_EXPR || code == EQ_EXPR);
13707 : :
13708 : 11010 : tree type = TREE_TYPE (inner);
13709 : 11010 : scalar_int_mode operand_mode = SCALAR_INT_TYPE_MODE (type);
13710 : 11010 : int ops_unsigned;
13711 : 11010 : tree signed_type, unsigned_type, intermediate_type;
13712 : 11010 : gimple *inner_def;
13713 : :
13714 : : /* First, see if we can fold the single bit test into a sign-bit
13715 : : test. */
13716 : 11010 : if (bitnum == TYPE_PRECISION (type) - 1
13717 : 11010 : && type_has_mode_precision_p (type))
13718 : : {
13719 : 231 : tree stype = signed_type_for (type);
13720 : 428 : tree tmp = fold_build2_loc (loc, code == EQ_EXPR ? GE_EXPR : LT_EXPR,
13721 : : result_type,
13722 : : fold_convert_loc (loc, stype, inner),
13723 : : build_int_cst (stype, 0));
13724 : 231 : return expand_expr (tmp, target, VOIDmode, EXPAND_NORMAL);
13725 : : }
13726 : :
13727 : : /* Otherwise we have (A & C) != 0 where C is a single bit,
13728 : : convert that into ((A >> C2) & 1). Where C2 = log2(C).
13729 : : Similarly for (A & C) == 0. */
13730 : :
13731 : : /* If INNER is a right shift of a constant and it plus BITNUM does
13732 : : not overflow, adjust BITNUM and INNER. */
13733 : 10779 : if ((inner_def = get_def_for_expr (inner, RSHIFT_EXPR))
13734 : 85 : && TREE_CODE (gimple_assign_rhs2 (inner_def)) == INTEGER_CST
13735 : 8 : && bitnum < TYPE_PRECISION (type)
13736 : 10787 : && wi::ltu_p (wi::to_wide (gimple_assign_rhs2 (inner_def)),
13737 : 10779 : TYPE_PRECISION (type) - bitnum))
13738 : : {
13739 : 8 : bitnum += tree_to_uhwi (gimple_assign_rhs2 (inner_def));
13740 : 8 : inner = gimple_assign_rhs1 (inner_def);
13741 : : }
13742 : :
13743 : : /* If we are going to be able to omit the AND below, we must do our
13744 : : operations as unsigned. If we must use the AND, we have a choice.
13745 : : Normally unsigned is faster, but for some machines signed is. */
13746 : 10779 : ops_unsigned = (load_extend_op (operand_mode) == SIGN_EXTEND
13747 : : && !flag_syntax_only) ? 0 : 1;
13748 : :
13749 : 10779 : signed_type = lang_hooks.types.type_for_mode (operand_mode, 0);
13750 : 10779 : unsigned_type = lang_hooks.types.type_for_mode (operand_mode, 1);
13751 : 10779 : intermediate_type = ops_unsigned ? unsigned_type : signed_type;
13752 : 10779 : inner = fold_convert_loc (loc, intermediate_type, inner);
13753 : :
13754 : 10779 : rtx inner0 = expand_expr (inner, NULL_RTX, VOIDmode, EXPAND_NORMAL);
13755 : :
13756 : 10779 : if (CONST_SCALAR_INT_P (inner0))
13757 : : {
13758 : 0 : wide_int t = rtx_mode_t (inner0, operand_mode);
13759 : 0 : bool setp = (wi::lrshift (t, bitnum) & 1) != 0;
13760 : 0 : return (setp ^ (code == EQ_EXPR)) ? const1_rtx : const0_rtx;
13761 : 0 : }
13762 : 10779 : int bitpos = bitnum;
13763 : :
13764 : 10779 : if (BYTES_BIG_ENDIAN)
13765 : : bitpos = GET_MODE_BITSIZE (operand_mode) - 1 - bitpos;
13766 : :
13767 : 10779 : inner0 = extract_bit_field (inner0, 1, bitpos, 1, target,
13768 : : operand_mode, mode, 0, NULL);
13769 : :
13770 : 10779 : if (code == EQ_EXPR)
13771 : 3913 : inner0 = expand_binop (GET_MODE (inner0), xor_optab, inner0, const1_rtx,
13772 : : NULL_RTX, 1, OPTAB_LIB_WIDEN);
13773 : 10779 : if (GET_MODE (inner0) != mode)
13774 : : {
13775 : 0 : rtx t = gen_reg_rtx (mode);
13776 : 0 : convert_move (t, inner0, 0);
13777 : 0 : return t;
13778 : : }
13779 : : return inner0;
13780 : : }
13781 : :
13782 : : /* Generate code to calculate OPS, and exploded expression
13783 : : using a store-flag instruction and return an rtx for the result.
13784 : : OPS reflects a comparison.
13785 : :
13786 : : If TARGET is nonzero, store the result there if convenient.
13787 : :
13788 : : Return zero if there is no suitable set-flag instruction
13789 : : available on this machine.
13790 : :
13791 : : Once expand_expr has been called on the arguments of the comparison,
13792 : : we are committed to doing the store flag, since it is not safe to
13793 : : re-evaluate the expression. We emit the store-flag insn by calling
13794 : : emit_store_flag, but only expand the arguments if we have a reason
13795 : : to believe that emit_store_flag will be successful. If we think that
13796 : : it will, but it isn't, we have to simulate the store-flag with a
13797 : : set/jump/set sequence. */
13798 : :
13799 : : static rtx
13800 : 546476 : do_store_flag (const_sepops ops, rtx target, machine_mode mode)
13801 : : {
13802 : 546476 : enum rtx_code code;
13803 : 546476 : tree arg0, arg1, type;
13804 : 546476 : machine_mode operand_mode;
13805 : 546476 : int unsignedp;
13806 : 546476 : rtx op0, op1;
13807 : 546476 : rtx subtarget = target;
13808 : 546476 : location_t loc = ops->location;
13809 : 546476 : unsigned HOST_WIDE_INT nunits;
13810 : :
13811 : 546476 : arg0 = ops->op0;
13812 : 546476 : arg1 = ops->op1;
13813 : :
13814 : : /* Don't crash if the comparison was erroneous. */
13815 : 546476 : if (arg0 == error_mark_node || arg1 == error_mark_node)
13816 : 0 : return const0_rtx;
13817 : :
13818 : 546476 : type = TREE_TYPE (arg0);
13819 : 546476 : operand_mode = TYPE_MODE (type);
13820 : 546476 : unsignedp = TYPE_UNSIGNED (type);
13821 : :
13822 : : /* We won't bother with BLKmode store-flag operations because it would mean
13823 : : passing a lot of information to emit_store_flag. */
13824 : 546476 : if (operand_mode == BLKmode)
13825 : : return 0;
13826 : :
13827 : : /* We won't bother with store-flag operations involving function pointers
13828 : : when function pointers must be canonicalized before comparisons. */
13829 : 546476 : if (targetm.have_canonicalize_funcptr_for_compare ()
13830 : 546476 : && ((POINTER_TYPE_P (TREE_TYPE (arg0))
13831 : 0 : && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (arg0))))
13832 : 0 : || (POINTER_TYPE_P (TREE_TYPE (arg1))
13833 : 0 : && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (arg1))))))
13834 : : return 0;
13835 : :
13836 : 546476 : STRIP_NOPS (arg0);
13837 : 546476 : STRIP_NOPS (arg1);
13838 : :
13839 : : /* For vector typed comparisons emit code to generate the desired
13840 : : all-ones or all-zeros mask. */
13841 : 546476 : if (VECTOR_TYPE_P (ops->type))
13842 : : {
13843 : 22938 : tree ifexp = build2 (ops->code, ops->type, arg0, arg1);
13844 : 22938 : if (VECTOR_BOOLEAN_TYPE_P (ops->type)
13845 : 45876 : && expand_vec_cmp_expr_p (TREE_TYPE (arg0), ops->type, ops->code))
13846 : 22938 : return expand_vec_cmp_expr (ops->type, ifexp, target);
13847 : : else
13848 : 0 : gcc_unreachable ();
13849 : : }
13850 : :
13851 : : /* Optimize (x % C1) == C2 or (x % C1) != C2 if it is beneficial
13852 : : into (x - C2) * C3 < C4. */
13853 : 523538 : if ((ops->code == EQ_EXPR || ops->code == NE_EXPR)
13854 : 324052 : && TREE_CODE (arg0) == SSA_NAME
13855 : 323528 : && TREE_CODE (arg1) == INTEGER_CST)
13856 : : {
13857 : 191076 : enum tree_code new_code = maybe_optimize_mod_cmp (ops->code,
13858 : : &arg0, &arg1);
13859 : 191076 : if (new_code != ops->code)
13860 : : {
13861 : 86 : struct separate_ops nops = *ops;
13862 : 86 : nops.code = new_code;
13863 : 86 : nops.op0 = arg0;
13864 : 86 : nops.op1 = arg1;
13865 : 86 : nops.type = TREE_TYPE (arg0);
13866 : 86 : return do_store_flag (&nops, target, mode);
13867 : : }
13868 : : }
13869 : :
13870 : : /* Optimize (x - y) < 0 into x < y if x - y has undefined overflow. */
13871 : 523452 : if (!unsignedp
13872 : 342358 : && (ops->code == LT_EXPR || ops->code == LE_EXPR
13873 : 342358 : || ops->code == GT_EXPR || ops->code == GE_EXPR)
13874 : 123683 : && integer_zerop (arg1)
13875 : 562365 : && TREE_CODE (arg0) == SSA_NAME)
13876 : 38909 : maybe_optimize_sub_cmp_0 (ops->code, &arg0, &arg1);
13877 : :
13878 : : /* Get the rtx comparison code to use. We know that EXP is a comparison
13879 : : operation of some type. Some comparisons against 1 and -1 can be
13880 : : converted to comparisons with zero. Do so here so that the tests
13881 : : below will be aware that we have a comparison with zero. These
13882 : : tests will not catch constants in the first operand, but constants
13883 : : are rarely passed as the first operand. */
13884 : :
13885 : 523452 : switch (ops->code)
13886 : : {
13887 : : case EQ_EXPR:
13888 : : code = EQ;
13889 : : break;
13890 : 197152 : case NE_EXPR:
13891 : 197152 : code = NE;
13892 : 197152 : break;
13893 : 39931 : case LT_EXPR:
13894 : 39931 : if (integer_onep (arg1))
13895 : 0 : arg1 = integer_zero_node, code = unsignedp ? LEU : LE;
13896 : : else
13897 : 39931 : code = unsignedp ? LTU : LT;
13898 : : break;
13899 : 35651 : case LE_EXPR:
13900 : 35651 : if (! unsignedp && integer_all_onesp (arg1))
13901 : 0 : arg1 = integer_zero_node, code = LT;
13902 : : else
13903 : 35651 : code = unsignedp ? LEU : LE;
13904 : : break;
13905 : 54564 : case GT_EXPR:
13906 : 54564 : if (! unsignedp && integer_all_onesp (arg1))
13907 : 0 : arg1 = integer_zero_node, code = GE;
13908 : : else
13909 : 54564 : code = unsignedp ? GTU : GT;
13910 : : break;
13911 : 45860 : case GE_EXPR:
13912 : 45860 : if (integer_onep (arg1))
13913 : 29221 : arg1 = integer_zero_node, code = unsignedp ? GTU : GT;
13914 : : else
13915 : 45860 : code = unsignedp ? GEU : GE;
13916 : : break;
13917 : :
13918 : 674 : case UNORDERED_EXPR:
13919 : 674 : code = UNORDERED;
13920 : 674 : break;
13921 : 678 : case ORDERED_EXPR:
13922 : 678 : code = ORDERED;
13923 : 678 : break;
13924 : 482 : case UNLT_EXPR:
13925 : 482 : code = UNLT;
13926 : 482 : break;
13927 : 10782 : case UNLE_EXPR:
13928 : 10782 : code = UNLE;
13929 : 10782 : break;
13930 : 825 : case UNGT_EXPR:
13931 : 825 : code = UNGT;
13932 : 825 : break;
13933 : 9818 : case UNGE_EXPR:
13934 : 9818 : code = UNGE;
13935 : 9818 : break;
13936 : 141 : case UNEQ_EXPR:
13937 : 141 : code = UNEQ;
13938 : 141 : break;
13939 : 80 : case LTGT_EXPR:
13940 : 80 : code = LTGT;
13941 : 80 : break;
13942 : :
13943 : 0 : default:
13944 : 0 : gcc_unreachable ();
13945 : : }
13946 : :
13947 : : /* Put a constant second. */
13948 : 523452 : if (TREE_CODE (arg0) == REAL_CST || TREE_CODE (arg0) == INTEGER_CST
13949 : 521973 : || TREE_CODE (arg0) == FIXED_CST)
13950 : : {
13951 : 1479 : std::swap (arg0, arg1);
13952 : 1479 : code = swap_condition (code);
13953 : : }
13954 : :
13955 : : /* If this is an equality or inequality test of a single bit, we can
13956 : : do this by shifting the bit being tested to the low-order bit and
13957 : : masking the result with the constant 1. If the condition was EQ,
13958 : : we xor it with 1. This does not require an scc insn and is faster
13959 : : than an scc insn even if we have it. */
13960 : :
13961 : 523452 : if ((code == NE || code == EQ)
13962 : 323966 : && (integer_zerop (arg1)
13963 : 204971 : || integer_pow2p (arg1))
13964 : : /* vector types are not handled here. */
13965 : 149177 : && TREE_CODE (TREE_TYPE (arg1)) != VECTOR_TYPE
13966 : 672619 : && (TYPE_PRECISION (ops->type) != 1 || TYPE_UNSIGNED (ops->type)))
13967 : : {
13968 : 149167 : tree narg0 = arg0;
13969 : 149167 : wide_int nz = tree_nonzero_bits (narg0);
13970 : 149167 : gimple *srcstmt = get_def_for_expr (narg0, BIT_AND_EXPR);
13971 : : /* If the defining statement was (x & POW2), then use that instead of
13972 : : the non-zero bits. */
13973 : 149167 : if (srcstmt && integer_pow2p (gimple_assign_rhs2 (srcstmt)))
13974 : : {
13975 : 6538 : nz = wi::to_wide (gimple_assign_rhs2 (srcstmt));
13976 : 6538 : narg0 = gimple_assign_rhs1 (srcstmt);
13977 : : }
13978 : :
13979 : 149167 : if (wi::popcount (nz) == 1
13980 : 149167 : && (integer_zerop (arg1)
13981 : 138196 : || wi::to_wide (arg1) == nz))
13982 : : {
13983 : 11010 : int bitnum = wi::exact_log2 (nz);
13984 : 11010 : enum tree_code tcode = EQ_EXPR;
13985 : 11010 : if ((code == NE) ^ !integer_zerop (arg1))
13986 : 7063 : tcode = NE_EXPR;
13987 : :
13988 : 11010 : type = lang_hooks.types.type_for_mode (mode, unsignedp);
13989 : 11010 : return expand_single_bit_test (loc, tcode,
13990 : : narg0,
13991 : : bitnum, type, target, mode);
13992 : : }
13993 : 149167 : }
13994 : :
13995 : :
13996 : 512442 : if (! get_subtarget (target)
13997 : 512442 : || GET_MODE (subtarget) != operand_mode)
13998 : : subtarget = 0;
13999 : :
14000 : 512442 : expand_operands (arg0, arg1, subtarget, &op0, &op1, EXPAND_NORMAL);
14001 : :
14002 : : /* For boolean vectors with less than mode precision
14003 : : make sure to fill padding with consistent values. */
14004 : 10 : if (VECTOR_BOOLEAN_TYPE_P (type)
14005 : 0 : && SCALAR_INT_MODE_P (operand_mode)
14006 : 512442 : && TYPE_VECTOR_SUBPARTS (type).is_constant (&nunits)
14007 : 512442 : && maybe_ne (GET_MODE_PRECISION (operand_mode), nunits))
14008 : : {
14009 : 0 : gcc_assert (code == EQ || code == NE);
14010 : 0 : op0 = expand_binop (mode, and_optab, op0,
14011 : 0 : GEN_INT ((HOST_WIDE_INT_1U << nunits) - 1),
14012 : : NULL_RTX, true, OPTAB_WIDEN);
14013 : 0 : op1 = expand_binop (mode, and_optab, op1,
14014 : : GEN_INT ((HOST_WIDE_INT_1U << nunits) - 1),
14015 : : NULL_RTX, true, OPTAB_WIDEN);
14016 : : }
14017 : :
14018 : 512442 : if (target == 0)
14019 : 326199 : target = gen_reg_rtx (mode);
14020 : :
14021 : : /* Try a cstore if possible. */
14022 : 512442 : return emit_store_flag_force (target, code, op0, op1,
14023 : : operand_mode, unsignedp,
14024 : 512442 : (TYPE_PRECISION (ops->type) == 1
14025 : 1024260 : && !TYPE_UNSIGNED (ops->type)) ? -1 : 1);
14026 : : }
14027 : :
14028 : : /* Attempt to generate a casesi instruction. Returns true if successful,
14029 : : false otherwise (i.e. if there is no casesi instruction).
14030 : :
14031 : : DEFAULT_PROBABILITY is the probability of jumping to the default
14032 : : label. */
14033 : : bool
14034 : 9961 : try_casesi (tree index_type, tree index_expr, tree minval, tree range,
14035 : : rtx table_label, rtx default_label, rtx fallback_label,
14036 : : profile_probability default_probability)
14037 : : {
14038 : 9961 : class expand_operand ops[5];
14039 : 9961 : scalar_int_mode index_mode = SImode;
14040 : 9961 : rtx op1, op2, index;
14041 : :
14042 : 9961 : if (! targetm.have_casesi ())
14043 : : return false;
14044 : :
14045 : : /* The index must be some form of integer. Convert it to SImode. */
14046 : 0 : scalar_int_mode omode = SCALAR_INT_TYPE_MODE (index_type);
14047 : 0 : if (GET_MODE_BITSIZE (omode) > GET_MODE_BITSIZE (index_mode))
14048 : : {
14049 : 0 : rtx rangertx = expand_normal (range);
14050 : :
14051 : : /* We must handle the endpoints in the original mode. */
14052 : 0 : index_expr = build2 (MINUS_EXPR, index_type,
14053 : : index_expr, minval);
14054 : 0 : minval = integer_zero_node;
14055 : 0 : index = expand_normal (index_expr);
14056 : 0 : if (default_label)
14057 : 0 : emit_cmp_and_jump_insns (rangertx, index, LTU, NULL_RTX,
14058 : : omode, 1, default_label,
14059 : : default_probability);
14060 : : /* Now we can safely truncate. */
14061 : 0 : index = convert_to_mode (index_mode, index, 0);
14062 : : }
14063 : : else
14064 : : {
14065 : 0 : if (omode != index_mode)
14066 : : {
14067 : 0 : index_type = lang_hooks.types.type_for_mode (index_mode, 0);
14068 : 0 : index_expr = fold_convert (index_type, index_expr);
14069 : : }
14070 : :
14071 : 0 : index = expand_normal (index_expr);
14072 : : }
14073 : :
14074 : 0 : do_pending_stack_adjust ();
14075 : :
14076 : 0 : op1 = expand_normal (minval);
14077 : 0 : op2 = expand_normal (range);
14078 : :
14079 : 0 : create_input_operand (&ops[0], index, index_mode);
14080 : 0 : create_convert_operand_from_type (&ops[1], op1, TREE_TYPE (minval));
14081 : 0 : create_convert_operand_from_type (&ops[2], op2, TREE_TYPE (range));
14082 : 0 : create_fixed_operand (&ops[3], table_label);
14083 : 0 : create_fixed_operand (&ops[4], (default_label
14084 : : ? default_label
14085 : : : fallback_label));
14086 : 0 : expand_jump_insn (targetm.code_for_casesi, 5, ops);
14087 : 0 : return true;
14088 : : }
14089 : :
14090 : : /* Attempt to generate a tablejump instruction; same concept. */
14091 : : /* Subroutine of the next function.
14092 : :
14093 : : INDEX is the value being switched on, with the lowest value
14094 : : in the table already subtracted.
14095 : : MODE is its expected mode (needed if INDEX is constant).
14096 : : RANGE is the length of the jump table.
14097 : : TABLE_LABEL is a CODE_LABEL rtx for the table itself.
14098 : :
14099 : : DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
14100 : : index value is out of range.
14101 : : DEFAULT_PROBABILITY is the probability of jumping to
14102 : : the default label. */
14103 : :
14104 : : static void
14105 : 9961 : do_tablejump (rtx index, machine_mode mode, rtx range, rtx table_label,
14106 : : rtx default_label, profile_probability default_probability)
14107 : : {
14108 : 9961 : rtx temp, vector;
14109 : :
14110 : 9961 : if (INTVAL (range) > cfun->cfg->max_jumptable_ents)
14111 : 7584 : cfun->cfg->max_jumptable_ents = INTVAL (range);
14112 : :
14113 : : /* Do an unsigned comparison (in the proper mode) between the index
14114 : : expression and the value which represents the length of the range.
14115 : : Since we just finished subtracting the lower bound of the range
14116 : : from the index expression, this comparison allows us to simultaneously
14117 : : check that the original index expression value is both greater than
14118 : : or equal to the minimum value of the range and less than or equal to
14119 : : the maximum value of the range. */
14120 : :
14121 : 9961 : if (default_label)
14122 : 5154 : emit_cmp_and_jump_insns (index, range, GTU, NULL_RTX, mode, 1,
14123 : : default_label, default_probability);
14124 : :
14125 : : /* If index is in range, it must fit in Pmode.
14126 : : Convert to Pmode so we can index with it. */
14127 : 10929 : if (mode != Pmode)
14128 : : {
14129 : 8969 : unsigned int width;
14130 : :
14131 : : /* We know the value of INDEX is between 0 and RANGE. If we have a
14132 : : sign-extended subreg, and RANGE does not have the sign bit set, then
14133 : : we have a value that is valid for both sign and zero extension. In
14134 : : this case, we get better code if we sign extend. */
14135 : 8969 : if (GET_CODE (index) == SUBREG
14136 : 9 : && SUBREG_PROMOTED_VAR_P (index)
14137 : 0 : && SUBREG_PROMOTED_SIGNED_P (index)
14138 : 0 : && ((width = GET_MODE_PRECISION (as_a <scalar_int_mode> (mode)))
14139 : : <= HOST_BITS_PER_WIDE_INT)
14140 : 8969 : && ! (UINTVAL (range) & (HOST_WIDE_INT_1U << (width - 1))))
14141 : 0 : index = convert_to_mode (Pmode, index, 0);
14142 : : else
14143 : 8969 : index = convert_to_mode (Pmode, index, 1);
14144 : : }
14145 : :
14146 : : /* Don't let a MEM slip through, because then INDEX that comes
14147 : : out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
14148 : : and break_out_memory_refs will go to work on it and mess it up. */
14149 : : #ifdef PIC_CASE_VECTOR_ADDRESS
14150 : : if (flag_pic && !REG_P (index))
14151 : : index = copy_to_mode_reg (Pmode, index);
14152 : : #endif
14153 : :
14154 : : /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
14155 : : GET_MODE_SIZE, because this indicates how large insns are. The other
14156 : : uses should all be Pmode, because they are addresses. This code
14157 : : could fail if addresses and insns are not the same size. */
14158 : 10929 : index = simplify_gen_binary (MULT, Pmode, index,
14159 : 19922 : gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE),
14160 : 9961 : Pmode));
14161 : 10929 : index = simplify_gen_binary (PLUS, Pmode, index,
14162 : 9961 : gen_rtx_LABEL_REF (Pmode, table_label));
14163 : :
14164 : : #ifdef PIC_CASE_VECTOR_ADDRESS
14165 : : if (flag_pic)
14166 : : index = PIC_CASE_VECTOR_ADDRESS (index);
14167 : : else
14168 : : #endif
14169 : 11431 : index = memory_address (CASE_VECTOR_MODE, index);
14170 : 11431 : temp = gen_reg_rtx (CASE_VECTOR_MODE);
14171 : 11431 : vector = gen_const_mem (CASE_VECTOR_MODE, index);
14172 : 9961 : convert_move (temp, vector, 0);
14173 : :
14174 : 9961 : emit_jump_insn (targetm.gen_tablejump (temp, table_label));
14175 : :
14176 : : /* If we are generating PIC code or if the table is PC-relative, the
14177 : : table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
14178 : 9961 : if (! CASE_VECTOR_PC_RELATIVE && ! flag_pic)
14179 : 8989 : emit_barrier ();
14180 : 9961 : }
14181 : :
14182 : : bool
14183 : 9961 : try_tablejump (tree index_type, tree index_expr, tree minval, tree range,
14184 : : rtx table_label, rtx default_label,
14185 : : profile_probability default_probability)
14186 : : {
14187 : 9961 : rtx index;
14188 : :
14189 : 9961 : if (! targetm.have_tablejump ())
14190 : : return false;
14191 : :
14192 : 9961 : index_expr = fold_build2 (MINUS_EXPR, index_type,
14193 : : fold_convert (index_type, index_expr),
14194 : : fold_convert (index_type, minval));
14195 : 9961 : index = expand_normal (index_expr);
14196 : 9961 : do_pending_stack_adjust ();
14197 : :
14198 : 9961 : do_tablejump (index, TYPE_MODE (index_type),
14199 : 9961 : convert_modes (TYPE_MODE (index_type),
14200 : 9961 : TYPE_MODE (TREE_TYPE (range)),
14201 : : expand_normal (range),
14202 : 9961 : TYPE_UNSIGNED (TREE_TYPE (range))),
14203 : : table_label, default_label, default_probability);
14204 : 9961 : return true;
14205 : : }
14206 : :
14207 : : /* Return a CONST_VECTOR rtx representing vector mask for
14208 : : a VECTOR_CST of booleans. */
14209 : : static rtx
14210 : 721 : const_vector_mask_from_tree (tree exp)
14211 : : {
14212 : 721 : machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
14213 : 721 : machine_mode inner = GET_MODE_INNER (mode);
14214 : :
14215 : 721 : rtx_vector_builder builder (mode, VECTOR_CST_NPATTERNS (exp),
14216 : 721 : VECTOR_CST_NELTS_PER_PATTERN (exp));
14217 : 721 : unsigned int count = builder.encoded_nelts ();
14218 : 3772 : for (unsigned int i = 0; i < count; ++i)
14219 : : {
14220 : 3051 : tree elt = VECTOR_CST_ELT (exp, i);
14221 : 3051 : gcc_assert (TREE_CODE (elt) == INTEGER_CST);
14222 : 3051 : if (integer_zerop (elt))
14223 : 1207 : builder.quick_push (CONST0_RTX (inner));
14224 : 1844 : else if (integer_onep (elt)
14225 : 1844 : || integer_minus_onep (elt))
14226 : 1844 : builder.quick_push (CONSTM1_RTX (inner));
14227 : : else
14228 : 0 : gcc_unreachable ();
14229 : : }
14230 : 721 : return builder.build ();
14231 : 721 : }
14232 : :
14233 : : /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
14234 : : static rtx
14235 : 556456 : const_vector_from_tree (tree exp)
14236 : : {
14237 : 556456 : machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
14238 : :
14239 : 556456 : if (initializer_zerop (exp))
14240 : 165490 : return CONST0_RTX (mode);
14241 : :
14242 : 390966 : if (VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (exp)))
14243 : 721 : return const_vector_mask_from_tree (exp);
14244 : :
14245 : 390245 : machine_mode inner = GET_MODE_INNER (mode);
14246 : :
14247 : 390245 : rtx_vector_builder builder (mode, VECTOR_CST_NPATTERNS (exp),
14248 : 390245 : VECTOR_CST_NELTS_PER_PATTERN (exp));
14249 : 390245 : unsigned int count = builder.encoded_nelts ();
14250 : 1267804 : for (unsigned int i = 0; i < count; ++i)
14251 : : {
14252 : 877559 : tree elt = VECTOR_CST_ELT (exp, i);
14253 : 877559 : if (TREE_CODE (elt) == REAL_CST)
14254 : 141361 : builder.quick_push (const_double_from_real_value (TREE_REAL_CST (elt),
14255 : : inner));
14256 : 736198 : else if (TREE_CODE (elt) == FIXED_CST)
14257 : 0 : builder.quick_push (CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt),
14258 : : inner));
14259 : : else
14260 : 736198 : builder.quick_push (immed_wide_int_const (wi::to_poly_wide (elt),
14261 : : inner));
14262 : : }
14263 : 390245 : return builder.build ();
14264 : 390245 : }
14265 : :
14266 : : /* Build a decl for a personality function given a language prefix. */
14267 : :
14268 : : tree
14269 : 32171 : build_personality_function (const char *lang)
14270 : : {
14271 : 32171 : const char *unwind_and_version;
14272 : 32171 : tree decl, type;
14273 : 32171 : char *name;
14274 : :
14275 : 32171 : switch (targetm_common.except_unwind_info (&global_options))
14276 : : {
14277 : : case UI_NONE:
14278 : : return NULL;
14279 : : case UI_SJLJ:
14280 : : unwind_and_version = "_sj0";
14281 : : break;
14282 : 32171 : case UI_DWARF2:
14283 : 32171 : case UI_TARGET:
14284 : 32171 : unwind_and_version = "_v0";
14285 : 32171 : break;
14286 : 0 : case UI_SEH:
14287 : 0 : unwind_and_version = "_seh0";
14288 : 0 : break;
14289 : 0 : default:
14290 : 0 : gcc_unreachable ();
14291 : : }
14292 : :
14293 : 32171 : name = ACONCAT (("__", lang, "_personality", unwind_and_version, NULL));
14294 : :
14295 : 32171 : type = build_function_type_list (unsigned_type_node,
14296 : : integer_type_node, integer_type_node,
14297 : : long_long_unsigned_type_node,
14298 : : ptr_type_node, ptr_type_node, NULL_TREE);
14299 : 32171 : decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
14300 : : get_identifier (name), type);
14301 : 32171 : DECL_ARTIFICIAL (decl) = 1;
14302 : 32171 : DECL_EXTERNAL (decl) = 1;
14303 : 32171 : TREE_PUBLIC (decl) = 1;
14304 : :
14305 : : /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
14306 : : are the flags assigned by targetm.encode_section_info. */
14307 : 32171 : SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl), 0), NULL);
14308 : :
14309 : 32171 : return decl;
14310 : : }
14311 : :
14312 : : /* Extracts the personality function of DECL and returns the corresponding
14313 : : libfunc. */
14314 : :
14315 : : rtx
14316 : 1617852 : get_personality_function (tree decl)
14317 : : {
14318 : 1617852 : tree personality = DECL_FUNCTION_PERSONALITY (decl);
14319 : 1617852 : enum eh_personality_kind pk;
14320 : :
14321 : 1617852 : pk = function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl));
14322 : 1617852 : if (pk == eh_personality_none)
14323 : : return NULL;
14324 : :
14325 : 157674 : if (!personality
14326 : 157674 : && pk == eh_personality_any)
14327 : 72726 : personality = lang_hooks.eh_personality ();
14328 : :
14329 : 157674 : if (pk == eh_personality_lang)
14330 : 84948 : gcc_assert (personality != NULL_TREE);
14331 : :
14332 : 157674 : return XEXP (DECL_RTL (personality), 0);
14333 : : }
14334 : :
14335 : : /* Returns a tree for the size of EXP in bytes. */
14336 : :
14337 : : static tree
14338 : 14619926 : tree_expr_size (const_tree exp)
14339 : : {
14340 : 14619926 : if (DECL_P (exp)
14341 : 14619926 : && DECL_SIZE_UNIT (exp) != 0)
14342 : 1957041 : return DECL_SIZE_UNIT (exp);
14343 : : else
14344 : 12662885 : return size_in_bytes (TREE_TYPE (exp));
14345 : : }
14346 : :
14347 : : /* Return an rtx for the size in bytes of the value of EXP. */
14348 : :
14349 : : rtx
14350 : 14425978 : expr_size (tree exp)
14351 : : {
14352 : 14425978 : tree size;
14353 : :
14354 : 14425978 : if (TREE_CODE (exp) == WITH_SIZE_EXPR)
14355 : 773 : size = TREE_OPERAND (exp, 1);
14356 : : else
14357 : : {
14358 : 14425205 : size = tree_expr_size (exp);
14359 : 14425205 : gcc_assert (size);
14360 : 14425205 : gcc_assert (size == SUBSTITUTE_PLACEHOLDER_IN_EXPR (size, exp));
14361 : : }
14362 : :
14363 : 14425978 : return expand_expr (size, NULL_RTX, TYPE_MODE (sizetype), EXPAND_NORMAL);
14364 : : }
14365 : :
14366 : : /* Return a wide integer for the size in bytes of the value of EXP, or -1
14367 : : if the size can vary or is larger than an integer. */
14368 : :
14369 : : HOST_WIDE_INT
14370 : 194721 : int_expr_size (const_tree exp)
14371 : : {
14372 : 194721 : tree size;
14373 : :
14374 : 194721 : if (TREE_CODE (exp) == WITH_SIZE_EXPR)
14375 : 0 : size = TREE_OPERAND (exp, 1);
14376 : : else
14377 : : {
14378 : 194721 : size = tree_expr_size (exp);
14379 : 194721 : gcc_assert (size);
14380 : : }
14381 : :
14382 : 194721 : if (size == 0 || !tree_fits_shwi_p (size))
14383 : 0 : return -1;
14384 : :
14385 : 194721 : return tree_to_shwi (size);
14386 : : }
14387 : :
14388 : : /* Return the quotient of polynomial long division of x^2N by POLYNOMIAL
14389 : : in GF (2^N).
14390 : : Author: Richard Sandiford <richard.sandiford@arm.com> */
14391 : :
14392 : : unsigned HOST_WIDE_INT
14393 : 0 : gf2n_poly_long_div_quotient (unsigned HOST_WIDE_INT polynomial,
14394 : : unsigned short n)
14395 : : {
14396 : : /* The result has degree N, so needs N + 1 bits. */
14397 : 0 : gcc_assert (n < 64);
14398 : :
14399 : : /* Perform a division step for the x^2N coefficient. At this point the
14400 : : quotient and remainder have N implicit trailing zeros. */
14401 : : unsigned HOST_WIDE_INT quotient = 1;
14402 : : unsigned HOST_WIDE_INT remainder = polynomial;
14403 : :
14404 : : /* Process the coefficients for x^(2N-1) down to x^N, with each step
14405 : : reducing the number of implicit trailing zeros by one. */
14406 : 0 : for (unsigned int i = 0; i < n; ++i)
14407 : : {
14408 : 0 : bool coeff = remainder & (HOST_WIDE_INT_1U << (n - 1));
14409 : 0 : quotient = (quotient << 1) | coeff;
14410 : 0 : remainder = (remainder << 1) ^ (coeff ? polynomial : 0);
14411 : : }
14412 : 0 : return quotient;
14413 : : }
14414 : :
14415 : : /* Calculate CRC for the initial CRC and given POLYNOMIAL.
14416 : : CRC_BITS is CRC size. */
14417 : :
14418 : : static unsigned HOST_WIDE_INT
14419 : 69376 : calculate_crc (unsigned HOST_WIDE_INT crc,
14420 : : unsigned HOST_WIDE_INT polynomial,
14421 : : unsigned short crc_bits)
14422 : : {
14423 : 69376 : unsigned HOST_WIDE_INT msb = HOST_WIDE_INT_1U << (crc_bits - 1);
14424 : 69376 : crc = crc << (crc_bits - 8);
14425 : 624384 : for (short i = 8; i > 0; --i)
14426 : : {
14427 : 555008 : if (crc & msb)
14428 : 277504 : crc = (crc << 1) ^ polynomial;
14429 : : else
14430 : 277504 : crc <<= 1;
14431 : : }
14432 : : /* Zero out bits in crc beyond the specified number of crc_bits. */
14433 : 69376 : if (crc_bits < sizeof (crc) * CHAR_BIT)
14434 : 60928 : crc &= (HOST_WIDE_INT_1U << crc_bits) - 1;
14435 : 69376 : return crc;
14436 : : }
14437 : :
14438 : : /* Assemble CRC table with 256 elements for the given POLYNOM and CRC_BITS.
14439 : : POLYNOM is the polynomial used to calculate the CRC table's elements.
14440 : : CRC_BITS is the size of CRC, may be 8, 16, ... . */
14441 : :
14442 : : static rtx
14443 : 271 : assemble_crc_table (unsigned HOST_WIDE_INT polynom, unsigned short crc_bits)
14444 : : {
14445 : 271 : unsigned table_el_n = 0x100;
14446 : 271 : tree ar = build_array_type (make_unsigned_type (crc_bits),
14447 : 271 : build_index_type (size_int (table_el_n - 1)));
14448 : :
14449 : : /* Initialize the table. */
14450 : 271 : vec<tree, va_gc> *initial_values;
14451 : 271 : vec_alloc (initial_values, table_el_n);
14452 : 69647 : for (size_t i = 0; i < table_el_n; ++i)
14453 : : {
14454 : 69376 : unsigned HOST_WIDE_INT crc = calculate_crc (i, polynom, crc_bits);
14455 : 69376 : tree element = build_int_cstu (make_unsigned_type (crc_bits), crc);
14456 : 69376 : vec_safe_push (initial_values, element);
14457 : : }
14458 : 271 : tree ctor = build_constructor_from_vec (ar, initial_values);
14459 : 271 : rtx mem = output_constant_def (ctor, 1);
14460 : 271 : gcc_assert (MEM_P (mem));
14461 : 271 : if (dump_file && (dump_flags & TDF_DETAILS))
14462 : : {
14463 : 32 : fprintf (dump_file,
14464 : : ";; emitting crc table crc_%u_polynomial_"
14465 : : HOST_WIDE_INT_PRINT_HEX " ",
14466 : : crc_bits, polynom);
14467 : 32 : print_rtl_single (dump_file, XEXP (mem, 0));
14468 : 32 : fprintf (dump_file, "\n");
14469 : : }
14470 : :
14471 : 271 : return XEXP (mem, 0);
14472 : : }
14473 : :
14474 : : /* Generate CRC lookup table by calculating CRC for all possible
14475 : : 8-bit data values. The table is stored with a specific name in the read-only
14476 : : static data section.
14477 : : POLYNOM is the polynomial used to calculate the CRC table's elements.
14478 : : CRC_BITS is the size of CRC, may be 8, 16, ... . */
14479 : :
14480 : : static rtx
14481 : 271 : generate_crc_table (unsigned HOST_WIDE_INT polynom, unsigned short crc_bits)
14482 : : {
14483 : 271 : gcc_assert (crc_bits <= 64);
14484 : :
14485 : 271 : return assemble_crc_table (polynom, crc_bits);
14486 : : }
14487 : :
14488 : : /* Generate table-based CRC code for the given CRC, INPUT_DATA and the
14489 : : POLYNOMIAL (without leading 1).
14490 : :
14491 : : First, using POLYNOMIAL's value generates CRC table of 256 elements,
14492 : : then generates the assembly for the following code,
14493 : : where crc_bit_size and data_bit_size may be 8, 16, 32, 64, depending on CRC:
14494 : :
14495 : : for (int i = 0; i < data_bit_size / 8; i++)
14496 : : crc = (crc << 8) ^ crc_table[(crc >> (crc_bit_size - 8))
14497 : : ^ (data >> (data_bit_size - (i + 1) * 8)
14498 : : & 0xFF))];
14499 : :
14500 : : So to take values from the table, we need 8-bit data.
14501 : : If input data size is not 8, then first we extract upper 8 bits,
14502 : : then the other 8 bits, and so on. */
14503 : :
14504 : : static void
14505 : 271 : calculate_table_based_CRC (rtx *crc, const rtx &input_data,
14506 : : const rtx &polynomial,
14507 : : machine_mode data_mode)
14508 : : {
14509 : 271 : machine_mode mode = GET_MODE (*crc);
14510 : 271 : unsigned short crc_bit_size = GET_MODE_BITSIZE (mode).to_constant ();
14511 : 271 : unsigned short data_size = GET_MODE_SIZE (data_mode).to_constant ();
14512 : 271 : rtx tab = generate_crc_table (UINTVAL (polynomial), crc_bit_size);
14513 : :
14514 : 742 : for (unsigned short i = 0; i < data_size; i++)
14515 : : {
14516 : : /* crc >> (crc_bit_size - 8). */
14517 : 471 : *crc = force_reg (mode, *crc);
14518 : 471 : rtx op1 = expand_shift (RSHIFT_EXPR, mode, *crc, crc_bit_size - 8,
14519 : : NULL_RTX, 1);
14520 : :
14521 : : /* data >> (8 * (GET_MODE_SIZE (data_mode).to_constant () - i - 1)). */
14522 : 471 : unsigned range_8 = 8 * (data_size - i - 1);
14523 : : /* CRC's mode is always at least as wide as INPUT_DATA. Convert
14524 : : INPUT_DATA into CRC's mode. */
14525 : 471 : rtx data = gen_reg_rtx (mode);
14526 : 471 : convert_move (data, input_data, 1);
14527 : 471 : data = expand_shift (RSHIFT_EXPR, mode, data, range_8, NULL_RTX, 1);
14528 : :
14529 : : /* data >> (8 * (GET_MODE_SIZE (mode)
14530 : : .to_constant () - i - 1)) & 0xFF. */
14531 : 471 : rtx data_final = expand_and (mode, data,
14532 : : gen_int_mode (255, mode), NULL_RTX);
14533 : :
14534 : : /* (crc >> (crc_bit_size - 8)) ^ data_8bit. */
14535 : 471 : rtx in = expand_binop (mode, xor_optab, op1, data_final,
14536 : : NULL_RTX, 1, OPTAB_WIDEN);
14537 : :
14538 : : /* ((crc >> (crc_bit_size - 8)) ^ data_8bit) & 0xFF. */
14539 : 471 : rtx index = expand_and (mode, in, gen_int_mode (255, mode),
14540 : : NULL_RTX);
14541 : 942 : int log_crc_size = exact_log2 (GET_MODE_SIZE (mode).to_constant ());
14542 : 471 : index = expand_shift (LSHIFT_EXPR, mode, index,
14543 : 471 : log_crc_size, NULL_RTX, 0);
14544 : :
14545 : 489 : rtx addr = gen_reg_rtx (Pmode);
14546 : 471 : convert_move (addr, index, 1);
14547 : 489 : addr = expand_binop (Pmode, add_optab, addr, tab, NULL_RTX,
14548 : : 0, OPTAB_DIRECT);
14549 : :
14550 : : /* crc_table[(crc >> (crc_bit_size - 8)) ^ data_8bit] */
14551 : 471 : rtx tab_el = validize_mem (gen_rtx_MEM (mode, addr));
14552 : :
14553 : : /* (crc << 8) if CRC is larger than 8, otherwise crc = 0. */
14554 : 471 : rtx high = NULL_RTX;
14555 : 471 : if (crc_bit_size != 8)
14556 : 432 : high = expand_shift (LSHIFT_EXPR, mode, *crc, 8, NULL_RTX, 0);
14557 : : else
14558 : 39 : high = gen_int_mode (0, mode);
14559 : :
14560 : : /* crc = (crc << 8)
14561 : : ^ crc_table[(crc >> (crc_bit_size - 8)) ^ data_8bit]; */
14562 : 471 : *crc = expand_binop (mode, xor_optab, tab_el, high, NULL_RTX, 1,
14563 : : OPTAB_WIDEN);
14564 : : }
14565 : 271 : }
14566 : :
14567 : : /* Generate table-based CRC code for the given CRC, INPUT_DATA and the
14568 : : POLYNOMIAL (without leading 1).
14569 : :
14570 : : CRC is OP1, data is OP2 and the polynomial is OP3.
14571 : : This must generate a CRC table and an assembly for the following code,
14572 : : where crc_bit_size and data_bit_size may be 8, 16, 32, 64:
14573 : : uint_crc_bit_size_t
14574 : : crc_crc_bit_size (uint_crc_bit_size_t crc_init,
14575 : : uint_data_bit_size_t data, size_t size)
14576 : : {
14577 : : uint_crc_bit_size_t crc = crc_init;
14578 : : for (int i = 0; i < data_bit_size / 8; i++)
14579 : : crc = (crc << 8) ^ crc_table[(crc >> (crc_bit_size - 8))
14580 : : ^ (data >> (data_bit_size - (i + 1) * 8)
14581 : : & 0xFF))];
14582 : : return crc;
14583 : : } */
14584 : :
14585 : : void
14586 : 134 : expand_crc_table_based (rtx op0, rtx op1, rtx op2, rtx op3,
14587 : : machine_mode data_mode)
14588 : : {
14589 : 134 : gcc_assert (!CONST_INT_P (op0));
14590 : 134 : gcc_assert (CONST_INT_P (op3));
14591 : 134 : machine_mode crc_mode = GET_MODE (op0);
14592 : 134 : rtx crc = gen_reg_rtx (crc_mode);
14593 : 134 : convert_move (crc, op1, 0);
14594 : 134 : calculate_table_based_CRC (&crc, op2, op3, data_mode);
14595 : 134 : convert_move (op0, crc, 0);
14596 : 134 : }
14597 : :
14598 : : /* Generate the common operation for reflecting values:
14599 : : *OP = (*OP & AND1_VALUE) << SHIFT_VAL | (*OP & AND2_VALUE) >> SHIFT_VAL; */
14600 : :
14601 : : void
14602 : 1744 : gen_common_operation_to_reflect (rtx *op,
14603 : : unsigned HOST_WIDE_INT and1_value,
14604 : : unsigned HOST_WIDE_INT and2_value,
14605 : : unsigned shift_val)
14606 : : {
14607 : 1744 : rtx op1 = expand_and (GET_MODE (*op), *op,
14608 : 1744 : gen_int_mode (and1_value, GET_MODE (*op)), NULL_RTX);
14609 : 1744 : op1 = expand_shift (LSHIFT_EXPR, GET_MODE (*op), op1, shift_val, op1, 0);
14610 : 1744 : rtx op2 = expand_and (GET_MODE (*op), *op,
14611 : 1744 : gen_int_mode (and2_value, GET_MODE (*op)), NULL_RTX);
14612 : 1744 : op2 = expand_shift (RSHIFT_EXPR, GET_MODE (*op), op2, shift_val, op2, 1);
14613 : 1744 : *op = expand_binop (GET_MODE (*op), ior_optab, op1,
14614 : : op2, *op, 0, OPTAB_LIB_WIDEN);
14615 : 1744 : }
14616 : :
14617 : : /* Reflect 64-bit value for the 64-bit target. */
14618 : :
14619 : : void
14620 : 47 : reflect_64_bit_value (rtx *op)
14621 : : {
14622 : 47 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x00000000FFFFFFFF),
14623 : : HOST_WIDE_INT_C (0xFFFFFFFF00000000), 32);
14624 : 47 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x0000FFFF0000FFFF),
14625 : : HOST_WIDE_INT_C (0xFFFF0000FFFF0000), 16);
14626 : 47 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x00FF00FF00FF00FF),
14627 : : HOST_WIDE_INT_C (0xFF00FF00FF00FF00), 8);
14628 : 47 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x0F0F0F0F0F0F0F0F),
14629 : : HOST_WIDE_INT_C (0xF0F0F0F0F0F0F0F0), 4);
14630 : 47 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x3333333333333333),
14631 : : HOST_WIDE_INT_C (0xCCCCCCCCCCCCCCCC), 2);
14632 : 47 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x5555555555555555),
14633 : : HOST_WIDE_INT_C (0xAAAAAAAAAAAAAAAA), 1);
14634 : 47 : }
14635 : :
14636 : : /* Reflect 32-bit value for the 32-bit target. */
14637 : :
14638 : : void
14639 : 131 : reflect_32_bit_value (rtx *op)
14640 : : {
14641 : 131 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x0000FFFF),
14642 : : HOST_WIDE_INT_C (0xFFFF0000), 16);
14643 : 131 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x00FF00FF),
14644 : : HOST_WIDE_INT_C (0xFF00FF00), 8);
14645 : 131 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x0F0F0F0F),
14646 : : HOST_WIDE_INT_C (0xF0F0F0F0), 4);
14647 : 131 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x33333333),
14648 : : HOST_WIDE_INT_C (0xCCCCCCCC), 2);
14649 : 131 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x55555555),
14650 : : HOST_WIDE_INT_C (0xAAAAAAAA), 1);
14651 : 131 : }
14652 : :
14653 : : /* Reflect 16-bit value for the 16-bit target. */
14654 : :
14655 : : void
14656 : 108 : reflect_16_bit_value (rtx *op)
14657 : : {
14658 : 108 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x00FF),
14659 : : HOST_WIDE_INT_C (0xFF00), 8);
14660 : 108 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x0F0F),
14661 : : HOST_WIDE_INT_C (0xF0F0), 4);
14662 : 108 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x3333),
14663 : : HOST_WIDE_INT_C (0xCCCC), 2);
14664 : 108 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x5555),
14665 : : HOST_WIDE_INT_C (0xAAAA), 1);
14666 : 108 : }
14667 : :
14668 : : /* Reflect 8-bit value for the 8-bit target. */
14669 : :
14670 : : void
14671 : 125 : reflect_8_bit_value (rtx *op)
14672 : : {
14673 : 125 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x0F),
14674 : : HOST_WIDE_INT_C (0xF0), 4);
14675 : 125 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x33),
14676 : : HOST_WIDE_INT_C (0xCC), 2);
14677 : 125 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x55),
14678 : : HOST_WIDE_INT_C (0xAA), 1);
14679 : 125 : }
14680 : :
14681 : : /* Generate instruction sequence which reflects the value of the OP
14682 : : using shift, and, or operations. OP's mode may be less than word_mode. */
14683 : :
14684 : : void
14685 : 411 : generate_reflecting_code_standard (rtx *op)
14686 : : {
14687 : 1233 : gcc_assert (GET_MODE_BITSIZE (GET_MODE (*op)).to_constant () >= 8
14688 : : && GET_MODE_BITSIZE (GET_MODE (*op)).to_constant () <= 64);
14689 : :
14690 : 822 : if (GET_MODE_BITSIZE (GET_MODE (*op)).to_constant () == 64)
14691 : 47 : reflect_64_bit_value (op);
14692 : 728 : else if (GET_MODE_BITSIZE (GET_MODE (*op)).to_constant () == 32)
14693 : 131 : reflect_32_bit_value (op);
14694 : 466 : else if (GET_MODE_BITSIZE (GET_MODE (*op)).to_constant () == 16)
14695 : 108 : reflect_16_bit_value (op);
14696 : : else
14697 : 125 : reflect_8_bit_value (op);
14698 : 411 : }
14699 : :
14700 : : /* Generate table-based reversed CRC code for the given CRC, INPUT_DATA and
14701 : : the POLYNOMIAL (without leading 1).
14702 : :
14703 : : CRC is OP1, data is OP2 and the polynomial is OP3.
14704 : : This must generate CRC table and assembly for the following code,
14705 : : where crc_bit_size and data_bit_size may be 8, 16, 32, 64:
14706 : : uint_crc_bit_size_t
14707 : : crc_crc_bit_size (uint_crc_bit_size_t crc_init,
14708 : : uint_data_bit_size_t data, size_t size)
14709 : : {
14710 : : reflect (crc_init)
14711 : : uint_crc_bit_size_t crc = crc_init;
14712 : : reflect (data);
14713 : : for (int i = 0; i < data_bit_size / 8; i++)
14714 : : crc = (crc << 8) ^ crc_table[(crc >> (crc_bit_size - 8))
14715 : : ^ (data >> (data_bit_size - (i + 1) * 8) & 0xFF))];
14716 : : reflect (crc);
14717 : : return crc;
14718 : : } */
14719 : :
14720 : : void
14721 : 137 : expand_reversed_crc_table_based (rtx op0, rtx op1, rtx op2, rtx op3,
14722 : : machine_mode data_mode,
14723 : : void (*gen_reflecting_code) (rtx *op))
14724 : : {
14725 : 137 : gcc_assert (!CONST_INT_P (op0));
14726 : 137 : gcc_assert (CONST_INT_P (op3));
14727 : 137 : machine_mode crc_mode = GET_MODE (op0);
14728 : :
14729 : 137 : rtx crc = gen_reg_rtx (crc_mode);
14730 : 137 : convert_move (crc, op1, 0);
14731 : 137 : gen_reflecting_code (&crc);
14732 : :
14733 : 137 : rtx data = gen_reg_rtx (data_mode);
14734 : 137 : convert_move (data, op2, 0);
14735 : 137 : gen_reflecting_code (&data);
14736 : :
14737 : 137 : calculate_table_based_CRC (&crc, data, op3, data_mode);
14738 : :
14739 : 137 : gen_reflecting_code (&crc);
14740 : 137 : convert_move (op0, crc, 0);
14741 : 137 : }
|