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