OSDN Git Service

* alias.c (get_alias_set): Remove handling of PLACEHOLDER_EXPR.
[pf3gnuchains/gcc-fork.git] / gcc / expr.c
1 /* Convert tree expression to rtl instructions, for GNU compiler.
2    Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3    2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
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
10 version.
11
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
15 for more details.
16
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
20 02111-1307, USA.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "machmode.h"
27 #include "real.h"
28 #include "rtl.h"
29 #include "tree.h"
30 #include "flags.h"
31 #include "regs.h"
32 #include "hard-reg-set.h"
33 #include "except.h"
34 #include "function.h"
35 #include "insn-config.h"
36 #include "insn-attr.h"
37 /* Include expr.h after insn-config.h so we get HAVE_conditional_move.  */
38 #include "expr.h"
39 #include "optabs.h"
40 #include "libfuncs.h"
41 #include "recog.h"
42 #include "reload.h"
43 #include "output.h"
44 #include "typeclass.h"
45 #include "toplev.h"
46 #include "ggc.h"
47 #include "langhooks.h"
48 #include "intl.h"
49 #include "tm_p.h"
50 #include "target.h"
51
52 /* Decide whether a function's arguments should be processed
53    from first to last or from last to first.
54
55    They should if the stack and args grow in opposite directions, but
56    only if we have push insns.  */
57
58 #ifdef PUSH_ROUNDING
59
60 #ifndef PUSH_ARGS_REVERSED
61 #if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD)
62 #define PUSH_ARGS_REVERSED      /* If it's last to first.  */
63 #endif
64 #endif
65
66 #endif
67
68 #ifndef STACK_PUSH_CODE
69 #ifdef STACK_GROWS_DOWNWARD
70 #define STACK_PUSH_CODE PRE_DEC
71 #else
72 #define STACK_PUSH_CODE PRE_INC
73 #endif
74 #endif
75
76 /* Convert defined/undefined to boolean.  */
77 #ifdef TARGET_MEM_FUNCTIONS
78 #undef TARGET_MEM_FUNCTIONS
79 #define TARGET_MEM_FUNCTIONS 1
80 #else
81 #define TARGET_MEM_FUNCTIONS 0
82 #endif
83
84
85 /* If this is nonzero, we do not bother generating VOLATILE
86    around volatile memory references, and we are willing to
87    output indirect addresses.  If cse is to follow, we reject
88    indirect addresses so a useful potential cse is generated;
89    if it is used only once, instruction combination will produce
90    the same indirect address eventually.  */
91 int cse_not_expected;
92
93 /* This structure is used by move_by_pieces to describe the move to
94    be performed.  */
95 struct move_by_pieces
96 {
97   rtx to;
98   rtx to_addr;
99   int autinc_to;
100   int explicit_inc_to;
101   rtx from;
102   rtx from_addr;
103   int autinc_from;
104   int explicit_inc_from;
105   unsigned HOST_WIDE_INT len;
106   HOST_WIDE_INT offset;
107   int reverse;
108 };
109
110 /* This structure is used by store_by_pieces to describe the clear to
111    be performed.  */
112
113 struct store_by_pieces
114 {
115   rtx to;
116   rtx to_addr;
117   int autinc_to;
118   int explicit_inc_to;
119   unsigned HOST_WIDE_INT len;
120   HOST_WIDE_INT offset;
121   rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode);
122   void *constfundata;
123   int reverse;
124 };
125
126 static rtx enqueue_insn (rtx, rtx);
127 static unsigned HOST_WIDE_INT move_by_pieces_ninsns (unsigned HOST_WIDE_INT,
128                                                      unsigned int);
129 static void move_by_pieces_1 (rtx (*) (rtx, ...), enum machine_mode,
130                               struct move_by_pieces *);
131 static bool block_move_libcall_safe_for_call_parm (void);
132 static bool emit_block_move_via_movstr (rtx, rtx, rtx, unsigned);
133 static rtx emit_block_move_via_libcall (rtx, rtx, rtx);
134 static tree emit_block_move_libcall_fn (int);
135 static void emit_block_move_via_loop (rtx, rtx, rtx, unsigned);
136 static rtx clear_by_pieces_1 (void *, HOST_WIDE_INT, enum machine_mode);
137 static void clear_by_pieces (rtx, unsigned HOST_WIDE_INT, unsigned int);
138 static void store_by_pieces_1 (struct store_by_pieces *, unsigned int);
139 static void store_by_pieces_2 (rtx (*) (rtx, ...), enum machine_mode,
140                                struct store_by_pieces *);
141 static bool clear_storage_via_clrstr (rtx, rtx, unsigned);
142 static rtx clear_storage_via_libcall (rtx, rtx);
143 static tree clear_storage_libcall_fn (int);
144 static rtx compress_float_constant (rtx, rtx);
145 static rtx get_subtarget (rtx);
146 static int is_zeros_p (tree);
147 static void store_constructor_field (rtx, unsigned HOST_WIDE_INT,
148                                      HOST_WIDE_INT, enum machine_mode,
149                                      tree, tree, int, int);
150 static void store_constructor (tree, rtx, int, HOST_WIDE_INT);
151 static rtx store_field (rtx, HOST_WIDE_INT, HOST_WIDE_INT, enum machine_mode,
152                         tree, enum machine_mode, int, tree, int);
153 static rtx var_rtx (tree);
154
155 static unsigned HOST_WIDE_INT highest_pow2_factor (tree);
156 static unsigned HOST_WIDE_INT highest_pow2_factor_for_target (tree, tree);
157
158 static int is_aligning_offset (tree, tree);
159 static rtx expand_increment (tree, int, int);
160 static void expand_operands (tree, tree, rtx, rtx*, rtx*,
161                              enum expand_modifier);
162 static rtx do_store_flag (tree, rtx, enum machine_mode, int);
163 #ifdef PUSH_ROUNDING
164 static void emit_single_push_insn (enum machine_mode, rtx, tree);
165 #endif
166 static void do_tablejump (rtx, enum machine_mode, rtx, rtx, rtx);
167 static rtx const_vector_from_tree (tree);
168
169 /* Record for each mode whether we can move a register directly to or
170    from an object of that mode in memory.  If we can't, we won't try
171    to use that mode directly when accessing a field of that mode.  */
172
173 static char direct_load[NUM_MACHINE_MODES];
174 static char direct_store[NUM_MACHINE_MODES];
175
176 /* Record for each mode whether we can float-extend from memory.  */
177
178 static bool float_extend_from_mem[NUM_MACHINE_MODES][NUM_MACHINE_MODES];
179
180 /* This macro is used to determine whether move_by_pieces should be called
181    to perform a structure copy.  */
182 #ifndef MOVE_BY_PIECES_P
183 #define MOVE_BY_PIECES_P(SIZE, ALIGN) \
184   (move_by_pieces_ninsns (SIZE, ALIGN) < (unsigned int) MOVE_RATIO)
185 #endif
186
187 /* This macro is used to determine whether clear_by_pieces should be
188    called to clear storage.  */
189 #ifndef CLEAR_BY_PIECES_P
190 #define CLEAR_BY_PIECES_P(SIZE, ALIGN) \
191   (move_by_pieces_ninsns (SIZE, ALIGN) < (unsigned int) CLEAR_RATIO)
192 #endif
193
194 /* This macro is used to determine whether store_by_pieces should be
195    called to "memset" storage with byte values other than zero, or
196    to "memcpy" storage when the source is a constant string.  */
197 #ifndef STORE_BY_PIECES_P
198 #define STORE_BY_PIECES_P(SIZE, ALIGN)  MOVE_BY_PIECES_P (SIZE, ALIGN)
199 #endif
200
201 /* This array records the insn_code of insns to perform block moves.  */
202 enum insn_code movstr_optab[NUM_MACHINE_MODES];
203
204 /* This array records the insn_code of insns to perform block clears.  */
205 enum insn_code clrstr_optab[NUM_MACHINE_MODES];
206
207 /* These arrays record the insn_code of two different kinds of insns
208    to perform block compares.  */
209 enum insn_code cmpstr_optab[NUM_MACHINE_MODES];
210 enum insn_code cmpmem_optab[NUM_MACHINE_MODES];
211
212 /* Stack of EXPR_WITH_FILE_LOCATION nested expressions.  */
213 struct file_stack *expr_wfl_stack;
214
215 /* SLOW_UNALIGNED_ACCESS is nonzero if unaligned accesses are very slow.  */
216
217 #ifndef SLOW_UNALIGNED_ACCESS
218 #define SLOW_UNALIGNED_ACCESS(MODE, ALIGN) STRICT_ALIGNMENT
219 #endif
220 \f
221 /* This is run once per compilation to set up which modes can be used
222    directly in memory and to initialize the block move optab.  */
223
224 void
225 init_expr_once (void)
226 {
227   rtx insn, pat;
228   enum machine_mode mode;
229   int num_clobbers;
230   rtx mem, mem1;
231   rtx reg;
232
233   /* Try indexing by frame ptr and try by stack ptr.
234      It is known that on the Convex the stack ptr isn't a valid index.
235      With luck, one or the other is valid on any machine.  */
236   mem = gen_rtx_MEM (VOIDmode, stack_pointer_rtx);
237   mem1 = gen_rtx_MEM (VOIDmode, frame_pointer_rtx);
238
239   /* A scratch register we can modify in-place below to avoid
240      useless RTL allocations.  */
241   reg = gen_rtx_REG (VOIDmode, -1);
242
243   insn = rtx_alloc (INSN);
244   pat = gen_rtx_SET (0, NULL_RTX, NULL_RTX);
245   PATTERN (insn) = pat;
246
247   for (mode = VOIDmode; (int) mode < NUM_MACHINE_MODES;
248        mode = (enum machine_mode) ((int) mode + 1))
249     {
250       int regno;
251
252       direct_load[(int) mode] = direct_store[(int) mode] = 0;
253       PUT_MODE (mem, mode);
254       PUT_MODE (mem1, mode);
255       PUT_MODE (reg, mode);
256
257       /* See if there is some register that can be used in this mode and
258          directly loaded or stored from memory.  */
259
260       if (mode != VOIDmode && mode != BLKmode)
261         for (regno = 0; regno < FIRST_PSEUDO_REGISTER
262              && (direct_load[(int) mode] == 0 || direct_store[(int) mode] == 0);
263              regno++)
264           {
265             if (! HARD_REGNO_MODE_OK (regno, mode))
266               continue;
267
268             REGNO (reg) = regno;
269
270             SET_SRC (pat) = mem;
271             SET_DEST (pat) = reg;
272             if (recog (pat, insn, &num_clobbers) >= 0)
273               direct_load[(int) mode] = 1;
274
275             SET_SRC (pat) = mem1;
276             SET_DEST (pat) = reg;
277             if (recog (pat, insn, &num_clobbers) >= 0)
278               direct_load[(int) mode] = 1;
279
280             SET_SRC (pat) = reg;
281             SET_DEST (pat) = mem;
282             if (recog (pat, insn, &num_clobbers) >= 0)
283               direct_store[(int) mode] = 1;
284
285             SET_SRC (pat) = reg;
286             SET_DEST (pat) = mem1;
287             if (recog (pat, insn, &num_clobbers) >= 0)
288               direct_store[(int) mode] = 1;
289           }
290     }
291
292   mem = gen_rtx_MEM (VOIDmode, gen_rtx_raw_REG (Pmode, 10000));
293
294   for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
295        mode = GET_MODE_WIDER_MODE (mode))
296     {
297       enum machine_mode srcmode;
298       for (srcmode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); srcmode != mode;
299            srcmode = GET_MODE_WIDER_MODE (srcmode))
300         {
301           enum insn_code ic;
302
303           ic = can_extend_p (mode, srcmode, 0);
304           if (ic == CODE_FOR_nothing)
305             continue;
306
307           PUT_MODE (mem, srcmode);
308
309           if ((*insn_data[ic].operand[1].predicate) (mem, srcmode))
310             float_extend_from_mem[mode][srcmode] = true;
311         }
312     }
313 }
314
315 /* This is run at the start of compiling a function.  */
316
317 void
318 init_expr (void)
319 {
320   cfun->expr = ggc_alloc_cleared (sizeof (struct expr_status));
321 }
322
323 /* Small sanity check that the queue is empty at the end of a function.  */
324
325 void
326 finish_expr_for_function (void)
327 {
328   if (pending_chain)
329     abort ();
330 }
331 \f
332 /* Manage the queue of increment instructions to be output
333    for POSTINCREMENT_EXPR expressions, etc.  */
334
335 /* Queue up to increment (or change) VAR later.  BODY says how:
336    BODY should be the same thing you would pass to emit_insn
337    to increment right away.  It will go to emit_insn later on.
338
339    The value is a QUEUED expression to be used in place of VAR
340    where you want to guarantee the pre-incrementation value of VAR.  */
341
342 static rtx
343 enqueue_insn (rtx var, rtx body)
344 {
345   pending_chain = gen_rtx_QUEUED (GET_MODE (var), var, NULL_RTX, NULL_RTX,
346                                   body, pending_chain);
347   return pending_chain;
348 }
349
350 /* Use protect_from_queue to convert a QUEUED expression
351    into something that you can put immediately into an instruction.
352    If the queued incrementation has not happened yet,
353    protect_from_queue returns the variable itself.
354    If the incrementation has happened, protect_from_queue returns a temp
355    that contains a copy of the old value of the variable.
356
357    Any time an rtx which might possibly be a QUEUED is to be put
358    into an instruction, it must be passed through protect_from_queue first.
359    QUEUED expressions are not meaningful in instructions.
360
361    Do not pass a value through protect_from_queue and then hold
362    on to it for a while before putting it in an instruction!
363    If the queue is flushed in between, incorrect code will result.  */
364
365 rtx
366 protect_from_queue (rtx x, int modify)
367 {
368   RTX_CODE code = GET_CODE (x);
369
370 #if 0  /* A QUEUED can hang around after the queue is forced out.  */
371   /* Shortcut for most common case.  */
372   if (pending_chain == 0)
373     return x;
374 #endif
375
376   if (code != QUEUED)
377     {
378       /* A special hack for read access to (MEM (QUEUED ...)) to facilitate
379          use of autoincrement.  Make a copy of the contents of the memory
380          location rather than a copy of the address, but not if the value is
381          of mode BLKmode.  Don't modify X in place since it might be
382          shared.  */
383       if (code == MEM && GET_MODE (x) != BLKmode
384           && GET_CODE (XEXP (x, 0)) == QUEUED && !modify)
385         {
386           rtx y = XEXP (x, 0);
387           rtx new = replace_equiv_address_nv (x, QUEUED_VAR (y));
388
389           if (QUEUED_INSN (y))
390             {
391               rtx temp = gen_reg_rtx (GET_MODE (x));
392
393               emit_insn_before (gen_move_insn (temp, new),
394                                 QUEUED_INSN (y));
395               return temp;
396             }
397
398           /* Copy the address into a pseudo, so that the returned value
399              remains correct across calls to emit_queue.  */
400           return replace_equiv_address (new, copy_to_reg (XEXP (new, 0)));
401         }
402
403       /* Otherwise, recursively protect the subexpressions of all
404          the kinds of rtx's that can contain a QUEUED.  */
405       if (code == MEM)
406         {
407           rtx tem = protect_from_queue (XEXP (x, 0), 0);
408           if (tem != XEXP (x, 0))
409             {
410               x = copy_rtx (x);
411               XEXP (x, 0) = tem;
412             }
413         }
414       else if (code == PLUS || code == MULT)
415         {
416           rtx new0 = protect_from_queue (XEXP (x, 0), 0);
417           rtx new1 = protect_from_queue (XEXP (x, 1), 0);
418           if (new0 != XEXP (x, 0) || new1 != XEXP (x, 1))
419             {
420               x = copy_rtx (x);
421               XEXP (x, 0) = new0;
422               XEXP (x, 1) = new1;
423             }
424         }
425       return x;
426     }
427   /* If the increment has not happened, use the variable itself.  Copy it
428      into a new pseudo so that the value remains correct across calls to
429      emit_queue.  */
430   if (QUEUED_INSN (x) == 0)
431     return copy_to_reg (QUEUED_VAR (x));
432   /* If the increment has happened and a pre-increment copy exists,
433      use that copy.  */
434   if (QUEUED_COPY (x) != 0)
435     return QUEUED_COPY (x);
436   /* The increment has happened but we haven't set up a pre-increment copy.
437      Set one up now, and use it.  */
438   QUEUED_COPY (x) = gen_reg_rtx (GET_MODE (QUEUED_VAR (x)));
439   emit_insn_before (gen_move_insn (QUEUED_COPY (x), QUEUED_VAR (x)),
440                     QUEUED_INSN (x));
441   return QUEUED_COPY (x);
442 }
443
444 /* Return nonzero if X contains a QUEUED expression:
445    if it contains anything that will be altered by a queued increment.
446    We handle only combinations of MEM, PLUS, MINUS and MULT operators
447    since memory addresses generally contain only those.  */
448
449 int
450 queued_subexp_p (rtx x)
451 {
452   enum rtx_code code = GET_CODE (x);
453   switch (code)
454     {
455     case QUEUED:
456       return 1;
457     case MEM:
458       return queued_subexp_p (XEXP (x, 0));
459     case MULT:
460     case PLUS:
461     case MINUS:
462       return (queued_subexp_p (XEXP (x, 0))
463               || queued_subexp_p (XEXP (x, 1)));
464     default:
465       return 0;
466     }
467 }
468
469 /* Perform all the pending incrementations.  */
470
471 void
472 emit_queue (void)
473 {
474   rtx p;
475   while ((p = pending_chain))
476     {
477       rtx body = QUEUED_BODY (p);
478
479       switch (GET_CODE (body))
480         {
481         case INSN:
482         case JUMP_INSN:
483         case CALL_INSN:
484         case CODE_LABEL:
485         case BARRIER:
486         case NOTE:
487           QUEUED_INSN (p) = body;
488           emit_insn (body);
489           break;
490
491 #ifdef ENABLE_CHECKING
492         case SEQUENCE:
493           abort ();
494           break;
495 #endif
496
497         default:
498           QUEUED_INSN (p) = emit_insn (body);
499           break;
500         }
501
502       pending_chain = QUEUED_NEXT (p);
503     }
504 }
505 \f
506 /* Copy data from FROM to TO, where the machine modes are not the same.
507    Both modes may be integer, or both may be floating.
508    UNSIGNEDP should be nonzero if FROM is an unsigned type.
509    This causes zero-extension instead of sign-extension.  */
510
511 void
512 convert_move (rtx to, rtx from, int unsignedp)
513 {
514   enum machine_mode to_mode = GET_MODE (to);
515   enum machine_mode from_mode = GET_MODE (from);
516   int to_real = GET_MODE_CLASS (to_mode) == MODE_FLOAT;
517   int from_real = GET_MODE_CLASS (from_mode) == MODE_FLOAT;
518   enum insn_code code;
519   rtx libcall;
520
521   /* rtx code for making an equivalent value.  */
522   enum rtx_code equiv_code = (unsignedp < 0 ? UNKNOWN
523                               : (unsignedp ? ZERO_EXTEND : SIGN_EXTEND));
524
525   to = protect_from_queue (to, 1);
526   from = protect_from_queue (from, 0);
527
528   if (to_real != from_real)
529     abort ();
530
531   /* If FROM is a SUBREG that indicates that we have already done at least
532      the required extension, strip it.  We don't handle such SUBREGs as
533      TO here.  */
534
535   if (GET_CODE (from) == SUBREG && SUBREG_PROMOTED_VAR_P (from)
536       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (from)))
537           >= GET_MODE_SIZE (to_mode))
538       && SUBREG_PROMOTED_UNSIGNED_P (from) == unsignedp)
539     from = gen_lowpart (to_mode, from), from_mode = to_mode;
540
541   if (GET_CODE (to) == SUBREG && SUBREG_PROMOTED_VAR_P (to))
542     abort ();
543
544   if (to_mode == from_mode
545       || (from_mode == VOIDmode && CONSTANT_P (from)))
546     {
547       emit_move_insn (to, from);
548       return;
549     }
550
551   if (VECTOR_MODE_P (to_mode) || VECTOR_MODE_P (from_mode))
552     {
553       if (GET_MODE_BITSIZE (from_mode) != GET_MODE_BITSIZE (to_mode))
554         abort ();
555
556       if (VECTOR_MODE_P (to_mode))
557         from = simplify_gen_subreg (to_mode, from, GET_MODE (from), 0);
558       else
559         to = simplify_gen_subreg (from_mode, to, GET_MODE (to), 0);
560
561       emit_move_insn (to, from);
562       return;
563     }
564
565   if (GET_CODE (to) == CONCAT && GET_CODE (from) == CONCAT)
566     {
567       convert_move (XEXP (to, 0), XEXP (from, 0), unsignedp);
568       convert_move (XEXP (to, 1), XEXP (from, 1), unsignedp);
569       return;
570     }
571
572   if (to_real)
573     {
574       rtx value, insns;
575       convert_optab tab;
576
577       if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode))
578         tab = sext_optab;
579       else if (GET_MODE_PRECISION (from_mode) > GET_MODE_PRECISION (to_mode))
580         tab = trunc_optab;
581       else
582         abort ();
583
584       /* Try converting directly if the insn is supported.  */
585
586       code = tab->handlers[to_mode][from_mode].insn_code;
587       if (code != CODE_FOR_nothing)
588         {
589           emit_unop_insn (code, to, from,
590                           tab == sext_optab ? FLOAT_EXTEND : FLOAT_TRUNCATE);
591           return;
592         }
593
594       /* Otherwise use a libcall.  */
595       libcall = tab->handlers[to_mode][from_mode].libfunc;
596
597       if (!libcall)
598         /* This conversion is not implemented yet.  */
599         abort ();
600
601       start_sequence ();
602       value = emit_library_call_value (libcall, NULL_RTX, LCT_CONST, to_mode,
603                                        1, from, from_mode);
604       insns = get_insns ();
605       end_sequence ();
606       emit_libcall_block (insns, to, value,
607                           tab == trunc_optab ? gen_rtx_FLOAT_TRUNCATE (to_mode,
608                                                                        from)
609                           : gen_rtx_FLOAT_EXTEND (to_mode, from));
610       return;
611     }
612
613   /* Handle pointer conversion.  */                     /* SPEE 900220.  */
614   /* Targets are expected to provide conversion insns between PxImode and
615      xImode for all MODE_PARTIAL_INT modes they use, but no others.  */
616   if (GET_MODE_CLASS (to_mode) == MODE_PARTIAL_INT)
617     {
618       enum machine_mode full_mode
619         = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode), MODE_INT);
620
621       if (trunc_optab->handlers[to_mode][full_mode].insn_code
622           == CODE_FOR_nothing)
623         abort ();
624
625       if (full_mode != from_mode)
626         from = convert_to_mode (full_mode, from, unsignedp);
627       emit_unop_insn (trunc_optab->handlers[to_mode][full_mode].insn_code,
628                       to, from, UNKNOWN);
629       return;
630     }
631   if (GET_MODE_CLASS (from_mode) == MODE_PARTIAL_INT)
632     {
633       enum machine_mode full_mode
634         = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode), MODE_INT);
635
636       if (sext_optab->handlers[full_mode][from_mode].insn_code
637           == CODE_FOR_nothing)
638         abort ();
639
640       emit_unop_insn (sext_optab->handlers[full_mode][from_mode].insn_code,
641                       to, from, UNKNOWN);
642       if (to_mode == full_mode)
643         return;
644
645       /* else proceed to integer conversions below.  */
646       from_mode = full_mode;
647     }
648
649   /* Now both modes are integers.  */
650
651   /* Handle expanding beyond a word.  */
652   if (GET_MODE_BITSIZE (from_mode) < GET_MODE_BITSIZE (to_mode)
653       && GET_MODE_BITSIZE (to_mode) > BITS_PER_WORD)
654     {
655       rtx insns;
656       rtx lowpart;
657       rtx fill_value;
658       rtx lowfrom;
659       int i;
660       enum machine_mode lowpart_mode;
661       int nwords = CEIL (GET_MODE_SIZE (to_mode), UNITS_PER_WORD);
662
663       /* Try converting directly if the insn is supported.  */
664       if ((code = can_extend_p (to_mode, from_mode, unsignedp))
665           != CODE_FOR_nothing)
666         {
667           /* If FROM is a SUBREG, put it into a register.  Do this
668              so that we always generate the same set of insns for
669              better cse'ing; if an intermediate assignment occurred,
670              we won't be doing the operation directly on the SUBREG.  */
671           if (optimize > 0 && GET_CODE (from) == SUBREG)
672             from = force_reg (from_mode, from);
673           emit_unop_insn (code, to, from, equiv_code);
674           return;
675         }
676       /* Next, try converting via full word.  */
677       else if (GET_MODE_BITSIZE (from_mode) < BITS_PER_WORD
678                && ((code = can_extend_p (to_mode, word_mode, unsignedp))
679                    != CODE_FOR_nothing))
680         {
681           if (GET_CODE (to) == REG)
682             {
683               if (reg_overlap_mentioned_p (to, from))
684                 from = force_reg (from_mode, from);
685               emit_insn (gen_rtx_CLOBBER (VOIDmode, to));
686             }
687           convert_move (gen_lowpart (word_mode, to), from, unsignedp);
688           emit_unop_insn (code, to,
689                           gen_lowpart (word_mode, to), equiv_code);
690           return;
691         }
692
693       /* No special multiword conversion insn; do it by hand.  */
694       start_sequence ();
695
696       /* Since we will turn this into a no conflict block, we must ensure
697          that the source does not overlap the target.  */
698
699       if (reg_overlap_mentioned_p (to, from))
700         from = force_reg (from_mode, from);
701
702       /* Get a copy of FROM widened to a word, if necessary.  */
703       if (GET_MODE_BITSIZE (from_mode) < BITS_PER_WORD)
704         lowpart_mode = word_mode;
705       else
706         lowpart_mode = from_mode;
707
708       lowfrom = convert_to_mode (lowpart_mode, from, unsignedp);
709
710       lowpart = gen_lowpart (lowpart_mode, to);
711       emit_move_insn (lowpart, lowfrom);
712
713       /* Compute the value to put in each remaining word.  */
714       if (unsignedp)
715         fill_value = const0_rtx;
716       else
717         {
718 #ifdef HAVE_slt
719           if (HAVE_slt
720               && insn_data[(int) CODE_FOR_slt].operand[0].mode == word_mode
721               && STORE_FLAG_VALUE == -1)
722             {
723               emit_cmp_insn (lowfrom, const0_rtx, NE, NULL_RTX,
724                              lowpart_mode, 0);
725               fill_value = gen_reg_rtx (word_mode);
726               emit_insn (gen_slt (fill_value));
727             }
728           else
729 #endif
730             {
731               fill_value
732                 = expand_shift (RSHIFT_EXPR, lowpart_mode, lowfrom,
733                                 size_int (GET_MODE_BITSIZE (lowpart_mode) - 1),
734                                 NULL_RTX, 0);
735               fill_value = convert_to_mode (word_mode, fill_value, 1);
736             }
737         }
738
739       /* Fill the remaining words.  */
740       for (i = GET_MODE_SIZE (lowpart_mode) / UNITS_PER_WORD; i < nwords; i++)
741         {
742           int index = (WORDS_BIG_ENDIAN ? nwords - i - 1 : i);
743           rtx subword = operand_subword (to, index, 1, to_mode);
744
745           if (subword == 0)
746             abort ();
747
748           if (fill_value != subword)
749             emit_move_insn (subword, fill_value);
750         }
751
752       insns = get_insns ();
753       end_sequence ();
754
755       emit_no_conflict_block (insns, to, from, NULL_RTX,
756                               gen_rtx_fmt_e (equiv_code, to_mode, copy_rtx (from)));
757       return;
758     }
759
760   /* Truncating multi-word to a word or less.  */
761   if (GET_MODE_BITSIZE (from_mode) > BITS_PER_WORD
762       && GET_MODE_BITSIZE (to_mode) <= BITS_PER_WORD)
763     {
764       if (!((GET_CODE (from) == MEM
765              && ! MEM_VOLATILE_P (from)
766              && direct_load[(int) to_mode]
767              && ! mode_dependent_address_p (XEXP (from, 0)))
768             || GET_CODE (from) == REG
769             || GET_CODE (from) == SUBREG))
770         from = force_reg (from_mode, from);
771       convert_move (to, gen_lowpart (word_mode, from), 0);
772       return;
773     }
774
775   /* Now follow all the conversions between integers
776      no more than a word long.  */
777
778   /* For truncation, usually we can just refer to FROM in a narrower mode.  */
779   if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode)
780       && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (to_mode),
781                                 GET_MODE_BITSIZE (from_mode)))
782     {
783       if (!((GET_CODE (from) == MEM
784              && ! MEM_VOLATILE_P (from)
785              && direct_load[(int) to_mode]
786              && ! mode_dependent_address_p (XEXP (from, 0)))
787             || GET_CODE (from) == REG
788             || GET_CODE (from) == SUBREG))
789         from = force_reg (from_mode, from);
790       if (GET_CODE (from) == REG && REGNO (from) < FIRST_PSEUDO_REGISTER
791           && ! HARD_REGNO_MODE_OK (REGNO (from), to_mode))
792         from = copy_to_reg (from);
793       emit_move_insn (to, gen_lowpart (to_mode, from));
794       return;
795     }
796
797   /* Handle extension.  */
798   if (GET_MODE_BITSIZE (to_mode) > GET_MODE_BITSIZE (from_mode))
799     {
800       /* Convert directly if that works.  */
801       if ((code = can_extend_p (to_mode, from_mode, unsignedp))
802           != CODE_FOR_nothing)
803         {
804           if (flag_force_mem)
805             from = force_not_mem (from);
806
807           emit_unop_insn (code, to, from, equiv_code);
808           return;
809         }
810       else
811         {
812           enum machine_mode intermediate;
813           rtx tmp;
814           tree shift_amount;
815
816           /* Search for a mode to convert via.  */
817           for (intermediate = from_mode; intermediate != VOIDmode;
818                intermediate = GET_MODE_WIDER_MODE (intermediate))
819             if (((can_extend_p (to_mode, intermediate, unsignedp)
820                   != CODE_FOR_nothing)
821                  || (GET_MODE_SIZE (to_mode) < GET_MODE_SIZE (intermediate)
822                      && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (to_mode),
823                                                GET_MODE_BITSIZE (intermediate))))
824                 && (can_extend_p (intermediate, from_mode, unsignedp)
825                     != CODE_FOR_nothing))
826               {
827                 convert_move (to, convert_to_mode (intermediate, from,
828                                                    unsignedp), unsignedp);
829                 return;
830               }
831
832           /* No suitable intermediate mode.
833              Generate what we need with shifts.  */
834           shift_amount = build_int_2 (GET_MODE_BITSIZE (to_mode)
835                                       - GET_MODE_BITSIZE (from_mode), 0);
836           from = gen_lowpart (to_mode, force_reg (from_mode, from));
837           tmp = expand_shift (LSHIFT_EXPR, to_mode, from, shift_amount,
838                               to, unsignedp);
839           tmp = expand_shift (RSHIFT_EXPR, to_mode, tmp, shift_amount,
840                               to, unsignedp);
841           if (tmp != to)
842             emit_move_insn (to, tmp);
843           return;
844         }
845     }
846
847   /* Support special truncate insns for certain modes.  */
848   if (trunc_optab->handlers[to_mode][from_mode].insn_code != CODE_FOR_nothing)
849     {
850       emit_unop_insn (trunc_optab->handlers[to_mode][from_mode].insn_code,
851                       to, from, UNKNOWN);
852       return;
853     }
854
855   /* Handle truncation of volatile memrefs, and so on;
856      the things that couldn't be truncated directly,
857      and for which there was no special instruction.
858
859      ??? Code above formerly short-circuited this, for most integer
860      mode pairs, with a force_reg in from_mode followed by a recursive
861      call to this routine.  Appears always to have been wrong.  */
862   if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode))
863     {
864       rtx temp = force_reg (to_mode, gen_lowpart (to_mode, from));
865       emit_move_insn (to, temp);
866       return;
867     }
868
869   /* Mode combination is not recognized.  */
870   abort ();
871 }
872
873 /* Return an rtx for a value that would result
874    from converting X to mode MODE.
875    Both X and MODE may be floating, or both integer.
876    UNSIGNEDP is nonzero if X is an unsigned value.
877    This can be done by referring to a part of X in place
878    or by copying to a new temporary with conversion.
879
880    This function *must not* call protect_from_queue
881    except when putting X into an insn (in which case convert_move does it).  */
882
883 rtx
884 convert_to_mode (enum machine_mode mode, rtx x, int unsignedp)
885 {
886   return convert_modes (mode, VOIDmode, x, unsignedp);
887 }
888
889 /* Return an rtx for a value that would result
890    from converting X from mode OLDMODE to mode MODE.
891    Both modes may be floating, or both integer.
892    UNSIGNEDP is nonzero if X is an unsigned value.
893
894    This can be done by referring to a part of X in place
895    or by copying to a new temporary with conversion.
896
897    You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode.
898
899    This function *must not* call protect_from_queue
900    except when putting X into an insn (in which case convert_move does it).  */
901
902 rtx
903 convert_modes (enum machine_mode mode, enum machine_mode oldmode, rtx x, int unsignedp)
904 {
905   rtx temp;
906
907   /* If FROM is a SUBREG that indicates that we have already done at least
908      the required extension, strip it.  */
909
910   if (GET_CODE (x) == SUBREG && SUBREG_PROMOTED_VAR_P (x)
911       && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) >= GET_MODE_SIZE (mode)
912       && SUBREG_PROMOTED_UNSIGNED_P (x) == unsignedp)
913     x = gen_lowpart (mode, x);
914
915   if (GET_MODE (x) != VOIDmode)
916     oldmode = GET_MODE (x);
917
918   if (mode == oldmode)
919     return x;
920
921   /* There is one case that we must handle specially: If we are converting
922      a CONST_INT into a mode whose size is twice HOST_BITS_PER_WIDE_INT and
923      we are to interpret the constant as unsigned, gen_lowpart will do
924      the wrong if the constant appears negative.  What we want to do is
925      make the high-order word of the constant zero, not all ones.  */
926
927   if (unsignedp && GET_MODE_CLASS (mode) == MODE_INT
928       && GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT
929       && GET_CODE (x) == CONST_INT && INTVAL (x) < 0)
930     {
931       HOST_WIDE_INT val = INTVAL (x);
932
933       if (oldmode != VOIDmode
934           && HOST_BITS_PER_WIDE_INT > GET_MODE_BITSIZE (oldmode))
935         {
936           int width = GET_MODE_BITSIZE (oldmode);
937
938           /* We need to zero extend VAL.  */
939           val &= ((HOST_WIDE_INT) 1 << width) - 1;
940         }
941
942       return immed_double_const (val, (HOST_WIDE_INT) 0, mode);
943     }
944
945   /* We can do this with a gen_lowpart if both desired and current modes
946      are integer, and this is either a constant integer, a register, or a
947      non-volatile MEM.  Except for the constant case where MODE is no
948      wider than HOST_BITS_PER_WIDE_INT, we must be narrowing the operand.  */
949
950   if ((GET_CODE (x) == CONST_INT
951        && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
952       || (GET_MODE_CLASS (mode) == MODE_INT
953           && GET_MODE_CLASS (oldmode) == MODE_INT
954           && (GET_CODE (x) == CONST_DOUBLE
955               || (GET_MODE_SIZE (mode) <= GET_MODE_SIZE (oldmode)
956                   && ((GET_CODE (x) == MEM && ! MEM_VOLATILE_P (x)
957                        && direct_load[(int) mode])
958                       || (GET_CODE (x) == REG
959                           && (! HARD_REGISTER_P (x)
960                               || HARD_REGNO_MODE_OK (REGNO (x), mode))
961                           && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (mode),
962                                                     GET_MODE_BITSIZE (GET_MODE (x)))))))))
963     {
964       /* ?? If we don't know OLDMODE, we have to assume here that
965          X does not need sign- or zero-extension.   This may not be
966          the case, but it's the best we can do.  */
967       if (GET_CODE (x) == CONST_INT && oldmode != VOIDmode
968           && GET_MODE_SIZE (mode) > GET_MODE_SIZE (oldmode))
969         {
970           HOST_WIDE_INT val = INTVAL (x);
971           int width = GET_MODE_BITSIZE (oldmode);
972
973           /* We must sign or zero-extend in this case.  Start by
974              zero-extending, then sign extend if we need to.  */
975           val &= ((HOST_WIDE_INT) 1 << width) - 1;
976           if (! unsignedp
977               && (val & ((HOST_WIDE_INT) 1 << (width - 1))))
978             val |= (HOST_WIDE_INT) (-1) << width;
979
980           return gen_int_mode (val, mode);
981         }
982
983       return gen_lowpart (mode, x);
984     }
985
986   /* Converting from integer constant into mode is always equivalent to an
987      subreg operation.  */
988   if (VECTOR_MODE_P (mode) && GET_MODE (x) == VOIDmode)
989     {
990       if (GET_MODE_BITSIZE (mode) != GET_MODE_BITSIZE (oldmode))
991         abort ();
992       return simplify_gen_subreg (mode, x, oldmode, 0);
993     }
994
995   temp = gen_reg_rtx (mode);
996   convert_move (temp, x, unsignedp);
997   return temp;
998 }
999 \f
1000 /* STORE_MAX_PIECES is the number of bytes at a time that we can
1001    store efficiently.  Due to internal GCC limitations, this is
1002    MOVE_MAX_PIECES limited by the number of bytes GCC can represent
1003    for an immediate constant.  */
1004
1005 #define STORE_MAX_PIECES  MIN (MOVE_MAX_PIECES, 2 * sizeof (HOST_WIDE_INT))
1006
1007 /* Determine whether the LEN bytes can be moved by using several move
1008    instructions.  Return nonzero if a call to move_by_pieces should
1009    succeed.  */
1010
1011 int
1012 can_move_by_pieces (unsigned HOST_WIDE_INT len,
1013                     unsigned int align ATTRIBUTE_UNUSED)
1014 {
1015   return MOVE_BY_PIECES_P (len, align);
1016 }
1017
1018 /* Generate several move instructions to copy LEN bytes from block FROM to
1019    block TO.  (These are MEM rtx's with BLKmode).  The caller must pass FROM
1020    and TO through protect_from_queue before calling.
1021
1022    If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
1023    used to push FROM to the stack.
1024
1025    ALIGN is maximum stack alignment we can assume.
1026
1027    If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
1028    mempcpy, and if ENDP is 2 return memory the end minus one byte ala
1029    stpcpy.  */
1030
1031 rtx
1032 move_by_pieces (rtx to, rtx from, unsigned HOST_WIDE_INT len,
1033                 unsigned int align, int endp)
1034 {
1035   struct move_by_pieces data;
1036   rtx to_addr, from_addr = XEXP (from, 0);
1037   unsigned int max_size = MOVE_MAX_PIECES + 1;
1038   enum machine_mode mode = VOIDmode, tmode;
1039   enum insn_code icode;
1040
1041   align = MIN (to ? MEM_ALIGN (to) : align, MEM_ALIGN (from));
1042
1043   data.offset = 0;
1044   data.from_addr = from_addr;
1045   if (to)
1046     {
1047       to_addr = XEXP (to, 0);
1048       data.to = to;
1049       data.autinc_to
1050         = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
1051            || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
1052       data.reverse
1053         = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
1054     }
1055   else
1056     {
1057       to_addr = NULL_RTX;
1058       data.to = NULL_RTX;
1059       data.autinc_to = 1;
1060 #ifdef STACK_GROWS_DOWNWARD
1061       data.reverse = 1;
1062 #else
1063       data.reverse = 0;
1064 #endif
1065     }
1066   data.to_addr = to_addr;
1067   data.from = from;
1068   data.autinc_from
1069     = (GET_CODE (from_addr) == PRE_INC || GET_CODE (from_addr) == PRE_DEC
1070        || GET_CODE (from_addr) == POST_INC
1071        || GET_CODE (from_addr) == POST_DEC);
1072
1073   data.explicit_inc_from = 0;
1074   data.explicit_inc_to = 0;
1075   if (data.reverse) data.offset = len;
1076   data.len = len;
1077
1078   /* If copying requires more than two move insns,
1079      copy addresses to registers (to make displacements shorter)
1080      and use post-increment if available.  */
1081   if (!(data.autinc_from && data.autinc_to)
1082       && move_by_pieces_ninsns (len, align) > 2)
1083     {
1084       /* Find the mode of the largest move...  */
1085       for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
1086            tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
1087         if (GET_MODE_SIZE (tmode) < max_size)
1088           mode = tmode;
1089
1090       if (USE_LOAD_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_from)
1091         {
1092           data.from_addr = copy_addr_to_reg (plus_constant (from_addr, len));
1093           data.autinc_from = 1;
1094           data.explicit_inc_from = -1;
1095         }
1096       if (USE_LOAD_POST_INCREMENT (mode) && ! data.autinc_from)
1097         {
1098           data.from_addr = copy_addr_to_reg (from_addr);
1099           data.autinc_from = 1;
1100           data.explicit_inc_from = 1;
1101         }
1102       if (!data.autinc_from && CONSTANT_P (from_addr))
1103         data.from_addr = copy_addr_to_reg (from_addr);
1104       if (USE_STORE_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_to)
1105         {
1106           data.to_addr = copy_addr_to_reg (plus_constant (to_addr, len));
1107           data.autinc_to = 1;
1108           data.explicit_inc_to = -1;
1109         }
1110       if (USE_STORE_POST_INCREMENT (mode) && ! data.reverse && ! data.autinc_to)
1111         {
1112           data.to_addr = copy_addr_to_reg (to_addr);
1113           data.autinc_to = 1;
1114           data.explicit_inc_to = 1;
1115         }
1116       if (!data.autinc_to && CONSTANT_P (to_addr))
1117         data.to_addr = copy_addr_to_reg (to_addr);
1118     }
1119
1120   if (! SLOW_UNALIGNED_ACCESS (word_mode, align)
1121       || align > MOVE_MAX * BITS_PER_UNIT || align >= BIGGEST_ALIGNMENT)
1122     align = MOVE_MAX * BITS_PER_UNIT;
1123
1124   /* First move what we can in the largest integer mode, then go to
1125      successively smaller modes.  */
1126
1127   while (max_size > 1)
1128     {
1129       for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
1130            tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
1131         if (GET_MODE_SIZE (tmode) < max_size)
1132           mode = tmode;
1133
1134       if (mode == VOIDmode)
1135         break;
1136
1137       icode = mov_optab->handlers[(int) mode].insn_code;
1138       if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
1139         move_by_pieces_1 (GEN_FCN (icode), mode, &data);
1140
1141       max_size = GET_MODE_SIZE (mode);
1142     }
1143
1144   /* The code above should have handled everything.  */
1145   if (data.len > 0)
1146     abort ();
1147
1148   if (endp)
1149     {
1150       rtx to1;
1151
1152       if (data.reverse)
1153         abort ();
1154       if (data.autinc_to)
1155         {
1156           if (endp == 2)
1157             {
1158               if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
1159                 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
1160               else
1161                 data.to_addr = copy_addr_to_reg (plus_constant (data.to_addr,
1162                                                                 -1));
1163             }
1164           to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
1165                                            data.offset);
1166         }
1167       else
1168         {
1169           if (endp == 2)
1170             --data.offset;
1171           to1 = adjust_address (data.to, QImode, data.offset);
1172         }
1173       return to1;
1174     }
1175   else
1176     return data.to;
1177 }
1178
1179 /* Return number of insns required to move L bytes by pieces.
1180    ALIGN (in bits) is maximum alignment we can assume.  */
1181
1182 static unsigned HOST_WIDE_INT
1183 move_by_pieces_ninsns (unsigned HOST_WIDE_INT l, unsigned int align)
1184 {
1185   unsigned HOST_WIDE_INT n_insns = 0;
1186   unsigned HOST_WIDE_INT max_size = MOVE_MAX + 1;
1187
1188   if (! SLOW_UNALIGNED_ACCESS (word_mode, align)
1189       || align > MOVE_MAX * BITS_PER_UNIT || align >= BIGGEST_ALIGNMENT)
1190     align = MOVE_MAX * BITS_PER_UNIT;
1191
1192   while (max_size > 1)
1193     {
1194       enum machine_mode mode = VOIDmode, tmode;
1195       enum insn_code icode;
1196
1197       for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
1198            tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
1199         if (GET_MODE_SIZE (tmode) < max_size)
1200           mode = tmode;
1201
1202       if (mode == VOIDmode)
1203         break;
1204
1205       icode = mov_optab->handlers[(int) mode].insn_code;
1206       if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
1207         n_insns += l / GET_MODE_SIZE (mode), l %= GET_MODE_SIZE (mode);
1208
1209       max_size = GET_MODE_SIZE (mode);
1210     }
1211
1212   if (l)
1213     abort ();
1214   return n_insns;
1215 }
1216
1217 /* Subroutine of move_by_pieces.  Move as many bytes as appropriate
1218    with move instructions for mode MODE.  GENFUN is the gen_... function
1219    to make a move insn for that mode.  DATA has all the other info.  */
1220
1221 static void
1222 move_by_pieces_1 (rtx (*genfun) (rtx, ...), enum machine_mode mode,
1223                   struct move_by_pieces *data)
1224 {
1225   unsigned int size = GET_MODE_SIZE (mode);
1226   rtx to1 = NULL_RTX, from1;
1227
1228   while (data->len >= size)
1229     {
1230       if (data->reverse)
1231         data->offset -= size;
1232
1233       if (data->to)
1234         {
1235           if (data->autinc_to)
1236             to1 = adjust_automodify_address (data->to, mode, data->to_addr,
1237                                              data->offset);
1238           else
1239             to1 = adjust_address (data->to, mode, data->offset);
1240         }
1241
1242       if (data->autinc_from)
1243         from1 = adjust_automodify_address (data->from, mode, data->from_addr,
1244                                            data->offset);
1245       else
1246         from1 = adjust_address (data->from, mode, data->offset);
1247
1248       if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
1249         emit_insn (gen_add2_insn (data->to_addr,
1250                                   GEN_INT (-(HOST_WIDE_INT)size)));
1251       if (HAVE_PRE_DECREMENT && data->explicit_inc_from < 0)
1252         emit_insn (gen_add2_insn (data->from_addr,
1253                                   GEN_INT (-(HOST_WIDE_INT)size)));
1254
1255       if (data->to)
1256         emit_insn ((*genfun) (to1, from1));
1257       else
1258         {
1259 #ifdef PUSH_ROUNDING
1260           emit_single_push_insn (mode, from1, NULL);
1261 #else
1262           abort ();
1263 #endif
1264         }
1265
1266       if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
1267         emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
1268       if (HAVE_POST_INCREMENT && data->explicit_inc_from > 0)
1269         emit_insn (gen_add2_insn (data->from_addr, GEN_INT (size)));
1270
1271       if (! data->reverse)
1272         data->offset += size;
1273
1274       data->len -= size;
1275     }
1276 }
1277 \f
1278 /* Emit code to move a block Y to a block X.  This may be done with
1279    string-move instructions, with multiple scalar move instructions,
1280    or with a library call.
1281
1282    Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
1283    SIZE is an rtx that says how long they are.
1284    ALIGN is the maximum alignment we can assume they have.
1285    METHOD describes what kind of copy this is, and what mechanisms may be used.
1286
1287    Return the address of the new block, if memcpy is called and returns it,
1288    0 otherwise.  */
1289
1290 rtx
1291 emit_block_move (rtx x, rtx y, rtx size, enum block_op_methods method)
1292 {
1293   bool may_use_call;
1294   rtx retval = 0;
1295   unsigned int align;
1296
1297   switch (method)
1298     {
1299     case BLOCK_OP_NORMAL:
1300       may_use_call = true;
1301       break;
1302
1303     case BLOCK_OP_CALL_PARM:
1304       may_use_call = block_move_libcall_safe_for_call_parm ();
1305
1306       /* Make inhibit_defer_pop nonzero around the library call
1307          to force it to pop the arguments right away.  */
1308       NO_DEFER_POP;
1309       break;
1310
1311     case BLOCK_OP_NO_LIBCALL:
1312       may_use_call = false;
1313       break;
1314
1315     default:
1316       abort ();
1317     }
1318
1319   align = MIN (MEM_ALIGN (x), MEM_ALIGN (y));
1320
1321   if (GET_MODE (x) != BLKmode)
1322     abort ();
1323   if (GET_MODE (y) != BLKmode)
1324     abort ();
1325
1326   x = protect_from_queue (x, 1);
1327   y = protect_from_queue (y, 0);
1328   size = protect_from_queue (size, 0);
1329
1330   if (GET_CODE (x) != MEM)
1331     abort ();
1332   if (GET_CODE (y) != MEM)
1333     abort ();
1334   if (size == 0)
1335     abort ();
1336
1337   /* Set MEM_SIZE as appropriate for this block copy.  The main place this
1338      can be incorrect is coming from __builtin_memcpy.  */
1339   if (GET_CODE (size) == CONST_INT)
1340     {
1341       if (INTVAL (size) == 0)
1342         return 0;
1343
1344       x = shallow_copy_rtx (x);
1345       y = shallow_copy_rtx (y);
1346       set_mem_size (x, size);
1347       set_mem_size (y, size);
1348     }
1349
1350   if (GET_CODE (size) == CONST_INT && MOVE_BY_PIECES_P (INTVAL (size), align))
1351     move_by_pieces (x, y, INTVAL (size), align, 0);
1352   else if (emit_block_move_via_movstr (x, y, size, align))
1353     ;
1354   else if (may_use_call)
1355     retval = emit_block_move_via_libcall (x, y, size);
1356   else
1357     emit_block_move_via_loop (x, y, size, align);
1358
1359   if (method == BLOCK_OP_CALL_PARM)
1360     OK_DEFER_POP;
1361
1362   return retval;
1363 }
1364
1365 /* A subroutine of emit_block_move.  Returns true if calling the
1366    block move libcall will not clobber any parameters which may have
1367    already been placed on the stack.  */
1368
1369 static bool
1370 block_move_libcall_safe_for_call_parm (void)
1371 {
1372   /* If arguments are pushed on the stack, then they're safe.  */
1373   if (PUSH_ARGS)
1374     return true;
1375
1376   /* If registers go on the stack anyway, any argument is sure to clobber
1377      an outgoing argument.  */
1378 #if defined (REG_PARM_STACK_SPACE) && defined (OUTGOING_REG_PARM_STACK_SPACE)
1379   {
1380     tree fn = emit_block_move_libcall_fn (false);
1381     (void) fn;
1382     if (REG_PARM_STACK_SPACE (fn) != 0)
1383       return false;
1384   }
1385 #endif
1386
1387   /* If any argument goes in memory, then it might clobber an outgoing
1388      argument.  */
1389   {
1390     CUMULATIVE_ARGS args_so_far;
1391     tree fn, arg;
1392
1393     fn = emit_block_move_libcall_fn (false);
1394     INIT_CUMULATIVE_ARGS (args_so_far, TREE_TYPE (fn), NULL_RTX, 0, 3);
1395
1396     arg = TYPE_ARG_TYPES (TREE_TYPE (fn));
1397     for ( ; arg != void_list_node ; arg = TREE_CHAIN (arg))
1398       {
1399         enum machine_mode mode = TYPE_MODE (TREE_VALUE (arg));
1400         rtx tmp = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1);
1401         if (!tmp || !REG_P (tmp))
1402           return false;
1403 #ifdef FUNCTION_ARG_PARTIAL_NREGS
1404         if (FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode,
1405                                         NULL_TREE, 1))
1406           return false;
1407 #endif
1408         FUNCTION_ARG_ADVANCE (args_so_far, mode, NULL_TREE, 1);
1409       }
1410   }
1411   return true;
1412 }
1413
1414 /* A subroutine of emit_block_move.  Expand a movstr pattern;
1415    return true if successful.  */
1416
1417 static bool
1418 emit_block_move_via_movstr (rtx x, rtx y, rtx size, unsigned int align)
1419 {
1420   rtx opalign = GEN_INT (align / BITS_PER_UNIT);
1421   int save_volatile_ok = volatile_ok;
1422   enum machine_mode mode;
1423
1424   /* Since this is a move insn, we don't care about volatility.  */
1425   volatile_ok = 1;
1426
1427   /* Try the most limited insn first, because there's no point
1428      including more than one in the machine description unless
1429      the more limited one has some advantage.  */
1430
1431   for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1432        mode = GET_MODE_WIDER_MODE (mode))
1433     {
1434       enum insn_code code = movstr_optab[(int) mode];
1435       insn_operand_predicate_fn pred;
1436
1437       if (code != CODE_FOR_nothing
1438           /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
1439              here because if SIZE is less than the mode mask, as it is
1440              returned by the macro, it will definitely be less than the
1441              actual mode mask.  */
1442           && ((GET_CODE (size) == CONST_INT
1443                && ((unsigned HOST_WIDE_INT) INTVAL (size)
1444                    <= (GET_MODE_MASK (mode) >> 1)))
1445               || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD)
1446           && ((pred = insn_data[(int) code].operand[0].predicate) == 0
1447               || (*pred) (x, BLKmode))
1448           && ((pred = insn_data[(int) code].operand[1].predicate) == 0
1449               || (*pred) (y, BLKmode))
1450           && ((pred = insn_data[(int) code].operand[3].predicate) == 0
1451               || (*pred) (opalign, VOIDmode)))
1452         {
1453           rtx op2;
1454           rtx last = get_last_insn ();
1455           rtx pat;
1456
1457           op2 = convert_to_mode (mode, size, 1);
1458           pred = insn_data[(int) code].operand[2].predicate;
1459           if (pred != 0 && ! (*pred) (op2, mode))
1460             op2 = copy_to_mode_reg (mode, op2);
1461
1462           /* ??? When called via emit_block_move_for_call, it'd be
1463              nice if there were some way to inform the backend, so
1464              that it doesn't fail the expansion because it thinks
1465              emitting the libcall would be more efficient.  */
1466
1467           pat = GEN_FCN ((int) code) (x, y, op2, opalign);
1468           if (pat)
1469             {
1470               emit_insn (pat);
1471               volatile_ok = save_volatile_ok;
1472               return true;
1473             }
1474           else
1475             delete_insns_since (last);
1476         }
1477     }
1478
1479   volatile_ok = save_volatile_ok;
1480   return false;
1481 }
1482
1483 /* A subroutine of emit_block_move.  Expand a call to memcpy or bcopy.
1484    Return the return value from memcpy, 0 otherwise.  */
1485
1486 static rtx
1487 emit_block_move_via_libcall (rtx dst, rtx src, rtx size)
1488 {
1489   rtx dst_addr, src_addr;
1490   tree call_expr, arg_list, fn, src_tree, dst_tree, size_tree;
1491   enum machine_mode size_mode;
1492   rtx retval;
1493
1494   /* DST, SRC, or SIZE may have been passed through protect_from_queue.
1495
1496      It is unsafe to save the value generated by protect_from_queue and reuse
1497      it later.  Consider what happens if emit_queue is called before the
1498      return value from protect_from_queue is used.
1499
1500      Expansion of the CALL_EXPR below will call emit_queue before we are
1501      finished emitting RTL for argument setup.  So if we are not careful we
1502      could get the wrong value for an argument.
1503
1504      To avoid this problem we go ahead and emit code to copy the addresses of
1505      DST and SRC and SIZE into new pseudos.  We can then place those new
1506      pseudos into an RTL_EXPR and use them later, even after a call to
1507      emit_queue.
1508
1509      Note this is not strictly needed for library calls since they do not call
1510      emit_queue before loading their arguments.  However, we may need to have
1511      library calls call emit_queue in the future since failing to do so could
1512      cause problems for targets which define SMALL_REGISTER_CLASSES and pass
1513      arguments in registers.  */
1514
1515   dst_addr = copy_to_mode_reg (Pmode, XEXP (dst, 0));
1516   src_addr = copy_to_mode_reg (Pmode, XEXP (src, 0));
1517
1518   dst_addr = convert_memory_address (ptr_mode, dst_addr);
1519   src_addr = convert_memory_address (ptr_mode, src_addr);
1520
1521   dst_tree = make_tree (ptr_type_node, dst_addr);
1522   src_tree = make_tree (ptr_type_node, src_addr);
1523
1524   if (TARGET_MEM_FUNCTIONS)
1525     size_mode = TYPE_MODE (sizetype);
1526   else
1527     size_mode = TYPE_MODE (unsigned_type_node);
1528
1529   size = convert_to_mode (size_mode, size, 1);
1530   size = copy_to_mode_reg (size_mode, size);
1531
1532   /* It is incorrect to use the libcall calling conventions to call
1533      memcpy in this context.  This could be a user call to memcpy and
1534      the user may wish to examine the return value from memcpy.  For
1535      targets where libcalls and normal calls have different conventions
1536      for returning pointers, we could end up generating incorrect code.
1537
1538      For convenience, we generate the call to bcopy this way as well.  */
1539
1540   if (TARGET_MEM_FUNCTIONS)
1541     size_tree = make_tree (sizetype, size);
1542   else
1543     size_tree = make_tree (unsigned_type_node, size);
1544
1545   fn = emit_block_move_libcall_fn (true);
1546   arg_list = tree_cons (NULL_TREE, size_tree, NULL_TREE);
1547   if (TARGET_MEM_FUNCTIONS)
1548     {
1549       arg_list = tree_cons (NULL_TREE, src_tree, arg_list);
1550       arg_list = tree_cons (NULL_TREE, dst_tree, arg_list);
1551     }
1552   else
1553     {
1554       arg_list = tree_cons (NULL_TREE, dst_tree, arg_list);
1555       arg_list = tree_cons (NULL_TREE, src_tree, arg_list);
1556     }
1557
1558   /* Now we have to build up the CALL_EXPR itself.  */
1559   call_expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (fn)), fn);
1560   call_expr = build (CALL_EXPR, TREE_TYPE (TREE_TYPE (fn)),
1561                      call_expr, arg_list, NULL_TREE);
1562
1563   retval = expand_expr (call_expr, NULL_RTX, VOIDmode, 0);
1564
1565   /* If we are initializing a readonly value, show the above call clobbered
1566      it. Otherwise, a load from it may erroneously be hoisted from a loop, or
1567      the delay slot scheduler might overlook conflicts and take nasty
1568      decisions.  */
1569   if (RTX_UNCHANGING_P (dst))
1570     add_function_usage_to
1571       (last_call_insn (), gen_rtx_EXPR_LIST (VOIDmode,
1572                                              gen_rtx_CLOBBER (VOIDmode, dst),
1573                                              NULL_RTX));
1574
1575   return TARGET_MEM_FUNCTIONS ? retval : NULL_RTX;
1576 }
1577
1578 /* A subroutine of emit_block_move_via_libcall.  Create the tree node
1579    for the function we use for block copies.  The first time FOR_CALL
1580    is true, we call assemble_external.  */
1581
1582 static GTY(()) tree block_move_fn;
1583
1584 void
1585 init_block_move_fn (const char *asmspec)
1586 {
1587   if (!block_move_fn)
1588     {
1589       tree args, fn;
1590
1591       if (TARGET_MEM_FUNCTIONS)
1592         {
1593           fn = get_identifier ("memcpy");
1594           args = build_function_type_list (ptr_type_node, ptr_type_node,
1595                                            const_ptr_type_node, sizetype,
1596                                            NULL_TREE);
1597         }
1598       else
1599         {
1600           fn = get_identifier ("bcopy");
1601           args = build_function_type_list (void_type_node, const_ptr_type_node,
1602                                            ptr_type_node, unsigned_type_node,
1603                                            NULL_TREE);
1604         }
1605
1606       fn = build_decl (FUNCTION_DECL, fn, args);
1607       DECL_EXTERNAL (fn) = 1;
1608       TREE_PUBLIC (fn) = 1;
1609       DECL_ARTIFICIAL (fn) = 1;
1610       TREE_NOTHROW (fn) = 1;
1611
1612       block_move_fn = fn;
1613     }
1614
1615   if (asmspec)
1616     {
1617       SET_DECL_RTL (block_move_fn, NULL_RTX);
1618       SET_DECL_ASSEMBLER_NAME (block_move_fn, get_identifier (asmspec));
1619     }
1620 }
1621
1622 static tree
1623 emit_block_move_libcall_fn (int for_call)
1624 {
1625   static bool emitted_extern;
1626
1627   if (!block_move_fn)
1628     init_block_move_fn (NULL);
1629
1630   if (for_call && !emitted_extern)
1631     {
1632       emitted_extern = true;
1633       make_decl_rtl (block_move_fn, NULL);
1634       assemble_external (block_move_fn);
1635     }
1636
1637   return block_move_fn;
1638 }
1639
1640 /* A subroutine of emit_block_move.  Copy the data via an explicit
1641    loop.  This is used only when libcalls are forbidden.  */
1642 /* ??? It'd be nice to copy in hunks larger than QImode.  */
1643
1644 static void
1645 emit_block_move_via_loop (rtx x, rtx y, rtx size,
1646                           unsigned int align ATTRIBUTE_UNUSED)
1647 {
1648   rtx cmp_label, top_label, iter, x_addr, y_addr, tmp;
1649   enum machine_mode iter_mode;
1650
1651   iter_mode = GET_MODE (size);
1652   if (iter_mode == VOIDmode)
1653     iter_mode = word_mode;
1654
1655   top_label = gen_label_rtx ();
1656   cmp_label = gen_label_rtx ();
1657   iter = gen_reg_rtx (iter_mode);
1658
1659   emit_move_insn (iter, const0_rtx);
1660
1661   x_addr = force_operand (XEXP (x, 0), NULL_RTX);
1662   y_addr = force_operand (XEXP (y, 0), NULL_RTX);
1663   do_pending_stack_adjust ();
1664
1665   emit_note (NOTE_INSN_LOOP_BEG);
1666
1667   emit_jump (cmp_label);
1668   emit_label (top_label);
1669
1670   tmp = convert_modes (Pmode, iter_mode, iter, true);
1671   x_addr = gen_rtx_PLUS (Pmode, x_addr, tmp);
1672   y_addr = gen_rtx_PLUS (Pmode, y_addr, tmp);
1673   x = change_address (x, QImode, x_addr);
1674   y = change_address (y, QImode, y_addr);
1675
1676   emit_move_insn (x, y);
1677
1678   tmp = expand_simple_binop (iter_mode, PLUS, iter, const1_rtx, iter,
1679                              true, OPTAB_LIB_WIDEN);
1680   if (tmp != iter)
1681     emit_move_insn (iter, tmp);
1682
1683   emit_note (NOTE_INSN_LOOP_CONT);
1684   emit_label (cmp_label);
1685
1686   emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
1687                            true, top_label);
1688
1689   emit_note (NOTE_INSN_LOOP_END);
1690 }
1691 \f
1692 /* Copy all or part of a value X into registers starting at REGNO.
1693    The number of registers to be filled is NREGS.  */
1694
1695 void
1696 move_block_to_reg (int regno, rtx x, int nregs, enum machine_mode mode)
1697 {
1698   int i;
1699 #ifdef HAVE_load_multiple
1700   rtx pat;
1701   rtx last;
1702 #endif
1703
1704   if (nregs == 0)
1705     return;
1706
1707   if (CONSTANT_P (x) && ! LEGITIMATE_CONSTANT_P (x))
1708     x = validize_mem (force_const_mem (mode, x));
1709
1710   /* See if the machine can do this with a load multiple insn.  */
1711 #ifdef HAVE_load_multiple
1712   if (HAVE_load_multiple)
1713     {
1714       last = get_last_insn ();
1715       pat = gen_load_multiple (gen_rtx_REG (word_mode, regno), x,
1716                                GEN_INT (nregs));
1717       if (pat)
1718         {
1719           emit_insn (pat);
1720           return;
1721         }
1722       else
1723         delete_insns_since (last);
1724     }
1725 #endif
1726
1727   for (i = 0; i < nregs; i++)
1728     emit_move_insn (gen_rtx_REG (word_mode, regno + i),
1729                     operand_subword_force (x, i, mode));
1730 }
1731
1732 /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
1733    The number of registers to be filled is NREGS.  */
1734
1735 void
1736 move_block_from_reg (int regno, rtx x, int nregs)
1737 {
1738   int i;
1739
1740   if (nregs == 0)
1741     return;
1742
1743   /* See if the machine can do this with a store multiple insn.  */
1744 #ifdef HAVE_store_multiple
1745   if (HAVE_store_multiple)
1746     {
1747       rtx last = get_last_insn ();
1748       rtx pat = gen_store_multiple (x, gen_rtx_REG (word_mode, regno),
1749                                     GEN_INT (nregs));
1750       if (pat)
1751         {
1752           emit_insn (pat);
1753           return;
1754         }
1755       else
1756         delete_insns_since (last);
1757     }
1758 #endif
1759
1760   for (i = 0; i < nregs; i++)
1761     {
1762       rtx tem = operand_subword (x, i, 1, BLKmode);
1763
1764       if (tem == 0)
1765         abort ();
1766
1767       emit_move_insn (tem, gen_rtx_REG (word_mode, regno + i));
1768     }
1769 }
1770
1771 /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
1772    ORIG, where ORIG is a non-consecutive group of registers represented by
1773    a PARALLEL.  The clone is identical to the original except in that the
1774    original set of registers is replaced by a new set of pseudo registers.
1775    The new set has the same modes as the original set.  */
1776
1777 rtx
1778 gen_group_rtx (rtx orig)
1779 {
1780   int i, length;
1781   rtx *tmps;
1782
1783   if (GET_CODE (orig) != PARALLEL)
1784     abort ();
1785
1786   length = XVECLEN (orig, 0);
1787   tmps = alloca (sizeof (rtx) * length);
1788
1789   /* Skip a NULL entry in first slot.  */
1790   i = XEXP (XVECEXP (orig, 0, 0), 0) ? 0 : 1;
1791
1792   if (i)
1793     tmps[0] = 0;
1794
1795   for (; i < length; i++)
1796     {
1797       enum machine_mode mode = GET_MODE (XEXP (XVECEXP (orig, 0, i), 0));
1798       rtx offset = XEXP (XVECEXP (orig, 0, i), 1);
1799
1800       tmps[i] = gen_rtx_EXPR_LIST (VOIDmode, gen_reg_rtx (mode), offset);
1801     }
1802
1803   return gen_rtx_PARALLEL (GET_MODE (orig), gen_rtvec_v (length, tmps));
1804 }
1805
1806 /* Emit code to move a block ORIG_SRC of type TYPE to a block DST,
1807    where DST is non-consecutive registers represented by a PARALLEL.
1808    SSIZE represents the total size of block ORIG_SRC in bytes, or -1
1809    if not known.  */
1810
1811 void
1812 emit_group_load (rtx dst, rtx orig_src, tree type ATTRIBUTE_UNUSED, int ssize)
1813 {
1814   rtx *tmps, src;
1815   int start, i;
1816
1817   if (GET_CODE (dst) != PARALLEL)
1818     abort ();
1819
1820   /* Check for a NULL entry, used to indicate that the parameter goes
1821      both on the stack and in registers.  */
1822   if (XEXP (XVECEXP (dst, 0, 0), 0))
1823     start = 0;
1824   else
1825     start = 1;
1826
1827   tmps = alloca (sizeof (rtx) * XVECLEN (dst, 0));
1828
1829   /* Process the pieces.  */
1830   for (i = start; i < XVECLEN (dst, 0); i++)
1831     {
1832       enum machine_mode mode = GET_MODE (XEXP (XVECEXP (dst, 0, i), 0));
1833       HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (dst, 0, i), 1));
1834       unsigned int bytelen = GET_MODE_SIZE (mode);
1835       int shift = 0;
1836
1837       /* Handle trailing fragments that run over the size of the struct.  */
1838       if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
1839         {
1840           /* Arrange to shift the fragment to where it belongs.
1841              extract_bit_field loads to the lsb of the reg.  */
1842           if (
1843 #ifdef BLOCK_REG_PADDING
1844               BLOCK_REG_PADDING (GET_MODE (orig_src), type, i == start)
1845               == (BYTES_BIG_ENDIAN ? upward : downward)
1846 #else
1847               BYTES_BIG_ENDIAN
1848 #endif
1849               )
1850             shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
1851           bytelen = ssize - bytepos;
1852           if (bytelen <= 0)
1853             abort ();
1854         }
1855
1856       /* If we won't be loading directly from memory, protect the real source
1857          from strange tricks we might play; but make sure that the source can
1858          be loaded directly into the destination.  */
1859       src = orig_src;
1860       if (GET_CODE (orig_src) != MEM
1861           && (!CONSTANT_P (orig_src)
1862               || (GET_MODE (orig_src) != mode
1863                   && GET_MODE (orig_src) != VOIDmode)))
1864         {
1865           if (GET_MODE (orig_src) == VOIDmode)
1866             src = gen_reg_rtx (mode);
1867           else
1868             src = gen_reg_rtx (GET_MODE (orig_src));
1869
1870           emit_move_insn (src, orig_src);
1871         }
1872
1873       /* Optimize the access just a bit.  */
1874       if (GET_CODE (src) == MEM
1875           && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (src))
1876               || MEM_ALIGN (src) >= GET_MODE_ALIGNMENT (mode))
1877           && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
1878           && bytelen == GET_MODE_SIZE (mode))
1879         {
1880           tmps[i] = gen_reg_rtx (mode);
1881           emit_move_insn (tmps[i], adjust_address (src, mode, bytepos));
1882         }
1883       else if (GET_CODE (src) == CONCAT)
1884         {
1885           unsigned int slen = GET_MODE_SIZE (GET_MODE (src));
1886           unsigned int slen0 = GET_MODE_SIZE (GET_MODE (XEXP (src, 0)));
1887
1888           if ((bytepos == 0 && bytelen == slen0)
1889               || (bytepos != 0 && bytepos + bytelen <= slen))
1890             {
1891               /* The following assumes that the concatenated objects all
1892                  have the same size.  In this case, a simple calculation
1893                  can be used to determine the object and the bit field
1894                  to be extracted.  */
1895               tmps[i] = XEXP (src, bytepos / slen0);
1896               if (! CONSTANT_P (tmps[i])
1897                   && (GET_CODE (tmps[i]) != REG || GET_MODE (tmps[i]) != mode))
1898                 tmps[i] = extract_bit_field (tmps[i], bytelen * BITS_PER_UNIT,
1899                                              (bytepos % slen0) * BITS_PER_UNIT,
1900                                              1, NULL_RTX, mode, mode, ssize);
1901             }
1902           else if (bytepos == 0)
1903             {
1904               rtx mem = assign_stack_temp (GET_MODE (src), slen, 0);
1905               emit_move_insn (mem, src);
1906               tmps[i] = adjust_address (mem, mode, 0);
1907             }
1908           else
1909             abort ();
1910         }
1911       /* FIXME: A SIMD parallel will eventually lead to a subreg of a
1912          SIMD register, which is currently broken.  While we get GCC
1913          to emit proper RTL for these cases, let's dump to memory.  */
1914       else if (VECTOR_MODE_P (GET_MODE (dst))
1915                && GET_CODE (src) == REG)
1916         {
1917           int slen = GET_MODE_SIZE (GET_MODE (src));
1918           rtx mem;
1919
1920           mem = assign_stack_temp (GET_MODE (src), slen, 0);
1921           emit_move_insn (mem, src);
1922           tmps[i] = adjust_address (mem, mode, (int) bytepos);
1923         }
1924       else if (CONSTANT_P (src) && GET_MODE (dst) != BLKmode
1925                && XVECLEN (dst, 0) > 1)
1926         tmps[i] = simplify_gen_subreg (mode, src, GET_MODE(dst), bytepos);
1927       else if (CONSTANT_P (src)
1928                || (GET_CODE (src) == REG && GET_MODE (src) == mode))
1929         tmps[i] = src;
1930       else
1931         tmps[i] = extract_bit_field (src, bytelen * BITS_PER_UNIT,
1932                                      bytepos * BITS_PER_UNIT, 1, NULL_RTX,
1933                                      mode, mode, ssize);
1934
1935       if (shift)
1936         expand_binop (mode, ashl_optab, tmps[i], GEN_INT (shift),
1937                       tmps[i], 0, OPTAB_WIDEN);
1938     }
1939
1940   emit_queue ();
1941
1942   /* Copy the extracted pieces into the proper (probable) hard regs.  */
1943   for (i = start; i < XVECLEN (dst, 0); i++)
1944     emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0), tmps[i]);
1945 }
1946
1947 /* Emit code to move a block SRC to block DST, where SRC and DST are
1948    non-consecutive groups of registers, each represented by a PARALLEL.  */
1949
1950 void
1951 emit_group_move (rtx dst, rtx src)
1952 {
1953   int i;
1954
1955   if (GET_CODE (src) != PARALLEL
1956       || GET_CODE (dst) != PARALLEL
1957       || XVECLEN (src, 0) != XVECLEN (dst, 0))
1958     abort ();
1959
1960   /* Skip first entry if NULL.  */
1961   for (i = XEXP (XVECEXP (src, 0, 0), 0) ? 0 : 1; i < XVECLEN (src, 0); i++)
1962     emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0),
1963                     XEXP (XVECEXP (src, 0, i), 0));
1964 }
1965
1966 /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
1967    where SRC is non-consecutive registers represented by a PARALLEL.
1968    SSIZE represents the total size of block ORIG_DST, or -1 if not
1969    known.  */
1970
1971 void
1972 emit_group_store (rtx orig_dst, rtx src, tree type ATTRIBUTE_UNUSED, int ssize)
1973 {
1974   rtx *tmps, dst;
1975   int start, i;
1976
1977   if (GET_CODE (src) != PARALLEL)
1978     abort ();
1979
1980   /* Check for a NULL entry, used to indicate that the parameter goes
1981      both on the stack and in registers.  */
1982   if (XEXP (XVECEXP (src, 0, 0), 0))
1983     start = 0;
1984   else
1985     start = 1;
1986
1987   tmps = alloca (sizeof (rtx) * XVECLEN (src, 0));
1988
1989   /* Copy the (probable) hard regs into pseudos.  */
1990   for (i = start; i < XVECLEN (src, 0); i++)
1991     {
1992       rtx reg = XEXP (XVECEXP (src, 0, i), 0);
1993       tmps[i] = gen_reg_rtx (GET_MODE (reg));
1994       emit_move_insn (tmps[i], reg);
1995     }
1996   emit_queue ();
1997
1998   /* If we won't be storing directly into memory, protect the real destination
1999      from strange tricks we might play.  */
2000   dst = orig_dst;
2001   if (GET_CODE (dst) == PARALLEL)
2002     {
2003       rtx temp;
2004
2005       /* We can get a PARALLEL dst if there is a conditional expression in
2006          a return statement.  In that case, the dst and src are the same,
2007          so no action is necessary.  */
2008       if (rtx_equal_p (dst, src))
2009         return;
2010
2011       /* It is unclear if we can ever reach here, but we may as well handle
2012          it.  Allocate a temporary, and split this into a store/load to/from
2013          the temporary.  */
2014
2015       temp = assign_stack_temp (GET_MODE (dst), ssize, 0);
2016       emit_group_store (temp, src, type, ssize);
2017       emit_group_load (dst, temp, type, ssize);
2018       return;
2019     }
2020   else if (GET_CODE (dst) != MEM && GET_CODE (dst) != CONCAT)
2021     {
2022       dst = gen_reg_rtx (GET_MODE (orig_dst));
2023       /* Make life a bit easier for combine.  */
2024       emit_move_insn (dst, CONST0_RTX (GET_MODE (orig_dst)));
2025     }
2026
2027   /* Process the pieces.  */
2028   for (i = start; i < XVECLEN (src, 0); i++)
2029     {
2030       HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (src, 0, i), 1));
2031       enum machine_mode mode = GET_MODE (tmps[i]);
2032       unsigned int bytelen = GET_MODE_SIZE (mode);
2033       rtx dest = dst;
2034
2035       /* Handle trailing fragments that run over the size of the struct.  */
2036       if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
2037         {
2038           /* store_bit_field always takes its value from the lsb.
2039              Move the fragment to the lsb if it's not already there.  */
2040           if (
2041 #ifdef BLOCK_REG_PADDING
2042               BLOCK_REG_PADDING (GET_MODE (orig_dst), type, i == start)
2043               == (BYTES_BIG_ENDIAN ? upward : downward)
2044 #else
2045               BYTES_BIG_ENDIAN
2046 #endif
2047               )
2048             {
2049               int shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
2050               expand_binop (mode, ashr_optab, tmps[i], GEN_INT (shift),
2051                             tmps[i], 0, OPTAB_WIDEN);
2052             }
2053           bytelen = ssize - bytepos;
2054         }
2055
2056       if (GET_CODE (dst) == CONCAT)
2057         {
2058           if (bytepos + bytelen <= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
2059             dest = XEXP (dst, 0);
2060           else if (bytepos >= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
2061             {
2062               bytepos -= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)));
2063               dest = XEXP (dst, 1);
2064             }
2065           else if (bytepos == 0 && XVECLEN (src, 0))
2066             {
2067               dest = assign_stack_temp (GET_MODE (dest),
2068                                         GET_MODE_SIZE (GET_MODE (dest)), 0);
2069               emit_move_insn (adjust_address (dest, GET_MODE (tmps[i]), bytepos),
2070                               tmps[i]);
2071               dst = dest;
2072               break;
2073             }
2074           else
2075             abort ();
2076         }
2077
2078       /* Optimize the access just a bit.  */
2079       if (GET_CODE (dest) == MEM
2080           && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (dest))
2081               || MEM_ALIGN (dest) >= GET_MODE_ALIGNMENT (mode))
2082           && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
2083           && bytelen == GET_MODE_SIZE (mode))
2084         emit_move_insn (adjust_address (dest, mode, bytepos), tmps[i]);
2085       else
2086         store_bit_field (dest, bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
2087                          mode, tmps[i], ssize);
2088     }
2089
2090   emit_queue ();
2091
2092   /* Copy from the pseudo into the (probable) hard reg.  */
2093   if (orig_dst != dst)
2094     emit_move_insn (orig_dst, dst);
2095 }
2096
2097 /* Generate code to copy a BLKmode object of TYPE out of a
2098    set of registers starting with SRCREG into TGTBLK.  If TGTBLK
2099    is null, a stack temporary is created.  TGTBLK is returned.
2100
2101    The purpose of this routine is to handle functions that return
2102    BLKmode structures in registers.  Some machines (the PA for example)
2103    want to return all small structures in registers regardless of the
2104    structure's alignment.  */
2105
2106 rtx
2107 copy_blkmode_from_reg (rtx tgtblk, rtx srcreg, tree type)
2108 {
2109   unsigned HOST_WIDE_INT bytes = int_size_in_bytes (type);
2110   rtx src = NULL, dst = NULL;
2111   unsigned HOST_WIDE_INT bitsize = MIN (TYPE_ALIGN (type), BITS_PER_WORD);
2112   unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0;
2113
2114   if (tgtblk == 0)
2115     {
2116       tgtblk = assign_temp (build_qualified_type (type,
2117                                                   (TYPE_QUALS (type)
2118                                                    | TYPE_QUAL_CONST)),
2119                             0, 1, 1);
2120       preserve_temp_slots (tgtblk);
2121     }
2122
2123   /* This code assumes srcreg is at least a full word.  If it isn't, copy it
2124      into a new pseudo which is a full word.  */
2125
2126   if (GET_MODE (srcreg) != BLKmode
2127       && GET_MODE_SIZE (GET_MODE (srcreg)) < UNITS_PER_WORD)
2128     srcreg = convert_to_mode (word_mode, srcreg, TREE_UNSIGNED (type));
2129
2130   /* If the structure doesn't take up a whole number of words, see whether
2131      SRCREG is padded on the left or on the right.  If it's on the left,
2132      set PADDING_CORRECTION to the number of bits to skip.
2133
2134      In most ABIs, the structure will be returned at the least end of
2135      the register, which translates to right padding on little-endian
2136      targets and left padding on big-endian targets.  The opposite
2137      holds if the structure is returned at the most significant
2138      end of the register.  */
2139   if (bytes % UNITS_PER_WORD != 0
2140       && (targetm.calls.return_in_msb (type)
2141           ? !BYTES_BIG_ENDIAN
2142           : BYTES_BIG_ENDIAN))
2143     padding_correction
2144       = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD) * BITS_PER_UNIT));
2145
2146   /* Copy the structure BITSIZE bites at a time.
2147
2148      We could probably emit more efficient code for machines which do not use
2149      strict alignment, but it doesn't seem worth the effort at the current
2150      time.  */
2151   for (bitpos = 0, xbitpos = padding_correction;
2152        bitpos < bytes * BITS_PER_UNIT;
2153        bitpos += bitsize, xbitpos += bitsize)
2154     {
2155       /* We need a new source operand each time xbitpos is on a
2156          word boundary and when xbitpos == padding_correction
2157          (the first time through).  */
2158       if (xbitpos % BITS_PER_WORD == 0
2159           || xbitpos == padding_correction)
2160         src = operand_subword_force (srcreg, xbitpos / BITS_PER_WORD,
2161                                      GET_MODE (srcreg));
2162
2163       /* We need a new destination operand each time bitpos is on
2164          a word boundary.  */
2165       if (bitpos % BITS_PER_WORD == 0)
2166         dst = operand_subword (tgtblk, bitpos / BITS_PER_WORD, 1, BLKmode);
2167
2168       /* Use xbitpos for the source extraction (right justified) and
2169          xbitpos for the destination store (left justified).  */
2170       store_bit_field (dst, bitsize, bitpos % BITS_PER_WORD, word_mode,
2171                        extract_bit_field (src, bitsize,
2172                                           xbitpos % BITS_PER_WORD, 1,
2173                                           NULL_RTX, word_mode, word_mode,
2174                                           BITS_PER_WORD),
2175                        BITS_PER_WORD);
2176     }
2177
2178   return tgtblk;
2179 }
2180
2181 /* Add a USE expression for REG to the (possibly empty) list pointed
2182    to by CALL_FUSAGE.  REG must denote a hard register.  */
2183
2184 void
2185 use_reg (rtx *call_fusage, rtx reg)
2186 {
2187   if (GET_CODE (reg) != REG
2188       || REGNO (reg) >= FIRST_PSEUDO_REGISTER)
2189     abort ();
2190
2191   *call_fusage
2192     = gen_rtx_EXPR_LIST (VOIDmode,
2193                          gen_rtx_USE (VOIDmode, reg), *call_fusage);
2194 }
2195
2196 /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
2197    starting at REGNO.  All of these registers must be hard registers.  */
2198
2199 void
2200 use_regs (rtx *call_fusage, int regno, int nregs)
2201 {
2202   int i;
2203
2204   if (regno + nregs > FIRST_PSEUDO_REGISTER)
2205     abort ();
2206
2207   for (i = 0; i < nregs; i++)
2208     use_reg (call_fusage, regno_reg_rtx[regno + i]);
2209 }
2210
2211 /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
2212    PARALLEL REGS.  This is for calls that pass values in multiple
2213    non-contiguous locations.  The Irix 6 ABI has examples of this.  */
2214
2215 void
2216 use_group_regs (rtx *call_fusage, rtx regs)
2217 {
2218   int i;
2219
2220   for (i = 0; i < XVECLEN (regs, 0); i++)
2221     {
2222       rtx reg = XEXP (XVECEXP (regs, 0, i), 0);
2223
2224       /* A NULL entry means the parameter goes both on the stack and in
2225          registers.  This can also be a MEM for targets that pass values
2226          partially on the stack and partially in registers.  */
2227       if (reg != 0 && GET_CODE (reg) == REG)
2228         use_reg (call_fusage, reg);
2229     }
2230 }
2231 \f
2232
2233 /* Determine whether the LEN bytes generated by CONSTFUN can be
2234    stored to memory using several move instructions.  CONSTFUNDATA is
2235    a pointer which will be passed as argument in every CONSTFUN call.
2236    ALIGN is maximum alignment we can assume.  Return nonzero if a
2237    call to store_by_pieces should succeed.  */
2238
2239 int
2240 can_store_by_pieces (unsigned HOST_WIDE_INT len,
2241                      rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode),
2242                      void *constfundata, unsigned int align)
2243 {
2244   unsigned HOST_WIDE_INT max_size, l;
2245   HOST_WIDE_INT offset = 0;
2246   enum machine_mode mode, tmode;
2247   enum insn_code icode;
2248   int reverse;
2249   rtx cst;
2250
2251   if (len == 0)
2252     return 1;
2253
2254   if (! STORE_BY_PIECES_P (len, align))
2255     return 0;
2256
2257   if (! SLOW_UNALIGNED_ACCESS (word_mode, align)
2258       || align > MOVE_MAX * BITS_PER_UNIT || align >= BIGGEST_ALIGNMENT)
2259     align = MOVE_MAX * BITS_PER_UNIT;
2260
2261   /* We would first store what we can in the largest integer mode, then go to
2262      successively smaller modes.  */
2263
2264   for (reverse = 0;
2265        reverse <= (HAVE_PRE_DECREMENT || HAVE_POST_DECREMENT);
2266        reverse++)
2267     {
2268       l = len;
2269       mode = VOIDmode;
2270       max_size = STORE_MAX_PIECES + 1;
2271       while (max_size > 1)
2272         {
2273           for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2274                tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2275             if (GET_MODE_SIZE (tmode) < max_size)
2276               mode = tmode;
2277
2278           if (mode == VOIDmode)
2279             break;
2280
2281           icode = mov_optab->handlers[(int) mode].insn_code;
2282           if (icode != CODE_FOR_nothing
2283               && align >= GET_MODE_ALIGNMENT (mode))
2284             {
2285               unsigned int size = GET_MODE_SIZE (mode);
2286
2287               while (l >= size)
2288                 {
2289                   if (reverse)
2290                     offset -= size;
2291
2292                   cst = (*constfun) (constfundata, offset, mode);
2293                   if (!LEGITIMATE_CONSTANT_P (cst))
2294                     return 0;
2295
2296                   if (!reverse)
2297                     offset += size;
2298
2299                   l -= size;
2300                 }
2301             }
2302
2303           max_size = GET_MODE_SIZE (mode);
2304         }
2305
2306       /* The code above should have handled everything.  */
2307       if (l != 0)
2308         abort ();
2309     }
2310
2311   return 1;
2312 }
2313
2314 /* Generate several move instructions to store LEN bytes generated by
2315    CONSTFUN to block TO.  (A MEM rtx with BLKmode).  CONSTFUNDATA is a
2316    pointer which will be passed as argument in every CONSTFUN call.
2317    ALIGN is maximum alignment we can assume.
2318    If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
2319    mempcpy, and if ENDP is 2 return memory the end minus one byte ala
2320    stpcpy.  */
2321
2322 rtx
2323 store_by_pieces (rtx to, unsigned HOST_WIDE_INT len,
2324                  rtx (*constfun) (void *, HOST_WIDE_INT, enum machine_mode),
2325                  void *constfundata, unsigned int align, int endp)
2326 {
2327   struct store_by_pieces data;
2328
2329   if (len == 0)
2330     {
2331       if (endp == 2)
2332         abort ();
2333       return to;
2334     }
2335
2336   if (! STORE_BY_PIECES_P (len, align))
2337     abort ();
2338   to = protect_from_queue (to, 1);
2339   data.constfun = constfun;
2340   data.constfundata = constfundata;
2341   data.len = len;
2342   data.to = to;
2343   store_by_pieces_1 (&data, align);
2344   if (endp)
2345     {
2346       rtx to1;
2347
2348       if (data.reverse)
2349         abort ();
2350       if (data.autinc_to)
2351         {
2352           if (endp == 2)
2353             {
2354               if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
2355                 emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
2356               else
2357                 data.to_addr = copy_addr_to_reg (plus_constant (data.to_addr,
2358                                                                 -1));
2359             }
2360           to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
2361                                            data.offset);
2362         }
2363       else
2364         {
2365           if (endp == 2)
2366             --data.offset;
2367           to1 = adjust_address (data.to, QImode, data.offset);
2368         }
2369       return to1;
2370     }
2371   else
2372     return data.to;
2373 }
2374
2375 /* Generate several move instructions to clear LEN bytes of block TO.  (A MEM
2376    rtx with BLKmode).  The caller must pass TO through protect_from_queue
2377    before calling. ALIGN is maximum alignment we can assume.  */
2378
2379 static void
2380 clear_by_pieces (rtx to, unsigned HOST_WIDE_INT len, unsigned int align)
2381 {
2382   struct store_by_pieces data;
2383
2384   if (len == 0)
2385     return;
2386
2387   data.constfun = clear_by_pieces_1;
2388   data.constfundata = NULL;
2389   data.len = len;
2390   data.to = to;
2391   store_by_pieces_1 (&data, align);
2392 }
2393
2394 /* Callback routine for clear_by_pieces.
2395    Return const0_rtx unconditionally.  */
2396
2397 static rtx
2398 clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED,
2399                    HOST_WIDE_INT offset ATTRIBUTE_UNUSED,
2400                    enum machine_mode mode ATTRIBUTE_UNUSED)
2401 {
2402   return const0_rtx;
2403 }
2404
2405 /* Subroutine of clear_by_pieces and store_by_pieces.
2406    Generate several move instructions to store LEN bytes of block TO.  (A MEM
2407    rtx with BLKmode).  The caller must pass TO through protect_from_queue
2408    before calling.  ALIGN is maximum alignment we can assume.  */
2409
2410 static void
2411 store_by_pieces_1 (struct store_by_pieces *data ATTRIBUTE_UNUSED,
2412                    unsigned int align ATTRIBUTE_UNUSED)
2413 {
2414   rtx to_addr = XEXP (data->to, 0);
2415   unsigned HOST_WIDE_INT max_size = STORE_MAX_PIECES + 1;
2416   enum machine_mode mode = VOIDmode, tmode;
2417   enum insn_code icode;
2418
2419   data->offset = 0;
2420   data->to_addr = to_addr;
2421   data->autinc_to
2422     = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
2423        || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
2424
2425   data->explicit_inc_to = 0;
2426   data->reverse
2427     = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
2428   if (data->reverse)
2429     data->offset = data->len;
2430
2431   /* If storing requires more than two move insns,
2432      copy addresses to registers (to make displacements shorter)
2433      and use post-increment if available.  */
2434   if (!data->autinc_to
2435       && move_by_pieces_ninsns (data->len, align) > 2)
2436     {
2437       /* Determine the main mode we'll be using.  */
2438       for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2439            tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2440         if (GET_MODE_SIZE (tmode) < max_size)
2441           mode = tmode;
2442
2443       if (USE_STORE_PRE_DECREMENT (mode) && data->reverse && ! data->autinc_to)
2444         {
2445           data->to_addr = copy_addr_to_reg (plus_constant (to_addr, data->len));
2446           data->autinc_to = 1;
2447           data->explicit_inc_to = -1;
2448         }
2449
2450       if (USE_STORE_POST_INCREMENT (mode) && ! data->reverse
2451           && ! data->autinc_to)
2452         {
2453           data->to_addr = copy_addr_to_reg (to_addr);
2454           data->autinc_to = 1;
2455           data->explicit_inc_to = 1;
2456         }
2457
2458       if ( !data->autinc_to && CONSTANT_P (to_addr))
2459         data->to_addr = copy_addr_to_reg (to_addr);
2460     }
2461
2462   if (! SLOW_UNALIGNED_ACCESS (word_mode, align)
2463       || align > MOVE_MAX * BITS_PER_UNIT || align >= BIGGEST_ALIGNMENT)
2464     align = MOVE_MAX * BITS_PER_UNIT;
2465
2466   /* First store what we can in the largest integer mode, then go to
2467      successively smaller modes.  */
2468
2469   while (max_size > 1)
2470     {
2471       for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2472            tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
2473         if (GET_MODE_SIZE (tmode) < max_size)
2474           mode = tmode;
2475
2476       if (mode == VOIDmode)
2477         break;
2478
2479       icode = mov_optab->handlers[(int) mode].insn_code;
2480       if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
2481         store_by_pieces_2 (GEN_FCN (icode), mode, data);
2482
2483       max_size = GET_MODE_SIZE (mode);
2484     }
2485
2486   /* The code above should have handled everything.  */
2487   if (data->len != 0)
2488     abort ();
2489 }
2490
2491 /* Subroutine of store_by_pieces_1.  Store as many bytes as appropriate
2492    with move instructions for mode MODE.  GENFUN is the gen_... function
2493    to make a move insn for that mode.  DATA has all the other info.  */
2494
2495 static void
2496 store_by_pieces_2 (rtx (*genfun) (rtx, ...), enum machine_mode mode,
2497                    struct store_by_pieces *data)
2498 {
2499   unsigned int size = GET_MODE_SIZE (mode);
2500   rtx to1, cst;
2501
2502   while (data->len >= size)
2503     {
2504       if (data->reverse)
2505         data->offset -= size;
2506
2507       if (data->autinc_to)
2508         to1 = adjust_automodify_address (data->to, mode, data->to_addr,
2509                                          data->offset);
2510       else
2511         to1 = adjust_address (data->to, mode, data->offset);
2512
2513       if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
2514         emit_insn (gen_add2_insn (data->to_addr,
2515                                   GEN_INT (-(HOST_WIDE_INT) size)));
2516
2517       cst = (*data->constfun) (data->constfundata, data->offset, mode);
2518       emit_insn ((*genfun) (to1, cst));
2519
2520       if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
2521         emit_insn (gen_add2_insn (data->to_addr, GEN_INT (size)));
2522
2523       if (! data->reverse)
2524         data->offset += size;
2525
2526       data->len -= size;
2527     }
2528 }
2529 \f
2530 /* Write zeros through the storage of OBJECT.  If OBJECT has BLKmode, SIZE is
2531    its length in bytes.  */
2532
2533 rtx
2534 clear_storage (rtx object, rtx size)
2535 {
2536   rtx retval = 0;
2537   unsigned int align = (GET_CODE (object) == MEM ? MEM_ALIGN (object)
2538                         : GET_MODE_ALIGNMENT (GET_MODE (object)));
2539
2540   /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
2541      just move a zero.  Otherwise, do this a piece at a time.  */
2542   if (GET_MODE (object) != BLKmode
2543       && GET_CODE (size) == CONST_INT
2544       && INTVAL (size) == (HOST_WIDE_INT) GET_MODE_SIZE (GET_MODE (object)))
2545     emit_move_insn (object, CONST0_RTX (GET_MODE (object)));
2546   else
2547     {
2548       object = protect_from_queue (object, 1);
2549       size = protect_from_queue (size, 0);
2550
2551       if (size == const0_rtx)
2552         ;
2553       else if (GET_CODE (size) == CONST_INT
2554           && CLEAR_BY_PIECES_P (INTVAL (size), align))
2555         clear_by_pieces (object, INTVAL (size), align);
2556       else if (clear_storage_via_clrstr (object, size, align))
2557         ;
2558       else
2559         retval = clear_storage_via_libcall (object, size);
2560     }
2561
2562   return retval;
2563 }
2564
2565 /* A subroutine of clear_storage.  Expand a clrstr pattern;
2566    return true if successful.  */
2567
2568 static bool
2569 clear_storage_via_clrstr (rtx object, rtx size, unsigned int align)
2570 {
2571   /* Try the most limited insn first, because there's no point
2572      including more than one in the machine description unless
2573      the more limited one has some advantage.  */
2574
2575   rtx opalign = GEN_INT (align / BITS_PER_UNIT);
2576   enum machine_mode mode;
2577
2578   for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
2579        mode = GET_MODE_WIDER_MODE (mode))
2580     {
2581       enum insn_code code = clrstr_optab[(int) mode];
2582       insn_operand_predicate_fn pred;
2583
2584       if (code != CODE_FOR_nothing
2585           /* We don't need MODE to be narrower than
2586              BITS_PER_HOST_WIDE_INT here because if SIZE is less than
2587              the mode mask, as it is returned by the macro, it will
2588              definitely be less than the actual mode mask.  */
2589           && ((GET_CODE (size) == CONST_INT
2590                && ((unsigned HOST_WIDE_INT) INTVAL (size)
2591                    <= (GET_MODE_MASK (mode) >> 1)))
2592               || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD)
2593           && ((pred = insn_data[(int) code].operand[0].predicate) == 0
2594               || (*pred) (object, BLKmode))
2595           && ((pred = insn_data[(int) code].operand[2].predicate) == 0
2596               || (*pred) (opalign, VOIDmode)))
2597         {
2598           rtx op1;
2599           rtx last = get_last_insn ();
2600           rtx pat;
2601
2602           op1 = convert_to_mode (mode, size, 1);
2603           pred = insn_data[(int) code].operand[1].predicate;
2604           if (pred != 0 && ! (*pred) (op1, mode))
2605             op1 = copy_to_mode_reg (mode, op1);
2606
2607           pat = GEN_FCN ((int) code) (object, op1, opalign);
2608           if (pat)
2609             {
2610               emit_insn (pat);
2611               return true;
2612             }
2613           else
2614             delete_insns_since (last);
2615         }
2616     }
2617
2618   return false;
2619 }
2620
2621 /* A subroutine of clear_storage.  Expand a call to memset or bzero.
2622    Return the return value of memset, 0 otherwise.  */
2623
2624 static rtx
2625 clear_storage_via_libcall (rtx object, rtx size)
2626 {
2627   tree call_expr, arg_list, fn, object_tree, size_tree;
2628   enum machine_mode size_mode;
2629   rtx retval;
2630
2631   /* OBJECT or SIZE may have been passed through protect_from_queue.
2632
2633      It is unsafe to save the value generated by protect_from_queue
2634      and reuse it later.  Consider what happens if emit_queue is
2635      called before the return value from protect_from_queue is used.
2636
2637      Expansion of the CALL_EXPR below will call emit_queue before
2638      we are finished emitting RTL for argument setup.  So if we are
2639      not careful we could get the wrong value for an argument.
2640
2641      To avoid this problem we go ahead and emit code to copy OBJECT
2642      and SIZE into new pseudos.  We can then place those new pseudos
2643      into an RTL_EXPR and use them later, even after a call to
2644      emit_queue.
2645
2646      Note this is not strictly needed for library calls since they
2647      do not call emit_queue before loading their arguments.  However,
2648      we may need to have library calls call emit_queue in the future
2649      since failing to do so could cause problems for targets which
2650      define SMALL_REGISTER_CLASSES and pass arguments in registers.  */
2651
2652   object = copy_to_mode_reg (Pmode, XEXP (object, 0));
2653
2654   if (TARGET_MEM_FUNCTIONS)
2655     size_mode = TYPE_MODE (sizetype);
2656   else
2657     size_mode = TYPE_MODE (unsigned_type_node);
2658   size = convert_to_mode (size_mode, size, 1);
2659   size = copy_to_mode_reg (size_mode, size);
2660
2661   /* It is incorrect to use the libcall calling conventions to call
2662      memset in this context.  This could be a user call to memset and
2663      the user may wish to examine the return value from memset.  For
2664      targets where libcalls and normal calls have different conventions
2665      for returning pointers, we could end up generating incorrect code.
2666
2667      For convenience, we generate the call to bzero this way as well.  */
2668
2669   object_tree = make_tree (ptr_type_node, object);
2670   if (TARGET_MEM_FUNCTIONS)
2671     size_tree = make_tree (sizetype, size);
2672   else
2673     size_tree = make_tree (unsigned_type_node, size);
2674
2675   fn = clear_storage_libcall_fn (true);
2676   arg_list = tree_cons (NULL_TREE, size_tree, NULL_TREE);
2677   if (TARGET_MEM_FUNCTIONS)
2678     arg_list = tree_cons (NULL_TREE, integer_zero_node, arg_list);
2679   arg_list = tree_cons (NULL_TREE, object_tree, arg_list);
2680
2681   /* Now we have to build up the CALL_EXPR itself.  */
2682   call_expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (fn)), fn);
2683   call_expr = build (CALL_EXPR, TREE_TYPE (TREE_TYPE (fn)),
2684                      call_expr, arg_list, NULL_TREE);
2685
2686   retval = expand_expr (call_expr, NULL_RTX, VOIDmode, 0);
2687
2688   /* If we are initializing a readonly value, show the above call
2689      clobbered it.  Otherwise, a load from it may erroneously be
2690      hoisted from a loop.  */
2691   if (RTX_UNCHANGING_P (object))
2692     emit_insn (gen_rtx_CLOBBER (VOIDmode, object));
2693
2694   return (TARGET_MEM_FUNCTIONS ? retval : NULL_RTX);
2695 }
2696
2697 /* A subroutine of clear_storage_via_libcall.  Create the tree node
2698    for the function we use for block clears.  The first time FOR_CALL
2699    is true, we call assemble_external.  */
2700
2701 static GTY(()) tree block_clear_fn;
2702
2703 void
2704 init_block_clear_fn (const char *asmspec)
2705 {
2706   if (!block_clear_fn)
2707     {
2708       tree fn, args;
2709
2710       if (TARGET_MEM_FUNCTIONS)
2711         {
2712           fn = get_identifier ("memset");
2713           args = build_function_type_list (ptr_type_node, ptr_type_node,
2714                                            integer_type_node, sizetype,
2715                                            NULL_TREE);
2716         }
2717       else
2718         {
2719           fn = get_identifier ("bzero");
2720           args = build_function_type_list (void_type_node, ptr_type_node,
2721                                            unsigned_type_node, NULL_TREE);
2722         }
2723
2724       fn = build_decl (FUNCTION_DECL, fn, args);
2725       DECL_EXTERNAL (fn) = 1;
2726       TREE_PUBLIC (fn) = 1;
2727       DECL_ARTIFICIAL (fn) = 1;
2728       TREE_NOTHROW (fn) = 1;
2729
2730       block_clear_fn = fn;
2731     }
2732
2733   if (asmspec)
2734     {
2735       SET_DECL_RTL (block_clear_fn, NULL_RTX);
2736       SET_DECL_ASSEMBLER_NAME (block_clear_fn, get_identifier (asmspec));
2737     }
2738 }
2739
2740 static tree
2741 clear_storage_libcall_fn (int for_call)
2742 {
2743   static bool emitted_extern;
2744
2745   if (!block_clear_fn)
2746     init_block_clear_fn (NULL);
2747
2748   if (for_call && !emitted_extern)
2749     {
2750       emitted_extern = true;
2751       make_decl_rtl (block_clear_fn, NULL);
2752       assemble_external (block_clear_fn);
2753     }
2754
2755   return block_clear_fn;
2756 }
2757 \f
2758 /* Generate code to copy Y into X.
2759    Both Y and X must have the same mode, except that
2760    Y can be a constant with VOIDmode.
2761    This mode cannot be BLKmode; use emit_block_move for that.
2762
2763    Return the last instruction emitted.  */
2764
2765 rtx
2766 emit_move_insn (rtx x, rtx y)
2767 {
2768   enum machine_mode mode = GET_MODE (x);
2769   rtx y_cst = NULL_RTX;
2770   rtx last_insn, set;
2771
2772   x = protect_from_queue (x, 1);
2773   y = protect_from_queue (y, 0);
2774
2775   if (mode == BLKmode || (GET_MODE (y) != mode && GET_MODE (y) != VOIDmode))
2776     abort ();
2777
2778   /* Never force constant_p_rtx to memory.  */
2779   if (GET_CODE (y) == CONSTANT_P_RTX)
2780     ;
2781   else if (CONSTANT_P (y))
2782     {
2783       if (optimize
2784           && SCALAR_FLOAT_MODE_P (GET_MODE (x))
2785           && (last_insn = compress_float_constant (x, y)))
2786         return last_insn;
2787
2788       y_cst = y;
2789
2790       if (!LEGITIMATE_CONSTANT_P (y))
2791         {
2792           y = force_const_mem (mode, y);
2793
2794           /* If the target's cannot_force_const_mem prevented the spill,
2795              assume that the target's move expanders will also take care
2796              of the non-legitimate constant.  */
2797           if (!y)
2798             y = y_cst;
2799         }
2800     }
2801
2802   /* If X or Y are memory references, verify that their addresses are valid
2803      for the machine.  */
2804   if (GET_CODE (x) == MEM
2805       && ((! memory_address_p (GET_MODE (x), XEXP (x, 0))
2806            && ! push_operand (x, GET_MODE (x)))
2807           || (flag_force_addr
2808               && CONSTANT_ADDRESS_P (XEXP (x, 0)))))
2809     x = validize_mem (x);
2810
2811   if (GET_CODE (y) == MEM
2812       && (! memory_address_p (GET_MODE (y), XEXP (y, 0))
2813           || (flag_force_addr
2814               && CONSTANT_ADDRESS_P (XEXP (y, 0)))))
2815     y = validize_mem (y);
2816
2817   if (mode == BLKmode)
2818     abort ();
2819
2820   last_insn = emit_move_insn_1 (x, y);
2821
2822   if (y_cst && GET_CODE (x) == REG
2823       && (set = single_set (last_insn)) != NULL_RTX
2824       && SET_DEST (set) == x
2825       && ! rtx_equal_p (y_cst, SET_SRC (set)))
2826     set_unique_reg_note (last_insn, REG_EQUAL, y_cst);
2827
2828   return last_insn;
2829 }
2830
2831 /* Low level part of emit_move_insn.
2832    Called just like emit_move_insn, but assumes X and Y
2833    are basically valid.  */
2834
2835 rtx
2836 emit_move_insn_1 (rtx x, rtx y)
2837 {
2838   enum machine_mode mode = GET_MODE (x);
2839   enum machine_mode submode;
2840   enum mode_class class = GET_MODE_CLASS (mode);
2841
2842   if ((unsigned int) mode >= (unsigned int) MAX_MACHINE_MODE)
2843     abort ();
2844
2845   if (mov_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
2846     return
2847       emit_insn (GEN_FCN (mov_optab->handlers[(int) mode].insn_code) (x, y));
2848
2849   /* Expand complex moves by moving real part and imag part, if possible.  */
2850   else if ((class == MODE_COMPLEX_FLOAT || class == MODE_COMPLEX_INT)
2851            && BLKmode != (submode = GET_MODE_INNER (mode))
2852            && (mov_optab->handlers[(int) submode].insn_code
2853                != CODE_FOR_nothing))
2854     {
2855       /* Don't split destination if it is a stack push.  */
2856       int stack = push_operand (x, GET_MODE (x));
2857
2858 #ifdef PUSH_ROUNDING
2859       /* In case we output to the stack, but the size is smaller than the
2860          machine can push exactly, we need to use move instructions.  */
2861       if (stack
2862           && (PUSH_ROUNDING (GET_MODE_SIZE (submode))
2863               != GET_MODE_SIZE (submode)))
2864         {
2865           rtx temp;
2866           HOST_WIDE_INT offset1, offset2;
2867
2868           /* Do not use anti_adjust_stack, since we don't want to update
2869              stack_pointer_delta.  */
2870           temp = expand_binop (Pmode,
2871 #ifdef STACK_GROWS_DOWNWARD
2872                                sub_optab,
2873 #else
2874                                add_optab,
2875 #endif
2876                                stack_pointer_rtx,
2877                                GEN_INT
2878                                  (PUSH_ROUNDING
2879                                   (GET_MODE_SIZE (GET_MODE (x)))),
2880                                stack_pointer_rtx, 0, OPTAB_LIB_WIDEN);
2881
2882           if (temp != stack_pointer_rtx)
2883             emit_move_insn (stack_pointer_rtx, temp);
2884
2885 #ifdef STACK_GROWS_DOWNWARD
2886           offset1 = 0;
2887           offset2 = GET_MODE_SIZE (submode);
2888 #else
2889           offset1 = -PUSH_ROUNDING (GET_MODE_SIZE (GET_MODE (x)));
2890           offset2 = (-PUSH_ROUNDING (GET_MODE_SIZE (GET_MODE (x)))
2891                      + GET_MODE_SIZE (submode));
2892 #endif
2893
2894           emit_move_insn (change_address (x, submode,
2895                                           gen_rtx_PLUS (Pmode,
2896                                                         stack_pointer_rtx,
2897                                                         GEN_INT (offset1))),
2898                           gen_realpart (submode, y));
2899           emit_move_insn (change_address (x, submode,
2900                                           gen_rtx_PLUS (Pmode,
2901                                                         stack_pointer_rtx,
2902                                                         GEN_INT (offset2))),
2903                           gen_imagpart (submode, y));
2904         }
2905       else
2906 #endif
2907       /* If this is a stack, push the highpart first, so it
2908          will be in the argument order.
2909
2910          In that case, change_address is used only to convert
2911          the mode, not to change the address.  */
2912       if (stack)
2913         {
2914           /* Note that the real part always precedes the imag part in memory
2915              regardless of machine's endianness.  */
2916 #ifdef STACK_GROWS_DOWNWARD
2917           emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
2918                           gen_imagpart (submode, y));
2919           emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
2920                           gen_realpart (submode, y));
2921 #else
2922           emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
2923                           gen_realpart (submode, y));
2924           emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
2925                           gen_imagpart (submode, y));
2926 #endif
2927         }
2928       else
2929         {
2930           rtx realpart_x, realpart_y;
2931           rtx imagpart_x, imagpart_y;
2932
2933           /* If this is a complex value with each part being smaller than a
2934              word, the usual calling sequence will likely pack the pieces into
2935              a single register.  Unfortunately, SUBREG of hard registers only
2936              deals in terms of words, so we have a problem converting input
2937              arguments to the CONCAT of two registers that is used elsewhere
2938              for complex values.  If this is before reload, we can copy it into
2939              memory and reload.  FIXME, we should see about using extract and
2940              insert on integer registers, but complex short and complex char
2941              variables should be rarely used.  */
2942           if (GET_MODE_BITSIZE (mode) < 2 * BITS_PER_WORD
2943               && (reload_in_progress | reload_completed) == 0)
2944             {
2945               int packed_dest_p
2946                 = (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER);
2947               int packed_src_p
2948                 = (REG_P (y) && REGNO (y) < FIRST_PSEUDO_REGISTER);
2949
2950               if (packed_dest_p || packed_src_p)
2951                 {
2952                   enum mode_class reg_class = ((class == MODE_COMPLEX_FLOAT)
2953                                                ? MODE_FLOAT : MODE_INT);
2954
2955                   enum machine_mode reg_mode
2956                     = mode_for_size (GET_MODE_BITSIZE (mode), reg_class, 1);
2957
2958                   if (reg_mode != BLKmode)
2959                     {
2960                       rtx mem = assign_stack_temp (reg_mode,
2961                                                    GET_MODE_SIZE (mode), 0);
2962                       rtx cmem = adjust_address (mem, mode, 0);
2963
2964                       cfun->cannot_inline
2965                         = N_("function using short complex types cannot be inline");
2966
2967                       if (packed_dest_p)
2968                         {
2969                           rtx sreg = gen_rtx_SUBREG (reg_mode, x, 0);
2970
2971                           emit_move_insn_1 (cmem, y);
2972                           return emit_move_insn_1 (sreg, mem);
2973                         }
2974                       else
2975                         {
2976                           rtx sreg = gen_rtx_SUBREG (reg_mode, y, 0);
2977
2978                           emit_move_insn_1 (mem, sreg);
2979                           return emit_move_insn_1 (x, cmem);
2980                         }
2981                     }
2982                 }
2983             }
2984
2985           realpart_x = gen_realpart (submode, x);
2986           realpart_y = gen_realpart (submode, y);
2987           imagpart_x = gen_imagpart (submode, x);
2988           imagpart_y = gen_imagpart (submode, y);
2989
2990           /* Show the output dies here.  This is necessary for SUBREGs
2991              of pseudos since we cannot track their lifetimes correctly;
2992              hard regs shouldn't appear here except as return values.
2993              We never want to emit such a clobber after reload.  */
2994           if (x != y
2995               && ! (reload_in_progress || reload_completed)
2996               && (GET_CODE (realpart_x) == SUBREG
2997                   || GET_CODE (imagpart_x) == SUBREG))
2998             emit_insn (gen_rtx_CLOBBER (VOIDmode, x));
2999
3000           emit_move_insn (realpart_x, realpart_y);
3001           emit_move_insn (imagpart_x, imagpart_y);
3002         }
3003
3004       return get_last_insn ();
3005     }
3006
3007   /* Handle MODE_CC modes:  If we don't have a special move insn for this mode,
3008      find a mode to do it in.  If we have a movcc, use it.  Otherwise,
3009      find the MODE_INT mode of the same width.  */
3010   else if (GET_MODE_CLASS (mode) == MODE_CC
3011            && mov_optab->handlers[(int) mode].insn_code == CODE_FOR_nothing)
3012     {
3013       enum insn_code insn_code;
3014       enum machine_mode tmode = VOIDmode;
3015       rtx x1 = x, y1 = y;
3016
3017       if (mode != CCmode
3018           && mov_optab->handlers[(int) CCmode].insn_code != CODE_FOR_nothing)
3019         tmode = CCmode;
3020       else
3021         for (tmode = QImode; tmode != VOIDmode;
3022              tmode = GET_MODE_WIDER_MODE (tmode))
3023           if (GET_MODE_SIZE (tmode) == GET_MODE_SIZE (mode))
3024             break;
3025
3026       if (tmode == VOIDmode)
3027         abort ();
3028
3029       /* Get X and Y in TMODE.  We can't use gen_lowpart here because it
3030          may call change_address which is not appropriate if we were
3031          called when a reload was in progress.  We don't have to worry
3032          about changing the address since the size in bytes is supposed to
3033          be the same.  Copy the MEM to change the mode and move any
3034          substitutions from the old MEM to the new one.  */
3035
3036       if (reload_in_progress)
3037         {
3038           x = gen_lowpart_common (tmode, x1);
3039           if (x == 0 && GET_CODE (x1) == MEM)
3040             {
3041               x = adjust_address_nv (x1, tmode, 0);
3042               copy_replacements (x1, x);
3043             }
3044
3045           y = gen_lowpart_common (tmode, y1);
3046           if (y == 0 && GET_CODE (y1) == MEM)
3047             {
3048               y = adjust_address_nv (y1, tmode, 0);
3049               copy_replacements (y1, y);
3050             }
3051         }
3052       else
3053         {
3054           x = gen_lowpart (tmode, x);
3055           y = gen_lowpart (tmode, y);
3056         }
3057
3058       insn_code = mov_optab->handlers[(int) tmode].insn_code;
3059       return emit_insn (GEN_FCN (insn_code) (x, y));
3060     }
3061
3062   /* Try using a move pattern for the corresponding integer mode.  This is
3063      only safe when simplify_subreg can convert MODE constants into integer
3064      constants.  At present, it can only do this reliably if the value
3065      fits within a HOST_WIDE_INT.  */
3066   else if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
3067            && (submode = int_mode_for_mode (mode)) != BLKmode
3068            && mov_optab->handlers[submode].insn_code != CODE_FOR_nothing)
3069     return emit_insn (GEN_FCN (mov_optab->handlers[submode].insn_code)
3070                       (simplify_gen_subreg (submode, x, mode, 0),
3071                        simplify_gen_subreg (submode, y, mode, 0)));
3072
3073   /* This will handle any multi-word or full-word mode that lacks a move_insn
3074      pattern.  However, you will get better code if you define such patterns,
3075      even if they must turn into multiple assembler instructions.  */
3076   else if (GET_MODE_SIZE (mode) >= UNITS_PER_WORD)
3077     {
3078       rtx last_insn = 0;
3079       rtx seq, inner;
3080       int need_clobber;
3081       int i;
3082
3083 #ifdef PUSH_ROUNDING
3084
3085       /* If X is a push on the stack, do the push now and replace
3086          X with a reference to the stack pointer.  */
3087       if (push_operand (x, GET_MODE (x)))
3088         {
3089           rtx temp;
3090           enum rtx_code code;
3091
3092           /* Do not use anti_adjust_stack, since we don't want to update
3093              stack_pointer_delta.  */
3094           temp = expand_binop (Pmode,
3095 #ifdef STACK_GROWS_DOWNWARD
3096                                sub_optab,
3097 #else
3098                                add_optab,
3099 #endif
3100                                stack_pointer_rtx,
3101                                GEN_INT
3102                                  (PUSH_ROUNDING
3103                                   (GET_MODE_SIZE (GET_MODE (x)))),
3104                                stack_pointer_rtx, 0, OPTAB_LIB_WIDEN);
3105
3106           if (temp != stack_pointer_rtx)
3107             emit_move_insn (stack_pointer_rtx, temp);
3108
3109           code = GET_CODE (XEXP (x, 0));
3110
3111           /* Just hope that small offsets off SP are OK.  */
3112           if (code == POST_INC)
3113             temp = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3114                                 GEN_INT (-((HOST_WIDE_INT)
3115                                            GET_MODE_SIZE (GET_MODE (x)))));
3116           else if (code == POST_DEC)
3117             temp = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3118                                 GEN_INT (GET_MODE_SIZE (GET_MODE (x))));
3119           else
3120             temp = stack_pointer_rtx;
3121
3122           x = change_address (x, VOIDmode, temp);
3123         }
3124 #endif
3125
3126       /* If we are in reload, see if either operand is a MEM whose address
3127          is scheduled for replacement.  */
3128       if (reload_in_progress && GET_CODE (x) == MEM
3129           && (inner = find_replacement (&XEXP (x, 0))) != XEXP (x, 0))
3130         x = replace_equiv_address_nv (x, inner);
3131       if (reload_in_progress && GET_CODE (y) == MEM
3132           && (inner = find_replacement (&XEXP (y, 0))) != XEXP (y, 0))
3133         y = replace_equiv_address_nv (y, inner);
3134
3135       start_sequence ();
3136
3137       need_clobber = 0;
3138       for (i = 0;
3139            i < (GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
3140            i++)
3141         {
3142           rtx xpart = operand_subword (x, i, 1, mode);
3143           rtx ypart = operand_subword (y, i, 1, mode);
3144
3145           /* If we can't get a part of Y, put Y into memory if it is a
3146              constant.  Otherwise, force it into a register.  If we still
3147              can't get a part of Y, abort.  */
3148           if (ypart == 0 && CONSTANT_P (y))
3149             {
3150               y = force_const_mem (mode, y);
3151               ypart = operand_subword (y, i, 1, mode);
3152             }
3153           else if (ypart == 0)
3154             ypart = operand_subword_force (y, i, mode);
3155
3156           if (xpart == 0 || ypart == 0)
3157             abort ();
3158
3159           need_clobber |= (GET_CODE (xpart) == SUBREG);
3160
3161           last_insn = emit_move_insn (xpart, ypart);
3162         }
3163
3164       seq = get_insns ();
3165       end_sequence ();
3166
3167       /* Show the output dies here.  This is necessary for SUBREGs
3168          of pseudos since we cannot track their lifetimes correctly;
3169          hard regs shouldn't appear here except as return values.
3170          We never want to emit such a clobber after reload.  */
3171       if (x != y
3172           && ! (reload_in_progress || reload_completed)
3173           && need_clobber != 0)
3174         emit_insn (gen_rtx_CLOBBER (VOIDmode, x));
3175
3176       emit_insn (seq);
3177
3178       return last_insn;
3179     }
3180   else
3181     abort ();
3182 }
3183
3184 /* If Y is representable exactly in a narrower mode, and the target can
3185    perform the extension directly from constant or memory, then emit the
3186    move as an extension.  */
3187
3188 static rtx
3189 compress_float_constant (rtx x, rtx y)
3190 {
3191   enum machine_mode dstmode = GET_MODE (x);
3192   enum machine_mode orig_srcmode = GET_MODE (y);
3193   enum machine_mode srcmode;
3194   REAL_VALUE_TYPE r;
3195
3196   REAL_VALUE_FROM_CONST_DOUBLE (r, y);
3197
3198   for (srcmode = GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode));
3199        srcmode != orig_srcmode;
3200        srcmode = GET_MODE_WIDER_MODE (srcmode))
3201     {
3202       enum insn_code ic;
3203       rtx trunc_y, last_insn;
3204
3205       /* Skip if the target can't extend this way.  */
3206       ic = can_extend_p (dstmode, srcmode, 0);
3207       if (ic == CODE_FOR_nothing)
3208         continue;
3209
3210       /* Skip if the narrowed value isn't exact.  */
3211       if (! exact_real_truncate (srcmode, &r))
3212         continue;
3213
3214       trunc_y = CONST_DOUBLE_FROM_REAL_VALUE (r, srcmode);
3215
3216       if (LEGITIMATE_CONSTANT_P (trunc_y))
3217         {
3218           /* Skip if the target needs extra instructions to perform
3219              the extension.  */
3220           if (! (*insn_data[ic].operand[1].predicate) (trunc_y, srcmode))
3221             continue;
3222         }
3223       else if (float_extend_from_mem[dstmode][srcmode])
3224         trunc_y = validize_mem (force_const_mem (srcmode, trunc_y));
3225       else
3226         continue;
3227
3228       emit_unop_insn (ic, x, trunc_y, UNKNOWN);
3229       last_insn = get_last_insn ();
3230
3231       if (GET_CODE (x) == REG)
3232         set_unique_reg_note (last_insn, REG_EQUAL, y);
3233
3234       return last_insn;
3235     }
3236
3237   return NULL_RTX;
3238 }
3239 \f
3240 /* Pushing data onto the stack.  */
3241
3242 /* Push a block of length SIZE (perhaps variable)
3243    and return an rtx to address the beginning of the block.
3244    Note that it is not possible for the value returned to be a QUEUED.
3245    The value may be virtual_outgoing_args_rtx.
3246
3247    EXTRA is the number of bytes of padding to push in addition to SIZE.
3248    BELOW nonzero means this padding comes at low addresses;
3249    otherwise, the padding comes at high addresses.  */
3250
3251 rtx
3252 push_block (rtx size, int extra, int below)
3253 {
3254   rtx temp;
3255
3256   size = convert_modes (Pmode, ptr_mode, size, 1);
3257   if (CONSTANT_P (size))
3258     anti_adjust_stack (plus_constant (size, extra));
3259   else if (GET_CODE (size) == REG && extra == 0)
3260     anti_adjust_stack (size);
3261   else
3262     {
3263       temp = copy_to_mode_reg (Pmode, size);
3264       if (extra != 0)
3265         temp = expand_binop (Pmode, add_optab, temp, GEN_INT (extra),
3266                              temp, 0, OPTAB_LIB_WIDEN);
3267       anti_adjust_stack (temp);
3268     }
3269
3270 #ifndef STACK_GROWS_DOWNWARD
3271   if (0)
3272 #else
3273   if (1)
3274 #endif
3275     {
3276       temp = virtual_outgoing_args_rtx;
3277       if (extra != 0 && below)
3278         temp = plus_constant (temp, extra);
3279     }
3280   else
3281     {
3282       if (GET_CODE (size) == CONST_INT)
3283         temp = plus_constant (virtual_outgoing_args_rtx,
3284                               -INTVAL (size) - (below ? 0 : extra));
3285       else if (extra != 0 && !below)
3286         temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
3287                              negate_rtx (Pmode, plus_constant (size, extra)));
3288       else
3289         temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
3290                              negate_rtx (Pmode, size));
3291     }
3292
3293   return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT), temp);
3294 }
3295
3296 #ifdef PUSH_ROUNDING
3297
3298 /* Emit single push insn.  */
3299
3300 static void
3301 emit_single_push_insn (enum machine_mode mode, rtx x, tree type)
3302 {
3303   rtx dest_addr;
3304   unsigned rounded_size = PUSH_ROUNDING (GET_MODE_SIZE (mode));
3305   rtx dest;
3306   enum insn_code icode;
3307   insn_operand_predicate_fn pred;
3308
3309   stack_pointer_delta += PUSH_ROUNDING (GET_MODE_SIZE (mode));
3310   /* If there is push pattern, use it.  Otherwise try old way of throwing
3311      MEM representing push operation to move expander.  */
3312   icode = push_optab->handlers[(int) mode].insn_code;
3313   if (icode != CODE_FOR_nothing)
3314     {
3315       if (((pred = insn_data[(int) icode].operand[0].predicate)
3316            && !((*pred) (x, mode))))
3317         x = force_reg (mode, x);
3318       emit_insn (GEN_FCN (icode) (x));
3319       return;
3320     }
3321   if (GET_MODE_SIZE (mode) == rounded_size)
3322     dest_addr = gen_rtx_fmt_e (STACK_PUSH_CODE, Pmode, stack_pointer_rtx);
3323   /* If we are to pad downward, adjust the stack pointer first and
3324      then store X into the stack location using an offset.  This is
3325      because emit_move_insn does not know how to pad; it does not have
3326      access to type.  */
3327   else if (FUNCTION_ARG_PADDING (mode, type) == downward)
3328     {
3329       unsigned padding_size = rounded_size - GET_MODE_SIZE (mode);
3330       HOST_WIDE_INT offset;
3331
3332       emit_move_insn (stack_pointer_rtx,
3333                       expand_binop (Pmode,
3334 #ifdef STACK_GROWS_DOWNWARD
3335                                     sub_optab,
3336 #else
3337                                     add_optab,
3338 #endif
3339                                     stack_pointer_rtx,
3340                                     GEN_INT (rounded_size),
3341                                     NULL_RTX, 0, OPTAB_LIB_WIDEN));
3342
3343       offset = (HOST_WIDE_INT) padding_size;
3344 #ifdef STACK_GROWS_DOWNWARD
3345       if (STACK_PUSH_CODE == POST_DEC)
3346         /* We have already decremented the stack pointer, so get the
3347            previous value.  */
3348         offset += (HOST_WIDE_INT) rounded_size;
3349 #else
3350       if (STACK_PUSH_CODE == POST_INC)
3351         /* We have already incremented the stack pointer, so get the
3352            previous value.  */
3353         offset -= (HOST_WIDE_INT) rounded_size;
3354 #endif
3355       dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (offset));
3356     }
3357   else
3358     {
3359 #ifdef STACK_GROWS_DOWNWARD
3360       /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC.  */
3361       dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3362                                 GEN_INT (-(HOST_WIDE_INT) rounded_size));
3363 #else
3364       /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC.  */
3365       dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
3366                                 GEN_INT (rounded_size));
3367 #endif
3368       dest_addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, dest_addr);
3369     }
3370
3371   dest = gen_rtx_MEM (mode, dest_addr);
3372
3373   if (type != 0)
3374     {
3375       set_mem_attributes (dest, type, 1);
3376
3377       if (flag_optimize_sibling_calls)
3378         /* Function incoming arguments may overlap with sibling call
3379            outgoing arguments and we cannot allow reordering of reads
3380            from function arguments with stores to outgoing arguments
3381            of sibling calls.  */
3382         set_mem_alias_set (dest, 0);
3383     }
3384   emit_move_insn (dest, x);
3385 }
3386 #endif
3387
3388 /* Generate code to push X onto the stack, assuming it has mode MODE and
3389    type TYPE.
3390    MODE is redundant except when X is a CONST_INT (since they don't
3391    carry mode info).
3392    SIZE is an rtx for the size of data to be copied (in bytes),
3393    needed only if X is BLKmode.
3394
3395    ALIGN (in bits) is maximum alignment we can assume.
3396
3397    If PARTIAL and REG are both nonzero, then copy that many of the first
3398    words of X into registers starting with REG, and push the rest of X.
3399    The amount of space pushed is decreased by PARTIAL words,
3400    rounded *down* to a multiple of PARM_BOUNDARY.
3401    REG must be a hard register in this case.
3402    If REG is zero but PARTIAL is not, take any all others actions for an
3403    argument partially in registers, but do not actually load any
3404    registers.
3405
3406    EXTRA is the amount in bytes of extra space to leave next to this arg.
3407    This is ignored if an argument block has already been allocated.
3408
3409    On a machine that lacks real push insns, ARGS_ADDR is the address of
3410    the bottom of the argument block for this call.  We use indexing off there
3411    to store the arg.  On machines with push insns, ARGS_ADDR is 0 when a
3412    argument block has not been preallocated.
3413
3414    ARGS_SO_FAR is the size of args previously pushed for this call.
3415
3416    REG_PARM_STACK_SPACE is nonzero if functions require stack space
3417    for arguments passed in registers.  If nonzero, it will be the number
3418    of bytes required.  */
3419
3420 void
3421 emit_push_insn (rtx x, enum machine_mode mode, tree type, rtx size,
3422                 unsigned int align, int partial, rtx reg, int extra,
3423                 rtx args_addr, rtx args_so_far, int reg_parm_stack_space,
3424                 rtx alignment_pad)
3425 {
3426   rtx xinner;
3427   enum direction stack_direction
3428 #ifdef STACK_GROWS_DOWNWARD
3429     = downward;
3430 #else
3431     = upward;
3432 #endif
3433
3434   /* Decide where to pad the argument: `downward' for below,
3435      `upward' for above, or `none' for don't pad it.
3436      Default is below for small data on big-endian machines; else above.  */
3437   enum direction where_pad = FUNCTION_ARG_PADDING (mode, type);
3438
3439   /* Invert direction if stack is post-decrement.
3440      FIXME: why?  */
3441   if (STACK_PUSH_CODE == POST_DEC)
3442     if (where_pad != none)
3443       where_pad = (where_pad == downward ? upward : downward);
3444
3445   xinner = x = protect_from_queue (x, 0);
3446
3447   if (mode == BLKmode)
3448     {
3449       /* Copy a block into the stack, entirely or partially.  */
3450
3451       rtx temp;
3452       int used = partial * UNITS_PER_WORD;
3453       int offset;
3454       int skip;
3455
3456       if (reg && GET_CODE (reg) == PARALLEL)
3457         {
3458           /* Use the size of the elt to compute offset.  */
3459           rtx elt = XEXP (XVECEXP (reg, 0, 0), 0);
3460           used = partial * GET_MODE_SIZE (GET_MODE (elt));
3461           offset = used % (PARM_BOUNDARY / BITS_PER_UNIT);
3462         }
3463       else
3464         offset = used % (PARM_BOUNDARY / BITS_PER_UNIT);
3465
3466       if (size == 0)
3467         abort ();
3468
3469       used -= offset;
3470
3471       /* USED is now the # of bytes we need not copy to the stack
3472          because registers will take care of them.  */
3473
3474       if (partial != 0)
3475         xinner = adjust_address (xinner, BLKmode, used);
3476
3477       /* If the partial register-part of the arg counts in its stack size,
3478          skip the part of stack space corresponding to the registers.
3479          Otherwise, start copying to the beginning of the stack space,
3480          by setting SKIP to 0.  */
3481       skip = (reg_parm_stack_space == 0) ? 0 : used;
3482
3483 #ifdef PUSH_ROUNDING
3484       /* Do it with several push insns if that doesn't take lots of insns
3485          and if there is no difficulty with push insns that skip bytes
3486          on the stack for alignment purposes.  */
3487       if (args_addr == 0
3488           && PUSH_ARGS
3489           && GET_CODE (size) == CONST_INT
3490           && skip == 0
3491           && MEM_ALIGN (xinner) >= align
3492           && (MOVE_BY_PIECES_P ((unsigned) INTVAL (size) - used, align))
3493           /* Here we avoid the case of a structure whose weak alignment
3494              forces many pushes of a small amount of data,
3495              and such small pushes do rounding that causes trouble.  */
3496           && ((! SLOW_UNALIGNED_ACCESS (word_mode, align))
3497               || align >= BIGGEST_ALIGNMENT
3498               || (PUSH_ROUNDING (align / BITS_PER_UNIT)
3499                   == (align / BITS_PER_UNIT)))
3500           && PUSH_ROUNDING (INTVAL (size)) == INTVAL (size))
3501         {
3502           /* Push padding now if padding above and stack grows down,
3503              or if padding below and stack grows up.
3504              But if space already allocated, this has already been done.  */
3505           if (extra && args_addr == 0
3506               && where_pad != none && where_pad != stack_direction)
3507             anti_adjust_stack (GEN_INT (extra));
3508
3509           move_by_pieces (NULL, xinner, INTVAL (size) - used, align, 0);
3510         }
3511       else
3512 #endif /* PUSH_ROUNDING  */
3513         {
3514           rtx target;
3515
3516           /* Otherwise make space on the stack and copy the data
3517              to the address of that space.  */
3518
3519           /* Deduct words put into registers from the size we must copy.  */
3520           if (partial != 0)
3521             {
3522               if (GET_CODE (size) == CONST_INT)
3523                 size = GEN_INT (INTVAL (size) - used);
3524               else
3525                 size = expand_binop (GET_MODE (size), sub_optab, size,
3526                                      GEN_INT (used), NULL_RTX, 0,
3527                                      OPTAB_LIB_WIDEN);
3528             }
3529
3530           /* Get the address of the stack space.
3531              In this case, we do not deal with EXTRA separately.
3532              A single stack adjust will do.  */
3533           if (! args_addr)
3534             {
3535               temp = push_block (size, extra, where_pad == downward);
3536               extra = 0;
3537             }
3538           else if (GET_CODE (args_so_far) == CONST_INT)
3539             temp = memory_address (BLKmode,
3540                                    plus_constant (args_addr,
3541                                                   skip + INTVAL (args_so_far)));
3542           else
3543             temp = memory_address (BLKmode,
3544                                    plus_constant (gen_rtx_PLUS (Pmode,
3545                                                                 args_addr,
3546                                                                 args_so_far),
3547                                                   skip));
3548
3549           if (!ACCUMULATE_OUTGOING_ARGS)
3550             {
3551               /* If the source is referenced relative to the stack pointer,
3552                  copy it to another register to stabilize it.  We do not need
3553                  to do this if we know that we won't be changing sp.  */
3554
3555               if (reg_mentioned_p (virtual_stack_dynamic_rtx, temp)
3556                   || reg_mentioned_p (virtual_outgoing_args_rtx, temp))
3557                 temp = copy_to_reg (temp);
3558             }
3559
3560           target = gen_rtx_MEM (BLKmode, temp);
3561
3562           if (type != 0)
3563             {
3564               set_mem_attributes (target, type, 1);
3565               /* Function incoming arguments may overlap with sibling call
3566                  outgoing arguments and we cannot allow reordering of reads
3567                  from function arguments with stores to outgoing arguments
3568                  of sibling calls.  */
3569               set_mem_alias_set (target, 0);
3570             }
3571
3572           /* ALIGN may well be better aligned than TYPE, e.g. due to
3573              PARM_BOUNDARY.  Assume the caller isn't lying.  */
3574           set_mem_align (target, align);
3575
3576           emit_block_move (target, xinner, size, BLOCK_OP_CALL_PARM);
3577         }
3578     }
3579   else if (partial > 0)
3580     {
3581       /* Scalar partly in registers.  */
3582
3583       int size = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
3584       int i;
3585       int not_stack;
3586       /* # words of start of argument
3587          that we must make space for but need not store.  */
3588       int offset = partial % (PARM_BOUNDARY / BITS_PER_WORD);
3589       int args_offset = INTVAL (args_so_far);
3590       int skip;
3591
3592       /* Push padding now if padding above and stack grows down,
3593          or if padding below and stack grows up.
3594          But if space already allocated, this has already been done.  */
3595       if (extra && args_addr == 0
3596           && where_pad != none && where_pad != stack_direction)
3597         anti_adjust_stack (GEN_INT (extra));
3598
3599       /* If we make space by pushing it, we might as well push
3600          the real data.  Otherwise, we can leave OFFSET nonzero
3601          and leave the space uninitialized.  */
3602       if (args_addr == 0)
3603         offset = 0;
3604
3605       /* Now NOT_STACK gets the number of words that we don't need to
3606          allocate on the stack.  */
3607       not_stack = partial - offset;
3608
3609       /* If the partial register-part of the arg counts in its stack size,
3610          skip the part of stack space corresponding to the registers.
3611          Otherwise, start copying to the beginning of the stack space,
3612          by setting SKIP to 0.  */
3613       skip = (reg_parm_stack_space == 0) ? 0 : not_stack;
3614
3615       if (CONSTANT_P (x) && ! LEGITIMATE_CONSTANT_P (x))
3616         x = validize_mem (force_const_mem (mode, x));
3617
3618       /* If X is a hard register in a non-integer mode, copy it into a pseudo;
3619          SUBREGs of such registers are not allowed.  */
3620       if ((GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER
3621            && GET_MODE_CLASS (GET_MODE (x)) != MODE_INT))
3622         x = copy_to_reg (x);
3623
3624       /* Loop over all the words allocated on the stack for this arg.  */
3625       /* We can do it by words, because any scalar bigger than a word
3626          has a size a multiple of a word.  */
3627 #ifndef PUSH_ARGS_REVERSED
3628       for (i = not_stack; i < size; i++)
3629 #else
3630       for (i = size - 1; i >= not_stack; i--)
3631 #endif
3632         if (i >= not_stack + offset)
3633           emit_push_insn (operand_subword_force (x, i, mode),
3634                           word_mode, NULL_TREE, NULL_RTX, align, 0, NULL_RTX,
3635                           0, args_addr,
3636                           GEN_INT (args_offset + ((i - not_stack + skip)
3637                                                   * UNITS_PER_WORD)),
3638                           reg_parm_stack_space, alignment_pad);
3639     }
3640   else
3641     {
3642       rtx addr;
3643       rtx dest;
3644
3645       /* Push padding now if padding above and stack grows down,
3646          or if padding below and stack grows up.
3647          But if space already allocated, this has already been done.  */
3648       if (extra && args_addr == 0
3649           && where_pad != none && where_pad != stack_direction)
3650         anti_adjust_stack (GEN_INT (extra));
3651
3652 #ifdef PUSH_ROUNDING
3653       if (args_addr == 0 && PUSH_ARGS)
3654         emit_single_push_insn (mode, x, type);
3655       else
3656 #endif
3657         {
3658           if (GET_CODE (args_so_far) == CONST_INT)
3659             addr
3660               = memory_address (mode,
3661                                 plus_constant (args_addr,
3662                                                INTVAL (args_so_far)));
3663           else
3664             addr = memory_address (mode, gen_rtx_PLUS (Pmode, args_addr,
3665                                                        args_so_far));
3666           dest = gen_rtx_MEM (mode, addr);
3667           if (type != 0)
3668             {
3669               set_mem_attributes (dest, type, 1);
3670               /* Function incoming arguments may overlap with sibling call
3671                  outgoing arguments and we cannot allow reordering of reads
3672                  from function arguments with stores to outgoing arguments
3673                  of sibling calls.  */
3674               set_mem_alias_set (dest, 0);
3675             }
3676
3677           emit_move_insn (dest, x);
3678         }
3679     }
3680
3681   /* If part should go in registers, copy that part
3682      into the appropriate registers.  Do this now, at the end,
3683      since mem-to-mem copies above may do function calls.  */
3684   if (partial > 0 && reg != 0)
3685     {
3686       /* Handle calls that pass values in multiple non-contiguous locations.
3687          The Irix 6 ABI has examples of this.  */
3688       if (GET_CODE (reg) == PARALLEL)
3689         emit_group_load (reg, x, type, -1);
3690       else
3691         move_block_to_reg (REGNO (reg), x, partial, mode);
3692     }
3693
3694   if (extra && args_addr == 0 && where_pad == stack_direction)
3695     anti_adjust_stack (GEN_INT (extra));
3696
3697   if (alignment_pad && args_addr == 0)
3698     anti_adjust_stack (alignment_pad);
3699 }
3700 \f
3701 /* Return X if X can be used as a subtarget in a sequence of arithmetic
3702    operations.  */
3703
3704 static rtx
3705 get_subtarget (rtx x)
3706 {
3707   return ((x == 0
3708            /* Only registers can be subtargets.  */
3709            || GET_CODE (x) != REG
3710            /* If the register is readonly, it can't be set more than once.  */
3711            || RTX_UNCHANGING_P (x)
3712            /* Don't use hard regs to avoid extending their life.  */
3713            || REGNO (x) < FIRST_PSEUDO_REGISTER
3714            /* Avoid subtargets inside loops,
3715               since they hide some invariant expressions.  */
3716            || preserve_subexpressions_p ())
3717           ? 0 : x);
3718 }
3719
3720 /* Expand an assignment that stores the value of FROM into TO.
3721    If WANT_VALUE is nonzero, return an rtx for the value of TO.
3722    (This may contain a QUEUED rtx;
3723    if the value is constant, this rtx is a constant.)
3724    Otherwise, the returned value is NULL_RTX.  */
3725
3726 rtx
3727 expand_assignment (tree to, tree from, int want_value)
3728 {
3729   rtx to_rtx = 0;
3730   rtx result;
3731
3732   /* Don't crash if the lhs of the assignment was erroneous.  */
3733
3734   if (TREE_CODE (to) == ERROR_MARK)
3735     {
3736       result = expand_expr (from, NULL_RTX, VOIDmode, 0);
3737       return want_value ? result : NULL_RTX;
3738     }
3739
3740   /* Assignment of a structure component needs special treatment
3741      if the structure component's rtx is not simply a MEM.
3742      Assignment of an array element at a constant index, and assignment of
3743      an array element in an unaligned packed structure field, has the same
3744      problem.  */
3745
3746   if (TREE_CODE (to) == COMPONENT_REF || TREE_CODE (to) == BIT_FIELD_REF
3747       || TREE_CODE (to) == ARRAY_REF || TREE_CODE (to) == ARRAY_RANGE_REF
3748       || TREE_CODE (TREE_TYPE (to)) == ARRAY_TYPE)
3749     {
3750       enum machine_mode mode1;
3751       HOST_WIDE_INT bitsize, bitpos;
3752       rtx orig_to_rtx;
3753       tree offset;
3754       int unsignedp;
3755       int volatilep = 0;
3756       tree tem;
3757
3758       push_temp_slots ();
3759       tem = get_inner_reference (to, &bitsize, &bitpos, &offset, &mode1,
3760                                  &unsignedp, &volatilep);
3761
3762       /* If we are going to use store_bit_field and extract_bit_field,
3763          make sure to_rtx will be safe for multiple use.  */
3764
3765       if (mode1 == VOIDmode && want_value)
3766         tem = stabilize_reference (tem);
3767
3768       orig_to_rtx = to_rtx = expand_expr (tem, NULL_RTX, VOIDmode, 0);
3769
3770       if (offset != 0)
3771         {
3772           rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, EXPAND_SUM);
3773
3774           if (GET_CODE (to_rtx) != MEM)
3775             abort ();
3776
3777 #ifdef POINTERS_EXTEND_UNSIGNED
3778           if (GET_MODE (offset_rtx) != Pmode)
3779             offset_rtx = convert_to_mode (Pmode, offset_rtx, 0);
3780 #else
3781           if (GET_MODE (offset_rtx) != ptr_mode)
3782             offset_rtx = convert_to_mode (ptr_mode, offset_rtx, 0);
3783 #endif
3784
3785           /* A constant address in TO_RTX can have VOIDmode, we must not try
3786              to call force_reg for that case.  Avoid that case.  */
3787           if (GET_CODE (to_rtx) == MEM
3788               && GET_MODE (to_rtx) == BLKmode
3789               && GET_MODE (XEXP (to_rtx, 0)) != VOIDmode
3790               && bitsize > 0
3791               && (bitpos % bitsize) == 0
3792               && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
3793               && MEM_ALIGN (to_rtx) == GET_MODE_ALIGNMENT (mode1))
3794             {
3795               to_rtx = adjust_address (to_rtx, mode1, bitpos / BITS_PER_UNIT);
3796               bitpos = 0;
3797             }
3798
3799           to_rtx = offset_address (to_rtx, offset_rtx,
3800                                    highest_pow2_factor_for_target (to,
3801                                                                    offset));
3802         }
3803
3804       if (GET_CODE (to_rtx) == MEM)
3805         {
3806           /* If the field is at offset zero, we could have been given the
3807              DECL_RTX of the parent struct.  Don't munge it.  */
3808           to_rtx = shallow_copy_rtx (to_rtx);
3809
3810           set_mem_attributes_minus_bitpos (to_rtx, to, 0, bitpos);
3811         }
3812
3813       /* Deal with volatile and readonly fields.  The former is only done
3814          for MEM.  Also set MEM_KEEP_ALIAS_SET_P if needed.  */
3815       if (volatilep && GET_CODE (to_rtx) == MEM)
3816         {
3817           if (to_rtx == orig_to_rtx)
3818             to_rtx = copy_rtx (to_rtx);
3819           MEM_VOLATILE_P (to_rtx) = 1;
3820         }
3821
3822       if (TREE_CODE (to) == COMPONENT_REF
3823           && TREE_READONLY (TREE_OPERAND (to, 1))
3824           /* We can't assert that a MEM won't be set more than once
3825              if the component is not addressable because another
3826              non-addressable component may be referenced by the same MEM.  */
3827           && ! (GET_CODE (to_rtx) == MEM && ! can_address_p (to)))
3828         {
3829           if (to_rtx == orig_to_rtx)
3830             to_rtx = copy_rtx (to_rtx);
3831           RTX_UNCHANGING_P (to_rtx) = 1;
3832         }
3833
3834       if (GET_CODE (to_rtx) == MEM && ! can_address_p (to))
3835         {
3836           if (to_rtx == orig_to_rtx)
3837             to_rtx = copy_rtx (to_rtx);
3838           MEM_KEEP_ALIAS_SET_P (to_rtx) = 1;
3839         }
3840
3841       result = store_field (to_rtx, bitsize, bitpos, mode1, from,
3842                             (want_value
3843                              /* Spurious cast for HPUX compiler.  */
3844                              ? ((enum machine_mode)
3845                                 TYPE_MODE (TREE_TYPE (to)))
3846                              : VOIDmode),
3847                             unsignedp, TREE_TYPE (tem), get_alias_set (to));
3848
3849       preserve_temp_slots (result);
3850       free_temp_slots ();
3851       pop_temp_slots ();
3852
3853       /* If the value is meaningful, convert RESULT to the proper mode.
3854          Otherwise, return nothing.  */
3855       return (want_value ? convert_modes (TYPE_MODE (TREE_TYPE (to)),
3856                                           TYPE_MODE (TREE_TYPE (from)),
3857                                           result,
3858                                           TREE_UNSIGNED (TREE_TYPE (to)))
3859               : NULL_RTX);
3860     }
3861
3862   /* If the rhs is a function call and its value is not an aggregate,
3863      call the function before we start to compute the lhs.
3864      This is needed for correct code for cases such as
3865      val = setjmp (buf) on machines where reference to val
3866      requires loading up part of an address in a separate insn.
3867
3868      Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
3869      since it might be a promoted variable where the zero- or sign- extension
3870      needs to be done.  Handling this in the normal way is safe because no
3871      computation is done before the call.  */
3872   if (TREE_CODE (from) == CALL_EXPR && ! aggregate_value_p (from, from)
3873       && TREE_CODE (TYPE_SIZE (TREE_TYPE (from))) == INTEGER_CST
3874       && ! ((TREE_CODE (to) == VAR_DECL || TREE_CODE (to) == PARM_DECL)
3875             && GET_CODE (DECL_RTL (to)) == REG))
3876     {
3877       rtx value;
3878
3879       push_temp_slots ();
3880       value = expand_expr (from, NULL_RTX, VOIDmode, 0);
3881       if (to_rtx == 0)
3882         to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
3883
3884       /* Handle calls that return values in multiple non-contiguous locations.
3885          The Irix 6 ABI has examples of this.  */
3886       if (GET_CODE (to_rtx) == PARALLEL)
3887         emit_group_load (to_rtx, value, TREE_TYPE (from),
3888                          int_size_in_bytes (TREE_TYPE (from)));
3889       else if (GET_MODE (to_rtx) == BLKmode)
3890         emit_block_move (to_rtx, value, expr_size (from), BLOCK_OP_NORMAL);
3891       else
3892         {
3893           if (POINTER_TYPE_P (TREE_TYPE (to)))
3894             value = convert_memory_address (GET_MODE (to_rtx), value);
3895           emit_move_insn (to_rtx, value);
3896         }
3897       preserve_temp_slots (to_rtx);
3898       free_temp_slots ();
3899       pop_temp_slots ();
3900       return want_value ? to_rtx : NULL_RTX;
3901     }
3902
3903   /* Ordinary treatment.  Expand TO to get a REG or MEM rtx.
3904      Don't re-expand if it was expanded already (in COMPONENT_REF case).  */
3905
3906   if (to_rtx == 0)
3907     to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
3908
3909   /* Don't move directly into a return register.  */
3910   if (TREE_CODE (to) == RESULT_DECL
3911       && (GET_CODE (to_rtx) == REG || GET_CODE (to_rtx) == PARALLEL))
3912     {
3913       rtx temp;
3914
3915       push_temp_slots ();
3916       temp = expand_expr (from, 0, GET_MODE (to_rtx), 0);
3917
3918       if (GET_CODE (to_rtx) == PARALLEL)
3919         emit_group_load (to_rtx, temp, TREE_TYPE (from),
3920                          int_size_in_bytes (TREE_TYPE (from)));
3921       else
3922         emit_move_insn (to_rtx, temp);
3923
3924       preserve_temp_slots (to_rtx);
3925       free_temp_slots ();
3926       pop_temp_slots ();
3927       return want_value ? to_rtx : NULL_RTX;
3928     }
3929
3930   /* In case we are returning the contents of an object which overlaps
3931      the place the value is being stored, use a safe function when copying
3932      a value through a pointer into a structure value return block.  */
3933   if (TREE_CODE (to) == RESULT_DECL && TREE_CODE (from) == INDIRECT_REF
3934       && current_function_returns_struct
3935       && !current_function_returns_pcc_struct)
3936     {
3937       rtx from_rtx, size;
3938
3939       push_temp_slots ();
3940       size = expr_size (from);
3941       from_rtx = expand_expr (from, NULL_RTX, VOIDmode, 0);
3942
3943       if (TARGET_MEM_FUNCTIONS)
3944         emit_library_call (memmove_libfunc, LCT_NORMAL,
3945                            VOIDmode, 3, XEXP (to_rtx, 0), Pmode,
3946                            XEXP (from_rtx, 0), Pmode,
3947                            convert_to_mode (TYPE_MODE (sizetype),
3948                                             size, TREE_UNSIGNED (sizetype)),
3949                            TYPE_MODE (sizetype));
3950       else
3951         emit_library_call (bcopy_libfunc, LCT_NORMAL,
3952                            VOIDmode, 3, XEXP (from_rtx, 0), Pmode,
3953                            XEXP (to_rtx, 0), Pmode,
3954                            convert_to_mode (TYPE_MODE (integer_type_node),
3955                                             size,
3956                                             TREE_UNSIGNED (integer_type_node)),
3957                            TYPE_MODE (integer_type_node));
3958
3959       preserve_temp_slots (to_rtx);
3960       free_temp_slots ();
3961       pop_temp_slots ();
3962       return want_value ? to_rtx : NULL_RTX;
3963     }
3964
3965   /* Compute FROM and store the value in the rtx we got.  */
3966
3967   push_temp_slots ();
3968   result = store_expr (from, to_rtx, want_value);
3969   preserve_temp_slots (result);
3970   free_temp_slots ();
3971   pop_temp_slots ();
3972   return want_value ? result : NULL_RTX;
3973 }
3974
3975 /* Generate code for computing expression EXP,
3976    and storing the value into TARGET.
3977    TARGET may contain a QUEUED rtx.
3978
3979    If WANT_VALUE & 1 is nonzero, return a copy of the value
3980    not in TARGET, so that we can be sure to use the proper
3981    value in a containing expression even if TARGET has something
3982    else stored in it.  If possible, we copy the value through a pseudo
3983    and return that pseudo.  Or, if the value is constant, we try to
3984    return the constant.  In some cases, we return a pseudo
3985    copied *from* TARGET.
3986
3987    If the mode is BLKmode then we may return TARGET itself.
3988    It turns out that in BLKmode it doesn't cause a problem.
3989    because C has no operators that could combine two different
3990    assignments into the same BLKmode object with different values
3991    with no sequence point.  Will other languages need this to
3992    be more thorough?
3993
3994    If WANT_VALUE & 1 is 0, we return NULL, to make sure
3995    to catch quickly any cases where the caller uses the value
3996    and fails to set WANT_VALUE.
3997
3998    If WANT_VALUE & 2 is set, this is a store into a call param on the
3999    stack, and block moves may need to be treated specially.  */
4000
4001 rtx
4002 store_expr (tree exp, rtx target, int want_value)
4003 {
4004   rtx temp;
4005   rtx alt_rtl = NULL_RTX;
4006   int dont_return_target = 0;
4007   int dont_store_target = 0;
4008
4009   if (VOID_TYPE_P (TREE_TYPE (exp)))
4010     {
4011       /* C++ can generate ?: expressions with a throw expression in one
4012          branch and an rvalue in the other. Here, we resolve attempts to
4013          store the throw expression's nonexistent result.  */
4014       if (want_value)
4015         abort ();
4016       expand_expr (exp, const0_rtx, VOIDmode, 0);
4017       return NULL_RTX;
4018     }
4019   if (TREE_CODE (exp) == COMPOUND_EXPR)
4020     {
4021       /* Perform first part of compound expression, then assign from second
4022          part.  */
4023       expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
4024                    want_value & 2 ? EXPAND_STACK_PARM : EXPAND_NORMAL);
4025       emit_queue ();
4026       return store_expr (TREE_OPERAND (exp, 1), target, want_value);
4027     }
4028   else if (TREE_CODE (exp) == COND_EXPR && GET_MODE (target) == BLKmode)
4029     {
4030       /* For conditional expression, get safe form of the target.  Then
4031          test the condition, doing the appropriate assignment on either
4032          side.  This avoids the creation of unnecessary temporaries.
4033          For non-BLKmode, it is more efficient not to do this.  */
4034
4035       rtx lab1 = gen_label_rtx (), lab2 = gen_label_rtx ();
4036
4037       emit_queue ();
4038       target = protect_from_queue (target, 1);
4039
4040       do_pending_stack_adjust ();
4041       NO_DEFER_POP;
4042       jumpifnot (TREE_OPERAND (exp, 0), lab1);
4043       start_cleanup_deferral ();
4044       store_expr (TREE_OPERAND (exp, 1), target, want_value & 2);
4045       end_cleanup_deferral ();
4046       emit_queue ();
4047       emit_jump_insn (gen_jump (lab2));
4048       emit_barrier ();
4049       emit_label (lab1);
4050       start_cleanup_deferral ();
4051       store_expr (TREE_OPERAND (exp, 2), target, want_value & 2);
4052       end_cleanup_deferral ();
4053       emit_queue ();
4054       emit_label (lab2);
4055       OK_DEFER_POP;
4056
4057       return want_value & 1 ? target : NULL_RTX;
4058     }
4059   else if (queued_subexp_p (target))
4060     /* If target contains a postincrement, let's not risk
4061        using it as the place to generate the rhs.  */
4062     {
4063       if (GET_MODE (target) != BLKmode && GET_MODE (target) != VOIDmode)
4064         {
4065           /* Expand EXP into a new pseudo.  */
4066           temp = gen_reg_rtx (GET_MODE (target));
4067           temp = expand_expr (exp, temp, GET_MODE (target),
4068                               (want_value & 2
4069                                ? EXPAND_STACK_PARM : EXPAND_NORMAL));
4070         }
4071       else
4072         temp = expand_expr (exp, NULL_RTX, GET_MODE (target),
4073                             (want_value & 2
4074                              ? EXPAND_STACK_PARM : EXPAND_NORMAL));
4075
4076       /* If target is volatile, ANSI requires accessing the value
4077          *from* the target, if it is accessed.  So make that happen.
4078          In no case return the target itself.  */
4079       if (! MEM_VOLATILE_P (target) && (want_value & 1) != 0)
4080         dont_return_target = 1;
4081     }
4082   else if ((want_value & 1) != 0
4083            && GET_CODE (target) == MEM
4084            && ! MEM_VOLATILE_P (target)
4085            && GET_MODE (target) != BLKmode)
4086     /* If target is in memory and caller wants value in a register instead,
4087        arrange that.  Pass TARGET as target for expand_expr so that,
4088        if EXP is another assignment, WANT_VALUE will be nonzero for it.
4089        We know expand_expr will not use the target in that case.
4090        Don't do this if TARGET is volatile because we are supposed
4091        to write it and then read it.  */
4092     {
4093       temp = expand_expr (exp, target, GET_MODE (target),
4094                           want_value & 2 ? EXPAND_STACK_PARM : EXPAND_NORMAL);
4095       if (GET_MODE (temp) != BLKmode && GET_MODE (temp) != VOIDmode)
4096         {
4097           /* If TEMP is already in the desired TARGET, only copy it from
4098              memory and don't store it there again.  */
4099           if (temp == target
4100               || (rtx_equal_p (temp, target)
4101                   && ! side_effects_p (temp) && ! side_effects_p (target)))
4102             dont_store_target = 1;
4103           temp = copy_to_reg (temp);
4104         }
4105       dont_return_target = 1;
4106     }
4107   else if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target))
4108     /* If this is a scalar in a register that is stored in a wider mode
4109        than the declared mode, compute the result into its declared mode
4110        and then convert to the wider mode.  Our value is the computed
4111        expression.  */
4112     {
4113       rtx inner_target = 0;
4114
4115       /* If we don't want a value, we can do the conversion inside EXP,
4116          which will often result in some optimizations.  Do the conversion
4117          in two steps: first change the signedness, if needed, then
4118          the extend.  But don't do this if the type of EXP is a subtype
4119          of something else since then the conversion might involve
4120          more than just converting modes.  */
4121       if ((want_value & 1) == 0
4122           && INTEGRAL_TYPE_P (TREE_TYPE (exp))
4123           && TREE_TYPE (TREE_TYPE (exp)) == 0)
4124         {
4125           if (TREE_UNSIGNED (TREE_TYPE (exp))
4126               != SUBREG_PROMOTED_UNSIGNED_P (target))
4127             exp = convert
4128               (lang_hooks.types.signed_or_unsigned_type
4129                (SUBREG_PROMOTED_UNSIGNED_P (target), TREE_TYPE (exp)), exp);
4130
4131           exp = convert (lang_hooks.types.type_for_mode
4132                          (GET_MODE (SUBREG_REG (target)),
4133                           SUBREG_PROMOTED_UNSIGNED_P (target)),
4134                          exp);
4135
4136           inner_target = SUBREG_REG (target);
4137         }
4138
4139       temp = expand_expr (exp, inner_target, VOIDmode,
4140                           want_value & 2 ? EXPAND_STACK_PARM : EXPAND_NORMAL);
4141
4142       /* If TEMP is a MEM and we want a result value, make the access
4143          now so it gets done only once.  Strictly speaking, this is
4144          only necessary if the MEM is volatile, or if the address
4145          overlaps TARGET.  But not performing the load twice also
4146          reduces the amount of rtl we generate and then have to CSE.  */
4147       if (GET_CODE (temp) == MEM && (want_value & 1) != 0)
4148         temp = copy_to_reg (temp);
4149
4150       /* If TEMP is a VOIDmode constant, use convert_modes to make
4151          sure that we properly convert it.  */
4152       if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode)
4153         {
4154           temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
4155                                 temp, SUBREG_PROMOTED_UNSIGNED_P (target));
4156           temp = convert_modes (GET_MODE (SUBREG_REG (target)),
4157                                 GET_MODE (target), temp,
4158                                 SUBREG_PROMOTED_UNSIGNED_P (target));
4159         }
4160
4161       convert_move (SUBREG_REG (target), temp,
4162                     SUBREG_PROMOTED_UNSIGNED_P (target));
4163
4164       /* If we promoted a constant, change the mode back down to match
4165          target.  Otherwise, the caller might get confused by a result whose
4166          mode is larger than expected.  */
4167
4168       if ((want_value & 1) != 0 && GET_MODE (temp) != GET_MODE (target))
4169         {
4170           if (GET_MODE (temp) != VOIDmode)
4171             {
4172               temp = gen_lowpart_SUBREG (GET_MODE (target), temp);
4173               SUBREG_PROMOTED_VAR_P (temp) = 1;
4174               SUBREG_PROMOTED_UNSIGNED_SET (temp,
4175                 SUBREG_PROMOTED_UNSIGNED_P (target));
4176             }
4177           else
4178             temp = convert_modes (GET_MODE (target),
4179                                   GET_MODE (SUBREG_REG (target)),
4180                                   temp, SUBREG_PROMOTED_UNSIGNED_P (target));
4181         }
4182
4183       return want_value & 1 ? temp : NULL_RTX;
4184     }
4185   else
4186     {
4187       temp = expand_expr_real (exp, target, GET_MODE (target),
4188                                (want_value & 2 
4189                                 ? EXPAND_STACK_PARM : EXPAND_NORMAL),
4190                                &alt_rtl);
4191       /* Return TARGET if it's a specified hardware register.
4192          If TARGET is a volatile mem ref, either return TARGET
4193          or return a reg copied *from* TARGET; ANSI requires this.
4194
4195          Otherwise, if TEMP is not TARGET, return TEMP
4196          if it is constant (for efficiency),
4197          or if we really want the correct value.  */
4198       if (!(target && GET_CODE (target) == REG
4199             && REGNO (target) < FIRST_PSEUDO_REGISTER)
4200           && !(GET_CODE (target) == MEM && MEM_VOLATILE_P (target))
4201           && ! rtx_equal_p (temp, target)
4202           && (CONSTANT_P (temp) || (want_value & 1) != 0))
4203         dont_return_target = 1;
4204     }
4205
4206   /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
4207      the same as that of TARGET, adjust the constant.  This is needed, for
4208      example, in case it is a CONST_DOUBLE and we want only a word-sized
4209      value.  */
4210   if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode
4211       && TREE_CODE (exp) != ERROR_MARK
4212       && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
4213     temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
4214                           temp, TREE_UNSIGNED (TREE_TYPE (exp)));
4215
4216   /* If value was not generated in the target, store it there.
4217      Convert the value to TARGET's type first if necessary.
4218      If TEMP and TARGET compare equal according to rtx_equal_p, but
4219      one or both of them are volatile memory refs, we have to distinguish
4220      two cases:
4221      - expand_expr has used TARGET.  In this case, we must not generate
4222        another copy.  This can be detected by TARGET being equal according
4223        to == .
4224      - expand_expr has not used TARGET - that means that the source just
4225        happens to have the same RTX form.  Since temp will have been created
4226        by expand_expr, it will compare unequal according to == .
4227        We must generate a copy in this case, to reach the correct number
4228        of volatile memory references.  */
4229
4230   if ((! rtx_equal_p (temp, target)
4231        || (temp != target && (side_effects_p (temp)
4232                               || side_effects_p (target))))
4233       && TREE_CODE (exp) != ERROR_MARK
4234       && ! dont_store_target
4235       /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
4236          but TARGET is not valid memory reference, TEMP will differ
4237          from TARGET although it is really the same location.  */
4238       && !(alt_rtl && rtx_equal_p (alt_rtl, target))
4239       /* If there's nothing to copy, don't bother.  Don't call expr_size
4240          unless necessary, because some front-ends (C++) expr_size-hook
4241          aborts on objects that are not supposed to be bit-copied or
4242          bit-initialized.  */
4243       && expr_size (exp) != const0_rtx)
4244     {
4245       emit_queue();
4246       target = protect_from_queue (target, 1);
4247       temp = protect_from_queue (temp, 0);
4248       if (GET_MODE (temp) != GET_MODE (target)
4249           && GET_MODE (temp) != VOIDmode)
4250         {
4251           int unsignedp = TREE_UNSIGNED (TREE_TYPE (exp));
4252           if (dont_return_target)
4253             {
4254               /* In this case, we will return TEMP,
4255                  so make sure it has the proper mode.
4256                  But don't forget to store the value into TARGET.  */
4257               temp = convert_to_mode (GET_MODE (target), temp, unsignedp);
4258               emit_move_insn (target, temp);
4259             }
4260           else
4261             convert_move (target, temp, unsignedp);
4262         }
4263
4264       else if (GET_MODE (temp) == BLKmode && TREE_CODE (exp) == STRING_CST)
4265         {
4266           /* Handle copying a string constant into an array.  The string
4267              constant may be shorter than the array.  So copy just the string's
4268              actual length, and clear the rest.  First get the size of the data
4269              type of the string, which is actually the size of the target.  */
4270           rtx size = expr_size (exp);
4271
4272           if (GET_CODE (size) == CONST_INT
4273               && INTVAL (size) < TREE_STRING_LENGTH (exp))
4274             emit_block_move (target, temp, size,
4275                              (want_value & 2
4276                               ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
4277           else
4278             {
4279               /* Compute the size of the data to copy from the string.  */
4280               tree copy_size
4281                 = size_binop (MIN_EXPR,
4282                               make_tree (sizetype, size),
4283                               size_int (TREE_STRING_LENGTH (exp)));
4284               rtx copy_size_rtx
4285                 = expand_expr (copy_size, NULL_RTX, VOIDmode,
4286                                (want_value & 2
4287                                 ? EXPAND_STACK_PARM : EXPAND_NORMAL));
4288               rtx label = 0;
4289
4290               /* Copy that much.  */
4291               copy_size_rtx = convert_to_mode (ptr_mode, copy_size_rtx,
4292                                                TREE_UNSIGNED (sizetype));
4293               emit_block_move (target, temp, copy_size_rtx,
4294                                (want_value & 2
4295                                 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
4296
4297               /* Figure out how much is left in TARGET that we have to clear.
4298                  Do all calculations in ptr_mode.  */
4299               if (GET_CODE (copy_size_rtx) == CONST_INT)
4300                 {
4301                   size = plus_constant (size, -INTVAL (copy_size_rtx));
4302                   target = adjust_address (target, BLKmode,
4303                                            INTVAL (copy_size_rtx));
4304                 }
4305               else
4306                 {
4307                   size = expand_binop (TYPE_MODE (sizetype), sub_optab, size,
4308                                        copy_size_rtx, NULL_RTX, 0,
4309                                        OPTAB_LIB_WIDEN);
4310
4311 #ifdef POINTERS_EXTEND_UNSIGNED
4312                   if (GET_MODE (copy_size_rtx) != Pmode)
4313                     copy_size_rtx = convert_to_mode (Pmode, copy_size_rtx,
4314                                                      TREE_UNSIGNED (sizetype));
4315 #endif
4316
4317                   target = offset_address (target, copy_size_rtx,
4318                                            highest_pow2_factor (copy_size));
4319                   label = gen_label_rtx ();
4320                   emit_cmp_and_jump_insns (size, const0_rtx, LT, NULL_RTX,
4321                                            GET_MODE (size), 0, label);
4322                 }
4323
4324               if (size != const0_rtx)
4325                 clear_storage (target, size);
4326
4327               if (label)
4328                 emit_label (label);
4329             }
4330         }
4331       /* Handle calls that return values in multiple non-contiguous locations.
4332          The Irix 6 ABI has examples of this.  */
4333       else if (GET_CODE (target) == PARALLEL)
4334         emit_group_load (target, temp, TREE_TYPE (exp),
4335                          int_size_in_bytes (TREE_TYPE (exp)));
4336       else if (GET_MODE (temp) == BLKmode)
4337         emit_block_move (target, temp, expr_size (exp),
4338                          (want_value & 2
4339                           ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
4340       else
4341         {
4342           temp = force_operand (temp, target);
4343           if (temp != target)
4344             emit_move_insn (target, temp);
4345         }
4346     }
4347
4348   /* If we don't want a value, return NULL_RTX.  */
4349   if ((want_value & 1) == 0)
4350     return NULL_RTX;
4351
4352   /* If we are supposed to return TEMP, do so as long as it isn't a MEM.
4353      ??? The latter test doesn't seem to make sense.  */
4354   else if (dont_return_target && GET_CODE (temp) != MEM)
4355     return temp;
4356
4357   /* Return TARGET itself if it is a hard register.  */
4358   else if ((want_value & 1) != 0
4359            && GET_MODE (target) != BLKmode
4360            && ! (GET_CODE (target) == REG
4361                  && REGNO (target) < FIRST_PSEUDO_REGISTER))
4362     return copy_to_reg (target);
4363
4364   else
4365     return target;
4366 }
4367 \f
4368 /* Return 1 if EXP just contains zeros.  FIXME merge with initializer_zerop.  */
4369
4370 static int
4371 is_zeros_p (tree exp)
4372 {
4373   tree elt;
4374
4375   switch (TREE_CODE (exp))
4376     {
4377     case CONVERT_EXPR:
4378     case NOP_EXPR:
4379     case NON_LVALUE_EXPR:
4380     case VIEW_CONVERT_EXPR:
4381       return is_zeros_p (TREE_OPERAND (exp, 0));
4382
4383     case INTEGER_CST:
4384       return integer_zerop (exp);
4385
4386     case COMPLEX_CST:
4387       return
4388         is_zeros_p (TREE_REALPART (exp)) && is_zeros_p (TREE_IMAGPART (exp));
4389
4390     case REAL_CST:
4391       return REAL_VALUES_IDENTICAL (TREE_REAL_CST (exp), dconst0);
4392
4393     case VECTOR_CST:
4394       for (elt = TREE_VECTOR_CST_ELTS (exp); elt;
4395            elt = TREE_CHAIN (elt))
4396         if (!is_zeros_p (TREE_VALUE (elt)))
4397           return 0;
4398
4399       return 1;
4400
4401     case CONSTRUCTOR:
4402       if (TREE_TYPE (exp) && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
4403         return CONSTRUCTOR_ELTS (exp) == NULL_TREE;
4404       for (elt = CONSTRUCTOR_ELTS (exp); elt; elt = TREE_CHAIN (elt))
4405         if (! is_zeros_p (TREE_VALUE (elt)))
4406           return 0;
4407
4408       return 1;
4409
4410     default:
4411       return 0;
4412     }
4413 }
4414
4415 /* Return 1 if EXP contains mostly (3/4)  zeros.  */
4416
4417 int
4418 mostly_zeros_p (tree exp)
4419 {
4420   if (TREE_CODE (exp) == CONSTRUCTOR)
4421     {
4422       int elts = 0, zeros = 0;
4423       tree elt = CONSTRUCTOR_ELTS (exp);
4424       if (TREE_TYPE (exp) && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
4425         {
4426           /* If there are no ranges of true bits, it is all zero.  */
4427           return elt == NULL_TREE;
4428         }
4429       for (; elt; elt = TREE_CHAIN (elt))
4430         {
4431           /* We do not handle the case where the index is a RANGE_EXPR,
4432              so the statistic will be somewhat inaccurate.
4433              We do make a more accurate count in store_constructor itself,
4434              so since this function is only used for nested array elements,
4435              this should be close enough.  */
4436           if (mostly_zeros_p (TREE_VALUE (elt)))
4437             zeros++;
4438           elts++;
4439         }
4440
4441       return 4 * zeros >= 3 * elts;
4442     }
4443
4444   return is_zeros_p (exp);
4445 }
4446 \f
4447 /* Helper function for store_constructor.
4448    TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
4449    TYPE is the type of the CONSTRUCTOR, not the element type.
4450    CLEARED is as for store_constructor.
4451    ALIAS_SET is the alias set to use for any stores.
4452
4453    This provides a recursive shortcut back to store_constructor when it isn't
4454    necessary to go through store_field.  This is so that we can pass through
4455    the cleared field to let store_constructor know that we may not have to
4456    clear a substructure if the outer structure has already been cleared.  */
4457
4458 static void
4459 store_constructor_field (rtx target, unsigned HOST_WIDE_INT bitsize,
4460                          HOST_WIDE_INT bitpos, enum machine_mode mode,
4461                          tree exp, tree type, int cleared, int alias_set)
4462 {
4463   if (TREE_CODE (exp) == CONSTRUCTOR
4464       && bitpos % BITS_PER_UNIT == 0
4465       /* If we have a nonzero bitpos for a register target, then we just
4466          let store_field do the bitfield handling.  This is unlikely to
4467          generate unnecessary clear instructions anyways.  */
4468       && (bitpos == 0 || GET_CODE (target) == MEM))
4469     {
4470       if (GET_CODE (target) == MEM)
4471         target
4472           = adjust_address (target,
4473                             GET_MODE (target) == BLKmode
4474                             || 0 != (bitpos
4475                                      % GET_MODE_ALIGNMENT (GET_MODE (target)))
4476                             ? BLKmode : VOIDmode, bitpos / BITS_PER_UNIT);
4477
4478
4479       /* Update the alias set, if required.  */
4480       if (GET_CODE (target) == MEM && ! MEM_KEEP_ALIAS_SET_P (target)
4481           && MEM_ALIAS_SET (target) != 0)
4482         {
4483           target = copy_rtx (target);
4484           set_mem_alias_set (target, alias_set);
4485         }
4486
4487       store_constructor (exp, target, cleared, bitsize / BITS_PER_UNIT);
4488     }
4489   else
4490     store_field (target, bitsize, bitpos, mode, exp, VOIDmode, 0, type,
4491                  alias_set);
4492 }
4493
4494 /* Store the value of constructor EXP into the rtx TARGET.
4495    TARGET is either a REG or a MEM; we know it cannot conflict, since
4496    safe_from_p has been called.
4497    CLEARED is true if TARGET is known to have been zero'd.
4498    SIZE is the number of bytes of TARGET we are allowed to modify: this
4499    may not be the same as the size of EXP if we are assigning to a field
4500    which has been packed to exclude padding bits.  */
4501
4502 static void
4503 store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size)
4504 {
4505   tree type = TREE_TYPE (exp);
4506 #ifdef WORD_REGISTER_OPERATIONS
4507   HOST_WIDE_INT exp_size = int_size_in_bytes (type);
4508 #endif
4509
4510   if (TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
4511       || TREE_CODE (type) == QUAL_UNION_TYPE)
4512     {
4513       tree elt;
4514
4515       /* If size is zero or the target is already cleared, do nothing.  */
4516       if (size == 0 || cleared)
4517         cleared = 1;
4518       /* We either clear the aggregate or indicate the value is dead.  */
4519       else if ((TREE_CODE (type) == UNION_TYPE
4520                 || TREE_CODE (type) == QUAL_UNION_TYPE)
4521                && ! CONSTRUCTOR_ELTS (exp))
4522         /* If the constructor is empty, clear the union.  */
4523         {
4524           clear_storage (target, expr_size (exp));
4525           cleared = 1;
4526         }
4527
4528       /* If we are building a static constructor into a register,
4529          set the initial value as zero so we can fold the value into
4530          a constant.  But if more than one register is involved,
4531          this probably loses.  */
4532       else if (GET_CODE (target) == REG && TREE_STATIC (exp)
4533                && GET_MODE_SIZE (GET_MODE (target)) <= UNITS_PER_WORD)
4534         {
4535           emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
4536           cleared = 1;
4537         }
4538
4539       /* If the constructor has fewer fields than the structure
4540          or if we are initializing the structure to mostly zeros,
4541          clear the whole structure first.  Don't do this if TARGET is a
4542          register whose mode size isn't equal to SIZE since clear_storage
4543          can't handle this case.  */
4544       else if (((list_length (CONSTRUCTOR_ELTS (exp)) != fields_length (type))
4545                 || mostly_zeros_p (exp))
4546                && (GET_CODE (target) != REG
4547                    || ((HOST_WIDE_INT) GET_MODE_SIZE (GET_MODE (target))
4548                        == size)))
4549         {
4550           rtx xtarget = target;
4551
4552           if (readonly_fields_p (type))
4553             {
4554               xtarget = copy_rtx (xtarget);
4555               RTX_UNCHANGING_P (xtarget) = 1;
4556             }
4557
4558           clear_storage (xtarget, GEN_INT (size));
4559           cleared = 1;
4560         }
4561
4562       if (! cleared)
4563         emit_insn (gen_rtx_CLOBBER (VOIDmode, target));
4564
4565       /* Store each element of the constructor into
4566          the corresponding field of TARGET.  */
4567
4568       for (elt = CONSTRUCTOR_ELTS (exp); elt; elt = TREE_CHAIN (elt))
4569         {
4570           tree field = TREE_PURPOSE (elt);
4571           tree value = TREE_VALUE (elt);
4572           enum machine_mode mode;
4573           HOST_WIDE_INT bitsize;
4574           HOST_WIDE_INT bitpos = 0;
4575           tree offset;
4576           rtx to_rtx = target;
4577
4578           /* Just ignore missing fields.
4579              We cleared the whole structure, above,
4580              if any fields are missing.  */
4581           if (field == 0)
4582             continue;
4583
4584           if (cleared && is_zeros_p (value))
4585             continue;
4586
4587           if (host_integerp (DECL_SIZE (field), 1))
4588             bitsize = tree_low_cst (DECL_SIZE (field), 1);
4589           else
4590             bitsize = -1;
4591
4592           mode = DECL_MODE (field);
4593           if (DECL_BIT_FIELD (field))
4594             mode = VOIDmode;
4595
4596           offset = DECL_FIELD_OFFSET (field);
4597           if (host_integerp (offset, 0)
4598               && host_integerp (bit_position (field), 0))
4599             {
4600               bitpos = int_bit_position (field);
4601               offset = 0;
4602             }
4603           else
4604             bitpos = tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 0);
4605
4606           if (offset)
4607             {
4608               rtx offset_rtx;
4609
4610               offset
4611                 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset,
4612                                                   make_tree (TREE_TYPE (exp),
4613                                                              target));
4614
4615               offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, 0);
4616               if (GET_CODE (to_rtx) != MEM)
4617                 abort ();
4618
4619 #ifdef POINTERS_EXTEND_UNSIGNED
4620               if (GET_MODE (offset_rtx) != Pmode)
4621                 offset_rtx = convert_to_mode (Pmode, offset_rtx, 0);
4622 #else
4623               if (GET_MODE (offset_rtx) != ptr_mode)
4624                 offset_rtx = convert_to_mode (ptr_mode, offset_rtx, 0);
4625 #endif
4626
4627               to_rtx = offset_address (to_rtx, offset_rtx,
4628                                        highest_pow2_factor (offset));
4629             }
4630
4631           if (TREE_READONLY (field))
4632             {
4633               if (GET_CODE (to_rtx) == MEM)
4634                 to_rtx = copy_rtx (to_rtx);
4635
4636               RTX_UNCHANGING_P (to_rtx) = 1;
4637             }
4638
4639 #ifdef WORD_REGISTER_OPERATIONS
4640           /* If this initializes a field that is smaller than a word, at the
4641              start of a word, try to widen it to a full word.
4642              This special case allows us to output C++ member function
4643              initializations in a form that the optimizers can understand.  */
4644           if (GET_CODE (target) == REG
4645               && bitsize < BITS_PER_WORD
4646               && bitpos % BITS_PER_WORD == 0
4647               && GET_MODE_CLASS (mode) == MODE_INT
4648               && TREE_CODE (value) == INTEGER_CST
4649               && exp_size >= 0
4650               && bitpos + BITS_PER_WORD <= exp_size * BITS_PER_UNIT)
4651             {
4652               tree type = TREE_TYPE (value);
4653
4654               if (TYPE_PRECISION (type) < BITS_PER_WORD)
4655                 {
4656                   type = lang_hooks.types.type_for_size
4657                     (BITS_PER_WORD, TREE_UNSIGNED (type));
4658                   value = convert (type, value);
4659                 }
4660
4661               if (BYTES_BIG_ENDIAN)
4662                 value
4663                   = fold (build (LSHIFT_EXPR, type, value,
4664                                  build_int_2 (BITS_PER_WORD - bitsize, 0)));
4665               bitsize = BITS_PER_WORD;
4666               mode = word_mode;
4667             }
4668 #endif
4669
4670           if (GET_CODE (to_rtx) == MEM && !MEM_KEEP_ALIAS_SET_P (to_rtx)
4671               && DECL_NONADDRESSABLE_P (field))
4672             {
4673               to_rtx = copy_rtx (to_rtx);
4674               MEM_KEEP_ALIAS_SET_P (to_rtx) = 1;
4675             }
4676
4677           store_constructor_field (to_rtx, bitsize, bitpos, mode,
4678                                    value, type, cleared,
4679                                    get_alias_set (TREE_TYPE (field)));
4680         }
4681     }
4682   else if (TREE_CODE (type) == ARRAY_TYPE
4683            || TREE_CODE (type) == VECTOR_TYPE)
4684     {
4685       tree elt;
4686       int i;
4687       int need_to_clear;
4688       tree domain = TYPE_DOMAIN (type);
4689       tree elttype = TREE_TYPE (type);
4690       int const_bounds_p;
4691       HOST_WIDE_INT minelt = 0;
4692       HOST_WIDE_INT maxelt = 0;
4693       int icode = 0;
4694       rtx *vector = NULL;
4695       int elt_size = 0;
4696       unsigned n_elts = 0;
4697
4698       /* Vectors are like arrays, but the domain is stored via an array
4699          type indirectly.  */
4700       if (TREE_CODE (type) == VECTOR_TYPE)
4701         {
4702           /* Note that although TYPE_DEBUG_REPRESENTATION_TYPE uses
4703              the same field as TYPE_DOMAIN, we are not guaranteed that
4704              it always will.  */
4705           domain = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4706           domain = TYPE_DOMAIN (TREE_TYPE (TYPE_FIELDS (domain)));
4707           if (REG_P (target) && VECTOR_MODE_P (GET_MODE (target)))
4708             {
4709               enum machine_mode mode = GET_MODE (target);
4710
4711               icode = (int) vec_init_optab->handlers[mode].insn_code;
4712               if (icode != CODE_FOR_nothing)
4713                 {
4714                   unsigned int i;
4715
4716                   elt_size = GET_MODE_SIZE (GET_MODE_INNER (mode));
4717                   n_elts = (GET_MODE_SIZE (mode) / elt_size);
4718                   vector = alloca (n_elts);
4719                   for (i = 0; i < n_elts; i++)
4720                     vector [i] = CONST0_RTX (GET_MODE_INNER (mode));
4721                 }
4722             }
4723         }
4724
4725       const_bounds_p = (TYPE_MIN_VALUE (domain)
4726                         && TYPE_MAX_VALUE (domain)
4727                         && host_integerp (TYPE_MIN_VALUE (domain), 0)
4728                         && host_integerp (TYPE_MAX_VALUE (domain), 0));
4729
4730       /* If we have constant bounds for the range of the type, get them.  */
4731       if (const_bounds_p)
4732         {
4733           minelt = tree_low_cst (TYPE_MIN_VALUE (domain), 0);
4734           maxelt = tree_low_cst (TYPE_MAX_VALUE (domain), 0);
4735         }
4736
4737       /* If the constructor has fewer elements than the array,
4738          clear the whole array first.  Similarly if this is
4739          static constructor of a non-BLKmode object.  */
4740       if (cleared || (GET_CODE (target) == REG && TREE_STATIC (exp)))
4741         need_to_clear = 1;
4742       else
4743         {
4744           HOST_WIDE_INT count = 0, zero_count = 0;
4745           need_to_clear = ! const_bounds_p;
4746
4747           /* This loop is a more accurate version of the loop in
4748              mostly_zeros_p (it handles RANGE_EXPR in an index).
4749              It is also needed to check for missing elements.  */
4750           for (elt = CONSTRUCTOR_ELTS (exp);
4751                elt != NULL_TREE && ! need_to_clear;
4752                elt = TREE_CHAIN (elt))
4753             {
4754               tree index = TREE_PURPOSE (elt);
4755               HOST_WIDE_INT this_node_count;
4756
4757               if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
4758                 {
4759                   tree lo_index = TREE_OPERAND (index, 0);
4760                   tree hi_index = TREE_OPERAND (index, 1);
4761
4762                   if (! host_integerp (lo_index, 1)
4763                       || ! host_integerp (hi_index, 1))
4764                     {
4765                       need_to_clear = 1;
4766                       break;
4767                     }
4768
4769                   this_node_count = (tree_low_cst (hi_index, 1)
4770                                      - tree_low_cst (lo_index, 1) + 1);
4771                 }
4772               else
4773                 this_node_count = 1;
4774
4775               count += this_node_count;
4776               if (mostly_zeros_p (TREE_VALUE (elt)))
4777                 zero_count += this_node_count;
4778             }
4779
4780           /* Clear the entire array first if there are any missing elements,
4781              or if the incidence of zero elements is >= 75%.  */
4782           if (! need_to_clear
4783               && (count < maxelt - minelt + 1 || 4 * zero_count >= 3 * count))
4784             need_to_clear = 1;
4785         }
4786
4787       if (need_to_clear && size > 0 && !vector)
4788         {
4789           if (! cleared)
4790             {
4791               if (REG_P (target))
4792                 emit_move_insn (target,  CONST0_RTX (GET_MODE (target)));
4793               else
4794                 clear_storage (target, GEN_INT (size));
4795             }
4796           cleared = 1;
4797         }
4798       else if (REG_P (target))
4799         /* Inform later passes that the old value is dead.  */
4800         emit_insn (gen_rtx_CLOBBER (VOIDmode, target));
4801
4802       /* Store each element of the constructor into
4803          the corresponding element of TARGET, determined
4804          by counting the elements.  */
4805       for (elt = CONSTRUCTOR_ELTS (exp), i = 0;
4806            elt;
4807            elt = TREE_CHAIN (elt), i++)
4808         {
4809           enum machine_mode mode;
4810           HOST_WIDE_INT bitsize;
4811           HOST_WIDE_INT bitpos;
4812           int unsignedp;
4813           tree value = TREE_VALUE (elt);
4814           tree index = TREE_PURPOSE (elt);
4815           rtx xtarget = target;
4816
4817           if (cleared && is_zeros_p (value))
4818             continue;
4819
4820           unsignedp = TREE_UNSIGNED (elttype);
4821           mode = TYPE_MODE (elttype);
4822           if (mode == BLKmode)
4823             bitsize = (host_integerp (TYPE_SIZE (elttype), 1)
4824                        ? tree_low_cst (TYPE_SIZE (elttype), 1)
4825                        : -1);
4826           else
4827             bitsize = GET_MODE_BITSIZE (mode);
4828
4829           if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
4830             {
4831               tree lo_index = TREE_OPERAND (index, 0);
4832               tree hi_index = TREE_OPERAND (index, 1);
4833               rtx index_r, pos_rtx, loop_end;
4834               struct nesting *loop;
4835               HOST_WIDE_INT lo, hi, count;
4836               tree position;
4837
4838               if (vector)
4839                 abort ();
4840
4841               /* If the range is constant and "small", unroll the loop.  */
4842               if (const_bounds_p
4843                   && host_integerp (lo_index, 0)
4844                   && host_integerp (hi_index, 0)
4845                   && (lo = tree_low_cst (lo_index, 0),
4846                       hi = tree_low_cst (hi_index, 0),
4847                       count = hi - lo + 1,
4848                       (GET_CODE (target) != MEM
4849                        || count <= 2
4850                        || (host_integerp (TYPE_SIZE (elttype), 1)
4851                            && (tree_low_cst (TYPE_SIZE (elttype), 1) * count
4852                                <= 40 * 8)))))
4853                 {
4854                   lo -= minelt;  hi -= minelt;
4855                   for (; lo <= hi; lo++)
4856                     {
4857                       bitpos = lo * tree_low_cst (TYPE_SIZE (elttype), 0);
4858
4859                       if (GET_CODE (target) == MEM
4860                           && !MEM_KEEP_ALIAS_SET_P (target)
4861                           && TREE_CODE (type) == ARRAY_TYPE
4862                           && TYPE_NONALIASED_COMPONENT (type))
4863                         {
4864                           target = copy_rtx (target);
4865                           MEM_KEEP_ALIAS_SET_P (target) = 1;
4866                         }
4867
4868                       store_constructor_field
4869                         (target, bitsize, bitpos, mode, value, type, cleared,
4870                          get_alias_set (elttype));
4871                     }
4872                 }
4873               else
4874                 {
4875                   expand_expr (hi_index, NULL_RTX, VOIDmode, 0);
4876                   loop_end = gen_label_rtx ();
4877
4878                   unsignedp = TREE_UNSIGNED (domain);
4879
4880                   index = build_decl (VAR_DECL, NULL_TREE, domain);
4881
4882                   index_r
4883                     = gen_reg_rtx (promote_mode (domain, DECL_MODE (index),
4884                                                  &unsignedp, 0));
4885                   SET_DECL_RTL (index, index_r);
4886                   if (TREE_CODE (value) == SAVE_EXPR
4887                       && SAVE_EXPR_RTL (value) == 0)
4888                     {
4889                       /* Make sure value gets expanded once before the
4890                          loop.  */
4891                       expand_expr (value, const0_rtx, VOIDmode, 0);
4892                       emit_queue ();
4893                     }
4894                   store_expr (lo_index, index_r, 0);
4895                   loop = expand_start_loop (0);
4896
4897                   /* Assign value to element index.  */
4898                   position
4899                     = convert (ssizetype,
4900                                fold (build (MINUS_EXPR, TREE_TYPE (index),
4901                                             index, TYPE_MIN_VALUE (domain))));
4902                   position = size_binop (MULT_EXPR, position,
4903                                          convert (ssizetype,
4904                                                   TYPE_SIZE_UNIT (elttype)));
4905
4906                   pos_rtx = expand_expr (position, 0, VOIDmode, 0);
4907                   xtarget = offset_address (target, pos_rtx,
4908                                             highest_pow2_factor (position));
4909                   xtarget = adjust_address (xtarget, mode, 0);
4910                   if (TREE_CODE (value) == CONSTRUCTOR)
4911                     store_constructor (value, xtarget, cleared,
4912                                        bitsize / BITS_PER_UNIT);
4913                   else
4914                     store_expr (value, xtarget, 0);
4915
4916                   expand_exit_loop_if_false (loop,
4917                                              build (LT_EXPR, integer_type_node,
4918                                                     index, hi_index));
4919
4920                   expand_increment (build (PREINCREMENT_EXPR,
4921                                            TREE_TYPE (index),
4922                                            index, integer_one_node), 0, 0);
4923                   expand_end_loop ();
4924                   emit_label (loop_end);
4925                 }
4926             }
4927           else if ((index != 0 && ! host_integerp (index, 0))
4928                    || ! host_integerp (TYPE_SIZE (elttype), 1))
4929             {
4930               tree position;
4931
4932               if (vector)
4933                 abort ();
4934
4935               if (index == 0)
4936                 index = ssize_int (1);
4937
4938               if (minelt)
4939                 index = convert (ssizetype,
4940                                  fold (build (MINUS_EXPR, index,
4941                                               TYPE_MIN_VALUE (domain))));
4942
4943               position = size_binop (MULT_EXPR, index,
4944                                      convert (ssizetype,
4945                                               TYPE_SIZE_UNIT (elttype)));
4946               xtarget = offset_address (target,
4947                                         expand_expr (position, 0, VOIDmode, 0),
4948                                         highest_pow2_factor (position));
4949               xtarget = adjust_address (xtarget, mode, 0);
4950               store_expr (value, xtarget, 0);
4951             }
4952           else if (vector)
4953             {
4954               int pos;
4955
4956               if (index != 0)
4957                 pos = tree_low_cst (index, 0) - minelt;
4958               else
4959                 pos = i;
4960               vector[pos] = expand_expr (value, NULL_RTX, VOIDmode, 0);
4961             }
4962           else
4963             {
4964               if (index != 0)
4965                 bitpos = ((tree_low_cst (index, 0) - minelt)
4966                           * tree_low_cst (TYPE_SIZE (elttype), 1));
4967               else
4968                 bitpos = (i * tree_low_cst (TYPE_SIZE (elttype), 1));
4969
4970               if (GET_CODE (target) == MEM && !MEM_KEEP_ALIAS_SET_P (target)
4971                   && TREE_CODE (type) == ARRAY_TYPE
4972                   && TYPE_NONALIASED_COMPONENT (type))
4973                 {
4974                   target = copy_rtx (target);
4975                   MEM_KEEP_ALIAS_SET_P (target) = 1;
4976                 }
4977               store_constructor_field (target, bitsize, bitpos, mode, value,
4978                                        type, cleared, get_alias_set (elttype));
4979             }
4980         }
4981       if (vector)
4982         {
4983           emit_insn (GEN_FCN (icode) (target,
4984                                       gen_rtx_PARALLEL (GET_MODE (target),
4985                                                         gen_rtvec_v (n_elts, vector))));
4986         }
4987     }
4988
4989   /* Set constructor assignments.  */
4990   else if (TREE_CODE (type) == SET_TYPE)
4991     {
4992       tree elt = CONSTRUCTOR_ELTS (exp);
4993       unsigned HOST_WIDE_INT nbytes = int_size_in_bytes (type), nbits;
4994       tree domain = TYPE_DOMAIN (type);
4995       tree domain_min, domain_max, bitlength;
4996
4997       /* The default implementation strategy is to extract the constant
4998          parts of the constructor, use that to initialize the target,
4999          and then "or" in whatever non-constant ranges we need in addition.
5000
5001          If a large set is all zero or all ones, it is
5002          probably better to set it using memset (if available) or bzero.
5003          Also, if a large set has just a single range, it may also be
5004          better to first clear all the first clear the set (using
5005          bzero/memset), and set the bits we want.  */
5006
5007       /* Check for all zeros.  */
5008       if (elt == NULL_TREE && size > 0)
5009         {
5010           if (!cleared)
5011             clear_storage (target, GEN_INT (size));
5012           return;
5013         }
5014
5015       domain_min = convert (sizetype, TYPE_MIN_VALUE (domain));
5016       domain_max = convert (sizetype, TYPE_MAX_VALUE (domain));
5017       bitlength = size_binop (PLUS_EXPR,
5018                               size_diffop (domain_max, domain_min),
5019                               ssize_int (1));
5020
5021       nbits = tree_low_cst (bitlength, 1);
5022
5023       /* For "small" sets, or "medium-sized" (up to 32 bytes) sets that
5024          are "complicated" (more than one range), initialize (the
5025          constant parts) by copying from a constant.  */
5026       if (GET_MODE (target) != BLKmode || nbits <= 2 * BITS_PER_WORD
5027           || (nbytes <= 32 && TREE_CHAIN (elt) != NULL_TREE))
5028         {
5029           unsigned int set_word_size = TYPE_ALIGN (TREE_TYPE (exp));
5030           enum machine_mode mode = mode_for_size (set_word_size, MODE_INT, 1);
5031           char *bit_buffer = alloca (nbits);
5032           HOST_WIDE_INT word = 0;
5033           unsigned int bit_pos = 0;
5034           unsigned int ibit = 0;
5035           unsigned int offset = 0;  /* In bytes from beginning of set.  */
5036
5037           elt = get_set_constructor_bits (exp, bit_buffer, nbits);
5038           for (;;)
5039             {
5040               if (bit_buffer[ibit])
5041                 {
5042                   if (BYTES_BIG_ENDIAN)
5043                     word |= (1 << (set_word_size - 1 - bit_pos));
5044                   else
5045                     word |= 1 << bit_pos;
5046                 }
5047
5048               bit_pos++;  ibit++;
5049               if (bit_pos >= set_word_size || ibit == nbits)
5050                 {
5051                   if (word != 0 || ! cleared)
5052                     {
5053                       rtx datum = GEN_INT (word);
5054                       rtx to_rtx;
5055
5056                       /* The assumption here is that it is safe to use
5057                          XEXP if the set is multi-word, but not if
5058                          it's single-word.  */
5059                       if (GET_CODE (target) == MEM)
5060                         to_rtx = adjust_address (target, mode, offset);
5061                       else if (offset == 0)
5062                         to_rtx = target;
5063                       else
5064                         abort ();
5065                       emit_move_insn (to_rtx, datum);
5066                     }
5067
5068                   if (ibit == nbits)
5069                     break;
5070                   word = 0;
5071                   bit_pos = 0;
5072                   offset += set_word_size / BITS_PER_UNIT;
5073                 }
5074             }
5075         }
5076       else if (!cleared)
5077         /* Don't bother clearing storage if the set is all ones.  */
5078         if (TREE_CHAIN (elt) != NULL_TREE
5079             || (TREE_PURPOSE (elt) == NULL_TREE
5080                 ? nbits != 1
5081                 : ( ! host_integerp (TREE_VALUE (elt), 0)
5082                    || ! host_integerp (TREE_PURPOSE (elt), 0)
5083                    || (tree_low_cst (TREE_VALUE (elt), 0)
5084                        - tree_low_cst (TREE_PURPOSE (elt), 0) + 1
5085                        != (HOST_WIDE_INT) nbits))))
5086           clear_storage (target, expr_size (exp));
5087
5088       for (; elt != NULL_TREE; elt = TREE_CHAIN (elt))
5089         {
5090           /* Start of range of element or NULL.  */
5091           tree startbit = TREE_PURPOSE (elt);
5092           /* End of range of element, or element value.  */
5093           tree endbit   = TREE_VALUE (elt);
5094           HOST_WIDE_INT startb, endb;
5095           rtx bitlength_rtx, startbit_rtx, endbit_rtx, targetx;
5096
5097           bitlength_rtx = expand_expr (bitlength,
5098                                        NULL_RTX, MEM, EXPAND_CONST_ADDRESS);
5099
5100           /* Handle non-range tuple element like [ expr ].  */
5101           if (startbit == NULL_TREE)
5102             {
5103               startbit = save_expr (endbit);
5104               endbit = startbit;
5105             }
5106
5107           startbit = convert (sizetype, startbit);
5108           endbit = convert (sizetype, endbit);
5109           if (! integer_zerop (domain_min))
5110             {
5111               startbit = size_binop (MINUS_EXPR, startbit, domain_min);
5112               endbit = size_binop (MINUS_EXPR, endbit, domain_min);
5113             }
5114           startbit_rtx = expand_expr (startbit, NULL_RTX, MEM,
5115                                       EXPAND_CONST_ADDRESS);
5116           endbit_rtx = expand_expr (endbit, NULL_RTX, MEM,
5117                                     EXPAND_CONST_ADDRESS);
5118
5119           if (REG_P (target))
5120             {
5121               targetx
5122                 = assign_temp
5123                   ((build_qualified_type (lang_hooks.types.type_for_mode
5124                                           (GET_MODE (target), 0),
5125                                           TYPE_QUAL_CONST)),
5126                    0, 1, 1);
5127               emit_move_insn (targetx, target);
5128             }
5129
5130           else if (GET_CODE (target) == MEM)
5131             targetx = target;
5132           else
5133             abort ();
5134
5135           /* Optimization:  If startbit and endbit are constants divisible
5136              by BITS_PER_UNIT, call memset instead.  */
5137           if (TARGET_MEM_FUNCTIONS
5138               && TREE_CODE (startbit) == INTEGER_CST
5139               && TREE_CODE (endbit) == INTEGER_CST
5140               && (startb = TREE_INT_CST_LOW (startbit)) % BITS_PER_UNIT == 0
5141               && (endb = TREE_INT_CST_LOW (endbit) + 1) % BITS_PER_UNIT == 0)
5142             {
5143               emit_library_call (memset_libfunc, LCT_NORMAL,
5144                                  VOIDmode, 3,
5145                                  plus_constant (XEXP (targetx, 0),
5146                                                 startb / BITS_PER_UNIT),
5147                                  Pmode,
5148                                  constm1_rtx, TYPE_MODE (integer_type_node),
5149                                  GEN_INT ((endb - startb) / BITS_PER_UNIT),
5150                                  TYPE_MODE (sizetype));
5151             }
5152           else
5153             emit_library_call (setbits_libfunc, LCT_NORMAL,
5154                                VOIDmode, 4, XEXP (targetx, 0),
5155                                Pmode, bitlength_rtx, TYPE_MODE (sizetype),
5156                                startbit_rtx, TYPE_MODE (sizetype),
5157                                endbit_rtx, TYPE_MODE (sizetype));
5158
5159           if (REG_P (target))
5160             emit_move_insn (target, targetx);
5161         }
5162     }
5163
5164   else
5165     abort ();
5166 }
5167
5168 /* Store the value of EXP (an expression tree)
5169    into a subfield of TARGET which has mode MODE and occupies
5170    BITSIZE bits, starting BITPOS bits from the start of TARGET.
5171    If MODE is VOIDmode, it means that we are storing into a bit-field.
5172
5173    If VALUE_MODE is VOIDmode, return nothing in particular.
5174    UNSIGNEDP is not used in this case.
5175
5176    Otherwise, return an rtx for the value stored.  This rtx
5177    has mode VALUE_MODE if that is convenient to do.
5178    In this case, UNSIGNEDP must be nonzero if the value is an unsigned type.
5179
5180    TYPE is the type of the underlying object,
5181
5182    ALIAS_SET is the alias set for the destination.  This value will
5183    (in general) be different from that for TARGET, since TARGET is a
5184    reference to the containing structure.  */
5185
5186 static rtx
5187 store_field (rtx target, HOST_WIDE_INT bitsize, HOST_WIDE_INT bitpos,
5188              enum machine_mode mode, tree exp, enum machine_mode value_mode,
5189              int unsignedp, tree type, int alias_set)
5190 {
5191   HOST_WIDE_INT width_mask = 0;
5192
5193   if (TREE_CODE (exp) == ERROR_MARK)
5194     return const0_rtx;
5195
5196   /* If we have nothing to store, do nothing unless the expression has
5197      side-effects.  */
5198   if (bitsize == 0)
5199     return expand_expr (exp, const0_rtx, VOIDmode, 0);
5200   else if (bitsize >= 0 && bitsize < HOST_BITS_PER_WIDE_INT)
5201     width_mask = ((HOST_WIDE_INT) 1 << bitsize) - 1;
5202
5203   /* If we are storing into an unaligned field of an aligned union that is
5204      in a register, we may have the mode of TARGET being an integer mode but
5205      MODE == BLKmode.  In that case, get an aligned object whose size and
5206      alignment are the same as TARGET and store TARGET into it (we can avoid
5207      the store if the field being stored is the entire width of TARGET).  Then
5208      call ourselves recursively to store the field into a BLKmode version of
5209      that object.  Finally, load from the object into TARGET.  This is not
5210      very efficient in general, but should only be slightly more expensive
5211      than the otherwise-required unaligned accesses.  Perhaps this can be
5212      cleaned up later.  It's tempting to make OBJECT readonly, but it's set
5213      twice, once with emit_move_insn and once via store_field.  */
5214
5215   if (mode == BLKmode
5216       && (GET_CODE (target) == REG || GET_CODE (target) == SUBREG))
5217     {
5218       rtx object = assign_temp (type, 0, 1, 1);
5219       rtx blk_object = adjust_address (object, BLKmode, 0);
5220
5221       if (bitsize != (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (target)))
5222         emit_move_insn (object, target);
5223
5224       store_field (blk_object, bitsize, bitpos, mode, exp, VOIDmode, 0, type,
5225                    alias_set);
5226
5227       emit_move_insn (target, object);
5228
5229       /* We want to return the BLKmode version of the data.  */
5230       return blk_object;
5231     }
5232
5233   if (GET_CODE (target) == CONCAT)
5234     {
5235       /* We're storing into a struct containing a single __complex.  */
5236
5237       if (bitpos != 0)
5238         abort ();
5239       return store_expr (exp, target, 0);
5240     }
5241
5242   /* If the structure is in a register or if the component
5243      is a bit field, we cannot use addressing to access it.
5244      Use bit-field techniques or SUBREG to store in it.  */
5245
5246   if (mode == VOIDmode
5247       || (mode != BLKmode && ! direct_store[(int) mode]
5248           && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
5249           && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT)
5250       || GET_CODE (target) == REG
5251       || GET_CODE (target) == SUBREG
5252       /* If the field isn't aligned enough to store as an ordinary memref,
5253          store it as a bit field.  */
5254       || (mode != BLKmode
5255           && ((((MEM_ALIGN (target) < GET_MODE_ALIGNMENT (mode))
5256                 || bitpos % GET_MODE_ALIGNMENT (mode))
5257                && SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (target)))
5258               || (bitpos % BITS_PER_UNIT != 0)))
5259       /* If the RHS and field are a constant size and the size of the
5260          RHS isn't the same size as the bitfield, we must use bitfield
5261          operations.  */
5262       || (bitsize >= 0
5263           && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) == INTEGER_CST
5264           && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)), bitsize) != 0))
5265     {
5266       rtx temp = expand_expr (exp, NULL_RTX, VOIDmode, 0);
5267
5268       /* If BITSIZE is narrower than the size of the type of EXP
5269          we will be narrowing TEMP.  Normally, what's wanted are the
5270          low-order bits.  However, if EXP's type is a record and this is
5271          big-endian machine, we want the upper BITSIZE bits.  */
5272       if (BYTES_BIG_ENDIAN && GET_MODE_CLASS (GET_MODE (temp)) == MODE_INT
5273           && bitsize < (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (temp))
5274           && TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
5275         temp = expand_shift (RSHIFT_EXPR, GET_MODE (temp), temp,
5276                              size_int (GET_MODE_BITSIZE (GET_MODE (temp))
5277                                        - bitsize),
5278                              NULL_RTX, 1);
5279
5280       /* Unless MODE is VOIDmode or BLKmode, convert TEMP to
5281          MODE.  */
5282       if (mode != VOIDmode && mode != BLKmode
5283           && mode != TYPE_MODE (TREE_TYPE (exp)))
5284         temp = convert_modes (mode, TYPE_MODE (TREE_TYPE (exp)), temp, 1);
5285
5286       /* If the modes of TARGET and TEMP are both BLKmode, both
5287          must be in memory and BITPOS must be aligned on a byte
5288          boundary.  If so, we simply do a block copy.  */
5289       if (GET_MODE (target) == BLKmode && GET_MODE (temp) == BLKmode)
5290         {
5291           if (GET_CODE (target) != MEM || GET_CODE (temp) != MEM
5292               || bitpos % BITS_PER_UNIT != 0)
5293             abort ();
5294
5295           target = adjust_address (target, VOIDmode, bitpos / BITS_PER_UNIT);
5296           emit_block_move (target, temp,
5297                            GEN_INT ((bitsize + BITS_PER_UNIT - 1)
5298                                     / BITS_PER_UNIT),
5299                            BLOCK_OP_NORMAL);
5300
5301           return value_mode == VOIDmode ? const0_rtx : target;
5302         }
5303
5304       /* Store the value in the bitfield.  */
5305       store_bit_field (target, bitsize, bitpos, mode, temp,
5306                        int_size_in_bytes (type));
5307
5308       if (value_mode != VOIDmode)
5309         {
5310           /* The caller wants an rtx for the value.
5311              If possible, avoid refetching from the bitfield itself.  */
5312           if (width_mask != 0
5313               && ! (GET_CODE (target) == MEM && MEM_VOLATILE_P (target)))
5314             {
5315               tree count;
5316               enum machine_mode tmode;
5317
5318               tmode = GET_MODE (temp);
5319               if (tmode == VOIDmode)
5320                 tmode = value_mode;
5321
5322               if (unsignedp)
5323                 return expand_and (tmode, temp,
5324                                    gen_int_mode (width_mask, tmode),
5325                                    NULL_RTX);
5326
5327               count = build_int_2 (GET_MODE_BITSIZE (tmode) - bitsize, 0);
5328               temp = expand_shift (LSHIFT_EXPR, tmode, temp, count, 0, 0);
5329               return expand_shift (RSHIFT_EXPR, tmode, temp, count, 0, 0);
5330             }
5331
5332           return extract_bit_field (target, bitsize, bitpos, unsignedp,
5333                                     NULL_RTX, value_mode, VOIDmode,
5334                                     int_size_in_bytes (type));
5335         }
5336       return const0_rtx;
5337     }
5338   else
5339     {
5340       rtx addr = XEXP (target, 0);
5341       rtx to_rtx = target;
5342
5343       /* If a value is wanted, it must be the lhs;
5344          so make the address stable for multiple use.  */
5345
5346       if (value_mode != VOIDmode && GET_CODE (addr) != REG
5347           && ! CONSTANT_ADDRESS_P (addr)
5348           /* A frame-pointer reference is already stable.  */
5349           && ! (GET_CODE (addr) == PLUS
5350                 && GET_CODE (XEXP (addr, 1)) == CONST_INT
5351                 && (XEXP (addr, 0) == virtual_incoming_args_rtx
5352                     || XEXP (addr, 0) == virtual_stack_vars_rtx)))
5353         to_rtx = replace_equiv_address (to_rtx, copy_to_reg (addr));
5354
5355       /* Now build a reference to just the desired component.  */
5356
5357       to_rtx = adjust_address (target, mode, bitpos / BITS_PER_UNIT);
5358
5359       if (to_rtx == target)
5360         to_rtx = copy_rtx (to_rtx);
5361
5362       MEM_SET_IN_STRUCT_P (to_rtx, 1);
5363       if (!MEM_KEEP_ALIAS_SET_P (to_rtx) && MEM_ALIAS_SET (to_rtx) != 0)
5364         set_mem_alias_set (to_rtx, alias_set);
5365
5366       return store_expr (exp, to_rtx, value_mode != VOIDmode);
5367     }
5368 }
5369 \f
5370 /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
5371    an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
5372    codes and find the ultimate containing object, which we return.
5373
5374    We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
5375    bit position, and *PUNSIGNEDP to the signedness of the field.
5376    If the position of the field is variable, we store a tree
5377    giving the variable offset (in units) in *POFFSET.
5378    This offset is in addition to the bit position.
5379    If the position is not variable, we store 0 in *POFFSET.
5380
5381    If any of the extraction expressions is volatile,
5382    we store 1 in *PVOLATILEP.  Otherwise we don't change that.
5383
5384    If the field is a bit-field, *PMODE is set to VOIDmode.  Otherwise, it
5385    is a mode that can be used to access the field.  In that case, *PBITSIZE
5386    is redundant.
5387
5388    If the field describes a variable-sized object, *PMODE is set to
5389    VOIDmode and *PBITSIZE is set to -1.  An access cannot be made in
5390    this case, but the address of the object can be found.  */
5391
5392 tree
5393 get_inner_reference (tree exp, HOST_WIDE_INT *pbitsize,
5394                      HOST_WIDE_INT *pbitpos, tree *poffset,
5395                      enum machine_mode *pmode, int *punsignedp,
5396                      int *pvolatilep)
5397 {
5398   tree size_tree = 0;
5399   enum machine_mode mode = VOIDmode;
5400   tree offset = size_zero_node;
5401   tree bit_offset = bitsize_zero_node;
5402   tree tem;
5403
5404   /* First get the mode, signedness, and size.  We do this from just the
5405      outermost expression.  */
5406   if (TREE_CODE (exp) == COMPONENT_REF)
5407     {
5408       size_tree = DECL_SIZE (TREE_OPERAND (exp, 1));
5409       if (! DECL_BIT_FIELD (TREE_OPERAND (exp, 1)))
5410         mode = DECL_MODE (TREE_OPERAND (exp, 1));
5411
5412       *punsignedp = TREE_UNSIGNED (TREE_OPERAND (exp, 1));
5413     }
5414   else if (TREE_CODE (exp) == BIT_FIELD_REF)
5415     {
5416       size_tree = TREE_OPERAND (exp, 1);
5417       *punsignedp = TREE_UNSIGNED (exp);
5418     }
5419   else
5420     {
5421       mode = TYPE_MODE (TREE_TYPE (exp));
5422       *punsignedp = TREE_UNSIGNED (TREE_TYPE (exp));
5423
5424       if (mode == BLKmode)
5425         size_tree = TYPE_SIZE (TREE_TYPE (exp));
5426       else
5427         *pbitsize = GET_MODE_BITSIZE (mode);
5428     }
5429
5430   if (size_tree != 0)
5431     {
5432       if (! host_integerp (size_tree, 1))
5433         mode = BLKmode, *pbitsize = -1;
5434       else
5435         *pbitsize = tree_low_cst (size_tree, 1);
5436     }
5437
5438   /* Compute cumulative bit-offset for nested component-refs and array-refs,
5439      and find the ultimate containing object.  */
5440   while (1)
5441     {
5442       if (TREE_CODE (exp) == BIT_FIELD_REF)
5443         bit_offset = size_binop (PLUS_EXPR, bit_offset, TREE_OPERAND (exp, 2));
5444       else if (TREE_CODE (exp) == COMPONENT_REF)
5445         {
5446           tree field = TREE_OPERAND (exp, 1);
5447           tree this_offset = DECL_FIELD_OFFSET (field);
5448
5449           /* If this field hasn't been filled in yet, don't go
5450              past it.  This should only happen when folding expressions
5451              made during type construction.  */
5452           if (this_offset == 0)
5453             break;
5454           else
5455             this_offset = SUBSTITUTE_PLACEHOLDER_IN_EXPR (this_offset, exp);
5456
5457           offset = size_binop (PLUS_EXPR, offset, this_offset);
5458           bit_offset = size_binop (PLUS_EXPR, bit_offset,
5459                                    DECL_FIELD_BIT_OFFSET (field));
5460
5461           /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN.  */
5462         }
5463
5464       else if (TREE_CODE (exp) == ARRAY_REF
5465                || TREE_CODE (exp) == ARRAY_RANGE_REF)
5466         {
5467           tree index = TREE_OPERAND (exp, 1);
5468           tree array = TREE_OPERAND (exp, 0);
5469           tree domain = TYPE_DOMAIN (TREE_TYPE (array));
5470           tree low_bound = (domain ? TYPE_MIN_VALUE (domain) : 0);
5471           tree unit_size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (array)));
5472
5473           /* We assume all arrays have sizes that are a multiple of a byte.
5474              First subtract the lower bound, if any, in the type of the
5475              index, then convert to sizetype and multiply by the size of the
5476              array element.  */
5477           if (low_bound != 0 && ! integer_zerop (low_bound))
5478             index = fold (build (MINUS_EXPR, TREE_TYPE (index),
5479                                  index, low_bound));
5480
5481           /* If the index has a self-referential type, instantiate it with
5482              the object; likewise fkor the component size.  */
5483           index = SUBSTITUTE_PLACEHOLDER_IN_EXPR (index, exp);
5484           unit_size = SUBSTITUTE_PLACEHOLDER_IN_EXPR (unit_size, array);
5485           offset = size_binop (PLUS_EXPR, offset,
5486                                size_binop (MULT_EXPR,
5487                                            convert (sizetype, index),
5488                                            unit_size));
5489         }
5490
5491       /* We can go inside most conversions: all NON_VALUE_EXPRs, all normal
5492          conversions that don't change the mode, and all view conversions
5493          except those that need to "step up" the alignment.  */
5494       else if (TREE_CODE (exp) != NON_LVALUE_EXPR
5495                && ! (TREE_CODE (exp) == VIEW_CONVERT_EXPR
5496                      && ! ((TYPE_ALIGN (TREE_TYPE (exp))
5497                             > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0))))
5498                            && STRICT_ALIGNMENT
5499                            && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0)))
5500                                < BIGGEST_ALIGNMENT)
5501                            && (TYPE_ALIGN_OK (TREE_TYPE (exp))
5502                                || TYPE_ALIGN_OK (TREE_TYPE
5503                                                  (TREE_OPERAND (exp, 0))))))
5504                && ! ((TREE_CODE (exp) == NOP_EXPR
5505                       || TREE_CODE (exp) == CONVERT_EXPR)
5506                      && (TYPE_MODE (TREE_TYPE (exp))
5507                          == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))))))
5508         break;
5509
5510       /* If any reference in the chain is volatile, the effect is volatile.  */
5511       if (TREE_THIS_VOLATILE (exp))
5512         *pvolatilep = 1;
5513
5514       exp = TREE_OPERAND (exp, 0);
5515     }
5516
5517   /* If OFFSET is constant, see if we can return the whole thing as a
5518      constant bit position.  Otherwise, split it up.  */
5519   if (host_integerp (offset, 0)
5520       && 0 != (tem = size_binop (MULT_EXPR, convert (bitsizetype, offset),
5521                                  bitsize_unit_node))
5522       && 0 != (tem = size_binop (PLUS_EXPR, tem, bit_offset))
5523       && host_integerp (tem, 0))
5524     *pbitpos = tree_low_cst (tem, 0), *poffset = 0;
5525   else
5526     *pbitpos = tree_low_cst (bit_offset, 0), *poffset = offset;
5527
5528   *pmode = mode;
5529   return exp;
5530 }
5531
5532 /* Return 1 if T is an expression that get_inner_reference handles.  */
5533
5534 int
5535 handled_component_p (tree t)
5536 {
5537   switch (TREE_CODE (t))
5538     {
5539     case BIT_FIELD_REF:
5540     case COMPONENT_REF:
5541     case ARRAY_REF:
5542     case ARRAY_RANGE_REF:
5543     case NON_LVALUE_EXPR:
5544     case VIEW_CONVERT_EXPR:
5545       return 1;
5546
5547     /* ??? Sure they are handled, but get_inner_reference may return
5548        a different PBITSIZE, depending upon whether the expression is
5549        wrapped up in a NOP_EXPR or not, e.g. for bitfields.  */
5550     case NOP_EXPR:
5551     case CONVERT_EXPR:
5552       return (TYPE_MODE (TREE_TYPE (t))
5553               == TYPE_MODE (TREE_TYPE (TREE_OPERAND (t, 0))));
5554
5555     default:
5556       return 0;
5557     }
5558 }
5559 \f
5560 /* Given an rtx VALUE that may contain additions and multiplications, return
5561    an equivalent value that just refers to a register, memory, or constant.
5562    This is done by generating instructions to perform the arithmetic and
5563    returning a pseudo-register containing the value.
5564
5565    The returned value may be a REG, SUBREG, MEM or constant.  */
5566
5567 rtx
5568 force_operand (rtx value, rtx target)
5569 {
5570   rtx op1, op2;
5571   /* Use subtarget as the target for operand 0 of a binary operation.  */
5572   rtx subtarget = get_subtarget (target);
5573   enum rtx_code code = GET_CODE (value);
5574
5575   /* Check for subreg applied to an expression produced by loop optimizer.  */
5576   if (code == SUBREG
5577       && GET_CODE (SUBREG_REG (value)) != REG
5578       && GET_CODE (SUBREG_REG (value)) != MEM)
5579     {
5580       value = simplify_gen_subreg (GET_MODE (value),
5581                                    force_reg (GET_MODE (SUBREG_REG (value)),
5582                                               force_operand (SUBREG_REG (value),
5583                                                              NULL_RTX)),
5584                                    GET_MODE (SUBREG_REG (value)),
5585                                    SUBREG_BYTE (value));
5586       code = GET_CODE (value);
5587     }
5588
5589   /* Check for a PIC address load.  */
5590   if ((code == PLUS || code == MINUS)
5591       && XEXP (value, 0) == pic_offset_table_rtx
5592       && (GET_CODE (XEXP (value, 1)) == SYMBOL_REF
5593           || GET_CODE (XEXP (value, 1)) == LABEL_REF
5594           || GET_CODE (XEXP (value, 1)) == CONST))
5595     {
5596       if (!subtarget)
5597         subtarget = gen_reg_rtx (GET_MODE (value));
5598       emit_move_insn (subtarget, value);
5599       return subtarget;
5600     }
5601
5602   if (code == ZERO_EXTEND || code == SIGN_EXTEND)
5603     {
5604       if (!target)
5605         target = gen_reg_rtx (GET_MODE (value));
5606       convert_move (target, force_operand (XEXP (value, 0), NULL),
5607                     code == ZERO_EXTEND);
5608       return target;
5609     }
5610
5611   if (ARITHMETIC_P (value))
5612     {
5613       op2 = XEXP (value, 1);
5614       if (!CONSTANT_P (op2) && !(GET_CODE (op2) == REG && op2 != subtarget))
5615         subtarget = 0;
5616       if (code == MINUS && GET_CODE (op2) == CONST_INT)
5617         {
5618           code = PLUS;
5619           op2 = negate_rtx (GET_MODE (value), op2);
5620         }
5621
5622       /* Check for an addition with OP2 a constant integer and our first
5623          operand a PLUS of a virtual register and something else.  In that
5624          case, we want to emit the sum of the virtual register and the
5625          constant first and then add the other value.  This allows virtual
5626          register instantiation to simply modify the constant rather than
5627          creating another one around this addition.  */
5628       if (code == PLUS && GET_CODE (op2) == CONST_INT
5629           && GET_CODE (XEXP (value, 0)) == PLUS
5630           && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
5631           && REGNO (XEXP (XEXP (value, 0), 0)) >= FIRST_VIRTUAL_REGISTER
5632           && REGNO (XEXP (XEXP (value, 0), 0)) <= LAST_VIRTUAL_REGISTER)
5633         {
5634           rtx temp = expand_simple_binop (GET_MODE (value), code,
5635                                           XEXP (XEXP (value, 0), 0), op2,
5636                                           subtarget, 0, OPTAB_LIB_WIDEN);
5637           return expand_simple_binop (GET_MODE (value), code, temp,
5638                                       force_operand (XEXP (XEXP (value,
5639                                                                  0), 1), 0),
5640                                       target, 0, OPTAB_LIB_WIDEN);
5641         }
5642
5643       op1 = force_operand (XEXP (value, 0), subtarget);
5644       op2 = force_operand (op2, NULL_RTX);
5645       switch (code)
5646         {
5647         case MULT:
5648           return expand_mult (GET_MODE (value), op1, op2, target, 1);
5649         case DIV:
5650           if (!INTEGRAL_MODE_P (GET_MODE (value)))
5651             return expand_simple_binop (GET_MODE (value), code, op1, op2,
5652                                         target, 1, OPTAB_LIB_WIDEN);
5653           else
5654             return expand_divmod (0,
5655                                   FLOAT_MODE_P (GET_MODE (value))
5656                                   ? RDIV_EXPR : TRUNC_DIV_EXPR,
5657                                   GET_MODE (value), op1, op2, target, 0);
5658           break;
5659         case MOD:
5660           return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
5661                                 target, 0);
5662           break;
5663         case UDIV:
5664           return expand_divmod (0, TRUNC_DIV_EXPR, GET_MODE (value), op1, op2,
5665                                 target, 1);
5666           break;
5667         case UMOD:
5668           return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
5669                                 target, 1);
5670           break;
5671         case ASHIFTRT:
5672           return expand_simple_binop (GET_MODE (value), code, op1, op2,
5673                                       target, 0, OPTAB_LIB_WIDEN);
5674           break;
5675         default:
5676           return expand_simple_binop (GET_MODE (value), code, op1, op2,
5677                                       target, 1, OPTAB_LIB_WIDEN);
5678         }
5679     }
5680   if (UNARY_P (value))
5681     {
5682       op1 = force_operand (XEXP (value, 0), NULL_RTX);
5683       return expand_simple_unop (GET_MODE (value), code, op1, target, 0);
5684     }
5685
5686 #ifdef INSN_SCHEDULING
5687   /* On machines that have insn scheduling, we want all memory reference to be
5688      explicit, so we need to deal with such paradoxical SUBREGs.  */
5689   if (GET_CODE (value) == SUBREG && GET_CODE (SUBREG_REG (value)) == MEM
5690       && (GET_MODE_SIZE (GET_MODE (value))
5691           > GET_MODE_SIZE (GET_MODE (SUBREG_REG (value)))))
5692     value
5693       = simplify_gen_subreg (GET_MODE (value),
5694                              force_reg (GET_MODE (SUBREG_REG (value)),
5695                                         force_operand (SUBREG_REG (value),
5696                                                        NULL_RTX)),
5697                              GET_MODE (SUBREG_REG (value)),
5698                              SUBREG_BYTE (value));
5699 #endif
5700
5701   return value;
5702 }
5703 \f
5704 /* Subroutine of expand_expr: return nonzero iff there is no way that
5705    EXP can reference X, which is being modified.  TOP_P is nonzero if this
5706    call is going to be used to determine whether we need a temporary
5707    for EXP, as opposed to a recursive call to this function.
5708
5709    It is always safe for this routine to return zero since it merely
5710    searches for optimization opportunities.  */
5711
5712 int
5713 safe_from_p (rtx x, tree exp, int top_p)
5714 {
5715   rtx exp_rtl = 0;
5716   int i, nops;
5717   static tree save_expr_list;
5718
5719   if (x == 0
5720       /* If EXP has varying size, we MUST use a target since we currently
5721          have no way of allocating temporaries of variable size
5722          (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
5723          So we assume here that something at a higher level has prevented a
5724          clash.  This is somewhat bogus, but the best we can do.  Only
5725          do this when X is BLKmode and when we are at the top level.  */
5726       || (top_p && TREE_TYPE (exp) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp))
5727           && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) != INTEGER_CST
5728           && (TREE_CODE (TREE_TYPE (exp)) != ARRAY_TYPE
5729               || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)) == NULL_TREE
5730               || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)))
5731               != INTEGER_CST)
5732           && GET_MODE (x) == BLKmode)
5733       /* If X is in the outgoing argument area, it is always safe.  */
5734       || (GET_CODE (x) == MEM
5735           && (XEXP (x, 0) == virtual_outgoing_args_rtx
5736               || (GET_CODE (XEXP (x, 0)) == PLUS
5737                   && XEXP (XEXP (x, 0), 0) == virtual_outgoing_args_rtx))))
5738     return 1;
5739
5740   /* If this is a subreg of a hard register, declare it unsafe, otherwise,
5741      find the underlying pseudo.  */
5742   if (GET_CODE (x) == SUBREG)
5743     {
5744       x = SUBREG_REG (x);
5745       if (GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER)
5746         return 0;
5747     }
5748
5749   /* A SAVE_EXPR might appear many times in the expression passed to the
5750      top-level safe_from_p call, and if it has a complex subexpression,
5751      examining it multiple times could result in a combinatorial explosion.
5752      E.g. on an Alpha running at least 200MHz, a Fortran testcase compiled
5753      with optimization took about 28 minutes to compile -- even though it was
5754      only a few lines long.  So we mark each SAVE_EXPR we see with TREE_PRIVATE
5755      and turn that off when we are done.  We keep a list of the SAVE_EXPRs
5756      we have processed.  Note that the only test of top_p was above.  */
5757
5758   if (top_p)
5759     {
5760       int rtn;
5761       tree t;
5762
5763       save_expr_list = 0;
5764
5765       rtn = safe_from_p (x, exp, 0);
5766
5767       for (t = save_expr_list; t != 0; t = TREE_CHAIN (t))
5768         TREE_PRIVATE (TREE_PURPOSE (t)) = 0;
5769
5770       return rtn;
5771     }
5772
5773   /* Now look at our tree code and possibly recurse.  */
5774   switch (TREE_CODE_CLASS (TREE_CODE (exp)))
5775     {
5776     case 'd':
5777       exp_rtl = DECL_RTL_IF_SET (exp);
5778       break;
5779
5780     case 'c':
5781       return 1;
5782
5783     case 'x':
5784       if (TREE_CODE (exp) == TREE_LIST)
5785         {
5786           while (1)
5787             {
5788               if (TREE_VALUE (exp) && !safe_from_p (x, TREE_VALUE (exp), 0))
5789                 return 0;
5790               exp = TREE_CHAIN (exp);
5791               if (!exp)
5792                 return 1;
5793               if (TREE_CODE (exp) != TREE_LIST)
5794                 return safe_from_p (x, exp, 0);
5795             }
5796         }
5797       else if (TREE_CODE (exp) == ERROR_MARK)
5798         return 1;       /* An already-visited SAVE_EXPR? */
5799       else
5800         return 0;
5801
5802     case '2':
5803     case '<':
5804       if (!safe_from_p (x, TREE_OPERAND (exp, 1), 0))
5805         return 0;
5806       /* Fall through.  */
5807
5808     case '1':
5809       return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
5810
5811     case 'e':
5812     case 'r':
5813       /* Now do code-specific tests.  EXP_RTL is set to any rtx we find in
5814          the expression.  If it is set, we conflict iff we are that rtx or
5815          both are in memory.  Otherwise, we check all operands of the
5816          expression recursively.  */
5817
5818       switch (TREE_CODE (exp))
5819         {
5820         case ADDR_EXPR:
5821           /* If the operand is static or we are static, we can't conflict.
5822              Likewise if we don't conflict with the operand at all.  */
5823           if (staticp (TREE_OPERAND (exp, 0))
5824               || TREE_STATIC (exp)
5825               || safe_from_p (x, TREE_OPERAND (exp, 0), 0))
5826             return 1;
5827
5828           /* Otherwise, the only way this can conflict is if we are taking
5829              the address of a DECL a that address if part of X, which is
5830              very rare.  */
5831           exp = TREE_OPERAND (exp, 0);
5832           if (DECL_P (exp))
5833             {
5834               if (!DECL_RTL_SET_P (exp)
5835                   || GET_CODE (DECL_RTL (exp)) != MEM)
5836                 return 0;
5837               else
5838                 exp_rtl = XEXP (DECL_RTL (exp), 0);
5839             }
5840           break;
5841
5842         case INDIRECT_REF:
5843           if (GET_CODE (x) == MEM
5844               && alias_sets_conflict_p (MEM_ALIAS_SET (x),
5845                                         get_alias_set (exp)))
5846             return 0;
5847           break;
5848
5849         case CALL_EXPR:
5850           /* Assume that the call will clobber all hard registers and
5851              all of memory.  */
5852           if ((GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER)
5853               || GET_CODE (x) == MEM)
5854             return 0;
5855           break;
5856
5857         case RTL_EXPR:
5858           /* If a sequence exists, we would have to scan every instruction
5859              in the sequence to see if it was safe.  This is probably not
5860              worthwhile.  */
5861           if (RTL_EXPR_SEQUENCE (exp))
5862             return 0;
5863
5864           exp_rtl = RTL_EXPR_RTL (exp);
5865           break;
5866
5867         case WITH_CLEANUP_EXPR:
5868           exp_rtl = WITH_CLEANUP_EXPR_RTL (exp);
5869           break;
5870
5871         case CLEANUP_POINT_EXPR:
5872           return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
5873
5874         case SAVE_EXPR:
5875           exp_rtl = SAVE_EXPR_RTL (exp);
5876           if (exp_rtl)
5877             break;
5878
5879           /* If we've already scanned this, don't do it again.  Otherwise,
5880              show we've scanned it and record for clearing the flag if we're
5881              going on.  */
5882           if (TREE_PRIVATE (exp))
5883             return 1;
5884
5885           TREE_PRIVATE (exp) = 1;
5886           if (! safe_from_p (x, TREE_OPERAND (exp, 0), 0))
5887             {
5888               TREE_PRIVATE (exp) = 0;
5889               return 0;
5890             }
5891
5892           save_expr_list = tree_cons (exp, NULL_TREE, save_expr_list);
5893           return 1;
5894
5895         case BIND_EXPR:
5896           /* The only operand we look at is operand 1.  The rest aren't
5897              part of the expression.  */
5898           return safe_from_p (x, TREE_OPERAND (exp, 1), 0);
5899
5900         default:
5901           break;
5902         }
5903
5904       /* If we have an rtx, we do not need to scan our operands.  */
5905       if (exp_rtl)
5906         break;
5907
5908       nops = first_rtl_op (TREE_CODE (exp));
5909       for (i = 0; i < nops; i++)
5910         if (TREE_OPERAND (exp, i) != 0
5911             && ! safe_from_p (x, TREE_OPERAND (exp, i), 0))
5912           return 0;
5913
5914       /* If this is a language-specific tree code, it may require
5915          special handling.  */
5916       if ((unsigned int) TREE_CODE (exp)
5917           >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
5918           && !lang_hooks.safe_from_p (x, exp))
5919         return 0;
5920     }
5921
5922   /* If we have an rtl, find any enclosed object.  Then see if we conflict
5923      with it.  */
5924   if (exp_rtl)
5925     {
5926       if (GET_CODE (exp_rtl) == SUBREG)
5927         {
5928           exp_rtl = SUBREG_REG (exp_rtl);
5929           if (GET_CODE (exp_rtl) == REG
5930               && REGNO (exp_rtl) < FIRST_PSEUDO_REGISTER)
5931             return 0;
5932         }
5933
5934       /* If the rtl is X, then it is not safe.  Otherwise, it is unless both
5935          are memory and they conflict.  */
5936       return ! (rtx_equal_p (x, exp_rtl)
5937                 || (GET_CODE (x) == MEM && GET_CODE (exp_rtl) == MEM
5938                     && true_dependence (exp_rtl, VOIDmode, x,
5939                                         rtx_addr_varies_p)));
5940     }
5941
5942   /* If we reach here, it is safe.  */
5943   return 1;
5944 }
5945
5946 /* Subroutine of expand_expr: return rtx if EXP is a
5947    variable or parameter; else return 0.  */
5948
5949 static rtx
5950 var_rtx (tree exp)
5951 {
5952   STRIP_NOPS (exp);
5953   switch (TREE_CODE (exp))
5954     {
5955     case PARM_DECL:
5956     case VAR_DECL:
5957       return DECL_RTL (exp);
5958     default:
5959       return 0;
5960     }
5961 }
5962 \f
5963 /* Return the highest power of two that EXP is known to be a multiple of.
5964    This is used in updating alignment of MEMs in array references.  */
5965
5966 static unsigned HOST_WIDE_INT
5967 highest_pow2_factor (tree exp)
5968 {
5969   unsigned HOST_WIDE_INT c0, c1;
5970
5971   switch (TREE_CODE (exp))
5972     {
5973     case INTEGER_CST:
5974       /* We can find the lowest bit that's a one.  If the low
5975          HOST_BITS_PER_WIDE_INT bits are zero, return BIGGEST_ALIGNMENT.
5976          We need to handle this case since we can find it in a COND_EXPR,
5977          a MIN_EXPR, or a MAX_EXPR.  If the constant overflows, we have an
5978          erroneous program, so return BIGGEST_ALIGNMENT to avoid any
5979          later ICE.  */
5980       if (TREE_CONSTANT_OVERFLOW (exp))
5981         return BIGGEST_ALIGNMENT;
5982       else
5983         {
5984           /* Note: tree_low_cst is intentionally not used here,
5985              we don't care about the upper bits.  */
5986           c0 = TREE_INT_CST_LOW (exp);
5987           c0 &= -c0;
5988           return c0 ? c0 : BIGGEST_ALIGNMENT;
5989         }
5990       break;
5991
5992     case PLUS_EXPR:  case MINUS_EXPR:  case MIN_EXPR:  case MAX_EXPR:
5993       c0 = highest_pow2_factor (TREE_OPERAND (exp, 0));
5994       c1 = highest_pow2_factor (TREE_OPERAND (exp, 1));
5995       return MIN (c0, c1);
5996
5997     case MULT_EXPR:
5998       c0 = highest_pow2_factor (TREE_OPERAND (exp, 0));
5999       c1 = highest_pow2_factor (TREE_OPERAND (exp, 1));
6000       return c0 * c1;
6001
6002     case ROUND_DIV_EXPR:  case TRUNC_DIV_EXPR:  case FLOOR_DIV_EXPR:
6003     case CEIL_DIV_EXPR:
6004       if (integer_pow2p (TREE_OPERAND (exp, 1))
6005           && host_integerp (TREE_OPERAND (exp, 1), 1))
6006         {
6007           c0 = highest_pow2_factor (TREE_OPERAND (exp, 0));
6008           c1 = tree_low_cst (TREE_OPERAND (exp, 1), 1);
6009           return MAX (1, c0 / c1);
6010         }
6011       break;
6012
6013     case NON_LVALUE_EXPR:  case NOP_EXPR:  case CONVERT_EXPR:
6014     case SAVE_EXPR:
6015       return highest_pow2_factor (TREE_OPERAND (exp, 0));
6016
6017     case COMPOUND_EXPR:
6018       return highest_pow2_factor (TREE_OPERAND (exp, 1));
6019
6020     case COND_EXPR:
6021       c0 = highest_pow2_factor (TREE_OPERAND (exp, 1));
6022       c1 = highest_pow2_factor (TREE_OPERAND (exp, 2));
6023       return MIN (c0, c1);
6024
6025     default:
6026       break;
6027     }
6028
6029   return 1;
6030 }
6031
6032 /* Similar, except that the alignment requirements of TARGET are
6033    taken into account.  Assume it is at least as aligned as its
6034    type, unless it is a COMPONENT_REF in which case the layout of
6035    the structure gives the alignment.  */
6036
6037 static unsigned HOST_WIDE_INT
6038 highest_pow2_factor_for_target (tree target, tree exp)
6039 {
6040   unsigned HOST_WIDE_INT target_align, factor;
6041
6042   factor = highest_pow2_factor (exp);
6043   if (TREE_CODE (target) == COMPONENT_REF)
6044     target_align = DECL_ALIGN (TREE_OPERAND (target, 1)) / BITS_PER_UNIT;
6045   else
6046     target_align = TYPE_ALIGN (TREE_TYPE (target)) / BITS_PER_UNIT;
6047   return MAX (factor, target_align);
6048 }
6049 \f
6050 /* Subroutine of expand_expr.  Expand the two operands of a binary
6051    expression EXP0 and EXP1 placing the results in OP0 and OP1.
6052    The value may be stored in TARGET if TARGET is nonzero.  The
6053    MODIFIER argument is as documented by expand_expr.  */
6054
6055 static void
6056 expand_operands (tree exp0, tree exp1, rtx target, rtx *op0, rtx *op1,
6057                  enum expand_modifier modifier)
6058 {
6059   if (! safe_from_p (target, exp1, 1))
6060     target = 0;
6061   if (operand_equal_p (exp0, exp1, 0))
6062     {
6063       *op0 = expand_expr (exp0, target, VOIDmode, modifier);
6064       *op1 = copy_rtx (*op0);
6065     }
6066   else
6067     {
6068       /* If we need to preserve evaluation order, copy exp0 into its own
6069          temporary variable so that it can't be clobbered by exp1.  */
6070       if (flag_evaluation_order && TREE_SIDE_EFFECTS (exp1))
6071         exp0 = save_expr (exp0);
6072       *op0 = expand_expr (exp0, target, VOIDmode, modifier);
6073       *op1 = expand_expr (exp1, NULL_RTX, VOIDmode, modifier);
6074     }
6075 }
6076
6077 \f
6078 /* expand_expr: generate code for computing expression EXP.
6079    An rtx for the computed value is returned.  The value is never null.
6080    In the case of a void EXP, const0_rtx is returned.
6081
6082    The value may be stored in TARGET if TARGET is nonzero.
6083    TARGET is just a suggestion; callers must assume that
6084    the rtx returned may not be the same as TARGET.
6085
6086    If TARGET is CONST0_RTX, it means that the value will be ignored.
6087
6088    If TMODE is not VOIDmode, it suggests generating the
6089    result in mode TMODE.  But this is done only when convenient.
6090    Otherwise, TMODE is ignored and the value generated in its natural mode.
6091    TMODE is just a suggestion; callers must assume that
6092    the rtx returned may not have mode TMODE.
6093
6094    Note that TARGET may have neither TMODE nor MODE.  In that case, it
6095    probably will not be used.
6096
6097    If MODIFIER is EXPAND_SUM then when EXP is an addition
6098    we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
6099    or a nest of (PLUS ...) and (MINUS ...) where the terms are
6100    products as above, or REG or MEM, or constant.
6101    Ordinarily in such cases we would output mul or add instructions
6102    and then return a pseudo reg containing the sum.
6103
6104    EXPAND_INITIALIZER is much like EXPAND_SUM except that
6105    it also marks a label as absolutely required (it can't be dead).
6106    It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
6107    This is used for outputting expressions used in initializers.
6108
6109    EXPAND_CONST_ADDRESS says that it is okay to return a MEM
6110    with a constant address even if that address is not normally legitimate.
6111    EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
6112
6113    EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
6114    a call parameter.  Such targets require special care as we haven't yet
6115    marked TARGET so that it's safe from being trashed by libcalls.  We
6116    don't want to use TARGET for anything but the final result;
6117    Intermediate values must go elsewhere.   Additionally, calls to
6118    emit_block_move will be flagged with BLOCK_OP_CALL_PARM.  
6119
6120    If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
6121    address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
6122    DECL_RTL of the VAR_DECL.  *ALT_RTL is also set if EXP is a
6123    COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
6124    recursively.  */
6125
6126 rtx
6127 expand_expr_real (tree exp, rtx target, enum machine_mode tmode,
6128                   enum expand_modifier modifier, rtx *alt_rtl)
6129 {
6130   rtx op0, op1, temp;
6131   tree type = TREE_TYPE (exp);
6132   int unsignedp = TREE_UNSIGNED (type);
6133   enum machine_mode mode;
6134   enum tree_code code = TREE_CODE (exp);
6135   optab this_optab;
6136   rtx subtarget, original_target;
6137   int ignore;
6138   tree context;
6139
6140   /* Handle ERROR_MARK before anybody tries to access its type.  */
6141   if (TREE_CODE (exp) == ERROR_MARK || TREE_CODE (type) == ERROR_MARK)
6142     {
6143       op0 = CONST0_RTX (tmode);
6144       if (op0 != 0)
6145         return op0;
6146       return const0_rtx;
6147     }
6148
6149   mode = TYPE_MODE (type);
6150   /* Use subtarget as the target for operand 0 of a binary operation.  */
6151   subtarget = get_subtarget (target);
6152   original_target = target;
6153   ignore = (target == const0_rtx
6154             || ((code == NON_LVALUE_EXPR || code == NOP_EXPR
6155                  || code == CONVERT_EXPR || code == REFERENCE_EXPR
6156                  || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
6157                 && TREE_CODE (type) == VOID_TYPE));
6158
6159   /* If we are going to ignore this result, we need only do something
6160      if there is a side-effect somewhere in the expression.  If there
6161      is, short-circuit the most common cases here.  Note that we must
6162      not call expand_expr with anything but const0_rtx in case this
6163      is an initial expansion of a size that contains a PLACEHOLDER_EXPR.  */
6164
6165   if (ignore)
6166     {
6167       if (! TREE_SIDE_EFFECTS (exp))
6168         return const0_rtx;
6169
6170       /* Ensure we reference a volatile object even if value is ignored, but
6171          don't do this if all we are doing is taking its address.  */
6172       if (TREE_THIS_VOLATILE (exp)
6173           && TREE_CODE (exp) != FUNCTION_DECL
6174           && mode != VOIDmode && mode != BLKmode
6175           && modifier != EXPAND_CONST_ADDRESS)
6176         {
6177           temp = expand_expr (exp, NULL_RTX, VOIDmode, modifier);
6178           if (GET_CODE (temp) == MEM)
6179             temp = copy_to_reg (temp);
6180           return const0_rtx;
6181         }
6182
6183       if (TREE_CODE_CLASS (code) == '1' || code == COMPONENT_REF
6184           || code == INDIRECT_REF || code == BUFFER_REF)
6185         return expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
6186                             modifier);
6187
6188       else if (TREE_CODE_CLASS (code) == '2' || TREE_CODE_CLASS (code) == '<'
6189                || code == ARRAY_REF || code == ARRAY_RANGE_REF)
6190         {
6191           expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, modifier);
6192           expand_expr (TREE_OPERAND (exp, 1), const0_rtx, VOIDmode, modifier);
6193           return const0_rtx;
6194         }
6195       else if ((code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR)
6196                && ! TREE_SIDE_EFFECTS (TREE_OPERAND (exp, 1)))
6197         /* If the second operand has no side effects, just evaluate
6198            the first.  */
6199         return expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
6200                             modifier);
6201       else if (code == BIT_FIELD_REF)
6202         {
6203           expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, modifier);
6204           expand_expr (TREE_OPERAND (exp, 1), const0_rtx, VOIDmode, modifier);
6205           expand_expr (TREE_OPERAND (exp, 2), const0_rtx, VOIDmode, modifier);
6206           return const0_rtx;
6207         }
6208
6209       target = 0;
6210     }
6211
6212   /* If will do cse, generate all results into pseudo registers
6213      since 1) that allows cse to find more things
6214      and 2) otherwise cse could produce an insn the machine
6215      cannot support.  An exception is a CONSTRUCTOR into a multi-word
6216      MEM: that's much more likely to be most efficient into the MEM.
6217      Another is a CALL_EXPR which must return in memory.  */
6218
6219   if (! cse_not_expected && mode != BLKmode && target
6220       && (GET_CODE (target) != REG || REGNO (target) < FIRST_PSEUDO_REGISTER)
6221       && ! (code == CONSTRUCTOR && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
6222       && ! (code == CALL_EXPR && aggregate_value_p (exp, exp)))
6223     target = 0;
6224
6225   switch (code)
6226     {
6227     case LABEL_DECL:
6228       {
6229         tree function = decl_function_context (exp);
6230         /* Labels in containing functions, or labels used from initializers,
6231            must be forced.  */
6232         if (modifier == EXPAND_INITIALIZER
6233             || (function != current_function_decl
6234                 && function != inline_function_decl
6235                 && function != 0))
6236           temp = force_label_rtx (exp);
6237         else
6238           temp = label_rtx (exp);
6239
6240         temp = gen_rtx_MEM (FUNCTION_MODE, gen_rtx_LABEL_REF (Pmode, temp));
6241         if (function != current_function_decl
6242             && function != inline_function_decl && function != 0)
6243           LABEL_REF_NONLOCAL_P (XEXP (temp, 0)) = 1;
6244         return temp;
6245       }
6246
6247     case PARM_DECL:
6248       if (!DECL_RTL_SET_P (exp))
6249         {
6250           error ("%Jprior parameter's size depends on '%D'", exp, exp);
6251           return CONST0_RTX (mode);
6252         }
6253
6254       /* ... fall through ...  */
6255
6256     case VAR_DECL:
6257       /* If a static var's type was incomplete when the decl was written,
6258          but the type is complete now, lay out the decl now.  */
6259       if (DECL_SIZE (exp) == 0
6260           && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp))
6261           && (TREE_STATIC (exp) || DECL_EXTERNAL (exp)))
6262         layout_decl (exp, 0);
6263
6264       /* ... fall through ...  */
6265
6266     case FUNCTION_DECL:
6267     case RESULT_DECL:
6268       if (DECL_RTL (exp) == 0)
6269         abort ();
6270
6271       /* Ensure variable marked as used even if it doesn't go through
6272          a parser.  If it hasn't be used yet, write out an external
6273          definition.  */
6274       if (! TREE_USED (exp))
6275         {
6276           assemble_external (exp);
6277           TREE_USED (exp) = 1;
6278         }
6279
6280       /* Show we haven't gotten RTL for this yet.  */
6281       temp = 0;
6282
6283       /* Handle variables inherited from containing functions.  */
6284       context = decl_function_context (exp);
6285
6286       /* We treat inline_function_decl as an alias for the current function
6287          because that is the inline function whose vars, types, etc.
6288          are being merged into the current function.
6289          See expand_inline_function.  */
6290
6291       if (context != 0 && context != current_function_decl
6292           && context != inline_function_decl
6293           /* If var is static, we don't need a static chain to access it.  */
6294           && ! (GET_CODE (DECL_RTL (exp)) == MEM
6295                 && CONSTANT_P (XEXP (DECL_RTL (exp), 0))))
6296         {
6297           rtx addr;
6298
6299           /* Mark as non-local and addressable.  */
6300           DECL_NONLOCAL (exp) = 1;
6301           if (DECL_NO_STATIC_CHAIN (current_function_decl))
6302             abort ();
6303           lang_hooks.mark_addressable (exp);
6304           if (GET_CODE (DECL_RTL (exp)) != MEM)
6305             abort ();
6306           addr = XEXP (DECL_RTL (exp), 0);
6307           if (GET_CODE (addr) == MEM)
6308             addr
6309               = replace_equiv_address (addr,
6310                                        fix_lexical_addr (XEXP (addr, 0), exp));
6311           else
6312             addr = fix_lexical_addr (addr, exp);
6313
6314           temp = replace_equiv_address (DECL_RTL (exp), addr);
6315         }
6316
6317       /* This is the case of an array whose size is to be determined
6318          from its initializer, while the initializer is still being parsed.
6319          See expand_decl.  */
6320
6321       else if (GET_CODE (DECL_RTL (exp)) == MEM
6322                && GET_CODE (XEXP (DECL_RTL (exp), 0)) == REG)
6323         temp = validize_mem (DECL_RTL (exp));
6324
6325       /* If DECL_RTL is memory, we are in the normal case and either
6326          the address is not valid or it is not a register and -fforce-addr
6327          is specified, get the address into a register.  */
6328
6329       else if (GET_CODE (DECL_RTL (exp)) == MEM
6330                && modifier != EXPAND_CONST_ADDRESS
6331                && modifier != EXPAND_SUM
6332                && modifier != EXPAND_INITIALIZER
6333                && (! memory_address_p (DECL_MODE (exp),
6334                                        XEXP (DECL_RTL (exp), 0))
6335                    || (flag_force_addr
6336                        && GET_CODE (XEXP (DECL_RTL (exp), 0)) != REG)))
6337         {
6338           if (alt_rtl)
6339             *alt_rtl = DECL_RTL (exp);
6340           temp = replace_equiv_address (DECL_RTL (exp),
6341                                         copy_rtx (XEXP (DECL_RTL (exp), 0)));
6342         }
6343
6344       /* If we got something, return it.  But first, set the alignment
6345          if the address is a register.  */
6346       if (temp != 0)
6347         {
6348           if (GET_CODE (temp) == MEM && GET_CODE (XEXP (temp, 0)) == REG)
6349             mark_reg_pointer (XEXP (temp, 0), DECL_ALIGN (exp));
6350
6351           return temp;
6352         }
6353
6354       /* If the mode of DECL_RTL does not match that of the decl, it
6355          must be a promoted value.  We return a SUBREG of the wanted mode,
6356          but mark it so that we know that it was already extended.  */
6357
6358       if (GET_CODE (DECL_RTL (exp)) == REG
6359           && GET_MODE (DECL_RTL (exp)) != DECL_MODE (exp))
6360         {
6361           /* Get the signedness used for this variable.  Ensure we get the
6362              same mode we got when the variable was declared.  */
6363           if (GET_MODE (DECL_RTL (exp))
6364               != promote_mode (type, DECL_MODE (exp), &unsignedp,
6365                                (TREE_CODE (exp) == RESULT_DECL ? 1 : 0)))
6366             abort ();
6367
6368           temp = gen_lowpart_SUBREG (mode, DECL_RTL (exp));
6369           SUBREG_PROMOTED_VAR_P (temp) = 1;
6370           SUBREG_PROMOTED_UNSIGNED_SET (temp, unsignedp);
6371           return temp;
6372         }
6373
6374       return DECL_RTL (exp);
6375
6376     case INTEGER_CST:
6377       temp = immed_double_const (TREE_INT_CST_LOW (exp),
6378                                  TREE_INT_CST_HIGH (exp), mode);
6379
6380       /* ??? If overflow is set, fold will have done an incomplete job,
6381          which can result in (plus xx (const_int 0)), which can get
6382          simplified by validate_replace_rtx during virtual register
6383          instantiation, which can result in unrecognizable insns.
6384          Avoid this by forcing all overflows into registers.  */
6385       if (TREE_CONSTANT_OVERFLOW (exp)
6386           && modifier != EXPAND_INITIALIZER)
6387         temp = force_reg (mode, temp);
6388
6389       return temp;
6390
6391     case VECTOR_CST:
6392       return const_vector_from_tree (exp);
6393
6394     case CONST_DECL:
6395       return expand_expr (DECL_INITIAL (exp), target, VOIDmode, modifier);
6396
6397     case REAL_CST:
6398       /* If optimized, generate immediate CONST_DOUBLE
6399          which will be turned into memory by reload if necessary.
6400
6401          We used to force a register so that loop.c could see it.  But
6402          this does not allow gen_* patterns to perform optimizations with
6403          the constants.  It also produces two insns in cases like "x = 1.0;".
6404          On most machines, floating-point constants are not permitted in
6405          many insns, so we'd end up copying it to a register in any case.
6406
6407          Now, we do the copying in expand_binop, if appropriate.  */
6408       return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp),
6409                                            TYPE_MODE (TREE_TYPE (exp)));
6410
6411     case COMPLEX_CST:
6412       /* Handle evaluating a complex constant in a CONCAT target.  */
6413       if (original_target && GET_CODE (original_target) == CONCAT)
6414         {
6415           enum machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
6416           rtx rtarg, itarg;
6417
6418           rtarg = XEXP (original_target, 0);
6419           itarg = XEXP (original_target, 1);
6420
6421           /* Move the real and imaginary parts separately.  */
6422           op0 = expand_expr (TREE_REALPART (exp), rtarg, mode, 0);
6423           op1 = expand_expr (TREE_IMAGPART (exp), itarg, mode, 0);
6424
6425           if (op0 != rtarg)
6426             emit_move_insn (rtarg, op0);
6427           if (op1 != itarg)
6428             emit_move_insn (itarg, op1);
6429
6430           return original_target;
6431         }
6432
6433       /* ... fall through ...  */
6434
6435     case STRING_CST:
6436       temp = output_constant_def (exp, 1);
6437
6438       /* temp contains a constant address.
6439          On RISC machines where a constant address isn't valid,
6440          make some insns to get that address into a register.  */
6441       if (modifier != EXPAND_CONST_ADDRESS
6442           && modifier != EXPAND_INITIALIZER
6443           && modifier != EXPAND_SUM
6444           && (! memory_address_p (mode, XEXP (temp, 0))
6445               || flag_force_addr))
6446         return replace_equiv_address (temp,
6447                                       copy_rtx (XEXP (temp, 0)));
6448       return temp;
6449
6450     case EXPR_WITH_FILE_LOCATION:
6451       {
6452         rtx to_return;
6453         struct file_stack fs;
6454
6455         fs.location = input_location;
6456         fs.next = expr_wfl_stack;
6457         input_filename = EXPR_WFL_FILENAME (exp);
6458         input_line = EXPR_WFL_LINENO (exp);
6459         expr_wfl_stack = &fs;
6460         if (EXPR_WFL_EMIT_LINE_NOTE (exp))
6461           emit_line_note (input_location);
6462         /* Possibly avoid switching back and forth here.  */
6463         to_return = expand_expr (EXPR_WFL_NODE (exp),
6464                                  (ignore ? const0_rtx : target),
6465                                  tmode, modifier);
6466         if (expr_wfl_stack != &fs)
6467           abort ();
6468         input_location = fs.location;
6469         expr_wfl_stack = fs.next;
6470         return to_return;
6471       }
6472
6473     case SAVE_EXPR:
6474       context = decl_function_context (exp);
6475
6476       /* If this SAVE_EXPR was at global context, assume we are an
6477          initialization function and move it into our context.  */
6478       if (context == 0)
6479         SAVE_EXPR_CONTEXT (exp) = current_function_decl;
6480
6481       /* We treat inline_function_decl as an alias for the current function
6482          because that is the inline function whose vars, types, etc.
6483          are being merged into the current function.
6484          See expand_inline_function.  */
6485       if (context == current_function_decl || context == inline_function_decl)
6486         context = 0;
6487
6488       /* If this is non-local, handle it.  */
6489       if (context)
6490         {
6491           /* The following call just exists to abort if the context is
6492              not of a containing function.  */
6493           find_function_data (context);
6494
6495           temp = SAVE_EXPR_RTL (exp);
6496           if (temp && GET_CODE (temp) == REG)
6497             {
6498               put_var_into_stack (exp, /*rescan=*/true);
6499               temp = SAVE_EXPR_RTL (exp);
6500             }
6501           if (temp == 0 || GET_CODE (temp) != MEM)
6502             abort ();
6503           return
6504             replace_equiv_address (temp,
6505                                    fix_lexical_addr (XEXP (temp, 0), exp));
6506         }
6507       if (SAVE_EXPR_RTL (exp) == 0)
6508         {
6509           if (mode == VOIDmode)
6510             temp = const0_rtx;
6511           else
6512             temp = assign_temp (build_qualified_type (type,
6513                                                       (TYPE_QUALS (type)
6514                                                        | TYPE_QUAL_CONST)),
6515                                 3, 0, 0);
6516
6517           SAVE_EXPR_RTL (exp) = temp;
6518           if (!optimize && GET_CODE (temp) == REG)
6519             save_expr_regs = gen_rtx_EXPR_LIST (VOIDmode, temp,
6520                                                 save_expr_regs);
6521
6522           /* If the mode of TEMP does not match that of the expression, it
6523              must be a promoted value.  We pass store_expr a SUBREG of the
6524              wanted mode but mark it so that we know that it was already
6525              extended.  */
6526
6527           if (GET_CODE (temp) == REG && GET_MODE (temp) != mode)
6528             {
6529               temp = gen_lowpart_SUBREG (mode, SAVE_EXPR_RTL (exp));
6530               promote_mode (type, mode, &unsignedp, 0);
6531               SUBREG_PROMOTED_VAR_P (temp) = 1;
6532               SUBREG_PROMOTED_UNSIGNED_SET (temp, unsignedp);
6533             }
6534
6535           if (temp == const0_rtx)
6536             expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
6537           else
6538             store_expr (TREE_OPERAND (exp, 0), temp,
6539                         modifier == EXPAND_STACK_PARM ? 2 : 0);
6540
6541           TREE_USED (exp) = 1;
6542         }
6543
6544       /* If the mode of SAVE_EXPR_RTL does not match that of the expression, it
6545          must be a promoted value.  We return a SUBREG of the wanted mode,
6546          but mark it so that we know that it was already extended.  */
6547
6548       if (GET_CODE (SAVE_EXPR_RTL (exp)) == REG
6549           && GET_MODE (SAVE_EXPR_RTL (exp)) != mode)
6550         {
6551           /* Compute the signedness and make the proper SUBREG.  */
6552           promote_mode (type, mode, &unsignedp, 0);
6553           temp = gen_lowpart_SUBREG (mode, SAVE_EXPR_RTL (exp));
6554           SUBREG_PROMOTED_VAR_P (temp) = 1;
6555           SUBREG_PROMOTED_UNSIGNED_SET (temp, unsignedp);
6556           return temp;
6557         }
6558
6559       return SAVE_EXPR_RTL (exp);
6560
6561     case UNSAVE_EXPR:
6562       {
6563         rtx temp;
6564         temp = expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
6565         TREE_OPERAND (exp, 0)
6566           = lang_hooks.unsave_expr_now (TREE_OPERAND (exp, 0));
6567         return temp;
6568       }
6569
6570     case GOTO_EXPR:
6571       if (TREE_CODE (TREE_OPERAND (exp, 0)) == LABEL_DECL)
6572         expand_goto (TREE_OPERAND (exp, 0));
6573       else
6574         expand_computed_goto (TREE_OPERAND (exp, 0));
6575       return const0_rtx;
6576
6577     case EXIT_EXPR:
6578       expand_exit_loop_if_false (NULL,
6579                                  invert_truthvalue (TREE_OPERAND (exp, 0)));
6580       return const0_rtx;
6581
6582     case LABELED_BLOCK_EXPR:
6583       if (LABELED_BLOCK_BODY (exp))
6584         expand_expr_stmt_value (LABELED_BLOCK_BODY (exp), 0, 1);
6585       /* Should perhaps use expand_label, but this is simpler and safer.  */
6586       do_pending_stack_adjust ();
6587       emit_label (label_rtx (LABELED_BLOCK_LABEL (exp)));
6588       return const0_rtx;
6589
6590     case EXIT_BLOCK_EXPR:
6591       if (EXIT_BLOCK_RETURN (exp))
6592         sorry ("returned value in block_exit_expr");
6593       expand_goto (LABELED_BLOCK_LABEL (EXIT_BLOCK_LABELED_BLOCK (exp)));
6594       return const0_rtx;
6595
6596     case LOOP_EXPR:
6597       push_temp_slots ();
6598       expand_start_loop (1);
6599       expand_expr_stmt_value (TREE_OPERAND (exp, 0), 0, 1);
6600       expand_end_loop ();
6601       pop_temp_slots ();
6602
6603       return const0_rtx;
6604
6605     case BIND_EXPR:
6606       {
6607         tree vars = TREE_OPERAND (exp, 0);
6608
6609         /* Need to open a binding contour here because
6610            if there are any cleanups they must be contained here.  */
6611         expand_start_bindings (2);
6612
6613         /* Mark the corresponding BLOCK for output in its proper place.  */
6614         if (TREE_OPERAND (exp, 2) != 0
6615             && ! TREE_USED (TREE_OPERAND (exp, 2)))
6616           lang_hooks.decls.insert_block (TREE_OPERAND (exp, 2));
6617
6618         /* If VARS have not yet been expanded, expand them now.  */
6619         while (vars)
6620           {
6621             if (!DECL_RTL_SET_P (vars))
6622               expand_decl (vars);
6623             expand_decl_init (vars);
6624             vars = TREE_CHAIN (vars);
6625           }
6626
6627         temp = expand_expr (TREE_OPERAND (exp, 1), target, tmode, modifier);
6628
6629         expand_end_bindings (TREE_OPERAND (exp, 0), 0, 0);
6630
6631         return temp;
6632       }
6633
6634     case RTL_EXPR:
6635       if (RTL_EXPR_SEQUENCE (exp))
6636         {
6637           if (RTL_EXPR_SEQUENCE (exp) == const0_rtx)
6638             abort ();
6639           emit_insn (RTL_EXPR_SEQUENCE (exp));
6640           RTL_EXPR_SEQUENCE (exp) = const0_rtx;
6641         }
6642       preserve_rtl_expr_result (RTL_EXPR_RTL (exp));
6643       free_temps_for_rtl_expr (exp);
6644       if (alt_rtl)
6645         *alt_rtl = RTL_EXPR_ALT_RTL (exp);
6646       return RTL_EXPR_RTL (exp);
6647
6648     case CONSTRUCTOR:
6649       /* If we don't need the result, just ensure we evaluate any
6650          subexpressions.  */
6651       if (ignore)
6652         {
6653           tree elt;
6654
6655           for (elt = CONSTRUCTOR_ELTS (exp); elt; elt = TREE_CHAIN (elt))
6656             expand_expr (TREE_VALUE (elt), const0_rtx, VOIDmode, 0);
6657
6658           return const0_rtx;
6659         }
6660
6661       /* All elts simple constants => refer to a constant in memory.  But
6662          if this is a non-BLKmode mode, let it store a field at a time
6663          since that should make a CONST_INT or CONST_DOUBLE when we
6664          fold.  Likewise, if we have a target we can use, it is best to
6665          store directly into the target unless the type is large enough
6666          that memcpy will be used.  If we are making an initializer and
6667          all operands are constant, put it in memory as well.
6668
6669         FIXME: Avoid trying to fill vector constructors piece-meal.
6670         Output them with output_constant_def below unless we're sure
6671         they're zeros.  This should go away when vector initializers
6672         are treated like VECTOR_CST instead of arrays.
6673       */
6674       else if ((TREE_STATIC (exp)
6675                 && ((mode == BLKmode
6676                      && ! (target != 0 && safe_from_p (target, exp, 1)))
6677                     || TREE_ADDRESSABLE (exp)
6678                     || (host_integerp (TYPE_SIZE_UNIT (type), 1)
6679                         && (! MOVE_BY_PIECES_P
6680                             (tree_low_cst (TYPE_SIZE_UNIT (type), 1),
6681                              TYPE_ALIGN (type)))
6682                         && ((TREE_CODE (type) == VECTOR_TYPE
6683                              && !is_zeros_p (exp))
6684                             || ! mostly_zeros_p (exp)))))
6685                || ((modifier == EXPAND_INITIALIZER
6686                     || modifier == EXPAND_CONST_ADDRESS)
6687                    && TREE_CONSTANT (exp)))
6688         {
6689           rtx constructor = output_constant_def (exp, 1);
6690
6691           if (modifier != EXPAND_CONST_ADDRESS
6692               && modifier != EXPAND_INITIALIZER
6693               && modifier != EXPAND_SUM)
6694             constructor = validize_mem (constructor);
6695
6696           return constructor;
6697         }
6698       else
6699         {
6700           /* Handle calls that pass values in multiple non-contiguous
6701              locations.  The Irix 6 ABI has examples of this.  */
6702           if (target == 0 || ! safe_from_p (target, exp, 1)
6703               || GET_CODE (target) == PARALLEL
6704               || modifier == EXPAND_STACK_PARM)
6705             target
6706               = assign_temp (build_qualified_type (type,
6707                                                    (TYPE_QUALS (type)
6708                                                     | (TREE_READONLY (exp)
6709                                                        * TYPE_QUAL_CONST))),
6710                              0, TREE_ADDRESSABLE (exp), 1);
6711
6712           store_constructor (exp, target, 0, int_expr_size (exp));
6713           return target;
6714         }
6715
6716     case INDIRECT_REF:
6717       {
6718         tree exp1 = TREE_OPERAND (exp, 0);
6719         tree index;
6720         tree string = string_constant (exp1, &index);
6721
6722         /* Try to optimize reads from const strings.  */
6723         if (string
6724             && TREE_CODE (string) == STRING_CST
6725             && TREE_CODE (index) == INTEGER_CST
6726             && compare_tree_int (index, TREE_STRING_LENGTH (string)) < 0
6727             && GET_MODE_CLASS (mode) == MODE_INT
6728             && GET_MODE_SIZE (mode) == 1
6729             && modifier != EXPAND_WRITE)
6730           return gen_int_mode (TREE_STRING_POINTER (string)
6731                                [TREE_INT_CST_LOW (index)], mode);
6732
6733         op0 = expand_expr (exp1, NULL_RTX, VOIDmode, EXPAND_SUM);
6734         op0 = memory_address (mode, op0);
6735         temp = gen_rtx_MEM (mode, op0);
6736         set_mem_attributes (temp, exp, 0);
6737
6738         /* If we are writing to this object and its type is a record with
6739            readonly fields, we must mark it as readonly so it will
6740            conflict with readonly references to those fields.  */
6741         if (modifier == EXPAND_WRITE && readonly_fields_p (type))
6742           RTX_UNCHANGING_P (temp) = 1;
6743
6744         return temp;
6745       }
6746
6747     case ARRAY_REF:
6748       if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) != ARRAY_TYPE)
6749         abort ();
6750
6751       {
6752         tree array = TREE_OPERAND (exp, 0);
6753         tree domain = TYPE_DOMAIN (TREE_TYPE (array));
6754         tree low_bound = domain ? TYPE_MIN_VALUE (domain) : integer_zero_node;
6755         tree index = convert (sizetype, TREE_OPERAND (exp, 1));
6756         HOST_WIDE_INT i;
6757
6758         /* Optimize the special-case of a zero lower bound.
6759
6760            We convert the low_bound to sizetype to avoid some problems
6761            with constant folding.  (E.g. suppose the lower bound is 1,
6762            and its mode is QI.  Without the conversion,  (ARRAY
6763            +(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1))
6764            +INDEX), which becomes (ARRAY+255+INDEX).  Oops!)  */
6765
6766         if (! integer_zerop (low_bound))
6767           index = size_diffop (index, convert (sizetype, low_bound));
6768
6769         /* Fold an expression like: "foo"[2].
6770            This is not done in fold so it won't happen inside &.
6771            Don't fold if this is for wide characters since it's too
6772            difficult to do correctly and this is a very rare case.  */
6773
6774         if (modifier != EXPAND_CONST_ADDRESS
6775             && modifier != EXPAND_INITIALIZER
6776             && modifier != EXPAND_MEMORY
6777             && TREE_CODE (array) == STRING_CST
6778             && TREE_CODE (index) == INTEGER_CST
6779             && compare_tree_int (index, TREE_STRING_LENGTH (array)) < 0
6780             && GET_MODE_CLASS (mode) == MODE_INT
6781             && GET_MODE_SIZE (mode) == 1)
6782           return gen_int_mode (TREE_STRING_POINTER (array)
6783                                [TREE_INT_CST_LOW (index)], mode);
6784
6785         /* If this is a constant index into a constant array,
6786            just get the value from the array.  Handle both the cases when
6787            we have an explicit constructor and when our operand is a variable
6788            that was declared const.  */
6789
6790         if (modifier != EXPAND_CONST_ADDRESS
6791             && modifier != EXPAND_INITIALIZER
6792             && modifier != EXPAND_MEMORY
6793             && TREE_CODE (array) == CONSTRUCTOR
6794             && ! TREE_SIDE_EFFECTS (array)
6795             && TREE_CODE (index) == INTEGER_CST
6796             && 0 > compare_tree_int (index,
6797                                      list_length (CONSTRUCTOR_ELTS
6798                                                   (TREE_OPERAND (exp, 0)))))
6799           {
6800             tree elem;
6801
6802             for (elem = CONSTRUCTOR_ELTS (TREE_OPERAND (exp, 0)),
6803                  i = TREE_INT_CST_LOW (index);
6804                  elem != 0 && i != 0; i--, elem = TREE_CHAIN (elem))
6805               ;
6806
6807             if (elem)
6808               return expand_expr (fold (TREE_VALUE (elem)), target, tmode,
6809                                   modifier);
6810           }
6811
6812         else if (optimize >= 1
6813                  && modifier != EXPAND_CONST_ADDRESS
6814                  && modifier != EXPAND_INITIALIZER
6815                  && modifier != EXPAND_MEMORY
6816                  && TREE_READONLY (array) && ! TREE_SIDE_EFFECTS (array)
6817                  && TREE_CODE (array) == VAR_DECL && DECL_INITIAL (array)
6818                  && TREE_CODE (DECL_INITIAL (array)) != ERROR_MARK
6819                  && targetm.binds_local_p (array))
6820           {
6821             if (TREE_CODE (index) == INTEGER_CST)
6822               {
6823                 tree init = DECL_INITIAL (array);
6824
6825                 if (TREE_CODE (init) == CONSTRUCTOR)
6826                   {
6827                     tree elem;
6828
6829                     for (elem = CONSTRUCTOR_ELTS (init);
6830                          (elem
6831                           && !tree_int_cst_equal (TREE_PURPOSE (elem), index));
6832                          elem = TREE_CHAIN (elem))
6833                       ;
6834
6835                     if (elem && !TREE_SIDE_EFFECTS (TREE_VALUE (elem)))
6836                       return expand_expr (fold (TREE_VALUE (elem)), target,
6837                                           tmode, modifier);
6838                   }
6839                 else if (TREE_CODE (init) == STRING_CST
6840                          && 0 > compare_tree_int (index,
6841                                                   TREE_STRING_LENGTH (init)))
6842                   {
6843                     tree type = TREE_TYPE (TREE_TYPE (init));
6844                     enum machine_mode mode = TYPE_MODE (type);
6845
6846                     if (GET_MODE_CLASS (mode) == MODE_INT
6847                         && GET_MODE_SIZE (mode) == 1)
6848                       return gen_int_mode (TREE_STRING_POINTER (init)
6849                                            [TREE_INT_CST_LOW (index)], mode);
6850                   }
6851               }
6852           }
6853       }
6854       goto normal_inner_ref;
6855
6856     case COMPONENT_REF:
6857       /* If the operand is a CONSTRUCTOR, we can just extract the
6858          appropriate field if it is present.  */
6859       if (TREE_CODE (TREE_OPERAND (exp, 0)) == CONSTRUCTOR)
6860         {
6861           tree elt;
6862
6863           for (elt = CONSTRUCTOR_ELTS (TREE_OPERAND (exp, 0)); elt;
6864                elt = TREE_CHAIN (elt))
6865             if (TREE_PURPOSE (elt) == TREE_OPERAND (exp, 1)
6866                 /* We can normally use the value of the field in the
6867                    CONSTRUCTOR.  However, if this is a bitfield in
6868                    an integral mode that we can fit in a HOST_WIDE_INT,
6869                    we must mask only the number of bits in the bitfield,
6870                    since this is done implicitly by the constructor.  If
6871                    the bitfield does not meet either of those conditions,
6872                    we can't do this optimization.  */
6873                 && (! DECL_BIT_FIELD (TREE_PURPOSE (elt))
6874                     || ((GET_MODE_CLASS (DECL_MODE (TREE_PURPOSE (elt)))
6875                          == MODE_INT)
6876                         && (GET_MODE_BITSIZE (DECL_MODE (TREE_PURPOSE (elt)))
6877                             <= HOST_BITS_PER_WIDE_INT))))
6878               {
6879                 if (DECL_BIT_FIELD (TREE_PURPOSE (elt))
6880                     && modifier == EXPAND_STACK_PARM)
6881                   target = 0;
6882                 op0 = expand_expr (TREE_VALUE (elt), target, tmode, modifier);
6883                 if (DECL_BIT_FIELD (TREE_PURPOSE (elt)))
6884                   {
6885                     HOST_WIDE_INT bitsize
6886                       = TREE_INT_CST_LOW (DECL_SIZE (TREE_PURPOSE (elt)));
6887                     enum machine_mode imode
6888                       = TYPE_MODE (TREE_TYPE (TREE_PURPOSE (elt)));
6889
6890                     if (TREE_UNSIGNED (TREE_TYPE (TREE_PURPOSE (elt))))
6891                       {
6892                         op1 = GEN_INT (((HOST_WIDE_INT) 1 << bitsize) - 1);
6893                         op0 = expand_and (imode, op0, op1, target);
6894                       }
6895                     else
6896                       {
6897                         tree count
6898                           = build_int_2 (GET_MODE_BITSIZE (imode) - bitsize,
6899                                          0);
6900
6901                         op0 = expand_shift (LSHIFT_EXPR, imode, op0, count,
6902                                             target, 0);
6903                         op0 = expand_shift (RSHIFT_EXPR, imode, op0, count,
6904                                             target, 0);
6905                       }
6906                   }
6907
6908                 return op0;
6909               }
6910         }
6911       goto normal_inner_ref;
6912
6913     case BIT_FIELD_REF:
6914     case ARRAY_RANGE_REF:
6915     normal_inner_ref:
6916       {
6917         enum machine_mode mode1;
6918         HOST_WIDE_INT bitsize, bitpos;
6919         tree offset;
6920         int volatilep = 0;
6921         tree tem = get_inner_reference (exp, &bitsize, &bitpos, &offset,
6922                                         &mode1, &unsignedp, &volatilep);
6923         rtx orig_op0;
6924
6925         /* If we got back the original object, something is wrong.  Perhaps
6926            we are evaluating an expression too early.  In any event, don't
6927            infinitely recurse.  */
6928         if (tem == exp)
6929           abort ();
6930
6931         /* If TEM's type is a union of variable size, pass TARGET to the inner
6932            computation, since it will need a temporary and TARGET is known
6933            to have to do.  This occurs in unchecked conversion in Ada.  */
6934
6935         orig_op0 = op0
6936           = expand_expr (tem,
6937                          (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
6938                           && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
6939                               != INTEGER_CST)
6940                           && modifier != EXPAND_STACK_PARM
6941                           ? target : NULL_RTX),
6942                          VOIDmode,
6943                          (modifier == EXPAND_INITIALIZER
6944                           || modifier == EXPAND_CONST_ADDRESS
6945                           || modifier == EXPAND_STACK_PARM)
6946                          ? modifier : EXPAND_NORMAL);
6947
6948         /* If this is a constant, put it into a register if it is a
6949            legitimate constant and OFFSET is 0 and memory if it isn't.  */
6950         if (CONSTANT_P (op0))
6951           {
6952             enum machine_mode mode = TYPE_MODE (TREE_TYPE (tem));
6953             if (mode != BLKmode && LEGITIMATE_CONSTANT_P (op0)
6954                 && offset == 0)
6955               op0 = force_reg (mode, op0);
6956             else
6957               op0 = validize_mem (force_const_mem (mode, op0));
6958           }
6959
6960         /* Otherwise, if this object not in memory and we either have an
6961            offset or a BLKmode result, put it there.  This case can't occur in
6962            C, but can in Ada if we have unchecked conversion of an expression
6963            from a scalar type to an array or record type or for an
6964            ARRAY_RANGE_REF whose type is BLKmode.  */
6965         else if (GET_CODE (op0) != MEM
6966                  && (offset != 0
6967                      || (code == ARRAY_RANGE_REF && mode == BLKmode)))
6968           {
6969             /* If the operand is a SAVE_EXPR, we can deal with this by
6970                forcing the SAVE_EXPR into memory.  */
6971             if (TREE_CODE (TREE_OPERAND (exp, 0)) == SAVE_EXPR)
6972               {
6973                 put_var_into_stack (TREE_OPERAND (exp, 0),
6974                                     /*rescan=*/true);
6975                 op0 = SAVE_EXPR_RTL (TREE_OPERAND (exp, 0));
6976               }
6977             else
6978               {
6979                 tree nt
6980                   = build_qualified_type (TREE_TYPE (tem),
6981                                           (TYPE_QUALS (TREE_TYPE (tem))
6982                                            | TYPE_QUAL_CONST));
6983                 rtx memloc = assign_temp (nt, 1, 1, 1);
6984
6985                 emit_move_insn (memloc, op0);
6986                 op0 = memloc;
6987               }
6988           }
6989
6990         if (offset != 0)
6991           {
6992             rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode,
6993                                           EXPAND_SUM);
6994
6995             if (GET_CODE (op0) != MEM)
6996               abort ();
6997
6998 #ifdef POINTERS_EXTEND_UNSIGNED
6999             if (GET_MODE (offset_rtx) != Pmode)
7000               offset_rtx = convert_to_mode (Pmode, offset_rtx, 0);
7001 #else
7002             if (GET_MODE (offset_rtx) != ptr_mode)
7003               offset_rtx = convert_to_mode (ptr_mode, offset_rtx, 0);
7004 #endif
7005
7006             if (GET_MODE (op0) == BLKmode
7007                 /* A constant address in OP0 can have VOIDmode, we must
7008                    not try to call force_reg in that case.  */
7009                 && GET_MODE (XEXP (op0, 0)) != VOIDmode
7010                 && bitsize != 0
7011                 && (bitpos % bitsize) == 0
7012                 && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
7013                 && MEM_ALIGN (op0) == GET_MODE_ALIGNMENT (mode1))
7014               {
7015                 op0 = adjust_address (op0, mode1, bitpos / BITS_PER_UNIT);
7016                 bitpos = 0;
7017               }
7018
7019             op0 = offset_address (op0, offset_rtx,
7020                                   highest_pow2_factor (offset));
7021           }
7022
7023         /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
7024            record its alignment as BIGGEST_ALIGNMENT.  */
7025         if (GET_CODE (op0) == MEM && bitpos == 0 && offset != 0
7026             && is_aligning_offset (offset, tem))
7027           set_mem_align (op0, BIGGEST_ALIGNMENT);
7028
7029         /* Don't forget about volatility even if this is a bitfield.  */
7030         if (GET_CODE (op0) == MEM && volatilep && ! MEM_VOLATILE_P (op0))
7031           {
7032             if (op0 == orig_op0)
7033               op0 = copy_rtx (op0);
7034
7035             MEM_VOLATILE_P (op0) = 1;
7036           }
7037
7038         /* The following code doesn't handle CONCAT.
7039            Assume only bitpos == 0 can be used for CONCAT, due to
7040            one element arrays having the same mode as its element.  */
7041         if (GET_CODE (op0) == CONCAT)
7042           {
7043             if (bitpos != 0 || bitsize != GET_MODE_BITSIZE (GET_MODE (op0)))
7044               abort ();
7045             return op0;
7046           }
7047
7048         /* In cases where an aligned union has an unaligned object
7049            as a field, we might be extracting a BLKmode value from
7050            an integer-mode (e.g., SImode) object.  Handle this case
7051            by doing the extract into an object as wide as the field
7052            (which we know to be the width of a basic mode), then
7053            storing into memory, and changing the mode to BLKmode.  */
7054         if (mode1 == VOIDmode
7055             || GET_CODE (op0) == REG || GET_CODE (op0) == SUBREG
7056             || (mode1 != BLKmode && ! direct_load[(int) mode1]
7057                 && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
7058                 && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT
7059                 && modifier != EXPAND_CONST_ADDRESS
7060                 && modifier != EXPAND_INITIALIZER)
7061             /* If the field isn't aligned enough to fetch as a memref,
7062                fetch it as a bit field.  */
7063             || (mode1 != BLKmode
7064                 && (((TYPE_ALIGN (TREE_TYPE (tem)) < GET_MODE_ALIGNMENT (mode)
7065                       || (bitpos % GET_MODE_ALIGNMENT (mode) != 0)
7066                       || (GET_CODE (op0) == MEM
7067                           && (MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode1)
7068                               || (bitpos % GET_MODE_ALIGNMENT (mode1) != 0))))
7069                      && ((modifier == EXPAND_CONST_ADDRESS
7070                           || modifier == EXPAND_INITIALIZER)
7071                          ? STRICT_ALIGNMENT
7072                          : SLOW_UNALIGNED_ACCESS (mode1, MEM_ALIGN (op0))))
7073                     || (bitpos % BITS_PER_UNIT != 0)))
7074             /* If the type and the field are a constant size and the
7075                size of the type isn't the same size as the bitfield,
7076                we must use bitfield operations.  */
7077             || (bitsize >= 0
7078                 && (TREE_CODE (TYPE_SIZE (TREE_TYPE (exp)))
7079                     == INTEGER_CST)
7080                 && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)),
7081                                           bitsize)))
7082           {
7083             enum machine_mode ext_mode = mode;
7084
7085             if (ext_mode == BLKmode
7086                 && ! (target != 0 && GET_CODE (op0) == MEM
7087                       && GET_CODE (target) == MEM
7088                       && bitpos % BITS_PER_UNIT == 0))
7089               ext_mode = mode_for_size (bitsize, MODE_INT, 1);
7090
7091             if (ext_mode == BLKmode)
7092               {
7093                 if (target == 0)
7094                   target = assign_temp (type, 0, 1, 1);
7095
7096                 if (bitsize == 0)
7097                   return target;
7098
7099                 /* In this case, BITPOS must start at a byte boundary and
7100                    TARGET, if specified, must be a MEM.  */
7101                 if (GET_CODE (op0) != MEM
7102                     || (target != 0 && GET_CODE (target) != MEM)
7103                     || bitpos % BITS_PER_UNIT != 0)
7104                   abort ();
7105
7106                 emit_block_move (target,
7107                                  adjust_address (op0, VOIDmode,
7108                                                  bitpos / BITS_PER_UNIT),
7109                                  GEN_INT ((bitsize + BITS_PER_UNIT - 1)
7110                                           / BITS_PER_UNIT),
7111                                  (modifier == EXPAND_STACK_PARM
7112                                   ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
7113
7114                 return target;
7115               }
7116
7117             op0 = validize_mem (op0);
7118
7119             if (GET_CODE (op0) == MEM && GET_CODE (XEXP (op0, 0)) == REG)
7120               mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
7121
7122             op0 = extract_bit_field (op0, bitsize, bitpos, unsignedp,
7123                                      (modifier == EXPAND_STACK_PARM
7124                                       ? NULL_RTX : target),
7125                                      ext_mode, ext_mode,
7126                                      int_size_in_bytes (TREE_TYPE (tem)));
7127
7128             /* If the result is a record type and BITSIZE is narrower than
7129                the mode of OP0, an integral mode, and this is a big endian
7130                machine, we must put the field into the high-order bits.  */
7131             if (TREE_CODE (type) == RECORD_TYPE && BYTES_BIG_ENDIAN
7132                 && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
7133                 && bitsize < (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (op0)))
7134               op0 = expand_shift (LSHIFT_EXPR, GET_MODE (op0), op0,
7135                                   size_int (GET_MODE_BITSIZE (GET_MODE (op0))
7136                                             - bitsize),
7137                                   op0, 1);
7138
7139             /* If the result type is BLKmode, store the data into a temporary
7140                of the appropriate type, but with the mode corresponding to the
7141                mode for the data we have (op0's mode).  It's tempting to make
7142                this a constant type, since we know it's only being stored once,
7143                but that can cause problems if we are taking the address of this
7144                COMPONENT_REF because the MEM of any reference via that address
7145                will have flags corresponding to the type, which will not
7146                necessarily be constant.  */
7147             if (mode == BLKmode)
7148               {
7149                 rtx new
7150                   = assign_stack_temp_for_type
7151                     (ext_mode, GET_MODE_BITSIZE (ext_mode), 0, type);
7152
7153                 emit_move_insn (new, op0);
7154                 op0 = copy_rtx (new);
7155                 PUT_MODE (op0, BLKmode);
7156                 set_mem_attributes (op0, exp, 1);
7157               }
7158
7159             return op0;
7160           }
7161
7162         /* If the result is BLKmode, use that to access the object
7163            now as well.  */
7164         if (mode == BLKmode)
7165           mode1 = BLKmode;
7166
7167         /* Get a reference to just this component.  */
7168         if (modifier == EXPAND_CONST_ADDRESS
7169             || modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
7170           op0 = adjust_address_nv (op0, mode1, bitpos / BITS_PER_UNIT);
7171         else
7172           op0 = adjust_address (op0, mode1, bitpos / BITS_PER_UNIT);
7173
7174         if (op0 == orig_op0)
7175           op0 = copy_rtx (op0);
7176
7177         set_mem_attributes (op0, exp, 0);
7178         if (GET_CODE (XEXP (op0, 0)) == REG)
7179           mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
7180
7181         MEM_VOLATILE_P (op0) |= volatilep;
7182         if (mode == mode1 || mode1 == BLKmode || mode1 == tmode
7183             || modifier == EXPAND_CONST_ADDRESS
7184             || modifier == EXPAND_INITIALIZER)
7185           return op0;
7186         else if (target == 0)
7187           target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
7188
7189         convert_move (target, op0, unsignedp);
7190         return target;
7191       }
7192
7193     case VTABLE_REF:
7194       {
7195         rtx insn, before = get_last_insn (), vtbl_ref;
7196
7197         /* Evaluate the interior expression.  */
7198         subtarget = expand_expr (TREE_OPERAND (exp, 0), target,
7199                                  tmode, modifier);
7200
7201         /* Get or create an instruction off which to hang a note.  */
7202         if (REG_P (subtarget))
7203           {
7204             target = subtarget;
7205             insn = get_last_insn ();
7206             if (insn == before)
7207               abort ();
7208             if (! INSN_P (insn))
7209               insn = prev_nonnote_insn (insn);
7210           }
7211         else
7212           {
7213             target = gen_reg_rtx (GET_MODE (subtarget));
7214             insn = emit_move_insn (target, subtarget);
7215           }
7216
7217         /* Collect the data for the note.  */
7218         vtbl_ref = XEXP (DECL_RTL (TREE_OPERAND (exp, 1)), 0);
7219         vtbl_ref = plus_constant (vtbl_ref,
7220                                   tree_low_cst (TREE_OPERAND (exp, 2), 0));
7221         /* Discard the initial CONST that was added.  */
7222         vtbl_ref = XEXP (vtbl_ref, 0);
7223
7224         REG_NOTES (insn)
7225           = gen_rtx_EXPR_LIST (REG_VTABLE_REF, vtbl_ref, REG_NOTES (insn));
7226
7227         return target;
7228       }
7229
7230       /* Intended for a reference to a buffer of a file-object in Pascal.
7231          But it's not certain that a special tree code will really be
7232          necessary for these.  INDIRECT_REF might work for them.  */
7233     case BUFFER_REF:
7234       abort ();
7235
7236     case IN_EXPR:
7237       {
7238         /* Pascal set IN expression.
7239
7240            Algorithm:
7241                rlo       = set_low - (set_low%bits_per_word);
7242                the_word  = set [ (index - rlo)/bits_per_word ];
7243                bit_index = index % bits_per_word;
7244                bitmask   = 1 << bit_index;
7245                return !!(the_word & bitmask);  */
7246
7247         tree set = TREE_OPERAND (exp, 0);
7248         tree index = TREE_OPERAND (exp, 1);
7249         int iunsignedp = TREE_UNSIGNED (TREE_TYPE (index));
7250         tree set_type = TREE_TYPE (set);
7251         tree set_low_bound = TYPE_MIN_VALUE (TYPE_DOMAIN (set_type));
7252         tree set_high_bound = TYPE_MAX_VALUE (TYPE_DOMAIN (set_type));
7253         rtx index_val = expand_expr (index, 0, VOIDmode, 0);
7254         rtx lo_r = expand_expr (set_low_bound, 0, VOIDmode, 0);
7255         rtx hi_r = expand_expr (set_high_bound, 0, VOIDmode, 0);
7256         rtx setval = expand_expr (set, 0, VOIDmode, 0);
7257         rtx setaddr = XEXP (setval, 0);
7258         enum machine_mode index_mode = TYPE_MODE (TREE_TYPE (index));
7259         rtx rlow;
7260         rtx diff, quo, rem, addr, bit, result;
7261
7262         /* If domain is empty, answer is no.  Likewise if index is constant
7263            and out of bounds.  */
7264         if (((TREE_CODE (set_high_bound) == INTEGER_CST
7265              && TREE_CODE (set_low_bound) == INTEGER_CST
7266              && tree_int_cst_lt (set_high_bound, set_low_bound))
7267              || (TREE_CODE (index) == INTEGER_CST
7268                  && TREE_CODE (set_low_bound) == INTEGER_CST
7269                  && tree_int_cst_lt (index, set_low_bound))
7270              || (TREE_CODE (set_high_bound) == INTEGER_CST
7271                  && TREE_CODE (index) == INTEGER_CST
7272                  && tree_int_cst_lt (set_high_bound, index))))
7273           return const0_rtx;
7274
7275         if (target == 0)
7276           target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
7277
7278         /* If we get here, we have to generate the code for both cases
7279            (in range and out of range).  */
7280
7281         op0 = gen_label_rtx ();
7282         op1 = gen_label_rtx ();
7283
7284         if (! (GET_CODE (index_val) == CONST_INT
7285                && GET_CODE (lo_r) == CONST_INT))
7286           emit_cmp_and_jump_insns (index_val, lo_r, LT, NULL_RTX,
7287                                    GET_MODE (index_val), iunsignedp, op1);
7288
7289         if (! (GET_CODE (index_val) == CONST_INT
7290                && GET_CODE (hi_r) == CONST_INT))
7291           emit_cmp_and_jump_insns (index_val, hi_r, GT, NULL_RTX,
7292                                    GET_MODE (index_val), iunsignedp, op1);
7293
7294         /* Calculate the element number of bit zero in the first word
7295            of the set.  */
7296         if (GET_CODE (lo_r) == CONST_INT)
7297           rlow = GEN_INT (INTVAL (lo_r)
7298                           & ~((HOST_WIDE_INT) 1 << BITS_PER_UNIT));
7299         else
7300           rlow = expand_binop (index_mode, and_optab, lo_r,
7301                                GEN_INT (~((HOST_WIDE_INT) 1 << BITS_PER_UNIT)),
7302                                NULL_RTX, iunsignedp, OPTAB_LIB_WIDEN);
7303
7304         diff = expand_binop (index_mode, sub_optab, index_val, rlow,
7305                              NULL_RTX, iunsignedp, OPTAB_LIB_WIDEN);
7306
7307         quo = expand_divmod (0, TRUNC_DIV_EXPR, index_mode, diff,
7308                              GEN_INT (BITS_PER_UNIT), NULL_RTX, iunsignedp);
7309         rem = expand_divmod (1, TRUNC_MOD_EXPR, index_mode, index_val,
7310                              GEN_INT (BITS_PER_UNIT), NULL_RTX, iunsignedp);
7311
7312         addr = memory_address (byte_mode,
7313                                expand_binop (index_mode, add_optab, diff,
7314                                              setaddr, NULL_RTX, iunsignedp,
7315                                              OPTAB_LIB_WIDEN));
7316
7317         /* Extract the bit we want to examine.  */
7318         bit = expand_shift (RSHIFT_EXPR, byte_mode,
7319                             gen_rtx_MEM (byte_mode, addr),
7320                             make_tree (TREE_TYPE (index), rem),
7321                             NULL_RTX, 1);
7322         result = expand_binop (byte_mode, and_optab, bit, const1_rtx,
7323                                GET_MODE (target) == byte_mode ? target : 0,
7324                                1, OPTAB_LIB_WIDEN);
7325
7326         if (result != target)
7327           convert_move (target, result, 1);
7328
7329         /* Output the code to handle the out-of-range case.  */
7330         emit_jump (op0);
7331         emit_label (op1);
7332         emit_move_insn (target, const0_rtx);
7333         emit_label (op0);
7334         return target;
7335       }
7336
7337     case WITH_CLEANUP_EXPR:
7338       if (WITH_CLEANUP_EXPR_RTL (exp) == 0)
7339         {
7340           WITH_CLEANUP_EXPR_RTL (exp)
7341             = expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
7342           expand_decl_cleanup_eh (NULL_TREE, TREE_OPERAND (exp, 1),
7343                                   CLEANUP_EH_ONLY (exp));
7344
7345           /* That's it for this cleanup.  */
7346           TREE_OPERAND (exp, 1) = 0;
7347         }
7348       return WITH_CLEANUP_EXPR_RTL (exp);
7349
7350     case CLEANUP_POINT_EXPR:
7351       {
7352         /* Start a new binding layer that will keep track of all cleanup
7353            actions to be performed.  */
7354         expand_start_bindings (2);
7355
7356         target_temp_slot_level = temp_slot_level;
7357
7358         op0 = expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
7359         /* If we're going to use this value, load it up now.  */
7360         if (! ignore)
7361           op0 = force_not_mem (op0);
7362         preserve_temp_slots (op0);
7363         expand_end_bindings (NULL_TREE, 0, 0);
7364       }
7365       return op0;
7366
7367     case CALL_EXPR:
7368       /* Check for a built-in function.  */
7369       if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
7370           && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
7371               == FUNCTION_DECL)
7372           && DECL_BUILT_IN (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
7373         {
7374           if (DECL_BUILT_IN_CLASS (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
7375               == BUILT_IN_FRONTEND)
7376           /* ??? Use (*fun) form because expand_expr is a macro.  */
7377             return (*lang_hooks.expand_expr) (exp, original_target,
7378                                               tmode, modifier,
7379                                               alt_rtl);
7380           else
7381             return expand_builtin (exp, target, subtarget, tmode, ignore);
7382         }
7383
7384       return expand_call (exp, target, ignore);
7385
7386     case NON_LVALUE_EXPR:
7387     case NOP_EXPR:
7388     case CONVERT_EXPR:
7389     case REFERENCE_EXPR:
7390       if (TREE_OPERAND (exp, 0) == error_mark_node)
7391         return const0_rtx;
7392
7393       if (TREE_CODE (type) == UNION_TYPE)
7394         {
7395           tree valtype = TREE_TYPE (TREE_OPERAND (exp, 0));
7396
7397           /* If both input and output are BLKmode, this conversion isn't doing
7398              anything except possibly changing memory attribute.  */
7399           if (mode == BLKmode && TYPE_MODE (valtype) == BLKmode)
7400             {
7401               rtx result = expand_expr (TREE_OPERAND (exp, 0), target, tmode,
7402                                         modifier);
7403
7404               result = copy_rtx (result);
7405               set_mem_attributes (result, exp, 0);
7406               return result;
7407             }
7408
7409           if (target == 0)
7410             {
7411               if (TYPE_MODE (type) != BLKmode)
7412                 target = gen_reg_rtx (TYPE_MODE (type));
7413               else
7414                 target = assign_temp (type, 0, 1, 1);
7415             }
7416
7417           if (GET_CODE (target) == MEM)
7418             /* Store data into beginning of memory target.  */
7419             store_expr (TREE_OPERAND (exp, 0),
7420                         adjust_address (target, TYPE_MODE (valtype), 0),
7421                         modifier == EXPAND_STACK_PARM ? 2 : 0);
7422
7423           else if (GET_CODE (target) == REG)
7424             /* Store this field into a union of the proper type.  */
7425             store_field (target,
7426                          MIN ((int_size_in_bytes (TREE_TYPE
7427                                                   (TREE_OPERAND (exp, 0)))
7428                                * BITS_PER_UNIT),
7429                               (HOST_WIDE_INT) GET_MODE_BITSIZE (mode)),
7430                          0, TYPE_MODE (valtype), TREE_OPERAND (exp, 0),
7431                          VOIDmode, 0, type, 0);
7432           else
7433             abort ();
7434
7435           /* Return the entire union.  */
7436           return target;
7437         }
7438
7439       if (mode == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))))
7440         {
7441           op0 = expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode,
7442                              modifier);
7443
7444           /* If the signedness of the conversion differs and OP0 is
7445              a promoted SUBREG, clear that indication since we now
7446              have to do the proper extension.  */
7447           if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))) != unsignedp
7448               && GET_CODE (op0) == SUBREG)
7449             SUBREG_PROMOTED_VAR_P (op0) = 0;
7450
7451           return op0;
7452         }
7453
7454       op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, mode, modifier);
7455       if (GET_MODE (op0) == mode)
7456         return op0;
7457
7458       /* If OP0 is a constant, just convert it into the proper mode.  */
7459       if (CONSTANT_P (op0))
7460         {
7461           tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
7462           enum machine_mode inner_mode = TYPE_MODE (inner_type);
7463
7464           if (modifier == EXPAND_INITIALIZER)
7465             return simplify_gen_subreg (mode, op0, inner_mode,
7466                                         subreg_lowpart_offset (mode,
7467                                                                inner_mode));
7468           else
7469             return convert_modes (mode, inner_mode, op0,
7470                                   TREE_UNSIGNED (inner_type));
7471         }
7472
7473       if (modifier == EXPAND_INITIALIZER)
7474         return gen_rtx_fmt_e (unsignedp ? ZERO_EXTEND : SIGN_EXTEND, mode, op0);
7475
7476       if (target == 0)
7477         return
7478           convert_to_mode (mode, op0,
7479                            TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
7480       else
7481         convert_move (target, op0,
7482                       TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
7483       return target;
7484
7485     case VIEW_CONVERT_EXPR:
7486       op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, mode, modifier);
7487
7488       /* If the input and output modes are both the same, we are done.
7489          Otherwise, if neither mode is BLKmode and both are integral and within
7490          a word, we can use gen_lowpart.  If neither is true, make sure the
7491          operand is in memory and convert the MEM to the new mode.  */
7492       if (TYPE_MODE (type) == GET_MODE (op0))
7493         ;
7494       else if (TYPE_MODE (type) != BLKmode && GET_MODE (op0) != BLKmode
7495                && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
7496                && GET_MODE_CLASS (TYPE_MODE (type)) == MODE_INT
7497                && GET_MODE_SIZE (TYPE_MODE (type)) <= UNITS_PER_WORD
7498                && GET_MODE_SIZE (GET_MODE (op0)) <= UNITS_PER_WORD)
7499         op0 = gen_lowpart (TYPE_MODE (type), op0);
7500       else if (GET_CODE (op0) != MEM)
7501         {
7502           /* If the operand is not a MEM, force it into memory.  Since we
7503              are going to be be changing the mode of the MEM, don't call
7504              force_const_mem for constants because we don't allow pool
7505              constants to change mode.  */
7506           tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
7507
7508           if (TREE_ADDRESSABLE (exp))
7509             abort ();
7510
7511           if (target == 0 || GET_MODE (target) != TYPE_MODE (inner_type))
7512             target
7513               = assign_stack_temp_for_type
7514                 (TYPE_MODE (inner_type),
7515                  GET_MODE_SIZE (TYPE_MODE (inner_type)), 0, inner_type);
7516
7517           emit_move_insn (target, op0);
7518           op0 = target;
7519         }
7520
7521       /* At this point, OP0 is in the correct mode.  If the output type is such
7522          that the operand is known to be aligned, indicate that it is.
7523          Otherwise, we need only be concerned about alignment for non-BLKmode
7524          results.  */
7525       if (GET_CODE (op0) == MEM)
7526         {
7527           op0 = copy_rtx (op0);
7528
7529           if (TYPE_ALIGN_OK (type))
7530             set_mem_align (op0, MAX (MEM_ALIGN (op0), TYPE_ALIGN (type)));
7531           else if (TYPE_MODE (type) != BLKmode && STRICT_ALIGNMENT
7532                    && MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (TYPE_MODE (type)))
7533             {
7534               tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
7535               HOST_WIDE_INT temp_size
7536                 = MAX (int_size_in_bytes (inner_type),
7537                        (HOST_WIDE_INT) GET_MODE_SIZE (TYPE_MODE (type)));
7538               rtx new = assign_stack_temp_for_type (TYPE_MODE (type),
7539                                                     temp_size, 0, type);
7540               rtx new_with_op0_mode = adjust_address (new, GET_MODE (op0), 0);
7541
7542               if (TREE_ADDRESSABLE (exp))
7543                 abort ();
7544
7545               if (GET_MODE (op0) == BLKmode)
7546                 emit_block_move (new_with_op0_mode, op0,
7547                                  GEN_INT (GET_MODE_SIZE (TYPE_MODE (type))),
7548                                  (modifier == EXPAND_STACK_PARM
7549                                   ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
7550               else
7551                 emit_move_insn (new_with_op0_mode, op0);
7552
7553               op0 = new;
7554             }
7555
7556           op0 = adjust_address (op0, TYPE_MODE (type), 0);
7557         }
7558
7559       return op0;
7560
7561     case PLUS_EXPR:
7562       this_optab = ! unsignedp && flag_trapv
7563                    && (GET_MODE_CLASS (mode) == MODE_INT)
7564                    ? addv_optab : add_optab;
7565
7566       /* If we are adding a constant, an RTL_EXPR that is sp, fp, or ap, and
7567          something else, make sure we add the register to the constant and
7568          then to the other thing.  This case can occur during strength
7569          reduction and doing it this way will produce better code if the
7570          frame pointer or argument pointer is eliminated.
7571
7572          fold-const.c will ensure that the constant is always in the inner
7573          PLUS_EXPR, so the only case we need to do anything about is if
7574          sp, ap, or fp is our second argument, in which case we must swap
7575          the innermost first argument and our second argument.  */
7576
7577       if (TREE_CODE (TREE_OPERAND (exp, 0)) == PLUS_EXPR
7578           && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 1)) == INTEGER_CST
7579           && TREE_CODE (TREE_OPERAND (exp, 1)) == RTL_EXPR
7580           && (RTL_EXPR_RTL (TREE_OPERAND (exp, 1)) == frame_pointer_rtx
7581               || RTL_EXPR_RTL (TREE_OPERAND (exp, 1)) == stack_pointer_rtx
7582               || RTL_EXPR_RTL (TREE_OPERAND (exp, 1)) == arg_pointer_rtx))
7583         {
7584           tree t = TREE_OPERAND (exp, 1);
7585
7586           TREE_OPERAND (exp, 1) = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
7587           TREE_OPERAND (TREE_OPERAND (exp, 0), 0) = t;
7588         }
7589
7590       /* If the result is to be ptr_mode and we are adding an integer to
7591          something, we might be forming a constant.  So try to use
7592          plus_constant.  If it produces a sum and we can't accept it,
7593          use force_operand.  This allows P = &ARR[const] to generate
7594          efficient code on machines where a SYMBOL_REF is not a valid
7595          address.
7596
7597          If this is an EXPAND_SUM call, always return the sum.  */
7598       if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER
7599           || (mode == ptr_mode && (unsignedp || ! flag_trapv)))
7600         {
7601           if (modifier == EXPAND_STACK_PARM)
7602             target = 0;
7603           if (TREE_CODE (TREE_OPERAND (exp, 0)) == INTEGER_CST
7604               && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
7605               && TREE_CONSTANT (TREE_OPERAND (exp, 1)))
7606             {
7607               rtx constant_part;
7608
7609               op1 = expand_expr (TREE_OPERAND (exp, 1), subtarget, VOIDmode,
7610                                  EXPAND_SUM);
7611               /* Use immed_double_const to ensure that the constant is
7612                  truncated according to the mode of OP1, then sign extended
7613                  to a HOST_WIDE_INT.  Using the constant directly can result
7614                  in non-canonical RTL in a 64x32 cross compile.  */
7615               constant_part
7616                 = immed_double_const (TREE_INT_CST_LOW (TREE_OPERAND (exp, 0)),
7617                                       (HOST_WIDE_INT) 0,
7618                                       TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 1))));
7619               op1 = plus_constant (op1, INTVAL (constant_part));
7620               if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
7621                 op1 = force_operand (op1, target);
7622               return op1;
7623             }
7624
7625           else if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
7626                    && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_INT
7627                    && TREE_CONSTANT (TREE_OPERAND (exp, 0)))
7628             {
7629               rtx constant_part;
7630
7631               op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode,
7632                                  (modifier == EXPAND_INITIALIZER
7633                                  ? EXPAND_INITIALIZER : EXPAND_SUM));
7634               if (! CONSTANT_P (op0))
7635                 {
7636                   op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX,
7637                                      VOIDmode, modifier);
7638                   /* Return a PLUS if modifier says it's OK.  */
7639                   if (modifier == EXPAND_SUM
7640                       || modifier == EXPAND_INITIALIZER)
7641                     return simplify_gen_binary (PLUS, mode, op0, op1);
7642                   goto binop2;
7643                 }
7644               /* Use immed_double_const to ensure that the constant is
7645                  truncated according to the mode of OP1, then sign extended
7646                  to a HOST_WIDE_INT.  Using the constant directly can result
7647                  in non-canonical RTL in a 64x32 cross compile.  */
7648               constant_part
7649                 = immed_double_const (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1)),
7650                                       (HOST_WIDE_INT) 0,
7651                                       TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))));
7652               op0 = plus_constant (op0, INTVAL (constant_part));
7653               if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
7654                 op0 = force_operand (op0, target);
7655               return op0;
7656             }
7657         }
7658
7659       /* No sense saving up arithmetic to be done
7660          if it's all in the wrong mode to form part of an address.
7661          And force_operand won't know whether to sign-extend or
7662          zero-extend.  */
7663       if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
7664           || mode != ptr_mode)
7665         {
7666           expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
7667                            subtarget, &op0, &op1, 0);
7668           if (op0 == const0_rtx)
7669             return op1;
7670           if (op1 == const0_rtx)
7671             return op0;
7672           goto binop2;
7673         }
7674
7675       expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
7676                        subtarget, &op0, &op1, modifier);
7677       return simplify_gen_binary (PLUS, mode, op0, op1);
7678
7679     case MINUS_EXPR:
7680       /* For initializers, we are allowed to return a MINUS of two
7681          symbolic constants.  Here we handle all cases when both operands
7682          are constant.  */
7683       /* Handle difference of two symbolic constants,
7684          for the sake of an initializer.  */
7685       if ((modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
7686           && really_constant_p (TREE_OPERAND (exp, 0))
7687           && really_constant_p (TREE_OPERAND (exp, 1)))
7688         {
7689           expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
7690                            NULL_RTX, &op0, &op1, modifier);
7691
7692           /* If the last operand is a CONST_INT, use plus_constant of
7693              the negated constant.  Else make the MINUS.  */
7694           if (GET_CODE (op1) == CONST_INT)
7695             return plus_constant (op0, - INTVAL (op1));
7696           else
7697             return gen_rtx_MINUS (mode, op0, op1);
7698         }
7699
7700       this_optab = ! unsignedp && flag_trapv
7701                    && (GET_MODE_CLASS(mode) == MODE_INT)
7702                    ? subv_optab : sub_optab;
7703
7704       /* No sense saving up arithmetic to be done
7705          if it's all in the wrong mode to form part of an address.
7706          And force_operand won't know whether to sign-extend or
7707          zero-extend.  */
7708       if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
7709           || mode != ptr_mode)
7710         goto binop;
7711
7712       expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
7713                        subtarget, &op0, &op1, modifier);
7714
7715       /* Convert A - const to A + (-const).  */
7716       if (GET_CODE (op1) == CONST_INT)
7717         {
7718           op1 = negate_rtx (mode, op1);
7719           return simplify_gen_binary (PLUS, mode, op0, op1);
7720         }
7721
7722       goto binop2;
7723
7724     case MULT_EXPR:
7725       /* If first operand is constant, swap them.
7726          Thus the following special case checks need only
7727          check the second operand.  */
7728       if (TREE_CODE (TREE_OPERAND (exp, 0)) == INTEGER_CST)
7729         {
7730           tree t1 = TREE_OPERAND (exp, 0);
7731           TREE_OPERAND (exp, 0) = TREE_OPERAND (exp, 1);
7732           TREE_OPERAND (exp, 1) = t1;
7733         }
7734
7735       /* Attempt to return something suitable for generating an
7736          indexed address, for machines that support that.  */
7737
7738       if (modifier == EXPAND_SUM && mode == ptr_mode
7739           && host_integerp (TREE_OPERAND (exp, 1), 0))
7740         {
7741           tree exp1 = TREE_OPERAND (exp, 1);
7742
7743           op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode,
7744                              EXPAND_SUM);
7745
7746           if (GET_CODE (op0) != REG)
7747             op0 = force_operand (op0, NULL_RTX);
7748           if (GET_CODE (op0) != REG)
7749             op0 = copy_to_mode_reg (mode, op0);
7750
7751           return gen_rtx_MULT (mode, op0,
7752                                gen_int_mode (tree_low_cst (exp1, 0),
7753                                              TYPE_MODE (TREE_TYPE (exp1))));
7754         }
7755
7756       if (modifier == EXPAND_STACK_PARM)
7757         target = 0;
7758
7759       /* Check for multiplying things that have been extended
7760          from a narrower type.  If this machine supports multiplying
7761          in that narrower type with a result in the desired type,
7762          do it that way, and avoid the explicit type-conversion.  */
7763       if (TREE_CODE (TREE_OPERAND (exp, 0)) == NOP_EXPR
7764           && TREE_CODE (type) == INTEGER_TYPE
7765           && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
7766               < TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp, 0))))
7767           && ((TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
7768                && int_fits_type_p (TREE_OPERAND (exp, 1),
7769                                    TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))
7770                /* Don't use a widening multiply if a shift will do.  */
7771                && ((GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 1))))
7772                     > HOST_BITS_PER_WIDE_INT)
7773                    || exact_log2 (TREE_INT_CST_LOW (TREE_OPERAND (exp, 1))) < 0))
7774               ||
7775               (TREE_CODE (TREE_OPERAND (exp, 1)) == NOP_EXPR
7776                && (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 1), 0)))
7777                    ==
7778                    TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))))
7779                /* If both operands are extended, they must either both
7780                   be zero-extended or both be sign-extended.  */
7781                && (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 1), 0)))
7782                    ==
7783                    TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)))))))
7784         {
7785           tree op0type = TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0));
7786           enum machine_mode innermode = TYPE_MODE (op0type);
7787           bool zextend_p = TREE_UNSIGNED (op0type);
7788           optab other_optab = zextend_p ? smul_widen_optab : umul_widen_optab;
7789           this_optab = zextend_p ? umul_widen_optab : smul_widen_optab;
7790
7791           if (mode == GET_MODE_WIDER_MODE (innermode))
7792             {
7793               if (this_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
7794                 {
7795                   if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST)
7796                     expand_operands (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
7797                                      TREE_OPERAND (exp, 1),
7798                                      NULL_RTX, &op0, &op1, 0);
7799                   else
7800                     expand_operands (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
7801                                      TREE_OPERAND (TREE_OPERAND (exp, 1), 0),
7802                                      NULL_RTX, &op0, &op1, 0);
7803                   goto binop2;
7804                 }
7805               else if (other_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing
7806                        && innermode == word_mode)
7807                 {
7808                   rtx htem, hipart;
7809                   op0 = expand_expr (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
7810                                      NULL_RTX, VOIDmode, 0);
7811                   if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST)
7812                     op1 = convert_modes (innermode, mode,
7813                                          expand_expr (TREE_OPERAND (exp, 1),
7814                                                       NULL_RTX, VOIDmode, 0),
7815                                          unsignedp);
7816                   else
7817                     op1 = expand_expr (TREE_OPERAND (TREE_OPERAND (exp, 1), 0),
7818                                        NULL_RTX, VOIDmode, 0);
7819                   temp = expand_binop (mode, other_optab, op0, op1, target,
7820                                        unsignedp, OPTAB_LIB_WIDEN);
7821                   hipart = gen_highpart (innermode, temp);
7822                   htem = expand_mult_highpart_adjust (innermode, hipart,
7823                                                       op0, op1, hipart,
7824                                                       zextend_p);
7825                   if (htem != hipart)
7826                     emit_move_insn (hipart, htem);
7827                   return temp;
7828                 }
7829             }
7830         }
7831       expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
7832                        subtarget, &op0, &op1, 0);
7833       return expand_mult (mode, op0, op1, target, unsignedp);
7834
7835     case TRUNC_DIV_EXPR:
7836     case FLOOR_DIV_EXPR:
7837     case CEIL_DIV_EXPR:
7838     case ROUND_DIV_EXPR:
7839     case EXACT_DIV_EXPR:
7840       if (modifier == EXPAND_STACK_PARM)
7841         target = 0;
7842       /* Possible optimization: compute the dividend with EXPAND_SUM
7843          then if the divisor is constant can optimize the case
7844          where some terms of the dividend have coeffs divisible by it.  */
7845       expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
7846                        subtarget, &op0, &op1, 0);
7847       return expand_divmod (0, code, mode, op0, op1, target, unsignedp);
7848
7849     case RDIV_EXPR:
7850       /* Emit a/b as a*(1/b).  Later we may manage CSE the reciprocal saving
7851          expensive divide.  If not, combine will rebuild the original
7852          computation.  */
7853       if (flag_unsafe_math_optimizations && optimize && !optimize_size
7854           && TREE_CODE (type) == REAL_TYPE
7855           && !real_onep (TREE_OPERAND (exp, 0)))
7856         return expand_expr (build (MULT_EXPR, type, TREE_OPERAND (exp, 0),
7857                                    build (RDIV_EXPR, type,
7858                                           build_real (type, dconst1),
7859                                           TREE_OPERAND (exp, 1))),
7860                             target, tmode, modifier);
7861       this_optab = sdiv_optab;
7862       goto binop;
7863
7864     case TRUNC_MOD_EXPR:
7865     case FLOOR_MOD_EXPR:
7866     case CEIL_MOD_EXPR:
7867     case ROUND_MOD_EXPR:
7868       if (modifier == EXPAND_STACK_PARM)
7869         target = 0;
7870       expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
7871                        subtarget, &op0, &op1, 0);
7872       return expand_divmod (1, code, mode, op0, op1, target, unsignedp);
7873
7874     case FIX_ROUND_EXPR:
7875     case FIX_FLOOR_EXPR:
7876     case FIX_CEIL_EXPR:
7877       abort ();                 /* Not used for C.  */
7878
7879     case FIX_TRUNC_EXPR:
7880       op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
7881       if (target == 0 || modifier == EXPAND_STACK_PARM)
7882         target = gen_reg_rtx (mode);
7883       expand_fix (target, op0, unsignedp);
7884       return target;
7885
7886     case FLOAT_EXPR:
7887       op0 = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0);
7888       if (target == 0 || modifier == EXPAND_STACK_PARM)
7889         target = gen_reg_rtx (mode);
7890       /* expand_float can't figure out what to do if FROM has VOIDmode.
7891          So give it the correct mode.  With -O, cse will optimize this.  */
7892       if (GET_MODE (op0) == VOIDmode)
7893         op0 = copy_to_mode_reg (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))),
7894                                 op0);
7895       expand_float (target, op0,
7896                     TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp, 0))));
7897       return target;
7898
7899     case NEGATE_EXPR:
7900       op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
7901       if (modifier == EXPAND_STACK_PARM)
7902         target = 0;
7903       temp = expand_unop (mode,
7904                           ! unsignedp && flag_trapv
7905                           && (GET_MODE_CLASS(mode) == MODE_INT)
7906                           ? negv_optab : neg_optab, op0, target, 0);
7907       if (temp == 0)
7908         abort ();
7909       return temp;
7910
7911     case ABS_EXPR:
7912       op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
7913       if (modifier == EXPAND_STACK_PARM)
7914         target = 0;
7915
7916       /* ABS_EXPR is not valid for complex arguments.  */
7917       if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT
7918           || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
7919         abort ();
7920
7921       /* Unsigned abs is simply the operand.  Testing here means we don't
7922          risk generating incorrect code below.  */
7923       if (TREE_UNSIGNED (type))
7924         return op0;
7925
7926       return expand_abs (mode, op0, target, unsignedp,
7927                          safe_from_p (target, TREE_OPERAND (exp, 0), 1));
7928
7929     case MAX_EXPR:
7930     case MIN_EXPR:
7931       target = original_target;
7932       if (target == 0
7933           || modifier == EXPAND_STACK_PARM
7934           || (GET_CODE (target) == MEM && MEM_VOLATILE_P (target))
7935           || GET_MODE (target) != mode
7936           || (GET_CODE (target) == REG
7937               && REGNO (target) < FIRST_PSEUDO_REGISTER))
7938         target = gen_reg_rtx (mode);
7939       expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
7940                        target, &op0, &op1, 0);
7941
7942       /* First try to do it with a special MIN or MAX instruction.
7943          If that does not win, use a conditional jump to select the proper
7944          value.  */
7945       this_optab = (unsignedp
7946                     ? (code == MIN_EXPR ? umin_optab : umax_optab)
7947                     : (code == MIN_EXPR ? smin_optab : smax_optab));
7948
7949       temp = expand_binop (mode, this_optab, op0, op1, target, unsignedp,
7950                            OPTAB_WIDEN);
7951       if (temp != 0)
7952         return temp;
7953
7954       /* At this point, a MEM target is no longer useful; we will get better
7955          code without it.  */
7956
7957       if (GET_CODE (target) == MEM)
7958         target = gen_reg_rtx (mode);
7959
7960       /* If op1 was placed in target, swap op0 and op1.  */
7961       if (target != op0 && target == op1)
7962         {
7963           rtx tem = op0;
7964           op0 = op1;
7965           op1 = tem;
7966         }
7967
7968       if (target != op0)
7969         emit_move_insn (target, op0);
7970
7971       op0 = gen_label_rtx ();
7972
7973       /* If this mode is an integer too wide to compare properly,
7974          compare word by word.  Rely on cse to optimize constant cases.  */
7975       if (GET_MODE_CLASS (mode) == MODE_INT
7976           && ! can_compare_p (GE, mode, ccp_jump))
7977         {
7978           if (code == MAX_EXPR)
7979             do_jump_by_parts_greater_rtx (mode, unsignedp, target, op1,
7980                                           NULL_RTX, op0);
7981           else
7982             do_jump_by_parts_greater_rtx (mode, unsignedp, op1, target,
7983                                           NULL_RTX, op0);
7984         }
7985       else
7986         {
7987           do_compare_rtx_and_jump (target, op1, code == MAX_EXPR ? GE : LE,
7988                                    unsignedp, mode, NULL_RTX, NULL_RTX, op0);
7989         }
7990       emit_move_insn (target, op1);
7991       emit_label (op0);
7992       return target;
7993
7994     case BIT_NOT_EXPR:
7995       op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
7996       if (modifier == EXPAND_STACK_PARM)
7997         target = 0;
7998       temp = expand_unop (mode, one_cmpl_optab, op0, target, 1);
7999       if (temp == 0)
8000         abort ();
8001       return temp;
8002
8003       /* ??? Can optimize bitwise operations with one arg constant.
8004          Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
8005          and (a bitwise1 b) bitwise2 b (etc)
8006          but that is probably not worth while.  */
8007
8008       /* BIT_AND_EXPR is for bitwise anding.  TRUTH_AND_EXPR is for anding two
8009          boolean values when we want in all cases to compute both of them.  In
8010          general it is fastest to do TRUTH_AND_EXPR by computing both operands
8011          as actual zero-or-1 values and then bitwise anding.  In cases where
8012          there cannot be any side effects, better code would be made by
8013          treating TRUTH_AND_EXPR like TRUTH_ANDIF_EXPR; but the question is
8014          how to recognize those cases.  */
8015
8016     case TRUTH_AND_EXPR:
8017     case BIT_AND_EXPR:
8018       this_optab = and_optab;
8019       goto binop;
8020
8021     case TRUTH_OR_EXPR:
8022     case BIT_IOR_EXPR:
8023       this_optab = ior_optab;
8024       goto binop;
8025
8026     case TRUTH_XOR_EXPR:
8027     case BIT_XOR_EXPR:
8028       this_optab = xor_optab;
8029       goto binop;
8030
8031     case LSHIFT_EXPR:
8032     case RSHIFT_EXPR:
8033     case LROTATE_EXPR:
8034     case RROTATE_EXPR:
8035       if (! safe_from_p (subtarget, TREE_OPERAND (exp, 1), 1))
8036         subtarget = 0;
8037       if (modifier == EXPAND_STACK_PARM)
8038         target = 0;
8039       op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
8040       return expand_shift (code, mode, op0, TREE_OPERAND (exp, 1), target,
8041                            unsignedp);
8042
8043       /* Could determine the answer when only additive constants differ.  Also,
8044          the addition of one can be handled by changing the condition.  */
8045     case LT_EXPR:
8046     case LE_EXPR:
8047     case GT_EXPR:
8048     case GE_EXPR:
8049     case EQ_EXPR:
8050     case NE_EXPR:
8051     case UNORDERED_EXPR:
8052     case ORDERED_EXPR:
8053     case UNLT_EXPR:
8054     case UNLE_EXPR:
8055     case UNGT_EXPR:
8056     case UNGE_EXPR:
8057     case UNEQ_EXPR:
8058       temp = do_store_flag (exp,
8059                             modifier != EXPAND_STACK_PARM ? target : NULL_RTX,
8060                             tmode != VOIDmode ? tmode : mode, 0);
8061       if (temp != 0)
8062         return temp;
8063
8064       /* For foo != 0, load foo, and if it is nonzero load 1 instead.  */
8065       if (code == NE_EXPR && integer_zerop (TREE_OPERAND (exp, 1))
8066           && original_target
8067           && GET_CODE (original_target) == REG
8068           && (GET_MODE (original_target)
8069               == TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0)))))
8070         {
8071           temp = expand_expr (TREE_OPERAND (exp, 0), original_target,
8072                               VOIDmode, 0);
8073
8074           /* If temp is constant, we can just compute the result.  */
8075           if (GET_CODE (temp) == CONST_INT)
8076             {
8077               if (INTVAL (temp) != 0)
8078                 emit_move_insn (target, const1_rtx);
8079               else
8080                 emit_move_insn (target, const0_rtx);
8081
8082               return target;
8083             }
8084
8085           if (temp != original_target)
8086             {
8087               enum machine_mode mode1 = GET_MODE (temp);
8088               if (mode1 == VOIDmode)
8089                 mode1 = tmode != VOIDmode ? tmode : mode;
8090
8091               temp = copy_to_mode_reg (mode1, temp);
8092             }
8093
8094           op1 = gen_label_rtx ();
8095           emit_cmp_and_jump_insns (temp, const0_rtx, EQ, NULL_RTX,
8096                                    GET_MODE (temp), unsignedp, op1);
8097           emit_move_insn (temp, const1_rtx);
8098           emit_label (op1);
8099           return temp;
8100         }
8101
8102       /* If no set-flag instruction, must generate a conditional
8103          store into a temporary variable.  Drop through
8104          and handle this like && and ||.  */
8105
8106     case TRUTH_ANDIF_EXPR:
8107     case TRUTH_ORIF_EXPR:
8108       if (! ignore
8109           && (target == 0
8110               || modifier == EXPAND_STACK_PARM
8111               || ! safe_from_p (target, exp, 1)
8112               /* Make sure we don't have a hard reg (such as function's return
8113                  value) live across basic blocks, if not optimizing.  */
8114               || (!optimize && GET_CODE (target) == REG
8115                   && REGNO (target) < FIRST_PSEUDO_REGISTER)))
8116         target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
8117
8118       if (target)
8119         emit_clr_insn (target);
8120
8121       op1 = gen_label_rtx ();
8122       jumpifnot (exp, op1);
8123
8124       if (target)
8125         emit_0_to_1_insn (target);
8126
8127       emit_label (op1);
8128       return ignore ? const0_rtx : target;
8129
8130     case TRUTH_NOT_EXPR:
8131       if (modifier == EXPAND_STACK_PARM)
8132         target = 0;
8133       op0 = expand_expr (TREE_OPERAND (exp, 0), target, VOIDmode, 0);
8134       /* The parser is careful to generate TRUTH_NOT_EXPR
8135          only with operands that are always zero or one.  */
8136       temp = expand_binop (mode, xor_optab, op0, const1_rtx,
8137                            target, 1, OPTAB_LIB_WIDEN);
8138       if (temp == 0)
8139         abort ();
8140       return temp;
8141
8142     case COMPOUND_EXPR:
8143       expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
8144       emit_queue ();
8145       return expand_expr_real (TREE_OPERAND (exp, 1),
8146                                (ignore ? const0_rtx : target),
8147                                VOIDmode, modifier, alt_rtl);
8148
8149     case COND_EXPR:
8150       /* If we would have a "singleton" (see below) were it not for a
8151          conversion in each arm, bring that conversion back out.  */
8152       if (TREE_CODE (TREE_OPERAND (exp, 1)) == NOP_EXPR
8153           && TREE_CODE (TREE_OPERAND (exp, 2)) == NOP_EXPR
8154           && (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 1), 0))
8155               == TREE_TYPE (TREE_OPERAND (TREE_OPERAND (exp, 2), 0))))
8156         {
8157           tree iftrue = TREE_OPERAND (TREE_OPERAND (exp, 1), 0);
8158           tree iffalse = TREE_OPERAND (TREE_OPERAND (exp, 2), 0);
8159
8160           if ((TREE_CODE_CLASS (TREE_CODE (iftrue)) == '2'
8161                && operand_equal_p (iffalse, TREE_OPERAND (iftrue, 0), 0))
8162               || (TREE_CODE_CLASS (TREE_CODE (iffalse)) == '2'
8163                   && operand_equal_p (iftrue, TREE_OPERAND (iffalse, 0), 0))
8164               || (TREE_CODE_CLASS (TREE_CODE (iftrue)) == '1'
8165                   && operand_equal_p (iffalse, TREE_OPERAND (iftrue, 0), 0))
8166               || (TREE_CODE_CLASS (TREE_CODE (iffalse)) == '1'
8167                   && operand_equal_p (iftrue, TREE_OPERAND (iffalse, 0), 0)))
8168             return expand_expr (build1 (NOP_EXPR, type,
8169                                         build (COND_EXPR, TREE_TYPE (iftrue),
8170                                                TREE_OPERAND (exp, 0),
8171                                                iftrue, iffalse)),
8172                                 target, tmode, modifier);
8173         }
8174
8175       {
8176         /* Note that COND_EXPRs whose type is a structure or union
8177            are required to be constructed to contain assignments of
8178            a temporary variable, so that we can evaluate them here
8179            for side effect only.  If type is void, we must do likewise.  */
8180
8181         /* If an arm of the branch requires a cleanup,
8182            only that cleanup is performed.  */
8183
8184         tree singleton = 0;
8185         tree binary_op = 0, unary_op = 0;
8186
8187         /* If this is (A ? 1 : 0) and A is a condition, just evaluate it and
8188            convert it to our mode, if necessary.  */
8189         if (integer_onep (TREE_OPERAND (exp, 1))
8190             && integer_zerop (TREE_OPERAND (exp, 2))
8191             && TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == '<')
8192           {
8193             if (ignore)
8194               {
8195                 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
8196                              modifier);
8197                 return const0_rtx;
8198               }
8199
8200             if (modifier == EXPAND_STACK_PARM)
8201               target = 0;
8202             op0 = expand_expr (TREE_OPERAND (exp, 0), target, mode, modifier);
8203             if (GET_MODE (op0) == mode)
8204               return op0;
8205
8206             if (target == 0)
8207               target = gen_reg_rtx (mode);
8208             convert_move (target, op0, unsignedp);
8209             return target;
8210           }
8211
8212         /* Check for X ? A + B : A.  If we have this, we can copy A to the
8213            output and conditionally add B.  Similarly for unary operations.
8214            Don't do this if X has side-effects because those side effects
8215            might affect A or B and the "?" operation is a sequence point in
8216            ANSI.  (operand_equal_p tests for side effects.)  */
8217
8218         if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 1))) == '2'
8219             && operand_equal_p (TREE_OPERAND (exp, 2),
8220                                 TREE_OPERAND (TREE_OPERAND (exp, 1), 0), 0))
8221           singleton = TREE_OPERAND (exp, 2), binary_op = TREE_OPERAND (exp, 1);
8222         else if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 2))) == '2'
8223                  && operand_equal_p (TREE_OPERAND (exp, 1),
8224                                      TREE_OPERAND (TREE_OPERAND (exp, 2), 0), 0))
8225           singleton = TREE_OPERAND (exp, 1), binary_op = TREE_OPERAND (exp, 2);
8226         else if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 1))) == '1'
8227                  && operand_equal_p (TREE_OPERAND (exp, 2),
8228                                      TREE_OPERAND (TREE_OPERAND (exp, 1), 0), 0))
8229           singleton = TREE_OPERAND (exp, 2), unary_op = TREE_OPERAND (exp, 1);
8230         else if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 2))) == '1'
8231                  && operand_equal_p (TREE_OPERAND (exp, 1),
8232                                      TREE_OPERAND (TREE_OPERAND (exp, 2), 0), 0))
8233           singleton = TREE_OPERAND (exp, 1), unary_op = TREE_OPERAND (exp, 2);
8234
8235         /* If we are not to produce a result, we have no target.  Otherwise,
8236            if a target was specified use it; it will not be used as an
8237            intermediate target unless it is safe.  If no target, use a
8238            temporary.  */
8239
8240         if (ignore)
8241           temp = 0;
8242         else if (modifier == EXPAND_STACK_PARM)
8243           temp = assign_temp (type, 0, 0, 1);
8244         else if (original_target
8245                  && (safe_from_p (original_target, TREE_OPERAND (exp, 0), 1)
8246                      || (singleton && GET_CODE (original_target) == REG
8247                          && REGNO (original_target) >= FIRST_PSEUDO_REGISTER
8248                          && original_target == var_rtx (singleton)))
8249                  && GET_MODE (original_target) == mode
8250 #ifdef HAVE_conditional_move
8251                  && (! can_conditionally_move_p (mode)
8252                      || GET_CODE (original_target) == REG
8253                      || TREE_ADDRESSABLE (type))
8254 #endif
8255                  && (GET_CODE (original_target) != MEM
8256                      || TREE_ADDRESSABLE (type)))
8257           temp = original_target;
8258         else if (TREE_ADDRESSABLE (type))
8259           abort ();
8260         else
8261           temp = assign_temp (type, 0, 0, 1);
8262
8263         /* If we had X ? A + C : A, with C a constant power of 2, and we can
8264            do the test of X as a store-flag operation, do this as
8265            A + ((X != 0) << log C).  Similarly for other simple binary
8266            operators.  Only do for C == 1 if BRANCH_COST is low.  */
8267         if (temp && singleton && binary_op
8268             && (TREE_CODE (binary_op) == PLUS_EXPR
8269                 || TREE_CODE (binary_op) == MINUS_EXPR
8270                 || TREE_CODE (binary_op) == BIT_IOR_EXPR
8271                 || TREE_CODE (binary_op) == BIT_XOR_EXPR)
8272             && (BRANCH_COST >= 3 ? integer_pow2p (TREE_OPERAND (binary_op, 1))
8273                 : integer_onep (TREE_OPERAND (binary_op, 1)))
8274             && TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == '<')
8275           {
8276             rtx result;
8277             tree cond;
8278             optab boptab = (TREE_CODE (binary_op) == PLUS_EXPR
8279                             ? (TYPE_TRAP_SIGNED (TREE_TYPE (binary_op))
8280                                ? addv_optab : add_optab)
8281                             : TREE_CODE (binary_op) == MINUS_EXPR
8282                             ? (TYPE_TRAP_SIGNED (TREE_TYPE (binary_op))
8283                                ? subv_optab : sub_optab)
8284                             : TREE_CODE (binary_op) == BIT_IOR_EXPR ? ior_optab
8285                             : xor_optab);
8286
8287             /* If we had X ? A : A + 1, do this as A + (X == 0).  */
8288             if (singleton == TREE_OPERAND (exp, 1))
8289               cond = invert_truthvalue (TREE_OPERAND (exp, 0));
8290             else
8291               cond = TREE_OPERAND (exp, 0);
8292
8293             result = do_store_flag (cond, (safe_from_p (temp, singleton, 1)
8294                                            ? temp : NULL_RTX),
8295                                     mode, BRANCH_COST <= 1);
8296
8297             if (result != 0 && ! integer_onep (TREE_OPERAND (binary_op, 1)))
8298               result = expand_shift (LSHIFT_EXPR, mode, result,
8299                                      build_int_2 (tree_log2
8300                                                   (TREE_OPERAND
8301                                                    (binary_op, 1)),
8302                                                   0),
8303                                      (safe_from_p (temp, singleton, 1)
8304                                       ? temp : NULL_RTX), 0);
8305
8306             if (result)
8307               {
8308                 op1 = expand_expr (singleton, NULL_RTX, VOIDmode, 0);
8309                 return expand_binop (mode, boptab, op1, result, temp,
8310                                      unsignedp, OPTAB_LIB_WIDEN);
8311               }
8312           }
8313
8314         do_pending_stack_adjust ();
8315         NO_DEFER_POP;
8316         op0 = gen_label_rtx ();
8317
8318         if (singleton && ! TREE_SIDE_EFFECTS (TREE_OPERAND (exp, 0)))
8319           {
8320             if (temp != 0)
8321               {
8322                 /* If the target conflicts with the other operand of the
8323                    binary op, we can't use it.  Also, we can't use the target
8324                    if it is a hard register, because evaluating the condition
8325                    might clobber it.  */
8326                 if ((binary_op
8327                      && ! safe_from_p (temp, TREE_OPERAND (binary_op, 1), 1))
8328                     || (GET_CODE (temp) == REG
8329                         && REGNO (temp) < FIRST_PSEUDO_REGISTER))
8330                   temp = gen_reg_rtx (mode);
8331                 store_expr (singleton, temp,
8332                             modifier == EXPAND_STACK_PARM ? 2 : 0);
8333               }
8334             else
8335               expand_expr (singleton,
8336                            ignore ? const0_rtx : NULL_RTX, VOIDmode, 0);
8337             if (singleton == TREE_OPERAND (exp, 1))
8338               jumpif (TREE_OPERAND (exp, 0), op0);
8339             else
8340               jumpifnot (TREE_OPERAND (exp, 0), op0);
8341
8342             start_cleanup_deferral ();
8343             if (binary_op && temp == 0)
8344               /* Just touch the other operand.  */
8345               expand_expr (TREE_OPERAND (binary_op, 1),
8346                            ignore ? const0_rtx : NULL_RTX, VOIDmode, 0);
8347             else if (binary_op)
8348               store_expr (build (TREE_CODE (binary_op), type,
8349                                  make_tree (type, temp),
8350                                  TREE_OPERAND (binary_op, 1)),
8351                           temp, modifier == EXPAND_STACK_PARM ? 2 : 0);
8352             else
8353               store_expr (build1 (TREE_CODE (unary_op), type,
8354                                   make_tree (type, temp)),
8355                           temp, modifier == EXPAND_STACK_PARM ? 2 : 0);
8356             op1 = op0;
8357           }
8358         /* Check for A op 0 ? A : FOO and A op 0 ? FOO : A where OP is any
8359            comparison operator.  If we have one of these cases, set the
8360            output to A, branch on A (cse will merge these two references),
8361            then set the output to FOO.  */
8362         else if (temp
8363                  && TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == '<'
8364                  && integer_zerop (TREE_OPERAND (TREE_OPERAND (exp, 0), 1))
8365                  && operand_equal_p (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
8366                                      TREE_OPERAND (exp, 1), 0)
8367                  && (! TREE_SIDE_EFFECTS (TREE_OPERAND (exp, 0))
8368                      || TREE_CODE (TREE_OPERAND (exp, 1)) == SAVE_EXPR)
8369                  && safe_from_p (temp, TREE_OPERAND (exp, 2), 1))
8370           {
8371             if (GET_CODE (temp) == REG
8372                 && REGNO (temp) < FIRST_PSEUDO_REGISTER)
8373               temp = gen_reg_rtx (mode);
8374             store_expr (TREE_OPERAND (exp, 1), temp,
8375                         modifier == EXPAND_STACK_PARM ? 2 : 0);
8376             jumpif (TREE_OPERAND (exp, 0), op0);
8377
8378             start_cleanup_deferral ();
8379             if (TREE_TYPE (TREE_OPERAND (exp, 2)) != void_type_node)
8380               store_expr (TREE_OPERAND (exp, 2), temp,
8381                           modifier == EXPAND_STACK_PARM ? 2 : 0);
8382             else
8383               expand_expr (TREE_OPERAND (exp, 2),
8384                            ignore ? const0_rtx : NULL_RTX, VOIDmode, 0);
8385             op1 = op0;
8386           }
8387         else if (temp
8388                  && TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == '<'
8389                  && integer_zerop (TREE_OPERAND (TREE_OPERAND (exp, 0), 1))
8390                  && operand_equal_p (TREE_OPERAND (TREE_OPERAND (exp, 0), 0),
8391                                      TREE_OPERAND (exp, 2), 0)
8392                  && (! TREE_SIDE_EFFECTS (TREE_OPERAND (exp, 0))
8393                      || TREE_CODE (TREE_OPERAND (exp, 2)) == SAVE_EXPR)
8394                  && safe_from_p (temp, TREE_OPERAND (exp, 1), 1))
8395           {
8396             if (GET_CODE (temp) == REG
8397                 && REGNO (temp) < FIRST_PSEUDO_REGISTER)
8398               temp = gen_reg_rtx (mode);
8399             store_expr (TREE_OPERAND (exp, 2), temp,
8400                         modifier == EXPAND_STACK_PARM ? 2 : 0);
8401             jumpifnot (TREE_OPERAND (exp, 0), op0);
8402
8403             start_cleanup_deferral ();
8404             if (TREE_TYPE (TREE_OPERAND (exp, 1)) != void_type_node)
8405               store_expr (TREE_OPERAND (exp, 1), temp,
8406                           modifier == EXPAND_STACK_PARM ? 2 : 0);
8407             else
8408               expand_expr (TREE_OPERAND (exp, 1),
8409                            ignore ? const0_rtx : NULL_RTX, VOIDmode, 0);
8410             op1 = op0;
8411           }
8412         else
8413           {
8414             op1 = gen_label_rtx ();
8415             jumpifnot (TREE_OPERAND (exp, 0), op0);
8416
8417             start_cleanup_deferral ();
8418
8419             /* One branch of the cond can be void, if it never returns. For
8420                example A ? throw : E  */
8421             if (temp != 0
8422                 && TREE_TYPE (TREE_OPERAND (exp, 1)) != void_type_node)
8423               store_expr (TREE_OPERAND (exp, 1), temp,
8424                           modifier == EXPAND_STACK_PARM ? 2 : 0);
8425             else
8426               expand_expr (TREE_OPERAND (exp, 1),
8427                            ignore ? const0_rtx : NULL_RTX, VOIDmode, 0);
8428             end_cleanup_deferral ();
8429             emit_queue ();
8430             emit_jump_insn (gen_jump (op1));
8431             emit_barrier ();
8432             emit_label (op0);
8433             start_cleanup_deferral ();
8434             if (temp != 0
8435                 && TREE_TYPE (TREE_OPERAND (exp, 2)) != void_type_node)
8436               store_expr (TREE_OPERAND (exp, 2), temp,
8437                           modifier == EXPAND_STACK_PARM ? 2 : 0);
8438             else
8439               expand_expr (TREE_OPERAND (exp, 2),
8440                            ignore ? const0_rtx : NULL_RTX, VOIDmode, 0);
8441           }
8442
8443         end_cleanup_deferral ();
8444
8445         emit_queue ();
8446         emit_label (op1);
8447         OK_DEFER_POP;
8448
8449         return temp;
8450       }
8451
8452     case TARGET_EXPR:
8453       {
8454         /* Something needs to be initialized, but we didn't know
8455            where that thing was when building the tree.  For example,
8456            it could be the return value of a function, or a parameter
8457            to a function which lays down in the stack, or a temporary
8458            variable which must be passed by reference.
8459
8460            We guarantee that the expression will either be constructed
8461            or copied into our original target.  */
8462
8463         tree slot = TREE_OPERAND (exp, 0);
8464         tree cleanups = NULL_TREE;
8465         tree exp1;
8466
8467         if (TREE_CODE (slot) != VAR_DECL)
8468           abort ();
8469
8470         if (! ignore)
8471           target = original_target;
8472
8473         /* Set this here so that if we get a target that refers to a
8474            register variable that's already been used, put_reg_into_stack
8475            knows that it should fix up those uses.  */
8476         TREE_USED (slot) = 1;
8477
8478         if (target == 0)
8479           {
8480             if (DECL_RTL_SET_P (slot))
8481               {
8482                 target = DECL_RTL (slot);
8483                 /* If we have already expanded the slot, so don't do
8484                    it again.  (mrs)  */
8485                 if (TREE_OPERAND (exp, 1) == NULL_TREE)
8486                   return target;
8487               }
8488             else
8489               {
8490                 target = assign_temp (type, 2, 0, 1);
8491                 /* All temp slots at this level must not conflict.  */
8492                 preserve_temp_slots (target);
8493                 SET_DECL_RTL (slot, target);
8494                 if (TREE_ADDRESSABLE (slot))
8495                   put_var_into_stack (slot, /*rescan=*/false);
8496
8497                 /* Since SLOT is not known to the called function
8498                    to belong to its stack frame, we must build an explicit
8499                    cleanup.  This case occurs when we must build up a reference
8500                    to pass the reference as an argument.  In this case,
8501                    it is very likely that such a reference need not be
8502                    built here.  */
8503
8504                 if (TREE_OPERAND (exp, 2) == 0)
8505                   TREE_OPERAND (exp, 2)
8506                     = lang_hooks.maybe_build_cleanup (slot);
8507                 cleanups = TREE_OPERAND (exp, 2);
8508               }
8509           }
8510         else
8511           {
8512             /* This case does occur, when expanding a parameter which
8513                needs to be constructed on the stack.  The target
8514                is the actual stack address that we want to initialize.
8515                The function we call will perform the cleanup in this case.  */
8516
8517             /* If we have already assigned it space, use that space,
8518                not target that we were passed in, as our target
8519                parameter is only a hint.  */
8520             if (DECL_RTL_SET_P (slot))
8521               {
8522                 target = DECL_RTL (slot);
8523                 /* If we have already expanded the slot, so don't do
8524                    it again.  (mrs)  */
8525                 if (TREE_OPERAND (exp, 1) == NULL_TREE)
8526                   return target;
8527               }
8528             else
8529               {
8530                 SET_DECL_RTL (slot, target);
8531                 /* If we must have an addressable slot, then make sure that
8532                    the RTL that we just stored in slot is OK.  */
8533                 if (TREE_ADDRESSABLE (slot))
8534                   put_var_into_stack (slot, /*rescan=*/true);
8535               }
8536           }
8537
8538         exp1 = TREE_OPERAND (exp, 3) = TREE_OPERAND (exp, 1);
8539         /* Mark it as expanded.  */
8540         TREE_OPERAND (exp, 1) = NULL_TREE;
8541
8542         store_expr (exp1, target, modifier == EXPAND_STACK_PARM ? 2 : 0);
8543
8544         expand_decl_cleanup_eh (NULL_TREE, cleanups, CLEANUP_EH_ONLY (exp));
8545
8546         return target;
8547       }
8548
8549     case INIT_EXPR:
8550       {
8551         tree lhs = TREE_OPERAND (exp, 0);
8552         tree rhs = TREE_OPERAND (exp, 1);
8553
8554         temp = expand_assignment (lhs, rhs, ! ignore);
8555         return temp;
8556       }
8557
8558     case MODIFY_EXPR:
8559       {
8560         /* If lhs is complex, expand calls in rhs before computing it.
8561            That's so we don't compute a pointer and save it over a
8562            call.  If lhs is simple, compute it first so we can give it
8563            as a target if the rhs is just a call.  This avoids an
8564            extra temp and copy and that prevents a partial-subsumption
8565            which makes bad code.  Actually we could treat
8566            component_ref's of vars like vars.  */
8567
8568         tree lhs = TREE_OPERAND (exp, 0);
8569         tree rhs = TREE_OPERAND (exp, 1);
8570
8571         temp = 0;
8572
8573         /* Check for |= or &= of a bitfield of size one into another bitfield
8574            of size 1.  In this case, (unless we need the result of the
8575            assignment) we can do this more efficiently with a
8576            test followed by an assignment, if necessary.
8577
8578            ??? At this point, we can't get a BIT_FIELD_REF here.  But if
8579            things change so we do, this code should be enhanced to
8580            support it.  */
8581         if (ignore
8582             && TREE_CODE (lhs) == COMPONENT_REF
8583             && (TREE_CODE (rhs) == BIT_IOR_EXPR
8584                 || TREE_CODE (rhs) == BIT_AND_EXPR)
8585             && TREE_OPERAND (rhs, 0) == lhs
8586             && TREE_CODE (TREE_OPERAND (rhs, 1)) == COMPONENT_REF
8587             && integer_onep (DECL_SIZE (TREE_OPERAND (lhs, 1)))
8588             && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs, 1), 1))))
8589           {
8590             rtx label = gen_label_rtx ();
8591
8592             do_jump (TREE_OPERAND (rhs, 1),
8593                      TREE_CODE (rhs) == BIT_IOR_EXPR ? label : 0,
8594                      TREE_CODE (rhs) == BIT_AND_EXPR ? label : 0);
8595             expand_assignment (lhs, convert (TREE_TYPE (rhs),
8596                                              (TREE_CODE (rhs) == BIT_IOR_EXPR
8597                                               ? integer_one_node
8598                                               : integer_zero_node)),
8599                                0);
8600             do_pending_stack_adjust ();
8601             emit_label (label);
8602             return const0_rtx;
8603           }
8604
8605         temp = expand_assignment (lhs, rhs, ! ignore);
8606
8607         return temp;
8608       }
8609
8610     case RETURN_EXPR:
8611       if (!TREE_OPERAND (exp, 0))
8612         expand_null_return ();
8613       else
8614         expand_return (TREE_OPERAND (exp, 0));
8615       return const0_rtx;
8616
8617     case PREINCREMENT_EXPR:
8618     case PREDECREMENT_EXPR:
8619       return expand_increment (exp, 0, ignore);
8620
8621     case POSTINCREMENT_EXPR:
8622     case POSTDECREMENT_EXPR:
8623       /* Faster to treat as pre-increment if result is not used.  */
8624       return expand_increment (exp, ! ignore, ignore);
8625
8626     case ADDR_EXPR:
8627       if (modifier == EXPAND_STACK_PARM)
8628         target = 0;
8629       /* Are we taking the address of a nested function?  */
8630       if (TREE_CODE (TREE_OPERAND (exp, 0)) == FUNCTION_DECL
8631           && decl_function_context (TREE_OPERAND (exp, 0)) != 0
8632           && ! DECL_NO_STATIC_CHAIN (TREE_OPERAND (exp, 0))
8633           && ! TREE_STATIC (exp))
8634         {
8635           op0 = trampoline_address (TREE_OPERAND (exp, 0));
8636           op0 = force_operand (op0, target);
8637         }
8638       /* If we are taking the address of something erroneous, just
8639          return a zero.  */
8640       else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ERROR_MARK)
8641         return const0_rtx;
8642       /* If we are taking the address of a constant and are at the
8643          top level, we have to use output_constant_def since we can't
8644          call force_const_mem at top level.  */
8645       else if (cfun == 0
8646                && (TREE_CODE (TREE_OPERAND (exp, 0)) == CONSTRUCTOR
8647                    || (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0)))
8648                        == 'c')))
8649         op0 = XEXP (output_constant_def (TREE_OPERAND (exp, 0), 0), 0);
8650       else
8651         {
8652           /* We make sure to pass const0_rtx down if we came in with
8653              ignore set, to avoid doing the cleanups twice for something.  */
8654           op0 = expand_expr (TREE_OPERAND (exp, 0),
8655                              ignore ? const0_rtx : NULL_RTX, VOIDmode,
8656                              (modifier == EXPAND_INITIALIZER
8657                               ? modifier : EXPAND_CONST_ADDRESS));
8658
8659           /* If we are going to ignore the result, OP0 will have been set
8660              to const0_rtx, so just return it.  Don't get confused and
8661              think we are taking the address of the constant.  */
8662           if (ignore)
8663             return op0;
8664
8665           /* Pass 1 for MODIFY, so that protect_from_queue doesn't get
8666              clever and returns a REG when given a MEM.  */
8667           op0 = protect_from_queue (op0, 1);
8668
8669           /* We would like the object in memory.  If it is a constant, we can
8670              have it be statically allocated into memory.  For a non-constant,
8671              we need to allocate some memory and store the value into it.  */
8672
8673           if (CONSTANT_P (op0))
8674             op0 = force_const_mem (TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp, 0))),
8675                                    op0);
8676           else if (GET_CODE (op0) == REG || GET_CODE (op0) == SUBREG
8677                    || GET_CODE (op0) == CONCAT || GET_CODE (op0) == ADDRESSOF
8678                    || GET_CODE (op0) == PARALLEL || GET_CODE (op0) == LO_SUM)
8679             {
8680               /* If the operand is a SAVE_EXPR, we can deal with this by
8681                  forcing the SAVE_EXPR into memory.  */
8682               if (TREE_CODE (TREE_OPERAND (exp, 0)) == SAVE_EXPR)
8683                 {
8684                   put_var_into_stack (TREE_OPERAND (exp, 0),
8685                                       /*rescan=*/true);
8686                   op0 = SAVE_EXPR_RTL (TREE_OPERAND (exp, 0));
8687                 }
8688               else
8689                 {
8690                   /* If this object is in a register, it can't be BLKmode.  */
8691                   tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
8692                   rtx memloc = assign_temp (inner_type, 1, 1, 1);
8693
8694                   if (GET_CODE (op0) == PARALLEL)
8695                     /* Handle calls that pass values in multiple
8696                        non-contiguous locations.  The Irix 6 ABI has examples
8697                        of this.  */
8698                     emit_group_store (memloc, op0, inner_type,
8699                                       int_size_in_bytes (inner_type));
8700                   else
8701                     emit_move_insn (memloc, op0);
8702
8703                   op0 = memloc;
8704                 }
8705             }
8706
8707           if (GET_CODE (op0) != MEM)
8708             abort ();
8709
8710           mark_temp_addr_taken (op0);
8711           if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
8712             {
8713               op0 = XEXP (op0, 0);
8714               if (GET_MODE (op0) == Pmode && mode == ptr_mode)
8715                 op0 = convert_memory_address (ptr_mode, op0);
8716               return op0;
8717             }
8718
8719           /* If OP0 is not aligned as least as much as the type requires, we
8720              need to make a temporary, copy OP0 to it, and take the address of
8721              the temporary.  We want to use the alignment of the type, not of
8722              the operand.  Note that this is incorrect for FUNCTION_TYPE, but
8723              the test for BLKmode means that can't happen.  The test for
8724              BLKmode is because we never make mis-aligned MEMs with
8725              non-BLKmode.
8726
8727              We don't need to do this at all if the machine doesn't have
8728              strict alignment.  */
8729           if (STRICT_ALIGNMENT && GET_MODE (op0) == BLKmode
8730               && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0)))
8731                   > MEM_ALIGN (op0))
8732               && MEM_ALIGN (op0) < BIGGEST_ALIGNMENT)
8733             {
8734               tree inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
8735               rtx new;
8736
8737               if (TYPE_ALIGN_OK (inner_type))
8738                 abort ();
8739
8740               if (TREE_ADDRESSABLE (inner_type))
8741                 {
8742                   /* We can't make a bitwise copy of this object, so fail.  */
8743                   error ("cannot take the address of an unaligned member");
8744                   return const0_rtx;
8745                 }
8746
8747               new = assign_stack_temp_for_type
8748                 (TYPE_MODE (inner_type),
8749                  MEM_SIZE (op0) ? INTVAL (MEM_SIZE (op0))
8750                  : int_size_in_bytes (inner_type),
8751                  1, build_qualified_type (inner_type,
8752                                           (TYPE_QUALS (inner_type)
8753                                            | TYPE_QUAL_CONST)));
8754
8755               emit_block_move (new, op0, expr_size (TREE_OPERAND (exp, 0)),
8756                                (modifier == EXPAND_STACK_PARM
8757                                 ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
8758
8759               op0 = new;
8760             }
8761
8762           op0 = force_operand (XEXP (op0, 0), target);
8763         }
8764
8765       if (flag_force_addr
8766           && GET_CODE (op0) != REG
8767           && modifier != EXPAND_CONST_ADDRESS
8768           && modifier != EXPAND_INITIALIZER
8769           && modifier != EXPAND_SUM)
8770         op0 = force_reg (Pmode, op0);
8771
8772       if (GET_CODE (op0) == REG
8773           && ! REG_USERVAR_P (op0))
8774         mark_reg_pointer (op0, TYPE_ALIGN (TREE_TYPE (type)));
8775
8776       if (GET_MODE (op0) == Pmode && mode == ptr_mode)
8777         op0 = convert_memory_address (ptr_mode, op0);
8778
8779       return op0;
8780
8781     case ENTRY_VALUE_EXPR:
8782       abort ();
8783
8784     /* COMPLEX type for Extended Pascal & Fortran  */
8785     case COMPLEX_EXPR:
8786       {
8787         enum machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
8788         rtx insns;
8789
8790         /* Get the rtx code of the operands.  */
8791         op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
8792         op1 = expand_expr (TREE_OPERAND (exp, 1), 0, VOIDmode, 0);
8793
8794         if (! target)
8795           target = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
8796
8797         start_sequence ();
8798
8799         /* Move the real (op0) and imaginary (op1) parts to their location.  */
8800         emit_move_insn (gen_realpart (mode, target), op0);
8801         emit_move_insn (gen_imagpart (mode, target), op1);
8802
8803         insns = get_insns ();
8804         end_sequence ();
8805
8806         /* Complex construction should appear as a single unit.  */
8807         /* If TARGET is a CONCAT, we got insns like RD = RS, ID = IS,
8808            each with a separate pseudo as destination.
8809            It's not correct for flow to treat them as a unit.  */
8810         if (GET_CODE (target) != CONCAT)
8811           emit_no_conflict_block (insns, target, op0, op1, NULL_RTX);
8812         else
8813           emit_insn (insns);
8814
8815         return target;
8816       }
8817
8818     case REALPART_EXPR:
8819       op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
8820       return gen_realpart (mode, op0);
8821
8822     case IMAGPART_EXPR:
8823       op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
8824       return gen_imagpart (mode, op0);
8825
8826     case CONJ_EXPR:
8827       {
8828         enum machine_mode partmode = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
8829         rtx imag_t;
8830         rtx insns;
8831
8832         op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
8833
8834         if (! target)
8835           target = gen_reg_rtx (mode);
8836
8837         start_sequence ();
8838
8839         /* Store the realpart and the negated imagpart to target.  */
8840         emit_move_insn (gen_realpart (partmode, target),
8841                         gen_realpart (partmode, op0));
8842
8843         imag_t = gen_imagpart (partmode, target);
8844         temp = expand_unop (partmode,
8845                             ! unsignedp && flag_trapv
8846                             && (GET_MODE_CLASS(partmode) == MODE_INT)
8847                             ? negv_optab : neg_optab,
8848                             gen_imagpart (partmode, op0), imag_t, 0);
8849         if (temp != imag_t)
8850           emit_move_insn (imag_t, temp);
8851
8852         insns = get_insns ();
8853         end_sequence ();
8854
8855         /* Conjugate should appear as a single unit
8856            If TARGET is a CONCAT, we got insns like RD = RS, ID = - IS,
8857            each with a separate pseudo as destination.
8858            It's not correct for flow to treat them as a unit.  */
8859         if (GET_CODE (target) != CONCAT)
8860           emit_no_conflict_block (insns, target, op0, NULL_RTX, NULL_RTX);
8861         else
8862           emit_insn (insns);
8863
8864         return target;
8865       }
8866
8867     case TRY_CATCH_EXPR:
8868       {
8869         tree handler = TREE_OPERAND (exp, 1);
8870
8871         expand_eh_region_start ();
8872
8873         op0 = expand_expr (TREE_OPERAND (exp, 0), 0, VOIDmode, 0);
8874
8875         expand_eh_region_end_cleanup (handler);
8876
8877         return op0;
8878       }
8879
8880     case TRY_FINALLY_EXPR:
8881       {
8882         tree try_block = TREE_OPERAND (exp, 0);
8883         tree finally_block = TREE_OPERAND (exp, 1);
8884
8885         if (!optimize || unsafe_for_reeval (finally_block) > 1)
8886           {
8887             /* In this case, wrapping FINALLY_BLOCK in an UNSAVE_EXPR
8888                is not sufficient, so we cannot expand the block twice.
8889                So we play games with GOTO_SUBROUTINE_EXPR to let us
8890                expand the thing only once.  */
8891             /* When not optimizing, we go ahead with this form since
8892                (1) user breakpoints operate more predictably without
8893                    code duplication, and
8894                (2) we're not running any of the global optimizers
8895                    that would explode in time/space with the highly
8896                    connected CFG created by the indirect branching.  */
8897
8898             rtx finally_label = gen_label_rtx ();
8899             rtx done_label = gen_label_rtx ();
8900             rtx return_link = gen_reg_rtx (Pmode);
8901             tree cleanup = build (GOTO_SUBROUTINE_EXPR, void_type_node,
8902                                   (tree) finally_label, (tree) return_link);
8903             TREE_SIDE_EFFECTS (cleanup) = 1;
8904
8905             /* Start a new binding layer that will keep track of all cleanup
8906                actions to be performed.  */
8907             expand_start_bindings (2);
8908             target_temp_slot_level = temp_slot_level;
8909
8910             expand_decl_cleanup (NULL_TREE, cleanup);
8911             op0 = expand_expr (try_block, target, tmode, modifier);
8912
8913             preserve_temp_slots (op0);
8914             expand_end_bindings (NULL_TREE, 0, 0);
8915             emit_jump (done_label);
8916             emit_label (finally_label);
8917             expand_expr (finally_block, const0_rtx, VOIDmode, 0);
8918             emit_indirect_jump (return_link);
8919             emit_label (done_label);
8920           }
8921         else
8922           {
8923             expand_start_bindings (2);
8924             target_temp_slot_level = temp_slot_level;
8925
8926             expand_decl_cleanup (NULL_TREE, finally_block);
8927             op0 = expand_expr (try_block, target, tmode, modifier);
8928
8929             preserve_temp_slots (op0);
8930             expand_end_bindings (NULL_TREE, 0, 0);
8931           }
8932
8933         return op0;
8934       }
8935
8936     case GOTO_SUBROUTINE_EXPR:
8937       {
8938         rtx subr = (rtx) TREE_OPERAND (exp, 0);
8939         rtx return_link = *(rtx *) &TREE_OPERAND (exp, 1);
8940         rtx return_address = gen_label_rtx ();
8941         emit_move_insn (return_link,
8942                         gen_rtx_LABEL_REF (Pmode, return_address));
8943         emit_jump (subr);
8944         emit_label (return_address);
8945         return const0_rtx;
8946       }
8947
8948     case VA_ARG_EXPR:
8949       return expand_builtin_va_arg (TREE_OPERAND (exp, 0), type);
8950
8951     case EXC_PTR_EXPR:
8952       return get_exception_pointer (cfun);
8953
8954     case FDESC_EXPR:
8955       /* Function descriptors are not valid except for as
8956          initialization constants, and should not be expanded.  */
8957       abort ();
8958
8959     default:
8960       /* ??? Use (*fun) form because expand_expr is a macro.  */
8961       return (*lang_hooks.expand_expr) (exp, original_target, tmode,
8962                                         modifier, alt_rtl);
8963     }
8964
8965   /* Here to do an ordinary binary operator, generating an instruction
8966      from the optab already placed in `this_optab'.  */
8967  binop:
8968   expand_operands (TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
8969                    subtarget, &op0, &op1, 0);
8970  binop2:
8971   if (modifier == EXPAND_STACK_PARM)
8972     target = 0;
8973   temp = expand_binop (mode, this_optab, op0, op1, target,
8974                        unsignedp, OPTAB_LIB_WIDEN);
8975   if (temp == 0)
8976     abort ();
8977   return temp;
8978 }
8979 \f
8980 /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
8981    when applied to the address of EXP produces an address known to be
8982    aligned more than BIGGEST_ALIGNMENT.  */
8983
8984 static int
8985 is_aligning_offset (tree offset, tree exp)
8986 {
8987   /* Strip off any conversions.  */
8988   while (TREE_CODE (offset) == NON_LVALUE_EXPR
8989          || TREE_CODE (offset) == NOP_EXPR
8990          || TREE_CODE (offset) == CONVERT_EXPR)
8991     offset = TREE_OPERAND (offset, 0);
8992
8993   /* We must now have a BIT_AND_EXPR with a constant that is one less than
8994      power of 2 and which is larger than BIGGEST_ALIGNMENT.  */
8995   if (TREE_CODE (offset) != BIT_AND_EXPR
8996       || !host_integerp (TREE_OPERAND (offset, 1), 1)
8997       || compare_tree_int (TREE_OPERAND (offset, 1), 
8998                            BIGGEST_ALIGNMENT / BITS_PER_UNIT) <= 0
8999       || !exact_log2 (tree_low_cst (TREE_OPERAND (offset, 1), 1) + 1) < 0)
9000     return 0;
9001
9002   /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
9003      It must be NEGATE_EXPR.  Then strip any more conversions.  */
9004   offset = TREE_OPERAND (offset, 0);
9005   while (TREE_CODE (offset) == NON_LVALUE_EXPR
9006          || TREE_CODE (offset) == NOP_EXPR
9007          || TREE_CODE (offset) == CONVERT_EXPR)
9008     offset = TREE_OPERAND (offset, 0);
9009
9010   if (TREE_CODE (offset) != NEGATE_EXPR)
9011     return 0;
9012
9013   offset = TREE_OPERAND (offset, 0);
9014   while (TREE_CODE (offset) == NON_LVALUE_EXPR
9015          || TREE_CODE (offset) == NOP_EXPR
9016          || TREE_CODE (offset) == CONVERT_EXPR)
9017     offset = TREE_OPERAND (offset, 0);
9018
9019   /* This must now be the address of EXP.  */
9020   return TREE_CODE (offset) == ADDR_EXPR && TREE_OPERAND (offset, 0) == exp;
9021 }
9022 \f
9023 /* Return the tree node if an ARG corresponds to a string constant or zero
9024    if it doesn't.  If we return nonzero, set *PTR_OFFSET to the offset
9025    in bytes within the string that ARG is accessing.  The type of the
9026    offset will be `sizetype'.  */
9027
9028 tree
9029 string_constant (tree arg, tree *ptr_offset)
9030 {
9031   STRIP_NOPS (arg);
9032
9033   if (TREE_CODE (arg) == ADDR_EXPR
9034       && TREE_CODE (TREE_OPERAND (arg, 0)) == STRING_CST)
9035     {
9036       *ptr_offset = size_zero_node;
9037       return TREE_OPERAND (arg, 0);
9038     }
9039   else if (TREE_CODE (arg) == PLUS_EXPR)
9040     {
9041       tree arg0 = TREE_OPERAND (arg, 0);
9042       tree arg1 = TREE_OPERAND (arg, 1);
9043
9044       STRIP_NOPS (arg0);
9045       STRIP_NOPS (arg1);
9046
9047       if (TREE_CODE (arg0) == ADDR_EXPR
9048           && TREE_CODE (TREE_OPERAND (arg0, 0)) == STRING_CST)
9049         {
9050           *ptr_offset = convert (sizetype, arg1);
9051           return TREE_OPERAND (arg0, 0);
9052         }
9053       else if (TREE_CODE (arg1) == ADDR_EXPR
9054                && TREE_CODE (TREE_OPERAND (arg1, 0)) == STRING_CST)
9055         {
9056           *ptr_offset = convert (sizetype, arg0);
9057           return TREE_OPERAND (arg1, 0);
9058         }
9059     }
9060
9061   return 0;
9062 }
9063 \f
9064 /* Expand code for a post- or pre- increment or decrement
9065    and return the RTX for the result.
9066    POST is 1 for postinc/decrements and 0 for preinc/decrements.  */
9067
9068 static rtx
9069 expand_increment (tree exp, int post, int ignore)
9070 {
9071   rtx op0, op1;
9072   rtx temp, value;
9073   tree incremented = TREE_OPERAND (exp, 0);
9074   optab this_optab = add_optab;
9075   int icode;
9076   enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
9077   int op0_is_copy = 0;
9078   int single_insn = 0;
9079   /* 1 means we can't store into OP0 directly,
9080      because it is a subreg narrower than a word,
9081      and we don't dare clobber the rest of the word.  */
9082   int bad_subreg = 0;
9083
9084   /* Stabilize any component ref that might need to be
9085      evaluated more than once below.  */
9086   if (!post
9087       || TREE_CODE (incremented) == BIT_FIELD_REF
9088       || (TREE_CODE (incremented) == COMPONENT_REF
9089           && (TREE_CODE (TREE_OPERAND (incremented, 0)) != INDIRECT_REF
9090               || DECL_BIT_FIELD (TREE_OPERAND (incremented, 1)))))
9091     incremented = stabilize_reference (incremented);
9092   /* Nested *INCREMENT_EXPRs can happen in C++.  We must force innermost
9093      ones into save exprs so that they don't accidentally get evaluated
9094      more than once by the code below.  */
9095   if (TREE_CODE (incremented) == PREINCREMENT_EXPR
9096       || TREE_CODE (incremented) == PREDECREMENT_EXPR)
9097     incremented = save_expr (incremented);
9098
9099   /* Compute the operands as RTX.
9100      Note whether OP0 is the actual lvalue or a copy of it:
9101      I believe it is a copy iff it is a register or subreg
9102      and insns were generated in computing it.  */
9103
9104   temp = get_last_insn ();
9105   op0 = expand_expr (incremented, NULL_RTX, VOIDmode, 0);
9106
9107   /* If OP0 is a SUBREG made for a promoted variable, we cannot increment
9108      in place but instead must do sign- or zero-extension during assignment,
9109      so we copy it into a new register and let the code below use it as
9110      a copy.
9111
9112      Note that we can safely modify this SUBREG since it is know not to be
9113      shared (it was made by the expand_expr call above).  */
9114
9115   if (GET_CODE (op0) == SUBREG && SUBREG_PROMOTED_VAR_P (op0))
9116     {
9117       if (post)
9118         SUBREG_REG (op0) = copy_to_reg (SUBREG_REG (op0));
9119       else
9120         bad_subreg = 1;
9121     }
9122   else if (GET_CODE (op0) == SUBREG
9123            && GET_MODE_BITSIZE (GET_MODE (op0)) < BITS_PER_WORD)
9124     {
9125       /* We cannot increment this SUBREG in place.  If we are
9126          post-incrementing, get a copy of the old value.  Otherwise,
9127          just mark that we cannot increment in place.  */
9128       if (post)
9129         op0 = copy_to_reg (op0);
9130       else
9131         bad_subreg = 1;
9132     }
9133
9134   op0_is_copy = ((GET_CODE (op0) == SUBREG || GET_CODE (op0) == REG)
9135                  && temp != get_last_insn ());
9136   op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
9137
9138   /* Decide whether incrementing or decrementing.  */
9139   if (TREE_CODE (exp) == POSTDECREMENT_EXPR
9140       || TREE_CODE (exp) == PREDECREMENT_EXPR)
9141     this_optab = sub_optab;
9142
9143   /* Convert decrement by a constant into a negative increment.  */
9144   if (this_optab == sub_optab
9145       && GET_CODE (op1) == CONST_INT)
9146     {
9147       op1 = GEN_INT (-INTVAL (op1));
9148       this_optab = add_optab;
9149     }
9150
9151   if (TYPE_TRAP_SIGNED (TREE_TYPE (exp)))
9152     this_optab = this_optab == add_optab ? addv_optab : subv_optab;
9153
9154   /* For a preincrement, see if we can do this with a single instruction.  */
9155   if (!post)
9156     {
9157       icode = (int) this_optab->handlers[(int) mode].insn_code;
9158       if (icode != (int) CODE_FOR_nothing
9159           /* Make sure that OP0 is valid for operands 0 and 1
9160              of the insn we want to queue.  */
9161           && (*insn_data[icode].operand[0].predicate) (op0, mode)
9162           && (*insn_data[icode].operand[1].predicate) (op0, mode)
9163           && (*insn_data[icode].operand[2].predicate) (op1, mode))
9164         single_insn = 1;
9165     }
9166
9167   /* If OP0 is not the actual lvalue, but rather a copy in a register,
9168      then we cannot just increment OP0.  We must therefore contrive to
9169      increment the original value.  Then, for postincrement, we can return
9170      OP0 since it is a copy of the old value.  For preincrement, expand here
9171      unless we can do it with a single insn.
9172
9173      Likewise if storing directly into OP0 would clobber high bits
9174      we need to preserve (bad_subreg).  */
9175   if (op0_is_copy || (!post && !single_insn) || bad_subreg)
9176     {
9177       /* This is the easiest way to increment the value wherever it is.
9178          Problems with multiple evaluation of INCREMENTED are prevented
9179          because either (1) it is a component_ref or preincrement,
9180          in which case it was stabilized above, or (2) it is an array_ref
9181          with constant index in an array in a register, which is
9182          safe to reevaluate.  */
9183       tree newexp = build (((TREE_CODE (exp) == POSTDECREMENT_EXPR
9184                              || TREE_CODE (exp) == PREDECREMENT_EXPR)
9185                             ? MINUS_EXPR : PLUS_EXPR),
9186                            TREE_TYPE (exp),
9187                            incremented,
9188                            TREE_OPERAND (exp, 1));
9189
9190       while (TREE_CODE (incremented) == NOP_EXPR
9191              || TREE_CODE (incremented) == CONVERT_EXPR)
9192         {
9193           newexp = convert (TREE_TYPE (incremented), newexp);
9194           incremented = TREE_OPERAND (incremented, 0);
9195         }
9196
9197       temp = expand_assignment (incremented, newexp, ! post && ! ignore);
9198       return post ? op0 : temp;
9199     }
9200
9201   if (post)
9202     {
9203       /* We have a true reference to the value in OP0.
9204          If there is an insn to add or subtract in this mode, queue it.
9205          Queuing the increment insn avoids the register shuffling
9206          that often results if we must increment now and first save
9207          the old value for subsequent use.  */
9208
9209 #if 0  /* Turned off to avoid making extra insn for indexed memref.  */
9210       op0 = stabilize (op0);
9211 #endif
9212
9213       icode = (int) this_optab->handlers[(int) mode].insn_code;
9214       if (icode != (int) CODE_FOR_nothing
9215           /* Make sure that OP0 is valid for operands 0 and 1
9216              of the insn we want to queue.  */
9217           && (*insn_data[icode].operand[0].predicate) (op0, mode)
9218           && (*insn_data[icode].operand[1].predicate) (op0, mode))
9219         {
9220           if (! (*insn_data[icode].operand[2].predicate) (op1, mode))
9221             op1 = force_reg (mode, op1);
9222
9223           return enqueue_insn (op0, GEN_FCN (icode) (op0, op0, op1));
9224         }
9225       if (icode != (int) CODE_FOR_nothing && GET_CODE (op0) == MEM)
9226         {
9227           rtx addr = (general_operand (XEXP (op0, 0), mode)
9228                       ? force_reg (Pmode, XEXP (op0, 0))
9229                       : copy_to_reg (XEXP (op0, 0)));
9230           rtx temp, result;
9231
9232           op0 = replace_equiv_address (op0, addr);
9233           temp = force_reg (GET_MODE (op0), op0);
9234           if (! (*insn_data[icode].operand[2].predicate) (op1, mode))
9235             op1 = force_reg (mode, op1);
9236
9237           /* The increment queue is LIFO, thus we have to `queue'
9238              the instructions in reverse order.  */
9239           enqueue_insn (op0, gen_move_insn (op0, temp));
9240           result = enqueue_insn (temp, GEN_FCN (icode) (temp, temp, op1));
9241           return result;
9242         }
9243     }
9244
9245   /* Preincrement, or we can't increment with one simple insn.  */
9246   if (post)
9247     /* Save a copy of the value before inc or dec, to return it later.  */
9248     temp = value = copy_to_reg (op0);
9249   else
9250     /* Arrange to return the incremented value.  */
9251     /* Copy the rtx because expand_binop will protect from the queue,
9252        and the results of that would be invalid for us to return
9253        if our caller does emit_queue before using our result.  */
9254     temp = copy_rtx (value = op0);
9255
9256   /* Increment however we can.  */
9257   op1 = expand_binop (mode, this_optab, value, op1, op0,
9258                       TREE_UNSIGNED (TREE_TYPE (exp)), OPTAB_LIB_WIDEN);
9259
9260   /* Make sure the value is stored into OP0.  */
9261   if (op1 != op0)
9262     emit_move_insn (op0, op1);
9263
9264   return temp;
9265 }
9266 \f
9267 /* Generate code to calculate EXP using a store-flag instruction
9268    and return an rtx for the result.  EXP is either a comparison
9269    or a TRUTH_NOT_EXPR whose operand is a comparison.
9270
9271    If TARGET is nonzero, store the result there if convenient.
9272
9273    If ONLY_CHEAP is nonzero, only do this if it is likely to be very
9274    cheap.
9275
9276    Return zero if there is no suitable set-flag instruction
9277    available on this machine.
9278
9279    Once expand_expr has been called on the arguments of the comparison,
9280    we are committed to doing the store flag, since it is not safe to
9281    re-evaluate the expression.  We emit the store-flag insn by calling
9282    emit_store_flag, but only expand the arguments if we have a reason
9283    to believe that emit_store_flag will be successful.  If we think that
9284    it will, but it isn't, we have to simulate the store-flag with a
9285    set/jump/set sequence.  */
9286
9287 static rtx
9288 do_store_flag (tree exp, rtx target, enum machine_mode mode, int only_cheap)
9289 {
9290   enum rtx_code code;
9291   tree arg0, arg1, type;
9292   tree tem;
9293   enum machine_mode operand_mode;
9294   int invert = 0;
9295   int unsignedp;
9296   rtx op0, op1;
9297   enum insn_code icode;
9298   rtx subtarget = target;
9299   rtx result, label;
9300
9301   /* If this is a TRUTH_NOT_EXPR, set a flag indicating we must invert the
9302      result at the end.  We can't simply invert the test since it would
9303      have already been inverted if it were valid.  This case occurs for
9304      some floating-point comparisons.  */
9305
9306   if (TREE_CODE (exp) == TRUTH_NOT_EXPR)
9307     invert = 1, exp = TREE_OPERAND (exp, 0);
9308
9309   arg0 = TREE_OPERAND (exp, 0);
9310   arg1 = TREE_OPERAND (exp, 1);
9311
9312   /* Don't crash if the comparison was erroneous.  */
9313   if (arg0 == error_mark_node || arg1 == error_mark_node)
9314     return const0_rtx;
9315
9316   type = TREE_TYPE (arg0);
9317   operand_mode = TYPE_MODE (type);
9318   unsignedp = TREE_UNSIGNED (type);
9319
9320   /* We won't bother with BLKmode store-flag operations because it would mean
9321      passing a lot of information to emit_store_flag.  */
9322   if (operand_mode == BLKmode)
9323     return 0;
9324
9325   /* We won't bother with store-flag operations involving function pointers
9326      when function pointers must be canonicalized before comparisons.  */
9327 #ifdef HAVE_canonicalize_funcptr_for_compare
9328   if (HAVE_canonicalize_funcptr_for_compare
9329       && ((TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == POINTER_TYPE
9330            && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))))
9331                == FUNCTION_TYPE))
9332           || (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 1))) == POINTER_TYPE
9333               && (TREE_CODE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 1))))
9334                   == FUNCTION_TYPE))))
9335     return 0;
9336 #endif
9337
9338   STRIP_NOPS (arg0);
9339   STRIP_NOPS (arg1);
9340
9341   /* Get the rtx comparison code to use.  We know that EXP is a comparison
9342      operation of some type.  Some comparisons against 1 and -1 can be
9343      converted to comparisons with zero.  Do so here so that the tests
9344      below will be aware that we have a comparison with zero.   These
9345      tests will not catch constants in the first operand, but constants
9346      are rarely passed as the first operand.  */
9347
9348   switch (TREE_CODE (exp))
9349     {
9350     case EQ_EXPR:
9351       code = EQ;
9352       break;
9353     case NE_EXPR:
9354       code = NE;
9355       break;
9356     case LT_EXPR:
9357       if (integer_onep (arg1))
9358         arg1 = integer_zero_node, code = unsignedp ? LEU : LE;
9359       else
9360         code = unsignedp ? LTU : LT;
9361       break;
9362     case LE_EXPR:
9363       if (! unsignedp && integer_all_onesp (arg1))
9364         arg1 = integer_zero_node, code = LT;
9365       else
9366         code = unsignedp ? LEU : LE;
9367       break;
9368     case GT_EXPR:
9369       if (! unsignedp && integer_all_onesp (arg1))
9370         arg1 = integer_zero_node, code = GE;
9371       else
9372         code = unsignedp ? GTU : GT;
9373       break;
9374     case GE_EXPR:
9375       if (integer_onep (arg1))
9376         arg1 = integer_zero_node, code = unsignedp ? GTU : GT;
9377       else
9378         code = unsignedp ? GEU : GE;
9379       break;
9380
9381     case UNORDERED_EXPR:
9382       code = UNORDERED;
9383       break;
9384     case ORDERED_EXPR:
9385       code = ORDERED;
9386       break;
9387     case UNLT_EXPR:
9388       code = UNLT;
9389       break;
9390     case UNLE_EXPR:
9391       code = UNLE;
9392       break;
9393     case UNGT_EXPR:
9394       code = UNGT;
9395       break;
9396     case UNGE_EXPR:
9397       code = UNGE;
9398       break;
9399     case UNEQ_EXPR:
9400       code = UNEQ;
9401       break;
9402
9403     default:
9404       abort ();
9405     }
9406
9407   /* Put a constant second.  */
9408   if (TREE_CODE (arg0) == REAL_CST || TREE_CODE (arg0) == INTEGER_CST)
9409     {
9410       tem = arg0; arg0 = arg1; arg1 = tem;
9411       code = swap_condition (code);
9412     }
9413
9414   /* If this is an equality or inequality test of a single bit, we can
9415      do this by shifting the bit being tested to the low-order bit and
9416      masking the result with the constant 1.  If the condition was EQ,
9417      we xor it with 1.  This does not require an scc insn and is faster
9418      than an scc insn even if we have it.
9419
9420      The code to make this transformation was moved into fold_single_bit_test,
9421      so we just call into the folder and expand its result.  */
9422
9423   if ((code == NE || code == EQ)
9424       && TREE_CODE (arg0) == BIT_AND_EXPR && integer_zerop (arg1)
9425       && integer_pow2p (TREE_OPERAND (arg0, 1)))
9426     {
9427       tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
9428       return expand_expr (fold_single_bit_test (code == NE ? NE_EXPR : EQ_EXPR,
9429                                                 arg0, arg1, type),
9430                           target, VOIDmode, EXPAND_NORMAL);
9431     }
9432
9433   /* Now see if we are likely to be able to do this.  Return if not.  */
9434   if (! can_compare_p (code, operand_mode, ccp_store_flag))
9435     return 0;
9436
9437   icode = setcc_gen_code[(int) code];
9438   if (icode == CODE_FOR_nothing
9439       || (only_cheap && insn_data[(int) icode].operand[0].mode != mode))
9440     {
9441       /* We can only do this if it is one of the special cases that
9442          can be handled without an scc insn.  */
9443       if ((code == LT && integer_zerop (arg1))
9444           || (! only_cheap && code == GE && integer_zerop (arg1)))
9445         ;
9446       else if (BRANCH_COST >= 0
9447                && ! only_cheap && (code == NE || code == EQ)
9448                && TREE_CODE (type) != REAL_TYPE
9449                && ((abs_optab->handlers[(int) operand_mode].insn_code
9450                     != CODE_FOR_nothing)
9451                    || (ffs_optab->handlers[(int) operand_mode].insn_code
9452                        != CODE_FOR_nothing)))
9453         ;
9454       else
9455         return 0;
9456     }
9457
9458   if (! get_subtarget (target)
9459       || GET_MODE (subtarget) != operand_mode)
9460     subtarget = 0;
9461
9462   expand_operands (arg0, arg1, subtarget, &op0, &op1, 0);
9463
9464   if (target == 0)
9465     target = gen_reg_rtx (mode);
9466
9467   /* Pass copies of OP0 and OP1 in case they contain a QUEUED.  This is safe
9468      because, if the emit_store_flag does anything it will succeed and
9469      OP0 and OP1 will not be used subsequently.  */
9470
9471   result = emit_store_flag (target, code,
9472                             queued_subexp_p (op0) ? copy_rtx (op0) : op0,
9473                             queued_subexp_p (op1) ? copy_rtx (op1) : op1,
9474                             operand_mode, unsignedp, 1);
9475
9476   if (result)
9477     {
9478       if (invert)
9479         result = expand_binop (mode, xor_optab, result, const1_rtx,
9480                                result, 0, OPTAB_LIB_WIDEN);
9481       return result;
9482     }
9483
9484   /* If this failed, we have to do this with set/compare/jump/set code.  */
9485   if (GET_CODE (target) != REG
9486       || reg_mentioned_p (target, op0) || reg_mentioned_p (target, op1))
9487     target = gen_reg_rtx (GET_MODE (target));
9488
9489   emit_move_insn (target, invert ? const0_rtx : const1_rtx);
9490   result = compare_from_rtx (op0, op1, code, unsignedp,
9491                              operand_mode, NULL_RTX);
9492   if (GET_CODE (result) == CONST_INT)
9493     return (((result == const0_rtx && ! invert)
9494              || (result != const0_rtx && invert))
9495             ? const0_rtx : const1_rtx);
9496
9497   /* The code of RESULT may not match CODE if compare_from_rtx
9498      decided to swap its operands and reverse the original code.
9499
9500      We know that compare_from_rtx returns either a CONST_INT or
9501      a new comparison code, so it is safe to just extract the
9502      code from RESULT.  */
9503   code = GET_CODE (result);
9504
9505   label = gen_label_rtx ();
9506   if (bcc_gen_fctn[(int) code] == 0)
9507     abort ();
9508
9509   emit_jump_insn ((*bcc_gen_fctn[(int) code]) (label));
9510   emit_move_insn (target, invert ? const1_rtx : const0_rtx);
9511   emit_label (label);
9512
9513   return target;
9514 }
9515 \f
9516
9517 /* Stubs in case we haven't got a casesi insn.  */
9518 #ifndef HAVE_casesi
9519 # define HAVE_casesi 0
9520 # define gen_casesi(a, b, c, d, e) (0)
9521 # define CODE_FOR_casesi CODE_FOR_nothing
9522 #endif
9523
9524 /* If the machine does not have a case insn that compares the bounds,
9525    this means extra overhead for dispatch tables, which raises the
9526    threshold for using them.  */
9527 #ifndef CASE_VALUES_THRESHOLD
9528 #define CASE_VALUES_THRESHOLD (HAVE_casesi ? 4 : 5)
9529 #endif /* CASE_VALUES_THRESHOLD */
9530
9531 unsigned int
9532 case_values_threshold (void)
9533 {
9534   return CASE_VALUES_THRESHOLD;
9535 }
9536
9537 /* Attempt to generate a casesi instruction.  Returns 1 if successful,
9538    0 otherwise (i.e. if there is no casesi instruction).  */
9539 int
9540 try_casesi (tree index_type, tree index_expr, tree minval, tree range,
9541             rtx table_label ATTRIBUTE_UNUSED, rtx default_label)
9542 {
9543   enum machine_mode index_mode = SImode;
9544   int index_bits = GET_MODE_BITSIZE (index_mode);
9545   rtx op1, op2, index;
9546   enum machine_mode op_mode;
9547
9548   if (! HAVE_casesi)
9549     return 0;
9550
9551   /* Convert the index to SImode.  */
9552   if (GET_MODE_BITSIZE (TYPE_MODE (index_type)) > GET_MODE_BITSIZE (index_mode))
9553     {
9554       enum machine_mode omode = TYPE_MODE (index_type);
9555       rtx rangertx = expand_expr (range, NULL_RTX, VOIDmode, 0);
9556
9557       /* We must handle the endpoints in the original mode.  */
9558       index_expr = build (MINUS_EXPR, index_type,
9559                           index_expr, minval);
9560       minval = integer_zero_node;
9561       index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
9562       emit_cmp_and_jump_insns (rangertx, index, LTU, NULL_RTX,
9563                                omode, 1, default_label);
9564       /* Now we can safely truncate.  */
9565       index = convert_to_mode (index_mode, index, 0);
9566     }
9567   else
9568     {
9569       if (TYPE_MODE (index_type) != index_mode)
9570         {
9571           index_expr = convert (lang_hooks.types.type_for_size
9572                                 (index_bits, 0), index_expr);
9573           index_type = TREE_TYPE (index_expr);
9574         }
9575
9576       index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
9577     }
9578   emit_queue ();
9579   index = protect_from_queue (index, 0);
9580   do_pending_stack_adjust ();
9581
9582   op_mode = insn_data[(int) CODE_FOR_casesi].operand[0].mode;
9583   if (! (*insn_data[(int) CODE_FOR_casesi].operand[0].predicate)
9584       (index, op_mode))
9585     index = copy_to_mode_reg (op_mode, index);
9586
9587   op1 = expand_expr (minval, NULL_RTX, VOIDmode, 0);
9588
9589   op_mode = insn_data[(int) CODE_FOR_casesi].operand[1].mode;
9590   op1 = convert_modes (op_mode, TYPE_MODE (TREE_TYPE (minval)),
9591                        op1, TREE_UNSIGNED (TREE_TYPE (minval)));
9592   if (! (*insn_data[(int) CODE_FOR_casesi].operand[1].predicate)
9593       (op1, op_mode))
9594     op1 = copy_to_mode_reg (op_mode, op1);
9595
9596   op2 = expand_expr (range, NULL_RTX, VOIDmode, 0);
9597
9598   op_mode = insn_data[(int) CODE_FOR_casesi].operand[2].mode;
9599   op2 = convert_modes (op_mode, TYPE_MODE (TREE_TYPE (range)),
9600                        op2, TREE_UNSIGNED (TREE_TYPE (range)));
9601   if (! (*insn_data[(int) CODE_FOR_casesi].operand[2].predicate)
9602       (op2, op_mode))
9603     op2 = copy_to_mode_reg (op_mode, op2);
9604
9605   emit_jump_insn (gen_casesi (index, op1, op2,
9606                               table_label, default_label));
9607   return 1;
9608 }
9609
9610 /* Attempt to generate a tablejump instruction; same concept.  */
9611 #ifndef HAVE_tablejump
9612 #define HAVE_tablejump 0
9613 #define gen_tablejump(x, y) (0)
9614 #endif
9615
9616 /* Subroutine of the next function.
9617
9618    INDEX is the value being switched on, with the lowest value
9619    in the table already subtracted.
9620    MODE is its expected mode (needed if INDEX is constant).
9621    RANGE is the length of the jump table.
9622    TABLE_LABEL is a CODE_LABEL rtx for the table itself.
9623
9624    DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
9625    index value is out of range.  */
9626
9627 static void
9628 do_tablejump (rtx index, enum machine_mode mode, rtx range, rtx table_label,
9629               rtx default_label)
9630 {
9631   rtx temp, vector;
9632
9633   if (INTVAL (range) > cfun->max_jumptable_ents)
9634     cfun->max_jumptable_ents = INTVAL (range);
9635
9636   /* Do an unsigned comparison (in the proper mode) between the index
9637      expression and the value which represents the length of the range.
9638      Since we just finished subtracting the lower bound of the range
9639      from the index expression, this comparison allows us to simultaneously
9640      check that the original index expression value is both greater than
9641      or equal to the minimum value of the range and less than or equal to
9642      the maximum value of the range.  */
9643
9644   emit_cmp_and_jump_insns (index, range, GTU, NULL_RTX, mode, 1,
9645                            default_label);
9646
9647   /* If index is in range, it must fit in Pmode.
9648      Convert to Pmode so we can index with it.  */
9649   if (mode != Pmode)
9650     index = convert_to_mode (Pmode, index, 1);
9651
9652   /* Don't let a MEM slip through, because then INDEX that comes
9653      out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
9654      and break_out_memory_refs will go to work on it and mess it up.  */
9655 #ifdef PIC_CASE_VECTOR_ADDRESS
9656   if (flag_pic && GET_CODE (index) != REG)
9657     index = copy_to_mode_reg (Pmode, index);
9658 #endif
9659
9660   /* If flag_force_addr were to affect this address
9661      it could interfere with the tricky assumptions made
9662      about addresses that contain label-refs,
9663      which may be valid only very near the tablejump itself.  */
9664   /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
9665      GET_MODE_SIZE, because this indicates how large insns are.  The other
9666      uses should all be Pmode, because they are addresses.  This code
9667      could fail if addresses and insns are not the same size.  */
9668   index = gen_rtx_PLUS (Pmode,
9669                         gen_rtx_MULT (Pmode, index,
9670                                       GEN_INT (GET_MODE_SIZE (CASE_VECTOR_MODE))),
9671                         gen_rtx_LABEL_REF (Pmode, table_label));
9672 #ifdef PIC_CASE_VECTOR_ADDRESS
9673   if (flag_pic)
9674     index = PIC_CASE_VECTOR_ADDRESS (index);
9675   else
9676 #endif
9677     index = memory_address_noforce (CASE_VECTOR_MODE, index);
9678   temp = gen_reg_rtx (CASE_VECTOR_MODE);
9679   vector = gen_rtx_MEM (CASE_VECTOR_MODE, index);
9680   RTX_UNCHANGING_P (vector) = 1;
9681   MEM_NOTRAP_P (vector) = 1;
9682   convert_move (temp, vector, 0);
9683
9684   emit_jump_insn (gen_tablejump (temp, table_label));
9685
9686   /* If we are generating PIC code or if the table is PC-relative, the
9687      table and JUMP_INSN must be adjacent, so don't output a BARRIER.  */
9688   if (! CASE_VECTOR_PC_RELATIVE && ! flag_pic)
9689     emit_barrier ();
9690 }
9691
9692 int
9693 try_tablejump (tree index_type, tree index_expr, tree minval, tree range,
9694                rtx table_label, rtx default_label)
9695 {
9696   rtx index;
9697
9698   if (! HAVE_tablejump)
9699     return 0;
9700
9701   index_expr = fold (build (MINUS_EXPR, index_type,
9702                             convert (index_type, index_expr),
9703                             convert (index_type, minval)));
9704   index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
9705   emit_queue ();
9706   index = protect_from_queue (index, 0);
9707   do_pending_stack_adjust ();
9708
9709   do_tablejump (index, TYPE_MODE (index_type),
9710                 convert_modes (TYPE_MODE (index_type),
9711                                TYPE_MODE (TREE_TYPE (range)),
9712                                expand_expr (range, NULL_RTX,
9713                                             VOIDmode, 0),
9714                                TREE_UNSIGNED (TREE_TYPE (range))),
9715                 table_label, default_label);
9716   return 1;
9717 }
9718
9719 /* Nonzero if the mode is a valid vector mode for this architecture.
9720    This returns nonzero even if there is no hardware support for the
9721    vector mode, but we can emulate with narrower modes.  */
9722
9723 int
9724 vector_mode_valid_p (enum machine_mode mode)
9725 {
9726   enum mode_class class = GET_MODE_CLASS (mode);
9727   enum machine_mode innermode;
9728
9729   /* Doh!  What's going on?  */
9730   if (class != MODE_VECTOR_INT
9731       && class != MODE_VECTOR_FLOAT)
9732     return 0;
9733
9734   /* Hardware support.  Woo hoo!  */
9735   if (VECTOR_MODE_SUPPORTED_P (mode))
9736     return 1;
9737
9738   innermode = GET_MODE_INNER (mode);
9739
9740   /* We should probably return 1 if requesting V4DI and we have no DI,
9741      but we have V2DI, but this is probably very unlikely.  */
9742
9743   /* If we have support for the inner mode, we can safely emulate it.
9744      We may not have V2DI, but me can emulate with a pair of DIs.  */
9745   return mov_optab->handlers[innermode].insn_code != CODE_FOR_nothing;
9746 }
9747
9748 /* Return a CONST_VECTOR rtx for a VECTOR_CST tree.  */
9749 static rtx
9750 const_vector_from_tree (tree exp)
9751 {
9752   rtvec v;
9753   int units, i;
9754   tree link, elt;
9755   enum machine_mode inner, mode;
9756
9757   mode = TYPE_MODE (TREE_TYPE (exp));
9758
9759   if (is_zeros_p (exp))
9760     return CONST0_RTX (mode);
9761
9762   units = GET_MODE_NUNITS (mode);
9763   inner = GET_MODE_INNER (mode);
9764
9765   v = rtvec_alloc (units);
9766
9767   link = TREE_VECTOR_CST_ELTS (exp);
9768   for (i = 0; link; link = TREE_CHAIN (link), ++i)
9769     {
9770       elt = TREE_VALUE (link);
9771
9772       if (TREE_CODE (elt) == REAL_CST)
9773         RTVEC_ELT (v, i) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt),
9774                                                          inner);
9775       else
9776         RTVEC_ELT (v, i) = immed_double_const (TREE_INT_CST_LOW (elt),
9777                                                TREE_INT_CST_HIGH (elt),
9778                                                inner);
9779     }
9780
9781   /* Initialize remaining elements to 0.  */
9782   for (; i < units; ++i)
9783     RTVEC_ELT (v, i) = CONST0_RTX (inner);
9784
9785   return gen_rtx_raw_CONST_VECTOR (mode, v);
9786 }
9787
9788 #include "gt-expr.h"