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