OSDN Git Service

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