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 : 213463 : init_expr_target (void)
119 : : {
120 : 213463 : rtx pat;
121 : 213463 : int num_clobbers;
122 : 213463 : rtx mem, mem1;
123 : 213463 : 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 : 213463 : mem = gen_rtx_MEM (word_mode, stack_pointer_rtx);
129 : 213463 : 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 : 213463 : reg = gen_rtx_REG (word_mode, LAST_VIRTUAL_REGISTER + 1);
134 : :
135 : 213463 : rtx_insn *insn = as_a<rtx_insn *> (rtx_alloc (INSN));
136 : 213463 : pat = gen_rtx_SET (NULL_RTX, NULL_RTX);
137 : 213463 : PATTERN (insn) = pat;
138 : :
139 : 26682875 : for (machine_mode mode = VOIDmode; (int) mode < NUM_MACHINE_MODES;
140 : 26469412 : mode = (machine_mode) ((int) mode + 1))
141 : : {
142 : 26469412 : int regno;
143 : :
144 : 26469412 : direct_load[(int) mode] = direct_store[(int) mode] = 0;
145 : 26469412 : PUT_MODE (mem, mode);
146 : 26469412 : 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 : 26469412 : if (mode != VOIDmode && mode != BLKmode)
152 : 1784301193 : for (regno = 0; regno < FIRST_PSEUDO_REGISTER
153 : 1810343679 : && (direct_load[(int) mode] == 0 || direct_store[(int) mode] == 0);
154 : : regno++)
155 : : {
156 : 1784301193 : if (!targetm.hard_regno_mode_ok (regno, mode))
157 : 1667478853 : continue;
158 : :
159 : 116822340 : set_mode_and_regno (reg, mode, regno);
160 : :
161 : 116822340 : SET_SRC (pat) = mem;
162 : 116822340 : SET_DEST (pat) = reg;
163 : 116822340 : if (recog (pat, insn, &num_clobbers) >= 0)
164 : 7175329 : direct_load[(int) mode] = 1;
165 : :
166 : 116822340 : SET_SRC (pat) = mem1;
167 : 116822340 : SET_DEST (pat) = reg;
168 : 116822340 : if (recog (pat, insn, &num_clobbers) >= 0)
169 : 7175329 : direct_load[(int) mode] = 1;
170 : :
171 : 116822340 : SET_SRC (pat) = reg;
172 : 116822340 : SET_DEST (pat) = mem;
173 : 116822340 : if (recog (pat, insn, &num_clobbers) >= 0)
174 : 7175329 : direct_store[(int) mode] = 1;
175 : :
176 : 116822340 : SET_SRC (pat) = reg;
177 : 116822340 : SET_DEST (pat) = mem1;
178 : 116822340 : if (recog (pat, insn, &num_clobbers) >= 0)
179 : 7175329 : direct_store[(int) mode] = 1;
180 : : }
181 : : }
182 : :
183 : 219124 : mem = gen_rtx_MEM (VOIDmode, gen_raw_REG (Pmode, LAST_VIRTUAL_REGISTER + 1));
184 : :
185 : 213463 : opt_scalar_float_mode mode_iter;
186 : 1494241 : FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_FLOAT)
187 : : {
188 : 1280778 : scalar_float_mode mode = mode_iter.require ();
189 : 1280778 : scalar_float_mode srcmode;
190 : 4482723 : FOR_EACH_MODE_UNTIL (srcmode, mode)
191 : : {
192 : 3201945 : enum insn_code ic;
193 : :
194 : 3201945 : ic = can_extend_p (mode, srcmode, 0);
195 : 3201945 : if (ic == CODE_FOR_nothing)
196 : 2557255 : continue;
197 : :
198 : 644690 : PUT_MODE (mem, srcmode);
199 : :
200 : 644690 : if (insn_operand_matches (ic, 1, mem))
201 : 642600 : float_extend_from_mem[mode][srcmode] = true;
202 : : }
203 : : }
204 : 213463 : }
205 : :
206 : : /* This is run at the start of compiling a function. */
207 : :
208 : : void
209 : 1701086 : init_expr (void)
210 : : {
211 : 1701086 : memset (&crtl->expr, 0, sizeof (crtl->expr));
212 : 1701086 : }
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 : 2072959 : convert_move (rtx to, rtx from, int unsignedp)
222 : : {
223 : 2072959 : machine_mode to_mode = GET_MODE (to);
224 : 2072959 : machine_mode from_mode = GET_MODE (from);
225 : :
226 : 2072959 : gcc_assert (to_mode != BLKmode);
227 : 2072959 : gcc_assert (from_mode != BLKmode);
228 : :
229 : : /* If the source and destination are already the same, then there's
230 : : nothing to do. */
231 : 2072959 : if (to == from)
232 : 2072959 : 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 : 2072959 : scalar_int_mode to_int_mode;
239 : 2072959 : if (GET_CODE (from) == SUBREG
240 : 107262 : && SUBREG_PROMOTED_VAR_P (from)
241 : 2072959 : && is_a <scalar_int_mode> (to_mode, &to_int_mode)
242 : 2072959 : && (GET_MODE_PRECISION (subreg_promoted_mode (from))
243 : 0 : >= GET_MODE_PRECISION (to_int_mode))
244 : 2072959 : && 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 : 2072959 : gcc_assert (GET_CODE (to) != SUBREG || !SUBREG_PROMOTED_VAR_P (to));
270 : :
271 : 2072959 : if (to_mode == from_mode
272 : 2021978 : || (from_mode == VOIDmode && CONSTANT_P (from)))
273 : : {
274 : 51245 : emit_move_insn (to, from);
275 : 51245 : return;
276 : : }
277 : :
278 : 2021714 : if (VECTOR_MODE_P (to_mode) || VECTOR_MODE_P (from_mode))
279 : : {
280 : 28128 : if (GET_MODE_UNIT_PRECISION (to_mode)
281 : 14064 : > GET_MODE_UNIT_PRECISION (from_mode))
282 : : {
283 : 5310 : optab op = unsignedp ? zext_optab : sext_optab;
284 : 5310 : insn_code icode = convert_optab_handler (op, to_mode, from_mode);
285 : 5310 : if (icode != CODE_FOR_nothing)
286 : : {
287 : 476 : emit_unop_insn (icode, to, from,
288 : : unsignedp ? ZERO_EXTEND : SIGN_EXTEND);
289 : 476 : return;
290 : : }
291 : : }
292 : :
293 : 27176 : if (GET_MODE_UNIT_PRECISION (to_mode)
294 : 13588 : < GET_MODE_UNIT_PRECISION (from_mode))
295 : : {
296 : 1742 : insn_code icode = convert_optab_handler (trunc_optab,
297 : : to_mode, from_mode);
298 : 1742 : if (icode != CODE_FOR_nothing)
299 : : {
300 : 811 : emit_unop_insn (icode, to, from, TRUNCATE);
301 : 811 : return;
302 : : }
303 : : }
304 : :
305 : 38331 : gcc_assert (known_eq (GET_MODE_BITSIZE (from_mode),
306 : : GET_MODE_BITSIZE (to_mode)));
307 : :
308 : 12777 : if (VECTOR_MODE_P (to_mode))
309 : 12777 : 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 : 12777 : emit_move_insn (to, from);
314 : 12777 : return;
315 : : }
316 : :
317 : 2007650 : 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 : 2007650 : convert_mode_scalar (to, from, unsignedp);
325 : : }
326 : :
327 : : /* Like convert_move, but deals only with scalar modes. */
328 : :
329 : : static void
330 : 2007694 : convert_mode_scalar (rtx to, rtx from, int unsignedp)
331 : : {
332 : : /* Both modes should be scalar types. */
333 : 2007699 : scalar_mode from_mode = as_a <scalar_mode> (GET_MODE (from));
334 : 2007699 : scalar_mode to_mode = as_a <scalar_mode> (GET_MODE (to));
335 : 2007699 : bool to_real = SCALAR_FLOAT_MODE_P (to_mode);
336 : 2007699 : bool from_real = SCALAR_FLOAT_MODE_P (from_mode);
337 : 2007699 : enum insn_code code;
338 : 2007699 : rtx libcall;
339 : :
340 : 2007699 : gcc_assert (to_real == from_real);
341 : :
342 : : /* rtx code for making an equivalent value. */
343 : 3112502 : enum rtx_code equiv_code = (unsignedp < 0 ? UNKNOWN
344 : 2007699 : : (unsignedp ? ZERO_EXTEND : SIGN_EXTEND));
345 : :
346 : 2007699 : 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 : 2007699 : if (to_real)
370 : : {
371 : 185031 : rtx value;
372 : 185031 : rtx_insn *insns;
373 : 185031 : convert_optab tab;
374 : :
375 : 185031 : gcc_assert ((GET_MODE_PRECISION (from_mode)
376 : : != GET_MODE_PRECISION (to_mode))
377 : : || acceptable_same_precision_modes (from_mode, to_mode));
378 : :
379 : 185031 : 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 : 184451 : else if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode))
394 : : tab = sext_optab;
395 : : else
396 : 19144 : tab = trunc_optab;
397 : :
398 : : /* Try converting directly if the insn is supported. */
399 : :
400 : 185031 : code = convert_optab_handler (tab, to_mode, from_mode);
401 : 185031 : if (code != CODE_FOR_nothing)
402 : : {
403 : 160841 : emit_unop_insn (code, to, from,
404 : : tab == sext_optab ? FLOAT_EXTEND : FLOAT_TRUNCATE);
405 : 160841 : return;
406 : : }
407 : :
408 : : #ifdef HAVE_SFmode
409 : 24190 : if (REAL_MODE_FORMAT (from_mode) == &arm_bfloat_half_format
410 : 24190 : && REAL_MODE_FORMAT (SFmode) == &ieee_single_format)
411 : : {
412 : 2740 : 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 : 2736 : 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 : 2735 : if (to_mode == SFmode
439 : 2735 : && !HONOR_NANS (from_mode)
440 : 40 : && !HONOR_NANS (to_mode)
441 : 2775 : && 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 : 39 : machine_mode fromi_mode, toi_mode;
446 : 78 : if (int_mode_for_size (GET_MODE_BITSIZE (from_mode),
447 : 39 : 0).exists (&fromi_mode)
448 : 39 : && int_mode_for_size (GET_MODE_BITSIZE (to_mode),
449 : 0 : 0).exists (&toi_mode))
450 : : {
451 : 39 : start_sequence ();
452 : 39 : rtx fromi = force_lowpart_subreg (fromi_mode, from,
453 : : from_mode);
454 : 39 : rtx tof = NULL_RTX;
455 : 39 : if (fromi)
456 : : {
457 : 39 : rtx toi;
458 : 39 : if (GET_MODE (fromi) == VOIDmode)
459 : 0 : toi = simplify_unary_operation (ZERO_EXTEND, toi_mode,
460 : : fromi, fromi_mode);
461 : : else
462 : : {
463 : 39 : toi = gen_reg_rtx (toi_mode);
464 : 39 : convert_mode_scalar (toi, fromi, 1);
465 : : }
466 : 39 : toi
467 : 78 : = maybe_expand_shift (LSHIFT_EXPR, toi_mode, toi,
468 : 39 : GET_MODE_PRECISION (to_mode)
469 : 39 : - GET_MODE_PRECISION (from_mode),
470 : : NULL_RTX, 1);
471 : 39 : if (toi)
472 : : {
473 : 39 : tof = force_lowpart_subreg (to_mode, toi, toi_mode);
474 : 39 : if (tof)
475 : 39 : emit_move_insn (to, tof);
476 : : }
477 : : }
478 : 39 : insns = end_sequence ();
479 : 39 : if (tof)
480 : : {
481 : 39 : emit_insn (insns);
482 : 39 : return;
483 : : }
484 : : }
485 : : }
486 : : }
487 : 24146 : if (REAL_MODE_FORMAT (from_mode) == &ieee_single_format
488 : 5009 : && REAL_MODE_FORMAT (to_mode) == &arm_bfloat_half_format
489 : 1804 : && !HONOR_NANS (from_mode)
490 : 0 : && !HONOR_NANS (to_mode)
491 : 0 : && !flag_rounding_math
492 : 24146 : && 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 : 24146 : libcall = convert_optab_libfunc (tab, to_mode, from_mode);
560 : :
561 : : /* Is this conversion implemented yet? */
562 : 24146 : gcc_assert (libcall);
563 : :
564 : 24146 : start_sequence ();
565 : 24146 : value = emit_library_call_value (libcall, NULL_RTX, LCT_CONST, to_mode,
566 : : from, from_mode);
567 : 24146 : insns = end_sequence ();
568 : 24146 : emit_libcall_block (insns, to, value,
569 : 7423 : tab == trunc_optab ? gen_rtx_FLOAT_TRUNCATE (to_mode,
570 : : from)
571 : 16723 : : gen_rtx_FLOAT_EXTEND (to_mode, from));
572 : 24146 : 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 : 1822668 : {
578 : 1822668 : convert_optab ctab;
579 : :
580 : 1822668 : if (GET_MODE_PRECISION (from_mode) > GET_MODE_PRECISION (to_mode))
581 : : ctab = trunc_optab;
582 : 1628849 : else if (unsignedp)
583 : : ctab = zext_optab;
584 : : else
585 : 834418 : ctab = sext_optab;
586 : :
587 : 1822668 : if (convert_optab_handler (ctab, to_mode, from_mode)
588 : : != CODE_FOR_nothing)
589 : : {
590 : 1623430 : emit_unop_insn (convert_optab_handler (ctab, to_mode, from_mode),
591 : : to, from, UNKNOWN);
592 : 1623430 : 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 : 199238 : 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 : 199238 : 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 : 199238 : gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode) ==
639 : : ALL_SCALAR_FIXED_POINT_MODE_P (to_mode));
640 : 199238 : 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 : 199238 : if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode)
657 : 201974 : && GET_MODE_PRECISION (to_mode) > BITS_PER_WORD)
658 : : {
659 : 5419 : rtx_insn *insns;
660 : 5419 : rtx lowpart;
661 : 5419 : rtx fill_value;
662 : 5419 : rtx lowfrom;
663 : 5419 : int i;
664 : 5419 : scalar_mode lowpart_mode;
665 : 10838 : int nwords = CEIL (GET_MODE_SIZE (to_mode), UNITS_PER_WORD);
666 : :
667 : : /* Try converting directly if the insn is supported. */
668 : 5419 : 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 : 5419 : else if (GET_MODE_PRECISION (from_mode) < BITS_PER_WORD
682 : 5419 : && ((code = can_extend_p (to_mode, word_mode, unsignedp))
683 : : != CODE_FOR_nothing))
684 : : {
685 : 5419 : rtx word_to = gen_reg_rtx (word_mode);
686 : 5419 : if (REG_P (to))
687 : : {
688 : 5348 : if (reg_overlap_mentioned_p (to, from))
689 : 0 : from = force_reg (from_mode, from);
690 : 5348 : emit_clobber (to);
691 : : }
692 : 5419 : convert_move (word_to, from, unsignedp);
693 : 5419 : emit_unop_insn (code, to, word_to, equiv_code);
694 : 5419 : 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 : 193819 : if (GET_MODE_PRECISION (from_mode) > BITS_PER_WORD
748 : 193819 : && GET_MODE_PRECISION (to_mode) <= BITS_PER_WORD)
749 : : {
750 : 71066 : if (!((MEM_P (from)
751 : 537 : && ! MEM_VOLATILE_P (from)
752 : 537 : && direct_load[(int) to_mode]
753 : 537 : && ! mode_dependent_address_p (XEXP (from, 0),
754 : 537 : MEM_ADDR_SPACE (from)))
755 : 40231 : || REG_P (from)
756 : : || GET_CODE (from) == SUBREG))
757 : 0 : from = force_reg (from_mode, from);
758 : 40768 : convert_move (to, gen_lowpart (word_mode, from), 0);
759 : 40768 : 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 : 306102 : if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode)
767 : 153051 : && TRULY_NOOP_TRUNCATION_MODES_P (to_mode, from_mode))
768 : : {
769 : 165657 : if (!((MEM_P (from)
770 : 13936 : && ! MEM_VOLATILE_P (from)
771 : 13877 : && direct_load[(int) to_mode]
772 : 13877 : && ! mode_dependent_address_p (XEXP (from, 0),
773 : 13877 : MEM_ADDR_SPACE (from)))
774 : 139174 : || REG_P (from)
775 : : || GET_CODE (from) == SUBREG))
776 : 918 : from = force_reg (from_mode, from);
777 : 127486 : if (REG_P (from) && REGNO (from) < FIRST_PSEUDO_REGISTER
778 : 153052 : && !targetm.hard_regno_mode_ok (REGNO (from), to_mode))
779 : 0 : from = copy_to_reg (from);
780 : 153051 : emit_move_insn (to, gen_lowpart (to_mode, from));
781 : 153051 : 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 : 1861531 : convert_to_mode (machine_mode mode, rtx x, int unsignedp)
869 : : {
870 : 1861531 : 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 : 4726077 : convert_modes (machine_mode mode, machine_mode oldmode, rtx x, int unsignedp)
885 : : {
886 : 4726077 : rtx temp;
887 : 4726077 : 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 : 4726077 : if (GET_CODE (x) == SUBREG
893 : 73641 : && SUBREG_PROMOTED_VAR_P (x)
894 : 4726077 : && is_a <scalar_int_mode> (mode, &int_mode)
895 : 4726077 : && (GET_MODE_PRECISION (subreg_promoted_mode (x))
896 : 7 : >= GET_MODE_PRECISION (int_mode))
897 : 4726084 : && 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 : 4726077 : if (GET_MODE (x) != VOIDmode)
921 : 2434375 : oldmode = GET_MODE (x);
922 : :
923 : 4726077 : if (mode == oldmode)
924 : : return x;
925 : :
926 : 3699146 : if (CONST_SCALAR_INT_P (x)
927 : 3699146 : && 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 : 1968317 : if (!is_a <scalar_int_mode> (oldmode))
933 : 1653205 : oldmode = MAX_MODE_INT;
934 : 1968317 : wide_int w = wide_int::from (rtx_mode_t (x, oldmode),
935 : 1968317 : GET_MODE_PRECISION (int_mode),
936 : 2826058 : unsignedp ? UNSIGNED : SIGNED);
937 : 1968317 : return immed_wide_int_const (w, int_mode);
938 : 1968317 : }
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 : 1730829 : scalar_int_mode int_oldmode;
944 : 1730829 : if (is_int_mode (mode, &int_mode)
945 : 1638747 : && is_int_mode (oldmode, &int_oldmode)
946 : 1638747 : && GET_MODE_PRECISION (int_mode) <= GET_MODE_PRECISION (int_oldmode)
947 : 453061 : && ((MEM_P (x) && !MEM_VOLATILE_P (x) && direct_load[(int) int_mode])
948 : 11889 : || CONST_POLY_INT_P (x)
949 : 441172 : || (REG_P (x)
950 : 404140 : && (!HARD_REGISTER_P (x)
951 : 983 : || targetm.hard_regno_mode_ok (REGNO (x), int_mode))
952 : 404140 : && TRULY_NOOP_TRUNCATION_MODES_P (int_mode, GET_MODE (x)))))
953 : 416029 : return gen_lowpart (int_mode, x);
954 : :
955 : : /* Converting from integer constant into mode is always equivalent to an
956 : : subreg operation. */
957 : 1314800 : 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 : 1314800 : temp = gen_reg_rtx (mode);
965 : 1314800 : convert_move (temp, x, unsignedp);
966 : 1314800 : 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 : 2687412 : alignment_for_piecewise_move (unsigned int max_pieces, unsigned int align)
1000 : : {
1001 : 2687412 : scalar_int_mode tmode
1002 : 2687412 : = int_mode_for_size (max_pieces * BITS_PER_UNIT, 0).require ();
1003 : :
1004 : 2687412 : if (align >= GET_MODE_ALIGNMENT (tmode))
1005 : 2123104 : align = GET_MODE_ALIGNMENT (tmode);
1006 : : else
1007 : : {
1008 : 564308 : scalar_int_mode xmode = NARROWEST_INT_MODE;
1009 : 564308 : opt_scalar_int_mode mode_iter;
1010 : 3401184 : FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_INT)
1011 : : {
1012 : 3395880 : tmode = mode_iter.require ();
1013 : 3395880 : if (GET_MODE_SIZE (tmode) > max_pieces
1014 : 3395880 : || targetm.slow_unaligned_access (tmode, align))
1015 : : break;
1016 : 2836876 : xmode = tmode;
1017 : : }
1018 : :
1019 : 564308 : align = MAX (align, GET_MODE_ALIGNMENT (xmode));
1020 : : }
1021 : :
1022 : 2687412 : return align;
1023 : : }
1024 : :
1025 : : /* Return true if we know how to implement OP using vectors of bytes. */
1026 : : static bool
1027 : 5697788 : can_use_qi_vectors (by_pieces_operation op)
1028 : : {
1029 : 5697788 : 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 : 25319025 : by_pieces_mode_supported_p (fixed_size_mode mode, by_pieces_operation op)
1038 : : {
1039 : 25319025 : if (optab_handler (mov_optab, mode) == CODE_FOR_nothing)
1040 : : return false;
1041 : :
1042 : 24160910 : if ((op == SET_BY_PIECES || op == CLEAR_BY_PIECES)
1043 : 572863 : && VECTOR_MODE_P (mode)
1044 : 24563885 : && optab_handler (vec_duplicate_optab, mode) == CODE_FOR_nothing)
1045 : : return false;
1046 : :
1047 : 24113113 : if (op == COMPARE_BY_PIECES
1048 : 24113113 : && !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 : 5210646 : widest_fixed_size_mode_for_size (unsigned int size, by_pieces_operation op)
1059 : : {
1060 : 5210646 : fixed_size_mode result = NARROWEST_INT_MODE;
1061 : :
1062 : 5210646 : gcc_checking_assert (size > 1);
1063 : :
1064 : : /* Use QI vector only if size is wider than a WORD. */
1065 : 5210646 : if (can_use_qi_vectors (op))
1066 : : {
1067 : 622405 : machine_mode mode;
1068 : 622405 : fixed_size_mode candidate;
1069 : 10287804 : FOR_EACH_MODE_IN_CLASS (mode, MODE_VECTOR_INT)
1070 : 10287804 : if (is_a<fixed_size_mode> (mode, &candidate)
1071 : 11380537 : && GET_MODE_SIZE (candidate) > UNITS_PER_WORD
1072 : 11159616 : && GET_MODE_INNER (candidate) == QImode)
1073 : : {
1074 : 4856972 : if (GET_MODE_SIZE (candidate) >= size)
1075 : : break;
1076 : 1806081 : if (by_pieces_mode_supported_p (candidate, op))
1077 : 9665399 : result = candidate;
1078 : : }
1079 : :
1080 : 622405 : if (result != NARROWEST_INT_MODE)
1081 : 384641 : return result;
1082 : : }
1083 : :
1084 : 4826005 : opt_scalar_int_mode tmode;
1085 : 4826005 : scalar_int_mode mode;
1086 : 38608040 : FOR_EACH_MODE_IN_CLASS (tmode, MODE_INT)
1087 : : {
1088 : 33782035 : mode = tmode.require ();
1089 : 33782035 : if (GET_MODE_SIZE (mode) < size
1090 : 33782035 : && by_pieces_mode_supported_p (mode, op))
1091 : 23473141 : result = mode;
1092 : : }
1093 : :
1094 : 4826005 : 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 : 957025 : can_do_by_pieces (unsigned HOST_WIDE_INT len, unsigned int align,
1102 : : enum by_pieces_operation op)
1103 : : {
1104 : 957025 : return targetm.use_by_pieces_infrastructure_p (len, align, op,
1105 : 957025 : 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 : 890273 : can_move_by_pieces (unsigned HOST_WIDE_INT len, unsigned int align)
1114 : : {
1115 : 890273 : 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 : 1899065 : by_pieces_ninsns (unsigned HOST_WIDE_INT l, unsigned int align,
1123 : : unsigned int max_size, by_pieces_operation op)
1124 : : {
1125 : 1899065 : unsigned HOST_WIDE_INT n_insns = 0;
1126 : 1899065 : fixed_size_mode mode;
1127 : :
1128 : 1899065 : 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 : 1899065 : mode = widest_fixed_size_mode_for_size (max_size, op);
1133 : 1899065 : gcc_assert (optab_handler (mov_optab, mode) != CODE_FOR_nothing);
1134 : 3798130 : unsigned HOST_WIDE_INT up = ROUND_UP (l, GET_MODE_SIZE (mode));
1135 : 1899065 : if (up > l)
1136 : : l = up;
1137 : 1899065 : align = GET_MODE_ALIGNMENT (mode);
1138 : : }
1139 : :
1140 : 1899065 : align = alignment_for_piecewise_move (MOVE_MAX_PIECES, align);
1141 : :
1142 : 5703549 : while (max_size > 1 && l > 0)
1143 : : {
1144 : 1905419 : mode = widest_fixed_size_mode_for_size (max_size, op);
1145 : 1905419 : gcc_assert (optab_handler (mov_optab, mode) != CODE_FOR_nothing);
1146 : :
1147 : 1905419 : unsigned int modesize = GET_MODE_SIZE (mode);
1148 : :
1149 : 1905419 : if (align >= GET_MODE_ALIGNMENT (mode))
1150 : : {
1151 : 1905419 : unsigned HOST_WIDE_INT n_pieces = l / modesize;
1152 : 1905419 : l %= modesize;
1153 : 1905419 : switch (op)
1154 : : {
1155 : 1838667 : default:
1156 : 1838667 : n_insns += n_pieces;
1157 : 1838667 : break;
1158 : :
1159 : 66752 : case COMPARE_BY_PIECES:
1160 : 66752 : int batch = targetm.compare_by_pieces_branch_ratio (mode);
1161 : 66752 : int batch_ops = 4 * batch - 1;
1162 : 66752 : unsigned HOST_WIDE_INT full = n_pieces / batch;
1163 : 66752 : n_insns += full * batch_ops;
1164 : 66752 : if (n_pieces % batch != 0)
1165 : 0 : n_insns++;
1166 : : break;
1167 : :
1168 : : }
1169 : : }
1170 : : max_size = modesize;
1171 : : }
1172 : :
1173 : 1899065 : gcc_assert (!l);
1174 : 1899065 : 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 : 733335 : int get_addr_inc ()
1217 : : {
1218 : 733335 : 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 : 1466670 : pieces_addr::pieces_addr (rtx obj, bool is_load, by_pieces_constfn constfn,
1230 : 1466670 : void *cfndata)
1231 : 1466670 : : m_obj (obj), m_is_load (is_load), m_constfn (constfn), m_cfndata (cfndata)
1232 : : {
1233 : 1466670 : m_addr_inc = 0;
1234 : 1466670 : m_auto = false;
1235 : 1466670 : if (obj)
1236 : : {
1237 : 1359497 : rtx addr = XEXP (obj, 0);
1238 : 1359497 : rtx_code code = GET_CODE (addr);
1239 : 1359497 : m_addr = addr;
1240 : 1359497 : bool dec = code == PRE_DEC || code == POST_DEC;
1241 : 1359497 : bool inc = code == PRE_INC || code == POST_INC;
1242 : 1359497 : m_auto = inc || dec;
1243 : 1359497 : 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 : 1359497 : gcc_assert (code != PRE_INC && code != POST_DEC);
1250 : : }
1251 : : else
1252 : : {
1253 : 107173 : m_addr = NULL_RTX;
1254 : 107173 : 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 : 107128 : gcc_assert (constfn != NULL);
1264 : : }
1265 : 1466670 : m_explicit_inc = 0;
1266 : 1466670 : if (constfn)
1267 : 131136 : gcc_assert (is_load);
1268 : 1466670 : }
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 : 363190 : pieces_addr::decide_autoinc (machine_mode ARG_UNUSED (mode), bool reverse,
1277 : : HOST_WIDE_INT len)
1278 : : {
1279 : 363190 : if (m_auto || m_obj == NULL_RTX)
1280 : : return;
1281 : :
1282 : 336908 : bool use_predec = (m_is_load
1283 : : ? USE_LOAD_PRE_DECREMENT (mode)
1284 : : : USE_STORE_PRE_DECREMENT (mode));
1285 : 336908 : bool use_postinc = (m_is_load
1286 : : ? USE_LOAD_POST_INCREMENT (mode)
1287 : : : USE_STORE_POST_INCREMENT (mode));
1288 : 336908 : machine_mode addr_mode = get_address_mode (m_obj);
1289 : :
1290 : 336908 : 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 : 336908 : 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 : 336908 : else if (CONSTANT_P (m_addr))
1305 : 70699 : 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 : 4030245 : pieces_addr::adjust (fixed_size_mode mode, HOST_WIDE_INT offset,
1314 : : by_pieces_prev *prev)
1315 : : {
1316 : 4030245 : if (m_constfn)
1317 : : /* Pass the previous data to m_constfn. */
1318 : 330220 : return m_constfn (m_cfndata, prev, offset, mode);
1319 : 3700025 : if (m_obj == NULL_RTX)
1320 : : return NULL_RTX;
1321 : 3699978 : if (m_auto)
1322 : 0 : return adjust_automodify_address (m_obj, mode, m_addr, offset);
1323 : : else
1324 : 3699978 : 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 : 4029578 : pieces_addr::maybe_predec (HOST_WIDE_INT size)
1342 : : {
1343 : 4029578 : if (m_explicit_inc >= 0)
1344 : 4029578 : 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 : 4029601 : pieces_addr::maybe_postinc (HOST_WIDE_INT size)
1354 : : {
1355 : 4029601 : if (m_explicit_inc <= 0)
1356 : 4029601 : 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 : 1125708 : virtual void finish_mode (machine_mode)
1391 : : {
1392 : 1125708 : }
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 : 733335 : 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 : 733335 : by_pieces_operation op)
1416 : 733335 : : m_to (to, to_load, NULL, NULL),
1417 : 733335 : m_from (from, from_load, from_cfn, from_cfn_data),
1418 : 733335 : m_len (len), m_max_size (max_pieces + 1),
1419 : 733335 : m_push (push), m_op (op)
1420 : : {
1421 : 733335 : int toi = m_to.get_addr_inc ();
1422 : 733335 : int fromi = m_from.get_addr_inc ();
1423 : 733335 : if (toi >= 0 && fromi >= 0)
1424 : 733290 : m_reverse = false;
1425 : 45 : else if (toi <= 0 && fromi <= 0)
1426 : 45 : m_reverse = true;
1427 : : else
1428 : 0 : gcc_unreachable ();
1429 : :
1430 : 733335 : m_offset = m_reverse ? len : 0;
1431 : 2719049 : 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 : 733335 : if (by_pieces_ninsns (len, align, m_max_size, MOVE_BY_PIECES) > 2)
1438 : : {
1439 : : /* Find the mode of the largest comparison. */
1440 : 181595 : fixed_size_mode mode
1441 : 181595 : = widest_fixed_size_mode_for_size (m_max_size, m_op);
1442 : :
1443 : 181595 : m_from.decide_autoinc (mode, m_reverse, len);
1444 : 181595 : m_to.decide_autoinc (mode, m_reverse, len);
1445 : : }
1446 : :
1447 : 733345 : align = alignment_for_piecewise_move (MOVE_MAX_PIECES, align);
1448 : 733335 : m_align = align;
1449 : :
1450 : 733335 : m_overlap_op_by_pieces = targetm.overlap_op_by_pieces_p ();
1451 : 733335 : }
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 : 1215547 : op_by_pieces_d::get_usable_mode (fixed_size_mode mode, unsigned int len)
1458 : : {
1459 : 1505293 : unsigned int size;
1460 : 1795039 : do
1461 : : {
1462 : 1505293 : size = GET_MODE_SIZE (mode);
1463 : 1505293 : if (len >= size && prepare_mode (mode, m_align))
1464 : : break;
1465 : : /* widest_fixed_size_mode_for_size checks SIZE > 1. */
1466 : 289746 : mode = widest_fixed_size_mode_for_size (size, m_op);
1467 : : }
1468 : : while (1);
1469 : 1215547 : 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 : 487142 : op_by_pieces_d::smallest_fixed_size_mode_for_size (unsigned int size)
1477 : : {
1478 : : /* Use QI vector only for > size of WORD. */
1479 : 499273 : if (can_use_qi_vectors (m_op) && size > UNITS_PER_WORD)
1480 : : {
1481 : 7551 : machine_mode mode;
1482 : 7551 : fixed_size_mode candidate;
1483 : 102166 : FOR_EACH_MODE_IN_CLASS (mode, MODE_VECTOR_INT)
1484 : 102166 : if (is_a<fixed_size_mode> (mode, &candidate)
1485 : 204332 : && GET_MODE_INNER (candidate) == QImode)
1486 : : {
1487 : : /* Don't return a mode wider than M_LEN. */
1488 : 94976 : if (GET_MODE_SIZE (candidate) > m_len)
1489 : : break;
1490 : :
1491 : 45764 : if (GET_MODE_SIZE (candidate) >= size
1492 : 45764 : && by_pieces_mode_supported_p (candidate, m_op))
1493 : 5827 : return candidate;
1494 : : }
1495 : : }
1496 : :
1497 : 481315 : 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 : 733335 : op_by_pieces_d::run ()
1507 : : {
1508 : 733335 : if (m_len == 0)
1509 : : return;
1510 : :
1511 : 728405 : unsigned HOST_WIDE_INT length = m_len;
1512 : :
1513 : : /* widest_fixed_size_mode_for_size checks M_MAX_SIZE > 1. */
1514 : 728405 : fixed_size_mode mode
1515 : 728405 : = widest_fixed_size_mode_for_size (m_max_size, m_op);
1516 : 728405 : mode = get_usable_mode (mode, length);
1517 : :
1518 : 728405 : by_pieces_prev to_prev = { nullptr, mode };
1519 : 728405 : by_pieces_prev from_prev = { nullptr, mode };
1520 : :
1521 : 1215547 : do
1522 : : {
1523 : 1215547 : unsigned int size = GET_MODE_SIZE (mode);
1524 : 1215547 : rtx to1 = NULL_RTX, from1;
1525 : :
1526 : 3230336 : while (length >= size)
1527 : : {
1528 : 2014789 : if (m_reverse)
1529 : 47 : m_offset -= size;
1530 : :
1531 : 2014789 : to1 = m_to.adjust (mode, m_offset, &to_prev);
1532 : 2014789 : to_prev.data = to1;
1533 : 2014789 : to_prev.mode = mode;
1534 : 2014789 : from1 = m_from.adjust (mode, m_offset, &from_prev);
1535 : 2014789 : from_prev.data = from1;
1536 : 2014789 : from_prev.mode = mode;
1537 : :
1538 : 2014789 : m_to.maybe_predec (-(HOST_WIDE_INT)size);
1539 : 2014789 : m_from.maybe_predec (-(HOST_WIDE_INT)size);
1540 : :
1541 : 2014789 : generate (to1, from1, mode);
1542 : :
1543 : 2014789 : m_to.maybe_postinc (size);
1544 : 2014789 : m_from.maybe_postinc (size);
1545 : :
1546 : 2014789 : if (!m_reverse)
1547 : 2014742 : m_offset += size;
1548 : :
1549 : 2014789 : length -= size;
1550 : : }
1551 : :
1552 : 1215547 : finish_mode (mode);
1553 : :
1554 : 1215547 : if (length == 0)
1555 : : return;
1556 : :
1557 : 487142 : 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 : 487142 : mode = smallest_fixed_size_mode_for_size (length);
1563 : 974284 : mode = get_usable_mode (mode, GET_MODE_SIZE (mode));
1564 : 487142 : int gap = GET_MODE_SIZE (mode) - length;
1565 : 487142 : 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 : 48869 : if (m_reverse)
1571 : 0 : m_offset += gap;
1572 : : else
1573 : 48869 : m_offset -= gap;
1574 : 48869 : 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 : 566013 : move_by_pieces_d (rtx to, rtx from, unsigned HOST_WIDE_INT len,
1604 : : unsigned int align)
1605 : 566013 : : op_by_pieces_d (MOVE_MAX_PIECES, to, false, from, true, NULL,
1606 : 1132026 : NULL, len, align, PUSHG_P (to), MOVE_BY_PIECES)
1607 : : {
1608 : 566013 : }
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 : 945439 : move_by_pieces_d::prepare_mode (machine_mode mode, unsigned int align)
1618 : : {
1619 : 945439 : insn_code icode = optab_handler (mov_optab, mode);
1620 : 945439 : m_gen_fun = GEN_FCN (icode);
1621 : 945439 : 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 : 1639812 : move_by_pieces_d::generate (rtx op0, rtx op1,
1632 : : machine_mode mode ATTRIBUTE_UNUSED)
1633 : : {
1634 : : #ifdef PUSH_ROUNDING
1635 : 1639812 : if (op0 == NULL_RTX)
1636 : : {
1637 : 47 : emit_single_push_insn (mode, op1, NULL);
1638 : 47 : return;
1639 : : }
1640 : : #endif
1641 : 1639765 : 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 : 566013 : 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 : 566013 : move_by_pieces_d data (to, from, len, align);
1680 : :
1681 : 566013 : data.run ();
1682 : :
1683 : 566013 : 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 : 107128 : 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 : 107128 : : op_by_pieces_d (STORE_MAX_PIECES, to, false, NULL_RTX, true, cfn,
1704 : 214256 : cfn_data, len, align, false, op)
1705 : : {
1706 : 107128 : }
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 : 180269 : store_by_pieces_d::prepare_mode (machine_mode mode, unsigned int align)
1716 : : {
1717 : 180269 : insn_code icode = optab_handler (mov_optab, mode);
1718 : 180269 : m_gen_fun = GEN_FCN (icode);
1719 : 180269 : 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 : 282108 : store_by_pieces_d::generate (rtx op0, rtx op1, machine_mode)
1730 : : {
1731 : 282108 : emit_insn (m_gen_fun (op0, op1));
1732 : 282108 : }
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 : 667 : store_by_pieces_d::finish_retmode (memop_ret retmode)
1740 : : {
1741 : 667 : gcc_assert (!m_reverse);
1742 : 667 : if (retmode == RETURN_END_MINUS_ONE)
1743 : : {
1744 : 23 : m_to.maybe_postinc (-1);
1745 : 23 : --m_offset;
1746 : : }
1747 : 667 : 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 : 88788 : can_store_by_pieces (unsigned HOST_WIDE_INT len,
1759 : : by_pieces_constfn constfun,
1760 : : void *constfundata, unsigned int align, bool memsetp)
1761 : : {
1762 : 88788 : unsigned HOST_WIDE_INT l;
1763 : 88788 : unsigned int max_size;
1764 : 88788 : HOST_WIDE_INT offset = 0;
1765 : 88788 : enum insn_code icode;
1766 : 88788 : int reverse;
1767 : : /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
1768 : 88788 : rtx cst ATTRIBUTE_UNUSED;
1769 : :
1770 : 88788 : if (len == 0)
1771 : : return true;
1772 : :
1773 : 137392 : if (!targetm.use_by_pieces_infrastructure_p (len, align,
1774 : : memsetp
1775 : : ? SET_BY_PIECES
1776 : : : STORE_BY_PIECES,
1777 : 88744 : optimize_insn_for_speed_p ()))
1778 : : return false;
1779 : :
1780 : 55012 : 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 : 55012 : for (reverse = 0;
1786 : 110024 : reverse <= (HAVE_PRE_DECREMENT || HAVE_POST_DECREMENT);
1787 : : reverse++)
1788 : : {
1789 : 55012 : l = len;
1790 : 55012 : max_size = STORE_MAX_PIECES + 1;
1791 : 261428 : while (max_size > 1 && l > 0)
1792 : : {
1793 : 206416 : auto op = memsetp ? SET_BY_PIECES : STORE_BY_PIECES;
1794 : 206416 : auto mode = widest_fixed_size_mode_for_size (max_size, op);
1795 : :
1796 : 206416 : icode = optab_handler (mov_optab, mode);
1797 : 206416 : if (icode != CODE_FOR_nothing
1798 : 206416 : && align >= GET_MODE_ALIGNMENT (mode))
1799 : : {
1800 : 206416 : unsigned int size = GET_MODE_SIZE (mode);
1801 : :
1802 : 360427 : while (l >= size)
1803 : : {
1804 : 154011 : if (reverse)
1805 : : offset -= size;
1806 : :
1807 : 154011 : 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 : 292121 : if (!((memsetp && VECTOR_MODE_P (mode))
1812 : 138110 : || targetm.legitimate_constant_p (mode, cst)))
1813 : 33732 : return false;
1814 : :
1815 : 154011 : if (!reverse)
1816 : 154011 : offset += size;
1817 : :
1818 : 154011 : l -= size;
1819 : : }
1820 : : }
1821 : :
1822 : 412832 : max_size = GET_MODE_SIZE (mode);
1823 : : }
1824 : :
1825 : : /* The code above should have handled everything. */
1826 : 55012 : 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 : 57179 : 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 : 57179 : if (len == 0)
1846 : : {
1847 : 2744 : gcc_assert (retmode != RETURN_END_MINUS_ONE);
1848 : : return to;
1849 : : }
1850 : :
1851 : 99228 : 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 : 54435 : store_by_pieces_d data (to, constfun, constfundata, len, align,
1857 : 54435 : memsetp ? SET_BY_PIECES : STORE_BY_PIECES);
1858 : 54435 : data.run ();
1859 : :
1860 : 54435 : if (retmode != RETURN_BEGIN)
1861 : 667 : return data.finish_retmode (retmode);
1862 : : else
1863 : : return to;
1864 : : }
1865 : :
1866 : : void
1867 : 52693 : clear_by_pieces (rtx to, unsigned HOST_WIDE_INT len, unsigned int align)
1868 : : {
1869 : 52693 : if (len == 0)
1870 : 0 : return;
1871 : :
1872 : : /* Use builtin_memset_read_str to support vector mode broadcast. */
1873 : 52693 : char c = 0;
1874 : 52693 : store_by_pieces_d data (to, builtin_memset_read_str, &c, len, align,
1875 : 52693 : CLEAR_BY_PIECES);
1876 : 52693 : 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 : 60194 : 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 : 60194 : : op_by_pieces_d (COMPARE_MAX_PIECES, op0, true, op1, true, op1_cfn,
1899 : 120388 : op1_cfn_data, len, align, false, COMPARE_BY_PIECES)
1900 : : {
1901 : 60194 : m_fail_label = fail_label;
1902 : 60194 : }
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 : 92869 : compare_by_pieces_d::generate (rtx op0, rtx op1, machine_mode mode)
1912 : : {
1913 : 92869 : 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 : 92869 : 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 : 89839 : compare_by_pieces_d::prepare_mode (machine_mode mode, unsigned int align)
1940 : : {
1941 : 89839 : insn_code icode = optab_handler (mov_optab, mode);
1942 : 89839 : if (icode == CODE_FOR_nothing
1943 : 89839 : || align < GET_MODE_ALIGNMENT (mode)
1944 : 179678 : || !can_compare_p (EQ, mode, ccp_jump))
1945 : 0 : return false;
1946 : 89839 : m_batch = targetm.compare_by_pieces_branch_ratio (mode);
1947 : 89839 : if (m_batch < 0)
1948 : : return false;
1949 : 89839 : m_accumulator = NULL_RTX;
1950 : 89839 : m_count = 0;
1951 : 89839 : 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 : 89839 : compare_by_pieces_d::finish_mode (machine_mode mode)
1960 : : {
1961 : 89839 : 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 : 89839 : }
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 : 60194 : 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 : 60194 : rtx_code_label *fail_label = gen_label_rtx ();
1985 : 60194 : rtx_code_label *end_label = gen_label_rtx ();
1986 : :
1987 : 60194 : if (target == NULL_RTX
1988 : 60194 : || !REG_P (target) || REGNO (target) < FIRST_PSEUDO_REGISTER)
1989 : 1 : target = gen_reg_rtx (TYPE_MODE (integer_type_node));
1990 : :
1991 : 60194 : compare_by_pieces_d data (arg0, arg1, a1_cfn, a1_cfn_data, len, align,
1992 : 60194 : fail_label);
1993 : :
1994 : 60194 : data.run ();
1995 : :
1996 : 60194 : emit_move_insn (target, const0_rtx);
1997 : 60194 : emit_jump (end_label);
1998 : 60194 : emit_barrier ();
1999 : 60194 : emit_label (fail_label);
2000 : 60194 : emit_move_insn (target, const1_rtx);
2001 : 60194 : emit_label (end_label);
2002 : :
2003 : 60194 : 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 : 654133 : 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 : 654133 : int may_use_call;
2033 : 654133 : rtx retval = 0;
2034 : 654133 : unsigned int align;
2035 : :
2036 : 654133 : if (is_move_done)
2037 : 84315 : *is_move_done = true;
2038 : :
2039 : 654133 : gcc_assert (size);
2040 : 654133 : if (CONST_INT_P (size) && INTVAL (size) == 0)
2041 : : return 0;
2042 : :
2043 : 653856 : switch (method)
2044 : : {
2045 : : case BLOCK_OP_NORMAL:
2046 : : case BLOCK_OP_TAILCALL:
2047 : : may_use_call = 1;
2048 : : break;
2049 : :
2050 : 268116 : case BLOCK_OP_CALL_PARM:
2051 : 268116 : 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 : 268116 : NO_DEFER_POP;
2056 : 268116 : break;
2057 : :
2058 : 353 : case BLOCK_OP_NO_LIBCALL:
2059 : 353 : may_use_call = 0;
2060 : 353 : break;
2061 : :
2062 : 1061 : case BLOCK_OP_NO_LIBCALL_RET:
2063 : 1061 : may_use_call = -1;
2064 : 1061 : break;
2065 : :
2066 : 0 : default:
2067 : 0 : gcc_unreachable ();
2068 : : }
2069 : :
2070 : 653856 : gcc_assert (MEM_P (x) && MEM_P (y));
2071 : 653939 : align = MIN (MEM_ALIGN (x), MEM_ALIGN (y));
2072 : 653856 : 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 : 653856 : x = adjust_address (x, BLKmode, 0);
2077 : 653856 : y = adjust_address (y, BLKmode, 0);
2078 : :
2079 : : /* If source and destination are the same, no need to copy anything. */
2080 : 653856 : if (rtx_equal_p (x, y)
2081 : 16 : && !MEM_VOLATILE_P (x)
2082 : 653872 : && !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 : 653840 : poly_int64 const_size;
2088 : 653840 : if (poly_int_rtx_p (size, &const_size))
2089 : : {
2090 : 585665 : x = shallow_copy_rtx (x);
2091 : 585665 : y = shallow_copy_rtx (y);
2092 : 585665 : set_mem_size (x, const_size);
2093 : 585665 : set_mem_size (y, const_size);
2094 : : }
2095 : :
2096 : 653840 : bool pieces_ok = CONST_INT_P (size)
2097 : 653840 : && can_move_by_pieces (INTVAL (size), align);
2098 : 653840 : bool pattern_ok = false;
2099 : :
2100 : 653840 : if (!pieces_ok || might_overlap)
2101 : : {
2102 : 93311 : pattern_ok
2103 : 93311 : = 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 : 93311 : 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 : 15695 : *is_move_done = false;
2112 : 15695 : return retval;
2113 : : }
2114 : : }
2115 : :
2116 : 77616 : bool dynamic_direction = false;
2117 : 77616 : if (!pattern_ok && !pieces_ok && may_use_call
2118 : 114832 : && (flag_inline_stringops & (might_overlap ? ILSOP_MEMMOVE : ILSOP_MEMCPY)))
2119 : : {
2120 : 638145 : may_use_call = 0;
2121 : 638145 : dynamic_direction = might_overlap;
2122 : : }
2123 : :
2124 : 638145 : if (pattern_ok)
2125 : : ;
2126 : 617945 : else if (pieces_ok)
2127 : 560529 : move_by_pieces (x, y, INTVAL (size), align, RETURN_BEGIN);
2128 : 57416 : else if (may_use_call && !might_overlap
2129 : 57368 : && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x))
2130 : 114784 : && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y)))
2131 : : {
2132 : 57368 : if (bail_out_libcall)
2133 : : {
2134 : 253 : if (is_move_done)
2135 : 253 : *is_move_done = false;
2136 : 253 : return retval;
2137 : : }
2138 : :
2139 : 57115 : if (may_use_call < 0)
2140 : 0 : return pc_rtx;
2141 : :
2142 : 57115 : 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 : 637892 : if (method == BLOCK_OP_CALL_PARM)
2153 : 268102 : OK_DEFER_POP;
2154 : :
2155 : : return retval;
2156 : : }
2157 : :
2158 : : rtx
2159 : 569818 : emit_block_move (rtx x, rtx y, rtx size, enum block_op_methods method,
2160 : : unsigned int ctz_size)
2161 : : {
2162 : 569818 : unsigned HOST_WIDE_INT max, min = 0;
2163 : 569818 : if (GET_CODE (size) == CONST_INT)
2164 : 569598 : min = max = UINTVAL (size);
2165 : : else
2166 : 220 : max = GET_MODE_MASK (GET_MODE (size));
2167 : 569818 : return emit_block_move_hints (x, y, size, method, 0, -1,
2168 : : min, max, max,
2169 : 569818 : 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 : 268116 : block_move_libcall_safe_for_call_parm (void)
2178 : : {
2179 : 268116 : tree fn;
2180 : :
2181 : : /* If arguments are pushed on the stack, then they're safe. */
2182 : 268116 : 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 : 93311 : 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 : 93311 : if (expected_align < align)
2246 : : expected_align = align;
2247 : 93311 : 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 : 93311 : 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 : 93311 : opt_scalar_int_mode mode_iter;
2263 : 647875 : FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_INT)
2264 : : {
2265 : 574764 : scalar_int_mode mode = mode_iter.require ();
2266 : 574764 : enum insn_code code;
2267 : 574764 : if (might_overlap)
2268 : 109865 : code = direct_optab_handler (movmem_optab, mode);
2269 : : else
2270 : 464899 : code = direct_optab_handler (cpymem_optab, mode);
2271 : :
2272 : 574764 : 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 : 574764 : && ((CONST_INT_P (size)
2279 : 37235 : && ((unsigned HOST_WIDE_INT) INTVAL (size)
2280 : 37235 : <= (GET_MODE_MASK (mode) >> 1)))
2281 : 97669 : || max_size <= (GET_MODE_MASK (mode) >> 1)
2282 : 125076 : || GET_MODE_BITSIZE (mode) >= GET_MODE_BITSIZE (Pmode)))
2283 : : {
2284 : 93213 : class expand_operand ops[9];
2285 : 93213 : 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 : 93213 : nops = insn_data[(int) code].n_generator_args;
2292 : 93213 : gcc_assert (nops == 4 || nops == 6 || nops == 8 || nops == 9);
2293 : :
2294 : 93213 : create_fixed_operand (&ops[0], x);
2295 : 93213 : create_fixed_operand (&ops[1], y);
2296 : : /* The check above guarantees that this size conversion is valid. */
2297 : 93213 : create_convert_operand_to (&ops[2], size, mode, true);
2298 : 93213 : create_integer_operand (&ops[3], align / BITS_PER_UNIT);
2299 : 93213 : if (nops >= 6)
2300 : : {
2301 : 93213 : create_integer_operand (&ops[4], expected_align / BITS_PER_UNIT);
2302 : 93213 : create_integer_operand (&ops[5], expected_size);
2303 : : }
2304 : 93213 : if (nops >= 8)
2305 : : {
2306 : 93213 : create_integer_operand (&ops[6], min_size);
2307 : : /* If we cannot represent the maximal size,
2308 : : make parameter NULL. */
2309 : 93213 : if ((HOST_WIDE_INT) max_size != -1)
2310 : 80187 : create_integer_operand (&ops[7], max_size);
2311 : : else
2312 : 13026 : create_fixed_operand (&ops[7], NULL);
2313 : : }
2314 : 93213 : if (nops == 9)
2315 : : {
2316 : : /* If we cannot represent the maximal size,
2317 : : make parameter NULL. */
2318 : 93213 : if ((HOST_WIDE_INT) probable_max_size != -1)
2319 : 81496 : create_integer_operand (&ops[8], probable_max_size);
2320 : : else
2321 : 11717 : create_fixed_operand (&ops[8], NULL);
2322 : : }
2323 : 93213 : if (maybe_expand_insn (code, nops, ops))
2324 : 20200 : return true;
2325 : : }
2326 : : }
2327 : :
2328 : : return false;
2329 : 93311 : }
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 : 57118 : emit_block_op_via_libcall (enum built_in_function fncode, rtx dst, rtx src,
2539 : : rtx size, bool tailcall)
2540 : : {
2541 : 57118 : rtx dst_addr, src_addr;
2542 : 57118 : tree call_expr, dst_tree, src_tree, size_tree;
2543 : 57118 : machine_mode size_mode;
2544 : :
2545 : : /* Since dst and src are passed to a libcall, mark the corresponding
2546 : : tree EXPR as addressable. */
2547 : 57118 : tree dst_expr = MEM_EXPR (dst);
2548 : 57118 : tree src_expr = MEM_EXPR (src);
2549 : 57118 : if (dst_expr)
2550 : 50415 : mark_addressable (dst_expr);
2551 : 57118 : if (src_expr)
2552 : 55729 : mark_addressable (src_expr);
2553 : :
2554 : 57118 : dst_addr = copy_addr_to_reg (XEXP (dst, 0));
2555 : 57118 : dst_addr = convert_memory_address (ptr_mode, dst_addr);
2556 : 57118 : dst_tree = make_tree (ptr_type_node, dst_addr);
2557 : :
2558 : 57118 : src_addr = copy_addr_to_reg (XEXP (src, 0));
2559 : 57118 : src_addr = convert_memory_address (ptr_mode, src_addr);
2560 : 57118 : src_tree = make_tree (ptr_type_node, src_addr);
2561 : :
2562 : 57118 : size_mode = TYPE_MODE (sizetype);
2563 : 57118 : size = convert_to_mode (size_mode, size, 1);
2564 : 57118 : size = copy_to_mode_reg (size_mode, size);
2565 : 57118 : 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 : 57118 : tree fn = builtin_decl_implicit (fncode);
2570 : 57118 : call_expr = build_call_expr (fn, 3, dst_tree, src_tree, size_tree);
2571 : 57118 : CALL_EXPR_TAILCALL (call_expr) = tailcall;
2572 : :
2573 : 57118 : 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 : 170551 : 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 : 170551 : machine_mode insn_mode = insn_data[icode].operand[0].mode;
2586 : :
2587 : 170551 : if (target && (!REG_P (target) || HARD_REGISTER_P (target)))
2588 : : target = NULL_RTX;
2589 : :
2590 : 170551 : class expand_operand ops[5];
2591 : 170551 : create_output_operand (&ops[0], target, insn_mode);
2592 : 170551 : create_fixed_operand (&ops[1], arg1_rtx);
2593 : 170551 : create_fixed_operand (&ops[2], arg2_rtx);
2594 : 170551 : create_convert_operand_from (&ops[3], arg3_rtx, TYPE_MODE (arg3_type),
2595 : 170551 : TYPE_UNSIGNED (arg3_type));
2596 : 170551 : create_integer_operand (&ops[4], align);
2597 : 170551 : if (maybe_expand_insn (icode, 5, ops))
2598 : 5755 : 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 : 42650 : 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 : 42650 : insn_code icode = direct_optab_handler (cmpmem_optab, SImode);
2615 : :
2616 : 42650 : if (icode == CODE_FOR_nothing)
2617 : : return NULL_RTX;
2618 : :
2619 : 42650 : 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 : 102843 : 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 : 102843 : rtx result = 0;
2648 : :
2649 : 102843 : if (CONST_INT_P (len) && INTVAL (len) == 0)
2650 : 0 : return const0_rtx;
2651 : :
2652 : 102843 : gcc_assert (MEM_P (x) && MEM_P (y));
2653 : 102843 : unsigned int align = MIN (MEM_ALIGN (x), MEM_ALIGN (y));
2654 : 102843 : gcc_assert (align >= BITS_PER_UNIT);
2655 : :
2656 : 102843 : x = adjust_address (x, BLKmode, 0);
2657 : 102843 : y = adjust_address (y, BLKmode, 0);
2658 : :
2659 : 102843 : if (equality_only
2660 : 88546 : && CONST_INT_P (len)
2661 : 169549 : && can_do_by_pieces (INTVAL (len), align, COMPARE_BY_PIECES))
2662 : 60193 : result = compare_by_pieces (x, y, INTVAL (len), target, align,
2663 : : y_cfn, y_cfndata);
2664 : : else
2665 : 42650 : result = emit_block_cmp_via_cmpmem (x, y, len, len_type, target, align);
2666 : :
2667 : 102843 : 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 : 3020 : gen_group_rtx (rtx orig)
2938 : : {
2939 : 3020 : int i, length;
2940 : 3020 : rtx *tmps;
2941 : :
2942 : 3020 : gcc_assert (GET_CODE (orig) == PARALLEL);
2943 : :
2944 : 3020 : length = XVECLEN (orig, 0);
2945 : 3020 : tmps = XALLOCAVEC (rtx, length);
2946 : :
2947 : : /* Skip a NULL entry in first slot. */
2948 : 3020 : i = XEXP (XVECEXP (orig, 0, 0), 0) ? 0 : 1;
2949 : :
2950 : 3020 : if (i)
2951 : 0 : tmps[0] = 0;
2952 : :
2953 : 7350 : for (; i < length; i++)
2954 : : {
2955 : 4330 : machine_mode mode = GET_MODE (XEXP (XVECEXP (orig, 0, i), 0));
2956 : 4330 : rtx offset = XEXP (XVECEXP (orig, 0, i), 1);
2957 : :
2958 : 4330 : tmps[i] = gen_rtx_EXPR_LIST (VOIDmode, gen_reg_rtx (mode), offset);
2959 : : }
2960 : :
2961 : 3020 : 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 : 306857 : emit_group_load_1 (rtx *tmps, rtx dst, rtx orig_src, tree type,
2970 : : poly_int64 ssize)
2971 : : {
2972 : 306860 : rtx src;
2973 : 306860 : int start, i;
2974 : 306860 : machine_mode m = GET_MODE (orig_src);
2975 : :
2976 : 306860 : gcc_assert (GET_CODE (dst) == PARALLEL);
2977 : :
2978 : 306860 : if (m != VOIDmode
2979 : 288151 : && !SCALAR_INT_MODE_P (m)
2980 : 18762 : && !MEM_P (orig_src)
2981 : 5461 : && 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 : 306857 : if (XEXP (XVECEXP (dst, 0, 0), 0))
3001 : : start = 0;
3002 : : else
3003 : 0 : start = 1;
3004 : :
3005 : : /* Process the pieces. */
3006 : 909334 : for (i = start; i < XVECLEN (dst, 0); i++)
3007 : : {
3008 : 602477 : machine_mode mode = GET_MODE (XEXP (XVECEXP (dst, 0, i), 0));
3009 : 602477 : poly_int64 bytepos = rtx_to_poly_int64 (XEXP (XVECEXP (dst, 0, i), 1));
3010 : 1204954 : poly_int64 bytelen = GET_MODE_SIZE (mode);
3011 : 602477 : 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 : 602477 : gcc_checking_assert (ordered_p (bytepos + bytelen, ssize));
3018 : 602477 : 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 : 1798 : bytelen = ssize - bytepos;
3032 : 1798 : 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 : 602477 : src = orig_src;
3039 : 602477 : if (!MEM_P (orig_src)
3040 : 500460 : && (!REG_P (orig_src) || HARD_REGISTER_P (orig_src))
3041 : 648203 : && !CONSTANT_P (orig_src))
3042 : : {
3043 : 8308 : gcc_assert (GET_MODE (orig_src) != VOIDmode);
3044 : 8308 : src = force_reg (GET_MODE (orig_src), orig_src);
3045 : : }
3046 : :
3047 : : /* Optimize the access just a bit. */
3048 : 602477 : if (MEM_P (src)
3049 : 102017 : && (! targetm.slow_unaligned_access (mode, MEM_ALIGN (src))
3050 : 0 : || MEM_ALIGN (src) >= GET_MODE_ALIGNMENT (mode))
3051 : 204034 : && multiple_p (bytepos * BITS_PER_UNIT, GET_MODE_ALIGNMENT (mode))
3052 : 704494 : && known_eq (bytelen, GET_MODE_SIZE (mode)))
3053 : : {
3054 : 100238 : tmps[i] = gen_reg_rtx (mode);
3055 : 100238 : emit_move_insn (tmps[i], adjust_address (src, mode, bytepos));
3056 : : }
3057 : 502239 : else if (COMPLEX_MODE_P (mode)
3058 : 0 : && GET_MODE (src) == mode
3059 : 502239 : && known_eq (bytelen, GET_MODE_SIZE (mode)))
3060 : : /* Let emit_move_complex do the bulk of the work. */
3061 : 0 : tmps[i] = src;
3062 : 502239 : else if (GET_CODE (src) == CONCAT)
3063 : : {
3064 : 16616 : poly_int64 slen = GET_MODE_SIZE (GET_MODE (src));
3065 : 16616 : poly_int64 slen0 = GET_MODE_SIZE (GET_MODE (XEXP (src, 0)));
3066 : 8308 : unsigned int elt;
3067 : 8308 : poly_int64 subpos;
3068 : :
3069 : 8308 : if (can_div_trunc_p (bytepos, slen0, &elt, &subpos)
3070 : 8308 : && 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 : 5700 : tmps[i] = XEXP (src, elt);
3077 : 5700 : if (maybe_ne (subpos, 0)
3078 : 5700 : || maybe_ne (subpos + bytelen, slen0)
3079 : 11400 : || (!CONSTANT_P (tmps[i])
3080 : 5700 : && (!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 : 493931 : else if (CONSTANT_P (src) && GET_MODE (dst) != BLKmode
3099 : 37418 : && XVECLEN (dst, 0) > 1)
3100 : 37418 : tmps[i] = force_subreg (mode, src, GET_MODE (dst), bytepos);
3101 : 456513 : 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 : 456513 : else if (REG_P (src) && GET_MODE (src) == mode)
3119 : 0 : tmps[i] = src;
3120 : : else
3121 : 456513 : tmps[i] = extract_bit_field (src, bytelen * BITS_PER_UNIT,
3122 : 913026 : bytepos * BITS_PER_UNIT, 1, NULL_RTX,
3123 : : mode, mode, false, NULL);
3124 : :
3125 : 602477 : 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 : 11292 : emit_group_load (rtx dst, rtx src, tree type, poly_int64 ssize)
3138 : : {
3139 : 11292 : rtx *tmps;
3140 : 11292 : int i;
3141 : :
3142 : 11292 : tmps = XALLOCAVEC (rtx, XVECLEN (dst, 0));
3143 : 11292 : emit_group_load_1 (tmps, dst, src, type, ssize);
3144 : :
3145 : : /* Copy the extracted pieces into the proper (probable) hard regs. */
3146 : 31632 : for (i = 0; i < XVECLEN (dst, 0); i++)
3147 : : {
3148 : 20340 : rtx d = XEXP (XVECEXP (dst, 0, i), 0);
3149 : 20340 : if (d == NULL)
3150 : 0 : continue;
3151 : 20340 : emit_move_insn (d, tmps[i]);
3152 : : }
3153 : 11292 : }
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 : 295565 : emit_group_load_into_temps (rtx parallel, rtx src, tree type, poly_int64 ssize)
3161 : : {
3162 : 295565 : rtvec vec;
3163 : 295565 : int i;
3164 : :
3165 : 295565 : vec = rtvec_alloc (XVECLEN (parallel, 0));
3166 : 295565 : 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 : 877702 : for (i = 0; i < XVECLEN (parallel, 0); i++)
3171 : : {
3172 : 582137 : rtx e = XVECEXP (parallel, 0, i);
3173 : 582137 : rtx d = XEXP (e, 0);
3174 : :
3175 : 582137 : if (d)
3176 : : {
3177 : 582137 : d = force_reg (GET_MODE (d), RTVEC_ELT (vec, i));
3178 : 582137 : e = alloc_EXPR_LIST (REG_NOTE_KIND (e), d, XEXP (e, 1));
3179 : : }
3180 : 582137 : RTVEC_ELT (vec, i) = e;
3181 : : }
3182 : :
3183 : 295565 : 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 : 298585 : emit_group_move (rtx dst, rtx src)
3191 : : {
3192 : 298585 : int i;
3193 : :
3194 : 298585 : 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 : 885052 : for (i = XEXP (XVECEXP (src, 0, 0), 0) ? 0 : 1; i < XVECLEN (src, 0); i++)
3200 : 586467 : emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0),
3201 : 586467 : XEXP (XVECEXP (src, 0, i), 0));
3202 : 298585 : }
3203 : :
3204 : : /* Move a group of registers represented by a PARALLEL into pseudos. */
3205 : :
3206 : : rtx
3207 : 5690 : emit_group_move_into_temps (rtx src)
3208 : : {
3209 : 5690 : rtvec vec = rtvec_alloc (XVECLEN (src, 0));
3210 : 5690 : int i;
3211 : :
3212 : 13379 : for (i = 0; i < XVECLEN (src, 0); i++)
3213 : : {
3214 : 7689 : rtx e = XVECEXP (src, 0, i);
3215 : 7689 : rtx d = XEXP (e, 0);
3216 : :
3217 : 7689 : if (d)
3218 : 7689 : e = alloc_EXPR_LIST (REG_NOTE_KIND (e), copy_to_reg (d), XEXP (e, 1));
3219 : 7689 : RTVEC_ELT (vec, i) = e;
3220 : : }
3221 : :
3222 : 5690 : 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 : 66028 : emit_group_store (rtx orig_dst, rtx src, tree type ATTRIBUTE_UNUSED,
3232 : : poly_int64 ssize)
3233 : : {
3234 : 66028 : rtx *tmps, dst;
3235 : 66028 : int start, finish, i;
3236 : 66028 : machine_mode m = GET_MODE (orig_dst);
3237 : :
3238 : 66028 : gcc_assert (GET_CODE (src) == PARALLEL);
3239 : :
3240 : 66028 : if (!SCALAR_INT_MODE_P (m)
3241 : 14041 : && !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 : 66028 : if (XEXP (XVECEXP (src, 0, 0), 0))
3262 : : start = 0;
3263 : : else
3264 : 0 : start = 1;
3265 : 66028 : finish = XVECLEN (src, 0);
3266 : :
3267 : 66028 : tmps = XALLOCAVEC (rtx, finish);
3268 : :
3269 : : /* Copy the (probable) hard regs into pseudos. */
3270 : 190048 : for (i = start; i < finish; i++)
3271 : : {
3272 : 124020 : rtx reg = XEXP (XVECEXP (src, 0, i), 0);
3273 : 124020 : if (!REG_P (reg) || REGNO (reg) < FIRST_PSEUDO_REGISTER)
3274 : : {
3275 : 116331 : tmps[i] = gen_reg_rtx (GET_MODE (reg));
3276 : 116331 : emit_move_insn (tmps[i], reg);
3277 : : }
3278 : : else
3279 : 7689 : 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 : 66028 : dst = orig_dst;
3285 : 66028 : 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 : 66028 : else if (!MEM_P (dst) && GET_CODE (dst) != CONCAT)
3304 : : {
3305 : 51371 : machine_mode outer = GET_MODE (dst);
3306 : 51371 : machine_mode inner;
3307 : 51371 : poly_int64 bytepos;
3308 : 51371 : bool done = false;
3309 : 51371 : rtx temp;
3310 : :
3311 : 51371 : 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 : 51371 : if (start < finish)
3318 : : {
3319 : 51371 : inner = GET_MODE (tmps[start]);
3320 : 51371 : bytepos = subreg_lowpart_offset (inner, outer);
3321 : 51371 : if (known_eq (rtx_to_poly_int64 (XEXP (XVECEXP (src, 0, start), 1)),
3322 : : bytepos))
3323 : : {
3324 : 51347 : temp = force_subreg (outer, tmps[start], inner, 0);
3325 : 51347 : if (temp)
3326 : : {
3327 : 50694 : emit_move_insn (dst, temp);
3328 : 50694 : done = true;
3329 : 50694 : start++;
3330 : : }
3331 : : }
3332 : : }
3333 : :
3334 : : /* If the first element wasn't the low part, try the last. */
3335 : 50694 : 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 : 50694 : if (!done)
3356 : 677 : emit_move_insn (dst, CONST0_RTX (outer));
3357 : : }
3358 : :
3359 : : /* Process the pieces. */
3360 : 136021 : for (i = start; i < finish; i++)
3361 : : {
3362 : 73326 : poly_int64 bytepos = rtx_to_poly_int64 (XEXP (XVECEXP (src, 0, i), 1));
3363 : 73326 : machine_mode mode = GET_MODE (tmps[i]);
3364 : 146652 : poly_int64 bytelen = GET_MODE_SIZE (mode);
3365 : 73326 : poly_uint64 adj_bytelen;
3366 : 73326 : 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 : 73326 : gcc_checking_assert (ordered_p (bytepos + bytelen, ssize));
3373 : 145827 : if (known_size_p (ssize) && maybe_gt (bytepos + bytelen, ssize))
3374 : 825 : adj_bytelen = ssize - bytepos;
3375 : : else
3376 : 73326 : 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 : 73326 : if (GET_CODE (dst) == CONCAT)
3381 : : {
3382 : 27766 : if (known_le (bytepos + adj_bytelen,
3383 : : GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)))))
3384 : : dest = XEXP (dst, 0);
3385 : :
3386 : 17216 : else if (known_ge (bytepos, GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)))))
3387 : : {
3388 : 10550 : bytepos -= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)));
3389 : 5275 : 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 : 69993 : 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 : 766 : 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 : 766 : store_bit_field (dest,
3474 : 766 : adj_bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
3475 : 2298 : 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 : 69227 : else if (MEM_P (dest)
3481 : 7529 : && (!targetm.slow_unaligned_access (mode, MEM_ALIGN (dest))
3482 : 0 : || MEM_ALIGN (dest) >= GET_MODE_ALIGNMENT (mode))
3483 : 15058 : && multiple_p (bytepos * BITS_PER_UNIT,
3484 : : GET_MODE_ALIGNMENT (mode))
3485 : 76756 : && known_eq (bytelen, GET_MODE_SIZE (mode)))
3486 : 7529 : emit_move_insn (adjust_address (dest, mode, bytepos), tmps[i]);
3487 : :
3488 : : else
3489 : 123396 : 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 : 66028 : 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 : 328708 : maybe_emit_group_store (rtx x, tree type)
3503 : : {
3504 : 328708 : machine_mode mode = TYPE_MODE (type);
3505 : 328708 : gcc_checking_assert (GET_MODE (x) == VOIDmode || GET_MODE (x) == mode);
3506 : 328708 : 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 : 3415 : copy_blkmode_to_reg (machine_mode mode_in, tree src)
3634 : : {
3635 : 3415 : int i, n_regs;
3636 : 3415 : unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0, bytes;
3637 : 3415 : unsigned int bitsize;
3638 : 3415 : 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 : 3415 : fixed_size_mode mode = as_a <fixed_size_mode> (mode_in);
3641 : 3415 : fixed_size_mode dst_mode;
3642 : 3415 : scalar_int_mode min_mode;
3643 : :
3644 : 3415 : gcc_assert (TYPE_MODE (TREE_TYPE (src)) == BLKmode);
3645 : :
3646 : 3415 : x = expand_normal (src);
3647 : :
3648 : 3415 : bytes = arg_int_size_in_bytes (TREE_TYPE (src));
3649 : 3415 : 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 : 11499270 : use_reg_mode (rtx *call_fusage, rtx reg, machine_mode mode)
3761 : : {
3762 : 11499270 : gcc_assert (REG_P (reg));
3763 : :
3764 : 11499270 : if (!HARD_REGISTER_P (reg))
3765 : : return;
3766 : :
3767 : 11499270 : *call_fusage
3768 : 11499270 : = 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 : 302767 : use_group_regs (rtx *call_fusage, rtx regs)
3803 : : {
3804 : 302767 : int i;
3805 : :
3806 : 899308 : for (i = 0; i < XVECLEN (regs, 0); i++)
3807 : : {
3808 : 596541 : 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 : 596541 : if (reg != 0 && REG_P (reg))
3814 : 596541 : use_reg (call_fusage, reg);
3815 : : }
3816 : 302767 : }
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 : 11737693 : get_def_for_expr (tree name, enum tree_code code)
3824 : : {
3825 : 11737693 : gimple *def_stmt;
3826 : :
3827 : 11737693 : if (TREE_CODE (name) != SSA_NAME)
3828 : : return NULL;
3829 : :
3830 : 9156893 : def_stmt = get_gimple_for_ssa_name (name);
3831 : 9156893 : if (!def_stmt
3832 : 1941418 : || !is_gimple_assign (def_stmt)
3833 : 11096962 : || 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 : 16218 : get_def_for_expr_class (tree name, enum tree_code_class tclass)
3845 : : {
3846 : 16218 : gimple *def_stmt;
3847 : :
3848 : 16218 : if (TREE_CODE (name) != SSA_NAME)
3849 : : return NULL;
3850 : :
3851 : 16218 : def_stmt = get_gimple_for_ssa_name (name);
3852 : 16218 : if (!def_stmt
3853 : 14072 : || !is_gimple_assign (def_stmt)
3854 : 30290 : || 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 : 129056 : 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 : 129056 : machine_mode mode = GET_MODE (object);
3872 : 129056 : unsigned int align;
3873 : :
3874 : 129056 : 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 : 129056 : poly_int64 size_val;
3879 : 129056 : if (mode != BLKmode
3880 : 54372 : && poly_int_rtx_p (size, &size_val)
3881 : 183428 : && known_eq (size_val, GET_MODE_SIZE (mode)))
3882 : : {
3883 : 54372 : rtx zero = CONST0_RTX (mode);
3884 : 54372 : if (zero != NULL)
3885 : : {
3886 : 54372 : emit_move_insn (object, zero);
3887 : 54372 : 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 : 74684 : if (size == const0_rtx)
3903 : : return NULL;
3904 : :
3905 : 74684 : align = MEM_ALIGN (object);
3906 : :
3907 : 74684 : if (CONST_INT_P (size)
3908 : 142263 : && targetm.use_by_pieces_infrastructure_p (INTVAL (size), align,
3909 : : CLEAR_BY_PIECES,
3910 : 67579 : optimize_insn_for_speed_p ()))
3911 : 52693 : clear_by_pieces (object, INTVAL (size), align);
3912 : 21991 : 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 : 14660 : else if (try_store_by_multiple_pieces (object, size, ctz_size,
3917 : : min_size, max_size,
3918 : : NULL_RTX, 0, align))
3919 : : ;
3920 : 14402 : else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object)))
3921 : 14402 : return set_storage_via_libcall (object, size, const0_rtx,
3922 : 14402 : method == BLOCK_OP_TAILCALL);
3923 : : else
3924 : 0 : gcc_unreachable ();
3925 : :
3926 : : return NULL;
3927 : : }
3928 : :
3929 : : rtx
3930 : 107599 : clear_storage (rtx object, rtx size, enum block_op_methods method)
3931 : : {
3932 : 107599 : unsigned HOST_WIDE_INT max, min = 0;
3933 : 107599 : if (GET_CODE (size) == CONST_INT)
3934 : 107599 : min = max = UINTVAL (size);
3935 : : else
3936 : 0 : max = GET_MODE_MASK (GET_MODE (size));
3937 : 107599 : 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 : 14406 : set_storage_via_libcall (rtx object, rtx size, rtx val, bool tailcall)
3946 : : {
3947 : 14406 : tree call_expr, fn, object_tree, size_tree, val_tree;
3948 : 14406 : machine_mode size_mode;
3949 : :
3950 : 14406 : object = copy_addr_to_reg (XEXP (object, 0));
3951 : 14406 : object_tree = make_tree (ptr_type_node, object);
3952 : :
3953 : 14406 : if (!CONST_INT_P (val))
3954 : 3 : val = convert_to_mode (TYPE_MODE (integer_type_node), val, 1);
3955 : 14406 : val_tree = make_tree (integer_type_node, val);
3956 : :
3957 : 14406 : size_mode = TYPE_MODE (sizetype);
3958 : 14406 : size = convert_to_mode (size_mode, size, 1);
3959 : 14406 : size = copy_to_mode_reg (size_mode, size);
3960 : 14406 : 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 : 14406 : fn = builtin_decl_implicit (BUILT_IN_MEMSET);
3965 : 14406 : call_expr = build_call_expr (fn, 3, object_tree, val_tree, size_tree);
3966 : 14406 : CALL_EXPR_TAILCALL (call_expr) = tailcall;
3967 : :
3968 : 14406 : return expand_call (call_expr, NULL_RTX, false);
3969 : : }
3970 : :
3971 : : /* Expand a setmem pattern; return true if successful. */
3972 : :
3973 : : bool
3974 : 30895 : 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 : 30895 : if (expected_align < align)
3985 : : expected_align = align;
3986 : 30895 : 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 : 30895 : opt_scalar_int_mode mode_iter;
3995 : 200264 : FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_INT)
3996 : : {
3997 : 178889 : scalar_int_mode mode = mode_iter.require ();
3998 : 178889 : enum insn_code code = direct_optab_handler (setmem_optab, mode);
3999 : :
4000 : 178889 : 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 : 178889 : && ((CONST_INT_P (size)
4007 : 24094 : && ((unsigned HOST_WIDE_INT) INTVAL (size)
4008 : 24094 : <= (GET_MODE_MASK (mode) >> 1)))
4009 : 27322 : || max_size <= (GET_MODE_MASK (mode) >> 1)
4010 : 30078 : || GET_MODE_BITSIZE (mode) >= GET_MODE_BITSIZE (Pmode)))
4011 : : {
4012 : 40731 : class expand_operand ops[9];
4013 : 40731 : unsigned int nops;
4014 : :
4015 : 40731 : nops = insn_data[(int) code].n_generator_args;
4016 : 40731 : gcc_assert (nops == 4 || nops == 6 || nops == 8 || nops == 9);
4017 : :
4018 : 40731 : create_fixed_operand (&ops[0], object);
4019 : : /* The check above guarantees that this size conversion is valid. */
4020 : 40731 : create_convert_operand_to (&ops[1], size, mode, true);
4021 : 40731 : create_convert_operand_from (&ops[2], val, byte_mode, true);
4022 : 40731 : create_integer_operand (&ops[3], align / BITS_PER_UNIT);
4023 : 40731 : if (nops >= 6)
4024 : : {
4025 : 40731 : create_integer_operand (&ops[4], expected_align / BITS_PER_UNIT);
4026 : 40731 : create_integer_operand (&ops[5], expected_size);
4027 : : }
4028 : 40731 : if (nops >= 8)
4029 : : {
4030 : 40731 : create_integer_operand (&ops[6], min_size);
4031 : : /* If we cannot represent the maximal size,
4032 : : make parameter NULL. */
4033 : 40731 : if ((HOST_WIDE_INT) max_size != -1)
4034 : 38387 : create_integer_operand (&ops[7], max_size);
4035 : : else
4036 : 2344 : create_fixed_operand (&ops[7], NULL);
4037 : : }
4038 : 40731 : if (nops == 9)
4039 : : {
4040 : : /* If we cannot represent the maximal size,
4041 : : make parameter NULL. */
4042 : 40731 : if ((HOST_WIDE_INT) probable_max_size != -1)
4043 : 38882 : create_integer_operand (&ops[8], probable_max_size);
4044 : : else
4045 : 1849 : create_fixed_operand (&ops[8], NULL);
4046 : : }
4047 : 40731 : if (maybe_expand_insn (code, nops, ops))
4048 : 9520 : 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 : 556840 : write_complex_part (rtx cplx, rtx val, bool imag_p, bool undefined_p)
4062 : : {
4063 : 556840 : machine_mode cmode;
4064 : 556840 : scalar_mode imode;
4065 : 556840 : unsigned ibitsize;
4066 : :
4067 : 556840 : if (GET_CODE (cplx) == CONCAT)
4068 : : {
4069 : 493910 : emit_move_insn (XEXP (cplx, imag_p), val);
4070 : 493910 : return;
4071 : : }
4072 : :
4073 : 62930 : cmode = GET_MODE (cplx);
4074 : 62930 : imode = GET_MODE_INNER (cmode);
4075 : 62930 : 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 : 62930 : if (MEM_P (cplx))
4083 : : {
4084 : 76056 : emit_move_insn (adjust_address_nv (cplx, imode,
4085 : : imag_p ? GET_MODE_SIZE (imode) : 0),
4086 : : val);
4087 : 50704 : 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 : 12226 : 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 : 12226 : || (REG_P (cplx)
4100 : 7306 : && REGNO (cplx) < FIRST_PSEUDO_REGISTER
4101 : 7120 : && REG_NREGS (cplx) % 2 == 0))
4102 : : {
4103 : 4936 : rtx part = simplify_gen_subreg (imode, cplx, cmode,
4104 : 7404 : imag_p ? GET_MODE_SIZE (imode) : 0);
4105 : 4936 : if (part)
4106 : : {
4107 : 4936 : emit_move_insn (part, val);
4108 : 4936 : 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 : 504612 : read_complex_part (rtx cplx, bool imag_p)
4124 : : {
4125 : 504612 : machine_mode cmode;
4126 : 504612 : scalar_mode imode;
4127 : 504612 : unsigned ibitsize;
4128 : :
4129 : 504612 : if (GET_CODE (cplx) == CONCAT)
4130 : 326670 : return XEXP (cplx, imag_p);
4131 : :
4132 : 177942 : cmode = GET_MODE (cplx);
4133 : 177942 : imode = GET_MODE_INNER (cmode);
4134 : 177942 : ibitsize = GET_MODE_BITSIZE (imode);
4135 : :
4136 : : /* Special case reads from complex constants that got spilled to memory. */
4137 : 177942 : if (MEM_P (cplx) && GET_CODE (XEXP (cplx, 0)) == SYMBOL_REF)
4138 : : {
4139 : 37919 : tree decl = SYMBOL_REF_DECL (XEXP (cplx, 0));
4140 : 37919 : 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 : 177942 : if (MEM_P (cplx))
4154 : 235757 : 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 : 20663 : 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 : 20663 : || (REG_P (cplx)
4167 : 338 : && REGNO (cplx) < FIRST_PSEUDO_REGISTER
4168 : 292 : && REG_NREGS (cplx) % 2 == 0))
4169 : : {
4170 : 10167 : rtx ret = simplify_gen_subreg (imode, cplx, cmode,
4171 : 15250 : imag_p ? GET_MODE_SIZE (imode) : 0);
4172 : 10167 : 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 : 242888 : emit_move_change_mode (machine_mode new_mode,
4190 : : machine_mode old_mode, rtx x, bool force)
4191 : : {
4192 : 242888 : rtx ret;
4193 : :
4194 : 242888 : 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 : 241570 : 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 : 52786 : 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 : 52786 : 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 : 188784 : if (force)
4222 : 188784 : 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 : 242888 : 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 : 121444 : emit_move_via_integer (machine_mode mode, rtx x, rtx y, bool force)
4236 : : {
4237 : 121444 : scalar_int_mode imode;
4238 : 121444 : enum insn_code code;
4239 : :
4240 : : /* There must exist a mode of the exact size we require. */
4241 : 121444 : if (!int_mode_for_mode (mode).exists (&imode))
4242 : 0 : return NULL;
4243 : :
4244 : : /* The target must support moves in this mode. */
4245 : 121444 : code = optab_handler (mov_optab, imode);
4246 : 121444 : if (code == CODE_FOR_nothing)
4247 : : return NULL;
4248 : :
4249 : 121444 : x = emit_move_change_mode (imode, mode, x, force);
4250 : 121444 : if (x == NULL_RTX)
4251 : : return NULL;
4252 : 121444 : y = emit_move_change_mode (imode, mode, y, force);
4253 : 121444 : if (y == NULL_RTX)
4254 : : return NULL;
4255 : 121444 : 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 : 81433 : 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 : 81433 : if (!reload_completed && !reload_in_progress
4366 : 162866 : && REG_P (x) && !reg_overlap_mentioned_p (x, y))
4367 : 6106 : emit_clobber (x);
4368 : :
4369 : 81433 : write_complex_part (x, read_complex_part (y, false), false, true);
4370 : 81433 : write_complex_part (x, read_complex_part (y, true), true, false);
4371 : :
4372 : 81433 : 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 : 85812 : emit_move_complex (machine_mode mode, rtx x, rtx y)
4380 : : {
4381 : 85812 : 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 : 85812 : 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 : 81039 : if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
4391 : 72835 : && optab_handler (mov_optab, GET_MODE_INNER (mode)) != CODE_FOR_nothing
4392 : 72835 : && !(REG_P (x)
4393 : 2200 : && HARD_REGISTER_P (x)
4394 : 564 : && REG_NREGS (x) == 1)
4395 : 153874 : && !(REG_P (y)
4396 : 3276 : && HARD_REGISTER_P (y)
4397 : 1638 : && REG_NREGS (y) == 1))
4398 : : try_int = false;
4399 : : /* Not possible if the values are inherently not adjacent. */
4400 : 8204 : 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 : 755 : else if (register_operand (x, mode) && register_operand (y, mode))
4404 : : try_int = true;
4405 : : /* If one of the operands is a memory, and alignment constraints
4406 : : are friendly enough, we may be able to do combined memory operations.
4407 : : We do not attempt this if Y is a constant because that combination is
4408 : : usually better with the by-parts thing below. */
4409 : 633 : else if ((MEM_P (x) ? !CONSTANT_P (y) : MEM_P (y))
4410 : : && (!STRICT_ALIGNMENT
4411 : : || get_mode_alignment (mode) == BIGGEST_ALIGNMENT))
4412 : : try_int = true;
4413 : : else
4414 : : try_int = false;
4415 : :
4416 : : if (try_int)
4417 : : {
4418 : 755 : 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 : 755 : if (MEM_P (x) && MEM_P (y))
4424 : : {
4425 : 724 : emit_block_move (x, y, gen_int_mode (GET_MODE_SIZE (mode), Pmode),
4426 : 359 : (optimize_insn_for_speed_p()
4427 : : ? BLOCK_OP_NO_LIBCALL : BLOCK_OP_NORMAL));
4428 : 359 : return get_last_insn ();
4429 : : }
4430 : :
4431 : 396 : ret = emit_move_via_integer (mode, x, y, true);
4432 : 396 : if (ret)
4433 : : return ret;
4434 : : }
4435 : :
4436 : 80284 : 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 : 76163049 : emit_move_insn_1 (rtx x, rtx y)
4572 : : {
4573 : 76163049 : machine_mode mode = GET_MODE (x);
4574 : 76163049 : enum insn_code code;
4575 : :
4576 : 76163049 : gcc_assert ((unsigned int) mode < (unsigned int) MAX_MACHINE_MODE);
4577 : :
4578 : 76163049 : code = optab_handler (mov_optab, mode);
4579 : 76163049 : if (code != CODE_FOR_nothing)
4580 : 75956189 : return emit_insn (GEN_FCN (code) (x, y));
4581 : :
4582 : : /* Expand complex moves by moving real part and imag part. */
4583 : 206860 : if (COMPLEX_MODE_P (mode))
4584 : 85812 : 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 : 121048 : 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 : 121048 : 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 : 70284389 : emit_move_insn (rtx x, rtx y)
4629 : : {
4630 : 70284389 : machine_mode mode = GET_MODE (x);
4631 : 70284389 : rtx y_cst = NULL_RTX;
4632 : 70284389 : rtx_insn *last_insn;
4633 : 70284389 : rtx set;
4634 : :
4635 : 70284389 : 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 : 70284389 : rtx x_inner = NULL_RTX;
4649 : 70284389 : rtx y_inner = NULL_RTX;
4650 : :
4651 : 73001812 : auto candidate_subreg_p = [&](rtx subreg) {
4652 : 2717423 : return (REG_P (SUBREG_REG (subreg))
4653 : 8150532 : && known_eq (GET_MODE_SIZE (GET_MODE (SUBREG_REG (subreg))),
4654 : : GET_MODE_SIZE (GET_MODE (subreg)))
4655 : 3022225 : && optab_handler (mov_optab, GET_MODE (SUBREG_REG (subreg)))
4656 : 2717423 : != CODE_FOR_nothing);
4657 : : };
4658 : :
4659 : 70290155 : auto candidate_mem_p = [&](machine_mode innermode, rtx mem) {
4660 : 5766 : return (!targetm.can_change_mode_class (innermode, GET_MODE (mem), ALL_REGS)
4661 : 5766 : && !push_operand (mem, GET_MODE (mem))
4662 : : /* Not a candiate if innermode requires too much alignment. */
4663 : 11472 : && (MEM_ALIGN (mem) >= GET_MODE_ALIGNMENT (innermode)
4664 : 234 : || targetm.slow_unaligned_access (GET_MODE (mem),
4665 : 117 : MEM_ALIGN (mem))
4666 : 234 : || !targetm.slow_unaligned_access (innermode,
4667 : 117 : MEM_ALIGN (mem))));
4668 : : };
4669 : :
4670 : 70284389 : if (SUBREG_P (x) && candidate_subreg_p (x))
4671 : 9336 : x_inner = SUBREG_REG (x);
4672 : :
4673 : 70284389 : if (SUBREG_P (y) && candidate_subreg_p (y))
4674 : 294140 : y_inner = SUBREG_REG (y);
4675 : :
4676 : 70284389 : if (x_inner != NULL_RTX
4677 : 70284389 : && y_inner != NULL_RTX
4678 : 1082 : && GET_MODE (x_inner) == GET_MODE (y_inner)
4679 : 70285078 : && !targetm.can_change_mode_class (GET_MODE (x_inner), mode, ALL_REGS))
4680 : : {
4681 : 689 : x = x_inner;
4682 : 689 : y = y_inner;
4683 : 689 : mode = GET_MODE (x_inner);
4684 : : }
4685 : 70283700 : else if (x_inner != NULL_RTX
4686 : 8647 : && MEM_P (y)
4687 : 70283964 : && candidate_mem_p (GET_MODE (x_inner), y))
4688 : : {
4689 : 264 : x = x_inner;
4690 : 264 : y = adjust_address (y, GET_MODE (x_inner), 0);
4691 : 264 : mode = GET_MODE (x_inner);
4692 : : }
4693 : 70283436 : else if (y_inner != NULL_RTX
4694 : 293451 : && MEM_P (x)
4695 : 70288938 : && candidate_mem_p (GET_MODE (y_inner), x))
4696 : : {
4697 : 5442 : x = adjust_address (x, GET_MODE (y_inner), 0);
4698 : 5442 : y = y_inner;
4699 : 5442 : mode = GET_MODE (y_inner);
4700 : : }
4701 : 70277994 : else if (x_inner != NULL_RTX
4702 : 8383 : && CONSTANT_P (y)
4703 : 465 : && !targetm.can_change_mode_class (GET_MODE (x_inner),
4704 : : mode, ALL_REGS)
4705 : 70278459 : && (y_inner = simplify_subreg (GET_MODE (x_inner), y, mode, 0)))
4706 : : {
4707 : 465 : x = x_inner;
4708 : 465 : y = y_inner;
4709 : 465 : mode = GET_MODE (x_inner);
4710 : : }
4711 : :
4712 : 70284389 : if (CONSTANT_P (y))
4713 : : {
4714 : 16473161 : if (optimize
4715 : 12870287 : && SCALAR_FLOAT_MODE_P (GET_MODE (x))
4716 : 17236626 : && (last_insn = compress_float_constant (x, y)))
4717 : : return last_insn;
4718 : :
4719 : 16404512 : y_cst = y;
4720 : :
4721 : 16404512 : if (!targetm.legitimate_constant_p (mode, y))
4722 : : {
4723 : 494202 : 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 : 494202 : if (!y)
4729 : : y = y_cst;
4730 : : else
4731 : 474269 : 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 : 70215740 : if (MEM_P (x)
4738 : 86195631 : && (! memory_address_addr_space_p (GET_MODE (x), XEXP (x, 0),
4739 : 13739379 : MEM_ADDR_SPACE (x))
4740 : 2240679 : && ! push_operand (x, GET_MODE (x))))
4741 : 167 : x = validize_mem (x);
4742 : :
4743 : 70215740 : if (MEM_P (y)
4744 : 87954892 : && ! memory_address_addr_space_p (GET_MODE (y), XEXP (y, 0),
4745 : 17739152 : MEM_ADDR_SPACE (y)))
4746 : 9273 : y = validize_mem (y);
4747 : :
4748 : 70215740 : gcc_assert (mode != BLKmode);
4749 : :
4750 : 70215740 : last_insn = emit_move_insn_1 (x, y);
4751 : :
4752 : 16404512 : if (y_cst && REG_P (x)
4753 : 12067007 : && (set = single_set (last_insn)) != NULL_RTX
4754 : 12067007 : && SET_DEST (set) == x
4755 : 82268313 : && ! rtx_equal_p (y_cst, SET_SRC (set)))
4756 : 1214884 : 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 : 5947229 : gen_move_insn (rtx x, rtx y)
4766 : : {
4767 : 5947229 : start_sequence ();
4768 : 5947229 : emit_move_insn_1 (x, y);
4769 : 5947229 : 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 : 763465 : compress_float_constant (rtx x, rtx y)
4778 : : {
4779 : 763465 : machine_mode dstmode = GET_MODE (x);
4780 : 763465 : machine_mode orig_srcmode = GET_MODE (y);
4781 : 763465 : machine_mode srcmode;
4782 : 763465 : const REAL_VALUE_TYPE *r;
4783 : 763465 : int oldcost, newcost;
4784 : 763465 : bool speed = optimize_insn_for_speed_p ();
4785 : :
4786 : 763465 : r = CONST_DOUBLE_REAL_VALUE (y);
4787 : :
4788 : 763465 : if (targetm.legitimate_constant_p (dstmode, y))
4789 : 762019 : oldcost = set_src_cost (y, orig_srcmode, speed);
4790 : : else
4791 : 1446 : oldcost = set_src_cost (force_const_mem (dstmode, y), dstmode, speed);
4792 : :
4793 : 2699653 : FOR_EACH_MODE_UNTIL (srcmode, orig_srcmode)
4794 : : {
4795 : 2004837 : enum insn_code ic;
4796 : 2004837 : rtx trunc_y;
4797 : 2004837 : rtx_insn *last_insn;
4798 : :
4799 : : /* Skip if the target can't extend this way. */
4800 : 2004837 : ic = can_extend_p (dstmode, srcmode, 0);
4801 : 2004837 : if (ic == CODE_FOR_nothing)
4802 : 1595523 : continue;
4803 : :
4804 : : /* Skip if the narrowed value isn't exact. */
4805 : 409314 : if (! exact_real_truncate (srcmode, r))
4806 : 51872 : continue;
4807 : :
4808 : 357442 : trunc_y = const_double_from_real_value (*r, srcmode);
4809 : :
4810 : 357442 : if (targetm.legitimate_constant_p (srcmode, trunc_y))
4811 : : {
4812 : : /* Skip if the target needs extra instructions to perform
4813 : : the extension. */
4814 : 353379 : if (!insn_operand_matches (ic, 1, trunc_y))
4815 : 3346 : continue;
4816 : : /* This is valid, but may not be cheaper than the original. */
4817 : 350033 : newcost = set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y),
4818 : : dstmode, speed);
4819 : 350033 : if (oldcost < newcost)
4820 : 281384 : continue;
4821 : : }
4822 : 4063 : 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 : 4063 : 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 : 68649 : 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 : 68649 : rtx target = x;
4843 : 68649 : if (REG_P (x) && HARD_REGISTER_P (x))
4844 : 1 : target = gen_reg_rtx (dstmode);
4845 : :
4846 : 68649 : emit_unop_insn (ic, target, trunc_y, UNKNOWN);
4847 : 68649 : last_insn = get_last_insn ();
4848 : :
4849 : 68649 : if (REG_P (target))
4850 : 57715 : set_unique_reg_note (last_insn, REG_EQUAL, y);
4851 : :
4852 : 68649 : 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 : 268055 : push_block (rtx size, poly_int64 extra, int below)
4872 : : {
4873 : 268055 : rtx temp;
4874 : :
4875 : 333184 : size = convert_modes (Pmode, ptr_mode, size, 1);
4876 : 268055 : if (CONSTANT_P (size))
4877 : 333184 : 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 : 268055 : if (STACK_GROWS_DOWNWARD)
4891 : : {
4892 : 268055 : temp = virtual_outgoing_args_rtx;
4893 : 268055 : 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 : 268055 : 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 : 2573330 : mem_autoinc_base (rtx mem)
4918 : : {
4919 : 0 : if (MEM_P (mem))
4920 : : {
4921 : 1573450 : rtx addr = XEXP (mem, 0);
4922 : 1573450 : if (GET_RTX_CLASS (GET_CODE (addr)) == RTX_AUTOINC)
4923 : 1028014 : 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 : 4417997 : find_args_size_adjust (rtx_insn *insn)
4950 : : {
4951 : 4417997 : rtx dest, set, pat;
4952 : 4417997 : int i;
4953 : :
4954 : 4417997 : pat = PATTERN (insn);
4955 : 4417997 : set = NULL;
4956 : :
4957 : : /* Look for a call_pop pattern. */
4958 : 4417997 : 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 : 2776136 : if (GET_CODE (pat) != PARALLEL)
4963 : 2761845 : 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 : 14291 : for (i = XVECLEN (pat, 0) - 1; i > 0; --i)
4969 : : {
4970 : 14291 : set = XVECEXP (pat, 0, i);
4971 : 14291 : if (GET_CODE (set) != SET)
4972 : 0 : continue;
4973 : 14291 : dest = SET_DEST (set);
4974 : 14291 : if (dest == stack_pointer_rtx)
4975 : : break;
4976 : : }
4977 : : /* We'd better have found the stack pointer adjust. */
4978 : 14291 : 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 : 1641861 : else if (GET_CODE (pat) == SET)
4984 : : set = pat;
4985 : 252550 : else if ((set = single_set (insn)) != NULL)
4986 : : ;
4987 : 47659 : 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 : 47659 : return 0;
5012 : :
5013 : 1608493 : dest = SET_DEST (set);
5014 : :
5015 : : /* Look for direct modifications of the stack pointer. */
5016 : 1608493 : 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 : 321828 : poly_int64 offset;
5022 : 321828 : if (SCALAR_INT_MODE_P (GET_MODE (dest))
5023 : 321828 : && strip_offset (SET_SRC (set), &offset) == stack_pointer_rtx)
5024 : 319447 : return offset;
5025 : : /* ??? Reload can generate no-op moves, which will be cleaned
5026 : : up later. Recognize it and continue searching. */
5027 : 2381 : else if (rtx_equal_p (dest, SET_SRC (set)))
5028 : 0 : return 0;
5029 : : else
5030 : 2381 : return HOST_WIDE_INT_MIN;
5031 : : }
5032 : : else
5033 : : {
5034 : 1286665 : rtx mem, addr;
5035 : :
5036 : : /* Otherwise only think about autoinc patterns. */
5037 : 2328600 : if (mem_autoinc_base (dest) == stack_pointer_rtx)
5038 : : {
5039 : 919305 : mem = dest;
5040 : 1273732 : gcc_checking_assert (mem_autoinc_base (SET_SRC (set))
5041 : : != stack_pointer_rtx);
5042 : : }
5043 : 544448 : else if (mem_autoinc_base (SET_SRC (set)) == stack_pointer_rtx)
5044 : : mem = SET_SRC (set);
5045 : : else
5046 : 258651 : return 0;
5047 : :
5048 : 1028014 : addr = XEXP (mem, 0);
5049 : 1028014 : switch (GET_CODE (addr))
5050 : : {
5051 : 108709 : case PRE_INC:
5052 : 108709 : case POST_INC:
5053 : 217418 : return GET_MODE_SIZE (GET_MODE (mem));
5054 : 901359 : case PRE_DEC:
5055 : 901359 : case POST_DEC:
5056 : 1802718 : return -GET_MODE_SIZE (GET_MODE (mem));
5057 : 17946 : case PRE_MODIFY:
5058 : 17946 : case POST_MODIFY:
5059 : 17946 : addr = XEXP (addr, 1);
5060 : 17946 : gcc_assert (GET_CODE (addr) == PLUS);
5061 : 17946 : gcc_assert (XEXP (addr, 0) == stack_pointer_rtx);
5062 : 17946 : return rtx_to_poly_int64 (XEXP (addr, 1));
5063 : 0 : default:
5064 : 0 : gcc_unreachable ();
5065 : : }
5066 : : }
5067 : : }
5068 : :
5069 : : poly_int64
5070 : 663745 : fixup_args_size_notes (rtx_insn *prev, rtx_insn *last,
5071 : : poly_int64 end_args_size)
5072 : : {
5073 : 663745 : poly_int64 args_size = end_args_size;
5074 : 663745 : bool saw_unknown = false;
5075 : 663745 : rtx_insn *insn;
5076 : :
5077 : 1896880 : for (insn = last; insn != prev; insn = PREV_INSN (insn))
5078 : : {
5079 : 1233135 : 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 : 1233135 : rtx note = find_reg_note (insn, REG_ARGS_SIZE, NULL_RTX);
5088 : 1233135 : gcc_assert (!note || known_eq (args_size, get_args_size (note)));
5089 : :
5090 : 1233135 : poly_int64 this_delta = find_args_size_adjust (insn);
5091 : 1233135 : if (known_eq (this_delta, 0))
5092 : : {
5093 : 609043 : if (!CALL_P (insn)
5094 : 5 : || ACCUMULATE_OUTGOING_ARGS
5095 : 304529 : || find_reg_note (insn, REG_NORETURN, NULL_RTX) == NULL_RTX)
5096 : 304519 : continue;
5097 : : }
5098 : :
5099 : 928616 : gcc_assert (!saw_unknown);
5100 : 928616 : if (known_eq (this_delta, HOST_WIDE_INT_MIN))
5101 : 2358 : saw_unknown = true;
5102 : :
5103 : 928616 : if (!note)
5104 : 928616 : add_args_size_note (insn, args_size);
5105 : : if (STACK_GROWS_DOWNWARD)
5106 : 928616 : this_delta = -poly_uint64 (this_delta);
5107 : :
5108 : 928616 : if (saw_unknown)
5109 : : args_size = HOST_WIDE_INT_MIN;
5110 : : else
5111 : 1233135 : args_size -= this_delta;
5112 : : }
5113 : :
5114 : 663745 : return args_size;
5115 : : }
5116 : :
5117 : : #ifdef PUSH_ROUNDING
5118 : : /* Emit single push insn. */
5119 : :
5120 : : static void
5121 : 1828605 : emit_single_push_insn_1 (machine_mode mode, rtx x, tree type)
5122 : : {
5123 : 1828605 : rtx dest_addr;
5124 : 3657210 : poly_int64 rounded_size = PUSH_ROUNDING (GET_MODE_SIZE (mode));
5125 : 1828605 : rtx dest;
5126 : 1828605 : 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 : 1828605 : icode = optab_handler (push_optab, mode);
5131 : 1828605 : 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 : 3657210 : if (known_eq (GET_MODE_SIZE (mode), rounded_size))
5140 : 3159969 : 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 : 102724 : 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 : 103268 : 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 : 103268 : dest_addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, dest_addr);
5178 : : }
5179 : :
5180 : 1828605 : dest = gen_rtx_MEM (mode, dest_addr);
5181 : :
5182 : 1828605 : if (type != 0)
5183 : : {
5184 : 1828558 : set_mem_attributes (dest, type, 1);
5185 : :
5186 : 1828558 : 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 : 137589 : set_mem_alias_set (dest, 0);
5192 : : }
5193 : 1828605 : emit_move_insn (dest, x);
5194 : : }
5195 : :
5196 : : /* Emit and annotate a single push insn. */
5197 : :
5198 : : static void
5199 : 1828605 : emit_single_push_insn (machine_mode mode, rtx x, tree type)
5200 : : {
5201 : 1828605 : poly_int64 delta, old_delta = stack_pointer_delta;
5202 : 1828605 : rtx_insn *prev = get_last_insn ();
5203 : 1828605 : rtx_insn *last;
5204 : :
5205 : 1828605 : 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 : 3657210 : stack_pointer_delta += PUSH_ROUNDING (GET_MODE_SIZE (mode));
5214 : :
5215 : 1828605 : last = get_last_insn ();
5216 : :
5217 : : /* Notice the common case where we emitted exactly one insn. */
5218 : 1828605 : if (PREV_INSN (last) == prev)
5219 : : {
5220 : 1719360 : add_args_size_note (last, stack_pointer_delta);
5221 : 1719360 : return;
5222 : : }
5223 : :
5224 : 109245 : delta = fixup_args_size_notes (prev, last, stack_pointer_delta);
5225 : 109245 : 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 : 2151710 : 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 : 2151710 : rtx xinner;
5291 : 2151710 : 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 : 2151710 : pad_direction where_pad = targetm.calls.function_arg_padding (mode, type);
5298 : :
5299 : : /* Invert direction if stack is post-decrement.
5300 : : FIXME: why? */
5301 : 2151710 : 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 : 2151710 : xinner = x;
5306 : :
5307 : 2151710 : int nregs = partial / UNITS_PER_WORD;
5308 : 2151710 : rtx *tmp_regs = NULL;
5309 : 2151710 : int overlapping = 0;
5310 : :
5311 : 2151710 : if (mode == BLKmode
5312 : : || (STRICT_ALIGNMENT && align < GET_MODE_ALIGNMENT (mode)))
5313 : : {
5314 : : /* Copy a block into the stack, entirely or partially. */
5315 : :
5316 : 268161 : rtx temp;
5317 : 268161 : int used;
5318 : 268161 : int offset;
5319 : 268161 : int skip;
5320 : :
5321 : 268161 : offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
5322 : 268161 : used = partial - offset;
5323 : :
5324 : 268161 : 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 : 268161 : 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 : 268161 : 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 : 268161 : 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 : 268161 : unsigned int push_size;
5356 : 268161 : if (CONST_INT_P (size))
5357 : 268161 : 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 : 268161 : if (args_addr == 0
5365 : 268098 : && 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 : 271108 : && 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 : 268116 : 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 : 268116 : 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 : 268116 : poly_int64 const_args_so_far;
5414 : 268116 : if (! args_addr)
5415 : : {
5416 : 268053 : temp = push_block (size, extra, where_pad == PAD_DOWNWARD);
5417 : 268053 : 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 : 268116 : 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 : 268116 : if (reg_mentioned_p (virtual_stack_dynamic_rtx, temp)
5438 : 268116 : || reg_mentioned_p (virtual_outgoing_args_rtx, temp))
5439 : 268053 : temp = copy_to_reg (temp);
5440 : : }
5441 : :
5442 : 268116 : 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 : 268116 : 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 : 268116 : 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 : 268116 : const_tree decl;
5494 : 268116 : HOST_WIDE_INT sz;
5495 : 268116 : if (partial == 0
5496 : 268116 : && MEM_P (xinner)
5497 : 268116 : && 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 : 268122 : && INTVAL (size) == sz)
5506 : 0 : store_constructor (DECL_INITIAL (decl), target, 0, sz, false);
5507 : : else
5508 : 268116 : emit_block_move (target, xinner, size, BLOCK_OP_CALL_PARM);
5509 : : }
5510 : : }
5511 : 1883549 : 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 : 1883549 : rtx addr;
5577 : 1883549 : 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 : 1883549 : if (maybe_ne (extra, 0)
5583 : 0 : && args_addr == 0
5584 : 0 : && where_pad != PAD_NONE
5585 : 1883549 : && where_pad != stack_direction)
5586 : 0 : anti_adjust_stack (gen_int_mode (extra, Pmode));
5587 : :
5588 : : #ifdef PUSH_ROUNDING
5589 : 1883549 : if (args_addr == 0 && targetm.calls.push_argument (0))
5590 : 1828558 : emit_single_push_insn (mode, x, type);
5591 : : else
5592 : : #endif
5593 : : {
5594 : 62954 : addr = simplify_gen_binary (PLUS, Pmode, args_addr, args_so_far);
5595 : 54991 : 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 : 54991 : set_mem_align (dest, align);
5605 : :
5606 : 54991 : 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 : 2151710 : 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 : 2151710 : if (maybe_ne (extra, 0) && args_addr == 0 && where_pad == stack_direction)
5632 : 0 : anti_adjust_stack (gen_int_mode (extra, Pmode));
5633 : :
5634 : 2151710 : if (alignment_pad && args_addr == 0)
5635 : 2096656 : 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 : 200265428 : get_subtarget (rtx x)
5645 : : {
5646 : 200265428 : return (optimize
5647 : 51921419 : || x == 0
5648 : : /* Only registers can be subtargets. */
5649 : 17419926 : || !REG_P (x)
5650 : : /* Don't use hard regs to avoid extending their life. */
5651 : 11842595 : || REGNO (x) < FIRST_PSEUDO_REGISTER
5652 : 200265428 : ? 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 : 4738510 : 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 : 4738510 : machine_mode str_mode = GET_MODE (str_rtx);
5669 : 4738510 : unsigned int str_bitsize;
5670 : 4738510 : tree op0, op1;
5671 : 4738510 : rtx value, result;
5672 : 4738510 : optab binop;
5673 : 4738510 : gimple *srcstmt;
5674 : 4738510 : enum tree_code code;
5675 : :
5676 : 4738510 : unsigned HOST_WIDE_INT bitsize, bitpos, bitregion_start, bitregion_end;
5677 : 4738510 : if (mode1 != VOIDmode
5678 : 69489 : || !pbitsize.is_constant (&bitsize)
5679 : 69489 : || !pbitpos.is_constant (&bitpos)
5680 : 69489 : || !pbitregion_start.is_constant (&bitregion_start)
5681 : 69489 : || !pbitregion_end.is_constant (&bitregion_end)
5682 : 70062 : || bitsize >= BITS_PER_WORD
5683 : 69220 : || !GET_MODE_BITSIZE (str_mode).is_constant (&str_bitsize)
5684 : 69793 : || str_bitsize > BITS_PER_WORD
5685 : 63836 : || TREE_SIDE_EFFECTS (to)
5686 : 4802217 : || TREE_THIS_VOLATILE (to))
5687 : : return false;
5688 : :
5689 : 63707 : STRIP_NOPS (src);
5690 : 63707 : if (TREE_CODE (src) != SSA_NAME)
5691 : : return false;
5692 : 21132 : if (TREE_CODE (TREE_TYPE (src)) != INTEGER_TYPE)
5693 : : return false;
5694 : :
5695 : 19173 : srcstmt = get_gimple_for_ssa_name (src);
5696 : 19173 : if (!srcstmt
5697 : 4599 : || !is_gimple_assign (srcstmt)
5698 : 23772 : || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt)) != tcc_binary)
5699 : : return false;
5700 : :
5701 : 781 : code = gimple_assign_rhs_code (srcstmt);
5702 : :
5703 : 781 : 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 : 781 : if (TREE_CODE (op0) == SSA_NAME)
5709 : : {
5710 : 781 : 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 : 781 : if (!op0stmt
5715 : 719 : || !is_gimple_assign (op0stmt)
5716 : 1500 : || gimple_assign_rhs_code (op0stmt) != TREE_CODE (to))
5717 : : return false;
5718 : 399 : op0 = gimple_assign_rhs1 (op0stmt);
5719 : : }
5720 : :
5721 : 399 : op1 = gimple_assign_rhs2 (srcstmt);
5722 : :
5723 : 399 : if (!operand_equal_p (to, op0, 0))
5724 : : return false;
5725 : :
5726 : 339 : if (MEM_P (str_rtx))
5727 : : {
5728 : 334 : unsigned HOST_WIDE_INT offset1;
5729 : :
5730 : 334 : if (str_bitsize == 0 || str_bitsize > BITS_PER_WORD)
5731 : 114 : str_bitsize = BITS_PER_WORD;
5732 : :
5733 : 334 : scalar_int_mode best_mode;
5734 : 334 : if (!get_best_mode (bitsize, bitpos, bitregion_start, bitregion_end,
5735 : 334 : MEM_ALIGN (str_rtx), str_bitsize, false, &best_mode))
5736 : 0 : return false;
5737 : 334 : str_mode = best_mode;
5738 : 334 : str_bitsize = GET_MODE_BITSIZE (best_mode);
5739 : :
5740 : 334 : offset1 = bitpos;
5741 : 334 : bitpos %= str_bitsize;
5742 : 334 : offset1 = (offset1 - bitpos) / BITS_PER_UNIT;
5743 : 334 : 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 : 339 : if (bitsize >= str_bitsize)
5751 : : return false;
5752 : :
5753 : : /* We can't handle fields split across multiple entities. */
5754 : 339 : if (bitpos + bitsize > str_bitsize)
5755 : : return false;
5756 : :
5757 : 339 : if (reverse ? !BYTES_BIG_ENDIAN : BYTES_BIG_ENDIAN)
5758 : 0 : bitpos = str_bitsize - bitpos - bitsize;
5759 : :
5760 : 339 : 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 : 168 : case BIT_IOR_EXPR:
5806 : 168 : case BIT_XOR_EXPR:
5807 : 168 : 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 : 918922 : get_bit_range (poly_uint64 *bitstart, poly_uint64 *bitend, tree exp,
5859 : : poly_int64 *bitpos, tree *offset)
5860 : : {
5861 : 918922 : poly_int64 bitoffset;
5862 : 918922 : tree field, repr;
5863 : :
5864 : 918922 : gcc_assert (TREE_CODE (exp) == COMPONENT_REF);
5865 : :
5866 : 918922 : field = TREE_OPERAND (exp, 1);
5867 : 918922 : 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 : 918922 : 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 : 918857 : if (handled_component_p (TREE_OPERAND (exp, 0)))
5880 : : {
5881 : 683080 : machine_mode rmode;
5882 : 683080 : poly_int64 rbitsize, rbitpos;
5883 : 683080 : tree roffset;
5884 : 683080 : int unsignedp, reversep, volatilep = 0;
5885 : 683080 : get_inner_reference (TREE_OPERAND (exp, 0), &rbitsize, &rbitpos,
5886 : : &roffset, &rmode, &unsignedp, &reversep,
5887 : : &volatilep);
5888 : 1366160 : 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 : 918857 : poly_uint64 field_offset, repr_offset;
5900 : 918857 : if (poly_int_tree_p (DECL_FIELD_OFFSET (field), &field_offset)
5901 : 1837709 : && poly_int_tree_p (DECL_FIELD_OFFSET (repr), &repr_offset))
5902 : 918852 : bitoffset = (field_offset - repr_offset) * BITS_PER_UNIT;
5903 : : else
5904 : : bitoffset = 0;
5905 : 918857 : bitoffset += (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field))
5906 : 918857 : - 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 : 918857 : if (maybe_gt (bitoffset, *bitpos))
5912 : : {
5913 : 11 : poly_int64 adjust_bits = upper_bound (bitoffset, *bitpos) - *bitpos;
5914 : 11 : poly_int64 adjust_bytes = exact_div (adjust_bits, BITS_PER_UNIT);
5915 : :
5916 : 11 : *bitpos += adjust_bits;
5917 : 11 : if (*offset == NULL_TREE)
5918 : 5 : *offset = size_int (-adjust_bytes);
5919 : : else
5920 : 6 : *offset = size_binop (MINUS_EXPR, *offset, size_int (adjust_bytes));
5921 : 11 : *bitstart = 0;
5922 : : }
5923 : : else
5924 : 918846 : *bitstart = *bitpos - bitoffset;
5925 : :
5926 : 918857 : *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 : 5370986 : non_mem_decl_p (tree base)
5935 : : {
5936 : 5370986 : if (!DECL_P (base)
5937 : 5370748 : || TREE_ADDRESSABLE (base)
5938 : 7835700 : || DECL_MODE (base) == BLKmode)
5939 : : return false;
5940 : :
5941 : 1601841 : if (!DECL_RTL_SET_P (base))
5942 : : return false;
5943 : :
5944 : 1484133 : 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 : 11786381 : mem_ref_refers_to_non_mem_p (tree ref)
5952 : : {
5953 : 11786381 : tree base;
5954 : :
5955 : 11786381 : if (TREE_CODE (ref) == MEM_REF
5956 : 11786381 : || TREE_CODE (ref) == TARGET_MEM_REF)
5957 : : {
5958 : 10279274 : tree addr = TREE_OPERAND (ref, 0);
5959 : :
5960 : 10279274 : if (TREE_CODE (addr) != ADDR_EXPR)
5961 : : return false;
5962 : :
5963 : 3863694 : base = TREE_OPERAND (addr, 0);
5964 : : }
5965 : : else
5966 : : base = ref;
5967 : :
5968 : 5370801 : 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 : 18392352 : expand_assignment (tree to, tree from, bool nontemporal)
5976 : : {
5977 : 18392352 : rtx to_rtx = 0;
5978 : 18392352 : rtx result;
5979 : 18392352 : machine_mode mode;
5980 : 18392352 : unsigned int align;
5981 : 18392352 : enum insn_code icode;
5982 : :
5983 : : /* Don't crash if the lhs of the assignment was erroneous. */
5984 : 18392352 : 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 : 18392352 : if (operand_equal_p (to, from, 0))
5992 : : return;
5993 : :
5994 : : /* Handle misaligned stores. */
5995 : 18392215 : mode = TYPE_MODE (TREE_TYPE (to));
5996 : 18392215 : if ((TREE_CODE (to) == MEM_REF
5997 : 18392215 : || TREE_CODE (to) == TARGET_MEM_REF
5998 : 16230178 : || DECL_P (to))
5999 : 4028053 : && mode != BLKmode
6000 : 3560915 : && !mem_ref_refers_to_non_mem_p (to)
6001 : 6338804 : && ((align = get_object_alignment (to))
6002 : 3169402 : < GET_MODE_ALIGNMENT (mode))
6003 : 18816134 : && (((icode = optab_handler (movmisalign_optab, mode))
6004 : : != CODE_FOR_nothing)
6005 : 95623 : || targetm.slow_unaligned_access (mode, align)))
6006 : : {
6007 : 328296 : rtx reg, mem;
6008 : :
6009 : 328296 : reg = expand_expr (from, NULL_RTX, VOIDmode, EXPAND_NORMAL);
6010 : : /* Handle PARALLEL. */
6011 : 328296 : reg = maybe_emit_group_store (reg, TREE_TYPE (from));
6012 : 328296 : reg = force_not_mem (reg);
6013 : 328296 : mem = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
6014 : 328296 : if (TREE_CODE (to) == MEM_REF && REF_REVERSE_STORAGE_ORDER (to))
6015 : 0 : reg = flip_storage_order (mode, reg);
6016 : :
6017 : 328296 : if (icode != CODE_FOR_nothing)
6018 : : {
6019 : 328296 : class expand_operand ops[2];
6020 : :
6021 : 328296 : create_fixed_operand (&ops[0], mem);
6022 : 328296 : create_input_operand (&ops[1], reg, mode);
6023 : : /* The movmisalign<mode> pattern cannot fail, else the assignment
6024 : : would silently be omitted. */
6025 : 328296 : 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 : 328296 : 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 : 18063919 : if (handled_component_p (to)
6039 : 13559912 : || (TREE_CODE (to) == MEM_REF
6040 : 1600906 : && (REF_REVERSE_STORAGE_ORDER (to)
6041 : 1600890 : || mem_ref_refers_to_non_mem_p (to)))
6042 : 13445821 : || TREE_CODE (TREE_TYPE (to)) == ARRAY_TYPE)
6043 : : {
6044 : 4738652 : machine_mode mode1;
6045 : 4738652 : poly_int64 bitsize, bitpos;
6046 : 4738652 : poly_uint64 bitregion_start = 0;
6047 : 4738652 : poly_uint64 bitregion_end = 0;
6048 : 4738652 : tree offset;
6049 : 4738652 : int unsignedp, reversep, volatilep = 0;
6050 : 4738652 : tree tem;
6051 : :
6052 : 4738652 : push_temp_slots ();
6053 : 4738652 : 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 : 4738652 : if (maybe_lt (bitpos, 0))
6058 : : {
6059 : 270 : gcc_assert (offset == NULL_TREE);
6060 : 270 : offset = size_int (bits_to_bytes_round_down (bitpos));
6061 : 270 : bitpos = num_trailing_bits (bitpos);
6062 : : }
6063 : :
6064 : 4738652 : if (TREE_CODE (to) == COMPONENT_REF
6065 : 4738652 : && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to, 1)))
6066 : 88027 : 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 : 4650625 : else if (maybe_gt (bitsize, 0)
6072 : 4650610 : && multiple_p (bitsize, BITS_PER_UNIT)
6073 : 9300977 : && multiple_p (bitpos, BITS_PER_UNIT))
6074 : : {
6075 : 4650352 : bitregion_start = bitpos;
6076 : 4650352 : bitregion_end = bitpos + bitsize - 1;
6077 : : }
6078 : :
6079 : 4738652 : 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 : 4738652 : if (MEM_P (to_rtx))
6086 : : {
6087 : 4043716 : if (mode1 != VOIDmode)
6088 : 3974965 : to_rtx = adjust_address (to_rtx, mode1, 0);
6089 : 68751 : else if (GET_MODE (to_rtx) == VOIDmode)
6090 : 0 : to_rtx = adjust_address (to_rtx, BLKmode, 0);
6091 : : }
6092 : :
6093 : 4738652 : rtx stemp = NULL_RTX, old_to_rtx = NULL_RTX;
6094 : 4738652 : if (offset != 0)
6095 : : {
6096 : 173393 : machine_mode address_mode;
6097 : 173393 : rtx offset_rtx;
6098 : :
6099 : 173393 : 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 : 173393 : offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, EXPAND_SUM);
6122 : 173393 : address_mode = get_address_mode (to_rtx);
6123 : 173393 : 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 : 294 : offset_rtx = force_operand (offset_rtx, NULL_RTX);
6129 : 294 : 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 : 173393 : poly_int64 bytepos;
6150 : 173393 : if (mode1 != VOIDmode
6151 : 173287 : && maybe_ne (bitpos, 0)
6152 : 46293 : && maybe_gt (bitsize, 0)
6153 : 219686 : && multiple_p (bitpos, BITS_PER_UNIT, &bytepos)
6154 : 219629 : && multiple_p (bitpos, bitsize)
6155 : 92472 : && multiple_p (bitsize, GET_MODE_ALIGNMENT (mode1))
6156 : 219629 : && MEM_ALIGN (to_rtx) >= GET_MODE_ALIGNMENT (mode1))
6157 : : {
6158 : 46221 : to_rtx = adjust_address (to_rtx, mode1, bytepos);
6159 : 46221 : bitregion_start = 0;
6160 : 46221 : if (known_ge (bitregion_end, poly_uint64 (bitpos)))
6161 : 46221 : bitregion_end -= bitpos;
6162 : 46221 : bitpos = 0;
6163 : : }
6164 : :
6165 : 173393 : 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 : 4738652 : if (!MEM_P (to_rtx)
6174 : 694932 : && GET_MODE (to_rtx) != BLKmode
6175 : 5433584 : && 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 : 4738649 : else if (GET_CODE (to_rtx) == CONCAT)
6182 : : {
6183 : 133 : machine_mode to_mode = GET_MODE (to_rtx);
6184 : 133 : gcc_checking_assert (COMPLEX_MODE_P (to_mode));
6185 : 266 : poly_int64 mode_bitsize = GET_MODE_BITSIZE (to_mode);
6186 : 133 : unsigned short inner_bitsize = GET_MODE_UNIT_BITSIZE (to_mode);
6187 : 133 : if (TYPE_MODE (TREE_TYPE (from)) == to_mode
6188 : 0 : && known_eq (bitpos, 0)
6189 : 133 : && known_eq (bitsize, mode_bitsize))
6190 : 0 : result = store_expr (from, to_rtx, false, nontemporal, reversep);
6191 : 133 : else if (TYPE_MODE (TREE_TYPE (from)) == GET_MODE_INNER (to_mode)
6192 : 86 : && known_eq (bitsize, inner_bitsize)
6193 : 219 : && (known_eq (bitpos, 0)
6194 : 33 : || known_eq (bitpos, inner_bitsize)))
6195 : 86 : 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 : 4738516 : else if (!MEM_P (to_rtx)
6276 : 694796 : && TREE_CODE (from) == CALL_EXPR
6277 : 405 : && COMPLETE_TYPE_P (TREE_TYPE (from))
6278 : 4738921 : && 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 : 4738510 : 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 : 4043720 : to_rtx = shallow_copy_rtx (to_rtx);
6294 : 4043720 : set_mem_attributes_minus_bitpos (to_rtx, to, 0, bitpos);
6295 : 4043720 : if (volatilep)
6296 : 8645 : MEM_VOLATILE_P (to_rtx) = 1;
6297 : : }
6298 : :
6299 : 4738510 : gcc_checking_assert (known_ge (bitpos, 0));
6300 : 4738510 : if (optimize_bitfield_assignment_op (bitsize, bitpos,
6301 : : bitregion_start, bitregion_end,
6302 : : mode1, to_rtx, to, from,
6303 : : reversep))
6304 : : result = NULL;
6305 : 4738385 : else if (SUBREG_P (to_rtx)
6306 : 4738385 : && 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 : 4738385 : 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 : 4738510 : if (stemp)
6350 : 3 : emit_move_insn (old_to_rtx, stemp);
6351 : : }
6352 : :
6353 : 4738652 : if (result)
6354 : 835182 : preserve_temp_slots (result);
6355 : 4738652 : pop_temp_slots ();
6356 : 4738652 : 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 : 2325042 : if (TREE_CODE (from) == CALL_EXPR && ! aggregate_value_p (from, from)
6370 : 2125752 : && COMPLETE_TYPE_P (TREE_TYPE (from))
6371 : 2125752 : && TREE_CODE (TYPE_SIZE (TREE_TYPE (from))) == INTEGER_CST
6372 : 15451019 : && ! (((VAR_P (to)
6373 : : || TREE_CODE (to) == PARM_DECL
6374 : : || TREE_CODE (to) == RESULT_DECL)
6375 : 129324 : && REG_P (DECL_RTL (to)))
6376 : 2004750 : || TREE_CODE (to) == SSA_NAME))
6377 : : {
6378 : 8610 : rtx value;
6379 : :
6380 : 8610 : push_temp_slots ();
6381 : 8610 : value = expand_normal (from);
6382 : :
6383 : 8610 : if (to_rtx == 0)
6384 : 8610 : 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 : 8610 : 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 : 8610 : else if (GET_CODE (value) == PARALLEL)
6397 : 1870 : emit_group_store (to_rtx, value, TREE_TYPE (from),
6398 : 1870 : int_size_in_bytes (TREE_TYPE (from)));
6399 : 6740 : 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 : 6493 : 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 : 6493 : emit_move_insn (to_rtx, value);
6415 : : }
6416 : :
6417 : 8610 : preserve_temp_slots (to_rtx);
6418 : 8610 : pop_temp_slots ();
6419 : 8610 : return;
6420 : : }
6421 : :
6422 : : /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
6423 : 13316657 : to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
6424 : :
6425 : : /* Don't move directly into a return register. */
6426 : 13316657 : if (TREE_CODE (to) == RESULT_DECL
6427 : 28755 : && (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 : 13316657 : if (TREE_CODE (to) == RESULT_DECL
6464 : 28755 : && 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 : 13316657 : && !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 : 13316657 : push_temp_slots ();
6487 : 13316657 : result = store_expr (from, to_rtx, 0, nontemporal, false);
6488 : 13316657 : preserve_temp_slots (result);
6489 : 13316657 : pop_temp_slots ();
6490 : 13316657 : 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 : 97151 : string_cst_read_str (void *data, void *, HOST_WIDE_INT offset,
6515 : : fixed_size_mode mode)
6516 : : {
6517 : 97151 : tree str = (tree) data;
6518 : :
6519 : 97151 : gcc_assert (offset >= 0);
6520 : 97151 : if (offset >= TREE_STRING_LENGTH (str))
6521 : 3548 : return const0_rtx;
6522 : :
6523 : 93603 : if ((unsigned HOST_WIDE_INT) offset + GET_MODE_SIZE (mode)
6524 : 93603 : > (unsigned HOST_WIDE_INT) TREE_STRING_LENGTH (str))
6525 : : {
6526 : 2662 : char *p = XALLOCAVEC (char, GET_MODE_SIZE (mode));
6527 : 2662 : size_t l = TREE_STRING_LENGTH (str) - offset;
6528 : 2662 : memcpy (p, TREE_STRING_POINTER (str) + offset, l);
6529 : 2662 : memset (p + l, '\0', GET_MODE_SIZE (mode) - l);
6530 : 2662 : return c_readstr (p, mode, false);
6531 : : }
6532 : :
6533 : 90941 : 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 : 17257737 : store_expr (tree exp, rtx target, int call_param_p,
6580 : : bool nontemporal, bool reverse)
6581 : : {
6582 : 17257737 : rtx temp;
6583 : 17257737 : rtx alt_rtl = NULL_RTX;
6584 : 17257737 : location_t loc = curr_insn_location ();
6585 : 17257737 : bool shortened_string_cst = false;
6586 : :
6587 : 17257737 : 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 : 17257737 : 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 : 17257737 : 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 : 17257737 : 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 : 17257730 : else if ((TREE_CODE (exp) == STRING_CST
6697 : 17246927 : || (TREE_CODE (exp) == MEM_REF
6698 : 1292528 : && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
6699 : 419164 : && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
6700 : : == STRING_CST
6701 : 4371 : && integer_zerop (TREE_OPERAND (exp, 1))))
6702 : 15174 : && !nontemporal && !call_param_p
6703 : 17272904 : && MEM_P (target))
6704 : : {
6705 : : /* Optimize initialization of an array with a STRING_CST. */
6706 : 15156 : HOST_WIDE_INT exp_len, str_copy_len;
6707 : 15156 : rtx dest_mem;
6708 : 15156 : tree str = TREE_CODE (exp) == STRING_CST
6709 : 15156 : ? exp : TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6710 : :
6711 : 15156 : exp_len = int_expr_size (exp);
6712 : 15156 : if (exp_len <= 0)
6713 : 0 : goto normal_expr;
6714 : :
6715 : 15156 : if (TREE_STRING_LENGTH (str) <= 0)
6716 : 0 : goto normal_expr;
6717 : :
6718 : 30312 : if (can_store_by_pieces (exp_len, string_cst_read_str, (void *) str,
6719 : 15156 : MEM_ALIGN (target), false))
6720 : : {
6721 : 14981 : store_by_pieces (target, exp_len, string_cst_read_str, (void *) str,
6722 : 14981 : MEM_ALIGN (target), false, RETURN_BEGIN);
6723 : 14981 : return NULL_RTX;
6724 : : }
6725 : :
6726 : 175 : 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 : 297 : while (str_copy_len)
6732 : : {
6733 : 254 : if (TREE_STRING_POINTER (str)[str_copy_len - 1])
6734 : : break;
6735 : 122 : str_copy_len--;
6736 : : }
6737 : :
6738 : 175 : if ((STORE_MAX_PIECES & (STORE_MAX_PIECES - 1)) == 0)
6739 : : {
6740 : 175 : str_copy_len += STORE_MAX_PIECES - 1;
6741 : 175 : str_copy_len &= ~(STORE_MAX_PIECES - 1);
6742 : : }
6743 : 175 : if (str_copy_len >= exp_len)
6744 : 124 : 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 : 17242700 : rtx tmp_target;
6761 : :
6762 : 17242700 : normal_expr:
6763 : : /* If we want to use a nontemporal or a reverse order store, force the
6764 : : value into a register first. */
6765 : 17242700 : tmp_target = nontemporal || reverse ? NULL_RTX : target;
6766 : 17242700 : tree rexp = exp;
6767 : 17242700 : if (TREE_CODE (exp) == STRING_CST
6768 : 41 : && tmp_target == target
6769 : 41 : && GET_MODE (target) == BLKmode
6770 : 17242741 : && TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
6771 : : {
6772 : 41 : rtx size = expr_size (exp);
6773 : 41 : if (CONST_INT_P (size)
6774 : 41 : && size != const0_rtx
6775 : 82 : && (UINTVAL (size)
6776 : 41 : > ((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 : 34485400 : 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 : 17242700 : 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 : 3551787 : if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode
6807 : 2553420 : && TREE_CODE (exp) != ERROR_MARK
6808 : 19796120 : && 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 : 17242700 : if ((! rtx_equal_p (temp, target)
6845 : 3109452 : || (temp != target && (side_effects_p (temp)
6846 : 46815 : || side_effects_p (target)
6847 : 46815 : || (MEM_P (temp)
6848 : 46338 : && !mems_same_for_tbaa_p (temp, target)))))
6849 : 14133252 : && 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 : 14133252 : && !(alt_rtl
6854 : 1994054 : && 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 : 31375952 : && expr_size (exp) != const0_rtx)
6862 : : {
6863 : 14133252 : if (GET_MODE (temp) != GET_MODE (target) && GET_MODE (temp) != VOIDmode)
6864 : : {
6865 : 1424 : gcc_assert (!shortened_string_cst);
6866 : 1424 : 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 : 1422 : convert_move (target, temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
6880 : : }
6881 : :
6882 : 14131828 : 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 : 41 : rtx size = expr_size (exp);
6889 : :
6890 : 41 : if (CONST_INT_P (size)
6891 : 41 : && 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 : 41 : machine_mode pointer_mode
6898 : 41 : = targetm.addr_space.pointer_mode (MEM_ADDR_SPACE (target));
6899 : 41 : machine_mode address_mode = get_address_mode (target);
6900 : :
6901 : : /* Compute the size of the data to copy from the string. */
6902 : 41 : tree copy_size
6903 : 41 : = size_binop_loc (loc, MIN_EXPR,
6904 : : make_tree (sizetype, size),
6905 : 41 : size_int (TREE_STRING_LENGTH (exp)));
6906 : 41 : rtx copy_size_rtx
6907 : 41 : = expand_expr (copy_size, NULL_RTX, VOIDmode,
6908 : : (call_param_p
6909 : : ? EXPAND_STACK_PARM : EXPAND_NORMAL));
6910 : 41 : rtx_code_label *label = 0;
6911 : :
6912 : : /* Copy that much. */
6913 : 123 : copy_size_rtx = convert_to_mode (pointer_mode, copy_size_rtx,
6914 : 41 : TYPE_UNSIGNED (sizetype));
6915 : 82 : 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 : 41 : poly_int64 const_copy_size;
6922 : 41 : if (poly_int_rtx_p (copy_size_rtx, &const_copy_size))
6923 : : {
6924 : 41 : size = plus_constant (address_mode, size, -const_copy_size);
6925 : 41 : 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 : 41 : if (size != const0_rtx)
6946 : 2 : clear_storage (target, size, BLOCK_OP_NORMAL);
6947 : :
6948 : 41 : if (label)
6949 : 0 : emit_label (label);
6950 : : }
6951 : : }
6952 : 14131787 : 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 : 14131787 : 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 : 14131787 : 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 : 14131787 : else if (GET_MODE (temp) == BLKmode)
6968 : 600388 : 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 : 13831593 : else if (nontemporal && emit_storent_insn (target, temp))
6973 : : ;
6974 : : else
6975 : : {
6976 : 13831576 : if (reverse)
6977 : 696 : temp = flip_storage_order (GET_MODE (target), temp);
6978 : 13831576 : temp = force_operand (temp, target);
6979 : 13831576 : if (temp != target)
6980 : 13829998 : emit_move_insn (target, temp);
6981 : : }
6982 : : }
6983 : : else
6984 : 3109448 : 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 : 3881285 : flexible_array_member_p (const_tree f, const_tree type)
6993 : : {
6994 : 3881285 : const_tree tf;
6995 : :
6996 : 3881285 : tf = TREE_TYPE (f);
6997 : 3881285 : return (DECL_CHAIN (f) == NULL
6998 : 1074404 : && 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 : 3881324 : && 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 : 3656348 : count_type_elements (const_tree type, bool for_ctor_p)
7014 : : {
7015 : 3656348 : switch (TREE_CODE (type))
7016 : : {
7017 : 150379 : case ARRAY_TYPE:
7018 : 150379 : {
7019 : 150379 : tree nelts_minus_one;
7020 : :
7021 : 150379 : nelts_minus_one = array_type_nelts_minus_one (type);
7022 : 150379 : if (nelts_minus_one && tree_fits_uhwi_p (nelts_minus_one))
7023 : : {
7024 : 150370 : unsigned HOST_WIDE_INT n;
7025 : :
7026 : 150370 : n = tree_to_uhwi (nelts_minus_one) + 1;
7027 : 150370 : if (n == 0 || for_ctor_p)
7028 : 149613 : return n;
7029 : : else
7030 : 757 : return n * count_type_elements (TREE_TYPE (type), false);
7031 : : }
7032 : 9 : return for_ctor_p ? -1 : 1;
7033 : : }
7034 : :
7035 : 1739256 : case RECORD_TYPE:
7036 : 1739256 : {
7037 : 1739256 : unsigned HOST_WIDE_INT n;
7038 : 1739256 : tree f;
7039 : :
7040 : 1739256 : n = 0;
7041 : 15702191 : for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
7042 : 13962935 : if (TREE_CODE (f) == FIELD_DECL)
7043 : : {
7044 : 4348122 : if (!for_ctor_p)
7045 : 466837 : n += count_type_elements (TREE_TYPE (f), false);
7046 : 3881285 : else if (!flexible_array_member_p (f, type))
7047 : : /* Don't count flexible arrays, which are not supposed
7048 : : to be initialized. */
7049 : 3881246 : n += 1;
7050 : : }
7051 : :
7052 : 1739256 : return n;
7053 : : }
7054 : :
7055 : 4865 : case UNION_TYPE:
7056 : 4865 : case QUAL_UNION_TYPE:
7057 : 4865 : {
7058 : 4865 : tree f;
7059 : 4865 : HOST_WIDE_INT n, m;
7060 : :
7061 : 4865 : 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 : 4865 : n = 1;
7067 : 111092 : for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
7068 : 106227 : if (TREE_CODE (f) == FIELD_DECL)
7069 : : {
7070 : 100230 : 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 : 100230 : if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f)),
7074 : 100230 : TYPE_SIZE (type)) != 1)
7075 : 71490 : m++;
7076 : 100230 : if (n < m)
7077 : 106227 : 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 : 1500432 : 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 : 1500432 : unsigned HOST_WIDE_INT idx;
7127 : 1500432 : HOST_WIDE_INT nz_elts, unique_nz_elts, init_elts, num_fields;
7128 : 1500432 : 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 : 1500432 : bool const_from_elts_p = constructor_static_from_elts_p (ctor);
7134 : 1500432 : bool const_p = const_from_elts_p ? true : TREE_STATIC (ctor);
7135 : :
7136 : 1500432 : nz_elts = 0;
7137 : 1500432 : unique_nz_elts = 0;
7138 : 1500432 : init_elts = 0;
7139 : 1500432 : num_fields = 0;
7140 : 1500432 : elt_type = NULL_TREE;
7141 : :
7142 : 5782827 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), idx, purpose, value)
7143 : : {
7144 : 4282395 : HOST_WIDE_INT mult = 1;
7145 : :
7146 : 4282395 : if (purpose && TREE_CODE (purpose) == RANGE_EXPR)
7147 : : {
7148 : 677 : tree lo_index = TREE_OPERAND (purpose, 0);
7149 : 677 : tree hi_index = TREE_OPERAND (purpose, 1);
7150 : :
7151 : 677 : if (tree_fits_uhwi_p (lo_index) && tree_fits_uhwi_p (hi_index))
7152 : 677 : mult = (tree_to_uhwi (hi_index)
7153 : 677 : - tree_to_uhwi (lo_index) + 1);
7154 : : }
7155 : 4282395 : num_fields += mult;
7156 : 4282395 : elt_type = TREE_TYPE (value);
7157 : :
7158 : 4282395 : switch (TREE_CODE (value))
7159 : : {
7160 : 531397 : case CONSTRUCTOR:
7161 : 531397 : {
7162 : 531397 : HOST_WIDE_INT nz = 0, unz = 0, ic = 0;
7163 : :
7164 : 531397 : bool const_elt_p = categorize_ctor_elements_1 (value, &nz, &unz,
7165 : : &ic, p_complete);
7166 : :
7167 : 531397 : nz_elts += mult * nz;
7168 : 531397 : unique_nz_elts += unz;
7169 : 531397 : init_elts += mult * ic;
7170 : :
7171 : 531397 : if (const_from_elts_p && const_p)
7172 : 318701 : const_p = const_elt_p;
7173 : : }
7174 : 531397 : break;
7175 : :
7176 : 2304311 : case INTEGER_CST:
7177 : 2304311 : case REAL_CST:
7178 : 2304311 : case FIXED_CST:
7179 : 2304311 : if (!initializer_zerop (value))
7180 : : {
7181 : 1655271 : nz_elts += mult;
7182 : 1655271 : unique_nz_elts++;
7183 : : }
7184 : 2304311 : init_elts += mult;
7185 : 2304311 : break;
7186 : :
7187 : 6301 : case STRING_CST:
7188 : 6301 : nz_elts += mult * TREE_STRING_LENGTH (value);
7189 : 6301 : unique_nz_elts += TREE_STRING_LENGTH (value);
7190 : 6301 : init_elts += mult * TREE_STRING_LENGTH (value);
7191 : 6301 : break;
7192 : :
7193 : 142 : case RAW_DATA_CST:
7194 : 142 : nz_elts += mult * RAW_DATA_LENGTH (value);
7195 : 142 : unique_nz_elts += RAW_DATA_LENGTH (value);
7196 : 142 : init_elts += mult * RAW_DATA_LENGTH (value);
7197 : 142 : num_fields += mult * (RAW_DATA_LENGTH (value) - 1);
7198 : 142 : 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 : 1436682 : default:
7233 : 1436682 : {
7234 : 1436682 : HOST_WIDE_INT tc = count_type_elements (elt_type, false);
7235 : 1436682 : nz_elts += mult * tc;
7236 : 1436682 : unique_nz_elts += tc;
7237 : 1436682 : init_elts += mult * tc;
7238 : :
7239 : 1436682 : if (const_from_elts_p && const_p)
7240 : 592011 : const_p
7241 : 592011 : = initializer_constant_valid_p (value,
7242 : : elt_type,
7243 : 592011 : TYPE_REVERSE_STORAGE_ORDER
7244 : : (TREE_TYPE (ctor)))
7245 : : != NULL_TREE;
7246 : : }
7247 : : break;
7248 : : }
7249 : : }
7250 : :
7251 : 1500432 : if (*p_complete && !complete_ctor_at_level_p (TREE_TYPE (ctor),
7252 : : num_fields, elt_type))
7253 : 173649 : *p_complete = 0;
7254 : 1326783 : else if (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
7255 : 1326783 : || TREE_CODE (TREE_TYPE (ctor)) == QUAL_UNION_TYPE)
7256 : : {
7257 : 11861 : if (*p_complete
7258 : 7637 : && CONSTRUCTOR_ZERO_PADDING_BITS (ctor)
7259 : 22006 : && (num_fields
7260 : 5074 : ? simple_cst_equal (TYPE_SIZE (TREE_TYPE (ctor)),
7261 : 5071 : TYPE_SIZE (elt_type)) != 1
7262 : 3 : : type_has_padding_at_level_p (TREE_TYPE (ctor))))
7263 : 3396 : *p_complete = 0;
7264 : 8465 : else if (*p_complete > 0
7265 : 12373 : && (num_fields
7266 : 3908 : ? simple_cst_equal (TYPE_SIZE (TREE_TYPE (ctor)),
7267 : 3908 : TYPE_SIZE (elt_type)) != 1
7268 : 0 : : type_has_padding_at_level_p (TREE_TYPE (ctor))))
7269 : 234 : *p_complete = -1;
7270 : : }
7271 : 1314922 : else if (*p_complete
7272 : 1207138 : && (CONSTRUCTOR_ZERO_PADDING_BITS (ctor)
7273 : 1184730 : || flag_zero_init_padding_bits == ZERO_INIT_PADDING_BITS_ALL)
7274 : 1337335 : && type_has_padding_at_level_p (TREE_TYPE (ctor)))
7275 : 2666 : *p_complete = 0;
7276 : 1312256 : else if (*p_complete > 0
7277 : 1312256 : && type_has_padding_at_level_p (TREE_TYPE (ctor)))
7278 : 14836 : *p_complete = -1;
7279 : :
7280 : 1500432 : *p_nz_elts += nz_elts;
7281 : 1500432 : *p_unique_nz_elts += unique_nz_elts;
7282 : 1500432 : *p_init_elts += init_elts;
7283 : :
7284 : 1500432 : 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 : 969035 : 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 : 969035 : *p_nz_elts = 0;
7313 : 969035 : *p_unique_nz_elts = 0;
7314 : 969035 : *p_init_elts = 0;
7315 : 969035 : *p_complete = 1;
7316 : :
7317 : 969035 : return categorize_ctor_elements_1 (ctor, p_nz_elts, p_unique_nz_elts,
7318 : 969035 : 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 : 21932 : 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 : 21932 : if (!ctor || TREE_CODE (ctor) != CONSTRUCTOR)
7330 : : return false;
7331 : :
7332 : 2736 : return TREE_CONSTANT (ctor)
7333 : 2736 : && !TREE_ADDRESSABLE (ctor)
7334 : 2725 : && CONSTRUCTOR_NELTS (ctor)
7335 : 2701 : && TREE_CODE (TREE_TYPE (ctor)) != ARRAY_TYPE
7336 : 627 : && int_expr_size (ctor) <= words * UNITS_PER_WORD
7337 : 2914 : && 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 : 1660444 : complete_ctor_at_level_p (const_tree type, HOST_WIDE_INT num_elts,
7348 : : const_tree last_type)
7349 : : {
7350 : 1660444 : if (TREE_CODE (type) == UNION_TYPE || TREE_CODE (type) == QUAL_UNION_TYPE)
7351 : : {
7352 : 8602 : 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 : 8589 : gcc_assert (num_elts == 1 && last_type);
7367 : :
7368 : 8589 : 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 : 1651842 : 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 : 355777 : mostly_zeros_p (const_tree exp)
7385 : : {
7386 : 355777 : if (TREE_CODE (exp) == CONSTRUCTOR)
7387 : : {
7388 : 111 : HOST_WIDE_INT nz_elts, unz_elts, init_elts;
7389 : 111 : int complete_p;
7390 : :
7391 : 111 : categorize_ctor_elements (exp, &nz_elts, &unz_elts, &init_elts,
7392 : : &complete_p);
7393 : 111 : return !complete_p || nz_elts < init_elts / 4;
7394 : : }
7395 : :
7396 : 355666 : return initializer_zerop (exp);
7397 : : }
7398 : :
7399 : : /* Return true if EXP contains all zeros. */
7400 : :
7401 : : static bool
7402 : 1241 : all_zeros_p (const_tree exp)
7403 : : {
7404 : 1241 : if (TREE_CODE (exp) == CONSTRUCTOR)
7405 : : {
7406 : 1241 : HOST_WIDE_INT nz_elts, unz_elts, init_elts;
7407 : 1241 : int complete_p;
7408 : :
7409 : 1241 : categorize_ctor_elements (exp, &nz_elts, &unz_elts, &init_elts,
7410 : : &complete_p);
7411 : 1241 : 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 : 32339 : 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 : 32339 : poly_int64 bytepos;
7437 : 32339 : poly_uint64 bytesize;
7438 : 32339 : 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 : 32339 : && 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 : 32403 : && (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 : 32275 : store_field (target, bitsize, bitpos, bitregion_start, bitregion_end, mode,
7471 : : exp, alias_set, false, reverse);
7472 : 32339 : }
7473 : :
7474 : :
7475 : : /* Returns the number of FIELD_DECLs in TYPE. */
7476 : :
7477 : : static int
7478 : 66626 : fields_length (const_tree type)
7479 : : {
7480 : 66626 : tree t = TYPE_FIELDS (type);
7481 : 66626 : int count = 0;
7482 : :
7483 : 693807 : for (; t; t = DECL_CHAIN (t))
7484 : 627181 : if (TREE_CODE (t) == FIELD_DECL)
7485 : 296362 : ++count;
7486 : :
7487 : 66626 : 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 : 244445 : store_constructor (tree exp, rtx target, int cleared, poly_int64 size,
7502 : : bool reverse)
7503 : : {
7504 : 244445 : tree type = TREE_TYPE (exp);
7505 : 244445 : HOST_WIDE_INT exp_size = int_size_in_bytes (type);
7506 : 244445 : poly_int64 bitregion_end = known_gt (size, 0) ? size * BITS_PER_UNIT - 1 : 0;
7507 : :
7508 : 244445 : switch (TREE_CODE (type))
7509 : : {
7510 : 67027 : case RECORD_TYPE:
7511 : 67027 : case UNION_TYPE:
7512 : 67027 : case QUAL_UNION_TYPE:
7513 : 67027 : {
7514 : 67027 : unsigned HOST_WIDE_INT idx;
7515 : 67027 : tree field, value;
7516 : :
7517 : : /* The storage order is specified for every aggregate type. */
7518 : 67027 : reverse = TYPE_REVERSE_STORAGE_ORDER (type);
7519 : :
7520 : : /* If size is zero or the target is already cleared, do nothing. */
7521 : 67027 : if (known_eq (size, 0) || cleared)
7522 : : cleared = 1;
7523 : : /* We either clear the aggregate or indicate the value is dead. */
7524 : 67027 : else if ((TREE_CODE (type) == UNION_TYPE
7525 : 67027 : || TREE_CODE (type) == QUAL_UNION_TYPE)
7526 : 67271 : && ! CONSTRUCTOR_ELTS (exp))
7527 : : /* If the constructor is empty, clear the union. */
7528 : : {
7529 : 195 : clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
7530 : 195 : 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 : 4182 : else if (REG_P (target) && TREE_STATIC (exp)
7538 : 67390 : && 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 : 66626 : else if (known_size_p (size)
7551 : 66709 : && (((int) CONSTRUCTOR_NELTS (exp) != fields_length (type))
7552 : 70 : || mostly_zeros_p (exp))
7553 : 133186 : && (!REG_P (target)
7554 : 7948 : || known_eq (GET_MODE_SIZE (GET_MODE (target)), size)))
7555 : : {
7556 : 77253 : clear_storage (target, gen_int_mode (size, Pmode),
7557 : : BLOCK_OP_NORMAL);
7558 : 66560 : cleared = 1;
7559 : : }
7560 : :
7561 : 67027 : 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 : 67232 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, field, value)
7567 : : {
7568 : 205 : machine_mode mode;
7569 : 205 : HOST_WIDE_INT bitsize;
7570 : 205 : HOST_WIDE_INT bitpos = 0;
7571 : 205 : tree offset;
7572 : 205 : rtx to_rtx = target;
7573 : :
7574 : : /* Just ignore missing fields. We cleared the whole
7575 : : structure, above, if any fields are missing. */
7576 : 205 : if (field == 0)
7577 : 205 : continue;
7578 : :
7579 : 205 : if (cleared && initializer_zerop (value))
7580 : 4 : continue;
7581 : :
7582 : 201 : if (tree_fits_uhwi_p (DECL_SIZE (field)))
7583 : 201 : bitsize = tree_to_uhwi (DECL_SIZE (field));
7584 : : else
7585 : 0 : gcc_unreachable ();
7586 : :
7587 : 201 : mode = DECL_MODE (field);
7588 : 201 : if (DECL_BIT_FIELD (field))
7589 : 24 : mode = VOIDmode;
7590 : :
7591 : 201 : offset = DECL_FIELD_OFFSET (field);
7592 : 201 : if (tree_fits_shwi_p (offset)
7593 : 201 : && tree_fits_shwi_p (bit_position (field)))
7594 : : {
7595 : 201 : bitpos = int_bit_position (field);
7596 : 201 : 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 : 201 : 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 : 86 : if (MEM_P (to_rtx) && !MEM_KEEP_ALIAS_SET_P (to_rtx)
7641 : 287 : && 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 : 201 : store_constructor_field (to_rtx, bitsize, bitpos,
7648 : 201 : 0, bitregion_end, mode,
7649 : : value, cleared,
7650 : 201 : get_alias_set (TREE_TYPE (field)),
7651 : : reverse);
7652 : : }
7653 : : break;
7654 : : }
7655 : 38442 : case ARRAY_TYPE:
7656 : 38442 : {
7657 : 38442 : tree value, index;
7658 : 38442 : unsigned HOST_WIDE_INT i, j = 0;
7659 : 38442 : bool need_to_clear;
7660 : 38442 : tree domain;
7661 : 38442 : tree elttype = TREE_TYPE (type);
7662 : 38442 : bool const_bounds_p;
7663 : 38442 : unsigned HOST_WIDE_INT minelt = 0;
7664 : 38442 : unsigned HOST_WIDE_INT maxelt = 0;
7665 : :
7666 : : /* The storage order is specified for every aggregate type. */
7667 : 38442 : reverse = TYPE_REVERSE_STORAGE_ORDER (type);
7668 : :
7669 : 38442 : domain = TYPE_DOMAIN (type);
7670 : 38442 : const_bounds_p = (TYPE_MIN_VALUE (domain)
7671 : 38442 : && TYPE_MAX_VALUE (domain)
7672 : 38442 : && tree_fits_uhwi_p (TYPE_MIN_VALUE (domain))
7673 : 76884 : && tree_fits_uhwi_p (TYPE_MAX_VALUE (domain)));
7674 : :
7675 : : /* If we have constant bounds for the range of the type, get them. */
7676 : 38442 : if (const_bounds_p)
7677 : : {
7678 : 38442 : minelt = tree_to_uhwi (TYPE_MIN_VALUE (domain));
7679 : 38442 : 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 : 38442 : if (cleared)
7686 : : need_to_clear = false;
7687 : 38396 : else if (REG_P (target) && TREE_STATIC (exp))
7688 : : need_to_clear = true;
7689 : : else
7690 : : {
7691 : 38293 : unsigned HOST_WIDE_INT idx;
7692 : 38293 : unsigned HOST_WIDE_INT count = 0, zero_count = 0;
7693 : 38293 : 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 : 38341 : 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 : 38293 : if (! need_to_clear
7734 : 38293 : && (count < maxelt - minelt + 1
7735 : 6 : || 4 * zero_count >= 3 * count))
7736 : : need_to_clear = true;
7737 : : }
7738 : :
7739 : 38390 : if (need_to_clear && maybe_gt (size, 0))
7740 : : {
7741 : 38390 : if (REG_P (target))
7742 : 1619 : emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
7743 : : else
7744 : 41514 : 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 : 39598 : 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 : 138976 : case VECTOR_TYPE:
7965 : 138976 : {
7966 : 138976 : unsigned HOST_WIDE_INT idx;
7967 : 138976 : constructor_elt *ce;
7968 : 138976 : bool need_to_clear;
7969 : 138976 : insn_code icode = CODE_FOR_nothing;
7970 : 138976 : tree elt;
7971 : 138976 : tree elttype = TREE_TYPE (type);
7972 : 138976 : int elt_size = vector_element_bits (type);
7973 : 138976 : machine_mode eltmode = TYPE_MODE (elttype);
7974 : 138976 : poly_int64 bitsize;
7975 : 138976 : poly_int64 bitpos;
7976 : 138976 : rtvec vector = NULL;
7977 : 138976 : poly_uint64 n_elts;
7978 : 138976 : unsigned HOST_WIDE_INT const_n_elts;
7979 : 138976 : alias_set_type alias;
7980 : 138976 : bool vec_vec_init_p = false;
7981 : 138976 : machine_mode mode = GET_MODE (target);
7982 : :
7983 : 138976 : gcc_assert (eltmode != BLKmode);
7984 : :
7985 : : /* Try using vec_duplicate_optab for uniform vectors. */
7986 : 138976 : icode = optab_handler (vec_duplicate_optab, mode);
7987 : 138976 : if (!TREE_SIDE_EFFECTS (exp)
7988 : 138976 : && VECTOR_MODE_P (mode)
7989 : 135818 : && 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 : 94896 : && (eltmode == GET_MODE_INNER (mode)
7995 : 0 : || insn_data[icode].operand[1].mode == eltmode)
7996 : 94896 : && (elt = uniform_vector_p (exp))
7997 : 155896 : && !VECTOR_TYPE_P (TREE_TYPE (elt)))
7998 : : {
7999 : 16920 : class expand_operand ops[2];
8000 : 16920 : create_output_operand (&ops[0], target, mode);
8001 : 16920 : create_input_operand (&ops[1], expand_normal (elt), eltmode);
8002 : 16920 : expand_insn (icode, 2, ops);
8003 : 16920 : if (!rtx_equal_p (target, ops[0].value))
8004 : 0 : emit_move_insn (target, ops[0].value);
8005 : 16920 : 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 : 122056 : if (elt_size == 1
8011 : 144 : && !TREE_SIDE_EFFECTS (exp)
8012 : 144 : && VECTOR_BOOLEAN_TYPE_P (type)
8013 : 144 : && SCALAR_INT_MODE_P (TYPE_MODE (type))
8014 : 144 : && (elt = uniform_vector_p (exp))
8015 : 122199 : && !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 : 121913 : n_elts = TYPE_VECTOR_SUBPARTS (type);
8036 : 121913 : if (REG_P (target)
8037 : 119057 : && VECTOR_MODE_P (mode))
8038 : : {
8039 : 118898 : const_n_elts = 0;
8040 : 118898 : if (CONSTRUCTOR_NELTS (exp)
8041 : 118898 : && (TREE_CODE (TREE_TYPE (CONSTRUCTOR_ELT (exp, 0)->value))
8042 : : == VECTOR_TYPE))
8043 : : {
8044 : 1072 : tree etype = TREE_TYPE (CONSTRUCTOR_ELT (exp, 0)->value);
8045 : 1072 : gcc_assert (known_eq (CONSTRUCTOR_NELTS (exp)
8046 : : * TYPE_VECTOR_SUBPARTS (etype),
8047 : : n_elts));
8048 : :
8049 : 3216 : icode = convert_optab_handler (vec_init_optab, mode,
8050 : 1072 : TYPE_MODE (etype));
8051 : 1072 : const_n_elts = CONSTRUCTOR_NELTS (exp);
8052 : 1072 : vec_vec_init_p = icode != CODE_FOR_nothing;
8053 : : }
8054 : 235652 : else if (exact_div (n_elts, GET_MODE_NUNITS (eltmode))
8055 : 117826 : .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 : 117826 : icode = convert_optab_handler (vec_init_optab, mode, eltmode);
8060 : : }
8061 : :
8062 : 118898 : if (const_n_elts && icode != CODE_FOR_nothing)
8063 : : {
8064 : 118277 : vector = rtvec_alloc (const_n_elts);
8065 : 436749 : for (unsigned int k = 0; k < const_n_elts; k++)
8066 : 318472 : 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 : 121913 : tree val_type = (CONSTRUCTOR_NELTS (exp) != 0
8074 : 121913 : ? TREE_TYPE (CONSTRUCTOR_ELT (exp, 0)->value)
8075 : 121913 : : elttype);
8076 : 121913 : if (VECTOR_TYPE_P (val_type))
8077 : 1377 : bitsize = tree_to_poly_uint64 (TYPE_SIZE (val_type));
8078 : : else
8079 : 120536 : 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 : 121913 : if (cleared)
8085 : : need_to_clear = false;
8086 : 121913 : 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 : 477531 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
8094 : : {
8095 : 355618 : poly_int64 n_elts_here = exact_div (bitsize, elt_size);
8096 : 355618 : count += n_elts_here;
8097 : 355618 : if (mostly_zeros_p (value))
8098 : 355618 : 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 : 121913 : need_to_clear = (maybe_lt (count, n_elts)
8104 : 121913 : || maybe_gt (4 * zero_count, 3 * count));
8105 : : }
8106 : :
8107 : 984 : if (need_to_clear && maybe_gt (size, 0) && !vector)
8108 : : {
8109 : 629 : if (REG_P (target))
8110 : 1 : emit_move_insn (target, CONST0_RTX (mode));
8111 : : else
8112 : 628 : 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 : 121913 : if (!cleared && !vector && REG_P (target) && maybe_gt (n_elts, 1u))
8119 : : {
8120 : 482 : emit_move_insn (target, CONST0_RTX (mode));
8121 : 482 : cleared = 1;
8122 : : }
8123 : :
8124 : 121913 : if (MEM_P (target))
8125 : 2856 : alias = MEM_ALIAS_SET (target);
8126 : : else
8127 : 119057 : 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 : 121913 : HOST_WIDE_INT chunk_size = 0;
8132 : 121913 : bool chunk_multiple_p = constant_multiple_p (bitsize, elt_size,
8133 : : &chunk_size);
8134 : 121913 : gcc_assert (chunk_multiple_p || vec_vec_init_p);
8135 : :
8136 : 477531 : for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (exp), idx, &ce);
8137 : : idx++)
8138 : : {
8139 : 355618 : HOST_WIDE_INT eltpos;
8140 : 355618 : tree value = ce->value;
8141 : :
8142 : 355618 : if (cleared && initializer_zerop (value))
8143 : 6434 : continue;
8144 : :
8145 : 349184 : if (ce->index)
8146 : 42743 : eltpos = tree_to_uhwi (ce->index);
8147 : : else
8148 : 306441 : eltpos = idx * chunk_size;
8149 : :
8150 : 349184 : if (vector)
8151 : : {
8152 : 317528 : if (vec_vec_init_p)
8153 : : {
8154 : 2124 : gcc_assert (ce->index == NULL_TREE);
8155 : 2124 : gcc_assert (TREE_CODE (TREE_TYPE (value)) == VECTOR_TYPE);
8156 : 2124 : eltpos = idx;
8157 : : }
8158 : : else
8159 : 315404 : gcc_assert (TREE_CODE (TREE_TYPE (value)) != VECTOR_TYPE);
8160 : 317528 : RTVEC_ELT (vector, eltpos) = expand_normal (value);
8161 : : }
8162 : : else
8163 : : {
8164 : 31656 : machine_mode value_mode
8165 : 31656 : = (TREE_CODE (TREE_TYPE (value)) == VECTOR_TYPE
8166 : 31656 : ? TYPE_MODE (TREE_TYPE (value)) : eltmode);
8167 : 31656 : bitpos = eltpos * elt_size;
8168 : 31656 : store_constructor_field (target, bitsize, bitpos, 0,
8169 : 31656 : bitregion_end, value_mode,
8170 : : value, cleared, alias, reverse);
8171 : : }
8172 : : }
8173 : :
8174 : 121913 : if (vector)
8175 : 118277 : 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 : 244445 : }
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 : 4770681 : 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 : 4770681 : 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 : 4770681 : if (known_eq (bitsize, 0)
8219 : 4770681 : && (!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 : 4770681 : 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 : 4770681 : poly_int64 decl_bitsize;
8236 : 4770681 : if (mode == VOIDmode
8237 : 4701293 : || (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 : 4695998 : || REG_P (target)
8241 : 3999996 : || 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 : 3999996 : || (mode != BLKmode
8245 : 3885333 : && ((((MEM_ALIGN (target) < GET_MODE_ALIGNMENT (mode))
8246 : 7684719 : || !multiple_p (bitpos, GET_MODE_ALIGNMENT (mode)))
8247 : 45705 : && targetm.slow_unaligned_access (mode, MEM_ALIGN (target)))
8248 : 3885333 : || !multiple_p (bitpos, BITS_PER_UNIT)))
8249 : 3999996 : || (known_size_p (bitsize)
8250 : 3999984 : && mode != BLKmode
8251 : 3885333 : && 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 : 3999987 : || (known_size_p (bitsize)
8256 : 3999975 : && poly_int_tree_p (TYPE_SIZE (TREE_TYPE (exp)))
8257 : 3999975 : && 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 : 8770652 : || (known_size_p (bitsize)
8287 : 3999959 : && TREE_CODE (exp) == MEM_REF
8288 : 30402 : && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
8289 : 23811 : && DECL_P (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
8290 : 19467 : && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
8291 : 5268 : && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) != BLKmode))
8292 : : {
8293 : 770906 : rtx temp;
8294 : 770906 : 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 : 770906 : nop_def = get_def_for_expr (exp, NOP_EXPR);
8302 : 770906 : if (nop_def)
8303 : : {
8304 : 7013 : tree type = TREE_TYPE (exp);
8305 : 7013 : if (INTEGRAL_TYPE_P (type)
8306 : 6811 : && maybe_ne (TYPE_PRECISION (type),
8307 : 13622 : GET_MODE_BITSIZE (TYPE_MODE (type)))
8308 : 10758 : && known_eq (bitsize, TYPE_PRECISION (type)))
8309 : : {
8310 : 3643 : tree op = gimple_assign_rhs1 (nop_def);
8311 : 3643 : type = TREE_TYPE (op);
8312 : 3643 : if (INTEGRAL_TYPE_P (type)
8313 : 3643 : && known_ge (TYPE_PRECISION (type), bitsize))
8314 : : exp = op;
8315 : : }
8316 : : }
8317 : :
8318 : 770906 : 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 : 770906 : 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 : 770906 : 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 : 770900 : 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 : 770906 : scalar_int_mode temp_mode;
8357 : 1539796 : if (AGGREGATE_TYPE_P (TREE_TYPE (exp))
8358 : 771694 : && is_int_mode (GET_MODE (temp), &temp_mode))
8359 : : {
8360 : 2530 : HOST_WIDE_INT size = GET_MODE_BITSIZE (temp_mode);
8361 : :
8362 : 2530 : reverse = TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (exp));
8363 : :
8364 : 2530 : if (reverse)
8365 : 0 : temp = flip_storage_order (temp_mode, temp);
8366 : :
8367 : 2530 : gcc_checking_assert (known_le (bitsize, size));
8368 : 2530 : if (maybe_lt (bitsize, size)
8369 : 2530 : && 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 : 701518 : if (mode != VOIDmode && mode != BLKmode
8378 : 1472160 : && 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 : 770906 : if (GET_MODE (temp) == BLKmode
8385 : 770906 : && (GET_MODE (target) == BLKmode
8386 : 173 : || (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 : 770839 : 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 : 770821 : gcc_checking_assert (known_ge (bitpos, 0));
8414 : 770821 : store_bit_field (target, bitsize, bitpos,
8415 : : bitregion_start, bitregion_end,
8416 : : mode, temp, reverse, false);
8417 : :
8418 : 770821 : return const0_rtx;
8419 : : }
8420 : : else
8421 : : {
8422 : : /* Now build a reference to just the desired component. */
8423 : 3999775 : rtx to_rtx = adjust_address (target, mode,
8424 : : exact_div (bitpos, BITS_PER_UNIT));
8425 : :
8426 : 3999775 : if (to_rtx == target)
8427 : 1286771 : to_rtx = copy_rtx (to_rtx);
8428 : :
8429 : 7736684 : if (!MEM_KEEP_ALIAS_SET_P (to_rtx) && MEM_ALIAS_SET (to_rtx) != 0)
8430 : 3479472 : 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 : 3999775 : if (TREE_CODE (exp) == CONSTRUCTOR && known_size_p (bitsize))
8435 : : {
8436 : 66527 : poly_int64 bytesize = exact_div (bitsize, BITS_PER_UNIT);
8437 : 66527 : store_constructor (exp, to_rtx, 0, bytesize, reverse);
8438 : 66527 : return to_rtx;
8439 : : }
8440 : :
8441 : 3933248 : 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 : 233564173 : 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 : 233564173 : tree size_tree = 0;
8474 : 233564173 : machine_mode mode = VOIDmode;
8475 : 233564173 : bool blkmode_bitfield = false;
8476 : 233564173 : tree offset = size_zero_node;
8477 : 233564173 : 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 : 233564173 : *pbitsize = -1;
8482 : 233564173 : if (TREE_CODE (exp) == COMPONENT_REF)
8483 : : {
8484 : 91788242 : tree field = TREE_OPERAND (exp, 1);
8485 : 91788242 : size_tree = DECL_SIZE (field);
8486 : 91788242 : if (flag_strict_volatile_bitfields > 0
8487 : 58 : && TREE_THIS_VOLATILE (exp)
8488 : 40 : && DECL_BIT_FIELD_TYPE (field)
8489 : 91788264 : && 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 : 91788220 : else if (!DECL_BIT_FIELD (field))
8495 : : {
8496 : 90374601 : 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 : 90374601 : if (VECTOR_TYPE_P (TREE_TYPE (field))
8501 : 90374601 : && VECTOR_MODE_P (TYPE_MODE_RAW (TREE_TYPE (field))))
8502 : 316441 : mode = TYPE_MODE (TREE_TYPE (field));
8503 : : }
8504 : 1413619 : else if (DECL_MODE (field) == BLKmode)
8505 : 628 : blkmode_bitfield = true;
8506 : :
8507 : 91788242 : *punsignedp = DECL_UNSIGNED (field);
8508 : : }
8509 : 141775931 : else if (TREE_CODE (exp) == BIT_FIELD_REF)
8510 : : {
8511 : 609690 : size_tree = TREE_OPERAND (exp, 1);
8512 : 1218993 : *punsignedp = (! INTEGRAL_TYPE_P (TREE_TYPE (exp))
8513 : 1076238 : || 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 : 609690 : if ((TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == VECTOR_TYPE
8518 : 426922 : && TREE_TYPE (exp) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)))
8519 : 388768 : && tree_int_cst_equal (size_tree, TYPE_SIZE (TREE_TYPE (exp))))
8520 : 647847 : || VECTOR_TYPE_P (TREE_TYPE (exp)))
8521 : 408043 : mode = TYPE_MODE (TREE_TYPE (exp));
8522 : : }
8523 : : else
8524 : : {
8525 : 141166241 : mode = TYPE_MODE (TREE_TYPE (exp));
8526 : 141166241 : *punsignedp = TYPE_UNSIGNED (TREE_TYPE (exp));
8527 : :
8528 : 141166241 : if (mode == BLKmode)
8529 : 58056895 : size_tree = TYPE_SIZE (TREE_TYPE (exp));
8530 : : else
8531 : 166218692 : *pbitsize = GET_MODE_BITSIZE (mode);
8532 : : }
8533 : :
8534 : 233564173 : if (size_tree != 0)
8535 : : {
8536 : 149785668 : if (!poly_int_tree_p (size_tree, pbitsize))
8537 : 339521 : mode = BLKmode, *pbitsize = -1;
8538 : : }
8539 : :
8540 : 233564173 : *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 : 554791481 : while (1)
8545 : : {
8546 : 394177827 : switch (TREE_CODE (exp))
8547 : : {
8548 : 609690 : case BIT_FIELD_REF:
8549 : 609690 : bit_offset += wi::to_poly_offset (TREE_OPERAND (exp, 2));
8550 : 609690 : break;
8551 : :
8552 : 129593818 : case COMPONENT_REF:
8553 : 129593818 : {
8554 : 129593818 : tree field = TREE_OPERAND (exp, 1);
8555 : 129593818 : 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 : 129593818 : if (this_offset == 0)
8561 : : break;
8562 : :
8563 : 129593818 : offset = size_binop (PLUS_EXPR, offset, this_offset);
8564 : 129593818 : 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 : 129593818 : break;
8569 : :
8570 : 27616235 : case ARRAY_REF:
8571 : 27616235 : case ARRAY_RANGE_REF:
8572 : 27616235 : {
8573 : 27616235 : tree index = TREE_OPERAND (exp, 1);
8574 : 27616235 : tree low_bound = array_ref_low_bound (exp);
8575 : 27616235 : 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 : 27616235 : if (! integer_zerop (low_bound))
8582 : 785678 : index = fold_build2 (MINUS_EXPR, TREE_TYPE (index),
8583 : : index, low_bound);
8584 : :
8585 : 27616235 : offset = size_binop (PLUS_EXPR, offset,
8586 : : size_binop (MULT_EXPR,
8587 : : fold_convert (sizetype, index),
8588 : : unit_size));
8589 : : }
8590 : 27616235 : break;
8591 : :
8592 : : case REALPART_EXPR:
8593 : : break;
8594 : :
8595 : : case IMAGPART_EXPR:
8596 : 160613654 : bit_offset += *pbitsize;
8597 : : break;
8598 : :
8599 : : case VIEW_CONVERT_EXPR:
8600 : : break;
8601 : :
8602 : 88667495 : case MEM_REF:
8603 : : /* Hand back the decl for MEM[&decl, off]. */
8604 : 88667495 : if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR)
8605 : : {
8606 : 20315548 : tree off = TREE_OPERAND (exp, 1);
8607 : 20315548 : if (!integer_zerop (off))
8608 : : {
8609 : 11379465 : poly_offset_int boff = mem_ref_offset (exp);
8610 : 11379465 : boff <<= LOG2_BITS_PER_UNIT;
8611 : 11379465 : bit_offset += boff;
8612 : : }
8613 : 20315548 : exp = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
8614 : : }
8615 : 88667495 : goto done;
8616 : :
8617 : 144896678 : default:
8618 : 144896678 : goto done;
8619 : : }
8620 : :
8621 : : /* If any reference in the chain is volatile, the effect is volatile. */
8622 : 160613654 : if (TREE_THIS_VOLATILE (exp))
8623 : 457748 : *pvolatilep = 1;
8624 : :
8625 : 160613654 : exp = TREE_OPERAND (exp, 0);
8626 : 160613654 : }
8627 : 233564173 : 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 : 233564173 : if (poly_int_tree_p (offset))
8633 : : {
8634 : 220245915 : poly_offset_int tem = wi::sext (wi::to_poly_offset (offset),
8635 : 220245915 : TYPE_PRECISION (sizetype));
8636 : 220245915 : tem <<= LOG2_BITS_PER_UNIT;
8637 : 220245915 : tem += bit_offset;
8638 : 220245915 : if (tem.to_shwi (pbitpos))
8639 : 220244539 : *poffset = offset = NULL_TREE;
8640 : : }
8641 : :
8642 : : /* Otherwise, split it up. */
8643 : 220245915 : if (offset)
8644 : : {
8645 : : /* Avoid returning a negative bitpos as this may wreak havoc later. */
8646 : 13319634 : if (!bit_offset.to_shwi (pbitpos) || maybe_lt (*pbitpos, 0))
8647 : : {
8648 : 292 : *pbitpos = num_trailing_bits (bit_offset.force_shwi ());
8649 : 292 : poly_offset_int bytes = bits_to_bytes_round_down (bit_offset);
8650 : 292 : offset = size_binop (PLUS_EXPR, offset,
8651 : : build_int_cst (sizetype, bytes.force_shwi ()));
8652 : : }
8653 : :
8654 : 13319634 : *poffset = offset;
8655 : : }
8656 : :
8657 : : /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
8658 : 233564173 : if (mode == VOIDmode
8659 : 1983050 : && blkmode_bitfield
8660 : 628 : && multiple_p (*pbitpos, BITS_PER_UNIT)
8661 : 233564661 : && multiple_p (*pbitsize, BITS_PER_UNIT))
8662 : 5 : *pmode = BLKmode;
8663 : : else
8664 : 233564168 : *pmode = mode;
8665 : :
8666 : 233564173 : 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 : 496566 : 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 : 496566 : unsigned HOST_WIDE_INT this_align, outer_align;
8678 : :
8679 : 496566 : switch (TREE_CODE (target))
8680 : : {
8681 : : case BIT_FIELD_REF:
8682 : : return 1;
8683 : :
8684 : 134897 : case COMPONENT_REF:
8685 : 134897 : this_align = DECL_ALIGN (TREE_OPERAND (target, 1));
8686 : 134897 : outer_align = target_align (TREE_OPERAND (target, 0));
8687 : 134897 : return MIN (this_align, outer_align);
8688 : :
8689 : 183931 : case ARRAY_REF:
8690 : 183931 : case ARRAY_RANGE_REF:
8691 : 183931 : this_align = TYPE_ALIGN (TREE_TYPE (target));
8692 : 183931 : outer_align = target_align (TREE_OPERAND (target, 0));
8693 : 183931 : return MIN (this_align, outer_align);
8694 : :
8695 : 4345 : CASE_CONVERT:
8696 : 4345 : case NON_LVALUE_EXPR:
8697 : 4345 : case VIEW_CONVERT_EXPR:
8698 : 4345 : this_align = TYPE_ALIGN (TREE_TYPE (target));
8699 : 4345 : outer_align = target_align (TREE_OPERAND (target, 0));
8700 : 4345 : return MAX (this_align, outer_align);
8701 : :
8702 : 173389 : default:
8703 : 173389 : 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 : 31086023 : force_operand (rtx value, rtx target)
8717 : : {
8718 : 31086023 : rtx op1, op2;
8719 : : /* Use subtarget as the target for operand 0 of a binary operation. */
8720 : 31086023 : rtx subtarget = get_subtarget (target);
8721 : 31086023 : enum rtx_code code = GET_CODE (value);
8722 : :
8723 : : /* Check for subreg applied to an expression produced by loop optimizer. */
8724 : 31086023 : if (code == SUBREG
8725 : 242043 : && !REG_P (SUBREG_REG (value))
8726 : 173 : && !MEM_P (SUBREG_REG (value)))
8727 : : {
8728 : 173 : value
8729 : 173 : = simplify_gen_subreg (GET_MODE (value),
8730 : 173 : force_reg (GET_MODE (SUBREG_REG (value)),
8731 : : force_operand (SUBREG_REG (value),
8732 : : NULL_RTX)),
8733 : 173 : GET_MODE (SUBREG_REG (value)),
8734 : 173 : SUBREG_BYTE (value));
8735 : 173 : code = GET_CODE (value);
8736 : : }
8737 : :
8738 : : /* Check for a PIC address load. */
8739 : 31086023 : if ((code == PLUS || code == MINUS)
8740 : 3758968 : && XEXP (value, 0) == pic_offset_table_rtx
8741 : 1960 : && (GET_CODE (XEXP (value, 1)) == SYMBOL_REF
8742 : 1960 : || GET_CODE (XEXP (value, 1)) == LABEL_REF
8743 : 1960 : || GET_CODE (XEXP (value, 1)) == CONST))
8744 : : {
8745 : 220 : if (!subtarget)
8746 : 220 : subtarget = gen_reg_rtx (GET_MODE (value));
8747 : 220 : emit_move_insn (subtarget, value);
8748 : 220 : return subtarget;
8749 : : }
8750 : :
8751 : 31085803 : if (ARITHMETIC_P (value))
8752 : : {
8753 : 3868453 : op2 = XEXP (value, 1);
8754 : 3868453 : if (!CONSTANT_P (op2) && !(REG_P (op2) && op2 != subtarget))
8755 : 3868453 : subtarget = 0;
8756 : 3868453 : 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 : 3696124 : if (code == PLUS && CONST_INT_P (op2)
8769 : 3339881 : && GET_CODE (XEXP (value, 0)) == PLUS
8770 : 103351 : && REG_P (XEXP (XEXP (value, 0), 0))
8771 : 3921213 : && VIRTUAL_REGISTER_P (XEXP (XEXP (value, 0), 0)))
8772 : : {
8773 : 2676 : rtx temp = expand_simple_binop (GET_MODE (value), code,
8774 : : XEXP (XEXP (value, 0), 0), op2,
8775 : : subtarget, 0, OPTAB_LIB_WIDEN);
8776 : 2676 : return expand_simple_binop (GET_MODE (value), code, temp,
8777 : 2676 : force_operand (XEXP (XEXP (value,
8778 : : 0), 1), 0),
8779 : 2676 : target, 0, OPTAB_LIB_WIDEN);
8780 : : }
8781 : :
8782 : 3865777 : op1 = force_operand (XEXP (value, 0), subtarget);
8783 : 3865777 : op2 = force_operand (op2, NULL_RTX);
8784 : 3865777 : switch (code)
8785 : : {
8786 : 90114 : case MULT:
8787 : 90114 : return expand_mult (GET_MODE (value), op1, op2, target, 1);
8788 : 222 : case DIV:
8789 : 222 : if (!INTEGRAL_MODE_P (GET_MODE (value)))
8790 : 222 : return expand_simple_binop (GET_MODE (value), code, op1, op2,
8791 : 222 : 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 : 384 : case UDIV:
8801 : 384 : return expand_divmod (0, TRUNC_DIV_EXPR, GET_MODE (value), op1, op2,
8802 : 384 : 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 : 80 : case ASHIFTRT:
8807 : 80 : return expand_simple_binop (GET_MODE (value), code, op1, op2,
8808 : 80 : target, 0, OPTAB_LIB_WIDEN);
8809 : 3774977 : default:
8810 : 3774977 : return expand_simple_binop (GET_MODE (value), code, op1, op2,
8811 : 3774977 : target, 1, OPTAB_LIB_WIDEN);
8812 : : }
8813 : : }
8814 : 27217350 : if (UNARY_P (value))
8815 : : {
8816 : 16580 : if (!target)
8817 : 6725 : 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 : 16580 : 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 : 16580 : op1 = force_operand (XEXP (value, 0), NULL_RTX);
8831 : 16580 : switch (code)
8832 : : {
8833 : 4779 : case ZERO_EXTEND:
8834 : 4779 : case SIGN_EXTEND:
8835 : 4779 : case TRUNCATE:
8836 : 4779 : case FLOAT_EXTEND:
8837 : 4779 : case FLOAT_TRUNCATE:
8838 : 4779 : convert_move (target, op1, code == ZERO_EXTEND);
8839 : 4779 : 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 : 11677 : default:
8852 : 11677 : 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 : 27200770 : 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 : 8445956 : safe_from_p (const_rtx x, tree exp, int top_p)
8882 : : {
8883 : 8445972 : rtx exp_rtl = 0;
8884 : 8445972 : int i, nops;
8885 : :
8886 : 8445972 : 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 : 1950382 : || (top_p && TREE_TYPE (exp) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp))
8894 : 1820189 : && 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 : 10396354 : || (MEM_P (x)
8902 : 184578 : && (XEXP (x, 0) == virtual_outgoing_args_rtx
8903 : 184578 : || (GET_CODE (XEXP (x, 0)) == PLUS
8904 : 137047 : && 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 : 1950382 : 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 : 1950382 : switch (TREE_CODE_CLASS (TREE_CODE (exp)))
8918 : : {
8919 : 427 : case tcc_declaration:
8920 : 427 : exp_rtl = DECL_RTL_IF_SET (exp);
8921 : : break;
8922 : :
8923 : : case tcc_constant:
8924 : : return true;
8925 : :
8926 : 853303 : case tcc_exceptional:
8927 : 853303 : 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 : 853303 : else if (TREE_CODE (exp) == CONSTRUCTOR)
8941 : : {
8942 : : constructor_elt *ce;
8943 : : unsigned HOST_WIDE_INT idx;
8944 : :
8945 : 7757956 : FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp), idx, ce)
8946 : 3945 : if ((ce->index != NULL_TREE && !safe_from_p (x, ce->index, 0))
8947 : 130018 : || !safe_from_p (x, ce->value, 0))
8948 : 104511 : return false;
8949 : : return true;
8950 : : }
8951 : 710681 : 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 : 266 : case tcc_expression:
8974 : 266 : case tcc_reference:
8975 : 266 : 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 : 266 : switch (TREE_CODE (exp))
8982 : : {
8983 : 243 : 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 : 243 : if (staticp (TREE_OPERAND (exp, 0))
8987 : 113 : || TREE_STATIC (exp)
8988 : 356 : || safe_from_p (x, TREE_OPERAND (exp, 0), 0))
8989 : 243 : 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 : 272 : if (exp_rtl)
9052 : : {
9053 : 249 : 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 : 249 : return ! (rtx_equal_p (x, exp_rtl)
9064 : 249 : || (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 : 32503616 : highest_pow2_factor (const_tree exp)
9078 : : {
9079 : 32503616 : unsigned HOST_WIDE_INT ret;
9080 : 32503616 : int trailing_zeros = tree_ctz (exp);
9081 : 32503616 : if (trailing_zeros >= HOST_BITS_PER_WIDE_INT)
9082 : 45183032 : return BIGGEST_ALIGNMENT;
9083 : 9573700 : ret = HOST_WIDE_INT_1U << trailing_zeros;
9084 : 18681962 : if (ret > BIGGEST_ALIGNMENT)
9085 : 12571968 : 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 : 173393 : highest_pow2_factor_for_target (const_tree target, const_tree exp)
9096 : : {
9097 : 173393 : unsigned HOST_WIDE_INT talign = target_align (target) / BITS_PER_UNIT;
9098 : 173393 : unsigned HOST_WIDE_INT factor = highest_pow2_factor (exp);
9099 : :
9100 : 173393 : 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 : 14121 : convert_tree_comp_to_rtx (enum tree_code tcode, int unsignedp)
9108 : : {
9109 : 14121 : enum rtx_code code;
9110 : 14121 : switch (tcode)
9111 : : {
9112 : : case EQ_EXPR:
9113 : : code = EQ;
9114 : : break;
9115 : 942 : case NE_EXPR:
9116 : 942 : code = NE;
9117 : 942 : break;
9118 : 3207 : case LT_EXPR:
9119 : 3207 : code = unsignedp ? LTU : LT;
9120 : : break;
9121 : 1664 : case LE_EXPR:
9122 : 1664 : code = unsignedp ? LEU : LE;
9123 : : break;
9124 : 1967 : case GT_EXPR:
9125 : 1967 : code = unsignedp ? GTU : GT;
9126 : : break;
9127 : 3459 : case GE_EXPR:
9128 : 3459 : 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 : 14121 : 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 : 7857536 : expand_operands (tree exp0, tree exp1, rtx target, rtx *op0, rtx *op1,
9168 : : enum expand_modifier modifier)
9169 : : {
9170 : 7857536 : if (! safe_from_p (target, exp1, 1))
9171 : 589721 : target = 0;
9172 : 7857536 : if (operand_equal_p (exp0, exp1, 0))
9173 : : {
9174 : 49265 : *op0 = expand_expr (exp0, target, VOIDmode, modifier);
9175 : 49265 : *op1 = copy_rtx (*op0);
9176 : : }
9177 : : else
9178 : : {
9179 : 7808271 : *op0 = expand_expr (exp0, target, VOIDmode, modifier);
9180 : 7808271 : *op1 = expand_expr (exp1, NULL_RTX, VOIDmode, modifier);
9181 : : }
9182 : 7857536 : }
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 : 2911831 : expand_expr_constant (tree exp, int defer, enum expand_modifier modifier)
9190 : : {
9191 : 2911831 : rtx mem;
9192 : :
9193 : 2911831 : mem = output_constant_def (exp, defer);
9194 : 2911831 : if (modifier != EXPAND_INITIALIZER)
9195 : 1874504 : mem = use_anchored_address (mem);
9196 : 2911831 : 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 : 14368019 : expand_expr_addr_expr_1 (tree exp, rtx target, scalar_int_mode tmode,
9204 : : enum expand_modifier modifier, addr_space_t as)
9205 : : {
9206 : 14368019 : rtx result, subtarget;
9207 : 14368019 : tree inner, offset;
9208 : 14368019 : poly_int64 bitsize, bitpos;
9209 : 14368019 : int unsignedp, reversep, volatilep = 0;
9210 : 14368019 : 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 : 14368019 : if (CONSTANT_CLASS_P (exp))
9219 : : {
9220 : 2675800 : result = XEXP (expand_expr_constant (exp, 0, modifier), 0);
9221 : 2675800 : if (modifier < EXPAND_SUM)
9222 : 1781927 : result = force_operand (result, target);
9223 : 2675800 : return result;
9224 : : }
9225 : :
9226 : : /* Everything must be something allowed by is_gimple_addressable. */
9227 : 11692219 : 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 : 595839 : case MEM_REF:
9234 : 595839 : {
9235 : 595839 : tree tem = TREE_OPERAND (exp, 0);
9236 : 595839 : if (!integer_zerop (TREE_OPERAND (exp, 1)))
9237 : 321098 : tem = fold_build_pointer_plus (tem, TREE_OPERAND (exp, 1));
9238 : 595839 : return expand_expr (tem, target, tmode, modifier);
9239 : : }
9240 : :
9241 : 1231 : case TARGET_MEM_REF:
9242 : 1231 : return addr_for_mem_ref (exp, as, true);
9243 : :
9244 : 58669 : case CONST_DECL:
9245 : : /* Expand the initializer like constants above. */
9246 : 58669 : result = XEXP (expand_expr_constant (DECL_INITIAL (exp),
9247 : : 0, modifier), 0);
9248 : 58669 : if (modifier < EXPAND_SUM)
9249 : 58663 : result = force_operand (result, target);
9250 : : return result;
9251 : :
9252 : 154 : 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 : 154 : offset = 0;
9256 : 154 : bitpos = 0;
9257 : 154 : inner = TREE_OPERAND (exp, 0);
9258 : 154 : break;
9259 : :
9260 : 88 : 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 : 88 : offset = 0;
9265 : 176 : bitpos = GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (exp)));
9266 : 88 : inner = TREE_OPERAND (exp, 0);
9267 : 88 : 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 : 11036189 : 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 : 11036189 : gcc_assert (TREE_CODE (exp) < LAST_AND_UNUSED_TREE_CODE);
9288 : 11036189 : if (DECL_P (exp)
9289 : 1343229 : || TREE_CODE (exp) == CONSTRUCTOR
9290 : 1343229 : || TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
9291 : : {
9292 : 15885509 : 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 : 9692960 : gcc_assert (MEM_P (result));
9301 : 9692960 : result = XEXP (result, 0);
9302 : :
9303 : : /* ??? Is this needed anymore? */
9304 : 9692960 : if (DECL_P (exp))
9305 : 9692960 : TREE_USED (exp) = 1;
9306 : :
9307 : 9692960 : if (modifier != EXPAND_INITIALIZER
9308 : : && modifier != EXPAND_CONST_ADDRESS
9309 : 9692960 : && modifier != EXPAND_SUM)
9310 : 4207178 : result = force_operand (result, target);
9311 : 9692960 : 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 : 1343229 : inner = get_inner_reference (exp, &bitsize, &bitpos, &offset, &mode1,
9320 : : &unsignedp, &reversep, &volatilep);
9321 : 1343229 : break;
9322 : : }
9323 : :
9324 : : /* We must have made progress. */
9325 : 1343471 : gcc_assert (inner != exp);
9326 : :
9327 : 1343471 : 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 : 1343471 : if (CONSTANT_CLASS_P (inner)
9331 : 1343471 : && 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 : 1343471 : result = expand_expr_addr_expr_1 (inner, subtarget, tmode, modifier, as);
9339 : :
9340 : 1343471 : if (offset)
9341 : : {
9342 : 54337 : rtx tmp;
9343 : :
9344 : 54337 : if (modifier != EXPAND_NORMAL)
9345 : 1529 : result = force_operand (result, NULL);
9346 : 55866 : 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 : 54337 : 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 : 54337 : result = convert_memory_address_addr_space (tmode, result, as);
9356 : 54337 : tmp = convert_memory_address_addr_space (tmode, tmp, as);
9357 : :
9358 : 54337 : if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
9359 : 1529 : result = simplify_gen_binary (PLUS, tmode, result, tmp);
9360 : : else
9361 : : {
9362 : 52808 : subtarget = maybe_ne (bitpos, 0) ? NULL_RTX : target;
9363 : 52808 : result = expand_simple_binop (tmode, PLUS, result, tmp, subtarget,
9364 : : 1, OPTAB_LIB_WIDEN);
9365 : : }
9366 : : }
9367 : :
9368 : 1343471 : 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 : 669976 : poly_int64 bytepos = exact_div (bitpos, BITS_PER_UNIT);
9373 : 669976 : result = convert_memory_address_addr_space (tmode, result, as);
9374 : 669976 : result = plus_constant (tmode, result, bytepos);
9375 : 669976 : if (modifier < EXPAND_SUM)
9376 : 635382 : 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 : 13024533 : expand_expr_addr_expr (tree exp, rtx target, machine_mode tmode,
9387 : : enum expand_modifier modifier)
9388 : : {
9389 : 13024533 : addr_space_t as = ADDR_SPACE_GENERIC;
9390 : 13024533 : scalar_int_mode address_mode = Pmode;
9391 : 13024533 : scalar_int_mode pointer_mode = ptr_mode;
9392 : 13024533 : machine_mode rmode;
9393 : 13024533 : rtx result;
9394 : :
9395 : : /* Target mode of VOIDmode says "whatever's natural". */
9396 : 13024533 : if (tmode == VOIDmode)
9397 : 11070718 : tmode = TYPE_MODE (TREE_TYPE (exp));
9398 : :
9399 : 13024533 : if (POINTER_TYPE_P (TREE_TYPE (exp)))
9400 : : {
9401 : 13024533 : as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)));
9402 : 13024533 : address_mode = targetm.addr_space.address_mode (as);
9403 : 13024533 : 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 : 13024533 : scalar_int_mode new_tmode = (tmode == pointer_mode
9410 : 13024533 : ? pointer_mode
9411 : 13024533 : : address_mode);
9412 : :
9413 : 13024533 : 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 : 13024533 : rmode = GET_MODE (result);
9420 : 13024533 : if (rmode == VOIDmode)
9421 : 6 : rmode = new_tmode;
9422 : 13024533 : if (rmode != new_tmode)
9423 : 74 : result = convert_memory_address_addr_space (new_tmode, result, as);
9424 : :
9425 : 13024533 : 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 : 179066 : expand_constructor (tree exp, rtx target, enum expand_modifier modifier,
9435 : : bool avoid_temp_mem)
9436 : : {
9437 : 179066 : tree type = TREE_TYPE (exp);
9438 : 179066 : 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 : 179066 : if (TREE_STATIC (exp)
9445 : 2173 : && !TREE_ADDRESSABLE (exp)
9446 : 2173 : && target != 0 && mode == BLKmode
9447 : 180307 : && all_zeros_p (exp))
9448 : : {
9449 : 1232 : clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
9450 : 1232 : 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 : 177834 : if ((TREE_STATIC (exp)
9467 : 941 : && ((mode == BLKmode
9468 : 46 : && ! (target != 0 && safe_from_p (target, exp, 1)))
9469 : 904 : || TREE_ADDRESSABLE (exp)
9470 : 904 : || (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type))
9471 : 904 : && (! can_move_by_pieces
9472 : 904 : (tree_to_uhwi (TYPE_SIZE_UNIT (type)),
9473 : 904 : TYPE_ALIGN (type)))
9474 : 4 : && ! mostly_zeros_p (exp))))
9475 : 178736 : || ((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 : 177795 : if (avoid_temp_mem
9498 : 66 : && 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 : 177832 : && ! 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 : 142587 : if (target == 0 || ! safe_from_p (target, exp, 1)
9509 : 38076 : || 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 : 215829 : || (GET_CODE (target) == MEM
9513 : 34011 : && MEM_VOLATILE_P (target)
9514 : 134 : && !TREE_ADDRESSABLE (TREE_TYPE (exp))))
9515 : : {
9516 : 139829 : if (avoid_temp_mem)
9517 : : return NULL_RTX;
9518 : :
9519 : 139818 : target = assign_temp (type, TREE_ADDRESSABLE (exp), 1);
9520 : : }
9521 : :
9522 : 177754 : store_constructor (exp, target, 0, int_expr_size (exp), false);
9523 : 177754 : 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 : 155614337 : 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 : 155614337 : rtx ret;
9592 : :
9593 : : /* Handle ERROR_MARK before anybody tries to access its type. */
9594 : 155614337 : if (TREE_CODE (exp) == ERROR_MARK
9595 : 155614337 : || (TREE_CODE (TREE_TYPE (exp)) == ERROR_MARK))
9596 : : {
9597 : 0 : ret = CONST0_RTX (tmode);
9598 : 0 : return ret ? ret : const0_rtx;
9599 : : }
9600 : :
9601 : 155614337 : ret = expand_expr_real_1 (exp, target, tmode, modifier, alt_rtl,
9602 : : inner_reference_p);
9603 : 155614337 : 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 : 17568 : expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED,
9613 : : tree treeop1 ATTRIBUTE_UNUSED,
9614 : : tree treeop2 ATTRIBUTE_UNUSED)
9615 : : {
9616 : 17568 : rtx insn;
9617 : 17568 : rtx op00, op01, op1, op2;
9618 : 17568 : enum rtx_code comparison_code;
9619 : 17568 : machine_mode comparison_mode;
9620 : 17568 : gimple *srcstmt;
9621 : 17568 : rtx temp;
9622 : 17568 : tree type = TREE_TYPE (treeop1);
9623 : 17568 : int unsignedp = TYPE_UNSIGNED (type);
9624 : 17568 : machine_mode mode = TYPE_MODE (type);
9625 : 17568 : machine_mode orig_mode = mode;
9626 : 17568 : 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 : 17568 : 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 : 16584 : if (!can_conditionally_move_p (mode))
9639 : : {
9640 : 167 : mode = promote_mode (type, mode, &unsignedp);
9641 : 167 : 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 : 16417 : temp = assign_temp (type, 0, 1);
9647 : :
9648 : 16417 : expanding_cond_expr_using_cmove = true;
9649 : 16417 : start_sequence ();
9650 : 16417 : expand_operands (treeop1, treeop2,
9651 : : mode == orig_mode ? temp : NULL_RTX, &op1, &op2,
9652 : : EXPAND_NORMAL);
9653 : :
9654 : 16417 : if (TREE_CODE (treeop0) == SSA_NAME
9655 : 16218 : && (srcstmt = get_def_for_expr_class (treeop0, tcc_comparison))
9656 : 30342 : && !VECTOR_TYPE_P (TREE_TYPE (gimple_assign_rhs1 (srcstmt))))
9657 : : {
9658 : 13922 : type = TREE_TYPE (gimple_assign_rhs1 (srcstmt));
9659 : 13922 : enum tree_code cmpcode = gimple_assign_rhs_code (srcstmt);
9660 : 13922 : op00 = expand_normal (gimple_assign_rhs1 (srcstmt));
9661 : 13922 : op01 = expand_normal (gimple_assign_rhs2 (srcstmt));
9662 : 13922 : comparison_mode = TYPE_MODE (type);
9663 : 13922 : unsignedp = TYPE_UNSIGNED (type);
9664 : 13922 : comparison_code = convert_tree_comp_to_rtx (cmpcode, unsignedp);
9665 : : }
9666 : 2495 : else if (COMPARISON_CLASS_P (treeop0)
9667 : 2495 : && !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 : 2296 : op00 = expand_normal (treeop0);
9680 : 2296 : op01 = const0_rtx;
9681 : 2296 : comparison_code = NE;
9682 : 2296 : comparison_mode = GET_MODE (op00);
9683 : 2296 : if (comparison_mode == VOIDmode)
9684 : 0 : comparison_mode = TYPE_MODE (TREE_TYPE (treeop0));
9685 : : }
9686 : 16417 : expanding_cond_expr_using_cmove = false;
9687 : :
9688 : 16417 : if (GET_MODE (op1) != mode)
9689 : 2116 : op1 = gen_lowpart (mode, op1);
9690 : :
9691 : 16417 : if (GET_MODE (op2) != mode)
9692 : 9240 : op2 = gen_lowpart (mode, op2);
9693 : :
9694 : : /* Try to emit the conditional move. */
9695 : 16417 : 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 : 16417 : if (insn)
9704 : : {
9705 : 13978 : rtx_insn *seq = end_sequence ();
9706 : 13978 : emit_insn (seq);
9707 : 13978 : return convert_modes (orig_mode, mode, temp, 0);
9708 : : }
9709 : :
9710 : : /* Otherwise discard the sequence and fall back to code with
9711 : : branches. */
9712 : 2439 : end_sequence ();
9713 : 2439 : 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 : 198448 : expand_misaligned_mem_ref (rtx temp, machine_mode mode, int unsignedp,
9726 : : unsigned int align, rtx target, rtx *alt_rtl)
9727 : : {
9728 : 198448 : enum insn_code icode;
9729 : :
9730 : 198448 : if ((icode = optab_handler (movmisalign_optab, mode))
9731 : : != CODE_FOR_nothing)
9732 : : {
9733 : 123204 : 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 : 123204 : create_output_operand (&ops[0], NULL_RTX, mode);
9739 : 123204 : create_fixed_operand (&ops[1], temp);
9740 : 123204 : expand_insn (icode, 2, ops);
9741 : 123204 : temp = ops[0].value;
9742 : : }
9743 : 75244 : 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 : 198448 : 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 : 159413 : expand_expr_divmod (tree_code code, machine_mode mode, tree treeop0,
9756 : : tree treeop1, rtx op0, rtx op1, rtx target, int unsignedp)
9757 : : {
9758 : 318826 : bool mod_p = (code == TRUNC_MOD_EXPR || code == FLOOR_MOD_EXPR
9759 : 159413 : || code == CEIL_MOD_EXPR || code == ROUND_MOD_EXPR);
9760 : 159413 : if (SCALAR_INT_MODE_P (mode)
9761 : 159413 : && optimize >= 2
9762 : 133348 : && get_range_pos_neg (treeop0, currently_expanding_gimple_stmt) == 1
9763 : 197721 : && 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 : 26038 : bool speed_p = optimize_insn_for_speed_p ();
9769 : 26038 : do_pending_stack_adjust ();
9770 : 26038 : start_sequence ();
9771 : 26038 : rtx uns_ret = expand_divmod (mod_p, code, mode, op0, op1, target, 1);
9772 : 26038 : rtx_insn *uns_insns = end_sequence ();
9773 : 26038 : start_sequence ();
9774 : 26038 : rtx sgn_ret = expand_divmod (mod_p, code, mode, op0, op1, target, 0);
9775 : 26038 : rtx_insn *sgn_insns = end_sequence ();
9776 : 26038 : unsigned uns_cost = seq_cost (uns_insns, speed_p);
9777 : 26038 : unsigned sgn_cost = seq_cost (sgn_insns, speed_p);
9778 : 26038 : bool was_tie = false;
9779 : :
9780 : : /* If costs are the same then use as tie breaker the other other
9781 : : factor. */
9782 : 26038 : if (uns_cost == sgn_cost)
9783 : : {
9784 : 12594 : uns_cost = seq_cost (uns_insns, !speed_p);
9785 : 12594 : sgn_cost = seq_cost (sgn_insns, !speed_p);
9786 : 12594 : was_tie = true;
9787 : : }
9788 : :
9789 : 26038 : 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 : 26038 : if (uns_cost < sgn_cost || (uns_cost == sgn_cost && unsignedp))
9795 : : {
9796 : 14307 : emit_insn (uns_insns);
9797 : 14307 : return uns_ret;
9798 : : }
9799 : 11731 : emit_insn (sgn_insns);
9800 : 11731 : return sgn_ret;
9801 : : }
9802 : 133375 : return expand_divmod (mod_p, code, mode, op0, op1, target, unsignedp);
9803 : : }
9804 : :
9805 : : rtx
9806 : 13052643 : expand_expr_real_2 (const_sepops ops, rtx target, machine_mode tmode,
9807 : : enum expand_modifier modifier)
9808 : : {
9809 : 13052643 : rtx op0, op1, op2, temp;
9810 : 13052643 : rtx_code_label *lab;
9811 : 13052643 : tree type;
9812 : 13052643 : int unsignedp;
9813 : 13052643 : machine_mode mode;
9814 : 13052643 : scalar_int_mode int_mode;
9815 : 13052643 : enum tree_code code = ops->code;
9816 : 13052643 : optab this_optab;
9817 : 13052643 : rtx subtarget, original_target;
9818 : 13052643 : int ignore;
9819 : 13052643 : bool reduce_bit_field;
9820 : 13052643 : location_t loc = ops->location;
9821 : 13052643 : tree treeop0, treeop1, treeop2;
9822 : : #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
9823 : : ? reduce_to_bit_field_precision ((expr), \
9824 : : target, \
9825 : : type) \
9826 : : : (expr))
9827 : :
9828 : 13052643 : type = ops->type;
9829 : 13052643 : mode = TYPE_MODE (type);
9830 : 13052643 : unsignedp = TYPE_UNSIGNED (type);
9831 : :
9832 : 13052643 : treeop0 = ops->op0;
9833 : 13052643 : treeop1 = ops->op1;
9834 : 13052643 : treeop2 = ops->op2;
9835 : :
9836 : : /* We should be called only on simple (binary or unary) expressions,
9837 : : exactly those that are valid in gimple expressions that aren't
9838 : : GIMPLE_SINGLE_RHS (or invalid). */
9839 : 13052643 : gcc_assert (get_gimple_rhs_class (code) == GIMPLE_UNARY_RHS
9840 : : || get_gimple_rhs_class (code) == GIMPLE_BINARY_RHS
9841 : : || get_gimple_rhs_class (code) == GIMPLE_TERNARY_RHS);
9842 : :
9843 : 26105286 : ignore = (target == const0_rtx
9844 : 13052643 : || ((CONVERT_EXPR_CODE_P (code)
9845 : 9368822 : || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
9846 : 3701389 : && TREE_CODE (type) == VOID_TYPE));
9847 : :
9848 : : /* We should be called only if we need the result. */
9849 : 0 : gcc_assert (!ignore);
9850 : :
9851 : : /* An operation in what may be a bit-field type needs the
9852 : : result to be reduced to the precision of the bit-field type,
9853 : : which is narrower than that of the type's mode. */
9854 : 26802861 : reduce_bit_field = (INTEGRAL_TYPE_P (type)
9855 : 13052643 : && !type_has_mode_precision_p (type));
9856 : :
9857 : 697575 : if (reduce_bit_field
9858 : 697575 : && (modifier == EXPAND_STACK_PARM
9859 : 697054 : || (target && GET_MODE (target) != mode)))
9860 : 386852 : target = 0;
9861 : :
9862 : : /* Use subtarget as the target for operand 0 of a binary operation. */
9863 : 13052643 : subtarget = get_subtarget (target);
9864 : 13052643 : original_target = target;
9865 : :
9866 : 13052643 : switch (code)
9867 : : {
9868 : 3687002 : case NON_LVALUE_EXPR:
9869 : 3687002 : case PAREN_EXPR:
9870 : 3687002 : CASE_CONVERT:
9871 : 3687002 : if (treeop0 == error_mark_node)
9872 : 0 : return const0_rtx;
9873 : :
9874 : 3687002 : if (TREE_CODE (type) == UNION_TYPE)
9875 : : {
9876 : 0 : tree valtype = TREE_TYPE (treeop0);
9877 : :
9878 : : /* If both input and output are BLKmode, this conversion isn't doing
9879 : : anything except possibly changing memory attribute. */
9880 : 0 : if (mode == BLKmode && TYPE_MODE (valtype) == BLKmode)
9881 : : {
9882 : 0 : rtx result = expand_expr (treeop0, target, tmode,
9883 : : modifier);
9884 : :
9885 : 0 : result = copy_rtx (result);
9886 : 0 : set_mem_attributes (result, type, 0);
9887 : 0 : return result;
9888 : : }
9889 : :
9890 : 0 : if (target == 0)
9891 : : {
9892 : 0 : if (TYPE_MODE (type) != BLKmode)
9893 : 0 : target = gen_reg_rtx (TYPE_MODE (type));
9894 : : else
9895 : 0 : target = assign_temp (type, 1, 1);
9896 : : }
9897 : :
9898 : 0 : if (MEM_P (target))
9899 : : /* Store data into beginning of memory target. */
9900 : 0 : store_expr (treeop0,
9901 : 0 : adjust_address (target, TYPE_MODE (valtype), 0),
9902 : : modifier == EXPAND_STACK_PARM,
9903 : 0 : false, TYPE_REVERSE_STORAGE_ORDER (type));
9904 : :
9905 : : else
9906 : : {
9907 : 0 : gcc_assert (REG_P (target)
9908 : : && !TYPE_REVERSE_STORAGE_ORDER (type));
9909 : :
9910 : : /* Store this field into a union of the proper type. */
9911 : 0 : poly_uint64 op0_size
9912 : 0 : = tree_to_poly_uint64 (TYPE_SIZE (TREE_TYPE (treeop0)));
9913 : 0 : poly_uint64 union_size = GET_MODE_BITSIZE (mode);
9914 : 0 : store_field (target,
9915 : : /* The conversion must be constructed so that
9916 : : we know at compile time how many bits
9917 : : to preserve. */
9918 : 0 : ordered_min (op0_size, union_size),
9919 : 0 : 0, 0, 0, TYPE_MODE (valtype), treeop0, 0,
9920 : : false, false);
9921 : : }
9922 : :
9923 : : /* Return the entire union. */
9924 : 0 : return target;
9925 : : }
9926 : :
9927 : 3687002 : if (mode == TYPE_MODE (TREE_TYPE (treeop0)))
9928 : : {
9929 : 2189174 : op0 = expand_expr (treeop0, target, VOIDmode,
9930 : : modifier);
9931 : :
9932 : 2189174 : return REDUCE_BIT_FIELD (op0);
9933 : : }
9934 : :
9935 : 1862341 : op0 = expand_expr (treeop0, NULL_RTX, mode,
9936 : : modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier);
9937 : 1497828 : if (GET_MODE (op0) == mode)
9938 : : ;
9939 : :
9940 : : /* If OP0 is a constant, just convert it into the proper mode. */
9941 : 1456629 : else if (CONSTANT_P (op0))
9942 : : {
9943 : 903 : tree inner_type = TREE_TYPE (treeop0);
9944 : 903 : machine_mode inner_mode = GET_MODE (op0);
9945 : :
9946 : 903 : if (inner_mode == VOIDmode)
9947 : 17 : inner_mode = TYPE_MODE (inner_type);
9948 : :
9949 : 903 : if (modifier == EXPAND_INITIALIZER)
9950 : 0 : op0 = force_lowpart_subreg (mode, op0, inner_mode);
9951 : : else
9952 : 903 : op0 = convert_modes (mode, inner_mode, op0,
9953 : 903 : TYPE_UNSIGNED (inner_type));
9954 : : }
9955 : :
9956 : 1455726 : else if (modifier == EXPAND_INITIALIZER)
9957 : 24 : op0 = gen_rtx_fmt_e (TYPE_UNSIGNED (TREE_TYPE (treeop0))
9958 : : ? ZERO_EXTEND : SIGN_EXTEND, mode, op0);
9959 : :
9960 : 1455714 : else if (SCALAR_INT_MODE_P (GET_MODE (op0))
9961 : 1283417 : && optimize >= 2
9962 : 749929 : && SCALAR_INT_MODE_P (mode)
9963 : 749929 : && INTEGRAL_TYPE_P (TREE_TYPE (treeop0))
9964 : 749727 : && (GET_MODE_SIZE (as_a <scalar_int_mode> (mode))
9965 : 1499454 : > GET_MODE_SIZE (as_a <scalar_int_mode> (GET_MODE (op0))))
9966 : 1964930 : && get_range_pos_neg (treeop0,
9967 : : currently_expanding_gimple_stmt) == 1)
9968 : : {
9969 : : /* If argument is known to be positive when interpreted
9970 : : as signed, we can expand it as both sign and zero
9971 : : extension. Choose the cheaper sequence in that case. */
9972 : 150544 : bool speed_p = optimize_insn_for_speed_p ();
9973 : 150544 : rtx uns_ret = NULL_RTX, sgn_ret = NULL_RTX;
9974 : 150544 : do_pending_stack_adjust ();
9975 : 150544 : start_sequence ();
9976 : 150544 : if (target == NULL_RTX)
9977 : 122606 : uns_ret = convert_to_mode (mode, op0, 1);
9978 : : else
9979 : 27938 : convert_move (target, op0, 1);
9980 : 150544 : rtx_insn *uns_insns = end_sequence ();
9981 : 150544 : start_sequence ();
9982 : 150544 : if (target == NULL_RTX)
9983 : 122606 : sgn_ret = convert_to_mode (mode, op0, 0);
9984 : : else
9985 : 27938 : convert_move (target, op0, 0);
9986 : 150544 : rtx_insn *sgn_insns = end_sequence ();
9987 : 150544 : unsigned uns_cost = seq_cost (uns_insns, speed_p);
9988 : 150544 : unsigned sgn_cost = seq_cost (sgn_insns, speed_p);
9989 : 150544 : bool was_tie = false;
9990 : :
9991 : : /* If costs are the same then use as tie breaker the other other
9992 : : factor. */
9993 : 150544 : if (uns_cost == sgn_cost)
9994 : : {
9995 : 41350 : uns_cost = seq_cost (uns_insns, !speed_p);
9996 : 41350 : sgn_cost = seq_cost (sgn_insns, !speed_p);
9997 : 41350 : was_tie = true;
9998 : : }
9999 : :
10000 : 150544 : if (dump_file && (dump_flags & TDF_DETAILS))
10001 : 0 : fprintf (dump_file, ";; positive extension:%s unsigned cost: %u; "
10002 : : "signed cost: %u\n",
10003 : : was_tie ? " (needed tie breaker)" : "",
10004 : : uns_cost, sgn_cost);
10005 : 150544 : if (uns_cost < sgn_cost
10006 : 150544 : || (uns_cost == sgn_cost && TYPE_UNSIGNED (TREE_TYPE (treeop0))))
10007 : : {
10008 : 137072 : emit_insn (uns_insns);
10009 : 137072 : sgn_ret = uns_ret;
10010 : : }
10011 : : else
10012 : 13472 : emit_insn (sgn_insns);
10013 : 150544 : if (target == NULL_RTX)
10014 : 122606 : op0 = sgn_ret;
10015 : : else
10016 : 27938 : op0 = target;
10017 : : }
10018 : 1305170 : else if (target == 0)
10019 : 809623 : op0 = convert_to_mode (mode, op0, TYPE_UNSIGNED (TREE_TYPE (treeop0)));
10020 : : else
10021 : : {
10022 : 495547 : convert_move (target, op0, TYPE_UNSIGNED (TREE_TYPE (treeop0)));
10023 : 495547 : op0 = target;
10024 : : }
10025 : :
10026 : 1497828 : return REDUCE_BIT_FIELD (op0);
10027 : :
10028 : 0 : case ADDR_SPACE_CONVERT_EXPR:
10029 : 0 : {
10030 : 0 : tree treeop0_type = TREE_TYPE (treeop0);
10031 : :
10032 : 0 : gcc_assert (POINTER_TYPE_P (type));
10033 : 0 : gcc_assert (POINTER_TYPE_P (treeop0_type));
10034 : :
10035 : 0 : addr_space_t as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
10036 : 0 : addr_space_t as_from = TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type));
10037 : :
10038 : : /* Conversions between pointers to the same address space should
10039 : : have been implemented via CONVERT_EXPR / NOP_EXPR. */
10040 : 0 : gcc_assert (as_to != as_from);
10041 : :
10042 : 0 : op0 = expand_expr (treeop0, NULL_RTX, VOIDmode, modifier);
10043 : :
10044 : : /* Ask target code to handle conversion between pointers
10045 : : to overlapping address spaces. */
10046 : 0 : if (targetm.addr_space.subset_p (as_to, as_from)
10047 : 0 : || targetm.addr_space.subset_p (as_from, as_to))
10048 : : {
10049 : 0 : op0 = targetm.addr_space.convert (op0, treeop0_type, type);
10050 : : }
10051 : : else
10052 : : {
10053 : : /* For disjoint address spaces, converting anything but a null
10054 : : pointer invokes undefined behavior. We truncate or extend the
10055 : : value as if we'd converted via integers, which handles 0 as
10056 : : required, and all others as the programmer likely expects. */
10057 : : #ifndef POINTERS_EXTEND_UNSIGNED
10058 : : const int POINTERS_EXTEND_UNSIGNED = 1;
10059 : : #endif
10060 : 0 : op0 = convert_modes (mode, TYPE_MODE (treeop0_type),
10061 : : op0, POINTERS_EXTEND_UNSIGNED);
10062 : : }
10063 : 0 : gcc_assert (op0);
10064 : : return op0;
10065 : : }
10066 : :
10067 : 1387698 : case POINTER_PLUS_EXPR:
10068 : : /* Even though the sizetype mode and the pointer's mode can be different
10069 : : expand is able to handle this correctly and get the correct result out
10070 : : of the PLUS_EXPR code. */
10071 : : /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
10072 : : if sizetype precision is smaller than pointer precision. */
10073 : 1387698 : if (TYPE_PRECISION (sizetype) < TYPE_PRECISION (type))
10074 : 0 : treeop1 = fold_convert_loc (loc, type,
10075 : : fold_convert_loc (loc, ssizetype,
10076 : : treeop1));
10077 : : /* If sizetype precision is larger than pointer precision, truncate the
10078 : : offset to have matching modes. */
10079 : 1387698 : else if (TYPE_PRECISION (sizetype) > TYPE_PRECISION (type))
10080 : 0 : treeop1 = fold_convert_loc (loc, type, treeop1);
10081 : : /* FALLTHRU */
10082 : :
10083 : 5224937 : case PLUS_EXPR:
10084 : : /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
10085 : : something else, make sure we add the register to the constant and
10086 : : then to the other thing. This case can occur during strength
10087 : : reduction and doing it this way will produce better code if the
10088 : : frame pointer or argument pointer is eliminated.
10089 : :
10090 : : fold-const.cc will ensure that the constant is always in the inner
10091 : : PLUS_EXPR, so the only case we need to do anything about is if
10092 : : sp, ap, or fp is our second argument, in which case we must swap
10093 : : the innermost first argument and our second argument. */
10094 : :
10095 : 5224937 : if (TREE_CODE (treeop0) == PLUS_EXPR
10096 : 6897 : && TREE_CODE (TREE_OPERAND (treeop0, 1)) == INTEGER_CST
10097 : 0 : && VAR_P (treeop1)
10098 : 5224937 : && (DECL_RTL (treeop1) == frame_pointer_rtx
10099 : 0 : || DECL_RTL (treeop1) == stack_pointer_rtx
10100 : 0 : || DECL_RTL (treeop1) == arg_pointer_rtx))
10101 : : {
10102 : 0 : gcc_unreachable ();
10103 : : }
10104 : :
10105 : : /* If the result is to be ptr_mode and we are adding an integer to
10106 : : something, we might be forming a constant. So try to use
10107 : : plus_constant. If it produces a sum and we can't accept it,
10108 : : use force_operand. This allows P = &ARR[const] to generate
10109 : : efficient code on machines where a SYMBOL_REF is not a valid
10110 : : address.
10111 : :
10112 : : If this is an EXPAND_SUM call, always return the sum. */
10113 : 5224937 : if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER
10114 : 5224937 : || (mode == ptr_mode && (unsignedp || ! flag_trapv)))
10115 : : {
10116 : 3421673 : if (modifier == EXPAND_STACK_PARM)
10117 : 18621 : target = 0;
10118 : 3421673 : if (TREE_CODE (treeop0) == INTEGER_CST
10119 : 3422680 : && HWI_COMPUTABLE_MODE_P (mode)
10120 : 3422684 : && TREE_CONSTANT (treeop1))
10121 : : {
10122 : 4 : rtx constant_part;
10123 : 4 : HOST_WIDE_INT wc;
10124 : 4 : machine_mode wmode = TYPE_MODE (TREE_TYPE (treeop1));
10125 : :
10126 : 4 : op1 = expand_expr (treeop1, subtarget, VOIDmode,
10127 : : EXPAND_SUM);
10128 : : /* Use wi::shwi to ensure that the constant is
10129 : : truncated according to the mode of OP1, then sign extended
10130 : : to a HOST_WIDE_INT. Using the constant directly can result
10131 : : in non-canonical RTL in a 64x32 cross compile. */
10132 : 4 : wc = TREE_INT_CST_LOW (treeop0);
10133 : 4 : constant_part =
10134 : 4 : immed_wide_int_const (wi::shwi (wc, wmode), wmode);
10135 : 4 : op1 = plus_constant (mode, op1, INTVAL (constant_part));
10136 : 4 : if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
10137 : 1 : op1 = force_operand (op1, target);
10138 : 4 : return REDUCE_BIT_FIELD (op1);
10139 : : }
10140 : :
10141 : 3421669 : else if (TREE_CODE (treeop1) == INTEGER_CST
10142 : 7264482 : && HWI_COMPUTABLE_MODE_P (mode)
10143 : 5740347 : && TREE_CONSTANT (treeop0))
10144 : : {
10145 : 279129 : rtx constant_part;
10146 : 279129 : HOST_WIDE_INT wc;
10147 : 279129 : machine_mode wmode = TYPE_MODE (TREE_TYPE (treeop0));
10148 : :
10149 : 487594 : op0 = expand_expr (treeop0, subtarget, VOIDmode,
10150 : : (modifier == EXPAND_INITIALIZER
10151 : : ? EXPAND_INITIALIZER : EXPAND_SUM));
10152 : 279129 : if (! CONSTANT_P (op0))
10153 : : {
10154 : 6 : op1 = expand_expr (treeop1, NULL_RTX,
10155 : : VOIDmode, modifier);
10156 : : /* Return a PLUS if modifier says it's OK. */
10157 : 6 : if (modifier == EXPAND_SUM
10158 : : || modifier == EXPAND_INITIALIZER)
10159 : 6 : return simplify_gen_binary (PLUS, mode, op0, op1);
10160 : 0 : goto binop2;
10161 : : }
10162 : : /* Use wi::shwi to ensure that the constant is
10163 : : truncated according to the mode of OP1, then sign extended
10164 : : to a HOST_WIDE_INT. Using the constant directly can result
10165 : : in non-canonical RTL in a 64x32 cross compile. */
10166 : 279123 : wc = TREE_INT_CST_LOW (treeop1);
10167 : 279123 : constant_part
10168 : 279123 : = immed_wide_int_const (wi::shwi (wc, wmode), wmode);
10169 : 279123 : op0 = plus_constant (mode, op0, INTVAL (constant_part));
10170 : 279123 : if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
10171 : 207667 : op0 = force_operand (op0, target);
10172 : 279123 : return REDUCE_BIT_FIELD (op0);
10173 : : }
10174 : : }
10175 : :
10176 : : /* Use TER to expand pointer addition of a negated value
10177 : : as pointer subtraction. */
10178 : 8801386 : if ((POINTER_TYPE_P (TREE_TYPE (treeop0))
10179 : 3837226 : || (TREE_CODE (TREE_TYPE (treeop0)) == VECTOR_TYPE
10180 : 77886 : && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0)))))
10181 : 1108578 : && TREE_CODE (treeop1) == SSA_NAME
10182 : 6081188 : && TYPE_MODE (TREE_TYPE (treeop0))
10183 : 567692 : == TYPE_MODE (TREE_TYPE (treeop1)))
10184 : : {
10185 : 567692 : gimple *def = get_def_for_expr (treeop1, NEGATE_EXPR);
10186 : 567692 : if (def)
10187 : : {
10188 : 2971 : treeop1 = gimple_assign_rhs1 (def);
10189 : 2971 : code = MINUS_EXPR;
10190 : 2971 : goto do_minus;
10191 : : }
10192 : : }
10193 : :
10194 : : /* No sense saving up arithmetic to be done
10195 : : if it's all in the wrong mode to form part of an address.
10196 : : And force_operand won't know whether to sign-extend or
10197 : : zero-extend. */
10198 : 4942833 : if (modifier != EXPAND_INITIALIZER
10199 : 4942833 : && (modifier != EXPAND_SUM || mode != ptr_mode))
10200 : : {
10201 : 4379325 : expand_operands (treeop0, treeop1,
10202 : : subtarget, &op0, &op1, modifier);
10203 : 4379325 : if (op0 == const0_rtx)
10204 : 8686 : return op1;
10205 : 4370639 : if (op1 == const0_rtx)
10206 : : return op0;
10207 : 4370387 : goto binop2;
10208 : : }
10209 : :
10210 : 563508 : expand_operands (treeop0, treeop1,
10211 : : subtarget, &op0, &op1, modifier);
10212 : 563508 : return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
10213 : :
10214 : 531381 : case MINUS_EXPR:
10215 : 531381 : case POINTER_DIFF_EXPR:
10216 : 531381 : do_minus:
10217 : : /* For initializers, we are allowed to return a MINUS of two
10218 : : symbolic constants. Here we handle all cases when both operands
10219 : : are constant. */
10220 : : /* Handle difference of two symbolic constants,
10221 : : for the sake of an initializer. */
10222 : 531381 : if ((modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
10223 : 3187 : && really_constant_p (treeop0)
10224 : 531861 : && really_constant_p (treeop1))
10225 : : {
10226 : 68 : expand_operands (treeop0, treeop1,
10227 : : NULL_RTX, &op0, &op1, modifier);
10228 : 68 : return simplify_gen_binary (MINUS, mode, op0, op1);
10229 : : }
10230 : :
10231 : : /* No sense saving up arithmetic to be done
10232 : : if it's all in the wrong mode to form part of an address.
10233 : : And force_operand won't know whether to sign-extend or
10234 : : zero-extend. */
10235 : 531313 : if (modifier != EXPAND_INITIALIZER
10236 : 531313 : && (modifier != EXPAND_SUM || mode != ptr_mode))
10237 : 528194 : goto binop;
10238 : :
10239 : 3119 : expand_operands (treeop0, treeop1,
10240 : : subtarget, &op0, &op1, modifier);
10241 : :
10242 : : /* Convert A - const to A + (-const). */
10243 : 3119 : if (CONST_INT_P (op1))
10244 : : {
10245 : 0 : op1 = negate_rtx (mode, op1);
10246 : 0 : return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
10247 : : }
10248 : :
10249 : 3119 : goto binop2;
10250 : :
10251 : 0 : case WIDEN_MULT_PLUS_EXPR:
10252 : 0 : case WIDEN_MULT_MINUS_EXPR:
10253 : 0 : expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
10254 : 0 : op2 = expand_normal (treeop2);
10255 : 0 : target = expand_widen_pattern_expr (ops, op0, op1, op2,
10256 : : target, unsignedp);
10257 : 0 : return target;
10258 : :
10259 : 18194 : case WIDEN_MULT_EXPR:
10260 : : /* If first operand is constant, swap them.
10261 : : Thus the following special case checks need only
10262 : : check the second operand. */
10263 : 18194 : if (TREE_CODE (treeop0) == INTEGER_CST)
10264 : 368 : std::swap (treeop0, treeop1);
10265 : :
10266 : : /* First, check if we have a multiplication of one signed and one
10267 : : unsigned operand. */
10268 : 18194 : if (TREE_CODE (treeop1) != INTEGER_CST
10269 : 18194 : && (TYPE_UNSIGNED (TREE_TYPE (treeop0))
10270 : 13743 : != TYPE_UNSIGNED (TREE_TYPE (treeop1))))
10271 : : {
10272 : 0 : machine_mode innermode = TYPE_MODE (TREE_TYPE (treeop0));
10273 : 0 : this_optab = usmul_widen_optab;
10274 : 0 : if (find_widening_optab_handler (this_optab, mode, innermode)
10275 : : != CODE_FOR_nothing)
10276 : : {
10277 : 0 : if (TYPE_UNSIGNED (TREE_TYPE (treeop0)))
10278 : 0 : expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
10279 : : EXPAND_NORMAL);
10280 : : else
10281 : 0 : expand_operands (treeop0, treeop1, NULL_RTX, &op1, &op0,
10282 : : EXPAND_NORMAL);
10283 : : /* op0 and op1 might still be constant, despite the above
10284 : : != INTEGER_CST check. Handle it. */
10285 : 0 : if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
10286 : : {
10287 : 0 : op0 = convert_modes (mode, innermode, op0, true);
10288 : 0 : op1 = convert_modes (mode, innermode, op1, false);
10289 : 0 : return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1,
10290 : : target, unsignedp));
10291 : : }
10292 : 0 : goto binop3;
10293 : : }
10294 : : }
10295 : : /* Check for a multiplication with matching signedness. */
10296 : 18194 : else if ((TREE_CODE (treeop1) == INTEGER_CST
10297 : 4451 : && int_fits_type_p (treeop1, TREE_TYPE (treeop0)))
10298 : 18194 : || (TYPE_UNSIGNED (TREE_TYPE (treeop1))
10299 : 13743 : == TYPE_UNSIGNED (TREE_TYPE (treeop0))))
10300 : : {
10301 : 18194 : tree op0type = TREE_TYPE (treeop0);
10302 : 18194 : machine_mode innermode = TYPE_MODE (op0type);
10303 : 18194 : bool zextend_p = TYPE_UNSIGNED (op0type);
10304 : 18194 : optab other_optab = zextend_p ? smul_widen_optab : umul_widen_optab;
10305 : 2529 : this_optab = zextend_p ? umul_widen_optab : smul_widen_optab;
10306 : :
10307 : 18194 : if (TREE_CODE (treeop0) != INTEGER_CST)
10308 : : {
10309 : 18194 : if (find_widening_optab_handler (this_optab, mode, innermode)
10310 : : != CODE_FOR_nothing)
10311 : : {
10312 : 18194 : expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
10313 : : EXPAND_NORMAL);
10314 : : /* op0 and op1 might still be constant, despite the above
10315 : : != INTEGER_CST check. Handle it. */
10316 : 18194 : if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
10317 : : {
10318 : 0 : widen_mult_const:
10319 : 0 : op0 = convert_modes (mode, innermode, op0, zextend_p);
10320 : 0 : op1
10321 : 0 : = convert_modes (mode, innermode, op1,
10322 : 0 : TYPE_UNSIGNED (TREE_TYPE (treeop1)));
10323 : 0 : return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1,
10324 : : target,
10325 : : unsignedp));
10326 : : }
10327 : 18194 : temp = expand_widening_mult (mode, op0, op1, target,
10328 : : unsignedp, this_optab);
10329 : 18194 : return REDUCE_BIT_FIELD (temp);
10330 : : }
10331 : 0 : if (find_widening_optab_handler (other_optab, mode, innermode)
10332 : : != CODE_FOR_nothing
10333 : 0 : && innermode == word_mode)
10334 : : {
10335 : 0 : rtx htem, hipart;
10336 : 0 : op0 = expand_normal (treeop0);
10337 : 0 : op1 = expand_normal (treeop1);
10338 : : /* op0 and op1 might be constants, despite the above
10339 : : != INTEGER_CST check. Handle it. */
10340 : 0 : if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
10341 : 0 : goto widen_mult_const;
10342 : 0 : temp = expand_binop (mode, other_optab, op0, op1, target,
10343 : : unsignedp, OPTAB_LIB_WIDEN);
10344 : 0 : hipart = gen_highpart (word_mode, temp);
10345 : 0 : htem = expand_mult_highpart_adjust (word_mode, hipart,
10346 : : op0, op1, hipart,
10347 : : zextend_p);
10348 : 0 : if (htem != hipart)
10349 : 0 : emit_move_insn (hipart, htem);
10350 : 0 : return REDUCE_BIT_FIELD (temp);
10351 : : }
10352 : : }
10353 : : }
10354 : 0 : treeop0 = fold_build1 (CONVERT_EXPR, type, treeop0);
10355 : 0 : treeop1 = fold_build1 (CONVERT_EXPR, type, treeop1);
10356 : 0 : expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
10357 : 0 : return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
10358 : :
10359 : 1361383 : case MULT_EXPR:
10360 : : /* If this is a fixed-point operation, then we cannot use the code
10361 : : below because "expand_mult" doesn't support sat/no-sat fixed-point
10362 : : multiplications. */
10363 : 1361383 : if (ALL_FIXED_POINT_MODE_P (mode))
10364 : 0 : goto binop;
10365 : :
10366 : : /* If first operand is constant, swap them.
10367 : : Thus the following special case checks need only
10368 : : check the second operand. */
10369 : 1361383 : if (TREE_CODE (treeop0) == INTEGER_CST)
10370 : 686 : std::swap (treeop0, treeop1);
10371 : :
10372 : : /* Attempt to return something suitable for generating an
10373 : : indexed address, for machines that support that. */
10374 : :
10375 : 525954 : if (modifier == EXPAND_SUM && mode == ptr_mode
10376 : 1887337 : && tree_fits_shwi_p (treeop1))
10377 : : {
10378 : 519585 : tree exp1 = treeop1;
10379 : :
10380 : 519585 : op0 = expand_expr (treeop0, subtarget, VOIDmode,
10381 : : EXPAND_SUM);
10382 : :
10383 : 519585 : if (!REG_P (op0))
10384 : 245277 : op0 = force_operand (op0, NULL_RTX);
10385 : 519585 : if (!REG_P (op0))
10386 : 2362 : op0 = copy_to_mode_reg (mode, op0);
10387 : :
10388 : 519585 : op1 = gen_int_mode (tree_to_shwi (exp1),
10389 : 519585 : TYPE_MODE (TREE_TYPE (exp1)));
10390 : 519585 : return REDUCE_BIT_FIELD (gen_rtx_MULT (mode, op0, op1));
10391 : : }
10392 : :
10393 : 841798 : if (modifier == EXPAND_STACK_PARM)
10394 : 2905 : target = 0;
10395 : :
10396 : 841798 : if (SCALAR_INT_MODE_P (mode) && optimize >= 2)
10397 : : {
10398 : 498347 : gimple *def_stmt0 = get_def_for_expr (treeop0, TRUNC_DIV_EXPR);
10399 : 498347 : gimple *def_stmt1 = get_def_for_expr (treeop1, TRUNC_DIV_EXPR);
10400 : 498347 : if (def_stmt0
10401 : 498347 : && !operand_equal_p (treeop1, gimple_assign_rhs2 (def_stmt0), 0))
10402 : : def_stmt0 = NULL;
10403 : 498347 : if (def_stmt1
10404 : 498347 : && !operand_equal_p (treeop0, gimple_assign_rhs2 (def_stmt1), 0))
10405 : : def_stmt1 = NULL;
10406 : :
10407 : 498347 : if (def_stmt0 || def_stmt1)
10408 : : {
10409 : : /* X / Y * Y can be expanded as X - X % Y too.
10410 : : Choose the cheaper sequence of those two. */
10411 : 235 : if (def_stmt0)
10412 : 235 : treeop0 = gimple_assign_rhs1 (def_stmt0);
10413 : : else
10414 : : {
10415 : 0 : treeop1 = treeop0;
10416 : 0 : treeop0 = gimple_assign_rhs1 (def_stmt1);
10417 : : }
10418 : 235 : expand_operands (treeop0, treeop1, subtarget, &op0, &op1,
10419 : : EXPAND_NORMAL);
10420 : 235 : bool speed_p = optimize_insn_for_speed_p ();
10421 : 235 : do_pending_stack_adjust ();
10422 : 235 : start_sequence ();
10423 : 235 : rtx divmul_ret
10424 : 235 : = expand_expr_divmod (TRUNC_DIV_EXPR, mode, treeop0, treeop1,
10425 : : op0, op1, NULL_RTX, unsignedp);
10426 : 235 : divmul_ret = expand_mult (mode, divmul_ret, op1, target,
10427 : : unsignedp);
10428 : 235 : rtx_insn *divmul_insns = end_sequence ();
10429 : 235 : start_sequence ();
10430 : 235 : rtx modsub_ret
10431 : 235 : = expand_expr_divmod (TRUNC_MOD_EXPR, mode, treeop0, treeop1,
10432 : : op0, op1, NULL_RTX, unsignedp);
10433 : 235 : this_optab = optab_for_tree_code (MINUS_EXPR, type,
10434 : : optab_default);
10435 : 235 : modsub_ret = expand_binop (mode, this_optab, op0, modsub_ret,
10436 : : target, unsignedp, OPTAB_LIB_WIDEN);
10437 : 235 : rtx_insn *modsub_insns = end_sequence ();
10438 : 235 : unsigned divmul_cost = seq_cost (divmul_insns, speed_p);
10439 : 235 : unsigned modsub_cost = seq_cost (modsub_insns, speed_p);
10440 : : /* If costs are the same then use as tie breaker the other other
10441 : : factor. */
10442 : 235 : if (divmul_cost == modsub_cost)
10443 : : {
10444 : 20 : divmul_cost = seq_cost (divmul_insns, !speed_p);
10445 : 20 : modsub_cost = seq_cost (modsub_insns, !speed_p);
10446 : : }
10447 : :
10448 : 235 : if (divmul_cost <= modsub_cost)
10449 : : {
10450 : 167 : emit_insn (divmul_insns);
10451 : 167 : return REDUCE_BIT_FIELD (divmul_ret);
10452 : : }
10453 : 68 : emit_insn (modsub_insns);
10454 : 68 : return REDUCE_BIT_FIELD (modsub_ret);
10455 : : }
10456 : : }
10457 : :
10458 : 841563 : expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
10459 : :
10460 : : /* Expand X*Y as X&-Y when Y must be zero or one. */
10461 : 841563 : if (SCALAR_INT_MODE_P (mode))
10462 : : {
10463 : 710656 : bool gimple_zero_one_valued_p (tree, tree (*)(tree));
10464 : 710656 : bool bit0_p = gimple_zero_one_valued_p (treeop0, nullptr);
10465 : 710656 : bool bit1_p = gimple_zero_one_valued_p (treeop1, nullptr);
10466 : :
10467 : : /* Expand X*Y as X&Y when both X and Y must be zero or one. */
10468 : 710656 : if (bit0_p && bit1_p)
10469 : 2 : return REDUCE_BIT_FIELD (expand_and (mode, op0, op1, target));
10470 : :
10471 : 710654 : if (bit0_p || bit1_p)
10472 : : {
10473 : 4327 : bool speed = optimize_insn_for_speed_p ();
10474 : 4327 : int cost = add_cost (speed, mode) + neg_cost (speed, mode);
10475 : 4327 : struct algorithm algorithm;
10476 : 4327 : enum mult_variant variant;
10477 : 4327 : if (CONST_INT_P (op1)
10478 : 4327 : ? !choose_mult_variant (mode, INTVAL (op1),
10479 : : &algorithm, &variant, cost)
10480 : 688 : : cost < mul_cost (speed, mode))
10481 : : {
10482 : 2062 : temp = bit0_p ? expand_and (mode, negate_rtx (mode, op0),
10483 : : op1, target)
10484 : 266 : : expand_and (mode, op0,
10485 : : negate_rtx (mode, op1),
10486 : : target);
10487 : 2062 : return REDUCE_BIT_FIELD (temp);
10488 : : }
10489 : : }
10490 : : }
10491 : :
10492 : 839499 : return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
10493 : :
10494 : 158943 : case TRUNC_MOD_EXPR:
10495 : 158943 : case FLOOR_MOD_EXPR:
10496 : 158943 : case CEIL_MOD_EXPR:
10497 : 158943 : case ROUND_MOD_EXPR:
10498 : :
10499 : 158943 : case TRUNC_DIV_EXPR:
10500 : 158943 : case FLOOR_DIV_EXPR:
10501 : 158943 : case CEIL_DIV_EXPR:
10502 : 158943 : case ROUND_DIV_EXPR:
10503 : 158943 : case EXACT_DIV_EXPR:
10504 : : /* If this is a fixed-point operation, then we cannot use the code
10505 : : below because "expand_divmod" doesn't support sat/no-sat fixed-point
10506 : : divisions. */
10507 : 158943 : if (ALL_FIXED_POINT_MODE_P (mode))
10508 : 0 : goto binop;
10509 : :
10510 : 158943 : if (modifier == EXPAND_STACK_PARM)
10511 : 314 : target = 0;
10512 : : /* Possible optimization: compute the dividend with EXPAND_SUM
10513 : : then if the divisor is constant can optimize the case
10514 : : where some terms of the dividend have coeffs divisible by it. */
10515 : 158943 : expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
10516 : 158943 : return expand_expr_divmod (code, mode, treeop0, treeop1, op0, op1,
10517 : 158943 : target, unsignedp);
10518 : :
10519 : 30928 : case RDIV_EXPR:
10520 : 30928 : goto binop;
10521 : :
10522 : 1620 : case MULT_HIGHPART_EXPR:
10523 : 1620 : expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
10524 : 1620 : temp = expand_mult_highpart (mode, op0, op1, target, unsignedp);
10525 : 1620 : gcc_assert (temp);
10526 : : return temp;
10527 : :
10528 : 0 : case FIXED_CONVERT_EXPR:
10529 : 0 : op0 = expand_normal (treeop0);
10530 : 0 : if (target == 0 || modifier == EXPAND_STACK_PARM)
10531 : 0 : target = gen_reg_rtx (mode);
10532 : :
10533 : 0 : if ((TREE_CODE (TREE_TYPE (treeop0)) == INTEGER_TYPE
10534 : 0 : && TYPE_UNSIGNED (TREE_TYPE (treeop0)))
10535 : 0 : || (TREE_CODE (type) == INTEGER_TYPE && TYPE_UNSIGNED (type)))
10536 : 0 : expand_fixed_convert (target, op0, 1, TYPE_SATURATING (type));
10537 : : else
10538 : 0 : expand_fixed_convert (target, op0, 0, TYPE_SATURATING (type));
10539 : : return target;
10540 : :
10541 : 47625 : case FIX_TRUNC_EXPR:
10542 : 47625 : op0 = expand_normal (treeop0);
10543 : 47625 : if (target == 0 || modifier == EXPAND_STACK_PARM)
10544 : 3036 : target = gen_reg_rtx (mode);
10545 : 47625 : expand_fix (target, op0, unsignedp);
10546 : 47625 : return target;
10547 : :
10548 : 133034 : case FLOAT_EXPR:
10549 : 133034 : op0 = expand_normal (treeop0);
10550 : 133034 : if (target == 0 || modifier == EXPAND_STACK_PARM)
10551 : 62565 : target = gen_reg_rtx (mode);
10552 : : /* expand_float can't figure out what to do if FROM has VOIDmode.
10553 : : So give it the correct mode. With -O, cse will optimize this. */
10554 : 133034 : if (GET_MODE (op0) == VOIDmode)
10555 : 108 : op0 = copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0)),
10556 : : op0);
10557 : 266068 : expand_float (target, op0,
10558 : 133034 : TYPE_UNSIGNED (TREE_TYPE (treeop0)));
10559 : 133034 : return target;
10560 : :
10561 : 50283 : case NEGATE_EXPR:
10562 : 50283 : op0 = expand_expr (treeop0, subtarget,
10563 : : VOIDmode, EXPAND_NORMAL);
10564 : 50283 : if (modifier == EXPAND_STACK_PARM)
10565 : 243 : target = 0;
10566 : 50283 : temp = expand_unop (mode,
10567 : : optab_for_tree_code (NEGATE_EXPR, type,
10568 : : optab_default),
10569 : : op0, target, 0);
10570 : 50283 : gcc_assert (temp);
10571 : 50283 : return REDUCE_BIT_FIELD (temp);
10572 : :
10573 : 24559 : case ABS_EXPR:
10574 : 24559 : case ABSU_EXPR:
10575 : 24559 : op0 = expand_expr (treeop0, subtarget,
10576 : : VOIDmode, EXPAND_NORMAL);
10577 : 24559 : if (modifier == EXPAND_STACK_PARM)
10578 : 48 : target = 0;
10579 : :
10580 : : /* ABS_EXPR is not valid for complex arguments. */
10581 : 24559 : gcc_assert (GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
10582 : : && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT);
10583 : :
10584 : : /* Unsigned abs is simply the operand. Testing here means we don't
10585 : : risk generating incorrect code below. */
10586 : 24559 : if (TYPE_UNSIGNED (TREE_TYPE (treeop0)))
10587 : : return op0;
10588 : :
10589 : 24559 : return expand_abs (mode, op0, target, unsignedp,
10590 : 49118 : safe_from_p (target, treeop0, 1));
10591 : :
10592 : 101939 : case MAX_EXPR:
10593 : 101939 : case MIN_EXPR:
10594 : 101939 : target = original_target;
10595 : 101939 : if (target == 0
10596 : 101939 : || modifier == EXPAND_STACK_PARM
10597 : 56982 : || (MEM_P (target) && MEM_VOLATILE_P (target))
10598 : 56982 : || GET_MODE (target) != mode
10599 : 158921 : || (REG_P (target)
10600 : 50340 : && REGNO (target) < FIRST_PSEUDO_REGISTER))
10601 : 44957 : target = gen_reg_rtx (mode);
10602 : 101939 : expand_operands (treeop0, treeop1,
10603 : : target, &op0, &op1, EXPAND_NORMAL);
10604 : :
10605 : : /* First try to do it with a special MIN or MAX instruction.
10606 : : If that does not win, use a conditional jump to select the proper
10607 : : value. */
10608 : 101939 : this_optab = optab_for_tree_code (code, type, optab_default);
10609 : 101939 : temp = expand_binop (mode, this_optab, op0, op1, target, unsignedp,
10610 : : OPTAB_WIDEN);
10611 : 101939 : if (temp != 0)
10612 : : return temp;
10613 : :
10614 : 122 : if (VECTOR_TYPE_P (type))
10615 : 0 : gcc_unreachable ();
10616 : :
10617 : : /* At this point, a MEM target is no longer useful; we will get better
10618 : : code without it. */
10619 : :
10620 : 122 : if (! REG_P (target))
10621 : 1 : target = gen_reg_rtx (mode);
10622 : :
10623 : : /* If op1 was placed in target, swap op0 and op1. */
10624 : 122 : if (target != op0 && target == op1)
10625 : 0 : std::swap (op0, op1);
10626 : :
10627 : : /* We generate better code and avoid problems with op1 mentioning
10628 : : target by forcing op1 into a pseudo if it isn't a constant. */
10629 : 122 : if (! CONSTANT_P (op1))
10630 : 42 : op1 = force_reg (mode, op1);
10631 : :
10632 : 122 : {
10633 : 122 : enum rtx_code comparison_code;
10634 : 122 : rtx cmpop1 = op1;
10635 : :
10636 : 122 : if (code == MAX_EXPR)
10637 : 62 : comparison_code = unsignedp ? GEU : GE;
10638 : : else
10639 : 60 : comparison_code = unsignedp ? LEU : LE;
10640 : :
10641 : : /* Canonicalize to comparisons against 0. */
10642 : 122 : if (op1 == const1_rtx)
10643 : : {
10644 : : /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
10645 : : or (a != 0 ? a : 1) for unsigned.
10646 : : For MIN we are safe converting (a <= 1 ? a : 1)
10647 : : into (a <= 0 ? a : 1) */
10648 : 0 : cmpop1 = const0_rtx;
10649 : 0 : if (code == MAX_EXPR)
10650 : 0 : comparison_code = unsignedp ? NE : GT;
10651 : : }
10652 : 122 : if (op1 == constm1_rtx && !unsignedp)
10653 : : {
10654 : : /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
10655 : : and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
10656 : 0 : cmpop1 = const0_rtx;
10657 : 0 : if (code == MIN_EXPR)
10658 : 0 : comparison_code = LT;
10659 : : }
10660 : :
10661 : : /* Use a conditional move if possible. */
10662 : 122 : if (can_conditionally_move_p (mode))
10663 : : {
10664 : 75 : rtx insn;
10665 : :
10666 : 75 : start_sequence ();
10667 : :
10668 : : /* Try to emit the conditional move. */
10669 : 75 : insn = emit_conditional_move (target,
10670 : : { comparison_code,
10671 : : op0, cmpop1, mode },
10672 : : op0, op1, mode,
10673 : : unsignedp);
10674 : :
10675 : : /* If we could do the conditional move, emit the sequence,
10676 : : and return. */
10677 : 75 : if (insn)
10678 : : {
10679 : 41 : rtx_insn *seq = end_sequence ();
10680 : 41 : emit_insn (seq);
10681 : 41 : return target;
10682 : : }
10683 : :
10684 : : /* Otherwise discard the sequence and fall back to code with
10685 : : branches. */
10686 : 34 : end_sequence ();
10687 : : }
10688 : :
10689 : 81 : if (target != op0)
10690 : 52 : emit_move_insn (target, op0);
10691 : :
10692 : 81 : lab = gen_label_rtx ();
10693 : 81 : do_compare_rtx_and_jump (target, cmpop1, comparison_code,
10694 : : unsignedp, mode, NULL_RTX, NULL, lab,
10695 : : profile_probability::uninitialized ());
10696 : : }
10697 : 81 : emit_move_insn (target, op1);
10698 : 81 : emit_label (lab);
10699 : 81 : return target;
10700 : :
10701 : 59290 : case BIT_NOT_EXPR:
10702 : 59290 : op0 = expand_expr (treeop0, subtarget,
10703 : : VOIDmode, EXPAND_NORMAL);
10704 : 59290 : if (modifier == EXPAND_STACK_PARM)
10705 : 87 : target = 0;
10706 : : /* In case we have to reduce the result to bitfield precision
10707 : : for unsigned bitfield expand this as XOR with a proper constant
10708 : : instead. */
10709 : 59290 : if (reduce_bit_field && TYPE_UNSIGNED (type))
10710 : : {
10711 : 22585 : int_mode = SCALAR_INT_TYPE_MODE (type);
10712 : 22585 : wide_int mask = wi::mask (TYPE_PRECISION (type),
10713 : 45170 : false, GET_MODE_PRECISION (int_mode));
10714 : :
10715 : 45170 : temp = expand_binop (int_mode, xor_optab, op0,
10716 : 45170 : immed_wide_int_const (mask, int_mode),
10717 : : target, 1, OPTAB_LIB_WIDEN);
10718 : 22585 : }
10719 : : else
10720 : 36705 : temp = expand_unop (mode, one_cmpl_optab, op0, target, 1);
10721 : 59290 : gcc_assert (temp);
10722 : : return temp;
10723 : :
10724 : : /* ??? Can optimize bitwise operations with one arg constant.
10725 : : Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
10726 : : and (a bitwise1 b) bitwise2 b (etc)
10727 : : but that is probably not worth while. */
10728 : :
10729 : 616124 : case BIT_AND_EXPR:
10730 : 616124 : case BIT_IOR_EXPR:
10731 : 616124 : case BIT_XOR_EXPR:
10732 : 616124 : goto binop;
10733 : :
10734 : 7814 : case LROTATE_EXPR:
10735 : 7814 : case RROTATE_EXPR:
10736 : 7814 : gcc_assert (VECTOR_MODE_P (TYPE_MODE (type))
10737 : : || type_has_mode_precision_p (type));
10738 : : /* fall through */
10739 : :
10740 : 289101 : case LSHIFT_EXPR:
10741 : 289101 : case RSHIFT_EXPR:
10742 : 289101 : {
10743 : : /* If this is a fixed-point operation, then we cannot use the code
10744 : : below because "expand_shift" doesn't support sat/no-sat fixed-point
10745 : : shifts. */
10746 : 289101 : if (ALL_FIXED_POINT_MODE_P (mode))
10747 : 0 : goto binop;
10748 : :
10749 : 289101 : if (! safe_from_p (subtarget, treeop1, 1))
10750 : 4846 : subtarget = 0;
10751 : 289101 : if (modifier == EXPAND_STACK_PARM)
10752 : 2584 : target = 0;
10753 : 289101 : op0 = expand_expr (treeop0, subtarget,
10754 : : VOIDmode, EXPAND_NORMAL);
10755 : :
10756 : : /* Left shift optimization when shifting across word_size boundary.
10757 : :
10758 : : If mode == GET_MODE_WIDER_MODE (word_mode), then normally
10759 : : there isn't native instruction to support this wide mode
10760 : : left shift. Given below scenario:
10761 : :
10762 : : Type A = (Type) B << C
10763 : :
10764 : : |< T >|
10765 : : | dest_high | dest_low |
10766 : :
10767 : : | word_size |
10768 : :
10769 : : If the shift amount C caused we shift B to across the word
10770 : : size boundary, i.e part of B shifted into high half of
10771 : : destination register, and part of B remains in the low
10772 : : half, then GCC will use the following left shift expand
10773 : : logic:
10774 : :
10775 : : 1. Initialize dest_low to B.
10776 : : 2. Initialize every bit of dest_high to the sign bit of B.
10777 : : 3. Logic left shift dest_low by C bit to finalize dest_low.
10778 : : The value of dest_low before this shift is kept in a temp D.
10779 : : 4. Logic left shift dest_high by C.
10780 : : 5. Logic right shift D by (word_size - C).
10781 : : 6. Or the result of 4 and 5 to finalize dest_high.
10782 : :
10783 : : While, by checking gimple statements, if operand B is
10784 : : coming from signed extension, then we can simplify above
10785 : : expand logic into:
10786 : :
10787 : : 1. dest_high = src_low >> (word_size - C).
10788 : : 2. dest_low = src_low << C.
10789 : :
10790 : : We can use one arithmetic right shift to finish all the
10791 : : purpose of steps 2, 4, 5, 6, thus we reduce the steps
10792 : : needed from 6 into 2.
10793 : :
10794 : : The case is similar for zero extension, except that we
10795 : : initialize dest_high to zero rather than copies of the sign
10796 : : bit from B. Furthermore, we need to use a logical right shift
10797 : : in this case.
10798 : :
10799 : : The choice of sign-extension versus zero-extension is
10800 : : determined entirely by whether or not B is signed and is
10801 : : independent of the current setting of unsignedp. */
10802 : :
10803 : 289101 : temp = NULL_RTX;
10804 : 289101 : if (code == LSHIFT_EXPR
10805 : 289101 : && target
10806 : 32637 : && REG_P (target)
10807 : 318943 : && GET_MODE_2XWIDER_MODE (word_mode).exists (&int_mode)
10808 : 29907 : && mode == int_mode
10809 : 1506 : && TREE_CONSTANT (treeop1)
10810 : 289937 : && TREE_CODE (treeop0) == SSA_NAME)
10811 : : {
10812 : 836 : gimple *def = SSA_NAME_DEF_STMT (treeop0);
10813 : 836 : if (is_gimple_assign (def)
10814 : 836 : && gimple_assign_rhs_code (def) == NOP_EXPR)
10815 : : {
10816 : 320 : scalar_int_mode rmode = SCALAR_INT_TYPE_MODE
10817 : : (TREE_TYPE (gimple_assign_rhs1 (def)));
10818 : :
10819 : 640 : if (GET_MODE_SIZE (rmode) < GET_MODE_SIZE (int_mode)
10820 : 594 : && TREE_INT_CST_LOW (treeop1) < GET_MODE_BITSIZE (word_mode)
10821 : 458 : && ((TREE_INT_CST_LOW (treeop1) + GET_MODE_BITSIZE (rmode))
10822 : 69 : >= GET_MODE_BITSIZE (word_mode)))
10823 : : {
10824 : 65 : rtx_insn *seq, *seq_old;
10825 : 65 : poly_uint64 high_off = subreg_highpart_offset (word_mode,
10826 : : int_mode);
10827 : 65 : bool extend_unsigned
10828 : 65 : = TYPE_UNSIGNED (TREE_TYPE (gimple_assign_rhs1 (def)));
10829 : 65 : rtx low = lowpart_subreg (word_mode, op0, int_mode);
10830 : 65 : rtx dest_low = lowpart_subreg (word_mode, target, int_mode);
10831 : 65 : rtx dest_high = simplify_gen_subreg (word_mode, target,
10832 : : int_mode, high_off);
10833 : 65 : HOST_WIDE_INT ramount = (BITS_PER_WORD
10834 : 65 : - TREE_INT_CST_LOW (treeop1));
10835 : 65 : tree rshift = build_int_cst (TREE_TYPE (treeop1), ramount);
10836 : :
10837 : 65 : start_sequence ();
10838 : : /* dest_high = src_low >> (word_size - C). */
10839 : 65 : temp = expand_variable_shift (RSHIFT_EXPR, word_mode, low,
10840 : : rshift, dest_high,
10841 : : extend_unsigned);
10842 : 65 : if (temp != dest_high)
10843 : 0 : emit_move_insn (dest_high, temp);
10844 : :
10845 : : /* dest_low = src_low << C. */
10846 : 65 : temp = expand_variable_shift (LSHIFT_EXPR, word_mode, low,
10847 : : treeop1, dest_low, unsignedp);
10848 : 65 : if (temp != dest_low)
10849 : 0 : emit_move_insn (dest_low, temp);
10850 : :
10851 : 65 : seq = end_sequence ();
10852 : 65 : temp = target ;
10853 : :
10854 : 65 : if (have_insn_for (ASHIFT, int_mode))
10855 : : {
10856 : 65 : bool speed_p = optimize_insn_for_speed_p ();
10857 : 65 : start_sequence ();
10858 : 65 : rtx ret_old = expand_variable_shift (code, int_mode,
10859 : : op0, treeop1,
10860 : : target,
10861 : : unsignedp);
10862 : :
10863 : 65 : seq_old = end_sequence ();
10864 : 130 : if (seq_cost (seq, speed_p)
10865 : 65 : >= seq_cost (seq_old, speed_p))
10866 : : {
10867 : 65 : seq = seq_old;
10868 : 65 : temp = ret_old;
10869 : : }
10870 : : }
10871 : 65 : emit_insn (seq);
10872 : : }
10873 : : }
10874 : : }
10875 : :
10876 : 65 : if (temp == NULL_RTX)
10877 : 289036 : temp = expand_variable_shift (code, mode, op0, treeop1, target,
10878 : : unsignedp);
10879 : 289101 : if (code == LSHIFT_EXPR)
10880 : 83205 : temp = REDUCE_BIT_FIELD (temp);
10881 : : return temp;
10882 : : }
10883 : :
10884 : : /* Could determine the answer when only additive constants differ. Also,
10885 : : the addition of one can be handled by changing the condition. */
10886 : 542666 : case LT_EXPR:
10887 : 542666 : case LE_EXPR:
10888 : 542666 : case GT_EXPR:
10889 : 542666 : case GE_EXPR:
10890 : 542666 : case EQ_EXPR:
10891 : 542666 : case NE_EXPR:
10892 : 542666 : case UNORDERED_EXPR:
10893 : 542666 : case ORDERED_EXPR:
10894 : 542666 : case UNLT_EXPR:
10895 : 542666 : case UNLE_EXPR:
10896 : 542666 : case UNGT_EXPR:
10897 : 542666 : case UNGE_EXPR:
10898 : 542666 : case UNEQ_EXPR:
10899 : 542666 : case LTGT_EXPR:
10900 : 542666 : {
10901 : 863108 : temp = do_store_flag (ops,
10902 : : modifier != EXPAND_STACK_PARM ? target : NULL_RTX,
10903 : : tmode != VOIDmode ? tmode : mode);
10904 : 542666 : if (temp)
10905 : : return temp;
10906 : :
10907 : : /* Use a compare and a jump for BLKmode comparisons, or for function
10908 : : type comparisons is have_canonicalize_funcptr_for_compare. */
10909 : :
10910 : 0 : if ((target == 0
10911 : 0 : || modifier == EXPAND_STACK_PARM
10912 : 0 : || ! safe_from_p (target, treeop0, 1)
10913 : 0 : || ! safe_from_p (target, treeop1, 1)
10914 : : /* Make sure we don't have a hard reg (such as function's return
10915 : : value) live across basic blocks, if not optimizing. */
10916 : 0 : || (!optimize && REG_P (target)
10917 : 0 : && REGNO (target) < FIRST_PSEUDO_REGISTER)))
10918 : 0 : target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
10919 : :
10920 : 0 : emit_move_insn (target, const0_rtx);
10921 : :
10922 : 0 : rtx_code_label *lab1 = gen_label_rtx ();
10923 : 0 : jumpifnot_1 (code, treeop0, treeop1, lab1,
10924 : : profile_probability::uninitialized ());
10925 : :
10926 : 0 : if (TYPE_PRECISION (type) == 1 && !TYPE_UNSIGNED (type))
10927 : 0 : emit_move_insn (target, constm1_rtx);
10928 : : else
10929 : 0 : emit_move_insn (target, const1_rtx);
10930 : :
10931 : 0 : emit_label (lab1);
10932 : 0 : return target;
10933 : : }
10934 : 54621 : case COMPLEX_EXPR:
10935 : : /* Get the rtx code of the operands. */
10936 : 54621 : op0 = expand_normal (treeop0);
10937 : 54621 : op1 = expand_normal (treeop1);
10938 : :
10939 : 54621 : if (!target)
10940 : 2693 : target = gen_reg_rtx (TYPE_MODE (type));
10941 : : else
10942 : : /* If target overlaps with op1, then either we need to force
10943 : : op1 into a pseudo (if target also overlaps with op0),
10944 : : or write the complex parts in reverse order. */
10945 : 51928 : switch (GET_CODE (target))
10946 : : {
10947 : 49198 : case CONCAT:
10948 : 49198 : if (reg_overlap_mentioned_p (XEXP (target, 0), op1))
10949 : : {
10950 : 0 : if (reg_overlap_mentioned_p (XEXP (target, 1), op0))
10951 : : {
10952 : 0 : complex_expr_force_op1:
10953 : 1718 : temp = gen_reg_rtx (GET_MODE_INNER (GET_MODE (target)));
10954 : 859 : emit_move_insn (temp, op1);
10955 : 859 : op1 = temp;
10956 : 859 : break;
10957 : : }
10958 : 0 : complex_expr_swap_order:
10959 : : /* Move the imaginary (op1) and real (op0) parts to their
10960 : : location. */
10961 : 1 : write_complex_part (target, op1, true, true);
10962 : 1 : write_complex_part (target, op0, false, false);
10963 : :
10964 : 1 : return target;
10965 : : }
10966 : : break;
10967 : 2730 : case MEM:
10968 : 5460 : temp = adjust_address_nv (target,
10969 : : GET_MODE_INNER (GET_MODE (target)), 0);
10970 : 2730 : if (reg_overlap_mentioned_p (temp, op1))
10971 : : {
10972 : 860 : scalar_mode imode = GET_MODE_INNER (GET_MODE (target));
10973 : 1720 : temp = adjust_address_nv (target, imode,
10974 : : GET_MODE_SIZE (imode));
10975 : 860 : if (reg_overlap_mentioned_p (temp, op0))
10976 : 859 : goto complex_expr_force_op1;
10977 : 1 : goto complex_expr_swap_order;
10978 : : }
10979 : : break;
10980 : 0 : default:
10981 : 0 : if (reg_overlap_mentioned_p (target, op1))
10982 : : {
10983 : 0 : if (reg_overlap_mentioned_p (target, op0))
10984 : 0 : goto complex_expr_force_op1;
10985 : 0 : goto complex_expr_swap_order;
10986 : : }
10987 : : break;
10988 : : }
10989 : :
10990 : : /* Move the real (op0) and imaginary (op1) parts to their location. */
10991 : 54620 : write_complex_part (target, op0, false, true);
10992 : 54620 : write_complex_part (target, op1, true, false);
10993 : :
10994 : 54620 : return target;
10995 : :
10996 : 0 : case WIDEN_SUM_EXPR:
10997 : 0 : {
10998 : 0 : tree oprnd0 = treeop0;
10999 : 0 : tree oprnd1 = treeop1;
11000 : :
11001 : 0 : expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
11002 : 0 : target = expand_widen_pattern_expr (ops, op0, NULL_RTX, op1,
11003 : : target, unsignedp);
11004 : 0 : return target;
11005 : : }
11006 : :
11007 : 15697 : case VEC_UNPACK_HI_EXPR:
11008 : 15697 : case VEC_UNPACK_LO_EXPR:
11009 : 15697 : case VEC_UNPACK_FIX_TRUNC_HI_EXPR:
11010 : 15697 : case VEC_UNPACK_FIX_TRUNC_LO_EXPR:
11011 : 15697 : {
11012 : 15697 : op0 = expand_normal (treeop0);
11013 : 15697 : temp = expand_widen_pattern_expr (ops, op0, NULL_RTX, NULL_RTX,
11014 : : target, unsignedp);
11015 : 15697 : gcc_assert (temp);
11016 : : return temp;
11017 : : }
11018 : :
11019 : 1784 : case VEC_UNPACK_FLOAT_HI_EXPR:
11020 : 1784 : case VEC_UNPACK_FLOAT_LO_EXPR:
11021 : 1784 : {
11022 : 1784 : op0 = expand_normal (treeop0);
11023 : : /* The signedness is determined from input operand. */
11024 : 1784 : temp = expand_widen_pattern_expr
11025 : 3568 : (ops, op0, NULL_RTX, NULL_RTX,
11026 : 1784 : target, TYPE_UNSIGNED (TREE_TYPE (treeop0)));
11027 : :
11028 : 1784 : gcc_assert (temp);
11029 : : return temp;
11030 : : }
11031 : :
11032 : 927 : case VEC_WIDEN_MULT_HI_EXPR:
11033 : 927 : case VEC_WIDEN_MULT_LO_EXPR:
11034 : 927 : case VEC_WIDEN_MULT_EVEN_EXPR:
11035 : 927 : case VEC_WIDEN_MULT_ODD_EXPR:
11036 : 927 : case VEC_WIDEN_LSHIFT_HI_EXPR:
11037 : 927 : case VEC_WIDEN_LSHIFT_LO_EXPR:
11038 : 927 : expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
11039 : 927 : target = expand_widen_pattern_expr (ops, op0, op1, NULL_RTX,
11040 : : target, unsignedp);
11041 : 927 : gcc_assert (target);
11042 : : return target;
11043 : :
11044 : 341 : case VEC_PACK_SAT_EXPR:
11045 : 341 : case VEC_PACK_FIX_TRUNC_EXPR:
11046 : 341 : mode = TYPE_MODE (TREE_TYPE (treeop0));
11047 : 341 : subtarget = NULL_RTX;
11048 : 341 : goto binop;
11049 : :
11050 : 9693 : case VEC_PACK_TRUNC_EXPR:
11051 : 9693 : if (VECTOR_BOOLEAN_TYPE_P (type)
11052 : 1092 : && VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (treeop0))
11053 : 1092 : && mode == TYPE_MODE (TREE_TYPE (treeop0))
11054 : 9893 : && SCALAR_INT_MODE_P (mode))
11055 : : {
11056 : 200 : class expand_operand eops[4];
11057 : 200 : machine_mode imode = TYPE_MODE (TREE_TYPE (treeop0));
11058 : 200 : expand_operands (treeop0, treeop1,
11059 : : subtarget, &op0, &op1, EXPAND_NORMAL);
11060 : 200 : this_optab = vec_pack_sbool_trunc_optab;
11061 : 200 : enum insn_code icode = optab_handler (this_optab, imode);
11062 : 200 : create_output_operand (&eops[0], target, mode);
11063 : 200 : create_convert_operand_from (&eops[1], op0, imode, false);
11064 : 200 : create_convert_operand_from (&eops[2], op1, imode, false);
11065 : 200 : temp = GEN_INT (TYPE_VECTOR_SUBPARTS (type).to_constant ());
11066 : 200 : create_input_operand (&eops[3], temp, imode);
11067 : 200 : expand_insn (icode, 4, eops);
11068 : 200 : return eops[0].value;
11069 : : }
11070 : 9493 : mode = TYPE_MODE (TREE_TYPE (treeop0));
11071 : 9493 : subtarget = NULL_RTX;
11072 : 9493 : goto binop;
11073 : :
11074 : 27 : case VEC_PACK_FLOAT_EXPR:
11075 : 27 : mode = TYPE_MODE (TREE_TYPE (treeop0));
11076 : 27 : expand_operands (treeop0, treeop1,
11077 : : subtarget, &op0, &op1, EXPAND_NORMAL);
11078 : 27 : this_optab = optab_for_tree_code (code, TREE_TYPE (treeop0),
11079 : : optab_default);
11080 : 81 : target = expand_binop (mode, this_optab, op0, op1, target,
11081 : 27 : TYPE_UNSIGNED (TREE_TYPE (treeop0)),
11082 : : OPTAB_LIB_WIDEN);
11083 : 27 : gcc_assert (target);
11084 : : return target;
11085 : :
11086 : 74547 : case VEC_PERM_EXPR:
11087 : 74547 : {
11088 : 74547 : expand_operands (treeop0, treeop1, target, &op0, &op1, EXPAND_NORMAL);
11089 : 74547 : vec_perm_builder sel;
11090 : 74547 : if (TREE_CODE (treeop2) == VECTOR_CST
11091 : 74547 : && tree_to_vec_perm_builder (&sel, treeop2))
11092 : : {
11093 : 74537 : machine_mode sel_mode = TYPE_MODE (TREE_TYPE (treeop2));
11094 : 74537 : temp = expand_vec_perm_const (mode, op0, op1, sel,
11095 : : sel_mode, target);
11096 : : }
11097 : : else
11098 : : {
11099 : 10 : op2 = expand_normal (treeop2);
11100 : 10 : temp = expand_vec_perm_var (mode, op0, op1, op2, target);
11101 : : }
11102 : 74547 : gcc_assert (temp);
11103 : 74547 : return temp;
11104 : 74547 : }
11105 : :
11106 : 369 : case DOT_PROD_EXPR:
11107 : 369 : {
11108 : 369 : tree oprnd0 = treeop0;
11109 : 369 : tree oprnd1 = treeop1;
11110 : 369 : tree oprnd2 = treeop2;
11111 : :
11112 : 369 : expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
11113 : 369 : op2 = expand_normal (oprnd2);
11114 : 369 : target = expand_widen_pattern_expr (ops, op0, op1, op2,
11115 : : target, unsignedp);
11116 : 369 : return target;
11117 : : }
11118 : :
11119 : 114 : case SAD_EXPR:
11120 : 114 : {
11121 : 114 : tree oprnd0 = treeop0;
11122 : 114 : tree oprnd1 = treeop1;
11123 : 114 : tree oprnd2 = treeop2;
11124 : :
11125 : 114 : expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
11126 : 114 : op2 = expand_normal (oprnd2);
11127 : 114 : target = expand_widen_pattern_expr (ops, op0, op1, op2,
11128 : : target, unsignedp);
11129 : 114 : return target;
11130 : : }
11131 : :
11132 : 0 : case REALIGN_LOAD_EXPR:
11133 : 0 : {
11134 : 0 : tree oprnd0 = treeop0;
11135 : 0 : tree oprnd1 = treeop1;
11136 : 0 : tree oprnd2 = treeop2;
11137 : :
11138 : 0 : this_optab = optab_for_tree_code (code, type, optab_default);
11139 : 0 : expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
11140 : 0 : op2 = expand_normal (oprnd2);
11141 : 0 : temp = expand_ternary_op (mode, this_optab, op0, op1, op2,
11142 : : target, unsignedp);
11143 : 0 : gcc_assert (temp);
11144 : : return temp;
11145 : : }
11146 : :
11147 : 17568 : case COND_EXPR:
11148 : 17568 : {
11149 : : /* A COND_EXPR with its type being VOID_TYPE represents a
11150 : : conditional jump and is handled in
11151 : : expand_gimple_cond_expr. */
11152 : 17568 : gcc_assert (!VOID_TYPE_P (type));
11153 : :
11154 : : /* Note that COND_EXPRs whose type is a structure or union
11155 : : are required to be constructed to contain assignments of
11156 : : a temporary variable, so that we can evaluate them here
11157 : : for side effect only. If type is void, we must do likewise. */
11158 : :
11159 : 17568 : gcc_assert (!TREE_ADDRESSABLE (type)
11160 : : && !ignore
11161 : : && TREE_TYPE (treeop1) != void_type_node
11162 : : && TREE_TYPE (treeop2) != void_type_node);
11163 : :
11164 : 17568 : temp = expand_cond_expr_using_cmove (treeop0, treeop1, treeop2);
11165 : 17568 : if (temp)
11166 : : return temp;
11167 : :
11168 : : /* If we are not to produce a result, we have no target. Otherwise,
11169 : : if a target was specified use it; it will not be used as an
11170 : : intermediate target unless it is safe. If no target, use a
11171 : : temporary. */
11172 : :
11173 : 3590 : if (modifier != EXPAND_STACK_PARM
11174 : 3590 : && original_target
11175 : 1987 : && safe_from_p (original_target, treeop0, 1)
11176 : 0 : && GET_MODE (original_target) == mode
11177 : 3590 : && !MEM_P (original_target))
11178 : : temp = original_target;
11179 : : else
11180 : 3590 : temp = assign_temp (type, 0, 1);
11181 : :
11182 : 3590 : do_pending_stack_adjust ();
11183 : 3590 : NO_DEFER_POP;
11184 : 3590 : rtx_code_label *lab0 = gen_label_rtx ();
11185 : 3590 : rtx_code_label *lab1 = gen_label_rtx ();
11186 : 3590 : jumpifnot (treeop0, lab0,
11187 : : profile_probability::uninitialized ());
11188 : 3590 : store_expr (treeop1, temp,
11189 : : modifier == EXPAND_STACK_PARM,
11190 : : false, false);
11191 : :
11192 : 3590 : emit_jump_insn (targetm.gen_jump (lab1));
11193 : 3590 : emit_barrier ();
11194 : 3590 : emit_label (lab0);
11195 : 3590 : store_expr (treeop2, temp,
11196 : : modifier == EXPAND_STACK_PARM,
11197 : : false, false);
11198 : :
11199 : 3590 : emit_label (lab1);
11200 : 3590 : OK_DEFER_POP;
11201 : 3590 : return temp;
11202 : : }
11203 : :
11204 : 0 : case VEC_DUPLICATE_EXPR:
11205 : 0 : op0 = expand_expr (treeop0, NULL_RTX, VOIDmode, modifier);
11206 : 0 : target = expand_vector_broadcast (mode, op0);
11207 : 0 : gcc_assert (target);
11208 : : return target;
11209 : :
11210 : 0 : case VEC_SERIES_EXPR:
11211 : 0 : expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, modifier);
11212 : 0 : return expand_vec_series_expr (mode, op0, op1, target);
11213 : :
11214 : 917 : case BIT_INSERT_EXPR:
11215 : 917 : {
11216 : 917 : unsigned bitpos = tree_to_uhwi (treeop2);
11217 : 917 : unsigned bitsize;
11218 : 917 : if (INTEGRAL_TYPE_P (TREE_TYPE (treeop1)))
11219 : 566 : bitsize = TYPE_PRECISION (TREE_TYPE (treeop1));
11220 : : else
11221 : 351 : bitsize = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (treeop1)));
11222 : 917 : op0 = expand_normal (treeop0);
11223 : 917 : op1 = expand_normal (treeop1);
11224 : 917 : rtx dst = gen_reg_rtx (mode);
11225 : 917 : emit_move_insn (dst, op0);
11226 : 917 : store_bit_field (dst, bitsize, bitpos, 0, 0,
11227 : 917 : TYPE_MODE (TREE_TYPE (treeop1)), op1, false, false);
11228 : 917 : return dst;
11229 : : }
11230 : :
11231 : 0 : default:
11232 : 0 : gcc_unreachable ();
11233 : : }
11234 : :
11235 : : /* Here to do an ordinary binary operator. */
11236 : 1185080 : binop:
11237 : 1185080 : expand_operands (treeop0, treeop1,
11238 : : subtarget, &op0, &op1, EXPAND_NORMAL);
11239 : 5558586 : binop2:
11240 : 5558586 : this_optab = optab_for_tree_code (code, type, optab_default);
11241 : 5558586 : binop3:
11242 : 5558586 : if (modifier == EXPAND_STACK_PARM)
11243 : 25010 : target = 0;
11244 : 5558586 : temp = expand_binop (mode, this_optab, op0, op1, target,
11245 : : unsignedp, OPTAB_LIB_WIDEN);
11246 : 5558586 : gcc_assert (temp);
11247 : : /* Bitwise operations do not need bitfield reduction as we expect their
11248 : : operands being properly truncated. */
11249 : 5558586 : if (code == BIT_XOR_EXPR
11250 : : || code == BIT_AND_EXPR
11251 : 5558586 : || code == BIT_IOR_EXPR)
11252 : : return temp;
11253 : 4942462 : return REDUCE_BIT_FIELD (temp);
11254 : : }
11255 : : #undef REDUCE_BIT_FIELD
11256 : :
11257 : :
11258 : : /* Return TRUE if expression STMT is suitable for replacement.
11259 : : Never consider memory loads as replaceable, because those don't ever lead
11260 : : into constant expressions. */
11261 : :
11262 : : static bool
11263 : 8 : stmt_is_replaceable_p (gimple *stmt)
11264 : : {
11265 : 8 : if (ssa_is_replaceable_p (stmt))
11266 : : {
11267 : : /* Don't move around loads. */
11268 : 7 : if (!gimple_assign_single_p (stmt)
11269 : 7 : || is_gimple_val (gimple_assign_rhs1 (stmt)))
11270 : 6 : return true;
11271 : : }
11272 : : return false;
11273 : : }
11274 : :
11275 : : /* A subroutine of expand_expr_real_1. Expand gimple assignment G,
11276 : : which is known to set an SSA_NAME result. The other arguments are
11277 : : as for expand_expr_real_1. */
11278 : :
11279 : : rtx
11280 : 14620942 : expand_expr_real_gassign (gassign *g, rtx target, machine_mode tmode,
11281 : : enum expand_modifier modifier, rtx *alt_rtl,
11282 : : bool inner_reference_p)
11283 : : {
11284 : 14620942 : separate_ops ops;
11285 : 14620942 : rtx r;
11286 : 14620942 : location_t saved_loc = curr_insn_location ();
11287 : 14620942 : auto loc = gimple_location (g);
11288 : 14620942 : if (loc != UNKNOWN_LOCATION)
11289 : 11777448 : set_curr_insn_location (loc);
11290 : 14620942 : tree lhs = gimple_assign_lhs (g);
11291 : 14620942 : ops.code = gimple_assign_rhs_code (g);
11292 : 14620942 : ops.type = TREE_TYPE (lhs);
11293 : 14620942 : switch (get_gimple_rhs_class (ops.code))
11294 : : {
11295 : 93316 : case GIMPLE_TERNARY_RHS:
11296 : 186632 : ops.op2 = gimple_assign_rhs3 (g);
11297 : : /* Fallthru */
11298 : 7755370 : case GIMPLE_BINARY_RHS:
11299 : 7755370 : ops.op1 = gimple_assign_rhs2 (g);
11300 : :
11301 : : /* Try to expand conditonal compare. */
11302 : 7755370 : if (targetm.have_ccmp ())
11303 : : {
11304 : 1106 : gcc_checking_assert (targetm.gen_ccmp_next != NULL);
11305 : 1106 : r = expand_ccmp_expr (g, TYPE_MODE (ops.type));
11306 : 1106 : if (r)
11307 : : break;
11308 : : }
11309 : : /* Fallthru */
11310 : 11169357 : case GIMPLE_UNARY_RHS:
11311 : 11169357 : ops.op0 = gimple_assign_rhs1 (g);
11312 : 11169357 : ops.location = loc;
11313 : 11169357 : r = expand_expr_real_2 (&ops, target, tmode, modifier);
11314 : 11169357 : break;
11315 : 3451567 : case GIMPLE_SINGLE_RHS:
11316 : 3451567 : {
11317 : 3451567 : r = expand_expr_real (gimple_assign_rhs1 (g), target,
11318 : : tmode, modifier, alt_rtl,
11319 : : inner_reference_p);
11320 : 3451567 : break;
11321 : : }
11322 : 0 : default:
11323 : 0 : gcc_unreachable ();
11324 : : }
11325 : 14620942 : set_curr_insn_location (saved_loc);
11326 : 14620942 : if (REG_P (r) && !REG_EXPR (r))
11327 : 3650378 : set_reg_attrs_for_decl_rtl (lhs, r);
11328 : 14620942 : return r;
11329 : : }
11330 : :
11331 : : rtx
11332 : 155615719 : expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
11333 : : enum expand_modifier modifier, rtx *alt_rtl,
11334 : : bool inner_reference_p)
11335 : : {
11336 : 155615719 : rtx op0, op1, temp, decl_rtl;
11337 : 155615719 : tree type;
11338 : 155615719 : int unsignedp;
11339 : 155615719 : machine_mode mode, dmode;
11340 : 155615719 : enum tree_code code = TREE_CODE (exp);
11341 : 155615719 : rtx subtarget, original_target;
11342 : 155615719 : int ignore;
11343 : 155615719 : bool reduce_bit_field;
11344 : 155615719 : location_t loc = EXPR_LOCATION (exp);
11345 : 155615719 : struct separate_ops ops;
11346 : 155615719 : tree treeop0, treeop1, treeop2;
11347 : 155615719 : tree ssa_name = NULL_TREE;
11348 : 155615719 : gimple *g;
11349 : :
11350 : : /* Some ABIs define padding bits in _BitInt uninitialized. Normally, RTL
11351 : : expansion sign/zero extends integral types with less than mode precision
11352 : : when reading from bit-fields and after arithmetic operations (see
11353 : : REDUCE_BIT_FIELD in expand_expr_real_2) and on subsequent loads relies
11354 : : on those extensions to have been already performed, but because of the
11355 : : above for _BitInt they need to be sign/zero extended when reading from
11356 : : locations that could be exposed to ABI boundaries (when loading from
11357 : : objects in memory, or function arguments, return value). Because we
11358 : : internally extend after arithmetic operations, we can avoid doing that
11359 : : when reading from SSA_NAMEs of vars. */
11360 : : #define EXTEND_BITINT(expr) \
11361 : : ((TREE_CODE (type) == BITINT_TYPE \
11362 : : && !bitint_extended \
11363 : : && reduce_bit_field \
11364 : : && mode != BLKmode \
11365 : : && modifier != EXPAND_MEMORY \
11366 : : && modifier != EXPAND_WRITE \
11367 : : && modifier != EXPAND_INITIALIZER \
11368 : : && modifier != EXPAND_CONST_ADDRESS) \
11369 : : ? reduce_to_bit_field_precision ((expr), NULL_RTX, type) : (expr))
11370 : :
11371 : 155615719 : type = TREE_TYPE (exp);
11372 : 155615719 : mode = TYPE_MODE (type);
11373 : 155615719 : unsignedp = TYPE_UNSIGNED (type);
11374 : 155615719 : if (TREE_CODE (type) == BITINT_TYPE && bitint_extended == -1)
11375 : : {
11376 : 8561 : struct bitint_info info;
11377 : 8561 : bool ok = targetm.c.bitint_type_info (TYPE_PRECISION (type), &info);
11378 : 8561 : gcc_assert (ok);
11379 : 8561 : bitint_extended = info.extended;
11380 : : }
11381 : :
11382 : 155615719 : treeop0 = treeop1 = treeop2 = NULL_TREE;
11383 : 155615719 : if (!VL_EXP_CLASS_P (exp))
11384 : 148916123 : switch (TREE_CODE_LENGTH (code))
11385 : : {
11386 : 5579753 : default:
11387 : 5579753 : case 3: treeop2 = TREE_OPERAND (exp, 2); /* FALLTHRU */
11388 : 13507290 : case 2: treeop1 = TREE_OPERAND (exp, 1); /* FALLTHRU */
11389 : 27808789 : case 1: treeop0 = TREE_OPERAND (exp, 0); /* FALLTHRU */
11390 : : case 0: break;
11391 : : }
11392 : 155615719 : ops.code = code;
11393 : 155615719 : ops.type = type;
11394 : 155615719 : ops.op0 = treeop0;
11395 : 155615719 : ops.op1 = treeop1;
11396 : 155615719 : ops.op2 = treeop2;
11397 : 155615719 : ops.location = loc;
11398 : :
11399 : 311231438 : ignore = (target == const0_rtx
11400 : 155615719 : || ((CONVERT_EXPR_CODE_P (code)
11401 : 150589359 : || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
11402 : 942641 : && TREE_CODE (type) == VOID_TYPE));
11403 : :
11404 : : /* An operation in what may be a bit-field type needs the
11405 : : result to be reduced to the precision of the bit-field type,
11406 : : which is narrower than that of the type's mode. */
11407 : 311231215 : reduce_bit_field = (!ignore
11408 : 151193740 : && INTEGRAL_TYPE_P (type)
11409 : 79080131 : && !type_has_mode_precision_p (type));
11410 : :
11411 : : /* If we are going to ignore this result, we need only do something
11412 : : if there is a side-effect somewhere in the expression. If there
11413 : : is, short-circuit the most common cases here. Note that we must
11414 : : not call expand_expr with anything but const0_rtx in case this
11415 : : is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
11416 : :
11417 : 4421979 : if (ignore)
11418 : : {
11419 : 4421979 : if (! TREE_SIDE_EFFECTS (exp))
11420 : : return const0_rtx;
11421 : :
11422 : : /* Ensure we reference a volatile object even if value is ignored, but
11423 : : don't do this if all we are doing is taking its address. */
11424 : 4421756 : if (TREE_THIS_VOLATILE (exp)
11425 : 0 : && TREE_CODE (exp) != FUNCTION_DECL
11426 : 0 : && mode != VOIDmode && mode != BLKmode
11427 : 0 : && modifier != EXPAND_CONST_ADDRESS)
11428 : : {
11429 : 0 : temp = expand_expr (exp, NULL_RTX, VOIDmode, modifier);
11430 : 0 : if (MEM_P (temp))
11431 : 0 : copy_to_reg (temp);
11432 : 0 : return const0_rtx;
11433 : : }
11434 : :
11435 : 4421756 : if (TREE_CODE_CLASS (code) == tcc_unary
11436 : : || code == BIT_FIELD_REF
11437 : 4421756 : || code == COMPONENT_REF
11438 : 4421756 : || code == INDIRECT_REF)
11439 : 0 : return expand_expr (treeop0, const0_rtx, VOIDmode,
11440 : 0 : modifier);
11441 : :
11442 : 4421756 : else if (TREE_CODE_CLASS (code) == tcc_binary
11443 : 4421756 : || TREE_CODE_CLASS (code) == tcc_comparison
11444 : 4421756 : || code == ARRAY_REF || code == ARRAY_RANGE_REF)
11445 : : {
11446 : 0 : expand_expr (treeop0, const0_rtx, VOIDmode, modifier);
11447 : 0 : expand_expr (treeop1, const0_rtx, VOIDmode, modifier);
11448 : 0 : return const0_rtx;
11449 : : }
11450 : :
11451 : : target = 0;
11452 : : }
11453 : :
11454 : 155615496 : if (reduce_bit_field && modifier == EXPAND_STACK_PARM)
11455 : 37695 : target = 0;
11456 : :
11457 : : /* Use subtarget as the target for operand 0 of a binary operation. */
11458 : 155615496 : subtarget = get_subtarget (target);
11459 : 155615496 : original_target = target;
11460 : :
11461 : 155615496 : switch (code)
11462 : : {
11463 : 10811 : case LABEL_DECL:
11464 : 10811 : {
11465 : 10811 : tree function = decl_function_context (exp);
11466 : :
11467 : 10811 : temp = label_rtx (exp);
11468 : 14755 : temp = gen_rtx_LABEL_REF (Pmode, temp);
11469 : :
11470 : 10811 : if (function != current_function_decl
11471 : 1263 : && function != 0)
11472 : 1263 : LABEL_REF_NONLOCAL_P (temp) = 1;
11473 : :
11474 : 10811 : temp = gen_rtx_MEM (FUNCTION_MODE, temp);
11475 : 10811 : return temp;
11476 : : }
11477 : :
11478 : 55804268 : case SSA_NAME:
11479 : : /* ??? ivopts calls expander, without any preparation from
11480 : : out-of-ssa. So fake instructions as if this was an access to the
11481 : : base variable. This unnecessarily allocates a pseudo, see how we can
11482 : : reuse it, if partition base vars have it set already. */
11483 : 55804268 : if (!currently_expanding_to_rtl)
11484 : : {
11485 : 0 : tree var = SSA_NAME_VAR (exp);
11486 : 0 : if (var && DECL_RTL_SET_P (var))
11487 : 0 : return DECL_RTL (var);
11488 : 0 : return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp)),
11489 : 0 : LAST_VIRTUAL_REGISTER + 1);
11490 : : }
11491 : :
11492 : 55804268 : g = get_gimple_for_ssa_name (exp);
11493 : : /* For EXPAND_INITIALIZER try harder to get something simpler. */
11494 : 55804268 : if (g == NULL
11495 : 55804268 : && modifier == EXPAND_INITIALIZER
11496 : 26 : && !SSA_NAME_IS_DEFAULT_DEF (exp)
11497 : 11 : && (optimize || !SSA_NAME_VAR (exp)
11498 : 1 : || DECL_IGNORED_P (SSA_NAME_VAR (exp)))
11499 : 10 : && is_gimple_assign (SSA_NAME_DEF_STMT (exp))
11500 : 55804276 : && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp)))
11501 : 6 : g = SSA_NAME_DEF_STMT (exp);
11502 : 55804268 : if (safe_is_a <gassign *> (g))
11503 : 8776345 : return expand_expr_real_gassign (as_a<gassign *> (g), target, tmode,
11504 : 8776345 : modifier, alt_rtl, inner_reference_p);
11505 : 47027923 : else if (safe_is_a <gcall *> (g))
11506 : : {
11507 : : /* ??? internal call expansion doesn't follow the usual API
11508 : : of returning the destination RTX and being passed a desired
11509 : : target. */
11510 : 65806 : if (modifier == EXPAND_WRITE)
11511 : 32907 : return DECL_RTL (SSA_NAME_VAR (exp));
11512 : 32899 : rtx dest = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
11513 : 32899 : tree tmplhs = make_tree (TREE_TYPE (exp), dest);
11514 : 32899 : tree var_or_id = SSA_NAME_VAR (exp);
11515 : : if (!var_or_id)
11516 : 25297 : var_or_id = SSA_NAME_IDENTIFIER (exp);
11517 : 32899 : SET_SSA_NAME_VAR_OR_IDENTIFIER (exp, tmplhs);
11518 : 32899 : expand_internal_call (as_a <gcall *> (g));
11519 : 32899 : SET_SSA_NAME_VAR_OR_IDENTIFIER (exp, var_or_id);
11520 : 32899 : return dest;
11521 : : }
11522 : :
11523 : 46962117 : ssa_name = exp;
11524 : 46962117 : decl_rtl = get_rtx_for_ssa_name (ssa_name);
11525 : 46962117 : exp = SSA_NAME_VAR (ssa_name);
11526 : : /* Optimize and avoid to EXTEND_BITINIT doing anything if it is an
11527 : : SSA_NAME computed within the current function. In such case the
11528 : : value have been already extended before. While if it is a function
11529 : : parameter, result or some memory location, we need to be prepared
11530 : : for some other compiler leaving the bits uninitialized. */
11531 : 18491421 : if (!exp || VAR_P (exp))
11532 : : reduce_bit_field = false;
11533 : 46962117 : goto expand_decl_rtl;
11534 : :
11535 : 19672879 : case VAR_DECL:
11536 : : /* Allow accel compiler to handle variables that require special
11537 : : treatment, e.g. if they have been modified in some way earlier in
11538 : : compilation by the adjust_private_decl OpenACC hook. */
11539 : 19672879 : if (flag_openacc && targetm.goacc.expand_var_decl)
11540 : : {
11541 : 0 : temp = targetm.goacc.expand_var_decl (exp);
11542 : 0 : if (temp)
11543 : : return temp;
11544 : : }
11545 : : /* Expand const VAR_DECLs with CONSTRUCTOR initializers that
11546 : : have scalar integer modes to a reg via store_constructor. */
11547 : 19672879 : if (TREE_READONLY (exp)
11548 : 3364237 : && !TREE_SIDE_EFFECTS (exp)
11549 : 3341824 : && (modifier == EXPAND_NORMAL || modifier == EXPAND_STACK_PARM)
11550 : 17417 : && immediate_const_ctor_p (DECL_INITIAL (exp))
11551 : 156 : && SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (exp)))
11552 : 124 : && crtl->emit.regno_pointer_align_length
11553 : 19673003 : && !target)
11554 : : {
11555 : 85 : target = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
11556 : 85 : store_constructor (DECL_INITIAL (exp), target, 0,
11557 : 85 : int_expr_size (DECL_INITIAL (exp)), false);
11558 : 85 : return target;
11559 : : }
11560 : : /* ... fall through ... */
11561 : :
11562 : 20219413 : case PARM_DECL:
11563 : : /* If a static var's type was incomplete when the decl was written,
11564 : : but the type is complete now, lay out the decl now. */
11565 : 20219413 : if (DECL_SIZE (exp) == 0
11566 : 44851 : && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp))
11567 : 20264152 : && (TREE_STATIC (exp) || DECL_EXTERNAL (exp)))
11568 : 44739 : layout_decl (exp, 0);
11569 : :
11570 : : /* fall through */
11571 : :
11572 : 21659512 : case FUNCTION_DECL:
11573 : 21659512 : case RESULT_DECL:
11574 : 21659512 : decl_rtl = DECL_RTL (exp);
11575 : 68621629 : expand_decl_rtl:
11576 : 68621629 : gcc_assert (decl_rtl);
11577 : :
11578 : : /* DECL_MODE might change when TYPE_MODE depends on attribute target
11579 : : settings for VECTOR_TYPE_P that might switch for the function. */
11580 : 68621629 : if (currently_expanding_to_rtl
11581 : 64960408 : && code == VAR_DECL && MEM_P (decl_rtl)
11582 : 83298784 : && VECTOR_TYPE_P (type) && exp && DECL_MODE (exp) != mode)
11583 : 57 : decl_rtl = change_address (decl_rtl, TYPE_MODE (type), 0);
11584 : : else
11585 : 68621572 : decl_rtl = copy_rtx (decl_rtl);
11586 : :
11587 : : /* Record writes to register variables. */
11588 : 68621629 : if (modifier == EXPAND_WRITE
11589 : 21638799 : && REG_P (decl_rtl)
11590 : 84423131 : && HARD_REGISTER_P (decl_rtl))
11591 : 2026 : add_to_hard_reg_set (&crtl->asm_clobbers,
11592 : 2026 : GET_MODE (decl_rtl), REGNO (decl_rtl));
11593 : :
11594 : : /* Ensure variable marked as used even if it doesn't go through
11595 : : a parser. If it hasn't be used yet, write out an external
11596 : : definition. */
11597 : 68621629 : if (exp)
11598 : 40150933 : TREE_USED (exp) = 1;
11599 : :
11600 : : /* Show we haven't gotten RTL for this yet. */
11601 : 108772562 : temp = 0;
11602 : :
11603 : : /* Variables inherited from containing functions should have
11604 : : been lowered by this point. */
11605 : 40150933 : if (exp)
11606 : : {
11607 : 40150933 : tree context = decl_function_context (exp);
11608 : 40150933 : gcc_assert (SCOPE_FILE_SCOPE_P (context)
11609 : : || context == current_function_decl
11610 : : || TREE_STATIC (exp)
11611 : : || DECL_EXTERNAL (exp)
11612 : : /* ??? C++ creates functions that are not
11613 : : TREE_STATIC. */
11614 : : || TREE_CODE (exp) == FUNCTION_DECL);
11615 : : }
11616 : :
11617 : : /* This is the case of an array whose size is to be determined
11618 : : from its initializer, while the initializer is still being parsed.
11619 : : ??? We aren't parsing while expanding anymore. */
11620 : :
11621 : 68621629 : if (MEM_P (decl_rtl) && REG_P (XEXP (decl_rtl, 0)))
11622 : 390263 : temp = validize_mem (decl_rtl);
11623 : :
11624 : : /* If DECL_RTL is memory, we are in the normal case and the
11625 : : address is not valid, get the address into a register. */
11626 : :
11627 : 68231366 : else if (MEM_P (decl_rtl) && modifier != EXPAND_INITIALIZER)
11628 : : {
11629 : 18632450 : if (alt_rtl)
11630 : 2040322 : *alt_rtl = decl_rtl;
11631 : 18632450 : decl_rtl = use_anchored_address (decl_rtl);
11632 : 18632450 : if (modifier != EXPAND_CONST_ADDRESS
11633 : 18632450 : && modifier != EXPAND_SUM
11634 : 30927236 : && !memory_address_addr_space_p (exp ? DECL_MODE (exp)
11635 : 17095 : : GET_MODE (decl_rtl),
11636 : : XEXP (decl_rtl, 0),
11637 : 12294786 : MEM_ADDR_SPACE (decl_rtl)))
11638 : 134697 : temp = replace_equiv_address (decl_rtl,
11639 : : copy_rtx (XEXP (decl_rtl, 0)));
11640 : : }
11641 : :
11642 : : /* If we got something, return it. But first, set the alignment
11643 : : if the address is a register. */
11644 : 19022713 : if (temp != 0)
11645 : : {
11646 : 524960 : if (exp && MEM_P (temp) && REG_P (XEXP (temp, 0)))
11647 : 494423 : mark_reg_pointer (XEXP (temp, 0), DECL_ALIGN (exp));
11648 : : }
11649 : 68096669 : else if (MEM_P (decl_rtl))
11650 : : temp = decl_rtl;
11651 : :
11652 : 46593672 : if (temp != 0)
11653 : : {
11654 : 22522390 : if (MEM_P (temp)
11655 : : && modifier != EXPAND_WRITE
11656 : 22522390 : && modifier != EXPAND_MEMORY
11657 : : && modifier != EXPAND_INITIALIZER
11658 : 16598515 : && modifier != EXPAND_CONST_ADDRESS
11659 : 6916359 : && modifier != EXPAND_SUM
11660 : 6916359 : && !inner_reference_p
11661 : 4499699 : && mode != BLKmode
11662 : 26655693 : && MEM_ALIGN (temp) < GET_MODE_ALIGNMENT (mode))
11663 : 19822 : temp = expand_misaligned_mem_ref (temp, mode, unsignedp,
11664 : 19822 : MEM_ALIGN (temp), NULL_RTX, NULL);
11665 : :
11666 : 22522390 : return EXTEND_BITINT (temp);
11667 : : }
11668 : :
11669 : 46099239 : if (exp)
11670 : 17645648 : dmode = DECL_MODE (exp);
11671 : : else
11672 : 28453591 : dmode = TYPE_MODE (TREE_TYPE (ssa_name));
11673 : :
11674 : : /* If the mode of DECL_RTL does not match that of the decl,
11675 : : there are two cases: we are dealing with a BLKmode value
11676 : : that is returned in a register, or we are dealing with
11677 : : a promoted value. In the latter case, return a SUBREG
11678 : : of the wanted mode, but mark it so that we know that it
11679 : : was already extended. */
11680 : 46099239 : if (REG_P (decl_rtl)
11681 : 45618499 : && dmode != BLKmode
11682 : 45618499 : && GET_MODE (decl_rtl) != dmode)
11683 : : {
11684 : 82 : machine_mode pmode;
11685 : :
11686 : : /* Get the signedness to be used for this variable. Ensure we get
11687 : : the same mode we got when the variable was declared. */
11688 : 82 : if (code != SSA_NAME)
11689 : 0 : pmode = promote_decl_mode (exp, &unsignedp);
11690 : 82 : else if ((g = SSA_NAME_DEF_STMT (ssa_name))
11691 : 82 : && gimple_code (g) == GIMPLE_CALL
11692 : 84 : && !gimple_call_internal_p (g))
11693 : 2 : pmode = promote_function_mode (type, mode, &unsignedp,
11694 : 2 : gimple_call_fntype (g),
11695 : : 2);
11696 : : else
11697 : 80 : pmode = promote_ssa_mode (ssa_name, &unsignedp);
11698 : 82 : gcc_assert (GET_MODE (decl_rtl) == pmode);
11699 : :
11700 : : /* Some ABIs require scalar floating point modes to be passed
11701 : : in a wider scalar integer mode. We need to explicitly
11702 : : truncate to an integer mode of the correct precision before
11703 : : using a SUBREG to reinterpret as a floating point value. */
11704 : 82 : if (SCALAR_FLOAT_MODE_P (mode)
11705 : 0 : && SCALAR_INT_MODE_P (pmode)
11706 : 82 : && known_lt (GET_MODE_SIZE (mode), GET_MODE_SIZE (pmode)))
11707 : 0 : return convert_wider_int_to_float (mode, pmode, decl_rtl);
11708 : :
11709 : 82 : temp = gen_lowpart_SUBREG (mode, decl_rtl);
11710 : 82 : SUBREG_PROMOTED_VAR_P (temp) = 1;
11711 : 82 : SUBREG_PROMOTED_SET (temp, unsignedp);
11712 : 82 : return EXTEND_BITINT (temp);
11713 : : }
11714 : :
11715 : 46099157 : return EXTEND_BITINT (decl_rtl);
11716 : :
11717 : 41860891 : case INTEGER_CST:
11718 : 41860891 : {
11719 : 41860891 : if (TREE_CODE (type) == BITINT_TYPE)
11720 : : {
11721 : 10624 : unsigned int prec = TYPE_PRECISION (type);
11722 : 10624 : struct bitint_info info;
11723 : 10624 : bool ok = targetm.c.bitint_type_info (prec, &info);
11724 : 10624 : gcc_assert (ok);
11725 : 10624 : scalar_int_mode limb_mode
11726 : 10624 : = as_a <scalar_int_mode> (info.limb_mode);
11727 : 10624 : unsigned int limb_prec = GET_MODE_PRECISION (limb_mode);
11728 : 17510 : if (prec > limb_prec && prec > MAX_FIXED_MODE_SIZE)
11729 : : {
11730 : : /* Emit large/huge _BitInt INTEGER_CSTs into memory. */
11731 : 4433 : exp = tree_output_constant_def (exp);
11732 : 4433 : return expand_expr (exp, target, VOIDmode, modifier);
11733 : : }
11734 : : }
11735 : :
11736 : : /* Given that TYPE_PRECISION (type) is not always equal to
11737 : : GET_MODE_PRECISION (TYPE_MODE (type)), we need to extend from
11738 : : the former to the latter according to the signedness of the
11739 : : type. */
11740 : 41856458 : scalar_int_mode int_mode = SCALAR_INT_TYPE_MODE (type);
11741 : 41856458 : temp = immed_wide_int_const
11742 : 41856458 : (wi::to_wide (exp, GET_MODE_PRECISION (int_mode)), int_mode);
11743 : 41856458 : return temp;
11744 : : }
11745 : :
11746 : 551035 : case VECTOR_CST:
11747 : 551035 : {
11748 : 551035 : tree tmp = NULL_TREE;
11749 : 551035 : if (VECTOR_MODE_P (mode))
11750 : 549165 : return const_vector_from_tree (exp);
11751 : 1870 : scalar_int_mode int_mode;
11752 : 1870 : if (is_int_mode (mode, &int_mode))
11753 : : {
11754 : 188 : tree type_for_mode = lang_hooks.types.type_for_mode (int_mode, 1);
11755 : 188 : if (type_for_mode)
11756 : 188 : tmp = fold_unary_loc (loc, VIEW_CONVERT_EXPR,
11757 : : type_for_mode, exp);
11758 : : }
11759 : 188 : if (!tmp)
11760 : : {
11761 : 1682 : vec<constructor_elt, va_gc> *v;
11762 : : /* Constructors need to be fixed-length. FIXME. */
11763 : 1682 : unsigned int nunits = VECTOR_CST_NELTS (exp).to_constant ();
11764 : 1682 : vec_alloc (v, nunits);
11765 : 24287 : for (unsigned int i = 0; i < nunits; ++i)
11766 : 22605 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, VECTOR_CST_ELT (exp, i));
11767 : 1682 : tmp = build_constructor (type, v);
11768 : : }
11769 : 1870 : return expand_expr (tmp, ignore ? const0_rtx : target,
11770 : 1870 : tmode, modifier);
11771 : : }
11772 : :
11773 : 141 : case CONST_DECL:
11774 : 141 : if (modifier == EXPAND_WRITE)
11775 : : {
11776 : : /* Writing into CONST_DECL is always invalid, but handle it
11777 : : gracefully. */
11778 : 2 : addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (exp));
11779 : 2 : scalar_int_mode address_mode = targetm.addr_space.address_mode (as);
11780 : 2 : op0 = expand_expr_addr_expr_1 (exp, NULL_RTX, address_mode,
11781 : : EXPAND_NORMAL, as);
11782 : 2 : op0 = memory_address_addr_space (mode, op0, as);
11783 : 2 : temp = gen_rtx_MEM (mode, op0);
11784 : 2 : set_mem_addr_space (temp, as);
11785 : 2 : return temp;
11786 : : }
11787 : 139 : return expand_expr (DECL_INITIAL (exp), target, VOIDmode, modifier);
11788 : :
11789 : 864048 : case REAL_CST:
11790 : : /* If optimized, generate immediate CONST_DOUBLE
11791 : : which will be turned into memory by reload if necessary.
11792 : :
11793 : : We used to force a register so that loop.c could see it. But
11794 : : this does not allow gen_* patterns to perform optimizations with
11795 : : the constants. It also produces two insns in cases like "x = 1.0;".
11796 : : On most machines, floating-point constants are not permitted in
11797 : : many insns, so we'd end up copying it to a register in any case.
11798 : :
11799 : : Now, we do the copying in expand_binop, if appropriate. */
11800 : 864048 : return const_double_from_real_value (TREE_REAL_CST (exp),
11801 : 1728096 : TYPE_MODE (TREE_TYPE (exp)));
11802 : :
11803 : 0 : case FIXED_CST:
11804 : 0 : return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp),
11805 : : TYPE_MODE (TREE_TYPE (exp)));
11806 : :
11807 : 18341 : case COMPLEX_CST:
11808 : : /* Handle evaluating a complex constant in a CONCAT target. */
11809 : 18341 : if (original_target && GET_CODE (original_target) == CONCAT)
11810 : : {
11811 : 213 : rtx rtarg, itarg;
11812 : :
11813 : 213 : mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
11814 : 213 : rtarg = XEXP (original_target, 0);
11815 : 213 : itarg = XEXP (original_target, 1);
11816 : :
11817 : : /* Move the real and imaginary parts separately. */
11818 : 213 : op0 = expand_expr (TREE_REALPART (exp), rtarg, mode, EXPAND_NORMAL);
11819 : 213 : op1 = expand_expr (TREE_IMAGPART (exp), itarg, mode, EXPAND_NORMAL);
11820 : :
11821 : 213 : if (op0 != rtarg)
11822 : 213 : emit_move_insn (rtarg, op0);
11823 : 213 : if (op1 != itarg)
11824 : 213 : emit_move_insn (itarg, op1);
11825 : :
11826 : 213 : return original_target;
11827 : : }
11828 : :
11829 : : /* fall through */
11830 : :
11831 : 177325 : case STRING_CST:
11832 : 177325 : temp = expand_expr_constant (exp, 1, modifier);
11833 : :
11834 : : /* temp contains a constant address.
11835 : : On RISC machines where a constant address isn't valid,
11836 : : make some insns to get that address into a register. */
11837 : 177325 : if (modifier != EXPAND_CONST_ADDRESS
11838 : : && modifier != EXPAND_INITIALIZER
11839 : 177325 : && modifier != EXPAND_SUM
11840 : 195892 : && ! memory_address_addr_space_p (mode, XEXP (temp, 0),
11841 : 18567 : MEM_ADDR_SPACE (temp)))
11842 : 12 : return replace_equiv_address (temp,
11843 : 12 : copy_rtx (XEXP (temp, 0)));
11844 : : return temp;
11845 : :
11846 : 0 : case POLY_INT_CST:
11847 : 0 : return immed_wide_int_const (poly_int_cst_value (exp), mode);
11848 : :
11849 : 1382 : case SAVE_EXPR:
11850 : 1382 : {
11851 : 1382 : tree val = treeop0;
11852 : 1382 : rtx ret = expand_expr_real_1 (val, target, tmode, modifier, alt_rtl,
11853 : : inner_reference_p);
11854 : :
11855 : 1382 : if (!SAVE_EXPR_RESOLVED_P (exp))
11856 : : {
11857 : : /* We can indeed still hit this case, typically via builtin
11858 : : expanders calling save_expr immediately before expanding
11859 : : something. Assume this means that we only have to deal
11860 : : with non-BLKmode values. */
11861 : 1339 : gcc_assert (GET_MODE (ret) != BLKmode);
11862 : :
11863 : 1339 : val = build_decl (curr_insn_location (),
11864 : 1339 : VAR_DECL, NULL, TREE_TYPE (exp));
11865 : 1339 : DECL_ARTIFICIAL (val) = 1;
11866 : 1339 : DECL_IGNORED_P (val) = 1;
11867 : 1339 : treeop0 = val;
11868 : 1339 : TREE_OPERAND (exp, 0) = treeop0;
11869 : 1339 : SAVE_EXPR_RESOLVED_P (exp) = 1;
11870 : :
11871 : 1339 : if (!CONSTANT_P (ret))
11872 : 1339 : ret = copy_to_reg (ret);
11873 : 1339 : SET_DECL_RTL (val, ret);
11874 : : }
11875 : :
11876 : : return ret;
11877 : : }
11878 : :
11879 : :
11880 : 178997 : case CONSTRUCTOR:
11881 : : /* If we don't need the result, just ensure we evaluate any
11882 : : subexpressions. */
11883 : 178997 : if (ignore)
11884 : : {
11885 : : unsigned HOST_WIDE_INT idx;
11886 : : tree value;
11887 : :
11888 : 0 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
11889 : 0 : expand_expr (value, const0_rtx, VOIDmode, EXPAND_NORMAL);
11890 : :
11891 : 0 : return const0_rtx;
11892 : : }
11893 : :
11894 : 178997 : return expand_constructor (exp, target, modifier, false);
11895 : :
11896 : 841494 : case TARGET_MEM_REF:
11897 : 841494 : {
11898 : 841494 : addr_space_t as
11899 : 841494 : = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
11900 : 841494 : unsigned int align;
11901 : :
11902 : 841494 : op0 = addr_for_mem_ref (exp, as, true);
11903 : 841494 : op0 = memory_address_addr_space (mode, op0, as);
11904 : 841494 : temp = gen_rtx_MEM (mode, op0);
11905 : 841494 : set_mem_attributes (temp, exp, 0);
11906 : 841494 : set_mem_addr_space (temp, as);
11907 : 841494 : align = get_object_alignment (exp);
11908 : 841494 : if (modifier != EXPAND_WRITE
11909 : 841494 : && modifier != EXPAND_MEMORY
11910 : 579808 : && mode != BLKmode
11911 : 1415814 : && align < GET_MODE_ALIGNMENT (mode))
11912 : 50378 : temp = expand_misaligned_mem_ref (temp, mode, unsignedp,
11913 : : align, NULL_RTX, NULL);
11914 : 841494 : return EXTEND_BITINT (temp);
11915 : : }
11916 : :
11917 : 6624387 : case MEM_REF:
11918 : 6624387 : {
11919 : 6624387 : const bool reverse = REF_REVERSE_STORAGE_ORDER (exp);
11920 : 6624387 : addr_space_t as
11921 : 6624387 : = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
11922 : 6624387 : machine_mode address_mode;
11923 : 6624387 : tree base = TREE_OPERAND (exp, 0);
11924 : 6624387 : gimple *def_stmt;
11925 : 6624387 : unsigned align;
11926 : : /* Handle expansion of non-aliased memory with non-BLKmode. That
11927 : : might end up in a register. */
11928 : 6624387 : if (mem_ref_refers_to_non_mem_p (exp))
11929 : : {
11930 : 85403 : poly_int64 offset = mem_ref_offset (exp).force_shwi ();
11931 : 85403 : base = TREE_OPERAND (base, 0);
11932 : 85403 : poly_uint64 type_size;
11933 : 85403 : if (known_eq (offset, 0)
11934 : 48111 : && !reverse
11935 : 48111 : && poly_int_tree_p (TYPE_SIZE (type), &type_size)
11936 : 181625 : && known_eq (GET_MODE_BITSIZE (DECL_MODE (base)), type_size))
11937 : 20242 : return expand_expr (build1 (VIEW_CONVERT_EXPR, type, base),
11938 : 20242 : target, tmode, modifier);
11939 : 65161 : unsigned align;
11940 : 65161 : if (TYPE_MODE (type) == BLKmode || maybe_lt (offset, 0))
11941 : : {
11942 : 200 : temp = assign_stack_temp (DECL_MODE (base),
11943 : 400 : GET_MODE_SIZE (DECL_MODE (base)));
11944 : 200 : store_expr (base, temp, 0, false, false);
11945 : 200 : temp = adjust_address (temp, TYPE_MODE (type), offset);
11946 : 200 : if (TYPE_MODE (type) == BLKmode)
11947 : 185 : set_mem_size (temp, int_size_in_bytes (type));
11948 : : /* When the original ref was misaligned so will be the
11949 : : access to the stack temporary. Not all targets handle
11950 : : this correctly, some will ICE in sanity checking.
11951 : : Handle this by doing bitfield extraction when necessary. */
11952 : 30 : else if ((align = get_object_alignment (exp))
11953 : 15 : < GET_MODE_ALIGNMENT (TYPE_MODE (type)))
11954 : 3 : temp
11955 : 3 : = expand_misaligned_mem_ref (temp, TYPE_MODE (type),
11956 : : unsignedp, align,
11957 : : modifier == EXPAND_STACK_PARM
11958 : : ? NULL_RTX : target, NULL);
11959 : 200 : return temp;
11960 : : }
11961 : : /* When the access is fully outside of the underlying object
11962 : : expand the offset as zero. This avoids out-of-bound
11963 : : BIT_FIELD_REFs and generates smaller code for these cases
11964 : : with UB. */
11965 : 64961 : type_size = tree_to_poly_uint64 (TYPE_SIZE_UNIT (type));
11966 : 129922 : if (!ranges_maybe_overlap_p (offset, type_size, 0,
11967 : 129922 : GET_MODE_SIZE (DECL_MODE (base))))
11968 : 149 : offset = 0;
11969 : 64961 : exp = build3 (BIT_FIELD_REF, type, base, TYPE_SIZE (type),
11970 : 64961 : bitsize_int (offset * BITS_PER_UNIT));
11971 : 64961 : REF_REVERSE_STORAGE_ORDER (exp) = reverse;
11972 : 64961 : return expand_expr (exp, target, tmode, modifier);
11973 : : }
11974 : 6538984 : address_mode = targetm.addr_space.address_mode (as);
11975 : 6538984 : if ((def_stmt = get_def_for_expr (base, BIT_AND_EXPR)))
11976 : : {
11977 : 38 : tree mask = gimple_assign_rhs2 (def_stmt);
11978 : 38 : base = build2 (BIT_AND_EXPR, TREE_TYPE (base),
11979 : : gimple_assign_rhs1 (def_stmt), mask);
11980 : 38 : TREE_OPERAND (exp, 0) = base;
11981 : : }
11982 : 6538984 : align = get_object_alignment (exp);
11983 : 6538984 : op0 = expand_expr (base, NULL_RTX, VOIDmode, EXPAND_SUM);
11984 : 6538984 : op0 = memory_address_addr_space (mode, op0, as);
11985 : 6538984 : if (!integer_zerop (TREE_OPERAND (exp, 1)))
11986 : : {
11987 : 2042869 : rtx off = immed_wide_int_const (mem_ref_offset (exp), address_mode);
11988 : 2042869 : op0 = simplify_gen_binary (PLUS, address_mode, op0, off);
11989 : 2042869 : op0 = memory_address_addr_space (mode, op0, as);
11990 : : }
11991 : 6538984 : temp = gen_rtx_MEM (mode, op0);
11992 : 6538984 : set_mem_attributes (temp, exp, 0);
11993 : 6538984 : set_mem_addr_space (temp, as);
11994 : 6538984 : if (TREE_THIS_VOLATILE (exp))
11995 : 12168 : MEM_VOLATILE_P (temp) = 1;
11996 : 6538984 : if (modifier == EXPAND_WRITE || modifier == EXPAND_MEMORY)
11997 : : return temp;
11998 : 3913929 : if (!inner_reference_p
11999 : 1999729 : && mode != BLKmode
12000 : 5853437 : && align < GET_MODE_ALIGNMENT (mode))
12001 : 133092 : temp = expand_misaligned_mem_ref (temp, mode, unsignedp, align,
12002 : : modifier == EXPAND_STACK_PARM
12003 : : ? NULL_RTX : target, alt_rtl);
12004 : 3913929 : if (reverse)
12005 : 7 : temp = flip_storage_order (mode, temp);
12006 : 3913929 : return EXTEND_BITINT (temp);
12007 : : }
12008 : :
12009 : 613660 : case ARRAY_REF:
12010 : :
12011 : 613660 : {
12012 : 613660 : tree array = treeop0;
12013 : 613660 : tree index = treeop1;
12014 : 613660 : tree init;
12015 : :
12016 : : /* Fold an expression like: "foo"[2].
12017 : : This is not done in fold so it won't happen inside &.
12018 : : Don't fold if this is for wide characters since it's too
12019 : : difficult to do correctly and this is a very rare case. */
12020 : :
12021 : 613660 : if (modifier != EXPAND_CONST_ADDRESS
12022 : 613660 : && modifier != EXPAND_INITIALIZER
12023 : 613660 : && modifier != EXPAND_MEMORY)
12024 : : {
12025 : 613551 : tree t = fold_read_from_constant_string (exp);
12026 : :
12027 : 613551 : if (t)
12028 : 0 : return expand_expr (t, target, tmode, modifier);
12029 : : }
12030 : :
12031 : : /* If this is a constant index into a constant array,
12032 : : just get the value from the array. Handle both the cases when
12033 : : we have an explicit constructor and when our operand is a variable
12034 : : that was declared const. */
12035 : :
12036 : 613660 : if (modifier != EXPAND_CONST_ADDRESS
12037 : : && modifier != EXPAND_INITIALIZER
12038 : : && modifier != EXPAND_MEMORY
12039 : 613551 : && TREE_CODE (array) == CONSTRUCTOR
12040 : 0 : && ! TREE_SIDE_EFFECTS (array)
12041 : 613660 : && TREE_CODE (index) == INTEGER_CST)
12042 : : {
12043 : : unsigned HOST_WIDE_INT ix;
12044 : : tree field, value;
12045 : :
12046 : 0 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array), ix,
12047 : : field, value)
12048 : 0 : if (tree_int_cst_equal (field, index))
12049 : : {
12050 : 0 : if (!TREE_SIDE_EFFECTS (value)
12051 : 0 : && TREE_CODE (value) != RAW_DATA_CST)
12052 : 0 : return expand_expr (fold (value), target, tmode, modifier);
12053 : : break;
12054 : : }
12055 : : }
12056 : :
12057 : 613660 : else if (optimize >= 1
12058 : : && modifier != EXPAND_CONST_ADDRESS
12059 : 347089 : && modifier != EXPAND_INITIALIZER
12060 : 347089 : && modifier != EXPAND_MEMORY
12061 : 346984 : && TREE_READONLY (array) && ! TREE_SIDE_EFFECTS (array)
12062 : 11572 : && TREE_CODE (index) == INTEGER_CST
12063 : 1752 : && (VAR_P (array) || TREE_CODE (array) == CONST_DECL)
12064 : 613788 : && (init = ctor_for_folding (array)) != error_mark_node)
12065 : : {
12066 : 90 : if (init == NULL_TREE)
12067 : : {
12068 : 5 : tree value = build_zero_cst (type);
12069 : 5 : if (TREE_CODE (value) == CONSTRUCTOR)
12070 : : {
12071 : : /* If VALUE is a CONSTRUCTOR, this optimization is only
12072 : : useful if this doesn't store the CONSTRUCTOR into
12073 : : memory. If it does, it is more efficient to just
12074 : : load the data from the array directly. */
12075 : 5 : rtx ret = expand_constructor (value, target,
12076 : : modifier, true);
12077 : 5 : if (ret == NULL_RTX)
12078 : : value = NULL_TREE;
12079 : : }
12080 : :
12081 : : if (value)
12082 : 0 : return expand_expr (value, target, tmode, modifier);
12083 : : }
12084 : 85 : else if (TREE_CODE (init) == CONSTRUCTOR)
12085 : : {
12086 : : unsigned HOST_WIDE_INT ix;
12087 : : tree field, value;
12088 : :
12089 : 162 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), ix,
12090 : : field, value)
12091 : 147 : if (tree_int_cst_equal (field, index))
12092 : : {
12093 : 69 : if (TREE_SIDE_EFFECTS (value)
12094 : 69 : || TREE_CODE (value) == RAW_DATA_CST)
12095 : : break;
12096 : :
12097 : 69 : if (TREE_CODE (value) == CONSTRUCTOR)
12098 : : {
12099 : : /* If VALUE is a CONSTRUCTOR, this
12100 : : optimization is only useful if
12101 : : this doesn't store the CONSTRUCTOR
12102 : : into memory. If it does, it is more
12103 : : efficient to just load the data from
12104 : : the array directly. */
12105 : 64 : rtx ret = expand_constructor (value, target,
12106 : : modifier, true);
12107 : 64 : if (ret == NULL_RTX)
12108 : : break;
12109 : : }
12110 : :
12111 : 31 : return expand_expr (fold (value), target, tmode,
12112 : 31 : modifier);
12113 : : }
12114 : : }
12115 : 1 : else if (TREE_CODE (init) == STRING_CST)
12116 : : {
12117 : 1 : tree low_bound = array_ref_low_bound (exp);
12118 : 1 : tree index1 = fold_convert_loc (loc, sizetype, treeop1);
12119 : :
12120 : : /* Optimize the special case of a zero lower bound.
12121 : :
12122 : : We convert the lower bound to sizetype to avoid problems
12123 : : with constant folding. E.g. suppose the lower bound is
12124 : : 1 and its mode is QI. Without the conversion
12125 : : (ARRAY + (INDEX - (unsigned char)1))
12126 : : becomes
12127 : : (ARRAY + (-(unsigned char)1) + INDEX)
12128 : : which becomes
12129 : : (ARRAY + 255 + INDEX). Oops! */
12130 : 1 : if (!integer_zerop (low_bound))
12131 : 0 : index1 = size_diffop_loc (loc, index1,
12132 : : fold_convert_loc (loc, sizetype,
12133 : : low_bound));
12134 : :
12135 : 1 : if (tree_fits_uhwi_p (index1)
12136 : 2 : && compare_tree_int (index1, TREE_STRING_LENGTH (init)) < 0)
12137 : : {
12138 : 0 : tree char_type = TREE_TYPE (TREE_TYPE (init));
12139 : 0 : scalar_int_mode char_mode;
12140 : :
12141 : 613629 : if (is_int_mode (TYPE_MODE (char_type), &char_mode)
12142 : 0 : && GET_MODE_SIZE (char_mode) == 1)
12143 : 0 : return gen_int_mode (TREE_STRING_POINTER (init)
12144 : 0 : [TREE_INT_CST_LOW (index1)],
12145 : : char_mode);
12146 : : }
12147 : : }
12148 : : }
12149 : : }
12150 : 613629 : goto normal_inner_ref;
12151 : :
12152 : 3788260 : case COMPONENT_REF:
12153 : 3788260 : gcc_assert (TREE_CODE (treeop0) != CONSTRUCTOR);
12154 : : /* Fall through. */
12155 : 4663901 : case BIT_FIELD_REF:
12156 : 4663901 : case ARRAY_RANGE_REF:
12157 : 3788260 : normal_inner_ref:
12158 : 4663901 : {
12159 : 4663901 : machine_mode mode1, mode2;
12160 : 4663901 : poly_int64 bitsize, bitpos, bytepos;
12161 : 4663901 : tree offset;
12162 : 4663901 : int reversep, volatilep = 0;
12163 : 4663901 : tree tem
12164 : 4663901 : = get_inner_reference (exp, &bitsize, &bitpos, &offset, &mode1,
12165 : : &unsignedp, &reversep, &volatilep);
12166 : 4663901 : rtx orig_op0, memloc;
12167 : 4663901 : bool clear_mem_expr = false;
12168 : 4663901 : bool must_force_mem;
12169 : :
12170 : : /* If we got back the original object, something is wrong. Perhaps
12171 : : we are evaluating an expression too early. In any event, don't
12172 : : infinitely recurse. */
12173 : 4663901 : gcc_assert (tem != exp);
12174 : :
12175 : : /* Make sure bitpos is not negative, this can wreak havoc later. */
12176 : 4663901 : if (maybe_lt (bitpos, 0))
12177 : : {
12178 : 247 : gcc_checking_assert (offset == NULL_TREE);
12179 : 247 : offset = size_int (bits_to_bytes_round_down (bitpos));
12180 : 247 : bitpos = num_trailing_bits (bitpos);
12181 : : }
12182 : :
12183 : : /* If we have either an offset, a BLKmode result, or a reference
12184 : : outside the underlying object, we must force it to memory.
12185 : : Such a case can occur in Ada if we have unchecked conversion
12186 : : of an expression from a scalar type to an aggregate type or
12187 : : for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
12188 : : passed a partially uninitialized object or a view-conversion
12189 : : to a larger size. */
12190 : 9327802 : must_force_mem = offset != NULL_TREE
12191 : 4383835 : || mode1 == BLKmode
12192 : 8975012 : || (mode == BLKmode
12193 : 0 : && !int_mode_for_size (bitsize, 1).exists ());
12194 : :
12195 : 543037 : const enum expand_modifier tem_modifier
12196 : : = must_force_mem
12197 : : ? EXPAND_MEMORY
12198 : 4311111 : : modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier;
12199 : :
12200 : : /* If TEM's type is a union of variable size, pass TARGET to the inner
12201 : : computation, since it will need a temporary and TARGET is known
12202 : : to have to do. This occurs in unchecked conversion in Ada. */
12203 : 4663901 : const rtx tem_target
12204 : 4663901 : = TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
12205 : 36409 : && COMPLETE_TYPE_P (TREE_TYPE (tem))
12206 : 36404 : && TREE_CODE (TYPE_SIZE (TREE_TYPE (tem))) != INTEGER_CST
12207 : 0 : && modifier != EXPAND_STACK_PARM
12208 : 4663901 : ? target
12209 : : : NULL_RTX;
12210 : :
12211 : 9327802 : orig_op0 = op0
12212 : 4663901 : = expand_expr_real (tem, tem_target, VOIDmode, tem_modifier, NULL,
12213 : : true);
12214 : :
12215 : : /* If the field has a mode, we want to access it in the
12216 : : field's mode, not the computed mode.
12217 : : If a MEM has VOIDmode (external with incomplete type),
12218 : : use BLKmode for it instead. */
12219 : 4663901 : if (MEM_P (op0))
12220 : : {
12221 : 4320837 : if (mode1 != VOIDmode)
12222 : 4149443 : op0 = adjust_address (op0, mode1, 0);
12223 : 171394 : else if (GET_MODE (op0) == VOIDmode)
12224 : 0 : op0 = adjust_address (op0, BLKmode, 0);
12225 : : }
12226 : :
12227 : 4663901 : mode2
12228 : 4663901 : = CONSTANT_P (op0) ? TYPE_MODE (TREE_TYPE (tem)) : GET_MODE (op0);
12229 : :
12230 : : /* See above for the rationale. */
12231 : 9327802 : if (maybe_gt (bitpos + bitsize, GET_MODE_BITSIZE (mode2)))
12232 : 2923389 : must_force_mem = true;
12233 : :
12234 : : /* Handle CONCAT first. */
12235 : 4663901 : if (GET_CODE (op0) == CONCAT && !must_force_mem)
12236 : : {
12237 : 126 : if (known_eq (bitpos, 0)
12238 : 230 : && known_eq (bitsize, GET_MODE_BITSIZE (GET_MODE (op0)))
12239 : 110 : && COMPLEX_MODE_P (mode1)
12240 : 105 : && COMPLEX_MODE_P (GET_MODE (op0))
12241 : 441 : && (GET_MODE_PRECISION (GET_MODE_INNER (mode1))
12242 : 210 : == GET_MODE_PRECISION (GET_MODE_INNER (GET_MODE (op0)))))
12243 : : {
12244 : 105 : if (reversep)
12245 : 0 : op0 = flip_storage_order (GET_MODE (op0), op0);
12246 : 105 : if (mode1 != GET_MODE (op0))
12247 : : {
12248 : : rtx parts[2];
12249 : 0 : for (int i = 0; i < 2; i++)
12250 : : {
12251 : 0 : rtx op = read_complex_part (op0, i != 0);
12252 : 0 : if (GET_CODE (op) == SUBREG)
12253 : 0 : op = force_reg (GET_MODE (op), op);
12254 : 0 : temp = gen_lowpart_common (GET_MODE_INNER (mode1), op);
12255 : 0 : if (temp)
12256 : : op = temp;
12257 : : else
12258 : : {
12259 : 0 : if (!REG_P (op) && !MEM_P (op))
12260 : 0 : op = force_reg (GET_MODE (op), op);
12261 : 0 : op = gen_lowpart (GET_MODE_INNER (mode1), op);
12262 : : }
12263 : 0 : parts[i] = op;
12264 : : }
12265 : 0 : op0 = gen_rtx_CONCAT (mode1, parts[0], parts[1]);
12266 : : }
12267 : 105 : return op0;
12268 : : }
12269 : 21 : if (known_eq (bitpos, 0)
12270 : 20 : && known_eq (bitsize,
12271 : : GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0))))
12272 : 23 : && maybe_ne (bitsize, 0))
12273 : : {
12274 : : op0 = XEXP (op0, 0);
12275 : : mode2 = GET_MODE (op0);
12276 : : }
12277 : 19 : else if (known_eq (bitpos,
12278 : : GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0))))
12279 : 4 : && known_eq (bitsize,
12280 : : GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 1))))
12281 : 0 : && maybe_ne (bitpos, 0)
12282 : 19 : && maybe_ne (bitsize, 0))
12283 : : {
12284 : 0 : op0 = XEXP (op0, 1);
12285 : 0 : bitpos = 0;
12286 : 0 : mode2 = GET_MODE (op0);
12287 : : }
12288 : : else
12289 : : /* Otherwise force into memory. */
12290 : : must_force_mem = true;
12291 : : }
12292 : :
12293 : : /* If this is a constant, put it in a register if it is a legitimate
12294 : : constant and we don't need a memory reference. */
12295 : 4663796 : if (CONSTANT_P (op0)
12296 : 25 : && mode2 != BLKmode
12297 : 25 : && targetm.legitimate_constant_p (mode2, op0)
12298 : 4663809 : && !must_force_mem)
12299 : 13 : op0 = force_reg (mode2, op0);
12300 : :
12301 : : /* Otherwise, if this is a constant, try to force it to the constant
12302 : : pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
12303 : : is a legitimate constant. */
12304 : 4663783 : else if (CONSTANT_P (op0) && (memloc = force_const_mem (mode2, op0)))
12305 : 12 : op0 = validize_mem (memloc);
12306 : :
12307 : : /* Otherwise, if this is a constant or the object is not in memory
12308 : : and need be, put it there. */
12309 : 4663771 : else if (CONSTANT_P (op0) || (!MEM_P (op0) && must_force_mem))
12310 : : {
12311 : 1216 : poly_int64 size;
12312 : 1216 : if (!poly_int_tree_p (TYPE_SIZE_UNIT (TREE_TYPE (tem)), &size))
12313 : 0 : size = max_int_size_in_bytes (TREE_TYPE (tem));
12314 : 1216 : memloc = assign_stack_local (TYPE_MODE (TREE_TYPE (tem)), size,
12315 : 1216 : TREE_CODE (tem) == SSA_NAME
12316 : 9 : ? TYPE_ALIGN (TREE_TYPE (tem))
12317 : 1207 : : get_object_alignment (tem));
12318 : 1216 : emit_move_insn (memloc, op0);
12319 : 1216 : op0 = memloc;
12320 : 1216 : clear_mem_expr = true;
12321 : : }
12322 : :
12323 : 4663796 : if (offset)
12324 : : {
12325 : 280066 : machine_mode address_mode;
12326 : 280066 : rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode,
12327 : : EXPAND_SUM);
12328 : :
12329 : 280066 : gcc_assert (MEM_P (op0));
12330 : :
12331 : 280066 : address_mode = get_address_mode (op0);
12332 : 280066 : if (GET_MODE (offset_rtx) != address_mode)
12333 : : {
12334 : : /* We cannot be sure that the RTL in offset_rtx is valid outside
12335 : : of a memory address context, so force it into a register
12336 : : before attempting to convert it to the desired mode. */
12337 : 414 : offset_rtx = force_operand (offset_rtx, NULL_RTX);
12338 : 414 : offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
12339 : : }
12340 : :
12341 : : /* See the comment in expand_assignment for the rationale. */
12342 : 280066 : if (mode1 != VOIDmode
12343 : 279832 : && maybe_ne (bitpos, 0)
12344 : 71964 : && maybe_gt (bitsize, 0)
12345 : 352030 : && multiple_p (bitpos, BITS_PER_UNIT, &bytepos)
12346 : 351491 : && multiple_p (bitpos, bitsize)
12347 : 142850 : && multiple_p (bitsize, GET_MODE_ALIGNMENT (mode1))
12348 : 351491 : && MEM_ALIGN (op0) >= GET_MODE_ALIGNMENT (mode1))
12349 : : {
12350 : 71398 : op0 = adjust_address (op0, mode1, bytepos);
12351 : 71398 : bitpos = 0;
12352 : : }
12353 : :
12354 : 280066 : op0 = offset_address (op0, offset_rtx,
12355 : : highest_pow2_factor (offset));
12356 : : }
12357 : :
12358 : : /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
12359 : : record its alignment as BIGGEST_ALIGNMENT. */
12360 : 4663796 : if (MEM_P (op0)
12361 : 4322065 : && known_eq (bitpos, 0)
12362 : 1481523 : && offset != 0
12363 : 4943130 : && is_aligning_offset (offset, tem))
12364 : 0 : set_mem_align (op0, BIGGEST_ALIGNMENT);
12365 : :
12366 : : /* Don't forget about volatility even if this is a bitfield. */
12367 : 4663796 : if (MEM_P (op0) && volatilep && ! MEM_VOLATILE_P (op0))
12368 : : {
12369 : 410 : if (op0 == orig_op0)
12370 : 158 : op0 = copy_rtx (op0);
12371 : :
12372 : 410 : MEM_VOLATILE_P (op0) = 1;
12373 : : }
12374 : :
12375 : 4663796 : if (MEM_P (op0) && TREE_CODE (tem) == FUNCTION_DECL)
12376 : : {
12377 : 6 : if (op0 == orig_op0)
12378 : 0 : op0 = copy_rtx (op0);
12379 : :
12380 : 6 : set_mem_align (op0, BITS_PER_UNIT);
12381 : : }
12382 : :
12383 : : /* In cases where an aligned union has an unaligned object
12384 : : as a field, we might be extracting a BLKmode value from
12385 : : an integer-mode (e.g., SImode) object. Handle this case
12386 : : by doing the extract into an object as wide as the field
12387 : : (which we know to be the width of a basic mode), then
12388 : : storing into memory, and changing the mode to BLKmode. */
12389 : 4663796 : if (mode1 == VOIDmode
12390 : 4412546 : || REG_P (op0) || GET_CODE (op0) == SUBREG
12391 : 4150637 : || (mode1 != BLKmode && ! direct_load[(int) mode1]
12392 : 26592 : && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
12393 : 22442 : && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT
12394 : : && modifier != EXPAND_CONST_ADDRESS
12395 : 15371 : && modifier != EXPAND_INITIALIZER
12396 : 15371 : && modifier != EXPAND_MEMORY)
12397 : : /* If the bitfield is volatile and the bitsize
12398 : : is narrower than the access size of the bitfield,
12399 : : we need to extract bitfields from the access. */
12400 : 4135266 : || (volatilep && TREE_CODE (exp) == COMPONENT_REF
12401 : 1277 : && DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1))
12402 : 10 : && mode1 != BLKmode
12403 : 20 : && maybe_lt (bitsize, GET_MODE_SIZE (mode1) * BITS_PER_UNIT))
12404 : : /* If the field isn't aligned enough to fetch as a memref,
12405 : : fetch it as a bit field. */
12406 : 4135257 : || (mode1 != BLKmode
12407 : 4061698 : && (((MEM_P (op0)
12408 : 4061698 : ? MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode1)
12409 : 7979451 : || !multiple_p (bitpos, GET_MODE_ALIGNMENT (mode1))
12410 : 0 : : TYPE_ALIGN (TREE_TYPE (tem)) < GET_MODE_ALIGNMENT (mode)
12411 : 0 : || !multiple_p (bitpos, GET_MODE_ALIGNMENT (mode)))
12412 : 75289 : && modifier != EXPAND_MEMORY
12413 : 75289 : && ((modifier == EXPAND_CONST_ADDRESS
12414 : 75289 : || modifier == EXPAND_INITIALIZER)
12415 : 75289 : ? STRICT_ALIGNMENT
12416 : 75289 : : targetm.slow_unaligned_access (mode1,
12417 : 75289 : MEM_ALIGN (op0))))
12418 : 4061698 : || !multiple_p (bitpos, BITS_PER_UNIT)))
12419 : : /* If the type and the field are a constant size and the
12420 : : size of the type isn't the same size as the bitfield,
12421 : : we must use bitfield operations. */
12422 : 12860751 : || (known_size_p (bitsize)
12423 : 4135257 : && TYPE_SIZE (TREE_TYPE (exp))
12424 : 4135257 : && poly_int_tree_p (TYPE_SIZE (TREE_TYPE (exp)))
12425 : 4135257 : && maybe_ne (wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (exp))),
12426 : : bitsize)))
12427 : : {
12428 : 528568 : machine_mode ext_mode = mode;
12429 : :
12430 : 528568 : if (ext_mode == BLKmode
12431 : 528568 : && ! (target != 0 && MEM_P (op0)
12432 : 22 : && MEM_P (target)
12433 : 22 : && multiple_p (bitpos, BITS_PER_UNIT)))
12434 : 3 : ext_mode = int_mode_for_size (bitsize, 1).else_blk ();
12435 : :
12436 : 528568 : if (ext_mode == BLKmode)
12437 : : {
12438 : 25 : if (target == 0)
12439 : 3 : target = assign_temp (type, 1, 1);
12440 : :
12441 : : /* ??? Unlike the similar test a few lines below, this one is
12442 : : very likely obsolete. */
12443 : 25 : if (known_eq (bitsize, 0))
12444 : : return target;
12445 : :
12446 : : /* In this case, BITPOS must start at a byte boundary and
12447 : : TARGET, if specified, must be a MEM. */
12448 : 25 : gcc_assert (MEM_P (op0)
12449 : : && (!target || MEM_P (target)));
12450 : :
12451 : 25 : bytepos = exact_div (bitpos, BITS_PER_UNIT);
12452 : 25 : poly_int64 bytesize = bits_to_bytes_round_up (bitsize);
12453 : 50 : emit_block_move (target,
12454 : : adjust_address (op0, VOIDmode, bytepos),
12455 : 25 : gen_int_mode (bytesize, Pmode),
12456 : : (modifier == EXPAND_STACK_PARM
12457 : : ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
12458 : :
12459 : 25 : return target;
12460 : : }
12461 : :
12462 : : /* If we have nothing to extract, the result will be 0 for targets
12463 : : with SHIFT_COUNT_TRUNCATED == 0 and garbage otherwise. Always
12464 : : return 0 for the sake of consistency, as reading a zero-sized
12465 : : bitfield is valid in Ada and the value is fully specified. */
12466 : 528543 : if (known_eq (bitsize, 0))
12467 : 0 : return const0_rtx;
12468 : :
12469 : 528543 : op0 = validize_mem (op0);
12470 : :
12471 : 528543 : if (MEM_P (op0) && REG_P (XEXP (op0, 0)))
12472 : 63171 : mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
12473 : :
12474 : : /* If the result has aggregate type and the extraction is done in
12475 : : an integral mode, then the field may be not aligned on a byte
12476 : : boundary; in this case, if it has reverse storage order, it
12477 : : needs to be extracted as a scalar field with reverse storage
12478 : : order and put back into memory order afterwards. */
12479 : 528543 : if (AGGREGATE_TYPE_P (type)
12480 : 5542 : && GET_MODE_CLASS (ext_mode) == MODE_INT)
12481 : 5458 : reversep = TYPE_REVERSE_STORAGE_ORDER (type);
12482 : :
12483 : 528543 : gcc_checking_assert (known_ge (bitpos, 0));
12484 : 541339 : op0 = extract_bit_field (op0, bitsize, bitpos, unsignedp,
12485 : : (modifier == EXPAND_STACK_PARM
12486 : : ? NULL_RTX : target),
12487 : : ext_mode, ext_mode, reversep, alt_rtl);
12488 : :
12489 : : /* If the result has aggregate type and the mode of OP0 is an
12490 : : integral mode then, if BITSIZE is narrower than this mode
12491 : : and this is for big-endian data, we must put the field
12492 : : into the high-order bits. And we must also put it back
12493 : : into memory order if it has been previously reversed. */
12494 : 528543 : scalar_int_mode op0_mode;
12495 : 528543 : if (AGGREGATE_TYPE_P (type)
12496 : 528543 : && is_int_mode (GET_MODE (op0), &op0_mode))
12497 : : {
12498 : 5458 : HOST_WIDE_INT size = GET_MODE_BITSIZE (op0_mode);
12499 : :
12500 : 5458 : gcc_checking_assert (known_le (bitsize, size));
12501 : 5458 : if (maybe_lt (bitsize, size)
12502 : 5458 : && reversep ? !BYTES_BIG_ENDIAN : BYTES_BIG_ENDIAN)
12503 : 0 : op0 = expand_shift (LSHIFT_EXPR, op0_mode, op0,
12504 : : size - bitsize, op0, 1);
12505 : :
12506 : 5458 : if (reversep)
12507 : 0 : op0 = flip_storage_order (op0_mode, op0);
12508 : : }
12509 : :
12510 : : /* If the result type is BLKmode, store the data into a temporary
12511 : : of the appropriate type, but with the mode corresponding to the
12512 : : mode for the data we have (op0's mode). */
12513 : 528543 : if (mode == BLKmode)
12514 : : {
12515 : 0 : rtx new_rtx
12516 : 0 : = assign_stack_temp_for_type (ext_mode,
12517 : 0 : GET_MODE_BITSIZE (ext_mode),
12518 : : type);
12519 : 0 : emit_move_insn (new_rtx, op0);
12520 : 0 : op0 = copy_rtx (new_rtx);
12521 : 0 : PUT_MODE (op0, BLKmode);
12522 : : }
12523 : :
12524 : 528543 : return op0;
12525 : : }
12526 : :
12527 : : /* If the result is BLKmode, use that to access the object
12528 : : now as well. */
12529 : 4135228 : if (mode == BLKmode)
12530 : 73534 : mode1 = BLKmode;
12531 : :
12532 : : /* Get a reference to just this component. */
12533 : 4135228 : bytepos = bits_to_bytes_round_down (bitpos);
12534 : 4135228 : if (modifier == EXPAND_CONST_ADDRESS
12535 : 4135228 : || modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
12536 : 180492 : op0 = adjust_address_nv (op0, mode1, bytepos);
12537 : : else
12538 : 3954736 : op0 = adjust_address (op0, mode1, bytepos);
12539 : :
12540 : 4135228 : if (op0 == orig_op0)
12541 : 140011 : op0 = copy_rtx (op0);
12542 : :
12543 : : /* Don't set memory attributes if the base expression is
12544 : : SSA_NAME that got expanded as a MEM or a CONSTANT. In that case,
12545 : : we should just honor its original memory attributes. */
12546 : 4135228 : if (!(TREE_CODE (tem) == SSA_NAME
12547 : 8616 : && (MEM_P (orig_op0) || CONSTANT_P (orig_op0))))
12548 : 4126612 : set_mem_attributes (op0, exp, 0);
12549 : :
12550 : 4135228 : if (REG_P (XEXP (op0, 0)))
12551 : 655540 : mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
12552 : :
12553 : : /* If op0 is a temporary because the original expressions was forced
12554 : : to memory, clear MEM_EXPR so that the original expression cannot
12555 : : be marked as addressable through MEM_EXPR of the temporary. */
12556 : 4135228 : if (clear_mem_expr)
12557 : 1182 : set_mem_expr (op0, NULL_TREE);
12558 : :
12559 : 4135228 : MEM_VOLATILE_P (op0) |= volatilep;
12560 : :
12561 : 4135228 : if (reversep
12562 : : && modifier != EXPAND_MEMORY
12563 : 483 : && modifier != EXPAND_WRITE)
12564 : 483 : op0 = flip_storage_order (mode1, op0);
12565 : :
12566 : 4135228 : op0 = EXTEND_BITINT (op0);
12567 : :
12568 : 4135228 : if (mode == mode1 || mode1 == BLKmode || mode1 == tmode
12569 : : || modifier == EXPAND_CONST_ADDRESS
12570 : 0 : || modifier == EXPAND_INITIALIZER)
12571 : : return op0;
12572 : :
12573 : 0 : if (target == 0)
12574 : 0 : target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
12575 : :
12576 : 0 : convert_move (target, op0, unsignedp);
12577 : 0 : return target;
12578 : : }
12579 : :
12580 : 74128 : case OBJ_TYPE_REF:
12581 : 74128 : return expand_expr (OBJ_TYPE_REF_EXPR (exp), target, tmode, modifier);
12582 : :
12583 : 6699381 : case CALL_EXPR:
12584 : : /* All valid uses of __builtin_va_arg_pack () are removed during
12585 : : inlining. */
12586 : 6699381 : if (CALL_EXPR_VA_ARG_PACK (exp))
12587 : 6 : error ("invalid use of %<__builtin_va_arg_pack ()%>");
12588 : 6699381 : {
12589 : 6699381 : tree fndecl = get_callee_fndecl (exp), attr;
12590 : :
12591 : 6699381 : if (fndecl
12592 : : /* Don't diagnose the error attribute in thunks, those are
12593 : : artificially created. */
12594 : 6507600 : && !CALL_FROM_THUNK_P (exp)
12595 : 13203063 : && (attr = lookup_attribute ("error",
12596 : 6503682 : DECL_ATTRIBUTES (fndecl))) != NULL)
12597 : : {
12598 : 5 : const char *ident = lang_hooks.decl_printable_name (fndecl, 1);
12599 : 10 : error ("call to %qs declared with attribute error: %s",
12600 : : identifier_to_locale (ident),
12601 : 5 : TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12602 : : }
12603 : 6699381 : if (fndecl
12604 : : /* Don't diagnose the warning attribute in thunks, those are
12605 : : artificially created. */
12606 : 6507600 : && !CALL_FROM_THUNK_P (exp)
12607 : 13203063 : && (attr = lookup_attribute ("warning",
12608 : 6503682 : DECL_ATTRIBUTES (fndecl))) != NULL)
12609 : : {
12610 : 17 : const char *ident = lang_hooks.decl_printable_name (fndecl, 1);
12611 : 34 : warning_at (EXPR_LOCATION (exp),
12612 : 17 : OPT_Wattribute_warning,
12613 : : "call to %qs declared with attribute warning: %s",
12614 : : identifier_to_locale (ident),
12615 : 17 : TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12616 : : }
12617 : :
12618 : : /* Check for a built-in function. */
12619 : 6699381 : if (fndecl && fndecl_built_in_p (fndecl))
12620 : : {
12621 : 1983799 : gcc_assert (DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_FRONTEND);
12622 : 1983799 : return expand_builtin (exp, target, subtarget, tmode, ignore);
12623 : : }
12624 : : }
12625 : 4715582 : temp = expand_call (exp, target, ignore);
12626 : 4715582 : return EXTEND_BITINT (temp);
12627 : :
12628 : 338061 : case VIEW_CONVERT_EXPR:
12629 : 338061 : op0 = NULL_RTX;
12630 : :
12631 : : /* If we are converting to BLKmode, try to avoid an intermediate
12632 : : temporary by fetching an inner memory reference. */
12633 : 338061 : if (mode == BLKmode
12634 : 74139 : && poly_int_tree_p (TYPE_SIZE (type))
12635 : 74139 : && TYPE_MODE (TREE_TYPE (treeop0)) != BLKmode
12636 : 338061 : && handled_component_p (treeop0))
12637 : : {
12638 : 0 : machine_mode mode1;
12639 : 0 : poly_int64 bitsize, bitpos, bytepos;
12640 : 0 : tree offset;
12641 : 0 : int reversep, volatilep = 0;
12642 : 0 : tree tem
12643 : 0 : = get_inner_reference (treeop0, &bitsize, &bitpos, &offset, &mode1,
12644 : : &unsignedp, &reversep, &volatilep);
12645 : :
12646 : : /* ??? We should work harder and deal with non-zero offsets. */
12647 : 0 : if (!offset
12648 : 0 : && multiple_p (bitpos, BITS_PER_UNIT, &bytepos)
12649 : 0 : && !reversep
12650 : 0 : && known_size_p (bitsize)
12651 : 0 : && known_eq (wi::to_poly_offset (TYPE_SIZE (type)), bitsize))
12652 : : {
12653 : : /* See the normal_inner_ref case for the rationale. */
12654 : 0 : rtx orig_op0
12655 : 0 : = expand_expr_real (tem,
12656 : 0 : (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
12657 : 0 : && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
12658 : : != INTEGER_CST)
12659 : 0 : && modifier != EXPAND_STACK_PARM
12660 : : ? target : NULL_RTX),
12661 : : VOIDmode,
12662 : : modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier,
12663 : : NULL, true);
12664 : :
12665 : 0 : if (MEM_P (orig_op0))
12666 : : {
12667 : 0 : op0 = orig_op0;
12668 : :
12669 : : /* Get a reference to just this component. */
12670 : 0 : if (modifier == EXPAND_CONST_ADDRESS
12671 : : || modifier == EXPAND_SUM
12672 : 0 : || modifier == EXPAND_INITIALIZER)
12673 : 0 : op0 = adjust_address_nv (op0, mode, bytepos);
12674 : : else
12675 : 0 : op0 = adjust_address (op0, mode, bytepos);
12676 : :
12677 : 0 : if (op0 == orig_op0)
12678 : 0 : op0 = copy_rtx (op0);
12679 : :
12680 : 0 : set_mem_attributes (op0, treeop0, 0);
12681 : 0 : if (REG_P (XEXP (op0, 0)))
12682 : 0 : mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
12683 : :
12684 : 0 : MEM_VOLATILE_P (op0) |= volatilep;
12685 : : }
12686 : : }
12687 : : }
12688 : :
12689 : 0 : if (!op0)
12690 : 338061 : op0 = expand_expr_real (treeop0, NULL_RTX, VOIDmode, modifier,
12691 : 338061 : NULL, inner_reference_p || mode == BLKmode);
12692 : :
12693 : : /* If the input and output modes are both the same, we are done. */
12694 : 338061 : if (mode == GET_MODE (op0))
12695 : : ;
12696 : : /* Similarly if the output mode is BLKmode and input is a MEM,
12697 : : adjust_address done below is all we need. */
12698 : 144924 : else if (mode == BLKmode && MEM_P (op0))
12699 : : ;
12700 : : /* If neither mode is BLKmode, and both modes are the same size
12701 : : then we can use gen_lowpart. */
12702 : : else if (mode != BLKmode
12703 : 144891 : && GET_MODE (op0) != BLKmode
12704 : 143568 : && known_eq (GET_MODE_PRECISION (mode),
12705 : : GET_MODE_PRECISION (GET_MODE (op0)))
12706 : 139676 : && !COMPLEX_MODE_P (GET_MODE (op0)))
12707 : : {
12708 : 138275 : if (GET_CODE (op0) == SUBREG)
12709 : 99 : op0 = force_reg (GET_MODE (op0), op0);
12710 : 138275 : temp = gen_lowpart_common (mode, op0);
12711 : 138275 : if (temp)
12712 : : op0 = temp;
12713 : : else
12714 : : {
12715 : 27309 : if (!REG_P (op0) && !MEM_P (op0))
12716 : 18 : op0 = force_reg (GET_MODE (op0), op0);
12717 : 27309 : op0 = gen_lowpart (mode, op0);
12718 : : }
12719 : : }
12720 : : /* If both types are integral, convert from one mode to the other. */
12721 : 6647 : else if (INTEGRAL_TYPE_P (type)
12722 : 3140 : && INTEGRAL_TYPE_P (TREE_TYPE (treeop0))
12723 : 0 : && mode != BLKmode
12724 : 6647 : && GET_MODE (op0) != BLKmode)
12725 : 0 : op0 = convert_modes (mode, GET_MODE (op0), op0,
12726 : 0 : TYPE_UNSIGNED (TREE_TYPE (treeop0)));
12727 : : /* If the output type is a bit-field type, do an extraction. */
12728 : 6647 : else if (reduce_bit_field
12729 : 1 : && mode != BLKmode
12730 : 1 : && (MEM_P (op0) || !COMPLEX_MODE_P (GET_MODE (op0))))
12731 : 0 : return extract_bit_field (op0, TYPE_PRECISION (type), 0,
12732 : 0 : TYPE_UNSIGNED (type), NULL_RTX,
12733 : : mode, mode, false, NULL);
12734 : : /* As a last resort, spill op0 to memory, and reload it in a
12735 : : different mode. */
12736 : 6647 : else if (!MEM_P (op0))
12737 : : {
12738 : : /* If the operand is not a MEM, force it into memory. Since we
12739 : : are going to be changing the mode of the MEM, don't call
12740 : : force_const_mem for constants because we don't allow pool
12741 : : constants to change mode. */
12742 : 5319 : tree inner_type = TREE_TYPE (treeop0);
12743 : :
12744 : 5319 : gcc_assert (!TREE_ADDRESSABLE (exp));
12745 : :
12746 : 5319 : if (target == 0 || GET_MODE (target) != TYPE_MODE (inner_type))
12747 : 5313 : target
12748 : : = assign_stack_temp_for_type
12749 : 5313 : (TYPE_MODE (inner_type),
12750 : 10626 : GET_MODE_SIZE (TYPE_MODE (inner_type)), inner_type);
12751 : :
12752 : 5319 : emit_move_insn (target, op0);
12753 : 5319 : op0 = target;
12754 : :
12755 : 5319 : if (reduce_bit_field && mode != BLKmode)
12756 : 1 : return extract_bit_field (op0, TYPE_PRECISION (type), 0,
12757 : 1 : TYPE_UNSIGNED (type), NULL_RTX,
12758 : : mode, mode, false, NULL);
12759 : : }
12760 : :
12761 : : /* If OP0 is (now) a MEM, we need to deal with alignment issues. If the
12762 : : output type is such that the operand is known to be aligned, indicate
12763 : : that it is. Otherwise, we need only be concerned about alignment for
12764 : : non-BLKmode results. */
12765 : 338060 : if (MEM_P (op0))
12766 : : {
12767 : 127200 : enum insn_code icode;
12768 : :
12769 : 127200 : if (modifier != EXPAND_WRITE
12770 : 127200 : && modifier != EXPAND_MEMORY
12771 : 127200 : && !inner_reference_p
12772 : 127200 : && mode != BLKmode
12773 : 180261 : && MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode))
12774 : : {
12775 : : /* If the target does have special handling for unaligned
12776 : : loads of mode then use them. */
12777 : 15789 : if ((icode = optab_handler (movmisalign_optab, mode))
12778 : : != CODE_FOR_nothing)
12779 : : {
12780 : 1918 : rtx reg;
12781 : :
12782 : 1918 : op0 = adjust_address (op0, mode, 0);
12783 : : /* We've already validated the memory, and we're creating a
12784 : : new pseudo destination. The predicates really can't
12785 : : fail. */
12786 : 1918 : reg = gen_reg_rtx (mode);
12787 : :
12788 : : /* Nor can the insn generator. */
12789 : 1918 : rtx_insn *insn = GEN_FCN (icode) (reg, op0);
12790 : 1918 : emit_insn (insn);
12791 : 1918 : return reg;
12792 : : }
12793 : : else if (STRICT_ALIGNMENT)
12794 : : {
12795 : : poly_uint64 mode_size = GET_MODE_SIZE (mode);
12796 : : poly_uint64 temp_size = mode_size;
12797 : : if (GET_MODE (op0) != BLKmode)
12798 : : temp_size = upper_bound (temp_size,
12799 : : GET_MODE_SIZE (GET_MODE (op0)));
12800 : : rtx new_rtx
12801 : : = assign_stack_temp_for_type (mode, temp_size, type);
12802 : : rtx new_with_op0_mode
12803 : : = adjust_address (new_rtx, GET_MODE (op0), 0);
12804 : :
12805 : : gcc_assert (!TREE_ADDRESSABLE (exp));
12806 : :
12807 : : if (GET_MODE (op0) == BLKmode)
12808 : : {
12809 : : rtx size_rtx = gen_int_mode (mode_size, Pmode);
12810 : : emit_block_move (new_with_op0_mode, op0, size_rtx,
12811 : : (modifier == EXPAND_STACK_PARM
12812 : : ? BLOCK_OP_CALL_PARM
12813 : : : BLOCK_OP_NORMAL));
12814 : : }
12815 : : else
12816 : : emit_move_insn (new_with_op0_mode, op0);
12817 : :
12818 : : op0 = new_rtx;
12819 : : }
12820 : : }
12821 : :
12822 : 125282 : op0 = adjust_address (op0, mode, 0);
12823 : : }
12824 : :
12825 : : return op0;
12826 : :
12827 : 62803 : case MODIFY_EXPR:
12828 : 62803 : {
12829 : 62803 : tree lhs = treeop0;
12830 : 62803 : tree rhs = treeop1;
12831 : 62803 : gcc_assert (ignore);
12832 : :
12833 : : /* Check for |= or &= of a bitfield of size one into another bitfield
12834 : : of size 1. In this case, (unless we need the result of the
12835 : : assignment) we can do this more efficiently with a
12836 : : test followed by an assignment, if necessary.
12837 : :
12838 : : ??? At this point, we can't get a BIT_FIELD_REF here. But if
12839 : : things change so we do, this code should be enhanced to
12840 : : support it. */
12841 : 62803 : if (TREE_CODE (lhs) == COMPONENT_REF
12842 : 59829 : && (TREE_CODE (rhs) == BIT_IOR_EXPR
12843 : 59829 : || TREE_CODE (rhs) == BIT_AND_EXPR)
12844 : 0 : && TREE_OPERAND (rhs, 0) == lhs
12845 : 0 : && TREE_CODE (TREE_OPERAND (rhs, 1)) == COMPONENT_REF
12846 : 0 : && integer_onep (DECL_SIZE (TREE_OPERAND (lhs, 1)))
12847 : 62803 : && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs, 1), 1))))
12848 : : {
12849 : 0 : rtx_code_label *label = gen_label_rtx ();
12850 : 0 : int value = TREE_CODE (rhs) == BIT_IOR_EXPR;
12851 : 0 : profile_probability prob = profile_probability::uninitialized ();
12852 : 0 : if (value)
12853 : 0 : jumpifnot (TREE_OPERAND (rhs, 1), label, prob);
12854 : : else
12855 : 0 : jumpif (TREE_OPERAND (rhs, 1), label, prob);
12856 : 0 : expand_assignment (lhs, build_int_cst (TREE_TYPE (rhs), value),
12857 : : false);
12858 : 0 : do_pending_stack_adjust ();
12859 : 0 : emit_label (label);
12860 : 0 : return const0_rtx;
12861 : : }
12862 : :
12863 : 62803 : expand_assignment (lhs, rhs, false);
12864 : 62803 : return const0_rtx;
12865 : : }
12866 : :
12867 : 13024533 : case ADDR_EXPR:
12868 : 13024533 : return expand_expr_addr_expr (exp, target, tmode, modifier);
12869 : :
12870 : 154183 : case REALPART_EXPR:
12871 : 154183 : op0 = expand_normal (treeop0);
12872 : 154183 : return read_complex_part (op0, false);
12873 : :
12874 : 178071 : case IMAGPART_EXPR:
12875 : 178071 : op0 = expand_normal (treeop0);
12876 : 178071 : return read_complex_part (op0, true);
12877 : :
12878 : 0 : case RETURN_EXPR:
12879 : 0 : case LABEL_EXPR:
12880 : 0 : case GOTO_EXPR:
12881 : 0 : case SWITCH_EXPR:
12882 : 0 : case ASM_EXPR:
12883 : : /* Expanded in cfgexpand.cc. */
12884 : 0 : gcc_unreachable ();
12885 : :
12886 : 0 : case TRY_CATCH_EXPR:
12887 : 0 : case CATCH_EXPR:
12888 : 0 : case EH_FILTER_EXPR:
12889 : 0 : case TRY_FINALLY_EXPR:
12890 : 0 : case EH_ELSE_EXPR:
12891 : : /* Lowered by tree-eh.cc. */
12892 : 0 : gcc_unreachable ();
12893 : :
12894 : 0 : case WITH_CLEANUP_EXPR:
12895 : 0 : case CLEANUP_POINT_EXPR:
12896 : 0 : case TARGET_EXPR:
12897 : 0 : case CASE_LABEL_EXPR:
12898 : 0 : case VA_ARG_EXPR:
12899 : 0 : case BIND_EXPR:
12900 : 0 : case INIT_EXPR:
12901 : 0 : case CONJ_EXPR:
12902 : 0 : case COMPOUND_EXPR:
12903 : 0 : case PREINCREMENT_EXPR:
12904 : 0 : case PREDECREMENT_EXPR:
12905 : 0 : case POSTINCREMENT_EXPR:
12906 : 0 : case POSTDECREMENT_EXPR:
12907 : 0 : case LOOP_EXPR:
12908 : 0 : case EXIT_EXPR:
12909 : 0 : case COMPOUND_LITERAL_EXPR:
12910 : : /* Lowered by gimplify.cc. */
12911 : 0 : gcc_unreachable ();
12912 : :
12913 : 0 : case FDESC_EXPR:
12914 : : /* Function descriptors are not valid except for as
12915 : : initialization constants, and should not be expanded. */
12916 : 0 : gcc_unreachable ();
12917 : :
12918 : 256 : case WITH_SIZE_EXPR:
12919 : : /* WITH_SIZE_EXPR expands to its first argument. The caller should
12920 : : have pulled out the size to use in whatever context it needed. */
12921 : 256 : return expand_expr_real (treeop0, original_target, tmode,
12922 : 256 : modifier, alt_rtl, inner_reference_p);
12923 : :
12924 : 1845559 : default:
12925 : 1845559 : return expand_expr_real_2 (&ops, target, tmode, modifier);
12926 : : }
12927 : : }
12928 : : #undef EXTEND_BITINT
12929 : :
12930 : : /* Subroutine of above: reduce EXP to the precision of TYPE (in the
12931 : : signedness of TYPE), possibly returning the result in TARGET.
12932 : : TYPE is known to be a partial integer type. */
12933 : : static rtx
12934 : 86997 : reduce_to_bit_field_precision (rtx exp, rtx target, tree type)
12935 : : {
12936 : 86997 : scalar_int_mode mode = SCALAR_INT_TYPE_MODE (type);
12937 : 86997 : HOST_WIDE_INT prec = TYPE_PRECISION (type);
12938 : 86997 : gcc_assert ((GET_MODE (exp) == VOIDmode || GET_MODE (exp) == mode)
12939 : : && (!target || GET_MODE (target) == mode));
12940 : :
12941 : : /* For constant values, reduce using wide_int_to_tree. */
12942 : 86997 : if (poly_int_rtx_p (exp))
12943 : : {
12944 : 2 : auto value = wi::to_poly_wide (exp, mode);
12945 : 2 : tree t = wide_int_to_tree (type, value);
12946 : 2 : return expand_expr (t, target, VOIDmode, EXPAND_NORMAL);
12947 : : }
12948 : 86995 : else if (TYPE_UNSIGNED (type))
12949 : : {
12950 : 68892 : rtx mask = immed_wide_int_const
12951 : 68892 : (wi::mask (prec, false, GET_MODE_PRECISION (mode)), mode);
12952 : 68892 : return expand_and (mode, exp, mask, target);
12953 : : }
12954 : : else
12955 : : {
12956 : 18103 : int count = GET_MODE_PRECISION (mode) - prec;
12957 : 18103 : exp = expand_shift (LSHIFT_EXPR, mode, exp, count, target, 0);
12958 : 18103 : return expand_shift (RSHIFT_EXPR, mode, exp, count, target, 0);
12959 : : }
12960 : : }
12961 : :
12962 : : /* Subroutine of above: returns true if OFFSET corresponds to an offset that
12963 : : when applied to the address of EXP produces an address known to be
12964 : : aligned more than BIGGEST_ALIGNMENT. */
12965 : :
12966 : : static bool
12967 : 279334 : is_aligning_offset (const_tree offset, const_tree exp)
12968 : : {
12969 : : /* Strip off any conversions. */
12970 : 303532 : while (CONVERT_EXPR_P (offset))
12971 : 24198 : offset = TREE_OPERAND (offset, 0);
12972 : :
12973 : : /* We must now have a BIT_AND_EXPR with a constant that is one less than
12974 : : power of 2 and which is larger than BIGGEST_ALIGNMENT. */
12975 : 279334 : if (TREE_CODE (offset) != BIT_AND_EXPR
12976 : 0 : || !tree_fits_uhwi_p (TREE_OPERAND (offset, 1))
12977 : 0 : || compare_tree_int (TREE_OPERAND (offset, 1),
12978 : 0 : BIGGEST_ALIGNMENT / BITS_PER_UNIT) <= 0
12979 : 279334 : || !pow2p_hwi (tree_to_uhwi (TREE_OPERAND (offset, 1)) + 1))
12980 : 279334 : return false;
12981 : :
12982 : : /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
12983 : : It must be NEGATE_EXPR. Then strip any more conversions. */
12984 : 0 : offset = TREE_OPERAND (offset, 0);
12985 : 0 : while (CONVERT_EXPR_P (offset))
12986 : 0 : offset = TREE_OPERAND (offset, 0);
12987 : :
12988 : 0 : if (TREE_CODE (offset) != NEGATE_EXPR)
12989 : : return false;
12990 : :
12991 : 0 : offset = TREE_OPERAND (offset, 0);
12992 : 0 : while (CONVERT_EXPR_P (offset))
12993 : 0 : offset = TREE_OPERAND (offset, 0);
12994 : :
12995 : : /* This must now be the address of EXP. */
12996 : 0 : return TREE_CODE (offset) == ADDR_EXPR && TREE_OPERAND (offset, 0) == exp;
12997 : : }
12998 : :
12999 : : /* Return a STRING_CST corresponding to ARG's constant initializer either
13000 : : if it's a string constant, or, when VALREP is set, any other constant,
13001 : : or null otherwise.
13002 : : On success, set *PTR_OFFSET to the (possibly non-constant) byte offset
13003 : : within the byte string that ARG is references. If nonnull set *MEM_SIZE
13004 : : to the size of the byte string. If nonnull, set *DECL to the constant
13005 : : declaration ARG refers to. */
13006 : :
13007 : : static tree
13008 : 15708538 : constant_byte_string (tree arg, tree *ptr_offset, tree *mem_size, tree *decl,
13009 : : bool valrep = false)
13010 : : {
13011 : 15708538 : tree dummy = NULL_TREE;
13012 : 15708538 : if (!mem_size)
13013 : 10598 : mem_size = &dummy;
13014 : :
13015 : : /* Store the type of the original expression before conversions
13016 : : via NOP_EXPR or POINTER_PLUS_EXPR to other types have been
13017 : : removed. */
13018 : 15708538 : tree argtype = TREE_TYPE (arg);
13019 : :
13020 : 15708538 : tree array;
13021 : 15708538 : STRIP_NOPS (arg);
13022 : :
13023 : : /* Non-constant index into the character array in an ARRAY_REF
13024 : : expression or null. */
13025 : 15708538 : tree varidx = NULL_TREE;
13026 : :
13027 : 15708538 : poly_int64 base_off = 0;
13028 : :
13029 : 15708538 : if (TREE_CODE (arg) == ADDR_EXPR)
13030 : : {
13031 : 6469556 : arg = TREE_OPERAND (arg, 0);
13032 : 6469556 : tree ref = arg;
13033 : 6469556 : if (TREE_CODE (arg) == ARRAY_REF)
13034 : : {
13035 : 548530 : tree idx = TREE_OPERAND (arg, 1);
13036 : 548530 : if (TREE_CODE (idx) != INTEGER_CST)
13037 : : {
13038 : : /* From a pointer (but not array) argument extract the variable
13039 : : index to prevent get_addr_base_and_unit_offset() from failing
13040 : : due to it. Use it later to compute the non-constant offset
13041 : : into the string and return it to the caller. */
13042 : 166572 : varidx = idx;
13043 : 166572 : ref = TREE_OPERAND (arg, 0);
13044 : :
13045 : 166572 : if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE)
13046 : : return NULL_TREE;
13047 : :
13048 : 28000 : if (!integer_zerop (array_ref_low_bound (arg)))
13049 : : return NULL_TREE;
13050 : :
13051 : 27272 : if (!integer_onep (array_ref_element_size (arg)))
13052 : : return NULL_TREE;
13053 : : }
13054 : : }
13055 : 6329116 : array = get_addr_base_and_unit_offset (ref, &base_off);
13056 : 6329116 : if (!array
13057 : 6282035 : || (TREE_CODE (array) != VAR_DECL
13058 : 6282035 : && TREE_CODE (array) != CONST_DECL
13059 : 3966134 : && TREE_CODE (array) != STRING_CST))
13060 : : return NULL_TREE;
13061 : : }
13062 : 9238982 : else if (TREE_CODE (arg) == PLUS_EXPR || TREE_CODE (arg) == POINTER_PLUS_EXPR)
13063 : : {
13064 : 26481 : tree arg0 = TREE_OPERAND (arg, 0);
13065 : 26481 : tree arg1 = TREE_OPERAND (arg, 1);
13066 : :
13067 : 26481 : tree offset;
13068 : 26481 : tree str = string_constant (arg0, &offset, mem_size, decl);
13069 : 26481 : if (!str)
13070 : : {
13071 : 17141 : str = string_constant (arg1, &offset, mem_size, decl);
13072 : 17141 : arg1 = arg0;
13073 : : }
13074 : :
13075 : 17141 : if (str)
13076 : : {
13077 : : /* Avoid pointers to arrays (see bug 86622). */
13078 : 9340 : if (POINTER_TYPE_P (TREE_TYPE (arg))
13079 : 9340 : && TREE_CODE (TREE_TYPE (TREE_TYPE (arg))) == ARRAY_TYPE
13080 : 2100 : && !(decl && !*decl)
13081 : 12140 : && !(decl && tree_fits_uhwi_p (DECL_SIZE_UNIT (*decl))
13082 : 1400 : && tree_fits_uhwi_p (*mem_size)
13083 : 1400 : && tree_int_cst_equal (*mem_size, DECL_SIZE_UNIT (*decl))))
13084 : 2100 : return NULL_TREE;
13085 : :
13086 : 7240 : tree type = TREE_TYPE (offset);
13087 : 7240 : arg1 = fold_convert (type, arg1);
13088 : 7240 : *ptr_offset = fold_build2 (PLUS_EXPR, type, offset, arg1);
13089 : 7240 : return str;
13090 : : }
13091 : : return NULL_TREE;
13092 : : }
13093 : 9212501 : else if (TREE_CODE (arg) == SSA_NAME)
13094 : : {
13095 : 4003404 : gimple *stmt = SSA_NAME_DEF_STMT (arg);
13096 : 4003404 : if (!is_gimple_assign (stmt))
13097 : : return NULL_TREE;
13098 : :
13099 : 1048103 : tree rhs1 = gimple_assign_rhs1 (stmt);
13100 : 1048103 : tree_code code = gimple_assign_rhs_code (stmt);
13101 : 1048103 : if (code == ADDR_EXPR)
13102 : 225434 : return string_constant (rhs1, ptr_offset, mem_size, decl);
13103 : 822669 : else if (code != POINTER_PLUS_EXPR)
13104 : : return NULL_TREE;
13105 : :
13106 : 197252 : tree offset;
13107 : 197252 : if (tree str = string_constant (rhs1, &offset, mem_size, decl))
13108 : : {
13109 : : /* Avoid pointers to arrays (see bug 86622). */
13110 : 22663 : if (POINTER_TYPE_P (TREE_TYPE (rhs1))
13111 : 22663 : && TREE_CODE (TREE_TYPE (TREE_TYPE (rhs1))) == ARRAY_TYPE
13112 : 19882 : && !(decl && !*decl)
13113 : 38869 : && !(decl && tree_fits_uhwi_p (DECL_SIZE_UNIT (*decl))
13114 : 8103 : && tree_fits_uhwi_p (*mem_size)
13115 : 8103 : && tree_int_cst_equal (*mem_size, DECL_SIZE_UNIT (*decl))))
13116 : 16359 : return NULL_TREE;
13117 : :
13118 : 6304 : tree rhs2 = gimple_assign_rhs2 (stmt);
13119 : 6304 : tree type = TREE_TYPE (offset);
13120 : 6304 : rhs2 = fold_convert (type, rhs2);
13121 : 6304 : *ptr_offset = fold_build2 (PLUS_EXPR, type, offset, rhs2);
13122 : 6304 : return str;
13123 : : }
13124 : : return NULL_TREE;
13125 : : }
13126 : 5209097 : else if (DECL_P (arg))
13127 : : array = arg;
13128 : : else
13129 : : return NULL_TREE;
13130 : :
13131 : 8623241 : tree offset = wide_int_to_tree (sizetype, base_off);
13132 : 8623241 : if (varidx)
13133 : : {
13134 : 2147 : if (TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE)
13135 : : return NULL_TREE;
13136 : :
13137 : 1636 : gcc_assert (TREE_CODE (arg) == ARRAY_REF);
13138 : 1636 : tree chartype = TREE_TYPE (TREE_TYPE (TREE_OPERAND (arg, 0)));
13139 : 1636 : if (TREE_CODE (chartype) != INTEGER_TYPE)
13140 : : return NULL;
13141 : :
13142 : 1479 : offset = fold_convert (sizetype, varidx);
13143 : : }
13144 : :
13145 : 8622573 : if (TREE_CODE (array) == STRING_CST)
13146 : : {
13147 : 3573981 : *ptr_offset = fold_convert (sizetype, offset);
13148 : 3573981 : *mem_size = TYPE_SIZE_UNIT (TREE_TYPE (array));
13149 : 3573981 : if (decl)
13150 : 789342 : *decl = NULL_TREE;
13151 : 3573981 : gcc_checking_assert (tree_to_shwi (TYPE_SIZE_UNIT (TREE_TYPE (array)))
13152 : : >= TREE_STRING_LENGTH (array));
13153 : : return array;
13154 : : }
13155 : :
13156 : 5048592 : tree init = ctor_for_folding (array);
13157 : 5048592 : if (!init || init == error_mark_node)
13158 : : return NULL_TREE;
13159 : :
13160 : 154450 : if (valrep)
13161 : : {
13162 : 57258 : HOST_WIDE_INT cstoff;
13163 : 57258 : if (!base_off.is_constant (&cstoff))
13164 : : return NULL_TREE;
13165 : :
13166 : : /* Check that the host and target are sane. */
13167 : 57258 : if (CHAR_BIT != 8 || BITS_PER_UNIT != 8)
13168 : : return NULL_TREE;
13169 : :
13170 : 57258 : HOST_WIDE_INT typesz = int_size_in_bytes (TREE_TYPE (init));
13171 : 57258 : if (typesz <= 0 || (int) typesz != typesz)
13172 : : return NULL_TREE;
13173 : :
13174 : 57088 : HOST_WIDE_INT size = typesz;
13175 : 57088 : if (VAR_P (array)
13176 : 57076 : && DECL_SIZE_UNIT (array)
13177 : 114164 : && tree_fits_shwi_p (DECL_SIZE_UNIT (array)))
13178 : : {
13179 : 57076 : size = tree_to_shwi (DECL_SIZE_UNIT (array));
13180 : 57076 : gcc_checking_assert (size >= typesz);
13181 : : }
13182 : :
13183 : : /* If value representation was requested convert the initializer
13184 : : for the whole array or object into a string of bytes forming
13185 : : its value representation and return it. */
13186 : 57088 : unsigned char *bytes = XNEWVEC (unsigned char, size);
13187 : 57088 : int r = native_encode_initializer (init, bytes, size);
13188 : 57088 : if (r < typesz)
13189 : : {
13190 : 56 : XDELETEVEC (bytes);
13191 : 56 : return NULL_TREE;
13192 : : }
13193 : :
13194 : 57032 : if (r < size)
13195 : 0 : memset (bytes + r, '\0', size - r);
13196 : :
13197 : 57032 : const char *p = reinterpret_cast<const char *>(bytes);
13198 : 57032 : init = build_string_literal (size, p, char_type_node);
13199 : 57032 : init = TREE_OPERAND (init, 0);
13200 : 57032 : init = TREE_OPERAND (init, 0);
13201 : 57032 : XDELETE (bytes);
13202 : :
13203 : 57032 : *mem_size = size_int (TREE_STRING_LENGTH (init));
13204 : 57032 : *ptr_offset = wide_int_to_tree (ssizetype, base_off);
13205 : :
13206 : 57032 : if (decl)
13207 : 0 : *decl = array;
13208 : :
13209 : 57032 : return init;
13210 : : }
13211 : :
13212 : 97192 : if (TREE_CODE (init) == CONSTRUCTOR)
13213 : : {
13214 : : /* Convert the 64-bit constant offset to a wider type to avoid
13215 : : overflow and use it to obtain the initializer for the subobject
13216 : : it points into. */
13217 : 79057 : offset_int wioff;
13218 : 79057 : if (!base_off.is_constant (&wioff))
13219 : 158 : return NULL_TREE;
13220 : :
13221 : 79057 : wioff *= BITS_PER_UNIT;
13222 : 79057 : if (!wi::fits_uhwi_p (wioff))
13223 : : return NULL_TREE;
13224 : :
13225 : 78949 : base_off = wioff.to_uhwi ();
13226 : 78949 : unsigned HOST_WIDE_INT fieldoff = 0;
13227 : 78949 : init = fold_ctor_reference (TREE_TYPE (arg), init, base_off, 0, array,
13228 : : &fieldoff);
13229 : 78949 : if (!init || init == error_mark_node)
13230 : : return NULL_TREE;
13231 : :
13232 : 78899 : HOST_WIDE_INT cstoff;
13233 : 78899 : if (!base_off.is_constant (&cstoff))
13234 : : return NULL_TREE;
13235 : :
13236 : 78899 : cstoff = (cstoff - fieldoff) / BITS_PER_UNIT;
13237 : 78899 : tree off = build_int_cst (sizetype, cstoff);
13238 : 78899 : if (varidx)
13239 : 944 : offset = fold_build2 (PLUS_EXPR, TREE_TYPE (offset), offset, off);
13240 : : else
13241 : : offset = off;
13242 : : }
13243 : :
13244 : 97034 : *ptr_offset = offset;
13245 : :
13246 : 97034 : tree inittype = TREE_TYPE (init);
13247 : :
13248 : 97034 : if (TREE_CODE (init) == INTEGER_CST
13249 : 97034 : && (TREE_CODE (TREE_TYPE (array)) == INTEGER_TYPE
13250 : 907 : || TYPE_MAIN_VARIANT (inittype) == char_type_node))
13251 : : {
13252 : : /* Check that the host and target are sane. */
13253 : 901 : if (CHAR_BIT != 8 || BITS_PER_UNIT != 8)
13254 : : return NULL_TREE;
13255 : :
13256 : : /* For a reference to (address of) a single constant character,
13257 : : store the native representation of the character in CHARBUF.
13258 : : If the reference is to an element of an array or a member
13259 : : of a struct, only consider narrow characters until ctors
13260 : : for wide character arrays are transformed to STRING_CSTs
13261 : : like those for narrow arrays. */
13262 : 901 : unsigned char charbuf[MAX_BITSIZE_MODE_ANY_MODE / BITS_PER_UNIT];
13263 : 901 : int len = native_encode_expr (init, charbuf, sizeof charbuf, 0);
13264 : 901 : if (len > 0)
13265 : : {
13266 : : /* Construct a string literal with elements of INITTYPE and
13267 : : the representation above. Then strip
13268 : : the ADDR_EXPR (ARRAY_REF (...)) around the STRING_CST. */
13269 : 901 : init = build_string_literal (len, (char *)charbuf, inittype);
13270 : 901 : init = TREE_OPERAND (TREE_OPERAND (init, 0), 0);
13271 : : }
13272 : : }
13273 : :
13274 : 97034 : tree initsize = TYPE_SIZE_UNIT (inittype);
13275 : :
13276 : 97034 : if (TREE_CODE (init) == CONSTRUCTOR && initializer_zerop (init))
13277 : : {
13278 : : /* Fold an empty/zero constructor for an implicitly initialized
13279 : : object or subobject into the empty string. */
13280 : :
13281 : : /* Determine the character type from that of the original
13282 : : expression. */
13283 : 9550 : tree chartype = argtype;
13284 : 9550 : if (POINTER_TYPE_P (chartype))
13285 : 9543 : chartype = TREE_TYPE (chartype);
13286 : 15394 : while (TREE_CODE (chartype) == ARRAY_TYPE)
13287 : 5844 : chartype = TREE_TYPE (chartype);
13288 : :
13289 : 9550 : if (INTEGRAL_TYPE_P (chartype)
13290 : 9550 : && TYPE_PRECISION (chartype) == TYPE_PRECISION (char_type_node))
13291 : : {
13292 : : /* Convert a char array to an empty STRING_CST having an array
13293 : : of the expected type and size. */
13294 : 9151 : if (!initsize)
13295 : 3090 : initsize = integer_zero_node;
13296 : 6061 : else if (!tree_fits_uhwi_p (initsize))
13297 : : return NULL_TREE;
13298 : :
13299 : 9145 : unsigned HOST_WIDE_INT size = tree_to_uhwi (initsize);
13300 : 9145 : if (size > (unsigned HOST_WIDE_INT) INT_MAX)
13301 : : return NULL_TREE;
13302 : :
13303 : 9145 : init = build_string_literal (size, NULL, chartype, size);
13304 : 9145 : init = TREE_OPERAND (init, 0);
13305 : 9145 : init = TREE_OPERAND (init, 0);
13306 : :
13307 : 9145 : *ptr_offset = integer_zero_node;
13308 : : }
13309 : : }
13310 : :
13311 : 97028 : if (decl)
13312 : 54923 : *decl = array;
13313 : :
13314 : 97028 : if (TREE_CODE (init) != STRING_CST)
13315 : : return NULL_TREE;
13316 : :
13317 : 67378 : *mem_size = initsize;
13318 : :
13319 : 67378 : gcc_checking_assert (tree_to_shwi (initsize) >= TREE_STRING_LENGTH (init));
13320 : :
13321 : : return init;
13322 : : }
13323 : :
13324 : : /* Return STRING_CST if an ARG corresponds to a string constant or zero
13325 : : if it doesn't. If we return nonzero, set *PTR_OFFSET to the (possibly
13326 : : non-constant) offset in bytes within the string that ARG is accessing.
13327 : : If MEM_SIZE is non-zero the storage size of the memory is returned.
13328 : : If DECL is non-zero the constant declaration is returned if available. */
13329 : :
13330 : : tree
13331 : 10839926 : string_constant (tree arg, tree *ptr_offset, tree *mem_size, tree *decl)
13332 : : {
13333 : 10839926 : return constant_byte_string (arg, ptr_offset, mem_size, decl, false);
13334 : : }
13335 : :
13336 : : /* Similar to string_constant, return a STRING_CST corresponding
13337 : : to the value representation of the first argument if it's
13338 : : a constant. */
13339 : :
13340 : : tree
13341 : 4868612 : byte_representation (tree arg, tree *ptr_offset, tree *mem_size, tree *decl)
13342 : : {
13343 : 4868612 : return constant_byte_string (arg, ptr_offset, mem_size, decl, true);
13344 : : }
13345 : :
13346 : : /* Optimize x % C1 == C2 for signed modulo if C1 is a power of two and C2
13347 : : is non-zero and C3 ((1<<(prec-1)) | (C1 - 1)):
13348 : : for C2 > 0 to x & C3 == C2
13349 : : for C2 < 0 to x & C3 == (C2 & C3). */
13350 : : enum tree_code
13351 : 35 : maybe_optimize_pow2p_mod_cmp (enum tree_code code, tree *arg0, tree *arg1)
13352 : : {
13353 : 35 : gimple *stmt = get_def_for_expr (*arg0, TRUNC_MOD_EXPR);
13354 : 35 : tree treeop0 = gimple_assign_rhs1 (stmt);
13355 : 35 : tree treeop1 = gimple_assign_rhs2 (stmt);
13356 : 35 : tree type = TREE_TYPE (*arg0);
13357 : 35 : scalar_int_mode mode;
13358 : 35 : if (!is_a <scalar_int_mode> (TYPE_MODE (type), &mode))
13359 : : return code;
13360 : 70 : if (GET_MODE_BITSIZE (mode) != TYPE_PRECISION (type)
13361 : 35 : || TYPE_PRECISION (type) <= 1
13362 : 35 : || TYPE_UNSIGNED (type)
13363 : : /* Signed x % c == 0 should have been optimized into unsigned modulo
13364 : : earlier. */
13365 : 35 : || integer_zerop (*arg1)
13366 : : /* If c is known to be non-negative, modulo will be expanded as unsigned
13367 : : modulo. */
13368 : 70 : || get_range_pos_neg (treeop0, currently_expanding_gimple_stmt) == 1)
13369 : 0 : return code;
13370 : :
13371 : : /* x % c == d where d < 0 && d <= -c should be always false. */
13372 : 35 : if (tree_int_cst_sgn (*arg1) == -1
13373 : 51 : && -wi::to_widest (treeop1) >= wi::to_widest (*arg1))
13374 : : return code;
13375 : :
13376 : 35 : int prec = TYPE_PRECISION (type);
13377 : 35 : wide_int w = wi::to_wide (treeop1) - 1;
13378 : 35 : w |= wi::shifted_mask (0, prec - 1, true, prec);
13379 : 35 : tree c3 = wide_int_to_tree (type, w);
13380 : 35 : tree c4 = *arg1;
13381 : 35 : if (tree_int_cst_sgn (*arg1) == -1)
13382 : 16 : c4 = wide_int_to_tree (type, w & wi::to_wide (*arg1));
13383 : :
13384 : 35 : rtx op0 = expand_normal (treeop0);
13385 : 35 : treeop0 = make_tree (TREE_TYPE (treeop0), op0);
13386 : :
13387 : 35 : bool speed_p = optimize_insn_for_speed_p ();
13388 : :
13389 : 35 : do_pending_stack_adjust ();
13390 : :
13391 : 35 : location_t loc = gimple_location (stmt);
13392 : 35 : struct separate_ops ops;
13393 : 35 : ops.code = TRUNC_MOD_EXPR;
13394 : 35 : ops.location = loc;
13395 : 35 : ops.type = TREE_TYPE (treeop0);
13396 : 35 : ops.op0 = treeop0;
13397 : 35 : ops.op1 = treeop1;
13398 : 35 : ops.op2 = NULL_TREE;
13399 : 35 : start_sequence ();
13400 : 35 : rtx mor = expand_expr_real_2 (&ops, NULL_RTX, TYPE_MODE (ops.type),
13401 : : EXPAND_NORMAL);
13402 : 35 : rtx_insn *moinsns = end_sequence ();
13403 : :
13404 : 35 : unsigned mocost = seq_cost (moinsns, speed_p);
13405 : 35 : mocost += rtx_cost (mor, mode, EQ, 0, speed_p);
13406 : 35 : mocost += rtx_cost (expand_normal (*arg1), mode, EQ, 1, speed_p);
13407 : :
13408 : 35 : ops.code = BIT_AND_EXPR;
13409 : 35 : ops.location = loc;
13410 : 35 : ops.type = TREE_TYPE (treeop0);
13411 : 35 : ops.op0 = treeop0;
13412 : 35 : ops.op1 = c3;
13413 : 35 : ops.op2 = NULL_TREE;
13414 : 35 : start_sequence ();
13415 : 35 : rtx mur = expand_expr_real_2 (&ops, NULL_RTX, TYPE_MODE (ops.type),
13416 : : EXPAND_NORMAL);
13417 : 35 : rtx_insn *muinsns = end_sequence ();
13418 : :
13419 : 35 : unsigned mucost = seq_cost (muinsns, speed_p);
13420 : 35 : mucost += rtx_cost (mur, mode, EQ, 0, speed_p);
13421 : 35 : mucost += rtx_cost (expand_normal (c4), mode, EQ, 1, speed_p);
13422 : :
13423 : 35 : if (mocost <= mucost)
13424 : : {
13425 : 0 : emit_insn (moinsns);
13426 : 0 : *arg0 = make_tree (TREE_TYPE (*arg0), mor);
13427 : 0 : return code;
13428 : : }
13429 : :
13430 : 35 : emit_insn (muinsns);
13431 : 35 : *arg0 = make_tree (TREE_TYPE (*arg0), mur);
13432 : 35 : *arg1 = c4;
13433 : 35 : return code;
13434 : 35 : }
13435 : :
13436 : : /* Attempt to optimize unsigned (X % C1) == C2 (or (X % C1) != C2).
13437 : : If C1 is odd to:
13438 : : (X - C2) * C3 <= C4 (or >), where
13439 : : C3 is modular multiplicative inverse of C1 and 1<<prec and
13440 : : C4 is ((1<<prec) - 1) / C1 or ((1<<prec) - 1) / C1 - 1 (the latter
13441 : : if C2 > ((1<<prec) - 1) % C1).
13442 : : If C1 is even, S = ctz (C1) and C2 is 0, use
13443 : : ((X * C3) r>> S) <= C4, where C3 is modular multiplicative
13444 : : inverse of C1>>S and 1<<prec and C4 is (((1<<prec) - 1) / (C1>>S)) >> S.
13445 : :
13446 : : For signed (X % C1) == 0 if C1 is odd to (all operations in it
13447 : : unsigned):
13448 : : (X * C3) + C4 <= 2 * C4, where
13449 : : C3 is modular multiplicative inverse of (unsigned) C1 and 1<<prec and
13450 : : C4 is ((1<<(prec - 1) - 1) / C1).
13451 : : If C1 is even, S = ctz(C1), use
13452 : : ((X * C3) + C4) r>> S <= (C4 >> (S - 1))
13453 : : where C3 is modular multiplicative inverse of (unsigned)(C1>>S) and 1<<prec
13454 : : and C4 is ((1<<(prec - 1) - 1) / (C1>>S)) & (-1<<S).
13455 : :
13456 : : See the Hacker's Delight book, section 10-17. */
13457 : : enum tree_code
13458 : 3297266 : maybe_optimize_mod_cmp (enum tree_code code, tree *arg0, tree *arg1)
13459 : : {
13460 : 3297266 : gcc_checking_assert (code == EQ_EXPR || code == NE_EXPR);
13461 : 3297266 : gcc_checking_assert (TREE_CODE (*arg1) == INTEGER_CST);
13462 : :
13463 : 3297266 : if (optimize < 2)
13464 : : return code;
13465 : :
13466 : 2500020 : gimple *stmt = get_def_for_expr (*arg0, TRUNC_MOD_EXPR);
13467 : 2500020 : if (stmt == NULL)
13468 : : return code;
13469 : :
13470 : 2357 : tree treeop0 = gimple_assign_rhs1 (stmt);
13471 : 2357 : tree treeop1 = gimple_assign_rhs2 (stmt);
13472 : 2357 : if (TREE_CODE (treeop0) != SSA_NAME
13473 : 2268 : || TREE_CODE (treeop1) != INTEGER_CST
13474 : : /* Don't optimize the undefined behavior case x % 0;
13475 : : x % 1 should have been optimized into zero, punt if
13476 : : it makes it here for whatever reason;
13477 : : x % -c should have been optimized into x % c. */
13478 : 1903 : || compare_tree_int (treeop1, 2) <= 0
13479 : : /* Likewise x % c == d where d >= c should be always false. */
13480 : 4179 : || tree_int_cst_le (treeop1, *arg1))
13481 : 535 : return code;
13482 : :
13483 : : /* Unsigned x % pow2 is handled right already, for signed
13484 : : modulo handle it in maybe_optimize_pow2p_mod_cmp. */
13485 : 1822 : if (integer_pow2p (treeop1))
13486 : 35 : return maybe_optimize_pow2p_mod_cmp (code, arg0, arg1);
13487 : :
13488 : 1787 : tree type = TREE_TYPE (*arg0);
13489 : 1787 : scalar_int_mode mode;
13490 : 3297238 : if (!is_a <scalar_int_mode> (TYPE_MODE (type), &mode))
13491 : : return code;
13492 : 3574 : if (GET_MODE_BITSIZE (mode) != TYPE_PRECISION (type)
13493 : 1787 : || TYPE_PRECISION (type) <= 1)
13494 : : return code;
13495 : :
13496 : 1787 : signop sgn = UNSIGNED;
13497 : : /* If both operands are known to have the sign bit clear, handle
13498 : : even the signed modulo case as unsigned. treeop1 is always
13499 : : positive >= 2, checked above. */
13500 : 1787 : if (!TYPE_UNSIGNED (type)
13501 : 1787 : && get_range_pos_neg (treeop0, currently_expanding_gimple_stmt) != 1)
13502 : : sgn = SIGNED;
13503 : :
13504 : 1787 : if (!TYPE_UNSIGNED (type))
13505 : : {
13506 : 1562 : if (tree_int_cst_sgn (*arg1) == -1)
13507 : : return code;
13508 : 1555 : type = unsigned_type_for (type);
13509 : 1555 : if (!type || TYPE_MODE (type) != TYPE_MODE (TREE_TYPE (*arg0)))
13510 : 0 : return code;
13511 : : }
13512 : :
13513 : 1780 : int prec = TYPE_PRECISION (type);
13514 : 1780 : wide_int w = wi::to_wide (treeop1);
13515 : 1780 : int shift = wi::ctz (w);
13516 : : /* Unsigned (X % C1) == C2 is equivalent to (X - C2) % C1 == 0 if
13517 : : C2 <= -1U % C1, because for any Z >= 0U - C2 in that case (Z % C1) != 0.
13518 : : If C1 is odd, we can handle all cases by subtracting
13519 : : C4 below. We could handle even the even C1 and C2 > -1U % C1 cases
13520 : : e.g. by testing for overflow on the subtraction, punt on that for now
13521 : : though. */
13522 : 1780 : if ((sgn == SIGNED || shift) && !integer_zerop (*arg1))
13523 : : {
13524 : 183 : if (sgn == SIGNED)
13525 : 168 : return code;
13526 : 26 : wide_int x = wi::umod_trunc (wi::mask (prec, false, prec), w);
13527 : 26 : if (wi::gtu_p (wi::to_wide (*arg1), x))
13528 : 11 : return code;
13529 : 26 : }
13530 : :
13531 : 1612 : imm_use_iterator imm_iter;
13532 : 1612 : use_operand_p use_p;
13533 : 12485 : FOR_EACH_IMM_USE_FAST (use_p, imm_iter, treeop0)
13534 : : {
13535 : 10874 : gimple *use_stmt = USE_STMT (use_p);
13536 : : /* Punt if treeop0 is used in the same bb in a division
13537 : : or another modulo with the same divisor. We should expect
13538 : : the division and modulo combined together. */
13539 : 21311 : if (use_stmt == stmt
13540 : 10874 : || gimple_bb (use_stmt) != gimple_bb (stmt))
13541 : 10437 : continue;
13542 : 437 : if (!is_gimple_assign (use_stmt)
13543 : 437 : || (gimple_assign_rhs_code (use_stmt) != TRUNC_DIV_EXPR
13544 : 430 : && gimple_assign_rhs_code (use_stmt) != TRUNC_MOD_EXPR))
13545 : 427 : continue;
13546 : 10 : if (gimple_assign_rhs1 (use_stmt) != treeop0
13547 : 10 : || !operand_equal_p (gimple_assign_rhs2 (use_stmt), treeop1, 0))
13548 : 9 : continue;
13549 : : return code;
13550 : : }
13551 : :
13552 : 1611 : w = wi::lrshift (w, shift);
13553 : 1611 : wide_int a = wide_int::from (w, prec + 1, UNSIGNED);
13554 : 1611 : wide_int b = wi::shifted_mask (prec, 1, false, prec + 1);
13555 : 1611 : wide_int m = wide_int::from (wi::mod_inv (a, b), prec, UNSIGNED);
13556 : 1611 : tree c3 = wide_int_to_tree (type, m);
13557 : 1611 : tree c5 = NULL_TREE;
13558 : 1611 : wide_int d, e;
13559 : 1611 : if (sgn == UNSIGNED)
13560 : : {
13561 : 948 : d = wi::divmod_trunc (wi::mask (prec, false, prec), w, UNSIGNED, &e);
13562 : : /* Use <= floor ((1<<prec) - 1) / C1 only if C2 <= ((1<<prec) - 1) % C1,
13563 : : otherwise use < or subtract one from C4. E.g. for
13564 : : x % 3U == 0 we transform this into x * 0xaaaaaaab <= 0x55555555, but
13565 : : x % 3U == 1 already needs to be
13566 : : (x - 1) * 0xaaaaaaabU <= 0x55555554. */
13567 : 948 : if (!shift && wi::gtu_p (wi::to_wide (*arg1), e))
13568 : 19 : d -= 1;
13569 : 948 : if (shift)
13570 : 444 : d = wi::lrshift (d, shift);
13571 : : }
13572 : : else
13573 : : {
13574 : 663 : e = wi::udiv_trunc (wi::mask (prec - 1, false, prec), w);
13575 : 663 : if (!shift)
13576 : 466 : d = wi::lshift (e, 1);
13577 : : else
13578 : : {
13579 : 197 : e = wi::bit_and (e, wi::mask (shift, true, prec));
13580 : 197 : d = wi::lrshift (e, shift - 1);
13581 : : }
13582 : 663 : c5 = wide_int_to_tree (type, e);
13583 : : }
13584 : 1611 : tree c4 = wide_int_to_tree (type, d);
13585 : :
13586 : 1611 : rtx op0 = expand_normal (treeop0);
13587 : 1611 : treeop0 = make_tree (TREE_TYPE (treeop0), op0);
13588 : :
13589 : 1611 : bool speed_p = optimize_insn_for_speed_p ();
13590 : :
13591 : 1611 : do_pending_stack_adjust ();
13592 : :
13593 : 1611 : location_t loc = gimple_location (stmt);
13594 : 1611 : struct separate_ops ops;
13595 : 1611 : ops.code = TRUNC_MOD_EXPR;
13596 : 1611 : ops.location = loc;
13597 : 1611 : ops.type = TREE_TYPE (treeop0);
13598 : 1611 : ops.op0 = treeop0;
13599 : 1611 : ops.op1 = treeop1;
13600 : 1611 : ops.op2 = NULL_TREE;
13601 : 1611 : start_sequence ();
13602 : 1611 : rtx mor = expand_expr_real_2 (&ops, NULL_RTX, TYPE_MODE (ops.type),
13603 : : EXPAND_NORMAL);
13604 : 1611 : rtx_insn *moinsns = end_sequence ();
13605 : :
13606 : 1611 : unsigned mocost = seq_cost (moinsns, speed_p);
13607 : 1611 : mocost += rtx_cost (mor, mode, EQ, 0, speed_p);
13608 : 1611 : mocost += rtx_cost (expand_normal (*arg1), mode, EQ, 1, speed_p);
13609 : :
13610 : 1611 : tree t = fold_convert_loc (loc, type, treeop0);
13611 : 1611 : if (!integer_zerop (*arg1))
13612 : 44 : t = fold_build2_loc (loc, MINUS_EXPR, type, t, fold_convert (type, *arg1));
13613 : 1611 : t = fold_build2_loc (loc, MULT_EXPR, type, t, c3);
13614 : 1611 : if (sgn == SIGNED)
13615 : 663 : t = fold_build2_loc (loc, PLUS_EXPR, type, t, c5);
13616 : 1611 : if (shift)
13617 : : {
13618 : 641 : tree s = build_int_cst (NULL_TREE, shift);
13619 : 641 : t = fold_build2_loc (loc, RROTATE_EXPR, type, t, s);
13620 : : }
13621 : :
13622 : 1611 : start_sequence ();
13623 : 1611 : rtx mur = expand_normal (t);
13624 : 1611 : rtx_insn *muinsns = end_sequence ();
13625 : :
13626 : 1611 : unsigned mucost = seq_cost (muinsns, speed_p);
13627 : 1611 : mucost += rtx_cost (mur, mode, LE, 0, speed_p);
13628 : 1611 : mucost += rtx_cost (expand_normal (c4), mode, LE, 1, speed_p);
13629 : :
13630 : 1611 : if (mocost <= mucost)
13631 : : {
13632 : 312 : emit_insn (moinsns);
13633 : 312 : *arg0 = make_tree (TREE_TYPE (*arg0), mor);
13634 : 312 : return code;
13635 : : }
13636 : :
13637 : 1299 : emit_insn (muinsns);
13638 : 1299 : *arg0 = make_tree (type, mur);
13639 : 1299 : *arg1 = c4;
13640 : 1299 : return code == EQ_EXPR ? LE_EXPR : GT_EXPR;
13641 : 3391 : }
13642 : :
13643 : : /* Optimize x - y < 0 into x < 0 if x - y has undefined overflow. */
13644 : :
13645 : : void
13646 : 237301 : maybe_optimize_sub_cmp_0 (enum tree_code code, tree *arg0, tree *arg1)
13647 : : {
13648 : 237301 : gcc_checking_assert (code == GT_EXPR || code == GE_EXPR
13649 : : || code == LT_EXPR || code == LE_EXPR);
13650 : 237301 : gcc_checking_assert (integer_zerop (*arg1));
13651 : :
13652 : 237301 : if (!optimize)
13653 : : return;
13654 : :
13655 : 203752 : gimple *stmt = get_def_for_expr (*arg0, MINUS_EXPR);
13656 : 203752 : if (stmt == NULL)
13657 : : return;
13658 : :
13659 : 1314 : tree treeop0 = gimple_assign_rhs1 (stmt);
13660 : 1314 : tree treeop1 = gimple_assign_rhs2 (stmt);
13661 : 1314 : if (!TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (treeop0)))
13662 : : return;
13663 : :
13664 : 1217 : if (issue_strict_overflow_warning (WARN_STRICT_OVERFLOW_COMPARISON))
13665 : 1 : warning_at (gimple_location (stmt), OPT_Wstrict_overflow,
13666 : : "assuming signed overflow does not occur when "
13667 : : "simplifying %<X - Y %s 0%> to %<X %s Y%>",
13668 : : op_symbol_code (code), op_symbol_code (code));
13669 : :
13670 : 1217 : *arg0 = treeop0;
13671 : 1217 : *arg1 = treeop1;
13672 : : }
13673 : :
13674 : :
13675 : : /* Expand CODE with arguments INNER & (1<<BITNUM) and 0 that represents
13676 : : a single bit equality/inequality test, returns where the result is located. */
13677 : :
13678 : : static rtx
13679 : 10890 : expand_single_bit_test (location_t loc, enum tree_code code,
13680 : : tree inner, int bitnum,
13681 : : tree result_type, rtx target,
13682 : : machine_mode mode)
13683 : : {
13684 : 10890 : gcc_assert (code == NE_EXPR || code == EQ_EXPR);
13685 : :
13686 : 10890 : tree type = TREE_TYPE (inner);
13687 : 10890 : scalar_int_mode operand_mode = SCALAR_INT_TYPE_MODE (type);
13688 : 10890 : int ops_unsigned;
13689 : 10890 : tree signed_type, unsigned_type, intermediate_type;
13690 : 10890 : gimple *inner_def;
13691 : :
13692 : : /* First, see if we can fold the single bit test into a sign-bit
13693 : : test. */
13694 : 10890 : if (bitnum == TYPE_PRECISION (type) - 1
13695 : 10890 : && type_has_mode_precision_p (type))
13696 : : {
13697 : 231 : tree stype = signed_type_for (type);
13698 : 428 : tree tmp = fold_build2_loc (loc, code == EQ_EXPR ? GE_EXPR : LT_EXPR,
13699 : : result_type,
13700 : : fold_convert_loc (loc, stype, inner),
13701 : : build_int_cst (stype, 0));
13702 : 231 : return expand_expr (tmp, target, VOIDmode, EXPAND_NORMAL);
13703 : : }
13704 : :
13705 : : /* Otherwise we have (A & C) != 0 where C is a single bit,
13706 : : convert that into ((A >> C2) & 1). Where C2 = log2(C).
13707 : : Similarly for (A & C) == 0. */
13708 : :
13709 : : /* If INNER is a right shift of a constant and it plus BITNUM does
13710 : : not overflow, adjust BITNUM and INNER. */
13711 : 10659 : if ((inner_def = get_def_for_expr (inner, RSHIFT_EXPR))
13712 : 85 : && TREE_CODE (gimple_assign_rhs2 (inner_def)) == INTEGER_CST
13713 : 8 : && bitnum < TYPE_PRECISION (type)
13714 : 10667 : && wi::ltu_p (wi::to_wide (gimple_assign_rhs2 (inner_def)),
13715 : 10659 : TYPE_PRECISION (type) - bitnum))
13716 : : {
13717 : 8 : bitnum += tree_to_uhwi (gimple_assign_rhs2 (inner_def));
13718 : 8 : inner = gimple_assign_rhs1 (inner_def);
13719 : : }
13720 : :
13721 : : /* If we are going to be able to omit the AND below, we must do our
13722 : : operations as unsigned. If we must use the AND, we have a choice.
13723 : : Normally unsigned is faster, but for some machines signed is. */
13724 : 10659 : ops_unsigned = (load_extend_op (operand_mode) == SIGN_EXTEND
13725 : : && !flag_syntax_only) ? 0 : 1;
13726 : :
13727 : 10659 : signed_type = lang_hooks.types.type_for_mode (operand_mode, 0);
13728 : 10659 : unsigned_type = lang_hooks.types.type_for_mode (operand_mode, 1);
13729 : 10659 : intermediate_type = ops_unsigned ? unsigned_type : signed_type;
13730 : 10659 : inner = fold_convert_loc (loc, intermediate_type, inner);
13731 : :
13732 : 10659 : rtx inner0 = expand_expr (inner, NULL_RTX, VOIDmode, EXPAND_NORMAL);
13733 : :
13734 : 10659 : if (CONST_SCALAR_INT_P (inner0))
13735 : : {
13736 : 0 : wide_int t = rtx_mode_t (inner0, operand_mode);
13737 : 0 : bool setp = (wi::lrshift (t, bitnum) & 1) != 0;
13738 : 0 : return (setp ^ (code == EQ_EXPR)) ? const1_rtx : const0_rtx;
13739 : 0 : }
13740 : 10659 : int bitpos = bitnum;
13741 : :
13742 : 10659 : if (BYTES_BIG_ENDIAN)
13743 : : bitpos = GET_MODE_BITSIZE (operand_mode) - 1 - bitpos;
13744 : :
13745 : 10659 : inner0 = extract_bit_field (inner0, 1, bitpos, 1, target,
13746 : : operand_mode, mode, 0, NULL);
13747 : :
13748 : 10659 : if (code == EQ_EXPR)
13749 : 3828 : inner0 = expand_binop (GET_MODE (inner0), xor_optab, inner0, const1_rtx,
13750 : : NULL_RTX, 1, OPTAB_LIB_WIDEN);
13751 : 10659 : if (GET_MODE (inner0) != mode)
13752 : : {
13753 : 0 : rtx t = gen_reg_rtx (mode);
13754 : 0 : convert_move (t, inner0, 0);
13755 : 0 : return t;
13756 : : }
13757 : : return inner0;
13758 : : }
13759 : :
13760 : : /* Generate code to calculate OPS, and exploded expression
13761 : : using a store-flag instruction and return an rtx for the result.
13762 : : OPS reflects a comparison.
13763 : :
13764 : : If TARGET is nonzero, store the result there if convenient.
13765 : :
13766 : : Return zero if there is no suitable set-flag instruction
13767 : : available on this machine.
13768 : :
13769 : : Once expand_expr has been called on the arguments of the comparison,
13770 : : we are committed to doing the store flag, since it is not safe to
13771 : : re-evaluate the expression. We emit the store-flag insn by calling
13772 : : emit_store_flag, but only expand the arguments if we have a reason
13773 : : to believe that emit_store_flag will be successful. If we think that
13774 : : it will, but it isn't, we have to simulate the store-flag with a
13775 : : set/jump/set sequence. */
13776 : :
13777 : : static rtx
13778 : 542741 : do_store_flag (const_sepops ops, rtx target, machine_mode mode)
13779 : : {
13780 : 542741 : enum rtx_code code;
13781 : 542741 : tree arg0, arg1, type;
13782 : 542741 : machine_mode operand_mode;
13783 : 542741 : int unsignedp;
13784 : 542741 : rtx op0, op1;
13785 : 542741 : rtx subtarget = target;
13786 : 542741 : location_t loc = ops->location;
13787 : 542741 : unsigned HOST_WIDE_INT nunits;
13788 : :
13789 : 542741 : arg0 = ops->op0;
13790 : 542741 : arg1 = ops->op1;
13791 : :
13792 : : /* Don't crash if the comparison was erroneous. */
13793 : 542741 : if (arg0 == error_mark_node || arg1 == error_mark_node)
13794 : 0 : return const0_rtx;
13795 : :
13796 : 542741 : type = TREE_TYPE (arg0);
13797 : 542741 : operand_mode = TYPE_MODE (type);
13798 : 542741 : unsignedp = TYPE_UNSIGNED (type);
13799 : :
13800 : : /* We won't bother with BLKmode store-flag operations because it would mean
13801 : : passing a lot of information to emit_store_flag. */
13802 : 542741 : if (operand_mode == BLKmode)
13803 : : return 0;
13804 : :
13805 : : /* We won't bother with store-flag operations involving function pointers
13806 : : when function pointers must be canonicalized before comparisons. */
13807 : 542741 : if (targetm.have_canonicalize_funcptr_for_compare ()
13808 : 542741 : && ((POINTER_TYPE_P (TREE_TYPE (arg0))
13809 : 0 : && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (arg0))))
13810 : 0 : || (POINTER_TYPE_P (TREE_TYPE (arg1))
13811 : 0 : && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (arg1))))))
13812 : : return 0;
13813 : :
13814 : 542741 : STRIP_NOPS (arg0);
13815 : 542741 : STRIP_NOPS (arg1);
13816 : :
13817 : : /* For vector typed comparisons emit code to generate the desired
13818 : : all-ones or all-zeros mask. */
13819 : 542741 : if (VECTOR_TYPE_P (ops->type))
13820 : : {
13821 : 20510 : tree ifexp = build2 (ops->code, ops->type, arg0, arg1);
13822 : 20510 : if (VECTOR_BOOLEAN_TYPE_P (ops->type)
13823 : 41020 : && expand_vec_cmp_expr_p (TREE_TYPE (arg0), ops->type, ops->code))
13824 : 20510 : return expand_vec_cmp_expr (ops->type, ifexp, target);
13825 : : else
13826 : 0 : gcc_unreachable ();
13827 : : }
13828 : :
13829 : : /* Optimize (x % C1) == C2 or (x % C1) != C2 if it is beneficial
13830 : : into (x - C2) * C3 < C4. */
13831 : 522231 : if ((ops->code == EQ_EXPR || ops->code == NE_EXPR)
13832 : 322919 : && TREE_CODE (arg0) == SSA_NAME
13833 : 322405 : && TREE_CODE (arg1) == INTEGER_CST)
13834 : : {
13835 : 190170 : enum tree_code new_code = maybe_optimize_mod_cmp (ops->code,
13836 : : &arg0, &arg1);
13837 : 190170 : if (new_code != ops->code)
13838 : : {
13839 : 75 : struct separate_ops nops = *ops;
13840 : 75 : nops.code = new_code;
13841 : 75 : nops.op0 = arg0;
13842 : 75 : nops.op1 = arg1;
13843 : 75 : nops.type = TREE_TYPE (arg0);
13844 : 75 : return do_store_flag (&nops, target, mode);
13845 : : }
13846 : : }
13847 : :
13848 : : /* Optimize (x - y) < 0 into x < y if x - y has undefined overflow. */
13849 : 522156 : if (!unsignedp
13850 : 340779 : && (ops->code == LT_EXPR || ops->code == LE_EXPR
13851 : 340779 : || ops->code == GT_EXPR || ops->code == GE_EXPR)
13852 : 123239 : && integer_zerop (arg1)
13853 : 561112 : && TREE_CODE (arg0) == SSA_NAME)
13854 : 38952 : maybe_optimize_sub_cmp_0 (ops->code, &arg0, &arg1);
13855 : :
13856 : : /* Get the rtx comparison code to use. We know that EXP is a comparison
13857 : : operation of some type. Some comparisons against 1 and -1 can be
13858 : : converted to comparisons with zero. Do so here so that the tests
13859 : : below will be aware that we have a comparison with zero. These
13860 : : tests will not catch constants in the first operand, but constants
13861 : : are rarely passed as the first operand. */
13862 : :
13863 : 522156 : switch (ops->code)
13864 : : {
13865 : : case EQ_EXPR:
13866 : : code = EQ;
13867 : : break;
13868 : 197071 : case NE_EXPR:
13869 : 197071 : code = NE;
13870 : 197071 : break;
13871 : 39873 : case LT_EXPR:
13872 : 39873 : if (integer_onep (arg1))
13873 : 0 : arg1 = integer_zero_node, code = unsignedp ? LEU : LE;
13874 : : else
13875 : 39873 : code = unsignedp ? LTU : LT;
13876 : : break;
13877 : 35268 : case LE_EXPR:
13878 : 35268 : if (! unsignedp && integer_all_onesp (arg1))
13879 : 0 : arg1 = integer_zero_node, code = LT;
13880 : : else
13881 : 35268 : code = unsignedp ? LEU : LE;
13882 : : break;
13883 : 54497 : case GT_EXPR:
13884 : 54497 : if (! unsignedp && integer_all_onesp (arg1))
13885 : 0 : arg1 = integer_zero_node, code = GE;
13886 : : else
13887 : 54497 : code = unsignedp ? GTU : GT;
13888 : : break;
13889 : 46194 : case GE_EXPR:
13890 : 46194 : if (integer_onep (arg1))
13891 : 29236 : arg1 = integer_zero_node, code = unsignedp ? GTU : GT;
13892 : : else
13893 : 46194 : code = unsignedp ? GEU : GE;
13894 : : break;
13895 : :
13896 : 674 : case UNORDERED_EXPR:
13897 : 674 : code = UNORDERED;
13898 : 674 : break;
13899 : 678 : case ORDERED_EXPR:
13900 : 678 : code = ORDERED;
13901 : 678 : break;
13902 : 482 : case UNLT_EXPR:
13903 : 482 : code = UNLT;
13904 : 482 : break;
13905 : 10782 : case UNLE_EXPR:
13906 : 10782 : code = UNLE;
13907 : 10782 : break;
13908 : 825 : case UNGT_EXPR:
13909 : 825 : code = UNGT;
13910 : 825 : break;
13911 : 9818 : case UNGE_EXPR:
13912 : 9818 : code = UNGE;
13913 : 9818 : break;
13914 : 141 : case UNEQ_EXPR:
13915 : 141 : code = UNEQ;
13916 : 141 : break;
13917 : 80 : case LTGT_EXPR:
13918 : 80 : code = LTGT;
13919 : 80 : break;
13920 : :
13921 : 0 : default:
13922 : 0 : gcc_unreachable ();
13923 : : }
13924 : :
13925 : : /* Put a constant second. */
13926 : 522156 : if (TREE_CODE (arg0) == REAL_CST || TREE_CODE (arg0) == INTEGER_CST
13927 : 520634 : || TREE_CODE (arg0) == FIXED_CST)
13928 : : {
13929 : 1522 : std::swap (arg0, arg1);
13930 : 1522 : code = swap_condition (code);
13931 : : }
13932 : :
13933 : : /* If this is an equality or inequality test of a single bit, we can
13934 : : do this by shifting the bit being tested to the low-order bit and
13935 : : masking the result with the constant 1. If the condition was EQ,
13936 : : we xor it with 1. This does not require an scc insn and is faster
13937 : : than an scc insn even if we have it. */
13938 : :
13939 : 522156 : if ((code == NE || code == EQ)
13940 : 322844 : && (integer_zerop (arg1)
13941 : 204304 : || integer_pow2p (arg1))
13942 : : /* vector types are not handled here. */
13943 : 148960 : && TREE_CODE (TREE_TYPE (arg1)) != VECTOR_TYPE
13944 : 671107 : && (TYPE_PRECISION (ops->type) != 1 || TYPE_UNSIGNED (ops->type)))
13945 : : {
13946 : 148951 : tree narg0 = arg0;
13947 : 148951 : wide_int nz = tree_nonzero_bits (narg0);
13948 : 148951 : gimple *srcstmt = get_def_for_expr (narg0, BIT_AND_EXPR);
13949 : : /* If the defining statement was (x & POW2), then use that instead of
13950 : : the non-zero bits. */
13951 : 148951 : if (srcstmt && integer_pow2p (gimple_assign_rhs2 (srcstmt)))
13952 : : {
13953 : 6540 : nz = wi::to_wide (gimple_assign_rhs2 (srcstmt));
13954 : 6540 : narg0 = gimple_assign_rhs1 (srcstmt);
13955 : : }
13956 : :
13957 : 148951 : if (wi::popcount (nz) == 1
13958 : 148951 : && (integer_zerop (arg1)
13959 : 138095 : || wi::to_wide (arg1) == nz))
13960 : : {
13961 : 10890 : int bitnum = wi::exact_log2 (nz);
13962 : 10890 : enum tree_code tcode = EQ_EXPR;
13963 : 10890 : if ((code == NE) ^ !integer_zerop (arg1))
13964 : 7028 : tcode = NE_EXPR;
13965 : :
13966 : 10890 : type = lang_hooks.types.type_for_mode (mode, unsignedp);
13967 : 10890 : return expand_single_bit_test (loc, tcode,
13968 : : narg0,
13969 : : bitnum, type, target, mode);
13970 : : }
13971 : 148951 : }
13972 : :
13973 : :
13974 : 511266 : if (! get_subtarget (target)
13975 : 511266 : || GET_MODE (subtarget) != operand_mode)
13976 : : subtarget = 0;
13977 : :
13978 : 511266 : expand_operands (arg0, arg1, subtarget, &op0, &op1, EXPAND_NORMAL);
13979 : :
13980 : : /* For boolean vectors with less than mode precision
13981 : : make sure to fill padding with consistent values. */
13982 : 9 : if (VECTOR_BOOLEAN_TYPE_P (type)
13983 : 0 : && SCALAR_INT_MODE_P (operand_mode)
13984 : 511266 : && TYPE_VECTOR_SUBPARTS (type).is_constant (&nunits)
13985 : 511266 : && maybe_ne (GET_MODE_PRECISION (operand_mode), nunits))
13986 : : {
13987 : 0 : gcc_assert (code == EQ || code == NE);
13988 : 0 : op0 = expand_binop (mode, and_optab, op0,
13989 : 0 : GEN_INT ((HOST_WIDE_INT_1U << nunits) - 1),
13990 : : NULL_RTX, true, OPTAB_WIDEN);
13991 : 0 : op1 = expand_binop (mode, and_optab, op1,
13992 : : GEN_INT ((HOST_WIDE_INT_1U << nunits) - 1),
13993 : : NULL_RTX, true, OPTAB_WIDEN);
13994 : : }
13995 : :
13996 : 511266 : if (target == 0)
13997 : 326169 : target = gen_reg_rtx (mode);
13998 : :
13999 : : /* Try a cstore if possible. */
14000 : 511266 : return emit_store_flag_force (target, code, op0, op1,
14001 : : operand_mode, unsignedp,
14002 : 511266 : (TYPE_PRECISION (ops->type) == 1
14003 : 1021922 : && !TYPE_UNSIGNED (ops->type)) ? -1 : 1);
14004 : : }
14005 : :
14006 : : /* Attempt to generate a casesi instruction. Returns true if successful,
14007 : : false otherwise (i.e. if there is no casesi instruction).
14008 : :
14009 : : DEFAULT_PROBABILITY is the probability of jumping to the default
14010 : : label. */
14011 : : bool
14012 : 9271 : try_casesi (tree index_type, tree index_expr, tree minval, tree range,
14013 : : rtx table_label, rtx default_label, rtx fallback_label,
14014 : : profile_probability default_probability)
14015 : : {
14016 : 9271 : class expand_operand ops[5];
14017 : 9271 : scalar_int_mode index_mode = SImode;
14018 : 9271 : rtx op1, op2, index;
14019 : :
14020 : 9271 : if (! targetm.have_casesi ())
14021 : : return false;
14022 : :
14023 : : /* The index must be some form of integer. Convert it to SImode. */
14024 : 0 : scalar_int_mode omode = SCALAR_INT_TYPE_MODE (index_type);
14025 : 0 : if (GET_MODE_BITSIZE (omode) > GET_MODE_BITSIZE (index_mode))
14026 : : {
14027 : 0 : rtx rangertx = expand_normal (range);
14028 : :
14029 : : /* We must handle the endpoints in the original mode. */
14030 : 0 : index_expr = build2 (MINUS_EXPR, index_type,
14031 : : index_expr, minval);
14032 : 0 : minval = integer_zero_node;
14033 : 0 : index = expand_normal (index_expr);
14034 : 0 : if (default_label)
14035 : 0 : emit_cmp_and_jump_insns (rangertx, index, LTU, NULL_RTX,
14036 : : omode, 1, default_label,
14037 : : default_probability);
14038 : : /* Now we can safely truncate. */
14039 : 0 : index = convert_to_mode (index_mode, index, 0);
14040 : : }
14041 : : else
14042 : : {
14043 : 0 : if (omode != index_mode)
14044 : : {
14045 : 0 : index_type = lang_hooks.types.type_for_mode (index_mode, 0);
14046 : 0 : index_expr = fold_convert (index_type, index_expr);
14047 : : }
14048 : :
14049 : 0 : index = expand_normal (index_expr);
14050 : : }
14051 : :
14052 : 0 : do_pending_stack_adjust ();
14053 : :
14054 : 0 : op1 = expand_normal (minval);
14055 : 0 : op2 = expand_normal (range);
14056 : :
14057 : 0 : create_input_operand (&ops[0], index, index_mode);
14058 : 0 : create_convert_operand_from_type (&ops[1], op1, TREE_TYPE (minval));
14059 : 0 : create_convert_operand_from_type (&ops[2], op2, TREE_TYPE (range));
14060 : 0 : create_fixed_operand (&ops[3], table_label);
14061 : 0 : create_fixed_operand (&ops[4], (default_label
14062 : : ? default_label
14063 : : : fallback_label));
14064 : 0 : expand_jump_insn (targetm.code_for_casesi, 5, ops);
14065 : 0 : return true;
14066 : : }
14067 : :
14068 : : /* Attempt to generate a tablejump instruction; same concept. */
14069 : : /* Subroutine of the next function.
14070 : :
14071 : : INDEX is the value being switched on, with the lowest value
14072 : : in the table already subtracted.
14073 : : MODE is its expected mode (needed if INDEX is constant).
14074 : : RANGE is the length of the jump table.
14075 : : TABLE_LABEL is a CODE_LABEL rtx for the table itself.
14076 : :
14077 : : DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
14078 : : index value is out of range.
14079 : : DEFAULT_PROBABILITY is the probability of jumping to
14080 : : the default label. */
14081 : :
14082 : : static void
14083 : 9271 : do_tablejump (rtx index, machine_mode mode, rtx range, rtx table_label,
14084 : : rtx default_label, profile_probability default_probability)
14085 : : {
14086 : 9271 : rtx temp, vector;
14087 : :
14088 : 9271 : if (INTVAL (range) > cfun->cfg->max_jumptable_ents)
14089 : 7327 : cfun->cfg->max_jumptable_ents = INTVAL (range);
14090 : :
14091 : : /* Do an unsigned comparison (in the proper mode) between the index
14092 : : expression and the value which represents the length of the range.
14093 : : Since we just finished subtracting the lower bound of the range
14094 : : from the index expression, this comparison allows us to simultaneously
14095 : : check that the original index expression value is both greater than
14096 : : or equal to the minimum value of the range and less than or equal to
14097 : : the maximum value of the range. */
14098 : :
14099 : 9271 : if (default_label)
14100 : 4979 : emit_cmp_and_jump_insns (index, range, GTU, NULL_RTX, mode, 1,
14101 : : default_label, default_probability);
14102 : :
14103 : : /* If index is in range, it must fit in Pmode.
14104 : : Convert to Pmode so we can index with it. */
14105 : 10241 : if (mode != Pmode)
14106 : : {
14107 : 8279 : unsigned int width;
14108 : :
14109 : : /* We know the value of INDEX is between 0 and RANGE. If we have a
14110 : : sign-extended subreg, and RANGE does not have the sign bit set, then
14111 : : we have a value that is valid for both sign and zero extension. In
14112 : : this case, we get better code if we sign extend. */
14113 : 8279 : if (GET_CODE (index) == SUBREG
14114 : 9 : && SUBREG_PROMOTED_VAR_P (index)
14115 : 0 : && SUBREG_PROMOTED_SIGNED_P (index)
14116 : 0 : && ((width = GET_MODE_PRECISION (as_a <scalar_int_mode> (mode)))
14117 : : <= HOST_BITS_PER_WIDE_INT)
14118 : 8279 : && ! (UINTVAL (range) & (HOST_WIDE_INT_1U << (width - 1))))
14119 : 0 : index = convert_to_mode (Pmode, index, 0);
14120 : : else
14121 : 8279 : index = convert_to_mode (Pmode, index, 1);
14122 : : }
14123 : :
14124 : : /* Don't let a MEM slip through, because then INDEX that comes
14125 : : out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
14126 : : and break_out_memory_refs will go to work on it and mess it up. */
14127 : : #ifdef PIC_CASE_VECTOR_ADDRESS
14128 : : if (flag_pic && !REG_P (index))
14129 : : index = copy_to_mode_reg (Pmode, index);
14130 : : #endif
14131 : :
14132 : : /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
14133 : : GET_MODE_SIZE, because this indicates how large insns are. The other
14134 : : uses should all be Pmode, because they are addresses. This code
14135 : : could fail if addresses and insns are not the same size. */
14136 : 10241 : index = simplify_gen_binary (MULT, Pmode, index,
14137 : 18542 : gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE),
14138 : 9271 : Pmode));
14139 : 10241 : index = simplify_gen_binary (PLUS, Pmode, index,
14140 : 9271 : gen_rtx_LABEL_REF (Pmode, table_label));
14141 : :
14142 : : #ifdef PIC_CASE_VECTOR_ADDRESS
14143 : : if (flag_pic)
14144 : : index = PIC_CASE_VECTOR_ADDRESS (index);
14145 : : else
14146 : : #endif
14147 : 10743 : index = memory_address (CASE_VECTOR_MODE, index);
14148 : 10743 : temp = gen_reg_rtx (CASE_VECTOR_MODE);
14149 : 10743 : vector = gen_const_mem (CASE_VECTOR_MODE, index);
14150 : 9271 : convert_move (temp, vector, 0);
14151 : :
14152 : 9271 : emit_jump_insn (targetm.gen_tablejump (temp, table_label));
14153 : :
14154 : : /* If we are generating PIC code or if the table is PC-relative, the
14155 : : table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
14156 : 9271 : if (! CASE_VECTOR_PC_RELATIVE && ! flag_pic)
14157 : 8299 : emit_barrier ();
14158 : 9271 : }
14159 : :
14160 : : bool
14161 : 9271 : try_tablejump (tree index_type, tree index_expr, tree minval, tree range,
14162 : : rtx table_label, rtx default_label,
14163 : : profile_probability default_probability)
14164 : : {
14165 : 9271 : rtx index;
14166 : :
14167 : 9271 : if (! targetm.have_tablejump ())
14168 : : return false;
14169 : :
14170 : 9271 : index_expr = fold_build2 (MINUS_EXPR, index_type,
14171 : : fold_convert (index_type, index_expr),
14172 : : fold_convert (index_type, minval));
14173 : 9271 : index = expand_normal (index_expr);
14174 : 9271 : do_pending_stack_adjust ();
14175 : :
14176 : 9271 : do_tablejump (index, TYPE_MODE (index_type),
14177 : 9271 : convert_modes (TYPE_MODE (index_type),
14178 : 9271 : TYPE_MODE (TREE_TYPE (range)),
14179 : : expand_normal (range),
14180 : 9271 : TYPE_UNSIGNED (TREE_TYPE (range))),
14181 : : table_label, default_label, default_probability);
14182 : 9271 : return true;
14183 : : }
14184 : :
14185 : : /* Return a CONST_VECTOR rtx representing vector mask for
14186 : : a VECTOR_CST of booleans. */
14187 : : static rtx
14188 : 33 : const_vector_mask_from_tree (tree exp)
14189 : : {
14190 : 33 : machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
14191 : 33 : machine_mode inner = GET_MODE_INNER (mode);
14192 : :
14193 : 33 : rtx_vector_builder builder (mode, VECTOR_CST_NPATTERNS (exp),
14194 : 33 : VECTOR_CST_NELTS_PER_PATTERN (exp));
14195 : 33 : unsigned int count = builder.encoded_nelts ();
14196 : 131 : for (unsigned int i = 0; i < count; ++i)
14197 : : {
14198 : 98 : tree elt = VECTOR_CST_ELT (exp, i);
14199 : 98 : gcc_assert (TREE_CODE (elt) == INTEGER_CST);
14200 : 98 : if (integer_zerop (elt))
14201 : 43 : builder.quick_push (CONST0_RTX (inner));
14202 : 55 : else if (integer_onep (elt)
14203 : 55 : || integer_minus_onep (elt))
14204 : 55 : builder.quick_push (CONSTM1_RTX (inner));
14205 : : else
14206 : 0 : gcc_unreachable ();
14207 : : }
14208 : 33 : return builder.build ();
14209 : 33 : }
14210 : :
14211 : : /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
14212 : : static rtx
14213 : 549165 : const_vector_from_tree (tree exp)
14214 : : {
14215 : 549165 : machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
14216 : :
14217 : 549165 : if (initializer_zerop (exp))
14218 : 165787 : return CONST0_RTX (mode);
14219 : :
14220 : 383378 : if (VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (exp)))
14221 : 33 : return const_vector_mask_from_tree (exp);
14222 : :
14223 : 383345 : machine_mode inner = GET_MODE_INNER (mode);
14224 : :
14225 : 383345 : rtx_vector_builder builder (mode, VECTOR_CST_NPATTERNS (exp),
14226 : 383345 : VECTOR_CST_NELTS_PER_PATTERN (exp));
14227 : 383345 : unsigned int count = builder.encoded_nelts ();
14228 : 1237335 : for (unsigned int i = 0; i < count; ++i)
14229 : : {
14230 : 853990 : tree elt = VECTOR_CST_ELT (exp, i);
14231 : 853990 : if (TREE_CODE (elt) == REAL_CST)
14232 : 133059 : builder.quick_push (const_double_from_real_value (TREE_REAL_CST (elt),
14233 : : inner));
14234 : 720931 : else if (TREE_CODE (elt) == FIXED_CST)
14235 : 0 : builder.quick_push (CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt),
14236 : : inner));
14237 : : else
14238 : 720931 : builder.quick_push (immed_wide_int_const (wi::to_poly_wide (elt),
14239 : : inner));
14240 : : }
14241 : 383345 : return builder.build ();
14242 : 383345 : }
14243 : :
14244 : : /* Build a decl for a personality function given a language prefix. */
14245 : :
14246 : : tree
14247 : 32417 : build_personality_function (const char *lang)
14248 : : {
14249 : 32417 : const char *unwind_and_version;
14250 : 32417 : tree decl, type;
14251 : 32417 : char *name;
14252 : :
14253 : 32417 : switch (targetm_common.except_unwind_info (&global_options))
14254 : : {
14255 : : case UI_NONE:
14256 : : return NULL;
14257 : : case UI_SJLJ:
14258 : : unwind_and_version = "_sj0";
14259 : : break;
14260 : 32417 : case UI_DWARF2:
14261 : 32417 : case UI_TARGET:
14262 : 32417 : unwind_and_version = "_v0";
14263 : 32417 : break;
14264 : 0 : case UI_SEH:
14265 : 0 : unwind_and_version = "_seh0";
14266 : 0 : break;
14267 : 0 : default:
14268 : 0 : gcc_unreachable ();
14269 : : }
14270 : :
14271 : 32417 : name = ACONCAT (("__", lang, "_personality", unwind_and_version, NULL));
14272 : :
14273 : 32417 : type = build_function_type_list (unsigned_type_node,
14274 : : integer_type_node, integer_type_node,
14275 : : long_long_unsigned_type_node,
14276 : : ptr_type_node, ptr_type_node, NULL_TREE);
14277 : 32417 : decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
14278 : : get_identifier (name), type);
14279 : 32417 : DECL_ARTIFICIAL (decl) = 1;
14280 : 32417 : DECL_EXTERNAL (decl) = 1;
14281 : 32417 : TREE_PUBLIC (decl) = 1;
14282 : :
14283 : : /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
14284 : : are the flags assigned by targetm.encode_section_info. */
14285 : 32417 : SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl), 0), NULL);
14286 : :
14287 : 32417 : return decl;
14288 : : }
14289 : :
14290 : : /* Extracts the personality function of DECL and returns the corresponding
14291 : : libfunc. */
14292 : :
14293 : : rtx
14294 : 1628612 : get_personality_function (tree decl)
14295 : : {
14296 : 1628612 : tree personality = DECL_FUNCTION_PERSONALITY (decl);
14297 : 1628612 : enum eh_personality_kind pk;
14298 : :
14299 : 1628612 : pk = function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl));
14300 : 1628612 : if (pk == eh_personality_none)
14301 : : return NULL;
14302 : :
14303 : 159324 : if (!personality
14304 : 159324 : && pk == eh_personality_any)
14305 : 75274 : personality = lang_hooks.eh_personality ();
14306 : :
14307 : 159324 : if (pk == eh_personality_lang)
14308 : 84050 : gcc_assert (personality != NULL_TREE);
14309 : :
14310 : 159324 : return XEXP (DECL_RTL (personality), 0);
14311 : : }
14312 : :
14313 : : /* Returns a tree for the size of EXP in bytes. */
14314 : :
14315 : : static tree
14316 : 14628088 : tree_expr_size (const_tree exp)
14317 : : {
14318 : 14628088 : if (DECL_P (exp)
14319 : 14628088 : && DECL_SIZE_UNIT (exp) != 0)
14320 : 1960377 : return DECL_SIZE_UNIT (exp);
14321 : : else
14322 : 12667711 : return size_in_bytes (TREE_TYPE (exp));
14323 : : }
14324 : :
14325 : : /* Return an rtx for the size in bytes of the value of EXP. */
14326 : :
14327 : : rtx
14328 : 14435220 : expr_size (tree exp)
14329 : : {
14330 : 14435220 : tree size;
14331 : :
14332 : 14435220 : if (TREE_CODE (exp) == WITH_SIZE_EXPR)
14333 : 767 : size = TREE_OPERAND (exp, 1);
14334 : : else
14335 : : {
14336 : 14434453 : size = tree_expr_size (exp);
14337 : 14434453 : gcc_assert (size);
14338 : 14434453 : gcc_assert (size == SUBSTITUTE_PLACEHOLDER_IN_EXPR (size, exp));
14339 : : }
14340 : :
14341 : 14435220 : return expand_expr (size, NULL_RTX, TYPE_MODE (sizetype), EXPAND_NORMAL);
14342 : : }
14343 : :
14344 : : /* Return a wide integer for the size in bytes of the value of EXP, or -1
14345 : : if the size can vary or is larger than an integer. */
14346 : :
14347 : : HOST_WIDE_INT
14348 : 193635 : int_expr_size (const_tree exp)
14349 : : {
14350 : 193635 : tree size;
14351 : :
14352 : 193635 : if (TREE_CODE (exp) == WITH_SIZE_EXPR)
14353 : 0 : size = TREE_OPERAND (exp, 1);
14354 : : else
14355 : : {
14356 : 193635 : size = tree_expr_size (exp);
14357 : 193635 : gcc_assert (size);
14358 : : }
14359 : :
14360 : 193635 : if (size == 0 || !tree_fits_shwi_p (size))
14361 : 0 : return -1;
14362 : :
14363 : 193635 : return tree_to_shwi (size);
14364 : : }
14365 : :
14366 : : /* Return the quotient of polynomial long division of x^2N by POLYNOMIAL
14367 : : in GF (2^N).
14368 : : Author: Richard Sandiford <richard.sandiford@arm.com> */
14369 : :
14370 : : unsigned HOST_WIDE_INT
14371 : 0 : gf2n_poly_long_div_quotient (unsigned HOST_WIDE_INT polynomial,
14372 : : unsigned short n)
14373 : : {
14374 : : /* The result has degree N, so needs N + 1 bits. */
14375 : 0 : gcc_assert (n < 64);
14376 : :
14377 : : /* Perform a division step for the x^2N coefficient. At this point the
14378 : : quotient and remainder have N implicit trailing zeros. */
14379 : : unsigned HOST_WIDE_INT quotient = 1;
14380 : : unsigned HOST_WIDE_INT remainder = polynomial;
14381 : :
14382 : : /* Process the coefficients for x^(2N-1) down to x^N, with each step
14383 : : reducing the number of implicit trailing zeros by one. */
14384 : 0 : for (unsigned int i = 0; i < n; ++i)
14385 : : {
14386 : 0 : bool coeff = remainder & (HOST_WIDE_INT_1U << (n - 1));
14387 : 0 : quotient = (quotient << 1) | coeff;
14388 : 0 : remainder = (remainder << 1) ^ (coeff ? polynomial : 0);
14389 : : }
14390 : 0 : return quotient;
14391 : : }
14392 : :
14393 : : /* Calculate CRC for the initial CRC and given POLYNOMIAL.
14394 : : CRC_BITS is CRC size. */
14395 : :
14396 : : static unsigned HOST_WIDE_INT
14397 : 69632 : calculate_crc (unsigned HOST_WIDE_INT crc,
14398 : : unsigned HOST_WIDE_INT polynomial,
14399 : : unsigned short crc_bits)
14400 : : {
14401 : 69632 : unsigned HOST_WIDE_INT msb = HOST_WIDE_INT_1U << (crc_bits - 1);
14402 : 69632 : crc = crc << (crc_bits - 8);
14403 : 626688 : for (short i = 8; i > 0; --i)
14404 : : {
14405 : 557056 : if (crc & msb)
14406 : 278528 : crc = (crc << 1) ^ polynomial;
14407 : : else
14408 : 278528 : crc <<= 1;
14409 : : }
14410 : : /* Zero out bits in crc beyond the specified number of crc_bits. */
14411 : 69632 : if (crc_bits < sizeof (crc) * CHAR_BIT)
14412 : 61184 : crc &= (HOST_WIDE_INT_1U << crc_bits) - 1;
14413 : 69632 : return crc;
14414 : : }
14415 : :
14416 : : /* Assemble CRC table with 256 elements for the given POLYNOM and CRC_BITS.
14417 : : POLYNOM is the polynomial used to calculate the CRC table's elements.
14418 : : CRC_BITS is the size of CRC, may be 8, 16, ... . */
14419 : :
14420 : : static rtx
14421 : 272 : assemble_crc_table (unsigned HOST_WIDE_INT polynom, unsigned short crc_bits)
14422 : : {
14423 : 272 : unsigned table_el_n = 0x100;
14424 : 272 : tree ar = build_array_type (make_unsigned_type (crc_bits),
14425 : 272 : build_index_type (size_int (table_el_n - 1)));
14426 : :
14427 : : /* Initialize the table. */
14428 : 272 : vec<tree, va_gc> *initial_values;
14429 : 272 : vec_alloc (initial_values, table_el_n);
14430 : 69904 : for (size_t i = 0; i < table_el_n; ++i)
14431 : : {
14432 : 69632 : unsigned HOST_WIDE_INT crc = calculate_crc (i, polynom, crc_bits);
14433 : 69632 : tree element = build_int_cstu (make_unsigned_type (crc_bits), crc);
14434 : 69632 : vec_safe_push (initial_values, element);
14435 : : }
14436 : 272 : tree ctor = build_constructor_from_vec (ar, initial_values);
14437 : 272 : rtx mem = output_constant_def (ctor, 1);
14438 : 272 : gcc_assert (MEM_P (mem));
14439 : 272 : if (dump_file && (dump_flags & TDF_DETAILS))
14440 : : {
14441 : 32 : fprintf (dump_file,
14442 : : ";; emitting crc table crc_%u_polynomial_"
14443 : : HOST_WIDE_INT_PRINT_HEX " ",
14444 : : crc_bits, polynom);
14445 : 32 : print_rtl_single (dump_file, XEXP (mem, 0));
14446 : 32 : fprintf (dump_file, "\n");
14447 : : }
14448 : :
14449 : 272 : return XEXP (mem, 0);
14450 : : }
14451 : :
14452 : : /* Generate CRC lookup table by calculating CRC for all possible
14453 : : 8-bit data values. The table is stored with a specific name in the read-only
14454 : : static data section.
14455 : : POLYNOM is the polynomial used to calculate the CRC table's elements.
14456 : : CRC_BITS is the size of CRC, may be 8, 16, ... . */
14457 : :
14458 : : static rtx
14459 : 272 : generate_crc_table (unsigned HOST_WIDE_INT polynom, unsigned short crc_bits)
14460 : : {
14461 : 272 : gcc_assert (crc_bits <= 64);
14462 : :
14463 : 272 : return assemble_crc_table (polynom, crc_bits);
14464 : : }
14465 : :
14466 : : /* Generate table-based CRC code for the given CRC, INPUT_DATA and the
14467 : : POLYNOMIAL (without leading 1).
14468 : :
14469 : : First, using POLYNOMIAL's value generates CRC table of 256 elements,
14470 : : then generates the assembly for the following code,
14471 : : where crc_bit_size and data_bit_size may be 8, 16, 32, 64, depending on CRC:
14472 : :
14473 : : for (int i = 0; i < data_bit_size / 8; i++)
14474 : : crc = (crc << 8) ^ crc_table[(crc >> (crc_bit_size - 8))
14475 : : ^ (data >> (data_bit_size - (i + 1) * 8)
14476 : : & 0xFF))];
14477 : :
14478 : : So to take values from the table, we need 8-bit data.
14479 : : If input data size is not 8, then first we extract upper 8 bits,
14480 : : then the other 8 bits, and so on. */
14481 : :
14482 : : static void
14483 : 272 : calculate_table_based_CRC (rtx *crc, const rtx &input_data,
14484 : : const rtx &polynomial,
14485 : : machine_mode data_mode)
14486 : : {
14487 : 272 : machine_mode mode = GET_MODE (*crc);
14488 : 272 : unsigned short crc_bit_size = GET_MODE_BITSIZE (mode).to_constant ();
14489 : 272 : unsigned short data_size = GET_MODE_SIZE (data_mode).to_constant ();
14490 : 272 : rtx tab = generate_crc_table (UINTVAL (polynomial), crc_bit_size);
14491 : :
14492 : 744 : for (unsigned short i = 0; i < data_size; i++)
14493 : : {
14494 : : /* crc >> (crc_bit_size - 8). */
14495 : 472 : *crc = force_reg (mode, *crc);
14496 : 472 : rtx op1 = expand_shift (RSHIFT_EXPR, mode, *crc, crc_bit_size - 8,
14497 : : NULL_RTX, 1);
14498 : :
14499 : : /* data >> (8 * (GET_MODE_SIZE (data_mode).to_constant () - i - 1)). */
14500 : 472 : unsigned range_8 = 8 * (data_size - i - 1);
14501 : : /* CRC's mode is always at least as wide as INPUT_DATA. Convert
14502 : : INPUT_DATA into CRC's mode. */
14503 : 472 : rtx data = gen_reg_rtx (mode);
14504 : 472 : convert_move (data, input_data, 1);
14505 : 472 : data = expand_shift (RSHIFT_EXPR, mode, data, range_8, NULL_RTX, 1);
14506 : :
14507 : : /* data >> (8 * (GET_MODE_SIZE (mode)
14508 : : .to_constant () - i - 1)) & 0xFF. */
14509 : 472 : rtx data_final = expand_and (mode, data,
14510 : : gen_int_mode (255, mode), NULL_RTX);
14511 : :
14512 : : /* (crc >> (crc_bit_size - 8)) ^ data_8bit. */
14513 : 472 : rtx in = expand_binop (mode, xor_optab, op1, data_final,
14514 : : NULL_RTX, 1, OPTAB_WIDEN);
14515 : :
14516 : : /* ((crc >> (crc_bit_size - 8)) ^ data_8bit) & 0xFF. */
14517 : 472 : rtx index = expand_and (mode, in, gen_int_mode (255, mode),
14518 : : NULL_RTX);
14519 : 944 : int log_crc_size = exact_log2 (GET_MODE_SIZE (mode).to_constant ());
14520 : 472 : index = expand_shift (LSHIFT_EXPR, mode, index,
14521 : 472 : log_crc_size, NULL_RTX, 0);
14522 : :
14523 : 490 : rtx addr = gen_reg_rtx (Pmode);
14524 : 472 : convert_move (addr, index, 1);
14525 : 490 : addr = expand_binop (Pmode, add_optab, addr, tab, NULL_RTX,
14526 : : 0, OPTAB_DIRECT);
14527 : :
14528 : : /* crc_table[(crc >> (crc_bit_size - 8)) ^ data_8bit] */
14529 : 472 : rtx tab_el = validize_mem (gen_rtx_MEM (mode, addr));
14530 : :
14531 : : /* (crc << 8) if CRC is larger than 8, otherwise crc = 0. */
14532 : 472 : rtx high = NULL_RTX;
14533 : 472 : if (crc_bit_size != 8)
14534 : 433 : high = expand_shift (LSHIFT_EXPR, mode, *crc, 8, NULL_RTX, 0);
14535 : : else
14536 : 39 : high = gen_int_mode (0, mode);
14537 : :
14538 : : /* crc = (crc << 8)
14539 : : ^ crc_table[(crc >> (crc_bit_size - 8)) ^ data_8bit]; */
14540 : 472 : *crc = expand_binop (mode, xor_optab, tab_el, high, NULL_RTX, 1,
14541 : : OPTAB_WIDEN);
14542 : : }
14543 : 272 : }
14544 : :
14545 : : /* Generate table-based CRC code for the given CRC, INPUT_DATA and the
14546 : : POLYNOMIAL (without leading 1).
14547 : :
14548 : : CRC is OP1, data is OP2 and the polynomial is OP3.
14549 : : This must generate a CRC table and an assembly for the following code,
14550 : : where crc_bit_size and data_bit_size may be 8, 16, 32, 64:
14551 : : uint_crc_bit_size_t
14552 : : crc_crc_bit_size (uint_crc_bit_size_t crc_init,
14553 : : uint_data_bit_size_t data, size_t size)
14554 : : {
14555 : : uint_crc_bit_size_t crc = crc_init;
14556 : : for (int i = 0; i < data_bit_size / 8; i++)
14557 : : crc = (crc << 8) ^ crc_table[(crc >> (crc_bit_size - 8))
14558 : : ^ (data >> (data_bit_size - (i + 1) * 8)
14559 : : & 0xFF))];
14560 : : return crc;
14561 : : } */
14562 : :
14563 : : void
14564 : 135 : expand_crc_table_based (rtx op0, rtx op1, rtx op2, rtx op3,
14565 : : machine_mode data_mode)
14566 : : {
14567 : 135 : gcc_assert (!CONST_INT_P (op0));
14568 : 135 : gcc_assert (CONST_INT_P (op3));
14569 : 135 : machine_mode crc_mode = GET_MODE (op0);
14570 : 135 : rtx crc = gen_reg_rtx (crc_mode);
14571 : 135 : convert_move (crc, op1, 0);
14572 : 135 : calculate_table_based_CRC (&crc, op2, op3, data_mode);
14573 : 135 : convert_move (op0, crc, 0);
14574 : 135 : }
14575 : :
14576 : : /* Generate the common operation for reflecting values:
14577 : : *OP = (*OP & AND1_VALUE) << SHIFT_VAL | (*OP & AND2_VALUE) >> SHIFT_VAL; */
14578 : :
14579 : : void
14580 : 1744 : gen_common_operation_to_reflect (rtx *op,
14581 : : unsigned HOST_WIDE_INT and1_value,
14582 : : unsigned HOST_WIDE_INT and2_value,
14583 : : unsigned shift_val)
14584 : : {
14585 : 1744 : rtx op1 = expand_and (GET_MODE (*op), *op,
14586 : 1744 : gen_int_mode (and1_value, GET_MODE (*op)), NULL_RTX);
14587 : 1744 : op1 = expand_shift (LSHIFT_EXPR, GET_MODE (*op), op1, shift_val, op1, 0);
14588 : 1744 : rtx op2 = expand_and (GET_MODE (*op), *op,
14589 : 1744 : gen_int_mode (and2_value, GET_MODE (*op)), NULL_RTX);
14590 : 1744 : op2 = expand_shift (RSHIFT_EXPR, GET_MODE (*op), op2, shift_val, op2, 1);
14591 : 1744 : *op = expand_binop (GET_MODE (*op), ior_optab, op1,
14592 : : op2, *op, 0, OPTAB_LIB_WIDEN);
14593 : 1744 : }
14594 : :
14595 : : /* Reflect 64-bit value for the 64-bit target. */
14596 : :
14597 : : void
14598 : 47 : reflect_64_bit_value (rtx *op)
14599 : : {
14600 : 47 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x00000000FFFFFFFF),
14601 : : HOST_WIDE_INT_C (0xFFFFFFFF00000000), 32);
14602 : 47 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x0000FFFF0000FFFF),
14603 : : HOST_WIDE_INT_C (0xFFFF0000FFFF0000), 16);
14604 : 47 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x00FF00FF00FF00FF),
14605 : : HOST_WIDE_INT_C (0xFF00FF00FF00FF00), 8);
14606 : 47 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x0F0F0F0F0F0F0F0F),
14607 : : HOST_WIDE_INT_C (0xF0F0F0F0F0F0F0F0), 4);
14608 : 47 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x3333333333333333),
14609 : : HOST_WIDE_INT_C (0xCCCCCCCCCCCCCCCC), 2);
14610 : 47 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x5555555555555555),
14611 : : HOST_WIDE_INT_C (0xAAAAAAAAAAAAAAAA), 1);
14612 : 47 : }
14613 : :
14614 : : /* Reflect 32-bit value for the 32-bit target. */
14615 : :
14616 : : void
14617 : 131 : reflect_32_bit_value (rtx *op)
14618 : : {
14619 : 131 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x0000FFFF),
14620 : : HOST_WIDE_INT_C (0xFFFF0000), 16);
14621 : 131 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x00FF00FF),
14622 : : HOST_WIDE_INT_C (0xFF00FF00), 8);
14623 : 131 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x0F0F0F0F),
14624 : : HOST_WIDE_INT_C (0xF0F0F0F0), 4);
14625 : 131 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x33333333),
14626 : : HOST_WIDE_INT_C (0xCCCCCCCC), 2);
14627 : 131 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x55555555),
14628 : : HOST_WIDE_INT_C (0xAAAAAAAA), 1);
14629 : 131 : }
14630 : :
14631 : : /* Reflect 16-bit value for the 16-bit target. */
14632 : :
14633 : : void
14634 : 108 : reflect_16_bit_value (rtx *op)
14635 : : {
14636 : 108 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x00FF),
14637 : : HOST_WIDE_INT_C (0xFF00), 8);
14638 : 108 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x0F0F),
14639 : : HOST_WIDE_INT_C (0xF0F0), 4);
14640 : 108 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x3333),
14641 : : HOST_WIDE_INT_C (0xCCCC), 2);
14642 : 108 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x5555),
14643 : : HOST_WIDE_INT_C (0xAAAA), 1);
14644 : 108 : }
14645 : :
14646 : : /* Reflect 8-bit value for the 8-bit target. */
14647 : :
14648 : : void
14649 : 125 : reflect_8_bit_value (rtx *op)
14650 : : {
14651 : 125 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x0F),
14652 : : HOST_WIDE_INT_C (0xF0), 4);
14653 : 125 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x33),
14654 : : HOST_WIDE_INT_C (0xCC), 2);
14655 : 125 : gen_common_operation_to_reflect (op, HOST_WIDE_INT_C (0x55),
14656 : : HOST_WIDE_INT_C (0xAA), 1);
14657 : 125 : }
14658 : :
14659 : : /* Generate instruction sequence which reflects the value of the OP
14660 : : using shift, and, or operations. OP's mode may be less than word_mode. */
14661 : :
14662 : : void
14663 : 411 : generate_reflecting_code_standard (rtx *op)
14664 : : {
14665 : 1233 : gcc_assert (GET_MODE_BITSIZE (GET_MODE (*op)).to_constant () >= 8
14666 : : && GET_MODE_BITSIZE (GET_MODE (*op)).to_constant () <= 64);
14667 : :
14668 : 822 : if (GET_MODE_BITSIZE (GET_MODE (*op)).to_constant () == 64)
14669 : 47 : reflect_64_bit_value (op);
14670 : 728 : else if (GET_MODE_BITSIZE (GET_MODE (*op)).to_constant () == 32)
14671 : 131 : reflect_32_bit_value (op);
14672 : 466 : else if (GET_MODE_BITSIZE (GET_MODE (*op)).to_constant () == 16)
14673 : 108 : reflect_16_bit_value (op);
14674 : : else
14675 : 125 : reflect_8_bit_value (op);
14676 : 411 : }
14677 : :
14678 : : /* Generate table-based reversed CRC code for the given CRC, INPUT_DATA and
14679 : : the POLYNOMIAL (without leading 1).
14680 : :
14681 : : CRC is OP1, data is OP2 and the polynomial is OP3.
14682 : : This must generate CRC table and assembly for the following code,
14683 : : where crc_bit_size and data_bit_size may be 8, 16, 32, 64:
14684 : : uint_crc_bit_size_t
14685 : : crc_crc_bit_size (uint_crc_bit_size_t crc_init,
14686 : : uint_data_bit_size_t data, size_t size)
14687 : : {
14688 : : reflect (crc_init)
14689 : : uint_crc_bit_size_t crc = crc_init;
14690 : : reflect (data);
14691 : : for (int i = 0; i < data_bit_size / 8; i++)
14692 : : crc = (crc << 8) ^ crc_table[(crc >> (crc_bit_size - 8))
14693 : : ^ (data >> (data_bit_size - (i + 1) * 8) & 0xFF))];
14694 : : reflect (crc);
14695 : : return crc;
14696 : : } */
14697 : :
14698 : : void
14699 : 137 : expand_reversed_crc_table_based (rtx op0, rtx op1, rtx op2, rtx op3,
14700 : : machine_mode data_mode,
14701 : : void (*gen_reflecting_code) (rtx *op))
14702 : : {
14703 : 137 : gcc_assert (!CONST_INT_P (op0));
14704 : 137 : gcc_assert (CONST_INT_P (op3));
14705 : 137 : machine_mode crc_mode = GET_MODE (op0);
14706 : :
14707 : 137 : rtx crc = gen_reg_rtx (crc_mode);
14708 : 137 : convert_move (crc, op1, 0);
14709 : 137 : gen_reflecting_code (&crc);
14710 : :
14711 : 137 : rtx data = gen_reg_rtx (data_mode);
14712 : 137 : convert_move (data, op2, 0);
14713 : 137 : gen_reflecting_code (&data);
14714 : :
14715 : 137 : calculate_table_based_CRC (&crc, data, op3, data_mode);
14716 : :
14717 : 137 : gen_reflecting_code (&crc);
14718 : 137 : convert_move (op0, crc, 0);
14719 : 137 : }
|