OSDN Git Service

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