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