OSDN Git Service

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