OSDN Git Service

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