* gcc_update: Update for configure.in -> configure.ac.
[official-gcc.git] / gcc / expr.c
bloba04e931acd06fc3cb4dc8bf13c823b23b4c5bb9b
1 /* Convert tree expression to rtl instructions, for GNU compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "machmode.h"
28 #include "real.h"
29 #include "rtl.h"
30 #include "tree.h"
31 #include "flags.h"
32 #include "regs.h"
33 #include "hard-reg-set.h"
34 #include "except.h"
35 #include "function.h"
36 #include "insn-config.h"
37 #include "insn-attr.h"
38 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
39 #include "expr.h"
40 #include "optabs.h"
41 #include "libfuncs.h"
42 #include "recog.h"
43 #include "reload.h"
44 #include "output.h"
45 #include "typeclass.h"
46 #include "toplev.h"
47 #include "ggc.h"
48 #include "langhooks.h"
49 #include "intl.h"
50 #include "tm_p.h"
51 #include "tree-iterator.h"
52 #include "tree-pass.h"
53 #include "tree-flow.h"
54 #include "target.h"
55 #include "timevar.h"
57 /* Decide whether a function's arguments should be processed
58 from first to last or from last to first.
60 They should if the stack and args grow in opposite directions, but
61 only if we have push insns. */
63 #ifdef PUSH_ROUNDING
65 #ifndef PUSH_ARGS_REVERSED
66 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
67 #define PUSH_ARGS_REVERSED /* If it's last to first. */
68 #endif
69 #endif
71 #endif
73 #ifndef STACK_PUSH_CODE
74 #ifdef STACK_GROWS_DOWNWARD
75 #define STACK_PUSH_CODE PRE_DEC
76 #else
77 #define STACK_PUSH_CODE PRE_INC
78 #endif
79 #endif
82 /* If this is nonzero, we do not bother generating VOLATILE
83 around volatile memory references, and we are willing to
84 output indirect addresses. If cse is to follow, we reject
85 indirect addresses so a useful potential cse is generated;
86 if it is used only once, instruction combination will produce
87 the same indirect address eventually. */
88 int cse_not_expected;
90 /* This structure is used by move_by_pieces to describe the move to
91 be performed. */
92 struct move_by_pieces
94 rtx to;
95 rtx to_addr;
96 int autinc_to;
97 int explicit_inc_to;
98 rtx from;
99 rtx from_addr;
100 int autinc_from;
101 int explicit_inc_from;
102 unsigned HOST_WIDE_INT len;
103 HOST_WIDE_INT offset;
104 int reverse;
107 /* This structure is used by store_by_pieces to describe the clear to
108 be performed. */
110 struct store_by_pieces
112 rtx to;
113 rtx to_addr;
114 int autinc_to;
115 int explicit_inc_to;
116 unsigned HOST_WIDE_INT len;
117 HOST_WIDE_INT offset;
118 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode);
119 void *constfundata;
120 int reverse;
123 static unsigned HOST_WIDE_INT move_by_pieces_ninsns (unsigned HOST_WIDE_INT,
124 unsigned int,
125 unsigned int);
126 static void move_by_pieces_1 (rtx (*) (rtx, ...), enum machine_mode,
127 struct move_by_pieces *);
128 static bool block_move_libcall_safe_for_call_parm (void);
129 static bool emit_block_move_via_movmem (rtx, rtx, rtx, unsigned, unsigned, HOST_WIDE_INT);
130 static tree emit_block_move_libcall_fn (int);
131 static void emit_block_move_via_loop (rtx, rtx, rtx, unsigned);
132 static rtx clear_by_pieces_1 (void *, HOST_WIDE_INT, enum machine_mode);
133 static void clear_by_pieces (rtx, unsigned HOST_WIDE_INT, unsigned int);
134 static void store_by_pieces_1 (struct store_by_pieces *, unsigned int);
135 static void store_by_pieces_2 (rtx (*) (rtx, ...), enum machine_mode,
136 struct store_by_pieces *);
137 static tree clear_storage_libcall_fn (int);
138 static rtx compress_float_constant (rtx, rtx);
139 static rtx get_subtarget (rtx);
140 static void store_constructor_field (rtx, unsigned HOST_WIDE_INT,
141 HOST_WIDE_INT, enum machine_mode,
142 tree, tree, int, int);
143 static void store_constructor (tree, rtx, int, HOST_WIDE_INT);
144 static rtx store_field (rtx, HOST_WIDE_INT, HOST_WIDE_INT, enum machine_mode,
145 tree, tree, int);
147 static unsigned HOST_WIDE_INT highest_pow2_factor_for_target (tree, tree);
149 static int is_aligning_offset (tree, tree);
150 static void expand_operands (tree, tree, rtx, rtx*, rtx*,
151 enum expand_modifier);
152 static rtx reduce_to_bit_field_precision (rtx, rtx, tree);
153 static rtx do_store_flag (tree, rtx, enum machine_mode, int);
154 #ifdef PUSH_ROUNDING
155 static void emit_single_push_insn (enum machine_mode, rtx, tree);
156 #endif
157 static void do_tablejump (rtx, enum machine_mode, rtx, rtx, rtx);
158 static rtx const_vector_from_tree (tree);
159 static void write_complex_part (rtx, rtx, bool);
161 /* Record for each mode whether we can move a register directly to or
162 from an object of that mode in memory. If we can't, we won't try
163 to use that mode directly when accessing a field of that mode. */
165 static char direct_load[NUM_MACHINE_MODES];
166 static char direct_store[NUM_MACHINE_MODES];
168 /* Record for each mode whether we can float-extend from memory. */
170 static bool float_extend_from_mem[NUM_MACHINE_MODES][NUM_MACHINE_MODES];
172 /* This macro is used to determine whether move_by_pieces should be called
173 to perform a structure copy. */
174 #ifndef MOVE_BY_PIECES_P
175 #define MOVE_BY_PIECES_P(SIZE, ALIGN) \
176 (move_by_pieces_ninsns (SIZE, ALIGN, MOVE_MAX_PIECES + 1) \
177 < (unsigned int) MOVE_RATIO)
178 #endif
180 /* This macro is used to determine whether clear_by_pieces should be
181 called to clear storage. */
182 #ifndef CLEAR_BY_PIECES_P
183 #define CLEAR_BY_PIECES_P(SIZE, ALIGN) \
184 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
185 < (unsigned int) CLEAR_RATIO)
186 #endif
188 /* This macro is used to determine whether store_by_pieces should be
189 called to "memset" storage with byte values other than zero, or
190 to "memcpy" storage when the source is a constant string. */
191 #ifndef STORE_BY_PIECES_P
192 #define STORE_BY_PIECES_P(SIZE, ALIGN) \
193 (move_by_pieces_ninsns (SIZE, ALIGN, STORE_MAX_PIECES + 1) \
194 < (unsigned int) MOVE_RATIO)
195 #endif
197 /* This array records the insn_code of insns to perform block moves. */
198 enum insn_code movmem_optab[NUM_MACHINE_MODES];
200 /* This array records the insn_code of insns to perform block sets. */
201 enum insn_code setmem_optab[NUM_MACHINE_MODES];
203 /* These arrays record the insn_code of three different kinds of insns
204 to perform block compares. */
205 enum insn_code cmpstr_optab[NUM_MACHINE_MODES];
206 enum insn_code cmpstrn_optab[NUM_MACHINE_MODES];
207 enum insn_code cmpmem_optab[NUM_MACHINE_MODES];
209 /* Synchronization primitives. */
210 enum insn_code sync_add_optab[NUM_MACHINE_MODES];
211 enum insn_code sync_sub_optab[NUM_MACHINE_MODES];
212 enum insn_code sync_ior_optab[NUM_MACHINE_MODES];
213 enum insn_code sync_and_optab[NUM_MACHINE_MODES];
214 enum insn_code sync_xor_optab[NUM_MACHINE_MODES];
215 enum insn_code sync_nand_optab[NUM_MACHINE_MODES];
216 enum insn_code sync_old_add_optab[NUM_MACHINE_MODES];
217 enum insn_code sync_old_sub_optab[NUM_MACHINE_MODES];
218 enum insn_code sync_old_ior_optab[NUM_MACHINE_MODES];
219 enum insn_code sync_old_and_optab[NUM_MACHINE_MODES];
220 enum insn_code sync_old_xor_optab[NUM_MACHINE_MODES];
221 enum insn_code sync_old_nand_optab[NUM_MACHINE_MODES];
222 enum insn_code sync_new_add_optab[NUM_MACHINE_MODES];
223 enum insn_code sync_new_sub_optab[NUM_MACHINE_MODES];
224 enum insn_code sync_new_ior_optab[NUM_MACHINE_MODES];
225 enum insn_code sync_new_and_optab[NUM_MACHINE_MODES];
226 enum insn_code sync_new_xor_optab[NUM_MACHINE_MODES];
227 enum insn_code sync_new_nand_optab[NUM_MACHINE_MODES];
228 enum insn_code sync_compare_and_swap[NUM_MACHINE_MODES];
229 enum insn_code sync_compare_and_swap_cc[NUM_MACHINE_MODES];
230 enum insn_code sync_lock_test_and_set[NUM_MACHINE_MODES];
231 enum insn_code sync_lock_release[NUM_MACHINE_MODES];
233 /* SLOW_UNALIGNED_ACCESS is nonzero if unaligned accesses are very slow. */
235 #ifndef SLOW_UNALIGNED_ACCESS
236 #define SLOW_UNALIGNED_ACCESS(MODE, ALIGN) STRICT_ALIGNMENT
237 #endif
239 /* This is run once per compilation to set up which modes can be used
240 directly in memory and to initialize the block move optab. */
242 void
243 init_expr_once (void)
245 rtx insn, pat;
246 enum machine_mode mode;
247 int num_clobbers;
248 rtx mem, mem1;
249 rtx reg;
251 /* Try indexing by frame ptr and try by stack ptr.
252 It is known that on the Convex the stack ptr isn't a valid index.
253 With luck, one or the other is valid on any machine. */
254 mem = gen_rtx_MEM (VOIDmode, stack_pointer_rtx);
255 mem1 = gen_rtx_MEM (VOIDmode, frame_pointer_rtx);
257 /* A scratch register we can modify in-place below to avoid
258 useless RTL allocations. */
259 reg = gen_rtx_REG (VOIDmode, -1);
261 insn = rtx_alloc (INSN);
262 pat = gen_rtx_SET (0, NULL_RTX, NULL_RTX);
263 PATTERN (insn) = pat;
265 for (mode = VOIDmode; (int) mode < NUM_MACHINE_MODES;
266 mode = (enum machine_mode) ((int) mode + 1))
268 int regno;
270 direct_load[(int) mode] = direct_store[(int) mode] = 0;
271 PUT_MODE (mem, mode);
272 PUT_MODE (mem1, mode);
273 PUT_MODE (reg, mode);
275 /* See if there is some register that can be used in this mode and
276 directly loaded or stored from memory. */
278 if (mode != VOIDmode && mode != BLKmode)
279 for (regno = 0; regno < FIRST_PSEUDO_REGISTER
280 && (direct_load[(int) mode] == 0 || direct_store[(int) mode] == 0);
281 regno++)
283 if (! HARD_REGNO_MODE_OK (regno, mode))
284 continue;
286 REGNO (reg) = regno;
288 SET_SRC (pat) = mem;
289 SET_DEST (pat) = reg;
290 if (recog (pat, insn, &num_clobbers) >= 0)
291 direct_load[(int) mode] = 1;
293 SET_SRC (pat) = mem1;
294 SET_DEST (pat) = reg;
295 if (recog (pat, insn, &num_clobbers) >= 0)
296 direct_load[(int) mode] = 1;
298 SET_SRC (pat) = reg;
299 SET_DEST (pat) = mem;
300 if (recog (pat, insn, &num_clobbers) >= 0)
301 direct_store[(int) mode] = 1;
303 SET_SRC (pat) = reg;
304 SET_DEST (pat) = mem1;
305 if (recog (pat, insn, &num_clobbers) >= 0)
306 direct_store[(int) mode] = 1;
310 mem = gen_rtx_MEM (VOIDmode, gen_rtx_raw_REG (Pmode, 10000));
312 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
313 mode = GET_MODE_WIDER_MODE (mode))
315 enum machine_mode srcmode;
316 for (srcmode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); srcmode != mode;
317 srcmode = GET_MODE_WIDER_MODE (srcmode))
319 enum insn_code ic;
321 ic = can_extend_p (mode, srcmode, 0);
322 if (ic == CODE_FOR_nothing)
323 continue;
325 PUT_MODE (mem, srcmode);
327 if ((*insn_data[ic].operand[1].predicate) (mem, srcmode))
328 float_extend_from_mem[mode][srcmode] = true;
333 /* This is run at the start of compiling a function. */
335 void
336 init_expr (void)
338 cfun->expr = ggc_alloc_cleared (sizeof (struct expr_status));
341 /* Copy data from FROM to TO, where the machine modes are not the same.
342 Both modes may be integer, or both may be floating.
343 UNSIGNEDP should be nonzero if FROM is an unsigned type.
344 This causes zero-extension instead of sign-extension. */
346 void
347 convert_move (rtx to, rtx from, int unsignedp)
349 enum machine_mode to_mode = GET_MODE (to);
350 enum machine_mode from_mode = GET_MODE (from);
351 int to_real = SCALAR_FLOAT_MODE_P (to_mode);
352 int from_real = SCALAR_FLOAT_MODE_P (from_mode);
353 enum insn_code code;
354 rtx libcall;
356 /* rtx code for making an equivalent value. */
357 enum rtx_code equiv_code = (unsignedp < 0 ? UNKNOWN
358 : (unsignedp ? ZERO_EXTEND : SIGN_EXTEND));
361 gcc_assert (to_real == from_real);
363 /* If the source and destination are already the same, then there's
364 nothing to do. */
365 if (to == from)
366 return;
368 /* If FROM is a SUBREG that indicates that we have already done at least
369 the required extension, strip it. We don't handle such SUBREGs as
370 TO here. */
372 if (GET_CODE (from) == SUBREG && SUBREG_PROMOTED_VAR_P (from)
373 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (from)))
374 >= GET_MODE_SIZE (to_mode))
375 && SUBREG_PROMOTED_UNSIGNED_P (from) == unsignedp)
376 from = gen_lowpart (to_mode, from), from_mode = to_mode;
378 gcc_assert (GET_CODE (to) != SUBREG || !SUBREG_PROMOTED_VAR_P (to));
380 if (to_mode == from_mode
381 || (from_mode == VOIDmode && CONSTANT_P (from)))
383 emit_move_insn (to, from);
384 return;
387 if (VECTOR_MODE_P (to_mode) || VECTOR_MODE_P (from_mode))
389 gcc_assert (GET_MODE_BITSIZE (from_mode) == GET_MODE_BITSIZE (to_mode));
391 if (VECTOR_MODE_P (to_mode))
392 from = simplify_gen_subreg (to_mode, from, GET_MODE (from), 0);
393 else
394 to = simplify_gen_subreg (from_mode, to, GET_MODE (to), 0);
396 emit_move_insn (to, from);
397 return;
400 if (GET_CODE (to) == CONCAT && GET_CODE (from) == CONCAT)
402 convert_move (XEXP (to, 0), XEXP (from, 0), unsignedp);
403 convert_move (XEXP (to, 1), XEXP (from, 1), unsignedp);
404 return;
407 if (to_real)
409 rtx value, insns;
410 convert_optab tab;
412 gcc_assert ((GET_MODE_PRECISION (from_mode)
413 != GET_MODE_PRECISION (to_mode))
414 || (DECIMAL_FLOAT_MODE_P (from_mode)
415 != DECIMAL_FLOAT_MODE_P (to_mode)));
417 if (GET_MODE_PRECISION (from_mode) == GET_MODE_PRECISION (to_mode))
418 /* Conversion between decimal float and binary float, same size. */
419 tab = DECIMAL_FLOAT_MODE_P (from_mode) ? trunc_optab : sext_optab;
420 else if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode))
421 tab = sext_optab;
422 else
423 tab = trunc_optab;
425 /* Try converting directly if the insn is supported. */
427 code = tab->handlers[to_mode][from_mode].insn_code;
428 if (code != CODE_FOR_nothing)
430 emit_unop_insn (code, to, from,
431 tab == sext_optab ? FLOAT_EXTEND : FLOAT_TRUNCATE);
432 return;
435 /* Otherwise use a libcall. */
436 libcall = tab->handlers[to_mode][from_mode].libfunc;
438 /* Is this conversion implemented yet? */
439 gcc_assert (libcall);
441 start_sequence ();
442 value = emit_library_call_value (libcall, NULL_RTX, LCT_CONST, to_mode,
443 1, from, from_mode);
444 insns = get_insns ();
445 end_sequence ();
446 emit_libcall_block (insns, to, value,
447 tab == trunc_optab ? gen_rtx_FLOAT_TRUNCATE (to_mode,
448 from)
449 : gen_rtx_FLOAT_EXTEND (to_mode, from));
450 return;
453 /* Handle pointer conversion. */ /* SPEE 900220. */
454 /* Targets are expected to provide conversion insns between PxImode and
455 xImode for all MODE_PARTIAL_INT modes they use, but no others. */
456 if (GET_MODE_CLASS (to_mode) == MODE_PARTIAL_INT)
458 enum machine_mode full_mode
459 = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode), MODE_INT);
461 gcc_assert (trunc_optab->handlers[to_mode][full_mode].insn_code
462 != CODE_FOR_nothing);
464 if (full_mode != from_mode)
465 from = convert_to_mode (full_mode, from, unsignedp);
466 emit_unop_insn (trunc_optab->handlers[to_mode][full_mode].insn_code,
467 to, from, UNKNOWN);
468 return;
470 if (GET_MODE_CLASS (from_mode) == MODE_PARTIAL_INT)
472 rtx new_from;
473 enum machine_mode full_mode
474 = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode), MODE_INT);
476 gcc_assert (sext_optab->handlers[full_mode][from_mode].insn_code
477 != CODE_FOR_nothing);
479 if (to_mode == full_mode)
481 emit_unop_insn (sext_optab->handlers[full_mode][from_mode].insn_code,
482 to, from, UNKNOWN);
483 return;
486 new_from = gen_reg_rtx (full_mode);
487 emit_unop_insn (sext_optab->handlers[full_mode][from_mode].insn_code,
488 new_from, from, UNKNOWN);
490 /* else proceed to integer conversions below. */
491 from_mode = full_mode;
492 from = new_from;
495 /* Now both modes are integers. */
497 /* Handle expanding beyond a word. */
498 if (GET_MODE_BITSIZE (from_mode) < GET_MODE_BITSIZE (to_mode)
499 && GET_MODE_BITSIZE (to_mode) > BITS_PER_WORD)
501 rtx insns;
502 rtx lowpart;
503 rtx fill_value;
504 rtx lowfrom;
505 int i;
506 enum machine_mode lowpart_mode;
507 int nwords = CEIL (GET_MODE_SIZE (to_mode), UNITS_PER_WORD);
509 /* Try converting directly if the insn is supported. */
510 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
511 != CODE_FOR_nothing)
513 /* If FROM is a SUBREG, put it into a register. Do this
514 so that we always generate the same set of insns for
515 better cse'ing; if an intermediate assignment occurred,
516 we won't be doing the operation directly on the SUBREG. */
517 if (optimize > 0 && GET_CODE (from) == SUBREG)
518 from = force_reg (from_mode, from);
519 emit_unop_insn (code, to, from, equiv_code);
520 return;
522 /* Next, try converting via full word. */
523 else if (GET_MODE_BITSIZE (from_mode) < BITS_PER_WORD
524 && ((code = can_extend_p (to_mode, word_mode, unsignedp))
525 != CODE_FOR_nothing))
527 if (REG_P (to))
529 if (reg_overlap_mentioned_p (to, from))
530 from = force_reg (from_mode, from);
531 emit_insn (gen_rtx_CLOBBER (VOIDmode, to));
533 convert_move (gen_lowpart (word_mode, to), from, unsignedp);
534 emit_unop_insn (code, to,
535 gen_lowpart (word_mode, to), equiv_code);
536 return;
539 /* No special multiword conversion insn; do it by hand. */
540 start_sequence ();
542 /* Since we will turn this into a no conflict block, we must ensure
543 that the source does not overlap the target. */
545 if (reg_overlap_mentioned_p (to, from))
546 from = force_reg (from_mode, from);
548 /* Get a copy of FROM widened to a word, if necessary. */
549 if (GET_MODE_BITSIZE (from_mode) < BITS_PER_WORD)
550 lowpart_mode = word_mode;
551 else
552 lowpart_mode = from_mode;
554 lowfrom = convert_to_mode (lowpart_mode, from, unsignedp);
556 lowpart = gen_lowpart (lowpart_mode, to);
557 emit_move_insn (lowpart, lowfrom);
559 /* Compute the value to put in each remaining word. */
560 if (unsignedp)
561 fill_value = const0_rtx;
562 else
564 #ifdef HAVE_slt
565 if (HAVE_slt
566 && insn_data[(int) CODE_FOR_slt].operand[0].mode == word_mode
567 && STORE_FLAG_VALUE == -1)
569 emit_cmp_insn (lowfrom, const0_rtx, NE, NULL_RTX,
570 lowpart_mode, 0);
571 fill_value = gen_reg_rtx (word_mode);
572 emit_insn (gen_slt (fill_value));
574 else
575 #endif
577 fill_value
578 = expand_shift (RSHIFT_EXPR, lowpart_mode, lowfrom,
579 size_int (GET_MODE_BITSIZE (lowpart_mode) - 1),
580 NULL_RTX, 0);
581 fill_value = convert_to_mode (word_mode, fill_value, 1);
585 /* Fill the remaining words. */
586 for (i = GET_MODE_SIZE (lowpart_mode) / UNITS_PER_WORD; i < nwords; i++)
588 int index = (WORDS_BIG_ENDIAN ? nwords - i - 1 : i);
589 rtx subword = operand_subword (to, index, 1, to_mode);
591 gcc_assert (subword);
593 if (fill_value != subword)
594 emit_move_insn (subword, fill_value);
597 insns = get_insns ();
598 end_sequence ();
600 emit_no_conflict_block (insns, to, from, NULL_RTX,
601 gen_rtx_fmt_e (equiv_code, to_mode, copy_rtx (from)));
602 return;
605 /* Truncating multi-word to a word or less. */
606 if (GET_MODE_BITSIZE (from_mode) > BITS_PER_WORD
607 && GET_MODE_BITSIZE (to_mode) <= BITS_PER_WORD)
609 if (!((MEM_P (from)
610 && ! MEM_VOLATILE_P (from)
611 && direct_load[(int) to_mode]
612 && ! mode_dependent_address_p (XEXP (from, 0)))
613 || REG_P (from)
614 || GET_CODE (from) == SUBREG))
615 from = force_reg (from_mode, from);
616 convert_move (to, gen_lowpart (word_mode, from), 0);
617 return;
620 /* Now follow all the conversions between integers
621 no more than a word long. */
623 /* For truncation, usually we can just refer to FROM in a narrower mode. */
624 if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode)
625 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (to_mode),
626 GET_MODE_BITSIZE (from_mode)))
628 if (!((MEM_P (from)
629 && ! MEM_VOLATILE_P (from)
630 && direct_load[(int) to_mode]
631 && ! mode_dependent_address_p (XEXP (from, 0)))
632 || REG_P (from)
633 || GET_CODE (from) == SUBREG))
634 from = force_reg (from_mode, from);
635 if (REG_P (from) && REGNO (from) < FIRST_PSEUDO_REGISTER
636 && ! HARD_REGNO_MODE_OK (REGNO (from), to_mode))
637 from = copy_to_reg (from);
638 emit_move_insn (to, gen_lowpart (to_mode, from));
639 return;
642 /* Handle extension. */
643 if (GET_MODE_BITSIZE (to_mode) > GET_MODE_BITSIZE (from_mode))
645 /* Convert directly if that works. */
646 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
647 != CODE_FOR_nothing)
649 emit_unop_insn (code, to, from, equiv_code);
650 return;
652 else
654 enum machine_mode intermediate;
655 rtx tmp;
656 tree shift_amount;
658 /* Search for a mode to convert via. */
659 for (intermediate = from_mode; intermediate != VOIDmode;
660 intermediate = GET_MODE_WIDER_MODE (intermediate))
661 if (((can_extend_p (to_mode, intermediate, unsignedp)
662 != CODE_FOR_nothing)
663 || (GET_MODE_SIZE (to_mode) < GET_MODE_SIZE (intermediate)
664 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (to_mode),
665 GET_MODE_BITSIZE (intermediate))))
666 && (can_extend_p (intermediate, from_mode, unsignedp)
667 != CODE_FOR_nothing))
669 convert_move (to, convert_to_mode (intermediate, from,
670 unsignedp), unsignedp);
671 return;
674 /* No suitable intermediate mode.
675 Generate what we need with shifts. */
676 shift_amount = build_int_cst (NULL_TREE,
677 GET_MODE_BITSIZE (to_mode)
678 - GET_MODE_BITSIZE (from_mode));
679 from = gen_lowpart (to_mode, force_reg (from_mode, from));
680 tmp = expand_shift (LSHIFT_EXPR, to_mode, from, shift_amount,
681 to, unsignedp);
682 tmp = expand_shift (RSHIFT_EXPR, to_mode, tmp, shift_amount,
683 to, unsignedp);
684 if (tmp != to)
685 emit_move_insn (to, tmp);
686 return;
690 /* Support special truncate insns for certain modes. */
691 if (trunc_optab->handlers[to_mode][from_mode].insn_code != CODE_FOR_nothing)
693 emit_unop_insn (trunc_optab->handlers[to_mode][from_mode].insn_code,
694 to, from, UNKNOWN);
695 return;
698 /* Handle truncation of volatile memrefs, and so on;
699 the things that couldn't be truncated directly,
700 and for which there was no special instruction.
702 ??? Code above formerly short-circuited this, for most integer
703 mode pairs, with a force_reg in from_mode followed by a recursive
704 call to this routine. Appears always to have been wrong. */
705 if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode))
707 rtx temp = force_reg (to_mode, gen_lowpart (to_mode, from));
708 emit_move_insn (to, temp);
709 return;
712 /* Mode combination is not recognized. */
713 gcc_unreachable ();
716 /* Return an rtx for a value that would result
717 from converting X to mode MODE.
718 Both X and MODE may be floating, or both integer.
719 UNSIGNEDP is nonzero if X is an unsigned value.
720 This can be done by referring to a part of X in place
721 or by copying to a new temporary with conversion. */
724 convert_to_mode (enum machine_mode mode, rtx x, int unsignedp)
726 return convert_modes (mode, VOIDmode, x, unsignedp);
729 /* Return an rtx for a value that would result
730 from converting X from mode OLDMODE to mode MODE.
731 Both modes may be floating, or both integer.
732 UNSIGNEDP is nonzero if X is an unsigned value.
734 This can be done by referring to a part of X in place
735 or by copying to a new temporary with conversion.
737 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
740 convert_modes (enum machine_mode mode, enum machine_mode oldmode, rtx x, int unsignedp)
742 rtx temp;
744 /* If FROM is a SUBREG that indicates that we have already done at least
745 the required extension, strip it. */
747 if (GET_CODE (x) == SUBREG && SUBREG_PROMOTED_VAR_P (x)
748 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) >= GET_MODE_SIZE (mode)
749 && SUBREG_PROMOTED_UNSIGNED_P (x) == unsignedp)
750 x = gen_lowpart (mode, x);
752 if (GET_MODE (x) != VOIDmode)
753 oldmode = GET_MODE (x);
755 if (mode == oldmode)
756 return x;
758 /* There is one case that we must handle specially: If we are converting
759 a CONST_INT into a mode whose size is twice HOST_BITS_PER_WIDE_INT and
760 we are to interpret the constant as unsigned, gen_lowpart will do
761 the wrong if the constant appears negative. What we want to do is
762 make the high-order word of the constant zero, not all ones. */
764 if (unsignedp && GET_MODE_CLASS (mode) == MODE_INT
765 && GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT
766 && GET_CODE (x) == CONST_INT && INTVAL (x) < 0)
768 HOST_WIDE_INT val = INTVAL (x);
770 if (oldmode != VOIDmode
771 && HOST_BITS_PER_WIDE_INT > GET_MODE_BITSIZE (oldmode))
773 int width = GET_MODE_BITSIZE (oldmode);
775 /* We need to zero extend VAL. */
776 val &= ((HOST_WIDE_INT) 1 << width) - 1;
779 return immed_double_const (val, (HOST_WIDE_INT) 0, mode);
782 /* We can do this with a gen_lowpart if both desired and current modes
783 are integer, and this is either a constant integer, a register, or a
784 non-volatile MEM. Except for the constant case where MODE is no
785 wider than HOST_BITS_PER_WIDE_INT, we must be narrowing the operand. */
787 if ((GET_CODE (x) == CONST_INT
788 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
789 || (GET_MODE_CLASS (mode) == MODE_INT
790 && GET_MODE_CLASS (oldmode) == MODE_INT
791 && (GET_CODE (x) == CONST_DOUBLE
792 || (GET_MODE_SIZE (mode) <= GET_MODE_SIZE (oldmode)
793 && ((MEM_P (x) && ! MEM_VOLATILE_P (x)
794 && direct_load[(int) mode])
795 || (REG_P (x)
796 && (! HARD_REGISTER_P (x)
797 || HARD_REGNO_MODE_OK (REGNO (x), mode))
798 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (mode),
799 GET_MODE_BITSIZE (GET_MODE (x)))))))))
801 /* ?? If we don't know OLDMODE, we have to assume here that
802 X does not need sign- or zero-extension. This may not be
803 the case, but it's the best we can do. */
804 if (GET_CODE (x) == CONST_INT && oldmode != VOIDmode
805 && GET_MODE_SIZE (mode) > GET_MODE_SIZE (oldmode))
807 HOST_WIDE_INT val = INTVAL (x);
808 int width = GET_MODE_BITSIZE (oldmode);
810 /* We must sign or zero-extend in this case. Start by
811 zero-extending, then sign extend if we need to. */
812 val &= ((HOST_WIDE_INT) 1 << width) - 1;
813 if (! unsignedp
814 && (val & ((HOST_WIDE_INT) 1 << (width - 1))))
815 val |= (HOST_WIDE_INT) (-1) << width;
817 return gen_int_mode (val, mode);
820 return gen_lowpart (mode, x);
823 /* Converting from integer constant into mode is always equivalent to an
824 subreg operation. */
825 if (VECTOR_MODE_P (mode) && GET_MODE (x) == VOIDmode)
827 gcc_assert (GET_MODE_BITSIZE (mode) == GET_MODE_BITSIZE (oldmode));
828 return simplify_gen_subreg (mode, x, oldmode, 0);
831 temp = gen_reg_rtx (mode);
832 convert_move (temp, x, unsignedp);
833 return temp;
836 /* STORE_MAX_PIECES is the number of bytes at a time that we can
837 store efficiently. Due to internal GCC limitations, this is
838 MOVE_MAX_PIECES limited by the number of bytes GCC can represent
839 for an immediate constant. */
841 #define STORE_MAX_PIECES MIN (MOVE_MAX_PIECES, 2 * sizeof (HOST_WIDE_INT))
843 /* Determine whether the LEN bytes can be moved by using several move
844 instructions. Return nonzero if a call to move_by_pieces should
845 succeed. */
848 can_move_by_pieces (unsigned HOST_WIDE_INT len,
849 unsigned int align ATTRIBUTE_UNUSED)
851 return MOVE_BY_PIECES_P (len, align);
854 /* Generate several move instructions to copy LEN bytes from block FROM to
855 block TO. (These are MEM rtx's with BLKmode).
857 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
858 used to push FROM to the stack.
860 ALIGN is maximum stack alignment we can assume.
862 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
863 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
864 stpcpy. */
867 move_by_pieces (rtx to, rtx from, unsigned HOST_WIDE_INT len,
868 unsigned int align, int endp)
870 struct move_by_pieces data;
871 rtx to_addr, from_addr = XEXP (from, 0);
872 unsigned int max_size = MOVE_MAX_PIECES + 1;
873 enum machine_mode mode = VOIDmode, tmode;
874 enum insn_code icode;
876 align = MIN (to ? MEM_ALIGN (to) : align, MEM_ALIGN (from));
878 data.offset = 0;
879 data.from_addr = from_addr;
880 if (to)
882 to_addr = XEXP (to, 0);
883 data.to = to;
884 data.autinc_to
885 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
886 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
887 data.reverse
888 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
890 else
892 to_addr = NULL_RTX;
893 data.to = NULL_RTX;
894 data.autinc_to = 1;
895 #ifdef STACK_GROWS_DOWNWARD
896 data.reverse = 1;
897 #else
898 data.reverse = 0;
899 #endif
901 data.to_addr = to_addr;
902 data.from = from;
903 data.autinc_from
904 = (GET_CODE (from_addr) == PRE_INC || GET_CODE (from_addr) == PRE_DEC
905 || GET_CODE (from_addr) == POST_INC
906 || GET_CODE (from_addr) == POST_DEC);
908 data.explicit_inc_from = 0;
909 data.explicit_inc_to = 0;
910 if (data.reverse) data.offset = len;
911 data.len = len;
913 /* If copying requires more than two move insns,
914 copy addresses to registers (to make displacements shorter)
915 and use post-increment if available. */
916 if (!(data.autinc_from && data.autinc_to)
917 && move_by_pieces_ninsns (len, align, max_size) > 2)
919 /* Find the mode of the largest move... */
920 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
921 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
922 if (GET_MODE_SIZE (tmode) < max_size)
923 mode = tmode;
925 if (USE_LOAD_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_from)
927 data.from_addr = copy_addr_to_reg (plus_constant (from_addr, len));
928 data.autinc_from = 1;
929 data.explicit_inc_from = -1;
931 if (USE_LOAD_POST_INCREMENT (mode) && ! data.autinc_from)
933 data.from_addr = copy_addr_to_reg (from_addr);
934 data.autinc_from = 1;
935 data.explicit_inc_from = 1;
937 if (!data.autinc_from && CONSTANT_P (from_addr))
938 data.from_addr = copy_addr_to_reg (from_addr);
939 if (USE_STORE_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_to)
941 data.to_addr = copy_addr_to_reg (plus_constant (to_addr, len));
942 data.autinc_to = 1;
943 data.explicit_inc_to = -1;
945 if (USE_STORE_POST_INCREMENT (mode) && ! data.reverse && ! data.autinc_to)
947 data.to_addr = copy_addr_to_reg (to_addr);
948 data.autinc_to = 1;
949 data.explicit_inc_to = 1;
951 if (!data.autinc_to && CONSTANT_P (to_addr))
952 data.to_addr = copy_addr_to_reg (to_addr);
955 tmode = mode_for_size (MOVE_MAX_PIECES * BITS_PER_UNIT, MODE_INT, 1);
956 if (align >= GET_MODE_ALIGNMENT (tmode))
957 align = GET_MODE_ALIGNMENT (tmode);
958 else
960 enum machine_mode xmode;
962 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
963 tmode != VOIDmode;
964 xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
965 if (GET_MODE_SIZE (tmode) > MOVE_MAX_PIECES
966 || SLOW_UNALIGNED_ACCESS (tmode, align))
967 break;
969 align = MAX (align, GET_MODE_ALIGNMENT (xmode));
972 /* First move what we can in the largest integer mode, then go to
973 successively smaller modes. */
975 while (max_size > 1)
977 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
978 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
979 if (GET_MODE_SIZE (tmode) < max_size)
980 mode = tmode;
982 if (mode == VOIDmode)
983 break;
985 icode = mov_optab->handlers[(int) mode].insn_code;
986 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
987 move_by_pieces_1 (GEN_FCN (icode), mode, &data);
989 max_size = GET_MODE_SIZE (mode);
992 /* The code above should have handled everything. */
993 gcc_assert (!data.len);
995 if (endp)
997 rtx to1;
999 gcc_assert (!data.reverse);
1000 if (data.autinc_to)
1002 if (endp == 2)
1004 if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
1005 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
1006 else
1007 data.to_addr = copy_addr_to_reg (plus_constant (data.to_addr,
1008 -1));
1010 to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
1011 data.offset);
1013 else
1015 if (endp == 2)
1016 --data.offset;
1017 to1 = adjust_address (data.to, QImode, data.offset);
1019 return to1;
1021 else
1022 return data.to;
1025 /* Return number of insns required to move L bytes by pieces.
1026 ALIGN (in bits) is maximum alignment we can assume. */
1028 static unsigned HOST_WIDE_INT
1029 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l, unsigned int align,
1030 unsigned int max_size)
1032 unsigned HOST_WIDE_INT n_insns = 0;
1033 enum machine_mode tmode;
1035 tmode = mode_for_size (MOVE_MAX_PIECES * BITS_PER_UNIT, MODE_INT, 1);
1036 if (align >= GET_MODE_ALIGNMENT (tmode))
1037 align = GET_MODE_ALIGNMENT (tmode);
1038 else
1040 enum machine_mode tmode, xmode;
1042 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
1043 tmode != VOIDmode;
1044 xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
1045 if (GET_MODE_SIZE (tmode) > MOVE_MAX_PIECES
1046 || SLOW_UNALIGNED_ACCESS (tmode, align))
1047 break;
1049 align = MAX (align, GET_MODE_ALIGNMENT (xmode));
1052 while (max_size > 1)
1054 enum machine_mode mode = VOIDmode;
1055 enum insn_code icode;
1057 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
1058 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
1059 if (GET_MODE_SIZE (tmode) < max_size)
1060 mode = tmode;
1062 if (mode == VOIDmode)
1063 break;
1065 icode = mov_optab->handlers[(int) mode].insn_code;
1066 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
1067 n_insns += l / GET_MODE_SIZE (mode), l %= GET_MODE_SIZE (mode);
1069 max_size = GET_MODE_SIZE (mode);
1072 gcc_assert (!l);
1073 return n_insns;
1076 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
1077 with move instructions for mode MODE. GENFUN is the gen_... function
1078 to make a move insn for that mode. DATA has all the other info. */
1080 static void
1081 move_by_pieces_1 (rtx (*genfun) (rtx, ...), enum machine_mode mode,
1082 struct move_by_pieces *data)
1084 unsigned int size = GET_MODE_SIZE (mode);
1085 rtx to1 = NULL_RTX, from1;
1087 while (data->len >= size)
1089 if (data->reverse)
1090 data->offset -= size;
1092 if (data->to)
1094 if (data->autinc_to)
1095 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
1096 data->offset);
1097 else
1098 to1 = adjust_address (data->to, mode, data->offset);
1101 if (data->autinc_from)
1102 from1 = adjust_automodify_address (data->from, mode, data->from_addr,
1103 data->offset);
1104 else
1105 from1 = adjust_address (data->from, mode, data->offset);
1107 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
1108 emit_insn (gen_add2_insn (data->to_addr,
1109 GEN_INT (-(HOST_WIDE_INT)size)));
1110 if (HAVE_PRE_DECREMENT && data->explicit_inc_from < 0)
1111 emit_insn (gen_add2_insn (data->from_addr,
1112 GEN_INT (-(HOST_WIDE_INT)size)));
1114 if (data->to)
1115 emit_insn ((*genfun) (to1, from1));
1116 else
1118 #ifdef PUSH_ROUNDING
1119 emit_single_push_insn (mode, from1, NULL);
1120 #else
1121 gcc_unreachable ();
1122 #endif
1125 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
1126 emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
1127 if (HAVE_POST_INCREMENT && data->explicit_inc_from > 0)
1128 emit_insn (gen_add2_insn (data->from_addr, GEN_INT (size)));
1130 if (! data->reverse)
1131 data->offset += size;
1133 data->len -= size;
1137 /* Emit code to move a block Y to a block X. This may be done with
1138 string-move instructions, with multiple scalar move instructions,
1139 or with a library call.
1141 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1142 SIZE is an rtx that says how long they are.
1143 ALIGN is the maximum alignment we can assume they have.
1144 METHOD describes what kind of copy this is, and what mechanisms may be used.
1146 Return the address of the new block, if memcpy is called and returns it,
1147 0 otherwise. */
1150 emit_block_move_hints (rtx x, rtx y, rtx size, enum block_op_methods method,
1151 unsigned int expected_align, HOST_WIDE_INT expected_size)
1153 bool may_use_call;
1154 rtx retval = 0;
1155 unsigned int align;
1157 switch (method)
1159 case BLOCK_OP_NORMAL:
1160 case BLOCK_OP_TAILCALL:
1161 may_use_call = true;
1162 break;
1164 case BLOCK_OP_CALL_PARM:
1165 may_use_call = block_move_libcall_safe_for_call_parm ();
1167 /* Make inhibit_defer_pop nonzero around the library call
1168 to force it to pop the arguments right away. */
1169 NO_DEFER_POP;
1170 break;
1172 case BLOCK_OP_NO_LIBCALL:
1173 may_use_call = false;
1174 break;
1176 default:
1177 gcc_unreachable ();
1180 align = MIN (MEM_ALIGN (x), MEM_ALIGN (y));
1182 gcc_assert (MEM_P (x));
1183 gcc_assert (MEM_P (y));
1184 gcc_assert (size);
1186 /* Make sure we've got BLKmode addresses; store_one_arg can decide that
1187 block copy is more efficient for other large modes, e.g. DCmode. */
1188 x = adjust_address (x, BLKmode, 0);
1189 y = adjust_address (y, BLKmode, 0);
1191 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1192 can be incorrect is coming from __builtin_memcpy. */
1193 if (GET_CODE (size) == CONST_INT)
1195 if (INTVAL (size) == 0)
1196 return 0;
1198 x = shallow_copy_rtx (x);
1199 y = shallow_copy_rtx (y);
1200 set_mem_size (x, size);
1201 set_mem_size (y, size);
1204 if (GET_CODE (size) == CONST_INT && MOVE_BY_PIECES_P (INTVAL (size), align))
1205 move_by_pieces (x, y, INTVAL (size), align, 0);
1206 else if (emit_block_move_via_movmem (x, y, size, align,
1207 expected_align, expected_size))
1209 else if (may_use_call)
1210 retval = emit_block_move_via_libcall (x, y, size,
1211 method == BLOCK_OP_TAILCALL);
1212 else
1213 emit_block_move_via_loop (x, y, size, align);
1215 if (method == BLOCK_OP_CALL_PARM)
1216 OK_DEFER_POP;
1218 return retval;
1222 emit_block_move (rtx x, rtx y, rtx size, enum block_op_methods method)
1224 return emit_block_move_hints (x, y, size, method, 0, -1);
1227 /* A subroutine of emit_block_move. Returns true if calling the
1228 block move libcall will not clobber any parameters which may have
1229 already been placed on the stack. */
1231 static bool
1232 block_move_libcall_safe_for_call_parm (void)
1234 /* If arguments are pushed on the stack, then they're safe. */
1235 if (PUSH_ARGS)
1236 return true;
1238 /* If registers go on the stack anyway, any argument is sure to clobber
1239 an outgoing argument. */
1240 #if defined (REG_PARM_STACK_SPACE) && defined (OUTGOING_REG_PARM_STACK_SPACE)
1242 tree fn = emit_block_move_libcall_fn (false);
1243 (void) fn;
1244 if (REG_PARM_STACK_SPACE (fn) != 0)
1245 return false;
1247 #endif
1249 /* If any argument goes in memory, then it might clobber an outgoing
1250 argument. */
1252 CUMULATIVE_ARGS args_so_far;
1253 tree fn, arg;
1255 fn = emit_block_move_libcall_fn (false);
1256 INIT_CUMULATIVE_ARGS (args_so_far, TREE_TYPE (fn), NULL_RTX, 0, 3);
1258 arg = TYPE_ARG_TYPES (TREE_TYPE (fn));
1259 for ( ; arg != void_list_node ; arg = TREE_CHAIN (arg))
1261 enum machine_mode mode = TYPE_MODE (TREE_VALUE (arg));
1262 rtx tmp = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
1263 if (!tmp || !REG_P (tmp))
1264 return false;
1265 if (targetm.calls.arg_partial_bytes (&args_so_far, mode, NULL, 1))
1266 return false;
1267 FUNCTION_ARG_ADVANCE (args_so_far, mode, NULL_TREE, 1);
1270 return true;
1273 /* A subroutine of emit_block_move. Expand a movmem pattern;
1274 return true if successful. */
1276 static bool
1277 emit_block_move_via_movmem (rtx x, rtx y, rtx size, unsigned int align,
1278 unsigned int expected_align, HOST_WIDE_INT expected_size)
1280 rtx opalign = GEN_INT (align / BITS_PER_UNIT);
1281 int save_volatile_ok = volatile_ok;
1282 enum machine_mode mode;
1284 if (expected_align < align)
1285 expected_align = align;
1287 /* Since this is a move insn, we don't care about volatility. */
1288 volatile_ok = 1;
1290 /* Try the most limited insn first, because there's no point
1291 including more than one in the machine description unless
1292 the more limited one has some advantage. */
1294 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1295 mode = GET_MODE_WIDER_MODE (mode))
1297 enum insn_code code = movmem_optab[(int) mode];
1298 insn_operand_predicate_fn pred;
1300 if (code != CODE_FOR_nothing
1301 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1302 here because if SIZE is less than the mode mask, as it is
1303 returned by the macro, it will definitely be less than the
1304 actual mode mask. */
1305 && ((GET_CODE (size) == CONST_INT
1306 && ((unsigned HOST_WIDE_INT) INTVAL (size)
1307 <= (GET_MODE_MASK (mode) >> 1)))
1308 || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD)
1309 && ((pred = insn_data[(int) code].operand[0].predicate) == 0
1310 || (*pred) (x, BLKmode))
1311 && ((pred = insn_data[(int) code].operand[1].predicate) == 0
1312 || (*pred) (y, BLKmode))
1313 && ((pred = insn_data[(int) code].operand[3].predicate) == 0
1314 || (*pred) (opalign, VOIDmode)))
1316 rtx op2;
1317 rtx last = get_last_insn ();
1318 rtx pat;
1320 op2 = convert_to_mode (mode, size, 1);
1321 pred = insn_data[(int) code].operand[2].predicate;
1322 if (pred != 0 && ! (*pred) (op2, mode))
1323 op2 = copy_to_mode_reg (mode, op2);
1325 /* ??? When called via emit_block_move_for_call, it'd be
1326 nice if there were some way to inform the backend, so
1327 that it doesn't fail the expansion because it thinks
1328 emitting the libcall would be more efficient. */
1330 if (insn_data[(int) code].n_operands == 4)
1331 pat = GEN_FCN ((int) code) (x, y, op2, opalign);
1332 else
1333 pat = GEN_FCN ((int) code) (x, y, op2, opalign,
1334 GEN_INT (expected_align),
1335 GEN_INT (expected_size));
1336 if (pat)
1338 emit_insn (pat);
1339 volatile_ok = save_volatile_ok;
1340 return true;
1342 else
1343 delete_insns_since (last);
1347 volatile_ok = save_volatile_ok;
1348 return false;
1351 /* A subroutine of emit_block_move. Expand a call to memcpy.
1352 Return the return value from memcpy, 0 otherwise. */
1355 emit_block_move_via_libcall (rtx dst, rtx src, rtx size, bool tailcall)
1357 rtx dst_addr, src_addr;
1358 tree call_expr, arg_list, fn, src_tree, dst_tree, size_tree;
1359 enum machine_mode size_mode;
1360 rtx retval;
1362 /* Emit code to copy the addresses of DST and SRC and SIZE into new
1363 pseudos. We can then place those new pseudos into a VAR_DECL and
1364 use them later. */
1366 dst_addr = copy_to_mode_reg (Pmode, XEXP (dst, 0));
1367 src_addr = copy_to_mode_reg (Pmode, XEXP (src, 0));
1369 dst_addr = convert_memory_address (ptr_mode, dst_addr);
1370 src_addr = convert_memory_address (ptr_mode, src_addr);
1372 dst_tree = make_tree (ptr_type_node, dst_addr);
1373 src_tree = make_tree (ptr_type_node, src_addr);
1375 size_mode = TYPE_MODE (sizetype);
1377 size = convert_to_mode (size_mode, size, 1);
1378 size = copy_to_mode_reg (size_mode, size);
1380 /* It is incorrect to use the libcall calling conventions to call
1381 memcpy in this context. This could be a user call to memcpy and
1382 the user may wish to examine the return value from memcpy. For
1383 targets where libcalls and normal calls have different conventions
1384 for returning pointers, we could end up generating incorrect code. */
1386 size_tree = make_tree (sizetype, size);
1388 fn = emit_block_move_libcall_fn (true);
1389 arg_list = tree_cons (NULL_TREE, size_tree, NULL_TREE);
1390 arg_list = tree_cons (NULL_TREE, src_tree, arg_list);
1391 arg_list = tree_cons (NULL_TREE, dst_tree, arg_list);
1393 /* Now we have to build up the CALL_EXPR itself. */
1394 call_expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (fn)), fn);
1395 call_expr = build3 (CALL_EXPR, TREE_TYPE (TREE_TYPE (fn)),
1396 call_expr, arg_list, NULL_TREE);
1397 CALL_EXPR_TAILCALL (call_expr) = tailcall;
1399 retval = expand_normal (call_expr);
1401 return retval;
1404 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1405 for the function we use for block copies. The first time FOR_CALL
1406 is true, we call assemble_external. */
1408 static GTY(()) tree block_move_fn;
1410 void
1411 init_block_move_fn (const char *asmspec)
1413 if (!block_move_fn)
1415 tree args, fn;
1417 fn = get_identifier ("memcpy");
1418 args = build_function_type_list (ptr_type_node, ptr_type_node,
1419 const_ptr_type_node, sizetype,
1420 NULL_TREE);
1422 fn = build_decl (FUNCTION_DECL, fn, args);
1423 DECL_EXTERNAL (fn) = 1;
1424 TREE_PUBLIC (fn) = 1;
1425 DECL_ARTIFICIAL (fn) = 1;
1426 TREE_NOTHROW (fn) = 1;
1427 DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
1428 DECL_VISIBILITY_SPECIFIED (fn) = 1;
1430 block_move_fn = fn;
1433 if (asmspec)
1434 set_user_assembler_name (block_move_fn, asmspec);
1437 static tree
1438 emit_block_move_libcall_fn (int for_call)
1440 static bool emitted_extern;
1442 if (!block_move_fn)
1443 init_block_move_fn (NULL);
1445 if (for_call && !emitted_extern)
1447 emitted_extern = true;
1448 make_decl_rtl (block_move_fn);
1449 assemble_external (block_move_fn);
1452 return block_move_fn;
1455 /* A subroutine of emit_block_move. Copy the data via an explicit
1456 loop. This is used only when libcalls are forbidden. */
1457 /* ??? It'd be nice to copy in hunks larger than QImode. */
1459 static void
1460 emit_block_move_via_loop (rtx x, rtx y, rtx size,
1461 unsigned int align ATTRIBUTE_UNUSED)
1463 rtx cmp_label, top_label, iter, x_addr, y_addr, tmp;
1464 enum machine_mode iter_mode;
1466 iter_mode = GET_MODE (size);
1467 if (iter_mode == VOIDmode)
1468 iter_mode = word_mode;
1470 top_label = gen_label_rtx ();
1471 cmp_label = gen_label_rtx ();
1472 iter = gen_reg_rtx (iter_mode);
1474 emit_move_insn (iter, const0_rtx);
1476 x_addr = force_operand (XEXP (x, 0), NULL_RTX);
1477 y_addr = force_operand (XEXP (y, 0), NULL_RTX);
1478 do_pending_stack_adjust ();
1480 emit_jump (cmp_label);
1481 emit_label (top_label);
1483 tmp = convert_modes (Pmode, iter_mode, iter, true);
1484 x_addr = gen_rtx_PLUS (Pmode, x_addr, tmp);
1485 y_addr = gen_rtx_PLUS (Pmode, y_addr, tmp);
1486 x = change_address (x, QImode, x_addr);
1487 y = change_address (y, QImode, y_addr);
1489 emit_move_insn (x, y);
1491 tmp = expand_simple_binop (iter_mode, PLUS, iter, const1_rtx, iter,
1492 true, OPTAB_LIB_WIDEN);
1493 if (tmp != iter)
1494 emit_move_insn (iter, tmp);
1496 emit_label (cmp_label);
1498 emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
1499 true, top_label);
1502 /* Copy all or part of a value X into registers starting at REGNO.
1503 The number of registers to be filled is NREGS. */
1505 void
1506 move_block_to_reg (int regno, rtx x, int nregs, enum machine_mode mode)
1508 int i;
1509 #ifdef HAVE_load_multiple
1510 rtx pat;
1511 rtx last;
1512 #endif
1514 if (nregs == 0)
1515 return;
1517 if (CONSTANT_P (x) && ! LEGITIMATE_CONSTANT_P (x))
1518 x = validize_mem (force_const_mem (mode, x));
1520 /* See if the machine can do this with a load multiple insn. */
1521 #ifdef HAVE_load_multiple
1522 if (HAVE_load_multiple)
1524 last = get_last_insn ();
1525 pat = gen_load_multiple (gen_rtx_REG (word_mode, regno), x,
1526 GEN_INT (nregs));
1527 if (pat)
1529 emit_insn (pat);
1530 return;
1532 else
1533 delete_insns_since (last);
1535 #endif
1537 for (i = 0; i < nregs; i++)
1538 emit_move_insn (gen_rtx_REG (word_mode, regno + i),
1539 operand_subword_force (x, i, mode));
1542 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1543 The number of registers to be filled is NREGS. */
1545 void
1546 move_block_from_reg (int regno, rtx x, int nregs)
1548 int i;
1550 if (nregs == 0)
1551 return;
1553 /* See if the machine can do this with a store multiple insn. */
1554 #ifdef HAVE_store_multiple
1555 if (HAVE_store_multiple)
1557 rtx last = get_last_insn ();
1558 rtx pat = gen_store_multiple (x, gen_rtx_REG (word_mode, regno),
1559 GEN_INT (nregs));
1560 if (pat)
1562 emit_insn (pat);
1563 return;
1565 else
1566 delete_insns_since (last);
1568 #endif
1570 for (i = 0; i < nregs; i++)
1572 rtx tem = operand_subword (x, i, 1, BLKmode);
1574 gcc_assert (tem);
1576 emit_move_insn (tem, gen_rtx_REG (word_mode, regno + i));
1580 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1581 ORIG, where ORIG is a non-consecutive group of registers represented by
1582 a PARALLEL. The clone is identical to the original except in that the
1583 original set of registers is replaced by a new set of pseudo registers.
1584 The new set has the same modes as the original set. */
1587 gen_group_rtx (rtx orig)
1589 int i, length;
1590 rtx *tmps;
1592 gcc_assert (GET_CODE (orig) == PARALLEL);
1594 length = XVECLEN (orig, 0);
1595 tmps = alloca (sizeof (rtx) * length);
1597 /* Skip a NULL entry in first slot. */
1598 i = XEXP (XVECEXP (orig, 0, 0), 0) ? 0 : 1;
1600 if (i)
1601 tmps[0] = 0;
1603 for (; i < length; i++)
1605 enum machine_mode mode = GET_MODE (XEXP (XVECEXP (orig, 0, i), 0));
1606 rtx offset = XEXP (XVECEXP (orig, 0, i), 1);
1608 tmps[i] = gen_rtx_EXPR_LIST (VOIDmode, gen_reg_rtx (mode), offset);
1611 return gen_rtx_PARALLEL (GET_MODE (orig), gen_rtvec_v (length, tmps));
1614 /* A subroutine of emit_group_load. Arguments as for emit_group_load,
1615 except that values are placed in TMPS[i], and must later be moved
1616 into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
1618 static void
1619 emit_group_load_1 (rtx *tmps, rtx dst, rtx orig_src, tree type, int ssize)
1621 rtx src;
1622 int start, i;
1623 enum machine_mode m = GET_MODE (orig_src);
1625 gcc_assert (GET_CODE (dst) == PARALLEL);
1627 if (m != VOIDmode
1628 && !SCALAR_INT_MODE_P (m)
1629 && !MEM_P (orig_src)
1630 && GET_CODE (orig_src) != CONCAT)
1632 enum machine_mode imode = int_mode_for_mode (GET_MODE (orig_src));
1633 if (imode == BLKmode)
1634 src = assign_stack_temp (GET_MODE (orig_src), ssize, 0);
1635 else
1636 src = gen_reg_rtx (imode);
1637 if (imode != BLKmode)
1638 src = gen_lowpart (GET_MODE (orig_src), src);
1639 emit_move_insn (src, orig_src);
1640 /* ...and back again. */
1641 if (imode != BLKmode)
1642 src = gen_lowpart (imode, src);
1643 emit_group_load_1 (tmps, dst, src, type, ssize);
1644 return;
1647 /* Check for a NULL entry, used to indicate that the parameter goes
1648 both on the stack and in registers. */
1649 if (XEXP (XVECEXP (dst, 0, 0), 0))
1650 start = 0;
1651 else
1652 start = 1;
1654 /* Process the pieces. */
1655 for (i = start; i < XVECLEN (dst, 0); i++)
1657 enum machine_mode mode = GET_MODE (XEXP (XVECEXP (dst, 0, i), 0));
1658 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (dst, 0, i), 1));
1659 unsigned int bytelen = GET_MODE_SIZE (mode);
1660 int shift = 0;
1662 /* Handle trailing fragments that run over the size of the struct. */
1663 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
1665 /* Arrange to shift the fragment to where it belongs.
1666 extract_bit_field loads to the lsb of the reg. */
1667 if (
1668 #ifdef BLOCK_REG_PADDING
1669 BLOCK_REG_PADDING (GET_MODE (orig_src), type, i == start)
1670 == (BYTES_BIG_ENDIAN ? upward : downward)
1671 #else
1672 BYTES_BIG_ENDIAN
1673 #endif
1675 shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
1676 bytelen = ssize - bytepos;
1677 gcc_assert (bytelen > 0);
1680 /* If we won't be loading directly from memory, protect the real source
1681 from strange tricks we might play; but make sure that the source can
1682 be loaded directly into the destination. */
1683 src = orig_src;
1684 if (!MEM_P (orig_src)
1685 && (!CONSTANT_P (orig_src)
1686 || (GET_MODE (orig_src) != mode
1687 && GET_MODE (orig_src) != VOIDmode)))
1689 if (GET_MODE (orig_src) == VOIDmode)
1690 src = gen_reg_rtx (mode);
1691 else
1692 src = gen_reg_rtx (GET_MODE (orig_src));
1694 emit_move_insn (src, orig_src);
1697 /* Optimize the access just a bit. */
1698 if (MEM_P (src)
1699 && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (src))
1700 || MEM_ALIGN (src) >= GET_MODE_ALIGNMENT (mode))
1701 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
1702 && bytelen == GET_MODE_SIZE (mode))
1704 tmps[i] = gen_reg_rtx (mode);
1705 emit_move_insn (tmps[i], adjust_address (src, mode, bytepos));
1707 else if (COMPLEX_MODE_P (mode)
1708 && GET_MODE (src) == mode
1709 && bytelen == GET_MODE_SIZE (mode))
1710 /* Let emit_move_complex do the bulk of the work. */
1711 tmps[i] = src;
1712 else if (GET_CODE (src) == CONCAT)
1714 unsigned int slen = GET_MODE_SIZE (GET_MODE (src));
1715 unsigned int slen0 = GET_MODE_SIZE (GET_MODE (XEXP (src, 0)));
1717 if ((bytepos == 0 && bytelen == slen0)
1718 || (bytepos != 0 && bytepos + bytelen <= slen))
1720 /* The following assumes that the concatenated objects all
1721 have the same size. In this case, a simple calculation
1722 can be used to determine the object and the bit field
1723 to be extracted. */
1724 tmps[i] = XEXP (src, bytepos / slen0);
1725 if (! CONSTANT_P (tmps[i])
1726 && (!REG_P (tmps[i]) || GET_MODE (tmps[i]) != mode))
1727 tmps[i] = extract_bit_field (tmps[i], bytelen * BITS_PER_UNIT,
1728 (bytepos % slen0) * BITS_PER_UNIT,
1729 1, NULL_RTX, mode, mode);
1731 else
1733 rtx mem;
1735 gcc_assert (!bytepos);
1736 mem = assign_stack_temp (GET_MODE (src), slen, 0);
1737 emit_move_insn (mem, src);
1738 tmps[i] = extract_bit_field (mem, bytelen * BITS_PER_UNIT,
1739 0, 1, NULL_RTX, mode, mode);
1742 /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1743 SIMD register, which is currently broken. While we get GCC
1744 to emit proper RTL for these cases, let's dump to memory. */
1745 else if (VECTOR_MODE_P (GET_MODE (dst))
1746 && REG_P (src))
1748 int slen = GET_MODE_SIZE (GET_MODE (src));
1749 rtx mem;
1751 mem = assign_stack_temp (GET_MODE (src), slen, 0);
1752 emit_move_insn (mem, src);
1753 tmps[i] = adjust_address (mem, mode, (int) bytepos);
1755 else if (CONSTANT_P (src) && GET_MODE (dst) != BLKmode
1756 && XVECLEN (dst, 0) > 1)
1757 tmps[i] = simplify_gen_subreg (mode, src, GET_MODE(dst), bytepos);
1758 else if (CONSTANT_P (src)
1759 || (REG_P (src) && GET_MODE (src) == mode))
1760 tmps[i] = src;
1761 else
1762 tmps[i] = extract_bit_field (src, bytelen * BITS_PER_UNIT,
1763 bytepos * BITS_PER_UNIT, 1, NULL_RTX,
1764 mode, mode);
1766 if (shift)
1767 tmps[i] = expand_shift (LSHIFT_EXPR, mode, tmps[i],
1768 build_int_cst (NULL_TREE, shift), tmps[i], 0);
1772 /* Emit code to move a block SRC of type TYPE to a block DST,
1773 where DST is non-consecutive registers represented by a PARALLEL.
1774 SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1775 if not known. */
1777 void
1778 emit_group_load (rtx dst, rtx src, tree type, int ssize)
1780 rtx *tmps;
1781 int i;
1783 tmps = alloca (sizeof (rtx) * XVECLEN (dst, 0));
1784 emit_group_load_1 (tmps, dst, src, type, ssize);
1786 /* Copy the extracted pieces into the proper (probable) hard regs. */
1787 for (i = 0; i < XVECLEN (dst, 0); i++)
1789 rtx d = XEXP (XVECEXP (dst, 0, i), 0);
1790 if (d == NULL)
1791 continue;
1792 emit_move_insn (d, tmps[i]);
1796 /* Similar, but load SRC into new pseudos in a format that looks like
1797 PARALLEL. This can later be fed to emit_group_move to get things
1798 in the right place. */
1801 emit_group_load_into_temps (rtx parallel, rtx src, tree type, int ssize)
1803 rtvec vec;
1804 int i;
1806 vec = rtvec_alloc (XVECLEN (parallel, 0));
1807 emit_group_load_1 (&RTVEC_ELT (vec, 0), parallel, src, type, ssize);
1809 /* Convert the vector to look just like the original PARALLEL, except
1810 with the computed values. */
1811 for (i = 0; i < XVECLEN (parallel, 0); i++)
1813 rtx e = XVECEXP (parallel, 0, i);
1814 rtx d = XEXP (e, 0);
1816 if (d)
1818 d = force_reg (GET_MODE (d), RTVEC_ELT (vec, i));
1819 e = alloc_EXPR_LIST (REG_NOTE_KIND (e), d, XEXP (e, 1));
1821 RTVEC_ELT (vec, i) = e;
1824 return gen_rtx_PARALLEL (GET_MODE (parallel), vec);
1827 /* Emit code to move a block SRC to block DST, where SRC and DST are
1828 non-consecutive groups of registers, each represented by a PARALLEL. */
1830 void
1831 emit_group_move (rtx dst, rtx src)
1833 int i;
1835 gcc_assert (GET_CODE (src) == PARALLEL
1836 && GET_CODE (dst) == PARALLEL
1837 && XVECLEN (src, 0) == XVECLEN (dst, 0));
1839 /* Skip first entry if NULL. */
1840 for (i = XEXP (XVECEXP (src, 0, 0), 0) ? 0 : 1; i < XVECLEN (src, 0); i++)
1841 emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0),
1842 XEXP (XVECEXP (src, 0, i), 0));
1845 /* Move a group of registers represented by a PARALLEL into pseudos. */
1848 emit_group_move_into_temps (rtx src)
1850 rtvec vec = rtvec_alloc (XVECLEN (src, 0));
1851 int i;
1853 for (i = 0; i < XVECLEN (src, 0); i++)
1855 rtx e = XVECEXP (src, 0, i);
1856 rtx d = XEXP (e, 0);
1858 if (d)
1859 e = alloc_EXPR_LIST (REG_NOTE_KIND (e), copy_to_reg (d), XEXP (e, 1));
1860 RTVEC_ELT (vec, i) = e;
1863 return gen_rtx_PARALLEL (GET_MODE (src), vec);
1866 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1867 where SRC is non-consecutive registers represented by a PARALLEL.
1868 SSIZE represents the total size of block ORIG_DST, or -1 if not
1869 known. */
1871 void
1872 emit_group_store (rtx orig_dst, rtx src, tree type ATTRIBUTE_UNUSED, int ssize)
1874 rtx *tmps, dst;
1875 int start, finish, i;
1876 enum machine_mode m = GET_MODE (orig_dst);
1878 gcc_assert (GET_CODE (src) == PARALLEL);
1880 if (!SCALAR_INT_MODE_P (m)
1881 && !MEM_P (orig_dst) && GET_CODE (orig_dst) != CONCAT)
1883 enum machine_mode imode = int_mode_for_mode (GET_MODE (orig_dst));
1884 if (imode == BLKmode)
1885 dst = assign_stack_temp (GET_MODE (orig_dst), ssize, 0);
1886 else
1887 dst = gen_reg_rtx (imode);
1888 emit_group_store (dst, src, type, ssize);
1889 if (imode != BLKmode)
1890 dst = gen_lowpart (GET_MODE (orig_dst), dst);
1891 emit_move_insn (orig_dst, dst);
1892 return;
1895 /* Check for a NULL entry, used to indicate that the parameter goes
1896 both on the stack and in registers. */
1897 if (XEXP (XVECEXP (src, 0, 0), 0))
1898 start = 0;
1899 else
1900 start = 1;
1901 finish = XVECLEN (src, 0);
1903 tmps = alloca (sizeof (rtx) * finish);
1905 /* Copy the (probable) hard regs into pseudos. */
1906 for (i = start; i < finish; i++)
1908 rtx reg = XEXP (XVECEXP (src, 0, i), 0);
1909 if (!REG_P (reg) || REGNO (reg) < FIRST_PSEUDO_REGISTER)
1911 tmps[i] = gen_reg_rtx (GET_MODE (reg));
1912 emit_move_insn (tmps[i], reg);
1914 else
1915 tmps[i] = reg;
1918 /* If we won't be storing directly into memory, protect the real destination
1919 from strange tricks we might play. */
1920 dst = orig_dst;
1921 if (GET_CODE (dst) == PARALLEL)
1923 rtx temp;
1925 /* We can get a PARALLEL dst if there is a conditional expression in
1926 a return statement. In that case, the dst and src are the same,
1927 so no action is necessary. */
1928 if (rtx_equal_p (dst, src))
1929 return;
1931 /* It is unclear if we can ever reach here, but we may as well handle
1932 it. Allocate a temporary, and split this into a store/load to/from
1933 the temporary. */
1935 temp = assign_stack_temp (GET_MODE (dst), ssize, 0);
1936 emit_group_store (temp, src, type, ssize);
1937 emit_group_load (dst, temp, type, ssize);
1938 return;
1940 else if (!MEM_P (dst) && GET_CODE (dst) != CONCAT)
1942 enum machine_mode outer = GET_MODE (dst);
1943 enum machine_mode inner;
1944 HOST_WIDE_INT bytepos;
1945 bool done = false;
1946 rtx temp;
1948 if (!REG_P (dst) || REGNO (dst) < FIRST_PSEUDO_REGISTER)
1949 dst = gen_reg_rtx (outer);
1951 /* Make life a bit easier for combine. */
1952 /* If the first element of the vector is the low part
1953 of the destination mode, use a paradoxical subreg to
1954 initialize the destination. */
1955 if (start < finish)
1957 inner = GET_MODE (tmps[start]);
1958 bytepos = subreg_lowpart_offset (inner, outer);
1959 if (INTVAL (XEXP (XVECEXP (src, 0, start), 1)) == bytepos)
1961 temp = simplify_gen_subreg (outer, tmps[start],
1962 inner, 0);
1963 if (temp)
1965 emit_move_insn (dst, temp);
1966 done = true;
1967 start++;
1972 /* If the first element wasn't the low part, try the last. */
1973 if (!done
1974 && start < finish - 1)
1976 inner = GET_MODE (tmps[finish - 1]);
1977 bytepos = subreg_lowpart_offset (inner, outer);
1978 if (INTVAL (XEXP (XVECEXP (src, 0, finish - 1), 1)) == bytepos)
1980 temp = simplify_gen_subreg (outer, tmps[finish - 1],
1981 inner, 0);
1982 if (temp)
1984 emit_move_insn (dst, temp);
1985 done = true;
1986 finish--;
1991 /* Otherwise, simply initialize the result to zero. */
1992 if (!done)
1993 emit_move_insn (dst, CONST0_RTX (outer));
1996 /* Process the pieces. */
1997 for (i = start; i < finish; i++)
1999 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (src, 0, i), 1));
2000 enum machine_mode mode = GET_MODE (tmps[i]);
2001 unsigned int bytelen = GET_MODE_SIZE (mode);
2002 rtx dest = dst;
2004 /* Handle trailing fragments that run over the size of the struct. */
2005 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
2007 /* store_bit_field always takes its value from the lsb.
2008 Move the fragment to the lsb if it's not already there. */
2009 if (
2010 #ifdef BLOCK_REG_PADDING
2011 BLOCK_REG_PADDING (GET_MODE (orig_dst), type, i == start)
2012 == (BYTES_BIG_ENDIAN ? upward : downward)
2013 #else
2014 BYTES_BIG_ENDIAN
2015 #endif
2018 int shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
2019 tmps[i] = expand_shift (RSHIFT_EXPR, mode, tmps[i],
2020 build_int_cst (NULL_TREE, shift),
2021 tmps[i], 0);
2023 bytelen = ssize - bytepos;
2026 if (GET_CODE (dst) == CONCAT)
2028 if (bytepos + bytelen <= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
2029 dest = XEXP (dst, 0);
2030 else if (bytepos >= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
2032 bytepos -= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)));
2033 dest = XEXP (dst, 1);
2035 else
2037 gcc_assert (bytepos == 0 && XVECLEN (src, 0));
2038 dest = assign_stack_temp (GET_MODE (dest),
2039 GET_MODE_SIZE (GET_MODE (dest)), 0);
2040 emit_move_insn (adjust_address (dest, GET_MODE (tmps[i]), bytepos),
2041 tmps[i]);
2042 dst = dest;
2043 break;
2047 /* Optimize the access just a bit. */
2048 if (MEM_P (dest)
2049 && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (dest))
2050 || MEM_ALIGN (dest) >= GET_MODE_ALIGNMENT (mode))
2051 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
2052 && bytelen == GET_MODE_SIZE (mode))
2053 emit_move_insn (adjust_address (dest, mode, bytepos), tmps[i]);
2054 else
2055 store_bit_field (dest, bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
2056 mode, tmps[i]);
2059 /* Copy from the pseudo into the (probable) hard reg. */
2060 if (orig_dst != dst)
2061 emit_move_insn (orig_dst, dst);
2064 /* Generate code to copy a BLKmode object of TYPE out of a
2065 set of registers starting with SRCREG into TGTBLK. If TGTBLK
2066 is null, a stack temporary is created. TGTBLK is returned.
2068 The purpose of this routine is to handle functions that return
2069 BLKmode structures in registers. Some machines (the PA for example)
2070 want to return all small structures in registers regardless of the
2071 structure's alignment. */
2074 copy_blkmode_from_reg (rtx tgtblk, rtx srcreg, tree type)
2076 unsigned HOST_WIDE_INT bytes = int_size_in_bytes (type);
2077 rtx src = NULL, dst = NULL;
2078 unsigned HOST_WIDE_INT bitsize = MIN (TYPE_ALIGN (type), BITS_PER_WORD);
2079 unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0;
2081 if (tgtblk == 0)
2083 tgtblk = assign_temp (build_qualified_type (type,
2084 (TYPE_QUALS (type)
2085 | TYPE_QUAL_CONST)),
2086 0, 1, 1);
2087 preserve_temp_slots (tgtblk);
2090 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2091 into a new pseudo which is a full word. */
2093 if (GET_MODE (srcreg) != BLKmode
2094 && GET_MODE_SIZE (GET_MODE (srcreg)) < UNITS_PER_WORD)
2095 srcreg = convert_to_mode (word_mode, srcreg, TYPE_UNSIGNED (type));
2097 /* If the structure doesn't take up a whole number of words, see whether
2098 SRCREG is padded on the left or on the right. If it's on the left,
2099 set PADDING_CORRECTION to the number of bits to skip.
2101 In most ABIs, the structure will be returned at the least end of
2102 the register, which translates to right padding on little-endian
2103 targets and left padding on big-endian targets. The opposite
2104 holds if the structure is returned at the most significant
2105 end of the register. */
2106 if (bytes % UNITS_PER_WORD != 0
2107 && (targetm.calls.return_in_msb (type)
2108 ? !BYTES_BIG_ENDIAN
2109 : BYTES_BIG_ENDIAN))
2110 padding_correction
2111 = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD) * BITS_PER_UNIT));
2113 /* Copy the structure BITSIZE bites at a time.
2115 We could probably emit more efficient code for machines which do not use
2116 strict alignment, but it doesn't seem worth the effort at the current
2117 time. */
2118 for (bitpos = 0, xbitpos = padding_correction;
2119 bitpos < bytes * BITS_PER_UNIT;
2120 bitpos += bitsize, xbitpos += bitsize)
2122 /* We need a new source operand each time xbitpos is on a
2123 word boundary and when xbitpos == padding_correction
2124 (the first time through). */
2125 if (xbitpos % BITS_PER_WORD == 0
2126 || xbitpos == padding_correction)
2127 src = operand_subword_force (srcreg, xbitpos / BITS_PER_WORD,
2128 GET_MODE (srcreg));
2130 /* We need a new destination operand each time bitpos is on
2131 a word boundary. */
2132 if (bitpos % BITS_PER_WORD == 0)
2133 dst = operand_subword (tgtblk, bitpos / BITS_PER_WORD, 1, BLKmode);
2135 /* Use xbitpos for the source extraction (right justified) and
2136 xbitpos for the destination store (left justified). */
2137 store_bit_field (dst, bitsize, bitpos % BITS_PER_WORD, word_mode,
2138 extract_bit_field (src, bitsize,
2139 xbitpos % BITS_PER_WORD, 1,
2140 NULL_RTX, word_mode, word_mode));
2143 return tgtblk;
2146 /* Add a USE expression for REG to the (possibly empty) list pointed
2147 to by CALL_FUSAGE. REG must denote a hard register. */
2149 void
2150 use_reg (rtx *call_fusage, rtx reg)
2152 gcc_assert (REG_P (reg) && REGNO (reg) < FIRST_PSEUDO_REGISTER);
2154 *call_fusage
2155 = gen_rtx_EXPR_LIST (VOIDmode,
2156 gen_rtx_USE (VOIDmode, reg), *call_fusage);
2159 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2160 starting at REGNO. All of these registers must be hard registers. */
2162 void
2163 use_regs (rtx *call_fusage, int regno, int nregs)
2165 int i;
2167 gcc_assert (regno + nregs <= FIRST_PSEUDO_REGISTER);
2169 for (i = 0; i < nregs; i++)
2170 use_reg (call_fusage, regno_reg_rtx[regno + i]);
2173 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2174 PARALLEL REGS. This is for calls that pass values in multiple
2175 non-contiguous locations. The Irix 6 ABI has examples of this. */
2177 void
2178 use_group_regs (rtx *call_fusage, rtx regs)
2180 int i;
2182 for (i = 0; i < XVECLEN (regs, 0); i++)
2184 rtx reg = XEXP (XVECEXP (regs, 0, i), 0);
2186 /* A NULL entry means the parameter goes both on the stack and in
2187 registers. This can also be a MEM for targets that pass values
2188 partially on the stack and partially in registers. */
2189 if (reg != 0 && REG_P (reg))
2190 use_reg (call_fusage, reg);
2195 /* Determine whether the LEN bytes generated by CONSTFUN can be
2196 stored to memory using several move instructions. CONSTFUNDATA is
2197 a pointer which will be passed as argument in every CONSTFUN call.
2198 ALIGN is maximum alignment we can assume. Return nonzero if a
2199 call to store_by_pieces should succeed. */
2202 can_store_by_pieces (unsigned HOST_WIDE_INT len,
2203 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode),
2204 void *constfundata, unsigned int align)
2206 unsigned HOST_WIDE_INT l;
2207 unsigned int max_size;
2208 HOST_WIDE_INT offset = 0;
2209 enum machine_mode mode, tmode;
2210 enum insn_code icode;
2211 int reverse;
2212 rtx cst;
2214 if (len == 0)
2215 return 1;
2217 if (! STORE_BY_PIECES_P (len, align))
2218 return 0;
2220 tmode = mode_for_size (STORE_MAX_PIECES * BITS_PER_UNIT, MODE_INT, 1);
2221 if (align >= GET_MODE_ALIGNMENT (tmode))
2222 align = GET_MODE_ALIGNMENT (tmode);
2223 else
2225 enum machine_mode xmode;
2227 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
2228 tmode != VOIDmode;
2229 xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
2230 if (GET_MODE_SIZE (tmode) > STORE_MAX_PIECES
2231 || SLOW_UNALIGNED_ACCESS (tmode, align))
2232 break;
2234 align = MAX (align, GET_MODE_ALIGNMENT (xmode));
2237 /* We would first store what we can in the largest integer mode, then go to
2238 successively smaller modes. */
2240 for (reverse = 0;
2241 reverse <= (HAVE_PRE_DECREMENT || HAVE_POST_DECREMENT);
2242 reverse++)
2244 l = len;
2245 mode = VOIDmode;
2246 max_size = STORE_MAX_PIECES + 1;
2247 while (max_size > 1)
2249 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2250 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2251 if (GET_MODE_SIZE (tmode) < max_size)
2252 mode = tmode;
2254 if (mode == VOIDmode)
2255 break;
2257 icode = mov_optab->handlers[(int) mode].insn_code;
2258 if (icode != CODE_FOR_nothing
2259 && align >= GET_MODE_ALIGNMENT (mode))
2261 unsigned int size = GET_MODE_SIZE (mode);
2263 while (l >= size)
2265 if (reverse)
2266 offset -= size;
2268 cst = (*constfun) (constfundata, offset, mode);
2269 if (!LEGITIMATE_CONSTANT_P (cst))
2270 return 0;
2272 if (!reverse)
2273 offset += size;
2275 l -= size;
2279 max_size = GET_MODE_SIZE (mode);
2282 /* The code above should have handled everything. */
2283 gcc_assert (!l);
2286 return 1;
2289 /* Generate several move instructions to store LEN bytes generated by
2290 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2291 pointer which will be passed as argument in every CONSTFUN call.
2292 ALIGN is maximum alignment we can assume.
2293 If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2294 mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2295 stpcpy. */
2298 store_by_pieces (rtx to, unsigned HOST_WIDE_INT len,
2299 rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode),
2300 void *constfundata, unsigned int align, int endp)
2302 struct store_by_pieces data;
2304 if (len == 0)
2306 gcc_assert (endp != 2);
2307 return to;
2310 gcc_assert (STORE_BY_PIECES_P (len, align));
2311 data.constfun = constfun;
2312 data.constfundata = constfundata;
2313 data.len = len;
2314 data.to = to;
2315 store_by_pieces_1 (&data, align);
2316 if (endp)
2318 rtx to1;
2320 gcc_assert (!data.reverse);
2321 if (data.autinc_to)
2323 if (endp == 2)
2325 if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
2326 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
2327 else
2328 data.to_addr = copy_addr_to_reg (plus_constant (data.to_addr,
2329 -1));
2331 to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
2332 data.offset);
2334 else
2336 if (endp == 2)
2337 --data.offset;
2338 to1 = adjust_address (data.to, QImode, data.offset);
2340 return to1;
2342 else
2343 return data.to;
2346 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2347 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2349 static void
2350 clear_by_pieces (rtx to, unsigned HOST_WIDE_INT len, unsigned int align)
2352 struct store_by_pieces data;
2354 if (len == 0)
2355 return;
2357 data.constfun = clear_by_pieces_1;
2358 data.constfundata = NULL;
2359 data.len = len;
2360 data.to = to;
2361 store_by_pieces_1 (&data, align);
2364 /* Callback routine for clear_by_pieces.
2365 Return const0_rtx unconditionally. */
2367 static rtx
2368 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED,
2369 HOST_WIDE_INT offset ATTRIBUTE_UNUSED,
2370 enum machine_mode mode ATTRIBUTE_UNUSED)
2372 return const0_rtx;
2375 /* Subroutine of clear_by_pieces and store_by_pieces.
2376 Generate several move instructions to store LEN bytes of block TO. (A MEM
2377 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
2379 static void
2380 store_by_pieces_1 (struct store_by_pieces *data ATTRIBUTE_UNUSED,
2381 unsigned int align ATTRIBUTE_UNUSED)
2383 rtx to_addr = XEXP (data->to, 0);
2384 unsigned int max_size = STORE_MAX_PIECES + 1;
2385 enum machine_mode mode = VOIDmode, tmode;
2386 enum insn_code icode;
2388 data->offset = 0;
2389 data->to_addr = to_addr;
2390 data->autinc_to
2391 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
2392 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
2394 data->explicit_inc_to = 0;
2395 data->reverse
2396 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
2397 if (data->reverse)
2398 data->offset = data->len;
2400 /* If storing requires more than two move insns,
2401 copy addresses to registers (to make displacements shorter)
2402 and use post-increment if available. */
2403 if (!data->autinc_to
2404 && move_by_pieces_ninsns (data->len, align, max_size) > 2)
2406 /* Determine the main mode we'll be using. */
2407 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2408 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2409 if (GET_MODE_SIZE (tmode) < max_size)
2410 mode = tmode;
2412 if (USE_STORE_PRE_DECREMENT (mode) && data->reverse && ! data->autinc_to)
2414 data->to_addr = copy_addr_to_reg (plus_constant (to_addr, data->len));
2415 data->autinc_to = 1;
2416 data->explicit_inc_to = -1;
2419 if (USE_STORE_POST_INCREMENT (mode) && ! data->reverse
2420 && ! data->autinc_to)
2422 data->to_addr = copy_addr_to_reg (to_addr);
2423 data->autinc_to = 1;
2424 data->explicit_inc_to = 1;
2427 if ( !data->autinc_to && CONSTANT_P (to_addr))
2428 data->to_addr = copy_addr_to_reg (to_addr);
2431 tmode = mode_for_size (STORE_MAX_PIECES * BITS_PER_UNIT, MODE_INT, 1);
2432 if (align >= GET_MODE_ALIGNMENT (tmode))
2433 align = GET_MODE_ALIGNMENT (tmode);
2434 else
2436 enum machine_mode xmode;
2438 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
2439 tmode != VOIDmode;
2440 xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
2441 if (GET_MODE_SIZE (tmode) > STORE_MAX_PIECES
2442 || SLOW_UNALIGNED_ACCESS (tmode, align))
2443 break;
2445 align = MAX (align, GET_MODE_ALIGNMENT (xmode));
2448 /* First store what we can in the largest integer mode, then go to
2449 successively smaller modes. */
2451 while (max_size > 1)
2453 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2454 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2455 if (GET_MODE_SIZE (tmode) < max_size)
2456 mode = tmode;
2458 if (mode == VOIDmode)
2459 break;
2461 icode = mov_optab->handlers[(int) mode].insn_code;
2462 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
2463 store_by_pieces_2 (GEN_FCN (icode), mode, data);
2465 max_size = GET_MODE_SIZE (mode);
2468 /* The code above should have handled everything. */
2469 gcc_assert (!data->len);
2472 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2473 with move instructions for mode MODE. GENFUN is the gen_... function
2474 to make a move insn for that mode. DATA has all the other info. */
2476 static void
2477 store_by_pieces_2 (rtx (*genfun) (rtx, ...), enum machine_mode mode,
2478 struct store_by_pieces *data)
2480 unsigned int size = GET_MODE_SIZE (mode);
2481 rtx to1, cst;
2483 while (data->len >= size)
2485 if (data->reverse)
2486 data->offset -= size;
2488 if (data->autinc_to)
2489 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
2490 data->offset);
2491 else
2492 to1 = adjust_address (data->to, mode, data->offset);
2494 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
2495 emit_insn (gen_add2_insn (data->to_addr,
2496 GEN_INT (-(HOST_WIDE_INT) size)));
2498 cst = (*data->constfun) (data->constfundata, data->offset, mode);
2499 emit_insn ((*genfun) (to1, cst));
2501 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
2502 emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
2504 if (! data->reverse)
2505 data->offset += size;
2507 data->len -= size;
2511 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2512 its length in bytes. */
2515 clear_storage_hints (rtx object, rtx size, enum block_op_methods method,
2516 unsigned int expected_align, HOST_WIDE_INT expected_size)
2518 enum machine_mode mode = GET_MODE (object);
2519 unsigned int align;
2521 gcc_assert (method == BLOCK_OP_NORMAL || method == BLOCK_OP_TAILCALL);
2523 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2524 just move a zero. Otherwise, do this a piece at a time. */
2525 if (mode != BLKmode
2526 && GET_CODE (size) == CONST_INT
2527 && INTVAL (size) == (HOST_WIDE_INT) GET_MODE_SIZE (mode))
2529 rtx zero = CONST0_RTX (mode);
2530 if (zero != NULL)
2532 emit_move_insn (object, zero);
2533 return NULL;
2536 if (COMPLEX_MODE_P (mode))
2538 zero = CONST0_RTX (GET_MODE_INNER (mode));
2539 if (zero != NULL)
2541 write_complex_part (object, zero, 0);
2542 write_complex_part (object, zero, 1);
2543 return NULL;
2548 if (size == const0_rtx)
2549 return NULL;
2551 align = MEM_ALIGN (object);
2553 if (GET_CODE (size) == CONST_INT
2554 && CLEAR_BY_PIECES_P (INTVAL (size), align))
2555 clear_by_pieces (object, INTVAL (size), align);
2556 else if (set_storage_via_setmem (object, size, const0_rtx, align,
2557 expected_align, expected_size))
2559 else
2560 return set_storage_via_libcall (object, size, const0_rtx,
2561 method == BLOCK_OP_TAILCALL);
2563 return NULL;
2567 clear_storage (rtx object, rtx size, enum block_op_methods method)
2569 return clear_storage_hints (object, size, method, 0, -1);
2573 /* A subroutine of clear_storage. Expand a call to memset.
2574 Return the return value of memset, 0 otherwise. */
2577 set_storage_via_libcall (rtx object, rtx size, rtx val, bool tailcall)
2579 tree call_expr, arg_list, fn, object_tree, size_tree, val_tree;
2580 enum machine_mode size_mode;
2581 rtx retval;
2583 /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
2584 place those into new pseudos into a VAR_DECL and use them later. */
2586 object = copy_to_mode_reg (Pmode, XEXP (object, 0));
2588 size_mode = TYPE_MODE (sizetype);
2589 size = convert_to_mode (size_mode, size, 1);
2590 size = copy_to_mode_reg (size_mode, size);
2592 /* It is incorrect to use the libcall calling conventions to call
2593 memset in this context. This could be a user call to memset and
2594 the user may wish to examine the return value from memset. For
2595 targets where libcalls and normal calls have different conventions
2596 for returning pointers, we could end up generating incorrect code. */
2598 object_tree = make_tree (ptr_type_node, object);
2599 if (GET_CODE (val) != CONST_INT)
2600 val = convert_to_mode (TYPE_MODE (integer_type_node), val, 1);
2601 size_tree = make_tree (sizetype, size);
2602 val_tree = make_tree (integer_type_node, val);
2604 fn = clear_storage_libcall_fn (true);
2605 arg_list = tree_cons (NULL_TREE, size_tree, NULL_TREE);
2606 arg_list = tree_cons (NULL_TREE, val_tree, arg_list);
2607 arg_list = tree_cons (NULL_TREE, object_tree, arg_list);
2609 /* Now we have to build up the CALL_EXPR itself. */
2610 call_expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (fn)), fn);
2611 call_expr = build3 (CALL_EXPR, TREE_TYPE (TREE_TYPE (fn)),
2612 call_expr, arg_list, NULL_TREE);
2613 CALL_EXPR_TAILCALL (call_expr) = tailcall;
2615 retval = expand_normal (call_expr);
2617 return retval;
2620 /* A subroutine of set_storage_via_libcall. Create the tree node
2621 for the function we use for block clears. The first time FOR_CALL
2622 is true, we call assemble_external. */
2624 static GTY(()) tree block_clear_fn;
2626 void
2627 init_block_clear_fn (const char *asmspec)
2629 if (!block_clear_fn)
2631 tree fn, args;
2633 fn = get_identifier ("memset");
2634 args = build_function_type_list (ptr_type_node, ptr_type_node,
2635 integer_type_node, sizetype,
2636 NULL_TREE);
2638 fn = build_decl (FUNCTION_DECL, fn, args);
2639 DECL_EXTERNAL (fn) = 1;
2640 TREE_PUBLIC (fn) = 1;
2641 DECL_ARTIFICIAL (fn) = 1;
2642 TREE_NOTHROW (fn) = 1;
2643 DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
2644 DECL_VISIBILITY_SPECIFIED (fn) = 1;
2646 block_clear_fn = fn;
2649 if (asmspec)
2650 set_user_assembler_name (block_clear_fn, asmspec);
2653 static tree
2654 clear_storage_libcall_fn (int for_call)
2656 static bool emitted_extern;
2658 if (!block_clear_fn)
2659 init_block_clear_fn (NULL);
2661 if (for_call && !emitted_extern)
2663 emitted_extern = true;
2664 make_decl_rtl (block_clear_fn);
2665 assemble_external (block_clear_fn);
2668 return block_clear_fn;
2671 /* Expand a setmem pattern; return true if successful. */
2673 bool
2674 set_storage_via_setmem (rtx object, rtx size, rtx val, unsigned int align,
2675 unsigned int expected_align, HOST_WIDE_INT expected_size)
2677 /* Try the most limited insn first, because there's no point
2678 including more than one in the machine description unless
2679 the more limited one has some advantage. */
2681 rtx opalign = GEN_INT (align / BITS_PER_UNIT);
2682 enum machine_mode mode;
2684 if (expected_align < align)
2685 expected_align = align;
2687 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
2688 mode = GET_MODE_WIDER_MODE (mode))
2690 enum insn_code code = setmem_optab[(int) mode];
2691 insn_operand_predicate_fn pred;
2693 if (code != CODE_FOR_nothing
2694 /* We don't need MODE to be narrower than
2695 BITS_PER_HOST_WIDE_INT here because if SIZE is less than
2696 the mode mask, as it is returned by the macro, it will
2697 definitely be less than the actual mode mask. */
2698 && ((GET_CODE (size) == CONST_INT
2699 && ((unsigned HOST_WIDE_INT) INTVAL (size)
2700 <= (GET_MODE_MASK (mode) >> 1)))
2701 || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD)
2702 && ((pred = insn_data[(int) code].operand[0].predicate) == 0
2703 || (*pred) (object, BLKmode))
2704 && ((pred = insn_data[(int) code].operand[3].predicate) == 0
2705 || (*pred) (opalign, VOIDmode)))
2707 rtx opsize, opchar;
2708 enum machine_mode char_mode;
2709 rtx last = get_last_insn ();
2710 rtx pat;
2712 opsize = convert_to_mode (mode, size, 1);
2713 pred = insn_data[(int) code].operand[1].predicate;
2714 if (pred != 0 && ! (*pred) (opsize, mode))
2715 opsize = copy_to_mode_reg (mode, opsize);
2717 opchar = val;
2718 char_mode = insn_data[(int) code].operand[2].mode;
2719 if (char_mode != VOIDmode)
2721 opchar = convert_to_mode (char_mode, opchar, 1);
2722 pred = insn_data[(int) code].operand[2].predicate;
2723 if (pred != 0 && ! (*pred) (opchar, char_mode))
2724 opchar = copy_to_mode_reg (char_mode, opchar);
2727 if (insn_data[(int) code].n_operands == 4)
2728 pat = GEN_FCN ((int) code) (object, opsize, opchar, opalign);
2729 else
2730 pat = GEN_FCN ((int) code) (object, opsize, opchar, opalign,
2731 GEN_INT (expected_align),
2732 GEN_INT (expected_size));
2733 if (pat)
2735 emit_insn (pat);
2736 return true;
2738 else
2739 delete_insns_since (last);
2743 return false;
2747 /* Write to one of the components of the complex value CPLX. Write VAL to
2748 the real part if IMAG_P is false, and the imaginary part if its true. */
2750 static void
2751 write_complex_part (rtx cplx, rtx val, bool imag_p)
2753 enum machine_mode cmode;
2754 enum machine_mode imode;
2755 unsigned ibitsize;
2757 if (GET_CODE (cplx) == CONCAT)
2759 emit_move_insn (XEXP (cplx, imag_p), val);
2760 return;
2763 cmode = GET_MODE (cplx);
2764 imode = GET_MODE_INNER (cmode);
2765 ibitsize = GET_MODE_BITSIZE (imode);
2767 /* For MEMs simplify_gen_subreg may generate an invalid new address
2768 because, e.g., the original address is considered mode-dependent
2769 by the target, which restricts simplify_subreg from invoking
2770 adjust_address_nv. Instead of preparing fallback support for an
2771 invalid address, we call adjust_address_nv directly. */
2772 if (MEM_P (cplx))
2774 emit_move_insn (adjust_address_nv (cplx, imode,
2775 imag_p ? GET_MODE_SIZE (imode) : 0),
2776 val);
2777 return;
2780 /* If the sub-object is at least word sized, then we know that subregging
2781 will work. This special case is important, since store_bit_field
2782 wants to operate on integer modes, and there's rarely an OImode to
2783 correspond to TCmode. */
2784 if (ibitsize >= BITS_PER_WORD
2785 /* For hard regs we have exact predicates. Assume we can split
2786 the original object if it spans an even number of hard regs.
2787 This special case is important for SCmode on 64-bit platforms
2788 where the natural size of floating-point regs is 32-bit. */
2789 || (REG_P (cplx)
2790 && REGNO (cplx) < FIRST_PSEUDO_REGISTER
2791 && hard_regno_nregs[REGNO (cplx)][cmode] % 2 == 0))
2793 rtx part = simplify_gen_subreg (imode, cplx, cmode,
2794 imag_p ? GET_MODE_SIZE (imode) : 0);
2795 if (part)
2797 emit_move_insn (part, val);
2798 return;
2800 else
2801 /* simplify_gen_subreg may fail for sub-word MEMs. */
2802 gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
2805 store_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0, imode, val);
2808 /* Extract one of the components of the complex value CPLX. Extract the
2809 real part if IMAG_P is false, and the imaginary part if it's true. */
2811 static rtx
2812 read_complex_part (rtx cplx, bool imag_p)
2814 enum machine_mode cmode, imode;
2815 unsigned ibitsize;
2817 if (GET_CODE (cplx) == CONCAT)
2818 return XEXP (cplx, imag_p);
2820 cmode = GET_MODE (cplx);
2821 imode = GET_MODE_INNER (cmode);
2822 ibitsize = GET_MODE_BITSIZE (imode);
2824 /* Special case reads from complex constants that got spilled to memory. */
2825 if (MEM_P (cplx) && GET_CODE (XEXP (cplx, 0)) == SYMBOL_REF)
2827 tree decl = SYMBOL_REF_DECL (XEXP (cplx, 0));
2828 if (decl && TREE_CODE (decl) == COMPLEX_CST)
2830 tree part = imag_p ? TREE_IMAGPART (decl) : TREE_REALPART (decl);
2831 if (CONSTANT_CLASS_P (part))
2832 return expand_expr (part, NULL_RTX, imode, EXPAND_NORMAL);
2836 /* For MEMs simplify_gen_subreg may generate an invalid new address
2837 because, e.g., the original address is considered mode-dependent
2838 by the target, which restricts simplify_subreg from invoking
2839 adjust_address_nv. Instead of preparing fallback support for an
2840 invalid address, we call adjust_address_nv directly. */
2841 if (MEM_P (cplx))
2842 return adjust_address_nv (cplx, imode,
2843 imag_p ? GET_MODE_SIZE (imode) : 0);
2845 /* If the sub-object is at least word sized, then we know that subregging
2846 will work. This special case is important, since extract_bit_field
2847 wants to operate on integer modes, and there's rarely an OImode to
2848 correspond to TCmode. */
2849 if (ibitsize >= BITS_PER_WORD
2850 /* For hard regs we have exact predicates. Assume we can split
2851 the original object if it spans an even number of hard regs.
2852 This special case is important for SCmode on 64-bit platforms
2853 where the natural size of floating-point regs is 32-bit. */
2854 || (REG_P (cplx)
2855 && REGNO (cplx) < FIRST_PSEUDO_REGISTER
2856 && hard_regno_nregs[REGNO (cplx)][cmode] % 2 == 0))
2858 rtx ret = simplify_gen_subreg (imode, cplx, cmode,
2859 imag_p ? GET_MODE_SIZE (imode) : 0);
2860 if (ret)
2861 return ret;
2862 else
2863 /* simplify_gen_subreg may fail for sub-word MEMs. */
2864 gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
2867 return extract_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0,
2868 true, NULL_RTX, imode, imode);
2871 /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
2872 NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
2873 represented in NEW_MODE. If FORCE is true, this will never happen, as
2874 we'll force-create a SUBREG if needed. */
2876 static rtx
2877 emit_move_change_mode (enum machine_mode new_mode,
2878 enum machine_mode old_mode, rtx x, bool force)
2880 rtx ret;
2882 if (MEM_P (x))
2884 /* We don't have to worry about changing the address since the
2885 size in bytes is supposed to be the same. */
2886 if (reload_in_progress)
2888 /* Copy the MEM to change the mode and move any
2889 substitutions from the old MEM to the new one. */
2890 ret = adjust_address_nv (x, new_mode, 0);
2891 copy_replacements (x, ret);
2893 else
2894 ret = adjust_address (x, new_mode, 0);
2896 else
2898 /* Note that we do want simplify_subreg's behavior of validating
2899 that the new mode is ok for a hard register. If we were to use
2900 simplify_gen_subreg, we would create the subreg, but would
2901 probably run into the target not being able to implement it. */
2902 /* Except, of course, when FORCE is true, when this is exactly what
2903 we want. Which is needed for CCmodes on some targets. */
2904 if (force)
2905 ret = simplify_gen_subreg (new_mode, x, old_mode, 0);
2906 else
2907 ret = simplify_subreg (new_mode, x, old_mode, 0);
2910 return ret;
2913 /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
2914 an integer mode of the same size as MODE. Returns the instruction
2915 emitted, or NULL if such a move could not be generated. */
2917 static rtx
2918 emit_move_via_integer (enum machine_mode mode, rtx x, rtx y, bool force)
2920 enum machine_mode imode;
2921 enum insn_code code;
2923 /* There must exist a mode of the exact size we require. */
2924 imode = int_mode_for_mode (mode);
2925 if (imode == BLKmode)
2926 return NULL_RTX;
2928 /* The target must support moves in this mode. */
2929 code = mov_optab->handlers[imode].insn_code;
2930 if (code == CODE_FOR_nothing)
2931 return NULL_RTX;
2933 x = emit_move_change_mode (imode, mode, x, force);
2934 if (x == NULL_RTX)
2935 return NULL_RTX;
2936 y = emit_move_change_mode (imode, mode, y, force);
2937 if (y == NULL_RTX)
2938 return NULL_RTX;
2939 return emit_insn (GEN_FCN (code) (x, y));
2942 /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
2943 Return an equivalent MEM that does not use an auto-increment. */
2945 static rtx
2946 emit_move_resolve_push (enum machine_mode mode, rtx x)
2948 enum rtx_code code = GET_CODE (XEXP (x, 0));
2949 HOST_WIDE_INT adjust;
2950 rtx temp;
2952 adjust = GET_MODE_SIZE (mode);
2953 #ifdef PUSH_ROUNDING
2954 adjust = PUSH_ROUNDING (adjust);
2955 #endif
2956 if (code == PRE_DEC || code == POST_DEC)
2957 adjust = -adjust;
2958 else if (code == PRE_MODIFY || code == POST_MODIFY)
2960 rtx expr = XEXP (XEXP (x, 0), 1);
2961 HOST_WIDE_INT val;
2963 gcc_assert (GET_CODE (expr) == PLUS || GET_CODE (expr) == MINUS);
2964 gcc_assert (GET_CODE (XEXP (expr, 1)) == CONST_INT);
2965 val = INTVAL (XEXP (expr, 1));
2966 if (GET_CODE (expr) == MINUS)
2967 val = -val;
2968 gcc_assert (adjust == val || adjust == -val);
2969 adjust = val;
2972 /* Do not use anti_adjust_stack, since we don't want to update
2973 stack_pointer_delta. */
2974 temp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
2975 GEN_INT (adjust), stack_pointer_rtx,
2976 0, OPTAB_LIB_WIDEN);
2977 if (temp != stack_pointer_rtx)
2978 emit_move_insn (stack_pointer_rtx, temp);
2980 switch (code)
2982 case PRE_INC:
2983 case PRE_DEC:
2984 case PRE_MODIFY:
2985 temp = stack_pointer_rtx;
2986 break;
2987 case POST_INC:
2988 case POST_DEC:
2989 case POST_MODIFY:
2990 temp = plus_constant (stack_pointer_rtx, -adjust);
2991 break;
2992 default:
2993 gcc_unreachable ();
2996 return replace_equiv_address (x, temp);
2999 /* A subroutine of emit_move_complex. Generate a move from Y into X.
3000 X is known to satisfy push_operand, and MODE is known to be complex.
3001 Returns the last instruction emitted. */
3003 static rtx
3004 emit_move_complex_push (enum machine_mode mode, rtx x, rtx y)
3006 enum machine_mode submode = GET_MODE_INNER (mode);
3007 bool imag_first;
3009 #ifdef PUSH_ROUNDING
3010 unsigned int submodesize = GET_MODE_SIZE (submode);
3012 /* In case we output to the stack, but the size is smaller than the
3013 machine can push exactly, we need to use move instructions. */
3014 if (PUSH_ROUNDING (submodesize) != submodesize)
3016 x = emit_move_resolve_push (mode, x);
3017 return emit_move_insn (x, y);
3019 #endif
3021 /* Note that the real part always precedes the imag part in memory
3022 regardless of machine's endianness. */
3023 switch (GET_CODE (XEXP (x, 0)))
3025 case PRE_DEC:
3026 case POST_DEC:
3027 imag_first = true;
3028 break;
3029 case PRE_INC:
3030 case POST_INC:
3031 imag_first = false;
3032 break;
3033 default:
3034 gcc_unreachable ();
3037 emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
3038 read_complex_part (y, imag_first));
3039 return emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
3040 read_complex_part (y, !imag_first));
3043 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3044 MODE is known to be complex. Returns the last instruction emitted. */
3046 static rtx
3047 emit_move_complex (enum machine_mode mode, rtx x, rtx y)
3049 bool try_int;
3051 /* Need to take special care for pushes, to maintain proper ordering
3052 of the data, and possibly extra padding. */
3053 if (push_operand (x, mode))
3054 return emit_move_complex_push (mode, x, y);
3056 /* See if we can coerce the target into moving both values at once. */
3058 /* Move floating point as parts. */
3059 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
3060 && mov_optab->handlers[GET_MODE_INNER (mode)].insn_code != CODE_FOR_nothing)
3061 try_int = false;
3062 /* Not possible if the values are inherently not adjacent. */
3063 else if (GET_CODE (x) == CONCAT || GET_CODE (y) == CONCAT)
3064 try_int = false;
3065 /* Is possible if both are registers (or subregs of registers). */
3066 else if (register_operand (x, mode) && register_operand (y, mode))
3067 try_int = true;
3068 /* If one of the operands is a memory, and alignment constraints
3069 are friendly enough, we may be able to do combined memory operations.
3070 We do not attempt this if Y is a constant because that combination is
3071 usually better with the by-parts thing below. */
3072 else if ((MEM_P (x) ? !CONSTANT_P (y) : MEM_P (y))
3073 && (!STRICT_ALIGNMENT
3074 || get_mode_alignment (mode) == BIGGEST_ALIGNMENT))
3075 try_int = true;
3076 else
3077 try_int = false;
3079 if (try_int)
3081 rtx ret;
3083 /* For memory to memory moves, optimal behavior can be had with the
3084 existing block move logic. */
3085 if (MEM_P (x) && MEM_P (y))
3087 emit_block_move (x, y, GEN_INT (GET_MODE_SIZE (mode)),
3088 BLOCK_OP_NO_LIBCALL);
3089 return get_last_insn ();
3092 ret = emit_move_via_integer (mode, x, y, true);
3093 if (ret)
3094 return ret;
3097 /* Show the output dies here. This is necessary for SUBREGs
3098 of pseudos since we cannot track their lifetimes correctly;
3099 hard regs shouldn't appear here except as return values. */
3100 if (!reload_completed && !reload_in_progress
3101 && REG_P (x) && !reg_overlap_mentioned_p (x, y))
3102 emit_insn (gen_rtx_CLOBBER (VOIDmode, x));
3104 write_complex_part (x, read_complex_part (y, false), false);
3105 write_complex_part (x, read_complex_part (y, true), true);
3106 return get_last_insn ();
3109 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3110 MODE is known to be MODE_CC. Returns the last instruction emitted. */
3112 static rtx
3113 emit_move_ccmode (enum machine_mode mode, rtx x, rtx y)
3115 rtx ret;
3117 /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
3118 if (mode != CCmode)
3120 enum insn_code code = mov_optab->handlers[CCmode].insn_code;
3121 if (code != CODE_FOR_nothing)
3123 x = emit_move_change_mode (CCmode, mode, x, true);
3124 y = emit_move_change_mode (CCmode, mode, y, true);
3125 return emit_insn (GEN_FCN (code) (x, y));
3129 /* Otherwise, find the MODE_INT mode of the same width. */
3130 ret = emit_move_via_integer (mode, x, y, false);
3131 gcc_assert (ret != NULL);
3132 return ret;
3135 /* Return true if word I of OP lies entirely in the
3136 undefined bits of a paradoxical subreg. */
3138 static bool
3139 undefined_operand_subword_p (rtx op, int i)
3141 enum machine_mode innermode, innermostmode;
3142 int offset;
3143 if (GET_CODE (op) != SUBREG)
3144 return false;
3145 innermode = GET_MODE (op);
3146 innermostmode = GET_MODE (SUBREG_REG (op));
3147 offset = i * UNITS_PER_WORD + SUBREG_BYTE (op);
3148 /* The SUBREG_BYTE represents offset, as if the value were stored in
3149 memory, except for a paradoxical subreg where we define
3150 SUBREG_BYTE to be 0; undo this exception as in
3151 simplify_subreg. */
3152 if (SUBREG_BYTE (op) == 0
3153 && GET_MODE_SIZE (innermostmode) < GET_MODE_SIZE (innermode))
3155 int difference = (GET_MODE_SIZE (innermostmode) - GET_MODE_SIZE (innermode));
3156 if (WORDS_BIG_ENDIAN)
3157 offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD;
3158 if (BYTES_BIG_ENDIAN)
3159 offset += difference % UNITS_PER_WORD;
3161 if (offset >= GET_MODE_SIZE (innermostmode)
3162 || offset <= -GET_MODE_SIZE (word_mode))
3163 return true;
3164 return false;
3167 /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
3168 MODE is any multi-word or full-word mode that lacks a move_insn
3169 pattern. Note that you will get better code if you define such
3170 patterns, even if they must turn into multiple assembler instructions. */
3172 static rtx
3173 emit_move_multi_word (enum machine_mode mode, rtx x, rtx y)
3175 rtx last_insn = 0;
3176 rtx seq, inner;
3177 bool need_clobber;
3178 int i;
3180 gcc_assert (GET_MODE_SIZE (mode) >= UNITS_PER_WORD);
3182 /* If X is a push on the stack, do the push now and replace
3183 X with a reference to the stack pointer. */
3184 if (push_operand (x, mode))
3185 x = emit_move_resolve_push (mode, x);
3187 /* If we are in reload, see if either operand is a MEM whose address
3188 is scheduled for replacement. */
3189 if (reload_in_progress && MEM_P (x)
3190 && (inner = find_replacement (&XEXP (x, 0))) != XEXP (x, 0))
3191 x = replace_equiv_address_nv (x, inner);
3192 if (reload_in_progress && MEM_P (y)
3193 && (inner = find_replacement (&XEXP (y, 0))) != XEXP (y, 0))
3194 y = replace_equiv_address_nv (y, inner);
3196 start_sequence ();
3198 need_clobber = false;
3199 for (i = 0;
3200 i < (GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
3201 i++)
3203 rtx xpart = operand_subword (x, i, 1, mode);
3204 rtx ypart;
3206 /* Do not generate code for a move if it would come entirely
3207 from the undefined bits of a paradoxical subreg. */
3208 if (undefined_operand_subword_p (y, i))
3209 continue;
3211 ypart = operand_subword (y, i, 1, mode);
3213 /* If we can't get a part of Y, put Y into memory if it is a
3214 constant. Otherwise, force it into a register. Then we must
3215 be able to get a part of Y. */
3216 if (ypart == 0 && CONSTANT_P (y))
3218 y = use_anchored_address (force_const_mem (mode, y));
3219 ypart = operand_subword (y, i, 1, mode);
3221 else if (ypart == 0)
3222 ypart = operand_subword_force (y, i, mode);
3224 gcc_assert (xpart && ypart);
3226 need_clobber |= (GET_CODE (xpart) == SUBREG);
3228 last_insn = emit_move_insn (xpart, ypart);
3231 seq = get_insns ();
3232 end_sequence ();
3234 /* Show the output dies here. This is necessary for SUBREGs
3235 of pseudos since we cannot track their lifetimes correctly;
3236 hard regs shouldn't appear here except as return values.
3237 We never want to emit such a clobber after reload. */
3238 if (x != y
3239 && ! (reload_in_progress || reload_completed)
3240 && need_clobber != 0)
3241 emit_insn (gen_rtx_CLOBBER (VOIDmode, x));
3243 emit_insn (seq);
3245 return last_insn;
3248 /* Low level part of emit_move_insn.
3249 Called just like emit_move_insn, but assumes X and Y
3250 are basically valid. */
3253 emit_move_insn_1 (rtx x, rtx y)
3255 enum machine_mode mode = GET_MODE (x);
3256 enum insn_code code;
3258 gcc_assert ((unsigned int) mode < (unsigned int) MAX_MACHINE_MODE);
3260 code = mov_optab->handlers[mode].insn_code;
3261 if (code != CODE_FOR_nothing)
3262 return emit_insn (GEN_FCN (code) (x, y));
3264 /* Expand complex moves by moving real part and imag part. */
3265 if (COMPLEX_MODE_P (mode))
3266 return emit_move_complex (mode, x, y);
3268 if (GET_MODE_CLASS (mode) == MODE_DECIMAL_FLOAT)
3270 rtx result = emit_move_via_integer (mode, x, y, true);
3272 /* If we can't find an integer mode, use multi words. */
3273 if (result)
3274 return result;
3275 else
3276 return emit_move_multi_word (mode, x, y);
3279 if (GET_MODE_CLASS (mode) == MODE_CC)
3280 return emit_move_ccmode (mode, x, y);
3282 /* Try using a move pattern for the corresponding integer mode. This is
3283 only safe when simplify_subreg can convert MODE constants into integer
3284 constants. At present, it can only do this reliably if the value
3285 fits within a HOST_WIDE_INT. */
3286 if (!CONSTANT_P (y) || GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
3288 rtx ret = emit_move_via_integer (mode, x, y, false);
3289 if (ret)
3290 return ret;
3293 return emit_move_multi_word (mode, x, y);
3296 /* Generate code to copy Y into X.
3297 Both Y and X must have the same mode, except that
3298 Y can be a constant with VOIDmode.
3299 This mode cannot be BLKmode; use emit_block_move for that.
3301 Return the last instruction emitted. */
3304 emit_move_insn (rtx x, rtx y)
3306 enum machine_mode mode = GET_MODE (x);
3307 rtx y_cst = NULL_RTX;
3308 rtx last_insn, set;
3310 gcc_assert (mode != BLKmode
3311 && (GET_MODE (y) == mode || GET_MODE (y) == VOIDmode));
3313 if (CONSTANT_P (y))
3315 if (optimize
3316 && SCALAR_FLOAT_MODE_P (GET_MODE (x))
3317 && (last_insn = compress_float_constant (x, y)))
3318 return last_insn;
3320 y_cst = y;
3322 if (!LEGITIMATE_CONSTANT_P (y))
3324 y = force_const_mem (mode, y);
3326 /* If the target's cannot_force_const_mem prevented the spill,
3327 assume that the target's move expanders will also take care
3328 of the non-legitimate constant. */
3329 if (!y)
3330 y = y_cst;
3331 else
3332 y = use_anchored_address (y);
3336 /* If X or Y are memory references, verify that their addresses are valid
3337 for the machine. */
3338 if (MEM_P (x)
3339 && ((! memory_address_p (GET_MODE (x), XEXP (x, 0))
3340 && ! push_operand (x, GET_MODE (x)))
3341 || (flag_force_addr
3342 && CONSTANT_ADDRESS_P (XEXP (x, 0)))))
3343 x = validize_mem (x);
3345 if (MEM_P (y)
3346 && (! memory_address_p (GET_MODE (y), XEXP (y, 0))
3347 || (flag_force_addr
3348 && CONSTANT_ADDRESS_P (XEXP (y, 0)))))
3349 y = validize_mem (y);
3351 gcc_assert (mode != BLKmode);
3353 last_insn = emit_move_insn_1 (x, y);
3355 if (y_cst && REG_P (x)
3356 && (set = single_set (last_insn)) != NULL_RTX
3357 && SET_DEST (set) == x
3358 && ! rtx_equal_p (y_cst, SET_SRC (set)))
3359 set_unique_reg_note (last_insn, REG_EQUAL, y_cst);
3361 return last_insn;
3364 /* If Y is representable exactly in a narrower mode, and the target can
3365 perform the extension directly from constant or memory, then emit the
3366 move as an extension. */
3368 static rtx
3369 compress_float_constant (rtx x, rtx y)
3371 enum machine_mode dstmode = GET_MODE (x);
3372 enum machine_mode orig_srcmode = GET_MODE (y);
3373 enum machine_mode srcmode;
3374 REAL_VALUE_TYPE r;
3375 int oldcost, newcost;
3377 REAL_VALUE_FROM_CONST_DOUBLE (r, y);
3379 if (LEGITIMATE_CONSTANT_P (y))
3380 oldcost = rtx_cost (y, SET);
3381 else
3382 oldcost = rtx_cost (force_const_mem (dstmode, y), SET);
3384 for (srcmode = GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode));
3385 srcmode != orig_srcmode;
3386 srcmode = GET_MODE_WIDER_MODE (srcmode))
3388 enum insn_code ic;
3389 rtx trunc_y, last_insn;
3391 /* Skip if the target can't extend this way. */
3392 ic = can_extend_p (dstmode, srcmode, 0);
3393 if (ic == CODE_FOR_nothing)
3394 continue;
3396 /* Skip if the narrowed value isn't exact. */
3397 if (! exact_real_truncate (srcmode, &r))
3398 continue;
3400 trunc_y = CONST_DOUBLE_FROM_REAL_VALUE (r, srcmode);
3402 if (LEGITIMATE_CONSTANT_P (trunc_y))
3404 /* Skip if the target needs extra instructions to perform
3405 the extension. */
3406 if (! (*insn_data[ic].operand[1].predicate) (trunc_y, srcmode))
3407 continue;
3408 /* This is valid, but may not be cheaper than the original. */
3409 newcost = rtx_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y), SET);
3410 if (oldcost < newcost)
3411 continue;
3413 else if (float_extend_from_mem[dstmode][srcmode])
3415 trunc_y = force_const_mem (srcmode, trunc_y);
3416 /* This is valid, but may not be cheaper than the original. */
3417 newcost = rtx_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y), SET);
3418 if (oldcost < newcost)
3419 continue;
3420 trunc_y = validize_mem (trunc_y);
3422 else
3423 continue;
3425 /* For CSE's benefit, force the compressed constant pool entry
3426 into a new pseudo. This constant may be used in different modes,
3427 and if not, combine will put things back together for us. */
3428 trunc_y = force_reg (srcmode, trunc_y);
3429 emit_unop_insn (ic, x, trunc_y, UNKNOWN);
3430 last_insn = get_last_insn ();
3432 if (REG_P (x))
3433 set_unique_reg_note (last_insn, REG_EQUAL, y);
3435 return last_insn;
3438 return NULL_RTX;
3441 /* Pushing data onto the stack. */
3443 /* Push a block of length SIZE (perhaps variable)
3444 and return an rtx to address the beginning of the block.
3445 The value may be virtual_outgoing_args_rtx.
3447 EXTRA is the number of bytes of padding to push in addition to SIZE.
3448 BELOW nonzero means this padding comes at low addresses;
3449 otherwise, the padding comes at high addresses. */
3452 push_block (rtx size, int extra, int below)
3454 rtx temp;
3456 size = convert_modes (Pmode, ptr_mode, size, 1);
3457 if (CONSTANT_P (size))
3458 anti_adjust_stack (plus_constant (size, extra));
3459 else if (REG_P (size) && extra == 0)
3460 anti_adjust_stack (size);
3461 else
3463 temp = copy_to_mode_reg (Pmode, size);
3464 if (extra != 0)
3465 temp = expand_binop (Pmode, add_optab, temp, GEN_INT (extra),
3466 temp, 0, OPTAB_LIB_WIDEN);
3467 anti_adjust_stack (temp);
3470 #ifndef STACK_GROWS_DOWNWARD
3471 if (0)
3472 #else
3473 if (1)
3474 #endif
3476 temp = virtual_outgoing_args_rtx;
3477 if (extra != 0 && below)
3478 temp = plus_constant (temp, extra);
3480 else
3482 if (GET_CODE (size) == CONST_INT)
3483 temp = plus_constant (virtual_outgoing_args_rtx,
3484 -INTVAL (size) - (below ? 0 : extra));
3485 else if (extra != 0 && !below)
3486 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
3487 negate_rtx (Pmode, plus_constant (size, extra)));
3488 else
3489 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
3490 negate_rtx (Pmode, size));
3493 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT), temp);
3496 #ifdef PUSH_ROUNDING
3498 /* Emit single push insn. */
3500 static void
3501 emit_single_push_insn (enum machine_mode mode, rtx x, tree type)
3503 rtx dest_addr;
3504 unsigned rounded_size = PUSH_ROUNDING (GET_MODE_SIZE (mode));
3505 rtx dest;
3506 enum insn_code icode;
3507 insn_operand_predicate_fn pred;
3509 stack_pointer_delta += PUSH_ROUNDING (GET_MODE_SIZE (mode));
3510 /* If there is push pattern, use it. Otherwise try old way of throwing
3511 MEM representing push operation to move expander. */
3512 icode = push_optab->handlers[(int) mode].insn_code;
3513 if (icode != CODE_FOR_nothing)
3515 if (((pred = insn_data[(int) icode].operand[0].predicate)
3516 && !((*pred) (x, mode))))
3517 x = force_reg (mode, x);
3518 emit_insn (GEN_FCN (icode) (x));
3519 return;
3521 if (GET_MODE_SIZE (mode) == rounded_size)
3522 dest_addr = gen_rtx_fmt_e (STACK_PUSH_CODE, Pmode, stack_pointer_rtx);
3523 /* If we are to pad downward, adjust the stack pointer first and
3524 then store X into the stack location using an offset. This is
3525 because emit_move_insn does not know how to pad; it does not have
3526 access to type. */
3527 else if (FUNCTION_ARG_PADDING (mode, type) == downward)
3529 unsigned padding_size = rounded_size - GET_MODE_SIZE (mode);
3530 HOST_WIDE_INT offset;
3532 emit_move_insn (stack_pointer_rtx,
3533 expand_binop (Pmode,
3534 #ifdef STACK_GROWS_DOWNWARD
3535 sub_optab,
3536 #else
3537 add_optab,
3538 #endif
3539 stack_pointer_rtx,
3540 GEN_INT (rounded_size),
3541 NULL_RTX, 0, OPTAB_LIB_WIDEN));
3543 offset = (HOST_WIDE_INT) padding_size;
3544 #ifdef STACK_GROWS_DOWNWARD
3545 if (STACK_PUSH_CODE == POST_DEC)
3546 /* We have already decremented the stack pointer, so get the
3547 previous value. */
3548 offset += (HOST_WIDE_INT) rounded_size;
3549 #else
3550 if (STACK_PUSH_CODE == POST_INC)
3551 /* We have already incremented the stack pointer, so get the
3552 previous value. */
3553 offset -= (HOST_WIDE_INT) rounded_size;
3554 #endif
3555 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (offset));
3557 else
3559 #ifdef STACK_GROWS_DOWNWARD
3560 /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
3561 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3562 GEN_INT (-(HOST_WIDE_INT) rounded_size));
3563 #else
3564 /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
3565 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3566 GEN_INT (rounded_size));
3567 #endif
3568 dest_addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, dest_addr);
3571 dest = gen_rtx_MEM (mode, dest_addr);
3573 if (type != 0)
3575 set_mem_attributes (dest, type, 1);
3577 if (flag_optimize_sibling_calls)
3578 /* Function incoming arguments may overlap with sibling call
3579 outgoing arguments and we cannot allow reordering of reads
3580 from function arguments with stores to outgoing arguments
3581 of sibling calls. */
3582 set_mem_alias_set (dest, 0);
3584 emit_move_insn (dest, x);
3586 #endif
3588 /* Generate code to push X onto the stack, assuming it has mode MODE and
3589 type TYPE.
3590 MODE is redundant except when X is a CONST_INT (since they don't
3591 carry mode info).
3592 SIZE is an rtx for the size of data to be copied (in bytes),
3593 needed only if X is BLKmode.
3595 ALIGN (in bits) is maximum alignment we can assume.
3597 If PARTIAL and REG are both nonzero, then copy that many of the first
3598 bytes of X into registers starting with REG, and push the rest of X.
3599 The amount of space pushed is decreased by PARTIAL bytes.
3600 REG must be a hard register in this case.
3601 If REG is zero but PARTIAL is not, take any all others actions for an
3602 argument partially in registers, but do not actually load any
3603 registers.
3605 EXTRA is the amount in bytes of extra space to leave next to this arg.
3606 This is ignored if an argument block has already been allocated.
3608 On a machine that lacks real push insns, ARGS_ADDR is the address of
3609 the bottom of the argument block for this call. We use indexing off there
3610 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
3611 argument block has not been preallocated.
3613 ARGS_SO_FAR is the size of args previously pushed for this call.
3615 REG_PARM_STACK_SPACE is nonzero if functions require stack space
3616 for arguments passed in registers. If nonzero, it will be the number
3617 of bytes required. */
3619 void
3620 emit_push_insn (rtx x, enum machine_mode mode, tree type, rtx size,
3621 unsigned int align, int partial, rtx reg, int extra,
3622 rtx args_addr, rtx args_so_far, int reg_parm_stack_space,
3623 rtx alignment_pad)
3625 rtx xinner;
3626 enum direction stack_direction
3627 #ifdef STACK_GROWS_DOWNWARD
3628 = downward;
3629 #else
3630 = upward;
3631 #endif
3633 /* Decide where to pad the argument: `downward' for below,
3634 `upward' for above, or `none' for don't pad it.
3635 Default is below for small data on big-endian machines; else above. */
3636 enum direction where_pad = FUNCTION_ARG_PADDING (mode, type);
3638 /* Invert direction if stack is post-decrement.
3639 FIXME: why? */
3640 if (STACK_PUSH_CODE == POST_DEC)
3641 if (where_pad != none)
3642 where_pad = (where_pad == downward ? upward : downward);
3644 xinner = x;
3646 if (mode == BLKmode
3647 || (STRICT_ALIGNMENT && align < GET_MODE_ALIGNMENT (mode)))
3649 /* Copy a block into the stack, entirely or partially. */
3651 rtx temp;
3652 int used;
3653 int offset;
3654 int skip;
3656 offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
3657 used = partial - offset;
3659 if (mode != BLKmode)
3661 /* A value is to be stored in an insufficiently aligned
3662 stack slot; copy via a suitably aligned slot if
3663 necessary. */
3664 size = GEN_INT (GET_MODE_SIZE (mode));
3665 if (!MEM_P (xinner))
3667 temp = assign_temp (type, 0, 1, 1);
3668 emit_move_insn (temp, xinner);
3669 xinner = temp;
3673 gcc_assert (size);
3675 /* USED is now the # of bytes we need not copy to the stack
3676 because registers will take care of them. */
3678 if (partial != 0)
3679 xinner = adjust_address (xinner, BLKmode, used);
3681 /* If the partial register-part of the arg counts in its stack size,
3682 skip the part of stack space corresponding to the registers.
3683 Otherwise, start copying to the beginning of the stack space,
3684 by setting SKIP to 0. */
3685 skip = (reg_parm_stack_space == 0) ? 0 : used;
3687 #ifdef PUSH_ROUNDING
3688 /* Do it with several push insns if that doesn't take lots of insns
3689 and if there is no difficulty with push insns that skip bytes
3690 on the stack for alignment purposes. */
3691 if (args_addr == 0
3692 && PUSH_ARGS
3693 && GET_CODE (size) == CONST_INT
3694 && skip == 0
3695 && MEM_ALIGN (xinner) >= align
3696 && (MOVE_BY_PIECES_P ((unsigned) INTVAL (size) - used, align))
3697 /* Here we avoid the case of a structure whose weak alignment
3698 forces many pushes of a small amount of data,
3699 and such small pushes do rounding that causes trouble. */
3700 && ((! SLOW_UNALIGNED_ACCESS (word_mode, align))
3701 || align >= BIGGEST_ALIGNMENT
3702 || (PUSH_ROUNDING (align / BITS_PER_UNIT)
3703 == (align / BITS_PER_UNIT)))
3704 && PUSH_ROUNDING (INTVAL (size)) == INTVAL (size))
3706 /* Push padding now if padding above and stack grows down,
3707 or if padding below and stack grows up.
3708 But if space already allocated, this has already been done. */
3709 if (extra && args_addr == 0
3710 && where_pad != none && where_pad != stack_direction)
3711 anti_adjust_stack (GEN_INT (extra));
3713 move_by_pieces (NULL, xinner, INTVAL (size) - used, align, 0);
3715 else
3716 #endif /* PUSH_ROUNDING */
3718 rtx target;
3720 /* Otherwise make space on the stack and copy the data
3721 to the address of that space. */
3723 /* Deduct words put into registers from the size we must copy. */
3724 if (partial != 0)
3726 if (GET_CODE (size) == CONST_INT)
3727 size = GEN_INT (INTVAL (size) - used);
3728 else
3729 size = expand_binop (GET_MODE (size), sub_optab, size,
3730 GEN_INT (used), NULL_RTX, 0,
3731 OPTAB_LIB_WIDEN);
3734 /* Get the address of the stack space.
3735 In this case, we do not deal with EXTRA separately.
3736 A single stack adjust will do. */
3737 if (! args_addr)
3739 temp = push_block (size, extra, where_pad == downward);
3740 extra = 0;
3742 else if (GET_CODE (args_so_far) == CONST_INT)
3743 temp = memory_address (BLKmode,
3744 plus_constant (args_addr,
3745 skip + INTVAL (args_so_far)));
3746 else
3747 temp = memory_address (BLKmode,
3748 plus_constant (gen_rtx_PLUS (Pmode,
3749 args_addr,
3750 args_so_far),
3751 skip));
3753 if (!ACCUMULATE_OUTGOING_ARGS)
3755 /* If the source is referenced relative to the stack pointer,
3756 copy it to another register to stabilize it. We do not need
3757 to do this if we know that we won't be changing sp. */
3759 if (reg_mentioned_p (virtual_stack_dynamic_rtx, temp)
3760 || reg_mentioned_p (virtual_outgoing_args_rtx, temp))
3761 temp = copy_to_reg (temp);
3764 target = gen_rtx_MEM (BLKmode, temp);
3766 /* We do *not* set_mem_attributes here, because incoming arguments
3767 may overlap with sibling call outgoing arguments and we cannot
3768 allow reordering of reads from function arguments with stores
3769 to outgoing arguments of sibling calls. We do, however, want
3770 to record the alignment of the stack slot. */
3771 /* ALIGN may well be better aligned than TYPE, e.g. due to
3772 PARM_BOUNDARY. Assume the caller isn't lying. */
3773 set_mem_align (target, align);
3775 emit_block_move (target, xinner, size, BLOCK_OP_CALL_PARM);
3778 else if (partial > 0)
3780 /* Scalar partly in registers. */
3782 int size = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
3783 int i;
3784 int not_stack;
3785 /* # bytes of start of argument
3786 that we must make space for but need not store. */
3787 int offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
3788 int args_offset = INTVAL (args_so_far);
3789 int skip;
3791 /* Push padding now if padding above and stack grows down,
3792 or if padding below and stack grows up.
3793 But if space already allocated, this has already been done. */
3794 if (extra && args_addr == 0
3795 && where_pad != none && where_pad != stack_direction)
3796 anti_adjust_stack (GEN_INT (extra));
3798 /* If we make space by pushing it, we might as well push
3799 the real data. Otherwise, we can leave OFFSET nonzero
3800 and leave the space uninitialized. */
3801 if (args_addr == 0)
3802 offset = 0;
3804 /* Now NOT_STACK gets the number of words that we don't need to
3805 allocate on the stack. Convert OFFSET to words too. */
3806 not_stack = (partial - offset) / UNITS_PER_WORD;
3807 offset /= UNITS_PER_WORD;
3809 /* If the partial register-part of the arg counts in its stack size,
3810 skip the part of stack space corresponding to the registers.
3811 Otherwise, start copying to the beginning of the stack space,
3812 by setting SKIP to 0. */
3813 skip = (reg_parm_stack_space == 0) ? 0 : not_stack;
3815 if (CONSTANT_P (x) && ! LEGITIMATE_CONSTANT_P (x))
3816 x = validize_mem (force_const_mem (mode, x));
3818 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
3819 SUBREGs of such registers are not allowed. */
3820 if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER
3821 && GET_MODE_CLASS (GET_MODE (x)) != MODE_INT))
3822 x = copy_to_reg (x);
3824 /* Loop over all the words allocated on the stack for this arg. */
3825 /* We can do it by words, because any scalar bigger than a word
3826 has a size a multiple of a word. */
3827 #ifndef PUSH_ARGS_REVERSED
3828 for (i = not_stack; i < size; i++)
3829 #else
3830 for (i = size - 1; i >= not_stack; i--)
3831 #endif
3832 if (i >= not_stack + offset)
3833 emit_push_insn (operand_subword_force (x, i, mode),
3834 word_mode, NULL_TREE, NULL_RTX, align, 0, NULL_RTX,
3835 0, args_addr,
3836 GEN_INT (args_offset + ((i - not_stack + skip)
3837 * UNITS_PER_WORD)),
3838 reg_parm_stack_space, alignment_pad);
3840 else
3842 rtx addr;
3843 rtx dest;
3845 /* Push padding now if padding above and stack grows down,
3846 or if padding below and stack grows up.
3847 But if space already allocated, this has already been done. */
3848 if (extra && args_addr == 0
3849 && where_pad != none && where_pad != stack_direction)
3850 anti_adjust_stack (GEN_INT (extra));
3852 #ifdef PUSH_ROUNDING
3853 if (args_addr == 0 && PUSH_ARGS)
3854 emit_single_push_insn (mode, x, type);
3855 else
3856 #endif
3858 if (GET_CODE (args_so_far) == CONST_INT)
3859 addr
3860 = memory_address (mode,
3861 plus_constant (args_addr,
3862 INTVAL (args_so_far)));
3863 else
3864 addr = memory_address (mode, gen_rtx_PLUS (Pmode, args_addr,
3865 args_so_far));
3866 dest = gen_rtx_MEM (mode, addr);
3868 /* We do *not* set_mem_attributes here, because incoming arguments
3869 may overlap with sibling call outgoing arguments and we cannot
3870 allow reordering of reads from function arguments with stores
3871 to outgoing arguments of sibling calls. We do, however, want
3872 to record the alignment of the stack slot. */
3873 /* ALIGN may well be better aligned than TYPE, e.g. due to
3874 PARM_BOUNDARY. Assume the caller isn't lying. */
3875 set_mem_align (dest, align);
3877 emit_move_insn (dest, x);
3881 /* If part should go in registers, copy that part
3882 into the appropriate registers. Do this now, at the end,
3883 since mem-to-mem copies above may do function calls. */
3884 if (partial > 0 && reg != 0)
3886 /* Handle calls that pass values in multiple non-contiguous locations.
3887 The Irix 6 ABI has examples of this. */
3888 if (GET_CODE (reg) == PARALLEL)
3889 emit_group_load (reg, x, type, -1);
3890 else
3892 gcc_assert (partial % UNITS_PER_WORD == 0);
3893 move_block_to_reg (REGNO (reg), x, partial / UNITS_PER_WORD, mode);
3897 if (extra && args_addr == 0 && where_pad == stack_direction)
3898 anti_adjust_stack (GEN_INT (extra));
3900 if (alignment_pad && args_addr == 0)
3901 anti_adjust_stack (alignment_pad);
3904 /* Return X if X can be used as a subtarget in a sequence of arithmetic
3905 operations. */
3907 static rtx
3908 get_subtarget (rtx x)
3910 return (optimize
3911 || x == 0
3912 /* Only registers can be subtargets. */
3913 || !REG_P (x)
3914 /* Don't use hard regs to avoid extending their life. */
3915 || REGNO (x) < FIRST_PSEUDO_REGISTER
3916 ? 0 : x);
3919 /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
3920 FIELD is a bitfield. Returns true if the optimization was successful,
3921 and there's nothing else to do. */
3923 static bool
3924 optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize,
3925 unsigned HOST_WIDE_INT bitpos,
3926 enum machine_mode mode1, rtx str_rtx,
3927 tree to, tree src)
3929 enum machine_mode str_mode = GET_MODE (str_rtx);
3930 unsigned int str_bitsize = GET_MODE_BITSIZE (str_mode);
3931 tree op0, op1;
3932 rtx value, result;
3933 optab binop;
3935 if (mode1 != VOIDmode
3936 || bitsize >= BITS_PER_WORD
3937 || str_bitsize > BITS_PER_WORD
3938 || TREE_SIDE_EFFECTS (to)
3939 || TREE_THIS_VOLATILE (to))
3940 return false;
3942 STRIP_NOPS (src);
3943 if (!BINARY_CLASS_P (src)
3944 || TREE_CODE (TREE_TYPE (src)) != INTEGER_TYPE)
3945 return false;
3947 op0 = TREE_OPERAND (src, 0);
3948 op1 = TREE_OPERAND (src, 1);
3949 STRIP_NOPS (op0);
3951 if (!operand_equal_p (to, op0, 0))
3952 return false;
3954 if (MEM_P (str_rtx))
3956 unsigned HOST_WIDE_INT offset1;
3958 if (str_bitsize == 0 || str_bitsize > BITS_PER_WORD)
3959 str_mode = word_mode;
3960 str_mode = get_best_mode (bitsize, bitpos,
3961 MEM_ALIGN (str_rtx), str_mode, 0);
3962 if (str_mode == VOIDmode)
3963 return false;
3964 str_bitsize = GET_MODE_BITSIZE (str_mode);
3966 offset1 = bitpos;
3967 bitpos %= str_bitsize;
3968 offset1 = (offset1 - bitpos) / BITS_PER_UNIT;
3969 str_rtx = adjust_address (str_rtx, str_mode, offset1);
3971 else if (!REG_P (str_rtx) && GET_CODE (str_rtx) != SUBREG)
3972 return false;
3974 /* If the bit field covers the whole REG/MEM, store_field
3975 will likely generate better code. */
3976 if (bitsize >= str_bitsize)
3977 return false;
3979 /* We can't handle fields split across multiple entities. */
3980 if (bitpos + bitsize > str_bitsize)
3981 return false;
3983 if (BYTES_BIG_ENDIAN)
3984 bitpos = str_bitsize - bitpos - bitsize;
3986 switch (TREE_CODE (src))
3988 case PLUS_EXPR:
3989 case MINUS_EXPR:
3990 /* For now, just optimize the case of the topmost bitfield
3991 where we don't need to do any masking and also
3992 1 bit bitfields where xor can be used.
3993 We might win by one instruction for the other bitfields
3994 too if insv/extv instructions aren't used, so that
3995 can be added later. */
3996 if (bitpos + bitsize != str_bitsize
3997 && (bitsize != 1 || TREE_CODE (op1) != INTEGER_CST))
3998 break;
4000 value = expand_expr (op1, NULL_RTX, str_mode, 0);
4001 value = convert_modes (str_mode,
4002 TYPE_MODE (TREE_TYPE (op1)), value,
4003 TYPE_UNSIGNED (TREE_TYPE (op1)));
4005 /* We may be accessing data outside the field, which means
4006 we can alias adjacent data. */
4007 if (MEM_P (str_rtx))
4009 str_rtx = shallow_copy_rtx (str_rtx);
4010 set_mem_alias_set (str_rtx, 0);
4011 set_mem_expr (str_rtx, 0);
4014 binop = TREE_CODE (src) == PLUS_EXPR ? add_optab : sub_optab;
4015 if (bitsize == 1 && bitpos + bitsize != str_bitsize)
4017 value = expand_and (str_mode, value, const1_rtx, NULL);
4018 binop = xor_optab;
4020 value = expand_shift (LSHIFT_EXPR, str_mode, value,
4021 build_int_cst (NULL_TREE, bitpos),
4022 NULL_RTX, 1);
4023 result = expand_binop (str_mode, binop, str_rtx,
4024 value, str_rtx, 1, OPTAB_WIDEN);
4025 if (result != str_rtx)
4026 emit_move_insn (str_rtx, result);
4027 return true;
4029 case BIT_IOR_EXPR:
4030 case BIT_XOR_EXPR:
4031 if (TREE_CODE (op1) != INTEGER_CST)
4032 break;
4033 value = expand_expr (op1, NULL_RTX, GET_MODE (str_rtx), 0);
4034 value = convert_modes (GET_MODE (str_rtx),
4035 TYPE_MODE (TREE_TYPE (op1)), value,
4036 TYPE_UNSIGNED (TREE_TYPE (op1)));
4038 /* We may be accessing data outside the field, which means
4039 we can alias adjacent data. */
4040 if (MEM_P (str_rtx))
4042 str_rtx = shallow_copy_rtx (str_rtx);
4043 set_mem_alias_set (str_rtx, 0);
4044 set_mem_expr (str_rtx, 0);
4047 binop = TREE_CODE (src) == BIT_IOR_EXPR ? ior_optab : xor_optab;
4048 if (bitpos + bitsize != GET_MODE_BITSIZE (GET_MODE (str_rtx)))
4050 rtx mask = GEN_INT (((unsigned HOST_WIDE_INT) 1 << bitsize)
4051 - 1);
4052 value = expand_and (GET_MODE (str_rtx), value, mask,
4053 NULL_RTX);
4055 value = expand_shift (LSHIFT_EXPR, GET_MODE (str_rtx), value,
4056 build_int_cst (NULL_TREE, bitpos),
4057 NULL_RTX, 1);
4058 result = expand_binop (GET_MODE (str_rtx), binop, str_rtx,
4059 value, str_rtx, 1, OPTAB_WIDEN);
4060 if (result != str_rtx)
4061 emit_move_insn (str_rtx, result);
4062 return true;
4064 default:
4065 break;
4068 return false;
4072 /* Expand an assignment that stores the value of FROM into TO. */
4074 void
4075 expand_assignment (tree to, tree from)
4077 rtx to_rtx = 0;
4078 rtx result;
4080 /* Don't crash if the lhs of the assignment was erroneous. */
4081 if (TREE_CODE (to) == ERROR_MARK)
4083 result = expand_normal (from);
4084 return;
4087 /* Optimize away no-op moves without side-effects. */
4088 if (operand_equal_p (to, from, 0))
4089 return;
4091 /* Assignment of a structure component needs special treatment
4092 if the structure component's rtx is not simply a MEM.
4093 Assignment of an array element at a constant index, and assignment of
4094 an array element in an unaligned packed structure field, has the same
4095 problem. */
4096 if (handled_component_p (to)
4097 || TREE_CODE (TREE_TYPE (to)) == ARRAY_TYPE)
4099 enum machine_mode mode1;
4100 HOST_WIDE_INT bitsize, bitpos;
4101 tree offset;
4102 int unsignedp;
4103 int volatilep = 0;
4104 tree tem;
4106 push_temp_slots ();
4107 tem = get_inner_reference (to, &bitsize, &bitpos, &offset, &mode1,
4108 &unsignedp, &volatilep, true);
4110 /* If we are going to use store_bit_field and extract_bit_field,
4111 make sure to_rtx will be safe for multiple use. */
4113 to_rtx = expand_normal (tem);
4115 if (offset != 0)
4117 rtx offset_rtx;
4119 if (!MEM_P (to_rtx))
4121 /* We can get constant negative offsets into arrays with broken
4122 user code. Translate this to a trap instead of ICEing. */
4123 gcc_assert (TREE_CODE (offset) == INTEGER_CST);
4124 expand_builtin_trap ();
4125 to_rtx = gen_rtx_MEM (BLKmode, const0_rtx);
4128 offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, EXPAND_SUM);
4129 #ifdef POINTERS_EXTEND_UNSIGNED
4130 if (GET_MODE (offset_rtx) != Pmode)
4131 offset_rtx = convert_to_mode (Pmode, offset_rtx, 0);
4132 #else
4133 if (GET_MODE (offset_rtx) != ptr_mode)
4134 offset_rtx = convert_to_mode (ptr_mode, offset_rtx, 0);
4135 #endif
4137 /* A constant address in TO_RTX can have VOIDmode, we must not try
4138 to call force_reg for that case. Avoid that case. */
4139 if (MEM_P (to_rtx)
4140 && GET_MODE (to_rtx) == BLKmode
4141 && GET_MODE (XEXP (to_rtx, 0)) != VOIDmode
4142 && bitsize > 0
4143 && (bitpos % bitsize) == 0
4144 && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
4145 && MEM_ALIGN (to_rtx) == GET_MODE_ALIGNMENT (mode1))
4147 to_rtx = adjust_address (to_rtx, mode1, bitpos / BITS_PER_UNIT);
4148 bitpos = 0;
4151 to_rtx = offset_address (to_rtx, offset_rtx,
4152 highest_pow2_factor_for_target (to,
4153 offset));
4156 /* Handle expand_expr of a complex value returning a CONCAT. */
4157 if (GET_CODE (to_rtx) == CONCAT)
4159 if (TREE_CODE (TREE_TYPE (from)) == COMPLEX_TYPE)
4161 gcc_assert (bitpos == 0);
4162 result = store_expr (from, to_rtx, false);
4164 else
4166 gcc_assert (bitpos == 0 || bitpos == GET_MODE_BITSIZE (mode1));
4167 result = store_expr (from, XEXP (to_rtx, bitpos != 0), false);
4170 else
4172 if (MEM_P (to_rtx))
4174 /* If the field is at offset zero, we could have been given the
4175 DECL_RTX of the parent struct. Don't munge it. */
4176 to_rtx = shallow_copy_rtx (to_rtx);
4178 set_mem_attributes_minus_bitpos (to_rtx, to, 0, bitpos);
4180 /* Deal with volatile and readonly fields. The former is only
4181 done for MEM. Also set MEM_KEEP_ALIAS_SET_P if needed. */
4182 if (volatilep)
4183 MEM_VOLATILE_P (to_rtx) = 1;
4184 if (component_uses_parent_alias_set (to))
4185 MEM_KEEP_ALIAS_SET_P (to_rtx) = 1;
4188 if (optimize_bitfield_assignment_op (bitsize, bitpos, mode1,
4189 to_rtx, to, from))
4190 result = NULL;
4191 else
4192 result = store_field (to_rtx, bitsize, bitpos, mode1, from,
4193 TREE_TYPE (tem), get_alias_set (to));
4196 if (result)
4197 preserve_temp_slots (result);
4198 free_temp_slots ();
4199 pop_temp_slots ();
4200 return;
4203 /* If the rhs is a function call and its value is not an aggregate,
4204 call the function before we start to compute the lhs.
4205 This is needed for correct code for cases such as
4206 val = setjmp (buf) on machines where reference to val
4207 requires loading up part of an address in a separate insn.
4209 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
4210 since it might be a promoted variable where the zero- or sign- extension
4211 needs to be done. Handling this in the normal way is safe because no
4212 computation is done before the call. */
4213 if (TREE_CODE (from) == CALL_EXPR && ! aggregate_value_p (from, from)
4214 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from))) == INTEGER_CST
4215 && ! ((TREE_CODE (to) == VAR_DECL || TREE_CODE (to) == PARM_DECL)
4216 && REG_P (DECL_RTL (to))))
4218 rtx value;
4220 push_temp_slots ();
4221 value = expand_normal (from);
4222 if (to_rtx == 0)
4223 to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
4225 /* Handle calls that return values in multiple non-contiguous locations.
4226 The Irix 6 ABI has examples of this. */
4227 if (GET_CODE (to_rtx) == PARALLEL)
4228 emit_group_load (to_rtx, value, TREE_TYPE (from),
4229 int_size_in_bytes (TREE_TYPE (from)));
4230 else if (GET_MODE (to_rtx) == BLKmode)
4231 emit_block_move (to_rtx, value, expr_size (from), BLOCK_OP_NORMAL);
4232 else
4234 if (POINTER_TYPE_P (TREE_TYPE (to)))
4235 value = convert_memory_address (GET_MODE (to_rtx), value);
4236 emit_move_insn (to_rtx, value);
4238 preserve_temp_slots (to_rtx);
4239 free_temp_slots ();
4240 pop_temp_slots ();
4241 return;
4244 /* Ordinary treatment. Expand TO to get a REG or MEM rtx.
4245 Don't re-expand if it was expanded already (in COMPONENT_REF case). */
4247 if (to_rtx == 0)
4248 to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
4250 /* Don't move directly into a return register. */
4251 if (TREE_CODE (to) == RESULT_DECL
4252 && (REG_P (to_rtx) || GET_CODE (to_rtx) == PARALLEL))
4254 rtx temp;
4256 push_temp_slots ();
4257 temp = expand_expr (from, 0, GET_MODE (to_rtx), 0);
4259 if (GET_CODE (to_rtx) == PARALLEL)
4260 emit_group_load (to_rtx, temp, TREE_TYPE (from),
4261 int_size_in_bytes (TREE_TYPE (from)));
4262 else
4263 emit_move_insn (to_rtx, temp);
4265 preserve_temp_slots (to_rtx);
4266 free_temp_slots ();
4267 pop_temp_slots ();
4268 return;
4271 /* In case we are returning the contents of an object which overlaps
4272 the place the value is being stored, use a safe function when copying
4273 a value through a pointer into a structure value return block. */
4274 if (TREE_CODE (to) == RESULT_DECL && TREE_CODE (from) == INDIRECT_REF
4275 && current_function_returns_struct
4276 && !current_function_returns_pcc_struct)
4278 rtx from_rtx, size;
4280 push_temp_slots ();
4281 size = expr_size (from);
4282 from_rtx = expand_normal (from);
4284 emit_library_call (memmove_libfunc, LCT_NORMAL,
4285 VOIDmode, 3, XEXP (to_rtx, 0), Pmode,
4286 XEXP (from_rtx, 0), Pmode,
4287 convert_to_mode (TYPE_MODE (sizetype),
4288 size, TYPE_UNSIGNED (sizetype)),
4289 TYPE_MODE (sizetype));
4291 preserve_temp_slots (to_rtx);
4292 free_temp_slots ();
4293 pop_temp_slots ();
4294 return;
4297 /* Compute FROM and store the value in the rtx we got. */
4299 push_temp_slots ();
4300 result = store_expr (from, to_rtx, 0);
4301 preserve_temp_slots (result);
4302 free_temp_slots ();
4303 pop_temp_slots ();
4304 return;
4307 /* Generate code for computing expression EXP,
4308 and storing the value into TARGET.
4310 If the mode is BLKmode then we may return TARGET itself.
4311 It turns out that in BLKmode it doesn't cause a problem.
4312 because C has no operators that could combine two different
4313 assignments into the same BLKmode object with different values
4314 with no sequence point. Will other languages need this to
4315 be more thorough?
4317 If CALL_PARAM_P is nonzero, this is a store into a call param on the
4318 stack, and block moves may need to be treated specially. */
4321 store_expr (tree exp, rtx target, int call_param_p)
4323 rtx temp;
4324 rtx alt_rtl = NULL_RTX;
4325 int dont_return_target = 0;
4327 if (VOID_TYPE_P (TREE_TYPE (exp)))
4329 /* C++ can generate ?: expressions with a throw expression in one
4330 branch and an rvalue in the other. Here, we resolve attempts to
4331 store the throw expression's nonexistent result. */
4332 gcc_assert (!call_param_p);
4333 expand_expr (exp, const0_rtx, VOIDmode, 0);
4334 return NULL_RTX;
4336 if (TREE_CODE (exp) == COMPOUND_EXPR)
4338 /* Perform first part of compound expression, then assign from second
4339 part. */
4340 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
4341 call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
4342 return store_expr (TREE_OPERAND (exp, 1), target, call_param_p);
4344 else if (TREE_CODE (exp) == COND_EXPR && GET_MODE (target) == BLKmode)
4346 /* For conditional expression, get safe form of the target. Then
4347 test the condition, doing the appropriate assignment on either
4348 side. This avoids the creation of unnecessary temporaries.
4349 For non-BLKmode, it is more efficient not to do this. */
4351 rtx lab1 = gen_label_rtx (), lab2 = gen_label_rtx ();
4353 do_pending_stack_adjust ();
4354 NO_DEFER_POP;
4355 jumpifnot (TREE_OPERAND (exp, 0), lab1);
4356 store_expr (TREE_OPERAND (exp, 1), target, call_param_p);
4357 emit_jump_insn (gen_jump (lab2));
4358 emit_barrier ();
4359 emit_label (lab1);
4360 store_expr (TREE_OPERAND (exp, 2), target, call_param_p);
4361 emit_label (lab2);
4362 OK_DEFER_POP;
4364 return NULL_RTX;
4366 else if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target))
4367 /* If this is a scalar in a register that is stored in a wider mode
4368 than the declared mode, compute the result into its declared mode
4369 and then convert to the wider mode. Our value is the computed
4370 expression. */
4372 rtx inner_target = 0;
4374 /* We can do the conversion inside EXP, which will often result
4375 in some optimizations. Do the conversion in two steps: first
4376 change the signedness, if needed, then the extend. But don't
4377 do this if the type of EXP is a subtype of something else
4378 since then the conversion might involve more than just
4379 converting modes. */
4380 if (INTEGRAL_TYPE_P (TREE_TYPE (exp))
4381 && TREE_TYPE (TREE_TYPE (exp)) == 0
4382 && (!lang_hooks.reduce_bit_field_operations
4383 || (GET_MODE_PRECISION (GET_MODE (target))
4384 == TYPE_PRECISION (TREE_TYPE (exp)))))
4386 if (TYPE_UNSIGNED (TREE_TYPE (exp))
4387 != SUBREG_PROMOTED_UNSIGNED_P (target))
4388 exp = fold_convert
4389 (lang_hooks.types.signed_or_unsigned_type
4390 (SUBREG_PROMOTED_UNSIGNED_P (target), TREE_TYPE (exp)), exp);
4392 exp = fold_convert (lang_hooks.types.type_for_mode
4393 (GET_MODE (SUBREG_REG (target)),
4394 SUBREG_PROMOTED_UNSIGNED_P (target)),
4395 exp);
4397 inner_target = SUBREG_REG (target);
4400 temp = expand_expr (exp, inner_target, VOIDmode,
4401 call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
4403 /* If TEMP is a VOIDmode constant, use convert_modes to make
4404 sure that we properly convert it. */
4405 if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode)
4407 temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
4408 temp, SUBREG_PROMOTED_UNSIGNED_P (target));
4409 temp = convert_modes (GET_MODE (SUBREG_REG (target)),
4410 GET_MODE (target), temp,
4411 SUBREG_PROMOTED_UNSIGNED_P (target));
4414 convert_move (SUBREG_REG (target), temp,
4415 SUBREG_PROMOTED_UNSIGNED_P (target));
4417 return NULL_RTX;
4419 else
4421 temp = expand_expr_real (exp, target, GET_MODE (target),
4422 (call_param_p
4423 ? EXPAND_STACK_PARM : EXPAND_NORMAL),
4424 &alt_rtl);
4425 /* Return TARGET if it's a specified hardware register.
4426 If TARGET is a volatile mem ref, either return TARGET
4427 or return a reg copied *from* TARGET; ANSI requires this.
4429 Otherwise, if TEMP is not TARGET, return TEMP
4430 if it is constant (for efficiency),
4431 or if we really want the correct value. */
4432 if (!(target && REG_P (target)
4433 && REGNO (target) < FIRST_PSEUDO_REGISTER)
4434 && !(MEM_P (target) && MEM_VOLATILE_P (target))
4435 && ! rtx_equal_p (temp, target)
4436 && CONSTANT_P (temp))
4437 dont_return_target = 1;
4440 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
4441 the same as that of TARGET, adjust the constant. This is needed, for
4442 example, in case it is a CONST_DOUBLE and we want only a word-sized
4443 value. */
4444 if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode
4445 && TREE_CODE (exp) != ERROR_MARK
4446 && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
4447 temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
4448 temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
4450 /* If value was not generated in the target, store it there.
4451 Convert the value to TARGET's type first if necessary and emit the
4452 pending incrementations that have been queued when expanding EXP.
4453 Note that we cannot emit the whole queue blindly because this will
4454 effectively disable the POST_INC optimization later.
4456 If TEMP and TARGET compare equal according to rtx_equal_p, but
4457 one or both of them are volatile memory refs, we have to distinguish
4458 two cases:
4459 - expand_expr has used TARGET. In this case, we must not generate
4460 another copy. This can be detected by TARGET being equal according
4461 to == .
4462 - expand_expr has not used TARGET - that means that the source just
4463 happens to have the same RTX form. Since temp will have been created
4464 by expand_expr, it will compare unequal according to == .
4465 We must generate a copy in this case, to reach the correct number
4466 of volatile memory references. */
4468 if ((! rtx_equal_p (temp, target)
4469 || (temp != target && (side_effects_p (temp)
4470 || side_effects_p (target))))
4471 && TREE_CODE (exp) != ERROR_MARK
4472 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
4473 but TARGET is not valid memory reference, TEMP will differ
4474 from TARGET although it is really the same location. */
4475 && !(alt_rtl && rtx_equal_p (alt_rtl, target))
4476 /* If there's nothing to copy, don't bother. Don't call
4477 expr_size unless necessary, because some front-ends (C++)
4478 expr_size-hook must not be given objects that are not
4479 supposed to be bit-copied or bit-initialized. */
4480 && expr_size (exp) != const0_rtx)
4482 if (GET_MODE (temp) != GET_MODE (target)
4483 && GET_MODE (temp) != VOIDmode)
4485 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (exp));
4486 if (dont_return_target)
4488 /* In this case, we will return TEMP,
4489 so make sure it has the proper mode.
4490 But don't forget to store the value into TARGET. */
4491 temp = convert_to_mode (GET_MODE (target), temp, unsignedp);
4492 emit_move_insn (target, temp);
4494 else
4495 convert_move (target, temp, unsignedp);
4498 else if (GET_MODE (temp) == BLKmode && TREE_CODE (exp) == STRING_CST)
4500 /* Handle copying a string constant into an array. The string
4501 constant may be shorter than the array. So copy just the string's
4502 actual length, and clear the rest. First get the size of the data
4503 type of the string, which is actually the size of the target. */
4504 rtx size = expr_size (exp);
4506 if (GET_CODE (size) == CONST_INT
4507 && INTVAL (size) < TREE_STRING_LENGTH (exp))
4508 emit_block_move (target, temp, size,
4509 (call_param_p
4510 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
4511 else
4513 /* Compute the size of the data to copy from the string. */
4514 tree copy_size
4515 = size_binop (MIN_EXPR,
4516 make_tree (sizetype, size),
4517 size_int (TREE_STRING_LENGTH (exp)));
4518 rtx copy_size_rtx
4519 = expand_expr (copy_size, NULL_RTX, VOIDmode,
4520 (call_param_p
4521 ? EXPAND_STACK_PARM : EXPAND_NORMAL));
4522 rtx label = 0;
4524 /* Copy that much. */
4525 copy_size_rtx = convert_to_mode (ptr_mode, copy_size_rtx,
4526 TYPE_UNSIGNED (sizetype));
4527 emit_block_move (target, temp, copy_size_rtx,
4528 (call_param_p
4529 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
4531 /* Figure out how much is left in TARGET that we have to clear.
4532 Do all calculations in ptr_mode. */
4533 if (GET_CODE (copy_size_rtx) == CONST_INT)
4535 size = plus_constant (size, -INTVAL (copy_size_rtx));
4536 target = adjust_address (target, BLKmode,
4537 INTVAL (copy_size_rtx));
4539 else
4541 size = expand_binop (TYPE_MODE (sizetype), sub_optab, size,
4542 copy_size_rtx, NULL_RTX, 0,
4543 OPTAB_LIB_WIDEN);
4545 #ifdef POINTERS_EXTEND_UNSIGNED
4546 if (GET_MODE (copy_size_rtx) != Pmode)
4547 copy_size_rtx = convert_to_mode (Pmode, copy_size_rtx,
4548 TYPE_UNSIGNED (sizetype));
4549 #endif
4551 target = offset_address (target, copy_size_rtx,
4552 highest_pow2_factor (copy_size));
4553 label = gen_label_rtx ();
4554 emit_cmp_and_jump_insns (size, const0_rtx, LT, NULL_RTX,
4555 GET_MODE (size), 0, label);
4558 if (size != const0_rtx)
4559 clear_storage (target, size, BLOCK_OP_NORMAL);
4561 if (label)
4562 emit_label (label);
4565 /* Handle calls that return values in multiple non-contiguous locations.
4566 The Irix 6 ABI has examples of this. */
4567 else if (GET_CODE (target) == PARALLEL)
4568 emit_group_load (target, temp, TREE_TYPE (exp),
4569 int_size_in_bytes (TREE_TYPE (exp)));
4570 else if (GET_MODE (temp) == BLKmode)
4571 emit_block_move (target, temp, expr_size (exp),
4572 (call_param_p
4573 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
4574 else
4576 temp = force_operand (temp, target);
4577 if (temp != target)
4578 emit_move_insn (target, temp);
4582 return NULL_RTX;
4585 /* Helper for categorize_ctor_elements. Identical interface. */
4587 static bool
4588 categorize_ctor_elements_1 (tree ctor, HOST_WIDE_INT *p_nz_elts,
4589 HOST_WIDE_INT *p_elt_count,
4590 bool *p_must_clear)
4592 unsigned HOST_WIDE_INT idx;
4593 HOST_WIDE_INT nz_elts, elt_count;
4594 tree value, purpose;
4596 /* Whether CTOR is a valid constant initializer, in accordance with what
4597 initializer_constant_valid_p does. If inferred from the constructor
4598 elements, true until proven otherwise. */
4599 bool const_from_elts_p = constructor_static_from_elts_p (ctor);
4600 bool const_p = const_from_elts_p ? true : TREE_STATIC (ctor);
4602 nz_elts = 0;
4603 elt_count = 0;
4605 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), idx, purpose, value)
4607 HOST_WIDE_INT mult;
4609 mult = 1;
4610 if (TREE_CODE (purpose) == RANGE_EXPR)
4612 tree lo_index = TREE_OPERAND (purpose, 0);
4613 tree hi_index = TREE_OPERAND (purpose, 1);
4615 if (host_integerp (lo_index, 1) && host_integerp (hi_index, 1))
4616 mult = (tree_low_cst (hi_index, 1)
4617 - tree_low_cst (lo_index, 1) + 1);
4620 switch (TREE_CODE (value))
4622 case CONSTRUCTOR:
4624 HOST_WIDE_INT nz = 0, ic = 0;
4626 bool const_elt_p
4627 = categorize_ctor_elements_1 (value, &nz, &ic, p_must_clear);
4629 nz_elts += mult * nz;
4630 elt_count += mult * ic;
4632 if (const_from_elts_p && const_p)
4633 const_p = const_elt_p;
4635 break;
4637 case INTEGER_CST:
4638 case REAL_CST:
4639 if (!initializer_zerop (value))
4640 nz_elts += mult;
4641 elt_count += mult;
4642 break;
4644 case STRING_CST:
4645 nz_elts += mult * TREE_STRING_LENGTH (value);
4646 elt_count += mult * TREE_STRING_LENGTH (value);
4647 break;
4649 case COMPLEX_CST:
4650 if (!initializer_zerop (TREE_REALPART (value)))
4651 nz_elts += mult;
4652 if (!initializer_zerop (TREE_IMAGPART (value)))
4653 nz_elts += mult;
4654 elt_count += mult;
4655 break;
4657 case VECTOR_CST:
4659 tree v;
4660 for (v = TREE_VECTOR_CST_ELTS (value); v; v = TREE_CHAIN (v))
4662 if (!initializer_zerop (TREE_VALUE (v)))
4663 nz_elts += mult;
4664 elt_count += mult;
4667 break;
4669 default:
4670 nz_elts += mult;
4671 elt_count += mult;
4673 if (const_from_elts_p && const_p)
4674 const_p = initializer_constant_valid_p (value, TREE_TYPE (value))
4675 != NULL_TREE;
4676 break;
4680 if (!*p_must_clear
4681 && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
4682 || TREE_CODE (TREE_TYPE (ctor)) == QUAL_UNION_TYPE))
4684 tree init_sub_type;
4685 bool clear_this = true;
4687 if (!VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor)))
4689 /* We don't expect more than one element of the union to be
4690 initialized. Not sure what we should do otherwise... */
4691 gcc_assert (VEC_length (constructor_elt, CONSTRUCTOR_ELTS (ctor))
4692 == 1);
4694 init_sub_type = TREE_TYPE (VEC_index (constructor_elt,
4695 CONSTRUCTOR_ELTS (ctor),
4696 0)->value);
4698 /* ??? We could look at each element of the union, and find the
4699 largest element. Which would avoid comparing the size of the
4700 initialized element against any tail padding in the union.
4701 Doesn't seem worth the effort... */
4702 if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (ctor)),
4703 TYPE_SIZE (init_sub_type)) == 1)
4705 /* And now we have to find out if the element itself is fully
4706 constructed. E.g. for union { struct { int a, b; } s; } u
4707 = { .s = { .a = 1 } }. */
4708 if (elt_count == count_type_elements (init_sub_type, false))
4709 clear_this = false;
4713 *p_must_clear = clear_this;
4716 *p_nz_elts += nz_elts;
4717 *p_elt_count += elt_count;
4719 return const_p;
4722 /* Examine CTOR to discover:
4723 * how many scalar fields are set to nonzero values,
4724 and place it in *P_NZ_ELTS;
4725 * how many scalar fields in total are in CTOR,
4726 and place it in *P_ELT_COUNT.
4727 * if a type is a union, and the initializer from the constructor
4728 is not the largest element in the union, then set *p_must_clear.
4730 Return whether or not CTOR is a valid static constant initializer, the same
4731 as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
4733 bool
4734 categorize_ctor_elements (tree ctor, HOST_WIDE_INT *p_nz_elts,
4735 HOST_WIDE_INT *p_elt_count,
4736 bool *p_must_clear)
4738 *p_nz_elts = 0;
4739 *p_elt_count = 0;
4740 *p_must_clear = false;
4742 return
4743 categorize_ctor_elements_1 (ctor, p_nz_elts, p_elt_count, p_must_clear);
4746 /* Count the number of scalars in TYPE. Return -1 on overflow or
4747 variable-sized. If ALLOW_FLEXARR is true, don't count flexible
4748 array member at the end of the structure. */
4750 HOST_WIDE_INT
4751 count_type_elements (tree type, bool allow_flexarr)
4753 const HOST_WIDE_INT max = ~((HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT-1));
4754 switch (TREE_CODE (type))
4756 case ARRAY_TYPE:
4758 tree telts = array_type_nelts (type);
4759 if (telts && host_integerp (telts, 1))
4761 HOST_WIDE_INT n = tree_low_cst (telts, 1) + 1;
4762 HOST_WIDE_INT m = count_type_elements (TREE_TYPE (type), false);
4763 if (n == 0)
4764 return 0;
4765 else if (max / n > m)
4766 return n * m;
4768 return -1;
4771 case RECORD_TYPE:
4773 HOST_WIDE_INT n = 0, t;
4774 tree f;
4776 for (f = TYPE_FIELDS (type); f ; f = TREE_CHAIN (f))
4777 if (TREE_CODE (f) == FIELD_DECL)
4779 t = count_type_elements (TREE_TYPE (f), false);
4780 if (t < 0)
4782 /* Check for structures with flexible array member. */
4783 tree tf = TREE_TYPE (f);
4784 if (allow_flexarr
4785 && TREE_CHAIN (f) == NULL
4786 && TREE_CODE (tf) == ARRAY_TYPE
4787 && TYPE_DOMAIN (tf)
4788 && TYPE_MIN_VALUE (TYPE_DOMAIN (tf))
4789 && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf)))
4790 && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf))
4791 && int_size_in_bytes (type) >= 0)
4792 break;
4794 return -1;
4796 n += t;
4799 return n;
4802 case UNION_TYPE:
4803 case QUAL_UNION_TYPE:
4805 /* Ho hum. How in the world do we guess here? Clearly it isn't
4806 right to count the fields. Guess based on the number of words. */
4807 HOST_WIDE_INT n = int_size_in_bytes (type);
4808 if (n < 0)
4809 return -1;
4810 return n / UNITS_PER_WORD;
4813 case COMPLEX_TYPE:
4814 return 2;
4816 case VECTOR_TYPE:
4817 return TYPE_VECTOR_SUBPARTS (type);
4819 case INTEGER_TYPE:
4820 case REAL_TYPE:
4821 case ENUMERAL_TYPE:
4822 case BOOLEAN_TYPE:
4823 case POINTER_TYPE:
4824 case OFFSET_TYPE:
4825 case REFERENCE_TYPE:
4826 return 1;
4828 case VOID_TYPE:
4829 case METHOD_TYPE:
4830 case FUNCTION_TYPE:
4831 case LANG_TYPE:
4832 default:
4833 gcc_unreachable ();
4837 /* Return 1 if EXP contains mostly (3/4) zeros. */
4839 static int
4840 mostly_zeros_p (tree exp)
4842 if (TREE_CODE (exp) == CONSTRUCTOR)
4845 HOST_WIDE_INT nz_elts, count, elts;
4846 bool must_clear;
4848 categorize_ctor_elements (exp, &nz_elts, &count, &must_clear);
4849 if (must_clear)
4850 return 1;
4852 elts = count_type_elements (TREE_TYPE (exp), false);
4854 return nz_elts < elts / 4;
4857 return initializer_zerop (exp);
4860 /* Return 1 if EXP contains all zeros. */
4862 static int
4863 all_zeros_p (tree exp)
4865 if (TREE_CODE (exp) == CONSTRUCTOR)
4868 HOST_WIDE_INT nz_elts, count;
4869 bool must_clear;
4871 categorize_ctor_elements (exp, &nz_elts, &count, &must_clear);
4872 return nz_elts == 0;
4875 return initializer_zerop (exp);
4878 /* Helper function for store_constructor.
4879 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
4880 TYPE is the type of the CONSTRUCTOR, not the element type.
4881 CLEARED is as for store_constructor.
4882 ALIAS_SET is the alias set to use for any stores.
4884 This provides a recursive shortcut back to store_constructor when it isn't
4885 necessary to go through store_field. This is so that we can pass through
4886 the cleared field to let store_constructor know that we may not have to
4887 clear a substructure if the outer structure has already been cleared. */
4889 static void
4890 store_constructor_field (rtx target, unsigned HOST_WIDE_INT bitsize,
4891 HOST_WIDE_INT bitpos, enum machine_mode mode,
4892 tree exp, tree type, int cleared, int alias_set)
4894 if (TREE_CODE (exp) == CONSTRUCTOR
4895 /* We can only call store_constructor recursively if the size and
4896 bit position are on a byte boundary. */
4897 && bitpos % BITS_PER_UNIT == 0
4898 && (bitsize > 0 && bitsize % BITS_PER_UNIT == 0)
4899 /* If we have a nonzero bitpos for a register target, then we just
4900 let store_field do the bitfield handling. This is unlikely to
4901 generate unnecessary clear instructions anyways. */
4902 && (bitpos == 0 || MEM_P (target)))
4904 if (MEM_P (target))
4905 target
4906 = adjust_address (target,
4907 GET_MODE (target) == BLKmode
4908 || 0 != (bitpos
4909 % GET_MODE_ALIGNMENT (GET_MODE (target)))
4910 ? BLKmode : VOIDmode, bitpos / BITS_PER_UNIT);
4913 /* Update the alias set, if required. */
4914 if (MEM_P (target) && ! MEM_KEEP_ALIAS_SET_P (target)
4915 && MEM_ALIAS_SET (target) != 0)
4917 target = copy_rtx (target);
4918 set_mem_alias_set (target, alias_set);
4921 store_constructor (exp, target, cleared, bitsize / BITS_PER_UNIT);
4923 else
4924 store_field (target, bitsize, bitpos, mode, exp, type, alias_set);
4927 /* Store the value of constructor EXP into the rtx TARGET.
4928 TARGET is either a REG or a MEM; we know it cannot conflict, since
4929 safe_from_p has been called.
4930 CLEARED is true if TARGET is known to have been zero'd.
4931 SIZE is the number of bytes of TARGET we are allowed to modify: this
4932 may not be the same as the size of EXP if we are assigning to a field
4933 which has been packed to exclude padding bits. */
4935 static void
4936 store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size)
4938 tree type = TREE_TYPE (exp);
4939 #ifdef WORD_REGISTER_OPERATIONS
4940 HOST_WIDE_INT exp_size = int_size_in_bytes (type);
4941 #endif
4943 switch (TREE_CODE (type))
4945 case RECORD_TYPE:
4946 case UNION_TYPE:
4947 case QUAL_UNION_TYPE:
4949 unsigned HOST_WIDE_INT idx;
4950 tree field, value;
4952 /* If size is zero or the target is already cleared, do nothing. */
4953 if (size == 0 || cleared)
4954 cleared = 1;
4955 /* We either clear the aggregate or indicate the value is dead. */
4956 else if ((TREE_CODE (type) == UNION_TYPE
4957 || TREE_CODE (type) == QUAL_UNION_TYPE)
4958 && ! CONSTRUCTOR_ELTS (exp))
4959 /* If the constructor is empty, clear the union. */
4961 clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
4962 cleared = 1;
4965 /* If we are building a static constructor into a register,
4966 set the initial value as zero so we can fold the value into
4967 a constant. But if more than one register is involved,
4968 this probably loses. */
4969 else if (REG_P (target) && TREE_STATIC (exp)
4970 && GET_MODE_SIZE (GET_MODE (target)) <= UNITS_PER_WORD)
4972 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
4973 cleared = 1;
4976 /* If the constructor has fewer fields than the structure or
4977 if we are initializing the structure to mostly zeros, clear
4978 the whole structure first. Don't do this if TARGET is a
4979 register whose mode size isn't equal to SIZE since
4980 clear_storage can't handle this case. */
4981 else if (size > 0
4982 && (((int)VEC_length (constructor_elt, CONSTRUCTOR_ELTS (exp))
4983 != fields_length (type))
4984 || mostly_zeros_p (exp))
4985 && (!REG_P (target)
4986 || ((HOST_WIDE_INT) GET_MODE_SIZE (GET_MODE (target))
4987 == size)))
4989 clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
4990 cleared = 1;
4993 if (! cleared)
4994 emit_insn (gen_rtx_CLOBBER (VOIDmode, target));
4996 /* Store each element of the constructor into the
4997 corresponding field of TARGET. */
4998 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, field, value)
5000 enum machine_mode mode;
5001 HOST_WIDE_INT bitsize;
5002 HOST_WIDE_INT bitpos = 0;
5003 tree offset;
5004 rtx to_rtx = target;
5006 /* Just ignore missing fields. We cleared the whole
5007 structure, above, if any fields are missing. */
5008 if (field == 0)
5009 continue;
5011 if (cleared && initializer_zerop (value))
5012 continue;
5014 if (host_integerp (DECL_SIZE (field), 1))
5015 bitsize = tree_low_cst (DECL_SIZE (field), 1);
5016 else
5017 bitsize = -1;
5019 mode = DECL_MODE (field);
5020 if (DECL_BIT_FIELD (field))
5021 mode = VOIDmode;
5023 offset = DECL_FIELD_OFFSET (field);
5024 if (host_integerp (offset, 0)
5025 && host_integerp (bit_position (field), 0))
5027 bitpos = int_bit_position (field);
5028 offset = 0;
5030 else
5031 bitpos = tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 0);
5033 if (offset)
5035 rtx offset_rtx;
5037 offset
5038 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset,
5039 make_tree (TREE_TYPE (exp),
5040 target));
5042 offset_rtx = expand_normal (offset);
5043 gcc_assert (MEM_P (to_rtx));
5045 #ifdef POINTERS_EXTEND_UNSIGNED
5046 if (GET_MODE (offset_rtx) != Pmode)
5047 offset_rtx = convert_to_mode (Pmode, offset_rtx, 0);
5048 #else
5049 if (GET_MODE (offset_rtx) != ptr_mode)
5050 offset_rtx = convert_to_mode (ptr_mode, offset_rtx, 0);
5051 #endif
5053 to_rtx = offset_address (to_rtx, offset_rtx,
5054 highest_pow2_factor (offset));
5057 #ifdef WORD_REGISTER_OPERATIONS
5058 /* If this initializes a field that is smaller than a
5059 word, at the start of a word, try to widen it to a full
5060 word. This special case allows us to output C++ member
5061 function initializations in a form that the optimizers
5062 can understand. */
5063 if (REG_P (target)
5064 && bitsize < BITS_PER_WORD
5065 && bitpos % BITS_PER_WORD == 0
5066 && GET_MODE_CLASS (mode) == MODE_INT
5067 && TREE_CODE (value) == INTEGER_CST
5068 && exp_size >= 0
5069 && bitpos + BITS_PER_WORD <= exp_size * BITS_PER_UNIT)
5071 tree type = TREE_TYPE (value);
5073 if (TYPE_PRECISION (type) < BITS_PER_WORD)
5075 type = lang_hooks.types.type_for_size
5076 (BITS_PER_WORD, TYPE_UNSIGNED (type));
5077 value = fold_convert (type, value);
5080 if (BYTES_BIG_ENDIAN)
5081 value
5082 = fold_build2 (LSHIFT_EXPR, type, value,
5083 build_int_cst (type,
5084 BITS_PER_WORD - bitsize));
5085 bitsize = BITS_PER_WORD;
5086 mode = word_mode;
5088 #endif
5090 if (MEM_P (to_rtx) && !MEM_KEEP_ALIAS_SET_P (to_rtx)
5091 && DECL_NONADDRESSABLE_P (field))
5093 to_rtx = copy_rtx (to_rtx);
5094 MEM_KEEP_ALIAS_SET_P (to_rtx) = 1;
5097 store_constructor_field (to_rtx, bitsize, bitpos, mode,
5098 value, type, cleared,
5099 get_alias_set (TREE_TYPE (field)));
5101 break;
5103 case ARRAY_TYPE:
5105 tree value, index;
5106 unsigned HOST_WIDE_INT i;
5107 int need_to_clear;
5108 tree domain;
5109 tree elttype = TREE_TYPE (type);
5110 int const_bounds_p;
5111 HOST_WIDE_INT minelt = 0;
5112 HOST_WIDE_INT maxelt = 0;
5114 domain = TYPE_DOMAIN (type);
5115 const_bounds_p = (TYPE_MIN_VALUE (domain)
5116 && TYPE_MAX_VALUE (domain)
5117 && host_integerp (TYPE_MIN_VALUE (domain), 0)
5118 && host_integerp (TYPE_MAX_VALUE (domain), 0));
5120 /* If we have constant bounds for the range of the type, get them. */
5121 if (const_bounds_p)
5123 minelt = tree_low_cst (TYPE_MIN_VALUE (domain), 0);
5124 maxelt = tree_low_cst (TYPE_MAX_VALUE (domain), 0);
5127 /* If the constructor has fewer elements than the array, clear
5128 the whole array first. Similarly if this is static
5129 constructor of a non-BLKmode object. */
5130 if (cleared)
5131 need_to_clear = 0;
5132 else if (REG_P (target) && TREE_STATIC (exp))
5133 need_to_clear = 1;
5134 else
5136 unsigned HOST_WIDE_INT idx;
5137 tree index, value;
5138 HOST_WIDE_INT count = 0, zero_count = 0;
5139 need_to_clear = ! const_bounds_p;
5141 /* This loop is a more accurate version of the loop in
5142 mostly_zeros_p (it handles RANGE_EXPR in an index). It
5143 is also needed to check for missing elements. */
5144 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, index, value)
5146 HOST_WIDE_INT this_node_count;
5148 if (need_to_clear)
5149 break;
5151 if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
5153 tree lo_index = TREE_OPERAND (index, 0);
5154 tree hi_index = TREE_OPERAND (index, 1);
5156 if (! host_integerp (lo_index, 1)
5157 || ! host_integerp (hi_index, 1))
5159 need_to_clear = 1;
5160 break;
5163 this_node_count = (tree_low_cst (hi_index, 1)
5164 - tree_low_cst (lo_index, 1) + 1);
5166 else
5167 this_node_count = 1;
5169 count += this_node_count;
5170 if (mostly_zeros_p (value))
5171 zero_count += this_node_count;
5174 /* Clear the entire array first if there are any missing
5175 elements, or if the incidence of zero elements is >=
5176 75%. */
5177 if (! need_to_clear
5178 && (count < maxelt - minelt + 1
5179 || 4 * zero_count >= 3 * count))
5180 need_to_clear = 1;
5183 if (need_to_clear && size > 0)
5185 if (REG_P (target))
5186 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
5187 else
5188 clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
5189 cleared = 1;
5192 if (!cleared && REG_P (target))
5193 /* Inform later passes that the old value is dead. */
5194 emit_insn (gen_rtx_CLOBBER (VOIDmode, target));
5196 /* Store each element of the constructor into the
5197 corresponding element of TARGET, determined by counting the
5198 elements. */
5199 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), i, index, value)
5201 enum machine_mode mode;
5202 HOST_WIDE_INT bitsize;
5203 HOST_WIDE_INT bitpos;
5204 int unsignedp;
5205 rtx xtarget = target;
5207 if (cleared && initializer_zerop (value))
5208 continue;
5210 unsignedp = TYPE_UNSIGNED (elttype);
5211 mode = TYPE_MODE (elttype);
5212 if (mode == BLKmode)
5213 bitsize = (host_integerp (TYPE_SIZE (elttype), 1)
5214 ? tree_low_cst (TYPE_SIZE (elttype), 1)
5215 : -1);
5216 else
5217 bitsize = GET_MODE_BITSIZE (mode);
5219 if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
5221 tree lo_index = TREE_OPERAND (index, 0);
5222 tree hi_index = TREE_OPERAND (index, 1);
5223 rtx index_r, pos_rtx;
5224 HOST_WIDE_INT lo, hi, count;
5225 tree position;
5227 /* If the range is constant and "small", unroll the loop. */
5228 if (const_bounds_p
5229 && host_integerp (lo_index, 0)
5230 && host_integerp (hi_index, 0)
5231 && (lo = tree_low_cst (lo_index, 0),
5232 hi = tree_low_cst (hi_index, 0),
5233 count = hi - lo + 1,
5234 (!MEM_P (target)
5235 || count <= 2
5236 || (host_integerp (TYPE_SIZE (elttype), 1)
5237 && (tree_low_cst (TYPE_SIZE (elttype), 1) * count
5238 <= 40 * 8)))))
5240 lo -= minelt; hi -= minelt;
5241 for (; lo <= hi; lo++)
5243 bitpos = lo * tree_low_cst (TYPE_SIZE (elttype), 0);
5245 if (MEM_P (target)
5246 && !MEM_KEEP_ALIAS_SET_P (target)
5247 && TREE_CODE (type) == ARRAY_TYPE
5248 && TYPE_NONALIASED_COMPONENT (type))
5250 target = copy_rtx (target);
5251 MEM_KEEP_ALIAS_SET_P (target) = 1;
5254 store_constructor_field
5255 (target, bitsize, bitpos, mode, value, type, cleared,
5256 get_alias_set (elttype));
5259 else
5261 rtx loop_start = gen_label_rtx ();
5262 rtx loop_end = gen_label_rtx ();
5263 tree exit_cond;
5265 expand_normal (hi_index);
5266 unsignedp = TYPE_UNSIGNED (domain);
5268 index = build_decl (VAR_DECL, NULL_TREE, domain);
5270 index_r
5271 = gen_reg_rtx (promote_mode (domain, DECL_MODE (index),
5272 &unsignedp, 0));
5273 SET_DECL_RTL (index, index_r);
5274 store_expr (lo_index, index_r, 0);
5276 /* Build the head of the loop. */
5277 do_pending_stack_adjust ();
5278 emit_label (loop_start);
5280 /* Assign value to element index. */
5281 position =
5282 fold_convert (ssizetype,
5283 fold_build2 (MINUS_EXPR,
5284 TREE_TYPE (index),
5285 index,
5286 TYPE_MIN_VALUE (domain)));
5288 position =
5289 size_binop (MULT_EXPR, position,
5290 fold_convert (ssizetype,
5291 TYPE_SIZE_UNIT (elttype)));
5293 pos_rtx = expand_normal (position);
5294 xtarget = offset_address (target, pos_rtx,
5295 highest_pow2_factor (position));
5296 xtarget = adjust_address (xtarget, mode, 0);
5297 if (TREE_CODE (value) == CONSTRUCTOR)
5298 store_constructor (value, xtarget, cleared,
5299 bitsize / BITS_PER_UNIT);
5300 else
5301 store_expr (value, xtarget, 0);
5303 /* Generate a conditional jump to exit the loop. */
5304 exit_cond = build2 (LT_EXPR, integer_type_node,
5305 index, hi_index);
5306 jumpif (exit_cond, loop_end);
5308 /* Update the loop counter, and jump to the head of
5309 the loop. */
5310 expand_assignment (index,
5311 build2 (PLUS_EXPR, TREE_TYPE (index),
5312 index, integer_one_node));
5314 emit_jump (loop_start);
5316 /* Build the end of the loop. */
5317 emit_label (loop_end);
5320 else if ((index != 0 && ! host_integerp (index, 0))
5321 || ! host_integerp (TYPE_SIZE (elttype), 1))
5323 tree position;
5325 if (index == 0)
5326 index = ssize_int (1);
5328 if (minelt)
5329 index = fold_convert (ssizetype,
5330 fold_build2 (MINUS_EXPR,
5331 TREE_TYPE (index),
5332 index,
5333 TYPE_MIN_VALUE (domain)));
5335 position =
5336 size_binop (MULT_EXPR, index,
5337 fold_convert (ssizetype,
5338 TYPE_SIZE_UNIT (elttype)));
5339 xtarget = offset_address (target,
5340 expand_normal (position),
5341 highest_pow2_factor (position));
5342 xtarget = adjust_address (xtarget, mode, 0);
5343 store_expr (value, xtarget, 0);
5345 else
5347 if (index != 0)
5348 bitpos = ((tree_low_cst (index, 0) - minelt)
5349 * tree_low_cst (TYPE_SIZE (elttype), 1));
5350 else
5351 bitpos = (i * tree_low_cst (TYPE_SIZE (elttype), 1));
5353 if (MEM_P (target) && !MEM_KEEP_ALIAS_SET_P (target)
5354 && TREE_CODE (type) == ARRAY_TYPE
5355 && TYPE_NONALIASED_COMPONENT (type))
5357 target = copy_rtx (target);
5358 MEM_KEEP_ALIAS_SET_P (target) = 1;
5360 store_constructor_field (target, bitsize, bitpos, mode, value,
5361 type, cleared, get_alias_set (elttype));
5364 break;
5367 case VECTOR_TYPE:
5369 unsigned HOST_WIDE_INT idx;
5370 constructor_elt *ce;
5371 int i;
5372 int need_to_clear;
5373 int icode = 0;
5374 tree elttype = TREE_TYPE (type);
5375 int elt_size = tree_low_cst (TYPE_SIZE (elttype), 1);
5376 enum machine_mode eltmode = TYPE_MODE (elttype);
5377 HOST_WIDE_INT bitsize;
5378 HOST_WIDE_INT bitpos;
5379 rtvec vector = NULL;
5380 unsigned n_elts;
5382 gcc_assert (eltmode != BLKmode);
5384 n_elts = TYPE_VECTOR_SUBPARTS (type);
5385 if (REG_P (target) && VECTOR_MODE_P (GET_MODE (target)))
5387 enum machine_mode mode = GET_MODE (target);
5389 icode = (int) vec_init_optab->handlers[mode].insn_code;
5390 if (icode != CODE_FOR_nothing)
5392 unsigned int i;
5394 vector = rtvec_alloc (n_elts);
5395 for (i = 0; i < n_elts; i++)
5396 RTVEC_ELT (vector, i) = CONST0_RTX (GET_MODE_INNER (mode));
5400 /* If the constructor has fewer elements than the vector,
5401 clear the whole array first. Similarly if this is static
5402 constructor of a non-BLKmode object. */
5403 if (cleared)
5404 need_to_clear = 0;
5405 else if (REG_P (target) && TREE_STATIC (exp))
5406 need_to_clear = 1;
5407 else
5409 unsigned HOST_WIDE_INT count = 0, zero_count = 0;
5410 tree value;
5412 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
5414 int n_elts_here = tree_low_cst
5415 (int_const_binop (TRUNC_DIV_EXPR,
5416 TYPE_SIZE (TREE_TYPE (value)),
5417 TYPE_SIZE (elttype), 0), 1);
5419 count += n_elts_here;
5420 if (mostly_zeros_p (value))
5421 zero_count += n_elts_here;
5424 /* Clear the entire vector first if there are any missing elements,
5425 or if the incidence of zero elements is >= 75%. */
5426 need_to_clear = (count < n_elts || 4 * zero_count >= 3 * count);
5429 if (need_to_clear && size > 0 && !vector)
5431 if (REG_P (target))
5432 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
5433 else
5434 clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
5435 cleared = 1;
5438 /* Inform later passes that the old value is dead. */
5439 if (!cleared && !vector && REG_P (target))
5440 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
5442 /* Store each element of the constructor into the corresponding
5443 element of TARGET, determined by counting the elements. */
5444 for (idx = 0, i = 0;
5445 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), idx, ce);
5446 idx++, i += bitsize / elt_size)
5448 HOST_WIDE_INT eltpos;
5449 tree value = ce->value;
5451 bitsize = tree_low_cst (TYPE_SIZE (TREE_TYPE (value)), 1);
5452 if (cleared && initializer_zerop (value))
5453 continue;
5455 if (ce->index)
5456 eltpos = tree_low_cst (ce->index, 1);
5457 else
5458 eltpos = i;
5460 if (vector)
5462 /* Vector CONSTRUCTORs should only be built from smaller
5463 vectors in the case of BLKmode vectors. */
5464 gcc_assert (TREE_CODE (TREE_TYPE (value)) != VECTOR_TYPE);
5465 RTVEC_ELT (vector, eltpos)
5466 = expand_normal (value);
5468 else
5470 enum machine_mode value_mode =
5471 TREE_CODE (TREE_TYPE (value)) == VECTOR_TYPE
5472 ? TYPE_MODE (TREE_TYPE (value))
5473 : eltmode;
5474 bitpos = eltpos * elt_size;
5475 store_constructor_field (target, bitsize, bitpos,
5476 value_mode, value, type,
5477 cleared, get_alias_set (elttype));
5481 if (vector)
5482 emit_insn (GEN_FCN (icode)
5483 (target,
5484 gen_rtx_PARALLEL (GET_MODE (target), vector)));
5485 break;
5488 default:
5489 gcc_unreachable ();
5493 /* Store the value of EXP (an expression tree)
5494 into a subfield of TARGET which has mode MODE and occupies
5495 BITSIZE bits, starting BITPOS bits from the start of TARGET.
5496 If MODE is VOIDmode, it means that we are storing into a bit-field.
5498 Always return const0_rtx unless we have something particular to
5499 return.
5501 TYPE is the type of the underlying object,
5503 ALIAS_SET is the alias set for the destination. This value will
5504 (in general) be different from that for TARGET, since TARGET is a
5505 reference to the containing structure. */
5507 static rtx
5508 store_field (rtx target, HOST_WIDE_INT bitsize, HOST_WIDE_INT bitpos,
5509 enum machine_mode mode, tree exp, tree type, int alias_set)
5511 HOST_WIDE_INT width_mask = 0;
5513 if (TREE_CODE (exp) == ERROR_MARK)
5514 return const0_rtx;
5516 /* If we have nothing to store, do nothing unless the expression has
5517 side-effects. */
5518 if (bitsize == 0)
5519 return expand_expr (exp, const0_rtx, VOIDmode, 0);
5520 else if (bitsize >= 0 && bitsize < HOST_BITS_PER_WIDE_INT)
5521 width_mask = ((HOST_WIDE_INT) 1 << bitsize) - 1;
5523 /* If we are storing into an unaligned field of an aligned union that is
5524 in a register, we may have the mode of TARGET being an integer mode but
5525 MODE == BLKmode. In that case, get an aligned object whose size and
5526 alignment are the same as TARGET and store TARGET into it (we can avoid
5527 the store if the field being stored is the entire width of TARGET). Then
5528 call ourselves recursively to store the field into a BLKmode version of
5529 that object. Finally, load from the object into TARGET. This is not
5530 very efficient in general, but should only be slightly more expensive
5531 than the otherwise-required unaligned accesses. Perhaps this can be
5532 cleaned up later. It's tempting to make OBJECT readonly, but it's set
5533 twice, once with emit_move_insn and once via store_field. */
5535 if (mode == BLKmode
5536 && (REG_P (target) || GET_CODE (target) == SUBREG))
5538 rtx object = assign_temp (type, 0, 1, 1);
5539 rtx blk_object = adjust_address (object, BLKmode, 0);
5541 if (bitsize != (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (target)))
5542 emit_move_insn (object, target);
5544 store_field (blk_object, bitsize, bitpos, mode, exp, type, alias_set);
5546 emit_move_insn (target, object);
5548 /* We want to return the BLKmode version of the data. */
5549 return blk_object;
5552 if (GET_CODE (target) == CONCAT)
5554 /* We're storing into a struct containing a single __complex. */
5556 gcc_assert (!bitpos);
5557 return store_expr (exp, target, 0);
5560 /* If the structure is in a register or if the component
5561 is a bit field, we cannot use addressing to access it.
5562 Use bit-field techniques or SUBREG to store in it. */
5564 if (mode == VOIDmode
5565 || (mode != BLKmode && ! direct_store[(int) mode]
5566 && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
5567 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT)
5568 || REG_P (target)
5569 || GET_CODE (target) == SUBREG
5570 /* If the field isn't aligned enough to store as an ordinary memref,
5571 store it as a bit field. */
5572 || (mode != BLKmode
5573 && ((((MEM_ALIGN (target) < GET_MODE_ALIGNMENT (mode))
5574 || bitpos % GET_MODE_ALIGNMENT (mode))
5575 && SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (target)))
5576 || (bitpos % BITS_PER_UNIT != 0)))
5577 /* If the RHS and field are a constant size and the size of the
5578 RHS isn't the same size as the bitfield, we must use bitfield
5579 operations. */
5580 || (bitsize >= 0
5581 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) == INTEGER_CST
5582 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)), bitsize) != 0))
5584 rtx temp;
5586 /* If EXP is a NOP_EXPR of precision less than its mode, then that
5587 implies a mask operation. If the precision is the same size as
5588 the field we're storing into, that mask is redundant. This is
5589 particularly common with bit field assignments generated by the
5590 C front end. */
5591 if (TREE_CODE (exp) == NOP_EXPR)
5593 tree type = TREE_TYPE (exp);
5594 if (INTEGRAL_TYPE_P (type)
5595 && TYPE_PRECISION (type) < GET_MODE_BITSIZE (TYPE_MODE (type))
5596 && bitsize == TYPE_PRECISION (type))
5598 type = TREE_TYPE (TREE_OPERAND (exp, 0));
5599 if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) >= bitsize)
5600 exp = TREE_OPERAND (exp, 0);
5604 temp = expand_normal (exp);
5606 /* If BITSIZE is narrower than the size of the type of EXP
5607 we will be narrowing TEMP. Normally, what's wanted are the
5608 low-order bits. However, if EXP's type is a record and this is
5609 big-endian machine, we want the upper BITSIZE bits. */
5610 if (BYTES_BIG_ENDIAN && GET_MODE_CLASS (GET_MODE (temp)) == MODE_INT
5611 && bitsize < (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (temp))
5612 && TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
5613 temp = expand_shift (RSHIFT_EXPR, GET_MODE (temp), temp,
5614 size_int (GET_MODE_BITSIZE (GET_MODE (temp))
5615 - bitsize),
5616 NULL_RTX, 1);
5618 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to
5619 MODE. */
5620 if (mode != VOIDmode && mode != BLKmode
5621 && mode != TYPE_MODE (TREE_TYPE (exp)))
5622 temp = convert_modes (mode, TYPE_MODE (TREE_TYPE (exp)), temp, 1);
5624 /* If the modes of TARGET and TEMP are both BLKmode, both
5625 must be in memory and BITPOS must be aligned on a byte
5626 boundary. If so, we simply do a block copy. */
5627 if (GET_MODE (target) == BLKmode && GET_MODE (temp) == BLKmode)
5629 gcc_assert (MEM_P (target) && MEM_P (temp)
5630 && !(bitpos % BITS_PER_UNIT));
5632 target = adjust_address (target, VOIDmode, bitpos / BITS_PER_UNIT);
5633 emit_block_move (target, temp,
5634 GEN_INT ((bitsize + BITS_PER_UNIT - 1)
5635 / BITS_PER_UNIT),
5636 BLOCK_OP_NORMAL);
5638 return const0_rtx;
5641 /* Store the value in the bitfield. */
5642 store_bit_field (target, bitsize, bitpos, mode, temp);
5644 return const0_rtx;
5646 else
5648 /* Now build a reference to just the desired component. */
5649 rtx to_rtx = adjust_address (target, mode, bitpos / BITS_PER_UNIT);
5651 if (to_rtx == target)
5652 to_rtx = copy_rtx (to_rtx);
5654 MEM_SET_IN_STRUCT_P (to_rtx, 1);
5655 if (!MEM_KEEP_ALIAS_SET_P (to_rtx) && MEM_ALIAS_SET (to_rtx) != 0)
5656 set_mem_alias_set (to_rtx, alias_set);
5658 return store_expr (exp, to_rtx, 0);
5662 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
5663 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
5664 codes and find the ultimate containing object, which we return.
5666 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
5667 bit position, and *PUNSIGNEDP to the signedness of the field.
5668 If the position of the field is variable, we store a tree
5669 giving the variable offset (in units) in *POFFSET.
5670 This offset is in addition to the bit position.
5671 If the position is not variable, we store 0 in *POFFSET.
5673 If any of the extraction expressions is volatile,
5674 we store 1 in *PVOLATILEP. Otherwise we don't change that.
5676 If the field is a bit-field, *PMODE is set to VOIDmode. Otherwise, it
5677 is a mode that can be used to access the field. In that case, *PBITSIZE
5678 is redundant.
5680 If the field describes a variable-sized object, *PMODE is set to
5681 VOIDmode and *PBITSIZE is set to -1. An access cannot be made in
5682 this case, but the address of the object can be found.
5684 If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
5685 look through nodes that serve as markers of a greater alignment than
5686 the one that can be deduced from the expression. These nodes make it
5687 possible for front-ends to prevent temporaries from being created by
5688 the middle-end on alignment considerations. For that purpose, the
5689 normal operating mode at high-level is to always pass FALSE so that
5690 the ultimate containing object is really returned; moreover, the
5691 associated predicate handled_component_p will always return TRUE
5692 on these nodes, thus indicating that they are essentially handled
5693 by get_inner_reference. TRUE should only be passed when the caller
5694 is scanning the expression in order to build another representation
5695 and specifically knows how to handle these nodes; as such, this is
5696 the normal operating mode in the RTL expanders. */
5698 tree
5699 get_inner_reference (tree exp, HOST_WIDE_INT *pbitsize,
5700 HOST_WIDE_INT *pbitpos, tree *poffset,
5701 enum machine_mode *pmode, int *punsignedp,
5702 int *pvolatilep, bool keep_aligning)
5704 tree size_tree = 0;
5705 enum machine_mode mode = VOIDmode;
5706 tree offset = size_zero_node;
5707 tree bit_offset = bitsize_zero_node;
5708 tree tem;
5710 /* First get the mode, signedness, and size. We do this from just the
5711 outermost expression. */
5712 if (TREE_CODE (exp) == COMPONENT_REF)
5714 size_tree = DECL_SIZE (TREE_OPERAND (exp, 1));
5715 if (! DECL_BIT_FIELD (TREE_OPERAND (exp, 1)))
5716 mode = DECL_MODE (TREE_OPERAND (exp, 1));
5718 *punsignedp = DECL_UNSIGNED (TREE_OPERAND (exp, 1));
5720 else if (TREE_CODE (exp) == BIT_FIELD_REF)
5722 size_tree = TREE_OPERAND (exp, 1);
5723 *punsignedp = BIT_FIELD_REF_UNSIGNED (exp);
5725 /* For vector types, with the correct size of access, use the mode of
5726 inner type. */
5727 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == VECTOR_TYPE
5728 && TREE_TYPE (exp) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)))
5729 && tree_int_cst_equal (size_tree, TYPE_SIZE (TREE_TYPE (exp))))
5730 mode = TYPE_MODE (TREE_TYPE (exp));
5732 else
5734 mode = TYPE_MODE (TREE_TYPE (exp));
5735 *punsignedp = TYPE_UNSIGNED (TREE_TYPE (exp));
5737 if (mode == BLKmode)
5738 size_tree = TYPE_SIZE (TREE_TYPE (exp));
5739 else
5740 *pbitsize = GET_MODE_BITSIZE (mode);
5743 if (size_tree != 0)
5745 if (! host_integerp (size_tree, 1))
5746 mode = BLKmode, *pbitsize = -1;
5747 else
5748 *pbitsize = tree_low_cst (size_tree, 1);
5751 /* Compute cumulative bit-offset for nested component-refs and array-refs,
5752 and find the ultimate containing object. */
5753 while (1)
5755 switch (TREE_CODE (exp))
5757 case BIT_FIELD_REF:
5758 bit_offset = size_binop (PLUS_EXPR, bit_offset,
5759 TREE_OPERAND (exp, 2));
5760 break;
5762 case COMPONENT_REF:
5764 tree field = TREE_OPERAND (exp, 1);
5765 tree this_offset = component_ref_field_offset (exp);
5767 /* If this field hasn't been filled in yet, don't go past it.
5768 This should only happen when folding expressions made during
5769 type construction. */
5770 if (this_offset == 0)
5771 break;
5773 offset = size_binop (PLUS_EXPR, offset, this_offset);
5774 bit_offset = size_binop (PLUS_EXPR, bit_offset,
5775 DECL_FIELD_BIT_OFFSET (field));
5777 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
5779 break;
5781 case ARRAY_REF:
5782 case ARRAY_RANGE_REF:
5784 tree index = TREE_OPERAND (exp, 1);
5785 tree low_bound = array_ref_low_bound (exp);
5786 tree unit_size = array_ref_element_size (exp);
5788 /* We assume all arrays have sizes that are a multiple of a byte.
5789 First subtract the lower bound, if any, in the type of the
5790 index, then convert to sizetype and multiply by the size of
5791 the array element. */
5792 if (! integer_zerop (low_bound))
5793 index = fold_build2 (MINUS_EXPR, TREE_TYPE (index),
5794 index, low_bound);
5796 offset = size_binop (PLUS_EXPR, offset,
5797 size_binop (MULT_EXPR,
5798 fold_convert (sizetype, index),
5799 unit_size));
5801 break;
5803 case REALPART_EXPR:
5804 break;
5806 case IMAGPART_EXPR:
5807 bit_offset = size_binop (PLUS_EXPR, bit_offset,
5808 bitsize_int (*pbitsize));
5809 break;
5811 case VIEW_CONVERT_EXPR:
5812 if (keep_aligning && STRICT_ALIGNMENT
5813 && (TYPE_ALIGN (TREE_TYPE (exp))
5814 > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0))))
5815 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0)))
5816 < BIGGEST_ALIGNMENT)
5817 && (TYPE_ALIGN_OK (TREE_TYPE (exp))
5818 || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp, 0)))))
5819 goto done;
5820 break;
5822 default:
5823 goto done;
5826 /* If any reference in the chain is volatile, the effect is volatile. */
5827 if (TREE_THIS_VOLATILE (exp))
5828 *pvolatilep = 1;
5830 exp = TREE_OPERAND (exp, 0);
5832 done:
5834 /* If OFFSET is constant, see if we can return the whole thing as a
5835 constant bit position. Otherwise, split it up. */
5836 if (host_integerp (offset, 0)
5837 && 0 != (tem = size_binop (MULT_EXPR,
5838 fold_convert (bitsizetype, offset),
5839 bitsize_unit_node))
5840 && 0 != (tem = size_binop (PLUS_EXPR, tem, bit_offset))
5841 && host_integerp (tem, 0))
5842 *pbitpos = tree_low_cst (tem, 0), *poffset = 0;
5843 else
5844 *pbitpos = tree_low_cst (bit_offset, 0), *poffset = offset;
5846 *pmode = mode;
5847 return exp;
5850 /* Return a tree of sizetype representing the size, in bytes, of the element
5851 of EXP, an ARRAY_REF. */
5853 tree
5854 array_ref_element_size (tree exp)
5856 tree aligned_size = TREE_OPERAND (exp, 3);
5857 tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)));
5859 /* If a size was specified in the ARRAY_REF, it's the size measured
5860 in alignment units of the element type. So multiply by that value. */
5861 if (aligned_size)
5863 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
5864 sizetype from another type of the same width and signedness. */
5865 if (TREE_TYPE (aligned_size) != sizetype)
5866 aligned_size = fold_convert (sizetype, aligned_size);
5867 return size_binop (MULT_EXPR, aligned_size,
5868 size_int (TYPE_ALIGN_UNIT (elmt_type)));
5871 /* Otherwise, take the size from that of the element type. Substitute
5872 any PLACEHOLDER_EXPR that we have. */
5873 else
5874 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type), exp);
5877 /* Return a tree representing the lower bound of the array mentioned in
5878 EXP, an ARRAY_REF. */
5880 tree
5881 array_ref_low_bound (tree exp)
5883 tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
5885 /* If a lower bound is specified in EXP, use it. */
5886 if (TREE_OPERAND (exp, 2))
5887 return TREE_OPERAND (exp, 2);
5889 /* Otherwise, if there is a domain type and it has a lower bound, use it,
5890 substituting for a PLACEHOLDER_EXPR as needed. */
5891 if (domain_type && TYPE_MIN_VALUE (domain_type))
5892 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type), exp);
5894 /* Otherwise, return a zero of the appropriate type. */
5895 return build_int_cst (TREE_TYPE (TREE_OPERAND (exp, 1)), 0);
5898 /* Return a tree representing the upper bound of the array mentioned in
5899 EXP, an ARRAY_REF. */
5901 tree
5902 array_ref_up_bound (tree exp)
5904 tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
5906 /* If there is a domain type and it has an upper bound, use it, substituting
5907 for a PLACEHOLDER_EXPR as needed. */
5908 if (domain_type && TYPE_MAX_VALUE (domain_type))
5909 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type), exp);
5911 /* Otherwise fail. */
5912 return NULL_TREE;
5915 /* Return a tree representing the offset, in bytes, of the field referenced
5916 by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
5918 tree
5919 component_ref_field_offset (tree exp)
5921 tree aligned_offset = TREE_OPERAND (exp, 2);
5922 tree field = TREE_OPERAND (exp, 1);
5924 /* If an offset was specified in the COMPONENT_REF, it's the offset measured
5925 in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
5926 value. */
5927 if (aligned_offset)
5929 /* ??? tree_ssa_useless_type_conversion will eliminate casts to
5930 sizetype from another type of the same width and signedness. */
5931 if (TREE_TYPE (aligned_offset) != sizetype)
5932 aligned_offset = fold_convert (sizetype, aligned_offset);
5933 return size_binop (MULT_EXPR, aligned_offset,
5934 size_int (DECL_OFFSET_ALIGN (field) / BITS_PER_UNIT));
5937 /* Otherwise, take the offset from that of the field. Substitute
5938 any PLACEHOLDER_EXPR that we have. */
5939 else
5940 return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field), exp);
5943 /* Return 1 if T is an expression that get_inner_reference handles. */
5946 handled_component_p (tree t)
5948 switch (TREE_CODE (t))
5950 case BIT_FIELD_REF:
5951 case COMPONENT_REF:
5952 case ARRAY_REF:
5953 case ARRAY_RANGE_REF:
5954 case VIEW_CONVERT_EXPR:
5955 case REALPART_EXPR:
5956 case IMAGPART_EXPR:
5957 return 1;
5959 default:
5960 return 0;
5964 /* Given an rtx VALUE that may contain additions and multiplications, return
5965 an equivalent value that just refers to a register, memory, or constant.
5966 This is done by generating instructions to perform the arithmetic and
5967 returning a pseudo-register containing the value.
5969 The returned value may be a REG, SUBREG, MEM or constant. */
5972 force_operand (rtx value, rtx target)
5974 rtx op1, op2;
5975 /* Use subtarget as the target for operand 0 of a binary operation. */
5976 rtx subtarget = get_subtarget (target);
5977 enum rtx_code code = GET_CODE (value);
5979 /* Check for subreg applied to an expression produced by loop optimizer. */
5980 if (code == SUBREG
5981 && !REG_P (SUBREG_REG (value))
5982 && !MEM_P (SUBREG_REG (value)))
5984 value = simplify_gen_subreg (GET_MODE (value),
5985 force_reg (GET_MODE (SUBREG_REG (value)),
5986 force_operand (SUBREG_REG (value),
5987 NULL_RTX)),
5988 GET_MODE (SUBREG_REG (value)),
5989 SUBREG_BYTE (value));
5990 code = GET_CODE (value);
5993 /* Check for a PIC address load. */
5994 if ((code == PLUS || code == MINUS)
5995 && XEXP (value, 0) == pic_offset_table_rtx
5996 && (GET_CODE (XEXP (value, 1)) == SYMBOL_REF
5997 || GET_CODE (XEXP (value, 1)) == LABEL_REF
5998 || GET_CODE (XEXP (value, 1)) == CONST))
6000 if (!subtarget)
6001 subtarget = gen_reg_rtx (GET_MODE (value));
6002 emit_move_insn (subtarget, value);
6003 return subtarget;
6006 if (ARITHMETIC_P (value))
6008 op2 = XEXP (value, 1);
6009 if (!CONSTANT_P (op2) && !(REG_P (op2) && op2 != subtarget))
6010 subtarget = 0;
6011 if (code == MINUS && GET_CODE (op2) == CONST_INT)
6013 code = PLUS;
6014 op2 = negate_rtx (GET_MODE (value), op2);
6017 /* Check for an addition with OP2 a constant integer and our first
6018 operand a PLUS of a virtual register and something else. In that
6019 case, we want to emit the sum of the virtual register and the
6020 constant first and then add the other value. This allows virtual
6021 register instantiation to simply modify the constant rather than
6022 creating another one around this addition. */
6023 if (code == PLUS && GET_CODE (op2) == CONST_INT
6024 && GET_CODE (XEXP (value, 0)) == PLUS
6025 && REG_P (XEXP (XEXP (value, 0), 0))
6026 && REGNO (XEXP (XEXP (value, 0), 0)) >= FIRST_VIRTUAL_REGISTER
6027 && REGNO (XEXP (XEXP (value, 0), 0)) <= LAST_VIRTUAL_REGISTER)
6029 rtx temp = expand_simple_binop (GET_MODE (value), code,
6030 XEXP (XEXP (value, 0), 0), op2,
6031 subtarget, 0, OPTAB_LIB_WIDEN);
6032 return expand_simple_binop (GET_MODE (value), code, temp,
6033 force_operand (XEXP (XEXP (value,
6034 0), 1), 0),
6035 target, 0, OPTAB_LIB_WIDEN);
6038 op1 = force_operand (XEXP (value, 0), subtarget);
6039 op2 = force_operand (op2, NULL_RTX);
6040 switch (code)
6042 case MULT:
6043 return expand_mult (GET_MODE (value), op1, op2, target, 1);
6044 case DIV:
6045 if (!INTEGRAL_MODE_P (GET_MODE (value)))
6046 return expand_simple_binop (GET_MODE (value), code, op1, op2,
6047 target, 1, OPTAB_LIB_WIDEN);
6048 else
6049 return expand_divmod (0,
6050 FLOAT_MODE_P (GET_MODE (value))
6051 ? RDIV_EXPR : TRUNC_DIV_EXPR,
6052 GET_MODE (value), op1, op2, target, 0);
6053 break;
6054 case MOD:
6055 return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
6056 target, 0);
6057 break;
6058 case UDIV:
6059 return expand_divmod (0, TRUNC_DIV_EXPR, GET_MODE (value), op1, op2,
6060 target, 1);
6061 break;
6062 case UMOD:
6063 return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
6064 target, 1);
6065 break;
6066 case ASHIFTRT:
6067 return expand_simple_binop (GET_MODE (value), code, op1, op2,
6068 target, 0, OPTAB_LIB_WIDEN);
6069 break;
6070 default:
6071 return expand_simple_binop (GET_MODE (value), code, op1, op2,
6072 target, 1, OPTAB_LIB_WIDEN);
6075 if (UNARY_P (value))
6077 if (!target)
6078 target = gen_reg_rtx (GET_MODE (value));
6079 op1 = force_operand (XEXP (value, 0), NULL_RTX);
6080 switch (code)
6082 case ZERO_EXTEND:
6083 case SIGN_EXTEND:
6084 case TRUNCATE:
6085 case FLOAT_EXTEND:
6086 case FLOAT_TRUNCATE:
6087 convert_move (target, op1, code == ZERO_EXTEND);
6088 return target;
6090 case FIX:
6091 case UNSIGNED_FIX:
6092 expand_fix (target, op1, code == UNSIGNED_FIX);
6093 return target;
6095 case FLOAT:
6096 case UNSIGNED_FLOAT:
6097 expand_float (target, op1, code == UNSIGNED_FLOAT);
6098 return target;
6100 default:
6101 return expand_simple_unop (GET_MODE (value), code, op1, target, 0);
6105 #ifdef INSN_SCHEDULING
6106 /* On machines that have insn scheduling, we want all memory reference to be
6107 explicit, so we need to deal with such paradoxical SUBREGs. */
6108 if (GET_CODE (value) == SUBREG && MEM_P (SUBREG_REG (value))
6109 && (GET_MODE_SIZE (GET_MODE (value))
6110 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (value)))))
6111 value
6112 = simplify_gen_subreg (GET_MODE (value),
6113 force_reg (GET_MODE (SUBREG_REG (value)),
6114 force_operand (SUBREG_REG (value),
6115 NULL_RTX)),
6116 GET_MODE (SUBREG_REG (value)),
6117 SUBREG_BYTE (value));
6118 #endif
6120 return value;
6123 /* Subroutine of expand_expr: return nonzero iff there is no way that
6124 EXP can reference X, which is being modified. TOP_P is nonzero if this
6125 call is going to be used to determine whether we need a temporary
6126 for EXP, as opposed to a recursive call to this function.
6128 It is always safe for this routine to return zero since it merely
6129 searches for optimization opportunities. */
6132 safe_from_p (rtx x, tree exp, int top_p)
6134 rtx exp_rtl = 0;
6135 int i, nops;
6137 if (x == 0
6138 /* If EXP has varying size, we MUST use a target since we currently
6139 have no way of allocating temporaries of variable size
6140 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
6141 So we assume here that something at a higher level has prevented a
6142 clash. This is somewhat bogus, but the best we can do. Only
6143 do this when X is BLKmode and when we are at the top level. */
6144 || (top_p && TREE_TYPE (exp) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp))
6145 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) != INTEGER_CST
6146 && (TREE_CODE (TREE_TYPE (exp)) != ARRAY_TYPE
6147 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)) == NULL_TREE
6148 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)))
6149 != INTEGER_CST)
6150 && GET_MODE (x) == BLKmode)
6151 /* If X is in the outgoing argument area, it is always safe. */
6152 || (MEM_P (x)
6153 && (XEXP (x, 0) == virtual_outgoing_args_rtx
6154 || (GET_CODE (XEXP (x, 0)) == PLUS
6155 && XEXP (XEXP (x, 0), 0) == virtual_outgoing_args_rtx))))
6156 return 1;
6158 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
6159 find the underlying pseudo. */
6160 if (GET_CODE (x) == SUBREG)
6162 x = SUBREG_REG (x);
6163 if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
6164 return 0;
6167 /* Now look at our tree code and possibly recurse. */
6168 switch (TREE_CODE_CLASS (TREE_CODE (exp)))
6170 case tcc_declaration:
6171 exp_rtl = DECL_RTL_IF_SET (exp);
6172 break;
6174 case tcc_constant:
6175 return 1;
6177 case tcc_exceptional:
6178 if (TREE_CODE (exp) == TREE_LIST)
6180 while (1)
6182 if (TREE_VALUE (exp) && !safe_from_p (x, TREE_VALUE (exp), 0))
6183 return 0;
6184 exp = TREE_CHAIN (exp);
6185 if (!exp)
6186 return 1;
6187 if (TREE_CODE (exp) != TREE_LIST)
6188 return safe_from_p (x, exp, 0);
6191 else if (TREE_CODE (exp) == CONSTRUCTOR)
6193 constructor_elt *ce;
6194 unsigned HOST_WIDE_INT idx;
6196 for (idx = 0;
6197 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), idx, ce);
6198 idx++)
6199 if ((ce->index != NULL_TREE && !safe_from_p (x, ce->index, 0))
6200 || !safe_from_p (x, ce->value, 0))
6201 return 0;
6202 return 1;
6204 else if (TREE_CODE (exp) == ERROR_MARK)
6205 return 1; /* An already-visited SAVE_EXPR? */
6206 else
6207 return 0;
6209 case tcc_statement:
6210 /* The only case we look at here is the DECL_INITIAL inside a
6211 DECL_EXPR. */
6212 return (TREE_CODE (exp) != DECL_EXPR
6213 || TREE_CODE (DECL_EXPR_DECL (exp)) != VAR_DECL
6214 || !DECL_INITIAL (DECL_EXPR_DECL (exp))
6215 || safe_from_p (x, DECL_INITIAL (DECL_EXPR_DECL (exp)), 0));
6217 case tcc_binary:
6218 case tcc_comparison:
6219 if (!safe_from_p (x, TREE_OPERAND (exp, 1), 0))
6220 return 0;
6221 /* Fall through. */
6223 case tcc_unary:
6224 return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
6226 case tcc_expression:
6227 case tcc_reference:
6228 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
6229 the expression. If it is set, we conflict iff we are that rtx or
6230 both are in memory. Otherwise, we check all operands of the
6231 expression recursively. */
6233 switch (TREE_CODE (exp))
6235 case ADDR_EXPR:
6236 /* If the operand is static or we are static, we can't conflict.
6237 Likewise if we don't conflict with the operand at all. */
6238 if (staticp (TREE_OPERAND (exp, 0))
6239 || TREE_STATIC (exp)
6240 || safe_from_p (x, TREE_OPERAND (exp, 0), 0))
6241 return 1;
6243 /* Otherwise, the only way this can conflict is if we are taking
6244 the address of a DECL a that address if part of X, which is
6245 very rare. */
6246 exp = TREE_OPERAND (exp, 0);
6247 if (DECL_P (exp))
6249 if (!DECL_RTL_SET_P (exp)
6250 || !MEM_P (DECL_RTL (exp)))
6251 return 0;
6252 else
6253 exp_rtl = XEXP (DECL_RTL (exp), 0);
6255 break;
6257 case MISALIGNED_INDIRECT_REF:
6258 case ALIGN_INDIRECT_REF:
6259 case INDIRECT_REF:
6260 if (MEM_P (x)
6261 && alias_sets_conflict_p (MEM_ALIAS_SET (x),
6262 get_alias_set (exp)))
6263 return 0;
6264 break;
6266 case CALL_EXPR:
6267 /* Assume that the call will clobber all hard registers and
6268 all of memory. */
6269 if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
6270 || MEM_P (x))
6271 return 0;
6272 break;
6274 case WITH_CLEANUP_EXPR:
6275 case CLEANUP_POINT_EXPR:
6276 /* Lowered by gimplify.c. */
6277 gcc_unreachable ();
6279 case SAVE_EXPR:
6280 return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
6282 default:
6283 break;
6286 /* If we have an rtx, we do not need to scan our operands. */
6287 if (exp_rtl)
6288 break;
6290 nops = TREE_CODE_LENGTH (TREE_CODE (exp));
6291 for (i = 0; i < nops; i++)
6292 if (TREE_OPERAND (exp, i) != 0
6293 && ! safe_from_p (x, TREE_OPERAND (exp, i), 0))
6294 return 0;
6296 /* If this is a language-specific tree code, it may require
6297 special handling. */
6298 if ((unsigned int) TREE_CODE (exp)
6299 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
6300 && !lang_hooks.safe_from_p (x, exp))
6301 return 0;
6302 break;
6304 case tcc_type:
6305 /* Should never get a type here. */
6306 gcc_unreachable ();
6308 case tcc_gimple_stmt:
6309 gcc_unreachable ();
6312 /* If we have an rtl, find any enclosed object. Then see if we conflict
6313 with it. */
6314 if (exp_rtl)
6316 if (GET_CODE (exp_rtl) == SUBREG)
6318 exp_rtl = SUBREG_REG (exp_rtl);
6319 if (REG_P (exp_rtl)
6320 && REGNO (exp_rtl) < FIRST_PSEUDO_REGISTER)
6321 return 0;
6324 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
6325 are memory and they conflict. */
6326 return ! (rtx_equal_p (x, exp_rtl)
6327 || (MEM_P (x) && MEM_P (exp_rtl)
6328 && true_dependence (exp_rtl, VOIDmode, x,
6329 rtx_addr_varies_p)));
6332 /* If we reach here, it is safe. */
6333 return 1;
6337 /* Return the highest power of two that EXP is known to be a multiple of.
6338 This is used in updating alignment of MEMs in array references. */
6340 unsigned HOST_WIDE_INT
6341 highest_pow2_factor (tree exp)
6343 unsigned HOST_WIDE_INT c0, c1;
6345 switch (TREE_CODE (exp))
6347 case INTEGER_CST:
6348 /* We can find the lowest bit that's a one. If the low
6349 HOST_BITS_PER_WIDE_INT bits are zero, return BIGGEST_ALIGNMENT.
6350 We need to handle this case since we can find it in a COND_EXPR,
6351 a MIN_EXPR, or a MAX_EXPR. If the constant overflows, we have an
6352 erroneous program, so return BIGGEST_ALIGNMENT to avoid any
6353 later ICE. */
6354 if (TREE_OVERFLOW (exp))
6355 return BIGGEST_ALIGNMENT;
6356 else
6358 /* Note: tree_low_cst is intentionally not used here,
6359 we don't care about the upper bits. */
6360 c0 = TREE_INT_CST_LOW (exp);
6361 c0 &= -c0;
6362 return c0 ? c0 : BIGGEST_ALIGNMENT;
6364 break;
6366 case PLUS_EXPR: case MINUS_EXPR: case MIN_EXPR: case MAX_EXPR:
6367 c0 = highest_pow2_factor (TREE_OPERAND (exp, 0));
6368 c1 = highest_pow2_factor (TREE_OPERAND (exp, 1));
6369 return MIN (c0, c1);
6371 case MULT_EXPR:
6372 c0 = highest_pow2_factor (TREE_OPERAND (exp, 0));
6373 c1 = highest_pow2_factor (TREE_OPERAND (exp, 1));
6374 return c0 * c1;
6376 case ROUND_DIV_EXPR: case TRUNC_DIV_EXPR: case FLOOR_DIV_EXPR:
6377 case CEIL_DIV_EXPR:
6378 if (integer_pow2p (TREE_OPERAND (exp, 1))
6379 && host_integerp (TREE_OPERAND (exp, 1), 1))
6381 c0 = highest_pow2_factor (TREE_OPERAND (exp, 0));
6382 c1 = tree_low_cst (TREE_OPERAND (exp, 1), 1);
6383 return MAX (1, c0 / c1);
6385 break;
6387 case NON_LVALUE_EXPR: case NOP_EXPR: case CONVERT_EXPR:
6388 case SAVE_EXPR:
6389 return highest_pow2_factor (TREE_OPERAND (exp, 0));
6391 case COMPOUND_EXPR:
6392 return highest_pow2_factor (TREE_OPERAND (exp, 1));
6394 case COND_EXPR:
6395 c0 = highest_pow2_factor (TREE_OPERAND (exp, 1));
6396 c1 = highest_pow2_factor (TREE_OPERAND (exp, 2));
6397 return MIN (c0, c1);
6399 default:
6400 break;
6403 return 1;
6406 /* Similar, except that the alignment requirements of TARGET are
6407 taken into account. Assume it is at least as aligned as its
6408 type, unless it is a COMPONENT_REF in which case the layout of
6409 the structure gives the alignment. */
6411 static unsigned HOST_WIDE_INT
6412 highest_pow2_factor_for_target (tree target, tree exp)
6414 unsigned HOST_WIDE_INT target_align, factor;
6416 factor = highest_pow2_factor (exp);
6417 if (TREE_CODE (target) == COMPONENT_REF)
6418 target_align = DECL_ALIGN_UNIT (TREE_OPERAND (target, 1));
6419 else
6420 target_align = TYPE_ALIGN_UNIT (TREE_TYPE (target));
6421 return MAX (factor, target_align);
6424 /* Expands variable VAR. */
6426 void
6427 expand_var (tree var)
6429 if (DECL_EXTERNAL (var))
6430 return;
6432 if (TREE_STATIC (var))
6433 /* If this is an inlined copy of a static local variable,
6434 look up the original decl. */
6435 var = DECL_ORIGIN (var);
6437 if (TREE_STATIC (var)
6438 ? !TREE_ASM_WRITTEN (var)
6439 : !DECL_RTL_SET_P (var))
6441 if (TREE_CODE (var) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (var))
6442 /* Should be ignored. */;
6443 else if (lang_hooks.expand_decl (var))
6444 /* OK. */;
6445 else if (TREE_CODE (var) == VAR_DECL && !TREE_STATIC (var))
6446 expand_decl (var);
6447 else if (TREE_CODE (var) == VAR_DECL && TREE_STATIC (var))
6448 rest_of_decl_compilation (var, 0, 0);
6449 else
6450 /* No expansion needed. */
6451 gcc_assert (TREE_CODE (var) == TYPE_DECL
6452 || TREE_CODE (var) == CONST_DECL
6453 || TREE_CODE (var) == FUNCTION_DECL
6454 || TREE_CODE (var) == LABEL_DECL);
6458 /* Subroutine of expand_expr. Expand the two operands of a binary
6459 expression EXP0 and EXP1 placing the results in OP0 and OP1.
6460 The value may be stored in TARGET if TARGET is nonzero. The
6461 MODIFIER argument is as documented by expand_expr. */
6463 static void
6464 expand_operands (tree exp0, tree exp1, rtx target, rtx *op0, rtx *op1,
6465 enum expand_modifier modifier)
6467 if (! safe_from_p (target, exp1, 1))
6468 target = 0;
6469 if (operand_equal_p (exp0, exp1, 0))
6471 *op0 = expand_expr (exp0, target, VOIDmode, modifier);
6472 *op1 = copy_rtx (*op0);
6474 else
6476 /* If we need to preserve evaluation order, copy exp0 into its own
6477 temporary variable so that it can't be clobbered by exp1. */
6478 if (flag_evaluation_order && TREE_SIDE_EFFECTS (exp1))
6479 exp0 = save_expr (exp0);
6480 *op0 = expand_expr (exp0, target, VOIDmode, modifier);
6481 *op1 = expand_expr (exp1, NULL_RTX, VOIDmode, modifier);
6486 /* Return a MEM that contains constant EXP. DEFER is as for
6487 output_constant_def and MODIFIER is as for expand_expr. */
6489 static rtx
6490 expand_expr_constant (tree exp, int defer, enum expand_modifier modifier)
6492 rtx mem;
6494 mem = output_constant_def (exp, defer);
6495 if (modifier != EXPAND_INITIALIZER)
6496 mem = use_anchored_address (mem);
6497 return mem;
6500 /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
6501 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
6503 static rtx
6504 expand_expr_addr_expr_1 (tree exp, rtx target, enum machine_mode tmode,
6505 enum expand_modifier modifier)
6507 rtx result, subtarget;
6508 tree inner, offset;
6509 HOST_WIDE_INT bitsize, bitpos;
6510 int volatilep, unsignedp;
6511 enum machine_mode mode1;
6513 /* If we are taking the address of a constant and are at the top level,
6514 we have to use output_constant_def since we can't call force_const_mem
6515 at top level. */
6516 /* ??? This should be considered a front-end bug. We should not be
6517 generating ADDR_EXPR of something that isn't an LVALUE. The only
6518 exception here is STRING_CST. */
6519 if (TREE_CODE (exp) == CONSTRUCTOR
6520 || CONSTANT_CLASS_P (exp))
6521 return XEXP (expand_expr_constant (exp, 0, modifier), 0);
6523 /* Everything must be something allowed by is_gimple_addressable. */
6524 switch (TREE_CODE (exp))
6526 case INDIRECT_REF:
6527 /* This case will happen via recursion for &a->b. */
6528 return expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
6530 case CONST_DECL:
6531 /* Recurse and make the output_constant_def clause above handle this. */
6532 return expand_expr_addr_expr_1 (DECL_INITIAL (exp), target,
6533 tmode, modifier);
6535 case REALPART_EXPR:
6536 /* The real part of the complex number is always first, therefore
6537 the address is the same as the address of the parent object. */
6538 offset = 0;
6539 bitpos = 0;
6540 inner = TREE_OPERAND (exp, 0);
6541 break;
6543 case IMAGPART_EXPR:
6544 /* The imaginary part of the complex number is always second.
6545 The expression is therefore always offset by the size of the
6546 scalar type. */
6547 offset = 0;
6548 bitpos = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp)));
6549 inner = TREE_OPERAND (exp, 0);
6550 break;
6552 default:
6553 /* If the object is a DECL, then expand it for its rtl. Don't bypass
6554 expand_expr, as that can have various side effects; LABEL_DECLs for
6555 example, may not have their DECL_RTL set yet. Assume language
6556 specific tree nodes can be expanded in some interesting way. */
6557 if (DECL_P (exp)
6558 || TREE_CODE (exp) >= LAST_AND_UNUSED_TREE_CODE)
6560 result = expand_expr (exp, target, tmode,
6561 modifier == EXPAND_INITIALIZER
6562 ? EXPAND_INITIALIZER : EXPAND_CONST_ADDRESS);
6564 /* If the DECL isn't in memory, then the DECL wasn't properly
6565 marked TREE_ADDRESSABLE, which will be either a front-end
6566 or a tree optimizer bug. */
6567 gcc_assert (MEM_P (result));
6568 result = XEXP (result, 0);
6570 /* ??? Is this needed anymore? */
6571 if (DECL_P (exp) && !TREE_USED (exp) == 0)
6573 assemble_external (exp);
6574 TREE_USED (exp) = 1;
6577 if (modifier != EXPAND_INITIALIZER
6578 && modifier != EXPAND_CONST_ADDRESS)
6579 result = force_operand (result, target);
6580 return result;
6583 /* Pass FALSE as the last argument to get_inner_reference although
6584 we are expanding to RTL. The rationale is that we know how to
6585 handle "aligning nodes" here: we can just bypass them because
6586 they won't change the final object whose address will be returned
6587 (they actually exist only for that purpose). */
6588 inner = get_inner_reference (exp, &bitsize, &bitpos, &offset,
6589 &mode1, &unsignedp, &volatilep, false);
6590 break;
6593 /* We must have made progress. */
6594 gcc_assert (inner != exp);
6596 subtarget = offset || bitpos ? NULL_RTX : target;
6597 result = expand_expr_addr_expr_1 (inner, subtarget, tmode, modifier);
6599 if (offset)
6601 rtx tmp;
6603 if (modifier != EXPAND_NORMAL)
6604 result = force_operand (result, NULL);
6605 tmp = expand_expr (offset, NULL, tmode, EXPAND_NORMAL);
6607 result = convert_memory_address (tmode, result);
6608 tmp = convert_memory_address (tmode, tmp);
6610 if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
6611 result = gen_rtx_PLUS (tmode, result, tmp);
6612 else
6614 subtarget = bitpos ? NULL_RTX : target;
6615 result = expand_simple_binop (tmode, PLUS, result, tmp, subtarget,
6616 1, OPTAB_LIB_WIDEN);
6620 if (bitpos)
6622 /* Someone beforehand should have rejected taking the address
6623 of such an object. */
6624 gcc_assert ((bitpos % BITS_PER_UNIT) == 0);
6626 result = plus_constant (result, bitpos / BITS_PER_UNIT);
6627 if (modifier < EXPAND_SUM)
6628 result = force_operand (result, target);
6631 return result;
6634 /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
6635 The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
6637 static rtx
6638 expand_expr_addr_expr (tree exp, rtx target, enum machine_mode tmode,
6639 enum expand_modifier modifier)
6641 enum machine_mode rmode;
6642 rtx result;
6644 /* Target mode of VOIDmode says "whatever's natural". */
6645 if (tmode == VOIDmode)
6646 tmode = TYPE_MODE (TREE_TYPE (exp));
6648 /* We can get called with some Weird Things if the user does silliness
6649 like "(short) &a". In that case, convert_memory_address won't do
6650 the right thing, so ignore the given target mode. */
6651 if (tmode != Pmode && tmode != ptr_mode)
6652 tmode = Pmode;
6654 result = expand_expr_addr_expr_1 (TREE_OPERAND (exp, 0), target,
6655 tmode, modifier);
6657 /* Despite expand_expr claims concerning ignoring TMODE when not
6658 strictly convenient, stuff breaks if we don't honor it. Note
6659 that combined with the above, we only do this for pointer modes. */
6660 rmode = GET_MODE (result);
6661 if (rmode == VOIDmode)
6662 rmode = tmode;
6663 if (rmode != tmode)
6664 result = convert_memory_address (tmode, result);
6666 return result;
6670 /* expand_expr: generate code for computing expression EXP.
6671 An rtx for the computed value is returned. The value is never null.
6672 In the case of a void EXP, const0_rtx is returned.
6674 The value may be stored in TARGET if TARGET is nonzero.
6675 TARGET is just a suggestion; callers must assume that
6676 the rtx returned may not be the same as TARGET.
6678 If TARGET is CONST0_RTX, it means that the value will be ignored.
6680 If TMODE is not VOIDmode, it suggests generating the
6681 result in mode TMODE. But this is done only when convenient.
6682 Otherwise, TMODE is ignored and the value generated in its natural mode.
6683 TMODE is just a suggestion; callers must assume that
6684 the rtx returned may not have mode TMODE.
6686 Note that TARGET may have neither TMODE nor MODE. In that case, it
6687 probably will not be used.
6689 If MODIFIER is EXPAND_SUM then when EXP is an addition
6690 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
6691 or a nest of (PLUS ...) and (MINUS ...) where the terms are
6692 products as above, or REG or MEM, or constant.
6693 Ordinarily in such cases we would output mul or add instructions
6694 and then return a pseudo reg containing the sum.
6696 EXPAND_INITIALIZER is much like EXPAND_SUM except that
6697 it also marks a label as absolutely required (it can't be dead).
6698 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
6699 This is used for outputting expressions used in initializers.
6701 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
6702 with a constant address even if that address is not normally legitimate.
6703 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
6705 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
6706 a call parameter. Such targets require special care as we haven't yet
6707 marked TARGET so that it's safe from being trashed by libcalls. We
6708 don't want to use TARGET for anything but the final result;
6709 Intermediate values must go elsewhere. Additionally, calls to
6710 emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
6712 If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
6713 address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
6714 DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
6715 COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
6716 recursively. */
6718 static rtx expand_expr_real_1 (tree, rtx, enum machine_mode,
6719 enum expand_modifier, rtx *);
6722 expand_expr_real (tree exp, rtx target, enum machine_mode tmode,
6723 enum expand_modifier modifier, rtx *alt_rtl)
6725 int rn = -1;
6726 rtx ret, last = NULL;
6728 /* Handle ERROR_MARK before anybody tries to access its type. */
6729 if (TREE_CODE (exp) == ERROR_MARK
6730 || (!GIMPLE_TUPLE_P (exp) && TREE_CODE (TREE_TYPE (exp)) == ERROR_MARK))
6732 ret = CONST0_RTX (tmode);
6733 return ret ? ret : const0_rtx;
6736 if (flag_non_call_exceptions)
6738 rn = lookup_stmt_eh_region (exp);
6739 /* If rn < 0, then either (1) tree-ssa not used or (2) doesn't throw. */
6740 if (rn >= 0)
6741 last = get_last_insn ();
6744 /* If this is an expression of some kind and it has an associated line
6745 number, then emit the line number before expanding the expression.
6747 We need to save and restore the file and line information so that
6748 errors discovered during expansion are emitted with the right
6749 information. It would be better of the diagnostic routines
6750 used the file/line information embedded in the tree nodes rather
6751 than globals. */
6752 if (cfun && cfun->ib_boundaries_block && EXPR_HAS_LOCATION (exp))
6754 location_t saved_location = input_location;
6755 input_location = EXPR_LOCATION (exp);
6756 emit_line_note (input_location);
6758 /* Record where the insns produced belong. */
6759 record_block_change (TREE_BLOCK (exp));
6761 ret = expand_expr_real_1 (exp, target, tmode, modifier, alt_rtl);
6763 input_location = saved_location;
6765 else
6767 ret = expand_expr_real_1 (exp, target, tmode, modifier, alt_rtl);
6770 /* If using non-call exceptions, mark all insns that may trap.
6771 expand_call() will mark CALL_INSNs before we get to this code,
6772 but it doesn't handle libcalls, and these may trap. */
6773 if (rn >= 0)
6775 rtx insn;
6776 for (insn = next_real_insn (last); insn;
6777 insn = next_real_insn (insn))
6779 if (! find_reg_note (insn, REG_EH_REGION, NULL_RTX)
6780 /* If we want exceptions for non-call insns, any
6781 may_trap_p instruction may throw. */
6782 && GET_CODE (PATTERN (insn)) != CLOBBER
6783 && GET_CODE (PATTERN (insn)) != USE
6784 && (CALL_P (insn) || may_trap_p (PATTERN (insn))))
6786 REG_NOTES (insn) = alloc_EXPR_LIST (REG_EH_REGION, GEN_INT (rn),
6787 REG_NOTES (insn));
6792 return ret;
6795 static rtx
6796 expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
6797 enum expand_modifier modifier, rtx *alt_rtl)
6799 rtx op0, op1, temp, decl_rtl;
6800 tree type;
6801 int unsignedp;
6802 enum machine_mode mode;
6803 enum tree_code code = TREE_CODE (exp);
6804 optab this_optab;
6805 rtx subtarget, original_target;
6806 int ignore;
6807 tree context, subexp0, subexp1;
6808 bool reduce_bit_field = false;
6809 #define REDUCE_BIT_FIELD(expr) (reduce_bit_field && !ignore \
6810 ? reduce_to_bit_field_precision ((expr), \
6811 target, \
6812 type) \
6813 : (expr))
6815 if (GIMPLE_STMT_P (exp))
6817 type = void_type_node;
6818 mode = VOIDmode;
6819 unsignedp = 0;
6821 else
6823 type = TREE_TYPE (exp);
6824 mode = TYPE_MODE (type);
6825 unsignedp = TYPE_UNSIGNED (type);
6827 if (lang_hooks.reduce_bit_field_operations
6828 && TREE_CODE (type) == INTEGER_TYPE
6829 && GET_MODE_PRECISION (mode) > TYPE_PRECISION (type))
6831 /* An operation in what may be a bit-field type needs the
6832 result to be reduced to the precision of the bit-field type,
6833 which is narrower than that of the type's mode. */
6834 reduce_bit_field = true;
6835 if (modifier == EXPAND_STACK_PARM)
6836 target = 0;
6839 /* Use subtarget as the target for operand 0 of a binary operation. */
6840 subtarget = get_subtarget (target);
6841 original_target = target;
6842 ignore = (target == const0_rtx
6843 || ((code == NON_LVALUE_EXPR || code == NOP_EXPR
6844 || code == CONVERT_EXPR || code == COND_EXPR
6845 || code == VIEW_CONVERT_EXPR)
6846 && TREE_CODE (type) == VOID_TYPE));
6848 /* If we are going to ignore this result, we need only do something
6849 if there is a side-effect somewhere in the expression. If there
6850 is, short-circuit the most common cases here. Note that we must
6851 not call expand_expr with anything but const0_rtx in case this
6852 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
6854 if (ignore)
6856 if (! TREE_SIDE_EFFECTS (exp))
6857 return const0_rtx;
6859 /* Ensure we reference a volatile object even if value is ignored, but
6860 don't do this if all we are doing is taking its address. */
6861 if (TREE_THIS_VOLATILE (exp)
6862 && TREE_CODE (exp) != FUNCTION_DECL
6863 && mode != VOIDmode && mode != BLKmode
6864 && modifier != EXPAND_CONST_ADDRESS)
6866 temp = expand_expr (exp, NULL_RTX, VOIDmode, modifier);
6867 if (MEM_P (temp))
6868 temp = copy_to_reg (temp);
6869 return const0_rtx;
6872 if (TREE_CODE_CLASS (code) == tcc_unary
6873 || code == COMPONENT_REF || code == INDIRECT_REF)
6874 return expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
6875 modifier);
6877 else if (TREE_CODE_CLASS (code) == tcc_binary
6878 || TREE_CODE_CLASS (code) == tcc_comparison
6879 || code == ARRAY_REF || code == ARRAY_RANGE_REF)
6881 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, modifier);
6882 expand_expr (TREE_OPERAND (exp, 1), const0_rtx, VOIDmode, modifier);
6883 return const0_rtx;
6885 else if (code == BIT_FIELD_REF)
6887 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, modifier);
6888 expand_expr (TREE_OPERAND (exp, 1), const0_rtx, VOIDmode, modifier);
6889 expand_expr (TREE_OPERAND (exp, 2), const0_rtx, VOIDmode, modifier);
6890 return const0_rtx;
6893 target = 0;
6897 switch (code)
6899 case LABEL_DECL:
6901 tree function = decl_function_context (exp);
6903 temp = label_rtx (exp);
6904 temp = gen_rtx_LABEL_REF (Pmode, temp);
6906 if (function != current_function_decl
6907 && function != 0)
6908 LABEL_REF_NONLOCAL_P (temp) = 1;
6910 temp = gen_rtx_MEM (FUNCTION_MODE, temp);
6911 return temp;
6914 case SSA_NAME:
6915 return expand_expr_real_1 (SSA_NAME_VAR (exp), target, tmode, modifier,
6916 NULL);
6918 case PARM_DECL:
6919 case VAR_DECL:
6920 /* If a static var's type was incomplete when the decl was written,
6921 but the type is complete now, lay out the decl now. */
6922 if (DECL_SIZE (exp) == 0
6923 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp))
6924 && (TREE_STATIC (exp) || DECL_EXTERNAL (exp)))
6925 layout_decl (exp, 0);
6927 /* ... fall through ... */
6929 case FUNCTION_DECL:
6930 case RESULT_DECL:
6931 decl_rtl = DECL_RTL (exp);
6932 gcc_assert (decl_rtl);
6934 /* Ensure variable marked as used even if it doesn't go through
6935 a parser. If it hasn't be used yet, write out an external
6936 definition. */
6937 if (! TREE_USED (exp))
6939 assemble_external (exp);
6940 TREE_USED (exp) = 1;
6943 /* Show we haven't gotten RTL for this yet. */
6944 temp = 0;
6946 /* Variables inherited from containing functions should have
6947 been lowered by this point. */
6948 context = decl_function_context (exp);
6949 gcc_assert (!context
6950 || context == current_function_decl
6951 || TREE_STATIC (exp)
6952 /* ??? C++ creates functions that are not TREE_STATIC. */
6953 || TREE_CODE (exp) == FUNCTION_DECL);
6955 /* This is the case of an array whose size is to be determined
6956 from its initializer, while the initializer is still being parsed.
6957 See expand_decl. */
6959 if (MEM_P (decl_rtl) && REG_P (XEXP (decl_rtl, 0)))
6960 temp = validize_mem (decl_rtl);
6962 /* If DECL_RTL is memory, we are in the normal case and either
6963 the address is not valid or it is not a register and -fforce-addr
6964 is specified, get the address into a register. */
6966 else if (MEM_P (decl_rtl) && modifier != EXPAND_INITIALIZER)
6968 if (alt_rtl)
6969 *alt_rtl = decl_rtl;
6970 decl_rtl = use_anchored_address (decl_rtl);
6971 if (modifier != EXPAND_CONST_ADDRESS
6972 && modifier != EXPAND_SUM
6973 && (!memory_address_p (DECL_MODE (exp), XEXP (decl_rtl, 0))
6974 || (flag_force_addr && !REG_P (XEXP (decl_rtl, 0)))))
6975 temp = replace_equiv_address (decl_rtl,
6976 copy_rtx (XEXP (decl_rtl, 0)));
6979 /* If we got something, return it. But first, set the alignment
6980 if the address is a register. */
6981 if (temp != 0)
6983 if (MEM_P (temp) && REG_P (XEXP (temp, 0)))
6984 mark_reg_pointer (XEXP (temp, 0), DECL_ALIGN (exp));
6986 return temp;
6989 /* If the mode of DECL_RTL does not match that of the decl, it
6990 must be a promoted value. We return a SUBREG of the wanted mode,
6991 but mark it so that we know that it was already extended. */
6993 if (REG_P (decl_rtl)
6994 && GET_MODE (decl_rtl) != DECL_MODE (exp))
6996 enum machine_mode pmode;
6998 /* Get the signedness used for this variable. Ensure we get the
6999 same mode we got when the variable was declared. */
7000 pmode = promote_mode (type, DECL_MODE (exp), &unsignedp,
7001 (TREE_CODE (exp) == RESULT_DECL
7002 || TREE_CODE (exp) == PARM_DECL) ? 1 : 0);
7003 gcc_assert (GET_MODE (decl_rtl) == pmode);
7005 temp = gen_lowpart_SUBREG (mode, decl_rtl);
7006 SUBREG_PROMOTED_VAR_P (temp) = 1;
7007 SUBREG_PROMOTED_UNSIGNED_SET (temp, unsignedp);
7008 return temp;
7011 return decl_rtl;
7013 case INTEGER_CST:
7014 temp = immed_double_const (TREE_INT_CST_LOW (exp),
7015 TREE_INT_CST_HIGH (exp), mode);
7017 /* ??? If overflow is set, fold will have done an incomplete job,
7018 which can result in (plus xx (const_int 0)), which can get
7019 simplified by validate_replace_rtx during virtual register
7020 instantiation, which can result in unrecognizable insns.
7021 Avoid this by forcing all overflows into registers. */
7022 if (TREE_OVERFLOW (exp)
7023 && modifier != EXPAND_INITIALIZER)
7024 temp = force_reg (mode, temp);
7026 return temp;
7028 case VECTOR_CST:
7030 tree tmp = NULL_TREE;
7031 if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
7032 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
7033 return const_vector_from_tree (exp);
7034 if (GET_MODE_CLASS (mode) == MODE_INT)
7036 tree type_for_mode = lang_hooks.types.type_for_mode (mode, 1);
7037 if (type_for_mode)
7038 tmp = fold_unary (VIEW_CONVERT_EXPR, type_for_mode, exp);
7040 if (!tmp)
7041 tmp = build_constructor_from_list (type,
7042 TREE_VECTOR_CST_ELTS (exp));
7043 return expand_expr (tmp, ignore ? const0_rtx : target,
7044 tmode, modifier);
7047 case CONST_DECL:
7048 return expand_expr (DECL_INITIAL (exp), target, VOIDmode, modifier);
7050 case REAL_CST:
7051 /* If optimized, generate immediate CONST_DOUBLE
7052 which will be turned into memory by reload if necessary.
7054 We used to force a register so that loop.c could see it. But
7055 this does not allow gen_* patterns to perform optimizations with
7056 the constants. It also produces two insns in cases like "x = 1.0;".
7057 On most machines, floating-point constants are not permitted in
7058 many insns, so we'd end up copying it to a register in any case.
7060 Now, we do the copying in expand_binop, if appropriate. */
7061 return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp),
7062 TYPE_MODE (TREE_TYPE (exp)));
7064 case COMPLEX_CST:
7065 /* Handle evaluating a complex constant in a CONCAT target. */
7066 if (original_target && GET_CODE (original_target) == CONCAT)
7068 enum machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
7069 rtx rtarg, itarg;
7071 rtarg = XEXP (original_target, 0);
7072 itarg = XEXP (original_target, 1);
7074 /* Move the real and imaginary parts separately. */
7075 op0 = expand_expr (TREE_REALPART (exp), rtarg, mode, 0);
7076 op1 = expand_expr (TREE_IMAGPART (exp), itarg, mode, 0);
7078 if (op0 != rtarg)
7079 emit_move_insn (rtarg, op0);
7080 if (op1 != itarg)
7081 emit_move_insn (itarg, op1);
7083 return original_target;
7086 /* ... fall through ... */
7088 case STRING_CST:
7089 temp = expand_expr_constant (exp, 1, modifier);
7091 /* temp contains a constant address.
7092 On RISC machines where a constant address isn't valid,
7093 make some insns to get that address into a register. */
7094 if (modifier != EXPAND_CONST_ADDRESS
7095 && modifier != EXPAND_INITIALIZER
7096 && modifier != EXPAND_SUM
7097 && (! memory_address_p (mode, XEXP (temp, 0))
7098 || flag_force_addr))
7099 return replace_equiv_address (temp,
7100 copy_rtx (XEXP (temp, 0)));
7101 return temp;
7103 case SAVE_EXPR:
7105 tree val = TREE_OPERAND (exp, 0);
7106 rtx ret = expand_expr_real_1 (val, target, tmode, modifier, alt_rtl);
7108 if (!SAVE_EXPR_RESOLVED_P (exp))
7110 /* We can indeed still hit this case, typically via builtin
7111 expanders calling save_expr immediately before expanding
7112 something. Assume this means that we only have to deal
7113 with non-BLKmode values. */
7114 gcc_assert (GET_MODE (ret) != BLKmode);
7116 val = build_decl (VAR_DECL, NULL, TREE_TYPE (exp));
7117 DECL_ARTIFICIAL (val) = 1;
7118 DECL_IGNORED_P (val) = 1;
7119 TREE_OPERAND (exp, 0) = val;
7120 SAVE_EXPR_RESOLVED_P (exp) = 1;
7122 if (!CONSTANT_P (ret))
7123 ret = copy_to_reg (ret);
7124 SET_DECL_RTL (val, ret);
7127 return ret;
7130 case GOTO_EXPR:
7131 if (TREE_CODE (TREE_OPERAND (exp, 0)) == LABEL_DECL)
7132 expand_goto (TREE_OPERAND (exp, 0));
7133 else
7134 expand_computed_goto (TREE_OPERAND (exp, 0));
7135 return const0_rtx;
7137 case CONSTRUCTOR:
7138 /* If we don't need the result, just ensure we evaluate any
7139 subexpressions. */
7140 if (ignore)
7142 unsigned HOST_WIDE_INT idx;
7143 tree value;
7145 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
7146 expand_expr (value, const0_rtx, VOIDmode, 0);
7148 return const0_rtx;
7151 /* Try to avoid creating a temporary at all. This is possible
7152 if all of the initializer is zero.
7153 FIXME: try to handle all [0..255] initializers we can handle
7154 with memset. */
7155 else if (TREE_STATIC (exp)
7156 && !TREE_ADDRESSABLE (exp)
7157 && target != 0 && mode == BLKmode
7158 && all_zeros_p (exp))
7160 clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
7161 return target;
7164 /* All elts simple constants => refer to a constant in memory. But
7165 if this is a non-BLKmode mode, let it store a field at a time
7166 since that should make a CONST_INT or CONST_DOUBLE when we
7167 fold. Likewise, if we have a target we can use, it is best to
7168 store directly into the target unless the type is large enough
7169 that memcpy will be used. If we are making an initializer and
7170 all operands are constant, put it in memory as well.
7172 FIXME: Avoid trying to fill vector constructors piece-meal.
7173 Output them with output_constant_def below unless we're sure
7174 they're zeros. This should go away when vector initializers
7175 are treated like VECTOR_CST instead of arrays.
7177 else if ((TREE_STATIC (exp)
7178 && ((mode == BLKmode
7179 && ! (target != 0 && safe_from_p (target, exp, 1)))
7180 || TREE_ADDRESSABLE (exp)
7181 || (host_integerp (TYPE_SIZE_UNIT (type), 1)
7182 && (! MOVE_BY_PIECES_P
7183 (tree_low_cst (TYPE_SIZE_UNIT (type), 1),
7184 TYPE_ALIGN (type)))
7185 && ! mostly_zeros_p (exp))))
7186 || ((modifier == EXPAND_INITIALIZER
7187 || modifier == EXPAND_CONST_ADDRESS)
7188 && TREE_CONSTANT (exp)))
7190 rtx constructor = expand_expr_constant (exp, 1, modifier);
7192 if (modifier != EXPAND_CONST_ADDRESS
7193 && modifier != EXPAND_INITIALIZER
7194 && modifier != EXPAND_SUM)
7195 constructor = validize_mem (constructor);
7197 return constructor;
7199 else
7201 /* Handle calls that pass values in multiple non-contiguous
7202 locations. The Irix 6 ABI has examples of this. */
7203 if (target == 0 || ! safe_from_p (target, exp, 1)
7204 || GET_CODE (target) == PARALLEL
7205 || modifier == EXPAND_STACK_PARM)
7206 target
7207 = assign_temp (build_qualified_type (type,
7208 (TYPE_QUALS (type)
7209 | (TREE_READONLY (exp)
7210 * TYPE_QUAL_CONST))),
7211 0, TREE_ADDRESSABLE (exp), 1);
7213 store_constructor (exp, target, 0, int_expr_size (exp));
7214 return target;
7217 case MISALIGNED_INDIRECT_REF:
7218 case ALIGN_INDIRECT_REF:
7219 case INDIRECT_REF:
7221 tree exp1 = TREE_OPERAND (exp, 0);
7223 if (modifier != EXPAND_WRITE)
7225 tree t;
7227 t = fold_read_from_constant_string (exp);
7228 if (t)
7229 return expand_expr (t, target, tmode, modifier);
7232 op0 = expand_expr (exp1, NULL_RTX, VOIDmode, EXPAND_SUM);
7233 op0 = memory_address (mode, op0);
7235 if (code == ALIGN_INDIRECT_REF)
7237 int align = TYPE_ALIGN_UNIT (type);
7238 op0 = gen_rtx_AND (Pmode, op0, GEN_INT (-align));
7239 op0 = memory_address (mode, op0);
7242 temp = gen_rtx_MEM (mode, op0);
7244 set_mem_attributes (temp, exp, 0);
7246 /* Resolve the misalignment now, so that we don't have to remember
7247 to resolve it later. Of course, this only works for reads. */
7248 /* ??? When we get around to supporting writes, we'll have to handle
7249 this in store_expr directly. The vectorizer isn't generating
7250 those yet, however. */
7251 if (code == MISALIGNED_INDIRECT_REF)
7253 int icode;
7254 rtx reg, insn;
7256 gcc_assert (modifier == EXPAND_NORMAL
7257 || modifier == EXPAND_STACK_PARM);
7259 /* The vectorizer should have already checked the mode. */
7260 icode = movmisalign_optab->handlers[mode].insn_code;
7261 gcc_assert (icode != CODE_FOR_nothing);
7263 /* We've already validated the memory, and we're creating a
7264 new pseudo destination. The predicates really can't fail. */
7265 reg = gen_reg_rtx (mode);
7267 /* Nor can the insn generator. */
7268 insn = GEN_FCN (icode) (reg, temp);
7269 emit_insn (insn);
7271 return reg;
7274 return temp;
7277 case TARGET_MEM_REF:
7279 struct mem_address addr;
7281 get_address_description (exp, &addr);
7282 op0 = addr_for_mem_ref (&addr, true);
7283 op0 = memory_address (mode, op0);
7284 temp = gen_rtx_MEM (mode, op0);
7285 set_mem_attributes (temp, TMR_ORIGINAL (exp), 0);
7287 return temp;
7289 case ARRAY_REF:
7292 tree array = TREE_OPERAND (exp, 0);
7293 tree index = TREE_OPERAND (exp, 1);
7295 /* Fold an expression like: "foo"[2].
7296 This is not done in fold so it won't happen inside &.
7297 Don't fold if this is for wide characters since it's too
7298 difficult to do correctly and this is a very rare case. */
7300 if (modifier != EXPAND_CONST_ADDRESS
7301 && modifier != EXPAND_INITIALIZER
7302 && modifier != EXPAND_MEMORY)
7304 tree t = fold_read_from_constant_string (exp);
7306 if (t)
7307 return expand_expr (t, target, tmode, modifier);
7310 /* If this is a constant index into a constant array,
7311 just get the value from the array. Handle both the cases when
7312 we have an explicit constructor and when our operand is a variable
7313 that was declared const. */
7315 if (modifier != EXPAND_CONST_ADDRESS
7316 && modifier != EXPAND_INITIALIZER
7317 && modifier != EXPAND_MEMORY
7318 && TREE_CODE (array) == CONSTRUCTOR
7319 && ! TREE_SIDE_EFFECTS (array)
7320 && TREE_CODE (index) == INTEGER_CST)
7322 unsigned HOST_WIDE_INT ix;
7323 tree field, value;
7325 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array), ix,
7326 field, value)
7327 if (tree_int_cst_equal (field, index))
7329 if (!TREE_SIDE_EFFECTS (value))
7330 return expand_expr (fold (value), target, tmode, modifier);
7331 break;
7335 else if (optimize >= 1
7336 && modifier != EXPAND_CONST_ADDRESS
7337 && modifier != EXPAND_INITIALIZER
7338 && modifier != EXPAND_MEMORY
7339 && TREE_READONLY (array) && ! TREE_SIDE_EFFECTS (array)
7340 && TREE_CODE (array) == VAR_DECL && DECL_INITIAL (array)
7341 && TREE_CODE (DECL_INITIAL (array)) != ERROR_MARK
7342 && targetm.binds_local_p (array))
7344 if (TREE_CODE (index) == INTEGER_CST)
7346 tree init = DECL_INITIAL (array);
7348 if (TREE_CODE (init) == CONSTRUCTOR)
7350 unsigned HOST_WIDE_INT ix;
7351 tree field, value;
7353 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), ix,
7354 field, value)
7355 if (tree_int_cst_equal (field, index))
7357 if (!TREE_SIDE_EFFECTS (value))
7358 return expand_expr (fold (value), target, tmode,
7359 modifier);
7360 break;
7363 else if(TREE_CODE (init) == STRING_CST)
7365 tree index1 = index;
7366 tree low_bound = array_ref_low_bound (exp);
7367 index1 = fold_convert (sizetype, TREE_OPERAND (exp, 1));
7369 /* Optimize the special-case of a zero lower bound.
7371 We convert the low_bound to sizetype to avoid some problems
7372 with constant folding. (E.g. suppose the lower bound is 1,
7373 and its mode is QI. Without the conversion,l (ARRAY
7374 +(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1))
7375 +INDEX), which becomes (ARRAY+255+INDEX). Opps!) */
7377 if (! integer_zerop (low_bound))
7378 index1 = size_diffop (index1, fold_convert (sizetype,
7379 low_bound));
7381 if (0 > compare_tree_int (index1,
7382 TREE_STRING_LENGTH (init)))
7384 tree type = TREE_TYPE (TREE_TYPE (init));
7385 enum machine_mode mode = TYPE_MODE (type);
7387 if (GET_MODE_CLASS (mode) == MODE_INT
7388 && GET_MODE_SIZE (mode) == 1)
7389 return gen_int_mode (TREE_STRING_POINTER (init)
7390 [TREE_INT_CST_LOW (index1)],
7391 mode);
7397 goto normal_inner_ref;
7399 case COMPONENT_REF:
7400 /* If the operand is a CONSTRUCTOR, we can just extract the
7401 appropriate field if it is present. */
7402 if (TREE_CODE (TREE_OPERAND (exp, 0)) == CONSTRUCTOR)
7404 unsigned HOST_WIDE_INT idx;
7405 tree field, value;
7407 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (TREE_OPERAND (exp, 0)),
7408 idx, field, value)
7409 if (field == TREE_OPERAND (exp, 1)
7410 /* We can normally use the value of the field in the
7411 CONSTRUCTOR. However, if this is a bitfield in
7412 an integral mode that we can fit in a HOST_WIDE_INT,
7413 we must mask only the number of bits in the bitfield,
7414 since this is done implicitly by the constructor. If
7415 the bitfield does not meet either of those conditions,
7416 we can't do this optimization. */
7417 && (! DECL_BIT_FIELD (field)
7418 || ((GET_MODE_CLASS (DECL_MODE (field)) == MODE_INT)
7419 && (GET_MODE_BITSIZE (DECL_MODE (field))
7420 <= HOST_BITS_PER_WIDE_INT))))
7422 if (DECL_BIT_FIELD (field)
7423 && modifier == EXPAND_STACK_PARM)
7424 target = 0;
7425 op0 = expand_expr (value, target, tmode, modifier);
7426 if (DECL_BIT_FIELD (field))
7428 HOST_WIDE_INT bitsize = TREE_INT_CST_LOW (DECL_SIZE (field));
7429 enum machine_mode imode = TYPE_MODE (TREE_TYPE (field));
7431 if (TYPE_UNSIGNED (TREE_TYPE (field)))
7433 op1 = GEN_INT (((HOST_WIDE_INT) 1 << bitsize) - 1);
7434 op0 = expand_and (imode, op0, op1, target);
7436 else
7438 tree count
7439 = build_int_cst (NULL_TREE,
7440 GET_MODE_BITSIZE (imode) - bitsize);
7442 op0 = expand_shift (LSHIFT_EXPR, imode, op0, count,
7443 target, 0);
7444 op0 = expand_shift (RSHIFT_EXPR, imode, op0, count,
7445 target, 0);
7449 return op0;
7452 goto normal_inner_ref;
7454 case BIT_FIELD_REF:
7455 case ARRAY_RANGE_REF:
7456 normal_inner_ref:
7458 enum machine_mode mode1;
7459 HOST_WIDE_INT bitsize, bitpos;
7460 tree offset;
7461 int volatilep = 0;
7462 tree tem = get_inner_reference (exp, &bitsize, &bitpos, &offset,
7463 &mode1, &unsignedp, &volatilep, true);
7464 rtx orig_op0;
7466 /* If we got back the original object, something is wrong. Perhaps
7467 we are evaluating an expression too early. In any event, don't
7468 infinitely recurse. */
7469 gcc_assert (tem != exp);
7471 /* If TEM's type is a union of variable size, pass TARGET to the inner
7472 computation, since it will need a temporary and TARGET is known
7473 to have to do. This occurs in unchecked conversion in Ada. */
7475 orig_op0 = op0
7476 = expand_expr (tem,
7477 (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
7478 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
7479 != INTEGER_CST)
7480 && modifier != EXPAND_STACK_PARM
7481 ? target : NULL_RTX),
7482 VOIDmode,
7483 (modifier == EXPAND_INITIALIZER
7484 || modifier == EXPAND_CONST_ADDRESS
7485 || modifier == EXPAND_STACK_PARM)
7486 ? modifier : EXPAND_NORMAL);
7488 /* If this is a constant, put it into a register if it is a legitimate
7489 constant, OFFSET is 0, and we won't try to extract outside the
7490 register (in case we were passed a partially uninitialized object
7491 or a view_conversion to a larger size). Force the constant to
7492 memory otherwise. */
7493 if (CONSTANT_P (op0))
7495 enum machine_mode mode = TYPE_MODE (TREE_TYPE (tem));
7496 if (mode != BLKmode && LEGITIMATE_CONSTANT_P (op0)
7497 && offset == 0
7498 && bitpos + bitsize <= GET_MODE_BITSIZE (mode))
7499 op0 = force_reg (mode, op0);
7500 else
7501 op0 = validize_mem (force_const_mem (mode, op0));
7504 /* Otherwise, if this object not in memory and we either have an
7505 offset, a BLKmode result, or a reference outside the object, put it
7506 there. Such cases can occur in Ada if we have unchecked conversion
7507 of an expression from a scalar type to an array or record type or
7508 for an ARRAY_RANGE_REF whose type is BLKmode. */
7509 else if (!MEM_P (op0)
7510 && (offset != 0
7511 || (bitpos + bitsize > GET_MODE_BITSIZE (GET_MODE (op0)))
7512 || (code == ARRAY_RANGE_REF && mode == BLKmode)))
7514 tree nt = build_qualified_type (TREE_TYPE (tem),
7515 (TYPE_QUALS (TREE_TYPE (tem))
7516 | TYPE_QUAL_CONST));
7517 rtx memloc = assign_temp (nt, 1, 1, 1);
7519 emit_move_insn (memloc, op0);
7520 op0 = memloc;
7523 if (offset != 0)
7525 rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode,
7526 EXPAND_SUM);
7528 gcc_assert (MEM_P (op0));
7530 #ifdef POINTERS_EXTEND_UNSIGNED
7531 if (GET_MODE (offset_rtx) != Pmode)
7532 offset_rtx = convert_to_mode (Pmode, offset_rtx, 0);
7533 #else
7534 if (GET_MODE (offset_rtx) != ptr_mode)
7535 offset_rtx = convert_to_mode (ptr_mode, offset_rtx, 0);
7536 #endif
7538 if (GET_MODE (op0) == BLKmode
7539 /* A constant address in OP0 can have VOIDmode, we must
7540 not try to call force_reg in that case. */
7541 && GET_MODE (XEXP (op0, 0)) != VOIDmode
7542 && bitsize != 0
7543 && (bitpos % bitsize) == 0
7544 && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
7545 && MEM_ALIGN (op0) == GET_MODE_ALIGNMENT (mode1))
7547 op0 = adjust_address (op0, mode1, bitpos / BITS_PER_UNIT);
7548 bitpos = 0;
7551 op0 = offset_address (op0, offset_rtx,
7552 highest_pow2_factor (offset));
7555 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
7556 record its alignment as BIGGEST_ALIGNMENT. */
7557 if (MEM_P (op0) && bitpos == 0 && offset != 0
7558 && is_aligning_offset (offset, tem))
7559 set_mem_align (op0, BIGGEST_ALIGNMENT);
7561 /* Don't forget about volatility even if this is a bitfield. */
7562 if (MEM_P (op0) && volatilep && ! MEM_VOLATILE_P (op0))
7564 if (op0 == orig_op0)
7565 op0 = copy_rtx (op0);
7567 MEM_VOLATILE_P (op0) = 1;
7570 /* The following code doesn't handle CONCAT.
7571 Assume only bitpos == 0 can be used for CONCAT, due to
7572 one element arrays having the same mode as its element. */
7573 if (GET_CODE (op0) == CONCAT)
7575 gcc_assert (bitpos == 0
7576 && bitsize == GET_MODE_BITSIZE (GET_MODE (op0)));
7577 return op0;
7580 /* In cases where an aligned union has an unaligned object
7581 as a field, we might be extracting a BLKmode value from
7582 an integer-mode (e.g., SImode) object. Handle this case
7583 by doing the extract into an object as wide as the field
7584 (which we know to be the width of a basic mode), then
7585 storing into memory, and changing the mode to BLKmode. */
7586 if (mode1 == VOIDmode
7587 || REG_P (op0) || GET_CODE (op0) == SUBREG
7588 || (mode1 != BLKmode && ! direct_load[(int) mode1]
7589 && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
7590 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT
7591 && modifier != EXPAND_CONST_ADDRESS
7592 && modifier != EXPAND_INITIALIZER)
7593 /* If the field isn't aligned enough to fetch as a memref,
7594 fetch it as a bit field. */
7595 || (mode1 != BLKmode
7596 && (((TYPE_ALIGN (TREE_TYPE (tem)) < GET_MODE_ALIGNMENT (mode)
7597 || (bitpos % GET_MODE_ALIGNMENT (mode) != 0)
7598 || (MEM_P (op0)
7599 && (MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode1)
7600 || (bitpos % GET_MODE_ALIGNMENT (mode1) != 0))))
7601 && ((modifier == EXPAND_CONST_ADDRESS
7602 || modifier == EXPAND_INITIALIZER)
7603 ? STRICT_ALIGNMENT
7604 : SLOW_UNALIGNED_ACCESS (mode1, MEM_ALIGN (op0))))
7605 || (bitpos % BITS_PER_UNIT != 0)))
7606 /* If the type and the field are a constant size and the
7607 size of the type isn't the same size as the bitfield,
7608 we must use bitfield operations. */
7609 || (bitsize >= 0
7610 && TYPE_SIZE (TREE_TYPE (exp))
7611 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) == INTEGER_CST
7612 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)),
7613 bitsize)))
7615 enum machine_mode ext_mode = mode;
7617 if (ext_mode == BLKmode
7618 && ! (target != 0 && MEM_P (op0)
7619 && MEM_P (target)
7620 && bitpos % BITS_PER_UNIT == 0))
7621 ext_mode = mode_for_size (bitsize, MODE_INT, 1);
7623 if (ext_mode == BLKmode)
7625 if (target == 0)
7626 target = assign_temp (type, 0, 1, 1);
7628 if (bitsize == 0)
7629 return target;
7631 /* In this case, BITPOS must start at a byte boundary and
7632 TARGET, if specified, must be a MEM. */
7633 gcc_assert (MEM_P (op0)
7634 && (!target || MEM_P (target))
7635 && !(bitpos % BITS_PER_UNIT));
7637 emit_block_move (target,
7638 adjust_address (op0, VOIDmode,
7639 bitpos / BITS_PER_UNIT),
7640 GEN_INT ((bitsize + BITS_PER_UNIT - 1)
7641 / BITS_PER_UNIT),
7642 (modifier == EXPAND_STACK_PARM
7643 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
7645 return target;
7648 op0 = validize_mem (op0);
7650 if (MEM_P (op0) && REG_P (XEXP (op0, 0)))
7651 mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
7653 op0 = extract_bit_field (op0, bitsize, bitpos, unsignedp,
7654 (modifier == EXPAND_STACK_PARM
7655 ? NULL_RTX : target),
7656 ext_mode, ext_mode);
7658 /* If the result is a record type and BITSIZE is narrower than
7659 the mode of OP0, an integral mode, and this is a big endian
7660 machine, we must put the field into the high-order bits. */
7661 if (TREE_CODE (type) == RECORD_TYPE && BYTES_BIG_ENDIAN
7662 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
7663 && bitsize < (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (op0)))
7664 op0 = expand_shift (LSHIFT_EXPR, GET_MODE (op0), op0,
7665 size_int (GET_MODE_BITSIZE (GET_MODE (op0))
7666 - bitsize),
7667 op0, 1);
7669 /* If the result type is BLKmode, store the data into a temporary
7670 of the appropriate type, but with the mode corresponding to the
7671 mode for the data we have (op0's mode). It's tempting to make
7672 this a constant type, since we know it's only being stored once,
7673 but that can cause problems if we are taking the address of this
7674 COMPONENT_REF because the MEM of any reference via that address
7675 will have flags corresponding to the type, which will not
7676 necessarily be constant. */
7677 if (mode == BLKmode)
7679 rtx new
7680 = assign_stack_temp_for_type
7681 (ext_mode, GET_MODE_BITSIZE (ext_mode), 0, type);
7683 emit_move_insn (new, op0);
7684 op0 = copy_rtx (new);
7685 PUT_MODE (op0, BLKmode);
7686 set_mem_attributes (op0, exp, 1);
7689 return op0;
7692 /* If the result is BLKmode, use that to access the object
7693 now as well. */
7694 if (mode == BLKmode)
7695 mode1 = BLKmode;
7697 /* Get a reference to just this component. */
7698 if (modifier == EXPAND_CONST_ADDRESS
7699 || modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
7700 op0 = adjust_address_nv (op0, mode1, bitpos / BITS_PER_UNIT);
7701 else
7702 op0 = adjust_address (op0, mode1, bitpos / BITS_PER_UNIT);
7704 if (op0 == orig_op0)
7705 op0 = copy_rtx (op0);
7707 set_mem_attributes (op0, exp, 0);
7708 if (REG_P (XEXP (op0, 0)))
7709 mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
7711 MEM_VOLATILE_P (op0) |= volatilep;
7712 if (mode == mode1 || mode1 == BLKmode || mode1 == tmode
7713 || modifier == EXPAND_CONST_ADDRESS
7714 || modifier == EXPAND_INITIALIZER)
7715 return op0;
7716 else if (target == 0)
7717 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
7719 convert_move (target, op0, unsignedp);
7720 return target;
7723 case OBJ_TYPE_REF:
7724 return expand_expr (OBJ_TYPE_REF_EXPR (exp), target, tmode, modifier);
7726 case CALL_EXPR:
7727 /* Check for a built-in function. */
7728 if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
7729 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
7730 == FUNCTION_DECL)
7731 && DECL_BUILT_IN (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
7733 if (DECL_BUILT_IN_CLASS (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
7734 == BUILT_IN_FRONTEND)
7735 return lang_hooks.expand_expr (exp, original_target,
7736 tmode, modifier,
7737 alt_rtl);
7738 else
7739 return expand_builtin (exp, target, subtarget, tmode, ignore);
7742 return expand_call (exp, target, ignore);
7744 case NON_LVALUE_EXPR:
7745 case NOP_EXPR:
7746 case CONVERT_EXPR:
7747 if (TREE_OPERAND (exp, 0) == error_mark_node)
7748 return const0_rtx;
7750 if (TREE_CODE (type) == UNION_TYPE)
7752 tree valtype = TREE_TYPE (TREE_OPERAND (exp, 0));
7754 /* If both input and output are BLKmode, this conversion isn't doing
7755 anything except possibly changing memory attribute. */
7756 if (mode == BLKmode && TYPE_MODE (valtype) == BLKmode)
7758 rtx result = expand_expr (TREE_OPERAND (exp, 0), target, tmode,
7759 modifier);
7761 result = copy_rtx (result);
7762 set_mem_attributes (result, exp, 0);
7763 return result;
7766 if (target == 0)
7768 if (TYPE_MODE (type) != BLKmode)
7769 target = gen_reg_rtx (TYPE_MODE (type));
7770 else
7771 target = assign_temp (type, 0, 1, 1);
7774 if (MEM_P (target))
7775 /* Store data into beginning of memory target. */
7776 store_expr (TREE_OPERAND (exp, 0),
7777 adjust_address (target, TYPE_MODE (valtype), 0),
7778 modifier == EXPAND_STACK_PARM);
7780 else
7782 gcc_assert (REG_P (target));
7784 /* Store this field into a union of the proper type. */
7785 store_field (target,
7786 MIN ((int_size_in_bytes (TREE_TYPE
7787 (TREE_OPERAND (exp, 0)))
7788 * BITS_PER_UNIT),
7789 (HOST_WIDE_INT) GET_MODE_BITSIZE (mode)),
7790 0, TYPE_MODE (valtype), TREE_OPERAND (exp, 0),
7791 type, 0);
7794 /* Return the entire union. */
7795 return target;
7798 if (mode == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))))
7800 op0 = expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode,
7801 modifier);
7803 /* If the signedness of the conversion differs and OP0 is
7804 a promoted SUBREG, clear that indication since we now
7805 have to do the proper extension. */
7806 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))) != unsignedp
7807 && GET_CODE (op0) == SUBREG)
7808 SUBREG_PROMOTED_VAR_P (op0) = 0;
7810 return REDUCE_BIT_FIELD (op0);
7813 op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, mode,
7814 modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier);
7815 if (GET_MODE (op0) == mode)
7818 /* If OP0 is a constant, just convert it into the proper mode. */
7819 else if (CONSTANT_P (op0))
7821 tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
7822 enum machine_mode inner_mode = TYPE_MODE (inner_type);
7824 if (modifier == EXPAND_INITIALIZER)
7825 op0 = simplify_gen_subreg (mode, op0, inner_mode,
7826 subreg_lowpart_offset (mode,
7827 inner_mode));
7828 else
7829 op0= convert_modes (mode, inner_mode, op0,
7830 TYPE_UNSIGNED (inner_type));
7833 else if (modifier == EXPAND_INITIALIZER)
7834 op0 = gen_rtx_fmt_e (unsignedp ? ZERO_EXTEND : SIGN_EXTEND, mode, op0);
7836 else if (target == 0)
7837 op0 = convert_to_mode (mode, op0,
7838 TYPE_UNSIGNED (TREE_TYPE
7839 (TREE_OPERAND (exp, 0))));
7840 else
7842 convert_move (target, op0,
7843 TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
7844 op0 = target;
7847 return REDUCE_BIT_FIELD (op0);
7849 case VIEW_CONVERT_EXPR:
7850 op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, mode, modifier);
7852 /* If the input and output modes are both the same, we are done. */
7853 if (TYPE_MODE (type) == GET_MODE (op0))
7855 /* If neither mode is BLKmode, and both modes are the same size
7856 then we can use gen_lowpart. */
7857 else if (TYPE_MODE (type) != BLKmode && GET_MODE (op0) != BLKmode
7858 && GET_MODE_SIZE (TYPE_MODE (type))
7859 == GET_MODE_SIZE (GET_MODE (op0)))
7861 if (GET_CODE (op0) == SUBREG)
7862 op0 = force_reg (GET_MODE (op0), op0);
7863 op0 = gen_lowpart (TYPE_MODE (type), op0);
7865 /* If both modes are integral, then we can convert from one to the
7866 other. */
7867 else if (SCALAR_INT_MODE_P (GET_MODE (op0))
7868 && SCALAR_INT_MODE_P (TYPE_MODE (type)))
7869 op0 = convert_modes (TYPE_MODE (type), GET_MODE (op0), op0,
7870 TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
7871 /* As a last resort, spill op0 to memory, and reload it in a
7872 different mode. */
7873 else if (!MEM_P (op0))
7875 /* If the operand is not a MEM, force it into memory. Since we
7876 are going to be changing the mode of the MEM, don't call
7877 force_const_mem for constants because we don't allow pool
7878 constants to change mode. */
7879 tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
7881 gcc_assert (!TREE_ADDRESSABLE (exp));
7883 if (target == 0 || GET_MODE (target) != TYPE_MODE (inner_type))
7884 target
7885 = assign_stack_temp_for_type
7886 (TYPE_MODE (inner_type),
7887 GET_MODE_SIZE (TYPE_MODE (inner_type)), 0, inner_type);
7889 emit_move_insn (target, op0);
7890 op0 = target;
7893 /* At this point, OP0 is in the correct mode. If the output type is such
7894 that the operand is known to be aligned, indicate that it is.
7895 Otherwise, we need only be concerned about alignment for non-BLKmode
7896 results. */
7897 if (MEM_P (op0))
7899 op0 = copy_rtx (op0);
7901 if (TYPE_ALIGN_OK (type))
7902 set_mem_align (op0, MAX (MEM_ALIGN (op0), TYPE_ALIGN (type)));
7903 else if (TYPE_MODE (type) != BLKmode && STRICT_ALIGNMENT
7904 && MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (TYPE_MODE (type)))
7906 tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
7907 HOST_WIDE_INT temp_size
7908 = MAX (int_size_in_bytes (inner_type),
7909 (HOST_WIDE_INT) GET_MODE_SIZE (TYPE_MODE (type)));
7910 rtx new = assign_stack_temp_for_type (TYPE_MODE (type),
7911 temp_size, 0, type);
7912 rtx new_with_op0_mode = adjust_address (new, GET_MODE (op0), 0);
7914 gcc_assert (!TREE_ADDRESSABLE (exp));
7916 if (GET_MODE (op0) == BLKmode)
7917 emit_block_move (new_with_op0_mode, op0,
7918 GEN_INT (GET_MODE_SIZE (TYPE_MODE (type))),
7919 (modifier == EXPAND_STACK_PARM
7920 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
7921 else
7922 emit_move_insn (new_with_op0_mode, op0);
7924 op0 = new;
7927 op0 = adjust_address (op0, TYPE_MODE (type), 0);
7930 return op0;
7932 case PLUS_EXPR:
7933 /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
7934 something else, make sure we add the register to the constant and
7935 then to the other thing. This case can occur during strength
7936 reduction and doing it this way will produce better code if the
7937 frame pointer or argument pointer is eliminated.
7939 fold-const.c will ensure that the constant is always in the inner
7940 PLUS_EXPR, so the only case we need to do anything about is if
7941 sp, ap, or fp is our second argument, in which case we must swap
7942 the innermost first argument and our second argument. */
7944 if (TREE_CODE (TREE_OPERAND (exp, 0)) == PLUS_EXPR
7945 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 1)) == INTEGER_CST
7946 && TREE_CODE (TREE_OPERAND (exp, 1)) == VAR_DECL
7947 && (DECL_RTL (TREE_OPERAND (exp, 1)) == frame_pointer_rtx
7948 || DECL_RTL (TREE_OPERAND (exp, 1)) == stack_pointer_rtx
7949 || DECL_RTL (TREE_OPERAND (exp, 1)) == arg_pointer_rtx))
7951 tree t = TREE_OPERAND (exp, 1);
7953 TREE_OPERAND (exp, 1) = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
7954 TREE_OPERAND (TREE_OPERAND (exp, 0), 0) = t;
7957 /* If the result is to be ptr_mode and we are adding an integer to
7958 something, we might be forming a constant. So try to use
7959 plus_constant. If it produces a sum and we can't accept it,
7960 use force_operand. This allows P = &ARR[const] to generate
7961 efficient code on machines where a SYMBOL_REF is not a valid
7962 address.
7964 If this is an EXPAND_SUM call, always return the sum. */
7965 if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER
7966 || (mode == ptr_mode && (unsignedp || ! flag_trapv)))
7968 if (modifier == EXPAND_STACK_PARM)
7969 target = 0;
7970 if (TREE_CODE (TREE_OPERAND (exp, 0)) == INTEGER_CST
7971 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
7972 && TREE_CONSTANT (TREE_OPERAND (exp, 1)))
7974 rtx constant_part;
7976 op1 = expand_expr (TREE_OPERAND (exp, 1), subtarget, VOIDmode,
7977 EXPAND_SUM);
7978 /* Use immed_double_const to ensure that the constant is
7979 truncated according to the mode of OP1, then sign extended
7980 to a HOST_WIDE_INT. Using the constant directly can result
7981 in non-canonical RTL in a 64x32 cross compile. */
7982 constant_part
7983 = immed_double_const (TREE_INT_CST_LOW (TREE_OPERAND (exp, 0)),
7984 (HOST_WIDE_INT) 0,
7985 TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 1))));
7986 op1 = plus_constant (op1, INTVAL (constant_part));
7987 if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
7988 op1 = force_operand (op1, target);
7989 return REDUCE_BIT_FIELD (op1);
7992 else if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
7993 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
7994 && TREE_CONSTANT (TREE_OPERAND (exp, 0)))
7996 rtx constant_part;
7998 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode,
7999 (modifier == EXPAND_INITIALIZER
8000 ? EXPAND_INITIALIZER : EXPAND_SUM));
8001 if (! CONSTANT_P (op0))
8003 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX,
8004 VOIDmode, modifier);
8005 /* Return a PLUS if modifier says it's OK. */
8006 if (modifier == EXPAND_SUM
8007 || modifier == EXPAND_INITIALIZER)
8008 return simplify_gen_binary (PLUS, mode, op0, op1);
8009 goto binop2;
8011 /* Use immed_double_const to ensure that the constant is
8012 truncated according to the mode of OP1, then sign extended
8013 to a HOST_WIDE_INT. Using the constant directly can result
8014 in non-canonical RTL in a 64x32 cross compile. */
8015 constant_part
8016 = immed_double_const (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1)),
8017 (HOST_WIDE_INT) 0,
8018 TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))));
8019 op0 = plus_constant (op0, INTVAL (constant_part));
8020 if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8021 op0 = force_operand (op0, target);
8022 return REDUCE_BIT_FIELD (op0);
8026 /* No sense saving up arithmetic to be done
8027 if it's all in the wrong mode to form part of an address.
8028 And force_operand won't know whether to sign-extend or
8029 zero-extend. */
8030 if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8031 || mode != ptr_mode)
8033 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8034 subtarget, &op0, &op1, 0);
8035 if (op0 == const0_rtx)
8036 return op1;
8037 if (op1 == const0_rtx)
8038 return op0;
8039 goto binop2;
8042 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8043 subtarget, &op0, &op1, modifier);
8044 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
8046 case MINUS_EXPR:
8047 /* For initializers, we are allowed to return a MINUS of two
8048 symbolic constants. Here we handle all cases when both operands
8049 are constant. */
8050 /* Handle difference of two symbolic constants,
8051 for the sake of an initializer. */
8052 if ((modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
8053 && really_constant_p (TREE_OPERAND (exp, 0))
8054 && really_constant_p (TREE_OPERAND (exp, 1)))
8056 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8057 NULL_RTX, &op0, &op1, modifier);
8059 /* If the last operand is a CONST_INT, use plus_constant of
8060 the negated constant. Else make the MINUS. */
8061 if (GET_CODE (op1) == CONST_INT)
8062 return REDUCE_BIT_FIELD (plus_constant (op0, - INTVAL (op1)));
8063 else
8064 return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode, op0, op1));
8067 /* No sense saving up arithmetic to be done
8068 if it's all in the wrong mode to form part of an address.
8069 And force_operand won't know whether to sign-extend or
8070 zero-extend. */
8071 if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8072 || mode != ptr_mode)
8073 goto binop;
8075 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8076 subtarget, &op0, &op1, modifier);
8078 /* Convert A - const to A + (-const). */
8079 if (GET_CODE (op1) == CONST_INT)
8081 op1 = negate_rtx (mode, op1);
8082 return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
8085 goto binop2;
8087 case MULT_EXPR:
8088 /* If first operand is constant, swap them.
8089 Thus the following special case checks need only
8090 check the second operand. */
8091 if (TREE_CODE (TREE_OPERAND (exp, 0)) == INTEGER_CST)
8093 tree t1 = TREE_OPERAND (exp, 0);
8094 TREE_OPERAND (exp, 0) = TREE_OPERAND (exp, 1);
8095 TREE_OPERAND (exp, 1) = t1;
8098 /* Attempt to return something suitable for generating an
8099 indexed address, for machines that support that. */
8101 if (modifier == EXPAND_SUM && mode == ptr_mode
8102 && host_integerp (TREE_OPERAND (exp, 1), 0))
8104 tree exp1 = TREE_OPERAND (exp, 1);
8106 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode,
8107 EXPAND_SUM);
8109 if (!REG_P (op0))
8110 op0 = force_operand (op0, NULL_RTX);
8111 if (!REG_P (op0))
8112 op0 = copy_to_mode_reg (mode, op0);
8114 return REDUCE_BIT_FIELD (gen_rtx_MULT (mode, op0,
8115 gen_int_mode (tree_low_cst (exp1, 0),
8116 TYPE_MODE (TREE_TYPE (exp1)))));
8119 if (modifier == EXPAND_STACK_PARM)
8120 target = 0;
8122 /* Check for multiplying things that have been extended
8123 from a narrower type. If this machine supports multiplying
8124 in that narrower type with a result in the desired type,
8125 do it that way, and avoid the explicit type-conversion. */
8127 subexp0 = TREE_OPERAND (exp, 0);
8128 subexp1 = TREE_OPERAND (exp, 1);
8129 /* First, check if we have a multiplication of one signed and one
8130 unsigned operand. */
8131 if (TREE_CODE (subexp0) == NOP_EXPR
8132 && TREE_CODE (subexp1) == NOP_EXPR
8133 && TREE_CODE (type) == INTEGER_TYPE
8134 && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (subexp0, 0)))
8135 < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp, 0))))
8136 && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (subexp0, 0)))
8137 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (subexp1, 0))))
8138 && (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (subexp0, 0)))
8139 != TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (subexp1, 0)))))
8141 enum machine_mode innermode
8142 = TYPE_MODE (TREE_TYPE (TREE_OPERAND (subexp0, 0)));
8143 this_optab = usmul_widen_optab;
8144 if (mode == GET_MODE_WIDER_MODE (innermode))
8146 if (this_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
8148 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (subexp0, 0))))
8149 expand_operands (TREE_OPERAND (subexp0, 0),
8150 TREE_OPERAND (subexp1, 0),
8151 NULL_RTX, &op0, &op1, 0);
8152 else
8153 expand_operands (TREE_OPERAND (subexp0, 0),
8154 TREE_OPERAND (subexp1, 0),
8155 NULL_RTX, &op1, &op0, 0);
8157 goto binop3;
8161 /* Check for a multiplication with matching signedness. */
8162 else if (TREE_CODE (TREE_OPERAND (exp, 0)) == NOP_EXPR
8163 && TREE_CODE (type) == INTEGER_TYPE
8164 && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
8165 < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp, 0))))
8166 && ((TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
8167 && int_fits_type_p (TREE_OPERAND (exp, 1),
8168 TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
8169 /* Don't use a widening multiply if a shift will do. */
8170 && ((GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 1))))
8171 > HOST_BITS_PER_WIDE_INT)
8172 || exact_log2 (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1))) < 0))
8174 (TREE_CODE (TREE_OPERAND (exp, 1)) == NOP_EXPR
8175 && (TYPE_PRECISION (TREE_TYPE
8176 (TREE_OPERAND (TREE_OPERAND (exp, 1), 0)))
8177 == TYPE_PRECISION (TREE_TYPE
8178 (TREE_OPERAND
8179 (TREE_OPERAND (exp, 0), 0))))
8180 /* If both operands are extended, they must either both
8181 be zero-extended or both be sign-extended. */
8182 && (TYPE_UNSIGNED (TREE_TYPE
8183 (TREE_OPERAND (TREE_OPERAND (exp, 1), 0)))
8184 == TYPE_UNSIGNED (TREE_TYPE
8185 (TREE_OPERAND
8186 (TREE_OPERAND (exp, 0), 0)))))))
8188 tree op0type = TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0));
8189 enum machine_mode innermode = TYPE_MODE (op0type);
8190 bool zextend_p = TYPE_UNSIGNED (op0type);
8191 optab other_optab = zextend_p ? smul_widen_optab : umul_widen_optab;
8192 this_optab = zextend_p ? umul_widen_optab : smul_widen_optab;
8194 if (mode == GET_MODE_2XWIDER_MODE (innermode))
8196 if (this_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
8198 if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST)
8199 expand_operands (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
8200 TREE_OPERAND (exp, 1),
8201 NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8202 else
8203 expand_operands (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
8204 TREE_OPERAND (TREE_OPERAND (exp, 1), 0),
8205 NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8206 goto binop3;
8208 else if (other_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing
8209 && innermode == word_mode)
8211 rtx htem, hipart;
8212 op0 = expand_normal (TREE_OPERAND (TREE_OPERAND (exp, 0), 0));
8213 if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST)
8214 op1 = convert_modes (innermode, mode,
8215 expand_normal (TREE_OPERAND (exp, 1)),
8216 unsignedp);
8217 else
8218 op1 = expand_normal (TREE_OPERAND (TREE_OPERAND (exp, 1), 0));
8219 temp = expand_binop (mode, other_optab, op0, op1, target,
8220 unsignedp, OPTAB_LIB_WIDEN);
8221 hipart = gen_highpart (innermode, temp);
8222 htem = expand_mult_highpart_adjust (innermode, hipart,
8223 op0, op1, hipart,
8224 zextend_p);
8225 if (htem != hipart)
8226 emit_move_insn (hipart, htem);
8227 return REDUCE_BIT_FIELD (temp);
8231 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8232 subtarget, &op0, &op1, 0);
8233 return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
8235 case TRUNC_DIV_EXPR:
8236 case FLOOR_DIV_EXPR:
8237 case CEIL_DIV_EXPR:
8238 case ROUND_DIV_EXPR:
8239 case EXACT_DIV_EXPR:
8240 if (modifier == EXPAND_STACK_PARM)
8241 target = 0;
8242 /* Possible optimization: compute the dividend with EXPAND_SUM
8243 then if the divisor is constant can optimize the case
8244 where some terms of the dividend have coeffs divisible by it. */
8245 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8246 subtarget, &op0, &op1, 0);
8247 return expand_divmod (0, code, mode, op0, op1, target, unsignedp);
8249 case RDIV_EXPR:
8250 goto binop;
8252 case TRUNC_MOD_EXPR:
8253 case FLOOR_MOD_EXPR:
8254 case CEIL_MOD_EXPR:
8255 case ROUND_MOD_EXPR:
8256 if (modifier == EXPAND_STACK_PARM)
8257 target = 0;
8258 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8259 subtarget, &op0, &op1, 0);
8260 return expand_divmod (1, code, mode, op0, op1, target, unsignedp);
8262 case FIX_TRUNC_EXPR:
8263 op0 = expand_normal (TREE_OPERAND (exp, 0));
8264 if (target == 0 || modifier == EXPAND_STACK_PARM)
8265 target = gen_reg_rtx (mode);
8266 expand_fix (target, op0, unsignedp);
8267 return target;
8269 case FLOAT_EXPR:
8270 op0 = expand_normal (TREE_OPERAND (exp, 0));
8271 if (target == 0 || modifier == EXPAND_STACK_PARM)
8272 target = gen_reg_rtx (mode);
8273 /* expand_float can't figure out what to do if FROM has VOIDmode.
8274 So give it the correct mode. With -O, cse will optimize this. */
8275 if (GET_MODE (op0) == VOIDmode)
8276 op0 = copy_to_mode_reg (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))),
8277 op0);
8278 expand_float (target, op0,
8279 TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
8280 return target;
8282 case NEGATE_EXPR:
8283 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
8284 if (modifier == EXPAND_STACK_PARM)
8285 target = 0;
8286 temp = expand_unop (mode,
8287 optab_for_tree_code (NEGATE_EXPR, type),
8288 op0, target, 0);
8289 gcc_assert (temp);
8290 return REDUCE_BIT_FIELD (temp);
8292 case ABS_EXPR:
8293 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
8294 if (modifier == EXPAND_STACK_PARM)
8295 target = 0;
8297 /* ABS_EXPR is not valid for complex arguments. */
8298 gcc_assert (GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
8299 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT);
8301 /* Unsigned abs is simply the operand. Testing here means we don't
8302 risk generating incorrect code below. */
8303 if (TYPE_UNSIGNED (type))
8304 return op0;
8306 return expand_abs (mode, op0, target, unsignedp,
8307 safe_from_p (target, TREE_OPERAND (exp, 0), 1));
8309 case MAX_EXPR:
8310 case MIN_EXPR:
8311 target = original_target;
8312 if (target == 0
8313 || modifier == EXPAND_STACK_PARM
8314 || (MEM_P (target) && MEM_VOLATILE_P (target))
8315 || GET_MODE (target) != mode
8316 || (REG_P (target)
8317 && REGNO (target) < FIRST_PSEUDO_REGISTER))
8318 target = gen_reg_rtx (mode);
8319 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8320 target, &op0, &op1, 0);
8322 /* First try to do it with a special MIN or MAX instruction.
8323 If that does not win, use a conditional jump to select the proper
8324 value. */
8325 this_optab = optab_for_tree_code (code, type);
8326 temp = expand_binop (mode, this_optab, op0, op1, target, unsignedp,
8327 OPTAB_WIDEN);
8328 if (temp != 0)
8329 return temp;
8331 /* At this point, a MEM target is no longer useful; we will get better
8332 code without it. */
8334 if (! REG_P (target))
8335 target = gen_reg_rtx (mode);
8337 /* If op1 was placed in target, swap op0 and op1. */
8338 if (target != op0 && target == op1)
8340 temp = op0;
8341 op0 = op1;
8342 op1 = temp;
8345 /* We generate better code and avoid problems with op1 mentioning
8346 target by forcing op1 into a pseudo if it isn't a constant. */
8347 if (! CONSTANT_P (op1))
8348 op1 = force_reg (mode, op1);
8351 enum rtx_code comparison_code;
8352 rtx cmpop1 = op1;
8354 if (code == MAX_EXPR)
8355 comparison_code = unsignedp ? GEU : GE;
8356 else
8357 comparison_code = unsignedp ? LEU : LE;
8359 /* Canonicalize to comparisons against 0. */
8360 if (op1 == const1_rtx)
8362 /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
8363 or (a != 0 ? a : 1) for unsigned.
8364 For MIN we are safe converting (a <= 1 ? a : 1)
8365 into (a <= 0 ? a : 1) */
8366 cmpop1 = const0_rtx;
8367 if (code == MAX_EXPR)
8368 comparison_code = unsignedp ? NE : GT;
8370 if (op1 == constm1_rtx && !unsignedp)
8372 /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
8373 and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
8374 cmpop1 = const0_rtx;
8375 if (code == MIN_EXPR)
8376 comparison_code = LT;
8378 #ifdef HAVE_conditional_move
8379 /* Use a conditional move if possible. */
8380 if (can_conditionally_move_p (mode))
8382 rtx insn;
8384 /* ??? Same problem as in expmed.c: emit_conditional_move
8385 forces a stack adjustment via compare_from_rtx, and we
8386 lose the stack adjustment if the sequence we are about
8387 to create is discarded. */
8388 do_pending_stack_adjust ();
8390 start_sequence ();
8392 /* Try to emit the conditional move. */
8393 insn = emit_conditional_move (target, comparison_code,
8394 op0, cmpop1, mode,
8395 op0, op1, mode,
8396 unsignedp);
8398 /* If we could do the conditional move, emit the sequence,
8399 and return. */
8400 if (insn)
8402 rtx seq = get_insns ();
8403 end_sequence ();
8404 emit_insn (seq);
8405 return target;
8408 /* Otherwise discard the sequence and fall back to code with
8409 branches. */
8410 end_sequence ();
8412 #endif
8413 if (target != op0)
8414 emit_move_insn (target, op0);
8416 temp = gen_label_rtx ();
8417 do_compare_rtx_and_jump (target, cmpop1, comparison_code,
8418 unsignedp, mode, NULL_RTX, NULL_RTX, temp);
8420 emit_move_insn (target, op1);
8421 emit_label (temp);
8422 return target;
8424 case BIT_NOT_EXPR:
8425 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
8426 if (modifier == EXPAND_STACK_PARM)
8427 target = 0;
8428 temp = expand_unop (mode, one_cmpl_optab, op0, target, 1);
8429 gcc_assert (temp);
8430 return temp;
8432 /* ??? Can optimize bitwise operations with one arg constant.
8433 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8434 and (a bitwise1 b) bitwise2 b (etc)
8435 but that is probably not worth while. */
8437 /* BIT_AND_EXPR is for bitwise anding. TRUTH_AND_EXPR is for anding two
8438 boolean values when we want in all cases to compute both of them. In
8439 general it is fastest to do TRUTH_AND_EXPR by computing both operands
8440 as actual zero-or-1 values and then bitwise anding. In cases where
8441 there cannot be any side effects, better code would be made by
8442 treating TRUTH_AND_EXPR like TRUTH_ANDIF_EXPR; but the question is
8443 how to recognize those cases. */
8445 case TRUTH_AND_EXPR:
8446 code = BIT_AND_EXPR;
8447 case BIT_AND_EXPR:
8448 goto binop;
8450 case TRUTH_OR_EXPR:
8451 code = BIT_IOR_EXPR;
8452 case BIT_IOR_EXPR:
8453 goto binop;
8455 case TRUTH_XOR_EXPR:
8456 code = BIT_XOR_EXPR;
8457 case BIT_XOR_EXPR:
8458 goto binop;
8460 case LSHIFT_EXPR:
8461 case RSHIFT_EXPR:
8462 case LROTATE_EXPR:
8463 case RROTATE_EXPR:
8464 if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1), 1))
8465 subtarget = 0;
8466 if (modifier == EXPAND_STACK_PARM)
8467 target = 0;
8468 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
8469 return expand_shift (code, mode, op0, TREE_OPERAND (exp, 1), target,
8470 unsignedp);
8472 /* Could determine the answer when only additive constants differ. Also,
8473 the addition of one can be handled by changing the condition. */
8474 case LT_EXPR:
8475 case LE_EXPR:
8476 case GT_EXPR:
8477 case GE_EXPR:
8478 case EQ_EXPR:
8479 case NE_EXPR:
8480 case UNORDERED_EXPR:
8481 case ORDERED_EXPR:
8482 case UNLT_EXPR:
8483 case UNLE_EXPR:
8484 case UNGT_EXPR:
8485 case UNGE_EXPR:
8486 case UNEQ_EXPR:
8487 case LTGT_EXPR:
8488 temp = do_store_flag (exp,
8489 modifier != EXPAND_STACK_PARM ? target : NULL_RTX,
8490 tmode != VOIDmode ? tmode : mode, 0);
8491 if (temp != 0)
8492 return temp;
8494 /* For foo != 0, load foo, and if it is nonzero load 1 instead. */
8495 if (code == NE_EXPR && integer_zerop (TREE_OPERAND (exp, 1))
8496 && original_target
8497 && REG_P (original_target)
8498 && (GET_MODE (original_target)
8499 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)))))
8501 temp = expand_expr (TREE_OPERAND (exp, 0), original_target,
8502 VOIDmode, 0);
8504 /* If temp is constant, we can just compute the result. */
8505 if (GET_CODE (temp) == CONST_INT)
8507 if (INTVAL (temp) != 0)
8508 emit_move_insn (target, const1_rtx);
8509 else
8510 emit_move_insn (target, const0_rtx);
8512 return target;
8515 if (temp != original_target)
8517 enum machine_mode mode1 = GET_MODE (temp);
8518 if (mode1 == VOIDmode)
8519 mode1 = tmode != VOIDmode ? tmode : mode;
8521 temp = copy_to_mode_reg (mode1, temp);
8524 op1 = gen_label_rtx ();
8525 emit_cmp_and_jump_insns (temp, const0_rtx, EQ, NULL_RTX,
8526 GET_MODE (temp), unsignedp, op1);
8527 emit_move_insn (temp, const1_rtx);
8528 emit_label (op1);
8529 return temp;
8532 /* If no set-flag instruction, must generate a conditional store
8533 into a temporary variable. Drop through and handle this
8534 like && and ||. */
8536 if (! ignore
8537 && (target == 0
8538 || modifier == EXPAND_STACK_PARM
8539 || ! safe_from_p (target, exp, 1)
8540 /* Make sure we don't have a hard reg (such as function's return
8541 value) live across basic blocks, if not optimizing. */
8542 || (!optimize && REG_P (target)
8543 && REGNO (target) < FIRST_PSEUDO_REGISTER)))
8544 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
8546 if (target)
8547 emit_move_insn (target, const0_rtx);
8549 op1 = gen_label_rtx ();
8550 jumpifnot (exp, op1);
8552 if (target)
8553 emit_move_insn (target, const1_rtx);
8555 emit_label (op1);
8556 return ignore ? const0_rtx : target;
8558 case TRUTH_NOT_EXPR:
8559 if (modifier == EXPAND_STACK_PARM)
8560 target = 0;
8561 op0 = expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode, 0);
8562 /* The parser is careful to generate TRUTH_NOT_EXPR
8563 only with operands that are always zero or one. */
8564 temp = expand_binop (mode, xor_optab, op0, const1_rtx,
8565 target, 1, OPTAB_LIB_WIDEN);
8566 gcc_assert (temp);
8567 return temp;
8569 case STATEMENT_LIST:
8571 tree_stmt_iterator iter;
8573 gcc_assert (ignore);
8575 for (iter = tsi_start (exp); !tsi_end_p (iter); tsi_next (&iter))
8576 expand_expr (tsi_stmt (iter), const0_rtx, VOIDmode, modifier);
8578 return const0_rtx;
8580 case COND_EXPR:
8581 /* A COND_EXPR with its type being VOID_TYPE represents a
8582 conditional jump and is handled in
8583 expand_gimple_cond_expr. */
8584 gcc_assert (!VOID_TYPE_P (TREE_TYPE (exp)));
8586 /* Note that COND_EXPRs whose type is a structure or union
8587 are required to be constructed to contain assignments of
8588 a temporary variable, so that we can evaluate them here
8589 for side effect only. If type is void, we must do likewise. */
8591 gcc_assert (!TREE_ADDRESSABLE (type)
8592 && !ignore
8593 && TREE_TYPE (TREE_OPERAND (exp, 1)) != void_type_node
8594 && TREE_TYPE (TREE_OPERAND (exp, 2)) != void_type_node);
8596 /* If we are not to produce a result, we have no target. Otherwise,
8597 if a target was specified use it; it will not be used as an
8598 intermediate target unless it is safe. If no target, use a
8599 temporary. */
8601 if (modifier != EXPAND_STACK_PARM
8602 && original_target
8603 && safe_from_p (original_target, TREE_OPERAND (exp, 0), 1)
8604 && GET_MODE (original_target) == mode
8605 #ifdef HAVE_conditional_move
8606 && (! can_conditionally_move_p (mode)
8607 || REG_P (original_target))
8608 #endif
8609 && !MEM_P (original_target))
8610 temp = original_target;
8611 else
8612 temp = assign_temp (type, 0, 0, 1);
8614 do_pending_stack_adjust ();
8615 NO_DEFER_POP;
8616 op0 = gen_label_rtx ();
8617 op1 = gen_label_rtx ();
8618 jumpifnot (TREE_OPERAND (exp, 0), op0);
8619 store_expr (TREE_OPERAND (exp, 1), temp,
8620 modifier == EXPAND_STACK_PARM);
8622 emit_jump_insn (gen_jump (op1));
8623 emit_barrier ();
8624 emit_label (op0);
8625 store_expr (TREE_OPERAND (exp, 2), temp,
8626 modifier == EXPAND_STACK_PARM);
8628 emit_label (op1);
8629 OK_DEFER_POP;
8630 return temp;
8632 case VEC_COND_EXPR:
8633 target = expand_vec_cond_expr (exp, target);
8634 return target;
8636 case GIMPLE_MODIFY_STMT:
8638 tree lhs = GIMPLE_STMT_OPERAND (exp, 0);
8639 tree rhs = GIMPLE_STMT_OPERAND (exp, 1);
8641 gcc_assert (ignore);
8643 /* Check for |= or &= of a bitfield of size one into another bitfield
8644 of size 1. In this case, (unless we need the result of the
8645 assignment) we can do this more efficiently with a
8646 test followed by an assignment, if necessary.
8648 ??? At this point, we can't get a BIT_FIELD_REF here. But if
8649 things change so we do, this code should be enhanced to
8650 support it. */
8651 if (TREE_CODE (lhs) == COMPONENT_REF
8652 && (TREE_CODE (rhs) == BIT_IOR_EXPR
8653 || TREE_CODE (rhs) == BIT_AND_EXPR)
8654 && TREE_OPERAND (rhs, 0) == lhs
8655 && TREE_CODE (TREE_OPERAND (rhs, 1)) == COMPONENT_REF
8656 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs, 1)))
8657 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs, 1), 1))))
8659 rtx label = gen_label_rtx ();
8660 int value = TREE_CODE (rhs) == BIT_IOR_EXPR;
8661 do_jump (TREE_OPERAND (rhs, 1),
8662 value ? label : 0,
8663 value ? 0 : label);
8664 expand_assignment (lhs, build_int_cst (TREE_TYPE (rhs), value));
8665 do_pending_stack_adjust ();
8666 emit_label (label);
8667 return const0_rtx;
8670 expand_assignment (lhs, rhs);
8672 return const0_rtx;
8675 case RETURN_EXPR:
8676 if (!TREE_OPERAND (exp, 0))
8677 expand_null_return ();
8678 else
8679 expand_return (TREE_OPERAND (exp, 0));
8680 return const0_rtx;
8682 case ADDR_EXPR:
8683 return expand_expr_addr_expr (exp, target, tmode, modifier);
8685 case COMPLEX_EXPR:
8686 /* Get the rtx code of the operands. */
8687 op0 = expand_normal (TREE_OPERAND (exp, 0));
8688 op1 = expand_normal (TREE_OPERAND (exp, 1));
8690 if (!target)
8691 target = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
8693 /* Move the real (op0) and imaginary (op1) parts to their location. */
8694 write_complex_part (target, op0, false);
8695 write_complex_part (target, op1, true);
8697 return target;
8699 case REALPART_EXPR:
8700 op0 = expand_normal (TREE_OPERAND (exp, 0));
8701 return read_complex_part (op0, false);
8703 case IMAGPART_EXPR:
8704 op0 = expand_normal (TREE_OPERAND (exp, 0));
8705 return read_complex_part (op0, true);
8707 case RESX_EXPR:
8708 expand_resx_expr (exp);
8709 return const0_rtx;
8711 case TRY_CATCH_EXPR:
8712 case CATCH_EXPR:
8713 case EH_FILTER_EXPR:
8714 case TRY_FINALLY_EXPR:
8715 /* Lowered by tree-eh.c. */
8716 gcc_unreachable ();
8718 case WITH_CLEANUP_EXPR:
8719 case CLEANUP_POINT_EXPR:
8720 case TARGET_EXPR:
8721 case CASE_LABEL_EXPR:
8722 case VA_ARG_EXPR:
8723 case BIND_EXPR:
8724 case INIT_EXPR:
8725 case CONJ_EXPR:
8726 case COMPOUND_EXPR:
8727 case PREINCREMENT_EXPR:
8728 case PREDECREMENT_EXPR:
8729 case POSTINCREMENT_EXPR:
8730 case POSTDECREMENT_EXPR:
8731 case LOOP_EXPR:
8732 case EXIT_EXPR:
8733 case TRUTH_ANDIF_EXPR:
8734 case TRUTH_ORIF_EXPR:
8735 /* Lowered by gimplify.c. */
8736 gcc_unreachable ();
8738 case EXC_PTR_EXPR:
8739 return get_exception_pointer (cfun);
8741 case FILTER_EXPR:
8742 return get_exception_filter (cfun);
8744 case FDESC_EXPR:
8745 /* Function descriptors are not valid except for as
8746 initialization constants, and should not be expanded. */
8747 gcc_unreachable ();
8749 case SWITCH_EXPR:
8750 expand_case (exp);
8751 return const0_rtx;
8753 case LABEL_EXPR:
8754 expand_label (TREE_OPERAND (exp, 0));
8755 return const0_rtx;
8757 case ASM_EXPR:
8758 expand_asm_expr (exp);
8759 return const0_rtx;
8761 case WITH_SIZE_EXPR:
8762 /* WITH_SIZE_EXPR expands to its first argument. The caller should
8763 have pulled out the size to use in whatever context it needed. */
8764 return expand_expr_real (TREE_OPERAND (exp, 0), original_target, tmode,
8765 modifier, alt_rtl);
8767 case REALIGN_LOAD_EXPR:
8769 tree oprnd0 = TREE_OPERAND (exp, 0);
8770 tree oprnd1 = TREE_OPERAND (exp, 1);
8771 tree oprnd2 = TREE_OPERAND (exp, 2);
8772 rtx op2;
8774 this_optab = optab_for_tree_code (code, type);
8775 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8776 op2 = expand_normal (oprnd2);
8777 temp = expand_ternary_op (mode, this_optab, op0, op1, op2,
8778 target, unsignedp);
8779 gcc_assert (temp);
8780 return temp;
8783 case DOT_PROD_EXPR:
8785 tree oprnd0 = TREE_OPERAND (exp, 0);
8786 tree oprnd1 = TREE_OPERAND (exp, 1);
8787 tree oprnd2 = TREE_OPERAND (exp, 2);
8788 rtx op2;
8790 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
8791 op2 = expand_normal (oprnd2);
8792 target = expand_widen_pattern_expr (exp, op0, op1, op2,
8793 target, unsignedp);
8794 return target;
8797 case WIDEN_SUM_EXPR:
8799 tree oprnd0 = TREE_OPERAND (exp, 0);
8800 tree oprnd1 = TREE_OPERAND (exp, 1);
8802 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, 0);
8803 target = expand_widen_pattern_expr (exp, op0, NULL_RTX, op1,
8804 target, unsignedp);
8805 return target;
8808 case REDUC_MAX_EXPR:
8809 case REDUC_MIN_EXPR:
8810 case REDUC_PLUS_EXPR:
8812 op0 = expand_normal (TREE_OPERAND (exp, 0));
8813 this_optab = optab_for_tree_code (code, type);
8814 temp = expand_unop (mode, this_optab, op0, target, unsignedp);
8815 gcc_assert (temp);
8816 return temp;
8819 case VEC_EXTRACT_EVEN_EXPR:
8820 case VEC_EXTRACT_ODD_EXPR:
8822 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8823 NULL_RTX, &op0, &op1, 0);
8824 this_optab = optab_for_tree_code (code, type);
8825 temp = expand_binop (mode, this_optab, op0, op1, target, unsignedp,
8826 OPTAB_WIDEN);
8827 gcc_assert (temp);
8828 return temp;
8831 case VEC_INTERLEAVE_HIGH_EXPR:
8832 case VEC_INTERLEAVE_LOW_EXPR:
8834 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8835 NULL_RTX, &op0, &op1, 0);
8836 this_optab = optab_for_tree_code (code, type);
8837 temp = expand_binop (mode, this_optab, op0, op1, target, unsignedp,
8838 OPTAB_WIDEN);
8839 gcc_assert (temp);
8840 return temp;
8843 case VEC_LSHIFT_EXPR:
8844 case VEC_RSHIFT_EXPR:
8846 target = expand_vec_shift_expr (exp, target);
8847 return target;
8850 case VEC_UNPACK_HI_EXPR:
8851 case VEC_UNPACK_LO_EXPR:
8853 op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
8854 this_optab = optab_for_tree_code (code, type);
8855 temp = expand_widen_pattern_expr (exp, op0, NULL_RTX, NULL_RTX,
8856 target, unsignedp);
8857 gcc_assert (temp);
8858 return temp;
8861 case VEC_WIDEN_MULT_HI_EXPR:
8862 case VEC_WIDEN_MULT_LO_EXPR:
8864 tree oprnd0 = TREE_OPERAND (exp, 0);
8865 tree oprnd1 = TREE_OPERAND (exp, 1);
8867 expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, 0);
8868 target = expand_widen_pattern_expr (exp, op0, op1, NULL_RTX,
8869 target, unsignedp);
8870 gcc_assert (target);
8871 return target;
8874 case VEC_PACK_MOD_EXPR:
8875 case VEC_PACK_SAT_EXPR:
8877 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
8878 goto binop;
8881 default:
8882 return lang_hooks.expand_expr (exp, original_target, tmode,
8883 modifier, alt_rtl);
8886 /* Here to do an ordinary binary operator. */
8887 binop:
8888 expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8889 subtarget, &op0, &op1, 0);
8890 binop2:
8891 this_optab = optab_for_tree_code (code, type);
8892 binop3:
8893 if (modifier == EXPAND_STACK_PARM)
8894 target = 0;
8895 temp = expand_binop (mode, this_optab, op0, op1, target,
8896 unsignedp, OPTAB_LIB_WIDEN);
8897 gcc_assert (temp);
8898 return REDUCE_BIT_FIELD (temp);
8900 #undef REDUCE_BIT_FIELD
8902 /* Subroutine of above: reduce EXP to the precision of TYPE (in the
8903 signedness of TYPE), possibly returning the result in TARGET. */
8904 static rtx
8905 reduce_to_bit_field_precision (rtx exp, rtx target, tree type)
8907 HOST_WIDE_INT prec = TYPE_PRECISION (type);
8908 if (target && GET_MODE (target) != GET_MODE (exp))
8909 target = 0;
8910 if (TYPE_UNSIGNED (type))
8912 rtx mask;
8913 if (prec < HOST_BITS_PER_WIDE_INT)
8914 mask = immed_double_const (((unsigned HOST_WIDE_INT) 1 << prec) - 1, 0,
8915 GET_MODE (exp));
8916 else
8917 mask = immed_double_const ((unsigned HOST_WIDE_INT) -1,
8918 ((unsigned HOST_WIDE_INT) 1
8919 << (prec - HOST_BITS_PER_WIDE_INT)) - 1,
8920 GET_MODE (exp));
8921 return expand_and (GET_MODE (exp), exp, mask, target);
8923 else
8925 tree count = build_int_cst (NULL_TREE,
8926 GET_MODE_BITSIZE (GET_MODE (exp)) - prec);
8927 exp = expand_shift (LSHIFT_EXPR, GET_MODE (exp), exp, count, target, 0);
8928 return expand_shift (RSHIFT_EXPR, GET_MODE (exp), exp, count, target, 0);
8932 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
8933 when applied to the address of EXP produces an address known to be
8934 aligned more than BIGGEST_ALIGNMENT. */
8936 static int
8937 is_aligning_offset (tree offset, tree exp)
8939 /* Strip off any conversions. */
8940 while (TREE_CODE (offset) == NON_LVALUE_EXPR
8941 || TREE_CODE (offset) == NOP_EXPR
8942 || TREE_CODE (offset) == CONVERT_EXPR)
8943 offset = TREE_OPERAND (offset, 0);
8945 /* We must now have a BIT_AND_EXPR with a constant that is one less than
8946 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
8947 if (TREE_CODE (offset) != BIT_AND_EXPR
8948 || !host_integerp (TREE_OPERAND (offset, 1), 1)
8949 || compare_tree_int (TREE_OPERAND (offset, 1),
8950 BIGGEST_ALIGNMENT / BITS_PER_UNIT) <= 0
8951 || !exact_log2 (tree_low_cst (TREE_OPERAND (offset, 1), 1) + 1) < 0)
8952 return 0;
8954 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
8955 It must be NEGATE_EXPR. Then strip any more conversions. */
8956 offset = TREE_OPERAND (offset, 0);
8957 while (TREE_CODE (offset) == NON_LVALUE_EXPR
8958 || TREE_CODE (offset) == NOP_EXPR
8959 || TREE_CODE (offset) == CONVERT_EXPR)
8960 offset = TREE_OPERAND (offset, 0);
8962 if (TREE_CODE (offset) != NEGATE_EXPR)
8963 return 0;
8965 offset = TREE_OPERAND (offset, 0);
8966 while (TREE_CODE (offset) == NON_LVALUE_EXPR
8967 || TREE_CODE (offset) == NOP_EXPR
8968 || TREE_CODE (offset) == CONVERT_EXPR)
8969 offset = TREE_OPERAND (offset, 0);
8971 /* This must now be the address of EXP. */
8972 return TREE_CODE (offset) == ADDR_EXPR && TREE_OPERAND (offset, 0) == exp;
8975 /* Return the tree node if an ARG corresponds to a string constant or zero
8976 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
8977 in bytes within the string that ARG is accessing. The type of the
8978 offset will be `sizetype'. */
8980 tree
8981 string_constant (tree arg, tree *ptr_offset)
8983 tree array, offset, lower_bound;
8984 STRIP_NOPS (arg);
8986 if (TREE_CODE (arg) == ADDR_EXPR)
8988 if (TREE_CODE (TREE_OPERAND (arg, 0)) == STRING_CST)
8990 *ptr_offset = size_zero_node;
8991 return TREE_OPERAND (arg, 0);
8993 else if (TREE_CODE (TREE_OPERAND (arg, 0)) == VAR_DECL)
8995 array = TREE_OPERAND (arg, 0);
8996 offset = size_zero_node;
8998 else if (TREE_CODE (TREE_OPERAND (arg, 0)) == ARRAY_REF)
9000 array = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
9001 offset = TREE_OPERAND (TREE_OPERAND (arg, 0), 1);
9002 if (TREE_CODE (array) != STRING_CST
9003 && TREE_CODE (array) != VAR_DECL)
9004 return 0;
9006 /* Check if the array has a nonzero lower bound. */
9007 lower_bound = array_ref_low_bound (TREE_OPERAND (arg, 0));
9008 if (!integer_zerop (lower_bound))
9010 /* If the offset and base aren't both constants, return 0. */
9011 if (TREE_CODE (lower_bound) != INTEGER_CST)
9012 return 0;
9013 if (TREE_CODE (offset) != INTEGER_CST)
9014 return 0;
9015 /* Adjust offset by the lower bound. */
9016 offset = size_diffop (fold_convert (sizetype, offset),
9017 fold_convert (sizetype, lower_bound));
9020 else
9021 return 0;
9023 else if (TREE_CODE (arg) == PLUS_EXPR)
9025 tree arg0 = TREE_OPERAND (arg, 0);
9026 tree arg1 = TREE_OPERAND (arg, 1);
9028 STRIP_NOPS (arg0);
9029 STRIP_NOPS (arg1);
9031 if (TREE_CODE (arg0) == ADDR_EXPR
9032 && (TREE_CODE (TREE_OPERAND (arg0, 0)) == STRING_CST
9033 || TREE_CODE (TREE_OPERAND (arg0, 0)) == VAR_DECL))
9035 array = TREE_OPERAND (arg0, 0);
9036 offset = arg1;
9038 else if (TREE_CODE (arg1) == ADDR_EXPR
9039 && (TREE_CODE (TREE_OPERAND (arg1, 0)) == STRING_CST
9040 || TREE_CODE (TREE_OPERAND (arg1, 0)) == VAR_DECL))
9042 array = TREE_OPERAND (arg1, 0);
9043 offset = arg0;
9045 else
9046 return 0;
9048 else
9049 return 0;
9051 if (TREE_CODE (array) == STRING_CST)
9053 *ptr_offset = fold_convert (sizetype, offset);
9054 return array;
9056 else if (TREE_CODE (array) == VAR_DECL)
9058 int length;
9060 /* Variables initialized to string literals can be handled too. */
9061 if (DECL_INITIAL (array) == NULL_TREE
9062 || TREE_CODE (DECL_INITIAL (array)) != STRING_CST)
9063 return 0;
9065 /* If they are read-only, non-volatile and bind locally. */
9066 if (! TREE_READONLY (array)
9067 || TREE_SIDE_EFFECTS (array)
9068 || ! targetm.binds_local_p (array))
9069 return 0;
9071 /* Avoid const char foo[4] = "abcde"; */
9072 if (DECL_SIZE_UNIT (array) == NULL_TREE
9073 || TREE_CODE (DECL_SIZE_UNIT (array)) != INTEGER_CST
9074 || (length = TREE_STRING_LENGTH (DECL_INITIAL (array))) <= 0
9075 || compare_tree_int (DECL_SIZE_UNIT (array), length) < 0)
9076 return 0;
9078 /* If variable is bigger than the string literal, OFFSET must be constant
9079 and inside of the bounds of the string literal. */
9080 offset = fold_convert (sizetype, offset);
9081 if (compare_tree_int (DECL_SIZE_UNIT (array), length) > 0
9082 && (! host_integerp (offset, 1)
9083 || compare_tree_int (offset, length) >= 0))
9084 return 0;
9086 *ptr_offset = offset;
9087 return DECL_INITIAL (array);
9090 return 0;
9093 /* Generate code to calculate EXP using a store-flag instruction
9094 and return an rtx for the result. EXP is either a comparison
9095 or a TRUTH_NOT_EXPR whose operand is a comparison.
9097 If TARGET is nonzero, store the result there if convenient.
9099 If ONLY_CHEAP is nonzero, only do this if it is likely to be very
9100 cheap.
9102 Return zero if there is no suitable set-flag instruction
9103 available on this machine.
9105 Once expand_expr has been called on the arguments of the comparison,
9106 we are committed to doing the store flag, since it is not safe to
9107 re-evaluate the expression. We emit the store-flag insn by calling
9108 emit_store_flag, but only expand the arguments if we have a reason
9109 to believe that emit_store_flag will be successful. If we think that
9110 it will, but it isn't, we have to simulate the store-flag with a
9111 set/jump/set sequence. */
9113 static rtx
9114 do_store_flag (tree exp, rtx target, enum machine_mode mode, int only_cheap)
9116 enum rtx_code code;
9117 tree arg0, arg1, type;
9118 tree tem;
9119 enum machine_mode operand_mode;
9120 int invert = 0;
9121 int unsignedp;
9122 rtx op0, op1;
9123 enum insn_code icode;
9124 rtx subtarget = target;
9125 rtx result, label;
9127 /* If this is a TRUTH_NOT_EXPR, set a flag indicating we must invert the
9128 result at the end. We can't simply invert the test since it would
9129 have already been inverted if it were valid. This case occurs for
9130 some floating-point comparisons. */
9132 if (TREE_CODE (exp) == TRUTH_NOT_EXPR)
9133 invert = 1, exp = TREE_OPERAND (exp, 0);
9135 arg0 = TREE_OPERAND (exp, 0);
9136 arg1 = TREE_OPERAND (exp, 1);
9138 /* Don't crash if the comparison was erroneous. */
9139 if (arg0 == error_mark_node || arg1 == error_mark_node)
9140 return const0_rtx;
9142 type = TREE_TYPE (arg0);
9143 operand_mode = TYPE_MODE (type);
9144 unsignedp = TYPE_UNSIGNED (type);
9146 /* We won't bother with BLKmode store-flag operations because it would mean
9147 passing a lot of information to emit_store_flag. */
9148 if (operand_mode == BLKmode)
9149 return 0;
9151 /* We won't bother with store-flag operations involving function pointers
9152 when function pointers must be canonicalized before comparisons. */
9153 #ifdef HAVE_canonicalize_funcptr_for_compare
9154 if (HAVE_canonicalize_funcptr_for_compare
9155 && ((TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == POINTER_TYPE
9156 && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))))
9157 == FUNCTION_TYPE))
9158 || (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 1))) == POINTER_TYPE
9159 && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 1))))
9160 == FUNCTION_TYPE))))
9161 return 0;
9162 #endif
9164 STRIP_NOPS (arg0);
9165 STRIP_NOPS (arg1);
9167 /* Get the rtx comparison code to use. We know that EXP is a comparison
9168 operation of some type. Some comparisons against 1 and -1 can be
9169 converted to comparisons with zero. Do so here so that the tests
9170 below will be aware that we have a comparison with zero. These
9171 tests will not catch constants in the first operand, but constants
9172 are rarely passed as the first operand. */
9174 switch (TREE_CODE (exp))
9176 case EQ_EXPR:
9177 code = EQ;
9178 break;
9179 case NE_EXPR:
9180 code = NE;
9181 break;
9182 case LT_EXPR:
9183 if (integer_onep (arg1))
9184 arg1 = integer_zero_node, code = unsignedp ? LEU : LE;
9185 else
9186 code = unsignedp ? LTU : LT;
9187 break;
9188 case LE_EXPR:
9189 if (! unsignedp && integer_all_onesp (arg1))
9190 arg1 = integer_zero_node, code = LT;
9191 else
9192 code = unsignedp ? LEU : LE;
9193 break;
9194 case GT_EXPR:
9195 if (! unsignedp && integer_all_onesp (arg1))
9196 arg1 = integer_zero_node, code = GE;
9197 else
9198 code = unsignedp ? GTU : GT;
9199 break;
9200 case GE_EXPR:
9201 if (integer_onep (arg1))
9202 arg1 = integer_zero_node, code = unsignedp ? GTU : GT;
9203 else
9204 code = unsignedp ? GEU : GE;
9205 break;
9207 case UNORDERED_EXPR:
9208 code = UNORDERED;
9209 break;
9210 case ORDERED_EXPR:
9211 code = ORDERED;
9212 break;
9213 case UNLT_EXPR:
9214 code = UNLT;
9215 break;
9216 case UNLE_EXPR:
9217 code = UNLE;
9218 break;
9219 case UNGT_EXPR:
9220 code = UNGT;
9221 break;
9222 case UNGE_EXPR:
9223 code = UNGE;
9224 break;
9225 case UNEQ_EXPR:
9226 code = UNEQ;
9227 break;
9228 case LTGT_EXPR:
9229 code = LTGT;
9230 break;
9232 default:
9233 gcc_unreachable ();
9236 /* Put a constant second. */
9237 if (TREE_CODE (arg0) == REAL_CST || TREE_CODE (arg0) == INTEGER_CST)
9239 tem = arg0; arg0 = arg1; arg1 = tem;
9240 code = swap_condition (code);
9243 /* If this is an equality or inequality test of a single bit, we can
9244 do this by shifting the bit being tested to the low-order bit and
9245 masking the result with the constant 1. If the condition was EQ,
9246 we xor it with 1. This does not require an scc insn and is faster
9247 than an scc insn even if we have it.
9249 The code to make this transformation was moved into fold_single_bit_test,
9250 so we just call into the folder and expand its result. */
9252 if ((code == NE || code == EQ)
9253 && TREE_CODE (arg0) == BIT_AND_EXPR && integer_zerop (arg1)
9254 && integer_pow2p (TREE_OPERAND (arg0, 1)))
9256 tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
9257 return expand_expr (fold_single_bit_test (code == NE ? NE_EXPR : EQ_EXPR,
9258 arg0, arg1, type),
9259 target, VOIDmode, EXPAND_NORMAL);
9262 /* Now see if we are likely to be able to do this. Return if not. */
9263 if (! can_compare_p (code, operand_mode, ccp_store_flag))
9264 return 0;
9266 icode = setcc_gen_code[(int) code];
9268 if (icode == CODE_FOR_nothing)
9270 enum machine_mode wmode;
9272 for (wmode = operand_mode;
9273 icode == CODE_FOR_nothing && wmode != VOIDmode;
9274 wmode = GET_MODE_WIDER_MODE (wmode))
9275 icode = cstore_optab->handlers[(int) wmode].insn_code;
9278 if (icode == CODE_FOR_nothing
9279 || (only_cheap && insn_data[(int) icode].operand[0].mode != mode))
9281 /* We can only do this if it is one of the special cases that
9282 can be handled without an scc insn. */
9283 if ((code == LT && integer_zerop (arg1))
9284 || (! only_cheap && code == GE && integer_zerop (arg1)))
9286 else if (! only_cheap && (code == NE || code == EQ)
9287 && TREE_CODE (type) != REAL_TYPE
9288 && ((abs_optab->handlers[(int) operand_mode].insn_code
9289 != CODE_FOR_nothing)
9290 || (ffs_optab->handlers[(int) operand_mode].insn_code
9291 != CODE_FOR_nothing)))
9293 else
9294 return 0;
9297 if (! get_subtarget (target)
9298 || GET_MODE (subtarget) != operand_mode)
9299 subtarget = 0;
9301 expand_operands (arg0, arg1, subtarget, &op0, &op1, 0);
9303 if (target == 0)
9304 target = gen_reg_rtx (mode);
9306 result = emit_store_flag (target, code, op0, op1,
9307 operand_mode, unsignedp, 1);
9309 if (result)
9311 if (invert)
9312 result = expand_binop (mode, xor_optab, result, const1_rtx,
9313 result, 0, OPTAB_LIB_WIDEN);
9314 return result;
9317 /* If this failed, we have to do this with set/compare/jump/set code. */
9318 if (!REG_P (target)
9319 || reg_mentioned_p (target, op0) || reg_mentioned_p (target, op1))
9320 target = gen_reg_rtx (GET_MODE (target));
9322 emit_move_insn (target, invert ? const0_rtx : const1_rtx);
9323 label = gen_label_rtx ();
9324 do_compare_rtx_and_jump (op0, op1, code, unsignedp, operand_mode, NULL_RTX,
9325 NULL_RTX, label);
9327 emit_move_insn (target, invert ? const1_rtx : const0_rtx);
9328 emit_label (label);
9330 return target;
9334 /* Stubs in case we haven't got a casesi insn. */
9335 #ifndef HAVE_casesi
9336 # define HAVE_casesi 0
9337 # define gen_casesi(a, b, c, d, e) (0)
9338 # define CODE_FOR_casesi CODE_FOR_nothing
9339 #endif
9341 /* If the machine does not have a case insn that compares the bounds,
9342 this means extra overhead for dispatch tables, which raises the
9343 threshold for using them. */
9344 #ifndef CASE_VALUES_THRESHOLD
9345 #define CASE_VALUES_THRESHOLD (HAVE_casesi ? 4 : 5)
9346 #endif /* CASE_VALUES_THRESHOLD */
9348 unsigned int
9349 case_values_threshold (void)
9351 return CASE_VALUES_THRESHOLD;
9354 /* Attempt to generate a casesi instruction. Returns 1 if successful,
9355 0 otherwise (i.e. if there is no casesi instruction). */
9357 try_casesi (tree index_type, tree index_expr, tree minval, tree range,
9358 rtx table_label ATTRIBUTE_UNUSED, rtx default_label)
9360 enum machine_mode index_mode = SImode;
9361 int index_bits = GET_MODE_BITSIZE (index_mode);
9362 rtx op1, op2, index;
9363 enum machine_mode op_mode;
9365 if (! HAVE_casesi)
9366 return 0;
9368 /* Convert the index to SImode. */
9369 if (GET_MODE_BITSIZE (TYPE_MODE (index_type)) > GET_MODE_BITSIZE (index_mode))
9371 enum machine_mode omode = TYPE_MODE (index_type);
9372 rtx rangertx = expand_normal (range);
9374 /* We must handle the endpoints in the original mode. */
9375 index_expr = build2 (MINUS_EXPR, index_type,
9376 index_expr, minval);
9377 minval = integer_zero_node;
9378 index = expand_normal (index_expr);
9379 emit_cmp_and_jump_insns (rangertx, index, LTU, NULL_RTX,
9380 omode, 1, default_label);
9381 /* Now we can safely truncate. */
9382 index = convert_to_mode (index_mode, index, 0);
9384 else
9386 if (TYPE_MODE (index_type) != index_mode)
9388 index_type = lang_hooks.types.type_for_size (index_bits, 0);
9389 index_expr = fold_convert (index_type, index_expr);
9392 index = expand_normal (index_expr);
9395 do_pending_stack_adjust ();
9397 op_mode = insn_data[(int) CODE_FOR_casesi].operand[0].mode;
9398 if (! (*insn_data[(int) CODE_FOR_casesi].operand[0].predicate)
9399 (index, op_mode))
9400 index = copy_to_mode_reg (op_mode, index);
9402 op1 = expand_normal (minval);
9404 op_mode = insn_data[(int) CODE_FOR_casesi].operand[1].mode;
9405 op1 = convert_modes (op_mode, TYPE_MODE (TREE_TYPE (minval)),
9406 op1, TYPE_UNSIGNED (TREE_TYPE (minval)));
9407 if (! (*insn_data[(int) CODE_FOR_casesi].operand[1].predicate)
9408 (op1, op_mode))
9409 op1 = copy_to_mode_reg (op_mode, op1);
9411 op2 = expand_normal (range);
9413 op_mode = insn_data[(int) CODE_FOR_casesi].operand[2].mode;
9414 op2 = convert_modes (op_mode, TYPE_MODE (TREE_TYPE (range)),
9415 op2, TYPE_UNSIGNED (TREE_TYPE (range)));
9416 if (! (*insn_data[(int) CODE_FOR_casesi].operand[2].predicate)
9417 (op2, op_mode))
9418 op2 = copy_to_mode_reg (op_mode, op2);
9420 emit_jump_insn (gen_casesi (index, op1, op2,
9421 table_label, default_label));
9422 return 1;
9425 /* Attempt to generate a tablejump instruction; same concept. */
9426 #ifndef HAVE_tablejump
9427 #define HAVE_tablejump 0
9428 #define gen_tablejump(x, y) (0)
9429 #endif
9431 /* Subroutine of the next function.
9433 INDEX is the value being switched on, with the lowest value
9434 in the table already subtracted.
9435 MODE is its expected mode (needed if INDEX is constant).
9436 RANGE is the length of the jump table.
9437 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
9439 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
9440 index value is out of range. */
9442 static void
9443 do_tablejump (rtx index, enum machine_mode mode, rtx range, rtx table_label,
9444 rtx default_label)
9446 rtx temp, vector;
9448 if (INTVAL (range) > cfun->max_jumptable_ents)
9449 cfun->max_jumptable_ents = INTVAL (range);
9451 /* Do an unsigned comparison (in the proper mode) between the index
9452 expression and the value which represents the length of the range.
9453 Since we just finished subtracting the lower bound of the range
9454 from the index expression, this comparison allows us to simultaneously
9455 check that the original index expression value is both greater than
9456 or equal to the minimum value of the range and less than or equal to
9457 the maximum value of the range. */
9459 emit_cmp_and_jump_insns (index, range, GTU, NULL_RTX, mode, 1,
9460 default_label);
9462 /* If index is in range, it must fit in Pmode.
9463 Convert to Pmode so we can index with it. */
9464 if (mode != Pmode)
9465 index = convert_to_mode (Pmode, index, 1);
9467 /* Don't let a MEM slip through, because then INDEX that comes
9468 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
9469 and break_out_memory_refs will go to work on it and mess it up. */
9470 #ifdef PIC_CASE_VECTOR_ADDRESS
9471 if (flag_pic && !REG_P (index))
9472 index = copy_to_mode_reg (Pmode, index);
9473 #endif
9475 /* If flag_force_addr were to affect this address
9476 it could interfere with the tricky assumptions made
9477 about addresses that contain label-refs,
9478 which may be valid only very near the tablejump itself. */
9479 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
9480 GET_MODE_SIZE, because this indicates how large insns are. The other
9481 uses should all be Pmode, because they are addresses. This code
9482 could fail if addresses and insns are not the same size. */
9483 index = gen_rtx_PLUS (Pmode,
9484 gen_rtx_MULT (Pmode, index,
9485 GEN_INT (GET_MODE_SIZE (CASE_VECTOR_MODE))),
9486 gen_rtx_LABEL_REF (Pmode, table_label));
9487 #ifdef PIC_CASE_VECTOR_ADDRESS
9488 if (flag_pic)
9489 index = PIC_CASE_VECTOR_ADDRESS (index);
9490 else
9491 #endif
9492 index = memory_address_noforce (CASE_VECTOR_MODE, index);
9493 temp = gen_reg_rtx (CASE_VECTOR_MODE);
9494 vector = gen_const_mem (CASE_VECTOR_MODE, index);
9495 convert_move (temp, vector, 0);
9497 emit_jump_insn (gen_tablejump (temp, table_label));
9499 /* If we are generating PIC code or if the table is PC-relative, the
9500 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
9501 if (! CASE_VECTOR_PC_RELATIVE && ! flag_pic)
9502 emit_barrier ();
9506 try_tablejump (tree index_type, tree index_expr, tree minval, tree range,
9507 rtx table_label, rtx default_label)
9509 rtx index;
9511 if (! HAVE_tablejump)
9512 return 0;
9514 index_expr = fold_build2 (MINUS_EXPR, index_type,
9515 fold_convert (index_type, index_expr),
9516 fold_convert (index_type, minval));
9517 index = expand_normal (index_expr);
9518 do_pending_stack_adjust ();
9520 do_tablejump (index, TYPE_MODE (index_type),
9521 convert_modes (TYPE_MODE (index_type),
9522 TYPE_MODE (TREE_TYPE (range)),
9523 expand_normal (range),
9524 TYPE_UNSIGNED (TREE_TYPE (range))),
9525 table_label, default_label);
9526 return 1;
9529 /* Nonzero if the mode is a valid vector mode for this architecture.
9530 This returns nonzero even if there is no hardware support for the
9531 vector mode, but we can emulate with narrower modes. */
9534 vector_mode_valid_p (enum machine_mode mode)
9536 enum mode_class class = GET_MODE_CLASS (mode);
9537 enum machine_mode innermode;
9539 /* Doh! What's going on? */
9540 if (class != MODE_VECTOR_INT
9541 && class != MODE_VECTOR_FLOAT)
9542 return 0;
9544 /* Hardware support. Woo hoo! */
9545 if (targetm.vector_mode_supported_p (mode))
9546 return 1;
9548 innermode = GET_MODE_INNER (mode);
9550 /* We should probably return 1 if requesting V4DI and we have no DI,
9551 but we have V2DI, but this is probably very unlikely. */
9553 /* If we have support for the inner mode, we can safely emulate it.
9554 We may not have V2DI, but me can emulate with a pair of DIs. */
9555 return targetm.scalar_mode_supported_p (innermode);
9558 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
9559 static rtx
9560 const_vector_from_tree (tree exp)
9562 rtvec v;
9563 int units, i;
9564 tree link, elt;
9565 enum machine_mode inner, mode;
9567 mode = TYPE_MODE (TREE_TYPE (exp));
9569 if (initializer_zerop (exp))
9570 return CONST0_RTX (mode);
9572 units = GET_MODE_NUNITS (mode);
9573 inner = GET_MODE_INNER (mode);
9575 v = rtvec_alloc (units);
9577 link = TREE_VECTOR_CST_ELTS (exp);
9578 for (i = 0; link; link = TREE_CHAIN (link), ++i)
9580 elt = TREE_VALUE (link);
9582 if (TREE_CODE (elt) == REAL_CST)
9583 RTVEC_ELT (v, i) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt),
9584 inner);
9585 else
9586 RTVEC_ELT (v, i) = immed_double_const (TREE_INT_CST_LOW (elt),
9587 TREE_INT_CST_HIGH (elt),
9588 inner);
9591 /* Initialize remaining elements to 0. */
9592 for (; i < units; ++i)
9593 RTVEC_ELT (v, i) = CONST0_RTX (inner);
9595 return gen_rtx_CONST_VECTOR (mode, v);
9597 #include "gt-expr.h"