OSDN Git Service

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