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