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 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
30 #include "hard-reg-set.h"
33 #include "insn-config.h"
34 #include "insn-attr.h"
35 /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
42 #include "typeclass.h"
45 #include "langhooks.h"
49 /* Decide whether a function's arguments should be processed
50 from first to last or from last to first.
52 They should if the stack and args grow in opposite directions, but
53 only if we have push insns. */
57 #ifndef PUSH_ARGS_REVERSED
58 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
59 #define PUSH_ARGS_REVERSED /* If it's last to first. */
65 #ifndef STACK_PUSH_CODE
66 #ifdef STACK_GROWS_DOWNWARD
67 #define STACK_PUSH_CODE PRE_DEC
69 #define STACK_PUSH_CODE PRE_INC
73 /* Assume that case vectors are not pc-relative. */
74 #ifndef CASE_VECTOR_PC_RELATIVE
75 #define CASE_VECTOR_PC_RELATIVE 0
78 /* Convert defined/undefined to boolean. */
79 #ifdef TARGET_MEM_FUNCTIONS
80 #undef TARGET_MEM_FUNCTIONS
81 #define TARGET_MEM_FUNCTIONS 1
83 #define TARGET_MEM_FUNCTIONS 0
87 /* If this is nonzero, we do not bother generating VOLATILE
88 around volatile memory references, and we are willing to
89 output indirect addresses. If cse is to follow, we reject
90 indirect addresses so a useful potential cse is generated;
91 if it is used only once, instruction combination will produce
92 the same indirect address eventually. */
95 /* Chain of pending expressions for PLACEHOLDER_EXPR to replace. */
96 static tree placeholder_list = 0;
98 /* This structure is used by move_by_pieces to describe the move to
100 struct move_by_pieces
109 int explicit_inc_from;
110 unsigned HOST_WIDE_INT len;
111 HOST_WIDE_INT offset;
115 /* This structure is used by store_by_pieces to describe the clear to
118 struct store_by_pieces
124 unsigned HOST_WIDE_INT len;
125 HOST_WIDE_INT offset;
126 rtx (*constfun) PARAMS ((PTR, HOST_WIDE_INT, enum machine_mode));
131 static rtx enqueue_insn PARAMS ((rtx, rtx));
132 static unsigned HOST_WIDE_INT move_by_pieces_ninsns
133 PARAMS ((unsigned HOST_WIDE_INT,
135 static void move_by_pieces_1 PARAMS ((rtx (*) (rtx, ...), enum machine_mode,
136 struct move_by_pieces *));
137 static bool block_move_libcall_safe_for_call_parm PARAMS ((void));
138 static bool emit_block_move_via_movstr PARAMS ((rtx, rtx, rtx, unsigned));
139 static rtx emit_block_move_via_libcall PARAMS ((rtx, rtx, rtx));
140 static tree emit_block_move_libcall_fn PARAMS ((int));
141 static void emit_block_move_via_loop PARAMS ((rtx, rtx, rtx, unsigned));
142 static rtx clear_by_pieces_1 PARAMS ((PTR, HOST_WIDE_INT,
144 static void clear_by_pieces PARAMS ((rtx, unsigned HOST_WIDE_INT,
146 static void store_by_pieces_1 PARAMS ((struct store_by_pieces *,
148 static void store_by_pieces_2 PARAMS ((rtx (*) (rtx, ...),
150 struct store_by_pieces *));
151 static bool clear_storage_via_clrstr PARAMS ((rtx, rtx, unsigned));
152 static rtx clear_storage_via_libcall PARAMS ((rtx, rtx));
153 static tree clear_storage_libcall_fn PARAMS ((int));
154 static rtx compress_float_constant PARAMS ((rtx, rtx));
155 static rtx get_subtarget PARAMS ((rtx));
156 static int is_zeros_p PARAMS ((tree));
157 static int mostly_zeros_p PARAMS ((tree));
158 static void store_constructor_field PARAMS ((rtx, unsigned HOST_WIDE_INT,
159 HOST_WIDE_INT, enum machine_mode,
160 tree, tree, int, int));
161 static void store_constructor PARAMS ((tree, rtx, int, HOST_WIDE_INT));
162 static rtx store_field PARAMS ((rtx, HOST_WIDE_INT,
163 HOST_WIDE_INT, enum machine_mode,
164 tree, enum machine_mode, int, tree,
166 static rtx var_rtx PARAMS ((tree));
167 static HOST_WIDE_INT highest_pow2_factor PARAMS ((tree));
168 static HOST_WIDE_INT highest_pow2_factor_for_type PARAMS ((tree, tree));
169 static int is_aligning_offset PARAMS ((tree, tree));
170 static rtx expand_increment PARAMS ((tree, int, int));
171 static void do_jump_by_parts_greater PARAMS ((tree, int, rtx, rtx));
172 static void do_jump_by_parts_equality PARAMS ((tree, rtx, rtx));
173 static void do_compare_and_jump PARAMS ((tree, enum rtx_code, enum rtx_code,
175 static rtx do_store_flag PARAMS ((tree, rtx, enum machine_mode, int));
177 static void emit_single_push_insn PARAMS ((enum machine_mode, rtx, tree));
179 static void do_tablejump PARAMS ((rtx, enum machine_mode, rtx, rtx, rtx));
180 static rtx const_vector_from_tree PARAMS ((tree));
182 /* Record for each mode whether we can move a register directly to or
183 from an object of that mode in memory. If we can't, we won't try
184 to use that mode directly when accessing a field of that mode. */
186 static char direct_load[NUM_MACHINE_MODES];
187 static char direct_store[NUM_MACHINE_MODES];
189 /* Record for each mode whether we can float-extend from memory. */
191 static bool float_extend_from_mem[NUM_MACHINE_MODES][NUM_MACHINE_MODES];
193 /* If a memory-to-memory move would take MOVE_RATIO or more simple
194 move-instruction sequences, we will do a movstr or libcall instead. */
197 #if defined (HAVE_movstrqi) || defined (HAVE_movstrhi) || defined (HAVE_movstrsi) || defined (HAVE_movstrdi) || defined (HAVE_movstrti)
200 /* If we are optimizing for space (-Os), cut down the default move ratio. */
201 #define MOVE_RATIO (optimize_size ? 3 : 15)
205 /* This macro is used to determine whether move_by_pieces should be called
206 to perform a structure copy. */
207 #ifndef MOVE_BY_PIECES_P
208 #define MOVE_BY_PIECES_P(SIZE, ALIGN) \
209 (move_by_pieces_ninsns (SIZE, ALIGN) < (unsigned int) MOVE_RATIO)
212 /* If a clear memory operation would take CLEAR_RATIO or more simple
213 move-instruction sequences, we will do a clrstr or libcall instead. */
216 #if defined (HAVE_clrstrqi) || defined (HAVE_clrstrhi) || defined (HAVE_clrstrsi) || defined (HAVE_clrstrdi) || defined (HAVE_clrstrti)
217 #define CLEAR_RATIO 2
219 /* If we are optimizing for space, cut down the default clear ratio. */
220 #define CLEAR_RATIO (optimize_size ? 3 : 15)
224 /* This macro is used to determine whether clear_by_pieces should be
225 called to clear storage. */
226 #ifndef CLEAR_BY_PIECES_P
227 #define CLEAR_BY_PIECES_P(SIZE, ALIGN) \
228 (move_by_pieces_ninsns (SIZE, ALIGN) < (unsigned int) CLEAR_RATIO)
231 /* This array records the insn_code of insns to perform block moves. */
232 enum insn_code movstr_optab[NUM_MACHINE_MODES];
234 /* This array records the insn_code of insns to perform block clears. */
235 enum insn_code clrstr_optab[NUM_MACHINE_MODES];
237 /* SLOW_UNALIGNED_ACCESS is nonzero if unaligned accesses are very slow. */
239 #ifndef SLOW_UNALIGNED_ACCESS
240 #define SLOW_UNALIGNED_ACCESS(MODE, ALIGN) STRICT_ALIGNMENT
243 /* This is run once per compilation to set up which modes can be used
244 directly in memory and to initialize the block move optab. */
250 enum machine_mode mode;
255 /* Try indexing by frame ptr and try by stack ptr.
256 It is known that on the Convex the stack ptr isn't a valid index.
257 With luck, one or the other is valid on any machine. */
258 mem = gen_rtx_MEM (VOIDmode, stack_pointer_rtx);
259 mem1 = gen_rtx_MEM (VOIDmode, frame_pointer_rtx);
261 /* A scratch register we can modify in-place below to avoid
262 useless RTL allocations. */
263 reg = gen_rtx_REG (VOIDmode, -1);
265 insn = rtx_alloc (INSN);
266 pat = gen_rtx_SET (0, NULL_RTX, NULL_RTX);
267 PATTERN (insn) = pat;
269 for (mode = VOIDmode; (int) mode < NUM_MACHINE_MODES;
270 mode = (enum machine_mode) ((int) mode + 1))
274 direct_load[(int) mode] = direct_store[(int) mode] = 0;
275 PUT_MODE (mem, mode);
276 PUT_MODE (mem1, mode);
277 PUT_MODE (reg, mode);
279 /* See if there is some register that can be used in this mode and
280 directly loaded or stored from memory. */
282 if (mode != VOIDmode && mode != BLKmode)
283 for (regno = 0; regno < FIRST_PSEUDO_REGISTER
284 && (direct_load[(int) mode] == 0 || direct_store[(int) mode] == 0);
287 if (! HARD_REGNO_MODE_OK (regno, mode))
293 SET_DEST (pat) = reg;
294 if (recog (pat, insn, &num_clobbers) >= 0)
295 direct_load[(int) mode] = 1;
297 SET_SRC (pat) = mem1;
298 SET_DEST (pat) = reg;
299 if (recog (pat, insn, &num_clobbers) >= 0)
300 direct_load[(int) mode] = 1;
303 SET_DEST (pat) = mem;
304 if (recog (pat, insn, &num_clobbers) >= 0)
305 direct_store[(int) mode] = 1;
308 SET_DEST (pat) = mem1;
309 if (recog (pat, insn, &num_clobbers) >= 0)
310 direct_store[(int) mode] = 1;
314 mem = gen_rtx_MEM (VOIDmode, gen_rtx_raw_REG (Pmode, 10000));
316 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
317 mode = GET_MODE_WIDER_MODE (mode))
319 enum machine_mode srcmode;
320 for (srcmode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); srcmode != mode;
321 srcmode = GET_MODE_WIDER_MODE (srcmode))
325 ic = can_extend_p (mode, srcmode, 0);
326 if (ic == CODE_FOR_nothing)
329 PUT_MODE (mem, srcmode);
331 if ((*insn_data[ic].operand[1].predicate) (mem, srcmode))
332 float_extend_from_mem[mode][srcmode] = true;
337 /* This is run at the start of compiling a function. */
342 cfun->expr = (struct expr_status *) ggc_alloc (sizeof (struct expr_status));
345 pending_stack_adjust = 0;
346 stack_pointer_delta = 0;
347 inhibit_defer_pop = 0;
349 apply_args_value = 0;
353 /* Small sanity check that the queue is empty at the end of a function. */
356 finish_expr_for_function ()
362 /* Manage the queue of increment instructions to be output
363 for POSTINCREMENT_EXPR expressions, etc. */
365 /* Queue up to increment (or change) VAR later. BODY says how:
366 BODY should be the same thing you would pass to emit_insn
367 to increment right away. It will go to emit_insn later on.
369 The value is a QUEUED expression to be used in place of VAR
370 where you want to guarantee the pre-incrementation value of VAR. */
373 enqueue_insn (var, body)
376 pending_chain = gen_rtx_QUEUED (GET_MODE (var), var, NULL_RTX, NULL_RTX,
377 body, pending_chain);
378 return pending_chain;
381 /* Use protect_from_queue to convert a QUEUED expression
382 into something that you can put immediately into an instruction.
383 If the queued incrementation has not happened yet,
384 protect_from_queue returns the variable itself.
385 If the incrementation has happened, protect_from_queue returns a temp
386 that contains a copy of the old value of the variable.
388 Any time an rtx which might possibly be a QUEUED is to be put
389 into an instruction, it must be passed through protect_from_queue first.
390 QUEUED expressions are not meaningful in instructions.
392 Do not pass a value through protect_from_queue and then hold
393 on to it for a while before putting it in an instruction!
394 If the queue is flushed in between, incorrect code will result. */
397 protect_from_queue (x, modify)
401 RTX_CODE code = GET_CODE (x);
403 #if 0 /* A QUEUED can hang around after the queue is forced out. */
404 /* Shortcut for most common case. */
405 if (pending_chain == 0)
411 /* A special hack for read access to (MEM (QUEUED ...)) to facilitate
412 use of autoincrement. Make a copy of the contents of the memory
413 location rather than a copy of the address, but not if the value is
414 of mode BLKmode. Don't modify X in place since it might be
416 if (code == MEM && GET_MODE (x) != BLKmode
417 && GET_CODE (XEXP (x, 0)) == QUEUED && !modify)
420 rtx new = replace_equiv_address_nv (x, QUEUED_VAR (y));
424 rtx temp = gen_reg_rtx (GET_MODE (x));
426 emit_insn_before (gen_move_insn (temp, new),
431 /* Copy the address into a pseudo, so that the returned value
432 remains correct across calls to emit_queue. */
433 return replace_equiv_address (new, copy_to_reg (XEXP (new, 0)));
436 /* Otherwise, recursively protect the subexpressions of all
437 the kinds of rtx's that can contain a QUEUED. */
440 rtx tem = protect_from_queue (XEXP (x, 0), 0);
441 if (tem != XEXP (x, 0))
447 else if (code == PLUS || code == MULT)
449 rtx new0 = protect_from_queue (XEXP (x, 0), 0);
450 rtx new1 = protect_from_queue (XEXP (x, 1), 0);
451 if (new0 != XEXP (x, 0) || new1 != XEXP (x, 1))
460 /* If the increment has not happened, use the variable itself. Copy it
461 into a new pseudo so that the value remains correct across calls to
463 if (QUEUED_INSN (x) == 0)
464 return copy_to_reg (QUEUED_VAR (x));
465 /* If the increment has happened and a pre-increment copy exists,
467 if (QUEUED_COPY (x) != 0)
468 return QUEUED_COPY (x);
469 /* The increment has happened but we haven't set up a pre-increment copy.
470 Set one up now, and use it. */
471 QUEUED_COPY (x) = gen_reg_rtx (GET_MODE (QUEUED_VAR (x)));
472 emit_insn_before (gen_move_insn (QUEUED_COPY (x), QUEUED_VAR (x)),
474 return QUEUED_COPY (x);
477 /* Return nonzero if X contains a QUEUED expression:
478 if it contains anything that will be altered by a queued increment.
479 We handle only combinations of MEM, PLUS, MINUS and MULT operators
480 since memory addresses generally contain only those. */
486 enum rtx_code code = GET_CODE (x);
492 return queued_subexp_p (XEXP (x, 0));
496 return (queued_subexp_p (XEXP (x, 0))
497 || queued_subexp_p (XEXP (x, 1)));
503 /* Perform all the pending incrementations. */
509 while ((p = pending_chain))
511 rtx body = QUEUED_BODY (p);
513 switch (GET_CODE (body))
521 QUEUED_INSN (p) = body;
525 #ifdef ENABLE_CHECKING
532 QUEUED_INSN (p) = emit_insn (body);
536 pending_chain = QUEUED_NEXT (p);
540 /* Copy data from FROM to TO, where the machine modes are not the same.
541 Both modes may be integer, or both may be floating.
542 UNSIGNEDP should be nonzero if FROM is an unsigned type.
543 This causes zero-extension instead of sign-extension. */
546 convert_move (to, from, unsignedp)
550 enum machine_mode to_mode = GET_MODE (to);
551 enum machine_mode from_mode = GET_MODE (from);
552 int to_real = GET_MODE_CLASS (to_mode) == MODE_FLOAT;
553 int from_real = GET_MODE_CLASS (from_mode) == MODE_FLOAT;
557 /* rtx code for making an equivalent value. */
558 enum rtx_code equiv_code = (unsignedp < 0 ? UNKNOWN
559 : (unsignedp ? ZERO_EXTEND : SIGN_EXTEND));
561 to = protect_from_queue (to, 1);
562 from = protect_from_queue (from, 0);
564 if (to_real != from_real)
567 /* If FROM is a SUBREG that indicates that we have already done at least
568 the required extension, strip it. We don't handle such SUBREGs as
571 if (GET_CODE (from) == SUBREG && SUBREG_PROMOTED_VAR_P (from)
572 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (from)))
573 >= GET_MODE_SIZE (to_mode))
574 && SUBREG_PROMOTED_UNSIGNED_P (from) == unsignedp)
575 from = gen_lowpart (to_mode, from), from_mode = to_mode;
577 if (GET_CODE (to) == SUBREG && SUBREG_PROMOTED_VAR_P (to))
580 if (to_mode == from_mode
581 || (from_mode == VOIDmode && CONSTANT_P (from)))
583 emit_move_insn (to, from);
587 if (VECTOR_MODE_P (to_mode) || VECTOR_MODE_P (from_mode))
589 if (GET_MODE_BITSIZE (from_mode) != GET_MODE_BITSIZE (to_mode))
592 if (VECTOR_MODE_P (to_mode))
593 from = simplify_gen_subreg (to_mode, from, GET_MODE (from), 0);
595 to = simplify_gen_subreg (from_mode, to, GET_MODE (to), 0);
597 emit_move_insn (to, from);
601 if (to_real != from_real)
608 if (GET_MODE_BITSIZE (from_mode) < GET_MODE_BITSIZE (to_mode))
610 /* Try converting directly if the insn is supported. */
611 if ((code = can_extend_p (to_mode, from_mode, 0))
614 emit_unop_insn (code, to, from, UNKNOWN);
619 #ifdef HAVE_trunchfqf2
620 if (HAVE_trunchfqf2 && from_mode == HFmode && to_mode == QFmode)
622 emit_unop_insn (CODE_FOR_trunchfqf2, to, from, UNKNOWN);
626 #ifdef HAVE_trunctqfqf2
627 if (HAVE_trunctqfqf2 && from_mode == TQFmode && to_mode == QFmode)
629 emit_unop_insn (CODE_FOR_trunctqfqf2, to, from, UNKNOWN);
633 #ifdef HAVE_truncsfqf2
634 if (HAVE_truncsfqf2 && from_mode == SFmode && to_mode == QFmode)
636 emit_unop_insn (CODE_FOR_truncsfqf2, to, from, UNKNOWN);
640 #ifdef HAVE_truncdfqf2
641 if (HAVE_truncdfqf2 && from_mode == DFmode && to_mode == QFmode)
643 emit_unop_insn (CODE_FOR_truncdfqf2, to, from, UNKNOWN);
647 #ifdef HAVE_truncxfqf2
648 if (HAVE_truncxfqf2 && from_mode == XFmode && to_mode == QFmode)
650 emit_unop_insn (CODE_FOR_truncxfqf2, to, from, UNKNOWN);
654 #ifdef HAVE_trunctfqf2
655 if (HAVE_trunctfqf2 && from_mode == TFmode && to_mode == QFmode)
657 emit_unop_insn (CODE_FOR_trunctfqf2, to, from, UNKNOWN);
662 #ifdef HAVE_trunctqfhf2
663 if (HAVE_trunctqfhf2 && from_mode == TQFmode && to_mode == HFmode)
665 emit_unop_insn (CODE_FOR_trunctqfhf2, to, from, UNKNOWN);
669 #ifdef HAVE_truncsfhf2
670 if (HAVE_truncsfhf2 && from_mode == SFmode && to_mode == HFmode)
672 emit_unop_insn (CODE_FOR_truncsfhf2, to, from, UNKNOWN);
676 #ifdef HAVE_truncdfhf2
677 if (HAVE_truncdfhf2 && from_mode == DFmode && to_mode == HFmode)
679 emit_unop_insn (CODE_FOR_truncdfhf2, to, from, UNKNOWN);
683 #ifdef HAVE_truncxfhf2
684 if (HAVE_truncxfhf2 && from_mode == XFmode && to_mode == HFmode)
686 emit_unop_insn (CODE_FOR_truncxfhf2, to, from, UNKNOWN);
690 #ifdef HAVE_trunctfhf2
691 if (HAVE_trunctfhf2 && from_mode == TFmode && to_mode == HFmode)
693 emit_unop_insn (CODE_FOR_trunctfhf2, to, from, UNKNOWN);
698 #ifdef HAVE_truncsftqf2
699 if (HAVE_truncsftqf2 && from_mode == SFmode && to_mode == TQFmode)
701 emit_unop_insn (CODE_FOR_truncsftqf2, to, from, UNKNOWN);
705 #ifdef HAVE_truncdftqf2
706 if (HAVE_truncdftqf2 && from_mode == DFmode && to_mode == TQFmode)
708 emit_unop_insn (CODE_FOR_truncdftqf2, to, from, UNKNOWN);
712 #ifdef HAVE_truncxftqf2
713 if (HAVE_truncxftqf2 && from_mode == XFmode && to_mode == TQFmode)
715 emit_unop_insn (CODE_FOR_truncxftqf2, to, from, UNKNOWN);
719 #ifdef HAVE_trunctftqf2
720 if (HAVE_trunctftqf2 && from_mode == TFmode && to_mode == TQFmode)
722 emit_unop_insn (CODE_FOR_trunctftqf2, to, from, UNKNOWN);
727 #ifdef HAVE_truncdfsf2
728 if (HAVE_truncdfsf2 && from_mode == DFmode && to_mode == SFmode)
730 emit_unop_insn (CODE_FOR_truncdfsf2, to, from, UNKNOWN);
734 #ifdef HAVE_truncxfsf2
735 if (HAVE_truncxfsf2 && from_mode == XFmode && to_mode == SFmode)
737 emit_unop_insn (CODE_FOR_truncxfsf2, to, from, UNKNOWN);
741 #ifdef HAVE_trunctfsf2
742 if (HAVE_trunctfsf2 && from_mode == TFmode && to_mode == SFmode)
744 emit_unop_insn (CODE_FOR_trunctfsf2, to, from, UNKNOWN);
748 #ifdef HAVE_truncxfdf2
749 if (HAVE_truncxfdf2 && from_mode == XFmode && to_mode == DFmode)
751 emit_unop_insn (CODE_FOR_truncxfdf2, to, from, UNKNOWN);
755 #ifdef HAVE_trunctfdf2
756 if (HAVE_trunctfdf2 && from_mode == TFmode && to_mode == DFmode)
758 emit_unop_insn (CODE_FOR_trunctfdf2, to, from, UNKNOWN);
770 libcall = extendsfdf2_libfunc;
774 libcall = extendsfxf2_libfunc;
778 libcall = extendsftf2_libfunc;
790 libcall = truncdfsf2_libfunc;
794 libcall = extenddfxf2_libfunc;
798 libcall = extenddftf2_libfunc;
810 libcall = truncxfsf2_libfunc;
814 libcall = truncxfdf2_libfunc;
826 libcall = trunctfsf2_libfunc;
830 libcall = trunctfdf2_libfunc;
842 if (libcall == (rtx) 0)
843 /* This conversion is not implemented yet. */
847 value = emit_library_call_value (libcall, NULL_RTX, LCT_CONST, to_mode,
849 insns = get_insns ();
851 emit_libcall_block (insns, to, value, gen_rtx_FLOAT_TRUNCATE (to_mode,
856 /* Now both modes are integers. */
858 /* Handle expanding beyond a word. */
859 if (GET_MODE_BITSIZE (from_mode) < GET_MODE_BITSIZE (to_mode)
860 && GET_MODE_BITSIZE (to_mode) > BITS_PER_WORD)
867 enum machine_mode lowpart_mode;
868 int nwords = CEIL (GET_MODE_SIZE (to_mode), UNITS_PER_WORD);
870 /* Try converting directly if the insn is supported. */
871 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
874 /* If FROM is a SUBREG, put it into a register. Do this
875 so that we always generate the same set of insns for
876 better cse'ing; if an intermediate assignment occurred,
877 we won't be doing the operation directly on the SUBREG. */
878 if (optimize > 0 && GET_CODE (from) == SUBREG)
879 from = force_reg (from_mode, from);
880 emit_unop_insn (code, to, from, equiv_code);
883 /* Next, try converting via full word. */
884 else if (GET_MODE_BITSIZE (from_mode) < BITS_PER_WORD
885 && ((code = can_extend_p (to_mode, word_mode, unsignedp))
886 != CODE_FOR_nothing))
888 if (GET_CODE (to) == REG)
889 emit_insn (gen_rtx_CLOBBER (VOIDmode, to));
890 convert_move (gen_lowpart (word_mode, to), from, unsignedp);
891 emit_unop_insn (code, to,
892 gen_lowpart (word_mode, to), equiv_code);
896 /* No special multiword conversion insn; do it by hand. */
899 /* Since we will turn this into a no conflict block, we must ensure
900 that the source does not overlap the target. */
902 if (reg_overlap_mentioned_p (to, from))
903 from = force_reg (from_mode, from);
905 /* Get a copy of FROM widened to a word, if necessary. */
906 if (GET_MODE_BITSIZE (from_mode) < BITS_PER_WORD)
907 lowpart_mode = word_mode;
909 lowpart_mode = from_mode;
911 lowfrom = convert_to_mode (lowpart_mode, from, unsignedp);
913 lowpart = gen_lowpart (lowpart_mode, to);
914 emit_move_insn (lowpart, lowfrom);
916 /* Compute the value to put in each remaining word. */
918 fill_value = const0_rtx;
923 && insn_data[(int) CODE_FOR_slt].operand[0].mode == word_mode
924 && STORE_FLAG_VALUE == -1)
926 emit_cmp_insn (lowfrom, const0_rtx, NE, NULL_RTX,
928 fill_value = gen_reg_rtx (word_mode);
929 emit_insn (gen_slt (fill_value));
935 = expand_shift (RSHIFT_EXPR, lowpart_mode, lowfrom,
936 size_int (GET_MODE_BITSIZE (lowpart_mode) - 1),
938 fill_value = convert_to_mode (word_mode, fill_value, 1);
942 /* Fill the remaining words. */
943 for (i = GET_MODE_SIZE (lowpart_mode) / UNITS_PER_WORD; i < nwords; i++)
945 int index = (WORDS_BIG_ENDIAN ? nwords - i - 1 : i);
946 rtx subword = operand_subword (to, index, 1, to_mode);
951 if (fill_value != subword)
952 emit_move_insn (subword, fill_value);
955 insns = get_insns ();
958 emit_no_conflict_block (insns, to, from, NULL_RTX,
959 gen_rtx_fmt_e (equiv_code, to_mode, copy_rtx (from)));
963 /* Truncating multi-word to a word or less. */
964 if (GET_MODE_BITSIZE (from_mode) > BITS_PER_WORD
965 && GET_MODE_BITSIZE (to_mode) <= BITS_PER_WORD)
967 if (!((GET_CODE (from) == MEM
968 && ! MEM_VOLATILE_P (from)
969 && direct_load[(int) to_mode]
970 && ! mode_dependent_address_p (XEXP (from, 0)))
971 || GET_CODE (from) == REG
972 || GET_CODE (from) == SUBREG))
973 from = force_reg (from_mode, from);
974 convert_move (to, gen_lowpart (word_mode, from), 0);
978 /* Handle pointer conversion. */ /* SPEE 900220. */
979 if (to_mode == PQImode)
981 if (from_mode != QImode)
982 from = convert_to_mode (QImode, from, unsignedp);
984 #ifdef HAVE_truncqipqi2
985 if (HAVE_truncqipqi2)
987 emit_unop_insn (CODE_FOR_truncqipqi2, to, from, UNKNOWN);
990 #endif /* HAVE_truncqipqi2 */
994 if (from_mode == PQImode)
996 if (to_mode != QImode)
998 from = convert_to_mode (QImode, from, unsignedp);
1003 #ifdef HAVE_extendpqiqi2
1004 if (HAVE_extendpqiqi2)
1006 emit_unop_insn (CODE_FOR_extendpqiqi2, to, from, UNKNOWN);
1009 #endif /* HAVE_extendpqiqi2 */
1014 if (to_mode == PSImode)
1016 if (from_mode != SImode)
1017 from = convert_to_mode (SImode, from, unsignedp);
1019 #ifdef HAVE_truncsipsi2
1020 if (HAVE_truncsipsi2)
1022 emit_unop_insn (CODE_FOR_truncsipsi2, to, from, UNKNOWN);
1025 #endif /* HAVE_truncsipsi2 */
1029 if (from_mode == PSImode)
1031 if (to_mode != SImode)
1033 from = convert_to_mode (SImode, from, unsignedp);
1038 #ifdef HAVE_extendpsisi2
1039 if (! unsignedp && HAVE_extendpsisi2)
1041 emit_unop_insn (CODE_FOR_extendpsisi2, to, from, UNKNOWN);
1044 #endif /* HAVE_extendpsisi2 */
1045 #ifdef HAVE_zero_extendpsisi2
1046 if (unsignedp && HAVE_zero_extendpsisi2)
1048 emit_unop_insn (CODE_FOR_zero_extendpsisi2, to, from, UNKNOWN);
1051 #endif /* HAVE_zero_extendpsisi2 */
1056 if (to_mode == PDImode)
1058 if (from_mode != DImode)
1059 from = convert_to_mode (DImode, from, unsignedp);
1061 #ifdef HAVE_truncdipdi2
1062 if (HAVE_truncdipdi2)
1064 emit_unop_insn (CODE_FOR_truncdipdi2, to, from, UNKNOWN);
1067 #endif /* HAVE_truncdipdi2 */
1071 if (from_mode == PDImode)
1073 if (to_mode != DImode)
1075 from = convert_to_mode (DImode, from, unsignedp);
1080 #ifdef HAVE_extendpdidi2
1081 if (HAVE_extendpdidi2)
1083 emit_unop_insn (CODE_FOR_extendpdidi2, to, from, UNKNOWN);
1086 #endif /* HAVE_extendpdidi2 */
1091 /* Now follow all the conversions between integers
1092 no more than a word long. */
1094 /* For truncation, usually we can just refer to FROM in a narrower mode. */
1095 if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode)
1096 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (to_mode),
1097 GET_MODE_BITSIZE (from_mode)))
1099 if (!((GET_CODE (from) == MEM
1100 && ! MEM_VOLATILE_P (from)
1101 && direct_load[(int) to_mode]
1102 && ! mode_dependent_address_p (XEXP (from, 0)))
1103 || GET_CODE (from) == REG
1104 || GET_CODE (from) == SUBREG))
1105 from = force_reg (from_mode, from);
1106 if (GET_CODE (from) == REG && REGNO (from) < FIRST_PSEUDO_REGISTER
1107 && ! HARD_REGNO_MODE_OK (REGNO (from), to_mode))
1108 from = copy_to_reg (from);
1109 emit_move_insn (to, gen_lowpart (to_mode, from));
1113 /* Handle extension. */
1114 if (GET_MODE_BITSIZE (to_mode) > GET_MODE_BITSIZE (from_mode))
1116 /* Convert directly if that works. */
1117 if ((code = can_extend_p (to_mode, from_mode, unsignedp))
1118 != CODE_FOR_nothing)
1121 from = force_not_mem (from);
1123 emit_unop_insn (code, to, from, equiv_code);
1128 enum machine_mode intermediate;
1132 /* Search for a mode to convert via. */
1133 for (intermediate = from_mode; intermediate != VOIDmode;
1134 intermediate = GET_MODE_WIDER_MODE (intermediate))
1135 if (((can_extend_p (to_mode, intermediate, unsignedp)
1136 != CODE_FOR_nothing)
1137 || (GET_MODE_SIZE (to_mode) < GET_MODE_SIZE (intermediate)
1138 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (to_mode),
1139 GET_MODE_BITSIZE (intermediate))))
1140 && (can_extend_p (intermediate, from_mode, unsignedp)
1141 != CODE_FOR_nothing))
1143 convert_move (to, convert_to_mode (intermediate, from,
1144 unsignedp), unsignedp);
1148 /* No suitable intermediate mode.
1149 Generate what we need with shifts. */
1150 shift_amount = build_int_2 (GET_MODE_BITSIZE (to_mode)
1151 - GET_MODE_BITSIZE (from_mode), 0);
1152 from = gen_lowpart (to_mode, force_reg (from_mode, from));
1153 tmp = expand_shift (LSHIFT_EXPR, to_mode, from, shift_amount,
1155 tmp = expand_shift (RSHIFT_EXPR, to_mode, tmp, shift_amount,
1158 emit_move_insn (to, tmp);
1163 /* Support special truncate insns for certain modes. */
1165 if (from_mode == DImode && to_mode == SImode)
1167 #ifdef HAVE_truncdisi2
1168 if (HAVE_truncdisi2)
1170 emit_unop_insn (CODE_FOR_truncdisi2, to, from, UNKNOWN);
1174 convert_move (to, force_reg (from_mode, from), unsignedp);
1178 if (from_mode == DImode && to_mode == HImode)
1180 #ifdef HAVE_truncdihi2
1181 if (HAVE_truncdihi2)
1183 emit_unop_insn (CODE_FOR_truncdihi2, to, from, UNKNOWN);
1187 convert_move (to, force_reg (from_mode, from), unsignedp);
1191 if (from_mode == DImode && to_mode == QImode)
1193 #ifdef HAVE_truncdiqi2
1194 if (HAVE_truncdiqi2)
1196 emit_unop_insn (CODE_FOR_truncdiqi2, to, from, UNKNOWN);
1200 convert_move (to, force_reg (from_mode, from), unsignedp);
1204 if (from_mode == SImode && to_mode == HImode)
1206 #ifdef HAVE_truncsihi2
1207 if (HAVE_truncsihi2)
1209 emit_unop_insn (CODE_FOR_truncsihi2, to, from, UNKNOWN);
1213 convert_move (to, force_reg (from_mode, from), unsignedp);
1217 if (from_mode == SImode && to_mode == QImode)
1219 #ifdef HAVE_truncsiqi2
1220 if (HAVE_truncsiqi2)
1222 emit_unop_insn (CODE_FOR_truncsiqi2, to, from, UNKNOWN);
1226 convert_move (to, force_reg (from_mode, from), unsignedp);
1230 if (from_mode == HImode && to_mode == QImode)
1232 #ifdef HAVE_trunchiqi2
1233 if (HAVE_trunchiqi2)
1235 emit_unop_insn (CODE_FOR_trunchiqi2, to, from, UNKNOWN);
1239 convert_move (to, force_reg (from_mode, from), unsignedp);
1243 if (from_mode == TImode && to_mode == DImode)
1245 #ifdef HAVE_trunctidi2
1246 if (HAVE_trunctidi2)
1248 emit_unop_insn (CODE_FOR_trunctidi2, to, from, UNKNOWN);
1252 convert_move (to, force_reg (from_mode, from), unsignedp);
1256 if (from_mode == TImode && to_mode == SImode)
1258 #ifdef HAVE_trunctisi2
1259 if (HAVE_trunctisi2)
1261 emit_unop_insn (CODE_FOR_trunctisi2, to, from, UNKNOWN);
1265 convert_move (to, force_reg (from_mode, from), unsignedp);
1269 if (from_mode == TImode && to_mode == HImode)
1271 #ifdef HAVE_trunctihi2
1272 if (HAVE_trunctihi2)
1274 emit_unop_insn (CODE_FOR_trunctihi2, to, from, UNKNOWN);
1278 convert_move (to, force_reg (from_mode, from), unsignedp);
1282 if (from_mode == TImode && to_mode == QImode)
1284 #ifdef HAVE_trunctiqi2
1285 if (HAVE_trunctiqi2)
1287 emit_unop_insn (CODE_FOR_trunctiqi2, to, from, UNKNOWN);
1291 convert_move (to, force_reg (from_mode, from), unsignedp);
1295 /* Handle truncation of volatile memrefs, and so on;
1296 the things that couldn't be truncated directly,
1297 and for which there was no special instruction. */
1298 if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode))
1300 rtx temp = force_reg (to_mode, gen_lowpart (to_mode, from));
1301 emit_move_insn (to, temp);
1305 /* Mode combination is not recognized. */
1309 /* Return an rtx for a value that would result
1310 from converting X to mode MODE.
1311 Both X and MODE may be floating, or both integer.
1312 UNSIGNEDP is nonzero if X is an unsigned value.
1313 This can be done by referring to a part of X in place
1314 or by copying to a new temporary with conversion.
1316 This function *must not* call protect_from_queue
1317 except when putting X into an insn (in which case convert_move does it). */
1320 convert_to_mode (mode, x, unsignedp)
1321 enum machine_mode mode;
1325 return convert_modes (mode, VOIDmode, x, unsignedp);
1328 /* Return an rtx for a value that would result
1329 from converting X from mode OLDMODE to mode MODE.
1330 Both modes may be floating, or both integer.
1331 UNSIGNEDP is nonzero if X is an unsigned value.
1333 This can be done by referring to a part of X in place
1334 or by copying to a new temporary with conversion.
1336 You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode.
1338 This function *must not* call protect_from_queue
1339 except when putting X into an insn (in which case convert_move does it). */
1342 convert_modes (mode, oldmode, x, unsignedp)
1343 enum machine_mode mode, oldmode;
1349 /* If FROM is a SUBREG that indicates that we have already done at least
1350 the required extension, strip it. */
1352 if (GET_CODE (x) == SUBREG && SUBREG_PROMOTED_VAR_P (x)
1353 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) >= GET_MODE_SIZE (mode)
1354 && SUBREG_PROMOTED_UNSIGNED_P (x) == unsignedp)
1355 x = gen_lowpart (mode, x);
1357 if (GET_MODE (x) != VOIDmode)
1358 oldmode = GET_MODE (x);
1360 if (mode == oldmode)
1363 /* There is one case that we must handle specially: If we are converting
1364 a CONST_INT into a mode whose size is twice HOST_BITS_PER_WIDE_INT and
1365 we are to interpret the constant as unsigned, gen_lowpart will do
1366 the wrong if the constant appears negative. What we want to do is
1367 make the high-order word of the constant zero, not all ones. */
1369 if (unsignedp && GET_MODE_CLASS (mode) == MODE_INT
1370 && GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT
1371 && GET_CODE (x) == CONST_INT && INTVAL (x) < 0)
1373 HOST_WIDE_INT val = INTVAL (x);
1375 if (oldmode != VOIDmode
1376 && HOST_BITS_PER_WIDE_INT > GET_MODE_BITSIZE (oldmode))
1378 int width = GET_MODE_BITSIZE (oldmode);
1380 /* We need to zero extend VAL. */
1381 val &= ((HOST_WIDE_INT) 1 << width) - 1;
1384 return immed_double_const (val, (HOST_WIDE_INT) 0, mode);
1387 /* We can do this with a gen_lowpart if both desired and current modes
1388 are integer, and this is either a constant integer, a register, or a
1389 non-volatile MEM. Except for the constant case where MODE is no
1390 wider than HOST_BITS_PER_WIDE_INT, we must be narrowing the operand. */
1392 if ((GET_CODE (x) == CONST_INT
1393 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
1394 || (GET_MODE_CLASS (mode) == MODE_INT
1395 && GET_MODE_CLASS (oldmode) == MODE_INT
1396 && (GET_CODE (x) == CONST_DOUBLE
1397 || (GET_MODE_SIZE (mode) <= GET_MODE_SIZE (oldmode)
1398 && ((GET_CODE (x) == MEM && ! MEM_VOLATILE_P (x)
1399 && direct_load[(int) mode])
1400 || (GET_CODE (x) == REG
1401 && (! HARD_REGISTER_P (x)
1402 || HARD_REGNO_MODE_OK (REGNO (x), mode))
1403 && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (mode),
1404 GET_MODE_BITSIZE (GET_MODE (x)))))))))
1406 /* ?? If we don't know OLDMODE, we have to assume here that
1407 X does not need sign- or zero-extension. This may not be
1408 the case, but it's the best we can do. */
1409 if (GET_CODE (x) == CONST_INT && oldmode != VOIDmode
1410 && GET_MODE_SIZE (mode) > GET_MODE_SIZE (oldmode))
1412 HOST_WIDE_INT val = INTVAL (x);
1413 int width = GET_MODE_BITSIZE (oldmode);
1415 /* We must sign or zero-extend in this case. Start by
1416 zero-extending, then sign extend if we need to. */
1417 val &= ((HOST_WIDE_INT) 1 << width) - 1;
1419 && (val & ((HOST_WIDE_INT) 1 << (width - 1))))
1420 val |= (HOST_WIDE_INT) (-1) << width;
1422 return gen_int_mode (val, mode);
1425 return gen_lowpart (mode, x);
1428 /* Converting from integer constant into mode is always equivalent to an
1429 subreg operation. */
1430 if (VECTOR_MODE_P (mode) && GET_MODE (x) == VOIDmode)
1432 if (GET_MODE_BITSIZE (mode) != GET_MODE_BITSIZE (oldmode))
1434 return simplify_gen_subreg (mode, x, oldmode, 0);
1437 temp = gen_reg_rtx (mode);
1438 convert_move (temp, x, unsignedp);
1442 /* This macro is used to determine what the largest unit size that
1443 move_by_pieces can use is. */
1445 /* MOVE_MAX_PIECES is the number of bytes at a time which we can
1446 move efficiently, as opposed to MOVE_MAX which is the maximum
1447 number of bytes we can move with a single instruction. */
1449 #ifndef MOVE_MAX_PIECES
1450 #define MOVE_MAX_PIECES MOVE_MAX
1453 /* STORE_MAX_PIECES is the number of bytes at a time that we can
1454 store efficiently. Due to internal GCC limitations, this is
1455 MOVE_MAX_PIECES limited by the number of bytes GCC can represent
1456 for an immediate constant. */
1458 #define STORE_MAX_PIECES MIN (MOVE_MAX_PIECES, 2 * sizeof (HOST_WIDE_INT))
1460 /* Generate several move instructions to copy LEN bytes from block FROM to
1461 block TO. (These are MEM rtx's with BLKmode). The caller must pass FROM
1462 and TO through protect_from_queue before calling.
1464 If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
1465 used to push FROM to the stack.
1467 ALIGN is maximum alignment we can assume. */
1470 move_by_pieces (to, from, len, align)
1472 unsigned HOST_WIDE_INT len;
1475 struct move_by_pieces data;
1476 rtx to_addr, from_addr = XEXP (from, 0);
1477 unsigned int max_size = MOVE_MAX_PIECES + 1;
1478 enum machine_mode mode = VOIDmode, tmode;
1479 enum insn_code icode;
1482 data.from_addr = from_addr;
1485 to_addr = XEXP (to, 0);
1488 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
1489 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
1491 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
1498 #ifdef STACK_GROWS_DOWNWARD
1504 data.to_addr = to_addr;
1507 = (GET_CODE (from_addr) == PRE_INC || GET_CODE (from_addr) == PRE_DEC
1508 || GET_CODE (from_addr) == POST_INC
1509 || GET_CODE (from_addr) == POST_DEC);
1511 data.explicit_inc_from = 0;
1512 data.explicit_inc_to = 0;
1513 if (data.reverse) data.offset = len;
1516 /* If copying requires more than two move insns,
1517 copy addresses to registers (to make displacements shorter)
1518 and use post-increment if available. */
1519 if (!(data.autinc_from && data.autinc_to)
1520 && move_by_pieces_ninsns (len, align) > 2)
1522 /* Find the mode of the largest move... */
1523 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
1524 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
1525 if (GET_MODE_SIZE (tmode) < max_size)
1528 if (USE_LOAD_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_from)
1530 data.from_addr = copy_addr_to_reg (plus_constant (from_addr, len));
1531 data.autinc_from = 1;
1532 data.explicit_inc_from = -1;
1534 if (USE_LOAD_POST_INCREMENT (mode) && ! data.autinc_from)
1536 data.from_addr = copy_addr_to_reg (from_addr);
1537 data.autinc_from = 1;
1538 data.explicit_inc_from = 1;
1540 if (!data.autinc_from && CONSTANT_P (from_addr))
1541 data.from_addr = copy_addr_to_reg (from_addr);
1542 if (USE_STORE_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_to)
1544 data.to_addr = copy_addr_to_reg (plus_constant (to_addr, len));
1546 data.explicit_inc_to = -1;
1548 if (USE_STORE_POST_INCREMENT (mode) && ! data.reverse && ! data.autinc_to)
1550 data.to_addr = copy_addr_to_reg (to_addr);
1552 data.explicit_inc_to = 1;
1554 if (!data.autinc_to && CONSTANT_P (to_addr))
1555 data.to_addr = copy_addr_to_reg (to_addr);
1558 if (! SLOW_UNALIGNED_ACCESS (word_mode, align)
1559 || align > MOVE_MAX * BITS_PER_UNIT || align >= BIGGEST_ALIGNMENT)
1560 align = MOVE_MAX * BITS_PER_UNIT;
1562 /* First move what we can in the largest integer mode, then go to
1563 successively smaller modes. */
1565 while (max_size > 1)
1567 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
1568 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
1569 if (GET_MODE_SIZE (tmode) < max_size)
1572 if (mode == VOIDmode)
1575 icode = mov_optab->handlers[(int) mode].insn_code;
1576 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
1577 move_by_pieces_1 (GEN_FCN (icode), mode, &data);
1579 max_size = GET_MODE_SIZE (mode);
1582 /* The code above should have handled everything. */
1587 /* Return number of insns required to move L bytes by pieces.
1588 ALIGN (in bits) is maximum alignment we can assume. */
1590 static unsigned HOST_WIDE_INT
1591 move_by_pieces_ninsns (l, align)
1592 unsigned HOST_WIDE_INT l;
1595 unsigned HOST_WIDE_INT n_insns = 0;
1596 unsigned HOST_WIDE_INT max_size = MOVE_MAX + 1;
1598 if (! SLOW_UNALIGNED_ACCESS (word_mode, align)
1599 || align > MOVE_MAX * BITS_PER_UNIT || align >= BIGGEST_ALIGNMENT)
1600 align = MOVE_MAX * BITS_PER_UNIT;
1602 while (max_size > 1)
1604 enum machine_mode mode = VOIDmode, tmode;
1605 enum insn_code icode;
1607 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
1608 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
1609 if (GET_MODE_SIZE (tmode) < max_size)
1612 if (mode == VOIDmode)
1615 icode = mov_optab->handlers[(int) mode].insn_code;
1616 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
1617 n_insns += l / GET_MODE_SIZE (mode), l %= GET_MODE_SIZE (mode);
1619 max_size = GET_MODE_SIZE (mode);
1627 /* Subroutine of move_by_pieces. Move as many bytes as appropriate
1628 with move instructions for mode MODE. GENFUN is the gen_... function
1629 to make a move insn for that mode. DATA has all the other info. */
1632 move_by_pieces_1 (genfun, mode, data)
1633 rtx (*genfun) PARAMS ((rtx, ...));
1634 enum machine_mode mode;
1635 struct move_by_pieces *data;
1637 unsigned int size = GET_MODE_SIZE (mode);
1638 rtx to1 = NULL_RTX, from1;
1640 while (data->len >= size)
1643 data->offset -= size;
1647 if (data->autinc_to)
1648 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
1651 to1 = adjust_address (data->to, mode, data->offset);
1654 if (data->autinc_from)
1655 from1 = adjust_automodify_address (data->from, mode, data->from_addr,
1658 from1 = adjust_address (data->from, mode, data->offset);
1660 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
1661 emit_insn (gen_add2_insn (data->to_addr,
1662 GEN_INT (-(HOST_WIDE_INT)size)));
1663 if (HAVE_PRE_DECREMENT && data->explicit_inc_from < 0)
1664 emit_insn (gen_add2_insn (data->from_addr,
1665 GEN_INT (-(HOST_WIDE_INT)size)));
1668 emit_insn ((*genfun) (to1, from1));
1671 #ifdef PUSH_ROUNDING
1672 emit_single_push_insn (mode, from1, NULL);
1678 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
1679 emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
1680 if (HAVE_POST_INCREMENT && data->explicit_inc_from > 0)
1681 emit_insn (gen_add2_insn (data->from_addr, GEN_INT (size)));
1683 if (! data->reverse)
1684 data->offset += size;
1690 /* Emit code to move a block Y to a block X. This may be done with
1691 string-move instructions, with multiple scalar move instructions,
1692 or with a library call.
1694 Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1695 SIZE is an rtx that says how long they are.
1696 ALIGN is the maximum alignment we can assume they have.
1697 METHOD describes what kind of copy this is, and what mechanisms may be used.
1699 Return the address of the new block, if memcpy is called and returns it,
1703 emit_block_move (x, y, size, method)
1705 enum block_op_methods method;
1713 case BLOCK_OP_NORMAL:
1714 may_use_call = true;
1717 case BLOCK_OP_CALL_PARM:
1718 may_use_call = block_move_libcall_safe_for_call_parm ();
1720 /* Make inhibit_defer_pop nonzero around the library call
1721 to force it to pop the arguments right away. */
1725 case BLOCK_OP_NO_LIBCALL:
1726 may_use_call = false;
1733 align = MIN (MEM_ALIGN (x), MEM_ALIGN (y));
1735 if (GET_MODE (x) != BLKmode)
1737 if (GET_MODE (y) != BLKmode)
1740 x = protect_from_queue (x, 1);
1741 y = protect_from_queue (y, 0);
1742 size = protect_from_queue (size, 0);
1744 if (GET_CODE (x) != MEM)
1746 if (GET_CODE (y) != MEM)
1751 /* Set MEM_SIZE as appropriate for this block copy. The main place this
1752 can be incorrect is coming from __builtin_memcpy. */
1753 if (GET_CODE (size) == CONST_INT)
1755 x = shallow_copy_rtx (x);
1756 y = shallow_copy_rtx (y);
1757 set_mem_size (x, size);
1758 set_mem_size (y, size);
1761 if (GET_CODE (size) == CONST_INT && MOVE_BY_PIECES_P (INTVAL (size), align))
1762 move_by_pieces (x, y, INTVAL (size), align);
1763 else if (emit_block_move_via_movstr (x, y, size, align))
1765 else if (may_use_call)
1766 retval = emit_block_move_via_libcall (x, y, size);
1768 emit_block_move_via_loop (x, y, size, align);
1770 if (method == BLOCK_OP_CALL_PARM)
1776 /* A subroutine of emit_block_move. Returns true if calling the
1777 block move libcall will not clobber any parameters which may have
1778 already been placed on the stack. */
1781 block_move_libcall_safe_for_call_parm ()
1787 /* Check to see whether memcpy takes all register arguments. */
1789 takes_regs_uninit, takes_regs_no, takes_regs_yes
1790 } takes_regs = takes_regs_uninit;
1794 case takes_regs_uninit:
1796 CUMULATIVE_ARGS args_so_far;
1799 fn = emit_block_move_libcall_fn (false);
1800 INIT_CUMULATIVE_ARGS (args_so_far, TREE_TYPE (fn), NULL_RTX, 0);
1802 arg = TYPE_ARG_TYPES (TREE_TYPE (fn));
1803 for ( ; arg != void_list_node ; arg = TREE_CHAIN (arg))
1805 enum machine_mode mode = TYPE_MODE (TREE_VALUE (arg));
1806 rtx tmp = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
1807 if (!tmp || !REG_P (tmp))
1808 goto fail_takes_regs;
1809 #ifdef FUNCTION_ARG_PARTIAL_NREGS
1810 if (FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode,
1812 goto fail_takes_regs;
1814 FUNCTION_ARG_ADVANCE (args_so_far, mode, NULL_TREE, 1);
1817 takes_regs = takes_regs_yes;
1820 case takes_regs_yes:
1824 takes_regs = takes_regs_no;
1835 /* A subroutine of emit_block_move. Expand a movstr pattern;
1836 return true if successful. */
1839 emit_block_move_via_movstr (x, y, size, align)
1843 /* Try the most limited insn first, because there's no point
1844 including more than one in the machine description unless
1845 the more limited one has some advantage. */
1847 rtx opalign = GEN_INT (align / BITS_PER_UNIT);
1848 enum machine_mode mode;
1850 /* Since this is a move insn, we don't care about volatility. */
1853 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1854 mode = GET_MODE_WIDER_MODE (mode))
1856 enum insn_code code = movstr_optab[(int) mode];
1857 insn_operand_predicate_fn pred;
1859 if (code != CODE_FOR_nothing
1860 /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1861 here because if SIZE is less than the mode mask, as it is
1862 returned by the macro, it will definitely be less than the
1863 actual mode mask. */
1864 && ((GET_CODE (size) == CONST_INT
1865 && ((unsigned HOST_WIDE_INT) INTVAL (size)
1866 <= (GET_MODE_MASK (mode) >> 1)))
1867 || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD)
1868 && ((pred = insn_data[(int) code].operand[0].predicate) == 0
1869 || (*pred) (x, BLKmode))
1870 && ((pred = insn_data[(int) code].operand[1].predicate) == 0
1871 || (*pred) (y, BLKmode))
1872 && ((pred = insn_data[(int) code].operand[3].predicate) == 0
1873 || (*pred) (opalign, VOIDmode)))
1876 rtx last = get_last_insn ();
1879 op2 = convert_to_mode (mode, size, 1);
1880 pred = insn_data[(int) code].operand[2].predicate;
1881 if (pred != 0 && ! (*pred) (op2, mode))
1882 op2 = copy_to_mode_reg (mode, op2);
1884 /* ??? When called via emit_block_move_for_call, it'd be
1885 nice if there were some way to inform the backend, so
1886 that it doesn't fail the expansion because it thinks
1887 emitting the libcall would be more efficient. */
1889 pat = GEN_FCN ((int) code) (x, y, op2, opalign);
1897 delete_insns_since (last);
1905 /* A subroutine of emit_block_move. Expand a call to memcpy or bcopy.
1906 Return the return value from memcpy, 0 otherwise. */
1909 emit_block_move_via_libcall (dst, src, size)
1912 tree call_expr, arg_list, fn, src_tree, dst_tree, size_tree;
1913 enum machine_mode size_mode;
1916 /* DST, SRC, or SIZE may have been passed through protect_from_queue.
1918 It is unsafe to save the value generated by protect_from_queue
1919 and reuse it later. Consider what happens if emit_queue is
1920 called before the return value from protect_from_queue is used.
1922 Expansion of the CALL_EXPR below will call emit_queue before
1923 we are finished emitting RTL for argument setup. So if we are
1924 not careful we could get the wrong value for an argument.
1926 To avoid this problem we go ahead and emit code to copy X, Y &
1927 SIZE into new pseudos. We can then place those new pseudos
1928 into an RTL_EXPR and use them later, even after a call to
1931 Note this is not strictly needed for library calls since they
1932 do not call emit_queue before loading their arguments. However,
1933 we may need to have library calls call emit_queue in the future
1934 since failing to do so could cause problems for targets which
1935 define SMALL_REGISTER_CLASSES and pass arguments in registers. */
1937 dst = copy_to_mode_reg (Pmode, XEXP (dst, 0));
1938 src = copy_to_mode_reg (Pmode, XEXP (src, 0));
1940 if (TARGET_MEM_FUNCTIONS)
1941 size_mode = TYPE_MODE (sizetype);
1943 size_mode = TYPE_MODE (unsigned_type_node);
1944 size = convert_to_mode (size_mode, size, 1);
1945 size = copy_to_mode_reg (size_mode, size);
1947 /* It is incorrect to use the libcall calling conventions to call
1948 memcpy in this context. This could be a user call to memcpy and
1949 the user may wish to examine the return value from memcpy. For
1950 targets where libcalls and normal calls have different conventions
1951 for returning pointers, we could end up generating incorrect code.
1953 For convenience, we generate the call to bcopy this way as well. */
1955 dst_tree = make_tree (ptr_type_node, dst);
1956 src_tree = make_tree (ptr_type_node, src);
1957 if (TARGET_MEM_FUNCTIONS)
1958 size_tree = make_tree (sizetype, size);
1960 size_tree = make_tree (unsigned_type_node, size);
1962 fn = emit_block_move_libcall_fn (true);
1963 arg_list = tree_cons (NULL_TREE, size_tree, NULL_TREE);
1964 if (TARGET_MEM_FUNCTIONS)
1966 arg_list = tree_cons (NULL_TREE, src_tree, arg_list);
1967 arg_list = tree_cons (NULL_TREE, dst_tree, arg_list);
1971 arg_list = tree_cons (NULL_TREE, dst_tree, arg_list);
1972 arg_list = tree_cons (NULL_TREE, src_tree, arg_list);
1975 /* Now we have to build up the CALL_EXPR itself. */
1976 call_expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (fn)), fn);
1977 call_expr = build (CALL_EXPR, TREE_TYPE (TREE_TYPE (fn)),
1978 call_expr, arg_list, NULL_TREE);
1979 TREE_SIDE_EFFECTS (call_expr) = 1;
1981 retval = expand_expr (call_expr, NULL_RTX, VOIDmode, 0);
1983 /* If we are initializing a readonly value, show the above call
1984 clobbered it. Otherwise, a load from it may erroneously be
1985 hoisted from a loop. */
1986 if (RTX_UNCHANGING_P (dst))
1987 emit_insn (gen_rtx_CLOBBER (VOIDmode, dst));
1989 return (TARGET_MEM_FUNCTIONS ? retval : NULL_RTX);
1992 /* A subroutine of emit_block_move_via_libcall. Create the tree node
1993 for the function we use for block copies. The first time FOR_CALL
1994 is true, we call assemble_external. */
1996 static GTY(()) tree block_move_fn;
1999 emit_block_move_libcall_fn (for_call)
2002 static bool emitted_extern;
2003 tree fn = block_move_fn, args;
2007 if (TARGET_MEM_FUNCTIONS)
2009 fn = get_identifier ("memcpy");
2010 args = build_function_type_list (ptr_type_node, ptr_type_node,
2011 const_ptr_type_node, sizetype,
2016 fn = get_identifier ("bcopy");
2017 args = build_function_type_list (void_type_node, const_ptr_type_node,
2018 ptr_type_node, unsigned_type_node,
2022 fn = build_decl (FUNCTION_DECL, fn, args);
2023 DECL_EXTERNAL (fn) = 1;
2024 TREE_PUBLIC (fn) = 1;
2025 DECL_ARTIFICIAL (fn) = 1;
2026 TREE_NOTHROW (fn) = 1;
2031 if (for_call && !emitted_extern)
2033 emitted_extern = true;
2034 make_decl_rtl (fn, NULL);
2035 assemble_external (fn);
2041 /* A subroutine of emit_block_move. Copy the data via an explicit
2042 loop. This is used only when libcalls are forbidden. */
2043 /* ??? It'd be nice to copy in hunks larger than QImode. */
2046 emit_block_move_via_loop (x, y, size, align)
2048 unsigned int align ATTRIBUTE_UNUSED;
2050 rtx cmp_label, top_label, iter, x_addr, y_addr, tmp;
2051 enum machine_mode iter_mode;
2053 iter_mode = GET_MODE (size);
2054 if (iter_mode == VOIDmode)
2055 iter_mode = word_mode;
2057 top_label = gen_label_rtx ();
2058 cmp_label = gen_label_rtx ();
2059 iter = gen_reg_rtx (iter_mode);
2061 emit_move_insn (iter, const0_rtx);
2063 x_addr = force_operand (XEXP (x, 0), NULL_RTX);
2064 y_addr = force_operand (XEXP (y, 0), NULL_RTX);
2065 do_pending_stack_adjust ();
2067 emit_note (NULL, NOTE_INSN_LOOP_BEG);
2069 emit_jump (cmp_label);
2070 emit_label (top_label);
2072 tmp = convert_modes (Pmode, iter_mode, iter, true);
2073 x_addr = gen_rtx_PLUS (Pmode, x_addr, tmp);
2074 y_addr = gen_rtx_PLUS (Pmode, y_addr, tmp);
2075 x = change_address (x, QImode, x_addr);
2076 y = change_address (y, QImode, y_addr);
2078 emit_move_insn (x, y);
2080 tmp = expand_simple_binop (iter_mode, PLUS, iter, const1_rtx, iter,
2081 true, OPTAB_LIB_WIDEN);
2083 emit_move_insn (iter, tmp);
2085 emit_note (NULL, NOTE_INSN_LOOP_CONT);
2086 emit_label (cmp_label);
2088 emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
2091 emit_note (NULL, NOTE_INSN_LOOP_END);
2094 /* Copy all or part of a value X into registers starting at REGNO.
2095 The number of registers to be filled is NREGS. */
2098 move_block_to_reg (regno, x, nregs, mode)
2102 enum machine_mode mode;
2105 #ifdef HAVE_load_multiple
2113 if (CONSTANT_P (x) && ! LEGITIMATE_CONSTANT_P (x))
2114 x = validize_mem (force_const_mem (mode, x));
2116 /* See if the machine can do this with a load multiple insn. */
2117 #ifdef HAVE_load_multiple
2118 if (HAVE_load_multiple)
2120 last = get_last_insn ();
2121 pat = gen_load_multiple (gen_rtx_REG (word_mode, regno), x,
2129 delete_insns_since (last);
2133 for (i = 0; i < nregs; i++)
2134 emit_move_insn (gen_rtx_REG (word_mode, regno + i),
2135 operand_subword_force (x, i, mode));
2138 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
2139 The number of registers to be filled is NREGS. SIZE indicates the number
2140 of bytes in the object X. */
2143 move_block_from_reg (regno, x, nregs, size)
2150 #ifdef HAVE_store_multiple
2154 enum machine_mode mode;
2159 /* If SIZE is that of a mode no bigger than a word, just use that
2160 mode's store operation. */
2161 if (size <= UNITS_PER_WORD
2162 && (mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0)) != BLKmode)
2164 emit_move_insn (adjust_address (x, mode, 0), gen_rtx_REG (mode, regno));
2168 /* Blocks smaller than a word on a BYTES_BIG_ENDIAN machine must be aligned
2169 to the left before storing to memory. Note that the previous test
2170 doesn't handle all cases (e.g. SIZE == 3). */
2171 if (size < UNITS_PER_WORD && BYTES_BIG_ENDIAN)
2173 rtx tem = operand_subword (x, 0, 1, BLKmode);
2179 shift = expand_shift (LSHIFT_EXPR, word_mode,
2180 gen_rtx_REG (word_mode, regno),
2181 build_int_2 ((UNITS_PER_WORD - size)
2182 * BITS_PER_UNIT, 0), NULL_RTX, 0);
2183 emit_move_insn (tem, shift);
2187 /* See if the machine can do this with a store multiple insn. */
2188 #ifdef HAVE_store_multiple
2189 if (HAVE_store_multiple)
2191 last = get_last_insn ();
2192 pat = gen_store_multiple (x, gen_rtx_REG (word_mode, regno),
2200 delete_insns_since (last);
2204 for (i = 0; i < nregs; i++)
2206 rtx tem = operand_subword (x, i, 1, BLKmode);
2211 emit_move_insn (tem, gen_rtx_REG (word_mode, regno + i));
2215 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
2216 ORIG, where ORIG is a non-consecutive group of registers represented by
2217 a PARALLEL. The clone is identical to the original except in that the
2218 original set of registers is replaced by a new set of pseudo registers.
2219 The new set has the same modes as the original set. */
2222 gen_group_rtx (orig)
2228 if (GET_CODE (orig) != PARALLEL)
2231 length = XVECLEN (orig, 0);
2232 tmps = (rtx *) alloca (sizeof (rtx) * length);
2234 /* Skip a NULL entry in first slot. */
2235 i = XEXP (XVECEXP (orig, 0, 0), 0) ? 0 : 1;
2240 for (; i < length; i++)
2242 enum machine_mode mode = GET_MODE (XEXP (XVECEXP (orig, 0, i), 0));
2243 rtx offset = XEXP (XVECEXP (orig, 0, i), 1);
2245 tmps[i] = gen_rtx_EXPR_LIST (VOIDmode, gen_reg_rtx (mode), offset);
2248 return gen_rtx_PARALLEL (GET_MODE (orig), gen_rtvec_v (length, tmps));
2251 /* Emit code to move a block SRC to a block DST, where DST is non-consecutive
2252 registers represented by a PARALLEL. SSIZE represents the total size of
2253 block SRC in bytes, or -1 if not known. */
2254 /* ??? If SSIZE % UNITS_PER_WORD != 0, we make the blatant assumption that
2255 the balance will be in what would be the low-order memory addresses, i.e.
2256 left justified for big endian, right justified for little endian. This
2257 happens to be true for the targets currently using this support. If this
2258 ever changes, a new target macro along the lines of FUNCTION_ARG_PADDING
2262 emit_group_load (dst, orig_src, ssize)
2269 if (GET_CODE (dst) != PARALLEL)
2272 /* Check for a NULL entry, used to indicate that the parameter goes
2273 both on the stack and in registers. */
2274 if (XEXP (XVECEXP (dst, 0, 0), 0))
2279 tmps = (rtx *) alloca (sizeof (rtx) * XVECLEN (dst, 0));
2281 /* Process the pieces. */
2282 for (i = start; i < XVECLEN (dst, 0); i++)
2284 enum machine_mode mode = GET_MODE (XEXP (XVECEXP (dst, 0, i), 0));
2285 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (dst, 0, i), 1));
2286 unsigned int bytelen = GET_MODE_SIZE (mode);
2289 /* Handle trailing fragments that run over the size of the struct. */
2290 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
2292 shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
2293 bytelen = ssize - bytepos;
2298 /* If we won't be loading directly from memory, protect the real source
2299 from strange tricks we might play; but make sure that the source can
2300 be loaded directly into the destination. */
2302 if (GET_CODE (orig_src) != MEM
2303 && (!CONSTANT_P (orig_src)
2304 || (GET_MODE (orig_src) != mode
2305 && GET_MODE (orig_src) != VOIDmode)))
2307 if (GET_MODE (orig_src) == VOIDmode)
2308 src = gen_reg_rtx (mode);
2310 src = gen_reg_rtx (GET_MODE (orig_src));
2312 emit_move_insn (src, orig_src);
2315 /* Optimize the access just a bit. */
2316 if (GET_CODE (src) == MEM
2317 && MEM_ALIGN (src) >= GET_MODE_ALIGNMENT (mode)
2318 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
2319 && bytelen == GET_MODE_SIZE (mode))
2321 tmps[i] = gen_reg_rtx (mode);
2322 emit_move_insn (tmps[i], adjust_address (src, mode, bytepos));
2324 else if (GET_CODE (src) == CONCAT)
2326 unsigned int slen = GET_MODE_SIZE (GET_MODE (src));
2327 unsigned int slen0 = GET_MODE_SIZE (GET_MODE (XEXP (src, 0)));
2329 if ((bytepos == 0 && bytelen == slen0)
2330 || (bytepos != 0 && bytepos + bytelen <= slen))
2332 /* The following assumes that the concatenated objects all
2333 have the same size. In this case, a simple calculation
2334 can be used to determine the object and the bit field
2336 tmps[i] = XEXP (src, bytepos / slen0);
2337 if (! CONSTANT_P (tmps[i])
2338 && (GET_CODE (tmps[i]) != REG || GET_MODE (tmps[i]) != mode))
2339 tmps[i] = extract_bit_field (tmps[i], bytelen * BITS_PER_UNIT,
2340 (bytepos % slen0) * BITS_PER_UNIT,
2341 1, NULL_RTX, mode, mode, ssize);
2343 else if (bytepos == 0)
2345 rtx mem = assign_stack_temp (GET_MODE (src), slen, 0);
2346 emit_move_insn (mem, src);
2347 tmps[i] = adjust_address (mem, mode, 0);
2352 else if (CONSTANT_P (src)
2353 || (GET_CODE (src) == REG && GET_MODE (src) == mode))
2356 tmps[i] = extract_bit_field (src, bytelen * BITS_PER_UNIT,
2357 bytepos * BITS_PER_UNIT, 1, NULL_RTX,
2360 if (BYTES_BIG_ENDIAN && shift)
2361 expand_binop (mode, ashl_optab, tmps[i], GEN_INT (shift),
2362 tmps[i], 0, OPTAB_WIDEN);
2367 /* Copy the extracted pieces into the proper (probable) hard regs. */
2368 for (i = start; i < XVECLEN (dst, 0); i++)
2369 emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0), tmps[i]);
2372 /* Emit code to move a block SRC to block DST, where SRC and DST are
2373 non-consecutive groups of registers, each represented by a PARALLEL. */
2376 emit_group_move (dst, src)
2381 if (GET_CODE (src) != PARALLEL
2382 || GET_CODE (dst) != PARALLEL
2383 || XVECLEN (src, 0) != XVECLEN (dst, 0))
2386 /* Skip first entry if NULL. */
2387 for (i = XEXP (XVECEXP (src, 0, 0), 0) ? 0 : 1; i < XVECLEN (src, 0); i++)
2388 emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0),
2389 XEXP (XVECEXP (src, 0, i), 0));
2392 /* Emit code to move a block SRC to a block DST, where SRC is non-consecutive
2393 registers represented by a PARALLEL. SSIZE represents the total size of
2394 block DST, or -1 if not known. */
2397 emit_group_store (orig_dst, src, ssize)
2404 if (GET_CODE (src) != PARALLEL)
2407 /* Check for a NULL entry, used to indicate that the parameter goes
2408 both on the stack and in registers. */
2409 if (XEXP (XVECEXP (src, 0, 0), 0))
2414 tmps = (rtx *) alloca (sizeof (rtx) * XVECLEN (src, 0));
2416 /* Copy the (probable) hard regs into pseudos. */
2417 for (i = start; i < XVECLEN (src, 0); i++)
2419 rtx reg = XEXP (XVECEXP (src, 0, i), 0);
2420 tmps[i] = gen_reg_rtx (GET_MODE (reg));
2421 emit_move_insn (tmps[i], reg);
2425 /* If we won't be storing directly into memory, protect the real destination
2426 from strange tricks we might play. */
2428 if (GET_CODE (dst) == PARALLEL)
2432 /* We can get a PARALLEL dst if there is a conditional expression in
2433 a return statement. In that case, the dst and src are the same,
2434 so no action is necessary. */
2435 if (rtx_equal_p (dst, src))
2438 /* It is unclear if we can ever reach here, but we may as well handle
2439 it. Allocate a temporary, and split this into a store/load to/from
2442 temp = assign_stack_temp (GET_MODE (dst), ssize, 0);
2443 emit_group_store (temp, src, ssize);
2444 emit_group_load (dst, temp, ssize);
2447 else if (GET_CODE (dst) != MEM && GET_CODE (dst) != CONCAT)
2449 dst = gen_reg_rtx (GET_MODE (orig_dst));
2450 /* Make life a bit easier for combine. */
2451 emit_move_insn (dst, CONST0_RTX (GET_MODE (orig_dst)));
2454 /* Process the pieces. */
2455 for (i = start; i < XVECLEN (src, 0); i++)
2457 HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (src, 0, i), 1));
2458 enum machine_mode mode = GET_MODE (tmps[i]);
2459 unsigned int bytelen = GET_MODE_SIZE (mode);
2462 /* Handle trailing fragments that run over the size of the struct. */
2463 if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
2465 if (BYTES_BIG_ENDIAN)
2467 int shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
2468 expand_binop (mode, ashr_optab, tmps[i], GEN_INT (shift),
2469 tmps[i], 0, OPTAB_WIDEN);
2471 bytelen = ssize - bytepos;
2474 if (GET_CODE (dst) == CONCAT)
2476 if (bytepos + bytelen <= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
2477 dest = XEXP (dst, 0);
2478 else if (bytepos >= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
2480 bytepos -= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)));
2481 dest = XEXP (dst, 1);
2483 else if (bytepos == 0 && XVECLEN (src, 0))
2485 dest = assign_stack_temp (GET_MODE (dest),
2486 GET_MODE_SIZE (GET_MODE (dest)), 0);
2487 emit_move_insn (adjust_address (dest, GET_MODE (tmps[i]), bytepos),
2496 /* Optimize the access just a bit. */
2497 if (GET_CODE (dest) == MEM
2498 && MEM_ALIGN (dest) >= GET_MODE_ALIGNMENT (mode)
2499 && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
2500 && bytelen == GET_MODE_SIZE (mode))
2501 emit_move_insn (adjust_address (dest, mode, bytepos), tmps[i]);
2503 store_bit_field (dest, bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
2504 mode, tmps[i], ssize);
2509 /* Copy from the pseudo into the (probable) hard reg. */
2510 if (orig_dst != dst)
2511 emit_move_insn (orig_dst, dst);
2514 /* Generate code to copy a BLKmode object of TYPE out of a
2515 set of registers starting with SRCREG into TGTBLK. If TGTBLK
2516 is null, a stack temporary is created. TGTBLK is returned.
2518 The primary purpose of this routine is to handle functions
2519 that return BLKmode structures in registers. Some machines
2520 (the PA for example) want to return all small structures
2521 in registers regardless of the structure's alignment. */
2524 copy_blkmode_from_reg (tgtblk, srcreg, type)
2529 unsigned HOST_WIDE_INT bytes = int_size_in_bytes (type);
2530 rtx src = NULL, dst = NULL;
2531 unsigned HOST_WIDE_INT bitsize = MIN (TYPE_ALIGN (type), BITS_PER_WORD);
2532 unsigned HOST_WIDE_INT bitpos, xbitpos, big_endian_correction = 0;
2536 tgtblk = assign_temp (build_qualified_type (type,
2538 | TYPE_QUAL_CONST)),
2540 preserve_temp_slots (tgtblk);
2543 /* This code assumes srcreg is at least a full word. If it isn't, copy it
2544 into a new pseudo which is a full word. */
2546 if (GET_MODE (srcreg) != BLKmode
2547 && GET_MODE_SIZE (GET_MODE (srcreg)) < UNITS_PER_WORD)
2548 srcreg = convert_to_mode (word_mode, srcreg, TREE_UNSIGNED (type));
2550 /* Structures whose size is not a multiple of a word are aligned
2551 to the least significant byte (to the right). On a BYTES_BIG_ENDIAN
2552 machine, this means we must skip the empty high order bytes when
2553 calculating the bit offset. */
2554 if (BYTES_BIG_ENDIAN
2555 && bytes % UNITS_PER_WORD)
2556 big_endian_correction
2557 = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD) * BITS_PER_UNIT));
2559 /* Copy the structure BITSIZE bites at a time.
2561 We could probably emit more efficient code for machines which do not use
2562 strict alignment, but it doesn't seem worth the effort at the current
2564 for (bitpos = 0, xbitpos = big_endian_correction;
2565 bitpos < bytes * BITS_PER_UNIT;
2566 bitpos += bitsize, xbitpos += bitsize)
2568 /* We need a new source operand each time xbitpos is on a
2569 word boundary and when xbitpos == big_endian_correction
2570 (the first time through). */
2571 if (xbitpos % BITS_PER_WORD == 0
2572 || xbitpos == big_endian_correction)
2573 src = operand_subword_force (srcreg, xbitpos / BITS_PER_WORD,
2576 /* We need a new destination operand each time bitpos is on
2578 if (bitpos % BITS_PER_WORD == 0)
2579 dst = operand_subword (tgtblk, bitpos / BITS_PER_WORD, 1, BLKmode);
2581 /* Use xbitpos for the source extraction (right justified) and
2582 xbitpos for the destination store (left justified). */
2583 store_bit_field (dst, bitsize, bitpos % BITS_PER_WORD, word_mode,
2584 extract_bit_field (src, bitsize,
2585 xbitpos % BITS_PER_WORD, 1,
2586 NULL_RTX, word_mode, word_mode,
2594 /* Add a USE expression for REG to the (possibly empty) list pointed
2595 to by CALL_FUSAGE. REG must denote a hard register. */
2598 use_reg (call_fusage, reg)
2599 rtx *call_fusage, reg;
2601 if (GET_CODE (reg) != REG
2602 || REGNO (reg) >= FIRST_PSEUDO_REGISTER)
2606 = gen_rtx_EXPR_LIST (VOIDmode,
2607 gen_rtx_USE (VOIDmode, reg), *call_fusage);
2610 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2611 starting at REGNO. All of these registers must be hard registers. */
2614 use_regs (call_fusage, regno, nregs)
2621 if (regno + nregs > FIRST_PSEUDO_REGISTER)
2624 for (i = 0; i < nregs; i++)
2625 use_reg (call_fusage, regno_reg_rtx[regno + i]);
2628 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2629 PARALLEL REGS. This is for calls that pass values in multiple
2630 non-contiguous locations. The Irix 6 ABI has examples of this. */
2633 use_group_regs (call_fusage, regs)
2639 for (i = 0; i < XVECLEN (regs, 0); i++)
2641 rtx reg = XEXP (XVECEXP (regs, 0, i), 0);
2643 /* A NULL entry means the parameter goes both on the stack and in
2644 registers. This can also be a MEM for targets that pass values
2645 partially on the stack and partially in registers. */
2646 if (reg != 0 && GET_CODE (reg) == REG)
2647 use_reg (call_fusage, reg);
2652 /* Determine whether the LEN bytes generated by CONSTFUN can be
2653 stored to memory using several move instructions. CONSTFUNDATA is
2654 a pointer which will be passed as argument in every CONSTFUN call.
2655 ALIGN is maximum alignment we can assume. Return nonzero if a
2656 call to store_by_pieces should succeed. */
2659 can_store_by_pieces (len, constfun, constfundata, align)
2660 unsigned HOST_WIDE_INT len;
2661 rtx (*constfun) PARAMS ((PTR, HOST_WIDE_INT, enum machine_mode));
2665 unsigned HOST_WIDE_INT max_size, l;
2666 HOST_WIDE_INT offset = 0;
2667 enum machine_mode mode, tmode;
2668 enum insn_code icode;
2675 if (! MOVE_BY_PIECES_P (len, align))
2678 if (! SLOW_UNALIGNED_ACCESS (word_mode, align)
2679 || align > MOVE_MAX * BITS_PER_UNIT || align >= BIGGEST_ALIGNMENT)
2680 align = MOVE_MAX * BITS_PER_UNIT;
2682 /* We would first store what we can in the largest integer mode, then go to
2683 successively smaller modes. */
2686 reverse <= (HAVE_PRE_DECREMENT || HAVE_POST_DECREMENT);
2691 max_size = STORE_MAX_PIECES + 1;
2692 while (max_size > 1)
2694 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2695 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2696 if (GET_MODE_SIZE (tmode) < max_size)
2699 if (mode == VOIDmode)
2702 icode = mov_optab->handlers[(int) mode].insn_code;
2703 if (icode != CODE_FOR_nothing
2704 && align >= GET_MODE_ALIGNMENT (mode))
2706 unsigned int size = GET_MODE_SIZE (mode);
2713 cst = (*constfun) (constfundata, offset, mode);
2714 if (!LEGITIMATE_CONSTANT_P (cst))
2724 max_size = GET_MODE_SIZE (mode);
2727 /* The code above should have handled everything. */
2735 /* Generate several move instructions to store LEN bytes generated by
2736 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
2737 pointer which will be passed as argument in every CONSTFUN call.
2738 ALIGN is maximum alignment we can assume. */
2741 store_by_pieces (to, len, constfun, constfundata, align)
2743 unsigned HOST_WIDE_INT len;
2744 rtx (*constfun) PARAMS ((PTR, HOST_WIDE_INT, enum machine_mode));
2748 struct store_by_pieces data;
2753 if (! MOVE_BY_PIECES_P (len, align))
2755 to = protect_from_queue (to, 1);
2756 data.constfun = constfun;
2757 data.constfundata = constfundata;
2760 store_by_pieces_1 (&data, align);
2763 /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
2764 rtx with BLKmode). The caller must pass TO through protect_from_queue
2765 before calling. ALIGN is maximum alignment we can assume. */
2768 clear_by_pieces (to, len, align)
2770 unsigned HOST_WIDE_INT len;
2773 struct store_by_pieces data;
2778 data.constfun = clear_by_pieces_1;
2779 data.constfundata = NULL;
2782 store_by_pieces_1 (&data, align);
2785 /* Callback routine for clear_by_pieces.
2786 Return const0_rtx unconditionally. */
2789 clear_by_pieces_1 (data, offset, mode)
2790 PTR data ATTRIBUTE_UNUSED;
2791 HOST_WIDE_INT offset ATTRIBUTE_UNUSED;
2792 enum machine_mode mode ATTRIBUTE_UNUSED;
2797 /* Subroutine of clear_by_pieces and store_by_pieces.
2798 Generate several move instructions to store LEN bytes of block TO. (A MEM
2799 rtx with BLKmode). The caller must pass TO through protect_from_queue
2800 before calling. ALIGN is maximum alignment we can assume. */
2803 store_by_pieces_1 (data, align)
2804 struct store_by_pieces *data;
2807 rtx to_addr = XEXP (data->to, 0);
2808 unsigned HOST_WIDE_INT max_size = STORE_MAX_PIECES + 1;
2809 enum machine_mode mode = VOIDmode, tmode;
2810 enum insn_code icode;
2813 data->to_addr = to_addr;
2815 = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
2816 || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
2818 data->explicit_inc_to = 0;
2820 = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
2822 data->offset = data->len;
2824 /* If storing requires more than two move insns,
2825 copy addresses to registers (to make displacements shorter)
2826 and use post-increment if available. */
2827 if (!data->autinc_to
2828 && move_by_pieces_ninsns (data->len, align) > 2)
2830 /* Determine the main mode we'll be using. */
2831 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2832 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2833 if (GET_MODE_SIZE (tmode) < max_size)
2836 if (USE_STORE_PRE_DECREMENT (mode) && data->reverse && ! data->autinc_to)
2838 data->to_addr = copy_addr_to_reg (plus_constant (to_addr, data->len));
2839 data->autinc_to = 1;
2840 data->explicit_inc_to = -1;
2843 if (USE_STORE_POST_INCREMENT (mode) && ! data->reverse
2844 && ! data->autinc_to)
2846 data->to_addr = copy_addr_to_reg (to_addr);
2847 data->autinc_to = 1;
2848 data->explicit_inc_to = 1;
2851 if ( !data->autinc_to && CONSTANT_P (to_addr))
2852 data->to_addr = copy_addr_to_reg (to_addr);
2855 if (! SLOW_UNALIGNED_ACCESS (word_mode, align)
2856 || align > MOVE_MAX * BITS_PER_UNIT || align >= BIGGEST_ALIGNMENT)
2857 align = MOVE_MAX * BITS_PER_UNIT;
2859 /* First store what we can in the largest integer mode, then go to
2860 successively smaller modes. */
2862 while (max_size > 1)
2864 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2865 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2866 if (GET_MODE_SIZE (tmode) < max_size)
2869 if (mode == VOIDmode)
2872 icode = mov_optab->handlers[(int) mode].insn_code;
2873 if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
2874 store_by_pieces_2 (GEN_FCN (icode), mode, data);
2876 max_size = GET_MODE_SIZE (mode);
2879 /* The code above should have handled everything. */
2884 /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
2885 with move instructions for mode MODE. GENFUN is the gen_... function
2886 to make a move insn for that mode. DATA has all the other info. */
2889 store_by_pieces_2 (genfun, mode, data)
2890 rtx (*genfun) PARAMS ((rtx, ...));
2891 enum machine_mode mode;
2892 struct store_by_pieces *data;
2894 unsigned int size = GET_MODE_SIZE (mode);
2897 while (data->len >= size)
2900 data->offset -= size;
2902 if (data->autinc_to)
2903 to1 = adjust_automodify_address (data->to, mode, data->to_addr,
2906 to1 = adjust_address (data->to, mode, data->offset);
2908 if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
2909 emit_insn (gen_add2_insn (data->to_addr,
2910 GEN_INT (-(HOST_WIDE_INT) size)));
2912 cst = (*data->constfun) (data->constfundata, data->offset, mode);
2913 emit_insn ((*genfun) (to1, cst));
2915 if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
2916 emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
2918 if (! data->reverse)
2919 data->offset += size;
2925 /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
2926 its length in bytes. */
2929 clear_storage (object, size)
2934 unsigned int align = (GET_CODE (object) == MEM ? MEM_ALIGN (object)
2935 : GET_MODE_ALIGNMENT (GET_MODE (object)));
2937 /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2938 just move a zero. Otherwise, do this a piece at a time. */
2939 if (GET_MODE (object) != BLKmode
2940 && GET_CODE (size) == CONST_INT
2941 && INTVAL (size) == (HOST_WIDE_INT) GET_MODE_SIZE (GET_MODE (object)))
2942 emit_move_insn (object, CONST0_RTX (GET_MODE (object)));
2945 object = protect_from_queue (object, 1);
2946 size = protect_from_queue (size, 0);
2948 if (GET_CODE (size) == CONST_INT && INTVAL (size) == 0)
2950 else if (GET_CODE (size) == CONST_INT
2951 && CLEAR_BY_PIECES_P (INTVAL (size), align))
2952 clear_by_pieces (object, INTVAL (size), align);
2953 else if (clear_storage_via_clrstr (object, size, align))
2956 retval = clear_storage_via_libcall (object, size);
2962 /* A subroutine of clear_storage. Expand a clrstr pattern;
2963 return true if successful. */
2966 clear_storage_via_clrstr (object, size, align)
2970 /* Try the most limited insn first, because there's no point
2971 including more than one in the machine description unless
2972 the more limited one has some advantage. */
2974 rtx opalign = GEN_INT (align / BITS_PER_UNIT);
2975 enum machine_mode mode;
2977 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
2978 mode = GET_MODE_WIDER_MODE (mode))
2980 enum insn_code code = clrstr_optab[(int) mode];
2981 insn_operand_predicate_fn pred;
2983 if (code != CODE_FOR_nothing
2984 /* We don't need MODE to be narrower than
2985 BITS_PER_HOST_WIDE_INT here because if SIZE is less than
2986 the mode mask, as it is returned by the macro, it will
2987 definitely be less than the actual mode mask. */
2988 && ((GET_CODE (size) == CONST_INT
2989 && ((unsigned HOST_WIDE_INT) INTVAL (size)
2990 <= (GET_MODE_MASK (mode) >> 1)))
2991 || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD)
2992 && ((pred = insn_data[(int) code].operand[0].predicate) == 0
2993 || (*pred) (object, BLKmode))
2994 && ((pred = insn_data[(int) code].operand[2].predicate) == 0
2995 || (*pred) (opalign, VOIDmode)))
2998 rtx last = get_last_insn ();
3001 op1 = convert_to_mode (mode, size, 1);
3002 pred = insn_data[(int) code].operand[1].predicate;
3003 if (pred != 0 && ! (*pred) (op1, mode))
3004 op1 = copy_to_mode_reg (mode, op1);
3006 pat = GEN_FCN ((int) code) (object, op1, opalign);
3013 delete_insns_since (last);
3020 /* A subroutine of clear_storage. Expand a call to memset or bzero.
3021 Return the return value of memset, 0 otherwise. */
3024 clear_storage_via_libcall (object, size)
3027 tree call_expr, arg_list, fn, object_tree, size_tree;
3028 enum machine_mode size_mode;
3031 /* OBJECT or SIZE may have been passed through protect_from_queue.
3033 It is unsafe to save the value generated by protect_from_queue
3034 and reuse it later. Consider what happens if emit_queue is
3035 called before the return value from protect_from_queue is used.
3037 Expansion of the CALL_EXPR below will call emit_queue before
3038 we are finished emitting RTL for argument setup. So if we are
3039 not careful we could get the wrong value for an argument.
3041 To avoid this problem we go ahead and emit code to copy OBJECT
3042 and SIZE into new pseudos. We can then place those new pseudos
3043 into an RTL_EXPR and use them later, even after a call to
3046 Note this is not strictly needed for library calls since they
3047 do not call emit_queue before loading their arguments. However,
3048 we may need to have library calls call emit_queue in the future
3049 since failing to do so could cause problems for targets which
3050 define SMALL_REGISTER_CLASSES and pass arguments in registers. */
3052 object = copy_to_mode_reg (Pmode, XEXP (object, 0));
3054 if (TARGET_MEM_FUNCTIONS)
3055 size_mode = TYPE_MODE (sizetype);
3057 size_mode = TYPE_MODE (unsigned_type_node);
3058 size = convert_to_mode (size_mode, size, 1);
3059 size = copy_to_mode_reg (size_mode, size);
3061 /* It is incorrect to use the libcall calling conventions to call
3062 memset in this context. This could be a user call to memset and
3063 the user may wish to examine the return value from memset. For
3064 targets where libcalls and normal calls have different conventions
3065 for returning pointers, we could end up generating incorrect code.
3067 For convenience, we generate the call to bzero this way as well. */
3069 object_tree = make_tree (ptr_type_node, object);
3070 if (TARGET_MEM_FUNCTIONS)
3071 size_tree = make_tree (sizetype, size);
3073 size_tree = make_tree (unsigned_type_node, size);
3075 fn = clear_storage_libcall_fn (true);
3076 arg_list = tree_cons (NULL_TREE, size_tree, NULL_TREE);
3077 if (TARGET_MEM_FUNCTIONS)
3078 arg_list = tree_cons (NULL_TREE, integer_zero_node, arg_list);
3079 arg_list = tree_cons (NULL_TREE, object_tree, arg_list);
3081 /* Now we have to build up the CALL_EXPR itself. */
3082 call_expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (fn)), fn);
3083 call_expr = build (CALL_EXPR, TREE_TYPE (TREE_TYPE (fn)),
3084 call_expr, arg_list, NULL_TREE);
3085 TREE_SIDE_EFFECTS (call_expr) = 1;
3087 retval = expand_expr (call_expr, NULL_RTX, VOIDmode, 0);
3089 /* If we are initializing a readonly value, show the above call
3090 clobbered it. Otherwise, a load from it may erroneously be
3091 hoisted from a loop. */
3092 if (RTX_UNCHANGING_P (object))
3093 emit_insn (gen_rtx_CLOBBER (VOIDmode, object));
3095 return (TARGET_MEM_FUNCTIONS ? retval : NULL_RTX);
3098 /* A subroutine of clear_storage_via_libcall. Create the tree node
3099 for the function we use for block clears. The first time FOR_CALL
3100 is true, we call assemble_external. */
3102 static GTY(()) tree block_clear_fn;
3105 clear_storage_libcall_fn (for_call)
3108 static bool emitted_extern;
3109 tree fn = block_clear_fn, args;
3113 if (TARGET_MEM_FUNCTIONS)
3115 fn = get_identifier ("memset");
3116 args = build_function_type_list (ptr_type_node, ptr_type_node,
3117 integer_type_node, sizetype,
3122 fn = get_identifier ("bzero");
3123 args = build_function_type_list (void_type_node, ptr_type_node,
3124 unsigned_type_node, NULL_TREE);
3127 fn = build_decl (FUNCTION_DECL, fn, args);
3128 DECL_EXTERNAL (fn) = 1;
3129 TREE_PUBLIC (fn) = 1;
3130 DECL_ARTIFICIAL (fn) = 1;
3131 TREE_NOTHROW (fn) = 1;
3133 block_clear_fn = fn;
3136 if (for_call && !emitted_extern)
3138 emitted_extern = true;
3139 make_decl_rtl (fn, NULL);
3140 assemble_external (fn);
3146 /* Generate code to copy Y into X.
3147 Both Y and X must have the same mode, except that
3148 Y can be a constant with VOIDmode.
3149 This mode cannot be BLKmode; use emit_block_move for that.
3151 Return the last instruction emitted. */
3154 emit_move_insn (x, y)
3157 enum machine_mode mode = GET_MODE (x);
3158 rtx y_cst = NULL_RTX;
3161 x = protect_from_queue (x, 1);
3162 y = protect_from_queue (y, 0);
3164 if (mode == BLKmode || (GET_MODE (y) != mode && GET_MODE (y) != VOIDmode))
3167 /* Never force constant_p_rtx to memory. */
3168 if (GET_CODE (y) == CONSTANT_P_RTX)
3170 else if (CONSTANT_P (y))
3173 && SCALAR_FLOAT_MODE_P (GET_MODE (x))
3174 && (last_insn = compress_float_constant (x, y)))
3177 if (!LEGITIMATE_CONSTANT_P (y))
3180 y = force_const_mem (mode, y);
3182 /* If the target's cannot_force_const_mem prevented the spill,
3183 assume that the target's move expanders will also take care
3184 of the non-legitimate constant. */
3190 /* If X or Y are memory references, verify that their addresses are valid
3192 if (GET_CODE (x) == MEM
3193 && ((! memory_address_p (GET_MODE (x), XEXP (x, 0))
3194 && ! push_operand (x, GET_MODE (x)))
3196 && CONSTANT_ADDRESS_P (XEXP (x, 0)))))
3197 x = validize_mem (x);
3199 if (GET_CODE (y) == MEM
3200 && (! memory_address_p (GET_MODE (y), XEXP (y, 0))
3202 && CONSTANT_ADDRESS_P (XEXP (y, 0)))))
3203 y = validize_mem (y);
3205 if (mode == BLKmode)
3208 last_insn = emit_move_insn_1 (x, y);
3210 if (y_cst && GET_CODE (x) == REG)
3211 set_unique_reg_note (last_insn, REG_EQUAL, y_cst);
3216 /* Low level part of emit_move_insn.
3217 Called just like emit_move_insn, but assumes X and Y
3218 are basically valid. */
3221 emit_move_insn_1 (x, y)
3224 enum machine_mode mode = GET_MODE (x);
3225 enum machine_mode submode;
3226 enum mode_class class = GET_MODE_CLASS (mode);
3228 if ((unsigned int) mode >= (unsigned int) MAX_MACHINE_MODE)
3231 if (mov_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
3233 emit_insn (GEN_FCN (mov_optab->handlers[(int) mode].insn_code) (x, y));
3235 /* Expand complex moves by moving real part and imag part, if possible. */
3236 else if ((class == MODE_COMPLEX_FLOAT || class == MODE_COMPLEX_INT)
3237 && BLKmode != (submode = GET_MODE_INNER (mode))
3238 && (mov_optab->handlers[(int) submode].insn_code
3239 != CODE_FOR_nothing))
3241 /* Don't split destination if it is a stack push. */
3242 int stack = push_operand (x, GET_MODE (x));
3244 #ifdef PUSH_ROUNDING
3245 /* In case we output to the stack, but the size is smaller machine can
3246 push exactly, we need to use move instructions. */
3248 && (PUSH_ROUNDING (GET_MODE_SIZE (submode))
3249 != GET_MODE_SIZE (submode)))
3252 HOST_WIDE_INT offset1, offset2;
3254 /* Do not use anti_adjust_stack, since we don't want to update
3255 stack_pointer_delta. */
3256 temp = expand_binop (Pmode,
3257 #ifdef STACK_GROWS_DOWNWARD
3265 (GET_MODE_SIZE (GET_MODE (x)))),
3266 stack_pointer_rtx, 0, OPTAB_LIB_WIDEN);
3268 if (temp != stack_pointer_rtx)
3269 emit_move_insn (stack_pointer_rtx, temp);
3271 #ifdef STACK_GROWS_DOWNWARD
3273 offset2 = GET_MODE_SIZE (submode);
3275 offset1 = -PUSH_ROUNDING (GET_MODE_SIZE (GET_MODE (x)));
3276 offset2 = (-PUSH_ROUNDING (GET_MODE_SIZE (GET_MODE (x)))
3277 + GET_MODE_SIZE (submode));
3280 emit_move_insn (change_address (x, submode,
3281 gen_rtx_PLUS (Pmode,
3283 GEN_INT (offset1))),
3284 gen_realpart (submode, y));
3285 emit_move_insn (change_address (x, submode,
3286 gen_rtx_PLUS (Pmode,
3288 GEN_INT (offset2))),
3289 gen_imagpart (submode, y));
3293 /* If this is a stack, push the highpart first, so it
3294 will be in the argument order.
3296 In that case, change_address is used only to convert
3297 the mode, not to change the address. */
3300 /* Note that the real part always precedes the imag part in memory
3301 regardless of machine's endianness. */
3302 #ifdef STACK_GROWS_DOWNWARD
3303 emit_insn (GEN_FCN (mov_optab->handlers[(int) submode].insn_code)
3304 (gen_rtx_MEM (submode, XEXP (x, 0)),
3305 gen_imagpart (submode, y)));
3306 emit_insn (GEN_FCN (mov_optab->handlers[(int) submode].insn_code)
3307 (gen_rtx_MEM (submode, XEXP (x, 0)),
3308 gen_realpart (submode, y)));
3310 emit_insn (GEN_FCN (mov_optab->handlers[(int) submode].insn_code)
3311 (gen_rtx_MEM (submode, XEXP (x, 0)),
3312 gen_realpart (submode, y)));
3313 emit_insn (GEN_FCN (mov_optab->handlers[(int) submode].insn_code)
3314 (gen_rtx_MEM (submode, XEXP (x, 0)),
3315 gen_imagpart (submode, y)));
3320 rtx realpart_x, realpart_y;
3321 rtx imagpart_x, imagpart_y;
3323 /* If this is a complex value with each part being smaller than a
3324 word, the usual calling sequence will likely pack the pieces into
3325 a single register. Unfortunately, SUBREG of hard registers only
3326 deals in terms of words, so we have a problem converting input
3327 arguments to the CONCAT of two registers that is used elsewhere
3328 for complex values. If this is before reload, we can copy it into
3329 memory and reload. FIXME, we should see about using extract and
3330 insert on integer registers, but complex short and complex char
3331 variables should be rarely used. */
3332 if (GET_MODE_BITSIZE (mode) < 2 * BITS_PER_WORD
3333 && (reload_in_progress | reload_completed) == 0)
3336 = (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER);
3338 = (REG_P (y) && REGNO (y) < FIRST_PSEUDO_REGISTER);
3340 if (packed_dest_p || packed_src_p)
3342 enum mode_class reg_class = ((class == MODE_COMPLEX_FLOAT)
3343 ? MODE_FLOAT : MODE_INT);
3345 enum machine_mode reg_mode
3346 = mode_for_size (GET_MODE_BITSIZE (mode), reg_class, 1);
3348 if (reg_mode != BLKmode)
3350 rtx mem = assign_stack_temp (reg_mode,
3351 GET_MODE_SIZE (mode), 0);
3352 rtx cmem = adjust_address (mem, mode, 0);
3355 = N_("function using short complex types cannot be inline");
3359 rtx sreg = gen_rtx_SUBREG (reg_mode, x, 0);
3361 emit_move_insn_1 (cmem, y);
3362 return emit_move_insn_1 (sreg, mem);
3366 rtx sreg = gen_rtx_SUBREG (reg_mode, y, 0);
3368 emit_move_insn_1 (mem, sreg);
3369 return emit_move_insn_1 (x, cmem);
3375 realpart_x = gen_realpart (submode, x);
3376 realpart_y = gen_realpart (submode, y);
3377 imagpart_x = gen_imagpart (submode, x);
3378 imagpart_y = gen_imagpart (submode, y);
3380 /* Show the output dies here. This is necessary for SUBREGs
3381 of pseudos since we cannot track their lifetimes correctly;
3382 hard regs shouldn't appear here except as return values.
3383 We never want to emit such a clobber after reload. */
3385 && ! (reload_in_progress || reload_completed)
3386 && (GET_CODE (realpart_x) == SUBREG
3387 || GET_CODE (imagpart_x) == SUBREG))
3388 emit_insn (gen_rtx_CLOBBER (VOIDmode, x));
3390 emit_insn (GEN_FCN (mov_optab->handlers[(int) submode].insn_code)
3391 (realpart_x, realpart_y));
3392 emit_insn (GEN_FCN (mov_optab->handlers[(int) submode].insn_code)
3393 (imagpart_x, imagpart_y));
3396 return get_last_insn ();
3399 /* This will handle any multi-word or full-word mode that lacks a move_insn
3400 pattern. However, you will get better code if you define such patterns,
3401 even if they must turn into multiple assembler instructions. */
3402 else if (GET_MODE_SIZE (mode) >= UNITS_PER_WORD)
3409 #ifdef PUSH_ROUNDING
3411 /* If X is a push on the stack, do the push now and replace
3412 X with a reference to the stack pointer. */
3413 if (push_operand (x, GET_MODE (x)))
3418 /* Do not use anti_adjust_stack, since we don't want to update
3419 stack_pointer_delta. */
3420 temp = expand_binop (Pmode,
3421 #ifdef STACK_GROWS_DOWNWARD
3429 (GET_MODE_SIZE (GET_MODE (x)))),
3430 stack_pointer_rtx, 0, OPTAB_LIB_WIDEN);
3432 if (temp != stack_pointer_rtx)
3433 emit_move_insn (stack_pointer_rtx, temp);
3435 code = GET_CODE (XEXP (x, 0));
3437 /* Just hope that small offsets off SP are OK. */
3438 if (code == POST_INC)
3439 temp = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3440 GEN_INT (-((HOST_WIDE_INT)
3441 GET_MODE_SIZE (GET_MODE (x)))));
3442 else if (code == POST_DEC)
3443 temp = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3444 GEN_INT (GET_MODE_SIZE (GET_MODE (x))));
3446 temp = stack_pointer_rtx;
3448 x = change_address (x, VOIDmode, temp);
3452 /* If we are in reload, see if either operand is a MEM whose address
3453 is scheduled for replacement. */
3454 if (reload_in_progress && GET_CODE (x) == MEM
3455 && (inner = find_replacement (&XEXP (x, 0))) != XEXP (x, 0))
3456 x = replace_equiv_address_nv (x, inner);
3457 if (reload_in_progress && GET_CODE (y) == MEM
3458 && (inner = find_replacement (&XEXP (y, 0))) != XEXP (y, 0))
3459 y = replace_equiv_address_nv (y, inner);
3465 i < (GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
3468 rtx xpart = operand_subword (x, i, 1, mode);
3469 rtx ypart = operand_subword (y, i, 1, mode);
3471 /* If we can't get a part of Y, put Y into memory if it is a
3472 constant. Otherwise, force it into a register. If we still
3473 can't get a part of Y, abort. */
3474 if (ypart == 0 && CONSTANT_P (y))
3476 y = force_const_mem (mode, y);
3477 ypart = operand_subword (y, i, 1, mode);
3479 else if (ypart == 0)
3480 ypart = operand_subword_force (y, i, mode);
3482 if (xpart == 0 || ypart == 0)
3485 need_clobber |= (GET_CODE (xpart) == SUBREG);
3487 last_insn = emit_move_insn (xpart, ypart);
3493 /* Show the output dies here. This is necessary for SUBREGs
3494 of pseudos since we cannot track their lifetimes correctly;
3495 hard regs shouldn't appear here except as return values.
3496 We never want to emit such a clobber after reload. */
3498 && ! (reload_in_progress || reload_completed)
3499 && need_clobber != 0)
3500 emit_insn (gen_rtx_CLOBBER (VOIDmode, x));
3510 /* If Y is representable exactly in a narrower mode, and the target can
3511 perform the extension directly from constant or memory, then emit the
3512 move as an extension. */
3515 compress_float_constant (x, y)
3518 enum machine_mode dstmode = GET_MODE (x);
3519 enum machine_mode orig_srcmode = GET_MODE (y);
3520 enum machine_mode srcmode;
3523 REAL_VALUE_FROM_CONST_DOUBLE (r, y);
3525 for (srcmode = GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode));
3526 srcmode != orig_srcmode;
3527 srcmode = GET_MODE_WIDER_MODE (srcmode))
3530 rtx trunc_y, last_insn;
3532 /* Skip if the target can't extend this way. */
3533 ic = can_extend_p (dstmode, srcmode, 0);
3534 if (ic == CODE_FOR_nothing)
3537 /* Skip if the narrowed value isn't exact. */
3538 if (! exact_real_truncate (srcmode, &r))
3541 trunc_y = CONST_DOUBLE_FROM_REAL_VALUE (r, srcmode);
3543 if (LEGITIMATE_CONSTANT_P (trunc_y))
3545 /* Skip if the target needs extra instructions to perform
3547 if (! (*insn_data[ic].operand[1].predicate) (trunc_y, srcmode))
3550 else if (float_extend_from_mem[dstmode][srcmode])
3551 trunc_y = validize_mem (force_const_mem (srcmode, trunc_y));
3555 emit_unop_insn (ic, x, trunc_y, UNKNOWN);
3556 last_insn = get_last_insn ();
3558 if (GET_CODE (x) == REG)
3559 REG_NOTES (last_insn)
3560 = gen_rtx_EXPR_LIST (REG_EQUAL, y, REG_NOTES (last_insn));
3568 /* Pushing data onto the stack. */
3570 /* Push a block of length SIZE (perhaps variable)
3571 and return an rtx to address the beginning of the block.
3572 Note that it is not possible for the value returned to be a QUEUED.
3573 The value may be virtual_outgoing_args_rtx.
3575 EXTRA is the number of bytes of padding to push in addition to SIZE.
3576 BELOW nonzero means this padding comes at low addresses;
3577 otherwise, the padding comes at high addresses. */
3580 push_block (size, extra, below)
3586 size = convert_modes (Pmode, ptr_mode, size, 1);
3587 if (CONSTANT_P (size))
3588 anti_adjust_stack (plus_constant (size, extra));
3589 else if (GET_CODE (size) == REG && extra == 0)
3590 anti_adjust_stack (size);
3593 temp = copy_to_mode_reg (Pmode, size);
3595 temp = expand_binop (Pmode, add_optab, temp, GEN_INT (extra),
3596 temp, 0, OPTAB_LIB_WIDEN);
3597 anti_adjust_stack (temp);
3600 #ifndef STACK_GROWS_DOWNWARD
3606 temp = virtual_outgoing_args_rtx;
3607 if (extra != 0 && below)
3608 temp = plus_constant (temp, extra);
3612 if (GET_CODE (size) == CONST_INT)
3613 temp = plus_constant (virtual_outgoing_args_rtx,
3614 -INTVAL (size) - (below ? 0 : extra));
3615 else if (extra != 0 && !below)
3616 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
3617 negate_rtx (Pmode, plus_constant (size, extra)));
3619 temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
3620 negate_rtx (Pmode, size));
3623 return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT), temp);
3626 #ifdef PUSH_ROUNDING
3628 /* Emit single push insn. */
3631 emit_single_push_insn (mode, x, type)
3633 enum machine_mode mode;
3637 unsigned rounded_size = PUSH_ROUNDING (GET_MODE_SIZE (mode));
3639 enum insn_code icode;
3640 insn_operand_predicate_fn pred;
3642 stack_pointer_delta += PUSH_ROUNDING (GET_MODE_SIZE (mode));
3643 /* If there is push pattern, use it. Otherwise try old way of throwing
3644 MEM representing push operation to move expander. */
3645 icode = push_optab->handlers[(int) mode].insn_code;
3646 if (icode != CODE_FOR_nothing)
3648 if (((pred = insn_data[(int) icode].operand[0].predicate)
3649 && !((*pred) (x, mode))))
3650 x = force_reg (mode, x);
3651 emit_insn (GEN_FCN (icode) (x));
3654 if (GET_MODE_SIZE (mode) == rounded_size)
3655 dest_addr = gen_rtx_fmt_e (STACK_PUSH_CODE, Pmode, stack_pointer_rtx);
3658 #ifdef STACK_GROWS_DOWNWARD
3659 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3660 GEN_INT (-(HOST_WIDE_INT) rounded_size));
3662 dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3663 GEN_INT (rounded_size));
3665 dest_addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, dest_addr);
3668 dest = gen_rtx_MEM (mode, dest_addr);
3672 set_mem_attributes (dest, type, 1);
3674 if (flag_optimize_sibling_calls)
3675 /* Function incoming arguments may overlap with sibling call
3676 outgoing arguments and we cannot allow reordering of reads
3677 from function arguments with stores to outgoing arguments
3678 of sibling calls. */
3679 set_mem_alias_set (dest, 0);
3681 emit_move_insn (dest, x);
3685 /* Generate code to push X onto the stack, assuming it has mode MODE and
3687 MODE is redundant except when X is a CONST_INT (since they don't
3689 SIZE is an rtx for the size of data to be copied (in bytes),
3690 needed only if X is BLKmode.
3692 ALIGN (in bits) is maximum alignment we can assume.
3694 If PARTIAL and REG are both nonzero, then copy that many of the first
3695 words of X into registers starting with REG, and push the rest of X.
3696 The amount of space pushed is decreased by PARTIAL words,
3697 rounded *down* to a multiple of PARM_BOUNDARY.
3698 REG must be a hard register in this case.
3699 If REG is zero but PARTIAL is not, take any all others actions for an
3700 argument partially in registers, but do not actually load any
3703 EXTRA is the amount in bytes of extra space to leave next to this arg.
3704 This is ignored if an argument block has already been allocated.
3706 On a machine that lacks real push insns, ARGS_ADDR is the address of
3707 the bottom of the argument block for this call. We use indexing off there
3708 to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
3709 argument block has not been preallocated.
3711 ARGS_SO_FAR is the size of args previously pushed for this call.
3713 REG_PARM_STACK_SPACE is nonzero if functions require stack space
3714 for arguments passed in registers. If nonzero, it will be the number
3715 of bytes required. */
3718 emit_push_insn (x, mode, type, size, align, partial, reg, extra,
3719 args_addr, args_so_far, reg_parm_stack_space,
3722 enum machine_mode mode;
3731 int reg_parm_stack_space;
3735 enum direction stack_direction
3736 #ifdef STACK_GROWS_DOWNWARD
3742 /* Decide where to pad the argument: `downward' for below,
3743 `upward' for above, or `none' for don't pad it.
3744 Default is below for small data on big-endian machines; else above. */
3745 enum direction where_pad = FUNCTION_ARG_PADDING (mode, type);
3747 /* Invert direction if stack is post-decrement.
3749 if (STACK_PUSH_CODE == POST_DEC)
3750 if (where_pad != none)
3751 where_pad = (where_pad == downward ? upward : downward);
3753 xinner = x = protect_from_queue (x, 0);
3755 if (mode == BLKmode)
3757 /* Copy a block into the stack, entirely or partially. */
3760 int used = partial * UNITS_PER_WORD;
3761 int offset = used % (PARM_BOUNDARY / BITS_PER_UNIT);
3769 /* USED is now the # of bytes we need not copy to the stack
3770 because registers will take care of them. */
3773 xinner = adjust_address (xinner, BLKmode, used);
3775 /* If the partial register-part of the arg counts in its stack size,
3776 skip the part of stack space corresponding to the registers.
3777 Otherwise, start copying to the beginning of the stack space,
3778 by setting SKIP to 0. */
3779 skip = (reg_parm_stack_space == 0) ? 0 : used;
3781 #ifdef PUSH_ROUNDING
3782 /* Do it with several push insns if that doesn't take lots of insns
3783 and if there is no difficulty with push insns that skip bytes
3784 on the stack for alignment purposes. */
3787 && GET_CODE (size) == CONST_INT
3789 && (MOVE_BY_PIECES_P ((unsigned) INTVAL (size) - used, align))
3790 /* Here we avoid the case of a structure whose weak alignment
3791 forces many pushes of a small amount of data,
3792 and such small pushes do rounding that causes trouble. */
3793 && ((! SLOW_UNALIGNED_ACCESS (word_mode, align))
3794 || align >= BIGGEST_ALIGNMENT
3795 || (PUSH_ROUNDING (align / BITS_PER_UNIT)
3796 == (align / BITS_PER_UNIT)))
3797 && PUSH_ROUNDING (INTVAL (size)) == INTVAL (size))
3799 /* Push padding now if padding above and stack grows down,
3800 or if padding below and stack grows up.
3801 But if space already allocated, this has already been done. */
3802 if (extra && args_addr == 0
3803 && where_pad != none && where_pad != stack_direction)
3804 anti_adjust_stack (GEN_INT (extra));
3806 move_by_pieces (NULL, xinner, INTVAL (size) - used, align);
3809 #endif /* PUSH_ROUNDING */
3813 /* Otherwise make space on the stack and copy the data
3814 to the address of that space. */
3816 /* Deduct words put into registers from the size we must copy. */
3819 if (GET_CODE (size) == CONST_INT)
3820 size = GEN_INT (INTVAL (size) - used);
3822 size = expand_binop (GET_MODE (size), sub_optab, size,
3823 GEN_INT (used), NULL_RTX, 0,
3827 /* Get the address of the stack space.
3828 In this case, we do not deal with EXTRA separately.
3829 A single stack adjust will do. */
3832 temp = push_block (size, extra, where_pad == downward);
3835 else if (GET_CODE (args_so_far) == CONST_INT)
3836 temp = memory_address (BLKmode,
3837 plus_constant (args_addr,
3838 skip + INTVAL (args_so_far)));
3840 temp = memory_address (BLKmode,
3841 plus_constant (gen_rtx_PLUS (Pmode,
3846 if (!ACCUMULATE_OUTGOING_ARGS)
3848 /* If the source is referenced relative to the stack pointer,
3849 copy it to another register to stabilize it. We do not need
3850 to do this if we know that we won't be changing sp. */
3852 if (reg_mentioned_p (virtual_stack_dynamic_rtx, temp)
3853 || reg_mentioned_p (virtual_outgoing_args_rtx, temp))
3854 temp = copy_to_reg (temp);
3857 target = gen_rtx_MEM (BLKmode, temp);
3861 set_mem_attributes (target, type, 1);
3862 /* Function incoming arguments may overlap with sibling call
3863 outgoing arguments and we cannot allow reordering of reads
3864 from function arguments with stores to outgoing arguments
3865 of sibling calls. */
3866 set_mem_alias_set (target, 0);
3869 /* ALIGN may well be better aligned than TYPE, e.g. due to
3870 PARM_BOUNDARY. Assume the caller isn't lying. */
3871 set_mem_align (target, align);
3873 emit_block_move (target, xinner, size, BLOCK_OP_CALL_PARM);
3876 else if (partial > 0)
3878 /* Scalar partly in registers. */
3880 int size = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
3883 /* # words of start of argument
3884 that we must make space for but need not store. */
3885 int offset = partial % (PARM_BOUNDARY / BITS_PER_WORD);
3886 int args_offset = INTVAL (args_so_far);
3889 /* Push padding now if padding above and stack grows down,
3890 or if padding below and stack grows up.
3891 But if space already allocated, this has already been done. */
3892 if (extra && args_addr == 0
3893 && where_pad != none && where_pad != stack_direction)
3894 anti_adjust_stack (GEN_INT (extra));
3896 /* If we make space by pushing it, we might as well push
3897 the real data. Otherwise, we can leave OFFSET nonzero
3898 and leave the space uninitialized. */
3902 /* Now NOT_STACK gets the number of words that we don't need to
3903 allocate on the stack. */
3904 not_stack = partial - offset;
3906 /* If the partial register-part of the arg counts in its stack size,
3907 skip the part of stack space corresponding to the registers.
3908 Otherwise, start copying to the beginning of the stack space,
3909 by setting SKIP to 0. */
3910 skip = (reg_parm_stack_space == 0) ? 0 : not_stack;
3912 if (CONSTANT_P (x) && ! LEGITIMATE_CONSTANT_P (x))
3913 x = validize_mem (force_const_mem (mode, x));
3915 /* If X is a hard register in a non-integer mode, copy it into a pseudo;
3916 SUBREGs of such registers are not allowed. */
3917 if ((GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER
3918 && GET_MODE_CLASS (GET_MODE (x)) != MODE_INT))
3919 x = copy_to_reg (x);
3921 /* Loop over all the words allocated on the stack for this arg. */
3922 /* We can do it by words, because any scalar bigger than a word
3923 has a size a multiple of a word. */
3924 #ifndef PUSH_ARGS_REVERSED
3925 for (i = not_stack; i < size; i++)
3927 for (i = size - 1; i >= not_stack; i--)
3929 if (i >= not_stack + offset)
3930 emit_push_insn (operand_subword_force (x, i, mode),
3931 word_mode, NULL_TREE, NULL_RTX, align, 0, NULL_RTX,
3933 GEN_INT (args_offset + ((i - not_stack + skip)
3935 reg_parm_stack_space, alignment_pad);
3940 rtx target = NULL_RTX;
3943 /* Push padding now if padding above and stack grows down,
3944 or if padding below and stack grows up.
3945 But if space already allocated, this has already been done. */
3946 if (extra && args_addr == 0
3947 && where_pad != none && where_pad != stack_direction)
3948 anti_adjust_stack (GEN_INT (extra));
3950 #ifdef PUSH_ROUNDING
3951 if (args_addr == 0 && PUSH_ARGS)
3952 emit_single_push_insn (mode, x, type);
3956 if (GET_CODE (args_so_far) == CONST_INT)
3958 = memory_address (mode,
3959 plus_constant (args_addr,
3960 INTVAL (args_so_far)));
3962 addr = memory_address (mode, gen_rtx_PLUS (Pmode, args_addr,
3965 dest = gen_rtx_MEM (mode, addr);
3968 set_mem_attributes (dest, type, 1);
3969 /* Function incoming arguments may overlap with sibling call
3970 outgoing arguments and we cannot allow reordering of reads
3971 from function arguments with stores to outgoing arguments
3972 of sibling calls. */
3973 set_mem_alias_set (dest, 0);
3976 emit_move_insn (dest, x);
3980 /* If part should go in registers, copy that part
3981 into the appropriate registers. Do this now, at the end,
3982 since mem-to-mem copies above may do function calls. */
3983 if (partial > 0 && reg != 0)
3985 /* Handle calls that pass values in multiple non-contiguous locations.
3986 The Irix 6 ABI has examples of this. */
3987 if (GET_CODE (reg) == PARALLEL)
3988 emit_group_load (reg, x, -1); /* ??? size? */
3990 move_block_to_reg (REGNO (reg), x, partial, mode);
3993 if (extra && args_addr == 0 && where_pad == stack_direction)
3994 anti_adjust_stack (GEN_INT (extra));
3996 if (alignment_pad && args_addr == 0)
3997 anti_adjust_stack (alignment_pad);
4000 /* Return X if X can be used as a subtarget in a sequence of arithmetic
4008 /* Only registers can be subtargets. */
4009 || GET_CODE (x) != REG
4010 /* If the register is readonly, it can't be set more than once. */
4011 || RTX_UNCHANGING_P (x)
4012 /* Don't use hard regs to avoid extending their life. */
4013 || REGNO (x) < FIRST_PSEUDO_REGISTER
4014 /* Avoid subtargets inside loops,
4015 since they hide some invariant expressions. */
4016 || preserve_subexpressions_p ())
4020 /* Expand an assignment that stores the value of FROM into TO.
4021 If WANT_VALUE is nonzero, return an rtx for the value of TO.
4022 (This may contain a QUEUED rtx;
4023 if the value is constant, this rtx is a constant.)
4024 Otherwise, the returned value is NULL_RTX.
4026 SUGGEST_REG is no longer actually used.
4027 It used to mean, copy the value through a register
4028 and return that register, if that is possible.
4029 We now use WANT_VALUE to decide whether to do this. */
4032 expand_assignment (to, from, want_value, suggest_reg)
4035 int suggest_reg ATTRIBUTE_UNUSED;
4040 /* Don't crash if the lhs of the assignment was erroneous. */
4042 if (TREE_CODE (to) == ERROR_MARK)
4044 result = expand_expr (from, NULL_RTX, VOIDmode, 0);
4045 return want_value ? result : NULL_RTX;
4048 /* Assignment of a structure component needs special treatment
4049 if the structure component's rtx is not simply a MEM.
4050 Assignment of an array element at a constant index, and assignment of
4051 an array element in an unaligned packed structure field, has the same
4054 if (TREE_CODE (to) == COMPONENT_REF || TREE_CODE (to) == BIT_FIELD_REF
4055 || TREE_CODE (to) == ARRAY_REF || TREE_CODE (to) == ARRAY_RANGE_REF
4056 || TREE_CODE (TREE_TYPE (to)) == ARRAY_TYPE)
4058 enum machine_mode mode1;
4059 HOST_WIDE_INT bitsize, bitpos;
4067 tem = get_inner_reference (to, &bitsize, &bitpos, &offset, &mode1,
4068 &unsignedp, &volatilep);
4070 /* If we are going to use store_bit_field and extract_bit_field,
4071 make sure to_rtx will be safe for multiple use. */
4073 if (mode1 == VOIDmode && want_value)
4074 tem = stabilize_reference (tem);
4076 orig_to_rtx = to_rtx = expand_expr (tem, NULL_RTX, VOIDmode, 0);
4080 rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, EXPAND_SUM);
4082 if (GET_CODE (to_rtx) != MEM)
4085 #ifdef POINTERS_EXTEND_UNSIGNED
4086 if (GET_MODE (offset_rtx) != Pmode)
4087 offset_rtx = convert_to_mode (Pmode, offset_rtx, 0);
4089 if (GET_MODE (offset_rtx) != ptr_mode)
4090 offset_rtx = convert_to_mode (ptr_mode, offset_rtx, 0);
4093 /* A constant address in TO_RTX can have VOIDmode, we must not try
4094 to call force_reg for that case. Avoid that case. */
4095 if (GET_CODE (to_rtx) == MEM
4096 && GET_MODE (to_rtx) == BLKmode
4097 && GET_MODE (XEXP (to_rtx, 0)) != VOIDmode
4099 && (bitpos % bitsize) == 0
4100 && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
4101 && MEM_ALIGN (to_rtx) == GET_MODE_ALIGNMENT (mode1))
4103 to_rtx = adjust_address (to_rtx, mode1, bitpos / BITS_PER_UNIT);
4107 to_rtx = offset_address (to_rtx, offset_rtx,
4108 highest_pow2_factor_for_type (TREE_TYPE (to),
4112 if (GET_CODE (to_rtx) == MEM)
4114 /* If the field is at offset zero, we could have been given the
4115 DECL_RTX of the parent struct. Don't munge it. */
4116 to_rtx = shallow_copy_rtx (to_rtx);
4118 set_mem_attributes_minus_bitpos (to_rtx, to, 0, bitpos);
4121 /* Deal with volatile and readonly fields. The former is only done
4122 for MEM. Also set MEM_KEEP_ALIAS_SET_P if needed. */
4123 if (volatilep && GET_CODE (to_rtx) == MEM)
4125 if (to_rtx == orig_to_rtx)
4126 to_rtx = copy_rtx (to_rtx);
4127 MEM_VOLATILE_P (to_rtx) = 1;
4130 if (TREE_CODE (to) == COMPONENT_REF
4131 && TREE_READONLY (TREE_OPERAND (to, 1)))
4133 if (to_rtx == orig_to_rtx)
4134 to_rtx = copy_rtx (to_rtx);
4135 RTX_UNCHANGING_P (to_rtx) = 1;
4138 if (GET_CODE (to_rtx) == MEM && ! can_address_p (to))
4140 if (to_rtx == orig_to_rtx)
4141 to_rtx = copy_rtx (to_rtx);
4142 MEM_KEEP_ALIAS_SET_P (to_rtx) = 1;
4145 result = store_field (to_rtx, bitsize, bitpos, mode1, from,
4147 /* Spurious cast for HPUX compiler. */
4148 ? ((enum machine_mode)
4149 TYPE_MODE (TREE_TYPE (to)))
4151 unsignedp, TREE_TYPE (tem), get_alias_set (to));
4153 preserve_temp_slots (result);
4157 /* If the value is meaningful, convert RESULT to the proper mode.
4158 Otherwise, return nothing. */
4159 return (want_value ? convert_modes (TYPE_MODE (TREE_TYPE (to)),
4160 TYPE_MODE (TREE_TYPE (from)),
4162 TREE_UNSIGNED (TREE_TYPE (to)))
4166 /* If the rhs is a function call and its value is not an aggregate,
4167 call the function before we start to compute the lhs.
4168 This is needed for correct code for cases such as
4169 val = setjmp (buf) on machines where reference to val
4170 requires loading up part of an address in a separate insn.
4172 Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
4173 since it might be a promoted variable where the zero- or sign- extension
4174 needs to be done. Handling this in the normal way is safe because no
4175 computation is done before the call. */
4176 if (TREE_CODE (from) == CALL_EXPR && ! aggregate_value_p (from)
4177 && TREE_CODE (TYPE_SIZE (TREE_TYPE (from))) == INTEGER_CST
4178 && ! ((TREE_CODE (to) == VAR_DECL || TREE_CODE (to) == PARM_DECL)
4179 && GET_CODE (DECL_RTL (to)) == REG))
4184 value = expand_expr (from, NULL_RTX, VOIDmode, 0);
4186 to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
4188 /* Handle calls that return values in multiple non-contiguous locations.
4189 The Irix 6 ABI has examples of this. */
4190 if (GET_CODE (to_rtx) == PARALLEL)
4191 emit_group_load (to_rtx, value, int_size_in_bytes (TREE_TYPE (from)));
4192 else if (GET_MODE (to_rtx) == BLKmode)
4193 emit_block_move (to_rtx, value, expr_size (from), BLOCK_OP_NORMAL);
4196 #ifdef POINTERS_EXTEND_UNSIGNED
4197 if (POINTER_TYPE_P (TREE_TYPE (to))
4198 && GET_MODE (to_rtx) != GET_MODE (value))
4199 value = convert_memory_address (GET_MODE (to_rtx), value);
4201 emit_move_insn (to_rtx, value);
4203 preserve_temp_slots (to_rtx);
4206 return want_value ? to_rtx : NULL_RTX;
4209 /* Ordinary treatment. Expand TO to get a REG or MEM rtx.
4210 Don't re-expand if it was expanded already (in COMPONENT_REF case). */
4213 to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
4215 /* Don't move directly into a return register. */
4216 if (TREE_CODE (to) == RESULT_DECL
4217 && (GET_CODE (to_rtx) == REG || GET_CODE (to_rtx) == PARALLEL))
4222 temp = expand_expr (from, 0, GET_MODE (to_rtx), 0);
4224 if (GET_CODE (to_rtx) == PARALLEL)
4225 emit_group_load (to_rtx, temp, int_size_in_bytes (TREE_TYPE (from)));
4227 emit_move_insn (to_rtx, temp);
4229 preserve_temp_slots (to_rtx);
4232 return want_value ? to_rtx : NULL_RTX;
4235 /* In case we are returning the contents of an object which overlaps
4236 the place the value is being stored, use a safe function when copying
4237 a value through a pointer into a structure value return block. */
4238 if (TREE_CODE (to) == RESULT_DECL && TREE_CODE (from) == INDIRECT_REF
4239 && current_function_returns_struct
4240 && !current_function_returns_pcc_struct)
4245 size = expr_size (from);
4246 from_rtx = expand_expr (from, NULL_RTX, VOIDmode, 0);
4248 if (TARGET_MEM_FUNCTIONS)
4249 emit_library_call (memmove_libfunc, LCT_NORMAL,
4250 VOIDmode, 3, XEXP (to_rtx, 0), Pmode,
4251 XEXP (from_rtx, 0), Pmode,
4252 convert_to_mode (TYPE_MODE (sizetype),
4253 size, TREE_UNSIGNED (sizetype)),
4254 TYPE_MODE (sizetype));
4256 emit_library_call (bcopy_libfunc, LCT_NORMAL,
4257 VOIDmode, 3, XEXP (from_rtx, 0), Pmode,
4258 XEXP (to_rtx, 0), Pmode,
4259 convert_to_mode (TYPE_MODE (integer_type_node),
4261 TREE_UNSIGNED (integer_type_node)),
4262 TYPE_MODE (integer_type_node));
4264 preserve_temp_slots (to_rtx);
4267 return want_value ? to_rtx : NULL_RTX;
4270 /* Compute FROM and store the value in the rtx we got. */
4273 result = store_expr (from, to_rtx, want_value);
4274 preserve_temp_slots (result);
4277 return want_value ? result : NULL_RTX;
4280 /* Generate code for computing expression EXP,
4281 and storing the value into TARGET.
4282 TARGET may contain a QUEUED rtx.
4284 If WANT_VALUE & 1 is nonzero, return a copy of the value
4285 not in TARGET, so that we can be sure to use the proper
4286 value in a containing expression even if TARGET has something
4287 else stored in it. If possible, we copy the value through a pseudo
4288 and return that pseudo. Or, if the value is constant, we try to
4289 return the constant. In some cases, we return a pseudo
4290 copied *from* TARGET.
4292 If the mode is BLKmode then we may return TARGET itself.
4293 It turns out that in BLKmode it doesn't cause a problem.
4294 because C has no operators that could combine two different
4295 assignments into the same BLKmode object with different values
4296 with no sequence point. Will other languages need this to
4299 If WANT_VALUE & 1 is 0, we return NULL, to make sure
4300 to catch quickly any cases where the caller uses the value
4301 and fails to set WANT_VALUE.
4303 If WANT_VALUE & 2 is set, this is a store into a call param on the
4304 stack, and block moves may need to be treated specially. */
4307 store_expr (exp, target, want_value)
4313 int dont_return_target = 0;
4314 int dont_store_target = 0;
4316 if (VOID_TYPE_P (TREE_TYPE (exp)))
4318 /* C++ can generate ?: expressions with a throw expression in one
4319 branch and an rvalue in the other. Here, we resolve attempts to
4320 store the throw expression's nonexistant result. */
4323 expand_expr (exp, const0_rtx, VOIDmode, 0);
4326 if (TREE_CODE (exp) == COMPOUND_EXPR)
4328 /* Perform first part of compound expression, then assign from second
4330 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
4331 want_value & 2 ? EXPAND_STACK_PARM : EXPAND_NORMAL);
4333 return store_expr (TREE_OPERAND (exp, 1), target, want_value);
4335 else if (TREE_CODE (exp) == COND_EXPR && GET_MODE (target) == BLKmode)
4337 /* For conditional expression, get safe form of the target. Then
4338 test the condition, doing the appropriate assignment on either
4339 side. This avoids the creation of unnecessary temporaries.
4340 For non-BLKmode, it is more efficient not to do this. */
4342 rtx lab1 = gen_label_rtx (), lab2 = gen_label_rtx ();
4345 target = protect_from_queue (target, 1);
4347 do_pending_stack_adjust ();
4349 jumpifnot (TREE_OPERAND (exp, 0), lab1);
4350 start_cleanup_deferral ();
4351 store_expr (TREE_OPERAND (exp, 1), target, want_value & 2);
4352 end_cleanup_deferral ();
4354 emit_jump_insn (gen_jump (lab2));
4357 start_cleanup_deferral ();
4358 store_expr (TREE_OPERAND (exp, 2), target, want_value & 2);
4359 end_cleanup_deferral ();
4364 return want_value & 1 ? target : NULL_RTX;
4366 else if (queued_subexp_p (target))
4367 /* If target contains a postincrement, let's not risk
4368 using it as the place to generate the rhs. */
4370 if (GET_MODE (target) != BLKmode && GET_MODE (target) != VOIDmode)
4372 /* Expand EXP into a new pseudo. */
4373 temp = gen_reg_rtx (GET_MODE (target));
4374 temp = expand_expr (exp, temp, GET_MODE (target),
4376 ? EXPAND_STACK_PARM : EXPAND_NORMAL));
4379 temp = expand_expr (exp, NULL_RTX, GET_MODE (target),
4381 ? EXPAND_STACK_PARM : EXPAND_NORMAL));
4383 /* If target is volatile, ANSI requires accessing the value
4384 *from* the target, if it is accessed. So make that happen.
4385 In no case return the target itself. */
4386 if (! MEM_VOLATILE_P (target) && (want_value & 1) != 0)
4387 dont_return_target = 1;
4389 else if ((want_value & 1) != 0
4390 && GET_CODE (target) == MEM
4391 && ! MEM_VOLATILE_P (target)
4392 && GET_MODE (target) != BLKmode)
4393 /* If target is in memory and caller wants value in a register instead,
4394 arrange that. Pass TARGET as target for expand_expr so that,
4395 if EXP is another assignment, WANT_VALUE will be nonzero for it.
4396 We know expand_expr will not use the target in that case.
4397 Don't do this if TARGET is volatile because we are supposed
4398 to write it and then read it. */
4400 temp = expand_expr (exp, target, GET_MODE (target),
4401 want_value & 2 ? EXPAND_STACK_PARM : EXPAND_NORMAL);
4402 if (GET_MODE (temp) != BLKmode && GET_MODE (temp) != VOIDmode)
4404 /* If TEMP is already in the desired TARGET, only copy it from
4405 memory and don't store it there again. */
4407 || (rtx_equal_p (temp, target)
4408 && ! side_effects_p (temp) && ! side_effects_p (target)))
4409 dont_store_target = 1;
4410 temp = copy_to_reg (temp);
4412 dont_return_target = 1;
4414 else if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target))
4415 /* If this is a scalar in a register that is stored in a wider mode
4416 than the declared mode, compute the result into its declared mode
4417 and then convert to the wider mode. Our value is the computed
4420 rtx inner_target = 0;
4422 /* If we don't want a value, we can do the conversion inside EXP,
4423 which will often result in some optimizations. Do the conversion
4424 in two steps: first change the signedness, if needed, then
4425 the extend. But don't do this if the type of EXP is a subtype
4426 of something else since then the conversion might involve
4427 more than just converting modes. */
4428 if ((want_value & 1) == 0
4429 && INTEGRAL_TYPE_P (TREE_TYPE (exp))
4430 && TREE_TYPE (TREE_TYPE (exp)) == 0)
4432 if (TREE_UNSIGNED (TREE_TYPE (exp))
4433 != SUBREG_PROMOTED_UNSIGNED_P (target))
4435 ((*lang_hooks.types.signed_or_unsigned_type)
4436 (SUBREG_PROMOTED_UNSIGNED_P (target), TREE_TYPE (exp)), exp);
4438 exp = convert ((*lang_hooks.types.type_for_mode)
4439 (GET_MODE (SUBREG_REG (target)),
4440 SUBREG_PROMOTED_UNSIGNED_P (target)),
4443 inner_target = SUBREG_REG (target);
4446 temp = expand_expr (exp, inner_target, VOIDmode,
4447 want_value & 2 ? EXPAND_STACK_PARM : EXPAND_NORMAL);
4449 /* If TEMP is a volatile MEM and we want a result value, make
4450 the access now so it gets done only once. Likewise if
4451 it contains TARGET. */
4452 if (GET_CODE (temp) == MEM && (want_value & 1) != 0
4453 && (MEM_VOLATILE_P (temp)
4454 || reg_mentioned_p (SUBREG_REG (target), XEXP (temp, 0))))
4455 temp = copy_to_reg (temp);
4457 /* If TEMP is a VOIDmode constant, use convert_modes to make
4458 sure that we properly convert it. */
4459 if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode)
4461 temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
4462 temp, SUBREG_PROMOTED_UNSIGNED_P (target));
4463 temp = convert_modes (GET_MODE (SUBREG_REG (target)),
4464 GET_MODE (target), temp,
4465 SUBREG_PROMOTED_UNSIGNED_P (target));
4468 convert_move (SUBREG_REG (target), temp,
4469 SUBREG_PROMOTED_UNSIGNED_P (target));
4471 /* If we promoted a constant, change the mode back down to match
4472 target. Otherwise, the caller might get confused by a result whose
4473 mode is larger than expected. */
4475 if ((want_value & 1) != 0 && GET_MODE (temp) != GET_MODE (target))
4477 if (GET_MODE (temp) != VOIDmode)
4479 temp = gen_lowpart_SUBREG (GET_MODE (target), temp);
4480 SUBREG_PROMOTED_VAR_P (temp) = 1;
4481 SUBREG_PROMOTED_UNSIGNED_SET (temp,
4482 SUBREG_PROMOTED_UNSIGNED_P (target));
4485 temp = convert_modes (GET_MODE (target),
4486 GET_MODE (SUBREG_REG (target)),
4487 temp, SUBREG_PROMOTED_UNSIGNED_P (target));
4490 return want_value & 1 ? temp : NULL_RTX;
4494 temp = expand_expr (exp, target, GET_MODE (target),
4495 want_value & 2 ? EXPAND_STACK_PARM : EXPAND_NORMAL);
4496 /* Return TARGET if it's a specified hardware register.
4497 If TARGET is a volatile mem ref, either return TARGET
4498 or return a reg copied *from* TARGET; ANSI requires this.
4500 Otherwise, if TEMP is not TARGET, return TEMP
4501 if it is constant (for efficiency),
4502 or if we really want the correct value. */
4503 if (!(target && GET_CODE (target) == REG
4504 && REGNO (target) < FIRST_PSEUDO_REGISTER)
4505 && !(GET_CODE (target) == MEM && MEM_VOLATILE_P (target))
4506 && ! rtx_equal_p (temp, target)
4507 && (CONSTANT_P (temp) || (want_value & 1) != 0))
4508 dont_return_target = 1;
4511 /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
4512 the same as that of TARGET, adjust the constant. This is needed, for
4513 example, in case it is a CONST_DOUBLE and we want only a word-sized
4515 if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode
4516 && TREE_CODE (exp) != ERROR_MARK
4517 && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
4518 temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
4519 temp, TREE_UNSIGNED (TREE_TYPE (exp)));
4521 /* If value was not generated in the target, store it there.
4522 Convert the value to TARGET's type first if necessary.
4523 If TEMP and TARGET compare equal according to rtx_equal_p, but
4524 one or both of them are volatile memory refs, we have to distinguish
4526 - expand_expr has used TARGET. In this case, we must not generate
4527 another copy. This can be detected by TARGET being equal according
4529 - expand_expr has not used TARGET - that means that the source just
4530 happens to have the same RTX form. Since temp will have been created
4531 by expand_expr, it will compare unequal according to == .
4532 We must generate a copy in this case, to reach the correct number
4533 of volatile memory references. */
4535 if ((! rtx_equal_p (temp, target)
4536 || (temp != target && (side_effects_p (temp)
4537 || side_effects_p (target))))
4538 && TREE_CODE (exp) != ERROR_MARK
4539 && ! dont_store_target
4540 /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
4541 but TARGET is not valid memory reference, TEMP will differ
4542 from TARGET although it is really the same location. */
4543 && (TREE_CODE_CLASS (TREE_CODE (exp)) != 'd'
4544 || target != DECL_RTL_IF_SET (exp))
4545 /* If there's nothing to copy, don't bother. Don't call expr_size
4546 unless necessary, because some front-ends (C++) expr_size-hook
4547 aborts on objects that are not supposed to be bit-copied or
4549 && expr_size (exp) != const0_rtx)
4551 target = protect_from_queue (target, 1);
4552 if (GET_MODE (temp) != GET_MODE (target)
4553 && GET_MODE (temp) != VOIDmode)
4555 int unsignedp = TREE_UNSIGNED (TREE_TYPE (exp));
4556 if (dont_return_target)
4558 /* In this case, we will return TEMP,
4559 so make sure it has the proper mode.
4560 But don't forget to store the value into TARGET. */
4561 temp = convert_to_mode (GET_MODE (target), temp, unsignedp);
4562 emit_move_insn (target, temp);
4565 convert_move (target, temp, unsignedp);
4568 else if (GET_MODE (temp) == BLKmode && TREE_CODE (exp) == STRING_CST)
4570 /* Handle copying a string constant into an array. The string
4571 constant may be shorter than the array. So copy just the string's
4572 actual length, and clear the rest. First get the size of the data
4573 type of the string, which is actually the size of the target. */
4574 rtx size = expr_size (exp);
4576 if (GET_CODE (size) == CONST_INT
4577 && INTVAL (size) < TREE_STRING_LENGTH (exp))
4578 emit_block_move (target, temp, size,
4580 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
4583 /* Compute the size of the data to copy from the string. */
4585 = size_binop (MIN_EXPR,
4586 make_tree (sizetype, size),
4587 size_int (TREE_STRING_LENGTH (exp)));
4589 = expand_expr (copy_size, NULL_RTX, VOIDmode,
4591 ? EXPAND_STACK_PARM : EXPAND_NORMAL));
4594 /* Copy that much. */
4595 copy_size_rtx = convert_to_mode (ptr_mode, copy_size_rtx,
4596 TREE_UNSIGNED (sizetype));
4597 emit_block_move (target, temp, copy_size_rtx,
4599 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
4601 /* Figure out how much is left in TARGET that we have to clear.
4602 Do all calculations in ptr_mode. */
4603 if (GET_CODE (copy_size_rtx) == CONST_INT)
4605 size = plus_constant (size, -INTVAL (copy_size_rtx));
4606 target = adjust_address (target, BLKmode,
4607 INTVAL (copy_size_rtx));
4611 size = expand_binop (TYPE_MODE (sizetype), sub_optab, size,
4612 copy_size_rtx, NULL_RTX, 0,
4615 #ifdef POINTERS_EXTEND_UNSIGNED
4616 if (GET_MODE (copy_size_rtx) != Pmode)
4617 copy_size_rtx = convert_to_mode (Pmode, copy_size_rtx,
4618 TREE_UNSIGNED (sizetype));
4621 target = offset_address (target, copy_size_rtx,
4622 highest_pow2_factor (copy_size));
4623 label = gen_label_rtx ();
4624 emit_cmp_and_jump_insns (size, const0_rtx, LT, NULL_RTX,
4625 GET_MODE (size), 0, label);
4628 if (size != const0_rtx)
4629 clear_storage (target, size);
4635 /* Handle calls that return values in multiple non-contiguous locations.
4636 The Irix 6 ABI has examples of this. */
4637 else if (GET_CODE (target) == PARALLEL)
4638 emit_group_load (target, temp, int_size_in_bytes (TREE_TYPE (exp)));
4639 else if (GET_MODE (temp) == BLKmode)
4640 emit_block_move (target, temp, expr_size (exp),
4642 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
4644 emit_move_insn (target, temp);
4647 /* If we don't want a value, return NULL_RTX. */
4648 if ((want_value & 1) == 0)
4651 /* If we are supposed to return TEMP, do so as long as it isn't a MEM.
4652 ??? The latter test doesn't seem to make sense. */
4653 else if (dont_return_target && GET_CODE (temp) != MEM)
4656 /* Return TARGET itself if it is a hard register. */
4657 else if ((want_value & 1) != 0
4658 && GET_MODE (target) != BLKmode
4659 && ! (GET_CODE (target) == REG
4660 && REGNO (target) < FIRST_PSEUDO_REGISTER))
4661 return copy_to_reg (target);
4667 /* Return 1 if EXP just contains zeros. */
4675 switch (TREE_CODE (exp))
4679 case NON_LVALUE_EXPR:
4680 case VIEW_CONVERT_EXPR:
4681 return is_zeros_p (TREE_OPERAND (exp, 0));
4684 return integer_zerop (exp);
4688 is_zeros_p (TREE_REALPART (exp)) && is_zeros_p (TREE_IMAGPART (exp));
4691 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (exp), dconst0);
4694 for (elt = TREE_VECTOR_CST_ELTS (exp); elt;
4695 elt = TREE_CHAIN (elt))
4696 if (!is_zeros_p (TREE_VALUE (elt)))
4702 if (TREE_TYPE (exp) && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
4703 return CONSTRUCTOR_ELTS (exp) == NULL_TREE;
4704 for (elt = CONSTRUCTOR_ELTS (exp); elt; elt = TREE_CHAIN (elt))
4705 if (! is_zeros_p (TREE_VALUE (elt)))
4715 /* Return 1 if EXP contains mostly (3/4) zeros. */
4718 mostly_zeros_p (exp)
4721 if (TREE_CODE (exp) == CONSTRUCTOR)
4723 int elts = 0, zeros = 0;
4724 tree elt = CONSTRUCTOR_ELTS (exp);
4725 if (TREE_TYPE (exp) && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
4727 /* If there are no ranges of true bits, it is all zero. */
4728 return elt == NULL_TREE;
4730 for (; elt; elt = TREE_CHAIN (elt))
4732 /* We do not handle the case where the index is a RANGE_EXPR,
4733 so the statistic will be somewhat inaccurate.
4734 We do make a more accurate count in store_constructor itself,
4735 so since this function is only used for nested array elements,
4736 this should be close enough. */
4737 if (mostly_zeros_p (TREE_VALUE (elt)))
4742 return 4 * zeros >= 3 * elts;
4745 return is_zeros_p (exp);
4748 /* Helper function for store_constructor.
4749 TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
4750 TYPE is the type of the CONSTRUCTOR, not the element type.
4751 CLEARED is as for store_constructor.
4752 ALIAS_SET is the alias set to use for any stores.
4754 This provides a recursive shortcut back to store_constructor when it isn't
4755 necessary to go through store_field. This is so that we can pass through
4756 the cleared field to let store_constructor know that we may not have to
4757 clear a substructure if the outer structure has already been cleared. */
4760 store_constructor_field (target, bitsize, bitpos, mode, exp, type, cleared,
4763 unsigned HOST_WIDE_INT bitsize;
4764 HOST_WIDE_INT bitpos;
4765 enum machine_mode mode;
4770 if (TREE_CODE (exp) == CONSTRUCTOR
4771 && bitpos % BITS_PER_UNIT == 0
4772 /* If we have a nonzero bitpos for a register target, then we just
4773 let store_field do the bitfield handling. This is unlikely to
4774 generate unnecessary clear instructions anyways. */
4775 && (bitpos == 0 || GET_CODE (target) == MEM))
4777 if (GET_CODE (target) == MEM)
4779 = adjust_address (target,
4780 GET_MODE (target) == BLKmode
4782 % GET_MODE_ALIGNMENT (GET_MODE (target)))
4783 ? BLKmode : VOIDmode, bitpos / BITS_PER_UNIT);
4786 /* Update the alias set, if required. */
4787 if (GET_CODE (target) == MEM && ! MEM_KEEP_ALIAS_SET_P (target)
4788 && MEM_ALIAS_SET (target) != 0)
4790 target = copy_rtx (target);
4791 set_mem_alias_set (target, alias_set);
4794 store_constructor (exp, target, cleared, bitsize / BITS_PER_UNIT);
4797 store_field (target, bitsize, bitpos, mode, exp, VOIDmode, 0, type,
4801 /* Store the value of constructor EXP into the rtx TARGET.
4802 TARGET is either a REG or a MEM; we know it cannot conflict, since
4803 safe_from_p has been called.
4804 CLEARED is true if TARGET is known to have been zero'd.
4805 SIZE is the number of bytes of TARGET we are allowed to modify: this
4806 may not be the same as the size of EXP if we are assigning to a field
4807 which has been packed to exclude padding bits. */
4810 store_constructor (exp, target, cleared, size)
4816 tree type = TREE_TYPE (exp);
4817 #ifdef WORD_REGISTER_OPERATIONS
4818 HOST_WIDE_INT exp_size = int_size_in_bytes (type);
4821 if (TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
4822 || TREE_CODE (type) == QUAL_UNION_TYPE)
4826 /* If size is zero or the target is already cleared, do nothing. */
4827 if (size == 0 || cleared)
4829 /* We either clear the aggregate or indicate the value is dead. */
4830 else if ((TREE_CODE (type) == UNION_TYPE
4831 || TREE_CODE (type) == QUAL_UNION_TYPE)
4832 && ! CONSTRUCTOR_ELTS (exp))
4833 /* If the constructor is empty, clear the union. */
4835 clear_storage (target, expr_size (exp));
4839 /* If we are building a static constructor into a register,
4840 set the initial value as zero so we can fold the value into
4841 a constant. But if more than one register is involved,
4842 this probably loses. */
4843 else if (GET_CODE (target) == REG && TREE_STATIC (exp)
4844 && GET_MODE_SIZE (GET_MODE (target)) <= UNITS_PER_WORD)
4846 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
4850 /* If the constructor has fewer fields than the structure
4851 or if we are initializing the structure to mostly zeros,
4852 clear the whole structure first. Don't do this if TARGET is a
4853 register whose mode size isn't equal to SIZE since clear_storage
4854 can't handle this case. */
4855 else if (((list_length (CONSTRUCTOR_ELTS (exp)) != fields_length (type))
4856 || mostly_zeros_p (exp))
4857 && (GET_CODE (target) != REG
4858 || ((HOST_WIDE_INT) GET_MODE_SIZE (GET_MODE (target))
4861 clear_storage (target, GEN_INT (size));
4866 emit_insn (gen_rtx_CLOBBER (VOIDmode, target));
4868 /* Store each element of the constructor into
4869 the corresponding field of TARGET. */
4871 for (elt = CONSTRUCTOR_ELTS (exp); elt; elt = TREE_CHAIN (elt))
4873 tree field = TREE_PURPOSE (elt);
4874 tree value = TREE_VALUE (elt);
4875 enum machine_mode mode;
4876 HOST_WIDE_INT bitsize;
4877 HOST_WIDE_INT bitpos = 0;
4880 rtx to_rtx = target;
4882 /* Just ignore missing fields.
4883 We cleared the whole structure, above,
4884 if any fields are missing. */
4888 if (cleared && is_zeros_p (value))
4891 if (host_integerp (DECL_SIZE (field), 1))
4892 bitsize = tree_low_cst (DECL_SIZE (field), 1);
4896 unsignedp = TREE_UNSIGNED (field);
4897 mode = DECL_MODE (field);
4898 if (DECL_BIT_FIELD (field))
4901 offset = DECL_FIELD_OFFSET (field);
4902 if (host_integerp (offset, 0)
4903 && host_integerp (bit_position (field), 0))
4905 bitpos = int_bit_position (field);
4909 bitpos = tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 0);
4915 if (contains_placeholder_p (offset))
4916 offset = build (WITH_RECORD_EXPR, sizetype,
4917 offset, make_tree (TREE_TYPE (exp), target));
4919 offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, 0);
4920 if (GET_CODE (to_rtx) != MEM)
4923 #ifdef POINTERS_EXTEND_UNSIGNED
4924 if (GET_MODE (offset_rtx) != Pmode)
4925 offset_rtx = convert_to_mode (Pmode, offset_rtx, 0);
4927 if (GET_MODE (offset_rtx) != ptr_mode)
4928 offset_rtx = convert_to_mode (ptr_mode, offset_rtx, 0);
4931 to_rtx = offset_address (to_rtx, offset_rtx,
4932 highest_pow2_factor (offset));
4935 if (TREE_READONLY (field))
4937 if (GET_CODE (to_rtx) == MEM)
4938 to_rtx = copy_rtx (to_rtx);
4940 RTX_UNCHANGING_P (to_rtx) = 1;
4943 #ifdef WORD_REGISTER_OPERATIONS
4944 /* If this initializes a field that is smaller than a word, at the
4945 start of a word, try to widen it to a full word.
4946 This special case allows us to output C++ member function
4947 initializations in a form that the optimizers can understand. */
4948 if (GET_CODE (target) == REG
4949 && bitsize < BITS_PER_WORD
4950 && bitpos % BITS_PER_WORD == 0
4951 && GET_MODE_CLASS (mode) == MODE_INT
4952 && TREE_CODE (value) == INTEGER_CST
4954 && bitpos + BITS_PER_WORD <= exp_size * BITS_PER_UNIT)
4956 tree type = TREE_TYPE (value);
4958 if (TYPE_PRECISION (type) < BITS_PER_WORD)
4960 type = (*lang_hooks.types.type_for_size)
4961 (BITS_PER_WORD, TREE_UNSIGNED (type));
4962 value = convert (type, value);
4965 if (BYTES_BIG_ENDIAN)
4967 = fold (build (LSHIFT_EXPR, type, value,
4968 build_int_2 (BITS_PER_WORD - bitsize, 0)));
4969 bitsize = BITS_PER_WORD;
4974 if (GET_CODE (to_rtx) == MEM && !MEM_KEEP_ALIAS_SET_P (to_rtx)
4975 && DECL_NONADDRESSABLE_P (field))
4977 to_rtx = copy_rtx (to_rtx);
4978 MEM_KEEP_ALIAS_SET_P (to_rtx) = 1;
4981 store_constructor_field (to_rtx, bitsize, bitpos, mode,
4982 value, type, cleared,
4983 get_alias_set (TREE_TYPE (field)));
4986 else if (TREE_CODE (type) == ARRAY_TYPE
4987 || TREE_CODE (type) == VECTOR_TYPE)
4992 tree domain = TYPE_DOMAIN (type);
4993 tree elttype = TREE_TYPE (type);
4995 HOST_WIDE_INT minelt = 0;
4996 HOST_WIDE_INT maxelt = 0;
4998 /* Vectors are like arrays, but the domain is stored via an array
5000 if (TREE_CODE (type) == VECTOR_TYPE)
5002 /* Note that although TYPE_DEBUG_REPRESENTATION_TYPE uses
5003 the same field as TYPE_DOMAIN, we are not guaranteed that
5005 domain = TYPE_DEBUG_REPRESENTATION_TYPE (type);
5006 domain = TYPE_DOMAIN (TREE_TYPE (TYPE_FIELDS (domain)));
5009 const_bounds_p = (TYPE_MIN_VALUE (domain)
5010 && TYPE_MAX_VALUE (domain)
5011 && host_integerp (TYPE_MIN_VALUE (domain), 0)
5012 && host_integerp (TYPE_MAX_VALUE (domain), 0));
5014 /* If we have constant bounds for the range of the type, get them. */
5017 minelt = tree_low_cst (TYPE_MIN_VALUE (domain), 0);
5018 maxelt = tree_low_cst (TYPE_MAX_VALUE (domain), 0);
5021 /* If the constructor has fewer elements than the array,
5022 clear the whole array first. Similarly if this is
5023 static constructor of a non-BLKmode object. */
5024 if (cleared || (GET_CODE (target) == REG && TREE_STATIC (exp)))
5028 HOST_WIDE_INT count = 0, zero_count = 0;
5029 need_to_clear = ! const_bounds_p;
5031 /* This loop is a more accurate version of the loop in
5032 mostly_zeros_p (it handles RANGE_EXPR in an index).
5033 It is also needed to check for missing elements. */
5034 for (elt = CONSTRUCTOR_ELTS (exp);
5035 elt != NULL_TREE && ! need_to_clear;
5036 elt = TREE_CHAIN (elt))
5038 tree index = TREE_PURPOSE (elt);
5039 HOST_WIDE_INT this_node_count;
5041 if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
5043 tree lo_index = TREE_OPERAND (index, 0);
5044 tree hi_index = TREE_OPERAND (index, 1);
5046 if (! host_integerp (lo_index, 1)
5047 || ! host_integerp (hi_index, 1))
5053 this_node_count = (tree_low_cst (hi_index, 1)
5054 - tree_low_cst (lo_index, 1) + 1);
5057 this_node_count = 1;
5059 count += this_node_count;
5060 if (mostly_zeros_p (TREE_VALUE (elt)))
5061 zero_count += this_node_count;
5064 /* Clear the entire array first if there are any missing elements,
5065 or if the incidence of zero elements is >= 75%. */
5067 && (count < maxelt - minelt + 1 || 4 * zero_count >= 3 * count))
5071 if (need_to_clear && size > 0)
5076 emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
5078 clear_storage (target, GEN_INT (size));
5082 else if (REG_P (target))
5083 /* Inform later passes that the old value is dead. */
5084 emit_insn (gen_rtx_CLOBBER (VOIDmode, target));
5086 /* Store each element of the constructor into
5087 the corresponding element of TARGET, determined
5088 by counting the elements. */
5089 for (elt = CONSTRUCTOR_ELTS (exp), i = 0;
5091 elt = TREE_CHAIN (elt), i++)
5093 enum machine_mode mode;
5094 HOST_WIDE_INT bitsize;
5095 HOST_WIDE_INT bitpos;
5097 tree value = TREE_VALUE (elt);
5098 tree index = TREE_PURPOSE (elt);
5099 rtx xtarget = target;
5101 if (cleared && is_zeros_p (value))
5104 unsignedp = TREE_UNSIGNED (elttype);
5105 mode = TYPE_MODE (elttype);
5106 if (mode == BLKmode)
5107 bitsize = (host_integerp (TYPE_SIZE (elttype), 1)
5108 ? tree_low_cst (TYPE_SIZE (elttype), 1)
5111 bitsize = GET_MODE_BITSIZE (mode);
5113 if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
5115 tree lo_index = TREE_OPERAND (index, 0);
5116 tree hi_index = TREE_OPERAND (index, 1);
5117 rtx index_r, pos_rtx, hi_r, loop_top, loop_end;
5118 struct nesting *loop;
5119 HOST_WIDE_INT lo, hi, count;
5122 /* If the range is constant and "small", unroll the loop. */
5124 && host_integerp (lo_index, 0)
5125 && host_integerp (hi_index, 0)
5126 && (lo = tree_low_cst (lo_index, 0),
5127 hi = tree_low_cst (hi_index, 0),
5128 count = hi - lo + 1,
5129 (GET_CODE (target) != MEM
5131 || (host_integerp (TYPE_SIZE (elttype), 1)
5132 && (tree_low_cst (TYPE_SIZE (elttype), 1) * count
5135 lo -= minelt; hi -= minelt;
5136 for (; lo <= hi; lo++)
5138 bitpos = lo * tree_low_cst (TYPE_SIZE (elttype), 0);
5140 if (GET_CODE (target) == MEM
5141 && !MEM_KEEP_ALIAS_SET_P (target)
5142 && TREE_CODE (type) == ARRAY_TYPE
5143 && TYPE_NONALIASED_COMPONENT (type))
5145 target = copy_rtx (target);
5146 MEM_KEEP_ALIAS_SET_P (target) = 1;
5149 store_constructor_field
5150 (target, bitsize, bitpos, mode, value, type, cleared,
5151 get_alias_set (elttype));
5156 hi_r = expand_expr (hi_index, NULL_RTX, VOIDmode, 0);
5157 loop_top = gen_label_rtx ();
5158 loop_end = gen_label_rtx ();
5160 unsignedp = TREE_UNSIGNED (domain);
5162 index = build_decl (VAR_DECL, NULL_TREE, domain);
5165 = gen_reg_rtx (promote_mode (domain, DECL_MODE (index),
5167 SET_DECL_RTL (index, index_r);
5168 if (TREE_CODE (value) == SAVE_EXPR
5169 && SAVE_EXPR_RTL (value) == 0)
5171 /* Make sure value gets expanded once before the
5173 expand_expr (value, const0_rtx, VOIDmode, 0);
5176 store_expr (lo_index, index_r, 0);
5177 loop = expand_start_loop (0);
5179 /* Assign value to element index. */
5181 = convert (ssizetype,
5182 fold (build (MINUS_EXPR, TREE_TYPE (index),
5183 index, TYPE_MIN_VALUE (domain))));
5184 position = size_binop (MULT_EXPR, position,
5186 TYPE_SIZE_UNIT (elttype)));
5188 pos_rtx = expand_expr (position, 0, VOIDmode, 0);
5189 xtarget = offset_address (target, pos_rtx,
5190 highest_pow2_factor (position));
5191 xtarget = adjust_address (xtarget, mode, 0);
5192 if (TREE_CODE (value) == CONSTRUCTOR)
5193 store_constructor (value, xtarget, cleared,
5194 bitsize / BITS_PER_UNIT);
5196 store_expr (value, xtarget, 0);
5198 expand_exit_loop_if_false (loop,
5199 build (LT_EXPR, integer_type_node,
5202 expand_increment (build (PREINCREMENT_EXPR,
5204 index, integer_one_node), 0, 0);
5206 emit_label (loop_end);
5209 else if ((index != 0 && ! host_integerp (index, 0))
5210 || ! host_integerp (TYPE_SIZE (elttype), 1))
5215 index = ssize_int (1);
5218 index = convert (ssizetype,
5219 fold (build (MINUS_EXPR, index,
5220 TYPE_MIN_VALUE (domain))));
5222 position = size_binop (MULT_EXPR, index,
5224 TYPE_SIZE_UNIT (elttype)));
5225 xtarget = offset_address (target,
5226 expand_expr (position, 0, VOIDmode, 0),
5227 highest_pow2_factor (position));
5228 xtarget = adjust_address (xtarget, mode, 0);
5229 store_expr (value, xtarget, 0);
5234 bitpos = ((tree_low_cst (index, 0) - minelt)
5235 * tree_low_cst (TYPE_SIZE (elttype), 1));
5237 bitpos = (i * tree_low_cst (TYPE_SIZE (elttype), 1));
5239 if (GET_CODE (target) == MEM && !MEM_KEEP_ALIAS_SET_P (target)
5240 && TREE_CODE (type) == ARRAY_TYPE
5241 && TYPE_NONALIASED_COMPONENT (type))
5243 target = copy_rtx (target);
5244 MEM_KEEP_ALIAS_SET_P (target) = 1;
5247 store_constructor_field (target, bitsize, bitpos, mode, value,
5248 type, cleared, get_alias_set (elttype));
5254 /* Set constructor assignments. */
5255 else if (TREE_CODE (type) == SET_TYPE)
5257 tree elt = CONSTRUCTOR_ELTS (exp);
5258 unsigned HOST_WIDE_INT nbytes = int_size_in_bytes (type), nbits;
5259 tree domain = TYPE_DOMAIN (type);
5260 tree domain_min, domain_max, bitlength;
5262 /* The default implementation strategy is to extract the constant
5263 parts of the constructor, use that to initialize the target,
5264 and then "or" in whatever non-constant ranges we need in addition.
5266 If a large set is all zero or all ones, it is
5267 probably better to set it using memset (if available) or bzero.
5268 Also, if a large set has just a single range, it may also be
5269 better to first clear all the first clear the set (using
5270 bzero/memset), and set the bits we want. */
5272 /* Check for all zeros. */
5273 if (elt == NULL_TREE && size > 0)
5276 clear_storage (target, GEN_INT (size));
5280 domain_min = convert (sizetype, TYPE_MIN_VALUE (domain));
5281 domain_max = convert (sizetype, TYPE_MAX_VALUE (domain));
5282 bitlength = size_binop (PLUS_EXPR,
5283 size_diffop (domain_max, domain_min),
5286 nbits = tree_low_cst (bitlength, 1);
5288 /* For "small" sets, or "medium-sized" (up to 32 bytes) sets that
5289 are "complicated" (more than one range), initialize (the
5290 constant parts) by copying from a constant. */
5291 if (GET_MODE (target) != BLKmode || nbits <= 2 * BITS_PER_WORD
5292 || (nbytes <= 32 && TREE_CHAIN (elt) != NULL_TREE))
5294 unsigned int set_word_size = TYPE_ALIGN (TREE_TYPE (exp));
5295 enum machine_mode mode = mode_for_size (set_word_size, MODE_INT, 1);
5296 char *bit_buffer = (char *) alloca (nbits);
5297 HOST_WIDE_INT word = 0;
5298 unsigned int bit_pos = 0;
5299 unsigned int ibit = 0;
5300 unsigned int offset = 0; /* In bytes from beginning of set. */
5302 elt = get_set_constructor_bits (exp, bit_buffer, nbits);
5305 if (bit_buffer[ibit])
5307 if (BYTES_BIG_ENDIAN)
5308 word |= (1 << (set_word_size - 1 - bit_pos));
5310 word |= 1 << bit_pos;
5314 if (bit_pos >= set_word_size || ibit == nbits)
5316 if (word != 0 || ! cleared)
5318 rtx datum = GEN_INT (word);
5321 /* The assumption here is that it is safe to use
5322 XEXP if the set is multi-word, but not if
5323 it's single-word. */
5324 if (GET_CODE (target) == MEM)
5325 to_rtx = adjust_address (target, mode, offset);
5326 else if (offset == 0)
5330 emit_move_insn (to_rtx, datum);
5337 offset += set_word_size / BITS_PER_UNIT;
5342 /* Don't bother clearing storage if the set is all ones. */
5343 if (TREE_CHAIN (elt) != NULL_TREE
5344 || (TREE_PURPOSE (elt) == NULL_TREE
5346 : ( ! host_integerp (TREE_VALUE (elt), 0)
5347 || ! host_integerp (TREE_PURPOSE (elt), 0)
5348 || (tree_low_cst (TREE_VALUE (elt), 0)
5349 - tree_low_cst (TREE_PURPOSE (elt), 0) + 1
5350 != (HOST_WIDE_INT) nbits))))
5351 clear_storage (target, expr_size (exp));
5353 for (; elt != NULL_TREE; elt = TREE_CHAIN (elt))
5355 /* Start of range of element or NULL. */
5356 tree startbit = TREE_PURPOSE (elt);
5357 /* End of range of element, or element value. */
5358 tree endbit = TREE_VALUE (elt);
5359 HOST_WIDE_INT startb, endb;
5360 rtx bitlength_rtx, startbit_rtx, endbit_rtx, targetx;
5362 bitlength_rtx = expand_expr (bitlength,
5363 NULL_RTX, MEM, EXPAND_CONST_ADDRESS);
5365 /* Handle non-range tuple element like [ expr ]. */
5366 if (startbit == NULL_TREE)
5368 startbit = save_expr (endbit);
5372 startbit = convert (sizetype, startbit);
5373 endbit = convert (sizetype, endbit);
5374 if (! integer_zerop (domain_min))
5376 startbit = size_binop (MINUS_EXPR, startbit, domain_min);
5377 endbit = size_binop (MINUS_EXPR, endbit, domain_min);
5379 startbit_rtx = expand_expr (startbit, NULL_RTX, MEM,
5380 EXPAND_CONST_ADDRESS);
5381 endbit_rtx = expand_expr (endbit, NULL_RTX, MEM,
5382 EXPAND_CONST_ADDRESS);
5388 ((build_qualified_type ((*lang_hooks.types.type_for_mode)
5389 (GET_MODE (target), 0),
5392 emit_move_insn (targetx, target);
5395 else if (GET_CODE (target) == MEM)
5400 /* Optimization: If startbit and endbit are constants divisible
5401 by BITS_PER_UNIT, call memset instead. */
5402 if (TARGET_MEM_FUNCTIONS
5403 && TREE_CODE (startbit) == INTEGER_CST
5404 && TREE_CODE (endbit) == INTEGER_CST
5405 && (startb = TREE_INT_CST_LOW (startbit)) % BITS_PER_UNIT == 0
5406 && (endb = TREE_INT_CST_LOW (endbit) + 1) % BITS_PER_UNIT == 0)
5408 emit_library_call (memset_libfunc, LCT_NORMAL,
5410 plus_constant (XEXP (targetx, 0),
5411 startb / BITS_PER_UNIT),
5413 constm1_rtx, TYPE_MODE (integer_type_node),
5414 GEN_INT ((endb - startb) / BITS_PER_UNIT),
5415 TYPE_MODE (sizetype));
5418 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__setbits"),
5419 LCT_NORMAL, VOIDmode, 4, XEXP (targetx, 0),
5420 Pmode, bitlength_rtx, TYPE_MODE (sizetype),
5421 startbit_rtx, TYPE_MODE (sizetype),
5422 endbit_rtx, TYPE_MODE (sizetype));
5425 emit_move_insn (target, targetx);
5433 /* Store the value of EXP (an expression tree)
5434 into a subfield of TARGET which has mode MODE and occupies
5435 BITSIZE bits, starting BITPOS bits from the start of TARGET.
5436 If MODE is VOIDmode, it means that we are storing into a bit-field.
5438 If VALUE_MODE is VOIDmode, return nothing in particular.
5439 UNSIGNEDP is not used in this case.
5441 Otherwise, return an rtx for the value stored. This rtx
5442 has mode VALUE_MODE if that is convenient to do.
5443 In this case, UNSIGNEDP must be nonzero if the value is an unsigned type.
5445 TYPE is the type of the underlying object,
5447 ALIAS_SET is the alias set for the destination. This value will
5448 (in general) be different from that for TARGET, since TARGET is a
5449 reference to the containing structure. */
5452 store_field (target, bitsize, bitpos, mode, exp, value_mode, unsignedp, type,
5455 HOST_WIDE_INT bitsize;
5456 HOST_WIDE_INT bitpos;
5457 enum machine_mode mode;
5459 enum machine_mode value_mode;
5464 HOST_WIDE_INT width_mask = 0;
5466 if (TREE_CODE (exp) == ERROR_MARK)
5469 /* If we have nothing to store, do nothing unless the expression has
5472 return expand_expr (exp, const0_rtx, VOIDmode, 0);
5473 else if (bitsize >=0 && bitsize < HOST_BITS_PER_WIDE_INT)
5474 width_mask = ((HOST_WIDE_INT) 1 << bitsize) - 1;
5476 /* If we are storing into an unaligned field of an aligned union that is
5477 in a register, we may have the mode of TARGET being an integer mode but
5478 MODE == BLKmode. In that case, get an aligned object whose size and
5479 alignment are the same as TARGET and store TARGET into it (we can avoid
5480 the store if the field being stored is the entire width of TARGET). Then
5481 call ourselves recursively to store the field into a BLKmode version of
5482 that object. Finally, load from the object into TARGET. This is not
5483 very efficient in general, but should only be slightly more expensive
5484 than the otherwise-required unaligned accesses. Perhaps this can be
5485 cleaned up later. */
5488 && (GET_CODE (target) == REG || GET_CODE (target) == SUBREG))
5492 (build_qualified_type (type, TYPE_QUALS (type) | TYPE_QUAL_CONST),
5494 rtx blk_object = adjust_address (object, BLKmode, 0);
5496 if (bitsize != (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (target)))
5497 emit_move_insn (object, target);
5499 store_field (blk_object, bitsize, bitpos, mode, exp, VOIDmode, 0, type,
5502 emit_move_insn (target, object);
5504 /* We want to return the BLKmode version of the data. */
5508 if (GET_CODE (target) == CONCAT)
5510 /* We're storing into a struct containing a single __complex. */
5514 return store_expr (exp, target, 0);
5517 /* If the structure is in a register or if the component
5518 is a bit field, we cannot use addressing to access it.
5519 Use bit-field techniques or SUBREG to store in it. */
5521 if (mode == VOIDmode
5522 || (mode != BLKmode && ! direct_store[(int) mode]
5523 && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
5524 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT)
5525 || GET_CODE (target) == REG
5526 || GET_CODE (target) == SUBREG
5527 /* If the field isn't aligned enough to store as an ordinary memref,
5528 store it as a bit field. */
5529 || (mode != BLKmode && SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (target))
5530 && (MEM_ALIGN (target) < GET_MODE_ALIGNMENT (mode)
5531 || bitpos % GET_MODE_ALIGNMENT (mode)))
5532 /* If the RHS and field are a constant size and the size of the
5533 RHS isn't the same size as the bitfield, we must use bitfield
5536 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) == INTEGER_CST
5537 && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)), bitsize) != 0))
5539 rtx temp = expand_expr (exp, NULL_RTX, VOIDmode, 0);
5541 /* If BITSIZE is narrower than the size of the type of EXP
5542 we will be narrowing TEMP. Normally, what's wanted are the
5543 low-order bits. However, if EXP's type is a record and this is
5544 big-endian machine, we want the upper BITSIZE bits. */
5545 if (BYTES_BIG_ENDIAN && GET_MODE_CLASS (GET_MODE (temp)) == MODE_INT
5546 && bitsize < (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (temp))
5547 && TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
5548 temp = expand_shift (RSHIFT_EXPR, GET_MODE (temp), temp,
5549 size_int (GET_MODE_BITSIZE (GET_MODE (temp))
5553 /* Unless MODE is VOIDmode or BLKmode, convert TEMP to
5555 if (mode != VOIDmode && mode != BLKmode
5556 && mode != TYPE_MODE (TREE_TYPE (exp)))
5557 temp = convert_modes (mode, TYPE_MODE (TREE_TYPE (exp)), temp, 1);
5559 /* If the modes of TARGET and TEMP are both BLKmode, both
5560 must be in memory and BITPOS must be aligned on a byte
5561 boundary. If so, we simply do a block copy. */
5562 if (GET_MODE (target) == BLKmode && GET_MODE (temp) == BLKmode)
5564 if (GET_CODE (target) != MEM || GET_CODE (temp) != MEM
5565 || bitpos % BITS_PER_UNIT != 0)
5568 target = adjust_address (target, VOIDmode, bitpos / BITS_PER_UNIT);
5569 emit_block_move (target, temp,
5570 GEN_INT ((bitsize + BITS_PER_UNIT - 1)
5574 return value_mode == VOIDmode ? const0_rtx : target;
5577 /* Store the value in the bitfield. */
5578 store_bit_field (target, bitsize, bitpos, mode, temp,
5579 int_size_in_bytes (type));
5581 if (value_mode != VOIDmode)
5583 /* The caller wants an rtx for the value.
5584 If possible, avoid refetching from the bitfield itself. */
5586 && ! (GET_CODE (target) == MEM && MEM_VOLATILE_P (target)))
5589 enum machine_mode tmode;
5591 tmode = GET_MODE (temp);
5592 if (tmode == VOIDmode)
5596 return expand_and (tmode, temp,
5597 gen_int_mode (width_mask, tmode),
5600 count = build_int_2 (GET_MODE_BITSIZE (tmode) - bitsize, 0);
5601 temp = expand_shift (LSHIFT_EXPR, tmode, temp, count, 0, 0);
5602 return expand_shift (RSHIFT_EXPR, tmode, temp, count, 0, 0);
5605 return extract_bit_field (target, bitsize, bitpos, unsignedp,
5606 NULL_RTX, value_mode, VOIDmode,
5607 int_size_in_bytes (type));
5613 rtx addr = XEXP (target, 0);
5614 rtx to_rtx = target;
5616 /* If a value is wanted, it must be the lhs;
5617 so make the address stable for multiple use. */
5619 if (value_mode != VOIDmode && GET_CODE (addr) != REG
5620 && ! CONSTANT_ADDRESS_P (addr)
5621 /* A frame-pointer reference is already stable. */
5622 && ! (GET_CODE (addr) == PLUS
5623 && GET_CODE (XEXP (addr, 1)) == CONST_INT
5624 && (XEXP (addr, 0) == virtual_incoming_args_rtx
5625 || XEXP (addr, 0) == virtual_stack_vars_rtx)))
5626 to_rtx = replace_equiv_address (to_rtx, copy_to_reg (addr));
5628 /* Now build a reference to just the desired component. */
5630 to_rtx = adjust_address (target, mode, bitpos / BITS_PER_UNIT);
5632 if (to_rtx == target)
5633 to_rtx = copy_rtx (to_rtx);
5635 MEM_SET_IN_STRUCT_P (to_rtx, 1);
5636 if (!MEM_KEEP_ALIAS_SET_P (to_rtx) && MEM_ALIAS_SET (to_rtx) != 0)
5637 set_mem_alias_set (to_rtx, alias_set);
5639 return store_expr (exp, to_rtx, value_mode != VOIDmode);
5643 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
5644 an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
5645 codes and find the ultimate containing object, which we return.
5647 We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
5648 bit position, and *PUNSIGNEDP to the signedness of the field.
5649 If the position of the field is variable, we store a tree
5650 giving the variable offset (in units) in *POFFSET.
5651 This offset is in addition to the bit position.
5652 If the position is not variable, we store 0 in *POFFSET.
5654 If any of the extraction expressions is volatile,
5655 we store 1 in *PVOLATILEP. Otherwise we don't change that.
5657 If the field is a bit-field, *PMODE is set to VOIDmode. Otherwise, it
5658 is a mode that can be used to access the field. In that case, *PBITSIZE
5661 If the field describes a variable-sized object, *PMODE is set to
5662 VOIDmode and *PBITSIZE is set to -1. An access cannot be made in
5663 this case, but the address of the object can be found. */
5666 get_inner_reference (exp, pbitsize, pbitpos, poffset, pmode,
5667 punsignedp, pvolatilep)
5669 HOST_WIDE_INT *pbitsize;
5670 HOST_WIDE_INT *pbitpos;
5672 enum machine_mode *pmode;
5677 enum machine_mode mode = VOIDmode;
5678 tree offset = size_zero_node;
5679 tree bit_offset = bitsize_zero_node;
5680 tree placeholder_ptr = 0;
5683 /* First get the mode, signedness, and size. We do this from just the
5684 outermost expression. */
5685 if (TREE_CODE (exp) == COMPONENT_REF)
5687 size_tree = DECL_SIZE (TREE_OPERAND (exp, 1));
5688 if (! DECL_BIT_FIELD (TREE_OPERAND (exp, 1)))
5689 mode = DECL_MODE (TREE_OPERAND (exp, 1));
5691 *punsignedp = TREE_UNSIGNED (TREE_OPERAND (exp, 1));
5693 else if (TREE_CODE (exp) == BIT_FIELD_REF)
5695 size_tree = TREE_OPERAND (exp, 1);
5696 *punsignedp = TREE_UNSIGNED (exp);
5700 mode = TYPE_MODE (TREE_TYPE (exp));
5701 *punsignedp = TREE_UNSIGNED (TREE_TYPE (exp));
5703 if (mode == BLKmode)
5704 size_tree = TYPE_SIZE (TREE_TYPE (exp));
5706 *pbitsize = GET_MODE_BITSIZE (mode);
5711 if (! host_integerp (size_tree, 1))
5712 mode = BLKmode, *pbitsize = -1;
5714 *pbitsize = tree_low_cst (size_tree, 1);
5717 /* Compute cumulative bit-offset for nested component-refs and array-refs,
5718 and find the ultimate containing object. */
5721 if (TREE_CODE (exp) == BIT_FIELD_REF)
5722 bit_offset = size_binop (PLUS_EXPR, bit_offset, TREE_OPERAND (exp, 2));
5723 else if (TREE_CODE (exp) == COMPONENT_REF)
5725 tree field = TREE_OPERAND (exp, 1);
5726 tree this_offset = DECL_FIELD_OFFSET (field);
5728 /* If this field hasn't been filled in yet, don't go
5729 past it. This should only happen when folding expressions
5730 made during type construction. */
5731 if (this_offset == 0)
5733 else if (! TREE_CONSTANT (this_offset)
5734 && contains_placeholder_p (this_offset))
5735 this_offset = build (WITH_RECORD_EXPR, sizetype, this_offset, exp);
5737 offset = size_binop (PLUS_EXPR, offset, this_offset);
5738 bit_offset = size_binop (PLUS_EXPR, bit_offset,
5739 DECL_FIELD_BIT_OFFSET (field));
5741 /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
5744 else if (TREE_CODE (exp) == ARRAY_REF
5745 || TREE_CODE (exp) == ARRAY_RANGE_REF)
5747 tree index = TREE_OPERAND (exp, 1);
5748 tree array = TREE_OPERAND (exp, 0);
5749 tree domain = TYPE_DOMAIN (TREE_TYPE (array));
5750 tree low_bound = (domain ? TYPE_MIN_VALUE (domain) : 0);
5751 tree unit_size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (array)));
5753 /* We assume all arrays have sizes that are a multiple of a byte.
5754 First subtract the lower bound, if any, in the type of the
5755 index, then convert to sizetype and multiply by the size of the
5757 if (low_bound != 0 && ! integer_zerop (low_bound))
5758 index = fold (build (MINUS_EXPR, TREE_TYPE (index),
5761 /* If the index has a self-referential type, pass it to a
5762 WITH_RECORD_EXPR; if the component size is, pass our
5763 component to one. */
5764 if (! TREE_CONSTANT (index)
5765 && contains_placeholder_p (index))
5766 index = build (WITH_RECORD_EXPR, TREE_TYPE (index), index, exp);
5767 if (! TREE_CONSTANT (unit_size)
5768 && contains_placeholder_p (unit_size))
5769 unit_size = build (WITH_RECORD_EXPR, sizetype, unit_size, array);
5771 offset = size_binop (PLUS_EXPR, offset,
5772 size_binop (MULT_EXPR,
5773 convert (sizetype, index),
5777 else if (TREE_CODE (exp) == PLACEHOLDER_EXPR)
5779 tree new = find_placeholder (exp, &placeholder_ptr);
5781 /* If we couldn't find the replacement, return the PLACEHOLDER_EXPR.
5782 We might have been called from tree optimization where we
5783 haven't set up an object yet. */
5791 else if (TREE_CODE (exp) != NON_LVALUE_EXPR
5792 && TREE_CODE (exp) != VIEW_CONVERT_EXPR
5793 && ! ((TREE_CODE (exp) == NOP_EXPR
5794 || TREE_CODE (exp) == CONVERT_EXPR)
5795 && (TYPE_MODE (TREE_TYPE (exp))
5796 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))))))
5799 /* If any reference in the chain is volatile, the effect is volatile. */
5800 if (TREE_THIS_VOLATILE (exp))
5803 exp = TREE_OPERAND (exp, 0);
5806 /* If OFFSET is constant, see if we can return the whole thing as a
5807 constant bit position. Otherwise, split it up. */
5808 if (host_integerp (offset, 0)
5809 && 0 != (tem = size_binop (MULT_EXPR, convert (bitsizetype, offset),
5811 && 0 != (tem = size_binop (PLUS_EXPR, tem, bit_offset))
5812 && host_integerp (tem, 0))
5813 *pbitpos = tree_low_cst (tem, 0), *poffset = 0;
5815 *pbitpos = tree_low_cst (bit_offset, 0), *poffset = offset;
5821 /* Return 1 if T is an expression that get_inner_reference handles. */
5824 handled_component_p (t)
5827 switch (TREE_CODE (t))
5832 case ARRAY_RANGE_REF:
5833 case NON_LVALUE_EXPR:
5834 case VIEW_CONVERT_EXPR:
5839 return (TYPE_MODE (TREE_TYPE (t))
5840 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (t, 0))));
5847 /* Given an rtx VALUE that may contain additions and multiplications, return
5848 an equivalent value that just refers to a register, memory, or constant.
5849 This is done by generating instructions to perform the arithmetic and
5850 returning a pseudo-register containing the value.
5852 The returned value may be a REG, SUBREG, MEM or constant. */
5855 force_operand (value, target)
5859 /* Use subtarget as the target for operand 0 of a binary operation. */
5860 rtx subtarget = get_subtarget (target);
5861 enum rtx_code code = GET_CODE (value);
5863 /* Check for a PIC address load. */
5864 if ((code == PLUS || code == MINUS)
5865 && XEXP (value, 0) == pic_offset_table_rtx
5866 && (GET_CODE (XEXP (value, 1)) == SYMBOL_REF
5867 || GET_CODE (XEXP (value, 1)) == LABEL_REF
5868 || GET_CODE (XEXP (value, 1)) == CONST))
5871 subtarget = gen_reg_rtx (GET_MODE (value));
5872 emit_move_insn (subtarget, value);
5876 if (code == ZERO_EXTEND || code == SIGN_EXTEND)
5879 target = gen_reg_rtx (GET_MODE (value));
5880 convert_move (target, force_operand (XEXP (value, 0), NULL),
5881 code == ZERO_EXTEND);
5885 if (GET_RTX_CLASS (code) == '2' || GET_RTX_CLASS (code) == 'c')
5887 op2 = XEXP (value, 1);
5888 if (!CONSTANT_P (op2) && !(GET_CODE (op2) == REG && op2 != subtarget))
5890 if (code == MINUS && GET_CODE (op2) == CONST_INT)
5893 op2 = negate_rtx (GET_MODE (value), op2);
5896 /* Check for an addition with OP2 a constant integer and our first
5897 operand a PLUS of a virtual register and something else. In that
5898 case, we want to emit the sum of the virtual register and the
5899 constant first and then add the other value. This allows virtual
5900 register instantiation to simply modify the constant rather than
5901 creating another one around this addition. */
5902 if (code == PLUS && GET_CODE (op2) == CONST_INT
5903 && GET_CODE (XEXP (value, 0)) == PLUS
5904 && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
5905 && REGNO (XEXP (XEXP (value, 0), 0)) >= FIRST_VIRTUAL_REGISTER
5906 && REGNO (XEXP (XEXP (value, 0), 0)) <= LAST_VIRTUAL_REGISTER)
5908 rtx temp = expand_simple_binop (GET_MODE (value), code,
5909 XEXP (XEXP (value, 0), 0), op2,
5910 subtarget, 0, OPTAB_LIB_WIDEN);
5911 return expand_simple_binop (GET_MODE (value), code, temp,
5912 force_operand (XEXP (XEXP (value,
5914 target, 0, OPTAB_LIB_WIDEN);
5917 op1 = force_operand (XEXP (value, 0), subtarget);
5918 op2 = force_operand (op2, NULL_RTX);
5922 return expand_mult (GET_MODE (value), op1, op2, target, 1);
5924 if (!INTEGRAL_MODE_P (GET_MODE (value)))
5925 return expand_simple_binop (GET_MODE (value), code, op1, op2,
5926 target, 1, OPTAB_LIB_WIDEN);
5928 return expand_divmod (0,
5929 FLOAT_MODE_P (GET_MODE (value))
5930 ? RDIV_EXPR : TRUNC_DIV_EXPR,
5931 GET_MODE (value), op1, op2, target, 0);
5934 return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
5938 return expand_divmod (0, TRUNC_DIV_EXPR, GET_MODE (value), op1, op2,
5942 return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
5946 return expand_simple_binop (GET_MODE (value), code, op1, op2,
5947 target, 0, OPTAB_LIB_WIDEN);
5950 return expand_simple_binop (GET_MODE (value), code, op1, op2,
5951 target, 1, OPTAB_LIB_WIDEN);
5954 if (GET_RTX_CLASS (code) == '1')
5956 op1 = force_operand (XEXP (value, 0), NULL_RTX);
5957 return expand_simple_unop (GET_MODE (value), code, op1, target, 0);
5960 #ifdef INSN_SCHEDULING
5961 /* On machines that have insn scheduling, we want all memory reference to be
5962 explicit, so we need to deal with such paradoxical SUBREGs. */
5963 if (GET_CODE (value) == SUBREG && GET_CODE (SUBREG_REG (value)) == MEM
5964 && (GET_MODE_SIZE (GET_MODE (value))
5965 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (value)))))
5967 = simplify_gen_subreg (GET_MODE (value),
5968 force_reg (GET_MODE (SUBREG_REG (value)),
5969 force_operand (SUBREG_REG (value),
5971 GET_MODE (SUBREG_REG (value)),
5972 SUBREG_BYTE (value));
5978 /* Subroutine of expand_expr: return nonzero iff there is no way that
5979 EXP can reference X, which is being modified. TOP_P is nonzero if this
5980 call is going to be used to determine whether we need a temporary
5981 for EXP, as opposed to a recursive call to this function.
5983 It is always safe for this routine to return zero since it merely
5984 searches for optimization opportunities. */
5987 safe_from_p (x, exp, top_p)
5994 static tree save_expr_list;
5997 /* If EXP has varying size, we MUST use a target since we currently
5998 have no way of allocating temporaries of variable size
5999 (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
6000 So we assume here that something at a higher level has prevented a
6001 clash. This is somewhat bogus, but the best we can do. Only
6002 do this when X is BLKmode and when we are at the top level. */
6003 || (top_p && TREE_TYPE (exp) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp))
6004 && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) != INTEGER_CST
6005 && (TREE_CODE (TREE_TYPE (exp)) != ARRAY_TYPE
6006 || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)) == NULL_TREE
6007 || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)))
6009 && GET_MODE (x) == BLKmode)
6010 /* If X is in the outgoing argument area, it is always safe. */
6011 || (GET_CODE (x) == MEM
6012 && (XEXP (x, 0) == virtual_outgoing_args_rtx
6013 || (GET_CODE (XEXP (x, 0)) == PLUS
6014 && XEXP (XEXP (x, 0), 0) == virtual_outgoing_args_rtx))))
6017 /* If this is a subreg of a hard register, declare it unsafe, otherwise,
6018 find the underlying pseudo. */
6019 if (GET_CODE (x) == SUBREG)
6022 if (GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER)
6026 /* A SAVE_EXPR might appear many times in the expression passed to the
6027 top-level safe_from_p call, and if it has a complex subexpression,
6028 examining it multiple times could result in a combinatorial explosion.
6029 E.g. on an Alpha running at least 200MHz, a Fortran test case compiled
6030 with optimization took about 28 minutes to compile -- even though it was
6031 only a few lines long. So we mark each SAVE_EXPR we see with TREE_PRIVATE
6032 and turn that off when we are done. We keep a list of the SAVE_EXPRs
6033 we have processed. Note that the only test of top_p was above. */
6042 rtn = safe_from_p (x, exp, 0);
6044 for (t = save_expr_list; t != 0; t = TREE_CHAIN (t))
6045 TREE_PRIVATE (TREE_PURPOSE (t)) = 0;
6050 /* Now look at our tree code and possibly recurse. */
6051 switch (TREE_CODE_CLASS (TREE_CODE (exp)))
6054 exp_rtl = DECL_RTL_IF_SET (exp);
6061 if (TREE_CODE (exp) == TREE_LIST)
6065 if (TREE_VALUE (exp) && !safe_from_p (x, TREE_VALUE (exp), 0))
6067 exp = TREE_CHAIN (exp);
6070 if (TREE_CODE (exp) != TREE_LIST)
6071 return safe_from_p (x, exp, 0);
6074 else if (TREE_CODE (exp) == ERROR_MARK)
6075 return 1; /* An already-visited SAVE_EXPR? */
6081 if (!safe_from_p (x, TREE_OPERAND (exp, 1), 0))
6086 return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
6090 /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
6091 the expression. If it is set, we conflict iff we are that rtx or
6092 both are in memory. Otherwise, we check all operands of the
6093 expression recursively. */
6095 switch (TREE_CODE (exp))
6098 /* If the operand is static or we are static, we can't conflict.
6099 Likewise if we don't conflict with the operand at all. */
6100 if (staticp (TREE_OPERAND (exp, 0))
6101 || TREE_STATIC (exp)
6102 || safe_from_p (x, TREE_OPERAND (exp, 0), 0))
6105 /* Otherwise, the only way this can conflict is if we are taking
6106 the address of a DECL a that address if part of X, which is
6108 exp = TREE_OPERAND (exp, 0);
6111 if (!DECL_RTL_SET_P (exp)
6112 || GET_CODE (DECL_RTL (exp)) != MEM)
6115 exp_rtl = XEXP (DECL_RTL (exp), 0);
6120 if (GET_CODE (x) == MEM
6121 && alias_sets_conflict_p (MEM_ALIAS_SET (x),
6122 get_alias_set (exp)))
6127 /* Assume that the call will clobber all hard registers and
6129 if ((GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER)
6130 || GET_CODE (x) == MEM)
6135 /* If a sequence exists, we would have to scan every instruction
6136 in the sequence to see if it was safe. This is probably not
6138 if (RTL_EXPR_SEQUENCE (exp))
6141 exp_rtl = RTL_EXPR_RTL (exp);
6144 case WITH_CLEANUP_EXPR:
6145 exp_rtl = WITH_CLEANUP_EXPR_RTL (exp);
6148 case CLEANUP_POINT_EXPR:
6149 return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
6152 exp_rtl = SAVE_EXPR_RTL (exp);
6156 /* If we've already scanned this, don't do it again. Otherwise,
6157 show we've scanned it and record for clearing the flag if we're
6159 if (TREE_PRIVATE (exp))
6162 TREE_PRIVATE (exp) = 1;
6163 if (! safe_from_p (x, TREE_OPERAND (exp, 0), 0))
6165 TREE_PRIVATE (exp) = 0;
6169 save_expr_list = tree_cons (exp, NULL_TREE, save_expr_list);
6173 /* The only operand we look at is operand 1. The rest aren't
6174 part of the expression. */
6175 return safe_from_p (x, TREE_OPERAND (exp, 1), 0);
6177 case METHOD_CALL_EXPR:
6178 /* This takes an rtx argument, but shouldn't appear here. */
6185 /* If we have an rtx, we do not need to scan our operands. */
6189 nops = first_rtl_op (TREE_CODE (exp));
6190 for (i = 0; i < nops; i++)
6191 if (TREE_OPERAND (exp, i) != 0
6192 && ! safe_from_p (x, TREE_OPERAND (exp, i), 0))
6195 /* If this is a language-specific tree code, it may require
6196 special handling. */
6197 if ((unsigned int) TREE_CODE (exp)
6198 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
6199 && !(*lang_hooks.safe_from_p) (x, exp))
6203 /* If we have an rtl, find any enclosed object. Then see if we conflict
6207 if (GET_CODE (exp_rtl) == SUBREG)
6209 exp_rtl = SUBREG_REG (exp_rtl);
6210 if (GET_CODE (exp_rtl) == REG
6211 && REGNO (exp_rtl) < FIRST_PSEUDO_REGISTER)
6215 /* If the rtl is X, then it is not safe. Otherwise, it is unless both
6216 are memory and they conflict. */
6217 return ! (rtx_equal_p (x, exp_rtl)
6218 || (GET_CODE (x) == MEM && GET_CODE (exp_rtl) == MEM
6219 && true_dependence (exp_rtl, VOIDmode, x,
6220 rtx_addr_varies_p)));
6223 /* If we reach here, it is safe. */
6227 /* Subroutine of expand_expr: return rtx if EXP is a
6228 variable or parameter; else return 0. */
6235 switch (TREE_CODE (exp))
6239 return DECL_RTL (exp);
6245 #ifdef MAX_INTEGER_COMPUTATION_MODE
6248 check_max_integer_computation_mode (exp)
6251 enum tree_code code;
6252 enum machine_mode mode;
6254 /* Strip any NOPs that don't change the mode. */
6256 code = TREE_CODE (exp);
6258 /* We must allow conversions of constants to MAX_INTEGER_COMPUTATION_MODE. */
6259 if (code == NOP_EXPR
6260 && TREE_CODE (TREE_OPERAND (exp, 0)) == INTEGER_CST)
6263 /* First check the type of the overall operation. We need only look at
6264 unary, binary and relational operations. */
6265 if (TREE_CODE_CLASS (code) == '1'
6266 || TREE_CODE_CLASS (code) == '2'
6267 || TREE_CODE_CLASS (code) == '<')
6269 mode = TYPE_MODE (TREE_TYPE (exp));
6270 if (GET_MODE_CLASS (mode) == MODE_INT
6271 && mode > MAX_INTEGER_COMPUTATION_MODE)
6272 internal_error ("unsupported wide integer operation");
6275 /* Check operand of a unary op. */
6276 if (TREE_CODE_CLASS (code) == '1')
6278 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
6279 if (GET_MODE_CLASS (mode) == MODE_INT
6280 && mode > MAX_INTEGER_COMPUTATION_MODE)
6281 internal_error ("unsupported wide integer operation");
6284 /* Check operands of a binary/comparison op. */
6285 if (TREE_CODE_CLASS (code) == '2' || TREE_CODE_CLASS (code) == '<')
6287 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
6288 if (GET_MODE_CLASS (mode) == MODE_INT
6289 && mode > MAX_INTEGER_COMPUTATION_MODE)
6290 internal_error ("unsupported wide integer operation");
6292 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 1)));
6293 if (GET_MODE_CLASS (mode) == MODE_INT
6294 && mode > MAX_INTEGER_COMPUTATION_MODE)
6295 internal_error ("unsupported wide integer operation");
6300 /* Return the highest power of two that EXP is known to be a multiple of.
6301 This is used in updating alignment of MEMs in array references. */
6303 static HOST_WIDE_INT
6304 highest_pow2_factor (exp)
6307 HOST_WIDE_INT c0, c1;
6309 switch (TREE_CODE (exp))
6312 /* We can find the lowest bit that's a one. If the low
6313 HOST_BITS_PER_WIDE_INT bits are zero, return BIGGEST_ALIGNMENT.
6314 We need to handle this case since we can find it in a COND_EXPR,
6315 a MIN_EXPR, or a MAX_EXPR. If the constant overlows, we have an
6316 erroneous program, so return BIGGEST_ALIGNMENT to avoid any
6318 if (TREE_CONSTANT_OVERFLOW (exp))
6319 return BIGGEST_ALIGNMENT;
6322 /* Note: tree_low_cst is intentionally not used here,
6323 we don't care about the upper bits. */
6324 c0 = TREE_INT_CST_LOW (exp);
6326 return c0 ? c0 : BIGGEST_ALIGNMENT;
6330 case PLUS_EXPR: case MINUS_EXPR: case MIN_EXPR: case MAX_EXPR:
6331 c0 = highest_pow2_factor (TREE_OPERAND (exp, 0));
6332 c1 = highest_pow2_factor (TREE_OPERAND (exp, 1));
6333 return MIN (c0, c1);
6336 c0 = highest_pow2_factor (TREE_OPERAND (exp, 0));
6337 c1 = highest_pow2_factor (TREE_OPERAND (exp, 1));
6340 case ROUND_DIV_EXPR: case TRUNC_DIV_EXPR: case FLOOR_DIV_EXPR:
6342 if (integer_pow2p (TREE_OPERAND (exp, 1))
6343 && host_integerp (TREE_OPERAND (exp, 1), 1))
6345 c0 = highest_pow2_factor (TREE_OPERAND (exp, 0));
6346 c1 = tree_low_cst (TREE_OPERAND (exp, 1), 1);
6347 return MAX (1, c0 / c1);
6351 case NON_LVALUE_EXPR: case NOP_EXPR: case CONVERT_EXPR:
6352 case SAVE_EXPR: case WITH_RECORD_EXPR:
6353 return highest_pow2_factor (TREE_OPERAND (exp, 0));
6356 return highest_pow2_factor (TREE_OPERAND (exp, 1));
6359 c0 = highest_pow2_factor (TREE_OPERAND (exp, 1));
6360 c1 = highest_pow2_factor (TREE_OPERAND (exp, 2));
6361 return MIN (c0, c1);
6370 /* Similar, except that it is known that the expression must be a multiple
6371 of the alignment of TYPE. */
6373 static HOST_WIDE_INT
6374 highest_pow2_factor_for_type (type, exp)
6378 HOST_WIDE_INT type_align, factor;
6380 factor = highest_pow2_factor (exp);
6381 type_align = TYPE_ALIGN (type) / BITS_PER_UNIT;
6382 return MAX (factor, type_align);
6385 /* Return an object on the placeholder list that matches EXP, a
6386 PLACEHOLDER_EXPR. An object "matches" if it is of the type of the
6387 PLACEHOLDER_EXPR or a pointer type to it. For further information, see
6388 tree.def. If no such object is found, return 0. If PLIST is nonzero, it
6389 is a location which initially points to a starting location in the
6390 placeholder list (zero means start of the list) and where a pointer into
6391 the placeholder list at which the object is found is placed. */
6394 find_placeholder (exp, plist)
6398 tree type = TREE_TYPE (exp);
6399 tree placeholder_expr;
6401 for (placeholder_expr
6402 = plist && *plist ? TREE_CHAIN (*plist) : placeholder_list;
6403 placeholder_expr != 0;
6404 placeholder_expr = TREE_CHAIN (placeholder_expr))
6406 tree need_type = TYPE_MAIN_VARIANT (type);
6409 /* Find the outermost reference that is of the type we want. If none,
6410 see if any object has a type that is a pointer to the type we
6412 for (elt = TREE_PURPOSE (placeholder_expr); elt != 0;
6413 elt = ((TREE_CODE (elt) == COMPOUND_EXPR
6414 || TREE_CODE (elt) == COND_EXPR)
6415 ? TREE_OPERAND (elt, 1)
6416 : (TREE_CODE_CLASS (TREE_CODE (elt)) == 'r'
6417 || TREE_CODE_CLASS (TREE_CODE (elt)) == '1'
6418 || TREE_CODE_CLASS (TREE_CODE (elt)) == '2'
6419 || TREE_CODE_CLASS (TREE_CODE (elt)) == 'e')
6420 ? TREE_OPERAND (elt, 0) : 0))
6421 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
6424 *plist = placeholder_expr;
6428 for (elt = TREE_PURPOSE (placeholder_expr); elt != 0;
6430 = ((TREE_CODE (elt) == COMPOUND_EXPR
6431 || TREE_CODE (elt) == COND_EXPR)
6432 ? TREE_OPERAND (elt, 1)
6433 : (TREE_CODE_CLASS (TREE_CODE (elt)) == 'r'
6434 || TREE_CODE_CLASS (TREE_CODE (elt)) == '1'
6435 || TREE_CODE_CLASS (TREE_CODE (elt)) == '2'
6436 || TREE_CODE_CLASS (TREE_CODE (elt)) == 'e')
6437 ? TREE_OPERAND (elt, 0) : 0))
6438 if (POINTER_TYPE_P (TREE_TYPE (elt))
6439 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
6443 *plist = placeholder_expr;
6444 return build1 (INDIRECT_REF, need_type, elt);
6451 /* expand_expr: generate code for computing expression EXP.
6452 An rtx for the computed value is returned. The value is never null.
6453 In the case of a void EXP, const0_rtx is returned.
6455 The value may be stored in TARGET if TARGET is nonzero.
6456 TARGET is just a suggestion; callers must assume that
6457 the rtx returned may not be the same as TARGET.
6459 If TARGET is CONST0_RTX, it means that the value will be ignored.
6461 If TMODE is not VOIDmode, it suggests generating the
6462 result in mode TMODE. But this is done only when convenient.
6463 Otherwise, TMODE is ignored and the value generated in its natural mode.
6464 TMODE is just a suggestion; callers must assume that
6465 the rtx returned may not have mode TMODE.
6467 Note that TARGET may have neither TMODE nor MODE. In that case, it
6468 probably will not be used.
6470 If MODIFIER is EXPAND_SUM then when EXP is an addition
6471 we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
6472 or a nest of (PLUS ...) and (MINUS ...) where the terms are
6473 products as above, or REG or MEM, or constant.
6474 Ordinarily in such cases we would output mul or add instructions
6475 and then return a pseudo reg containing the sum.
6477 EXPAND_INITIALIZER is much like EXPAND_SUM except that
6478 it also marks a label as absolutely required (it can't be dead).
6479 It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
6480 This is used for outputting expressions used in initializers.
6482 EXPAND_CONST_ADDRESS says that it is okay to return a MEM
6483 with a constant address even if that address is not normally legitimate.
6484 EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
6486 EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
6487 a call parameter. Such targets require special care as we haven't yet
6488 marked TARGET so that it's safe from being trashed by libcalls. We
6489 don't want to use TARGET for anything but the final result;
6490 Intermediate values must go elsewhere. Additionally, calls to
6491 emit_block_move will be flagged with BLOCK_OP_CALL_PARM. */
6494 expand_expr (exp, target, tmode, modifier)
6497 enum machine_mode tmode;
6498 enum expand_modifier modifier;
6501 tree type = TREE_TYPE (exp);
6502 int unsignedp = TREE_UNSIGNED (type);
6503 enum machine_mode mode;
6504 enum tree_code code = TREE_CODE (exp);
6506 rtx subtarget, original_target;
6510 /* Handle ERROR_MARK before anybody tries to access its type. */
6511 if (TREE_CODE (exp) == ERROR_MARK || TREE_CODE (type) == ERROR_MARK)
6513 op0 = CONST0_RTX (tmode);
6519 mode = TYPE_MODE (type);
6520 /* Use subtarget as the target for operand 0 of a binary operation. */
6521 subtarget = get_subtarget (target);
6522 original_target = target;
6523 ignore = (target == const0_rtx
6524 || ((code == NON_LVALUE_EXPR || code == NOP_EXPR
6525 || code == CONVERT_EXPR || code == REFERENCE_EXPR
6526 || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
6527 && TREE_CODE (type) == VOID_TYPE));
6529 /* If we are going to ignore this result, we need only do something
6530 if there is a side-effect somewhere in the expression. If there
6531 is, short-circuit the most common cases here. Note that we must
6532 not call expand_expr with anything but const0_rtx in case this
6533 is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
6537 if (! TREE_SIDE_EFFECTS (exp))
6540 /* Ensure we reference a volatile object even if value is ignored, but
6541 don't do this if all we are doing is taking its address. */
6542 if (TREE_THIS_VOLATILE (exp)
6543 && TREE_CODE (exp) != FUNCTION_DECL
6544 && mode != VOIDmode && mode != BLKmode
6545 && modifier != EXPAND_CONST_ADDRESS)
6547 temp = expand_expr (exp, NULL_RTX, VOIDmode, modifier);
6548 if (GET_CODE (temp) == MEM)
6549 temp = copy_to_reg (temp);
6553 if (TREE_CODE_CLASS (code) == '1' || code == COMPONENT_REF
6554 || code == INDIRECT_REF || code == BUFFER_REF)
6555 return expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
6558 else if (TREE_CODE_CLASS (code) == '2' || TREE_CODE_CLASS (code) == '<'
6559 || code == ARRAY_REF || code == ARRAY_RANGE_REF)
6561 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, modifier);
6562 expand_expr (TREE_OPERAND (exp, 1), const0_rtx, VOIDmode, modifier);
6565 else if ((code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR)
6566 && ! TREE_SIDE_EFFECTS (TREE_OPERAND (exp, 1)))
6567 /* If the second operand has no side effects, just evaluate
6569 return expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
6571 else if (code == BIT_FIELD_REF)
6573 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, modifier);
6574 expand_expr (TREE_OPERAND (exp, 1), const0_rtx, VOIDmode, modifier);
6575 expand_expr (TREE_OPERAND (exp, 2), const0_rtx, VOIDmode, modifier);
6582 #ifdef MAX_INTEGER_COMPUTATION_MODE
6583 /* Only check stuff here if the mode we want is different from the mode
6584 of the expression; if it's the same, check_max_integer_computiation_mode
6585 will handle it. Do we really need to check this stuff at all? */
6588 && GET_MODE (target) != mode
6589 && TREE_CODE (exp) != INTEGER_CST
6590 && TREE_CODE (exp) != PARM_DECL
6591 && TREE_CODE (exp) != ARRAY_REF
6592 && TREE_CODE (exp) != ARRAY_RANGE_REF
6593 && TREE_CODE (exp) != COMPONENT_REF
6594 && TREE_CODE (exp) != BIT_FIELD_REF
6595 && TREE_CODE (exp) != INDIRECT_REF
6596 && TREE_CODE (exp) != CALL_EXPR
6597 && TREE_CODE (exp) != VAR_DECL
6598 && TREE_CODE (exp) != RTL_EXPR)
6600 enum machine_mode mode = GET_MODE (target);
6602 if (GET_MODE_CLASS (mode) == MODE_INT
6603 && mode > MAX_INTEGER_COMPUTATION_MODE)
6604 internal_error ("unsupported wide integer operation");
6608 && TREE_CODE (exp) != INTEGER_CST
6609 && TREE_CODE (exp) != PARM_DECL
6610 && TREE_CODE (exp) != ARRAY_REF
6611 && TREE_CODE (exp) != ARRAY_RANGE_REF
6612 && TREE_CODE (exp) != COMPONENT_REF
6613 && TREE_CODE (exp) != BIT_FIELD_REF
6614 && TREE_CODE (exp) != INDIRECT_REF
6615 && TREE_CODE (exp) != VAR_DECL
6616 && TREE_CODE (exp) != CALL_EXPR
6617 && TREE_CODE (exp) != RTL_EXPR
6618 && GET_MODE_CLASS (tmode) == MODE_INT
6619 && tmode > MAX_INTEGER_COMPUTATION_MODE)
6620 internal_error ("unsupported wide integer operation");
6622 check_max_integer_computation_mode (exp);
6625 /* If will do cse, generate all results into pseudo registers
6626 since 1) that allows cse to find more things
6627 and 2) otherwise cse could produce an insn the machine
6628 cannot support. And exception is a CONSTRUCTOR into a multi-word
6629 MEM: that's much more likely to be most efficient into the MEM. */
6631 if (! cse_not_expected && mode != BLKmode && target
6632 && (GET_CODE (target) != REG || REGNO (target) < FIRST_PSEUDO_REGISTER)
6633 && ! (code == CONSTRUCTOR && GET_MODE_SIZE (mode) > UNITS_PER_WORD))
6640 tree function = decl_function_context (exp);
6641 /* Handle using a label in a containing function. */
6642 if (function != current_function_decl
6643 && function != inline_function_decl && function != 0)
6645 struct function *p = find_function_data (function);
6646 p->expr->x_forced_labels
6647 = gen_rtx_EXPR_LIST (VOIDmode, label_rtx (exp),
6648 p->expr->x_forced_labels);
6652 if (modifier == EXPAND_INITIALIZER)
6653 forced_labels = gen_rtx_EXPR_LIST (VOIDmode,
6658 temp = gen_rtx_MEM (FUNCTION_MODE,
6659 gen_rtx_LABEL_REF (Pmode, label_rtx (exp)));
6660 if (function != current_function_decl
6661 && function != inline_function_decl && function != 0)
6662 LABEL_REF_NONLOCAL_P (XEXP (temp, 0)) = 1;
6667 if (!DECL_RTL_SET_P (exp))
6669 error_with_decl (exp, "prior parameter's size depends on `%s'");
6670 return CONST0_RTX (mode);
6673 /* ... fall through ... */
6676 /* If a static var's type was incomplete when the decl was written,
6677 but the type is complete now, lay out the decl now. */
6678 if (DECL_SIZE (exp) == 0
6679 && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp))
6680 && (TREE_STATIC (exp) || DECL_EXTERNAL (exp)))
6681 layout_decl (exp, 0);
6683 /* ... fall through ... */
6687 if (DECL_RTL (exp) == 0)
6690 /* Ensure variable marked as used even if it doesn't go through
6691 a parser. If it hasn't be used yet, write out an external
6693 if (! TREE_USED (exp))
6695 assemble_external (exp);
6696 TREE_USED (exp) = 1;
6699 /* Show we haven't gotten RTL for this yet. */
6702 /* Handle variables inherited from containing functions. */
6703 context = decl_function_context (exp);
6705 /* We treat inline_function_decl as an alias for the current function
6706 because that is the inline function whose vars, types, etc.
6707 are being merged into the current function.
6708 See expand_inline_function. */
6710 if (context != 0 && context != current_function_decl
6711 && context != inline_function_decl
6712 /* If var is static, we don't need a static chain to access it. */
6713 && ! (GET_CODE (DECL_RTL (exp)) == MEM
6714 && CONSTANT_P (XEXP (DECL_RTL (exp), 0))))
6718 /* Mark as non-local and addressable. */
6719 DECL_NONLOCAL (exp) = 1;
6720 if (DECL_NO_STATIC_CHAIN (current_function_decl))
6722 (*lang_hooks.mark_addressable) (exp);
6723 if (GET_CODE (DECL_RTL (exp)) != MEM)
6725 addr = XEXP (DECL_RTL (exp), 0);
6726 if (GET_CODE (addr) == MEM)
6728 = replace_equiv_address (addr,
6729 fix_lexical_addr (XEXP (addr, 0), exp));
6731 addr = fix_lexical_addr (addr, exp);
6733 temp = replace_equiv_address (DECL_RTL (exp), addr);
6736 /* This is the case of an array whose size is to be determined
6737 from its initializer, while the initializer is still being parsed.
6740 else if (GET_CODE (DECL_RTL (exp)) == MEM
6741 && GET_CODE (XEXP (DECL_RTL (exp), 0)) == REG)
6742 temp = validize_mem (DECL_RTL (exp));
6744 /* If DECL_RTL is memory, we are in the normal case and either
6745 the address is not valid or it is not a register and -fforce-addr
6746 is specified, get the address into a register. */
6748 else if (GET_CODE (DECL_RTL (exp)) == MEM
6749 && modifier != EXPAND_CONST_ADDRESS
6750 && modifier != EXPAND_SUM
6751 && modifier != EXPAND_INITIALIZER
6752 && (! memory_address_p (DECL_MODE (exp),
6753 XEXP (DECL_RTL (exp), 0))
6755 && GET_CODE (XEXP (DECL_RTL (exp), 0)) != REG)))
6756 temp = replace_equiv_address (DECL_RTL (exp),
6757 copy_rtx (XEXP (DECL_RTL (exp), 0)));
6759 /* If we got something, return it. But first, set the alignment
6760 if the address is a register. */
6763 if (GET_CODE (temp) == MEM && GET_CODE (XEXP (temp, 0)) == REG)
6764 mark_reg_pointer (XEXP (temp, 0), DECL_ALIGN (exp));
6769 /* If the mode of DECL_RTL does not match that of the decl, it
6770 must be a promoted value. We return a SUBREG of the wanted mode,
6771 but mark it so that we know that it was already extended. */
6773 if (GET_CODE (DECL_RTL (exp)) == REG
6774 && GET_MODE (DECL_RTL (exp)) != DECL_MODE (exp))
6776 /* Get the signedness used for this variable. Ensure we get the
6777 same mode we got when the variable was declared. */
6778 if (GET_MODE (DECL_RTL (exp))
6779 != promote_mode (type, DECL_MODE (exp), &unsignedp,
6780 (TREE_CODE (exp) == RESULT_DECL ? 1 : 0)))
6783 temp = gen_lowpart_SUBREG (mode, DECL_RTL (exp));
6784 SUBREG_PROMOTED_VAR_P (temp) = 1;
6785 SUBREG_PROMOTED_UNSIGNED_SET (temp, unsignedp);
6789 return DECL_RTL (exp);
6792 temp = immed_double_const (TREE_INT_CST_LOW (exp),
6793 TREE_INT_CST_HIGH (exp), mode);
6795 /* ??? If overflow is set, fold will have done an incomplete job,
6796 which can result in (plus xx (const_int 0)), which can get
6797 simplified by validate_replace_rtx during virtual register
6798 instantiation, which can result in unrecognizable insns.
6799 Avoid this by forcing all overflows into registers. */
6800 if (TREE_CONSTANT_OVERFLOW (exp)
6801 && modifier != EXPAND_INITIALIZER)
6802 temp = force_reg (mode, temp);
6807 return const_vector_from_tree (exp);
6810 return expand_expr (DECL_INITIAL (exp), target, VOIDmode, modifier);
6813 /* If optimized, generate immediate CONST_DOUBLE
6814 which will be turned into memory by reload if necessary.
6816 We used to force a register so that loop.c could see it. But
6817 this does not allow gen_* patterns to perform optimizations with
6818 the constants. It also produces two insns in cases like "x = 1.0;".
6819 On most machines, floating-point constants are not permitted in
6820 many insns, so we'd end up copying it to a register in any case.
6822 Now, we do the copying in expand_binop, if appropriate. */
6823 return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp),
6824 TYPE_MODE (TREE_TYPE (exp)));
6828 if (! TREE_CST_RTL (exp))
6829 output_constant_def (exp, 1);
6831 /* TREE_CST_RTL probably contains a constant address.
6832 On RISC machines where a constant address isn't valid,
6833 make some insns to get that address into a register. */
6834 if (GET_CODE (TREE_CST_RTL (exp)) == MEM
6835 && modifier != EXPAND_CONST_ADDRESS
6836 && modifier != EXPAND_INITIALIZER
6837 && modifier != EXPAND_SUM
6838 && (! memory_address_p (mode, XEXP (TREE_CST_RTL (exp), 0))
6840 && GET_CODE (XEXP (TREE_CST_RTL (exp), 0)) != REG)))
6841 return replace_equiv_address (TREE_CST_RTL (exp),
6842 copy_rtx (XEXP (TREE_CST_RTL (exp), 0)));
6843 return TREE_CST_RTL (exp);
6845 case EXPR_WITH_FILE_LOCATION:
6848 const char *saved_input_filename = input_filename;
6849 int saved_lineno = lineno;
6850 input_filename = EXPR_WFL_FILENAME (exp);
6851 lineno = EXPR_WFL_LINENO (exp);
6852 if (EXPR_WFL_EMIT_LINE_NOTE (exp))
6853 emit_line_note (input_filename, lineno);
6854 /* Possibly avoid switching back and forth here. */
6855 to_return = expand_expr (EXPR_WFL_NODE (exp), target, tmode, modifier);
6856 input_filename = saved_input_filename;
6857 lineno = saved_lineno;
6862 context = decl_function_context (exp);
6864 /* If this SAVE_EXPR was at global context, assume we are an
6865 initialization function and move it into our context. */
6867 SAVE_EXPR_CONTEXT (exp) = current_function_decl;
6869 /* We treat inline_function_decl as an alias for the current function
6870 because that is the inline function whose vars, types, etc.
6871 are being merged into the current function.
6872 See expand_inline_function. */
6873 if (context == current_function_decl || context == inline_function_decl)
6876 /* If this is non-local, handle it. */
6879 /* The following call just exists to abort if the context is
6880 not of a containing function. */
6881 find_function_data (context);
6883 temp = SAVE_EXPR_RTL (exp);
6884 if (temp && GET_CODE (temp) == REG)
6886 put_var_into_stack (exp, /*rescan=*/true);
6887 temp = SAVE_EXPR_RTL (exp);
6889 if (temp == 0 || GET_CODE (temp) != MEM)
6892 replace_equiv_address (temp,
6893 fix_lexical_addr (XEXP (temp, 0), exp));
6895 if (SAVE_EXPR_RTL (exp) == 0)
6897 if (mode == VOIDmode)
6900 temp = assign_temp (build_qualified_type (type,
6902 | TYPE_QUAL_CONST)),
6905 SAVE_EXPR_RTL (exp) = temp;
6906 if (!optimize && GET_CODE (temp) == REG)
6907 save_expr_regs = gen_rtx_EXPR_LIST (VOIDmode, temp,
6910 /* If the mode of TEMP does not match that of the expression, it
6911 must be a promoted value. We pass store_expr a SUBREG of the
6912 wanted mode but mark it so that we know that it was already
6915 if (GET_CODE (temp) == REG && GET_MODE (temp) != mode)
6917 temp = gen_lowpart_SUBREG (mode, SAVE_EXPR_RTL (exp));
6918 promote_mode (type, mode, &unsignedp, 0);
6919 SUBREG_PROMOTED_VAR_P (temp) = 1;
6920 SUBREG_PROMOTED_UNSIGNED_SET (temp, unsignedp);
6923 if (temp == const0_rtx)
6924 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
6926 store_expr (TREE_OPERAND (exp, 0), temp,
6927 modifier == EXPAND_STACK_PARM ? 2 : 0);
6929 TREE_USED (exp) = 1;
6932 /* If the mode of SAVE_EXPR_RTL does not match that of the expression, it
6933 must be a promoted value. We return a SUBREG of the wanted mode,
6934 but mark it so that we know that it was already extended. */
6936 if (GET_CODE (SAVE_EXPR_RTL (exp)) == REG
6937 && GET_MODE (SAVE_EXPR_RTL (exp)) != mode)
6939 /* Compute the signedness and make the proper SUBREG. */
6940 promote_mode (type, mode, &unsignedp, 0);
6941 temp = gen_lowpart_SUBREG (mode, SAVE_EXPR_RTL (exp));
6942 SUBREG_PROMOTED_VAR_P (temp) = 1;
6943 SUBREG_PROMOTED_UNSIGNED_SET (temp, unsignedp);
6947 return SAVE_EXPR_RTL (exp);
6952 temp = expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
6953 TREE_OPERAND (exp, 0)
6954 = (*lang_hooks.unsave_expr_now) (TREE_OPERAND (exp, 0));
6958 case PLACEHOLDER_EXPR:
6960 tree old_list = placeholder_list;
6961 tree placeholder_expr = 0;
6963 exp = find_placeholder (exp, &placeholder_expr);
6967 placeholder_list = TREE_CHAIN (placeholder_expr);
6968 temp = expand_expr (exp, original_target, tmode, modifier);
6969 placeholder_list = old_list;
6973 case WITH_RECORD_EXPR:
6974 /* Put the object on the placeholder list, expand our first operand,
6975 and pop the list. */
6976 placeholder_list = tree_cons (TREE_OPERAND (exp, 1), NULL_TREE,
6978 target = expand_expr (TREE_OPERAND (exp, 0), original_target, tmode,
6980 placeholder_list = TREE_CHAIN (placeholder_list);
6984 if (TREE_CODE (TREE_OPERAND (exp, 0)) == LABEL_DECL)
6985 expand_goto (TREE_OPERAND (exp, 0));
6987 expand_computed_goto (TREE_OPERAND (exp, 0));
6991 expand_exit_loop_if_false (NULL,
6992 invert_truthvalue (TREE_OPERAND (exp, 0)));
6995 case LABELED_BLOCK_EXPR:
6996 if (LABELED_BLOCK_BODY (exp))
6997 expand_expr_stmt_value (LABELED_BLOCK_BODY (exp), 0, 1);
6998 /* Should perhaps use expand_label, but this is simpler and safer. */
6999 do_pending_stack_adjust ();
7000 emit_label (label_rtx (LABELED_BLOCK_LABEL (exp)));
7003 case EXIT_BLOCK_EXPR:
7004 if (EXIT_BLOCK_RETURN (exp))
7005 sorry ("returned value in block_exit_expr");
7006 expand_goto (LABELED_BLOCK_LABEL (EXIT_BLOCK_LABELED_BLOCK (exp)));
7011 expand_start_loop (1);
7012 expand_expr_stmt_value (TREE_OPERAND (exp, 0), 0, 1);
7020 tree vars = TREE_OPERAND (exp, 0);
7021 int vars_need_expansion = 0;
7023 /* Need to open a binding contour here because
7024 if there are any cleanups they must be contained here. */
7025 expand_start_bindings (2);
7027 /* Mark the corresponding BLOCK for output in its proper place. */
7028 if (TREE_OPERAND (exp, 2) != 0
7029 && ! TREE_USED (TREE_OPERAND (exp, 2)))
7030 (*lang_hooks.decls.insert_block) (TREE_OPERAND (exp, 2));
7032 /* If VARS have not yet been expanded, expand them now. */
7035 if (!DECL_RTL_SET_P (vars))
7037 vars_need_expansion = 1;
7040 expand_decl_init (vars);
7041 vars = TREE_CHAIN (vars);
7044 temp = expand_expr (TREE_OPERAND (exp, 1), target, tmode, modifier);
7046 expand_end_bindings (TREE_OPERAND (exp, 0), 0, 0);
7052 if (RTL_EXPR_SEQUENCE (exp))
7054 if (RTL_EXPR_SEQUENCE (exp) == const0_rtx)
7056 emit_insn (RTL_EXPR_SEQUENCE (exp));
7057 RTL_EXPR_SEQUENCE (exp) = const0_rtx;
7059 preserve_rtl_expr_result (RTL_EXPR_RTL (exp));
7060 free_temps_for_rtl_expr (exp);
7061 return RTL_EXPR_RTL (exp);
7064 /* If we don't need the result, just ensure we evaluate any
7070 for (elt = CONSTRUCTOR_ELTS (exp); elt; elt = TREE_CHAIN (elt))
7071 expand_expr (TREE_VALUE (elt), const0_rtx, VOIDmode, 0);
7076 /* All elts simple constants => refer to a constant in memory. But
7077 if this is a non-BLKmode mode, let it store a field at a time
7078 since that should make a CONST_INT or CONST_DOUBLE when we
7079 fold. Likewise, if we have a target we can use, it is best to
7080 store directly into the target unless the type is large enough
7081 that memcpy will be used. If we are making an initializer and
7082 all operands are constant, put it in memory as well.
7084 FIXME: Avoid trying to fill vector constructors piece-meal.
7085 Output them with output_constant_def below unless we're sure
7086 they're zeros. This should go away when vector initializers
7087 are treated like VECTOR_CST instead of arrays.
7089 else if ((TREE_STATIC (exp)
7090 && ((mode == BLKmode
7091 && ! (target != 0 && safe_from_p (target, exp, 1)))
7092 || TREE_ADDRESSABLE (exp)
7093 || (host_integerp (TYPE_SIZE_UNIT (type), 1)
7094 && (! MOVE_BY_PIECES_P
7095 (tree_low_cst (TYPE_SIZE_UNIT (type), 1),
7097 && ((TREE_CODE (type) == VECTOR_TYPE
7098 && !is_zeros_p (exp))
7099 || ! mostly_zeros_p (exp)))))
7100 || (modifier == EXPAND_INITIALIZER && TREE_CONSTANT (exp)))
7102 rtx constructor = output_constant_def (exp, 1);
7104 if (modifier != EXPAND_CONST_ADDRESS
7105 && modifier != EXPAND_INITIALIZER
7106 && modifier != EXPAND_SUM)
7107 constructor = validize_mem (constructor);
7113 /* Handle calls that pass values in multiple non-contiguous
7114 locations. The Irix 6 ABI has examples of this. */
7115 if (target == 0 || ! safe_from_p (target, exp, 1)
7116 || GET_CODE (target) == PARALLEL
7117 || modifier == EXPAND_STACK_PARM)
7119 = assign_temp (build_qualified_type (type,
7121 | (TREE_READONLY (exp)
7122 * TYPE_QUAL_CONST))),
7123 0, TREE_ADDRESSABLE (exp), 1);
7125 store_constructor (exp, target, 0, int_expr_size (exp));
7131 tree exp1 = TREE_OPERAND (exp, 0);
7133 tree string = string_constant (exp1, &index);
7135 /* Try to optimize reads from const strings. */
7137 && TREE_CODE (string) == STRING_CST
7138 && TREE_CODE (index) == INTEGER_CST
7139 && compare_tree_int (index, TREE_STRING_LENGTH (string)) < 0
7140 && GET_MODE_CLASS (mode) == MODE_INT
7141 && GET_MODE_SIZE (mode) == 1
7142 && modifier != EXPAND_WRITE)
7143 return gen_int_mode (TREE_STRING_POINTER (string)
7144 [TREE_INT_CST_LOW (index)], mode);
7146 op0 = expand_expr (exp1, NULL_RTX, VOIDmode, EXPAND_SUM);
7147 op0 = memory_address (mode, op0);
7148 temp = gen_rtx_MEM (mode, op0);
7149 set_mem_attributes (temp, exp, 0);
7151 /* If we are writing to this object and its type is a record with
7152 readonly fields, we must mark it as readonly so it will
7153 conflict with readonly references to those fields. */
7154 if (modifier == EXPAND_WRITE && readonly_fields_p (type))
7155 RTX_UNCHANGING_P (temp) = 1;
7161 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) != ARRAY_TYPE)
7165 tree array = TREE_OPERAND (exp, 0);
7166 tree domain = TYPE_DOMAIN (TREE_TYPE (array));
7167 tree low_bound = domain ? TYPE_MIN_VALUE (domain) : integer_zero_node;
7168 tree index = convert (sizetype, TREE_OPERAND (exp, 1));
7171 /* Optimize the special-case of a zero lower bound.
7173 We convert the low_bound to sizetype to avoid some problems
7174 with constant folding. (E.g. suppose the lower bound is 1,
7175 and its mode is QI. Without the conversion, (ARRAY
7176 +(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1))
7177 +INDEX), which becomes (ARRAY+255+INDEX). Oops!) */
7179 if (! integer_zerop (low_bound))
7180 index = size_diffop (index, convert (sizetype, low_bound));
7182 /* Fold an expression like: "foo"[2].
7183 This is not done in fold so it won't happen inside &.
7184 Don't fold if this is for wide characters since it's too
7185 difficult to do correctly and this is a very rare case. */
7187 if (modifier != EXPAND_CONST_ADDRESS
7188 && modifier != EXPAND_INITIALIZER
7189 && modifier != EXPAND_MEMORY
7190 && TREE_CODE (array) == STRING_CST
7191 && TREE_CODE (index) == INTEGER_CST
7192 && compare_tree_int (index, TREE_STRING_LENGTH (array)) < 0
7193 && GET_MODE_CLASS (mode) == MODE_INT
7194 && GET_MODE_SIZE (mode) == 1)
7195 return gen_int_mode (TREE_STRING_POINTER (array)
7196 [TREE_INT_CST_LOW (index)], mode);
7198 /* If this is a constant index into a constant array,
7199 just get the value from the array. Handle both the cases when
7200 we have an explicit constructor and when our operand is a variable
7201 that was declared const. */
7203 if (modifier != EXPAND_CONST_ADDRESS
7204 && modifier != EXPAND_INITIALIZER
7205 && modifier != EXPAND_MEMORY
7206 && TREE_CODE (array) == CONSTRUCTOR
7207 && ! TREE_SIDE_EFFECTS (array)
7208 && TREE_CODE (index) == INTEGER_CST
7209 && 0 > compare_tree_int (index,
7210 list_length (CONSTRUCTOR_ELTS
7211 (TREE_OPERAND (exp, 0)))))
7215 for (elem = CONSTRUCTOR_ELTS (TREE_OPERAND (exp, 0)),
7216 i = TREE_INT_CST_LOW (index);
7217 elem != 0 && i != 0; i--, elem = TREE_CHAIN (elem))
7221 return expand_expr (fold (TREE_VALUE (elem)), target, tmode,
7225 else if (optimize >= 1
7226 && modifier != EXPAND_CONST_ADDRESS
7227 && modifier != EXPAND_INITIALIZER
7228 && modifier != EXPAND_MEMORY
7229 && TREE_READONLY (array) && ! TREE_SIDE_EFFECTS (array)
7230 && TREE_CODE (array) == VAR_DECL && DECL_INITIAL (array)
7231 && TREE_CODE (DECL_INITIAL (array)) != ERROR_MARK)
7233 if (TREE_CODE (index) == INTEGER_CST)
7235 tree init = DECL_INITIAL (array);
7237 if (TREE_CODE (init) == CONSTRUCTOR)
7241 for (elem = CONSTRUCTOR_ELTS (init);
7243 && !tree_int_cst_equal (TREE_PURPOSE (elem), index));
7244 elem = TREE_CHAIN (elem))
7247 if (elem && !TREE_SIDE_EFFECTS (TREE_VALUE (elem)))
7248 return expand_expr (fold (TREE_VALUE (elem)), target,
7251 else if (TREE_CODE (init) == STRING_CST
7252 && 0 > compare_tree_int (index,
7253 TREE_STRING_LENGTH (init)))
7255 tree type = TREE_TYPE (TREE_TYPE (init));
7256 enum machine_mode mode = TYPE_MODE (type);
7258 if (GET_MODE_CLASS (mode) == MODE_INT
7259 && GET_MODE_SIZE (mode) == 1)
7260 return gen_int_mode (TREE_STRING_POINTER (init)
7261 [TREE_INT_CST_LOW (index)], mode);
7270 case ARRAY_RANGE_REF:
7271 /* If the operand is a CONSTRUCTOR, we can just extract the
7272 appropriate field if it is present. Don't do this if we have
7273 already written the data since we want to refer to that copy
7274 and varasm.c assumes that's what we'll do. */
7275 if (code == COMPONENT_REF
7276 && TREE_CODE (TREE_OPERAND (exp, 0)) == CONSTRUCTOR
7277 && TREE_CST_RTL (TREE_OPERAND (exp, 0)) == 0)
7281 for (elt = CONSTRUCTOR_ELTS (TREE_OPERAND (exp, 0)); elt;
7282 elt = TREE_CHAIN (elt))
7283 if (TREE_PURPOSE (elt) == TREE_OPERAND (exp, 1)
7284 /* We can normally use the value of the field in the
7285 CONSTRUCTOR. However, if this is a bitfield in
7286 an integral mode that we can fit in a HOST_WIDE_INT,
7287 we must mask only the number of bits in the bitfield,
7288 since this is done implicitly by the constructor. If
7289 the bitfield does not meet either of those conditions,
7290 we can't do this optimization. */
7291 && (! DECL_BIT_FIELD (TREE_PURPOSE (elt))
7292 || ((GET_MODE_CLASS (DECL_MODE (TREE_PURPOSE (elt)))
7294 && (GET_MODE_BITSIZE (DECL_MODE (TREE_PURPOSE (elt)))
7295 <= HOST_BITS_PER_WIDE_INT))))
7297 if (DECL_BIT_FIELD (TREE_PURPOSE (elt))
7298 && modifier == EXPAND_STACK_PARM)
7300 op0 = expand_expr (TREE_VALUE (elt), target, tmode, modifier);
7301 if (DECL_BIT_FIELD (TREE_PURPOSE (elt)))
7303 HOST_WIDE_INT bitsize
7304 = TREE_INT_CST_LOW (DECL_SIZE (TREE_PURPOSE (elt)));
7305 enum machine_mode imode
7306 = TYPE_MODE (TREE_TYPE (TREE_PURPOSE (elt)));
7308 if (TREE_UNSIGNED (TREE_TYPE (TREE_PURPOSE (elt))))
7310 op1 = GEN_INT (((HOST_WIDE_INT) 1 << bitsize) - 1);
7311 op0 = expand_and (imode, op0, op1, target);
7316 = build_int_2 (GET_MODE_BITSIZE (imode) - bitsize,
7319 op0 = expand_shift (LSHIFT_EXPR, imode, op0, count,
7321 op0 = expand_shift (RSHIFT_EXPR, imode, op0, count,
7331 enum machine_mode mode1;
7332 HOST_WIDE_INT bitsize, bitpos;
7335 tree tem = get_inner_reference (exp, &bitsize, &bitpos, &offset,
7336 &mode1, &unsignedp, &volatilep);
7339 /* If we got back the original object, something is wrong. Perhaps
7340 we are evaluating an expression too early. In any event, don't
7341 infinitely recurse. */
7345 /* If TEM's type is a union of variable size, pass TARGET to the inner
7346 computation, since it will need a temporary and TARGET is known
7347 to have to do. This occurs in unchecked conversion in Ada. */
7351 (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
7352 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
7354 && modifier != EXPAND_STACK_PARM
7355 ? target : NULL_RTX),
7357 (modifier == EXPAND_INITIALIZER
7358 || modifier == EXPAND_CONST_ADDRESS
7359 || modifier == EXPAND_STACK_PARM)
7360 ? modifier : EXPAND_NORMAL);
7362 /* If this is a constant, put it into a register if it is a
7363 legitimate constant and OFFSET is 0 and memory if it isn't. */
7364 if (CONSTANT_P (op0))
7366 enum machine_mode mode = TYPE_MODE (TREE_TYPE (tem));
7367 if (mode != BLKmode && LEGITIMATE_CONSTANT_P (op0)
7369 op0 = force_reg (mode, op0);
7371 op0 = validize_mem (force_const_mem (mode, op0));
7376 rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode,
7379 /* If this object is in a register, put it into memory.
7380 This case can't occur in C, but can in Ada if we have
7381 unchecked conversion of an expression from a scalar type to
7382 an array or record type. */
7383 if (GET_CODE (op0) == REG || GET_CODE (op0) == SUBREG
7384 || GET_CODE (op0) == CONCAT || GET_CODE (op0) == ADDRESSOF)
7386 /* If the operand is a SAVE_EXPR, we can deal with this by
7387 forcing the SAVE_EXPR into memory. */
7388 if (TREE_CODE (TREE_OPERAND (exp, 0)) == SAVE_EXPR)
7390 put_var_into_stack (TREE_OPERAND (exp, 0),
7392 op0 = SAVE_EXPR_RTL (TREE_OPERAND (exp, 0));
7397 = build_qualified_type (TREE_TYPE (tem),
7398 (TYPE_QUALS (TREE_TYPE (tem))
7399 | TYPE_QUAL_CONST));
7400 rtx memloc = assign_temp (nt, 1, 1, 1);
7402 emit_move_insn (memloc, op0);
7407 if (GET_CODE (op0) != MEM)
7410 #ifdef POINTERS_EXTEND_UNSIGNED
7411 if (GET_MODE (offset_rtx) != Pmode)
7412 offset_rtx = convert_to_mode (Pmode, offset_rtx, 0);
7414 if (GET_MODE (offset_rtx) != ptr_mode)
7415 offset_rtx = convert_to_mode (ptr_mode, offset_rtx, 0);
7418 /* A constant address in OP0 can have VOIDmode, we must not try
7419 to call force_reg for that case. Avoid that case. */
7420 if (GET_CODE (op0) == MEM
7421 && GET_MODE (op0) == BLKmode
7422 && GET_MODE (XEXP (op0, 0)) != VOIDmode
7424 && (bitpos % bitsize) == 0
7425 && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
7426 && MEM_ALIGN (op0) == GET_MODE_ALIGNMENT (mode1))
7428 op0 = adjust_address (op0, mode1, bitpos / BITS_PER_UNIT);
7432 op0 = offset_address (op0, offset_rtx,
7433 highest_pow2_factor (offset));
7436 /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
7437 record its alignment as BIGGEST_ALIGNMENT. */
7438 if (GET_CODE (op0) == MEM && bitpos == 0 && offset != 0
7439 && is_aligning_offset (offset, tem))
7440 set_mem_align (op0, BIGGEST_ALIGNMENT);
7442 /* Don't forget about volatility even if this is a bitfield. */
7443 if (GET_CODE (op0) == MEM && volatilep && ! MEM_VOLATILE_P (op0))
7445 if (op0 == orig_op0)
7446 op0 = copy_rtx (op0);
7448 MEM_VOLATILE_P (op0) = 1;
7451 /* The following code doesn't handle CONCAT.
7452 Assume only bitpos == 0 can be used for CONCAT, due to
7453 one element arrays having the same mode as its element. */
7454 if (GET_CODE (op0) == CONCAT)
7456 if (bitpos != 0 || bitsize != GET_MODE_BITSIZE (GET_MODE (op0)))
7461 /* In cases where an aligned union has an unaligned object
7462 as a field, we might be extracting a BLKmode value from
7463 an integer-mode (e.g., SImode) object. Handle this case
7464 by doing the extract into an object as wide as the field
7465 (which we know to be the width of a basic mode), then
7466 storing into memory, and changing the mode to BLKmode. */
7467 if (mode1 == VOIDmode
7468 || GET_CODE (op0) == REG || GET_CODE (op0) == SUBREG
7469 || (mode1 != BLKmode && ! direct_load[(int) mode1]
7470 && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
7471 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT
7472 && modifier != EXPAND_CONST_ADDRESS
7473 && modifier != EXPAND_INITIALIZER)
7474 /* If the field isn't aligned enough to fetch as a memref,
7475 fetch it as a bit field. */
7476 || (mode1 != BLKmode
7477 && SLOW_UNALIGNED_ACCESS (mode1, MEM_ALIGN (op0))
7478 && ((TYPE_ALIGN (TREE_TYPE (tem))
7479 < GET_MODE_ALIGNMENT (mode))
7480 || (bitpos % GET_MODE_ALIGNMENT (mode) != 0)))
7481 /* If the type and the field are a constant size and the
7482 size of the type isn't the same size as the bitfield,
7483 we must use bitfield operations. */
7485 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (exp)))
7487 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)),
7490 enum machine_mode ext_mode = mode;
7492 if (ext_mode == BLKmode
7493 && ! (target != 0 && GET_CODE (op0) == MEM
7494 && GET_CODE (target) == MEM
7495 && bitpos % BITS_PER_UNIT == 0))
7496 ext_mode = mode_for_size (bitsize, MODE_INT, 1);
7498 if (ext_mode == BLKmode)
7500 /* In this case, BITPOS must start at a byte boundary and
7501 TARGET, if specified, must be a MEM. */
7502 if (GET_CODE (op0) != MEM
7503 || (target != 0 && GET_CODE (target) != MEM)
7504 || bitpos % BITS_PER_UNIT != 0)
7507 op0 = adjust_address (op0, VOIDmode, bitpos / BITS_PER_UNIT);
7509 target = assign_temp (type, 0, 1, 1);
7511 emit_block_move (target, op0,
7512 GEN_INT ((bitsize + BITS_PER_UNIT - 1)
7514 (modifier == EXPAND_STACK_PARM
7515 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
7520 op0 = validize_mem (op0);
7522 if (GET_CODE (op0) == MEM && GET_CODE (XEXP (op0, 0)) == REG)
7523 mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
7525 op0 = extract_bit_field (op0, bitsize, bitpos, unsignedp,
7526 (modifier == EXPAND_STACK_PARM
7527 ? NULL_RTX : target),
7529 int_size_in_bytes (TREE_TYPE (tem)));
7531 /* If the result is a record type and BITSIZE is narrower than
7532 the mode of OP0, an integral mode, and this is a big endian
7533 machine, we must put the field into the high-order bits. */
7534 if (TREE_CODE (type) == RECORD_TYPE && BYTES_BIG_ENDIAN
7535 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
7536 && bitsize < (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (op0)))
7537 op0 = expand_shift (LSHIFT_EXPR, GET_MODE (op0), op0,
7538 size_int (GET_MODE_BITSIZE (GET_MODE (op0))
7542 if (mode == BLKmode)
7544 rtx new = assign_temp (build_qualified_type
7545 ((*lang_hooks.types.type_for_mode)
7547 TYPE_QUAL_CONST), 0, 1, 1);
7549 emit_move_insn (new, op0);
7550 op0 = copy_rtx (new);
7551 PUT_MODE (op0, BLKmode);
7552 set_mem_attributes (op0, exp, 1);
7558 /* If the result is BLKmode, use that to access the object
7560 if (mode == BLKmode)
7563 /* Get a reference to just this component. */
7564 if (modifier == EXPAND_CONST_ADDRESS
7565 || modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
7566 op0 = adjust_address_nv (op0, mode1, bitpos / BITS_PER_UNIT);
7568 op0 = adjust_address (op0, mode1, bitpos / BITS_PER_UNIT);
7570 if (op0 == orig_op0)
7571 op0 = copy_rtx (op0);
7573 set_mem_attributes (op0, exp, 0);
7574 if (GET_CODE (XEXP (op0, 0)) == REG)
7575 mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
7577 MEM_VOLATILE_P (op0) |= volatilep;
7578 if (mode == mode1 || mode1 == BLKmode || mode1 == tmode
7579 || modifier == EXPAND_CONST_ADDRESS
7580 || modifier == EXPAND_INITIALIZER)
7582 else if (target == 0)
7583 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
7585 convert_move (target, op0, unsignedp);
7591 rtx insn, before = get_last_insn (), vtbl_ref;
7593 /* Evaluate the interior expression. */
7594 subtarget = expand_expr (TREE_OPERAND (exp, 0), target,
7597 /* Get or create an instruction off which to hang a note. */
7598 if (REG_P (subtarget))
7601 insn = get_last_insn ();
7604 if (! INSN_P (insn))
7605 insn = prev_nonnote_insn (insn);
7609 target = gen_reg_rtx (GET_MODE (subtarget));
7610 insn = emit_move_insn (target, subtarget);
7613 /* Collect the data for the note. */
7614 vtbl_ref = XEXP (DECL_RTL (TREE_OPERAND (exp, 1)), 0);
7615 vtbl_ref = plus_constant (vtbl_ref,
7616 tree_low_cst (TREE_OPERAND (exp, 2), 0));
7617 /* Discard the initial CONST that was added. */
7618 vtbl_ref = XEXP (vtbl_ref, 0);
7621 = gen_rtx_EXPR_LIST (REG_VTABLE_REF, vtbl_ref, REG_NOTES (insn));
7626 /* Intended for a reference to a buffer of a file-object in Pascal.
7627 But it's not certain that a special tree code will really be
7628 necessary for these. INDIRECT_REF might work for them. */
7634 /* Pascal set IN expression.
7637 rlo = set_low - (set_low%bits_per_word);
7638 the_word = set [ (index - rlo)/bits_per_word ];
7639 bit_index = index % bits_per_word;
7640 bitmask = 1 << bit_index;
7641 return !!(the_word & bitmask); */
7643 tree set = TREE_OPERAND (exp, 0);
7644 tree index = TREE_OPERAND (exp, 1);
7645 int iunsignedp = TREE_UNSIGNED (TREE_TYPE (index));
7646 tree set_type = TREE_TYPE (set);
7647 tree set_low_bound = TYPE_MIN_VALUE (TYPE_DOMAIN (set_type));
7648 tree set_high_bound = TYPE_MAX_VALUE (TYPE_DOMAIN (set_type));
7649 rtx index_val = expand_expr (index, 0, VOIDmode, 0);
7650 rtx lo_r = expand_expr (set_low_bound, 0, VOIDmode, 0);
7651 rtx hi_r = expand_expr (set_high_bound, 0, VOIDmode, 0);
7652 rtx setval = expand_expr (set, 0, VOIDmode, 0);
7653 rtx setaddr = XEXP (setval, 0);
7654 enum machine_mode index_mode = TYPE_MODE (TREE_TYPE (index));
7656 rtx diff, quo, rem, addr, bit, result;
7658 /* If domain is empty, answer is no. Likewise if index is constant
7659 and out of bounds. */
7660 if (((TREE_CODE (set_high_bound) == INTEGER_CST
7661 && TREE_CODE (set_low_bound) == INTEGER_CST
7662 && tree_int_cst_lt (set_high_bound, set_low_bound))
7663 || (TREE_CODE (index) == INTEGER_CST
7664 && TREE_CODE (set_low_bound) == INTEGER_CST
7665 && tree_int_cst_lt (index, set_low_bound))
7666 || (TREE_CODE (set_high_bound) == INTEGER_CST
7667 && TREE_CODE (index) == INTEGER_CST
7668 && tree_int_cst_lt (set_high_bound, index))))
7672 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
7674 /* If we get here, we have to generate the code for both cases
7675 (in range and out of range). */
7677 op0 = gen_label_rtx ();
7678 op1 = gen_label_rtx ();
7680 if (! (GET_CODE (index_val) == CONST_INT
7681 && GET_CODE (lo_r) == CONST_INT))
7682 emit_cmp_and_jump_insns (index_val, lo_r, LT, NULL_RTX,
7683 GET_MODE (index_val), iunsignedp, op1);
7685 if (! (GET_CODE (index_val) == CONST_INT
7686 && GET_CODE (hi_r) == CONST_INT))
7687 emit_cmp_and_jump_insns (index_val, hi_r, GT, NULL_RTX,
7688 GET_MODE (index_val), iunsignedp, op1);
7690 /* Calculate the element number of bit zero in the first word
7692 if (GET_CODE (lo_r) == CONST_INT)
7693 rlow = GEN_INT (INTVAL (lo_r)
7694 & ~((HOST_WIDE_INT) 1 << BITS_PER_UNIT));
7696 rlow = expand_binop (index_mode, and_optab, lo_r,
7697 GEN_INT (~((HOST_WIDE_INT) 1 << BITS_PER_UNIT)),
7698 NULL_RTX, iunsignedp, OPTAB_LIB_WIDEN);
7700 diff = expand_binop (index_mode, sub_optab, index_val, rlow,
7701 NULL_RTX, iunsignedp, OPTAB_LIB_WIDEN);
7703 quo = expand_divmod (0, TRUNC_DIV_EXPR, index_mode, diff,
7704 GEN_INT (BITS_PER_UNIT), NULL_RTX, iunsignedp);
7705 rem = expand_divmod (1, TRUNC_MOD_EXPR, index_mode, index_val,
7706 GEN_INT (BITS_PER_UNIT), NULL_RTX, iunsignedp);
7708 addr = memory_address (byte_mode,
7709 expand_binop (index_mode, add_optab, diff,
7710 setaddr, NULL_RTX, iunsignedp,
7713 /* Extract the bit we want to examine. */
7714 bit = expand_shift (RSHIFT_EXPR, byte_mode,
7715 gen_rtx_MEM (byte_mode, addr),
7716 make_tree (TREE_TYPE (index), rem),
7718 result = expand_binop (byte_mode, and_optab, bit, const1_rtx,
7719 GET_MODE (target) == byte_mode ? target : 0,
7720 1, OPTAB_LIB_WIDEN);
7722 if (result != target)
7723 convert_move (target, result, 1);
7725 /* Output the code to handle the out-of-range case. */
7728 emit_move_insn (target, const0_rtx);
7733 case WITH_CLEANUP_EXPR:
7734 if (WITH_CLEANUP_EXPR_RTL (exp) == 0)
7736 WITH_CLEANUP_EXPR_RTL (exp)
7737 = expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
7738 expand_decl_cleanup_eh (NULL_TREE, TREE_OPERAND (exp, 1),
7739 CLEANUP_EH_ONLY (exp));
7741 /* That's it for this cleanup. */
7742 TREE_OPERAND (exp, 1) = 0;
7744 return WITH_CLEANUP_EXPR_RTL (exp);
7746 case CLEANUP_POINT_EXPR:
7748 /* Start a new binding layer that will keep track of all cleanup
7749 actions to be performed. */
7750 expand_start_bindings (2);
7752 target_temp_slot_level = temp_slot_level;
7754 op0 = expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
7755 /* If we're going to use this value, load it up now. */
7757 op0 = force_not_mem (op0);
7758 preserve_temp_slots (op0);
7759 expand_end_bindings (NULL_TREE, 0, 0);
7764 /* Check for a built-in function. */
7765 if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
7766 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
7768 && DECL_BUILT_IN (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
7770 if (DECL_BUILT_IN_CLASS (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
7771 == BUILT_IN_FRONTEND)
7772 return (*lang_hooks.expand_expr) (exp, original_target,
7775 return expand_builtin (exp, target, subtarget, tmode, ignore);
7778 return expand_call (exp, target, ignore);
7780 case NON_LVALUE_EXPR:
7783 case REFERENCE_EXPR:
7784 if (TREE_OPERAND (exp, 0) == error_mark_node)
7787 if (TREE_CODE (type) == UNION_TYPE)
7789 tree valtype = TREE_TYPE (TREE_OPERAND (exp, 0));
7791 /* If both input and output are BLKmode, this conversion isn't doing
7792 anything except possibly changing memory attribute. */
7793 if (mode == BLKmode && TYPE_MODE (valtype) == BLKmode)
7795 rtx result = expand_expr (TREE_OPERAND (exp, 0), target, tmode,
7798 result = copy_rtx (result);
7799 set_mem_attributes (result, exp, 0);
7804 target = assign_temp (type, 0, 1, 1);
7806 if (GET_CODE (target) == MEM)
7807 /* Store data into beginning of memory target. */
7808 store_expr (TREE_OPERAND (exp, 0),
7809 adjust_address (target, TYPE_MODE (valtype), 0),
7810 modifier == EXPAND_STACK_PARM ? 2 : 0);
7812 else if (GET_CODE (target) == REG)
7813 /* Store this field into a union of the proper type. */
7814 store_field (target,
7815 MIN ((int_size_in_bytes (TREE_TYPE
7816 (TREE_OPERAND (exp, 0)))
7818 (HOST_WIDE_INT) GET_MODE_BITSIZE (mode)),
7819 0, TYPE_MODE (valtype), TREE_OPERAND (exp, 0),
7820 VOIDmode, 0, type, 0);
7824 /* Return the entire union. */
7828 if (mode == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))))
7830 op0 = expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode,
7833 /* If the signedness of the conversion differs and OP0 is
7834 a promoted SUBREG, clear that indication since we now
7835 have to do the proper extension. */
7836 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))) != unsignedp
7837 && GET_CODE (op0) == SUBREG)
7838 SUBREG_PROMOTED_VAR_P (op0) = 0;
7843 op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, mode, modifier);
7844 if (GET_MODE (op0) == mode)
7847 /* If OP0 is a constant, just convert it into the proper mode. */
7848 if (CONSTANT_P (op0))
7850 tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
7851 enum machine_mode inner_mode = TYPE_MODE (inner_type);
7853 if (modifier == EXPAND_INITIALIZER)
7854 return simplify_gen_subreg (mode, op0, inner_mode,
7855 subreg_lowpart_offset (mode,
7858 return convert_modes (mode, inner_mode, op0,
7859 TREE_UNSIGNED (inner_type));
7862 if (modifier == EXPAND_INITIALIZER)
7863 return gen_rtx_fmt_e (unsignedp ? ZERO_EXTEND : SIGN_EXTEND, mode, op0);
7867 convert_to_mode (mode, op0,
7868 TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
7870 convert_move (target, op0,
7871 TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
7874 case VIEW_CONVERT_EXPR:
7875 op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, mode, modifier);
7877 /* If the input and output modes are both the same, we are done.
7878 Otherwise, if neither mode is BLKmode and both are within a word, we
7879 can use gen_lowpart. If neither is true, make sure the operand is
7880 in memory and convert the MEM to the new mode. */
7881 if (TYPE_MODE (type) == GET_MODE (op0))
7883 else if (TYPE_MODE (type) != BLKmode && GET_MODE (op0) != BLKmode
7884 && GET_MODE_SIZE (TYPE_MODE (type)) <= UNITS_PER_WORD
7885 && GET_MODE_SIZE (GET_MODE (op0)) <= UNITS_PER_WORD)
7886 op0 = gen_lowpart (TYPE_MODE (type), op0);
7887 else if (GET_CODE (op0) != MEM)
7889 /* If the operand is not a MEM, force it into memory. Since we
7890 are going to be be changing the mode of the MEM, don't call
7891 force_const_mem for constants because we don't allow pool
7892 constants to change mode. */
7893 tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
7895 if (TREE_ADDRESSABLE (exp))
7898 if (target == 0 || GET_MODE (target) != TYPE_MODE (inner_type))
7900 = assign_stack_temp_for_type
7901 (TYPE_MODE (inner_type),
7902 GET_MODE_SIZE (TYPE_MODE (inner_type)), 0, inner_type);
7904 emit_move_insn (target, op0);
7908 /* At this point, OP0 is in the correct mode. If the output type is such
7909 that the operand is known to be aligned, indicate that it is.
7910 Otherwise, we need only be concerned about alignment for non-BLKmode
7912 if (GET_CODE (op0) == MEM)
7914 op0 = copy_rtx (op0);
7916 if (TYPE_ALIGN_OK (type))
7917 set_mem_align (op0, MAX (MEM_ALIGN (op0), TYPE_ALIGN (type)));
7918 else if (TYPE_MODE (type) != BLKmode && STRICT_ALIGNMENT
7919 && MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (TYPE_MODE (type)))
7921 tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
7922 HOST_WIDE_INT temp_size
7923 = MAX (int_size_in_bytes (inner_type),
7924 (HOST_WIDE_INT) GET_MODE_SIZE (TYPE_MODE (type)));
7925 rtx new = assign_stack_temp_for_type (TYPE_MODE (type),
7926 temp_size, 0, type);
7927 rtx new_with_op0_mode = adjust_address (new, GET_MODE (op0), 0);
7929 if (TREE_ADDRESSABLE (exp))
7932 if (GET_MODE (op0) == BLKmode)
7933 emit_block_move (new_with_op0_mode, op0,
7934 GEN_INT (GET_MODE_SIZE (TYPE_MODE (type))),
7935 (modifier == EXPAND_STACK_PARM
7936 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
7938 emit_move_insn (new_with_op0_mode, op0);
7943 op0 = adjust_address (op0, TYPE_MODE (type), 0);
7949 this_optab = ! unsignedp && flag_trapv
7950 && (GET_MODE_CLASS (mode) == MODE_INT)
7951 ? addv_optab : add_optab;
7953 /* If we are adding a constant, an RTL_EXPR that is sp, fp, or ap, and
7954 something else, make sure we add the register to the constant and
7955 then to the other thing. This case can occur during strength
7956 reduction and doing it this way will produce better code if the
7957 frame pointer or argument pointer is eliminated.
7959 fold-const.c will ensure that the constant is always in the inner
7960 PLUS_EXPR, so the only case we need to do anything about is if
7961 sp, ap, or fp is our second argument, in which case we must swap
7962 the innermost first argument and our second argument. */
7964 if (TREE_CODE (TREE_OPERAND (exp, 0)) == PLUS_EXPR
7965 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 1)) == INTEGER_CST
7966 && TREE_CODE (TREE_OPERAND (exp, 1)) == RTL_EXPR
7967 && (RTL_EXPR_RTL (TREE_OPERAND (exp, 1)) == frame_pointer_rtx
7968 || RTL_EXPR_RTL (TREE_OPERAND (exp, 1)) == stack_pointer_rtx
7969 || RTL_EXPR_RTL (TREE_OPERAND (exp, 1)) == arg_pointer_rtx))
7971 tree t = TREE_OPERAND (exp, 1);
7973 TREE_OPERAND (exp, 1) = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
7974 TREE_OPERAND (TREE_OPERAND (exp, 0), 0) = t;
7977 /* If the result is to be ptr_mode and we are adding an integer to
7978 something, we might be forming a constant. So try to use
7979 plus_constant. If it produces a sum and we can't accept it,
7980 use force_operand. This allows P = &ARR[const] to generate
7981 efficient code on machines where a SYMBOL_REF is not a valid
7984 If this is an EXPAND_SUM call, always return the sum. */
7985 if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER
7986 || (mode == ptr_mode && (unsignedp || ! flag_trapv)))
7988 if (modifier == EXPAND_STACK_PARM)
7990 if (TREE_CODE (TREE_OPERAND (exp, 0)) == INTEGER_CST
7991 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
7992 && TREE_CONSTANT (TREE_OPERAND (exp, 1)))
7996 op1 = expand_expr (TREE_OPERAND (exp, 1), subtarget, VOIDmode,
7998 /* Use immed_double_const to ensure that the constant is
7999 truncated according to the mode of OP1, then sign extended
8000 to a HOST_WIDE_INT. Using the constant directly can result
8001 in non-canonical RTL in a 64x32 cross compile. */
8003 = immed_double_const (TREE_INT_CST_LOW (TREE_OPERAND (exp, 0)),
8005 TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 1))));
8006 op1 = plus_constant (op1, INTVAL (constant_part));
8007 if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8008 op1 = force_operand (op1, target);
8012 else if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
8013 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_INT
8014 && TREE_CONSTANT (TREE_OPERAND (exp, 0)))
8018 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode,
8019 (modifier == EXPAND_INITIALIZER
8020 ? EXPAND_INITIALIZER : EXPAND_SUM));
8021 if (! CONSTANT_P (op0))
8023 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX,
8024 VOIDmode, modifier);
8025 /* Don't go to both_summands if modifier
8026 says it's not right to return a PLUS. */
8027 if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8031 /* Use immed_double_const to ensure that the constant is
8032 truncated according to the mode of OP1, then sign extended
8033 to a HOST_WIDE_INT. Using the constant directly can result
8034 in non-canonical RTL in a 64x32 cross compile. */
8036 = immed_double_const (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1)),
8038 TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))));
8039 op0 = plus_constant (op0, INTVAL (constant_part));
8040 if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8041 op0 = force_operand (op0, target);
8046 if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1), 1))
8049 /* No sense saving up arithmetic to be done
8050 if it's all in the wrong mode to form part of an address.
8051 And force_operand won't know whether to sign-extend or
8053 if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8054 || mode != ptr_mode)
8056 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
8057 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
8058 if (op0 == const0_rtx)
8060 if (op1 == const0_rtx)
8065 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, modifier);
8066 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, modifier);
8068 /* We come here from MINUS_EXPR when the second operand is a
8071 /* Make sure any term that's a sum with a constant comes last. */
8072 if (GET_CODE (op0) == PLUS
8073 && CONSTANT_P (XEXP (op0, 1)))
8079 /* If adding to a sum including a constant,
8080 associate it to put the constant outside. */
8081 if (GET_CODE (op1) == PLUS
8082 && CONSTANT_P (XEXP (op1, 1)))
8084 rtx constant_term = const0_rtx;
8086 temp = simplify_binary_operation (PLUS, mode, XEXP (op1, 0), op0);
8089 /* Ensure that MULT comes first if there is one. */
8090 else if (GET_CODE (op0) == MULT)
8091 op0 = gen_rtx_PLUS (mode, op0, XEXP (op1, 0));
8093 op0 = gen_rtx_PLUS (mode, XEXP (op1, 0), op0);
8095 /* Let's also eliminate constants from op0 if possible. */
8096 op0 = eliminate_constant_term (op0, &constant_term);
8098 /* CONSTANT_TERM and XEXP (op1, 1) are known to be constant, so
8099 their sum should be a constant. Form it into OP1, since the
8100 result we want will then be OP0 + OP1. */
8102 temp = simplify_binary_operation (PLUS, mode, constant_term,
8107 op1 = gen_rtx_PLUS (mode, constant_term, XEXP (op1, 1));
8110 /* Put a constant term last and put a multiplication first. */
8111 if (CONSTANT_P (op0) || GET_CODE (op1) == MULT)
8112 temp = op1, op1 = op0, op0 = temp;
8114 temp = simplify_binary_operation (PLUS, mode, op0, op1);
8115 return temp ? temp : gen_rtx_PLUS (mode, op0, op1);
8118 /* For initializers, we are allowed to return a MINUS of two
8119 symbolic constants. Here we handle all cases when both operands
8121 /* Handle difference of two symbolic constants,
8122 for the sake of an initializer. */
8123 if ((modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
8124 && really_constant_p (TREE_OPERAND (exp, 0))
8125 && really_constant_p (TREE_OPERAND (exp, 1)))
8127 rtx op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode,
8129 rtx op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode,
8132 /* If the last operand is a CONST_INT, use plus_constant of
8133 the negated constant. Else make the MINUS. */
8134 if (GET_CODE (op1) == CONST_INT)
8135 return plus_constant (op0, - INTVAL (op1));
8137 return gen_rtx_MINUS (mode, op0, op1);
8140 this_optab = ! unsignedp && flag_trapv
8141 && (GET_MODE_CLASS(mode) == MODE_INT)
8142 ? subv_optab : sub_optab;
8144 /* No sense saving up arithmetic to be done
8145 if it's all in the wrong mode to form part of an address.
8146 And force_operand won't know whether to sign-extend or
8148 if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
8149 || mode != ptr_mode)
8152 if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1), 1))
8155 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, modifier);
8156 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, modifier);
8158 /* Convert A - const to A + (-const). */
8159 if (GET_CODE (op1) == CONST_INT)
8161 op1 = negate_rtx (mode, op1);
8168 /* If first operand is constant, swap them.
8169 Thus the following special case checks need only
8170 check the second operand. */
8171 if (TREE_CODE (TREE_OPERAND (exp, 0)) == INTEGER_CST)
8173 tree t1 = TREE_OPERAND (exp, 0);
8174 TREE_OPERAND (exp, 0) = TREE_OPERAND (exp, 1);
8175 TREE_OPERAND (exp, 1) = t1;
8178 /* Attempt to return something suitable for generating an
8179 indexed address, for machines that support that. */
8181 if (modifier == EXPAND_SUM && mode == ptr_mode
8182 && host_integerp (TREE_OPERAND (exp, 1), 0))
8184 tree exp1 = TREE_OPERAND (exp, 1);
8186 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode,
8189 /* If we knew for certain that this is arithmetic for an array
8190 reference, and we knew the bounds of the array, then we could
8191 apply the distributive law across (PLUS X C) for constant C.
8192 Without such knowledge, we risk overflowing the computation
8193 when both X and C are large, but X+C isn't. */
8194 /* ??? Could perhaps special-case EXP being unsigned and C being
8195 positive. In that case we are certain that X+C is no smaller
8196 than X and so the transformed expression will overflow iff the
8197 original would have. */
8199 if (GET_CODE (op0) != REG)
8200 op0 = force_operand (op0, NULL_RTX);
8201 if (GET_CODE (op0) != REG)
8202 op0 = copy_to_mode_reg (mode, op0);
8204 return gen_rtx_MULT (mode, op0,
8205 gen_int_mode (tree_low_cst (exp1, 0),
8206 TYPE_MODE (TREE_TYPE (exp1))));
8209 if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1), 1))
8212 if (modifier == EXPAND_STACK_PARM)
8215 /* Check for multiplying things that have been extended
8216 from a narrower type. If this machine supports multiplying
8217 in that narrower type with a result in the desired type,
8218 do it that way, and avoid the explicit type-conversion. */
8219 if (TREE_CODE (TREE_OPERAND (exp, 0)) == NOP_EXPR
8220 && TREE_CODE (type) == INTEGER_TYPE
8221 && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
8222 < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp, 0))))
8223 && ((TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
8224 && int_fits_type_p (TREE_OPERAND (exp, 1),
8225 TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
8226 /* Don't use a widening multiply if a shift will do. */
8227 && ((GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 1))))
8228 > HOST_BITS_PER_WIDE_INT)
8229 || exact_log2 (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1))) < 0))
8231 (TREE_CODE (TREE_OPERAND (exp, 1)) == NOP_EXPR
8232 && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 1), 0)))
8234 TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))))
8235 /* If both operands are extended, they must either both
8236 be zero-extended or both be sign-extended. */
8237 && (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 1), 0)))
8239 TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))))))
8241 enum machine_mode innermode
8242 = TYPE_MODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)));
8243 optab other_optab = (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
8244 ? smul_widen_optab : umul_widen_optab);
8245 this_optab = (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
8246 ? umul_widen_optab : smul_widen_optab);
8247 if (mode == GET_MODE_WIDER_MODE (innermode))
8249 if (this_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
8251 op0 = expand_expr (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
8252 NULL_RTX, VOIDmode, 0);
8253 if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST)
8254 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX,
8257 op1 = expand_expr (TREE_OPERAND (TREE_OPERAND (exp, 1), 0),
8258 NULL_RTX, VOIDmode, 0);
8261 else if (other_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing
8262 && innermode == word_mode)
8265 op0 = expand_expr (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
8266 NULL_RTX, VOIDmode, 0);
8267 if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST)
8268 op1 = convert_modes (innermode, mode,
8269 expand_expr (TREE_OPERAND (exp, 1),
8270 NULL_RTX, VOIDmode, 0),
8273 op1 = expand_expr (TREE_OPERAND (TREE_OPERAND (exp, 1), 0),
8274 NULL_RTX, VOIDmode, 0);
8275 temp = expand_binop (mode, other_optab, op0, op1, target,
8276 unsignedp, OPTAB_LIB_WIDEN);
8277 htem = expand_mult_highpart_adjust (innermode,
8278 gen_highpart (innermode, temp),
8280 gen_highpart (innermode, temp),
8282 emit_move_insn (gen_highpart (innermode, temp), htem);
8287 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
8288 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
8289 return expand_mult (mode, op0, op1, target, unsignedp);
8291 case TRUNC_DIV_EXPR:
8292 case FLOOR_DIV_EXPR:
8294 case ROUND_DIV_EXPR:
8295 case EXACT_DIV_EXPR:
8296 if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1), 1))
8298 if (modifier == EXPAND_STACK_PARM)
8300 /* Possible optimization: compute the dividend with EXPAND_SUM
8301 then if the divisor is constant can optimize the case
8302 where some terms of the dividend have coeffs divisible by it. */
8303 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
8304 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
8305 return expand_divmod (0, code, mode, op0, op1, target, unsignedp);
8308 /* Emit a/b as a*(1/b). Later we may manage CSE the reciprocal saving
8309 expensive divide. If not, combine will rebuild the original
8311 if (flag_unsafe_math_optimizations && optimize && !optimize_size
8312 && TREE_CODE (type) == REAL_TYPE
8313 && !real_onep (TREE_OPERAND (exp, 0)))
8314 return expand_expr (build (MULT_EXPR, type, TREE_OPERAND (exp, 0),
8315 build (RDIV_EXPR, type,
8316 build_real (type, dconst1),
8317 TREE_OPERAND (exp, 1))),
8318 target, tmode, modifier);
8319 this_optab = sdiv_optab;
8322 case TRUNC_MOD_EXPR:
8323 case FLOOR_MOD_EXPR:
8325 case ROUND_MOD_EXPR:
8326 if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1), 1))
8328 if (modifier == EXPAND_STACK_PARM)
8330 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
8331 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
8332 return expand_divmod (1, code, mode, op0, op1, target, unsignedp);
8334 case FIX_ROUND_EXPR:
8335 case FIX_FLOOR_EXPR:
8337 abort (); /* Not used for C. */
8339 case FIX_TRUNC_EXPR:
8340 op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
8341 if (target == 0 || modifier == EXPAND_STACK_PARM)
8342 target = gen_reg_rtx (mode);
8343 expand_fix (target, op0, unsignedp);
8347 op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
8348 if (target == 0 || modifier == EXPAND_STACK_PARM)
8349 target = gen_reg_rtx (mode);
8350 /* expand_float can't figure out what to do if FROM has VOIDmode.
8351 So give it the correct mode. With -O, cse will optimize this. */
8352 if (GET_MODE (op0) == VOIDmode)
8353 op0 = copy_to_mode_reg (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))),
8355 expand_float (target, op0,
8356 TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
8360 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
8361 if (modifier == EXPAND_STACK_PARM)
8363 temp = expand_unop (mode,
8364 ! unsignedp && flag_trapv
8365 && (GET_MODE_CLASS(mode) == MODE_INT)
8366 ? negv_optab : neg_optab, op0, target, 0);
8372 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
8373 if (modifier == EXPAND_STACK_PARM)
8376 /* Handle complex values specially. */
8377 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT
8378 || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
8379 return expand_complex_abs (mode, op0, target, unsignedp);
8381 /* Unsigned abs is simply the operand. Testing here means we don't
8382 risk generating incorrect code below. */
8383 if (TREE_UNSIGNED (type))
8386 return expand_abs (mode, op0, target, unsignedp,
8387 safe_from_p (target, TREE_OPERAND (exp, 0), 1));
8391 target = original_target;
8393 || modifier == EXPAND_STACK_PARM
8394 || ! safe_from_p (target, TREE_OPERAND (exp, 1), 1)
8395 || (GET_CODE (target) == MEM && MEM_VOLATILE_P (target))
8396 || GET_MODE (target) != mode
8397 || (GET_CODE (target) == REG
8398 && REGNO (target) < FIRST_PSEUDO_REGISTER))
8399 target = gen_reg_rtx (mode);
8400 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
8401 op0 = expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode, 0);
8403 /* First try to do it with a special MIN or MAX instruction.
8404 If that does not win, use a conditional jump to select the proper
8406 this_optab = (TREE_UNSIGNED (type)
8407 ? (code == MIN_EXPR ? umin_optab : umax_optab)
8408 : (code == MIN_EXPR ? smin_optab : smax_optab));
8410 temp = expand_binop (mode, this_optab, op0, op1, target, unsignedp,
8415 /* At this point, a MEM target is no longer useful; we will get better
8418 if (GET_CODE (target) == MEM)
8419 target = gen_reg_rtx (mode);
8422 emit_move_insn (target, op0);
8424 op0 = gen_label_rtx ();
8426 /* If this mode is an integer too wide to compare properly,
8427 compare word by word. Rely on cse to optimize constant cases. */
8428 if (GET_MODE_CLASS (mode) == MODE_INT
8429 && ! can_compare_p (GE, mode, ccp_jump))
8431 if (code == MAX_EXPR)
8432 do_jump_by_parts_greater_rtx (mode, TREE_UNSIGNED (type),
8433 target, op1, NULL_RTX, op0);
8435 do_jump_by_parts_greater_rtx (mode, TREE_UNSIGNED (type),
8436 op1, target, NULL_RTX, op0);
8440 int unsignedp = TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 1)));
8441 do_compare_rtx_and_jump (target, op1, code == MAX_EXPR ? GE : LE,
8442 unsignedp, mode, NULL_RTX, NULL_RTX,
8445 emit_move_insn (target, op1);
8450 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
8451 if (modifier == EXPAND_STACK_PARM)
8453 temp = expand_unop (mode, one_cmpl_optab, op0, target, 1);
8459 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
8460 if (modifier == EXPAND_STACK_PARM)
8462 temp = expand_unop (mode, ffs_optab, op0, target, 1);
8467 /* ??? Can optimize bitwise operations with one arg constant.
8468 Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8469 and (a bitwise1 b) bitwise2 b (etc)
8470 but that is probably not worth while. */
8472 /* BIT_AND_EXPR is for bitwise anding. TRUTH_AND_EXPR is for anding two
8473 boolean values when we want in all cases to compute both of them. In
8474 general it is fastest to do TRUTH_AND_EXPR by computing both operands
8475 as actual zero-or-1 values and then bitwise anding. In cases where
8476 there cannot be any side effects, better code would be made by
8477 treating TRUTH_AND_EXPR like TRUTH_ANDIF_EXPR; but the question is
8478 how to recognize those cases. */
8480 case TRUTH_AND_EXPR:
8482 this_optab = and_optab;
8487 this_optab = ior_optab;
8490 case TRUTH_XOR_EXPR:
8492 this_optab = xor_optab;
8499 if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1), 1))
8501 if (modifier == EXPAND_STACK_PARM)
8503 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
8504 return expand_shift (code, mode, op0, TREE_OPERAND (exp, 1), target,
8507 /* Could determine the answer when only additive constants differ. Also,
8508 the addition of one can be handled by changing the condition. */
8515 case UNORDERED_EXPR:
8522 temp = do_store_flag (exp,
8523 modifier != EXPAND_STACK_PARM ? target : NULL_RTX,
8524 tmode != VOIDmode ? tmode : mode, 0);
8528 /* For foo != 0, load foo, and if it is nonzero load 1 instead. */
8529 if (code == NE_EXPR && integer_zerop (TREE_OPERAND (exp, 1))
8531 && GET_CODE (original_target) == REG
8532 && (GET_MODE (original_target)
8533 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)))))
8535 temp = expand_expr (TREE_OPERAND (exp, 0), original_target,
8538 /* If temp is constant, we can just compute the result. */
8539 if (GET_CODE (temp) == CONST_INT)
8541 if (INTVAL (temp) != 0)
8542 emit_move_insn (target, const1_rtx);
8544 emit_move_insn (target, const0_rtx);
8549 if (temp != original_target)
8551 enum machine_mode mode1 = GET_MODE (temp);
8552 if (mode1 == VOIDmode)
8553 mode1 = tmode != VOIDmode ? tmode : mode;
8555 temp = copy_to_mode_reg (mode1, temp);
8558 op1 = gen_label_rtx ();
8559 emit_cmp_and_jump_insns (temp, const0_rtx, EQ, NULL_RTX,
8560 GET_MODE (temp), unsignedp, op1);
8561 emit_move_insn (temp, const1_rtx);
8566 /* If no set-flag instruction, must generate a conditional
8567 store into a temporary variable. Drop through
8568 and handle this like && and ||. */
8570 case TRUTH_ANDIF_EXPR:
8571 case TRUTH_ORIF_EXPR:
8574 || modifier == EXPAND_STACK_PARM
8575 || ! safe_from_p (target, exp, 1)
8576 /* Make sure we don't have a hard reg (such as function's return
8577 value) live across basic blocks, if not optimizing. */
8578 || (!optimize && GET_CODE (target) == REG
8579 && REGNO (target) < FIRST_PSEUDO_REGISTER)))
8580 target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
8583 emit_clr_insn (target);
8585 op1 = gen_label_rtx ();
8586 jumpifnot (exp, op1);
8589 emit_0_to_1_insn (target);
8592 return ignore ? const0_rtx : target;
8594 case TRUTH_NOT_EXPR:
8595 if (modifier == EXPAND_STACK_PARM)
8597 op0 = expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode, 0);
8598 /* The parser is careful to generate TRUTH_NOT_EXPR
8599 only with operands that are always zero or one. */
8600 temp = expand_binop (mode, xor_optab, op0, const1_rtx,
8601 target, 1, OPTAB_LIB_WIDEN);
8607 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
8609 return expand_expr (TREE_OPERAND (exp, 1),
8610 (ignore ? const0_rtx : target),
8611 VOIDmode, modifier);
8614 /* If we would have a "singleton" (see below) were it not for a
8615 conversion in each arm, bring that conversion back out. */
8616 if (TREE_CODE (TREE_OPERAND (exp, 1)) == NOP_EXPR
8617 && TREE_CODE (TREE_OPERAND (exp, 2)) == NOP_EXPR
8618 && (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 1), 0))
8619 == TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 2), 0))))
8621 tree iftrue = TREE_OPERAND (TREE_OPERAND (exp, 1), 0);
8622 tree iffalse = TREE_OPERAND (TREE_OPERAND (exp, 2), 0);
8624 if ((TREE_CODE_CLASS (TREE_CODE (iftrue)) == '2'
8625 && operand_equal_p (iffalse, TREE_OPERAND (iftrue, 0), 0))
8626 || (TREE_CODE_CLASS (TREE_CODE (iffalse)) == '2'
8627 && operand_equal_p (iftrue, TREE_OPERAND (iffalse, 0), 0))
8628 || (TREE_CODE_CLASS (TREE_CODE (iftrue)) == '1'
8629 && operand_equal_p (iffalse, TREE_OPERAND (iftrue, 0), 0))
8630 || (TREE_CODE_CLASS (TREE_CODE (iffalse)) == '1'
8631 && operand_equal_p (iftrue, TREE_OPERAND (iffalse, 0), 0)))
8632 return expand_expr (build1 (NOP_EXPR, type,
8633 build (COND_EXPR, TREE_TYPE (iftrue),
8634 TREE_OPERAND (exp, 0),
8636 target, tmode, modifier);
8640 /* Note that COND_EXPRs whose type is a structure or union
8641 are required to be constructed to contain assignments of
8642 a temporary variable, so that we can evaluate them here
8643 for side effect only. If type is void, we must do likewise. */
8645 /* If an arm of the branch requires a cleanup,
8646 only that cleanup is performed. */
8649 tree binary_op = 0, unary_op = 0;
8651 /* If this is (A ? 1 : 0) and A is a condition, just evaluate it and
8652 convert it to our mode, if necessary. */
8653 if (integer_onep (TREE_OPERAND (exp, 1))
8654 && integer_zerop (TREE_OPERAND (exp, 2))
8655 && TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == '<')
8659 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
8664 if (modifier == EXPAND_STACK_PARM)
8666 op0 = expand_expr (TREE_OPERAND (exp, 0), target, mode, modifier);
8667 if (GET_MODE (op0) == mode)
8671 target = gen_reg_rtx (mode);
8672 convert_move (target, op0, unsignedp);
8676 /* Check for X ? A + B : A. If we have this, we can copy A to the
8677 output and conditionally add B. Similarly for unary operations.
8678 Don't do this if X has side-effects because those side effects
8679 might affect A or B and the "?" operation is a sequence point in
8680 ANSI. (operand_equal_p tests for side effects.) */
8682 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 1))) == '2'
8683 && operand_equal_p (TREE_OPERAND (exp, 2),
8684 TREE_OPERAND (TREE_OPERAND (exp, 1), 0), 0))
8685 singleton = TREE_OPERAND (exp, 2), binary_op = TREE_OPERAND (exp, 1);
8686 else if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 2))) == '2'
8687 && operand_equal_p (TREE_OPERAND (exp, 1),
8688 TREE_OPERAND (TREE_OPERAND (exp, 2), 0), 0))
8689 singleton = TREE_OPERAND (exp, 1), binary_op = TREE_OPERAND (exp, 2);
8690 else if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 1))) == '1'
8691 && operand_equal_p (TREE_OPERAND (exp, 2),
8692 TREE_OPERAND (TREE_OPERAND (exp, 1), 0), 0))
8693 singleton = TREE_OPERAND (exp, 2), unary_op = TREE_OPERAND (exp, 1);
8694 else if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 2))) == '1'
8695 && operand_equal_p (TREE_OPERAND (exp, 1),
8696 TREE_OPERAND (TREE_OPERAND (exp, 2), 0), 0))
8697 singleton = TREE_OPERAND (exp, 1), unary_op = TREE_OPERAND (exp, 2);
8699 /* If we are not to produce a result, we have no target. Otherwise,
8700 if a target was specified use it; it will not be used as an
8701 intermediate target unless it is safe. If no target, use a
8706 else if (modifier == EXPAND_STACK_PARM)
8707 temp = assign_temp (type, 0, 0, 1);
8708 else if (original_target
8709 && (safe_from_p (original_target, TREE_OPERAND (exp, 0), 1)
8710 || (singleton && GET_CODE (original_target) == REG
8711 && REGNO (original_target) >= FIRST_PSEUDO_REGISTER
8712 && original_target == var_rtx (singleton)))
8713 && GET_MODE (original_target) == mode
8714 #ifdef HAVE_conditional_move
8715 && (! can_conditionally_move_p (mode)
8716 || GET_CODE (original_target) == REG
8717 || TREE_ADDRESSABLE (type))
8719 && (GET_CODE (original_target) != MEM
8720 || TREE_ADDRESSABLE (type)))
8721 temp = original_target;
8722 else if (TREE_ADDRESSABLE (type))
8725 temp = assign_temp (type, 0, 0, 1);
8727 /* If we had X ? A + C : A, with C a constant power of 2, and we can
8728 do the test of X as a store-flag operation, do this as
8729 A + ((X != 0) << log C). Similarly for other simple binary
8730 operators. Only do for C == 1 if BRANCH_COST is low. */
8731 if (temp && singleton && binary_op
8732 && (TREE_CODE (binary_op) == PLUS_EXPR
8733 || TREE_CODE (binary_op) == MINUS_EXPR
8734 || TREE_CODE (binary_op) == BIT_IOR_EXPR
8735 || TREE_CODE (binary_op) == BIT_XOR_EXPR)
8736 && (BRANCH_COST >= 3 ? integer_pow2p (TREE_OPERAND (binary_op, 1))
8737 : integer_onep (TREE_OPERAND (binary_op, 1)))
8738 && TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == '<')
8742 optab boptab = (TREE_CODE (binary_op) == PLUS_EXPR
8743 ? (TYPE_TRAP_SIGNED (TREE_TYPE (binary_op))
8744 ? addv_optab : add_optab)
8745 : TREE_CODE (binary_op) == MINUS_EXPR
8746 ? (TYPE_TRAP_SIGNED (TREE_TYPE (binary_op))
8747 ? subv_optab : sub_optab)
8748 : TREE_CODE (binary_op) == BIT_IOR_EXPR ? ior_optab
8751 /* If we had X ? A : A + 1, do this as A + (X == 0). */
8752 if (singleton == TREE_OPERAND (exp, 1))
8753 cond = invert_truthvalue (TREE_OPERAND (exp, 0));
8755 cond = TREE_OPERAND (exp, 0);
8757 result = do_store_flag (cond, (safe_from_p (temp, singleton, 1)
8759 mode, BRANCH_COST <= 1);
8761 if (result != 0 && ! integer_onep (TREE_OPERAND (binary_op, 1)))
8762 result = expand_shift (LSHIFT_EXPR, mode, result,
8763 build_int_2 (tree_log2
8767 (safe_from_p (temp, singleton, 1)
8768 ? temp : NULL_RTX), 0);
8772 op1 = expand_expr (singleton, NULL_RTX, VOIDmode, 0);
8773 return expand_binop (mode, boptab, op1, result, temp,
8774 unsignedp, OPTAB_LIB_WIDEN);
8778 do_pending_stack_adjust ();
8780 op0 = gen_label_rtx ();
8782 if (singleton && ! TREE_SIDE_EFFECTS (TREE_OPERAND (exp, 0)))
8786 /* If the target conflicts with the other operand of the
8787 binary op, we can't use it. Also, we can't use the target
8788 if it is a hard register, because evaluating the condition
8789 might clobber it. */
8791 && ! safe_from_p (temp, TREE_OPERAND (binary_op, 1), 1))
8792 || (GET_CODE (temp) == REG
8793 && REGNO (temp) < FIRST_PSEUDO_REGISTER))
8794 temp = gen_reg_rtx (mode);
8795 store_expr (singleton, temp,
8796 modifier == EXPAND_STACK_PARM ? 2 : 0);
8799 expand_expr (singleton,
8800 ignore ? const0_rtx : NULL_RTX, VOIDmode, 0);
8801 if (singleton == TREE_OPERAND (exp, 1))
8802 jumpif (TREE_OPERAND (exp, 0), op0);
8804 jumpifnot (TREE_OPERAND (exp, 0), op0);
8806 start_cleanup_deferral ();
8807 if (binary_op && temp == 0)
8808 /* Just touch the other operand. */
8809 expand_expr (TREE_OPERAND (binary_op, 1),
8810 ignore ? const0_rtx : NULL_RTX, VOIDmode, 0);
8812 store_expr (build (TREE_CODE (binary_op), type,
8813 make_tree (type, temp),
8814 TREE_OPERAND (binary_op, 1)),
8815 temp, modifier == EXPAND_STACK_PARM ? 2 : 0);
8817 store_expr (build1 (TREE_CODE (unary_op), type,
8818 make_tree (type, temp)),
8819 temp, modifier == EXPAND_STACK_PARM ? 2 : 0);
8822 /* Check for A op 0 ? A : FOO and A op 0 ? FOO : A where OP is any
8823 comparison operator. If we have one of these cases, set the
8824 output to A, branch on A (cse will merge these two references),
8825 then set the output to FOO. */
8827 && TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == '<'
8828 && integer_zerop (TREE_OPERAND (TREE_OPERAND (exp, 0), 1))
8829 && operand_equal_p (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
8830 TREE_OPERAND (exp, 1), 0)
8831 && (! TREE_SIDE_EFFECTS (TREE_OPERAND (exp, 0))
8832 || TREE_CODE (TREE_OPERAND (exp, 1)) == SAVE_EXPR)
8833 && safe_from_p (temp, TREE_OPERAND (exp, 2), 1))
8835 if (GET_CODE (temp) == REG
8836 && REGNO (temp) < FIRST_PSEUDO_REGISTER)
8837 temp = gen_reg_rtx (mode);
8838 store_expr (TREE_OPERAND (exp, 1), temp,
8839 modifier == EXPAND_STACK_PARM ? 2 : 0);
8840 jumpif (TREE_OPERAND (exp, 0), op0);
8842 start_cleanup_deferral ();
8843 store_expr (TREE_OPERAND (exp, 2), temp,
8844 modifier == EXPAND_STACK_PARM ? 2 : 0);
8848 && TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == '<'
8849 && integer_zerop (TREE_OPERAND (TREE_OPERAND (exp, 0), 1))
8850 && operand_equal_p (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
8851 TREE_OPERAND (exp, 2), 0)
8852 && (! TREE_SIDE_EFFECTS (TREE_OPERAND (exp, 0))
8853 || TREE_CODE (TREE_OPERAND (exp, 2)) == SAVE_EXPR)
8854 && safe_from_p (temp, TREE_OPERAND (exp, 1), 1))
8856 if (GET_CODE (temp) == REG
8857 && REGNO (temp) < FIRST_PSEUDO_REGISTER)
8858 temp = gen_reg_rtx (mode);
8859 store_expr (TREE_OPERAND (exp, 2), temp,
8860 modifier == EXPAND_STACK_PARM ? 2 : 0);
8861 jumpifnot (TREE_OPERAND (exp, 0), op0);
8863 start_cleanup_deferral ();
8864 store_expr (TREE_OPERAND (exp, 1), temp,
8865 modifier == EXPAND_STACK_PARM ? 2 : 0);
8870 op1 = gen_label_rtx ();
8871 jumpifnot (TREE_OPERAND (exp, 0), op0);
8873 start_cleanup_deferral ();
8875 /* One branch of the cond can be void, if it never returns. For
8876 example A ? throw : E */
8878 && TREE_TYPE (TREE_OPERAND (exp, 1)) != void_type_node)
8879 store_expr (TREE_OPERAND (exp, 1), temp,
8880 modifier == EXPAND_STACK_PARM ? 2 : 0);
8882 expand_expr (TREE_OPERAND (exp, 1),
8883 ignore ? const0_rtx : NULL_RTX, VOIDmode, 0);
8884 end_cleanup_deferral ();
8886 emit_jump_insn (gen_jump (op1));
8889 start_cleanup_deferral ();
8891 && TREE_TYPE (TREE_OPERAND (exp, 2)) != void_type_node)
8892 store_expr (TREE_OPERAND (exp, 2), temp,
8893 modifier == EXPAND_STACK_PARM ? 2 : 0);
8895 expand_expr (TREE_OPERAND (exp, 2),
8896 ignore ? const0_rtx : NULL_RTX, VOIDmode, 0);
8899 end_cleanup_deferral ();
8910 /* Something needs to be initialized, but we didn't know
8911 where that thing was when building the tree. For example,
8912 it could be the return value of a function, or a parameter
8913 to a function which lays down in the stack, or a temporary
8914 variable which must be passed by reference.
8916 We guarantee that the expression will either be constructed
8917 or copied into our original target. */
8919 tree slot = TREE_OPERAND (exp, 0);
8920 tree cleanups = NULL_TREE;
8923 if (TREE_CODE (slot) != VAR_DECL)
8927 target = original_target;
8929 /* Set this here so that if we get a target that refers to a
8930 register variable that's already been used, put_reg_into_stack
8931 knows that it should fix up those uses. */
8932 TREE_USED (slot) = 1;
8936 if (DECL_RTL_SET_P (slot))
8938 target = DECL_RTL (slot);
8939 /* If we have already expanded the slot, so don't do
8941 if (TREE_OPERAND (exp, 1) == NULL_TREE)
8946 target = assign_temp (type, 2, 0, 1);
8947 /* All temp slots at this level must not conflict. */
8948 preserve_temp_slots (target);
8949 SET_DECL_RTL (slot, target);
8950 if (TREE_ADDRESSABLE (slot))
8951 put_var_into_stack (slot, /*rescan=*/false);
8953 /* Since SLOT is not known to the called function
8954 to belong to its stack frame, we must build an explicit
8955 cleanup. This case occurs when we must build up a reference
8956 to pass the reference as an argument. In this case,
8957 it is very likely that such a reference need not be
8960 if (TREE_OPERAND (exp, 2) == 0)
8961 TREE_OPERAND (exp, 2)
8962 = (*lang_hooks.maybe_build_cleanup) (slot);
8963 cleanups = TREE_OPERAND (exp, 2);
8968 /* This case does occur, when expanding a parameter which
8969 needs to be constructed on the stack. The target
8970 is the actual stack address that we want to initialize.
8971 The function we call will perform the cleanup in this case. */
8973 /* If we have already assigned it space, use that space,
8974 not target that we were passed in, as our target
8975 parameter is only a hint. */
8976 if (DECL_RTL_SET_P (slot))
8978 target = DECL_RTL (slot);
8979 /* If we have already expanded the slot, so don't do
8981 if (TREE_OPERAND (exp, 1) == NULL_TREE)
8986 SET_DECL_RTL (slot, target);
8987 /* If we must have an addressable slot, then make sure that
8988 the RTL that we just stored in slot is OK. */
8989 if (TREE_ADDRESSABLE (slot))
8990 put_var_into_stack (slot, /*rescan=*/true);
8994 exp1 = TREE_OPERAND (exp, 3) = TREE_OPERAND (exp, 1);
8995 /* Mark it as expanded. */
8996 TREE_OPERAND (exp, 1) = NULL_TREE;
8998 store_expr (exp1, target, modifier == EXPAND_STACK_PARM ? 2 : 0);
9000 expand_decl_cleanup_eh (NULL_TREE, cleanups, CLEANUP_EH_ONLY (exp));
9007 tree lhs = TREE_OPERAND (exp, 0);
9008 tree rhs = TREE_OPERAND (exp, 1);
9010 temp = expand_assignment (lhs, rhs, ! ignore, original_target != 0);
9016 /* If lhs is complex, expand calls in rhs before computing it.
9017 That's so we don't compute a pointer and save it over a
9018 call. If lhs is simple, compute it first so we can give it
9019 as a target if the rhs is just a call. This avoids an
9020 extra temp and copy and that prevents a partial-subsumption
9021 which makes bad code. Actually we could treat
9022 component_ref's of vars like vars. */
9024 tree lhs = TREE_OPERAND (exp, 0);
9025 tree rhs = TREE_OPERAND (exp, 1);
9029 /* Check for |= or &= of a bitfield of size one into another bitfield
9030 of size 1. In this case, (unless we need the result of the
9031 assignment) we can do this more efficiently with a
9032 test followed by an assignment, if necessary.
9034 ??? At this point, we can't get a BIT_FIELD_REF here. But if
9035 things change so we do, this code should be enhanced to
9038 && TREE_CODE (lhs) == COMPONENT_REF
9039 && (TREE_CODE (rhs) == BIT_IOR_EXPR
9040 || TREE_CODE (rhs) == BIT_AND_EXPR)
9041 && TREE_OPERAND (rhs, 0) == lhs
9042 && TREE_CODE (TREE_OPERAND (rhs, 1)) == COMPONENT_REF
9043 && integer_onep (DECL_SIZE (TREE_OPERAND (lhs, 1)))
9044 && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs, 1), 1))))
9046 rtx label = gen_label_rtx ();
9048 do_jump (TREE_OPERAND (rhs, 1),
9049 TREE_CODE (rhs) == BIT_IOR_EXPR ? label : 0,
9050 TREE_CODE (rhs) == BIT_AND_EXPR ? label : 0);
9051 expand_assignment (lhs, convert (TREE_TYPE (rhs),
9052 (TREE_CODE (rhs) == BIT_IOR_EXPR
9054 : integer_zero_node)),
9056 do_pending_stack_adjust ();
9061 temp = expand_assignment (lhs, rhs, ! ignore, original_target != 0);
9067 if (!TREE_OPERAND (exp, 0))
9068 expand_null_return ();
9070 expand_return (TREE_OPERAND (exp, 0));
9073 case PREINCREMENT_EXPR:
9074 case PREDECREMENT_EXPR:
9075 return expand_increment (exp, 0, ignore);
9077 case POSTINCREMENT_EXPR:
9078 case POSTDECREMENT_EXPR:
9079 /* Faster to treat as pre-increment if result is not used. */
9080 return expand_increment (exp, ! ignore, ignore);
9083 if (modifier == EXPAND_STACK_PARM)
9085 /* Are we taking the address of a nested function? */
9086 if (TREE_CODE (TREE_OPERAND (exp, 0)) == FUNCTION_DECL
9087 && decl_function_context (TREE_OPERAND (exp, 0)) != 0
9088 && ! DECL_NO_STATIC_CHAIN (TREE_OPERAND (exp, 0))
9089 && ! TREE_STATIC (exp))
9091 op0 = trampoline_address (TREE_OPERAND (exp, 0));
9092 op0 = force_operand (op0, target);
9094 /* If we are taking the address of something erroneous, just
9096 else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ERROR_MARK)
9098 /* If we are taking the address of a constant and are at the
9099 top level, we have to use output_constant_def since we can't
9100 call force_const_mem at top level. */
9102 && (TREE_CODE (TREE_OPERAND (exp, 0)) == CONSTRUCTOR
9103 || (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0)))
9105 op0 = XEXP (output_constant_def (TREE_OPERAND (exp, 0), 0), 0);
9108 /* We make sure to pass const0_rtx down if we came in with
9109 ignore set, to avoid doing the cleanups twice for something. */
9110 op0 = expand_expr (TREE_OPERAND (exp, 0),
9111 ignore ? const0_rtx : NULL_RTX, VOIDmode,
9112 (modifier == EXPAND_INITIALIZER
9113 ? modifier : EXPAND_CONST_ADDRESS));
9115 /* If we are going to ignore the result, OP0 will have been set
9116 to const0_rtx, so just return it. Don't get confused and
9117 think we are taking the address of the constant. */
9121 /* Pass 1 for MODIFY, so that protect_from_queue doesn't get
9122 clever and returns a REG when given a MEM. */
9123 op0 = protect_from_queue (op0, 1);
9125 /* We would like the object in memory. If it is a constant, we can
9126 have it be statically allocated into memory. For a non-constant,
9127 we need to allocate some memory and store the value into it. */
9129 if (CONSTANT_P (op0))
9130 op0 = force_const_mem (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))),
9132 else if (GET_CODE (op0) == REG || GET_CODE (op0) == SUBREG
9133 || GET_CODE (op0) == CONCAT || GET_CODE (op0) == ADDRESSOF
9134 || GET_CODE (op0) == PARALLEL)
9136 /* If the operand is a SAVE_EXPR, we can deal with this by
9137 forcing the SAVE_EXPR into memory. */
9138 if (TREE_CODE (TREE_OPERAND (exp, 0)) == SAVE_EXPR)
9140 put_var_into_stack (TREE_OPERAND (exp, 0),
9142 op0 = SAVE_EXPR_RTL (TREE_OPERAND (exp, 0));
9146 /* If this object is in a register, it can't be BLKmode. */
9147 tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
9148 rtx memloc = assign_temp (inner_type, 1, 1, 1);
9150 if (GET_CODE (op0) == PARALLEL)
9151 /* Handle calls that pass values in multiple
9152 non-contiguous locations. The Irix 6 ABI has examples
9154 emit_group_store (memloc, op0,
9155 int_size_in_bytes (inner_type));
9157 emit_move_insn (memloc, op0);
9163 if (GET_CODE (op0) != MEM)
9166 mark_temp_addr_taken (op0);
9167 if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
9169 op0 = XEXP (op0, 0);
9170 #ifdef POINTERS_EXTEND_UNSIGNED
9171 if (GET_MODE (op0) == Pmode && GET_MODE (op0) != mode
9172 && mode == ptr_mode)
9173 op0 = convert_memory_address (ptr_mode, op0);
9178 /* If OP0 is not aligned as least as much as the type requires, we
9179 need to make a temporary, copy OP0 to it, and take the address of
9180 the temporary. We want to use the alignment of the type, not of
9181 the operand. Note that this is incorrect for FUNCTION_TYPE, but
9182 the test for BLKmode means that can't happen. The test for
9183 BLKmode is because we never make mis-aligned MEMs with
9186 We don't need to do this at all if the machine doesn't have
9187 strict alignment. */
9188 if (STRICT_ALIGNMENT && GET_MODE (op0) == BLKmode
9189 && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0)))
9191 && MEM_ALIGN (op0) < BIGGEST_ALIGNMENT)
9193 tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
9196 if (TYPE_ALIGN_OK (inner_type))
9199 if (TREE_ADDRESSABLE (inner_type))
9201 /* We can't make a bitwise copy of this object, so fail. */
9202 error ("cannot take the address of an unaligned member");
9206 new = assign_stack_temp_for_type
9207 (TYPE_MODE (inner_type),
9208 MEM_SIZE (op0) ? INTVAL (MEM_SIZE (op0))
9209 : int_size_in_bytes (inner_type),
9210 1, build_qualified_type (inner_type,
9211 (TYPE_QUALS (inner_type)
9212 | TYPE_QUAL_CONST)));
9214 emit_block_move (new, op0, expr_size (TREE_OPERAND (exp, 0)),
9215 (modifier == EXPAND_STACK_PARM
9216 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
9221 op0 = force_operand (XEXP (op0, 0), target);
9225 && GET_CODE (op0) != REG
9226 && modifier != EXPAND_CONST_ADDRESS
9227 && modifier != EXPAND_INITIALIZER
9228 && modifier != EXPAND_SUM)
9229 op0 = force_reg (Pmode, op0);
9231 if (GET_CODE (op0) == REG
9232 && ! REG_USERVAR_P (op0))
9233 mark_reg_pointer (op0, TYPE_ALIGN (TREE_TYPE (type)));
9235 #ifdef POINTERS_EXTEND_UNSIGNED
9236 if (GET_MODE (op0) == Pmode && GET_MODE (op0) != mode
9237 && mode == ptr_mode)
9238 op0 = convert_memory_address (ptr_mode, op0);
9243 case ENTRY_VALUE_EXPR:
9246 /* COMPLEX type for Extended Pascal & Fortran */
9249 enum machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
9252 /* Get the rtx code of the operands. */
9253 op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
9254 op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
9257 target = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
9261 /* Move the real (op0) and imaginary (op1) parts to their location. */
9262 emit_move_insn (gen_realpart (mode, target), op0);
9263 emit_move_insn (gen_imagpart (mode, target), op1);
9265 insns = get_insns ();
9268 /* Complex construction should appear as a single unit. */
9269 /* If TARGET is a CONCAT, we got insns like RD = RS, ID = IS,
9270 each with a separate pseudo as destination.
9271 It's not correct for flow to treat them as a unit. */
9272 if (GET_CODE (target) != CONCAT)
9273 emit_no_conflict_block (insns, target, op0, op1, NULL_RTX);
9281 op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
9282 return gen_realpart (mode, op0);
9285 op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
9286 return gen_imagpart (mode, op0);
9290 enum machine_mode partmode = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
9294 op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
9297 target = gen_reg_rtx (mode);
9301 /* Store the realpart and the negated imagpart to target. */
9302 emit_move_insn (gen_realpart (partmode, target),
9303 gen_realpart (partmode, op0));
9305 imag_t = gen_imagpart (partmode, target);
9306 temp = expand_unop (partmode,
9307 ! unsignedp && flag_trapv
9308 && (GET_MODE_CLASS(partmode) == MODE_INT)
9309 ? negv_optab : neg_optab,
9310 gen_imagpart (partmode, op0), imag_t, 0);
9312 emit_move_insn (imag_t, temp);
9314 insns = get_insns ();
9317 /* Conjugate should appear as a single unit
9318 If TARGET is a CONCAT, we got insns like RD = RS, ID = - IS,
9319 each with a separate pseudo as destination.
9320 It's not correct for flow to treat them as a unit. */
9321 if (GET_CODE (target) != CONCAT)
9322 emit_no_conflict_block (insns, target, op0, NULL_RTX, NULL_RTX);
9329 case TRY_CATCH_EXPR:
9331 tree handler = TREE_OPERAND (exp, 1);
9333 expand_eh_region_start ();
9335 op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
9337 expand_eh_region_end_cleanup (handler);
9342 case TRY_FINALLY_EXPR:
9344 tree try_block = TREE_OPERAND (exp, 0);
9345 tree finally_block = TREE_OPERAND (exp, 1);
9347 if (!optimize || unsafe_for_reeval (finally_block) > 1)
9349 /* In this case, wrapping FINALLY_BLOCK in an UNSAVE_EXPR
9350 is not sufficient, so we cannot expand the block twice.
9351 So we play games with GOTO_SUBROUTINE_EXPR to let us
9352 expand the thing only once. */
9353 /* When not optimizing, we go ahead with this form since
9354 (1) user breakpoints operate more predictably without
9355 code duplication, and
9356 (2) we're not running any of the global optimizers
9357 that would explode in time/space with the highly
9358 connected CFG created by the indirect branching. */
9360 rtx finally_label = gen_label_rtx ();
9361 rtx done_label = gen_label_rtx ();
9362 rtx return_link = gen_reg_rtx (Pmode);
9363 tree cleanup = build (GOTO_SUBROUTINE_EXPR, void_type_node,
9364 (tree) finally_label, (tree) return_link);
9365 TREE_SIDE_EFFECTS (cleanup) = 1;
9367 /* Start a new binding layer that will keep track of all cleanup
9368 actions to be performed. */
9369 expand_start_bindings (2);
9370 target_temp_slot_level = temp_slot_level;
9372 expand_decl_cleanup (NULL_TREE, cleanup);
9373 op0 = expand_expr (try_block, target, tmode, modifier);
9375 preserve_temp_slots (op0);
9376 expand_end_bindings (NULL_TREE, 0, 0);
9377 emit_jump (done_label);
9378 emit_label (finally_label);
9379 expand_expr (finally_block, const0_rtx, VOIDmode, 0);
9380 emit_indirect_jump (return_link);
9381 emit_label (done_label);
9385 expand_start_bindings (2);
9386 target_temp_slot_level = temp_slot_level;
9388 expand_decl_cleanup (NULL_TREE, finally_block);
9389 op0 = expand_expr (try_block, target, tmode, modifier);
9391 preserve_temp_slots (op0);
9392 expand_end_bindings (NULL_TREE, 0, 0);
9398 case GOTO_SUBROUTINE_EXPR:
9400 rtx subr = (rtx) TREE_OPERAND (exp, 0);
9401 rtx return_link = *(rtx *) &TREE_OPERAND (exp, 1);
9402 rtx return_address = gen_label_rtx ();
9403 emit_move_insn (return_link,
9404 gen_rtx_LABEL_REF (Pmode, return_address));
9406 emit_label (return_address);
9411 return expand_builtin_va_arg (TREE_OPERAND (exp, 0), type);
9414 return get_exception_pointer (cfun);
9417 /* Function descriptors are not valid except for as
9418 initialization constants, and should not be expanded. */
9422 return (*lang_hooks.expand_expr) (exp, original_target, tmode, modifier);
9425 /* Here to do an ordinary binary operator, generating an instruction
9426 from the optab already placed in `this_optab'. */
9428 if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1), 1))
9430 op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
9431 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
9433 if (modifier == EXPAND_STACK_PARM)
9435 temp = expand_binop (mode, this_optab, op0, op1, target,
9436 unsignedp, OPTAB_LIB_WIDEN);
9442 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
9443 when applied to the address of EXP produces an address known to be
9444 aligned more than BIGGEST_ALIGNMENT. */
9447 is_aligning_offset (offset, exp)
9451 /* Strip off any conversions and WITH_RECORD_EXPR nodes. */
9452 while (TREE_CODE (offset) == NON_LVALUE_EXPR
9453 || TREE_CODE (offset) == NOP_EXPR
9454 || TREE_CODE (offset) == CONVERT_EXPR
9455 || TREE_CODE (offset) == WITH_RECORD_EXPR)
9456 offset = TREE_OPERAND (offset, 0);
9458 /* We must now have a BIT_AND_EXPR with a constant that is one less than
9459 power of 2 and which is larger than BIGGEST_ALIGNMENT. */
9460 if (TREE_CODE (offset) != BIT_AND_EXPR
9461 || !host_integerp (TREE_OPERAND (offset, 1), 1)
9462 || compare_tree_int (TREE_OPERAND (offset, 1), BIGGEST_ALIGNMENT) <= 0
9463 || !exact_log2 (tree_low_cst (TREE_OPERAND (offset, 1), 1) + 1) < 0)
9466 /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
9467 It must be NEGATE_EXPR. Then strip any more conversions. */
9468 offset = TREE_OPERAND (offset, 0);
9469 while (TREE_CODE (offset) == NON_LVALUE_EXPR
9470 || TREE_CODE (offset) == NOP_EXPR
9471 || TREE_CODE (offset) == CONVERT_EXPR)
9472 offset = TREE_OPERAND (offset, 0);
9474 if (TREE_CODE (offset) != NEGATE_EXPR)
9477 offset = TREE_OPERAND (offset, 0);
9478 while (TREE_CODE (offset) == NON_LVALUE_EXPR
9479 || TREE_CODE (offset) == NOP_EXPR
9480 || TREE_CODE (offset) == CONVERT_EXPR)
9481 offset = TREE_OPERAND (offset, 0);
9483 /* This must now be the address either of EXP or of a PLACEHOLDER_EXPR
9484 whose type is the same as EXP. */
9485 return (TREE_CODE (offset) == ADDR_EXPR
9486 && (TREE_OPERAND (offset, 0) == exp
9487 || (TREE_CODE (TREE_OPERAND (offset, 0)) == PLACEHOLDER_EXPR
9488 && (TREE_TYPE (TREE_OPERAND (offset, 0))
9489 == TREE_TYPE (exp)))));
9492 /* Return the tree node if an ARG corresponds to a string constant or zero
9493 if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
9494 in bytes within the string that ARG is accessing. The type of the
9495 offset will be `sizetype'. */
9498 string_constant (arg, ptr_offset)
9504 if (TREE_CODE (arg) == ADDR_EXPR
9505 && TREE_CODE (TREE_OPERAND (arg, 0)) == STRING_CST)
9507 *ptr_offset = size_zero_node;
9508 return TREE_OPERAND (arg, 0);
9510 else if (TREE_CODE (arg) == PLUS_EXPR)
9512 tree arg0 = TREE_OPERAND (arg, 0);
9513 tree arg1 = TREE_OPERAND (arg, 1);
9518 if (TREE_CODE (arg0) == ADDR_EXPR
9519 && TREE_CODE (TREE_OPERAND (arg0, 0)) == STRING_CST)
9521 *ptr_offset = convert (sizetype, arg1);
9522 return TREE_OPERAND (arg0, 0);
9524 else if (TREE_CODE (arg1) == ADDR_EXPR
9525 && TREE_CODE (TREE_OPERAND (arg1, 0)) == STRING_CST)
9527 *ptr_offset = convert (sizetype, arg0);
9528 return TREE_OPERAND (arg1, 0);
9535 /* Expand code for a post- or pre- increment or decrement
9536 and return the RTX for the result.
9537 POST is 1 for postinc/decrements and 0 for preinc/decrements. */
9540 expand_increment (exp, post, ignore)
9546 tree incremented = TREE_OPERAND (exp, 0);
9547 optab this_optab = add_optab;
9549 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
9550 int op0_is_copy = 0;
9551 int single_insn = 0;
9552 /* 1 means we can't store into OP0 directly,
9553 because it is a subreg narrower than a word,
9554 and we don't dare clobber the rest of the word. */
9557 /* Stabilize any component ref that might need to be
9558 evaluated more than once below. */
9560 || TREE_CODE (incremented) == BIT_FIELD_REF
9561 || (TREE_CODE (incremented) == COMPONENT_REF
9562 && (TREE_CODE (TREE_OPERAND (incremented, 0)) != INDIRECT_REF
9563 || DECL_BIT_FIELD (TREE_OPERAND (incremented, 1)))))
9564 incremented = stabilize_reference (incremented);
9565 /* Nested *INCREMENT_EXPRs can happen in C++. We must force innermost
9566 ones into save exprs so that they don't accidentally get evaluated
9567 more than once by the code below. */
9568 if (TREE_CODE (incremented) == PREINCREMENT_EXPR
9569 || TREE_CODE (incremented) == PREDECREMENT_EXPR)
9570 incremented = save_expr (incremented);
9572 /* Compute the operands as RTX.
9573 Note whether OP0 is the actual lvalue or a copy of it:
9574 I believe it is a copy iff it is a register or subreg
9575 and insns were generated in computing it. */
9577 temp = get_last_insn ();
9578 op0 = expand_expr (incremented, NULL_RTX, VOIDmode, 0);
9580 /* If OP0 is a SUBREG made for a promoted variable, we cannot increment
9581 in place but instead must do sign- or zero-extension during assignment,
9582 so we copy it into a new register and let the code below use it as
9585 Note that we can safely modify this SUBREG since it is know not to be
9586 shared (it was made by the expand_expr call above). */
9588 if (GET_CODE (op0) == SUBREG && SUBREG_PROMOTED_VAR_P (op0))
9591 SUBREG_REG (op0) = copy_to_reg (SUBREG_REG (op0));
9595 else if (GET_CODE (op0) == SUBREG
9596 && GET_MODE_BITSIZE (GET_MODE (op0)) < BITS_PER_WORD)
9598 /* We cannot increment this SUBREG in place. If we are
9599 post-incrementing, get a copy of the old value. Otherwise,
9600 just mark that we cannot increment in place. */
9602 op0 = copy_to_reg (op0);
9607 op0_is_copy = ((GET_CODE (op0) == SUBREG || GET_CODE (op0) == REG)
9608 && temp != get_last_insn ());
9609 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
9611 /* Decide whether incrementing or decrementing. */
9612 if (TREE_CODE (exp) == POSTDECREMENT_EXPR
9613 || TREE_CODE (exp) == PREDECREMENT_EXPR)
9614 this_optab = sub_optab;
9616 /* Convert decrement by a constant into a negative increment. */
9617 if (this_optab == sub_optab
9618 && GET_CODE (op1) == CONST_INT)
9620 op1 = GEN_INT (-INTVAL (op1));
9621 this_optab = add_optab;
9624 if (TYPE_TRAP_SIGNED (TREE_TYPE (exp)))
9625 this_optab = this_optab == add_optab ? addv_optab : subv_optab;
9627 /* For a preincrement, see if we can do this with a single instruction. */
9630 icode = (int) this_optab->handlers[(int) mode].insn_code;
9631 if (icode != (int) CODE_FOR_nothing
9632 /* Make sure that OP0 is valid for operands 0 and 1
9633 of the insn we want to queue. */
9634 && (*insn_data[icode].operand[0].predicate) (op0, mode)
9635 && (*insn_data[icode].operand[1].predicate) (op0, mode)
9636 && (*insn_data[icode].operand[2].predicate) (op1, mode))
9640 /* If OP0 is not the actual lvalue, but rather a copy in a register,
9641 then we cannot just increment OP0. We must therefore contrive to
9642 increment the original value. Then, for postincrement, we can return
9643 OP0 since it is a copy of the old value. For preincrement, expand here
9644 unless we can do it with a single insn.
9646 Likewise if storing directly into OP0 would clobber high bits
9647 we need to preserve (bad_subreg). */
9648 if (op0_is_copy || (!post && !single_insn) || bad_subreg)
9650 /* This is the easiest way to increment the value wherever it is.
9651 Problems with multiple evaluation of INCREMENTED are prevented
9652 because either (1) it is a component_ref or preincrement,
9653 in which case it was stabilized above, or (2) it is an array_ref
9654 with constant index in an array in a register, which is
9655 safe to reevaluate. */
9656 tree newexp = build (((TREE_CODE (exp) == POSTDECREMENT_EXPR
9657 || TREE_CODE (exp) == PREDECREMENT_EXPR)
9658 ? MINUS_EXPR : PLUS_EXPR),
9661 TREE_OPERAND (exp, 1));
9663 while (TREE_CODE (incremented) == NOP_EXPR
9664 || TREE_CODE (incremented) == CONVERT_EXPR)
9666 newexp = convert (TREE_TYPE (incremented), newexp);
9667 incremented = TREE_OPERAND (incremented, 0);
9670 temp = expand_assignment (incremented, newexp, ! post && ! ignore , 0);
9671 return post ? op0 : temp;
9676 /* We have a true reference to the value in OP0.
9677 If there is an insn to add or subtract in this mode, queue it.
9678 Queueing the increment insn avoids the register shuffling
9679 that often results if we must increment now and first save
9680 the old value for subsequent use. */
9682 #if 0 /* Turned off to avoid making extra insn for indexed memref. */
9683 op0 = stabilize (op0);
9686 icode = (int) this_optab->handlers[(int) mode].insn_code;
9687 if (icode != (int) CODE_FOR_nothing
9688 /* Make sure that OP0 is valid for operands 0 and 1
9689 of the insn we want to queue. */
9690 && (*insn_data[icode].operand[0].predicate) (op0, mode)
9691 && (*insn_data[icode].operand[1].predicate) (op0, mode))
9693 if (! (*insn_data[icode].operand[2].predicate) (op1, mode))
9694 op1 = force_reg (mode, op1);
9696 return enqueue_insn (op0, GEN_FCN (icode) (op0, op0, op1));
9698 if (icode != (int) CODE_FOR_nothing && GET_CODE (op0) == MEM)
9700 rtx addr = (general_operand (XEXP (op0, 0), mode)
9701 ? force_reg (Pmode, XEXP (op0, 0))
9702 : copy_to_reg (XEXP (op0, 0)));
9705 op0 = replace_equiv_address (op0, addr);
9706 temp = force_reg (GET_MODE (op0), op0);
9707 if (! (*insn_data[icode].operand[2].predicate) (op1, mode))
9708 op1 = force_reg (mode, op1);
9710 /* The increment queue is LIFO, thus we have to `queue'
9711 the instructions in reverse order. */
9712 enqueue_insn (op0, gen_move_insn (op0, temp));
9713 result = enqueue_insn (temp, GEN_FCN (icode) (temp, temp, op1));
9718 /* Preincrement, or we can't increment with one simple insn. */
9720 /* Save a copy of the value before inc or dec, to return it later. */
9721 temp = value = copy_to_reg (op0);
9723 /* Arrange to return the incremented value. */
9724 /* Copy the rtx because expand_binop will protect from the queue,
9725 and the results of that would be invalid for us to return
9726 if our caller does emit_queue before using our result. */
9727 temp = copy_rtx (value = op0);
9729 /* Increment however we can. */
9730 op1 = expand_binop (mode, this_optab, value, op1, op0,
9731 TREE_UNSIGNED (TREE_TYPE (exp)), OPTAB_LIB_WIDEN);
9733 /* Make sure the value is stored into OP0. */
9735 emit_move_insn (op0, op1);
9740 /* At the start of a function, record that we have no previously-pushed
9741 arguments waiting to be popped. */
9744 init_pending_stack_adjust ()
9746 pending_stack_adjust = 0;
9749 /* When exiting from function, if safe, clear out any pending stack adjust
9750 so the adjustment won't get done.
9752 Note, if the current function calls alloca, then it must have a
9753 frame pointer regardless of the value of flag_omit_frame_pointer. */
9756 clear_pending_stack_adjust ()
9758 #ifdef EXIT_IGNORE_STACK
9760 && (! flag_omit_frame_pointer || current_function_calls_alloca)
9761 && EXIT_IGNORE_STACK
9762 && ! (DECL_INLINE (current_function_decl) && ! flag_no_inline)
9763 && ! flag_inline_functions)
9765 stack_pointer_delta -= pending_stack_adjust,
9766 pending_stack_adjust = 0;
9771 /* Pop any previously-pushed arguments that have not been popped yet. */
9774 do_pending_stack_adjust ()
9776 if (inhibit_defer_pop == 0)
9778 if (pending_stack_adjust != 0)
9779 adjust_stack (GEN_INT (pending_stack_adjust));
9780 pending_stack_adjust = 0;
9784 /* Expand conditional expressions. */
9786 /* Generate code to evaluate EXP and jump to LABEL if the value is zero.
9787 LABEL is an rtx of code CODE_LABEL, in this function and all the
9791 jumpifnot (exp, label)
9795 do_jump (exp, label, NULL_RTX);
9798 /* Generate code to evaluate EXP and jump to LABEL if the value is nonzero. */
9805 do_jump (exp, NULL_RTX, label);
9808 /* Generate code to evaluate EXP and jump to IF_FALSE_LABEL if
9809 the result is zero, or IF_TRUE_LABEL if the result is one.
9810 Either of IF_FALSE_LABEL and IF_TRUE_LABEL may be zero,
9811 meaning fall through in that case.
9813 do_jump always does any pending stack adjust except when it does not
9814 actually perform a jump. An example where there is no jump
9815 is when EXP is `(foo (), 0)' and IF_FALSE_LABEL is null.
9817 This function is responsible for optimizing cases such as
9818 &&, || and comparison operators in EXP. */
9821 do_jump (exp, if_false_label, if_true_label)
9823 rtx if_false_label, if_true_label;
9825 enum tree_code code = TREE_CODE (exp);
9826 /* Some cases need to create a label to jump to
9827 in order to properly fall through.
9828 These cases set DROP_THROUGH_LABEL nonzero. */
9829 rtx drop_through_label = 0;
9833 enum machine_mode mode;
9835 #ifdef MAX_INTEGER_COMPUTATION_MODE
9836 check_max_integer_computation_mode (exp);
9847 temp = integer_zerop (exp) ? if_false_label : if_true_label;
9853 /* This is not true with #pragma weak */
9855 /* The address of something can never be zero. */
9857 emit_jump (if_true_label);
9862 do_jump (TREE_OPERAND (exp, 0), if_false_label, if_true_label);
9863 TREE_OPERAND (exp, 0)
9864 = (*lang_hooks.unsave_expr_now) (TREE_OPERAND (exp, 0));
9868 if (TREE_CODE (TREE_OPERAND (exp, 0)) == COMPONENT_REF
9869 || TREE_CODE (TREE_OPERAND (exp, 0)) == BIT_FIELD_REF
9870 || TREE_CODE (TREE_OPERAND (exp, 0)) == ARRAY_REF
9871 || TREE_CODE (TREE_OPERAND (exp, 0)) == ARRAY_RANGE_REF)
9874 /* If we are narrowing the operand, we have to do the compare in the
9876 if ((TYPE_PRECISION (TREE_TYPE (exp))
9877 < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp, 0)))))
9879 case NON_LVALUE_EXPR:
9880 case REFERENCE_EXPR:
9885 /* These cannot change zero->nonzero or vice versa. */
9886 do_jump (TREE_OPERAND (exp, 0), if_false_label, if_true_label);
9889 case WITH_RECORD_EXPR:
9890 /* Put the object on the placeholder list, recurse through our first
9891 operand, and pop the list. */
9892 placeholder_list = tree_cons (TREE_OPERAND (exp, 1), NULL_TREE,
9894 do_jump (TREE_OPERAND (exp, 0), if_false_label, if_true_label);
9895 placeholder_list = TREE_CHAIN (placeholder_list);
9899 /* This is never less insns than evaluating the PLUS_EXPR followed by
9900 a test and can be longer if the test is eliminated. */
9902 /* Reduce to minus. */
9903 exp = build (MINUS_EXPR, TREE_TYPE (exp),
9904 TREE_OPERAND (exp, 0),
9905 fold (build1 (NEGATE_EXPR, TREE_TYPE (TREE_OPERAND (exp, 1)),
9906 TREE_OPERAND (exp, 1))));
9907 /* Process as MINUS. */
9911 /* Nonzero iff operands of minus differ. */
9912 do_compare_and_jump (build (NE_EXPR, TREE_TYPE (exp),
9913 TREE_OPERAND (exp, 0),
9914 TREE_OPERAND (exp, 1)),
9915 NE, NE, if_false_label, if_true_label);
9919 /* If we are AND'ing with a small constant, do this comparison in the
9920 smallest type that fits. If the machine doesn't have comparisons
9921 that small, it will be converted back to the wider comparison.
9922 This helps if we are testing the sign bit of a narrower object.
9923 combine can't do this for us because it can't know whether a
9924 ZERO_EXTRACT or a compare in a smaller mode exists, but we do. */
9926 if (! SLOW_BYTE_ACCESS
9927 && TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
9928 && TYPE_PRECISION (TREE_TYPE (exp)) <= HOST_BITS_PER_WIDE_INT
9929 && (i = tree_floor_log2 (TREE_OPERAND (exp, 1))) >= 0
9930 && (mode = mode_for_size (i + 1, MODE_INT, 0)) != BLKmode
9931 && (type = (*lang_hooks.types.type_for_mode) (mode, 1)) != 0
9932 && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (exp))
9933 && (cmp_optab->handlers[(int) TYPE_MODE (type)].insn_code
9934 != CODE_FOR_nothing))
9936 do_jump (convert (type, exp), if_false_label, if_true_label);
9941 case TRUTH_NOT_EXPR:
9942 do_jump (TREE_OPERAND (exp, 0), if_true_label, if_false_label);
9945 case TRUTH_ANDIF_EXPR:
9946 if (if_false_label == 0)
9947 if_false_label = drop_through_label = gen_label_rtx ();
9948 do_jump (TREE_OPERAND (exp, 0), if_false_label, NULL_RTX);
9949 start_cleanup_deferral ();
9950 do_jump (TREE_OPERAND (exp, 1), if_false_label, if_true_label);
9951 end_cleanup_deferral ();
9954 case TRUTH_ORIF_EXPR:
9955 if (if_true_label == 0)
9956 if_true_label = drop_through_label = gen_label_rtx ();
9957 do_jump (TREE_OPERAND (exp, 0), NULL_RTX, if_true_label);
9958 start_cleanup_deferral ();
9959 do_jump (TREE_OPERAND (exp, 1), if_false_label, if_true_label);
9960 end_cleanup_deferral ();
9965 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
9966 preserve_temp_slots (NULL_RTX);
9970 do_pending_stack_adjust ();
9971 do_jump (TREE_OPERAND (exp, 1), if_false_label, if_true_label);
9977 case ARRAY_RANGE_REF:
9979 HOST_WIDE_INT bitsize, bitpos;
9981 enum machine_mode mode;
9986 /* Get description of this reference. We don't actually care
9987 about the underlying object here. */
9988 get_inner_reference (exp, &bitsize, &bitpos, &offset, &mode,
9989 &unsignedp, &volatilep);
9991 type = (*lang_hooks.types.type_for_size) (bitsize, unsignedp);
9992 if (! SLOW_BYTE_ACCESS
9993 && type != 0 && bitsize >= 0
9994 && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (exp))
9995 && (cmp_optab->handlers[(int) TYPE_MODE (type)].insn_code
9996 != CODE_FOR_nothing))
9998 do_jump (convert (type, exp), if_false_label, if_true_label);
10005 /* Do (a ? 1 : 0) and (a ? 0 : 1) as special cases. */
10006 if (integer_onep (TREE_OPERAND (exp, 1))
10007 && integer_zerop (TREE_OPERAND (exp, 2)))
10008 do_jump (TREE_OPERAND (exp, 0), if_false_label, if_true_label);
10010 else if (integer_zerop (TREE_OPERAND (exp, 1))
10011 && integer_onep (TREE_OPERAND (exp, 2)))
10012 do_jump (TREE_OPERAND (exp, 0), if_true_label, if_false_label);
10016 rtx label1 = gen_label_rtx ();
10017 drop_through_label = gen_label_rtx ();
10019 do_jump (TREE_OPERAND (exp, 0), label1, NULL_RTX);
10021 start_cleanup_deferral ();
10022 /* Now the THEN-expression. */
10023 do_jump (TREE_OPERAND (exp, 1),
10024 if_false_label ? if_false_label : drop_through_label,
10025 if_true_label ? if_true_label : drop_through_label);
10026 /* In case the do_jump just above never jumps. */
10027 do_pending_stack_adjust ();
10028 emit_label (label1);
10030 /* Now the ELSE-expression. */
10031 do_jump (TREE_OPERAND (exp, 2),
10032 if_false_label ? if_false_label : drop_through_label,
10033 if_true_label ? if_true_label : drop_through_label);
10034 end_cleanup_deferral ();
10040 tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
10042 if (GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_COMPLEX_FLOAT
10043 || GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_COMPLEX_INT)
10045 tree exp0 = save_expr (TREE_OPERAND (exp, 0));
10046 tree exp1 = save_expr (TREE_OPERAND (exp, 1));
10049 (build (TRUTH_ANDIF_EXPR, TREE_TYPE (exp),
10050 fold (build (EQ_EXPR, TREE_TYPE (exp),
10051 fold (build1 (REALPART_EXPR,
10052 TREE_TYPE (inner_type),
10054 fold (build1 (REALPART_EXPR,
10055 TREE_TYPE (inner_type),
10057 fold (build (EQ_EXPR, TREE_TYPE (exp),
10058 fold (build1 (IMAGPART_EXPR,
10059 TREE_TYPE (inner_type),
10061 fold (build1 (IMAGPART_EXPR,
10062 TREE_TYPE (inner_type),
10064 if_false_label, if_true_label);
10067 else if (integer_zerop (TREE_OPERAND (exp, 1)))
10068 do_jump (TREE_OPERAND (exp, 0), if_true_label, if_false_label);
10070 else if (GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_INT
10071 && !can_compare_p (EQ, TYPE_MODE (inner_type), ccp_jump))
10072 do_jump_by_parts_equality (exp, if_false_label, if_true_label);
10074 do_compare_and_jump (exp, EQ, EQ, if_false_label, if_true_label);
10080 tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
10082 if (GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_COMPLEX_FLOAT
10083 || GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_COMPLEX_INT)
10085 tree exp0 = save_expr (TREE_OPERAND (exp, 0));
10086 tree exp1 = save_expr (TREE_OPERAND (exp, 1));
10089 (build (TRUTH_ORIF_EXPR, TREE_TYPE (exp),
10090 fold (build (NE_EXPR, TREE_TYPE (exp),
10091 fold (build1 (REALPART_EXPR,
10092 TREE_TYPE (inner_type),
10094 fold (build1 (REALPART_EXPR,
10095 TREE_TYPE (inner_type),
10097 fold (build (NE_EXPR, TREE_TYPE (exp),
10098 fold (build1 (IMAGPART_EXPR,
10099 TREE_TYPE (inner_type),
10101 fold (build1 (IMAGPART_EXPR,
10102 TREE_TYPE (inner_type),
10104 if_false_label, if_true_label);
10107 else if (integer_zerop (TREE_OPERAND (exp, 1)))
10108 do_jump (TREE_OPERAND (exp, 0), if_false_label, if_true_label);
10110 else if (GET_MODE_CLASS (TYPE_MODE (inner_type)) == MODE_INT
10111 && !can_compare_p (NE, TYPE_MODE (inner_type), ccp_jump))
10112 do_jump_by_parts_equality (exp, if_true_label, if_false_label);
10114 do_compare_and_jump (exp, NE, NE, if_false_label, if_true_label);
10119 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
10120 if (GET_MODE_CLASS (mode) == MODE_INT
10121 && ! can_compare_p (LT, mode, ccp_jump))
10122 do_jump_by_parts_greater (exp, 1, if_false_label, if_true_label);
10124 do_compare_and_jump (exp, LT, LTU, if_false_label, if_true_label);
10128 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
10129 if (GET_MODE_CLASS (mode) == MODE_INT
10130 && ! can_compare_p (LE, mode, ccp_jump))
10131 do_jump_by_parts_greater (exp, 0, if_true_label, if_false_label);
10133 do_compare_and_jump (exp, LE, LEU, if_false_label, if_true_label);
10137 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
10138 if (GET_MODE_CLASS (mode) == MODE_INT
10139 && ! can_compare_p (GT, mode, ccp_jump))
10140 do_jump_by_parts_greater (exp, 0, if_false_label, if_true_label);
10142 do_compare_and_jump (exp, GT, GTU, if_false_label, if_true_label);
10146 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
10147 if (GET_MODE_CLASS (mode) == MODE_INT
10148 && ! can_compare_p (GE, mode, ccp_jump))
10149 do_jump_by_parts_greater (exp, 1, if_true_label, if_false_label);
10151 do_compare_and_jump (exp, GE, GEU, if_false_label, if_true_label);
10154 case UNORDERED_EXPR:
10157 enum rtx_code cmp, rcmp;
10160 if (code == UNORDERED_EXPR)
10161 cmp = UNORDERED, rcmp = ORDERED;
10163 cmp = ORDERED, rcmp = UNORDERED;
10164 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
10167 if (! can_compare_p (cmp, mode, ccp_jump)
10168 && (can_compare_p (rcmp, mode, ccp_jump)
10169 /* If the target doesn't provide either UNORDERED or ORDERED
10170 comparisons, canonicalize on UNORDERED for the library. */
10171 || rcmp == UNORDERED))
10175 do_compare_and_jump (exp, cmp, cmp, if_false_label, if_true_label);
10177 do_compare_and_jump (exp, rcmp, rcmp, if_true_label, if_false_label);
10182 enum rtx_code rcode1;
10183 enum tree_code tcode2;
10188 goto unordered_bcc;
10192 goto unordered_bcc;
10196 goto unordered_bcc;
10200 goto unordered_bcc;
10204 goto unordered_bcc;
10207 mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
10208 if (can_compare_p (rcode1, mode, ccp_jump))
10209 do_compare_and_jump (exp, rcode1, rcode1, if_false_label,
10213 tree op0 = save_expr (TREE_OPERAND (exp, 0));
10214 tree op1 = save_expr (TREE_OPERAND (exp, 1));
10217 /* If the target doesn't support combined unordered
10218 compares, decompose into UNORDERED + comparison. */
10219 cmp0 = fold (build (UNORDERED_EXPR, TREE_TYPE (exp), op0, op1));
10220 cmp1 = fold (build (tcode2, TREE_TYPE (exp), op0, op1));
10221 exp = build (TRUTH_ORIF_EXPR, TREE_TYPE (exp), cmp0, cmp1);
10222 do_jump (exp, if_false_label, if_true_label);
10228 __builtin_expect (<test>, 0) and
10229 __builtin_expect (<test>, 1)
10231 We need to do this here, so that <test> is not converted to a SCC
10232 operation on machines that use condition code registers and COMPARE
10233 like the PowerPC, and then the jump is done based on whether the SCC
10234 operation produced a 1 or 0. */
10236 /* Check for a built-in function. */
10237 if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR)
10239 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
10240 tree arglist = TREE_OPERAND (exp, 1);
10242 if (TREE_CODE (fndecl) == FUNCTION_DECL
10243 && DECL_BUILT_IN (fndecl)
10244 && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_EXPECT
10245 && arglist != NULL_TREE
10246 && TREE_CHAIN (arglist) != NULL_TREE)
10248 rtx seq = expand_builtin_expect_jump (exp, if_false_label,
10251 if (seq != NULL_RTX)
10258 /* fall through and generate the normal code. */
10262 temp = expand_expr (exp, NULL_RTX, VOIDmode, 0);
10264 /* This is not needed any more and causes poor code since it causes
10265 comparisons and tests from non-SI objects to have different code
10267 /* Copy to register to avoid generating bad insns by cse
10268 from (set (mem ...) (arithop)) (set (cc0) (mem ...)). */
10269 if (!cse_not_expected && GET_CODE (temp) == MEM)
10270 temp = copy_to_reg (temp);
10272 do_pending_stack_adjust ();
10273 /* Do any postincrements in the expression that was tested. */
10276 if (GET_CODE (temp) == CONST_INT
10277 || (GET_CODE (temp) == CONST_DOUBLE && GET_MODE (temp) == VOIDmode)
10278 || GET_CODE (temp) == LABEL_REF)
10280 rtx target = temp == const0_rtx ? if_false_label : if_true_label;
10282 emit_jump (target);
10284 else if (GET_MODE_CLASS (GET_MODE (temp)) == MODE_INT
10285 && ! can_compare_p (NE, GET_MODE (temp), ccp_jump))
10286 /* Note swapping the labels gives us not-equal. */
10287 do_jump_by_parts_equality_rtx (temp, if_true_label, if_false_label);
10288 else if (GET_MODE (temp) != VOIDmode)
10289 do_compare_rtx_and_jump (temp, CONST0_RTX (GET_MODE (temp)),
10290 NE, TREE_UNSIGNED (TREE_TYPE (exp)),
10291 GET_MODE (temp), NULL_RTX,
10292 if_false_label, if_true_label);
10297 if (drop_through_label)
10299 /* If do_jump produces code that might be jumped around,
10300 do any stack adjusts from that code, before the place
10301 where control merges in. */
10302 do_pending_stack_adjust ();
10303 emit_label (drop_through_label);
10307 /* Given a comparison expression EXP for values too wide to be compared
10308 with one insn, test the comparison and jump to the appropriate label.
10309 The code of EXP is ignored; we always test GT if SWAP is 0,
10310 and LT if SWAP is 1. */
10313 do_jump_by_parts_greater (exp, swap, if_false_label, if_true_label)
10316 rtx if_false_label, if_true_label;
10318 rtx op0 = expand_expr (TREE_OPERAND (exp, swap), NULL_RTX, VOIDmode, 0);
10319 rtx op1 = expand_expr (TREE_OPERAND (exp, !swap), NULL_RTX, VOIDmode, 0);
10320 enum machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
10321 int unsignedp = TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0)));
10323 do_jump_by_parts_greater_rtx (mode, unsignedp, op0, op1, if_false_label, if_true_label);
10326 /* Compare OP0 with OP1, word at a time, in mode MODE.
10327 UNSIGNEDP says to do unsigned comparison.
10328 Jump to IF_TRUE_LABEL if OP0 is greater, IF_FALSE_LABEL otherwise. */
10331 do_jump_by_parts_greater_rtx (mode, unsignedp, op0, op1, if_false_label, if_true_label)
10332 enum machine_mode mode;
10335 rtx if_false_label, if_true_label;
10337 int nwords = (GET_MODE_SIZE (mode) / UNITS_PER_WORD);
10338 rtx drop_through_label = 0;
10341 if (! if_true_label || ! if_false_label)
10342 drop_through_label = gen_label_rtx ();
10343 if (! if_true_label)
10344 if_true_label = drop_through_label;
10345 if (! if_false_label)
10346 if_false_label = drop_through_label;
10348 /* Compare a word at a time, high order first. */
10349 for (i = 0; i < nwords; i++)
10351 rtx op0_word, op1_word;
10353 if (WORDS_BIG_ENDIAN)
10355 op0_word = operand_subword_force (op0, i, mode);
10356 op1_word = operand_subword_force (op1, i, mode);
10360 op0_word = operand_subword_force (op0, nwords - 1 - i, mode);
10361 op1_word = operand_subword_force (op1, nwords - 1 - i, mode);
10364 /* All but high-order word must be compared as unsigned. */
10365 do_compare_rtx_and_jump (op0_word, op1_word, GT,
10366 (unsignedp || i > 0), word_mode, NULL_RTX,
10367 NULL_RTX, if_true_label);
10369 /* Consider lower words only if these are equal. */
10370 do_compare_rtx_and_jump (op0_word, op1_word, NE, unsignedp, word_mode,
10371 NULL_RTX, NULL_RTX, if_false_label);
10374 if (if_false_label)
10375 emit_jump (if_false_label);
10376 if (drop_through_label)
10377 emit_label (drop_through_label);
10380 /* Given an EQ_EXPR expression EXP for values too wide to be compared
10381 with one insn, test the comparison and jump to the appropriate label. */
10384 do_jump_by_parts_equality (exp, if_false_label, if_true_label)
10386 rtx if_false_label, if_true_label;
10388 rtx op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
10389 rtx op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
10390 enum machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)));
10391 int nwords = (GET_MODE_SIZE (mode) / UNITS_PER_WORD);
10393 rtx drop_through_label = 0;
10395 if (! if_false_label)
10396 drop_through_label = if_false_label = gen_label_rtx ();
10398 for (i = 0; i < nwords; i++)
10399 do_compare_rtx_and_jump (operand_subword_force (op0, i, mode),
10400 operand_subword_force (op1, i, mode),
10401 EQ, TREE_UNSIGNED (TREE_TYPE (exp)),
10402 word_mode, NULL_RTX, if_false_label, NULL_RTX);
10405 emit_jump (if_true_label);
10406 if (drop_through_label)
10407 emit_label (drop_through_label);
10410 /* Jump according to whether OP0 is 0.
10411 We assume that OP0 has an integer mode that is too wide
10412 for the available compare insns. */
10415 do_jump_by_parts_equality_rtx (op0, if_false_label, if_true_label)
10417 rtx if_false_label, if_true_label;
10419 int nwords = GET_MODE_SIZE (GET_MODE (op0)) / UNITS_PER_WORD;
10422 rtx drop_through_label = 0;
10424 /* The fastest way of doing this comparison on almost any machine is to
10425 "or" all the words and compare the result. If all have to be loaded
10426 from memory and this is a very wide item, it's possible this may
10427 be slower, but that's highly unlikely. */
10429 part = gen_reg_rtx (word_mode);
10430 emit_move_insn (part, operand_subword_force (op0, 0, GET_MODE (op0)));
10431 for (i = 1; i < nwords && part != 0; i++)
10432 part = expand_binop (word_mode, ior_optab, part,
10433 operand_subword_force (op0, i, GET_MODE (op0)),
10434 part, 1, OPTAB_WIDEN);
10438 do_compare_rtx_and_jump (part, const0_rtx, EQ, 1, word_mode,
10439 NULL_RTX, if_false_label, if_true_label);
10444 /* If we couldn't do the "or" simply, do this with a series of compares. */
10445 if (! if_false_label)
10446 drop_through_label = if_false_label = gen_label_rtx ();
10448 for (i = 0; i < nwords; i++)
10449 do_compare_rtx_and_jump (operand_subword_force (op0, i, GET_MODE (op0)),
10450 const0_rtx, EQ, 1, word_mode, NULL_RTX,
10451 if_false_label, NULL_RTX);
10454 emit_jump (if_true_label);
10456 if (drop_through_label)
10457 emit_label (drop_through_label);
10460 /* Generate code for a comparison of OP0 and OP1 with rtx code CODE.
10461 (including code to compute the values to be compared)
10462 and set (CC0) according to the result.
10463 The decision as to signed or unsigned comparison must be made by the caller.
10465 We force a stack adjustment unless there are currently
10466 things pushed on the stack that aren't yet used.
10468 If MODE is BLKmode, SIZE is an RTX giving the size of the objects being
10472 compare_from_rtx (op0, op1, code, unsignedp, mode, size)
10474 enum rtx_code code;
10476 enum machine_mode mode;
10479 enum rtx_code ucode;
10482 /* If one operand is constant, make it the second one. Only do this
10483 if the other operand is not constant as well. */
10485 if (swap_commutative_operands_p (op0, op1))
10490 code = swap_condition (code);
10493 if (flag_force_mem)
10495 op0 = force_not_mem (op0);
10496 op1 = force_not_mem (op1);
10499 do_pending_stack_adjust ();
10501 ucode = unsignedp ? unsigned_condition (code) : code;
10502 if ((tem = simplify_relational_operation (ucode, mode, op0, op1)) != 0)
10506 /* There's no need to do this now that combine.c can eliminate lots of
10507 sign extensions. This can be less efficient in certain cases on other
10510 /* If this is a signed equality comparison, we can do it as an
10511 unsigned comparison since zero-extension is cheaper than sign
10512 extension and comparisons with zero are done as unsigned. This is
10513 the case even on machines that can do fast sign extension, since
10514 zero-extension is easier to combine with other operations than
10515 sign-extension is. If we are comparing against a constant, we must
10516 convert it to what it would look like unsigned. */
10517 if ((code == EQ || code == NE) && ! unsignedp
10518 && GET_MODE_BITSIZE (GET_MODE (op0)) <= HOST_BITS_PER_WIDE_INT)
10520 if (GET_CODE (op1) == CONST_INT
10521 && (INTVAL (op1) & GET_MODE_MASK (GET_MODE (op0))) != INTVAL (op1))
10522 op1 = GEN_INT (INTVAL (op1) & GET_MODE_MASK (GET_MODE (op0)));
10527 emit_cmp_insn (op0, op1, code, size, mode, unsignedp);
10530 return gen_rtx_fmt_ee (code, VOIDmode, cc0_rtx, const0_rtx);
10532 return gen_rtx_fmt_ee (code, VOIDmode, op0, op1);
10536 /* Like do_compare_and_jump but expects the values to compare as two rtx's.
10537 The decision as to signed or unsigned comparison must be made by the caller.
10539 If MODE is BLKmode, SIZE is an RTX giving the size of the objects being
10543 do_compare_rtx_and_jump (op0, op1, code, unsignedp, mode, size,
10544 if_false_label, if_true_label)
10546 enum rtx_code code;
10548 enum machine_mode mode;
10550 rtx if_false_label, if_true_label;
10552 enum rtx_code ucode;
10554 int dummy_true_label = 0;
10556 /* Reverse the comparison if that is safe and we want to jump if it is
10558 if (! if_true_label && ! FLOAT_MODE_P (mode))
10560 if_true_label = if_false_label;
10561 if_false_label = 0;
10562 code = reverse_condition (code);
10565 /* If one operand is constant, make it the second one. Only do this
10566 if the other operand is not constant as well. */
10568 if (swap_commutative_operands_p (op0, op1))
10573 code = swap_condition (code);
10576 if (flag_force_mem)
10578 op0 = force_not_mem (op0);
10579 op1 = force_not_mem (op1);
10582 do_pending_stack_adjust ();
10584 ucode = unsignedp ? unsigned_condition (code) : code;
10585 if ((tem = simplify_relational_operation (ucode, mode, op0, op1)) != 0)
10587 if (tem == const_true_rtx)
10590 emit_jump (if_true_label);
10594 if (if_false_label)
10595 emit_jump (if_false_label);
10601 /* There's no need to do this now that combine.c can eliminate lots of
10602 sign extensions. This can be less efficient in certain cases on other
10605 /* If this is a signed equality comparison, we can do it as an
10606 unsigned comparison since zero-extension is cheaper than sign
10607 extension and comparisons with zero are done as unsigned. This is
10608 the case even on machines that can do fast sign extension, since
10609 zero-extension is easier to combine with other operations than
10610 sign-extension is. If we are comparing against a constant, we must
10611 convert it to what it would look like unsigned. */
10612 if ((code == EQ || code == NE) && ! unsignedp
10613 && GET_MODE_BITSIZE (GET_MODE (op0)) <= HOST_BITS_PER_WIDE_INT)
10615 if (GET_CODE (op1) == CONST_INT
10616 && (INTVAL (op1) & GET_MODE_MASK (GET_MODE (op0))) != INTVAL (op1))
10617 op1 = GEN_INT (INTVAL (op1) & GET_MODE_MASK (GET_MODE (op0)));
10622 if (! if_true_label)
10624 dummy_true_label = 1;
10625 if_true_label = gen_label_rtx ();
10628 emit_cmp_and_jump_insns (op0, op1, code, size, mode, unsignedp,
10631 if (if_false_label)
10632 emit_jump (if_false_label);
10633 if (dummy_true_label)
10634 emit_label (if_true_label);
10637 /* Generate code for a comparison expression EXP (including code to compute
10638 the values to be compared) and a conditional jump to IF_FALSE_LABEL and/or
10639 IF_TRUE_LABEL. One of the labels can be NULL_RTX, in which case the
10640 generated code will drop through.
10641 SIGNED_CODE should be the rtx operation for this comparison for
10642 signed data; UNSIGNED_CODE, likewise for use if data is unsigned.
10644 We force a stack adjustment unless there are currently
10645 things pushed on the stack that aren't yet used. */
10648 do_compare_and_jump (exp, signed_code, unsigned_code, if_false_label,
10651 enum rtx_code signed_code, unsigned_code;
10652 rtx if_false_label, if_true_label;
10656 enum machine_mode mode;
10658 enum rtx_code code;
10660 /* Don't crash if the comparison was erroneous. */
10661 op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
10662 if (TREE_CODE (TREE_OPERAND (exp, 0)) == ERROR_MARK)
10665 op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
10666 if (TREE_CODE (TREE_OPERAND (exp, 1)) == ERROR_MARK)
10669 type = TREE_TYPE (TREE_OPERAND (exp, 0));
10670 mode = TYPE_MODE (type);
10671 if (TREE_CODE (TREE_OPERAND (exp, 0)) == INTEGER_CST
10672 && (TREE_CODE (TREE_OPERAND (exp, 1)) != INTEGER_CST
10673 || (GET_MODE_BITSIZE (mode)
10674 > GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp,
10677 /* op0 might have been replaced by promoted constant, in which
10678 case the type of second argument should be used. */
10679 type = TREE_TYPE (TREE_OPERAND (exp, 1));
10680 mode = TYPE_MODE (type);
10682 unsignedp = TREE_UNSIGNED (type);
10683 code = unsignedp ? unsigned_code : signed_code;
10685 #ifdef HAVE_canonicalize_funcptr_for_compare
10686 /* If function pointers need to be "canonicalized" before they can
10687 be reliably compared, then canonicalize them. */
10688 if (HAVE_canonicalize_funcptr_for_compare
10689 && TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == POINTER_TYPE
10690 && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))))
10693 rtx new_op0 = gen_reg_rtx (mode);
10695 emit_insn (gen_canonicalize_funcptr_for_compare (new_op0, op0));
10699 if (HAVE_canonicalize_funcptr_for_compare
10700 && TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 1))) == POINTER_TYPE
10701 && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 1))))
10704 rtx new_op1 = gen_reg_rtx (mode);
10706 emit_insn (gen_canonicalize_funcptr_for_compare (new_op1, op1));
10711 /* Do any postincrements in the expression that was tested. */
10714 do_compare_rtx_and_jump (op0, op1, code, unsignedp, mode,
10716 ? expr_size (TREE_OPERAND (exp, 0)) : NULL_RTX),
10717 if_false_label, if_true_label);
10720 /* Generate code to calculate EXP using a store-flag instruction
10721 and return an rtx for the result. EXP is either a comparison
10722 or a TRUTH_NOT_EXPR whose operand is a comparison.
10724 If TARGET is nonzero, store the result there if convenient.
10726 If ONLY_CHEAP is nonzero, only do this if it is likely to be very
10729 Return zero if there is no suitable set-flag instruction
10730 available on this machine.
10732 Once expand_expr has been called on the arguments of the comparison,
10733 we are committed to doing the store flag, since it is not safe to
10734 re-evaluate the expression. We emit the store-flag insn by calling
10735 emit_store_flag, but only expand the arguments if we have a reason
10736 to believe that emit_store_flag will be successful. If we think that
10737 it will, but it isn't, we have to simulate the store-flag with a
10738 set/jump/set sequence. */
10741 do_store_flag (exp, target, mode, only_cheap)
10744 enum machine_mode mode;
10747 enum rtx_code code;
10748 tree arg0, arg1, type;
10750 enum machine_mode operand_mode;
10754 enum insn_code icode;
10755 rtx subtarget = target;
10758 /* If this is a TRUTH_NOT_EXPR, set a flag indicating we must invert the
10759 result at the end. We can't simply invert the test since it would
10760 have already been inverted if it were valid. This case occurs for
10761 some floating-point comparisons. */
10763 if (TREE_CODE (exp) == TRUTH_NOT_EXPR)
10764 invert = 1, exp = TREE_OPERAND (exp, 0);
10766 arg0 = TREE_OPERAND (exp, 0);
10767 arg1 = TREE_OPERAND (exp, 1);
10769 /* Don't crash if the comparison was erroneous. */
10770 if (arg0 == error_mark_node || arg1 == error_mark_node)
10773 type = TREE_TYPE (arg0);
10774 operand_mode = TYPE_MODE (type);
10775 unsignedp = TREE_UNSIGNED (type);
10777 /* We won't bother with BLKmode store-flag operations because it would mean
10778 passing a lot of information to emit_store_flag. */
10779 if (operand_mode == BLKmode)
10782 /* We won't bother with store-flag operations involving function pointers
10783 when function pointers must be canonicalized before comparisons. */
10784 #ifdef HAVE_canonicalize_funcptr_for_compare
10785 if (HAVE_canonicalize_funcptr_for_compare
10786 && ((TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == POINTER_TYPE
10787 && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))))
10789 || (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 1))) == POINTER_TYPE
10790 && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 1))))
10791 == FUNCTION_TYPE))))
10798 /* Get the rtx comparison code to use. We know that EXP is a comparison
10799 operation of some type. Some comparisons against 1 and -1 can be
10800 converted to comparisons with zero. Do so here so that the tests
10801 below will be aware that we have a comparison with zero. These
10802 tests will not catch constants in the first operand, but constants
10803 are rarely passed as the first operand. */
10805 switch (TREE_CODE (exp))
10814 if (integer_onep (arg1))
10815 arg1 = integer_zero_node, code = unsignedp ? LEU : LE;
10817 code = unsignedp ? LTU : LT;
10820 if (! unsignedp && integer_all_onesp (arg1))
10821 arg1 = integer_zero_node, code = LT;
10823 code = unsignedp ? LEU : LE;
10826 if (! unsignedp && integer_all_onesp (arg1))
10827 arg1 = integer_zero_node, code = GE;
10829 code = unsignedp ? GTU : GT;
10832 if (integer_onep (arg1))
10833 arg1 = integer_zero_node, code = unsignedp ? GTU : GT;
10835 code = unsignedp ? GEU : GE;
10838 case UNORDERED_EXPR:
10864 /* Put a constant second. */
10865 if (TREE_CODE (arg0) == REAL_CST || TREE_CODE (arg0) == INTEGER_CST)
10867 tem = arg0; arg0 = arg1; arg1 = tem;
10868 code = swap_condition (code);
10871 /* If this is an equality or inequality test of a single bit, we can
10872 do this by shifting the bit being tested to the low-order bit and
10873 masking the result with the constant 1. If the condition was EQ,
10874 we xor it with 1. This does not require an scc insn and is faster
10875 than an scc insn even if we have it. */
10877 if ((code == NE || code == EQ)
10878 && TREE_CODE (arg0) == BIT_AND_EXPR && integer_zerop (arg1)
10879 && integer_pow2p (TREE_OPERAND (arg0, 1)))
10881 tree inner = TREE_OPERAND (arg0, 0);
10882 int bitnum = tree_log2 (TREE_OPERAND (arg0, 1));
10885 /* If INNER is a right shift of a constant and it plus BITNUM does
10886 not overflow, adjust BITNUM and INNER. */
10888 if (TREE_CODE (inner) == RSHIFT_EXPR
10889 && TREE_CODE (TREE_OPERAND (inner, 1)) == INTEGER_CST
10890 && TREE_INT_CST_HIGH (TREE_OPERAND (inner, 1)) == 0
10891 && bitnum < TYPE_PRECISION (type)
10892 && 0 > compare_tree_int (TREE_OPERAND (inner, 1),
10893 bitnum - TYPE_PRECISION (type)))
10895 bitnum += TREE_INT_CST_LOW (TREE_OPERAND (inner, 1));
10896 inner = TREE_OPERAND (inner, 0);
10899 /* If we are going to be able to omit the AND below, we must do our
10900 operations as unsigned. If we must use the AND, we have a choice.
10901 Normally unsigned is faster, but for some machines signed is. */
10902 ops_unsignedp = (bitnum == TYPE_PRECISION (type) - 1 ? 1
10903 #ifdef LOAD_EXTEND_OP
10904 : (LOAD_EXTEND_OP (operand_mode) == SIGN_EXTEND ? 0 : 1)
10910 if (! get_subtarget (subtarget)
10911 || GET_MODE (subtarget) != operand_mode
10912 || ! safe_from_p (subtarget, inner, 1))
10915 op0 = expand_expr (inner, subtarget, VOIDmode, 0);
10918 op0 = expand_shift (RSHIFT_EXPR, operand_mode, op0,
10919 size_int (bitnum), subtarget, ops_unsignedp);
10921 if (GET_MODE (op0) != mode)
10922 op0 = convert_to_mode (mode, op0, ops_unsignedp);
10924 if ((code == EQ && ! invert) || (code == NE && invert))
10925 op0 = expand_binop (mode, xor_optab, op0, const1_rtx, subtarget,
10926 ops_unsignedp, OPTAB_LIB_WIDEN);
10928 /* Put the AND last so it can combine with more things. */
10929 if (bitnum != TYPE_PRECISION (type) - 1)
10930 op0 = expand_and (mode, op0, const1_rtx, subtarget);
10935 /* Now see if we are likely to be able to do this. Return if not. */
10936 if (! can_compare_p (code, operand_mode, ccp_store_flag))
10939 icode = setcc_gen_code[(int) code];
10940 if (icode == CODE_FOR_nothing
10941 || (only_cheap && insn_data[(int) icode].operand[0].mode != mode))
10943 /* We can only do this if it is one of the special cases that
10944 can be handled without an scc insn. */
10945 if ((code == LT && integer_zerop (arg1))
10946 || (! only_cheap && code == GE && integer_zerop (arg1)))
10948 else if (BRANCH_COST >= 0
10949 && ! only_cheap && (code == NE || code == EQ)
10950 && TREE_CODE (type) != REAL_TYPE
10951 && ((abs_optab->handlers[(int) operand_mode].insn_code
10952 != CODE_FOR_nothing)
10953 || (ffs_optab->handlers[(int) operand_mode].insn_code
10954 != CODE_FOR_nothing)))
10960 if (! get_subtarget (target)
10961 || GET_MODE (subtarget) != operand_mode
10962 || ! safe_from_p (subtarget, arg1, 1))
10965 op0 = expand_expr (arg0, subtarget, VOIDmode, 0);
10966 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
10969 target = gen_reg_rtx (mode);
10971 /* Pass copies of OP0 and OP1 in case they contain a QUEUED. This is safe
10972 because, if the emit_store_flag does anything it will succeed and
10973 OP0 and OP1 will not be used subsequently. */
10975 result = emit_store_flag (target, code,
10976 queued_subexp_p (op0) ? copy_rtx (op0) : op0,
10977 queued_subexp_p (op1) ? copy_rtx (op1) : op1,
10978 operand_mode, unsignedp, 1);
10983 result = expand_binop (mode, xor_optab, result, const1_rtx,
10984 result, 0, OPTAB_LIB_WIDEN);
10988 /* If this failed, we have to do this with set/compare/jump/set code. */
10989 if (GET_CODE (target) != REG
10990 || reg_mentioned_p (target, op0) || reg_mentioned_p (target, op1))
10991 target = gen_reg_rtx (GET_MODE (target));
10993 emit_move_insn (target, invert ? const0_rtx : const1_rtx);
10994 result = compare_from_rtx (op0, op1, code, unsignedp,
10995 operand_mode, NULL_RTX);
10996 if (GET_CODE (result) == CONST_INT)
10997 return (((result == const0_rtx && ! invert)
10998 || (result != const0_rtx && invert))
10999 ? const0_rtx : const1_rtx);
11001 /* The code of RESULT may not match CODE if compare_from_rtx
11002 decided to swap its operands and reverse the original code.
11004 We know that compare_from_rtx returns either a CONST_INT or
11005 a new comparison code, so it is safe to just extract the
11006 code from RESULT. */
11007 code = GET_CODE (result);
11009 label = gen_label_rtx ();
11010 if (bcc_gen_fctn[(int) code] == 0)
11013 emit_jump_insn ((*bcc_gen_fctn[(int) code]) (label));
11014 emit_move_insn (target, invert ? const1_rtx : const0_rtx);
11015 emit_label (label);
11021 /* Stubs in case we haven't got a casesi insn. */
11022 #ifndef HAVE_casesi
11023 # define HAVE_casesi 0
11024 # define gen_casesi(a, b, c, d, e) (0)
11025 # define CODE_FOR_casesi CODE_FOR_nothing
11028 /* If the machine does not have a case insn that compares the bounds,
11029 this means extra overhead for dispatch tables, which raises the
11030 threshold for using them. */
11031 #ifndef CASE_VALUES_THRESHOLD
11032 #define CASE_VALUES_THRESHOLD (HAVE_casesi ? 4 : 5)
11033 #endif /* CASE_VALUES_THRESHOLD */
11036 case_values_threshold ()
11038 return CASE_VALUES_THRESHOLD;
11041 /* Attempt to generate a casesi instruction. Returns 1 if successful,
11042 0 otherwise (i.e. if there is no casesi instruction). */
11044 try_casesi (index_type, index_expr, minval, range,
11045 table_label, default_label)
11046 tree index_type, index_expr, minval, range;
11047 rtx table_label ATTRIBUTE_UNUSED;
11050 enum machine_mode index_mode = SImode;
11051 int index_bits = GET_MODE_BITSIZE (index_mode);
11052 rtx op1, op2, index;
11053 enum machine_mode op_mode;
11058 /* Convert the index to SImode. */
11059 if (GET_MODE_BITSIZE (TYPE_MODE (index_type)) > GET_MODE_BITSIZE (index_mode))
11061 enum machine_mode omode = TYPE_MODE (index_type);
11062 rtx rangertx = expand_expr (range, NULL_RTX, VOIDmode, 0);
11064 /* We must handle the endpoints in the original mode. */
11065 index_expr = build (MINUS_EXPR, index_type,
11066 index_expr, minval);
11067 minval = integer_zero_node;
11068 index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
11069 emit_cmp_and_jump_insns (rangertx, index, LTU, NULL_RTX,
11070 omode, 1, default_label);
11071 /* Now we can safely truncate. */
11072 index = convert_to_mode (index_mode, index, 0);
11076 if (TYPE_MODE (index_type) != index_mode)
11078 index_expr = convert ((*lang_hooks.types.type_for_size)
11079 (index_bits, 0), index_expr);
11080 index_type = TREE_TYPE (index_expr);
11083 index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
11086 index = protect_from_queue (index, 0);
11087 do_pending_stack_adjust ();
11089 op_mode = insn_data[(int) CODE_FOR_casesi].operand[0].mode;
11090 if (! (*insn_data[(int) CODE_FOR_casesi].operand[0].predicate)
11092 index = copy_to_mode_reg (op_mode, index);
11094 op1 = expand_expr (minval, NULL_RTX, VOIDmode, 0);
11096 op_mode = insn_data[(int) CODE_FOR_casesi].operand[1].mode;
11097 op1 = convert_modes (op_mode, TYPE_MODE (TREE_TYPE (minval)),
11098 op1, TREE_UNSIGNED (TREE_TYPE (minval)));
11099 if (! (*insn_data[(int) CODE_FOR_casesi].operand[1].predicate)
11101 op1 = copy_to_mode_reg (op_mode, op1);
11103 op2 = expand_expr (range, NULL_RTX, VOIDmode, 0);
11105 op_mode = insn_data[(int) CODE_FOR_casesi].operand[2].mode;
11106 op2 = convert_modes (op_mode, TYPE_MODE (TREE_TYPE (range)),
11107 op2, TREE_UNSIGNED (TREE_TYPE (range)));
11108 if (! (*insn_data[(int) CODE_FOR_casesi].operand[2].predicate)
11110 op2 = copy_to_mode_reg (op_mode, op2);
11112 emit_jump_insn (gen_casesi (index, op1, op2,
11113 table_label, default_label));
11117 /* Attempt to generate a tablejump instruction; same concept. */
11118 #ifndef HAVE_tablejump
11119 #define HAVE_tablejump 0
11120 #define gen_tablejump(x, y) (0)
11123 /* Subroutine of the next function.
11125 INDEX is the value being switched on, with the lowest value
11126 in the table already subtracted.
11127 MODE is its expected mode (needed if INDEX is constant).
11128 RANGE is the length of the jump table.
11129 TABLE_LABEL is a CODE_LABEL rtx for the table itself.
11131 DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
11132 index value is out of range. */
11135 do_tablejump (index, mode, range, table_label, default_label)
11136 rtx index, range, table_label, default_label;
11137 enum machine_mode mode;
11141 if (INTVAL (range) > cfun->max_jumptable_ents)
11142 cfun->max_jumptable_ents = INTVAL (range);
11144 /* Do an unsigned comparison (in the proper mode) between the index
11145 expression and the value which represents the length of the range.
11146 Since we just finished subtracting the lower bound of the range
11147 from the index expression, this comparison allows us to simultaneously
11148 check that the original index expression value is both greater than
11149 or equal to the minimum value of the range and less than or equal to
11150 the maximum value of the range. */
11152 emit_cmp_and_jump_insns (index, range, GTU, NULL_RTX, mode, 1,
11155 /* If index is in range, it must fit in Pmode.
11156 Convert to Pmode so we can index with it. */
11158 index = convert_to_mode (Pmode, index, 1);
11160 /* Don't let a MEM slip thru, because then INDEX that comes
11161 out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
11162 and break_out_memory_refs will go to work on it and mess it up. */
11163 #ifdef PIC_CASE_VECTOR_ADDRESS
11164 if (flag_pic && GET_CODE (index) != REG)
11165 index = copy_to_mode_reg (Pmode, index);
11168 /* If flag_force_addr were to affect this address
11169 it could interfere with the tricky assumptions made
11170 about addresses that contain label-refs,
11171 which may be valid only very near the tablejump itself. */
11172 /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
11173 GET_MODE_SIZE, because this indicates how large insns are. The other
11174 uses should all be Pmode, because they are addresses. This code
11175 could fail if addresses and insns are not the same size. */
11176 index = gen_rtx_PLUS (Pmode,
11177 gen_rtx_MULT (Pmode, index,
11178 GEN_INT (GET_MODE_SIZE (CASE_VECTOR_MODE))),
11179 gen_rtx_LABEL_REF (Pmode, table_label));
11180 #ifdef PIC_CASE_VECTOR_ADDRESS
11182 index = PIC_CASE_VECTOR_ADDRESS (index);
11185 index = memory_address_noforce (CASE_VECTOR_MODE, index);
11186 temp = gen_reg_rtx (CASE_VECTOR_MODE);
11187 vector = gen_rtx_MEM (CASE_VECTOR_MODE, index);
11188 RTX_UNCHANGING_P (vector) = 1;
11189 MEM_NOTRAP_P (vector) = 1;
11190 convert_move (temp, vector, 0);
11192 emit_jump_insn (gen_tablejump (temp, table_label));
11194 /* If we are generating PIC code or if the table is PC-relative, the
11195 table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
11196 if (! CASE_VECTOR_PC_RELATIVE && ! flag_pic)
11201 try_tablejump (index_type, index_expr, minval, range,
11202 table_label, default_label)
11203 tree index_type, index_expr, minval, range;
11204 rtx table_label, default_label;
11208 if (! HAVE_tablejump)
11211 index_expr = fold (build (MINUS_EXPR, index_type,
11212 convert (index_type, index_expr),
11213 convert (index_type, minval)));
11214 index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
11216 index = protect_from_queue (index, 0);
11217 do_pending_stack_adjust ();
11219 do_tablejump (index, TYPE_MODE (index_type),
11220 convert_modes (TYPE_MODE (index_type),
11221 TYPE_MODE (TREE_TYPE (range)),
11222 expand_expr (range, NULL_RTX,
11224 TREE_UNSIGNED (TREE_TYPE (range))),
11225 table_label, default_label);
11229 /* Nonzero if the mode is a valid vector mode for this architecture.
11230 This returns nonzero even if there is no hardware support for the
11231 vector mode, but we can emulate with narrower modes. */
11234 vector_mode_valid_p (mode)
11235 enum machine_mode mode;
11237 enum mode_class class = GET_MODE_CLASS (mode);
11238 enum machine_mode innermode;
11240 /* Doh! What's going on? */
11241 if (class != MODE_VECTOR_INT
11242 && class != MODE_VECTOR_FLOAT)
11245 /* Hardware support. Woo hoo! */
11246 if (VECTOR_MODE_SUPPORTED_P (mode))
11249 innermode = GET_MODE_INNER (mode);
11251 /* We should probably return 1 if requesting V4DI and we have no DI,
11252 but we have V2DI, but this is probably very unlikely. */
11254 /* If we have support for the inner mode, we can safely emulate it.
11255 We may not have V2DI, but me can emulate with a pair of DIs. */
11256 return mov_optab->handlers[innermode].insn_code != CODE_FOR_nothing;
11259 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
11261 const_vector_from_tree (exp)
11267 enum machine_mode inner, mode;
11269 mode = TYPE_MODE (TREE_TYPE (exp));
11271 if (is_zeros_p (exp))
11272 return CONST0_RTX (mode);
11274 units = GET_MODE_NUNITS (mode);
11275 inner = GET_MODE_INNER (mode);
11277 v = rtvec_alloc (units);
11279 link = TREE_VECTOR_CST_ELTS (exp);
11280 for (i = 0; link; link = TREE_CHAIN (link), ++i)
11282 elt = TREE_VALUE (link);
11284 if (TREE_CODE (elt) == REAL_CST)
11285 RTVEC_ELT (v, i) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt),
11288 RTVEC_ELT (v, i) = immed_double_const (TREE_INT_CST_LOW (elt),
11289 TREE_INT_CST_HIGH (elt),
11293 return gen_rtx_raw_CONST_VECTOR (mode, v);
11296 #include "gt-expr.h"