Clean up some minor white space issues in trans-decl.c and trans-expr.c
[official-gcc.git] / gcc / expr.c
blob8123cc2d01bc72736d4af503fa50c89aff488106
1 /* Convert tree expression to rtl instructions, for GNU compiler.
2 Copyright (C) 1988-2016 Free Software Foundation, Inc.
4 This file is part of GCC.
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.
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.
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/>. */
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 "tm_p.h"
30 #include "ssa.h"
31 #include "expmed.h"
32 #include "optabs.h"
33 #include "regs.h"
34 #include "emit-rtl.h"
35 #include "recog.h"
36 #include "cgraph.h"
37 #include "diagnostic.h"
38 #include "alias.h"
39 #include "fold-const.h"
40 #include "stor-layout.h"
41 #include "attribs.h"
42 #include "varasm.h"
43 #include "except.h"
44 #include "insn-attr.h"
45 #include "dojump.h"
46 #include "explow.h"
47 #include "calls.h"
48 #include "stmt.h"
49 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
50 #include "expr.h"
51 #include "optabs-tree.h"
52 #include "libfuncs.h"
53 #include "reload.h"
54 #include "langhooks.h"
55 #include "common/common-target.h"
56 #include "tree-ssa-live.h"
57 #include "tree-outof-ssa.h"
58 #include "tree-ssa-address.h"
59 #include "builtins.h"
60 #include "tree-chkp.h"
61 #include "rtl-chkp.h"
62 #include "ccmp.h"
65 /* If this is nonzero, we do not bother generating VOLATILE
66 around volatile memory references, and we are willing to
67 output indirect addresses. If cse is to follow, we reject
68 indirect addresses so a useful potential cse is generated;
69 if it is used only once, instruction combination will produce
70 the same indirect address eventually. */
71 int cse_not_expected;
73 /* This structure is used by move_by_pieces to describe the move to
74 be performed. */
75 struct move_by_pieces_d
77 rtx to;
78 rtx to_addr;
79 int autinc_to;
80 int explicit_inc_to;
81 rtx from;
82 rtx from_addr;
83 int autinc_from;
84 int explicit_inc_from;
85 unsigned HOST_WIDE_INT len;
86 HOST_WIDE_INT offset;
87 int reverse;
90 /* This structure is used by store_by_pieces to describe the clear to
91 be performed. */
93 struct store_by_pieces_d
95 rtx to;
96 rtx to_addr;
97 int autinc_to;
98 int explicit_inc_to;
99 unsigned HOST_WIDE_INT len;
100 HOST_WIDE_INT offset;
101 rtx (*constfun) (void *, HOST_WIDE_INT, machine_mode);
102 void *constfundata;
103 int reverse;
106 static void move_by_pieces_1 (insn_gen_fn, machine_mode,
107 struct move_by_pieces_d *);
108 static bool block_move_libcall_safe_for_call_parm (void);
109 static bool emit_block_move_via_movmem (rtx, rtx, rtx, unsigned, unsigned, HOST_WIDE_INT,
110 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT,
111 unsigned HOST_WIDE_INT);
112 static tree emit_block_move_libcall_fn (int);
113 static void emit_block_move_via_loop (rtx, rtx, rtx, unsigned);
114 static rtx clear_by_pieces_1 (void *, HOST_WIDE_INT, machine_mode);
115 static void clear_by_pieces (rtx, unsigned HOST_WIDE_INT, unsigned int);
116 static void store_by_pieces_1 (struct store_by_pieces_d *, unsigned int);
117 static void store_by_pieces_2 (insn_gen_fn, machine_mode,
118 struct store_by_pieces_d *);
119 static tree clear_storage_libcall_fn (int);
120 static rtx_insn *compress_float_constant (rtx, rtx);
121 static rtx get_subtarget (rtx);
122 static void store_constructor_field (rtx, unsigned HOST_WIDE_INT,
123 HOST_WIDE_INT, machine_mode,
124 tree, int, alias_set_type, bool);
125 static void store_constructor (tree, rtx, int, HOST_WIDE_INT, bool);
126 static rtx store_field (rtx, HOST_WIDE_INT, HOST_WIDE_INT,
127 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT,
128 machine_mode, tree, alias_set_type, bool, bool);
130 static unsigned HOST_WIDE_INT highest_pow2_factor_for_target (const_tree, const_tree);
132 static int is_aligning_offset (const_tree, const_tree);
133 static rtx reduce_to_bit_field_precision (rtx, rtx, tree);
134 static rtx do_store_flag (sepops, rtx, machine_mode);
135 #ifdef PUSH_ROUNDING
136 static void emit_single_push_insn (machine_mode, rtx, tree);
137 #endif
138 static void do_tablejump (rtx, machine_mode, rtx, rtx, rtx, int);
139 static rtx const_vector_from_tree (tree);
140 static rtx const_scalar_mask_from_tree (tree);
141 static tree tree_expr_size (const_tree);
142 static HOST_WIDE_INT int_expr_size (tree);
145 /* This is run to set up which modes can be used
146 directly in memory and to initialize the block move optab. It is run
147 at the beginning of compilation and when the target is reinitialized. */
149 void
150 init_expr_target (void)
152 rtx insn, pat;
153 machine_mode mode;
154 int num_clobbers;
155 rtx mem, mem1;
156 rtx reg;
158 /* Try indexing by frame ptr and try by stack ptr.
159 It is known that on the Convex the stack ptr isn't a valid index.
160 With luck, one or the other is valid on any machine. */
161 mem = gen_rtx_MEM (word_mode, stack_pointer_rtx);
162 mem1 = gen_rtx_MEM (word_mode, frame_pointer_rtx);
164 /* A scratch register we can modify in-place below to avoid
165 useless RTL allocations. */
166 reg = gen_rtx_REG (word_mode, LAST_VIRTUAL_REGISTER + 1);
168 insn = rtx_alloc (INSN);
169 pat = gen_rtx_SET (NULL_RTX, NULL_RTX);
170 PATTERN (insn) = pat;
172 for (mode = VOIDmode; (int) mode < NUM_MACHINE_MODES;
173 mode = (machine_mode) ((int) mode + 1))
175 int regno;
177 direct_load[(int) mode] = direct_store[(int) mode] = 0;
178 PUT_MODE (mem, mode);
179 PUT_MODE (mem1, mode);
181 /* See if there is some register that can be used in this mode and
182 directly loaded or stored from memory. */
184 if (mode != VOIDmode && mode != BLKmode)
185 for (regno = 0; regno < FIRST_PSEUDO_REGISTER
186 && (direct_load[(int) mode] == 0 || direct_store[(int) mode] == 0);
187 regno++)
189 if (! HARD_REGNO_MODE_OK (regno, mode))
190 continue;
192 set_mode_and_regno (reg, mode, regno);
194 SET_SRC (pat) = mem;
195 SET_DEST (pat) = reg;
196 if (recog (pat, insn, &num_clobbers) >= 0)
197 direct_load[(int) mode] = 1;
199 SET_SRC (pat) = mem1;
200 SET_DEST (pat) = reg;
201 if (recog (pat, insn, &num_clobbers) >= 0)
202 direct_load[(int) mode] = 1;
204 SET_SRC (pat) = reg;
205 SET_DEST (pat) = mem;
206 if (recog (pat, insn, &num_clobbers) >= 0)
207 direct_store[(int) mode] = 1;
209 SET_SRC (pat) = reg;
210 SET_DEST (pat) = mem1;
211 if (recog (pat, insn, &num_clobbers) >= 0)
212 direct_store[(int) mode] = 1;
216 mem = gen_rtx_MEM (VOIDmode, gen_raw_REG (Pmode, LAST_VIRTUAL_REGISTER + 1));
218 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
219 mode = GET_MODE_WIDER_MODE (mode))
221 machine_mode srcmode;
222 for (srcmode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); srcmode != mode;
223 srcmode = GET_MODE_WIDER_MODE (srcmode))
225 enum insn_code ic;
227 ic = can_extend_p (mode, srcmode, 0);
228 if (ic == CODE_FOR_nothing)
229 continue;
231 PUT_MODE (mem, srcmode);
233 if (insn_operand_matches (ic, 1, mem))
234 float_extend_from_mem[mode][srcmode] = true;
239 /* This is run at the start of compiling a function. */
241 void
242 init_expr (void)
244 memset (&crtl->expr, 0, sizeof (crtl->expr));
247 /* Copy data from FROM to TO, where the machine modes are not the same.
248 Both modes may be integer, or both may be floating, or both may be
249 fixed-point.
250 UNSIGNEDP should be nonzero if FROM is an unsigned type.
251 This causes zero-extension instead of sign-extension. */
253 void
254 convert_move (rtx to, rtx from, int unsignedp)
256 machine_mode to_mode = GET_MODE (to);
257 machine_mode from_mode = GET_MODE (from);
258 int to_real = SCALAR_FLOAT_MODE_P (to_mode);
259 int from_real = SCALAR_FLOAT_MODE_P (from_mode);
260 enum insn_code code;
261 rtx libcall;
263 /* rtx code for making an equivalent value. */
264 enum rtx_code equiv_code = (unsignedp < 0 ? UNKNOWN
265 : (unsignedp ? ZERO_EXTEND : SIGN_EXTEND));
268 gcc_assert (to_real == from_real);
269 gcc_assert (to_mode != BLKmode);
270 gcc_assert (from_mode != BLKmode);
272 /* If the source and destination are already the same, then there's
273 nothing to do. */
274 if (to == from)
275 return;
277 /* If FROM is a SUBREG that indicates that we have already done at least
278 the required extension, strip it. We don't handle such SUBREGs as
279 TO here. */
281 if (GET_CODE (from) == SUBREG && SUBREG_PROMOTED_VAR_P (from)
282 && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (from)))
283 >= GET_MODE_PRECISION (to_mode))
284 && SUBREG_CHECK_PROMOTED_SIGN (from, unsignedp))
285 from = gen_lowpart (to_mode, from), from_mode = to_mode;
287 gcc_assert (GET_CODE (to) != SUBREG || !SUBREG_PROMOTED_VAR_P (to));
289 if (to_mode == from_mode
290 || (from_mode == VOIDmode && CONSTANT_P (from)))
292 emit_move_insn (to, from);
293 return;
296 if (VECTOR_MODE_P (to_mode) || VECTOR_MODE_P (from_mode))
298 gcc_assert (GET_MODE_BITSIZE (from_mode) == GET_MODE_BITSIZE (to_mode));
300 if (VECTOR_MODE_P (to_mode))
301 from = simplify_gen_subreg (to_mode, from, GET_MODE (from), 0);
302 else
303 to = simplify_gen_subreg (from_mode, to, GET_MODE (to), 0);
305 emit_move_insn (to, from);
306 return;
309 if (GET_CODE (to) == CONCAT && GET_CODE (from) == CONCAT)
311 convert_move (XEXP (to, 0), XEXP (from, 0), unsignedp);
312 convert_move (XEXP (to, 1), XEXP (from, 1), unsignedp);
313 return;
316 if (to_real)
318 rtx value;
319 rtx_insn *insns;
320 convert_optab tab;
322 gcc_assert ((GET_MODE_PRECISION (from_mode)
323 != GET_MODE_PRECISION (to_mode))
324 || (DECIMAL_FLOAT_MODE_P (from_mode)
325 != DECIMAL_FLOAT_MODE_P (to_mode)));
327 if (GET_MODE_PRECISION (from_mode) == GET_MODE_PRECISION (to_mode))
328 /* Conversion between decimal float and binary float, same size. */
329 tab = DECIMAL_FLOAT_MODE_P (from_mode) ? trunc_optab : sext_optab;
330 else if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode))
331 tab = sext_optab;
332 else
333 tab = trunc_optab;
335 /* Try converting directly if the insn is supported. */
337 code = convert_optab_handler (tab, to_mode, from_mode);
338 if (code != CODE_FOR_nothing)
340 emit_unop_insn (code, to, from,
341 tab == sext_optab ? FLOAT_EXTEND : FLOAT_TRUNCATE);
342 return;
345 /* Otherwise use a libcall. */
346 libcall = convert_optab_libfunc (tab, to_mode, from_mode);
348 /* Is this conversion implemented yet? */
349 gcc_assert (libcall);
351 start_sequence ();
352 value = emit_library_call_value (libcall, NULL_RTX, LCT_CONST, to_mode,
353 1, from, from_mode);
354 insns = get_insns ();
355 end_sequence ();
356 emit_libcall_block (insns, to, value,
357 tab == trunc_optab ? gen_rtx_FLOAT_TRUNCATE (to_mode,
358 from)
359 : gen_rtx_FLOAT_EXTEND (to_mode, from));
360 return;
363 /* Handle pointer conversion. */ /* SPEE 900220. */
364 /* If the target has a converter from FROM_MODE to TO_MODE, use it. */
366 convert_optab ctab;
368 if (GET_MODE_PRECISION (from_mode) > GET_MODE_PRECISION (to_mode))
369 ctab = trunc_optab;
370 else if (unsignedp)
371 ctab = zext_optab;
372 else
373 ctab = sext_optab;
375 if (convert_optab_handler (ctab, to_mode, from_mode)
376 != CODE_FOR_nothing)
378 emit_unop_insn (convert_optab_handler (ctab, to_mode, from_mode),
379 to, from, UNKNOWN);
380 return;
384 /* Targets are expected to provide conversion insns between PxImode and
385 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
386 if (GET_MODE_CLASS (to_mode) == MODE_PARTIAL_INT)
388 machine_mode full_mode
389 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode), MODE_INT);
391 gcc_assert (convert_optab_handler (trunc_optab, to_mode, full_mode)
392 != CODE_FOR_nothing);
394 if (full_mode != from_mode)
395 from = convert_to_mode (full_mode, from, unsignedp);
396 emit_unop_insn (convert_optab_handler (trunc_optab, to_mode, full_mode),
397 to, from, UNKNOWN);
398 return;
400 if (GET_MODE_CLASS (from_mode) == MODE_PARTIAL_INT)
402 rtx new_from;
403 machine_mode full_mode
404 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode), MODE_INT);
405 convert_optab ctab = unsignedp ? zext_optab : sext_optab;
406 enum insn_code icode;
408 icode = convert_optab_handler (ctab, full_mode, from_mode);
409 gcc_assert (icode != CODE_FOR_nothing);
411 if (to_mode == full_mode)
413 emit_unop_insn (icode, to, from, UNKNOWN);
414 return;
417 new_from = gen_reg_rtx (full_mode);
418 emit_unop_insn (icode, new_from, from, UNKNOWN);
420 /* else proceed to integer conversions below. */
421 from_mode = full_mode;
422 from = new_from;
425 /* Make sure both are fixed-point modes or both are not. */
426 gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode) ==
427 ALL_SCALAR_FIXED_POINT_MODE_P (to_mode));
428 if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode))
430 /* If we widen from_mode to to_mode and they are in the same class,
431 we won't saturate the result.
432 Otherwise, always saturate the result to play safe. */
433 if (GET_MODE_CLASS (from_mode) == GET_MODE_CLASS (to_mode)
434 && GET_MODE_SIZE (from_mode) < GET_MODE_SIZE (to_mode))
435 expand_fixed_convert (to, from, 0, 0);
436 else
437 expand_fixed_convert (to, from, 0, 1);
438 return;
441 /* Now both modes are integers. */
443 /* Handle expanding beyond a word. */
444 if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode)
445 && GET_MODE_PRECISION (to_mode) > BITS_PER_WORD)
447 rtx_insn *insns;
448 rtx lowpart;
449 rtx fill_value;
450 rtx lowfrom;
451 int i;
452 machine_mode lowpart_mode;
453 int nwords = CEIL (GET_MODE_SIZE (to_mode), UNITS_PER_WORD);
455 /* Try converting directly if the insn is supported. */
456 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
457 != CODE_FOR_nothing)
459 /* If FROM is a SUBREG, put it into a register. Do this
460 so that we always generate the same set of insns for
461 better cse'ing; if an intermediate assignment occurred,
462 we won't be doing the operation directly on the SUBREG. */
463 if (optimize > 0 && GET_CODE (from) == SUBREG)
464 from = force_reg (from_mode, from);
465 emit_unop_insn (code, to, from, equiv_code);
466 return;
468 /* Next, try converting via full word. */
469 else if (GET_MODE_PRECISION (from_mode) < BITS_PER_WORD
470 && ((code = can_extend_p (to_mode, word_mode, unsignedp))
471 != CODE_FOR_nothing))
473 rtx word_to = gen_reg_rtx (word_mode);
474 if (REG_P (to))
476 if (reg_overlap_mentioned_p (to, from))
477 from = force_reg (from_mode, from);
478 emit_clobber (to);
480 convert_move (word_to, from, unsignedp);
481 emit_unop_insn (code, to, word_to, equiv_code);
482 return;
485 /* No special multiword conversion insn; do it by hand. */
486 start_sequence ();
488 /* Since we will turn this into a no conflict block, we must ensure the
489 the source does not overlap the target so force it into an isolated
490 register when maybe so. Likewise for any MEM input, since the
491 conversion sequence might require several references to it and we
492 must ensure we're getting the same value every time. */
494 if (MEM_P (from) || reg_overlap_mentioned_p (to, from))
495 from = force_reg (from_mode, from);
497 /* Get a copy of FROM widened to a word, if necessary. */
498 if (GET_MODE_PRECISION (from_mode) < BITS_PER_WORD)
499 lowpart_mode = word_mode;
500 else
501 lowpart_mode = from_mode;
503 lowfrom = convert_to_mode (lowpart_mode, from, unsignedp);
505 lowpart = gen_lowpart (lowpart_mode, to);
506 emit_move_insn (lowpart, lowfrom);
508 /* Compute the value to put in each remaining word. */
509 if (unsignedp)
510 fill_value = const0_rtx;
511 else
512 fill_value = emit_store_flag_force (gen_reg_rtx (word_mode),
513 LT, lowfrom, const0_rtx,
514 lowpart_mode, 0, -1);
516 /* Fill the remaining words. */
517 for (i = GET_MODE_SIZE (lowpart_mode) / UNITS_PER_WORD; i < nwords; i++)
519 int index = (WORDS_BIG_ENDIAN ? nwords - i - 1 : i);
520 rtx subword = operand_subword (to, index, 1, to_mode);
522 gcc_assert (subword);
524 if (fill_value != subword)
525 emit_move_insn (subword, fill_value);
528 insns = get_insns ();
529 end_sequence ();
531 emit_insn (insns);
532 return;
535 /* Truncating multi-word to a word or less. */
536 if (GET_MODE_PRECISION (from_mode) > BITS_PER_WORD
537 && GET_MODE_PRECISION (to_mode) <= BITS_PER_WORD)
539 if (!((MEM_P (from)
540 && ! MEM_VOLATILE_P (from)
541 && direct_load[(int) to_mode]
542 && ! mode_dependent_address_p (XEXP (from, 0),
543 MEM_ADDR_SPACE (from)))
544 || REG_P (from)
545 || GET_CODE (from) == SUBREG))
546 from = force_reg (from_mode, from);
547 convert_move (to, gen_lowpart (word_mode, from), 0);
548 return;
551 /* Now follow all the conversions between integers
552 no more than a word long. */
554 /* For truncation, usually we can just refer to FROM in a narrower mode. */
555 if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode)
556 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode, from_mode))
558 if (!((MEM_P (from)
559 && ! MEM_VOLATILE_P (from)
560 && direct_load[(int) to_mode]
561 && ! mode_dependent_address_p (XEXP (from, 0),
562 MEM_ADDR_SPACE (from)))
563 || REG_P (from)
564 || GET_CODE (from) == SUBREG))
565 from = force_reg (from_mode, from);
566 if (REG_P (from) && REGNO (from) < FIRST_PSEUDO_REGISTER
567 && ! HARD_REGNO_MODE_OK (REGNO (from), to_mode))
568 from = copy_to_reg (from);
569 emit_move_insn (to, gen_lowpart (to_mode, from));
570 return;
573 /* Handle extension. */
574 if (GET_MODE_PRECISION (to_mode) > GET_MODE_PRECISION (from_mode))
576 /* Convert directly if that works. */
577 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
578 != CODE_FOR_nothing)
580 emit_unop_insn (code, to, from, equiv_code);
581 return;
583 else
585 machine_mode intermediate;
586 rtx tmp;
587 int shift_amount;
589 /* Search for a mode to convert via. */
590 for (intermediate = from_mode; intermediate != VOIDmode;
591 intermediate = GET_MODE_WIDER_MODE (intermediate))
592 if (((can_extend_p (to_mode, intermediate, unsignedp)
593 != CODE_FOR_nothing)
594 || (GET_MODE_SIZE (to_mode) < GET_MODE_SIZE (intermediate)
595 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode, intermediate)))
596 && (can_extend_p (intermediate, from_mode, unsignedp)
597 != CODE_FOR_nothing))
599 convert_move (to, convert_to_mode (intermediate, from,
600 unsignedp), unsignedp);
601 return;
604 /* No suitable intermediate mode.
605 Generate what we need with shifts. */
606 shift_amount = (GET_MODE_PRECISION (to_mode)
607 - GET_MODE_PRECISION (from_mode));
608 from = gen_lowpart (to_mode, force_reg (from_mode, from));
609 tmp = expand_shift (LSHIFT_EXPR, to_mode, from, shift_amount,
610 to, unsignedp);
611 tmp = expand_shift (RSHIFT_EXPR, to_mode, tmp, shift_amount,
612 to, unsignedp);
613 if (tmp != to)
614 emit_move_insn (to, tmp);
615 return;
619 /* Support special truncate insns for certain modes. */
620 if (convert_optab_handler (trunc_optab, to_mode,
621 from_mode) != CODE_FOR_nothing)
623 emit_unop_insn (convert_optab_handler (trunc_optab, to_mode, from_mode),
624 to, from, UNKNOWN);
625 return;
628 /* Handle truncation of volatile memrefs, and so on;
629 the things that couldn't be truncated directly,
630 and for which there was no special instruction.
632 ??? Code above formerly short-circuited this, for most integer
633 mode pairs, with a force_reg in from_mode followed by a recursive
634 call to this routine. Appears always to have been wrong. */
635 if (GET_MODE_PRECISION (to_mode) < GET_MODE_PRECISION (from_mode))
637 rtx temp = force_reg (to_mode, gen_lowpart (to_mode, from));
638 emit_move_insn (to, temp);
639 return;
642 /* Mode combination is not recognized. */
643 gcc_unreachable ();
646 /* Return an rtx for a value that would result
647 from converting X to mode MODE.
648 Both X and MODE may be floating, or both integer.
649 UNSIGNEDP is nonzero if X is an unsigned value.
650 This can be done by referring to a part of X in place
651 or by copying to a new temporary with conversion. */
654 convert_to_mode (machine_mode mode, rtx x, int unsignedp)
656 return convert_modes (mode, VOIDmode, x, unsignedp);
659 /* Return an rtx for a value that would result
660 from converting X from mode OLDMODE to mode MODE.
661 Both modes may be floating, or both integer.
662 UNSIGNEDP is nonzero if X is an unsigned value.
664 This can be done by referring to a part of X in place
665 or by copying to a new temporary with conversion.
667 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
670 convert_modes (machine_mode mode, machine_mode oldmode, rtx x, int unsignedp)
672 rtx temp;
674 /* If FROM is a SUBREG that indicates that we have already done at least
675 the required extension, strip it. */
677 if (GET_CODE (x) == SUBREG && SUBREG_PROMOTED_VAR_P (x)
678 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) >= GET_MODE_SIZE (mode)
679 && SUBREG_CHECK_PROMOTED_SIGN (x, unsignedp))
680 x = gen_lowpart (mode, SUBREG_REG (x));
682 if (GET_MODE (x) != VOIDmode)
683 oldmode = GET_MODE (x);
685 if (mode == oldmode)
686 return x;
688 if (CONST_SCALAR_INT_P (x) && GET_MODE_CLASS (mode) == MODE_INT)
690 /* If the caller did not tell us the old mode, then there is not
691 much to do with respect to canonicalization. We have to
692 assume that all the bits are significant. */
693 if (GET_MODE_CLASS (oldmode) != MODE_INT)
694 oldmode = MAX_MODE_INT;
695 wide_int w = wide_int::from (std::make_pair (x, oldmode),
696 GET_MODE_PRECISION (mode),
697 unsignedp ? UNSIGNED : SIGNED);
698 return immed_wide_int_const (w, mode);
701 /* We can do this with a gen_lowpart if both desired and current modes
702 are integer, and this is either a constant integer, a register, or a
703 non-volatile MEM. */
704 if (GET_MODE_CLASS (mode) == MODE_INT
705 && GET_MODE_CLASS (oldmode) == MODE_INT
706 && GET_MODE_PRECISION (mode) <= GET_MODE_PRECISION (oldmode)
707 && ((MEM_P (x) && !MEM_VOLATILE_P (x) && direct_load[(int) mode])
708 || (REG_P (x)
709 && (!HARD_REGISTER_P (x)
710 || HARD_REGNO_MODE_OK (REGNO (x), mode))
711 && TRULY_NOOP_TRUNCATION_MODES_P (mode, GET_MODE (x)))))
713 return gen_lowpart (mode, x);
715 /* Converting from integer constant into mode is always equivalent to an
716 subreg operation. */
717 if (VECTOR_MODE_P (mode) && GET_MODE (x) == VOIDmode)
719 gcc_assert (GET_MODE_BITSIZE (mode) == GET_MODE_BITSIZE (oldmode));
720 return simplify_gen_subreg (mode, x, oldmode, 0);
723 temp = gen_reg_rtx (mode);
724 convert_move (temp, x, unsignedp);
725 return temp;
728 /* Return the largest alignment we can use for doing a move (or store)
729 of MAX_PIECES. ALIGN is the largest alignment we could use. */
731 static unsigned int
732 alignment_for_piecewise_move (unsigned int max_pieces, unsigned int align)
734 machine_mode tmode;
736 tmode = mode_for_size (max_pieces * BITS_PER_UNIT, MODE_INT, 1);
737 if (align >= GET_MODE_ALIGNMENT (tmode))
738 align = GET_MODE_ALIGNMENT (tmode);
739 else
741 machine_mode tmode, xmode;
743 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
744 tmode != VOIDmode;
745 xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
746 if (GET_MODE_SIZE (tmode) > max_pieces
747 || SLOW_UNALIGNED_ACCESS (tmode, align))
748 break;
750 align = MAX (align, GET_MODE_ALIGNMENT (xmode));
753 return align;
756 /* Return the widest integer mode no wider than SIZE. If no such mode
757 can be found, return VOIDmode. */
759 static machine_mode
760 widest_int_mode_for_size (unsigned int size)
762 machine_mode tmode, mode = VOIDmode;
764 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
765 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
766 if (GET_MODE_SIZE (tmode) < size)
767 mode = tmode;
769 return mode;
772 /* Determine whether the LEN bytes can be moved by using several move
773 instructions. Return nonzero if a call to move_by_pieces should
774 succeed. */
777 can_move_by_pieces (unsigned HOST_WIDE_INT len,
778 unsigned int align)
780 return targetm.use_by_pieces_infrastructure_p (len, align, MOVE_BY_PIECES,
781 optimize_insn_for_speed_p ());
784 /* Generate several move instructions to copy LEN bytes from block FROM to
785 block TO. (These are MEM rtx's with BLKmode).
787 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
788 used to push FROM to the stack.
790 ALIGN is maximum stack alignment we can assume.
792 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
793 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
794 stpcpy. */
797 move_by_pieces (rtx to, rtx from, unsigned HOST_WIDE_INT len,
798 unsigned int align, int endp)
800 struct move_by_pieces_d data;
801 machine_mode to_addr_mode;
802 machine_mode from_addr_mode = get_address_mode (from);
803 rtx to_addr, from_addr = XEXP (from, 0);
804 unsigned int max_size = MOVE_MAX_PIECES + 1;
805 enum insn_code icode;
807 align = MIN (to ? MEM_ALIGN (to) : align, MEM_ALIGN (from));
809 data.offset = 0;
810 data.from_addr = from_addr;
811 if (to)
813 to_addr_mode = get_address_mode (to);
814 to_addr = XEXP (to, 0);
815 data.to = to;
816 data.autinc_to
817 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
818 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
819 data.reverse
820 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
822 else
824 to_addr_mode = VOIDmode;
825 to_addr = NULL_RTX;
826 data.to = NULL_RTX;
827 data.autinc_to = 1;
828 if (STACK_GROWS_DOWNWARD)
829 data.reverse = 1;
830 else
831 data.reverse = 0;
833 data.to_addr = to_addr;
834 data.from = from;
835 data.autinc_from
836 = (GET_CODE (from_addr) == PRE_INC || GET_CODE (from_addr) == PRE_DEC
837 || GET_CODE (from_addr) == POST_INC
838 || GET_CODE (from_addr) == POST_DEC);
840 data.explicit_inc_from = 0;
841 data.explicit_inc_to = 0;
842 if (data.reverse) data.offset = len;
843 data.len = len;
845 /* If copying requires more than two move insns,
846 copy addresses to registers (to make displacements shorter)
847 and use post-increment if available. */
848 if (!(data.autinc_from && data.autinc_to)
849 && move_by_pieces_ninsns (len, align, max_size) > 2)
851 /* Find the mode of the largest move...
852 MODE might not be used depending on the definitions of the
853 USE_* macros below. */
854 machine_mode mode ATTRIBUTE_UNUSED
855 = widest_int_mode_for_size (max_size);
857 if (USE_LOAD_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_from)
859 data.from_addr = copy_to_mode_reg (from_addr_mode,
860 plus_constant (from_addr_mode,
861 from_addr, len));
862 data.autinc_from = 1;
863 data.explicit_inc_from = -1;
865 if (USE_LOAD_POST_INCREMENT (mode) && ! data.autinc_from)
867 data.from_addr = copy_to_mode_reg (from_addr_mode, from_addr);
868 data.autinc_from = 1;
869 data.explicit_inc_from = 1;
871 if (!data.autinc_from && CONSTANT_P (from_addr))
872 data.from_addr = copy_to_mode_reg (from_addr_mode, from_addr);
873 if (USE_STORE_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_to)
875 data.to_addr = copy_to_mode_reg (to_addr_mode,
876 plus_constant (to_addr_mode,
877 to_addr, len));
878 data.autinc_to = 1;
879 data.explicit_inc_to = -1;
881 if (USE_STORE_POST_INCREMENT (mode) && ! data.reverse && ! data.autinc_to)
883 data.to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
884 data.autinc_to = 1;
885 data.explicit_inc_to = 1;
887 if (!data.autinc_to && CONSTANT_P (to_addr))
888 data.to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
891 align = alignment_for_piecewise_move (MOVE_MAX_PIECES, align);
893 /* First move what we can in the largest integer mode, then go to
894 successively smaller modes. */
896 while (max_size > 1 && data.len > 0)
898 machine_mode mode = widest_int_mode_for_size (max_size);
900 if (mode == VOIDmode)
901 break;
903 icode = optab_handler (mov_optab, mode);
904 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
905 move_by_pieces_1 (GEN_FCN (icode), mode, &data);
907 max_size = GET_MODE_SIZE (mode);
910 /* The code above should have handled everything. */
911 gcc_assert (!data.len);
913 if (endp)
915 rtx to1;
917 gcc_assert (!data.reverse);
918 if (data.autinc_to)
920 if (endp == 2)
922 if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
923 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
924 else
925 data.to_addr = copy_to_mode_reg (to_addr_mode,
926 plus_constant (to_addr_mode,
927 data.to_addr,
928 -1));
930 to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
931 data.offset);
933 else
935 if (endp == 2)
936 --data.offset;
937 to1 = adjust_address (data.to, QImode, data.offset);
939 return to1;
941 else
942 return data.to;
945 /* Return number of insns required to move L bytes by pieces.
946 ALIGN (in bits) is maximum alignment we can assume. */
948 unsigned HOST_WIDE_INT
949 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l, unsigned int align,
950 unsigned int max_size)
952 unsigned HOST_WIDE_INT n_insns = 0;
954 align = alignment_for_piecewise_move (MOVE_MAX_PIECES, align);
956 while (max_size > 1 && l > 0)
958 machine_mode mode;
959 enum insn_code icode;
961 mode = widest_int_mode_for_size (max_size);
963 if (mode == VOIDmode)
964 break;
966 icode = optab_handler (mov_optab, mode);
967 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
968 n_insns += l / GET_MODE_SIZE (mode), l %= GET_MODE_SIZE (mode);
970 max_size = GET_MODE_SIZE (mode);
973 gcc_assert (!l);
974 return n_insns;
977 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
978 with move instructions for mode MODE. GENFUN is the gen_... function
979 to make a move insn for that mode. DATA has all the other info. */
981 static void
982 move_by_pieces_1 (insn_gen_fn genfun, machine_mode mode,
983 struct move_by_pieces_d *data)
985 unsigned int size = GET_MODE_SIZE (mode);
986 rtx to1 = NULL_RTX, from1;
988 while (data->len >= size)
990 if (data->reverse)
991 data->offset -= size;
993 if (data->to)
995 if (data->autinc_to)
996 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
997 data->offset);
998 else
999 to1 = adjust_address (data->to, mode, data->offset);
1002 if (data->autinc_from)
1003 from1 = adjust_automodify_address (data->from, mode, data->from_addr,
1004 data->offset);
1005 else
1006 from1 = adjust_address (data->from, mode, data->offset);
1008 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
1009 emit_insn (gen_add2_insn (data->to_addr,
1010 gen_int_mode (-(HOST_WIDE_INT) size,
1011 GET_MODE (data->to_addr))));
1012 if (HAVE_PRE_DECREMENT && data->explicit_inc_from < 0)
1013 emit_insn (gen_add2_insn (data->from_addr,
1014 gen_int_mode (-(HOST_WIDE_INT) size,
1015 GET_MODE (data->from_addr))));
1017 if (data->to)
1018 emit_insn ((*genfun) (to1, from1));
1019 else
1021 #ifdef PUSH_ROUNDING
1022 emit_single_push_insn (mode, from1, NULL);
1023 #else
1024 gcc_unreachable ();
1025 #endif
1028 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
1029 emit_insn (gen_add2_insn (data->to_addr,
1030 gen_int_mode (size,
1031 GET_MODE (data->to_addr))));
1032 if (HAVE_POST_INCREMENT && data->explicit_inc_from > 0)
1033 emit_insn (gen_add2_insn (data->from_addr,
1034 gen_int_mode (size,
1035 GET_MODE (data->from_addr))));
1037 if (! data->reverse)
1038 data->offset += size;
1040 data->len -= size;
1044 /* Emit code to move a block Y to a block X. This may be done with
1045 string-move instructions, with multiple scalar move instructions,
1046 or with a library call.
1048 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1049 SIZE is an rtx that says how long they are.
1050 ALIGN is the maximum alignment we can assume they have.
1051 METHOD describes what kind of copy this is, and what mechanisms may be used.
1052 MIN_SIZE is the minimal size of block to move
1053 MAX_SIZE is the maximal size of block to move, if it can not be represented
1054 in unsigned HOST_WIDE_INT, than it is mask of all ones.
1056 Return the address of the new block, if memcpy is called and returns it,
1057 0 otherwise. */
1060 emit_block_move_hints (rtx x, rtx y, rtx size, enum block_op_methods method,
1061 unsigned int expected_align, HOST_WIDE_INT expected_size,
1062 unsigned HOST_WIDE_INT min_size,
1063 unsigned HOST_WIDE_INT max_size,
1064 unsigned HOST_WIDE_INT probable_max_size)
1066 bool may_use_call;
1067 rtx retval = 0;
1068 unsigned int align;
1070 gcc_assert (size);
1071 if (CONST_INT_P (size)
1072 && INTVAL (size) == 0)
1073 return 0;
1075 switch (method)
1077 case BLOCK_OP_NORMAL:
1078 case BLOCK_OP_TAILCALL:
1079 may_use_call = true;
1080 break;
1082 case BLOCK_OP_CALL_PARM:
1083 may_use_call = block_move_libcall_safe_for_call_parm ();
1085 /* Make inhibit_defer_pop nonzero around the library call
1086 to force it to pop the arguments right away. */
1087 NO_DEFER_POP;
1088 break;
1090 case BLOCK_OP_NO_LIBCALL:
1091 may_use_call = false;
1092 break;
1094 default:
1095 gcc_unreachable ();
1098 gcc_assert (MEM_P (x) && MEM_P (y));
1099 align = MIN (MEM_ALIGN (x), MEM_ALIGN (y));
1100 gcc_assert (align >= BITS_PER_UNIT);
1102 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1103 block copy is more efficient for other large modes, e.g. DCmode. */
1104 x = adjust_address (x, BLKmode, 0);
1105 y = adjust_address (y, BLKmode, 0);
1107 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1108 can be incorrect is coming from __builtin_memcpy. */
1109 if (CONST_INT_P (size))
1111 x = shallow_copy_rtx (x);
1112 y = shallow_copy_rtx (y);
1113 set_mem_size (x, INTVAL (size));
1114 set_mem_size (y, INTVAL (size));
1117 if (CONST_INT_P (size) && can_move_by_pieces (INTVAL (size), align))
1118 move_by_pieces (x, y, INTVAL (size), align, 0);
1119 else if (emit_block_move_via_movmem (x, y, size, align,
1120 expected_align, expected_size,
1121 min_size, max_size, probable_max_size))
1123 else if (may_use_call
1124 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x))
1125 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y)))
1127 /* Since x and y are passed to a libcall, mark the corresponding
1128 tree EXPR as addressable. */
1129 tree y_expr = MEM_EXPR (y);
1130 tree x_expr = MEM_EXPR (x);
1131 if (y_expr)
1132 mark_addressable (y_expr);
1133 if (x_expr)
1134 mark_addressable (x_expr);
1135 retval = emit_block_move_via_libcall (x, y, size,
1136 method == BLOCK_OP_TAILCALL);
1139 else
1140 emit_block_move_via_loop (x, y, size, align);
1142 if (method == BLOCK_OP_CALL_PARM)
1143 OK_DEFER_POP;
1145 return retval;
1149 emit_block_move (rtx x, rtx y, rtx size, enum block_op_methods method)
1151 unsigned HOST_WIDE_INT max, min = 0;
1152 if (GET_CODE (size) == CONST_INT)
1153 min = max = UINTVAL (size);
1154 else
1155 max = GET_MODE_MASK (GET_MODE (size));
1156 return emit_block_move_hints (x, y, size, method, 0, -1,
1157 min, max, max);
1160 /* A subroutine of emit_block_move. Returns true if calling the
1161 block move libcall will not clobber any parameters which may have
1162 already been placed on the stack. */
1164 static bool
1165 block_move_libcall_safe_for_call_parm (void)
1167 #if defined (REG_PARM_STACK_SPACE)
1168 tree fn;
1169 #endif
1171 /* If arguments are pushed on the stack, then they're safe. */
1172 if (PUSH_ARGS)
1173 return true;
1175 /* If registers go on the stack anyway, any argument is sure to clobber
1176 an outgoing argument. */
1177 #if defined (REG_PARM_STACK_SPACE)
1178 fn = emit_block_move_libcall_fn (false);
1179 /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
1180 depend on its argument. */
1181 (void) fn;
1182 if (OUTGOING_REG_PARM_STACK_SPACE ((!fn ? NULL_TREE : TREE_TYPE (fn)))
1183 && REG_PARM_STACK_SPACE (fn) != 0)
1184 return false;
1185 #endif
1187 /* If any argument goes in memory, then it might clobber an outgoing
1188 argument. */
1190 CUMULATIVE_ARGS args_so_far_v;
1191 cumulative_args_t args_so_far;
1192 tree fn, arg;
1194 fn = emit_block_move_libcall_fn (false);
1195 INIT_CUMULATIVE_ARGS (args_so_far_v, TREE_TYPE (fn), NULL_RTX, 0, 3);
1196 args_so_far = pack_cumulative_args (&args_so_far_v);
1198 arg = TYPE_ARG_TYPES (TREE_TYPE (fn));
1199 for ( ; arg != void_list_node ; arg = TREE_CHAIN (arg))
1201 machine_mode mode = TYPE_MODE (TREE_VALUE (arg));
1202 rtx tmp = targetm.calls.function_arg (args_so_far, mode,
1203 NULL_TREE, true);
1204 if (!tmp || !REG_P (tmp))
1205 return false;
1206 if (targetm.calls.arg_partial_bytes (args_so_far, mode, NULL, 1))
1207 return false;
1208 targetm.calls.function_arg_advance (args_so_far, mode,
1209 NULL_TREE, true);
1212 return true;
1215 /* A subroutine of emit_block_move. Expand a movmem pattern;
1216 return true if successful. */
1218 static bool
1219 emit_block_move_via_movmem (rtx x, rtx y, rtx size, unsigned int align,
1220 unsigned int expected_align, HOST_WIDE_INT expected_size,
1221 unsigned HOST_WIDE_INT min_size,
1222 unsigned HOST_WIDE_INT max_size,
1223 unsigned HOST_WIDE_INT probable_max_size)
1225 int save_volatile_ok = volatile_ok;
1226 machine_mode mode;
1228 if (expected_align < align)
1229 expected_align = align;
1230 if (expected_size != -1)
1232 if ((unsigned HOST_WIDE_INT)expected_size > probable_max_size)
1233 expected_size = probable_max_size;
1234 if ((unsigned HOST_WIDE_INT)expected_size < min_size)
1235 expected_size = min_size;
1238 /* Since this is a move insn, we don't care about volatility. */
1239 volatile_ok = 1;
1241 /* Try the most limited insn first, because there's no point
1242 including more than one in the machine description unless
1243 the more limited one has some advantage. */
1245 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1246 mode = GET_MODE_WIDER_MODE (mode))
1248 enum insn_code code = direct_optab_handler (movmem_optab, mode);
1250 if (code != CODE_FOR_nothing
1251 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1252 here because if SIZE is less than the mode mask, as it is
1253 returned by the macro, it will definitely be less than the
1254 actual mode mask. Since SIZE is within the Pmode address
1255 space, we limit MODE to Pmode. */
1256 && ((CONST_INT_P (size)
1257 && ((unsigned HOST_WIDE_INT) INTVAL (size)
1258 <= (GET_MODE_MASK (mode) >> 1)))
1259 || max_size <= (GET_MODE_MASK (mode) >> 1)
1260 || GET_MODE_BITSIZE (mode) >= GET_MODE_BITSIZE (Pmode)))
1262 struct expand_operand ops[9];
1263 unsigned int nops;
1265 /* ??? When called via emit_block_move_for_call, it'd be
1266 nice if there were some way to inform the backend, so
1267 that it doesn't fail the expansion because it thinks
1268 emitting the libcall would be more efficient. */
1269 nops = insn_data[(int) code].n_generator_args;
1270 gcc_assert (nops == 4 || nops == 6 || nops == 8 || nops == 9);
1272 create_fixed_operand (&ops[0], x);
1273 create_fixed_operand (&ops[1], y);
1274 /* The check above guarantees that this size conversion is valid. */
1275 create_convert_operand_to (&ops[2], size, mode, true);
1276 create_integer_operand (&ops[3], align / BITS_PER_UNIT);
1277 if (nops >= 6)
1279 create_integer_operand (&ops[4], expected_align / BITS_PER_UNIT);
1280 create_integer_operand (&ops[5], expected_size);
1282 if (nops >= 8)
1284 create_integer_operand (&ops[6], min_size);
1285 /* If we can not represent the maximal size,
1286 make parameter NULL. */
1287 if ((HOST_WIDE_INT) max_size != -1)
1288 create_integer_operand (&ops[7], max_size);
1289 else
1290 create_fixed_operand (&ops[7], NULL);
1292 if (nops == 9)
1294 /* If we can not represent the maximal size,
1295 make parameter NULL. */
1296 if ((HOST_WIDE_INT) probable_max_size != -1)
1297 create_integer_operand (&ops[8], probable_max_size);
1298 else
1299 create_fixed_operand (&ops[8], NULL);
1301 if (maybe_expand_insn (code, nops, ops))
1303 volatile_ok = save_volatile_ok;
1304 return true;
1309 volatile_ok = save_volatile_ok;
1310 return false;
1313 /* A subroutine of emit_block_move. Expand a call to memcpy.
1314 Return the return value from memcpy, 0 otherwise. */
1317 emit_block_move_via_libcall (rtx dst, rtx src, rtx size, bool tailcall)
1319 rtx dst_addr, src_addr;
1320 tree call_expr, fn, src_tree, dst_tree, size_tree;
1321 machine_mode size_mode;
1322 rtx retval;
1324 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1325 pseudos. We can then place those new pseudos into a VAR_DECL and
1326 use them later. */
1328 dst_addr = copy_addr_to_reg (XEXP (dst, 0));
1329 src_addr = copy_addr_to_reg (XEXP (src, 0));
1331 dst_addr = convert_memory_address (ptr_mode, dst_addr);
1332 src_addr = convert_memory_address (ptr_mode, src_addr);
1334 dst_tree = make_tree (ptr_type_node, dst_addr);
1335 src_tree = make_tree (ptr_type_node, src_addr);
1337 size_mode = TYPE_MODE (sizetype);
1339 size = convert_to_mode (size_mode, size, 1);
1340 size = copy_to_mode_reg (size_mode, size);
1342 /* It is incorrect to use the libcall calling conventions to call
1343 memcpy in this context. This could be a user call to memcpy and
1344 the user may wish to examine the return value from memcpy. For
1345 targets where libcalls and normal calls have different conventions
1346 for returning pointers, we could end up generating incorrect code. */
1348 size_tree = make_tree (sizetype, size);
1350 fn = emit_block_move_libcall_fn (true);
1351 call_expr = build_call_expr (fn, 3, dst_tree, src_tree, size_tree);
1352 CALL_EXPR_TAILCALL (call_expr) = tailcall;
1354 retval = expand_normal (call_expr);
1356 return retval;
1359 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1360 for the function we use for block copies. */
1362 static GTY(()) tree block_move_fn;
1364 void
1365 init_block_move_fn (const char *asmspec)
1367 if (!block_move_fn)
1369 tree args, fn, attrs, attr_args;
1371 fn = get_identifier ("memcpy");
1372 args = build_function_type_list (ptr_type_node, ptr_type_node,
1373 const_ptr_type_node, sizetype,
1374 NULL_TREE);
1376 fn = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, fn, args);
1377 DECL_EXTERNAL (fn) = 1;
1378 TREE_PUBLIC (fn) = 1;
1379 DECL_ARTIFICIAL (fn) = 1;
1380 TREE_NOTHROW (fn) = 1;
1381 DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
1382 DECL_VISIBILITY_SPECIFIED (fn) = 1;
1384 attr_args = build_tree_list (NULL_TREE, build_string (1, "1"));
1385 attrs = tree_cons (get_identifier ("fn spec"), attr_args, NULL);
1387 decl_attributes (&fn, attrs, ATTR_FLAG_BUILT_IN);
1389 block_move_fn = fn;
1392 if (asmspec)
1393 set_user_assembler_name (block_move_fn, asmspec);
1396 static tree
1397 emit_block_move_libcall_fn (int for_call)
1399 static bool emitted_extern;
1401 if (!block_move_fn)
1402 init_block_move_fn (NULL);
1404 if (for_call && !emitted_extern)
1406 emitted_extern = true;
1407 make_decl_rtl (block_move_fn);
1410 return block_move_fn;
1413 /* A subroutine of emit_block_move. Copy the data via an explicit
1414 loop. This is used only when libcalls are forbidden. */
1415 /* ??? It'd be nice to copy in hunks larger than QImode. */
1417 static void
1418 emit_block_move_via_loop (rtx x, rtx y, rtx size,
1419 unsigned int align ATTRIBUTE_UNUSED)
1421 rtx_code_label *cmp_label, *top_label;
1422 rtx iter, x_addr, y_addr, tmp;
1423 machine_mode x_addr_mode = get_address_mode (x);
1424 machine_mode y_addr_mode = get_address_mode (y);
1425 machine_mode iter_mode;
1427 iter_mode = GET_MODE (size);
1428 if (iter_mode == VOIDmode)
1429 iter_mode = word_mode;
1431 top_label = gen_label_rtx ();
1432 cmp_label = gen_label_rtx ();
1433 iter = gen_reg_rtx (iter_mode);
1435 emit_move_insn (iter, const0_rtx);
1437 x_addr = force_operand (XEXP (x, 0), NULL_RTX);
1438 y_addr = force_operand (XEXP (y, 0), NULL_RTX);
1439 do_pending_stack_adjust ();
1441 emit_jump (cmp_label);
1442 emit_label (top_label);
1444 tmp = convert_modes (x_addr_mode, iter_mode, iter, true);
1445 x_addr = simplify_gen_binary (PLUS, x_addr_mode, x_addr, tmp);
1447 if (x_addr_mode != y_addr_mode)
1448 tmp = convert_modes (y_addr_mode, iter_mode, iter, true);
1449 y_addr = simplify_gen_binary (PLUS, y_addr_mode, y_addr, tmp);
1451 x = change_address (x, QImode, x_addr);
1452 y = change_address (y, QImode, y_addr);
1454 emit_move_insn (x, y);
1456 tmp = expand_simple_binop (iter_mode, PLUS, iter, const1_rtx, iter,
1457 true, OPTAB_LIB_WIDEN);
1458 if (tmp != iter)
1459 emit_move_insn (iter, tmp);
1461 emit_label (cmp_label);
1463 emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
1464 true, top_label, REG_BR_PROB_BASE * 90 / 100);
1467 /* Copy all or part of a value X into registers starting at REGNO.
1468 The number of registers to be filled is NREGS. */
1470 void
1471 move_block_to_reg (int regno, rtx x, int nregs, machine_mode mode)
1473 if (nregs == 0)
1474 return;
1476 if (CONSTANT_P (x) && !targetm.legitimate_constant_p (mode, x))
1477 x = validize_mem (force_const_mem (mode, x));
1479 /* See if the machine can do this with a load multiple insn. */
1480 if (targetm.have_load_multiple ())
1482 rtx_insn *last = get_last_insn ();
1483 rtx first = gen_rtx_REG (word_mode, regno);
1484 if (rtx_insn *pat = targetm.gen_load_multiple (first, x,
1485 GEN_INT (nregs)))
1487 emit_insn (pat);
1488 return;
1490 else
1491 delete_insns_since (last);
1494 for (int i = 0; i < nregs; i++)
1495 emit_move_insn (gen_rtx_REG (word_mode, regno + i),
1496 operand_subword_force (x, i, mode));
1499 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1500 The number of registers to be filled is NREGS. */
1502 void
1503 move_block_from_reg (int regno, rtx x, int nregs)
1505 if (nregs == 0)
1506 return;
1508 /* See if the machine can do this with a store multiple insn. */
1509 if (targetm.have_store_multiple ())
1511 rtx_insn *last = get_last_insn ();
1512 rtx first = gen_rtx_REG (word_mode, regno);
1513 if (rtx_insn *pat = targetm.gen_store_multiple (x, first,
1514 GEN_INT (nregs)))
1516 emit_insn (pat);
1517 return;
1519 else
1520 delete_insns_since (last);
1523 for (int i = 0; i < nregs; i++)
1525 rtx tem = operand_subword (x, i, 1, BLKmode);
1527 gcc_assert (tem);
1529 emit_move_insn (tem, gen_rtx_REG (word_mode, regno + i));
1533 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1534 ORIG, where ORIG is a non-consecutive group of registers represented by
1535 a PARALLEL. The clone is identical to the original except in that the
1536 original set of registers is replaced by a new set of pseudo registers.
1537 The new set has the same modes as the original set. */
1540 gen_group_rtx (rtx orig)
1542 int i, length;
1543 rtx *tmps;
1545 gcc_assert (GET_CODE (orig) == PARALLEL);
1547 length = XVECLEN (orig, 0);
1548 tmps = XALLOCAVEC (rtx, length);
1550 /* Skip a NULL entry in first slot. */
1551 i = XEXP (XVECEXP (orig, 0, 0), 0) ? 0 : 1;
1553 if (i)
1554 tmps[0] = 0;
1556 for (; i < length; i++)
1558 machine_mode mode = GET_MODE (XEXP (XVECEXP (orig, 0, i), 0));
1559 rtx offset = XEXP (XVECEXP (orig, 0, i), 1);
1561 tmps[i] = gen_rtx_EXPR_LIST (VOIDmode, gen_reg_rtx (mode), offset);
1564 return gen_rtx_PARALLEL (GET_MODE (orig), gen_rtvec_v (length, tmps));
1567 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1568 except that values are placed in TMPS[i], and must later be moved
1569 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1571 static void
1572 emit_group_load_1 (rtx *tmps, rtx dst, rtx orig_src, tree type, int ssize)
1574 rtx src;
1575 int start, i;
1576 machine_mode m = GET_MODE (orig_src);
1578 gcc_assert (GET_CODE (dst) == PARALLEL);
1580 if (m != VOIDmode
1581 && !SCALAR_INT_MODE_P (m)
1582 && !MEM_P (orig_src)
1583 && GET_CODE (orig_src) != CONCAT)
1585 machine_mode imode = int_mode_for_mode (GET_MODE (orig_src));
1586 if (imode == BLKmode)
1587 src = assign_stack_temp (GET_MODE (orig_src), ssize);
1588 else
1589 src = gen_reg_rtx (imode);
1590 if (imode != BLKmode)
1591 src = gen_lowpart (GET_MODE (orig_src), src);
1592 emit_move_insn (src, orig_src);
1593 /* ...and back again. */
1594 if (imode != BLKmode)
1595 src = gen_lowpart (imode, src);
1596 emit_group_load_1 (tmps, dst, src, type, ssize);
1597 return;
1600 /* Check for a NULL entry, used to indicate that the parameter goes
1601 both on the stack and in registers. */
1602 if (XEXP (XVECEXP (dst, 0, 0), 0))
1603 start = 0;
1604 else
1605 start = 1;
1607 /* Process the pieces. */
1608 for (i = start; i < XVECLEN (dst, 0); i++)
1610 machine_mode mode = GET_MODE (XEXP (XVECEXP (dst, 0, i), 0));
1611 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (dst, 0, i), 1));
1612 unsigned int bytelen = GET_MODE_SIZE (mode);
1613 int shift = 0;
1615 /* Handle trailing fragments that run over the size of the struct. */
1616 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
1618 /* Arrange to shift the fragment to where it belongs.
1619 extract_bit_field loads to the lsb of the reg. */
1620 if (
1621 #ifdef BLOCK_REG_PADDING
1622 BLOCK_REG_PADDING (GET_MODE (orig_src), type, i == start)
1623 == (BYTES_BIG_ENDIAN ? upward : downward)
1624 #else
1625 BYTES_BIG_ENDIAN
1626 #endif
1628 shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
1629 bytelen = ssize - bytepos;
1630 gcc_assert (bytelen > 0);
1633 /* If we won't be loading directly from memory, protect the real source
1634 from strange tricks we might play; but make sure that the source can
1635 be loaded directly into the destination. */
1636 src = orig_src;
1637 if (!MEM_P (orig_src)
1638 && (!CONSTANT_P (orig_src)
1639 || (GET_MODE (orig_src) != mode
1640 && GET_MODE (orig_src) != VOIDmode)))
1642 if (GET_MODE (orig_src) == VOIDmode)
1643 src = gen_reg_rtx (mode);
1644 else
1645 src = gen_reg_rtx (GET_MODE (orig_src));
1647 emit_move_insn (src, orig_src);
1650 /* Optimize the access just a bit. */
1651 if (MEM_P (src)
1652 && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (src))
1653 || MEM_ALIGN (src) >= GET_MODE_ALIGNMENT (mode))
1654 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
1655 && bytelen == GET_MODE_SIZE (mode))
1657 tmps[i] = gen_reg_rtx (mode);
1658 emit_move_insn (tmps[i], adjust_address (src, mode, bytepos));
1660 else if (COMPLEX_MODE_P (mode)
1661 && GET_MODE (src) == mode
1662 && bytelen == GET_MODE_SIZE (mode))
1663 /* Let emit_move_complex do the bulk of the work. */
1664 tmps[i] = src;
1665 else if (GET_CODE (src) == CONCAT)
1667 unsigned int slen = GET_MODE_SIZE (GET_MODE (src));
1668 unsigned int slen0 = GET_MODE_SIZE (GET_MODE (XEXP (src, 0)));
1670 if ((bytepos == 0 && bytelen == slen0)
1671 || (bytepos != 0 && bytepos + bytelen <= slen))
1673 /* The following assumes that the concatenated objects all
1674 have the same size. In this case, a simple calculation
1675 can be used to determine the object and the bit field
1676 to be extracted. */
1677 tmps[i] = XEXP (src, bytepos / slen0);
1678 if (! CONSTANT_P (tmps[i])
1679 && (!REG_P (tmps[i]) || GET_MODE (tmps[i]) != mode))
1680 tmps[i] = extract_bit_field (tmps[i], bytelen * BITS_PER_UNIT,
1681 (bytepos % slen0) * BITS_PER_UNIT,
1682 1, NULL_RTX, mode, mode, false);
1684 else
1686 rtx mem;
1688 gcc_assert (!bytepos);
1689 mem = assign_stack_temp (GET_MODE (src), slen);
1690 emit_move_insn (mem, src);
1691 tmps[i] = extract_bit_field (mem, bytelen * BITS_PER_UNIT,
1692 0, 1, NULL_RTX, mode, mode, false);
1695 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1696 SIMD register, which is currently broken. While we get GCC
1697 to emit proper RTL for these cases, let's dump to memory. */
1698 else if (VECTOR_MODE_P (GET_MODE (dst))
1699 && REG_P (src))
1701 int slen = GET_MODE_SIZE (GET_MODE (src));
1702 rtx mem;
1704 mem = assign_stack_temp (GET_MODE (src), slen);
1705 emit_move_insn (mem, src);
1706 tmps[i] = adjust_address (mem, mode, (int) bytepos);
1708 else if (CONSTANT_P (src) && GET_MODE (dst) != BLKmode
1709 && XVECLEN (dst, 0) > 1)
1710 tmps[i] = simplify_gen_subreg (mode, src, GET_MODE (dst), bytepos);
1711 else if (CONSTANT_P (src))
1713 HOST_WIDE_INT len = (HOST_WIDE_INT) bytelen;
1715 if (len == ssize)
1716 tmps[i] = src;
1717 else
1719 rtx first, second;
1721 /* TODO: const_wide_int can have sizes other than this... */
1722 gcc_assert (2 * len == ssize);
1723 split_double (src, &first, &second);
1724 if (i)
1725 tmps[i] = second;
1726 else
1727 tmps[i] = first;
1730 else if (REG_P (src) && GET_MODE (src) == mode)
1731 tmps[i] = src;
1732 else
1733 tmps[i] = extract_bit_field (src, bytelen * BITS_PER_UNIT,
1734 bytepos * BITS_PER_UNIT, 1, NULL_RTX,
1735 mode, mode, false);
1737 if (shift)
1738 tmps[i] = expand_shift (LSHIFT_EXPR, mode, tmps[i],
1739 shift, tmps[i], 0);
1743 /* Emit code to move a block SRC of type TYPE to a block DST,
1744 where DST is non-consecutive registers represented by a PARALLEL.
1745 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1746 if not known. */
1748 void
1749 emit_group_load (rtx dst, rtx src, tree type, int ssize)
1751 rtx *tmps;
1752 int i;
1754 tmps = XALLOCAVEC (rtx, XVECLEN (dst, 0));
1755 emit_group_load_1 (tmps, dst, src, type, ssize);
1757 /* Copy the extracted pieces into the proper (probable) hard regs. */
1758 for (i = 0; i < XVECLEN (dst, 0); i++)
1760 rtx d = XEXP (XVECEXP (dst, 0, i), 0);
1761 if (d == NULL)
1762 continue;
1763 emit_move_insn (d, tmps[i]);
1767 /* Similar, but load SRC into new pseudos in a format that looks like
1768 PARALLEL. This can later be fed to emit_group_move to get things
1769 in the right place. */
1772 emit_group_load_into_temps (rtx parallel, rtx src, tree type, int ssize)
1774 rtvec vec;
1775 int i;
1777 vec = rtvec_alloc (XVECLEN (parallel, 0));
1778 emit_group_load_1 (&RTVEC_ELT (vec, 0), parallel, src, type, ssize);
1780 /* Convert the vector to look just like the original PARALLEL, except
1781 with the computed values. */
1782 for (i = 0; i < XVECLEN (parallel, 0); i++)
1784 rtx e = XVECEXP (parallel, 0, i);
1785 rtx d = XEXP (e, 0);
1787 if (d)
1789 d = force_reg (GET_MODE (d), RTVEC_ELT (vec, i));
1790 e = alloc_EXPR_LIST (REG_NOTE_KIND (e), d, XEXP (e, 1));
1792 RTVEC_ELT (vec, i) = e;
1795 return gen_rtx_PARALLEL (GET_MODE (parallel), vec);
1798 /* Emit code to move a block SRC to block DST, where SRC and DST are
1799 non-consecutive groups of registers, each represented by a PARALLEL. */
1801 void
1802 emit_group_move (rtx dst, rtx src)
1804 int i;
1806 gcc_assert (GET_CODE (src) == PARALLEL
1807 && GET_CODE (dst) == PARALLEL
1808 && XVECLEN (src, 0) == XVECLEN (dst, 0));
1810 /* Skip first entry if NULL. */
1811 for (i = XEXP (XVECEXP (src, 0, 0), 0) ? 0 : 1; i < XVECLEN (src, 0); i++)
1812 emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0),
1813 XEXP (XVECEXP (src, 0, i), 0));
1816 /* Move a group of registers represented by a PARALLEL into pseudos. */
1819 emit_group_move_into_temps (rtx src)
1821 rtvec vec = rtvec_alloc (XVECLEN (src, 0));
1822 int i;
1824 for (i = 0; i < XVECLEN (src, 0); i++)
1826 rtx e = XVECEXP (src, 0, i);
1827 rtx d = XEXP (e, 0);
1829 if (d)
1830 e = alloc_EXPR_LIST (REG_NOTE_KIND (e), copy_to_reg (d), XEXP (e, 1));
1831 RTVEC_ELT (vec, i) = e;
1834 return gen_rtx_PARALLEL (GET_MODE (src), vec);
1837 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1838 where SRC is non-consecutive registers represented by a PARALLEL.
1839 SSIZE represents the total size of block ORIG_DST, or -1 if not
1840 known. */
1842 void
1843 emit_group_store (rtx orig_dst, rtx src, tree type ATTRIBUTE_UNUSED, int ssize)
1845 rtx *tmps, dst;
1846 int start, finish, i;
1847 machine_mode m = GET_MODE (orig_dst);
1849 gcc_assert (GET_CODE (src) == PARALLEL);
1851 if (!SCALAR_INT_MODE_P (m)
1852 && !MEM_P (orig_dst) && GET_CODE (orig_dst) != CONCAT)
1854 machine_mode imode = int_mode_for_mode (GET_MODE (orig_dst));
1855 if (imode == BLKmode)
1856 dst = assign_stack_temp (GET_MODE (orig_dst), ssize);
1857 else
1858 dst = gen_reg_rtx (imode);
1859 emit_group_store (dst, src, type, ssize);
1860 if (imode != BLKmode)
1861 dst = gen_lowpart (GET_MODE (orig_dst), dst);
1862 emit_move_insn (orig_dst, dst);
1863 return;
1866 /* Check for a NULL entry, used to indicate that the parameter goes
1867 both on the stack and in registers. */
1868 if (XEXP (XVECEXP (src, 0, 0), 0))
1869 start = 0;
1870 else
1871 start = 1;
1872 finish = XVECLEN (src, 0);
1874 tmps = XALLOCAVEC (rtx, finish);
1876 /* Copy the (probable) hard regs into pseudos. */
1877 for (i = start; i < finish; i++)
1879 rtx reg = XEXP (XVECEXP (src, 0, i), 0);
1880 if (!REG_P (reg) || REGNO (reg) < FIRST_PSEUDO_REGISTER)
1882 tmps[i] = gen_reg_rtx (GET_MODE (reg));
1883 emit_move_insn (tmps[i], reg);
1885 else
1886 tmps[i] = reg;
1889 /* If we won't be storing directly into memory, protect the real destination
1890 from strange tricks we might play. */
1891 dst = orig_dst;
1892 if (GET_CODE (dst) == PARALLEL)
1894 rtx temp;
1896 /* We can get a PARALLEL dst if there is a conditional expression in
1897 a return statement. In that case, the dst and src are the same,
1898 so no action is necessary. */
1899 if (rtx_equal_p (dst, src))
1900 return;
1902 /* It is unclear if we can ever reach here, but we may as well handle
1903 it. Allocate a temporary, and split this into a store/load to/from
1904 the temporary. */
1905 temp = assign_stack_temp (GET_MODE (dst), ssize);
1906 emit_group_store (temp, src, type, ssize);
1907 emit_group_load (dst, temp, type, ssize);
1908 return;
1910 else if (!MEM_P (dst) && GET_CODE (dst) != CONCAT)
1912 machine_mode outer = GET_MODE (dst);
1913 machine_mode inner;
1914 HOST_WIDE_INT bytepos;
1915 bool done = false;
1916 rtx temp;
1918 if (!REG_P (dst) || REGNO (dst) < FIRST_PSEUDO_REGISTER)
1919 dst = gen_reg_rtx (outer);
1921 /* Make life a bit easier for combine. */
1922 /* If the first element of the vector is the low part
1923 of the destination mode, use a paradoxical subreg to
1924 initialize the destination. */
1925 if (start < finish)
1927 inner = GET_MODE (tmps[start]);
1928 bytepos = subreg_lowpart_offset (inner, outer);
1929 if (INTVAL (XEXP (XVECEXP (src, 0, start), 1)) == bytepos)
1931 temp = simplify_gen_subreg (outer, tmps[start],
1932 inner, 0);
1933 if (temp)
1935 emit_move_insn (dst, temp);
1936 done = true;
1937 start++;
1942 /* If the first element wasn't the low part, try the last. */
1943 if (!done
1944 && start < finish - 1)
1946 inner = GET_MODE (tmps[finish - 1]);
1947 bytepos = subreg_lowpart_offset (inner, outer);
1948 if (INTVAL (XEXP (XVECEXP (src, 0, finish - 1), 1)) == bytepos)
1950 temp = simplify_gen_subreg (outer, tmps[finish - 1],
1951 inner, 0);
1952 if (temp)
1954 emit_move_insn (dst, temp);
1955 done = true;
1956 finish--;
1961 /* Otherwise, simply initialize the result to zero. */
1962 if (!done)
1963 emit_move_insn (dst, CONST0_RTX (outer));
1966 /* Process the pieces. */
1967 for (i = start; i < finish; i++)
1969 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (src, 0, i), 1));
1970 machine_mode mode = GET_MODE (tmps[i]);
1971 unsigned int bytelen = GET_MODE_SIZE (mode);
1972 unsigned int adj_bytelen;
1973 rtx dest = dst;
1975 /* Handle trailing fragments that run over the size of the struct. */
1976 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
1977 adj_bytelen = ssize - bytepos;
1978 else
1979 adj_bytelen = bytelen;
1981 if (GET_CODE (dst) == CONCAT)
1983 if (bytepos + adj_bytelen
1984 <= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
1985 dest = XEXP (dst, 0);
1986 else if (bytepos >= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
1988 bytepos -= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)));
1989 dest = XEXP (dst, 1);
1991 else
1993 machine_mode dest_mode = GET_MODE (dest);
1994 machine_mode tmp_mode = GET_MODE (tmps[i]);
1996 gcc_assert (bytepos == 0 && XVECLEN (src, 0));
1998 if (GET_MODE_ALIGNMENT (dest_mode)
1999 >= GET_MODE_ALIGNMENT (tmp_mode))
2001 dest = assign_stack_temp (dest_mode,
2002 GET_MODE_SIZE (dest_mode));
2003 emit_move_insn (adjust_address (dest,
2004 tmp_mode,
2005 bytepos),
2006 tmps[i]);
2007 dst = dest;
2009 else
2011 dest = assign_stack_temp (tmp_mode,
2012 GET_MODE_SIZE (tmp_mode));
2013 emit_move_insn (dest, tmps[i]);
2014 dst = adjust_address (dest, dest_mode, bytepos);
2016 break;
2020 /* Handle trailing fragments that run over the size of the struct. */
2021 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
2023 /* store_bit_field always takes its value from the lsb.
2024 Move the fragment to the lsb if it's not already there. */
2025 if (
2026 #ifdef BLOCK_REG_PADDING
2027 BLOCK_REG_PADDING (GET_MODE (orig_dst), type, i == start)
2028 == (BYTES_BIG_ENDIAN ? upward : downward)
2029 #else
2030 BYTES_BIG_ENDIAN
2031 #endif
2034 int shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
2035 tmps[i] = expand_shift (RSHIFT_EXPR, mode, tmps[i],
2036 shift, tmps[i], 0);
2039 /* Make sure not to write past the end of the struct. */
2040 store_bit_field (dest,
2041 adj_bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
2042 bytepos * BITS_PER_UNIT, ssize * BITS_PER_UNIT - 1,
2043 VOIDmode, tmps[i], false);
2046 /* Optimize the access just a bit. */
2047 else if (MEM_P (dest)
2048 && (!SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (dest))
2049 || MEM_ALIGN (dest) >= GET_MODE_ALIGNMENT (mode))
2050 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
2051 && bytelen == GET_MODE_SIZE (mode))
2052 emit_move_insn (adjust_address (dest, mode, bytepos), tmps[i]);
2054 else
2055 store_bit_field (dest, bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
2056 0, 0, mode, tmps[i], false);
2059 /* Copy from the pseudo into the (probable) hard reg. */
2060 if (orig_dst != dst)
2061 emit_move_insn (orig_dst, dst);
2064 /* Return a form of X that does not use a PARALLEL. TYPE is the type
2065 of the value stored in X. */
2068 maybe_emit_group_store (rtx x, tree type)
2070 machine_mode mode = TYPE_MODE (type);
2071 gcc_checking_assert (GET_MODE (x) == VOIDmode || GET_MODE (x) == mode);
2072 if (GET_CODE (x) == PARALLEL)
2074 rtx result = gen_reg_rtx (mode);
2075 emit_group_store (result, x, type, int_size_in_bytes (type));
2076 return result;
2078 return x;
2081 /* Copy a BLKmode object of TYPE out of a register SRCREG into TARGET.
2083 This is used on targets that return BLKmode values in registers. */
2085 void
2086 copy_blkmode_from_reg (rtx target, rtx srcreg, tree type)
2088 unsigned HOST_WIDE_INT bytes = int_size_in_bytes (type);
2089 rtx src = NULL, dst = NULL;
2090 unsigned HOST_WIDE_INT bitsize = MIN (TYPE_ALIGN (type), BITS_PER_WORD);
2091 unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0;
2092 machine_mode mode = GET_MODE (srcreg);
2093 machine_mode tmode = GET_MODE (target);
2094 machine_mode copy_mode;
2096 /* BLKmode registers created in the back-end shouldn't have survived. */
2097 gcc_assert (mode != BLKmode);
2099 /* If the structure doesn't take up a whole number of words, see whether
2100 SRCREG is padded on the left or on the right. If it's on the left,
2101 set PADDING_CORRECTION to the number of bits to skip.
2103 In most ABIs, the structure will be returned at the least end of
2104 the register, which translates to right padding on little-endian
2105 targets and left padding on big-endian targets. The opposite
2106 holds if the structure is returned at the most significant
2107 end of the register. */
2108 if (bytes % UNITS_PER_WORD != 0
2109 && (targetm.calls.return_in_msb (type)
2110 ? !BYTES_BIG_ENDIAN
2111 : BYTES_BIG_ENDIAN))
2112 padding_correction
2113 = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD) * BITS_PER_UNIT));
2115 /* We can use a single move if we have an exact mode for the size. */
2116 else if (MEM_P (target)
2117 && (!SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (target))
2118 || MEM_ALIGN (target) >= GET_MODE_ALIGNMENT (mode))
2119 && bytes == GET_MODE_SIZE (mode))
2121 emit_move_insn (adjust_address (target, mode, 0), srcreg);
2122 return;
2125 /* And if we additionally have the same mode for a register. */
2126 else if (REG_P (target)
2127 && GET_MODE (target) == mode
2128 && bytes == GET_MODE_SIZE (mode))
2130 emit_move_insn (target, srcreg);
2131 return;
2134 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2135 into a new pseudo which is a full word. */
2136 if (GET_MODE_SIZE (mode) < UNITS_PER_WORD)
2138 srcreg = convert_to_mode (word_mode, srcreg, TYPE_UNSIGNED (type));
2139 mode = word_mode;
2142 /* Copy the structure BITSIZE bits at a time. If the target lives in
2143 memory, take care of not reading/writing past its end by selecting
2144 a copy mode suited to BITSIZE. This should always be possible given
2145 how it is computed.
2147 If the target lives in register, make sure not to select a copy mode
2148 larger than the mode of the register.
2150 We could probably emit more efficient code for machines which do not use
2151 strict alignment, but it doesn't seem worth the effort at the current
2152 time. */
2154 copy_mode = word_mode;
2155 if (MEM_P (target))
2157 machine_mode mem_mode = mode_for_size (bitsize, MODE_INT, 1);
2158 if (mem_mode != BLKmode)
2159 copy_mode = mem_mode;
2161 else if (REG_P (target) && GET_MODE_BITSIZE (tmode) < BITS_PER_WORD)
2162 copy_mode = tmode;
2164 for (bitpos = 0, xbitpos = padding_correction;
2165 bitpos < bytes * BITS_PER_UNIT;
2166 bitpos += bitsize, xbitpos += bitsize)
2168 /* We need a new source operand each time xbitpos is on a
2169 word boundary and when xbitpos == padding_correction
2170 (the first time through). */
2171 if (xbitpos % BITS_PER_WORD == 0 || xbitpos == padding_correction)
2172 src = operand_subword_force (srcreg, xbitpos / BITS_PER_WORD, mode);
2174 /* We need a new destination operand each time bitpos is on
2175 a word boundary. */
2176 if (REG_P (target) && GET_MODE_BITSIZE (tmode) < BITS_PER_WORD)
2177 dst = target;
2178 else if (bitpos % BITS_PER_WORD == 0)
2179 dst = operand_subword (target, bitpos / BITS_PER_WORD, 1, tmode);
2181 /* Use xbitpos for the source extraction (right justified) and
2182 bitpos for the destination store (left justified). */
2183 store_bit_field (dst, bitsize, bitpos % BITS_PER_WORD, 0, 0, copy_mode,
2184 extract_bit_field (src, bitsize,
2185 xbitpos % BITS_PER_WORD, 1,
2186 NULL_RTX, copy_mode, copy_mode,
2187 false),
2188 false);
2192 /* Copy BLKmode value SRC into a register of mode MODE. Return the
2193 register if it contains any data, otherwise return null.
2195 This is used on targets that return BLKmode values in registers. */
2198 copy_blkmode_to_reg (machine_mode mode, tree src)
2200 int i, n_regs;
2201 unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0, bytes;
2202 unsigned int bitsize;
2203 rtx *dst_words, dst, x, src_word = NULL_RTX, dst_word = NULL_RTX;
2204 machine_mode dst_mode;
2206 gcc_assert (TYPE_MODE (TREE_TYPE (src)) == BLKmode);
2208 x = expand_normal (src);
2210 bytes = int_size_in_bytes (TREE_TYPE (src));
2211 if (bytes == 0)
2212 return NULL_RTX;
2214 /* If the structure doesn't take up a whole number of words, see
2215 whether the register value should be padded on the left or on
2216 the right. Set PADDING_CORRECTION to the number of padding
2217 bits needed on the left side.
2219 In most ABIs, the structure will be returned at the least end of
2220 the register, which translates to right padding on little-endian
2221 targets and left padding on big-endian targets. The opposite
2222 holds if the structure is returned at the most significant
2223 end of the register. */
2224 if (bytes % UNITS_PER_WORD != 0
2225 && (targetm.calls.return_in_msb (TREE_TYPE (src))
2226 ? !BYTES_BIG_ENDIAN
2227 : BYTES_BIG_ENDIAN))
2228 padding_correction = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD)
2229 * BITS_PER_UNIT));
2231 n_regs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2232 dst_words = XALLOCAVEC (rtx, n_regs);
2233 bitsize = MIN (TYPE_ALIGN (TREE_TYPE (src)), BITS_PER_WORD);
2235 /* Copy the structure BITSIZE bits at a time. */
2236 for (bitpos = 0, xbitpos = padding_correction;
2237 bitpos < bytes * BITS_PER_UNIT;
2238 bitpos += bitsize, xbitpos += bitsize)
2240 /* We need a new destination pseudo each time xbitpos is
2241 on a word boundary and when xbitpos == padding_correction
2242 (the first time through). */
2243 if (xbitpos % BITS_PER_WORD == 0
2244 || xbitpos == padding_correction)
2246 /* Generate an appropriate register. */
2247 dst_word = gen_reg_rtx (word_mode);
2248 dst_words[xbitpos / BITS_PER_WORD] = dst_word;
2250 /* Clear the destination before we move anything into it. */
2251 emit_move_insn (dst_word, CONST0_RTX (word_mode));
2254 /* We need a new source operand each time bitpos is on a word
2255 boundary. */
2256 if (bitpos % BITS_PER_WORD == 0)
2257 src_word = operand_subword_force (x, bitpos / BITS_PER_WORD, BLKmode);
2259 /* Use bitpos for the source extraction (left justified) and
2260 xbitpos for the destination store (right justified). */
2261 store_bit_field (dst_word, bitsize, xbitpos % BITS_PER_WORD,
2262 0, 0, word_mode,
2263 extract_bit_field (src_word, bitsize,
2264 bitpos % BITS_PER_WORD, 1,
2265 NULL_RTX, word_mode, word_mode,
2266 false),
2267 false);
2270 if (mode == BLKmode)
2272 /* Find the smallest integer mode large enough to hold the
2273 entire structure. */
2274 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2275 mode != VOIDmode;
2276 mode = GET_MODE_WIDER_MODE (mode))
2277 /* Have we found a large enough mode? */
2278 if (GET_MODE_SIZE (mode) >= bytes)
2279 break;
2281 /* A suitable mode should have been found. */
2282 gcc_assert (mode != VOIDmode);
2285 if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
2286 dst_mode = word_mode;
2287 else
2288 dst_mode = mode;
2289 dst = gen_reg_rtx (dst_mode);
2291 for (i = 0; i < n_regs; i++)
2292 emit_move_insn (operand_subword (dst, i, 0, dst_mode), dst_words[i]);
2294 if (mode != dst_mode)
2295 dst = gen_lowpart (mode, dst);
2297 return dst;
2300 /* Add a USE expression for REG to the (possibly empty) list pointed
2301 to by CALL_FUSAGE. REG must denote a hard register. */
2303 void
2304 use_reg_mode (rtx *call_fusage, rtx reg, machine_mode mode)
2306 gcc_assert (REG_P (reg));
2308 if (!HARD_REGISTER_P (reg))
2309 return;
2311 *call_fusage
2312 = gen_rtx_EXPR_LIST (mode, gen_rtx_USE (VOIDmode, reg), *call_fusage);
2315 /* Add a CLOBBER expression for REG to the (possibly empty) list pointed
2316 to by CALL_FUSAGE. REG must denote a hard register. */
2318 void
2319 clobber_reg_mode (rtx *call_fusage, rtx reg, machine_mode mode)
2321 gcc_assert (REG_P (reg) && REGNO (reg) < FIRST_PSEUDO_REGISTER);
2323 *call_fusage
2324 = gen_rtx_EXPR_LIST (mode, gen_rtx_CLOBBER (VOIDmode, reg), *call_fusage);
2327 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2328 starting at REGNO. All of these registers must be hard registers. */
2330 void
2331 use_regs (rtx *call_fusage, int regno, int nregs)
2333 int i;
2335 gcc_assert (regno + nregs <= FIRST_PSEUDO_REGISTER);
2337 for (i = 0; i < nregs; i++)
2338 use_reg (call_fusage, regno_reg_rtx[regno + i]);
2341 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2342 PARALLEL REGS. This is for calls that pass values in multiple
2343 non-contiguous locations. The Irix 6 ABI has examples of this. */
2345 void
2346 use_group_regs (rtx *call_fusage, rtx regs)
2348 int i;
2350 for (i = 0; i < XVECLEN (regs, 0); i++)
2352 rtx reg = XEXP (XVECEXP (regs, 0, i), 0);
2354 /* A NULL entry means the parameter goes both on the stack and in
2355 registers. This can also be a MEM for targets that pass values
2356 partially on the stack and partially in registers. */
2357 if (reg != 0 && REG_P (reg))
2358 use_reg (call_fusage, reg);
2362 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2363 assigment and the code of the expresion on the RHS is CODE. Return
2364 NULL otherwise. */
2366 static gimple *
2367 get_def_for_expr (tree name, enum tree_code code)
2369 gimple *def_stmt;
2371 if (TREE_CODE (name) != SSA_NAME)
2372 return NULL;
2374 def_stmt = get_gimple_for_ssa_name (name);
2375 if (!def_stmt
2376 || gimple_assign_rhs_code (def_stmt) != code)
2377 return NULL;
2379 return def_stmt;
2382 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2383 assigment and the class of the expresion on the RHS is CLASS. Return
2384 NULL otherwise. */
2386 static gimple *
2387 get_def_for_expr_class (tree name, enum tree_code_class tclass)
2389 gimple *def_stmt;
2391 if (TREE_CODE (name) != SSA_NAME)
2392 return NULL;
2394 def_stmt = get_gimple_for_ssa_name (name);
2395 if (!def_stmt
2396 || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt)) != tclass)
2397 return NULL;
2399 return def_stmt;
2403 /* Determine whether the LEN bytes generated by CONSTFUN can be
2404 stored to memory using several move instructions. CONSTFUNDATA is
2405 a pointer which will be passed as argument in every CONSTFUN call.
2406 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2407 a memset operation and false if it's a copy of a constant string.
2408 Return nonzero if a call to store_by_pieces should succeed. */
2411 can_store_by_pieces (unsigned HOST_WIDE_INT len,
2412 rtx (*constfun) (void *, HOST_WIDE_INT, machine_mode),
2413 void *constfundata, unsigned int align, bool memsetp)
2415 unsigned HOST_WIDE_INT l;
2416 unsigned int max_size;
2417 HOST_WIDE_INT offset = 0;
2418 machine_mode mode;
2419 enum insn_code icode;
2420 int reverse;
2421 /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
2422 rtx cst ATTRIBUTE_UNUSED;
2424 if (len == 0)
2425 return 1;
2427 if (!targetm.use_by_pieces_infrastructure_p (len, align,
2428 memsetp
2429 ? SET_BY_PIECES
2430 : STORE_BY_PIECES,
2431 optimize_insn_for_speed_p ()))
2432 return 0;
2434 align = alignment_for_piecewise_move (STORE_MAX_PIECES, align);
2436 /* We would first store what we can in the largest integer mode, then go to
2437 successively smaller modes. */
2439 for (reverse = 0;
2440 reverse <= (HAVE_PRE_DECREMENT || HAVE_POST_DECREMENT);
2441 reverse++)
2443 l = len;
2444 max_size = STORE_MAX_PIECES + 1;
2445 while (max_size > 1 && l > 0)
2447 mode = widest_int_mode_for_size (max_size);
2449 if (mode == VOIDmode)
2450 break;
2452 icode = optab_handler (mov_optab, mode);
2453 if (icode != CODE_FOR_nothing
2454 && align >= GET_MODE_ALIGNMENT (mode))
2456 unsigned int size = GET_MODE_SIZE (mode);
2458 while (l >= size)
2460 if (reverse)
2461 offset -= size;
2463 cst = (*constfun) (constfundata, offset, mode);
2464 if (!targetm.legitimate_constant_p (mode, cst))
2465 return 0;
2467 if (!reverse)
2468 offset += size;
2470 l -= size;
2474 max_size = GET_MODE_SIZE (mode);
2477 /* The code above should have handled everything. */
2478 gcc_assert (!l);
2481 return 1;
2484 /* Generate several move instructions to store LEN bytes generated by
2485 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2486 pointer which will be passed as argument in every CONSTFUN call.
2487 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2488 a memset operation and false if it's a copy of a constant string.
2489 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2490 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2491 stpcpy. */
2494 store_by_pieces (rtx to, unsigned HOST_WIDE_INT len,
2495 rtx (*constfun) (void *, HOST_WIDE_INT, machine_mode),
2496 void *constfundata, unsigned int align, bool memsetp, int endp)
2498 machine_mode to_addr_mode = get_address_mode (to);
2499 struct store_by_pieces_d data;
2501 if (len == 0)
2503 gcc_assert (endp != 2);
2504 return to;
2507 gcc_assert (targetm.use_by_pieces_infrastructure_p
2508 (len, align,
2509 memsetp
2510 ? SET_BY_PIECES
2511 : STORE_BY_PIECES,
2512 optimize_insn_for_speed_p ()));
2514 data.constfun = constfun;
2515 data.constfundata = constfundata;
2516 data.len = len;
2517 data.to = to;
2518 store_by_pieces_1 (&data, align);
2519 if (endp)
2521 rtx to1;
2523 gcc_assert (!data.reverse);
2524 if (data.autinc_to)
2526 if (endp == 2)
2528 if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
2529 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
2530 else
2531 data.to_addr = copy_to_mode_reg (to_addr_mode,
2532 plus_constant (to_addr_mode,
2533 data.to_addr,
2534 -1));
2536 to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
2537 data.offset);
2539 else
2541 if (endp == 2)
2542 --data.offset;
2543 to1 = adjust_address (data.to, QImode, data.offset);
2545 return to1;
2547 else
2548 return data.to;
2551 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2552 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2554 static void
2555 clear_by_pieces (rtx to, unsigned HOST_WIDE_INT len, unsigned int align)
2557 struct store_by_pieces_d data;
2559 if (len == 0)
2560 return;
2562 data.constfun = clear_by_pieces_1;
2563 data.constfundata = NULL;
2564 data.len = len;
2565 data.to = to;
2566 store_by_pieces_1 (&data, align);
2569 /* Callback routine for clear_by_pieces.
2570 Return const0_rtx unconditionally. */
2572 static rtx
2573 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED,
2574 HOST_WIDE_INT offset ATTRIBUTE_UNUSED,
2575 machine_mode mode ATTRIBUTE_UNUSED)
2577 return const0_rtx;
2580 /* Subroutine of clear_by_pieces and store_by_pieces.
2581 Generate several move instructions to store LEN bytes of block TO. (A MEM
2582 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2584 static void
2585 store_by_pieces_1 (struct store_by_pieces_d *data ATTRIBUTE_UNUSED,
2586 unsigned int align ATTRIBUTE_UNUSED)
2588 machine_mode to_addr_mode = get_address_mode (data->to);
2589 rtx to_addr = XEXP (data->to, 0);
2590 unsigned int max_size = STORE_MAX_PIECES + 1;
2591 enum insn_code icode;
2593 data->offset = 0;
2594 data->to_addr = to_addr;
2595 data->autinc_to
2596 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
2597 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
2599 data->explicit_inc_to = 0;
2600 data->reverse
2601 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
2602 if (data->reverse)
2603 data->offset = data->len;
2605 /* If storing requires more than two move insns,
2606 copy addresses to registers (to make displacements shorter)
2607 and use post-increment if available. */
2608 if (!data->autinc_to
2609 && move_by_pieces_ninsns (data->len, align, max_size) > 2)
2611 /* Determine the main mode we'll be using.
2612 MODE might not be used depending on the definitions of the
2613 USE_* macros below. */
2614 machine_mode mode ATTRIBUTE_UNUSED
2615 = widest_int_mode_for_size (max_size);
2617 if (USE_STORE_PRE_DECREMENT (mode) && data->reverse && ! data->autinc_to)
2619 data->to_addr = copy_to_mode_reg (to_addr_mode,
2620 plus_constant (to_addr_mode,
2621 to_addr,
2622 data->len));
2623 data->autinc_to = 1;
2624 data->explicit_inc_to = -1;
2627 if (USE_STORE_POST_INCREMENT (mode) && ! data->reverse
2628 && ! data->autinc_to)
2630 data->to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
2631 data->autinc_to = 1;
2632 data->explicit_inc_to = 1;
2635 if ( !data->autinc_to && CONSTANT_P (to_addr))
2636 data->to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
2639 align = alignment_for_piecewise_move (STORE_MAX_PIECES, align);
2641 /* First store what we can in the largest integer mode, then go to
2642 successively smaller modes. */
2644 while (max_size > 1 && data->len > 0)
2646 machine_mode mode = widest_int_mode_for_size (max_size);
2648 if (mode == VOIDmode)
2649 break;
2651 icode = optab_handler (mov_optab, mode);
2652 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
2653 store_by_pieces_2 (GEN_FCN (icode), mode, data);
2655 max_size = GET_MODE_SIZE (mode);
2658 /* The code above should have handled everything. */
2659 gcc_assert (!data->len);
2662 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2663 with move instructions for mode MODE. GENFUN is the gen_... function
2664 to make a move insn for that mode. DATA has all the other info. */
2666 static void
2667 store_by_pieces_2 (insn_gen_fn genfun, machine_mode mode,
2668 struct store_by_pieces_d *data)
2670 unsigned int size = GET_MODE_SIZE (mode);
2671 rtx to1, cst;
2673 while (data->len >= size)
2675 if (data->reverse)
2676 data->offset -= size;
2678 if (data->autinc_to)
2679 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
2680 data->offset);
2681 else
2682 to1 = adjust_address (data->to, mode, data->offset);
2684 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
2685 emit_insn (gen_add2_insn (data->to_addr,
2686 gen_int_mode (-(HOST_WIDE_INT) size,
2687 GET_MODE (data->to_addr))));
2689 cst = (*data->constfun) (data->constfundata, data->offset, mode);
2690 emit_insn ((*genfun) (to1, cst));
2692 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
2693 emit_insn (gen_add2_insn (data->to_addr,
2694 gen_int_mode (size,
2695 GET_MODE (data->to_addr))));
2697 if (! data->reverse)
2698 data->offset += size;
2700 data->len -= size;
2704 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2705 its length in bytes. */
2708 clear_storage_hints (rtx object, rtx size, enum block_op_methods method,
2709 unsigned int expected_align, HOST_WIDE_INT expected_size,
2710 unsigned HOST_WIDE_INT min_size,
2711 unsigned HOST_WIDE_INT max_size,
2712 unsigned HOST_WIDE_INT probable_max_size)
2714 machine_mode mode = GET_MODE (object);
2715 unsigned int align;
2717 gcc_assert (method == BLOCK_OP_NORMAL || method == BLOCK_OP_TAILCALL);
2719 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2720 just move a zero. Otherwise, do this a piece at a time. */
2721 if (mode != BLKmode
2722 && CONST_INT_P (size)
2723 && INTVAL (size) == (HOST_WIDE_INT) GET_MODE_SIZE (mode))
2725 rtx zero = CONST0_RTX (mode);
2726 if (zero != NULL)
2728 emit_move_insn (object, zero);
2729 return NULL;
2732 if (COMPLEX_MODE_P (mode))
2734 zero = CONST0_RTX (GET_MODE_INNER (mode));
2735 if (zero != NULL)
2737 write_complex_part (object, zero, 0);
2738 write_complex_part (object, zero, 1);
2739 return NULL;
2744 if (size == const0_rtx)
2745 return NULL;
2747 align = MEM_ALIGN (object);
2749 if (CONST_INT_P (size)
2750 && targetm.use_by_pieces_infrastructure_p (INTVAL (size), align,
2751 CLEAR_BY_PIECES,
2752 optimize_insn_for_speed_p ()))
2753 clear_by_pieces (object, INTVAL (size), align);
2754 else if (set_storage_via_setmem (object, size, const0_rtx, align,
2755 expected_align, expected_size,
2756 min_size, max_size, probable_max_size))
2758 else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object)))
2759 return set_storage_via_libcall (object, size, const0_rtx,
2760 method == BLOCK_OP_TAILCALL);
2761 else
2762 gcc_unreachable ();
2764 return NULL;
2768 clear_storage (rtx object, rtx size, enum block_op_methods method)
2770 unsigned HOST_WIDE_INT max, min = 0;
2771 if (GET_CODE (size) == CONST_INT)
2772 min = max = UINTVAL (size);
2773 else
2774 max = GET_MODE_MASK (GET_MODE (size));
2775 return clear_storage_hints (object, size, method, 0, -1, min, max, max);
2779 /* A subroutine of clear_storage. Expand a call to memset.
2780 Return the return value of memset, 0 otherwise. */
2783 set_storage_via_libcall (rtx object, rtx size, rtx val, bool tailcall)
2785 tree call_expr, fn, object_tree, size_tree, val_tree;
2786 machine_mode size_mode;
2787 rtx retval;
2789 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2790 place those into new pseudos into a VAR_DECL and use them later. */
2792 object = copy_addr_to_reg (XEXP (object, 0));
2794 size_mode = TYPE_MODE (sizetype);
2795 size = convert_to_mode (size_mode, size, 1);
2796 size = copy_to_mode_reg (size_mode, size);
2798 /* It is incorrect to use the libcall calling conventions to call
2799 memset in this context. This could be a user call to memset and
2800 the user may wish to examine the return value from memset. For
2801 targets where libcalls and normal calls have different conventions
2802 for returning pointers, we could end up generating incorrect code. */
2804 object_tree = make_tree (ptr_type_node, object);
2805 if (!CONST_INT_P (val))
2806 val = convert_to_mode (TYPE_MODE (integer_type_node), val, 1);
2807 size_tree = make_tree (sizetype, size);
2808 val_tree = make_tree (integer_type_node, val);
2810 fn = clear_storage_libcall_fn (true);
2811 call_expr = build_call_expr (fn, 3, object_tree, val_tree, size_tree);
2812 CALL_EXPR_TAILCALL (call_expr) = tailcall;
2814 retval = expand_normal (call_expr);
2816 return retval;
2819 /* A subroutine of set_storage_via_libcall. Create the tree node
2820 for the function we use for block clears. */
2822 tree block_clear_fn;
2824 void
2825 init_block_clear_fn (const char *asmspec)
2827 if (!block_clear_fn)
2829 tree fn, args;
2831 fn = get_identifier ("memset");
2832 args = build_function_type_list (ptr_type_node, ptr_type_node,
2833 integer_type_node, sizetype,
2834 NULL_TREE);
2836 fn = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, fn, args);
2837 DECL_EXTERNAL (fn) = 1;
2838 TREE_PUBLIC (fn) = 1;
2839 DECL_ARTIFICIAL (fn) = 1;
2840 TREE_NOTHROW (fn) = 1;
2841 DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
2842 DECL_VISIBILITY_SPECIFIED (fn) = 1;
2844 block_clear_fn = fn;
2847 if (asmspec)
2848 set_user_assembler_name (block_clear_fn, asmspec);
2851 static tree
2852 clear_storage_libcall_fn (int for_call)
2854 static bool emitted_extern;
2856 if (!block_clear_fn)
2857 init_block_clear_fn (NULL);
2859 if (for_call && !emitted_extern)
2861 emitted_extern = true;
2862 make_decl_rtl (block_clear_fn);
2865 return block_clear_fn;
2868 /* Expand a setmem pattern; return true if successful. */
2870 bool
2871 set_storage_via_setmem (rtx object, rtx size, rtx val, unsigned int align,
2872 unsigned int expected_align, HOST_WIDE_INT expected_size,
2873 unsigned HOST_WIDE_INT min_size,
2874 unsigned HOST_WIDE_INT max_size,
2875 unsigned HOST_WIDE_INT probable_max_size)
2877 /* Try the most limited insn first, because there's no point
2878 including more than one in the machine description unless
2879 the more limited one has some advantage. */
2881 machine_mode mode;
2883 if (expected_align < align)
2884 expected_align = align;
2885 if (expected_size != -1)
2887 if ((unsigned HOST_WIDE_INT)expected_size > max_size)
2888 expected_size = max_size;
2889 if ((unsigned HOST_WIDE_INT)expected_size < min_size)
2890 expected_size = min_size;
2893 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
2894 mode = GET_MODE_WIDER_MODE (mode))
2896 enum insn_code code = direct_optab_handler (setmem_optab, mode);
2898 if (code != CODE_FOR_nothing
2899 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
2900 here because if SIZE is less than the mode mask, as it is
2901 returned by the macro, it will definitely be less than the
2902 actual mode mask. Since SIZE is within the Pmode address
2903 space, we limit MODE to Pmode. */
2904 && ((CONST_INT_P (size)
2905 && ((unsigned HOST_WIDE_INT) INTVAL (size)
2906 <= (GET_MODE_MASK (mode) >> 1)))
2907 || max_size <= (GET_MODE_MASK (mode) >> 1)
2908 || GET_MODE_BITSIZE (mode) >= GET_MODE_BITSIZE (Pmode)))
2910 struct expand_operand ops[9];
2911 unsigned int nops;
2913 nops = insn_data[(int) code].n_generator_args;
2914 gcc_assert (nops == 4 || nops == 6 || nops == 8 || nops == 9);
2916 create_fixed_operand (&ops[0], object);
2917 /* The check above guarantees that this size conversion is valid. */
2918 create_convert_operand_to (&ops[1], size, mode, true);
2919 create_convert_operand_from (&ops[2], val, byte_mode, true);
2920 create_integer_operand (&ops[3], align / BITS_PER_UNIT);
2921 if (nops >= 6)
2923 create_integer_operand (&ops[4], expected_align / BITS_PER_UNIT);
2924 create_integer_operand (&ops[5], expected_size);
2926 if (nops >= 8)
2928 create_integer_operand (&ops[6], min_size);
2929 /* If we can not represent the maximal size,
2930 make parameter NULL. */
2931 if ((HOST_WIDE_INT) max_size != -1)
2932 create_integer_operand (&ops[7], max_size);
2933 else
2934 create_fixed_operand (&ops[7], NULL);
2936 if (nops == 9)
2938 /* If we can not represent the maximal size,
2939 make parameter NULL. */
2940 if ((HOST_WIDE_INT) probable_max_size != -1)
2941 create_integer_operand (&ops[8], probable_max_size);
2942 else
2943 create_fixed_operand (&ops[8], NULL);
2945 if (maybe_expand_insn (code, nops, ops))
2946 return true;
2950 return false;
2954 /* Write to one of the components of the complex value CPLX. Write VAL to
2955 the real part if IMAG_P is false, and the imaginary part if its true. */
2957 void
2958 write_complex_part (rtx cplx, rtx val, bool imag_p)
2960 machine_mode cmode;
2961 machine_mode imode;
2962 unsigned ibitsize;
2964 if (GET_CODE (cplx) == CONCAT)
2966 emit_move_insn (XEXP (cplx, imag_p), val);
2967 return;
2970 cmode = GET_MODE (cplx);
2971 imode = GET_MODE_INNER (cmode);
2972 ibitsize = GET_MODE_BITSIZE (imode);
2974 /* For MEMs simplify_gen_subreg may generate an invalid new address
2975 because, e.g., the original address is considered mode-dependent
2976 by the target, which restricts simplify_subreg from invoking
2977 adjust_address_nv. Instead of preparing fallback support for an
2978 invalid address, we call adjust_address_nv directly. */
2979 if (MEM_P (cplx))
2981 emit_move_insn (adjust_address_nv (cplx, imode,
2982 imag_p ? GET_MODE_SIZE (imode) : 0),
2983 val);
2984 return;
2987 /* If the sub-object is at least word sized, then we know that subregging
2988 will work. This special case is important, since store_bit_field
2989 wants to operate on integer modes, and there's rarely an OImode to
2990 correspond to TCmode. */
2991 if (ibitsize >= BITS_PER_WORD
2992 /* For hard regs we have exact predicates. Assume we can split
2993 the original object if it spans an even number of hard regs.
2994 This special case is important for SCmode on 64-bit platforms
2995 where the natural size of floating-point regs is 32-bit. */
2996 || (REG_P (cplx)
2997 && REGNO (cplx) < FIRST_PSEUDO_REGISTER
2998 && REG_NREGS (cplx) % 2 == 0))
3000 rtx part = simplify_gen_subreg (imode, cplx, cmode,
3001 imag_p ? GET_MODE_SIZE (imode) : 0);
3002 if (part)
3004 emit_move_insn (part, val);
3005 return;
3007 else
3008 /* simplify_gen_subreg may fail for sub-word MEMs. */
3009 gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
3012 store_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0, 0, 0, imode, val,
3013 false);
3016 /* Extract one of the components of the complex value CPLX. Extract the
3017 real part if IMAG_P is false, and the imaginary part if it's true. */
3020 read_complex_part (rtx cplx, bool imag_p)
3022 machine_mode cmode, imode;
3023 unsigned ibitsize;
3025 if (GET_CODE (cplx) == CONCAT)
3026 return XEXP (cplx, imag_p);
3028 cmode = GET_MODE (cplx);
3029 imode = GET_MODE_INNER (cmode);
3030 ibitsize = GET_MODE_BITSIZE (imode);
3032 /* Special case reads from complex constants that got spilled to memory. */
3033 if (MEM_P (cplx) && GET_CODE (XEXP (cplx, 0)) == SYMBOL_REF)
3035 tree decl = SYMBOL_REF_DECL (XEXP (cplx, 0));
3036 if (decl && TREE_CODE (decl) == COMPLEX_CST)
3038 tree part = imag_p ? TREE_IMAGPART (decl) : TREE_REALPART (decl);
3039 if (CONSTANT_CLASS_P (part))
3040 return expand_expr (part, NULL_RTX, imode, EXPAND_NORMAL);
3044 /* For MEMs simplify_gen_subreg may generate an invalid new address
3045 because, e.g., the original address is considered mode-dependent
3046 by the target, which restricts simplify_subreg from invoking
3047 adjust_address_nv. Instead of preparing fallback support for an
3048 invalid address, we call adjust_address_nv directly. */
3049 if (MEM_P (cplx))
3050 return adjust_address_nv (cplx, imode,
3051 imag_p ? GET_MODE_SIZE (imode) : 0);
3053 /* If the sub-object is at least word sized, then we know that subregging
3054 will work. This special case is important, since extract_bit_field
3055 wants to operate on integer modes, and there's rarely an OImode to
3056 correspond to TCmode. */
3057 if (ibitsize >= BITS_PER_WORD
3058 /* For hard regs we have exact predicates. Assume we can split
3059 the original object if it spans an even number of hard regs.
3060 This special case is important for SCmode on 64-bit platforms
3061 where the natural size of floating-point regs is 32-bit. */
3062 || (REG_P (cplx)
3063 && REGNO (cplx) < FIRST_PSEUDO_REGISTER
3064 && REG_NREGS (cplx) % 2 == 0))
3066 rtx ret = simplify_gen_subreg (imode, cplx, cmode,
3067 imag_p ? GET_MODE_SIZE (imode) : 0);
3068 if (ret)
3069 return ret;
3070 else
3071 /* simplify_gen_subreg may fail for sub-word MEMs. */
3072 gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
3075 return extract_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0,
3076 true, NULL_RTX, imode, imode, false);
3079 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
3080 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
3081 represented in NEW_MODE. If FORCE is true, this will never happen, as
3082 we'll force-create a SUBREG if needed. */
3084 static rtx
3085 emit_move_change_mode (machine_mode new_mode,
3086 machine_mode old_mode, rtx x, bool force)
3088 rtx ret;
3090 if (push_operand (x, GET_MODE (x)))
3092 ret = gen_rtx_MEM (new_mode, XEXP (x, 0));
3093 MEM_COPY_ATTRIBUTES (ret, x);
3095 else if (MEM_P (x))
3097 /* We don't have to worry about changing the address since the
3098 size in bytes is supposed to be the same. */
3099 if (reload_in_progress)
3101 /* Copy the MEM to change the mode and move any
3102 substitutions from the old MEM to the new one. */
3103 ret = adjust_address_nv (x, new_mode, 0);
3104 copy_replacements (x, ret);
3106 else
3107 ret = adjust_address (x, new_mode, 0);
3109 else
3111 /* Note that we do want simplify_subreg's behavior of validating
3112 that the new mode is ok for a hard register. If we were to use
3113 simplify_gen_subreg, we would create the subreg, but would
3114 probably run into the target not being able to implement it. */
3115 /* Except, of course, when FORCE is true, when this is exactly what
3116 we want. Which is needed for CCmodes on some targets. */
3117 if (force)
3118 ret = simplify_gen_subreg (new_mode, x, old_mode, 0);
3119 else
3120 ret = simplify_subreg (new_mode, x, old_mode, 0);
3123 return ret;
3126 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
3127 an integer mode of the same size as MODE. Returns the instruction
3128 emitted, or NULL if such a move could not be generated. */
3130 static rtx_insn *
3131 emit_move_via_integer (machine_mode mode, rtx x, rtx y, bool force)
3133 machine_mode imode;
3134 enum insn_code code;
3136 /* There must exist a mode of the exact size we require. */
3137 imode = int_mode_for_mode (mode);
3138 if (imode == BLKmode)
3139 return NULL;
3141 /* The target must support moves in this mode. */
3142 code = optab_handler (mov_optab, imode);
3143 if (code == CODE_FOR_nothing)
3144 return NULL;
3146 x = emit_move_change_mode (imode, mode, x, force);
3147 if (x == NULL_RTX)
3148 return NULL;
3149 y = emit_move_change_mode (imode, mode, y, force);
3150 if (y == NULL_RTX)
3151 return NULL;
3152 return emit_insn (GEN_FCN (code) (x, y));
3155 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
3156 Return an equivalent MEM that does not use an auto-increment. */
3159 emit_move_resolve_push (machine_mode mode, rtx x)
3161 enum rtx_code code = GET_CODE (XEXP (x, 0));
3162 HOST_WIDE_INT adjust;
3163 rtx temp;
3165 adjust = GET_MODE_SIZE (mode);
3166 #ifdef PUSH_ROUNDING
3167 adjust = PUSH_ROUNDING (adjust);
3168 #endif
3169 if (code == PRE_DEC || code == POST_DEC)
3170 adjust = -adjust;
3171 else if (code == PRE_MODIFY || code == POST_MODIFY)
3173 rtx expr = XEXP (XEXP (x, 0), 1);
3174 HOST_WIDE_INT val;
3176 gcc_assert (GET_CODE (expr) == PLUS || GET_CODE (expr) == MINUS);
3177 gcc_assert (CONST_INT_P (XEXP (expr, 1)));
3178 val = INTVAL (XEXP (expr, 1));
3179 if (GET_CODE (expr) == MINUS)
3180 val = -val;
3181 gcc_assert (adjust == val || adjust == -val);
3182 adjust = val;
3185 /* Do not use anti_adjust_stack, since we don't want to update
3186 stack_pointer_delta. */
3187 temp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
3188 gen_int_mode (adjust, Pmode), stack_pointer_rtx,
3189 0, OPTAB_LIB_WIDEN);
3190 if (temp != stack_pointer_rtx)
3191 emit_move_insn (stack_pointer_rtx, temp);
3193 switch (code)
3195 case PRE_INC:
3196 case PRE_DEC:
3197 case PRE_MODIFY:
3198 temp = stack_pointer_rtx;
3199 break;
3200 case POST_INC:
3201 case POST_DEC:
3202 case POST_MODIFY:
3203 temp = plus_constant (Pmode, stack_pointer_rtx, -adjust);
3204 break;
3205 default:
3206 gcc_unreachable ();
3209 return replace_equiv_address (x, temp);
3212 /* A subroutine of emit_move_complex. Generate a move from Y into X.
3213 X is known to satisfy push_operand, and MODE is known to be complex.
3214 Returns the last instruction emitted. */
3216 rtx_insn *
3217 emit_move_complex_push (machine_mode mode, rtx x, rtx y)
3219 machine_mode submode = GET_MODE_INNER (mode);
3220 bool imag_first;
3222 #ifdef PUSH_ROUNDING
3223 unsigned int submodesize = GET_MODE_SIZE (submode);
3225 /* In case we output to the stack, but the size is smaller than the
3226 machine can push exactly, we need to use move instructions. */
3227 if (PUSH_ROUNDING (submodesize) != submodesize)
3229 x = emit_move_resolve_push (mode, x);
3230 return emit_move_insn (x, y);
3232 #endif
3234 /* Note that the real part always precedes the imag part in memory
3235 regardless of machine's endianness. */
3236 switch (GET_CODE (XEXP (x, 0)))
3238 case PRE_DEC:
3239 case POST_DEC:
3240 imag_first = true;
3241 break;
3242 case PRE_INC:
3243 case POST_INC:
3244 imag_first = false;
3245 break;
3246 default:
3247 gcc_unreachable ();
3250 emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
3251 read_complex_part (y, imag_first));
3252 return emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
3253 read_complex_part (y, !imag_first));
3256 /* A subroutine of emit_move_complex. Perform the move from Y to X
3257 via two moves of the parts. Returns the last instruction emitted. */
3259 rtx_insn *
3260 emit_move_complex_parts (rtx x, rtx y)
3262 /* Show the output dies here. This is necessary for SUBREGs
3263 of pseudos since we cannot track their lifetimes correctly;
3264 hard regs shouldn't appear here except as return values. */
3265 if (!reload_completed && !reload_in_progress
3266 && REG_P (x) && !reg_overlap_mentioned_p (x, y))
3267 emit_clobber (x);
3269 write_complex_part (x, read_complex_part (y, false), false);
3270 write_complex_part (x, read_complex_part (y, true), true);
3272 return get_last_insn ();
3275 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3276 MODE is known to be complex. Returns the last instruction emitted. */
3278 static rtx_insn *
3279 emit_move_complex (machine_mode mode, rtx x, rtx y)
3281 bool try_int;
3283 /* Need to take special care for pushes, to maintain proper ordering
3284 of the data, and possibly extra padding. */
3285 if (push_operand (x, mode))
3286 return emit_move_complex_push (mode, x, y);
3288 /* See if we can coerce the target into moving both values at once, except
3289 for floating point where we favor moving as parts if this is easy. */
3290 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
3291 && optab_handler (mov_optab, GET_MODE_INNER (mode)) != CODE_FOR_nothing
3292 && !(REG_P (x)
3293 && HARD_REGISTER_P (x)
3294 && REG_NREGS (x) == 1)
3295 && !(REG_P (y)
3296 && HARD_REGISTER_P (y)
3297 && REG_NREGS (y) == 1))
3298 try_int = false;
3299 /* Not possible if the values are inherently not adjacent. */
3300 else if (GET_CODE (x) == CONCAT || GET_CODE (y) == CONCAT)
3301 try_int = false;
3302 /* Is possible if both are registers (or subregs of registers). */
3303 else if (register_operand (x, mode) && register_operand (y, mode))
3304 try_int = true;
3305 /* If one of the operands is a memory, and alignment constraints
3306 are friendly enough, we may be able to do combined memory operations.
3307 We do not attempt this if Y is a constant because that combination is
3308 usually better with the by-parts thing below. */
3309 else if ((MEM_P (x) ? !CONSTANT_P (y) : MEM_P (y))
3310 && (!STRICT_ALIGNMENT
3311 || get_mode_alignment (mode) == BIGGEST_ALIGNMENT))
3312 try_int = true;
3313 else
3314 try_int = false;
3316 if (try_int)
3318 rtx_insn *ret;
3320 /* For memory to memory moves, optimal behavior can be had with the
3321 existing block move logic. */
3322 if (MEM_P (x) && MEM_P (y))
3324 emit_block_move (x, y, GEN_INT (GET_MODE_SIZE (mode)),
3325 BLOCK_OP_NO_LIBCALL);
3326 return get_last_insn ();
3329 ret = emit_move_via_integer (mode, x, y, true);
3330 if (ret)
3331 return ret;
3334 return emit_move_complex_parts (x, y);
3337 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3338 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3340 static rtx_insn *
3341 emit_move_ccmode (machine_mode mode, rtx x, rtx y)
3343 rtx_insn *ret;
3345 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3346 if (mode != CCmode)
3348 enum insn_code code = optab_handler (mov_optab, CCmode);
3349 if (code != CODE_FOR_nothing)
3351 x = emit_move_change_mode (CCmode, mode, x, true);
3352 y = emit_move_change_mode (CCmode, mode, y, true);
3353 return emit_insn (GEN_FCN (code) (x, y));
3357 /* Otherwise, find the MODE_INT mode of the same width. */
3358 ret = emit_move_via_integer (mode, x, y, false);
3359 gcc_assert (ret != NULL);
3360 return ret;
3363 /* Return true if word I of OP lies entirely in the
3364 undefined bits of a paradoxical subreg. */
3366 static bool
3367 undefined_operand_subword_p (const_rtx op, int i)
3369 machine_mode innermode, innermostmode;
3370 int offset;
3371 if (GET_CODE (op) != SUBREG)
3372 return false;
3373 innermode = GET_MODE (op);
3374 innermostmode = GET_MODE (SUBREG_REG (op));
3375 offset = i * UNITS_PER_WORD + SUBREG_BYTE (op);
3376 /* The SUBREG_BYTE represents offset, as if the value were stored in
3377 memory, except for a paradoxical subreg where we define
3378 SUBREG_BYTE to be 0; undo this exception as in
3379 simplify_subreg. */
3380 if (SUBREG_BYTE (op) == 0
3381 && GET_MODE_SIZE (innermostmode) < GET_MODE_SIZE (innermode))
3383 int difference = (GET_MODE_SIZE (innermostmode) - GET_MODE_SIZE (innermode));
3384 if (WORDS_BIG_ENDIAN)
3385 offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD;
3386 if (BYTES_BIG_ENDIAN)
3387 offset += difference % UNITS_PER_WORD;
3389 if (offset >= GET_MODE_SIZE (innermostmode)
3390 || offset <= -GET_MODE_SIZE (word_mode))
3391 return true;
3392 return false;
3395 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3396 MODE is any multi-word or full-word mode that lacks a move_insn
3397 pattern. Note that you will get better code if you define such
3398 patterns, even if they must turn into multiple assembler instructions. */
3400 static rtx_insn *
3401 emit_move_multi_word (machine_mode mode, rtx x, rtx y)
3403 rtx_insn *last_insn = 0;
3404 rtx_insn *seq;
3405 rtx inner;
3406 bool need_clobber;
3407 int i;
3409 gcc_assert (GET_MODE_SIZE (mode) >= UNITS_PER_WORD);
3411 /* If X is a push on the stack, do the push now and replace
3412 X with a reference to the stack pointer. */
3413 if (push_operand (x, mode))
3414 x = emit_move_resolve_push (mode, x);
3416 /* If we are in reload, see if either operand is a MEM whose address
3417 is scheduled for replacement. */
3418 if (reload_in_progress && MEM_P (x)
3419 && (inner = find_replacement (&XEXP (x, 0))) != XEXP (x, 0))
3420 x = replace_equiv_address_nv (x, inner);
3421 if (reload_in_progress && MEM_P (y)
3422 && (inner = find_replacement (&XEXP (y, 0))) != XEXP (y, 0))
3423 y = replace_equiv_address_nv (y, inner);
3425 start_sequence ();
3427 need_clobber = false;
3428 for (i = 0;
3429 i < (GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
3430 i++)
3432 rtx xpart = operand_subword (x, i, 1, mode);
3433 rtx ypart;
3435 /* Do not generate code for a move if it would come entirely
3436 from the undefined bits of a paradoxical subreg. */
3437 if (undefined_operand_subword_p (y, i))
3438 continue;
3440 ypart = operand_subword (y, i, 1, mode);
3442 /* If we can't get a part of Y, put Y into memory if it is a
3443 constant. Otherwise, force it into a register. Then we must
3444 be able to get a part of Y. */
3445 if (ypart == 0 && CONSTANT_P (y))
3447 y = use_anchored_address (force_const_mem (mode, y));
3448 ypart = operand_subword (y, i, 1, mode);
3450 else if (ypart == 0)
3451 ypart = operand_subword_force (y, i, mode);
3453 gcc_assert (xpart && ypart);
3455 need_clobber |= (GET_CODE (xpart) == SUBREG);
3457 last_insn = emit_move_insn (xpart, ypart);
3460 seq = get_insns ();
3461 end_sequence ();
3463 /* Show the output dies here. This is necessary for SUBREGs
3464 of pseudos since we cannot track their lifetimes correctly;
3465 hard regs shouldn't appear here except as return values.
3466 We never want to emit such a clobber after reload. */
3467 if (x != y
3468 && ! (reload_in_progress || reload_completed)
3469 && need_clobber != 0)
3470 emit_clobber (x);
3472 emit_insn (seq);
3474 return last_insn;
3477 /* Low level part of emit_move_insn.
3478 Called just like emit_move_insn, but assumes X and Y
3479 are basically valid. */
3481 rtx_insn *
3482 emit_move_insn_1 (rtx x, rtx y)
3484 machine_mode mode = GET_MODE (x);
3485 enum insn_code code;
3487 gcc_assert ((unsigned int) mode < (unsigned int) MAX_MACHINE_MODE);
3489 code = optab_handler (mov_optab, mode);
3490 if (code != CODE_FOR_nothing)
3491 return emit_insn (GEN_FCN (code) (x, y));
3493 /* Expand complex moves by moving real part and imag part. */
3494 if (COMPLEX_MODE_P (mode))
3495 return emit_move_complex (mode, x, y);
3497 if (GET_MODE_CLASS (mode) == MODE_DECIMAL_FLOAT
3498 || ALL_FIXED_POINT_MODE_P (mode))
3500 rtx_insn *result = emit_move_via_integer (mode, x, y, true);
3502 /* If we can't find an integer mode, use multi words. */
3503 if (result)
3504 return result;
3505 else
3506 return emit_move_multi_word (mode, x, y);
3509 if (GET_MODE_CLASS (mode) == MODE_CC)
3510 return emit_move_ccmode (mode, x, y);
3512 /* Try using a move pattern for the corresponding integer mode. This is
3513 only safe when simplify_subreg can convert MODE constants into integer
3514 constants. At present, it can only do this reliably if the value
3515 fits within a HOST_WIDE_INT. */
3516 if (!CONSTANT_P (y) || GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
3518 rtx_insn *ret = emit_move_via_integer (mode, x, y, lra_in_progress);
3520 if (ret)
3522 if (! lra_in_progress || recog (PATTERN (ret), ret, 0) >= 0)
3523 return ret;
3527 return emit_move_multi_word (mode, x, y);
3530 /* Generate code to copy Y into X.
3531 Both Y and X must have the same mode, except that
3532 Y can be a constant with VOIDmode.
3533 This mode cannot be BLKmode; use emit_block_move for that.
3535 Return the last instruction emitted. */
3537 rtx_insn *
3538 emit_move_insn (rtx x, rtx y)
3540 machine_mode mode = GET_MODE (x);
3541 rtx y_cst = NULL_RTX;
3542 rtx_insn *last_insn;
3543 rtx set;
3545 gcc_assert (mode != BLKmode
3546 && (GET_MODE (y) == mode || GET_MODE (y) == VOIDmode));
3548 if (CONSTANT_P (y))
3550 if (optimize
3551 && SCALAR_FLOAT_MODE_P (GET_MODE (x))
3552 && (last_insn = compress_float_constant (x, y)))
3553 return last_insn;
3555 y_cst = y;
3557 if (!targetm.legitimate_constant_p (mode, y))
3559 y = force_const_mem (mode, y);
3561 /* If the target's cannot_force_const_mem prevented the spill,
3562 assume that the target's move expanders will also take care
3563 of the non-legitimate constant. */
3564 if (!y)
3565 y = y_cst;
3566 else
3567 y = use_anchored_address (y);
3571 /* If X or Y are memory references, verify that their addresses are valid
3572 for the machine. */
3573 if (MEM_P (x)
3574 && (! memory_address_addr_space_p (GET_MODE (x), XEXP (x, 0),
3575 MEM_ADDR_SPACE (x))
3576 && ! push_operand (x, GET_MODE (x))))
3577 x = validize_mem (x);
3579 if (MEM_P (y)
3580 && ! memory_address_addr_space_p (GET_MODE (y), XEXP (y, 0),
3581 MEM_ADDR_SPACE (y)))
3582 y = validize_mem (y);
3584 gcc_assert (mode != BLKmode);
3586 last_insn = emit_move_insn_1 (x, y);
3588 if (y_cst && REG_P (x)
3589 && (set = single_set (last_insn)) != NULL_RTX
3590 && SET_DEST (set) == x
3591 && ! rtx_equal_p (y_cst, SET_SRC (set)))
3592 set_unique_reg_note (last_insn, REG_EQUAL, copy_rtx (y_cst));
3594 return last_insn;
3597 /* Generate the body of an instruction to copy Y into X.
3598 It may be a list of insns, if one insn isn't enough. */
3600 rtx_insn *
3601 gen_move_insn (rtx x, rtx y)
3603 rtx_insn *seq;
3605 start_sequence ();
3606 emit_move_insn_1 (x, y);
3607 seq = get_insns ();
3608 end_sequence ();
3609 return seq;
3612 /* If Y is representable exactly in a narrower mode, and the target can
3613 perform the extension directly from constant or memory, then emit the
3614 move as an extension. */
3616 static rtx_insn *
3617 compress_float_constant (rtx x, rtx y)
3619 machine_mode dstmode = GET_MODE (x);
3620 machine_mode orig_srcmode = GET_MODE (y);
3621 machine_mode srcmode;
3622 const REAL_VALUE_TYPE *r;
3623 int oldcost, newcost;
3624 bool speed = optimize_insn_for_speed_p ();
3626 r = CONST_DOUBLE_REAL_VALUE (y);
3628 if (targetm.legitimate_constant_p (dstmode, y))
3629 oldcost = set_src_cost (y, orig_srcmode, speed);
3630 else
3631 oldcost = set_src_cost (force_const_mem (dstmode, y), dstmode, speed);
3633 for (srcmode = GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode));
3634 srcmode != orig_srcmode;
3635 srcmode = GET_MODE_WIDER_MODE (srcmode))
3637 enum insn_code ic;
3638 rtx trunc_y;
3639 rtx_insn *last_insn;
3641 /* Skip if the target can't extend this way. */
3642 ic = can_extend_p (dstmode, srcmode, 0);
3643 if (ic == CODE_FOR_nothing)
3644 continue;
3646 /* Skip if the narrowed value isn't exact. */
3647 if (! exact_real_truncate (srcmode, r))
3648 continue;
3650 trunc_y = const_double_from_real_value (*r, srcmode);
3652 if (targetm.legitimate_constant_p (srcmode, trunc_y))
3654 /* Skip if the target needs extra instructions to perform
3655 the extension. */
3656 if (!insn_operand_matches (ic, 1, trunc_y))
3657 continue;
3658 /* This is valid, but may not be cheaper than the original. */
3659 newcost = set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y),
3660 dstmode, speed);
3661 if (oldcost < newcost)
3662 continue;
3664 else if (float_extend_from_mem[dstmode][srcmode])
3666 trunc_y = force_const_mem (srcmode, trunc_y);
3667 /* This is valid, but may not be cheaper than the original. */
3668 newcost = set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y),
3669 dstmode, speed);
3670 if (oldcost < newcost)
3671 continue;
3672 trunc_y = validize_mem (trunc_y);
3674 else
3675 continue;
3677 /* For CSE's benefit, force the compressed constant pool entry
3678 into a new pseudo. This constant may be used in different modes,
3679 and if not, combine will put things back together for us. */
3680 trunc_y = force_reg (srcmode, trunc_y);
3682 /* If x is a hard register, perform the extension into a pseudo,
3683 so that e.g. stack realignment code is aware of it. */
3684 rtx target = x;
3685 if (REG_P (x) && HARD_REGISTER_P (x))
3686 target = gen_reg_rtx (dstmode);
3688 emit_unop_insn (ic, target, trunc_y, UNKNOWN);
3689 last_insn = get_last_insn ();
3691 if (REG_P (target))
3692 set_unique_reg_note (last_insn, REG_EQUAL, y);
3694 if (target != x)
3695 return emit_move_insn (x, target);
3696 return last_insn;
3699 return NULL;
3702 /* Pushing data onto the stack. */
3704 /* Push a block of length SIZE (perhaps variable)
3705 and return an rtx to address the beginning of the block.
3706 The value may be virtual_outgoing_args_rtx.
3708 EXTRA is the number of bytes of padding to push in addition to SIZE.
3709 BELOW nonzero means this padding comes at low addresses;
3710 otherwise, the padding comes at high addresses. */
3713 push_block (rtx size, int extra, int below)
3715 rtx temp;
3717 size = convert_modes (Pmode, ptr_mode, size, 1);
3718 if (CONSTANT_P (size))
3719 anti_adjust_stack (plus_constant (Pmode, size, extra));
3720 else if (REG_P (size) && extra == 0)
3721 anti_adjust_stack (size);
3722 else
3724 temp = copy_to_mode_reg (Pmode, size);
3725 if (extra != 0)
3726 temp = expand_binop (Pmode, add_optab, temp,
3727 gen_int_mode (extra, Pmode),
3728 temp, 0, OPTAB_LIB_WIDEN);
3729 anti_adjust_stack (temp);
3732 if (STACK_GROWS_DOWNWARD)
3734 temp = virtual_outgoing_args_rtx;
3735 if (extra != 0 && below)
3736 temp = plus_constant (Pmode, temp, extra);
3738 else
3740 if (CONST_INT_P (size))
3741 temp = plus_constant (Pmode, virtual_outgoing_args_rtx,
3742 -INTVAL (size) - (below ? 0 : extra));
3743 else if (extra != 0 && !below)
3744 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
3745 negate_rtx (Pmode, plus_constant (Pmode, size,
3746 extra)));
3747 else
3748 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
3749 negate_rtx (Pmode, size));
3752 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT), temp);
3755 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
3757 static rtx
3758 mem_autoinc_base (rtx mem)
3760 if (MEM_P (mem))
3762 rtx addr = XEXP (mem, 0);
3763 if (GET_RTX_CLASS (GET_CODE (addr)) == RTX_AUTOINC)
3764 return XEXP (addr, 0);
3766 return NULL;
3769 /* A utility routine used here, in reload, and in try_split. The insns
3770 after PREV up to and including LAST are known to adjust the stack,
3771 with a final value of END_ARGS_SIZE. Iterate backward from LAST
3772 placing notes as appropriate. PREV may be NULL, indicating the
3773 entire insn sequence prior to LAST should be scanned.
3775 The set of allowed stack pointer modifications is small:
3776 (1) One or more auto-inc style memory references (aka pushes),
3777 (2) One or more addition/subtraction with the SP as destination,
3778 (3) A single move insn with the SP as destination,
3779 (4) A call_pop insn,
3780 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
3782 Insns in the sequence that do not modify the SP are ignored,
3783 except for noreturn calls.
3785 The return value is the amount of adjustment that can be trivially
3786 verified, via immediate operand or auto-inc. If the adjustment
3787 cannot be trivially extracted, the return value is INT_MIN. */
3789 HOST_WIDE_INT
3790 find_args_size_adjust (rtx_insn *insn)
3792 rtx dest, set, pat;
3793 int i;
3795 pat = PATTERN (insn);
3796 set = NULL;
3798 /* Look for a call_pop pattern. */
3799 if (CALL_P (insn))
3801 /* We have to allow non-call_pop patterns for the case
3802 of emit_single_push_insn of a TLS address. */
3803 if (GET_CODE (pat) != PARALLEL)
3804 return 0;
3806 /* All call_pop have a stack pointer adjust in the parallel.
3807 The call itself is always first, and the stack adjust is
3808 usually last, so search from the end. */
3809 for (i = XVECLEN (pat, 0) - 1; i > 0; --i)
3811 set = XVECEXP (pat, 0, i);
3812 if (GET_CODE (set) != SET)
3813 continue;
3814 dest = SET_DEST (set);
3815 if (dest == stack_pointer_rtx)
3816 break;
3818 /* We'd better have found the stack pointer adjust. */
3819 if (i == 0)
3820 return 0;
3821 /* Fall through to process the extracted SET and DEST
3822 as if it was a standalone insn. */
3824 else if (GET_CODE (pat) == SET)
3825 set = pat;
3826 else if ((set = single_set (insn)) != NULL)
3828 else if (GET_CODE (pat) == PARALLEL)
3830 /* ??? Some older ports use a parallel with a stack adjust
3831 and a store for a PUSH_ROUNDING pattern, rather than a
3832 PRE/POST_MODIFY rtx. Don't force them to update yet... */
3833 /* ??? See h8300 and m68k, pushqi1. */
3834 for (i = XVECLEN (pat, 0) - 1; i >= 0; --i)
3836 set = XVECEXP (pat, 0, i);
3837 if (GET_CODE (set) != SET)
3838 continue;
3839 dest = SET_DEST (set);
3840 if (dest == stack_pointer_rtx)
3841 break;
3843 /* We do not expect an auto-inc of the sp in the parallel. */
3844 gcc_checking_assert (mem_autoinc_base (dest) != stack_pointer_rtx);
3845 gcc_checking_assert (mem_autoinc_base (SET_SRC (set))
3846 != stack_pointer_rtx);
3848 if (i < 0)
3849 return 0;
3851 else
3852 return 0;
3854 dest = SET_DEST (set);
3856 /* Look for direct modifications of the stack pointer. */
3857 if (REG_P (dest) && REGNO (dest) == STACK_POINTER_REGNUM)
3859 /* Look for a trivial adjustment, otherwise assume nothing. */
3860 /* Note that the SPU restore_stack_block pattern refers to
3861 the stack pointer in V4SImode. Consider that non-trivial. */
3862 if (SCALAR_INT_MODE_P (GET_MODE (dest))
3863 && GET_CODE (SET_SRC (set)) == PLUS
3864 && XEXP (SET_SRC (set), 0) == stack_pointer_rtx
3865 && CONST_INT_P (XEXP (SET_SRC (set), 1)))
3866 return INTVAL (XEXP (SET_SRC (set), 1));
3867 /* ??? Reload can generate no-op moves, which will be cleaned
3868 up later. Recognize it and continue searching. */
3869 else if (rtx_equal_p (dest, SET_SRC (set)))
3870 return 0;
3871 else
3872 return HOST_WIDE_INT_MIN;
3874 else
3876 rtx mem, addr;
3878 /* Otherwise only think about autoinc patterns. */
3879 if (mem_autoinc_base (dest) == stack_pointer_rtx)
3881 mem = dest;
3882 gcc_checking_assert (mem_autoinc_base (SET_SRC (set))
3883 != stack_pointer_rtx);
3885 else if (mem_autoinc_base (SET_SRC (set)) == stack_pointer_rtx)
3886 mem = SET_SRC (set);
3887 else
3888 return 0;
3890 addr = XEXP (mem, 0);
3891 switch (GET_CODE (addr))
3893 case PRE_INC:
3894 case POST_INC:
3895 return GET_MODE_SIZE (GET_MODE (mem));
3896 case PRE_DEC:
3897 case POST_DEC:
3898 return -GET_MODE_SIZE (GET_MODE (mem));
3899 case PRE_MODIFY:
3900 case POST_MODIFY:
3901 addr = XEXP (addr, 1);
3902 gcc_assert (GET_CODE (addr) == PLUS);
3903 gcc_assert (XEXP (addr, 0) == stack_pointer_rtx);
3904 gcc_assert (CONST_INT_P (XEXP (addr, 1)));
3905 return INTVAL (XEXP (addr, 1));
3906 default:
3907 gcc_unreachable ();
3913 fixup_args_size_notes (rtx_insn *prev, rtx_insn *last, int end_args_size)
3915 int args_size = end_args_size;
3916 bool saw_unknown = false;
3917 rtx_insn *insn;
3919 for (insn = last; insn != prev; insn = PREV_INSN (insn))
3921 HOST_WIDE_INT this_delta;
3923 if (!NONDEBUG_INSN_P (insn))
3924 continue;
3926 this_delta = find_args_size_adjust (insn);
3927 if (this_delta == 0)
3929 if (!CALL_P (insn)
3930 || ACCUMULATE_OUTGOING_ARGS
3931 || find_reg_note (insn, REG_NORETURN, NULL_RTX) == NULL_RTX)
3932 continue;
3935 gcc_assert (!saw_unknown);
3936 if (this_delta == HOST_WIDE_INT_MIN)
3937 saw_unknown = true;
3939 add_reg_note (insn, REG_ARGS_SIZE, GEN_INT (args_size));
3940 if (STACK_GROWS_DOWNWARD)
3941 this_delta = -(unsigned HOST_WIDE_INT) this_delta;
3943 args_size -= this_delta;
3946 return saw_unknown ? INT_MIN : args_size;
3949 #ifdef PUSH_ROUNDING
3950 /* Emit single push insn. */
3952 static void
3953 emit_single_push_insn_1 (machine_mode mode, rtx x, tree type)
3955 rtx dest_addr;
3956 unsigned rounded_size = PUSH_ROUNDING (GET_MODE_SIZE (mode));
3957 rtx dest;
3958 enum insn_code icode;
3960 stack_pointer_delta += PUSH_ROUNDING (GET_MODE_SIZE (mode));
3961 /* If there is push pattern, use it. Otherwise try old way of throwing
3962 MEM representing push operation to move expander. */
3963 icode = optab_handler (push_optab, mode);
3964 if (icode != CODE_FOR_nothing)
3966 struct expand_operand ops[1];
3968 create_input_operand (&ops[0], x, mode);
3969 if (maybe_expand_insn (icode, 1, ops))
3970 return;
3972 if (GET_MODE_SIZE (mode) == rounded_size)
3973 dest_addr = gen_rtx_fmt_e (STACK_PUSH_CODE, Pmode, stack_pointer_rtx);
3974 /* If we are to pad downward, adjust the stack pointer first and
3975 then store X into the stack location using an offset. This is
3976 because emit_move_insn does not know how to pad; it does not have
3977 access to type. */
3978 else if (FUNCTION_ARG_PADDING (mode, type) == downward)
3980 unsigned padding_size = rounded_size - GET_MODE_SIZE (mode);
3981 HOST_WIDE_INT offset;
3983 emit_move_insn (stack_pointer_rtx,
3984 expand_binop (Pmode,
3985 STACK_GROWS_DOWNWARD ? sub_optab
3986 : add_optab,
3987 stack_pointer_rtx,
3988 gen_int_mode (rounded_size, Pmode),
3989 NULL_RTX, 0, OPTAB_LIB_WIDEN));
3991 offset = (HOST_WIDE_INT) padding_size;
3992 if (STACK_GROWS_DOWNWARD && STACK_PUSH_CODE == POST_DEC)
3993 /* We have already decremented the stack pointer, so get the
3994 previous value. */
3995 offset += (HOST_WIDE_INT) rounded_size;
3997 if (!STACK_GROWS_DOWNWARD && STACK_PUSH_CODE == POST_INC)
3998 /* We have already incremented the stack pointer, so get the
3999 previous value. */
4000 offset -= (HOST_WIDE_INT) rounded_size;
4002 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
4003 gen_int_mode (offset, Pmode));
4005 else
4007 if (STACK_GROWS_DOWNWARD)
4008 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
4009 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
4010 gen_int_mode (-(HOST_WIDE_INT) rounded_size,
4011 Pmode));
4012 else
4013 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
4014 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
4015 gen_int_mode (rounded_size, Pmode));
4017 dest_addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, dest_addr);
4020 dest = gen_rtx_MEM (mode, dest_addr);
4022 if (type != 0)
4024 set_mem_attributes (dest, type, 1);
4026 if (cfun->tail_call_marked)
4027 /* Function incoming arguments may overlap with sibling call
4028 outgoing arguments and we cannot allow reordering of reads
4029 from function arguments with stores to outgoing arguments
4030 of sibling calls. */
4031 set_mem_alias_set (dest, 0);
4033 emit_move_insn (dest, x);
4036 /* Emit and annotate a single push insn. */
4038 static void
4039 emit_single_push_insn (machine_mode mode, rtx x, tree type)
4041 int delta, old_delta = stack_pointer_delta;
4042 rtx_insn *prev = get_last_insn ();
4043 rtx_insn *last;
4045 emit_single_push_insn_1 (mode, x, type);
4047 last = get_last_insn ();
4049 /* Notice the common case where we emitted exactly one insn. */
4050 if (PREV_INSN (last) == prev)
4052 add_reg_note (last, REG_ARGS_SIZE, GEN_INT (stack_pointer_delta));
4053 return;
4056 delta = fixup_args_size_notes (prev, last, stack_pointer_delta);
4057 gcc_assert (delta == INT_MIN || delta == old_delta);
4059 #endif
4061 /* If reading SIZE bytes from X will end up reading from
4062 Y return the number of bytes that overlap. Return -1
4063 if there is no overlap or -2 if we can't determine
4064 (for example when X and Y have different base registers). */
4066 static int
4067 memory_load_overlap (rtx x, rtx y, HOST_WIDE_INT size)
4069 rtx tmp = plus_constant (Pmode, x, size);
4070 rtx sub = simplify_gen_binary (MINUS, Pmode, tmp, y);
4072 if (!CONST_INT_P (sub))
4073 return -2;
4075 HOST_WIDE_INT val = INTVAL (sub);
4077 return IN_RANGE (val, 1, size) ? val : -1;
4080 /* Generate code to push X onto the stack, assuming it has mode MODE and
4081 type TYPE.
4082 MODE is redundant except when X is a CONST_INT (since they don't
4083 carry mode info).
4084 SIZE is an rtx for the size of data to be copied (in bytes),
4085 needed only if X is BLKmode.
4086 Return true if successful. May return false if asked to push a
4087 partial argument during a sibcall optimization (as specified by
4088 SIBCALL_P) and the incoming and outgoing pointers cannot be shown
4089 to not overlap.
4091 ALIGN (in bits) is maximum alignment we can assume.
4093 If PARTIAL and REG are both nonzero, then copy that many of the first
4094 bytes of X into registers starting with REG, and push the rest of X.
4095 The amount of space pushed is decreased by PARTIAL bytes.
4096 REG must be a hard register in this case.
4097 If REG is zero but PARTIAL is not, take any all others actions for an
4098 argument partially in registers, but do not actually load any
4099 registers.
4101 EXTRA is the amount in bytes of extra space to leave next to this arg.
4102 This is ignored if an argument block has already been allocated.
4104 On a machine that lacks real push insns, ARGS_ADDR is the address of
4105 the bottom of the argument block for this call. We use indexing off there
4106 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
4107 argument block has not been preallocated.
4109 ARGS_SO_FAR is the size of args previously pushed for this call.
4111 REG_PARM_STACK_SPACE is nonzero if functions require stack space
4112 for arguments passed in registers. If nonzero, it will be the number
4113 of bytes required. */
4115 bool
4116 emit_push_insn (rtx x, machine_mode mode, tree type, rtx size,
4117 unsigned int align, int partial, rtx reg, int extra,
4118 rtx args_addr, rtx args_so_far, int reg_parm_stack_space,
4119 rtx alignment_pad, bool sibcall_p)
4121 rtx xinner;
4122 enum direction stack_direction = STACK_GROWS_DOWNWARD ? downward : upward;
4124 /* Decide where to pad the argument: `downward' for below,
4125 `upward' for above, or `none' for don't pad it.
4126 Default is below for small data on big-endian machines; else above. */
4127 enum direction where_pad = FUNCTION_ARG_PADDING (mode, type);
4129 /* Invert direction if stack is post-decrement.
4130 FIXME: why? */
4131 if (STACK_PUSH_CODE == POST_DEC)
4132 if (where_pad != none)
4133 where_pad = (where_pad == downward ? upward : downward);
4135 xinner = x;
4137 int nregs = partial / UNITS_PER_WORD;
4138 rtx *tmp_regs = NULL;
4139 int overlapping = 0;
4141 if (mode == BLKmode
4142 || (STRICT_ALIGNMENT && align < GET_MODE_ALIGNMENT (mode)))
4144 /* Copy a block into the stack, entirely or partially. */
4146 rtx temp;
4147 int used;
4148 int offset;
4149 int skip;
4151 offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
4152 used = partial - offset;
4154 if (mode != BLKmode)
4156 /* A value is to be stored in an insufficiently aligned
4157 stack slot; copy via a suitably aligned slot if
4158 necessary. */
4159 size = GEN_INT (GET_MODE_SIZE (mode));
4160 if (!MEM_P (xinner))
4162 temp = assign_temp (type, 1, 1);
4163 emit_move_insn (temp, xinner);
4164 xinner = temp;
4168 gcc_assert (size);
4170 /* USED is now the # of bytes we need not copy to the stack
4171 because registers will take care of them. */
4173 if (partial != 0)
4174 xinner = adjust_address (xinner, BLKmode, used);
4176 /* If the partial register-part of the arg counts in its stack size,
4177 skip the part of stack space corresponding to the registers.
4178 Otherwise, start copying to the beginning of the stack space,
4179 by setting SKIP to 0. */
4180 skip = (reg_parm_stack_space == 0) ? 0 : used;
4182 #ifdef PUSH_ROUNDING
4183 /* Do it with several push insns if that doesn't take lots of insns
4184 and if there is no difficulty with push insns that skip bytes
4185 on the stack for alignment purposes. */
4186 if (args_addr == 0
4187 && PUSH_ARGS
4188 && CONST_INT_P (size)
4189 && skip == 0
4190 && MEM_ALIGN (xinner) >= align
4191 && can_move_by_pieces ((unsigned) INTVAL (size) - used, align)
4192 /* Here we avoid the case of a structure whose weak alignment
4193 forces many pushes of a small amount of data,
4194 and such small pushes do rounding that causes trouble. */
4195 && ((! SLOW_UNALIGNED_ACCESS (word_mode, align))
4196 || align >= BIGGEST_ALIGNMENT
4197 || (PUSH_ROUNDING (align / BITS_PER_UNIT)
4198 == (align / BITS_PER_UNIT)))
4199 && (HOST_WIDE_INT) PUSH_ROUNDING (INTVAL (size)) == INTVAL (size))
4201 /* Push padding now if padding above and stack grows down,
4202 or if padding below and stack grows up.
4203 But if space already allocated, this has already been done. */
4204 if (extra && args_addr == 0
4205 && where_pad != none && where_pad != stack_direction)
4206 anti_adjust_stack (GEN_INT (extra));
4208 move_by_pieces (NULL, xinner, INTVAL (size) - used, align, 0);
4210 else
4211 #endif /* PUSH_ROUNDING */
4213 rtx target;
4215 /* Otherwise make space on the stack and copy the data
4216 to the address of that space. */
4218 /* Deduct words put into registers from the size we must copy. */
4219 if (partial != 0)
4221 if (CONST_INT_P (size))
4222 size = GEN_INT (INTVAL (size) - used);
4223 else
4224 size = expand_binop (GET_MODE (size), sub_optab, size,
4225 gen_int_mode (used, GET_MODE (size)),
4226 NULL_RTX, 0, OPTAB_LIB_WIDEN);
4229 /* Get the address of the stack space.
4230 In this case, we do not deal with EXTRA separately.
4231 A single stack adjust will do. */
4232 if (! args_addr)
4234 temp = push_block (size, extra, where_pad == downward);
4235 extra = 0;
4237 else if (CONST_INT_P (args_so_far))
4238 temp = memory_address (BLKmode,
4239 plus_constant (Pmode, args_addr,
4240 skip + INTVAL (args_so_far)));
4241 else
4242 temp = memory_address (BLKmode,
4243 plus_constant (Pmode,
4244 gen_rtx_PLUS (Pmode,
4245 args_addr,
4246 args_so_far),
4247 skip));
4249 if (!ACCUMULATE_OUTGOING_ARGS)
4251 /* If the source is referenced relative to the stack pointer,
4252 copy it to another register to stabilize it. We do not need
4253 to do this if we know that we won't be changing sp. */
4255 if (reg_mentioned_p (virtual_stack_dynamic_rtx, temp)
4256 || reg_mentioned_p (virtual_outgoing_args_rtx, temp))
4257 temp = copy_to_reg (temp);
4260 target = gen_rtx_MEM (BLKmode, temp);
4262 /* We do *not* set_mem_attributes here, because incoming arguments
4263 may overlap with sibling call outgoing arguments and we cannot
4264 allow reordering of reads from function arguments with stores
4265 to outgoing arguments of sibling calls. We do, however, want
4266 to record the alignment of the stack slot. */
4267 /* ALIGN may well be better aligned than TYPE, e.g. due to
4268 PARM_BOUNDARY. Assume the caller isn't lying. */
4269 set_mem_align (target, align);
4271 /* If part should go in registers and pushing to that part would
4272 overwrite some of the values that need to go into regs, load the
4273 overlapping values into temporary pseudos to be moved into the hard
4274 regs at the end after the stack pushing has completed.
4275 We cannot load them directly into the hard regs here because
4276 they can be clobbered by the block move expansions.
4277 See PR 65358. */
4279 if (partial > 0 && reg != 0 && mode == BLKmode
4280 && GET_CODE (reg) != PARALLEL)
4282 overlapping = memory_load_overlap (XEXP (x, 0), temp, partial);
4283 if (overlapping > 0)
4285 gcc_assert (overlapping % UNITS_PER_WORD == 0);
4286 overlapping /= UNITS_PER_WORD;
4288 tmp_regs = XALLOCAVEC (rtx, overlapping);
4290 for (int i = 0; i < overlapping; i++)
4291 tmp_regs[i] = gen_reg_rtx (word_mode);
4293 for (int i = 0; i < overlapping; i++)
4294 emit_move_insn (tmp_regs[i],
4295 operand_subword_force (target, i, mode));
4297 else if (overlapping == -1)
4298 overlapping = 0;
4299 /* Could not determine whether there is overlap.
4300 Fail the sibcall. */
4301 else
4303 overlapping = 0;
4304 if (sibcall_p)
4305 return false;
4308 emit_block_move (target, xinner, size, BLOCK_OP_CALL_PARM);
4311 else if (partial > 0)
4313 /* Scalar partly in registers. */
4315 int size = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
4316 int i;
4317 int not_stack;
4318 /* # bytes of start of argument
4319 that we must make space for but need not store. */
4320 int offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
4321 int args_offset = INTVAL (args_so_far);
4322 int skip;
4324 /* Push padding now if padding above and stack grows down,
4325 or if padding below and stack grows up.
4326 But if space already allocated, this has already been done. */
4327 if (extra && args_addr == 0
4328 && where_pad != none && where_pad != stack_direction)
4329 anti_adjust_stack (GEN_INT (extra));
4331 /* If we make space by pushing it, we might as well push
4332 the real data. Otherwise, we can leave OFFSET nonzero
4333 and leave the space uninitialized. */
4334 if (args_addr == 0)
4335 offset = 0;
4337 /* Now NOT_STACK gets the number of words that we don't need to
4338 allocate on the stack. Convert OFFSET to words too. */
4339 not_stack = (partial - offset) / UNITS_PER_WORD;
4340 offset /= UNITS_PER_WORD;
4342 /* If the partial register-part of the arg counts in its stack size,
4343 skip the part of stack space corresponding to the registers.
4344 Otherwise, start copying to the beginning of the stack space,
4345 by setting SKIP to 0. */
4346 skip = (reg_parm_stack_space == 0) ? 0 : not_stack;
4348 if (CONSTANT_P (x) && !targetm.legitimate_constant_p (mode, x))
4349 x = validize_mem (force_const_mem (mode, x));
4351 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
4352 SUBREGs of such registers are not allowed. */
4353 if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER
4354 && GET_MODE_CLASS (GET_MODE (x)) != MODE_INT))
4355 x = copy_to_reg (x);
4357 /* Loop over all the words allocated on the stack for this arg. */
4358 /* We can do it by words, because any scalar bigger than a word
4359 has a size a multiple of a word. */
4360 for (i = size - 1; i >= not_stack; i--)
4361 if (i >= not_stack + offset)
4362 if (!emit_push_insn (operand_subword_force (x, i, mode),
4363 word_mode, NULL_TREE, NULL_RTX, align, 0, NULL_RTX,
4364 0, args_addr,
4365 GEN_INT (args_offset + ((i - not_stack + skip)
4366 * UNITS_PER_WORD)),
4367 reg_parm_stack_space, alignment_pad, sibcall_p))
4368 return false;
4370 else
4372 rtx addr;
4373 rtx dest;
4375 /* Push padding now if padding above and stack grows down,
4376 or if padding below and stack grows up.
4377 But if space already allocated, this has already been done. */
4378 if (extra && args_addr == 0
4379 && where_pad != none && where_pad != stack_direction)
4380 anti_adjust_stack (GEN_INT (extra));
4382 #ifdef PUSH_ROUNDING
4383 if (args_addr == 0 && PUSH_ARGS)
4384 emit_single_push_insn (mode, x, type);
4385 else
4386 #endif
4388 if (CONST_INT_P (args_so_far))
4389 addr
4390 = memory_address (mode,
4391 plus_constant (Pmode, args_addr,
4392 INTVAL (args_so_far)));
4393 else
4394 addr = memory_address (mode, gen_rtx_PLUS (Pmode, args_addr,
4395 args_so_far));
4396 dest = gen_rtx_MEM (mode, addr);
4398 /* We do *not* set_mem_attributes here, because incoming arguments
4399 may overlap with sibling call outgoing arguments and we cannot
4400 allow reordering of reads from function arguments with stores
4401 to outgoing arguments of sibling calls. We do, however, want
4402 to record the alignment of the stack slot. */
4403 /* ALIGN may well be better aligned than TYPE, e.g. due to
4404 PARM_BOUNDARY. Assume the caller isn't lying. */
4405 set_mem_align (dest, align);
4407 emit_move_insn (dest, x);
4411 /* Move the partial arguments into the registers and any overlapping
4412 values that we moved into the pseudos in tmp_regs. */
4413 if (partial > 0 && reg != 0)
4415 /* Handle calls that pass values in multiple non-contiguous locations.
4416 The Irix 6 ABI has examples of this. */
4417 if (GET_CODE (reg) == PARALLEL)
4418 emit_group_load (reg, x, type, -1);
4419 else
4421 gcc_assert (partial % UNITS_PER_WORD == 0);
4422 move_block_to_reg (REGNO (reg), x, nregs - overlapping, mode);
4424 for (int i = 0; i < overlapping; i++)
4425 emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg)
4426 + nregs - overlapping + i),
4427 tmp_regs[i]);
4432 if (extra && args_addr == 0 && where_pad == stack_direction)
4433 anti_adjust_stack (GEN_INT (extra));
4435 if (alignment_pad && args_addr == 0)
4436 anti_adjust_stack (alignment_pad);
4438 return true;
4441 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4442 operations. */
4444 static rtx
4445 get_subtarget (rtx x)
4447 return (optimize
4448 || x == 0
4449 /* Only registers can be subtargets. */
4450 || !REG_P (x)
4451 /* Don't use hard regs to avoid extending their life. */
4452 || REGNO (x) < FIRST_PSEUDO_REGISTER
4453 ? 0 : x);
4456 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
4457 FIELD is a bitfield. Returns true if the optimization was successful,
4458 and there's nothing else to do. */
4460 static bool
4461 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize,
4462 unsigned HOST_WIDE_INT bitpos,
4463 unsigned HOST_WIDE_INT bitregion_start,
4464 unsigned HOST_WIDE_INT bitregion_end,
4465 machine_mode mode1, rtx str_rtx,
4466 tree to, tree src, bool reverse)
4468 machine_mode str_mode = GET_MODE (str_rtx);
4469 unsigned int str_bitsize = GET_MODE_BITSIZE (str_mode);
4470 tree op0, op1;
4471 rtx value, result;
4472 optab binop;
4473 gimple *srcstmt;
4474 enum tree_code code;
4476 if (mode1 != VOIDmode
4477 || bitsize >= BITS_PER_WORD
4478 || str_bitsize > BITS_PER_WORD
4479 || TREE_SIDE_EFFECTS (to)
4480 || TREE_THIS_VOLATILE (to))
4481 return false;
4483 STRIP_NOPS (src);
4484 if (TREE_CODE (src) != SSA_NAME)
4485 return false;
4486 if (TREE_CODE (TREE_TYPE (src)) != INTEGER_TYPE)
4487 return false;
4489 srcstmt = get_gimple_for_ssa_name (src);
4490 if (!srcstmt
4491 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt)) != tcc_binary)
4492 return false;
4494 code = gimple_assign_rhs_code (srcstmt);
4496 op0 = gimple_assign_rhs1 (srcstmt);
4498 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
4499 to find its initialization. Hopefully the initialization will
4500 be from a bitfield load. */
4501 if (TREE_CODE (op0) == SSA_NAME)
4503 gimple *op0stmt = get_gimple_for_ssa_name (op0);
4505 /* We want to eventually have OP0 be the same as TO, which
4506 should be a bitfield. */
4507 if (!op0stmt
4508 || !is_gimple_assign (op0stmt)
4509 || gimple_assign_rhs_code (op0stmt) != TREE_CODE (to))
4510 return false;
4511 op0 = gimple_assign_rhs1 (op0stmt);
4514 op1 = gimple_assign_rhs2 (srcstmt);
4516 if (!operand_equal_p (to, op0, 0))
4517 return false;
4519 if (MEM_P (str_rtx))
4521 unsigned HOST_WIDE_INT offset1;
4523 if (str_bitsize == 0 || str_bitsize > BITS_PER_WORD)
4524 str_mode = word_mode;
4525 str_mode = get_best_mode (bitsize, bitpos,
4526 bitregion_start, bitregion_end,
4527 MEM_ALIGN (str_rtx), str_mode, 0);
4528 if (str_mode == VOIDmode)
4529 return false;
4530 str_bitsize = GET_MODE_BITSIZE (str_mode);
4532 offset1 = bitpos;
4533 bitpos %= str_bitsize;
4534 offset1 = (offset1 - bitpos) / BITS_PER_UNIT;
4535 str_rtx = adjust_address (str_rtx, str_mode, offset1);
4537 else if (!REG_P (str_rtx) && GET_CODE (str_rtx) != SUBREG)
4538 return false;
4539 else
4540 gcc_assert (!reverse);
4542 /* If the bit field covers the whole REG/MEM, store_field
4543 will likely generate better code. */
4544 if (bitsize >= str_bitsize)
4545 return false;
4547 /* We can't handle fields split across multiple entities. */
4548 if (bitpos + bitsize > str_bitsize)
4549 return false;
4551 if (reverse ? !BYTES_BIG_ENDIAN : BYTES_BIG_ENDIAN)
4552 bitpos = str_bitsize - bitpos - bitsize;
4554 switch (code)
4556 case PLUS_EXPR:
4557 case MINUS_EXPR:
4558 /* For now, just optimize the case of the topmost bitfield
4559 where we don't need to do any masking and also
4560 1 bit bitfields where xor can be used.
4561 We might win by one instruction for the other bitfields
4562 too if insv/extv instructions aren't used, so that
4563 can be added later. */
4564 if ((reverse || bitpos + bitsize != str_bitsize)
4565 && (bitsize != 1 || TREE_CODE (op1) != INTEGER_CST))
4566 break;
4568 value = expand_expr (op1, NULL_RTX, str_mode, EXPAND_NORMAL);
4569 value = convert_modes (str_mode,
4570 TYPE_MODE (TREE_TYPE (op1)), value,
4571 TYPE_UNSIGNED (TREE_TYPE (op1)));
4573 /* We may be accessing data outside the field, which means
4574 we can alias adjacent data. */
4575 if (MEM_P (str_rtx))
4577 str_rtx = shallow_copy_rtx (str_rtx);
4578 set_mem_alias_set (str_rtx, 0);
4579 set_mem_expr (str_rtx, 0);
4582 if (bitsize == 1 && (reverse || bitpos + bitsize != str_bitsize))
4584 value = expand_and (str_mode, value, const1_rtx, NULL);
4585 binop = xor_optab;
4587 else
4588 binop = code == PLUS_EXPR ? add_optab : sub_optab;
4590 value = expand_shift (LSHIFT_EXPR, str_mode, value, bitpos, NULL_RTX, 1);
4591 if (reverse)
4592 value = flip_storage_order (str_mode, value);
4593 result = expand_binop (str_mode, binop, str_rtx,
4594 value, str_rtx, 1, OPTAB_WIDEN);
4595 if (result != str_rtx)
4596 emit_move_insn (str_rtx, result);
4597 return true;
4599 case BIT_IOR_EXPR:
4600 case BIT_XOR_EXPR:
4601 if (TREE_CODE (op1) != INTEGER_CST)
4602 break;
4603 value = expand_expr (op1, NULL_RTX, str_mode, EXPAND_NORMAL);
4604 value = convert_modes (str_mode,
4605 TYPE_MODE (TREE_TYPE (op1)), value,
4606 TYPE_UNSIGNED (TREE_TYPE (op1)));
4608 /* We may be accessing data outside the field, which means
4609 we can alias adjacent data. */
4610 if (MEM_P (str_rtx))
4612 str_rtx = shallow_copy_rtx (str_rtx);
4613 set_mem_alias_set (str_rtx, 0);
4614 set_mem_expr (str_rtx, 0);
4617 binop = code == BIT_IOR_EXPR ? ior_optab : xor_optab;
4618 if (bitpos + bitsize != str_bitsize)
4620 rtx mask = gen_int_mode (((unsigned HOST_WIDE_INT) 1 << bitsize) - 1,
4621 str_mode);
4622 value = expand_and (str_mode, value, mask, NULL_RTX);
4624 value = expand_shift (LSHIFT_EXPR, str_mode, value, bitpos, NULL_RTX, 1);
4625 if (reverse)
4626 value = flip_storage_order (str_mode, value);
4627 result = expand_binop (str_mode, binop, str_rtx,
4628 value, str_rtx, 1, OPTAB_WIDEN);
4629 if (result != str_rtx)
4630 emit_move_insn (str_rtx, result);
4631 return true;
4633 default:
4634 break;
4637 return false;
4640 /* In the C++ memory model, consecutive bit fields in a structure are
4641 considered one memory location.
4643 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
4644 returns the bit range of consecutive bits in which this COMPONENT_REF
4645 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
4646 and *OFFSET may be adjusted in the process.
4648 If the access does not need to be restricted, 0 is returned in both
4649 *BITSTART and *BITEND. */
4651 static void
4652 get_bit_range (unsigned HOST_WIDE_INT *bitstart,
4653 unsigned HOST_WIDE_INT *bitend,
4654 tree exp,
4655 HOST_WIDE_INT *bitpos,
4656 tree *offset)
4658 HOST_WIDE_INT bitoffset;
4659 tree field, repr;
4661 gcc_assert (TREE_CODE (exp) == COMPONENT_REF);
4663 field = TREE_OPERAND (exp, 1);
4664 repr = DECL_BIT_FIELD_REPRESENTATIVE (field);
4665 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
4666 need to limit the range we can access. */
4667 if (!repr)
4669 *bitstart = *bitend = 0;
4670 return;
4673 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
4674 part of a larger bit field, then the representative does not serve any
4675 useful purpose. This can occur in Ada. */
4676 if (handled_component_p (TREE_OPERAND (exp, 0)))
4678 machine_mode rmode;
4679 HOST_WIDE_INT rbitsize, rbitpos;
4680 tree roffset;
4681 int unsignedp, reversep, volatilep = 0;
4682 get_inner_reference (TREE_OPERAND (exp, 0), &rbitsize, &rbitpos,
4683 &roffset, &rmode, &unsignedp, &reversep,
4684 &volatilep, false);
4685 if ((rbitpos % BITS_PER_UNIT) != 0)
4687 *bitstart = *bitend = 0;
4688 return;
4692 /* Compute the adjustment to bitpos from the offset of the field
4693 relative to the representative. DECL_FIELD_OFFSET of field and
4694 repr are the same by construction if they are not constants,
4695 see finish_bitfield_layout. */
4696 if (tree_fits_uhwi_p (DECL_FIELD_OFFSET (field))
4697 && tree_fits_uhwi_p (DECL_FIELD_OFFSET (repr)))
4698 bitoffset = (tree_to_uhwi (DECL_FIELD_OFFSET (field))
4699 - tree_to_uhwi (DECL_FIELD_OFFSET (repr))) * BITS_PER_UNIT;
4700 else
4701 bitoffset = 0;
4702 bitoffset += (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field))
4703 - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr)));
4705 /* If the adjustment is larger than bitpos, we would have a negative bit
4706 position for the lower bound and this may wreak havoc later. Adjust
4707 offset and bitpos to make the lower bound non-negative in that case. */
4708 if (bitoffset > *bitpos)
4710 HOST_WIDE_INT adjust = bitoffset - *bitpos;
4711 gcc_assert ((adjust % BITS_PER_UNIT) == 0);
4713 *bitpos += adjust;
4714 if (*offset == NULL_TREE)
4715 *offset = size_int (-adjust / BITS_PER_UNIT);
4716 else
4717 *offset
4718 = size_binop (MINUS_EXPR, *offset, size_int (adjust / BITS_PER_UNIT));
4719 *bitstart = 0;
4721 else
4722 *bitstart = *bitpos - bitoffset;
4724 *bitend = *bitstart + tree_to_uhwi (DECL_SIZE (repr)) - 1;
4727 /* Returns true if ADDR is an ADDR_EXPR of a DECL that does not reside
4728 in memory and has non-BLKmode. DECL_RTL must not be a MEM; if
4729 DECL_RTL was not set yet, return NORTL. */
4731 static inline bool
4732 addr_expr_of_non_mem_decl_p_1 (tree addr, bool nortl)
4734 if (TREE_CODE (addr) != ADDR_EXPR)
4735 return false;
4737 tree base = TREE_OPERAND (addr, 0);
4739 if (!DECL_P (base)
4740 || TREE_ADDRESSABLE (base)
4741 || DECL_MODE (base) == BLKmode)
4742 return false;
4744 if (!DECL_RTL_SET_P (base))
4745 return nortl;
4747 return (!MEM_P (DECL_RTL (base)));
4750 /* Returns true if the MEM_REF REF refers to an object that does not
4751 reside in memory and has non-BLKmode. */
4753 static inline bool
4754 mem_ref_refers_to_non_mem_p (tree ref)
4756 tree base = TREE_OPERAND (ref, 0);
4757 return addr_expr_of_non_mem_decl_p_1 (base, false);
4760 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
4761 is true, try generating a nontemporal store. */
4763 void
4764 expand_assignment (tree to, tree from, bool nontemporal)
4766 rtx to_rtx = 0;
4767 rtx result;
4768 machine_mode mode;
4769 unsigned int align;
4770 enum insn_code icode;
4772 /* Don't crash if the lhs of the assignment was erroneous. */
4773 if (TREE_CODE (to) == ERROR_MARK)
4775 expand_normal (from);
4776 return;
4779 /* Optimize away no-op moves without side-effects. */
4780 if (operand_equal_p (to, from, 0))
4781 return;
4783 /* Handle misaligned stores. */
4784 mode = TYPE_MODE (TREE_TYPE (to));
4785 if ((TREE_CODE (to) == MEM_REF
4786 || TREE_CODE (to) == TARGET_MEM_REF)
4787 && mode != BLKmode
4788 && !mem_ref_refers_to_non_mem_p (to)
4789 && ((align = get_object_alignment (to))
4790 < GET_MODE_ALIGNMENT (mode))
4791 && (((icode = optab_handler (movmisalign_optab, mode))
4792 != CODE_FOR_nothing)
4793 || SLOW_UNALIGNED_ACCESS (mode, align)))
4795 rtx reg, mem;
4797 reg = expand_expr (from, NULL_RTX, VOIDmode, EXPAND_NORMAL);
4798 reg = force_not_mem (reg);
4799 mem = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
4800 if (TREE_CODE (to) == MEM_REF && REF_REVERSE_STORAGE_ORDER (to))
4801 reg = flip_storage_order (mode, reg);
4803 if (icode != CODE_FOR_nothing)
4805 struct expand_operand ops[2];
4807 create_fixed_operand (&ops[0], mem);
4808 create_input_operand (&ops[1], reg, mode);
4809 /* The movmisalign<mode> pattern cannot fail, else the assignment
4810 would silently be omitted. */
4811 expand_insn (icode, 2, ops);
4813 else
4814 store_bit_field (mem, GET_MODE_BITSIZE (mode), 0, 0, 0, mode, reg,
4815 false);
4816 return;
4819 /* Assignment of a structure component needs special treatment
4820 if the structure component's rtx is not simply a MEM.
4821 Assignment of an array element at a constant index, and assignment of
4822 an array element in an unaligned packed structure field, has the same
4823 problem. Same for (partially) storing into a non-memory object. */
4824 if (handled_component_p (to)
4825 || (TREE_CODE (to) == MEM_REF
4826 && (REF_REVERSE_STORAGE_ORDER (to)
4827 || mem_ref_refers_to_non_mem_p (to)))
4828 || TREE_CODE (TREE_TYPE (to)) == ARRAY_TYPE)
4830 machine_mode mode1;
4831 HOST_WIDE_INT bitsize, bitpos;
4832 unsigned HOST_WIDE_INT bitregion_start = 0;
4833 unsigned HOST_WIDE_INT bitregion_end = 0;
4834 tree offset;
4835 int unsignedp, reversep, volatilep = 0;
4836 tree tem;
4838 push_temp_slots ();
4839 tem = get_inner_reference (to, &bitsize, &bitpos, &offset, &mode1,
4840 &unsignedp, &reversep, &volatilep, true);
4842 /* Make sure bitpos is not negative, it can wreak havoc later. */
4843 if (bitpos < 0)
4845 gcc_assert (offset == NULL_TREE);
4846 offset = size_int (bitpos >> (BITS_PER_UNIT == 8
4847 ? 3 : exact_log2 (BITS_PER_UNIT)));
4848 bitpos &= BITS_PER_UNIT - 1;
4851 if (TREE_CODE (to) == COMPONENT_REF
4852 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to, 1)))
4853 get_bit_range (&bitregion_start, &bitregion_end, to, &bitpos, &offset);
4854 /* The C++ memory model naturally applies to byte-aligned fields.
4855 However, if we do not have a DECL_BIT_FIELD_TYPE but BITPOS or
4856 BITSIZE are not byte-aligned, there is no need to limit the range
4857 we can access. This can occur with packed structures in Ada. */
4858 else if (bitsize > 0
4859 && bitsize % BITS_PER_UNIT == 0
4860 && bitpos % BITS_PER_UNIT == 0)
4862 bitregion_start = bitpos;
4863 bitregion_end = bitpos + bitsize - 1;
4866 to_rtx = expand_expr (tem, NULL_RTX, VOIDmode, EXPAND_WRITE);
4868 /* If the field has a mode, we want to access it in the
4869 field's mode, not the computed mode.
4870 If a MEM has VOIDmode (external with incomplete type),
4871 use BLKmode for it instead. */
4872 if (MEM_P (to_rtx))
4874 if (mode1 != VOIDmode)
4875 to_rtx = adjust_address (to_rtx, mode1, 0);
4876 else if (GET_MODE (to_rtx) == VOIDmode)
4877 to_rtx = adjust_address (to_rtx, BLKmode, 0);
4880 if (offset != 0)
4882 machine_mode address_mode;
4883 rtx offset_rtx;
4885 if (!MEM_P (to_rtx))
4887 /* We can get constant negative offsets into arrays with broken
4888 user code. Translate this to a trap instead of ICEing. */
4889 gcc_assert (TREE_CODE (offset) == INTEGER_CST);
4890 expand_builtin_trap ();
4891 to_rtx = gen_rtx_MEM (BLKmode, const0_rtx);
4894 offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, EXPAND_SUM);
4895 address_mode = get_address_mode (to_rtx);
4896 if (GET_MODE (offset_rtx) != address_mode)
4898 /* We cannot be sure that the RTL in offset_rtx is valid outside
4899 of a memory address context, so force it into a register
4900 before attempting to convert it to the desired mode. */
4901 offset_rtx = force_operand (offset_rtx, NULL_RTX);
4902 offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
4905 /* If we have an expression in OFFSET_RTX and a non-zero
4906 byte offset in BITPOS, adding the byte offset before the
4907 OFFSET_RTX results in better intermediate code, which makes
4908 later rtl optimization passes perform better.
4910 We prefer intermediate code like this:
4912 r124:DI=r123:DI+0x18
4913 [r124:DI]=r121:DI
4915 ... instead of ...
4917 r124:DI=r123:DI+0x10
4918 [r124:DI+0x8]=r121:DI
4920 This is only done for aligned data values, as these can
4921 be expected to result in single move instructions. */
4922 if (mode1 != VOIDmode
4923 && bitpos != 0
4924 && bitsize > 0
4925 && (bitpos % bitsize) == 0
4926 && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
4927 && MEM_ALIGN (to_rtx) >= GET_MODE_ALIGNMENT (mode1))
4929 to_rtx = adjust_address (to_rtx, mode1, bitpos / BITS_PER_UNIT);
4930 bitregion_start = 0;
4931 if (bitregion_end >= (unsigned HOST_WIDE_INT) bitpos)
4932 bitregion_end -= bitpos;
4933 bitpos = 0;
4936 to_rtx = offset_address (to_rtx, offset_rtx,
4937 highest_pow2_factor_for_target (to,
4938 offset));
4941 /* No action is needed if the target is not a memory and the field
4942 lies completely outside that target. This can occur if the source
4943 code contains an out-of-bounds access to a small array. */
4944 if (!MEM_P (to_rtx)
4945 && GET_MODE (to_rtx) != BLKmode
4946 && (unsigned HOST_WIDE_INT) bitpos
4947 >= GET_MODE_PRECISION (GET_MODE (to_rtx)))
4949 expand_normal (from);
4950 result = NULL;
4952 /* Handle expand_expr of a complex value returning a CONCAT. */
4953 else if (GET_CODE (to_rtx) == CONCAT)
4955 unsigned short mode_bitsize = GET_MODE_BITSIZE (GET_MODE (to_rtx));
4956 if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from)))
4957 && bitpos == 0
4958 && bitsize == mode_bitsize)
4959 result = store_expr (from, to_rtx, false, nontemporal, reversep);
4960 else if (bitsize == mode_bitsize / 2
4961 && (bitpos == 0 || bitpos == mode_bitsize / 2))
4962 result = store_expr (from, XEXP (to_rtx, bitpos != 0), false,
4963 nontemporal, reversep);
4964 else if (bitpos + bitsize <= mode_bitsize / 2)
4965 result = store_field (XEXP (to_rtx, 0), bitsize, bitpos,
4966 bitregion_start, bitregion_end,
4967 mode1, from, get_alias_set (to),
4968 nontemporal, reversep);
4969 else if (bitpos >= mode_bitsize / 2)
4970 result = store_field (XEXP (to_rtx, 1), bitsize,
4971 bitpos - mode_bitsize / 2,
4972 bitregion_start, bitregion_end,
4973 mode1, from, get_alias_set (to),
4974 nontemporal, reversep);
4975 else if (bitpos == 0 && bitsize == mode_bitsize)
4977 rtx from_rtx;
4978 result = expand_normal (from);
4979 from_rtx = simplify_gen_subreg (GET_MODE (to_rtx), result,
4980 TYPE_MODE (TREE_TYPE (from)), 0);
4981 emit_move_insn (XEXP (to_rtx, 0),
4982 read_complex_part (from_rtx, false));
4983 emit_move_insn (XEXP (to_rtx, 1),
4984 read_complex_part (from_rtx, true));
4986 else
4988 rtx temp = assign_stack_temp (GET_MODE (to_rtx),
4989 GET_MODE_SIZE (GET_MODE (to_rtx)));
4990 write_complex_part (temp, XEXP (to_rtx, 0), false);
4991 write_complex_part (temp, XEXP (to_rtx, 1), true);
4992 result = store_field (temp, bitsize, bitpos,
4993 bitregion_start, bitregion_end,
4994 mode1, from, get_alias_set (to),
4995 nontemporal, reversep);
4996 emit_move_insn (XEXP (to_rtx, 0), read_complex_part (temp, false));
4997 emit_move_insn (XEXP (to_rtx, 1), read_complex_part (temp, true));
5000 else
5002 if (MEM_P (to_rtx))
5004 /* If the field is at offset zero, we could have been given the
5005 DECL_RTX of the parent struct. Don't munge it. */
5006 to_rtx = shallow_copy_rtx (to_rtx);
5007 set_mem_attributes_minus_bitpos (to_rtx, to, 0, bitpos);
5008 if (volatilep)
5009 MEM_VOLATILE_P (to_rtx) = 1;
5012 if (optimize_bitfield_assignment_op (bitsize, bitpos,
5013 bitregion_start, bitregion_end,
5014 mode1, to_rtx, to, from,
5015 reversep))
5016 result = NULL;
5017 else
5018 result = store_field (to_rtx, bitsize, bitpos,
5019 bitregion_start, bitregion_end,
5020 mode1, from, get_alias_set (to),
5021 nontemporal, reversep);
5024 if (result)
5025 preserve_temp_slots (result);
5026 pop_temp_slots ();
5027 return;
5030 /* If the rhs is a function call and its value is not an aggregate,
5031 call the function before we start to compute the lhs.
5032 This is needed for correct code for cases such as
5033 val = setjmp (buf) on machines where reference to val
5034 requires loading up part of an address in a separate insn.
5036 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
5037 since it might be a promoted variable where the zero- or sign- extension
5038 needs to be done. Handling this in the normal way is safe because no
5039 computation is done before the call. The same is true for SSA names. */
5040 if (TREE_CODE (from) == CALL_EXPR && ! aggregate_value_p (from, from)
5041 && COMPLETE_TYPE_P (TREE_TYPE (from))
5042 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from))) == INTEGER_CST
5043 && ! (((TREE_CODE (to) == VAR_DECL
5044 || TREE_CODE (to) == PARM_DECL
5045 || TREE_CODE (to) == RESULT_DECL)
5046 && REG_P (DECL_RTL (to)))
5047 || TREE_CODE (to) == SSA_NAME))
5049 rtx value;
5050 rtx bounds;
5052 push_temp_slots ();
5053 value = expand_normal (from);
5055 /* Split value and bounds to store them separately. */
5056 chkp_split_slot (value, &value, &bounds);
5058 if (to_rtx == 0)
5059 to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
5061 /* Handle calls that return values in multiple non-contiguous locations.
5062 The Irix 6 ABI has examples of this. */
5063 if (GET_CODE (to_rtx) == PARALLEL)
5065 if (GET_CODE (value) == PARALLEL)
5066 emit_group_move (to_rtx, value);
5067 else
5068 emit_group_load (to_rtx, value, TREE_TYPE (from),
5069 int_size_in_bytes (TREE_TYPE (from)));
5071 else if (GET_CODE (value) == PARALLEL)
5072 emit_group_store (to_rtx, value, TREE_TYPE (from),
5073 int_size_in_bytes (TREE_TYPE (from)));
5074 else if (GET_MODE (to_rtx) == BLKmode)
5076 /* Handle calls that return BLKmode values in registers. */
5077 if (REG_P (value))
5078 copy_blkmode_from_reg (to_rtx, value, TREE_TYPE (from));
5079 else
5080 emit_block_move (to_rtx, value, expr_size (from), BLOCK_OP_NORMAL);
5082 else
5084 if (POINTER_TYPE_P (TREE_TYPE (to)))
5085 value = convert_memory_address_addr_space
5086 (GET_MODE (to_rtx), value,
5087 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to))));
5089 emit_move_insn (to_rtx, value);
5092 /* Store bounds if required. */
5093 if (bounds
5094 && (BOUNDED_P (to) || chkp_type_has_pointer (TREE_TYPE (to))))
5096 gcc_assert (MEM_P (to_rtx));
5097 chkp_emit_bounds_store (bounds, value, to_rtx);
5100 preserve_temp_slots (to_rtx);
5101 pop_temp_slots ();
5102 return;
5105 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
5106 to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
5108 /* Don't move directly into a return register. */
5109 if (TREE_CODE (to) == RESULT_DECL
5110 && (REG_P (to_rtx) || GET_CODE (to_rtx) == PARALLEL))
5112 rtx temp;
5114 push_temp_slots ();
5116 /* If the source is itself a return value, it still is in a pseudo at
5117 this point so we can move it back to the return register directly. */
5118 if (REG_P (to_rtx)
5119 && TYPE_MODE (TREE_TYPE (from)) == BLKmode
5120 && TREE_CODE (from) != CALL_EXPR)
5121 temp = copy_blkmode_to_reg (GET_MODE (to_rtx), from);
5122 else
5123 temp = expand_expr (from, NULL_RTX, GET_MODE (to_rtx), EXPAND_NORMAL);
5125 /* Handle calls that return values in multiple non-contiguous locations.
5126 The Irix 6 ABI has examples of this. */
5127 if (GET_CODE (to_rtx) == PARALLEL)
5129 if (GET_CODE (temp) == PARALLEL)
5130 emit_group_move (to_rtx, temp);
5131 else
5132 emit_group_load (to_rtx, temp, TREE_TYPE (from),
5133 int_size_in_bytes (TREE_TYPE (from)));
5135 else if (temp)
5136 emit_move_insn (to_rtx, temp);
5138 preserve_temp_slots (to_rtx);
5139 pop_temp_slots ();
5140 return;
5143 /* In case we are returning the contents of an object which overlaps
5144 the place the value is being stored, use a safe function when copying
5145 a value through a pointer into a structure value return block. */
5146 if (TREE_CODE (to) == RESULT_DECL
5147 && TREE_CODE (from) == INDIRECT_REF
5148 && ADDR_SPACE_GENERIC_P
5149 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from, 0)))))
5150 && refs_may_alias_p (to, from)
5151 && cfun->returns_struct
5152 && !cfun->returns_pcc_struct)
5154 rtx from_rtx, size;
5156 push_temp_slots ();
5157 size = expr_size (from);
5158 from_rtx = expand_normal (from);
5160 emit_library_call (memmove_libfunc, LCT_NORMAL,
5161 VOIDmode, 3, XEXP (to_rtx, 0), Pmode,
5162 XEXP (from_rtx, 0), Pmode,
5163 convert_to_mode (TYPE_MODE (sizetype),
5164 size, TYPE_UNSIGNED (sizetype)),
5165 TYPE_MODE (sizetype));
5167 preserve_temp_slots (to_rtx);
5168 pop_temp_slots ();
5169 return;
5172 /* Compute FROM and store the value in the rtx we got. */
5174 push_temp_slots ();
5175 result = store_expr_with_bounds (from, to_rtx, 0, nontemporal, false, to);
5176 preserve_temp_slots (result);
5177 pop_temp_slots ();
5178 return;
5181 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
5182 succeeded, false otherwise. */
5184 bool
5185 emit_storent_insn (rtx to, rtx from)
5187 struct expand_operand ops[2];
5188 machine_mode mode = GET_MODE (to);
5189 enum insn_code code = optab_handler (storent_optab, mode);
5191 if (code == CODE_FOR_nothing)
5192 return false;
5194 create_fixed_operand (&ops[0], to);
5195 create_input_operand (&ops[1], from, mode);
5196 return maybe_expand_insn (code, 2, ops);
5199 /* Generate code for computing expression EXP,
5200 and storing the value into TARGET.
5202 If the mode is BLKmode then we may return TARGET itself.
5203 It turns out that in BLKmode it doesn't cause a problem.
5204 because C has no operators that could combine two different
5205 assignments into the same BLKmode object with different values
5206 with no sequence point. Will other languages need this to
5207 be more thorough?
5209 If CALL_PARAM_P is nonzero, this is a store into a call param on the
5210 stack, and block moves may need to be treated specially.
5212 If NONTEMPORAL is true, try using a nontemporal store instruction.
5214 If REVERSE is true, the store is to be done in reverse order.
5216 If BTARGET is not NULL then computed bounds of EXP are
5217 associated with BTARGET. */
5220 store_expr_with_bounds (tree exp, rtx target, int call_param_p,
5221 bool nontemporal, bool reverse, tree btarget)
5223 rtx temp;
5224 rtx alt_rtl = NULL_RTX;
5225 location_t loc = curr_insn_location ();
5227 if (VOID_TYPE_P (TREE_TYPE (exp)))
5229 /* C++ can generate ?: expressions with a throw expression in one
5230 branch and an rvalue in the other. Here, we resolve attempts to
5231 store the throw expression's nonexistent result. */
5232 gcc_assert (!call_param_p);
5233 expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL);
5234 return NULL_RTX;
5236 if (TREE_CODE (exp) == COMPOUND_EXPR)
5238 /* Perform first part of compound expression, then assign from second
5239 part. */
5240 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
5241 call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
5242 return store_expr_with_bounds (TREE_OPERAND (exp, 1), target,
5243 call_param_p, nontemporal, reverse,
5244 btarget);
5246 else if (TREE_CODE (exp) == COND_EXPR && GET_MODE (target) == BLKmode)
5248 /* For conditional expression, get safe form of the target. Then
5249 test the condition, doing the appropriate assignment on either
5250 side. This avoids the creation of unnecessary temporaries.
5251 For non-BLKmode, it is more efficient not to do this. */
5253 rtx_code_label *lab1 = gen_label_rtx (), *lab2 = gen_label_rtx ();
5255 do_pending_stack_adjust ();
5256 NO_DEFER_POP;
5257 jumpifnot (TREE_OPERAND (exp, 0), lab1, -1);
5258 store_expr_with_bounds (TREE_OPERAND (exp, 1), target, call_param_p,
5259 nontemporal, reverse, btarget);
5260 emit_jump_insn (targetm.gen_jump (lab2));
5261 emit_barrier ();
5262 emit_label (lab1);
5263 store_expr_with_bounds (TREE_OPERAND (exp, 2), target, call_param_p,
5264 nontemporal, reverse, btarget);
5265 emit_label (lab2);
5266 OK_DEFER_POP;
5268 return NULL_RTX;
5270 else if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target))
5271 /* If this is a scalar in a register that is stored in a wider mode
5272 than the declared mode, compute the result into its declared mode
5273 and then convert to the wider mode. Our value is the computed
5274 expression. */
5276 rtx inner_target = 0;
5278 /* We can do the conversion inside EXP, which will often result
5279 in some optimizations. Do the conversion in two steps: first
5280 change the signedness, if needed, then the extend. But don't
5281 do this if the type of EXP is a subtype of something else
5282 since then the conversion might involve more than just
5283 converting modes. */
5284 if (INTEGRAL_TYPE_P (TREE_TYPE (exp))
5285 && TREE_TYPE (TREE_TYPE (exp)) == 0
5286 && GET_MODE_PRECISION (GET_MODE (target))
5287 == TYPE_PRECISION (TREE_TYPE (exp)))
5289 if (!SUBREG_CHECK_PROMOTED_SIGN (target,
5290 TYPE_UNSIGNED (TREE_TYPE (exp))))
5292 /* Some types, e.g. Fortran's logical*4, won't have a signed
5293 version, so use the mode instead. */
5294 tree ntype
5295 = (signed_or_unsigned_type_for
5296 (SUBREG_PROMOTED_SIGN (target), TREE_TYPE (exp)));
5297 if (ntype == NULL)
5298 ntype = lang_hooks.types.type_for_mode
5299 (TYPE_MODE (TREE_TYPE (exp)),
5300 SUBREG_PROMOTED_SIGN (target));
5302 exp = fold_convert_loc (loc, ntype, exp);
5305 exp = fold_convert_loc (loc, lang_hooks.types.type_for_mode
5306 (GET_MODE (SUBREG_REG (target)),
5307 SUBREG_PROMOTED_SIGN (target)),
5308 exp);
5310 inner_target = SUBREG_REG (target);
5313 temp = expand_expr (exp, inner_target, VOIDmode,
5314 call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
5316 /* Handle bounds returned by call. */
5317 if (TREE_CODE (exp) == CALL_EXPR)
5319 rtx bounds;
5320 chkp_split_slot (temp, &temp, &bounds);
5321 if (bounds && btarget)
5323 gcc_assert (TREE_CODE (btarget) == SSA_NAME);
5324 rtx tmp = targetm.calls.load_returned_bounds (bounds);
5325 chkp_set_rtl_bounds (btarget, tmp);
5329 /* If TEMP is a VOIDmode constant, use convert_modes to make
5330 sure that we properly convert it. */
5331 if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode)
5333 temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
5334 temp, SUBREG_PROMOTED_SIGN (target));
5335 temp = convert_modes (GET_MODE (SUBREG_REG (target)),
5336 GET_MODE (target), temp,
5337 SUBREG_PROMOTED_SIGN (target));
5340 convert_move (SUBREG_REG (target), temp,
5341 SUBREG_PROMOTED_SIGN (target));
5343 return NULL_RTX;
5345 else if ((TREE_CODE (exp) == STRING_CST
5346 || (TREE_CODE (exp) == MEM_REF
5347 && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
5348 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
5349 == STRING_CST
5350 && integer_zerop (TREE_OPERAND (exp, 1))))
5351 && !nontemporal && !call_param_p
5352 && MEM_P (target))
5354 /* Optimize initialization of an array with a STRING_CST. */
5355 HOST_WIDE_INT exp_len, str_copy_len;
5356 rtx dest_mem;
5357 tree str = TREE_CODE (exp) == STRING_CST
5358 ? exp : TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5360 exp_len = int_expr_size (exp);
5361 if (exp_len <= 0)
5362 goto normal_expr;
5364 if (TREE_STRING_LENGTH (str) <= 0)
5365 goto normal_expr;
5367 str_copy_len = strlen (TREE_STRING_POINTER (str));
5368 if (str_copy_len < TREE_STRING_LENGTH (str) - 1)
5369 goto normal_expr;
5371 str_copy_len = TREE_STRING_LENGTH (str);
5372 if ((STORE_MAX_PIECES & (STORE_MAX_PIECES - 1)) == 0
5373 && TREE_STRING_POINTER (str)[TREE_STRING_LENGTH (str) - 1] == '\0')
5375 str_copy_len += STORE_MAX_PIECES - 1;
5376 str_copy_len &= ~(STORE_MAX_PIECES - 1);
5378 str_copy_len = MIN (str_copy_len, exp_len);
5379 if (!can_store_by_pieces (str_copy_len, builtin_strncpy_read_str,
5380 CONST_CAST (char *, TREE_STRING_POINTER (str)),
5381 MEM_ALIGN (target), false))
5382 goto normal_expr;
5384 dest_mem = target;
5386 dest_mem = store_by_pieces (dest_mem,
5387 str_copy_len, builtin_strncpy_read_str,
5388 CONST_CAST (char *,
5389 TREE_STRING_POINTER (str)),
5390 MEM_ALIGN (target), false,
5391 exp_len > str_copy_len ? 1 : 0);
5392 if (exp_len > str_copy_len)
5393 clear_storage (adjust_address (dest_mem, BLKmode, 0),
5394 GEN_INT (exp_len - str_copy_len),
5395 BLOCK_OP_NORMAL);
5396 return NULL_RTX;
5398 else
5400 rtx tmp_target;
5402 normal_expr:
5403 /* If we want to use a nontemporal or a reverse order store, force the
5404 value into a register first. */
5405 tmp_target = nontemporal || reverse ? NULL_RTX : target;
5406 temp = expand_expr_real (exp, tmp_target, GET_MODE (target),
5407 (call_param_p
5408 ? EXPAND_STACK_PARM : EXPAND_NORMAL),
5409 &alt_rtl, false);
5411 /* Handle bounds returned by call. */
5412 if (TREE_CODE (exp) == CALL_EXPR)
5414 rtx bounds;
5415 chkp_split_slot (temp, &temp, &bounds);
5416 if (bounds && btarget)
5418 gcc_assert (TREE_CODE (btarget) == SSA_NAME);
5419 rtx tmp = targetm.calls.load_returned_bounds (bounds);
5420 chkp_set_rtl_bounds (btarget, tmp);
5425 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
5426 the same as that of TARGET, adjust the constant. This is needed, for
5427 example, in case it is a CONST_DOUBLE or CONST_WIDE_INT and we want
5428 only a word-sized value. */
5429 if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode
5430 && TREE_CODE (exp) != ERROR_MARK
5431 && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
5432 temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
5433 temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
5435 /* If value was not generated in the target, store it there.
5436 Convert the value to TARGET's type first if necessary and emit the
5437 pending incrementations that have been queued when expanding EXP.
5438 Note that we cannot emit the whole queue blindly because this will
5439 effectively disable the POST_INC optimization later.
5441 If TEMP and TARGET compare equal according to rtx_equal_p, but
5442 one or both of them are volatile memory refs, we have to distinguish
5443 two cases:
5444 - expand_expr has used TARGET. In this case, we must not generate
5445 another copy. This can be detected by TARGET being equal according
5446 to == .
5447 - expand_expr has not used TARGET - that means that the source just
5448 happens to have the same RTX form. Since temp will have been created
5449 by expand_expr, it will compare unequal according to == .
5450 We must generate a copy in this case, to reach the correct number
5451 of volatile memory references. */
5453 if ((! rtx_equal_p (temp, target)
5454 || (temp != target && (side_effects_p (temp)
5455 || side_effects_p (target))))
5456 && TREE_CODE (exp) != ERROR_MARK
5457 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5458 but TARGET is not valid memory reference, TEMP will differ
5459 from TARGET although it is really the same location. */
5460 && !(alt_rtl
5461 && rtx_equal_p (alt_rtl, target)
5462 && !side_effects_p (alt_rtl)
5463 && !side_effects_p (target))
5464 /* If there's nothing to copy, don't bother. Don't call
5465 expr_size unless necessary, because some front-ends (C++)
5466 expr_size-hook must not be given objects that are not
5467 supposed to be bit-copied or bit-initialized. */
5468 && expr_size (exp) != const0_rtx)
5470 if (GET_MODE (temp) != GET_MODE (target) && GET_MODE (temp) != VOIDmode)
5472 if (GET_MODE (target) == BLKmode)
5474 /* Handle calls that return BLKmode values in registers. */
5475 if (REG_P (temp) && TREE_CODE (exp) == CALL_EXPR)
5476 copy_blkmode_from_reg (target, temp, TREE_TYPE (exp));
5477 else
5478 store_bit_field (target,
5479 INTVAL (expr_size (exp)) * BITS_PER_UNIT,
5480 0, 0, 0, GET_MODE (temp), temp, reverse);
5482 else
5483 convert_move (target, temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
5486 else if (GET_MODE (temp) == BLKmode && TREE_CODE (exp) == STRING_CST)
5488 /* Handle copying a string constant into an array. The string
5489 constant may be shorter than the array. So copy just the string's
5490 actual length, and clear the rest. First get the size of the data
5491 type of the string, which is actually the size of the target. */
5492 rtx size = expr_size (exp);
5494 if (CONST_INT_P (size)
5495 && INTVAL (size) < TREE_STRING_LENGTH (exp))
5496 emit_block_move (target, temp, size,
5497 (call_param_p
5498 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
5499 else
5501 machine_mode pointer_mode
5502 = targetm.addr_space.pointer_mode (MEM_ADDR_SPACE (target));
5503 machine_mode address_mode = get_address_mode (target);
5505 /* Compute the size of the data to copy from the string. */
5506 tree copy_size
5507 = size_binop_loc (loc, MIN_EXPR,
5508 make_tree (sizetype, size),
5509 size_int (TREE_STRING_LENGTH (exp)));
5510 rtx copy_size_rtx
5511 = expand_expr (copy_size, NULL_RTX, VOIDmode,
5512 (call_param_p
5513 ? EXPAND_STACK_PARM : EXPAND_NORMAL));
5514 rtx_code_label *label = 0;
5516 /* Copy that much. */
5517 copy_size_rtx = convert_to_mode (pointer_mode, copy_size_rtx,
5518 TYPE_UNSIGNED (sizetype));
5519 emit_block_move (target, temp, copy_size_rtx,
5520 (call_param_p
5521 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
5523 /* Figure out how much is left in TARGET that we have to clear.
5524 Do all calculations in pointer_mode. */
5525 if (CONST_INT_P (copy_size_rtx))
5527 size = plus_constant (address_mode, size,
5528 -INTVAL (copy_size_rtx));
5529 target = adjust_address (target, BLKmode,
5530 INTVAL (copy_size_rtx));
5532 else
5534 size = expand_binop (TYPE_MODE (sizetype), sub_optab, size,
5535 copy_size_rtx, NULL_RTX, 0,
5536 OPTAB_LIB_WIDEN);
5538 if (GET_MODE (copy_size_rtx) != address_mode)
5539 copy_size_rtx = convert_to_mode (address_mode,
5540 copy_size_rtx,
5541 TYPE_UNSIGNED (sizetype));
5543 target = offset_address (target, copy_size_rtx,
5544 highest_pow2_factor (copy_size));
5545 label = gen_label_rtx ();
5546 emit_cmp_and_jump_insns (size, const0_rtx, LT, NULL_RTX,
5547 GET_MODE (size), 0, label);
5550 if (size != const0_rtx)
5551 clear_storage (target, size, BLOCK_OP_NORMAL);
5553 if (label)
5554 emit_label (label);
5557 /* Handle calls that return values in multiple non-contiguous locations.
5558 The Irix 6 ABI has examples of this. */
5559 else if (GET_CODE (target) == PARALLEL)
5561 if (GET_CODE (temp) == PARALLEL)
5562 emit_group_move (target, temp);
5563 else
5564 emit_group_load (target, temp, TREE_TYPE (exp),
5565 int_size_in_bytes (TREE_TYPE (exp)));
5567 else if (GET_CODE (temp) == PARALLEL)
5568 emit_group_store (target, temp, TREE_TYPE (exp),
5569 int_size_in_bytes (TREE_TYPE (exp)));
5570 else if (GET_MODE (temp) == BLKmode)
5571 emit_block_move (target, temp, expr_size (exp),
5572 (call_param_p
5573 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
5574 /* If we emit a nontemporal store, there is nothing else to do. */
5575 else if (nontemporal && emit_storent_insn (target, temp))
5577 else
5579 if (reverse)
5580 temp = flip_storage_order (GET_MODE (target), temp);
5581 temp = force_operand (temp, target);
5582 if (temp != target)
5583 emit_move_insn (target, temp);
5587 return NULL_RTX;
5590 /* Same as store_expr_with_bounds but ignoring bounds of EXP. */
5592 store_expr (tree exp, rtx target, int call_param_p, bool nontemporal,
5593 bool reverse)
5595 return store_expr_with_bounds (exp, target, call_param_p, nontemporal,
5596 reverse, NULL);
5599 /* Return true if field F of structure TYPE is a flexible array. */
5601 static bool
5602 flexible_array_member_p (const_tree f, const_tree type)
5604 const_tree tf;
5606 tf = TREE_TYPE (f);
5607 return (DECL_CHAIN (f) == NULL
5608 && TREE_CODE (tf) == ARRAY_TYPE
5609 && TYPE_DOMAIN (tf)
5610 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf))
5611 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf)))
5612 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf))
5613 && int_size_in_bytes (type) >= 0);
5616 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5617 must have in order for it to completely initialize a value of type TYPE.
5618 Return -1 if the number isn't known.
5620 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5622 static HOST_WIDE_INT
5623 count_type_elements (const_tree type, bool for_ctor_p)
5625 switch (TREE_CODE (type))
5627 case ARRAY_TYPE:
5629 tree nelts;
5631 nelts = array_type_nelts (type);
5632 if (nelts && tree_fits_uhwi_p (nelts))
5634 unsigned HOST_WIDE_INT n;
5636 n = tree_to_uhwi (nelts) + 1;
5637 if (n == 0 || for_ctor_p)
5638 return n;
5639 else
5640 return n * count_type_elements (TREE_TYPE (type), false);
5642 return for_ctor_p ? -1 : 1;
5645 case RECORD_TYPE:
5647 unsigned HOST_WIDE_INT n;
5648 tree f;
5650 n = 0;
5651 for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
5652 if (TREE_CODE (f) == FIELD_DECL)
5654 if (!for_ctor_p)
5655 n += count_type_elements (TREE_TYPE (f), false);
5656 else if (!flexible_array_member_p (f, type))
5657 /* Don't count flexible arrays, which are not supposed
5658 to be initialized. */
5659 n += 1;
5662 return n;
5665 case UNION_TYPE:
5666 case QUAL_UNION_TYPE:
5668 tree f;
5669 HOST_WIDE_INT n, m;
5671 gcc_assert (!for_ctor_p);
5672 /* Estimate the number of scalars in each field and pick the
5673 maximum. Other estimates would do instead; the idea is simply
5674 to make sure that the estimate is not sensitive to the ordering
5675 of the fields. */
5676 n = 1;
5677 for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
5678 if (TREE_CODE (f) == FIELD_DECL)
5680 m = count_type_elements (TREE_TYPE (f), false);
5681 /* If the field doesn't span the whole union, add an extra
5682 scalar for the rest. */
5683 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f)),
5684 TYPE_SIZE (type)) != 1)
5685 m++;
5686 if (n < m)
5687 n = m;
5689 return n;
5692 case COMPLEX_TYPE:
5693 return 2;
5695 case VECTOR_TYPE:
5696 return TYPE_VECTOR_SUBPARTS (type);
5698 case INTEGER_TYPE:
5699 case REAL_TYPE:
5700 case FIXED_POINT_TYPE:
5701 case ENUMERAL_TYPE:
5702 case BOOLEAN_TYPE:
5703 case POINTER_TYPE:
5704 case OFFSET_TYPE:
5705 case REFERENCE_TYPE:
5706 case NULLPTR_TYPE:
5707 return 1;
5709 case ERROR_MARK:
5710 return 0;
5712 case VOID_TYPE:
5713 case METHOD_TYPE:
5714 case FUNCTION_TYPE:
5715 case LANG_TYPE:
5716 default:
5717 gcc_unreachable ();
5721 /* Helper for categorize_ctor_elements. Identical interface. */
5723 static bool
5724 categorize_ctor_elements_1 (const_tree ctor, HOST_WIDE_INT *p_nz_elts,
5725 HOST_WIDE_INT *p_init_elts, bool *p_complete)
5727 unsigned HOST_WIDE_INT idx;
5728 HOST_WIDE_INT nz_elts, init_elts, num_fields;
5729 tree value, purpose, elt_type;
5731 /* Whether CTOR is a valid constant initializer, in accordance with what
5732 initializer_constant_valid_p does. If inferred from the constructor
5733 elements, true until proven otherwise. */
5734 bool const_from_elts_p = constructor_static_from_elts_p (ctor);
5735 bool const_p = const_from_elts_p ? true : TREE_STATIC (ctor);
5737 nz_elts = 0;
5738 init_elts = 0;
5739 num_fields = 0;
5740 elt_type = NULL_TREE;
5742 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), idx, purpose, value)
5744 HOST_WIDE_INT mult = 1;
5746 if (purpose && TREE_CODE (purpose) == RANGE_EXPR)
5748 tree lo_index = TREE_OPERAND (purpose, 0);
5749 tree hi_index = TREE_OPERAND (purpose, 1);
5751 if (tree_fits_uhwi_p (lo_index) && tree_fits_uhwi_p (hi_index))
5752 mult = (tree_to_uhwi (hi_index)
5753 - tree_to_uhwi (lo_index) + 1);
5755 num_fields += mult;
5756 elt_type = TREE_TYPE (value);
5758 switch (TREE_CODE (value))
5760 case CONSTRUCTOR:
5762 HOST_WIDE_INT nz = 0, ic = 0;
5764 bool const_elt_p = categorize_ctor_elements_1 (value, &nz, &ic,
5765 p_complete);
5767 nz_elts += mult * nz;
5768 init_elts += mult * ic;
5770 if (const_from_elts_p && const_p)
5771 const_p = const_elt_p;
5773 break;
5775 case INTEGER_CST:
5776 case REAL_CST:
5777 case FIXED_CST:
5778 if (!initializer_zerop (value))
5779 nz_elts += mult;
5780 init_elts += mult;
5781 break;
5783 case STRING_CST:
5784 nz_elts += mult * TREE_STRING_LENGTH (value);
5785 init_elts += mult * TREE_STRING_LENGTH (value);
5786 break;
5788 case COMPLEX_CST:
5789 if (!initializer_zerop (TREE_REALPART (value)))
5790 nz_elts += mult;
5791 if (!initializer_zerop (TREE_IMAGPART (value)))
5792 nz_elts += mult;
5793 init_elts += mult;
5794 break;
5796 case VECTOR_CST:
5798 unsigned i;
5799 for (i = 0; i < VECTOR_CST_NELTS (value); ++i)
5801 tree v = VECTOR_CST_ELT (value, i);
5802 if (!initializer_zerop (v))
5803 nz_elts += mult;
5804 init_elts += mult;
5807 break;
5809 default:
5811 HOST_WIDE_INT tc = count_type_elements (elt_type, false);
5812 nz_elts += mult * tc;
5813 init_elts += mult * tc;
5815 if (const_from_elts_p && const_p)
5816 const_p
5817 = initializer_constant_valid_p (value,
5818 elt_type,
5819 TYPE_REVERSE_STORAGE_ORDER
5820 (TREE_TYPE (ctor)))
5821 != NULL_TREE;
5823 break;
5827 if (*p_complete && !complete_ctor_at_level_p (TREE_TYPE (ctor),
5828 num_fields, elt_type))
5829 *p_complete = false;
5831 *p_nz_elts += nz_elts;
5832 *p_init_elts += init_elts;
5834 return const_p;
5837 /* Examine CTOR to discover:
5838 * how many scalar fields are set to nonzero values,
5839 and place it in *P_NZ_ELTS;
5840 * how many scalar fields in total are in CTOR,
5841 and place it in *P_ELT_COUNT.
5842 * whether the constructor is complete -- in the sense that every
5843 meaningful byte is explicitly given a value --
5844 and place it in *P_COMPLETE.
5846 Return whether or not CTOR is a valid static constant initializer, the same
5847 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5849 bool
5850 categorize_ctor_elements (const_tree ctor, HOST_WIDE_INT *p_nz_elts,
5851 HOST_WIDE_INT *p_init_elts, bool *p_complete)
5853 *p_nz_elts = 0;
5854 *p_init_elts = 0;
5855 *p_complete = true;
5857 return categorize_ctor_elements_1 (ctor, p_nz_elts, p_init_elts, p_complete);
5860 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
5861 of which had type LAST_TYPE. Each element was itself a complete
5862 initializer, in the sense that every meaningful byte was explicitly
5863 given a value. Return true if the same is true for the constructor
5864 as a whole. */
5866 bool
5867 complete_ctor_at_level_p (const_tree type, HOST_WIDE_INT num_elts,
5868 const_tree last_type)
5870 if (TREE_CODE (type) == UNION_TYPE
5871 || TREE_CODE (type) == QUAL_UNION_TYPE)
5873 if (num_elts == 0)
5874 return false;
5876 gcc_assert (num_elts == 1 && last_type);
5878 /* ??? We could look at each element of the union, and find the
5879 largest element. Which would avoid comparing the size of the
5880 initialized element against any tail padding in the union.
5881 Doesn't seem worth the effort... */
5882 return simple_cst_equal (TYPE_SIZE (type), TYPE_SIZE (last_type)) == 1;
5885 return count_type_elements (type, true) == num_elts;
5888 /* Return 1 if EXP contains mostly (3/4) zeros. */
5890 static int
5891 mostly_zeros_p (const_tree exp)
5893 if (TREE_CODE (exp) == CONSTRUCTOR)
5895 HOST_WIDE_INT nz_elts, init_elts;
5896 bool complete_p;
5898 categorize_ctor_elements (exp, &nz_elts, &init_elts, &complete_p);
5899 return !complete_p || nz_elts < init_elts / 4;
5902 return initializer_zerop (exp);
5905 /* Return 1 if EXP contains all zeros. */
5907 static int
5908 all_zeros_p (const_tree exp)
5910 if (TREE_CODE (exp) == CONSTRUCTOR)
5912 HOST_WIDE_INT nz_elts, init_elts;
5913 bool complete_p;
5915 categorize_ctor_elements (exp, &nz_elts, &init_elts, &complete_p);
5916 return nz_elts == 0;
5919 return initializer_zerop (exp);
5922 /* Helper function for store_constructor.
5923 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
5924 CLEARED is as for store_constructor.
5925 ALIAS_SET is the alias set to use for any stores.
5926 If REVERSE is true, the store is to be done in reverse order.
5928 This provides a recursive shortcut back to store_constructor when it isn't
5929 necessary to go through store_field. This is so that we can pass through
5930 the cleared field to let store_constructor know that we may not have to
5931 clear a substructure if the outer structure has already been cleared. */
5933 static void
5934 store_constructor_field (rtx target, unsigned HOST_WIDE_INT bitsize,
5935 HOST_WIDE_INT bitpos, machine_mode mode,
5936 tree exp, int cleared,
5937 alias_set_type alias_set, bool reverse)
5939 if (TREE_CODE (exp) == CONSTRUCTOR
5940 /* We can only call store_constructor recursively if the size and
5941 bit position are on a byte boundary. */
5942 && bitpos % BITS_PER_UNIT == 0
5943 && (bitsize > 0 && bitsize % BITS_PER_UNIT == 0)
5944 /* If we have a nonzero bitpos for a register target, then we just
5945 let store_field do the bitfield handling. This is unlikely to
5946 generate unnecessary clear instructions anyways. */
5947 && (bitpos == 0 || MEM_P (target)))
5949 if (MEM_P (target))
5950 target
5951 = adjust_address (target,
5952 GET_MODE (target) == BLKmode
5953 || 0 != (bitpos
5954 % GET_MODE_ALIGNMENT (GET_MODE (target)))
5955 ? BLKmode : VOIDmode, bitpos / BITS_PER_UNIT);
5958 /* Update the alias set, if required. */
5959 if (MEM_P (target) && ! MEM_KEEP_ALIAS_SET_P (target)
5960 && MEM_ALIAS_SET (target) != 0)
5962 target = copy_rtx (target);
5963 set_mem_alias_set (target, alias_set);
5966 store_constructor (exp, target, cleared, bitsize / BITS_PER_UNIT,
5967 reverse);
5969 else
5970 store_field (target, bitsize, bitpos, 0, 0, mode, exp, alias_set, false,
5971 reverse);
5975 /* Returns the number of FIELD_DECLs in TYPE. */
5977 static int
5978 fields_length (const_tree type)
5980 tree t = TYPE_FIELDS (type);
5981 int count = 0;
5983 for (; t; t = DECL_CHAIN (t))
5984 if (TREE_CODE (t) == FIELD_DECL)
5985 ++count;
5987 return count;
5991 /* Store the value of constructor EXP into the rtx TARGET.
5992 TARGET is either a REG or a MEM; we know it cannot conflict, since
5993 safe_from_p has been called.
5994 CLEARED is true if TARGET is known to have been zero'd.
5995 SIZE is the number of bytes of TARGET we are allowed to modify: this
5996 may not be the same as the size of EXP if we are assigning to a field
5997 which has been packed to exclude padding bits.
5998 If REVERSE is true, the store is to be done in reverse order. */
6000 static void
6001 store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size,
6002 bool reverse)
6004 tree type = TREE_TYPE (exp);
6005 HOST_WIDE_INT exp_size = int_size_in_bytes (type);
6007 switch (TREE_CODE (type))
6009 case RECORD_TYPE:
6010 case UNION_TYPE:
6011 case QUAL_UNION_TYPE:
6013 unsigned HOST_WIDE_INT idx;
6014 tree field, value;
6016 /* The storage order is specified for every aggregate type. */
6017 reverse = TYPE_REVERSE_STORAGE_ORDER (type);
6019 /* If size is zero or the target is already cleared, do nothing. */
6020 if (size == 0 || cleared)
6021 cleared = 1;
6022 /* We either clear the aggregate or indicate the value is dead. */
6023 else if ((TREE_CODE (type) == UNION_TYPE
6024 || TREE_CODE (type) == QUAL_UNION_TYPE)
6025 && ! CONSTRUCTOR_ELTS (exp))
6026 /* If the constructor is empty, clear the union. */
6028 clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
6029 cleared = 1;
6032 /* If we are building a static constructor into a register,
6033 set the initial value as zero so we can fold the value into
6034 a constant. But if more than one register is involved,
6035 this probably loses. */
6036 else if (REG_P (target) && TREE_STATIC (exp)
6037 && GET_MODE_SIZE (GET_MODE (target)) <= UNITS_PER_WORD)
6039 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
6040 cleared = 1;
6043 /* If the constructor has fewer fields than the structure or
6044 if we are initializing the structure to mostly zeros, clear
6045 the whole structure first. Don't do this if TARGET is a
6046 register whose mode size isn't equal to SIZE since
6047 clear_storage can't handle this case. */
6048 else if (size > 0
6049 && (((int)vec_safe_length (CONSTRUCTOR_ELTS (exp))
6050 != fields_length (type))
6051 || mostly_zeros_p (exp))
6052 && (!REG_P (target)
6053 || ((HOST_WIDE_INT) GET_MODE_SIZE (GET_MODE (target))
6054 == size)))
6056 clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
6057 cleared = 1;
6060 if (REG_P (target) && !cleared)
6061 emit_clobber (target);
6063 /* Store each element of the constructor into the
6064 corresponding field of TARGET. */
6065 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, field, value)
6067 machine_mode mode;
6068 HOST_WIDE_INT bitsize;
6069 HOST_WIDE_INT bitpos = 0;
6070 tree offset;
6071 rtx to_rtx = target;
6073 /* Just ignore missing fields. We cleared the whole
6074 structure, above, if any fields are missing. */
6075 if (field == 0)
6076 continue;
6078 if (cleared && initializer_zerop (value))
6079 continue;
6081 if (tree_fits_uhwi_p (DECL_SIZE (field)))
6082 bitsize = tree_to_uhwi (DECL_SIZE (field));
6083 else
6084 bitsize = -1;
6086 mode = DECL_MODE (field);
6087 if (DECL_BIT_FIELD (field))
6088 mode = VOIDmode;
6090 offset = DECL_FIELD_OFFSET (field);
6091 if (tree_fits_shwi_p (offset)
6092 && tree_fits_shwi_p (bit_position (field)))
6094 bitpos = int_bit_position (field);
6095 offset = 0;
6097 else
6098 bitpos = tree_to_shwi (DECL_FIELD_BIT_OFFSET (field));
6100 if (offset)
6102 machine_mode address_mode;
6103 rtx offset_rtx;
6105 offset
6106 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset,
6107 make_tree (TREE_TYPE (exp),
6108 target));
6110 offset_rtx = expand_normal (offset);
6111 gcc_assert (MEM_P (to_rtx));
6113 address_mode = get_address_mode (to_rtx);
6114 if (GET_MODE (offset_rtx) != address_mode)
6115 offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
6117 to_rtx = offset_address (to_rtx, offset_rtx,
6118 highest_pow2_factor (offset));
6121 /* If this initializes a field that is smaller than a
6122 word, at the start of a word, try to widen it to a full
6123 word. This special case allows us to output C++ member
6124 function initializations in a form that the optimizers
6125 can understand. */
6126 if (WORD_REGISTER_OPERATIONS
6127 && REG_P (target)
6128 && bitsize < BITS_PER_WORD
6129 && bitpos % BITS_PER_WORD == 0
6130 && GET_MODE_CLASS (mode) == MODE_INT
6131 && TREE_CODE (value) == INTEGER_CST
6132 && exp_size >= 0
6133 && bitpos + BITS_PER_WORD <= exp_size * BITS_PER_UNIT)
6135 tree type = TREE_TYPE (value);
6137 if (TYPE_PRECISION (type) < BITS_PER_WORD)
6139 type = lang_hooks.types.type_for_mode
6140 (word_mode, TYPE_UNSIGNED (type));
6141 value = fold_convert (type, value);
6144 if (BYTES_BIG_ENDIAN)
6145 value
6146 = fold_build2 (LSHIFT_EXPR, type, value,
6147 build_int_cst (type,
6148 BITS_PER_WORD - bitsize));
6149 bitsize = BITS_PER_WORD;
6150 mode = word_mode;
6153 if (MEM_P (to_rtx) && !MEM_KEEP_ALIAS_SET_P (to_rtx)
6154 && DECL_NONADDRESSABLE_P (field))
6156 to_rtx = copy_rtx (to_rtx);
6157 MEM_KEEP_ALIAS_SET_P (to_rtx) = 1;
6160 store_constructor_field (to_rtx, bitsize, bitpos, mode,
6161 value, cleared,
6162 get_alias_set (TREE_TYPE (field)),
6163 reverse);
6165 break;
6167 case ARRAY_TYPE:
6169 tree value, index;
6170 unsigned HOST_WIDE_INT i;
6171 int need_to_clear;
6172 tree domain;
6173 tree elttype = TREE_TYPE (type);
6174 int const_bounds_p;
6175 HOST_WIDE_INT minelt = 0;
6176 HOST_WIDE_INT maxelt = 0;
6178 /* The storage order is specified for every aggregate type. */
6179 reverse = TYPE_REVERSE_STORAGE_ORDER (type);
6181 domain = TYPE_DOMAIN (type);
6182 const_bounds_p = (TYPE_MIN_VALUE (domain)
6183 && TYPE_MAX_VALUE (domain)
6184 && tree_fits_shwi_p (TYPE_MIN_VALUE (domain))
6185 && tree_fits_shwi_p (TYPE_MAX_VALUE (domain)));
6187 /* If we have constant bounds for the range of the type, get them. */
6188 if (const_bounds_p)
6190 minelt = tree_to_shwi (TYPE_MIN_VALUE (domain));
6191 maxelt = tree_to_shwi (TYPE_MAX_VALUE (domain));
6194 /* If the constructor has fewer elements than the array, clear
6195 the whole array first. Similarly if this is static
6196 constructor of a non-BLKmode object. */
6197 if (cleared)
6198 need_to_clear = 0;
6199 else if (REG_P (target) && TREE_STATIC (exp))
6200 need_to_clear = 1;
6201 else
6203 unsigned HOST_WIDE_INT idx;
6204 tree index, value;
6205 HOST_WIDE_INT count = 0, zero_count = 0;
6206 need_to_clear = ! const_bounds_p;
6208 /* This loop is a more accurate version of the loop in
6209 mostly_zeros_p (it handles RANGE_EXPR in an index). It
6210 is also needed to check for missing elements. */
6211 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, index, value)
6213 HOST_WIDE_INT this_node_count;
6215 if (need_to_clear)
6216 break;
6218 if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
6220 tree lo_index = TREE_OPERAND (index, 0);
6221 tree hi_index = TREE_OPERAND (index, 1);
6223 if (! tree_fits_uhwi_p (lo_index)
6224 || ! tree_fits_uhwi_p (hi_index))
6226 need_to_clear = 1;
6227 break;
6230 this_node_count = (tree_to_uhwi (hi_index)
6231 - tree_to_uhwi (lo_index) + 1);
6233 else
6234 this_node_count = 1;
6236 count += this_node_count;
6237 if (mostly_zeros_p (value))
6238 zero_count += this_node_count;
6241 /* Clear the entire array first if there are any missing
6242 elements, or if the incidence of zero elements is >=
6243 75%. */
6244 if (! need_to_clear
6245 && (count < maxelt - minelt + 1
6246 || 4 * zero_count >= 3 * count))
6247 need_to_clear = 1;
6250 if (need_to_clear && size > 0)
6252 if (REG_P (target))
6253 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
6254 else
6255 clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
6256 cleared = 1;
6259 if (!cleared && REG_P (target))
6260 /* Inform later passes that the old value is dead. */
6261 emit_clobber (target);
6263 /* Store each element of the constructor into the
6264 corresponding element of TARGET, determined by counting the
6265 elements. */
6266 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), i, index, value)
6268 machine_mode mode;
6269 HOST_WIDE_INT bitsize;
6270 HOST_WIDE_INT bitpos;
6271 rtx xtarget = target;
6273 if (cleared && initializer_zerop (value))
6274 continue;
6276 mode = TYPE_MODE (elttype);
6277 if (mode == BLKmode)
6278 bitsize = (tree_fits_uhwi_p (TYPE_SIZE (elttype))
6279 ? tree_to_uhwi (TYPE_SIZE (elttype))
6280 : -1);
6281 else
6282 bitsize = GET_MODE_BITSIZE (mode);
6284 if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
6286 tree lo_index = TREE_OPERAND (index, 0);
6287 tree hi_index = TREE_OPERAND (index, 1);
6288 rtx index_r, pos_rtx;
6289 HOST_WIDE_INT lo, hi, count;
6290 tree position;
6292 /* If the range is constant and "small", unroll the loop. */
6293 if (const_bounds_p
6294 && tree_fits_shwi_p (lo_index)
6295 && tree_fits_shwi_p (hi_index)
6296 && (lo = tree_to_shwi (lo_index),
6297 hi = tree_to_shwi (hi_index),
6298 count = hi - lo + 1,
6299 (!MEM_P (target)
6300 || count <= 2
6301 || (tree_fits_uhwi_p (TYPE_SIZE (elttype))
6302 && (tree_to_uhwi (TYPE_SIZE (elttype)) * count
6303 <= 40 * 8)))))
6305 lo -= minelt; hi -= minelt;
6306 for (; lo <= hi; lo++)
6308 bitpos = lo * tree_to_shwi (TYPE_SIZE (elttype));
6310 if (MEM_P (target)
6311 && !MEM_KEEP_ALIAS_SET_P (target)
6312 && TREE_CODE (type) == ARRAY_TYPE
6313 && TYPE_NONALIASED_COMPONENT (type))
6315 target = copy_rtx (target);
6316 MEM_KEEP_ALIAS_SET_P (target) = 1;
6319 store_constructor_field
6320 (target, bitsize, bitpos, mode, value, cleared,
6321 get_alias_set (elttype), reverse);
6324 else
6326 rtx_code_label *loop_start = gen_label_rtx ();
6327 rtx_code_label *loop_end = gen_label_rtx ();
6328 tree exit_cond;
6330 expand_normal (hi_index);
6332 index = build_decl (EXPR_LOCATION (exp),
6333 VAR_DECL, NULL_TREE, domain);
6334 index_r = gen_reg_rtx (promote_decl_mode (index, NULL));
6335 SET_DECL_RTL (index, index_r);
6336 store_expr (lo_index, index_r, 0, false, reverse);
6338 /* Build the head of the loop. */
6339 do_pending_stack_adjust ();
6340 emit_label (loop_start);
6342 /* Assign value to element index. */
6343 position =
6344 fold_convert (ssizetype,
6345 fold_build2 (MINUS_EXPR,
6346 TREE_TYPE (index),
6347 index,
6348 TYPE_MIN_VALUE (domain)));
6350 position =
6351 size_binop (MULT_EXPR, position,
6352 fold_convert (ssizetype,
6353 TYPE_SIZE_UNIT (elttype)));
6355 pos_rtx = expand_normal (position);
6356 xtarget = offset_address (target, pos_rtx,
6357 highest_pow2_factor (position));
6358 xtarget = adjust_address (xtarget, mode, 0);
6359 if (TREE_CODE (value) == CONSTRUCTOR)
6360 store_constructor (value, xtarget, cleared,
6361 bitsize / BITS_PER_UNIT, reverse);
6362 else
6363 store_expr (value, xtarget, 0, false, reverse);
6365 /* Generate a conditional jump to exit the loop. */
6366 exit_cond = build2 (LT_EXPR, integer_type_node,
6367 index, hi_index);
6368 jumpif (exit_cond, loop_end, -1);
6370 /* Update the loop counter, and jump to the head of
6371 the loop. */
6372 expand_assignment (index,
6373 build2 (PLUS_EXPR, TREE_TYPE (index),
6374 index, integer_one_node),
6375 false);
6377 emit_jump (loop_start);
6379 /* Build the end of the loop. */
6380 emit_label (loop_end);
6383 else if ((index != 0 && ! tree_fits_shwi_p (index))
6384 || ! tree_fits_uhwi_p (TYPE_SIZE (elttype)))
6386 tree position;
6388 if (index == 0)
6389 index = ssize_int (1);
6391 if (minelt)
6392 index = fold_convert (ssizetype,
6393 fold_build2 (MINUS_EXPR,
6394 TREE_TYPE (index),
6395 index,
6396 TYPE_MIN_VALUE (domain)));
6398 position =
6399 size_binop (MULT_EXPR, index,
6400 fold_convert (ssizetype,
6401 TYPE_SIZE_UNIT (elttype)));
6402 xtarget = offset_address (target,
6403 expand_normal (position),
6404 highest_pow2_factor (position));
6405 xtarget = adjust_address (xtarget, mode, 0);
6406 store_expr (value, xtarget, 0, false, reverse);
6408 else
6410 if (index != 0)
6411 bitpos = ((tree_to_shwi (index) - minelt)
6412 * tree_to_uhwi (TYPE_SIZE (elttype)));
6413 else
6414 bitpos = (i * tree_to_uhwi (TYPE_SIZE (elttype)));
6416 if (MEM_P (target) && !MEM_KEEP_ALIAS_SET_P (target)
6417 && TREE_CODE (type) == ARRAY_TYPE
6418 && TYPE_NONALIASED_COMPONENT (type))
6420 target = copy_rtx (target);
6421 MEM_KEEP_ALIAS_SET_P (target) = 1;
6423 store_constructor_field (target, bitsize, bitpos, mode, value,
6424 cleared, get_alias_set (elttype),
6425 reverse);
6428 break;
6431 case VECTOR_TYPE:
6433 unsigned HOST_WIDE_INT idx;
6434 constructor_elt *ce;
6435 int i;
6436 int need_to_clear;
6437 int icode = CODE_FOR_nothing;
6438 tree elttype = TREE_TYPE (type);
6439 int elt_size = tree_to_uhwi (TYPE_SIZE (elttype));
6440 machine_mode eltmode = TYPE_MODE (elttype);
6441 HOST_WIDE_INT bitsize;
6442 HOST_WIDE_INT bitpos;
6443 rtvec vector = NULL;
6444 unsigned n_elts;
6445 alias_set_type alias;
6447 gcc_assert (eltmode != BLKmode);
6449 n_elts = TYPE_VECTOR_SUBPARTS (type);
6450 if (REG_P (target) && VECTOR_MODE_P (GET_MODE (target)))
6452 machine_mode mode = GET_MODE (target);
6454 icode = (int) optab_handler (vec_init_optab, mode);
6455 /* Don't use vec_init<mode> if some elements have VECTOR_TYPE. */
6456 if (icode != CODE_FOR_nothing)
6458 tree value;
6460 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
6461 if (TREE_CODE (TREE_TYPE (value)) == VECTOR_TYPE)
6463 icode = CODE_FOR_nothing;
6464 break;
6467 if (icode != CODE_FOR_nothing)
6469 unsigned int i;
6471 vector = rtvec_alloc (n_elts);
6472 for (i = 0; i < n_elts; i++)
6473 RTVEC_ELT (vector, i) = CONST0_RTX (GET_MODE_INNER (mode));
6477 /* If the constructor has fewer elements than the vector,
6478 clear the whole array first. Similarly if this is static
6479 constructor of a non-BLKmode object. */
6480 if (cleared)
6481 need_to_clear = 0;
6482 else if (REG_P (target) && TREE_STATIC (exp))
6483 need_to_clear = 1;
6484 else
6486 unsigned HOST_WIDE_INT count = 0, zero_count = 0;
6487 tree value;
6489 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
6491 int n_elts_here = tree_to_uhwi
6492 (int_const_binop (TRUNC_DIV_EXPR,
6493 TYPE_SIZE (TREE_TYPE (value)),
6494 TYPE_SIZE (elttype)));
6496 count += n_elts_here;
6497 if (mostly_zeros_p (value))
6498 zero_count += n_elts_here;
6501 /* Clear the entire vector first if there are any missing elements,
6502 or if the incidence of zero elements is >= 75%. */
6503 need_to_clear = (count < n_elts || 4 * zero_count >= 3 * count);
6506 if (need_to_clear && size > 0 && !vector)
6508 if (REG_P (target))
6509 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
6510 else
6511 clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
6512 cleared = 1;
6515 /* Inform later passes that the old value is dead. */
6516 if (!cleared && !vector && REG_P (target))
6517 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
6519 if (MEM_P (target))
6520 alias = MEM_ALIAS_SET (target);
6521 else
6522 alias = get_alias_set (elttype);
6524 /* Store each element of the constructor into the corresponding
6525 element of TARGET, determined by counting the elements. */
6526 for (idx = 0, i = 0;
6527 vec_safe_iterate (CONSTRUCTOR_ELTS (exp), idx, &ce);
6528 idx++, i += bitsize / elt_size)
6530 HOST_WIDE_INT eltpos;
6531 tree value = ce->value;
6533 bitsize = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (value)));
6534 if (cleared && initializer_zerop (value))
6535 continue;
6537 if (ce->index)
6538 eltpos = tree_to_uhwi (ce->index);
6539 else
6540 eltpos = i;
6542 if (vector)
6544 /* vec_init<mode> should not be used if there are VECTOR_TYPE
6545 elements. */
6546 gcc_assert (TREE_CODE (TREE_TYPE (value)) != VECTOR_TYPE);
6547 RTVEC_ELT (vector, eltpos)
6548 = expand_normal (value);
6550 else
6552 machine_mode value_mode =
6553 TREE_CODE (TREE_TYPE (value)) == VECTOR_TYPE
6554 ? TYPE_MODE (TREE_TYPE (value))
6555 : eltmode;
6556 bitpos = eltpos * elt_size;
6557 store_constructor_field (target, bitsize, bitpos, value_mode,
6558 value, cleared, alias, reverse);
6562 if (vector)
6563 emit_insn (GEN_FCN (icode)
6564 (target,
6565 gen_rtx_PARALLEL (GET_MODE (target), vector)));
6566 break;
6569 default:
6570 gcc_unreachable ();
6574 /* Store the value of EXP (an expression tree)
6575 into a subfield of TARGET which has mode MODE and occupies
6576 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6577 If MODE is VOIDmode, it means that we are storing into a bit-field.
6579 BITREGION_START is bitpos of the first bitfield in this region.
6580 BITREGION_END is the bitpos of the ending bitfield in this region.
6581 These two fields are 0, if the C++ memory model does not apply,
6582 or we are not interested in keeping track of bitfield regions.
6584 Always return const0_rtx unless we have something particular to
6585 return.
6587 ALIAS_SET is the alias set for the destination. This value will
6588 (in general) be different from that for TARGET, since TARGET is a
6589 reference to the containing structure.
6591 If NONTEMPORAL is true, try generating a nontemporal store.
6593 If REVERSE is true, the store is to be done in reverse order. */
6595 static rtx
6596 store_field (rtx target, HOST_WIDE_INT bitsize, HOST_WIDE_INT bitpos,
6597 unsigned HOST_WIDE_INT bitregion_start,
6598 unsigned HOST_WIDE_INT bitregion_end,
6599 machine_mode mode, tree exp,
6600 alias_set_type alias_set, bool nontemporal, bool reverse)
6602 if (TREE_CODE (exp) == ERROR_MARK)
6603 return const0_rtx;
6605 /* If we have nothing to store, do nothing unless the expression has
6606 side-effects. */
6607 if (bitsize == 0)
6608 return expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL);
6610 if (GET_CODE (target) == CONCAT)
6612 /* We're storing into a struct containing a single __complex. */
6614 gcc_assert (!bitpos);
6615 return store_expr (exp, target, 0, nontemporal, reverse);
6618 /* If the structure is in a register or if the component
6619 is a bit field, we cannot use addressing to access it.
6620 Use bit-field techniques or SUBREG to store in it. */
6622 if (mode == VOIDmode
6623 || (mode != BLKmode && ! direct_store[(int) mode]
6624 && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
6625 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT)
6626 || REG_P (target)
6627 || GET_CODE (target) == SUBREG
6628 /* If the field isn't aligned enough to store as an ordinary memref,
6629 store it as a bit field. */
6630 || (mode != BLKmode
6631 && ((((MEM_ALIGN (target) < GET_MODE_ALIGNMENT (mode))
6632 || bitpos % GET_MODE_ALIGNMENT (mode))
6633 && SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (target)))
6634 || (bitpos % BITS_PER_UNIT != 0)))
6635 || (bitsize >= 0 && mode != BLKmode
6636 && GET_MODE_BITSIZE (mode) > bitsize)
6637 /* If the RHS and field are a constant size and the size of the
6638 RHS isn't the same size as the bitfield, we must use bitfield
6639 operations. */
6640 || (bitsize >= 0
6641 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) == INTEGER_CST
6642 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)), bitsize) != 0
6643 /* Except for initialization of full bytes from a CONSTRUCTOR, which
6644 we will handle specially below. */
6645 && !(TREE_CODE (exp) == CONSTRUCTOR
6646 && bitsize % BITS_PER_UNIT == 0))
6647 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6648 decl we must use bitfield operations. */
6649 || (bitsize >= 0
6650 && TREE_CODE (exp) == MEM_REF
6651 && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
6652 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
6653 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp, 0),0 ))
6654 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) != BLKmode))
6656 rtx temp;
6657 gimple *nop_def;
6659 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6660 implies a mask operation. If the precision is the same size as
6661 the field we're storing into, that mask is redundant. This is
6662 particularly common with bit field assignments generated by the
6663 C front end. */
6664 nop_def = get_def_for_expr (exp, NOP_EXPR);
6665 if (nop_def)
6667 tree type = TREE_TYPE (exp);
6668 if (INTEGRAL_TYPE_P (type)
6669 && TYPE_PRECISION (type) < GET_MODE_BITSIZE (TYPE_MODE (type))
6670 && bitsize == TYPE_PRECISION (type))
6672 tree op = gimple_assign_rhs1 (nop_def);
6673 type = TREE_TYPE (op);
6674 if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) >= bitsize)
6675 exp = op;
6679 temp = expand_normal (exp);
6681 /* If the value has a record type and an integral mode then, if BITSIZE
6682 is narrower than this mode and this is for big-endian data, we must
6683 first put the value into the low-order bits. Moreover, the field may
6684 be not aligned on a byte boundary; in this case, if it has reverse
6685 storage order, it needs to be accessed as a scalar field with reverse
6686 storage order and we must first put the value into target order. */
6687 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
6688 && GET_MODE_CLASS (GET_MODE (temp)) == MODE_INT)
6690 HOST_WIDE_INT size = GET_MODE_BITSIZE (GET_MODE (temp));
6692 reverse = TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (exp));
6694 if (reverse)
6695 temp = flip_storage_order (GET_MODE (temp), temp);
6697 if (bitsize < size
6698 && reverse ? !BYTES_BIG_ENDIAN : BYTES_BIG_ENDIAN)
6699 temp = expand_shift (RSHIFT_EXPR, GET_MODE (temp), temp,
6700 size - bitsize, NULL_RTX, 1);
6703 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
6704 if (mode != VOIDmode && mode != BLKmode
6705 && mode != TYPE_MODE (TREE_TYPE (exp)))
6706 temp = convert_modes (mode, TYPE_MODE (TREE_TYPE (exp)), temp, 1);
6708 /* If TEMP is not a PARALLEL (see below) and its mode and that of TARGET
6709 are both BLKmode, both must be in memory and BITPOS must be aligned
6710 on a byte boundary. If so, we simply do a block copy. Likewise for
6711 a BLKmode-like TARGET. */
6712 if (GET_CODE (temp) != PARALLEL
6713 && GET_MODE (temp) == BLKmode
6714 && (GET_MODE (target) == BLKmode
6715 || (MEM_P (target)
6716 && GET_MODE_CLASS (GET_MODE (target)) == MODE_INT
6717 && (bitpos % BITS_PER_UNIT) == 0
6718 && (bitsize % BITS_PER_UNIT) == 0)))
6720 gcc_assert (MEM_P (target) && MEM_P (temp)
6721 && (bitpos % BITS_PER_UNIT) == 0);
6723 target = adjust_address (target, VOIDmode, bitpos / BITS_PER_UNIT);
6724 emit_block_move (target, temp,
6725 GEN_INT ((bitsize + BITS_PER_UNIT - 1)
6726 / BITS_PER_UNIT),
6727 BLOCK_OP_NORMAL);
6729 return const0_rtx;
6732 /* Handle calls that return values in multiple non-contiguous locations.
6733 The Irix 6 ABI has examples of this. */
6734 if (GET_CODE (temp) == PARALLEL)
6736 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
6737 rtx temp_target;
6738 if (mode == BLKmode || mode == VOIDmode)
6739 mode = smallest_mode_for_size (size * BITS_PER_UNIT, MODE_INT);
6740 temp_target = gen_reg_rtx (mode);
6741 emit_group_store (temp_target, temp, TREE_TYPE (exp), size);
6742 temp = temp_target;
6744 else if (mode == BLKmode)
6746 /* Handle calls that return BLKmode values in registers. */
6747 if (REG_P (temp) && TREE_CODE (exp) == CALL_EXPR)
6749 rtx temp_target = gen_reg_rtx (GET_MODE (temp));
6750 copy_blkmode_from_reg (temp_target, temp, TREE_TYPE (exp));
6751 temp = temp_target;
6753 else
6755 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
6756 rtx temp_target;
6757 mode = smallest_mode_for_size (size * BITS_PER_UNIT, MODE_INT);
6758 temp_target = gen_reg_rtx (mode);
6759 temp_target
6760 = extract_bit_field (temp, size * BITS_PER_UNIT, 0, 1,
6761 temp_target, mode, mode, false);
6762 temp = temp_target;
6766 /* Store the value in the bitfield. */
6767 store_bit_field (target, bitsize, bitpos,
6768 bitregion_start, bitregion_end,
6769 mode, temp, reverse);
6771 return const0_rtx;
6773 else
6775 /* Now build a reference to just the desired component. */
6776 rtx to_rtx = adjust_address (target, mode, bitpos / BITS_PER_UNIT);
6778 if (to_rtx == target)
6779 to_rtx = copy_rtx (to_rtx);
6781 if (!MEM_KEEP_ALIAS_SET_P (to_rtx) && MEM_ALIAS_SET (to_rtx) != 0)
6782 set_mem_alias_set (to_rtx, alias_set);
6784 /* Above we avoided using bitfield operations for storing a CONSTRUCTOR
6785 into a target smaller than its type; handle that case now. */
6786 if (TREE_CODE (exp) == CONSTRUCTOR && bitsize >= 0)
6788 gcc_assert (bitsize % BITS_PER_UNIT == 0);
6789 store_constructor (exp, to_rtx, 0, bitsize / BITS_PER_UNIT, reverse);
6790 return to_rtx;
6793 return store_expr (exp, to_rtx, 0, nontemporal, reverse);
6797 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6798 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6799 codes and find the ultimate containing object, which we return.
6801 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6802 bit position, *PUNSIGNEDP to the signedness and *PREVERSEP to the
6803 storage order of the field.
6804 If the position of the field is variable, we store a tree
6805 giving the variable offset (in units) in *POFFSET.
6806 This offset is in addition to the bit position.
6807 If the position is not variable, we store 0 in *POFFSET.
6809 If any of the extraction expressions is volatile,
6810 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6812 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6813 Otherwise, it is a mode that can be used to access the field.
6815 If the field describes a variable-sized object, *PMODE is set to
6816 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6817 this case, but the address of the object can be found.
6819 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
6820 look through nodes that serve as markers of a greater alignment than
6821 the one that can be deduced from the expression. These nodes make it
6822 possible for front-ends to prevent temporaries from being created by
6823 the middle-end on alignment considerations. For that purpose, the
6824 normal operating mode at high-level is to always pass FALSE so that
6825 the ultimate containing object is really returned; moreover, the
6826 associated predicate handled_component_p will always return TRUE
6827 on these nodes, thus indicating that they are essentially handled
6828 by get_inner_reference. TRUE should only be passed when the caller
6829 is scanning the expression in order to build another representation
6830 and specifically knows how to handle these nodes; as such, this is
6831 the normal operating mode in the RTL expanders. */
6833 tree
6834 get_inner_reference (tree exp, HOST_WIDE_INT *pbitsize,
6835 HOST_WIDE_INT *pbitpos, tree *poffset,
6836 machine_mode *pmode, int *punsignedp,
6837 int *preversep, int *pvolatilep, bool keep_aligning)
6839 tree size_tree = 0;
6840 machine_mode mode = VOIDmode;
6841 bool blkmode_bitfield = false;
6842 tree offset = size_zero_node;
6843 offset_int bit_offset = 0;
6845 /* First get the mode, signedness, storage order and size. We do this from
6846 just the outermost expression. */
6847 *pbitsize = -1;
6848 if (TREE_CODE (exp) == COMPONENT_REF)
6850 tree field = TREE_OPERAND (exp, 1);
6851 size_tree = DECL_SIZE (field);
6852 if (flag_strict_volatile_bitfields > 0
6853 && TREE_THIS_VOLATILE (exp)
6854 && DECL_BIT_FIELD_TYPE (field)
6855 && DECL_MODE (field) != BLKmode)
6856 /* Volatile bitfields should be accessed in the mode of the
6857 field's type, not the mode computed based on the bit
6858 size. */
6859 mode = TYPE_MODE (DECL_BIT_FIELD_TYPE (field));
6860 else if (!DECL_BIT_FIELD (field))
6861 mode = DECL_MODE (field);
6862 else if (DECL_MODE (field) == BLKmode)
6863 blkmode_bitfield = true;
6865 *punsignedp = DECL_UNSIGNED (field);
6867 else if (TREE_CODE (exp) == BIT_FIELD_REF)
6869 size_tree = TREE_OPERAND (exp, 1);
6870 *punsignedp = (! INTEGRAL_TYPE_P (TREE_TYPE (exp))
6871 || TYPE_UNSIGNED (TREE_TYPE (exp)));
6873 /* For vector types, with the correct size of access, use the mode of
6874 inner type. */
6875 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == VECTOR_TYPE
6876 && TREE_TYPE (exp) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)))
6877 && tree_int_cst_equal (size_tree, TYPE_SIZE (TREE_TYPE (exp))))
6878 mode = TYPE_MODE (TREE_TYPE (exp));
6880 else
6882 mode = TYPE_MODE (TREE_TYPE (exp));
6883 *punsignedp = TYPE_UNSIGNED (TREE_TYPE (exp));
6885 if (mode == BLKmode)
6886 size_tree = TYPE_SIZE (TREE_TYPE (exp));
6887 else
6888 *pbitsize = GET_MODE_BITSIZE (mode);
6891 if (size_tree != 0)
6893 if (! tree_fits_uhwi_p (size_tree))
6894 mode = BLKmode, *pbitsize = -1;
6895 else
6896 *pbitsize = tree_to_uhwi (size_tree);
6899 *preversep = reverse_storage_order_for_component_p (exp);
6901 /* Compute cumulative bit-offset for nested component-refs and array-refs,
6902 and find the ultimate containing object. */
6903 while (1)
6905 switch (TREE_CODE (exp))
6907 case BIT_FIELD_REF:
6908 bit_offset += wi::to_offset (TREE_OPERAND (exp, 2));
6909 break;
6911 case COMPONENT_REF:
6913 tree field = TREE_OPERAND (exp, 1);
6914 tree this_offset = component_ref_field_offset (exp);
6916 /* If this field hasn't been filled in yet, don't go past it.
6917 This should only happen when folding expressions made during
6918 type construction. */
6919 if (this_offset == 0)
6920 break;
6922 offset = size_binop (PLUS_EXPR, offset, this_offset);
6923 bit_offset += wi::to_offset (DECL_FIELD_BIT_OFFSET (field));
6925 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
6927 break;
6929 case ARRAY_REF:
6930 case ARRAY_RANGE_REF:
6932 tree index = TREE_OPERAND (exp, 1);
6933 tree low_bound = array_ref_low_bound (exp);
6934 tree unit_size = array_ref_element_size (exp);
6936 /* We assume all arrays have sizes that are a multiple of a byte.
6937 First subtract the lower bound, if any, in the type of the
6938 index, then convert to sizetype and multiply by the size of
6939 the array element. */
6940 if (! integer_zerop (low_bound))
6941 index = fold_build2 (MINUS_EXPR, TREE_TYPE (index),
6942 index, low_bound);
6944 offset = size_binop (PLUS_EXPR, offset,
6945 size_binop (MULT_EXPR,
6946 fold_convert (sizetype, index),
6947 unit_size));
6949 break;
6951 case REALPART_EXPR:
6952 break;
6954 case IMAGPART_EXPR:
6955 bit_offset += *pbitsize;
6956 break;
6958 case VIEW_CONVERT_EXPR:
6959 if (keep_aligning && STRICT_ALIGNMENT
6960 && (TYPE_ALIGN (TREE_TYPE (exp))
6961 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0))))
6962 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0)))
6963 < BIGGEST_ALIGNMENT)
6964 && (TYPE_ALIGN_OK (TREE_TYPE (exp))
6965 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp, 0)))))
6966 goto done;
6967 break;
6969 case MEM_REF:
6970 /* Hand back the decl for MEM[&decl, off]. */
6971 if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR)
6973 tree off = TREE_OPERAND (exp, 1);
6974 if (!integer_zerop (off))
6976 offset_int boff, coff = mem_ref_offset (exp);
6977 boff = wi::lshift (coff, LOG2_BITS_PER_UNIT);
6978 bit_offset += boff;
6980 exp = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6982 goto done;
6984 default:
6985 goto done;
6988 /* If any reference in the chain is volatile, the effect is volatile. */
6989 if (TREE_THIS_VOLATILE (exp))
6990 *pvolatilep = 1;
6992 exp = TREE_OPERAND (exp, 0);
6994 done:
6996 /* If OFFSET is constant, see if we can return the whole thing as a
6997 constant bit position. Make sure to handle overflow during
6998 this conversion. */
6999 if (TREE_CODE (offset) == INTEGER_CST)
7001 offset_int tem = wi::sext (wi::to_offset (offset),
7002 TYPE_PRECISION (sizetype));
7003 tem = wi::lshift (tem, LOG2_BITS_PER_UNIT);
7004 tem += bit_offset;
7005 if (wi::fits_shwi_p (tem))
7007 *pbitpos = tem.to_shwi ();
7008 *poffset = offset = NULL_TREE;
7012 /* Otherwise, split it up. */
7013 if (offset)
7015 /* Avoid returning a negative bitpos as this may wreak havoc later. */
7016 if (wi::neg_p (bit_offset) || !wi::fits_shwi_p (bit_offset))
7018 offset_int mask = wi::mask <offset_int> (LOG2_BITS_PER_UNIT, false);
7019 offset_int tem = bit_offset.and_not (mask);
7020 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
7021 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
7022 bit_offset -= tem;
7023 tem = wi::arshift (tem, LOG2_BITS_PER_UNIT);
7024 offset = size_binop (PLUS_EXPR, offset,
7025 wide_int_to_tree (sizetype, tem));
7028 *pbitpos = bit_offset.to_shwi ();
7029 *poffset = offset;
7032 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
7033 if (mode == VOIDmode
7034 && blkmode_bitfield
7035 && (*pbitpos % BITS_PER_UNIT) == 0
7036 && (*pbitsize % BITS_PER_UNIT) == 0)
7037 *pmode = BLKmode;
7038 else
7039 *pmode = mode;
7041 return exp;
7044 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
7046 static unsigned HOST_WIDE_INT
7047 target_align (const_tree target)
7049 /* We might have a chain of nested references with intermediate misaligning
7050 bitfields components, so need to recurse to find out. */
7052 unsigned HOST_WIDE_INT this_align, outer_align;
7054 switch (TREE_CODE (target))
7056 case BIT_FIELD_REF:
7057 return 1;
7059 case COMPONENT_REF:
7060 this_align = DECL_ALIGN (TREE_OPERAND (target, 1));
7061 outer_align = target_align (TREE_OPERAND (target, 0));
7062 return MIN (this_align, outer_align);
7064 case ARRAY_REF:
7065 case ARRAY_RANGE_REF:
7066 this_align = TYPE_ALIGN (TREE_TYPE (target));
7067 outer_align = target_align (TREE_OPERAND (target, 0));
7068 return MIN (this_align, outer_align);
7070 CASE_CONVERT:
7071 case NON_LVALUE_EXPR:
7072 case VIEW_CONVERT_EXPR:
7073 this_align = TYPE_ALIGN (TREE_TYPE (target));
7074 outer_align = target_align (TREE_OPERAND (target, 0));
7075 return MAX (this_align, outer_align);
7077 default:
7078 return TYPE_ALIGN (TREE_TYPE (target));
7083 /* Given an rtx VALUE that may contain additions and multiplications, return
7084 an equivalent value that just refers to a register, memory, or constant.
7085 This is done by generating instructions to perform the arithmetic and
7086 returning a pseudo-register containing the value.
7088 The returned value may be a REG, SUBREG, MEM or constant. */
7091 force_operand (rtx value, rtx target)
7093 rtx op1, op2;
7094 /* Use subtarget as the target for operand 0 of a binary operation. */
7095 rtx subtarget = get_subtarget (target);
7096 enum rtx_code code = GET_CODE (value);
7098 /* Check for subreg applied to an expression produced by loop optimizer. */
7099 if (code == SUBREG
7100 && !REG_P (SUBREG_REG (value))
7101 && !MEM_P (SUBREG_REG (value)))
7103 value
7104 = simplify_gen_subreg (GET_MODE (value),
7105 force_reg (GET_MODE (SUBREG_REG (value)),
7106 force_operand (SUBREG_REG (value),
7107 NULL_RTX)),
7108 GET_MODE (SUBREG_REG (value)),
7109 SUBREG_BYTE (value));
7110 code = GET_CODE (value);
7113 /* Check for a PIC address load. */
7114 if ((code == PLUS || code == MINUS)
7115 && XEXP (value, 0) == pic_offset_table_rtx
7116 && (GET_CODE (XEXP (value, 1)) == SYMBOL_REF
7117 || GET_CODE (XEXP (value, 1)) == LABEL_REF
7118 || GET_CODE (XEXP (value, 1)) == CONST))
7120 if (!subtarget)
7121 subtarget = gen_reg_rtx (GET_MODE (value));
7122 emit_move_insn (subtarget, value);
7123 return subtarget;
7126 if (ARITHMETIC_P (value))
7128 op2 = XEXP (value, 1);
7129 if (!CONSTANT_P (op2) && !(REG_P (op2) && op2 != subtarget))
7130 subtarget = 0;
7131 if (code == MINUS && CONST_INT_P (op2))
7133 code = PLUS;
7134 op2 = negate_rtx (GET_MODE (value), op2);
7137 /* Check for an addition with OP2 a constant integer and our first
7138 operand a PLUS of a virtual register and something else. In that
7139 case, we want to emit the sum of the virtual register and the
7140 constant first and then add the other value. This allows virtual
7141 register instantiation to simply modify the constant rather than
7142 creating another one around this addition. */
7143 if (code == PLUS && CONST_INT_P (op2)
7144 && GET_CODE (XEXP (value, 0)) == PLUS
7145 && REG_P (XEXP (XEXP (value, 0), 0))
7146 && REGNO (XEXP (XEXP (value, 0), 0)) >= FIRST_VIRTUAL_REGISTER
7147 && REGNO (XEXP (XEXP (value, 0), 0)) <= LAST_VIRTUAL_REGISTER)
7149 rtx temp = expand_simple_binop (GET_MODE (value), code,
7150 XEXP (XEXP (value, 0), 0), op2,
7151 subtarget, 0, OPTAB_LIB_WIDEN);
7152 return expand_simple_binop (GET_MODE (value), code, temp,
7153 force_operand (XEXP (XEXP (value,
7154 0), 1), 0),
7155 target, 0, OPTAB_LIB_WIDEN);
7158 op1 = force_operand (XEXP (value, 0), subtarget);
7159 op2 = force_operand (op2, NULL_RTX);
7160 switch (code)
7162 case MULT:
7163 return expand_mult (GET_MODE (value), op1, op2, target, 1);
7164 case DIV:
7165 if (!INTEGRAL_MODE_P (GET_MODE (value)))
7166 return expand_simple_binop (GET_MODE (value), code, op1, op2,
7167 target, 1, OPTAB_LIB_WIDEN);
7168 else
7169 return expand_divmod (0,
7170 FLOAT_MODE_P (GET_MODE (value))
7171 ? RDIV_EXPR : TRUNC_DIV_EXPR,
7172 GET_MODE (value), op1, op2, target, 0);
7173 case MOD:
7174 return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
7175 target, 0);
7176 case UDIV:
7177 return expand_divmod (0, TRUNC_DIV_EXPR, GET_MODE (value), op1, op2,
7178 target, 1);
7179 case UMOD:
7180 return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
7181 target, 1);
7182 case ASHIFTRT:
7183 return expand_simple_binop (GET_MODE (value), code, op1, op2,
7184 target, 0, OPTAB_LIB_WIDEN);
7185 default:
7186 return expand_simple_binop (GET_MODE (value), code, op1, op2,
7187 target, 1, OPTAB_LIB_WIDEN);
7190 if (UNARY_P (value))
7192 if (!target)
7193 target = gen_reg_rtx (GET_MODE (value));
7194 op1 = force_operand (XEXP (value, 0), NULL_RTX);
7195 switch (code)
7197 case ZERO_EXTEND:
7198 case SIGN_EXTEND:
7199 case TRUNCATE:
7200 case FLOAT_EXTEND:
7201 case FLOAT_TRUNCATE:
7202 convert_move (target, op1, code == ZERO_EXTEND);
7203 return target;
7205 case FIX:
7206 case UNSIGNED_FIX:
7207 expand_fix (target, op1, code == UNSIGNED_FIX);
7208 return target;
7210 case FLOAT:
7211 case UNSIGNED_FLOAT:
7212 expand_float (target, op1, code == UNSIGNED_FLOAT);
7213 return target;
7215 default:
7216 return expand_simple_unop (GET_MODE (value), code, op1, target, 0);
7220 #ifdef INSN_SCHEDULING
7221 /* On machines that have insn scheduling, we want all memory reference to be
7222 explicit, so we need to deal with such paradoxical SUBREGs. */
7223 if (paradoxical_subreg_p (value) && MEM_P (SUBREG_REG (value)))
7224 value
7225 = simplify_gen_subreg (GET_MODE (value),
7226 force_reg (GET_MODE (SUBREG_REG (value)),
7227 force_operand (SUBREG_REG (value),
7228 NULL_RTX)),
7229 GET_MODE (SUBREG_REG (value)),
7230 SUBREG_BYTE (value));
7231 #endif
7233 return value;
7236 /* Subroutine of expand_expr: return nonzero iff there is no way that
7237 EXP can reference X, which is being modified. TOP_P is nonzero if this
7238 call is going to be used to determine whether we need a temporary
7239 for EXP, as opposed to a recursive call to this function.
7241 It is always safe for this routine to return zero since it merely
7242 searches for optimization opportunities. */
7245 safe_from_p (const_rtx x, tree exp, int top_p)
7247 rtx exp_rtl = 0;
7248 int i, nops;
7250 if (x == 0
7251 /* If EXP has varying size, we MUST use a target since we currently
7252 have no way of allocating temporaries of variable size
7253 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7254 So we assume here that something at a higher level has prevented a
7255 clash. This is somewhat bogus, but the best we can do. Only
7256 do this when X is BLKmode and when we are at the top level. */
7257 || (top_p && TREE_TYPE (exp) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp))
7258 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) != INTEGER_CST
7259 && (TREE_CODE (TREE_TYPE (exp)) != ARRAY_TYPE
7260 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)) == NULL_TREE
7261 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)))
7262 != INTEGER_CST)
7263 && GET_MODE (x) == BLKmode)
7264 /* If X is in the outgoing argument area, it is always safe. */
7265 || (MEM_P (x)
7266 && (XEXP (x, 0) == virtual_outgoing_args_rtx
7267 || (GET_CODE (XEXP (x, 0)) == PLUS
7268 && XEXP (XEXP (x, 0), 0) == virtual_outgoing_args_rtx))))
7269 return 1;
7271 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7272 find the underlying pseudo. */
7273 if (GET_CODE (x) == SUBREG)
7275 x = SUBREG_REG (x);
7276 if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
7277 return 0;
7280 /* Now look at our tree code and possibly recurse. */
7281 switch (TREE_CODE_CLASS (TREE_CODE (exp)))
7283 case tcc_declaration:
7284 exp_rtl = DECL_RTL_IF_SET (exp);
7285 break;
7287 case tcc_constant:
7288 return 1;
7290 case tcc_exceptional:
7291 if (TREE_CODE (exp) == TREE_LIST)
7293 while (1)
7295 if (TREE_VALUE (exp) && !safe_from_p (x, TREE_VALUE (exp), 0))
7296 return 0;
7297 exp = TREE_CHAIN (exp);
7298 if (!exp)
7299 return 1;
7300 if (TREE_CODE (exp) != TREE_LIST)
7301 return safe_from_p (x, exp, 0);
7304 else if (TREE_CODE (exp) == CONSTRUCTOR)
7306 constructor_elt *ce;
7307 unsigned HOST_WIDE_INT idx;
7309 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp), idx, ce)
7310 if ((ce->index != NULL_TREE && !safe_from_p (x, ce->index, 0))
7311 || !safe_from_p (x, ce->value, 0))
7312 return 0;
7313 return 1;
7315 else if (TREE_CODE (exp) == ERROR_MARK)
7316 return 1; /* An already-visited SAVE_EXPR? */
7317 else
7318 return 0;
7320 case tcc_statement:
7321 /* The only case we look at here is the DECL_INITIAL inside a
7322 DECL_EXPR. */
7323 return (TREE_CODE (exp) != DECL_EXPR
7324 || TREE_CODE (DECL_EXPR_DECL (exp)) != VAR_DECL
7325 || !DECL_INITIAL (DECL_EXPR_DECL (exp))
7326 || safe_from_p (x, DECL_INITIAL (DECL_EXPR_DECL (exp)), 0));
7328 case tcc_binary:
7329 case tcc_comparison:
7330 if (!safe_from_p (x, TREE_OPERAND (exp, 1), 0))
7331 return 0;
7332 /* Fall through. */
7334 case tcc_unary:
7335 return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
7337 case tcc_expression:
7338 case tcc_reference:
7339 case tcc_vl_exp:
7340 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7341 the expression. If it is set, we conflict iff we are that rtx or
7342 both are in memory. Otherwise, we check all operands of the
7343 expression recursively. */
7345 switch (TREE_CODE (exp))
7347 case ADDR_EXPR:
7348 /* If the operand is static or we are static, we can't conflict.
7349 Likewise if we don't conflict with the operand at all. */
7350 if (staticp (TREE_OPERAND (exp, 0))
7351 || TREE_STATIC (exp)
7352 || safe_from_p (x, TREE_OPERAND (exp, 0), 0))
7353 return 1;
7355 /* Otherwise, the only way this can conflict is if we are taking
7356 the address of a DECL a that address if part of X, which is
7357 very rare. */
7358 exp = TREE_OPERAND (exp, 0);
7359 if (DECL_P (exp))
7361 if (!DECL_RTL_SET_P (exp)
7362 || !MEM_P (DECL_RTL (exp)))
7363 return 0;
7364 else
7365 exp_rtl = XEXP (DECL_RTL (exp), 0);
7367 break;
7369 case MEM_REF:
7370 if (MEM_P (x)
7371 && alias_sets_conflict_p (MEM_ALIAS_SET (x),
7372 get_alias_set (exp)))
7373 return 0;
7374 break;
7376 case CALL_EXPR:
7377 /* Assume that the call will clobber all hard registers and
7378 all of memory. */
7379 if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
7380 || MEM_P (x))
7381 return 0;
7382 break;
7384 case WITH_CLEANUP_EXPR:
7385 case CLEANUP_POINT_EXPR:
7386 /* Lowered by gimplify.c. */
7387 gcc_unreachable ();
7389 case SAVE_EXPR:
7390 return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
7392 default:
7393 break;
7396 /* If we have an rtx, we do not need to scan our operands. */
7397 if (exp_rtl)
7398 break;
7400 nops = TREE_OPERAND_LENGTH (exp);
7401 for (i = 0; i < nops; i++)
7402 if (TREE_OPERAND (exp, i) != 0
7403 && ! safe_from_p (x, TREE_OPERAND (exp, i), 0))
7404 return 0;
7406 break;
7408 case tcc_type:
7409 /* Should never get a type here. */
7410 gcc_unreachable ();
7413 /* If we have an rtl, find any enclosed object. Then see if we conflict
7414 with it. */
7415 if (exp_rtl)
7417 if (GET_CODE (exp_rtl) == SUBREG)
7419 exp_rtl = SUBREG_REG (exp_rtl);
7420 if (REG_P (exp_rtl)
7421 && REGNO (exp_rtl) < FIRST_PSEUDO_REGISTER)
7422 return 0;
7425 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7426 are memory and they conflict. */
7427 return ! (rtx_equal_p (x, exp_rtl)
7428 || (MEM_P (x) && MEM_P (exp_rtl)
7429 && true_dependence (exp_rtl, VOIDmode, x)));
7432 /* If we reach here, it is safe. */
7433 return 1;
7437 /* Return the highest power of two that EXP is known to be a multiple of.
7438 This is used in updating alignment of MEMs in array references. */
7440 unsigned HOST_WIDE_INT
7441 highest_pow2_factor (const_tree exp)
7443 unsigned HOST_WIDE_INT ret;
7444 int trailing_zeros = tree_ctz (exp);
7445 if (trailing_zeros >= HOST_BITS_PER_WIDE_INT)
7446 return BIGGEST_ALIGNMENT;
7447 ret = (unsigned HOST_WIDE_INT) 1 << trailing_zeros;
7448 if (ret > BIGGEST_ALIGNMENT)
7449 return BIGGEST_ALIGNMENT;
7450 return ret;
7453 /* Similar, except that the alignment requirements of TARGET are
7454 taken into account. Assume it is at least as aligned as its
7455 type, unless it is a COMPONENT_REF in which case the layout of
7456 the structure gives the alignment. */
7458 static unsigned HOST_WIDE_INT
7459 highest_pow2_factor_for_target (const_tree target, const_tree exp)
7461 unsigned HOST_WIDE_INT talign = target_align (target) / BITS_PER_UNIT;
7462 unsigned HOST_WIDE_INT factor = highest_pow2_factor (exp);
7464 return MAX (factor, talign);
7467 /* Convert the tree comparison code TCODE to the rtl one where the
7468 signedness is UNSIGNEDP. */
7470 static enum rtx_code
7471 convert_tree_comp_to_rtx (enum tree_code tcode, int unsignedp)
7473 enum rtx_code code;
7474 switch (tcode)
7476 case EQ_EXPR:
7477 code = EQ;
7478 break;
7479 case NE_EXPR:
7480 code = NE;
7481 break;
7482 case LT_EXPR:
7483 code = unsignedp ? LTU : LT;
7484 break;
7485 case LE_EXPR:
7486 code = unsignedp ? LEU : LE;
7487 break;
7488 case GT_EXPR:
7489 code = unsignedp ? GTU : GT;
7490 break;
7491 case GE_EXPR:
7492 code = unsignedp ? GEU : GE;
7493 break;
7494 case UNORDERED_EXPR:
7495 code = UNORDERED;
7496 break;
7497 case ORDERED_EXPR:
7498 code = ORDERED;
7499 break;
7500 case UNLT_EXPR:
7501 code = UNLT;
7502 break;
7503 case UNLE_EXPR:
7504 code = UNLE;
7505 break;
7506 case UNGT_EXPR:
7507 code = UNGT;
7508 break;
7509 case UNGE_EXPR:
7510 code = UNGE;
7511 break;
7512 case UNEQ_EXPR:
7513 code = UNEQ;
7514 break;
7515 case LTGT_EXPR:
7516 code = LTGT;
7517 break;
7519 default:
7520 gcc_unreachable ();
7522 return code;
7525 /* Subroutine of expand_expr. Expand the two operands of a binary
7526 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7527 The value may be stored in TARGET if TARGET is nonzero. The
7528 MODIFIER argument is as documented by expand_expr. */
7530 void
7531 expand_operands (tree exp0, tree exp1, rtx target, rtx *op0, rtx *op1,
7532 enum expand_modifier modifier)
7534 if (! safe_from_p (target, exp1, 1))
7535 target = 0;
7536 if (operand_equal_p (exp0, exp1, 0))
7538 *op0 = expand_expr (exp0, target, VOIDmode, modifier);
7539 *op1 = copy_rtx (*op0);
7541 else
7543 /* If we need to preserve evaluation order, copy exp0 into its own
7544 temporary variable so that it can't be clobbered by exp1. */
7545 if (flag_evaluation_order && TREE_SIDE_EFFECTS (exp1))
7546 exp0 = save_expr (exp0);
7547 *op0 = expand_expr (exp0, target, VOIDmode, modifier);
7548 *op1 = expand_expr (exp1, NULL_RTX, VOIDmode, modifier);
7553 /* Return a MEM that contains constant EXP. DEFER is as for
7554 output_constant_def and MODIFIER is as for expand_expr. */
7556 static rtx
7557 expand_expr_constant (tree exp, int defer, enum expand_modifier modifier)
7559 rtx mem;
7561 mem = output_constant_def (exp, defer);
7562 if (modifier != EXPAND_INITIALIZER)
7563 mem = use_anchored_address (mem);
7564 return mem;
7567 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7568 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7570 static rtx
7571 expand_expr_addr_expr_1 (tree exp, rtx target, machine_mode tmode,
7572 enum expand_modifier modifier, addr_space_t as)
7574 rtx result, subtarget;
7575 tree inner, offset;
7576 HOST_WIDE_INT bitsize, bitpos;
7577 int unsignedp, reversep, volatilep = 0;
7578 machine_mode mode1;
7580 /* If we are taking the address of a constant and are at the top level,
7581 we have to use output_constant_def since we can't call force_const_mem
7582 at top level. */
7583 /* ??? This should be considered a front-end bug. We should not be
7584 generating ADDR_EXPR of something that isn't an LVALUE. The only
7585 exception here is STRING_CST. */
7586 if (CONSTANT_CLASS_P (exp))
7588 result = XEXP (expand_expr_constant (exp, 0, modifier), 0);
7589 if (modifier < EXPAND_SUM)
7590 result = force_operand (result, target);
7591 return result;
7594 /* Everything must be something allowed by is_gimple_addressable. */
7595 switch (TREE_CODE (exp))
7597 case INDIRECT_REF:
7598 /* This case will happen via recursion for &a->b. */
7599 return expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
7601 case MEM_REF:
7603 tree tem = TREE_OPERAND (exp, 0);
7604 if (!integer_zerop (TREE_OPERAND (exp, 1)))
7605 tem = fold_build_pointer_plus (tem, TREE_OPERAND (exp, 1));
7606 return expand_expr (tem, target, tmode, modifier);
7609 case CONST_DECL:
7610 /* Expand the initializer like constants above. */
7611 result = XEXP (expand_expr_constant (DECL_INITIAL (exp),
7612 0, modifier), 0);
7613 if (modifier < EXPAND_SUM)
7614 result = force_operand (result, target);
7615 return result;
7617 case REALPART_EXPR:
7618 /* The real part of the complex number is always first, therefore
7619 the address is the same as the address of the parent object. */
7620 offset = 0;
7621 bitpos = 0;
7622 inner = TREE_OPERAND (exp, 0);
7623 break;
7625 case IMAGPART_EXPR:
7626 /* The imaginary part of the complex number is always second.
7627 The expression is therefore always offset by the size of the
7628 scalar type. */
7629 offset = 0;
7630 bitpos = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp)));
7631 inner = TREE_OPERAND (exp, 0);
7632 break;
7634 case COMPOUND_LITERAL_EXPR:
7635 /* Allow COMPOUND_LITERAL_EXPR in initializers or coming from
7636 initializers, if e.g. rtl_for_decl_init is called on DECL_INITIAL
7637 with COMPOUND_LITERAL_EXPRs in it, or ARRAY_REF on a const static
7638 array with address of COMPOUND_LITERAL_EXPR in DECL_INITIAL;
7639 the initializers aren't gimplified. */
7640 if (COMPOUND_LITERAL_EXPR_DECL (exp)
7641 && TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (exp)))
7642 return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp),
7643 target, tmode, modifier, as);
7644 /* FALLTHRU */
7645 default:
7646 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7647 expand_expr, as that can have various side effects; LABEL_DECLs for
7648 example, may not have their DECL_RTL set yet. Expand the rtl of
7649 CONSTRUCTORs too, which should yield a memory reference for the
7650 constructor's contents. Assume language specific tree nodes can
7651 be expanded in some interesting way. */
7652 gcc_assert (TREE_CODE (exp) < LAST_AND_UNUSED_TREE_CODE);
7653 if (DECL_P (exp)
7654 || TREE_CODE (exp) == CONSTRUCTOR
7655 || TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
7657 result = expand_expr (exp, target, tmode,
7658 modifier == EXPAND_INITIALIZER
7659 ? EXPAND_INITIALIZER : EXPAND_CONST_ADDRESS);
7661 /* If the DECL isn't in memory, then the DECL wasn't properly
7662 marked TREE_ADDRESSABLE, which will be either a front-end
7663 or a tree optimizer bug. */
7665 gcc_assert (MEM_P (result));
7666 result = XEXP (result, 0);
7668 /* ??? Is this needed anymore? */
7669 if (DECL_P (exp))
7670 TREE_USED (exp) = 1;
7672 if (modifier != EXPAND_INITIALIZER
7673 && modifier != EXPAND_CONST_ADDRESS
7674 && modifier != EXPAND_SUM)
7675 result = force_operand (result, target);
7676 return result;
7679 /* Pass FALSE as the last argument to get_inner_reference although
7680 we are expanding to RTL. The rationale is that we know how to
7681 handle "aligning nodes" here: we can just bypass them because
7682 they won't change the final object whose address will be returned
7683 (they actually exist only for that purpose). */
7684 inner = get_inner_reference (exp, &bitsize, &bitpos, &offset, &mode1,
7685 &unsignedp, &reversep, &volatilep, false);
7686 break;
7689 /* We must have made progress. */
7690 gcc_assert (inner != exp);
7692 subtarget = offset || bitpos ? NULL_RTX : target;
7693 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7694 inner alignment, force the inner to be sufficiently aligned. */
7695 if (CONSTANT_CLASS_P (inner)
7696 && TYPE_ALIGN (TREE_TYPE (inner)) < TYPE_ALIGN (TREE_TYPE (exp)))
7698 inner = copy_node (inner);
7699 TREE_TYPE (inner) = copy_node (TREE_TYPE (inner));
7700 TYPE_ALIGN (TREE_TYPE (inner)) = TYPE_ALIGN (TREE_TYPE (exp));
7701 TYPE_USER_ALIGN (TREE_TYPE (inner)) = 1;
7703 result = expand_expr_addr_expr_1 (inner, subtarget, tmode, modifier, as);
7705 if (offset)
7707 rtx tmp;
7709 if (modifier != EXPAND_NORMAL)
7710 result = force_operand (result, NULL);
7711 tmp = expand_expr (offset, NULL_RTX, tmode,
7712 modifier == EXPAND_INITIALIZER
7713 ? EXPAND_INITIALIZER : EXPAND_NORMAL);
7715 /* expand_expr is allowed to return an object in a mode other
7716 than TMODE. If it did, we need to convert. */
7717 if (GET_MODE (tmp) != VOIDmode && tmode != GET_MODE (tmp))
7718 tmp = convert_modes (tmode, GET_MODE (tmp),
7719 tmp, TYPE_UNSIGNED (TREE_TYPE (offset)));
7720 result = convert_memory_address_addr_space (tmode, result, as);
7721 tmp = convert_memory_address_addr_space (tmode, tmp, as);
7723 if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
7724 result = simplify_gen_binary (PLUS, tmode, result, tmp);
7725 else
7727 subtarget = bitpos ? NULL_RTX : target;
7728 result = expand_simple_binop (tmode, PLUS, result, tmp, subtarget,
7729 1, OPTAB_LIB_WIDEN);
7733 if (bitpos)
7735 /* Someone beforehand should have rejected taking the address
7736 of such an object. */
7737 gcc_assert ((bitpos % BITS_PER_UNIT) == 0);
7739 result = convert_memory_address_addr_space (tmode, result, as);
7740 result = plus_constant (tmode, result, bitpos / BITS_PER_UNIT);
7741 if (modifier < EXPAND_SUM)
7742 result = force_operand (result, target);
7745 return result;
7748 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7749 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7751 static rtx
7752 expand_expr_addr_expr (tree exp, rtx target, machine_mode tmode,
7753 enum expand_modifier modifier)
7755 addr_space_t as = ADDR_SPACE_GENERIC;
7756 machine_mode address_mode = Pmode;
7757 machine_mode pointer_mode = ptr_mode;
7758 machine_mode rmode;
7759 rtx result;
7761 /* Target mode of VOIDmode says "whatever's natural". */
7762 if (tmode == VOIDmode)
7763 tmode = TYPE_MODE (TREE_TYPE (exp));
7765 if (POINTER_TYPE_P (TREE_TYPE (exp)))
7767 as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)));
7768 address_mode = targetm.addr_space.address_mode (as);
7769 pointer_mode = targetm.addr_space.pointer_mode (as);
7772 /* We can get called with some Weird Things if the user does silliness
7773 like "(short) &a". In that case, convert_memory_address won't do
7774 the right thing, so ignore the given target mode. */
7775 if (tmode != address_mode && tmode != pointer_mode)
7776 tmode = address_mode;
7778 result = expand_expr_addr_expr_1 (TREE_OPERAND (exp, 0), target,
7779 tmode, modifier, as);
7781 /* Despite expand_expr claims concerning ignoring TMODE when not
7782 strictly convenient, stuff breaks if we don't honor it. Note
7783 that combined with the above, we only do this for pointer modes. */
7784 rmode = GET_MODE (result);
7785 if (rmode == VOIDmode)
7786 rmode = tmode;
7787 if (rmode != tmode)
7788 result = convert_memory_address_addr_space (tmode, result, as);
7790 return result;
7793 /* Generate code for computing CONSTRUCTOR EXP.
7794 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7795 is TRUE, instead of creating a temporary variable in memory
7796 NULL is returned and the caller needs to handle it differently. */
7798 static rtx
7799 expand_constructor (tree exp, rtx target, enum expand_modifier modifier,
7800 bool avoid_temp_mem)
7802 tree type = TREE_TYPE (exp);
7803 machine_mode mode = TYPE_MODE (type);
7805 /* Try to avoid creating a temporary at all. This is possible
7806 if all of the initializer is zero.
7807 FIXME: try to handle all [0..255] initializers we can handle
7808 with memset. */
7809 if (TREE_STATIC (exp)
7810 && !TREE_ADDRESSABLE (exp)
7811 && target != 0 && mode == BLKmode
7812 && all_zeros_p (exp))
7814 clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
7815 return target;
7818 /* All elts simple constants => refer to a constant in memory. But
7819 if this is a non-BLKmode mode, let it store a field at a time
7820 since that should make a CONST_INT, CONST_WIDE_INT or
7821 CONST_DOUBLE when we fold. Likewise, if we have a target we can
7822 use, it is best to store directly into the target unless the type
7823 is large enough that memcpy will be used. If we are making an
7824 initializer and all operands are constant, put it in memory as
7825 well.
7827 FIXME: Avoid trying to fill vector constructors piece-meal.
7828 Output them with output_constant_def below unless we're sure
7829 they're zeros. This should go away when vector initializers
7830 are treated like VECTOR_CST instead of arrays. */
7831 if ((TREE_STATIC (exp)
7832 && ((mode == BLKmode
7833 && ! (target != 0 && safe_from_p (target, exp, 1)))
7834 || TREE_ADDRESSABLE (exp)
7835 || (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type))
7836 && (! can_move_by_pieces
7837 (tree_to_uhwi (TYPE_SIZE_UNIT (type)),
7838 TYPE_ALIGN (type)))
7839 && ! mostly_zeros_p (exp))))
7840 || ((modifier == EXPAND_INITIALIZER || modifier == EXPAND_CONST_ADDRESS)
7841 && TREE_CONSTANT (exp)))
7843 rtx constructor;
7845 if (avoid_temp_mem)
7846 return NULL_RTX;
7848 constructor = expand_expr_constant (exp, 1, modifier);
7850 if (modifier != EXPAND_CONST_ADDRESS
7851 && modifier != EXPAND_INITIALIZER
7852 && modifier != EXPAND_SUM)
7853 constructor = validize_mem (constructor);
7855 return constructor;
7858 /* Handle calls that pass values in multiple non-contiguous
7859 locations. The Irix 6 ABI has examples of this. */
7860 if (target == 0 || ! safe_from_p (target, exp, 1)
7861 || GET_CODE (target) == PARALLEL || modifier == EXPAND_STACK_PARM)
7863 if (avoid_temp_mem)
7864 return NULL_RTX;
7866 target = assign_temp (type, TREE_ADDRESSABLE (exp), 1);
7869 store_constructor (exp, target, 0, int_expr_size (exp), false);
7870 return target;
7874 /* expand_expr: generate code for computing expression EXP.
7875 An rtx for the computed value is returned. The value is never null.
7876 In the case of a void EXP, const0_rtx is returned.
7878 The value may be stored in TARGET if TARGET is nonzero.
7879 TARGET is just a suggestion; callers must assume that
7880 the rtx returned may not be the same as TARGET.
7882 If TARGET is CONST0_RTX, it means that the value will be ignored.
7884 If TMODE is not VOIDmode, it suggests generating the
7885 result in mode TMODE. But this is done only when convenient.
7886 Otherwise, TMODE is ignored and the value generated in its natural mode.
7887 TMODE is just a suggestion; callers must assume that
7888 the rtx returned may not have mode TMODE.
7890 Note that TARGET may have neither TMODE nor MODE. In that case, it
7891 probably will not be used.
7893 If MODIFIER is EXPAND_SUM then when EXP is an addition
7894 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
7895 or a nest of (PLUS ...) and (MINUS ...) where the terms are
7896 products as above, or REG or MEM, or constant.
7897 Ordinarily in such cases we would output mul or add instructions
7898 and then return a pseudo reg containing the sum.
7900 EXPAND_INITIALIZER is much like EXPAND_SUM except that
7901 it also marks a label as absolutely required (it can't be dead).
7902 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
7903 This is used for outputting expressions used in initializers.
7905 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
7906 with a constant address even if that address is not normally legitimate.
7907 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
7909 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
7910 a call parameter. Such targets require special care as we haven't yet
7911 marked TARGET so that it's safe from being trashed by libcalls. We
7912 don't want to use TARGET for anything but the final result;
7913 Intermediate values must go elsewhere. Additionally, calls to
7914 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
7916 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
7917 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
7918 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
7919 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
7920 recursively.
7922 If INNER_REFERENCE_P is true, we are expanding an inner reference.
7923 In this case, we don't adjust a returned MEM rtx that wouldn't be
7924 sufficiently aligned for its mode; instead, it's up to the caller
7925 to deal with it afterwards. This is used to make sure that unaligned
7926 base objects for which out-of-bounds accesses are supported, for
7927 example record types with trailing arrays, aren't realigned behind
7928 the back of the caller.
7929 The normal operating mode is to pass FALSE for this parameter. */
7932 expand_expr_real (tree exp, rtx target, machine_mode tmode,
7933 enum expand_modifier modifier, rtx *alt_rtl,
7934 bool inner_reference_p)
7936 rtx ret;
7938 /* Handle ERROR_MARK before anybody tries to access its type. */
7939 if (TREE_CODE (exp) == ERROR_MARK
7940 || (TREE_CODE (TREE_TYPE (exp)) == ERROR_MARK))
7942 ret = CONST0_RTX (tmode);
7943 return ret ? ret : const0_rtx;
7946 ret = expand_expr_real_1 (exp, target, tmode, modifier, alt_rtl,
7947 inner_reference_p);
7948 return ret;
7951 /* Try to expand the conditional expression which is represented by
7952 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If it succeeds
7953 return the rtl reg which represents the result. Otherwise return
7954 NULL_RTX. */
7956 static rtx
7957 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED,
7958 tree treeop1 ATTRIBUTE_UNUSED,
7959 tree treeop2 ATTRIBUTE_UNUSED)
7961 rtx insn;
7962 rtx op00, op01, op1, op2;
7963 enum rtx_code comparison_code;
7964 machine_mode comparison_mode;
7965 gimple *srcstmt;
7966 rtx temp;
7967 tree type = TREE_TYPE (treeop1);
7968 int unsignedp = TYPE_UNSIGNED (type);
7969 machine_mode mode = TYPE_MODE (type);
7970 machine_mode orig_mode = mode;
7972 /* If we cannot do a conditional move on the mode, try doing it
7973 with the promoted mode. */
7974 if (!can_conditionally_move_p (mode))
7976 mode = promote_mode (type, mode, &unsignedp);
7977 if (!can_conditionally_move_p (mode))
7978 return NULL_RTX;
7979 temp = assign_temp (type, 0, 0); /* Use promoted mode for temp. */
7981 else
7982 temp = assign_temp (type, 0, 1);
7984 start_sequence ();
7985 expand_operands (treeop1, treeop2,
7986 temp, &op1, &op2, EXPAND_NORMAL);
7988 if (TREE_CODE (treeop0) == SSA_NAME
7989 && (srcstmt = get_def_for_expr_class (treeop0, tcc_comparison)))
7991 tree type = TREE_TYPE (gimple_assign_rhs1 (srcstmt));
7992 enum tree_code cmpcode = gimple_assign_rhs_code (srcstmt);
7993 op00 = expand_normal (gimple_assign_rhs1 (srcstmt));
7994 op01 = expand_normal (gimple_assign_rhs2 (srcstmt));
7995 comparison_mode = TYPE_MODE (type);
7996 unsignedp = TYPE_UNSIGNED (type);
7997 comparison_code = convert_tree_comp_to_rtx (cmpcode, unsignedp);
7999 else if (COMPARISON_CLASS_P (treeop0))
8001 tree type = TREE_TYPE (TREE_OPERAND (treeop0, 0));
8002 enum tree_code cmpcode = TREE_CODE (treeop0);
8003 op00 = expand_normal (TREE_OPERAND (treeop0, 0));
8004 op01 = expand_normal (TREE_OPERAND (treeop0, 1));
8005 unsignedp = TYPE_UNSIGNED (type);
8006 comparison_mode = TYPE_MODE (type);
8007 comparison_code = convert_tree_comp_to_rtx (cmpcode, unsignedp);
8009 else
8011 op00 = expand_normal (treeop0);
8012 op01 = const0_rtx;
8013 comparison_code = NE;
8014 comparison_mode = GET_MODE (op00);
8015 if (comparison_mode == VOIDmode)
8016 comparison_mode = TYPE_MODE (TREE_TYPE (treeop0));
8019 if (GET_MODE (op1) != mode)
8020 op1 = gen_lowpart (mode, op1);
8022 if (GET_MODE (op2) != mode)
8023 op2 = gen_lowpart (mode, op2);
8025 /* Try to emit the conditional move. */
8026 insn = emit_conditional_move (temp, comparison_code,
8027 op00, op01, comparison_mode,
8028 op1, op2, mode,
8029 unsignedp);
8031 /* If we could do the conditional move, emit the sequence,
8032 and return. */
8033 if (insn)
8035 rtx_insn *seq = get_insns ();
8036 end_sequence ();
8037 emit_insn (seq);
8038 return convert_modes (orig_mode, mode, temp, 0);
8041 /* Otherwise discard the sequence and fall back to code with
8042 branches. */
8043 end_sequence ();
8044 return NULL_RTX;
8048 expand_expr_real_2 (sepops ops, rtx target, machine_mode tmode,
8049 enum expand_modifier modifier)
8051 rtx op0, op1, op2, temp;
8052 rtx_code_label *lab;
8053 tree type;
8054 int unsignedp;
8055 machine_mode mode;
8056 enum tree_code code = ops->code;
8057 optab this_optab;
8058 rtx subtarget, original_target;
8059 int ignore;
8060 bool reduce_bit_field;
8061 location_t loc = ops->location;
8062 tree treeop0, treeop1, treeop2;
8063 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
8064 ? reduce_to_bit_field_precision ((expr), \
8065 target, \
8066 type) \
8067 : (expr))
8069 type = ops->type;
8070 mode = TYPE_MODE (type);
8071 unsignedp = TYPE_UNSIGNED (type);
8073 treeop0 = ops->op0;
8074 treeop1 = ops->op1;
8075 treeop2 = ops->op2;
8077 /* We should be called only on simple (binary or unary) expressions,
8078 exactly those that are valid in gimple expressions that aren't
8079 GIMPLE_SINGLE_RHS (or invalid). */
8080 gcc_assert (get_gimple_rhs_class (code) == GIMPLE_UNARY_RHS
8081 || get_gimple_rhs_class (code) == GIMPLE_BINARY_RHS
8082 || get_gimple_rhs_class (code) == GIMPLE_TERNARY_RHS);
8084 ignore = (target == const0_rtx
8085 || ((CONVERT_EXPR_CODE_P (code)
8086 || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
8087 && TREE_CODE (type) == VOID_TYPE));
8089 /* We should be called only if we need the result. */
8090 gcc_assert (!ignore);
8092 /* An operation in what may be a bit-field type needs the
8093 result to be reduced to the precision of the bit-field type,
8094 which is narrower than that of the type's mode. */
8095 reduce_bit_field = (INTEGRAL_TYPE_P (type)
8096 && GET_MODE_PRECISION (mode) > TYPE_PRECISION (type));
8098 if (reduce_bit_field && modifier == EXPAND_STACK_PARM)
8099 target = 0;
8101 /* Use subtarget as the target for operand 0 of a binary operation. */
8102 subtarget = get_subtarget (target);
8103 original_target = target;
8105 switch (code)
8107 case NON_LVALUE_EXPR:
8108 case PAREN_EXPR:
8109 CASE_CONVERT:
8110 if (treeop0 == error_mark_node)
8111 return const0_rtx;
8113 if (TREE_CODE (type) == UNION_TYPE)
8115 tree valtype = TREE_TYPE (treeop0);
8117 /* If both input and output are BLKmode, this conversion isn't doing
8118 anything except possibly changing memory attribute. */
8119 if (mode == BLKmode && TYPE_MODE (valtype) == BLKmode)
8121 rtx result = expand_expr (treeop0, target, tmode,
8122 modifier);
8124 result = copy_rtx (result);
8125 set_mem_attributes (result, type, 0);
8126 return result;
8129 if (target == 0)
8131 if (TYPE_MODE (type) != BLKmode)
8132 target = gen_reg_rtx (TYPE_MODE (type));
8133 else
8134 target = assign_temp (type, 1, 1);
8137 if (MEM_P (target))
8138 /* Store data into beginning of memory target. */
8139 store_expr (treeop0,
8140 adjust_address (target, TYPE_MODE (valtype), 0),
8141 modifier == EXPAND_STACK_PARM,
8142 false, TYPE_REVERSE_STORAGE_ORDER (type));
8144 else
8146 gcc_assert (REG_P (target)
8147 && !TYPE_REVERSE_STORAGE_ORDER (type));
8149 /* Store this field into a union of the proper type. */
8150 store_field (target,
8151 MIN ((int_size_in_bytes (TREE_TYPE
8152 (treeop0))
8153 * BITS_PER_UNIT),
8154 (HOST_WIDE_INT) GET_MODE_BITSIZE (mode)),
8155 0, 0, 0, TYPE_MODE (valtype), treeop0, 0,
8156 false, false);
8159 /* Return the entire union. */
8160 return target;
8163 if (mode == TYPE_MODE (TREE_TYPE (treeop0)))
8165 op0 = expand_expr (treeop0, target, VOIDmode,
8166 modifier);
8168 /* If the signedness of the conversion differs and OP0 is
8169 a promoted SUBREG, clear that indication since we now
8170 have to do the proper extension. */
8171 if (TYPE_UNSIGNED (TREE_TYPE (treeop0)) != unsignedp
8172 && GET_CODE (op0) == SUBREG)
8173 SUBREG_PROMOTED_VAR_P (op0) = 0;
8175 return REDUCE_BIT_FIELD (op0);
8178 op0 = expand_expr (treeop0, NULL_RTX, mode,
8179 modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier);
8180 if (GET_MODE (op0) == mode)
8183 /* If OP0 is a constant, just convert it into the proper mode. */
8184 else if (CONSTANT_P (op0))
8186 tree inner_type = TREE_TYPE (treeop0);
8187 machine_mode inner_mode = GET_MODE (op0);
8189 if (inner_mode == VOIDmode)
8190 inner_mode = TYPE_MODE (inner_type);
8192 if (modifier == EXPAND_INITIALIZER)
8193 op0 = lowpart_subreg (mode, op0, inner_mode);
8194 else
8195 op0= convert_modes (mode, inner_mode, op0,
8196 TYPE_UNSIGNED (inner_type));
8199 else if (modifier == EXPAND_INITIALIZER)
8200 op0 = gen_rtx_fmt_e (unsignedp ? ZERO_EXTEND : SIGN_EXTEND, mode, op0);
8202 else if (target == 0)
8203 op0 = convert_to_mode (mode, op0,
8204 TYPE_UNSIGNED (TREE_TYPE
8205 (treeop0)));
8206 else
8208 convert_move (target, op0,
8209 TYPE_UNSIGNED (TREE_TYPE (treeop0)));
8210 op0 = target;
8213 return REDUCE_BIT_FIELD (op0);
8215 case ADDR_SPACE_CONVERT_EXPR:
8217 tree treeop0_type = TREE_TYPE (treeop0);
8219 gcc_assert (POINTER_TYPE_P (type));
8220 gcc_assert (POINTER_TYPE_P (treeop0_type));
8222 addr_space_t as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
8223 addr_space_t as_from = TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type));
8225 /* Conversions between pointers to the same address space should
8226 have been implemented via CONVERT_EXPR / NOP_EXPR. */
8227 gcc_assert (as_to != as_from);
8229 op0 = expand_expr (treeop0, NULL_RTX, VOIDmode, modifier);
8231 /* Ask target code to handle conversion between pointers
8232 to overlapping address spaces. */
8233 if (targetm.addr_space.subset_p (as_to, as_from)
8234 || targetm.addr_space.subset_p (as_from, as_to))
8236 op0 = targetm.addr_space.convert (op0, treeop0_type, type);
8238 else
8240 /* For disjoint address spaces, converting anything but a null
8241 pointer invokes undefined behaviour. We truncate or extend the
8242 value as if we'd converted via integers, which handles 0 as
8243 required, and all others as the programmer likely expects. */
8244 #ifndef POINTERS_EXTEND_UNSIGNED
8245 const int POINTERS_EXTEND_UNSIGNED = 1;
8246 #endif
8247 op0 = convert_modes (mode, TYPE_MODE (treeop0_type),
8248 op0, POINTERS_EXTEND_UNSIGNED);
8250 gcc_assert (op0);
8251 return op0;
8254 case POINTER_PLUS_EXPR:
8255 /* Even though the sizetype mode and the pointer's mode can be different
8256 expand is able to handle this correctly and get the correct result out
8257 of the PLUS_EXPR code. */
8258 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
8259 if sizetype precision is smaller than pointer precision. */
8260 if (TYPE_PRECISION (sizetype) < TYPE_PRECISION (type))
8261 treeop1 = fold_convert_loc (loc, type,
8262 fold_convert_loc (loc, ssizetype,
8263 treeop1));
8264 /* If sizetype precision is larger than pointer precision, truncate the
8265 offset to have matching modes. */
8266 else if (TYPE_PRECISION (sizetype) > TYPE_PRECISION (type))
8267 treeop1 = fold_convert_loc (loc, type, treeop1);
8269 case PLUS_EXPR:
8270 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8271 something else, make sure we add the register to the constant and
8272 then to the other thing. This case can occur during strength
8273 reduction and doing it this way will produce better code if the
8274 frame pointer or argument pointer is eliminated.
8276 fold-const.c will ensure that the constant is always in the inner
8277 PLUS_EXPR, so the only case we need to do anything about is if
8278 sp, ap, or fp is our second argument, in which case we must swap
8279 the innermost first argument and our second argument. */
8281 if (TREE_CODE (treeop0) == PLUS_EXPR
8282 && TREE_CODE (TREE_OPERAND (treeop0, 1)) == INTEGER_CST
8283 && TREE_CODE (treeop1) == VAR_DECL
8284 && (DECL_RTL (treeop1) == frame_pointer_rtx
8285 || DECL_RTL (treeop1) == stack_pointer_rtx
8286 || DECL_RTL (treeop1) == arg_pointer_rtx))
8288 gcc_unreachable ();
8291 /* If the result is to be ptr_mode and we are adding an integer to
8292 something, we might be forming a constant. So try to use
8293 plus_constant. If it produces a sum and we can't accept it,
8294 use force_operand. This allows P = &ARR[const] to generate
8295 efficient code on machines where a SYMBOL_REF is not a valid
8296 address.
8298 If this is an EXPAND_SUM call, always return the sum. */
8299 if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER
8300 || (mode == ptr_mode && (unsignedp || ! flag_trapv)))
8302 if (modifier == EXPAND_STACK_PARM)
8303 target = 0;
8304 if (TREE_CODE (treeop0) == INTEGER_CST
8305 && GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT
8306 && TREE_CONSTANT (treeop1))
8308 rtx constant_part;
8309 HOST_WIDE_INT wc;
8310 machine_mode wmode = TYPE_MODE (TREE_TYPE (treeop1));
8312 op1 = expand_expr (treeop1, subtarget, VOIDmode,
8313 EXPAND_SUM);
8314 /* Use wi::shwi to ensure that the constant is
8315 truncated according to the mode of OP1, then sign extended
8316 to a HOST_WIDE_INT. Using the constant directly can result
8317 in non-canonical RTL in a 64x32 cross compile. */
8318 wc = TREE_INT_CST_LOW (treeop0);
8319 constant_part =
8320 immed_wide_int_const (wi::shwi (wc, wmode), wmode);
8321 op1 = plus_constant (mode, op1, INTVAL (constant_part));
8322 if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8323 op1 = force_operand (op1, target);
8324 return REDUCE_BIT_FIELD (op1);
8327 else if (TREE_CODE (treeop1) == INTEGER_CST
8328 && GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT
8329 && TREE_CONSTANT (treeop0))
8331 rtx constant_part;
8332 HOST_WIDE_INT wc;
8333 machine_mode wmode = TYPE_MODE (TREE_TYPE (treeop0));
8335 op0 = expand_expr (treeop0, subtarget, VOIDmode,
8336 (modifier == EXPAND_INITIALIZER
8337 ? EXPAND_INITIALIZER : EXPAND_SUM));
8338 if (! CONSTANT_P (op0))
8340 op1 = expand_expr (treeop1, NULL_RTX,
8341 VOIDmode, modifier);
8342 /* Return a PLUS if modifier says it's OK. */
8343 if (modifier == EXPAND_SUM
8344 || modifier == EXPAND_INITIALIZER)
8345 return simplify_gen_binary (PLUS, mode, op0, op1);
8346 goto binop2;
8348 /* Use wi::shwi to ensure that the constant is
8349 truncated according to the mode of OP1, then sign extended
8350 to a HOST_WIDE_INT. Using the constant directly can result
8351 in non-canonical RTL in a 64x32 cross compile. */
8352 wc = TREE_INT_CST_LOW (treeop1);
8353 constant_part
8354 = immed_wide_int_const (wi::shwi (wc, wmode), wmode);
8355 op0 = plus_constant (mode, op0, INTVAL (constant_part));
8356 if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8357 op0 = force_operand (op0, target);
8358 return REDUCE_BIT_FIELD (op0);
8362 /* Use TER to expand pointer addition of a negated value
8363 as pointer subtraction. */
8364 if ((POINTER_TYPE_P (TREE_TYPE (treeop0))
8365 || (TREE_CODE (TREE_TYPE (treeop0)) == VECTOR_TYPE
8366 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0)))))
8367 && TREE_CODE (treeop1) == SSA_NAME
8368 && TYPE_MODE (TREE_TYPE (treeop0))
8369 == TYPE_MODE (TREE_TYPE (treeop1)))
8371 gimple *def = get_def_for_expr (treeop1, NEGATE_EXPR);
8372 if (def)
8374 treeop1 = gimple_assign_rhs1 (def);
8375 code = MINUS_EXPR;
8376 goto do_minus;
8380 /* No sense saving up arithmetic to be done
8381 if it's all in the wrong mode to form part of an address.
8382 And force_operand won't know whether to sign-extend or
8383 zero-extend. */
8384 if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8385 || mode != ptr_mode)
8387 expand_operands (treeop0, treeop1,
8388 subtarget, &op0, &op1, EXPAND_NORMAL);
8389 if (op0 == const0_rtx)
8390 return op1;
8391 if (op1 == const0_rtx)
8392 return op0;
8393 goto binop2;
8396 expand_operands (treeop0, treeop1,
8397 subtarget, &op0, &op1, modifier);
8398 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
8400 case MINUS_EXPR:
8401 do_minus:
8402 /* For initializers, we are allowed to return a MINUS of two
8403 symbolic constants. Here we handle all cases when both operands
8404 are constant. */
8405 /* Handle difference of two symbolic constants,
8406 for the sake of an initializer. */
8407 if ((modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
8408 && really_constant_p (treeop0)
8409 && really_constant_p (treeop1))
8411 expand_operands (treeop0, treeop1,
8412 NULL_RTX, &op0, &op1, modifier);
8414 /* If the last operand is a CONST_INT, use plus_constant of
8415 the negated constant. Else make the MINUS. */
8416 if (CONST_INT_P (op1))
8417 return REDUCE_BIT_FIELD (plus_constant (mode, op0,
8418 -INTVAL (op1)));
8419 else
8420 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode, op0, op1));
8423 /* No sense saving up arithmetic to be done
8424 if it's all in the wrong mode to form part of an address.
8425 And force_operand won't know whether to sign-extend or
8426 zero-extend. */
8427 if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8428 || mode != ptr_mode)
8429 goto binop;
8431 expand_operands (treeop0, treeop1,
8432 subtarget, &op0, &op1, modifier);
8434 /* Convert A - const to A + (-const). */
8435 if (CONST_INT_P (op1))
8437 op1 = negate_rtx (mode, op1);
8438 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
8441 goto binop2;
8443 case WIDEN_MULT_PLUS_EXPR:
8444 case WIDEN_MULT_MINUS_EXPR:
8445 expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8446 op2 = expand_normal (treeop2);
8447 target = expand_widen_pattern_expr (ops, op0, op1, op2,
8448 target, unsignedp);
8449 return target;
8451 case WIDEN_MULT_EXPR:
8452 /* If first operand is constant, swap them.
8453 Thus the following special case checks need only
8454 check the second operand. */
8455 if (TREE_CODE (treeop0) == INTEGER_CST)
8456 std::swap (treeop0, treeop1);
8458 /* First, check if we have a multiplication of one signed and one
8459 unsigned operand. */
8460 if (TREE_CODE (treeop1) != INTEGER_CST
8461 && (TYPE_UNSIGNED (TREE_TYPE (treeop0))
8462 != TYPE_UNSIGNED (TREE_TYPE (treeop1))))
8464 machine_mode innermode = TYPE_MODE (TREE_TYPE (treeop0));
8465 this_optab = usmul_widen_optab;
8466 if (find_widening_optab_handler (this_optab, mode, innermode, 0)
8467 != CODE_FOR_nothing)
8469 if (TYPE_UNSIGNED (TREE_TYPE (treeop0)))
8470 expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
8471 EXPAND_NORMAL);
8472 else
8473 expand_operands (treeop0, treeop1, NULL_RTX, &op1, &op0,
8474 EXPAND_NORMAL);
8475 /* op0 and op1 might still be constant, despite the above
8476 != INTEGER_CST check. Handle it. */
8477 if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
8479 op0 = convert_modes (innermode, mode, op0, true);
8480 op1 = convert_modes (innermode, mode, op1, false);
8481 return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1,
8482 target, unsignedp));
8484 goto binop3;
8487 /* Check for a multiplication with matching signedness. */
8488 else if ((TREE_CODE (treeop1) == INTEGER_CST
8489 && int_fits_type_p (treeop1, TREE_TYPE (treeop0)))
8490 || (TYPE_UNSIGNED (TREE_TYPE (treeop1))
8491 == TYPE_UNSIGNED (TREE_TYPE (treeop0))))
8493 tree op0type = TREE_TYPE (treeop0);
8494 machine_mode innermode = TYPE_MODE (op0type);
8495 bool zextend_p = TYPE_UNSIGNED (op0type);
8496 optab other_optab = zextend_p ? smul_widen_optab : umul_widen_optab;
8497 this_optab = zextend_p ? umul_widen_optab : smul_widen_optab;
8499 if (TREE_CODE (treeop0) != INTEGER_CST)
8501 if (find_widening_optab_handler (this_optab, mode, innermode, 0)
8502 != CODE_FOR_nothing)
8504 expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
8505 EXPAND_NORMAL);
8506 /* op0 and op1 might still be constant, despite the above
8507 != INTEGER_CST check. Handle it. */
8508 if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
8510 widen_mult_const:
8511 op0 = convert_modes (innermode, mode, op0, zextend_p);
8513 = convert_modes (innermode, mode, op1,
8514 TYPE_UNSIGNED (TREE_TYPE (treeop1)));
8515 return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1,
8516 target,
8517 unsignedp));
8519 temp = expand_widening_mult (mode, op0, op1, target,
8520 unsignedp, this_optab);
8521 return REDUCE_BIT_FIELD (temp);
8523 if (find_widening_optab_handler (other_optab, mode, innermode, 0)
8524 != CODE_FOR_nothing
8525 && innermode == word_mode)
8527 rtx htem, hipart;
8528 op0 = expand_normal (treeop0);
8529 if (TREE_CODE (treeop1) == INTEGER_CST)
8530 op1 = convert_modes (innermode, mode,
8531 expand_normal (treeop1),
8532 TYPE_UNSIGNED (TREE_TYPE (treeop1)));
8533 else
8534 op1 = expand_normal (treeop1);
8535 /* op0 and op1 might still be constant, despite the above
8536 != INTEGER_CST check. Handle it. */
8537 if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
8538 goto widen_mult_const;
8539 temp = expand_binop (mode, other_optab, op0, op1, target,
8540 unsignedp, OPTAB_LIB_WIDEN);
8541 hipart = gen_highpart (innermode, temp);
8542 htem = expand_mult_highpart_adjust (innermode, hipart,
8543 op0, op1, hipart,
8544 zextend_p);
8545 if (htem != hipart)
8546 emit_move_insn (hipart, htem);
8547 return REDUCE_BIT_FIELD (temp);
8551 treeop0 = fold_build1 (CONVERT_EXPR, type, treeop0);
8552 treeop1 = fold_build1 (CONVERT_EXPR, type, treeop1);
8553 expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
8554 return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
8556 case FMA_EXPR:
8558 optab opt = fma_optab;
8559 gimple *def0, *def2;
8561 /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
8562 call. */
8563 if (optab_handler (fma_optab, mode) == CODE_FOR_nothing)
8565 tree fn = mathfn_built_in (TREE_TYPE (treeop0), BUILT_IN_FMA);
8566 tree call_expr;
8568 gcc_assert (fn != NULL_TREE);
8569 call_expr = build_call_expr (fn, 3, treeop0, treeop1, treeop2);
8570 return expand_builtin (call_expr, target, subtarget, mode, false);
8573 def0 = get_def_for_expr (treeop0, NEGATE_EXPR);
8574 /* The multiplication is commutative - look at its 2nd operand
8575 if the first isn't fed by a negate. */
8576 if (!def0)
8578 def0 = get_def_for_expr (treeop1, NEGATE_EXPR);
8579 /* Swap operands if the 2nd operand is fed by a negate. */
8580 if (def0)
8581 std::swap (treeop0, treeop1);
8583 def2 = get_def_for_expr (treeop2, NEGATE_EXPR);
8585 op0 = op2 = NULL;
8587 if (def0 && def2
8588 && optab_handler (fnms_optab, mode) != CODE_FOR_nothing)
8590 opt = fnms_optab;
8591 op0 = expand_normal (gimple_assign_rhs1 (def0));
8592 op2 = expand_normal (gimple_assign_rhs1 (def2));
8594 else if (def0
8595 && optab_handler (fnma_optab, mode) != CODE_FOR_nothing)
8597 opt = fnma_optab;
8598 op0 = expand_normal (gimple_assign_rhs1 (def0));
8600 else if (def2
8601 && optab_handler (fms_optab, mode) != CODE_FOR_nothing)
8603 opt = fms_optab;
8604 op2 = expand_normal (gimple_assign_rhs1 (def2));
8607 if (op0 == NULL)
8608 op0 = expand_expr (treeop0, subtarget, VOIDmode, EXPAND_NORMAL);
8609 if (op2 == NULL)
8610 op2 = expand_normal (treeop2);
8611 op1 = expand_normal (treeop1);
8613 return expand_ternary_op (TYPE_MODE (type), opt,
8614 op0, op1, op2, target, 0);
8617 case MULT_EXPR:
8618 /* If this is a fixed-point operation, then we cannot use the code
8619 below because "expand_mult" doesn't support sat/no-sat fixed-point
8620 multiplications. */
8621 if (ALL_FIXED_POINT_MODE_P (mode))
8622 goto binop;
8624 /* If first operand is constant, swap them.
8625 Thus the following special case checks need only
8626 check the second operand. */
8627 if (TREE_CODE (treeop0) == INTEGER_CST)
8628 std::swap (treeop0, treeop1);
8630 /* Attempt to return something suitable for generating an
8631 indexed address, for machines that support that. */
8633 if (modifier == EXPAND_SUM && mode == ptr_mode
8634 && tree_fits_shwi_p (treeop1))
8636 tree exp1 = treeop1;
8638 op0 = expand_expr (treeop0, subtarget, VOIDmode,
8639 EXPAND_SUM);
8641 if (!REG_P (op0))
8642 op0 = force_operand (op0, NULL_RTX);
8643 if (!REG_P (op0))
8644 op0 = copy_to_mode_reg (mode, op0);
8646 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode, op0,
8647 gen_int_mode (tree_to_shwi (exp1),
8648 TYPE_MODE (TREE_TYPE (exp1)))));
8651 if (modifier == EXPAND_STACK_PARM)
8652 target = 0;
8654 expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
8655 return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
8657 case TRUNC_DIV_EXPR:
8658 case FLOOR_DIV_EXPR:
8659 case CEIL_DIV_EXPR:
8660 case ROUND_DIV_EXPR:
8661 case EXACT_DIV_EXPR:
8662 /* If this is a fixed-point operation, then we cannot use the code
8663 below because "expand_divmod" doesn't support sat/no-sat fixed-point
8664 divisions. */
8665 if (ALL_FIXED_POINT_MODE_P (mode))
8666 goto binop;
8668 if (modifier == EXPAND_STACK_PARM)
8669 target = 0;
8670 /* Possible optimization: compute the dividend with EXPAND_SUM
8671 then if the divisor is constant can optimize the case
8672 where some terms of the dividend have coeffs divisible by it. */
8673 expand_operands (treeop0, treeop1,
8674 subtarget, &op0, &op1, EXPAND_NORMAL);
8675 return expand_divmod (0, code, mode, op0, op1, target, unsignedp);
8677 case RDIV_EXPR:
8678 goto binop;
8680 case MULT_HIGHPART_EXPR:
8681 expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
8682 temp = expand_mult_highpart (mode, op0, op1, target, unsignedp);
8683 gcc_assert (temp);
8684 return temp;
8686 case TRUNC_MOD_EXPR:
8687 case FLOOR_MOD_EXPR:
8688 case CEIL_MOD_EXPR:
8689 case ROUND_MOD_EXPR:
8690 if (modifier == EXPAND_STACK_PARM)
8691 target = 0;
8692 expand_operands (treeop0, treeop1,
8693 subtarget, &op0, &op1, EXPAND_NORMAL);
8694 return expand_divmod (1, code, mode, op0, op1, target, unsignedp);
8696 case FIXED_CONVERT_EXPR:
8697 op0 = expand_normal (treeop0);
8698 if (target == 0 || modifier == EXPAND_STACK_PARM)
8699 target = gen_reg_rtx (mode);
8701 if ((TREE_CODE (TREE_TYPE (treeop0)) == INTEGER_TYPE
8702 && TYPE_UNSIGNED (TREE_TYPE (treeop0)))
8703 || (TREE_CODE (type) == INTEGER_TYPE && TYPE_UNSIGNED (type)))
8704 expand_fixed_convert (target, op0, 1, TYPE_SATURATING (type));
8705 else
8706 expand_fixed_convert (target, op0, 0, TYPE_SATURATING (type));
8707 return target;
8709 case FIX_TRUNC_EXPR:
8710 op0 = expand_normal (treeop0);
8711 if (target == 0 || modifier == EXPAND_STACK_PARM)
8712 target = gen_reg_rtx (mode);
8713 expand_fix (target, op0, unsignedp);
8714 return target;
8716 case FLOAT_EXPR:
8717 op0 = expand_normal (treeop0);
8718 if (target == 0 || modifier == EXPAND_STACK_PARM)
8719 target = gen_reg_rtx (mode);
8720 /* expand_float can't figure out what to do if FROM has VOIDmode.
8721 So give it the correct mode. With -O, cse will optimize this. */
8722 if (GET_MODE (op0) == VOIDmode)
8723 op0 = copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0)),
8724 op0);
8725 expand_float (target, op0,
8726 TYPE_UNSIGNED (TREE_TYPE (treeop0)));
8727 return target;
8729 case NEGATE_EXPR:
8730 op0 = expand_expr (treeop0, subtarget,
8731 VOIDmode, EXPAND_NORMAL);
8732 if (modifier == EXPAND_STACK_PARM)
8733 target = 0;
8734 temp = expand_unop (mode,
8735 optab_for_tree_code (NEGATE_EXPR, type,
8736 optab_default),
8737 op0, target, 0);
8738 gcc_assert (temp);
8739 return REDUCE_BIT_FIELD (temp);
8741 case ABS_EXPR:
8742 op0 = expand_expr (treeop0, subtarget,
8743 VOIDmode, EXPAND_NORMAL);
8744 if (modifier == EXPAND_STACK_PARM)
8745 target = 0;
8747 /* ABS_EXPR is not valid for complex arguments. */
8748 gcc_assert (GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
8749 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT);
8751 /* Unsigned abs is simply the operand. Testing here means we don't
8752 risk generating incorrect code below. */
8753 if (TYPE_UNSIGNED (type))
8754 return op0;
8756 return expand_abs (mode, op0, target, unsignedp,
8757 safe_from_p (target, treeop0, 1));
8759 case MAX_EXPR:
8760 case MIN_EXPR:
8761 target = original_target;
8762 if (target == 0
8763 || modifier == EXPAND_STACK_PARM
8764 || (MEM_P (target) && MEM_VOLATILE_P (target))
8765 || GET_MODE (target) != mode
8766 || (REG_P (target)
8767 && REGNO (target) < FIRST_PSEUDO_REGISTER))
8768 target = gen_reg_rtx (mode);
8769 expand_operands (treeop0, treeop1,
8770 target, &op0, &op1, EXPAND_NORMAL);
8772 /* First try to do it with a special MIN or MAX instruction.
8773 If that does not win, use a conditional jump to select the proper
8774 value. */
8775 this_optab = optab_for_tree_code (code, type, optab_default);
8776 temp = expand_binop (mode, this_optab, op0, op1, target, unsignedp,
8777 OPTAB_WIDEN);
8778 if (temp != 0)
8779 return temp;
8781 /* At this point, a MEM target is no longer useful; we will get better
8782 code without it. */
8784 if (! REG_P (target))
8785 target = gen_reg_rtx (mode);
8787 /* If op1 was placed in target, swap op0 and op1. */
8788 if (target != op0 && target == op1)
8789 std::swap (op0, op1);
8791 /* We generate better code and avoid problems with op1 mentioning
8792 target by forcing op1 into a pseudo if it isn't a constant. */
8793 if (! CONSTANT_P (op1))
8794 op1 = force_reg (mode, op1);
8797 enum rtx_code comparison_code;
8798 rtx cmpop1 = op1;
8800 if (code == MAX_EXPR)
8801 comparison_code = unsignedp ? GEU : GE;
8802 else
8803 comparison_code = unsignedp ? LEU : LE;
8805 /* Canonicalize to comparisons against 0. */
8806 if (op1 == const1_rtx)
8808 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8809 or (a != 0 ? a : 1) for unsigned.
8810 For MIN we are safe converting (a <= 1 ? a : 1)
8811 into (a <= 0 ? a : 1) */
8812 cmpop1 = const0_rtx;
8813 if (code == MAX_EXPR)
8814 comparison_code = unsignedp ? NE : GT;
8816 if (op1 == constm1_rtx && !unsignedp)
8818 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8819 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8820 cmpop1 = const0_rtx;
8821 if (code == MIN_EXPR)
8822 comparison_code = LT;
8825 /* Use a conditional move if possible. */
8826 if (can_conditionally_move_p (mode))
8828 rtx insn;
8830 start_sequence ();
8832 /* Try to emit the conditional move. */
8833 insn = emit_conditional_move (target, comparison_code,
8834 op0, cmpop1, mode,
8835 op0, op1, mode,
8836 unsignedp);
8838 /* If we could do the conditional move, emit the sequence,
8839 and return. */
8840 if (insn)
8842 rtx_insn *seq = get_insns ();
8843 end_sequence ();
8844 emit_insn (seq);
8845 return target;
8848 /* Otherwise discard the sequence and fall back to code with
8849 branches. */
8850 end_sequence ();
8853 if (target != op0)
8854 emit_move_insn (target, op0);
8856 lab = gen_label_rtx ();
8857 do_compare_rtx_and_jump (target, cmpop1, comparison_code,
8858 unsignedp, mode, NULL_RTX, NULL, lab,
8859 -1);
8861 emit_move_insn (target, op1);
8862 emit_label (lab);
8863 return target;
8865 case BIT_NOT_EXPR:
8866 op0 = expand_expr (treeop0, subtarget,
8867 VOIDmode, EXPAND_NORMAL);
8868 if (modifier == EXPAND_STACK_PARM)
8869 target = 0;
8870 /* In case we have to reduce the result to bitfield precision
8871 for unsigned bitfield expand this as XOR with a proper constant
8872 instead. */
8873 if (reduce_bit_field && TYPE_UNSIGNED (type))
8875 wide_int mask = wi::mask (TYPE_PRECISION (type),
8876 false, GET_MODE_PRECISION (mode));
8878 temp = expand_binop (mode, xor_optab, op0,
8879 immed_wide_int_const (mask, mode),
8880 target, 1, OPTAB_LIB_WIDEN);
8882 else
8883 temp = expand_unop (mode, one_cmpl_optab, op0, target, 1);
8884 gcc_assert (temp);
8885 return temp;
8887 /* ??? Can optimize bitwise operations with one arg constant.
8888 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8889 and (a bitwise1 b) bitwise2 b (etc)
8890 but that is probably not worth while. */
8892 case BIT_AND_EXPR:
8893 case BIT_IOR_EXPR:
8894 case BIT_XOR_EXPR:
8895 goto binop;
8897 case LROTATE_EXPR:
8898 case RROTATE_EXPR:
8899 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type))
8900 || (GET_MODE_PRECISION (TYPE_MODE (type))
8901 == TYPE_PRECISION (type)));
8902 /* fall through */
8904 case LSHIFT_EXPR:
8905 case RSHIFT_EXPR:
8907 /* If this is a fixed-point operation, then we cannot use the code
8908 below because "expand_shift" doesn't support sat/no-sat fixed-point
8909 shifts. */
8910 if (ALL_FIXED_POINT_MODE_P (mode))
8911 goto binop;
8913 if (! safe_from_p (subtarget, treeop1, 1))
8914 subtarget = 0;
8915 if (modifier == EXPAND_STACK_PARM)
8916 target = 0;
8917 op0 = expand_expr (treeop0, subtarget,
8918 VOIDmode, EXPAND_NORMAL);
8920 /* Left shift optimization when shifting across word_size boundary.
8922 If mode == GET_MODE_WIDER_MODE (word_mode), then normally there isn't
8923 native instruction to support this wide mode left shift. Given below
8924 scenario:
8926 Type A = (Type) B << C
8928 |< T >|
8929 | dest_high | dest_low |
8931 | word_size |
8933 If the shift amount C caused we shift B to across the word size
8934 boundary, i.e part of B shifted into high half of destination
8935 register, and part of B remains in the low half, then GCC will use
8936 the following left shift expand logic:
8938 1. Initialize dest_low to B.
8939 2. Initialize every bit of dest_high to the sign bit of B.
8940 3. Logic left shift dest_low by C bit to finalize dest_low.
8941 The value of dest_low before this shift is kept in a temp D.
8942 4. Logic left shift dest_high by C.
8943 5. Logic right shift D by (word_size - C).
8944 6. Or the result of 4 and 5 to finalize dest_high.
8946 While, by checking gimple statements, if operand B is coming from
8947 signed extension, then we can simplify above expand logic into:
8949 1. dest_high = src_low >> (word_size - C).
8950 2. dest_low = src_low << C.
8952 We can use one arithmetic right shift to finish all the purpose of
8953 steps 2, 4, 5, 6, thus we reduce the steps needed from 6 into 2. */
8955 temp = NULL_RTX;
8956 if (code == LSHIFT_EXPR
8957 && target
8958 && REG_P (target)
8959 && ! unsignedp
8960 && mode == GET_MODE_WIDER_MODE (word_mode)
8961 && GET_MODE_SIZE (mode) == 2 * GET_MODE_SIZE (word_mode)
8962 && TREE_CONSTANT (treeop1)
8963 && TREE_CODE (treeop0) == SSA_NAME)
8965 gimple *def = SSA_NAME_DEF_STMT (treeop0);
8966 if (is_gimple_assign (def)
8967 && gimple_assign_rhs_code (def) == NOP_EXPR)
8969 machine_mode rmode = TYPE_MODE
8970 (TREE_TYPE (gimple_assign_rhs1 (def)));
8972 if (GET_MODE_SIZE (rmode) < GET_MODE_SIZE (mode)
8973 && TREE_INT_CST_LOW (treeop1) < GET_MODE_BITSIZE (word_mode)
8974 && ((TREE_INT_CST_LOW (treeop1) + GET_MODE_BITSIZE (rmode))
8975 >= GET_MODE_BITSIZE (word_mode)))
8977 rtx_insn *seq, *seq_old;
8978 unsigned int high_off = subreg_highpart_offset (word_mode,
8979 mode);
8980 rtx low = lowpart_subreg (word_mode, op0, mode);
8981 rtx dest_low = lowpart_subreg (word_mode, target, mode);
8982 rtx dest_high = simplify_gen_subreg (word_mode, target,
8983 mode, high_off);
8984 HOST_WIDE_INT ramount = (BITS_PER_WORD
8985 - TREE_INT_CST_LOW (treeop1));
8986 tree rshift = build_int_cst (TREE_TYPE (treeop1), ramount);
8988 start_sequence ();
8989 /* dest_high = src_low >> (word_size - C). */
8990 temp = expand_variable_shift (RSHIFT_EXPR, word_mode, low,
8991 rshift, dest_high, unsignedp);
8992 if (temp != dest_high)
8993 emit_move_insn (dest_high, temp);
8995 /* dest_low = src_low << C. */
8996 temp = expand_variable_shift (LSHIFT_EXPR, word_mode, low,
8997 treeop1, dest_low, unsignedp);
8998 if (temp != dest_low)
8999 emit_move_insn (dest_low, temp);
9001 seq = get_insns ();
9002 end_sequence ();
9003 temp = target ;
9005 if (have_insn_for (ASHIFT, mode))
9007 bool speed_p = optimize_insn_for_speed_p ();
9008 start_sequence ();
9009 rtx ret_old = expand_variable_shift (code, mode, op0,
9010 treeop1, target,
9011 unsignedp);
9013 seq_old = get_insns ();
9014 end_sequence ();
9015 if (seq_cost (seq, speed_p)
9016 >= seq_cost (seq_old, speed_p))
9018 seq = seq_old;
9019 temp = ret_old;
9022 emit_insn (seq);
9027 if (temp == NULL_RTX)
9028 temp = expand_variable_shift (code, mode, op0, treeop1, target,
9029 unsignedp);
9030 if (code == LSHIFT_EXPR)
9031 temp = REDUCE_BIT_FIELD (temp);
9032 return temp;
9035 /* Could determine the answer when only additive constants differ. Also,
9036 the addition of one can be handled by changing the condition. */
9037 case LT_EXPR:
9038 case LE_EXPR:
9039 case GT_EXPR:
9040 case GE_EXPR:
9041 case EQ_EXPR:
9042 case NE_EXPR:
9043 case UNORDERED_EXPR:
9044 case ORDERED_EXPR:
9045 case UNLT_EXPR:
9046 case UNLE_EXPR:
9047 case UNGT_EXPR:
9048 case UNGE_EXPR:
9049 case UNEQ_EXPR:
9050 case LTGT_EXPR:
9052 temp = do_store_flag (ops,
9053 modifier != EXPAND_STACK_PARM ? target : NULL_RTX,
9054 tmode != VOIDmode ? tmode : mode);
9055 if (temp)
9056 return temp;
9058 /* Use a compare and a jump for BLKmode comparisons, or for function
9059 type comparisons is have_canonicalize_funcptr_for_compare. */
9061 if ((target == 0
9062 || modifier == EXPAND_STACK_PARM
9063 || ! safe_from_p (target, treeop0, 1)
9064 || ! safe_from_p (target, treeop1, 1)
9065 /* Make sure we don't have a hard reg (such as function's return
9066 value) live across basic blocks, if not optimizing. */
9067 || (!optimize && REG_P (target)
9068 && REGNO (target) < FIRST_PSEUDO_REGISTER)))
9069 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
9071 emit_move_insn (target, const0_rtx);
9073 rtx_code_label *lab1 = gen_label_rtx ();
9074 jumpifnot_1 (code, treeop0, treeop1, lab1, -1);
9076 if (TYPE_PRECISION (type) == 1 && !TYPE_UNSIGNED (type))
9077 emit_move_insn (target, constm1_rtx);
9078 else
9079 emit_move_insn (target, const1_rtx);
9081 emit_label (lab1);
9082 return target;
9084 case COMPLEX_EXPR:
9085 /* Get the rtx code of the operands. */
9086 op0 = expand_normal (treeop0);
9087 op1 = expand_normal (treeop1);
9089 if (!target)
9090 target = gen_reg_rtx (TYPE_MODE (type));
9091 else
9092 /* If target overlaps with op1, then either we need to force
9093 op1 into a pseudo (if target also overlaps with op0),
9094 or write the complex parts in reverse order. */
9095 switch (GET_CODE (target))
9097 case CONCAT:
9098 if (reg_overlap_mentioned_p (XEXP (target, 0), op1))
9100 if (reg_overlap_mentioned_p (XEXP (target, 1), op0))
9102 complex_expr_force_op1:
9103 temp = gen_reg_rtx (GET_MODE_INNER (GET_MODE (target)));
9104 emit_move_insn (temp, op1);
9105 op1 = temp;
9106 break;
9108 complex_expr_swap_order:
9109 /* Move the imaginary (op1) and real (op0) parts to their
9110 location. */
9111 write_complex_part (target, op1, true);
9112 write_complex_part (target, op0, false);
9114 return target;
9116 break;
9117 case MEM:
9118 temp = adjust_address_nv (target,
9119 GET_MODE_INNER (GET_MODE (target)), 0);
9120 if (reg_overlap_mentioned_p (temp, op1))
9122 machine_mode imode = GET_MODE_INNER (GET_MODE (target));
9123 temp = adjust_address_nv (target, imode,
9124 GET_MODE_SIZE (imode));
9125 if (reg_overlap_mentioned_p (temp, op0))
9126 goto complex_expr_force_op1;
9127 goto complex_expr_swap_order;
9129 break;
9130 default:
9131 if (reg_overlap_mentioned_p (target, op1))
9133 if (reg_overlap_mentioned_p (target, op0))
9134 goto complex_expr_force_op1;
9135 goto complex_expr_swap_order;
9137 break;
9140 /* Move the real (op0) and imaginary (op1) parts to their location. */
9141 write_complex_part (target, op0, false);
9142 write_complex_part (target, op1, true);
9144 return target;
9146 case WIDEN_SUM_EXPR:
9148 tree oprnd0 = treeop0;
9149 tree oprnd1 = treeop1;
9151 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
9152 target = expand_widen_pattern_expr (ops, op0, NULL_RTX, op1,
9153 target, unsignedp);
9154 return target;
9157 case REDUC_MAX_EXPR:
9158 case REDUC_MIN_EXPR:
9159 case REDUC_PLUS_EXPR:
9161 op0 = expand_normal (treeop0);
9162 this_optab = optab_for_tree_code (code, type, optab_default);
9163 machine_mode vec_mode = TYPE_MODE (TREE_TYPE (treeop0));
9165 struct expand_operand ops[2];
9166 enum insn_code icode = optab_handler (this_optab, vec_mode);
9168 create_output_operand (&ops[0], target, mode);
9169 create_input_operand (&ops[1], op0, vec_mode);
9170 expand_insn (icode, 2, ops);
9171 target = ops[0].value;
9172 if (GET_MODE (target) != mode)
9173 return gen_lowpart (tmode, target);
9174 return target;
9177 case VEC_UNPACK_HI_EXPR:
9178 case VEC_UNPACK_LO_EXPR:
9180 op0 = expand_normal (treeop0);
9181 temp = expand_widen_pattern_expr (ops, op0, NULL_RTX, NULL_RTX,
9182 target, unsignedp);
9183 gcc_assert (temp);
9184 return temp;
9187 case VEC_UNPACK_FLOAT_HI_EXPR:
9188 case VEC_UNPACK_FLOAT_LO_EXPR:
9190 op0 = expand_normal (treeop0);
9191 /* The signedness is determined from input operand. */
9192 temp = expand_widen_pattern_expr
9193 (ops, op0, NULL_RTX, NULL_RTX,
9194 target, TYPE_UNSIGNED (TREE_TYPE (treeop0)));
9196 gcc_assert (temp);
9197 return temp;
9200 case VEC_WIDEN_MULT_HI_EXPR:
9201 case VEC_WIDEN_MULT_LO_EXPR:
9202 case VEC_WIDEN_MULT_EVEN_EXPR:
9203 case VEC_WIDEN_MULT_ODD_EXPR:
9204 case VEC_WIDEN_LSHIFT_HI_EXPR:
9205 case VEC_WIDEN_LSHIFT_LO_EXPR:
9206 expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
9207 target = expand_widen_pattern_expr (ops, op0, op1, NULL_RTX,
9208 target, unsignedp);
9209 gcc_assert (target);
9210 return target;
9212 case VEC_PACK_TRUNC_EXPR:
9213 case VEC_PACK_SAT_EXPR:
9214 case VEC_PACK_FIX_TRUNC_EXPR:
9215 mode = TYPE_MODE (TREE_TYPE (treeop0));
9216 goto binop;
9218 case VEC_PERM_EXPR:
9219 expand_operands (treeop0, treeop1, target, &op0, &op1, EXPAND_NORMAL);
9220 op2 = expand_normal (treeop2);
9222 /* Careful here: if the target doesn't support integral vector modes,
9223 a constant selection vector could wind up smooshed into a normal
9224 integral constant. */
9225 if (CONSTANT_P (op2) && GET_CODE (op2) != CONST_VECTOR)
9227 tree sel_type = TREE_TYPE (treeop2);
9228 machine_mode vmode
9229 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type)),
9230 TYPE_VECTOR_SUBPARTS (sel_type));
9231 gcc_assert (GET_MODE_CLASS (vmode) == MODE_VECTOR_INT);
9232 op2 = simplify_subreg (vmode, op2, TYPE_MODE (sel_type), 0);
9233 gcc_assert (op2 && GET_CODE (op2) == CONST_VECTOR);
9235 else
9236 gcc_assert (GET_MODE_CLASS (GET_MODE (op2)) == MODE_VECTOR_INT);
9238 temp = expand_vec_perm (mode, op0, op1, op2, target);
9239 gcc_assert (temp);
9240 return temp;
9242 case DOT_PROD_EXPR:
9244 tree oprnd0 = treeop0;
9245 tree oprnd1 = treeop1;
9246 tree oprnd2 = treeop2;
9247 rtx op2;
9249 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
9250 op2 = expand_normal (oprnd2);
9251 target = expand_widen_pattern_expr (ops, op0, op1, op2,
9252 target, unsignedp);
9253 return target;
9256 case SAD_EXPR:
9258 tree oprnd0 = treeop0;
9259 tree oprnd1 = treeop1;
9260 tree oprnd2 = treeop2;
9261 rtx op2;
9263 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
9264 op2 = expand_normal (oprnd2);
9265 target = expand_widen_pattern_expr (ops, op0, op1, op2,
9266 target, unsignedp);
9267 return target;
9270 case REALIGN_LOAD_EXPR:
9272 tree oprnd0 = treeop0;
9273 tree oprnd1 = treeop1;
9274 tree oprnd2 = treeop2;
9275 rtx op2;
9277 this_optab = optab_for_tree_code (code, type, optab_default);
9278 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
9279 op2 = expand_normal (oprnd2);
9280 temp = expand_ternary_op (mode, this_optab, op0, op1, op2,
9281 target, unsignedp);
9282 gcc_assert (temp);
9283 return temp;
9286 case COND_EXPR:
9288 /* A COND_EXPR with its type being VOID_TYPE represents a
9289 conditional jump and is handled in
9290 expand_gimple_cond_expr. */
9291 gcc_assert (!VOID_TYPE_P (type));
9293 /* Note that COND_EXPRs whose type is a structure or union
9294 are required to be constructed to contain assignments of
9295 a temporary variable, so that we can evaluate them here
9296 for side effect only. If type is void, we must do likewise. */
9298 gcc_assert (!TREE_ADDRESSABLE (type)
9299 && !ignore
9300 && TREE_TYPE (treeop1) != void_type_node
9301 && TREE_TYPE (treeop2) != void_type_node);
9303 temp = expand_cond_expr_using_cmove (treeop0, treeop1, treeop2);
9304 if (temp)
9305 return temp;
9307 /* If we are not to produce a result, we have no target. Otherwise,
9308 if a target was specified use it; it will not be used as an
9309 intermediate target unless it is safe. If no target, use a
9310 temporary. */
9312 if (modifier != EXPAND_STACK_PARM
9313 && original_target
9314 && safe_from_p (original_target, treeop0, 1)
9315 && GET_MODE (original_target) == mode
9316 && !MEM_P (original_target))
9317 temp = original_target;
9318 else
9319 temp = assign_temp (type, 0, 1);
9321 do_pending_stack_adjust ();
9322 NO_DEFER_POP;
9323 rtx_code_label *lab0 = gen_label_rtx ();
9324 rtx_code_label *lab1 = gen_label_rtx ();
9325 jumpifnot (treeop0, lab0, -1);
9326 store_expr (treeop1, temp,
9327 modifier == EXPAND_STACK_PARM,
9328 false, false);
9330 emit_jump_insn (targetm.gen_jump (lab1));
9331 emit_barrier ();
9332 emit_label (lab0);
9333 store_expr (treeop2, temp,
9334 modifier == EXPAND_STACK_PARM,
9335 false, false);
9337 emit_label (lab1);
9338 OK_DEFER_POP;
9339 return temp;
9342 case VEC_COND_EXPR:
9343 target = expand_vec_cond_expr (type, treeop0, treeop1, treeop2, target);
9344 return target;
9346 default:
9347 gcc_unreachable ();
9350 /* Here to do an ordinary binary operator. */
9351 binop:
9352 expand_operands (treeop0, treeop1,
9353 subtarget, &op0, &op1, EXPAND_NORMAL);
9354 binop2:
9355 this_optab = optab_for_tree_code (code, type, optab_default);
9356 binop3:
9357 if (modifier == EXPAND_STACK_PARM)
9358 target = 0;
9359 temp = expand_binop (mode, this_optab, op0, op1, target,
9360 unsignedp, OPTAB_LIB_WIDEN);
9361 gcc_assert (temp);
9362 /* Bitwise operations do not need bitfield reduction as we expect their
9363 operands being properly truncated. */
9364 if (code == BIT_XOR_EXPR
9365 || code == BIT_AND_EXPR
9366 || code == BIT_IOR_EXPR)
9367 return temp;
9368 return REDUCE_BIT_FIELD (temp);
9370 #undef REDUCE_BIT_FIELD
9373 /* Return TRUE if expression STMT is suitable for replacement.
9374 Never consider memory loads as replaceable, because those don't ever lead
9375 into constant expressions. */
9377 static bool
9378 stmt_is_replaceable_p (gimple *stmt)
9380 if (ssa_is_replaceable_p (stmt))
9382 /* Don't move around loads. */
9383 if (!gimple_assign_single_p (stmt)
9384 || is_gimple_val (gimple_assign_rhs1 (stmt)))
9385 return true;
9387 return false;
9391 expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
9392 enum expand_modifier modifier, rtx *alt_rtl,
9393 bool inner_reference_p)
9395 rtx op0, op1, temp, decl_rtl;
9396 tree type;
9397 int unsignedp;
9398 machine_mode mode, dmode;
9399 enum tree_code code = TREE_CODE (exp);
9400 rtx subtarget, original_target;
9401 int ignore;
9402 tree context;
9403 bool reduce_bit_field;
9404 location_t loc = EXPR_LOCATION (exp);
9405 struct separate_ops ops;
9406 tree treeop0, treeop1, treeop2;
9407 tree ssa_name = NULL_TREE;
9408 gimple *g;
9410 type = TREE_TYPE (exp);
9411 mode = TYPE_MODE (type);
9412 unsignedp = TYPE_UNSIGNED (type);
9414 treeop0 = treeop1 = treeop2 = NULL_TREE;
9415 if (!VL_EXP_CLASS_P (exp))
9416 switch (TREE_CODE_LENGTH (code))
9418 default:
9419 case 3: treeop2 = TREE_OPERAND (exp, 2);
9420 case 2: treeop1 = TREE_OPERAND (exp, 1);
9421 case 1: treeop0 = TREE_OPERAND (exp, 0);
9422 case 0: break;
9424 ops.code = code;
9425 ops.type = type;
9426 ops.op0 = treeop0;
9427 ops.op1 = treeop1;
9428 ops.op2 = treeop2;
9429 ops.location = loc;
9431 ignore = (target == const0_rtx
9432 || ((CONVERT_EXPR_CODE_P (code)
9433 || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
9434 && TREE_CODE (type) == VOID_TYPE));
9436 /* An operation in what may be a bit-field type needs the
9437 result to be reduced to the precision of the bit-field type,
9438 which is narrower than that of the type's mode. */
9439 reduce_bit_field = (!ignore
9440 && INTEGRAL_TYPE_P (type)
9441 && GET_MODE_PRECISION (mode) > TYPE_PRECISION (type));
9443 /* If we are going to ignore this result, we need only do something
9444 if there is a side-effect somewhere in the expression. If there
9445 is, short-circuit the most common cases here. Note that we must
9446 not call expand_expr with anything but const0_rtx in case this
9447 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
9449 if (ignore)
9451 if (! TREE_SIDE_EFFECTS (exp))
9452 return const0_rtx;
9454 /* Ensure we reference a volatile object even if value is ignored, but
9455 don't do this if all we are doing is taking its address. */
9456 if (TREE_THIS_VOLATILE (exp)
9457 && TREE_CODE (exp) != FUNCTION_DECL
9458 && mode != VOIDmode && mode != BLKmode
9459 && modifier != EXPAND_CONST_ADDRESS)
9461 temp = expand_expr (exp, NULL_RTX, VOIDmode, modifier);
9462 if (MEM_P (temp))
9463 copy_to_reg (temp);
9464 return const0_rtx;
9467 if (TREE_CODE_CLASS (code) == tcc_unary
9468 || code == BIT_FIELD_REF
9469 || code == COMPONENT_REF
9470 || code == INDIRECT_REF)
9471 return expand_expr (treeop0, const0_rtx, VOIDmode,
9472 modifier);
9474 else if (TREE_CODE_CLASS (code) == tcc_binary
9475 || TREE_CODE_CLASS (code) == tcc_comparison
9476 || code == ARRAY_REF || code == ARRAY_RANGE_REF)
9478 expand_expr (treeop0, const0_rtx, VOIDmode, modifier);
9479 expand_expr (treeop1, const0_rtx, VOIDmode, modifier);
9480 return const0_rtx;
9483 target = 0;
9486 if (reduce_bit_field && modifier == EXPAND_STACK_PARM)
9487 target = 0;
9489 /* Use subtarget as the target for operand 0 of a binary operation. */
9490 subtarget = get_subtarget (target);
9491 original_target = target;
9493 switch (code)
9495 case LABEL_DECL:
9497 tree function = decl_function_context (exp);
9499 temp = label_rtx (exp);
9500 temp = gen_rtx_LABEL_REF (Pmode, temp);
9502 if (function != current_function_decl
9503 && function != 0)
9504 LABEL_REF_NONLOCAL_P (temp) = 1;
9506 temp = gen_rtx_MEM (FUNCTION_MODE, temp);
9507 return temp;
9510 case SSA_NAME:
9511 /* ??? ivopts calls expander, without any preparation from
9512 out-of-ssa. So fake instructions as if this was an access to the
9513 base variable. This unnecessarily allocates a pseudo, see how we can
9514 reuse it, if partition base vars have it set already. */
9515 if (!currently_expanding_to_rtl)
9517 tree var = SSA_NAME_VAR (exp);
9518 if (var && DECL_RTL_SET_P (var))
9519 return DECL_RTL (var);
9520 return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp)),
9521 LAST_VIRTUAL_REGISTER + 1);
9524 g = get_gimple_for_ssa_name (exp);
9525 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9526 if (g == NULL
9527 && modifier == EXPAND_INITIALIZER
9528 && !SSA_NAME_IS_DEFAULT_DEF (exp)
9529 && (optimize || !SSA_NAME_VAR (exp)
9530 || DECL_IGNORED_P (SSA_NAME_VAR (exp)))
9531 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp)))
9532 g = SSA_NAME_DEF_STMT (exp);
9533 if (g)
9535 rtx r;
9536 location_t saved_loc = curr_insn_location ();
9537 location_t loc = gimple_location (g);
9538 if (loc != UNKNOWN_LOCATION)
9539 set_curr_insn_location (loc);
9540 ops.code = gimple_assign_rhs_code (g);
9541 switch (get_gimple_rhs_class (ops.code))
9543 case GIMPLE_TERNARY_RHS:
9544 ops.op2 = gimple_assign_rhs3 (g);
9545 /* Fallthru */
9546 case GIMPLE_BINARY_RHS:
9547 ops.op1 = gimple_assign_rhs2 (g);
9549 /* Try to expand conditonal compare. */
9550 if (targetm.gen_ccmp_first)
9552 gcc_checking_assert (targetm.gen_ccmp_next != NULL);
9553 r = expand_ccmp_expr (g);
9554 if (r)
9555 break;
9557 /* Fallthru */
9558 case GIMPLE_UNARY_RHS:
9559 ops.op0 = gimple_assign_rhs1 (g);
9560 ops.type = TREE_TYPE (gimple_assign_lhs (g));
9561 ops.location = loc;
9562 r = expand_expr_real_2 (&ops, target, tmode, modifier);
9563 break;
9564 case GIMPLE_SINGLE_RHS:
9566 r = expand_expr_real (gimple_assign_rhs1 (g), target,
9567 tmode, modifier, NULL, inner_reference_p);
9568 break;
9570 default:
9571 gcc_unreachable ();
9573 set_curr_insn_location (saved_loc);
9574 if (REG_P (r) && !REG_EXPR (r))
9575 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp), r);
9576 return r;
9579 ssa_name = exp;
9580 decl_rtl = get_rtx_for_ssa_name (ssa_name);
9581 exp = SSA_NAME_VAR (ssa_name);
9582 goto expand_decl_rtl;
9584 case PARM_DECL:
9585 case VAR_DECL:
9586 /* If a static var's type was incomplete when the decl was written,
9587 but the type is complete now, lay out the decl now. */
9588 if (DECL_SIZE (exp) == 0
9589 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp))
9590 && (TREE_STATIC (exp) || DECL_EXTERNAL (exp)))
9591 layout_decl (exp, 0);
9593 /* ... fall through ... */
9595 case FUNCTION_DECL:
9596 case RESULT_DECL:
9597 decl_rtl = DECL_RTL (exp);
9598 expand_decl_rtl:
9599 gcc_assert (decl_rtl);
9600 decl_rtl = copy_rtx (decl_rtl);
9601 /* Record writes to register variables. */
9602 if (modifier == EXPAND_WRITE
9603 && REG_P (decl_rtl)
9604 && HARD_REGISTER_P (decl_rtl))
9605 add_to_hard_reg_set (&crtl->asm_clobbers,
9606 GET_MODE (decl_rtl), REGNO (decl_rtl));
9608 /* Ensure variable marked as used even if it doesn't go through
9609 a parser. If it hasn't be used yet, write out an external
9610 definition. */
9611 if (exp)
9612 TREE_USED (exp) = 1;
9614 /* Show we haven't gotten RTL for this yet. */
9615 temp = 0;
9617 /* Variables inherited from containing functions should have
9618 been lowered by this point. */
9619 if (exp)
9620 context = decl_function_context (exp);
9621 gcc_assert (!exp
9622 || SCOPE_FILE_SCOPE_P (context)
9623 || context == current_function_decl
9624 || TREE_STATIC (exp)
9625 || DECL_EXTERNAL (exp)
9626 /* ??? C++ creates functions that are not TREE_STATIC. */
9627 || TREE_CODE (exp) == FUNCTION_DECL);
9629 /* This is the case of an array whose size is to be determined
9630 from its initializer, while the initializer is still being parsed.
9631 ??? We aren't parsing while expanding anymore. */
9633 if (MEM_P (decl_rtl) && REG_P (XEXP (decl_rtl, 0)))
9634 temp = validize_mem (decl_rtl);
9636 /* If DECL_RTL is memory, we are in the normal case and the
9637 address is not valid, get the address into a register. */
9639 else if (MEM_P (decl_rtl) && modifier != EXPAND_INITIALIZER)
9641 if (alt_rtl)
9642 *alt_rtl = decl_rtl;
9643 decl_rtl = use_anchored_address (decl_rtl);
9644 if (modifier != EXPAND_CONST_ADDRESS
9645 && modifier != EXPAND_SUM
9646 && !memory_address_addr_space_p (exp ? DECL_MODE (exp)
9647 : GET_MODE (decl_rtl),
9648 XEXP (decl_rtl, 0),
9649 MEM_ADDR_SPACE (decl_rtl)))
9650 temp = replace_equiv_address (decl_rtl,
9651 copy_rtx (XEXP (decl_rtl, 0)));
9654 /* If we got something, return it. But first, set the alignment
9655 if the address is a register. */
9656 if (temp != 0)
9658 if (exp && MEM_P (temp) && REG_P (XEXP (temp, 0)))
9659 mark_reg_pointer (XEXP (temp, 0), DECL_ALIGN (exp));
9661 return temp;
9664 if (exp)
9665 dmode = DECL_MODE (exp);
9666 else
9667 dmode = TYPE_MODE (TREE_TYPE (ssa_name));
9669 /* If the mode of DECL_RTL does not match that of the decl,
9670 there are two cases: we are dealing with a BLKmode value
9671 that is returned in a register, or we are dealing with
9672 a promoted value. In the latter case, return a SUBREG
9673 of the wanted mode, but mark it so that we know that it
9674 was already extended. */
9675 if (REG_P (decl_rtl)
9676 && dmode != BLKmode
9677 && GET_MODE (decl_rtl) != dmode)
9679 machine_mode pmode;
9681 /* Get the signedness to be used for this variable. Ensure we get
9682 the same mode we got when the variable was declared. */
9683 if (code != SSA_NAME)
9684 pmode = promote_decl_mode (exp, &unsignedp);
9685 else if ((g = SSA_NAME_DEF_STMT (ssa_name))
9686 && gimple_code (g) == GIMPLE_CALL
9687 && !gimple_call_internal_p (g))
9688 pmode = promote_function_mode (type, mode, &unsignedp,
9689 gimple_call_fntype (g),
9691 else
9692 pmode = promote_ssa_mode (ssa_name, &unsignedp);
9693 gcc_assert (GET_MODE (decl_rtl) == pmode);
9695 temp = gen_lowpart_SUBREG (mode, decl_rtl);
9696 SUBREG_PROMOTED_VAR_P (temp) = 1;
9697 SUBREG_PROMOTED_SET (temp, unsignedp);
9698 return temp;
9701 return decl_rtl;
9703 case INTEGER_CST:
9704 /* Given that TYPE_PRECISION (type) is not always equal to
9705 GET_MODE_PRECISION (TYPE_MODE (type)), we need to extend from
9706 the former to the latter according to the signedness of the
9707 type. */
9708 temp = immed_wide_int_const (wide_int::from
9709 (exp,
9710 GET_MODE_PRECISION (TYPE_MODE (type)),
9711 TYPE_SIGN (type)),
9712 TYPE_MODE (type));
9713 return temp;
9715 case VECTOR_CST:
9717 tree tmp = NULL_TREE;
9718 if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
9719 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT
9720 || GET_MODE_CLASS (mode) == MODE_VECTOR_FRACT
9721 || GET_MODE_CLASS (mode) == MODE_VECTOR_UFRACT
9722 || GET_MODE_CLASS (mode) == MODE_VECTOR_ACCUM
9723 || GET_MODE_CLASS (mode) == MODE_VECTOR_UACCUM)
9724 return const_vector_from_tree (exp);
9725 if (GET_MODE_CLASS (mode) == MODE_INT)
9727 if (VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (exp)))
9728 return const_scalar_mask_from_tree (exp);
9729 else
9731 tree type_for_mode = lang_hooks.types.type_for_mode (mode, 1);
9732 if (type_for_mode)
9733 tmp = fold_unary_loc (loc, VIEW_CONVERT_EXPR,
9734 type_for_mode, exp);
9737 if (!tmp)
9739 vec<constructor_elt, va_gc> *v;
9740 unsigned i;
9741 vec_alloc (v, VECTOR_CST_NELTS (exp));
9742 for (i = 0; i < VECTOR_CST_NELTS (exp); ++i)
9743 CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, VECTOR_CST_ELT (exp, i));
9744 tmp = build_constructor (type, v);
9746 return expand_expr (tmp, ignore ? const0_rtx : target,
9747 tmode, modifier);
9750 case CONST_DECL:
9751 return expand_expr (DECL_INITIAL (exp), target, VOIDmode, modifier);
9753 case REAL_CST:
9754 /* If optimized, generate immediate CONST_DOUBLE
9755 which will be turned into memory by reload if necessary.
9757 We used to force a register so that loop.c could see it. But
9758 this does not allow gen_* patterns to perform optimizations with
9759 the constants. It also produces two insns in cases like "x = 1.0;".
9760 On most machines, floating-point constants are not permitted in
9761 many insns, so we'd end up copying it to a register in any case.
9763 Now, we do the copying in expand_binop, if appropriate. */
9764 return const_double_from_real_value (TREE_REAL_CST (exp),
9765 TYPE_MODE (TREE_TYPE (exp)));
9767 case FIXED_CST:
9768 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp),
9769 TYPE_MODE (TREE_TYPE (exp)));
9771 case COMPLEX_CST:
9772 /* Handle evaluating a complex constant in a CONCAT target. */
9773 if (original_target && GET_CODE (original_target) == CONCAT)
9775 machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
9776 rtx rtarg, itarg;
9778 rtarg = XEXP (original_target, 0);
9779 itarg = XEXP (original_target, 1);
9781 /* Move the real and imaginary parts separately. */
9782 op0 = expand_expr (TREE_REALPART (exp), rtarg, mode, EXPAND_NORMAL);
9783 op1 = expand_expr (TREE_IMAGPART (exp), itarg, mode, EXPAND_NORMAL);
9785 if (op0 != rtarg)
9786 emit_move_insn (rtarg, op0);
9787 if (op1 != itarg)
9788 emit_move_insn (itarg, op1);
9790 return original_target;
9793 /* ... fall through ... */
9795 case STRING_CST:
9796 temp = expand_expr_constant (exp, 1, modifier);
9798 /* temp contains a constant address.
9799 On RISC machines where a constant address isn't valid,
9800 make some insns to get that address into a register. */
9801 if (modifier != EXPAND_CONST_ADDRESS
9802 && modifier != EXPAND_INITIALIZER
9803 && modifier != EXPAND_SUM
9804 && ! memory_address_addr_space_p (mode, XEXP (temp, 0),
9805 MEM_ADDR_SPACE (temp)))
9806 return replace_equiv_address (temp,
9807 copy_rtx (XEXP (temp, 0)));
9808 return temp;
9810 case SAVE_EXPR:
9812 tree val = treeop0;
9813 rtx ret = expand_expr_real_1 (val, target, tmode, modifier, alt_rtl,
9814 inner_reference_p);
9816 if (!SAVE_EXPR_RESOLVED_P (exp))
9818 /* We can indeed still hit this case, typically via builtin
9819 expanders calling save_expr immediately before expanding
9820 something. Assume this means that we only have to deal
9821 with non-BLKmode values. */
9822 gcc_assert (GET_MODE (ret) != BLKmode);
9824 val = build_decl (curr_insn_location (),
9825 VAR_DECL, NULL, TREE_TYPE (exp));
9826 DECL_ARTIFICIAL (val) = 1;
9827 DECL_IGNORED_P (val) = 1;
9828 treeop0 = val;
9829 TREE_OPERAND (exp, 0) = treeop0;
9830 SAVE_EXPR_RESOLVED_P (exp) = 1;
9832 if (!CONSTANT_P (ret))
9833 ret = copy_to_reg (ret);
9834 SET_DECL_RTL (val, ret);
9837 return ret;
9841 case CONSTRUCTOR:
9842 /* If we don't need the result, just ensure we evaluate any
9843 subexpressions. */
9844 if (ignore)
9846 unsigned HOST_WIDE_INT idx;
9847 tree value;
9849 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
9850 expand_expr (value, const0_rtx, VOIDmode, EXPAND_NORMAL);
9852 return const0_rtx;
9855 return expand_constructor (exp, target, modifier, false);
9857 case TARGET_MEM_REF:
9859 addr_space_t as
9860 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
9861 enum insn_code icode;
9862 unsigned int align;
9864 op0 = addr_for_mem_ref (exp, as, true);
9865 op0 = memory_address_addr_space (mode, op0, as);
9866 temp = gen_rtx_MEM (mode, op0);
9867 set_mem_attributes (temp, exp, 0);
9868 set_mem_addr_space (temp, as);
9869 align = get_object_alignment (exp);
9870 if (modifier != EXPAND_WRITE
9871 && modifier != EXPAND_MEMORY
9872 && mode != BLKmode
9873 && align < GET_MODE_ALIGNMENT (mode)
9874 /* If the target does not have special handling for unaligned
9875 loads of mode then it can use regular moves for them. */
9876 && ((icode = optab_handler (movmisalign_optab, mode))
9877 != CODE_FOR_nothing))
9879 struct expand_operand ops[2];
9881 /* We've already validated the memory, and we're creating a
9882 new pseudo destination. The predicates really can't fail,
9883 nor can the generator. */
9884 create_output_operand (&ops[0], NULL_RTX, mode);
9885 create_fixed_operand (&ops[1], temp);
9886 expand_insn (icode, 2, ops);
9887 temp = ops[0].value;
9889 return temp;
9892 case MEM_REF:
9894 const bool reverse = REF_REVERSE_STORAGE_ORDER (exp);
9895 addr_space_t as
9896 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
9897 machine_mode address_mode;
9898 tree base = TREE_OPERAND (exp, 0);
9899 gimple *def_stmt;
9900 enum insn_code icode;
9901 unsigned align;
9902 /* Handle expansion of non-aliased memory with non-BLKmode. That
9903 might end up in a register. */
9904 if (mem_ref_refers_to_non_mem_p (exp))
9906 HOST_WIDE_INT offset = mem_ref_offset (exp).to_short_addr ();
9907 base = TREE_OPERAND (base, 0);
9908 if (offset == 0
9909 && !reverse
9910 && tree_fits_uhwi_p (TYPE_SIZE (type))
9911 && (GET_MODE_BITSIZE (DECL_MODE (base))
9912 == tree_to_uhwi (TYPE_SIZE (type))))
9913 return expand_expr (build1 (VIEW_CONVERT_EXPR, type, base),
9914 target, tmode, modifier);
9915 if (TYPE_MODE (type) == BLKmode)
9917 temp = assign_stack_temp (DECL_MODE (base),
9918 GET_MODE_SIZE (DECL_MODE (base)));
9919 store_expr (base, temp, 0, false, false);
9920 temp = adjust_address (temp, BLKmode, offset);
9921 set_mem_size (temp, int_size_in_bytes (type));
9922 return temp;
9924 exp = build3 (BIT_FIELD_REF, type, base, TYPE_SIZE (type),
9925 bitsize_int (offset * BITS_PER_UNIT));
9926 REF_REVERSE_STORAGE_ORDER (exp) = reverse;
9927 return expand_expr (exp, target, tmode, modifier);
9929 address_mode = targetm.addr_space.address_mode (as);
9930 base = TREE_OPERAND (exp, 0);
9931 if ((def_stmt = get_def_for_expr (base, BIT_AND_EXPR)))
9933 tree mask = gimple_assign_rhs2 (def_stmt);
9934 base = build2 (BIT_AND_EXPR, TREE_TYPE (base),
9935 gimple_assign_rhs1 (def_stmt), mask);
9936 TREE_OPERAND (exp, 0) = base;
9938 align = get_object_alignment (exp);
9939 op0 = expand_expr (base, NULL_RTX, VOIDmode, EXPAND_SUM);
9940 op0 = memory_address_addr_space (mode, op0, as);
9941 if (!integer_zerop (TREE_OPERAND (exp, 1)))
9943 rtx off = immed_wide_int_const (mem_ref_offset (exp), address_mode);
9944 op0 = simplify_gen_binary (PLUS, address_mode, op0, off);
9945 op0 = memory_address_addr_space (mode, op0, as);
9947 temp = gen_rtx_MEM (mode, op0);
9948 set_mem_attributes (temp, exp, 0);
9949 set_mem_addr_space (temp, as);
9950 if (TREE_THIS_VOLATILE (exp))
9951 MEM_VOLATILE_P (temp) = 1;
9952 if (modifier != EXPAND_WRITE
9953 && modifier != EXPAND_MEMORY
9954 && !inner_reference_p
9955 && mode != BLKmode
9956 && align < GET_MODE_ALIGNMENT (mode))
9958 if ((icode = optab_handler (movmisalign_optab, mode))
9959 != CODE_FOR_nothing)
9961 struct expand_operand ops[2];
9963 /* We've already validated the memory, and we're creating a
9964 new pseudo destination. The predicates really can't fail,
9965 nor can the generator. */
9966 create_output_operand (&ops[0], NULL_RTX, mode);
9967 create_fixed_operand (&ops[1], temp);
9968 expand_insn (icode, 2, ops);
9969 temp = ops[0].value;
9971 else if (SLOW_UNALIGNED_ACCESS (mode, align))
9972 temp = extract_bit_field (temp, GET_MODE_BITSIZE (mode),
9973 0, TYPE_UNSIGNED (TREE_TYPE (exp)),
9974 (modifier == EXPAND_STACK_PARM
9975 ? NULL_RTX : target),
9976 mode, mode, false);
9978 if (reverse
9979 && modifier != EXPAND_MEMORY
9980 && modifier != EXPAND_WRITE)
9981 temp = flip_storage_order (mode, temp);
9982 return temp;
9985 case ARRAY_REF:
9988 tree array = treeop0;
9989 tree index = treeop1;
9990 tree init;
9992 /* Fold an expression like: "foo"[2].
9993 This is not done in fold so it won't happen inside &.
9994 Don't fold if this is for wide characters since it's too
9995 difficult to do correctly and this is a very rare case. */
9997 if (modifier != EXPAND_CONST_ADDRESS
9998 && modifier != EXPAND_INITIALIZER
9999 && modifier != EXPAND_MEMORY)
10001 tree t = fold_read_from_constant_string (exp);
10003 if (t)
10004 return expand_expr (t, target, tmode, modifier);
10007 /* If this is a constant index into a constant array,
10008 just get the value from the array. Handle both the cases when
10009 we have an explicit constructor and when our operand is a variable
10010 that was declared const. */
10012 if (modifier != EXPAND_CONST_ADDRESS
10013 && modifier != EXPAND_INITIALIZER
10014 && modifier != EXPAND_MEMORY
10015 && TREE_CODE (array) == CONSTRUCTOR
10016 && ! TREE_SIDE_EFFECTS (array)
10017 && TREE_CODE (index) == INTEGER_CST)
10019 unsigned HOST_WIDE_INT ix;
10020 tree field, value;
10022 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array), ix,
10023 field, value)
10024 if (tree_int_cst_equal (field, index))
10026 if (!TREE_SIDE_EFFECTS (value))
10027 return expand_expr (fold (value), target, tmode, modifier);
10028 break;
10032 else if (optimize >= 1
10033 && modifier != EXPAND_CONST_ADDRESS
10034 && modifier != EXPAND_INITIALIZER
10035 && modifier != EXPAND_MEMORY
10036 && TREE_READONLY (array) && ! TREE_SIDE_EFFECTS (array)
10037 && TREE_CODE (index) == INTEGER_CST
10038 && (TREE_CODE (array) == VAR_DECL
10039 || TREE_CODE (array) == CONST_DECL)
10040 && (init = ctor_for_folding (array)) != error_mark_node)
10042 if (init == NULL_TREE)
10044 tree value = build_zero_cst (type);
10045 if (TREE_CODE (value) == CONSTRUCTOR)
10047 /* If VALUE is a CONSTRUCTOR, this optimization is only
10048 useful if this doesn't store the CONSTRUCTOR into
10049 memory. If it does, it is more efficient to just
10050 load the data from the array directly. */
10051 rtx ret = expand_constructor (value, target,
10052 modifier, true);
10053 if (ret == NULL_RTX)
10054 value = NULL_TREE;
10057 if (value)
10058 return expand_expr (value, target, tmode, modifier);
10060 else if (TREE_CODE (init) == CONSTRUCTOR)
10062 unsigned HOST_WIDE_INT ix;
10063 tree field, value;
10065 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), ix,
10066 field, value)
10067 if (tree_int_cst_equal (field, index))
10069 if (TREE_SIDE_EFFECTS (value))
10070 break;
10072 if (TREE_CODE (value) == CONSTRUCTOR)
10074 /* If VALUE is a CONSTRUCTOR, this
10075 optimization is only useful if
10076 this doesn't store the CONSTRUCTOR
10077 into memory. If it does, it is more
10078 efficient to just load the data from
10079 the array directly. */
10080 rtx ret = expand_constructor (value, target,
10081 modifier, true);
10082 if (ret == NULL_RTX)
10083 break;
10086 return
10087 expand_expr (fold (value), target, tmode, modifier);
10090 else if (TREE_CODE (init) == STRING_CST)
10092 tree low_bound = array_ref_low_bound (exp);
10093 tree index1 = fold_convert_loc (loc, sizetype, treeop1);
10095 /* Optimize the special case of a zero lower bound.
10097 We convert the lower bound to sizetype to avoid problems
10098 with constant folding. E.g. suppose the lower bound is
10099 1 and its mode is QI. Without the conversion
10100 (ARRAY + (INDEX - (unsigned char)1))
10101 becomes
10102 (ARRAY + (-(unsigned char)1) + INDEX)
10103 which becomes
10104 (ARRAY + 255 + INDEX). Oops! */
10105 if (!integer_zerop (low_bound))
10106 index1 = size_diffop_loc (loc, index1,
10107 fold_convert_loc (loc, sizetype,
10108 low_bound));
10110 if (compare_tree_int (index1, TREE_STRING_LENGTH (init)) < 0)
10112 tree type = TREE_TYPE (TREE_TYPE (init));
10113 machine_mode mode = TYPE_MODE (type);
10115 if (GET_MODE_CLASS (mode) == MODE_INT
10116 && GET_MODE_SIZE (mode) == 1)
10117 return gen_int_mode (TREE_STRING_POINTER (init)
10118 [TREE_INT_CST_LOW (index1)],
10119 mode);
10124 goto normal_inner_ref;
10126 case COMPONENT_REF:
10127 /* If the operand is a CONSTRUCTOR, we can just extract the
10128 appropriate field if it is present. */
10129 if (TREE_CODE (treeop0) == CONSTRUCTOR)
10131 unsigned HOST_WIDE_INT idx;
10132 tree field, value;
10134 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0),
10135 idx, field, value)
10136 if (field == treeop1
10137 /* We can normally use the value of the field in the
10138 CONSTRUCTOR. However, if this is a bitfield in
10139 an integral mode that we can fit in a HOST_WIDE_INT,
10140 we must mask only the number of bits in the bitfield,
10141 since this is done implicitly by the constructor. If
10142 the bitfield does not meet either of those conditions,
10143 we can't do this optimization. */
10144 && (! DECL_BIT_FIELD (field)
10145 || ((GET_MODE_CLASS (DECL_MODE (field)) == MODE_INT)
10146 && (GET_MODE_PRECISION (DECL_MODE (field))
10147 <= HOST_BITS_PER_WIDE_INT))))
10149 if (DECL_BIT_FIELD (field)
10150 && modifier == EXPAND_STACK_PARM)
10151 target = 0;
10152 op0 = expand_expr (value, target, tmode, modifier);
10153 if (DECL_BIT_FIELD (field))
10155 HOST_WIDE_INT bitsize = TREE_INT_CST_LOW (DECL_SIZE (field));
10156 machine_mode imode = TYPE_MODE (TREE_TYPE (field));
10158 if (TYPE_UNSIGNED (TREE_TYPE (field)))
10160 op1 = gen_int_mode (((HOST_WIDE_INT) 1 << bitsize) - 1,
10161 imode);
10162 op0 = expand_and (imode, op0, op1, target);
10164 else
10166 int count = GET_MODE_PRECISION (imode) - bitsize;
10168 op0 = expand_shift (LSHIFT_EXPR, imode, op0, count,
10169 target, 0);
10170 op0 = expand_shift (RSHIFT_EXPR, imode, op0, count,
10171 target, 0);
10175 return op0;
10178 goto normal_inner_ref;
10180 case BIT_FIELD_REF:
10181 case ARRAY_RANGE_REF:
10182 normal_inner_ref:
10184 machine_mode mode1, mode2;
10185 HOST_WIDE_INT bitsize, bitpos;
10186 tree offset;
10187 int reversep, volatilep = 0, must_force_mem;
10188 tree tem
10189 = get_inner_reference (exp, &bitsize, &bitpos, &offset, &mode1,
10190 &unsignedp, &reversep, &volatilep, true);
10191 rtx orig_op0, memloc;
10192 bool clear_mem_expr = false;
10194 /* If we got back the original object, something is wrong. Perhaps
10195 we are evaluating an expression too early. In any event, don't
10196 infinitely recurse. */
10197 gcc_assert (tem != exp);
10199 /* If TEM's type is a union of variable size, pass TARGET to the inner
10200 computation, since it will need a temporary and TARGET is known
10201 to have to do. This occurs in unchecked conversion in Ada. */
10202 orig_op0 = op0
10203 = expand_expr_real (tem,
10204 (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
10205 && COMPLETE_TYPE_P (TREE_TYPE (tem))
10206 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
10207 != INTEGER_CST)
10208 && modifier != EXPAND_STACK_PARM
10209 ? target : NULL_RTX),
10210 VOIDmode,
10211 modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier,
10212 NULL, true);
10214 /* If the field has a mode, we want to access it in the
10215 field's mode, not the computed mode.
10216 If a MEM has VOIDmode (external with incomplete type),
10217 use BLKmode for it instead. */
10218 if (MEM_P (op0))
10220 if (mode1 != VOIDmode)
10221 op0 = adjust_address (op0, mode1, 0);
10222 else if (GET_MODE (op0) == VOIDmode)
10223 op0 = adjust_address (op0, BLKmode, 0);
10226 mode2
10227 = CONSTANT_P (op0) ? TYPE_MODE (TREE_TYPE (tem)) : GET_MODE (op0);
10229 /* If we have either an offset, a BLKmode result, or a reference
10230 outside the underlying object, we must force it to memory.
10231 Such a case can occur in Ada if we have unchecked conversion
10232 of an expression from a scalar type to an aggregate type or
10233 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
10234 passed a partially uninitialized object or a view-conversion
10235 to a larger size. */
10236 must_force_mem = (offset
10237 || mode1 == BLKmode
10238 || bitpos + bitsize > GET_MODE_BITSIZE (mode2));
10240 /* Handle CONCAT first. */
10241 if (GET_CODE (op0) == CONCAT && !must_force_mem)
10243 if (bitpos == 0
10244 && bitsize == GET_MODE_BITSIZE (GET_MODE (op0)))
10246 if (reversep)
10247 op0 = flip_storage_order (GET_MODE (op0), op0);
10248 return op0;
10250 if (bitpos == 0
10251 && bitsize == GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0)))
10252 && bitsize)
10254 op0 = XEXP (op0, 0);
10255 mode2 = GET_MODE (op0);
10257 else if (bitpos == GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0)))
10258 && bitsize == GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 1)))
10259 && bitpos
10260 && bitsize)
10262 op0 = XEXP (op0, 1);
10263 bitpos = 0;
10264 mode2 = GET_MODE (op0);
10266 else
10267 /* Otherwise force into memory. */
10268 must_force_mem = 1;
10271 /* If this is a constant, put it in a register if it is a legitimate
10272 constant and we don't need a memory reference. */
10273 if (CONSTANT_P (op0)
10274 && mode2 != BLKmode
10275 && targetm.legitimate_constant_p (mode2, op0)
10276 && !must_force_mem)
10277 op0 = force_reg (mode2, op0);
10279 /* Otherwise, if this is a constant, try to force it to the constant
10280 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
10281 is a legitimate constant. */
10282 else if (CONSTANT_P (op0) && (memloc = force_const_mem (mode2, op0)))
10283 op0 = validize_mem (memloc);
10285 /* Otherwise, if this is a constant or the object is not in memory
10286 and need be, put it there. */
10287 else if (CONSTANT_P (op0) || (!MEM_P (op0) && must_force_mem))
10289 memloc = assign_temp (TREE_TYPE (tem), 1, 1);
10290 emit_move_insn (memloc, op0);
10291 op0 = memloc;
10292 clear_mem_expr = true;
10295 if (offset)
10297 machine_mode address_mode;
10298 rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode,
10299 EXPAND_SUM);
10301 gcc_assert (MEM_P (op0));
10303 address_mode = get_address_mode (op0);
10304 if (GET_MODE (offset_rtx) != address_mode)
10306 /* We cannot be sure that the RTL in offset_rtx is valid outside
10307 of a memory address context, so force it into a register
10308 before attempting to convert it to the desired mode. */
10309 offset_rtx = force_operand (offset_rtx, NULL_RTX);
10310 offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
10313 /* See the comment in expand_assignment for the rationale. */
10314 if (mode1 != VOIDmode
10315 && bitpos != 0
10316 && bitsize > 0
10317 && (bitpos % bitsize) == 0
10318 && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
10319 && MEM_ALIGN (op0) >= GET_MODE_ALIGNMENT (mode1))
10321 op0 = adjust_address (op0, mode1, bitpos / BITS_PER_UNIT);
10322 bitpos = 0;
10325 op0 = offset_address (op0, offset_rtx,
10326 highest_pow2_factor (offset));
10329 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
10330 record its alignment as BIGGEST_ALIGNMENT. */
10331 if (MEM_P (op0) && bitpos == 0 && offset != 0
10332 && is_aligning_offset (offset, tem))
10333 set_mem_align (op0, BIGGEST_ALIGNMENT);
10335 /* Don't forget about volatility even if this is a bitfield. */
10336 if (MEM_P (op0) && volatilep && ! MEM_VOLATILE_P (op0))
10338 if (op0 == orig_op0)
10339 op0 = copy_rtx (op0);
10341 MEM_VOLATILE_P (op0) = 1;
10344 /* In cases where an aligned union has an unaligned object
10345 as a field, we might be extracting a BLKmode value from
10346 an integer-mode (e.g., SImode) object. Handle this case
10347 by doing the extract into an object as wide as the field
10348 (which we know to be the width of a basic mode), then
10349 storing into memory, and changing the mode to BLKmode. */
10350 if (mode1 == VOIDmode
10351 || REG_P (op0) || GET_CODE (op0) == SUBREG
10352 || (mode1 != BLKmode && ! direct_load[(int) mode1]
10353 && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
10354 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT
10355 && modifier != EXPAND_CONST_ADDRESS
10356 && modifier != EXPAND_INITIALIZER
10357 && modifier != EXPAND_MEMORY)
10358 /* If the bitfield is volatile and the bitsize
10359 is narrower than the access size of the bitfield,
10360 we need to extract bitfields from the access. */
10361 || (volatilep && TREE_CODE (exp) == COMPONENT_REF
10362 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1))
10363 && mode1 != BLKmode
10364 && bitsize < GET_MODE_SIZE (mode1) * BITS_PER_UNIT)
10365 /* If the field isn't aligned enough to fetch as a memref,
10366 fetch it as a bit field. */
10367 || (mode1 != BLKmode
10368 && (((TYPE_ALIGN (TREE_TYPE (tem)) < GET_MODE_ALIGNMENT (mode)
10369 || (bitpos % GET_MODE_ALIGNMENT (mode) != 0)
10370 || (MEM_P (op0)
10371 && (MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode1)
10372 || (bitpos % GET_MODE_ALIGNMENT (mode1) != 0))))
10373 && modifier != EXPAND_MEMORY
10374 && ((modifier == EXPAND_CONST_ADDRESS
10375 || modifier == EXPAND_INITIALIZER)
10376 ? STRICT_ALIGNMENT
10377 : SLOW_UNALIGNED_ACCESS (mode1, MEM_ALIGN (op0))))
10378 || (bitpos % BITS_PER_UNIT != 0)))
10379 /* If the type and the field are a constant size and the
10380 size of the type isn't the same size as the bitfield,
10381 we must use bitfield operations. */
10382 || (bitsize >= 0
10383 && TYPE_SIZE (TREE_TYPE (exp))
10384 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) == INTEGER_CST
10385 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)),
10386 bitsize)))
10388 machine_mode ext_mode = mode;
10390 if (ext_mode == BLKmode
10391 && ! (target != 0 && MEM_P (op0)
10392 && MEM_P (target)
10393 && bitpos % BITS_PER_UNIT == 0))
10394 ext_mode = mode_for_size (bitsize, MODE_INT, 1);
10396 if (ext_mode == BLKmode)
10398 if (target == 0)
10399 target = assign_temp (type, 1, 1);
10401 /* ??? Unlike the similar test a few lines below, this one is
10402 very likely obsolete. */
10403 if (bitsize == 0)
10404 return target;
10406 /* In this case, BITPOS must start at a byte boundary and
10407 TARGET, if specified, must be a MEM. */
10408 gcc_assert (MEM_P (op0)
10409 && (!target || MEM_P (target))
10410 && !(bitpos % BITS_PER_UNIT));
10412 emit_block_move (target,
10413 adjust_address (op0, VOIDmode,
10414 bitpos / BITS_PER_UNIT),
10415 GEN_INT ((bitsize + BITS_PER_UNIT - 1)
10416 / BITS_PER_UNIT),
10417 (modifier == EXPAND_STACK_PARM
10418 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
10420 return target;
10423 /* If we have nothing to extract, the result will be 0 for targets
10424 with SHIFT_COUNT_TRUNCATED == 0 and garbage otherwise. Always
10425 return 0 for the sake of consistency, as reading a zero-sized
10426 bitfield is valid in Ada and the value is fully specified. */
10427 if (bitsize == 0)
10428 return const0_rtx;
10430 op0 = validize_mem (op0);
10432 if (MEM_P (op0) && REG_P (XEXP (op0, 0)))
10433 mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
10435 /* If the result has a record type and the extraction is done in
10436 an integral mode, then the field may be not aligned on a byte
10437 boundary; in this case, if it has reverse storage order, it
10438 needs to be extracted as a scalar field with reverse storage
10439 order and put back into memory order afterwards. */
10440 if (TREE_CODE (type) == RECORD_TYPE
10441 && GET_MODE_CLASS (ext_mode) == MODE_INT)
10442 reversep = TYPE_REVERSE_STORAGE_ORDER (type);
10444 op0 = extract_bit_field (op0, bitsize, bitpos, unsignedp,
10445 (modifier == EXPAND_STACK_PARM
10446 ? NULL_RTX : target),
10447 ext_mode, ext_mode, reversep);
10449 /* If the result has a record type and the mode of OP0 is an
10450 integral mode then, if BITSIZE is narrower than this mode
10451 and this is for big-endian data, we must put the field
10452 into the high-order bits. And we must also put it back
10453 into memory order if it has been previously reversed. */
10454 if (TREE_CODE (type) == RECORD_TYPE
10455 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT)
10457 HOST_WIDE_INT size = GET_MODE_BITSIZE (GET_MODE (op0));
10459 if (bitsize < size
10460 && reversep ? !BYTES_BIG_ENDIAN : BYTES_BIG_ENDIAN)
10461 op0 = expand_shift (LSHIFT_EXPR, GET_MODE (op0), op0,
10462 size - bitsize, op0, 1);
10464 if (reversep)
10465 op0 = flip_storage_order (GET_MODE (op0), op0);
10468 /* If the result type is BLKmode, store the data into a temporary
10469 of the appropriate type, but with the mode corresponding to the
10470 mode for the data we have (op0's mode). */
10471 if (mode == BLKmode)
10473 rtx new_rtx
10474 = assign_stack_temp_for_type (ext_mode,
10475 GET_MODE_BITSIZE (ext_mode),
10476 type);
10477 emit_move_insn (new_rtx, op0);
10478 op0 = copy_rtx (new_rtx);
10479 PUT_MODE (op0, BLKmode);
10482 return op0;
10485 /* If the result is BLKmode, use that to access the object
10486 now as well. */
10487 if (mode == BLKmode)
10488 mode1 = BLKmode;
10490 /* Get a reference to just this component. */
10491 if (modifier == EXPAND_CONST_ADDRESS
10492 || modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
10493 op0 = adjust_address_nv (op0, mode1, bitpos / BITS_PER_UNIT);
10494 else
10495 op0 = adjust_address (op0, mode1, bitpos / BITS_PER_UNIT);
10497 if (op0 == orig_op0)
10498 op0 = copy_rtx (op0);
10500 set_mem_attributes (op0, exp, 0);
10502 if (REG_P (XEXP (op0, 0)))
10503 mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
10505 /* If op0 is a temporary because the original expressions was forced
10506 to memory, clear MEM_EXPR so that the original expression cannot
10507 be marked as addressable through MEM_EXPR of the temporary. */
10508 if (clear_mem_expr)
10509 set_mem_expr (op0, NULL_TREE);
10511 MEM_VOLATILE_P (op0) |= volatilep;
10513 if (reversep
10514 && modifier != EXPAND_MEMORY
10515 && modifier != EXPAND_WRITE)
10516 op0 = flip_storage_order (mode1, op0);
10518 if (mode == mode1 || mode1 == BLKmode || mode1 == tmode
10519 || modifier == EXPAND_CONST_ADDRESS
10520 || modifier == EXPAND_INITIALIZER)
10521 return op0;
10523 if (target == 0)
10524 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
10526 convert_move (target, op0, unsignedp);
10527 return target;
10530 case OBJ_TYPE_REF:
10531 return expand_expr (OBJ_TYPE_REF_EXPR (exp), target, tmode, modifier);
10533 case CALL_EXPR:
10534 /* All valid uses of __builtin_va_arg_pack () are removed during
10535 inlining. */
10536 if (CALL_EXPR_VA_ARG_PACK (exp))
10537 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp);
10539 tree fndecl = get_callee_fndecl (exp), attr;
10541 if (fndecl
10542 && (attr = lookup_attribute ("error",
10543 DECL_ATTRIBUTES (fndecl))) != NULL)
10544 error ("%Kcall to %qs declared with attribute error: %s",
10545 exp, identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 1)),
10546 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
10547 if (fndecl
10548 && (attr = lookup_attribute ("warning",
10549 DECL_ATTRIBUTES (fndecl))) != NULL)
10550 warning_at (tree_nonartificial_location (exp),
10551 0, "%Kcall to %qs declared with attribute warning: %s",
10552 exp, identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 1)),
10553 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
10555 /* Check for a built-in function. */
10556 if (fndecl && DECL_BUILT_IN (fndecl))
10558 gcc_assert (DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_FRONTEND);
10559 if (CALL_WITH_BOUNDS_P (exp))
10560 return expand_builtin_with_bounds (exp, target, subtarget,
10561 tmode, ignore);
10562 else
10563 return expand_builtin (exp, target, subtarget, tmode, ignore);
10566 return expand_call (exp, target, ignore);
10568 case VIEW_CONVERT_EXPR:
10569 op0 = NULL_RTX;
10571 /* If we are converting to BLKmode, try to avoid an intermediate
10572 temporary by fetching an inner memory reference. */
10573 if (mode == BLKmode
10574 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
10575 && TYPE_MODE (TREE_TYPE (treeop0)) != BLKmode
10576 && handled_component_p (treeop0))
10578 machine_mode mode1;
10579 HOST_WIDE_INT bitsize, bitpos;
10580 tree offset;
10581 int unsignedp, reversep, volatilep = 0;
10582 tree tem
10583 = get_inner_reference (treeop0, &bitsize, &bitpos, &offset, &mode1,
10584 &unsignedp, &reversep, &volatilep, true);
10585 rtx orig_op0;
10587 /* ??? We should work harder and deal with non-zero offsets. */
10588 if (!offset
10589 && (bitpos % BITS_PER_UNIT) == 0
10590 && !reversep
10591 && bitsize >= 0
10592 && compare_tree_int (TYPE_SIZE (type), bitsize) == 0)
10594 /* See the normal_inner_ref case for the rationale. */
10595 orig_op0
10596 = expand_expr_real (tem,
10597 (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
10598 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
10599 != INTEGER_CST)
10600 && modifier != EXPAND_STACK_PARM
10601 ? target : NULL_RTX),
10602 VOIDmode,
10603 modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier,
10604 NULL, true);
10606 if (MEM_P (orig_op0))
10608 op0 = orig_op0;
10610 /* Get a reference to just this component. */
10611 if (modifier == EXPAND_CONST_ADDRESS
10612 || modifier == EXPAND_SUM
10613 || modifier == EXPAND_INITIALIZER)
10614 op0 = adjust_address_nv (op0, mode, bitpos / BITS_PER_UNIT);
10615 else
10616 op0 = adjust_address (op0, mode, bitpos / BITS_PER_UNIT);
10618 if (op0 == orig_op0)
10619 op0 = copy_rtx (op0);
10621 set_mem_attributes (op0, treeop0, 0);
10622 if (REG_P (XEXP (op0, 0)))
10623 mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
10625 MEM_VOLATILE_P (op0) |= volatilep;
10630 if (!op0)
10631 op0 = expand_expr_real (treeop0, NULL_RTX, VOIDmode, modifier,
10632 NULL, inner_reference_p);
10634 /* If the input and output modes are both the same, we are done. */
10635 if (mode == GET_MODE (op0))
10637 /* If neither mode is BLKmode, and both modes are the same size
10638 then we can use gen_lowpart. */
10639 else if (mode != BLKmode && GET_MODE (op0) != BLKmode
10640 && (GET_MODE_PRECISION (mode)
10641 == GET_MODE_PRECISION (GET_MODE (op0)))
10642 && !COMPLEX_MODE_P (GET_MODE (op0)))
10644 if (GET_CODE (op0) == SUBREG)
10645 op0 = force_reg (GET_MODE (op0), op0);
10646 temp = gen_lowpart_common (mode, op0);
10647 if (temp)
10648 op0 = temp;
10649 else
10651 if (!REG_P (op0) && !MEM_P (op0))
10652 op0 = force_reg (GET_MODE (op0), op0);
10653 op0 = gen_lowpart (mode, op0);
10656 /* If both types are integral, convert from one mode to the other. */
10657 else if (INTEGRAL_TYPE_P (type) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0)))
10658 op0 = convert_modes (mode, GET_MODE (op0), op0,
10659 TYPE_UNSIGNED (TREE_TYPE (treeop0)));
10660 /* If the output type is a bit-field type, do an extraction. */
10661 else if (reduce_bit_field)
10662 return extract_bit_field (op0, TYPE_PRECISION (type), 0,
10663 TYPE_UNSIGNED (type), NULL_RTX,
10664 mode, mode, false);
10665 /* As a last resort, spill op0 to memory, and reload it in a
10666 different mode. */
10667 else if (!MEM_P (op0))
10669 /* If the operand is not a MEM, force it into memory. Since we
10670 are going to be changing the mode of the MEM, don't call
10671 force_const_mem for constants because we don't allow pool
10672 constants to change mode. */
10673 tree inner_type = TREE_TYPE (treeop0);
10675 gcc_assert (!TREE_ADDRESSABLE (exp));
10677 if (target == 0 || GET_MODE (target) != TYPE_MODE (inner_type))
10678 target
10679 = assign_stack_temp_for_type
10680 (TYPE_MODE (inner_type),
10681 GET_MODE_SIZE (TYPE_MODE (inner_type)), inner_type);
10683 emit_move_insn (target, op0);
10684 op0 = target;
10687 /* If OP0 is (now) a MEM, we need to deal with alignment issues. If the
10688 output type is such that the operand is known to be aligned, indicate
10689 that it is. Otherwise, we need only be concerned about alignment for
10690 non-BLKmode results. */
10691 if (MEM_P (op0))
10693 enum insn_code icode;
10695 if (TYPE_ALIGN_OK (type))
10697 /* ??? Copying the MEM without substantially changing it might
10698 run afoul of the code handling volatile memory references in
10699 store_expr, which assumes that TARGET is returned unmodified
10700 if it has been used. */
10701 op0 = copy_rtx (op0);
10702 set_mem_align (op0, MAX (MEM_ALIGN (op0), TYPE_ALIGN (type)));
10704 else if (modifier != EXPAND_WRITE
10705 && modifier != EXPAND_MEMORY
10706 && !inner_reference_p
10707 && mode != BLKmode
10708 && MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode))
10710 /* If the target does have special handling for unaligned
10711 loads of mode then use them. */
10712 if ((icode = optab_handler (movmisalign_optab, mode))
10713 != CODE_FOR_nothing)
10715 rtx reg;
10717 op0 = adjust_address (op0, mode, 0);
10718 /* We've already validated the memory, and we're creating a
10719 new pseudo destination. The predicates really can't
10720 fail. */
10721 reg = gen_reg_rtx (mode);
10723 /* Nor can the insn generator. */
10724 rtx_insn *insn = GEN_FCN (icode) (reg, op0);
10725 emit_insn (insn);
10726 return reg;
10728 else if (STRICT_ALIGNMENT)
10730 tree inner_type = TREE_TYPE (treeop0);
10731 HOST_WIDE_INT temp_size
10732 = MAX (int_size_in_bytes (inner_type),
10733 (HOST_WIDE_INT) GET_MODE_SIZE (mode));
10734 rtx new_rtx
10735 = assign_stack_temp_for_type (mode, temp_size, type);
10736 rtx new_with_op0_mode
10737 = adjust_address (new_rtx, GET_MODE (op0), 0);
10739 gcc_assert (!TREE_ADDRESSABLE (exp));
10741 if (GET_MODE (op0) == BLKmode)
10742 emit_block_move (new_with_op0_mode, op0,
10743 GEN_INT (GET_MODE_SIZE (mode)),
10744 (modifier == EXPAND_STACK_PARM
10745 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
10746 else
10747 emit_move_insn (new_with_op0_mode, op0);
10749 op0 = new_rtx;
10753 op0 = adjust_address (op0, mode, 0);
10756 return op0;
10758 case MODIFY_EXPR:
10760 tree lhs = treeop0;
10761 tree rhs = treeop1;
10762 gcc_assert (ignore);
10764 /* Check for |= or &= of a bitfield of size one into another bitfield
10765 of size 1. In this case, (unless we need the result of the
10766 assignment) we can do this more efficiently with a
10767 test followed by an assignment, if necessary.
10769 ??? At this point, we can't get a BIT_FIELD_REF here. But if
10770 things change so we do, this code should be enhanced to
10771 support it. */
10772 if (TREE_CODE (lhs) == COMPONENT_REF
10773 && (TREE_CODE (rhs) == BIT_IOR_EXPR
10774 || TREE_CODE (rhs) == BIT_AND_EXPR)
10775 && TREE_OPERAND (rhs, 0) == lhs
10776 && TREE_CODE (TREE_OPERAND (rhs, 1)) == COMPONENT_REF
10777 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs, 1)))
10778 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs, 1), 1))))
10780 rtx_code_label *label = gen_label_rtx ();
10781 int value = TREE_CODE (rhs) == BIT_IOR_EXPR;
10782 do_jump (TREE_OPERAND (rhs, 1),
10783 value ? label : 0,
10784 value ? 0 : label, -1);
10785 expand_assignment (lhs, build_int_cst (TREE_TYPE (rhs), value),
10786 false);
10787 do_pending_stack_adjust ();
10788 emit_label (label);
10789 return const0_rtx;
10792 expand_assignment (lhs, rhs, false);
10793 return const0_rtx;
10796 case ADDR_EXPR:
10797 return expand_expr_addr_expr (exp, target, tmode, modifier);
10799 case REALPART_EXPR:
10800 op0 = expand_normal (treeop0);
10801 return read_complex_part (op0, false);
10803 case IMAGPART_EXPR:
10804 op0 = expand_normal (treeop0);
10805 return read_complex_part (op0, true);
10807 case RETURN_EXPR:
10808 case LABEL_EXPR:
10809 case GOTO_EXPR:
10810 case SWITCH_EXPR:
10811 case ASM_EXPR:
10812 /* Expanded in cfgexpand.c. */
10813 gcc_unreachable ();
10815 case TRY_CATCH_EXPR:
10816 case CATCH_EXPR:
10817 case EH_FILTER_EXPR:
10818 case TRY_FINALLY_EXPR:
10819 /* Lowered by tree-eh.c. */
10820 gcc_unreachable ();
10822 case WITH_CLEANUP_EXPR:
10823 case CLEANUP_POINT_EXPR:
10824 case TARGET_EXPR:
10825 case CASE_LABEL_EXPR:
10826 case VA_ARG_EXPR:
10827 case BIND_EXPR:
10828 case INIT_EXPR:
10829 case CONJ_EXPR:
10830 case COMPOUND_EXPR:
10831 case PREINCREMENT_EXPR:
10832 case PREDECREMENT_EXPR:
10833 case POSTINCREMENT_EXPR:
10834 case POSTDECREMENT_EXPR:
10835 case LOOP_EXPR:
10836 case EXIT_EXPR:
10837 case COMPOUND_LITERAL_EXPR:
10838 /* Lowered by gimplify.c. */
10839 gcc_unreachable ();
10841 case FDESC_EXPR:
10842 /* Function descriptors are not valid except for as
10843 initialization constants, and should not be expanded. */
10844 gcc_unreachable ();
10846 case WITH_SIZE_EXPR:
10847 /* WITH_SIZE_EXPR expands to its first argument. The caller should
10848 have pulled out the size to use in whatever context it needed. */
10849 return expand_expr_real (treeop0, original_target, tmode,
10850 modifier, alt_rtl, inner_reference_p);
10852 default:
10853 return expand_expr_real_2 (&ops, target, tmode, modifier);
10857 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
10858 signedness of TYPE), possibly returning the result in TARGET. */
10859 static rtx
10860 reduce_to_bit_field_precision (rtx exp, rtx target, tree type)
10862 HOST_WIDE_INT prec = TYPE_PRECISION (type);
10863 if (target && GET_MODE (target) != GET_MODE (exp))
10864 target = 0;
10865 /* For constant values, reduce using build_int_cst_type. */
10866 if (CONST_INT_P (exp))
10868 HOST_WIDE_INT value = INTVAL (exp);
10869 tree t = build_int_cst_type (type, value);
10870 return expand_expr (t, target, VOIDmode, EXPAND_NORMAL);
10872 else if (TYPE_UNSIGNED (type))
10874 machine_mode mode = GET_MODE (exp);
10875 rtx mask = immed_wide_int_const
10876 (wi::mask (prec, false, GET_MODE_PRECISION (mode)), mode);
10877 return expand_and (mode, exp, mask, target);
10879 else
10881 int count = GET_MODE_PRECISION (GET_MODE (exp)) - prec;
10882 exp = expand_shift (LSHIFT_EXPR, GET_MODE (exp),
10883 exp, count, target, 0);
10884 return expand_shift (RSHIFT_EXPR, GET_MODE (exp),
10885 exp, count, target, 0);
10889 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
10890 when applied to the address of EXP produces an address known to be
10891 aligned more than BIGGEST_ALIGNMENT. */
10893 static int
10894 is_aligning_offset (const_tree offset, const_tree exp)
10896 /* Strip off any conversions. */
10897 while (CONVERT_EXPR_P (offset))
10898 offset = TREE_OPERAND (offset, 0);
10900 /* We must now have a BIT_AND_EXPR with a constant that is one less than
10901 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
10902 if (TREE_CODE (offset) != BIT_AND_EXPR
10903 || !tree_fits_uhwi_p (TREE_OPERAND (offset, 1))
10904 || compare_tree_int (TREE_OPERAND (offset, 1),
10905 BIGGEST_ALIGNMENT / BITS_PER_UNIT) <= 0
10906 || exact_log2 (tree_to_uhwi (TREE_OPERAND (offset, 1)) + 1) < 0)
10907 return 0;
10909 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
10910 It must be NEGATE_EXPR. Then strip any more conversions. */
10911 offset = TREE_OPERAND (offset, 0);
10912 while (CONVERT_EXPR_P (offset))
10913 offset = TREE_OPERAND (offset, 0);
10915 if (TREE_CODE (offset) != NEGATE_EXPR)
10916 return 0;
10918 offset = TREE_OPERAND (offset, 0);
10919 while (CONVERT_EXPR_P (offset))
10920 offset = TREE_OPERAND (offset, 0);
10922 /* This must now be the address of EXP. */
10923 return TREE_CODE (offset) == ADDR_EXPR && TREE_OPERAND (offset, 0) == exp;
10926 /* Return the tree node if an ARG corresponds to a string constant or zero
10927 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
10928 in bytes within the string that ARG is accessing. The type of the
10929 offset will be `sizetype'. */
10931 tree
10932 string_constant (tree arg, tree *ptr_offset)
10934 tree array, offset, lower_bound;
10935 STRIP_NOPS (arg);
10937 if (TREE_CODE (arg) == ADDR_EXPR)
10939 if (TREE_CODE (TREE_OPERAND (arg, 0)) == STRING_CST)
10941 *ptr_offset = size_zero_node;
10942 return TREE_OPERAND (arg, 0);
10944 else if (TREE_CODE (TREE_OPERAND (arg, 0)) == VAR_DECL)
10946 array = TREE_OPERAND (arg, 0);
10947 offset = size_zero_node;
10949 else if (TREE_CODE (TREE_OPERAND (arg, 0)) == ARRAY_REF)
10951 array = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
10952 offset = TREE_OPERAND (TREE_OPERAND (arg, 0), 1);
10953 if (TREE_CODE (array) != STRING_CST
10954 && TREE_CODE (array) != VAR_DECL)
10955 return 0;
10957 /* Check if the array has a nonzero lower bound. */
10958 lower_bound = array_ref_low_bound (TREE_OPERAND (arg, 0));
10959 if (!integer_zerop (lower_bound))
10961 /* If the offset and base aren't both constants, return 0. */
10962 if (TREE_CODE (lower_bound) != INTEGER_CST)
10963 return 0;
10964 if (TREE_CODE (offset) != INTEGER_CST)
10965 return 0;
10966 /* Adjust offset by the lower bound. */
10967 offset = size_diffop (fold_convert (sizetype, offset),
10968 fold_convert (sizetype, lower_bound));
10971 else if (TREE_CODE (TREE_OPERAND (arg, 0)) == MEM_REF)
10973 array = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
10974 offset = TREE_OPERAND (TREE_OPERAND (arg, 0), 1);
10975 if (TREE_CODE (array) != ADDR_EXPR)
10976 return 0;
10977 array = TREE_OPERAND (array, 0);
10978 if (TREE_CODE (array) != STRING_CST
10979 && TREE_CODE (array) != VAR_DECL)
10980 return 0;
10982 else
10983 return 0;
10985 else if (TREE_CODE (arg) == PLUS_EXPR || TREE_CODE (arg) == POINTER_PLUS_EXPR)
10987 tree arg0 = TREE_OPERAND (arg, 0);
10988 tree arg1 = TREE_OPERAND (arg, 1);
10990 STRIP_NOPS (arg0);
10991 STRIP_NOPS (arg1);
10993 if (TREE_CODE (arg0) == ADDR_EXPR
10994 && (TREE_CODE (TREE_OPERAND (arg0, 0)) == STRING_CST
10995 || TREE_CODE (TREE_OPERAND (arg0, 0)) == VAR_DECL))
10997 array = TREE_OPERAND (arg0, 0);
10998 offset = arg1;
11000 else if (TREE_CODE (arg1) == ADDR_EXPR
11001 && (TREE_CODE (TREE_OPERAND (arg1, 0)) == STRING_CST
11002 || TREE_CODE (TREE_OPERAND (arg1, 0)) == VAR_DECL))
11004 array = TREE_OPERAND (arg1, 0);
11005 offset = arg0;
11007 else
11008 return 0;
11010 else
11011 return 0;
11013 if (TREE_CODE (array) == STRING_CST)
11015 *ptr_offset = fold_convert (sizetype, offset);
11016 return array;
11018 else if (TREE_CODE (array) == VAR_DECL
11019 || TREE_CODE (array) == CONST_DECL)
11021 int length;
11022 tree init = ctor_for_folding (array);
11024 /* Variables initialized to string literals can be handled too. */
11025 if (init == error_mark_node
11026 || !init
11027 || TREE_CODE (init) != STRING_CST)
11028 return 0;
11030 /* Avoid const char foo[4] = "abcde"; */
11031 if (DECL_SIZE_UNIT (array) == NULL_TREE
11032 || TREE_CODE (DECL_SIZE_UNIT (array)) != INTEGER_CST
11033 || (length = TREE_STRING_LENGTH (init)) <= 0
11034 || compare_tree_int (DECL_SIZE_UNIT (array), length) < 0)
11035 return 0;
11037 /* If variable is bigger than the string literal, OFFSET must be constant
11038 and inside of the bounds of the string literal. */
11039 offset = fold_convert (sizetype, offset);
11040 if (compare_tree_int (DECL_SIZE_UNIT (array), length) > 0
11041 && (! tree_fits_uhwi_p (offset)
11042 || compare_tree_int (offset, length) >= 0))
11043 return 0;
11045 *ptr_offset = offset;
11046 return init;
11049 return 0;
11052 /* Generate code to calculate OPS, and exploded expression
11053 using a store-flag instruction and return an rtx for the result.
11054 OPS reflects a comparison.
11056 If TARGET is nonzero, store the result there if convenient.
11058 Return zero if there is no suitable set-flag instruction
11059 available on this machine.
11061 Once expand_expr has been called on the arguments of the comparison,
11062 we are committed to doing the store flag, since it is not safe to
11063 re-evaluate the expression. We emit the store-flag insn by calling
11064 emit_store_flag, but only expand the arguments if we have a reason
11065 to believe that emit_store_flag will be successful. If we think that
11066 it will, but it isn't, we have to simulate the store-flag with a
11067 set/jump/set sequence. */
11069 static rtx
11070 do_store_flag (sepops ops, rtx target, machine_mode mode)
11072 enum rtx_code code;
11073 tree arg0, arg1, type;
11074 machine_mode operand_mode;
11075 int unsignedp;
11076 rtx op0, op1;
11077 rtx subtarget = target;
11078 location_t loc = ops->location;
11080 arg0 = ops->op0;
11081 arg1 = ops->op1;
11083 /* Don't crash if the comparison was erroneous. */
11084 if (arg0 == error_mark_node || arg1 == error_mark_node)
11085 return const0_rtx;
11087 type = TREE_TYPE (arg0);
11088 operand_mode = TYPE_MODE (type);
11089 unsignedp = TYPE_UNSIGNED (type);
11091 /* We won't bother with BLKmode store-flag operations because it would mean
11092 passing a lot of information to emit_store_flag. */
11093 if (operand_mode == BLKmode)
11094 return 0;
11096 /* We won't bother with store-flag operations involving function pointers
11097 when function pointers must be canonicalized before comparisons. */
11098 if (targetm.have_canonicalize_funcptr_for_compare ()
11099 && ((TREE_CODE (TREE_TYPE (arg0)) == POINTER_TYPE
11100 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0)))
11101 == FUNCTION_TYPE))
11102 || (TREE_CODE (TREE_TYPE (arg1)) == POINTER_TYPE
11103 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1)))
11104 == FUNCTION_TYPE))))
11105 return 0;
11107 STRIP_NOPS (arg0);
11108 STRIP_NOPS (arg1);
11110 /* For vector typed comparisons emit code to generate the desired
11111 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
11112 expander for this. */
11113 if (TREE_CODE (ops->type) == VECTOR_TYPE)
11115 tree ifexp = build2 (ops->code, ops->type, arg0, arg1);
11116 if (VECTOR_BOOLEAN_TYPE_P (ops->type)
11117 && expand_vec_cmp_expr_p (TREE_TYPE (arg0), ops->type))
11118 return expand_vec_cmp_expr (ops->type, ifexp, target);
11119 else
11121 tree if_true = constant_boolean_node (true, ops->type);
11122 tree if_false = constant_boolean_node (false, ops->type);
11123 return expand_vec_cond_expr (ops->type, ifexp, if_true,
11124 if_false, target);
11128 /* Get the rtx comparison code to use. We know that EXP is a comparison
11129 operation of some type. Some comparisons against 1 and -1 can be
11130 converted to comparisons with zero. Do so here so that the tests
11131 below will be aware that we have a comparison with zero. These
11132 tests will not catch constants in the first operand, but constants
11133 are rarely passed as the first operand. */
11135 switch (ops->code)
11137 case EQ_EXPR:
11138 code = EQ;
11139 break;
11140 case NE_EXPR:
11141 code = NE;
11142 break;
11143 case LT_EXPR:
11144 if (integer_onep (arg1))
11145 arg1 = integer_zero_node, code = unsignedp ? LEU : LE;
11146 else
11147 code = unsignedp ? LTU : LT;
11148 break;
11149 case LE_EXPR:
11150 if (! unsignedp && integer_all_onesp (arg1))
11151 arg1 = integer_zero_node, code = LT;
11152 else
11153 code = unsignedp ? LEU : LE;
11154 break;
11155 case GT_EXPR:
11156 if (! unsignedp && integer_all_onesp (arg1))
11157 arg1 = integer_zero_node, code = GE;
11158 else
11159 code = unsignedp ? GTU : GT;
11160 break;
11161 case GE_EXPR:
11162 if (integer_onep (arg1))
11163 arg1 = integer_zero_node, code = unsignedp ? GTU : GT;
11164 else
11165 code = unsignedp ? GEU : GE;
11166 break;
11168 case UNORDERED_EXPR:
11169 code = UNORDERED;
11170 break;
11171 case ORDERED_EXPR:
11172 code = ORDERED;
11173 break;
11174 case UNLT_EXPR:
11175 code = UNLT;
11176 break;
11177 case UNLE_EXPR:
11178 code = UNLE;
11179 break;
11180 case UNGT_EXPR:
11181 code = UNGT;
11182 break;
11183 case UNGE_EXPR:
11184 code = UNGE;
11185 break;
11186 case UNEQ_EXPR:
11187 code = UNEQ;
11188 break;
11189 case LTGT_EXPR:
11190 code = LTGT;
11191 break;
11193 default:
11194 gcc_unreachable ();
11197 /* Put a constant second. */
11198 if (TREE_CODE (arg0) == REAL_CST || TREE_CODE (arg0) == INTEGER_CST
11199 || TREE_CODE (arg0) == FIXED_CST)
11201 std::swap (arg0, arg1);
11202 code = swap_condition (code);
11205 /* If this is an equality or inequality test of a single bit, we can
11206 do this by shifting the bit being tested to the low-order bit and
11207 masking the result with the constant 1. If the condition was EQ,
11208 we xor it with 1. This does not require an scc insn and is faster
11209 than an scc insn even if we have it.
11211 The code to make this transformation was moved into fold_single_bit_test,
11212 so we just call into the folder and expand its result. */
11214 if ((code == NE || code == EQ)
11215 && integer_zerop (arg1)
11216 && (TYPE_PRECISION (ops->type) != 1 || TYPE_UNSIGNED (ops->type)))
11218 gimple *srcstmt = get_def_for_expr (arg0, BIT_AND_EXPR);
11219 if (srcstmt
11220 && integer_pow2p (gimple_assign_rhs2 (srcstmt)))
11222 enum tree_code tcode = code == NE ? NE_EXPR : EQ_EXPR;
11223 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
11224 tree temp = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (arg1),
11225 gimple_assign_rhs1 (srcstmt),
11226 gimple_assign_rhs2 (srcstmt));
11227 temp = fold_single_bit_test (loc, tcode, temp, arg1, type);
11228 if (temp)
11229 return expand_expr (temp, target, VOIDmode, EXPAND_NORMAL);
11233 if (! get_subtarget (target)
11234 || GET_MODE (subtarget) != operand_mode)
11235 subtarget = 0;
11237 expand_operands (arg0, arg1, subtarget, &op0, &op1, EXPAND_NORMAL);
11239 if (target == 0)
11240 target = gen_reg_rtx (mode);
11242 /* Try a cstore if possible. */
11243 return emit_store_flag_force (target, code, op0, op1,
11244 operand_mode, unsignedp,
11245 (TYPE_PRECISION (ops->type) == 1
11246 && !TYPE_UNSIGNED (ops->type)) ? -1 : 1);
11249 /* Attempt to generate a casesi instruction. Returns 1 if successful,
11250 0 otherwise (i.e. if there is no casesi instruction).
11252 DEFAULT_PROBABILITY is the probability of jumping to the default
11253 label. */
11255 try_casesi (tree index_type, tree index_expr, tree minval, tree range,
11256 rtx table_label, rtx default_label, rtx fallback_label,
11257 int default_probability)
11259 struct expand_operand ops[5];
11260 machine_mode index_mode = SImode;
11261 rtx op1, op2, index;
11263 if (! targetm.have_casesi ())
11264 return 0;
11266 /* Convert the index to SImode. */
11267 if (GET_MODE_BITSIZE (TYPE_MODE (index_type)) > GET_MODE_BITSIZE (index_mode))
11269 machine_mode omode = TYPE_MODE (index_type);
11270 rtx rangertx = expand_normal (range);
11272 /* We must handle the endpoints in the original mode. */
11273 index_expr = build2 (MINUS_EXPR, index_type,
11274 index_expr, minval);
11275 minval = integer_zero_node;
11276 index = expand_normal (index_expr);
11277 if (default_label)
11278 emit_cmp_and_jump_insns (rangertx, index, LTU, NULL_RTX,
11279 omode, 1, default_label,
11280 default_probability);
11281 /* Now we can safely truncate. */
11282 index = convert_to_mode (index_mode, index, 0);
11284 else
11286 if (TYPE_MODE (index_type) != index_mode)
11288 index_type = lang_hooks.types.type_for_mode (index_mode, 0);
11289 index_expr = fold_convert (index_type, index_expr);
11292 index = expand_normal (index_expr);
11295 do_pending_stack_adjust ();
11297 op1 = expand_normal (minval);
11298 op2 = expand_normal (range);
11300 create_input_operand (&ops[0], index, index_mode);
11301 create_convert_operand_from_type (&ops[1], op1, TREE_TYPE (minval));
11302 create_convert_operand_from_type (&ops[2], op2, TREE_TYPE (range));
11303 create_fixed_operand (&ops[3], table_label);
11304 create_fixed_operand (&ops[4], (default_label
11305 ? default_label
11306 : fallback_label));
11307 expand_jump_insn (targetm.code_for_casesi, 5, ops);
11308 return 1;
11311 /* Attempt to generate a tablejump instruction; same concept. */
11312 /* Subroutine of the next function.
11314 INDEX is the value being switched on, with the lowest value
11315 in the table already subtracted.
11316 MODE is its expected mode (needed if INDEX is constant).
11317 RANGE is the length of the jump table.
11318 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
11320 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
11321 index value is out of range.
11322 DEFAULT_PROBABILITY is the probability of jumping to
11323 the default label. */
11325 static void
11326 do_tablejump (rtx index, machine_mode mode, rtx range, rtx table_label,
11327 rtx default_label, int default_probability)
11329 rtx temp, vector;
11331 if (INTVAL (range) > cfun->cfg->max_jumptable_ents)
11332 cfun->cfg->max_jumptable_ents = INTVAL (range);
11334 /* Do an unsigned comparison (in the proper mode) between the index
11335 expression and the value which represents the length of the range.
11336 Since we just finished subtracting the lower bound of the range
11337 from the index expression, this comparison allows us to simultaneously
11338 check that the original index expression value is both greater than
11339 or equal to the minimum value of the range and less than or equal to
11340 the maximum value of the range. */
11342 if (default_label)
11343 emit_cmp_and_jump_insns (index, range, GTU, NULL_RTX, mode, 1,
11344 default_label, default_probability);
11347 /* If index is in range, it must fit in Pmode.
11348 Convert to Pmode so we can index with it. */
11349 if (mode != Pmode)
11350 index = convert_to_mode (Pmode, index, 1);
11352 /* Don't let a MEM slip through, because then INDEX that comes
11353 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
11354 and break_out_memory_refs will go to work on it and mess it up. */
11355 #ifdef PIC_CASE_VECTOR_ADDRESS
11356 if (flag_pic && !REG_P (index))
11357 index = copy_to_mode_reg (Pmode, index);
11358 #endif
11360 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
11361 GET_MODE_SIZE, because this indicates how large insns are. The other
11362 uses should all be Pmode, because they are addresses. This code
11363 could fail if addresses and insns are not the same size. */
11364 index = simplify_gen_binary (MULT, Pmode, index,
11365 gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE),
11366 Pmode));
11367 index = simplify_gen_binary (PLUS, Pmode, index,
11368 gen_rtx_LABEL_REF (Pmode, table_label));
11370 #ifdef PIC_CASE_VECTOR_ADDRESS
11371 if (flag_pic)
11372 index = PIC_CASE_VECTOR_ADDRESS (index);
11373 else
11374 #endif
11375 index = memory_address (CASE_VECTOR_MODE, index);
11376 temp = gen_reg_rtx (CASE_VECTOR_MODE);
11377 vector = gen_const_mem (CASE_VECTOR_MODE, index);
11378 convert_move (temp, vector, 0);
11380 emit_jump_insn (targetm.gen_tablejump (temp, table_label));
11382 /* If we are generating PIC code or if the table is PC-relative, the
11383 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
11384 if (! CASE_VECTOR_PC_RELATIVE && ! flag_pic)
11385 emit_barrier ();
11389 try_tablejump (tree index_type, tree index_expr, tree minval, tree range,
11390 rtx table_label, rtx default_label, int default_probability)
11392 rtx index;
11394 if (! targetm.have_tablejump ())
11395 return 0;
11397 index_expr = fold_build2 (MINUS_EXPR, index_type,
11398 fold_convert (index_type, index_expr),
11399 fold_convert (index_type, minval));
11400 index = expand_normal (index_expr);
11401 do_pending_stack_adjust ();
11403 do_tablejump (index, TYPE_MODE (index_type),
11404 convert_modes (TYPE_MODE (index_type),
11405 TYPE_MODE (TREE_TYPE (range)),
11406 expand_normal (range),
11407 TYPE_UNSIGNED (TREE_TYPE (range))),
11408 table_label, default_label, default_probability);
11409 return 1;
11412 /* Return a CONST_VECTOR rtx representing vector mask for
11413 a VECTOR_CST of booleans. */
11414 static rtx
11415 const_vector_mask_from_tree (tree exp)
11417 rtvec v;
11418 unsigned i;
11419 int units;
11420 tree elt;
11421 machine_mode inner, mode;
11423 mode = TYPE_MODE (TREE_TYPE (exp));
11424 units = GET_MODE_NUNITS (mode);
11425 inner = GET_MODE_INNER (mode);
11427 v = rtvec_alloc (units);
11429 for (i = 0; i < VECTOR_CST_NELTS (exp); ++i)
11431 elt = VECTOR_CST_ELT (exp, i);
11433 gcc_assert (TREE_CODE (elt) == INTEGER_CST);
11434 if (integer_zerop (elt))
11435 RTVEC_ELT (v, i) = CONST0_RTX (inner);
11436 else if (integer_onep (elt)
11437 || integer_minus_onep (elt))
11438 RTVEC_ELT (v, i) = CONSTM1_RTX (inner);
11439 else
11440 gcc_unreachable ();
11443 return gen_rtx_CONST_VECTOR (mode, v);
11446 /* Return a CONST_INT rtx representing vector mask for
11447 a VECTOR_CST of booleans. */
11448 static rtx
11449 const_scalar_mask_from_tree (tree exp)
11451 machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
11452 wide_int res = wi::zero (GET_MODE_PRECISION (mode));
11453 tree elt;
11454 unsigned i;
11456 for (i = 0; i < VECTOR_CST_NELTS (exp); ++i)
11458 elt = VECTOR_CST_ELT (exp, i);
11459 gcc_assert (TREE_CODE (elt) == INTEGER_CST);
11460 if (integer_all_onesp (elt))
11461 res = wi::set_bit (res, i);
11462 else
11463 gcc_assert (integer_zerop (elt));
11466 return immed_wide_int_const (res, mode);
11469 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
11470 static rtx
11471 const_vector_from_tree (tree exp)
11473 rtvec v;
11474 unsigned i;
11475 int units;
11476 tree elt;
11477 machine_mode inner, mode;
11479 mode = TYPE_MODE (TREE_TYPE (exp));
11481 if (initializer_zerop (exp))
11482 return CONST0_RTX (mode);
11484 if (VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (exp)))
11485 return const_vector_mask_from_tree (exp);
11487 units = GET_MODE_NUNITS (mode);
11488 inner = GET_MODE_INNER (mode);
11490 v = rtvec_alloc (units);
11492 for (i = 0; i < VECTOR_CST_NELTS (exp); ++i)
11494 elt = VECTOR_CST_ELT (exp, i);
11496 if (TREE_CODE (elt) == REAL_CST)
11497 RTVEC_ELT (v, i) = const_double_from_real_value (TREE_REAL_CST (elt),
11498 inner);
11499 else if (TREE_CODE (elt) == FIXED_CST)
11500 RTVEC_ELT (v, i) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt),
11501 inner);
11502 else
11503 RTVEC_ELT (v, i) = immed_wide_int_const (elt, inner);
11506 return gen_rtx_CONST_VECTOR (mode, v);
11509 /* Build a decl for a personality function given a language prefix. */
11511 tree
11512 build_personality_function (const char *lang)
11514 const char *unwind_and_version;
11515 tree decl, type;
11516 char *name;
11518 switch (targetm_common.except_unwind_info (&global_options))
11520 case UI_NONE:
11521 return NULL;
11522 case UI_SJLJ:
11523 unwind_and_version = "_sj0";
11524 break;
11525 case UI_DWARF2:
11526 case UI_TARGET:
11527 unwind_and_version = "_v0";
11528 break;
11529 case UI_SEH:
11530 unwind_and_version = "_seh0";
11531 break;
11532 default:
11533 gcc_unreachable ();
11536 name = ACONCAT (("__", lang, "_personality", unwind_and_version, NULL));
11538 type = build_function_type_list (integer_type_node, integer_type_node,
11539 long_long_unsigned_type_node,
11540 ptr_type_node, ptr_type_node, NULL_TREE);
11541 decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
11542 get_identifier (name), type);
11543 DECL_ARTIFICIAL (decl) = 1;
11544 DECL_EXTERNAL (decl) = 1;
11545 TREE_PUBLIC (decl) = 1;
11547 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
11548 are the flags assigned by targetm.encode_section_info. */
11549 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl), 0), NULL);
11551 return decl;
11554 /* Extracts the personality function of DECL and returns the corresponding
11555 libfunc. */
11558 get_personality_function (tree decl)
11560 tree personality = DECL_FUNCTION_PERSONALITY (decl);
11561 enum eh_personality_kind pk;
11563 pk = function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl));
11564 if (pk == eh_personality_none)
11565 return NULL;
11567 if (!personality
11568 && pk == eh_personality_any)
11569 personality = lang_hooks.eh_personality ();
11571 if (pk == eh_personality_lang)
11572 gcc_assert (personality != NULL_TREE);
11574 return XEXP (DECL_RTL (personality), 0);
11577 /* Returns a tree for the size of EXP in bytes. */
11579 static tree
11580 tree_expr_size (const_tree exp)
11582 if (DECL_P (exp)
11583 && DECL_SIZE_UNIT (exp) != 0)
11584 return DECL_SIZE_UNIT (exp);
11585 else
11586 return size_in_bytes (TREE_TYPE (exp));
11589 /* Return an rtx for the size in bytes of the value of EXP. */
11592 expr_size (tree exp)
11594 tree size;
11596 if (TREE_CODE (exp) == WITH_SIZE_EXPR)
11597 size = TREE_OPERAND (exp, 1);
11598 else
11600 size = tree_expr_size (exp);
11601 gcc_assert (size);
11602 gcc_assert (size == SUBSTITUTE_PLACEHOLDER_IN_EXPR (size, exp));
11605 return expand_expr (size, NULL_RTX, TYPE_MODE (sizetype), EXPAND_NORMAL);
11608 /* Return a wide integer for the size in bytes of the value of EXP, or -1
11609 if the size can vary or is larger than an integer. */
11611 static HOST_WIDE_INT
11612 int_expr_size (tree exp)
11614 tree size;
11616 if (TREE_CODE (exp) == WITH_SIZE_EXPR)
11617 size = TREE_OPERAND (exp, 1);
11618 else
11620 size = tree_expr_size (exp);
11621 gcc_assert (size);
11624 if (size == 0 || !tree_fits_shwi_p (size))
11625 return -1;
11627 return tree_to_shwi (size);
11630 #include "gt-expr.h"