OSDN Git Service

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