OSDN Git Service

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