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