1 /* Convert tree expression to rtl instructions, for GNU compiler.
2 Copyright (C) 1988-2024 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"
38 #include "diagnostic.h"
40 #include "fold-const.h"
41 #include "stor-layout.h"
45 #include "insn-attr.h"
50 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
52 #include "optabs-tree.h"
55 #include "langhooks.h"
56 #include "common/common-target.h"
58 #include "tree-ssa-live.h"
59 #include "tree-outof-ssa.h"
60 #include "tree-ssa-address.h"
63 #include "gimple-iterator.h"
64 #include "gimple-fold.h"
65 #include "rtx-vector-builder.h"
66 #include "tree-pretty-print.h"
70 /* If this is nonzero, we do not bother generating VOLATILE
71 around volatile memory references, and we are willing to
72 output indirect addresses. If cse is to follow, we reject
73 indirect addresses so a useful potential cse is generated;
74 if it is used only once, instruction combination will produce
75 the same indirect address eventually. */
78 static bool block_move_libcall_safe_for_call_parm (void);
79 static bool emit_block_move_via_pattern (rtx
, rtx
, rtx
, unsigned, unsigned,
80 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
,
81 unsigned HOST_WIDE_INT
,
82 unsigned HOST_WIDE_INT
, bool);
83 static void emit_block_move_via_loop (rtx
, rtx
, rtx
, unsigned, int);
84 static void emit_block_move_via_sized_loop (rtx
, rtx
, rtx
, unsigned, unsigned);
85 static void emit_block_move_via_oriented_loop (rtx
, rtx
, rtx
, unsigned, unsigned);
86 static rtx
emit_block_cmp_via_loop (rtx
, rtx
, rtx
, tree
, rtx
, bool,
88 static void clear_by_pieces (rtx
, unsigned HOST_WIDE_INT
, unsigned int);
89 static rtx_insn
*compress_float_constant (rtx
, rtx
);
90 static rtx
get_subtarget (rtx
);
91 static rtx
store_field (rtx
, poly_int64
, poly_int64
, poly_uint64
, poly_uint64
,
92 machine_mode
, tree
, alias_set_type
, bool, bool);
94 static unsigned HOST_WIDE_INT
highest_pow2_factor_for_target (const_tree
, const_tree
);
96 static bool is_aligning_offset (const_tree
, const_tree
);
97 static rtx
reduce_to_bit_field_precision (rtx
, rtx
, tree
);
98 static rtx
do_store_flag (sepops
, rtx
, machine_mode
);
100 static void emit_single_push_insn (machine_mode
, rtx
, tree
);
102 static void do_tablejump (rtx
, machine_mode
, rtx
, rtx
, rtx
,
103 profile_probability
);
104 static rtx
const_vector_from_tree (tree
);
105 static tree
tree_expr_size (const_tree
);
106 static void convert_mode_scalar (rtx
, rtx
, int);
109 /* This is run to set up which modes can be used
110 directly in memory and to initialize the block move optab. It is run
111 at the beginning of compilation and when the target is reinitialized. */
114 init_expr_target (void)
121 /* Try indexing by frame ptr and try by stack ptr.
122 It is known that on the Convex the stack ptr isn't a valid index.
123 With luck, one or the other is valid on any machine. */
124 mem
= gen_rtx_MEM (word_mode
, stack_pointer_rtx
);
125 mem1
= gen_rtx_MEM (word_mode
, frame_pointer_rtx
);
127 /* A scratch register we can modify in-place below to avoid
128 useless RTL allocations. */
129 reg
= gen_rtx_REG (word_mode
, LAST_VIRTUAL_REGISTER
+ 1);
131 rtx_insn
*insn
= as_a
<rtx_insn
*> (rtx_alloc (INSN
));
132 pat
= gen_rtx_SET (NULL_RTX
, NULL_RTX
);
133 PATTERN (insn
) = pat
;
135 for (machine_mode mode
= VOIDmode
; (int) mode
< NUM_MACHINE_MODES
;
136 mode
= (machine_mode
) ((int) mode
+ 1))
140 direct_load
[(int) mode
] = direct_store
[(int) mode
] = 0;
141 PUT_MODE (mem
, mode
);
142 PUT_MODE (mem1
, mode
);
144 /* See if there is some register that can be used in this mode and
145 directly loaded or stored from memory. */
147 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
148 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
149 && (direct_load
[(int) mode
] == 0 || direct_store
[(int) mode
] == 0);
152 if (!targetm
.hard_regno_mode_ok (regno
, mode
))
155 set_mode_and_regno (reg
, mode
, regno
);
158 SET_DEST (pat
) = reg
;
159 if (recog (pat
, insn
, &num_clobbers
) >= 0)
160 direct_load
[(int) mode
] = 1;
162 SET_SRC (pat
) = mem1
;
163 SET_DEST (pat
) = reg
;
164 if (recog (pat
, insn
, &num_clobbers
) >= 0)
165 direct_load
[(int) mode
] = 1;
168 SET_DEST (pat
) = mem
;
169 if (recog (pat
, insn
, &num_clobbers
) >= 0)
170 direct_store
[(int) mode
] = 1;
173 SET_DEST (pat
) = mem1
;
174 if (recog (pat
, insn
, &num_clobbers
) >= 0)
175 direct_store
[(int) mode
] = 1;
179 mem
= gen_rtx_MEM (VOIDmode
, gen_raw_REG (Pmode
, LAST_VIRTUAL_REGISTER
+ 1));
181 opt_scalar_float_mode mode_iter
;
182 FOR_EACH_MODE_IN_CLASS (mode_iter
, MODE_FLOAT
)
184 scalar_float_mode mode
= mode_iter
.require ();
185 scalar_float_mode srcmode
;
186 FOR_EACH_MODE_UNTIL (srcmode
, mode
)
190 ic
= can_extend_p (mode
, srcmode
, 0);
191 if (ic
== CODE_FOR_nothing
)
194 PUT_MODE (mem
, srcmode
);
196 if (insn_operand_matches (ic
, 1, mem
))
197 float_extend_from_mem
[mode
][srcmode
] = true;
202 /* This is run at the start of compiling a function. */
207 memset (&crtl
->expr
, 0, sizeof (crtl
->expr
));
210 /* Copy data from FROM to TO, where the machine modes are not the same.
211 Both modes may be integer, or both may be floating, or both may be
213 UNSIGNEDP should be nonzero if FROM is an unsigned type.
214 This causes zero-extension instead of sign-extension. */
217 convert_move (rtx to
, rtx from
, int unsignedp
)
219 machine_mode to_mode
= GET_MODE (to
);
220 machine_mode from_mode
= GET_MODE (from
);
222 gcc_assert (to_mode
!= BLKmode
);
223 gcc_assert (from_mode
!= BLKmode
);
225 /* If the source and destination are already the same, then there's
230 /* If FROM is a SUBREG that indicates that we have already done at least
231 the required extension, strip it. We don't handle such SUBREGs as
234 scalar_int_mode to_int_mode
;
235 if (GET_CODE (from
) == SUBREG
236 && SUBREG_PROMOTED_VAR_P (from
)
237 && is_a
<scalar_int_mode
> (to_mode
, &to_int_mode
)
238 && (GET_MODE_PRECISION (subreg_promoted_mode (from
))
239 >= GET_MODE_PRECISION (to_int_mode
))
240 && SUBREG_CHECK_PROMOTED_SIGN (from
, unsignedp
))
242 scalar_int_mode int_orig_mode
;
243 scalar_int_mode int_inner_mode
;
244 machine_mode orig_mode
= GET_MODE (from
);
246 from
= gen_lowpart (to_int_mode
, SUBREG_REG (from
));
247 from_mode
= to_int_mode
;
249 /* Preserve SUBREG_PROMOTED_VAR_P if the new mode is wider than
250 the original mode, but narrower than the inner mode. */
251 if (GET_CODE (from
) == SUBREG
252 && is_a
<scalar_int_mode
> (orig_mode
, &int_orig_mode
)
253 && GET_MODE_PRECISION (to_int_mode
)
254 > GET_MODE_PRECISION (int_orig_mode
)
255 && is_a
<scalar_int_mode
> (GET_MODE (SUBREG_REG (from
)),
257 && GET_MODE_PRECISION (int_inner_mode
)
258 > GET_MODE_PRECISION (to_int_mode
))
260 SUBREG_PROMOTED_VAR_P (from
) = 1;
261 SUBREG_PROMOTED_SET (from
, unsignedp
);
265 gcc_assert (GET_CODE (to
) != SUBREG
|| !SUBREG_PROMOTED_VAR_P (to
));
267 if (to_mode
== from_mode
268 || (from_mode
== VOIDmode
&& CONSTANT_P (from
)))
270 emit_move_insn (to
, from
);
274 if (VECTOR_MODE_P (to_mode
) || VECTOR_MODE_P (from_mode
))
276 if (GET_MODE_UNIT_PRECISION (to_mode
)
277 > GET_MODE_UNIT_PRECISION (from_mode
))
279 optab op
= unsignedp
? zext_optab
: sext_optab
;
280 insn_code icode
= convert_optab_handler (op
, to_mode
, from_mode
);
281 if (icode
!= CODE_FOR_nothing
)
283 emit_unop_insn (icode
, to
, from
,
284 unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
);
289 if (GET_MODE_UNIT_PRECISION (to_mode
)
290 < GET_MODE_UNIT_PRECISION (from_mode
))
292 insn_code icode
= convert_optab_handler (trunc_optab
,
294 if (icode
!= CODE_FOR_nothing
)
296 emit_unop_insn (icode
, to
, from
, TRUNCATE
);
301 gcc_assert (known_eq (GET_MODE_BITSIZE (from_mode
),
302 GET_MODE_BITSIZE (to_mode
)));
304 if (VECTOR_MODE_P (to_mode
))
305 from
= simplify_gen_subreg (to_mode
, from
, GET_MODE (from
), 0);
307 to
= simplify_gen_subreg (from_mode
, to
, GET_MODE (to
), 0);
309 emit_move_insn (to
, from
);
313 if (GET_CODE (to
) == CONCAT
&& GET_CODE (from
) == CONCAT
)
315 convert_move (XEXP (to
, 0), XEXP (from
, 0), unsignedp
);
316 convert_move (XEXP (to
, 1), XEXP (from
, 1), unsignedp
);
320 convert_mode_scalar (to
, from
, unsignedp
);
323 /* Like convert_move, but deals only with scalar modes. */
326 convert_mode_scalar (rtx to
, rtx from
, int unsignedp
)
328 /* Both modes should be scalar types. */
329 scalar_mode from_mode
= as_a
<scalar_mode
> (GET_MODE (from
));
330 scalar_mode to_mode
= as_a
<scalar_mode
> (GET_MODE (to
));
331 bool to_real
= SCALAR_FLOAT_MODE_P (to_mode
);
332 bool from_real
= SCALAR_FLOAT_MODE_P (from_mode
);
336 gcc_assert (to_real
== from_real
);
338 /* rtx code for making an equivalent value. */
339 enum rtx_code equiv_code
= (unsignedp
< 0 ? UNKNOWN
340 : (unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
));
348 gcc_assert ((GET_MODE_PRECISION (from_mode
)
349 != GET_MODE_PRECISION (to_mode
))
350 || (DECIMAL_FLOAT_MODE_P (from_mode
)
351 != DECIMAL_FLOAT_MODE_P (to_mode
))
352 || (REAL_MODE_FORMAT (from_mode
) == &arm_bfloat_half_format
353 && REAL_MODE_FORMAT (to_mode
) == &ieee_half_format
)
354 || (REAL_MODE_FORMAT (to_mode
) == &arm_bfloat_half_format
355 && REAL_MODE_FORMAT (from_mode
) == &ieee_half_format
));
357 if (GET_MODE_PRECISION (from_mode
) == GET_MODE_PRECISION (to_mode
))
358 /* Conversion between decimal float and binary float, same size. */
359 tab
= DECIMAL_FLOAT_MODE_P (from_mode
) ? trunc_optab
: sext_optab
;
360 else if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
))
365 /* Try converting directly if the insn is supported. */
367 code
= convert_optab_handler (tab
, to_mode
, from_mode
);
368 if (code
!= CODE_FOR_nothing
)
370 emit_unop_insn (code
, to
, from
,
371 tab
== sext_optab
? FLOAT_EXTEND
: FLOAT_TRUNCATE
);
376 if (REAL_MODE_FORMAT (from_mode
) == &arm_bfloat_half_format
377 && REAL_MODE_FORMAT (SFmode
) == &ieee_single_format
)
379 if (GET_MODE_PRECISION (to_mode
) > GET_MODE_PRECISION (SFmode
))
381 /* To cut down on libgcc size, implement
382 BFmode -> {DF,XF,TF}mode conversions by
383 BFmode -> SFmode -> {DF,XF,TF}mode conversions. */
384 rtx temp
= gen_reg_rtx (SFmode
);
385 convert_mode_scalar (temp
, from
, unsignedp
);
386 convert_mode_scalar (to
, temp
, unsignedp
);
389 if (REAL_MODE_FORMAT (to_mode
) == &ieee_half_format
)
391 /* Similarly, implement BFmode -> HFmode as
392 BFmode -> SFmode -> HFmode conversion where SFmode
393 has superset of BFmode values. We don't need
394 to handle sNaNs by raising exception and turning
395 into into qNaN though, as that can be done in the
396 SFmode -> HFmode conversion too. */
397 rtx temp
= gen_reg_rtx (SFmode
);
398 int save_flag_finite_math_only
= flag_finite_math_only
;
399 flag_finite_math_only
= true;
400 convert_mode_scalar (temp
, from
, unsignedp
);
401 flag_finite_math_only
= save_flag_finite_math_only
;
402 convert_mode_scalar (to
, temp
, unsignedp
);
405 if (to_mode
== SFmode
406 && !HONOR_NANS (from_mode
)
407 && !HONOR_NANS (to_mode
)
408 && optimize_insn_for_speed_p ())
410 /* If we don't expect sNaNs, for BFmode -> SFmode we can just
411 shift the bits up. */
412 machine_mode fromi_mode
, toi_mode
;
413 if (int_mode_for_size (GET_MODE_BITSIZE (from_mode
),
414 0).exists (&fromi_mode
)
415 && int_mode_for_size (GET_MODE_BITSIZE (to_mode
),
416 0).exists (&toi_mode
))
419 rtx fromi
= lowpart_subreg (fromi_mode
, from
, from_mode
);
424 if (GET_MODE (fromi
) == VOIDmode
)
425 toi
= simplify_unary_operation (ZERO_EXTEND
, toi_mode
,
429 toi
= gen_reg_rtx (toi_mode
);
430 convert_mode_scalar (toi
, fromi
, 1);
433 = maybe_expand_shift (LSHIFT_EXPR
, toi_mode
, toi
,
434 GET_MODE_PRECISION (to_mode
)
435 - GET_MODE_PRECISION (from_mode
),
439 tof
= lowpart_subreg (to_mode
, toi
, toi_mode
);
441 emit_move_insn (to
, tof
);
444 insns
= get_insns ();
454 if (REAL_MODE_FORMAT (from_mode
) == &ieee_single_format
455 && REAL_MODE_FORMAT (to_mode
) == &arm_bfloat_half_format
456 && !HONOR_NANS (from_mode
)
457 && !HONOR_NANS (to_mode
)
458 && !flag_rounding_math
459 && optimize_insn_for_speed_p ())
461 /* If we don't expect qNaNs nor sNaNs and can assume rounding
462 to nearest, we can expand the conversion inline as
463 (fromi + 0x7fff + ((fromi >> 16) & 1)) >> 16. */
464 machine_mode fromi_mode
, toi_mode
;
465 if (int_mode_for_size (GET_MODE_BITSIZE (from_mode
),
466 0).exists (&fromi_mode
)
467 && int_mode_for_size (GET_MODE_BITSIZE (to_mode
),
468 0).exists (&toi_mode
))
471 rtx fromi
= lowpart_subreg (fromi_mode
, from
, from_mode
);
477 int shift
= (GET_MODE_PRECISION (from_mode
)
478 - GET_MODE_PRECISION (to_mode
));
480 = maybe_expand_shift (RSHIFT_EXPR
, fromi_mode
, fromi
,
485 = expand_binop (fromi_mode
, and_optab
, temp1
, const1_rtx
,
486 NULL_RTX
, 1, OPTAB_DIRECT
);
490 = expand_binop (fromi_mode
, add_optab
, fromi
,
491 gen_int_mode ((HOST_WIDE_INT_1U
493 fromi_mode
), NULL_RTX
,
498 = expand_binop (fromi_mode
, add_optab
, temp3
, temp2
,
499 NULL_RTX
, 1, OPTAB_DIRECT
);
502 rtx temp5
= maybe_expand_shift (RSHIFT_EXPR
, fromi_mode
,
503 temp4
, shift
, NULL_RTX
, 1);
506 rtx temp6
= lowpart_subreg (toi_mode
, temp5
, fromi_mode
);
509 tof
= lowpart_subreg (to_mode
, force_reg (toi_mode
, temp6
),
512 emit_move_insn (to
, tof
);
515 insns
= get_insns ();
526 /* Otherwise use a libcall. */
527 libcall
= convert_optab_libfunc (tab
, to_mode
, from_mode
);
529 /* Is this conversion implemented yet? */
530 gcc_assert (libcall
);
533 value
= emit_library_call_value (libcall
, NULL_RTX
, LCT_CONST
, to_mode
,
535 insns
= get_insns ();
537 emit_libcall_block (insns
, to
, value
,
538 tab
== trunc_optab
? gen_rtx_FLOAT_TRUNCATE (to_mode
,
540 : gen_rtx_FLOAT_EXTEND (to_mode
, from
));
544 /* Handle pointer conversion. */ /* SPEE 900220. */
545 /* If the target has a converter from FROM_MODE to TO_MODE, use it. */
549 if (GET_MODE_PRECISION (from_mode
) > GET_MODE_PRECISION (to_mode
))
556 if (convert_optab_handler (ctab
, to_mode
, from_mode
)
559 emit_unop_insn (convert_optab_handler (ctab
, to_mode
, from_mode
),
565 /* Targets are expected to provide conversion insns between PxImode and
566 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
567 if (GET_MODE_CLASS (to_mode
) == MODE_PARTIAL_INT
)
569 scalar_int_mode full_mode
570 = smallest_int_mode_for_size (GET_MODE_BITSIZE (to_mode
));
572 gcc_assert (convert_optab_handler (trunc_optab
, to_mode
, full_mode
)
573 != CODE_FOR_nothing
);
575 if (full_mode
!= from_mode
)
576 from
= convert_to_mode (full_mode
, from
, unsignedp
);
577 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, full_mode
),
581 if (GET_MODE_CLASS (from_mode
) == MODE_PARTIAL_INT
)
584 scalar_int_mode full_mode
585 = smallest_int_mode_for_size (GET_MODE_BITSIZE (from_mode
));
586 convert_optab ctab
= unsignedp
? zext_optab
: sext_optab
;
587 enum insn_code icode
;
589 icode
= convert_optab_handler (ctab
, full_mode
, from_mode
);
590 gcc_assert (icode
!= CODE_FOR_nothing
);
592 if (to_mode
== full_mode
)
594 emit_unop_insn (icode
, to
, from
, UNKNOWN
);
598 new_from
= gen_reg_rtx (full_mode
);
599 emit_unop_insn (icode
, new_from
, from
, UNKNOWN
);
601 /* else proceed to integer conversions below. */
602 from_mode
= full_mode
;
606 /* Make sure both are fixed-point modes or both are not. */
607 gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
) ==
608 ALL_SCALAR_FIXED_POINT_MODE_P (to_mode
));
609 if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode
))
611 /* If we widen from_mode to to_mode and they are in the same class,
612 we won't saturate the result.
613 Otherwise, always saturate the result to play safe. */
614 if (GET_MODE_CLASS (from_mode
) == GET_MODE_CLASS (to_mode
)
615 && GET_MODE_SIZE (from_mode
) < GET_MODE_SIZE (to_mode
))
616 expand_fixed_convert (to
, from
, 0, 0);
618 expand_fixed_convert (to
, from
, 0, 1);
622 /* Now both modes are integers. */
624 /* Handle expanding beyond a word. */
625 if (GET_MODE_PRECISION (from_mode
) < GET_MODE_PRECISION (to_mode
)
626 && GET_MODE_PRECISION (to_mode
) > BITS_PER_WORD
)
633 scalar_mode lowpart_mode
;
634 int nwords
= CEIL (GET_MODE_SIZE (to_mode
), UNITS_PER_WORD
);
636 /* Try converting directly if the insn is supported. */
637 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
640 /* If FROM is a SUBREG, put it into a register. Do this
641 so that we always generate the same set of insns for
642 better cse'ing; if an intermediate assignment occurred,
643 we won't be doing the operation directly on the SUBREG. */
644 if (optimize
> 0 && GET_CODE (from
) == SUBREG
)
645 from
= force_reg (from_mode
, from
);
646 emit_unop_insn (code
, to
, from
, equiv_code
);
649 /* Next, try converting via full word. */
650 else if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
651 && ((code
= can_extend_p (to_mode
, word_mode
, unsignedp
))
652 != CODE_FOR_nothing
))
654 rtx word_to
= gen_reg_rtx (word_mode
);
657 if (reg_overlap_mentioned_p (to
, from
))
658 from
= force_reg (from_mode
, from
);
661 convert_move (word_to
, from
, unsignedp
);
662 emit_unop_insn (code
, to
, word_to
, equiv_code
);
666 /* No special multiword conversion insn; do it by hand. */
669 /* Since we will turn this into a no conflict block, we must ensure
670 the source does not overlap the target so force it into an isolated
671 register when maybe so. Likewise for any MEM input, since the
672 conversion sequence might require several references to it and we
673 must ensure we're getting the same value every time. */
675 if (MEM_P (from
) || reg_overlap_mentioned_p (to
, from
))
676 from
= force_reg (from_mode
, from
);
678 /* Get a copy of FROM widened to a word, if necessary. */
679 if (GET_MODE_PRECISION (from_mode
) < BITS_PER_WORD
)
680 lowpart_mode
= word_mode
;
682 lowpart_mode
= from_mode
;
684 lowfrom
= convert_to_mode (lowpart_mode
, from
, unsignedp
);
686 lowpart
= gen_lowpart (lowpart_mode
, to
);
687 emit_move_insn (lowpart
, lowfrom
);
689 /* Compute the value to put in each remaining word. */
691 fill_value
= const0_rtx
;
693 fill_value
= emit_store_flag_force (gen_reg_rtx (word_mode
),
694 LT
, lowfrom
, const0_rtx
,
695 lowpart_mode
, 0, -1);
697 /* Fill the remaining words. */
698 for (i
= GET_MODE_SIZE (lowpart_mode
) / UNITS_PER_WORD
; i
< nwords
; i
++)
700 int index
= (WORDS_BIG_ENDIAN
? nwords
- i
- 1 : i
);
701 rtx subword
= operand_subword (to
, index
, 1, to_mode
);
703 gcc_assert (subword
);
705 if (fill_value
!= subword
)
706 emit_move_insn (subword
, fill_value
);
709 insns
= get_insns ();
716 /* Truncating multi-word to a word or less. */
717 if (GET_MODE_PRECISION (from_mode
) > BITS_PER_WORD
718 && GET_MODE_PRECISION (to_mode
) <= BITS_PER_WORD
)
721 && ! MEM_VOLATILE_P (from
)
722 && direct_load
[(int) to_mode
]
723 && ! mode_dependent_address_p (XEXP (from
, 0),
724 MEM_ADDR_SPACE (from
)))
726 || GET_CODE (from
) == SUBREG
))
727 from
= force_reg (from_mode
, from
);
728 convert_move (to
, gen_lowpart (word_mode
, from
), 0);
732 /* Now follow all the conversions between integers
733 no more than a word long. */
735 /* For truncation, usually we can just refer to FROM in a narrower mode. */
736 if (GET_MODE_BITSIZE (to_mode
) < GET_MODE_BITSIZE (from_mode
)
737 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
, from_mode
))
740 && ! MEM_VOLATILE_P (from
)
741 && direct_load
[(int) to_mode
]
742 && ! mode_dependent_address_p (XEXP (from
, 0),
743 MEM_ADDR_SPACE (from
)))
745 || GET_CODE (from
) == SUBREG
))
746 from
= force_reg (from_mode
, from
);
747 if (REG_P (from
) && REGNO (from
) < FIRST_PSEUDO_REGISTER
748 && !targetm
.hard_regno_mode_ok (REGNO (from
), to_mode
))
749 from
= copy_to_reg (from
);
750 emit_move_insn (to
, gen_lowpart (to_mode
, from
));
754 /* Handle extension. */
755 if (GET_MODE_PRECISION (to_mode
) > GET_MODE_PRECISION (from_mode
))
757 /* Convert directly if that works. */
758 if ((code
= can_extend_p (to_mode
, from_mode
, unsignedp
))
761 emit_unop_insn (code
, to
, from
, equiv_code
);
769 /* Search for a mode to convert via. */
770 opt_scalar_mode intermediate_iter
;
771 FOR_EACH_MODE_FROM (intermediate_iter
, from_mode
)
773 scalar_mode intermediate
= intermediate_iter
.require ();
774 if (((can_extend_p (to_mode
, intermediate
, unsignedp
)
776 || (GET_MODE_SIZE (to_mode
) < GET_MODE_SIZE (intermediate
)
777 && TRULY_NOOP_TRUNCATION_MODES_P (to_mode
,
779 && (can_extend_p (intermediate
, from_mode
, unsignedp
)
780 != CODE_FOR_nothing
))
782 convert_move (to
, convert_to_mode (intermediate
, from
,
783 unsignedp
), unsignedp
);
788 /* No suitable intermediate mode.
789 Generate what we need with shifts. */
790 shift_amount
= (GET_MODE_PRECISION (to_mode
)
791 - GET_MODE_PRECISION (from_mode
));
792 from
= gen_lowpart (to_mode
, force_reg (from_mode
, from
));
793 tmp
= expand_shift (LSHIFT_EXPR
, to_mode
, from
, shift_amount
,
795 tmp
= expand_shift (RSHIFT_EXPR
, to_mode
, tmp
, shift_amount
,
798 emit_move_insn (to
, tmp
);
803 /* Support special truncate insns for certain modes. */
804 if (convert_optab_handler (trunc_optab
, to_mode
,
805 from_mode
) != CODE_FOR_nothing
)
807 emit_unop_insn (convert_optab_handler (trunc_optab
, to_mode
, from_mode
),
812 /* Handle truncation of volatile memrefs, and so on;
813 the things that couldn't be truncated directly,
814 and for which there was no special instruction.
816 ??? Code above formerly short-circuited this, for most integer
817 mode pairs, with a force_reg in from_mode followed by a recursive
818 call to this routine. Appears always to have been wrong. */
819 if (GET_MODE_PRECISION (to_mode
) < GET_MODE_PRECISION (from_mode
))
821 rtx temp
= force_reg (to_mode
, gen_lowpart (to_mode
, from
));
822 emit_move_insn (to
, temp
);
826 /* Mode combination is not recognized. */
830 /* Return an rtx for a value that would result
831 from converting X to mode MODE.
832 Both X and MODE may be floating, or both integer.
833 UNSIGNEDP is nonzero if X is an unsigned value.
834 This can be done by referring to a part of X in place
835 or by copying to a new temporary with conversion. */
838 convert_to_mode (machine_mode mode
, rtx x
, int unsignedp
)
840 return convert_modes (mode
, VOIDmode
, x
, unsignedp
);
843 /* Return an rtx for a value that would result
844 from converting X from mode OLDMODE to mode MODE.
845 Both modes may be floating, or both integer.
846 UNSIGNEDP is nonzero if X is an unsigned value.
848 This can be done by referring to a part of X in place
849 or by copying to a new temporary with conversion.
851 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
854 convert_modes (machine_mode mode
, machine_mode oldmode
, rtx x
, int unsignedp
)
857 scalar_int_mode int_mode
;
859 /* If FROM is a SUBREG that indicates that we have already done at least
860 the required extension, strip it. */
862 if (GET_CODE (x
) == SUBREG
863 && SUBREG_PROMOTED_VAR_P (x
)
864 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
865 && (GET_MODE_PRECISION (subreg_promoted_mode (x
))
866 >= GET_MODE_PRECISION (int_mode
))
867 && SUBREG_CHECK_PROMOTED_SIGN (x
, unsignedp
))
869 scalar_int_mode int_orig_mode
;
870 scalar_int_mode int_inner_mode
;
871 machine_mode orig_mode
= GET_MODE (x
);
872 x
= gen_lowpart (int_mode
, SUBREG_REG (x
));
874 /* Preserve SUBREG_PROMOTED_VAR_P if the new mode is wider than
875 the original mode, but narrower than the inner mode. */
876 if (GET_CODE (x
) == SUBREG
877 && is_a
<scalar_int_mode
> (orig_mode
, &int_orig_mode
)
878 && GET_MODE_PRECISION (int_mode
)
879 > GET_MODE_PRECISION (int_orig_mode
)
880 && is_a
<scalar_int_mode
> (GET_MODE (SUBREG_REG (x
)),
882 && GET_MODE_PRECISION (int_inner_mode
)
883 > GET_MODE_PRECISION (int_mode
))
885 SUBREG_PROMOTED_VAR_P (x
) = 1;
886 SUBREG_PROMOTED_SET (x
, unsignedp
);
890 if (GET_MODE (x
) != VOIDmode
)
891 oldmode
= GET_MODE (x
);
896 if (CONST_SCALAR_INT_P (x
)
897 && is_a
<scalar_int_mode
> (mode
, &int_mode
))
899 /* If the caller did not tell us the old mode, then there is not
900 much to do with respect to canonicalization. We have to
901 assume that all the bits are significant. */
902 if (!is_a
<scalar_int_mode
> (oldmode
))
903 oldmode
= MAX_MODE_INT
;
904 wide_int w
= wide_int::from (rtx_mode_t (x
, oldmode
),
905 GET_MODE_PRECISION (int_mode
),
906 unsignedp
? UNSIGNED
: SIGNED
);
907 return immed_wide_int_const (w
, int_mode
);
910 /* We can do this with a gen_lowpart if both desired and current modes
911 are integer, and this is either a constant integer, a register, or a
913 scalar_int_mode int_oldmode
;
914 if (is_int_mode (mode
, &int_mode
)
915 && is_int_mode (oldmode
, &int_oldmode
)
916 && GET_MODE_PRECISION (int_mode
) <= GET_MODE_PRECISION (int_oldmode
)
917 && ((MEM_P (x
) && !MEM_VOLATILE_P (x
) && direct_load
[(int) int_mode
])
918 || CONST_POLY_INT_P (x
)
920 && (!HARD_REGISTER_P (x
)
921 || targetm
.hard_regno_mode_ok (REGNO (x
), int_mode
))
922 && TRULY_NOOP_TRUNCATION_MODES_P (int_mode
, GET_MODE (x
)))))
923 return gen_lowpart (int_mode
, x
);
925 /* Converting from integer constant into mode is always equivalent to an
927 if (VECTOR_MODE_P (mode
) && GET_MODE (x
) == VOIDmode
)
929 gcc_assert (known_eq (GET_MODE_BITSIZE (mode
),
930 GET_MODE_BITSIZE (oldmode
)));
931 return simplify_gen_subreg (mode
, x
, oldmode
, 0);
934 temp
= gen_reg_rtx (mode
);
935 convert_move (temp
, x
, unsignedp
);
939 /* Variant of convert_modes for ABI parameter passing/return.
940 Return an rtx for a value that would result from converting X from
941 a floating point mode FMODE to wider integer mode MODE. */
944 convert_float_to_wider_int (machine_mode mode
, machine_mode fmode
, rtx x
)
946 gcc_assert (SCALAR_INT_MODE_P (mode
) && SCALAR_FLOAT_MODE_P (fmode
));
947 scalar_int_mode tmp_mode
= int_mode_for_mode (fmode
).require ();
948 rtx tmp
= force_reg (tmp_mode
, gen_lowpart (tmp_mode
, x
));
949 return convert_modes (mode
, tmp_mode
, tmp
, 1);
952 /* Variant of convert_modes for ABI parameter passing/return.
953 Return an rtx for a value that would result from converting X from
954 an integer mode IMODE to a narrower floating point mode MODE. */
957 convert_wider_int_to_float (machine_mode mode
, machine_mode imode
, rtx x
)
959 gcc_assert (SCALAR_FLOAT_MODE_P (mode
) && SCALAR_INT_MODE_P (imode
));
960 scalar_int_mode tmp_mode
= int_mode_for_mode (mode
).require ();
961 rtx tmp
= force_reg (tmp_mode
, gen_lowpart (tmp_mode
, x
));
962 return gen_lowpart_SUBREG (mode
, tmp
);
965 /* Return the largest alignment we can use for doing a move (or store)
966 of MAX_PIECES. ALIGN is the largest alignment we could use. */
969 alignment_for_piecewise_move (unsigned int max_pieces
, unsigned int align
)
971 scalar_int_mode tmode
972 = int_mode_for_size (max_pieces
* BITS_PER_UNIT
, 0).require ();
974 if (align
>= GET_MODE_ALIGNMENT (tmode
))
975 align
= GET_MODE_ALIGNMENT (tmode
);
978 scalar_int_mode xmode
= NARROWEST_INT_MODE
;
979 opt_scalar_int_mode mode_iter
;
980 FOR_EACH_MODE_IN_CLASS (mode_iter
, MODE_INT
)
982 tmode
= mode_iter
.require ();
983 if (GET_MODE_SIZE (tmode
) > max_pieces
984 || targetm
.slow_unaligned_access (tmode
, align
))
989 align
= MAX (align
, GET_MODE_ALIGNMENT (xmode
));
995 /* Return true if we know how to implement OP using vectors of bytes. */
997 can_use_qi_vectors (by_pieces_operation op
)
999 return (op
== COMPARE_BY_PIECES
1000 || op
== SET_BY_PIECES
1001 || op
== CLEAR_BY_PIECES
);
1004 /* Return true if optabs exists for the mode and certain by pieces
1007 by_pieces_mode_supported_p (fixed_size_mode mode
, by_pieces_operation op
)
1009 if (optab_handler (mov_optab
, mode
) == CODE_FOR_nothing
)
1012 if ((op
== SET_BY_PIECES
|| op
== CLEAR_BY_PIECES
)
1013 && VECTOR_MODE_P (mode
)
1014 && optab_handler (vec_duplicate_optab
, mode
) == CODE_FOR_nothing
)
1017 if (op
== COMPARE_BY_PIECES
1018 && !can_compare_p (EQ
, mode
, ccp_jump
))
1024 /* Return the widest mode that can be used to perform part of an
1025 operation OP on SIZE bytes. Try to use QI vector modes where
1027 static fixed_size_mode
1028 widest_fixed_size_mode_for_size (unsigned int size
, by_pieces_operation op
)
1030 fixed_size_mode result
= NARROWEST_INT_MODE
;
1032 gcc_checking_assert (size
> 1);
1034 /* Use QI vector only if size is wider than a WORD. */
1035 if (can_use_qi_vectors (op
) && size
> UNITS_PER_WORD
)
1038 fixed_size_mode candidate
;
1039 FOR_EACH_MODE_IN_CLASS (mode
, MODE_VECTOR_INT
)
1040 if (is_a
<fixed_size_mode
> (mode
, &candidate
)
1041 && GET_MODE_INNER (candidate
) == QImode
)
1043 if (GET_MODE_SIZE (candidate
) >= size
)
1045 if (by_pieces_mode_supported_p (candidate
, op
))
1049 if (result
!= NARROWEST_INT_MODE
)
1053 opt_scalar_int_mode tmode
;
1054 scalar_int_mode mode
;
1055 FOR_EACH_MODE_IN_CLASS (tmode
, MODE_INT
)
1057 mode
= tmode
.require ();
1058 if (GET_MODE_SIZE (mode
) < size
1059 && by_pieces_mode_supported_p (mode
, op
))
1066 /* Determine whether an operation OP on LEN bytes with alignment ALIGN can
1067 and should be performed piecewise. */
1070 can_do_by_pieces (unsigned HOST_WIDE_INT len
, unsigned int align
,
1071 enum by_pieces_operation op
)
1073 return targetm
.use_by_pieces_infrastructure_p (len
, align
, op
,
1074 optimize_insn_for_speed_p ());
1077 /* Determine whether the LEN bytes can be moved by using several move
1078 instructions. Return nonzero if a call to move_by_pieces should
1082 can_move_by_pieces (unsigned HOST_WIDE_INT len
, unsigned int align
)
1084 return can_do_by_pieces (len
, align
, MOVE_BY_PIECES
);
1087 /* Return number of insns required to perform operation OP by pieces
1088 for L bytes. ALIGN (in bits) is maximum alignment we can assume. */
1090 unsigned HOST_WIDE_INT
1091 by_pieces_ninsns (unsigned HOST_WIDE_INT l
, unsigned int align
,
1092 unsigned int max_size
, by_pieces_operation op
)
1094 unsigned HOST_WIDE_INT n_insns
= 0;
1095 fixed_size_mode mode
;
1097 if (targetm
.overlap_op_by_pieces_p ())
1099 /* NB: Round up L and ALIGN to the widest integer mode for
1101 mode
= widest_fixed_size_mode_for_size (max_size
, op
);
1102 gcc_assert (optab_handler (mov_optab
, mode
) != CODE_FOR_nothing
);
1103 unsigned HOST_WIDE_INT up
= ROUND_UP (l
, GET_MODE_SIZE (mode
));
1106 align
= GET_MODE_ALIGNMENT (mode
);
1109 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
1111 while (max_size
> 1 && l
> 0)
1113 mode
= widest_fixed_size_mode_for_size (max_size
, op
);
1114 gcc_assert (optab_handler (mov_optab
, mode
) != CODE_FOR_nothing
);
1116 unsigned int modesize
= GET_MODE_SIZE (mode
);
1118 if (align
>= GET_MODE_ALIGNMENT (mode
))
1120 unsigned HOST_WIDE_INT n_pieces
= l
/ modesize
;
1125 n_insns
+= n_pieces
;
1128 case COMPARE_BY_PIECES
:
1129 int batch
= targetm
.compare_by_pieces_branch_ratio (mode
);
1130 int batch_ops
= 4 * batch
- 1;
1131 unsigned HOST_WIDE_INT full
= n_pieces
/ batch
;
1132 n_insns
+= full
* batch_ops
;
1133 if (n_pieces
% batch
!= 0)
1139 max_size
= modesize
;
1146 /* Used when performing piecewise block operations, holds information
1147 about one of the memory objects involved. The member functions
1148 can be used to generate code for loading from the object and
1149 updating the address when iterating. */
1153 /* The object being referenced, a MEM. Can be NULL_RTX to indicate
1156 /* The address of the object. Can differ from that seen in the
1157 MEM rtx if we copied the address to a register. */
1159 /* Nonzero if the address on the object has an autoincrement already,
1160 signifies whether that was an increment or decrement. */
1161 signed char m_addr_inc
;
1162 /* Nonzero if we intend to use autoinc without the address already
1163 having autoinc form. We will insert add insns around each memory
1164 reference, expecting later passes to form autoinc addressing modes.
1165 The only supported options are predecrement and postincrement. */
1166 signed char m_explicit_inc
;
1167 /* True if we have either of the two possible cases of using
1170 /* True if this is an address to be used for load operations rather
1174 /* Optionally, a function to obtain constants for any given offset into
1175 the objects, and data associated with it. */
1176 by_pieces_constfn m_constfn
;
1179 pieces_addr (rtx
, bool, by_pieces_constfn
, void *);
1180 rtx
adjust (fixed_size_mode
, HOST_WIDE_INT
, by_pieces_prev
* = nullptr);
1181 void increment_address (HOST_WIDE_INT
);
1182 void maybe_predec (HOST_WIDE_INT
);
1183 void maybe_postinc (HOST_WIDE_INT
);
1184 void decide_autoinc (machine_mode
, bool, HOST_WIDE_INT
);
1191 /* Initialize a pieces_addr structure from an object OBJ. IS_LOAD is
1192 true if the operation to be performed on this object is a load
1193 rather than a store. For stores, OBJ can be NULL, in which case we
1194 assume the operation is a stack push. For loads, the optional
1195 CONSTFN and its associated CFNDATA can be used in place of the
1198 pieces_addr::pieces_addr (rtx obj
, bool is_load
, by_pieces_constfn constfn
,
1200 : m_obj (obj
), m_is_load (is_load
), m_constfn (constfn
), m_cfndata (cfndata
)
1206 rtx addr
= XEXP (obj
, 0);
1207 rtx_code code
= GET_CODE (addr
);
1209 bool dec
= code
== PRE_DEC
|| code
== POST_DEC
;
1210 bool inc
= code
== PRE_INC
|| code
== POST_INC
;
1211 m_auto
= inc
|| dec
;
1213 m_addr_inc
= dec
? -1 : 1;
1215 /* While we have always looked for these codes here, the code
1216 implementing the memory operation has never handled them.
1217 Support could be added later if necessary or beneficial. */
1218 gcc_assert (code
!= PRE_INC
&& code
!= POST_DEC
);
1226 if (STACK_GROWS_DOWNWARD
)
1232 gcc_assert (constfn
!= NULL
);
1236 gcc_assert (is_load
);
1239 /* Decide whether to use autoinc for an address involved in a memory op.
1240 MODE is the mode of the accesses, REVERSE is true if we've decided to
1241 perform the operation starting from the end, and LEN is the length of
1242 the operation. Don't override an earlier decision to set m_auto. */
1245 pieces_addr::decide_autoinc (machine_mode
ARG_UNUSED (mode
), bool reverse
,
1248 if (m_auto
|| m_obj
== NULL_RTX
)
1251 bool use_predec
= (m_is_load
1252 ? USE_LOAD_PRE_DECREMENT (mode
)
1253 : USE_STORE_PRE_DECREMENT (mode
));
1254 bool use_postinc
= (m_is_load
1255 ? USE_LOAD_POST_INCREMENT (mode
)
1256 : USE_STORE_POST_INCREMENT (mode
));
1257 machine_mode addr_mode
= get_address_mode (m_obj
);
1259 if (use_predec
&& reverse
)
1261 m_addr
= copy_to_mode_reg (addr_mode
,
1262 plus_constant (addr_mode
,
1265 m_explicit_inc
= -1;
1267 else if (use_postinc
&& !reverse
)
1269 m_addr
= copy_to_mode_reg (addr_mode
, m_addr
);
1273 else if (CONSTANT_P (m_addr
))
1274 m_addr
= copy_to_mode_reg (addr_mode
, m_addr
);
1277 /* Adjust the address to refer to the data at OFFSET in MODE. If we
1278 are using autoincrement for this address, we don't add the offset,
1279 but we still modify the MEM's properties. */
1282 pieces_addr::adjust (fixed_size_mode mode
, HOST_WIDE_INT offset
,
1283 by_pieces_prev
*prev
)
1286 /* Pass the previous data to m_constfn. */
1287 return m_constfn (m_cfndata
, prev
, offset
, mode
);
1288 if (m_obj
== NULL_RTX
)
1291 return adjust_automodify_address (m_obj
, mode
, m_addr
, offset
);
1293 return adjust_address (m_obj
, mode
, offset
);
1296 /* Emit an add instruction to increment the address by SIZE. */
1299 pieces_addr::increment_address (HOST_WIDE_INT size
)
1301 rtx amount
= gen_int_mode (size
, GET_MODE (m_addr
));
1302 emit_insn (gen_add2_insn (m_addr
, amount
));
1305 /* If we are supposed to decrement the address after each access, emit code
1306 to do so now. Increment by SIZE (which has should have the correct sign
1310 pieces_addr::maybe_predec (HOST_WIDE_INT size
)
1312 if (m_explicit_inc
>= 0)
1314 gcc_assert (HAVE_PRE_DECREMENT
);
1315 increment_address (size
);
1318 /* If we are supposed to decrement the address after each access, emit code
1319 to do so now. Increment by SIZE. */
1322 pieces_addr::maybe_postinc (HOST_WIDE_INT size
)
1324 if (m_explicit_inc
<= 0)
1326 gcc_assert (HAVE_POST_INCREMENT
);
1327 increment_address (size
);
1330 /* This structure is used by do_op_by_pieces to describe the operation
1333 class op_by_pieces_d
1336 fixed_size_mode
get_usable_mode (fixed_size_mode
, unsigned int);
1337 fixed_size_mode
smallest_fixed_size_mode_for_size (unsigned int);
1340 pieces_addr m_to
, m_from
;
1341 /* Make m_len read-only so that smallest_fixed_size_mode_for_size can
1342 use it to check the valid mode size. */
1343 const unsigned HOST_WIDE_INT m_len
;
1344 HOST_WIDE_INT m_offset
;
1345 unsigned int m_align
;
1346 unsigned int m_max_size
;
1348 /* True if this is a stack push. */
1350 /* True if targetm.overlap_op_by_pieces_p () returns true. */
1351 bool m_overlap_op_by_pieces
;
1352 /* The type of operation that we're performing. */
1353 by_pieces_operation m_op
;
1355 /* Virtual functions, overriden by derived classes for the specific
1357 virtual void generate (rtx
, rtx
, machine_mode
) = 0;
1358 virtual bool prepare_mode (machine_mode
, unsigned int) = 0;
1359 virtual void finish_mode (machine_mode
)
1364 op_by_pieces_d (unsigned int, rtx
, bool, rtx
, bool, by_pieces_constfn
,
1365 void *, unsigned HOST_WIDE_INT
, unsigned int, bool,
1366 by_pieces_operation
);
1370 /* The constructor for an op_by_pieces_d structure. We require two
1371 objects named TO and FROM, which are identified as loads or stores
1372 by TO_LOAD and FROM_LOAD. If FROM is a load, the optional FROM_CFN
1373 and its associated FROM_CFN_DATA can be used to replace loads with
1374 constant values. MAX_PIECES describes the maximum number of bytes
1375 at a time which can be moved efficiently. LEN describes the length
1376 of the operation. */
1378 op_by_pieces_d::op_by_pieces_d (unsigned int max_pieces
, rtx to
,
1379 bool to_load
, rtx from
, bool from_load
,
1380 by_pieces_constfn from_cfn
,
1381 void *from_cfn_data
,
1382 unsigned HOST_WIDE_INT len
,
1383 unsigned int align
, bool push
,
1384 by_pieces_operation op
)
1385 : m_to (to
, to_load
, NULL
, NULL
),
1386 m_from (from
, from_load
, from_cfn
, from_cfn_data
),
1387 m_len (len
), m_max_size (max_pieces
+ 1),
1388 m_push (push
), m_op (op
)
1390 int toi
= m_to
.get_addr_inc ();
1391 int fromi
= m_from
.get_addr_inc ();
1392 if (toi
>= 0 && fromi
>= 0)
1394 else if (toi
<= 0 && fromi
<= 0)
1399 m_offset
= m_reverse
? len
: 0;
1400 align
= MIN (to
? MEM_ALIGN (to
) : align
,
1401 from
? MEM_ALIGN (from
) : align
);
1403 /* If copying requires more than two move insns,
1404 copy addresses to registers (to make displacements shorter)
1405 and use post-increment if available. */
1406 if (by_pieces_ninsns (len
, align
, m_max_size
, MOVE_BY_PIECES
) > 2)
1408 /* Find the mode of the largest comparison. */
1409 fixed_size_mode mode
1410 = widest_fixed_size_mode_for_size (m_max_size
, m_op
);
1412 m_from
.decide_autoinc (mode
, m_reverse
, len
);
1413 m_to
.decide_autoinc (mode
, m_reverse
, len
);
1416 align
= alignment_for_piecewise_move (MOVE_MAX_PIECES
, align
);
1419 m_overlap_op_by_pieces
= targetm
.overlap_op_by_pieces_p ();
1422 /* This function returns the largest usable integer mode for LEN bytes
1423 whose size is no bigger than size of MODE. */
1426 op_by_pieces_d::get_usable_mode (fixed_size_mode mode
, unsigned int len
)
1431 size
= GET_MODE_SIZE (mode
);
1432 if (len
>= size
&& prepare_mode (mode
, m_align
))
1434 /* widest_fixed_size_mode_for_size checks SIZE > 1. */
1435 mode
= widest_fixed_size_mode_for_size (size
, m_op
);
1441 /* Return the smallest integer or QI vector mode that is not narrower
1445 op_by_pieces_d::smallest_fixed_size_mode_for_size (unsigned int size
)
1447 /* Use QI vector only for > size of WORD. */
1448 if (can_use_qi_vectors (m_op
) && size
> UNITS_PER_WORD
)
1451 fixed_size_mode candidate
;
1452 FOR_EACH_MODE_IN_CLASS (mode
, MODE_VECTOR_INT
)
1453 if (is_a
<fixed_size_mode
> (mode
, &candidate
)
1454 && GET_MODE_INNER (candidate
) == QImode
)
1456 /* Don't return a mode wider than M_LEN. */
1457 if (GET_MODE_SIZE (candidate
) > m_len
)
1460 if (GET_MODE_SIZE (candidate
) >= size
1461 && by_pieces_mode_supported_p (candidate
, m_op
))
1466 return smallest_int_mode_for_size (size
* BITS_PER_UNIT
);
1469 /* This function contains the main loop used for expanding a block
1470 operation. First move what we can in the largest integer mode,
1471 then go to successively smaller modes. For every access, call
1472 GENFUN with the two operands and the EXTRA_DATA. */
1475 op_by_pieces_d::run ()
1480 unsigned HOST_WIDE_INT length
= m_len
;
1482 /* widest_fixed_size_mode_for_size checks M_MAX_SIZE > 1. */
1483 fixed_size_mode mode
1484 = widest_fixed_size_mode_for_size (m_max_size
, m_op
);
1485 mode
= get_usable_mode (mode
, length
);
1487 by_pieces_prev to_prev
= { nullptr, mode
};
1488 by_pieces_prev from_prev
= { nullptr, mode
};
1492 unsigned int size
= GET_MODE_SIZE (mode
);
1493 rtx to1
= NULL_RTX
, from1
;
1495 while (length
>= size
)
1500 to1
= m_to
.adjust (mode
, m_offset
, &to_prev
);
1502 to_prev
.mode
= mode
;
1503 from1
= m_from
.adjust (mode
, m_offset
, &from_prev
);
1504 from_prev
.data
= from1
;
1505 from_prev
.mode
= mode
;
1507 m_to
.maybe_predec (-(HOST_WIDE_INT
)size
);
1508 m_from
.maybe_predec (-(HOST_WIDE_INT
)size
);
1510 generate (to1
, from1
, mode
);
1512 m_to
.maybe_postinc (size
);
1513 m_from
.maybe_postinc (size
);
1526 if (!m_push
&& m_overlap_op_by_pieces
)
1528 /* NB: Generate overlapping operations if it is not a stack
1529 push since stack push must not overlap. Get the smallest
1530 fixed size mode for M_LEN bytes. */
1531 mode
= smallest_fixed_size_mode_for_size (length
);
1532 mode
= get_usable_mode (mode
, GET_MODE_SIZE (mode
));
1533 int gap
= GET_MODE_SIZE (mode
) - length
;
1536 /* If size of MODE > M_LEN, generate the last operation
1537 in MODE for the remaining bytes with ovelapping memory
1538 from the previois operation. */
1548 /* widest_fixed_size_mode_for_size checks SIZE > 1. */
1549 mode
= widest_fixed_size_mode_for_size (size
, m_op
);
1550 mode
= get_usable_mode (mode
, length
);
1556 /* Derived class from op_by_pieces_d, providing support for block move
1559 #ifdef PUSH_ROUNDING
1560 #define PUSHG_P(to) ((to) == nullptr)
1562 #define PUSHG_P(to) false
1565 class move_by_pieces_d
: public op_by_pieces_d
1567 insn_gen_fn m_gen_fun
;
1568 void generate (rtx
, rtx
, machine_mode
) final override
;
1569 bool prepare_mode (machine_mode
, unsigned int) final override
;
1572 move_by_pieces_d (rtx to
, rtx from
, unsigned HOST_WIDE_INT len
,
1574 : op_by_pieces_d (MOVE_MAX_PIECES
, to
, false, from
, true, NULL
,
1575 NULL
, len
, align
, PUSHG_P (to
), MOVE_BY_PIECES
)
1578 rtx
finish_retmode (memop_ret
);
1581 /* Return true if MODE can be used for a set of copies, given an
1582 alignment ALIGN. Prepare whatever data is necessary for later
1583 calls to generate. */
1586 move_by_pieces_d::prepare_mode (machine_mode mode
, unsigned int align
)
1588 insn_code icode
= optab_handler (mov_optab
, mode
);
1589 m_gen_fun
= GEN_FCN (icode
);
1590 return icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
);
1593 /* A callback used when iterating for a compare_by_pieces_operation.
1594 OP0 and OP1 are the values that have been loaded and should be
1595 compared in MODE. If OP0 is NULL, this means we should generate a
1596 push; otherwise EXTRA_DATA holds a pointer to a pointer to the insn
1597 gen function that should be used to generate the mode. */
1600 move_by_pieces_d::generate (rtx op0
, rtx op1
,
1601 machine_mode mode ATTRIBUTE_UNUSED
)
1603 #ifdef PUSH_ROUNDING
1604 if (op0
== NULL_RTX
)
1606 emit_single_push_insn (mode
, op1
, NULL
);
1610 emit_insn (m_gen_fun (op0
, op1
));
1613 /* Perform the final adjustment at the end of a string to obtain the
1614 correct return value for the block operation.
1615 Return value is based on RETMODE argument. */
1618 move_by_pieces_d::finish_retmode (memop_ret retmode
)
1620 gcc_assert (!m_reverse
);
1621 if (retmode
== RETURN_END_MINUS_ONE
)
1623 m_to
.maybe_postinc (-1);
1626 return m_to
.adjust (QImode
, m_offset
);
1629 /* Generate several move instructions to copy LEN bytes from block FROM to
1630 block TO. (These are MEM rtx's with BLKmode).
1632 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
1633 used to push FROM to the stack.
1635 ALIGN is maximum stack alignment we can assume.
1637 Return value is based on RETMODE argument. */
1640 move_by_pieces (rtx to
, rtx from
, unsigned HOST_WIDE_INT len
,
1641 unsigned int align
, memop_ret retmode
)
1643 #ifndef PUSH_ROUNDING
1648 move_by_pieces_d
data (to
, from
, len
, align
);
1652 if (retmode
!= RETURN_BEGIN
)
1653 return data
.finish_retmode (retmode
);
1658 /* Derived class from op_by_pieces_d, providing support for block move
1661 class store_by_pieces_d
: public op_by_pieces_d
1663 insn_gen_fn m_gen_fun
;
1665 void generate (rtx
, rtx
, machine_mode
) final override
;
1666 bool prepare_mode (machine_mode
, unsigned int) final override
;
1669 store_by_pieces_d (rtx to
, by_pieces_constfn cfn
, void *cfn_data
,
1670 unsigned HOST_WIDE_INT len
, unsigned int align
,
1671 by_pieces_operation op
)
1672 : op_by_pieces_d (STORE_MAX_PIECES
, to
, false, NULL_RTX
, true, cfn
,
1673 cfn_data
, len
, align
, false, op
)
1676 rtx
finish_retmode (memop_ret
);
1679 /* Return true if MODE can be used for a set of stores, given an
1680 alignment ALIGN. Prepare whatever data is necessary for later
1681 calls to generate. */
1684 store_by_pieces_d::prepare_mode (machine_mode mode
, unsigned int align
)
1686 insn_code icode
= optab_handler (mov_optab
, mode
);
1687 m_gen_fun
= GEN_FCN (icode
);
1688 return icode
!= CODE_FOR_nothing
&& align
>= GET_MODE_ALIGNMENT (mode
);
1691 /* A callback used when iterating for a store_by_pieces_operation.
1692 OP0 and OP1 are the values that have been loaded and should be
1693 compared in MODE. If OP0 is NULL, this means we should generate a
1694 push; otherwise EXTRA_DATA holds a pointer to a pointer to the insn
1695 gen function that should be used to generate the mode. */
1698 store_by_pieces_d::generate (rtx op0
, rtx op1
, machine_mode
)
1700 emit_insn (m_gen_fun (op0
, op1
));
1703 /* Perform the final adjustment at the end of a string to obtain the
1704 correct return value for the block operation.
1705 Return value is based on RETMODE argument. */
1708 store_by_pieces_d::finish_retmode (memop_ret retmode
)
1710 gcc_assert (!m_reverse
);
1711 if (retmode
== RETURN_END_MINUS_ONE
)
1713 m_to
.maybe_postinc (-1);
1716 return m_to
.adjust (QImode
, m_offset
);
1719 /* Determine whether the LEN bytes generated by CONSTFUN can be
1720 stored to memory using several move instructions. CONSTFUNDATA is
1721 a pointer which will be passed as argument in every CONSTFUN call.
1722 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
1723 a memset operation and false if it's a copy of a constant string.
1724 Return true if a call to store_by_pieces should succeed. */
1727 can_store_by_pieces (unsigned HOST_WIDE_INT len
,
1728 by_pieces_constfn constfun
,
1729 void *constfundata
, unsigned int align
, bool memsetp
)
1731 unsigned HOST_WIDE_INT l
;
1732 unsigned int max_size
;
1733 HOST_WIDE_INT offset
= 0;
1734 enum insn_code icode
;
1736 /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
1737 rtx cst ATTRIBUTE_UNUSED
;
1742 if (!targetm
.use_by_pieces_infrastructure_p (len
, align
,
1746 optimize_insn_for_speed_p ()))
1749 align
= alignment_for_piecewise_move (STORE_MAX_PIECES
, align
);
1751 /* We would first store what we can in the largest integer mode, then go to
1752 successively smaller modes. */
1755 reverse
<= (HAVE_PRE_DECREMENT
|| HAVE_POST_DECREMENT
);
1759 max_size
= STORE_MAX_PIECES
+ 1;
1760 while (max_size
> 1 && l
> 0)
1762 auto op
= memsetp
? SET_BY_PIECES
: STORE_BY_PIECES
;
1763 auto mode
= widest_fixed_size_mode_for_size (max_size
, op
);
1765 icode
= optab_handler (mov_optab
, mode
);
1766 if (icode
!= CODE_FOR_nothing
1767 && align
>= GET_MODE_ALIGNMENT (mode
))
1769 unsigned int size
= GET_MODE_SIZE (mode
);
1776 cst
= (*constfun
) (constfundata
, nullptr, offset
, mode
);
1777 /* All CONST_VECTORs can be loaded for memset since
1778 vec_duplicate_optab is a precondition to pick a
1779 vector mode for the memset expander. */
1780 if (!((memsetp
&& VECTOR_MODE_P (mode
))
1781 || targetm
.legitimate_constant_p (mode
, cst
)))
1791 max_size
= GET_MODE_SIZE (mode
);
1794 /* The code above should have handled everything. */
1801 /* Generate several move instructions to store LEN bytes generated by
1802 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
1803 pointer which will be passed as argument in every CONSTFUN call.
1804 ALIGN is maximum alignment we can assume. MEMSETP is true if this is
1805 a memset operation and false if it's a copy of a constant string.
1806 Return value is based on RETMODE argument. */
1809 store_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
,
1810 by_pieces_constfn constfun
,
1811 void *constfundata
, unsigned int align
, bool memsetp
,
1816 gcc_assert (retmode
!= RETURN_END_MINUS_ONE
);
1820 gcc_assert (targetm
.use_by_pieces_infrastructure_p
1822 memsetp
? SET_BY_PIECES
: STORE_BY_PIECES
,
1823 optimize_insn_for_speed_p ()));
1825 store_by_pieces_d
data (to
, constfun
, constfundata
, len
, align
,
1826 memsetp
? SET_BY_PIECES
: STORE_BY_PIECES
);
1829 if (retmode
!= RETURN_BEGIN
)
1830 return data
.finish_retmode (retmode
);
1835 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
1836 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
1839 clear_by_pieces (rtx to
, unsigned HOST_WIDE_INT len
, unsigned int align
)
1844 /* Use builtin_memset_read_str to support vector mode broadcast. */
1846 store_by_pieces_d
data (to
, builtin_memset_read_str
, &c
, len
, align
,
1851 /* Context used by compare_by_pieces_genfn. It stores the fail label
1852 to jump to in case of miscomparison, and for branch ratios greater than 1,
1853 it stores an accumulator and the current and maximum counts before
1854 emitting another branch. */
1856 class compare_by_pieces_d
: public op_by_pieces_d
1858 rtx_code_label
*m_fail_label
;
1860 int m_count
, m_batch
;
1862 void generate (rtx
, rtx
, machine_mode
) final override
;
1863 bool prepare_mode (machine_mode
, unsigned int) final override
;
1864 void finish_mode (machine_mode
) final override
;
1867 compare_by_pieces_d (rtx op0
, rtx op1
, by_pieces_constfn op1_cfn
,
1868 void *op1_cfn_data
, HOST_WIDE_INT len
, int align
,
1869 rtx_code_label
*fail_label
)
1870 : op_by_pieces_d (COMPARE_MAX_PIECES
, op0
, true, op1
, true, op1_cfn
,
1871 op1_cfn_data
, len
, align
, false, COMPARE_BY_PIECES
)
1873 m_fail_label
= fail_label
;
1877 /* A callback used when iterating for a compare_by_pieces_operation.
1878 OP0 and OP1 are the values that have been loaded and should be
1879 compared in MODE. DATA holds a pointer to the compare_by_pieces_data
1880 context structure. */
1883 compare_by_pieces_d::generate (rtx op0
, rtx op1
, machine_mode mode
)
1887 rtx temp
= expand_binop (mode
, sub_optab
, op0
, op1
, NULL_RTX
,
1888 true, OPTAB_LIB_WIDEN
);
1890 temp
= expand_binop (mode
, ior_optab
, m_accumulator
, temp
, temp
,
1891 true, OPTAB_LIB_WIDEN
);
1892 m_accumulator
= temp
;
1894 if (++m_count
< m_batch
)
1898 op0
= m_accumulator
;
1900 m_accumulator
= NULL_RTX
;
1902 do_compare_rtx_and_jump (op0
, op1
, NE
, true, mode
, NULL_RTX
, NULL
,
1903 m_fail_label
, profile_probability::uninitialized ());
1906 /* Return true if MODE can be used for a set of moves and comparisons,
1907 given an alignment ALIGN. Prepare whatever data is necessary for
1908 later calls to generate. */
1911 compare_by_pieces_d::prepare_mode (machine_mode mode
, unsigned int align
)
1913 insn_code icode
= optab_handler (mov_optab
, mode
);
1914 if (icode
== CODE_FOR_nothing
1915 || align
< GET_MODE_ALIGNMENT (mode
)
1916 || !can_compare_p (EQ
, mode
, ccp_jump
))
1918 m_batch
= targetm
.compare_by_pieces_branch_ratio (mode
);
1921 m_accumulator
= NULL_RTX
;
1926 /* Called after expanding a series of comparisons in MODE. If we have
1927 accumulated results for which we haven't emitted a branch yet, do
1931 compare_by_pieces_d::finish_mode (machine_mode mode
)
1933 if (m_accumulator
!= NULL_RTX
)
1934 do_compare_rtx_and_jump (m_accumulator
, const0_rtx
, NE
, true, mode
,
1935 NULL_RTX
, NULL
, m_fail_label
,
1936 profile_probability::uninitialized ());
1939 /* Generate several move instructions to compare LEN bytes from blocks
1940 ARG0 and ARG1. (These are MEM rtx's with BLKmode).
1942 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
1943 used to push FROM to the stack.
1945 ALIGN is maximum stack alignment we can assume.
1947 Optionally, the caller can pass a constfn and associated data in A1_CFN
1948 and A1_CFN_DATA. describing that the second operand being compared is a
1949 known constant and how to obtain its data. */
1952 compare_by_pieces (rtx arg0
, rtx arg1
, unsigned HOST_WIDE_INT len
,
1953 rtx target
, unsigned int align
,
1954 by_pieces_constfn a1_cfn
, void *a1_cfn_data
)
1956 rtx_code_label
*fail_label
= gen_label_rtx ();
1957 rtx_code_label
*end_label
= gen_label_rtx ();
1959 if (target
== NULL_RTX
1960 || !REG_P (target
) || REGNO (target
) < FIRST_PSEUDO_REGISTER
)
1961 target
= gen_reg_rtx (TYPE_MODE (integer_type_node
));
1963 compare_by_pieces_d
data (arg0
, arg1
, a1_cfn
, a1_cfn_data
, len
, align
,
1968 emit_move_insn (target
, const0_rtx
);
1969 emit_jump (end_label
);
1971 emit_label (fail_label
);
1972 emit_move_insn (target
, const1_rtx
);
1973 emit_label (end_label
);
1978 /* Emit code to move a block Y to a block X. This may be done with
1979 string-move instructions, with multiple scalar move instructions,
1980 or with a library call.
1982 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1983 SIZE is an rtx that says how long they are.
1984 ALIGN is the maximum alignment we can assume they have.
1985 METHOD describes what kind of copy this is, and what mechanisms may be used.
1986 MIN_SIZE is the minimal size of block to move
1987 MAX_SIZE is the maximal size of block to move, if it cannot be represented
1988 in unsigned HOST_WIDE_INT, than it is mask of all ones.
1989 CTZ_SIZE is the trailing-zeros count of SIZE; even a nonconstant SIZE is
1990 known to be a multiple of 1<<CTZ_SIZE.
1992 Return the address of the new block, if memcpy is called and returns it,
1996 emit_block_move_hints (rtx x
, rtx y
, rtx size
, enum block_op_methods method
,
1997 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
1998 unsigned HOST_WIDE_INT min_size
,
1999 unsigned HOST_WIDE_INT max_size
,
2000 unsigned HOST_WIDE_INT probable_max_size
,
2001 bool bail_out_libcall
, bool *is_move_done
,
2002 bool might_overlap
, unsigned ctz_size
)
2009 *is_move_done
= true;
2012 if (CONST_INT_P (size
) && INTVAL (size
) == 0)
2017 case BLOCK_OP_NORMAL
:
2018 case BLOCK_OP_TAILCALL
:
2022 case BLOCK_OP_CALL_PARM
:
2023 may_use_call
= block_move_libcall_safe_for_call_parm ();
2025 /* Make inhibit_defer_pop nonzero around the library call
2026 to force it to pop the arguments right away. */
2030 case BLOCK_OP_NO_LIBCALL
:
2034 case BLOCK_OP_NO_LIBCALL_RET
:
2042 gcc_assert (MEM_P (x
) && MEM_P (y
));
2043 align
= MIN (MEM_ALIGN (x
), MEM_ALIGN (y
));
2044 gcc_assert (align
>= BITS_PER_UNIT
);
2046 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
2047 block copy is more efficient for other large modes, e.g. DCmode. */
2048 x
= adjust_address (x
, BLKmode
, 0);
2049 y
= adjust_address (y
, BLKmode
, 0);
2051 /* If source and destination are the same, no need to copy anything. */
2052 if (rtx_equal_p (x
, y
)
2053 && !MEM_VOLATILE_P (x
)
2054 && !MEM_VOLATILE_P (y
))
2057 /* Set MEM_SIZE as appropriate for this block copy. The main place this
2058 can be incorrect is coming from __builtin_memcpy. */
2059 poly_int64 const_size
;
2060 if (poly_int_rtx_p (size
, &const_size
))
2062 x
= shallow_copy_rtx (x
);
2063 y
= shallow_copy_rtx (y
);
2064 set_mem_size (x
, const_size
);
2065 set_mem_size (y
, const_size
);
2068 bool pieces_ok
= CONST_INT_P (size
)
2069 && can_move_by_pieces (INTVAL (size
), align
);
2070 bool pattern_ok
= false;
2072 if (!pieces_ok
|| might_overlap
)
2075 = emit_block_move_via_pattern (x
, y
, size
, align
,
2076 expected_align
, expected_size
,
2077 min_size
, max_size
, probable_max_size
,
2079 if (!pattern_ok
&& might_overlap
)
2081 /* Do not try any of the other methods below as they are not safe
2082 for overlapping moves. */
2083 *is_move_done
= false;
2088 bool dynamic_direction
= false;
2089 if (!pattern_ok
&& !pieces_ok
&& may_use_call
2090 && (flag_inline_stringops
& (might_overlap
? ILSOP_MEMMOVE
: ILSOP_MEMCPY
)))
2093 dynamic_direction
= might_overlap
;
2099 move_by_pieces (x
, y
, INTVAL (size
), align
, RETURN_BEGIN
);
2100 else if (may_use_call
&& !might_overlap
2101 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x
))
2102 && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y
)))
2104 if (bail_out_libcall
)
2107 *is_move_done
= false;
2111 if (may_use_call
< 0)
2114 retval
= emit_block_copy_via_libcall (x
, y
, size
,
2115 method
== BLOCK_OP_TAILCALL
);
2117 else if (dynamic_direction
)
2118 emit_block_move_via_oriented_loop (x
, y
, size
, align
, ctz_size
);
2119 else if (might_overlap
)
2120 *is_move_done
= false;
2122 emit_block_move_via_sized_loop (x
, y
, size
, align
, ctz_size
);
2124 if (method
== BLOCK_OP_CALL_PARM
)
2131 emit_block_move (rtx x
, rtx y
, rtx size
, enum block_op_methods method
,
2132 unsigned int ctz_size
)
2134 unsigned HOST_WIDE_INT max
, min
= 0;
2135 if (GET_CODE (size
) == CONST_INT
)
2136 min
= max
= UINTVAL (size
);
2138 max
= GET_MODE_MASK (GET_MODE (size
));
2139 return emit_block_move_hints (x
, y
, size
, method
, 0, -1,
2141 false, NULL
, false, ctz_size
);
2144 /* A subroutine of emit_block_move. Returns true if calling the
2145 block move libcall will not clobber any parameters which may have
2146 already been placed on the stack. */
2149 block_move_libcall_safe_for_call_parm (void)
2153 /* If arguments are pushed on the stack, then they're safe. */
2154 if (targetm
.calls
.push_argument (0))
2157 /* If registers go on the stack anyway, any argument is sure to clobber
2158 an outgoing argument. */
2159 #if defined (REG_PARM_STACK_SPACE)
2160 fn
= builtin_decl_implicit (BUILT_IN_MEMCPY
);
2161 /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
2162 depend on its argument. */
2164 if (OUTGOING_REG_PARM_STACK_SPACE ((!fn
? NULL_TREE
: TREE_TYPE (fn
)))
2165 && REG_PARM_STACK_SPACE (fn
) != 0)
2169 /* If any argument goes in memory, then it might clobber an outgoing
2172 CUMULATIVE_ARGS args_so_far_v
;
2173 cumulative_args_t args_so_far
;
2176 fn
= builtin_decl_implicit (BUILT_IN_MEMCPY
);
2177 INIT_CUMULATIVE_ARGS (args_so_far_v
, TREE_TYPE (fn
), NULL_RTX
, 0, 3);
2178 args_so_far
= pack_cumulative_args (&args_so_far_v
);
2180 arg
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
2181 for ( ; arg
!= void_list_node
; arg
= TREE_CHAIN (arg
))
2183 machine_mode mode
= TYPE_MODE (TREE_VALUE (arg
));
2184 function_arg_info
arg_info (mode
, /*named=*/true);
2185 rtx tmp
= targetm
.calls
.function_arg (args_so_far
, arg_info
);
2186 if (!tmp
|| !REG_P (tmp
))
2188 if (targetm
.calls
.arg_partial_bytes (args_so_far
, arg_info
))
2190 targetm
.calls
.function_arg_advance (args_so_far
, arg_info
);
2196 /* A subroutine of emit_block_move. Expand a cpymem or movmem pattern;
2197 return true if successful.
2199 X is the destination of the copy or move.
2200 Y is the source of the copy or move.
2201 SIZE is the size of the block to be moved.
2203 MIGHT_OVERLAP indicates this originated with expansion of a
2204 builtin_memmove() and the source and destination blocks may
2209 emit_block_move_via_pattern (rtx x
, rtx y
, rtx size
, unsigned int align
,
2210 unsigned int expected_align
,
2211 HOST_WIDE_INT expected_size
,
2212 unsigned HOST_WIDE_INT min_size
,
2213 unsigned HOST_WIDE_INT max_size
,
2214 unsigned HOST_WIDE_INT probable_max_size
,
2217 if (expected_align
< align
)
2218 expected_align
= align
;
2219 if (expected_size
!= -1)
2221 if ((unsigned HOST_WIDE_INT
)expected_size
> probable_max_size
)
2222 expected_size
= probable_max_size
;
2223 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
2224 expected_size
= min_size
;
2227 /* Since this is a move insn, we don't care about volatility. */
2228 temporary_volatile_ok
v (true);
2230 /* Try the most limited insn first, because there's no point
2231 including more than one in the machine description unless
2232 the more limited one has some advantage. */
2234 opt_scalar_int_mode mode_iter
;
2235 FOR_EACH_MODE_IN_CLASS (mode_iter
, MODE_INT
)
2237 scalar_int_mode mode
= mode_iter
.require ();
2238 enum insn_code code
;
2240 code
= direct_optab_handler (movmem_optab
, mode
);
2242 code
= direct_optab_handler (cpymem_optab
, mode
);
2244 if (code
!= CODE_FOR_nothing
2245 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
2246 here because if SIZE is less than the mode mask, as it is
2247 returned by the macro, it will definitely be less than the
2248 actual mode mask. Since SIZE is within the Pmode address
2249 space, we limit MODE to Pmode. */
2250 && ((CONST_INT_P (size
)
2251 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
2252 <= (GET_MODE_MASK (mode
) >> 1)))
2253 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
2254 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
2256 class expand_operand ops
[9];
2259 /* ??? When called via emit_block_move_for_call, it'd be
2260 nice if there were some way to inform the backend, so
2261 that it doesn't fail the expansion because it thinks
2262 emitting the libcall would be more efficient. */
2263 nops
= insn_data
[(int) code
].n_generator_args
;
2264 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
2266 create_fixed_operand (&ops
[0], x
);
2267 create_fixed_operand (&ops
[1], y
);
2268 /* The check above guarantees that this size conversion is valid. */
2269 create_convert_operand_to (&ops
[2], size
, mode
, true);
2270 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
2273 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
2274 create_integer_operand (&ops
[5], expected_size
);
2278 create_integer_operand (&ops
[6], min_size
);
2279 /* If we cannot represent the maximal size,
2280 make parameter NULL. */
2281 if ((HOST_WIDE_INT
) max_size
!= -1)
2282 create_integer_operand (&ops
[7], max_size
);
2284 create_fixed_operand (&ops
[7], NULL
);
2288 /* If we cannot represent the maximal size,
2289 make parameter NULL. */
2290 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
2291 create_integer_operand (&ops
[8], probable_max_size
);
2293 create_fixed_operand (&ops
[8], NULL
);
2295 if (maybe_expand_insn (code
, nops
, ops
))
2303 /* Like emit_block_move_via_loop, but choose a suitable INCR based on
2304 ALIGN and CTZ_SIZE. */
2307 emit_block_move_via_sized_loop (rtx x
, rtx y
, rtx size
,
2309 unsigned int ctz_size
)
2311 int incr
= align
/ BITS_PER_UNIT
;
2313 if (CONST_INT_P (size
))
2314 ctz_size
= MAX (ctz_size
, (unsigned) wi::ctz (UINTVAL (size
)));
2316 if (HOST_WIDE_INT_1U
<< ctz_size
< (unsigned HOST_WIDE_INT
) incr
)
2317 incr
= HOST_WIDE_INT_1U
<< ctz_size
;
2319 while (incr
> 1 && !can_move_by_pieces (incr
, align
))
2322 gcc_checking_assert (incr
);
2324 return emit_block_move_via_loop (x
, y
, size
, align
, incr
);
2327 /* Like emit_block_move_via_sized_loop, but besides choosing INCR so
2328 as to ensure safe moves even in case of overlap, output dynamic
2329 tests to choose between two loops, one moving downwards, another
2333 emit_block_move_via_oriented_loop (rtx x
, rtx y
, rtx size
,
2335 unsigned int ctz_size
)
2337 int incr
= align
/ BITS_PER_UNIT
;
2339 if (CONST_INT_P (size
))
2340 ctz_size
= MAX (ctz_size
, (unsigned) wi::ctz (UINTVAL (size
)));
2342 if (HOST_WIDE_INT_1U
<< ctz_size
< (unsigned HOST_WIDE_INT
) incr
)
2343 incr
= HOST_WIDE_INT_1U
<< ctz_size
;
2345 while (incr
> 1 && !int_mode_for_size (incr
, 0).exists ())
2348 gcc_checking_assert (incr
);
2350 rtx_code_label
*upw_label
, *end_label
;
2351 upw_label
= gen_label_rtx ();
2352 end_label
= gen_label_rtx ();
2354 rtx x_addr
= force_operand (XEXP (x
, 0), NULL_RTX
);
2355 rtx y_addr
= force_operand (XEXP (y
, 0), NULL_RTX
);
2356 do_pending_stack_adjust ();
2358 machine_mode mode
= GET_MODE (x_addr
);
2359 if (mode
!= GET_MODE (y_addr
))
2361 scalar_int_mode xmode
2362 = smallest_int_mode_for_size (GET_MODE_BITSIZE (mode
));
2363 scalar_int_mode ymode
2364 = smallest_int_mode_for_size (GET_MODE_BITSIZE
2365 (GET_MODE (y_addr
)));
2366 if (GET_MODE_BITSIZE (xmode
) < GET_MODE_BITSIZE (ymode
))
2371 #ifndef POINTERS_EXTEND_UNSIGNED
2372 const int POINTERS_EXTEND_UNSIGNED
= 1;
2374 x_addr
= convert_modes (mode
, GET_MODE (x_addr
), x_addr
,
2375 POINTERS_EXTEND_UNSIGNED
);
2376 y_addr
= convert_modes (mode
, GET_MODE (y_addr
), y_addr
,
2377 POINTERS_EXTEND_UNSIGNED
);
2380 /* Test for overlap: if (x >= y || x + size <= y) goto upw_label. */
2381 emit_cmp_and_jump_insns (x_addr
, y_addr
, GEU
, NULL_RTX
, mode
,
2383 profile_probability::guessed_always ()
2384 .apply_scale (5, 10));
2385 rtx tmp
= convert_modes (GET_MODE (x_addr
), GET_MODE (size
), size
, true);
2386 tmp
= simplify_gen_binary (PLUS
, GET_MODE (x_addr
), x_addr
, tmp
);
2388 emit_cmp_and_jump_insns (tmp
, y_addr
, LEU
, NULL_RTX
, mode
,
2390 profile_probability::guessed_always ()
2391 .apply_scale (8, 10));
2393 emit_block_move_via_loop (x
, y
, size
, align
, -incr
);
2395 emit_jump (end_label
);
2396 emit_label (upw_label
);
2398 emit_block_move_via_loop (x
, y
, size
, align
, incr
);
2400 emit_label (end_label
);
2403 /* A subroutine of emit_block_move. Copy the data via an explicit
2404 loop. This is used only when libcalls are forbidden, or when
2405 inlining is required. INCR is the block size to be copied in each
2406 loop iteration. If it is negative, the absolute value is used, and
2407 the block is copied backwards. INCR must be a power of two, an
2408 exact divisor for SIZE and ALIGN, and imply a mode that can be
2409 safely copied per iteration assuming no overlap. */
2412 emit_block_move_via_loop (rtx x
, rtx y
, rtx size
,
2413 unsigned int align
, int incr
)
2415 rtx_code_label
*cmp_label
, *top_label
;
2416 rtx iter
, x_addr
, y_addr
, tmp
;
2417 machine_mode x_addr_mode
= get_address_mode (x
);
2418 machine_mode y_addr_mode
= get_address_mode (y
);
2419 machine_mode iter_mode
;
2421 iter_mode
= GET_MODE (size
);
2422 if (iter_mode
== VOIDmode
)
2423 iter_mode
= word_mode
;
2425 top_label
= gen_label_rtx ();
2426 cmp_label
= gen_label_rtx ();
2427 iter
= gen_reg_rtx (iter_mode
);
2429 bool downwards
= incr
< 0;
2434 machine_mode move_mode
;
2440 iter_limit
= const0_rtx
;
2441 iter_incr
= GEN_INT (incr
);
2445 iter_init
= const0_rtx
;
2448 iter_incr
= GEN_INT (incr
);
2450 emit_move_insn (iter
, iter_init
);
2452 opt_scalar_int_mode int_move_mode
2453 = int_mode_for_size (incr
* BITS_PER_UNIT
, 1);
2454 if (!int_move_mode
.exists (&move_mode
)
2455 || GET_MODE_BITSIZE (int_move_mode
.require ()) != incr
* BITS_PER_UNIT
)
2457 move_mode
= BLKmode
;
2458 gcc_checking_assert (can_move_by_pieces (incr
, align
));
2461 x_addr
= force_operand (XEXP (x
, 0), NULL_RTX
);
2462 y_addr
= force_operand (XEXP (y
, 0), NULL_RTX
);
2463 do_pending_stack_adjust ();
2465 emit_jump (cmp_label
);
2466 emit_label (top_label
);
2468 tmp
= convert_modes (x_addr_mode
, iter_mode
, iter
, true);
2469 x_addr
= simplify_gen_binary (PLUS
, x_addr_mode
, x_addr
, tmp
);
2471 if (x_addr_mode
!= y_addr_mode
)
2472 tmp
= convert_modes (y_addr_mode
, iter_mode
, iter
, true);
2473 y_addr
= simplify_gen_binary (PLUS
, y_addr_mode
, y_addr
, tmp
);
2475 x
= change_address (x
, move_mode
, x_addr
);
2476 y
= change_address (y
, move_mode
, y_addr
);
2478 if (move_mode
== BLKmode
)
2481 emit_block_move_hints (x
, y
, iter_incr
, BLOCK_OP_NO_LIBCALL
,
2482 align
, incr
, incr
, incr
, incr
,
2483 false, &done
, false);
2484 gcc_checking_assert (done
);
2487 emit_move_insn (x
, y
);
2490 emit_label (cmp_label
);
2492 tmp
= expand_simple_binop (iter_mode
, PLUS
, iter
, iter_incr
, iter
,
2493 true, OPTAB_LIB_WIDEN
);
2495 emit_move_insn (iter
, tmp
);
2498 emit_label (cmp_label
);
2500 emit_cmp_and_jump_insns (iter
, iter_limit
, iter_cond
, NULL_RTX
, iter_mode
,
2502 profile_probability::guessed_always ()
2503 .apply_scale (9, 10));
2506 /* Expand a call to memcpy or memmove or memcmp, and return the result.
2507 TAILCALL is true if this is a tail call. */
2510 emit_block_op_via_libcall (enum built_in_function fncode
, rtx dst
, rtx src
,
2511 rtx size
, bool tailcall
)
2513 rtx dst_addr
, src_addr
;
2514 tree call_expr
, dst_tree
, src_tree
, size_tree
;
2515 machine_mode size_mode
;
2517 /* Since dst and src are passed to a libcall, mark the corresponding
2518 tree EXPR as addressable. */
2519 tree dst_expr
= MEM_EXPR (dst
);
2520 tree src_expr
= MEM_EXPR (src
);
2522 mark_addressable (dst_expr
);
2524 mark_addressable (src_expr
);
2526 dst_addr
= copy_addr_to_reg (XEXP (dst
, 0));
2527 dst_addr
= convert_memory_address (ptr_mode
, dst_addr
);
2528 dst_tree
= make_tree (ptr_type_node
, dst_addr
);
2530 src_addr
= copy_addr_to_reg (XEXP (src
, 0));
2531 src_addr
= convert_memory_address (ptr_mode
, src_addr
);
2532 src_tree
= make_tree (ptr_type_node
, src_addr
);
2534 size_mode
= TYPE_MODE (sizetype
);
2535 size
= convert_to_mode (size_mode
, size
, 1);
2536 size
= copy_to_mode_reg (size_mode
, size
);
2537 size_tree
= make_tree (sizetype
, size
);
2539 /* It is incorrect to use the libcall calling conventions for calls to
2540 memcpy/memmove/memcmp because they can be provided by the user. */
2541 tree fn
= builtin_decl_implicit (fncode
);
2542 call_expr
= build_call_expr (fn
, 3, dst_tree
, src_tree
, size_tree
);
2543 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
2545 return expand_call (call_expr
, NULL_RTX
, false);
2548 /* Try to expand cmpstrn or cmpmem operation ICODE with the given operands.
2549 ARG3_TYPE is the type of ARG3_RTX. Return the result rtx on success,
2550 otherwise return null. */
2553 expand_cmpstrn_or_cmpmem (insn_code icode
, rtx target
, rtx arg1_rtx
,
2554 rtx arg2_rtx
, tree arg3_type
, rtx arg3_rtx
,
2555 HOST_WIDE_INT align
)
2557 machine_mode insn_mode
= insn_data
[icode
].operand
[0].mode
;
2559 if (target
&& (!REG_P (target
) || HARD_REGISTER_P (target
)))
2562 class expand_operand ops
[5];
2563 create_output_operand (&ops
[0], target
, insn_mode
);
2564 create_fixed_operand (&ops
[1], arg1_rtx
);
2565 create_fixed_operand (&ops
[2], arg2_rtx
);
2566 create_convert_operand_from (&ops
[3], arg3_rtx
, TYPE_MODE (arg3_type
),
2567 TYPE_UNSIGNED (arg3_type
));
2568 create_integer_operand (&ops
[4], align
);
2569 if (maybe_expand_insn (icode
, 5, ops
))
2570 return ops
[0].value
;
2574 /* Expand a block compare between X and Y with length LEN using the
2575 cmpmem optab, placing the result in TARGET. LEN_TYPE is the type
2576 of the expression that was used to calculate the length. ALIGN
2577 gives the known minimum common alignment. */
2580 emit_block_cmp_via_cmpmem (rtx x
, rtx y
, rtx len
, tree len_type
, rtx target
,
2583 /* Note: The cmpstrnsi pattern, if it exists, is not suitable for
2584 implementing memcmp because it will stop if it encounters two
2586 insn_code icode
= direct_optab_handler (cmpmem_optab
, SImode
);
2588 if (icode
== CODE_FOR_nothing
)
2591 return expand_cmpstrn_or_cmpmem (icode
, target
, x
, y
, len_type
, len
, align
);
2594 /* Emit code to compare a block Y to a block X. This may be done with
2595 string-compare instructions, with multiple scalar instructions,
2596 or with a library call.
2598 Both X and Y must be MEM rtx's. LEN is an rtx that says how long
2599 they are. LEN_TYPE is the type of the expression that was used to
2600 calculate it, and CTZ_LEN is the known trailing-zeros count of LEN,
2601 so LEN must be a multiple of 1<<CTZ_LEN even if it's not constant.
2603 If EQUALITY_ONLY is true, it means we don't have to return the tri-state
2604 value of a normal memcmp call, instead we can just compare for equality.
2605 If FORCE_LIBCALL is true, we should emit a call to memcmp rather than
2608 Optionally, the caller can pass a constfn and associated data in Y_CFN
2609 and Y_CFN_DATA. describing that the second operand being compared is a
2610 known constant and how to obtain its data.
2611 Return the result of the comparison, or NULL_RTX if we failed to
2612 perform the operation. */
2615 emit_block_cmp_hints (rtx x
, rtx y
, rtx len
, tree len_type
, rtx target
,
2616 bool equality_only
, by_pieces_constfn y_cfn
,
2617 void *y_cfndata
, unsigned ctz_len
)
2621 if (CONST_INT_P (len
) && INTVAL (len
) == 0)
2624 gcc_assert (MEM_P (x
) && MEM_P (y
));
2625 unsigned int align
= MIN (MEM_ALIGN (x
), MEM_ALIGN (y
));
2626 gcc_assert (align
>= BITS_PER_UNIT
);
2628 x
= adjust_address (x
, BLKmode
, 0);
2629 y
= adjust_address (y
, BLKmode
, 0);
2632 && CONST_INT_P (len
)
2633 && can_do_by_pieces (INTVAL (len
), align
, COMPARE_BY_PIECES
))
2634 result
= compare_by_pieces (x
, y
, INTVAL (len
), target
, align
,
2637 result
= emit_block_cmp_via_cmpmem (x
, y
, len
, len_type
, target
, align
);
2639 if (!result
&& (flag_inline_stringops
& ILSOP_MEMCMP
))
2640 result
= emit_block_cmp_via_loop (x
, y
, len
, len_type
,
2641 target
, equality_only
,
2647 /* Like emit_block_cmp_hints, but with known alignment and no support
2648 for constats. Always expand to a loop with iterations that compare
2649 blocks of the largest compare-by-pieces size that divides both len
2650 and align, and then, if !EQUALITY_ONLY, identify the word and then
2651 the unit that first differs to return the result. */
2654 emit_block_cmp_via_loop (rtx x
, rtx y
, rtx len
, tree len_type
, rtx target
,
2655 bool equality_only
, unsigned align
, unsigned ctz_len
)
2657 unsigned incr
= align
/ BITS_PER_UNIT
;
2659 if (CONST_INT_P (len
))
2660 ctz_len
= MAX (ctz_len
, (unsigned) wi::ctz (UINTVAL (len
)));
2662 if (HOST_WIDE_INT_1U
<< ctz_len
< (unsigned HOST_WIDE_INT
) incr
)
2663 incr
= HOST_WIDE_INT_1U
<< ctz_len
;
2666 && !can_do_by_pieces (incr
, align
, COMPARE_BY_PIECES
))
2669 rtx_code_label
*cmp_label
, *top_label
, *ne_label
, *res_label
;
2670 rtx iter
, x_addr
, y_addr
, tmp
;
2671 machine_mode x_addr_mode
= get_address_mode (x
);
2672 machine_mode y_addr_mode
= get_address_mode (y
);
2673 machine_mode iter_mode
;
2675 iter_mode
= GET_MODE (len
);
2676 if (iter_mode
== VOIDmode
)
2677 iter_mode
= word_mode
;
2679 rtx iter_init
= const0_rtx
;
2680 rtx_code iter_cond
= LTU
;
2681 rtx_code entry_cond
= GEU
;
2682 rtx iter_limit
= len
;
2683 rtx iter_incr
= GEN_INT (incr
);
2684 machine_mode cmp_mode
;
2686 /* We can drop the loop back edge if we know there's exactly one
2688 top_label
= (!rtx_equal_p (len
, iter_incr
)
2691 /* We need not test before entering the loop if len is known
2692 nonzero. ??? This could be even stricter, testing whether a
2693 nonconstant LEN could possibly be zero. */
2694 cmp_label
= (!CONSTANT_P (len
) || rtx_equal_p (len
, iter_init
)
2697 ne_label
= gen_label_rtx ();
2698 res_label
= gen_label_rtx ();
2700 iter
= gen_reg_rtx (iter_mode
);
2701 emit_move_insn (iter
, iter_init
);
2703 opt_scalar_int_mode int_cmp_mode
2704 = int_mode_for_size (incr
* BITS_PER_UNIT
, 1);
2705 if (!int_cmp_mode
.exists (&cmp_mode
)
2706 || GET_MODE_BITSIZE (int_cmp_mode
.require ()) != incr
* BITS_PER_UNIT
2707 || !can_compare_p (NE
, cmp_mode
, ccp_jump
))
2710 gcc_checking_assert (incr
!= 1);
2713 /* Save the base addresses. */
2714 x_addr
= force_operand (XEXP (x
, 0), NULL_RTX
);
2715 y_addr
= force_operand (XEXP (y
, 0), NULL_RTX
);
2716 do_pending_stack_adjust ();
2721 emit_jump (cmp_label
);
2723 emit_cmp_and_jump_insns (iter
, iter_limit
, entry_cond
,
2724 NULL_RTX
, iter_mode
,
2726 profile_probability::guessed_always ()
2727 .apply_scale (1, 10));
2730 emit_label (top_label
);
2732 /* Offset the base addresses by ITER. */
2733 tmp
= convert_modes (x_addr_mode
, iter_mode
, iter
, true);
2734 x_addr
= simplify_gen_binary (PLUS
, x_addr_mode
, x_addr
, tmp
);
2736 if (x_addr_mode
!= y_addr_mode
)
2737 tmp
= convert_modes (y_addr_mode
, iter_mode
, iter
, true);
2738 y_addr
= simplify_gen_binary (PLUS
, y_addr_mode
, y_addr
, tmp
);
2740 x
= change_address (x
, cmp_mode
, x_addr
);
2741 y
= change_address (y
, cmp_mode
, y_addr
);
2743 /* Compare one block. */
2745 if (cmp_mode
== BLKmode
)
2746 part_res
= compare_by_pieces (x
, y
, incr
, target
, align
, 0, 0);
2748 part_res
= expand_binop (cmp_mode
, sub_optab
, x
, y
, NULL_RTX
,
2749 true, OPTAB_LIB_WIDEN
);
2751 /* Stop if we found a difference. */
2752 emit_cmp_and_jump_insns (part_res
, GEN_INT (0), NE
, NULL_RTX
,
2753 GET_MODE (part_res
), true, ne_label
,
2754 profile_probability::guessed_always ()
2755 .apply_scale (1, 10));
2757 /* Increment ITER. */
2758 tmp
= expand_simple_binop (iter_mode
, PLUS
, iter
, iter_incr
, iter
,
2759 true, OPTAB_LIB_WIDEN
);
2761 emit_move_insn (iter
, tmp
);
2764 emit_label (cmp_label
);
2765 /* Loop until we reach the limit. */
2768 emit_cmp_and_jump_insns (iter
, iter_limit
, iter_cond
, NULL_RTX
, iter_mode
,
2770 profile_probability::guessed_always ()
2771 .apply_scale (9, 10));
2773 /* We got to the end without differences, so the result is zero. */
2774 if (target
== NULL_RTX
2775 || !REG_P (target
) || REGNO (target
) < FIRST_PSEUDO_REGISTER
)
2776 target
= gen_reg_rtx (TYPE_MODE (integer_type_node
));
2778 emit_move_insn (target
, const0_rtx
);
2779 emit_jump (res_label
);
2781 emit_label (ne_label
);
2783 /* Return nonzero, or pinpoint the difference to return the expected
2784 result for non-equality tests. */
2786 emit_move_insn (target
, const1_rtx
);
2789 if (incr
> UNITS_PER_WORD
)
2790 /* ??? Re-compare the block found to be different one word at a
2792 part_res
= emit_block_cmp_via_loop (x
, y
, GEN_INT (incr
), len_type
,
2793 target
, equality_only
,
2796 /* ??? Re-compare the block found to be different one byte at a
2797 time. We could do better using part_res, and being careful
2798 about endianness. */
2799 part_res
= emit_block_cmp_via_loop (x
, y
, GEN_INT (incr
), len_type
,
2800 target
, equality_only
,
2802 else if (known_gt (GET_MODE_BITSIZE (GET_MODE (target
)),
2803 GET_MODE_BITSIZE (cmp_mode
)))
2804 part_res
= expand_binop (GET_MODE (target
), sub_optab
, x
, y
, target
,
2805 true, OPTAB_LIB_WIDEN
);
2808 /* In the odd chance target is QImode, we can't count on
2809 widening subtract to capture the result of the unsigned
2811 rtx_code_label
*ltu_label
;
2812 ltu_label
= gen_label_rtx ();
2813 emit_cmp_and_jump_insns (x
, y
, LTU
, NULL_RTX
,
2814 cmp_mode
, true, ltu_label
,
2815 profile_probability::guessed_always ()
2816 .apply_scale (5, 10));
2818 emit_move_insn (target
, const1_rtx
);
2819 emit_jump (res_label
);
2821 emit_label (ltu_label
);
2822 emit_move_insn (target
, constm1_rtx
);
2826 if (target
!= part_res
)
2827 convert_move (target
, part_res
, false);
2830 emit_label (res_label
);
2836 /* Copy all or part of a value X into registers starting at REGNO.
2837 The number of registers to be filled is NREGS. */
2840 move_block_to_reg (int regno
, rtx x
, int nregs
, machine_mode mode
)
2845 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
2846 x
= validize_mem (force_const_mem (mode
, x
));
2848 /* See if the machine can do this with a load multiple insn. */
2849 if (targetm
.have_load_multiple ())
2851 rtx_insn
*last
= get_last_insn ();
2852 rtx first
= gen_rtx_REG (word_mode
, regno
);
2853 if (rtx_insn
*pat
= targetm
.gen_load_multiple (first
, x
,
2860 delete_insns_since (last
);
2863 for (int i
= 0; i
< nregs
; i
++)
2864 emit_move_insn (gen_rtx_REG (word_mode
, regno
+ i
),
2865 operand_subword_force (x
, i
, mode
));
2868 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
2869 The number of registers to be filled is NREGS. */
2872 move_block_from_reg (int regno
, rtx x
, int nregs
)
2877 /* See if the machine can do this with a store multiple insn. */
2878 if (targetm
.have_store_multiple ())
2880 rtx_insn
*last
= get_last_insn ();
2881 rtx first
= gen_rtx_REG (word_mode
, regno
);
2882 if (rtx_insn
*pat
= targetm
.gen_store_multiple (x
, first
,
2889 delete_insns_since (last
);
2892 for (int i
= 0; i
< nregs
; i
++)
2894 rtx tem
= operand_subword (x
, i
, 1, BLKmode
);
2898 emit_move_insn (tem
, gen_rtx_REG (word_mode
, regno
+ i
));
2902 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
2903 ORIG, where ORIG is a non-consecutive group of registers represented by
2904 a PARALLEL. The clone is identical to the original except in that the
2905 original set of registers is replaced by a new set of pseudo registers.
2906 The new set has the same modes as the original set. */
2909 gen_group_rtx (rtx orig
)
2914 gcc_assert (GET_CODE (orig
) == PARALLEL
);
2916 length
= XVECLEN (orig
, 0);
2917 tmps
= XALLOCAVEC (rtx
, length
);
2919 /* Skip a NULL entry in first slot. */
2920 i
= XEXP (XVECEXP (orig
, 0, 0), 0) ? 0 : 1;
2925 for (; i
< length
; i
++)
2927 machine_mode mode
= GET_MODE (XEXP (XVECEXP (orig
, 0, i
), 0));
2928 rtx offset
= XEXP (XVECEXP (orig
, 0, i
), 1);
2930 tmps
[i
] = gen_rtx_EXPR_LIST (VOIDmode
, gen_reg_rtx (mode
), offset
);
2933 return gen_rtx_PARALLEL (GET_MODE (orig
), gen_rtvec_v (length
, tmps
));
2936 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
2937 except that values are placed in TMPS[i], and must later be moved
2938 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
2941 emit_group_load_1 (rtx
*tmps
, rtx dst
, rtx orig_src
, tree type
,
2946 machine_mode m
= GET_MODE (orig_src
);
2948 gcc_assert (GET_CODE (dst
) == PARALLEL
);
2951 && !SCALAR_INT_MODE_P (m
)
2952 && !MEM_P (orig_src
)
2953 && GET_CODE (orig_src
) != CONCAT
)
2955 scalar_int_mode imode
;
2956 if (int_mode_for_mode (GET_MODE (orig_src
)).exists (&imode
))
2958 src
= gen_reg_rtx (imode
);
2959 emit_move_insn (gen_lowpart (GET_MODE (orig_src
), src
), orig_src
);
2963 src
= assign_stack_temp (GET_MODE (orig_src
), ssize
);
2964 emit_move_insn (src
, orig_src
);
2966 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
2970 /* Check for a NULL entry, used to indicate that the parameter goes
2971 both on the stack and in registers. */
2972 if (XEXP (XVECEXP (dst
, 0, 0), 0))
2977 /* Process the pieces. */
2978 for (i
= start
; i
< XVECLEN (dst
, 0); i
++)
2980 machine_mode mode
= GET_MODE (XEXP (XVECEXP (dst
, 0, i
), 0));
2981 poly_int64 bytepos
= rtx_to_poly_int64 (XEXP (XVECEXP (dst
, 0, i
), 1));
2982 poly_int64 bytelen
= GET_MODE_SIZE (mode
);
2983 poly_int64 shift
= 0;
2985 /* Handle trailing fragments that run over the size of the struct.
2986 It's the target's responsibility to make sure that the fragment
2987 cannot be strictly smaller in some cases and strictly larger
2989 gcc_checking_assert (ordered_p (bytepos
+ bytelen
, ssize
));
2990 if (known_size_p (ssize
) && maybe_gt (bytepos
+ bytelen
, ssize
))
2992 /* Arrange to shift the fragment to where it belongs.
2993 extract_bit_field loads to the lsb of the reg. */
2995 #ifdef BLOCK_REG_PADDING
2996 BLOCK_REG_PADDING (GET_MODE (orig_src
), type
, i
== start
)
2997 == (BYTES_BIG_ENDIAN
? PAD_UPWARD
: PAD_DOWNWARD
)
3002 shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
3003 bytelen
= ssize
- bytepos
;
3004 gcc_assert (maybe_gt (bytelen
, 0));
3007 /* If we won't be loading directly from memory, protect the real source
3008 from strange tricks we might play; but make sure that the source can
3009 be loaded directly into the destination. */
3011 if (!MEM_P (orig_src
)
3012 && (!REG_P (orig_src
) || HARD_REGISTER_P (orig_src
))
3013 && !CONSTANT_P (orig_src
))
3015 gcc_assert (GET_MODE (orig_src
) != VOIDmode
);
3016 src
= force_reg (GET_MODE (orig_src
), orig_src
);
3019 /* Optimize the access just a bit. */
3021 && (! targetm
.slow_unaligned_access (mode
, MEM_ALIGN (src
))
3022 || MEM_ALIGN (src
) >= GET_MODE_ALIGNMENT (mode
))
3023 && multiple_p (bytepos
* BITS_PER_UNIT
, GET_MODE_ALIGNMENT (mode
))
3024 && known_eq (bytelen
, GET_MODE_SIZE (mode
)))
3026 tmps
[i
] = gen_reg_rtx (mode
);
3027 emit_move_insn (tmps
[i
], adjust_address (src
, mode
, bytepos
));
3029 else if (COMPLEX_MODE_P (mode
)
3030 && GET_MODE (src
) == mode
3031 && known_eq (bytelen
, GET_MODE_SIZE (mode
)))
3032 /* Let emit_move_complex do the bulk of the work. */
3034 else if (GET_CODE (src
) == CONCAT
)
3036 poly_int64 slen
= GET_MODE_SIZE (GET_MODE (src
));
3037 poly_int64 slen0
= GET_MODE_SIZE (GET_MODE (XEXP (src
, 0)));
3041 if (can_div_trunc_p (bytepos
, slen0
, &elt
, &subpos
)
3042 && known_le (subpos
+ bytelen
, slen0
))
3044 /* The following assumes that the concatenated objects all
3045 have the same size. In this case, a simple calculation
3046 can be used to determine the object and the bit field
3048 tmps
[i
] = XEXP (src
, elt
);
3049 if (maybe_ne (subpos
, 0)
3050 || maybe_ne (subpos
+ bytelen
, slen0
)
3051 || (!CONSTANT_P (tmps
[i
])
3052 && (!REG_P (tmps
[i
]) || GET_MODE (tmps
[i
]) != mode
)))
3053 tmps
[i
] = extract_bit_field (tmps
[i
], bytelen
* BITS_PER_UNIT
,
3054 subpos
* BITS_PER_UNIT
,
3055 1, NULL_RTX
, mode
, mode
, false,
3062 gcc_assert (known_eq (bytepos
, 0));
3063 mem
= assign_stack_temp (GET_MODE (src
), slen
);
3064 emit_move_insn (mem
, src
);
3065 tmps
[i
] = extract_bit_field (mem
, bytelen
* BITS_PER_UNIT
,
3066 0, 1, NULL_RTX
, mode
, mode
, false,
3070 else if (CONSTANT_P (src
) && GET_MODE (dst
) != BLKmode
3071 && XVECLEN (dst
, 0) > 1)
3072 tmps
[i
] = simplify_gen_subreg (mode
, src
, GET_MODE (dst
), bytepos
);
3073 else if (CONSTANT_P (src
))
3075 if (known_eq (bytelen
, ssize
))
3081 /* TODO: const_wide_int can have sizes other than this... */
3082 gcc_assert (known_eq (2 * bytelen
, ssize
));
3083 split_double (src
, &first
, &second
);
3090 else if (REG_P (src
) && GET_MODE (src
) == mode
)
3093 tmps
[i
] = extract_bit_field (src
, bytelen
* BITS_PER_UNIT
,
3094 bytepos
* BITS_PER_UNIT
, 1, NULL_RTX
,
3095 mode
, mode
, false, NULL
);
3097 if (maybe_ne (shift
, 0))
3098 tmps
[i
] = expand_shift (LSHIFT_EXPR
, mode
, tmps
[i
],
3103 /* Emit code to move a block SRC of type TYPE to a block DST,
3104 where DST is non-consecutive registers represented by a PARALLEL.
3105 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
3109 emit_group_load (rtx dst
, rtx src
, tree type
, poly_int64 ssize
)
3114 tmps
= XALLOCAVEC (rtx
, XVECLEN (dst
, 0));
3115 emit_group_load_1 (tmps
, dst
, src
, type
, ssize
);
3117 /* Copy the extracted pieces into the proper (probable) hard regs. */
3118 for (i
= 0; i
< XVECLEN (dst
, 0); i
++)
3120 rtx d
= XEXP (XVECEXP (dst
, 0, i
), 0);
3123 emit_move_insn (d
, tmps
[i
]);
3127 /* Similar, but load SRC into new pseudos in a format that looks like
3128 PARALLEL. This can later be fed to emit_group_move to get things
3129 in the right place. */
3132 emit_group_load_into_temps (rtx parallel
, rtx src
, tree type
, poly_int64 ssize
)
3137 vec
= rtvec_alloc (XVECLEN (parallel
, 0));
3138 emit_group_load_1 (&RTVEC_ELT (vec
, 0), parallel
, src
, type
, ssize
);
3140 /* Convert the vector to look just like the original PARALLEL, except
3141 with the computed values. */
3142 for (i
= 0; i
< XVECLEN (parallel
, 0); i
++)
3144 rtx e
= XVECEXP (parallel
, 0, i
);
3145 rtx d
= XEXP (e
, 0);
3149 d
= force_reg (GET_MODE (d
), RTVEC_ELT (vec
, i
));
3150 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), d
, XEXP (e
, 1));
3152 RTVEC_ELT (vec
, i
) = e
;
3155 return gen_rtx_PARALLEL (GET_MODE (parallel
), vec
);
3158 /* Emit code to move a block SRC to block DST, where SRC and DST are
3159 non-consecutive groups of registers, each represented by a PARALLEL. */
3162 emit_group_move (rtx dst
, rtx src
)
3166 gcc_assert (GET_CODE (src
) == PARALLEL
3167 && GET_CODE (dst
) == PARALLEL
3168 && XVECLEN (src
, 0) == XVECLEN (dst
, 0));
3170 /* Skip first entry if NULL. */
3171 for (i
= XEXP (XVECEXP (src
, 0, 0), 0) ? 0 : 1; i
< XVECLEN (src
, 0); i
++)
3172 emit_move_insn (XEXP (XVECEXP (dst
, 0, i
), 0),
3173 XEXP (XVECEXP (src
, 0, i
), 0));
3176 /* Move a group of registers represented by a PARALLEL into pseudos. */
3179 emit_group_move_into_temps (rtx src
)
3181 rtvec vec
= rtvec_alloc (XVECLEN (src
, 0));
3184 for (i
= 0; i
< XVECLEN (src
, 0); i
++)
3186 rtx e
= XVECEXP (src
, 0, i
);
3187 rtx d
= XEXP (e
, 0);
3190 e
= alloc_EXPR_LIST (REG_NOTE_KIND (e
), copy_to_reg (d
), XEXP (e
, 1));
3191 RTVEC_ELT (vec
, i
) = e
;
3194 return gen_rtx_PARALLEL (GET_MODE (src
), vec
);
3197 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
3198 where SRC is non-consecutive registers represented by a PARALLEL.
3199 SSIZE represents the total size of block ORIG_DST, or -1 if not
3203 emit_group_store (rtx orig_dst
, rtx src
, tree type ATTRIBUTE_UNUSED
,
3207 int start
, finish
, i
;
3208 machine_mode m
= GET_MODE (orig_dst
);
3210 gcc_assert (GET_CODE (src
) == PARALLEL
);
3212 if (!SCALAR_INT_MODE_P (m
)
3213 && !MEM_P (orig_dst
) && GET_CODE (orig_dst
) != CONCAT
)
3215 scalar_int_mode imode
;
3216 if (int_mode_for_mode (GET_MODE (orig_dst
)).exists (&imode
))
3218 dst
= gen_reg_rtx (imode
);
3219 emit_group_store (dst
, src
, type
, ssize
);
3220 dst
= gen_lowpart (GET_MODE (orig_dst
), dst
);
3224 dst
= assign_stack_temp (GET_MODE (orig_dst
), ssize
);
3225 emit_group_store (dst
, src
, type
, ssize
);
3227 emit_move_insn (orig_dst
, dst
);
3231 /* Check for a NULL entry, used to indicate that the parameter goes
3232 both on the stack and in registers. */
3233 if (XEXP (XVECEXP (src
, 0, 0), 0))
3237 finish
= XVECLEN (src
, 0);
3239 tmps
= XALLOCAVEC (rtx
, finish
);
3241 /* Copy the (probable) hard regs into pseudos. */
3242 for (i
= start
; i
< finish
; i
++)
3244 rtx reg
= XEXP (XVECEXP (src
, 0, i
), 0);
3245 if (!REG_P (reg
) || REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
3247 tmps
[i
] = gen_reg_rtx (GET_MODE (reg
));
3248 emit_move_insn (tmps
[i
], reg
);
3254 /* If we won't be storing directly into memory, protect the real destination
3255 from strange tricks we might play. */
3257 if (GET_CODE (dst
) == PARALLEL
)
3261 /* We can get a PARALLEL dst if there is a conditional expression in
3262 a return statement. In that case, the dst and src are the same,
3263 so no action is necessary. */
3264 if (rtx_equal_p (dst
, src
))
3267 /* It is unclear if we can ever reach here, but we may as well handle
3268 it. Allocate a temporary, and split this into a store/load to/from
3270 temp
= assign_stack_temp (GET_MODE (dst
), ssize
);
3271 emit_group_store (temp
, src
, type
, ssize
);
3272 emit_group_load (dst
, temp
, type
, ssize
);
3275 else if (!MEM_P (dst
) && GET_CODE (dst
) != CONCAT
)
3277 machine_mode outer
= GET_MODE (dst
);
3283 if (!REG_P (dst
) || REGNO (dst
) < FIRST_PSEUDO_REGISTER
)
3284 dst
= gen_reg_rtx (outer
);
3286 /* Make life a bit easier for combine: if the first element of the
3287 vector is the low part of the destination mode, use a paradoxical
3288 subreg to initialize the destination. */
3291 inner
= GET_MODE (tmps
[start
]);
3292 bytepos
= subreg_lowpart_offset (inner
, outer
);
3293 if (known_eq (rtx_to_poly_int64 (XEXP (XVECEXP (src
, 0, start
), 1)),
3296 temp
= simplify_gen_subreg (outer
, tmps
[start
], inner
, 0);
3299 emit_move_insn (dst
, temp
);
3306 /* If the first element wasn't the low part, try the last. */
3308 && start
< finish
- 1)
3310 inner
= GET_MODE (tmps
[finish
- 1]);
3311 bytepos
= subreg_lowpart_offset (inner
, outer
);
3312 if (known_eq (rtx_to_poly_int64 (XEXP (XVECEXP (src
, 0,
3316 temp
= simplify_gen_subreg (outer
, tmps
[finish
- 1], inner
, 0);
3319 emit_move_insn (dst
, temp
);
3326 /* Otherwise, simply initialize the result to zero. */
3328 emit_move_insn (dst
, CONST0_RTX (outer
));
3331 /* Process the pieces. */
3332 for (i
= start
; i
< finish
; i
++)
3334 poly_int64 bytepos
= rtx_to_poly_int64 (XEXP (XVECEXP (src
, 0, i
), 1));
3335 machine_mode mode
= GET_MODE (tmps
[i
]);
3336 poly_int64 bytelen
= GET_MODE_SIZE (mode
);
3337 poly_uint64 adj_bytelen
;
3340 /* Handle trailing fragments that run over the size of the struct.
3341 It's the target's responsibility to make sure that the fragment
3342 cannot be strictly smaller in some cases and strictly larger
3344 gcc_checking_assert (ordered_p (bytepos
+ bytelen
, ssize
));
3345 if (known_size_p (ssize
) && maybe_gt (bytepos
+ bytelen
, ssize
))
3346 adj_bytelen
= ssize
- bytepos
;
3348 adj_bytelen
= bytelen
;
3350 /* Deal with destination CONCATs by either storing into one of the parts
3351 or doing a copy after storing into a register or stack temporary. */
3352 if (GET_CODE (dst
) == CONCAT
)
3354 if (known_le (bytepos
+ adj_bytelen
,
3355 GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0)))))
3356 dest
= XEXP (dst
, 0);
3358 else if (known_ge (bytepos
, GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0)))))
3360 bytepos
-= GET_MODE_SIZE (GET_MODE (XEXP (dst
, 0)));
3361 dest
= XEXP (dst
, 1);
3366 machine_mode dest_mode
= GET_MODE (dest
);
3367 machine_mode tmp_mode
= GET_MODE (tmps
[i
]);
3368 scalar_int_mode dest_imode
;
3370 gcc_assert (known_eq (bytepos
, 0) && XVECLEN (src
, 0));
3372 /* If the source is a single scalar integer register, and the
3373 destination has a complex mode for which a same-sized integer
3374 mode exists, then we can take the left-justified part of the
3375 source in the complex mode. */
3376 if (finish
== start
+ 1
3378 && SCALAR_INT_MODE_P (tmp_mode
)
3379 && COMPLEX_MODE_P (dest_mode
)
3380 && int_mode_for_mode (dest_mode
).exists (&dest_imode
))
3382 const scalar_int_mode tmp_imode
3383 = as_a
<scalar_int_mode
> (tmp_mode
);
3385 if (GET_MODE_BITSIZE (dest_imode
)
3386 < GET_MODE_BITSIZE (tmp_imode
))
3388 dest
= gen_reg_rtx (dest_imode
);
3389 if (BYTES_BIG_ENDIAN
)
3390 tmps
[i
] = expand_shift (RSHIFT_EXPR
, tmp_mode
, tmps
[i
],
3391 GET_MODE_BITSIZE (tmp_imode
)
3392 - GET_MODE_BITSIZE (dest_imode
),
3394 emit_move_insn (dest
, gen_lowpart (dest_imode
, tmps
[i
]));
3395 dst
= gen_lowpart (dest_mode
, dest
);
3398 dst
= gen_lowpart (dest_mode
, tmps
[i
]);
3401 /* Otherwise spill the source onto the stack using the more
3402 aligned of the two modes. */
3403 else if (GET_MODE_ALIGNMENT (dest_mode
)
3404 >= GET_MODE_ALIGNMENT (tmp_mode
))
3406 dest
= assign_stack_temp (dest_mode
,
3407 GET_MODE_SIZE (dest_mode
));
3408 emit_move_insn (adjust_address (dest
, tmp_mode
, bytepos
),
3415 dest
= assign_stack_temp (tmp_mode
,
3416 GET_MODE_SIZE (tmp_mode
));
3417 emit_move_insn (dest
, tmps
[i
]);
3418 dst
= adjust_address (dest
, dest_mode
, bytepos
);
3425 /* Handle trailing fragments that run over the size of the struct. */
3426 if (known_size_p (ssize
) && maybe_gt (bytepos
+ bytelen
, ssize
))
3428 /* store_bit_field always takes its value from the lsb.
3429 Move the fragment to the lsb if it's not already there. */
3431 #ifdef BLOCK_REG_PADDING
3432 BLOCK_REG_PADDING (GET_MODE (orig_dst
), type
, i
== start
)
3433 == (BYTES_BIG_ENDIAN
? PAD_UPWARD
: PAD_DOWNWARD
)
3439 poly_int64 shift
= (bytelen
- (ssize
- bytepos
)) * BITS_PER_UNIT
;
3440 tmps
[i
] = expand_shift (RSHIFT_EXPR
, mode
, tmps
[i
],
3444 /* Make sure not to write past the end of the struct. */
3445 store_bit_field (dest
,
3446 adj_bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
3447 bytepos
* BITS_PER_UNIT
, ssize
* BITS_PER_UNIT
- 1,
3448 VOIDmode
, tmps
[i
], false, false);
3451 /* Optimize the access just a bit. */
3452 else if (MEM_P (dest
)
3453 && (!targetm
.slow_unaligned_access (mode
, MEM_ALIGN (dest
))
3454 || MEM_ALIGN (dest
) >= GET_MODE_ALIGNMENT (mode
))
3455 && multiple_p (bytepos
* BITS_PER_UNIT
,
3456 GET_MODE_ALIGNMENT (mode
))
3457 && known_eq (bytelen
, GET_MODE_SIZE (mode
)))
3458 emit_move_insn (adjust_address (dest
, mode
, bytepos
), tmps
[i
]);
3461 store_bit_field (dest
, bytelen
* BITS_PER_UNIT
, bytepos
* BITS_PER_UNIT
,
3462 0, 0, mode
, tmps
[i
], false, false);
3465 /* Copy from the pseudo into the (probable) hard reg. */
3466 if (orig_dst
!= dst
)
3467 emit_move_insn (orig_dst
, dst
);
3470 /* Return a form of X that does not use a PARALLEL. TYPE is the type
3471 of the value stored in X. */
3474 maybe_emit_group_store (rtx x
, tree type
)
3476 machine_mode mode
= TYPE_MODE (type
);
3477 gcc_checking_assert (GET_MODE (x
) == VOIDmode
|| GET_MODE (x
) == mode
);
3478 if (GET_CODE (x
) == PARALLEL
)
3480 rtx result
= gen_reg_rtx (mode
);
3481 emit_group_store (result
, x
, type
, int_size_in_bytes (type
));
3487 /* Copy a BLKmode object of TYPE out of a register SRCREG into TARGET.
3489 This is used on targets that return BLKmode values in registers. */
3492 copy_blkmode_from_reg (rtx target
, rtx srcreg
, tree type
)
3494 unsigned HOST_WIDE_INT bytes
= int_size_in_bytes (type
);
3495 rtx src
= NULL
, dst
= NULL
;
3496 unsigned HOST_WIDE_INT bitsize
= MIN (TYPE_ALIGN (type
), BITS_PER_WORD
);
3497 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0;
3498 /* No current ABI uses variable-sized modes to pass a BLKmnode type. */
3499 fixed_size_mode mode
= as_a
<fixed_size_mode
> (GET_MODE (srcreg
));
3500 fixed_size_mode tmode
= as_a
<fixed_size_mode
> (GET_MODE (target
));
3501 fixed_size_mode copy_mode
;
3503 /* BLKmode registers created in the back-end shouldn't have survived. */
3504 gcc_assert (mode
!= BLKmode
);
3506 /* If the structure doesn't take up a whole number of words, see whether
3507 SRCREG is padded on the left or on the right. If it's on the left,
3508 set PADDING_CORRECTION to the number of bits to skip.
3510 In most ABIs, the structure will be returned at the least end of
3511 the register, which translates to right padding on little-endian
3512 targets and left padding on big-endian targets. The opposite
3513 holds if the structure is returned at the most significant
3514 end of the register. */
3515 if (bytes
% UNITS_PER_WORD
!= 0
3516 && (targetm
.calls
.return_in_msb (type
)
3518 : BYTES_BIG_ENDIAN
))
3520 = (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
) * BITS_PER_UNIT
));
3522 /* We can use a single move if we have an exact mode for the size. */
3523 else if (MEM_P (target
)
3524 && (!targetm
.slow_unaligned_access (mode
, MEM_ALIGN (target
))
3525 || MEM_ALIGN (target
) >= GET_MODE_ALIGNMENT (mode
))
3526 && bytes
== GET_MODE_SIZE (mode
))
3528 emit_move_insn (adjust_address (target
, mode
, 0), srcreg
);
3532 /* And if we additionally have the same mode for a register. */
3533 else if (REG_P (target
)
3534 && GET_MODE (target
) == mode
3535 && bytes
== GET_MODE_SIZE (mode
))
3537 emit_move_insn (target
, srcreg
);
3541 /* This code assumes srcreg is at least a full word. If it isn't, copy it
3542 into a new pseudo which is a full word. */
3543 if (GET_MODE_SIZE (mode
) < UNITS_PER_WORD
)
3545 srcreg
= convert_to_mode (word_mode
, srcreg
, TYPE_UNSIGNED (type
));
3549 /* Copy the structure BITSIZE bits at a time. If the target lives in
3550 memory, take care of not reading/writing past its end by selecting
3551 a copy mode suited to BITSIZE. This should always be possible given
3554 If the target lives in register, make sure not to select a copy mode
3555 larger than the mode of the register.
3557 We could probably emit more efficient code for machines which do not use
3558 strict alignment, but it doesn't seem worth the effort at the current
3561 copy_mode
= word_mode
;
3564 opt_scalar_int_mode mem_mode
= int_mode_for_size (bitsize
, 1);
3565 if (mem_mode
.exists ())
3566 copy_mode
= mem_mode
.require ();
3568 else if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
3571 for (bitpos
= 0, xbitpos
= padding_correction
;
3572 bitpos
< bytes
* BITS_PER_UNIT
;
3573 bitpos
+= bitsize
, xbitpos
+= bitsize
)
3575 /* We need a new source operand each time xbitpos is on a
3576 word boundary and when xbitpos == padding_correction
3577 (the first time through). */
3578 if (xbitpos
% BITS_PER_WORD
== 0 || xbitpos
== padding_correction
)
3579 src
= operand_subword_force (srcreg
, xbitpos
/ BITS_PER_WORD
, mode
);
3581 /* We need a new destination operand each time bitpos is on
3583 if (REG_P (target
) && GET_MODE_BITSIZE (tmode
) < BITS_PER_WORD
)
3585 else if (bitpos
% BITS_PER_WORD
== 0)
3586 dst
= operand_subword (target
, bitpos
/ BITS_PER_WORD
, 1, tmode
);
3588 /* Use xbitpos for the source extraction (right justified) and
3589 bitpos for the destination store (left justified). */
3590 store_bit_field (dst
, bitsize
, bitpos
% BITS_PER_WORD
, 0, 0, copy_mode
,
3591 extract_bit_field (src
, bitsize
,
3592 xbitpos
% BITS_PER_WORD
, 1,
3593 NULL_RTX
, copy_mode
, copy_mode
,
3599 /* Copy BLKmode value SRC into a register of mode MODE_IN. Return the
3600 register if it contains any data, otherwise return null.
3602 This is used on targets that return BLKmode values in registers. */
3605 copy_blkmode_to_reg (machine_mode mode_in
, tree src
)
3608 unsigned HOST_WIDE_INT bitpos
, xbitpos
, padding_correction
= 0, bytes
;
3609 unsigned int bitsize
;
3610 rtx
*dst_words
, dst
, x
, src_word
= NULL_RTX
, dst_word
= NULL_RTX
;
3611 /* No current ABI uses variable-sized modes to pass a BLKmnode type. */
3612 fixed_size_mode mode
= as_a
<fixed_size_mode
> (mode_in
);
3613 fixed_size_mode dst_mode
;
3614 scalar_int_mode min_mode
;
3616 gcc_assert (TYPE_MODE (TREE_TYPE (src
)) == BLKmode
);
3618 x
= expand_normal (src
);
3620 bytes
= arg_int_size_in_bytes (TREE_TYPE (src
));
3624 /* If the structure doesn't take up a whole number of words, see
3625 whether the register value should be padded on the left or on
3626 the right. Set PADDING_CORRECTION to the number of padding
3627 bits needed on the left side.
3629 In most ABIs, the structure will be returned at the least end of
3630 the register, which translates to right padding on little-endian
3631 targets and left padding on big-endian targets. The opposite
3632 holds if the structure is returned at the most significant
3633 end of the register. */
3634 if (bytes
% UNITS_PER_WORD
!= 0
3635 && (targetm
.calls
.return_in_msb (TREE_TYPE (src
))
3637 : BYTES_BIG_ENDIAN
))
3638 padding_correction
= (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
)
3641 n_regs
= (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
3642 dst_words
= XALLOCAVEC (rtx
, n_regs
);
3643 bitsize
= MIN (TYPE_ALIGN (TREE_TYPE (src
)), BITS_PER_WORD
);
3644 min_mode
= smallest_int_mode_for_size (bitsize
);
3646 /* Copy the structure BITSIZE bits at a time. */
3647 for (bitpos
= 0, xbitpos
= padding_correction
;
3648 bitpos
< bytes
* BITS_PER_UNIT
;
3649 bitpos
+= bitsize
, xbitpos
+= bitsize
)
3651 /* We need a new destination pseudo each time xbitpos is
3652 on a word boundary and when xbitpos == padding_correction
3653 (the first time through). */
3654 if (xbitpos
% BITS_PER_WORD
== 0
3655 || xbitpos
== padding_correction
)
3657 /* Generate an appropriate register. */
3658 dst_word
= gen_reg_rtx (word_mode
);
3659 dst_words
[xbitpos
/ BITS_PER_WORD
] = dst_word
;
3661 /* Clear the destination before we move anything into it. */
3662 emit_move_insn (dst_word
, CONST0_RTX (word_mode
));
3665 /* Find the largest integer mode that can be used to copy all or as
3666 many bits as possible of the structure if the target supports larger
3667 copies. There are too many corner cases here w.r.t to alignments on
3668 the read/writes. So if there is any padding just use single byte
3670 opt_scalar_int_mode mode_iter
;
3671 if (padding_correction
== 0 && !STRICT_ALIGNMENT
)
3673 FOR_EACH_MODE_FROM (mode_iter
, min_mode
)
3675 unsigned int msize
= GET_MODE_BITSIZE (mode_iter
.require ());
3676 if (msize
<= ((bytes
* BITS_PER_UNIT
) - bitpos
)
3677 && msize
<= BITS_PER_WORD
)
3684 /* We need a new source operand each time bitpos is on a word
3686 if (bitpos
% BITS_PER_WORD
== 0)
3687 src_word
= operand_subword_force (x
, bitpos
/ BITS_PER_WORD
, BLKmode
);
3689 /* Use bitpos for the source extraction (left justified) and
3690 xbitpos for the destination store (right justified). */
3691 store_bit_field (dst_word
, bitsize
, xbitpos
% BITS_PER_WORD
,
3693 extract_bit_field (src_word
, bitsize
,
3694 bitpos
% BITS_PER_WORD
, 1,
3695 NULL_RTX
, word_mode
, word_mode
,
3700 if (mode
== BLKmode
)
3702 /* Find the smallest integer mode large enough to hold the
3703 entire structure. */
3704 opt_scalar_int_mode mode_iter
;
3705 FOR_EACH_MODE_IN_CLASS (mode_iter
, MODE_INT
)
3706 if (GET_MODE_SIZE (mode_iter
.require ()) >= bytes
)
3709 /* A suitable mode should have been found. */
3710 mode
= mode_iter
.require ();
3713 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (word_mode
))
3714 dst_mode
= word_mode
;
3717 dst
= gen_reg_rtx (dst_mode
);
3719 for (i
= 0; i
< n_regs
; i
++)
3720 emit_move_insn (operand_subword (dst
, i
, 0, dst_mode
), dst_words
[i
]);
3722 if (mode
!= dst_mode
)
3723 dst
= gen_lowpart (mode
, dst
);
3728 /* Add a USE expression for REG to the (possibly empty) list pointed
3729 to by CALL_FUSAGE. REG must denote a hard register. */
3732 use_reg_mode (rtx
*call_fusage
, rtx reg
, machine_mode mode
)
3734 gcc_assert (REG_P (reg
));
3736 if (!HARD_REGISTER_P (reg
))
3740 = gen_rtx_EXPR_LIST (mode
, gen_rtx_USE (VOIDmode
, reg
), *call_fusage
);
3743 /* Add a CLOBBER expression for REG to the (possibly empty) list pointed
3744 to by CALL_FUSAGE. REG must denote a hard register. */
3747 clobber_reg_mode (rtx
*call_fusage
, rtx reg
, machine_mode mode
)
3749 gcc_assert (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
);
3752 = gen_rtx_EXPR_LIST (mode
, gen_rtx_CLOBBER (VOIDmode
, reg
), *call_fusage
);
3755 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
3756 starting at REGNO. All of these registers must be hard registers. */
3759 use_regs (rtx
*call_fusage
, int regno
, int nregs
)
3763 gcc_assert (regno
+ nregs
<= FIRST_PSEUDO_REGISTER
);
3765 for (i
= 0; i
< nregs
; i
++)
3766 use_reg (call_fusage
, regno_reg_rtx
[regno
+ i
]);
3769 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
3770 PARALLEL REGS. This is for calls that pass values in multiple
3771 non-contiguous locations. The Irix 6 ABI has examples of this. */
3774 use_group_regs (rtx
*call_fusage
, rtx regs
)
3778 for (i
= 0; i
< XVECLEN (regs
, 0); i
++)
3780 rtx reg
= XEXP (XVECEXP (regs
, 0, i
), 0);
3782 /* A NULL entry means the parameter goes both on the stack and in
3783 registers. This can also be a MEM for targets that pass values
3784 partially on the stack and partially in registers. */
3785 if (reg
!= 0 && REG_P (reg
))
3786 use_reg (call_fusage
, reg
);
3790 /* Return the defining gimple statement for SSA_NAME NAME if it is an
3791 assigment and the code of the expresion on the RHS is CODE. Return
3795 get_def_for_expr (tree name
, enum tree_code code
)
3799 if (TREE_CODE (name
) != SSA_NAME
)
3802 def_stmt
= get_gimple_for_ssa_name (name
);
3804 || gimple_assign_rhs_code (def_stmt
) != code
)
3810 /* Return the defining gimple statement for SSA_NAME NAME if it is an
3811 assigment and the class of the expresion on the RHS is CLASS. Return
3815 get_def_for_expr_class (tree name
, enum tree_code_class tclass
)
3819 if (TREE_CODE (name
) != SSA_NAME
)
3822 def_stmt
= get_gimple_for_ssa_name (name
);
3824 || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt
)) != tclass
)
3830 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
3831 its length in bytes. */
3834 clear_storage_hints (rtx object
, rtx size
, enum block_op_methods method
,
3835 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
3836 unsigned HOST_WIDE_INT min_size
,
3837 unsigned HOST_WIDE_INT max_size
,
3838 unsigned HOST_WIDE_INT probable_max_size
,
3841 machine_mode mode
= GET_MODE (object
);
3844 gcc_assert (method
== BLOCK_OP_NORMAL
|| method
== BLOCK_OP_TAILCALL
);
3846 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
3847 just move a zero. Otherwise, do this a piece at a time. */
3848 poly_int64 size_val
;
3850 && poly_int_rtx_p (size
, &size_val
)
3851 && known_eq (size_val
, GET_MODE_SIZE (mode
)))
3853 rtx zero
= CONST0_RTX (mode
);
3856 emit_move_insn (object
, zero
);
3860 if (COMPLEX_MODE_P (mode
))
3862 zero
= CONST0_RTX (GET_MODE_INNER (mode
));
3865 write_complex_part (object
, zero
, 0, true);
3866 write_complex_part (object
, zero
, 1, false);
3872 if (size
== const0_rtx
)
3875 align
= MEM_ALIGN (object
);
3877 if (CONST_INT_P (size
)
3878 && targetm
.use_by_pieces_infrastructure_p (INTVAL (size
), align
,
3880 optimize_insn_for_speed_p ()))
3881 clear_by_pieces (object
, INTVAL (size
), align
);
3882 else if (set_storage_via_setmem (object
, size
, const0_rtx
, align
,
3883 expected_align
, expected_size
,
3884 min_size
, max_size
, probable_max_size
))
3886 else if (try_store_by_multiple_pieces (object
, size
, ctz_size
,
3888 NULL_RTX
, 0, align
))
3890 else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object
)))
3891 return set_storage_via_libcall (object
, size
, const0_rtx
,
3892 method
== BLOCK_OP_TAILCALL
);
3900 clear_storage (rtx object
, rtx size
, enum block_op_methods method
)
3902 unsigned HOST_WIDE_INT max
, min
= 0;
3903 if (GET_CODE (size
) == CONST_INT
)
3904 min
= max
= UINTVAL (size
);
3906 max
= GET_MODE_MASK (GET_MODE (size
));
3907 return clear_storage_hints (object
, size
, method
, 0, -1, min
, max
, max
, 0);
3911 /* A subroutine of clear_storage. Expand a call to memset.
3912 Return the return value of memset, 0 otherwise. */
3915 set_storage_via_libcall (rtx object
, rtx size
, rtx val
, bool tailcall
)
3917 tree call_expr
, fn
, object_tree
, size_tree
, val_tree
;
3918 machine_mode size_mode
;
3920 object
= copy_addr_to_reg (XEXP (object
, 0));
3921 object_tree
= make_tree (ptr_type_node
, object
);
3923 if (!CONST_INT_P (val
))
3924 val
= convert_to_mode (TYPE_MODE (integer_type_node
), val
, 1);
3925 val_tree
= make_tree (integer_type_node
, val
);
3927 size_mode
= TYPE_MODE (sizetype
);
3928 size
= convert_to_mode (size_mode
, size
, 1);
3929 size
= copy_to_mode_reg (size_mode
, size
);
3930 size_tree
= make_tree (sizetype
, size
);
3932 /* It is incorrect to use the libcall calling conventions for calls to
3933 memset because it can be provided by the user. */
3934 fn
= builtin_decl_implicit (BUILT_IN_MEMSET
);
3935 call_expr
= build_call_expr (fn
, 3, object_tree
, val_tree
, size_tree
);
3936 CALL_EXPR_TAILCALL (call_expr
) = tailcall
;
3938 return expand_call (call_expr
, NULL_RTX
, false);
3941 /* Expand a setmem pattern; return true if successful. */
3944 set_storage_via_setmem (rtx object
, rtx size
, rtx val
, unsigned int align
,
3945 unsigned int expected_align
, HOST_WIDE_INT expected_size
,
3946 unsigned HOST_WIDE_INT min_size
,
3947 unsigned HOST_WIDE_INT max_size
,
3948 unsigned HOST_WIDE_INT probable_max_size
)
3950 /* Try the most limited insn first, because there's no point
3951 including more than one in the machine description unless
3952 the more limited one has some advantage. */
3954 if (expected_align
< align
)
3955 expected_align
= align
;
3956 if (expected_size
!= -1)
3958 if ((unsigned HOST_WIDE_INT
)expected_size
> max_size
)
3959 expected_size
= max_size
;
3960 if ((unsigned HOST_WIDE_INT
)expected_size
< min_size
)
3961 expected_size
= min_size
;
3964 opt_scalar_int_mode mode_iter
;
3965 FOR_EACH_MODE_IN_CLASS (mode_iter
, MODE_INT
)
3967 scalar_int_mode mode
= mode_iter
.require ();
3968 enum insn_code code
= direct_optab_handler (setmem_optab
, mode
);
3970 if (code
!= CODE_FOR_nothing
3971 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
3972 here because if SIZE is less than the mode mask, as it is
3973 returned by the macro, it will definitely be less than the
3974 actual mode mask. Since SIZE is within the Pmode address
3975 space, we limit MODE to Pmode. */
3976 && ((CONST_INT_P (size
)
3977 && ((unsigned HOST_WIDE_INT
) INTVAL (size
)
3978 <= (GET_MODE_MASK (mode
) >> 1)))
3979 || max_size
<= (GET_MODE_MASK (mode
) >> 1)
3980 || GET_MODE_BITSIZE (mode
) >= GET_MODE_BITSIZE (Pmode
)))
3982 class expand_operand ops
[9];
3985 nops
= insn_data
[(int) code
].n_generator_args
;
3986 gcc_assert (nops
== 4 || nops
== 6 || nops
== 8 || nops
== 9);
3988 create_fixed_operand (&ops
[0], object
);
3989 /* The check above guarantees that this size conversion is valid. */
3990 create_convert_operand_to (&ops
[1], size
, mode
, true);
3991 create_convert_operand_from (&ops
[2], val
, byte_mode
, true);
3992 create_integer_operand (&ops
[3], align
/ BITS_PER_UNIT
);
3995 create_integer_operand (&ops
[4], expected_align
/ BITS_PER_UNIT
);
3996 create_integer_operand (&ops
[5], expected_size
);
4000 create_integer_operand (&ops
[6], min_size
);
4001 /* If we cannot represent the maximal size,
4002 make parameter NULL. */
4003 if ((HOST_WIDE_INT
) max_size
!= -1)
4004 create_integer_operand (&ops
[7], max_size
);
4006 create_fixed_operand (&ops
[7], NULL
);
4010 /* If we cannot represent the maximal size,
4011 make parameter NULL. */
4012 if ((HOST_WIDE_INT
) probable_max_size
!= -1)
4013 create_integer_operand (&ops
[8], probable_max_size
);
4015 create_fixed_operand (&ops
[8], NULL
);
4017 if (maybe_expand_insn (code
, nops
, ops
))
4026 /* Write to one of the components of the complex value CPLX. Write VAL to
4027 the real part if IMAG_P is false, and the imaginary part if its true.
4028 If UNDEFINED_P then the value in CPLX is currently undefined. */
4031 write_complex_part (rtx cplx
, rtx val
, bool imag_p
, bool undefined_p
)
4037 if (GET_CODE (cplx
) == CONCAT
)
4039 emit_move_insn (XEXP (cplx
, imag_p
), val
);
4043 cmode
= GET_MODE (cplx
);
4044 imode
= GET_MODE_INNER (cmode
);
4045 ibitsize
= GET_MODE_BITSIZE (imode
);
4047 /* For MEMs simplify_gen_subreg may generate an invalid new address
4048 because, e.g., the original address is considered mode-dependent
4049 by the target, which restricts simplify_subreg from invoking
4050 adjust_address_nv. Instead of preparing fallback support for an
4051 invalid address, we call adjust_address_nv directly. */
4054 emit_move_insn (adjust_address_nv (cplx
, imode
,
4055 imag_p
? GET_MODE_SIZE (imode
) : 0),
4060 /* If the sub-object is at least word sized, then we know that subregging
4061 will work. This special case is important, since store_bit_field
4062 wants to operate on integer modes, and there's rarely an OImode to
4063 correspond to TCmode. */
4064 if (ibitsize
>= BITS_PER_WORD
4065 /* For hard regs we have exact predicates. Assume we can split
4066 the original object if it spans an even number of hard regs.
4067 This special case is important for SCmode on 64-bit platforms
4068 where the natural size of floating-point regs is 32-bit. */
4070 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
4071 && REG_NREGS (cplx
) % 2 == 0))
4073 rtx part
= simplify_gen_subreg (imode
, cplx
, cmode
,
4074 imag_p
? GET_MODE_SIZE (imode
) : 0);
4077 emit_move_insn (part
, val
);
4081 /* simplify_gen_subreg may fail for sub-word MEMs. */
4082 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
4085 store_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0, 0, 0, imode
, val
,
4086 false, undefined_p
);
4089 /* Extract one of the components of the complex value CPLX. Extract the
4090 real part if IMAG_P is false, and the imaginary part if it's true. */
4093 read_complex_part (rtx cplx
, bool imag_p
)
4099 if (GET_CODE (cplx
) == CONCAT
)
4100 return XEXP (cplx
, imag_p
);
4102 cmode
= GET_MODE (cplx
);
4103 imode
= GET_MODE_INNER (cmode
);
4104 ibitsize
= GET_MODE_BITSIZE (imode
);
4106 /* Special case reads from complex constants that got spilled to memory. */
4107 if (MEM_P (cplx
) && GET_CODE (XEXP (cplx
, 0)) == SYMBOL_REF
)
4109 tree decl
= SYMBOL_REF_DECL (XEXP (cplx
, 0));
4110 if (decl
&& TREE_CODE (decl
) == COMPLEX_CST
)
4112 tree part
= imag_p
? TREE_IMAGPART (decl
) : TREE_REALPART (decl
);
4113 if (CONSTANT_CLASS_P (part
))
4114 return expand_expr (part
, NULL_RTX
, imode
, EXPAND_NORMAL
);
4118 /* For MEMs simplify_gen_subreg may generate an invalid new address
4119 because, e.g., the original address is considered mode-dependent
4120 by the target, which restricts simplify_subreg from invoking
4121 adjust_address_nv. Instead of preparing fallback support for an
4122 invalid address, we call adjust_address_nv directly. */
4124 return adjust_address_nv (cplx
, imode
,
4125 imag_p
? GET_MODE_SIZE (imode
) : 0);
4127 /* If the sub-object is at least word sized, then we know that subregging
4128 will work. This special case is important, since extract_bit_field
4129 wants to operate on integer modes, and there's rarely an OImode to
4130 correspond to TCmode. */
4131 if (ibitsize
>= BITS_PER_WORD
4132 /* For hard regs we have exact predicates. Assume we can split
4133 the original object if it spans an even number of hard regs.
4134 This special case is important for SCmode on 64-bit platforms
4135 where the natural size of floating-point regs is 32-bit. */
4137 && REGNO (cplx
) < FIRST_PSEUDO_REGISTER
4138 && REG_NREGS (cplx
) % 2 == 0))
4140 rtx ret
= simplify_gen_subreg (imode
, cplx
, cmode
,
4141 imag_p
? GET_MODE_SIZE (imode
) : 0);
4145 /* simplify_gen_subreg may fail for sub-word MEMs. */
4146 gcc_assert (MEM_P (cplx
) && ibitsize
< BITS_PER_WORD
);
4149 return extract_bit_field (cplx
, ibitsize
, imag_p
? ibitsize
: 0,
4150 true, NULL_RTX
, imode
, imode
, false, NULL
);
4153 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
4154 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
4155 represented in NEW_MODE. If FORCE is true, this will never happen, as
4156 we'll force-create a SUBREG if needed. */
4159 emit_move_change_mode (machine_mode new_mode
,
4160 machine_mode old_mode
, rtx x
, bool force
)
4164 if (push_operand (x
, GET_MODE (x
)))
4166 ret
= gen_rtx_MEM (new_mode
, XEXP (x
, 0));
4167 MEM_COPY_ATTRIBUTES (ret
, x
);
4171 /* We don't have to worry about changing the address since the
4172 size in bytes is supposed to be the same. */
4173 if (reload_in_progress
)
4175 /* Copy the MEM to change the mode and move any
4176 substitutions from the old MEM to the new one. */
4177 ret
= adjust_address_nv (x
, new_mode
, 0);
4178 copy_replacements (x
, ret
);
4181 ret
= adjust_address (x
, new_mode
, 0);
4185 /* Note that we do want simplify_subreg's behavior of validating
4186 that the new mode is ok for a hard register. If we were to use
4187 simplify_gen_subreg, we would create the subreg, but would
4188 probably run into the target not being able to implement it. */
4189 /* Except, of course, when FORCE is true, when this is exactly what
4190 we want. Which is needed for CCmodes on some targets. */
4192 ret
= simplify_gen_subreg (new_mode
, x
, old_mode
, 0);
4194 ret
= simplify_subreg (new_mode
, x
, old_mode
, 0);
4200 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
4201 an integer mode of the same size as MODE. Returns the instruction
4202 emitted, or NULL if such a move could not be generated. */
4205 emit_move_via_integer (machine_mode mode
, rtx x
, rtx y
, bool force
)
4207 scalar_int_mode imode
;
4208 enum insn_code code
;
4210 /* There must exist a mode of the exact size we require. */
4211 if (!int_mode_for_mode (mode
).exists (&imode
))
4214 /* The target must support moves in this mode. */
4215 code
= optab_handler (mov_optab
, imode
);
4216 if (code
== CODE_FOR_nothing
)
4219 x
= emit_move_change_mode (imode
, mode
, x
, force
);
4222 y
= emit_move_change_mode (imode
, mode
, y
, force
);
4225 return emit_insn (GEN_FCN (code
) (x
, y
));
4228 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
4229 Return an equivalent MEM that does not use an auto-increment. */
4232 emit_move_resolve_push (machine_mode mode
, rtx x
)
4234 enum rtx_code code
= GET_CODE (XEXP (x
, 0));
4237 poly_int64 adjust
= GET_MODE_SIZE (mode
);
4238 #ifdef PUSH_ROUNDING
4239 adjust
= PUSH_ROUNDING (adjust
);
4241 if (code
== PRE_DEC
|| code
== POST_DEC
)
4243 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
4245 rtx expr
= XEXP (XEXP (x
, 0), 1);
4247 gcc_assert (GET_CODE (expr
) == PLUS
|| GET_CODE (expr
) == MINUS
);
4248 poly_int64 val
= rtx_to_poly_int64 (XEXP (expr
, 1));
4249 if (GET_CODE (expr
) == MINUS
)
4251 gcc_assert (known_eq (adjust
, val
) || known_eq (adjust
, -val
));
4255 /* Do not use anti_adjust_stack, since we don't want to update
4256 stack_pointer_delta. */
4257 temp
= expand_simple_binop (Pmode
, PLUS
, stack_pointer_rtx
,
4258 gen_int_mode (adjust
, Pmode
), stack_pointer_rtx
,
4259 0, OPTAB_LIB_WIDEN
);
4260 if (temp
!= stack_pointer_rtx
)
4261 emit_move_insn (stack_pointer_rtx
, temp
);
4268 temp
= stack_pointer_rtx
;
4273 temp
= plus_constant (Pmode
, stack_pointer_rtx
, -adjust
);
4279 return replace_equiv_address (x
, temp
);
4282 /* A subroutine of emit_move_complex. Generate a move from Y into X.
4283 X is known to satisfy push_operand, and MODE is known to be complex.
4284 Returns the last instruction emitted. */
4287 emit_move_complex_push (machine_mode mode
, rtx x
, rtx y
)
4289 scalar_mode submode
= GET_MODE_INNER (mode
);
4292 #ifdef PUSH_ROUNDING
4293 poly_int64 submodesize
= GET_MODE_SIZE (submode
);
4295 /* In case we output to the stack, but the size is smaller than the
4296 machine can push exactly, we need to use move instructions. */
4297 if (maybe_ne (PUSH_ROUNDING (submodesize
), submodesize
))
4299 x
= emit_move_resolve_push (mode
, x
);
4300 return emit_move_insn (x
, y
);
4304 /* Note that the real part always precedes the imag part in memory
4305 regardless of machine's endianness. */
4306 switch (GET_CODE (XEXP (x
, 0)))
4320 emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
4321 read_complex_part (y
, imag_first
));
4322 return emit_move_insn (gen_rtx_MEM (submode
, XEXP (x
, 0)),
4323 read_complex_part (y
, !imag_first
));
4326 /* A subroutine of emit_move_complex. Perform the move from Y to X
4327 via two moves of the parts. Returns the last instruction emitted. */
4330 emit_move_complex_parts (rtx x
, rtx y
)
4332 /* Show the output dies here. This is necessary for SUBREGs
4333 of pseudos since we cannot track their lifetimes correctly;
4334 hard regs shouldn't appear here except as return values. */
4335 if (!reload_completed
&& !reload_in_progress
4336 && REG_P (x
) && !reg_overlap_mentioned_p (x
, y
))
4339 write_complex_part (x
, read_complex_part (y
, false), false, true);
4340 write_complex_part (x
, read_complex_part (y
, true), true, false);
4342 return get_last_insn ();
4345 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
4346 MODE is known to be complex. Returns the last instruction emitted. */
4349 emit_move_complex (machine_mode mode
, rtx x
, rtx y
)
4353 /* Need to take special care for pushes, to maintain proper ordering
4354 of the data, and possibly extra padding. */
4355 if (push_operand (x
, mode
))
4356 return emit_move_complex_push (mode
, x
, y
);
4358 /* See if we can coerce the target into moving both values at once, except
4359 for floating point where we favor moving as parts if this is easy. */
4360 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
4361 && optab_handler (mov_optab
, GET_MODE_INNER (mode
)) != CODE_FOR_nothing
4363 && HARD_REGISTER_P (x
)
4364 && REG_NREGS (x
) == 1)
4366 && HARD_REGISTER_P (y
)
4367 && REG_NREGS (y
) == 1))
4369 /* Not possible if the values are inherently not adjacent. */
4370 else if (GET_CODE (x
) == CONCAT
|| GET_CODE (y
) == CONCAT
)
4372 /* Is possible if both are registers (or subregs of registers). */
4373 else if (register_operand (x
, mode
) && register_operand (y
, mode
))
4375 /* If one of the operands is a memory, and alignment constraints
4376 are friendly enough, we may be able to do combined memory operations.
4377 We do not attempt this if Y is a constant because that combination is
4378 usually better with the by-parts thing below. */
4379 else if ((MEM_P (x
) ? !CONSTANT_P (y
) : MEM_P (y
))
4380 && (!STRICT_ALIGNMENT
4381 || get_mode_alignment (mode
) == BIGGEST_ALIGNMENT
))
4390 /* For memory to memory moves, optimal behavior can be had with the
4391 existing block move logic. But use normal expansion if optimizing
4393 if (MEM_P (x
) && MEM_P (y
))
4395 emit_block_move (x
, y
, gen_int_mode (GET_MODE_SIZE (mode
), Pmode
),
4396 (optimize_insn_for_speed_p()
4397 ? BLOCK_OP_NO_LIBCALL
: BLOCK_OP_NORMAL
));
4398 return get_last_insn ();
4401 ret
= emit_move_via_integer (mode
, x
, y
, true);
4406 return emit_move_complex_parts (x
, y
);
4409 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
4410 MODE is known to be MODE_CC. Returns the last instruction emitted. */
4413 emit_move_ccmode (machine_mode mode
, rtx x
, rtx y
)
4417 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
4420 enum insn_code code
= optab_handler (mov_optab
, CCmode
);
4421 if (code
!= CODE_FOR_nothing
)
4423 x
= emit_move_change_mode (CCmode
, mode
, x
, true);
4424 y
= emit_move_change_mode (CCmode
, mode
, y
, true);
4425 return emit_insn (GEN_FCN (code
) (x
, y
));
4429 /* Otherwise, find the MODE_INT mode of the same width. */
4430 ret
= emit_move_via_integer (mode
, x
, y
, false);
4431 gcc_assert (ret
!= NULL
);
4435 /* Return true if word I of OP lies entirely in the
4436 undefined bits of a paradoxical subreg. */
4439 undefined_operand_subword_p (const_rtx op
, int i
)
4441 if (GET_CODE (op
) != SUBREG
)
4443 machine_mode innermostmode
= GET_MODE (SUBREG_REG (op
));
4444 poly_int64 offset
= i
* UNITS_PER_WORD
+ subreg_memory_offset (op
);
4445 return (known_ge (offset
, GET_MODE_SIZE (innermostmode
))
4446 || known_le (offset
, -UNITS_PER_WORD
));
4449 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
4450 MODE is any multi-word or full-word mode that lacks a move_insn
4451 pattern. Note that you will get better code if you define such
4452 patterns, even if they must turn into multiple assembler instructions. */
4455 emit_move_multi_word (machine_mode mode
, rtx x
, rtx y
)
4457 rtx_insn
*last_insn
= 0;
4463 /* This function can only handle cases where the number of words is
4464 known at compile time. */
4465 mode_size
= GET_MODE_SIZE (mode
).to_constant ();
4466 gcc_assert (mode_size
>= UNITS_PER_WORD
);
4468 /* If X is a push on the stack, do the push now and replace
4469 X with a reference to the stack pointer. */
4470 if (push_operand (x
, mode
))
4471 x
= emit_move_resolve_push (mode
, x
);
4473 /* If we are in reload, see if either operand is a MEM whose address
4474 is scheduled for replacement. */
4475 if (reload_in_progress
&& MEM_P (x
)
4476 && (inner
= find_replacement (&XEXP (x
, 0))) != XEXP (x
, 0))
4477 x
= replace_equiv_address_nv (x
, inner
);
4478 if (reload_in_progress
&& MEM_P (y
)
4479 && (inner
= find_replacement (&XEXP (y
, 0))) != XEXP (y
, 0))
4480 y
= replace_equiv_address_nv (y
, inner
);
4484 need_clobber
= false;
4485 for (i
= 0; i
< CEIL (mode_size
, UNITS_PER_WORD
); i
++)
4487 /* Do not generate code for a move if it would go entirely
4488 to the non-existing bits of a paradoxical subreg. */
4489 if (undefined_operand_subword_p (x
, i
))
4492 rtx xpart
= operand_subword (x
, i
, 1, mode
);
4495 /* Do not generate code for a move if it would come entirely
4496 from the undefined bits of a paradoxical subreg. */
4497 if (undefined_operand_subword_p (y
, i
))
4500 ypart
= operand_subword (y
, i
, 1, mode
);
4502 /* If we can't get a part of Y, put Y into memory if it is a
4503 constant. Otherwise, force it into a register. Then we must
4504 be able to get a part of Y. */
4505 if (ypart
== 0 && CONSTANT_P (y
))
4507 y
= use_anchored_address (force_const_mem (mode
, y
));
4508 ypart
= operand_subword (y
, i
, 1, mode
);
4510 else if (ypart
== 0)
4511 ypart
= operand_subword_force (y
, i
, mode
);
4513 gcc_assert (xpart
&& ypart
);
4515 need_clobber
|= (GET_CODE (xpart
) == SUBREG
);
4517 last_insn
= emit_move_insn (xpart
, ypart
);
4523 /* Show the output dies here. This is necessary for SUBREGs
4524 of pseudos since we cannot track their lifetimes correctly;
4525 hard regs shouldn't appear here except as return values.
4526 We never want to emit such a clobber after reload. */
4528 && ! (reload_in_progress
|| reload_completed
)
4529 && need_clobber
!= 0)
4537 /* Low level part of emit_move_insn.
4538 Called just like emit_move_insn, but assumes X and Y
4539 are basically valid. */
4542 emit_move_insn_1 (rtx x
, rtx y
)
4544 machine_mode mode
= GET_MODE (x
);
4545 enum insn_code code
;
4547 gcc_assert ((unsigned int) mode
< (unsigned int) MAX_MACHINE_MODE
);
4549 code
= optab_handler (mov_optab
, mode
);
4550 if (code
!= CODE_FOR_nothing
)
4551 return emit_insn (GEN_FCN (code
) (x
, y
));
4553 /* Expand complex moves by moving real part and imag part. */
4554 if (COMPLEX_MODE_P (mode
))
4555 return emit_move_complex (mode
, x
, y
);
4557 if (GET_MODE_CLASS (mode
) == MODE_DECIMAL_FLOAT
4558 || ALL_FIXED_POINT_MODE_P (mode
))
4560 rtx_insn
*result
= emit_move_via_integer (mode
, x
, y
, true);
4562 /* If we can't find an integer mode, use multi words. */
4566 return emit_move_multi_word (mode
, x
, y
);
4569 if (GET_MODE_CLASS (mode
) == MODE_CC
)
4570 return emit_move_ccmode (mode
, x
, y
);
4572 /* Try using a move pattern for the corresponding integer mode. This is
4573 only safe when simplify_subreg can convert MODE constants into integer
4574 constants. At present, it can only do this reliably if the value
4575 fits within a HOST_WIDE_INT. */
4577 || known_le (GET_MODE_BITSIZE (mode
), HOST_BITS_PER_WIDE_INT
))
4579 rtx_insn
*ret
= emit_move_via_integer (mode
, x
, y
, lra_in_progress
);
4583 if (! lra_in_progress
|| recog (PATTERN (ret
), ret
, 0) >= 0)
4588 return emit_move_multi_word (mode
, x
, y
);
4591 /* Generate code to copy Y into X.
4592 Both Y and X must have the same mode, except that
4593 Y can be a constant with VOIDmode.
4594 This mode cannot be BLKmode; use emit_block_move for that.
4596 Return the last instruction emitted. */
4599 emit_move_insn (rtx x
, rtx y
)
4601 machine_mode mode
= GET_MODE (x
);
4602 rtx y_cst
= NULL_RTX
;
4603 rtx_insn
*last_insn
;
4606 gcc_assert (mode
!= BLKmode
4607 && (GET_MODE (y
) == mode
|| GET_MODE (y
) == VOIDmode
));
4609 /* If we have a copy that looks like one of the following patterns:
4610 (set (subreg:M1 (reg:M2 ...)) (subreg:M1 (reg:M2 ...)))
4611 (set (subreg:M1 (reg:M2 ...)) (mem:M1 ADDR))
4612 (set (mem:M1 ADDR) (subreg:M1 (reg:M2 ...)))
4613 (set (subreg:M1 (reg:M2 ...)) (constant C))
4614 where mode M1 is equal in size to M2, try to detect whether the
4615 mode change involves an implicit round trip through memory.
4616 If so, see if we can avoid that by removing the subregs and
4617 doing the move in mode M2 instead. */
4619 rtx x_inner
= NULL_RTX
;
4620 rtx y_inner
= NULL_RTX
;
4622 auto candidate_subreg_p
= [&](rtx subreg
) {
4623 return (REG_P (SUBREG_REG (subreg
))
4624 && known_eq (GET_MODE_SIZE (GET_MODE (SUBREG_REG (subreg
))),
4625 GET_MODE_SIZE (GET_MODE (subreg
)))
4626 && optab_handler (mov_optab
, GET_MODE (SUBREG_REG (subreg
)))
4627 != CODE_FOR_nothing
);
4630 auto candidate_mem_p
= [&](machine_mode innermode
, rtx mem
) {
4631 return (!targetm
.can_change_mode_class (innermode
, GET_MODE (mem
), ALL_REGS
)
4632 && !push_operand (mem
, GET_MODE (mem
))
4633 /* Not a candiate if innermode requires too much alignment. */
4634 && (MEM_ALIGN (mem
) >= GET_MODE_ALIGNMENT (innermode
)
4635 || targetm
.slow_unaligned_access (GET_MODE (mem
),
4637 || !targetm
.slow_unaligned_access (innermode
,
4641 if (SUBREG_P (x
) && candidate_subreg_p (x
))
4642 x_inner
= SUBREG_REG (x
);
4644 if (SUBREG_P (y
) && candidate_subreg_p (y
))
4645 y_inner
= SUBREG_REG (y
);
4647 if (x_inner
!= NULL_RTX
4648 && y_inner
!= NULL_RTX
4649 && GET_MODE (x_inner
) == GET_MODE (y_inner
)
4650 && !targetm
.can_change_mode_class (GET_MODE (x_inner
), mode
, ALL_REGS
))
4654 mode
= GET_MODE (x_inner
);
4656 else if (x_inner
!= NULL_RTX
4658 && candidate_mem_p (GET_MODE (x_inner
), y
))
4661 y
= adjust_address (y
, GET_MODE (x_inner
), 0);
4662 mode
= GET_MODE (x_inner
);
4664 else if (y_inner
!= NULL_RTX
4666 && candidate_mem_p (GET_MODE (y_inner
), x
))
4668 x
= adjust_address (x
, GET_MODE (y_inner
), 0);
4670 mode
= GET_MODE (y_inner
);
4672 else if (x_inner
!= NULL_RTX
4674 && !targetm
.can_change_mode_class (GET_MODE (x_inner
),
4676 && (y_inner
= simplify_subreg (GET_MODE (x_inner
), y
, mode
, 0)))
4680 mode
= GET_MODE (x_inner
);
4686 && SCALAR_FLOAT_MODE_P (GET_MODE (x
))
4687 && (last_insn
= compress_float_constant (x
, y
)))
4692 if (!targetm
.legitimate_constant_p (mode
, y
))
4694 y
= force_const_mem (mode
, y
);
4696 /* If the target's cannot_force_const_mem prevented the spill,
4697 assume that the target's move expanders will also take care
4698 of the non-legitimate constant. */
4702 y
= use_anchored_address (y
);
4706 /* If X or Y are memory references, verify that their addresses are valid
4709 && (! memory_address_addr_space_p (GET_MODE (x
), XEXP (x
, 0),
4711 && ! push_operand (x
, GET_MODE (x
))))
4712 x
= validize_mem (x
);
4715 && ! memory_address_addr_space_p (GET_MODE (y
), XEXP (y
, 0),
4716 MEM_ADDR_SPACE (y
)))
4717 y
= validize_mem (y
);
4719 gcc_assert (mode
!= BLKmode
);
4721 last_insn
= emit_move_insn_1 (x
, y
);
4723 if (y_cst
&& REG_P (x
)
4724 && (set
= single_set (last_insn
)) != NULL_RTX
4725 && SET_DEST (set
) == x
4726 && ! rtx_equal_p (y_cst
, SET_SRC (set
)))
4727 set_unique_reg_note (last_insn
, REG_EQUAL
, copy_rtx (y_cst
));
4732 /* Generate the body of an instruction to copy Y into X.
4733 It may be a list of insns, if one insn isn't enough. */
4736 gen_move_insn (rtx x
, rtx y
)
4741 emit_move_insn_1 (x
, y
);
4747 /* If Y is representable exactly in a narrower mode, and the target can
4748 perform the extension directly from constant or memory, then emit the
4749 move as an extension. */
4752 compress_float_constant (rtx x
, rtx y
)
4754 machine_mode dstmode
= GET_MODE (x
);
4755 machine_mode orig_srcmode
= GET_MODE (y
);
4756 machine_mode srcmode
;
4757 const REAL_VALUE_TYPE
*r
;
4758 int oldcost
, newcost
;
4759 bool speed
= optimize_insn_for_speed_p ();
4761 r
= CONST_DOUBLE_REAL_VALUE (y
);
4763 if (targetm
.legitimate_constant_p (dstmode
, y
))
4764 oldcost
= set_src_cost (y
, orig_srcmode
, speed
);
4766 oldcost
= set_src_cost (force_const_mem (dstmode
, y
), dstmode
, speed
);
4768 FOR_EACH_MODE_UNTIL (srcmode
, orig_srcmode
)
4772 rtx_insn
*last_insn
;
4774 /* Skip if the target can't extend this way. */
4775 ic
= can_extend_p (dstmode
, srcmode
, 0);
4776 if (ic
== CODE_FOR_nothing
)
4779 /* Skip if the narrowed value isn't exact. */
4780 if (! exact_real_truncate (srcmode
, r
))
4783 trunc_y
= const_double_from_real_value (*r
, srcmode
);
4785 if (targetm
.legitimate_constant_p (srcmode
, trunc_y
))
4787 /* Skip if the target needs extra instructions to perform
4789 if (!insn_operand_matches (ic
, 1, trunc_y
))
4791 /* This is valid, but may not be cheaper than the original. */
4792 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
4794 if (oldcost
< newcost
)
4797 else if (float_extend_from_mem
[dstmode
][srcmode
])
4799 trunc_y
= force_const_mem (srcmode
, trunc_y
);
4800 /* This is valid, but may not be cheaper than the original. */
4801 newcost
= set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode
, trunc_y
),
4803 if (oldcost
< newcost
)
4805 trunc_y
= validize_mem (trunc_y
);
4810 /* For CSE's benefit, force the compressed constant pool entry
4811 into a new pseudo. This constant may be used in different modes,
4812 and if not, combine will put things back together for us. */
4813 trunc_y
= force_reg (srcmode
, trunc_y
);
4815 /* If x is a hard register, perform the extension into a pseudo,
4816 so that e.g. stack realignment code is aware of it. */
4818 if (REG_P (x
) && HARD_REGISTER_P (x
))
4819 target
= gen_reg_rtx (dstmode
);
4821 emit_unop_insn (ic
, target
, trunc_y
, UNKNOWN
);
4822 last_insn
= get_last_insn ();
4825 set_unique_reg_note (last_insn
, REG_EQUAL
, y
);
4828 return emit_move_insn (x
, target
);
4835 /* Pushing data onto the stack. */
4837 /* Push a block of length SIZE (perhaps variable)
4838 and return an rtx to address the beginning of the block.
4839 The value may be virtual_outgoing_args_rtx.
4841 EXTRA is the number of bytes of padding to push in addition to SIZE.
4842 BELOW nonzero means this padding comes at low addresses;
4843 otherwise, the padding comes at high addresses. */
4846 push_block (rtx size
, poly_int64 extra
, int below
)
4850 size
= convert_modes (Pmode
, ptr_mode
, size
, 1);
4851 if (CONSTANT_P (size
))
4852 anti_adjust_stack (plus_constant (Pmode
, size
, extra
));
4853 else if (REG_P (size
) && known_eq (extra
, 0))
4854 anti_adjust_stack (size
);
4857 temp
= copy_to_mode_reg (Pmode
, size
);
4858 if (maybe_ne (extra
, 0))
4859 temp
= expand_binop (Pmode
, add_optab
, temp
,
4860 gen_int_mode (extra
, Pmode
),
4861 temp
, 0, OPTAB_LIB_WIDEN
);
4862 anti_adjust_stack (temp
);
4865 if (STACK_GROWS_DOWNWARD
)
4867 temp
= virtual_outgoing_args_rtx
;
4868 if (maybe_ne (extra
, 0) && below
)
4869 temp
= plus_constant (Pmode
, temp
, extra
);
4874 if (poly_int_rtx_p (size
, &csize
))
4875 temp
= plus_constant (Pmode
, virtual_outgoing_args_rtx
,
4876 -csize
- (below
? 0 : extra
));
4877 else if (maybe_ne (extra
, 0) && !below
)
4878 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
4879 negate_rtx (Pmode
, plus_constant (Pmode
, size
,
4882 temp
= gen_rtx_PLUS (Pmode
, virtual_outgoing_args_rtx
,
4883 negate_rtx (Pmode
, size
));
4886 return memory_address (NARROWEST_INT_MODE
, temp
);
4889 /* A utility routine that returns the base of an auto-inc memory, or NULL. */
4892 mem_autoinc_base (rtx mem
)
4896 rtx addr
= XEXP (mem
, 0);
4897 if (GET_RTX_CLASS (GET_CODE (addr
)) == RTX_AUTOINC
)
4898 return XEXP (addr
, 0);
4903 /* A utility routine used here, in reload, and in try_split. The insns
4904 after PREV up to and including LAST are known to adjust the stack,
4905 with a final value of END_ARGS_SIZE. Iterate backward from LAST
4906 placing notes as appropriate. PREV may be NULL, indicating the
4907 entire insn sequence prior to LAST should be scanned.
4909 The set of allowed stack pointer modifications is small:
4910 (1) One or more auto-inc style memory references (aka pushes),
4911 (2) One or more addition/subtraction with the SP as destination,
4912 (3) A single move insn with the SP as destination,
4913 (4) A call_pop insn,
4914 (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
4916 Insns in the sequence that do not modify the SP are ignored,
4917 except for noreturn calls.
4919 The return value is the amount of adjustment that can be trivially
4920 verified, via immediate operand or auto-inc. If the adjustment
4921 cannot be trivially extracted, the return value is HOST_WIDE_INT_MIN. */
4924 find_args_size_adjust (rtx_insn
*insn
)
4929 pat
= PATTERN (insn
);
4932 /* Look for a call_pop pattern. */
4935 /* We have to allow non-call_pop patterns for the case
4936 of emit_single_push_insn of a TLS address. */
4937 if (GET_CODE (pat
) != PARALLEL
)
4940 /* All call_pop have a stack pointer adjust in the parallel.
4941 The call itself is always first, and the stack adjust is
4942 usually last, so search from the end. */
4943 for (i
= XVECLEN (pat
, 0) - 1; i
> 0; --i
)
4945 set
= XVECEXP (pat
, 0, i
);
4946 if (GET_CODE (set
) != SET
)
4948 dest
= SET_DEST (set
);
4949 if (dest
== stack_pointer_rtx
)
4952 /* We'd better have found the stack pointer adjust. */
4955 /* Fall through to process the extracted SET and DEST
4956 as if it was a standalone insn. */
4958 else if (GET_CODE (pat
) == SET
)
4960 else if ((set
= single_set (insn
)) != NULL
)
4962 else if (GET_CODE (pat
) == PARALLEL
)
4964 /* ??? Some older ports use a parallel with a stack adjust
4965 and a store for a PUSH_ROUNDING pattern, rather than a
4966 PRE/POST_MODIFY rtx. Don't force them to update yet... */
4967 /* ??? See h8300 and m68k, pushqi1. */
4968 for (i
= XVECLEN (pat
, 0) - 1; i
>= 0; --i
)
4970 set
= XVECEXP (pat
, 0, i
);
4971 if (GET_CODE (set
) != SET
)
4973 dest
= SET_DEST (set
);
4974 if (dest
== stack_pointer_rtx
)
4977 /* We do not expect an auto-inc of the sp in the parallel. */
4978 gcc_checking_assert (mem_autoinc_base (dest
) != stack_pointer_rtx
);
4979 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
4980 != stack_pointer_rtx
);
4988 dest
= SET_DEST (set
);
4990 /* Look for direct modifications of the stack pointer. */
4991 if (REG_P (dest
) && REGNO (dest
) == STACK_POINTER_REGNUM
)
4993 /* Look for a trivial adjustment, otherwise assume nothing. */
4994 /* Note that the SPU restore_stack_block pattern refers to
4995 the stack pointer in V4SImode. Consider that non-trivial. */
4997 if (SCALAR_INT_MODE_P (GET_MODE (dest
))
4998 && strip_offset (SET_SRC (set
), &offset
) == stack_pointer_rtx
)
5000 /* ??? Reload can generate no-op moves, which will be cleaned
5001 up later. Recognize it and continue searching. */
5002 else if (rtx_equal_p (dest
, SET_SRC (set
)))
5005 return HOST_WIDE_INT_MIN
;
5011 /* Otherwise only think about autoinc patterns. */
5012 if (mem_autoinc_base (dest
) == stack_pointer_rtx
)
5015 gcc_checking_assert (mem_autoinc_base (SET_SRC (set
))
5016 != stack_pointer_rtx
);
5018 else if (mem_autoinc_base (SET_SRC (set
)) == stack_pointer_rtx
)
5019 mem
= SET_SRC (set
);
5023 addr
= XEXP (mem
, 0);
5024 switch (GET_CODE (addr
))
5028 return GET_MODE_SIZE (GET_MODE (mem
));
5031 return -GET_MODE_SIZE (GET_MODE (mem
));
5034 addr
= XEXP (addr
, 1);
5035 gcc_assert (GET_CODE (addr
) == PLUS
);
5036 gcc_assert (XEXP (addr
, 0) == stack_pointer_rtx
);
5037 return rtx_to_poly_int64 (XEXP (addr
, 1));
5045 fixup_args_size_notes (rtx_insn
*prev
, rtx_insn
*last
,
5046 poly_int64 end_args_size
)
5048 poly_int64 args_size
= end_args_size
;
5049 bool saw_unknown
= false;
5052 for (insn
= last
; insn
!= prev
; insn
= PREV_INSN (insn
))
5054 if (!NONDEBUG_INSN_P (insn
))
5057 /* We might have existing REG_ARGS_SIZE notes, e.g. when pushing
5058 a call argument containing a TLS address that itself requires
5059 a call to __tls_get_addr. The handling of stack_pointer_delta
5060 in emit_single_push_insn is supposed to ensure that any such
5061 notes are already correct. */
5062 rtx note
= find_reg_note (insn
, REG_ARGS_SIZE
, NULL_RTX
);
5063 gcc_assert (!note
|| known_eq (args_size
, get_args_size (note
)));
5065 poly_int64 this_delta
= find_args_size_adjust (insn
);
5066 if (known_eq (this_delta
, 0))
5069 || ACCUMULATE_OUTGOING_ARGS
5070 || find_reg_note (insn
, REG_NORETURN
, NULL_RTX
) == NULL_RTX
)
5074 gcc_assert (!saw_unknown
);
5075 if (known_eq (this_delta
, HOST_WIDE_INT_MIN
))
5079 add_args_size_note (insn
, args_size
);
5080 if (STACK_GROWS_DOWNWARD
)
5081 this_delta
= -poly_uint64 (this_delta
);
5084 args_size
= HOST_WIDE_INT_MIN
;
5086 args_size
-= this_delta
;
5092 #ifdef PUSH_ROUNDING
5093 /* Emit single push insn. */
5096 emit_single_push_insn_1 (machine_mode mode
, rtx x
, tree type
)
5099 poly_int64 rounded_size
= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
5101 enum insn_code icode
;
5103 /* If there is push pattern, use it. Otherwise try old way of throwing
5104 MEM representing push operation to move expander. */
5105 icode
= optab_handler (push_optab
, mode
);
5106 if (icode
!= CODE_FOR_nothing
)
5108 class expand_operand ops
[1];
5110 create_input_operand (&ops
[0], x
, mode
);
5111 if (maybe_expand_insn (icode
, 1, ops
))
5114 if (known_eq (GET_MODE_SIZE (mode
), rounded_size
))
5115 dest_addr
= gen_rtx_fmt_e (STACK_PUSH_CODE
, Pmode
, stack_pointer_rtx
);
5116 /* If we are to pad downward, adjust the stack pointer first and
5117 then store X into the stack location using an offset. This is
5118 because emit_move_insn does not know how to pad; it does not have
5120 else if (targetm
.calls
.function_arg_padding (mode
, type
) == PAD_DOWNWARD
)
5122 emit_move_insn (stack_pointer_rtx
,
5123 expand_binop (Pmode
,
5124 STACK_GROWS_DOWNWARD
? sub_optab
5127 gen_int_mode (rounded_size
, Pmode
),
5128 NULL_RTX
, 0, OPTAB_LIB_WIDEN
));
5130 poly_int64 offset
= rounded_size
- GET_MODE_SIZE (mode
);
5131 if (STACK_GROWS_DOWNWARD
&& STACK_PUSH_CODE
== POST_DEC
)
5132 /* We have already decremented the stack pointer, so get the
5134 offset
+= rounded_size
;
5136 if (!STACK_GROWS_DOWNWARD
&& STACK_PUSH_CODE
== POST_INC
)
5137 /* We have already incremented the stack pointer, so get the
5139 offset
-= rounded_size
;
5141 dest_addr
= plus_constant (Pmode
, stack_pointer_rtx
, offset
);
5145 if (STACK_GROWS_DOWNWARD
)
5146 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
5147 dest_addr
= plus_constant (Pmode
, stack_pointer_rtx
, -rounded_size
);
5149 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
5150 dest_addr
= plus_constant (Pmode
, stack_pointer_rtx
, rounded_size
);
5152 dest_addr
= gen_rtx_PRE_MODIFY (Pmode
, stack_pointer_rtx
, dest_addr
);
5155 dest
= gen_rtx_MEM (mode
, dest_addr
);
5159 set_mem_attributes (dest
, type
, 1);
5161 if (cfun
->tail_call_marked
)
5162 /* Function incoming arguments may overlap with sibling call
5163 outgoing arguments and we cannot allow reordering of reads
5164 from function arguments with stores to outgoing arguments
5165 of sibling calls. */
5166 set_mem_alias_set (dest
, 0);
5168 emit_move_insn (dest
, x
);
5171 /* Emit and annotate a single push insn. */
5174 emit_single_push_insn (machine_mode mode
, rtx x
, tree type
)
5176 poly_int64 delta
, old_delta
= stack_pointer_delta
;
5177 rtx_insn
*prev
= get_last_insn ();
5180 emit_single_push_insn_1 (mode
, x
, type
);
5182 /* Adjust stack_pointer_delta to describe the situation after the push
5183 we just performed. Note that we must do this after the push rather
5184 than before the push in case calculating X needs pushes and pops of
5185 its own (e.g. if calling __tls_get_addr). The REG_ARGS_SIZE notes
5186 for such pushes and pops must not include the effect of the future
5188 stack_pointer_delta
+= PUSH_ROUNDING (GET_MODE_SIZE (mode
));
5190 last
= get_last_insn ();
5192 /* Notice the common case where we emitted exactly one insn. */
5193 if (PREV_INSN (last
) == prev
)
5195 add_args_size_note (last
, stack_pointer_delta
);
5199 delta
= fixup_args_size_notes (prev
, last
, stack_pointer_delta
);
5200 gcc_assert (known_eq (delta
, HOST_WIDE_INT_MIN
)
5201 || known_eq (delta
, old_delta
));
5205 /* If reading SIZE bytes from X will end up reading from
5206 Y return the number of bytes that overlap. Return -1
5207 if there is no overlap or -2 if we can't determine
5208 (for example when X and Y have different base registers). */
5211 memory_load_overlap (rtx x
, rtx y
, HOST_WIDE_INT size
)
5213 rtx tmp
= plus_constant (Pmode
, x
, size
);
5214 rtx sub
= simplify_gen_binary (MINUS
, Pmode
, tmp
, y
);
5216 if (!CONST_INT_P (sub
))
5219 HOST_WIDE_INT val
= INTVAL (sub
);
5221 return IN_RANGE (val
, 1, size
) ? val
: -1;
5224 /* Generate code to push X onto the stack, assuming it has mode MODE and
5226 MODE is redundant except when X is a CONST_INT (since they don't
5228 SIZE is an rtx for the size of data to be copied (in bytes),
5229 needed only if X is BLKmode.
5230 Return true if successful. May return false if asked to push a
5231 partial argument during a sibcall optimization (as specified by
5232 SIBCALL_P) and the incoming and outgoing pointers cannot be shown
5235 ALIGN (in bits) is maximum alignment we can assume.
5237 If PARTIAL and REG are both nonzero, then copy that many of the first
5238 bytes of X into registers starting with REG, and push the rest of X.
5239 The amount of space pushed is decreased by PARTIAL bytes.
5240 REG must be a hard register in this case.
5241 If REG is zero but PARTIAL is not, take any all others actions for an
5242 argument partially in registers, but do not actually load any
5245 EXTRA is the amount in bytes of extra space to leave next to this arg.
5246 This is ignored if an argument block has already been allocated.
5248 On a machine that lacks real push insns, ARGS_ADDR is the address of
5249 the bottom of the argument block for this call. We use indexing off there
5250 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
5251 argument block has not been preallocated.
5253 ARGS_SO_FAR is the size of args previously pushed for this call.
5255 REG_PARM_STACK_SPACE is nonzero if functions require stack space
5256 for arguments passed in registers. If nonzero, it will be the number
5257 of bytes required. */
5260 emit_push_insn (rtx x
, machine_mode mode
, tree type
, rtx size
,
5261 unsigned int align
, int partial
, rtx reg
, poly_int64 extra
,
5262 rtx args_addr
, rtx args_so_far
, int reg_parm_stack_space
,
5263 rtx alignment_pad
, bool sibcall_p
)
5266 pad_direction stack_direction
5267 = STACK_GROWS_DOWNWARD
? PAD_DOWNWARD
: PAD_UPWARD
;
5269 /* Decide where to pad the argument: PAD_DOWNWARD for below,
5270 PAD_UPWARD for above, or PAD_NONE for don't pad it.
5271 Default is below for small data on big-endian machines; else above. */
5272 pad_direction where_pad
= targetm
.calls
.function_arg_padding (mode
, type
);
5274 /* Invert direction if stack is post-decrement.
5276 if (STACK_PUSH_CODE
== POST_DEC
)
5277 if (where_pad
!= PAD_NONE
)
5278 where_pad
= (where_pad
== PAD_DOWNWARD
? PAD_UPWARD
: PAD_DOWNWARD
);
5282 int nregs
= partial
/ UNITS_PER_WORD
;
5283 rtx
*tmp_regs
= NULL
;
5284 int overlapping
= 0;
5287 || (STRICT_ALIGNMENT
&& align
< GET_MODE_ALIGNMENT (mode
)))
5289 /* Copy a block into the stack, entirely or partially. */
5296 offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
5297 used
= partial
- offset
;
5299 if (mode
!= BLKmode
)
5301 /* A value is to be stored in an insufficiently aligned
5302 stack slot; copy via a suitably aligned slot if
5304 size
= gen_int_mode (GET_MODE_SIZE (mode
), Pmode
);
5305 if (!MEM_P (xinner
))
5307 temp
= assign_temp (type
, 1, 1);
5308 emit_move_insn (temp
, xinner
);
5315 /* USED is now the # of bytes we need not copy to the stack
5316 because registers will take care of them. */
5319 xinner
= adjust_address (xinner
, BLKmode
, used
);
5321 /* If the partial register-part of the arg counts in its stack size,
5322 skip the part of stack space corresponding to the registers.
5323 Otherwise, start copying to the beginning of the stack space,
5324 by setting SKIP to 0. */
5325 skip
= (reg_parm_stack_space
== 0) ? 0 : used
;
5327 #ifdef PUSH_ROUNDING
5328 /* NB: Let the backend known the number of bytes to push and
5329 decide if push insns should be generated. */
5330 unsigned int push_size
;
5331 if (CONST_INT_P (size
))
5332 push_size
= INTVAL (size
);
5336 /* Do it with several push insns if that doesn't take lots of insns
5337 and if there is no difficulty with push insns that skip bytes
5338 on the stack for alignment purposes. */
5340 && targetm
.calls
.push_argument (push_size
)
5341 && CONST_INT_P (size
)
5343 && MEM_ALIGN (xinner
) >= align
5344 && can_move_by_pieces ((unsigned) INTVAL (size
) - used
, align
)
5345 /* Here we avoid the case of a structure whose weak alignment
5346 forces many pushes of a small amount of data,
5347 and such small pushes do rounding that causes trouble. */
5348 && ((!targetm
.slow_unaligned_access (word_mode
, align
))
5349 || align
>= BIGGEST_ALIGNMENT
5350 || known_eq (PUSH_ROUNDING (align
/ BITS_PER_UNIT
),
5351 align
/ BITS_PER_UNIT
))
5352 && known_eq (PUSH_ROUNDING (INTVAL (size
)), INTVAL (size
)))
5354 /* Push padding now if padding above and stack grows down,
5355 or if padding below and stack grows up.
5356 But if space already allocated, this has already been done. */
5357 if (maybe_ne (extra
, 0)
5359 && where_pad
!= PAD_NONE
5360 && where_pad
!= stack_direction
)
5361 anti_adjust_stack (gen_int_mode (extra
, Pmode
));
5363 move_by_pieces (NULL
, xinner
, INTVAL (size
) - used
, align
,
5367 #endif /* PUSH_ROUNDING */
5371 /* Otherwise make space on the stack and copy the data
5372 to the address of that space. */
5374 /* Deduct words put into registers from the size we must copy. */
5377 if (CONST_INT_P (size
))
5378 size
= GEN_INT (INTVAL (size
) - used
);
5380 size
= expand_binop (GET_MODE (size
), sub_optab
, size
,
5381 gen_int_mode (used
, GET_MODE (size
)),
5382 NULL_RTX
, 0, OPTAB_LIB_WIDEN
);
5385 /* Get the address of the stack space.
5386 In this case, we do not deal with EXTRA separately.
5387 A single stack adjust will do. */
5388 poly_int64 const_args_so_far
;
5391 temp
= push_block (size
, extra
, where_pad
== PAD_DOWNWARD
);
5394 else if (poly_int_rtx_p (args_so_far
, &const_args_so_far
))
5395 temp
= memory_address (BLKmode
,
5396 plus_constant (Pmode
, args_addr
,
5397 skip
+ const_args_so_far
));
5399 temp
= memory_address (BLKmode
,
5400 plus_constant (Pmode
,
5401 gen_rtx_PLUS (Pmode
,
5406 if (!ACCUMULATE_OUTGOING_ARGS
)
5408 /* If the source is referenced relative to the stack pointer,
5409 copy it to another register to stabilize it. We do not need
5410 to do this if we know that we won't be changing sp. */
5412 if (reg_mentioned_p (virtual_stack_dynamic_rtx
, temp
)
5413 || reg_mentioned_p (virtual_outgoing_args_rtx
, temp
))
5414 temp
= copy_to_reg (temp
);
5417 target
= gen_rtx_MEM (BLKmode
, temp
);
5419 /* We do *not* set_mem_attributes here, because incoming arguments
5420 may overlap with sibling call outgoing arguments and we cannot
5421 allow reordering of reads from function arguments with stores
5422 to outgoing arguments of sibling calls. We do, however, want
5423 to record the alignment of the stack slot. */
5424 /* ALIGN may well be better aligned than TYPE, e.g. due to
5425 PARM_BOUNDARY. Assume the caller isn't lying. */
5426 set_mem_align (target
, align
);
5428 /* If part should go in registers and pushing to that part would
5429 overwrite some of the values that need to go into regs, load the
5430 overlapping values into temporary pseudos to be moved into the hard
5431 regs at the end after the stack pushing has completed.
5432 We cannot load them directly into the hard regs here because
5433 they can be clobbered by the block move expansions.
5436 if (partial
> 0 && reg
!= 0 && mode
== BLKmode
5437 && GET_CODE (reg
) != PARALLEL
)
5439 overlapping
= memory_load_overlap (XEXP (x
, 0), temp
, partial
);
5440 if (overlapping
> 0)
5442 gcc_assert (overlapping
% UNITS_PER_WORD
== 0);
5443 overlapping
/= UNITS_PER_WORD
;
5445 tmp_regs
= XALLOCAVEC (rtx
, overlapping
);
5447 for (int i
= 0; i
< overlapping
; i
++)
5448 tmp_regs
[i
] = gen_reg_rtx (word_mode
);
5450 for (int i
= 0; i
< overlapping
; i
++)
5451 emit_move_insn (tmp_regs
[i
],
5452 operand_subword_force (target
, i
, mode
));
5454 else if (overlapping
== -1)
5456 /* Could not determine whether there is overlap.
5457 Fail the sibcall. */
5466 /* If source is a constant VAR_DECL with a simple constructor,
5467 store the constructor to the stack instead of moving it. */
5471 && SYMBOL_REF_P (XEXP (xinner
, 0))
5472 && (decl
= SYMBOL_REF_DECL (XEXP (xinner
, 0))) != NULL_TREE
5474 && TREE_READONLY (decl
)
5475 && !TREE_SIDE_EFFECTS (decl
)
5476 && immediate_const_ctor_p (DECL_INITIAL (decl
), 2))
5477 store_constructor (DECL_INITIAL (decl
), target
, 0,
5478 int_expr_size (DECL_INITIAL (decl
)), false);
5480 emit_block_move (target
, xinner
, size
, BLOCK_OP_CALL_PARM
);
5483 else if (partial
> 0)
5485 /* Scalar partly in registers. This case is only supported
5486 for fixed-wdth modes. */
5487 int num_words
= GET_MODE_SIZE (mode
).to_constant ();
5488 num_words
/= UNITS_PER_WORD
;
5491 /* # bytes of start of argument
5492 that we must make space for but need not store. */
5493 int offset
= partial
% (PARM_BOUNDARY
/ BITS_PER_UNIT
);
5494 int args_offset
= INTVAL (args_so_far
);
5497 /* Push padding now if padding above and stack grows down,
5498 or if padding below and stack grows up.
5499 But if space already allocated, this has already been done. */
5500 if (maybe_ne (extra
, 0)
5502 && where_pad
!= PAD_NONE
5503 && where_pad
!= stack_direction
)
5504 anti_adjust_stack (gen_int_mode (extra
, Pmode
));
5506 /* If we make space by pushing it, we might as well push
5507 the real data. Otherwise, we can leave OFFSET nonzero
5508 and leave the space uninitialized. */
5512 /* Now NOT_STACK gets the number of words that we don't need to
5513 allocate on the stack. Convert OFFSET to words too. */
5514 not_stack
= (partial
- offset
) / UNITS_PER_WORD
;
5515 offset
/= UNITS_PER_WORD
;
5517 /* If the partial register-part of the arg counts in its stack size,
5518 skip the part of stack space corresponding to the registers.
5519 Otherwise, start copying to the beginning of the stack space,
5520 by setting SKIP to 0. */
5521 skip
= (reg_parm_stack_space
== 0) ? 0 : not_stack
;
5523 if (CONSTANT_P (x
) && !targetm
.legitimate_constant_p (mode
, x
))
5524 x
= validize_mem (force_const_mem (mode
, x
));
5526 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
5527 SUBREGs of such registers are not allowed. */
5528 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
5529 && GET_MODE_CLASS (GET_MODE (x
)) != MODE_INT
))
5530 x
= copy_to_reg (x
);
5532 /* Loop over all the words allocated on the stack for this arg. */
5533 /* We can do it by words, because any scalar bigger than a word
5534 has a size a multiple of a word. */
5535 for (i
= num_words
- 1; i
>= not_stack
; i
--)
5536 if (i
>= not_stack
+ offset
)
5537 if (!emit_push_insn (operand_subword_force (x
, i
, mode
),
5538 word_mode
, NULL_TREE
, NULL_RTX
, align
, 0, NULL_RTX
,
5540 GEN_INT (args_offset
+ ((i
- not_stack
+ skip
)
5542 reg_parm_stack_space
, alignment_pad
, sibcall_p
))
5550 /* Push padding now if padding above and stack grows down,
5551 or if padding below and stack grows up.
5552 But if space already allocated, this has already been done. */
5553 if (maybe_ne (extra
, 0)
5555 && where_pad
!= PAD_NONE
5556 && where_pad
!= stack_direction
)
5557 anti_adjust_stack (gen_int_mode (extra
, Pmode
));
5559 #ifdef PUSH_ROUNDING
5560 if (args_addr
== 0 && targetm
.calls
.push_argument (0))
5561 emit_single_push_insn (mode
, x
, type
);
5565 addr
= simplify_gen_binary (PLUS
, Pmode
, args_addr
, args_so_far
);
5566 dest
= gen_rtx_MEM (mode
, memory_address (mode
, addr
));
5568 /* We do *not* set_mem_attributes here, because incoming arguments
5569 may overlap with sibling call outgoing arguments and we cannot
5570 allow reordering of reads from function arguments with stores
5571 to outgoing arguments of sibling calls. We do, however, want
5572 to record the alignment of the stack slot. */
5573 /* ALIGN may well be better aligned than TYPE, e.g. due to
5574 PARM_BOUNDARY. Assume the caller isn't lying. */
5575 set_mem_align (dest
, align
);
5577 emit_move_insn (dest
, x
);
5581 /* Move the partial arguments into the registers and any overlapping
5582 values that we moved into the pseudos in tmp_regs. */
5583 if (partial
> 0 && reg
!= 0)
5585 /* Handle calls that pass values in multiple non-contiguous locations.
5586 The Irix 6 ABI has examples of this. */
5587 if (GET_CODE (reg
) == PARALLEL
)
5588 emit_group_load (reg
, x
, type
, -1);
5591 gcc_assert (partial
% UNITS_PER_WORD
== 0);
5592 move_block_to_reg (REGNO (reg
), x
, nregs
- overlapping
, mode
);
5594 for (int i
= 0; i
< overlapping
; i
++)
5595 emit_move_insn (gen_rtx_REG (word_mode
, REGNO (reg
)
5596 + nregs
- overlapping
+ i
),
5602 if (maybe_ne (extra
, 0) && args_addr
== 0 && where_pad
== stack_direction
)
5603 anti_adjust_stack (gen_int_mode (extra
, Pmode
));
5605 if (alignment_pad
&& args_addr
== 0)
5606 anti_adjust_stack (alignment_pad
);
5611 /* Return X if X can be used as a subtarget in a sequence of arithmetic
5615 get_subtarget (rtx x
)
5619 /* Only registers can be subtargets. */
5621 /* Don't use hard regs to avoid extending their life. */
5622 || REGNO (x
) < FIRST_PSEUDO_REGISTER
5626 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
5627 FIELD is a bitfield. Returns true if the optimization was successful,
5628 and there's nothing else to do. */
5631 optimize_bitfield_assignment_op (poly_uint64 pbitsize
,
5632 poly_uint64 pbitpos
,
5633 poly_uint64 pbitregion_start
,
5634 poly_uint64 pbitregion_end
,
5635 machine_mode mode1
, rtx str_rtx
,
5636 tree to
, tree src
, bool reverse
)
5638 /* str_mode is not guaranteed to be a scalar type. */
5639 machine_mode str_mode
= GET_MODE (str_rtx
);
5640 unsigned int str_bitsize
;
5645 enum tree_code code
;
5647 unsigned HOST_WIDE_INT bitsize
, bitpos
, bitregion_start
, bitregion_end
;
5648 if (mode1
!= VOIDmode
5649 || !pbitsize
.is_constant (&bitsize
)
5650 || !pbitpos
.is_constant (&bitpos
)
5651 || !pbitregion_start
.is_constant (&bitregion_start
)
5652 || !pbitregion_end
.is_constant (&bitregion_end
)
5653 || bitsize
>= BITS_PER_WORD
5654 || !GET_MODE_BITSIZE (str_mode
).is_constant (&str_bitsize
)
5655 || str_bitsize
> BITS_PER_WORD
5656 || TREE_SIDE_EFFECTS (to
)
5657 || TREE_THIS_VOLATILE (to
))
5661 if (TREE_CODE (src
) != SSA_NAME
)
5663 if (TREE_CODE (TREE_TYPE (src
)) != INTEGER_TYPE
)
5666 srcstmt
= get_gimple_for_ssa_name (src
);
5668 || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt
)) != tcc_binary
)
5671 code
= gimple_assign_rhs_code (srcstmt
);
5673 op0
= gimple_assign_rhs1 (srcstmt
);
5675 /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
5676 to find its initialization. Hopefully the initialization will
5677 be from a bitfield load. */
5678 if (TREE_CODE (op0
) == SSA_NAME
)
5680 gimple
*op0stmt
= get_gimple_for_ssa_name (op0
);
5682 /* We want to eventually have OP0 be the same as TO, which
5683 should be a bitfield. */
5685 || !is_gimple_assign (op0stmt
)
5686 || gimple_assign_rhs_code (op0stmt
) != TREE_CODE (to
))
5688 op0
= gimple_assign_rhs1 (op0stmt
);
5691 op1
= gimple_assign_rhs2 (srcstmt
);
5693 if (!operand_equal_p (to
, op0
, 0))
5696 if (MEM_P (str_rtx
))
5698 unsigned HOST_WIDE_INT offset1
;
5700 if (str_bitsize
== 0 || str_bitsize
> BITS_PER_WORD
)
5701 str_bitsize
= BITS_PER_WORD
;
5703 scalar_int_mode best_mode
;
5704 if (!get_best_mode (bitsize
, bitpos
, bitregion_start
, bitregion_end
,
5705 MEM_ALIGN (str_rtx
), str_bitsize
, false, &best_mode
))
5707 str_mode
= best_mode
;
5708 str_bitsize
= GET_MODE_BITSIZE (best_mode
);
5711 bitpos
%= str_bitsize
;
5712 offset1
= (offset1
- bitpos
) / BITS_PER_UNIT
;
5713 str_rtx
= adjust_address (str_rtx
, str_mode
, offset1
);
5715 else if (!REG_P (str_rtx
) && GET_CODE (str_rtx
) != SUBREG
)
5718 /* If the bit field covers the whole REG/MEM, store_field
5719 will likely generate better code. */
5720 if (bitsize
>= str_bitsize
)
5723 /* We can't handle fields split across multiple entities. */
5724 if (bitpos
+ bitsize
> str_bitsize
)
5727 if (reverse
? !BYTES_BIG_ENDIAN
: BYTES_BIG_ENDIAN
)
5728 bitpos
= str_bitsize
- bitpos
- bitsize
;
5734 /* For now, just optimize the case of the topmost bitfield
5735 where we don't need to do any masking and also
5736 1 bit bitfields where xor can be used.
5737 We might win by one instruction for the other bitfields
5738 too if insv/extv instructions aren't used, so that
5739 can be added later. */
5740 if ((reverse
|| bitpos
+ bitsize
!= str_bitsize
)
5741 && (bitsize
!= 1 || TREE_CODE (op1
) != INTEGER_CST
))
5744 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
5745 value
= convert_modes (str_mode
,
5746 TYPE_MODE (TREE_TYPE (op1
)), value
,
5747 TYPE_UNSIGNED (TREE_TYPE (op1
)));
5749 /* We may be accessing data outside the field, which means
5750 we can alias adjacent data. */
5751 if (MEM_P (str_rtx
))
5753 str_rtx
= shallow_copy_rtx (str_rtx
);
5754 set_mem_alias_set (str_rtx
, 0);
5755 set_mem_expr (str_rtx
, 0);
5758 if (bitsize
== 1 && (reverse
|| bitpos
+ bitsize
!= str_bitsize
))
5760 value
= expand_and (str_mode
, value
, const1_rtx
, NULL
);
5764 binop
= code
== PLUS_EXPR
? add_optab
: sub_optab
;
5766 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
5768 value
= flip_storage_order (str_mode
, value
);
5769 result
= expand_binop (str_mode
, binop
, str_rtx
,
5770 value
, str_rtx
, 1, OPTAB_WIDEN
);
5771 if (result
!= str_rtx
)
5772 emit_move_insn (str_rtx
, result
);
5777 if (TREE_CODE (op1
) != INTEGER_CST
)
5779 value
= expand_expr (op1
, NULL_RTX
, str_mode
, EXPAND_NORMAL
);
5780 value
= convert_modes (str_mode
,
5781 TYPE_MODE (TREE_TYPE (op1
)), value
,
5782 TYPE_UNSIGNED (TREE_TYPE (op1
)));
5784 /* We may be accessing data outside the field, which means
5785 we can alias adjacent data. */
5786 if (MEM_P (str_rtx
))
5788 str_rtx
= shallow_copy_rtx (str_rtx
);
5789 set_mem_alias_set (str_rtx
, 0);
5790 set_mem_expr (str_rtx
, 0);
5793 binop
= code
== BIT_IOR_EXPR
? ior_optab
: xor_optab
;
5794 if (bitpos
+ bitsize
!= str_bitsize
)
5796 rtx mask
= gen_int_mode ((HOST_WIDE_INT_1U
<< bitsize
) - 1,
5798 value
= expand_and (str_mode
, value
, mask
, NULL_RTX
);
5800 value
= expand_shift (LSHIFT_EXPR
, str_mode
, value
, bitpos
, NULL_RTX
, 1);
5802 value
= flip_storage_order (str_mode
, value
);
5803 result
= expand_binop (str_mode
, binop
, str_rtx
,
5804 value
, str_rtx
, 1, OPTAB_WIDEN
);
5805 if (result
!= str_rtx
)
5806 emit_move_insn (str_rtx
, result
);
5816 /* In the C++ memory model, consecutive bit fields in a structure are
5817 considered one memory location.
5819 Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
5820 returns the bit range of consecutive bits in which this COMPONENT_REF
5821 belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
5822 and *OFFSET may be adjusted in the process.
5824 If the access does not need to be restricted, 0 is returned in both
5825 *BITSTART and *BITEND. */
5828 get_bit_range (poly_uint64
*bitstart
, poly_uint64
*bitend
, tree exp
,
5829 poly_int64
*bitpos
, tree
*offset
)
5831 poly_int64 bitoffset
;
5834 gcc_assert (TREE_CODE (exp
) == COMPONENT_REF
);
5836 field
= TREE_OPERAND (exp
, 1);
5837 repr
= DECL_BIT_FIELD_REPRESENTATIVE (field
);
5838 /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
5839 need to limit the range we can access. */
5842 *bitstart
= *bitend
= 0;
5846 /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
5847 part of a larger bit field, then the representative does not serve any
5848 useful purpose. This can occur in Ada. */
5849 if (handled_component_p (TREE_OPERAND (exp
, 0)))
5852 poly_int64 rbitsize
, rbitpos
;
5854 int unsignedp
, reversep
, volatilep
= 0;
5855 get_inner_reference (TREE_OPERAND (exp
, 0), &rbitsize
, &rbitpos
,
5856 &roffset
, &rmode
, &unsignedp
, &reversep
,
5858 if (!multiple_p (rbitpos
, BITS_PER_UNIT
))
5860 *bitstart
= *bitend
= 0;
5865 /* Compute the adjustment to bitpos from the offset of the field
5866 relative to the representative. DECL_FIELD_OFFSET of field and
5867 repr are the same by construction if they are not constants,
5868 see finish_bitfield_layout. */
5869 poly_uint64 field_offset
, repr_offset
;
5870 if (poly_int_tree_p (DECL_FIELD_OFFSET (field
), &field_offset
)
5871 && poly_int_tree_p (DECL_FIELD_OFFSET (repr
), &repr_offset
))
5872 bitoffset
= (field_offset
- repr_offset
) * BITS_PER_UNIT
;
5875 bitoffset
+= (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field
))
5876 - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr
)));
5878 /* If the adjustment is larger than bitpos, we would have a negative bit
5879 position for the lower bound and this may wreak havoc later. Adjust
5880 offset and bitpos to make the lower bound non-negative in that case. */
5881 if (maybe_gt (bitoffset
, *bitpos
))
5883 poly_int64 adjust_bits
= upper_bound (bitoffset
, *bitpos
) - *bitpos
;
5884 poly_int64 adjust_bytes
= exact_div (adjust_bits
, BITS_PER_UNIT
);
5886 *bitpos
+= adjust_bits
;
5887 if (*offset
== NULL_TREE
)
5888 *offset
= size_int (-adjust_bytes
);
5890 *offset
= size_binop (MINUS_EXPR
, *offset
, size_int (adjust_bytes
));
5894 *bitstart
= *bitpos
- bitoffset
;
5896 *bitend
= *bitstart
+ tree_to_poly_uint64 (DECL_SIZE (repr
)) - 1;
5899 /* Returns true if BASE is a DECL that does not reside in memory and
5900 has non-BLKmode. DECL_RTL must not be a MEM; if
5901 DECL_RTL was not set yet, return false. */
5904 non_mem_decl_p (tree base
)
5907 || TREE_ADDRESSABLE (base
)
5908 || DECL_MODE (base
) == BLKmode
)
5911 if (!DECL_RTL_SET_P (base
))
5914 return (!MEM_P (DECL_RTL (base
)));
5917 /* Returns true if REF refers to an object that does not
5918 reside in memory and has non-BLKmode. */
5921 mem_ref_refers_to_non_mem_p (tree ref
)
5925 if (TREE_CODE (ref
) == MEM_REF
5926 || TREE_CODE (ref
) == TARGET_MEM_REF
)
5928 tree addr
= TREE_OPERAND (ref
, 0);
5930 if (TREE_CODE (addr
) != ADDR_EXPR
)
5933 base
= TREE_OPERAND (addr
, 0);
5938 return non_mem_decl_p (base
);
5941 /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
5942 is true, try generating a nontemporal store. */
5945 expand_assignment (tree to
, tree from
, bool nontemporal
)
5951 enum insn_code icode
;
5953 /* Don't crash if the lhs of the assignment was erroneous. */
5954 if (TREE_CODE (to
) == ERROR_MARK
)
5956 expand_normal (from
);
5960 /* Optimize away no-op moves without side-effects. */
5961 if (operand_equal_p (to
, from
, 0))
5964 /* Handle misaligned stores. */
5965 mode
= TYPE_MODE (TREE_TYPE (to
));
5966 if ((TREE_CODE (to
) == MEM_REF
5967 || TREE_CODE (to
) == TARGET_MEM_REF
5970 && !mem_ref_refers_to_non_mem_p (to
)
5971 && ((align
= get_object_alignment (to
))
5972 < GET_MODE_ALIGNMENT (mode
))
5973 && (((icode
= optab_handler (movmisalign_optab
, mode
))
5974 != CODE_FOR_nothing
)
5975 || targetm
.slow_unaligned_access (mode
, align
)))
5979 reg
= expand_expr (from
, NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
5980 /* Handle PARALLEL. */
5981 reg
= maybe_emit_group_store (reg
, TREE_TYPE (from
));
5982 reg
= force_not_mem (reg
);
5983 mem
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5984 if (TREE_CODE (to
) == MEM_REF
&& REF_REVERSE_STORAGE_ORDER (to
))
5985 reg
= flip_storage_order (mode
, reg
);
5987 if (icode
!= CODE_FOR_nothing
)
5989 class expand_operand ops
[2];
5991 create_fixed_operand (&ops
[0], mem
);
5992 create_input_operand (&ops
[1], reg
, mode
);
5993 /* The movmisalign<mode> pattern cannot fail, else the assignment
5994 would silently be omitted. */
5995 expand_insn (icode
, 2, ops
);
5998 store_bit_field (mem
, GET_MODE_BITSIZE (mode
), 0, 0, 0, mode
, reg
,
6003 /* Assignment of a structure component needs special treatment
6004 if the structure component's rtx is not simply a MEM.
6005 Assignment of an array element at a constant index, and assignment of
6006 an array element in an unaligned packed structure field, has the same
6007 problem. Same for (partially) storing into a non-memory object. */
6008 if (handled_component_p (to
)
6009 || (TREE_CODE (to
) == MEM_REF
6010 && (REF_REVERSE_STORAGE_ORDER (to
)
6011 || mem_ref_refers_to_non_mem_p (to
)))
6012 || TREE_CODE (TREE_TYPE (to
)) == ARRAY_TYPE
)
6015 poly_int64 bitsize
, bitpos
;
6016 poly_uint64 bitregion_start
= 0;
6017 poly_uint64 bitregion_end
= 0;
6019 int unsignedp
, reversep
, volatilep
= 0;
6023 tem
= get_inner_reference (to
, &bitsize
, &bitpos
, &offset
, &mode1
,
6024 &unsignedp
, &reversep
, &volatilep
);
6026 /* Make sure bitpos is not negative, it can wreak havoc later. */
6027 if (maybe_lt (bitpos
, 0))
6029 gcc_assert (offset
== NULL_TREE
);
6030 offset
= size_int (bits_to_bytes_round_down (bitpos
));
6031 bitpos
= num_trailing_bits (bitpos
);
6034 if (TREE_CODE (to
) == COMPONENT_REF
6035 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to
, 1)))
6036 get_bit_range (&bitregion_start
, &bitregion_end
, to
, &bitpos
, &offset
);
6037 /* The C++ memory model naturally applies to byte-aligned fields.
6038 However, if we do not have a DECL_BIT_FIELD_TYPE but BITPOS or
6039 BITSIZE are not byte-aligned, there is no need to limit the range
6040 we can access. This can occur with packed structures in Ada. */
6041 else if (maybe_gt (bitsize
, 0)
6042 && multiple_p (bitsize
, BITS_PER_UNIT
)
6043 && multiple_p (bitpos
, BITS_PER_UNIT
))
6045 bitregion_start
= bitpos
;
6046 bitregion_end
= bitpos
+ bitsize
- 1;
6049 to_rtx
= expand_expr (tem
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
6051 /* If the field has a mode, we want to access it in the
6052 field's mode, not the computed mode.
6053 If a MEM has VOIDmode (external with incomplete type),
6054 use BLKmode for it instead. */
6057 if (mode1
!= VOIDmode
)
6058 to_rtx
= adjust_address (to_rtx
, mode1
, 0);
6059 else if (GET_MODE (to_rtx
) == VOIDmode
)
6060 to_rtx
= adjust_address (to_rtx
, BLKmode
, 0);
6065 machine_mode address_mode
;
6068 if (!MEM_P (to_rtx
))
6070 /* We can get constant negative offsets into arrays with broken
6071 user code. Translate this to a trap instead of ICEing. */
6072 gcc_assert (TREE_CODE (offset
) == INTEGER_CST
);
6073 expand_builtin_trap ();
6074 to_rtx
= gen_rtx_MEM (BLKmode
, const0_rtx
);
6077 offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
6078 address_mode
= get_address_mode (to_rtx
);
6079 if (GET_MODE (offset_rtx
) != address_mode
)
6081 /* We cannot be sure that the RTL in offset_rtx is valid outside
6082 of a memory address context, so force it into a register
6083 before attempting to convert it to the desired mode. */
6084 offset_rtx
= force_operand (offset_rtx
, NULL_RTX
);
6085 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
6088 /* If we have an expression in OFFSET_RTX and a non-zero
6089 byte offset in BITPOS, adding the byte offset before the
6090 OFFSET_RTX results in better intermediate code, which makes
6091 later rtl optimization passes perform better.
6093 We prefer intermediate code like this:
6095 r124:DI=r123:DI+0x18
6100 r124:DI=r123:DI+0x10
6101 [r124:DI+0x8]=r121:DI
6103 This is only done for aligned data values, as these can
6104 be expected to result in single move instructions. */
6106 if (mode1
!= VOIDmode
6107 && maybe_ne (bitpos
, 0)
6108 && maybe_gt (bitsize
, 0)
6109 && multiple_p (bitpos
, BITS_PER_UNIT
, &bytepos
)
6110 && multiple_p (bitpos
, bitsize
)
6111 && multiple_p (bitsize
, GET_MODE_ALIGNMENT (mode1
))
6112 && MEM_ALIGN (to_rtx
) >= GET_MODE_ALIGNMENT (mode1
))
6114 to_rtx
= adjust_address (to_rtx
, mode1
, bytepos
);
6115 bitregion_start
= 0;
6116 if (known_ge (bitregion_end
, poly_uint64 (bitpos
)))
6117 bitregion_end
-= bitpos
;
6121 to_rtx
= offset_address (to_rtx
, offset_rtx
,
6122 highest_pow2_factor_for_target (to
,
6126 /* No action is needed if the target is not a memory and the field
6127 lies completely outside that target. This can occur if the source
6128 code contains an out-of-bounds access to a small array. */
6130 && GET_MODE (to_rtx
) != BLKmode
6131 && known_ge (bitpos
, GET_MODE_PRECISION (GET_MODE (to_rtx
))))
6133 expand_normal (from
);
6136 /* Handle expand_expr of a complex value returning a CONCAT. */
6137 else if (GET_CODE (to_rtx
) == CONCAT
)
6139 machine_mode to_mode
= GET_MODE (to_rtx
);
6140 gcc_checking_assert (COMPLEX_MODE_P (to_mode
));
6141 poly_int64 mode_bitsize
= GET_MODE_BITSIZE (to_mode
);
6142 unsigned short inner_bitsize
= GET_MODE_UNIT_BITSIZE (to_mode
);
6143 if (TYPE_MODE (TREE_TYPE (from
)) == to_mode
6144 && known_eq (bitpos
, 0)
6145 && known_eq (bitsize
, mode_bitsize
))
6146 result
= store_expr (from
, to_rtx
, false, nontemporal
, reversep
);
6147 else if (TYPE_MODE (TREE_TYPE (from
)) == GET_MODE_INNER (to_mode
)
6148 && known_eq (bitsize
, inner_bitsize
)
6149 && (known_eq (bitpos
, 0)
6150 || known_eq (bitpos
, inner_bitsize
)))
6151 result
= store_expr (from
, XEXP (to_rtx
, maybe_ne (bitpos
, 0)),
6152 false, nontemporal
, reversep
);
6153 else if (known_le (bitpos
+ bitsize
, inner_bitsize
))
6154 result
= store_field (XEXP (to_rtx
, 0), bitsize
, bitpos
,
6155 bitregion_start
, bitregion_end
,
6156 mode1
, from
, get_alias_set (to
),
6157 nontemporal
, reversep
);
6158 else if (known_ge (bitpos
, inner_bitsize
))
6159 result
= store_field (XEXP (to_rtx
, 1), bitsize
,
6160 bitpos
- inner_bitsize
,
6161 bitregion_start
, bitregion_end
,
6162 mode1
, from
, get_alias_set (to
),
6163 nontemporal
, reversep
);
6164 else if (known_eq (bitpos
, 0) && known_eq (bitsize
, mode_bitsize
))
6166 result
= expand_normal (from
);
6167 if (GET_CODE (result
) == CONCAT
)
6169 to_mode
= GET_MODE_INNER (to_mode
);
6170 machine_mode from_mode
= GET_MODE_INNER (GET_MODE (result
));
6172 = simplify_gen_subreg (to_mode
, XEXP (result
, 0),
6175 = simplify_gen_subreg (to_mode
, XEXP (result
, 1),
6177 if (!from_real
|| !from_imag
)
6178 goto concat_store_slow
;
6179 emit_move_insn (XEXP (to_rtx
, 0), from_real
);
6180 emit_move_insn (XEXP (to_rtx
, 1), from_imag
);
6184 machine_mode from_mode
6185 = GET_MODE (result
) == VOIDmode
6186 ? TYPE_MODE (TREE_TYPE (from
))
6187 : GET_MODE (result
);
6190 from_rtx
= change_address (result
, to_mode
, NULL_RTX
);
6193 = simplify_gen_subreg (to_mode
, result
, from_mode
, 0);
6196 emit_move_insn (XEXP (to_rtx
, 0),
6197 read_complex_part (from_rtx
, false));
6198 emit_move_insn (XEXP (to_rtx
, 1),
6199 read_complex_part (from_rtx
, true));
6203 to_mode
= GET_MODE_INNER (to_mode
);
6205 = simplify_gen_subreg (to_mode
, result
, from_mode
, 0);
6207 = simplify_gen_subreg (to_mode
, result
, from_mode
,
6208 GET_MODE_SIZE (to_mode
));
6209 if (!from_real
|| !from_imag
)
6210 goto concat_store_slow
;
6211 emit_move_insn (XEXP (to_rtx
, 0), from_real
);
6212 emit_move_insn (XEXP (to_rtx
, 1), from_imag
);
6219 rtx temp
= assign_stack_temp (GET_MODE (to_rtx
),
6220 GET_MODE_SIZE (GET_MODE (to_rtx
)));
6221 write_complex_part (temp
, XEXP (to_rtx
, 0), false, true);
6222 write_complex_part (temp
, XEXP (to_rtx
, 1), true, false);
6223 result
= store_field (temp
, bitsize
, bitpos
,
6224 bitregion_start
, bitregion_end
,
6225 mode1
, from
, get_alias_set (to
),
6226 nontemporal
, reversep
);
6227 emit_move_insn (XEXP (to_rtx
, 0), read_complex_part (temp
, false));
6228 emit_move_insn (XEXP (to_rtx
, 1), read_complex_part (temp
, true));
6231 /* For calls to functions returning variable length structures, if TO_RTX
6232 is not a MEM, go through a MEM because we must not create temporaries
6234 else if (!MEM_P (to_rtx
)
6235 && TREE_CODE (from
) == CALL_EXPR
6236 && COMPLETE_TYPE_P (TREE_TYPE (from
))
6237 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from
))) != INTEGER_CST
)
6239 rtx temp
= assign_stack_temp (GET_MODE (to_rtx
),
6240 GET_MODE_SIZE (GET_MODE (to_rtx
)));
6241 result
= store_field (temp
, bitsize
, bitpos
, bitregion_start
,
6242 bitregion_end
, mode1
, from
, get_alias_set (to
),
6243 nontemporal
, reversep
);
6244 emit_move_insn (to_rtx
, temp
);
6250 /* If the field is at offset zero, we could have been given the
6251 DECL_RTX of the parent struct. Don't munge it. */
6252 to_rtx
= shallow_copy_rtx (to_rtx
);
6253 set_mem_attributes_minus_bitpos (to_rtx
, to
, 0, bitpos
);
6255 MEM_VOLATILE_P (to_rtx
) = 1;
6258 gcc_checking_assert (known_ge (bitpos
, 0));
6259 if (optimize_bitfield_assignment_op (bitsize
, bitpos
,
6260 bitregion_start
, bitregion_end
,
6261 mode1
, to_rtx
, to
, from
,
6264 else if (SUBREG_P (to_rtx
)
6265 && SUBREG_PROMOTED_VAR_P (to_rtx
))
6267 /* If to_rtx is a promoted subreg, we need to zero or sign
6268 extend the value afterwards. */
6269 if (TREE_CODE (to
) == MEM_REF
6270 && TYPE_MODE (TREE_TYPE (from
)) != BLKmode
6271 && !REF_REVERSE_STORAGE_ORDER (to
)
6272 && known_eq (bitpos
, 0)
6273 && known_eq (bitsize
, GET_MODE_BITSIZE (GET_MODE (to_rtx
))))
6274 result
= store_expr (from
, to_rtx
, 0, nontemporal
, false);
6275 /* Check if the field overlaps the MSB, requiring extension. */
6276 else if (maybe_eq (bitpos
+ bitsize
,
6277 GET_MODE_BITSIZE (GET_MODE (to_rtx
))))
6279 scalar_int_mode imode
= subreg_unpromoted_mode (to_rtx
);
6280 scalar_int_mode omode
= subreg_promoted_mode (to_rtx
);
6281 rtx to_rtx1
= lowpart_subreg (imode
, SUBREG_REG (to_rtx
),
6283 result
= store_field (to_rtx1
, bitsize
, bitpos
,
6284 bitregion_start
, bitregion_end
,
6285 mode1
, from
, get_alias_set (to
),
6286 nontemporal
, reversep
);
6287 /* If the target usually keeps IMODE appropriately
6288 extended in OMODE it's unsafe to refer to it using
6289 a SUBREG whilst this invariant doesn't hold. */
6290 if (targetm
.mode_rep_extended (imode
, omode
) != UNKNOWN
)
6291 to_rtx1
= simplify_gen_unary (TRUNCATE
, imode
,
6292 SUBREG_REG (to_rtx
), omode
);
6293 convert_move (SUBREG_REG (to_rtx
), to_rtx1
,
6294 SUBREG_PROMOTED_SIGN (to_rtx
));
6297 result
= store_field (to_rtx
, bitsize
, bitpos
,
6298 bitregion_start
, bitregion_end
,
6299 mode1
, from
, get_alias_set (to
),
6300 nontemporal
, reversep
);
6303 result
= store_field (to_rtx
, bitsize
, bitpos
,
6304 bitregion_start
, bitregion_end
,
6305 mode1
, from
, get_alias_set (to
),
6306 nontemporal
, reversep
);
6310 preserve_temp_slots (result
);
6315 /* If the rhs is a function call and its value is not an aggregate,
6316 call the function before we start to compute the lhs.
6317 This is needed for correct code for cases such as
6318 val = setjmp (buf) on machines where reference to val
6319 requires loading up part of an address in a separate insn.
6321 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
6322 since it might be a promoted variable where the zero- or sign- extension
6323 needs to be done. Handling this in the normal way is safe because no
6324 computation is done before the call. The same is true for SSA names. */
6325 if (TREE_CODE (from
) == CALL_EXPR
&& ! aggregate_value_p (from
, from
)
6326 && COMPLETE_TYPE_P (TREE_TYPE (from
))
6327 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from
))) == INTEGER_CST
6329 || TREE_CODE (to
) == PARM_DECL
6330 || TREE_CODE (to
) == RESULT_DECL
)
6331 && REG_P (DECL_RTL (to
)))
6332 || TREE_CODE (to
) == SSA_NAME
))
6337 value
= expand_normal (from
);
6340 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
6342 /* Handle calls that return values in multiple non-contiguous locations.
6343 The Irix 6 ABI has examples of this. */
6344 if (GET_CODE (to_rtx
) == PARALLEL
)
6346 if (GET_CODE (value
) == PARALLEL
)
6347 emit_group_move (to_rtx
, value
);
6349 emit_group_load (to_rtx
, value
, TREE_TYPE (from
),
6350 int_size_in_bytes (TREE_TYPE (from
)));
6352 else if (GET_CODE (value
) == PARALLEL
)
6353 emit_group_store (to_rtx
, value
, TREE_TYPE (from
),
6354 int_size_in_bytes (TREE_TYPE (from
)));
6355 else if (GET_MODE (to_rtx
) == BLKmode
)
6357 /* Handle calls that return BLKmode values in registers. */
6359 copy_blkmode_from_reg (to_rtx
, value
, TREE_TYPE (from
));
6361 emit_block_move (to_rtx
, value
, expr_size (from
), BLOCK_OP_NORMAL
);
6365 if (POINTER_TYPE_P (TREE_TYPE (to
)))
6366 value
= convert_memory_address_addr_space
6367 (as_a
<scalar_int_mode
> (GET_MODE (to_rtx
)), value
,
6368 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to
))));
6370 emit_move_insn (to_rtx
, value
);
6373 preserve_temp_slots (to_rtx
);
6378 /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
6379 to_rtx
= expand_expr (to
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
6381 /* Don't move directly into a return register. */
6382 if (TREE_CODE (to
) == RESULT_DECL
6383 && (REG_P (to_rtx
) || GET_CODE (to_rtx
) == PARALLEL
))
6389 /* If the source is itself a return value, it still is in a pseudo at
6390 this point so we can move it back to the return register directly. */
6392 && TYPE_MODE (TREE_TYPE (from
)) == BLKmode
6393 && TREE_CODE (from
) != CALL_EXPR
)
6394 temp
= copy_blkmode_to_reg (GET_MODE (to_rtx
), from
);
6396 temp
= expand_expr (from
, NULL_RTX
, GET_MODE (to_rtx
), EXPAND_NORMAL
);
6398 /* Handle calls that return values in multiple non-contiguous locations.
6399 The Irix 6 ABI has examples of this. */
6400 if (GET_CODE (to_rtx
) == PARALLEL
)
6402 if (GET_CODE (temp
) == PARALLEL
)
6403 emit_group_move (to_rtx
, temp
);
6405 emit_group_load (to_rtx
, temp
, TREE_TYPE (from
),
6406 int_size_in_bytes (TREE_TYPE (from
)));
6409 emit_move_insn (to_rtx
, temp
);
6411 preserve_temp_slots (to_rtx
);
6416 /* In case we are returning the contents of an object which overlaps
6417 the place the value is being stored, use a safe function when copying
6418 a value through a pointer into a structure value return block. */
6419 if (TREE_CODE (to
) == RESULT_DECL
6420 && TREE_CODE (from
) == INDIRECT_REF
6421 && ADDR_SPACE_GENERIC_P
6422 (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from
, 0)))))
6423 && refs_may_alias_p (to
, from
)
6424 && cfun
->returns_struct
6425 && !cfun
->returns_pcc_struct
)
6430 size
= expr_size (from
);
6431 from_rtx
= expand_normal (from
);
6433 emit_block_move_via_libcall (XEXP (to_rtx
, 0), XEXP (from_rtx
, 0), size
);
6435 preserve_temp_slots (to_rtx
);
6440 /* Compute FROM and store the value in the rtx we got. */
6443 result
= store_expr (from
, to_rtx
, 0, nontemporal
, false);
6444 preserve_temp_slots (result
);
6449 /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
6450 succeeded, false otherwise. */
6453 emit_storent_insn (rtx to
, rtx from
)
6455 class expand_operand ops
[2];
6456 machine_mode mode
= GET_MODE (to
);
6457 enum insn_code code
= optab_handler (storent_optab
, mode
);
6459 if (code
== CODE_FOR_nothing
)
6462 create_fixed_operand (&ops
[0], to
);
6463 create_input_operand (&ops
[1], from
, mode
);
6464 return maybe_expand_insn (code
, 2, ops
);
6467 /* Helper function for store_expr storing of STRING_CST. */
6470 string_cst_read_str (void *data
, void *, HOST_WIDE_INT offset
,
6471 fixed_size_mode mode
)
6473 tree str
= (tree
) data
;
6475 gcc_assert (offset
>= 0);
6476 if (offset
>= TREE_STRING_LENGTH (str
))
6479 if ((unsigned HOST_WIDE_INT
) offset
+ GET_MODE_SIZE (mode
)
6480 > (unsigned HOST_WIDE_INT
) TREE_STRING_LENGTH (str
))
6482 char *p
= XALLOCAVEC (char, GET_MODE_SIZE (mode
));
6483 size_t l
= TREE_STRING_LENGTH (str
) - offset
;
6484 memcpy (p
, TREE_STRING_POINTER (str
) + offset
, l
);
6485 memset (p
+ l
, '\0', GET_MODE_SIZE (mode
) - l
);
6486 return c_readstr (p
, mode
, false);
6489 return c_readstr (TREE_STRING_POINTER (str
) + offset
, mode
, false);
6492 /* Generate code for computing expression EXP,
6493 and storing the value into TARGET.
6495 If the mode is BLKmode then we may return TARGET itself.
6496 It turns out that in BLKmode it doesn't cause a problem.
6497 because C has no operators that could combine two different
6498 assignments into the same BLKmode object with different values
6499 with no sequence point. Will other languages need this to
6502 If CALL_PARAM_P is nonzero, this is a store into a call param on the
6503 stack, and block moves may need to be treated specially.
6505 If NONTEMPORAL is true, try using a nontemporal store instruction.
6507 If REVERSE is true, the store is to be done in reverse order. */
6510 store_expr (tree exp
, rtx target
, int call_param_p
,
6511 bool nontemporal
, bool reverse
)
6514 rtx alt_rtl
= NULL_RTX
;
6515 location_t loc
= curr_insn_location ();
6516 bool shortened_string_cst
= false;
6518 if (VOID_TYPE_P (TREE_TYPE (exp
)))
6520 /* C++ can generate ?: expressions with a throw expression in one
6521 branch and an rvalue in the other. Here, we resolve attempts to
6522 store the throw expression's nonexistent result. */
6523 gcc_assert (!call_param_p
);
6524 expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
6527 if (TREE_CODE (exp
) == COMPOUND_EXPR
)
6529 /* Perform first part of compound expression, then assign from second
6531 expand_expr (TREE_OPERAND (exp
, 0), const0_rtx
, VOIDmode
,
6532 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
6533 return store_expr (TREE_OPERAND (exp
, 1), target
,
6534 call_param_p
, nontemporal
, reverse
);
6536 else if (TREE_CODE (exp
) == COND_EXPR
&& GET_MODE (target
) == BLKmode
)
6538 /* For conditional expression, get safe form of the target. Then
6539 test the condition, doing the appropriate assignment on either
6540 side. This avoids the creation of unnecessary temporaries.
6541 For non-BLKmode, it is more efficient not to do this. */
6543 rtx_code_label
*lab1
= gen_label_rtx (), *lab2
= gen_label_rtx ();
6545 do_pending_stack_adjust ();
6547 jumpifnot (TREE_OPERAND (exp
, 0), lab1
,
6548 profile_probability::uninitialized ());
6549 store_expr (TREE_OPERAND (exp
, 1), target
, call_param_p
,
6550 nontemporal
, reverse
);
6551 emit_jump_insn (targetm
.gen_jump (lab2
));
6554 store_expr (TREE_OPERAND (exp
, 2), target
, call_param_p
,
6555 nontemporal
, reverse
);
6561 else if (GET_CODE (target
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (target
))
6562 /* If this is a scalar in a register that is stored in a wider mode
6563 than the declared mode, compute the result into its declared mode
6564 and then convert to the wider mode. Our value is the computed
6567 rtx inner_target
= 0;
6568 scalar_int_mode outer_mode
= subreg_unpromoted_mode (target
);
6569 scalar_int_mode inner_mode
= subreg_promoted_mode (target
);
6571 /* We can do the conversion inside EXP, which will often result
6572 in some optimizations. Do the conversion in two steps: first
6573 change the signedness, if needed, then the extend. But don't
6574 do this if the type of EXP is a subtype of something else
6575 since then the conversion might involve more than just
6576 converting modes. */
6577 if (INTEGRAL_TYPE_P (TREE_TYPE (exp
))
6578 && TREE_TYPE (TREE_TYPE (exp
)) == 0
6579 && GET_MODE_PRECISION (outer_mode
)
6580 == TYPE_PRECISION (TREE_TYPE (exp
)))
6582 if (!SUBREG_CHECK_PROMOTED_SIGN (target
,
6583 TYPE_UNSIGNED (TREE_TYPE (exp
))))
6585 /* Some types, e.g. Fortran's logical*4, won't have a signed
6586 version, so use the mode instead. */
6588 = (signed_or_unsigned_type_for
6589 (SUBREG_PROMOTED_SIGN (target
), TREE_TYPE (exp
)));
6591 ntype
= lang_hooks
.types
.type_for_mode
6592 (TYPE_MODE (TREE_TYPE (exp
)),
6593 SUBREG_PROMOTED_SIGN (target
));
6595 exp
= fold_convert_loc (loc
, ntype
, exp
);
6598 exp
= fold_convert_loc (loc
, lang_hooks
.types
.type_for_mode
6599 (inner_mode
, SUBREG_PROMOTED_SIGN (target
)),
6602 inner_target
= SUBREG_REG (target
);
6605 temp
= expand_expr (exp
, inner_target
, VOIDmode
,
6606 call_param_p
? EXPAND_STACK_PARM
: EXPAND_NORMAL
);
6609 /* If TEMP is a VOIDmode constant, use convert_modes to make
6610 sure that we properly convert it. */
6611 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
)
6613 temp
= convert_modes (outer_mode
, TYPE_MODE (TREE_TYPE (exp
)),
6614 temp
, SUBREG_PROMOTED_SIGN (target
));
6615 temp
= convert_modes (inner_mode
, outer_mode
, temp
,
6616 SUBREG_PROMOTED_SIGN (target
));
6618 else if (!SCALAR_INT_MODE_P (GET_MODE (temp
)))
6619 temp
= convert_modes (outer_mode
, TYPE_MODE (TREE_TYPE (exp
)),
6620 temp
, SUBREG_PROMOTED_SIGN (target
));
6622 convert_move (SUBREG_REG (target
), temp
,
6623 SUBREG_PROMOTED_SIGN (target
));
6627 else if ((TREE_CODE (exp
) == STRING_CST
6628 || (TREE_CODE (exp
) == MEM_REF
6629 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
6630 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
6632 && integer_zerop (TREE_OPERAND (exp
, 1))))
6633 && !nontemporal
&& !call_param_p
6636 /* Optimize initialization of an array with a STRING_CST. */
6637 HOST_WIDE_INT exp_len
, str_copy_len
;
6639 tree str
= TREE_CODE (exp
) == STRING_CST
6640 ? exp
: TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
6642 exp_len
= int_expr_size (exp
);
6646 if (TREE_STRING_LENGTH (str
) <= 0)
6649 if (can_store_by_pieces (exp_len
, string_cst_read_str
, (void *) str
,
6650 MEM_ALIGN (target
), false))
6652 store_by_pieces (target
, exp_len
, string_cst_read_str
, (void *) str
,
6653 MEM_ALIGN (target
), false, RETURN_BEGIN
);
6657 str_copy_len
= TREE_STRING_LENGTH (str
);
6659 /* Trailing NUL bytes in EXP will be handled by the call to
6660 clear_storage, which is more efficient than copying them from
6661 the STRING_CST, so trim those from STR_COPY_LEN. */
6662 while (str_copy_len
)
6664 if (TREE_STRING_POINTER (str
)[str_copy_len
- 1])
6669 if ((STORE_MAX_PIECES
& (STORE_MAX_PIECES
- 1)) == 0)
6671 str_copy_len
+= STORE_MAX_PIECES
- 1;
6672 str_copy_len
&= ~(STORE_MAX_PIECES
- 1);
6674 if (str_copy_len
>= exp_len
)
6677 if (!can_store_by_pieces (str_copy_len
, string_cst_read_str
,
6678 (void *) str
, MEM_ALIGN (target
), false))
6681 dest_mem
= store_by_pieces (target
, str_copy_len
, string_cst_read_str
,
6682 (void *) str
, MEM_ALIGN (target
), false,
6684 clear_storage (adjust_address_1 (dest_mem
, BLKmode
, 0, 1, 1, 0,
6685 exp_len
- str_copy_len
),
6686 GEN_INT (exp_len
- str_copy_len
), BLOCK_OP_NORMAL
);
6694 /* If we want to use a nontemporal or a reverse order store, force the
6695 value into a register first. */
6696 tmp_target
= nontemporal
|| reverse
? NULL_RTX
: target
;
6698 if (TREE_CODE (exp
) == STRING_CST
6699 && tmp_target
== target
6700 && GET_MODE (target
) == BLKmode
6701 && TYPE_MODE (TREE_TYPE (exp
)) == BLKmode
)
6703 rtx size
= expr_size (exp
);
6704 if (CONST_INT_P (size
)
6705 && size
!= const0_rtx
6707 > ((unsigned HOST_WIDE_INT
) TREE_STRING_LENGTH (exp
) + 32)))
6709 /* If the STRING_CST has much larger array type than
6710 TREE_STRING_LENGTH, only emit the TREE_STRING_LENGTH part of
6711 it into the rodata section as the code later on will use
6712 memset zero for the remainder anyway. See PR95052. */
6713 tmp_target
= NULL_RTX
;
6714 rexp
= copy_node (exp
);
6716 = build_index_type (size_int (TREE_STRING_LENGTH (exp
) - 1));
6717 TREE_TYPE (rexp
) = build_array_type (TREE_TYPE (TREE_TYPE (exp
)),
6719 shortened_string_cst
= true;
6722 temp
= expand_expr_real (rexp
, tmp_target
, GET_MODE (target
),
6724 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
),
6726 if (shortened_string_cst
)
6728 gcc_assert (MEM_P (temp
));
6729 temp
= change_address (temp
, BLKmode
, NULL_RTX
);
6733 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
6734 the same as that of TARGET, adjust the constant. This is needed, for
6735 example, in case it is a CONST_DOUBLE or CONST_WIDE_INT and we want
6736 only a word-sized value. */
6737 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
6738 && TREE_CODE (exp
) != ERROR_MARK
6739 && GET_MODE (target
) != TYPE_MODE (TREE_TYPE (exp
)))
6741 gcc_assert (!shortened_string_cst
);
6742 if (GET_MODE_CLASS (GET_MODE (target
))
6743 != GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (exp
)))
6744 && known_eq (GET_MODE_BITSIZE (GET_MODE (target
)),
6745 GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp
)))))
6747 rtx t
= simplify_gen_subreg (GET_MODE (target
), temp
,
6748 TYPE_MODE (TREE_TYPE (exp
)), 0);
6752 if (GET_MODE (temp
) == VOIDmode
)
6753 temp
= convert_modes (GET_MODE (target
), TYPE_MODE (TREE_TYPE (exp
)),
6754 temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
6757 /* If value was not generated in the target, store it there.
6758 Convert the value to TARGET's type first if necessary and emit the
6759 pending incrementations that have been queued when expanding EXP.
6760 Note that we cannot emit the whole queue blindly because this will
6761 effectively disable the POST_INC optimization later.
6763 If TEMP and TARGET compare equal according to rtx_equal_p, but
6764 one or both of them are volatile memory refs, we have to distinguish
6766 - expand_expr has used TARGET. In this case, we must not generate
6767 another copy. This can be detected by TARGET being equal according
6769 - expand_expr has not used TARGET - that means that the source just
6770 happens to have the same RTX form. Since temp will have been created
6771 by expand_expr, it will compare unequal according to == .
6772 We must generate a copy in this case, to reach the correct number
6773 of volatile memory references. */
6775 if ((! rtx_equal_p (temp
, target
)
6776 || (temp
!= target
&& (side_effects_p (temp
)
6777 || side_effects_p (target
)
6779 && !mems_same_for_tbaa_p (temp
, target
)))))
6780 && TREE_CODE (exp
) != ERROR_MARK
6781 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
6782 but TARGET is not valid memory reference, TEMP will differ
6783 from TARGET although it is really the same location. */
6785 && rtx_equal_p (alt_rtl
, target
)
6786 && !side_effects_p (alt_rtl
)
6787 && !side_effects_p (target
))
6788 /* If there's nothing to copy, don't bother. Don't call
6789 expr_size unless necessary, because some front-ends (C++)
6790 expr_size-hook must not be given objects that are not
6791 supposed to be bit-copied or bit-initialized. */
6792 && expr_size (exp
) != const0_rtx
)
6794 if (GET_MODE (temp
) != GET_MODE (target
) && GET_MODE (temp
) != VOIDmode
)
6796 gcc_assert (!shortened_string_cst
);
6797 if (GET_MODE (target
) == BLKmode
)
6799 /* Handle calls that return BLKmode values in registers. */
6800 if (REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
6801 copy_blkmode_from_reg (target
, temp
, TREE_TYPE (exp
));
6803 store_bit_field (target
,
6804 rtx_to_poly_int64 (expr_size (exp
))
6806 0, 0, 0, GET_MODE (temp
), temp
, reverse
,
6810 convert_move (target
, temp
, TYPE_UNSIGNED (TREE_TYPE (exp
)));
6813 else if (GET_MODE (temp
) == BLKmode
&& TREE_CODE (exp
) == STRING_CST
)
6815 /* Handle copying a string constant into an array. The string
6816 constant may be shorter than the array. So copy just the string's
6817 actual length, and clear the rest. First get the size of the data
6818 type of the string, which is actually the size of the target. */
6819 rtx size
= expr_size (exp
);
6821 if (CONST_INT_P (size
)
6822 && INTVAL (size
) < TREE_STRING_LENGTH (exp
))
6823 emit_block_move (target
, temp
, size
,
6825 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
6828 machine_mode pointer_mode
6829 = targetm
.addr_space
.pointer_mode (MEM_ADDR_SPACE (target
));
6830 machine_mode address_mode
= get_address_mode (target
);
6832 /* Compute the size of the data to copy from the string. */
6834 = size_binop_loc (loc
, MIN_EXPR
,
6835 make_tree (sizetype
, size
),
6836 size_int (TREE_STRING_LENGTH (exp
)));
6838 = expand_expr (copy_size
, NULL_RTX
, VOIDmode
,
6840 ? EXPAND_STACK_PARM
: EXPAND_NORMAL
));
6841 rtx_code_label
*label
= 0;
6843 /* Copy that much. */
6844 copy_size_rtx
= convert_to_mode (pointer_mode
, copy_size_rtx
,
6845 TYPE_UNSIGNED (sizetype
));
6846 emit_block_move (target
, temp
, copy_size_rtx
,
6848 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
6850 /* Figure out how much is left in TARGET that we have to clear.
6851 Do all calculations in pointer_mode. */
6852 poly_int64 const_copy_size
;
6853 if (poly_int_rtx_p (copy_size_rtx
, &const_copy_size
))
6855 size
= plus_constant (address_mode
, size
, -const_copy_size
);
6856 target
= adjust_address (target
, BLKmode
, const_copy_size
);
6860 size
= expand_binop (TYPE_MODE (sizetype
), sub_optab
, size
,
6861 copy_size_rtx
, NULL_RTX
, 0,
6864 if (GET_MODE (copy_size_rtx
) != address_mode
)
6865 copy_size_rtx
= convert_to_mode (address_mode
,
6867 TYPE_UNSIGNED (sizetype
));
6869 target
= offset_address (target
, copy_size_rtx
,
6870 highest_pow2_factor (copy_size
));
6871 label
= gen_label_rtx ();
6872 emit_cmp_and_jump_insns (size
, const0_rtx
, LT
, NULL_RTX
,
6873 GET_MODE (size
), 0, label
);
6876 if (size
!= const0_rtx
)
6877 clear_storage (target
, size
, BLOCK_OP_NORMAL
);
6883 else if (shortened_string_cst
)
6885 /* Handle calls that return values in multiple non-contiguous locations.
6886 The Irix 6 ABI has examples of this. */
6887 else if (GET_CODE (target
) == PARALLEL
)
6889 if (GET_CODE (temp
) == PARALLEL
)
6890 emit_group_move (target
, temp
);
6892 emit_group_load (target
, temp
, TREE_TYPE (exp
),
6893 int_size_in_bytes (TREE_TYPE (exp
)));
6895 else if (GET_CODE (temp
) == PARALLEL
)
6896 emit_group_store (target
, temp
, TREE_TYPE (exp
),
6897 int_size_in_bytes (TREE_TYPE (exp
)));
6898 else if (GET_MODE (temp
) == BLKmode
)
6899 emit_block_move (target
, temp
, expr_size (exp
),
6901 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
6902 /* If we emit a nontemporal store, there is nothing else to do. */
6903 else if (nontemporal
&& emit_storent_insn (target
, temp
))
6908 temp
= flip_storage_order (GET_MODE (target
), temp
);
6909 temp
= force_operand (temp
, target
);
6911 emit_move_insn (target
, temp
);
6915 gcc_assert (!shortened_string_cst
);
6920 /* Return true if field F of structure TYPE is a flexible array. */
6923 flexible_array_member_p (const_tree f
, const_tree type
)
6928 return (DECL_CHAIN (f
) == NULL
6929 && TREE_CODE (tf
) == ARRAY_TYPE
6931 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf
))
6932 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf
)))
6933 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf
))
6934 && int_size_in_bytes (type
) >= 0);
6937 /* If FOR_CTOR_P, return the number of top-level elements that a constructor
6938 must have in order for it to completely initialize a value of type TYPE.
6939 Return -1 if the number isn't known.
6941 If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
6943 static HOST_WIDE_INT
6944 count_type_elements (const_tree type
, bool for_ctor_p
)
6946 switch (TREE_CODE (type
))
6952 nelts
= array_type_nelts (type
);
6953 if (nelts
&& tree_fits_uhwi_p (nelts
))
6955 unsigned HOST_WIDE_INT n
;
6957 n
= tree_to_uhwi (nelts
) + 1;
6958 if (n
== 0 || for_ctor_p
)
6961 return n
* count_type_elements (TREE_TYPE (type
), false);
6963 return for_ctor_p
? -1 : 1;
6968 unsigned HOST_WIDE_INT n
;
6972 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
6973 if (TREE_CODE (f
) == FIELD_DECL
)
6976 n
+= count_type_elements (TREE_TYPE (f
), false);
6977 else if (!flexible_array_member_p (f
, type
))
6978 /* Don't count flexible arrays, which are not supposed
6979 to be initialized. */
6987 case QUAL_UNION_TYPE
:
6992 gcc_assert (!for_ctor_p
);
6993 /* Estimate the number of scalars in each field and pick the
6994 maximum. Other estimates would do instead; the idea is simply
6995 to make sure that the estimate is not sensitive to the ordering
6998 for (f
= TYPE_FIELDS (type
); f
; f
= DECL_CHAIN (f
))
6999 if (TREE_CODE (f
) == FIELD_DECL
)
7001 m
= count_type_elements (TREE_TYPE (f
), false);
7002 /* If the field doesn't span the whole union, add an extra
7003 scalar for the rest. */
7004 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f
)),
7005 TYPE_SIZE (type
)) != 1)
7018 unsigned HOST_WIDE_INT nelts
;
7019 if (TYPE_VECTOR_SUBPARTS (type
).is_constant (&nelts
))
7027 case FIXED_POINT_TYPE
:
7032 case REFERENCE_TYPE
:
7050 /* Helper for categorize_ctor_elements. Identical interface. */
7053 categorize_ctor_elements_1 (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
7054 HOST_WIDE_INT
*p_unique_nz_elts
,
7055 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
7057 unsigned HOST_WIDE_INT idx
;
7058 HOST_WIDE_INT nz_elts
, unique_nz_elts
, init_elts
, num_fields
;
7059 tree value
, purpose
, elt_type
;
7061 /* Whether CTOR is a valid constant initializer, in accordance with what
7062 initializer_constant_valid_p does. If inferred from the constructor
7063 elements, true until proven otherwise. */
7064 bool const_from_elts_p
= constructor_static_from_elts_p (ctor
);
7065 bool const_p
= const_from_elts_p
? true : TREE_STATIC (ctor
);
7071 elt_type
= NULL_TREE
;
7073 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor
), idx
, purpose
, value
)
7075 HOST_WIDE_INT mult
= 1;
7077 if (purpose
&& TREE_CODE (purpose
) == RANGE_EXPR
)
7079 tree lo_index
= TREE_OPERAND (purpose
, 0);
7080 tree hi_index
= TREE_OPERAND (purpose
, 1);
7082 if (tree_fits_uhwi_p (lo_index
) && tree_fits_uhwi_p (hi_index
))
7083 mult
= (tree_to_uhwi (hi_index
)
7084 - tree_to_uhwi (lo_index
) + 1);
7087 elt_type
= TREE_TYPE (value
);
7089 switch (TREE_CODE (value
))
7093 HOST_WIDE_INT nz
= 0, unz
= 0, ic
= 0;
7095 bool const_elt_p
= categorize_ctor_elements_1 (value
, &nz
, &unz
,
7098 nz_elts
+= mult
* nz
;
7099 unique_nz_elts
+= unz
;
7100 init_elts
+= mult
* ic
;
7102 if (const_from_elts_p
&& const_p
)
7103 const_p
= const_elt_p
;
7110 if (!initializer_zerop (value
))
7119 nz_elts
+= mult
* TREE_STRING_LENGTH (value
);
7120 unique_nz_elts
+= TREE_STRING_LENGTH (value
);
7121 init_elts
+= mult
* TREE_STRING_LENGTH (value
);
7125 if (!initializer_zerop (TREE_REALPART (value
)))
7130 if (!initializer_zerop (TREE_IMAGPART (value
)))
7135 init_elts
+= 2 * mult
;
7140 /* We can only construct constant-length vectors using
7142 unsigned int nunits
= VECTOR_CST_NELTS (value
).to_constant ();
7143 for (unsigned int i
= 0; i
< nunits
; ++i
)
7145 tree v
= VECTOR_CST_ELT (value
, i
);
7146 if (!initializer_zerop (v
))
7158 HOST_WIDE_INT tc
= count_type_elements (elt_type
, false);
7159 nz_elts
+= mult
* tc
;
7160 unique_nz_elts
+= tc
;
7161 init_elts
+= mult
* tc
;
7163 if (const_from_elts_p
&& const_p
)
7165 = initializer_constant_valid_p (value
,
7167 TYPE_REVERSE_STORAGE_ORDER
7175 if (*p_complete
&& !complete_ctor_at_level_p (TREE_TYPE (ctor
),
7176 num_fields
, elt_type
))
7177 *p_complete
= false;
7179 *p_nz_elts
+= nz_elts
;
7180 *p_unique_nz_elts
+= unique_nz_elts
;
7181 *p_init_elts
+= init_elts
;
7186 /* Examine CTOR to discover:
7187 * how many scalar fields are set to nonzero values,
7188 and place it in *P_NZ_ELTS;
7189 * the same, but counting RANGE_EXPRs as multiplier of 1 instead of
7190 high - low + 1 (this can be useful for callers to determine ctors
7191 that could be cheaply initialized with - perhaps nested - loops
7192 compared to copied from huge read-only data),
7193 and place it in *P_UNIQUE_NZ_ELTS;
7194 * how many scalar fields in total are in CTOR,
7195 and place it in *P_ELT_COUNT.
7196 * whether the constructor is complete -- in the sense that every
7197 meaningful byte is explicitly given a value --
7198 and place it in *P_COMPLETE.
7200 Return whether or not CTOR is a valid static constant initializer, the same
7201 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
7204 categorize_ctor_elements (const_tree ctor
, HOST_WIDE_INT
*p_nz_elts
,
7205 HOST_WIDE_INT
*p_unique_nz_elts
,
7206 HOST_WIDE_INT
*p_init_elts
, bool *p_complete
)
7209 *p_unique_nz_elts
= 0;
7213 return categorize_ctor_elements_1 (ctor
, p_nz_elts
, p_unique_nz_elts
,
7214 p_init_elts
, p_complete
);
7217 /* Return true if constructor CTOR is simple enough to be materialized
7218 in an integer mode register. Limit the size to WORDS words, which
7222 immediate_const_ctor_p (const_tree ctor
, unsigned int words
)
7224 /* Allow function to be called with a VAR_DECL's DECL_INITIAL. */
7225 if (!ctor
|| TREE_CODE (ctor
) != CONSTRUCTOR
)
7228 return TREE_CONSTANT (ctor
)
7229 && !TREE_ADDRESSABLE (ctor
)
7230 && CONSTRUCTOR_NELTS (ctor
)
7231 && TREE_CODE (TREE_TYPE (ctor
)) != ARRAY_TYPE
7232 && int_expr_size (ctor
) <= words
* UNITS_PER_WORD
7233 && initializer_constant_valid_for_bitfield_p (ctor
);
7236 /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
7237 of which had type LAST_TYPE. Each element was itself a complete
7238 initializer, in the sense that every meaningful byte was explicitly
7239 given a value. Return true if the same is true for the constructor
7243 complete_ctor_at_level_p (const_tree type
, HOST_WIDE_INT num_elts
,
7244 const_tree last_type
)
7246 if (TREE_CODE (type
) == UNION_TYPE
7247 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
7252 gcc_assert (num_elts
== 1 && last_type
);
7254 /* ??? We could look at each element of the union, and find the
7255 largest element. Which would avoid comparing the size of the
7256 initialized element against any tail padding in the union.
7257 Doesn't seem worth the effort... */
7258 return simple_cst_equal (TYPE_SIZE (type
), TYPE_SIZE (last_type
)) == 1;
7261 return count_type_elements (type
, true) == num_elts
;
7264 /* Return true if EXP contains mostly (3/4) zeros. */
7267 mostly_zeros_p (const_tree exp
)
7269 if (TREE_CODE (exp
) == CONSTRUCTOR
)
7271 HOST_WIDE_INT nz_elts
, unz_elts
, init_elts
;
7274 categorize_ctor_elements (exp
, &nz_elts
, &unz_elts
, &init_elts
,
7276 return !complete_p
|| nz_elts
< init_elts
/ 4;
7279 return initializer_zerop (exp
);
7282 /* Return true if EXP contains all zeros. */
7285 all_zeros_p (const_tree exp
)
7287 if (TREE_CODE (exp
) == CONSTRUCTOR
)
7289 HOST_WIDE_INT nz_elts
, unz_elts
, init_elts
;
7292 categorize_ctor_elements (exp
, &nz_elts
, &unz_elts
, &init_elts
,
7294 return nz_elts
== 0;
7297 return initializer_zerop (exp
);
7300 /* Helper function for store_constructor.
7301 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
7302 CLEARED is as for store_constructor.
7303 ALIAS_SET is the alias set to use for any stores.
7304 If REVERSE is true, the store is to be done in reverse order.
7306 This provides a recursive shortcut back to store_constructor when it isn't
7307 necessary to go through store_field. This is so that we can pass through
7308 the cleared field to let store_constructor know that we may not have to
7309 clear a substructure if the outer structure has already been cleared. */
7312 store_constructor_field (rtx target
, poly_uint64 bitsize
, poly_int64 bitpos
,
7313 poly_uint64 bitregion_start
,
7314 poly_uint64 bitregion_end
,
7316 tree exp
, int cleared
,
7317 alias_set_type alias_set
, bool reverse
)
7320 poly_uint64 bytesize
;
7321 if (TREE_CODE (exp
) == CONSTRUCTOR
7322 /* We can only call store_constructor recursively if the size and
7323 bit position are on a byte boundary. */
7324 && multiple_p (bitpos
, BITS_PER_UNIT
, &bytepos
)
7325 && maybe_ne (bitsize
, 0U)
7326 && multiple_p (bitsize
, BITS_PER_UNIT
, &bytesize
)
7327 /* If we have a nonzero bitpos for a register target, then we just
7328 let store_field do the bitfield handling. This is unlikely to
7329 generate unnecessary clear instructions anyways. */
7330 && (known_eq (bitpos
, 0) || MEM_P (target
)))
7334 machine_mode target_mode
= GET_MODE (target
);
7335 if (target_mode
!= BLKmode
7336 && !multiple_p (bitpos
, GET_MODE_ALIGNMENT (target_mode
)))
7337 target_mode
= BLKmode
;
7338 target
= adjust_address (target
, target_mode
, bytepos
);
7342 /* Update the alias set, if required. */
7343 if (MEM_P (target
) && ! MEM_KEEP_ALIAS_SET_P (target
)
7344 && MEM_ALIAS_SET (target
) != 0)
7346 target
= copy_rtx (target
);
7347 set_mem_alias_set (target
, alias_set
);
7350 store_constructor (exp
, target
, cleared
, bytesize
, reverse
);
7353 store_field (target
, bitsize
, bitpos
, bitregion_start
, bitregion_end
, mode
,
7354 exp
, alias_set
, false, reverse
);
7358 /* Returns the number of FIELD_DECLs in TYPE. */
7361 fields_length (const_tree type
)
7363 tree t
= TYPE_FIELDS (type
);
7366 for (; t
; t
= DECL_CHAIN (t
))
7367 if (TREE_CODE (t
) == FIELD_DECL
)
7374 /* Store the value of constructor EXP into the rtx TARGET.
7375 TARGET is either a REG or a MEM; we know it cannot conflict, since
7376 safe_from_p has been called.
7377 CLEARED is true if TARGET is known to have been zero'd.
7378 SIZE is the number of bytes of TARGET we are allowed to modify: this
7379 may not be the same as the size of EXP if we are assigning to a field
7380 which has been packed to exclude padding bits.
7381 If REVERSE is true, the store is to be done in reverse order. */
7384 store_constructor (tree exp
, rtx target
, int cleared
, poly_int64 size
,
7387 tree type
= TREE_TYPE (exp
);
7388 HOST_WIDE_INT exp_size
= int_size_in_bytes (type
);
7389 poly_int64 bitregion_end
= known_gt (size
, 0) ? size
* BITS_PER_UNIT
- 1 : 0;
7391 switch (TREE_CODE (type
))
7395 case QUAL_UNION_TYPE
:
7397 unsigned HOST_WIDE_INT idx
;
7400 /* The storage order is specified for every aggregate type. */
7401 reverse
= TYPE_REVERSE_STORAGE_ORDER (type
);
7403 /* If size is zero or the target is already cleared, do nothing. */
7404 if (known_eq (size
, 0) || cleared
)
7406 /* We either clear the aggregate or indicate the value is dead. */
7407 else if ((TREE_CODE (type
) == UNION_TYPE
7408 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
7409 && ! CONSTRUCTOR_ELTS (exp
))
7410 /* If the constructor is empty, clear the union. */
7412 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
7416 /* If we are building a static constructor into a register,
7417 set the initial value as zero so we can fold the value into
7418 a constant. But if more than one register is involved,
7419 this probably loses. */
7420 else if (REG_P (target
) && TREE_STATIC (exp
)
7421 && known_le (GET_MODE_SIZE (GET_MODE (target
)),
7422 REGMODE_NATURAL_SIZE (GET_MODE (target
))))
7424 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
7428 /* If the constructor has fewer fields than the structure or
7429 if we are initializing the structure to mostly zeros, clear
7430 the whole structure first. Don't do this if TARGET is a
7431 register whose mode size isn't equal to SIZE since
7432 clear_storage can't handle this case. */
7433 else if (known_size_p (size
)
7434 && (((int) CONSTRUCTOR_NELTS (exp
) != fields_length (type
))
7435 || mostly_zeros_p (exp
))
7437 || known_eq (GET_MODE_SIZE (GET_MODE (target
)), size
)))
7439 clear_storage (target
, gen_int_mode (size
, Pmode
),
7444 if (REG_P (target
) && !cleared
)
7445 emit_clobber (target
);
7447 /* Store each element of the constructor into the
7448 corresponding field of TARGET. */
7449 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, field
, value
)
7452 HOST_WIDE_INT bitsize
;
7453 HOST_WIDE_INT bitpos
= 0;
7455 rtx to_rtx
= target
;
7457 /* Just ignore missing fields. We cleared the whole
7458 structure, above, if any fields are missing. */
7462 if (cleared
&& initializer_zerop (value
))
7465 if (tree_fits_uhwi_p (DECL_SIZE (field
)))
7466 bitsize
= tree_to_uhwi (DECL_SIZE (field
));
7470 mode
= DECL_MODE (field
);
7471 if (DECL_BIT_FIELD (field
))
7474 offset
= DECL_FIELD_OFFSET (field
);
7475 if (tree_fits_shwi_p (offset
)
7476 && tree_fits_shwi_p (bit_position (field
)))
7478 bitpos
= int_bit_position (field
);
7484 /* If this initializes a field that is smaller than a
7485 word, at the start of a word, try to widen it to a full
7486 word. This special case allows us to output C++ member
7487 function initializations in a form that the optimizers
7489 if (WORD_REGISTER_OPERATIONS
7491 && bitsize
< BITS_PER_WORD
7492 && bitpos
% BITS_PER_WORD
== 0
7493 && GET_MODE_CLASS (mode
) == MODE_INT
7494 && TREE_CODE (value
) == INTEGER_CST
7496 && bitpos
+ BITS_PER_WORD
<= exp_size
* BITS_PER_UNIT
)
7498 type
= TREE_TYPE (value
);
7500 if (TYPE_PRECISION (type
) < BITS_PER_WORD
)
7502 type
= lang_hooks
.types
.type_for_mode
7503 (word_mode
, TYPE_UNSIGNED (type
));
7504 value
= fold_convert (type
, value
);
7505 /* Make sure the bits beyond the original bitsize are zero
7506 so that we can correctly avoid extra zeroing stores in
7507 later constructor elements. */
7509 = wide_int_to_tree (type
, wi::mask (bitsize
, false,
7511 value
= fold_build2 (BIT_AND_EXPR
, type
, value
, bitsize_mask
);
7514 if (BYTES_BIG_ENDIAN
)
7516 = fold_build2 (LSHIFT_EXPR
, type
, value
,
7517 build_int_cst (type
,
7518 BITS_PER_WORD
- bitsize
));
7519 bitsize
= BITS_PER_WORD
;
7523 if (MEM_P (to_rtx
) && !MEM_KEEP_ALIAS_SET_P (to_rtx
)
7524 && DECL_NONADDRESSABLE_P (field
))
7526 to_rtx
= copy_rtx (to_rtx
);
7527 MEM_KEEP_ALIAS_SET_P (to_rtx
) = 1;
7530 store_constructor_field (to_rtx
, bitsize
, bitpos
,
7531 0, bitregion_end
, mode
,
7533 get_alias_set (TREE_TYPE (field
)),
7541 unsigned HOST_WIDE_INT i
;
7544 tree elttype
= TREE_TYPE (type
);
7545 bool const_bounds_p
;
7546 HOST_WIDE_INT minelt
= 0;
7547 HOST_WIDE_INT maxelt
= 0;
7549 /* The storage order is specified for every aggregate type. */
7550 reverse
= TYPE_REVERSE_STORAGE_ORDER (type
);
7552 domain
= TYPE_DOMAIN (type
);
7553 const_bounds_p
= (TYPE_MIN_VALUE (domain
)
7554 && TYPE_MAX_VALUE (domain
)
7555 && tree_fits_shwi_p (TYPE_MIN_VALUE (domain
))
7556 && tree_fits_shwi_p (TYPE_MAX_VALUE (domain
)));
7558 /* If we have constant bounds for the range of the type, get them. */
7561 minelt
= tree_to_shwi (TYPE_MIN_VALUE (domain
));
7562 maxelt
= tree_to_shwi (TYPE_MAX_VALUE (domain
));
7565 /* If the constructor has fewer elements than the array, clear
7566 the whole array first. Similarly if this is static
7567 constructor of a non-BLKmode object. */
7569 need_to_clear
= false;
7570 else if (REG_P (target
) && TREE_STATIC (exp
))
7571 need_to_clear
= true;
7574 unsigned HOST_WIDE_INT idx
;
7575 HOST_WIDE_INT count
= 0, zero_count
= 0;
7576 need_to_clear
= ! const_bounds_p
;
7578 /* This loop is a more accurate version of the loop in
7579 mostly_zeros_p (it handles RANGE_EXPR in an index). It
7580 is also needed to check for missing elements. */
7581 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, index
, value
)
7583 HOST_WIDE_INT this_node_count
;
7588 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
7590 tree lo_index
= TREE_OPERAND (index
, 0);
7591 tree hi_index
= TREE_OPERAND (index
, 1);
7593 if (! tree_fits_uhwi_p (lo_index
)
7594 || ! tree_fits_uhwi_p (hi_index
))
7596 need_to_clear
= true;
7600 this_node_count
= (tree_to_uhwi (hi_index
)
7601 - tree_to_uhwi (lo_index
) + 1);
7604 this_node_count
= 1;
7606 count
+= this_node_count
;
7607 if (mostly_zeros_p (value
))
7608 zero_count
+= this_node_count
;
7611 /* Clear the entire array first if there are any missing
7612 elements, or if the incidence of zero elements is >=
7615 && (count
< maxelt
- minelt
+ 1
7616 || 4 * zero_count
>= 3 * count
))
7617 need_to_clear
= true;
7620 if (need_to_clear
&& maybe_gt (size
, 0))
7623 emit_move_insn (target
, CONST0_RTX (GET_MODE (target
)));
7625 clear_storage (target
, gen_int_mode (size
, Pmode
),
7630 if (!cleared
&& REG_P (target
))
7631 /* Inform later passes that the old value is dead. */
7632 emit_clobber (target
);
7634 /* Store each element of the constructor into the
7635 corresponding element of TARGET, determined by counting the
7637 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), i
, index
, value
)
7641 HOST_WIDE_INT bitpos
;
7642 rtx xtarget
= target
;
7644 if (cleared
&& initializer_zerop (value
))
7647 mode
= TYPE_MODE (elttype
);
7648 if (mode
!= BLKmode
)
7649 bitsize
= GET_MODE_BITSIZE (mode
);
7650 else if (!poly_int_tree_p (TYPE_SIZE (elttype
), &bitsize
))
7653 if (index
!= NULL_TREE
&& TREE_CODE (index
) == RANGE_EXPR
)
7655 tree lo_index
= TREE_OPERAND (index
, 0);
7656 tree hi_index
= TREE_OPERAND (index
, 1);
7657 rtx index_r
, pos_rtx
;
7658 HOST_WIDE_INT lo
, hi
, count
;
7661 /* If the range is constant and "small", unroll the loop. */
7663 && tree_fits_shwi_p (lo_index
)
7664 && tree_fits_shwi_p (hi_index
)
7665 && (lo
= tree_to_shwi (lo_index
),
7666 hi
= tree_to_shwi (hi_index
),
7667 count
= hi
- lo
+ 1,
7670 || (tree_fits_uhwi_p (TYPE_SIZE (elttype
))
7671 && (tree_to_uhwi (TYPE_SIZE (elttype
)) * count
7674 lo
-= minelt
; hi
-= minelt
;
7675 for (; lo
<= hi
; lo
++)
7677 bitpos
= lo
* tree_to_shwi (TYPE_SIZE (elttype
));
7680 && !MEM_KEEP_ALIAS_SET_P (target
)
7681 && TREE_CODE (type
) == ARRAY_TYPE
7682 && TYPE_NONALIASED_COMPONENT (type
))
7684 target
= copy_rtx (target
);
7685 MEM_KEEP_ALIAS_SET_P (target
) = 1;
7688 store_constructor_field
7689 (target
, bitsize
, bitpos
, 0, bitregion_end
,
7690 mode
, value
, cleared
,
7691 get_alias_set (elttype
), reverse
);
7696 rtx_code_label
*loop_start
= gen_label_rtx ();
7697 rtx_code_label
*loop_end
= gen_label_rtx ();
7700 expand_normal (hi_index
);
7702 index
= build_decl (EXPR_LOCATION (exp
),
7703 VAR_DECL
, NULL_TREE
, domain
);
7704 index_r
= gen_reg_rtx (promote_decl_mode (index
, NULL
));
7705 SET_DECL_RTL (index
, index_r
);
7706 store_expr (lo_index
, index_r
, 0, false, reverse
);
7708 /* Build the head of the loop. */
7709 do_pending_stack_adjust ();
7710 emit_label (loop_start
);
7712 /* Assign value to element index. */
7714 fold_convert (ssizetype
,
7715 fold_build2 (MINUS_EXPR
,
7718 TYPE_MIN_VALUE (domain
)));
7721 size_binop (MULT_EXPR
, position
,
7722 fold_convert (ssizetype
,
7723 TYPE_SIZE_UNIT (elttype
)));
7725 pos_rtx
= expand_normal (position
);
7726 xtarget
= offset_address (target
, pos_rtx
,
7727 highest_pow2_factor (position
));
7728 xtarget
= adjust_address (xtarget
, mode
, 0);
7729 if (TREE_CODE (value
) == CONSTRUCTOR
)
7730 store_constructor (value
, xtarget
, cleared
,
7731 exact_div (bitsize
, BITS_PER_UNIT
),
7734 store_expr (value
, xtarget
, 0, false, reverse
);
7736 /* Generate a conditional jump to exit the loop. */
7737 exit_cond
= build2 (LT_EXPR
, integer_type_node
,
7739 jumpif (exit_cond
, loop_end
,
7740 profile_probability::uninitialized ());
7742 /* Update the loop counter, and jump to the head of
7744 expand_assignment (index
,
7745 build2 (PLUS_EXPR
, TREE_TYPE (index
),
7746 index
, integer_one_node
),
7749 emit_jump (loop_start
);
7751 /* Build the end of the loop. */
7752 emit_label (loop_end
);
7755 else if ((index
!= 0 && ! tree_fits_shwi_p (index
))
7756 || ! tree_fits_uhwi_p (TYPE_SIZE (elttype
)))
7761 index
= ssize_int (1);
7764 index
= fold_convert (ssizetype
,
7765 fold_build2 (MINUS_EXPR
,
7768 TYPE_MIN_VALUE (domain
)));
7771 size_binop (MULT_EXPR
, index
,
7772 fold_convert (ssizetype
,
7773 TYPE_SIZE_UNIT (elttype
)));
7774 xtarget
= offset_address (target
,
7775 expand_normal (position
),
7776 highest_pow2_factor (position
));
7777 xtarget
= adjust_address (xtarget
, mode
, 0);
7778 store_expr (value
, xtarget
, 0, false, reverse
);
7783 bitpos
= ((tree_to_shwi (index
) - minelt
)
7784 * tree_to_uhwi (TYPE_SIZE (elttype
)));
7786 bitpos
= (i
* tree_to_uhwi (TYPE_SIZE (elttype
)));
7788 if (MEM_P (target
) && !MEM_KEEP_ALIAS_SET_P (target
)
7789 && TREE_CODE (type
) == ARRAY_TYPE
7790 && TYPE_NONALIASED_COMPONENT (type
))
7792 target
= copy_rtx (target
);
7793 MEM_KEEP_ALIAS_SET_P (target
) = 1;
7795 store_constructor_field (target
, bitsize
, bitpos
, 0,
7796 bitregion_end
, mode
, value
,
7797 cleared
, get_alias_set (elttype
),
7806 unsigned HOST_WIDE_INT idx
;
7807 constructor_elt
*ce
;
7810 insn_code icode
= CODE_FOR_nothing
;
7812 tree elttype
= TREE_TYPE (type
);
7813 int elt_size
= vector_element_bits (type
);
7814 machine_mode eltmode
= TYPE_MODE (elttype
);
7815 HOST_WIDE_INT bitsize
;
7816 HOST_WIDE_INT bitpos
;
7817 rtvec vector
= NULL
;
7819 unsigned HOST_WIDE_INT const_n_elts
;
7820 alias_set_type alias
;
7821 bool vec_vec_init_p
= false;
7822 machine_mode mode
= GET_MODE (target
);
7824 gcc_assert (eltmode
!= BLKmode
);
7826 /* Try using vec_duplicate_optab for uniform vectors. */
7827 if (!TREE_SIDE_EFFECTS (exp
)
7828 && VECTOR_MODE_P (mode
)
7829 && eltmode
== GET_MODE_INNER (mode
)
7830 && ((icode
= optab_handler (vec_duplicate_optab
, mode
))
7831 != CODE_FOR_nothing
)
7832 && (elt
= uniform_vector_p (exp
))
7833 && !VECTOR_TYPE_P (TREE_TYPE (elt
)))
7835 class expand_operand ops
[2];
7836 create_output_operand (&ops
[0], target
, mode
);
7837 create_input_operand (&ops
[1], expand_normal (elt
), eltmode
);
7838 expand_insn (icode
, 2, ops
);
7839 if (!rtx_equal_p (target
, ops
[0].value
))
7840 emit_move_insn (target
, ops
[0].value
);
7843 /* Use sign-extension for uniform boolean vectors with
7844 integer modes and single-bit mask entries.
7845 Effectively "vec_duplicate" for bitmasks. */
7847 && !TREE_SIDE_EFFECTS (exp
)
7848 && VECTOR_BOOLEAN_TYPE_P (type
)
7849 && SCALAR_INT_MODE_P (TYPE_MODE (type
))
7850 && (elt
= uniform_vector_p (exp
))
7851 && !VECTOR_TYPE_P (TREE_TYPE (elt
)))
7853 rtx op0
= force_reg (TYPE_MODE (TREE_TYPE (elt
)),
7854 expand_normal (elt
));
7855 rtx tmp
= gen_reg_rtx (mode
);
7856 convert_move (tmp
, op0
, 0);
7858 /* Ensure no excess bits are set.
7859 GCN needs this for nunits < 64.
7860 x86 needs this for nunits < 8. */
7861 auto nunits
= TYPE_VECTOR_SUBPARTS (type
).to_constant ();
7862 if (maybe_ne (GET_MODE_PRECISION (mode
), nunits
))
7863 tmp
= expand_binop (mode
, and_optab
, tmp
,
7864 GEN_INT ((1 << nunits
) - 1), target
,
7867 emit_move_insn (target
, tmp
);
7871 n_elts
= TYPE_VECTOR_SUBPARTS (type
);
7873 && VECTOR_MODE_P (mode
)
7874 && n_elts
.is_constant (&const_n_elts
))
7876 machine_mode emode
= eltmode
;
7877 bool vector_typed_elts_p
= false;
7879 if (CONSTRUCTOR_NELTS (exp
)
7880 && (TREE_CODE (TREE_TYPE (CONSTRUCTOR_ELT (exp
, 0)->value
))
7883 tree etype
= TREE_TYPE (CONSTRUCTOR_ELT (exp
, 0)->value
);
7884 gcc_assert (known_eq (CONSTRUCTOR_NELTS (exp
)
7885 * TYPE_VECTOR_SUBPARTS (etype
),
7887 emode
= TYPE_MODE (etype
);
7888 vector_typed_elts_p
= true;
7890 icode
= convert_optab_handler (vec_init_optab
, mode
, emode
);
7891 if (icode
!= CODE_FOR_nothing
)
7893 unsigned int n
= const_n_elts
;
7895 if (vector_typed_elts_p
)
7897 n
= CONSTRUCTOR_NELTS (exp
);
7898 vec_vec_init_p
= true;
7900 vector
= rtvec_alloc (n
);
7901 for (unsigned int k
= 0; k
< n
; k
++)
7902 RTVEC_ELT (vector
, k
) = CONST0_RTX (emode
);
7906 /* Compute the size of the elements in the CTOR. It differs
7907 from the size of the vector type elements only when the
7908 CTOR elements are vectors themselves. */
7909 tree val_type
= (CONSTRUCTOR_NELTS (exp
) != 0
7910 ? TREE_TYPE (CONSTRUCTOR_ELT (exp
, 0)->value
)
7912 if (VECTOR_TYPE_P (val_type
))
7913 bitsize
= tree_to_uhwi (TYPE_SIZE (val_type
));
7917 /* If the constructor has fewer elements than the vector,
7918 clear the whole array first. Similarly if this is static
7919 constructor of a non-BLKmode object. */
7921 need_to_clear
= false;
7922 else if (REG_P (target
) && TREE_STATIC (exp
))
7923 need_to_clear
= true;
7926 unsigned HOST_WIDE_INT count
= 0, zero_count
= 0;
7929 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
7931 int n_elts_here
= bitsize
/ elt_size
;
7932 count
+= n_elts_here
;
7933 if (mostly_zeros_p (value
))
7934 zero_count
+= n_elts_here
;
7937 /* Clear the entire vector first if there are any missing elements,
7938 or if the incidence of zero elements is >= 75%. */
7939 need_to_clear
= (maybe_lt (count
, n_elts
)
7940 || 4 * zero_count
>= 3 * count
);
7943 if (need_to_clear
&& maybe_gt (size
, 0) && !vector
)
7946 emit_move_insn (target
, CONST0_RTX (mode
));
7948 clear_storage (target
, gen_int_mode (size
, Pmode
),
7953 /* Inform later passes that the old value is dead. */
7954 if (!cleared
&& !vector
&& REG_P (target
) && maybe_gt (n_elts
, 1u))
7956 emit_move_insn (target
, CONST0_RTX (mode
));
7961 alias
= MEM_ALIAS_SET (target
);
7963 alias
= get_alias_set (elttype
);
7965 /* Store each element of the constructor into the corresponding
7966 element of TARGET, determined by counting the elements. */
7967 for (idx
= 0, i
= 0;
7968 vec_safe_iterate (CONSTRUCTOR_ELTS (exp
), idx
, &ce
);
7969 idx
++, i
+= bitsize
/ elt_size
)
7971 HOST_WIDE_INT eltpos
;
7972 tree value
= ce
->value
;
7974 if (cleared
&& initializer_zerop (value
))
7978 eltpos
= tree_to_uhwi (ce
->index
);
7986 gcc_assert (ce
->index
== NULL_TREE
);
7987 gcc_assert (TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
);
7991 gcc_assert (TREE_CODE (TREE_TYPE (value
)) != VECTOR_TYPE
);
7992 RTVEC_ELT (vector
, eltpos
) = expand_normal (value
);
7996 machine_mode value_mode
7997 = (TREE_CODE (TREE_TYPE (value
)) == VECTOR_TYPE
7998 ? TYPE_MODE (TREE_TYPE (value
)) : eltmode
);
7999 bitpos
= eltpos
* elt_size
;
8000 store_constructor_field (target
, bitsize
, bitpos
, 0,
8001 bitregion_end
, value_mode
,
8002 value
, cleared
, alias
, reverse
);
8007 emit_insn (GEN_FCN (icode
) (target
,
8008 gen_rtx_PARALLEL (mode
, vector
)));
8017 /* Store the value of EXP (an expression tree)
8018 into a subfield of TARGET which has mode MODE and occupies
8019 BITSIZE bits, starting BITPOS bits from the start of TARGET.
8020 If MODE is VOIDmode, it means that we are storing into a bit-field.
8022 BITREGION_START is bitpos of the first bitfield in this region.
8023 BITREGION_END is the bitpos of the ending bitfield in this region.
8024 These two fields are 0, if the C++ memory model does not apply,
8025 or we are not interested in keeping track of bitfield regions.
8027 Always return const0_rtx unless we have something particular to
8030 ALIAS_SET is the alias set for the destination. This value will
8031 (in general) be different from that for TARGET, since TARGET is a
8032 reference to the containing structure.
8034 If NONTEMPORAL is true, try generating a nontemporal store.
8036 If REVERSE is true, the store is to be done in reverse order. */
8039 store_field (rtx target
, poly_int64 bitsize
, poly_int64 bitpos
,
8040 poly_uint64 bitregion_start
, poly_uint64 bitregion_end
,
8041 machine_mode mode
, tree exp
,
8042 alias_set_type alias_set
, bool nontemporal
, bool reverse
)
8044 if (TREE_CODE (exp
) == ERROR_MARK
)
8047 /* If we have nothing to store, do nothing unless the expression has
8048 side-effects. Don't do that for zero sized addressable lhs of
8050 if (known_eq (bitsize
, 0)
8051 && (!TREE_ADDRESSABLE (TREE_TYPE (exp
))
8052 || TREE_CODE (exp
) != CALL_EXPR
))
8053 return expand_expr (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
8055 if (GET_CODE (target
) == CONCAT
)
8057 /* We're storing into a struct containing a single __complex. */
8059 gcc_assert (known_eq (bitpos
, 0));
8060 return store_expr (exp
, target
, 0, nontemporal
, reverse
);
8063 /* If the structure is in a register or if the component
8064 is a bit field, we cannot use addressing to access it.
8065 Use bit-field techniques or SUBREG to store in it. */
8067 poly_int64 decl_bitsize
;
8068 if (mode
== VOIDmode
8069 || (mode
!= BLKmode
&& ! direct_store
[(int) mode
]
8070 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
8071 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
8073 || GET_CODE (target
) == SUBREG
8074 /* If the field isn't aligned enough to store as an ordinary memref,
8075 store it as a bit field. */
8077 && ((((MEM_ALIGN (target
) < GET_MODE_ALIGNMENT (mode
))
8078 || !multiple_p (bitpos
, GET_MODE_ALIGNMENT (mode
)))
8079 && targetm
.slow_unaligned_access (mode
, MEM_ALIGN (target
)))
8080 || !multiple_p (bitpos
, BITS_PER_UNIT
)))
8081 || (known_size_p (bitsize
)
8083 && maybe_gt (GET_MODE_BITSIZE (mode
), bitsize
))
8084 /* If the RHS and field are a constant size and the size of the
8085 RHS isn't the same size as the bitfield, we must use bitfield
8087 || (known_size_p (bitsize
)
8088 && poly_int_tree_p (TYPE_SIZE (TREE_TYPE (exp
)))
8089 && maybe_ne (wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (exp
))),
8091 /* Except for initialization of full bytes from a CONSTRUCTOR, which
8092 we will handle specially below. */
8093 && !(TREE_CODE (exp
) == CONSTRUCTOR
8094 && multiple_p (bitsize
, BITS_PER_UNIT
))
8095 /* And except for bitwise copying of TREE_ADDRESSABLE types,
8096 where the FIELD_DECL has the right bitsize, but TREE_TYPE (exp)
8097 includes some extra padding. store_expr / expand_expr will in
8098 that case call get_inner_reference that will have the bitsize
8099 we check here and thus the block move will not clobber the
8100 padding that shouldn't be clobbered. In the future we could
8101 replace the TREE_ADDRESSABLE check with a check that
8102 get_base_address needs to live in memory. */
8103 && (!TREE_ADDRESSABLE (TREE_TYPE (exp
))
8104 || TREE_CODE (exp
) != COMPONENT_REF
8105 || !multiple_p (bitsize
, BITS_PER_UNIT
)
8106 || !multiple_p (bitpos
, BITS_PER_UNIT
)
8107 || !poly_int_tree_p (DECL_SIZE (TREE_OPERAND (exp
, 1)),
8109 || maybe_ne (decl_bitsize
, bitsize
))
8110 /* A call with an addressable return type and return-slot
8111 optimization must not need bitfield operations but we must
8112 pass down the original target. */
8113 && (TREE_CODE (exp
) != CALL_EXPR
8114 || !TREE_ADDRESSABLE (TREE_TYPE (exp
))
8115 || !CALL_EXPR_RETURN_SLOT_OPT (exp
)))
8116 /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
8117 decl we must use bitfield operations. */
8118 || (known_size_p (bitsize
)
8119 && TREE_CODE (exp
) == MEM_REF
8120 && TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
8121 && DECL_P (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
8122 && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
8123 && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)) != BLKmode
))
8128 /* If EXP is a NOP_EXPR of precision less than its mode, then that
8129 implies a mask operation. If the precision is the same size as
8130 the field we're storing into, that mask is redundant. This is
8131 particularly common with bit field assignments generated by the
8133 nop_def
= get_def_for_expr (exp
, NOP_EXPR
);
8136 tree type
= TREE_TYPE (exp
);
8137 if (INTEGRAL_TYPE_P (type
)
8138 && maybe_ne (TYPE_PRECISION (type
),
8139 GET_MODE_BITSIZE (TYPE_MODE (type
)))
8140 && known_eq (bitsize
, TYPE_PRECISION (type
)))
8142 tree op
= gimple_assign_rhs1 (nop_def
);
8143 type
= TREE_TYPE (op
);
8144 if (INTEGRAL_TYPE_P (type
)
8145 && known_ge (TYPE_PRECISION (type
), bitsize
))
8150 temp
= expand_normal (exp
);
8152 /* We don't support variable-sized BLKmode bitfields, since our
8153 handling of BLKmode is bound up with the ability to break
8154 things into words. */
8155 gcc_assert (mode
!= BLKmode
|| bitsize
.is_constant ());
8157 /* Handle calls that return values in multiple non-contiguous locations.
8158 The Irix 6 ABI has examples of this. */
8159 if (GET_CODE (temp
) == PARALLEL
)
8161 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
8162 machine_mode temp_mode
= GET_MODE (temp
);
8163 if (temp_mode
== BLKmode
|| temp_mode
== VOIDmode
)
8164 temp_mode
= smallest_int_mode_for_size (size
* BITS_PER_UNIT
);
8165 rtx temp_target
= gen_reg_rtx (temp_mode
);
8166 emit_group_store (temp_target
, temp
, TREE_TYPE (exp
), size
);
8170 /* Handle calls that return BLKmode values in registers. */
8171 else if (mode
== BLKmode
&& REG_P (temp
) && TREE_CODE (exp
) == CALL_EXPR
)
8173 rtx temp_target
= gen_reg_rtx (GET_MODE (temp
));
8174 copy_blkmode_from_reg (temp_target
, temp
, TREE_TYPE (exp
));
8178 /* If the value has aggregate type and an integral mode then, if BITSIZE
8179 is narrower than this mode and this is for big-endian data, we first
8180 need to put the value into the low-order bits for store_bit_field,
8181 except when MODE is BLKmode and BITSIZE larger than the word size
8182 (see the handling of fields larger than a word in store_bit_field).
8183 Moreover, the field may be not aligned on a byte boundary; in this
8184 case, if it has reverse storage order, it needs to be accessed as a
8185 scalar field with reverse storage order and we must first put the
8186 value into target order. */
8187 scalar_int_mode temp_mode
;
8188 if (AGGREGATE_TYPE_P (TREE_TYPE (exp
))
8189 && is_int_mode (GET_MODE (temp
), &temp_mode
))
8191 HOST_WIDE_INT size
= GET_MODE_BITSIZE (temp_mode
);
8193 reverse
= TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (exp
));
8196 temp
= flip_storage_order (temp_mode
, temp
);
8198 gcc_checking_assert (known_le (bitsize
, size
));
8199 if (maybe_lt (bitsize
, size
)
8200 && reverse
? !BYTES_BIG_ENDIAN
: BYTES_BIG_ENDIAN
8201 /* Use of to_constant for BLKmode was checked above. */
8202 && !(mode
== BLKmode
&& bitsize
.to_constant () > BITS_PER_WORD
))
8203 temp
= expand_shift (RSHIFT_EXPR
, temp_mode
, temp
,
8204 size
- bitsize
, NULL_RTX
, 1);
8207 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
8208 if (mode
!= VOIDmode
&& mode
!= BLKmode
8209 && mode
!= TYPE_MODE (TREE_TYPE (exp
)))
8210 temp
= convert_modes (mode
, TYPE_MODE (TREE_TYPE (exp
)), temp
, 1);
8212 /* If the mode of TEMP and TARGET is BLKmode, both must be in memory
8213 and BITPOS must be aligned on a byte boundary. If so, we simply do
8214 a block copy. Likewise for a BLKmode-like TARGET. */
8215 if (GET_MODE (temp
) == BLKmode
8216 && (GET_MODE (target
) == BLKmode
8218 && GET_MODE_CLASS (GET_MODE (target
)) == MODE_INT
8219 && multiple_p (bitpos
, BITS_PER_UNIT
)
8220 && multiple_p (bitsize
, BITS_PER_UNIT
))))
8222 gcc_assert (MEM_P (target
) && MEM_P (temp
));
8223 poly_int64 bytepos
= exact_div (bitpos
, BITS_PER_UNIT
);
8224 poly_int64 bytesize
= bits_to_bytes_round_up (bitsize
);
8226 target
= adjust_address (target
, VOIDmode
, bytepos
);
8227 emit_block_move (target
, temp
,
8228 gen_int_mode (bytesize
, Pmode
),
8234 /* If the mode of TEMP is still BLKmode and BITSIZE not larger than the
8235 word size, we need to load the value (see again store_bit_field). */
8236 if (GET_MODE (temp
) == BLKmode
&& known_le (bitsize
, BITS_PER_WORD
))
8238 temp_mode
= smallest_int_mode_for_size (bitsize
);
8239 temp
= extract_bit_field (temp
, bitsize
, 0, 1, NULL_RTX
, temp_mode
,
8240 temp_mode
, false, NULL
);
8243 /* Store the value in the bitfield. */
8244 gcc_checking_assert (known_ge (bitpos
, 0));
8245 store_bit_field (target
, bitsize
, bitpos
,
8246 bitregion_start
, bitregion_end
,
8247 mode
, temp
, reverse
, false);
8253 /* Now build a reference to just the desired component. */
8254 rtx to_rtx
= adjust_address (target
, mode
,
8255 exact_div (bitpos
, BITS_PER_UNIT
));
8257 if (to_rtx
== target
)
8258 to_rtx
= copy_rtx (to_rtx
);
8260 if (!MEM_KEEP_ALIAS_SET_P (to_rtx
) && MEM_ALIAS_SET (to_rtx
) != 0)
8261 set_mem_alias_set (to_rtx
, alias_set
);
8263 /* Above we avoided using bitfield operations for storing a CONSTRUCTOR
8264 into a target smaller than its type; handle that case now. */
8265 if (TREE_CODE (exp
) == CONSTRUCTOR
&& known_size_p (bitsize
))
8267 poly_int64 bytesize
= exact_div (bitsize
, BITS_PER_UNIT
);
8268 store_constructor (exp
, to_rtx
, 0, bytesize
, reverse
);
8272 return store_expr (exp
, to_rtx
, 0, nontemporal
, reverse
);
8276 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
8277 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
8278 codes and find the ultimate containing object, which we return.
8280 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
8281 bit position, *PUNSIGNEDP to the signedness and *PREVERSEP to the
8282 storage order of the field.
8283 If the position of the field is variable, we store a tree
8284 giving the variable offset (in units) in *POFFSET.
8285 This offset is in addition to the bit position.
8286 If the position is not variable, we store 0 in *POFFSET.
8288 If any of the extraction expressions is volatile,
8289 we store 1 in *PVOLATILEP. Otherwise we don't change that.
8291 If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
8292 Otherwise, it is a mode that can be used to access the field.
8294 If the field describes a variable-sized object, *PMODE is set to
8295 BLKmode and *PBITSIZE is set to -1. An access cannot be made in
8296 this case, but the address of the object can be found. */
8299 get_inner_reference (tree exp
, poly_int64
*pbitsize
,
8300 poly_int64
*pbitpos
, tree
*poffset
,
8301 machine_mode
*pmode
, int *punsignedp
,
8302 int *preversep
, int *pvolatilep
)
8305 machine_mode mode
= VOIDmode
;
8306 bool blkmode_bitfield
= false;
8307 tree offset
= size_zero_node
;
8308 poly_offset_int bit_offset
= 0;
8310 /* First get the mode, signedness, storage order and size. We do this from
8311 just the outermost expression. */
8313 if (TREE_CODE (exp
) == COMPONENT_REF
)
8315 tree field
= TREE_OPERAND (exp
, 1);
8316 size_tree
= DECL_SIZE (field
);
8317 if (flag_strict_volatile_bitfields
> 0
8318 && TREE_THIS_VOLATILE (exp
)
8319 && DECL_BIT_FIELD_TYPE (field
)
8320 && DECL_MODE (field
) != BLKmode
)
8321 /* Volatile bitfields should be accessed in the mode of the
8322 field's type, not the mode computed based on the bit
8324 mode
= TYPE_MODE (DECL_BIT_FIELD_TYPE (field
));
8325 else if (!DECL_BIT_FIELD (field
))
8327 mode
= DECL_MODE (field
);
8328 /* For vector fields re-check the target flags, as DECL_MODE
8329 could have been set with different target flags than
8330 the current function has. */
8331 if (VECTOR_TYPE_P (TREE_TYPE (field
))
8332 && VECTOR_MODE_P (TYPE_MODE_RAW (TREE_TYPE (field
))))
8333 mode
= TYPE_MODE (TREE_TYPE (field
));
8335 else if (DECL_MODE (field
) == BLKmode
)
8336 blkmode_bitfield
= true;
8338 *punsignedp
= DECL_UNSIGNED (field
);
8340 else if (TREE_CODE (exp
) == BIT_FIELD_REF
)
8342 size_tree
= TREE_OPERAND (exp
, 1);
8343 *punsignedp
= (! INTEGRAL_TYPE_P (TREE_TYPE (exp
))
8344 || TYPE_UNSIGNED (TREE_TYPE (exp
)));
8346 /* For vector element types with the correct size of access or for
8347 vector typed accesses use the mode of the access type. */
8348 if ((TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == VECTOR_TYPE
8349 && TREE_TYPE (exp
) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0)))
8350 && tree_int_cst_equal (size_tree
, TYPE_SIZE (TREE_TYPE (exp
))))
8351 || VECTOR_TYPE_P (TREE_TYPE (exp
)))
8352 mode
= TYPE_MODE (TREE_TYPE (exp
));
8356 mode
= TYPE_MODE (TREE_TYPE (exp
));
8357 *punsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
8359 if (mode
== BLKmode
)
8360 size_tree
= TYPE_SIZE (TREE_TYPE (exp
));
8362 *pbitsize
= GET_MODE_BITSIZE (mode
);
8367 if (! tree_fits_uhwi_p (size_tree
))
8368 mode
= BLKmode
, *pbitsize
= -1;
8370 *pbitsize
= tree_to_uhwi (size_tree
);
8373 *preversep
= reverse_storage_order_for_component_p (exp
);
8375 /* Compute cumulative bit-offset for nested component-refs and array-refs,
8376 and find the ultimate containing object. */
8379 switch (TREE_CODE (exp
))
8382 bit_offset
+= wi::to_poly_offset (TREE_OPERAND (exp
, 2));
8387 tree field
= TREE_OPERAND (exp
, 1);
8388 tree this_offset
= component_ref_field_offset (exp
);
8390 /* If this field hasn't been filled in yet, don't go past it.
8391 This should only happen when folding expressions made during
8392 type construction. */
8393 if (this_offset
== 0)
8396 offset
= size_binop (PLUS_EXPR
, offset
, this_offset
);
8397 bit_offset
+= wi::to_poly_offset (DECL_FIELD_BIT_OFFSET (field
));
8399 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
8404 case ARRAY_RANGE_REF
:
8406 tree index
= TREE_OPERAND (exp
, 1);
8407 tree low_bound
= array_ref_low_bound (exp
);
8408 tree unit_size
= array_ref_element_size (exp
);
8410 /* We assume all arrays have sizes that are a multiple of a byte.
8411 First subtract the lower bound, if any, in the type of the
8412 index, then convert to sizetype and multiply by the size of
8413 the array element. */
8414 if (! integer_zerop (low_bound
))
8415 index
= fold_build2 (MINUS_EXPR
, TREE_TYPE (index
),
8418 offset
= size_binop (PLUS_EXPR
, offset
,
8419 size_binop (MULT_EXPR
,
8420 fold_convert (sizetype
, index
),
8429 bit_offset
+= *pbitsize
;
8432 case VIEW_CONVERT_EXPR
:
8436 /* Hand back the decl for MEM[&decl, off]. */
8437 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
)
8439 tree off
= TREE_OPERAND (exp
, 1);
8440 if (!integer_zerop (off
))
8442 poly_offset_int boff
= mem_ref_offset (exp
);
8443 boff
<<= LOG2_BITS_PER_UNIT
;
8446 exp
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
8454 /* If any reference in the chain is volatile, the effect is volatile. */
8455 if (TREE_THIS_VOLATILE (exp
))
8458 exp
= TREE_OPERAND (exp
, 0);
8462 /* If OFFSET is constant, see if we can return the whole thing as a
8463 constant bit position. Make sure to handle overflow during
8465 if (poly_int_tree_p (offset
))
8467 poly_offset_int tem
= wi::sext (wi::to_poly_offset (offset
),
8468 TYPE_PRECISION (sizetype
));
8469 tem
<<= LOG2_BITS_PER_UNIT
;
8471 if (tem
.to_shwi (pbitpos
))
8472 *poffset
= offset
= NULL_TREE
;
8475 /* Otherwise, split it up. */
8478 /* Avoid returning a negative bitpos as this may wreak havoc later. */
8479 if (!bit_offset
.to_shwi (pbitpos
) || maybe_lt (*pbitpos
, 0))
8481 *pbitpos
= num_trailing_bits (bit_offset
.force_shwi ());
8482 poly_offset_int bytes
= bits_to_bytes_round_down (bit_offset
);
8483 offset
= size_binop (PLUS_EXPR
, offset
,
8484 build_int_cst (sizetype
, bytes
.force_shwi ()));
8490 /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
8491 if (mode
== VOIDmode
8493 && multiple_p (*pbitpos
, BITS_PER_UNIT
)
8494 && multiple_p (*pbitsize
, BITS_PER_UNIT
))
8502 /* Alignment in bits the TARGET of an assignment may be assumed to have. */
8504 static unsigned HOST_WIDE_INT
8505 target_align (const_tree target
)
8507 /* We might have a chain of nested references with intermediate misaligning
8508 bitfields components, so need to recurse to find out. */
8510 unsigned HOST_WIDE_INT this_align
, outer_align
;
8512 switch (TREE_CODE (target
))
8518 this_align
= DECL_ALIGN (TREE_OPERAND (target
, 1));
8519 outer_align
= target_align (TREE_OPERAND (target
, 0));
8520 return MIN (this_align
, outer_align
);
8523 case ARRAY_RANGE_REF
:
8524 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
8525 outer_align
= target_align (TREE_OPERAND (target
, 0));
8526 return MIN (this_align
, outer_align
);
8529 case NON_LVALUE_EXPR
:
8530 case VIEW_CONVERT_EXPR
:
8531 this_align
= TYPE_ALIGN (TREE_TYPE (target
));
8532 outer_align
= target_align (TREE_OPERAND (target
, 0));
8533 return MAX (this_align
, outer_align
);
8536 return TYPE_ALIGN (TREE_TYPE (target
));
8541 /* Given an rtx VALUE that may contain additions and multiplications, return
8542 an equivalent value that just refers to a register, memory, or constant.
8543 This is done by generating instructions to perform the arithmetic and
8544 returning a pseudo-register containing the value.
8546 The returned value may be a REG, SUBREG, MEM or constant. */
8549 force_operand (rtx value
, rtx target
)
8552 /* Use subtarget as the target for operand 0 of a binary operation. */
8553 rtx subtarget
= get_subtarget (target
);
8554 enum rtx_code code
= GET_CODE (value
);
8556 /* Check for subreg applied to an expression produced by loop optimizer. */
8558 && !REG_P (SUBREG_REG (value
))
8559 && !MEM_P (SUBREG_REG (value
)))
8562 = simplify_gen_subreg (GET_MODE (value
),
8563 force_reg (GET_MODE (SUBREG_REG (value
)),
8564 force_operand (SUBREG_REG (value
),
8566 GET_MODE (SUBREG_REG (value
)),
8567 SUBREG_BYTE (value
));
8568 code
= GET_CODE (value
);
8571 /* Check for a PIC address load. */
8572 if ((code
== PLUS
|| code
== MINUS
)
8573 && XEXP (value
, 0) == pic_offset_table_rtx
8574 && (GET_CODE (XEXP (value
, 1)) == SYMBOL_REF
8575 || GET_CODE (XEXP (value
, 1)) == LABEL_REF
8576 || GET_CODE (XEXP (value
, 1)) == CONST
))
8579 subtarget
= gen_reg_rtx (GET_MODE (value
));
8580 emit_move_insn (subtarget
, value
);
8584 if (ARITHMETIC_P (value
))
8586 op2
= XEXP (value
, 1);
8587 if (!CONSTANT_P (op2
) && !(REG_P (op2
) && op2
!= subtarget
))
8589 if (code
== MINUS
&& CONST_INT_P (op2
))
8592 op2
= negate_rtx (GET_MODE (value
), op2
);
8595 /* Check for an addition with OP2 a constant integer and our first
8596 operand a PLUS of a virtual register and something else. In that
8597 case, we want to emit the sum of the virtual register and the
8598 constant first and then add the other value. This allows virtual
8599 register instantiation to simply modify the constant rather than
8600 creating another one around this addition. */
8601 if (code
== PLUS
&& CONST_INT_P (op2
)
8602 && GET_CODE (XEXP (value
, 0)) == PLUS
8603 && REG_P (XEXP (XEXP (value
, 0), 0))
8604 && VIRTUAL_REGISTER_P (XEXP (XEXP (value
, 0), 0)))
8606 rtx temp
= expand_simple_binop (GET_MODE (value
), code
,
8607 XEXP (XEXP (value
, 0), 0), op2
,
8608 subtarget
, 0, OPTAB_LIB_WIDEN
);
8609 return expand_simple_binop (GET_MODE (value
), code
, temp
,
8610 force_operand (XEXP (XEXP (value
,
8612 target
, 0, OPTAB_LIB_WIDEN
);
8615 op1
= force_operand (XEXP (value
, 0), subtarget
);
8616 op2
= force_operand (op2
, NULL_RTX
);
8620 return expand_mult (GET_MODE (value
), op1
, op2
, target
, 1);
8622 if (!INTEGRAL_MODE_P (GET_MODE (value
)))
8623 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
8624 target
, 1, OPTAB_LIB_WIDEN
);
8626 return expand_divmod (0,
8627 FLOAT_MODE_P (GET_MODE (value
))
8628 ? RDIV_EXPR
: TRUNC_DIV_EXPR
,
8629 GET_MODE (value
), op1
, op2
, target
, 0);
8631 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
8634 return expand_divmod (0, TRUNC_DIV_EXPR
, GET_MODE (value
), op1
, op2
,
8637 return expand_divmod (1, TRUNC_MOD_EXPR
, GET_MODE (value
), op1
, op2
,
8640 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
8641 target
, 0, OPTAB_LIB_WIDEN
);
8643 return expand_simple_binop (GET_MODE (value
), code
, op1
, op2
,
8644 target
, 1, OPTAB_LIB_WIDEN
);
8647 if (UNARY_P (value
))
8650 target
= gen_reg_rtx (GET_MODE (value
));
8651 op1
= force_operand (XEXP (value
, 0), NULL_RTX
);
8658 case FLOAT_TRUNCATE
:
8659 convert_move (target
, op1
, code
== ZERO_EXTEND
);
8664 expand_fix (target
, op1
, code
== UNSIGNED_FIX
);
8668 case UNSIGNED_FLOAT
:
8669 expand_float (target
, op1
, code
== UNSIGNED_FLOAT
);
8673 return expand_simple_unop (GET_MODE (value
), code
, op1
, target
, 0);
8677 #ifdef INSN_SCHEDULING
8678 /* On machines that have insn scheduling, we want all memory reference to be
8679 explicit, so we need to deal with such paradoxical SUBREGs. */
8680 if (paradoxical_subreg_p (value
) && MEM_P (SUBREG_REG (value
)))
8682 = simplify_gen_subreg (GET_MODE (value
),
8683 force_reg (GET_MODE (SUBREG_REG (value
)),
8684 force_operand (SUBREG_REG (value
),
8686 GET_MODE (SUBREG_REG (value
)),
8687 SUBREG_BYTE (value
));
8693 /* Subroutine of expand_expr: return true iff there is no way that
8694 EXP can reference X, which is being modified. TOP_P is nonzero if this
8695 call is going to be used to determine whether we need a temporary
8696 for EXP, as opposed to a recursive call to this function.
8698 It is always safe for this routine to return false since it merely
8699 searches for optimization opportunities. */
8702 safe_from_p (const_rtx x
, tree exp
, int top_p
)
8708 /* If EXP has varying size, we MUST use a target since we currently
8709 have no way of allocating temporaries of variable size
8710 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
8711 So we assume here that something at a higher level has prevented a
8712 clash. This is somewhat bogus, but the best we can do. Only
8713 do this when X is BLKmode and when we are at the top level. */
8714 || (top_p
&& TREE_TYPE (exp
) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp
))
8715 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp
))) != INTEGER_CST
8716 && (TREE_CODE (TREE_TYPE (exp
)) != ARRAY_TYPE
8717 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)) == NULL_TREE
8718 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp
)))
8720 && GET_MODE (x
) == BLKmode
)
8721 /* If X is in the outgoing argument area, it is always safe. */
8723 && (XEXP (x
, 0) == virtual_outgoing_args_rtx
8724 || (GET_CODE (XEXP (x
, 0)) == PLUS
8725 && XEXP (XEXP (x
, 0), 0) == virtual_outgoing_args_rtx
))))
8728 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
8729 find the underlying pseudo. */
8730 if (GET_CODE (x
) == SUBREG
)
8733 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
8737 /* Now look at our tree code and possibly recurse. */
8738 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
8740 case tcc_declaration
:
8741 exp_rtl
= DECL_RTL_IF_SET (exp
);
8747 case tcc_exceptional
:
8748 if (TREE_CODE (exp
) == TREE_LIST
)
8752 if (TREE_VALUE (exp
) && !safe_from_p (x
, TREE_VALUE (exp
), 0))
8754 exp
= TREE_CHAIN (exp
);
8757 if (TREE_CODE (exp
) != TREE_LIST
)
8758 return safe_from_p (x
, exp
, 0);
8761 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
8763 constructor_elt
*ce
;
8764 unsigned HOST_WIDE_INT idx
;
8766 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp
), idx
, ce
)
8767 if ((ce
->index
!= NULL_TREE
&& !safe_from_p (x
, ce
->index
, 0))
8768 || !safe_from_p (x
, ce
->value
, 0))
8772 else if (TREE_CODE (exp
) == ERROR_MARK
)
8773 return true; /* An already-visited SAVE_EXPR? */
8778 /* The only case we look at here is the DECL_INITIAL inside a
8780 return (TREE_CODE (exp
) != DECL_EXPR
8781 || TREE_CODE (DECL_EXPR_DECL (exp
)) != VAR_DECL
8782 || !DECL_INITIAL (DECL_EXPR_DECL (exp
))
8783 || safe_from_p (x
, DECL_INITIAL (DECL_EXPR_DECL (exp
)), 0));
8786 case tcc_comparison
:
8787 if (!safe_from_p (x
, TREE_OPERAND (exp
, 1), 0))
8792 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
8794 case tcc_expression
:
8797 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
8798 the expression. If it is set, we conflict iff we are that rtx or
8799 both are in memory. Otherwise, we check all operands of the
8800 expression recursively. */
8802 switch (TREE_CODE (exp
))
8805 /* If the operand is static or we are static, we can't conflict.
8806 Likewise if we don't conflict with the operand at all. */
8807 if (staticp (TREE_OPERAND (exp
, 0))
8808 || TREE_STATIC (exp
)
8809 || safe_from_p (x
, TREE_OPERAND (exp
, 0), 0))
8812 /* Otherwise, the only way this can conflict is if we are taking
8813 the address of a DECL a that address if part of X, which is
8815 exp
= TREE_OPERAND (exp
, 0);
8818 if (!DECL_RTL_SET_P (exp
)
8819 || !MEM_P (DECL_RTL (exp
)))
8822 exp_rtl
= XEXP (DECL_RTL (exp
), 0);
8828 && alias_sets_conflict_p (MEM_ALIAS_SET (x
),
8829 get_alias_set (exp
)))
8834 /* Assume that the call will clobber all hard registers and
8836 if ((REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
8841 case WITH_CLEANUP_EXPR
:
8842 case CLEANUP_POINT_EXPR
:
8843 /* Lowered by gimplify.cc. */
8847 return safe_from_p (x
, TREE_OPERAND (exp
, 0), 0);
8853 /* If we have an rtx, we do not need to scan our operands. */
8857 nops
= TREE_OPERAND_LENGTH (exp
);
8858 for (i
= 0; i
< nops
; i
++)
8859 if (TREE_OPERAND (exp
, i
) != 0
8860 && ! safe_from_p (x
, TREE_OPERAND (exp
, i
), 0))
8866 /* Should never get a type here. */
8870 /* If we have an rtl, find any enclosed object. Then see if we conflict
8874 if (GET_CODE (exp_rtl
) == SUBREG
)
8876 exp_rtl
= SUBREG_REG (exp_rtl
);
8878 && REGNO (exp_rtl
) < FIRST_PSEUDO_REGISTER
)
8882 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
8883 are memory and they conflict. */
8884 return ! (rtx_equal_p (x
, exp_rtl
)
8885 || (MEM_P (x
) && MEM_P (exp_rtl
)
8886 && true_dependence (exp_rtl
, VOIDmode
, x
)));
8889 /* If we reach here, it is safe. */
8894 /* Return the highest power of two that EXP is known to be a multiple of.
8895 This is used in updating alignment of MEMs in array references. */
8897 unsigned HOST_WIDE_INT
8898 highest_pow2_factor (const_tree exp
)
8900 unsigned HOST_WIDE_INT ret
;
8901 int trailing_zeros
= tree_ctz (exp
);
8902 if (trailing_zeros
>= HOST_BITS_PER_WIDE_INT
)
8903 return BIGGEST_ALIGNMENT
;
8904 ret
= HOST_WIDE_INT_1U
<< trailing_zeros
;
8905 if (ret
> BIGGEST_ALIGNMENT
)
8906 return BIGGEST_ALIGNMENT
;
8910 /* Similar, except that the alignment requirements of TARGET are
8911 taken into account. Assume it is at least as aligned as its
8912 type, unless it is a COMPONENT_REF in which case the layout of
8913 the structure gives the alignment. */
8915 static unsigned HOST_WIDE_INT
8916 highest_pow2_factor_for_target (const_tree target
, const_tree exp
)
8918 unsigned HOST_WIDE_INT talign
= target_align (target
) / BITS_PER_UNIT
;
8919 unsigned HOST_WIDE_INT factor
= highest_pow2_factor (exp
);
8921 return MAX (factor
, talign
);
8924 /* Convert the tree comparison code TCODE to the rtl one where the
8925 signedness is UNSIGNEDP. */
8927 static enum rtx_code
8928 convert_tree_comp_to_rtx (enum tree_code tcode
, int unsignedp
)
8940 code
= unsignedp
? LTU
: LT
;
8943 code
= unsignedp
? LEU
: LE
;
8946 code
= unsignedp
? GTU
: GT
;
8949 code
= unsignedp
? GEU
: GE
;
8951 case UNORDERED_EXPR
:
8982 /* Subroutine of expand_expr. Expand the two operands of a binary
8983 expression EXP0 and EXP1 placing the results in OP0 and OP1.
8984 The value may be stored in TARGET if TARGET is nonzero. The
8985 MODIFIER argument is as documented by expand_expr. */
8988 expand_operands (tree exp0
, tree exp1
, rtx target
, rtx
*op0
, rtx
*op1
,
8989 enum expand_modifier modifier
)
8991 if (! safe_from_p (target
, exp1
, 1))
8993 if (operand_equal_p (exp0
, exp1
, 0))
8995 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
8996 *op1
= copy_rtx (*op0
);
9000 *op0
= expand_expr (exp0
, target
, VOIDmode
, modifier
);
9001 *op1
= expand_expr (exp1
, NULL_RTX
, VOIDmode
, modifier
);
9006 /* Return a MEM that contains constant EXP. DEFER is as for
9007 output_constant_def and MODIFIER is as for expand_expr. */
9010 expand_expr_constant (tree exp
, int defer
, enum expand_modifier modifier
)
9014 mem
= output_constant_def (exp
, defer
);
9015 if (modifier
!= EXPAND_INITIALIZER
)
9016 mem
= use_anchored_address (mem
);
9020 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
9021 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
9024 expand_expr_addr_expr_1 (tree exp
, rtx target
, scalar_int_mode tmode
,
9025 enum expand_modifier modifier
, addr_space_t as
)
9027 rtx result
, subtarget
;
9029 poly_int64 bitsize
, bitpos
;
9030 int unsignedp
, reversep
, volatilep
= 0;
9033 /* If we are taking the address of a constant and are at the top level,
9034 we have to use output_constant_def since we can't call force_const_mem
9036 /* ??? This should be considered a front-end bug. We should not be
9037 generating ADDR_EXPR of something that isn't an LVALUE. The only
9038 exception here is STRING_CST. */
9039 if (CONSTANT_CLASS_P (exp
))
9041 result
= XEXP (expand_expr_constant (exp
, 0, modifier
), 0);
9042 if (modifier
< EXPAND_SUM
)
9043 result
= force_operand (result
, target
);
9047 /* Everything must be something allowed by is_gimple_addressable. */
9048 switch (TREE_CODE (exp
))
9051 /* This case will happen via recursion for &a->b. */
9052 return expand_expr (TREE_OPERAND (exp
, 0), target
, tmode
, modifier
);
9056 tree tem
= TREE_OPERAND (exp
, 0);
9057 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
9058 tem
= fold_build_pointer_plus (tem
, TREE_OPERAND (exp
, 1));
9059 return expand_expr (tem
, target
, tmode
, modifier
);
9062 case TARGET_MEM_REF
:
9063 return addr_for_mem_ref (exp
, as
, true);
9066 /* Expand the initializer like constants above. */
9067 result
= XEXP (expand_expr_constant (DECL_INITIAL (exp
),
9069 if (modifier
< EXPAND_SUM
)
9070 result
= force_operand (result
, target
);
9074 /* The real part of the complex number is always first, therefore
9075 the address is the same as the address of the parent object. */
9078 inner
= TREE_OPERAND (exp
, 0);
9082 /* The imaginary part of the complex number is always second.
9083 The expression is therefore always offset by the size of the
9086 bitpos
= GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (exp
)));
9087 inner
= TREE_OPERAND (exp
, 0);
9090 case COMPOUND_LITERAL_EXPR
:
9091 /* Allow COMPOUND_LITERAL_EXPR in initializers or coming from
9092 initializers, if e.g. rtl_for_decl_init is called on DECL_INITIAL
9093 with COMPOUND_LITERAL_EXPRs in it, or ARRAY_REF on a const static
9094 array with address of COMPOUND_LITERAL_EXPR in DECL_INITIAL;
9095 the initializers aren't gimplified. */
9096 if (COMPOUND_LITERAL_EXPR_DECL (exp
)
9097 && is_global_var (COMPOUND_LITERAL_EXPR_DECL (exp
)))
9098 return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp
),
9099 target
, tmode
, modifier
, as
);
9102 /* If the object is a DECL, then expand it for its rtl. Don't bypass
9103 expand_expr, as that can have various side effects; LABEL_DECLs for
9104 example, may not have their DECL_RTL set yet. Expand the rtl of
9105 CONSTRUCTORs too, which should yield a memory reference for the
9106 constructor's contents. Assume language specific tree nodes can
9107 be expanded in some interesting way. */
9108 gcc_assert (TREE_CODE (exp
) < LAST_AND_UNUSED_TREE_CODE
);
9110 || TREE_CODE (exp
) == CONSTRUCTOR
9111 || TREE_CODE (exp
) == COMPOUND_LITERAL_EXPR
)
9113 result
= expand_expr (exp
, target
, tmode
,
9114 modifier
== EXPAND_INITIALIZER
9115 ? EXPAND_INITIALIZER
: EXPAND_CONST_ADDRESS
);
9117 /* If the DECL isn't in memory, then the DECL wasn't properly
9118 marked TREE_ADDRESSABLE, which will be either a front-end
9119 or a tree optimizer bug. */
9121 gcc_assert (MEM_P (result
));
9122 result
= XEXP (result
, 0);
9124 /* ??? Is this needed anymore? */
9126 TREE_USED (exp
) = 1;
9128 if (modifier
!= EXPAND_INITIALIZER
9129 && modifier
!= EXPAND_CONST_ADDRESS
9130 && modifier
!= EXPAND_SUM
)
9131 result
= force_operand (result
, target
);
9135 /* Pass FALSE as the last argument to get_inner_reference although
9136 we are expanding to RTL. The rationale is that we know how to
9137 handle "aligning nodes" here: we can just bypass them because
9138 they won't change the final object whose address will be returned
9139 (they actually exist only for that purpose). */
9140 inner
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
, &mode1
,
9141 &unsignedp
, &reversep
, &volatilep
);
9145 /* We must have made progress. */
9146 gcc_assert (inner
!= exp
);
9148 subtarget
= offset
|| maybe_ne (bitpos
, 0) ? NULL_RTX
: target
;
9149 /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
9150 inner alignment, force the inner to be sufficiently aligned. */
9151 if (CONSTANT_CLASS_P (inner
)
9152 && TYPE_ALIGN (TREE_TYPE (inner
)) < TYPE_ALIGN (TREE_TYPE (exp
)))
9154 inner
= copy_node (inner
);
9155 TREE_TYPE (inner
) = copy_node (TREE_TYPE (inner
));
9156 SET_TYPE_ALIGN (TREE_TYPE (inner
), TYPE_ALIGN (TREE_TYPE (exp
)));
9157 TYPE_USER_ALIGN (TREE_TYPE (inner
)) = 1;
9159 result
= expand_expr_addr_expr_1 (inner
, subtarget
, tmode
, modifier
, as
);
9165 if (modifier
!= EXPAND_NORMAL
)
9166 result
= force_operand (result
, NULL
);
9167 tmp
= expand_expr (offset
, NULL_RTX
, tmode
,
9168 modifier
== EXPAND_INITIALIZER
9169 ? EXPAND_INITIALIZER
: EXPAND_NORMAL
);
9171 /* expand_expr is allowed to return an object in a mode other
9172 than TMODE. If it did, we need to convert. */
9173 if (GET_MODE (tmp
) != VOIDmode
&& tmode
!= GET_MODE (tmp
))
9174 tmp
= convert_modes (tmode
, GET_MODE (tmp
),
9175 tmp
, TYPE_UNSIGNED (TREE_TYPE (offset
)));
9176 result
= convert_memory_address_addr_space (tmode
, result
, as
);
9177 tmp
= convert_memory_address_addr_space (tmode
, tmp
, as
);
9179 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
9180 result
= simplify_gen_binary (PLUS
, tmode
, result
, tmp
);
9183 subtarget
= maybe_ne (bitpos
, 0) ? NULL_RTX
: target
;
9184 result
= expand_simple_binop (tmode
, PLUS
, result
, tmp
, subtarget
,
9185 1, OPTAB_LIB_WIDEN
);
9189 if (maybe_ne (bitpos
, 0))
9191 /* Someone beforehand should have rejected taking the address
9192 of an object that isn't byte-aligned. */
9193 poly_int64 bytepos
= exact_div (bitpos
, BITS_PER_UNIT
);
9194 result
= convert_memory_address_addr_space (tmode
, result
, as
);
9195 result
= plus_constant (tmode
, result
, bytepos
);
9196 if (modifier
< EXPAND_SUM
)
9197 result
= force_operand (result
, target
);
9203 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
9204 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
9207 expand_expr_addr_expr (tree exp
, rtx target
, machine_mode tmode
,
9208 enum expand_modifier modifier
)
9210 addr_space_t as
= ADDR_SPACE_GENERIC
;
9211 scalar_int_mode address_mode
= Pmode
;
9212 scalar_int_mode pointer_mode
= ptr_mode
;
9216 /* Target mode of VOIDmode says "whatever's natural". */
9217 if (tmode
== VOIDmode
)
9218 tmode
= TYPE_MODE (TREE_TYPE (exp
));
9220 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
9222 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
9223 address_mode
= targetm
.addr_space
.address_mode (as
);
9224 pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
9227 /* We can get called with some Weird Things if the user does silliness
9228 like "(short) &a". In that case, convert_memory_address won't do
9229 the right thing, so ignore the given target mode. */
9230 scalar_int_mode new_tmode
= (tmode
== pointer_mode
9234 result
= expand_expr_addr_expr_1 (TREE_OPERAND (exp
, 0), target
,
9235 new_tmode
, modifier
, as
);
9237 /* Despite expand_expr claims concerning ignoring TMODE when not
9238 strictly convenient, stuff breaks if we don't honor it. Note
9239 that combined with the above, we only do this for pointer modes. */
9240 rmode
= GET_MODE (result
);
9241 if (rmode
== VOIDmode
)
9243 if (rmode
!= new_tmode
)
9244 result
= convert_memory_address_addr_space (new_tmode
, result
, as
);
9249 /* Generate code for computing CONSTRUCTOR EXP.
9250 An rtx for the computed value is returned. If AVOID_TEMP_MEM
9251 is TRUE, instead of creating a temporary variable in memory
9252 NULL is returned and the caller needs to handle it differently. */
9255 expand_constructor (tree exp
, rtx target
, enum expand_modifier modifier
,
9256 bool avoid_temp_mem
)
9258 tree type
= TREE_TYPE (exp
);
9259 machine_mode mode
= TYPE_MODE (type
);
9261 /* Try to avoid creating a temporary at all. This is possible
9262 if all of the initializer is zero.
9263 FIXME: try to handle all [0..255] initializers we can handle
9265 if (TREE_STATIC (exp
)
9266 && !TREE_ADDRESSABLE (exp
)
9267 && target
!= 0 && mode
== BLKmode
9268 && all_zeros_p (exp
))
9270 clear_storage (target
, expr_size (exp
), BLOCK_OP_NORMAL
);
9274 /* All elts simple constants => refer to a constant in memory. But
9275 if this is a non-BLKmode mode, let it store a field at a time
9276 since that should make a CONST_INT, CONST_WIDE_INT or
9277 CONST_DOUBLE when we fold. Likewise, if we have a target we can
9278 use, it is best to store directly into the target unless the type
9279 is large enough that memcpy will be used. If we are making an
9280 initializer and all operands are constant, put it in memory as
9283 FIXME: Avoid trying to fill vector constructors piece-meal.
9284 Output them with output_constant_def below unless we're sure
9285 they're zeros. This should go away when vector initializers
9286 are treated like VECTOR_CST instead of arrays. */
9287 if ((TREE_STATIC (exp
)
9288 && ((mode
== BLKmode
9289 && ! (target
!= 0 && safe_from_p (target
, exp
, 1)))
9290 || TREE_ADDRESSABLE (exp
)
9291 || (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
9292 && (! can_move_by_pieces
9293 (tree_to_uhwi (TYPE_SIZE_UNIT (type
)),
9295 && ! mostly_zeros_p (exp
))))
9296 || ((modifier
== EXPAND_INITIALIZER
|| modifier
== EXPAND_CONST_ADDRESS
)
9297 && TREE_CONSTANT (exp
)))
9304 constructor
= expand_expr_constant (exp
, 1, modifier
);
9306 if (modifier
!= EXPAND_CONST_ADDRESS
9307 && modifier
!= EXPAND_INITIALIZER
9308 && modifier
!= EXPAND_SUM
)
9309 constructor
= validize_mem (constructor
);
9314 /* If the CTOR is available in static storage and not mostly
9315 zeros and we can move it by pieces prefer to do so since
9316 that's usually more efficient than performing a series of
9317 stores from immediates. */
9319 && TREE_STATIC (exp
)
9320 && TREE_CONSTANT (exp
)
9321 && tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
9322 && can_move_by_pieces (tree_to_uhwi (TYPE_SIZE_UNIT (type
)),
9324 && ! mostly_zeros_p (exp
))
9327 /* Handle calls that pass values in multiple non-contiguous
9328 locations. The Irix 6 ABI has examples of this. */
9329 if (target
== 0 || ! safe_from_p (target
, exp
, 1)
9330 || GET_CODE (target
) == PARALLEL
|| modifier
== EXPAND_STACK_PARM
9331 /* Also make a temporary if the store is to volatile memory, to
9332 avoid individual accesses to aggregate members. */
9333 || (GET_CODE (target
) == MEM
9334 && MEM_VOLATILE_P (target
)
9335 && !TREE_ADDRESSABLE (TREE_TYPE (exp
))))
9340 target
= assign_temp (type
, TREE_ADDRESSABLE (exp
), 1);
9343 store_constructor (exp
, target
, 0, int_expr_size (exp
), false);
9348 /* expand_expr: generate code for computing expression EXP.
9349 An rtx for the computed value is returned. The value is never null.
9350 In the case of a void EXP, const0_rtx is returned.
9352 The value may be stored in TARGET if TARGET is nonzero.
9353 TARGET is just a suggestion; callers must assume that
9354 the rtx returned may not be the same as TARGET.
9356 If TARGET is CONST0_RTX, it means that the value will be ignored.
9358 If TMODE is not VOIDmode, it suggests generating the
9359 result in mode TMODE. But this is done only when convenient.
9360 Otherwise, TMODE is ignored and the value generated in its natural mode.
9361 TMODE is just a suggestion; callers must assume that
9362 the rtx returned may not have mode TMODE.
9364 Note that TARGET may have neither TMODE nor MODE. In that case, it
9365 probably will not be used.
9367 If MODIFIER is EXPAND_SUM then when EXP is an addition
9368 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
9369 or a nest of (PLUS ...) and (MINUS ...) where the terms are
9370 products as above, or REG or MEM, or constant.
9371 Ordinarily in such cases we would output mul or add instructions
9372 and then return a pseudo reg containing the sum.
9374 EXPAND_INITIALIZER is much like EXPAND_SUM except that
9375 it also marks a label as absolutely required (it can't be dead).
9376 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
9377 This is used for outputting expressions used in initializers.
9379 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
9380 with a constant address even if that address is not normally legitimate.
9381 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
9383 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
9384 a call parameter. Such targets require special care as we haven't yet
9385 marked TARGET so that it's safe from being trashed by libcalls. We
9386 don't want to use TARGET for anything but the final result;
9387 Intermediate values must go elsewhere. Additionally, calls to
9388 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
9390 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
9391 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
9392 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
9393 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
9395 If the result can be stored at TARGET, and ALT_RTL is non-NULL,
9396 then *ALT_RTL is set to TARGET (before legitimziation).
9398 If INNER_REFERENCE_P is true, we are expanding an inner reference.
9399 In this case, we don't adjust a returned MEM rtx that wouldn't be
9400 sufficiently aligned for its mode; instead, it's up to the caller
9401 to deal with it afterwards. This is used to make sure that unaligned
9402 base objects for which out-of-bounds accesses are supported, for
9403 example record types with trailing arrays, aren't realigned behind
9404 the back of the caller.
9405 The normal operating mode is to pass FALSE for this parameter. */
9408 expand_expr_real (tree exp
, rtx target
, machine_mode tmode
,
9409 enum expand_modifier modifier
, rtx
*alt_rtl
,
9410 bool inner_reference_p
)
9414 /* Handle ERROR_MARK before anybody tries to access its type. */
9415 if (TREE_CODE (exp
) == ERROR_MARK
9416 || (TREE_CODE (TREE_TYPE (exp
)) == ERROR_MARK
))
9418 ret
= CONST0_RTX (tmode
);
9419 return ret
? ret
: const0_rtx
;
9422 ret
= expand_expr_real_1 (exp
, target
, tmode
, modifier
, alt_rtl
,
9427 /* Try to expand the conditional expression which is represented by
9428 TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If it succeeds
9429 return the rtl reg which represents the result. Otherwise return
9433 expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED
,
9434 tree treeop1 ATTRIBUTE_UNUSED
,
9435 tree treeop2 ATTRIBUTE_UNUSED
)
9438 rtx op00
, op01
, op1
, op2
;
9439 enum rtx_code comparison_code
;
9440 machine_mode comparison_mode
;
9443 tree type
= TREE_TYPE (treeop1
);
9444 int unsignedp
= TYPE_UNSIGNED (type
);
9445 machine_mode mode
= TYPE_MODE (type
);
9446 machine_mode orig_mode
= mode
;
9447 static bool expanding_cond_expr_using_cmove
= false;
9449 /* Conditional move expansion can end up TERing two operands which,
9450 when recursively hitting conditional expressions can result in
9451 exponential behavior if the cmove expansion ultimatively fails.
9452 It's hardly profitable to TER a cmove into a cmove so avoid doing
9453 that by failing early if we end up recursing. */
9454 if (expanding_cond_expr_using_cmove
)
9457 /* If we cannot do a conditional move on the mode, try doing it
9458 with the promoted mode. */
9459 if (!can_conditionally_move_p (mode
))
9461 mode
= promote_mode (type
, mode
, &unsignedp
);
9462 if (!can_conditionally_move_p (mode
))
9464 temp
= assign_temp (type
, 0, 0); /* Use promoted mode for temp. */
9467 temp
= assign_temp (type
, 0, 1);
9469 expanding_cond_expr_using_cmove
= true;
9471 expand_operands (treeop1
, treeop2
,
9472 mode
== orig_mode
? temp
: NULL_RTX
, &op1
, &op2
,
9475 if (TREE_CODE (treeop0
) == SSA_NAME
9476 && (srcstmt
= get_def_for_expr_class (treeop0
, tcc_comparison
)))
9478 type
= TREE_TYPE (gimple_assign_rhs1 (srcstmt
));
9479 enum tree_code cmpcode
= gimple_assign_rhs_code (srcstmt
);
9480 op00
= expand_normal (gimple_assign_rhs1 (srcstmt
));
9481 op01
= expand_normal (gimple_assign_rhs2 (srcstmt
));
9482 comparison_mode
= TYPE_MODE (type
);
9483 unsignedp
= TYPE_UNSIGNED (type
);
9484 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
9486 else if (COMPARISON_CLASS_P (treeop0
))
9488 type
= TREE_TYPE (TREE_OPERAND (treeop0
, 0));
9489 enum tree_code cmpcode
= TREE_CODE (treeop0
);
9490 op00
= expand_normal (TREE_OPERAND (treeop0
, 0));
9491 op01
= expand_normal (TREE_OPERAND (treeop0
, 1));
9492 unsignedp
= TYPE_UNSIGNED (type
);
9493 comparison_mode
= TYPE_MODE (type
);
9494 comparison_code
= convert_tree_comp_to_rtx (cmpcode
, unsignedp
);
9498 op00
= expand_normal (treeop0
);
9500 comparison_code
= NE
;
9501 comparison_mode
= GET_MODE (op00
);
9502 if (comparison_mode
== VOIDmode
)
9503 comparison_mode
= TYPE_MODE (TREE_TYPE (treeop0
));
9505 expanding_cond_expr_using_cmove
= false;
9507 if (GET_MODE (op1
) != mode
)
9508 op1
= gen_lowpart (mode
, op1
);
9510 if (GET_MODE (op2
) != mode
)
9511 op2
= gen_lowpart (mode
, op2
);
9513 /* Try to emit the conditional move. */
9514 insn
= emit_conditional_move (temp
,
9515 { comparison_code
, op00
, op01
,
9520 /* If we could do the conditional move, emit the sequence,
9524 rtx_insn
*seq
= get_insns ();
9527 return convert_modes (orig_mode
, mode
, temp
, 0);
9530 /* Otherwise discard the sequence and fall back to code with
9536 /* A helper function for expand_expr_real_2 to be used with a
9537 misaligned mem_ref TEMP. Assume an unsigned type if UNSIGNEDP
9538 is nonzero, with alignment ALIGN in bits.
9539 Store the value at TARGET if possible (if TARGET is nonzero).
9540 Regardless of TARGET, we return the rtx for where the value is placed.
9541 If the result can be stored at TARGET, and ALT_RTL is non-NULL,
9542 then *ALT_RTL is set to TARGET (before legitimziation). */
9545 expand_misaligned_mem_ref (rtx temp
, machine_mode mode
, int unsignedp
,
9546 unsigned int align
, rtx target
, rtx
*alt_rtl
)
9548 enum insn_code icode
;
9550 if ((icode
= optab_handler (movmisalign_optab
, mode
))
9551 != CODE_FOR_nothing
)
9553 class expand_operand ops
[2];
9555 /* We've already validated the memory, and we're creating a
9556 new pseudo destination. The predicates really can't fail,
9557 nor can the generator. */
9558 create_output_operand (&ops
[0], NULL_RTX
, mode
);
9559 create_fixed_operand (&ops
[1], temp
);
9560 expand_insn (icode
, 2, ops
);
9561 temp
= ops
[0].value
;
9563 else if (targetm
.slow_unaligned_access (mode
, align
))
9564 temp
= extract_bit_field (temp
, GET_MODE_BITSIZE (mode
),
9565 0, unsignedp
, target
,
9566 mode
, mode
, false, alt_rtl
);
9570 /* Helper function of expand_expr_2, expand a division or modulo.
9571 op0 and op1 should be already expanded treeop0 and treeop1, using
9575 expand_expr_divmod (tree_code code
, machine_mode mode
, tree treeop0
,
9576 tree treeop1
, rtx op0
, rtx op1
, rtx target
, int unsignedp
)
9578 bool mod_p
= (code
== TRUNC_MOD_EXPR
|| code
== FLOOR_MOD_EXPR
9579 || code
== CEIL_MOD_EXPR
|| code
== ROUND_MOD_EXPR
);
9580 if (SCALAR_INT_MODE_P (mode
)
9582 && get_range_pos_neg (treeop0
) == 1
9583 && get_range_pos_neg (treeop1
) == 1)
9585 /* If both arguments are known to be positive when interpreted
9586 as signed, we can expand it as both signed and unsigned
9587 division or modulo. Choose the cheaper sequence in that case. */
9588 bool speed_p
= optimize_insn_for_speed_p ();
9589 do_pending_stack_adjust ();
9591 rtx uns_ret
= expand_divmod (mod_p
, code
, mode
, op0
, op1
, target
, 1);
9592 rtx_insn
*uns_insns
= get_insns ();
9595 rtx sgn_ret
= expand_divmod (mod_p
, code
, mode
, op0
, op1
, target
, 0);
9596 rtx_insn
*sgn_insns
= get_insns ();
9598 unsigned uns_cost
= seq_cost (uns_insns
, speed_p
);
9599 unsigned sgn_cost
= seq_cost (sgn_insns
, speed_p
);
9601 /* If costs are the same then use as tie breaker the other other
9603 if (uns_cost
== sgn_cost
)
9605 uns_cost
= seq_cost (uns_insns
, !speed_p
);
9606 sgn_cost
= seq_cost (sgn_insns
, !speed_p
);
9609 if (uns_cost
< sgn_cost
|| (uns_cost
== sgn_cost
&& unsignedp
))
9611 emit_insn (uns_insns
);
9614 emit_insn (sgn_insns
);
9617 return expand_divmod (mod_p
, code
, mode
, op0
, op1
, target
, unsignedp
);
9621 expand_expr_real_2 (sepops ops
, rtx target
, machine_mode tmode
,
9622 enum expand_modifier modifier
)
9624 rtx op0
, op1
, op2
, temp
;
9625 rtx_code_label
*lab
;
9629 scalar_int_mode int_mode
;
9630 enum tree_code code
= ops
->code
;
9632 rtx subtarget
, original_target
;
9634 bool reduce_bit_field
;
9635 location_t loc
= ops
->location
;
9636 tree treeop0
, treeop1
, treeop2
;
9637 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
9638 ? reduce_to_bit_field_precision ((expr), \
9644 mode
= TYPE_MODE (type
);
9645 unsignedp
= TYPE_UNSIGNED (type
);
9651 /* We should be called only on simple (binary or unary) expressions,
9652 exactly those that are valid in gimple expressions that aren't
9653 GIMPLE_SINGLE_RHS (or invalid). */
9654 gcc_assert (get_gimple_rhs_class (code
) == GIMPLE_UNARY_RHS
9655 || get_gimple_rhs_class (code
) == GIMPLE_BINARY_RHS
9656 || get_gimple_rhs_class (code
) == GIMPLE_TERNARY_RHS
);
9658 ignore
= (target
== const0_rtx
9659 || ((CONVERT_EXPR_CODE_P (code
)
9660 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
9661 && TREE_CODE (type
) == VOID_TYPE
));
9663 /* We should be called only if we need the result. */
9664 gcc_assert (!ignore
);
9666 /* An operation in what may be a bit-field type needs the
9667 result to be reduced to the precision of the bit-field type,
9668 which is narrower than that of the type's mode. */
9669 reduce_bit_field
= (INTEGRAL_TYPE_P (type
)
9670 && !type_has_mode_precision_p (type
));
9672 if (reduce_bit_field
9673 && (modifier
== EXPAND_STACK_PARM
9674 || (target
&& GET_MODE (target
) != mode
)))
9677 /* Use subtarget as the target for operand 0 of a binary operation. */
9678 subtarget
= get_subtarget (target
);
9679 original_target
= target
;
9683 case NON_LVALUE_EXPR
:
9686 if (treeop0
== error_mark_node
)
9689 if (TREE_CODE (type
) == UNION_TYPE
)
9691 tree valtype
= TREE_TYPE (treeop0
);
9693 /* If both input and output are BLKmode, this conversion isn't doing
9694 anything except possibly changing memory attribute. */
9695 if (mode
== BLKmode
&& TYPE_MODE (valtype
) == BLKmode
)
9697 rtx result
= expand_expr (treeop0
, target
, tmode
,
9700 result
= copy_rtx (result
);
9701 set_mem_attributes (result
, type
, 0);
9707 if (TYPE_MODE (type
) != BLKmode
)
9708 target
= gen_reg_rtx (TYPE_MODE (type
));
9710 target
= assign_temp (type
, 1, 1);
9714 /* Store data into beginning of memory target. */
9715 store_expr (treeop0
,
9716 adjust_address (target
, TYPE_MODE (valtype
), 0),
9717 modifier
== EXPAND_STACK_PARM
,
9718 false, TYPE_REVERSE_STORAGE_ORDER (type
));
9722 gcc_assert (REG_P (target
)
9723 && !TYPE_REVERSE_STORAGE_ORDER (type
));
9725 /* Store this field into a union of the proper type. */
9726 poly_uint64 op0_size
9727 = tree_to_poly_uint64 (TYPE_SIZE (TREE_TYPE (treeop0
)));
9728 poly_uint64 union_size
= GET_MODE_BITSIZE (mode
);
9729 store_field (target
,
9730 /* The conversion must be constructed so that
9731 we know at compile time how many bits
9733 ordered_min (op0_size
, union_size
),
9734 0, 0, 0, TYPE_MODE (valtype
), treeop0
, 0,
9738 /* Return the entire union. */
9742 if (mode
== TYPE_MODE (TREE_TYPE (treeop0
)))
9744 op0
= expand_expr (treeop0
, target
, VOIDmode
,
9747 return REDUCE_BIT_FIELD (op0
);
9750 op0
= expand_expr (treeop0
, NULL_RTX
, mode
,
9751 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
);
9752 if (GET_MODE (op0
) == mode
)
9755 /* If OP0 is a constant, just convert it into the proper mode. */
9756 else if (CONSTANT_P (op0
))
9758 tree inner_type
= TREE_TYPE (treeop0
);
9759 machine_mode inner_mode
= GET_MODE (op0
);
9761 if (inner_mode
== VOIDmode
)
9762 inner_mode
= TYPE_MODE (inner_type
);
9764 if (modifier
== EXPAND_INITIALIZER
)
9765 op0
= lowpart_subreg (mode
, op0
, inner_mode
);
9767 op0
= convert_modes (mode
, inner_mode
, op0
,
9768 TYPE_UNSIGNED (inner_type
));
9771 else if (modifier
== EXPAND_INITIALIZER
)
9772 op0
= gen_rtx_fmt_e (TYPE_UNSIGNED (TREE_TYPE (treeop0
))
9773 ? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
);
9775 else if (target
== 0)
9776 op0
= convert_to_mode (mode
, op0
,
9777 TYPE_UNSIGNED (TREE_TYPE
9781 convert_move (target
, op0
,
9782 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
9786 return REDUCE_BIT_FIELD (op0
);
9788 case ADDR_SPACE_CONVERT_EXPR
:
9790 tree treeop0_type
= TREE_TYPE (treeop0
);
9792 gcc_assert (POINTER_TYPE_P (type
));
9793 gcc_assert (POINTER_TYPE_P (treeop0_type
));
9795 addr_space_t as_to
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
9796 addr_space_t as_from
= TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type
));
9798 /* Conversions between pointers to the same address space should
9799 have been implemented via CONVERT_EXPR / NOP_EXPR. */
9800 gcc_assert (as_to
!= as_from
);
9802 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
9804 /* Ask target code to handle conversion between pointers
9805 to overlapping address spaces. */
9806 if (targetm
.addr_space
.subset_p (as_to
, as_from
)
9807 || targetm
.addr_space
.subset_p (as_from
, as_to
))
9809 op0
= targetm
.addr_space
.convert (op0
, treeop0_type
, type
);
9813 /* For disjoint address spaces, converting anything but a null
9814 pointer invokes undefined behavior. We truncate or extend the
9815 value as if we'd converted via integers, which handles 0 as
9816 required, and all others as the programmer likely expects. */
9817 #ifndef POINTERS_EXTEND_UNSIGNED
9818 const int POINTERS_EXTEND_UNSIGNED
= 1;
9820 op0
= convert_modes (mode
, TYPE_MODE (treeop0_type
),
9821 op0
, POINTERS_EXTEND_UNSIGNED
);
9827 case POINTER_PLUS_EXPR
:
9828 /* Even though the sizetype mode and the pointer's mode can be different
9829 expand is able to handle this correctly and get the correct result out
9830 of the PLUS_EXPR code. */
9831 /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
9832 if sizetype precision is smaller than pointer precision. */
9833 if (TYPE_PRECISION (sizetype
) < TYPE_PRECISION (type
))
9834 treeop1
= fold_convert_loc (loc
, type
,
9835 fold_convert_loc (loc
, ssizetype
,
9837 /* If sizetype precision is larger than pointer precision, truncate the
9838 offset to have matching modes. */
9839 else if (TYPE_PRECISION (sizetype
) > TYPE_PRECISION (type
))
9840 treeop1
= fold_convert_loc (loc
, type
, treeop1
);
9844 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
9845 something else, make sure we add the register to the constant and
9846 then to the other thing. This case can occur during strength
9847 reduction and doing it this way will produce better code if the
9848 frame pointer or argument pointer is eliminated.
9850 fold-const.cc will ensure that the constant is always in the inner
9851 PLUS_EXPR, so the only case we need to do anything about is if
9852 sp, ap, or fp is our second argument, in which case we must swap
9853 the innermost first argument and our second argument. */
9855 if (TREE_CODE (treeop0
) == PLUS_EXPR
9856 && TREE_CODE (TREE_OPERAND (treeop0
, 1)) == INTEGER_CST
9858 && (DECL_RTL (treeop1
) == frame_pointer_rtx
9859 || DECL_RTL (treeop1
) == stack_pointer_rtx
9860 || DECL_RTL (treeop1
) == arg_pointer_rtx
))
9865 /* If the result is to be ptr_mode and we are adding an integer to
9866 something, we might be forming a constant. So try to use
9867 plus_constant. If it produces a sum and we can't accept it,
9868 use force_operand. This allows P = &ARR[const] to generate
9869 efficient code on machines where a SYMBOL_REF is not a valid
9872 If this is an EXPAND_SUM call, always return the sum. */
9873 if (modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
9874 || (mode
== ptr_mode
&& (unsignedp
|| ! flag_trapv
)))
9876 if (modifier
== EXPAND_STACK_PARM
)
9878 if (TREE_CODE (treeop0
) == INTEGER_CST
9879 && HWI_COMPUTABLE_MODE_P (mode
)
9880 && TREE_CONSTANT (treeop1
))
9884 machine_mode wmode
= TYPE_MODE (TREE_TYPE (treeop1
));
9886 op1
= expand_expr (treeop1
, subtarget
, VOIDmode
,
9888 /* Use wi::shwi to ensure that the constant is
9889 truncated according to the mode of OP1, then sign extended
9890 to a HOST_WIDE_INT. Using the constant directly can result
9891 in non-canonical RTL in a 64x32 cross compile. */
9892 wc
= TREE_INT_CST_LOW (treeop0
);
9894 immed_wide_int_const (wi::shwi (wc
, wmode
), wmode
);
9895 op1
= plus_constant (mode
, op1
, INTVAL (constant_part
));
9896 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
9897 op1
= force_operand (op1
, target
);
9898 return REDUCE_BIT_FIELD (op1
);
9901 else if (TREE_CODE (treeop1
) == INTEGER_CST
9902 && HWI_COMPUTABLE_MODE_P (mode
)
9903 && TREE_CONSTANT (treeop0
))
9907 machine_mode wmode
= TYPE_MODE (TREE_TYPE (treeop0
));
9909 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
9910 (modifier
== EXPAND_INITIALIZER
9911 ? EXPAND_INITIALIZER
: EXPAND_SUM
));
9912 if (! CONSTANT_P (op0
))
9914 op1
= expand_expr (treeop1
, NULL_RTX
,
9915 VOIDmode
, modifier
);
9916 /* Return a PLUS if modifier says it's OK. */
9917 if (modifier
== EXPAND_SUM
9918 || modifier
== EXPAND_INITIALIZER
)
9919 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
9922 /* Use wi::shwi to ensure that the constant is
9923 truncated according to the mode of OP1, then sign extended
9924 to a HOST_WIDE_INT. Using the constant directly can result
9925 in non-canonical RTL in a 64x32 cross compile. */
9926 wc
= TREE_INT_CST_LOW (treeop1
);
9928 = immed_wide_int_const (wi::shwi (wc
, wmode
), wmode
);
9929 op0
= plus_constant (mode
, op0
, INTVAL (constant_part
));
9930 if (modifier
!= EXPAND_SUM
&& modifier
!= EXPAND_INITIALIZER
)
9931 op0
= force_operand (op0
, target
);
9932 return REDUCE_BIT_FIELD (op0
);
9936 /* Use TER to expand pointer addition of a negated value
9937 as pointer subtraction. */
9938 if ((POINTER_TYPE_P (TREE_TYPE (treeop0
))
9939 || (TREE_CODE (TREE_TYPE (treeop0
)) == VECTOR_TYPE
9940 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0
)))))
9941 && TREE_CODE (treeop1
) == SSA_NAME
9942 && TYPE_MODE (TREE_TYPE (treeop0
))
9943 == TYPE_MODE (TREE_TYPE (treeop1
)))
9945 gimple
*def
= get_def_for_expr (treeop1
, NEGATE_EXPR
);
9948 treeop1
= gimple_assign_rhs1 (def
);
9954 /* No sense saving up arithmetic to be done
9955 if it's all in the wrong mode to form part of an address.
9956 And force_operand won't know whether to sign-extend or
9958 if (modifier
!= EXPAND_INITIALIZER
9959 && (modifier
!= EXPAND_SUM
|| mode
!= ptr_mode
))
9961 expand_operands (treeop0
, treeop1
,
9962 subtarget
, &op0
, &op1
, modifier
);
9963 if (op0
== const0_rtx
)
9965 if (op1
== const0_rtx
)
9970 expand_operands (treeop0
, treeop1
,
9971 subtarget
, &op0
, &op1
, modifier
);
9972 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
9975 case POINTER_DIFF_EXPR
:
9977 /* For initializers, we are allowed to return a MINUS of two
9978 symbolic constants. Here we handle all cases when both operands
9980 /* Handle difference of two symbolic constants,
9981 for the sake of an initializer. */
9982 if ((modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
9983 && really_constant_p (treeop0
)
9984 && really_constant_p (treeop1
))
9986 expand_operands (treeop0
, treeop1
,
9987 NULL_RTX
, &op0
, &op1
, modifier
);
9988 return simplify_gen_binary (MINUS
, mode
, op0
, op1
);
9991 /* No sense saving up arithmetic to be done
9992 if it's all in the wrong mode to form part of an address.
9993 And force_operand won't know whether to sign-extend or
9995 if (modifier
!= EXPAND_INITIALIZER
9996 && (modifier
!= EXPAND_SUM
|| mode
!= ptr_mode
))
9999 expand_operands (treeop0
, treeop1
,
10000 subtarget
, &op0
, &op1
, modifier
);
10002 /* Convert A - const to A + (-const). */
10003 if (CONST_INT_P (op1
))
10005 op1
= negate_rtx (mode
, op1
);
10006 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS
, mode
, op0
, op1
));
10011 case WIDEN_MULT_PLUS_EXPR
:
10012 case WIDEN_MULT_MINUS_EXPR
:
10013 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
10014 op2
= expand_normal (treeop2
);
10015 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
10016 target
, unsignedp
);
10019 case WIDEN_MULT_EXPR
:
10020 /* If first operand is constant, swap them.
10021 Thus the following special case checks need only
10022 check the second operand. */
10023 if (TREE_CODE (treeop0
) == INTEGER_CST
)
10024 std::swap (treeop0
, treeop1
);
10026 /* First, check if we have a multiplication of one signed and one
10027 unsigned operand. */
10028 if (TREE_CODE (treeop1
) != INTEGER_CST
10029 && (TYPE_UNSIGNED (TREE_TYPE (treeop0
))
10030 != TYPE_UNSIGNED (TREE_TYPE (treeop1
))))
10032 machine_mode innermode
= TYPE_MODE (TREE_TYPE (treeop0
));
10033 this_optab
= usmul_widen_optab
;
10034 if (find_widening_optab_handler (this_optab
, mode
, innermode
)
10035 != CODE_FOR_nothing
)
10037 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
10038 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
10041 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op1
, &op0
,
10043 /* op0 and op1 might still be constant, despite the above
10044 != INTEGER_CST check. Handle it. */
10045 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
10047 op0
= convert_modes (mode
, innermode
, op0
, true);
10048 op1
= convert_modes (mode
, innermode
, op1
, false);
10049 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
10050 target
, unsignedp
));
10055 /* Check for a multiplication with matching signedness. */
10056 else if ((TREE_CODE (treeop1
) == INTEGER_CST
10057 && int_fits_type_p (treeop1
, TREE_TYPE (treeop0
)))
10058 || (TYPE_UNSIGNED (TREE_TYPE (treeop1
))
10059 == TYPE_UNSIGNED (TREE_TYPE (treeop0
))))
10061 tree op0type
= TREE_TYPE (treeop0
);
10062 machine_mode innermode
= TYPE_MODE (op0type
);
10063 bool zextend_p
= TYPE_UNSIGNED (op0type
);
10064 optab other_optab
= zextend_p
? smul_widen_optab
: umul_widen_optab
;
10065 this_optab
= zextend_p
? umul_widen_optab
: smul_widen_optab
;
10067 if (TREE_CODE (treeop0
) != INTEGER_CST
)
10069 if (find_widening_optab_handler (this_optab
, mode
, innermode
)
10070 != CODE_FOR_nothing
)
10072 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
,
10074 /* op0 and op1 might still be constant, despite the above
10075 != INTEGER_CST check. Handle it. */
10076 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
10079 op0
= convert_modes (mode
, innermode
, op0
, zextend_p
);
10081 = convert_modes (mode
, innermode
, op1
,
10082 TYPE_UNSIGNED (TREE_TYPE (treeop1
)));
10083 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
,
10087 temp
= expand_widening_mult (mode
, op0
, op1
, target
,
10088 unsignedp
, this_optab
);
10089 return REDUCE_BIT_FIELD (temp
);
10091 if (find_widening_optab_handler (other_optab
, mode
, innermode
)
10092 != CODE_FOR_nothing
10093 && innermode
== word_mode
)
10096 op0
= expand_normal (treeop0
);
10097 op1
= expand_normal (treeop1
);
10098 /* op0 and op1 might be constants, despite the above
10099 != INTEGER_CST check. Handle it. */
10100 if (GET_MODE (op0
) == VOIDmode
&& GET_MODE (op1
) == VOIDmode
)
10101 goto widen_mult_const
;
10102 temp
= expand_binop (mode
, other_optab
, op0
, op1
, target
,
10103 unsignedp
, OPTAB_LIB_WIDEN
);
10104 hipart
= gen_highpart (word_mode
, temp
);
10105 htem
= expand_mult_highpart_adjust (word_mode
, hipart
,
10108 if (htem
!= hipart
)
10109 emit_move_insn (hipart
, htem
);
10110 return REDUCE_BIT_FIELD (temp
);
10114 treeop0
= fold_build1 (CONVERT_EXPR
, type
, treeop0
);
10115 treeop1
= fold_build1 (CONVERT_EXPR
, type
, treeop1
);
10116 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
10117 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
10120 /* If this is a fixed-point operation, then we cannot use the code
10121 below because "expand_mult" doesn't support sat/no-sat fixed-point
10122 multiplications. */
10123 if (ALL_FIXED_POINT_MODE_P (mode
))
10126 /* If first operand is constant, swap them.
10127 Thus the following special case checks need only
10128 check the second operand. */
10129 if (TREE_CODE (treeop0
) == INTEGER_CST
)
10130 std::swap (treeop0
, treeop1
);
10132 /* Attempt to return something suitable for generating an
10133 indexed address, for machines that support that. */
10135 if (modifier
== EXPAND_SUM
&& mode
== ptr_mode
10136 && tree_fits_shwi_p (treeop1
))
10138 tree exp1
= treeop1
;
10140 op0
= expand_expr (treeop0
, subtarget
, VOIDmode
,
10144 op0
= force_operand (op0
, NULL_RTX
);
10146 op0
= copy_to_mode_reg (mode
, op0
);
10148 op1
= gen_int_mode (tree_to_shwi (exp1
),
10149 TYPE_MODE (TREE_TYPE (exp1
)));
10150 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode
, op0
, op1
));
10153 if (modifier
== EXPAND_STACK_PARM
)
10156 if (SCALAR_INT_MODE_P (mode
) && optimize
>= 2)
10158 gimple
*def_stmt0
= get_def_for_expr (treeop0
, TRUNC_DIV_EXPR
);
10159 gimple
*def_stmt1
= get_def_for_expr (treeop1
, TRUNC_DIV_EXPR
);
10161 && !operand_equal_p (treeop1
, gimple_assign_rhs2 (def_stmt0
), 0))
10164 && !operand_equal_p (treeop0
, gimple_assign_rhs2 (def_stmt1
), 0))
10167 if (def_stmt0
|| def_stmt1
)
10169 /* X / Y * Y can be expanded as X - X % Y too.
10170 Choose the cheaper sequence of those two. */
10172 treeop0
= gimple_assign_rhs1 (def_stmt0
);
10176 treeop0
= gimple_assign_rhs1 (def_stmt1
);
10178 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
,
10180 bool speed_p
= optimize_insn_for_speed_p ();
10181 do_pending_stack_adjust ();
10184 = expand_expr_divmod (TRUNC_DIV_EXPR
, mode
, treeop0
, treeop1
,
10185 op0
, op1
, NULL_RTX
, unsignedp
);
10186 divmul_ret
= expand_mult (mode
, divmul_ret
, op1
, target
,
10188 rtx_insn
*divmul_insns
= get_insns ();
10192 = expand_expr_divmod (TRUNC_MOD_EXPR
, mode
, treeop0
, treeop1
,
10193 op0
, op1
, NULL_RTX
, unsignedp
);
10194 this_optab
= optab_for_tree_code (MINUS_EXPR
, type
,
10196 modsub_ret
= expand_binop (mode
, this_optab
, op0
, modsub_ret
,
10197 target
, unsignedp
, OPTAB_LIB_WIDEN
);
10198 rtx_insn
*modsub_insns
= get_insns ();
10200 unsigned divmul_cost
= seq_cost (divmul_insns
, speed_p
);
10201 unsigned modsub_cost
= seq_cost (modsub_insns
, speed_p
);
10202 /* If costs are the same then use as tie breaker the other other
10204 if (divmul_cost
== modsub_cost
)
10206 divmul_cost
= seq_cost (divmul_insns
, !speed_p
);
10207 modsub_cost
= seq_cost (modsub_insns
, !speed_p
);
10210 if (divmul_cost
<= modsub_cost
)
10212 emit_insn (divmul_insns
);
10213 return REDUCE_BIT_FIELD (divmul_ret
);
10215 emit_insn (modsub_insns
);
10216 return REDUCE_BIT_FIELD (modsub_ret
);
10220 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
10222 /* Expand X*Y as X&-Y when Y must be zero or one. */
10223 if (SCALAR_INT_MODE_P (mode
))
10225 bool gimple_zero_one_valued_p (tree
, tree (*)(tree
));
10226 bool bit0_p
= gimple_zero_one_valued_p (treeop0
, nullptr);
10227 bool bit1_p
= gimple_zero_one_valued_p (treeop1
, nullptr);
10229 /* Expand X*Y as X&Y when both X and Y must be zero or one. */
10230 if (bit0_p
&& bit1_p
)
10231 return REDUCE_BIT_FIELD (expand_and (mode
, op0
, op1
, target
));
10233 if (bit0_p
|| bit1_p
)
10235 bool speed
= optimize_insn_for_speed_p ();
10236 int cost
= add_cost (speed
, mode
) + neg_cost (speed
, mode
);
10237 struct algorithm algorithm
;
10238 enum mult_variant variant
;
10239 if (CONST_INT_P (op1
)
10240 ? !choose_mult_variant (mode
, INTVAL (op1
),
10241 &algorithm
, &variant
, cost
)
10242 : cost
< mul_cost (speed
, mode
))
10244 target
= bit0_p
? expand_and (mode
, negate_rtx (mode
, op0
),
10246 : expand_and (mode
, op0
,
10247 negate_rtx (mode
, op1
),
10249 return REDUCE_BIT_FIELD (target
);
10254 return REDUCE_BIT_FIELD (expand_mult (mode
, op0
, op1
, target
, unsignedp
));
10256 case TRUNC_MOD_EXPR
:
10257 case FLOOR_MOD_EXPR
:
10258 case CEIL_MOD_EXPR
:
10259 case ROUND_MOD_EXPR
:
10261 case TRUNC_DIV_EXPR
:
10262 case FLOOR_DIV_EXPR
:
10263 case CEIL_DIV_EXPR
:
10264 case ROUND_DIV_EXPR
:
10265 case EXACT_DIV_EXPR
:
10266 /* If this is a fixed-point operation, then we cannot use the code
10267 below because "expand_divmod" doesn't support sat/no-sat fixed-point
10269 if (ALL_FIXED_POINT_MODE_P (mode
))
10272 if (modifier
== EXPAND_STACK_PARM
)
10274 /* Possible optimization: compute the dividend with EXPAND_SUM
10275 then if the divisor is constant can optimize the case
10276 where some terms of the dividend have coeffs divisible by it. */
10277 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
10278 return expand_expr_divmod (code
, mode
, treeop0
, treeop1
, op0
, op1
,
10279 target
, unsignedp
);
10284 case MULT_HIGHPART_EXPR
:
10285 expand_operands (treeop0
, treeop1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
10286 temp
= expand_mult_highpart (mode
, op0
, op1
, target
, unsignedp
);
10290 case FIXED_CONVERT_EXPR
:
10291 op0
= expand_normal (treeop0
);
10292 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
10293 target
= gen_reg_rtx (mode
);
10295 if ((TREE_CODE (TREE_TYPE (treeop0
)) == INTEGER_TYPE
10296 && TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
10297 || (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
)))
10298 expand_fixed_convert (target
, op0
, 1, TYPE_SATURATING (type
));
10300 expand_fixed_convert (target
, op0
, 0, TYPE_SATURATING (type
));
10303 case FIX_TRUNC_EXPR
:
10304 op0
= expand_normal (treeop0
);
10305 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
10306 target
= gen_reg_rtx (mode
);
10307 expand_fix (target
, op0
, unsignedp
);
10311 op0
= expand_normal (treeop0
);
10312 if (target
== 0 || modifier
== EXPAND_STACK_PARM
)
10313 target
= gen_reg_rtx (mode
);
10314 /* expand_float can't figure out what to do if FROM has VOIDmode.
10315 So give it the correct mode. With -O, cse will optimize this. */
10316 if (GET_MODE (op0
) == VOIDmode
)
10317 op0
= copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0
)),
10319 expand_float (target
, op0
,
10320 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
10324 op0
= expand_expr (treeop0
, subtarget
,
10325 VOIDmode
, EXPAND_NORMAL
);
10326 if (modifier
== EXPAND_STACK_PARM
)
10328 temp
= expand_unop (mode
,
10329 optab_for_tree_code (NEGATE_EXPR
, type
,
10333 return REDUCE_BIT_FIELD (temp
);
10337 op0
= expand_expr (treeop0
, subtarget
,
10338 VOIDmode
, EXPAND_NORMAL
);
10339 if (modifier
== EXPAND_STACK_PARM
)
10342 /* ABS_EXPR is not valid for complex arguments. */
10343 gcc_assert (GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
10344 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
);
10346 /* Unsigned abs is simply the operand. Testing here means we don't
10347 risk generating incorrect code below. */
10348 if (TYPE_UNSIGNED (TREE_TYPE (treeop0
)))
10351 return expand_abs (mode
, op0
, target
, unsignedp
,
10352 safe_from_p (target
, treeop0
, 1));
10356 target
= original_target
;
10358 || modifier
== EXPAND_STACK_PARM
10359 || (MEM_P (target
) && MEM_VOLATILE_P (target
))
10360 || GET_MODE (target
) != mode
10362 && REGNO (target
) < FIRST_PSEUDO_REGISTER
))
10363 target
= gen_reg_rtx (mode
);
10364 expand_operands (treeop0
, treeop1
,
10365 target
, &op0
, &op1
, EXPAND_NORMAL
);
10367 /* First try to do it with a special MIN or MAX instruction.
10368 If that does not win, use a conditional jump to select the proper
10370 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
10371 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
, unsignedp
,
10376 if (VECTOR_TYPE_P (type
))
10377 gcc_unreachable ();
10379 /* At this point, a MEM target is no longer useful; we will get better
10380 code without it. */
10382 if (! REG_P (target
))
10383 target
= gen_reg_rtx (mode
);
10385 /* If op1 was placed in target, swap op0 and op1. */
10386 if (target
!= op0
&& target
== op1
)
10387 std::swap (op0
, op1
);
10389 /* We generate better code and avoid problems with op1 mentioning
10390 target by forcing op1 into a pseudo if it isn't a constant. */
10391 if (! CONSTANT_P (op1
))
10392 op1
= force_reg (mode
, op1
);
10395 enum rtx_code comparison_code
;
10398 if (code
== MAX_EXPR
)
10399 comparison_code
= unsignedp
? GEU
: GE
;
10401 comparison_code
= unsignedp
? LEU
: LE
;
10403 /* Canonicalize to comparisons against 0. */
10404 if (op1
== const1_rtx
)
10406 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
10407 or (a != 0 ? a : 1) for unsigned.
10408 For MIN we are safe converting (a <= 1 ? a : 1)
10409 into (a <= 0 ? a : 1) */
10410 cmpop1
= const0_rtx
;
10411 if (code
== MAX_EXPR
)
10412 comparison_code
= unsignedp
? NE
: GT
;
10414 if (op1
== constm1_rtx
&& !unsignedp
)
10416 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
10417 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
10418 cmpop1
= const0_rtx
;
10419 if (code
== MIN_EXPR
)
10420 comparison_code
= LT
;
10423 /* Use a conditional move if possible. */
10424 if (can_conditionally_move_p (mode
))
10430 /* Try to emit the conditional move. */
10431 insn
= emit_conditional_move (target
,
10433 op0
, cmpop1
, mode
},
10437 /* If we could do the conditional move, emit the sequence,
10441 rtx_insn
*seq
= get_insns ();
10447 /* Otherwise discard the sequence and fall back to code with
10453 emit_move_insn (target
, op0
);
10455 lab
= gen_label_rtx ();
10456 do_compare_rtx_and_jump (target
, cmpop1
, comparison_code
,
10457 unsignedp
, mode
, NULL_RTX
, NULL
, lab
,
10458 profile_probability::uninitialized ());
10460 emit_move_insn (target
, op1
);
10465 op0
= expand_expr (treeop0
, subtarget
,
10466 VOIDmode
, EXPAND_NORMAL
);
10467 if (modifier
== EXPAND_STACK_PARM
)
10469 /* In case we have to reduce the result to bitfield precision
10470 for unsigned bitfield expand this as XOR with a proper constant
10472 if (reduce_bit_field
&& TYPE_UNSIGNED (type
))
10474 int_mode
= SCALAR_INT_TYPE_MODE (type
);
10475 wide_int mask
= wi::mask (TYPE_PRECISION (type
),
10476 false, GET_MODE_PRECISION (int_mode
));
10478 temp
= expand_binop (int_mode
, xor_optab
, op0
,
10479 immed_wide_int_const (mask
, int_mode
),
10480 target
, 1, OPTAB_LIB_WIDEN
);
10483 temp
= expand_unop (mode
, one_cmpl_optab
, op0
, target
, 1);
10487 /* ??? Can optimize bitwise operations with one arg constant.
10488 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
10489 and (a bitwise1 b) bitwise2 b (etc)
10490 but that is probably not worth while. */
10499 gcc_assert (VECTOR_MODE_P (TYPE_MODE (type
))
10500 || type_has_mode_precision_p (type
));
10506 /* If this is a fixed-point operation, then we cannot use the code
10507 below because "expand_shift" doesn't support sat/no-sat fixed-point
10509 if (ALL_FIXED_POINT_MODE_P (mode
))
10512 if (! safe_from_p (subtarget
, treeop1
, 1))
10514 if (modifier
== EXPAND_STACK_PARM
)
10516 op0
= expand_expr (treeop0
, subtarget
,
10517 VOIDmode
, EXPAND_NORMAL
);
10519 /* Left shift optimization when shifting across word_size boundary.
10521 If mode == GET_MODE_WIDER_MODE (word_mode), then normally
10522 there isn't native instruction to support this wide mode
10523 left shift. Given below scenario:
10525 Type A = (Type) B << C
10528 | dest_high | dest_low |
10532 If the shift amount C caused we shift B to across the word
10533 size boundary, i.e part of B shifted into high half of
10534 destination register, and part of B remains in the low
10535 half, then GCC will use the following left shift expand
10538 1. Initialize dest_low to B.
10539 2. Initialize every bit of dest_high to the sign bit of B.
10540 3. Logic left shift dest_low by C bit to finalize dest_low.
10541 The value of dest_low before this shift is kept in a temp D.
10542 4. Logic left shift dest_high by C.
10543 5. Logic right shift D by (word_size - C).
10544 6. Or the result of 4 and 5 to finalize dest_high.
10546 While, by checking gimple statements, if operand B is
10547 coming from signed extension, then we can simplify above
10550 1. dest_high = src_low >> (word_size - C).
10551 2. dest_low = src_low << C.
10553 We can use one arithmetic right shift to finish all the
10554 purpose of steps 2, 4, 5, 6, thus we reduce the steps
10555 needed from 6 into 2.
10557 The case is similar for zero extension, except that we
10558 initialize dest_high to zero rather than copies of the sign
10559 bit from B. Furthermore, we need to use a logical right shift
10562 The choice of sign-extension versus zero-extension is
10563 determined entirely by whether or not B is signed and is
10564 independent of the current setting of unsignedp. */
10567 if (code
== LSHIFT_EXPR
10570 && GET_MODE_2XWIDER_MODE (word_mode
).exists (&int_mode
)
10571 && mode
== int_mode
10572 && TREE_CONSTANT (treeop1
)
10573 && TREE_CODE (treeop0
) == SSA_NAME
)
10575 gimple
*def
= SSA_NAME_DEF_STMT (treeop0
);
10576 if (is_gimple_assign (def
)
10577 && gimple_assign_rhs_code (def
) == NOP_EXPR
)
10579 scalar_int_mode rmode
= SCALAR_INT_TYPE_MODE
10580 (TREE_TYPE (gimple_assign_rhs1 (def
)));
10582 if (GET_MODE_SIZE (rmode
) < GET_MODE_SIZE (int_mode
)
10583 && TREE_INT_CST_LOW (treeop1
) < GET_MODE_BITSIZE (word_mode
)
10584 && ((TREE_INT_CST_LOW (treeop1
) + GET_MODE_BITSIZE (rmode
))
10585 >= GET_MODE_BITSIZE (word_mode
)))
10587 rtx_insn
*seq
, *seq_old
;
10588 poly_uint64 high_off
= subreg_highpart_offset (word_mode
,
10590 bool extend_unsigned
10591 = TYPE_UNSIGNED (TREE_TYPE (gimple_assign_rhs1 (def
)));
10592 rtx low
= lowpart_subreg (word_mode
, op0
, int_mode
);
10593 rtx dest_low
= lowpart_subreg (word_mode
, target
, int_mode
);
10594 rtx dest_high
= simplify_gen_subreg (word_mode
, target
,
10595 int_mode
, high_off
);
10596 HOST_WIDE_INT ramount
= (BITS_PER_WORD
10597 - TREE_INT_CST_LOW (treeop1
));
10598 tree rshift
= build_int_cst (TREE_TYPE (treeop1
), ramount
);
10601 /* dest_high = src_low >> (word_size - C). */
10602 temp
= expand_variable_shift (RSHIFT_EXPR
, word_mode
, low
,
10605 if (temp
!= dest_high
)
10606 emit_move_insn (dest_high
, temp
);
10608 /* dest_low = src_low << C. */
10609 temp
= expand_variable_shift (LSHIFT_EXPR
, word_mode
, low
,
10610 treeop1
, dest_low
, unsignedp
);
10611 if (temp
!= dest_low
)
10612 emit_move_insn (dest_low
, temp
);
10614 seq
= get_insns ();
10618 if (have_insn_for (ASHIFT
, int_mode
))
10620 bool speed_p
= optimize_insn_for_speed_p ();
10622 rtx ret_old
= expand_variable_shift (code
, int_mode
,
10627 seq_old
= get_insns ();
10629 if (seq_cost (seq
, speed_p
)
10630 >= seq_cost (seq_old
, speed_p
))
10641 if (temp
== NULL_RTX
)
10642 temp
= expand_variable_shift (code
, mode
, op0
, treeop1
, target
,
10644 if (code
== LSHIFT_EXPR
)
10645 temp
= REDUCE_BIT_FIELD (temp
);
10649 /* Could determine the answer when only additive constants differ. Also,
10650 the addition of one can be handled by changing the condition. */
10657 case UNORDERED_EXPR
:
10666 temp
= do_store_flag (ops
,
10667 modifier
!= EXPAND_STACK_PARM
? target
: NULL_RTX
,
10668 tmode
!= VOIDmode
? tmode
: mode
);
10672 /* Use a compare and a jump for BLKmode comparisons, or for function
10673 type comparisons is have_canonicalize_funcptr_for_compare. */
10676 || modifier
== EXPAND_STACK_PARM
10677 || ! safe_from_p (target
, treeop0
, 1)
10678 || ! safe_from_p (target
, treeop1
, 1)
10679 /* Make sure we don't have a hard reg (such as function's return
10680 value) live across basic blocks, if not optimizing. */
10681 || (!optimize
&& REG_P (target
)
10682 && REGNO (target
) < FIRST_PSEUDO_REGISTER
)))
10683 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
10685 emit_move_insn (target
, const0_rtx
);
10687 rtx_code_label
*lab1
= gen_label_rtx ();
10688 jumpifnot_1 (code
, treeop0
, treeop1
, lab1
,
10689 profile_probability::uninitialized ());
10691 if (TYPE_PRECISION (type
) == 1 && !TYPE_UNSIGNED (type
))
10692 emit_move_insn (target
, constm1_rtx
);
10694 emit_move_insn (target
, const1_rtx
);
10700 /* Get the rtx code of the operands. */
10701 op0
= expand_normal (treeop0
);
10702 op1
= expand_normal (treeop1
);
10705 target
= gen_reg_rtx (TYPE_MODE (type
));
10707 /* If target overlaps with op1, then either we need to force
10708 op1 into a pseudo (if target also overlaps with op0),
10709 or write the complex parts in reverse order. */
10710 switch (GET_CODE (target
))
10713 if (reg_overlap_mentioned_p (XEXP (target
, 0), op1
))
10715 if (reg_overlap_mentioned_p (XEXP (target
, 1), op0
))
10717 complex_expr_force_op1
:
10718 temp
= gen_reg_rtx (GET_MODE_INNER (GET_MODE (target
)));
10719 emit_move_insn (temp
, op1
);
10723 complex_expr_swap_order
:
10724 /* Move the imaginary (op1) and real (op0) parts to their
10726 write_complex_part (target
, op1
, true, true);
10727 write_complex_part (target
, op0
, false, false);
10733 temp
= adjust_address_nv (target
,
10734 GET_MODE_INNER (GET_MODE (target
)), 0);
10735 if (reg_overlap_mentioned_p (temp
, op1
))
10737 scalar_mode imode
= GET_MODE_INNER (GET_MODE (target
));
10738 temp
= adjust_address_nv (target
, imode
,
10739 GET_MODE_SIZE (imode
));
10740 if (reg_overlap_mentioned_p (temp
, op0
))
10741 goto complex_expr_force_op1
;
10742 goto complex_expr_swap_order
;
10746 if (reg_overlap_mentioned_p (target
, op1
))
10748 if (reg_overlap_mentioned_p (target
, op0
))
10749 goto complex_expr_force_op1
;
10750 goto complex_expr_swap_order
;
10755 /* Move the real (op0) and imaginary (op1) parts to their location. */
10756 write_complex_part (target
, op0
, false, true);
10757 write_complex_part (target
, op1
, true, false);
10761 case WIDEN_SUM_EXPR
:
10763 tree oprnd0
= treeop0
;
10764 tree oprnd1
= treeop1
;
10766 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
10767 target
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, op1
,
10768 target
, unsignedp
);
10772 case VEC_UNPACK_HI_EXPR
:
10773 case VEC_UNPACK_LO_EXPR
:
10774 case VEC_UNPACK_FIX_TRUNC_HI_EXPR
:
10775 case VEC_UNPACK_FIX_TRUNC_LO_EXPR
:
10777 op0
= expand_normal (treeop0
);
10778 temp
= expand_widen_pattern_expr (ops
, op0
, NULL_RTX
, NULL_RTX
,
10779 target
, unsignedp
);
10784 case VEC_UNPACK_FLOAT_HI_EXPR
:
10785 case VEC_UNPACK_FLOAT_LO_EXPR
:
10787 op0
= expand_normal (treeop0
);
10788 /* The signedness is determined from input operand. */
10789 temp
= expand_widen_pattern_expr
10790 (ops
, op0
, NULL_RTX
, NULL_RTX
,
10791 target
, TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
10797 case VEC_WIDEN_MULT_HI_EXPR
:
10798 case VEC_WIDEN_MULT_LO_EXPR
:
10799 case VEC_WIDEN_MULT_EVEN_EXPR
:
10800 case VEC_WIDEN_MULT_ODD_EXPR
:
10801 case VEC_WIDEN_LSHIFT_HI_EXPR
:
10802 case VEC_WIDEN_LSHIFT_LO_EXPR
:
10803 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
10804 target
= expand_widen_pattern_expr (ops
, op0
, op1
, NULL_RTX
,
10805 target
, unsignedp
);
10806 gcc_assert (target
);
10809 case VEC_PACK_SAT_EXPR
:
10810 case VEC_PACK_FIX_TRUNC_EXPR
:
10811 mode
= TYPE_MODE (TREE_TYPE (treeop0
));
10812 subtarget
= NULL_RTX
;
10815 case VEC_PACK_TRUNC_EXPR
:
10816 if (VECTOR_BOOLEAN_TYPE_P (type
)
10817 && VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (treeop0
))
10818 && mode
== TYPE_MODE (TREE_TYPE (treeop0
))
10819 && SCALAR_INT_MODE_P (mode
))
10821 class expand_operand eops
[4];
10822 machine_mode imode
= TYPE_MODE (TREE_TYPE (treeop0
));
10823 expand_operands (treeop0
, treeop1
,
10824 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
10825 this_optab
= vec_pack_sbool_trunc_optab
;
10826 enum insn_code icode
= optab_handler (this_optab
, imode
);
10827 create_output_operand (&eops
[0], target
, mode
);
10828 create_convert_operand_from (&eops
[1], op0
, imode
, false);
10829 create_convert_operand_from (&eops
[2], op1
, imode
, false);
10830 temp
= GEN_INT (TYPE_VECTOR_SUBPARTS (type
).to_constant ());
10831 create_input_operand (&eops
[3], temp
, imode
);
10832 expand_insn (icode
, 4, eops
);
10833 return eops
[0].value
;
10835 mode
= TYPE_MODE (TREE_TYPE (treeop0
));
10836 subtarget
= NULL_RTX
;
10839 case VEC_PACK_FLOAT_EXPR
:
10840 mode
= TYPE_MODE (TREE_TYPE (treeop0
));
10841 expand_operands (treeop0
, treeop1
,
10842 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
10843 this_optab
= optab_for_tree_code (code
, TREE_TYPE (treeop0
),
10845 target
= expand_binop (mode
, this_optab
, op0
, op1
, target
,
10846 TYPE_UNSIGNED (TREE_TYPE (treeop0
)),
10848 gcc_assert (target
);
10851 case VEC_PERM_EXPR
:
10853 expand_operands (treeop0
, treeop1
, target
, &op0
, &op1
, EXPAND_NORMAL
);
10854 vec_perm_builder sel
;
10855 if (TREE_CODE (treeop2
) == VECTOR_CST
10856 && tree_to_vec_perm_builder (&sel
, treeop2
))
10858 machine_mode sel_mode
= TYPE_MODE (TREE_TYPE (treeop2
));
10859 temp
= expand_vec_perm_const (mode
, op0
, op1
, sel
,
10864 op2
= expand_normal (treeop2
);
10865 temp
= expand_vec_perm_var (mode
, op0
, op1
, op2
, target
);
10871 case DOT_PROD_EXPR
:
10873 tree oprnd0
= treeop0
;
10874 tree oprnd1
= treeop1
;
10875 tree oprnd2
= treeop2
;
10877 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
10878 op2
= expand_normal (oprnd2
);
10879 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
10880 target
, unsignedp
);
10886 tree oprnd0
= treeop0
;
10887 tree oprnd1
= treeop1
;
10888 tree oprnd2
= treeop2
;
10890 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
10891 op2
= expand_normal (oprnd2
);
10892 target
= expand_widen_pattern_expr (ops
, op0
, op1
, op2
,
10893 target
, unsignedp
);
10897 case REALIGN_LOAD_EXPR
:
10899 tree oprnd0
= treeop0
;
10900 tree oprnd1
= treeop1
;
10901 tree oprnd2
= treeop2
;
10903 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
10904 expand_operands (oprnd0
, oprnd1
, NULL_RTX
, &op0
, &op1
, EXPAND_NORMAL
);
10905 op2
= expand_normal (oprnd2
);
10906 temp
= expand_ternary_op (mode
, this_optab
, op0
, op1
, op2
,
10907 target
, unsignedp
);
10914 /* A COND_EXPR with its type being VOID_TYPE represents a
10915 conditional jump and is handled in
10916 expand_gimple_cond_expr. */
10917 gcc_assert (!VOID_TYPE_P (type
));
10919 /* Note that COND_EXPRs whose type is a structure or union
10920 are required to be constructed to contain assignments of
10921 a temporary variable, so that we can evaluate them here
10922 for side effect only. If type is void, we must do likewise. */
10924 gcc_assert (!TREE_ADDRESSABLE (type
)
10926 && TREE_TYPE (treeop1
) != void_type_node
10927 && TREE_TYPE (treeop2
) != void_type_node
);
10929 temp
= expand_cond_expr_using_cmove (treeop0
, treeop1
, treeop2
);
10933 /* If we are not to produce a result, we have no target. Otherwise,
10934 if a target was specified use it; it will not be used as an
10935 intermediate target unless it is safe. If no target, use a
10938 if (modifier
!= EXPAND_STACK_PARM
10940 && safe_from_p (original_target
, treeop0
, 1)
10941 && GET_MODE (original_target
) == mode
10942 && !MEM_P (original_target
))
10943 temp
= original_target
;
10945 temp
= assign_temp (type
, 0, 1);
10947 do_pending_stack_adjust ();
10949 rtx_code_label
*lab0
= gen_label_rtx ();
10950 rtx_code_label
*lab1
= gen_label_rtx ();
10951 jumpifnot (treeop0
, lab0
,
10952 profile_probability::uninitialized ());
10953 store_expr (treeop1
, temp
,
10954 modifier
== EXPAND_STACK_PARM
,
10957 emit_jump_insn (targetm
.gen_jump (lab1
));
10960 store_expr (treeop2
, temp
,
10961 modifier
== EXPAND_STACK_PARM
,
10969 case VEC_DUPLICATE_EXPR
:
10970 op0
= expand_expr (treeop0
, NULL_RTX
, VOIDmode
, modifier
);
10971 target
= expand_vector_broadcast (mode
, op0
);
10972 gcc_assert (target
);
10975 case VEC_SERIES_EXPR
:
10976 expand_operands (treeop0
, treeop1
, NULL_RTX
, &op0
, &op1
, modifier
);
10977 return expand_vec_series_expr (mode
, op0
, op1
, target
);
10979 case BIT_INSERT_EXPR
:
10981 unsigned bitpos
= tree_to_uhwi (treeop2
);
10983 if (INTEGRAL_TYPE_P (TREE_TYPE (treeop1
)))
10984 bitsize
= TYPE_PRECISION (TREE_TYPE (treeop1
));
10986 bitsize
= tree_to_uhwi (TYPE_SIZE (TREE_TYPE (treeop1
)));
10987 op0
= expand_normal (treeop0
);
10988 op1
= expand_normal (treeop1
);
10989 rtx dst
= gen_reg_rtx (mode
);
10990 emit_move_insn (dst
, op0
);
10991 store_bit_field (dst
, bitsize
, bitpos
, 0, 0,
10992 TYPE_MODE (TREE_TYPE (treeop1
)), op1
, false, false);
10997 gcc_unreachable ();
11000 /* Here to do an ordinary binary operator. */
11002 expand_operands (treeop0
, treeop1
,
11003 subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
11005 this_optab
= optab_for_tree_code (code
, type
, optab_default
);
11007 if (modifier
== EXPAND_STACK_PARM
)
11009 temp
= expand_binop (mode
, this_optab
, op0
, op1
, target
,
11010 unsignedp
, OPTAB_LIB_WIDEN
);
11012 /* Bitwise operations do not need bitfield reduction as we expect their
11013 operands being properly truncated. */
11014 if (code
== BIT_XOR_EXPR
11015 || code
== BIT_AND_EXPR
11016 || code
== BIT_IOR_EXPR
)
11018 return REDUCE_BIT_FIELD (temp
);
11020 #undef REDUCE_BIT_FIELD
11023 /* Return TRUE if expression STMT is suitable for replacement.
11024 Never consider memory loads as replaceable, because those don't ever lead
11025 into constant expressions. */
11028 stmt_is_replaceable_p (gimple
*stmt
)
11030 if (ssa_is_replaceable_p (stmt
))
11032 /* Don't move around loads. */
11033 if (!gimple_assign_single_p (stmt
)
11034 || is_gimple_val (gimple_assign_rhs1 (stmt
)))
11041 expand_expr_real_1 (tree exp
, rtx target
, machine_mode tmode
,
11042 enum expand_modifier modifier
, rtx
*alt_rtl
,
11043 bool inner_reference_p
)
11045 rtx op0
, op1
, temp
, decl_rtl
;
11048 machine_mode mode
, dmode
;
11049 enum tree_code code
= TREE_CODE (exp
);
11050 rtx subtarget
, original_target
;
11052 bool reduce_bit_field
;
11053 location_t loc
= EXPR_LOCATION (exp
);
11054 struct separate_ops ops
;
11055 tree treeop0
, treeop1
, treeop2
;
11056 tree ssa_name
= NULL_TREE
;
11059 /* Some ABIs define padding bits in _BitInt uninitialized. Normally, RTL
11060 expansion sign/zero extends integral types with less than mode precision
11061 when reading from bit-fields and after arithmetic operations (see
11062 REDUCE_BIT_FIELD in expand_expr_real_2) and on subsequent loads relies
11063 on those extensions to have been already performed, but because of the
11064 above for _BitInt they need to be sign/zero extended when reading from
11065 locations that could be exposed to ABI boundaries (when loading from
11066 objects in memory, or function arguments, return value). Because we
11067 internally extend after arithmetic operations, we can avoid doing that
11068 when reading from SSA_NAMEs of vars. */
11069 #define EXTEND_BITINT(expr) \
11070 ((TREE_CODE (type) == BITINT_TYPE \
11071 && reduce_bit_field \
11072 && mode != BLKmode \
11073 && modifier != EXPAND_MEMORY \
11074 && modifier != EXPAND_WRITE \
11075 && modifier != EXPAND_INITIALIZER \
11076 && modifier != EXPAND_CONST_ADDRESS) \
11077 ? reduce_to_bit_field_precision ((expr), NULL_RTX, type) : (expr))
11079 type
= TREE_TYPE (exp
);
11080 mode
= TYPE_MODE (type
);
11081 unsignedp
= TYPE_UNSIGNED (type
);
11083 treeop0
= treeop1
= treeop2
= NULL_TREE
;
11084 if (!VL_EXP_CLASS_P (exp
))
11085 switch (TREE_CODE_LENGTH (code
))
11088 case 3: treeop2
= TREE_OPERAND (exp
, 2); /* FALLTHRU */
11089 case 2: treeop1
= TREE_OPERAND (exp
, 1); /* FALLTHRU */
11090 case 1: treeop0
= TREE_OPERAND (exp
, 0); /* FALLTHRU */
11098 ops
.location
= loc
;
11100 ignore
= (target
== const0_rtx
11101 || ((CONVERT_EXPR_CODE_P (code
)
11102 || code
== COND_EXPR
|| code
== VIEW_CONVERT_EXPR
)
11103 && TREE_CODE (type
) == VOID_TYPE
));
11105 /* An operation in what may be a bit-field type needs the
11106 result to be reduced to the precision of the bit-field type,
11107 which is narrower than that of the type's mode. */
11108 reduce_bit_field
= (!ignore
11109 && INTEGRAL_TYPE_P (type
)
11110 && !type_has_mode_precision_p (type
));
11112 /* If we are going to ignore this result, we need only do something
11113 if there is a side-effect somewhere in the expression. If there
11114 is, short-circuit the most common cases here. Note that we must
11115 not call expand_expr with anything but const0_rtx in case this
11116 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
11120 if (! TREE_SIDE_EFFECTS (exp
))
11123 /* Ensure we reference a volatile object even if value is ignored, but
11124 don't do this if all we are doing is taking its address. */
11125 if (TREE_THIS_VOLATILE (exp
)
11126 && TREE_CODE (exp
) != FUNCTION_DECL
11127 && mode
!= VOIDmode
&& mode
!= BLKmode
11128 && modifier
!= EXPAND_CONST_ADDRESS
)
11130 temp
= expand_expr (exp
, NULL_RTX
, VOIDmode
, modifier
);
11132 copy_to_reg (temp
);
11136 if (TREE_CODE_CLASS (code
) == tcc_unary
11137 || code
== BIT_FIELD_REF
11138 || code
== COMPONENT_REF
11139 || code
== INDIRECT_REF
)
11140 return expand_expr (treeop0
, const0_rtx
, VOIDmode
,
11143 else if (TREE_CODE_CLASS (code
) == tcc_binary
11144 || TREE_CODE_CLASS (code
) == tcc_comparison
11145 || code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
11147 expand_expr (treeop0
, const0_rtx
, VOIDmode
, modifier
);
11148 expand_expr (treeop1
, const0_rtx
, VOIDmode
, modifier
);
11155 if (reduce_bit_field
&& modifier
== EXPAND_STACK_PARM
)
11158 /* Use subtarget as the target for operand 0 of a binary operation. */
11159 subtarget
= get_subtarget (target
);
11160 original_target
= target
;
11166 tree function
= decl_function_context (exp
);
11168 temp
= label_rtx (exp
);
11169 temp
= gen_rtx_LABEL_REF (Pmode
, temp
);
11171 if (function
!= current_function_decl
11173 LABEL_REF_NONLOCAL_P (temp
) = 1;
11175 temp
= gen_rtx_MEM (FUNCTION_MODE
, temp
);
11180 /* ??? ivopts calls expander, without any preparation from
11181 out-of-ssa. So fake instructions as if this was an access to the
11182 base variable. This unnecessarily allocates a pseudo, see how we can
11183 reuse it, if partition base vars have it set already. */
11184 if (!currently_expanding_to_rtl
)
11186 tree var
= SSA_NAME_VAR (exp
);
11187 if (var
&& DECL_RTL_SET_P (var
))
11188 return DECL_RTL (var
);
11189 return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp
)),
11190 LAST_VIRTUAL_REGISTER
+ 1);
11193 g
= get_gimple_for_ssa_name (exp
);
11194 /* For EXPAND_INITIALIZER try harder to get something simpler. */
11196 && modifier
== EXPAND_INITIALIZER
11197 && !SSA_NAME_IS_DEFAULT_DEF (exp
)
11198 && (optimize
|| !SSA_NAME_VAR (exp
)
11199 || DECL_IGNORED_P (SSA_NAME_VAR (exp
)))
11200 && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp
)))
11201 g
= SSA_NAME_DEF_STMT (exp
);
11205 location_t saved_loc
= curr_insn_location ();
11206 loc
= gimple_location (g
);
11207 if (loc
!= UNKNOWN_LOCATION
)
11208 set_curr_insn_location (loc
);
11209 ops
.code
= gimple_assign_rhs_code (g
);
11210 switch (get_gimple_rhs_class (ops
.code
))
11212 case GIMPLE_TERNARY_RHS
:
11213 ops
.op2
= gimple_assign_rhs3 (g
);
11215 case GIMPLE_BINARY_RHS
:
11216 ops
.op1
= gimple_assign_rhs2 (g
);
11218 /* Try to expand conditonal compare. */
11219 if (targetm
.gen_ccmp_first
)
11221 gcc_checking_assert (targetm
.gen_ccmp_next
!= NULL
);
11222 r
= expand_ccmp_expr (g
, mode
);
11227 case GIMPLE_UNARY_RHS
:
11228 ops
.op0
= gimple_assign_rhs1 (g
);
11229 ops
.type
= TREE_TYPE (gimple_assign_lhs (g
));
11230 ops
.location
= loc
;
11231 r
= expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
11233 case GIMPLE_SINGLE_RHS
:
11235 r
= expand_expr_real (gimple_assign_rhs1 (g
), target
,
11236 tmode
, modifier
, alt_rtl
,
11237 inner_reference_p
);
11241 gcc_unreachable ();
11243 set_curr_insn_location (saved_loc
);
11244 if (REG_P (r
) && !REG_EXPR (r
))
11245 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp
), r
);
11250 decl_rtl
= get_rtx_for_ssa_name (ssa_name
);
11251 exp
= SSA_NAME_VAR (ssa_name
);
11252 /* Optimize and avoid to EXTEND_BITINIT doing anything if it is an
11253 SSA_NAME computed within the current function. In such case the
11254 value have been already extended before. While if it is a function
11255 parameter, result or some memory location, we need to be prepared
11256 for some other compiler leaving the bits uninitialized. */
11257 if (!exp
|| VAR_P (exp
))
11258 reduce_bit_field
= false;
11259 goto expand_decl_rtl
;
11262 /* Allow accel compiler to handle variables that require special
11263 treatment, e.g. if they have been modified in some way earlier in
11264 compilation by the adjust_private_decl OpenACC hook. */
11265 if (flag_openacc
&& targetm
.goacc
.expand_var_decl
)
11267 temp
= targetm
.goacc
.expand_var_decl (exp
);
11271 /* Expand const VAR_DECLs with CONSTRUCTOR initializers that
11272 have scalar integer modes to a reg via store_constructor. */
11273 if (TREE_READONLY (exp
)
11274 && !TREE_SIDE_EFFECTS (exp
)
11275 && (modifier
== EXPAND_NORMAL
|| modifier
== EXPAND_STACK_PARM
)
11276 && immediate_const_ctor_p (DECL_INITIAL (exp
))
11277 && SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (exp
)))
11278 && crtl
->emit
.regno_pointer_align_length
11281 target
= gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp
)));
11282 store_constructor (DECL_INITIAL (exp
), target
, 0,
11283 int_expr_size (DECL_INITIAL (exp
)), false);
11286 /* ... fall through ... */
11289 /* If a static var's type was incomplete when the decl was written,
11290 but the type is complete now, lay out the decl now. */
11291 if (DECL_SIZE (exp
) == 0
11292 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp
))
11293 && (TREE_STATIC (exp
) || DECL_EXTERNAL (exp
)))
11294 layout_decl (exp
, 0);
11298 case FUNCTION_DECL
:
11300 decl_rtl
= DECL_RTL (exp
);
11302 gcc_assert (decl_rtl
);
11304 /* DECL_MODE might change when TYPE_MODE depends on attribute target
11305 settings for VECTOR_TYPE_P that might switch for the function. */
11306 if (currently_expanding_to_rtl
11307 && code
== VAR_DECL
&& MEM_P (decl_rtl
)
11308 && VECTOR_TYPE_P (type
) && exp
&& DECL_MODE (exp
) != mode
)
11309 decl_rtl
= change_address (decl_rtl
, TYPE_MODE (type
), 0);
11311 decl_rtl
= copy_rtx (decl_rtl
);
11313 /* Record writes to register variables. */
11314 if (modifier
== EXPAND_WRITE
11315 && REG_P (decl_rtl
)
11316 && HARD_REGISTER_P (decl_rtl
))
11317 add_to_hard_reg_set (&crtl
->asm_clobbers
,
11318 GET_MODE (decl_rtl
), REGNO (decl_rtl
));
11320 /* Ensure variable marked as used even if it doesn't go through
11321 a parser. If it hasn't be used yet, write out an external
11324 TREE_USED (exp
) = 1;
11326 /* Show we haven't gotten RTL for this yet. */
11329 /* Variables inherited from containing functions should have
11330 been lowered by this point. */
11333 tree context
= decl_function_context (exp
);
11334 gcc_assert (SCOPE_FILE_SCOPE_P (context
)
11335 || context
== current_function_decl
11336 || TREE_STATIC (exp
)
11337 || DECL_EXTERNAL (exp
)
11338 /* ??? C++ creates functions that are not
11340 || TREE_CODE (exp
) == FUNCTION_DECL
);
11343 /* This is the case of an array whose size is to be determined
11344 from its initializer, while the initializer is still being parsed.
11345 ??? We aren't parsing while expanding anymore. */
11347 if (MEM_P (decl_rtl
) && REG_P (XEXP (decl_rtl
, 0)))
11348 temp
= validize_mem (decl_rtl
);
11350 /* If DECL_RTL is memory, we are in the normal case and the
11351 address is not valid, get the address into a register. */
11353 else if (MEM_P (decl_rtl
) && modifier
!= EXPAND_INITIALIZER
)
11356 *alt_rtl
= decl_rtl
;
11357 decl_rtl
= use_anchored_address (decl_rtl
);
11358 if (modifier
!= EXPAND_CONST_ADDRESS
11359 && modifier
!= EXPAND_SUM
11360 && !memory_address_addr_space_p (exp
? DECL_MODE (exp
)
11361 : GET_MODE (decl_rtl
),
11362 XEXP (decl_rtl
, 0),
11363 MEM_ADDR_SPACE (decl_rtl
)))
11364 temp
= replace_equiv_address (decl_rtl
,
11365 copy_rtx (XEXP (decl_rtl
, 0)));
11368 /* If we got something, return it. But first, set the alignment
11369 if the address is a register. */
11372 if (exp
&& MEM_P (temp
) && REG_P (XEXP (temp
, 0)))
11373 mark_reg_pointer (XEXP (temp
, 0), DECL_ALIGN (exp
));
11375 else if (MEM_P (decl_rtl
))
11381 && modifier
!= EXPAND_WRITE
11382 && modifier
!= EXPAND_MEMORY
11383 && modifier
!= EXPAND_INITIALIZER
11384 && modifier
!= EXPAND_CONST_ADDRESS
11385 && modifier
!= EXPAND_SUM
11386 && !inner_reference_p
11388 && MEM_ALIGN (temp
) < GET_MODE_ALIGNMENT (mode
))
11389 temp
= expand_misaligned_mem_ref (temp
, mode
, unsignedp
,
11390 MEM_ALIGN (temp
), NULL_RTX
, NULL
);
11392 return EXTEND_BITINT (temp
);
11396 dmode
= DECL_MODE (exp
);
11398 dmode
= TYPE_MODE (TREE_TYPE (ssa_name
));
11400 /* If the mode of DECL_RTL does not match that of the decl,
11401 there are two cases: we are dealing with a BLKmode value
11402 that is returned in a register, or we are dealing with
11403 a promoted value. In the latter case, return a SUBREG
11404 of the wanted mode, but mark it so that we know that it
11405 was already extended. */
11406 if (REG_P (decl_rtl
)
11407 && dmode
!= BLKmode
11408 && GET_MODE (decl_rtl
) != dmode
)
11410 machine_mode pmode
;
11412 /* Get the signedness to be used for this variable. Ensure we get
11413 the same mode we got when the variable was declared. */
11414 if (code
!= SSA_NAME
)
11415 pmode
= promote_decl_mode (exp
, &unsignedp
);
11416 else if ((g
= SSA_NAME_DEF_STMT (ssa_name
))
11417 && gimple_code (g
) == GIMPLE_CALL
11418 && !gimple_call_internal_p (g
))
11419 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
11420 gimple_call_fntype (g
),
11423 pmode
= promote_ssa_mode (ssa_name
, &unsignedp
);
11424 gcc_assert (GET_MODE (decl_rtl
) == pmode
);
11426 /* Some ABIs require scalar floating point modes to be passed
11427 in a wider scalar integer mode. We need to explicitly
11428 truncate to an integer mode of the correct precision before
11429 using a SUBREG to reinterpret as a floating point value. */
11430 if (SCALAR_FLOAT_MODE_P (mode
)
11431 && SCALAR_INT_MODE_P (pmode
)
11432 && known_lt (GET_MODE_SIZE (mode
), GET_MODE_SIZE (pmode
)))
11433 return convert_wider_int_to_float (mode
, pmode
, decl_rtl
);
11435 temp
= gen_lowpart_SUBREG (mode
, decl_rtl
);
11436 SUBREG_PROMOTED_VAR_P (temp
) = 1;
11437 SUBREG_PROMOTED_SET (temp
, unsignedp
);
11438 return EXTEND_BITINT (temp
);
11441 return EXTEND_BITINT (decl_rtl
);
11445 if (TREE_CODE (type
) == BITINT_TYPE
)
11447 unsigned int prec
= TYPE_PRECISION (type
);
11448 struct bitint_info info
;
11449 bool ok
= targetm
.c
.bitint_type_info (prec
, &info
);
11451 scalar_int_mode limb_mode
11452 = as_a
<scalar_int_mode
> (info
.limb_mode
);
11453 unsigned int limb_prec
= GET_MODE_PRECISION (limb_mode
);
11454 if (prec
> limb_prec
&& prec
> MAX_FIXED_MODE_SIZE
)
11456 /* Emit large/huge _BitInt INTEGER_CSTs into memory. */
11457 exp
= tree_output_constant_def (exp
);
11458 return expand_expr (exp
, target
, VOIDmode
, modifier
);
11462 /* Given that TYPE_PRECISION (type) is not always equal to
11463 GET_MODE_PRECISION (TYPE_MODE (type)), we need to extend from
11464 the former to the latter according to the signedness of the
11466 scalar_int_mode int_mode
= SCALAR_INT_TYPE_MODE (type
);
11467 temp
= immed_wide_int_const
11468 (wi::to_wide (exp
, GET_MODE_PRECISION (int_mode
)), int_mode
);
11474 tree tmp
= NULL_TREE
;
11475 if (VECTOR_MODE_P (mode
))
11476 return const_vector_from_tree (exp
);
11477 scalar_int_mode int_mode
;
11478 if (is_int_mode (mode
, &int_mode
))
11480 tree type_for_mode
= lang_hooks
.types
.type_for_mode (int_mode
, 1);
11482 tmp
= fold_unary_loc (loc
, VIEW_CONVERT_EXPR
,
11483 type_for_mode
, exp
);
11487 vec
<constructor_elt
, va_gc
> *v
;
11488 /* Constructors need to be fixed-length. FIXME. */
11489 unsigned int nunits
= VECTOR_CST_NELTS (exp
).to_constant ();
11490 vec_alloc (v
, nunits
);
11491 for (unsigned int i
= 0; i
< nunits
; ++i
)
11492 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, VECTOR_CST_ELT (exp
, i
));
11493 tmp
= build_constructor (type
, v
);
11495 return expand_expr (tmp
, ignore
? const0_rtx
: target
,
11500 if (modifier
== EXPAND_WRITE
)
11502 /* Writing into CONST_DECL is always invalid, but handle it
11504 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (exp
));
11505 scalar_int_mode address_mode
= targetm
.addr_space
.address_mode (as
);
11506 op0
= expand_expr_addr_expr_1 (exp
, NULL_RTX
, address_mode
,
11507 EXPAND_NORMAL
, as
);
11508 op0
= memory_address_addr_space (mode
, op0
, as
);
11509 temp
= gen_rtx_MEM (mode
, op0
);
11510 set_mem_addr_space (temp
, as
);
11513 return expand_expr (DECL_INITIAL (exp
), target
, VOIDmode
, modifier
);
11516 /* If optimized, generate immediate CONST_DOUBLE
11517 which will be turned into memory by reload if necessary.
11519 We used to force a register so that loop.c could see it. But
11520 this does not allow gen_* patterns to perform optimizations with
11521 the constants. It also produces two insns in cases like "x = 1.0;".
11522 On most machines, floating-point constants are not permitted in
11523 many insns, so we'd end up copying it to a register in any case.
11525 Now, we do the copying in expand_binop, if appropriate. */
11526 return const_double_from_real_value (TREE_REAL_CST (exp
),
11527 TYPE_MODE (TREE_TYPE (exp
)));
11530 return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp
),
11531 TYPE_MODE (TREE_TYPE (exp
)));
11534 /* Handle evaluating a complex constant in a CONCAT target. */
11535 if (original_target
&& GET_CODE (original_target
) == CONCAT
)
11539 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
11540 rtarg
= XEXP (original_target
, 0);
11541 itarg
= XEXP (original_target
, 1);
11543 /* Move the real and imaginary parts separately. */
11544 op0
= expand_expr (TREE_REALPART (exp
), rtarg
, mode
, EXPAND_NORMAL
);
11545 op1
= expand_expr (TREE_IMAGPART (exp
), itarg
, mode
, EXPAND_NORMAL
);
11548 emit_move_insn (rtarg
, op0
);
11550 emit_move_insn (itarg
, op1
);
11552 return original_target
;
11558 temp
= expand_expr_constant (exp
, 1, modifier
);
11560 /* temp contains a constant address.
11561 On RISC machines where a constant address isn't valid,
11562 make some insns to get that address into a register. */
11563 if (modifier
!= EXPAND_CONST_ADDRESS
11564 && modifier
!= EXPAND_INITIALIZER
11565 && modifier
!= EXPAND_SUM
11566 && ! memory_address_addr_space_p (mode
, XEXP (temp
, 0),
11567 MEM_ADDR_SPACE (temp
)))
11568 return replace_equiv_address (temp
,
11569 copy_rtx (XEXP (temp
, 0)));
11573 return immed_wide_int_const (poly_int_cst_value (exp
), mode
);
11577 tree val
= treeop0
;
11578 rtx ret
= expand_expr_real_1 (val
, target
, tmode
, modifier
, alt_rtl
,
11579 inner_reference_p
);
11581 if (!SAVE_EXPR_RESOLVED_P (exp
))
11583 /* We can indeed still hit this case, typically via builtin
11584 expanders calling save_expr immediately before expanding
11585 something. Assume this means that we only have to deal
11586 with non-BLKmode values. */
11587 gcc_assert (GET_MODE (ret
) != BLKmode
);
11589 val
= build_decl (curr_insn_location (),
11590 VAR_DECL
, NULL
, TREE_TYPE (exp
));
11591 DECL_ARTIFICIAL (val
) = 1;
11592 DECL_IGNORED_P (val
) = 1;
11594 TREE_OPERAND (exp
, 0) = treeop0
;
11595 SAVE_EXPR_RESOLVED_P (exp
) = 1;
11597 if (!CONSTANT_P (ret
))
11598 ret
= copy_to_reg (ret
);
11599 SET_DECL_RTL (val
, ret
);
11607 /* If we don't need the result, just ensure we evaluate any
11611 unsigned HOST_WIDE_INT idx
;
11614 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
11615 expand_expr (value
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
11620 return expand_constructor (exp
, target
, modifier
, false);
11622 case TARGET_MEM_REF
:
11625 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
11626 unsigned int align
;
11628 op0
= addr_for_mem_ref (exp
, as
, true);
11629 op0
= memory_address_addr_space (mode
, op0
, as
);
11630 temp
= gen_rtx_MEM (mode
, op0
);
11631 set_mem_attributes (temp
, exp
, 0);
11632 set_mem_addr_space (temp
, as
);
11633 align
= get_object_alignment (exp
);
11634 if (modifier
!= EXPAND_WRITE
11635 && modifier
!= EXPAND_MEMORY
11637 && align
< GET_MODE_ALIGNMENT (mode
))
11638 temp
= expand_misaligned_mem_ref (temp
, mode
, unsignedp
,
11639 align
, NULL_RTX
, NULL
);
11640 return EXTEND_BITINT (temp
);
11645 const bool reverse
= REF_REVERSE_STORAGE_ORDER (exp
);
11647 = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp
, 0))));
11648 machine_mode address_mode
;
11649 tree base
= TREE_OPERAND (exp
, 0);
11652 /* Handle expansion of non-aliased memory with non-BLKmode. That
11653 might end up in a register. */
11654 if (mem_ref_refers_to_non_mem_p (exp
))
11656 poly_int64 offset
= mem_ref_offset (exp
).force_shwi ();
11657 base
= TREE_OPERAND (base
, 0);
11658 poly_uint64 type_size
;
11659 if (known_eq (offset
, 0)
11661 && poly_int_tree_p (TYPE_SIZE (type
), &type_size
)
11662 && known_eq (GET_MODE_BITSIZE (DECL_MODE (base
)), type_size
))
11663 return expand_expr (build1 (VIEW_CONVERT_EXPR
, type
, base
),
11664 target
, tmode
, modifier
);
11665 if (TYPE_MODE (type
) == BLKmode
)
11667 temp
= assign_stack_temp (DECL_MODE (base
),
11668 GET_MODE_SIZE (DECL_MODE (base
)));
11669 store_expr (base
, temp
, 0, false, false);
11670 temp
= adjust_address (temp
, BLKmode
, offset
);
11671 set_mem_size (temp
, int_size_in_bytes (type
));
11674 exp
= build3 (BIT_FIELD_REF
, type
, base
, TYPE_SIZE (type
),
11675 bitsize_int (offset
* BITS_PER_UNIT
));
11676 REF_REVERSE_STORAGE_ORDER (exp
) = reverse
;
11677 return expand_expr (exp
, target
, tmode
, modifier
);
11679 address_mode
= targetm
.addr_space
.address_mode (as
);
11680 if ((def_stmt
= get_def_for_expr (base
, BIT_AND_EXPR
)))
11682 tree mask
= gimple_assign_rhs2 (def_stmt
);
11683 base
= build2 (BIT_AND_EXPR
, TREE_TYPE (base
),
11684 gimple_assign_rhs1 (def_stmt
), mask
);
11685 TREE_OPERAND (exp
, 0) = base
;
11687 align
= get_object_alignment (exp
);
11688 op0
= expand_expr (base
, NULL_RTX
, VOIDmode
, EXPAND_SUM
);
11689 op0
= memory_address_addr_space (mode
, op0
, as
);
11690 if (!integer_zerop (TREE_OPERAND (exp
, 1)))
11692 rtx off
= immed_wide_int_const (mem_ref_offset (exp
), address_mode
);
11693 op0
= simplify_gen_binary (PLUS
, address_mode
, op0
, off
);
11694 op0
= memory_address_addr_space (mode
, op0
, as
);
11696 temp
= gen_rtx_MEM (mode
, op0
);
11697 set_mem_attributes (temp
, exp
, 0);
11698 set_mem_addr_space (temp
, as
);
11699 if (TREE_THIS_VOLATILE (exp
))
11700 MEM_VOLATILE_P (temp
) = 1;
11701 if (modifier
== EXPAND_WRITE
|| modifier
== EXPAND_MEMORY
)
11703 if (!inner_reference_p
11705 && align
< GET_MODE_ALIGNMENT (mode
))
11706 temp
= expand_misaligned_mem_ref (temp
, mode
, unsignedp
, align
,
11707 modifier
== EXPAND_STACK_PARM
11708 ? NULL_RTX
: target
, alt_rtl
);
11710 temp
= flip_storage_order (mode
, temp
);
11711 return EXTEND_BITINT (temp
);
11717 tree array
= treeop0
;
11718 tree index
= treeop1
;
11721 /* Fold an expression like: "foo"[2].
11722 This is not done in fold so it won't happen inside &.
11723 Don't fold if this is for wide characters since it's too
11724 difficult to do correctly and this is a very rare case. */
11726 if (modifier
!= EXPAND_CONST_ADDRESS
11727 && modifier
!= EXPAND_INITIALIZER
11728 && modifier
!= EXPAND_MEMORY
)
11730 tree t
= fold_read_from_constant_string (exp
);
11733 return expand_expr (t
, target
, tmode
, modifier
);
11736 /* If this is a constant index into a constant array,
11737 just get the value from the array. Handle both the cases when
11738 we have an explicit constructor and when our operand is a variable
11739 that was declared const. */
11741 if (modifier
!= EXPAND_CONST_ADDRESS
11742 && modifier
!= EXPAND_INITIALIZER
11743 && modifier
!= EXPAND_MEMORY
11744 && TREE_CODE (array
) == CONSTRUCTOR
11745 && ! TREE_SIDE_EFFECTS (array
)
11746 && TREE_CODE (index
) == INTEGER_CST
)
11748 unsigned HOST_WIDE_INT ix
;
11751 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array
), ix
,
11753 if (tree_int_cst_equal (field
, index
))
11755 if (!TREE_SIDE_EFFECTS (value
))
11756 return expand_expr (fold (value
), target
, tmode
, modifier
);
11761 else if (optimize
>= 1
11762 && modifier
!= EXPAND_CONST_ADDRESS
11763 && modifier
!= EXPAND_INITIALIZER
11764 && modifier
!= EXPAND_MEMORY
11765 && TREE_READONLY (array
) && ! TREE_SIDE_EFFECTS (array
)
11766 && TREE_CODE (index
) == INTEGER_CST
11767 && (VAR_P (array
) || TREE_CODE (array
) == CONST_DECL
)
11768 && (init
= ctor_for_folding (array
)) != error_mark_node
)
11770 if (init
== NULL_TREE
)
11772 tree value
= build_zero_cst (type
);
11773 if (TREE_CODE (value
) == CONSTRUCTOR
)
11775 /* If VALUE is a CONSTRUCTOR, this optimization is only
11776 useful if this doesn't store the CONSTRUCTOR into
11777 memory. If it does, it is more efficient to just
11778 load the data from the array directly. */
11779 rtx ret
= expand_constructor (value
, target
,
11781 if (ret
== NULL_RTX
)
11786 return expand_expr (value
, target
, tmode
, modifier
);
11788 else if (TREE_CODE (init
) == CONSTRUCTOR
)
11790 unsigned HOST_WIDE_INT ix
;
11793 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init
), ix
,
11795 if (tree_int_cst_equal (field
, index
))
11797 if (TREE_SIDE_EFFECTS (value
))
11800 if (TREE_CODE (value
) == CONSTRUCTOR
)
11802 /* If VALUE is a CONSTRUCTOR, this
11803 optimization is only useful if
11804 this doesn't store the CONSTRUCTOR
11805 into memory. If it does, it is more
11806 efficient to just load the data from
11807 the array directly. */
11808 rtx ret
= expand_constructor (value
, target
,
11810 if (ret
== NULL_RTX
)
11815 expand_expr (fold (value
), target
, tmode
, modifier
);
11818 else if (TREE_CODE (init
) == STRING_CST
)
11820 tree low_bound
= array_ref_low_bound (exp
);
11821 tree index1
= fold_convert_loc (loc
, sizetype
, treeop1
);
11823 /* Optimize the special case of a zero lower bound.
11825 We convert the lower bound to sizetype to avoid problems
11826 with constant folding. E.g. suppose the lower bound is
11827 1 and its mode is QI. Without the conversion
11828 (ARRAY + (INDEX - (unsigned char)1))
11830 (ARRAY + (-(unsigned char)1) + INDEX)
11832 (ARRAY + 255 + INDEX). Oops! */
11833 if (!integer_zerop (low_bound
))
11834 index1
= size_diffop_loc (loc
, index1
,
11835 fold_convert_loc (loc
, sizetype
,
11838 if (tree_fits_uhwi_p (index1
)
11839 && compare_tree_int (index1
, TREE_STRING_LENGTH (init
)) < 0)
11841 tree char_type
= TREE_TYPE (TREE_TYPE (init
));
11842 scalar_int_mode char_mode
;
11844 if (is_int_mode (TYPE_MODE (char_type
), &char_mode
)
11845 && GET_MODE_SIZE (char_mode
) == 1)
11846 return gen_int_mode (TREE_STRING_POINTER (init
)
11847 [TREE_INT_CST_LOW (index1
)],
11853 goto normal_inner_ref
;
11855 case COMPONENT_REF
:
11856 gcc_assert (TREE_CODE (treeop0
) != CONSTRUCTOR
);
11857 /* Fall through. */
11858 case BIT_FIELD_REF
:
11859 case ARRAY_RANGE_REF
:
11862 machine_mode mode1
, mode2
;
11863 poly_int64 bitsize
, bitpos
, bytepos
;
11865 int reversep
, volatilep
= 0;
11867 = get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
, &mode1
,
11868 &unsignedp
, &reversep
, &volatilep
);
11869 rtx orig_op0
, memloc
;
11870 bool clear_mem_expr
= false;
11871 bool must_force_mem
;
11873 /* If we got back the original object, something is wrong. Perhaps
11874 we are evaluating an expression too early. In any event, don't
11875 infinitely recurse. */
11876 gcc_assert (tem
!= exp
);
11878 /* Make sure bitpos is not negative, this can wreak havoc later. */
11879 if (maybe_lt (bitpos
, 0))
11881 gcc_checking_assert (offset
== NULL_TREE
);
11882 offset
= size_int (bits_to_bytes_round_down (bitpos
));
11883 bitpos
= num_trailing_bits (bitpos
);
11886 /* If we have either an offset, a BLKmode result, or a reference
11887 outside the underlying object, we must force it to memory.
11888 Such a case can occur in Ada if we have unchecked conversion
11889 of an expression from a scalar type to an aggregate type or
11890 for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
11891 passed a partially uninitialized object or a view-conversion
11892 to a larger size. */
11893 must_force_mem
= offset
!= NULL_TREE
11894 || mode1
== BLKmode
11895 || (mode
== BLKmode
11896 && !int_mode_for_size (bitsize
, 1).exists ());
11898 const enum expand_modifier tem_modifier
11901 : modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
;
11903 /* If TEM's type is a union of variable size, pass TARGET to the inner
11904 computation, since it will need a temporary and TARGET is known
11905 to have to do. This occurs in unchecked conversion in Ada. */
11906 const rtx tem_target
11907 = TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
11908 && COMPLETE_TYPE_P (TREE_TYPE (tem
))
11909 && TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
))) != INTEGER_CST
11910 && modifier
!= EXPAND_STACK_PARM
11915 = expand_expr_real (tem
, tem_target
, VOIDmode
, tem_modifier
, NULL
,
11918 /* If the field has a mode, we want to access it in the
11919 field's mode, not the computed mode.
11920 If a MEM has VOIDmode (external with incomplete type),
11921 use BLKmode for it instead. */
11924 if (mode1
!= VOIDmode
)
11925 op0
= adjust_address (op0
, mode1
, 0);
11926 else if (GET_MODE (op0
) == VOIDmode
)
11927 op0
= adjust_address (op0
, BLKmode
, 0);
11931 = CONSTANT_P (op0
) ? TYPE_MODE (TREE_TYPE (tem
)) : GET_MODE (op0
);
11933 /* See above for the rationale. */
11934 if (maybe_gt (bitpos
+ bitsize
, GET_MODE_BITSIZE (mode2
)))
11935 must_force_mem
= true;
11937 /* Handle CONCAT first. */
11938 if (GET_CODE (op0
) == CONCAT
&& !must_force_mem
)
11940 if (known_eq (bitpos
, 0)
11941 && known_eq (bitsize
, GET_MODE_BITSIZE (GET_MODE (op0
)))
11942 && COMPLEX_MODE_P (mode1
)
11943 && COMPLEX_MODE_P (GET_MODE (op0
))
11944 && (GET_MODE_PRECISION (GET_MODE_INNER (mode1
))
11945 == GET_MODE_PRECISION (GET_MODE_INNER (GET_MODE (op0
)))))
11948 op0
= flip_storage_order (GET_MODE (op0
), op0
);
11949 if (mode1
!= GET_MODE (op0
))
11952 for (int i
= 0; i
< 2; i
++)
11954 rtx op
= read_complex_part (op0
, i
!= 0);
11955 if (GET_CODE (op
) == SUBREG
)
11956 op
= force_reg (GET_MODE (op
), op
);
11957 temp
= gen_lowpart_common (GET_MODE_INNER (mode1
), op
);
11962 if (!REG_P (op
) && !MEM_P (op
))
11963 op
= force_reg (GET_MODE (op
), op
);
11964 op
= gen_lowpart (GET_MODE_INNER (mode1
), op
);
11968 op0
= gen_rtx_CONCAT (mode1
, parts
[0], parts
[1]);
11972 if (known_eq (bitpos
, 0)
11973 && known_eq (bitsize
,
11974 GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0))))
11975 && maybe_ne (bitsize
, 0))
11977 op0
= XEXP (op0
, 0);
11978 mode2
= GET_MODE (op0
);
11980 else if (known_eq (bitpos
,
11981 GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 0))))
11982 && known_eq (bitsize
,
11983 GET_MODE_BITSIZE (GET_MODE (XEXP (op0
, 1))))
11984 && maybe_ne (bitpos
, 0)
11985 && maybe_ne (bitsize
, 0))
11987 op0
= XEXP (op0
, 1);
11989 mode2
= GET_MODE (op0
);
11992 /* Otherwise force into memory. */
11993 must_force_mem
= true;
11996 /* If this is a constant, put it in a register if it is a legitimate
11997 constant and we don't need a memory reference. */
11998 if (CONSTANT_P (op0
)
11999 && mode2
!= BLKmode
12000 && targetm
.legitimate_constant_p (mode2
, op0
)
12001 && !must_force_mem
)
12002 op0
= force_reg (mode2
, op0
);
12004 /* Otherwise, if this is a constant, try to force it to the constant
12005 pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
12006 is a legitimate constant. */
12007 else if (CONSTANT_P (op0
) && (memloc
= force_const_mem (mode2
, op0
)))
12008 op0
= validize_mem (memloc
);
12010 /* Otherwise, if this is a constant or the object is not in memory
12011 and need be, put it there. */
12012 else if (CONSTANT_P (op0
) || (!MEM_P (op0
) && must_force_mem
))
12014 memloc
= assign_temp (TREE_TYPE (tem
), 1, 1);
12015 emit_move_insn (memloc
, op0
);
12017 clear_mem_expr
= true;
12022 machine_mode address_mode
;
12023 rtx offset_rtx
= expand_expr (offset
, NULL_RTX
, VOIDmode
,
12026 gcc_assert (MEM_P (op0
));
12028 address_mode
= get_address_mode (op0
);
12029 if (GET_MODE (offset_rtx
) != address_mode
)
12031 /* We cannot be sure that the RTL in offset_rtx is valid outside
12032 of a memory address context, so force it into a register
12033 before attempting to convert it to the desired mode. */
12034 offset_rtx
= force_operand (offset_rtx
, NULL_RTX
);
12035 offset_rtx
= convert_to_mode (address_mode
, offset_rtx
, 0);
12038 /* See the comment in expand_assignment for the rationale. */
12039 if (mode1
!= VOIDmode
12040 && maybe_ne (bitpos
, 0)
12041 && maybe_gt (bitsize
, 0)
12042 && multiple_p (bitpos
, BITS_PER_UNIT
, &bytepos
)
12043 && multiple_p (bitpos
, bitsize
)
12044 && multiple_p (bitsize
, GET_MODE_ALIGNMENT (mode1
))
12045 && MEM_ALIGN (op0
) >= GET_MODE_ALIGNMENT (mode1
))
12047 op0
= adjust_address (op0
, mode1
, bytepos
);
12051 op0
= offset_address (op0
, offset_rtx
,
12052 highest_pow2_factor (offset
));
12055 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
12056 record its alignment as BIGGEST_ALIGNMENT. */
12058 && known_eq (bitpos
, 0)
12060 && is_aligning_offset (offset
, tem
))
12061 set_mem_align (op0
, BIGGEST_ALIGNMENT
);
12063 /* Don't forget about volatility even if this is a bitfield. */
12064 if (MEM_P (op0
) && volatilep
&& ! MEM_VOLATILE_P (op0
))
12066 if (op0
== orig_op0
)
12067 op0
= copy_rtx (op0
);
12069 MEM_VOLATILE_P (op0
) = 1;
12072 if (MEM_P (op0
) && TREE_CODE (tem
) == FUNCTION_DECL
)
12074 if (op0
== orig_op0
)
12075 op0
= copy_rtx (op0
);
12077 set_mem_align (op0
, BITS_PER_UNIT
);
12080 /* In cases where an aligned union has an unaligned object
12081 as a field, we might be extracting a BLKmode value from
12082 an integer-mode (e.g., SImode) object. Handle this case
12083 by doing the extract into an object as wide as the field
12084 (which we know to be the width of a basic mode), then
12085 storing into memory, and changing the mode to BLKmode. */
12086 if (mode1
== VOIDmode
12087 || REG_P (op0
) || GET_CODE (op0
) == SUBREG
12088 || (mode1
!= BLKmode
&& ! direct_load
[(int) mode1
]
12089 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
12090 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
12091 && modifier
!= EXPAND_CONST_ADDRESS
12092 && modifier
!= EXPAND_INITIALIZER
12093 && modifier
!= EXPAND_MEMORY
)
12094 /* If the bitfield is volatile and the bitsize
12095 is narrower than the access size of the bitfield,
12096 we need to extract bitfields from the access. */
12097 || (volatilep
&& TREE_CODE (exp
) == COMPONENT_REF
12098 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp
, 1))
12099 && mode1
!= BLKmode
12100 && maybe_lt (bitsize
, GET_MODE_SIZE (mode1
) * BITS_PER_UNIT
))
12101 /* If the field isn't aligned enough to fetch as a memref,
12102 fetch it as a bit field. */
12103 || (mode1
!= BLKmode
12105 ? MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode1
)
12106 || !multiple_p (bitpos
, GET_MODE_ALIGNMENT (mode1
))
12107 : TYPE_ALIGN (TREE_TYPE (tem
)) < GET_MODE_ALIGNMENT (mode
)
12108 || !multiple_p (bitpos
, GET_MODE_ALIGNMENT (mode
)))
12109 && modifier
!= EXPAND_MEMORY
12110 && ((modifier
== EXPAND_CONST_ADDRESS
12111 || modifier
== EXPAND_INITIALIZER
)
12113 : targetm
.slow_unaligned_access (mode1
,
12115 || !multiple_p (bitpos
, BITS_PER_UNIT
)))
12116 /* If the type and the field are a constant size and the
12117 size of the type isn't the same size as the bitfield,
12118 we must use bitfield operations. */
12119 || (known_size_p (bitsize
)
12120 && TYPE_SIZE (TREE_TYPE (exp
))
12121 && poly_int_tree_p (TYPE_SIZE (TREE_TYPE (exp
)))
12122 && maybe_ne (wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (exp
))),
12125 machine_mode ext_mode
= mode
;
12127 if (ext_mode
== BLKmode
12128 && ! (target
!= 0 && MEM_P (op0
)
12130 && multiple_p (bitpos
, BITS_PER_UNIT
)))
12131 ext_mode
= int_mode_for_size (bitsize
, 1).else_blk ();
12133 if (ext_mode
== BLKmode
)
12136 target
= assign_temp (type
, 1, 1);
12138 /* ??? Unlike the similar test a few lines below, this one is
12139 very likely obsolete. */
12140 if (known_eq (bitsize
, 0))
12143 /* In this case, BITPOS must start at a byte boundary and
12144 TARGET, if specified, must be a MEM. */
12145 gcc_assert (MEM_P (op0
)
12146 && (!target
|| MEM_P (target
)));
12148 bytepos
= exact_div (bitpos
, BITS_PER_UNIT
);
12149 poly_int64 bytesize
= bits_to_bytes_round_up (bitsize
);
12150 emit_block_move (target
,
12151 adjust_address (op0
, VOIDmode
, bytepos
),
12152 gen_int_mode (bytesize
, Pmode
),
12153 (modifier
== EXPAND_STACK_PARM
12154 ? BLOCK_OP_CALL_PARM
: BLOCK_OP_NORMAL
));
12159 /* If we have nothing to extract, the result will be 0 for targets
12160 with SHIFT_COUNT_TRUNCATED == 0 and garbage otherwise. Always
12161 return 0 for the sake of consistency, as reading a zero-sized
12162 bitfield is valid in Ada and the value is fully specified. */
12163 if (known_eq (bitsize
, 0))
12166 op0
= validize_mem (op0
);
12168 if (MEM_P (op0
) && REG_P (XEXP (op0
, 0)))
12169 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
12171 /* If the result has aggregate type and the extraction is done in
12172 an integral mode, then the field may be not aligned on a byte
12173 boundary; in this case, if it has reverse storage order, it
12174 needs to be extracted as a scalar field with reverse storage
12175 order and put back into memory order afterwards. */
12176 if (AGGREGATE_TYPE_P (type
)
12177 && GET_MODE_CLASS (ext_mode
) == MODE_INT
)
12178 reversep
= TYPE_REVERSE_STORAGE_ORDER (type
);
12180 gcc_checking_assert (known_ge (bitpos
, 0));
12181 op0
= extract_bit_field (op0
, bitsize
, bitpos
, unsignedp
,
12182 (modifier
== EXPAND_STACK_PARM
12183 ? NULL_RTX
: target
),
12184 ext_mode
, ext_mode
, reversep
, alt_rtl
);
12186 /* If the result has aggregate type and the mode of OP0 is an
12187 integral mode then, if BITSIZE is narrower than this mode
12188 and this is for big-endian data, we must put the field
12189 into the high-order bits. And we must also put it back
12190 into memory order if it has been previously reversed. */
12191 scalar_int_mode op0_mode
;
12192 if (AGGREGATE_TYPE_P (type
)
12193 && is_int_mode (GET_MODE (op0
), &op0_mode
))
12195 HOST_WIDE_INT size
= GET_MODE_BITSIZE (op0_mode
);
12197 gcc_checking_assert (known_le (bitsize
, size
));
12198 if (maybe_lt (bitsize
, size
)
12199 && reversep
? !BYTES_BIG_ENDIAN
: BYTES_BIG_ENDIAN
)
12200 op0
= expand_shift (LSHIFT_EXPR
, op0_mode
, op0
,
12201 size
- bitsize
, op0
, 1);
12204 op0
= flip_storage_order (op0_mode
, op0
);
12207 /* If the result type is BLKmode, store the data into a temporary
12208 of the appropriate type, but with the mode corresponding to the
12209 mode for the data we have (op0's mode). */
12210 if (mode
== BLKmode
)
12213 = assign_stack_temp_for_type (ext_mode
,
12214 GET_MODE_BITSIZE (ext_mode
),
12216 emit_move_insn (new_rtx
, op0
);
12217 op0
= copy_rtx (new_rtx
);
12218 PUT_MODE (op0
, BLKmode
);
12224 /* If the result is BLKmode, use that to access the object
12226 if (mode
== BLKmode
)
12229 /* Get a reference to just this component. */
12230 bytepos
= bits_to_bytes_round_down (bitpos
);
12231 if (modifier
== EXPAND_CONST_ADDRESS
12232 || modifier
== EXPAND_SUM
|| modifier
== EXPAND_INITIALIZER
)
12233 op0
= adjust_address_nv (op0
, mode1
, bytepos
);
12235 op0
= adjust_address (op0
, mode1
, bytepos
);
12237 if (op0
== orig_op0
)
12238 op0
= copy_rtx (op0
);
12240 /* Don't set memory attributes if the base expression is
12241 SSA_NAME that got expanded as a MEM or a CONSTANT. In that case,
12242 we should just honor its original memory attributes. */
12243 if (!(TREE_CODE (tem
) == SSA_NAME
12244 && (MEM_P (orig_op0
) || CONSTANT_P (orig_op0
))))
12245 set_mem_attributes (op0
, exp
, 0);
12247 if (REG_P (XEXP (op0
, 0)))
12248 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
12250 /* If op0 is a temporary because the original expressions was forced
12251 to memory, clear MEM_EXPR so that the original expression cannot
12252 be marked as addressable through MEM_EXPR of the temporary. */
12253 if (clear_mem_expr
)
12254 set_mem_expr (op0
, NULL_TREE
);
12256 MEM_VOLATILE_P (op0
) |= volatilep
;
12259 && modifier
!= EXPAND_MEMORY
12260 && modifier
!= EXPAND_WRITE
)
12261 op0
= flip_storage_order (mode1
, op0
);
12263 op0
= EXTEND_BITINT (op0
);
12265 if (mode
== mode1
|| mode1
== BLKmode
|| mode1
== tmode
12266 || modifier
== EXPAND_CONST_ADDRESS
12267 || modifier
== EXPAND_INITIALIZER
)
12271 target
= gen_reg_rtx (tmode
!= VOIDmode
? tmode
: mode
);
12273 convert_move (target
, op0
, unsignedp
);
12278 return expand_expr (OBJ_TYPE_REF_EXPR (exp
), target
, tmode
, modifier
);
12281 /* All valid uses of __builtin_va_arg_pack () are removed during
12283 if (CALL_EXPR_VA_ARG_PACK (exp
))
12284 error ("invalid use of %<__builtin_va_arg_pack ()%>");
12286 tree fndecl
= get_callee_fndecl (exp
), attr
;
12289 /* Don't diagnose the error attribute in thunks, those are
12290 artificially created. */
12291 && !CALL_FROM_THUNK_P (exp
)
12292 && (attr
= lookup_attribute ("error",
12293 DECL_ATTRIBUTES (fndecl
))) != NULL
)
12295 const char *ident
= lang_hooks
.decl_printable_name (fndecl
, 1);
12296 error ("call to %qs declared with attribute error: %s",
12297 identifier_to_locale (ident
),
12298 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
12301 /* Don't diagnose the warning attribute in thunks, those are
12302 artificially created. */
12303 && !CALL_FROM_THUNK_P (exp
)
12304 && (attr
= lookup_attribute ("warning",
12305 DECL_ATTRIBUTES (fndecl
))) != NULL
)
12307 const char *ident
= lang_hooks
.decl_printable_name (fndecl
, 1);
12308 warning_at (EXPR_LOCATION (exp
),
12309 OPT_Wattribute_warning
,
12310 "call to %qs declared with attribute warning: %s",
12311 identifier_to_locale (ident
),
12312 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
))));
12315 /* Check for a built-in function. */
12316 if (fndecl
&& fndecl_built_in_p (fndecl
))
12318 gcc_assert (DECL_BUILT_IN_CLASS (fndecl
) != BUILT_IN_FRONTEND
);
12319 return expand_builtin (exp
, target
, subtarget
, tmode
, ignore
);
12322 return expand_call (exp
, target
, ignore
);
12324 case VIEW_CONVERT_EXPR
:
12327 /* If we are converting to BLKmode, try to avoid an intermediate
12328 temporary by fetching an inner memory reference. */
12329 if (mode
== BLKmode
12330 && poly_int_tree_p (TYPE_SIZE (type
))
12331 && TYPE_MODE (TREE_TYPE (treeop0
)) != BLKmode
12332 && handled_component_p (treeop0
))
12334 machine_mode mode1
;
12335 poly_int64 bitsize
, bitpos
, bytepos
;
12337 int reversep
, volatilep
= 0;
12339 = get_inner_reference (treeop0
, &bitsize
, &bitpos
, &offset
, &mode1
,
12340 &unsignedp
, &reversep
, &volatilep
);
12342 /* ??? We should work harder and deal with non-zero offsets. */
12344 && multiple_p (bitpos
, BITS_PER_UNIT
, &bytepos
)
12346 && known_size_p (bitsize
)
12347 && known_eq (wi::to_poly_offset (TYPE_SIZE (type
)), bitsize
))
12349 /* See the normal_inner_ref case for the rationale. */
12351 = expand_expr_real (tem
,
12352 (TREE_CODE (TREE_TYPE (tem
)) == UNION_TYPE
12353 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem
)))
12355 && modifier
!= EXPAND_STACK_PARM
12356 ? target
: NULL_RTX
),
12358 modifier
== EXPAND_SUM
? EXPAND_NORMAL
: modifier
,
12361 if (MEM_P (orig_op0
))
12365 /* Get a reference to just this component. */
12366 if (modifier
== EXPAND_CONST_ADDRESS
12367 || modifier
== EXPAND_SUM
12368 || modifier
== EXPAND_INITIALIZER
)
12369 op0
= adjust_address_nv (op0
, mode
, bytepos
);
12371 op0
= adjust_address (op0
, mode
, bytepos
);
12373 if (op0
== orig_op0
)
12374 op0
= copy_rtx (op0
);
12376 set_mem_attributes (op0
, treeop0
, 0);
12377 if (REG_P (XEXP (op0
, 0)))
12378 mark_reg_pointer (XEXP (op0
, 0), MEM_ALIGN (op0
));
12380 MEM_VOLATILE_P (op0
) |= volatilep
;
12386 op0
= expand_expr_real (treeop0
, NULL_RTX
, VOIDmode
, modifier
,
12387 NULL
, inner_reference_p
);
12389 /* If the input and output modes are both the same, we are done. */
12390 if (mode
== GET_MODE (op0
))
12392 /* If neither mode is BLKmode, and both modes are the same size
12393 then we can use gen_lowpart. */
12394 else if (mode
!= BLKmode
12395 && GET_MODE (op0
) != BLKmode
12396 && known_eq (GET_MODE_PRECISION (mode
),
12397 GET_MODE_PRECISION (GET_MODE (op0
)))
12398 && !COMPLEX_MODE_P (GET_MODE (op0
)))
12400 if (GET_CODE (op0
) == SUBREG
)
12401 op0
= force_reg (GET_MODE (op0
), op0
);
12402 temp
= gen_lowpart_common (mode
, op0
);
12407 if (!REG_P (op0
) && !MEM_P (op0
))
12408 op0
= force_reg (GET_MODE (op0
), op0
);
12409 op0
= gen_lowpart (mode
, op0
);
12412 /* If both types are integral, convert from one mode to the other. */
12413 else if (INTEGRAL_TYPE_P (type
) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0
)))
12414 op0
= convert_modes (mode
, GET_MODE (op0
), op0
,
12415 TYPE_UNSIGNED (TREE_TYPE (treeop0
)));
12416 /* If the output type is a bit-field type, do an extraction. */
12417 else if (reduce_bit_field
)
12418 return extract_bit_field (op0
, TYPE_PRECISION (type
), 0,
12419 TYPE_UNSIGNED (type
), NULL_RTX
,
12420 mode
, mode
, false, NULL
);
12421 /* As a last resort, spill op0 to memory, and reload it in a
12423 else if (!MEM_P (op0
))
12425 /* If the operand is not a MEM, force it into memory. Since we
12426 are going to be changing the mode of the MEM, don't call
12427 force_const_mem for constants because we don't allow pool
12428 constants to change mode. */
12429 tree inner_type
= TREE_TYPE (treeop0
);
12431 gcc_assert (!TREE_ADDRESSABLE (exp
));
12433 if (target
== 0 || GET_MODE (target
) != TYPE_MODE (inner_type
))
12435 = assign_stack_temp_for_type
12436 (TYPE_MODE (inner_type
),
12437 GET_MODE_SIZE (TYPE_MODE (inner_type
)), inner_type
);
12439 emit_move_insn (target
, op0
);
12443 /* If OP0 is (now) a MEM, we need to deal with alignment issues. If the
12444 output type is such that the operand is known to be aligned, indicate
12445 that it is. Otherwise, we need only be concerned about alignment for
12446 non-BLKmode results. */
12449 enum insn_code icode
;
12451 if (modifier
!= EXPAND_WRITE
12452 && modifier
!= EXPAND_MEMORY
12453 && !inner_reference_p
12455 && MEM_ALIGN (op0
) < GET_MODE_ALIGNMENT (mode
))
12457 /* If the target does have special handling for unaligned
12458 loads of mode then use them. */
12459 if ((icode
= optab_handler (movmisalign_optab
, mode
))
12460 != CODE_FOR_nothing
)
12464 op0
= adjust_address (op0
, mode
, 0);
12465 /* We've already validated the memory, and we're creating a
12466 new pseudo destination. The predicates really can't
12468 reg
= gen_reg_rtx (mode
);
12470 /* Nor can the insn generator. */
12471 rtx_insn
*insn
= GEN_FCN (icode
) (reg
, op0
);
12475 else if (STRICT_ALIGNMENT
)
12477 poly_uint64 mode_size
= GET_MODE_SIZE (mode
);
12478 poly_uint64 temp_size
= mode_size
;
12479 if (GET_MODE (op0
) != BLKmode
)
12480 temp_size
= upper_bound (temp_size
,
12481 GET_MODE_SIZE (GET_MODE (op0
)));
12483 = assign_stack_temp_for_type (mode
, temp_size
, type
);
12484 rtx new_with_op0_mode
12485 = adjust_address (new_rtx
, GET_MODE (op0
), 0);
12487 gcc_assert (!TREE_ADDRESSABLE (exp
));
12489 if (GET_MODE (op0
) == BLKmode
)
12491 rtx size_rtx
= gen_int_mode (mode_size
, Pmode
);
12492 emit_block_move (new_with_op0_mode
, op0
, size_rtx
,
12493 (modifier
== EXPAND_STACK_PARM
12494 ? BLOCK_OP_CALL_PARM
12495 : BLOCK_OP_NORMAL
));
12498 emit_move_insn (new_with_op0_mode
, op0
);
12504 op0
= adjust_address (op0
, mode
, 0);
12511 tree lhs
= treeop0
;
12512 tree rhs
= treeop1
;
12513 gcc_assert (ignore
);
12515 /* Check for |= or &= of a bitfield of size one into another bitfield
12516 of size 1. In this case, (unless we need the result of the
12517 assignment) we can do this more efficiently with a
12518 test followed by an assignment, if necessary.
12520 ??? At this point, we can't get a BIT_FIELD_REF here. But if
12521 things change so we do, this code should be enhanced to
12523 if (TREE_CODE (lhs
) == COMPONENT_REF
12524 && (TREE_CODE (rhs
) == BIT_IOR_EXPR
12525 || TREE_CODE (rhs
) == BIT_AND_EXPR
)
12526 && TREE_OPERAND (rhs
, 0) == lhs
12527 && TREE_CODE (TREE_OPERAND (rhs
, 1)) == COMPONENT_REF
12528 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs
, 1)))
12529 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs
, 1), 1))))
12531 rtx_code_label
*label
= gen_label_rtx ();
12532 int value
= TREE_CODE (rhs
) == BIT_IOR_EXPR
;
12533 profile_probability prob
= profile_probability::uninitialized ();
12535 jumpifnot (TREE_OPERAND (rhs
, 1), label
, prob
);
12537 jumpif (TREE_OPERAND (rhs
, 1), label
, prob
);
12538 expand_assignment (lhs
, build_int_cst (TREE_TYPE (rhs
), value
),
12540 do_pending_stack_adjust ();
12541 emit_label (label
);
12545 expand_assignment (lhs
, rhs
, false);
12550 return expand_expr_addr_expr (exp
, target
, tmode
, modifier
);
12552 case REALPART_EXPR
:
12553 op0
= expand_normal (treeop0
);
12554 return read_complex_part (op0
, false);
12556 case IMAGPART_EXPR
:
12557 op0
= expand_normal (treeop0
);
12558 return read_complex_part (op0
, true);
12565 /* Expanded in cfgexpand.cc. */
12566 gcc_unreachable ();
12568 case TRY_CATCH_EXPR
:
12570 case EH_FILTER_EXPR
:
12571 case TRY_FINALLY_EXPR
:
12573 /* Lowered by tree-eh.cc. */
12574 gcc_unreachable ();
12576 case WITH_CLEANUP_EXPR
:
12577 case CLEANUP_POINT_EXPR
:
12579 case CASE_LABEL_EXPR
:
12584 case COMPOUND_EXPR
:
12585 case PREINCREMENT_EXPR
:
12586 case PREDECREMENT_EXPR
:
12587 case POSTINCREMENT_EXPR
:
12588 case POSTDECREMENT_EXPR
:
12591 case COMPOUND_LITERAL_EXPR
:
12592 /* Lowered by gimplify.cc. */
12593 gcc_unreachable ();
12596 /* Function descriptors are not valid except for as
12597 initialization constants, and should not be expanded. */
12598 gcc_unreachable ();
12600 case WITH_SIZE_EXPR
:
12601 /* WITH_SIZE_EXPR expands to its first argument. The caller should
12602 have pulled out the size to use in whatever context it needed. */
12603 return expand_expr_real (treeop0
, original_target
, tmode
,
12604 modifier
, alt_rtl
, inner_reference_p
);
12607 return expand_expr_real_2 (&ops
, target
, tmode
, modifier
);
12610 #undef EXTEND_BITINT
12612 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
12613 signedness of TYPE), possibly returning the result in TARGET.
12614 TYPE is known to be a partial integer type. */
12616 reduce_to_bit_field_precision (rtx exp
, rtx target
, tree type
)
12618 scalar_int_mode mode
= SCALAR_INT_TYPE_MODE (type
);
12619 HOST_WIDE_INT prec
= TYPE_PRECISION (type
);
12620 gcc_assert ((GET_MODE (exp
) == VOIDmode
|| GET_MODE (exp
) == mode
)
12621 && (!target
|| GET_MODE (target
) == mode
));
12623 /* For constant values, reduce using wide_int_to_tree. */
12624 if (poly_int_rtx_p (exp
))
12626 auto value
= wi::to_poly_wide (exp
, mode
);
12627 tree t
= wide_int_to_tree (type
, value
);
12628 return expand_expr (t
, target
, VOIDmode
, EXPAND_NORMAL
);
12630 else if (TYPE_UNSIGNED (type
))
12632 rtx mask
= immed_wide_int_const
12633 (wi::mask (prec
, false, GET_MODE_PRECISION (mode
)), mode
);
12634 return expand_and (mode
, exp
, mask
, target
);
12638 int count
= GET_MODE_PRECISION (mode
) - prec
;
12639 exp
= expand_shift (LSHIFT_EXPR
, mode
, exp
, count
, target
, 0);
12640 return expand_shift (RSHIFT_EXPR
, mode
, exp
, count
, target
, 0);
12644 /* Subroutine of above: returns true if OFFSET corresponds to an offset that
12645 when applied to the address of EXP produces an address known to be
12646 aligned more than BIGGEST_ALIGNMENT. */
12649 is_aligning_offset (const_tree offset
, const_tree exp
)
12651 /* Strip off any conversions. */
12652 while (CONVERT_EXPR_P (offset
))
12653 offset
= TREE_OPERAND (offset
, 0);
12655 /* We must now have a BIT_AND_EXPR with a constant that is one less than
12656 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
12657 if (TREE_CODE (offset
) != BIT_AND_EXPR
12658 || !tree_fits_uhwi_p (TREE_OPERAND (offset
, 1))
12659 || compare_tree_int (TREE_OPERAND (offset
, 1),
12660 BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) <= 0
12661 || !pow2p_hwi (tree_to_uhwi (TREE_OPERAND (offset
, 1)) + 1))
12664 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
12665 It must be NEGATE_EXPR. Then strip any more conversions. */
12666 offset
= TREE_OPERAND (offset
, 0);
12667 while (CONVERT_EXPR_P (offset
))
12668 offset
= TREE_OPERAND (offset
, 0);
12670 if (TREE_CODE (offset
) != NEGATE_EXPR
)
12673 offset
= TREE_OPERAND (offset
, 0);
12674 while (CONVERT_EXPR_P (offset
))
12675 offset
= TREE_OPERAND (offset
, 0);
12677 /* This must now be the address of EXP. */
12678 return TREE_CODE (offset
) == ADDR_EXPR
&& TREE_OPERAND (offset
, 0) == exp
;
12681 /* Return a STRING_CST corresponding to ARG's constant initializer either
12682 if it's a string constant, or, when VALREP is set, any other constant,
12684 On success, set *PTR_OFFSET to the (possibly non-constant) byte offset
12685 within the byte string that ARG is references. If nonnull set *MEM_SIZE
12686 to the size of the byte string. If nonnull, set *DECL to the constant
12687 declaration ARG refers to. */
12690 constant_byte_string (tree arg
, tree
*ptr_offset
, tree
*mem_size
, tree
*decl
,
12691 bool valrep
= false)
12693 tree dummy
= NULL_TREE
;
12697 /* Store the type of the original expression before conversions
12698 via NOP_EXPR or POINTER_PLUS_EXPR to other types have been
12700 tree argtype
= TREE_TYPE (arg
);
12705 /* Non-constant index into the character array in an ARRAY_REF
12706 expression or null. */
12707 tree varidx
= NULL_TREE
;
12709 poly_int64 base_off
= 0;
12711 if (TREE_CODE (arg
) == ADDR_EXPR
)
12713 arg
= TREE_OPERAND (arg
, 0);
12715 if (TREE_CODE (arg
) == ARRAY_REF
)
12717 tree idx
= TREE_OPERAND (arg
, 1);
12718 if (TREE_CODE (idx
) != INTEGER_CST
)
12720 /* From a pointer (but not array) argument extract the variable
12721 index to prevent get_addr_base_and_unit_offset() from failing
12722 due to it. Use it later to compute the non-constant offset
12723 into the string and return it to the caller. */
12725 ref
= TREE_OPERAND (arg
, 0);
12727 if (TREE_CODE (TREE_TYPE (arg
)) == ARRAY_TYPE
)
12730 if (!integer_zerop (array_ref_low_bound (arg
)))
12733 if (!integer_onep (array_ref_element_size (arg
)))
12737 array
= get_addr_base_and_unit_offset (ref
, &base_off
);
12739 || (TREE_CODE (array
) != VAR_DECL
12740 && TREE_CODE (array
) != CONST_DECL
12741 && TREE_CODE (array
) != STRING_CST
))
12744 else if (TREE_CODE (arg
) == PLUS_EXPR
|| TREE_CODE (arg
) == POINTER_PLUS_EXPR
)
12746 tree arg0
= TREE_OPERAND (arg
, 0);
12747 tree arg1
= TREE_OPERAND (arg
, 1);
12750 tree str
= string_constant (arg0
, &offset
, mem_size
, decl
);
12753 str
= string_constant (arg1
, &offset
, mem_size
, decl
);
12759 /* Avoid pointers to arrays (see bug 86622). */
12760 if (POINTER_TYPE_P (TREE_TYPE (arg
))
12761 && TREE_CODE (TREE_TYPE (TREE_TYPE (arg
))) == ARRAY_TYPE
12762 && !(decl
&& !*decl
)
12763 && !(decl
&& tree_fits_uhwi_p (DECL_SIZE_UNIT (*decl
))
12764 && tree_fits_uhwi_p (*mem_size
)
12765 && tree_int_cst_equal (*mem_size
, DECL_SIZE_UNIT (*decl
))))
12768 tree type
= TREE_TYPE (offset
);
12769 arg1
= fold_convert (type
, arg1
);
12770 *ptr_offset
= fold_build2 (PLUS_EXPR
, type
, offset
, arg1
);
12775 else if (TREE_CODE (arg
) == SSA_NAME
)
12777 gimple
*stmt
= SSA_NAME_DEF_STMT (arg
);
12778 if (!is_gimple_assign (stmt
))
12781 tree rhs1
= gimple_assign_rhs1 (stmt
);
12782 tree_code code
= gimple_assign_rhs_code (stmt
);
12783 if (code
== ADDR_EXPR
)
12784 return string_constant (rhs1
, ptr_offset
, mem_size
, decl
);
12785 else if (code
!= POINTER_PLUS_EXPR
)
12789 if (tree str
= string_constant (rhs1
, &offset
, mem_size
, decl
))
12791 /* Avoid pointers to arrays (see bug 86622). */
12792 if (POINTER_TYPE_P (TREE_TYPE (rhs1
))
12793 && TREE_CODE (TREE_TYPE (TREE_TYPE (rhs1
))) == ARRAY_TYPE
12794 && !(decl
&& !*decl
)
12795 && !(decl
&& tree_fits_uhwi_p (DECL_SIZE_UNIT (*decl
))
12796 && tree_fits_uhwi_p (*mem_size
)
12797 && tree_int_cst_equal (*mem_size
, DECL_SIZE_UNIT (*decl
))))
12800 tree rhs2
= gimple_assign_rhs2 (stmt
);
12801 tree type
= TREE_TYPE (offset
);
12802 rhs2
= fold_convert (type
, rhs2
);
12803 *ptr_offset
= fold_build2 (PLUS_EXPR
, type
, offset
, rhs2
);
12808 else if (DECL_P (arg
))
12813 tree offset
= wide_int_to_tree (sizetype
, base_off
);
12816 if (TREE_CODE (TREE_TYPE (array
)) != ARRAY_TYPE
)
12819 gcc_assert (TREE_CODE (arg
) == ARRAY_REF
);
12820 tree chartype
= TREE_TYPE (TREE_TYPE (TREE_OPERAND (arg
, 0)));
12821 if (TREE_CODE (chartype
) != INTEGER_TYPE
)
12824 offset
= fold_convert (sizetype
, varidx
);
12827 if (TREE_CODE (array
) == STRING_CST
)
12829 *ptr_offset
= fold_convert (sizetype
, offset
);
12830 *mem_size
= TYPE_SIZE_UNIT (TREE_TYPE (array
));
12833 gcc_checking_assert (tree_to_shwi (TYPE_SIZE_UNIT (TREE_TYPE (array
)))
12834 >= TREE_STRING_LENGTH (array
));
12838 tree init
= ctor_for_folding (array
);
12839 if (!init
|| init
== error_mark_node
)
12844 HOST_WIDE_INT cstoff
;
12845 if (!base_off
.is_constant (&cstoff
))
12848 /* Check that the host and target are sane. */
12849 if (CHAR_BIT
!= 8 || BITS_PER_UNIT
!= 8)
12852 HOST_WIDE_INT typesz
= int_size_in_bytes (TREE_TYPE (init
));
12853 if (typesz
<= 0 || (int) typesz
!= typesz
)
12856 HOST_WIDE_INT size
= typesz
;
12858 && DECL_SIZE_UNIT (array
)
12859 && tree_fits_shwi_p (DECL_SIZE_UNIT (array
)))
12861 size
= tree_to_shwi (DECL_SIZE_UNIT (array
));
12862 gcc_checking_assert (size
>= typesz
);
12865 /* If value representation was requested convert the initializer
12866 for the whole array or object into a string of bytes forming
12867 its value representation and return it. */
12868 unsigned char *bytes
= XNEWVEC (unsigned char, size
);
12869 int r
= native_encode_initializer (init
, bytes
, size
);
12872 XDELETEVEC (bytes
);
12877 memset (bytes
+ r
, '\0', size
- r
);
12879 const char *p
= reinterpret_cast<const char *>(bytes
);
12880 init
= build_string_literal (size
, p
, char_type_node
);
12881 init
= TREE_OPERAND (init
, 0);
12882 init
= TREE_OPERAND (init
, 0);
12885 *mem_size
= size_int (TREE_STRING_LENGTH (init
));
12886 *ptr_offset
= wide_int_to_tree (ssizetype
, base_off
);
12894 if (TREE_CODE (init
) == CONSTRUCTOR
)
12896 /* Convert the 64-bit constant offset to a wider type to avoid
12897 overflow and use it to obtain the initializer for the subobject
12900 if (!base_off
.is_constant (&wioff
))
12903 wioff
*= BITS_PER_UNIT
;
12904 if (!wi::fits_uhwi_p (wioff
))
12907 base_off
= wioff
.to_uhwi ();
12908 unsigned HOST_WIDE_INT fieldoff
= 0;
12909 init
= fold_ctor_reference (TREE_TYPE (arg
), init
, base_off
, 0, array
,
12911 if (!init
|| init
== error_mark_node
)
12914 HOST_WIDE_INT cstoff
;
12915 if (!base_off
.is_constant (&cstoff
))
12918 cstoff
= (cstoff
- fieldoff
) / BITS_PER_UNIT
;
12919 tree off
= build_int_cst (sizetype
, cstoff
);
12921 offset
= fold_build2 (PLUS_EXPR
, TREE_TYPE (offset
), offset
, off
);
12926 *ptr_offset
= offset
;
12928 tree inittype
= TREE_TYPE (init
);
12930 if (TREE_CODE (init
) == INTEGER_CST
12931 && (TREE_CODE (TREE_TYPE (array
)) == INTEGER_TYPE
12932 || TYPE_MAIN_VARIANT (inittype
) == char_type_node
))
12934 /* Check that the host and target are sane. */
12935 if (CHAR_BIT
!= 8 || BITS_PER_UNIT
!= 8)
12938 /* For a reference to (address of) a single constant character,
12939 store the native representation of the character in CHARBUF.
12940 If the reference is to an element of an array or a member
12941 of a struct, only consider narrow characters until ctors
12942 for wide character arrays are transformed to STRING_CSTs
12943 like those for narrow arrays. */
12944 unsigned char charbuf
[MAX_BITSIZE_MODE_ANY_MODE
/ BITS_PER_UNIT
];
12945 int len
= native_encode_expr (init
, charbuf
, sizeof charbuf
, 0);
12948 /* Construct a string literal with elements of INITTYPE and
12949 the representation above. Then strip
12950 the ADDR_EXPR (ARRAY_REF (...)) around the STRING_CST. */
12951 init
= build_string_literal (len
, (char *)charbuf
, inittype
);
12952 init
= TREE_OPERAND (TREE_OPERAND (init
, 0), 0);
12956 tree initsize
= TYPE_SIZE_UNIT (inittype
);
12958 if (TREE_CODE (init
) == CONSTRUCTOR
&& initializer_zerop (init
))
12960 /* Fold an empty/zero constructor for an implicitly initialized
12961 object or subobject into the empty string. */
12963 /* Determine the character type from that of the original
12965 tree chartype
= argtype
;
12966 if (POINTER_TYPE_P (chartype
))
12967 chartype
= TREE_TYPE (chartype
);
12968 while (TREE_CODE (chartype
) == ARRAY_TYPE
)
12969 chartype
= TREE_TYPE (chartype
);
12971 if (INTEGRAL_TYPE_P (chartype
)
12972 && TYPE_PRECISION (chartype
) == TYPE_PRECISION (char_type_node
))
12974 /* Convert a char array to an empty STRING_CST having an array
12975 of the expected type and size. */
12977 initsize
= integer_zero_node
;
12979 unsigned HOST_WIDE_INT size
= tree_to_uhwi (initsize
);
12980 if (size
> (unsigned HOST_WIDE_INT
) INT_MAX
)
12983 init
= build_string_literal (size
, NULL
, chartype
, size
);
12984 init
= TREE_OPERAND (init
, 0);
12985 init
= TREE_OPERAND (init
, 0);
12987 *ptr_offset
= integer_zero_node
;
12994 if (TREE_CODE (init
) != STRING_CST
)
12997 *mem_size
= initsize
;
12999 gcc_checking_assert (tree_to_shwi (initsize
) >= TREE_STRING_LENGTH (init
));
13004 /* Return STRING_CST if an ARG corresponds to a string constant or zero
13005 if it doesn't. If we return nonzero, set *PTR_OFFSET to the (possibly
13006 non-constant) offset in bytes within the string that ARG is accessing.
13007 If MEM_SIZE is non-zero the storage size of the memory is returned.
13008 If DECL is non-zero the constant declaration is returned if available. */
13011 string_constant (tree arg
, tree
*ptr_offset
, tree
*mem_size
, tree
*decl
)
13013 return constant_byte_string (arg
, ptr_offset
, mem_size
, decl
, false);
13016 /* Similar to string_constant, return a STRING_CST corresponding
13017 to the value representation of the first argument if it's
13021 byte_representation (tree arg
, tree
*ptr_offset
, tree
*mem_size
, tree
*decl
)
13023 return constant_byte_string (arg
, ptr_offset
, mem_size
, decl
, true);
13026 /* Optimize x % C1 == C2 for signed modulo if C1 is a power of two and C2
13027 is non-zero and C3 ((1<<(prec-1)) | (C1 - 1)):
13028 for C2 > 0 to x & C3 == C2
13029 for C2 < 0 to x & C3 == (C2 & C3). */
13031 maybe_optimize_pow2p_mod_cmp (enum tree_code code
, tree
*arg0
, tree
*arg1
)
13033 gimple
*stmt
= get_def_for_expr (*arg0
, TRUNC_MOD_EXPR
);
13034 tree treeop0
= gimple_assign_rhs1 (stmt
);
13035 tree treeop1
= gimple_assign_rhs2 (stmt
);
13036 tree type
= TREE_TYPE (*arg0
);
13037 scalar_int_mode mode
;
13038 if (!is_a
<scalar_int_mode
> (TYPE_MODE (type
), &mode
))
13040 if (GET_MODE_BITSIZE (mode
) != TYPE_PRECISION (type
)
13041 || TYPE_PRECISION (type
) <= 1
13042 || TYPE_UNSIGNED (type
)
13043 /* Signed x % c == 0 should have been optimized into unsigned modulo
13045 || integer_zerop (*arg1
)
13046 /* If c is known to be non-negative, modulo will be expanded as unsigned
13048 || get_range_pos_neg (treeop0
) == 1)
13051 /* x % c == d where d < 0 && d <= -c should be always false. */
13052 if (tree_int_cst_sgn (*arg1
) == -1
13053 && -wi::to_widest (treeop1
) >= wi::to_widest (*arg1
))
13056 int prec
= TYPE_PRECISION (type
);
13057 wide_int w
= wi::to_wide (treeop1
) - 1;
13058 w
|= wi::shifted_mask (0, prec
- 1, true, prec
);
13059 tree c3
= wide_int_to_tree (type
, w
);
13061 if (tree_int_cst_sgn (*arg1
) == -1)
13062 c4
= wide_int_to_tree (type
, w
& wi::to_wide (*arg1
));
13064 rtx op0
= expand_normal (treeop0
);
13065 treeop0
= make_tree (TREE_TYPE (treeop0
), op0
);
13067 bool speed_p
= optimize_insn_for_speed_p ();
13069 do_pending_stack_adjust ();
13071 location_t loc
= gimple_location (stmt
);
13072 struct separate_ops ops
;
13073 ops
.code
= TRUNC_MOD_EXPR
;
13074 ops
.location
= loc
;
13075 ops
.type
= TREE_TYPE (treeop0
);
13078 ops
.op2
= NULL_TREE
;
13080 rtx mor
= expand_expr_real_2 (&ops
, NULL_RTX
, TYPE_MODE (ops
.type
),
13082 rtx_insn
*moinsns
= get_insns ();
13085 unsigned mocost
= seq_cost (moinsns
, speed_p
);
13086 mocost
+= rtx_cost (mor
, mode
, EQ
, 0, speed_p
);
13087 mocost
+= rtx_cost (expand_normal (*arg1
), mode
, EQ
, 1, speed_p
);
13089 ops
.code
= BIT_AND_EXPR
;
13090 ops
.location
= loc
;
13091 ops
.type
= TREE_TYPE (treeop0
);
13094 ops
.op2
= NULL_TREE
;
13096 rtx mur
= expand_expr_real_2 (&ops
, NULL_RTX
, TYPE_MODE (ops
.type
),
13098 rtx_insn
*muinsns
= get_insns ();
13101 unsigned mucost
= seq_cost (muinsns
, speed_p
);
13102 mucost
+= rtx_cost (mur
, mode
, EQ
, 0, speed_p
);
13103 mucost
+= rtx_cost (expand_normal (c4
), mode
, EQ
, 1, speed_p
);
13105 if (mocost
<= mucost
)
13107 emit_insn (moinsns
);
13108 *arg0
= make_tree (TREE_TYPE (*arg0
), mor
);
13112 emit_insn (muinsns
);
13113 *arg0
= make_tree (TREE_TYPE (*arg0
), mur
);
13118 /* Attempt to optimize unsigned (X % C1) == C2 (or (X % C1) != C2).
13120 (X - C2) * C3 <= C4 (or >), where
13121 C3 is modular multiplicative inverse of C1 and 1<<prec and
13122 C4 is ((1<<prec) - 1) / C1 or ((1<<prec) - 1) / C1 - 1 (the latter
13123 if C2 > ((1<<prec) - 1) % C1).
13124 If C1 is even, S = ctz (C1) and C2 is 0, use
13125 ((X * C3) r>> S) <= C4, where C3 is modular multiplicative
13126 inverse of C1>>S and 1<<prec and C4 is (((1<<prec) - 1) / (C1>>S)) >> S.
13128 For signed (X % C1) == 0 if C1 is odd to (all operations in it
13130 (X * C3) + C4 <= 2 * C4, where
13131 C3 is modular multiplicative inverse of (unsigned) C1 and 1<<prec and
13132 C4 is ((1<<(prec - 1) - 1) / C1).
13133 If C1 is even, S = ctz(C1), use
13134 ((X * C3) + C4) r>> S <= (C4 >> (S - 1))
13135 where C3 is modular multiplicative inverse of (unsigned)(C1>>S) and 1<<prec
13136 and C4 is ((1<<(prec - 1) - 1) / (C1>>S)) & (-1<<S).
13138 See the Hacker's Delight book, section 10-17. */
13140 maybe_optimize_mod_cmp (enum tree_code code
, tree
*arg0
, tree
*arg1
)
13142 gcc_checking_assert (code
== EQ_EXPR
|| code
== NE_EXPR
);
13143 gcc_checking_assert (TREE_CODE (*arg1
) == INTEGER_CST
);
13148 gimple
*stmt
= get_def_for_expr (*arg0
, TRUNC_MOD_EXPR
);
13152 tree treeop0
= gimple_assign_rhs1 (stmt
);
13153 tree treeop1
= gimple_assign_rhs2 (stmt
);
13154 if (TREE_CODE (treeop0
) != SSA_NAME
13155 || TREE_CODE (treeop1
) != INTEGER_CST
13156 /* Don't optimize the undefined behavior case x % 0;
13157 x % 1 should have been optimized into zero, punt if
13158 it makes it here for whatever reason;
13159 x % -c should have been optimized into x % c. */
13160 || compare_tree_int (treeop1
, 2) <= 0
13161 /* Likewise x % c == d where d >= c should be always false. */
13162 || tree_int_cst_le (treeop1
, *arg1
))
13165 /* Unsigned x % pow2 is handled right already, for signed
13166 modulo handle it in maybe_optimize_pow2p_mod_cmp. */
13167 if (integer_pow2p (treeop1
))
13168 return maybe_optimize_pow2p_mod_cmp (code
, arg0
, arg1
);
13170 tree type
= TREE_TYPE (*arg0
);
13171 scalar_int_mode mode
;
13172 if (!is_a
<scalar_int_mode
> (TYPE_MODE (type
), &mode
))
13174 if (GET_MODE_BITSIZE (mode
) != TYPE_PRECISION (type
)
13175 || TYPE_PRECISION (type
) <= 1)
13178 signop sgn
= UNSIGNED
;
13179 /* If both operands are known to have the sign bit clear, handle
13180 even the signed modulo case as unsigned. treeop1 is always
13181 positive >= 2, checked above. */
13182 if (!TYPE_UNSIGNED (type
) && get_range_pos_neg (treeop0
) != 1)
13185 if (!TYPE_UNSIGNED (type
))
13187 if (tree_int_cst_sgn (*arg1
) == -1)
13189 type
= unsigned_type_for (type
);
13190 if (!type
|| TYPE_MODE (type
) != TYPE_MODE (TREE_TYPE (*arg0
)))
13194 int prec
= TYPE_PRECISION (type
);
13195 wide_int w
= wi::to_wide (treeop1
);
13196 int shift
= wi::ctz (w
);
13197 /* Unsigned (X % C1) == C2 is equivalent to (X - C2) % C1 == 0 if
13198 C2 <= -1U % C1, because for any Z >= 0U - C2 in that case (Z % C1) != 0.
13199 If C1 is odd, we can handle all cases by subtracting
13200 C4 below. We could handle even the even C1 and C2 > -1U % C1 cases
13201 e.g. by testing for overflow on the subtraction, punt on that for now
13203 if ((sgn
== SIGNED
|| shift
) && !integer_zerop (*arg1
))
13207 wide_int x
= wi::umod_trunc (wi::mask (prec
, false, prec
), w
);
13208 if (wi::gtu_p (wi::to_wide (*arg1
), x
))
13212 imm_use_iterator imm_iter
;
13213 use_operand_p use_p
;
13214 FOR_EACH_IMM_USE_FAST (use_p
, imm_iter
, treeop0
)
13216 gimple
*use_stmt
= USE_STMT (use_p
);
13217 /* Punt if treeop0 is used in the same bb in a division
13218 or another modulo with the same divisor. We should expect
13219 the division and modulo combined together. */
13220 if (use_stmt
== stmt
13221 || gimple_bb (use_stmt
) != gimple_bb (stmt
))
13223 if (!is_gimple_assign (use_stmt
)
13224 || (gimple_assign_rhs_code (use_stmt
) != TRUNC_DIV_EXPR
13225 && gimple_assign_rhs_code (use_stmt
) != TRUNC_MOD_EXPR
))
13227 if (gimple_assign_rhs1 (use_stmt
) != treeop0
13228 || !operand_equal_p (gimple_assign_rhs2 (use_stmt
), treeop1
, 0))
13233 w
= wi::lrshift (w
, shift
);
13234 wide_int a
= wide_int::from (w
, prec
+ 1, UNSIGNED
);
13235 wide_int b
= wi::shifted_mask (prec
, 1, false, prec
+ 1);
13236 wide_int m
= wide_int::from (wi::mod_inv (a
, b
), prec
, UNSIGNED
);
13237 tree c3
= wide_int_to_tree (type
, m
);
13238 tree c5
= NULL_TREE
;
13240 if (sgn
== UNSIGNED
)
13242 d
= wi::divmod_trunc (wi::mask (prec
, false, prec
), w
, UNSIGNED
, &e
);
13243 /* Use <= floor ((1<<prec) - 1) / C1 only if C2 <= ((1<<prec) - 1) % C1,
13244 otherwise use < or subtract one from C4. E.g. for
13245 x % 3U == 0 we transform this into x * 0xaaaaaaab <= 0x55555555, but
13246 x % 3U == 1 already needs to be
13247 (x - 1) * 0xaaaaaaabU <= 0x55555554. */
13248 if (!shift
&& wi::gtu_p (wi::to_wide (*arg1
), e
))
13251 d
= wi::lrshift (d
, shift
);
13255 e
= wi::udiv_trunc (wi::mask (prec
- 1, false, prec
), w
);
13257 d
= wi::lshift (e
, 1);
13260 e
= wi::bit_and (e
, wi::mask (shift
, true, prec
));
13261 d
= wi::lrshift (e
, shift
- 1);
13263 c5
= wide_int_to_tree (type
, e
);
13265 tree c4
= wide_int_to_tree (type
, d
);
13267 rtx op0
= expand_normal (treeop0
);
13268 treeop0
= make_tree (TREE_TYPE (treeop0
), op0
);
13270 bool speed_p
= optimize_insn_for_speed_p ();
13272 do_pending_stack_adjust ();
13274 location_t loc
= gimple_location (stmt
);
13275 struct separate_ops ops
;
13276 ops
.code
= TRUNC_MOD_EXPR
;
13277 ops
.location
= loc
;
13278 ops
.type
= TREE_TYPE (treeop0
);
13281 ops
.op2
= NULL_TREE
;
13283 rtx mor
= expand_expr_real_2 (&ops
, NULL_RTX
, TYPE_MODE (ops
.type
),
13285 rtx_insn
*moinsns
= get_insns ();
13288 unsigned mocost
= seq_cost (moinsns
, speed_p
);
13289 mocost
+= rtx_cost (mor
, mode
, EQ
, 0, speed_p
);
13290 mocost
+= rtx_cost (expand_normal (*arg1
), mode
, EQ
, 1, speed_p
);
13292 tree t
= fold_convert_loc (loc
, type
, treeop0
);
13293 if (!integer_zerop (*arg1
))
13294 t
= fold_build2_loc (loc
, MINUS_EXPR
, type
, t
, fold_convert (type
, *arg1
));
13295 t
= fold_build2_loc (loc
, MULT_EXPR
, type
, t
, c3
);
13297 t
= fold_build2_loc (loc
, PLUS_EXPR
, type
, t
, c5
);
13300 tree s
= build_int_cst (NULL_TREE
, shift
);
13301 t
= fold_build2_loc (loc
, RROTATE_EXPR
, type
, t
, s
);
13305 rtx mur
= expand_normal (t
);
13306 rtx_insn
*muinsns
= get_insns ();
13309 unsigned mucost
= seq_cost (muinsns
, speed_p
);
13310 mucost
+= rtx_cost (mur
, mode
, LE
, 0, speed_p
);
13311 mucost
+= rtx_cost (expand_normal (c4
), mode
, LE
, 1, speed_p
);
13313 if (mocost
<= mucost
)
13315 emit_insn (moinsns
);
13316 *arg0
= make_tree (TREE_TYPE (*arg0
), mor
);
13320 emit_insn (muinsns
);
13321 *arg0
= make_tree (type
, mur
);
13323 return code
== EQ_EXPR
? LE_EXPR
: GT_EXPR
;
13326 /* Optimize x - y < 0 into x < 0 if x - y has undefined overflow. */
13329 maybe_optimize_sub_cmp_0 (enum tree_code code
, tree
*arg0
, tree
*arg1
)
13331 gcc_checking_assert (code
== GT_EXPR
|| code
== GE_EXPR
13332 || code
== LT_EXPR
|| code
== LE_EXPR
);
13333 gcc_checking_assert (integer_zerop (*arg1
));
13338 gimple
*stmt
= get_def_for_expr (*arg0
, MINUS_EXPR
);
13342 tree treeop0
= gimple_assign_rhs1 (stmt
);
13343 tree treeop1
= gimple_assign_rhs2 (stmt
);
13344 if (!TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (treeop0
)))
13347 if (issue_strict_overflow_warning (WARN_STRICT_OVERFLOW_COMPARISON
))
13348 warning_at (gimple_location (stmt
), OPT_Wstrict_overflow
,
13349 "assuming signed overflow does not occur when "
13350 "simplifying %<X - Y %s 0%> to %<X %s Y%>",
13351 op_symbol_code (code
), op_symbol_code (code
));
13358 /* Expand CODE with arguments INNER & (1<<BITNUM) and 0 that represents
13359 a single bit equality/inequality test, returns where the result is located. */
13362 expand_single_bit_test (location_t loc
, enum tree_code code
,
13363 tree inner
, int bitnum
,
13364 tree result_type
, rtx target
,
13367 gcc_assert (code
== NE_EXPR
|| code
== EQ_EXPR
);
13369 tree type
= TREE_TYPE (inner
);
13370 scalar_int_mode operand_mode
= SCALAR_INT_TYPE_MODE (type
);
13372 tree signed_type
, unsigned_type
, intermediate_type
;
13375 /* First, see if we can fold the single bit test into a sign-bit
13377 if (bitnum
== TYPE_PRECISION (type
) - 1
13378 && type_has_mode_precision_p (type
))
13380 tree stype
= signed_type_for (type
);
13381 tree tmp
= fold_build2_loc (loc
, code
== EQ_EXPR
? GE_EXPR
: LT_EXPR
,
13383 fold_convert_loc (loc
, stype
, inner
),
13384 build_int_cst (stype
, 0));
13385 return expand_expr (tmp
, target
, VOIDmode
, EXPAND_NORMAL
);
13388 /* Otherwise we have (A & C) != 0 where C is a single bit,
13389 convert that into ((A >> C2) & 1). Where C2 = log2(C).
13390 Similarly for (A & C) == 0. */
13392 /* If INNER is a right shift of a constant and it plus BITNUM does
13393 not overflow, adjust BITNUM and INNER. */
13394 if ((inner_def
= get_def_for_expr (inner
, RSHIFT_EXPR
))
13395 && TREE_CODE (gimple_assign_rhs2 (inner_def
)) == INTEGER_CST
13396 && bitnum
< TYPE_PRECISION (type
)
13397 && wi::ltu_p (wi::to_wide (gimple_assign_rhs2 (inner_def
)),
13398 TYPE_PRECISION (type
) - bitnum
))
13400 bitnum
+= tree_to_uhwi (gimple_assign_rhs2 (inner_def
));
13401 inner
= gimple_assign_rhs1 (inner_def
);
13404 /* If we are going to be able to omit the AND below, we must do our
13405 operations as unsigned. If we must use the AND, we have a choice.
13406 Normally unsigned is faster, but for some machines signed is. */
13407 ops_unsigned
= (load_extend_op (operand_mode
) == SIGN_EXTEND
13408 && !flag_syntax_only
) ? 0 : 1;
13410 signed_type
= lang_hooks
.types
.type_for_mode (operand_mode
, 0);
13411 unsigned_type
= lang_hooks
.types
.type_for_mode (operand_mode
, 1);
13412 intermediate_type
= ops_unsigned
? unsigned_type
: signed_type
;
13413 inner
= fold_convert_loc (loc
, intermediate_type
, inner
);
13415 rtx inner0
= expand_expr (inner
, NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
13417 if (CONST_SCALAR_INT_P (inner0
))
13419 wide_int t
= rtx_mode_t (inner0
, operand_mode
);
13420 bool setp
= (wi::lrshift (t
, bitnum
) & 1) != 0;
13421 return (setp
^ (code
== EQ_EXPR
)) ? const1_rtx
: const0_rtx
;
13423 int bitpos
= bitnum
;
13425 if (BYTES_BIG_ENDIAN
)
13426 bitpos
= GET_MODE_BITSIZE (operand_mode
) - 1 - bitpos
;
13428 inner0
= extract_bit_field (inner0
, 1, bitpos
, 1, target
,
13429 operand_mode
, mode
, 0, NULL
);
13431 if (code
== EQ_EXPR
)
13432 inner0
= expand_binop (GET_MODE (inner0
), xor_optab
, inner0
, const1_rtx
,
13433 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
13434 if (GET_MODE (inner0
) != mode
)
13436 rtx t
= gen_reg_rtx (mode
);
13437 convert_move (t
, inner0
, 0);
13443 /* Generate code to calculate OPS, and exploded expression
13444 using a store-flag instruction and return an rtx for the result.
13445 OPS reflects a comparison.
13447 If TARGET is nonzero, store the result there if convenient.
13449 Return zero if there is no suitable set-flag instruction
13450 available on this machine.
13452 Once expand_expr has been called on the arguments of the comparison,
13453 we are committed to doing the store flag, since it is not safe to
13454 re-evaluate the expression. We emit the store-flag insn by calling
13455 emit_store_flag, but only expand the arguments if we have a reason
13456 to believe that emit_store_flag will be successful. If we think that
13457 it will, but it isn't, we have to simulate the store-flag with a
13458 set/jump/set sequence. */
13461 do_store_flag (sepops ops
, rtx target
, machine_mode mode
)
13463 enum rtx_code code
;
13464 tree arg0
, arg1
, type
;
13465 machine_mode operand_mode
;
13468 rtx subtarget
= target
;
13469 location_t loc
= ops
->location
;
13474 /* Don't crash if the comparison was erroneous. */
13475 if (arg0
== error_mark_node
|| arg1
== error_mark_node
)
13478 type
= TREE_TYPE (arg0
);
13479 operand_mode
= TYPE_MODE (type
);
13480 unsignedp
= TYPE_UNSIGNED (type
);
13482 /* We won't bother with BLKmode store-flag operations because it would mean
13483 passing a lot of information to emit_store_flag. */
13484 if (operand_mode
== BLKmode
)
13487 /* We won't bother with store-flag operations involving function pointers
13488 when function pointers must be canonicalized before comparisons. */
13489 if (targetm
.have_canonicalize_funcptr_for_compare ()
13490 && ((POINTER_TYPE_P (TREE_TYPE (arg0
))
13491 && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (arg0
))))
13492 || (POINTER_TYPE_P (TREE_TYPE (arg1
))
13493 && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (arg1
))))))
13499 /* For vector typed comparisons emit code to generate the desired
13500 all-ones or all-zeros mask. */
13501 if (VECTOR_TYPE_P (ops
->type
))
13503 tree ifexp
= build2 (ops
->code
, ops
->type
, arg0
, arg1
);
13504 if (VECTOR_BOOLEAN_TYPE_P (ops
->type
)
13505 && expand_vec_cmp_expr_p (TREE_TYPE (arg0
), ops
->type
, ops
->code
))
13506 return expand_vec_cmp_expr (ops
->type
, ifexp
, target
);
13508 gcc_unreachable ();
13511 /* Optimize (x % C1) == C2 or (x % C1) != C2 if it is beneficial
13512 into (x - C2) * C3 < C4. */
13513 if ((ops
->code
== EQ_EXPR
|| ops
->code
== NE_EXPR
)
13514 && TREE_CODE (arg0
) == SSA_NAME
13515 && TREE_CODE (arg1
) == INTEGER_CST
)
13517 enum tree_code new_code
= maybe_optimize_mod_cmp (ops
->code
,
13519 if (new_code
!= ops
->code
)
13521 struct separate_ops nops
= *ops
;
13522 nops
.code
= ops
->code
= new_code
;
13525 nops
.type
= TREE_TYPE (arg0
);
13526 return do_store_flag (&nops
, target
, mode
);
13530 /* Optimize (x - y) < 0 into x < y if x - y has undefined overflow. */
13532 && (ops
->code
== LT_EXPR
|| ops
->code
== LE_EXPR
13533 || ops
->code
== GT_EXPR
|| ops
->code
== GE_EXPR
)
13534 && integer_zerop (arg1
)
13535 && TREE_CODE (arg0
) == SSA_NAME
)
13536 maybe_optimize_sub_cmp_0 (ops
->code
, &arg0
, &arg1
);
13538 /* Get the rtx comparison code to use. We know that EXP is a comparison
13539 operation of some type. Some comparisons against 1 and -1 can be
13540 converted to comparisons with zero. Do so here so that the tests
13541 below will be aware that we have a comparison with zero. These
13542 tests will not catch constants in the first operand, but constants
13543 are rarely passed as the first operand. */
13554 if (integer_onep (arg1
))
13555 arg1
= integer_zero_node
, code
= unsignedp
? LEU
: LE
;
13557 code
= unsignedp
? LTU
: LT
;
13560 if (! unsignedp
&& integer_all_onesp (arg1
))
13561 arg1
= integer_zero_node
, code
= LT
;
13563 code
= unsignedp
? LEU
: LE
;
13566 if (! unsignedp
&& integer_all_onesp (arg1
))
13567 arg1
= integer_zero_node
, code
= GE
;
13569 code
= unsignedp
? GTU
: GT
;
13572 if (integer_onep (arg1
))
13573 arg1
= integer_zero_node
, code
= unsignedp
? GTU
: GT
;
13575 code
= unsignedp
? GEU
: GE
;
13578 case UNORDERED_EXPR
:
13604 gcc_unreachable ();
13607 /* Put a constant second. */
13608 if (TREE_CODE (arg0
) == REAL_CST
|| TREE_CODE (arg0
) == INTEGER_CST
13609 || TREE_CODE (arg0
) == FIXED_CST
)
13611 std::swap (arg0
, arg1
);
13612 code
= swap_condition (code
);
13615 /* If this is an equality or inequality test of a single bit, we can
13616 do this by shifting the bit being tested to the low-order bit and
13617 masking the result with the constant 1. If the condition was EQ,
13618 we xor it with 1. This does not require an scc insn and is faster
13619 than an scc insn even if we have it. */
13621 if ((code
== NE
|| code
== EQ
)
13622 && (integer_zerop (arg1
)
13623 || integer_pow2p (arg1
))
13624 /* vector types are not handled here. */
13625 && TREE_CODE (TREE_TYPE (arg1
)) != VECTOR_TYPE
13626 && (TYPE_PRECISION (ops
->type
) != 1 || TYPE_UNSIGNED (ops
->type
)))
13629 wide_int nz
= tree_nonzero_bits (narg0
);
13630 gimple
*srcstmt
= get_def_for_expr (narg0
, BIT_AND_EXPR
);
13631 /* If the defining statement was (x & POW2), then use that instead of
13632 the non-zero bits. */
13633 if (srcstmt
&& integer_pow2p (gimple_assign_rhs2 (srcstmt
)))
13635 nz
= wi::to_wide (gimple_assign_rhs2 (srcstmt
));
13636 narg0
= gimple_assign_rhs1 (srcstmt
);
13639 if (wi::popcount (nz
) == 1
13640 && (integer_zerop (arg1
)
13641 || wi::to_wide (arg1
) == nz
))
13643 int bitnum
= wi::exact_log2 (nz
);
13644 enum tree_code tcode
= EQ_EXPR
;
13645 if ((code
== NE
) ^ !integer_zerop (arg1
))
13648 type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
13649 return expand_single_bit_test (loc
, tcode
,
13651 bitnum
, type
, target
, mode
);
13656 if (! get_subtarget (target
)
13657 || GET_MODE (subtarget
) != operand_mode
)
13660 expand_operands (arg0
, arg1
, subtarget
, &op0
, &op1
, EXPAND_NORMAL
);
13663 target
= gen_reg_rtx (mode
);
13665 /* Try a cstore if possible. */
13666 return emit_store_flag_force (target
, code
, op0
, op1
,
13667 operand_mode
, unsignedp
,
13668 (TYPE_PRECISION (ops
->type
) == 1
13669 && !TYPE_UNSIGNED (ops
->type
)) ? -1 : 1);
13672 /* Attempt to generate a casesi instruction. Returns true if successful,
13673 false otherwise (i.e. if there is no casesi instruction).
13675 DEFAULT_PROBABILITY is the probability of jumping to the default
13678 try_casesi (tree index_type
, tree index_expr
, tree minval
, tree range
,
13679 rtx table_label
, rtx default_label
, rtx fallback_label
,
13680 profile_probability default_probability
)
13682 class expand_operand ops
[5];
13683 scalar_int_mode index_mode
= SImode
;
13684 rtx op1
, op2
, index
;
13686 if (! targetm
.have_casesi ())
13689 /* The index must be some form of integer. Convert it to SImode. */
13690 scalar_int_mode omode
= SCALAR_INT_TYPE_MODE (index_type
);
13691 if (GET_MODE_BITSIZE (omode
) > GET_MODE_BITSIZE (index_mode
))
13693 rtx rangertx
= expand_normal (range
);
13695 /* We must handle the endpoints in the original mode. */
13696 index_expr
= build2 (MINUS_EXPR
, index_type
,
13697 index_expr
, minval
);
13698 minval
= integer_zero_node
;
13699 index
= expand_normal (index_expr
);
13701 emit_cmp_and_jump_insns (rangertx
, index
, LTU
, NULL_RTX
,
13702 omode
, 1, default_label
,
13703 default_probability
);
13704 /* Now we can safely truncate. */
13705 index
= convert_to_mode (index_mode
, index
, 0);
13709 if (omode
!= index_mode
)
13711 index_type
= lang_hooks
.types
.type_for_mode (index_mode
, 0);
13712 index_expr
= fold_convert (index_type
, index_expr
);
13715 index
= expand_normal (index_expr
);
13718 do_pending_stack_adjust ();
13720 op1
= expand_normal (minval
);
13721 op2
= expand_normal (range
);
13723 create_input_operand (&ops
[0], index
, index_mode
);
13724 create_convert_operand_from_type (&ops
[1], op1
, TREE_TYPE (minval
));
13725 create_convert_operand_from_type (&ops
[2], op2
, TREE_TYPE (range
));
13726 create_fixed_operand (&ops
[3], table_label
);
13727 create_fixed_operand (&ops
[4], (default_label
13729 : fallback_label
));
13730 expand_jump_insn (targetm
.code_for_casesi
, 5, ops
);
13734 /* Attempt to generate a tablejump instruction; same concept. */
13735 /* Subroutine of the next function.
13737 INDEX is the value being switched on, with the lowest value
13738 in the table already subtracted.
13739 MODE is its expected mode (needed if INDEX is constant).
13740 RANGE is the length of the jump table.
13741 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
13743 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
13744 index value is out of range.
13745 DEFAULT_PROBABILITY is the probability of jumping to
13746 the default label. */
13749 do_tablejump (rtx index
, machine_mode mode
, rtx range
, rtx table_label
,
13750 rtx default_label
, profile_probability default_probability
)
13754 if (INTVAL (range
) > cfun
->cfg
->max_jumptable_ents
)
13755 cfun
->cfg
->max_jumptable_ents
= INTVAL (range
);
13757 /* Do an unsigned comparison (in the proper mode) between the index
13758 expression and the value which represents the length of the range.
13759 Since we just finished subtracting the lower bound of the range
13760 from the index expression, this comparison allows us to simultaneously
13761 check that the original index expression value is both greater than
13762 or equal to the minimum value of the range and less than or equal to
13763 the maximum value of the range. */
13766 emit_cmp_and_jump_insns (index
, range
, GTU
, NULL_RTX
, mode
, 1,
13767 default_label
, default_probability
);
13769 /* If index is in range, it must fit in Pmode.
13770 Convert to Pmode so we can index with it. */
13773 unsigned int width
;
13775 /* We know the value of INDEX is between 0 and RANGE. If we have a
13776 sign-extended subreg, and RANGE does not have the sign bit set, then
13777 we have a value that is valid for both sign and zero extension. In
13778 this case, we get better code if we sign extend. */
13779 if (GET_CODE (index
) == SUBREG
13780 && SUBREG_PROMOTED_VAR_P (index
)
13781 && SUBREG_PROMOTED_SIGNED_P (index
)
13782 && ((width
= GET_MODE_PRECISION (as_a
<scalar_int_mode
> (mode
)))
13783 <= HOST_BITS_PER_WIDE_INT
)
13784 && ! (UINTVAL (range
) & (HOST_WIDE_INT_1U
<< (width
- 1))))
13785 index
= convert_to_mode (Pmode
, index
, 0);
13787 index
= convert_to_mode (Pmode
, index
, 1);
13790 /* Don't let a MEM slip through, because then INDEX that comes
13791 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
13792 and break_out_memory_refs will go to work on it and mess it up. */
13793 #ifdef PIC_CASE_VECTOR_ADDRESS
13794 if (flag_pic
&& !REG_P (index
))
13795 index
= copy_to_mode_reg (Pmode
, index
);
13798 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
13799 GET_MODE_SIZE, because this indicates how large insns are. The other
13800 uses should all be Pmode, because they are addresses. This code
13801 could fail if addresses and insns are not the same size. */
13802 index
= simplify_gen_binary (MULT
, Pmode
, index
,
13803 gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE
),
13805 index
= simplify_gen_binary (PLUS
, Pmode
, index
,
13806 gen_rtx_LABEL_REF (Pmode
, table_label
));
13808 #ifdef PIC_CASE_VECTOR_ADDRESS
13810 index
= PIC_CASE_VECTOR_ADDRESS (index
);
13813 index
= memory_address (CASE_VECTOR_MODE
, index
);
13814 temp
= gen_reg_rtx (CASE_VECTOR_MODE
);
13815 vector
= gen_const_mem (CASE_VECTOR_MODE
, index
);
13816 convert_move (temp
, vector
, 0);
13818 emit_jump_insn (targetm
.gen_tablejump (temp
, table_label
));
13820 /* If we are generating PIC code or if the table is PC-relative, the
13821 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
13822 if (! CASE_VECTOR_PC_RELATIVE
&& ! flag_pic
)
13827 try_tablejump (tree index_type
, tree index_expr
, tree minval
, tree range
,
13828 rtx table_label
, rtx default_label
,
13829 profile_probability default_probability
)
13833 if (! targetm
.have_tablejump ())
13836 index_expr
= fold_build2 (MINUS_EXPR
, index_type
,
13837 fold_convert (index_type
, index_expr
),
13838 fold_convert (index_type
, minval
));
13839 index
= expand_normal (index_expr
);
13840 do_pending_stack_adjust ();
13842 do_tablejump (index
, TYPE_MODE (index_type
),
13843 convert_modes (TYPE_MODE (index_type
),
13844 TYPE_MODE (TREE_TYPE (range
)),
13845 expand_normal (range
),
13846 TYPE_UNSIGNED (TREE_TYPE (range
))),
13847 table_label
, default_label
, default_probability
);
13851 /* Return a CONST_VECTOR rtx representing vector mask for
13852 a VECTOR_CST of booleans. */
13854 const_vector_mask_from_tree (tree exp
)
13856 machine_mode mode
= TYPE_MODE (TREE_TYPE (exp
));
13857 machine_mode inner
= GET_MODE_INNER (mode
);
13859 rtx_vector_builder
builder (mode
, VECTOR_CST_NPATTERNS (exp
),
13860 VECTOR_CST_NELTS_PER_PATTERN (exp
));
13861 unsigned int count
= builder
.encoded_nelts ();
13862 for (unsigned int i
= 0; i
< count
; ++i
)
13864 tree elt
= VECTOR_CST_ELT (exp
, i
);
13865 gcc_assert (TREE_CODE (elt
) == INTEGER_CST
);
13866 if (integer_zerop (elt
))
13867 builder
.quick_push (CONST0_RTX (inner
));
13868 else if (integer_onep (elt
)
13869 || integer_minus_onep (elt
))
13870 builder
.quick_push (CONSTM1_RTX (inner
));
13872 gcc_unreachable ();
13874 return builder
.build ();
13877 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
13879 const_vector_from_tree (tree exp
)
13881 machine_mode mode
= TYPE_MODE (TREE_TYPE (exp
));
13883 if (initializer_zerop (exp
))
13884 return CONST0_RTX (mode
);
13886 if (VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (exp
)))
13887 return const_vector_mask_from_tree (exp
);
13889 machine_mode inner
= GET_MODE_INNER (mode
);
13891 rtx_vector_builder
builder (mode
, VECTOR_CST_NPATTERNS (exp
),
13892 VECTOR_CST_NELTS_PER_PATTERN (exp
));
13893 unsigned int count
= builder
.encoded_nelts ();
13894 for (unsigned int i
= 0; i
< count
; ++i
)
13896 tree elt
= VECTOR_CST_ELT (exp
, i
);
13897 if (TREE_CODE (elt
) == REAL_CST
)
13898 builder
.quick_push (const_double_from_real_value (TREE_REAL_CST (elt
),
13900 else if (TREE_CODE (elt
) == FIXED_CST
)
13901 builder
.quick_push (CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt
),
13904 builder
.quick_push (immed_wide_int_const (wi::to_poly_wide (elt
),
13907 return builder
.build ();
13910 /* Build a decl for a personality function given a language prefix. */
13913 build_personality_function (const char *lang
)
13915 const char *unwind_and_version
;
13919 switch (targetm_common
.except_unwind_info (&global_options
))
13924 unwind_and_version
= "_sj0";
13928 unwind_and_version
= "_v0";
13931 unwind_and_version
= "_seh0";
13934 gcc_unreachable ();
13937 name
= ACONCAT (("__", lang
, "_personality", unwind_and_version
, NULL
));
13939 type
= build_function_type_list (unsigned_type_node
,
13940 integer_type_node
, integer_type_node
,
13941 long_long_unsigned_type_node
,
13942 ptr_type_node
, ptr_type_node
, NULL_TREE
);
13943 decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
13944 get_identifier (name
), type
);
13945 DECL_ARTIFICIAL (decl
) = 1;
13946 DECL_EXTERNAL (decl
) = 1;
13947 TREE_PUBLIC (decl
) = 1;
13949 /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
13950 are the flags assigned by targetm.encode_section_info. */
13951 SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl
), 0), NULL
);
13956 /* Extracts the personality function of DECL and returns the corresponding
13960 get_personality_function (tree decl
)
13962 tree personality
= DECL_FUNCTION_PERSONALITY (decl
);
13963 enum eh_personality_kind pk
;
13965 pk
= function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl
));
13966 if (pk
== eh_personality_none
)
13970 && pk
== eh_personality_any
)
13971 personality
= lang_hooks
.eh_personality ();
13973 if (pk
== eh_personality_lang
)
13974 gcc_assert (personality
!= NULL_TREE
);
13976 return XEXP (DECL_RTL (personality
), 0);
13979 /* Returns a tree for the size of EXP in bytes. */
13982 tree_expr_size (const_tree exp
)
13985 && DECL_SIZE_UNIT (exp
) != 0)
13986 return DECL_SIZE_UNIT (exp
);
13988 return size_in_bytes (TREE_TYPE (exp
));
13991 /* Return an rtx for the size in bytes of the value of EXP. */
13994 expr_size (tree exp
)
13998 if (TREE_CODE (exp
) == WITH_SIZE_EXPR
)
13999 size
= TREE_OPERAND (exp
, 1);
14002 size
= tree_expr_size (exp
);
14004 gcc_assert (size
== SUBSTITUTE_PLACEHOLDER_IN_EXPR (size
, exp
));
14007 return expand_expr (size
, NULL_RTX
, TYPE_MODE (sizetype
), EXPAND_NORMAL
);
14010 /* Return a wide integer for the size in bytes of the value of EXP, or -1
14011 if the size can vary or is larger than an integer. */
14014 int_expr_size (const_tree exp
)
14018 if (TREE_CODE (exp
) == WITH_SIZE_EXPR
)
14019 size
= TREE_OPERAND (exp
, 1);
14022 size
= tree_expr_size (exp
);
14026 if (size
== 0 || !tree_fits_shwi_p (size
))
14029 return tree_to_shwi (size
);