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
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
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/>. */
22 #include "coretypes.h"
37 #include "diagnostic.h"
39 #include "fold-const.h"
40 #include "stor-layout.h"
44 #include "insn-attr.h"
49 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
51 #include "optabs-tree.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"
60 #include "tree-chkp.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. */
73 /* This structure is used by move_by_pieces to describe the move to
75 struct move_by_pieces_d
84 int explicit_inc_from
;
85 unsigned HOST_WIDE_INT len
;
90 /* This structure is used by store_by_pieces to describe the clear to
93 struct store_by_pieces_d
99 unsigned HOST_WIDE_INT len
;
100 HOST_WIDE_INT offset
;
101 rtx (*constfun
) (void *, HOST_WIDE_INT
, machine_mode
);
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
);
136 static void emit_single_push_insn (machine_mode
, rtx
, tree
);
138 static void do_tablejump (rtx
, machine_mode
, rtx
, rtx
, rtx
, int);
139 static rtx
const_vector_from_tree (tree
);
140 static tree
tree_expr_size (const_tree
);
141 static HOST_WIDE_INT
int_expr_size (tree
);
144 /* This is run to set up which modes can be used
145 directly in memory and to initialize the block move optab. It is run
146 at the beginning of compilation and when the target is reinitialized. */
149 init_expr_target (void)
157 /* Try indexing by frame ptr and try by stack ptr.
158 It is known that on the Convex the stack ptr isn't a valid index.
159 With luck, one or the other is valid on any machine. */
160 mem
= gen_rtx_MEM (word_mode
, stack_pointer_rtx
);
161 mem1
= gen_rtx_MEM (word_mode
, frame_pointer_rtx
);
163 /* A scratch register we can modify in-place below to avoid
164 useless RTL allocations. */
165 reg
= gen_rtx_REG (word_mode
, LAST_VIRTUAL_REGISTER
+ 1);
167 insn
= rtx_alloc (INSN
);
168 pat
= gen_rtx_SET (NULL_RTX
, NULL_RTX
);
169 PATTERN (insn
) = pat
;
171 for (mode
= VOIDmode
; (int) mode
< NUM_MACHINE_MODES
;
172 mode
= (machine_mode
) ((int) mode
+ 1))
176 direct_load
[(int) mode
] = direct_store
[(int) mode
] = 0;
177 PUT_MODE (mem
, mode
);
178 PUT_MODE (mem1
, mode
);
180 /* See if there is some register that can be used in this mode and
181 directly loaded or stored from memory. */
183 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
184 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
185 && (direct_load
[(int) mode
] == 0 || direct_store
[(int) mode
] == 0);
188 if (! HARD_REGNO_MODE_OK (regno
, mode
))
191 set_mode_and_regno (reg
, mode
, regno
);
194 SET_DEST (pat
) = reg
;
195 if (recog (pat
, insn
, &num_clobbers
) >= 0)
196 direct_load
[(int) mode
] = 1;
198 SET_SRC (pat
) = mem1
;
199 SET_DEST (pat
) = reg
;
200 if (recog (pat
, insn
, &num_clobbers
) >= 0)
201 direct_load
[(int) mode
] = 1;
204 SET_DEST (pat
) = mem
;
205 if (recog (pat
, insn
, &num_clobbers
) >= 0)
206 direct_store
[(int) mode
] = 1;
209 SET_DEST (pat
) = mem1
;
210 if (recog (pat
, insn
, &num_clobbers
) >= 0)
211 direct_store
[(int) mode
] = 1;
215 mem
= gen_rtx_MEM (VOIDmode
, gen_raw_REG (Pmode
, LAST_VIRTUAL_REGISTER
+ 1));
217 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); mode
!= VOIDmode
;
218 mode
= GET_MODE_WIDER_MODE (mode
))
220 machine_mode srcmode
;
221 for (srcmode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
); srcmode
!= mode
;
222 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
226 ic
= can_extend_p (mode
, srcmode
, 0);
227 if (ic
== CODE_FOR_nothing
)
230 PUT_MODE (mem
, srcmode
);
232 if (insn_operand_matches (ic
, 1, mem
))
233 float_extend_from_mem
[mode
][srcmode
] = true;
238 /* This is run at the start of compiling a function. */
243 memset (&crtl
->expr
, 0, sizeof (crtl
->expr
));
246 /* Copy data from FROM to TO, where the machine modes are not the same.
247 Both modes may be integer, or both may be floating, or both may be
249 UNSIGNEDP should be nonzero if FROM is an unsigned type.
250 This causes zero-extension instead of sign-extension. */
253 convert_move (rtx to
, rtx from
, int unsignedp
)
255 machine_mode to_mode
= GET_MODE (to
);
256 machine_mode from_mode
= GET_MODE (from
);
257 int to_real
= SCALAR_FLOAT_MODE_P (to_mode
);
258 int from_real
= SCALAR_FLOAT_MODE_P (from_mode
);
262 /* rtx code for making an equivalent value. */
263 enum rtx_code equiv_code
= (unsignedp
< 0 ? UNKNOWN
264 : (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
));
267 gcc_assert (to_real
== from_real
);
268 gcc_assert (to_mode
!= BLKmode
);
269 gcc_assert (from_mode
!= BLKmode
);
271 /* If the source and destination are already the same, then there's
276 /* If FROM is a SUBREG that indicates that we have already done at least
277 the required extension, strip it. We don't handle such SUBREGs as
280 if (GET_CODE (from
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (from
)
281 && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (from
)))
282 >= GET_MODE_PRECISION (to_mode
))
283 && SUBREG_CHECK_PROMOTED_SIGN (from
, unsignedp
))
284 from
= gen_lowpart (to_mode
, from
), from_mode
= to_mode
;
286 gcc_assert (GET_CODE (to
) != SUBREG
|| !SUBREG_PROMOTED_VAR_P (to
));
288 if (to_mode
== from_mode
289 || (from_mode
== VOIDmode
&& CONSTANT_P (from
)))
291 emit_move_insn (to
, from
);
295 if (VECTOR_MODE_P (to_mode
) || VECTOR_MODE_P (from_mode
))
297 gcc_assert (GET_MODE_BITSIZE (from_mode
) == GET_MODE_BITSIZE (to_mode
));
299 if (VECTOR_MODE_P (to_mode
))
300 from
= simplify_gen_subreg (to_mode
, from
, GET_MODE (from
), 0);
302 to
= simplify_gen_subreg (from_mode
, to
, GET_MODE (to
), 0);
304 emit_move_insn (to
, from
);
308 if (GET_CODE (to
) == CONCAT
&& GET_CODE (from
) == CONCAT
)
310 convert_move (XEXP (to
, 0), XEXP (from
, 0), unsignedp
);
311 convert_move (XEXP (to
, 1), XEXP (from
, 1), unsignedp
);
321 gcc_assert ((GET_MODE_PRECISION (from_mode
)
322 != GET_MODE_PRECISION (to_mode
))
323 || (DECIMAL_FLOAT_MODE_P (from_mode
)
324 != DECIMAL_FLOAT_MODE_P (to_mode
)));
326 if (GET_MODE_PRECISION (from_mode
) == GET_MODE_PRECISION (to_mode
))
327 /* Conversion between decimal float and binary float, same size. */
328 tab
= DECIMAL_FLOAT_MODE_P (from_mode
) ? trunc_optab
: sext_optab
;
329 else if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
))
334 /* Try converting directly if the insn is supported. */
336 code
= convert_optab_handler (tab
, to_mode
, from_mode
);
337 if (code
!= CODE_FOR_nothing
)
339 emit_unop_insn (code
, to
, from
,
340 tab
== sext_optab
? FLOAT_EXTEND
: FLOAT_TRUNCATE
);
344 /* Otherwise use a libcall. */
345 libcall
= convert_optab_libfunc (tab
, to_mode
, from_mode
);
347 /* Is this conversion implemented yet? */
348 gcc_assert (libcall
);
351 value
= emit_library_call_value (libcall
, NULL_RTX
, LCT_CONST
, to_mode
,
353 insns
= get_insns ();
355 emit_libcall_block (insns
, to
, value
,
356 tab
== trunc_optab
? gen_rtx_FLOAT_TRUNCATE (to_mode
,
358 : gen_rtx_FLOAT_EXTEND (to_mode
, from
));
362 /* Handle pointer conversion. */ /* SPEE 900220. */
363 /* If the target has a converter from FROM_MODE to TO_MODE, use it. */
367 if (GET_MODE_PRECISION (from_mode
) > GET_MODE_PRECISION (to_mode
))
374 if (convert_optab_handler (ctab
, to_mode
, from_mode
)
377 emit_unop_insn (convert_optab_handler (ctab
, to_mode
, from_mode
),
383 /* Targets are expected to provide conversion insns between PxImode and
384 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
385 if (GET_MODE_CLASS (to_mode
) == MODE_PARTIAL_INT
)
387 machine_mode full_mode
388 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode
), MODE_INT
);
390 gcc_assert (convert_optab_handler (trunc_optab
, to_mode
, full_mode
)
391 != CODE_FOR_nothing
);
393 if (full_mode
!= from_mode
)
394 from
= convert_to_mode (full_mode
, from
, unsignedp
);
395 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, full_mode
),
399 if (GET_MODE_CLASS (from_mode
) == MODE_PARTIAL_INT
)
402 machine_mode full_mode
403 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode
), MODE_INT
);
404 convert_optab ctab
= unsignedp
? zext_optab
: sext_optab
;
405 enum insn_code icode
;
407 icode
= convert_optab_handler (ctab
, full_mode
, from_mode
);
408 gcc_assert (icode
!= CODE_FOR_nothing
);
410 if (to_mode
== full_mode
)
412 emit_unop_insn (icode
, to
, from
, UNKNOWN
);
416 new_from
= gen_reg_rtx (full_mode
);
417 emit_unop_insn (icode
, new_from
, from
, UNKNOWN
);
419 /* else proceed to integer conversions below. */
420 from_mode
= full_mode
;
424 /* Make sure both are fixed-point modes or both are not. */
425 gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
) ==
426 ALL_SCALAR_FIXED_POINT_MODE_P (to_mode
));
427 if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
))
429 /* If we widen from_mode to to_mode and they are in the same class,
430 we won't saturate the result.
431 Otherwise, always saturate the result to play safe. */
432 if (GET_MODE_CLASS (from_mode
) == GET_MODE_CLASS (to_mode
)
433 && GET_MODE_SIZE (from_mode
) < GET_MODE_SIZE (to_mode
))
434 expand_fixed_convert (to
, from
, 0, 0);
436 expand_fixed_convert (to
, from
, 0, 1);
440 /* Now both modes are integers. */
442 /* Handle expanding beyond a word. */
443 if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
)
444 && GET_MODE_PRECISION (to_mode
) > BITS_PER_WORD
)
451 machine_mode lowpart_mode
;
452 int nwords
= CEIL (GET_MODE_SIZE (to_mode
), UNITS_PER_WORD
);
454 /* Try converting directly if the insn is supported. */
455 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
458 /* If FROM is a SUBREG, put it into a register. Do this
459 so that we always generate the same set of insns for
460 better cse'ing; if an intermediate assignment occurred,
461 we won't be doing the operation directly on the SUBREG. */
462 if (optimize
> 0 && GET_CODE (from
) == SUBREG
)
463 from
= force_reg (from_mode
, from
);
464 emit_unop_insn (code
, to
, from
, equiv_code
);
467 /* Next, try converting via full word. */
468 else if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
469 && ((code
= can_extend_p (to_mode
, word_mode
, unsignedp
))
470 != CODE_FOR_nothing
))
472 rtx word_to
= gen_reg_rtx (word_mode
);
475 if (reg_overlap_mentioned_p (to
, from
))
476 from
= force_reg (from_mode
, from
);
479 convert_move (word_to
, from
, unsignedp
);
480 emit_unop_insn (code
, to
, word_to
, equiv_code
);
484 /* No special multiword conversion insn; do it by hand. */
487 /* Since we will turn this into a no conflict block, we must ensure the
488 the source does not overlap the target so force it into an isolated
489 register when maybe so. Likewise for any MEM input, since the
490 conversion sequence might require several references to it and we
491 must ensure we're getting the same value every time. */
493 if (MEM_P (from
) || reg_overlap_mentioned_p (to
, from
))
494 from
= force_reg (from_mode
, from
);
496 /* Get a copy of FROM widened to a word, if necessary. */
497 if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
)
498 lowpart_mode
= word_mode
;
500 lowpart_mode
= from_mode
;
502 lowfrom
= convert_to_mode (lowpart_mode
, from
, unsignedp
);
504 lowpart
= gen_lowpart (lowpart_mode
, to
);
505 emit_move_insn (lowpart
, lowfrom
);
507 /* Compute the value to put in each remaining word. */
509 fill_value
= const0_rtx
;
511 fill_value
= emit_store_flag_force (gen_reg_rtx (word_mode
),
512 LT
, lowfrom
, const0_rtx
,
513 lowpart_mode
, 0, -1);
515 /* Fill the remaining words. */
516 for (i
= GET_MODE_SIZE (lowpart_mode
) / UNITS_PER_WORD
; i
< nwords
; i
++)
518 int index
= (WORDS_BIG_ENDIAN
? nwords
- i
- 1 : i
);
519 rtx subword
= operand_subword (to
, index
, 1, to_mode
);
521 gcc_assert (subword
);
523 if (fill_value
!= subword
)
524 emit_move_insn (subword
, fill_value
);
527 insns
= get_insns ();
534 /* Truncating multi-word to a word or less. */
535 if (GET_MODE_PRECISION (from_mode
) > BITS_PER_WORD
536 && GET_MODE_PRECISION (to_mode
) <= BITS_PER_WORD
)
539 && ! MEM_VOLATILE_P (from
)
540 && direct_load
[(int) to_mode
]
541 && ! mode_dependent_address_p (XEXP (from
, 0),
542 MEM_ADDR_SPACE (from
)))
544 || GET_CODE (from
) == SUBREG
))
545 from
= force_reg (from_mode
, from
);
546 convert_move (to
, gen_lowpart (word_mode
, from
), 0);
550 /* Now follow all the conversions between integers
551 no more than a word long. */
553 /* For truncation, usually we can just refer to FROM in a narrower mode. */
554 if (GET_MODE_BITSIZE (to_mode
) < GET_MODE_BITSIZE (from_mode
)
555 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, from_mode
))
558 && ! MEM_VOLATILE_P (from
)
559 && direct_load
[(int) to_mode
]
560 && ! mode_dependent_address_p (XEXP (from
, 0),
561 MEM_ADDR_SPACE (from
)))
563 || GET_CODE (from
) == SUBREG
))
564 from
= force_reg (from_mode
, from
);
565 if (REG_P (from
) && REGNO (from
) < FIRST_PSEUDO_REGISTER
566 && ! HARD_REGNO_MODE_OK (REGNO (from
), to_mode
))
567 from
= copy_to_reg (from
);
568 emit_move_insn (to
, gen_lowpart (to_mode
, from
));
572 /* Handle extension. */
573 if (GET_MODE_PRECISION (to_mode
) > GET_MODE_PRECISION (from_mode
))
575 /* Convert directly if that works. */
576 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
579 emit_unop_insn (code
, to
, from
, equiv_code
);
584 machine_mode intermediate
;
588 /* Search for a mode to convert via. */
589 for (intermediate
= from_mode
; intermediate
!= VOIDmode
;
590 intermediate
= GET_MODE_WIDER_MODE (intermediate
))
591 if (((can_extend_p (to_mode
, intermediate
, unsignedp
)
593 || (GET_MODE_SIZE (to_mode
) < GET_MODE_SIZE (intermediate
)
594 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, intermediate
)))
595 && (can_extend_p (intermediate
, from_mode
, unsignedp
)
596 != CODE_FOR_nothing
))
598 convert_move (to
, convert_to_mode (intermediate
, from
,
599 unsignedp
), unsignedp
);
603 /* No suitable intermediate mode.
604 Generate what we need with shifts. */
605 shift_amount
= (GET_MODE_PRECISION (to_mode
)
606 - GET_MODE_PRECISION (from_mode
));
607 from
= gen_lowpart (to_mode
, force_reg (from_mode
, from
));
608 tmp
= expand_shift (LSHIFT_EXPR
, to_mode
, from
, shift_amount
,
610 tmp
= expand_shift (RSHIFT_EXPR
, to_mode
, tmp
, shift_amount
,
613 emit_move_insn (to
, tmp
);
618 /* Support special truncate insns for certain modes. */
619 if (convert_optab_handler (trunc_optab
, to_mode
,
620 from_mode
) != CODE_FOR_nothing
)
622 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, from_mode
),
627 /* Handle truncation of volatile memrefs, and so on;
628 the things that couldn't be truncated directly,
629 and for which there was no special instruction.
631 ??? Code above formerly short-circuited this, for most integer
632 mode pairs, with a force_reg in from_mode followed by a recursive
633 call to this routine. Appears always to have been wrong. */
634 if (GET_MODE_PRECISION (to_mode
) < GET_MODE_PRECISION (from_mode
))
636 rtx temp
= force_reg (to_mode
, gen_lowpart (to_mode
, from
));
637 emit_move_insn (to
, temp
);
641 /* Mode combination is not recognized. */
645 /* Return an rtx for a value that would result
646 from converting X to mode MODE.
647 Both X and MODE may be floating, or both integer.
648 UNSIGNEDP is nonzero if X is an unsigned value.
649 This can be done by referring to a part of X in place
650 or by copying to a new temporary with conversion. */
653 convert_to_mode (machine_mode mode
, rtx x
, int unsignedp
)
655 return convert_modes (mode
, VOIDmode
, x
, unsignedp
);
658 /* Return an rtx for a value that would result
659 from converting X from mode OLDMODE to mode MODE.
660 Both modes may be floating, or both integer.
661 UNSIGNEDP is nonzero if X is an unsigned value.
663 This can be done by referring to a part of X in place
664 or by copying to a new temporary with conversion.
666 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
669 convert_modes (machine_mode mode
, machine_mode oldmode
, rtx x
, int unsignedp
)
673 /* If FROM is a SUBREG that indicates that we have already done at least
674 the required extension, strip it. */
676 if (GET_CODE (x
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (x
)
677 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))) >= GET_MODE_SIZE (mode
)
678 && SUBREG_CHECK_PROMOTED_SIGN (x
, unsignedp
))
679 x
= gen_lowpart (mode
, SUBREG_REG (x
));
681 if (GET_MODE (x
) != VOIDmode
)
682 oldmode
= GET_MODE (x
);
687 if (CONST_SCALAR_INT_P (x
) && GET_MODE_CLASS (mode
) == MODE_INT
)
689 /* If the caller did not tell us the old mode, then there is not
690 much to do with respect to canonicalization. We have to
691 assume that all the bits are significant. */
692 if (GET_MODE_CLASS (oldmode
) != MODE_INT
)
693 oldmode
= MAX_MODE_INT
;
694 wide_int w
= wide_int::from (std::make_pair (x
, oldmode
),
695 GET_MODE_PRECISION (mode
),
696 unsignedp
? UNSIGNED
: SIGNED
);
697 return immed_wide_int_const (w
, mode
);
700 /* We can do this with a gen_lowpart if both desired and current modes
701 are integer, and this is either a constant integer, a register, or a
703 if (GET_MODE_CLASS (mode
) == MODE_INT
704 && GET_MODE_CLASS (oldmode
) == MODE_INT
705 && GET_MODE_PRECISION (mode
) <= GET_MODE_PRECISION (oldmode
)
706 && ((MEM_P (x
) && !MEM_VOLATILE_P (x
) && direct_load
[(int) mode
])
708 && (!HARD_REGISTER_P (x
)
709 || HARD_REGNO_MODE_OK (REGNO (x
), mode
))
710 && TRULY_NOOP_TRUNCATION_MODES_P (mode
, GET_MODE (x
)))))
712 return gen_lowpart (mode
, x
);
714 /* Converting from integer constant into mode is always equivalent to an
716 if (VECTOR_MODE_P (mode
) && GET_MODE (x
) == VOIDmode
)
718 gcc_assert (GET_MODE_BITSIZE (mode
) == GET_MODE_BITSIZE (oldmode
));
719 return simplify_gen_subreg (mode
, x
, oldmode
, 0);
722 temp
= gen_reg_rtx (mode
);
723 convert_move (temp
, x
, unsignedp
);
727 /* Return the largest alignment we can use for doing a move (or store)
728 of MAX_PIECES. ALIGN is the largest alignment we could use. */
731 alignment_for_piecewise_move (unsigned int max_pieces
, unsigned int align
)
735 tmode
= mode_for_size (max_pieces
* BITS_PER_UNIT
, MODE_INT
, 1);
736 if (align
>= GET_MODE_ALIGNMENT (tmode
))
737 align
= GET_MODE_ALIGNMENT (tmode
);
740 machine_mode tmode
, xmode
;
742 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
), xmode
= tmode
;
744 xmode
= tmode
, tmode
= GET_MODE_WIDER_MODE (tmode
))
745 if (GET_MODE_SIZE (tmode
) > max_pieces
746 || SLOW_UNALIGNED_ACCESS (tmode
, align
))
749 align
= MAX (align
, GET_MODE_ALIGNMENT (xmode
));
755 /* Return the widest integer mode no wider than SIZE. If no such mode
756 can be found, return VOIDmode. */
759 widest_int_mode_for_size (unsigned int size
)
761 machine_mode tmode
, mode
= VOIDmode
;
763 for (tmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
764 tmode
!= VOIDmode
; tmode
= GET_MODE_WIDER_MODE (tmode
))
765 if (GET_MODE_SIZE (tmode
) < size
)
771 /* Determine whether the LEN bytes can be moved by using several move
772 instructions. Return nonzero if a call to move_by_pieces should
776 can_move_by_pieces (unsigned HOST_WIDE_INT len
,
779 return targetm
.use_by_pieces_infrastructure_p (len
, align
, MOVE_BY_PIECES
,
780 optimize_insn_for_speed_p ());
783 /* Generate several move instructions to copy LEN bytes from block FROM to
784 block TO. (These are MEM rtx's with BLKmode).
786 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
787 used to push FROM to the stack.
789 ALIGN is maximum stack alignment we can assume.
791 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
792 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
796 move_by_pieces (rtx to
, rtx from
, unsigned HOST_WIDE_INT len
,
797 unsigned int align
, int endp
)
799 struct move_by_pieces_d data
;
800 machine_mode to_addr_mode
;
801 machine_mode from_addr_mode
= get_address_mode (from
);
802 rtx to_addr
, from_addr
= XEXP (from
, 0);
803 unsigned int max_size
= MOVE_MAX_PIECES
+ 1;
804 enum insn_code icode
;
806 align
= MIN (to
? MEM_ALIGN (to
) : align
, MEM_ALIGN (from
));
809 data
.from_addr
= from_addr
;
812 to_addr_mode
= get_address_mode (to
);
813 to_addr
= XEXP (to
, 0);
816 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
817 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
819 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
823 to_addr_mode
= VOIDmode
;
827 if (STACK_GROWS_DOWNWARD
)
832 data
.to_addr
= to_addr
;
835 = (GET_CODE (from_addr
) == PRE_INC
|| GET_CODE (from_addr
) == PRE_DEC
836 || GET_CODE (from_addr
) == POST_INC
837 || GET_CODE (from_addr
) == POST_DEC
);
839 data
.explicit_inc_from
= 0;
840 data
.explicit_inc_to
= 0;
841 if (data
.reverse
) data
.offset
= len
;
844 /* If copying requires more than two move insns,
845 copy addresses to registers (to make displacements shorter)
846 and use post-increment if available. */
847 if (!(data
.autinc_from
&& data
.autinc_to
)
848 && move_by_pieces_ninsns (len
, align
, max_size
) > 2)
850 /* Find the mode of the largest move...
851 MODE might not be used depending on the definitions of the
852 USE_* macros below. */
853 machine_mode mode ATTRIBUTE_UNUSED
854 = widest_int_mode_for_size (max_size
);
856 if (USE_LOAD_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_from
)
858 data
.from_addr
= copy_to_mode_reg (from_addr_mode
,
859 plus_constant (from_addr_mode
,
861 data
.autinc_from
= 1;
862 data
.explicit_inc_from
= -1;
864 if (USE_LOAD_POST_INCREMENT (mode
) && ! data
.autinc_from
)
866 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
867 data
.autinc_from
= 1;
868 data
.explicit_inc_from
= 1;
870 if (!data
.autinc_from
&& CONSTANT_P (from_addr
))
871 data
.from_addr
= copy_to_mode_reg (from_addr_mode
, from_addr
);
872 if (USE_STORE_PRE_DECREMENT (mode
) && data
.reverse
&& ! data
.autinc_to
)
874 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
875 plus_constant (to_addr_mode
,
878 data
.explicit_inc_to
= -1;
880 if (USE_STORE_POST_INCREMENT (mode
) && ! data
.reverse
&& ! data
.autinc_to
)
882 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
884 data
.explicit_inc_to
= 1;
886 if (!data
.autinc_to
&& CONSTANT_P (to_addr
))
887 data
.to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
890 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
892 /* First move what we can in the largest integer mode, then go to
893 successively smaller modes. */
895 while (max_size
> 1 && data
.len
> 0)
897 machine_mode mode
= widest_int_mode_for_size (max_size
);
899 if (mode
== VOIDmode
)
902 icode
= optab_handler (mov_optab
, mode
);
903 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
904 move_by_pieces_1 (GEN_FCN (icode
), mode
, &data
);
906 max_size
= GET_MODE_SIZE (mode
);
909 /* The code above should have handled everything. */
910 gcc_assert (!data
.len
);
916 gcc_assert (!data
.reverse
);
921 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
922 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
924 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
925 plus_constant (to_addr_mode
,
929 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
936 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
944 /* Return number of insns required to move L bytes by pieces.
945 ALIGN (in bits) is maximum alignment we can assume. */
947 unsigned HOST_WIDE_INT
948 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l
, unsigned int align
,
949 unsigned int max_size
)
951 unsigned HOST_WIDE_INT n_insns
= 0;
953 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
955 while (max_size
> 1 && l
> 0)
958 enum insn_code icode
;
960 mode
= widest_int_mode_for_size (max_size
);
962 if (mode
== VOIDmode
)
965 icode
= optab_handler (mov_optab
, mode
);
966 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
967 n_insns
+= l
/ GET_MODE_SIZE (mode
), l
%= GET_MODE_SIZE (mode
);
969 max_size
= GET_MODE_SIZE (mode
);
976 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
977 with move instructions for mode MODE. GENFUN is the gen_... function
978 to make a move insn for that mode. DATA has all the other info. */
981 move_by_pieces_1 (insn_gen_fn genfun
, machine_mode mode
,
982 struct move_by_pieces_d
*data
)
984 unsigned int size
= GET_MODE_SIZE (mode
);
985 rtx to1
= NULL_RTX
, from1
;
987 while (data
->len
>= size
)
990 data
->offset
-= size
;
995 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
998 to1
= adjust_address (data
->to
, mode
, data
->offset
);
1001 if (data
->autinc_from
)
1002 from1
= adjust_automodify_address (data
->from
, mode
, data
->from_addr
,
1005 from1
= adjust_address (data
->from
, mode
, data
->offset
);
1007 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
1008 emit_insn (gen_add2_insn (data
->to_addr
,
1009 gen_int_mode (-(HOST_WIDE_INT
) size
,
1010 GET_MODE (data
->to_addr
))));
1011 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_from
< 0)
1012 emit_insn (gen_add2_insn (data
->from_addr
,
1013 gen_int_mode (-(HOST_WIDE_INT
) size
,
1014 GET_MODE (data
->from_addr
))));
1017 emit_insn ((*genfun
) (to1
, from1
));
1020 #ifdef PUSH_ROUNDING
1021 emit_single_push_insn (mode
, from1
, NULL
);
1027 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
1028 emit_insn (gen_add2_insn (data
->to_addr
,
1030 GET_MODE (data
->to_addr
))));
1031 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_from
> 0)
1032 emit_insn (gen_add2_insn (data
->from_addr
,
1034 GET_MODE (data
->from_addr
))));
1036 if (! data
->reverse
)
1037 data
->offset
+= size
;
1043 /* Emit code to move a block Y to a block X. This may be done with
1044 string-move instructions, with multiple scalar move instructions,
1045 or with a library call.
1047 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1048 SIZE is an rtx that says how long they are.
1049 ALIGN is the maximum alignment we can assume they have.
1050 METHOD describes what kind of copy this is, and what mechanisms may be used.
1051 MIN_SIZE is the minimal size of block to move
1052 MAX_SIZE is the maximal size of block to move, if it can not be represented
1053 in unsigned HOST_WIDE_INT, than it is mask of all ones.
1055 Return the address of the new block, if memcpy is called and returns it,
1059 emit_block_move_hints (rtx x
, rtx y
, rtx size
, enum block_op_methods method
,
1060 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
1061 unsigned HOST_WIDE_INT min_size
,
1062 unsigned HOST_WIDE_INT max_size
,
1063 unsigned HOST_WIDE_INT probable_max_size
)
1070 if (CONST_INT_P (size
)
1071 && INTVAL (size
) == 0)
1076 case BLOCK_OP_NORMAL
:
1077 case BLOCK_OP_TAILCALL
:
1078 may_use_call
= true;
1081 case BLOCK_OP_CALL_PARM
:
1082 may_use_call
= block_move_libcall_safe_for_call_parm ();
1084 /* Make inhibit_defer_pop nonzero around the library call
1085 to force it to pop the arguments right away. */
1089 case BLOCK_OP_NO_LIBCALL
:
1090 may_use_call
= false;
1097 gcc_assert (MEM_P (x
) && MEM_P (y
));
1098 align
= MIN (MEM_ALIGN (x
), MEM_ALIGN (y
));
1099 gcc_assert (align
>= BITS_PER_UNIT
);
1101 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1102 block copy is more efficient for other large modes, e.g. DCmode. */
1103 x
= adjust_address (x
, BLKmode
, 0);
1104 y
= adjust_address (y
, BLKmode
, 0);
1106 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1107 can be incorrect is coming from __builtin_memcpy. */
1108 if (CONST_INT_P (size
))
1110 x
= shallow_copy_rtx (x
);
1111 y
= shallow_copy_rtx (y
);
1112 set_mem_size (x
, INTVAL (size
));
1113 set_mem_size (y
, INTVAL (size
));
1116 if (CONST_INT_P (size
) && can_move_by_pieces (INTVAL (size
), align
))
1117 move_by_pieces (x
, y
, INTVAL (size
), align
, 0);
1118 else if (emit_block_move_via_movmem (x
, y
, size
, align
,
1119 expected_align
, expected_size
,
1120 min_size
, max_size
, probable_max_size
))
1122 else if (may_use_call
1123 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x
))
1124 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y
)))
1126 /* Since x and y are passed to a libcall, mark the corresponding
1127 tree EXPR as addressable. */
1128 tree y_expr
= MEM_EXPR (y
);
1129 tree x_expr
= MEM_EXPR (x
);
1131 mark_addressable (y_expr
);
1133 mark_addressable (x_expr
);
1134 retval
= emit_block_move_via_libcall (x
, y
, size
,
1135 method
== BLOCK_OP_TAILCALL
);
1139 emit_block_move_via_loop (x
, y
, size
, align
);
1141 if (method
== BLOCK_OP_CALL_PARM
)
1148 emit_block_move (rtx x
, rtx y
, rtx size
, enum block_op_methods method
)
1150 unsigned HOST_WIDE_INT max
, min
= 0;
1151 if (GET_CODE (size
) == CONST_INT
)
1152 min
= max
= UINTVAL (size
);
1154 max
= GET_MODE_MASK (GET_MODE (size
));
1155 return emit_block_move_hints (x
, y
, size
, method
, 0, -1,
1159 /* A subroutine of emit_block_move. Returns true if calling the
1160 block move libcall will not clobber any parameters which may have
1161 already been placed on the stack. */
1164 block_move_libcall_safe_for_call_parm (void)
1166 #if defined (REG_PARM_STACK_SPACE)
1170 /* If arguments are pushed on the stack, then they're safe. */
1174 /* If registers go on the stack anyway, any argument is sure to clobber
1175 an outgoing argument. */
1176 #if defined (REG_PARM_STACK_SPACE)
1177 fn
= emit_block_move_libcall_fn (false);
1178 /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
1179 depend on its argument. */
1181 if (OUTGOING_REG_PARM_STACK_SPACE ((!fn
? NULL_TREE
: TREE_TYPE (fn
)))
1182 && REG_PARM_STACK_SPACE (fn
) != 0)
1186 /* If any argument goes in memory, then it might clobber an outgoing
1189 CUMULATIVE_ARGS args_so_far_v
;
1190 cumulative_args_t args_so_far
;
1193 fn
= emit_block_move_libcall_fn (false);
1194 INIT_CUMULATIVE_ARGS (args_so_far_v
, TREE_TYPE (fn
), NULL_RTX
, 0, 3);
1195 args_so_far
= pack_cumulative_args (&args_so_far_v
);
1197 arg
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1198 for ( ; arg
!= void_list_node
; arg
= TREE_CHAIN (arg
))
1200 machine_mode mode
= TYPE_MODE (TREE_VALUE (arg
));
1201 rtx tmp
= targetm
.calls
.function_arg (args_so_far
, mode
,
1203 if (!tmp
|| !REG_P (tmp
))
1205 if (targetm
.calls
.arg_partial_bytes (args_so_far
, mode
, NULL
, 1))
1207 targetm
.calls
.function_arg_advance (args_so_far
, mode
,
1214 /* A subroutine of emit_block_move. Expand a movmem pattern;
1215 return true if successful. */
1218 emit_block_move_via_movmem (rtx x
, rtx y
, rtx size
, unsigned int align
,
1219 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
1220 unsigned HOST_WIDE_INT min_size
,
1221 unsigned HOST_WIDE_INT max_size
,
1222 unsigned HOST_WIDE_INT probable_max_size
)
1224 int save_volatile_ok
= volatile_ok
;
1227 if (expected_align
< align
)
1228 expected_align
= align
;
1229 if (expected_size
!= -1)
1231 if ((unsigned HOST_WIDE_INT
)expected_size
> probable_max_size
)
1232 expected_size
= probable_max_size
;
1233 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
1234 expected_size
= min_size
;
1237 /* Since this is a move insn, we don't care about volatility. */
1240 /* Try the most limited insn first, because there's no point
1241 including more than one in the machine description unless
1242 the more limited one has some advantage. */
1244 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
1245 mode
= GET_MODE_WIDER_MODE (mode
))
1247 enum insn_code code
= direct_optab_handler (movmem_optab
, mode
);
1249 if (code
!= CODE_FOR_nothing
1250 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1251 here because if SIZE is less than the mode mask, as it is
1252 returned by the macro, it will definitely be less than the
1253 actual mode mask. Since SIZE is within the Pmode address
1254 space, we limit MODE to Pmode. */
1255 && ((CONST_INT_P (size
)
1256 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
1257 <= (GET_MODE_MASK (mode
) >> 1)))
1258 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
1259 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
1261 struct expand_operand ops
[9];
1264 /* ??? When called via emit_block_move_for_call, it'd be
1265 nice if there were some way to inform the backend, so
1266 that it doesn't fail the expansion because it thinks
1267 emitting the libcall would be more efficient. */
1268 nops
= insn_data
[(int) code
].n_generator_args
;
1269 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
1271 create_fixed_operand (&ops
[0], x
);
1272 create_fixed_operand (&ops
[1], y
);
1273 /* The check above guarantees that this size conversion is valid. */
1274 create_convert_operand_to (&ops
[2], size
, mode
, true);
1275 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
1278 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
1279 create_integer_operand (&ops
[5], expected_size
);
1283 create_integer_operand (&ops
[6], min_size
);
1284 /* If we can not represent the maximal size,
1285 make parameter NULL. */
1286 if ((HOST_WIDE_INT
) max_size
!= -1)
1287 create_integer_operand (&ops
[7], max_size
);
1289 create_fixed_operand (&ops
[7], NULL
);
1293 /* If we can not represent the maximal size,
1294 make parameter NULL. */
1295 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
1296 create_integer_operand (&ops
[8], probable_max_size
);
1298 create_fixed_operand (&ops
[8], NULL
);
1300 if (maybe_expand_insn (code
, nops
, ops
))
1302 volatile_ok
= save_volatile_ok
;
1308 volatile_ok
= save_volatile_ok
;
1312 /* A subroutine of emit_block_move. Expand a call to memcpy.
1313 Return the return value from memcpy, 0 otherwise. */
1316 emit_block_move_via_libcall (rtx dst
, rtx src
, rtx size
, bool tailcall
)
1318 rtx dst_addr
, src_addr
;
1319 tree call_expr
, fn
, src_tree
, dst_tree
, size_tree
;
1320 machine_mode size_mode
;
1323 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1324 pseudos. We can then place those new pseudos into a VAR_DECL and
1327 dst_addr
= copy_addr_to_reg (XEXP (dst
, 0));
1328 src_addr
= copy_addr_to_reg (XEXP (src
, 0));
1330 dst_addr
= convert_memory_address (ptr_mode
, dst_addr
);
1331 src_addr
= convert_memory_address (ptr_mode
, src_addr
);
1333 dst_tree
= make_tree (ptr_type_node
, dst_addr
);
1334 src_tree
= make_tree (ptr_type_node
, src_addr
);
1336 size_mode
= TYPE_MODE (sizetype
);
1338 size
= convert_to_mode (size_mode
, size
, 1);
1339 size
= copy_to_mode_reg (size_mode
, size
);
1341 /* It is incorrect to use the libcall calling conventions to call
1342 memcpy in this context. This could be a user call to memcpy and
1343 the user may wish to examine the return value from memcpy. For
1344 targets where libcalls and normal calls have different conventions
1345 for returning pointers, we could end up generating incorrect code. */
1347 size_tree
= make_tree (sizetype
, size
);
1349 fn
= emit_block_move_libcall_fn (true);
1350 call_expr
= build_call_expr (fn
, 3, dst_tree
, src_tree
, size_tree
);
1351 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
1353 retval
= expand_normal (call_expr
);
1358 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1359 for the function we use for block copies. */
1361 static GTY(()) tree block_move_fn
;
1364 init_block_move_fn (const char *asmspec
)
1368 tree args
, fn
, attrs
, attr_args
;
1370 fn
= get_identifier ("memcpy");
1371 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
1372 const_ptr_type_node
, sizetype
,
1375 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
1376 DECL_EXTERNAL (fn
) = 1;
1377 TREE_PUBLIC (fn
) = 1;
1378 DECL_ARTIFICIAL (fn
) = 1;
1379 TREE_NOTHROW (fn
) = 1;
1380 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
1381 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
1383 attr_args
= build_tree_list (NULL_TREE
, build_string (1, "1"));
1384 attrs
= tree_cons (get_identifier ("fn spec"), attr_args
, NULL
);
1386 decl_attributes (&fn
, attrs
, ATTR_FLAG_BUILT_IN
);
1392 set_user_assembler_name (block_move_fn
, asmspec
);
1396 emit_block_move_libcall_fn (int for_call
)
1398 static bool emitted_extern
;
1401 init_block_move_fn (NULL
);
1403 if (for_call
&& !emitted_extern
)
1405 emitted_extern
= true;
1406 make_decl_rtl (block_move_fn
);
1409 return block_move_fn
;
1412 /* A subroutine of emit_block_move. Copy the data via an explicit
1413 loop. This is used only when libcalls are forbidden. */
1414 /* ??? It'd be nice to copy in hunks larger than QImode. */
1417 emit_block_move_via_loop (rtx x
, rtx y
, rtx size
,
1418 unsigned int align ATTRIBUTE_UNUSED
)
1420 rtx_code_label
*cmp_label
, *top_label
;
1421 rtx iter
, x_addr
, y_addr
, tmp
;
1422 machine_mode x_addr_mode
= get_address_mode (x
);
1423 machine_mode y_addr_mode
= get_address_mode (y
);
1424 machine_mode iter_mode
;
1426 iter_mode
= GET_MODE (size
);
1427 if (iter_mode
== VOIDmode
)
1428 iter_mode
= word_mode
;
1430 top_label
= gen_label_rtx ();
1431 cmp_label
= gen_label_rtx ();
1432 iter
= gen_reg_rtx (iter_mode
);
1434 emit_move_insn (iter
, const0_rtx
);
1436 x_addr
= force_operand (XEXP (x
, 0), NULL_RTX
);
1437 y_addr
= force_operand (XEXP (y
, 0), NULL_RTX
);
1438 do_pending_stack_adjust ();
1440 emit_jump (cmp_label
);
1441 emit_label (top_label
);
1443 tmp
= convert_modes (x_addr_mode
, iter_mode
, iter
, true);
1444 x_addr
= simplify_gen_binary (PLUS
, x_addr_mode
, x_addr
, tmp
);
1446 if (x_addr_mode
!= y_addr_mode
)
1447 tmp
= convert_modes (y_addr_mode
, iter_mode
, iter
, true);
1448 y_addr
= simplify_gen_binary (PLUS
, y_addr_mode
, y_addr
, tmp
);
1450 x
= change_address (x
, QImode
, x_addr
);
1451 y
= change_address (y
, QImode
, y_addr
);
1453 emit_move_insn (x
, y
);
1455 tmp
= expand_simple_binop (iter_mode
, PLUS
, iter
, const1_rtx
, iter
,
1456 true, OPTAB_LIB_WIDEN
);
1458 emit_move_insn (iter
, tmp
);
1460 emit_label (cmp_label
);
1462 emit_cmp_and_jump_insns (iter
, size
, LT
, NULL_RTX
, iter_mode
,
1463 true, top_label
, REG_BR_PROB_BASE
* 90 / 100);
1466 /* Copy all or part of a value X into registers starting at REGNO.
1467 The number of registers to be filled is NREGS. */
1470 move_block_to_reg (int regno
, rtx x
, int nregs
, machine_mode mode
)
1475 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
1476 x
= validize_mem (force_const_mem (mode
, x
));
1478 /* See if the machine can do this with a load multiple insn. */
1479 if (targetm
.have_load_multiple ())
1481 rtx_insn
*last
= get_last_insn ();
1482 rtx first
= gen_rtx_REG (word_mode
, regno
);
1483 if (rtx_insn
*pat
= targetm
.gen_load_multiple (first
, x
,
1490 delete_insns_since (last
);
1493 for (int i
= 0; i
< nregs
; i
++)
1494 emit_move_insn (gen_rtx_REG (word_mode
, regno
+ i
),
1495 operand_subword_force (x
, i
, mode
));
1498 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1499 The number of registers to be filled is NREGS. */
1502 move_block_from_reg (int regno
, rtx x
, int nregs
)
1507 /* See if the machine can do this with a store multiple insn. */
1508 if (targetm
.have_store_multiple ())
1510 rtx_insn
*last
= get_last_insn ();
1511 rtx first
= gen_rtx_REG (word_mode
, regno
);
1512 if (rtx_insn
*pat
= targetm
.gen_store_multiple (x
, first
,
1519 delete_insns_since (last
);
1522 for (int i
= 0; i
< nregs
; i
++)
1524 rtx tem
= operand_subword (x
, i
, 1, BLKmode
);
1528 emit_move_insn (tem
, gen_rtx_REG (word_mode
, regno
+ i
));
1532 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1533 ORIG, where ORIG is a non-consecutive group of registers represented by
1534 a PARALLEL. The clone is identical to the original except in that the
1535 original set of registers is replaced by a new set of pseudo registers.
1536 The new set has the same modes as the original set. */
1539 gen_group_rtx (rtx orig
)
1544 gcc_assert (GET_CODE (orig
) == PARALLEL
);
1546 length
= XVECLEN (orig
, 0);
1547 tmps
= XALLOCAVEC (rtx
, length
);
1549 /* Skip a NULL entry in first slot. */
1550 i
= XEXP (XVECEXP (orig
, 0, 0), 0) ? 0 : 1;
1555 for (; i
< length
; i
++)
1557 machine_mode mode
= GET_MODE (XEXP (XVECEXP (orig
, 0, i
), 0));
1558 rtx offset
= XEXP (XVECEXP (orig
, 0, i
), 1);
1560 tmps
[i
] = gen_rtx_EXPR_LIST (VOIDmode
, gen_reg_rtx (mode
), offset
);
1563 return gen_rtx_PARALLEL (GET_MODE (orig
), gen_rtvec_v (length
, tmps
));
1566 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1567 except that values are placed in TMPS[i], and must later be moved
1568 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1571 emit_group_load_1 (rtx
*tmps
, rtx dst
, rtx orig_src
, tree type
, int ssize
)
1575 machine_mode m
= GET_MODE (orig_src
);
1577 gcc_assert (GET_CODE (dst
) == PARALLEL
);
1580 && !SCALAR_INT_MODE_P (m
)
1581 && !MEM_P (orig_src
)
1582 && GET_CODE (orig_src
) != CONCAT
)
1584 machine_mode imode
= int_mode_for_mode (GET_MODE (orig_src
));
1585 if (imode
== BLKmode
)
1586 src
= assign_stack_temp (GET_MODE (orig_src
), ssize
);
1588 src
= gen_reg_rtx (imode
);
1589 if (imode
!= BLKmode
)
1590 src
= gen_lowpart (GET_MODE (orig_src
), src
);
1591 emit_move_insn (src
, orig_src
);
1592 /* ...and back again. */
1593 if (imode
!= BLKmode
)
1594 src
= gen_lowpart (imode
, src
);
1595 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1599 /* Check for a NULL entry, used to indicate that the parameter goes
1600 both on the stack and in registers. */
1601 if (XEXP (XVECEXP (dst
, 0, 0), 0))
1606 /* Process the pieces. */
1607 for (i
= start
; i
< XVECLEN (dst
, 0); i
++)
1609 machine_mode mode
= GET_MODE (XEXP (XVECEXP (dst
, 0, i
), 0));
1610 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (dst
, 0, i
), 1));
1611 unsigned int bytelen
= GET_MODE_SIZE (mode
);
1614 /* Handle trailing fragments that run over the size of the struct. */
1615 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
1617 /* Arrange to shift the fragment to where it belongs.
1618 extract_bit_field loads to the lsb of the reg. */
1620 #ifdef BLOCK_REG_PADDING
1621 BLOCK_REG_PADDING (GET_MODE (orig_src
), type
, i
== start
)
1622 == (BYTES_BIG_ENDIAN
? upward
: downward
)
1627 shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
1628 bytelen
= ssize
- bytepos
;
1629 gcc_assert (bytelen
> 0);
1632 /* If we won't be loading directly from memory, protect the real source
1633 from strange tricks we might play; but make sure that the source can
1634 be loaded directly into the destination. */
1636 if (!MEM_P (orig_src
)
1637 && (!CONSTANT_P (orig_src
)
1638 || (GET_MODE (orig_src
) != mode
1639 && GET_MODE (orig_src
) != VOIDmode
)))
1641 if (GET_MODE (orig_src
) == VOIDmode
)
1642 src
= gen_reg_rtx (mode
);
1644 src
= gen_reg_rtx (GET_MODE (orig_src
));
1646 emit_move_insn (src
, orig_src
);
1649 /* Optimize the access just a bit. */
1651 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (src
))
1652 || MEM_ALIGN (src
) >= GET_MODE_ALIGNMENT (mode
))
1653 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
1654 && bytelen
== GET_MODE_SIZE (mode
))
1656 tmps
[i
] = gen_reg_rtx (mode
);
1657 emit_move_insn (tmps
[i
], adjust_address (src
, mode
, bytepos
));
1659 else if (COMPLEX_MODE_P (mode
)
1660 && GET_MODE (src
) == mode
1661 && bytelen
== GET_MODE_SIZE (mode
))
1662 /* Let emit_move_complex do the bulk of the work. */
1664 else if (GET_CODE (src
) == CONCAT
)
1666 unsigned int slen
= GET_MODE_SIZE (GET_MODE (src
));
1667 unsigned int slen0
= GET_MODE_SIZE (GET_MODE (XEXP (src
, 0)));
1669 if ((bytepos
== 0 && bytelen
== slen0
)
1670 || (bytepos
!= 0 && bytepos
+ bytelen
<= slen
))
1672 /* The following assumes that the concatenated objects all
1673 have the same size. In this case, a simple calculation
1674 can be used to determine the object and the bit field
1676 tmps
[i
] = XEXP (src
, bytepos
/ slen0
);
1677 if (! CONSTANT_P (tmps
[i
])
1678 && (!REG_P (tmps
[i
]) || GET_MODE (tmps
[i
]) != mode
))
1679 tmps
[i
] = extract_bit_field (tmps
[i
], bytelen
* BITS_PER_UNIT
,
1680 (bytepos
% slen0
) * BITS_PER_UNIT
,
1681 1, NULL_RTX
, mode
, mode
, false);
1687 gcc_assert (!bytepos
);
1688 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1689 emit_move_insn (mem
, src
);
1690 tmps
[i
] = extract_bit_field (mem
, bytelen
* BITS_PER_UNIT
,
1691 0, 1, NULL_RTX
, mode
, mode
, false);
1694 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1695 SIMD register, which is currently broken. While we get GCC
1696 to emit proper RTL for these cases, let's dump to memory. */
1697 else if (VECTOR_MODE_P (GET_MODE (dst
))
1700 int slen
= GET_MODE_SIZE (GET_MODE (src
));
1703 mem
= assign_stack_temp (GET_MODE (src
), slen
);
1704 emit_move_insn (mem
, src
);
1705 tmps
[i
] = adjust_address (mem
, mode
, (int) bytepos
);
1707 else if (CONSTANT_P (src
) && GET_MODE (dst
) != BLKmode
1708 && XVECLEN (dst
, 0) > 1)
1709 tmps
[i
] = simplify_gen_subreg (mode
, src
, GET_MODE (dst
), bytepos
);
1710 else if (CONSTANT_P (src
))
1712 HOST_WIDE_INT len
= (HOST_WIDE_INT
) bytelen
;
1720 /* TODO: const_wide_int can have sizes other than this... */
1721 gcc_assert (2 * len
== ssize
);
1722 split_double (src
, &first
, &second
);
1729 else if (REG_P (src
) && GET_MODE (src
) == mode
)
1732 tmps
[i
] = extract_bit_field (src
, bytelen
* BITS_PER_UNIT
,
1733 bytepos
* BITS_PER_UNIT
, 1, NULL_RTX
,
1737 tmps
[i
] = expand_shift (LSHIFT_EXPR
, mode
, tmps
[i
],
1742 /* Emit code to move a block SRC of type TYPE to a block DST,
1743 where DST is non-consecutive registers represented by a PARALLEL.
1744 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1748 emit_group_load (rtx dst
, rtx src
, tree type
, int ssize
)
1753 tmps
= XALLOCAVEC (rtx
, XVECLEN (dst
, 0));
1754 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
1756 /* Copy the extracted pieces into the proper (probable) hard regs. */
1757 for (i
= 0; i
< XVECLEN (dst
, 0); i
++)
1759 rtx d
= XEXP (XVECEXP (dst
, 0, i
), 0);
1762 emit_move_insn (d
, tmps
[i
]);
1766 /* Similar, but load SRC into new pseudos in a format that looks like
1767 PARALLEL. This can later be fed to emit_group_move to get things
1768 in the right place. */
1771 emit_group_load_into_temps (rtx parallel
, rtx src
, tree type
, int ssize
)
1776 vec
= rtvec_alloc (XVECLEN (parallel
, 0));
1777 emit_group_load_1 (&RTVEC_ELT (vec
, 0), parallel
, src
, type
, ssize
);
1779 /* Convert the vector to look just like the original PARALLEL, except
1780 with the computed values. */
1781 for (i
= 0; i
< XVECLEN (parallel
, 0); i
++)
1783 rtx e
= XVECEXP (parallel
, 0, i
);
1784 rtx d
= XEXP (e
, 0);
1788 d
= force_reg (GET_MODE (d
), RTVEC_ELT (vec
, i
));
1789 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), d
, XEXP (e
, 1));
1791 RTVEC_ELT (vec
, i
) = e
;
1794 return gen_rtx_PARALLEL (GET_MODE (parallel
), vec
);
1797 /* Emit code to move a block SRC to block DST, where SRC and DST are
1798 non-consecutive groups of registers, each represented by a PARALLEL. */
1801 emit_group_move (rtx dst
, rtx src
)
1805 gcc_assert (GET_CODE (src
) == PARALLEL
1806 && GET_CODE (dst
) == PARALLEL
1807 && XVECLEN (src
, 0) == XVECLEN (dst
, 0));
1809 /* Skip first entry if NULL. */
1810 for (i
= XEXP (XVECEXP (src
, 0, 0), 0) ? 0 : 1; i
< XVECLEN (src
, 0); i
++)
1811 emit_move_insn (XEXP (XVECEXP (dst
, 0, i
), 0),
1812 XEXP (XVECEXP (src
, 0, i
), 0));
1815 /* Move a group of registers represented by a PARALLEL into pseudos. */
1818 emit_group_move_into_temps (rtx src
)
1820 rtvec vec
= rtvec_alloc (XVECLEN (src
, 0));
1823 for (i
= 0; i
< XVECLEN (src
, 0); i
++)
1825 rtx e
= XVECEXP (src
, 0, i
);
1826 rtx d
= XEXP (e
, 0);
1829 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), copy_to_reg (d
), XEXP (e
, 1));
1830 RTVEC_ELT (vec
, i
) = e
;
1833 return gen_rtx_PARALLEL (GET_MODE (src
), vec
);
1836 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1837 where SRC is non-consecutive registers represented by a PARALLEL.
1838 SSIZE represents the total size of block ORIG_DST, or -1 if not
1842 emit_group_store (rtx orig_dst
, rtx src
, tree type ATTRIBUTE_UNUSED
, int ssize
)
1845 int start
, finish
, i
;
1846 machine_mode m
= GET_MODE (orig_dst
);
1848 gcc_assert (GET_CODE (src
) == PARALLEL
);
1850 if (!SCALAR_INT_MODE_P (m
)
1851 && !MEM_P (orig_dst
) && GET_CODE (orig_dst
) != CONCAT
)
1853 machine_mode imode
= int_mode_for_mode (GET_MODE (orig_dst
));
1854 if (imode
== BLKmode
)
1855 dst
= assign_stack_temp (GET_MODE (orig_dst
), ssize
);
1857 dst
= gen_reg_rtx (imode
);
1858 emit_group_store (dst
, src
, type
, ssize
);
1859 if (imode
!= BLKmode
)
1860 dst
= gen_lowpart (GET_MODE (orig_dst
), dst
);
1861 emit_move_insn (orig_dst
, dst
);
1865 /* Check for a NULL entry, used to indicate that the parameter goes
1866 both on the stack and in registers. */
1867 if (XEXP (XVECEXP (src
, 0, 0), 0))
1871 finish
= XVECLEN (src
, 0);
1873 tmps
= XALLOCAVEC (rtx
, finish
);
1875 /* Copy the (probable) hard regs into pseudos. */
1876 for (i
= start
; i
< finish
; i
++)
1878 rtx reg
= XEXP (XVECEXP (src
, 0, i
), 0);
1879 if (!REG_P (reg
) || REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
1881 tmps
[i
] = gen_reg_rtx (GET_MODE (reg
));
1882 emit_move_insn (tmps
[i
], reg
);
1888 /* If we won't be storing directly into memory, protect the real destination
1889 from strange tricks we might play. */
1891 if (GET_CODE (dst
) == PARALLEL
)
1895 /* We can get a PARALLEL dst if there is a conditional expression in
1896 a return statement. In that case, the dst and src are the same,
1897 so no action is necessary. */
1898 if (rtx_equal_p (dst
, src
))
1901 /* It is unclear if we can ever reach here, but we may as well handle
1902 it. Allocate a temporary, and split this into a store/load to/from
1904 temp
= assign_stack_temp (GET_MODE (dst
), ssize
);
1905 emit_group_store (temp
, src
, type
, ssize
);
1906 emit_group_load (dst
, temp
, type
, ssize
);
1909 else if (!MEM_P (dst
) && GET_CODE (dst
) != CONCAT
)
1911 machine_mode outer
= GET_MODE (dst
);
1913 HOST_WIDE_INT bytepos
;
1917 if (!REG_P (dst
) || REGNO (dst
) < FIRST_PSEUDO_REGISTER
)
1918 dst
= gen_reg_rtx (outer
);
1920 /* Make life a bit easier for combine. */
1921 /* If the first element of the vector is the low part
1922 of the destination mode, use a paradoxical subreg to
1923 initialize the destination. */
1926 inner
= GET_MODE (tmps
[start
]);
1927 bytepos
= subreg_lowpart_offset (inner
, outer
);
1928 if (INTVAL (XEXP (XVECEXP (src
, 0, start
), 1)) == bytepos
)
1930 temp
= simplify_gen_subreg (outer
, tmps
[start
],
1934 emit_move_insn (dst
, temp
);
1941 /* If the first element wasn't the low part, try the last. */
1943 && start
< finish
- 1)
1945 inner
= GET_MODE (tmps
[finish
- 1]);
1946 bytepos
= subreg_lowpart_offset (inner
, outer
);
1947 if (INTVAL (XEXP (XVECEXP (src
, 0, finish
- 1), 1)) == bytepos
)
1949 temp
= simplify_gen_subreg (outer
, tmps
[finish
- 1],
1953 emit_move_insn (dst
, temp
);
1960 /* Otherwise, simply initialize the result to zero. */
1962 emit_move_insn (dst
, CONST0_RTX (outer
));
1965 /* Process the pieces. */
1966 for (i
= start
; i
< finish
; i
++)
1968 HOST_WIDE_INT bytepos
= INTVAL (XEXP (XVECEXP (src
, 0, i
), 1));
1969 machine_mode mode
= GET_MODE (tmps
[i
]);
1970 unsigned int bytelen
= GET_MODE_SIZE (mode
);
1971 unsigned int adj_bytelen
;
1974 /* Handle trailing fragments that run over the size of the struct. */
1975 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
1976 adj_bytelen
= ssize
- bytepos
;
1978 adj_bytelen
= bytelen
;
1980 if (GET_CODE (dst
) == CONCAT
)
1982 if (bytepos
+ adj_bytelen
1983 <= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
1984 dest
= XEXP (dst
, 0);
1985 else if (bytepos
>= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0))))
1987 bytepos
-= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0)));
1988 dest
= XEXP (dst
, 1);
1992 machine_mode dest_mode
= GET_MODE (dest
);
1993 machine_mode tmp_mode
= GET_MODE (tmps
[i
]);
1995 gcc_assert (bytepos
== 0 && XVECLEN (src
, 0));
1997 if (GET_MODE_ALIGNMENT (dest_mode
)
1998 >= GET_MODE_ALIGNMENT (tmp_mode
))
2000 dest
= assign_stack_temp (dest_mode
,
2001 GET_MODE_SIZE (dest_mode
));
2002 emit_move_insn (adjust_address (dest
,
2010 dest
= assign_stack_temp (tmp_mode
,
2011 GET_MODE_SIZE (tmp_mode
));
2012 emit_move_insn (dest
, tmps
[i
]);
2013 dst
= adjust_address (dest
, dest_mode
, bytepos
);
2019 /* Handle trailing fragments that run over the size of the struct. */
2020 if (ssize
>= 0 && bytepos
+ (HOST_WIDE_INT
) bytelen
> ssize
)
2022 /* store_bit_field always takes its value from the lsb.
2023 Move the fragment to the lsb if it's not already there. */
2025 #ifdef BLOCK_REG_PADDING
2026 BLOCK_REG_PADDING (GET_MODE (orig_dst
), type
, i
== start
)
2027 == (BYTES_BIG_ENDIAN
? upward
: downward
)
2033 int shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
2034 tmps
[i
] = expand_shift (RSHIFT_EXPR
, mode
, tmps
[i
],
2038 /* Make sure not to write past the end of the struct. */
2039 store_bit_field (dest
,
2040 adj_bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2041 bytepos
* BITS_PER_UNIT
, ssize
* BITS_PER_UNIT
- 1,
2042 VOIDmode
, tmps
[i
], false);
2045 /* Optimize the access just a bit. */
2046 else if (MEM_P (dest
)
2047 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (dest
))
2048 || MEM_ALIGN (dest
) >= GET_MODE_ALIGNMENT (mode
))
2049 && bytepos
* BITS_PER_UNIT
% GET_MODE_ALIGNMENT (mode
) == 0
2050 && bytelen
== GET_MODE_SIZE (mode
))
2051 emit_move_insn (adjust_address (dest
, mode
, bytepos
), tmps
[i
]);
2054 store_bit_field (dest
, bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
2055 0, 0, mode
, tmps
[i
], false);
2058 /* Copy from the pseudo into the (probable) hard reg. */
2059 if (orig_dst
!= dst
)
2060 emit_move_insn (orig_dst
, dst
);
2063 /* Return a form of X that does not use a PARALLEL. TYPE is the type
2064 of the value stored in X. */
2067 maybe_emit_group_store (rtx x
, tree type
)
2069 machine_mode mode
= TYPE_MODE (type
);
2070 gcc_checking_assert (GET_MODE (x
) == VOIDmode
|| GET_MODE (x
) == mode
);
2071 if (GET_CODE (x
) == PARALLEL
)
2073 rtx result
= gen_reg_rtx (mode
);
2074 emit_group_store (result
, x
, type
, int_size_in_bytes (type
));
2080 /* Copy a BLKmode object of TYPE out of a register SRCREG into TARGET.
2082 This is used on targets that return BLKmode values in registers. */
2085 copy_blkmode_from_reg (rtx target
, rtx srcreg
, tree type
)
2087 unsigned HOST_WIDE_INT bytes
= int_size_in_bytes (type
);
2088 rtx src
= NULL
, dst
= NULL
;
2089 unsigned HOST_WIDE_INT bitsize
= MIN (TYPE_ALIGN (type
), BITS_PER_WORD
);
2090 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0;
2091 machine_mode mode
= GET_MODE (srcreg
);
2092 machine_mode tmode
= GET_MODE (target
);
2093 machine_mode copy_mode
;
2095 /* BLKmode registers created in the back-end shouldn't have survived. */
2096 gcc_assert (mode
!= BLKmode
);
2098 /* If the structure doesn't take up a whole number of words, see whether
2099 SRCREG is padded on the left or on the right. If it's on the left,
2100 set PADDING_CORRECTION to the number of bits to skip.
2102 In most ABIs, the structure will be returned at the least end of
2103 the register, which translates to right padding on little-endian
2104 targets and left padding on big-endian targets. The opposite
2105 holds if the structure is returned at the most significant
2106 end of the register. */
2107 if (bytes
% UNITS_PER_WORD
!= 0
2108 && (targetm
.calls
.return_in_msb (type
)
2110 : BYTES_BIG_ENDIAN
))
2112 = (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
) * BITS_PER_UNIT
));
2114 /* We can use a single move if we have an exact mode for the size. */
2115 else if (MEM_P (target
)
2116 && (!SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
))
2117 || MEM_ALIGN (target
) >= GET_MODE_ALIGNMENT (mode
))
2118 && bytes
== GET_MODE_SIZE (mode
))
2120 emit_move_insn (adjust_address (target
, mode
, 0), srcreg
);
2124 /* And if we additionally have the same mode for a register. */
2125 else if (REG_P (target
)
2126 && GET_MODE (target
) == mode
2127 && bytes
== GET_MODE_SIZE (mode
))
2129 emit_move_insn (target
, srcreg
);
2133 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2134 into a new pseudo which is a full word. */
2135 if (GET_MODE_SIZE (mode
) < UNITS_PER_WORD
)
2137 srcreg
= convert_to_mode (word_mode
, srcreg
, TYPE_UNSIGNED (type
));
2141 /* Copy the structure BITSIZE bits at a time. If the target lives in
2142 memory, take care of not reading/writing past its end by selecting
2143 a copy mode suited to BITSIZE. This should always be possible given
2146 If the target lives in register, make sure not to select a copy mode
2147 larger than the mode of the register.
2149 We could probably emit more efficient code for machines which do not use
2150 strict alignment, but it doesn't seem worth the effort at the current
2153 copy_mode
= word_mode
;
2156 machine_mode mem_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
2157 if (mem_mode
!= BLKmode
)
2158 copy_mode
= mem_mode
;
2160 else if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2163 for (bitpos
= 0, xbitpos
= padding_correction
;
2164 bitpos
< bytes
* BITS_PER_UNIT
;
2165 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2167 /* We need a new source operand each time xbitpos is on a
2168 word boundary and when xbitpos == padding_correction
2169 (the first time through). */
2170 if (xbitpos
% BITS_PER_WORD
== 0 || xbitpos
== padding_correction
)
2171 src
= operand_subword_force (srcreg
, xbitpos
/ BITS_PER_WORD
, mode
);
2173 /* We need a new destination operand each time bitpos is on
2175 if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
2177 else if (bitpos
% BITS_PER_WORD
== 0)
2178 dst
= operand_subword (target
, bitpos
/ BITS_PER_WORD
, 1, tmode
);
2180 /* Use xbitpos for the source extraction (right justified) and
2181 bitpos for the destination store (left justified). */
2182 store_bit_field (dst
, bitsize
, bitpos
% BITS_PER_WORD
, 0, 0, copy_mode
,
2183 extract_bit_field (src
, bitsize
,
2184 xbitpos
% BITS_PER_WORD
, 1,
2185 NULL_RTX
, copy_mode
, copy_mode
,
2191 /* Copy BLKmode value SRC into a register of mode MODE. Return the
2192 register if it contains any data, otherwise return null.
2194 This is used on targets that return BLKmode values in registers. */
2197 copy_blkmode_to_reg (machine_mode mode
, tree src
)
2200 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0, bytes
;
2201 unsigned int bitsize
;
2202 rtx
*dst_words
, dst
, x
, src_word
= NULL_RTX
, dst_word
= NULL_RTX
;
2203 machine_mode dst_mode
;
2205 gcc_assert (TYPE_MODE (TREE_TYPE (src
)) == BLKmode
);
2207 x
= expand_normal (src
);
2209 bytes
= int_size_in_bytes (TREE_TYPE (src
));
2213 /* If the structure doesn't take up a whole number of words, see
2214 whether the register value should be padded on the left or on
2215 the right. Set PADDING_CORRECTION to the number of padding
2216 bits needed on the left side.
2218 In most ABIs, the structure will be returned at the least end of
2219 the register, which translates to right padding on little-endian
2220 targets and left padding on big-endian targets. The opposite
2221 holds if the structure is returned at the most significant
2222 end of the register. */
2223 if (bytes
% UNITS_PER_WORD
!= 0
2224 && (targetm
.calls
.return_in_msb (TREE_TYPE (src
))
2226 : BYTES_BIG_ENDIAN
))
2227 padding_correction
= (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
)
2230 n_regs
= (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
2231 dst_words
= XALLOCAVEC (rtx
, n_regs
);
2232 bitsize
= MIN (TYPE_ALIGN (TREE_TYPE (src
)), BITS_PER_WORD
);
2234 /* Copy the structure BITSIZE bits at a time. */
2235 for (bitpos
= 0, xbitpos
= padding_correction
;
2236 bitpos
< bytes
* BITS_PER_UNIT
;
2237 bitpos
+= bitsize
, xbitpos
+= bitsize
)
2239 /* We need a new destination pseudo each time xbitpos is
2240 on a word boundary and when xbitpos == padding_correction
2241 (the first time through). */
2242 if (xbitpos
% BITS_PER_WORD
== 0
2243 || xbitpos
== padding_correction
)
2245 /* Generate an appropriate register. */
2246 dst_word
= gen_reg_rtx (word_mode
);
2247 dst_words
[xbitpos
/ BITS_PER_WORD
] = dst_word
;
2249 /* Clear the destination before we move anything into it. */
2250 emit_move_insn (dst_word
, CONST0_RTX (word_mode
));
2253 /* We need a new source operand each time bitpos is on a word
2255 if (bitpos
% BITS_PER_WORD
== 0)
2256 src_word
= operand_subword_force (x
, bitpos
/ BITS_PER_WORD
, BLKmode
);
2258 /* Use bitpos for the source extraction (left justified) and
2259 xbitpos for the destination store (right justified). */
2260 store_bit_field (dst_word
, bitsize
, xbitpos
% BITS_PER_WORD
,
2262 extract_bit_field (src_word
, bitsize
,
2263 bitpos
% BITS_PER_WORD
, 1,
2264 NULL_RTX
, word_mode
, word_mode
,
2269 if (mode
== BLKmode
)
2271 /* Find the smallest integer mode large enough to hold the
2272 entire structure. */
2273 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
2275 mode
= GET_MODE_WIDER_MODE (mode
))
2276 /* Have we found a large enough mode? */
2277 if (GET_MODE_SIZE (mode
) >= bytes
)
2280 /* A suitable mode should have been found. */
2281 gcc_assert (mode
!= VOIDmode
);
2284 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (word_mode
))
2285 dst_mode
= word_mode
;
2288 dst
= gen_reg_rtx (dst_mode
);
2290 for (i
= 0; i
< n_regs
; i
++)
2291 emit_move_insn (operand_subword (dst
, i
, 0, dst_mode
), dst_words
[i
]);
2293 if (mode
!= dst_mode
)
2294 dst
= gen_lowpart (mode
, dst
);
2299 /* Add a USE expression for REG to the (possibly empty) list pointed
2300 to by CALL_FUSAGE. REG must denote a hard register. */
2303 use_reg_mode (rtx
*call_fusage
, rtx reg
, machine_mode mode
)
2305 gcc_assert (REG_P (reg
));
2307 if (!HARD_REGISTER_P (reg
))
2311 = gen_rtx_EXPR_LIST (mode
, gen_rtx_USE (VOIDmode
, reg
), *call_fusage
);
2314 /* Add a CLOBBER expression for REG to the (possibly empty) list pointed
2315 to by CALL_FUSAGE. REG must denote a hard register. */
2318 clobber_reg_mode (rtx
*call_fusage
, rtx reg
, machine_mode mode
)
2320 gcc_assert (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
);
2323 = gen_rtx_EXPR_LIST (mode
, gen_rtx_CLOBBER (VOIDmode
, reg
), *call_fusage
);
2326 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2327 starting at REGNO. All of these registers must be hard registers. */
2330 use_regs (rtx
*call_fusage
, int regno
, int nregs
)
2334 gcc_assert (regno
+ nregs
<= FIRST_PSEUDO_REGISTER
);
2336 for (i
= 0; i
< nregs
; i
++)
2337 use_reg (call_fusage
, regno_reg_rtx
[regno
+ i
]);
2340 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2341 PARALLEL REGS. This is for calls that pass values in multiple
2342 non-contiguous locations. The Irix 6 ABI has examples of this. */
2345 use_group_regs (rtx
*call_fusage
, rtx regs
)
2349 for (i
= 0; i
< XVECLEN (regs
, 0); i
++)
2351 rtx reg
= XEXP (XVECEXP (regs
, 0, i
), 0);
2353 /* A NULL entry means the parameter goes both on the stack and in
2354 registers. This can also be a MEM for targets that pass values
2355 partially on the stack and partially in registers. */
2356 if (reg
!= 0 && REG_P (reg
))
2357 use_reg (call_fusage
, reg
);
2361 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2362 assigment and the code of the expresion on the RHS is CODE. Return
2366 get_def_for_expr (tree name
, enum tree_code code
)
2370 if (TREE_CODE (name
) != SSA_NAME
)
2373 def_stmt
= get_gimple_for_ssa_name (name
);
2375 || gimple_assign_rhs_code (def_stmt
) != code
)
2381 /* Return the defining gimple statement for SSA_NAME NAME if it is an
2382 assigment and the class of the expresion on the RHS is CLASS. Return
2386 get_def_for_expr_class (tree name
, enum tree_code_class tclass
)
2390 if (TREE_CODE (name
) != SSA_NAME
)
2393 def_stmt
= get_gimple_for_ssa_name (name
);
2395 || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt
)) != tclass
)
2402 /* Determine whether the LEN bytes generated by CONSTFUN can be
2403 stored to memory using several move instructions. CONSTFUNDATA is
2404 a pointer which will be passed as argument in every CONSTFUN call.
2405 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2406 a memset operation and false if it's a copy of a constant string.
2407 Return nonzero if a call to store_by_pieces should succeed. */
2410 can_store_by_pieces (unsigned HOST_WIDE_INT len
,
2411 rtx (*constfun
) (void *, HOST_WIDE_INT
, machine_mode
),
2412 void *constfundata
, unsigned int align
, bool memsetp
)
2414 unsigned HOST_WIDE_INT l
;
2415 unsigned int max_size
;
2416 HOST_WIDE_INT offset
= 0;
2418 enum insn_code icode
;
2420 /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
2421 rtx cst ATTRIBUTE_UNUSED
;
2426 if (!targetm
.use_by_pieces_infrastructure_p (len
, align
,
2430 optimize_insn_for_speed_p ()))
2433 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2435 /* We would first store what we can in the largest integer mode, then go to
2436 successively smaller modes. */
2439 reverse
<= (HAVE_PRE_DECREMENT
|| HAVE_POST_DECREMENT
);
2443 max_size
= STORE_MAX_PIECES
+ 1;
2444 while (max_size
> 1 && l
> 0)
2446 mode
= widest_int_mode_for_size (max_size
);
2448 if (mode
== VOIDmode
)
2451 icode
= optab_handler (mov_optab
, mode
);
2452 if (icode
!= CODE_FOR_nothing
2453 && align
>= GET_MODE_ALIGNMENT (mode
))
2455 unsigned int size
= GET_MODE_SIZE (mode
);
2462 cst
= (*constfun
) (constfundata
, offset
, mode
);
2463 if (!targetm
.legitimate_constant_p (mode
, cst
))
2473 max_size
= GET_MODE_SIZE (mode
);
2476 /* The code above should have handled everything. */
2483 /* Generate several move instructions to store LEN bytes generated by
2484 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2485 pointer which will be passed as argument in every CONSTFUN call.
2486 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
2487 a memset operation and false if it's a copy of a constant string.
2488 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2489 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2493 store_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
,
2494 rtx (*constfun
) (void *, HOST_WIDE_INT
, machine_mode
),
2495 void *constfundata
, unsigned int align
, bool memsetp
, int endp
)
2497 machine_mode to_addr_mode
= get_address_mode (to
);
2498 struct store_by_pieces_d data
;
2502 gcc_assert (endp
!= 2);
2506 gcc_assert (targetm
.use_by_pieces_infrastructure_p
2511 optimize_insn_for_speed_p ()));
2513 data
.constfun
= constfun
;
2514 data
.constfundata
= constfundata
;
2517 store_by_pieces_1 (&data
, align
);
2522 gcc_assert (!data
.reverse
);
2527 if (HAVE_POST_INCREMENT
&& data
.explicit_inc_to
> 0)
2528 emit_insn (gen_add2_insn (data
.to_addr
, constm1_rtx
));
2530 data
.to_addr
= copy_to_mode_reg (to_addr_mode
,
2531 plus_constant (to_addr_mode
,
2535 to1
= adjust_automodify_address (data
.to
, QImode
, data
.to_addr
,
2542 to1
= adjust_address (data
.to
, QImode
, data
.offset
);
2550 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2551 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2554 clear_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
, unsigned int align
)
2556 struct store_by_pieces_d data
;
2561 data
.constfun
= clear_by_pieces_1
;
2562 data
.constfundata
= NULL
;
2565 store_by_pieces_1 (&data
, align
);
2568 /* Callback routine for clear_by_pieces.
2569 Return const0_rtx unconditionally. */
2572 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED
,
2573 HOST_WIDE_INT offset ATTRIBUTE_UNUSED
,
2574 machine_mode mode ATTRIBUTE_UNUSED
)
2579 /* Subroutine of clear_by_pieces and store_by_pieces.
2580 Generate several move instructions to store LEN bytes of block TO. (A MEM
2581 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2584 store_by_pieces_1 (struct store_by_pieces_d
*data ATTRIBUTE_UNUSED
,
2585 unsigned int align ATTRIBUTE_UNUSED
)
2587 machine_mode to_addr_mode
= get_address_mode (data
->to
);
2588 rtx to_addr
= XEXP (data
->to
, 0);
2589 unsigned int max_size
= STORE_MAX_PIECES
+ 1;
2590 enum insn_code icode
;
2593 data
->to_addr
= to_addr
;
2595 = (GET_CODE (to_addr
) == PRE_INC
|| GET_CODE (to_addr
) == PRE_DEC
2596 || GET_CODE (to_addr
) == POST_INC
|| GET_CODE (to_addr
) == POST_DEC
);
2598 data
->explicit_inc_to
= 0;
2600 = (GET_CODE (to_addr
) == PRE_DEC
|| GET_CODE (to_addr
) == POST_DEC
);
2602 data
->offset
= data
->len
;
2604 /* If storing requires more than two move insns,
2605 copy addresses to registers (to make displacements shorter)
2606 and use post-increment if available. */
2607 if (!data
->autinc_to
2608 && move_by_pieces_ninsns (data
->len
, align
, max_size
) > 2)
2610 /* Determine the main mode we'll be using.
2611 MODE might not be used depending on the definitions of the
2612 USE_* macros below. */
2613 machine_mode mode ATTRIBUTE_UNUSED
2614 = widest_int_mode_for_size (max_size
);
2616 if (USE_STORE_PRE_DECREMENT (mode
) && data
->reverse
&& ! data
->autinc_to
)
2618 data
->to_addr
= copy_to_mode_reg (to_addr_mode
,
2619 plus_constant (to_addr_mode
,
2622 data
->autinc_to
= 1;
2623 data
->explicit_inc_to
= -1;
2626 if (USE_STORE_POST_INCREMENT (mode
) && ! data
->reverse
2627 && ! data
->autinc_to
)
2629 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2630 data
->autinc_to
= 1;
2631 data
->explicit_inc_to
= 1;
2634 if ( !data
->autinc_to
&& CONSTANT_P (to_addr
))
2635 data
->to_addr
= copy_to_mode_reg (to_addr_mode
, to_addr
);
2638 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
2640 /* First store what we can in the largest integer mode, then go to
2641 successively smaller modes. */
2643 while (max_size
> 1 && data
->len
> 0)
2645 machine_mode mode
= widest_int_mode_for_size (max_size
);
2647 if (mode
== VOIDmode
)
2650 icode
= optab_handler (mov_optab
, mode
);
2651 if (icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
))
2652 store_by_pieces_2 (GEN_FCN (icode
), mode
, data
);
2654 max_size
= GET_MODE_SIZE (mode
);
2657 /* The code above should have handled everything. */
2658 gcc_assert (!data
->len
);
2661 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2662 with move instructions for mode MODE. GENFUN is the gen_... function
2663 to make a move insn for that mode. DATA has all the other info. */
2666 store_by_pieces_2 (insn_gen_fn genfun
, machine_mode mode
,
2667 struct store_by_pieces_d
*data
)
2669 unsigned int size
= GET_MODE_SIZE (mode
);
2672 while (data
->len
>= size
)
2675 data
->offset
-= size
;
2677 if (data
->autinc_to
)
2678 to1
= adjust_automodify_address (data
->to
, mode
, data
->to_addr
,
2681 to1
= adjust_address (data
->to
, mode
, data
->offset
);
2683 if (HAVE_PRE_DECREMENT
&& data
->explicit_inc_to
< 0)
2684 emit_insn (gen_add2_insn (data
->to_addr
,
2685 gen_int_mode (-(HOST_WIDE_INT
) size
,
2686 GET_MODE (data
->to_addr
))));
2688 cst
= (*data
->constfun
) (data
->constfundata
, data
->offset
, mode
);
2689 emit_insn ((*genfun
) (to1
, cst
));
2691 if (HAVE_POST_INCREMENT
&& data
->explicit_inc_to
> 0)
2692 emit_insn (gen_add2_insn (data
->to_addr
,
2694 GET_MODE (data
->to_addr
))));
2696 if (! data
->reverse
)
2697 data
->offset
+= size
;
2703 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2704 its length in bytes. */
2707 clear_storage_hints (rtx object
, rtx size
, enum block_op_methods method
,
2708 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
2709 unsigned HOST_WIDE_INT min_size
,
2710 unsigned HOST_WIDE_INT max_size
,
2711 unsigned HOST_WIDE_INT probable_max_size
)
2713 machine_mode mode
= GET_MODE (object
);
2716 gcc_assert (method
== BLOCK_OP_NORMAL
|| method
== BLOCK_OP_TAILCALL
);
2718 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2719 just move a zero. Otherwise, do this a piece at a time. */
2721 && CONST_INT_P (size
)
2722 && INTVAL (size
) == (HOST_WIDE_INT
) GET_MODE_SIZE (mode
))
2724 rtx zero
= CONST0_RTX (mode
);
2727 emit_move_insn (object
, zero
);
2731 if (COMPLEX_MODE_P (mode
))
2733 zero
= CONST0_RTX (GET_MODE_INNER (mode
));
2736 write_complex_part (object
, zero
, 0);
2737 write_complex_part (object
, zero
, 1);
2743 if (size
== const0_rtx
)
2746 align
= MEM_ALIGN (object
);
2748 if (CONST_INT_P (size
)
2749 && targetm
.use_by_pieces_infrastructure_p (INTVAL (size
), align
,
2751 optimize_insn_for_speed_p ()))
2752 clear_by_pieces (object
, INTVAL (size
), align
);
2753 else if (set_storage_via_setmem (object
, size
, const0_rtx
, align
,
2754 expected_align
, expected_size
,
2755 min_size
, max_size
, probable_max_size
))
2757 else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object
)))
2758 return set_storage_via_libcall (object
, size
, const0_rtx
,
2759 method
== BLOCK_OP_TAILCALL
);
2767 clear_storage (rtx object
, rtx size
, enum block_op_methods method
)
2769 unsigned HOST_WIDE_INT max
, min
= 0;
2770 if (GET_CODE (size
) == CONST_INT
)
2771 min
= max
= UINTVAL (size
);
2773 max
= GET_MODE_MASK (GET_MODE (size
));
2774 return clear_storage_hints (object
, size
, method
, 0, -1, min
, max
, max
);
2778 /* A subroutine of clear_storage. Expand a call to memset.
2779 Return the return value of memset, 0 otherwise. */
2782 set_storage_via_libcall (rtx object
, rtx size
, rtx val
, bool tailcall
)
2784 tree call_expr
, fn
, object_tree
, size_tree
, val_tree
;
2785 machine_mode size_mode
;
2788 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2789 place those into new pseudos into a VAR_DECL and use them later. */
2791 object
= copy_addr_to_reg (XEXP (object
, 0));
2793 size_mode
= TYPE_MODE (sizetype
);
2794 size
= convert_to_mode (size_mode
, size
, 1);
2795 size
= copy_to_mode_reg (size_mode
, size
);
2797 /* It is incorrect to use the libcall calling conventions to call
2798 memset in this context. This could be a user call to memset and
2799 the user may wish to examine the return value from memset. For
2800 targets where libcalls and normal calls have different conventions
2801 for returning pointers, we could end up generating incorrect code. */
2803 object_tree
= make_tree (ptr_type_node
, object
);
2804 if (!CONST_INT_P (val
))
2805 val
= convert_to_mode (TYPE_MODE (integer_type_node
), val
, 1);
2806 size_tree
= make_tree (sizetype
, size
);
2807 val_tree
= make_tree (integer_type_node
, val
);
2809 fn
= clear_storage_libcall_fn (true);
2810 call_expr
= build_call_expr (fn
, 3, object_tree
, val_tree
, size_tree
);
2811 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
2813 retval
= expand_normal (call_expr
);
2818 /* A subroutine of set_storage_via_libcall. Create the tree node
2819 for the function we use for block clears. */
2821 tree block_clear_fn
;
2824 init_block_clear_fn (const char *asmspec
)
2826 if (!block_clear_fn
)
2830 fn
= get_identifier ("memset");
2831 args
= build_function_type_list (ptr_type_node
, ptr_type_node
,
2832 integer_type_node
, sizetype
,
2835 fn
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, fn
, args
);
2836 DECL_EXTERNAL (fn
) = 1;
2837 TREE_PUBLIC (fn
) = 1;
2838 DECL_ARTIFICIAL (fn
) = 1;
2839 TREE_NOTHROW (fn
) = 1;
2840 DECL_VISIBILITY (fn
) = VISIBILITY_DEFAULT
;
2841 DECL_VISIBILITY_SPECIFIED (fn
) = 1;
2843 block_clear_fn
= fn
;
2847 set_user_assembler_name (block_clear_fn
, asmspec
);
2851 clear_storage_libcall_fn (int for_call
)
2853 static bool emitted_extern
;
2855 if (!block_clear_fn
)
2856 init_block_clear_fn (NULL
);
2858 if (for_call
&& !emitted_extern
)
2860 emitted_extern
= true;
2861 make_decl_rtl (block_clear_fn
);
2864 return block_clear_fn
;
2867 /* Expand a setmem pattern; return true if successful. */
2870 set_storage_via_setmem (rtx object
, rtx size
, rtx val
, unsigned int align
,
2871 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
2872 unsigned HOST_WIDE_INT min_size
,
2873 unsigned HOST_WIDE_INT max_size
,
2874 unsigned HOST_WIDE_INT probable_max_size
)
2876 /* Try the most limited insn first, because there's no point
2877 including more than one in the machine description unless
2878 the more limited one has some advantage. */
2882 if (expected_align
< align
)
2883 expected_align
= align
;
2884 if (expected_size
!= -1)
2886 if ((unsigned HOST_WIDE_INT
)expected_size
> max_size
)
2887 expected_size
= max_size
;
2888 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
2889 expected_size
= min_size
;
2892 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
); mode
!= VOIDmode
;
2893 mode
= GET_MODE_WIDER_MODE (mode
))
2895 enum insn_code code
= direct_optab_handler (setmem_optab
, mode
);
2897 if (code
!= CODE_FOR_nothing
2898 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
2899 here because if SIZE is less than the mode mask, as it is
2900 returned by the macro, it will definitely be less than the
2901 actual mode mask. Since SIZE is within the Pmode address
2902 space, we limit MODE to Pmode. */
2903 && ((CONST_INT_P (size
)
2904 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
2905 <= (GET_MODE_MASK (mode
) >> 1)))
2906 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
2907 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
2909 struct expand_operand ops
[9];
2912 nops
= insn_data
[(int) code
].n_generator_args
;
2913 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
2915 create_fixed_operand (&ops
[0], object
);
2916 /* The check above guarantees that this size conversion is valid. */
2917 create_convert_operand_to (&ops
[1], size
, mode
, true);
2918 create_convert_operand_from (&ops
[2], val
, byte_mode
, true);
2919 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
2922 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
2923 create_integer_operand (&ops
[5], expected_size
);
2927 create_integer_operand (&ops
[6], min_size
);
2928 /* If we can not represent the maximal size,
2929 make parameter NULL. */
2930 if ((HOST_WIDE_INT
) max_size
!= -1)
2931 create_integer_operand (&ops
[7], max_size
);
2933 create_fixed_operand (&ops
[7], NULL
);
2937 /* If we can not represent the maximal size,
2938 make parameter NULL. */
2939 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
2940 create_integer_operand (&ops
[8], probable_max_size
);
2942 create_fixed_operand (&ops
[8], NULL
);
2944 if (maybe_expand_insn (code
, nops
, ops
))
2953 /* Write to one of the components of the complex value CPLX. Write VAL to
2954 the real part if IMAG_P is false, and the imaginary part if its true. */
2957 write_complex_part (rtx cplx
, rtx val
, bool imag_p
)
2963 if (GET_CODE (cplx
) == CONCAT
)
2965 emit_move_insn (XEXP (cplx
, imag_p
), val
);
2969 cmode
= GET_MODE (cplx
);
2970 imode
= GET_MODE_INNER (cmode
);
2971 ibitsize
= GET_MODE_BITSIZE (imode
);
2973 /* For MEMs simplify_gen_subreg may generate an invalid new address
2974 because, e.g., the original address is considered mode-dependent
2975 by the target, which restricts simplify_subreg from invoking
2976 adjust_address_nv. Instead of preparing fallback support for an
2977 invalid address, we call adjust_address_nv directly. */
2980 emit_move_insn (adjust_address_nv (cplx
, imode
,
2981 imag_p
? GET_MODE_SIZE (imode
) : 0),
2986 /* If the sub-object is at least word sized, then we know that subregging
2987 will work. This special case is important, since store_bit_field
2988 wants to operate on integer modes, and there's rarely an OImode to
2989 correspond to TCmode. */
2990 if (ibitsize
>= BITS_PER_WORD
2991 /* For hard regs we have exact predicates. Assume we can split
2992 the original object if it spans an even number of hard regs.
2993 This special case is important for SCmode on 64-bit platforms
2994 where the natural size of floating-point regs is 32-bit. */
2996 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
2997 && REG_NREGS (cplx
) % 2 == 0))
2999 rtx part
= simplify_gen_subreg (imode
, cplx
, cmode
,
3000 imag_p
? GET_MODE_SIZE (imode
) : 0);
3003 emit_move_insn (part
, val
);
3007 /* simplify_gen_subreg may fail for sub-word MEMs. */
3008 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3011 store_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0, 0, 0, imode
, val
,
3015 /* Extract one of the components of the complex value CPLX. Extract the
3016 real part if IMAG_P is false, and the imaginary part if it's true. */
3019 read_complex_part (rtx cplx
, bool imag_p
)
3021 machine_mode cmode
, imode
;
3024 if (GET_CODE (cplx
) == CONCAT
)
3025 return XEXP (cplx
, imag_p
);
3027 cmode
= GET_MODE (cplx
);
3028 imode
= GET_MODE_INNER (cmode
);
3029 ibitsize
= GET_MODE_BITSIZE (imode
);
3031 /* Special case reads from complex constants that got spilled to memory. */
3032 if (MEM_P (cplx
) && GET_CODE (XEXP (cplx
, 0)) == SYMBOL_REF
)
3034 tree decl
= SYMBOL_REF_DECL (XEXP (cplx
, 0));
3035 if (decl
&& TREE_CODE (decl
) == COMPLEX_CST
)
3037 tree part
= imag_p
? TREE_IMAGPART (decl
) : TREE_REALPART (decl
);
3038 if (CONSTANT_CLASS_P (part
))
3039 return expand_expr (part
, NULL_RTX
, imode
, EXPAND_NORMAL
);
3043 /* For MEMs simplify_gen_subreg may generate an invalid new address
3044 because, e.g., the original address is considered mode-dependent
3045 by the target, which restricts simplify_subreg from invoking
3046 adjust_address_nv. Instead of preparing fallback support for an
3047 invalid address, we call adjust_address_nv directly. */
3049 return adjust_address_nv (cplx
, imode
,
3050 imag_p
? GET_MODE_SIZE (imode
) : 0);
3052 /* If the sub-object is at least word sized, then we know that subregging
3053 will work. This special case is important, since extract_bit_field
3054 wants to operate on integer modes, and there's rarely an OImode to
3055 correspond to TCmode. */
3056 if (ibitsize
>= BITS_PER_WORD
3057 /* For hard regs we have exact predicates. Assume we can split
3058 the original object if it spans an even number of hard regs.
3059 This special case is important for SCmode on 64-bit platforms
3060 where the natural size of floating-point regs is 32-bit. */
3062 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
3063 && REG_NREGS (cplx
) % 2 == 0))
3065 rtx ret
= simplify_gen_subreg (imode
, cplx
, cmode
,
3066 imag_p
? GET_MODE_SIZE (imode
) : 0);
3070 /* simplify_gen_subreg may fail for sub-word MEMs. */
3071 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
3074 return extract_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0,
3075 true, NULL_RTX
, imode
, imode
, false);
3078 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
3079 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
3080 represented in NEW_MODE. If FORCE is true, this will never happen, as
3081 we'll force-create a SUBREG if needed. */
3084 emit_move_change_mode (machine_mode new_mode
,
3085 machine_mode old_mode
, rtx x
, bool force
)
3089 if (push_operand (x
, GET_MODE (x
)))
3091 ret
= gen_rtx_MEM (new_mode
, XEXP (x
, 0));
3092 MEM_COPY_ATTRIBUTES (ret
, x
);
3096 /* We don't have to worry about changing the address since the
3097 size in bytes is supposed to be the same. */
3098 if (reload_in_progress
)
3100 /* Copy the MEM to change the mode and move any
3101 substitutions from the old MEM to the new one. */
3102 ret
= adjust_address_nv (x
, new_mode
, 0);
3103 copy_replacements (x
, ret
);
3106 ret
= adjust_address (x
, new_mode
, 0);
3110 /* Note that we do want simplify_subreg's behavior of validating
3111 that the new mode is ok for a hard register. If we were to use
3112 simplify_gen_subreg, we would create the subreg, but would
3113 probably run into the target not being able to implement it. */
3114 /* Except, of course, when FORCE is true, when this is exactly what
3115 we want. Which is needed for CCmodes on some targets. */
3117 ret
= simplify_gen_subreg (new_mode
, x
, old_mode
, 0);
3119 ret
= simplify_subreg (new_mode
, x
, old_mode
, 0);
3125 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
3126 an integer mode of the same size as MODE. Returns the instruction
3127 emitted, or NULL if such a move could not be generated. */
3130 emit_move_via_integer (machine_mode mode
, rtx x
, rtx y
, bool force
)
3133 enum insn_code code
;
3135 /* There must exist a mode of the exact size we require. */
3136 imode
= int_mode_for_mode (mode
);
3137 if (imode
== BLKmode
)
3140 /* The target must support moves in this mode. */
3141 code
= optab_handler (mov_optab
, imode
);
3142 if (code
== CODE_FOR_nothing
)
3145 x
= emit_move_change_mode (imode
, mode
, x
, force
);
3148 y
= emit_move_change_mode (imode
, mode
, y
, force
);
3151 return emit_insn (GEN_FCN (code
) (x
, y
));
3154 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
3155 Return an equivalent MEM that does not use an auto-increment. */
3158 emit_move_resolve_push (machine_mode mode
, rtx x
)
3160 enum rtx_code code
= GET_CODE (XEXP (x
, 0));
3161 HOST_WIDE_INT adjust
;
3164 adjust
= GET_MODE_SIZE (mode
);
3165 #ifdef PUSH_ROUNDING
3166 adjust
= PUSH_ROUNDING (adjust
);
3168 if (code
== PRE_DEC
|| code
== POST_DEC
)
3170 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
3172 rtx expr
= XEXP (XEXP (x
, 0), 1);
3175 gcc_assert (GET_CODE (expr
) == PLUS
|| GET_CODE (expr
) == MINUS
);
3176 gcc_assert (CONST_INT_P (XEXP (expr
, 1)));
3177 val
= INTVAL (XEXP (expr
, 1));
3178 if (GET_CODE (expr
) == MINUS
)
3180 gcc_assert (adjust
== val
|| adjust
== -val
);
3184 /* Do not use anti_adjust_stack, since we don't want to update
3185 stack_pointer_delta. */
3186 temp
= expand_simple_binop (Pmode
, PLUS
, stack_pointer_rtx
,
3187 gen_int_mode (adjust
, Pmode
), stack_pointer_rtx
,
3188 0, OPTAB_LIB_WIDEN
);
3189 if (temp
!= stack_pointer_rtx
)
3190 emit_move_insn (stack_pointer_rtx
, temp
);
3197 temp
= stack_pointer_rtx
;
3202 temp
= plus_constant (Pmode
, stack_pointer_rtx
, -adjust
);
3208 return replace_equiv_address (x
, temp
);
3211 /* A subroutine of emit_move_complex. Generate a move from Y into X.
3212 X is known to satisfy push_operand, and MODE is known to be complex.
3213 Returns the last instruction emitted. */
3216 emit_move_complex_push (machine_mode mode
, rtx x
, rtx y
)
3218 machine_mode submode
= GET_MODE_INNER (mode
);
3221 #ifdef PUSH_ROUNDING
3222 unsigned int submodesize
= GET_MODE_SIZE (submode
);
3224 /* In case we output to the stack, but the size is smaller than the
3225 machine can push exactly, we need to use move instructions. */
3226 if (PUSH_ROUNDING (submodesize
) != submodesize
)
3228 x
= emit_move_resolve_push (mode
, x
);
3229 return emit_move_insn (x
, y
);
3233 /* Note that the real part always precedes the imag part in memory
3234 regardless of machine's endianness. */
3235 switch (GET_CODE (XEXP (x
, 0)))
3249 emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3250 read_complex_part (y
, imag_first
));
3251 return emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
3252 read_complex_part (y
, !imag_first
));
3255 /* A subroutine of emit_move_complex. Perform the move from Y to X
3256 via two moves of the parts. Returns the last instruction emitted. */
3259 emit_move_complex_parts (rtx x
, rtx y
)
3261 /* Show the output dies here. This is necessary for SUBREGs
3262 of pseudos since we cannot track their lifetimes correctly;
3263 hard regs shouldn't appear here except as return values. */
3264 if (!reload_completed
&& !reload_in_progress
3265 && REG_P (x
) && !reg_overlap_mentioned_p (x
, y
))
3268 write_complex_part (x
, read_complex_part (y
, false), false);
3269 write_complex_part (x
, read_complex_part (y
, true), true);
3271 return get_last_insn ();
3274 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3275 MODE is known to be complex. Returns the last instruction emitted. */
3278 emit_move_complex (machine_mode mode
, rtx x
, rtx y
)
3282 /* Need to take special care for pushes, to maintain proper ordering
3283 of the data, and possibly extra padding. */
3284 if (push_operand (x
, mode
))
3285 return emit_move_complex_push (mode
, x
, y
);
3287 /* See if we can coerce the target into moving both values at once, except
3288 for floating point where we favor moving as parts if this is easy. */
3289 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
3290 && optab_handler (mov_optab
, GET_MODE_INNER (mode
)) != CODE_FOR_nothing
3292 && HARD_REGISTER_P (x
)
3293 && REG_NREGS (x
) == 1)
3295 && HARD_REGISTER_P (y
)
3296 && REG_NREGS (y
) == 1))
3298 /* Not possible if the values are inherently not adjacent. */
3299 else if (GET_CODE (x
) == CONCAT
|| GET_CODE (y
) == CONCAT
)
3301 /* Is possible if both are registers (or subregs of registers). */
3302 else if (register_operand (x
, mode
) && register_operand (y
, mode
))
3304 /* If one of the operands is a memory, and alignment constraints
3305 are friendly enough, we may be able to do combined memory operations.
3306 We do not attempt this if Y is a constant because that combination is
3307 usually better with the by-parts thing below. */
3308 else if ((MEM_P (x
) ? !CONSTANT_P (y
) : MEM_P (y
))
3309 && (!STRICT_ALIGNMENT
3310 || get_mode_alignment (mode
) == BIGGEST_ALIGNMENT
))
3319 /* For memory to memory moves, optimal behavior can be had with the
3320 existing block move logic. */
3321 if (MEM_P (x
) && MEM_P (y
))
3323 emit_block_move (x
, y
, GEN_INT (GET_MODE_SIZE (mode
)),
3324 BLOCK_OP_NO_LIBCALL
);
3325 return get_last_insn ();
3328 ret
= emit_move_via_integer (mode
, x
, y
, true);
3333 return emit_move_complex_parts (x
, y
);
3336 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3337 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3340 emit_move_ccmode (machine_mode mode
, rtx x
, rtx y
)
3344 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3347 enum insn_code code
= optab_handler (mov_optab
, CCmode
);
3348 if (code
!= CODE_FOR_nothing
)
3350 x
= emit_move_change_mode (CCmode
, mode
, x
, true);
3351 y
= emit_move_change_mode (CCmode
, mode
, y
, true);
3352 return emit_insn (GEN_FCN (code
) (x
, y
));
3356 /* Otherwise, find the MODE_INT mode of the same width. */
3357 ret
= emit_move_via_integer (mode
, x
, y
, false);
3358 gcc_assert (ret
!= NULL
);
3362 /* Return true if word I of OP lies entirely in the
3363 undefined bits of a paradoxical subreg. */
3366 undefined_operand_subword_p (const_rtx op
, int i
)
3368 machine_mode innermode
, innermostmode
;
3370 if (GET_CODE (op
) != SUBREG
)
3372 innermode
= GET_MODE (op
);
3373 innermostmode
= GET_MODE (SUBREG_REG (op
));
3374 offset
= i
* UNITS_PER_WORD
+ SUBREG_BYTE (op
);
3375 /* The SUBREG_BYTE represents offset, as if the value were stored in
3376 memory, except for a paradoxical subreg where we define
3377 SUBREG_BYTE to be 0; undo this exception as in
3379 if (SUBREG_BYTE (op
) == 0
3380 && GET_MODE_SIZE (innermostmode
) < GET_MODE_SIZE (innermode
))
3382 int difference
= (GET_MODE_SIZE (innermostmode
) - GET_MODE_SIZE (innermode
));
3383 if (WORDS_BIG_ENDIAN
)
3384 offset
+= (difference
/ UNITS_PER_WORD
) * UNITS_PER_WORD
;
3385 if (BYTES_BIG_ENDIAN
)
3386 offset
+= difference
% UNITS_PER_WORD
;
3388 if (offset
>= GET_MODE_SIZE (innermostmode
)
3389 || offset
<= -GET_MODE_SIZE (word_mode
))
3394 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3395 MODE is any multi-word or full-word mode that lacks a move_insn
3396 pattern. Note that you will get better code if you define such
3397 patterns, even if they must turn into multiple assembler instructions. */
3400 emit_move_multi_word (machine_mode mode
, rtx x
, rtx y
)
3402 rtx_insn
*last_insn
= 0;
3408 gcc_assert (GET_MODE_SIZE (mode
) >= UNITS_PER_WORD
);
3410 /* If X is a push on the stack, do the push now and replace
3411 X with a reference to the stack pointer. */
3412 if (push_operand (x
, mode
))
3413 x
= emit_move_resolve_push (mode
, x
);
3415 /* If we are in reload, see if either operand is a MEM whose address
3416 is scheduled for replacement. */
3417 if (reload_in_progress
&& MEM_P (x
)
3418 && (inner
= find_replacement (&XEXP (x
, 0))) != XEXP (x
, 0))
3419 x
= replace_equiv_address_nv (x
, inner
);
3420 if (reload_in_progress
&& MEM_P (y
)
3421 && (inner
= find_replacement (&XEXP (y
, 0))) != XEXP (y
, 0))
3422 y
= replace_equiv_address_nv (y
, inner
);
3426 need_clobber
= false;
3428 i
< (GET_MODE_SIZE (mode
) + (UNITS_PER_WORD
- 1)) / UNITS_PER_WORD
;
3431 rtx xpart
= operand_subword (x
, i
, 1, mode
);
3434 /* Do not generate code for a move if it would come entirely
3435 from the undefined bits of a paradoxical subreg. */
3436 if (undefined_operand_subword_p (y
, i
))
3439 ypart
= operand_subword (y
, i
, 1, mode
);
3441 /* If we can't get a part of Y, put Y into memory if it is a
3442 constant. Otherwise, force it into a register. Then we must
3443 be able to get a part of Y. */
3444 if (ypart
== 0 && CONSTANT_P (y
))
3446 y
= use_anchored_address (force_const_mem (mode
, y
));
3447 ypart
= operand_subword (y
, i
, 1, mode
);
3449 else if (ypart
== 0)
3450 ypart
= operand_subword_force (y
, i
, mode
);
3452 gcc_assert (xpart
&& ypart
);
3454 need_clobber
|= (GET_CODE (xpart
) == SUBREG
);
3456 last_insn
= emit_move_insn (xpart
, ypart
);
3462 /* Show the output dies here. This is necessary for SUBREGs
3463 of pseudos since we cannot track their lifetimes correctly;
3464 hard regs shouldn't appear here except as return values.
3465 We never want to emit such a clobber after reload. */
3467 && ! (reload_in_progress
|| reload_completed
)
3468 && need_clobber
!= 0)
3476 /* Low level part of emit_move_insn.
3477 Called just like emit_move_insn, but assumes X and Y
3478 are basically valid. */
3481 emit_move_insn_1 (rtx x
, rtx y
)
3483 machine_mode mode
= GET_MODE (x
);
3484 enum insn_code code
;
3486 gcc_assert ((unsigned int) mode
< (unsigned int) MAX_MACHINE_MODE
);
3488 code
= optab_handler (mov_optab
, mode
);
3489 if (code
!= CODE_FOR_nothing
)
3490 return emit_insn (GEN_FCN (code
) (x
, y
));
3492 /* Expand complex moves by moving real part and imag part. */
3493 if (COMPLEX_MODE_P (mode
))
3494 return emit_move_complex (mode
, x
, y
);
3496 if (GET_MODE_CLASS (mode
) == MODE_DECIMAL_FLOAT
3497 || ALL_FIXED_POINT_MODE_P (mode
))
3499 rtx_insn
*result
= emit_move_via_integer (mode
, x
, y
, true);
3501 /* If we can't find an integer mode, use multi words. */
3505 return emit_move_multi_word (mode
, x
, y
);
3508 if (GET_MODE_CLASS (mode
) == MODE_CC
)
3509 return emit_move_ccmode (mode
, x
, y
);
3511 /* Try using a move pattern for the corresponding integer mode. This is
3512 only safe when simplify_subreg can convert MODE constants into integer
3513 constants. At present, it can only do this reliably if the value
3514 fits within a HOST_WIDE_INT. */
3515 if (!CONSTANT_P (y
) || GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
3517 rtx_insn
*ret
= emit_move_via_integer (mode
, x
, y
, lra_in_progress
);
3521 if (! lra_in_progress
|| recog (PATTERN (ret
), ret
, 0) >= 0)
3526 return emit_move_multi_word (mode
, x
, y
);
3529 /* Generate code to copy Y into X.
3530 Both Y and X must have the same mode, except that
3531 Y can be a constant with VOIDmode.
3532 This mode cannot be BLKmode; use emit_block_move for that.
3534 Return the last instruction emitted. */
3537 emit_move_insn (rtx x
, rtx y
)
3539 machine_mode mode
= GET_MODE (x
);
3540 rtx y_cst
= NULL_RTX
;
3541 rtx_insn
*last_insn
;
3544 gcc_assert (mode
!= BLKmode
3545 && (GET_MODE (y
) == mode
|| GET_MODE (y
) == VOIDmode
));
3550 && SCALAR_FLOAT_MODE_P (GET_MODE (x
))
3551 && (last_insn
= compress_float_constant (x
, y
)))
3556 if (!targetm
.legitimate_constant_p (mode
, y
))
3558 y
= force_const_mem (mode
, y
);
3560 /* If the target's cannot_force_const_mem prevented the spill,
3561 assume that the target's move expanders will also take care
3562 of the non-legitimate constant. */
3566 y
= use_anchored_address (y
);
3570 /* If X or Y are memory references, verify that their addresses are valid
3573 && (! memory_address_addr_space_p (GET_MODE (x
), XEXP (x
, 0),
3575 && ! push_operand (x
, GET_MODE (x
))))
3576 x
= validize_mem (x
);
3579 && ! memory_address_addr_space_p (GET_MODE (y
), XEXP (y
, 0),
3580 MEM_ADDR_SPACE (y
)))
3581 y
= validize_mem (y
);
3583 gcc_assert (mode
!= BLKmode
);
3585 last_insn
= emit_move_insn_1 (x
, y
);
3587 if (y_cst
&& REG_P (x
)
3588 && (set
= single_set (last_insn
)) != NULL_RTX
3589 && SET_DEST (set
) == x
3590 && ! rtx_equal_p (y_cst
, SET_SRC (set
)))
3591 set_unique_reg_note (last_insn
, REG_EQUAL
, copy_rtx (y_cst
));
3596 /* Generate the body of an instruction to copy Y into X.
3597 It may be a list of insns, if one insn isn't enough. */
3600 gen_move_insn (rtx x
, rtx y
)
3605 emit_move_insn_1 (x
, y
);
3611 /* If Y is representable exactly in a narrower mode, and the target can
3612 perform the extension directly from constant or memory, then emit the
3613 move as an extension. */
3616 compress_float_constant (rtx x
, rtx y
)
3618 machine_mode dstmode
= GET_MODE (x
);
3619 machine_mode orig_srcmode
= GET_MODE (y
);
3620 machine_mode srcmode
;
3621 const REAL_VALUE_TYPE
*r
;
3622 int oldcost
, newcost
;
3623 bool speed
= optimize_insn_for_speed_p ();
3625 r
= CONST_DOUBLE_REAL_VALUE (y
);
3627 if (targetm
.legitimate_constant_p (dstmode
, y
))
3628 oldcost
= set_src_cost (y
, orig_srcmode
, speed
);
3630 oldcost
= set_src_cost (force_const_mem (dstmode
, y
), dstmode
, speed
);
3632 for (srcmode
= GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode
));
3633 srcmode
!= orig_srcmode
;
3634 srcmode
= GET_MODE_WIDER_MODE (srcmode
))
3638 rtx_insn
*last_insn
;
3640 /* Skip if the target can't extend this way. */
3641 ic
= can_extend_p (dstmode
, srcmode
, 0);
3642 if (ic
== CODE_FOR_nothing
)
3645 /* Skip if the narrowed value isn't exact. */
3646 if (! exact_real_truncate (srcmode
, r
))
3649 trunc_y
= const_double_from_real_value (*r
, srcmode
);
3651 if (targetm
.legitimate_constant_p (srcmode
, trunc_y
))
3653 /* Skip if the target needs extra instructions to perform
3655 if (!insn_operand_matches (ic
, 1, trunc_y
))
3657 /* This is valid, but may not be cheaper than the original. */
3658 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3660 if (oldcost
< newcost
)
3663 else if (float_extend_from_mem
[dstmode
][srcmode
])
3665 trunc_y
= force_const_mem (srcmode
, trunc_y
);
3666 /* This is valid, but may not be cheaper than the original. */
3667 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
3669 if (oldcost
< newcost
)
3671 trunc_y
= validize_mem (trunc_y
);
3676 /* For CSE's benefit, force the compressed constant pool entry
3677 into a new pseudo. This constant may be used in different modes,
3678 and if not, combine will put things back together for us. */
3679 trunc_y
= force_reg (srcmode
, trunc_y
);
3681 /* If x is a hard register, perform the extension into a pseudo,
3682 so that e.g. stack realignment code is aware of it. */
3684 if (REG_P (x
) && HARD_REGISTER_P (x
))
3685 target
= gen_reg_rtx (dstmode
);
3687 emit_unop_insn (ic
, target
, trunc_y
, UNKNOWN
);
3688 last_insn
= get_last_insn ();
3691 set_unique_reg_note (last_insn
, REG_EQUAL
, y
);
3694 return emit_move_insn (x
, target
);
3701 /* Pushing data onto the stack. */
3703 /* Push a block of length SIZE (perhaps variable)
3704 and return an rtx to address the beginning of the block.
3705 The value may be virtual_outgoing_args_rtx.
3707 EXTRA is the number of bytes of padding to push in addition to SIZE.
3708 BELOW nonzero means this padding comes at low addresses;
3709 otherwise, the padding comes at high addresses. */
3712 push_block (rtx size
, int extra
, int below
)
3716 size
= convert_modes (Pmode
, ptr_mode
, size
, 1);
3717 if (CONSTANT_P (size
))
3718 anti_adjust_stack (plus_constant (Pmode
, size
, extra
));
3719 else if (REG_P (size
) && extra
== 0)
3720 anti_adjust_stack (size
);
3723 temp
= copy_to_mode_reg (Pmode
, size
);
3725 temp
= expand_binop (Pmode
, add_optab
, temp
,
3726 gen_int_mode (extra
, Pmode
),
3727 temp
, 0, OPTAB_LIB_WIDEN
);
3728 anti_adjust_stack (temp
);
3731 if (STACK_GROWS_DOWNWARD
)
3733 temp
= virtual_outgoing_args_rtx
;
3734 if (extra
!= 0 && below
)
3735 temp
= plus_constant (Pmode
, temp
, extra
);
3739 if (CONST_INT_P (size
))
3740 temp
= plus_constant (Pmode
, virtual_outgoing_args_rtx
,
3741 -INTVAL (size
) - (below
? 0 : extra
));
3742 else if (extra
!= 0 && !below
)
3743 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3744 negate_rtx (Pmode
, plus_constant (Pmode
, size
,
3747 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
3748 negate_rtx (Pmode
, size
));
3751 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT
), temp
);
3754 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
3757 mem_autoinc_base (rtx mem
)
3761 rtx addr
= XEXP (mem
, 0);
3762 if (GET_RTX_CLASS (GET_CODE (addr
)) == RTX_AUTOINC
)
3763 return XEXP (addr
, 0);
3768 /* A utility routine used here, in reload, and in try_split. The insns
3769 after PREV up to and including LAST are known to adjust the stack,
3770 with a final value of END_ARGS_SIZE. Iterate backward from LAST
3771 placing notes as appropriate. PREV may be NULL, indicating the
3772 entire insn sequence prior to LAST should be scanned.
3774 The set of allowed stack pointer modifications is small:
3775 (1) One or more auto-inc style memory references (aka pushes),
3776 (2) One or more addition/subtraction with the SP as destination,
3777 (3) A single move insn with the SP as destination,
3778 (4) A call_pop insn,
3779 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
3781 Insns in the sequence that do not modify the SP are ignored,
3782 except for noreturn calls.
3784 The return value is the amount of adjustment that can be trivially
3785 verified, via immediate operand or auto-inc. If the adjustment
3786 cannot be trivially extracted, the return value is INT_MIN. */
3789 find_args_size_adjust (rtx_insn
*insn
)
3794 pat
= PATTERN (insn
);
3797 /* Look for a call_pop pattern. */
3800 /* We have to allow non-call_pop patterns for the case
3801 of emit_single_push_insn of a TLS address. */
3802 if (GET_CODE (pat
) != PARALLEL
)
3805 /* All call_pop have a stack pointer adjust in the parallel.
3806 The call itself is always first, and the stack adjust is
3807 usually last, so search from the end. */
3808 for (i
= XVECLEN (pat
, 0) - 1; i
> 0; --i
)
3810 set
= XVECEXP (pat
, 0, i
);
3811 if (GET_CODE (set
) != SET
)
3813 dest
= SET_DEST (set
);
3814 if (dest
== stack_pointer_rtx
)
3817 /* We'd better have found the stack pointer adjust. */
3820 /* Fall through to process the extracted SET and DEST
3821 as if it was a standalone insn. */
3823 else if (GET_CODE (pat
) == SET
)
3825 else if ((set
= single_set (insn
)) != NULL
)
3827 else if (GET_CODE (pat
) == PARALLEL
)
3829 /* ??? Some older ports use a parallel with a stack adjust
3830 and a store for a PUSH_ROUNDING pattern, rather than a
3831 PRE/POST_MODIFY rtx. Don't force them to update yet... */
3832 /* ??? See h8300 and m68k, pushqi1. */
3833 for (i
= XVECLEN (pat
, 0) - 1; i
>= 0; --i
)
3835 set
= XVECEXP (pat
, 0, i
);
3836 if (GET_CODE (set
) != SET
)
3838 dest
= SET_DEST (set
);
3839 if (dest
== stack_pointer_rtx
)
3842 /* We do not expect an auto-inc of the sp in the parallel. */
3843 gcc_checking_assert (mem_autoinc_base (dest
) != stack_pointer_rtx
);
3844 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3845 != stack_pointer_rtx
);
3853 dest
= SET_DEST (set
);
3855 /* Look for direct modifications of the stack pointer. */
3856 if (REG_P (dest
) && REGNO (dest
) == STACK_POINTER_REGNUM
)
3858 /* Look for a trivial adjustment, otherwise assume nothing. */
3859 /* Note that the SPU restore_stack_block pattern refers to
3860 the stack pointer in V4SImode. Consider that non-trivial. */
3861 if (SCALAR_INT_MODE_P (GET_MODE (dest
))
3862 && GET_CODE (SET_SRC (set
)) == PLUS
3863 && XEXP (SET_SRC (set
), 0) == stack_pointer_rtx
3864 && CONST_INT_P (XEXP (SET_SRC (set
), 1)))
3865 return INTVAL (XEXP (SET_SRC (set
), 1));
3866 /* ??? Reload can generate no-op moves, which will be cleaned
3867 up later. Recognize it and continue searching. */
3868 else if (rtx_equal_p (dest
, SET_SRC (set
)))
3871 return HOST_WIDE_INT_MIN
;
3877 /* Otherwise only think about autoinc patterns. */
3878 if (mem_autoinc_base (dest
) == stack_pointer_rtx
)
3881 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
3882 != stack_pointer_rtx
);
3884 else if (mem_autoinc_base (SET_SRC (set
)) == stack_pointer_rtx
)
3885 mem
= SET_SRC (set
);
3889 addr
= XEXP (mem
, 0);
3890 switch (GET_CODE (addr
))
3894 return GET_MODE_SIZE (GET_MODE (mem
));
3897 return -GET_MODE_SIZE (GET_MODE (mem
));
3900 addr
= XEXP (addr
, 1);
3901 gcc_assert (GET_CODE (addr
) == PLUS
);
3902 gcc_assert (XEXP (addr
, 0) == stack_pointer_rtx
);
3903 gcc_assert (CONST_INT_P (XEXP (addr
, 1)));
3904 return INTVAL (XEXP (addr
, 1));
3912 fixup_args_size_notes (rtx_insn
*prev
, rtx_insn
*last
, int end_args_size
)
3914 int args_size
= end_args_size
;
3915 bool saw_unknown
= false;
3918 for (insn
= last
; insn
!= prev
; insn
= PREV_INSN (insn
))
3920 HOST_WIDE_INT this_delta
;
3922 if (!NONDEBUG_INSN_P (insn
))
3925 this_delta
= find_args_size_adjust (insn
);
3926 if (this_delta
== 0)
3929 || ACCUMULATE_OUTGOING_ARGS
3930 || find_reg_note (insn
, REG_NORETURN
, NULL_RTX
) == NULL_RTX
)
3934 gcc_assert (!saw_unknown
);
3935 if (this_delta
== HOST_WIDE_INT_MIN
)
3938 add_reg_note (insn
, REG_ARGS_SIZE
, GEN_INT (args_size
));
3939 if (STACK_GROWS_DOWNWARD
)
3940 this_delta
= -(unsigned HOST_WIDE_INT
) this_delta
;
3942 args_size
-= this_delta
;
3945 return saw_unknown
? INT_MIN
: args_size
;
3948 #ifdef PUSH_ROUNDING
3949 /* Emit single push insn. */
3952 emit_single_push_insn_1 (machine_mode mode
, rtx x
, tree type
)
3955 unsigned rounded_size
= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3957 enum insn_code icode
;
3959 stack_pointer_delta
+= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
3960 /* If there is push pattern, use it. Otherwise try old way of throwing
3961 MEM representing push operation to move expander. */
3962 icode
= optab_handler (push_optab
, mode
);
3963 if (icode
!= CODE_FOR_nothing
)
3965 struct expand_operand ops
[1];
3967 create_input_operand (&ops
[0], x
, mode
);
3968 if (maybe_expand_insn (icode
, 1, ops
))
3971 if (GET_MODE_SIZE (mode
) == rounded_size
)
3972 dest_addr
= gen_rtx_fmt_e (STACK_PUSH_CODE
, Pmode
, stack_pointer_rtx
);
3973 /* If we are to pad downward, adjust the stack pointer first and
3974 then store X into the stack location using an offset. This is
3975 because emit_move_insn does not know how to pad; it does not have
3977 else if (FUNCTION_ARG_PADDING (mode
, type
) == downward
)
3979 unsigned padding_size
= rounded_size
- GET_MODE_SIZE (mode
);
3980 HOST_WIDE_INT offset
;
3982 emit_move_insn (stack_pointer_rtx
,
3983 expand_binop (Pmode
,
3984 STACK_GROWS_DOWNWARD
? sub_optab
3987 gen_int_mode (rounded_size
, Pmode
),
3988 NULL_RTX
, 0, OPTAB_LIB_WIDEN
));
3990 offset
= (HOST_WIDE_INT
) padding_size
;
3991 if (STACK_GROWS_DOWNWARD
&& STACK_PUSH_CODE
== POST_DEC
)
3992 /* We have already decremented the stack pointer, so get the
3994 offset
+= (HOST_WIDE_INT
) rounded_size
;
3996 if (!STACK_GROWS_DOWNWARD
&& STACK_PUSH_CODE
== POST_INC
)
3997 /* We have already incremented the stack pointer, so get the
3999 offset
-= (HOST_WIDE_INT
) rounded_size
;
4001 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4002 gen_int_mode (offset
, Pmode
));
4006 if (STACK_GROWS_DOWNWARD
)
4007 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
4008 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4009 gen_int_mode (-(HOST_WIDE_INT
) rounded_size
,
4012 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
4013 dest_addr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
,
4014 gen_int_mode (rounded_size
, Pmode
));
4016 dest_addr
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
, dest_addr
);
4019 dest
= gen_rtx_MEM (mode
, dest_addr
);
4023 set_mem_attributes (dest
, type
, 1);
4025 if (cfun
->tail_call_marked
)
4026 /* Function incoming arguments may overlap with sibling call
4027 outgoing arguments and we cannot allow reordering of reads
4028 from function arguments with stores to outgoing arguments
4029 of sibling calls. */
4030 set_mem_alias_set (dest
, 0);
4032 emit_move_insn (dest
, x
);
4035 /* Emit and annotate a single push insn. */
4038 emit_single_push_insn (machine_mode mode
, rtx x
, tree type
)
4040 int delta
, old_delta
= stack_pointer_delta
;
4041 rtx_insn
*prev
= get_last_insn ();
4044 emit_single_push_insn_1 (mode
, x
, type
);
4046 last
= get_last_insn ();
4048 /* Notice the common case where we emitted exactly one insn. */
4049 if (PREV_INSN (last
) == prev
)
4051 add_reg_note (last
, REG_ARGS_SIZE
, GEN_INT (stack_pointer_delta
));
4055 delta
= fixup_args_size_notes (prev
, last
, stack_pointer_delta
);
4056 gcc_assert (delta
== INT_MIN
|| delta
== old_delta
);
4060 /* If reading SIZE bytes from X will end up reading from
4061 Y return the number of bytes that overlap. Return -1
4062 if there is no overlap or -2 if we can't determine
4063 (for example when X and Y have different base registers). */
4066 memory_load_overlap (rtx x
, rtx y
, HOST_WIDE_INT size
)
4068 rtx tmp
= plus_constant (Pmode
, x
, size
);
4069 rtx sub
= simplify_gen_binary (MINUS
, Pmode
, tmp
, y
);
4071 if (!CONST_INT_P (sub
))
4074 HOST_WIDE_INT val
= INTVAL (sub
);
4076 return IN_RANGE (val
, 1, size
) ? val
: -1;
4079 /* Generate code to push X onto the stack, assuming it has mode MODE and
4081 MODE is redundant except when X is a CONST_INT (since they don't
4083 SIZE is an rtx for the size of data to be copied (in bytes),
4084 needed only if X is BLKmode.
4085 Return true if successful. May return false if asked to push a
4086 partial argument during a sibcall optimization (as specified by
4087 SIBCALL_P) and the incoming and outgoing pointers cannot be shown
4090 ALIGN (in bits) is maximum alignment we can assume.
4092 If PARTIAL and REG are both nonzero, then copy that many of the first
4093 bytes of X into registers starting with REG, and push the rest of X.
4094 The amount of space pushed is decreased by PARTIAL bytes.
4095 REG must be a hard register in this case.
4096 If REG is zero but PARTIAL is not, take any all others actions for an
4097 argument partially in registers, but do not actually load any
4100 EXTRA is the amount in bytes of extra space to leave next to this arg.
4101 This is ignored if an argument block has already been allocated.
4103 On a machine that lacks real push insns, ARGS_ADDR is the address of
4104 the bottom of the argument block for this call. We use indexing off there
4105 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
4106 argument block has not been preallocated.
4108 ARGS_SO_FAR is the size of args previously pushed for this call.
4110 REG_PARM_STACK_SPACE is nonzero if functions require stack space
4111 for arguments passed in registers. If nonzero, it will be the number
4112 of bytes required. */
4115 emit_push_insn (rtx x
, machine_mode mode
, tree type
, rtx size
,
4116 unsigned int align
, int partial
, rtx reg
, int extra
,
4117 rtx args_addr
, rtx args_so_far
, int reg_parm_stack_space
,
4118 rtx alignment_pad
, bool sibcall_p
)
4121 enum direction stack_direction
= STACK_GROWS_DOWNWARD
? downward
: upward
;
4123 /* Decide where to pad the argument: `downward' for below,
4124 `upward' for above, or `none' for don't pad it.
4125 Default is below for small data on big-endian machines; else above. */
4126 enum direction where_pad
= FUNCTION_ARG_PADDING (mode
, type
);
4128 /* Invert direction if stack is post-decrement.
4130 if (STACK_PUSH_CODE
== POST_DEC
)
4131 if (where_pad
!= none
)
4132 where_pad
= (where_pad
== downward
? upward
: downward
);
4136 int nregs
= partial
/ UNITS_PER_WORD
;
4137 rtx
*tmp_regs
= NULL
;
4138 int overlapping
= 0;
4141 || (STRICT_ALIGNMENT
&& align
< GET_MODE_ALIGNMENT (mode
)))
4143 /* Copy a block into the stack, entirely or partially. */
4150 offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4151 used
= partial
- offset
;
4153 if (mode
!= BLKmode
)
4155 /* A value is to be stored in an insufficiently aligned
4156 stack slot; copy via a suitably aligned slot if
4158 size
= GEN_INT (GET_MODE_SIZE (mode
));
4159 if (!MEM_P (xinner
))
4161 temp
= assign_temp (type
, 1, 1);
4162 emit_move_insn (temp
, xinner
);
4169 /* USED is now the # of bytes we need not copy to the stack
4170 because registers will take care of them. */
4173 xinner
= adjust_address (xinner
, BLKmode
, used
);
4175 /* If the partial register-part of the arg counts in its stack size,
4176 skip the part of stack space corresponding to the registers.
4177 Otherwise, start copying to the beginning of the stack space,
4178 by setting SKIP to 0. */
4179 skip
= (reg_parm_stack_space
== 0) ? 0 : used
;
4181 #ifdef PUSH_ROUNDING
4182 /* Do it with several push insns if that doesn't take lots of insns
4183 and if there is no difficulty with push insns that skip bytes
4184 on the stack for alignment purposes. */
4187 && CONST_INT_P (size
)
4189 && MEM_ALIGN (xinner
) >= align
4190 && can_move_by_pieces ((unsigned) INTVAL (size
) - used
, align
)
4191 /* Here we avoid the case of a structure whose weak alignment
4192 forces many pushes of a small amount of data,
4193 and such small pushes do rounding that causes trouble. */
4194 && ((! SLOW_UNALIGNED_ACCESS (word_mode
, align
))
4195 || align
>= BIGGEST_ALIGNMENT
4196 || (PUSH_ROUNDING (align
/ BITS_PER_UNIT
)
4197 == (align
/ BITS_PER_UNIT
)))
4198 && (HOST_WIDE_INT
) PUSH_ROUNDING (INTVAL (size
)) == INTVAL (size
))
4200 /* Push padding now if padding above and stack grows down,
4201 or if padding below and stack grows up.
4202 But if space already allocated, this has already been done. */
4203 if (extra
&& args_addr
== 0
4204 && where_pad
!= none
&& where_pad
!= stack_direction
)
4205 anti_adjust_stack (GEN_INT (extra
));
4207 move_by_pieces (NULL
, xinner
, INTVAL (size
) - used
, align
, 0);
4210 #endif /* PUSH_ROUNDING */
4214 /* Otherwise make space on the stack and copy the data
4215 to the address of that space. */
4217 /* Deduct words put into registers from the size we must copy. */
4220 if (CONST_INT_P (size
))
4221 size
= GEN_INT (INTVAL (size
) - used
);
4223 size
= expand_binop (GET_MODE (size
), sub_optab
, size
,
4224 gen_int_mode (used
, GET_MODE (size
)),
4225 NULL_RTX
, 0, OPTAB_LIB_WIDEN
);
4228 /* Get the address of the stack space.
4229 In this case, we do not deal with EXTRA separately.
4230 A single stack adjust will do. */
4233 temp
= push_block (size
, extra
, where_pad
== downward
);
4236 else if (CONST_INT_P (args_so_far
))
4237 temp
= memory_address (BLKmode
,
4238 plus_constant (Pmode
, args_addr
,
4239 skip
+ INTVAL (args_so_far
)));
4241 temp
= memory_address (BLKmode
,
4242 plus_constant (Pmode
,
4243 gen_rtx_PLUS (Pmode
,
4248 if (!ACCUMULATE_OUTGOING_ARGS
)
4250 /* If the source is referenced relative to the stack pointer,
4251 copy it to another register to stabilize it. We do not need
4252 to do this if we know that we won't be changing sp. */
4254 if (reg_mentioned_p (virtual_stack_dynamic_rtx
, temp
)
4255 || reg_mentioned_p (virtual_outgoing_args_rtx
, temp
))
4256 temp
= copy_to_reg (temp
);
4259 target
= gen_rtx_MEM (BLKmode
, temp
);
4261 /* We do *not* set_mem_attributes here, because incoming arguments
4262 may overlap with sibling call outgoing arguments and we cannot
4263 allow reordering of reads from function arguments with stores
4264 to outgoing arguments of sibling calls. We do, however, want
4265 to record the alignment of the stack slot. */
4266 /* ALIGN may well be better aligned than TYPE, e.g. due to
4267 PARM_BOUNDARY. Assume the caller isn't lying. */
4268 set_mem_align (target
, align
);
4270 /* If part should go in registers and pushing to that part would
4271 overwrite some of the values that need to go into regs, load the
4272 overlapping values into temporary pseudos to be moved into the hard
4273 regs at the end after the stack pushing has completed.
4274 We cannot load them directly into the hard regs here because
4275 they can be clobbered by the block move expansions.
4278 if (partial
> 0 && reg
!= 0 && mode
== BLKmode
4279 && GET_CODE (reg
) != PARALLEL
)
4281 overlapping
= memory_load_overlap (XEXP (x
, 0), temp
, partial
);
4282 if (overlapping
> 0)
4284 gcc_assert (overlapping
% UNITS_PER_WORD
== 0);
4285 overlapping
/= UNITS_PER_WORD
;
4287 tmp_regs
= XALLOCAVEC (rtx
, overlapping
);
4289 for (int i
= 0; i
< overlapping
; i
++)
4290 tmp_regs
[i
] = gen_reg_rtx (word_mode
);
4292 for (int i
= 0; i
< overlapping
; i
++)
4293 emit_move_insn (tmp_regs
[i
],
4294 operand_subword_force (target
, i
, mode
));
4296 else if (overlapping
== -1)
4298 /* Could not determine whether there is overlap.
4299 Fail the sibcall. */
4307 emit_block_move (target
, xinner
, size
, BLOCK_OP_CALL_PARM
);
4310 else if (partial
> 0)
4312 /* Scalar partly in registers. */
4314 int size
= GET_MODE_SIZE (mode
) / UNITS_PER_WORD
;
4317 /* # bytes of start of argument
4318 that we must make space for but need not store. */
4319 int offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
4320 int args_offset
= INTVAL (args_so_far
);
4323 /* Push padding now if padding above and stack grows down,
4324 or if padding below and stack grows up.
4325 But if space already allocated, this has already been done. */
4326 if (extra
&& args_addr
== 0
4327 && where_pad
!= none
&& where_pad
!= stack_direction
)
4328 anti_adjust_stack (GEN_INT (extra
));
4330 /* If we make space by pushing it, we might as well push
4331 the real data. Otherwise, we can leave OFFSET nonzero
4332 and leave the space uninitialized. */
4336 /* Now NOT_STACK gets the number of words that we don't need to
4337 allocate on the stack. Convert OFFSET to words too. */
4338 not_stack
= (partial
- offset
) / UNITS_PER_WORD
;
4339 offset
/= UNITS_PER_WORD
;
4341 /* If the partial register-part of the arg counts in its stack size,
4342 skip the part of stack space corresponding to the registers.
4343 Otherwise, start copying to the beginning of the stack space,
4344 by setting SKIP to 0. */
4345 skip
= (reg_parm_stack_space
== 0) ? 0 : not_stack
;
4347 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
4348 x
= validize_mem (force_const_mem (mode
, x
));
4350 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
4351 SUBREGs of such registers are not allowed. */
4352 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
4353 && GET_MODE_CLASS (GET_MODE (x
)) != MODE_INT
))
4354 x
= copy_to_reg (x
);
4356 /* Loop over all the words allocated on the stack for this arg. */
4357 /* We can do it by words, because any scalar bigger than a word
4358 has a size a multiple of a word. */
4359 for (i
= size
- 1; i
>= not_stack
; i
--)
4360 if (i
>= not_stack
+ offset
)
4361 if (!emit_push_insn (operand_subword_force (x
, i
, mode
),
4362 word_mode
, NULL_TREE
, NULL_RTX
, align
, 0, NULL_RTX
,
4364 GEN_INT (args_offset
+ ((i
- not_stack
+ skip
)
4366 reg_parm_stack_space
, alignment_pad
, sibcall_p
))
4374 /* Push padding now if padding above and stack grows down,
4375 or if padding below and stack grows up.
4376 But if space already allocated, this has already been done. */
4377 if (extra
&& args_addr
== 0
4378 && where_pad
!= none
&& where_pad
!= stack_direction
)
4379 anti_adjust_stack (GEN_INT (extra
));
4381 #ifdef PUSH_ROUNDING
4382 if (args_addr
== 0 && PUSH_ARGS
)
4383 emit_single_push_insn (mode
, x
, type
);
4387 if (CONST_INT_P (args_so_far
))
4389 = memory_address (mode
,
4390 plus_constant (Pmode
, args_addr
,
4391 INTVAL (args_so_far
)));
4393 addr
= memory_address (mode
, gen_rtx_PLUS (Pmode
, args_addr
,
4395 dest
= gen_rtx_MEM (mode
, addr
);
4397 /* We do *not* set_mem_attributes here, because incoming arguments
4398 may overlap with sibling call outgoing arguments and we cannot
4399 allow reordering of reads from function arguments with stores
4400 to outgoing arguments of sibling calls. We do, however, want
4401 to record the alignment of the stack slot. */
4402 /* ALIGN may well be better aligned than TYPE, e.g. due to
4403 PARM_BOUNDARY. Assume the caller isn't lying. */
4404 set_mem_align (dest
, align
);
4406 emit_move_insn (dest
, x
);
4410 /* Move the partial arguments into the registers and any overlapping
4411 values that we moved into the pseudos in tmp_regs. */
4412 if (partial
> 0 && reg
!= 0)
4414 /* Handle calls that pass values in multiple non-contiguous locations.
4415 The Irix 6 ABI has examples of this. */
4416 if (GET_CODE (reg
) == PARALLEL
)
4417 emit_group_load (reg
, x
, type
, -1);
4420 gcc_assert (partial
% UNITS_PER_WORD
== 0);
4421 move_block_to_reg (REGNO (reg
), x
, nregs
- overlapping
, mode
);
4423 for (int i
= 0; i
< overlapping
; i
++)
4424 emit_move_insn (gen_rtx_REG (word_mode
, REGNO (reg
)
4425 + nregs
- overlapping
+ i
),
4431 if (extra
&& args_addr
== 0 && where_pad
== stack_direction
)
4432 anti_adjust_stack (GEN_INT (extra
));
4434 if (alignment_pad
&& args_addr
== 0)
4435 anti_adjust_stack (alignment_pad
);
4440 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4444 get_subtarget (rtx x
)
4448 /* Only registers can be subtargets. */
4450 /* Don't use hard regs to avoid extending their life. */
4451 || REGNO (x
) < FIRST_PSEUDO_REGISTER
4455 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
4456 FIELD is a bitfield. Returns true if the optimization was successful,
4457 and there's nothing else to do. */
4460 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize
,
4461 unsigned HOST_WIDE_INT bitpos
,
4462 unsigned HOST_WIDE_INT bitregion_start
,
4463 unsigned HOST_WIDE_INT bitregion_end
,
4464 machine_mode mode1
, rtx str_rtx
,
4465 tree to
, tree src
, bool reverse
)
4467 machine_mode str_mode
= GET_MODE (str_rtx
);
4468 unsigned int str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4473 enum tree_code code
;
4475 if (mode1
!= VOIDmode
4476 || bitsize
>= BITS_PER_WORD
4477 || str_bitsize
> BITS_PER_WORD
4478 || TREE_SIDE_EFFECTS (to
)
4479 || TREE_THIS_VOLATILE (to
))
4483 if (TREE_CODE (src
) != SSA_NAME
)
4485 if (TREE_CODE (TREE_TYPE (src
)) != INTEGER_TYPE
)
4488 srcstmt
= get_gimple_for_ssa_name (src
);
4490 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt
)) != tcc_binary
)
4493 code
= gimple_assign_rhs_code (srcstmt
);
4495 op0
= gimple_assign_rhs1 (srcstmt
);
4497 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
4498 to find its initialization. Hopefully the initialization will
4499 be from a bitfield load. */
4500 if (TREE_CODE (op0
) == SSA_NAME
)
4502 gimple
*op0stmt
= get_gimple_for_ssa_name (op0
);
4504 /* We want to eventually have OP0 be the same as TO, which
4505 should be a bitfield. */
4507 || !is_gimple_assign (op0stmt
)
4508 || gimple_assign_rhs_code (op0stmt
) != TREE_CODE (to
))
4510 op0
= gimple_assign_rhs1 (op0stmt
);
4513 op1
= gimple_assign_rhs2 (srcstmt
);
4515 if (!operand_equal_p (to
, op0
, 0))
4518 if (MEM_P (str_rtx
))
4520 unsigned HOST_WIDE_INT offset1
;
4522 if (str_bitsize
== 0 || str_bitsize
> BITS_PER_WORD
)
4523 str_mode
= word_mode
;
4524 str_mode
= get_best_mode (bitsize
, bitpos
,
4525 bitregion_start
, bitregion_end
,
4526 MEM_ALIGN (str_rtx
), str_mode
, 0);
4527 if (str_mode
== VOIDmode
)
4529 str_bitsize
= GET_MODE_BITSIZE (str_mode
);
4532 bitpos
%= str_bitsize
;
4533 offset1
= (offset1
- bitpos
) / BITS_PER_UNIT
;
4534 str_rtx
= adjust_address (str_rtx
, str_mode
, offset1
);
4536 else if (!REG_P (str_rtx
) && GET_CODE (str_rtx
) != SUBREG
)
4539 gcc_assert (!reverse
);
4541 /* If the bit field covers the whole REG/MEM, store_field
4542 will likely generate better code. */
4543 if (bitsize
>= str_bitsize
)
4546 /* We can't handle fields split across multiple entities. */
4547 if (bitpos
+ bitsize
> str_bitsize
)
4550 if (reverse
? !BYTES_BIG_ENDIAN
: BYTES_BIG_ENDIAN
)
4551 bitpos
= str_bitsize
- bitpos
- bitsize
;
4557 /* For now, just optimize the case of the topmost bitfield
4558 where we don't need to do any masking and also
4559 1 bit bitfields where xor can be used.
4560 We might win by one instruction for the other bitfields
4561 too if insv/extv instructions aren't used, so that
4562 can be added later. */
4563 if ((reverse
|| bitpos
+ bitsize
!= str_bitsize
)
4564 && (bitsize
!= 1 || TREE_CODE (op1
) != INTEGER_CST
))
4567 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4568 value
= convert_modes (str_mode
,
4569 TYPE_MODE (TREE_TYPE (op1
)), value
,
4570 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4572 /* We may be accessing data outside the field, which means
4573 we can alias adjacent data. */
4574 if (MEM_P (str_rtx
))
4576 str_rtx
= shallow_copy_rtx (str_rtx
);
4577 set_mem_alias_set (str_rtx
, 0);
4578 set_mem_expr (str_rtx
, 0);
4581 if (bitsize
== 1 && (reverse
|| bitpos
+ bitsize
!= str_bitsize
))
4583 value
= expand_and (str_mode
, value
, const1_rtx
, NULL
);
4587 binop
= code
== PLUS_EXPR
? add_optab
: sub_optab
;
4589 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4591 value
= flip_storage_order (str_mode
, value
);
4592 result
= expand_binop (str_mode
, binop
, str_rtx
,
4593 value
, str_rtx
, 1, OPTAB_WIDEN
);
4594 if (result
!= str_rtx
)
4595 emit_move_insn (str_rtx
, result
);
4600 if (TREE_CODE (op1
) != INTEGER_CST
)
4602 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
4603 value
= convert_modes (str_mode
,
4604 TYPE_MODE (TREE_TYPE (op1
)), value
,
4605 TYPE_UNSIGNED (TREE_TYPE (op1
)));
4607 /* We may be accessing data outside the field, which means
4608 we can alias adjacent data. */
4609 if (MEM_P (str_rtx
))
4611 str_rtx
= shallow_copy_rtx (str_rtx
);
4612 set_mem_alias_set (str_rtx
, 0);
4613 set_mem_expr (str_rtx
, 0);
4616 binop
= code
== BIT_IOR_EXPR
? ior_optab
: xor_optab
;
4617 if (bitpos
+ bitsize
!= str_bitsize
)
4619 rtx mask
= gen_int_mode (((unsigned HOST_WIDE_INT
) 1 << bitsize
) - 1,
4621 value
= expand_and (str_mode
, value
, mask
, NULL_RTX
);
4623 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
4625 value
= flip_storage_order (str_mode
, value
);
4626 result
= expand_binop (str_mode
, binop
, str_rtx
,
4627 value
, str_rtx
, 1, OPTAB_WIDEN
);
4628 if (result
!= str_rtx
)
4629 emit_move_insn (str_rtx
, result
);
4639 /* In the C++ memory model, consecutive bit fields in a structure are
4640 considered one memory location.
4642 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
4643 returns the bit range of consecutive bits in which this COMPONENT_REF
4644 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
4645 and *OFFSET may be adjusted in the process.
4647 If the access does not need to be restricted, 0 is returned in both
4648 *BITSTART and *BITEND. */
4651 get_bit_range (unsigned HOST_WIDE_INT
*bitstart
,
4652 unsigned HOST_WIDE_INT
*bitend
,
4654 HOST_WIDE_INT
*bitpos
,
4657 HOST_WIDE_INT bitoffset
;
4660 gcc_assert (TREE_CODE (exp
) == COMPONENT_REF
);
4662 field
= TREE_OPERAND (exp
, 1);
4663 repr
= DECL_BIT_FIELD_REPRESENTATIVE (field
);
4664 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
4665 need to limit the range we can access. */
4668 *bitstart
= *bitend
= 0;
4672 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
4673 part of a larger bit field, then the representative does not serve any
4674 useful purpose. This can occur in Ada. */
4675 if (handled_component_p (TREE_OPERAND (exp
, 0)))
4678 HOST_WIDE_INT rbitsize
, rbitpos
;
4680 int unsignedp
, reversep
, volatilep
= 0;
4681 get_inner_reference (TREE_OPERAND (exp
, 0), &rbitsize
, &rbitpos
,
4682 &roffset
, &rmode
, &unsignedp
, &reversep
,
4684 if ((rbitpos
% BITS_PER_UNIT
) != 0)
4686 *bitstart
= *bitend
= 0;
4691 /* Compute the adjustment to bitpos from the offset of the field
4692 relative to the representative. DECL_FIELD_OFFSET of field and
4693 repr are the same by construction if they are not constants,
4694 see finish_bitfield_layout. */
4695 if (tree_fits_uhwi_p (DECL_FIELD_OFFSET (field
))
4696 && tree_fits_uhwi_p (DECL_FIELD_OFFSET (repr
)))
4697 bitoffset
= (tree_to_uhwi (DECL_FIELD_OFFSET (field
))
4698 - tree_to_uhwi (DECL_FIELD_OFFSET (repr
))) * BITS_PER_UNIT
;
4701 bitoffset
+= (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field
))
4702 - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr
)));
4704 /* If the adjustment is larger than bitpos, we would have a negative bit
4705 position for the lower bound and this may wreak havoc later. Adjust
4706 offset and bitpos to make the lower bound non-negative in that case. */
4707 if (bitoffset
> *bitpos
)
4709 HOST_WIDE_INT adjust
= bitoffset
- *bitpos
;
4710 gcc_assert ((adjust
% BITS_PER_UNIT
) == 0);
4713 if (*offset
== NULL_TREE
)
4714 *offset
= size_int (-adjust
/ BITS_PER_UNIT
);
4717 = size_binop (MINUS_EXPR
, *offset
, size_int (adjust
/ BITS_PER_UNIT
));
4721 *bitstart
= *bitpos
- bitoffset
;
4723 *bitend
= *bitstart
+ tree_to_uhwi (DECL_SIZE (repr
)) - 1;
4726 /* Returns true if ADDR is an ADDR_EXPR of a DECL that does not reside
4727 in memory and has non-BLKmode. DECL_RTL must not be a MEM; if
4728 DECL_RTL was not set yet, return NORTL. */
4731 addr_expr_of_non_mem_decl_p_1 (tree addr
, bool nortl
)
4733 if (TREE_CODE (addr
) != ADDR_EXPR
)
4736 tree base
= TREE_OPERAND (addr
, 0);
4739 || TREE_ADDRESSABLE (base
)
4740 || DECL_MODE (base
) == BLKmode
)
4743 if (!DECL_RTL_SET_P (base
))
4746 return (!MEM_P (DECL_RTL (base
)));
4749 /* Returns true if the MEM_REF REF refers to an object that does not
4750 reside in memory and has non-BLKmode. */
4753 mem_ref_refers_to_non_mem_p (tree ref
)
4755 tree base
= TREE_OPERAND (ref
, 0);
4756 return addr_expr_of_non_mem_decl_p_1 (base
, false);
4759 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
4760 is true, try generating a nontemporal store. */
4763 expand_assignment (tree to
, tree from
, bool nontemporal
)
4769 enum insn_code icode
;
4771 /* Don't crash if the lhs of the assignment was erroneous. */
4772 if (TREE_CODE (to
) == ERROR_MARK
)
4774 expand_normal (from
);
4778 /* Optimize away no-op moves without side-effects. */
4779 if (operand_equal_p (to
, from
, 0))
4782 /* Handle misaligned stores. */
4783 mode
= TYPE_MODE (TREE_TYPE (to
));
4784 if ((TREE_CODE (to
) == MEM_REF
4785 || TREE_CODE (to
) == TARGET_MEM_REF
)
4787 && !mem_ref_refers_to_non_mem_p (to
)
4788 && ((align
= get_object_alignment (to
))
4789 < GET_MODE_ALIGNMENT (mode
))
4790 && (((icode
= optab_handler (movmisalign_optab
, mode
))
4791 != CODE_FOR_nothing
)
4792 || SLOW_UNALIGNED_ACCESS (mode
, align
)))
4796 reg
= expand_expr (from
, NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
4797 reg
= force_not_mem (reg
);
4798 mem
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4799 if (TREE_CODE (to
) == MEM_REF
&& REF_REVERSE_STORAGE_ORDER (to
))
4800 reg
= flip_storage_order (mode
, reg
);
4802 if (icode
!= CODE_FOR_nothing
)
4804 struct expand_operand ops
[2];
4806 create_fixed_operand (&ops
[0], mem
);
4807 create_input_operand (&ops
[1], reg
, mode
);
4808 /* The movmisalign<mode> pattern cannot fail, else the assignment
4809 would silently be omitted. */
4810 expand_insn (icode
, 2, ops
);
4813 store_bit_field (mem
, GET_MODE_BITSIZE (mode
), 0, 0, 0, mode
, reg
,
4818 /* Assignment of a structure component needs special treatment
4819 if the structure component's rtx is not simply a MEM.
4820 Assignment of an array element at a constant index, and assignment of
4821 an array element in an unaligned packed structure field, has the same
4822 problem. Same for (partially) storing into a non-memory object. */
4823 if (handled_component_p (to
)
4824 || (TREE_CODE (to
) == MEM_REF
4825 && (REF_REVERSE_STORAGE_ORDER (to
)
4826 || mem_ref_refers_to_non_mem_p (to
)))
4827 || TREE_CODE (TREE_TYPE (to
)) == ARRAY_TYPE
)
4830 HOST_WIDE_INT bitsize
, bitpos
;
4831 unsigned HOST_WIDE_INT bitregion_start
= 0;
4832 unsigned HOST_WIDE_INT bitregion_end
= 0;
4834 int unsignedp
, reversep
, volatilep
= 0;
4838 tem
= get_inner_reference (to
, &bitsize
, &bitpos
, &offset
, &mode1
,
4839 &unsignedp
, &reversep
, &volatilep
, true);
4841 /* Make sure bitpos is not negative, it can wreak havoc later. */
4844 gcc_assert (offset
== NULL_TREE
);
4845 offset
= size_int (bitpos
>> (BITS_PER_UNIT
== 8
4846 ? 3 : exact_log2 (BITS_PER_UNIT
)));
4847 bitpos
&= BITS_PER_UNIT
- 1;
4850 if (TREE_CODE (to
) == COMPONENT_REF
4851 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to
, 1)))
4852 get_bit_range (&bitregion_start
, &bitregion_end
, to
, &bitpos
, &offset
);
4853 /* The C++ memory model naturally applies to byte-aligned fields.
4854 However, if we do not have a DECL_BIT_FIELD_TYPE but BITPOS or
4855 BITSIZE are not byte-aligned, there is no need to limit the range
4856 we can access. This can occur with packed structures in Ada. */
4857 else if (bitsize
> 0
4858 && bitsize
% BITS_PER_UNIT
== 0
4859 && bitpos
% BITS_PER_UNIT
== 0)
4861 bitregion_start
= bitpos
;
4862 bitregion_end
= bitpos
+ bitsize
- 1;
4865 to_rtx
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4867 /* If the field has a mode, we want to access it in the
4868 field's mode, not the computed mode.
4869 If a MEM has VOIDmode (external with incomplete type),
4870 use BLKmode for it instead. */
4873 if (mode1
!= VOIDmode
)
4874 to_rtx
= adjust_address (to_rtx
, mode1
, 0);
4875 else if (GET_MODE (to_rtx
) == VOIDmode
)
4876 to_rtx
= adjust_address (to_rtx
, BLKmode
, 0);
4881 machine_mode address_mode
;
4884 if (!MEM_P (to_rtx
))
4886 /* We can get constant negative offsets into arrays with broken
4887 user code. Translate this to a trap instead of ICEing. */
4888 gcc_assert (TREE_CODE (offset
) == INTEGER_CST
);
4889 expand_builtin_trap ();
4890 to_rtx
= gen_rtx_MEM (BLKmode
, const0_rtx
);
4893 offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
4894 address_mode
= get_address_mode (to_rtx
);
4895 if (GET_MODE (offset_rtx
) != address_mode
)
4897 /* We cannot be sure that the RTL in offset_rtx is valid outside
4898 of a memory address context, so force it into a register
4899 before attempting to convert it to the desired mode. */
4900 offset_rtx
= force_operand (offset_rtx
, NULL_RTX
);
4901 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
4904 /* If we have an expression in OFFSET_RTX and a non-zero
4905 byte offset in BITPOS, adding the byte offset before the
4906 OFFSET_RTX results in better intermediate code, which makes
4907 later rtl optimization passes perform better.
4909 We prefer intermediate code like this:
4911 r124:DI=r123:DI+0x18
4916 r124:DI=r123:DI+0x10
4917 [r124:DI+0x8]=r121:DI
4919 This is only done for aligned data values, as these can
4920 be expected to result in single move instructions. */
4921 if (mode1
!= VOIDmode
4924 && (bitpos
% bitsize
) == 0
4925 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
4926 && MEM_ALIGN (to_rtx
) >= GET_MODE_ALIGNMENT (mode1
))
4928 to_rtx
= adjust_address (to_rtx
, mode1
, bitpos
/ BITS_PER_UNIT
);
4929 bitregion_start
= 0;
4930 if (bitregion_end
>= (unsigned HOST_WIDE_INT
) bitpos
)
4931 bitregion_end
-= bitpos
;
4935 to_rtx
= offset_address (to_rtx
, offset_rtx
,
4936 highest_pow2_factor_for_target (to
,
4940 /* No action is needed if the target is not a memory and the field
4941 lies completely outside that target. This can occur if the source
4942 code contains an out-of-bounds access to a small array. */
4944 && GET_MODE (to_rtx
) != BLKmode
4945 && (unsigned HOST_WIDE_INT
) bitpos
4946 >= GET_MODE_PRECISION (GET_MODE (to_rtx
)))
4948 expand_normal (from
);
4951 /* Handle expand_expr of a complex value returning a CONCAT. */
4952 else if (GET_CODE (to_rtx
) == CONCAT
)
4954 unsigned short mode_bitsize
= GET_MODE_BITSIZE (GET_MODE (to_rtx
));
4955 if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from
)))
4957 && bitsize
== mode_bitsize
)
4958 result
= store_expr (from
, to_rtx
, false, nontemporal
, reversep
);
4959 else if (bitsize
== mode_bitsize
/ 2
4960 && (bitpos
== 0 || bitpos
== mode_bitsize
/ 2))
4961 result
= store_expr (from
, XEXP (to_rtx
, bitpos
!= 0), false,
4962 nontemporal
, reversep
);
4963 else if (bitpos
+ bitsize
<= mode_bitsize
/ 2)
4964 result
= store_field (XEXP (to_rtx
, 0), bitsize
, bitpos
,
4965 bitregion_start
, bitregion_end
,
4966 mode1
, from
, get_alias_set (to
),
4967 nontemporal
, reversep
);
4968 else if (bitpos
>= mode_bitsize
/ 2)
4969 result
= store_field (XEXP (to_rtx
, 1), bitsize
,
4970 bitpos
- mode_bitsize
/ 2,
4971 bitregion_start
, bitregion_end
,
4972 mode1
, from
, get_alias_set (to
),
4973 nontemporal
, reversep
);
4974 else if (bitpos
== 0 && bitsize
== mode_bitsize
)
4977 result
= expand_normal (from
);
4978 from_rtx
= simplify_gen_subreg (GET_MODE (to_rtx
), result
,
4979 TYPE_MODE (TREE_TYPE (from
)), 0);
4980 emit_move_insn (XEXP (to_rtx
, 0),
4981 read_complex_part (from_rtx
, false));
4982 emit_move_insn (XEXP (to_rtx
, 1),
4983 read_complex_part (from_rtx
, true));
4987 rtx temp
= assign_stack_temp (GET_MODE (to_rtx
),
4988 GET_MODE_SIZE (GET_MODE (to_rtx
)));
4989 write_complex_part (temp
, XEXP (to_rtx
, 0), false);
4990 write_complex_part (temp
, XEXP (to_rtx
, 1), true);
4991 result
= store_field (temp
, bitsize
, bitpos
,
4992 bitregion_start
, bitregion_end
,
4993 mode1
, from
, get_alias_set (to
),
4994 nontemporal
, reversep
);
4995 emit_move_insn (XEXP (to_rtx
, 0), read_complex_part (temp
, false));
4996 emit_move_insn (XEXP (to_rtx
, 1), read_complex_part (temp
, true));
5003 /* If the field is at offset zero, we could have been given the
5004 DECL_RTX of the parent struct. Don't munge it. */
5005 to_rtx
= shallow_copy_rtx (to_rtx
);
5006 set_mem_attributes_minus_bitpos (to_rtx
, to
, 0, bitpos
);
5008 MEM_VOLATILE_P (to_rtx
) = 1;
5011 if (optimize_bitfield_assignment_op (bitsize
, bitpos
,
5012 bitregion_start
, bitregion_end
,
5013 mode1
, to_rtx
, to
, from
,
5017 result
= store_field (to_rtx
, bitsize
, bitpos
,
5018 bitregion_start
, bitregion_end
,
5019 mode1
, from
, get_alias_set (to
),
5020 nontemporal
, reversep
);
5024 preserve_temp_slots (result
);
5029 /* If the rhs is a function call and its value is not an aggregate,
5030 call the function before we start to compute the lhs.
5031 This is needed for correct code for cases such as
5032 val = setjmp (buf) on machines where reference to val
5033 requires loading up part of an address in a separate insn.
5035 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
5036 since it might be a promoted variable where the zero- or sign- extension
5037 needs to be done. Handling this in the normal way is safe because no
5038 computation is done before the call. The same is true for SSA names. */
5039 if (TREE_CODE (from
) == CALL_EXPR
&& ! aggregate_value_p (from
, from
)
5040 && COMPLETE_TYPE_P (TREE_TYPE (from
))
5041 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from
))) == INTEGER_CST
5042 && ! (((TREE_CODE (to
) == VAR_DECL
5043 || TREE_CODE (to
) == PARM_DECL
5044 || TREE_CODE (to
) == RESULT_DECL
)
5045 && REG_P (DECL_RTL (to
)))
5046 || TREE_CODE (to
) == SSA_NAME
))
5052 value
= expand_normal (from
);
5054 /* Split value and bounds to store them separately. */
5055 chkp_split_slot (value
, &value
, &bounds
);
5058 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5060 /* Handle calls that return values in multiple non-contiguous locations.
5061 The Irix 6 ABI has examples of this. */
5062 if (GET_CODE (to_rtx
) == PARALLEL
)
5064 if (GET_CODE (value
) == PARALLEL
)
5065 emit_group_move (to_rtx
, value
);
5067 emit_group_load (to_rtx
, value
, TREE_TYPE (from
),
5068 int_size_in_bytes (TREE_TYPE (from
)));
5070 else if (GET_CODE (value
) == PARALLEL
)
5071 emit_group_store (to_rtx
, value
, TREE_TYPE (from
),
5072 int_size_in_bytes (TREE_TYPE (from
)));
5073 else if (GET_MODE (to_rtx
) == BLKmode
)
5075 /* Handle calls that return BLKmode values in registers. */
5077 copy_blkmode_from_reg (to_rtx
, value
, TREE_TYPE (from
));
5079 emit_block_move (to_rtx
, value
, expr_size (from
), BLOCK_OP_NORMAL
);
5083 if (POINTER_TYPE_P (TREE_TYPE (to
)))
5084 value
= convert_memory_address_addr_space
5085 (GET_MODE (to_rtx
), value
,
5086 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to
))));
5088 emit_move_insn (to_rtx
, value
);
5091 /* Store bounds if required. */
5093 && (BOUNDED_P (to
) || chkp_type_has_pointer (TREE_TYPE (to
))))
5095 gcc_assert (MEM_P (to_rtx
));
5096 chkp_emit_bounds_store (bounds
, value
, to_rtx
);
5099 preserve_temp_slots (to_rtx
);
5104 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
5105 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5107 /* Don't move directly into a return register. */
5108 if (TREE_CODE (to
) == RESULT_DECL
5109 && (REG_P (to_rtx
) || GET_CODE (to_rtx
) == PARALLEL
))
5115 /* If the source is itself a return value, it still is in a pseudo at
5116 this point so we can move it back to the return register directly. */
5118 && TYPE_MODE (TREE_TYPE (from
)) == BLKmode
5119 && TREE_CODE (from
) != CALL_EXPR
)
5120 temp
= copy_blkmode_to_reg (GET_MODE (to_rtx
), from
);
5122 temp
= expand_expr (from
, NULL_RTX
, GET_MODE (to_rtx
), EXPAND_NORMAL
);
5124 /* Handle calls that return values in multiple non-contiguous locations.
5125 The Irix 6 ABI has examples of this. */
5126 if (GET_CODE (to_rtx
) == PARALLEL
)
5128 if (GET_CODE (temp
) == PARALLEL
)
5129 emit_group_move (to_rtx
, temp
);
5131 emit_group_load (to_rtx
, temp
, TREE_TYPE (from
),
5132 int_size_in_bytes (TREE_TYPE (from
)));
5135 emit_move_insn (to_rtx
, temp
);
5137 preserve_temp_slots (to_rtx
);
5142 /* In case we are returning the contents of an object which overlaps
5143 the place the value is being stored, use a safe function when copying
5144 a value through a pointer into a structure value return block. */
5145 if (TREE_CODE (to
) == RESULT_DECL
5146 && TREE_CODE (from
) == INDIRECT_REF
5147 && ADDR_SPACE_GENERIC_P
5148 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from
, 0)))))
5149 && refs_may_alias_p (to
, from
)
5150 && cfun
->returns_struct
5151 && !cfun
->returns_pcc_struct
)
5156 size
= expr_size (from
);
5157 from_rtx
= expand_normal (from
);
5159 emit_library_call (memmove_libfunc
, LCT_NORMAL
,
5160 VOIDmode
, 3, XEXP (to_rtx
, 0), Pmode
,
5161 XEXP (from_rtx
, 0), Pmode
,
5162 convert_to_mode (TYPE_MODE (sizetype
),
5163 size
, TYPE_UNSIGNED (sizetype
)),
5164 TYPE_MODE (sizetype
));
5166 preserve_temp_slots (to_rtx
);
5171 /* Compute FROM and store the value in the rtx we got. */
5174 result
= store_expr_with_bounds (from
, to_rtx
, 0, nontemporal
, false, to
);
5175 preserve_temp_slots (result
);
5180 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
5181 succeeded, false otherwise. */
5184 emit_storent_insn (rtx to
, rtx from
)
5186 struct expand_operand ops
[2];
5187 machine_mode mode
= GET_MODE (to
);
5188 enum insn_code code
= optab_handler (storent_optab
, mode
);
5190 if (code
== CODE_FOR_nothing
)
5193 create_fixed_operand (&ops
[0], to
);
5194 create_input_operand (&ops
[1], from
, mode
);
5195 return maybe_expand_insn (code
, 2, ops
);
5198 /* Generate code for computing expression EXP,
5199 and storing the value into TARGET.
5201 If the mode is BLKmode then we may return TARGET itself.
5202 It turns out that in BLKmode it doesn't cause a problem.
5203 because C has no operators that could combine two different
5204 assignments into the same BLKmode object with different values
5205 with no sequence point. Will other languages need this to
5208 If CALL_PARAM_P is nonzero, this is a store into a call param on the
5209 stack, and block moves may need to be treated specially.
5211 If NONTEMPORAL is true, try using a nontemporal store instruction.
5213 If REVERSE is true, the store is to be done in reverse order.
5215 If BTARGET is not NULL then computed bounds of EXP are
5216 associated with BTARGET. */
5219 store_expr_with_bounds (tree exp
, rtx target
, int call_param_p
,
5220 bool nontemporal
, bool reverse
, tree btarget
)
5223 rtx alt_rtl
= NULL_RTX
;
5224 location_t loc
= curr_insn_location ();
5226 if (VOID_TYPE_P (TREE_TYPE (exp
)))
5228 /* C++ can generate ?: expressions with a throw expression in one
5229 branch and an rvalue in the other. Here, we resolve attempts to
5230 store the throw expression's nonexistent result. */
5231 gcc_assert (!call_param_p
);
5232 expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5235 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
5237 /* Perform first part of compound expression, then assign from second
5239 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
,
5240 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5241 return store_expr_with_bounds (TREE_OPERAND (exp
, 1), target
,
5242 call_param_p
, nontemporal
, reverse
,
5245 else if (TREE_CODE (exp
) == COND_EXPR
&& GET_MODE (target
) == BLKmode
)
5247 /* For conditional expression, get safe form of the target. Then
5248 test the condition, doing the appropriate assignment on either
5249 side. This avoids the creation of unnecessary temporaries.
5250 For non-BLKmode, it is more efficient not to do this. */
5252 rtx_code_label
*lab1
= gen_label_rtx (), *lab2
= gen_label_rtx ();
5254 do_pending_stack_adjust ();
5256 jumpifnot (TREE_OPERAND (exp
, 0), lab1
, -1);
5257 store_expr_with_bounds (TREE_OPERAND (exp
, 1), target
, call_param_p
,
5258 nontemporal
, reverse
, btarget
);
5259 emit_jump_insn (targetm
.gen_jump (lab2
));
5262 store_expr_with_bounds (TREE_OPERAND (exp
, 2), target
, call_param_p
,
5263 nontemporal
, reverse
, btarget
);
5269 else if (GET_CODE (target
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (target
))
5270 /* If this is a scalar in a register that is stored in a wider mode
5271 than the declared mode, compute the result into its declared mode
5272 and then convert to the wider mode. Our value is the computed
5275 rtx inner_target
= 0;
5277 /* We can do the conversion inside EXP, which will often result
5278 in some optimizations. Do the conversion in two steps: first
5279 change the signedness, if needed, then the extend. But don't
5280 do this if the type of EXP is a subtype of something else
5281 since then the conversion might involve more than just
5282 converting modes. */
5283 if (INTEGRAL_TYPE_P (TREE_TYPE (exp
))
5284 && TREE_TYPE (TREE_TYPE (exp
)) == 0
5285 && GET_MODE_PRECISION (GET_MODE (target
))
5286 == TYPE_PRECISION (TREE_TYPE (exp
)))
5288 if (!SUBREG_CHECK_PROMOTED_SIGN (target
,
5289 TYPE_UNSIGNED (TREE_TYPE (exp
))))
5291 /* Some types, e.g. Fortran's logical*4, won't have a signed
5292 version, so use the mode instead. */
5294 = (signed_or_unsigned_type_for
5295 (SUBREG_PROMOTED_SIGN (target
), TREE_TYPE (exp
)));
5297 ntype
= lang_hooks
.types
.type_for_mode
5298 (TYPE_MODE (TREE_TYPE (exp
)),
5299 SUBREG_PROMOTED_SIGN (target
));
5301 exp
= fold_convert_loc (loc
, ntype
, exp
);
5304 exp
= fold_convert_loc (loc
, lang_hooks
.types
.type_for_mode
5305 (GET_MODE (SUBREG_REG (target
)),
5306 SUBREG_PROMOTED_SIGN (target
)),
5309 inner_target
= SUBREG_REG (target
);
5312 temp
= expand_expr (exp
, inner_target
, VOIDmode
,
5313 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
5315 /* Handle bounds returned by call. */
5316 if (TREE_CODE (exp
) == CALL_EXPR
)
5319 chkp_split_slot (temp
, &temp
, &bounds
);
5320 if (bounds
&& btarget
)
5322 gcc_assert (TREE_CODE (btarget
) == SSA_NAME
);
5323 rtx tmp
= targetm
.calls
.load_returned_bounds (bounds
);
5324 chkp_set_rtl_bounds (btarget
, tmp
);
5328 /* If TEMP is a VOIDmode constant, use convert_modes to make
5329 sure that we properly convert it. */
5330 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
)
5332 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5333 temp
, SUBREG_PROMOTED_SIGN (target
));
5334 temp
= convert_modes (GET_MODE (SUBREG_REG (target
)),
5335 GET_MODE (target
), temp
,
5336 SUBREG_PROMOTED_SIGN (target
));
5339 convert_move (SUBREG_REG (target
), temp
,
5340 SUBREG_PROMOTED_SIGN (target
));
5344 else if ((TREE_CODE (exp
) == STRING_CST
5345 || (TREE_CODE (exp
) == MEM_REF
5346 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
5347 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
5349 && integer_zerop (TREE_OPERAND (exp
, 1))))
5350 && !nontemporal
&& !call_param_p
5353 /* Optimize initialization of an array with a STRING_CST. */
5354 HOST_WIDE_INT exp_len
, str_copy_len
;
5356 tree str
= TREE_CODE (exp
) == STRING_CST
5357 ? exp
: TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
5359 exp_len
= int_expr_size (exp
);
5363 if (TREE_STRING_LENGTH (str
) <= 0)
5366 str_copy_len
= strlen (TREE_STRING_POINTER (str
));
5367 if (str_copy_len
< TREE_STRING_LENGTH (str
) - 1)
5370 str_copy_len
= TREE_STRING_LENGTH (str
);
5371 if ((STORE_MAX_PIECES
& (STORE_MAX_PIECES
- 1)) == 0
5372 && TREE_STRING_POINTER (str
)[TREE_STRING_LENGTH (str
) - 1] == '\0')
5374 str_copy_len
+= STORE_MAX_PIECES
- 1;
5375 str_copy_len
&= ~(STORE_MAX_PIECES
- 1);
5377 str_copy_len
= MIN (str_copy_len
, exp_len
);
5378 if (!can_store_by_pieces (str_copy_len
, builtin_strncpy_read_str
,
5379 CONST_CAST (char *, TREE_STRING_POINTER (str
)),
5380 MEM_ALIGN (target
), false))
5385 dest_mem
= store_by_pieces (dest_mem
,
5386 str_copy_len
, builtin_strncpy_read_str
,
5388 TREE_STRING_POINTER (str
)),
5389 MEM_ALIGN (target
), false,
5390 exp_len
> str_copy_len
? 1 : 0);
5391 if (exp_len
> str_copy_len
)
5392 clear_storage (adjust_address (dest_mem
, BLKmode
, 0),
5393 GEN_INT (exp_len
- str_copy_len
),
5402 /* If we want to use a nontemporal or a reverse order store, force the
5403 value into a register first. */
5404 tmp_target
= nontemporal
|| reverse
? NULL_RTX
: target
;
5405 temp
= expand_expr_real (exp
, tmp_target
, GET_MODE (target
),
5407 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
),
5410 /* Handle bounds returned by call. */
5411 if (TREE_CODE (exp
) == CALL_EXPR
)
5414 chkp_split_slot (temp
, &temp
, &bounds
);
5415 if (bounds
&& btarget
)
5417 gcc_assert (TREE_CODE (btarget
) == SSA_NAME
);
5418 rtx tmp
= targetm
.calls
.load_returned_bounds (bounds
);
5419 chkp_set_rtl_bounds (btarget
, tmp
);
5424 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
5425 the same as that of TARGET, adjust the constant. This is needed, for
5426 example, in case it is a CONST_DOUBLE or CONST_WIDE_INT and we want
5427 only a word-sized value. */
5428 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
5429 && TREE_CODE (exp
) != ERROR_MARK
5430 && GET_MODE (target
) != TYPE_MODE (TREE_TYPE (exp
)))
5431 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
5432 temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5434 /* If value was not generated in the target, store it there.
5435 Convert the value to TARGET's type first if necessary and emit the
5436 pending incrementations that have been queued when expanding EXP.
5437 Note that we cannot emit the whole queue blindly because this will
5438 effectively disable the POST_INC optimization later.
5440 If TEMP and TARGET compare equal according to rtx_equal_p, but
5441 one or both of them are volatile memory refs, we have to distinguish
5443 - expand_expr has used TARGET. In this case, we must not generate
5444 another copy. This can be detected by TARGET being equal according
5446 - expand_expr has not used TARGET - that means that the source just
5447 happens to have the same RTX form. Since temp will have been created
5448 by expand_expr, it will compare unequal according to == .
5449 We must generate a copy in this case, to reach the correct number
5450 of volatile memory references. */
5452 if ((! rtx_equal_p (temp
, target
)
5453 || (temp
!= target
&& (side_effects_p (temp
)
5454 || side_effects_p (target
))))
5455 && TREE_CODE (exp
) != ERROR_MARK
5456 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
5457 but TARGET is not valid memory reference, TEMP will differ
5458 from TARGET although it is really the same location. */
5460 && rtx_equal_p (alt_rtl
, target
)
5461 && !side_effects_p (alt_rtl
)
5462 && !side_effects_p (target
))
5463 /* If there's nothing to copy, don't bother. Don't call
5464 expr_size unless necessary, because some front-ends (C++)
5465 expr_size-hook must not be given objects that are not
5466 supposed to be bit-copied or bit-initialized. */
5467 && expr_size (exp
) != const0_rtx
)
5469 if (GET_MODE (temp
) != GET_MODE (target
) && GET_MODE (temp
) != VOIDmode
)
5471 if (GET_MODE (target
) == BLKmode
)
5473 /* Handle calls that return BLKmode values in registers. */
5474 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
5475 copy_blkmode_from_reg (target
, temp
, TREE_TYPE (exp
));
5477 store_bit_field (target
,
5478 INTVAL (expr_size (exp
)) * BITS_PER_UNIT
,
5479 0, 0, 0, GET_MODE (temp
), temp
, reverse
);
5482 convert_move (target
, temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
5485 else if (GET_MODE (temp
) == BLKmode
&& TREE_CODE (exp
) == STRING_CST
)
5487 /* Handle copying a string constant into an array. The string
5488 constant may be shorter than the array. So copy just the string's
5489 actual length, and clear the rest. First get the size of the data
5490 type of the string, which is actually the size of the target. */
5491 rtx size
= expr_size (exp
);
5493 if (CONST_INT_P (size
)
5494 && INTVAL (size
) < TREE_STRING_LENGTH (exp
))
5495 emit_block_move (target
, temp
, size
,
5497 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5500 machine_mode pointer_mode
5501 = targetm
.addr_space
.pointer_mode (MEM_ADDR_SPACE (target
));
5502 machine_mode address_mode
= get_address_mode (target
);
5504 /* Compute the size of the data to copy from the string. */
5506 = size_binop_loc (loc
, MIN_EXPR
,
5507 make_tree (sizetype
, size
),
5508 size_int (TREE_STRING_LENGTH (exp
)));
5510 = expand_expr (copy_size
, NULL_RTX
, VOIDmode
,
5512 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
));
5513 rtx_code_label
*label
= 0;
5515 /* Copy that much. */
5516 copy_size_rtx
= convert_to_mode (pointer_mode
, copy_size_rtx
,
5517 TYPE_UNSIGNED (sizetype
));
5518 emit_block_move (target
, temp
, copy_size_rtx
,
5520 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5522 /* Figure out how much is left in TARGET that we have to clear.
5523 Do all calculations in pointer_mode. */
5524 if (CONST_INT_P (copy_size_rtx
))
5526 size
= plus_constant (address_mode
, size
,
5527 -INTVAL (copy_size_rtx
));
5528 target
= adjust_address (target
, BLKmode
,
5529 INTVAL (copy_size_rtx
));
5533 size
= expand_binop (TYPE_MODE (sizetype
), sub_optab
, size
,
5534 copy_size_rtx
, NULL_RTX
, 0,
5537 if (GET_MODE (copy_size_rtx
) != address_mode
)
5538 copy_size_rtx
= convert_to_mode (address_mode
,
5540 TYPE_UNSIGNED (sizetype
));
5542 target
= offset_address (target
, copy_size_rtx
,
5543 highest_pow2_factor (copy_size
));
5544 label
= gen_label_rtx ();
5545 emit_cmp_and_jump_insns (size
, const0_rtx
, LT
, NULL_RTX
,
5546 GET_MODE (size
), 0, label
);
5549 if (size
!= const0_rtx
)
5550 clear_storage (target
, size
, BLOCK_OP_NORMAL
);
5556 /* Handle calls that return values in multiple non-contiguous locations.
5557 The Irix 6 ABI has examples of this. */
5558 else if (GET_CODE (target
) == PARALLEL
)
5560 if (GET_CODE (temp
) == PARALLEL
)
5561 emit_group_move (target
, temp
);
5563 emit_group_load (target
, temp
, TREE_TYPE (exp
),
5564 int_size_in_bytes (TREE_TYPE (exp
)));
5566 else if (GET_CODE (temp
) == PARALLEL
)
5567 emit_group_store (target
, temp
, TREE_TYPE (exp
),
5568 int_size_in_bytes (TREE_TYPE (exp
)));
5569 else if (GET_MODE (temp
) == BLKmode
)
5570 emit_block_move (target
, temp
, expr_size (exp
),
5572 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
5573 /* If we emit a nontemporal store, there is nothing else to do. */
5574 else if (nontemporal
&& emit_storent_insn (target
, temp
))
5579 temp
= flip_storage_order (GET_MODE (target
), temp
);
5580 temp
= force_operand (temp
, target
);
5582 emit_move_insn (target
, temp
);
5589 /* Same as store_expr_with_bounds but ignoring bounds of EXP. */
5591 store_expr (tree exp
, rtx target
, int call_param_p
, bool nontemporal
,
5594 return store_expr_with_bounds (exp
, target
, call_param_p
, nontemporal
,
5598 /* Return true if field F of structure TYPE is a flexible array. */
5601 flexible_array_member_p (const_tree f
, const_tree type
)
5606 return (DECL_CHAIN (f
) == NULL
5607 && TREE_CODE (tf
) == ARRAY_TYPE
5609 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf
))
5610 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf
)))
5611 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf
))
5612 && int_size_in_bytes (type
) >= 0);
5615 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
5616 must have in order for it to completely initialize a value of type TYPE.
5617 Return -1 if the number isn't known.
5619 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
5621 static HOST_WIDE_INT
5622 count_type_elements (const_tree type
, bool for_ctor_p
)
5624 switch (TREE_CODE (type
))
5630 nelts
= array_type_nelts (type
);
5631 if (nelts
&& tree_fits_uhwi_p (nelts
))
5633 unsigned HOST_WIDE_INT n
;
5635 n
= tree_to_uhwi (nelts
) + 1;
5636 if (n
== 0 || for_ctor_p
)
5639 return n
* count_type_elements (TREE_TYPE (type
), false);
5641 return for_ctor_p
? -1 : 1;
5646 unsigned HOST_WIDE_INT n
;
5650 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5651 if (TREE_CODE (f
) == FIELD_DECL
)
5654 n
+= count_type_elements (TREE_TYPE (f
), false);
5655 else if (!flexible_array_member_p (f
, type
))
5656 /* Don't count flexible arrays, which are not supposed
5657 to be initialized. */
5665 case QUAL_UNION_TYPE
:
5670 gcc_assert (!for_ctor_p
);
5671 /* Estimate the number of scalars in each field and pick the
5672 maximum. Other estimates would do instead; the idea is simply
5673 to make sure that the estimate is not sensitive to the ordering
5676 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
5677 if (TREE_CODE (f
) == FIELD_DECL
)
5679 m
= count_type_elements (TREE_TYPE (f
), false);
5680 /* If the field doesn't span the whole union, add an extra
5681 scalar for the rest. */
5682 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f
)),
5683 TYPE_SIZE (type
)) != 1)
5695 return TYPE_VECTOR_SUBPARTS (type
);
5699 case FIXED_POINT_TYPE
:
5704 case REFERENCE_TYPE
:
5720 /* Helper for categorize_ctor_elements. Identical interface. */
5723 categorize_ctor_elements_1 (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5724 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5726 unsigned HOST_WIDE_INT idx
;
5727 HOST_WIDE_INT nz_elts
, init_elts
, num_fields
;
5728 tree value
, purpose
, elt_type
;
5730 /* Whether CTOR is a valid constant initializer, in accordance with what
5731 initializer_constant_valid_p does. If inferred from the constructor
5732 elements, true until proven otherwise. */
5733 bool const_from_elts_p
= constructor_static_from_elts_p (ctor
);
5734 bool const_p
= const_from_elts_p
? true : TREE_STATIC (ctor
);
5739 elt_type
= NULL_TREE
;
5741 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), idx
, purpose
, value
)
5743 HOST_WIDE_INT mult
= 1;
5745 if (purpose
&& TREE_CODE (purpose
) == RANGE_EXPR
)
5747 tree lo_index
= TREE_OPERAND (purpose
, 0);
5748 tree hi_index
= TREE_OPERAND (purpose
, 1);
5750 if (tree_fits_uhwi_p (lo_index
) && tree_fits_uhwi_p (hi_index
))
5751 mult
= (tree_to_uhwi (hi_index
)
5752 - tree_to_uhwi (lo_index
) + 1);
5755 elt_type
= TREE_TYPE (value
);
5757 switch (TREE_CODE (value
))
5761 HOST_WIDE_INT nz
= 0, ic
= 0;
5763 bool const_elt_p
= categorize_ctor_elements_1 (value
, &nz
, &ic
,
5766 nz_elts
+= mult
* nz
;
5767 init_elts
+= mult
* ic
;
5769 if (const_from_elts_p
&& const_p
)
5770 const_p
= const_elt_p
;
5777 if (!initializer_zerop (value
))
5783 nz_elts
+= mult
* TREE_STRING_LENGTH (value
);
5784 init_elts
+= mult
* TREE_STRING_LENGTH (value
);
5788 if (!initializer_zerop (TREE_REALPART (value
)))
5790 if (!initializer_zerop (TREE_IMAGPART (value
)))
5798 for (i
= 0; i
< VECTOR_CST_NELTS (value
); ++i
)
5800 tree v
= VECTOR_CST_ELT (value
, i
);
5801 if (!initializer_zerop (v
))
5810 HOST_WIDE_INT tc
= count_type_elements (elt_type
, false);
5811 nz_elts
+= mult
* tc
;
5812 init_elts
+= mult
* tc
;
5814 if (const_from_elts_p
&& const_p
)
5816 = initializer_constant_valid_p (value
,
5818 TYPE_REVERSE_STORAGE_ORDER
5826 if (*p_complete
&& !complete_ctor_at_level_p (TREE_TYPE (ctor
),
5827 num_fields
, elt_type
))
5828 *p_complete
= false;
5830 *p_nz_elts
+= nz_elts
;
5831 *p_init_elts
+= init_elts
;
5836 /* Examine CTOR to discover:
5837 * how many scalar fields are set to nonzero values,
5838 and place it in *P_NZ_ELTS;
5839 * how many scalar fields in total are in CTOR,
5840 and place it in *P_ELT_COUNT.
5841 * whether the constructor is complete -- in the sense that every
5842 meaningful byte is explicitly given a value --
5843 and place it in *P_COMPLETE.
5845 Return whether or not CTOR is a valid static constant initializer, the same
5846 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
5849 categorize_ctor_elements (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
5850 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
5856 return categorize_ctor_elements_1 (ctor
, p_nz_elts
, p_init_elts
, p_complete
);
5859 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
5860 of which had type LAST_TYPE. Each element was itself a complete
5861 initializer, in the sense that every meaningful byte was explicitly
5862 given a value. Return true if the same is true for the constructor
5866 complete_ctor_at_level_p (const_tree type
, HOST_WIDE_INT num_elts
,
5867 const_tree last_type
)
5869 if (TREE_CODE (type
) == UNION_TYPE
5870 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
5875 gcc_assert (num_elts
== 1 && last_type
);
5877 /* ??? We could look at each element of the union, and find the
5878 largest element. Which would avoid comparing the size of the
5879 initialized element against any tail padding in the union.
5880 Doesn't seem worth the effort... */
5881 return simple_cst_equal (TYPE_SIZE (type
), TYPE_SIZE (last_type
)) == 1;
5884 return count_type_elements (type
, true) == num_elts
;
5887 /* Return 1 if EXP contains mostly (3/4) zeros. */
5890 mostly_zeros_p (const_tree exp
)
5892 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5894 HOST_WIDE_INT nz_elts
, init_elts
;
5897 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5898 return !complete_p
|| nz_elts
< init_elts
/ 4;
5901 return initializer_zerop (exp
);
5904 /* Return 1 if EXP contains all zeros. */
5907 all_zeros_p (const_tree exp
)
5909 if (TREE_CODE (exp
) == CONSTRUCTOR
)
5911 HOST_WIDE_INT nz_elts
, init_elts
;
5914 categorize_ctor_elements (exp
, &nz_elts
, &init_elts
, &complete_p
);
5915 return nz_elts
== 0;
5918 return initializer_zerop (exp
);
5921 /* Helper function for store_constructor.
5922 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
5923 CLEARED is as for store_constructor.
5924 ALIAS_SET is the alias set to use for any stores.
5925 If REVERSE is true, the store is to be done in reverse order.
5927 This provides a recursive shortcut back to store_constructor when it isn't
5928 necessary to go through store_field. This is so that we can pass through
5929 the cleared field to let store_constructor know that we may not have to
5930 clear a substructure if the outer structure has already been cleared. */
5933 store_constructor_field (rtx target
, unsigned HOST_WIDE_INT bitsize
,
5934 HOST_WIDE_INT bitpos
, machine_mode mode
,
5935 tree exp
, int cleared
,
5936 alias_set_type alias_set
, bool reverse
)
5938 if (TREE_CODE (exp
) == CONSTRUCTOR
5939 /* We can only call store_constructor recursively if the size and
5940 bit position are on a byte boundary. */
5941 && bitpos
% BITS_PER_UNIT
== 0
5942 && (bitsize
> 0 && bitsize
% BITS_PER_UNIT
== 0)
5943 /* If we have a nonzero bitpos for a register target, then we just
5944 let store_field do the bitfield handling. This is unlikely to
5945 generate unnecessary clear instructions anyways. */
5946 && (bitpos
== 0 || MEM_P (target
)))
5950 = adjust_address (target
,
5951 GET_MODE (target
) == BLKmode
5953 % GET_MODE_ALIGNMENT (GET_MODE (target
)))
5954 ? BLKmode
: VOIDmode
, bitpos
/ BITS_PER_UNIT
);
5957 /* Update the alias set, if required. */
5958 if (MEM_P (target
) && ! MEM_KEEP_ALIAS_SET_P (target
)
5959 && MEM_ALIAS_SET (target
) != 0)
5961 target
= copy_rtx (target
);
5962 set_mem_alias_set (target
, alias_set
);
5965 store_constructor (exp
, target
, cleared
, bitsize
/ BITS_PER_UNIT
,
5969 store_field (target
, bitsize
, bitpos
, 0, 0, mode
, exp
, alias_set
, false,
5974 /* Returns the number of FIELD_DECLs in TYPE. */
5977 fields_length (const_tree type
)
5979 tree t
= TYPE_FIELDS (type
);
5982 for (; t
; t
= DECL_CHAIN (t
))
5983 if (TREE_CODE (t
) == FIELD_DECL
)
5990 /* Store the value of constructor EXP into the rtx TARGET.
5991 TARGET is either a REG or a MEM; we know it cannot conflict, since
5992 safe_from_p has been called.
5993 CLEARED is true if TARGET is known to have been zero'd.
5994 SIZE is the number of bytes of TARGET we are allowed to modify: this
5995 may not be the same as the size of EXP if we are assigning to a field
5996 which has been packed to exclude padding bits.
5997 If REVERSE is true, the store is to be done in reverse order. */
6000 store_constructor (tree exp
, rtx target
, int cleared
, HOST_WIDE_INT size
,
6003 tree type
= TREE_TYPE (exp
);
6004 HOST_WIDE_INT exp_size
= int_size_in_bytes (type
);
6006 switch (TREE_CODE (type
))
6010 case QUAL_UNION_TYPE
:
6012 unsigned HOST_WIDE_INT idx
;
6015 /* The storage order is specified for every aggregate type. */
6016 reverse
= TYPE_REVERSE_STORAGE_ORDER (type
);
6018 /* If size is zero or the target is already cleared, do nothing. */
6019 if (size
== 0 || cleared
)
6021 /* We either clear the aggregate or indicate the value is dead. */
6022 else if ((TREE_CODE (type
) == UNION_TYPE
6023 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
6024 && ! CONSTRUCTOR_ELTS (exp
))
6025 /* If the constructor is empty, clear the union. */
6027 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
6031 /* If we are building a static constructor into a register,
6032 set the initial value as zero so we can fold the value into
6033 a constant. But if more than one register is involved,
6034 this probably loses. */
6035 else if (REG_P (target
) && TREE_STATIC (exp
)
6036 && GET_MODE_SIZE (GET_MODE (target
)) <= UNITS_PER_WORD
)
6038 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6042 /* If the constructor has fewer fields than the structure or
6043 if we are initializing the structure to mostly zeros, clear
6044 the whole structure first. Don't do this if TARGET is a
6045 register whose mode size isn't equal to SIZE since
6046 clear_storage can't handle this case. */
6048 && (((int)vec_safe_length (CONSTRUCTOR_ELTS (exp
))
6049 != fields_length (type
))
6050 || mostly_zeros_p (exp
))
6052 || ((HOST_WIDE_INT
) GET_MODE_SIZE (GET_MODE (target
))
6055 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6059 if (REG_P (target
) && !cleared
)
6060 emit_clobber (target
);
6062 /* Store each element of the constructor into the
6063 corresponding field of TARGET. */
6064 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, field
, value
)
6067 HOST_WIDE_INT bitsize
;
6068 HOST_WIDE_INT bitpos
= 0;
6070 rtx to_rtx
= target
;
6072 /* Just ignore missing fields. We cleared the whole
6073 structure, above, if any fields are missing. */
6077 if (cleared
&& initializer_zerop (value
))
6080 if (tree_fits_uhwi_p (DECL_SIZE (field
)))
6081 bitsize
= tree_to_uhwi (DECL_SIZE (field
));
6085 mode
= DECL_MODE (field
);
6086 if (DECL_BIT_FIELD (field
))
6089 offset
= DECL_FIELD_OFFSET (field
);
6090 if (tree_fits_shwi_p (offset
)
6091 && tree_fits_shwi_p (bit_position (field
)))
6093 bitpos
= int_bit_position (field
);
6097 bitpos
= tree_to_shwi (DECL_FIELD_BIT_OFFSET (field
));
6101 machine_mode address_mode
;
6105 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset
,
6106 make_tree (TREE_TYPE (exp
),
6109 offset_rtx
= expand_normal (offset
);
6110 gcc_assert (MEM_P (to_rtx
));
6112 address_mode
= get_address_mode (to_rtx
);
6113 if (GET_MODE (offset_rtx
) != address_mode
)
6114 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
6116 to_rtx
= offset_address (to_rtx
, offset_rtx
,
6117 highest_pow2_factor (offset
));
6120 /* If this initializes a field that is smaller than a
6121 word, at the start of a word, try to widen it to a full
6122 word. This special case allows us to output C++ member
6123 function initializations in a form that the optimizers
6125 if (WORD_REGISTER_OPERATIONS
6127 && bitsize
< BITS_PER_WORD
6128 && bitpos
% BITS_PER_WORD
== 0
6129 && GET_MODE_CLASS (mode
) == MODE_INT
6130 && TREE_CODE (value
) == INTEGER_CST
6132 && bitpos
+ BITS_PER_WORD
<= exp_size
* BITS_PER_UNIT
)
6134 tree type
= TREE_TYPE (value
);
6136 if (TYPE_PRECISION (type
) < BITS_PER_WORD
)
6138 type
= lang_hooks
.types
.type_for_mode
6139 (word_mode
, TYPE_UNSIGNED (type
));
6140 value
= fold_convert (type
, value
);
6143 if (BYTES_BIG_ENDIAN
)
6145 = fold_build2 (LSHIFT_EXPR
, type
, value
,
6146 build_int_cst (type
,
6147 BITS_PER_WORD
- bitsize
));
6148 bitsize
= BITS_PER_WORD
;
6152 if (MEM_P (to_rtx
) && !MEM_KEEP_ALIAS_SET_P (to_rtx
)
6153 && DECL_NONADDRESSABLE_P (field
))
6155 to_rtx
= copy_rtx (to_rtx
);
6156 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
6159 store_constructor_field (to_rtx
, bitsize
, bitpos
, mode
,
6161 get_alias_set (TREE_TYPE (field
)),
6169 unsigned HOST_WIDE_INT i
;
6172 tree elttype
= TREE_TYPE (type
);
6174 HOST_WIDE_INT minelt
= 0;
6175 HOST_WIDE_INT maxelt
= 0;
6177 /* The storage order is specified for every aggregate type. */
6178 reverse
= TYPE_REVERSE_STORAGE_ORDER (type
);
6180 domain
= TYPE_DOMAIN (type
);
6181 const_bounds_p
= (TYPE_MIN_VALUE (domain
)
6182 && TYPE_MAX_VALUE (domain
)
6183 && tree_fits_shwi_p (TYPE_MIN_VALUE (domain
))
6184 && tree_fits_shwi_p (TYPE_MAX_VALUE (domain
)));
6186 /* If we have constant bounds for the range of the type, get them. */
6189 minelt
= tree_to_shwi (TYPE_MIN_VALUE (domain
));
6190 maxelt
= tree_to_shwi (TYPE_MAX_VALUE (domain
));
6193 /* If the constructor has fewer elements than the array, clear
6194 the whole array first. Similarly if this is static
6195 constructor of a non-BLKmode object. */
6198 else if (REG_P (target
) && TREE_STATIC (exp
))
6202 unsigned HOST_WIDE_INT idx
;
6204 HOST_WIDE_INT count
= 0, zero_count
= 0;
6205 need_to_clear
= ! const_bounds_p
;
6207 /* This loop is a more accurate version of the loop in
6208 mostly_zeros_p (it handles RANGE_EXPR in an index). It
6209 is also needed to check for missing elements. */
6210 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, index
, value
)
6212 HOST_WIDE_INT this_node_count
;
6217 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6219 tree lo_index
= TREE_OPERAND (index
, 0);
6220 tree hi_index
= TREE_OPERAND (index
, 1);
6222 if (! tree_fits_uhwi_p (lo_index
)
6223 || ! tree_fits_uhwi_p (hi_index
))
6229 this_node_count
= (tree_to_uhwi (hi_index
)
6230 - tree_to_uhwi (lo_index
) + 1);
6233 this_node_count
= 1;
6235 count
+= this_node_count
;
6236 if (mostly_zeros_p (value
))
6237 zero_count
+= this_node_count
;
6240 /* Clear the entire array first if there are any missing
6241 elements, or if the incidence of zero elements is >=
6244 && (count
< maxelt
- minelt
+ 1
6245 || 4 * zero_count
>= 3 * count
))
6249 if (need_to_clear
&& size
> 0)
6252 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6254 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6258 if (!cleared
&& REG_P (target
))
6259 /* Inform later passes that the old value is dead. */
6260 emit_clobber (target
);
6262 /* Store each element of the constructor into the
6263 corresponding element of TARGET, determined by counting the
6265 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), i
, index
, value
)
6268 HOST_WIDE_INT bitsize
;
6269 HOST_WIDE_INT bitpos
;
6270 rtx xtarget
= target
;
6272 if (cleared
&& initializer_zerop (value
))
6275 mode
= TYPE_MODE (elttype
);
6276 if (mode
== BLKmode
)
6277 bitsize
= (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6278 ? tree_to_uhwi (TYPE_SIZE (elttype
))
6281 bitsize
= GET_MODE_BITSIZE (mode
);
6283 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
6285 tree lo_index
= TREE_OPERAND (index
, 0);
6286 tree hi_index
= TREE_OPERAND (index
, 1);
6287 rtx index_r
, pos_rtx
;
6288 HOST_WIDE_INT lo
, hi
, count
;
6291 /* If the range is constant and "small", unroll the loop. */
6293 && tree_fits_shwi_p (lo_index
)
6294 && tree_fits_shwi_p (hi_index
)
6295 && (lo
= tree_to_shwi (lo_index
),
6296 hi
= tree_to_shwi (hi_index
),
6297 count
= hi
- lo
+ 1,
6300 || (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
6301 && (tree_to_uhwi (TYPE_SIZE (elttype
)) * count
6304 lo
-= minelt
; hi
-= minelt
;
6305 for (; lo
<= hi
; lo
++)
6307 bitpos
= lo
* tree_to_shwi (TYPE_SIZE (elttype
));
6310 && !MEM_KEEP_ALIAS_SET_P (target
)
6311 && TREE_CODE (type
) == ARRAY_TYPE
6312 && TYPE_NONALIASED_COMPONENT (type
))
6314 target
= copy_rtx (target
);
6315 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6318 store_constructor_field
6319 (target
, bitsize
, bitpos
, mode
, value
, cleared
,
6320 get_alias_set (elttype
), reverse
);
6325 rtx_code_label
*loop_start
= gen_label_rtx ();
6326 rtx_code_label
*loop_end
= gen_label_rtx ();
6329 expand_normal (hi_index
);
6331 index
= build_decl (EXPR_LOCATION (exp
),
6332 VAR_DECL
, NULL_TREE
, domain
);
6333 index_r
= gen_reg_rtx (promote_decl_mode (index
, NULL
));
6334 SET_DECL_RTL (index
, index_r
);
6335 store_expr (lo_index
, index_r
, 0, false, reverse
);
6337 /* Build the head of the loop. */
6338 do_pending_stack_adjust ();
6339 emit_label (loop_start
);
6341 /* Assign value to element index. */
6343 fold_convert (ssizetype
,
6344 fold_build2 (MINUS_EXPR
,
6347 TYPE_MIN_VALUE (domain
)));
6350 size_binop (MULT_EXPR
, position
,
6351 fold_convert (ssizetype
,
6352 TYPE_SIZE_UNIT (elttype
)));
6354 pos_rtx
= expand_normal (position
);
6355 xtarget
= offset_address (target
, pos_rtx
,
6356 highest_pow2_factor (position
));
6357 xtarget
= adjust_address (xtarget
, mode
, 0);
6358 if (TREE_CODE (value
) == CONSTRUCTOR
)
6359 store_constructor (value
, xtarget
, cleared
,
6360 bitsize
/ BITS_PER_UNIT
, reverse
);
6362 store_expr (value
, xtarget
, 0, false, reverse
);
6364 /* Generate a conditional jump to exit the loop. */
6365 exit_cond
= build2 (LT_EXPR
, integer_type_node
,
6367 jumpif (exit_cond
, loop_end
, -1);
6369 /* Update the loop counter, and jump to the head of
6371 expand_assignment (index
,
6372 build2 (PLUS_EXPR
, TREE_TYPE (index
),
6373 index
, integer_one_node
),
6376 emit_jump (loop_start
);
6378 /* Build the end of the loop. */
6379 emit_label (loop_end
);
6382 else if ((index
!= 0 && ! tree_fits_shwi_p (index
))
6383 || ! tree_fits_uhwi_p (TYPE_SIZE (elttype
)))
6388 index
= ssize_int (1);
6391 index
= fold_convert (ssizetype
,
6392 fold_build2 (MINUS_EXPR
,
6395 TYPE_MIN_VALUE (domain
)));
6398 size_binop (MULT_EXPR
, index
,
6399 fold_convert (ssizetype
,
6400 TYPE_SIZE_UNIT (elttype
)));
6401 xtarget
= offset_address (target
,
6402 expand_normal (position
),
6403 highest_pow2_factor (position
));
6404 xtarget
= adjust_address (xtarget
, mode
, 0);
6405 store_expr (value
, xtarget
, 0, false, reverse
);
6410 bitpos
= ((tree_to_shwi (index
) - minelt
)
6411 * tree_to_uhwi (TYPE_SIZE (elttype
)));
6413 bitpos
= (i
* tree_to_uhwi (TYPE_SIZE (elttype
)));
6415 if (MEM_P (target
) && !MEM_KEEP_ALIAS_SET_P (target
)
6416 && TREE_CODE (type
) == ARRAY_TYPE
6417 && TYPE_NONALIASED_COMPONENT (type
))
6419 target
= copy_rtx (target
);
6420 MEM_KEEP_ALIAS_SET_P (target
) = 1;
6422 store_constructor_field (target
, bitsize
, bitpos
, mode
, value
,
6423 cleared
, get_alias_set (elttype
),
6432 unsigned HOST_WIDE_INT idx
;
6433 constructor_elt
*ce
;
6436 int icode
= CODE_FOR_nothing
;
6437 tree elttype
= TREE_TYPE (type
);
6438 int elt_size
= tree_to_uhwi (TYPE_SIZE (elttype
));
6439 machine_mode eltmode
= TYPE_MODE (elttype
);
6440 HOST_WIDE_INT bitsize
;
6441 HOST_WIDE_INT bitpos
;
6442 rtvec vector
= NULL
;
6444 alias_set_type alias
;
6446 gcc_assert (eltmode
!= BLKmode
);
6448 n_elts
= TYPE_VECTOR_SUBPARTS (type
);
6449 if (REG_P (target
) && VECTOR_MODE_P (GET_MODE (target
)))
6451 machine_mode mode
= GET_MODE (target
);
6453 icode
= (int) optab_handler (vec_init_optab
, mode
);
6454 /* Don't use vec_init<mode> if some elements have VECTOR_TYPE. */
6455 if (icode
!= CODE_FOR_nothing
)
6459 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6460 if (TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
)
6462 icode
= CODE_FOR_nothing
;
6466 if (icode
!= CODE_FOR_nothing
)
6470 vector
= rtvec_alloc (n_elts
);
6471 for (i
= 0; i
< n_elts
; i
++)
6472 RTVEC_ELT (vector
, i
) = CONST0_RTX (GET_MODE_INNER (mode
));
6476 /* If the constructor has fewer elements than the vector,
6477 clear the whole array first. Similarly if this is static
6478 constructor of a non-BLKmode object. */
6481 else if (REG_P (target
) && TREE_STATIC (exp
))
6485 unsigned HOST_WIDE_INT count
= 0, zero_count
= 0;
6488 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
6490 int n_elts_here
= tree_to_uhwi
6491 (int_const_binop (TRUNC_DIV_EXPR
,
6492 TYPE_SIZE (TREE_TYPE (value
)),
6493 TYPE_SIZE (elttype
)));
6495 count
+= n_elts_here
;
6496 if (mostly_zeros_p (value
))
6497 zero_count
+= n_elts_here
;
6500 /* Clear the entire vector first if there are any missing elements,
6501 or if the incidence of zero elements is >= 75%. */
6502 need_to_clear
= (count
< n_elts
|| 4 * zero_count
>= 3 * count
);
6505 if (need_to_clear
&& size
> 0 && !vector
)
6508 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6510 clear_storage (target
, GEN_INT (size
), BLOCK_OP_NORMAL
);
6514 /* Inform later passes that the old value is dead. */
6515 if (!cleared
&& !vector
&& REG_P (target
))
6516 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
6519 alias
= MEM_ALIAS_SET (target
);
6521 alias
= get_alias_set (elttype
);
6523 /* Store each element of the constructor into the corresponding
6524 element of TARGET, determined by counting the elements. */
6525 for (idx
= 0, i
= 0;
6526 vec_safe_iterate (CONSTRUCTOR_ELTS (exp
), idx
, &ce
);
6527 idx
++, i
+= bitsize
/ elt_size
)
6529 HOST_WIDE_INT eltpos
;
6530 tree value
= ce
->value
;
6532 bitsize
= tree_to_uhwi (TYPE_SIZE (TREE_TYPE (value
)));
6533 if (cleared
&& initializer_zerop (value
))
6537 eltpos
= tree_to_uhwi (ce
->index
);
6543 /* vec_init<mode> should not be used if there are VECTOR_TYPE
6545 gcc_assert (TREE_CODE (TREE_TYPE (value
)) != VECTOR_TYPE
);
6546 RTVEC_ELT (vector
, eltpos
)
6547 = expand_normal (value
);
6551 machine_mode value_mode
=
6552 TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
6553 ? TYPE_MODE (TREE_TYPE (value
))
6555 bitpos
= eltpos
* elt_size
;
6556 store_constructor_field (target
, bitsize
, bitpos
, value_mode
,
6557 value
, cleared
, alias
, reverse
);
6562 emit_insn (GEN_FCN (icode
)
6564 gen_rtx_PARALLEL (GET_MODE (target
), vector
)));
6573 /* Store the value of EXP (an expression tree)
6574 into a subfield of TARGET which has mode MODE and occupies
6575 BITSIZE bits, starting BITPOS bits from the start of TARGET.
6576 If MODE is VOIDmode, it means that we are storing into a bit-field.
6578 BITREGION_START is bitpos of the first bitfield in this region.
6579 BITREGION_END is the bitpos of the ending bitfield in this region.
6580 These two fields are 0, if the C++ memory model does not apply,
6581 or we are not interested in keeping track of bitfield regions.
6583 Always return const0_rtx unless we have something particular to
6586 ALIAS_SET is the alias set for the destination. This value will
6587 (in general) be different from that for TARGET, since TARGET is a
6588 reference to the containing structure.
6590 If NONTEMPORAL is true, try generating a nontemporal store.
6592 If REVERSE is true, the store is to be done in reverse order. */
6595 store_field (rtx target
, HOST_WIDE_INT bitsize
, HOST_WIDE_INT bitpos
,
6596 unsigned HOST_WIDE_INT bitregion_start
,
6597 unsigned HOST_WIDE_INT bitregion_end
,
6598 machine_mode mode
, tree exp
,
6599 alias_set_type alias_set
, bool nontemporal
, bool reverse
)
6601 if (TREE_CODE (exp
) == ERROR_MARK
)
6604 /* If we have nothing to store, do nothing unless the expression has
6607 return expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
6609 if (GET_CODE (target
) == CONCAT
)
6611 /* We're storing into a struct containing a single __complex. */
6613 gcc_assert (!bitpos
);
6614 return store_expr (exp
, target
, 0, nontemporal
, reverse
);
6617 /* If the structure is in a register or if the component
6618 is a bit field, we cannot use addressing to access it.
6619 Use bit-field techniques or SUBREG to store in it. */
6621 if (mode
== VOIDmode
6622 || (mode
!= BLKmode
&& ! direct_store
[(int) mode
]
6623 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
6624 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
6626 || GET_CODE (target
) == SUBREG
6627 /* If the field isn't aligned enough to store as an ordinary memref,
6628 store it as a bit field. */
6630 && ((((MEM_ALIGN (target
) < GET_MODE_ALIGNMENT (mode
))
6631 || bitpos
% GET_MODE_ALIGNMENT (mode
))
6632 && SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (target
)))
6633 || (bitpos
% BITS_PER_UNIT
!= 0)))
6634 || (bitsize
>= 0 && mode
!= BLKmode
6635 && GET_MODE_BITSIZE (mode
) > bitsize
)
6636 /* If the RHS and field are a constant size and the size of the
6637 RHS isn't the same size as the bitfield, we must use bitfield
6640 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
6641 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)), bitsize
) != 0
6642 /* Except for initialization of full bytes from a CONSTRUCTOR, which
6643 we will handle specially below. */
6644 && !(TREE_CODE (exp
) == CONSTRUCTOR
6645 && bitsize
% BITS_PER_UNIT
== 0))
6646 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
6647 decl we must use bitfield operations. */
6649 && TREE_CODE (exp
) == MEM_REF
6650 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
6651 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
6652 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp
, 0),0 ))
6653 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)) != BLKmode
))
6658 /* If EXP is a NOP_EXPR of precision less than its mode, then that
6659 implies a mask operation. If the precision is the same size as
6660 the field we're storing into, that mask is redundant. This is
6661 particularly common with bit field assignments generated by the
6663 nop_def
= get_def_for_expr (exp
, NOP_EXPR
);
6666 tree type
= TREE_TYPE (exp
);
6667 if (INTEGRAL_TYPE_P (type
)
6668 && TYPE_PRECISION (type
) < GET_MODE_BITSIZE (TYPE_MODE (type
))
6669 && bitsize
== TYPE_PRECISION (type
))
6671 tree op
= gimple_assign_rhs1 (nop_def
);
6672 type
= TREE_TYPE (op
);
6673 if (INTEGRAL_TYPE_P (type
) && TYPE_PRECISION (type
) >= bitsize
)
6678 temp
= expand_normal (exp
);
6680 /* If the value has a record type and an integral mode then, if BITSIZE
6681 is narrower than this mode and this is for big-endian data, we must
6682 first put the value into the low-order bits. Moreover, the field may
6683 be not aligned on a byte boundary; in this case, if it has reverse
6684 storage order, it needs to be accessed as a scalar field with reverse
6685 storage order and we must first put the value into target order. */
6686 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
6687 && GET_MODE_CLASS (GET_MODE (temp
)) == MODE_INT
)
6689 HOST_WIDE_INT size
= GET_MODE_BITSIZE (GET_MODE (temp
));
6691 reverse
= TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (exp
));
6694 temp
= flip_storage_order (GET_MODE (temp
), temp
);
6697 && reverse
? !BYTES_BIG_ENDIAN
: BYTES_BIG_ENDIAN
)
6698 temp
= expand_shift (RSHIFT_EXPR
, GET_MODE (temp
), temp
,
6699 size
- bitsize
, NULL_RTX
, 1);
6702 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
6703 if (mode
!= VOIDmode
&& mode
!= BLKmode
6704 && mode
!= TYPE_MODE (TREE_TYPE (exp
)))
6705 temp
= convert_modes (mode
, TYPE_MODE (TREE_TYPE (exp
)), temp
, 1);
6707 /* If TEMP is not a PARALLEL (see below) and its mode and that of TARGET
6708 are both BLKmode, both must be in memory and BITPOS must be aligned
6709 on a byte boundary. If so, we simply do a block copy. Likewise for
6710 a BLKmode-like TARGET. */
6711 if (GET_CODE (temp
) != PARALLEL
6712 && GET_MODE (temp
) == BLKmode
6713 && (GET_MODE (target
) == BLKmode
6715 && GET_MODE_CLASS (GET_MODE (target
)) == MODE_INT
6716 && (bitpos
% BITS_PER_UNIT
) == 0
6717 && (bitsize
% BITS_PER_UNIT
) == 0)))
6719 gcc_assert (MEM_P (target
) && MEM_P (temp
)
6720 && (bitpos
% BITS_PER_UNIT
) == 0);
6722 target
= adjust_address (target
, VOIDmode
, bitpos
/ BITS_PER_UNIT
);
6723 emit_block_move (target
, temp
,
6724 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
6731 /* Handle calls that return values in multiple non-contiguous locations.
6732 The Irix 6 ABI has examples of this. */
6733 if (GET_CODE (temp
) == PARALLEL
)
6735 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6737 if (mode
== BLKmode
|| mode
== VOIDmode
)
6738 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6739 temp_target
= gen_reg_rtx (mode
);
6740 emit_group_store (temp_target
, temp
, TREE_TYPE (exp
), size
);
6743 else if (mode
== BLKmode
)
6745 /* Handle calls that return BLKmode values in registers. */
6746 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
6748 rtx temp_target
= gen_reg_rtx (GET_MODE (temp
));
6749 copy_blkmode_from_reg (temp_target
, temp
, TREE_TYPE (exp
));
6754 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
6756 mode
= smallest_mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
);
6757 temp_target
= gen_reg_rtx (mode
);
6759 = extract_bit_field (temp
, size
* BITS_PER_UNIT
, 0, 1,
6760 temp_target
, mode
, mode
, false);
6765 /* Store the value in the bitfield. */
6766 store_bit_field (target
, bitsize
, bitpos
,
6767 bitregion_start
, bitregion_end
,
6768 mode
, temp
, reverse
);
6774 /* Now build a reference to just the desired component. */
6775 rtx to_rtx
= adjust_address (target
, mode
, bitpos
/ BITS_PER_UNIT
);
6777 if (to_rtx
== target
)
6778 to_rtx
= copy_rtx (to_rtx
);
6780 if (!MEM_KEEP_ALIAS_SET_P (to_rtx
) && MEM_ALIAS_SET (to_rtx
) != 0)
6781 set_mem_alias_set (to_rtx
, alias_set
);
6783 /* Above we avoided using bitfield operations for storing a CONSTRUCTOR
6784 into a target smaller than its type; handle that case now. */
6785 if (TREE_CODE (exp
) == CONSTRUCTOR
&& bitsize
>= 0)
6787 gcc_assert (bitsize
% BITS_PER_UNIT
== 0);
6788 store_constructor (exp
, to_rtx
, 0, bitsize
/ BITS_PER_UNIT
, reverse
);
6792 return store_expr (exp
, to_rtx
, 0, nontemporal
, reverse
);
6796 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
6797 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
6798 codes and find the ultimate containing object, which we return.
6800 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
6801 bit position, *PUNSIGNEDP to the signedness and *PREVERSEP to the
6802 storage order of the field.
6803 If the position of the field is variable, we store a tree
6804 giving the variable offset (in units) in *POFFSET.
6805 This offset is in addition to the bit position.
6806 If the position is not variable, we store 0 in *POFFSET.
6808 If any of the extraction expressions is volatile,
6809 we store 1 in *PVOLATILEP. Otherwise we don't change that.
6811 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
6812 Otherwise, it is a mode that can be used to access the field.
6814 If the field describes a variable-sized object, *PMODE is set to
6815 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
6816 this case, but the address of the object can be found.
6818 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
6819 look through nodes that serve as markers of a greater alignment than
6820 the one that can be deduced from the expression. These nodes make it
6821 possible for front-ends to prevent temporaries from being created by
6822 the middle-end on alignment considerations. For that purpose, the
6823 normal operating mode at high-level is to always pass FALSE so that
6824 the ultimate containing object is really returned; moreover, the
6825 associated predicate handled_component_p will always return TRUE
6826 on these nodes, thus indicating that they are essentially handled
6827 by get_inner_reference. TRUE should only be passed when the caller
6828 is scanning the expression in order to build another representation
6829 and specifically knows how to handle these nodes; as such, this is
6830 the normal operating mode in the RTL expanders. */
6833 get_inner_reference (tree exp
, HOST_WIDE_INT
*pbitsize
,
6834 HOST_WIDE_INT
*pbitpos
, tree
*poffset
,
6835 machine_mode
*pmode
, int *punsignedp
,
6836 int *preversep
, int *pvolatilep
, bool keep_aligning
)
6839 machine_mode mode
= VOIDmode
;
6840 bool blkmode_bitfield
= false;
6841 tree offset
= size_zero_node
;
6842 offset_int bit_offset
= 0;
6844 /* First get the mode, signedness, storage order and size. We do this from
6845 just the outermost expression. */
6847 if (TREE_CODE (exp
) == COMPONENT_REF
)
6849 tree field
= TREE_OPERAND (exp
, 1);
6850 size_tree
= DECL_SIZE (field
);
6851 if (flag_strict_volatile_bitfields
> 0
6852 && TREE_THIS_VOLATILE (exp
)
6853 && DECL_BIT_FIELD_TYPE (field
)
6854 && DECL_MODE (field
) != BLKmode
)
6855 /* Volatile bitfields should be accessed in the mode of the
6856 field's type, not the mode computed based on the bit
6858 mode
= TYPE_MODE (DECL_BIT_FIELD_TYPE (field
));
6859 else if (!DECL_BIT_FIELD (field
))
6860 mode
= DECL_MODE (field
);
6861 else if (DECL_MODE (field
) == BLKmode
)
6862 blkmode_bitfield
= true;
6864 *punsignedp
= DECL_UNSIGNED (field
);
6866 else if (TREE_CODE (exp
) == BIT_FIELD_REF
)
6868 size_tree
= TREE_OPERAND (exp
, 1);
6869 *punsignedp
= (! INTEGRAL_TYPE_P (TREE_TYPE (exp
))
6870 || TYPE_UNSIGNED (TREE_TYPE (exp
)));
6872 /* For vector types, with the correct size of access, use the mode of
6874 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == VECTOR_TYPE
6875 && TREE_TYPE (exp
) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6876 && tree_int_cst_equal (size_tree
, TYPE_SIZE (TREE_TYPE (exp
))))
6877 mode
= TYPE_MODE (TREE_TYPE (exp
));
6881 mode
= TYPE_MODE (TREE_TYPE (exp
));
6882 *punsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
6884 if (mode
== BLKmode
)
6885 size_tree
= TYPE_SIZE (TREE_TYPE (exp
));
6887 *pbitsize
= GET_MODE_BITSIZE (mode
);
6892 if (! tree_fits_uhwi_p (size_tree
))
6893 mode
= BLKmode
, *pbitsize
= -1;
6895 *pbitsize
= tree_to_uhwi (size_tree
);
6898 *preversep
= reverse_storage_order_for_component_p (exp
);
6900 /* Compute cumulative bit-offset for nested component-refs and array-refs,
6901 and find the ultimate containing object. */
6904 switch (TREE_CODE (exp
))
6907 bit_offset
+= wi::to_offset (TREE_OPERAND (exp
, 2));
6912 tree field
= TREE_OPERAND (exp
, 1);
6913 tree this_offset
= component_ref_field_offset (exp
);
6915 /* If this field hasn't been filled in yet, don't go past it.
6916 This should only happen when folding expressions made during
6917 type construction. */
6918 if (this_offset
== 0)
6921 offset
= size_binop (PLUS_EXPR
, offset
, this_offset
);
6922 bit_offset
+= wi::to_offset (DECL_FIELD_BIT_OFFSET (field
));
6924 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
6929 case ARRAY_RANGE_REF
:
6931 tree index
= TREE_OPERAND (exp
, 1);
6932 tree low_bound
= array_ref_low_bound (exp
);
6933 tree unit_size
= array_ref_element_size (exp
);
6935 /* We assume all arrays have sizes that are a multiple of a byte.
6936 First subtract the lower bound, if any, in the type of the
6937 index, then convert to sizetype and multiply by the size of
6938 the array element. */
6939 if (! integer_zerop (low_bound
))
6940 index
= fold_build2 (MINUS_EXPR
, TREE_TYPE (index
),
6943 offset
= size_binop (PLUS_EXPR
, offset
,
6944 size_binop (MULT_EXPR
,
6945 fold_convert (sizetype
, index
),
6954 bit_offset
+= *pbitsize
;
6957 case VIEW_CONVERT_EXPR
:
6958 if (keep_aligning
&& STRICT_ALIGNMENT
6959 && (TYPE_ALIGN (TREE_TYPE (exp
))
6960 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0))))
6961 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp
, 0)))
6962 < BIGGEST_ALIGNMENT
)
6963 && (TYPE_ALIGN_OK (TREE_TYPE (exp
))
6964 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp
, 0)))))
6969 /* Hand back the decl for MEM[&decl, off]. */
6970 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
)
6972 tree off
= TREE_OPERAND (exp
, 1);
6973 if (!integer_zerop (off
))
6975 offset_int boff
, coff
= mem_ref_offset (exp
);
6976 boff
= wi::lshift (coff
, LOG2_BITS_PER_UNIT
);
6979 exp
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
6987 /* If any reference in the chain is volatile, the effect is volatile. */
6988 if (TREE_THIS_VOLATILE (exp
))
6991 exp
= TREE_OPERAND (exp
, 0);
6995 /* If OFFSET is constant, see if we can return the whole thing as a
6996 constant bit position. Make sure to handle overflow during
6998 if (TREE_CODE (offset
) == INTEGER_CST
)
7000 offset_int tem
= wi::sext (wi::to_offset (offset
),
7001 TYPE_PRECISION (sizetype
));
7002 tem
= wi::lshift (tem
, LOG2_BITS_PER_UNIT
);
7004 if (wi::fits_shwi_p (tem
))
7006 *pbitpos
= tem
.to_shwi ();
7007 *poffset
= offset
= NULL_TREE
;
7011 /* Otherwise, split it up. */
7014 /* Avoid returning a negative bitpos as this may wreak havoc later. */
7015 if (wi::neg_p (bit_offset
) || !wi::fits_shwi_p (bit_offset
))
7017 offset_int mask
= wi::mask
<offset_int
> (LOG2_BITS_PER_UNIT
, false);
7018 offset_int tem
= bit_offset
.and_not (mask
);
7019 /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
7020 Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
7022 tem
= wi::arshift (tem
, LOG2_BITS_PER_UNIT
);
7023 offset
= size_binop (PLUS_EXPR
, offset
,
7024 wide_int_to_tree (sizetype
, tem
));
7027 *pbitpos
= bit_offset
.to_shwi ();
7031 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
7032 if (mode
== VOIDmode
7034 && (*pbitpos
% BITS_PER_UNIT
) == 0
7035 && (*pbitsize
% BITS_PER_UNIT
) == 0)
7043 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
7045 static unsigned HOST_WIDE_INT
7046 target_align (const_tree target
)
7048 /* We might have a chain of nested references with intermediate misaligning
7049 bitfields components, so need to recurse to find out. */
7051 unsigned HOST_WIDE_INT this_align
, outer_align
;
7053 switch (TREE_CODE (target
))
7059 this_align
= DECL_ALIGN (TREE_OPERAND (target
, 1));
7060 outer_align
= target_align (TREE_OPERAND (target
, 0));
7061 return MIN (this_align
, outer_align
);
7064 case ARRAY_RANGE_REF
:
7065 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7066 outer_align
= target_align (TREE_OPERAND (target
, 0));
7067 return MIN (this_align
, outer_align
);
7070 case NON_LVALUE_EXPR
:
7071 case VIEW_CONVERT_EXPR
:
7072 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
7073 outer_align
= target_align (TREE_OPERAND (target
, 0));
7074 return MAX (this_align
, outer_align
);
7077 return TYPE_ALIGN (TREE_TYPE (target
));
7082 /* Given an rtx VALUE that may contain additions and multiplications, return
7083 an equivalent value that just refers to a register, memory, or constant.
7084 This is done by generating instructions to perform the arithmetic and
7085 returning a pseudo-register containing the value.
7087 The returned value may be a REG, SUBREG, MEM or constant. */
7090 force_operand (rtx value
, rtx target
)
7093 /* Use subtarget as the target for operand 0 of a binary operation. */
7094 rtx subtarget
= get_subtarget (target
);
7095 enum rtx_code code
= GET_CODE (value
);
7097 /* Check for subreg applied to an expression produced by loop optimizer. */
7099 && !REG_P (SUBREG_REG (value
))
7100 && !MEM_P (SUBREG_REG (value
)))
7103 = simplify_gen_subreg (GET_MODE (value
),
7104 force_reg (GET_MODE (SUBREG_REG (value
)),
7105 force_operand (SUBREG_REG (value
),
7107 GET_MODE (SUBREG_REG (value
)),
7108 SUBREG_BYTE (value
));
7109 code
= GET_CODE (value
);
7112 /* Check for a PIC address load. */
7113 if ((code
== PLUS
|| code
== MINUS
)
7114 && XEXP (value
, 0) == pic_offset_table_rtx
7115 && (GET_CODE (XEXP (value
, 1)) == SYMBOL_REF
7116 || GET_CODE (XEXP (value
, 1)) == LABEL_REF
7117 || GET_CODE (XEXP (value
, 1)) == CONST
))
7120 subtarget
= gen_reg_rtx (GET_MODE (value
));
7121 emit_move_insn (subtarget
, value
);
7125 if (ARITHMETIC_P (value
))
7127 op2
= XEXP (value
, 1);
7128 if (!CONSTANT_P (op2
) && !(REG_P (op2
) && op2
!= subtarget
))
7130 if (code
== MINUS
&& CONST_INT_P (op2
))
7133 op2
= negate_rtx (GET_MODE (value
), op2
);
7136 /* Check for an addition with OP2 a constant integer and our first
7137 operand a PLUS of a virtual register and something else. In that
7138 case, we want to emit the sum of the virtual register and the
7139 constant first and then add the other value. This allows virtual
7140 register instantiation to simply modify the constant rather than
7141 creating another one around this addition. */
7142 if (code
== PLUS
&& CONST_INT_P (op2
)
7143 && GET_CODE (XEXP (value
, 0)) == PLUS
7144 && REG_P (XEXP (XEXP (value
, 0), 0))
7145 && REGNO (XEXP (XEXP (value
, 0), 0)) >= FIRST_VIRTUAL_REGISTER
7146 && REGNO (XEXP (XEXP (value
, 0), 0)) <= LAST_VIRTUAL_REGISTER
)
7148 rtx temp
= expand_simple_binop (GET_MODE (value
), code
,
7149 XEXP (XEXP (value
, 0), 0), op2
,
7150 subtarget
, 0, OPTAB_LIB_WIDEN
);
7151 return expand_simple_binop (GET_MODE (value
), code
, temp
,
7152 force_operand (XEXP (XEXP (value
,
7154 target
, 0, OPTAB_LIB_WIDEN
);
7157 op1
= force_operand (XEXP (value
, 0), subtarget
);
7158 op2
= force_operand (op2
, NULL_RTX
);
7162 return expand_mult (GET_MODE (value
), op1
, op2
, target
, 1);
7164 if (!INTEGRAL_MODE_P (GET_MODE (value
)))
7165 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7166 target
, 1, OPTAB_LIB_WIDEN
);
7168 return expand_divmod (0,
7169 FLOAT_MODE_P (GET_MODE (value
))
7170 ? RDIV_EXPR
: TRUNC_DIV_EXPR
,
7171 GET_MODE (value
), op1
, op2
, target
, 0);
7173 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7176 return expand_divmod (0, TRUNC_DIV_EXPR
, GET_MODE (value
), op1
, op2
,
7179 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
7182 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7183 target
, 0, OPTAB_LIB_WIDEN
);
7185 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
7186 target
, 1, OPTAB_LIB_WIDEN
);
7189 if (UNARY_P (value
))
7192 target
= gen_reg_rtx (GET_MODE (value
));
7193 op1
= force_operand (XEXP (value
, 0), NULL_RTX
);
7200 case FLOAT_TRUNCATE
:
7201 convert_move (target
, op1
, code
== ZERO_EXTEND
);
7206 expand_fix (target
, op1
, code
== UNSIGNED_FIX
);
7210 case UNSIGNED_FLOAT
:
7211 expand_float (target
, op1
, code
== UNSIGNED_FLOAT
);
7215 return expand_simple_unop (GET_MODE (value
), code
, op1
, target
, 0);
7219 #ifdef INSN_SCHEDULING
7220 /* On machines that have insn scheduling, we want all memory reference to be
7221 explicit, so we need to deal with such paradoxical SUBREGs. */
7222 if (paradoxical_subreg_p (value
) && MEM_P (SUBREG_REG (value
)))
7224 = simplify_gen_subreg (GET_MODE (value
),
7225 force_reg (GET_MODE (SUBREG_REG (value
)),
7226 force_operand (SUBREG_REG (value
),
7228 GET_MODE (SUBREG_REG (value
)),
7229 SUBREG_BYTE (value
));
7235 /* Subroutine of expand_expr: return nonzero iff there is no way that
7236 EXP can reference X, which is being modified. TOP_P is nonzero if this
7237 call is going to be used to determine whether we need a temporary
7238 for EXP, as opposed to a recursive call to this function.
7240 It is always safe for this routine to return zero since it merely
7241 searches for optimization opportunities. */
7244 safe_from_p (const_rtx x
, tree exp
, int top_p
)
7250 /* If EXP has varying size, we MUST use a target since we currently
7251 have no way of allocating temporaries of variable size
7252 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
7253 So we assume here that something at a higher level has prevented a
7254 clash. This is somewhat bogus, but the best we can do. Only
7255 do this when X is BLKmode and when we are at the top level. */
7256 || (top_p
&& TREE_TYPE (exp
) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp
))
7257 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) != INTEGER_CST
7258 && (TREE_CODE (TREE_TYPE (exp
)) != ARRAY_TYPE
7259 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)) == NULL_TREE
7260 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)))
7262 && GET_MODE (x
) == BLKmode
)
7263 /* If X is in the outgoing argument area, it is always safe. */
7265 && (XEXP (x
, 0) == virtual_outgoing_args_rtx
7266 || (GET_CODE (XEXP (x
, 0)) == PLUS
7267 && XEXP (XEXP (x
, 0), 0) == virtual_outgoing_args_rtx
))))
7270 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
7271 find the underlying pseudo. */
7272 if (GET_CODE (x
) == SUBREG
)
7275 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7279 /* Now look at our tree code and possibly recurse. */
7280 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
7282 case tcc_declaration
:
7283 exp_rtl
= DECL_RTL_IF_SET (exp
);
7289 case tcc_exceptional
:
7290 if (TREE_CODE (exp
) == TREE_LIST
)
7294 if (TREE_VALUE (exp
) && !safe_from_p (x
, TREE_VALUE (exp
), 0))
7296 exp
= TREE_CHAIN (exp
);
7299 if (TREE_CODE (exp
) != TREE_LIST
)
7300 return safe_from_p (x
, exp
, 0);
7303 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
7305 constructor_elt
*ce
;
7306 unsigned HOST_WIDE_INT idx
;
7308 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp
), idx
, ce
)
7309 if ((ce
->index
!= NULL_TREE
&& !safe_from_p (x
, ce
->index
, 0))
7310 || !safe_from_p (x
, ce
->value
, 0))
7314 else if (TREE_CODE (exp
) == ERROR_MARK
)
7315 return 1; /* An already-visited SAVE_EXPR? */
7320 /* The only case we look at here is the DECL_INITIAL inside a
7322 return (TREE_CODE (exp
) != DECL_EXPR
7323 || TREE_CODE (DECL_EXPR_DECL (exp
)) != VAR_DECL
7324 || !DECL_INITIAL (DECL_EXPR_DECL (exp
))
7325 || safe_from_p (x
, DECL_INITIAL (DECL_EXPR_DECL (exp
)), 0));
7328 case tcc_comparison
:
7329 if (!safe_from_p (x
, TREE_OPERAND (exp
, 1), 0))
7334 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7336 case tcc_expression
:
7339 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
7340 the expression. If it is set, we conflict iff we are that rtx or
7341 both are in memory. Otherwise, we check all operands of the
7342 expression recursively. */
7344 switch (TREE_CODE (exp
))
7347 /* If the operand is static or we are static, we can't conflict.
7348 Likewise if we don't conflict with the operand at all. */
7349 if (staticp (TREE_OPERAND (exp
, 0))
7350 || TREE_STATIC (exp
)
7351 || safe_from_p (x
, TREE_OPERAND (exp
, 0), 0))
7354 /* Otherwise, the only way this can conflict is if we are taking
7355 the address of a DECL a that address if part of X, which is
7357 exp
= TREE_OPERAND (exp
, 0);
7360 if (!DECL_RTL_SET_P (exp
)
7361 || !MEM_P (DECL_RTL (exp
)))
7364 exp_rtl
= XEXP (DECL_RTL (exp
), 0);
7370 && alias_sets_conflict_p (MEM_ALIAS_SET (x
),
7371 get_alias_set (exp
)))
7376 /* Assume that the call will clobber all hard registers and
7378 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
7383 case WITH_CLEANUP_EXPR
:
7384 case CLEANUP_POINT_EXPR
:
7385 /* Lowered by gimplify.c. */
7389 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
7395 /* If we have an rtx, we do not need to scan our operands. */
7399 nops
= TREE_OPERAND_LENGTH (exp
);
7400 for (i
= 0; i
< nops
; i
++)
7401 if (TREE_OPERAND (exp
, i
) != 0
7402 && ! safe_from_p (x
, TREE_OPERAND (exp
, i
), 0))
7408 /* Should never get a type here. */
7412 /* If we have an rtl, find any enclosed object. Then see if we conflict
7416 if (GET_CODE (exp_rtl
) == SUBREG
)
7418 exp_rtl
= SUBREG_REG (exp_rtl
);
7420 && REGNO (exp_rtl
) < FIRST_PSEUDO_REGISTER
)
7424 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
7425 are memory and they conflict. */
7426 return ! (rtx_equal_p (x
, exp_rtl
)
7427 || (MEM_P (x
) && MEM_P (exp_rtl
)
7428 && true_dependence (exp_rtl
, VOIDmode
, x
)));
7431 /* If we reach here, it is safe. */
7436 /* Return the highest power of two that EXP is known to be a multiple of.
7437 This is used in updating alignment of MEMs in array references. */
7439 unsigned HOST_WIDE_INT
7440 highest_pow2_factor (const_tree exp
)
7442 unsigned HOST_WIDE_INT ret
;
7443 int trailing_zeros
= tree_ctz (exp
);
7444 if (trailing_zeros
>= HOST_BITS_PER_WIDE_INT
)
7445 return BIGGEST_ALIGNMENT
;
7446 ret
= (unsigned HOST_WIDE_INT
) 1 << trailing_zeros
;
7447 if (ret
> BIGGEST_ALIGNMENT
)
7448 return BIGGEST_ALIGNMENT
;
7452 /* Similar, except that the alignment requirements of TARGET are
7453 taken into account. Assume it is at least as aligned as its
7454 type, unless it is a COMPONENT_REF in which case the layout of
7455 the structure gives the alignment. */
7457 static unsigned HOST_WIDE_INT
7458 highest_pow2_factor_for_target (const_tree target
, const_tree exp
)
7460 unsigned HOST_WIDE_INT talign
= target_align (target
) / BITS_PER_UNIT
;
7461 unsigned HOST_WIDE_INT factor
= highest_pow2_factor (exp
);
7463 return MAX (factor
, talign
);
7466 /* Convert the tree comparison code TCODE to the rtl one where the
7467 signedness is UNSIGNEDP. */
7469 static enum rtx_code
7470 convert_tree_comp_to_rtx (enum tree_code tcode
, int unsignedp
)
7482 code
= unsignedp
? LTU
: LT
;
7485 code
= unsignedp
? LEU
: LE
;
7488 code
= unsignedp
? GTU
: GT
;
7491 code
= unsignedp
? GEU
: GE
;
7493 case UNORDERED_EXPR
:
7524 /* Subroutine of expand_expr. Expand the two operands of a binary
7525 expression EXP0 and EXP1 placing the results in OP0 and OP1.
7526 The value may be stored in TARGET if TARGET is nonzero. The
7527 MODIFIER argument is as documented by expand_expr. */
7530 expand_operands (tree exp0
, tree exp1
, rtx target
, rtx
*op0
, rtx
*op1
,
7531 enum expand_modifier modifier
)
7533 if (! safe_from_p (target
, exp1
, 1))
7535 if (operand_equal_p (exp0
, exp1
, 0))
7537 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7538 *op1
= copy_rtx (*op0
);
7542 /* If we need to preserve evaluation order, copy exp0 into its own
7543 temporary variable so that it can't be clobbered by exp1. */
7544 if (flag_evaluation_order
&& TREE_SIDE_EFFECTS (exp1
))
7545 exp0
= save_expr (exp0
);
7546 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
7547 *op1
= expand_expr (exp1
, NULL_RTX
, VOIDmode
, modifier
);
7552 /* Return a MEM that contains constant EXP. DEFER is as for
7553 output_constant_def and MODIFIER is as for expand_expr. */
7556 expand_expr_constant (tree exp
, int defer
, enum expand_modifier modifier
)
7560 mem
= output_constant_def (exp
, defer
);
7561 if (modifier
!= EXPAND_INITIALIZER
)
7562 mem
= use_anchored_address (mem
);
7566 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
7567 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7570 expand_expr_addr_expr_1 (tree exp
, rtx target
, machine_mode tmode
,
7571 enum expand_modifier modifier
, addr_space_t as
)
7573 rtx result
, subtarget
;
7575 HOST_WIDE_INT bitsize
, bitpos
;
7576 int unsignedp
, reversep
, volatilep
= 0;
7579 /* If we are taking the address of a constant and are at the top level,
7580 we have to use output_constant_def since we can't call force_const_mem
7582 /* ??? This should be considered a front-end bug. We should not be
7583 generating ADDR_EXPR of something that isn't an LVALUE. The only
7584 exception here is STRING_CST. */
7585 if (CONSTANT_CLASS_P (exp
))
7587 result
= XEXP (expand_expr_constant (exp
, 0, modifier
), 0);
7588 if (modifier
< EXPAND_SUM
)
7589 result
= force_operand (result
, target
);
7593 /* Everything must be something allowed by is_gimple_addressable. */
7594 switch (TREE_CODE (exp
))
7597 /* This case will happen via recursion for &a->b. */
7598 return expand_expr (TREE_OPERAND (exp
, 0), target
, tmode
, modifier
);
7602 tree tem
= TREE_OPERAND (exp
, 0);
7603 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
7604 tem
= fold_build_pointer_plus (tem
, TREE_OPERAND (exp
, 1));
7605 return expand_expr (tem
, target
, tmode
, modifier
);
7609 /* Expand the initializer like constants above. */
7610 result
= XEXP (expand_expr_constant (DECL_INITIAL (exp
),
7612 if (modifier
< EXPAND_SUM
)
7613 result
= force_operand (result
, target
);
7617 /* The real part of the complex number is always first, therefore
7618 the address is the same as the address of the parent object. */
7621 inner
= TREE_OPERAND (exp
, 0);
7625 /* The imaginary part of the complex number is always second.
7626 The expression is therefore always offset by the size of the
7629 bitpos
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp
)));
7630 inner
= TREE_OPERAND (exp
, 0);
7633 case COMPOUND_LITERAL_EXPR
:
7634 /* Allow COMPOUND_LITERAL_EXPR in initializers or coming from
7635 initializers, if e.g. rtl_for_decl_init is called on DECL_INITIAL
7636 with COMPOUND_LITERAL_EXPRs in it, or ARRAY_REF on a const static
7637 array with address of COMPOUND_LITERAL_EXPR in DECL_INITIAL;
7638 the initializers aren't gimplified. */
7639 if (COMPOUND_LITERAL_EXPR_DECL (exp
)
7640 && TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (exp
)))
7641 return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp
),
7642 target
, tmode
, modifier
, as
);
7645 /* If the object is a DECL, then expand it for its rtl. Don't bypass
7646 expand_expr, as that can have various side effects; LABEL_DECLs for
7647 example, may not have their DECL_RTL set yet. Expand the rtl of
7648 CONSTRUCTORs too, which should yield a memory reference for the
7649 constructor's contents. Assume language specific tree nodes can
7650 be expanded in some interesting way. */
7651 gcc_assert (TREE_CODE (exp
) < LAST_AND_UNUSED_TREE_CODE
);
7653 || TREE_CODE (exp
) == CONSTRUCTOR
7654 || TREE_CODE (exp
) == COMPOUND_LITERAL_EXPR
)
7656 result
= expand_expr (exp
, target
, tmode
,
7657 modifier
== EXPAND_INITIALIZER
7658 ? EXPAND_INITIALIZER
: EXPAND_CONST_ADDRESS
);
7660 /* If the DECL isn't in memory, then the DECL wasn't properly
7661 marked TREE_ADDRESSABLE, which will be either a front-end
7662 or a tree optimizer bug. */
7664 gcc_assert (MEM_P (result
));
7665 result
= XEXP (result
, 0);
7667 /* ??? Is this needed anymore? */
7669 TREE_USED (exp
) = 1;
7671 if (modifier
!= EXPAND_INITIALIZER
7672 && modifier
!= EXPAND_CONST_ADDRESS
7673 && modifier
!= EXPAND_SUM
)
7674 result
= force_operand (result
, target
);
7678 /* Pass FALSE as the last argument to get_inner_reference although
7679 we are expanding to RTL. The rationale is that we know how to
7680 handle "aligning nodes" here: we can just bypass them because
7681 they won't change the final object whose address will be returned
7682 (they actually exist only for that purpose). */
7683 inner
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
, &mode1
,
7684 &unsignedp
, &reversep
, &volatilep
, false);
7688 /* We must have made progress. */
7689 gcc_assert (inner
!= exp
);
7691 subtarget
= offset
|| bitpos
? NULL_RTX
: target
;
7692 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
7693 inner alignment, force the inner to be sufficiently aligned. */
7694 if (CONSTANT_CLASS_P (inner
)
7695 && TYPE_ALIGN (TREE_TYPE (inner
)) < TYPE_ALIGN (TREE_TYPE (exp
)))
7697 inner
= copy_node (inner
);
7698 TREE_TYPE (inner
) = copy_node (TREE_TYPE (inner
));
7699 TYPE_ALIGN (TREE_TYPE (inner
)) = TYPE_ALIGN (TREE_TYPE (exp
));
7700 TYPE_USER_ALIGN (TREE_TYPE (inner
)) = 1;
7702 result
= expand_expr_addr_expr_1 (inner
, subtarget
, tmode
, modifier
, as
);
7708 if (modifier
!= EXPAND_NORMAL
)
7709 result
= force_operand (result
, NULL
);
7710 tmp
= expand_expr (offset
, NULL_RTX
, tmode
,
7711 modifier
== EXPAND_INITIALIZER
7712 ? EXPAND_INITIALIZER
: EXPAND_NORMAL
);
7714 /* expand_expr is allowed to return an object in a mode other
7715 than TMODE. If it did, we need to convert. */
7716 if (GET_MODE (tmp
) != VOIDmode
&& tmode
!= GET_MODE (tmp
))
7717 tmp
= convert_modes (tmode
, GET_MODE (tmp
),
7718 tmp
, TYPE_UNSIGNED (TREE_TYPE (offset
)));
7719 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7720 tmp
= convert_memory_address_addr_space (tmode
, tmp
, as
);
7722 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
7723 result
= simplify_gen_binary (PLUS
, tmode
, result
, tmp
);
7726 subtarget
= bitpos
? NULL_RTX
: target
;
7727 result
= expand_simple_binop (tmode
, PLUS
, result
, tmp
, subtarget
,
7728 1, OPTAB_LIB_WIDEN
);
7734 /* Someone beforehand should have rejected taking the address
7735 of such an object. */
7736 gcc_assert ((bitpos
% BITS_PER_UNIT
) == 0);
7738 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7739 result
= plus_constant (tmode
, result
, bitpos
/ BITS_PER_UNIT
);
7740 if (modifier
< EXPAND_SUM
)
7741 result
= force_operand (result
, target
);
7747 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
7748 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
7751 expand_expr_addr_expr (tree exp
, rtx target
, machine_mode tmode
,
7752 enum expand_modifier modifier
)
7754 addr_space_t as
= ADDR_SPACE_GENERIC
;
7755 machine_mode address_mode
= Pmode
;
7756 machine_mode pointer_mode
= ptr_mode
;
7760 /* Target mode of VOIDmode says "whatever's natural". */
7761 if (tmode
== VOIDmode
)
7762 tmode
= TYPE_MODE (TREE_TYPE (exp
));
7764 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
7766 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
7767 address_mode
= targetm
.addr_space
.address_mode (as
);
7768 pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7771 /* We can get called with some Weird Things if the user does silliness
7772 like "(short) &a". In that case, convert_memory_address won't do
7773 the right thing, so ignore the given target mode. */
7774 if (tmode
!= address_mode
&& tmode
!= pointer_mode
)
7775 tmode
= address_mode
;
7777 result
= expand_expr_addr_expr_1 (TREE_OPERAND (exp
, 0), target
,
7778 tmode
, modifier
, as
);
7780 /* Despite expand_expr claims concerning ignoring TMODE when not
7781 strictly convenient, stuff breaks if we don't honor it. Note
7782 that combined with the above, we only do this for pointer modes. */
7783 rmode
= GET_MODE (result
);
7784 if (rmode
== VOIDmode
)
7787 result
= convert_memory_address_addr_space (tmode
, result
, as
);
7792 /* Generate code for computing CONSTRUCTOR EXP.
7793 An rtx for the computed value is returned. If AVOID_TEMP_MEM
7794 is TRUE, instead of creating a temporary variable in memory
7795 NULL is returned and the caller needs to handle it differently. */
7798 expand_constructor (tree exp
, rtx target
, enum expand_modifier modifier
,
7799 bool avoid_temp_mem
)
7801 tree type
= TREE_TYPE (exp
);
7802 machine_mode mode
= TYPE_MODE (type
);
7804 /* Try to avoid creating a temporary at all. This is possible
7805 if all of the initializer is zero.
7806 FIXME: try to handle all [0..255] initializers we can handle
7808 if (TREE_STATIC (exp
)
7809 && !TREE_ADDRESSABLE (exp
)
7810 && target
!= 0 && mode
== BLKmode
7811 && all_zeros_p (exp
))
7813 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
7817 /* All elts simple constants => refer to a constant in memory. But
7818 if this is a non-BLKmode mode, let it store a field at a time
7819 since that should make a CONST_INT, CONST_WIDE_INT or
7820 CONST_DOUBLE when we fold. Likewise, if we have a target we can
7821 use, it is best to store directly into the target unless the type
7822 is large enough that memcpy will be used. If we are making an
7823 initializer and all operands are constant, put it in memory as
7826 FIXME: Avoid trying to fill vector constructors piece-meal.
7827 Output them with output_constant_def below unless we're sure
7828 they're zeros. This should go away when vector initializers
7829 are treated like VECTOR_CST instead of arrays. */
7830 if ((TREE_STATIC (exp
)
7831 && ((mode
== BLKmode
7832 && ! (target
!= 0 && safe_from_p (target
, exp
, 1)))
7833 || TREE_ADDRESSABLE (exp
)
7834 || (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
7835 && (! can_move_by_pieces
7836 (tree_to_uhwi (TYPE_SIZE_UNIT (type
)),
7838 && ! mostly_zeros_p (exp
))))
7839 || ((modifier
== EXPAND_INITIALIZER
|| modifier
== EXPAND_CONST_ADDRESS
)
7840 && TREE_CONSTANT (exp
)))
7847 constructor
= expand_expr_constant (exp
, 1, modifier
);
7849 if (modifier
!= EXPAND_CONST_ADDRESS
7850 && modifier
!= EXPAND_INITIALIZER
7851 && modifier
!= EXPAND_SUM
)
7852 constructor
= validize_mem (constructor
);
7857 /* Handle calls that pass values in multiple non-contiguous
7858 locations. The Irix 6 ABI has examples of this. */
7859 if (target
== 0 || ! safe_from_p (target
, exp
, 1)
7860 || GET_CODE (target
) == PARALLEL
|| modifier
== EXPAND_STACK_PARM
)
7865 target
= assign_temp (type
, TREE_ADDRESSABLE (exp
), 1);
7868 store_constructor (exp
, target
, 0, int_expr_size (exp
), false);
7873 /* expand_expr: generate code for computing expression EXP.
7874 An rtx for the computed value is returned. The value is never null.
7875 In the case of a void EXP, const0_rtx is returned.
7877 The value may be stored in TARGET if TARGET is nonzero.
7878 TARGET is just a suggestion; callers must assume that
7879 the rtx returned may not be the same as TARGET.
7881 If TARGET is CONST0_RTX, it means that the value will be ignored.
7883 If TMODE is not VOIDmode, it suggests generating the
7884 result in mode TMODE. But this is done only when convenient.
7885 Otherwise, TMODE is ignored and the value generated in its natural mode.
7886 TMODE is just a suggestion; callers must assume that
7887 the rtx returned may not have mode TMODE.
7889 Note that TARGET may have neither TMODE nor MODE. In that case, it
7890 probably will not be used.
7892 If MODIFIER is EXPAND_SUM then when EXP is an addition
7893 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
7894 or a nest of (PLUS ...) and (MINUS ...) where the terms are
7895 products as above, or REG or MEM, or constant.
7896 Ordinarily in such cases we would output mul or add instructions
7897 and then return a pseudo reg containing the sum.
7899 EXPAND_INITIALIZER is much like EXPAND_SUM except that
7900 it also marks a label as absolutely required (it can't be dead).
7901 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
7902 This is used for outputting expressions used in initializers.
7904 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
7905 with a constant address even if that address is not normally legitimate.
7906 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
7908 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
7909 a call parameter. Such targets require special care as we haven't yet
7910 marked TARGET so that it's safe from being trashed by libcalls. We
7911 don't want to use TARGET for anything but the final result;
7912 Intermediate values must go elsewhere. Additionally, calls to
7913 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
7915 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
7916 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
7917 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
7918 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
7921 If INNER_REFERENCE_P is true, we are expanding an inner reference.
7922 In this case, we don't adjust a returned MEM rtx that wouldn't be
7923 sufficiently aligned for its mode; instead, it's up to the caller
7924 to deal with it afterwards. This is used to make sure that unaligned
7925 base objects for which out-of-bounds accesses are supported, for
7926 example record types with trailing arrays, aren't realigned behind
7927 the back of the caller.
7928 The normal operating mode is to pass FALSE for this parameter. */
7931 expand_expr_real (tree exp
, rtx target
, machine_mode tmode
,
7932 enum expand_modifier modifier
, rtx
*alt_rtl
,
7933 bool inner_reference_p
)
7937 /* Handle ERROR_MARK before anybody tries to access its type. */
7938 if (TREE_CODE (exp
) == ERROR_MARK
7939 || (TREE_CODE (TREE_TYPE (exp
)) == ERROR_MARK
))
7941 ret
= CONST0_RTX (tmode
);
7942 return ret
? ret
: const0_rtx
;
7945 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
,
7950 /* Try to expand the conditional expression which is represented by
7951 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If it succeeds
7952 return the rtl reg which represents the result. Otherwise return
7956 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED
,
7957 tree treeop1 ATTRIBUTE_UNUSED
,
7958 tree treeop2 ATTRIBUTE_UNUSED
)
7961 rtx op00
, op01
, op1
, op2
;
7962 enum rtx_code comparison_code
;
7963 machine_mode comparison_mode
;
7966 tree type
= TREE_TYPE (treeop1
);
7967 int unsignedp
= TYPE_UNSIGNED (type
);
7968 machine_mode mode
= TYPE_MODE (type
);
7969 machine_mode orig_mode
= mode
;
7971 /* If we cannot do a conditional move on the mode, try doing it
7972 with the promoted mode. */
7973 if (!can_conditionally_move_p (mode
))
7975 mode
= promote_mode (type
, mode
, &unsignedp
);
7976 if (!can_conditionally_move_p (mode
))
7978 temp
= assign_temp (type
, 0, 0); /* Use promoted mode for temp. */
7981 temp
= assign_temp (type
, 0, 1);
7984 expand_operands (treeop1
, treeop2
,
7985 temp
, &op1
, &op2
, EXPAND_NORMAL
);
7987 if (TREE_CODE (treeop0
) == SSA_NAME
7988 && (srcstmt
= get_def_for_expr_class (treeop0
, tcc_comparison
)))
7990 tree type
= TREE_TYPE (gimple_assign_rhs1 (srcstmt
));
7991 enum tree_code cmpcode
= gimple_assign_rhs_code (srcstmt
);
7992 op00
= expand_normal (gimple_assign_rhs1 (srcstmt
));
7993 op01
= expand_normal (gimple_assign_rhs2 (srcstmt
));
7994 comparison_mode
= TYPE_MODE (type
);
7995 unsignedp
= TYPE_UNSIGNED (type
);
7996 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
7998 else if (COMPARISON_CLASS_P (treeop0
))
8000 tree type
= TREE_TYPE (TREE_OPERAND (treeop0
, 0));
8001 enum tree_code cmpcode
= TREE_CODE (treeop0
);
8002 op00
= expand_normal (TREE_OPERAND (treeop0
, 0));
8003 op01
= expand_normal (TREE_OPERAND (treeop0
, 1));
8004 unsignedp
= TYPE_UNSIGNED (type
);
8005 comparison_mode
= TYPE_MODE (type
);
8006 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
8010 op00
= expand_normal (treeop0
);
8012 comparison_code
= NE
;
8013 comparison_mode
= GET_MODE (op00
);
8014 if (comparison_mode
== VOIDmode
)
8015 comparison_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
8018 if (GET_MODE (op1
) != mode
)
8019 op1
= gen_lowpart (mode
, op1
);
8021 if (GET_MODE (op2
) != mode
)
8022 op2
= gen_lowpart (mode
, op2
);
8024 /* Try to emit the conditional move. */
8025 insn
= emit_conditional_move (temp
, comparison_code
,
8026 op00
, op01
, comparison_mode
,
8030 /* If we could do the conditional move, emit the sequence,
8034 rtx_insn
*seq
= get_insns ();
8037 return convert_modes (orig_mode
, mode
, temp
, 0);
8040 /* Otherwise discard the sequence and fall back to code with
8047 expand_expr_real_2 (sepops ops
, rtx target
, machine_mode tmode
,
8048 enum expand_modifier modifier
)
8050 rtx op0
, op1
, op2
, temp
;
8051 rtx_code_label
*lab
;
8055 enum tree_code code
= ops
->code
;
8057 rtx subtarget
, original_target
;
8059 bool reduce_bit_field
;
8060 location_t loc
= ops
->location
;
8061 tree treeop0
, treeop1
, treeop2
;
8062 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
8063 ? reduce_to_bit_field_precision ((expr), \
8069 mode
= TYPE_MODE (type
);
8070 unsignedp
= TYPE_UNSIGNED (type
);
8076 /* We should be called only on simple (binary or unary) expressions,
8077 exactly those that are valid in gimple expressions that aren't
8078 GIMPLE_SINGLE_RHS (or invalid). */
8079 gcc_assert (get_gimple_rhs_class (code
) == GIMPLE_UNARY_RHS
8080 || get_gimple_rhs_class (code
) == GIMPLE_BINARY_RHS
8081 || get_gimple_rhs_class (code
) == GIMPLE_TERNARY_RHS
);
8083 ignore
= (target
== const0_rtx
8084 || ((CONVERT_EXPR_CODE_P (code
)
8085 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
8086 && TREE_CODE (type
) == VOID_TYPE
));
8088 /* We should be called only if we need the result. */
8089 gcc_assert (!ignore
);
8091 /* An operation in what may be a bit-field type needs the
8092 result to be reduced to the precision of the bit-field type,
8093 which is narrower than that of the type's mode. */
8094 reduce_bit_field
= (INTEGRAL_TYPE_P (type
)
8095 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
8097 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
8100 /* Use subtarget as the target for operand 0 of a binary operation. */
8101 subtarget
= get_subtarget (target
);
8102 original_target
= target
;
8106 case NON_LVALUE_EXPR
:
8109 if (treeop0
== error_mark_node
)
8112 if (TREE_CODE (type
) == UNION_TYPE
)
8114 tree valtype
= TREE_TYPE (treeop0
);
8116 /* If both input and output are BLKmode, this conversion isn't doing
8117 anything except possibly changing memory attribute. */
8118 if (mode
== BLKmode
&& TYPE_MODE (valtype
) == BLKmode
)
8120 rtx result
= expand_expr (treeop0
, target
, tmode
,
8123 result
= copy_rtx (result
);
8124 set_mem_attributes (result
, type
, 0);
8130 if (TYPE_MODE (type
) != BLKmode
)
8131 target
= gen_reg_rtx (TYPE_MODE (type
));
8133 target
= assign_temp (type
, 1, 1);
8137 /* Store data into beginning of memory target. */
8138 store_expr (treeop0
,
8139 adjust_address (target
, TYPE_MODE (valtype
), 0),
8140 modifier
== EXPAND_STACK_PARM
,
8141 false, TYPE_REVERSE_STORAGE_ORDER (type
));
8145 gcc_assert (REG_P (target
)
8146 && !TYPE_REVERSE_STORAGE_ORDER (type
));
8148 /* Store this field into a union of the proper type. */
8149 store_field (target
,
8150 MIN ((int_size_in_bytes (TREE_TYPE
8153 (HOST_WIDE_INT
) GET_MODE_BITSIZE (mode
)),
8154 0, 0, 0, TYPE_MODE (valtype
), treeop0
, 0,
8158 /* Return the entire union. */
8162 if (mode
== TYPE_MODE (TREE_TYPE (treeop0
)))
8164 op0
= expand_expr (treeop0
, target
, VOIDmode
,
8167 /* If the signedness of the conversion differs and OP0 is
8168 a promoted SUBREG, clear that indication since we now
8169 have to do the proper extension. */
8170 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)) != unsignedp
8171 && GET_CODE (op0
) == SUBREG
)
8172 SUBREG_PROMOTED_VAR_P (op0
) = 0;
8174 return REDUCE_BIT_FIELD (op0
);
8177 op0
= expand_expr (treeop0
, NULL_RTX
, mode
,
8178 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
8179 if (GET_MODE (op0
) == mode
)
8182 /* If OP0 is a constant, just convert it into the proper mode. */
8183 else if (CONSTANT_P (op0
))
8185 tree inner_type
= TREE_TYPE (treeop0
);
8186 machine_mode inner_mode
= GET_MODE (op0
);
8188 if (inner_mode
== VOIDmode
)
8189 inner_mode
= TYPE_MODE (inner_type
);
8191 if (modifier
== EXPAND_INITIALIZER
)
8192 op0
= lowpart_subreg (mode
, op0
, inner_mode
);
8194 op0
= convert_modes (mode
, inner_mode
, op0
,
8195 TYPE_UNSIGNED (inner_type
));
8198 else if (modifier
== EXPAND_INITIALIZER
)
8199 op0
= gen_rtx_fmt_e (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
);
8201 else if (target
== 0)
8202 op0
= convert_to_mode (mode
, op0
,
8203 TYPE_UNSIGNED (TREE_TYPE
8207 convert_move (target
, op0
,
8208 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8212 return REDUCE_BIT_FIELD (op0
);
8214 case ADDR_SPACE_CONVERT_EXPR
:
8216 tree treeop0_type
= TREE_TYPE (treeop0
);
8218 gcc_assert (POINTER_TYPE_P (type
));
8219 gcc_assert (POINTER_TYPE_P (treeop0_type
));
8221 addr_space_t as_to
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
8222 addr_space_t as_from
= TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type
));
8224 /* Conversions between pointers to the same address space should
8225 have been implemented via CONVERT_EXPR / NOP_EXPR. */
8226 gcc_assert (as_to
!= as_from
);
8228 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
8230 /* Ask target code to handle conversion between pointers
8231 to overlapping address spaces. */
8232 if (targetm
.addr_space
.subset_p (as_to
, as_from
)
8233 || targetm
.addr_space
.subset_p (as_from
, as_to
))
8235 op0
= targetm
.addr_space
.convert (op0
, treeop0_type
, type
);
8239 /* For disjoint address spaces, converting anything but a null
8240 pointer invokes undefined behaviour. We truncate or extend the
8241 value as if we'd converted via integers, which handles 0 as
8242 required, and all others as the programmer likely expects. */
8243 #ifndef POINTERS_EXTEND_UNSIGNED
8244 const int POINTERS_EXTEND_UNSIGNED
= 1;
8246 op0
= convert_modes (mode
, TYPE_MODE (treeop0_type
),
8247 op0
, POINTERS_EXTEND_UNSIGNED
);
8253 case POINTER_PLUS_EXPR
:
8254 /* Even though the sizetype mode and the pointer's mode can be different
8255 expand is able to handle this correctly and get the correct result out
8256 of the PLUS_EXPR code. */
8257 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
8258 if sizetype precision is smaller than pointer precision. */
8259 if (TYPE_PRECISION (sizetype
) < TYPE_PRECISION (type
))
8260 treeop1
= fold_convert_loc (loc
, type
,
8261 fold_convert_loc (loc
, ssizetype
,
8263 /* If sizetype precision is larger than pointer precision, truncate the
8264 offset to have matching modes. */
8265 else if (TYPE_PRECISION (sizetype
) > TYPE_PRECISION (type
))
8266 treeop1
= fold_convert_loc (loc
, type
, treeop1
);
8269 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
8270 something else, make sure we add the register to the constant and
8271 then to the other thing. This case can occur during strength
8272 reduction and doing it this way will produce better code if the
8273 frame pointer or argument pointer is eliminated.
8275 fold-const.c will ensure that the constant is always in the inner
8276 PLUS_EXPR, so the only case we need to do anything about is if
8277 sp, ap, or fp is our second argument, in which case we must swap
8278 the innermost first argument and our second argument. */
8280 if (TREE_CODE (treeop0
) == PLUS_EXPR
8281 && TREE_CODE (TREE_OPERAND (treeop0
, 1)) == INTEGER_CST
8282 && TREE_CODE (treeop1
) == VAR_DECL
8283 && (DECL_RTL (treeop1
) == frame_pointer_rtx
8284 || DECL_RTL (treeop1
) == stack_pointer_rtx
8285 || DECL_RTL (treeop1
) == arg_pointer_rtx
))
8290 /* If the result is to be ptr_mode and we are adding an integer to
8291 something, we might be forming a constant. So try to use
8292 plus_constant. If it produces a sum and we can't accept it,
8293 use force_operand. This allows P = &ARR[const] to generate
8294 efficient code on machines where a SYMBOL_REF is not a valid
8297 If this is an EXPAND_SUM call, always return the sum. */
8298 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
8299 || (mode
== ptr_mode
&& (unsignedp
|| ! flag_trapv
)))
8301 if (modifier
== EXPAND_STACK_PARM
)
8303 if (TREE_CODE (treeop0
) == INTEGER_CST
8304 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8305 && TREE_CONSTANT (treeop1
))
8309 machine_mode wmode
= TYPE_MODE (TREE_TYPE (treeop1
));
8311 op1
= expand_expr (treeop1
, subtarget
, VOIDmode
,
8313 /* Use wi::shwi to ensure that the constant is
8314 truncated according to the mode of OP1, then sign extended
8315 to a HOST_WIDE_INT. Using the constant directly can result
8316 in non-canonical RTL in a 64x32 cross compile. */
8317 wc
= TREE_INT_CST_LOW (treeop0
);
8319 immed_wide_int_const (wi::shwi (wc
, wmode
), wmode
);
8320 op1
= plus_constant (mode
, op1
, INTVAL (constant_part
));
8321 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8322 op1
= force_operand (op1
, target
);
8323 return REDUCE_BIT_FIELD (op1
);
8326 else if (TREE_CODE (treeop1
) == INTEGER_CST
8327 && GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
8328 && TREE_CONSTANT (treeop0
))
8332 machine_mode wmode
= TYPE_MODE (TREE_TYPE (treeop0
));
8334 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8335 (modifier
== EXPAND_INITIALIZER
8336 ? EXPAND_INITIALIZER
: EXPAND_SUM
));
8337 if (! CONSTANT_P (op0
))
8339 op1
= expand_expr (treeop1
, NULL_RTX
,
8340 VOIDmode
, modifier
);
8341 /* Return a PLUS if modifier says it's OK. */
8342 if (modifier
== EXPAND_SUM
8343 || modifier
== EXPAND_INITIALIZER
)
8344 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
8347 /* Use wi::shwi to ensure that the constant is
8348 truncated according to the mode of OP1, then sign extended
8349 to a HOST_WIDE_INT. Using the constant directly can result
8350 in non-canonical RTL in a 64x32 cross compile. */
8351 wc
= TREE_INT_CST_LOW (treeop1
);
8353 = immed_wide_int_const (wi::shwi (wc
, wmode
), wmode
);
8354 op0
= plus_constant (mode
, op0
, INTVAL (constant_part
));
8355 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8356 op0
= force_operand (op0
, target
);
8357 return REDUCE_BIT_FIELD (op0
);
8361 /* Use TER to expand pointer addition of a negated value
8362 as pointer subtraction. */
8363 if ((POINTER_TYPE_P (TREE_TYPE (treeop0
))
8364 || (TREE_CODE (TREE_TYPE (treeop0
)) == VECTOR_TYPE
8365 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0
)))))
8366 && TREE_CODE (treeop1
) == SSA_NAME
8367 && TYPE_MODE (TREE_TYPE (treeop0
))
8368 == TYPE_MODE (TREE_TYPE (treeop1
)))
8370 gimple
*def
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8373 treeop1
= gimple_assign_rhs1 (def
);
8379 /* No sense saving up arithmetic to be done
8380 if it's all in the wrong mode to form part of an address.
8381 And force_operand won't know whether to sign-extend or
8383 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8384 || mode
!= ptr_mode
)
8386 expand_operands (treeop0
, treeop1
,
8387 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8388 if (op0
== const0_rtx
)
8390 if (op1
== const0_rtx
)
8395 expand_operands (treeop0
, treeop1
,
8396 subtarget
, &op0
, &op1
, modifier
);
8397 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8401 /* For initializers, we are allowed to return a MINUS of two
8402 symbolic constants. Here we handle all cases when both operands
8404 /* Handle difference of two symbolic constants,
8405 for the sake of an initializer. */
8406 if ((modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
8407 && really_constant_p (treeop0
)
8408 && really_constant_p (treeop1
))
8410 expand_operands (treeop0
, treeop1
,
8411 NULL_RTX
, &op0
, &op1
, modifier
);
8413 /* If the last operand is a CONST_INT, use plus_constant of
8414 the negated constant. Else make the MINUS. */
8415 if (CONST_INT_P (op1
))
8416 return REDUCE_BIT_FIELD (plus_constant (mode
, op0
,
8419 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode
, op0
, op1
));
8422 /* No sense saving up arithmetic to be done
8423 if it's all in the wrong mode to form part of an address.
8424 And force_operand won't know whether to sign-extend or
8426 if ((modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
8427 || mode
!= ptr_mode
)
8430 expand_operands (treeop0
, treeop1
,
8431 subtarget
, &op0
, &op1
, modifier
);
8433 /* Convert A - const to A + (-const). */
8434 if (CONST_INT_P (op1
))
8436 op1
= negate_rtx (mode
, op1
);
8437 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
8442 case WIDEN_MULT_PLUS_EXPR
:
8443 case WIDEN_MULT_MINUS_EXPR
:
8444 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
8445 op2
= expand_normal (treeop2
);
8446 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
8450 case WIDEN_MULT_EXPR
:
8451 /* If first operand is constant, swap them.
8452 Thus the following special case checks need only
8453 check the second operand. */
8454 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8455 std::swap (treeop0
, treeop1
);
8457 /* First, check if we have a multiplication of one signed and one
8458 unsigned operand. */
8459 if (TREE_CODE (treeop1
) != INTEGER_CST
8460 && (TYPE_UNSIGNED (TREE_TYPE (treeop0
))
8461 != TYPE_UNSIGNED (TREE_TYPE (treeop1
))))
8463 machine_mode innermode
= TYPE_MODE (TREE_TYPE (treeop0
));
8464 this_optab
= usmul_widen_optab
;
8465 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8466 != CODE_FOR_nothing
)
8468 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8469 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8472 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op1
, &op0
,
8474 /* op0 and op1 might still be constant, despite the above
8475 != INTEGER_CST check. Handle it. */
8476 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8478 op0
= convert_modes (innermode
, mode
, op0
, true);
8479 op1
= convert_modes (innermode
, mode
, op1
, false);
8480 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8481 target
, unsignedp
));
8486 /* Check for a multiplication with matching signedness. */
8487 else if ((TREE_CODE (treeop1
) == INTEGER_CST
8488 && int_fits_type_p (treeop1
, TREE_TYPE (treeop0
)))
8489 || (TYPE_UNSIGNED (TREE_TYPE (treeop1
))
8490 == TYPE_UNSIGNED (TREE_TYPE (treeop0
))))
8492 tree op0type
= TREE_TYPE (treeop0
);
8493 machine_mode innermode
= TYPE_MODE (op0type
);
8494 bool zextend_p
= TYPE_UNSIGNED (op0type
);
8495 optab other_optab
= zextend_p
? smul_widen_optab
: umul_widen_optab
;
8496 this_optab
= zextend_p
? umul_widen_optab
: smul_widen_optab
;
8498 if (TREE_CODE (treeop0
) != INTEGER_CST
)
8500 if (find_widening_optab_handler (this_optab
, mode
, innermode
, 0)
8501 != CODE_FOR_nothing
)
8503 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
8505 /* op0 and op1 might still be constant, despite the above
8506 != INTEGER_CST check. Handle it. */
8507 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8510 op0
= convert_modes (innermode
, mode
, op0
, zextend_p
);
8512 = convert_modes (innermode
, mode
, op1
,
8513 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8514 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
8518 temp
= expand_widening_mult (mode
, op0
, op1
, target
,
8519 unsignedp
, this_optab
);
8520 return REDUCE_BIT_FIELD (temp
);
8522 if (find_widening_optab_handler (other_optab
, mode
, innermode
, 0)
8524 && innermode
== word_mode
)
8527 op0
= expand_normal (treeop0
);
8528 if (TREE_CODE (treeop1
) == INTEGER_CST
)
8529 op1
= convert_modes (innermode
, mode
,
8530 expand_normal (treeop1
),
8531 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
8533 op1
= expand_normal (treeop1
);
8534 /* op0 and op1 might still be constant, despite the above
8535 != INTEGER_CST check. Handle it. */
8536 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
8537 goto widen_mult_const
;
8538 temp
= expand_binop (mode
, other_optab
, op0
, op1
, target
,
8539 unsignedp
, OPTAB_LIB_WIDEN
);
8540 hipart
= gen_highpart (innermode
, temp
);
8541 htem
= expand_mult_highpart_adjust (innermode
, hipart
,
8545 emit_move_insn (hipart
, htem
);
8546 return REDUCE_BIT_FIELD (temp
);
8550 treeop0
= fold_build1 (CONVERT_EXPR
, type
, treeop0
);
8551 treeop1
= fold_build1 (CONVERT_EXPR
, type
, treeop1
);
8552 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8553 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8557 optab opt
= fma_optab
;
8558 gimple
*def0
, *def2
;
8560 /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
8562 if (optab_handler (fma_optab
, mode
) == CODE_FOR_nothing
)
8564 tree fn
= mathfn_built_in (TREE_TYPE (treeop0
), BUILT_IN_FMA
);
8567 gcc_assert (fn
!= NULL_TREE
);
8568 call_expr
= build_call_expr (fn
, 3, treeop0
, treeop1
, treeop2
);
8569 return expand_builtin (call_expr
, target
, subtarget
, mode
, false);
8572 def0
= get_def_for_expr (treeop0
, NEGATE_EXPR
);
8573 /* The multiplication is commutative - look at its 2nd operand
8574 if the first isn't fed by a negate. */
8577 def0
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
8578 /* Swap operands if the 2nd operand is fed by a negate. */
8580 std::swap (treeop0
, treeop1
);
8582 def2
= get_def_for_expr (treeop2
, NEGATE_EXPR
);
8587 && optab_handler (fnms_optab
, mode
) != CODE_FOR_nothing
)
8590 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8591 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8594 && optab_handler (fnma_optab
, mode
) != CODE_FOR_nothing
)
8597 op0
= expand_normal (gimple_assign_rhs1 (def0
));
8600 && optab_handler (fms_optab
, mode
) != CODE_FOR_nothing
)
8603 op2
= expand_normal (gimple_assign_rhs1 (def2
));
8607 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
, EXPAND_NORMAL
);
8609 op2
= expand_normal (treeop2
);
8610 op1
= expand_normal (treeop1
);
8612 return expand_ternary_op (TYPE_MODE (type
), opt
,
8613 op0
, op1
, op2
, target
, 0);
8617 /* If this is a fixed-point operation, then we cannot use the code
8618 below because "expand_mult" doesn't support sat/no-sat fixed-point
8620 if (ALL_FIXED_POINT_MODE_P (mode
))
8623 /* If first operand is constant, swap them.
8624 Thus the following special case checks need only
8625 check the second operand. */
8626 if (TREE_CODE (treeop0
) == INTEGER_CST
)
8627 std::swap (treeop0
, treeop1
);
8629 /* Attempt to return something suitable for generating an
8630 indexed address, for machines that support that. */
8632 if (modifier
== EXPAND_SUM
&& mode
== ptr_mode
8633 && tree_fits_shwi_p (treeop1
))
8635 tree exp1
= treeop1
;
8637 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
8641 op0
= force_operand (op0
, NULL_RTX
);
8643 op0
= copy_to_mode_reg (mode
, op0
);
8645 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode
, op0
,
8646 gen_int_mode (tree_to_shwi (exp1
),
8647 TYPE_MODE (TREE_TYPE (exp1
)))));
8650 if (modifier
== EXPAND_STACK_PARM
)
8653 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8654 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
8656 case TRUNC_DIV_EXPR
:
8657 case FLOOR_DIV_EXPR
:
8659 case ROUND_DIV_EXPR
:
8660 case EXACT_DIV_EXPR
:
8661 /* If this is a fixed-point operation, then we cannot use the code
8662 below because "expand_divmod" doesn't support sat/no-sat fixed-point
8664 if (ALL_FIXED_POINT_MODE_P (mode
))
8667 if (modifier
== EXPAND_STACK_PARM
)
8669 /* Possible optimization: compute the dividend with EXPAND_SUM
8670 then if the divisor is constant can optimize the case
8671 where some terms of the dividend have coeffs divisible by it. */
8672 expand_operands (treeop0
, treeop1
,
8673 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8674 return expand_divmod (0, code
, mode
, op0
, op1
, target
, unsignedp
);
8679 case MULT_HIGHPART_EXPR
:
8680 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8681 temp
= expand_mult_highpart (mode
, op0
, op1
, target
, unsignedp
);
8685 case TRUNC_MOD_EXPR
:
8686 case FLOOR_MOD_EXPR
:
8688 case ROUND_MOD_EXPR
:
8689 if (modifier
== EXPAND_STACK_PARM
)
8691 expand_operands (treeop0
, treeop1
,
8692 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
8693 return expand_divmod (1, code
, mode
, op0
, op1
, target
, unsignedp
);
8695 case FIXED_CONVERT_EXPR
:
8696 op0
= expand_normal (treeop0
);
8697 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8698 target
= gen_reg_rtx (mode
);
8700 if ((TREE_CODE (TREE_TYPE (treeop0
)) == INTEGER_TYPE
8701 && TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
8702 || (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
)))
8703 expand_fixed_convert (target
, op0
, 1, TYPE_SATURATING (type
));
8705 expand_fixed_convert (target
, op0
, 0, TYPE_SATURATING (type
));
8708 case FIX_TRUNC_EXPR
:
8709 op0
= expand_normal (treeop0
);
8710 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8711 target
= gen_reg_rtx (mode
);
8712 expand_fix (target
, op0
, unsignedp
);
8716 op0
= expand_normal (treeop0
);
8717 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
8718 target
= gen_reg_rtx (mode
);
8719 /* expand_float can't figure out what to do if FROM has VOIDmode.
8720 So give it the correct mode. With -O, cse will optimize this. */
8721 if (GET_MODE (op0
) == VOIDmode
)
8722 op0
= copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0
)),
8724 expand_float (target
, op0
,
8725 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
8729 op0
= expand_expr (treeop0
, subtarget
,
8730 VOIDmode
, EXPAND_NORMAL
);
8731 if (modifier
== EXPAND_STACK_PARM
)
8733 temp
= expand_unop (mode
,
8734 optab_for_tree_code (NEGATE_EXPR
, type
,
8738 return REDUCE_BIT_FIELD (temp
);
8741 op0
= expand_expr (treeop0
, subtarget
,
8742 VOIDmode
, EXPAND_NORMAL
);
8743 if (modifier
== EXPAND_STACK_PARM
)
8746 /* ABS_EXPR is not valid for complex arguments. */
8747 gcc_assert (GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
8748 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
);
8750 /* Unsigned abs is simply the operand. Testing here means we don't
8751 risk generating incorrect code below. */
8752 if (TYPE_UNSIGNED (type
))
8755 return expand_abs (mode
, op0
, target
, unsignedp
,
8756 safe_from_p (target
, treeop0
, 1));
8760 target
= original_target
;
8762 || modifier
== EXPAND_STACK_PARM
8763 || (MEM_P (target
) && MEM_VOLATILE_P (target
))
8764 || GET_MODE (target
) != mode
8766 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
8767 target
= gen_reg_rtx (mode
);
8768 expand_operands (treeop0
, treeop1
,
8769 target
, &op0
, &op1
, EXPAND_NORMAL
);
8771 /* First try to do it with a special MIN or MAX instruction.
8772 If that does not win, use a conditional jump to select the proper
8774 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
8775 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
, unsignedp
,
8780 /* At this point, a MEM target is no longer useful; we will get better
8783 if (! REG_P (target
))
8784 target
= gen_reg_rtx (mode
);
8786 /* If op1 was placed in target, swap op0 and op1. */
8787 if (target
!= op0
&& target
== op1
)
8788 std::swap (op0
, op1
);
8790 /* We generate better code and avoid problems with op1 mentioning
8791 target by forcing op1 into a pseudo if it isn't a constant. */
8792 if (! CONSTANT_P (op1
))
8793 op1
= force_reg (mode
, op1
);
8796 enum rtx_code comparison_code
;
8799 if (code
== MAX_EXPR
)
8800 comparison_code
= unsignedp
? GEU
: GE
;
8802 comparison_code
= unsignedp
? LEU
: LE
;
8804 /* Canonicalize to comparisons against 0. */
8805 if (op1
== const1_rtx
)
8807 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8808 or (a != 0 ? a : 1) for unsigned.
8809 For MIN we are safe converting (a <= 1 ? a : 1)
8810 into (a <= 0 ? a : 1) */
8811 cmpop1
= const0_rtx
;
8812 if (code
== MAX_EXPR
)
8813 comparison_code
= unsignedp
? NE
: GT
;
8815 if (op1
== constm1_rtx
&& !unsignedp
)
8817 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8818 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8819 cmpop1
= const0_rtx
;
8820 if (code
== MIN_EXPR
)
8821 comparison_code
= LT
;
8824 /* Use a conditional move if possible. */
8825 if (can_conditionally_move_p (mode
))
8831 /* Try to emit the conditional move. */
8832 insn
= emit_conditional_move (target
, comparison_code
,
8837 /* If we could do the conditional move, emit the sequence,
8841 rtx_insn
*seq
= get_insns ();
8847 /* Otherwise discard the sequence and fall back to code with
8853 emit_move_insn (target
, op0
);
8855 lab
= gen_label_rtx ();
8856 do_compare_rtx_and_jump (target
, cmpop1
, comparison_code
,
8857 unsignedp
, mode
, NULL_RTX
, NULL
, lab
,
8860 emit_move_insn (target
, op1
);
8865 op0
= expand_expr (treeop0
, subtarget
,
8866 VOIDmode
, EXPAND_NORMAL
);
8867 if (modifier
== EXPAND_STACK_PARM
)
8869 /* In case we have to reduce the result to bitfield precision
8870 for unsigned bitfield expand this as XOR with a proper constant
8872 if (reduce_bit_field
&& TYPE_UNSIGNED (type
))
8874 wide_int mask
= wi::mask (TYPE_PRECISION (type
),
8875 false, GET_MODE_PRECISION (mode
));
8877 temp
= expand_binop (mode
, xor_optab
, op0
,
8878 immed_wide_int_const (mask
, mode
),
8879 target
, 1, OPTAB_LIB_WIDEN
);
8882 temp
= expand_unop (mode
, one_cmpl_optab
, op0
, target
, 1);
8886 /* ??? Can optimize bitwise operations with one arg constant.
8887 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8888 and (a bitwise1 b) bitwise2 b (etc)
8889 but that is probably not worth while. */
8898 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type
))
8899 || (GET_MODE_PRECISION (TYPE_MODE (type
))
8900 == TYPE_PRECISION (type
)));
8906 /* If this is a fixed-point operation, then we cannot use the code
8907 below because "expand_shift" doesn't support sat/no-sat fixed-point
8909 if (ALL_FIXED_POINT_MODE_P (mode
))
8912 if (! safe_from_p (subtarget
, treeop1
, 1))
8914 if (modifier
== EXPAND_STACK_PARM
)
8916 op0
= expand_expr (treeop0
, subtarget
,
8917 VOIDmode
, EXPAND_NORMAL
);
8919 /* Left shift optimization when shifting across word_size boundary.
8921 If mode == GET_MODE_WIDER_MODE (word_mode), then normally there isn't
8922 native instruction to support this wide mode left shift. Given below
8925 Type A = (Type) B << C
8928 | dest_high | dest_low |
8932 If the shift amount C caused we shift B to across the word size
8933 boundary, i.e part of B shifted into high half of destination
8934 register, and part of B remains in the low half, then GCC will use
8935 the following left shift expand logic:
8937 1. Initialize dest_low to B.
8938 2. Initialize every bit of dest_high to the sign bit of B.
8939 3. Logic left shift dest_low by C bit to finalize dest_low.
8940 The value of dest_low before this shift is kept in a temp D.
8941 4. Logic left shift dest_high by C.
8942 5. Logic right shift D by (word_size - C).
8943 6. Or the result of 4 and 5 to finalize dest_high.
8945 While, by checking gimple statements, if operand B is coming from
8946 signed extension, then we can simplify above expand logic into:
8948 1. dest_high = src_low >> (word_size - C).
8949 2. dest_low = src_low << C.
8951 We can use one arithmetic right shift to finish all the purpose of
8952 steps 2, 4, 5, 6, thus we reduce the steps needed from 6 into 2. */
8955 if (code
== LSHIFT_EXPR
8959 && mode
== GET_MODE_WIDER_MODE (word_mode
)
8960 && GET_MODE_SIZE (mode
) == 2 * GET_MODE_SIZE (word_mode
)
8961 && TREE_CONSTANT (treeop1
)
8962 && TREE_CODE (treeop0
) == SSA_NAME
)
8964 gimple
*def
= SSA_NAME_DEF_STMT (treeop0
);
8965 if (is_gimple_assign (def
)
8966 && gimple_assign_rhs_code (def
) == NOP_EXPR
)
8968 machine_mode rmode
= TYPE_MODE
8969 (TREE_TYPE (gimple_assign_rhs1 (def
)));
8971 if (GET_MODE_SIZE (rmode
) < GET_MODE_SIZE (mode
)
8972 && TREE_INT_CST_LOW (treeop1
) < GET_MODE_BITSIZE (word_mode
)
8973 && ((TREE_INT_CST_LOW (treeop1
) + GET_MODE_BITSIZE (rmode
))
8974 >= GET_MODE_BITSIZE (word_mode
)))
8976 rtx_insn
*seq
, *seq_old
;
8977 unsigned int high_off
= subreg_highpart_offset (word_mode
,
8979 rtx low
= lowpart_subreg (word_mode
, op0
, mode
);
8980 rtx dest_low
= lowpart_subreg (word_mode
, target
, mode
);
8981 rtx dest_high
= simplify_gen_subreg (word_mode
, target
,
8983 HOST_WIDE_INT ramount
= (BITS_PER_WORD
8984 - TREE_INT_CST_LOW (treeop1
));
8985 tree rshift
= build_int_cst (TREE_TYPE (treeop1
), ramount
);
8988 /* dest_high = src_low >> (word_size - C). */
8989 temp
= expand_variable_shift (RSHIFT_EXPR
, word_mode
, low
,
8990 rshift
, dest_high
, unsignedp
);
8991 if (temp
!= dest_high
)
8992 emit_move_insn (dest_high
, temp
);
8994 /* dest_low = src_low << C. */
8995 temp
= expand_variable_shift (LSHIFT_EXPR
, word_mode
, low
,
8996 treeop1
, dest_low
, unsignedp
);
8997 if (temp
!= dest_low
)
8998 emit_move_insn (dest_low
, temp
);
9004 if (have_insn_for (ASHIFT
, mode
))
9006 bool speed_p
= optimize_insn_for_speed_p ();
9008 rtx ret_old
= expand_variable_shift (code
, mode
, op0
,
9012 seq_old
= get_insns ();
9014 if (seq_cost (seq
, speed_p
)
9015 >= seq_cost (seq_old
, speed_p
))
9026 if (temp
== NULL_RTX
)
9027 temp
= expand_variable_shift (code
, mode
, op0
, treeop1
, target
,
9029 if (code
== LSHIFT_EXPR
)
9030 temp
= REDUCE_BIT_FIELD (temp
);
9034 /* Could determine the answer when only additive constants differ. Also,
9035 the addition of one can be handled by changing the condition. */
9042 case UNORDERED_EXPR
:
9051 temp
= do_store_flag (ops
,
9052 modifier
!= EXPAND_STACK_PARM
? target
: NULL_RTX
,
9053 tmode
!= VOIDmode
? tmode
: mode
);
9057 /* Use a compare and a jump for BLKmode comparisons, or for function
9058 type comparisons is have_canonicalize_funcptr_for_compare. */
9061 || modifier
== EXPAND_STACK_PARM
9062 || ! safe_from_p (target
, treeop0
, 1)
9063 || ! safe_from_p (target
, treeop1
, 1)
9064 /* Make sure we don't have a hard reg (such as function's return
9065 value) live across basic blocks, if not optimizing. */
9066 || (!optimize
&& REG_P (target
)
9067 && REGNO (target
) < FIRST_PSEUDO_REGISTER
)))
9068 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
9070 emit_move_insn (target
, const0_rtx
);
9072 rtx_code_label
*lab1
= gen_label_rtx ();
9073 jumpifnot_1 (code
, treeop0
, treeop1
, lab1
, -1);
9075 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
9076 emit_move_insn (target
, constm1_rtx
);
9078 emit_move_insn (target
, const1_rtx
);
9084 /* Get the rtx code of the operands. */
9085 op0
= expand_normal (treeop0
);
9086 op1
= expand_normal (treeop1
);
9089 target
= gen_reg_rtx (TYPE_MODE (type
));
9091 /* If target overlaps with op1, then either we need to force
9092 op1 into a pseudo (if target also overlaps with op0),
9093 or write the complex parts in reverse order. */
9094 switch (GET_CODE (target
))
9097 if (reg_overlap_mentioned_p (XEXP (target
, 0), op1
))
9099 if (reg_overlap_mentioned_p (XEXP (target
, 1), op0
))
9101 complex_expr_force_op1
:
9102 temp
= gen_reg_rtx (GET_MODE_INNER (GET_MODE (target
)));
9103 emit_move_insn (temp
, op1
);
9107 complex_expr_swap_order
:
9108 /* Move the imaginary (op1) and real (op0) parts to their
9110 write_complex_part (target
, op1
, true);
9111 write_complex_part (target
, op0
, false);
9117 temp
= adjust_address_nv (target
,
9118 GET_MODE_INNER (GET_MODE (target
)), 0);
9119 if (reg_overlap_mentioned_p (temp
, op1
))
9121 machine_mode imode
= GET_MODE_INNER (GET_MODE (target
));
9122 temp
= adjust_address_nv (target
, imode
,
9123 GET_MODE_SIZE (imode
));
9124 if (reg_overlap_mentioned_p (temp
, op0
))
9125 goto complex_expr_force_op1
;
9126 goto complex_expr_swap_order
;
9130 if (reg_overlap_mentioned_p (target
, op1
))
9132 if (reg_overlap_mentioned_p (target
, op0
))
9133 goto complex_expr_force_op1
;
9134 goto complex_expr_swap_order
;
9139 /* Move the real (op0) and imaginary (op1) parts to their location. */
9140 write_complex_part (target
, op0
, false);
9141 write_complex_part (target
, op1
, true);
9145 case WIDEN_SUM_EXPR
:
9147 tree oprnd0
= treeop0
;
9148 tree oprnd1
= treeop1
;
9150 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9151 target
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, op1
,
9156 case REDUC_MAX_EXPR
:
9157 case REDUC_MIN_EXPR
:
9158 case REDUC_PLUS_EXPR
:
9160 op0
= expand_normal (treeop0
);
9161 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9162 machine_mode vec_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
9164 if (optab_handler (this_optab
, vec_mode
) != CODE_FOR_nothing
)
9166 struct expand_operand ops
[2];
9167 enum insn_code icode
= optab_handler (this_optab
, vec_mode
);
9169 create_output_operand (&ops
[0], target
, mode
);
9170 create_input_operand (&ops
[1], op0
, vec_mode
);
9171 if (maybe_expand_insn (icode
, 2, ops
))
9173 target
= ops
[0].value
;
9174 if (GET_MODE (target
) != mode
)
9175 return gen_lowpart (tmode
, target
);
9179 /* Fall back to optab with vector result, and then extract scalar. */
9180 this_optab
= scalar_reduc_to_vector (this_optab
, type
);
9181 temp
= expand_unop (vec_mode
, this_optab
, op0
, NULL_RTX
, unsignedp
);
9183 /* The tree code produces a scalar result, but (somewhat by convention)
9184 the optab produces a vector with the result in element 0 if
9185 little-endian, or element N-1 if big-endian. So pull the scalar
9186 result out of that element. */
9187 int index
= BYTES_BIG_ENDIAN
? GET_MODE_NUNITS (vec_mode
) - 1 : 0;
9188 int bitsize
= GET_MODE_UNIT_BITSIZE (vec_mode
);
9189 temp
= extract_bit_field (temp
, bitsize
, bitsize
* index
, unsignedp
,
9190 target
, mode
, mode
, false);
9195 case VEC_UNPACK_HI_EXPR
:
9196 case VEC_UNPACK_LO_EXPR
:
9198 op0
= expand_normal (treeop0
);
9199 temp
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, NULL_RTX
,
9205 case VEC_UNPACK_FLOAT_HI_EXPR
:
9206 case VEC_UNPACK_FLOAT_LO_EXPR
:
9208 op0
= expand_normal (treeop0
);
9209 /* The signedness is determined from input operand. */
9210 temp
= expand_widen_pattern_expr
9211 (ops
, op0
, NULL_RTX
, NULL_RTX
,
9212 target
, TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
9218 case VEC_WIDEN_MULT_HI_EXPR
:
9219 case VEC_WIDEN_MULT_LO_EXPR
:
9220 case VEC_WIDEN_MULT_EVEN_EXPR
:
9221 case VEC_WIDEN_MULT_ODD_EXPR
:
9222 case VEC_WIDEN_LSHIFT_HI_EXPR
:
9223 case VEC_WIDEN_LSHIFT_LO_EXPR
:
9224 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9225 target
= expand_widen_pattern_expr (ops
, op0
, op1
, NULL_RTX
,
9227 gcc_assert (target
);
9230 case VEC_PACK_TRUNC_EXPR
:
9231 case VEC_PACK_SAT_EXPR
:
9232 case VEC_PACK_FIX_TRUNC_EXPR
:
9233 mode
= TYPE_MODE (TREE_TYPE (treeop0
));
9237 expand_operands (treeop0
, treeop1
, target
, &op0
, &op1
, EXPAND_NORMAL
);
9238 op2
= expand_normal (treeop2
);
9240 /* Careful here: if the target doesn't support integral vector modes,
9241 a constant selection vector could wind up smooshed into a normal
9242 integral constant. */
9243 if (CONSTANT_P (op2
) && GET_CODE (op2
) != CONST_VECTOR
)
9245 tree sel_type
= TREE_TYPE (treeop2
);
9247 = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type
)),
9248 TYPE_VECTOR_SUBPARTS (sel_type
));
9249 gcc_assert (GET_MODE_CLASS (vmode
) == MODE_VECTOR_INT
);
9250 op2
= simplify_subreg (vmode
, op2
, TYPE_MODE (sel_type
), 0);
9251 gcc_assert (op2
&& GET_CODE (op2
) == CONST_VECTOR
);
9254 gcc_assert (GET_MODE_CLASS (GET_MODE (op2
)) == MODE_VECTOR_INT
);
9256 temp
= expand_vec_perm (mode
, op0
, op1
, op2
, target
);
9262 tree oprnd0
= treeop0
;
9263 tree oprnd1
= treeop1
;
9264 tree oprnd2
= treeop2
;
9267 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9268 op2
= expand_normal (oprnd2
);
9269 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9276 tree oprnd0
= treeop0
;
9277 tree oprnd1
= treeop1
;
9278 tree oprnd2
= treeop2
;
9281 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9282 op2
= expand_normal (oprnd2
);
9283 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
9288 case REALIGN_LOAD_EXPR
:
9290 tree oprnd0
= treeop0
;
9291 tree oprnd1
= treeop1
;
9292 tree oprnd2
= treeop2
;
9295 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9296 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
9297 op2
= expand_normal (oprnd2
);
9298 temp
= expand_ternary_op (mode
, this_optab
, op0
, op1
, op2
,
9306 /* A COND_EXPR with its type being VOID_TYPE represents a
9307 conditional jump and is handled in
9308 expand_gimple_cond_expr. */
9309 gcc_assert (!VOID_TYPE_P (type
));
9311 /* Note that COND_EXPRs whose type is a structure or union
9312 are required to be constructed to contain assignments of
9313 a temporary variable, so that we can evaluate them here
9314 for side effect only. If type is void, we must do likewise. */
9316 gcc_assert (!TREE_ADDRESSABLE (type
)
9318 && TREE_TYPE (treeop1
) != void_type_node
9319 && TREE_TYPE (treeop2
) != void_type_node
);
9321 temp
= expand_cond_expr_using_cmove (treeop0
, treeop1
, treeop2
);
9325 /* If we are not to produce a result, we have no target. Otherwise,
9326 if a target was specified use it; it will not be used as an
9327 intermediate target unless it is safe. If no target, use a
9330 if (modifier
!= EXPAND_STACK_PARM
9332 && safe_from_p (original_target
, treeop0
, 1)
9333 && GET_MODE (original_target
) == mode
9334 && !MEM_P (original_target
))
9335 temp
= original_target
;
9337 temp
= assign_temp (type
, 0, 1);
9339 do_pending_stack_adjust ();
9341 rtx_code_label
*lab0
= gen_label_rtx ();
9342 rtx_code_label
*lab1
= gen_label_rtx ();
9343 jumpifnot (treeop0
, lab0
, -1);
9344 store_expr (treeop1
, temp
,
9345 modifier
== EXPAND_STACK_PARM
,
9348 emit_jump_insn (targetm
.gen_jump (lab1
));
9351 store_expr (treeop2
, temp
,
9352 modifier
== EXPAND_STACK_PARM
,
9361 target
= expand_vec_cond_expr (type
, treeop0
, treeop1
, treeop2
, target
);
9368 /* Here to do an ordinary binary operator. */
9370 expand_operands (treeop0
, treeop1
,
9371 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
9373 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
9375 if (modifier
== EXPAND_STACK_PARM
)
9377 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
,
9378 unsignedp
, OPTAB_LIB_WIDEN
);
9380 /* Bitwise operations do not need bitfield reduction as we expect their
9381 operands being properly truncated. */
9382 if (code
== BIT_XOR_EXPR
9383 || code
== BIT_AND_EXPR
9384 || code
== BIT_IOR_EXPR
)
9386 return REDUCE_BIT_FIELD (temp
);
9388 #undef REDUCE_BIT_FIELD
9391 /* Return TRUE if expression STMT is suitable for replacement.
9392 Never consider memory loads as replaceable, because those don't ever lead
9393 into constant expressions. */
9396 stmt_is_replaceable_p (gimple
*stmt
)
9398 if (ssa_is_replaceable_p (stmt
))
9400 /* Don't move around loads. */
9401 if (!gimple_assign_single_p (stmt
)
9402 || is_gimple_val (gimple_assign_rhs1 (stmt
)))
9409 expand_expr_real_1 (tree exp
, rtx target
, machine_mode tmode
,
9410 enum expand_modifier modifier
, rtx
*alt_rtl
,
9411 bool inner_reference_p
)
9413 rtx op0
, op1
, temp
, decl_rtl
;
9416 machine_mode mode
, dmode
;
9417 enum tree_code code
= TREE_CODE (exp
);
9418 rtx subtarget
, original_target
;
9421 bool reduce_bit_field
;
9422 location_t loc
= EXPR_LOCATION (exp
);
9423 struct separate_ops ops
;
9424 tree treeop0
, treeop1
, treeop2
;
9425 tree ssa_name
= NULL_TREE
;
9428 type
= TREE_TYPE (exp
);
9429 mode
= TYPE_MODE (type
);
9430 unsignedp
= TYPE_UNSIGNED (type
);
9432 treeop0
= treeop1
= treeop2
= NULL_TREE
;
9433 if (!VL_EXP_CLASS_P (exp
))
9434 switch (TREE_CODE_LENGTH (code
))
9437 case 3: treeop2
= TREE_OPERAND (exp
, 2);
9438 case 2: treeop1
= TREE_OPERAND (exp
, 1);
9439 case 1: treeop0
= TREE_OPERAND (exp
, 0);
9449 ignore
= (target
== const0_rtx
9450 || ((CONVERT_EXPR_CODE_P (code
)
9451 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
9452 && TREE_CODE (type
) == VOID_TYPE
));
9454 /* An operation in what may be a bit-field type needs the
9455 result to be reduced to the precision of the bit-field type,
9456 which is narrower than that of the type's mode. */
9457 reduce_bit_field
= (!ignore
9458 && INTEGRAL_TYPE_P (type
)
9459 && GET_MODE_PRECISION (mode
) > TYPE_PRECISION (type
));
9461 /* If we are going to ignore this result, we need only do something
9462 if there is a side-effect somewhere in the expression. If there
9463 is, short-circuit the most common cases here. Note that we must
9464 not call expand_expr with anything but const0_rtx in case this
9465 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
9469 if (! TREE_SIDE_EFFECTS (exp
))
9472 /* Ensure we reference a volatile object even if value is ignored, but
9473 don't do this if all we are doing is taking its address. */
9474 if (TREE_THIS_VOLATILE (exp
)
9475 && TREE_CODE (exp
) != FUNCTION_DECL
9476 && mode
!= VOIDmode
&& mode
!= BLKmode
9477 && modifier
!= EXPAND_CONST_ADDRESS
)
9479 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, modifier
);
9485 if (TREE_CODE_CLASS (code
) == tcc_unary
9486 || code
== BIT_FIELD_REF
9487 || code
== COMPONENT_REF
9488 || code
== INDIRECT_REF
)
9489 return expand_expr (treeop0
, const0_rtx
, VOIDmode
,
9492 else if (TREE_CODE_CLASS (code
) == tcc_binary
9493 || TREE_CODE_CLASS (code
) == tcc_comparison
9494 || code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
9496 expand_expr (treeop0
, const0_rtx
, VOIDmode
, modifier
);
9497 expand_expr (treeop1
, const0_rtx
, VOIDmode
, modifier
);
9504 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
9507 /* Use subtarget as the target for operand 0 of a binary operation. */
9508 subtarget
= get_subtarget (target
);
9509 original_target
= target
;
9515 tree function
= decl_function_context (exp
);
9517 temp
= label_rtx (exp
);
9518 temp
= gen_rtx_LABEL_REF (Pmode
, temp
);
9520 if (function
!= current_function_decl
9522 LABEL_REF_NONLOCAL_P (temp
) = 1;
9524 temp
= gen_rtx_MEM (FUNCTION_MODE
, temp
);
9529 /* ??? ivopts calls expander, without any preparation from
9530 out-of-ssa. So fake instructions as if this was an access to the
9531 base variable. This unnecessarily allocates a pseudo, see how we can
9532 reuse it, if partition base vars have it set already. */
9533 if (!currently_expanding_to_rtl
)
9535 tree var
= SSA_NAME_VAR (exp
);
9536 if (var
&& DECL_RTL_SET_P (var
))
9537 return DECL_RTL (var
);
9538 return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp
)),
9539 LAST_VIRTUAL_REGISTER
+ 1);
9542 g
= get_gimple_for_ssa_name (exp
);
9543 /* For EXPAND_INITIALIZER try harder to get something simpler. */
9545 && modifier
== EXPAND_INITIALIZER
9546 && !SSA_NAME_IS_DEFAULT_DEF (exp
)
9547 && (optimize
|| !SSA_NAME_VAR (exp
)
9548 || DECL_IGNORED_P (SSA_NAME_VAR (exp
)))
9549 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp
)))
9550 g
= SSA_NAME_DEF_STMT (exp
);
9554 location_t saved_loc
= curr_insn_location ();
9555 location_t loc
= gimple_location (g
);
9556 if (loc
!= UNKNOWN_LOCATION
)
9557 set_curr_insn_location (loc
);
9558 ops
.code
= gimple_assign_rhs_code (g
);
9559 switch (get_gimple_rhs_class (ops
.code
))
9561 case GIMPLE_TERNARY_RHS
:
9562 ops
.op2
= gimple_assign_rhs3 (g
);
9564 case GIMPLE_BINARY_RHS
:
9565 ops
.op1
= gimple_assign_rhs2 (g
);
9567 /* Try to expand conditonal compare. */
9568 if (targetm
.gen_ccmp_first
)
9570 gcc_checking_assert (targetm
.gen_ccmp_next
!= NULL
);
9571 r
= expand_ccmp_expr (g
);
9576 case GIMPLE_UNARY_RHS
:
9577 ops
.op0
= gimple_assign_rhs1 (g
);
9578 ops
.type
= TREE_TYPE (gimple_assign_lhs (g
));
9580 r
= expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
9582 case GIMPLE_SINGLE_RHS
:
9584 r
= expand_expr_real (gimple_assign_rhs1 (g
), target
,
9585 tmode
, modifier
, NULL
, inner_reference_p
);
9591 set_curr_insn_location (saved_loc
);
9592 if (REG_P (r
) && !REG_EXPR (r
))
9593 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp
), r
);
9598 decl_rtl
= get_rtx_for_ssa_name (ssa_name
);
9599 exp
= SSA_NAME_VAR (ssa_name
);
9600 goto expand_decl_rtl
;
9604 /* If a static var's type was incomplete when the decl was written,
9605 but the type is complete now, lay out the decl now. */
9606 if (DECL_SIZE (exp
) == 0
9607 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp
))
9608 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
9609 layout_decl (exp
, 0);
9611 /* ... fall through ... */
9615 decl_rtl
= DECL_RTL (exp
);
9617 gcc_assert (decl_rtl
);
9618 decl_rtl
= copy_rtx (decl_rtl
);
9619 /* Record writes to register variables. */
9620 if (modifier
== EXPAND_WRITE
9622 && HARD_REGISTER_P (decl_rtl
))
9623 add_to_hard_reg_set (&crtl
->asm_clobbers
,
9624 GET_MODE (decl_rtl
), REGNO (decl_rtl
));
9626 /* Ensure variable marked as used even if it doesn't go through
9627 a parser. If it hasn't be used yet, write out an external
9630 TREE_USED (exp
) = 1;
9632 /* Show we haven't gotten RTL for this yet. */
9635 /* Variables inherited from containing functions should have
9636 been lowered by this point. */
9638 context
= decl_function_context (exp
);
9640 || SCOPE_FILE_SCOPE_P (context
)
9641 || context
== current_function_decl
9642 || TREE_STATIC (exp
)
9643 || DECL_EXTERNAL (exp
)
9644 /* ??? C++ creates functions that are not TREE_STATIC. */
9645 || TREE_CODE (exp
) == FUNCTION_DECL
);
9647 /* This is the case of an array whose size is to be determined
9648 from its initializer, while the initializer is still being parsed.
9649 ??? We aren't parsing while expanding anymore. */
9651 if (MEM_P (decl_rtl
) && REG_P (XEXP (decl_rtl
, 0)))
9652 temp
= validize_mem (decl_rtl
);
9654 /* If DECL_RTL is memory, we are in the normal case and the
9655 address is not valid, get the address into a register. */
9657 else if (MEM_P (decl_rtl
) && modifier
!= EXPAND_INITIALIZER
)
9660 *alt_rtl
= decl_rtl
;
9661 decl_rtl
= use_anchored_address (decl_rtl
);
9662 if (modifier
!= EXPAND_CONST_ADDRESS
9663 && modifier
!= EXPAND_SUM
9664 && !memory_address_addr_space_p (exp
? DECL_MODE (exp
)
9665 : GET_MODE (decl_rtl
),
9667 MEM_ADDR_SPACE (decl_rtl
)))
9668 temp
= replace_equiv_address (decl_rtl
,
9669 copy_rtx (XEXP (decl_rtl
, 0)));
9672 /* If we got something, return it. But first, set the alignment
9673 if the address is a register. */
9676 if (exp
&& MEM_P (temp
) && REG_P (XEXP (temp
, 0)))
9677 mark_reg_pointer (XEXP (temp
, 0), DECL_ALIGN (exp
));
9683 dmode
= DECL_MODE (exp
);
9685 dmode
= TYPE_MODE (TREE_TYPE (ssa_name
));
9687 /* If the mode of DECL_RTL does not match that of the decl,
9688 there are two cases: we are dealing with a BLKmode value
9689 that is returned in a register, or we are dealing with
9690 a promoted value. In the latter case, return a SUBREG
9691 of the wanted mode, but mark it so that we know that it
9692 was already extended. */
9693 if (REG_P (decl_rtl
)
9695 && GET_MODE (decl_rtl
) != dmode
)
9699 /* Get the signedness to be used for this variable. Ensure we get
9700 the same mode we got when the variable was declared. */
9701 if (code
!= SSA_NAME
)
9702 pmode
= promote_decl_mode (exp
, &unsignedp
);
9703 else if ((g
= SSA_NAME_DEF_STMT (ssa_name
))
9704 && gimple_code (g
) == GIMPLE_CALL
9705 && !gimple_call_internal_p (g
))
9706 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
9707 gimple_call_fntype (g
),
9710 pmode
= promote_ssa_mode (ssa_name
, &unsignedp
);
9711 gcc_assert (GET_MODE (decl_rtl
) == pmode
);
9713 temp
= gen_lowpart_SUBREG (mode
, decl_rtl
);
9714 SUBREG_PROMOTED_VAR_P (temp
) = 1;
9715 SUBREG_PROMOTED_SET (temp
, unsignedp
);
9722 /* Given that TYPE_PRECISION (type) is not always equal to
9723 GET_MODE_PRECISION (TYPE_MODE (type)), we need to extend from
9724 the former to the latter according to the signedness of the
9726 temp
= immed_wide_int_const (wide_int::from
9728 GET_MODE_PRECISION (TYPE_MODE (type
)),
9735 tree tmp
= NULL_TREE
;
9736 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
9737 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
9738 || GET_MODE_CLASS (mode
) == MODE_VECTOR_FRACT
9739 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UFRACT
9740 || GET_MODE_CLASS (mode
) == MODE_VECTOR_ACCUM
9741 || GET_MODE_CLASS (mode
) == MODE_VECTOR_UACCUM
)
9742 return const_vector_from_tree (exp
);
9743 if (GET_MODE_CLASS (mode
) == MODE_INT
)
9745 tree type_for_mode
= lang_hooks
.types
.type_for_mode (mode
, 1);
9747 tmp
= fold_unary_loc (loc
, VIEW_CONVERT_EXPR
, type_for_mode
, exp
);
9751 vec
<constructor_elt
, va_gc
> *v
;
9753 vec_alloc (v
, VECTOR_CST_NELTS (exp
));
9754 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
9755 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, VECTOR_CST_ELT (exp
, i
));
9756 tmp
= build_constructor (type
, v
);
9758 return expand_expr (tmp
, ignore
? const0_rtx
: target
,
9763 return expand_expr (DECL_INITIAL (exp
), target
, VOIDmode
, modifier
);
9766 /* If optimized, generate immediate CONST_DOUBLE
9767 which will be turned into memory by reload if necessary.
9769 We used to force a register so that loop.c could see it. But
9770 this does not allow gen_* patterns to perform optimizations with
9771 the constants. It also produces two insns in cases like "x = 1.0;".
9772 On most machines, floating-point constants are not permitted in
9773 many insns, so we'd end up copying it to a register in any case.
9775 Now, we do the copying in expand_binop, if appropriate. */
9776 return const_double_from_real_value (TREE_REAL_CST (exp
),
9777 TYPE_MODE (TREE_TYPE (exp
)));
9780 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp
),
9781 TYPE_MODE (TREE_TYPE (exp
)));
9784 /* Handle evaluating a complex constant in a CONCAT target. */
9785 if (original_target
&& GET_CODE (original_target
) == CONCAT
)
9787 machine_mode mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
9790 rtarg
= XEXP (original_target
, 0);
9791 itarg
= XEXP (original_target
, 1);
9793 /* Move the real and imaginary parts separately. */
9794 op0
= expand_expr (TREE_REALPART (exp
), rtarg
, mode
, EXPAND_NORMAL
);
9795 op1
= expand_expr (TREE_IMAGPART (exp
), itarg
, mode
, EXPAND_NORMAL
);
9798 emit_move_insn (rtarg
, op0
);
9800 emit_move_insn (itarg
, op1
);
9802 return original_target
;
9805 /* ... fall through ... */
9808 temp
= expand_expr_constant (exp
, 1, modifier
);
9810 /* temp contains a constant address.
9811 On RISC machines where a constant address isn't valid,
9812 make some insns to get that address into a register. */
9813 if (modifier
!= EXPAND_CONST_ADDRESS
9814 && modifier
!= EXPAND_INITIALIZER
9815 && modifier
!= EXPAND_SUM
9816 && ! memory_address_addr_space_p (mode
, XEXP (temp
, 0),
9817 MEM_ADDR_SPACE (temp
)))
9818 return replace_equiv_address (temp
,
9819 copy_rtx (XEXP (temp
, 0)));
9825 rtx ret
= expand_expr_real_1 (val
, target
, tmode
, modifier
, alt_rtl
,
9828 if (!SAVE_EXPR_RESOLVED_P (exp
))
9830 /* We can indeed still hit this case, typically via builtin
9831 expanders calling save_expr immediately before expanding
9832 something. Assume this means that we only have to deal
9833 with non-BLKmode values. */
9834 gcc_assert (GET_MODE (ret
) != BLKmode
);
9836 val
= build_decl (curr_insn_location (),
9837 VAR_DECL
, NULL
, TREE_TYPE (exp
));
9838 DECL_ARTIFICIAL (val
) = 1;
9839 DECL_IGNORED_P (val
) = 1;
9841 TREE_OPERAND (exp
, 0) = treeop0
;
9842 SAVE_EXPR_RESOLVED_P (exp
) = 1;
9844 if (!CONSTANT_P (ret
))
9845 ret
= copy_to_reg (ret
);
9846 SET_DECL_RTL (val
, ret
);
9854 /* If we don't need the result, just ensure we evaluate any
9858 unsigned HOST_WIDE_INT idx
;
9861 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
9862 expand_expr (value
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
9867 return expand_constructor (exp
, target
, modifier
, false);
9869 case TARGET_MEM_REF
:
9872 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9873 enum insn_code icode
;
9876 op0
= addr_for_mem_ref (exp
, as
, true);
9877 op0
= memory_address_addr_space (mode
, op0
, as
);
9878 temp
= gen_rtx_MEM (mode
, op0
);
9879 set_mem_attributes (temp
, exp
, 0);
9880 set_mem_addr_space (temp
, as
);
9881 align
= get_object_alignment (exp
);
9882 if (modifier
!= EXPAND_WRITE
9883 && modifier
!= EXPAND_MEMORY
9885 && align
< GET_MODE_ALIGNMENT (mode
)
9886 /* If the target does not have special handling for unaligned
9887 loads of mode then it can use regular moves for them. */
9888 && ((icode
= optab_handler (movmisalign_optab
, mode
))
9889 != CODE_FOR_nothing
))
9891 struct expand_operand ops
[2];
9893 /* We've already validated the memory, and we're creating a
9894 new pseudo destination. The predicates really can't fail,
9895 nor can the generator. */
9896 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9897 create_fixed_operand (&ops
[1], temp
);
9898 expand_insn (icode
, 2, ops
);
9899 temp
= ops
[0].value
;
9906 const bool reverse
= REF_REVERSE_STORAGE_ORDER (exp
);
9908 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
9909 machine_mode address_mode
;
9910 tree base
= TREE_OPERAND (exp
, 0);
9912 enum insn_code icode
;
9914 /* Handle expansion of non-aliased memory with non-BLKmode. That
9915 might end up in a register. */
9916 if (mem_ref_refers_to_non_mem_p (exp
))
9918 HOST_WIDE_INT offset
= mem_ref_offset (exp
).to_short_addr ();
9919 base
= TREE_OPERAND (base
, 0);
9922 && tree_fits_uhwi_p (TYPE_SIZE (type
))
9923 && (GET_MODE_BITSIZE (DECL_MODE (base
))
9924 == tree_to_uhwi (TYPE_SIZE (type
))))
9925 return expand_expr (build1 (VIEW_CONVERT_EXPR
, type
, base
),
9926 target
, tmode
, modifier
);
9927 if (TYPE_MODE (type
) == BLKmode
)
9929 temp
= assign_stack_temp (DECL_MODE (base
),
9930 GET_MODE_SIZE (DECL_MODE (base
)));
9931 store_expr (base
, temp
, 0, false, false);
9932 temp
= adjust_address (temp
, BLKmode
, offset
);
9933 set_mem_size (temp
, int_size_in_bytes (type
));
9936 exp
= build3 (BIT_FIELD_REF
, type
, base
, TYPE_SIZE (type
),
9937 bitsize_int (offset
* BITS_PER_UNIT
));
9938 REF_REVERSE_STORAGE_ORDER (exp
) = reverse
;
9939 return expand_expr (exp
, target
, tmode
, modifier
);
9941 address_mode
= targetm
.addr_space
.address_mode (as
);
9942 base
= TREE_OPERAND (exp
, 0);
9943 if ((def_stmt
= get_def_for_expr (base
, BIT_AND_EXPR
)))
9945 tree mask
= gimple_assign_rhs2 (def_stmt
);
9946 base
= build2 (BIT_AND_EXPR
, TREE_TYPE (base
),
9947 gimple_assign_rhs1 (def_stmt
), mask
);
9948 TREE_OPERAND (exp
, 0) = base
;
9950 align
= get_object_alignment (exp
);
9951 op0
= expand_expr (base
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
9952 op0
= memory_address_addr_space (mode
, op0
, as
);
9953 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
9955 rtx off
= immed_wide_int_const (mem_ref_offset (exp
), address_mode
);
9956 op0
= simplify_gen_binary (PLUS
, address_mode
, op0
, off
);
9957 op0
= memory_address_addr_space (mode
, op0
, as
);
9959 temp
= gen_rtx_MEM (mode
, op0
);
9960 set_mem_attributes (temp
, exp
, 0);
9961 set_mem_addr_space (temp
, as
);
9962 if (TREE_THIS_VOLATILE (exp
))
9963 MEM_VOLATILE_P (temp
) = 1;
9964 if (modifier
!= EXPAND_WRITE
9965 && modifier
!= EXPAND_MEMORY
9966 && !inner_reference_p
9968 && align
< GET_MODE_ALIGNMENT (mode
))
9970 if ((icode
= optab_handler (movmisalign_optab
, mode
))
9971 != CODE_FOR_nothing
)
9973 struct expand_operand ops
[2];
9975 /* We've already validated the memory, and we're creating a
9976 new pseudo destination. The predicates really can't fail,
9977 nor can the generator. */
9978 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9979 create_fixed_operand (&ops
[1], temp
);
9980 expand_insn (icode
, 2, ops
);
9981 temp
= ops
[0].value
;
9983 else if (SLOW_UNALIGNED_ACCESS (mode
, align
))
9984 temp
= extract_bit_field (temp
, GET_MODE_BITSIZE (mode
),
9985 0, TYPE_UNSIGNED (TREE_TYPE (exp
)),
9986 (modifier
== EXPAND_STACK_PARM
9987 ? NULL_RTX
: target
),
9991 && modifier
!= EXPAND_MEMORY
9992 && modifier
!= EXPAND_WRITE
)
9993 temp
= flip_storage_order (mode
, temp
);
10000 tree array
= treeop0
;
10001 tree index
= treeop1
;
10004 /* Fold an expression like: "foo"[2].
10005 This is not done in fold so it won't happen inside &.
10006 Don't fold if this is for wide characters since it's too
10007 difficult to do correctly and this is a very rare case. */
10009 if (modifier
!= EXPAND_CONST_ADDRESS
10010 && modifier
!= EXPAND_INITIALIZER
10011 && modifier
!= EXPAND_MEMORY
)
10013 tree t
= fold_read_from_constant_string (exp
);
10016 return expand_expr (t
, target
, tmode
, modifier
);
10019 /* If this is a constant index into a constant array,
10020 just get the value from the array. Handle both the cases when
10021 we have an explicit constructor and when our operand is a variable
10022 that was declared const. */
10024 if (modifier
!= EXPAND_CONST_ADDRESS
10025 && modifier
!= EXPAND_INITIALIZER
10026 && modifier
!= EXPAND_MEMORY
10027 && TREE_CODE (array
) == CONSTRUCTOR
10028 && ! TREE_SIDE_EFFECTS (array
)
10029 && TREE_CODE (index
) == INTEGER_CST
)
10031 unsigned HOST_WIDE_INT ix
;
10034 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array
), ix
,
10036 if (tree_int_cst_equal (field
, index
))
10038 if (!TREE_SIDE_EFFECTS (value
))
10039 return expand_expr (fold (value
), target
, tmode
, modifier
);
10044 else if (optimize
>= 1
10045 && modifier
!= EXPAND_CONST_ADDRESS
10046 && modifier
!= EXPAND_INITIALIZER
10047 && modifier
!= EXPAND_MEMORY
10048 && TREE_READONLY (array
) && ! TREE_SIDE_EFFECTS (array
)
10049 && TREE_CODE (index
) == INTEGER_CST
10050 && (TREE_CODE (array
) == VAR_DECL
10051 || TREE_CODE (array
) == CONST_DECL
)
10052 && (init
= ctor_for_folding (array
)) != error_mark_node
)
10054 if (init
== NULL_TREE
)
10056 tree value
= build_zero_cst (type
);
10057 if (TREE_CODE (value
) == CONSTRUCTOR
)
10059 /* If VALUE is a CONSTRUCTOR, this optimization is only
10060 useful if this doesn't store the CONSTRUCTOR into
10061 memory. If it does, it is more efficient to just
10062 load the data from the array directly. */
10063 rtx ret
= expand_constructor (value
, target
,
10065 if (ret
== NULL_RTX
)
10070 return expand_expr (value
, target
, tmode
, modifier
);
10072 else if (TREE_CODE (init
) == CONSTRUCTOR
)
10074 unsigned HOST_WIDE_INT ix
;
10077 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), ix
,
10079 if (tree_int_cst_equal (field
, index
))
10081 if (TREE_SIDE_EFFECTS (value
))
10084 if (TREE_CODE (value
) == CONSTRUCTOR
)
10086 /* If VALUE is a CONSTRUCTOR, this
10087 optimization is only useful if
10088 this doesn't store the CONSTRUCTOR
10089 into memory. If it does, it is more
10090 efficient to just load the data from
10091 the array directly. */
10092 rtx ret
= expand_constructor (value
, target
,
10094 if (ret
== NULL_RTX
)
10099 expand_expr (fold (value
), target
, tmode
, modifier
);
10102 else if (TREE_CODE (init
) == STRING_CST
)
10104 tree low_bound
= array_ref_low_bound (exp
);
10105 tree index1
= fold_convert_loc (loc
, sizetype
, treeop1
);
10107 /* Optimize the special case of a zero lower bound.
10109 We convert the lower bound to sizetype to avoid problems
10110 with constant folding. E.g. suppose the lower bound is
10111 1 and its mode is QI. Without the conversion
10112 (ARRAY + (INDEX - (unsigned char)1))
10114 (ARRAY + (-(unsigned char)1) + INDEX)
10116 (ARRAY + 255 + INDEX). Oops! */
10117 if (!integer_zerop (low_bound
))
10118 index1
= size_diffop_loc (loc
, index1
,
10119 fold_convert_loc (loc
, sizetype
,
10122 if (compare_tree_int (index1
, TREE_STRING_LENGTH (init
)) < 0)
10124 tree type
= TREE_TYPE (TREE_TYPE (init
));
10125 machine_mode mode
= TYPE_MODE (type
);
10127 if (GET_MODE_CLASS (mode
) == MODE_INT
10128 && GET_MODE_SIZE (mode
) == 1)
10129 return gen_int_mode (TREE_STRING_POINTER (init
)
10130 [TREE_INT_CST_LOW (index1
)],
10136 goto normal_inner_ref
;
10138 case COMPONENT_REF
:
10139 /* If the operand is a CONSTRUCTOR, we can just extract the
10140 appropriate field if it is present. */
10141 if (TREE_CODE (treeop0
) == CONSTRUCTOR
)
10143 unsigned HOST_WIDE_INT idx
;
10146 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0
),
10148 if (field
== treeop1
10149 /* We can normally use the value of the field in the
10150 CONSTRUCTOR. However, if this is a bitfield in
10151 an integral mode that we can fit in a HOST_WIDE_INT,
10152 we must mask only the number of bits in the bitfield,
10153 since this is done implicitly by the constructor. If
10154 the bitfield does not meet either of those conditions,
10155 we can't do this optimization. */
10156 && (! DECL_BIT_FIELD (field
)
10157 || ((GET_MODE_CLASS (DECL_MODE (field
)) == MODE_INT
)
10158 && (GET_MODE_PRECISION (DECL_MODE (field
))
10159 <= HOST_BITS_PER_WIDE_INT
))))
10161 if (DECL_BIT_FIELD (field
)
10162 && modifier
== EXPAND_STACK_PARM
)
10164 op0
= expand_expr (value
, target
, tmode
, modifier
);
10165 if (DECL_BIT_FIELD (field
))
10167 HOST_WIDE_INT bitsize
= TREE_INT_CST_LOW (DECL_SIZE (field
));
10168 machine_mode imode
= TYPE_MODE (TREE_TYPE (field
));
10170 if (TYPE_UNSIGNED (TREE_TYPE (field
)))
10172 op1
= gen_int_mode (((HOST_WIDE_INT
) 1 << bitsize
) - 1,
10174 op0
= expand_and (imode
, op0
, op1
, target
);
10178 int count
= GET_MODE_PRECISION (imode
) - bitsize
;
10180 op0
= expand_shift (LSHIFT_EXPR
, imode
, op0
, count
,
10182 op0
= expand_shift (RSHIFT_EXPR
, imode
, op0
, count
,
10190 goto normal_inner_ref
;
10192 case BIT_FIELD_REF
:
10193 case ARRAY_RANGE_REF
:
10196 machine_mode mode1
, mode2
;
10197 HOST_WIDE_INT bitsize
, bitpos
;
10199 int reversep
, volatilep
= 0, must_force_mem
;
10201 = get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
, &mode1
,
10202 &unsignedp
, &reversep
, &volatilep
, true);
10203 rtx orig_op0
, memloc
;
10204 bool clear_mem_expr
= false;
10206 /* If we got back the original object, something is wrong. Perhaps
10207 we are evaluating an expression too early. In any event, don't
10208 infinitely recurse. */
10209 gcc_assert (tem
!= exp
);
10211 /* If TEM's type is a union of variable size, pass TARGET to the inner
10212 computation, since it will need a temporary and TARGET is known
10213 to have to do. This occurs in unchecked conversion in Ada. */
10215 = expand_expr_real (tem
,
10216 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10217 && COMPLETE_TYPE_P (TREE_TYPE (tem
))
10218 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10220 && modifier
!= EXPAND_STACK_PARM
10221 ? target
: NULL_RTX
),
10223 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
,
10226 /* If the field has a mode, we want to access it in the
10227 field's mode, not the computed mode.
10228 If a MEM has VOIDmode (external with incomplete type),
10229 use BLKmode for it instead. */
10232 if (mode1
!= VOIDmode
)
10233 op0
= adjust_address (op0
, mode1
, 0);
10234 else if (GET_MODE (op0
) == VOIDmode
)
10235 op0
= adjust_address (op0
, BLKmode
, 0);
10239 = CONSTANT_P (op0
) ? TYPE_MODE (TREE_TYPE (tem
)) : GET_MODE (op0
);
10241 /* If we have either an offset, a BLKmode result, or a reference
10242 outside the underlying object, we must force it to memory.
10243 Such a case can occur in Ada if we have unchecked conversion
10244 of an expression from a scalar type to an aggregate type or
10245 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
10246 passed a partially uninitialized object or a view-conversion
10247 to a larger size. */
10248 must_force_mem
= (offset
10249 || mode1
== BLKmode
10250 || bitpos
+ bitsize
> GET_MODE_BITSIZE (mode2
));
10252 /* Handle CONCAT first. */
10253 if (GET_CODE (op0
) == CONCAT
&& !must_force_mem
)
10256 && bitsize
== GET_MODE_BITSIZE (GET_MODE (op0
)))
10259 op0
= flip_storage_order (GET_MODE (op0
), op0
);
10263 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
10266 op0
= XEXP (op0
, 0);
10267 mode2
= GET_MODE (op0
);
10269 else if (bitpos
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0)))
10270 && bitsize
== GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 1)))
10274 op0
= XEXP (op0
, 1);
10276 mode2
= GET_MODE (op0
);
10279 /* Otherwise force into memory. */
10280 must_force_mem
= 1;
10283 /* If this is a constant, put it in a register if it is a legitimate
10284 constant and we don't need a memory reference. */
10285 if (CONSTANT_P (op0
)
10286 && mode2
!= BLKmode
10287 && targetm
.legitimate_constant_p (mode2
, op0
)
10288 && !must_force_mem
)
10289 op0
= force_reg (mode2
, op0
);
10291 /* Otherwise, if this is a constant, try to force it to the constant
10292 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
10293 is a legitimate constant. */
10294 else if (CONSTANT_P (op0
) && (memloc
= force_const_mem (mode2
, op0
)))
10295 op0
= validize_mem (memloc
);
10297 /* Otherwise, if this is a constant or the object is not in memory
10298 and need be, put it there. */
10299 else if (CONSTANT_P (op0
) || (!MEM_P (op0
) && must_force_mem
))
10301 memloc
= assign_temp (TREE_TYPE (tem
), 1, 1);
10302 emit_move_insn (memloc
, op0
);
10304 clear_mem_expr
= true;
10309 machine_mode address_mode
;
10310 rtx offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
,
10313 gcc_assert (MEM_P (op0
));
10315 address_mode
= get_address_mode (op0
);
10316 if (GET_MODE (offset_rtx
) != address_mode
)
10318 /* We cannot be sure that the RTL in offset_rtx is valid outside
10319 of a memory address context, so force it into a register
10320 before attempting to convert it to the desired mode. */
10321 offset_rtx
= force_operand (offset_rtx
, NULL_RTX
);
10322 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
10325 /* See the comment in expand_assignment for the rationale. */
10326 if (mode1
!= VOIDmode
10329 && (bitpos
% bitsize
) == 0
10330 && (bitsize
% GET_MODE_ALIGNMENT (mode1
)) == 0
10331 && MEM_ALIGN (op0
) >= GET_MODE_ALIGNMENT (mode1
))
10333 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10337 op0
= offset_address (op0
, offset_rtx
,
10338 highest_pow2_factor (offset
));
10341 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
10342 record its alignment as BIGGEST_ALIGNMENT. */
10343 if (MEM_P (op0
) && bitpos
== 0 && offset
!= 0
10344 && is_aligning_offset (offset
, tem
))
10345 set_mem_align (op0
, BIGGEST_ALIGNMENT
);
10347 /* Don't forget about volatility even if this is a bitfield. */
10348 if (MEM_P (op0
) && volatilep
&& ! MEM_VOLATILE_P (op0
))
10350 if (op0
== orig_op0
)
10351 op0
= copy_rtx (op0
);
10353 MEM_VOLATILE_P (op0
) = 1;
10356 /* In cases where an aligned union has an unaligned object
10357 as a field, we might be extracting a BLKmode value from
10358 an integer-mode (e.g., SImode) object. Handle this case
10359 by doing the extract into an object as wide as the field
10360 (which we know to be the width of a basic mode), then
10361 storing into memory, and changing the mode to BLKmode. */
10362 if (mode1
== VOIDmode
10363 || REG_P (op0
) || GET_CODE (op0
) == SUBREG
10364 || (mode1
!= BLKmode
&& ! direct_load
[(int) mode1
]
10365 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
10366 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
10367 && modifier
!= EXPAND_CONST_ADDRESS
10368 && modifier
!= EXPAND_INITIALIZER
10369 && modifier
!= EXPAND_MEMORY
)
10370 /* If the bitfield is volatile and the bitsize
10371 is narrower than the access size of the bitfield,
10372 we need to extract bitfields from the access. */
10373 || (volatilep
&& TREE_CODE (exp
) == COMPONENT_REF
10374 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp
, 1))
10375 && mode1
!= BLKmode
10376 && bitsize
< GET_MODE_SIZE (mode1
) * BITS_PER_UNIT
)
10377 /* If the field isn't aligned enough to fetch as a memref,
10378 fetch it as a bit field. */
10379 || (mode1
!= BLKmode
10380 && (((TYPE_ALIGN (TREE_TYPE (tem
)) < GET_MODE_ALIGNMENT (mode
)
10381 || (bitpos
% GET_MODE_ALIGNMENT (mode
) != 0)
10383 && (MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode1
)
10384 || (bitpos
% GET_MODE_ALIGNMENT (mode1
) != 0))))
10385 && modifier
!= EXPAND_MEMORY
10386 && ((modifier
== EXPAND_CONST_ADDRESS
10387 || modifier
== EXPAND_INITIALIZER
)
10389 : SLOW_UNALIGNED_ACCESS (mode1
, MEM_ALIGN (op0
))))
10390 || (bitpos
% BITS_PER_UNIT
!= 0)))
10391 /* If the type and the field are a constant size and the
10392 size of the type isn't the same size as the bitfield,
10393 we must use bitfield operations. */
10395 && TYPE_SIZE (TREE_TYPE (exp
))
10396 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) == INTEGER_CST
10397 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp
)),
10400 machine_mode ext_mode
= mode
;
10402 if (ext_mode
== BLKmode
10403 && ! (target
!= 0 && MEM_P (op0
)
10405 && bitpos
% BITS_PER_UNIT
== 0))
10406 ext_mode
= mode_for_size (bitsize
, MODE_INT
, 1);
10408 if (ext_mode
== BLKmode
)
10411 target
= assign_temp (type
, 1, 1);
10413 /* ??? Unlike the similar test a few lines below, this one is
10414 very likely obsolete. */
10418 /* In this case, BITPOS must start at a byte boundary and
10419 TARGET, if specified, must be a MEM. */
10420 gcc_assert (MEM_P (op0
)
10421 && (!target
|| MEM_P (target
))
10422 && !(bitpos
% BITS_PER_UNIT
));
10424 emit_block_move (target
,
10425 adjust_address (op0
, VOIDmode
,
10426 bitpos
/ BITS_PER_UNIT
),
10427 GEN_INT ((bitsize
+ BITS_PER_UNIT
- 1)
10429 (modifier
== EXPAND_STACK_PARM
10430 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10435 /* If we have nothing to extract, the result will be 0 for targets
10436 with SHIFT_COUNT_TRUNCATED == 0 and garbage otherwise. Always
10437 return 0 for the sake of consistency, as reading a zero-sized
10438 bitfield is valid in Ada and the value is fully specified. */
10442 op0
= validize_mem (op0
);
10444 if (MEM_P (op0
) && REG_P (XEXP (op0
, 0)))
10445 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10447 /* If the result has a record type and the extraction is done in
10448 an integral mode, then the field may be not aligned on a byte
10449 boundary; in this case, if it has reverse storage order, it
10450 needs to be extracted as a scalar field with reverse storage
10451 order and put back into memory order afterwards. */
10452 if (TREE_CODE (type
) == RECORD_TYPE
10453 && GET_MODE_CLASS (ext_mode
) == MODE_INT
)
10454 reversep
= TYPE_REVERSE_STORAGE_ORDER (type
);
10456 op0
= extract_bit_field (op0
, bitsize
, bitpos
, unsignedp
,
10457 (modifier
== EXPAND_STACK_PARM
10458 ? NULL_RTX
: target
),
10459 ext_mode
, ext_mode
, reversep
);
10461 /* If the result has a record type and the mode of OP0 is an
10462 integral mode then, if BITSIZE is narrower than this mode
10463 and this is for big-endian data, we must put the field
10464 into the high-order bits. And we must also put it back
10465 into memory order if it has been previously reversed. */
10466 if (TREE_CODE (type
) == RECORD_TYPE
10467 && GET_MODE_CLASS (GET_MODE (op0
)) == MODE_INT
)
10469 HOST_WIDE_INT size
= GET_MODE_BITSIZE (GET_MODE (op0
));
10472 && reversep
? !BYTES_BIG_ENDIAN
: BYTES_BIG_ENDIAN
)
10473 op0
= expand_shift (LSHIFT_EXPR
, GET_MODE (op0
), op0
,
10474 size
- bitsize
, op0
, 1);
10477 op0
= flip_storage_order (GET_MODE (op0
), op0
);
10480 /* If the result type is BLKmode, store the data into a temporary
10481 of the appropriate type, but with the mode corresponding to the
10482 mode for the data we have (op0's mode). */
10483 if (mode
== BLKmode
)
10486 = assign_stack_temp_for_type (ext_mode
,
10487 GET_MODE_BITSIZE (ext_mode
),
10489 emit_move_insn (new_rtx
, op0
);
10490 op0
= copy_rtx (new_rtx
);
10491 PUT_MODE (op0
, BLKmode
);
10497 /* If the result is BLKmode, use that to access the object
10499 if (mode
== BLKmode
)
10502 /* Get a reference to just this component. */
10503 if (modifier
== EXPAND_CONST_ADDRESS
10504 || modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
10505 op0
= adjust_address_nv (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10507 op0
= adjust_address (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
10509 if (op0
== orig_op0
)
10510 op0
= copy_rtx (op0
);
10512 set_mem_attributes (op0
, exp
, 0);
10514 if (REG_P (XEXP (op0
, 0)))
10515 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10517 /* If op0 is a temporary because the original expressions was forced
10518 to memory, clear MEM_EXPR so that the original expression cannot
10519 be marked as addressable through MEM_EXPR of the temporary. */
10520 if (clear_mem_expr
)
10521 set_mem_expr (op0
, NULL_TREE
);
10523 MEM_VOLATILE_P (op0
) |= volatilep
;
10526 && modifier
!= EXPAND_MEMORY
10527 && modifier
!= EXPAND_WRITE
)
10528 op0
= flip_storage_order (mode1
, op0
);
10530 if (mode
== mode1
|| mode1
== BLKmode
|| mode1
== tmode
10531 || modifier
== EXPAND_CONST_ADDRESS
10532 || modifier
== EXPAND_INITIALIZER
)
10536 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
10538 convert_move (target
, op0
, unsignedp
);
10543 return expand_expr (OBJ_TYPE_REF_EXPR (exp
), target
, tmode
, modifier
);
10546 /* All valid uses of __builtin_va_arg_pack () are removed during
10548 if (CALL_EXPR_VA_ARG_PACK (exp
))
10549 error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp
);
10551 tree fndecl
= get_callee_fndecl (exp
), attr
;
10554 && (attr
= lookup_attribute ("error",
10555 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10556 error ("%Kcall to %qs declared with attribute error: %s",
10557 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10558 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10560 && (attr
= lookup_attribute ("warning",
10561 DECL_ATTRIBUTES (fndecl
))) != NULL
)
10562 warning_at (tree_nonartificial_location (exp
),
10563 0, "%Kcall to %qs declared with attribute warning: %s",
10564 exp
, identifier_to_locale (lang_hooks
.decl_printable_name (fndecl
, 1)),
10565 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
10567 /* Check for a built-in function. */
10568 if (fndecl
&& DECL_BUILT_IN (fndecl
))
10570 gcc_assert (DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_FRONTEND
);
10571 if (CALL_WITH_BOUNDS_P (exp
))
10572 return expand_builtin_with_bounds (exp
, target
, subtarget
,
10575 return expand_builtin (exp
, target
, subtarget
, tmode
, ignore
);
10578 return expand_call (exp
, target
, ignore
);
10580 case VIEW_CONVERT_EXPR
:
10583 /* If we are converting to BLKmode, try to avoid an intermediate
10584 temporary by fetching an inner memory reference. */
10585 if (mode
== BLKmode
10586 && TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
10587 && TYPE_MODE (TREE_TYPE (treeop0
)) != BLKmode
10588 && handled_component_p (treeop0
))
10590 machine_mode mode1
;
10591 HOST_WIDE_INT bitsize
, bitpos
;
10593 int unsignedp
, reversep
, volatilep
= 0;
10595 = get_inner_reference (treeop0
, &bitsize
, &bitpos
, &offset
, &mode1
,
10596 &unsignedp
, &reversep
, &volatilep
, true);
10599 /* ??? We should work harder and deal with non-zero offsets. */
10601 && (bitpos
% BITS_PER_UNIT
) == 0
10604 && compare_tree_int (TYPE_SIZE (type
), bitsize
) == 0)
10606 /* See the normal_inner_ref case for the rationale. */
10608 = expand_expr_real (tem
,
10609 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
10610 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
10612 && modifier
!= EXPAND_STACK_PARM
10613 ? target
: NULL_RTX
),
10615 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
,
10618 if (MEM_P (orig_op0
))
10622 /* Get a reference to just this component. */
10623 if (modifier
== EXPAND_CONST_ADDRESS
10624 || modifier
== EXPAND_SUM
10625 || modifier
== EXPAND_INITIALIZER
)
10626 op0
= adjust_address_nv (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10628 op0
= adjust_address (op0
, mode
, bitpos
/ BITS_PER_UNIT
);
10630 if (op0
== orig_op0
)
10631 op0
= copy_rtx (op0
);
10633 set_mem_attributes (op0
, treeop0
, 0);
10634 if (REG_P (XEXP (op0
, 0)))
10635 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
10637 MEM_VOLATILE_P (op0
) |= volatilep
;
10643 op0
= expand_expr_real (treeop0
, NULL_RTX
, VOIDmode
, modifier
,
10644 NULL
, inner_reference_p
);
10646 /* If the input and output modes are both the same, we are done. */
10647 if (mode
== GET_MODE (op0
))
10649 /* If neither mode is BLKmode, and both modes are the same size
10650 then we can use gen_lowpart. */
10651 else if (mode
!= BLKmode
&& GET_MODE (op0
) != BLKmode
10652 && (GET_MODE_PRECISION (mode
)
10653 == GET_MODE_PRECISION (GET_MODE (op0
)))
10654 && !COMPLEX_MODE_P (GET_MODE (op0
)))
10656 if (GET_CODE (op0
) == SUBREG
)
10657 op0
= force_reg (GET_MODE (op0
), op0
);
10658 temp
= gen_lowpart_common (mode
, op0
);
10663 if (!REG_P (op0
) && !MEM_P (op0
))
10664 op0
= force_reg (GET_MODE (op0
), op0
);
10665 op0
= gen_lowpart (mode
, op0
);
10668 /* If both types are integral, convert from one mode to the other. */
10669 else if (INTEGRAL_TYPE_P (type
) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0
)))
10670 op0
= convert_modes (mode
, GET_MODE (op0
), op0
,
10671 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
10672 /* If the output type is a bit-field type, do an extraction. */
10673 else if (reduce_bit_field
)
10674 return extract_bit_field (op0
, TYPE_PRECISION (type
), 0,
10675 TYPE_UNSIGNED (type
), NULL_RTX
,
10676 mode
, mode
, false);
10677 /* As a last resort, spill op0 to memory, and reload it in a
10679 else if (!MEM_P (op0
))
10681 /* If the operand is not a MEM, force it into memory. Since we
10682 are going to be changing the mode of the MEM, don't call
10683 force_const_mem for constants because we don't allow pool
10684 constants to change mode. */
10685 tree inner_type
= TREE_TYPE (treeop0
);
10687 gcc_assert (!TREE_ADDRESSABLE (exp
));
10689 if (target
== 0 || GET_MODE (target
) != TYPE_MODE (inner_type
))
10691 = assign_stack_temp_for_type
10692 (TYPE_MODE (inner_type
),
10693 GET_MODE_SIZE (TYPE_MODE (inner_type
)), inner_type
);
10695 emit_move_insn (target
, op0
);
10699 /* If OP0 is (now) a MEM, we need to deal with alignment issues. If the
10700 output type is such that the operand is known to be aligned, indicate
10701 that it is. Otherwise, we need only be concerned about alignment for
10702 non-BLKmode results. */
10705 enum insn_code icode
;
10707 if (TYPE_ALIGN_OK (type
))
10709 /* ??? Copying the MEM without substantially changing it might
10710 run afoul of the code handling volatile memory references in
10711 store_expr, which assumes that TARGET is returned unmodified
10712 if it has been used. */
10713 op0
= copy_rtx (op0
);
10714 set_mem_align (op0
, MAX (MEM_ALIGN (op0
), TYPE_ALIGN (type
)));
10716 else if (modifier
!= EXPAND_WRITE
10717 && modifier
!= EXPAND_MEMORY
10718 && !inner_reference_p
10720 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
))
10722 /* If the target does have special handling for unaligned
10723 loads of mode then use them. */
10724 if ((icode
= optab_handler (movmisalign_optab
, mode
))
10725 != CODE_FOR_nothing
)
10729 op0
= adjust_address (op0
, mode
, 0);
10730 /* We've already validated the memory, and we're creating a
10731 new pseudo destination. The predicates really can't
10733 reg
= gen_reg_rtx (mode
);
10735 /* Nor can the insn generator. */
10736 rtx_insn
*insn
= GEN_FCN (icode
) (reg
, op0
);
10740 else if (STRICT_ALIGNMENT
)
10742 tree inner_type
= TREE_TYPE (treeop0
);
10743 HOST_WIDE_INT temp_size
10744 = MAX (int_size_in_bytes (inner_type
),
10745 (HOST_WIDE_INT
) GET_MODE_SIZE (mode
));
10747 = assign_stack_temp_for_type (mode
, temp_size
, type
);
10748 rtx new_with_op0_mode
10749 = adjust_address (new_rtx
, GET_MODE (op0
), 0);
10751 gcc_assert (!TREE_ADDRESSABLE (exp
));
10753 if (GET_MODE (op0
) == BLKmode
)
10754 emit_block_move (new_with_op0_mode
, op0
,
10755 GEN_INT (GET_MODE_SIZE (mode
)),
10756 (modifier
== EXPAND_STACK_PARM
10757 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
10759 emit_move_insn (new_with_op0_mode
, op0
);
10765 op0
= adjust_address (op0
, mode
, 0);
10772 tree lhs
= treeop0
;
10773 tree rhs
= treeop1
;
10774 gcc_assert (ignore
);
10776 /* Check for |= or &= of a bitfield of size one into another bitfield
10777 of size 1. In this case, (unless we need the result of the
10778 assignment) we can do this more efficiently with a
10779 test followed by an assignment, if necessary.
10781 ??? At this point, we can't get a BIT_FIELD_REF here. But if
10782 things change so we do, this code should be enhanced to
10784 if (TREE_CODE (lhs
) == COMPONENT_REF
10785 && (TREE_CODE (rhs
) == BIT_IOR_EXPR
10786 || TREE_CODE (rhs
) == BIT_AND_EXPR
)
10787 && TREE_OPERAND (rhs
, 0) == lhs
10788 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == COMPONENT_REF
10789 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs
, 1)))
10790 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs
, 1), 1))))
10792 rtx_code_label
*label
= gen_label_rtx ();
10793 int value
= TREE_CODE (rhs
) == BIT_IOR_EXPR
;
10794 do_jump (TREE_OPERAND (rhs
, 1),
10796 value
? 0 : label
, -1);
10797 expand_assignment (lhs
, build_int_cst (TREE_TYPE (rhs
), value
),
10799 do_pending_stack_adjust ();
10800 emit_label (label
);
10804 expand_assignment (lhs
, rhs
, false);
10809 return expand_expr_addr_expr (exp
, target
, tmode
, modifier
);
10811 case REALPART_EXPR
:
10812 op0
= expand_normal (treeop0
);
10813 return read_complex_part (op0
, false);
10815 case IMAGPART_EXPR
:
10816 op0
= expand_normal (treeop0
);
10817 return read_complex_part (op0
, true);
10824 /* Expanded in cfgexpand.c. */
10825 gcc_unreachable ();
10827 case TRY_CATCH_EXPR
:
10829 case EH_FILTER_EXPR
:
10830 case TRY_FINALLY_EXPR
:
10831 /* Lowered by tree-eh.c. */
10832 gcc_unreachable ();
10834 case WITH_CLEANUP_EXPR
:
10835 case CLEANUP_POINT_EXPR
:
10837 case CASE_LABEL_EXPR
:
10842 case COMPOUND_EXPR
:
10843 case PREINCREMENT_EXPR
:
10844 case PREDECREMENT_EXPR
:
10845 case POSTINCREMENT_EXPR
:
10846 case POSTDECREMENT_EXPR
:
10849 case COMPOUND_LITERAL_EXPR
:
10850 /* Lowered by gimplify.c. */
10851 gcc_unreachable ();
10854 /* Function descriptors are not valid except for as
10855 initialization constants, and should not be expanded. */
10856 gcc_unreachable ();
10858 case WITH_SIZE_EXPR
:
10859 /* WITH_SIZE_EXPR expands to its first argument. The caller should
10860 have pulled out the size to use in whatever context it needed. */
10861 return expand_expr_real (treeop0
, original_target
, tmode
,
10862 modifier
, alt_rtl
, inner_reference_p
);
10865 return expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
10869 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
10870 signedness of TYPE), possibly returning the result in TARGET. */
10872 reduce_to_bit_field_precision (rtx exp
, rtx target
, tree type
)
10874 HOST_WIDE_INT prec
= TYPE_PRECISION (type
);
10875 if (target
&& GET_MODE (target
) != GET_MODE (exp
))
10877 /* For constant values, reduce using build_int_cst_type. */
10878 if (CONST_INT_P (exp
))
10880 HOST_WIDE_INT value
= INTVAL (exp
);
10881 tree t
= build_int_cst_type (type
, value
);
10882 return expand_expr (t
, target
, VOIDmode
, EXPAND_NORMAL
);
10884 else if (TYPE_UNSIGNED (type
))
10886 machine_mode mode
= GET_MODE (exp
);
10887 rtx mask
= immed_wide_int_const
10888 (wi::mask (prec
, false, GET_MODE_PRECISION (mode
)), mode
);
10889 return expand_and (mode
, exp
, mask
, target
);
10893 int count
= GET_MODE_PRECISION (GET_MODE (exp
)) - prec
;
10894 exp
= expand_shift (LSHIFT_EXPR
, GET_MODE (exp
),
10895 exp
, count
, target
, 0);
10896 return expand_shift (RSHIFT_EXPR
, GET_MODE (exp
),
10897 exp
, count
, target
, 0);
10901 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
10902 when applied to the address of EXP produces an address known to be
10903 aligned more than BIGGEST_ALIGNMENT. */
10906 is_aligning_offset (const_tree offset
, const_tree exp
)
10908 /* Strip off any conversions. */
10909 while (CONVERT_EXPR_P (offset
))
10910 offset
= TREE_OPERAND (offset
, 0);
10912 /* We must now have a BIT_AND_EXPR with a constant that is one less than
10913 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
10914 if (TREE_CODE (offset
) != BIT_AND_EXPR
10915 || !tree_fits_uhwi_p (TREE_OPERAND (offset
, 1))
10916 || compare_tree_int (TREE_OPERAND (offset
, 1),
10917 BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) <= 0
10918 || exact_log2 (tree_to_uhwi (TREE_OPERAND (offset
, 1)) + 1) < 0)
10921 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
10922 It must be NEGATE_EXPR. Then strip any more conversions. */
10923 offset
= TREE_OPERAND (offset
, 0);
10924 while (CONVERT_EXPR_P (offset
))
10925 offset
= TREE_OPERAND (offset
, 0);
10927 if (TREE_CODE (offset
) != NEGATE_EXPR
)
10930 offset
= TREE_OPERAND (offset
, 0);
10931 while (CONVERT_EXPR_P (offset
))
10932 offset
= TREE_OPERAND (offset
, 0);
10934 /* This must now be the address of EXP. */
10935 return TREE_CODE (offset
) == ADDR_EXPR
&& TREE_OPERAND (offset
, 0) == exp
;
10938 /* Return the tree node if an ARG corresponds to a string constant or zero
10939 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
10940 in bytes within the string that ARG is accessing. The type of the
10941 offset will be `sizetype'. */
10944 string_constant (tree arg
, tree
*ptr_offset
)
10946 tree array
, offset
, lower_bound
;
10949 if (TREE_CODE (arg
) == ADDR_EXPR
)
10951 if (TREE_CODE (TREE_OPERAND (arg
, 0)) == STRING_CST
)
10953 *ptr_offset
= size_zero_node
;
10954 return TREE_OPERAND (arg
, 0);
10956 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == VAR_DECL
)
10958 array
= TREE_OPERAND (arg
, 0);
10959 offset
= size_zero_node
;
10961 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == ARRAY_REF
)
10963 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10964 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10965 if (TREE_CODE (array
) != STRING_CST
10966 && TREE_CODE (array
) != VAR_DECL
)
10969 /* Check if the array has a nonzero lower bound. */
10970 lower_bound
= array_ref_low_bound (TREE_OPERAND (arg
, 0));
10971 if (!integer_zerop (lower_bound
))
10973 /* If the offset and base aren't both constants, return 0. */
10974 if (TREE_CODE (lower_bound
) != INTEGER_CST
)
10976 if (TREE_CODE (offset
) != INTEGER_CST
)
10978 /* Adjust offset by the lower bound. */
10979 offset
= size_diffop (fold_convert (sizetype
, offset
),
10980 fold_convert (sizetype
, lower_bound
));
10983 else if (TREE_CODE (TREE_OPERAND (arg
, 0)) == MEM_REF
)
10985 array
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 0);
10986 offset
= TREE_OPERAND (TREE_OPERAND (arg
, 0), 1);
10987 if (TREE_CODE (array
) != ADDR_EXPR
)
10989 array
= TREE_OPERAND (array
, 0);
10990 if (TREE_CODE (array
) != STRING_CST
10991 && TREE_CODE (array
) != VAR_DECL
)
10997 else if (TREE_CODE (arg
) == PLUS_EXPR
|| TREE_CODE (arg
) == POINTER_PLUS_EXPR
)
10999 tree arg0
= TREE_OPERAND (arg
, 0);
11000 tree arg1
= TREE_OPERAND (arg
, 1);
11005 if (TREE_CODE (arg0
) == ADDR_EXPR
11006 && (TREE_CODE (TREE_OPERAND (arg0
, 0)) == STRING_CST
11007 || TREE_CODE (TREE_OPERAND (arg0
, 0)) == VAR_DECL
))
11009 array
= TREE_OPERAND (arg0
, 0);
11012 else if (TREE_CODE (arg1
) == ADDR_EXPR
11013 && (TREE_CODE (TREE_OPERAND (arg1
, 0)) == STRING_CST
11014 || TREE_CODE (TREE_OPERAND (arg1
, 0)) == VAR_DECL
))
11016 array
= TREE_OPERAND (arg1
, 0);
11025 if (TREE_CODE (array
) == STRING_CST
)
11027 *ptr_offset
= fold_convert (sizetype
, offset
);
11030 else if (TREE_CODE (array
) == VAR_DECL
11031 || TREE_CODE (array
) == CONST_DECL
)
11034 tree init
= ctor_for_folding (array
);
11036 /* Variables initialized to string literals can be handled too. */
11037 if (init
== error_mark_node
11039 || TREE_CODE (init
) != STRING_CST
)
11042 /* Avoid const char foo[4] = "abcde"; */
11043 if (DECL_SIZE_UNIT (array
) == NULL_TREE
11044 || TREE_CODE (DECL_SIZE_UNIT (array
)) != INTEGER_CST
11045 || (length
= TREE_STRING_LENGTH (init
)) <= 0
11046 || compare_tree_int (DECL_SIZE_UNIT (array
), length
) < 0)
11049 /* If variable is bigger than the string literal, OFFSET must be constant
11050 and inside of the bounds of the string literal. */
11051 offset
= fold_convert (sizetype
, offset
);
11052 if (compare_tree_int (DECL_SIZE_UNIT (array
), length
) > 0
11053 && (! tree_fits_uhwi_p (offset
)
11054 || compare_tree_int (offset
, length
) >= 0))
11057 *ptr_offset
= offset
;
11064 /* Generate code to calculate OPS, and exploded expression
11065 using a store-flag instruction and return an rtx for the result.
11066 OPS reflects a comparison.
11068 If TARGET is nonzero, store the result there if convenient.
11070 Return zero if there is no suitable set-flag instruction
11071 available on this machine.
11073 Once expand_expr has been called on the arguments of the comparison,
11074 we are committed to doing the store flag, since it is not safe to
11075 re-evaluate the expression. We emit the store-flag insn by calling
11076 emit_store_flag, but only expand the arguments if we have a reason
11077 to believe that emit_store_flag will be successful. If we think that
11078 it will, but it isn't, we have to simulate the store-flag with a
11079 set/jump/set sequence. */
11082 do_store_flag (sepops ops
, rtx target
, machine_mode mode
)
11084 enum rtx_code code
;
11085 tree arg0
, arg1
, type
;
11086 machine_mode operand_mode
;
11089 rtx subtarget
= target
;
11090 location_t loc
= ops
->location
;
11095 /* Don't crash if the comparison was erroneous. */
11096 if (arg0
== error_mark_node
|| arg1
== error_mark_node
)
11099 type
= TREE_TYPE (arg0
);
11100 operand_mode
= TYPE_MODE (type
);
11101 unsignedp
= TYPE_UNSIGNED (type
);
11103 /* We won't bother with BLKmode store-flag operations because it would mean
11104 passing a lot of information to emit_store_flag. */
11105 if (operand_mode
== BLKmode
)
11108 /* We won't bother with store-flag operations involving function pointers
11109 when function pointers must be canonicalized before comparisons. */
11110 if (targetm
.have_canonicalize_funcptr_for_compare ()
11111 && ((TREE_CODE (TREE_TYPE (arg0
)) == POINTER_TYPE
11112 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0
)))
11114 || (TREE_CODE (TREE_TYPE (arg1
)) == POINTER_TYPE
11115 && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1
)))
11116 == FUNCTION_TYPE
))))
11122 /* For vector typed comparisons emit code to generate the desired
11123 all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
11124 expander for this. */
11125 if (TREE_CODE (ops
->type
) == VECTOR_TYPE
)
11127 tree ifexp
= build2 (ops
->code
, ops
->type
, arg0
, arg1
);
11128 if (VECTOR_BOOLEAN_TYPE_P (ops
->type
)
11129 && expand_vec_cmp_expr_p (TREE_TYPE (arg0
), ops
->type
))
11130 return expand_vec_cmp_expr (ops
->type
, ifexp
, target
);
11133 tree if_true
= constant_boolean_node (true, ops
->type
);
11134 tree if_false
= constant_boolean_node (false, ops
->type
);
11135 return expand_vec_cond_expr (ops
->type
, ifexp
, if_true
,
11140 /* Get the rtx comparison code to use. We know that EXP is a comparison
11141 operation of some type. Some comparisons against 1 and -1 can be
11142 converted to comparisons with zero. Do so here so that the tests
11143 below will be aware that we have a comparison with zero. These
11144 tests will not catch constants in the first operand, but constants
11145 are rarely passed as the first operand. */
11156 if (integer_onep (arg1
))
11157 arg1
= integer_zero_node
, code
= unsignedp
? LEU
: LE
;
11159 code
= unsignedp
? LTU
: LT
;
11162 if (! unsignedp
&& integer_all_onesp (arg1
))
11163 arg1
= integer_zero_node
, code
= LT
;
11165 code
= unsignedp
? LEU
: LE
;
11168 if (! unsignedp
&& integer_all_onesp (arg1
))
11169 arg1
= integer_zero_node
, code
= GE
;
11171 code
= unsignedp
? GTU
: GT
;
11174 if (integer_onep (arg1
))
11175 arg1
= integer_zero_node
, code
= unsignedp
? GTU
: GT
;
11177 code
= unsignedp
? GEU
: GE
;
11180 case UNORDERED_EXPR
:
11206 gcc_unreachable ();
11209 /* Put a constant second. */
11210 if (TREE_CODE (arg0
) == REAL_CST
|| TREE_CODE (arg0
) == INTEGER_CST
11211 || TREE_CODE (arg0
) == FIXED_CST
)
11213 std::swap (arg0
, arg1
);
11214 code
= swap_condition (code
);
11217 /* If this is an equality or inequality test of a single bit, we can
11218 do this by shifting the bit being tested to the low-order bit and
11219 masking the result with the constant 1. If the condition was EQ,
11220 we xor it with 1. This does not require an scc insn and is faster
11221 than an scc insn even if we have it.
11223 The code to make this transformation was moved into fold_single_bit_test,
11224 so we just call into the folder and expand its result. */
11226 if ((code
== NE
|| code
== EQ
)
11227 && integer_zerop (arg1
)
11228 && (TYPE_PRECISION (ops
->type
) != 1 || TYPE_UNSIGNED (ops
->type
)))
11230 gimple
*srcstmt
= get_def_for_expr (arg0
, BIT_AND_EXPR
);
11232 && integer_pow2p (gimple_assign_rhs2 (srcstmt
)))
11234 enum tree_code tcode
= code
== NE
? NE_EXPR
: EQ_EXPR
;
11235 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11236 tree temp
= fold_build2_loc (loc
, BIT_AND_EXPR
, TREE_TYPE (arg1
),
11237 gimple_assign_rhs1 (srcstmt
),
11238 gimple_assign_rhs2 (srcstmt
));
11239 temp
= fold_single_bit_test (loc
, tcode
, temp
, arg1
, type
);
11241 return expand_expr (temp
, target
, VOIDmode
, EXPAND_NORMAL
);
11245 if (! get_subtarget (target
)
11246 || GET_MODE (subtarget
) != operand_mode
)
11249 expand_operands (arg0
, arg1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
11252 target
= gen_reg_rtx (mode
);
11254 /* Try a cstore if possible. */
11255 return emit_store_flag_force (target
, code
, op0
, op1
,
11256 operand_mode
, unsignedp
,
11257 (TYPE_PRECISION (ops
->type
) == 1
11258 && !TYPE_UNSIGNED (ops
->type
)) ? -1 : 1);
11261 /* Attempt to generate a casesi instruction. Returns 1 if successful,
11262 0 otherwise (i.e. if there is no casesi instruction).
11264 DEFAULT_PROBABILITY is the probability of jumping to the default
11267 try_casesi (tree index_type
, tree index_expr
, tree minval
, tree range
,
11268 rtx table_label
, rtx default_label
, rtx fallback_label
,
11269 int default_probability
)
11271 struct expand_operand ops
[5];
11272 machine_mode index_mode
= SImode
;
11273 rtx op1
, op2
, index
;
11275 if (! targetm
.have_casesi ())
11278 /* Convert the index to SImode. */
11279 if (GET_MODE_BITSIZE (TYPE_MODE (index_type
)) > GET_MODE_BITSIZE (index_mode
))
11281 machine_mode omode
= TYPE_MODE (index_type
);
11282 rtx rangertx
= expand_normal (range
);
11284 /* We must handle the endpoints in the original mode. */
11285 index_expr
= build2 (MINUS_EXPR
, index_type
,
11286 index_expr
, minval
);
11287 minval
= integer_zero_node
;
11288 index
= expand_normal (index_expr
);
11290 emit_cmp_and_jump_insns (rangertx
, index
, LTU
, NULL_RTX
,
11291 omode
, 1, default_label
,
11292 default_probability
);
11293 /* Now we can safely truncate. */
11294 index
= convert_to_mode (index_mode
, index
, 0);
11298 if (TYPE_MODE (index_type
) != index_mode
)
11300 index_type
= lang_hooks
.types
.type_for_mode (index_mode
, 0);
11301 index_expr
= fold_convert (index_type
, index_expr
);
11304 index
= expand_normal (index_expr
);
11307 do_pending_stack_adjust ();
11309 op1
= expand_normal (minval
);
11310 op2
= expand_normal (range
);
11312 create_input_operand (&ops
[0], index
, index_mode
);
11313 create_convert_operand_from_type (&ops
[1], op1
, TREE_TYPE (minval
));
11314 create_convert_operand_from_type (&ops
[2], op2
, TREE_TYPE (range
));
11315 create_fixed_operand (&ops
[3], table_label
);
11316 create_fixed_operand (&ops
[4], (default_label
11318 : fallback_label
));
11319 expand_jump_insn (targetm
.code_for_casesi
, 5, ops
);
11323 /* Attempt to generate a tablejump instruction; same concept. */
11324 /* Subroutine of the next function.
11326 INDEX is the value being switched on, with the lowest value
11327 in the table already subtracted.
11328 MODE is its expected mode (needed if INDEX is constant).
11329 RANGE is the length of the jump table.
11330 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
11332 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
11333 index value is out of range.
11334 DEFAULT_PROBABILITY is the probability of jumping to
11335 the default label. */
11338 do_tablejump (rtx index
, machine_mode mode
, rtx range
, rtx table_label
,
11339 rtx default_label
, int default_probability
)
11343 if (INTVAL (range
) > cfun
->cfg
->max_jumptable_ents
)
11344 cfun
->cfg
->max_jumptable_ents
= INTVAL (range
);
11346 /* Do an unsigned comparison (in the proper mode) between the index
11347 expression and the value which represents the length of the range.
11348 Since we just finished subtracting the lower bound of the range
11349 from the index expression, this comparison allows us to simultaneously
11350 check that the original index expression value is both greater than
11351 or equal to the minimum value of the range and less than or equal to
11352 the maximum value of the range. */
11355 emit_cmp_and_jump_insns (index
, range
, GTU
, NULL_RTX
, mode
, 1,
11356 default_label
, default_probability
);
11359 /* If index is in range, it must fit in Pmode.
11360 Convert to Pmode so we can index with it. */
11362 index
= convert_to_mode (Pmode
, index
, 1);
11364 /* Don't let a MEM slip through, because then INDEX that comes
11365 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
11366 and break_out_memory_refs will go to work on it and mess it up. */
11367 #ifdef PIC_CASE_VECTOR_ADDRESS
11368 if (flag_pic
&& !REG_P (index
))
11369 index
= copy_to_mode_reg (Pmode
, index
);
11372 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
11373 GET_MODE_SIZE, because this indicates how large insns are. The other
11374 uses should all be Pmode, because they are addresses. This code
11375 could fail if addresses and insns are not the same size. */
11376 index
= simplify_gen_binary (MULT
, Pmode
, index
,
11377 gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE
),
11379 index
= simplify_gen_binary (PLUS
, Pmode
, index
,
11380 gen_rtx_LABEL_REF (Pmode
, table_label
));
11382 #ifdef PIC_CASE_VECTOR_ADDRESS
11384 index
= PIC_CASE_VECTOR_ADDRESS (index
);
11387 index
= memory_address (CASE_VECTOR_MODE
, index
);
11388 temp
= gen_reg_rtx (CASE_VECTOR_MODE
);
11389 vector
= gen_const_mem (CASE_VECTOR_MODE
, index
);
11390 convert_move (temp
, vector
, 0);
11392 emit_jump_insn (targetm
.gen_tablejump (temp
, table_label
));
11394 /* If we are generating PIC code or if the table is PC-relative, the
11395 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
11396 if (! CASE_VECTOR_PC_RELATIVE
&& ! flag_pic
)
11401 try_tablejump (tree index_type
, tree index_expr
, tree minval
, tree range
,
11402 rtx table_label
, rtx default_label
, int default_probability
)
11406 if (! targetm
.have_tablejump ())
11409 index_expr
= fold_build2 (MINUS_EXPR
, index_type
,
11410 fold_convert (index_type
, index_expr
),
11411 fold_convert (index_type
, minval
));
11412 index
= expand_normal (index_expr
);
11413 do_pending_stack_adjust ();
11415 do_tablejump (index
, TYPE_MODE (index_type
),
11416 convert_modes (TYPE_MODE (index_type
),
11417 TYPE_MODE (TREE_TYPE (range
)),
11418 expand_normal (range
),
11419 TYPE_UNSIGNED (TREE_TYPE (range
))),
11420 table_label
, default_label
, default_probability
);
11424 /* Return a CONST_VECTOR rtx representing vector mask for
11425 a VECTOR_CST of booleans. */
11427 const_vector_mask_from_tree (tree exp
)
11433 machine_mode inner
, mode
;
11435 mode
= TYPE_MODE (TREE_TYPE (exp
));
11436 units
= GET_MODE_NUNITS (mode
);
11437 inner
= GET_MODE_INNER (mode
);
11439 v
= rtvec_alloc (units
);
11441 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
11443 elt
= VECTOR_CST_ELT (exp
, i
);
11445 gcc_assert (TREE_CODE (elt
) == INTEGER_CST
);
11446 if (integer_zerop (elt
))
11447 RTVEC_ELT (v
, i
) = CONST0_RTX (inner
);
11448 else if (integer_onep (elt
)
11449 || integer_minus_onep (elt
))
11450 RTVEC_ELT (v
, i
) = CONSTM1_RTX (inner
);
11452 gcc_unreachable ();
11455 return gen_rtx_CONST_VECTOR (mode
, v
);
11458 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
11460 const_vector_from_tree (tree exp
)
11466 machine_mode inner
, mode
;
11468 mode
= TYPE_MODE (TREE_TYPE (exp
));
11470 if (initializer_zerop (exp
))
11471 return CONST0_RTX (mode
);
11473 if (VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (exp
)))
11474 return const_vector_mask_from_tree (exp
);
11476 units
= GET_MODE_NUNITS (mode
);
11477 inner
= GET_MODE_INNER (mode
);
11479 v
= rtvec_alloc (units
);
11481 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
11483 elt
= VECTOR_CST_ELT (exp
, i
);
11485 if (TREE_CODE (elt
) == REAL_CST
)
11486 RTVEC_ELT (v
, i
) = const_double_from_real_value (TREE_REAL_CST (elt
),
11488 else if (TREE_CODE (elt
) == FIXED_CST
)
11489 RTVEC_ELT (v
, i
) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt
),
11492 RTVEC_ELT (v
, i
) = immed_wide_int_const (elt
, inner
);
11495 return gen_rtx_CONST_VECTOR (mode
, v
);
11498 /* Build a decl for a personality function given a language prefix. */
11501 build_personality_function (const char *lang
)
11503 const char *unwind_and_version
;
11507 switch (targetm_common
.except_unwind_info (&global_options
))
11512 unwind_and_version
= "_sj0";
11516 unwind_and_version
= "_v0";
11519 unwind_and_version
= "_seh0";
11522 gcc_unreachable ();
11525 name
= ACONCAT (("__", lang
, "_personality", unwind_and_version
, NULL
));
11527 type
= build_function_type_list (integer_type_node
, integer_type_node
,
11528 long_long_unsigned_type_node
,
11529 ptr_type_node
, ptr_type_node
, NULL_TREE
);
11530 decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
11531 get_identifier (name
), type
);
11532 DECL_ARTIFICIAL (decl
) = 1;
11533 DECL_EXTERNAL (decl
) = 1;
11534 TREE_PUBLIC (decl
) = 1;
11536 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
11537 are the flags assigned by targetm.encode_section_info. */
11538 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl
), 0), NULL
);
11543 /* Extracts the personality function of DECL and returns the corresponding
11547 get_personality_function (tree decl
)
11549 tree personality
= DECL_FUNCTION_PERSONALITY (decl
);
11550 enum eh_personality_kind pk
;
11552 pk
= function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl
));
11553 if (pk
== eh_personality_none
)
11557 && pk
== eh_personality_any
)
11558 personality
= lang_hooks
.eh_personality ();
11560 if (pk
== eh_personality_lang
)
11561 gcc_assert (personality
!= NULL_TREE
);
11563 return XEXP (DECL_RTL (personality
), 0);
11566 /* Returns a tree for the size of EXP in bytes. */
11569 tree_expr_size (const_tree exp
)
11572 && DECL_SIZE_UNIT (exp
) != 0)
11573 return DECL_SIZE_UNIT (exp
);
11575 return size_in_bytes (TREE_TYPE (exp
));
11578 /* Return an rtx for the size in bytes of the value of EXP. */
11581 expr_size (tree exp
)
11585 if (TREE_CODE (exp
) == WITH_SIZE_EXPR
)
11586 size
= TREE_OPERAND (exp
, 1);
11589 size
= tree_expr_size (exp
);
11591 gcc_assert (size
== SUBSTITUTE_PLACEHOLDER_IN_EXPR (size
, exp
));
11594 return expand_expr (size
, NULL_RTX
, TYPE_MODE (sizetype
), EXPAND_NORMAL
);
11597 /* Return a wide integer for the size in bytes of the value of EXP, or -1
11598 if the size can vary or is larger than an integer. */
11600 static HOST_WIDE_INT
11601 int_expr_size (tree exp
)
11605 if (TREE_CODE (exp
) == WITH_SIZE_EXPR
)
11606 size
= TREE_OPERAND (exp
, 1);
11609 size
= tree_expr_size (exp
);
11613 if (size
== 0 || !tree_fits_shwi_p (size
))
11616 return tree_to_shwi (size
);
11619 #include "gt-expr.h"