OSDN Git Service

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