OSDN Git Service

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