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