OSDN Git Service

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